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