xref: /AOO41X/main/sw/source/ui/docvw/SidebarWin.cxx (revision efeef26f81c84063fb0a91bde3856d4a51172d90)
1*efeef26fSAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*efeef26fSAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*efeef26fSAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*efeef26fSAndrew Rist  * distributed with this work for additional information
6*efeef26fSAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*efeef26fSAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*efeef26fSAndrew Rist  * "License"); you may not use this file except in compliance
9*efeef26fSAndrew Rist  * with the License.  You may obtain a copy of the License at
10cdf0e10cSrcweir  *
11*efeef26fSAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12cdf0e10cSrcweir  *
13*efeef26fSAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*efeef26fSAndrew Rist  * software distributed under the License is distributed on an
15*efeef26fSAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*efeef26fSAndrew Rist  * KIND, either express or implied.  See the License for the
17*efeef26fSAndrew Rist  * specific language governing permissions and limitations
18*efeef26fSAndrew Rist  * under the License.
19cdf0e10cSrcweir  *
20*efeef26fSAndrew Rist  *************************************************************/
21*efeef26fSAndrew Rist 
22*efeef26fSAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir #include "precompiled_sw.hxx"
25cdf0e10cSrcweir 
26cdf0e10cSrcweir #include <SidebarWin.hxx>
27cdf0e10cSrcweir #include <SidebarWinAcc.hxx>
28cdf0e10cSrcweir #include <PostItMgr.hxx>
29cdf0e10cSrcweir 
30cdf0e10cSrcweir #include <SidebarTxtControl.hxx>
31cdf0e10cSrcweir #include <AnchorOverlayObject.hxx>
32cdf0e10cSrcweir #include <ShadowOverlayObject.hxx>
33cdf0e10cSrcweir 
34cdf0e10cSrcweir #include <annotation.hrc>
35cdf0e10cSrcweir #include <popup.hrc>
36cdf0e10cSrcweir #include <docvw.hrc>
37cdf0e10cSrcweir #include <app.hrc>
38cdf0e10cSrcweir #include <access.hrc>
39cdf0e10cSrcweir 
40cdf0e10cSrcweir #include <viewopt.hxx>
41cdf0e10cSrcweir #include <cmdid.h>
42cdf0e10cSrcweir 
43cdf0e10cSrcweir #include <editeng/fontitem.hxx>
44cdf0e10cSrcweir #include <editeng/fhgtitem.hxx>
45cdf0e10cSrcweir #include <editeng/langitem.hxx>
46cdf0e10cSrcweir #include <editeng/editview.hxx>
47cdf0e10cSrcweir #include <editeng/outliner.hxx>
48cdf0e10cSrcweir #include <editeng/editeng.hxx>
49cdf0e10cSrcweir #include <editeng/eeitem.hxx>
50cdf0e10cSrcweir 
51cdf0e10cSrcweir #include <svl/zforlist.hxx>
52cdf0e10cSrcweir #include <svl/undo.hxx>
53cdf0e10cSrcweir #include <svl/stritem.hxx>
54cdf0e10cSrcweir 
55cdf0e10cSrcweir #include <sfx2/viewfrm.hxx>
56cdf0e10cSrcweir #include <sfx2/bindings.hxx>
57cdf0e10cSrcweir #include <sfx2/dispatch.hxx>
58cdf0e10cSrcweir 
59cdf0e10cSrcweir #include <vcl/scrbar.hxx>
60cdf0e10cSrcweir #include <vcl/svapp.hxx>
61cdf0e10cSrcweir #include <vcl/menubtn.hxx>
62cdf0e10cSrcweir 
63cdf0e10cSrcweir #include <edtwin.hxx>
64cdf0e10cSrcweir #include <view.hxx>
65cdf0e10cSrcweir #include <docsh.hxx>
66cdf0e10cSrcweir #include <wrtsh.hxx>
67cdf0e10cSrcweir #include <doc.hxx>
68cdf0e10cSrcweir #include <swmodule.hxx>
69cdf0e10cSrcweir #include <langhelper.hxx>
70cdf0e10cSrcweir 
71cdf0e10cSrcweir #include <sw_primitivetypes2d.hxx>
72cdf0e10cSrcweir #include <drawinglayer/primitive2d/primitivetools2d.hxx>
73cdf0e10cSrcweir #include <drawinglayer/primitive2d/fillgradientprimitive2d.hxx>
74cdf0e10cSrcweir #include <drawinglayer/primitive2d/polypolygonprimitive2d.hxx>
75cdf0e10cSrcweir #include <drawinglayer/primitive2d/polygonprimitive2d.hxx>
76cdf0e10cSrcweir #include <drawinglayer/primitive2d/shadowprimitive2d.hxx>
77cdf0e10cSrcweir 
78cdf0e10cSrcweir namespace css = ::com::sun::star;
79cdf0e10cSrcweir 
80cdf0e10cSrcweir namespace sw { namespace sidebarwindows {
81cdf0e10cSrcweir 
82cdf0e10cSrcweir #define METABUTTON_WIDTH        16
83cdf0e10cSrcweir #define METABUTTON_HEIGHT       18
84cdf0e10cSrcweir #define METABUTTON_AREA_WIDTH   30
85cdf0e10cSrcweir #define POSTIT_META_HEIGHT  (sal_Int32)     30
86cdf0e10cSrcweir #define POSTIT_MINIMUMSIZE_WITHOUT_META     50
87cdf0e10cSrcweir 
88cdf0e10cSrcweir #define POSTIT_SHADOW_BRIGHT    Color(180,180,180)
89cdf0e10cSrcweir #define POSTIT_SHADOW_DARK      Color(83,83,83)
90cdf0e10cSrcweir 
91cdf0e10cSrcweir #define EMPTYSTRING             rtl::OUString::createFromAscii("")
92cdf0e10cSrcweir 
93cdf0e10cSrcweir /************** SwSidebarWin************************************/
94cdf0e10cSrcweir SwSidebarWin::SwSidebarWin( SwEditWin& rEditWin,
95cdf0e10cSrcweir                             WinBits nBits,
96cdf0e10cSrcweir                             SwPostItMgr& aMgr,
97cdf0e10cSrcweir                             SwPostItBits aBits,
98cdf0e10cSrcweir                             SwSidebarItem& rSidebarItem )
99cdf0e10cSrcweir     : Window(&rEditWin, nBits)
100cdf0e10cSrcweir     , mrMgr(aMgr)
101cdf0e10cSrcweir     , mrView( rEditWin.GetView() )
102cdf0e10cSrcweir     , nFlags(aBits)
103cdf0e10cSrcweir     , mnEventId(0)
104cdf0e10cSrcweir     , mpOutlinerView(0)
105cdf0e10cSrcweir     , mpOutliner(0)
106cdf0e10cSrcweir     , mpSidebarTxtControl(0)
107cdf0e10cSrcweir     , mpVScrollbar(0)
108cdf0e10cSrcweir     , mpMetadataAuthor(0)
109cdf0e10cSrcweir     , mpMetadataDate(0)
110cdf0e10cSrcweir     , mpMenuButton(0)
111cdf0e10cSrcweir     , mpAnchor(0)
112cdf0e10cSrcweir     , mpShadow(0)
113cdf0e10cSrcweir     , mColorAnchor()
114cdf0e10cSrcweir     , mColorDark()
115cdf0e10cSrcweir     , mColorLight()
116cdf0e10cSrcweir     , mChangeColor()
117cdf0e10cSrcweir     , meSidebarPosition( sw::sidebarwindows::SIDEBAR_NONE )
118cdf0e10cSrcweir     , mPosSize()
119cdf0e10cSrcweir     , mAnchorRect()
120cdf0e10cSrcweir     , mPageBorder( 0 )
121cdf0e10cSrcweir     , mbMouseOver( false )
122cdf0e10cSrcweir     , mLayoutStatus( SwPostItHelper::INVISIBLE )
123cdf0e10cSrcweir     , mbReadonly( false )
124cdf0e10cSrcweir     , mbIsFollow( false )
125cdf0e10cSrcweir     , mrSidebarItem( rSidebarItem )
126cdf0e10cSrcweir     , mpAnchorFrm( rSidebarItem.maLayoutInfo.mpAnchorFrm )
127cdf0e10cSrcweir {
128cdf0e10cSrcweir     mpShadow = ShadowOverlayObject::CreateShadowOverlayObject( mrView );
129cdf0e10cSrcweir     if ( mpShadow )
130cdf0e10cSrcweir     {
131cdf0e10cSrcweir         mpShadow->setVisible(false);
132cdf0e10cSrcweir     }
133cdf0e10cSrcweir 
134cdf0e10cSrcweir     mrMgr.ConnectSidebarWinToFrm( *(mrSidebarItem.maLayoutInfo.mpAnchorFrm),
135cdf0e10cSrcweir                                   *(mrSidebarItem.GetFmtFld()),
136cdf0e10cSrcweir                                   *this );
137cdf0e10cSrcweir }
138cdf0e10cSrcweir 
139cdf0e10cSrcweir SwSidebarWin::~SwSidebarWin()
140cdf0e10cSrcweir {
141cdf0e10cSrcweir     mrMgr.DisconnectSidebarWinFromFrm( *(mrSidebarItem.maLayoutInfo.mpAnchorFrm),
142cdf0e10cSrcweir                                        *this );
143cdf0e10cSrcweir 
144cdf0e10cSrcweir     Disable();
145cdf0e10cSrcweir 
146cdf0e10cSrcweir     if ( mpSidebarTxtControl )
147cdf0e10cSrcweir     {
148cdf0e10cSrcweir         if ( mpOutlinerView )
149cdf0e10cSrcweir         {
150cdf0e10cSrcweir             mpOutlinerView->SetWindow( 0 );
151cdf0e10cSrcweir         }
152cdf0e10cSrcweir         delete mpSidebarTxtControl;
153cdf0e10cSrcweir         mpSidebarTxtControl = 0;
154cdf0e10cSrcweir     }
155cdf0e10cSrcweir 
156cdf0e10cSrcweir     if ( mpOutlinerView )
157cdf0e10cSrcweir     {
158cdf0e10cSrcweir         delete mpOutlinerView;
159cdf0e10cSrcweir         mpOutlinerView = 0;
160cdf0e10cSrcweir     }
161cdf0e10cSrcweir 
162cdf0e10cSrcweir     if (mpOutliner)
163cdf0e10cSrcweir     {
164cdf0e10cSrcweir         delete mpOutliner;
165cdf0e10cSrcweir         mpOutliner = 0;
166cdf0e10cSrcweir     }
167cdf0e10cSrcweir 
168cdf0e10cSrcweir     if (mpMetadataAuthor)
169cdf0e10cSrcweir     {
170cdf0e10cSrcweir         mpMetadataAuthor->RemoveEventListener( LINK( this, SwSidebarWin, WindowEventListener ) );
171cdf0e10cSrcweir         delete mpMetadataAuthor;
172cdf0e10cSrcweir         mpMetadataAuthor = 0;
173cdf0e10cSrcweir     }
174cdf0e10cSrcweir 
175cdf0e10cSrcweir     if (mpMetadataDate)
176cdf0e10cSrcweir     {
177cdf0e10cSrcweir         mpMetadataDate->RemoveEventListener( LINK( this, SwSidebarWin, WindowEventListener ) );
178cdf0e10cSrcweir         delete mpMetadataDate;
179cdf0e10cSrcweir         mpMetadataDate = 0;
180cdf0e10cSrcweir     }
181cdf0e10cSrcweir 
182cdf0e10cSrcweir     if (mpVScrollbar)
183cdf0e10cSrcweir     {
184cdf0e10cSrcweir         mpVScrollbar->RemoveEventListener( LINK( this, SwSidebarWin, WindowEventListener ) );
185cdf0e10cSrcweir         delete mpVScrollbar;
186cdf0e10cSrcweir         mpVScrollbar = 0;
187cdf0e10cSrcweir     }
188cdf0e10cSrcweir 
189cdf0e10cSrcweir     AnchorOverlayObject::DestroyAnchorOverlayObject( mpAnchor );
190cdf0e10cSrcweir     mpAnchor = 0;
191cdf0e10cSrcweir 
192cdf0e10cSrcweir     ShadowOverlayObject::DestroyShadowOverlayObject( mpShadow );
193cdf0e10cSrcweir     mpShadow = 0;
194cdf0e10cSrcweir 
195cdf0e10cSrcweir     delete mpMenuButton;
196cdf0e10cSrcweir     mpMenuButton = 0;
197cdf0e10cSrcweir 
198cdf0e10cSrcweir     if (mnEventId)
199cdf0e10cSrcweir         Application::RemoveUserEvent( mnEventId );
200cdf0e10cSrcweir }
201cdf0e10cSrcweir 
202cdf0e10cSrcweir void SwSidebarWin::Paint( const Rectangle& rRect)
203cdf0e10cSrcweir {
204cdf0e10cSrcweir     Window::Paint(rRect);
205cdf0e10cSrcweir 
206cdf0e10cSrcweir     if (mpMetadataAuthor->IsVisible() )
207cdf0e10cSrcweir     {
208cdf0e10cSrcweir         //draw left over space
209cdf0e10cSrcweir         if ( Application::GetSettings().GetStyleSettings().GetHighContrastMode() )
210cdf0e10cSrcweir         {
211cdf0e10cSrcweir             SetFillColor(COL_BLACK);
212cdf0e10cSrcweir         }
213cdf0e10cSrcweir         else
214cdf0e10cSrcweir         {
215cdf0e10cSrcweir             SetFillColor(mColorDark);
216cdf0e10cSrcweir         }
217cdf0e10cSrcweir         SetLineColor();
218cdf0e10cSrcweir         DrawRect( PixelToLogic(
219cdf0e10cSrcweir                 Rectangle( Point( mpMetadataAuthor->GetPosPixel().X() +
220cdf0e10cSrcweir                                     mpMetadataAuthor->GetSizePixel().Width(),
221cdf0e10cSrcweir                                   mpMetadataAuthor->GetPosPixel().Y() ),
222cdf0e10cSrcweir                            Size( GetMetaButtonAreaWidth(),
223cdf0e10cSrcweir                                  mpMetadataAuthor->GetSizePixel().Height() +
224cdf0e10cSrcweir                                     mpMetadataDate->GetSizePixel().Height() ) ) ) );
225cdf0e10cSrcweir     }
226cdf0e10cSrcweir }
227cdf0e10cSrcweir 
228cdf0e10cSrcweir void SwSidebarWin::SetPosSizePixelRect( long nX,
229cdf0e10cSrcweir                                         long nY,
230cdf0e10cSrcweir                                         long nWidth,
231cdf0e10cSrcweir                                         long nHeight,
232cdf0e10cSrcweir                                         const SwRect &aRect,
233cdf0e10cSrcweir                                         const long aPageBorder)
234cdf0e10cSrcweir {
235cdf0e10cSrcweir     mPosSize = Rectangle(Point(nX,nY),Size(nWidth,nHeight));
236cdf0e10cSrcweir     mAnchorRect = aRect;
237cdf0e10cSrcweir     mPageBorder = aPageBorder;
238cdf0e10cSrcweir }
239cdf0e10cSrcweir 
240cdf0e10cSrcweir void SwSidebarWin::SetSize( const Size& rNewSize )
241cdf0e10cSrcweir {
242cdf0e10cSrcweir     mPosSize.SetSize(rNewSize);
243cdf0e10cSrcweir }
244cdf0e10cSrcweir 
245cdf0e10cSrcweir void SwSidebarWin::SetVirtualPosSize( const Point& aPoint, const Size& aSize)
246cdf0e10cSrcweir {
247cdf0e10cSrcweir     mPosSize = Rectangle(aPoint,aSize);
248cdf0e10cSrcweir }
249cdf0e10cSrcweir 
250cdf0e10cSrcweir void SwSidebarWin::TranslateTopPosition(const long aAmount)
251cdf0e10cSrcweir {
252cdf0e10cSrcweir     mPosSize.Move(0,aAmount);
253cdf0e10cSrcweir }
254cdf0e10cSrcweir 
255cdf0e10cSrcweir void SwSidebarWin::ShowAnchorOnly(const Point &aPoint)
256cdf0e10cSrcweir {
257cdf0e10cSrcweir     HideNote();
258cdf0e10cSrcweir     SetPosAndSize();
259cdf0e10cSrcweir     if (mpAnchor)
260cdf0e10cSrcweir     {
261cdf0e10cSrcweir         mpAnchor->SetSixthPosition(basegfx::B2DPoint(aPoint.X(),aPoint.Y()));
262cdf0e10cSrcweir         mpAnchor->SetSeventhPosition(basegfx::B2DPoint(aPoint.X(),aPoint.Y()));
263cdf0e10cSrcweir         mpAnchor->SetAnchorState(AS_ALL);
264cdf0e10cSrcweir         mpAnchor->setVisible(true);
265cdf0e10cSrcweir     }
266cdf0e10cSrcweir     if (mpShadow)
267cdf0e10cSrcweir         mpShadow->setVisible(false);
268cdf0e10cSrcweir }
269cdf0e10cSrcweir 
270cdf0e10cSrcweir SfxItemSet SwSidebarWin::DefaultItem()
271cdf0e10cSrcweir {
272cdf0e10cSrcweir     SfxItemSet aItem( mrView.GetDocShell()->GetPool() );
273cdf0e10cSrcweir     aItem.Put(SvxFontHeightItem(200,100,EE_CHAR_FONTHEIGHT));
274cdf0e10cSrcweir     aItem.Put(SvxFontItem(FAMILY_SWISS,GetSettings().GetStyleSettings().GetFieldFont().GetName(),
275cdf0e10cSrcweir         EMPTYSTRING,PITCH_DONTKNOW,RTL_TEXTENCODING_DONTKNOW,EE_CHAR_FONTINFO));
276cdf0e10cSrcweir     return aItem;
277cdf0e10cSrcweir }
278cdf0e10cSrcweir 
279cdf0e10cSrcweir void SwSidebarWin::InitControls()
280cdf0e10cSrcweir {
281cdf0e10cSrcweir     AddEventListener( LINK( this, SwSidebarWin, WindowEventListener ) );
282cdf0e10cSrcweir 
283cdf0e10cSrcweir     // actual window which holds the user text
284cdf0e10cSrcweir     mpSidebarTxtControl = new SidebarTxtControl( *this,
285cdf0e10cSrcweir                                                  WB_NODIALOGCONTROL,
286cdf0e10cSrcweir                                                  mrView, mrMgr );
287cdf0e10cSrcweir     mpSidebarTxtControl->SetPointer(Pointer(POINTER_TEXT));
288cdf0e10cSrcweir 
289cdf0e10cSrcweir     // window controls for author and date
290cdf0e10cSrcweir     mpMetadataAuthor = new Edit( this, 0 );
291cdf0e10cSrcweir     mpMetadataAuthor->SetAccessibleName( SW_RES( STR_ACCESS_ANNOTATION_AUTHOR_NAME ) );
292cdf0e10cSrcweir     mpMetadataAuthor->SetReadOnly();
293cdf0e10cSrcweir     mpMetadataAuthor->AlwaysDisableInput(true);
294cdf0e10cSrcweir     mpMetadataAuthor->SetCallHandlersOnInputDisabled(true);
295cdf0e10cSrcweir     mpMetadataAuthor->AddEventListener( LINK( this, SwSidebarWin, WindowEventListener ) );
296cdf0e10cSrcweir     // we should leave this setting alone, but for this we need a better layout algo
297cdf0e10cSrcweir     // with variable meta size height
298cdf0e10cSrcweir     {
299cdf0e10cSrcweir         AllSettings aSettings = mpMetadataAuthor->GetSettings();
300cdf0e10cSrcweir         StyleSettings aStyleSettings = aSettings.GetStyleSettings();
301cdf0e10cSrcweir         Font aFont = aStyleSettings.GetFieldFont();
302cdf0e10cSrcweir         aFont.SetHeight(8);
303cdf0e10cSrcweir         aStyleSettings.SetFieldFont(aFont);
304cdf0e10cSrcweir         aSettings.SetStyleSettings(aStyleSettings);
305cdf0e10cSrcweir         mpMetadataAuthor->SetSettings(aSettings);
306cdf0e10cSrcweir     }
307cdf0e10cSrcweir 
308cdf0e10cSrcweir     mpMetadataDate = new Edit( this, 0 );
309cdf0e10cSrcweir     mpMetadataDate->SetAccessibleName( SW_RES( STR_ACCESS_ANNOTATION_DATE_NAME ) );
310cdf0e10cSrcweir     mpMetadataDate->SetReadOnly();
311cdf0e10cSrcweir     mpMetadataDate->AlwaysDisableInput(true);
312cdf0e10cSrcweir     mpMetadataDate->SetCallHandlersOnInputDisabled(true);
313cdf0e10cSrcweir     mpMetadataDate->AddEventListener( LINK( this, SwSidebarWin, WindowEventListener ) );
314cdf0e10cSrcweir     // we should leave this setting alone, but for this we need a better layout algo
315cdf0e10cSrcweir     // with variable meta size height
316cdf0e10cSrcweir     {
317cdf0e10cSrcweir         AllSettings aSettings = mpMetadataDate->GetSettings();
318cdf0e10cSrcweir         StyleSettings aStyleSettings = aSettings.GetStyleSettings();
319cdf0e10cSrcweir         Font aFont = aStyleSettings.GetFieldFont();
320cdf0e10cSrcweir         aFont.SetHeight(8);
321cdf0e10cSrcweir         aStyleSettings.SetFieldFont(aFont);
322cdf0e10cSrcweir         aSettings.SetStyleSettings(aStyleSettings);
323cdf0e10cSrcweir         mpMetadataDate->SetSettings(aSettings);
324cdf0e10cSrcweir     }
325cdf0e10cSrcweir 
326cdf0e10cSrcweir 
327cdf0e10cSrcweir     SwDocShell* aShell = mrView.GetDocShell();
328cdf0e10cSrcweir     mpOutliner = new Outliner(&aShell->GetPool(),OUTLINERMODE_TEXTOBJECT);
329cdf0e10cSrcweir     aShell->GetDoc()->SetCalcFieldValueHdl( mpOutliner );
330cdf0e10cSrcweir     mpOutliner->SetUpdateMode( sal_True );
331cdf0e10cSrcweir     Rescale();
332cdf0e10cSrcweir 
333cdf0e10cSrcweir     mpOutlinerView = new OutlinerView ( mpOutliner, mpSidebarTxtControl );
334cdf0e10cSrcweir     mpOutlinerView->SetBackgroundColor(COL_TRANSPARENT);
335cdf0e10cSrcweir     mpOutliner->InsertView(mpOutlinerView );
336cdf0e10cSrcweir     mpOutlinerView->SetOutputArea( PixelToLogic( Rectangle(0,0,1,1) ) );
337cdf0e10cSrcweir 
338cdf0e10cSrcweir     mpOutlinerView->SetAttribs(DefaultItem());
339cdf0e10cSrcweir 
340cdf0e10cSrcweir     // TODO: ??
341cdf0e10cSrcweir     EEHorizontalTextDirection aDefHoriTextDir = Application::GetSettings().GetLayoutRTL() ? EE_HTEXTDIR_R2L : EE_HTEXTDIR_L2R;
342cdf0e10cSrcweir     mpOutliner->SetDefaultHorizontalTextDirection( aDefHoriTextDir );
343cdf0e10cSrcweir 
344cdf0e10cSrcweir     //create Scrollbars
345cdf0e10cSrcweir     mpVScrollbar = new ScrollBar(this, WB_3DLOOK |WB_VSCROLL|WB_DRAG);
346cdf0e10cSrcweir     mpVScrollbar->EnableNativeWidget(false);
347cdf0e10cSrcweir     mpVScrollbar->EnableRTL( false );
348cdf0e10cSrcweir     mpVScrollbar->SetScrollHdl(LINK(this, SwSidebarWin, ScrollHdl));
349cdf0e10cSrcweir     mpVScrollbar->EnableDrag();
350cdf0e10cSrcweir     mpVScrollbar->AddEventListener( LINK( this, SwSidebarWin, WindowEventListener ) );
351cdf0e10cSrcweir 
352cdf0e10cSrcweir     const SwViewOption* pVOpt = mrView.GetWrtShellPtr()->GetViewOptions();
353cdf0e10cSrcweir     sal_uLong nCntrl = mpOutliner->GetControlWord();
354cdf0e10cSrcweir     // TODO: crash when AUTOCOMPLETE enabled
355cdf0e10cSrcweir     nCntrl |= EE_CNTRL_MARKFIELDS | EE_CNTRL_PASTESPECIAL | EE_CNTRL_AUTOCORRECT  | EV_CNTRL_AUTOSCROLL | EE_CNTRL_URLSFXEXECUTE; // | EE_CNTRL_AUTOCOMPLETE;
356cdf0e10cSrcweir     if (pVOpt->IsFieldShadings())
357cdf0e10cSrcweir         nCntrl |= EE_CNTRL_MARKFIELDS;
358cdf0e10cSrcweir     else
359cdf0e10cSrcweir         nCntrl &= ~EE_CNTRL_MARKFIELDS;
360cdf0e10cSrcweir     if (pVOpt->IsOnlineSpell())
361cdf0e10cSrcweir         nCntrl |= EE_CNTRL_ONLINESPELLING;
362cdf0e10cSrcweir     else
363cdf0e10cSrcweir         nCntrl &= ~EE_CNTRL_ONLINESPELLING;
364cdf0e10cSrcweir     mpOutliner->SetControlWord(nCntrl);
365cdf0e10cSrcweir 
366cdf0e10cSrcweir     sal_uInt16 aIndex = SW_MOD()->InsertRedlineAuthor(GetAuthor());
367cdf0e10cSrcweir     SetColor( mrMgr.GetColorDark(aIndex),
368cdf0e10cSrcweir               mrMgr.GetColorLight(aIndex),
369cdf0e10cSrcweir               mrMgr.GetColorAnchor(aIndex));
370cdf0e10cSrcweir 
371cdf0e10cSrcweir     CheckMetaText();
372cdf0e10cSrcweir 
373cdf0e10cSrcweir     mpMenuButton = CreateMenuButton();
374cdf0e10cSrcweir 
375cdf0e10cSrcweir     SetLanguage(GetLanguage());
376cdf0e10cSrcweir     GetOutlinerView()->StartSpeller();
377cdf0e10cSrcweir     SetPostItText();
378cdf0e10cSrcweir     Engine()->CompleteOnlineSpelling();
379cdf0e10cSrcweir 
380cdf0e10cSrcweir     mpSidebarTxtControl->Show();
381cdf0e10cSrcweir     mpMetadataAuthor->Show();
382cdf0e10cSrcweir     mpMetadataDate->Show();
383cdf0e10cSrcweir     mpVScrollbar->Show();
384cdf0e10cSrcweir }
385cdf0e10cSrcweir 
386cdf0e10cSrcweir void SwSidebarWin::CheckMetaText()
387cdf0e10cSrcweir {
388cdf0e10cSrcweir     const SvtSysLocale aSysLocale;
389cdf0e10cSrcweir     const LocaleDataWrapper& rLocalData = aSysLocale.GetLocaleData();
390cdf0e10cSrcweir     String sMeta = GetAuthor();
391cdf0e10cSrcweir     if (sMeta.Len() == 0)
392cdf0e10cSrcweir     {
393cdf0e10cSrcweir         sMeta = String(SW_RES(STR_NOAUTHOR));
394cdf0e10cSrcweir     }
395cdf0e10cSrcweir     else if (sMeta.Len() > 22)
396cdf0e10cSrcweir     {
397cdf0e10cSrcweir         sMeta.Erase(20);
398cdf0e10cSrcweir         sMeta = sMeta + rtl::OUString::createFromAscii("...");
399cdf0e10cSrcweir     }
400cdf0e10cSrcweir     if ( mpMetadataAuthor->GetText() != sMeta )
401cdf0e10cSrcweir     {
402cdf0e10cSrcweir         mpMetadataAuthor->SetText(sMeta);
403cdf0e10cSrcweir     }
404cdf0e10cSrcweir 
405cdf0e10cSrcweir     Date aDate = GetDate();
406cdf0e10cSrcweir     if (aDate==Date())
407cdf0e10cSrcweir     {
408cdf0e10cSrcweir         sMeta = String(SW_RES(STR_POSTIT_TODAY));
409cdf0e10cSrcweir     }
410cdf0e10cSrcweir     else if (aDate == Date(Date()-1))
411cdf0e10cSrcweir     {
412cdf0e10cSrcweir         sMeta = String(SW_RES(STR_POSTIT_YESTERDAY));
413cdf0e10cSrcweir     }
414cdf0e10cSrcweir     else if (aDate.IsValid() )
415cdf0e10cSrcweir     {
416cdf0e10cSrcweir         sMeta = rLocalData.getDate(aDate);
417cdf0e10cSrcweir     }
418cdf0e10cSrcweir     else
419cdf0e10cSrcweir     {
420cdf0e10cSrcweir         sMeta = String(SW_RES(STR_NODATE));
421cdf0e10cSrcweir     }
422cdf0e10cSrcweir     if (GetTime()!=0)
423cdf0e10cSrcweir     {
424cdf0e10cSrcweir         sMeta = sMeta + rtl::OUString::createFromAscii(" ")  + rLocalData.getTime( GetTime(),false );
425cdf0e10cSrcweir     }
426cdf0e10cSrcweir     if ( mpMetadataDate->GetText() != sMeta )
427cdf0e10cSrcweir     {
428cdf0e10cSrcweir         mpMetadataDate->SetText(sMeta);
429cdf0e10cSrcweir     }
430cdf0e10cSrcweir 
431cdf0e10cSrcweir }
432cdf0e10cSrcweir 
433cdf0e10cSrcweir void SwSidebarWin::Rescale()
434cdf0e10cSrcweir {
435cdf0e10cSrcweir     MapMode aMode = GetParent()->GetMapMode();
436cdf0e10cSrcweir     aMode.SetOrigin( Point() );
437cdf0e10cSrcweir     mpOutliner->SetRefMapMode( aMode );
438cdf0e10cSrcweir     SetMapMode( aMode );
439cdf0e10cSrcweir     mpSidebarTxtControl->SetMapMode( aMode );
440cdf0e10cSrcweir     if ( mpMetadataAuthor )
441cdf0e10cSrcweir     {
442cdf0e10cSrcweir         Font aFont( mpMetadataAuthor->GetSettings().GetStyleSettings().GetFieldFont() );
443cdf0e10cSrcweir         sal_Int32 nHeight = aFont.GetHeight();
444cdf0e10cSrcweir         nHeight = nHeight * aMode.GetScaleY().GetNumerator() / aMode.GetScaleY().GetDenominator();
445cdf0e10cSrcweir         aFont.SetHeight( nHeight );
446cdf0e10cSrcweir         mpMetadataAuthor->SetControlFont( aFont );
447cdf0e10cSrcweir     }
448cdf0e10cSrcweir     if ( mpMetadataDate )
449cdf0e10cSrcweir     {
450cdf0e10cSrcweir         Font aFont( mpMetadataDate->GetSettings().GetStyleSettings().GetFieldFont() );
451cdf0e10cSrcweir         sal_Int32 nHeight = aFont.GetHeight();
452cdf0e10cSrcweir         nHeight = nHeight * aMode.GetScaleY().GetNumerator() / aMode.GetScaleY().GetDenominator();
453cdf0e10cSrcweir         aFont.SetHeight( nHeight );
454cdf0e10cSrcweir         mpMetadataDate->SetControlFont( aFont );
455cdf0e10cSrcweir     }
456cdf0e10cSrcweir }
457cdf0e10cSrcweir 
458cdf0e10cSrcweir void SwSidebarWin::SetPosAndSize()
459cdf0e10cSrcweir {
460cdf0e10cSrcweir     bool bChange = false;
461cdf0e10cSrcweir 
462cdf0e10cSrcweir     if (GetSizePixel() != mPosSize.GetSize())
463cdf0e10cSrcweir     {
464cdf0e10cSrcweir         bChange = true;
465cdf0e10cSrcweir         SetSizePixel(mPosSize.GetSize());
466cdf0e10cSrcweir         DoResize();
467cdf0e10cSrcweir     }
468cdf0e10cSrcweir 
469cdf0e10cSrcweir     if (GetPosPixel().X() != mPosSize.TopLeft().X() || (abs(GetPosPixel().Y() - mPosSize.TopLeft().Y()) > 5) )
470cdf0e10cSrcweir     {
471cdf0e10cSrcweir         bChange = true;
472cdf0e10cSrcweir         SetPosPixel(mPosSize.TopLeft());
473cdf0e10cSrcweir 
474cdf0e10cSrcweir         Point aLineStart;
475cdf0e10cSrcweir         Point aLineEnd ;
476cdf0e10cSrcweir         switch ( meSidebarPosition )
477cdf0e10cSrcweir         {
478cdf0e10cSrcweir             case sw::sidebarwindows::SIDEBAR_LEFT:
479cdf0e10cSrcweir             {
480cdf0e10cSrcweir                 aLineStart = EditWin()->PixelToLogic( Point(GetPosPixel().X()+GetSizePixel().Width(),GetPosPixel().Y()-1) );
481cdf0e10cSrcweir                 aLineEnd = EditWin()->PixelToLogic( Point(GetPosPixel().X(),GetPosPixel().Y()-1) );
482cdf0e10cSrcweir             }
483cdf0e10cSrcweir             break;
484cdf0e10cSrcweir             case sw::sidebarwindows::SIDEBAR_RIGHT:
485cdf0e10cSrcweir             {
486cdf0e10cSrcweir                 aLineStart = EditWin()->PixelToLogic( Point(GetPosPixel().X(),GetPosPixel().Y()-1) );
487cdf0e10cSrcweir                 aLineEnd = EditWin()->PixelToLogic( Point(GetPosPixel().X()+GetSizePixel().Width(),GetPosPixel().Y()-1) );
488cdf0e10cSrcweir             }
489cdf0e10cSrcweir             break;
490cdf0e10cSrcweir             default:
491cdf0e10cSrcweir                 ASSERT( false,
492cdf0e10cSrcweir                         "<SwSidebarWin::SetPosAndSize()> - unexpected position of sidebar" );
493cdf0e10cSrcweir             break;
494cdf0e10cSrcweir         }
495cdf0e10cSrcweir 
496cdf0e10cSrcweir         if (!IsPreview())
497cdf0e10cSrcweir         {
498cdf0e10cSrcweir             if (mpAnchor)
499cdf0e10cSrcweir             {
500cdf0e10cSrcweir                 mpAnchor->SetAllPosition( basegfx::B2DPoint( mAnchorRect.Left() , mAnchorRect.Bottom() - 5* 15),
501cdf0e10cSrcweir                                           basegfx::B2DPoint( mAnchorRect.Left()-5*15 , mAnchorRect.Bottom()+5*15),
502cdf0e10cSrcweir                                           basegfx::B2DPoint( mAnchorRect.Left()+5*15 , mAnchorRect.Bottom()+5*15),
503cdf0e10cSrcweir                                           basegfx::B2DPoint( mAnchorRect.Left(), mAnchorRect.Bottom()+2*15),
504cdf0e10cSrcweir                                           basegfx::B2DPoint( mPageBorder ,mAnchorRect.Bottom()+2*15),
505cdf0e10cSrcweir                                           basegfx::B2DPoint( aLineStart.X(),aLineStart.Y()),
506cdf0e10cSrcweir                                           basegfx::B2DPoint( aLineEnd.X(),aLineEnd.Y()));
507cdf0e10cSrcweir                 mpAnchor->SetHeight(mAnchorRect.Height());
508cdf0e10cSrcweir             }
509cdf0e10cSrcweir             else
510cdf0e10cSrcweir             {
511cdf0e10cSrcweir                 mpAnchor = AnchorOverlayObject::CreateAnchorOverlayObject( mrView,
512cdf0e10cSrcweir                                                                            mAnchorRect,
513cdf0e10cSrcweir                                                                            mPageBorder,
514cdf0e10cSrcweir                                                                            aLineStart,
515cdf0e10cSrcweir                                                                            aLineEnd,
516cdf0e10cSrcweir                                                                            mColorAnchor );
517cdf0e10cSrcweir                 if ( mpAnchor )
518cdf0e10cSrcweir                 {
519cdf0e10cSrcweir                     mpAnchor->SetHeight(mAnchorRect.Height());
520cdf0e10cSrcweir                     mpAnchor->setVisible(true);
521cdf0e10cSrcweir                     mpAnchor->SetAnchorState(AS_TRI);
522cdf0e10cSrcweir                     if (HasChildPathFocus())
523cdf0e10cSrcweir                     {
524cdf0e10cSrcweir                         mpAnchor->setLineSolid(true);
525cdf0e10cSrcweir                     }
526cdf0e10cSrcweir                 }
527cdf0e10cSrcweir             }
528cdf0e10cSrcweir         }
529cdf0e10cSrcweir     }
530cdf0e10cSrcweir     else
531cdf0e10cSrcweir     {
532cdf0e10cSrcweir         if ( mpAnchor &&
533cdf0e10cSrcweir              ( mpAnchor->getBasePosition() != basegfx::B2DPoint( mAnchorRect.Left() , mAnchorRect.Bottom()-5*15) ) )
534cdf0e10cSrcweir         {
535cdf0e10cSrcweir             mpAnchor->SetTriPosition( basegfx::B2DPoint( mAnchorRect.Left() , mAnchorRect.Bottom() - 5* 15),
536cdf0e10cSrcweir                                       basegfx::B2DPoint( mAnchorRect.Left()-5*15 , mAnchorRect.Bottom()+5*15),
537cdf0e10cSrcweir                                       basegfx::B2DPoint( mAnchorRect.Left()+5*15 , mAnchorRect.Bottom()+5*15),
538cdf0e10cSrcweir                                       basegfx::B2DPoint( mAnchorRect.Left(), mAnchorRect.Bottom()+2*15),
539cdf0e10cSrcweir                                       basegfx::B2DPoint( mPageBorder , mAnchorRect.Bottom()+2*15));
540cdf0e10cSrcweir         }
541cdf0e10cSrcweir     }
542cdf0e10cSrcweir 
543cdf0e10cSrcweir     if (bChange)
544cdf0e10cSrcweir     {
545cdf0e10cSrcweir         Point aStart = EditWin()->PixelToLogic(GetPosPixel()+Point(0,GetSizePixel().Height()));
546cdf0e10cSrcweir         Point aEnd = EditWin()->PixelToLogic(GetPosPixel()+Point(GetSizePixel().Width()-1,GetSizePixel().Height()));
547cdf0e10cSrcweir         mpShadow->SetPosition(basegfx::B2DPoint(aStart.X(),aStart.Y()), basegfx::B2DPoint(aEnd.X(),aEnd.Y()));
548cdf0e10cSrcweir     }
549cdf0e10cSrcweir 
550cdf0e10cSrcweir     if (mrMgr.ShowNotes())
551cdf0e10cSrcweir     {
552cdf0e10cSrcweir         if (IsFollow() && !HasChildPathFocus())
553cdf0e10cSrcweir         {
554cdf0e10cSrcweir             // --> OD 2010-06-03 #i111964#
555cdf0e10cSrcweir             if ( mpAnchor )
556cdf0e10cSrcweir             {
557cdf0e10cSrcweir                 mpAnchor->SetAnchorState(AS_END);
558cdf0e10cSrcweir             }
559cdf0e10cSrcweir             // <--
560cdf0e10cSrcweir         }
561cdf0e10cSrcweir         else
562cdf0e10cSrcweir         {
563cdf0e10cSrcweir             // --> OD 2010-06-03 #i111964#
564cdf0e10cSrcweir             if ( mpAnchor )
565cdf0e10cSrcweir             {
566cdf0e10cSrcweir                 mpAnchor->SetAnchorState(AS_ALL);
567cdf0e10cSrcweir             }
568cdf0e10cSrcweir             // <--
569cdf0e10cSrcweir             SwSidebarWin* pWin = GetTopReplyNote();
570cdf0e10cSrcweir             // --> OD 2010-06-03 #i111964#
571cdf0e10cSrcweir             if ( pWin && pWin->Anchor() )
572cdf0e10cSrcweir             // <--
573cdf0e10cSrcweir             {
574cdf0e10cSrcweir                 pWin->Anchor()->SetAnchorState(AS_END);
575cdf0e10cSrcweir             }
576cdf0e10cSrcweir         }
577cdf0e10cSrcweir     }
578cdf0e10cSrcweir }
579cdf0e10cSrcweir 
580cdf0e10cSrcweir void SwSidebarWin::DoResize()
581cdf0e10cSrcweir {
582cdf0e10cSrcweir     long aTextHeight    =  LogicToPixel( mpOutliner->CalcTextSize()).Height();
583cdf0e10cSrcweir     long aHeight        =  GetSizePixel().Height();
584cdf0e10cSrcweir     unsigned long aWidth    =  GetSizePixel().Width();
585cdf0e10cSrcweir 
586cdf0e10cSrcweir     aHeight -= GetMetaHeight();
587cdf0e10cSrcweir     mpMetadataAuthor->Show();
588cdf0e10cSrcweir     mpMetadataDate->Show();
589cdf0e10cSrcweir     mpSidebarTxtControl->SetQuickHelpText(EMPTYSTRING);
590cdf0e10cSrcweir 
591cdf0e10cSrcweir     if ((aTextHeight > aHeight) && !IsPreview())
592cdf0e10cSrcweir     {   // we need vertical scrollbars and have to reduce the width
593cdf0e10cSrcweir         aWidth -= GetScrollbarWidth();
594cdf0e10cSrcweir         mpVScrollbar->Show();
595cdf0e10cSrcweir     }
596cdf0e10cSrcweir     else
597cdf0e10cSrcweir     {
598cdf0e10cSrcweir         mpVScrollbar->Hide();
599cdf0e10cSrcweir     }
600cdf0e10cSrcweir 
601cdf0e10cSrcweir     {
602cdf0e10cSrcweir         const Size aSizeOfMetadataControls( GetSizePixel().Width() - GetMetaButtonAreaWidth(),
603cdf0e10cSrcweir                                             GetMetaHeight()/2 );
604cdf0e10cSrcweir         mpMetadataAuthor->SetPosSizePixel( 0,
605cdf0e10cSrcweir                                            aHeight,
606cdf0e10cSrcweir                                            aSizeOfMetadataControls.Width(),
607cdf0e10cSrcweir                                            aSizeOfMetadataControls.Height() );
608cdf0e10cSrcweir         mpMetadataDate->SetPosSizePixel( 0,
609cdf0e10cSrcweir                                          aHeight + aSizeOfMetadataControls.Height(),
610cdf0e10cSrcweir                                          aSizeOfMetadataControls.Width(),
611cdf0e10cSrcweir                                          aSizeOfMetadataControls.Height() );
612cdf0e10cSrcweir     }
613cdf0e10cSrcweir 
614cdf0e10cSrcweir     mpOutliner->SetPaperSize( PixelToLogic( Size(aWidth,aHeight) ) ) ;
615cdf0e10cSrcweir     mpOutlinerView->SetOutputArea( PixelToLogic( Rectangle(0,0,aWidth,aHeight) ) );
616cdf0e10cSrcweir     if (!mpVScrollbar->IsVisible())
617cdf0e10cSrcweir     {   // if we do not have a scrollbar anymore, we want to see the complete text
618cdf0e10cSrcweir         mpOutlinerView->SetVisArea( PixelToLogic( Rectangle(0,0,aWidth,aHeight) ) );
619cdf0e10cSrcweir     }
620cdf0e10cSrcweir 
621cdf0e10cSrcweir     if (!Application::GetSettings().GetLayoutRTL())
622cdf0e10cSrcweir     {
623cdf0e10cSrcweir         mpSidebarTxtControl->SetPosSizePixel(0, 0, aWidth, aHeight);
624cdf0e10cSrcweir         mpVScrollbar->SetPosSizePixel( aWidth, 0, GetScrollbarWidth(), aHeight);
625cdf0e10cSrcweir     }
626cdf0e10cSrcweir     else
627cdf0e10cSrcweir     {
628cdf0e10cSrcweir         mpSidebarTxtControl->SetPosSizePixel( ( (aTextHeight > aHeight) && !IsPreview()
629cdf0e10cSrcweir                                       ? GetScrollbarWidth() : 0 ) , 0,
630cdf0e10cSrcweir                                       aWidth, aHeight);
631cdf0e10cSrcweir         mpVScrollbar->SetPosSizePixel( 0, 0, GetScrollbarWidth(), aHeight);
632cdf0e10cSrcweir     }
633cdf0e10cSrcweir 
634cdf0e10cSrcweir     mpVScrollbar->SetVisibleSize( PixelToLogic(Size(0,aHeight)).Height() );
635cdf0e10cSrcweir     mpVScrollbar->SetPageSize( PixelToLogic(Size(0,aHeight)).Height() * 8 / 10 );
636cdf0e10cSrcweir     mpVScrollbar->SetLineSize( mpOutliner->GetTextHeight() / 10 );
637cdf0e10cSrcweir     SetScrollbar();
638cdf0e10cSrcweir     mpVScrollbar->SetRange( Range(0, mpOutliner->GetTextHeight()));
639cdf0e10cSrcweir 
640cdf0e10cSrcweir     //calculate rects for meta- button
641cdf0e10cSrcweir     const Fraction& fx( GetMapMode().GetScaleX() );
642cdf0e10cSrcweir     const Fraction& fy( GetMapMode().GetScaleY() );
643cdf0e10cSrcweir 
644cdf0e10cSrcweir     const Point aPos( mpMetadataAuthor->GetPosPixel());
645cdf0e10cSrcweir     Rectangle aRectMetaButton;
646cdf0e10cSrcweir     if (IsPreview())
647cdf0e10cSrcweir     {
648cdf0e10cSrcweir         aRectMetaButton = PixelToLogic(
649cdf0e10cSrcweir             Rectangle( Point( aPos.X()+GetSizePixel().Width()-(METABUTTON_WIDTH*4+10)*fx.GetNumerator()/fx.GetDenominator(),
650cdf0e10cSrcweir                               aPos.Y()+5*fy.GetNumerator()/fy.GetDenominator() ),
651cdf0e10cSrcweir                        Size( METABUTTON_WIDTH*4*fx.GetNumerator()/fx.GetDenominator(),
652cdf0e10cSrcweir                              METABUTTON_HEIGHT*fy.GetNumerator()/fy.GetDenominator() ) ) );
653cdf0e10cSrcweir     }
654cdf0e10cSrcweir     else
655cdf0e10cSrcweir     {
656cdf0e10cSrcweir         aRectMetaButton = PixelToLogic(
657cdf0e10cSrcweir             Rectangle( Point( aPos.X()+GetSizePixel().Width()-(METABUTTON_WIDTH+10)*fx.GetNumerator()/fx.GetDenominator(),
658cdf0e10cSrcweir                               aPos.Y()+5*fy.GetNumerator()/fy.GetDenominator() ),
659cdf0e10cSrcweir                        Size( METABUTTON_WIDTH*fx.GetNumerator()/fx.GetDenominator(),
660cdf0e10cSrcweir                              METABUTTON_HEIGHT*fy.GetNumerator()/fy.GetDenominator() ) ) );
661cdf0e10cSrcweir     }
662cdf0e10cSrcweir 
663cdf0e10cSrcweir     {
664cdf0e10cSrcweir         const Rectangle aRectMetaButtonPixel( LogicToPixel( aRectMetaButton ) );
665cdf0e10cSrcweir         mpMenuButton->SetPosSizePixel( aRectMetaButtonPixel.Left(),
666cdf0e10cSrcweir                                        aRectMetaButtonPixel.Top(),
667cdf0e10cSrcweir                                        aRectMetaButtonPixel.GetWidth(),
668cdf0e10cSrcweir                                        aRectMetaButtonPixel.GetHeight() );
669cdf0e10cSrcweir     }
670cdf0e10cSrcweir }
671cdf0e10cSrcweir 
672cdf0e10cSrcweir void SwSidebarWin::SetSizePixel( const Size& rNewSize )
673cdf0e10cSrcweir {
674cdf0e10cSrcweir     Window::SetSizePixel(rNewSize);
675cdf0e10cSrcweir 
676cdf0e10cSrcweir     if (mpShadow)
677cdf0e10cSrcweir     {
678cdf0e10cSrcweir         Point aStart = EditWin()->PixelToLogic(GetPosPixel()+Point(0,GetSizePixel().Height()));
679cdf0e10cSrcweir         Point aEnd = EditWin()->PixelToLogic(GetPosPixel()+Point(GetSizePixel().Width()-1,GetSizePixel().Height()));
680cdf0e10cSrcweir         mpShadow->SetPosition(basegfx::B2DPoint(aStart.X(),aStart.Y()), basegfx::B2DPoint(aEnd.X(),aEnd.Y()));
681cdf0e10cSrcweir     }
682cdf0e10cSrcweir }
683cdf0e10cSrcweir 
684cdf0e10cSrcweir void SwSidebarWin::SetScrollbar()
685cdf0e10cSrcweir {
686cdf0e10cSrcweir     mpVScrollbar->SetThumbPos( mpOutlinerView->GetVisArea().Top()+ mpOutlinerView->GetEditView().GetCursor()->GetOffsetY());
687cdf0e10cSrcweir }
688cdf0e10cSrcweir 
689cdf0e10cSrcweir void SwSidebarWin::ResizeIfNeccessary(long aOldHeight, long aNewHeight)
690cdf0e10cSrcweir {
691cdf0e10cSrcweir     if (aOldHeight != aNewHeight)
692cdf0e10cSrcweir     {
693cdf0e10cSrcweir         //check for lower border or next note
694cdf0e10cSrcweir         long aBorder = mrMgr.GetNextBorder();
695cdf0e10cSrcweir         if (aBorder != -1)
696cdf0e10cSrcweir         {
697cdf0e10cSrcweir             if (aNewHeight > GetMinimumSizeWithoutMeta())
698cdf0e10cSrcweir             {
699cdf0e10cSrcweir                 long aNewLowerValue = GetPosPixel().Y() + aNewHeight + GetMetaHeight();
700cdf0e10cSrcweir                 if (aNewLowerValue < aBorder)
701cdf0e10cSrcweir                     SetSizePixel(Size(GetSizePixel().Width(),aNewHeight+GetMetaHeight()));
702cdf0e10cSrcweir                 else
703cdf0e10cSrcweir                     SetSizePixel(Size(GetSizePixel().Width(),aBorder - GetPosPixel().Y()));
704cdf0e10cSrcweir                 DoResize();
705cdf0e10cSrcweir                 Invalidate();
706cdf0e10cSrcweir             }
707cdf0e10cSrcweir             else
708cdf0e10cSrcweir             {
709cdf0e10cSrcweir                 if (GetSizePixel().Height() != GetMinimumSizeWithoutMeta() + GetMetaHeight())
710cdf0e10cSrcweir                     SetSizePixel(Size(GetSizePixel().Width(),GetMinimumSizeWithoutMeta() + GetMetaHeight()));
711cdf0e10cSrcweir                 DoResize();
712cdf0e10cSrcweir                 Invalidate();
713cdf0e10cSrcweir             }
714cdf0e10cSrcweir         }
715cdf0e10cSrcweir         else
716cdf0e10cSrcweir         {
717cdf0e10cSrcweir             DoResize();
718cdf0e10cSrcweir             Invalidate();
719cdf0e10cSrcweir         }
720cdf0e10cSrcweir     }
721cdf0e10cSrcweir     else
722cdf0e10cSrcweir     {
723cdf0e10cSrcweir         SetScrollbar();
724cdf0e10cSrcweir     }
725cdf0e10cSrcweir }
726cdf0e10cSrcweir 
727cdf0e10cSrcweir void SwSidebarWin::SetColor(Color aColorDark,Color aColorLight, Color aColorAnchor)
728cdf0e10cSrcweir {
729cdf0e10cSrcweir     mColorDark =  aColorDark;
730cdf0e10cSrcweir     mColorLight = aColorLight;
731cdf0e10cSrcweir     mColorAnchor = aColorAnchor;
732cdf0e10cSrcweir 
733cdf0e10cSrcweir     if ( !Application::GetSettings().GetStyleSettings().GetHighContrastMode() )
734cdf0e10cSrcweir     {
735cdf0e10cSrcweir         {
736cdf0e10cSrcweir             mpMetadataAuthor->SetControlBackground(mColorDark);
737cdf0e10cSrcweir             AllSettings aSettings = mpMetadataAuthor->GetSettings();
738cdf0e10cSrcweir             StyleSettings aStyleSettings = aSettings.GetStyleSettings();
739cdf0e10cSrcweir             aStyleSettings.SetFieldTextColor(aColorAnchor);
740cdf0e10cSrcweir             aSettings.SetStyleSettings(aStyleSettings);
741cdf0e10cSrcweir             mpMetadataAuthor->SetSettings(aSettings);
742cdf0e10cSrcweir         }
743cdf0e10cSrcweir 
744cdf0e10cSrcweir         {
745cdf0e10cSrcweir             mpMetadataDate->SetControlBackground(mColorDark);
746cdf0e10cSrcweir             AllSettings aSettings = mpMetadataDate->GetSettings();
747cdf0e10cSrcweir             StyleSettings aStyleSettings = aSettings.GetStyleSettings();
748cdf0e10cSrcweir             aStyleSettings.SetFieldTextColor(aColorAnchor);
749cdf0e10cSrcweir             aSettings.SetStyleSettings(aStyleSettings);
750cdf0e10cSrcweir             mpMetadataDate->SetSettings(aSettings);
751cdf0e10cSrcweir         }
752cdf0e10cSrcweir 
753cdf0e10cSrcweir         AllSettings aSettings2 = mpVScrollbar->GetSettings();
754cdf0e10cSrcweir         StyleSettings aStyleSettings2 = aSettings2.GetStyleSettings();
755cdf0e10cSrcweir         aStyleSettings2.SetButtonTextColor(Color(0,0,0));
756cdf0e10cSrcweir         aStyleSettings2.SetCheckedColor(mColorLight); //hintergund
757cdf0e10cSrcweir         aStyleSettings2.SetShadowColor(mColorAnchor);
758cdf0e10cSrcweir         aStyleSettings2.SetFaceColor(mColorDark);
759cdf0e10cSrcweir         aSettings2.SetStyleSettings(aStyleSettings2);
760cdf0e10cSrcweir         mpVScrollbar->SetSettings(aSettings2);
761cdf0e10cSrcweir     }
762cdf0e10cSrcweir }
763cdf0e10cSrcweir 
764cdf0e10cSrcweir void SwSidebarWin::SetSidebarPosition(sw::sidebarwindows::SidebarPosition eSidebarPosition)
765cdf0e10cSrcweir {
766cdf0e10cSrcweir     meSidebarPosition = eSidebarPosition;
767cdf0e10cSrcweir }
768cdf0e10cSrcweir 
769cdf0e10cSrcweir void SwSidebarWin::SetReadonly(sal_Bool bSet)
770cdf0e10cSrcweir {
771cdf0e10cSrcweir     mbReadonly = bSet;
772cdf0e10cSrcweir     GetOutlinerView()->SetReadOnly(bSet);
773cdf0e10cSrcweir }
774cdf0e10cSrcweir 
775cdf0e10cSrcweir void SwSidebarWin::SetLanguage(const SvxLanguageItem aNewItem)
776cdf0e10cSrcweir {
777cdf0e10cSrcweir     Link pLink = Engine()->GetModifyHdl();
778cdf0e10cSrcweir     Engine()->SetModifyHdl( Link() );
779cdf0e10cSrcweir     ESelection aOld = GetOutlinerView()->GetSelection();
780cdf0e10cSrcweir 
781cdf0e10cSrcweir     ESelection aNewSelection( 0, 0, (sal_uInt16)Engine()->GetParagraphCount()-1, USHRT_MAX );
782cdf0e10cSrcweir     GetOutlinerView()->SetSelection( aNewSelection );
783cdf0e10cSrcweir     SfxItemSet aEditAttr(GetOutlinerView()->GetAttribs());
784cdf0e10cSrcweir     aEditAttr.Put(aNewItem);
785cdf0e10cSrcweir     GetOutlinerView()->SetAttribs( aEditAttr );
786cdf0e10cSrcweir 
787cdf0e10cSrcweir     GetOutlinerView()->SetSelection(aOld);
788cdf0e10cSrcweir     Engine()->SetModifyHdl( pLink );
789cdf0e10cSrcweir 
790cdf0e10cSrcweir     const SwViewOption* pVOpt = mrView.GetWrtShellPtr()->GetViewOptions();
791cdf0e10cSrcweir     sal_uLong nCntrl = Engine()->GetControlWord();
792cdf0e10cSrcweir     // turn off
793cdf0e10cSrcweir     if (!pVOpt->IsOnlineSpell())
794cdf0e10cSrcweir         nCntrl &= ~EE_CNTRL_ONLINESPELLING;
795cdf0e10cSrcweir     else
796cdf0e10cSrcweir         nCntrl &= ~EE_CNTRL_ONLINESPELLING;
797cdf0e10cSrcweir     Engine()->SetControlWord(nCntrl);
798cdf0e10cSrcweir 
799cdf0e10cSrcweir     //turn back on
800cdf0e10cSrcweir     if (pVOpt->IsOnlineSpell())
801cdf0e10cSrcweir         nCntrl |= EE_CNTRL_ONLINESPELLING;
802cdf0e10cSrcweir     else
803cdf0e10cSrcweir         nCntrl &= ~EE_CNTRL_ONLINESPELLING;
804cdf0e10cSrcweir     Engine()->SetControlWord(nCntrl);
805cdf0e10cSrcweir 
806cdf0e10cSrcweir     Engine()->CompleteOnlineSpelling();
807cdf0e10cSrcweir     Invalidate();
808cdf0e10cSrcweir }
809cdf0e10cSrcweir 
810cdf0e10cSrcweir void SwSidebarWin::DataChanged( const DataChangedEvent& aEvent)
811cdf0e10cSrcweir {
812cdf0e10cSrcweir     Window::DataChanged( aEvent );
813cdf0e10cSrcweir }
814cdf0e10cSrcweir 
815cdf0e10cSrcweir void SwSidebarWin::GetFocus()
816cdf0e10cSrcweir {
817cdf0e10cSrcweir     if (mpSidebarTxtControl)
818cdf0e10cSrcweir         mpSidebarTxtControl->GrabFocus();
819cdf0e10cSrcweir }
820cdf0e10cSrcweir 
821cdf0e10cSrcweir void SwSidebarWin::LoseFocus()
822cdf0e10cSrcweir {
823cdf0e10cSrcweir }
824cdf0e10cSrcweir 
825cdf0e10cSrcweir void SwSidebarWin::ShowNote()
826cdf0e10cSrcweir {
827cdf0e10cSrcweir     SetPosAndSize();
828cdf0e10cSrcweir     if (!IsVisible())
829cdf0e10cSrcweir         Window::Show();
830cdf0e10cSrcweir     if (mpShadow && !mpShadow->isVisible())
831cdf0e10cSrcweir         mpShadow->setVisible(true);
832cdf0e10cSrcweir     if (mpAnchor && !mpAnchor->isVisible())
833cdf0e10cSrcweir         mpAnchor->setVisible(true);
834cdf0e10cSrcweir }
835cdf0e10cSrcweir 
836cdf0e10cSrcweir void SwSidebarWin::HideNote()
837cdf0e10cSrcweir {
838cdf0e10cSrcweir     if (IsVisible())
839cdf0e10cSrcweir         Window::Hide();
840cdf0e10cSrcweir     if (mpAnchor)
841cdf0e10cSrcweir     {
842cdf0e10cSrcweir         if (mrMgr.IsShowAnchor())
843cdf0e10cSrcweir             mpAnchor->SetAnchorState(AS_TRI);
844cdf0e10cSrcweir         else
845cdf0e10cSrcweir             mpAnchor->setVisible(false);
846cdf0e10cSrcweir     }
847cdf0e10cSrcweir     if (mpShadow && mpShadow->isVisible())
848cdf0e10cSrcweir         mpShadow->setVisible(false);
849cdf0e10cSrcweir }
850cdf0e10cSrcweir 
851cdf0e10cSrcweir void SwSidebarWin::ActivatePostIt()
852cdf0e10cSrcweir {
853cdf0e10cSrcweir     mrMgr.AssureStdModeAtShell();
854cdf0e10cSrcweir 
855cdf0e10cSrcweir     mpOutliner->ClearModifyFlag();
856cdf0e10cSrcweir     mpOutliner->GetUndoManager().Clear();
857cdf0e10cSrcweir 
858cdf0e10cSrcweir     CheckMetaText();
859cdf0e10cSrcweir     SetViewState(VS_EDIT);
860cdf0e10cSrcweir     GetOutlinerView()->ShowCursor();
861cdf0e10cSrcweir 
862cdf0e10cSrcweir     mpOutlinerView->GetEditView().SetInsertMode(mrView.GetWrtShellPtr()->IsInsMode());
863cdf0e10cSrcweir 
864cdf0e10cSrcweir     if ( !Application::GetSettings().GetStyleSettings().GetHighContrastMode() )
865cdf0e10cSrcweir         GetOutlinerView()->SetBackgroundColor(mColorDark);
866cdf0e10cSrcweir }
867cdf0e10cSrcweir 
868cdf0e10cSrcweir void SwSidebarWin::DeactivatePostIt()
869cdf0e10cSrcweir {
870cdf0e10cSrcweir     // remove selection, #i87073#
871cdf0e10cSrcweir     if (GetOutlinerView()->GetEditView().HasSelection())
872cdf0e10cSrcweir     {
873cdf0e10cSrcweir         ESelection aSelection = GetOutlinerView()->GetEditView().GetSelection();
874cdf0e10cSrcweir         aSelection.nEndPara = aSelection.nStartPara;
875cdf0e10cSrcweir         aSelection.nEndPos = aSelection.nStartPos;
876cdf0e10cSrcweir         GetOutlinerView()->GetEditView().SetSelection(aSelection);
877cdf0e10cSrcweir     }
878cdf0e10cSrcweir 
879cdf0e10cSrcweir     mpOutliner->CompleteOnlineSpelling();
880cdf0e10cSrcweir 
881cdf0e10cSrcweir     SetViewState(VS_NORMAL);
882cdf0e10cSrcweir     // write the visible text back into the SwField
883cdf0e10cSrcweir     UpdateData();
884cdf0e10cSrcweir 
885cdf0e10cSrcweir     if ( !Application::GetSettings().GetStyleSettings().GetHighContrastMode() )
886cdf0e10cSrcweir         GetOutlinerView()->SetBackgroundColor(COL_TRANSPARENT);
887cdf0e10cSrcweir 
888cdf0e10cSrcweir 
889cdf0e10cSrcweir     if ( !IsProtected() &&
890cdf0e10cSrcweir          Engine()->GetEditEngine().GetText()==String(EMPTYSTRING) )
891cdf0e10cSrcweir     {
892cdf0e10cSrcweir         mnEventId = Application::PostUserEvent( LINK( this, SwSidebarWin, DeleteHdl), 0 );
893cdf0e10cSrcweir     }
894cdf0e10cSrcweir }
895cdf0e10cSrcweir 
896cdf0e10cSrcweir void SwSidebarWin::ToggleInsMode()
897cdf0e10cSrcweir {
898cdf0e10cSrcweir     if (!mrView.GetWrtShell().IsRedlineOn())
899cdf0e10cSrcweir     {
900cdf0e10cSrcweir         //change outliner
901cdf0e10cSrcweir         mpOutlinerView->GetEditView().SetInsertMode(!mpOutlinerView->GetEditView().IsInsertMode());
902cdf0e10cSrcweir         //change documnet
903cdf0e10cSrcweir         mrView.GetWrtShell().ToggleInsMode();
904cdf0e10cSrcweir         //update statusbar
905cdf0e10cSrcweir         SfxBindings &rBnd = mrView.GetViewFrame()->GetBindings();
906cdf0e10cSrcweir         rBnd.Invalidate(SID_ATTR_INSERT);
907cdf0e10cSrcweir         rBnd.Update(SID_ATTR_INSERT);
908cdf0e10cSrcweir     }
909cdf0e10cSrcweir }
910cdf0e10cSrcweir 
911cdf0e10cSrcweir void SwSidebarWin::ExecuteCommand(sal_uInt16 nSlot)
912cdf0e10cSrcweir {
913cdf0e10cSrcweir     mrMgr.AssureStdModeAtShell();
914cdf0e10cSrcweir 
915cdf0e10cSrcweir     switch (nSlot)
916cdf0e10cSrcweir     {
917cdf0e10cSrcweir         case FN_POSTIT:
918cdf0e10cSrcweir         case FN_REPLY:
919cdf0e10cSrcweir         {
920cdf0e10cSrcweir             // if this note is empty, it will be deleted once losing the focus, so no reply, but only a new note
921cdf0e10cSrcweir             // will be created
922cdf0e10cSrcweir             if (Engine()->GetEditEngine().GetText() != String(EMPTYSTRING))
923cdf0e10cSrcweir             {
924cdf0e10cSrcweir                 OutlinerParaObject* pPara = new OutlinerParaObject(*GetOutlinerView()->GetEditView().CreateTextObject());
925cdf0e10cSrcweir                 mrMgr.RegisterAnswer(pPara);
926cdf0e10cSrcweir             }
927cdf0e10cSrcweir             if (mrMgr.HasActiveSidebarWin())
928cdf0e10cSrcweir                 mrMgr.SetActiveSidebarWin(0);
929cdf0e10cSrcweir             SwitchToFieldPos();
930cdf0e10cSrcweir             mrView.GetViewFrame()->GetDispatcher()->Execute(FN_POSTIT);
931cdf0e10cSrcweir             break;
932cdf0e10cSrcweir         }
933cdf0e10cSrcweir         case FN_DELETE_COMMENT:
934cdf0e10cSrcweir 
935cdf0e10cSrcweir                 //Delete(); // do not kill the parent of our open popup menu
936cdf0e10cSrcweir                 mnEventId = Application::PostUserEvent( LINK( this, SwSidebarWin, DeleteHdl), 0 );
937cdf0e10cSrcweir             break;
938cdf0e10cSrcweir         case FN_DELETE_ALL_NOTES:
939cdf0e10cSrcweir         case FN_HIDE_ALL_NOTES:
940cdf0e10cSrcweir             // not possible as slot as this would require that "this" is the active postit
941cdf0e10cSrcweir             mrView.GetViewFrame()->GetBindings().Execute( nSlot, 0, 0, SFX_CALLMODE_ASYNCHRON );
942cdf0e10cSrcweir             break;
943cdf0e10cSrcweir         case FN_DELETE_NOTE_AUTHOR:
944cdf0e10cSrcweir         case FN_HIDE_NOTE_AUTHOR:
945cdf0e10cSrcweir         {
946cdf0e10cSrcweir             // not possible as slot as this would require that "this" is the active postit
947cdf0e10cSrcweir             SfxStringItem aItem( nSlot, GetAuthor() );
948cdf0e10cSrcweir             const SfxPoolItem* aItems[2];
949cdf0e10cSrcweir             aItems[0] = &aItem;
950cdf0e10cSrcweir             aItems[1] = 0;
951cdf0e10cSrcweir             mrView.GetViewFrame()->GetBindings().Execute( nSlot, aItems, 0, SFX_CALLMODE_ASYNCHRON );
952cdf0e10cSrcweir         }
953cdf0e10cSrcweir         default:
954cdf0e10cSrcweir             mrView.GetViewFrame()->GetBindings().Execute( nSlot );
955cdf0e10cSrcweir             break;
956cdf0e10cSrcweir     }
957cdf0e10cSrcweir }
958cdf0e10cSrcweir 
959cdf0e10cSrcweir SwEditWin*  SwSidebarWin::EditWin()
960cdf0e10cSrcweir {
961cdf0e10cSrcweir     return &mrView.GetEditWin();
962cdf0e10cSrcweir }
963cdf0e10cSrcweir 
964cdf0e10cSrcweir long SwSidebarWin::GetPostItTextHeight()
965cdf0e10cSrcweir {
966cdf0e10cSrcweir     return mpOutliner ? LogicToPixel(mpOutliner->CalcTextSize()).Height() : 0;
967cdf0e10cSrcweir }
968cdf0e10cSrcweir 
969cdf0e10cSrcweir void SwSidebarWin::SwitchToPostIt(sal_uInt16 aDirection)
970cdf0e10cSrcweir {
971cdf0e10cSrcweir     SwSidebarWin* pPostIt = mrMgr.GetNextPostIt(aDirection, this);
972cdf0e10cSrcweir     if (pPostIt)
973cdf0e10cSrcweir         pPostIt->GrabFocus();
974cdf0e10cSrcweir }
975cdf0e10cSrcweir 
976cdf0e10cSrcweir IMPL_LINK( SwSidebarWin, WindowEventListener, VclSimpleEvent*, pEvent )
977cdf0e10cSrcweir {
978cdf0e10cSrcweir     VclWindowEvent* pWinEvent = dynamic_cast<VclWindowEvent*>(pEvent);
979cdf0e10cSrcweir     if ( pWinEvent )
980cdf0e10cSrcweir     {
981cdf0e10cSrcweir         if ( pWinEvent->GetId() == VCLEVENT_WINDOW_MOUSEMOVE )
982cdf0e10cSrcweir         {
983cdf0e10cSrcweir             MouseEvent* pMouseEvt = (MouseEvent*)pWinEvent->GetData();
984cdf0e10cSrcweir             if ( pMouseEvt->IsEnterWindow() )
985cdf0e10cSrcweir             {
986cdf0e10cSrcweir                 mbMouseOver = true;
987cdf0e10cSrcweir                 if ( !HasFocus() )
988cdf0e10cSrcweir                 {
989cdf0e10cSrcweir                     SetViewState(VS_VIEW);
990cdf0e10cSrcweir                     Invalidate();
991cdf0e10cSrcweir                 }
992cdf0e10cSrcweir             }
993cdf0e10cSrcweir             else if ( pMouseEvt->IsLeaveWindow())
994cdf0e10cSrcweir             {
995cdf0e10cSrcweir                 if (IsPreview())
996cdf0e10cSrcweir                 {
997cdf0e10cSrcweir                     //doLazyDelete();
998cdf0e10cSrcweir                 }
999cdf0e10cSrcweir                 else
1000cdf0e10cSrcweir                 {
1001cdf0e10cSrcweir                     mbMouseOver = false;
1002cdf0e10cSrcweir                     if ( !HasFocus() )
1003cdf0e10cSrcweir                     {
1004cdf0e10cSrcweir                         SetViewState(VS_NORMAL);
1005cdf0e10cSrcweir                         Invalidate();
1006cdf0e10cSrcweir                     }
1007cdf0e10cSrcweir                 }
1008cdf0e10cSrcweir             }
1009cdf0e10cSrcweir         }
1010cdf0e10cSrcweir         else if ( pWinEvent->GetId() == VCLEVENT_WINDOW_ACTIVATE &&
1011cdf0e10cSrcweir                   pWinEvent->GetWindow() == mpSidebarTxtControl )
1012cdf0e10cSrcweir         {
1013cdf0e10cSrcweir             const sal_Bool bLockView = mrView.GetWrtShell().IsViewLocked();
1014cdf0e10cSrcweir             mrView.GetWrtShell().LockView( sal_True );
1015cdf0e10cSrcweir 
1016cdf0e10cSrcweir             if ( !IsPreview() )
1017cdf0e10cSrcweir             {
1018cdf0e10cSrcweir                 mrMgr.SetActiveSidebarWin( this );
1019cdf0e10cSrcweir             }
1020cdf0e10cSrcweir 
1021cdf0e10cSrcweir             mrView.GetWrtShell().LockView( bLockView );
1022cdf0e10cSrcweir             mrMgr.MakeVisible( this );
1023cdf0e10cSrcweir         }
1024cdf0e10cSrcweir         else if ( pWinEvent->GetWindow() == mpSidebarTxtControl )
1025cdf0e10cSrcweir         {
1026cdf0e10cSrcweir             int i = 5;
1027cdf0e10cSrcweir             ++i;
1028cdf0e10cSrcweir         }
1029cdf0e10cSrcweir     }
1030cdf0e10cSrcweir     return sal_True;
1031cdf0e10cSrcweir }
1032cdf0e10cSrcweir 
1033cdf0e10cSrcweir void SwSidebarWin::Delete()
1034cdf0e10cSrcweir {
1035cdf0e10cSrcweir     if ( mrMgr.GetActiveSidebarWin() == this)
1036cdf0e10cSrcweir     {
1037cdf0e10cSrcweir         mrMgr.SetActiveSidebarWin(0);
1038cdf0e10cSrcweir         // if the note is empty, the previous line will send a delete event, but we are already there
1039cdf0e10cSrcweir         if (mnEventId)
1040cdf0e10cSrcweir         {
1041cdf0e10cSrcweir             Application::RemoveUserEvent( mnEventId );
1042cdf0e10cSrcweir             mnEventId = 0;
1043cdf0e10cSrcweir         }
1044cdf0e10cSrcweir     }
1045cdf0e10cSrcweir }
1046cdf0e10cSrcweir 
1047cdf0e10cSrcweir IMPL_LINK(SwSidebarWin, ScrollHdl, ScrollBar*, pScroll)
1048cdf0e10cSrcweir {
1049cdf0e10cSrcweir     long nDiff = GetOutlinerView()->GetEditView().GetVisArea().Top() - pScroll->GetThumbPos();
1050cdf0e10cSrcweir     GetOutlinerView()->Scroll( 0, nDiff );
1051cdf0e10cSrcweir     return 0;
1052cdf0e10cSrcweir }
1053cdf0e10cSrcweir 
1054cdf0e10cSrcweir IMPL_LINK(SwSidebarWin, ModifyHdl, void*, pVoid)
1055cdf0e10cSrcweir {
1056cdf0e10cSrcweir     // no warnings, please
1057cdf0e10cSrcweir     pVoid=0;
1058cdf0e10cSrcweir     mrView.GetDocShell()->SetModified(sal_True);
1059cdf0e10cSrcweir     return 0;
1060cdf0e10cSrcweir }
1061cdf0e10cSrcweir 
1062cdf0e10cSrcweir IMPL_LINK(SwSidebarWin, DeleteHdl, void*, pVoid)
1063cdf0e10cSrcweir {
1064cdf0e10cSrcweir     // no warnings, please
1065cdf0e10cSrcweir     pVoid=0;
1066cdf0e10cSrcweir     mnEventId = 0;
1067cdf0e10cSrcweir     Delete();
1068cdf0e10cSrcweir     return 0;
1069cdf0e10cSrcweir }
1070cdf0e10cSrcweir 
1071cdf0e10cSrcweir 
1072cdf0e10cSrcweir void SwSidebarWin::ResetAttributes()
1073cdf0e10cSrcweir {
1074cdf0e10cSrcweir     mpOutlinerView->RemoveAttribsKeepLanguages(sal_True);
1075cdf0e10cSrcweir     mpOutliner->RemoveFields(sal_True);
1076cdf0e10cSrcweir     mpOutlinerView->SetAttribs(DefaultItem());
1077cdf0e10cSrcweir }
1078cdf0e10cSrcweir 
1079cdf0e10cSrcweir sal_Int32 SwSidebarWin::GetScrollbarWidth()
1080cdf0e10cSrcweir {
1081cdf0e10cSrcweir     return mrView.GetWrtShell().GetViewOptions()->GetZoom() / 10;
1082cdf0e10cSrcweir }
1083cdf0e10cSrcweir 
1084cdf0e10cSrcweir sal_Int32 SwSidebarWin::GetMetaButtonAreaWidth()
1085cdf0e10cSrcweir {
1086cdf0e10cSrcweir     const Fraction& f( GetMapMode().GetScaleX() );
1087cdf0e10cSrcweir     if (IsPreview())
1088cdf0e10cSrcweir         return 3 * METABUTTON_AREA_WIDTH * f.GetNumerator() / f.GetDenominator();
1089cdf0e10cSrcweir     else
1090cdf0e10cSrcweir         return METABUTTON_AREA_WIDTH * f.GetNumerator() / f.GetDenominator();
1091cdf0e10cSrcweir }
1092cdf0e10cSrcweir 
1093cdf0e10cSrcweir sal_Int32 SwSidebarWin::GetMetaHeight()
1094cdf0e10cSrcweir {
1095cdf0e10cSrcweir     const Fraction& f( GetMapMode().GetScaleY() );
1096cdf0e10cSrcweir     return POSTIT_META_HEIGHT * f.GetNumerator() / f.GetDenominator();
1097cdf0e10cSrcweir }
1098cdf0e10cSrcweir 
1099cdf0e10cSrcweir sal_Int32 SwSidebarWin::GetMinimumSizeWithMeta()
1100cdf0e10cSrcweir {
1101cdf0e10cSrcweir     return mrMgr.GetMinimumSizeWithMeta();
1102cdf0e10cSrcweir }
1103cdf0e10cSrcweir 
1104cdf0e10cSrcweir sal_Int32 SwSidebarWin::GetMinimumSizeWithoutMeta()
1105cdf0e10cSrcweir {
1106cdf0e10cSrcweir     const Fraction& f( GetMapMode().GetScaleY() );
1107cdf0e10cSrcweir     return POSTIT_MINIMUMSIZE_WITHOUT_META * f.GetNumerator() / f.GetDenominator();
1108cdf0e10cSrcweir }
1109cdf0e10cSrcweir 
1110cdf0e10cSrcweir void SwSidebarWin::SetSpellChecking()
1111cdf0e10cSrcweir {
1112cdf0e10cSrcweir     const SwViewOption* pVOpt = mrView.GetWrtShellPtr()->GetViewOptions();
1113cdf0e10cSrcweir     sal_uLong nCntrl = mpOutliner->GetControlWord();
1114cdf0e10cSrcweir     if (pVOpt->IsOnlineSpell())
1115cdf0e10cSrcweir         nCntrl |= EE_CNTRL_ONLINESPELLING;
1116cdf0e10cSrcweir     else
1117cdf0e10cSrcweir         nCntrl &= ~EE_CNTRL_ONLINESPELLING;
1118cdf0e10cSrcweir     mpOutliner->SetControlWord(nCntrl);
1119cdf0e10cSrcweir 
1120cdf0e10cSrcweir     mpOutliner->CompleteOnlineSpelling();
1121cdf0e10cSrcweir     Invalidate();
1122cdf0e10cSrcweir }
1123cdf0e10cSrcweir 
1124cdf0e10cSrcweir void SwSidebarWin::SetViewState(ViewState bViewState)
1125cdf0e10cSrcweir {
1126cdf0e10cSrcweir     switch (bViewState)
1127cdf0e10cSrcweir     {
1128cdf0e10cSrcweir         case VS_EDIT:
1129cdf0e10cSrcweir         {
1130cdf0e10cSrcweir             if (mpAnchor)
1131cdf0e10cSrcweir             {
1132cdf0e10cSrcweir                 mpAnchor->SetAnchorState(AS_ALL);
1133cdf0e10cSrcweir                 SwSidebarWin* pWin = GetTopReplyNote();
1134cdf0e10cSrcweir                 // --> OD 2010-06-03 #i111964#
1135cdf0e10cSrcweir                 if ( pWin && pWin->Anchor() )
1136cdf0e10cSrcweir                 // <--
1137cdf0e10cSrcweir                 {
1138cdf0e10cSrcweir                     pWin->Anchor()->SetAnchorState(AS_END);
1139cdf0e10cSrcweir                 }
1140cdf0e10cSrcweir                 mpAnchor->setLineSolid(true);
1141cdf0e10cSrcweir             }
1142cdf0e10cSrcweir             if (mpShadow)
1143cdf0e10cSrcweir                 mpShadow->SetShadowState(SS_EDIT);
1144cdf0e10cSrcweir             break;
1145cdf0e10cSrcweir         }
1146cdf0e10cSrcweir         case VS_VIEW:
1147cdf0e10cSrcweir         {
1148cdf0e10cSrcweir             if (mpAnchor)
1149cdf0e10cSrcweir                 mpAnchor->setLineSolid(true);
1150cdf0e10cSrcweir             if (mpShadow)
1151cdf0e10cSrcweir                 mpShadow->SetShadowState(SS_VIEW);
1152cdf0e10cSrcweir             break;
1153cdf0e10cSrcweir         }
1154cdf0e10cSrcweir         case VS_NORMAL:
1155cdf0e10cSrcweir         {
1156cdf0e10cSrcweir             if (mpAnchor)
1157cdf0e10cSrcweir             {
1158cdf0e10cSrcweir                 if (IsFollow())
1159cdf0e10cSrcweir                 {
1160cdf0e10cSrcweir                     // if there is no visible parent note, we want to see the complete anchor ??
1161cdf0e10cSrcweir                     //if (IsAnyStackParentVisible())
1162cdf0e10cSrcweir                     mpAnchor->SetAnchorState(AS_END);
1163cdf0e10cSrcweir                     SwSidebarWin* pTopWinSelf = GetTopReplyNote();
1164cdf0e10cSrcweir                     SwSidebarWin* pTopWinActive = mrMgr.HasActiveSidebarWin()
1165cdf0e10cSrcweir                                                   ? mrMgr.GetActiveSidebarWin()->GetTopReplyNote()
1166cdf0e10cSrcweir                                                   : 0;
1167cdf0e10cSrcweir                     // --> OD 2010-06-03 #i111964#
1168cdf0e10cSrcweir                     if ( pTopWinSelf && ( pTopWinSelf != pTopWinActive ) &&
1169cdf0e10cSrcweir                          pTopWinSelf->Anchor() )
1170cdf0e10cSrcweir                     // <--
1171cdf0e10cSrcweir                     {
1172cdf0e10cSrcweir                         if ( pTopWinSelf != mrMgr.GetActiveSidebarWin() )
1173cdf0e10cSrcweir                         {
1174cdf0e10cSrcweir                             pTopWinSelf->Anchor()->setLineSolid(false);
1175cdf0e10cSrcweir                         }
1176cdf0e10cSrcweir                         pTopWinSelf->Anchor()->SetAnchorState(AS_ALL);
1177cdf0e10cSrcweir                     }
1178cdf0e10cSrcweir                 }
1179cdf0e10cSrcweir                 mpAnchor->setLineSolid(false);
1180cdf0e10cSrcweir             }
1181cdf0e10cSrcweir             if ( mpShadow )
1182cdf0e10cSrcweir             {
1183cdf0e10cSrcweir                 mpShadow->SetShadowState(SS_NORMAL);
1184cdf0e10cSrcweir             }
1185cdf0e10cSrcweir             break;
1186cdf0e10cSrcweir         }
1187cdf0e10cSrcweir     }
1188cdf0e10cSrcweir }
1189cdf0e10cSrcweir 
1190cdf0e10cSrcweir SwSidebarWin* SwSidebarWin::GetTopReplyNote()
1191cdf0e10cSrcweir {
1192cdf0e10cSrcweir     SwSidebarWin* pTopNote = 0;
1193cdf0e10cSrcweir     SwSidebarWin* pSidebarWin = IsFollow() ? mrMgr.GetNextPostIt(KEY_PAGEUP, this) : 0;
1194cdf0e10cSrcweir     while (pSidebarWin)
1195cdf0e10cSrcweir     {
1196cdf0e10cSrcweir         pTopNote = pSidebarWin;
1197cdf0e10cSrcweir         pSidebarWin = pSidebarWin->IsFollow() ? mrMgr.GetNextPostIt(KEY_PAGEUP, pSidebarWin) : 0;
1198cdf0e10cSrcweir     }
1199cdf0e10cSrcweir     return pTopNote;
1200cdf0e10cSrcweir }
1201cdf0e10cSrcweir 
1202cdf0e10cSrcweir void SwSidebarWin::SwitchToFieldPos()
1203cdf0e10cSrcweir {
1204cdf0e10cSrcweir     if ( mrMgr.GetActiveSidebarWin() == this )
1205cdf0e10cSrcweir             mrMgr.SetActiveSidebarWin(0);
1206cdf0e10cSrcweir     GotoPos();
1207cdf0e10cSrcweir     sal_uInt32 aCount = MoveCaret();
1208cdf0e10cSrcweir     if (aCount)
1209cdf0e10cSrcweir         mrView.GetDocShell()->GetWrtShell()->SwCrsrShell::Right(aCount, 0, sal_False);
1210cdf0e10cSrcweir     GrabFocusToDocument();
1211cdf0e10cSrcweir }
1212cdf0e10cSrcweir 
1213cdf0e10cSrcweir SvxLanguageItem SwSidebarWin::GetLanguage(void)
1214cdf0e10cSrcweir {
1215cdf0e10cSrcweir     return SvxLanguageItem(SwLangHelper::GetLanguage(mrView.GetWrtShell(),RES_CHRATR_LANGUAGE),RES_CHRATR_LANGUAGE);
1216cdf0e10cSrcweir }
1217cdf0e10cSrcweir 
1218cdf0e10cSrcweir void SwSidebarWin::SetChangeTracking( const SwPostItHelper::SwLayoutStatus aLayoutStatus,
1219cdf0e10cSrcweir                                       const Color& aChangeColor )
1220cdf0e10cSrcweir {
1221cdf0e10cSrcweir     if ( (mLayoutStatus != aLayoutStatus) ||
1222cdf0e10cSrcweir          (mChangeColor != aChangeColor) )
1223cdf0e10cSrcweir     {
1224cdf0e10cSrcweir         mLayoutStatus = aLayoutStatus;
1225cdf0e10cSrcweir         mChangeColor = aChangeColor;
1226cdf0e10cSrcweir         Invalidate();
1227cdf0e10cSrcweir     }
1228cdf0e10cSrcweir }
1229cdf0e10cSrcweir 
1230cdf0e10cSrcweir bool SwSidebarWin::HasScrollbar() const
1231cdf0e10cSrcweir {
1232cdf0e10cSrcweir     return mpVScrollbar != 0;
1233cdf0e10cSrcweir }
1234cdf0e10cSrcweir 
1235cdf0e10cSrcweir bool SwSidebarWin::IsScrollbarVisible() const
1236cdf0e10cSrcweir {
1237cdf0e10cSrcweir     return HasScrollbar() && mpVScrollbar->IsVisible();
1238cdf0e10cSrcweir }
1239cdf0e10cSrcweir 
1240cdf0e10cSrcweir void SwSidebarWin::ChangeSidebarItem( SwSidebarItem& rSidebarItem )
1241cdf0e10cSrcweir {
1242cdf0e10cSrcweir     const bool bAnchorChanged = mpAnchorFrm != rSidebarItem.maLayoutInfo.mpAnchorFrm;
1243cdf0e10cSrcweir     if ( bAnchorChanged )
1244cdf0e10cSrcweir     {
1245cdf0e10cSrcweir         mrMgr.DisconnectSidebarWinFromFrm( *(mpAnchorFrm), *this );
1246cdf0e10cSrcweir     }
1247cdf0e10cSrcweir 
1248cdf0e10cSrcweir     mrSidebarItem = rSidebarItem;
1249cdf0e10cSrcweir     mpAnchorFrm = mrSidebarItem.maLayoutInfo.mpAnchorFrm;
1250cdf0e10cSrcweir 
1251cdf0e10cSrcweir     if ( GetWindowPeer() )
1252cdf0e10cSrcweir     {
1253cdf0e10cSrcweir         SidebarWinAccessible* pAcc =
1254cdf0e10cSrcweir                         static_cast<SidebarWinAccessible*>( GetWindowPeer() );
1255cdf0e10cSrcweir         ASSERT( dynamic_cast<SidebarWinAccessible*>( GetWindowPeer() ),
1256cdf0e10cSrcweir                 "<SwSidebarWin::ChangeSidebarItem(..)> - unexpected type of window peer -> crash possible!" );
1257cdf0e10cSrcweir         pAcc->ChangeSidebarItem( mrSidebarItem );
1258cdf0e10cSrcweir     }
1259cdf0e10cSrcweir 
1260cdf0e10cSrcweir     if ( bAnchorChanged )
1261cdf0e10cSrcweir     {
1262cdf0e10cSrcweir         mrMgr.ConnectSidebarWinToFrm( *(mrSidebarItem.maLayoutInfo.mpAnchorFrm),
1263cdf0e10cSrcweir                                       *(mrSidebarItem.GetFmtFld()),
1264cdf0e10cSrcweir                                       *this );
1265cdf0e10cSrcweir     }
1266cdf0e10cSrcweir }
1267cdf0e10cSrcweir 
1268cdf0e10cSrcweir css::uno::Reference< css::accessibility::XAccessible > SwSidebarWin::CreateAccessible()
1269cdf0e10cSrcweir {
1270cdf0e10cSrcweir     SidebarWinAccessible* pAcc( new SidebarWinAccessible( *this,
1271cdf0e10cSrcweir                                                           mrView.GetWrtShell(),
1272cdf0e10cSrcweir                                                           mrSidebarItem ) );
1273cdf0e10cSrcweir     css::uno::Reference< css::awt::XWindowPeer > xWinPeer( pAcc );
1274cdf0e10cSrcweir     SetWindowPeer( xWinPeer, pAcc );
1275cdf0e10cSrcweir 
1276cdf0e10cSrcweir     css::uno::Reference< css::accessibility::XAccessible > xAcc( xWinPeer, css::uno::UNO_QUERY );
1277cdf0e10cSrcweir     return xAcc;
1278cdf0e10cSrcweir }
1279cdf0e10cSrcweir 
1280cdf0e10cSrcweir } } // eof of namespace sw::sidebarwindows
1281cdf0e10cSrcweir 
1282cdf0e10cSrcweir /********** SwRedComment**************/
1283cdf0e10cSrcweir /*
1284cdf0e10cSrcweir SwRedComment::SwRedComment( Window* pParent, WinBits nBits,SwPostItMgr* aMgr,SwPostItBits aBits,SwRedline* pRed)
1285cdf0e10cSrcweir     : SwSidebarWin(pParent,nBits,aMgr,aBits),
1286cdf0e10cSrcweir     pRedline(pRed)
1287cdf0e10cSrcweir {
1288cdf0e10cSrcweir }
1289cdf0e10cSrcweir 
1290cdf0e10cSrcweir void SwRedComment::SetPopup()
1291cdf0e10cSrcweir {
1292cdf0e10cSrcweir     mpButtonPopup = new PopupMenu(SW_RES(MN_REDCOMMENT_BUTTON));
1293cdf0e10cSrcweir     //mpButtonPopup->SetMenuFlags(MENU_FLAG_ALWAYSSHOWDISABLEDENTRIES);
1294cdf0e10cSrcweir }
1295cdf0e10cSrcweir 
1296cdf0e10cSrcweir void SwRedComment::UpdateData()
1297cdf0e10cSrcweir {
1298cdf0e10cSrcweir     if ( Engine()->IsModified() )
1299cdf0e10cSrcweir     {
1300cdf0e10cSrcweir         // so we get a new layout of notes (Anchor position is still the same and we would otherwise not get one)
1301cdf0e10cSrcweir         Mgr()->SetLayout();
1302cdf0e10cSrcweir         // SetRedline is calling SetModified already
1303cdf0e10cSrcweir         DocView()->GetWrtShell().SetRedlineComment(Engine()->GetEditEngine().GetText());
1304cdf0e10cSrcweir     }
1305cdf0e10cSrcweir     Engine()->ClearModifyFlag();
1306cdf0e10cSrcweir     Engine()->GetUndoManager().Clear();
1307cdf0e10cSrcweir }
1308cdf0e10cSrcweir 
1309cdf0e10cSrcweir void SwRedComment::SetPostItText()
1310cdf0e10cSrcweir {
1311cdf0e10cSrcweir     Engine()->SetModifyHdl( Link() );
1312cdf0e10cSrcweir     Engine()->EnableUndo( sal_False );
1313cdf0e10cSrcweir 
1314cdf0e10cSrcweir     Engine()->Clear();
1315cdf0e10cSrcweir     View()->SetAttribs(DefaultItem());
1316cdf0e10cSrcweir     View()->InsertText(pRedline->GetComment(),false);
1317cdf0e10cSrcweir 
1318cdf0e10cSrcweir     Engine()->ClearModifyFlag();
1319cdf0e10cSrcweir     Engine()->GetUndoManager().Clear();
1320cdf0e10cSrcweir     Engine()->EnableUndo( sal_True );
1321cdf0e10cSrcweir     Engine()->SetModifyHdl( LINK( this, SwSidebarWin, ModifyHdl ) );
1322cdf0e10cSrcweir     Invalidate();
1323cdf0e10cSrcweir }
1324cdf0e10cSrcweir 
1325cdf0e10cSrcweir void SwRedComment::DeactivatePostIt()
1326cdf0e10cSrcweir {
1327cdf0e10cSrcweir     SwSidebarWin::DeactivatePostIt();
1328cdf0e10cSrcweir     // current Redline is still selected
1329cdf0e10cSrcweir     DocView()->GetWrtShellPtr()->ClearMark();
1330cdf0e10cSrcweir }
1331cdf0e10cSrcweir 
1332cdf0e10cSrcweir void SwRedComment::ActivatePostIt()
1333cdf0e10cSrcweir {
1334cdf0e10cSrcweir     SwSidebarWin::ActivatePostIt();
1335cdf0e10cSrcweir 
1336cdf0e10cSrcweir     // do we want the redline selected?
1337cdf0e10cSrcweir     // otherwise, SwRedComment::ActivatePostIt() as well as SwRedComment::DeactivatePostIt()
1338cdf0e10cSrcweir     // can be thrown out completly
1339cdf0e10cSrcweir     DocView()->GetDocShell()->GetWrtShell()->GotoRedline(
1340cdf0e10cSrcweir         DocView()->GetDocShell()->GetWrtShell()->FindRedlineOfData(pRedline->GetRedlineData()),true);
1341cdf0e10cSrcweir }
1342cdf0e10cSrcweir 
1343cdf0e10cSrcweir void SwRedComment::MouseButtonDown( const MouseEvent& rMEvt )
1344cdf0e10cSrcweir {
1345cdf0e10cSrcweir     if (mRectMetaButton.IsInside(PixelToLogic(rMEvt.GetPosPixel())) && rMEvt.IsLeft())
1346cdf0e10cSrcweir     {
1347cdf0e10cSrcweir         ExecuteCommand( mpButtonPopup->Execute( this,Rectangle(LogicToPixel(mRectMetaButton.BottomLeft()),LogicToPixel(mRectMetaButton.BottomLeft())),POPUPMENU_EXECUTE_DOWN | POPUPMENU_NOMOUSEUPCLOSE) );
1348cdf0e10cSrcweir     }
1349cdf0e10cSrcweir }
1350cdf0e10cSrcweir 
1351cdf0e10cSrcweir void SwRedComment::Delete()
1352cdf0e10cSrcweir {
1353cdf0e10cSrcweir     SwSidebarWin::Delete();
1354cdf0e10cSrcweir     // we are not neccessarily on our redline, so let's move there
1355cdf0e10cSrcweir     GotoPos();
1356cdf0e10cSrcweir     DocView()->GetWrtShell().SetRedlineComment(EMPTYSTRING);
1357cdf0e10cSrcweir     DocView()->GetWrtShell().ClearMark();
1358cdf0e10cSrcweir     // so we get a new layout of notes (Anchor position is still the same and we would otherwise not get one)
1359cdf0e10cSrcweir     Mgr()->SetLayout();
1360cdf0e10cSrcweir     Mgr()->RemoveItem(pRedline);
1361cdf0e10cSrcweir }
1362cdf0e10cSrcweir 
1363cdf0e10cSrcweir void SwRedComment::GotoPos()
1364cdf0e10cSrcweir {
1365cdf0e10cSrcweir     DocView()->GetDocShell()->GetWrtShell()->GotoRedline(
1366cdf0e10cSrcweir         DocView()->GetDocShell()->GetWrtShell()->FindRedlineOfData(pRedline->GetRedlineData()));
1367cdf0e10cSrcweir }
1368cdf0e10cSrcweir 
1369cdf0e10cSrcweir String SwRedComment::GetAuthor()
1370cdf0e10cSrcweir {
1371cdf0e10cSrcweir     return pRedline->GetAuthorString();
1372cdf0e10cSrcweir }
1373cdf0e10cSrcweir 
1374cdf0e10cSrcweir Date SwRedComment::GetDate()
1375cdf0e10cSrcweir {
1376cdf0e10cSrcweir     return pRedline->GetTimeStamp().GetDate();
1377cdf0e10cSrcweir }
1378cdf0e10cSrcweir 
1379cdf0e10cSrcweir Time SwRedComment::GetTime()
1380cdf0e10cSrcweir {
1381cdf0e10cSrcweir     return pRedline->GetTimeStamp().GetTime();
1382cdf0e10cSrcweir }
1383cdf0e10cSrcweir 
1384cdf0e10cSrcweir bool SwRedComment::IsProtected()
1385cdf0e10cSrcweir {
1386cdf0e10cSrcweir     return SwSidebarWin::IsProtected() || pRedline->Start()->nNode.GetNode().GetTxtNode()->IsInProtectSect();
1387cdf0e10cSrcweir }
1388cdf0e10cSrcweir */
1389