bump product version to 4.1.6.2
[LibreOffice.git] / sd / source / ui / annotations / annotationwindow.cxx
blob876853171cc05a0b715bc5ed89479778df3adf4b
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
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>
54 #include <linguistic/lngprops.hxx>
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>
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>
72 #include <basegfx/matrix/b2dhommatrix.hxx>
73 #include <basegfx/tuple/b2dtuple.hxx>
74 #include <basegfx/polygon/b2dpolygontools.hxx>
76 #include "annotations.hrc"
77 #include "annotationwindow.hxx"
78 #include "annotationmanagerimpl.hxx"
80 #include "DrawDocShell.hxx"
81 #include "ViewShell.hxx"
82 #include "drawdoc.hxx"
83 #include "View.hxx"
84 #include "textapi.hxx"
85 #include "sdresid.hxx"
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;
93 #define METABUTTON_WIDTH 16
94 #define METABUTTON_HEIGHT 18
95 #define METABUTTON_AREA_WIDTH 30
96 #define POSTIT_META_HEIGHT (sal_Int32) 30
98 namespace sd {
100 extern OUString getAnnotationDateTimeString( const Reference< XAnnotation >& xAnnotation );
101 extern SfxItemPool* GetAnnotationPool();
102 extern com::sun::star::util::DateTime getCurrentDateTime();
104 Color ColorFromAlphaColor(sal_uInt8 aTransparency, Color &aFront, Color &aBack )
106 return Color((sal_uInt8)(aFront.GetRed() * aTransparency/(double)255 + aBack.GetRed() * (1-aTransparency/(double)255)),
107 (sal_uInt8)(aFront.GetGreen() * aTransparency/(double)255 + aBack.GetGreen() * (1-aTransparency/(double)255)),
108 (sal_uInt8)(aFront.GetBlue() * aTransparency/(double)255 + aBack.GetBlue() * (1-aTransparency/(double)255)));
111 /************ AnnotationTextWindow **********************************/
113 AnnotationTextWindow::AnnotationTextWindow( AnnotationWindow* pParent, WinBits nBits )
114 : Control(pParent, nBits)
115 , mpOutlinerView(0)
116 , mpAnnotationWindow( pParent )
120 AnnotationTextWindow::~AnnotationTextWindow()
124 void AnnotationTextWindow::Paint( const Rectangle& rRect)
126 const bool bHighContrast = Application::GetSettings().GetStyleSettings().GetHighContrastMode();
127 if ( !bHighContrast )
129 DrawGradient(Rectangle(Point(0,0),PixelToLogic(GetSizePixel())),
130 Gradient(GradientStyle_LINEAR,mpAnnotationWindow->maColorLight,mpAnnotationWindow->maColor));
133 if( mpOutlinerView )
135 Color aBackgroundColor( mpAnnotationWindow->maColor );
136 if( bHighContrast )
138 aBackgroundColor = GetSettings().GetStyleSettings().GetWindowColor();
141 mpOutlinerView->SetBackgroundColor( aBackgroundColor );
143 mpOutlinerView->Paint( rRect );
147 void AnnotationTextWindow::KeyInput( const KeyEvent& rKeyEvt )
149 const KeyCode& rKeyCode = rKeyEvt.GetKeyCode();
150 sal_uInt16 nKey = rKeyCode.GetCode();
152 if ((rKeyCode.IsMod1() && rKeyCode.IsMod2()) && ((nKey == KEY_PAGEUP) || (nKey == KEY_PAGEDOWN)))
154 SfxDispatcher* pDispatcher = mpAnnotationWindow->DocShell()->GetViewShell()->GetViewFrame()->GetDispatcher();
155 if( pDispatcher )
156 pDispatcher->Execute( nKey == KEY_PAGEDOWN ? SID_NEXT_POSTIT : SID_PREVIOUS_POSTIT );
158 else if (nKey == KEY_INSERT)
160 if (!rKeyCode.IsMod1() && !rKeyCode.IsMod2())
161 mpAnnotationWindow->ToggleInsMode();
163 else
165 long aOldHeight = mpAnnotationWindow->GetPostItTextHeight();
166 bool bDone = false;
168 /// HACK: need to switch off processing of Undo/Redo in Outliner
169 if ( !( (nKey == KEY_Z || nKey == KEY_Y) && rKeyCode.IsMod1()) )
171 bool bIsProtected = mpAnnotationWindow->IsProtected();
172 if (!bIsProtected || (bIsProtected && !mpAnnotationWindow->Engine()->GetEditEngine().DoesKeyChangeText(rKeyEvt)) )
174 bDone = mpOutlinerView->PostKeyEvent( rKeyEvt );
176 if (bDone)
178 mpAnnotationWindow->ResizeIfNeccessary(aOldHeight,mpAnnotationWindow->GetPostItTextHeight());
180 else
182 Control::KeyInput(rKeyEvt);
187 void AnnotationTextWindow::MouseMove( const MouseEvent& rMEvt )
189 if ( mpOutlinerView )
191 mpOutlinerView->MouseMove( rMEvt );
192 SetPointer( mpOutlinerView->GetPointer( rMEvt.GetPosPixel() ) );
196 void AnnotationTextWindow::MouseButtonDown( const MouseEvent& rMEvt )
198 GrabFocus();
199 if ( mpOutlinerView )
200 mpOutlinerView->MouseButtonDown( rMEvt );
201 // todo mpOutlinerView->DocView()->GetViewFrame()->GetBindings().InvalidateAll(sal_False);
204 void AnnotationTextWindow::MouseButtonUp( const MouseEvent& rMEvt )
206 if ( mpOutlinerView )
207 mpOutlinerView->MouseButtonUp( rMEvt );
210 void AnnotationTextWindow::Command( const CommandEvent& rCEvt )
212 if ( rCEvt.GetCommand() == COMMAND_CONTEXTMENU )
214 mpAnnotationWindow->Command(rCEvt);
216 else
218 if ( mpOutlinerView )
219 mpOutlinerView->Command( rCEvt );
220 else
221 Window::Command(rCEvt);
225 void AnnotationTextWindow::GetFocus()
227 Window::GetFocus();
230 void AnnotationTextWindow::LoseFocus()
232 Window::LoseFocus();
235 OUString AnnotationTextWindow::GetSurroundingText() const
237 if( mpOutlinerView )
239 EditEngine *aEditEngine = mpOutlinerView->GetEditView().GetEditEngine();
240 if( mpOutlinerView->HasSelection() )
241 return mpOutlinerView->GetSelected();
242 else
244 ESelection aSelection = mpOutlinerView->GetEditView().GetSelection();
245 return aEditEngine->GetText(aSelection.nStartPara);
248 return OUString();
251 Selection AnnotationTextWindow::GetSurroundingTextSelection() const
253 if( mpOutlinerView )
255 if( mpOutlinerView->HasSelection() )
256 return Selection( 0, mpOutlinerView->GetSelected().Len() );
257 else
259 ESelection aSelection = mpOutlinerView->GetEditView().GetSelection();
260 return Selection( aSelection.nStartPos, aSelection.nEndPos );
263 else
264 return Selection( 0, 0 );
267 /************** AnnotationWindow***********************************++*/
269 AnnotationWindow::AnnotationWindow( AnnotationManagerImpl& rManager, DrawDocShell* pDocShell, Window* pParent )
270 : FloatingWindow(pParent, WB_SYSTEMWINDOW|WB_BORDER|WB_NEEDSFOCUS)
271 , mrManager( rManager )
272 , mpDocShell( pDocShell )
273 , mpView( pDocShell->GetViewShell()->GetView() )
274 , mpDoc( pDocShell->GetDoc() )
275 , mpOutlinerView(0)
276 , mpOutliner(0)
277 , mpVScrollbar(0)
278 , mbReadonly(pDocShell->IsReadOnly())
279 , mbProtected(false)
280 , mbMouseOverButton(false)
281 , mpTextWindow(0)
282 , mpMeta(0)
286 AnnotationWindow::~AnnotationWindow()
288 delete mpMeta;
289 delete mpOutlinerView;
290 delete mpOutliner;
291 delete mpVScrollbar;
292 delete mpTextWindow;
295 void AnnotationWindow::InitControls()
297 // actual window which holds the user text
298 mpTextWindow = new AnnotationTextWindow(this, WB_NODIALOGCONTROL);
299 mpTextWindow->SetPointer(Pointer(POINTER_TEXT));
301 // window control for author and date
302 mpMeta = new MultiLineEdit(this,0);
303 mpMeta->SetReadOnly();
304 mpMeta->SetRightToLeft(Application::GetSettings().GetLayoutRTL());
305 mpMeta->AlwaysDisableInput(true);
306 mpMeta->SetCallHandlersOnInputDisabled(true);
308 // we should leave this setting alone, but for this we need a better layout algo
309 // with variable meta size height
310 AllSettings aSettings = mpMeta->GetSettings();
311 StyleSettings aStyleSettings = aSettings.GetStyleSettings();
312 Font aFont = aStyleSettings.GetFieldFont();
313 aFont.SetHeight(8);
314 aStyleSettings.SetFieldFont(aFont);
315 aSettings.SetStyleSettings(aStyleSettings);
316 mpMeta->SetSettings(aSettings);
318 mpOutliner = new ::Outliner(GetAnnotationPool(),OUTLINERMODE_TEXTOBJECT);
319 Doc()->SetCalcFieldValueHdl( mpOutliner );
320 mpOutliner->SetUpdateMode( sal_True );
321 Rescale();
323 OutputDevice* pDev = Doc()->GetRefDevice();
324 if( pDev )
326 mpOutliner->SetRefDevice( pDev );
329 mpTextWindow->EnableRTL( sal_False );
330 mpOutlinerView = new OutlinerView ( mpOutliner, mpTextWindow );
331 mpOutliner->InsertView(mpOutlinerView );
332 mpTextWindow->SetOutlinerView(mpOutlinerView);
333 mpOutlinerView->SetOutputArea( PixelToLogic( Rectangle(0,0,1,1) ) );
335 //create Scrollbars
336 mpVScrollbar = new ScrollBar(this, WB_3DLOOK |WB_VSCROLL|WB_DRAG);
337 mpVScrollbar->EnableNativeWidget(false);
338 mpVScrollbar->EnableRTL( false );
339 mpVScrollbar->SetScrollHdl(LINK(this, AnnotationWindow, ScrollHdl));
340 mpVScrollbar->EnableDrag();
342 sal_uLong nCntrl = mpOutliner->GetControlWord();
343 nCntrl |= EE_CNTRL_PASTESPECIAL | EE_CNTRL_AUTOCORRECT | EV_CNTRL_AUTOSCROLL | EE_CNTRL_NOCOLORS;
344 mpOutliner->SetControlWord(nCntrl);
346 Engine()->SetModifyHdl( Link() );
347 Engine()->EnableUndo( sal_False );
349 Engine()->ClearModifyFlag();
350 Engine()->GetUndoManager().Clear();
351 Engine()->EnableUndo( sal_True );
352 Engine()->SetModifyHdl( LINK( this, AnnotationWindow, ModifyHdl ) );
354 Invalidate();
356 SetLanguage(GetLanguage());
358 mpMeta->Show();
359 mpVScrollbar->Show();
360 mpTextWindow->Show();
363 void AnnotationWindow::StartEdit()
365 getView()->SetSelection(ESelection(EE_PARA_MAX_COUNT,EE_TEXTPOS_MAX_COUNT,EE_PARA_MAX_COUNT,EE_TEXTPOS_MAX_COUNT));
366 getView()->ShowCursor();
369 void AnnotationWindow::Rescale()
371 MapMode aMode(MAP_100TH_MM);
372 aMode.SetOrigin( Point() );
373 mpOutliner->SetRefMapMode( aMode );
374 SetMapMode( aMode );
375 mpTextWindow->SetMapMode( aMode );
376 if ( mpMeta )
378 Font aFont( mpMeta->GetSettings().GetStyleSettings().GetFieldFont() );
379 sal_Int32 nHeight = aFont.GetHeight();
380 nHeight = nHeight * aMode.GetScaleY().GetNumerator() / aMode.GetScaleY().GetDenominator();
381 aFont.SetHeight( nHeight );
382 mpMeta->SetControlFont( aFont );
386 void AnnotationWindow::DoResize()
388 unsigned long aWidth = GetSizePixel().Width();
389 long aHeight = GetSizePixel().Height() - POSTIT_META_HEIGHT;
391 mpOutliner->SetPaperSize( PixelToLogic( Size(aWidth,aHeight) ) ) ;
392 long aTextHeight = LogicToPixel( mpOutliner->CalcTextSize()).Height();
394 if( aTextHeight > aHeight )
395 { // we need vertical scrollbars and have to reduce the width
396 aWidth -= GetScrollbarWidth();
397 mpVScrollbar->Show();
399 else
401 mpVScrollbar->Hide();
404 mpTextWindow->setPosSizePixel(0,0,aWidth, aHeight);
406 if( mbReadonly )
407 mpMeta->setPosSizePixel(0,aHeight,GetSizePixel().Width(),POSTIT_META_HEIGHT);
408 else
409 mpMeta->setPosSizePixel(0,aHeight,GetSizePixel().Width()-METABUTTON_AREA_WIDTH,POSTIT_META_HEIGHT);
411 mpOutliner->SetPaperSize( PixelToLogic( Size(aWidth,aHeight) ) ) ;
412 mpOutlinerView->SetOutputArea( PixelToLogic( Rectangle(0,0,aWidth,aHeight) ) );
413 if (!mpVScrollbar->IsVisible())
414 { // if we do not have a scrollbar anymore, we want to see the complete text
415 mpOutlinerView->SetVisArea( PixelToLogic( Rectangle(0,0,aWidth,aHeight) ) );
417 mpVScrollbar->setPosSizePixel( 0 + aWidth, 0, GetScrollbarWidth(), aHeight );
418 mpVScrollbar->SetVisibleSize( PixelToLogic(Size(0,aHeight)).Height() );
419 mpVScrollbar->SetPageSize( PixelToLogic(Size(0,aHeight)).Height() * 8 / 10 );
420 mpVScrollbar->SetLineSize( mpOutliner->GetTextHeight() / 10 );
421 SetScrollbar();
422 mpVScrollbar->SetRange( Range(0, mpOutliner->GetTextHeight()));
424 Point aPos( mpMeta->GetPosPixel());
425 Point aBase( aPos.X() + aPos.X() + GetSizePixel().Width(), aPos.Y() );
426 Point aLeft = PixelToLogic( Point( aBase.X() - (METABUTTON_WIDTH+5), aBase.Y()+17 ) );
427 Point aRight = PixelToLogic( Point( aBase.X() - (METABUTTON_WIDTH-1), aBase.Y()+17 ) );
428 Point aBottom = PixelToLogic( Point( aBase.X() - (METABUTTON_WIDTH+2), aBase.Y()+20 ) );
430 maPopupTriangle.clear();
431 maPopupTriangle.append(basegfx::B2DPoint(aLeft.X(),aLeft.Y()));
432 maPopupTriangle.append(basegfx::B2DPoint(aRight.X(),aRight.Y()));
433 maPopupTriangle.append(basegfx::B2DPoint(aBottom.X(),aBottom.Y()));
434 maPopupTriangle.setClosed(true);
435 maRectMetaButton = PixelToLogic( Rectangle( Point(
436 aPos.X()+GetSizePixel().Width()-(METABUTTON_WIDTH+10),
437 aPos.Y()+5 ),
438 Size( METABUTTON_WIDTH, METABUTTON_HEIGHT ) ) );
442 void AnnotationWindow::SetSizePixel( const Size& rNewSize )
444 Window::SetSizePixel(rNewSize);
447 void AnnotationWindow::SetScrollbar()
449 mpVScrollbar->SetThumbPos( mpOutlinerView->GetVisArea().Top()+ mpOutlinerView->GetEditView().GetCursor()->GetOffsetY());
452 void AnnotationWindow::ResizeIfNeccessary(long aOldHeight, long aNewHeight)
454 if (aOldHeight != aNewHeight)
456 DoResize();
457 Invalidate();
459 else
461 SetScrollbar();
465 void AnnotationWindow::SetLanguage(const SvxLanguageItem &aNewItem)
467 Engine()->SetModifyHdl( Link() );
468 ESelection aOld = getView()->GetSelection();
470 ESelection aNewSelection( 0, 0, Engine()->GetParagraphCount()-1, EE_TEXTPOS_ALL );
471 getView()->SetSelection( aNewSelection );
472 SfxItemSet aEditAttr(getView()->GetAttribs());
473 aEditAttr.Put(aNewItem);
474 getView()->SetAttribs( aEditAttr );
476 getView()->SetSelection(aOld);
477 Engine()->SetModifyHdl( LINK( this, AnnotationWindow, ModifyHdl ) );
479 Invalidate();
482 void AnnotationWindow::ToggleInsMode()
484 if( mpOutlinerView )
486 SfxBindings &rBnd = mpDocShell->GetViewShell()->GetViewFrame()->GetBindings();
487 rBnd.Invalidate(SID_ATTR_INSERT);
488 rBnd.Update(SID_ATTR_INSERT);
492 long AnnotationWindow::GetPostItTextHeight()
494 return mpOutliner ? LogicToPixel(mpOutliner->CalcTextSize()).Height() : 0;
497 IMPL_LINK(AnnotationWindow, ScrollHdl, ScrollBar*, pScroll)
499 long nDiff = getView()->GetEditView().GetVisArea().Top() - pScroll->GetThumbPos();
500 getView()->Scroll( 0, nDiff );
501 return 0;
504 IMPL_LINK_NOARG(AnnotationWindow, ModifyHdl)
506 return 0;
509 sal_Int32 AnnotationWindow::GetScrollbarWidth()
511 return 16;
514 SvxLanguageItem AnnotationWindow::GetLanguage(void)
516 return SvxLanguageItem( Doc()->GetLanguage( EE_CHAR_LANGUAGE ), SID_ATTR_LANGUAGE );
519 // --------------------------------------------------------------------
521 TextApiObject* getTextApiObject( const Reference< XAnnotation >& xAnnotation )
523 if( xAnnotation.is() )
525 Reference< XText > xText( xAnnotation->getTextRange() );
526 return TextApiObject::getImplementation( xText );
528 return 0;
531 // --------------------------------------------------------------------
533 void AnnotationWindow::setAnnotation( const Reference< XAnnotation >& xAnnotation, bool bGrabFocus )
535 if( (xAnnotation != mxAnnotation) && xAnnotation.is() )
537 mxAnnotation = xAnnotation;
539 SetColor();
541 SvtUserOptions aUserOptions;
542 mbProtected = aUserOptions.GetFullName() != xAnnotation->getAuthor();
544 Engine()->Clear();
545 TextApiObject* pTextApi = getTextApiObject( mxAnnotation );
547 if( pTextApi )
549 std::auto_ptr< OutlinerParaObject > pOPO( pTextApi->CreateText() );
550 Engine()->SetText( *pOPO.get() );
553 Engine()->SetModifyHdl( LINK( this, AnnotationWindow, ModifyHdl ) );
554 Engine()->ClearModifyFlag();
555 Engine()->GetUndoManager().Clear();
557 Invalidate();
559 OUString sMeta( xAnnotation->getAuthor() );
560 OUString sDateTime( getAnnotationDateTimeString(xAnnotation) );
562 if( !sDateTime.isEmpty() )
564 if( !sMeta.isEmpty() )
565 sMeta += "\n";
567 sMeta += sDateTime;
569 mpMeta->SetText(sMeta);
571 if( bGrabFocus )
572 GrabFocus();
576 void AnnotationWindow::SetColor()
578 sal_uInt16 nAuthorIdx = mpDoc->GetAnnotationAuthorIndex( mxAnnotation->getAuthor() );
580 const bool bHighContrast = Application::GetSettings().GetStyleSettings().GetHighContrastMode();
581 if( bHighContrast )
583 StyleSettings aStyleSettings = GetSettings().GetStyleSettings();
585 maColor = aStyleSettings.GetWindowColor();
586 maColorDark = maColor;
587 maColorLight = aStyleSettings.GetWindowTextColor();
589 else
591 maColor = mrManager.GetColor( nAuthorIdx );
592 maColorDark = mrManager.GetColorDark( nAuthorIdx );
593 maColorLight = mrManager.GetColorLight( nAuthorIdx );
596 mpOutlinerView->SetBackgroundColor(maColor);
597 Engine()->SetBackgroundColor(maColor);
600 SvtAccessibilityOptions aOptions;
601 Engine()->ForceAutoColor( bHighContrast || aOptions.GetIsAutomaticFontColor() );
604 mpMeta->SetControlBackground(maColor);
605 AllSettings aSettings = mpMeta->GetSettings();
606 StyleSettings aStyleSettings = aSettings.GetStyleSettings();
607 aStyleSettings.SetFieldTextColor( bHighContrast ? maColorLight : maColorDark);
608 aSettings.SetStyleSettings(aStyleSettings);
609 mpMeta->SetSettings(aSettings);
611 AllSettings aSettings2 = mpVScrollbar->GetSettings();
612 StyleSettings aStyleSettings2 = aSettings2.GetStyleSettings();
613 aStyleSettings2.SetButtonTextColor(Color(0,0,0));
614 aStyleSettings2.SetCheckedColor(maColorLight); //hintergund
615 aStyleSettings2.SetShadowColor(maColorDark);
616 aStyleSettings2.SetFaceColor(maColor);
617 aSettings2.SetStyleSettings(aStyleSettings2);
618 mpVScrollbar->SetSettings(aSettings2);
621 void AnnotationWindow::Deactivate()
623 Reference< XAnnotation > xAnnotation( mxAnnotation );
625 // write changed text back to annotation
626 if ( Engine()->IsModified() )
628 TextApiObject* pTextApi = getTextApiObject( xAnnotation );
630 if( pTextApi )
632 OutlinerParaObject* pOPO = Engine()->CreateParaObject();
633 if( pOPO )
635 if( mpDoc->IsUndoEnabled() )
636 mpDoc->BegUndo( String( SdResId( STR_ANNOTATION_UNDO_EDIT ) ) );
638 pTextApi->SetText( *pOPO );
639 delete pOPO;
641 // set current time to changed annotation
642 xAnnotation->setDateTime( getCurrentDateTime() );
644 if( mpDoc->IsUndoEnabled() )
645 mpDoc->EndUndo();
647 DocView()->GetDocSh()->SetModified(sal_True);
652 Engine()->ClearModifyFlag();
654 Engine()->GetUndoManager().Clear();
657 void AnnotationWindow::Paint( const Rectangle& rRect)
659 FloatingWindow::Paint( rRect );
661 if(mpMeta->IsVisible() && !mbReadonly)
663 const bool bHighContrast = Application::GetSettings().GetStyleSettings().GetHighContrastMode();
664 //draw left over space
665 if ( bHighContrast )
666 SetFillColor(COL_BLACK);
667 else
668 SetFillColor(maColor);
669 SetLineColor();
670 DrawRect(PixelToLogic(Rectangle(Point(mpMeta->GetPosPixel().X()+mpMeta->GetSizePixel().Width(),mpMeta->GetPosPixel().Y()),Size(METABUTTON_AREA_WIDTH,mpMeta->GetSizePixel().Height()))));
672 if ( bHighContrast )
674 //draw rect around button
675 SetFillColor(COL_BLACK);
676 SetLineColor(COL_WHITE);
678 else
680 //draw button
681 Gradient aGradient;
682 if (mbMouseOverButton)
683 aGradient = Gradient(GradientStyle_LINEAR,ColorFromAlphaColor(80,maColorDark,maColor),ColorFromAlphaColor(15,maColorDark,maColor));
684 else
685 aGradient = Gradient(GradientStyle_LINEAR,ColorFromAlphaColor(15,maColorDark,maColor),ColorFromAlphaColor(80,maColorDark,maColor));
686 DrawGradient(maRectMetaButton,aGradient);
687 //draw rect around button
688 SetFillColor();
689 SetLineColor(ColorFromAlphaColor(90,maColorDark,maColor));
691 DrawRect(maRectMetaButton);
693 //draw arrow
694 if( bHighContrast )
695 SetFillColor(COL_WHITE);
696 else
697 SetFillColor(COL_BLACK);
698 SetLineColor();
699 DrawPolygon(Polygon(maPopupTriangle));
703 void AnnotationWindow::MouseMove( const MouseEvent& rMEvt )
705 if( !mbReadonly )
707 if (maRectMetaButton.IsInside(PixelToLogic(rMEvt.GetPosPixel())))
709 if (!mbMouseOverButton)
711 Invalidate(maRectMetaButton);
712 mbMouseOverButton = true;
715 else
717 if (mbMouseOverButton)
719 Invalidate(maRectMetaButton);
720 mbMouseOverButton = false;
726 void AnnotationWindow::MouseButtonDown( const MouseEvent& rMEvt )
728 if (!mbReadonly && maRectMetaButton.IsInside(PixelToLogic(rMEvt.GetPosPixel())) && rMEvt.IsLeft())
730 // context menu
731 Rectangle aRect(LogicToPixel(maRectMetaButton.BottomLeft()),LogicToPixel(maRectMetaButton.BottomLeft()));
732 mrManager.ExecuteAnnotationContextMenu( mxAnnotation, (::Window*)this, aRect, true );
736 void AnnotationWindow::Command( const CommandEvent& rCEvt )
738 if ( rCEvt.GetCommand() == COMMAND_CONTEXTMENU )
740 if( mpMeta->IsVisible() &&(mpMeta->GetPosPixel().Y() < rCEvt.GetMousePosPixel().Y()) )
741 return;
742 mrManager.ExecuteAnnotationContextMenu( mxAnnotation, this, Rectangle(rCEvt.GetMousePosPixel(),Size(1,1)) );
744 else
746 FloatingWindow::Command(rCEvt);
750 void AnnotationWindow::GetFocus()
752 if( mpTextWindow )
753 mpTextWindow->GrabFocus();
754 else
755 FloatingWindow::GetFocus();
758 void AnnotationWindow::ExecuteSlot( sal_uInt16 nSID )
760 if( nSID == SID_COPY )
762 getView()->Copy();
764 else if( nSID == SID_PASTE )
766 getView()->PasteSpecial();
767 DoResize();
769 else
771 SfxItemSet aEditAttr(getView()->GetAttribs());
772 SfxItemSet aNewAttr(mpOutliner->GetEmptyItemSet());
774 switch( nSID )
776 case SID_ATTR_CHAR_WEIGHT:
778 FontWeight eFW = ( (const SvxWeightItem&) aEditAttr.Get( EE_CHAR_WEIGHT ) ).GetWeight();
779 aNewAttr.Put( SvxWeightItem( eFW == WEIGHT_NORMAL ? WEIGHT_BOLD : WEIGHT_NORMAL, EE_CHAR_WEIGHT ) );
781 break;
782 case SID_ATTR_CHAR_POSTURE:
784 FontItalic eFI = ( (const SvxPostureItem&) aEditAttr.Get( EE_CHAR_ITALIC ) ).GetPosture();
785 aNewAttr.Put( SvxPostureItem( eFI == ITALIC_NORMAL ? ITALIC_NONE : ITALIC_NORMAL, EE_CHAR_ITALIC ) );
787 break;
788 case SID_ATTR_CHAR_UNDERLINE:
790 FontUnderline eFU = ( (const SvxUnderlineItem&) aEditAttr. Get( EE_CHAR_UNDERLINE ) ).GetLineStyle();
791 aNewAttr.Put( SvxUnderlineItem( eFU == UNDERLINE_SINGLE ? UNDERLINE_NONE : UNDERLINE_SINGLE, EE_CHAR_UNDERLINE ) );
793 break;
794 case SID_ATTR_CHAR_STRIKEOUT:
796 FontStrikeout eFSO = ( ( (const SvxCrossedOutItem&) aEditAttr.Get( EE_CHAR_STRIKEOUT ) ).GetStrikeout() );
797 aNewAttr.Put( SvxCrossedOutItem( eFSO == STRIKEOUT_SINGLE ? STRIKEOUT_NONE : STRIKEOUT_SINGLE, EE_CHAR_STRIKEOUT ) );
799 break;
801 getView()->SetAttribs( aNewAttr );
807 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */