xref: /aoo42x/main/sw/source/ui/docvw/SidebarWin.cxx (revision d2b26721)
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************************************/
SwSidebarWin(SwEditWin & rEditWin,WinBits nBits,SwPostItMgr & aMgr,SwPostItBits aBits,SwSidebarItem & rSidebarItem)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 
~SwSidebarWin()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 
Paint(const Rectangle & rRect)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 
SetPosSizePixelRect(long nX,long nY,long nWidth,long nHeight,const SwRect & aAnchorRect,const long aPageBorder)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 
SetSize(const Size & rNewSize)248 void SwSidebarWin::SetSize( const Size& rNewSize )
249 {
250     mPosSize.SetSize(rNewSize);
251 }
252 
SetVirtualPosSize(const Point & aPoint,const Size & aSize)253 void SwSidebarWin::SetVirtualPosSize( const Point& aPoint, const Size& aSize)
254 {
255     mPosSize = Rectangle(aPoint,aSize);
256 }
257 
TranslateTopPosition(const long aAmount)258 void SwSidebarWin::TranslateTopPosition(const long aAmount)
259 {
260     mPosSize.Move(0,aAmount);
261 }
262 
ShowAnchorOnly(const Point & aPoint)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 
DefaultItem()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 
InitControls()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 
CheckMetaText()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 
Rescale()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 
SetPosAndSize()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 ( mrMgr.ShowNotes()
583          && mrSidebarItem.maLayoutInfo.mnStartNodeIdx != 0
584          && mrSidebarItem.maLayoutInfo.mnStartContent != STRING_NOTFOUND )
585     {
586         std::vector< basegfx::B2DRange > aAnnotationTextRanges;
587         {
588             const SwTxtAnnotationFld* pTxtAnnotationFld =
589                 dynamic_cast< const SwTxtAnnotationFld* >( mrSidebarItem.GetFmtFld().GetTxtFld() );
590             if ( pTxtAnnotationFld != NULL
591                  && pTxtAnnotationFld->GetpTxtNode() != NULL )
592             {
593                 SwTxtNode* pTxtNode = pTxtAnnotationFld->GetpTxtNode();
594                 SwNodes& rNds = pTxtNode->GetDoc()->GetNodes();
595                 SwCntntNode* const pCntntNd = rNds[mrSidebarItem.maLayoutInfo.mnStartNodeIdx]->GetCntntNode();
596                 SwPosition aStartPos( *pCntntNd, mrSidebarItem.maLayoutInfo.mnStartContent );
597                 SwShellCrsr* pTmpCrsr = NULL;
598                 const bool bTableCrsrNeeded = pTxtNode->FindTableBoxStartNode() != pCntntNd->FindTableBoxStartNode();
599                 if ( bTableCrsrNeeded )
600                 {
601                     SwShellTableCrsr* pTableCrsr = new SwShellTableCrsr( DocView().GetWrtShell(), aStartPos );
602                     pTableCrsr->SetMark();
603                     pTableCrsr->GetMark()->nNode = *pTxtNode;
604                     pTableCrsr->GetMark()->nContent.Assign( pTxtNode, *(pTxtAnnotationFld->GetStart())+1 );
605                     pTableCrsr->NewTableSelection();
606                     pTmpCrsr = pTableCrsr;
607                 }
608                 else
609                 {
610                     SwShellCrsr* pCrsr = new SwShellCrsr( DocView().GetWrtShell(), aStartPos );
611                     pCrsr->SetMark();
612                     pCrsr->GetMark()->nNode = *pTxtNode;
613                     pCrsr->GetMark()->nContent.Assign( pTxtNode, *(pTxtAnnotationFld->GetStart())+1 );
614                     pTmpCrsr = pCrsr;
615                 }
616                 ::boost::scoped_ptr<SwShellCrsr> pTmpCrsrForAnnotationTextRange( pTmpCrsr );
617 
618                 pTmpCrsrForAnnotationTextRange->FillRects();
619 
620                 for( sal_uInt16 a(0); a < pTmpCrsrForAnnotationTextRange->Count(); ++a )
621                 {
622                     const SwRect aNextRect((*pTmpCrsrForAnnotationTextRange)[a]);
623                     const Rectangle aPntRect(aNextRect.SVRect());
624 
625                     aAnnotationTextRanges.push_back(basegfx::B2DRange(
626                         aPntRect.Left(), aPntRect.Top(),
627                         aPntRect.Right() + 1, aPntRect.Bottom() + 1));
628                 }
629             }
630         }
631 
632         if ( mpTextRangeOverlay != NULL )
633         {
634             mpTextRangeOverlay->setRanges( aAnnotationTextRanges );
635             if ( mpAnchor != NULL && mpAnchor->getLineSolid() )
636             {
637                 mpTextRangeOverlay->ShowSolidBorder();
638             }
639             else
640             {
641                 mpTextRangeOverlay->HideSolidBorder();
642             }
643         }
644         else
645         {
646             mpTextRangeOverlay =
647                 sw::overlay::OverlayRanges::CreateOverlayRange(
648                     DocView(),
649                     mColorAnchor,
650                     aAnnotationTextRanges,
651                     mpAnchor != NULL ? mpAnchor->getLineSolid() : false );
652         }
653     }
654     else
655     {
656         delete mpTextRangeOverlay;
657         mpTextRangeOverlay = NULL;
658     }
659 }
660 
DoResize()661 void SwSidebarWin::DoResize()
662 {
663     long aTextHeight    =  LogicToPixel( mpOutliner->CalcTextSize()).Height();
664     long aHeight        =  GetSizePixel().Height();
665     unsigned long aWidth    =  GetSizePixel().Width();
666 
667     aHeight -= GetMetaHeight();
668     mpMetadataAuthor->Show();
669     mpMetadataDate->Show();
670     mpSidebarTxtControl->SetQuickHelpText(EMPTYSTRING);
671 
672     if ((aTextHeight > aHeight) && !IsPreview())
673     {   // we need vertical scrollbars and have to reduce the width
674         aWidth -= GetScrollbarWidth();
675         mpVScrollbar->Show();
676     }
677     else
678     {
679         mpVScrollbar->Hide();
680     }
681 
682     {
683         const Size aSizeOfMetadataControls( GetSizePixel().Width() - GetMetaButtonAreaWidth(),
684                                             GetMetaHeight()/2 );
685         mpMetadataAuthor->SetPosSizePixel( 0,
686                                            aHeight,
687                                            aSizeOfMetadataControls.Width(),
688                                            aSizeOfMetadataControls.Height() );
689         mpMetadataDate->SetPosSizePixel( 0,
690                                          aHeight + aSizeOfMetadataControls.Height(),
691                                          aSizeOfMetadataControls.Width(),
692                                          aSizeOfMetadataControls.Height() );
693     }
694 
695     mpOutliner->SetPaperSize( PixelToLogic( Size(aWidth,aHeight) ) ) ;
696     mpOutlinerView->SetOutputArea( PixelToLogic( Rectangle(0,0,aWidth,aHeight) ) );
697     if (!mpVScrollbar->IsVisible())
698     {   // if we do not have a scrollbar anymore, we want to see the complete text
699         mpOutlinerView->SetVisArea( PixelToLogic( Rectangle(0,0,aWidth,aHeight) ) );
700     }
701 
702     if (!Application::GetSettings().GetLayoutRTL())
703     {
704         mpSidebarTxtControl->SetPosSizePixel(0, 0, aWidth, aHeight);
705         mpVScrollbar->SetPosSizePixel( aWidth, 0, GetScrollbarWidth(), aHeight);
706     }
707     else
708     {
709         mpSidebarTxtControl->SetPosSizePixel( ( (aTextHeight > aHeight) && !IsPreview()
710                                       ? GetScrollbarWidth() : 0 ) , 0,
711                                       aWidth, aHeight);
712         mpVScrollbar->SetPosSizePixel( 0, 0, GetScrollbarWidth(), aHeight);
713     }
714 
715     mpVScrollbar->SetVisibleSize( PixelToLogic(Size(0,aHeight)).Height() );
716     mpVScrollbar->SetPageSize( PixelToLogic(Size(0,aHeight)).Height() * 8 / 10 );
717     mpVScrollbar->SetLineSize( mpOutliner->GetTextHeight() / 10 );
718     SetScrollbar();
719     mpVScrollbar->SetRange( Range(0, mpOutliner->GetTextHeight()));
720 
721     //calculate rects for meta- button
722     const Fraction& fx( GetMapMode().GetScaleX() );
723     const Fraction& fy( GetMapMode().GetScaleY() );
724 
725     const Point aPos( mpMetadataAuthor->GetPosPixel());
726     Rectangle aRectMetaButton;
727     if (IsPreview())
728     {
729         aRectMetaButton = PixelToLogic(
730             Rectangle( Point( aPos.X()+GetSizePixel().Width()-(METABUTTON_WIDTH*4+10)*fx.GetNumerator()/fx.GetDenominator(),
731                               aPos.Y()+5*fy.GetNumerator()/fy.GetDenominator() ),
732                        Size( METABUTTON_WIDTH*4*fx.GetNumerator()/fx.GetDenominator(),
733                              METABUTTON_HEIGHT*fy.GetNumerator()/fy.GetDenominator() ) ) );
734     }
735     else
736     {
737         aRectMetaButton = PixelToLogic(
738             Rectangle( Point( aPos.X()+GetSizePixel().Width()-(METABUTTON_WIDTH+10)*fx.GetNumerator()/fx.GetDenominator(),
739                               aPos.Y()+5*fy.GetNumerator()/fy.GetDenominator() ),
740                        Size( METABUTTON_WIDTH*fx.GetNumerator()/fx.GetDenominator(),
741                              METABUTTON_HEIGHT*fy.GetNumerator()/fy.GetDenominator() ) ) );
742     }
743 
744     {
745         const Rectangle aRectMetaButtonPixel( LogicToPixel( aRectMetaButton ) );
746         mpMenuButton->SetPosSizePixel( aRectMetaButtonPixel.Left(),
747                                        aRectMetaButtonPixel.Top(),
748                                        aRectMetaButtonPixel.GetWidth(),
749                                        aRectMetaButtonPixel.GetHeight() );
750     }
751 }
752 
SetSizePixel(const Size & rNewSize)753 void SwSidebarWin::SetSizePixel( const Size& rNewSize )
754 {
755     Window::SetSizePixel(rNewSize);
756 
757     if (mpShadow)
758     {
759         Point aStart = EditWin()->PixelToLogic(GetPosPixel()+Point(0,GetSizePixel().Height()));
760         Point aEnd = EditWin()->PixelToLogic(GetPosPixel()+Point(GetSizePixel().Width()-1,GetSizePixel().Height()));
761         mpShadow->SetPosition(basegfx::B2DPoint(aStart.X(),aStart.Y()), basegfx::B2DPoint(aEnd.X(),aEnd.Y()));
762     }
763 }
764 
SetScrollbar()765 void SwSidebarWin::SetScrollbar()
766 {
767     mpVScrollbar->SetThumbPos( mpOutlinerView->GetVisArea().Top()+ mpOutlinerView->GetEditView().GetCursor()->GetOffsetY());
768 }
769 
ResizeIfNeccessary(long aOldHeight,long aNewHeight)770 void SwSidebarWin::ResizeIfNeccessary(long aOldHeight, long aNewHeight)
771 {
772     if (aOldHeight != aNewHeight)
773     {
774         //check for lower border or next note
775         long aBorder = mrMgr.GetNextBorder();
776         if (aBorder != -1)
777         {
778             if (aNewHeight > GetMinimumSizeWithoutMeta())
779             {
780                 long aNewLowerValue = GetPosPixel().Y() + aNewHeight + GetMetaHeight();
781                 if (aNewLowerValue < aBorder)
782                     SetSizePixel(Size(GetSizePixel().Width(),aNewHeight+GetMetaHeight()));
783                 else
784                     SetSizePixel(Size(GetSizePixel().Width(),aBorder - GetPosPixel().Y()));
785                 DoResize();
786                 Invalidate();
787             }
788             else
789             {
790                 if (GetSizePixel().Height() != GetMinimumSizeWithoutMeta() + GetMetaHeight())
791                     SetSizePixel(Size(GetSizePixel().Width(),GetMinimumSizeWithoutMeta() + GetMetaHeight()));
792                 DoResize();
793                 Invalidate();
794             }
795         }
796         else
797         {
798             DoResize();
799             Invalidate();
800         }
801     }
802     else
803     {
804         SetScrollbar();
805     }
806 }
807 
SetColor(Color aColorDark,Color aColorLight,Color aColorAnchor)808 void SwSidebarWin::SetColor(Color aColorDark,Color aColorLight, Color aColorAnchor)
809 {
810     mColorDark =  aColorDark;
811     mColorLight = aColorLight;
812     mColorAnchor = aColorAnchor;
813 
814     if ( !Application::GetSettings().GetStyleSettings().GetHighContrastMode() )
815     {
816         {
817             mpMetadataAuthor->SetControlBackground(mColorDark);
818             AllSettings aSettings = mpMetadataAuthor->GetSettings();
819             StyleSettings aStyleSettings = aSettings.GetStyleSettings();
820             aStyleSettings.SetFieldTextColor(aColorAnchor);
821             aSettings.SetStyleSettings(aStyleSettings);
822             mpMetadataAuthor->SetSettings(aSettings);
823         }
824 
825         {
826             mpMetadataDate->SetControlBackground(mColorDark);
827             AllSettings aSettings = mpMetadataDate->GetSettings();
828             StyleSettings aStyleSettings = aSettings.GetStyleSettings();
829             aStyleSettings.SetFieldTextColor(aColorAnchor);
830             aSettings.SetStyleSettings(aStyleSettings);
831             mpMetadataDate->SetSettings(aSettings);
832         }
833 
834         AllSettings aSettings2 = mpVScrollbar->GetSettings();
835         StyleSettings aStyleSettings2 = aSettings2.GetStyleSettings();
836         aStyleSettings2.SetButtonTextColor(Color(0,0,0));
837         aStyleSettings2.SetCheckedColor(mColorLight); //hintergund
838         aStyleSettings2.SetShadowColor(mColorAnchor);
839         aStyleSettings2.SetFaceColor(mColorDark);
840         aSettings2.SetStyleSettings(aStyleSettings2);
841         mpVScrollbar->SetSettings(aSettings2);
842     }
843 }
844 
SetSidebarPosition(sw::sidebarwindows::SidebarPosition eSidebarPosition)845 void SwSidebarWin::SetSidebarPosition(sw::sidebarwindows::SidebarPosition eSidebarPosition)
846 {
847     meSidebarPosition = eSidebarPosition;
848 }
849 
SetReadonly(sal_Bool bSet)850 void SwSidebarWin::SetReadonly(sal_Bool bSet)
851 {
852     mbReadonly = bSet;
853     GetOutlinerView()->SetReadOnly(bSet);
854 }
855 
SetLanguage(const SvxLanguageItem aNewItem)856 void SwSidebarWin::SetLanguage(const SvxLanguageItem aNewItem)
857 {
858     Link pLink = Engine()->GetModifyHdl();
859     Engine()->SetModifyHdl( Link() );
860     ESelection aOld = GetOutlinerView()->GetSelection();
861 
862     ESelection aNewSelection( 0, 0, Engine()->GetParagraphCount()-1, USHRT_MAX );
863     GetOutlinerView()->SetSelection( aNewSelection );
864     SfxItemSet aEditAttr(GetOutlinerView()->GetAttribs());
865     aEditAttr.Put(aNewItem);
866     GetOutlinerView()->SetAttribs( aEditAttr );
867 
868     GetOutlinerView()->SetSelection(aOld);
869     Engine()->SetModifyHdl( pLink );
870 
871     const SwViewOption* pVOpt = mrView.GetWrtShellPtr()->GetViewOptions();
872     sal_uLong nCntrl = Engine()->GetControlWord();
873     // turn off
874     if (!pVOpt->IsOnlineSpell())
875         nCntrl &= ~EE_CNTRL_ONLINESPELLING;
876     else
877         nCntrl &= ~EE_CNTRL_ONLINESPELLING;
878     Engine()->SetControlWord(nCntrl);
879 
880     //turn back on
881     if (pVOpt->IsOnlineSpell())
882         nCntrl |= EE_CNTRL_ONLINESPELLING;
883     else
884         nCntrl &= ~EE_CNTRL_ONLINESPELLING;
885     Engine()->SetControlWord(nCntrl);
886 
887     Engine()->CompleteOnlineSpelling();
888     Invalidate();
889 }
890 
DataChanged(const DataChangedEvent & aEvent)891 void SwSidebarWin::DataChanged( const DataChangedEvent& aEvent)
892 {
893     Window::DataChanged( aEvent );
894 }
895 
GetFocus()896 void SwSidebarWin::GetFocus()
897 {
898     if (mpSidebarTxtControl)
899         mpSidebarTxtControl->GrabFocus();
900 }
901 
LoseFocus()902 void SwSidebarWin::LoseFocus()
903 {
904 }
905 
ShowNote()906 void SwSidebarWin::ShowNote()
907 {
908     SetPosAndSize();
909     if (!IsVisible())
910         Window::Show();
911     if (mpShadow && !mpShadow->isVisible())
912         mpShadow->setVisible(true);
913     if (mpAnchor && !mpAnchor->isVisible())
914         mpAnchor->setVisible(true);
915 }
916 
HideNote()917 void SwSidebarWin::HideNote()
918 {
919     if (IsVisible())
920         Window::Hide();
921     if (mpAnchor)
922     {
923         if (mrMgr.IsShowAnchor())
924             mpAnchor->SetAnchorState(AS_TRI);
925         else
926             mpAnchor->setVisible(false);
927     }
928     if (mpShadow && mpShadow->isVisible())
929         mpShadow->setVisible(false);
930 }
931 
ActivatePostIt()932 void SwSidebarWin::ActivatePostIt()
933 {
934     mrMgr.AssureStdModeAtShell();
935 
936     mpOutliner->ClearModifyFlag();
937     mpOutliner->GetUndoManager().Clear();
938 
939     CheckMetaText();
940     SetViewState(VS_EDIT);
941     GetOutlinerView()->ShowCursor();
942 
943     mpOutlinerView->GetEditView().SetInsertMode(mrView.GetWrtShellPtr()->IsInsMode());
944 
945     if ( !Application::GetSettings().GetStyleSettings().GetHighContrastMode() )
946         GetOutlinerView()->SetBackgroundColor(mColorDark);
947 }
948 
DeactivatePostIt()949 void SwSidebarWin::DeactivatePostIt()
950 {
951     // remove selection, #i87073#
952     if (GetOutlinerView()->GetEditView().HasSelection())
953     {
954         ESelection aSelection = GetOutlinerView()->GetEditView().GetSelection();
955         aSelection.nEndPara = aSelection.nStartPara;
956         aSelection.nEndPos = aSelection.nStartPos;
957         GetOutlinerView()->GetEditView().SetSelection(aSelection);
958     }
959 
960     mpOutliner->CompleteOnlineSpelling();
961 
962     SetViewState(VS_NORMAL);
963     // write the visible text back into the SwField
964     UpdateData();
965 
966     if ( !Application::GetSettings().GetStyleSettings().GetHighContrastMode() )
967         GetOutlinerView()->SetBackgroundColor(COL_TRANSPARENT);
968 
969 
970     if ( !IsProtected() &&
971          Engine()->GetEditEngine().GetText()==String(EMPTYSTRING) )
972     {
973         mnEventId = Application::PostUserEvent( LINK( this, SwSidebarWin, DeleteHdl), 0 );
974     }
975 }
976 
ToggleInsMode()977 void SwSidebarWin::ToggleInsMode()
978 {
979     if (!mrView.GetWrtShell().IsRedlineOn())
980     {
981         //change outliner
982         mpOutlinerView->GetEditView().SetInsertMode(!mpOutlinerView->GetEditView().IsInsertMode());
983         //change documnet
984         mrView.GetWrtShell().ToggleInsMode();
985         //update statusbar
986         SfxBindings &rBnd = mrView.GetViewFrame()->GetBindings();
987         rBnd.Invalidate(SID_ATTR_INSERT);
988         rBnd.Update(SID_ATTR_INSERT);
989     }
990 }
991 
ExecuteCommand(sal_uInt16 nSlot)992 void SwSidebarWin::ExecuteCommand(sal_uInt16 nSlot)
993 {
994     mrMgr.AssureStdModeAtShell();
995 
996     switch (nSlot)
997     {
998         case FN_POSTIT:
999         case FN_REPLY:
1000         {
1001             // if this note is empty, it will be deleted once losing the focus, so no reply, but only a new note
1002             // will be created
1003             if (Engine()->GetEditEngine().GetText() != String(EMPTYSTRING))
1004             {
1005                 OutlinerParaObject* pPara = new OutlinerParaObject(*GetOutlinerView()->GetEditView().CreateTextObject());
1006                 mrMgr.RegisterAnswer(pPara);
1007             }
1008             if (mrMgr.HasActiveSidebarWin())
1009                 mrMgr.SetActiveSidebarWin(0);
1010             SwitchToFieldPos();
1011             mrView.GetViewFrame()->GetDispatcher()->Execute(FN_POSTIT);
1012             break;
1013         }
1014         case FN_DELETE_COMMENT:
1015 
1016                 //Delete(); // do not kill the parent of our open popup menu
1017                 mnEventId = Application::PostUserEvent( LINK( this, SwSidebarWin, DeleteHdl), 0 );
1018             break;
1019         case FN_DELETE_ALL_NOTES:
1020         case FN_HIDE_ALL_NOTES:
1021             // not possible as slot as this would require that "this" is the active postit
1022             mrView.GetViewFrame()->GetBindings().Execute( nSlot, 0, 0, SFX_CALLMODE_ASYNCHRON );
1023             break;
1024         case FN_DELETE_NOTE_AUTHOR:
1025         case FN_HIDE_NOTE_AUTHOR:
1026         {
1027             // not possible as slot as this would require that "this" is the active postit
1028             SfxStringItem aItem( nSlot, GetAuthor() );
1029             const SfxPoolItem* aItems[2];
1030             aItems[0] = &aItem;
1031             aItems[1] = 0;
1032             mrView.GetViewFrame()->GetBindings().Execute( nSlot, aItems, 0, SFX_CALLMODE_ASYNCHRON );
1033         }
1034         default:
1035             mrView.GetViewFrame()->GetBindings().Execute( nSlot );
1036             break;
1037     }
1038 }
1039 
EditWin()1040 SwEditWin*  SwSidebarWin::EditWin()
1041 {
1042     return &mrView.GetEditWin();
1043 }
1044 
GetPostItTextHeight()1045 long SwSidebarWin::GetPostItTextHeight()
1046 {
1047     return mpOutliner ? LogicToPixel(mpOutliner->CalcTextSize()).Height() : 0;
1048 }
1049 
SwitchToPostIt(sal_uInt16 aDirection)1050 void SwSidebarWin::SwitchToPostIt(sal_uInt16 aDirection)
1051 {
1052     SwSidebarWin* pPostIt = mrMgr.GetNextPostIt(aDirection, this);
1053     if (pPostIt)
1054         pPostIt->GrabFocus();
1055 }
1056 
IMPL_LINK(SwSidebarWin,WindowEventListener,VclSimpleEvent *,pEvent)1057 IMPL_LINK( SwSidebarWin, WindowEventListener, VclSimpleEvent*, pEvent )
1058 {
1059     VclWindowEvent* pWinEvent = dynamic_cast<VclWindowEvent*>(pEvent);
1060     if ( pWinEvent )
1061     {
1062         if ( pWinEvent->GetId() == VCLEVENT_WINDOW_MOUSEMOVE )
1063         {
1064             MouseEvent* pMouseEvt = (MouseEvent*)pWinEvent->GetData();
1065             if ( pMouseEvt->IsEnterWindow() )
1066             {
1067                 mbMouseOver = true;
1068                 if ( !HasFocus() )
1069                 {
1070                     SetViewState(VS_VIEW);
1071                     Invalidate();
1072                 }
1073             }
1074             else if ( pMouseEvt->IsLeaveWindow())
1075             {
1076                 if (IsPreview())
1077                 {
1078                     //doLazyDelete();
1079                 }
1080                 else
1081                 {
1082                     mbMouseOver = false;
1083                     if ( !HasFocus() )
1084                     {
1085                         SetViewState(VS_NORMAL);
1086                         Invalidate();
1087                     }
1088                 }
1089             }
1090         }
1091         else if ( pWinEvent->GetId() == VCLEVENT_WINDOW_ACTIVATE &&
1092                   pWinEvent->GetWindow() == mpSidebarTxtControl )
1093         {
1094             const sal_Bool bLockView = mrView.GetWrtShell().IsViewLocked();
1095             mrView.GetWrtShell().LockView( sal_True );
1096 
1097             if ( !IsPreview() )
1098             {
1099                 mrMgr.SetActiveSidebarWin( this );
1100             }
1101 
1102             mrView.GetWrtShell().LockView( bLockView );
1103             mrMgr.MakeVisible( this );
1104         }
1105         else if ( pWinEvent->GetWindow() == mpSidebarTxtControl )
1106         {
1107             int i = 5;
1108             ++i;
1109         }
1110     }
1111     return sal_True;
1112 }
1113 
Delete()1114 void SwSidebarWin::Delete()
1115 {
1116     if ( mrMgr.GetActiveSidebarWin() == this)
1117     {
1118         mrMgr.SetActiveSidebarWin(0);
1119         // if the note is empty, the previous line will send a delete event, but we are already there
1120         if (mnEventId)
1121         {
1122             Application::RemoveUserEvent( mnEventId );
1123             mnEventId = 0;
1124         }
1125     }
1126 }
1127 
IMPL_LINK(SwSidebarWin,ScrollHdl,ScrollBar *,pScroll)1128 IMPL_LINK(SwSidebarWin, ScrollHdl, ScrollBar*, pScroll)
1129 {
1130     long nDiff = GetOutlinerView()->GetEditView().GetVisArea().Top() - pScroll->GetThumbPos();
1131     GetOutlinerView()->Scroll( 0, nDiff );
1132     return 0;
1133 }
1134 
IMPL_LINK(SwSidebarWin,ModifyHdl,void *,pVoid)1135 IMPL_LINK(SwSidebarWin, ModifyHdl, void*, pVoid)
1136 {
1137     // no warnings, please
1138     pVoid=0;
1139     mrView.GetDocShell()->SetModified(sal_True);
1140     return 0;
1141 }
1142 
IMPL_LINK(SwSidebarWin,DeleteHdl,void *,pVoid)1143 IMPL_LINK(SwSidebarWin, DeleteHdl, void*, pVoid)
1144 {
1145     // no warnings, please
1146     pVoid=0;
1147     mnEventId = 0;
1148     Delete();
1149     return 0;
1150 }
1151 
1152 
ResetAttributes()1153 void SwSidebarWin::ResetAttributes()
1154 {
1155     mpOutlinerView->RemoveAttribsKeepLanguages(sal_True);
1156     mpOutliner->RemoveFields(sal_True);
1157     mpOutlinerView->SetAttribs(DefaultItem());
1158 }
1159 
GetScrollbarWidth()1160 sal_Int32 SwSidebarWin::GetScrollbarWidth()
1161 {
1162     return mrView.GetWrtShell().GetViewOptions()->GetZoom() / 10;
1163 }
1164 
GetMetaButtonAreaWidth()1165 sal_Int32 SwSidebarWin::GetMetaButtonAreaWidth()
1166 {
1167     const Fraction& f( GetMapMode().GetScaleX() );
1168     if (IsPreview())
1169         return 3 * METABUTTON_AREA_WIDTH * f.GetNumerator() / f.GetDenominator();
1170     else
1171         return METABUTTON_AREA_WIDTH * f.GetNumerator() / f.GetDenominator();
1172 }
1173 
GetMetaHeight()1174 sal_Int32 SwSidebarWin::GetMetaHeight()
1175 {
1176     const Fraction& f( GetMapMode().GetScaleY() );
1177     return POSTIT_META_HEIGHT * f.GetNumerator() / f.GetDenominator();
1178 }
1179 
GetMinimumSizeWithMeta()1180 sal_Int32 SwSidebarWin::GetMinimumSizeWithMeta()
1181 {
1182     return mrMgr.GetMinimumSizeWithMeta();
1183 }
1184 
GetMinimumSizeWithoutMeta()1185 sal_Int32 SwSidebarWin::GetMinimumSizeWithoutMeta()
1186 {
1187     const Fraction& f( GetMapMode().GetScaleY() );
1188     return POSTIT_MINIMUMSIZE_WITHOUT_META * f.GetNumerator() / f.GetDenominator();
1189 }
1190 
SetSpellChecking()1191 void SwSidebarWin::SetSpellChecking()
1192 {
1193     const SwViewOption* pVOpt = mrView.GetWrtShellPtr()->GetViewOptions();
1194     sal_uLong nCntrl = mpOutliner->GetControlWord();
1195     if (pVOpt->IsOnlineSpell())
1196         nCntrl |= EE_CNTRL_ONLINESPELLING;
1197     else
1198         nCntrl &= ~EE_CNTRL_ONLINESPELLING;
1199     mpOutliner->SetControlWord(nCntrl);
1200 
1201     mpOutliner->CompleteOnlineSpelling();
1202     Invalidate();
1203 }
1204 
SetViewState(ViewState bViewState)1205 void SwSidebarWin::SetViewState(ViewState bViewState)
1206 {
1207     switch (bViewState)
1208     {
1209         case VS_EDIT:
1210         {
1211             if (mpAnchor)
1212             {
1213                 mpAnchor->SetAnchorState(AS_ALL);
1214                 SwSidebarWin* pWin = GetTopReplyNote();
1215                 // --> OD 2010-06-03 #i111964#
1216                 if ( pWin && pWin->Anchor() )
1217                 // <--
1218                 {
1219                     pWin->Anchor()->SetAnchorState(AS_END);
1220                 }
1221                 mpAnchor->setLineSolid(true);
1222                 if ( mpTextRangeOverlay != NULL )
1223                 {
1224                     mpTextRangeOverlay->ShowSolidBorder();
1225                 }
1226             }
1227             if (mpShadow)
1228                 mpShadow->SetShadowState(SS_EDIT);
1229             break;
1230         }
1231         case VS_VIEW:
1232         {
1233             if (mpAnchor)
1234             {
1235                 mpAnchor->setLineSolid(true);
1236                 if ( mpTextRangeOverlay != NULL )
1237                 {
1238                     mpTextRangeOverlay->ShowSolidBorder();
1239                 }
1240             }
1241             if (mpShadow)
1242                 mpShadow->SetShadowState(SS_VIEW);
1243             break;
1244         }
1245         case VS_NORMAL:
1246         {
1247             if (mpAnchor)
1248             {
1249                 if (IsFollow())
1250                 {
1251                     // if there is no visible parent note, we want to see the complete anchor ??
1252                     //if (IsAnyStackParentVisible())
1253                     mpAnchor->SetAnchorState(AS_END);
1254                     SwSidebarWin* pTopWinSelf = GetTopReplyNote();
1255                     SwSidebarWin* pTopWinActive = mrMgr.HasActiveSidebarWin()
1256                                                   ? mrMgr.GetActiveSidebarWin()->GetTopReplyNote()
1257                                                   : 0;
1258                     if ( pTopWinSelf && ( pTopWinSelf != pTopWinActive ) &&
1259                          pTopWinSelf->Anchor() )
1260                     {
1261                         if ( pTopWinSelf != mrMgr.GetActiveSidebarWin() )
1262                         {
1263                             pTopWinSelf->Anchor()->setLineSolid(false);
1264                             if ( pTopWinSelf->TextRange() != NULL )
1265                             {
1266                                 pTopWinSelf->TextRange()->HideSolidBorder();
1267                             }
1268                         }
1269                         pTopWinSelf->Anchor()->SetAnchorState(AS_ALL);
1270                     }
1271                 }
1272                 mpAnchor->setLineSolid(false);
1273                 if ( mpTextRangeOverlay != NULL )
1274                 {
1275                     mpTextRangeOverlay->HideSolidBorder();
1276                 }
1277             }
1278             if ( mpShadow )
1279             {
1280                 mpShadow->SetShadowState(SS_NORMAL);
1281             }
1282             break;
1283         }
1284     }
1285 }
1286 
GetTopReplyNote()1287 SwSidebarWin* SwSidebarWin::GetTopReplyNote()
1288 {
1289     SwSidebarWin* pTopNote = 0;
1290     SwSidebarWin* pSidebarWin = IsFollow() ? mrMgr.GetNextPostIt(KEY_PAGEUP, this) : 0;
1291     while (pSidebarWin)
1292     {
1293         pTopNote = pSidebarWin;
1294         pSidebarWin = pSidebarWin->IsFollow() ? mrMgr.GetNextPostIt(KEY_PAGEUP, pSidebarWin) : 0;
1295     }
1296     return pTopNote;
1297 }
1298 
SwitchToFieldPos()1299 void SwSidebarWin::SwitchToFieldPos()
1300 {
1301     if ( mrMgr.GetActiveSidebarWin() == this )
1302             mrMgr.SetActiveSidebarWin(0);
1303     GotoPos();
1304     sal_uInt32 aCount = MoveCaret();
1305     if (aCount)
1306         mrView.GetDocShell()->GetWrtShell()->SwCrsrShell::Right(aCount, 0, sal_False);
1307     GrabFocusToDocument();
1308 }
1309 
GetLanguage(void)1310 SvxLanguageItem SwSidebarWin::GetLanguage(void)
1311 {
1312     return SvxLanguageItem(SwLangHelper::GetLanguage(mrView.GetWrtShell(),RES_CHRATR_LANGUAGE),RES_CHRATR_LANGUAGE);
1313 }
1314 
SetChangeTracking(const SwPostItHelper::SwLayoutStatus aLayoutStatus,const Color & aChangeColor)1315 void SwSidebarWin::SetChangeTracking( const SwPostItHelper::SwLayoutStatus aLayoutStatus,
1316                                       const Color& aChangeColor )
1317 {
1318     if ( (mLayoutStatus != aLayoutStatus) ||
1319          (mChangeColor != aChangeColor) )
1320     {
1321         mLayoutStatus = aLayoutStatus;
1322         mChangeColor = aChangeColor;
1323         Invalidate();
1324     }
1325 }
1326 
HasScrollbar() const1327 bool SwSidebarWin::HasScrollbar() const
1328 {
1329     return mpVScrollbar != 0;
1330 }
1331 
IsScrollbarVisible() const1332 bool SwSidebarWin::IsScrollbarVisible() const
1333 {
1334     return HasScrollbar() && mpVScrollbar->IsVisible();
1335 }
1336 
ChangeSidebarItem(SwSidebarItem & rSidebarItem)1337 void SwSidebarWin::ChangeSidebarItem( SwSidebarItem& rSidebarItem )
1338 {
1339     const bool bAnchorChanged = mpAnchorFrm != rSidebarItem.maLayoutInfo.mpAnchorFrm;
1340     if ( bAnchorChanged )
1341     {
1342         mrMgr.DisconnectSidebarWinFromFrm( *(mpAnchorFrm), *this );
1343     }
1344 
1345     mrSidebarItem = rSidebarItem;
1346     mpAnchorFrm = mrSidebarItem.maLayoutInfo.mpAnchorFrm;
1347 
1348     if ( GetWindowPeer() )
1349     {
1350         SidebarWinAccessible* pAcc =
1351                         static_cast<SidebarWinAccessible*>( GetWindowPeer() );
1352         ASSERT( dynamic_cast<SidebarWinAccessible*>( GetWindowPeer() ),
1353                 "<SwSidebarWin::ChangeSidebarItem(..)> - unexpected type of window peer -> crash possible!" );
1354         pAcc->ChangeSidebarItem( mrSidebarItem );
1355     }
1356 
1357     if ( bAnchorChanged )
1358     {
1359         mrMgr.ConnectSidebarWinToFrm( *(mrSidebarItem.maLayoutInfo.mpAnchorFrm),
1360                                       mrSidebarItem.GetFmtFld(),
1361                                       *this );
1362     }
1363 }
1364 
CreateAccessible()1365 css::uno::Reference< css::accessibility::XAccessible > SwSidebarWin::CreateAccessible()
1366 {
1367     SidebarWinAccessible* pAcc( new SidebarWinAccessible( *this,
1368                                                           mrView.GetWrtShell(),
1369                                                           mrSidebarItem ) );
1370     css::uno::Reference< css::awt::XWindowPeer > xWinPeer( pAcc );
1371     SetWindowPeer( xWinPeer, pAcc );
1372 
1373     css::uno::Reference< css::accessibility::XAccessible > xAcc( xWinPeer, css::uno::UNO_QUERY );
1374     return xAcc;
1375 }
1376 
1377 } } // eof of namespace sw::sidebarwindows
1378 
1379 /********** SwRedComment**************/
1380 /*
1381 SwRedComment::SwRedComment( Window* pParent, WinBits nBits,SwPostItMgr* aMgr,SwPostItBits aBits,SwRedline* pRed)
1382     : SwSidebarWin(pParent,nBits,aMgr,aBits),
1383     pRedline(pRed)
1384 {
1385 }
1386 
1387 void SwRedComment::SetPopup()
1388 {
1389     mpButtonPopup = new PopupMenu(SW_RES(MN_REDCOMMENT_BUTTON));
1390     //mpButtonPopup->SetMenuFlags(MENU_FLAG_ALWAYSSHOWDISABLEDENTRIES);
1391 }
1392 
1393 void SwRedComment::UpdateData()
1394 {
1395     if ( Engine()->IsModified() )
1396     {
1397         // so we get a new layout of notes (Anchor position is still the same and we would otherwise not get one)
1398         Mgr()->SetLayout();
1399         // SetRedline is calling SetModified already
1400         DocView()->GetWrtShell().SetRedlineComment(Engine()->GetEditEngine().GetText());
1401     }
1402     Engine()->ClearModifyFlag();
1403     Engine()->GetUndoManager().Clear();
1404 }
1405 
1406 void SwRedComment::SetPostItText()
1407 {
1408     Engine()->SetModifyHdl( Link() );
1409     Engine()->EnableUndo( sal_False );
1410 
1411     Engine()->Clear();
1412     View()->SetAttribs(DefaultItem());
1413     View()->InsertText(pRedline->GetComment(),false);
1414 
1415     Engine()->ClearModifyFlag();
1416     Engine()->GetUndoManager().Clear();
1417     Engine()->EnableUndo( sal_True );
1418     Engine()->SetModifyHdl( LINK( this, SwSidebarWin, ModifyHdl ) );
1419     Invalidate();
1420 }
1421 
1422 void SwRedComment::DeactivatePostIt()
1423 {
1424     SwSidebarWin::DeactivatePostIt();
1425     // current Redline is still selected
1426     DocView()->GetWrtShellPtr()->ClearMark();
1427 }
1428 
1429 void SwRedComment::ActivatePostIt()
1430 {
1431     SwSidebarWin::ActivatePostIt();
1432 
1433     // do we want the redline selected?
1434     // otherwise, SwRedComment::ActivatePostIt() as well as SwRedComment::DeactivatePostIt()
1435     // can be thrown out completely
1436     DocView()->GetDocShell()->GetWrtShell()->GotoRedline(
1437         DocView()->GetDocShell()->GetWrtShell()->FindRedlineOfData(pRedline->GetRedlineData()),true);
1438 }
1439 
1440 void SwRedComment::MouseButtonDown( const MouseEvent& rMEvt )
1441 {
1442     if (mRectMetaButton.IsInside(PixelToLogic(rMEvt.GetPosPixel())) && rMEvt.IsLeft())
1443     {
1444         ExecuteCommand( mpButtonPopup->Execute( this,Rectangle(LogicToPixel(mRectMetaButton.BottomLeft()),LogicToPixel(mRectMetaButton.BottomLeft())),POPUPMENU_EXECUTE_DOWN | POPUPMENU_NOMOUSEUPCLOSE) );
1445     }
1446 }
1447 
1448 void SwRedComment::Delete()
1449 {
1450     SwSidebarWin::Delete();
1451     // we are not necessarily on our redline, so let's move there
1452     GotoPos();
1453     DocView()->GetWrtShell().SetRedlineComment(EMPTYSTRING);
1454     DocView()->GetWrtShell().ClearMark();
1455     // so we get a new layout of notes (Anchor position is still the same and we would otherwise not get one)
1456     Mgr()->SetLayout();
1457     Mgr()->RemoveItem(pRedline);
1458 }
1459 
1460 void SwRedComment::GotoPos()
1461 {
1462     DocView()->GetDocShell()->GetWrtShell()->GotoRedline(
1463         DocView()->GetDocShell()->GetWrtShell()->FindRedlineOfData(pRedline->GetRedlineData()));
1464 }
1465 
1466 String SwRedComment::GetAuthor()
1467 {
1468     return pRedline->GetAuthorString();
1469 }
1470 
1471 Date SwRedComment::GetDate()
1472 {
1473     return pRedline->GetTimeStamp().GetDate();
1474 }
1475 
1476 Time SwRedComment::GetTime()
1477 {
1478     return pRedline->GetTimeStamp().GetTime();
1479 }
1480 
1481 bool SwRedComment::IsProtected()
1482 {
1483     return SwSidebarWin::IsProtected() || pRedline->Start()->nNode.GetNode().GetTxtNode()->IsInProtectSect();
1484 }
1485 */
1486