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