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