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 :
21 : #include <editeng/fontitem.hxx>
22 : #include <editeng/eeitem.hxx>
23 : #include <editeng/fhgtitem.hxx>
24 : #include <editeng/bulletitem.hxx>
25 : #include <editeng/udlnitem.hxx>
26 : #include <editeng/shdditem.hxx>
27 : #include <editeng/flditem.hxx>
28 : #include <editeng/frmdir.hxx>
29 : #include <editeng/frmdiritem.hxx>
30 : #include <editeng/langitem.hxx>
31 : #include <editeng/adjustitem.hxx>
32 : #include <editeng/editview.hxx>
33 : #include <svx/svdview.hxx>
34 : #include <svx/sdrpaintwindow.hxx>
35 : #include <svx/sdr/overlay/overlaymanager.hxx>
36 : #include <editeng/editstat.hxx> //EditEngine flags
37 : #include <editeng/outliner.hxx>
38 : #include <editeng/editeng.hxx>
39 : #include <editeng/editobj.hxx>
40 : #include <editeng/unolingu.hxx>
41 : #include <editeng/outlobj.hxx>
42 : #include <editeng/postitem.hxx>
43 : #include <editeng/wghtitem.hxx>
44 : #include <editeng/crossedoutitem.hxx>
45 : #include <svx/svxids.hrc>
46 : #include <svtools/langtab.hxx>
47 : #include <svl/slstitm.hxx>
48 : #include <unotools/securityoptions.hxx>
49 : #include <unotools/useroptions.hxx>
50 : #include <svl/languageoptions.hxx>
51 : #include <svl/zforlist.hxx>
52 : #include <svtools/svmedit.hxx>
53 :
54 : #include <linguistic/lngprops.hxx>
55 :
56 : #include <sfx2/request.hxx>
57 : #include <sfx2/viewfrm.hxx>
58 : #include <sfx2/bindings.hxx>
59 : #include <sfx2/dispatch.hxx>
60 : #include <sfx2/mnumgr.hxx>
61 :
62 : #include <vcl/vclenum.hxx>
63 : #include <vcl/edit.hxx>
64 : #include <vcl/help.hxx>
65 : #include <vcl/scrbar.hxx>
66 : #include <vcl/button.hxx>
67 : #include <vcl/svapp.hxx>
68 : #include <vcl/gradient.hxx>
69 : #include <vcl/cursor.hxx>
70 : #include <tools/helpers.hxx>
71 :
72 : #include <basegfx/matrix/b2dhommatrix.hxx>
73 : #include <basegfx/tuple/b2dtuple.hxx>
74 : #include <basegfx/polygon/b2dpolygontools.hxx>
75 :
76 : #include "annotations.hrc"
77 : #include "annotationwindow.hxx"
78 : #include "annotationmanagerimpl.hxx"
79 :
80 : #include "DrawDocShell.hxx"
81 : #include "ViewShell.hxx"
82 : #include "drawdoc.hxx"
83 : #include "View.hxx"
84 : #include "textapi.hxx"
85 : #include "sdresid.hxx"
86 :
87 : using namespace ::sd;
88 : using namespace ::com::sun::star;
89 : using namespace ::com::sun::star::uno;
90 : using namespace ::com::sun::star::office;
91 : using namespace ::com::sun::star::text;
92 :
93 : #define METABUTTON_WIDTH 16
94 : #define METABUTTON_HEIGHT 18
95 : #define METABUTTON_AREA_WIDTH 30
96 : #define POSTIT_META_HEIGHT (sal_Int32) 30
97 :
98 : namespace sd {
99 :
100 : extern OUString getAnnotationDateTimeString( const Reference< XAnnotation >& xAnnotation );
101 : extern SfxItemPool* GetAnnotationPool();
102 : extern com::sun::star::util::DateTime getCurrentDateTime();
103 :
104 0 : Color ColorFromAlphaColor(sal_uInt8 aTransparency, Color &aFront, Color &aBack )
105 : {
106 0 : return Color((sal_uInt8)(aFront.GetRed() * aTransparency/(double)255 + aBack.GetRed() * (1-aTransparency/(double)255)),
107 0 : (sal_uInt8)(aFront.GetGreen() * aTransparency/(double)255 + aBack.GetGreen() * (1-aTransparency/(double)255)),
108 0 : (sal_uInt8)(aFront.GetBlue() * aTransparency/(double)255 + aBack.GetBlue() * (1-aTransparency/(double)255)));
109 : }
110 :
111 : /************ AnnotationTextWindow **********************************/
112 :
113 0 : AnnotationTextWindow::AnnotationTextWindow( AnnotationWindow* pParent, WinBits nBits )
114 : : Control(pParent, nBits)
115 : , mpOutlinerView(0)
116 0 : , mpAnnotationWindow( pParent )
117 : {
118 0 : }
119 :
120 0 : AnnotationTextWindow::~AnnotationTextWindow()
121 : {
122 0 : }
123 :
124 0 : void AnnotationTextWindow::Paint( const Rectangle& rRect)
125 : {
126 0 : const bool bHighContrast = Application::GetSettings().GetStyleSettings().GetHighContrastMode();
127 0 : if ( !bHighContrast )
128 : {
129 0 : DrawGradient(Rectangle(Point(0,0),PixelToLogic(GetSizePixel())),
130 0 : Gradient(GradientStyle_LINEAR,mpAnnotationWindow->maColorLight,mpAnnotationWindow->maColor));
131 : }
132 :
133 0 : if( mpOutlinerView )
134 : {
135 0 : Color aBackgroundColor( mpAnnotationWindow->maColor );
136 0 : if( bHighContrast )
137 : {
138 0 : aBackgroundColor = GetSettings().GetStyleSettings().GetWindowColor();
139 : }
140 :
141 0 : mpOutlinerView->SetBackgroundColor( aBackgroundColor );
142 :
143 0 : mpOutlinerView->Paint( rRect );
144 : }
145 0 : }
146 :
147 0 : void AnnotationTextWindow::KeyInput( const KeyEvent& rKeyEvt )
148 : {
149 0 : const KeyCode& rKeyCode = rKeyEvt.GetKeyCode();
150 0 : sal_uInt16 nKey = rKeyCode.GetCode();
151 :
152 0 : if ((rKeyCode.IsMod1() && rKeyCode.IsMod2()) && ((nKey == KEY_PAGEUP) || (nKey == KEY_PAGEDOWN)))
153 : {
154 0 : SfxDispatcher* pDispatcher = mpAnnotationWindow->DocShell()->GetViewShell()->GetViewFrame()->GetDispatcher();
155 0 : if( pDispatcher )
156 0 : pDispatcher->Execute( nKey == KEY_PAGEDOWN ? SID_NEXT_POSTIT : SID_PREVIOUS_POSTIT );
157 : }
158 0 : else if (nKey == KEY_INSERT)
159 : {
160 0 : if (!rKeyCode.IsMod1() && !rKeyCode.IsMod2())
161 0 : mpAnnotationWindow->ToggleInsMode();
162 : }
163 : else
164 : {
165 0 : long aOldHeight = mpAnnotationWindow->GetPostItTextHeight();
166 0 : bool bDone = false;
167 :
168 : /// HACK: need to switch off processing of Undo/Redo in Outliner
169 0 : if ( !( (nKey == KEY_Z || nKey == KEY_Y) && rKeyCode.IsMod1()) )
170 : {
171 0 : bool bIsProtected = mpAnnotationWindow->IsProtected();
172 0 : if (!bIsProtected || (bIsProtected && !mpAnnotationWindow->Engine()->GetEditEngine().DoesKeyChangeText(rKeyEvt)) )
173 :
174 0 : bDone = mpOutlinerView->PostKeyEvent( rKeyEvt );
175 : }
176 0 : if (bDone)
177 : {
178 0 : mpAnnotationWindow->ResizeIfNeccessary(aOldHeight,mpAnnotationWindow->GetPostItTextHeight());
179 : }
180 : else
181 : {
182 0 : Control::KeyInput(rKeyEvt);
183 : }
184 : }
185 0 : }
186 :
187 0 : void AnnotationTextWindow::MouseMove( const MouseEvent& rMEvt )
188 : {
189 0 : if ( mpOutlinerView )
190 : {
191 0 : mpOutlinerView->MouseMove( rMEvt );
192 0 : SetPointer( mpOutlinerView->GetPointer( rMEvt.GetPosPixel() ) );
193 : }
194 0 : }
195 :
196 0 : void AnnotationTextWindow::MouseButtonDown( const MouseEvent& rMEvt )
197 : {
198 0 : GrabFocus();
199 0 : if ( mpOutlinerView )
200 0 : mpOutlinerView->MouseButtonDown( rMEvt );
201 : // todo mpOutlinerView->DocView()->GetViewFrame()->GetBindings().InvalidateAll(sal_False);
202 0 : }
203 :
204 0 : void AnnotationTextWindow::MouseButtonUp( const MouseEvent& rMEvt )
205 : {
206 0 : if ( mpOutlinerView )
207 0 : mpOutlinerView->MouseButtonUp( rMEvt );
208 0 : }
209 :
210 0 : void AnnotationTextWindow::Command( const CommandEvent& rCEvt )
211 : {
212 0 : if ( rCEvt.GetCommand() == COMMAND_CONTEXTMENU )
213 : {
214 0 : mpAnnotationWindow->Command(rCEvt);
215 : }
216 : else
217 : {
218 0 : if ( mpOutlinerView )
219 0 : mpOutlinerView->Command( rCEvt );
220 : else
221 0 : Window::Command(rCEvt);
222 : }
223 0 : }
224 :
225 0 : void AnnotationTextWindow::GetFocus()
226 : {
227 0 : Window::GetFocus();
228 0 : }
229 :
230 0 : void AnnotationTextWindow::LoseFocus()
231 : {
232 0 : Window::LoseFocus();
233 0 : }
234 :
235 0 : OUString AnnotationTextWindow::GetSurroundingText() const
236 : {
237 0 : if( mpOutlinerView )
238 : {
239 0 : EditEngine *aEditEngine = mpOutlinerView->GetEditView().GetEditEngine();
240 0 : if( mpOutlinerView->HasSelection() )
241 0 : return mpOutlinerView->GetSelected();
242 : else
243 : {
244 0 : ESelection aSelection = mpOutlinerView->GetEditView().GetSelection();
245 0 : return aEditEngine->GetText(aSelection.nStartPara);
246 : }
247 : }
248 0 : return OUString();
249 : }
250 :
251 0 : Selection AnnotationTextWindow::GetSurroundingTextSelection() const
252 : {
253 0 : if( mpOutlinerView )
254 : {
255 0 : if( mpOutlinerView->HasSelection() )
256 0 : return Selection( 0, mpOutlinerView->GetSelected().Len() );
257 : else
258 : {
259 0 : ESelection aSelection = mpOutlinerView->GetEditView().GetSelection();
260 0 : return Selection( aSelection.nStartPos, aSelection.nEndPos );
261 : }
262 : }
263 : else
264 0 : return Selection( 0, 0 );
265 : }
266 :
267 : /************** AnnotationWindow***********************************++*/
268 :
269 0 : AnnotationWindow::AnnotationWindow( AnnotationManagerImpl& rManager, DrawDocShell* pDocShell, Window* pParent )
270 : : FloatingWindow(pParent, WB_SYSTEMWINDOW|WB_BORDER|WB_NEEDSFOCUS)
271 : , mrManager( rManager )
272 : , mpDocShell( pDocShell )
273 0 : , mpView( pDocShell->GetViewShell()->GetView() )
274 0 : , mpDoc( pDocShell->GetDoc() )
275 : , mpOutlinerView(0)
276 : , mpOutliner(0)
277 : , mpVScrollbar(0)
278 0 : , mbReadonly(pDocShell->IsReadOnly())
279 : , mbProtected(false)
280 : , mbMouseOverButton(false)
281 : , mpTextWindow(0)
282 0 : , mpMeta(0)
283 : {
284 0 : }
285 :
286 0 : AnnotationWindow::~AnnotationWindow()
287 : {
288 0 : delete mpMeta;
289 0 : delete mpOutlinerView;
290 0 : delete mpOutliner;
291 0 : delete mpVScrollbar;
292 0 : delete mpTextWindow;
293 0 : }
294 :
295 0 : void AnnotationWindow::InitControls()
296 : {
297 : // actual window which holds the user text
298 0 : mpTextWindow = new AnnotationTextWindow(this, WB_NODIALOGCONTROL);
299 0 : mpTextWindow->SetPointer(Pointer(POINTER_TEXT));
300 :
301 : // window control for author and date
302 0 : mpMeta = new MultiLineEdit(this,0);
303 0 : mpMeta->SetReadOnly();
304 0 : mpMeta->SetRightToLeft(Application::GetSettings().GetLayoutRTL());
305 0 : mpMeta->AlwaysDisableInput(true);
306 0 : mpMeta->SetCallHandlersOnInputDisabled(true);
307 :
308 : // we should leave this setting alone, but for this we need a better layout algo
309 : // with variable meta size height
310 0 : AllSettings aSettings = mpMeta->GetSettings();
311 0 : StyleSettings aStyleSettings = aSettings.GetStyleSettings();
312 0 : Font aFont = aStyleSettings.GetFieldFont();
313 0 : aFont.SetHeight(8);
314 0 : aStyleSettings.SetFieldFont(aFont);
315 0 : aSettings.SetStyleSettings(aStyleSettings);
316 0 : mpMeta->SetSettings(aSettings);
317 :
318 0 : mpOutliner = new ::Outliner(GetAnnotationPool(),OUTLINERMODE_TEXTOBJECT);
319 0 : Doc()->SetCalcFieldValueHdl( mpOutliner );
320 0 : mpOutliner->SetUpdateMode( sal_True );
321 0 : Rescale();
322 :
323 0 : OutputDevice* pDev = Doc()->GetRefDevice();
324 0 : if( pDev )
325 : {
326 0 : mpOutliner->SetRefDevice( pDev );
327 : }
328 :
329 0 : mpTextWindow->EnableRTL( sal_False );
330 0 : mpOutlinerView = new OutlinerView ( mpOutliner, mpTextWindow );
331 0 : mpOutliner->InsertView(mpOutlinerView );
332 0 : mpTextWindow->SetOutlinerView(mpOutlinerView);
333 0 : mpOutlinerView->SetOutputArea( PixelToLogic( Rectangle(0,0,1,1) ) );
334 :
335 : //create Scrollbars
336 0 : mpVScrollbar = new ScrollBar(this, WB_3DLOOK |WB_VSCROLL|WB_DRAG);
337 0 : mpVScrollbar->EnableNativeWidget(false);
338 0 : mpVScrollbar->EnableRTL( false );
339 0 : mpVScrollbar->SetScrollHdl(LINK(this, AnnotationWindow, ScrollHdl));
340 0 : mpVScrollbar->EnableDrag();
341 :
342 0 : sal_uLong nCntrl = mpOutliner->GetControlWord();
343 0 : nCntrl |= EE_CNTRL_PASTESPECIAL | EE_CNTRL_AUTOCORRECT | EV_CNTRL_AUTOSCROLL | EE_CNTRL_NOCOLORS;
344 0 : mpOutliner->SetControlWord(nCntrl);
345 :
346 0 : Engine()->SetModifyHdl( Link() );
347 0 : Engine()->EnableUndo( sal_False );
348 :
349 0 : Engine()->ClearModifyFlag();
350 0 : Engine()->GetUndoManager().Clear();
351 0 : Engine()->EnableUndo( sal_True );
352 0 : Engine()->SetModifyHdl( LINK( this, AnnotationWindow, ModifyHdl ) );
353 :
354 0 : Invalidate();
355 :
356 0 : SetLanguage(GetLanguage());
357 :
358 0 : mpMeta->Show();
359 0 : mpVScrollbar->Show();
360 0 : mpTextWindow->Show();
361 0 : }
362 :
363 0 : void AnnotationWindow::StartEdit()
364 : {
365 0 : getView()->SetSelection(ESelection(EE_PARA_MAX_COUNT,EE_TEXTPOS_MAX_COUNT,EE_PARA_MAX_COUNT,EE_TEXTPOS_MAX_COUNT));
366 0 : getView()->ShowCursor();
367 0 : }
368 :
369 0 : void AnnotationWindow::Rescale()
370 : {
371 0 : MapMode aMode(MAP_100TH_MM);
372 0 : aMode.SetOrigin( Point() );
373 0 : mpOutliner->SetRefMapMode( aMode );
374 0 : SetMapMode( aMode );
375 0 : mpTextWindow->SetMapMode( aMode );
376 0 : if ( mpMeta )
377 : {
378 0 : Font aFont( mpMeta->GetSettings().GetStyleSettings().GetFieldFont() );
379 0 : sal_Int32 nHeight = aFont.GetHeight();
380 0 : nHeight = nHeight * aMode.GetScaleY().GetNumerator() / aMode.GetScaleY().GetDenominator();
381 0 : aFont.SetHeight( nHeight );
382 0 : mpMeta->SetControlFont( aFont );
383 0 : }
384 0 : }
385 :
386 0 : void AnnotationWindow::DoResize()
387 : {
388 0 : unsigned long aWidth = GetSizePixel().Width();
389 0 : long aHeight = GetSizePixel().Height() - POSTIT_META_HEIGHT;
390 :
391 0 : mpOutliner->SetPaperSize( PixelToLogic( Size(aWidth,aHeight) ) ) ;
392 0 : long aTextHeight = LogicToPixel( mpOutliner->CalcTextSize()).Height();
393 :
394 0 : if( aTextHeight > aHeight )
395 : { // we need vertical scrollbars and have to reduce the width
396 0 : aWidth -= GetScrollbarWidth();
397 0 : mpVScrollbar->Show();
398 : }
399 : else
400 : {
401 0 : mpVScrollbar->Hide();
402 : }
403 :
404 0 : mpTextWindow->setPosSizePixel(0,0,aWidth, aHeight);
405 :
406 0 : if( mbReadonly )
407 0 : mpMeta->setPosSizePixel(0,aHeight,GetSizePixel().Width(),POSTIT_META_HEIGHT);
408 : else
409 0 : mpMeta->setPosSizePixel(0,aHeight,GetSizePixel().Width()-METABUTTON_AREA_WIDTH,POSTIT_META_HEIGHT);
410 :
411 0 : mpOutliner->SetPaperSize( PixelToLogic( Size(aWidth,aHeight) ) ) ;
412 0 : mpOutlinerView->SetOutputArea( PixelToLogic( Rectangle(0,0,aWidth,aHeight) ) );
413 0 : if (!mpVScrollbar->IsVisible())
414 : { // if we do not have a scrollbar anymore, we want to see the complete text
415 0 : mpOutlinerView->SetVisArea( PixelToLogic( Rectangle(0,0,aWidth,aHeight) ) );
416 : }
417 0 : mpVScrollbar->setPosSizePixel( 0 + aWidth, 0, GetScrollbarWidth(), aHeight );
418 0 : mpVScrollbar->SetVisibleSize( PixelToLogic(Size(0,aHeight)).Height() );
419 0 : mpVScrollbar->SetPageSize( PixelToLogic(Size(0,aHeight)).Height() * 8 / 10 );
420 0 : mpVScrollbar->SetLineSize( mpOutliner->GetTextHeight() / 10 );
421 0 : SetScrollbar();
422 0 : mpVScrollbar->SetRange( Range(0, mpOutliner->GetTextHeight()));
423 :
424 0 : Point aPos( mpMeta->GetPosPixel());
425 0 : Point aBase( aPos.X() + aPos.X() + GetSizePixel().Width(), aPos.Y() );
426 0 : Point aLeft = PixelToLogic( Point( aBase.X() - (METABUTTON_WIDTH+5), aBase.Y()+17 ) );
427 0 : Point aRight = PixelToLogic( Point( aBase.X() - (METABUTTON_WIDTH-1), aBase.Y()+17 ) );
428 0 : Point aBottom = PixelToLogic( Point( aBase.X() - (METABUTTON_WIDTH+2), aBase.Y()+20 ) );
429 :
430 0 : maPopupTriangle.clear();
431 0 : maPopupTriangle.append(basegfx::B2DPoint(aLeft.X(),aLeft.Y()));
432 0 : maPopupTriangle.append(basegfx::B2DPoint(aRight.X(),aRight.Y()));
433 0 : maPopupTriangle.append(basegfx::B2DPoint(aBottom.X(),aBottom.Y()));
434 0 : maPopupTriangle.setClosed(true);
435 : maRectMetaButton = PixelToLogic( Rectangle( Point(
436 0 : aPos.X()+GetSizePixel().Width()-(METABUTTON_WIDTH+10),
437 0 : aPos.Y()+5 ),
438 0 : Size( METABUTTON_WIDTH, METABUTTON_HEIGHT ) ) );
439 :
440 0 : }
441 :
442 0 : void AnnotationWindow::SetSizePixel( const Size& rNewSize )
443 : {
444 0 : Window::SetSizePixel(rNewSize);
445 0 : }
446 :
447 0 : void AnnotationWindow::SetScrollbar()
448 : {
449 0 : mpVScrollbar->SetThumbPos( mpOutlinerView->GetVisArea().Top()+ mpOutlinerView->GetEditView().GetCursor()->GetOffsetY());
450 0 : }
451 :
452 0 : void AnnotationWindow::ResizeIfNeccessary(long aOldHeight, long aNewHeight)
453 : {
454 0 : if (aOldHeight != aNewHeight)
455 : {
456 0 : DoResize();
457 0 : Invalidate();
458 : }
459 : else
460 : {
461 0 : SetScrollbar();
462 : }
463 0 : }
464 :
465 0 : void AnnotationWindow::SetLanguage(const SvxLanguageItem &aNewItem)
466 : {
467 0 : Engine()->SetModifyHdl( Link() );
468 0 : ESelection aOld = getView()->GetSelection();
469 :
470 0 : ESelection aNewSelection( 0, 0, Engine()->GetParagraphCount()-1, EE_TEXTPOS_ALL );
471 0 : getView()->SetSelection( aNewSelection );
472 0 : SfxItemSet aEditAttr(getView()->GetAttribs());
473 0 : aEditAttr.Put(aNewItem);
474 0 : getView()->SetAttribs( aEditAttr );
475 :
476 0 : getView()->SetSelection(aOld);
477 0 : Engine()->SetModifyHdl( LINK( this, AnnotationWindow, ModifyHdl ) );
478 :
479 0 : Invalidate();
480 0 : }
481 :
482 0 : void AnnotationWindow::ToggleInsMode()
483 : {
484 0 : if( mpOutlinerView )
485 : {
486 0 : SfxBindings &rBnd = mpDocShell->GetViewShell()->GetViewFrame()->GetBindings();
487 0 : rBnd.Invalidate(SID_ATTR_INSERT);
488 0 : rBnd.Update(SID_ATTR_INSERT);
489 : }
490 0 : }
491 :
492 0 : long AnnotationWindow::GetPostItTextHeight()
493 : {
494 0 : return mpOutliner ? LogicToPixel(mpOutliner->CalcTextSize()).Height() : 0;
495 : }
496 :
497 0 : IMPL_LINK(AnnotationWindow, ScrollHdl, ScrollBar*, pScroll)
498 : {
499 0 : long nDiff = getView()->GetEditView().GetVisArea().Top() - pScroll->GetThumbPos();
500 0 : getView()->Scroll( 0, nDiff );
501 0 : return 0;
502 : }
503 :
504 0 : IMPL_LINK_NOARG(AnnotationWindow, ModifyHdl)
505 : {
506 0 : return 0;
507 : }
508 :
509 0 : sal_Int32 AnnotationWindow::GetScrollbarWidth()
510 : {
511 0 : return 16;
512 : }
513 :
514 0 : SvxLanguageItem AnnotationWindow::GetLanguage(void)
515 : {
516 0 : return SvxLanguageItem( Doc()->GetLanguage( EE_CHAR_LANGUAGE ), SID_ATTR_LANGUAGE );
517 : }
518 :
519 : // --------------------------------------------------------------------
520 :
521 0 : TextApiObject* getTextApiObject( const Reference< XAnnotation >& xAnnotation )
522 : {
523 0 : if( xAnnotation.is() )
524 : {
525 0 : Reference< XText > xText( xAnnotation->getTextRange() );
526 0 : return TextApiObject::getImplementation( xText );
527 : }
528 0 : return 0;
529 : }
530 :
531 : // --------------------------------------------------------------------
532 :
533 0 : void AnnotationWindow::setAnnotation( const Reference< XAnnotation >& xAnnotation, bool bGrabFocus )
534 : {
535 0 : if( (xAnnotation != mxAnnotation) && xAnnotation.is() )
536 : {
537 0 : mxAnnotation = xAnnotation;
538 :
539 0 : SetColor();
540 :
541 0 : SvtUserOptions aUserOptions;
542 0 : mbProtected = aUserOptions.GetFullName() != xAnnotation->getAuthor();
543 :
544 0 : Engine()->Clear();
545 0 : TextApiObject* pTextApi = getTextApiObject( mxAnnotation );
546 :
547 0 : if( pTextApi )
548 : {
549 0 : std::auto_ptr< OutlinerParaObject > pOPO( pTextApi->CreateText() );
550 0 : Engine()->SetText( *pOPO.get() );
551 : }
552 :
553 0 : Engine()->SetModifyHdl( LINK( this, AnnotationWindow, ModifyHdl ) );
554 0 : Engine()->ClearModifyFlag();
555 0 : Engine()->GetUndoManager().Clear();
556 :
557 0 : Invalidate();
558 :
559 0 : OUString sMeta( xAnnotation->getAuthor() );
560 0 : OUString sDateTime( getAnnotationDateTimeString(xAnnotation) );
561 :
562 0 : if( !sDateTime.isEmpty() )
563 : {
564 0 : if( !sMeta.isEmpty() )
565 0 : sMeta += "\n";
566 :
567 0 : sMeta += sDateTime;
568 : }
569 0 : mpMeta->SetText(sMeta);
570 :
571 0 : if( bGrabFocus )
572 0 : GrabFocus();
573 : }
574 0 : }
575 :
576 0 : void AnnotationWindow::SetColor()
577 : {
578 0 : sal_uInt16 nAuthorIdx = mpDoc->GetAnnotationAuthorIndex( mxAnnotation->getAuthor() );
579 :
580 0 : const bool bHighContrast = Application::GetSettings().GetStyleSettings().GetHighContrastMode();
581 0 : if( bHighContrast )
582 : {
583 0 : StyleSettings aStyleSettings = GetSettings().GetStyleSettings();
584 :
585 0 : maColor = aStyleSettings.GetWindowColor();
586 0 : maColorDark = maColor;
587 0 : maColorLight = aStyleSettings.GetWindowTextColor();
588 : }
589 : else
590 : {
591 0 : maColor = mrManager.GetColor( nAuthorIdx );
592 0 : maColorDark = mrManager.GetColorDark( nAuthorIdx );
593 0 : maColorLight = mrManager.GetColorLight( nAuthorIdx );
594 : }
595 :
596 0 : mpOutlinerView->SetBackgroundColor(maColor);
597 0 : Engine()->SetBackgroundColor(maColor);
598 :
599 : {
600 0 : SvtAccessibilityOptions aOptions;
601 0 : Engine()->ForceAutoColor( bHighContrast || aOptions.GetIsAutomaticFontColor() );
602 : }
603 :
604 0 : mpMeta->SetControlBackground(maColor);
605 0 : AllSettings aSettings = mpMeta->GetSettings();
606 0 : StyleSettings aStyleSettings = aSettings.GetStyleSettings();
607 0 : aStyleSettings.SetFieldTextColor( bHighContrast ? maColorLight : maColorDark);
608 0 : aSettings.SetStyleSettings(aStyleSettings);
609 0 : mpMeta->SetSettings(aSettings);
610 :
611 0 : AllSettings aSettings2 = mpVScrollbar->GetSettings();
612 0 : StyleSettings aStyleSettings2 = aSettings2.GetStyleSettings();
613 0 : aStyleSettings2.SetButtonTextColor(Color(0,0,0));
614 0 : aStyleSettings2.SetCheckedColor(maColorLight); //hintergund
615 0 : aStyleSettings2.SetShadowColor(maColorDark);
616 0 : aStyleSettings2.SetFaceColor(maColor);
617 0 : aSettings2.SetStyleSettings(aStyleSettings2);
618 0 : mpVScrollbar->SetSettings(aSettings2);
619 0 : }
620 :
621 0 : void AnnotationWindow::Deactivate()
622 : {
623 0 : Reference< XAnnotation > xAnnotation( mxAnnotation );
624 :
625 : // write changed text back to annotation
626 0 : if ( Engine()->IsModified() )
627 : {
628 0 : TextApiObject* pTextApi = getTextApiObject( xAnnotation );
629 :
630 0 : if( pTextApi )
631 : {
632 0 : OutlinerParaObject* pOPO = Engine()->CreateParaObject();
633 0 : if( pOPO )
634 : {
635 0 : if( mpDoc->IsUndoEnabled() )
636 0 : mpDoc->BegUndo( String( SdResId( STR_ANNOTATION_UNDO_EDIT ) ) );
637 :
638 0 : pTextApi->SetText( *pOPO );
639 0 : delete pOPO;
640 :
641 : // set current time to changed annotation
642 0 : xAnnotation->setDateTime( getCurrentDateTime() );
643 :
644 0 : if( mpDoc->IsUndoEnabled() )
645 0 : mpDoc->EndUndo();
646 :
647 0 : DocView()->GetDocSh()->SetModified(sal_True);
648 : }
649 :
650 : }
651 : }
652 0 : Engine()->ClearModifyFlag();
653 :
654 0 : Engine()->GetUndoManager().Clear();
655 0 : }
656 :
657 0 : void AnnotationWindow::Paint( const Rectangle& rRect)
658 : {
659 0 : FloatingWindow::Paint( rRect );
660 :
661 0 : if(mpMeta->IsVisible() && !mbReadonly)
662 : {
663 0 : const bool bHighContrast = Application::GetSettings().GetStyleSettings().GetHighContrastMode();
664 : //draw left over space
665 0 : if ( bHighContrast )
666 0 : SetFillColor(COL_BLACK);
667 : else
668 0 : SetFillColor(maColor);
669 0 : SetLineColor();
670 0 : DrawRect(PixelToLogic(Rectangle(Point(mpMeta->GetPosPixel().X()+mpMeta->GetSizePixel().Width(),mpMeta->GetPosPixel().Y()),Size(METABUTTON_AREA_WIDTH,mpMeta->GetSizePixel().Height()))));
671 :
672 0 : if ( bHighContrast )
673 : {
674 : //draw rect around button
675 0 : SetFillColor(COL_BLACK);
676 0 : SetLineColor(COL_WHITE);
677 : }
678 : else
679 : {
680 : //draw button
681 0 : Gradient aGradient;
682 0 : if (mbMouseOverButton)
683 0 : aGradient = Gradient(GradientStyle_LINEAR,ColorFromAlphaColor(80,maColorDark,maColor),ColorFromAlphaColor(15,maColorDark,maColor));
684 : else
685 0 : aGradient = Gradient(GradientStyle_LINEAR,ColorFromAlphaColor(15,maColorDark,maColor),ColorFromAlphaColor(80,maColorDark,maColor));
686 0 : DrawGradient(maRectMetaButton,aGradient);
687 : //draw rect around button
688 0 : SetFillColor();
689 0 : SetLineColor(ColorFromAlphaColor(90,maColorDark,maColor));
690 : }
691 0 : DrawRect(maRectMetaButton);
692 :
693 : //draw arrow
694 0 : if( bHighContrast )
695 0 : SetFillColor(COL_WHITE);
696 : else
697 0 : SetFillColor(COL_BLACK);
698 0 : SetLineColor();
699 0 : DrawPolygon(Polygon(maPopupTriangle));
700 : }
701 0 : }
702 :
703 0 : void AnnotationWindow::MouseMove( const MouseEvent& rMEvt )
704 : {
705 0 : if( !mbReadonly )
706 : {
707 0 : if (maRectMetaButton.IsInside(PixelToLogic(rMEvt.GetPosPixel())))
708 : {
709 0 : if (!mbMouseOverButton)
710 : {
711 0 : Invalidate(maRectMetaButton);
712 0 : mbMouseOverButton = true;
713 : }
714 : }
715 : else
716 : {
717 0 : if (mbMouseOverButton)
718 : {
719 0 : Invalidate(maRectMetaButton);
720 0 : mbMouseOverButton = false;
721 : }
722 : }
723 : }
724 0 : }
725 :
726 0 : void AnnotationWindow::MouseButtonDown( const MouseEvent& rMEvt )
727 : {
728 0 : if (!mbReadonly && maRectMetaButton.IsInside(PixelToLogic(rMEvt.GetPosPixel())) && rMEvt.IsLeft())
729 : {
730 : // context menu
731 0 : Rectangle aRect(LogicToPixel(maRectMetaButton.BottomLeft()),LogicToPixel(maRectMetaButton.BottomLeft()));
732 0 : mrManager.ExecuteAnnotationContextMenu( mxAnnotation, (::Window*)this, aRect, true );
733 : }
734 0 : }
735 :
736 0 : void AnnotationWindow::Command( const CommandEvent& rCEvt )
737 : {
738 0 : if ( rCEvt.GetCommand() == COMMAND_CONTEXTMENU )
739 : {
740 0 : if( mpMeta->IsVisible() &&(mpMeta->GetPosPixel().Y() < rCEvt.GetMousePosPixel().Y()) )
741 0 : return;
742 0 : mrManager.ExecuteAnnotationContextMenu( mxAnnotation, this, Rectangle(rCEvt.GetMousePosPixel(),Size(1,1)) );
743 : }
744 : else
745 : {
746 0 : FloatingWindow::Command(rCEvt);
747 : }
748 : }
749 :
750 0 : void AnnotationWindow::GetFocus()
751 : {
752 0 : if( mpTextWindow )
753 0 : mpTextWindow->GrabFocus();
754 : else
755 0 : FloatingWindow::GetFocus();
756 0 : }
757 :
758 0 : void AnnotationWindow::ExecuteSlot( sal_uInt16 nSID )
759 : {
760 0 : if( nSID == SID_COPY )
761 : {
762 0 : getView()->Copy();
763 : }
764 0 : else if( nSID == SID_PASTE )
765 : {
766 0 : getView()->PasteSpecial();
767 0 : DoResize();
768 : }
769 : else
770 : {
771 0 : SfxItemSet aEditAttr(getView()->GetAttribs());
772 0 : SfxItemSet aNewAttr(mpOutliner->GetEmptyItemSet());
773 :
774 0 : switch( nSID )
775 : {
776 : case SID_ATTR_CHAR_WEIGHT:
777 : {
778 0 : FontWeight eFW = ( (const SvxWeightItem&) aEditAttr.Get( EE_CHAR_WEIGHT ) ).GetWeight();
779 0 : aNewAttr.Put( SvxWeightItem( eFW == WEIGHT_NORMAL ? WEIGHT_BOLD : WEIGHT_NORMAL, EE_CHAR_WEIGHT ) );
780 : }
781 0 : break;
782 : case SID_ATTR_CHAR_POSTURE:
783 : {
784 0 : FontItalic eFI = ( (const SvxPostureItem&) aEditAttr.Get( EE_CHAR_ITALIC ) ).GetPosture();
785 0 : aNewAttr.Put( SvxPostureItem( eFI == ITALIC_NORMAL ? ITALIC_NONE : ITALIC_NORMAL, EE_CHAR_ITALIC ) );
786 : }
787 0 : break;
788 : case SID_ATTR_CHAR_UNDERLINE:
789 : {
790 0 : FontUnderline eFU = ( (const SvxUnderlineItem&) aEditAttr. Get( EE_CHAR_UNDERLINE ) ).GetLineStyle();
791 0 : aNewAttr.Put( SvxUnderlineItem( eFU == UNDERLINE_SINGLE ? UNDERLINE_NONE : UNDERLINE_SINGLE, EE_CHAR_UNDERLINE ) );
792 : }
793 0 : break;
794 : case SID_ATTR_CHAR_STRIKEOUT:
795 : {
796 0 : FontStrikeout eFSO = ( ( (const SvxCrossedOutItem&) aEditAttr.Get( EE_CHAR_STRIKEOUT ) ).GetStrikeout() );
797 0 : aNewAttr.Put( SvxCrossedOutItem( eFSO == STRIKEOUT_SINGLE ? STRIKEOUT_NONE : STRIKEOUT_SINGLE, EE_CHAR_STRIKEOUT ) );
798 : }
799 0 : break;
800 : }
801 0 : getView()->SetAttribs( aNewAttr );
802 : }
803 0 : }
804 :
805 33 : }
806 :
807 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|