1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 <editeng/editund2.hxx>
32 #include <officecfg/Office/Common.hxx>
33 #include <svx/svxids.hrc>
34 #include <unotools/useroptions.hxx>
36 #include <sfx2/viewfrm.hxx>
37 #include <sfx2/bindings.hxx>
38 #include <sfx2/dispatch.hxx>
39 #include <svl/stritem.hxx>
41 #include <vcl/commandevent.hxx>
42 #include <vcl/commandinfoprovider.hxx>
43 #include <vcl/decoview.hxx>
44 #include <vcl/vclenum.hxx>
45 #include <vcl/svapp.hxx>
46 #include <vcl/gradient.hxx>
47 #include <vcl/settings.hxx>
48 #include <vcl/ptrstyle.hxx>
49 #include <vcl/virdev.hxx>
51 #include <strings.hrc>
52 #include "annotationwindow.hxx"
53 #include "annotationmanagerimpl.hxx"
55 #include <com/sun/star/office/XAnnotation.hpp>
56 #include <DrawDocShell.hxx>
57 #include <ViewShell.hxx>
58 #include <drawdoc.hxx>
59 #include <svx/annotation/TextAPI.hxx>
60 #include <svx/annotation/Annotation.hxx>
61 #include <svx/annotation/ObjectAnnotationData.hxx>
62 #include <svx/svdorect.hxx>
63 #include <sdresid.hxx>
69 #define METABUTTON_WIDTH 16
70 #define METABUTTON_HEIGHT 18
71 #define POSTIT_META_HEIGHT sal_Int32(30)
75 void AnnotationTextWindow::Paint(vcl::RenderContext
& rRenderContext
, const ::tools::Rectangle
& rRect
)
77 Size aSize
= GetOutputSizePixel();
79 const bool bHighContrast
= Application::GetSettings().GetStyleSettings().GetHighContrastMode();
82 rRenderContext
.DrawGradient(::tools::Rectangle(Point(0,0), rRenderContext
.PixelToLogic(aSize
)),
83 Gradient(css::awt::GradientStyle_LINEAR
, mrContents
.maColorLight
, mrContents
.maColor
));
86 DoPaint(rRenderContext
, rRect
);
89 void AnnotationTextWindow::EditViewScrollStateChange()
91 mrContents
.SetScrollbar();
94 bool AnnotationTextWindow::KeyInput(const KeyEvent
& rKeyEvt
)
96 const vcl::KeyCode
& rKeyCode
= rKeyEvt
.GetKeyCode();
97 sal_uInt16 nKey
= rKeyCode
.GetCode();
101 if ((rKeyCode
.IsMod1() && rKeyCode
.IsMod2()) && ((nKey
== KEY_PAGEUP
) || (nKey
== KEY_PAGEDOWN
)))
103 SfxDispatcher
* pDispatcher
= mrContents
.DocShell()->GetViewShell()->GetViewFrame()->GetDispatcher();
105 pDispatcher
->Execute( nKey
== KEY_PAGEDOWN
? SID_NEXT_POSTIT
: SID_PREVIOUS_POSTIT
);
108 else if (nKey
== KEY_INSERT
)
110 if (!rKeyCode
.IsMod1() && !rKeyCode
.IsMod2())
111 mrContents
.ToggleInsMode();
116 ::tools::Long aOldHeight
= mrContents
.GetPostItTextHeight();
118 /// HACK: need to switch off processing of Undo/Redo in Outliner
119 if ( !( (nKey
== KEY_Z
|| nKey
== KEY_Y
) && rKeyCode
.IsMod1()) )
121 bool bIsProtected
= mrContents
.IsProtected();
122 if (!bIsProtected
|| !EditEngine::DoesKeyChangeText(rKeyEvt
) )
124 if (EditView
* pEditView
= GetEditView())
126 bDone
= pEditView
->PostKeyEvent(rKeyEvt
);
127 if (!bDone
&& rKeyEvt
.GetKeyCode().IsMod1() && !rKeyEvt
.GetKeyCode().IsMod2())
131 EditEngine
* pEditEngine
= GetEditEngine();
132 sal_Int32 nPar
= pEditEngine
->GetParagraphCount();
135 sal_Int32 nLen
= pEditEngine
->GetTextLen(nPar
- 1);
136 pEditView
->SetSelection(ESelection(0, 0, nPar
- 1, nLen
));
146 mrContents
.ResizeIfNecessary(aOldHeight
, mrContents
.GetPostItTextHeight());
153 return WeldEditView::KeyInput(rKeyEvt
);
156 AnnotationTextWindow::AnnotationTextWindow(AnnotationWindow
& rContents
)
157 : mrContents(rContents
)
161 EditView
* AnnotationTextWindow::GetEditView() const
163 OutlinerView
* pOutlinerView
= mrContents
.GetOutlinerView();
166 return &pOutlinerView
->GetEditView();
169 EditEngine
* AnnotationTextWindow::GetEditEngine() const
171 OutlinerView
* pOutlinerView
= mrContents
.GetOutlinerView();
174 return &pOutlinerView
->GetEditView().getEditEngine();
177 void AnnotationTextWindow::SetDrawingArea(weld::DrawingArea
* pDrawingArea
)
180 pDrawingArea
->set_size_request(aSize
.Width(), aSize
.Height());
182 SetOutputSizePixel(aSize
);
184 weld::CustomWidgetController::SetDrawingArea(pDrawingArea
);
188 const StyleSettings
& rStyleSettings
= Application::GetSettings().GetStyleSettings();
189 Color aBgColor
= rStyleSettings
.GetWindowColor();
191 OutputDevice
& rDevice
= pDrawingArea
->get_ref_device();
193 rDevice
.SetMapMode(MapMode(MapUnit::Map100thMM
));
194 rDevice
.SetBackground(aBgColor
);
196 Size
aOutputSize(rDevice
.PixelToLogic(aSize
));
198 EditView
* pEditView
= GetEditView();
199 pEditView
->setEditViewCallbacks(this);
201 EditEngine
* pEditEngine
= GetEditEngine();
202 pEditEngine
->SetPaperSize(aOutputSize
);
203 pEditEngine
->SetRefDevice(&rDevice
);
205 pEditView
->SetOutputArea(::tools::Rectangle(Point(0, 0), aOutputSize
));
206 pEditView
->SetBackgroundColor(aBgColor
);
208 pDrawingArea
->set_cursor(PointerStyle::Text
);
213 // see SwAnnotationWin in sw for something similar
214 AnnotationWindow::AnnotationWindow(weld::Window
* pParent
, const ::tools::Rectangle
& rRect
,
215 DrawDocShell
* pDocShell
,
216 rtl::Reference
<sdr::annotation::Annotation
> const& xAnnotation
)
217 : mxBuilder(Application::CreateBuilder(pParent
, u
"modules/simpress/ui/annotation.ui"_ustr
))
218 , mxPopover(mxBuilder
->weld_popover(u
"Annotation"_ustr
))
219 , mxContainer(mxBuilder
->weld_widget(u
"container"_ustr
))
220 , mpDocShell(pDocShell
)
221 , mpDoc(pDocShell
->GetDoc())
222 , mbReadonly(pDocShell
->IsReadOnly())
225 mxContainer
->set_size_request(320, 240);
226 mxPopover
->popup_at_rect(pParent
, rRect
);
229 setAnnotation(xAnnotation
);
234 mxTextControl
->GrabFocus();
237 AnnotationWindow::~AnnotationWindow()
241 void AnnotationWindow::InitControls()
243 // window control for author and date
244 mxMeta
= mxBuilder
->weld_label(u
"meta"_ustr
);
245 mxMeta
->set_direction(AllSettings::GetLayoutRTL());
247 maLabelFont
= Application::GetSettings().GetStyleSettings().GetLabelFont();
248 maLabelFont
.SetFontHeight(8);
250 // we should leave this setting alone, but for this we need a better layout algo
251 // with variable meta size height
252 mxMeta
->set_font(maLabelFont
);
254 mpOutliner
.reset( new ::Outliner(GetAnnotationPool(),OutlinerMode::TextObject
) );
255 SdDrawDocument::SetCalcFieldValueHdl( mpOutliner
.get() );
256 mpOutliner
->SetUpdateLayout( true );
258 if (OutputDevice
* pDev
= mpDoc
->GetRefDevice())
259 mpOutliner
->SetRefDevice( pDev
);
261 mpOutlinerView
.reset( new OutlinerView ( mpOutliner
.get(), nullptr) );
262 mpOutliner
->InsertView(mpOutlinerView
.get() );
265 mxVScrollbar
= mxBuilder
->weld_scrolled_window(u
"scrolledwindow"_ustr
, true);
267 // actual window which holds the user text
268 mxTextControl
.reset(new AnnotationTextWindow(*this));
269 mxTextControlWin
.reset(new weld::CustomWeld(*mxBuilder
, u
"editview"_ustr
, *mxTextControl
));
270 mxTextControl
->SetPointer(PointerStyle::Text
);
273 OutputDevice
& rDevice
= mxTextControl
->GetDrawingArea()->get_ref_device();
275 mxVScrollbar
->set_direction(false);
276 mxVScrollbar
->connect_vadjustment_changed(LINK(this, AnnotationWindow
, ScrollHdl
));
278 mpOutlinerView
->SetBackgroundColor(COL_TRANSPARENT
);
279 mpOutlinerView
->SetOutputArea(rDevice
.PixelToLogic(::tools::Rectangle(0, 0, 1, 1)));
281 mxMenuButton
= mxBuilder
->weld_menu_button(u
"menubutton"_ustr
);
283 mxMenuButton
->hide();
285 mxMenuButton
->connect_selected(LINK(this, AnnotationWindow
, MenuItemSelectedHdl
));
287 EEControlBits nCntrl
= mpOutliner
->GetControlWord();
288 nCntrl
|= EEControlBits::PASTESPECIAL
| EEControlBits::AUTOCORRECT
| EEControlBits::USECHARATTRIBS
| EEControlBits::NOCOLORS
;
289 mpOutliner
->SetControlWord(nCntrl
);
291 mpOutliner
->SetModifyHdl( Link
<LinkParamNone
*,void>() );
292 mpOutliner
->EnableUndo( false );
294 mpOutliner
->ClearModifyFlag();
295 mpOutliner
->GetUndoManager().Clear();
296 mpOutliner
->EnableUndo( true );
298 SetLanguage(SvxLanguageItem(mpDoc
->GetLanguage(EE_CHAR_LANGUAGE
), SID_ATTR_LANGUAGE
));
300 mxTextControl
->GrabFocus();
303 IMPL_LINK(AnnotationWindow
, MenuItemSelectedHdl
, const OUString
&, rIdent
, void)
305 SfxDispatcher
* pDispatcher
= mpDocShell
->GetViewShell()->GetViewFrame()->GetDispatcher();
309 uno::Reference
<office::XAnnotation
> xUnoAnnotation(mxAnnotation
);
311 if (rIdent
== ".uno:ReplyToAnnotation")
314 const SfxUnoAnyItem
aItem(SID_REPLYTO_POSTIT
, uno::Any(xUnoAnnotation
));
315 pDispatcher
->ExecuteList(SID_REPLYTO_POSTIT
,
316 SfxCallMode::ASYNCHRON
, { &aItem
});
318 else if (rIdent
== ".uno:DeleteAnnotation")
320 const SfxUnoAnyItem
aItem(SID_DELETE_POSTIT
, uno::Any(xUnoAnnotation
));
321 pDispatcher
->ExecuteList(SID_DELETE_POSTIT
, SfxCallMode::ASYNCHRON
,
324 else if (rIdent
== ".uno:DeleteAllAnnotationByAuthor")
326 const SfxStringItem
aItem( SID_DELETEALLBYAUTHOR_POSTIT
, mxAnnotation
->getAuthor() );
327 pDispatcher
->ExecuteList( SID_DELETEALLBYAUTHOR_POSTIT
,
328 SfxCallMode::ASYNCHRON
, { &aItem
});
330 else if (rIdent
== ".uno:DeleteAllAnnotation")
331 pDispatcher
->Execute( SID_DELETEALL_POSTIT
);
334 void AnnotationWindow::FillMenuButton()
336 SvtUserOptions aUserOptions
;
337 OUString
sCurrentAuthor( aUserOptions
.GetFullName() );
338 OUString
sAuthor( mxAnnotation
->getAuthor() );
340 OUString
aStr(mxMenuButton
->get_item_label(u
".uno:DeleteAllAnnotationByAuthor"_ustr
));
341 OUString
aReplace( sAuthor
);
342 if( aReplace
.isEmpty() )
343 aReplace
= SdResId( STR_ANNOTATION_NOAUTHOR
);
344 aStr
= aStr
.replaceFirst("%1", aReplace
);
345 mxMenuButton
->set_item_label(u
".uno:DeleteAllAnnotationByAuthor"_ustr
, aStr
);
347 bool bShowReply
= sAuthor
!= sCurrentAuthor
&& !mbReadonly
;
348 mxMenuButton
->set_item_visible(u
".uno:ReplyToAnnotation"_ustr
, bShowReply
);
349 mxMenuButton
->set_item_visible(u
"separator"_ustr
, bShowReply
);
350 mxMenuButton
->set_item_visible(u
".uno:DeleteAnnotation"_ustr
, mxAnnotation
.is() && !mbReadonly
);
351 mxMenuButton
->set_item_visible(u
".uno:DeleteAllAnnotationByAuthor"_ustr
, !mbReadonly
);
352 mxMenuButton
->set_item_visible(u
".uno:DeleteAllAnnotation"_ustr
, !mbReadonly
);
355 void AnnotationWindow::StartEdit()
357 GetOutlinerView()->SetSelection(ESelection::AtEnd());
358 GetOutlinerView()->ShowCursor();
361 void AnnotationWindow::SetMapMode(const MapMode
& rNewMapMode
)
363 OutputDevice
& rDevice
= mxTextControl
->GetDrawingArea()->get_ref_device();
364 rDevice
.SetMapMode(rNewMapMode
);
367 void AnnotationWindow::Rescale()
369 MapMode
aMode(MapUnit::Map100thMM
);
370 aMode
.SetOrigin( Point() );
371 mpOutliner
->SetRefMapMode( aMode
);
376 vcl::Font aFont
= maLabelFont
;
377 sal_Int32 nHeight
= ::tools::Long(aFont
.GetFontHeight() * aMode
.GetScaleY());
378 aFont
.SetFontHeight( nHeight
);
379 mxMeta
->set_font(aFont
);
383 void AnnotationWindow::DoResize()
385 OutputDevice
& rDevice
= mxTextControl
->GetDrawingArea()->get_ref_device();
387 ::tools::Long aHeight
= mxContainer
->get_preferred_size().Height();
388 ::tools::ULong aWidth
= mxContainer
->get_preferred_size().Width();
390 aHeight
-= POSTIT_META_HEIGHT
;
392 mpOutliner
->SetPaperSize( rDevice
.PixelToLogic( Size(aWidth
, aHeight
) ) ) ;
393 ::tools::Long aTextHeight
= rDevice
.LogicToPixel(mpOutliner
->CalcTextSize()).Height();
395 if( aTextHeight
> aHeight
)
397 const int nThickness
= mxVScrollbar
->get_scroll_thickness();
400 // we need vertical scrollbars and have to reduce the width
401 aWidth
-= nThickness
;
402 mpOutliner
->SetPaperSize(rDevice
.PixelToLogic(Size(aWidth
, aHeight
)));
404 mxVScrollbar
->set_vpolicy(VclPolicyType::ALWAYS
);
408 mxVScrollbar
->set_vpolicy(VclPolicyType::NEVER
);
411 ::tools::Rectangle aOutputArea
= rDevice
.PixelToLogic(::tools::Rectangle(0, 0, aWidth
, aHeight
));
412 if (mxVScrollbar
->get_vpolicy() == VclPolicyType::NEVER
)
414 // if we do not have a scrollbar anymore, we want to see the complete text
415 mpOutlinerView
->SetVisArea(aOutputArea
);
417 mpOutlinerView
->SetOutputArea(aOutputArea
);
418 mpOutlinerView
->ShowCursor(true, true);
420 int nUpper
= mpOutliner
->GetTextHeight();
421 int nCurrentDocPos
= mpOutlinerView
->GetVisArea().Top();
422 int nStepIncrement
= mpOutliner
->GetTextHeight() / 10;
423 int nPageIncrement
= rDevice
.PixelToLogic(Size(0,aHeight
)).Height() * 8 / 10;
424 int nPageSize
= rDevice
.PixelToLogic(Size(0,aHeight
)).Height();
426 /* limit the page size to below nUpper because gtk's gtk_scrolled_window_start_deceleration has
429 lower = gtk_adjustment_get_lower
430 upper = gtk_adjustment_get_upper - gtk_adjustment_get_page_size
432 and requires that upper > lower or the deceleration animation never ends
434 nPageSize
= std::min(nPageSize
, nUpper
);
436 mxVScrollbar
->vadjustment_configure(nCurrentDocPos
, 0, nUpper
,
437 nStepIncrement
, nPageIncrement
, nPageSize
);
440 void AnnotationWindow::SetScrollbar()
442 mxVScrollbar
->vadjustment_set_value(mpOutlinerView
->GetVisArea().Top());
445 void AnnotationWindow::ResizeIfNecessary(::tools::Long aOldHeight
, ::tools::Long aNewHeight
)
447 if (aOldHeight
!= aNewHeight
)
453 void AnnotationWindow::SetLanguage(const SvxLanguageItem
&aNewItem
)
455 mpOutliner
->SetModifyHdl( Link
<LinkParamNone
*,void>() );
456 ESelection aOld
= GetOutlinerView()->GetSelection();
458 GetOutlinerView()->SetSelection(ESelection::All());
459 SfxItemSet
aEditAttr(GetOutlinerView()->GetAttribs());
460 aEditAttr
.Put(aNewItem
);
461 GetOutlinerView()->SetAttribs( aEditAttr
);
463 GetOutlinerView()->SetSelection(aOld
);
465 mxTextControl
->Invalidate();
468 void AnnotationWindow::ToggleInsMode()
472 SfxBindings
&rBnd
= mpDocShell
->GetViewShell()->GetViewFrame()->GetBindings();
473 rBnd
.Invalidate(SID_ATTR_INSERT
);
474 rBnd
.Update(SID_ATTR_INSERT
);
478 ::tools::Long
AnnotationWindow::GetPostItTextHeight()
480 OutputDevice
& rDevice
= mxTextControl
->GetDrawingArea()->get_ref_device();
481 return mpOutliner
? rDevice
.LogicToPixel(mpOutliner
->CalcTextSize()).Height() : 0;
484 IMPL_LINK(AnnotationWindow
, ScrollHdl
, weld::ScrolledWindow
&, rScrolledWindow
, void)
486 ::tools::Long nDiff
= GetOutlinerView()->GetEditView().GetVisArea().Top() - rScrolledWindow
.vadjustment_get_value();
487 GetOutlinerView()->Scroll( 0, nDiff
);
490 sdr::annotation::TextApiObject
* getTextApiObject(const uno::Reference
<office::XAnnotation
>& xAnnotation
)
492 if( xAnnotation
.is() )
494 uno::Reference
<text::XText
> xText( xAnnotation
->getTextRange() );
495 return sdr::annotation::TextApiObject::getImplementation(xText
);
500 void AnnotationWindow::setAnnotation(rtl::Reference
<sdr::annotation::Annotation
> const& xAnnotation
)
502 if (xAnnotation
== mxAnnotation
|| !xAnnotation
.is())
505 mxAnnotation
= xAnnotation
;
509 SvtUserOptions aUserOptions
;
510 mbProtected
= aUserOptions
.GetFullName() != xAnnotation
->getAuthor();
513 auto* pTextApi
= getTextApiObject(mxAnnotation
);
517 std::optional
< OutlinerParaObject
> pOPO( pTextApi
->CreateText() );
518 mpOutliner
->SetText(*pOPO
);
521 mpOutliner
->ClearModifyFlag();
522 mpOutliner
->GetUndoManager().Clear();
526 OUString
sMeta( xAnnotation
->getAuthor() );
527 OUString
sDateTime( getAnnotationDateTimeString(xAnnotation
) );
529 if( !sDateTime
.isEmpty() )
531 if( !sMeta
.isEmpty() )
536 mxMeta
->set_label(sMeta
);
539 void AnnotationWindow::SetColor()
541 sal_uInt16 nAuthorIdx
= mpDoc
->GetAnnotationAuthorIndex( mxAnnotation
->getAuthor() );
543 const StyleSettings
& rStyleSettings
= Application::GetSettings().GetStyleSettings();
544 const bool bHighContrast
= rStyleSettings
.GetHighContrastMode();
547 maColor
= rStyleSettings
.GetWindowColor();
548 maColorDark
= maColor
;
549 maColorLight
= rStyleSettings
.GetWindowTextColor();
553 maColor
= AnnotationManagerImpl::GetColor( nAuthorIdx
);
554 maColorDark
= AnnotationManagerImpl::GetColorDark( nAuthorIdx
);
555 maColorLight
= AnnotationManagerImpl::GetColorLight( nAuthorIdx
);
558 mpOutliner
->ForceAutoColor( bHighContrast
|| officecfg::Office::Common::Accessibility::IsAutomaticFontColor::get() );
560 mxPopover
->set_background(maColor
);
561 mxMenuButton
->set_background(maColor
);
563 ScopedVclPtrInstance
<VirtualDevice
> xVirDev
;
564 xVirDev
->SetLineColor();
565 xVirDev
->SetFillColor(maColor
);
567 Size
aSize(METABUTTON_WIDTH
, METABUTTON_HEIGHT
);
568 ::tools::Rectangle
aRect(Point(0, 0), aSize
);
569 xVirDev
->SetOutputSizePixel(aSize
);
570 xVirDev
->DrawRect(aRect
);
572 ::tools::Rectangle
aSymbolRect(aRect
);
573 // 25% distance to the left and right button border
574 const ::tools::Long nBorderDistanceLeftAndRight
= ((aSymbolRect
.GetWidth() * 250) + 500) / 1000;
575 aSymbolRect
.AdjustLeft(nBorderDistanceLeftAndRight
);
576 aSymbolRect
.AdjustRight( -nBorderDistanceLeftAndRight
);
577 // 40% distance to the top button border
578 const ::tools::Long nBorderDistanceTop
= ((aSymbolRect
.GetHeight() * 400) + 500) / 1000;
579 aSymbolRect
.AdjustTop(nBorderDistanceTop
);
580 // 15% distance to the bottom button border
581 const ::tools::Long nBorderDistanceBottom
= ((aSymbolRect
.GetHeight() * 150) + 500) / 1000;
582 aSymbolRect
.AdjustBottom( -nBorderDistanceBottom
);
583 DecorationView
aDecoView(xVirDev
.get());
584 aDecoView
.DrawSymbol(aSymbolRect
, SymbolType::SPIN_DOWN
, COL_BLACK
,
585 DrawSymbolFlags::NONE
);
586 mxMenuButton
->set_image(xVirDev
);
587 mxMenuButton
->set_size_request(aSize
.Width() + 4, aSize
.Height() + 4);
589 mxMeta
->set_font_color(bHighContrast
? maColorLight
: maColorDark
);
591 mxVScrollbar
->customize_scrollbars(maColorLight
,
594 mxVScrollbar
->set_scroll_thickness(GetPrefScrollbarWidth());
597 void AnnotationWindow::SaveToDocument()
599 uno::Reference
<office::XAnnotation
> xAnnotation(mxAnnotation
);
601 // write changed text back to annotation
602 if (mpOutliner
->IsModified())
604 auto* pTextApi
= getTextApiObject( xAnnotation
);
608 std::optional
<OutlinerParaObject
> pOPO
= mpOutliner
->CreateParaObject();
611 if( mpDoc
->IsUndoEnabled() )
612 mpDoc
->BegUndo( SdResId( STR_ANNOTATION_UNDO_EDIT
) );
614 pTextApi
->SetText( *pOPO
);
617 // set current time to changed annotation
618 xAnnotation
->setDateTime( getCurrentDateTime() );
620 rtl::Reference
<sdr::annotation::Annotation
> xSdrAnnotation
= dynamic_cast<sdr::annotation::Annotation
*>(xAnnotation
.get());
621 if (xSdrAnnotation
&& xSdrAnnotation
->getCreationInfo().meType
== sdr::annotation::AnnotationType::FreeText
)
623 SdrObject
* pObject
= xSdrAnnotation
->findAnnotationObject();
624 SdrRectObj
* pRectangleObject
= pObject
? dynamic_cast<SdrRectObj
*>(pObject
) : nullptr;
625 if (pRectangleObject
)
627 OUString aString
= xSdrAnnotation
->getTextRange()->getString();
628 pRectangleObject
->SetText(aString
);
632 if( mpDoc
->IsUndoEnabled() )
635 mpDocShell
->SetModified();
640 mpOutliner
->ClearModifyFlag();
642 mpOutliner
->GetUndoManager().Clear();
645 bool AnnotationTextWindow::Command(const CommandEvent
& rCEvt
)
647 if (rCEvt
.GetCommand() == CommandEventId::ContextMenu
)
649 if (mrContents
.DocShell()->IsReadOnly())
652 SfxDispatcher
* pDispatcher
= mrContents
.DocShell()->GetViewShell()->GetViewFrame()->GetDispatcher();
656 if (IsMouseCaptured())
658 // so the menu can capture it and the EditView doesn't get the button release and change its
659 // selection on a successful button click
663 ::tools::Rectangle
aRect(rCEvt
.GetMousePosPixel(), Size(1, 1));
664 weld::Widget
* pPopupParent
= GetDrawingArea();
665 std::unique_ptr
<weld::Builder
> xBuilder(Application::CreateBuilder(pPopupParent
, u
"modules/simpress/ui/annotationtagmenu.ui"_ustr
));
666 std::unique_ptr
<weld::Menu
> xMenu(xBuilder
->weld_menu(u
"menu"_ustr
));
668 auto xAnnotation
= mrContents
.getAnnotation();
670 SvtUserOptions aUserOptions
;
671 OUString
sCurrentAuthor( aUserOptions
.GetFullName() );
672 OUString
sAuthor( xAnnotation
->getAuthor() );
674 OUString
aStr(xMenu
->get_label(u
".uno:DeleteAllAnnotationByAuthor"_ustr
));
675 OUString
aReplace( sAuthor
);
676 if( aReplace
.isEmpty() )
677 aReplace
= SdResId( STR_ANNOTATION_NOAUTHOR
);
678 aStr
= aStr
.replaceFirst("%1", aReplace
);
679 xMenu
->set_label(u
".uno:DeleteAllAnnotationByAuthor"_ustr
, aStr
);
681 bool bShowReply
= sAuthor
!= sCurrentAuthor
;
682 xMenu
->set_visible(u
".uno:ReplyToAnnotation"_ustr
, bShowReply
);
683 xMenu
->set_visible(u
"separator"_ustr
, bShowReply
);
684 xMenu
->set_visible(u
".uno:DeleteAnnotation"_ustr
, xAnnotation
.is());
685 xMenu
->set_visible(u
".uno:DeleteAllAnnotationByAuthor"_ustr
, true);
686 xMenu
->set_visible(u
".uno:DeleteAllAnnotation"_ustr
, true);
690 auto xFrame
= mrContents
.DocShell()->GetViewShell()->GetViewFrame()->GetFrame().GetFrameInterface();
691 OUString
aModuleName(vcl::CommandInfoProvider::GetModuleIdentifier(xFrame
));
693 bool bEditable
= !mrContents
.IsProtected();
696 SfxItemSet
aSet(mrContents
.GetOutlinerView()->GetAttribs());
698 xMenu
->insert(nInsertPos
++, u
".uno:Bold"_ustr
,
699 vcl::CommandInfoProvider::GetMenuLabelForCommand(
700 vcl::CommandInfoProvider::GetCommandProperties(u
".uno:Bold"_ustr
, aModuleName
)),
701 nullptr, nullptr, vcl::CommandInfoProvider::GetXGraphicForCommand(u
".uno:Bold"_ustr
, xFrame
),
704 if ( aSet
.GetItemState( EE_CHAR_WEIGHT
) == SfxItemState::SET
)
706 if( aSet
.Get( EE_CHAR_WEIGHT
).GetWeight() == WEIGHT_BOLD
)
707 xMenu
->set_active(u
".uno:Bold"_ustr
, true);
710 xMenu
->insert(nInsertPos
++, u
".uno:Italic"_ustr
,
711 vcl::CommandInfoProvider::GetMenuLabelForCommand(
712 vcl::CommandInfoProvider::GetCommandProperties(u
".uno:Italic"_ustr
, aModuleName
)),
713 nullptr, nullptr, vcl::CommandInfoProvider::GetXGraphicForCommand(u
".uno:Italic"_ustr
, xFrame
),
716 if ( aSet
.GetItemState( EE_CHAR_ITALIC
) == SfxItemState::SET
)
718 if( aSet
.Get( EE_CHAR_ITALIC
).GetPosture() != ITALIC_NONE
)
719 xMenu
->set_active(u
".uno:Italic"_ustr
, true);
723 xMenu
->insert(nInsertPos
++, u
".uno:Underline"_ustr
,
724 vcl::CommandInfoProvider::GetMenuLabelForCommand(
725 vcl::CommandInfoProvider::GetCommandProperties(u
".uno:Underline"_ustr
, aModuleName
)),
726 nullptr, nullptr, vcl::CommandInfoProvider::GetXGraphicForCommand(u
".uno:Underline"_ustr
, xFrame
),
729 if ( aSet
.GetItemState( EE_CHAR_UNDERLINE
) == SfxItemState::SET
)
731 if( aSet
.Get( EE_CHAR_UNDERLINE
).GetLineStyle() != LINESTYLE_NONE
)
732 xMenu
->set_active(u
".uno:Underline"_ustr
, true);
735 xMenu
->insert(nInsertPos
++, u
".uno:Strikeout"_ustr
,
736 vcl::CommandInfoProvider::GetMenuLabelForCommand(
737 vcl::CommandInfoProvider::GetCommandProperties(u
".uno:Strikeout"_ustr
, aModuleName
)),
738 nullptr, nullptr, vcl::CommandInfoProvider::GetXGraphicForCommand(u
".uno:Strikeout"_ustr
, xFrame
),
741 if ( aSet
.GetItemState( EE_CHAR_STRIKEOUT
) == SfxItemState::SET
)
743 if( aSet
.Get( EE_CHAR_STRIKEOUT
).GetStrikeout() != STRIKEOUT_NONE
)
744 xMenu
->set_active(u
".uno:Strikeout"_ustr
, true);
747 xMenu
->insert_separator(nInsertPos
++, u
"separator2"_ustr
);
750 xMenu
->insert(nInsertPos
++, u
".uno:Copy"_ustr
,
751 vcl::CommandInfoProvider::GetMenuLabelForCommand(
752 vcl::CommandInfoProvider::GetCommandProperties(u
".uno:Copy"_ustr
, aModuleName
)),
753 nullptr, nullptr, vcl::CommandInfoProvider::GetXGraphicForCommand(u
".uno:Copy"_ustr
, xFrame
),
756 xMenu
->insert(nInsertPos
++, u
".uno:Paste"_ustr
,
757 vcl::CommandInfoProvider::GetMenuLabelForCommand(
758 vcl::CommandInfoProvider::GetCommandProperties(u
".uno:Paste"_ustr
, aModuleName
)),
759 nullptr, nullptr, vcl::CommandInfoProvider::GetXGraphicForCommand(u
".uno:Paste"_ustr
, xFrame
),
762 bool bCanPaste
= false;
765 TransferableDataHelper
aDataHelper(TransferableDataHelper::CreateFromClipboard(GetClipboard()));
766 bCanPaste
= aDataHelper
.GetFormatCount() != 0;
769 xMenu
->insert_separator(nInsertPos
++, u
"separator3"_ustr
);
771 xMenu
->set_sensitive(u
".uno:Copy"_ustr
, mrContents
.GetOutlinerView()->HasSelection());
772 xMenu
->set_sensitive(u
".uno:Paste"_ustr
, bCanPaste
);
774 auto sId
= xMenu
->popup_at_rect(pPopupParent
, aRect
);
776 uno::Reference
<office::XAnnotation
> xUnoAnnotation(mrContents
.getAnnotation());
778 if (sId
== ".uno:ReplyToAnnotation")
780 const SfxUnoAnyItem
aItem(SID_REPLYTO_POSTIT
, uno::Any(xUnoAnnotation
));
781 pDispatcher
->ExecuteList(SID_REPLYTO_POSTIT
,
782 SfxCallMode::ASYNCHRON
, { &aItem
});
784 else if (sId
== ".uno:DeleteAnnotation")
786 const SfxUnoAnyItem
aItem(SID_DELETE_POSTIT
, uno::Any(xUnoAnnotation
));
787 pDispatcher
->ExecuteList(SID_DELETE_POSTIT
, SfxCallMode::ASYNCHRON
,
790 else if (sId
== ".uno:DeleteAllAnnotationByAuthor")
792 const SfxStringItem
aItem( SID_DELETEALLBYAUTHOR_POSTIT
, sAuthor
);
793 pDispatcher
->ExecuteList( SID_DELETEALLBYAUTHOR_POSTIT
,
794 SfxCallMode::ASYNCHRON
, { &aItem
});
796 else if (sId
== ".uno:DeleteAllAnnotation")
797 pDispatcher
->Execute( SID_DELETEALL_POSTIT
);
798 else if (sId
== ".uno:Copy")
800 mrContents
.GetOutlinerView()->Copy();
802 else if (sId
== ".uno:Paste")
804 mrContents
.GetOutlinerView()->PasteSpecial();
805 mrContents
.DoResize();
807 else if (!sId
.isEmpty())
809 SfxItemSet
aEditAttr(mrContents
.GetOutlinerView()->GetAttribs());
810 SfxItemSet
aNewAttr(mrContents
.GetOutliner()->GetEmptyItemSet());
812 if (sId
== ".uno:Bold")
814 FontWeight eFW
= aEditAttr
.Get( EE_CHAR_WEIGHT
).GetWeight();
815 aNewAttr
.Put( SvxWeightItem( eFW
== WEIGHT_NORMAL
? WEIGHT_BOLD
: WEIGHT_NORMAL
, EE_CHAR_WEIGHT
) );
817 else if (sId
== ".uno:Italic")
819 FontItalic eFI
= aEditAttr
.Get( EE_CHAR_ITALIC
).GetPosture();
820 aNewAttr
.Put( SvxPostureItem( eFI
== ITALIC_NORMAL
? ITALIC_NONE
: ITALIC_NORMAL
, EE_CHAR_ITALIC
) );
822 else if (sId
== ".uno:Underline")
824 FontLineStyle eFU
= aEditAttr
. Get( EE_CHAR_UNDERLINE
).GetLineStyle();
825 aNewAttr
.Put( SvxUnderlineItem( eFU
== LINESTYLE_SINGLE
? LINESTYLE_NONE
: LINESTYLE_SINGLE
, EE_CHAR_UNDERLINE
) );
827 else if (sId
== ".uno:Strikeout")
829 FontStrikeout eFSO
= aEditAttr
.Get( EE_CHAR_STRIKEOUT
).GetStrikeout();
830 aNewAttr
.Put( SvxCrossedOutItem( eFSO
== STRIKEOUT_SINGLE
? STRIKEOUT_NONE
: STRIKEOUT_SINGLE
, EE_CHAR_STRIKEOUT
) );
833 mrContents
.GetOutlinerView()->SetAttribs( aNewAttr
);
838 return WeldEditView::Command(rCEvt
);
843 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */