LibreOffice Module sw (master)  1
wrtsh3.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 <svx/svxids.hrc>
21 #include <sfx2/app.hxx>
22 #include <sfx2/bindings.hxx>
23 #include <sfx2/viewfrm.hxx>
24 #include <svx/svdmark.hxx>
25 #include <svx/svdview.hxx>
26 #include <svx/svdouno.hxx>
27 #include <svx/srchdlg.hxx>
28 #include <com/sun/star/form/FormButtonType.hpp>
29 #include <com/sun/star/beans/XPropertySet.hpp>
30 #include <osl/diagnose.h>
31 #include <swmodule.hxx>
32 #include <wrtsh.hxx>
33 #include <view.hxx>
34 #include <IMark.hxx>
35 #include <doc.hxx>
36 
37 using namespace ::com::sun::star;
38 
39 bool SwWrtShell::MoveBookMark( BookMarkMove eFuncId, const ::sw::mark::IMark* const pMark)
40 {
42  (this->*m_fnKillSel)( nullptr, false );
43 
44  bool bRet = true;
45  switch(eFuncId)
46  {
47  case BOOKMARK_INDEX:bRet = SwCursorShell::GotoMark( pMark );break;
48  case BOOKMARK_NEXT: bRet = SwCursorShell::GoNextBookmark();break;
49  case BOOKMARK_PREV: bRet = SwCursorShell::GoPrevBookmark();break;
50  default:;//prevent warning
51  }
52 
53  if( bRet && IsSelFrameMode() )
54  {
55  UnSelectFrame();
57  }
58  if( IsSelection() )
59  {
62  }
63  return bRet;
64 }
65 
66 bool SwWrtShell::GotoField( const SwFormatField& rField )
67 {
68  (this->*m_fnKillSel)( nullptr, false );
69 
70  bool bRet = SwCursorShell::GotoFormatField( rField );
71  if( bRet && IsSelFrameMode() )
72  {
73  UnSelectFrame();
75  }
76 
77  if( IsSelection() )
78  {
81  }
82 
83  return bRet;
84 }
85 
87 {
88  (this->*m_fnKillSel)( nullptr, false );
89  bool bRet = SwCursorShell::GotoFieldmark(pMark);
90  if( bRet && IsSelFrameMode() )
91  {
92  UnSelectFrame();
94  }
95  if( IsSelection() )
96  {
99  }
100  return bRet;
101 }
102 
103 // Invalidate FontWork-Slots
104 
106 {
107  static sal_uInt16 const aInval[] =
108  {
109  SID_ATTR_FILL_STYLE, SID_ATTR_FILL_COLOR, SID_ATTR_LINE_STYLE,
110  SID_ATTR_LINE_WIDTH, SID_ATTR_LINE_COLOR,
111  /*AF: these may be needed for the sidebar.
112  SID_SVX_AREA_TRANSPARENCY, SID_SVX_AREA_TRANSP_GRADIENT,
113  SID_SVX_AREA_TRANS_TYPE,
114  */
115  0
116  };
117 
119 
120  bool bOldVal = g_bNoInterrupt;
121  g_bNoInterrupt = true; // Trick to run AttrChangedNotify by timer.
122  GetView().AttrChangedNotify(nullptr);
123  g_bNoInterrupt = bOldVal;
124 }
125 
126 void SwWrtShell::GotoMark( const OUString& rName )
127 {
129  if (ppMark == getIDocumentMarkAccess()->getAllMarksEnd())
130  return;
131  MoveBookMark( BOOKMARK_INDEX, *ppMark );
132 }
133 
134 void SwWrtShell::GotoMark( const ::sw::mark::IMark* const pMark )
135 {
136  MoveBookMark( BOOKMARK_INDEX, pMark );
137 }
138 
140 {
141  if ( !getIDocumentMarkAccess()->getBookmarksCount() )
142  {
143  SvxSearchDialogWrapper::SetSearchLabel( SearchLabel::NavElementNotFound );
144  return false;
145  }
146  LockView( true );
147  bool bRet = MoveBookMark( BOOKMARK_NEXT );
148  if ( !bRet )
149  {
150  MoveBookMark( BOOKMARK_INDEX, *getIDocumentMarkAccess()->getBookmarksBegin() );
151  SvxSearchDialogWrapper::SetSearchLabel( SearchLabel::EndWrapped );
152  }
153  else
154  SvxSearchDialogWrapper::SetSearchLabel( SearchLabel::Empty );
155  LockView( false );
156  ShowCursor();
157  return true;
158 }
159 
161 {
162  if ( !getIDocumentMarkAccess()->getBookmarksCount() )
163  {
164  SvxSearchDialogWrapper::SetSearchLabel( SearchLabel::NavElementNotFound );
165  return false;
166  }
167  LockView( true );
168  bool bRet = MoveBookMark( BOOKMARK_PREV );
169  if ( !bRet )
170  {
171  MoveBookMark( BOOKMARK_INDEX, *( getIDocumentMarkAccess()->getBookmarksEnd() - 1 ) );
172  SvxSearchDialogWrapper::SetSearchLabel( SearchLabel::StartWrapped );
173  }
174  else
175  SvxSearchDialogWrapper::SetSearchLabel( SearchLabel::Empty );
176  LockView( false );
177  ShowCursor();
178  return true;
179 }
180 
181 void SwWrtShell::ExecMacro( const SvxMacro& rMacro, OUString* pRet, SbxArray* pArgs )
182 {
183  // execute macro, if it is allowed.
184  if ( IsMacroExecAllowed() )
185  {
186  GetDoc()->ExecMacro( rMacro, pRet, pArgs );
187  }
188 }
189 
190 sal_uInt16 SwWrtShell::CallEvent( SvMacroItemId nEvent, const SwCallMouseEvent& rCallEvent,
191  bool bChkPtr)
192 {
193  return GetDoc()->CallEvent( nEvent, rCallEvent, bChkPtr );
194 }
195 
196  // If a util::URL-Button is selected, return its util::URL
197  // otherwise an empty string.
198 bool SwWrtShell::GetURLFromButton( OUString& rURL, OUString& rDescr ) const
199 {
200  bool bRet = false;
201  const SdrView *pDView = GetDrawView();
202  if( pDView )
203  {
204  // A fly is precisely achievable if it is selected.
205  const SdrMarkList &rMarkList = pDView->GetMarkedObjectList();
206 
207  if (rMarkList.GetMark(0))
208  {
209  SdrUnoObj* pUnoCtrl = dynamic_cast<SdrUnoObj*>( rMarkList.GetMark(0)->GetMarkedSdrObj() );
210  if (pUnoCtrl && SdrInventor::FmForm == pUnoCtrl->GetObjInventor())
211  {
212  const uno::Reference< awt::XControlModel >& xControlModel = pUnoCtrl->GetUnoControlModel();
213 
214  OSL_ENSURE( xControlModel.is(), "UNO-Control without Model" );
215  if( !xControlModel.is() )
216  return bRet;
217 
218  uno::Reference< beans::XPropertySet > xPropSet(xControlModel, uno::UNO_QUERY);
219 
220  uno::Any aTmp;
221 
222  uno::Reference< beans::XPropertySetInfo > xInfo = xPropSet->getPropertySetInfo();
223  if(xInfo->hasPropertyByName( "ButtonType" ))
224  {
225  aTmp = xPropSet->getPropertyValue( "ButtonType" );
226  form::FormButtonType eTmpButtonType;
227  aTmp >>= eTmpButtonType;
228  if( form::FormButtonType_URL == eTmpButtonType)
229  {
230  // Label
231  aTmp = xPropSet->getPropertyValue( "Label" );
232  OUString uTmp;
233  if( (aTmp >>= uTmp) && !uTmp.isEmpty())
234  {
235  rDescr = uTmp;
236  }
237 
238  // util::URL
239  aTmp = xPropSet->getPropertyValue( "TargetURL" );
240  if( (aTmp >>= uTmp) && !uTmp.isEmpty())
241  {
242  rURL = uTmp;
243  }
244  bRet = true;
245  }
246  }
247  }
248  }
249  }
250 
251  return bRet;
252 }
253 
254 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
SfxViewFrame * GetViewFrame() const
virtual void DrawSelChanged() override
Definition: wrtsh3.cxx:105
SdrView * GetDrawView()
Definition: vnew.cxx:373
bool GetURLFromButton(OUString &rURL, OUString &rDescr) const
Definition: wrtsh3.cxx:198
wrapper iterator: wraps iterator of implementation while hiding MarkBase class; only IMark instances ...
SAL_DLLPRIVATE bool MoveBookMark(BookMarkMove eFuncId, const ::sw::mark::IMark *const pMark=nullptr)
Definition: wrtsh3.cxx:39
SvMacroItemId
SdrMark * GetMark(size_t nNum) const
void Invalidate(sal_uInt16 nId)
bool GotoMark(const ::sw::mark::IMark *const pMark)
Definition: crbm.cxx:184
sal_uInt16 CallEvent(SvMacroItemId nEvent, const SwCallMouseEvent &rCallEvent, bool bChkPtr=false)
Definition: docbasic.cxx:130
tools::Long ResetSelect(const Point *, bool)
Definition: select.cxx:333
const SwView & GetView() const
Definition: wrtsh.hxx:431
virtual const_iterator_t findMark(const OUString &rMark) const =0
Finds a mark by name.
SELECTFUNC m_fnSetCursor
Definition: wrtsh.hxx:112
SwDoc * GetDoc() const
Definition: viewsh.hxx:281
const IDocumentMarkAccess * getIDocumentMarkAccess() const
Provides access to the document bookmark interface.
Definition: viewsh.cxx:2672
void ExecMacro(const SvxMacro &rMacro, OUString *pRet=nullptr, SbxArray *pArgs=nullptr)
Definition: wrtsh3.cxx:181
SdrObject * GetMarkedSdrObj() const
bool IsSelection() const
Definition: crsrsh.hxx:879
bool GoNextBookmark()
Definition: wrtsh3.cxx:139
SfxBindings & GetBindings()
const SdrMarkList & GetMarkedObjectList() const
bool GotoFieldmark(const ::sw::mark::IFieldmark *const pMark)
Definition: crbm.cxx:302
bool GoNextBookmark()
Definition: crbm.cxx:200
static void SetSearchLabel(const SearchLabel &rSL)
bool GoPrevBookmark()
Definition: wrtsh3.cxx:160
virtual SdrInventor GetObjInventor() const
bool IsMacroExecAllowed() const
Definition: crsrsh.hxx:837
void GotoMark(const ::sw::mark::IMark *const pMark)
Definition: wrtsh3.cxx:134
void addCurrentPosition()
Definition: wrtsh1.cxx:1578
bool GotoField(const SwFormatField &rField)
Definition: wrtsh3.cxx:66
void LockView(bool b)
Definition: viewsh.hxx:462
void ExecMacro(const SvxMacro &rMacro, OUString *pRet, SbxArray *pArgs)
Definition: docbasic.cxx:76
void ShowCursor()
Definition: crsrsh.cxx:2390
void UnSelectFrame()
Definition: select.cxx:323
bool GoPrevBookmark()
Definition: crbm.cxx:233
SAL_DLLPRIVATE tools::Long SetCursorKillSel(const Point *, bool bProp)
Definition: select.cxx:316
sal_uInt16 CallEvent(SvMacroItemId nEvent, const SwCallMouseEvent &rCallEvent, bool bCheckPtr=false)
Definition: wrtsh3.cxx:190
void LeaveSelFrameMode()
Definition: select.cxx:720
const css::uno::Reference< css::awt::XControlModel > & GetUnoControlModel() const
bool g_bNoInterrupt
Definition: swmodule.cxx:115
bool GotoFieldmark(::sw::mark::IFieldmark const *const pMark)
Definition: wrtsh3.cxx:86
bool GotoFormatField(const SwFormatField &rField)
Definition: crstrvl.cxx:834
SELECTFUNC m_fnKillSel
Definition: wrtsh.hxx:114
bool IsSelFrameMode() const
Definition: wrtsh.hxx:173