bump product version to 5.0.4.1
[LibreOffice.git] / sd / source / ui / annotations / annotationwindow.cxx
blobbcad03da6ab8e14f427994737ce3530274a9c04d
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 .
20 #include <editeng/fontitem.hxx>
21 #include <editeng/eeitem.hxx>
22 #include <editeng/fhgtitem.hxx>
23 #include <editeng/bulletitem.hxx>
24 #include <editeng/udlnitem.hxx>
25 #include <editeng/shdditem.hxx>
26 #include <editeng/flditem.hxx>
27 #include <editeng/frmdir.hxx>
28 #include <editeng/frmdiritem.hxx>
29 #include <editeng/langitem.hxx>
30 #include <editeng/adjustitem.hxx>
31 #include <editeng/editview.hxx>
32 #include <svx/svdview.hxx>
33 #include <svx/sdrpaintwindow.hxx>
34 #include <svx/sdr/overlay/overlaymanager.hxx>
35 #include <editeng/editstat.hxx>
36 #include <editeng/outliner.hxx>
37 #include <editeng/editeng.hxx>
38 #include <editeng/editobj.hxx>
39 #include <editeng/unolingu.hxx>
40 #include <editeng/outlobj.hxx>
41 #include <editeng/postitem.hxx>
42 #include <editeng/wghtitem.hxx>
43 #include <editeng/crossedoutitem.hxx>
44 #include <svx/svxids.hrc>
45 #include <svtools/langtab.hxx>
46 #include <svl/slstitm.hxx>
47 #include <unotools/securityoptions.hxx>
48 #include <unotools/useroptions.hxx>
49 #include <svl/languageoptions.hxx>
50 #include <svl/zforlist.hxx>
51 #include <svtools/svmedit.hxx>
53 #include <linguistic/lngprops.hxx>
55 #include <sfx2/request.hxx>
56 #include <sfx2/viewfrm.hxx>
57 #include <sfx2/bindings.hxx>
58 #include <sfx2/dispatch.hxx>
59 #include <sfx2/mnumgr.hxx>
61 #include <vcl/vclenum.hxx>
62 #include <vcl/edit.hxx>
63 #include <vcl/help.hxx>
64 #include <vcl/scrbar.hxx>
65 #include <vcl/button.hxx>
66 #include <vcl/svapp.hxx>
67 #include <vcl/gradient.hxx>
68 #include <vcl/cursor.hxx>
69 #include <vcl/settings.hxx>
71 #include <tools/helpers.hxx>
73 #include <basegfx/matrix/b2dhommatrix.hxx>
74 #include <basegfx/tuple/b2dtuple.hxx>
75 #include <basegfx/polygon/b2dpolygontools.hxx>
77 #include "annotations.hrc"
78 #include "annotationwindow.hxx"
79 #include "annotationmanagerimpl.hxx"
81 #include "DrawDocShell.hxx"
82 #include "ViewShell.hxx"
83 #include "drawdoc.hxx"
84 #include "View.hxx"
85 #include "textapi.hxx"
86 #include "sdresid.hxx"
88 #include <boost/scoped_ptr.hpp>
90 using namespace ::sd;
91 using namespace ::com::sun::star;
92 using namespace ::com::sun::star::uno;
93 using namespace ::com::sun::star::office;
94 using namespace ::com::sun::star::text;
96 #define METABUTTON_WIDTH 16
97 #define METABUTTON_HEIGHT 18
98 #define METABUTTON_AREA_WIDTH 30
99 #define POSTIT_META_HEIGHT (sal_Int32) 30
101 namespace sd {
103 Color ColorFromAlphaColor(sal_uInt8 aTransparency, Color &aFront, Color &aBack )
105 return Color((sal_uInt8)(aFront.GetRed() * aTransparency/(double)255 + aBack.GetRed() * (1-aTransparency/(double)255)),
106 (sal_uInt8)(aFront.GetGreen() * aTransparency/(double)255 + aBack.GetGreen() * (1-aTransparency/(double)255)),
107 (sal_uInt8)(aFront.GetBlue() * aTransparency/(double)255 + aBack.GetBlue() * (1-aTransparency/(double)255)));
110 /************ AnnotationTextWindow **********************************/
112 AnnotationTextWindow::AnnotationTextWindow( AnnotationWindow* pParent, WinBits nBits )
113 : Control(pParent, nBits)
114 , mpOutlinerView(0)
115 , mpAnnotationWindow( pParent )
119 AnnotationTextWindow::~AnnotationTextWindow()
121 disposeOnce();
124 void AnnotationTextWindow::dispose()
126 mpAnnotationWindow.clear();
127 Control::dispose();
130 void AnnotationTextWindow::Paint( vcl::RenderContext& /*rRenderContext*/, const Rectangle& rRect)
132 const bool bHighContrast = Application::GetSettings().GetStyleSettings().GetHighContrastMode();
133 if ( !bHighContrast )
135 DrawGradient(Rectangle(Point(0,0),PixelToLogic(GetSizePixel())),
136 Gradient(GradientStyle_LINEAR,mpAnnotationWindow->maColorLight,mpAnnotationWindow->maColor));
139 if( mpOutlinerView )
141 Color aBackgroundColor( mpAnnotationWindow->maColor );
142 if( bHighContrast )
144 aBackgroundColor = GetSettings().GetStyleSettings().GetWindowColor();
147 mpOutlinerView->SetBackgroundColor( aBackgroundColor );
149 mpOutlinerView->Paint( rRect );
153 void AnnotationTextWindow::KeyInput( const KeyEvent& rKeyEvt )
155 const vcl::KeyCode& rKeyCode = rKeyEvt.GetKeyCode();
156 sal_uInt16 nKey = rKeyCode.GetCode();
158 if ((rKeyCode.IsMod1() && rKeyCode.IsMod2()) && ((nKey == KEY_PAGEUP) || (nKey == KEY_PAGEDOWN)))
160 SfxDispatcher* pDispatcher = mpAnnotationWindow->DocShell()->GetViewShell()->GetViewFrame()->GetDispatcher();
161 if( pDispatcher )
162 pDispatcher->Execute( nKey == KEY_PAGEDOWN ? SID_NEXT_POSTIT : SID_PREVIOUS_POSTIT );
164 else if (nKey == KEY_INSERT)
166 if (!rKeyCode.IsMod1() && !rKeyCode.IsMod2())
167 mpAnnotationWindow->ToggleInsMode();
169 else
171 long aOldHeight = mpAnnotationWindow->GetPostItTextHeight();
172 bool bDone = false;
174 /// HACK: need to switch off processing of Undo/Redo in Outliner
175 if ( !( (nKey == KEY_Z || nKey == KEY_Y) && rKeyCode.IsMod1()) )
177 bool bIsProtected = mpAnnotationWindow->IsProtected();
178 if (!bIsProtected || (bIsProtected && !EditEngine::DoesKeyChangeText(rKeyEvt)) )
180 bDone = mpOutlinerView->PostKeyEvent( rKeyEvt );
182 if (bDone)
184 mpAnnotationWindow->ResizeIfNecessary(aOldHeight,mpAnnotationWindow->GetPostItTextHeight());
186 else
188 Control::KeyInput(rKeyEvt);
193 void AnnotationTextWindow::MouseMove( const MouseEvent& rMEvt )
195 if ( mpOutlinerView )
197 mpOutlinerView->MouseMove( rMEvt );
198 SetPointer( mpOutlinerView->GetPointer( rMEvt.GetPosPixel() ) );
202 void AnnotationTextWindow::MouseButtonDown( const MouseEvent& rMEvt )
204 GrabFocus();
205 if ( mpOutlinerView )
206 mpOutlinerView->MouseButtonDown( rMEvt );
207 // todo mpOutlinerView->DocView()->GetViewFrame()->GetBindings().InvalidateAll(sal_False);
210 void AnnotationTextWindow::MouseButtonUp( const MouseEvent& rMEvt )
212 if ( mpOutlinerView )
213 mpOutlinerView->MouseButtonUp( rMEvt );
216 void AnnotationTextWindow::Command( const CommandEvent& rCEvt )
218 if ( rCEvt.GetCommand() == CommandEventId::ContextMenu )
220 mpAnnotationWindow->Command(rCEvt);
222 else
224 if ( mpOutlinerView )
225 mpOutlinerView->Command( rCEvt );
226 else
227 Window::Command(rCEvt);
231 void AnnotationTextWindow::GetFocus()
233 Window::GetFocus();
236 void AnnotationTextWindow::LoseFocus()
238 Window::LoseFocus();
241 OUString AnnotationTextWindow::GetSurroundingText() const
243 if( mpOutlinerView )
245 EditEngine *aEditEngine = mpOutlinerView->GetEditView().GetEditEngine();
246 if( mpOutlinerView->HasSelection() )
247 return mpOutlinerView->GetSelected();
248 else
250 ESelection aSelection = mpOutlinerView->GetEditView().GetSelection();
251 return aEditEngine->GetText(aSelection.nStartPara);
254 return OUString();
257 Selection AnnotationTextWindow::GetSurroundingTextSelection() const
259 if( mpOutlinerView )
261 if( mpOutlinerView->HasSelection() )
262 return Selection( 0, mpOutlinerView->GetSelected().getLength() );
263 else
265 ESelection aSelection = mpOutlinerView->GetEditView().GetSelection();
266 return Selection( aSelection.nStartPos, aSelection.nEndPos );
269 else
270 return Selection( 0, 0 );
273 /************** AnnotationWindow***********************************++*/
275 AnnotationWindow::AnnotationWindow( AnnotationManagerImpl& rManager, DrawDocShell* pDocShell, vcl::Window* pParent )
276 : FloatingWindow(pParent, WB_SYSTEMWINDOW|WB_BORDER|WB_NEEDSFOCUS)
277 , mrManager( rManager )
278 , mpDocShell( pDocShell )
279 , mpView( pDocShell->GetViewShell()->GetView() )
280 , mpDoc( pDocShell->GetDoc() )
281 , mpOutlinerView(0)
282 , mpOutliner(0)
283 , mpVScrollbar(0)
284 , mbReadonly(pDocShell->IsReadOnly())
285 , mbProtected(false)
286 , mbMouseOverButton(false)
287 , mpTextWindow(0)
288 , mpMeta(0)
292 AnnotationWindow::~AnnotationWindow()
294 disposeOnce();
297 void AnnotationWindow::dispose()
299 mpMeta.disposeAndClear();
300 delete mpOutlinerView;
301 delete mpOutliner;
302 mpVScrollbar.disposeAndClear();
303 mpTextWindow.disposeAndClear();
304 FloatingWindow::dispose();
307 void AnnotationWindow::InitControls()
309 // actual window which holds the user text
310 mpTextWindow = VclPtr<AnnotationTextWindow>::Create(this, WB_NODIALOGCONTROL);
311 mpTextWindow->SetPointer(Pointer(PointerStyle::Text));
313 // window control for author and date
314 mpMeta = VclPtr<MultiLineEdit>::Create(this,0);
315 mpMeta->SetReadOnly();
316 mpMeta->SetRightToLeft(AllSettings::GetLayoutRTL());
317 mpMeta->AlwaysDisableInput(true);
318 mpMeta->SetCallHandlersOnInputDisabled(true);
320 // we should leave this setting alone, but for this we need a better layout algo
321 // with variable meta size height
322 AllSettings aSettings = mpMeta->GetSettings();
323 StyleSettings aStyleSettings = aSettings.GetStyleSettings();
324 vcl::Font aFont = aStyleSettings.GetFieldFont();
325 aFont.SetHeight(8);
326 aStyleSettings.SetFieldFont(aFont);
327 aSettings.SetStyleSettings(aStyleSettings);
328 mpMeta->SetSettings(aSettings);
330 mpOutliner = new ::Outliner(GetAnnotationPool(),OUTLINERMODE_TEXTOBJECT);
331 Doc()->SetCalcFieldValueHdl( mpOutliner );
332 mpOutliner->SetUpdateMode( true );
333 Rescale();
335 OutputDevice* pDev = Doc()->GetRefDevice();
336 if( pDev )
338 mpOutliner->SetRefDevice( pDev );
341 mpTextWindow->EnableRTL( false );
342 mpOutlinerView = new OutlinerView ( mpOutliner, mpTextWindow );
343 mpOutliner->InsertView(mpOutlinerView );
344 mpTextWindow->SetOutlinerView(mpOutlinerView);
345 mpOutlinerView->SetOutputArea( PixelToLogic( Rectangle(0,0,1,1) ) );
347 //create Scrollbars
348 mpVScrollbar = VclPtr<ScrollBar>::Create(this, WB_3DLOOK |WB_VSCROLL|WB_DRAG);
349 mpVScrollbar->EnableNativeWidget(false);
350 mpVScrollbar->EnableRTL( false );
351 mpVScrollbar->SetScrollHdl(LINK(this, AnnotationWindow, ScrollHdl));
352 mpVScrollbar->EnableDrag();
354 EEControlBits nCntrl = mpOutliner->GetControlWord();
355 nCntrl |= EEControlBits::PASTESPECIAL | EEControlBits::AUTOCORRECT | EEControlBits::USECHARATTRIBS | EEControlBits::NOCOLORS;
356 mpOutliner->SetControlWord(nCntrl);
358 Engine()->SetModifyHdl( Link<>() );
359 Engine()->EnableUndo( false );
361 Engine()->ClearModifyFlag();
362 Engine()->GetUndoManager().Clear();
363 Engine()->EnableUndo( true );
364 Engine()->SetModifyHdl( LINK( this, AnnotationWindow, ModifyHdl ) );
366 Invalidate();
368 SetLanguage(GetLanguage());
370 mpMeta->Show();
371 mpVScrollbar->Show();
372 mpTextWindow->Show();
375 void AnnotationWindow::StartEdit()
377 getView()->SetSelection(ESelection(EE_PARA_MAX_COUNT,EE_TEXTPOS_MAX_COUNT,EE_PARA_MAX_COUNT,EE_TEXTPOS_MAX_COUNT));
378 getView()->ShowCursor();
381 void AnnotationWindow::Rescale()
383 MapMode aMode(MAP_100TH_MM);
384 aMode.SetOrigin( Point() );
385 mpOutliner->SetRefMapMode( aMode );
386 SetMapMode( aMode );
387 mpTextWindow->SetMapMode( aMode );
388 if ( mpMeta )
390 vcl::Font aFont( mpMeta->GetSettings().GetStyleSettings().GetFieldFont() );
391 sal_Int32 nHeight = aFont.GetHeight();
392 nHeight = nHeight * aMode.GetScaleY().GetNumerator() / aMode.GetScaleY().GetDenominator();
393 aFont.SetHeight( nHeight );
394 mpMeta->SetControlFont( aFont );
398 void AnnotationWindow::DoResize()
400 unsigned long aWidth = GetSizePixel().Width();
401 long aHeight = GetSizePixel().Height() - POSTIT_META_HEIGHT;
403 mpOutliner->SetPaperSize( PixelToLogic( Size(aWidth,aHeight) ) ) ;
404 long aTextHeight = LogicToPixel( mpOutliner->CalcTextSize()).Height();
406 if( aTextHeight > aHeight )
407 { // we need vertical scrollbars and have to reduce the width
408 aWidth -= GetScrollbarWidth();
409 mpVScrollbar->Show();
411 else
413 mpVScrollbar->Hide();
416 mpTextWindow->setPosSizePixel(0,0,aWidth, aHeight);
418 if( mbReadonly )
419 mpMeta->setPosSizePixel(0,aHeight,GetSizePixel().Width(),POSTIT_META_HEIGHT);
420 else
421 mpMeta->setPosSizePixel(0,aHeight,GetSizePixel().Width()-METABUTTON_AREA_WIDTH,POSTIT_META_HEIGHT);
423 mpOutliner->SetPaperSize( PixelToLogic( Size(aWidth,aHeight) ) ) ;
424 mpOutlinerView->SetOutputArea( PixelToLogic( Rectangle(0,0,aWidth,aHeight) ) );
425 if (!mpVScrollbar->IsVisible())
426 { // if we do not have a scrollbar anymore, we want to see the complete text
427 mpOutlinerView->SetVisArea( PixelToLogic( Rectangle(0,0,aWidth,aHeight) ) );
429 mpVScrollbar->setPosSizePixel( 0 + aWidth, 0, GetScrollbarWidth(), aHeight );
430 mpVScrollbar->SetVisibleSize( PixelToLogic(Size(0,aHeight)).Height() );
431 mpVScrollbar->SetPageSize( PixelToLogic(Size(0,aHeight)).Height() * 8 / 10 );
432 mpVScrollbar->SetLineSize( mpOutliner->GetTextHeight() / 10 );
433 SetScrollbar();
434 mpVScrollbar->SetRange( Range(0, mpOutliner->GetTextHeight()));
436 Point aPos( mpMeta->GetPosPixel());
437 Point aBase( aPos.X() + aPos.X() + GetSizePixel().Width(), aPos.Y() );
438 Point aLeft = PixelToLogic( Point( aBase.X() - (METABUTTON_WIDTH+5), aBase.Y()+17 ) );
439 Point aRight = PixelToLogic( Point( aBase.X() - (METABUTTON_WIDTH-1), aBase.Y()+17 ) );
440 Point aBottom = PixelToLogic( Point( aBase.X() - (METABUTTON_WIDTH+2), aBase.Y()+20 ) );
442 maPopupTriangle.clear();
443 maPopupTriangle.append(basegfx::B2DPoint(aLeft.X(),aLeft.Y()));
444 maPopupTriangle.append(basegfx::B2DPoint(aRight.X(),aRight.Y()));
445 maPopupTriangle.append(basegfx::B2DPoint(aBottom.X(),aBottom.Y()));
446 maPopupTriangle.setClosed(true);
447 maRectMetaButton = PixelToLogic( Rectangle( Point(
448 aPos.X()+GetSizePixel().Width()-(METABUTTON_WIDTH+10),
449 aPos.Y()+5 ),
450 Size( METABUTTON_WIDTH, METABUTTON_HEIGHT ) ) );
454 void AnnotationWindow::SetSizePixel( const Size& rNewSize )
456 Window::SetSizePixel(rNewSize);
459 void AnnotationWindow::SetScrollbar()
461 mpVScrollbar->SetThumbPos(mpOutlinerView->GetVisArea().Top());
464 void AnnotationWindow::ResizeIfNecessary(long aOldHeight, long aNewHeight)
466 if (aOldHeight != aNewHeight)
468 DoResize();
469 Invalidate();
471 else
473 SetScrollbar();
477 void AnnotationWindow::SetLanguage(const SvxLanguageItem &aNewItem)
479 Engine()->SetModifyHdl( Link<>() );
480 ESelection aOld = getView()->GetSelection();
482 ESelection aNewSelection( 0, 0, Engine()->GetParagraphCount()-1, EE_TEXTPOS_ALL );
483 getView()->SetSelection( aNewSelection );
484 SfxItemSet aEditAttr(getView()->GetAttribs());
485 aEditAttr.Put(aNewItem);
486 getView()->SetAttribs( aEditAttr );
488 getView()->SetSelection(aOld);
489 Engine()->SetModifyHdl( LINK( this, AnnotationWindow, ModifyHdl ) );
491 Invalidate();
494 void AnnotationWindow::ToggleInsMode()
496 if( mpOutlinerView )
498 SfxBindings &rBnd = mpDocShell->GetViewShell()->GetViewFrame()->GetBindings();
499 rBnd.Invalidate(SID_ATTR_INSERT);
500 rBnd.Update(SID_ATTR_INSERT);
504 long AnnotationWindow::GetPostItTextHeight()
506 return mpOutliner ? LogicToPixel(mpOutliner->CalcTextSize()).Height() : 0;
509 IMPL_LINK(AnnotationWindow, ScrollHdl, ScrollBar*, pScroll)
511 long nDiff = getView()->GetEditView().GetVisArea().Top() - pScroll->GetThumbPos();
512 getView()->Scroll( 0, nDiff );
513 return 0;
516 IMPL_STATIC_LINK_NOARG(AnnotationWindow, ModifyHdl)
518 return 0;
521 SvxLanguageItem AnnotationWindow::GetLanguage()
523 return SvxLanguageItem( Doc()->GetLanguage( EE_CHAR_LANGUAGE ), SID_ATTR_LANGUAGE );
526 TextApiObject* getTextApiObject( const Reference< XAnnotation >& xAnnotation )
528 if( xAnnotation.is() )
530 Reference< XText > xText( xAnnotation->getTextRange() );
531 return TextApiObject::getImplementation( xText );
533 return 0;
536 void AnnotationWindow::setAnnotation( const Reference< XAnnotation >& xAnnotation, bool bGrabFocus )
538 if( (xAnnotation != mxAnnotation) && xAnnotation.is() )
540 mxAnnotation = xAnnotation;
542 SetColor();
544 SvtUserOptions aUserOptions;
545 mbProtected = aUserOptions.GetFullName() != xAnnotation->getAuthor();
547 Engine()->Clear();
548 TextApiObject* pTextApi = getTextApiObject( mxAnnotation );
550 if( pTextApi )
552 boost::scoped_ptr< OutlinerParaObject > pOPO( pTextApi->CreateText() );
553 Engine()->SetText( *pOPO.get() );
556 Engine()->SetModifyHdl( LINK( this, AnnotationWindow, ModifyHdl ) );
557 Engine()->ClearModifyFlag();
558 Engine()->GetUndoManager().Clear();
560 Invalidate();
562 OUString sMeta( xAnnotation->getAuthor() );
563 OUString sDateTime( getAnnotationDateTimeString(xAnnotation) );
565 if( !sDateTime.isEmpty() )
567 if( !sMeta.isEmpty() )
568 sMeta += "\n";
570 sMeta += sDateTime;
572 mpMeta->SetText(sMeta);
574 if( bGrabFocus )
575 GrabFocus();
579 void AnnotationWindow::SetColor()
581 sal_uInt16 nAuthorIdx = mpDoc->GetAnnotationAuthorIndex( mxAnnotation->getAuthor() );
583 const bool bHighContrast = Application::GetSettings().GetStyleSettings().GetHighContrastMode();
584 if( bHighContrast )
586 StyleSettings aStyleSettings = GetSettings().GetStyleSettings();
588 maColor = aStyleSettings.GetWindowColor();
589 maColorDark = maColor;
590 maColorLight = aStyleSettings.GetWindowTextColor();
592 else
594 maColor = AnnotationManagerImpl::GetColor( nAuthorIdx );
595 maColorDark = AnnotationManagerImpl::GetColorDark( nAuthorIdx );
596 maColorLight = AnnotationManagerImpl::GetColorLight( nAuthorIdx );
599 mpOutlinerView->SetBackgroundColor(maColor);
600 Engine()->SetBackgroundColor(maColor);
603 SvtAccessibilityOptions aOptions;
604 Engine()->ForceAutoColor( bHighContrast || aOptions.GetIsAutomaticFontColor() );
607 mpMeta->SetControlBackground(maColor);
608 AllSettings aSettings = mpMeta->GetSettings();
609 StyleSettings aStyleSettings = aSettings.GetStyleSettings();
610 aStyleSettings.SetFieldTextColor( bHighContrast ? maColorLight : maColorDark);
611 aSettings.SetStyleSettings(aStyleSettings);
612 mpMeta->SetSettings(aSettings);
614 AllSettings aSettings2 = mpVScrollbar->GetSettings();
615 StyleSettings aStyleSettings2 = aSettings2.GetStyleSettings();
616 aStyleSettings2.SetButtonTextColor(Color(0,0,0));
617 aStyleSettings2.SetCheckedColor(maColorLight); //hintergund
618 aStyleSettings2.SetShadowColor(maColorDark);
619 aStyleSettings2.SetFaceColor(maColor);
620 aSettings2.SetStyleSettings(aStyleSettings2);
621 mpVScrollbar->SetSettings(aSettings2);
624 void AnnotationWindow::Deactivate()
626 Reference< XAnnotation > xAnnotation( mxAnnotation );
628 // write changed text back to annotation
629 if ( Engine()->IsModified() )
631 TextApiObject* pTextApi = getTextApiObject( xAnnotation );
633 if( pTextApi )
635 OutlinerParaObject* pOPO = Engine()->CreateParaObject();
636 if( pOPO )
638 if( mpDoc->IsUndoEnabled() )
639 mpDoc->BegUndo( SD_RESSTR( STR_ANNOTATION_UNDO_EDIT ) );
641 pTextApi->SetText( *pOPO );
642 delete pOPO;
644 // set current time to changed annotation
645 xAnnotation->setDateTime( getCurrentDateTime() );
647 if( mpDoc->IsUndoEnabled() )
648 mpDoc->EndUndo();
650 DocView()->GetDocSh()->SetModified(true);
655 Engine()->ClearModifyFlag();
657 Engine()->GetUndoManager().Clear();
660 void AnnotationWindow::Paint(vcl::RenderContext& rRenderContext, const Rectangle& rRect)
662 FloatingWindow::Paint(rRenderContext, rRect);
664 if(mpMeta->IsVisible() && !mbReadonly)
666 const bool bHighContrast = Application::GetSettings().GetStyleSettings().GetHighContrastMode();
667 //draw left over space
668 if ( bHighContrast )
669 SetFillColor(COL_BLACK);
670 else
671 SetFillColor(maColor);
672 SetLineColor();
673 DrawRect(PixelToLogic(Rectangle(Point(mpMeta->GetPosPixel().X()+mpMeta->GetSizePixel().Width(),mpMeta->GetPosPixel().Y()),Size(METABUTTON_AREA_WIDTH,mpMeta->GetSizePixel().Height()))));
675 if ( bHighContrast )
677 //draw rect around button
678 SetFillColor(COL_BLACK);
679 SetLineColor(COL_WHITE);
681 else
683 //draw button
684 Gradient aGradient;
685 if (mbMouseOverButton)
686 aGradient = Gradient(GradientStyle_LINEAR,ColorFromAlphaColor(80,maColorDark,maColor),ColorFromAlphaColor(15,maColorDark,maColor));
687 else
688 aGradient = Gradient(GradientStyle_LINEAR,ColorFromAlphaColor(15,maColorDark,maColor),ColorFromAlphaColor(80,maColorDark,maColor));
689 DrawGradient(maRectMetaButton,aGradient);
690 //draw rect around button
691 SetFillColor();
692 SetLineColor(ColorFromAlphaColor(90,maColorDark,maColor));
694 DrawRect(maRectMetaButton);
696 //draw arrow
697 if( bHighContrast )
698 SetFillColor(COL_WHITE);
699 else
700 SetFillColor(COL_BLACK);
701 SetLineColor();
702 DrawPolygon(Polygon(maPopupTriangle));
706 void AnnotationWindow::MouseMove( const MouseEvent& rMEvt )
708 if( !mbReadonly )
710 if (maRectMetaButton.IsInside(PixelToLogic(rMEvt.GetPosPixel())))
712 if (!mbMouseOverButton)
714 Invalidate(maRectMetaButton);
715 mbMouseOverButton = true;
718 else
720 if (mbMouseOverButton)
722 Invalidate(maRectMetaButton);
723 mbMouseOverButton = false;
729 void AnnotationWindow::MouseButtonDown( const MouseEvent& rMEvt )
731 if (!mbReadonly && maRectMetaButton.IsInside(PixelToLogic(rMEvt.GetPosPixel())) && rMEvt.IsLeft())
733 // context menu
734 Rectangle aRect(LogicToPixel(maRectMetaButton.BottomLeft()),LogicToPixel(maRectMetaButton.BottomLeft()));
735 mrManager.ExecuteAnnotationContextMenu( mxAnnotation, (vcl::Window*)this, aRect, true );
739 void AnnotationWindow::Command( const CommandEvent& rCEvt )
741 if ( rCEvt.GetCommand() == CommandEventId::ContextMenu )
743 if( mpMeta->IsVisible() &&(mpMeta->GetPosPixel().Y() < rCEvt.GetMousePosPixel().Y()) )
744 return;
745 mrManager.ExecuteAnnotationContextMenu( mxAnnotation, this, Rectangle(rCEvt.GetMousePosPixel(),Size(1,1)) );
747 else
749 FloatingWindow::Command(rCEvt);
753 void AnnotationWindow::GetFocus()
755 if( mpTextWindow )
756 mpTextWindow->GrabFocus();
757 else
758 FloatingWindow::GetFocus();
761 void AnnotationWindow::ExecuteSlot( sal_uInt16 nSID )
763 if( nSID == SID_COPY )
765 getView()->Copy();
767 else if( nSID == SID_PASTE )
769 getView()->PasteSpecial();
770 DoResize();
772 else
774 SfxItemSet aEditAttr(getView()->GetAttribs());
775 SfxItemSet aNewAttr(mpOutliner->GetEmptyItemSet());
777 switch( nSID )
779 case SID_ATTR_CHAR_WEIGHT:
781 FontWeight eFW = static_cast<const SvxWeightItem&>( aEditAttr.Get( EE_CHAR_WEIGHT ) ).GetWeight();
782 aNewAttr.Put( SvxWeightItem( eFW == WEIGHT_NORMAL ? WEIGHT_BOLD : WEIGHT_NORMAL, EE_CHAR_WEIGHT ) );
784 break;
785 case SID_ATTR_CHAR_POSTURE:
787 FontItalic eFI = static_cast<const SvxPostureItem&>( aEditAttr.Get( EE_CHAR_ITALIC ) ).GetPosture();
788 aNewAttr.Put( SvxPostureItem( eFI == ITALIC_NORMAL ? ITALIC_NONE : ITALIC_NORMAL, EE_CHAR_ITALIC ) );
790 break;
791 case SID_ATTR_CHAR_UNDERLINE:
793 FontUnderline eFU = static_cast<const SvxUnderlineItem&>( aEditAttr. Get( EE_CHAR_UNDERLINE ) ).GetLineStyle();
794 aNewAttr.Put( SvxUnderlineItem( eFU == UNDERLINE_SINGLE ? UNDERLINE_NONE : UNDERLINE_SINGLE, EE_CHAR_UNDERLINE ) );
796 break;
797 case SID_ATTR_CHAR_STRIKEOUT:
799 FontStrikeout eFSO = static_cast<const SvxCrossedOutItem&>( aEditAttr.Get( EE_CHAR_STRIKEOUT ) ).GetStrikeout();
800 aNewAttr.Put( SvxCrossedOutItem( eFSO == STRIKEOUT_SINGLE ? STRIKEOUT_NONE : STRIKEOUT_SINGLE, EE_CHAR_STRIKEOUT ) );
802 break;
804 getView()->SetAttribs( aNewAttr );
810 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */