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 <sfx2/dispatch.hxx>
32#include <comphelper/lok.hxx>
33#include <tools/json_writer.hxx>
34#include <LibreOfficeKit/LibreOfficeKitEnums.h>
35
36#include <swmodule.hxx>
37#include <wrtsh.hxx>
38#include <view.hxx>
39#include <IMark.hxx>
40#include <doc.hxx>
42#include <IDocumentUndoRedo.hxx>
43#include <SwRewriter.hxx>
44#include <strings.hrc>
46
47using namespace ::com::sun::star;
48
49bool SwWrtShell::MoveBookMark( BookMarkMove eFuncId, const ::sw::mark::IMark* const pMark)
50{
52 (this->*m_fnKillSel)( nullptr, false );
53
54 bool bRet = true;
55 switch(eFuncId)
56 {
57 case BOOKMARK_INDEX:bRet = SwCursorShell::GotoMark( pMark );break;
60 default:;//prevent warning
61 }
62
63 if( bRet && IsSelFrameMode() )
64 {
67 }
68 if( IsSelection() )
69 {
72 }
73 return bRet;
74}
75
77{
78 (this->*m_fnKillSel)( nullptr, false );
79
80 bool bRet = SwCursorShell::GotoFormatField( rField );
81 if( bRet && IsSelFrameMode() )
82 {
85 }
86
87 if( IsSelection() )
88 {
91 }
92
93 return bRet;
94}
95
97{
98 std::shared_ptr<SwContentControl> pContentControl = rContentControl.GetContentControl();
99 if (IsFrameSelected() && pContentControl && pContentControl->GetPicture())
100 {
101 // A frame is already selected, and its anchor is inside a picture content control.
102 if (pContentControl->GetShowingPlaceHolder())
103 {
104 // Replace the placeholder image with a real one.
107 {
108 tools::JsonWriter aJson;
109 aJson.put("action", "change-picture");
110 std::unique_ptr<char, o3tl::free_delete> pJson(aJson.extractData());
111 GetSfxViewShell()->libreOfficeKitViewCallback(LOK_CALLBACK_CONTENT_CONTROL,
112 pJson.get());
113 }
114 else
115 {
116 GetView().GetViewFrame()->GetDispatcher()->Execute(SID_CHANGE_PICTURE,
117 SfxCallMode::SYNCHRON);
118 }
119 pContentControl->SetShowingPlaceHolder(false);
120 }
121 return true;
122 }
123
124 (this->*m_fnKillSel)(nullptr, false);
125
126 bool bRet = SwCursorShell::GotoFormatContentControl(rContentControl);
127
128 if (bRet && pContentControl && pContentControl->GetCheckbox())
129 {
130 // Checkbox: GotoFormatContentControl() selected the old state.
131 LockView(/*bViewLocked=*/true);
132 OUString aOldState;
133 OUString aNewState;
134 if (pContentControl->GetChecked())
135 {
136 aOldState = pContentControl->GetCheckedState();
137 aNewState = pContentControl->GetUncheckedState();
138 }
139 else
140 {
141 aOldState = pContentControl->GetUncheckedState();
142 aNewState = pContentControl->GetCheckedState();
143 }
144 SwRewriter aRewriter;
145 aRewriter.AddRule(UndoArg1, aOldState);
146 aRewriter.AddRule(UndoArg2, SwResId(STR_YIELDS));
147 aRewriter.AddRule(UndoArg3, aNewState);
149
150 // Toggle the state.
151 pContentControl->SetReadWrite(true);
152 DelLeft();
153 pContentControl->SetChecked(!pContentControl->GetChecked());
154 Insert(aNewState);
155 pContentControl->SetReadWrite(false);
156
158 LockView(/*bViewLocked=*/false);
159 ShowCursor();
160 }
161 else if (bRet && pContentControl && pContentControl->GetSelectedListItem())
162 {
163 // Dropdown: GotoFormatContentControl() selected the old content.
164 size_t nSelectedListItem = *pContentControl->GetSelectedListItem();
165 LockView(/*bViewLocked=*/true);
166 OUString aOldState = GetCursorDescr();
167 OUString aNewState = pContentControl->GetListItems()[nSelectedListItem].ToString();
168 SwRewriter aRewriter;
169 aRewriter.AddRule(UndoArg1, aOldState);
170 aRewriter.AddRule(UndoArg2, SwResId(STR_YIELDS));
171 aRewriter.AddRule(UndoArg3, SwResId(STR_START_QUOTE) + aNewState + SwResId(STR_END_QUOTE));
173
174 // Update the content.
175 pContentControl->SetReadWrite(true);
176 DelLeft();
177 pContentControl->SetSelectedListItem(std::nullopt);
178 Insert(aNewState);
179 pContentControl->SetReadWrite(false);
180
182 LockView(/*bViewLocked=*/false);
183 ShowCursor();
184 }
185 else if (bRet && pContentControl && pContentControl->GetSelectedDate())
186 {
187 // Date: GotoFormatContentControl() selected the old content.
188 LockView(/*bViewLocked=*/true);
189 OUString aOldState = GetCursorDescr();
190 OUString aNewState = pContentControl->GetDateString();
191 SwRewriter aRewriter;
192 aRewriter.AddRule(UndoArg1, aOldState);
193 aRewriter.AddRule(UndoArg2, SwResId(STR_YIELDS));
194 aRewriter.AddRule(UndoArg3, SwResId(STR_START_QUOTE) + aNewState + SwResId(STR_END_QUOTE));
196
197 // Write the doc model.
198 pContentControl->SetCurrentDateValue(*pContentControl->GetSelectedDate());
199 pContentControl->SetSelectedDate(std::nullopt);
200
201 // Update the content.
202 DelLeft();
203 Insert(aNewState);
204
206 LockView(/*bViewLocked=*/false);
207 ShowCursor();
208 }
209
210 if (bRet && IsSelFrameMode())
211 {
214 }
215
216 if (IsSelection())
217 {
220 }
221
222 return bRet;
223}
224
226{
227 (this->*m_fnKillSel)( nullptr, false );
228 bool bRet = SwCursorShell::GotoFieldmark(pMark);
229 if( bRet && IsSelFrameMode() )
230 {
233 }
234 if( IsSelection() )
235 {
238 }
239 return bRet;
240}
241
242// Invalidate FontWork-Slots
243
245{
246 static sal_uInt16 const aInval[] =
247 {
248 SID_ATTR_FILL_STYLE, SID_ATTR_FILL_COLOR, SID_ATTR_LINE_STYLE,
249 SID_ATTR_LINE_WIDTH, SID_ATTR_LINE_COLOR,
250 /*AF: these may be needed for the sidebar.
251 SID_SVX_AREA_TRANSPARENCY, SID_SVX_AREA_TRANSP_GRADIENT,
252 SID_SVX_AREA_TRANS_TYPE,
253 */
254 0
255 };
256
258
259 bool bOldVal = g_bNoInterrupt;
260 g_bNoInterrupt = true; // Trick to run AttrChangedNotify by timer.
261 GetView().AttrChangedNotify(nullptr);
262 g_bNoInterrupt = bOldVal;
263}
264
265void SwWrtShell::GotoMark( const OUString& rName )
266{
268 if (ppMark == getIDocumentMarkAccess()->getAllMarksEnd())
269 return;
270 MoveBookMark( BOOKMARK_INDEX, *ppMark );
271}
272
273void SwWrtShell::GotoMark( const ::sw::mark::IMark* const pMark )
274{
276}
277
279{
280 if ( !getIDocumentMarkAccess()->getBookmarksCount() )
281 {
282 SvxSearchDialogWrapper::SetSearchLabel( SearchLabel::NavElementNotFound );
283 return false;
284 }
285 LockView( true );
286 bool bRet = MoveBookMark( BOOKMARK_NEXT );
287 if ( !bRet )
288 {
289 MoveBookMark( BOOKMARK_INDEX, *getIDocumentMarkAccess()->getBookmarksBegin() );
290 SvxSearchDialogWrapper::SetSearchLabel( SearchLabel::EndWrapped );
291 }
292 else
293 SvxSearchDialogWrapper::SetSearchLabel( SearchLabel::Empty );
294 LockView( false );
295 ShowCursor();
296 return true;
297}
298
300{
301 if ( !getIDocumentMarkAccess()->getBookmarksCount() )
302 {
303 SvxSearchDialogWrapper::SetSearchLabel( SearchLabel::NavElementNotFound );
304 return false;
305 }
306 LockView( true );
307 bool bRet = MoveBookMark( BOOKMARK_PREV );
308 if ( !bRet )
309 {
310 MoveBookMark( BOOKMARK_INDEX, *( getIDocumentMarkAccess()->getBookmarksEnd() - 1 ) );
311 SvxSearchDialogWrapper::SetSearchLabel( SearchLabel::StartWrapped );
312 }
313 else
314 SvxSearchDialogWrapper::SetSearchLabel( SearchLabel::Empty );
315 LockView( false );
316 ShowCursor();
317 return true;
318}
319
320void SwWrtShell::ExecMacro( const SvxMacro& rMacro, OUString* pRet, SbxArray* pArgs )
321{
322 // execute macro, if it is allowed.
323 if ( IsMacroExecAllowed() )
324 {
325 GetDoc()->ExecMacro( rMacro, pRet, pArgs );
326 }
327}
328
329sal_uInt16 SwWrtShell::CallEvent( SvMacroItemId nEvent, const SwCallMouseEvent& rCallEvent,
330 bool bChkPtr)
331{
332 return GetDoc()->CallEvent( nEvent, rCallEvent, bChkPtr );
333}
334
335 // If a util::URL-Button is selected, return its util::URL
336 // otherwise an empty string.
337bool SwWrtShell::GetURLFromButton( OUString& rURL, OUString& rDescr ) const
338{
339 bool bRet = false;
340 const SdrView *pDView = GetDrawView();
341 if( pDView )
342 {
343 // A fly is precisely achievable if it is selected.
344 const SdrMarkList &rMarkList = pDView->GetMarkedObjectList();
345
346 if (rMarkList.GetMark(0))
347 {
348 SdrUnoObj* pUnoCtrl = dynamic_cast<SdrUnoObj*>( rMarkList.GetMark(0)->GetMarkedSdrObj() );
349 if (pUnoCtrl && SdrInventor::FmForm == pUnoCtrl->GetObjInventor())
350 {
351 const uno::Reference< awt::XControlModel >& xControlModel = pUnoCtrl->GetUnoControlModel();
352
353 OSL_ENSURE( xControlModel.is(), "UNO-Control without Model" );
354 if( !xControlModel.is() )
355 return bRet;
356
357 uno::Reference< beans::XPropertySet > xPropSet(xControlModel, uno::UNO_QUERY);
358
359 uno::Any aTmp;
360
361 uno::Reference< beans::XPropertySetInfo > xInfo = xPropSet->getPropertySetInfo();
362 if(xInfo->hasPropertyByName( "ButtonType" ))
363 {
364 aTmp = xPropSet->getPropertyValue( "ButtonType" );
365 form::FormButtonType eTmpButtonType;
366 aTmp >>= eTmpButtonType;
367 if( form::FormButtonType_URL == eTmpButtonType)
368 {
369 // Label
370 aTmp = xPropSet->getPropertyValue( "Label" );
371 OUString uTmp;
372 if( (aTmp >>= uTmp) && !uTmp.isEmpty())
373 {
374 rDescr = uTmp;
375 }
376
377 // util::URL
378 aTmp = xPropSet->getPropertyValue( "TargetURL" );
379 if( (aTmp >>= uTmp) && !uTmp.isEmpty())
380 {
381 rURL = uTmp;
382 }
383 bRet = true;
384 }
385 }
386 }
387 }
388 }
389
390 return bRet;
391}
392
393/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
@ UndoArg1
Definition: SwRewriter.hxx:29
@ UndoArg3
Definition: SwRewriter.hxx:31
@ UndoArg2
Definition: SwRewriter.hxx:30
wrapper iterator: wraps iterator of implementation while hiding MarkBase class; only IMark instances ...
virtual const_iterator_t findMark(const OUString &rMark) const =0
Finds a mark by name.
virtual SwUndoId EndUndo(SwUndoId const eUndoId, SwRewriter const *const pRewriter)=0
Closes undo block.
virtual SwUndoId StartUndo(SwUndoId const eUndoId, SwRewriter const *const pRewriter)=0
Opens undo block.
SdrMark * GetMark(size_t nNum) const
const SdrMarkList & GetMarkedObjectList() const
SdrObject * GetMarkedSdrObj() const
virtual SdrInventor GetObjInventor() const
const css::uno::Reference< css::awt::XControlModel > & GetUnoControlModel() const
void Invalidate(sal_uInt16 nId)
const SfxPoolItem * Execute(sal_uInt16 nSlot, SfxCallMode nCall=SfxCallMode::SLOT, const SfxPoolItem **pArgs=nullptr, sal_uInt16 nModi=0, const SfxPoolItem **pInternalArgs=nullptr)
SfxBindings & GetBindings()
SfxDispatcher * GetDispatcher()
SfxViewFrame * GetViewFrame() const
virtual void libreOfficeKitViewCallback(int nType, const char *pPayload) const override
static void SetSearchLabel(const SearchLabel &rSL)
OUString GetCursorDescr() const
Returns textual description of the current selection.
Definition: crsrsh.cxx:3670
void ShowCursor()
Definition: crsrsh.cxx:2410
bool IsMacroExecAllowed() const
Definition: crsrsh.hxx:862
bool GotoFieldmark(const ::sw::mark::IFieldmark *const pMark)
Definition: crbm.cxx:305
bool GoPrevBookmark()
Definition: crbm.cxx:236
bool GotoMark(const ::sw::mark::IMark *const pMark)
Definition: crbm.cxx:187
bool IsSelection() const
Definition: crsrsh.hxx:899
bool GoNextBookmark()
Definition: crbm.cxx:203
bool GotoFormatField(const SwFormatField &rField)
Definition: crstrvl.cxx:870
bool GotoFormatContentControl(const SwFormatContentControl &rContentControl)
Definition: crstrvl.cxx:829
sal_uInt16 CallEvent(SvMacroItemId nEvent, const SwCallMouseEvent &rCallEvent, bool bChkPtr=false)
Definition: docbasic.cxx:130
void ExecMacro(const SvxMacro &rMacro, OUString *pRet, SbxArray *pArgs)
Definition: docbasic.cxx:76
bool IsFrameSelected() const
Definition: feshview.cxx:1253
SfxPoolItem subclass that wraps an SwContentControl.
const std::shared_ptr< SwContentControl > & GetContentControl() const
void AddRule(SwUndoArg eWhat, const OUString &rWith)
Definition: SwRewriter.cxx:25
const IDocumentMarkAccess * getIDocumentMarkAccess() const
Provides access to the document bookmark interface.
Definition: viewsh.cxx:2807
IDocumentUndoRedo const & GetIDocumentUndoRedo() const
Provides access to the document undo/redo interface.
Definition: viewsh.cxx:2821
SwDoc * GetDoc() const
Definition: viewsh.hxx:290
SfxViewShell * GetSfxViewShell() const
Definition: viewsh.hxx:451
void LockView(bool b)
Definition: viewsh.hxx:472
SdrView * GetDrawView()
Definition: vnew.cxx:373
void StopShellTimer()
Definition: view.cxx:1819
bool IsSelFrameMode() const
Definition: wrtsh.hxx:177
SAL_DLLPRIVATE tools::Long SetCursorKillSel(const Point *, bool bProp)
Definition: select.cxx:316
bool GotoContentControl(const SwFormatContentControl &rContentControl)
Definition: wrtsh3.cxx:96
bool GoNextBookmark()
Definition: wrtsh3.cxx:278
void LeaveSelFrameMode()
Definition: select.cxx:720
@ BOOKMARK_PREV
Definition: wrtsh.hxx:638
@ BOOKMARK_INDEX
Definition: wrtsh.hxx:636
@ BOOKMARK_NEXT
Definition: wrtsh.hxx:637
bool DelLeft()
Definition: delete.cxx:134
void addCurrentPosition()
Definition: wrtsh1.cxx:1852
bool GotoFieldmark(::sw::mark::IFieldmark const *const pMark)
Definition: wrtsh3.cxx:225
void GotoMark(const ::sw::mark::IMark *const pMark)
Definition: wrtsh3.cxx:273
bool GetURLFromButton(OUString &rURL, OUString &rDescr) const
Definition: wrtsh3.cxx:337
SAL_DLLPRIVATE bool MoveBookMark(BookMarkMove eFuncId, const ::sw::mark::IMark *const pMark=nullptr)
Definition: wrtsh3.cxx:49
void Insert(const OUString &)
Definition: wrtsh1.cxx:224
sal_uInt16 CallEvent(SvMacroItemId nEvent, const SwCallMouseEvent &rCallEvent, bool bCheckPtr=false)
Definition: wrtsh3.cxx:329
SELECTFUNC m_fnKillSel
Definition: wrtsh.hxx:117
void ExecMacro(const SvxMacro &rMacro, OUString *pRet=nullptr, SbxArray *pArgs=nullptr)
Definition: wrtsh3.cxx:320
bool GoPrevBookmark()
Definition: wrtsh3.cxx:299
bool GotoField(const SwFormatField &rField)
Definition: wrtsh3.cxx:76
SELECTFUNC m_fnSetCursor
Definition: wrtsh.hxx:115
virtual void DrawSelChanged() override
Definition: wrtsh3.cxx:244
void UnSelectFrame()
Definition: select.cxx:323
tools::Long ResetSelect(const Point *, bool)
Definition: select.cxx:333
const SwView & GetView() const
Definition: wrtsh.hxx:438
void put(const char *pPropName, const OUString &rPropValue)
char * extractData()
SvMacroItemId
OUString SwResId(TranslateId aId)
Definition: swmodule.cxx:165
bool g_bNoInterrupt
Definition: swmodule.cxx:115