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 DelLeft();
176 pContentControl->SetSelectedListItem(std::nullopt);
177 Insert(aNewState);
178
180 LockView(/*bViewLocked=*/false);
181 ShowCursor();
182 }
183 else if (bRet && pContentControl && pContentControl->GetSelectedDate())
184 {
185 // Date: GotoFormatContentControl() selected the old content.
186 LockView(/*bViewLocked=*/true);
187 OUString aOldState = GetCursorDescr();
188 OUString aNewState = pContentControl->GetDateString();
189 SwRewriter aRewriter;
190 aRewriter.AddRule(UndoArg1, aOldState);
191 aRewriter.AddRule(UndoArg2, SwResId(STR_YIELDS));
192 aRewriter.AddRule(UndoArg3, SwResId(STR_START_QUOTE) + aNewState + SwResId(STR_END_QUOTE));
194
195 // Write the doc model.
196 pContentControl->SetCurrentDateValue(*pContentControl->GetSelectedDate());
197 pContentControl->SetSelectedDate(std::nullopt);
198
199 // Update the content.
200 DelLeft();
201 Insert(aNewState);
202
204 LockView(/*bViewLocked=*/false);
205 ShowCursor();
206 }
207
208 if (bRet && IsSelFrameMode())
209 {
212 }
213
214 if (IsSelection())
215 {
218 }
219
220 return bRet;
221}
222
224{
225 (this->*m_fnKillSel)( nullptr, false );
226 bool bRet = SwCursorShell::GotoFieldmark(pMark);
227 if( bRet && IsSelFrameMode() )
228 {
231 }
232 if( IsSelection() )
233 {
236 }
237 return bRet;
238}
239
240// Invalidate FontWork-Slots
241
243{
244 static sal_uInt16 const aInval[] =
245 {
246 SID_ATTR_FILL_STYLE, SID_ATTR_FILL_COLOR, SID_ATTR_LINE_STYLE,
247 SID_ATTR_LINE_WIDTH, SID_ATTR_LINE_COLOR,
248 /*AF: these may be needed for the sidebar.
249 SID_SVX_AREA_TRANSPARENCY, SID_SVX_AREA_TRANSP_GRADIENT,
250 SID_SVX_AREA_TRANS_TYPE,
251 */
252 0
253 };
254
256
257 bool bOldVal = g_bNoInterrupt;
258 g_bNoInterrupt = true; // Trick to run AttrChangedNotify by timer.
259 GetView().AttrChangedNotify(nullptr);
260 g_bNoInterrupt = bOldVal;
261}
262
263void SwWrtShell::GotoMark( const OUString& rName )
264{
266 if (ppMark == getIDocumentMarkAccess()->getAllMarksEnd())
267 return;
268 MoveBookMark( BOOKMARK_INDEX, *ppMark );
269}
270
271void SwWrtShell::GotoMark( const ::sw::mark::IMark* const pMark )
272{
274}
275
277{
278 if ( !getIDocumentMarkAccess()->getBookmarksCount() )
279 {
280 SvxSearchDialogWrapper::SetSearchLabel( SearchLabel::NavElementNotFound );
281 return false;
282 }
283 LockView( true );
284 bool bRet = MoveBookMark( BOOKMARK_NEXT );
285 if ( !bRet )
286 {
287 MoveBookMark( BOOKMARK_INDEX, *getIDocumentMarkAccess()->getBookmarksBegin() );
288 SvxSearchDialogWrapper::SetSearchLabel( SearchLabel::EndWrapped );
289 }
290 else
291 SvxSearchDialogWrapper::SetSearchLabel( SearchLabel::Empty );
292 LockView( false );
293 ShowCursor();
294 return true;
295}
296
298{
299 if ( !getIDocumentMarkAccess()->getBookmarksCount() )
300 {
301 SvxSearchDialogWrapper::SetSearchLabel( SearchLabel::NavElementNotFound );
302 return false;
303 }
304 LockView( true );
305 bool bRet = MoveBookMark( BOOKMARK_PREV );
306 if ( !bRet )
307 {
308 MoveBookMark( BOOKMARK_INDEX, *( getIDocumentMarkAccess()->getBookmarksEnd() - 1 ) );
309 SvxSearchDialogWrapper::SetSearchLabel( SearchLabel::StartWrapped );
310 }
311 else
312 SvxSearchDialogWrapper::SetSearchLabel( SearchLabel::Empty );
313 LockView( false );
314 ShowCursor();
315 return true;
316}
317
318void SwWrtShell::ExecMacro( const SvxMacro& rMacro, OUString* pRet, SbxArray* pArgs )
319{
320 // execute macro, if it is allowed.
321 if ( IsMacroExecAllowed() )
322 {
323 GetDoc()->ExecMacro( rMacro, pRet, pArgs );
324 }
325}
326
327sal_uInt16 SwWrtShell::CallEvent( SvMacroItemId nEvent, const SwCallMouseEvent& rCallEvent,
328 bool bChkPtr)
329{
330 return GetDoc()->CallEvent( nEvent, rCallEvent, bChkPtr );
331}
332
333 // If a util::URL-Button is selected, return its util::URL
334 // otherwise an empty string.
335bool SwWrtShell::GetURLFromButton( OUString& rURL, OUString& rDescr ) const
336{
337 bool bRet = false;
338 const SdrView *pDView = GetDrawView();
339 if( pDView )
340 {
341 // A fly is precisely achievable if it is selected.
342 const SdrMarkList &rMarkList = pDView->GetMarkedObjectList();
343
344 if (rMarkList.GetMark(0))
345 {
346 SdrUnoObj* pUnoCtrl = dynamic_cast<SdrUnoObj*>( rMarkList.GetMark(0)->GetMarkedSdrObj() );
347 if (pUnoCtrl && SdrInventor::FmForm == pUnoCtrl->GetObjInventor())
348 {
349 const uno::Reference< awt::XControlModel >& xControlModel = pUnoCtrl->GetUnoControlModel();
350
351 OSL_ENSURE( xControlModel.is(), "UNO-Control without Model" );
352 if( !xControlModel.is() )
353 return bRet;
354
355 uno::Reference< beans::XPropertySet > xPropSet(xControlModel, uno::UNO_QUERY);
356
357 uno::Any aTmp;
358
359 uno::Reference< beans::XPropertySetInfo > xInfo = xPropSet->getPropertySetInfo();
360 if(xInfo->hasPropertyByName( "ButtonType" ))
361 {
362 aTmp = xPropSet->getPropertyValue( "ButtonType" );
363 form::FormButtonType eTmpButtonType;
364 aTmp >>= eTmpButtonType;
365 if( form::FormButtonType_URL == eTmpButtonType)
366 {
367 // Label
368 aTmp = xPropSet->getPropertyValue( "Label" );
369 OUString uTmp;
370 if( (aTmp >>= uTmp) && !uTmp.isEmpty())
371 {
372 rDescr = uTmp;
373 }
374
375 // util::URL
376 aTmp = xPropSet->getPropertyValue( "TargetURL" );
377 if( (aTmp >>= uTmp) && !uTmp.isEmpty())
378 {
379 rURL = uTmp;
380 }
381 bRet = true;
382 }
383 }
384 }
385 }
386 }
387
388 return bRet;
389}
390
391/* 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:3673
void ShowCursor()
Definition: crsrsh.cxx:2398
bool IsMacroExecAllowed() const
Definition: crsrsh.hxx:851
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:888
bool GoNextBookmark()
Definition: crbm.cxx:203
bool GotoFormatField(const SwFormatField &rField)
Definition: crstrvl.cxx:900
bool GotoFormatContentControl(const SwFormatContentControl &rContentControl)
Definition: crstrvl.cxx:856
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:1254
SfxPoolItem subclass that wraps an SwContentControl.
std::shared_ptr< SwContentControl > GetContentControl()
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:2781
IDocumentUndoRedo const & GetIDocumentUndoRedo() const
Provides access to the document undo/redo interface.
Definition: viewsh.cxx:2795
SwDoc * GetDoc() const
Definition: viewsh.hxx:282
SfxViewShell * GetSfxViewShell() const
Definition: viewsh.hxx:446
void LockView(bool b)
Definition: viewsh.hxx:467
SdrView * GetDrawView()
Definition: vnew.cxx:373
void StopShellTimer()
Definition: view.cxx:1812
bool IsSelFrameMode() const
Definition: wrtsh.hxx:176
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:276
void LeaveSelFrameMode()
Definition: select.cxx:720
@ BOOKMARK_PREV
Definition: wrtsh.hxx:632
@ BOOKMARK_INDEX
Definition: wrtsh.hxx:630
@ BOOKMARK_NEXT
Definition: wrtsh.hxx:631
bool DelLeft()
Definition: delete.cxx:134
void addCurrentPosition()
Definition: wrtsh1.cxx:1839
bool GotoFieldmark(::sw::mark::IFieldmark const *const pMark)
Definition: wrtsh3.cxx:223
void GotoMark(const ::sw::mark::IMark *const pMark)
Definition: wrtsh3.cxx:271
bool GetURLFromButton(OUString &rURL, OUString &rDescr) const
Definition: wrtsh3.cxx:335
SAL_DLLPRIVATE bool MoveBookMark(BookMarkMove eFuncId, const ::sw::mark::IMark *const pMark=nullptr)
Definition: wrtsh3.cxx:49
void Insert(const OUString &)
Definition: wrtsh1.cxx:223
sal_uInt16 CallEvent(SvMacroItemId nEvent, const SwCallMouseEvent &rCallEvent, bool bCheckPtr=false)
Definition: wrtsh3.cxx:327
SELECTFUNC m_fnKillSel
Definition: wrtsh.hxx:117
void ExecMacro(const SvxMacro &rMacro, OUString *pRet=nullptr, SbxArray *pArgs=nullptr)
Definition: wrtsh3.cxx:318
bool GoPrevBookmark()
Definition: wrtsh3.cxx:297
bool GotoField(const SwFormatField &rField)
Definition: wrtsh3.cxx:76
SELECTFUNC m_fnSetCursor
Definition: wrtsh.hxx:115
virtual void DrawSelChanged() override
Definition: wrtsh3.cxx:242
void UnSelectFrame()
Definition: select.cxx:323
tools::Long ResetSelect(const Point *, bool)
Definition: select.cxx:333
const SwView & GetView() const
Definition: wrtsh.hxx:437
void put(const char *pPropName, const OUString &rPropValue)
char * extractData()
SvMacroItemId
OUString SwResId(TranslateId aId)
Definition: swmodule.cxx:164
bool g_bNoInterrupt
Definition: swmodule.cxx:114