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 bool bOnlyRefresh)
98{
99 std::shared_ptr<SwContentControl> pContentControl = rContentControl.GetContentControl();
100 if (IsFrameSelected() && pContentControl && pContentControl->GetPicture())
101 {
102 // A frame is already selected, and its anchor is inside a picture content control.
103 if (pContentControl->GetShowingPlaceHolder())
104 {
105 // Replace the placeholder image with a real one.
108 {
109 tools::JsonWriter aJson;
110 aJson.put("action", "change-picture");
111 OString pJson(aJson.finishAndGetAsOString());
112 GetSfxViewShell()->libreOfficeKitViewCallback(LOK_CALLBACK_CONTENT_CONTROL,
113 pJson);
114 }
115 else
116 {
117 GetView().GetViewFrame().GetDispatcher()->Execute(SID_CHANGE_PICTURE,
118 SfxCallMode::SYNCHRON);
119 }
120 pContentControl->SetShowingPlaceHolder(false);
121 }
122 return true;
123 }
124
125 (this->*m_fnKillSel)(nullptr, false);
126
127 bool bRet = SwCursorShell::GotoFormatContentControl(rContentControl);
128
129 if (bRet && pContentControl && pContentControl->GetCheckbox())
130 {
131 // Checkbox: GotoFormatContentControl() selected the old state.
132 LockView(/*bViewLocked=*/true);
133 OUString aOldState = GetCursorDescr();
134 OUString aNewState;
135 if (pContentControl->GetChecked())
136 aNewState = bOnlyRefresh ? pContentControl->GetCheckedState()
137 : pContentControl->GetUncheckedState();
138 else
139 aNewState = bOnlyRefresh ? pContentControl->GetUncheckedState()
140 : pContentControl->GetCheckedState();
141
142 SwRewriter aRewriter;
143 aRewriter.AddRule(UndoArg1, aOldState);
144 aRewriter.AddRule(UndoArg2, SwResId(STR_YIELDS));
145 aRewriter.AddRule(UndoArg3, aNewState);
146 GetIDocumentUndoRedo().StartUndo(SwUndoId::REPLACE, &aRewriter);
147
148 // Toggle the state.
149 pContentControl->SetReadWrite(true);
150 DelLeft();
151 if (!bOnlyRefresh)
152 pContentControl->SetChecked(!pContentControl->GetChecked());
153 Insert(aNewState);
154 pContentControl->SetReadWrite(false);
155
156 GetIDocumentUndoRedo().EndUndo(SwUndoId::REPLACE, &aRewriter);
157 LockView(/*bViewLocked=*/false);
158 ShowCursor();
159 }
160 else if (bRet && pContentControl && pContentControl->GetSelectedListItem())
161 {
162 // Dropdown: GotoFormatContentControl() selected the old content.
163 size_t nSelectedListItem = *pContentControl->GetSelectedListItem();
164 LockView(/*bViewLocked=*/true);
165 OUString aOldState = GetCursorDescr();
166 OUString aNewState = pContentControl->GetListItems()[nSelectedListItem].ToString();
167 SwRewriter aRewriter;
168 aRewriter.AddRule(UndoArg1, aOldState);
169 aRewriter.AddRule(UndoArg2, SwResId(STR_YIELDS));
170 aRewriter.AddRule(UndoArg3, SwResId(STR_START_QUOTE) + aNewState + SwResId(STR_END_QUOTE));
171 GetIDocumentUndoRedo().StartUndo(SwUndoId::REPLACE, &aRewriter);
172
173 // Update the content.
174 pContentControl->SetReadWrite(true);
175 DelLeft();
176 pContentControl->SetSelectedListItem(std::nullopt);
177 Insert(aNewState);
178 pContentControl->SetReadWrite(false);
179
180 GetIDocumentUndoRedo().EndUndo(SwUndoId::REPLACE, &aRewriter);
181 LockView(/*bViewLocked=*/false);
182 ShowCursor();
183 }
184 else if (bRet && pContentControl && pContentControl->GetSelectedDate())
185 {
186 // Date: GotoFormatContentControl() selected the old content.
187 LockView(/*bViewLocked=*/true);
188 OUString aOldState = GetCursorDescr();
189 OUString aNewState = pContentControl->GetDateString();
190 SwRewriter aRewriter;
191 aRewriter.AddRule(UndoArg1, aOldState);
192 aRewriter.AddRule(UndoArg2, SwResId(STR_YIELDS));
193 aRewriter.AddRule(UndoArg3, SwResId(STR_START_QUOTE) + aNewState + SwResId(STR_END_QUOTE));
194 GetIDocumentUndoRedo().StartUndo(SwUndoId::REPLACE, &aRewriter);
195
196 // Write the doc model.
197 pContentControl->SetCurrentDateValue(*pContentControl->GetSelectedDate());
198 pContentControl->SetSelectedDate(std::nullopt);
199
200 // Update the content.
201 DelLeft();
202 Insert(aNewState);
203
204 GetIDocumentUndoRedo().EndUndo(SwUndoId::REPLACE, &aRewriter);
205 LockView(/*bViewLocked=*/false);
206 ShowCursor();
207 }
208
209 if (bRet && IsSelFrameMode())
210 {
213 }
214
215 if (IsSelection())
216 {
219 }
220
221 return bRet;
222}
223
224bool SwWrtShell::GotoFieldmark(::sw::mark::IFieldmark const * const pMark)
225{
226 (this->*m_fnKillSel)( nullptr, false );
227 bool bRet = SwCursorShell::GotoFieldmark(pMark);
228 if( bRet && IsSelFrameMode() )
229 {
232 }
233 if( IsSelection() )
234 {
237 }
238 return bRet;
239}
240
241// Invalidate FontWork-Slots
242
244{
245 static sal_uInt16 const aInval[] =
246 {
247 SID_ATTR_FILL_STYLE, SID_ATTR_FILL_COLOR, SID_ATTR_LINE_STYLE,
248 SID_ATTR_LINE_WIDTH, SID_ATTR_LINE_COLOR,
249 /*AF: these may be needed for the sidebar.
250 SID_SVX_AREA_TRANSPARENCY, SID_SVX_AREA_TRANSP_GRADIENT,
251 SID_SVX_AREA_TRANS_TYPE,
252 */
253 0
254 };
255
257
258 bool bOldVal = g_bNoInterrupt;
259 g_bNoInterrupt = true; // Trick to run AttrChangedNotify by timer.
260 GetView().AttrChangedNotify(nullptr);
261 g_bNoInterrupt = bOldVal;
262}
263
264void SwWrtShell::GotoMark( const OUString& rName )
265{
267 if (ppMark == getIDocumentMarkAccess()->getAllMarksEnd())
268 return;
269 MoveBookMark( BOOKMARK_INDEX, *ppMark );
270}
271
272void SwWrtShell::GotoMark( const ::sw::mark::IMark* const pMark )
273{
275}
276
278{
279 if ( !getIDocumentMarkAccess()->getBookmarksCount() )
280 {
281 SvxSearchDialogWrapper::SetSearchLabel( SearchLabel::NavElementNotFound );
282 return false;
283 }
284 LockView( true );
285 bool bRet = MoveBookMark( BOOKMARK_NEXT );
286 if ( !bRet )
287 {
288 MoveBookMark( BOOKMARK_INDEX, *getIDocumentMarkAccess()->getBookmarksBegin() );
289 SvxSearchDialogWrapper::SetSearchLabel( SearchLabel::EndWrapped );
290 }
291 else
292 SvxSearchDialogWrapper::SetSearchLabel( SearchLabel::Empty );
293 LockView( false );
294 ShowCursor();
295 return true;
296}
297
299{
300 if ( !getIDocumentMarkAccess()->getBookmarksCount() )
301 {
302 SvxSearchDialogWrapper::SetSearchLabel( SearchLabel::NavElementNotFound );
303 return false;
304 }
305 LockView( true );
306 bool bRet = MoveBookMark( BOOKMARK_PREV );
307 if ( !bRet )
308 {
309 MoveBookMark( BOOKMARK_INDEX, *( getIDocumentMarkAccess()->getBookmarksEnd() - 1 ) );
310 SvxSearchDialogWrapper::SetSearchLabel( SearchLabel::StartWrapped );
311 }
312 else
313 SvxSearchDialogWrapper::SetSearchLabel( SearchLabel::Empty );
314 LockView( false );
315 ShowCursor();
316 return true;
317}
318
319void SwWrtShell::ExecMacro( const SvxMacro& rMacro, OUString* pRet, SbxArray* pArgs )
320{
321 // execute macro, if it is allowed.
322 if ( IsMacroExecAllowed() )
323 {
324 GetDoc()->ExecMacro( rMacro, pRet, pArgs );
325 }
326}
327
328sal_uInt16 SwWrtShell::CallEvent( SvMacroItemId nEvent, const SwCallMouseEvent& rCallEvent,
329 bool bChkPtr)
330{
331 return GetDoc()->CallEvent( nEvent, rCallEvent, bChkPtr );
332}
333
334 // If a util::URL-Button is selected, return its util::URL
335 // otherwise an empty string.
336bool SwWrtShell::GetURLFromButton( OUString& rURL, OUString& rDescr ) const
337{
338 bool bRet = false;
339 const SdrView *pDView = GetDrawView();
340 if( pDView )
341 {
342 // A fly is precisely achievable if it is selected.
343 const SdrMarkList &rMarkList = pDView->GetMarkedObjectList();
344
345 if (rMarkList.GetMark(0))
346 {
347 SdrUnoObj* pUnoCtrl = dynamic_cast<SdrUnoObj*>( rMarkList.GetMark(0)->GetMarkedSdrObj() );
348 if (pUnoCtrl && SdrInventor::FmForm == pUnoCtrl->GetObjInventor())
349 {
350 const uno::Reference< awt::XControlModel >& xControlModel = pUnoCtrl->GetUnoControlModel();
351
352 OSL_ENSURE( xControlModel.is(), "UNO-Control without Model" );
353 if( !xControlModel.is() )
354 return bRet;
355
356 uno::Reference< beans::XPropertySet > xPropSet(xControlModel, uno::UNO_QUERY);
357
358 uno::Any aTmp;
359
360 uno::Reference< beans::XPropertySetInfo > xInfo = xPropSet->getPropertySetInfo();
361 if(xInfo->hasPropertyByName( "ButtonType" ))
362 {
363 aTmp = xPropSet->getPropertyValue( "ButtonType" );
364 form::FormButtonType eTmpButtonType;
365 aTmp >>= eTmpButtonType;
366 if( form::FormButtonType_URL == eTmpButtonType)
367 {
368 // Label
369 aTmp = xPropSet->getPropertyValue( "Label" );
370 OUString uTmp;
371 if( (aTmp >>= uTmp) && !uTmp.isEmpty())
372 {
373 rDescr = uTmp;
374 }
375
376 // util::URL
377 aTmp = xPropSet->getPropertyValue( "TargetURL" );
378 if( (aTmp >>= uTmp) && !uTmp.isEmpty())
379 {
380 rURL = uTmp;
381 }
382 bRet = true;
383 }
384 }
385 }
386 }
387 }
388
389 return bRet;
390}
391
392/* 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.
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()
virtual void libreOfficeKitViewCallback(int nType, const OString &pPayload) const override
SfxViewFrame & GetViewFrame() const
static void SetSearchLabel(const SearchLabel &rSL)
OUString GetCursorDescr() const
Returns textual description of the current selection.
Definition: crsrsh.cxx:4009
void ShowCursor()
Definition: crsrsh.cxx:2710
bool IsMacroExecAllowed() const
Definition: crsrsh.hxx:873
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:910
bool GoNextBookmark()
Definition: crbm.cxx:203
bool GotoFormatField(const SwFormatField &rField)
Definition: crstrvl.cxx:1001
bool GotoFormatContentControl(const SwFormatContentControl &rContentControl)
Definition: crstrvl.cxx:834
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:1133
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:2821
IDocumentUndoRedo const & GetIDocumentUndoRedo() const
Provides access to the document undo/redo interface.
Definition: viewsh.cxx:2835
SwDoc * GetDoc() const
Definition: viewsh.hxx:308
SfxViewShell * GetSfxViewShell() const
Definition: viewsh.hxx:470
void LockView(bool b)
Definition: viewsh.hxx:491
SdrView * GetDrawView()
Definition: vnew.cxx:386
void StopShellTimer()
Definition: view.cxx:1836
bool IsSelFrameMode() const
Definition: wrtsh.hxx:177
SAL_DLLPRIVATE tools::Long SetCursorKillSel(const Point *, bool bProp)
Definition: select.cxx:325
bool GoNextBookmark()
Definition: wrtsh3.cxx:277
void LeaveSelFrameMode()
Definition: select.cxx:729
@ BOOKMARK_PREV
Definition: wrtsh.hxx:645
@ BOOKMARK_INDEX
Definition: wrtsh.hxx:643
@ BOOKMARK_NEXT
Definition: wrtsh.hxx:644
bool DelLeft()
Definition: delete.cxx:136
void addCurrentPosition()
Definition: wrtsh1.cxx:1869
bool GotoFieldmark(::sw::mark::IFieldmark const *const pMark)
Definition: wrtsh3.cxx:224
void GotoMark(const ::sw::mark::IMark *const pMark)
Definition: wrtsh3.cxx:272
bool GetURLFromButton(OUString &rURL, OUString &rDescr) const
Definition: wrtsh3.cxx:336
SAL_DLLPRIVATE bool MoveBookMark(BookMarkMove eFuncId, const ::sw::mark::IMark *const pMark=nullptr)
Definition: wrtsh3.cxx:49
void Insert(const OUString &)
Definition: wrtsh1.cxx:226
bool GotoContentControl(const SwFormatContentControl &rContentControl, bool bOnlyRefresh=false)
Definition: wrtsh3.cxx:96
sal_uInt16 CallEvent(SvMacroItemId nEvent, const SwCallMouseEvent &rCallEvent, bool bCheckPtr=false)
Definition: wrtsh3.cxx:328
SELECTFUNC m_fnKillSel
Definition: wrtsh.hxx:117
void ExecMacro(const SvxMacro &rMacro, OUString *pRet=nullptr, SbxArray *pArgs=nullptr)
Definition: wrtsh3.cxx:319
bool GoPrevBookmark()
Definition: wrtsh3.cxx:298
bool GotoField(const SwFormatField &rField)
Definition: wrtsh3.cxx:76
SELECTFUNC m_fnSetCursor
Definition: wrtsh.hxx:115
virtual void DrawSelChanged() override
Definition: wrtsh3.cxx:243
void UnSelectFrame()
Definition: select.cxx:332
tools::Long ResetSelect(const Point *, bool)
Definition: select.cxx:342
const SwView & GetView() const
Definition: wrtsh.hxx:443
void put(std::u16string_view pPropName, const OUString &rPropValue)
OString finishAndGetAsOString()
SvMacroItemId
OUString SwResId(TranslateId aId)
Definition: swmodule.cxx:168
bool g_bNoInterrupt
Definition: swmodule.cxx:115