bump product version to 6.3.0.0.beta1
[LibreOffice.git] / sd / source / ui / annotations / annotationwindow.cxx
blob6c566287cd41733c3d0667027106c82eab3fd252
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/eeitem.hxx>
21 #include <editeng/udlnitem.hxx>
22 #include <editeng/langitem.hxx>
23 #include <editeng/editview.hxx>
24 #include <editeng/editstat.hxx>
25 #include <editeng/outliner.hxx>
26 #include <editeng/editeng.hxx>
27 #include <editeng/outlobj.hxx>
28 #include <editeng/postitem.hxx>
29 #include <editeng/wghtitem.hxx>
30 #include <editeng/crossedoutitem.hxx>
31 #include <svx/svxids.hrc>
32 #include <unotools/useroptions.hxx>
33 #include <svtools/svmedit.hxx>
35 #include <sfx2/viewfrm.hxx>
36 #include <sfx2/bindings.hxx>
37 #include <sfx2/dispatch.hxx>
39 #include <vcl/commandevent.hxx>
40 #include <vcl/vclenum.hxx>
41 #include <vcl/scrbar.hxx>
42 #include <vcl/svapp.hxx>
43 #include <vcl/gradient.hxx>
44 #include <vcl/settings.hxx>
45 #include <vcl/ptrstyle.hxx>
47 #include <strings.hrc>
48 #include "annotationwindow.hxx"
49 #include "annotationmanagerimpl.hxx"
51 #include <com/sun/star/office/XAnnotation.hpp>
52 #include <DrawDocShell.hxx>
53 #include <ViewShell.hxx>
54 #include <drawdoc.hxx>
55 #include <textapi.hxx>
56 #include <sdresid.hxx>
58 #include <memory>
60 using namespace ::sd;
61 using namespace ::com::sun::star;
62 using namespace ::com::sun::star::uno;
63 using namespace ::com::sun::star::office;
64 using namespace ::com::sun::star::text;
66 #define METABUTTON_WIDTH 16
67 #define METABUTTON_HEIGHT 18
68 #define METABUTTON_AREA_WIDTH 30
69 #define POSTIT_META_HEIGHT sal_Int32(30)
71 namespace sd {
73 static Color ColorFromAlphaColor(sal_uInt8 aTransparency, Color const &aFront, Color const &aBack )
75 return Color(static_cast<sal_uInt8>(aFront.GetRed() * aTransparency/double(255) + aBack.GetRed() * (1-aTransparency/double(255))),
76 static_cast<sal_uInt8>(aFront.GetGreen() * aTransparency/double(255) + aBack.GetGreen() * (1-aTransparency/double(255))),
77 static_cast<sal_uInt8>(aFront.GetBlue() * aTransparency/double(255) + aBack.GetBlue() * (1-aTransparency/double(255))));
80 /************ AnnotationTextWindow **********************************/
82 AnnotationTextWindow::AnnotationTextWindow( AnnotationWindow* pParent, WinBits nBits )
83 : Control(pParent, nBits)
84 , mpOutlinerView(nullptr)
85 , mpAnnotationWindow( pParent )
89 AnnotationTextWindow::~AnnotationTextWindow()
91 disposeOnce();
94 void AnnotationTextWindow::dispose()
96 mpAnnotationWindow.clear();
97 Control::dispose();
100 void AnnotationTextWindow::Paint( vcl::RenderContext& /*rRenderContext*/, const ::tools::Rectangle& rRect)
102 const bool bHighContrast = Application::GetSettings().GetStyleSettings().GetHighContrastMode();
103 if ( !bHighContrast )
105 DrawGradient(::tools::Rectangle(Point(0,0),PixelToLogic(GetSizePixel())),
106 Gradient(GradientStyle::Linear,mpAnnotationWindow->maColorLight,mpAnnotationWindow->maColor));
109 if( mpOutlinerView )
111 Color aBackgroundColor( mpAnnotationWindow->maColor );
112 if( bHighContrast )
114 aBackgroundColor = GetSettings().GetStyleSettings().GetWindowColor();
117 mpOutlinerView->SetBackgroundColor( aBackgroundColor );
119 mpOutlinerView->Paint( rRect );
123 void AnnotationTextWindow::KeyInput( const KeyEvent& rKeyEvt )
125 const vcl::KeyCode& rKeyCode = rKeyEvt.GetKeyCode();
126 sal_uInt16 nKey = rKeyCode.GetCode();
128 if ((rKeyCode.IsMod1() && rKeyCode.IsMod2()) && ((nKey == KEY_PAGEUP) || (nKey == KEY_PAGEDOWN)))
130 SfxDispatcher* pDispatcher = mpAnnotationWindow->DocShell()->GetViewShell()->GetViewFrame()->GetDispatcher();
131 if( pDispatcher )
132 pDispatcher->Execute( nKey == KEY_PAGEDOWN ? SID_NEXT_POSTIT : SID_PREVIOUS_POSTIT );
134 else if (nKey == KEY_INSERT)
136 if (!rKeyCode.IsMod1() && !rKeyCode.IsMod2())
137 mpAnnotationWindow->ToggleInsMode();
139 else
141 long aOldHeight = mpAnnotationWindow->GetPostItTextHeight();
142 bool bDone = false;
144 /// HACK: need to switch off processing of Undo/Redo in Outliner
145 if ( !( (nKey == KEY_Z || nKey == KEY_Y) && rKeyCode.IsMod1()) )
147 bool bIsProtected = mpAnnotationWindow->IsProtected();
148 if (!bIsProtected || !EditEngine::DoesKeyChangeText(rKeyEvt) )
150 bDone = mpOutlinerView->PostKeyEvent( rKeyEvt );
152 if (bDone)
154 mpAnnotationWindow->ResizeIfNecessary(aOldHeight,mpAnnotationWindow->GetPostItTextHeight());
156 else
158 Control::KeyInput(rKeyEvt);
163 void AnnotationTextWindow::MouseMove( const MouseEvent& rMEvt )
165 if ( mpOutlinerView )
167 mpOutlinerView->MouseMove( rMEvt );
168 SetPointer( mpOutlinerView->GetPointer( rMEvt.GetPosPixel() ) );
172 void AnnotationTextWindow::MouseButtonDown( const MouseEvent& rMEvt )
174 GrabFocus();
175 if ( mpOutlinerView )
176 mpOutlinerView->MouseButtonDown( rMEvt );
179 void AnnotationTextWindow::MouseButtonUp( const MouseEvent& rMEvt )
181 if ( mpOutlinerView )
182 mpOutlinerView->MouseButtonUp( rMEvt );
185 void AnnotationTextWindow::Command( const CommandEvent& rCEvt )
187 if ( rCEvt.GetCommand() == CommandEventId::ContextMenu )
189 mpAnnotationWindow->Command(rCEvt);
191 else
193 if ( mpOutlinerView )
194 mpOutlinerView->Command( rCEvt );
195 else
196 Window::Command(rCEvt);
200 OUString AnnotationTextWindow::GetSurroundingText() const
202 if( mpOutlinerView )
204 EditEngine *aEditEngine = mpOutlinerView->GetEditView().GetEditEngine();
205 if( mpOutlinerView->HasSelection() )
206 return mpOutlinerView->GetSelected();
207 else
209 ESelection aSelection = mpOutlinerView->GetEditView().GetSelection();
210 return aEditEngine->GetText(aSelection.nStartPara);
213 return OUString();
216 Selection AnnotationTextWindow::GetSurroundingTextSelection() const
218 if( mpOutlinerView )
220 if( mpOutlinerView->HasSelection() )
221 return Selection( 0, mpOutlinerView->GetSelected().getLength() );
222 else
224 ESelection aSelection = mpOutlinerView->GetEditView().GetSelection();
225 return Selection( aSelection.nStartPos, aSelection.nEndPos );
228 else
229 return Selection( 0, 0 );
232 /************** AnnotationWindow***********************************++*/
234 AnnotationWindow::AnnotationWindow( AnnotationManagerImpl& rManager, DrawDocShell* pDocShell, vcl::Window* pParent )
235 : FloatingWindow(pParent, WB_BORDER)
236 , mrManager( rManager )
237 , mpDocShell( pDocShell )
238 , mpDoc( pDocShell->GetDoc() )
239 , mpVScrollbar(nullptr)
240 , mbReadonly(pDocShell->IsReadOnly())
241 , mbProtected(false)
242 , mbMouseOverButton(false)
243 , mpTextWindow(nullptr)
244 , mpMeta(nullptr)
246 EnableAlwaysOnTop();
249 AnnotationWindow::~AnnotationWindow()
251 disposeOnce();
254 void AnnotationWindow::dispose()
256 mpMeta.disposeAndClear();
257 mpOutlinerView.reset();
258 mpOutliner.reset();
259 mpOutliner = nullptr;
260 mpVScrollbar.disposeAndClear();
261 mpTextWindow.disposeAndClear();
262 FloatingWindow::dispose();
265 void AnnotationWindow::InitControls()
267 // actual window which holds the user text
268 mpTextWindow = VclPtr<AnnotationTextWindow>::Create(this, WB_NODIALOGCONTROL);
269 mpTextWindow->SetPointer(PointerStyle::Text);
271 // window control for author and date
272 mpMeta = VclPtr<MultiLineEdit>::Create(this,0);
273 mpMeta->SetReadOnly();
274 mpMeta->SetRightToLeft(AllSettings::GetLayoutRTL());
275 mpMeta->AlwaysDisableInput(true);
276 mpMeta->SetCallHandlersOnInputDisabled(true);
278 // we should leave this setting alone, but for this we need a better layout algo
279 // with variable meta size height
280 AllSettings aSettings = mpMeta->GetSettings();
281 StyleSettings aStyleSettings = aSettings.GetStyleSettings();
282 vcl::Font aFont = aStyleSettings.GetFieldFont();
283 aFont.SetFontHeight(8);
284 aStyleSettings.SetFieldFont(aFont);
285 aSettings.SetStyleSettings(aStyleSettings);
286 mpMeta->SetSettings(aSettings);
288 mpOutliner.reset( new ::Outliner(GetAnnotationPool(),OutlinerMode::TextObject) );
289 SdDrawDocument::SetCalcFieldValueHdl( mpOutliner.get() );
290 mpOutliner->SetUpdateMode( true );
291 Rescale();
293 OutputDevice* pDev = Doc()->GetRefDevice();
294 if( pDev )
296 mpOutliner->SetRefDevice( pDev );
299 mpTextWindow->EnableRTL( false );
300 mpOutlinerView.reset( new OutlinerView ( mpOutliner.get(), mpTextWindow ) );
301 mpOutliner->InsertView(mpOutlinerView.get() );
302 mpTextWindow->SetOutlinerView(mpOutlinerView.get());
303 mpOutlinerView->SetOutputArea( PixelToLogic( ::tools::Rectangle(0,0,1,1) ) );
305 //create Scrollbars
306 mpVScrollbar = VclPtr<ScrollBar>::Create(this, WB_3DLOOK |WB_VSCROLL|WB_DRAG);
307 mpVScrollbar->EnableNativeWidget(false);
308 mpVScrollbar->EnableRTL( false );
309 mpVScrollbar->SetScrollHdl(LINK(this, AnnotationWindow, ScrollHdl));
310 mpVScrollbar->EnableDrag();
312 EEControlBits nCntrl = mpOutliner->GetControlWord();
313 nCntrl |= EEControlBits::PASTESPECIAL | EEControlBits::AUTOCORRECT | EEControlBits::USECHARATTRIBS | EEControlBits::NOCOLORS;
314 mpOutliner->SetControlWord(nCntrl);
316 Engine()->SetModifyHdl( Link<LinkParamNone*,void>() );
317 Engine()->EnableUndo( false );
319 Engine()->ClearModifyFlag();
320 Engine()->GetUndoManager().Clear();
321 Engine()->EnableUndo( true );
323 Invalidate();
325 SetLanguage(SvxLanguageItem( Doc()->GetLanguage( EE_CHAR_LANGUAGE ), SID_ATTR_LANGUAGE ));
327 mpMeta->Show();
328 mpVScrollbar->Show();
329 mpTextWindow->Show();
332 void AnnotationWindow::StartEdit()
334 getView()->SetSelection(ESelection(EE_PARA_MAX_COUNT,EE_TEXTPOS_MAX_COUNT,EE_PARA_MAX_COUNT,EE_TEXTPOS_MAX_COUNT));
335 getView()->ShowCursor();
338 void AnnotationWindow::Rescale()
340 MapMode aMode(MapUnit::Map100thMM);
341 aMode.SetOrigin( Point() );
342 mpOutliner->SetRefMapMode( aMode );
343 SetMapMode( aMode );
344 mpTextWindow->SetMapMode( aMode );
345 if ( mpMeta )
347 vcl::Font aFont( mpMeta->GetSettings().GetStyleSettings().GetFieldFont() );
348 sal_Int32 nHeight = long(aFont.GetFontHeight() * aMode.GetScaleY());
349 aFont.SetFontHeight( nHeight );
350 mpMeta->SetControlFont( aFont );
354 void AnnotationWindow::DoResize()
356 unsigned long aWidth = GetSizePixel().Width();
357 long aHeight = GetSizePixel().Height() - POSTIT_META_HEIGHT;
359 mpOutliner->SetPaperSize( PixelToLogic( Size(aWidth,aHeight) ) ) ;
360 long aTextHeight = LogicToPixel( mpOutliner->CalcTextSize()).Height();
362 if( aTextHeight > aHeight )
363 { // we need vertical scrollbars and have to reduce the width
364 aWidth -= GetScrollbarWidth();
365 mpVScrollbar->Show();
367 else
369 mpVScrollbar->Hide();
372 mpTextWindow->setPosSizePixel(0,0,aWidth, aHeight);
374 if( mbReadonly )
375 mpMeta->setPosSizePixel(0,aHeight,GetSizePixel().Width(),POSTIT_META_HEIGHT);
376 else
377 mpMeta->setPosSizePixel(0,aHeight,GetSizePixel().Width()-METABUTTON_AREA_WIDTH,POSTIT_META_HEIGHT);
379 mpOutliner->SetPaperSize( PixelToLogic( Size(aWidth,aHeight) ) ) ;
380 mpOutlinerView->SetOutputArea( PixelToLogic( ::tools::Rectangle(0,0,aWidth,aHeight) ) );
381 if (!mpVScrollbar->IsVisible())
382 { // if we do not have a scrollbar anymore, we want to see the complete text
383 mpOutlinerView->SetVisArea( PixelToLogic( ::tools::Rectangle(0,0,aWidth,aHeight) ) );
385 mpVScrollbar->setPosSizePixel( 0 + aWidth, 0, GetScrollbarWidth(), aHeight );
386 mpVScrollbar->SetVisibleSize( PixelToLogic(Size(0,aHeight)).Height() );
387 mpVScrollbar->SetPageSize( PixelToLogic(Size(0,aHeight)).Height() * 8 / 10 );
388 mpVScrollbar->SetLineSize( mpOutliner->GetTextHeight() / 10 );
389 SetScrollbar();
390 mpVScrollbar->SetRange( Range(0, mpOutliner->GetTextHeight()));
392 Point aPos( mpMeta->GetPosPixel());
393 Point aBase( aPos.X() + aPos.X() + GetSizePixel().Width(), aPos.Y() );
394 Point aLeft = PixelToLogic( Point( aBase.X() - (METABUTTON_WIDTH+5), aBase.Y()+17 ) );
395 Point aRight = PixelToLogic( Point( aBase.X() - (METABUTTON_WIDTH-1), aBase.Y()+17 ) );
396 Point aBottom = PixelToLogic( Point( aBase.X() - (METABUTTON_WIDTH+2), aBase.Y()+20 ) );
398 maPopupTriangle.clear();
399 maPopupTriangle.append(basegfx::B2DPoint(aLeft.X(),aLeft.Y()));
400 maPopupTriangle.append(basegfx::B2DPoint(aRight.X(),aRight.Y()));
401 maPopupTriangle.append(basegfx::B2DPoint(aBottom.X(),aBottom.Y()));
402 maPopupTriangle.setClosed(true);
403 maRectMetaButton = PixelToLogic( ::tools::Rectangle( Point(
404 aPos.X()+GetSizePixel().Width()-(METABUTTON_WIDTH+10),
405 aPos.Y()+5 ),
406 Size( METABUTTON_WIDTH, METABUTTON_HEIGHT ) ) );
410 void AnnotationWindow::SetScrollbar()
412 mpVScrollbar->SetThumbPos(mpOutlinerView->GetVisArea().Top());
415 void AnnotationWindow::ResizeIfNecessary(long aOldHeight, long aNewHeight)
417 if (aOldHeight != aNewHeight)
419 DoResize();
420 Invalidate();
422 else
424 SetScrollbar();
428 void AnnotationWindow::SetLanguage(const SvxLanguageItem &aNewItem)
430 Engine()->SetModifyHdl( Link<LinkParamNone*,void>() );
431 ESelection aOld = getView()->GetSelection();
433 ESelection aNewSelection( 0, 0, Engine()->GetParagraphCount()-1, EE_TEXTPOS_ALL );
434 getView()->SetSelection( aNewSelection );
435 SfxItemSet aEditAttr(getView()->GetAttribs());
436 aEditAttr.Put(aNewItem);
437 getView()->SetAttribs( aEditAttr );
439 getView()->SetSelection(aOld);
441 Invalidate();
444 void AnnotationWindow::ToggleInsMode()
446 if( mpOutlinerView )
448 SfxBindings &rBnd = mpDocShell->GetViewShell()->GetViewFrame()->GetBindings();
449 rBnd.Invalidate(SID_ATTR_INSERT);
450 rBnd.Update(SID_ATTR_INSERT);
454 long AnnotationWindow::GetPostItTextHeight()
456 return mpOutliner ? LogicToPixel(mpOutliner->CalcTextSize()).Height() : 0;
459 IMPL_LINK(AnnotationWindow, ScrollHdl, ScrollBar*, pScroll, void)
461 long nDiff = getView()->GetEditView().GetVisArea().Top() - pScroll->GetThumbPos();
462 getView()->Scroll( 0, nDiff );
465 TextApiObject* getTextApiObject( const Reference< XAnnotation >& xAnnotation )
467 if( xAnnotation.is() )
469 Reference< XText > xText( xAnnotation->getTextRange() );
470 return TextApiObject::getImplementation( xText );
472 return nullptr;
475 void AnnotationWindow::setAnnotation( const Reference< XAnnotation >& xAnnotation )
477 if( (xAnnotation == mxAnnotation) || !xAnnotation.is() )
478 return;
480 mxAnnotation = xAnnotation;
482 SetColor();
484 SvtUserOptions aUserOptions;
485 mbProtected = aUserOptions.GetFullName() != xAnnotation->getAuthor();
487 Engine()->Clear();
488 TextApiObject* pTextApi = getTextApiObject( mxAnnotation );
490 if( pTextApi )
492 std::unique_ptr< OutlinerParaObject > pOPO( pTextApi->CreateText() );
493 Engine()->SetText(*pOPO);
496 Engine()->ClearModifyFlag();
497 Engine()->GetUndoManager().Clear();
499 Invalidate();
501 OUString sMeta( xAnnotation->getAuthor() );
502 OUString sDateTime( getAnnotationDateTimeString(xAnnotation) );
504 if( !sDateTime.isEmpty() )
506 if( !sMeta.isEmpty() )
507 sMeta += "\n";
509 sMeta += sDateTime;
511 mpMeta->SetText(sMeta);
514 void AnnotationWindow::SetColor()
516 sal_uInt16 nAuthorIdx = mpDoc->GetAnnotationAuthorIndex( mxAnnotation->getAuthor() );
518 const bool bHighContrast = Application::GetSettings().GetStyleSettings().GetHighContrastMode();
519 if( bHighContrast )
521 StyleSettings aStyleSettings = GetSettings().GetStyleSettings();
523 maColor = aStyleSettings.GetWindowColor();
524 maColorDark = maColor;
525 maColorLight = aStyleSettings.GetWindowTextColor();
527 else
529 maColor = AnnotationManagerImpl::GetColor( nAuthorIdx );
530 maColorDark = AnnotationManagerImpl::GetColorDark( nAuthorIdx );
531 maColorLight = AnnotationManagerImpl::GetColorLight( nAuthorIdx );
534 mpOutlinerView->SetBackgroundColor(maColor);
535 Engine()->SetBackgroundColor(maColor);
538 SvtAccessibilityOptions aOptions;
539 Engine()->ForceAutoColor( bHighContrast || aOptions.GetIsAutomaticFontColor() );
542 mpMeta->SetControlBackground(maColor);
543 AllSettings aSettings = mpMeta->GetSettings();
544 StyleSettings aStyleSettings = aSettings.GetStyleSettings();
545 aStyleSettings.SetFieldTextColor( bHighContrast ? maColorLight : maColorDark);
546 aSettings.SetStyleSettings(aStyleSettings);
547 mpMeta->SetSettings(aSettings);
549 AllSettings aSettings2 = mpVScrollbar->GetSettings();
550 StyleSettings aStyleSettings2 = aSettings2.GetStyleSettings();
551 aStyleSettings2.SetButtonTextColor(Color(0,0,0));
552 aStyleSettings2.SetCheckedColor(maColorLight); //hintergund
553 aStyleSettings2.SetShadowColor(maColorDark);
554 aStyleSettings2.SetFaceColor(maColor);
555 aSettings2.SetStyleSettings(aStyleSettings2);
556 mpVScrollbar->SetSettings(aSettings2);
559 void AnnotationWindow::Deactivate()
561 //tdf#99388 and tdf#99712, don't deactivate if we lose focus because of our
562 //own popup
563 if (mrManager.getPopupMenuActive())
564 return;
566 if (!mpOutliner) //in dispose
567 return;
569 Reference< XAnnotation > xAnnotation( mxAnnotation );
571 // write changed text back to annotation
572 if ( Engine()->IsModified() )
574 TextApiObject* pTextApi = getTextApiObject( xAnnotation );
576 if( pTextApi )
578 std::unique_ptr<OutlinerParaObject> pOPO = Engine()->CreateParaObject();
579 if( pOPO )
581 if( mpDoc->IsUndoEnabled() )
582 mpDoc->BegUndo( SdResId( STR_ANNOTATION_UNDO_EDIT ) );
584 pTextApi->SetText( *pOPO );
585 pOPO.reset();
587 // set current time to changed annotation
588 xAnnotation->setDateTime( getCurrentDateTime() );
590 if( mpDoc->IsUndoEnabled() )
591 mpDoc->EndUndo();
593 mpDocShell->SetModified();
598 Engine()->ClearModifyFlag();
600 Engine()->GetUndoManager().Clear();
603 void AnnotationWindow::Paint(vcl::RenderContext& rRenderContext, const ::tools::Rectangle& rRect)
605 FloatingWindow::Paint(rRenderContext, rRect);
607 if(!(mpMeta->IsVisible() && !mbReadonly))
608 return;
610 const bool bHighContrast = Application::GetSettings().GetStyleSettings().GetHighContrastMode();
611 //draw left over space
612 if ( bHighContrast )
613 SetFillColor(COL_BLACK);
614 else
615 SetFillColor(maColor);
616 SetLineColor();
617 DrawRect(PixelToLogic(::tools::Rectangle(Point(mpMeta->GetPosPixel().X()+mpMeta->GetSizePixel().Width(),mpMeta->GetPosPixel().Y()),Size(METABUTTON_AREA_WIDTH,mpMeta->GetSizePixel().Height()))));
619 if ( bHighContrast )
621 //draw rect around button
622 SetFillColor(COL_BLACK);
623 SetLineColor(COL_WHITE);
625 else
627 //draw button
628 Gradient aGradient;
629 if (mbMouseOverButton)
630 aGradient = Gradient(GradientStyle::Linear,ColorFromAlphaColor(80,maColorDark,maColor),ColorFromAlphaColor(15,maColorDark,maColor));
631 else
632 aGradient = Gradient(GradientStyle::Linear,ColorFromAlphaColor(15,maColorDark,maColor),ColorFromAlphaColor(80,maColorDark,maColor));
633 DrawGradient(maRectMetaButton,aGradient);
634 //draw rect around button
635 SetFillColor();
636 SetLineColor(ColorFromAlphaColor(90,maColorDark,maColor));
638 DrawRect(maRectMetaButton);
640 //draw arrow
641 if( bHighContrast )
642 SetFillColor(COL_WHITE);
643 else
644 SetFillColor(COL_BLACK);
645 SetLineColor();
646 DrawPolygon( ::tools::Polygon(maPopupTriangle));
649 void AnnotationWindow::MouseMove( const MouseEvent& rMEvt )
651 if( mbReadonly )
652 return;
654 if (maRectMetaButton.IsInside(PixelToLogic(rMEvt.GetPosPixel())))
656 if (!mbMouseOverButton)
658 Invalidate(maRectMetaButton);
659 mbMouseOverButton = true;
662 else
664 if (mbMouseOverButton)
666 Invalidate(maRectMetaButton);
667 mbMouseOverButton = false;
672 void AnnotationWindow::MouseButtonDown( const MouseEvent& rMEvt )
674 if (!mbReadonly && maRectMetaButton.IsInside(PixelToLogic(rMEvt.GetPosPixel())) && rMEvt.IsLeft())
676 // context menu
677 ::tools::Rectangle aRect(LogicToPixel(maRectMetaButton.BottomLeft()),LogicToPixel(maRectMetaButton.BottomLeft()));
678 mrManager.ExecuteAnnotationContextMenu( mxAnnotation, static_cast<vcl::Window*>(this), aRect, true );
682 void AnnotationWindow::Command( const CommandEvent& rCEvt )
684 if ( rCEvt.GetCommand() == CommandEventId::ContextMenu )
686 if( mpMeta->IsVisible() &&(mpMeta->GetPosPixel().Y() < rCEvt.GetMousePosPixel().Y()) )
687 return;
688 mrManager.ExecuteAnnotationContextMenu( mxAnnotation, this, ::tools::Rectangle(rCEvt.GetMousePosPixel(),Size(1,1)) );
690 else
692 FloatingWindow::Command(rCEvt);
696 void AnnotationWindow::GetFocus()
698 if( mpTextWindow )
699 mpTextWindow->GrabFocus();
700 else
701 FloatingWindow::GetFocus();
704 void AnnotationWindow::ExecuteSlot( sal_uInt16 nSID )
706 if( nSID == SID_COPY )
708 getView()->Copy();
710 else if( nSID == SID_PASTE )
712 getView()->PasteSpecial();
713 DoResize();
715 else
717 SfxItemSet aEditAttr(getView()->GetAttribs());
718 SfxItemSet aNewAttr(mpOutliner->GetEmptyItemSet());
720 switch( nSID )
722 case SID_ATTR_CHAR_WEIGHT:
724 FontWeight eFW = aEditAttr.Get( EE_CHAR_WEIGHT ).GetWeight();
725 aNewAttr.Put( SvxWeightItem( eFW == WEIGHT_NORMAL ? WEIGHT_BOLD : WEIGHT_NORMAL, EE_CHAR_WEIGHT ) );
727 break;
728 case SID_ATTR_CHAR_POSTURE:
730 FontItalic eFI = aEditAttr.Get( EE_CHAR_ITALIC ).GetPosture();
731 aNewAttr.Put( SvxPostureItem( eFI == ITALIC_NORMAL ? ITALIC_NONE : ITALIC_NORMAL, EE_CHAR_ITALIC ) );
733 break;
734 case SID_ATTR_CHAR_UNDERLINE:
736 FontLineStyle eFU = aEditAttr. Get( EE_CHAR_UNDERLINE ).GetLineStyle();
737 aNewAttr.Put( SvxUnderlineItem( eFU == LINESTYLE_SINGLE ? LINESTYLE_NONE : LINESTYLE_SINGLE, EE_CHAR_UNDERLINE ) );
739 break;
740 case SID_ATTR_CHAR_STRIKEOUT:
742 FontStrikeout eFSO = aEditAttr.Get( EE_CHAR_STRIKEOUT ).GetStrikeout();
743 aNewAttr.Put( SvxCrossedOutItem( eFSO == STRIKEOUT_SINGLE ? STRIKEOUT_NONE : STRIKEOUT_SINGLE, EE_CHAR_STRIKEOUT ) );
745 break;
747 getView()->SetAttribs( aNewAttr );
753 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */