LibreOffice Module sw (master)  1
SidebarTxtControl.cxx
Go to the documentation of this file.
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3  * This file is part of the LibreOffice project.
4  *
5  * This Source Code Form is subject to the terms of the Mozilla Public
6  * License, v. 2.0. If a copy of the MPL was not distributed with this
7  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8  *
9  * This file incorporates work covered by the following license notice:
10  *
11  * Licensed to the Apache Software Foundation (ASF) under one or more
12  * contributor license agreements. See the NOTICE file distributed
13  * with this work for additional information regarding copyright
14  * ownership. The ASF licenses this file to you under the Apache
15  * License, Version 2.0 (the "License"); you may not use this file
16  * except in compliance with the License. You may obtain a copy of
17  * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18  */
19 
20 #include "SidebarTxtControl.hxx"
21 
22 #include "SidebarTxtControlAcc.hxx"
23 #include <docsh.hxx>
24 #include <doc.hxx>
25 
26 #include <PostItMgr.hxx>
27 #include <edtwin.hxx>
28 
29 #include <cmdid.h>
30 #include <strings.hrc>
31 
33 
34 #include <sfx2/viewfrm.hxx>
35 #include <sfx2/bindings.hxx>
36 #include <sfx2/dispatch.hxx>
37 #include <sfx2/sfxhelp.hxx>
38 
39 #include <vcl/commandevent.hxx>
40 #include <vcl/svapp.hxx>
41 #include <vcl/help.hxx>
42 #include <vcl/weld.hxx>
43 #include <vcl/gradient.hxx>
44 #include <vcl/scrbar.hxx>
45 #include <vcl/settings.hxx>
46 
47 #include <editeng/outliner.hxx>
48 #include <editeng/editeng.hxx>
49 #include <editeng/editview.hxx>
50 #include <editeng/flditem.hxx>
51 #include <LibreOfficeKit/LibreOfficeKitEnums.h>
52 #include <comphelper/lok.hxx>
53 #include <sfx2/lokhelper.hxx>
54 
55 #include <uitool.hxx>
56 #include <view.hxx>
57 #include <wrtsh.hxx>
58 #include <shellres.hxx>
59 #include <AnnotationWin.hxx>
60 #include <redline.hxx>
61 #include <memory>
62 
63 namespace sw { namespace sidebarwindows {
64 
66  WinBits nBits,
67  SwView& rDocView,
68  SwPostItMgr& rPostItMgr )
69  : Control( &rSidebarWin, nBits )
70  , mrSidebarWin( rSidebarWin )
71  , mrDocView( rDocView )
72  , mrPostItMgr( rPostItMgr )
73 {
75 }
76 
78 {
79  disposeOnce();
80 }
81 
83 {
86 }
87 
89 {
91 }
92 
94 {
95  Window::GetFocus();
96  if ( !mrSidebarWin.IsMouseOver() )
97  {
98  Invalidate();
99  }
100 }
101 
103 {
104  // write the visible text back into the SwField
106 
107  Window::LoseFocus();
108  if ( !mrSidebarWin.IsMouseOver() )
109  {
110  Invalidate();
111  }
112 }
113 
115 {
116  const char* pResId = nullptr;
117  switch( mrSidebarWin.GetLayoutStatus() )
118  {
119  case SwPostItHelper::INSERTED: pResId = STR_REDLINE_INSERT; break;
120  case SwPostItHelper::DELETED: pResId = STR_REDLINE_DELETE; break;
121  default: pResId = nullptr;
122  }
123 
124  SwContentAtPos aContentAtPos( IsAttrAtPos::Redline );
125  if ( pResId &&
127  {
128  OUString sText = SwResId(pResId) + ": " +
129  aContentAtPos.aFnd.pRedl->GetAuthorString() + " - " +
130  GetAppLangDateTimeString( aContentAtPos.aFnd.pRedl->GetTimeStamp() );
132  }
133 }
134 
135 void SidebarTextControl::Draw(OutputDevice* pDev, const Point& rPt, const Size& rSz, DrawFlags)
136 {
137  //Take the control's height, but overwrite the scrollbar area if there was one
138  Size aSize(PixelToLogic(GetSizePixel()));
139  aSize.setWidth( rSz.Width() );
140 
141  if ( GetTextView() )
142  {
143  GetTextView()->GetOutliner()->Draw(pDev, tools::Rectangle(rPt, aSize));
144  }
145 
147  {
149  pDev->DrawLine( PixelToLogic( GetPosPixel(), pDev->GetMapMode() ),
151  Point( GetSizePixel().Width(),
152  GetSizePixel().Height() ), pDev->GetMapMode() ) );
153  pDev->DrawLine( PixelToLogic( GetPosPixel() +
154  Point( GetSizePixel().Width(),0), pDev->GetMapMode() ),
156  Point( 0, GetSizePixel().Height() ), pDev->GetMapMode() ) );
157  }
158 }
159 
161 {
162  if (!rRenderContext.GetSettings().GetStyleSettings().GetHighContrastMode())
163  {
165  {
166  rRenderContext.DrawGradient(tools::Rectangle(Point(0,0), rRenderContext.PixelToLogic(GetSizePixel())),
167  Gradient(GradientStyle::Linear, mrSidebarWin.ColorDark(), mrSidebarWin.ColorDark()));
168  }
169  else
170  {
171  rRenderContext.DrawGradient(tools::Rectangle(Point(0,0), rRenderContext.PixelToLogic(GetSizePixel())),
172  Gradient(GradientStyle::Linear, mrSidebarWin.ColorLight(), mrSidebarWin.ColorDark()));
173  }
174  }
175 
176  if (GetTextView())
177  {
178  GetTextView()->Paint(rRect, &rRenderContext);
179  }
180 
182  {
183  rRenderContext.SetLineColor(mrSidebarWin.GetChangeColor());
184  rRenderContext.DrawLine(rRenderContext.PixelToLogic(GetPosPixel()),
185  rRenderContext.PixelToLogic(GetPosPixel() + Point(GetSizePixel().Width(),
186  GetSizePixel().Height())));
187  rRenderContext.DrawLine(rRenderContext.PixelToLogic(GetPosPixel() + Point(GetSizePixel().Width(),
188  0)),
189  rRenderContext.PixelToLogic(GetPosPixel() + Point(0,
190  GetSizePixel().Height())));
191  }
192 }
193 
195 {
196  tools::Rectangle aRectangle;
197 
198  if (!pRectangle)
199  {
200  Push(PushFlags::MAPMODE);
201  EnableMapMode();
202  aRectangle = tools::Rectangle(Point(0, 0), PixelToLogic(GetSizePixel()));
203  Pop();
204  }
205  else
206  aRectangle = *pRectangle;
207 
208  // Convert from relative twips to absolute ones.
209  vcl::Window& rParent = mrSidebarWin.EditWin();
210  Point aOffset(GetOutOffXPixel() - rParent.GetOutOffXPixel(), GetOutOffYPixel() - rParent.GetOutOffYPixel());
211  rParent.Push(PushFlags::MAPMODE);
212  rParent.EnableMapMode();
213  aOffset = rParent.PixelToLogic(aOffset);
214  rParent.Pop();
215  aRectangle.Move(aOffset.getX(), aOffset.getY());
216 
217  OString sRectangle = aRectangle.toString();
218  SwWrtShell& rWrtShell = mrDocView.GetWrtShell();
219  SfxLokHelper::notifyInvalidation(rWrtShell.GetSfxViewShell(), sRectangle);
220 }
221 
223 {
224  if (getenv("SW_DEBUG") && rKeyEvt.GetKeyCode().GetCode() == KEY_F12)
225  {
226  if (rKeyEvt.GetKeyCode().IsShift())
227  {
229  return;
230  }
231  }
232 
233  const vcl::KeyCode& rKeyCode = rKeyEvt.GetKeyCode();
234  sal_uInt16 nKey = rKeyCode.GetCode();
235  if ( ( rKeyCode.IsMod1() && rKeyCode.IsMod2() ) &&
236  ( (nKey == KEY_PAGEUP) || (nKey == KEY_PAGEDOWN) ) )
237  {
239  }
240  else if ( nKey == KEY_ESCAPE ||
241  ( rKeyCode.IsMod1() &&
242  ( nKey == KEY_PAGEUP ||
243  nKey == KEY_PAGEDOWN ) ) )
244  {
246  }
247  else if ( rKeyCode.GetFullCode() == KEY_INSERT )
248  {
250  }
251  else
252  {
253  // MakeVisible can lose our MapMode, save it.
254  auto oldMapMode = GetMapMode();
255  //let's make sure we see our note
258  SetMapMode(oldMapMode);
259 
260  long aOldHeight = mrSidebarWin.GetPostItTextHeight();
261  bool bDone = false;
262 
264  if ( !( (nKey == KEY_Z || nKey == KEY_Y) && rKeyCode.IsMod1()) )
265  {
266  bool bIsProtected = mrSidebarWin.IsProtected();
267  if ( !bIsProtected || !EditEngine::DoesKeyChangeText(rKeyEvt) )
268  {
269  bDone = GetTextView() && GetTextView()->PostKeyEvent( rKeyEvt );
270  }
271  else
272  {
273  std::unique_ptr<weld::Builder> xBuilder(Application::CreateBuilder(GetFrameWeld(), "modules/swriter/ui/inforeadonlydialog.ui"));
274  std::unique_ptr<weld::MessageDialog> xQuery(xBuilder->weld_message_dialog("InfoReadonlyDialog"));
275  xQuery->run();
276  }
277  }
278  if (bDone)
280  else
281  {
282  // write back data first when showing navigator
283  if ( nKey==KEY_F5 )
285  if (!mrDocView.KeyInput(rKeyEvt))
286  Window::KeyInput(rKeyEvt);
287  }
288  }
289 
291 }
292 
294 {
295  if ( GetTextView() )
296  {
297  OutlinerView* pOutlinerView( GetTextView() );
298  pOutlinerView->MouseMove( rMEvt );
299  // mba: why does OutlinerView not handle the modifier setting?!
300  // this forces the postit to handle *all* pointer types
301  SetPointer( pOutlinerView->GetPointer( rMEvt.GetPosPixel() ) );
302 
303  const EditView& aEV = pOutlinerView->GetEditView();
304  const SvxFieldItem* pItem = aEV.GetFieldUnderMousePointer();
305  if ( pItem )
306  {
307  const SvxFieldData* pField = pItem->GetField();
308  const SvxURLField* pURL = dynamic_cast<const SvxURLField*>( pField );
309  if ( pURL )
310  {
311  OUString sText(SfxHelp::GetURLHelpText(pURL->GetURL()));
313  this, PixelToLogic(tools::Rectangle(GetPosPixel(), Size(50, 10))), sText);
314  }
315  }
316  }
317 }
318 
320 {
321  if ( GetTextView() )
322  {
323  SvtSecurityOptions aSecOpts;
324  bool bExecuteMod = aSecOpts.IsOptionSet( SvtSecurityOptions::EOption::CtrlClickHyperlink);
325 
326  if ( !bExecuteMod || (rMEvt.GetModifier() == KEY_MOD1))
327  {
328  const EditView& aEV = GetTextView()->GetEditView();
329  const SvxFieldItem* pItem = aEV.GetFieldUnderMousePointer();
330  if ( pItem )
331  {
332  const SvxFieldData* pField = pItem->GetField();
333  const SvxURLField* pURL = dynamic_cast<const SvxURLField*>( pField );
334  if ( pURL )
335  {
336  GetTextView()->MouseButtonDown( rMEvt );
338  const OUString& sURL( pURL->GetURL() );
339  const OUString& sTarget( pURL->GetTargetFrame() );
340  ::LoadURL(rSh, sURL, LoadUrlFlags::NONE, sTarget);
341  return;
342  }
343  }
344  }
345  }
346 
347  GrabFocus();
348  if ( GetTextView() )
349  {
350  GetTextView()->MouseButtonDown( rMEvt );
351  }
353 }
354 
356 {
357  if ( GetTextView() )
358  GetTextView()->MouseButtonUp( rMEvt );
359 }
360 
361 IMPL_LINK( SidebarTextControl, OnlineSpellCallback, SpellCallbackInfo&, rInfo, void )
362 {
363  if ( rInfo.nCommand == SpellCallbackCommand::STARTSPELLDLG )
364  {
365  mrDocView.GetViewFrame()->GetDispatcher()->Execute( FN_SPELL_GRAMMAR_DIALOG, SfxCallMode::ASYNCHRON);
366  }
367 }
368 
370 {
371  if ( rCEvt.GetCommand() == CommandEventId::ContextMenu )
372  {
373  if ( !mrSidebarWin.IsProtected() &&
374  GetTextView() &&
376  {
377  Link<SpellCallbackInfo&,void> aLink = LINK(this, SidebarTextControl, OnlineSpellCallback);
379  }
380  else
381  {
382  Point aPos;
383  if (rCEvt.IsMouseEvent())
384  aPos = rCEvt.GetMousePosPixel();
385  else
386  {
387  const Size aSize = GetSizePixel();
388  aPos = Point( aSize.getWidth()/2, aSize.getHeight()/2 );
389  }
390  SfxDispatcher::ExecutePopup(this, &aPos);
391  }
392  }
393  else
394  if (rCEvt.GetCommand() == CommandEventId::Wheel)
395  {
397  {
398  const CommandWheelData* pData = rCEvt.GetWheelData();
399  if (pData->IsShift() || pData->IsMod1() || pData->IsMod2())
400  {
402  }
403  else
404  {
405  HandleScrollCommand( rCEvt, nullptr , mrSidebarWin.Scrollbar());
406  }
407  }
408  else
409  {
411  }
412  }
413  else
414  {
415  if ( GetTextView() )
416  GetTextView()->Command( rCEvt );
417  else
418  Window::Command(rCEvt);
419  }
420 }
421 
423 {
424  if (GetTextView())
425  return GetTextView()->GetSurroundingText();
426  return OUString();
427 }
428 
430 {
431  if( GetTextView() )
433  else
434  return Selection( 0, 0 );
435 }
436 
437 css::uno::Reference< css::accessibility::XAccessible > SidebarTextControl::CreateAccessible()
438 {
439 
441  css::uno::Reference< css::awt::XWindowPeer > xWinPeer( pAcc );
442  SetWindowPeer( xWinPeer, pAcc );
443 
444  css::uno::Reference< css::accessibility::XAccessible > xAcc( xWinPeer, css::uno::UNO_QUERY );
445  return xAcc;
446 }
447 
448 } } // end of namespace sw::sidebarwindows
449 
450 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
bool IsOptionSet(EOption eOption) const
virtual Point GetPosPixel() const
bool MouseButtonDown(const MouseEvent &)
SfxViewFrame * GetViewFrame() const
long Width() const
virtual void Command(const CommandEvent &rCEvt) override
bool IsMod1() const
const SvxFieldItem * GetFieldUnderMousePointer() const
void ExecuteSpellPopup(const Point &rPosPixel, Link< SpellCallbackInfo &, void > const *pCallBack)
OUString const & GetAuthorString(sal_uInt16 nPos=0) const
Definition: docredln.cxx:1729
#define KEY_PAGEDOWN
virtual css::uno::Reference< css::accessibility::XAccessible > CreateAccessible() override
#define KEY_PAGEUP
virtual void MouseMove(const MouseEvent &rMEvt) override
long GetOutOffXPixel() const
const StyleSettings & GetStyleSettings() const
bool MouseButtonUp(const MouseEvent &)
IMPL_LINK(SidebarTextControl, OnlineSpellCallback, SpellCallbackInfo &, rInfo, void)
virtual Size GetSizePixel() const
#define KEY_MOD1
void Draw(OutputDevice *pOutDev, const tools::Rectangle &rOutRect)
void ResizeIfNecessary(long aOldHeight, long aNewHeight)
bool IsShift() const
const MapMode & GetMapMode() const
sal_uInt16 GetCode() const
Dialog to specify the properties of date form field.
Definition: accfrmobj.cxx:38
void EnableMapMode(bool bEnable=true)
const CommandWheelData * GetWheelData() const
SfxViewShell * GetSfxViewShell() const
Definition: viewsh.hxx:444
virtual Selection GetSurroundingTextSelection() const override
OUString GetAppLangDateTimeString(const DateTime &)
Definition: uitool.cxx:819
bool HandleScrollCommand(const CommandEvent &rCmd, ScrollBar *pHScrl, ScrollBar *pVScrl)
const OUString & GetTargetFrame() const
void SetMapMode()
void ExecutePopup(const OUString &rResName, vcl::Window *pWin=nullptr, const Point *pPos=nullptr)
#define KEY_Y
#define KEY_F5
SwWrtShell & GetWrtShell() const
Definition: view.hxx:400
void Move(long nHorzMoveDelta, long nVertMoveDelta)
Used by the UI to modify the document model.
Definition: wrtsh.hxx:88
SwPostItHelper::SwLayoutStatus GetLayoutStatus()
weld::Window * GetFrameWeld() const
sal_Int64 WinBits
void LoadURL(SwViewShell &rVSh, const OUString &rURL, LoadUrlFlags nFilter, const OUString &rTargetFrameName)
Definition: wrtsh2.cxx:491
OUString GetSurroundingText() const
static void notifyInvalidation(SfxViewShell const *pThisView, const OString &rPayload)
virtual void Draw(OutputDevice *pDev, const Point &, const Size &, DrawFlags) override
virtual void MouseButtonDown(const MouseEvent &rMouseEvent) override
bool IsMouseEvent() const
const DateTime & GetTimeStamp(sal_uInt16 nPos=0) const
Definition: docredln.cxx:1734
bool GetHighContrastMode() const
SidebarTextControl(sw::annotation::SwAnnotationWin &rSidebarWin, WinBits nBits, SwView &rDocView, SwPostItMgr &rPostItMgr)
void DrawLine(const Point &rStartPt, const Point &rEndPt)
PointerStyle GetPointer(const Point &rPosPixel)
virtual void Paint(vcl::RenderContext &rRenderContext, const tools::Rectangle &rRect) override
void LogicInvalidate(const tools::Rectangle *pRectangle) override
EditView & GetEditView() const
const Point & GetMousePosPixel() const
SwDoc * GetDoc()
returns Doc. But be careful!
Definition: docsh.hxx:203
static bool DoesKeyChangeText(const KeyEvent &rKeyEvent)
void SetLineColor()
void SetWindowPeer(css::uno::Reference< css::awt::XWindowPeer > const &xPeer, VCLXWindow *pVCLXWindow)
DrawFlags
virtual void RequestHelp(const HelpEvent &rEvt) override
void dumpAsXml(xmlTextWriterPtr=nullptr) const
Dumps the entire nodes structure to the given destination (file nodes.xml in the current directory by...
Definition: docfmt.cxx:1950
bool IsMod2() const
SfxBindings & GetBindings()
#define KEY_ESCAPE
virtual void Invalidate(InvalidateFlags nFlags=InvalidateFlags::NONE)
void MakeVisible(const sw::annotation::SwAnnotationWin *pPostIt)
Definition: PostItMgr.cxx:1082
CommandEventId GetCommand() const
Outliner * GetOutliner() const
void SwitchToPostIt(sal_uInt16 aDirection)
virtual void dispose() override
const AllSettings & GetSettings() const
OUString SwResId(const char *pId)
Definition: swmodule.cxx:191
bool MouseMove(const MouseEvent &)
sal_uInt16 GetModifier() const
#define KEY_Z
void GrabFocus()
static void ShowQuickHelp(vcl::Window *pParent, const tools::Rectangle &rScreenRect, const OUString &rHelpText, QuickHelpFlags nStyle=QuickHelpFlags::NONE)
SwDocShell * GetDocShell()
Definition: view.cxx:1127
#define KEY_F12
const OUString & GetURL() const
const Point & GetMousePosPixel() const
Point PixelToLogic(const Point &rDevicePt) const
void AddEventListener(const Link< VclWindowEvent &, void > &rEventListener)
void SetPointer(PointerStyle)
const vcl::KeyCode & GetKeyCode() const
bool IsShift() const
bool IsMouseOver() const
#define FN_SPELL_GRAMMAR_DIALOG
Definition: cmdid.h:583
void Command(const CommandEvent &rCEvt)
virtual void KeyInput(const KeyEvent &rKeyEvt) override
bool PostKeyEvent(const KeyEvent &rKEvt, vcl::Window const *pFrameWin=nullptr)
bool IsMod1() const
long GetOutOffYPixel() const
const Point & GetPosPixel() const
sal_uInt16 GetFullCode() const
const SwRangeRedline * pRedl
Definition: crsrsh.hxx:101
virtual bool KeyInput(const KeyEvent &rKeyEvent)
static weld::Builder * CreateBuilder(weld::Widget *pParent, const OUString &rUIFile)
void InvalidateAll(bool bWithMsg)
#define KEY_INSERT
void RemoveEventListener(const Link< VclWindowEvent &, void > &rEventListener)
bool HandleWheelCommands(const CommandEvent &)
Definition: viewport.cxx:1209
bool GetContentAtPos(const Point &rPt, SwContentAtPos &rContentAtPos, bool bSetCursor=false, SwRect *pFieldRect=nullptr)
Definition: crstrvl.cxx:1268
long getHeight() const
virtual OUString GetSurroundingText() const override
rtl::OString toString() const
bool HasFocus() const
void Push(PushFlags nFlags=PushFlags::ALL)
long getWidth() const
void DrawGradient(const tools::Rectangle &rRect, const Gradient &rGradient)
void setWidth(long nWidth)
static OUString GetURLHelpText(const OUString &)
Selection GetSurroundingTextSelection() const
sw::annotation::SwAnnotationWin & mrSidebarWin
Definition: view.hxx:146
virtual void MouseButtonUp(const MouseEvent &rMEvt) override
const SvxFieldData * GetField() const
bool IsMod2() const
bool IsWrongSpelledWordAtPos(const Point &rPosPixel, bool bMarkIfWrong=false)
union SwContentAtPos::@25 aFnd
void Paint(const tools::Rectangle &rRect, OutputDevice *pTargetDevice=nullptr)