1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
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>
36 #include <swmodule.hxx>
41 #include <formatcontentcontrol.hxx>
42 #include <IDocumentUndoRedo.hxx>
43 #include <SwRewriter.hxx>
44 #include <strings.hrc>
45 #include <textcontentcontrol.hxx>
47 using namespace ::com::sun::star
;
49 bool SwWrtShell::MoveBookMark( BookMarkMove eFuncId
, const ::sw::mark::IMark
* const pMark
)
52 (this->*m_fnKillSel
)( nullptr, false );
57 case BOOKMARK_INDEX
:bRet
= SwCursorShell::GotoMark( pMark
);break;
58 case BOOKMARK_NEXT
: bRet
= SwCursorShell::GoNextBookmark();break;
59 case BOOKMARK_PREV
: bRet
= SwCursorShell::GoPrevBookmark();break;
60 default:;//prevent warning
63 if( bRet
&& IsSelFrameMode() )
70 m_fnKillSel
= &SwWrtShell::ResetSelect
;
71 m_fnSetCursor
= &SwWrtShell::SetCursorKillSel
;
76 bool SwWrtShell::GotoField( const SwFormatField
& rField
)
78 (this->*m_fnKillSel
)( nullptr, false );
80 bool bRet
= SwCursorShell::GotoFormatField( rField
);
81 if( bRet
&& IsSelFrameMode() )
89 m_fnKillSel
= &SwWrtShell::ResetSelect
;
90 m_fnSetCursor
= &SwWrtShell::SetCursorKillSel
;
96 bool SwWrtShell::GotoContentControl(const SwFormatContentControl
& rContentControl
,
99 std::shared_ptr
<SwContentControl
> pContentControl
= rContentControl
.GetContentControl();
100 if (IsFrameSelected() && pContentControl
&& pContentControl
->GetPicture())
102 // A frame is already selected, and its anchor is inside a picture content control.
103 if (pContentControl
->GetShowingPlaceHolder())
105 // Replace the placeholder image with a real one.
106 GetView().StopShellTimer();
107 if (comphelper::LibreOfficeKit::isActive())
109 tools::JsonWriter aJson
;
110 aJson
.put("action", "change-picture");
111 OString
pJson(aJson
.finishAndGetAsOString());
112 GetSfxViewShell()->libreOfficeKitViewCallback(LOK_CALLBACK_CONTENT_CONTROL
,
117 GetView().GetViewFrame().GetDispatcher()->Execute(SID_CHANGE_PICTURE
,
118 SfxCallMode::SYNCHRON
);
120 pContentControl
->SetShowingPlaceHolder(false);
125 (this->*m_fnKillSel
)(nullptr, false);
127 bool bRet
= SwCursorShell::GotoFormatContentControl(rContentControl
);
129 if (bRet
&& pContentControl
&& pContentControl
->GetCheckbox())
131 // Checkbox: GotoFormatContentControl() selected the old state.
132 LockView(/*bViewLocked=*/true);
133 OUString aOldState
= GetCursorDescr();
135 if (pContentControl
->GetChecked())
136 aNewState
= bOnlyRefresh
? pContentControl
->GetCheckedState()
137 : pContentControl
->GetUncheckedState();
139 aNewState
= bOnlyRefresh
? pContentControl
->GetUncheckedState()
140 : pContentControl
->GetCheckedState();
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
);
149 pContentControl
->SetReadWrite(true);
152 pContentControl
->SetChecked(!pContentControl
->GetChecked());
154 pContentControl
->SetReadWrite(false);
156 GetIDocumentUndoRedo().EndUndo(SwUndoId::REPLACE
, &aRewriter
);
157 LockView(/*bViewLocked=*/false);
160 else if (bRet
&& pContentControl
&& pContentControl
->GetSelectedListItem())
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
);
173 // Update the content.
174 pContentControl
->SetReadWrite(true);
176 pContentControl
->SetSelectedListItem(std::nullopt
);
178 pContentControl
->SetReadWrite(false);
180 GetIDocumentUndoRedo().EndUndo(SwUndoId::REPLACE
, &aRewriter
);
181 LockView(/*bViewLocked=*/false);
184 else if (bRet
&& pContentControl
&& pContentControl
->GetSelectedDate())
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
);
196 // Write the doc model.
197 pContentControl
->SetCurrentDateValue(*pContentControl
->GetSelectedDate());
198 pContentControl
->SetSelectedDate(std::nullopt
);
200 // Update the content.
204 GetIDocumentUndoRedo().EndUndo(SwUndoId::REPLACE
, &aRewriter
);
205 LockView(/*bViewLocked=*/false);
209 if (bRet
&& IsSelFrameMode())
217 m_fnKillSel
= &SwWrtShell::ResetSelect
;
218 m_fnSetCursor
= &SwWrtShell::SetCursorKillSel
;
224 bool SwWrtShell::GotoFieldmark(::sw::mark::IFieldmark
const * const pMark
)
226 (this->*m_fnKillSel
)( nullptr, false );
227 bool bRet
= SwCursorShell::GotoFieldmark(pMark
);
228 if( bRet
&& IsSelFrameMode() )
235 m_fnKillSel
= &SwWrtShell::ResetSelect
;
236 m_fnSetCursor
= &SwWrtShell::SetCursorKillSel
;
241 // Invalidate FontWork-Slots
243 void SwWrtShell::DrawSelChanged( )
245 static sal_uInt16
const aInval
[] =
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,
256 GetView().GetViewFrame().GetBindings().Invalidate(aInval
);
258 bool bOldVal
= g_bNoInterrupt
;
259 g_bNoInterrupt
= true; // Trick to run AttrChangedNotify by timer.
260 GetView().AttrChangedNotify(nullptr);
261 g_bNoInterrupt
= bOldVal
;
264 void SwWrtShell::GotoMark( const OUString
& rName
)
266 IDocumentMarkAccess::const_iterator_t ppMark
= getIDocumentMarkAccess()->findMark( rName
);
267 if (ppMark
== getIDocumentMarkAccess()->getAllMarksEnd())
269 MoveBookMark( BOOKMARK_INDEX
, *ppMark
);
272 void SwWrtShell::GotoMark( const ::sw::mark::IMark
* const pMark
)
274 MoveBookMark( BOOKMARK_INDEX
, pMark
);
277 bool SwWrtShell::GoNextBookmark()
279 if ( !getIDocumentMarkAccess()->getBookmarksCount() )
281 SvxSearchDialogWrapper::SetSearchLabel( SearchLabel::NavElementNotFound
);
285 bool bRet
= MoveBookMark( BOOKMARK_NEXT
);
288 MoveBookMark( BOOKMARK_INDEX
, *getIDocumentMarkAccess()->getBookmarksBegin() );
289 SvxSearchDialogWrapper::SetSearchLabel( SearchLabel::EndWrapped
);
292 SvxSearchDialogWrapper::SetSearchLabel( SearchLabel::Empty
);
298 bool SwWrtShell::GoPrevBookmark()
300 if ( !getIDocumentMarkAccess()->getBookmarksCount() )
302 SvxSearchDialogWrapper::SetSearchLabel( SearchLabel::NavElementNotFound
);
306 bool bRet
= MoveBookMark( BOOKMARK_PREV
);
309 MoveBookMark( BOOKMARK_INDEX
, *( getIDocumentMarkAccess()->getBookmarksEnd() - 1 ) );
310 SvxSearchDialogWrapper::SetSearchLabel( SearchLabel::StartWrapped
);
313 SvxSearchDialogWrapper::SetSearchLabel( SearchLabel::Empty
);
319 void SwWrtShell::ExecMacro( const SvxMacro
& rMacro
, OUString
* pRet
, SbxArray
* pArgs
)
321 // execute macro, if it is allowed.
322 if ( IsMacroExecAllowed() )
324 GetDoc()->ExecMacro( rMacro
, pRet
, pArgs
);
328 sal_uInt16
SwWrtShell::CallEvent( SvMacroItemId nEvent
, const SwCallMouseEvent
& rCallEvent
,
331 return GetDoc()->CallEvent( nEvent
, rCallEvent
, bChkPtr
);
334 // If a util::URL-Button is selected, return its util::URL
335 // otherwise an empty string.
336 bool SwWrtShell::GetURLFromButton( OUString
& rURL
, OUString
& rDescr
) const
339 const SdrView
*pDView
= GetDrawView();
342 // A fly is precisely achievable if it is selected.
343 const SdrMarkList
&rMarkList
= pDView
->GetMarkedObjectList();
345 if (rMarkList
.GetMark(0))
347 SdrUnoObj
* pUnoCtrl
= dynamic_cast<SdrUnoObj
*>( rMarkList
.GetMark(0)->GetMarkedSdrObj() );
348 if (pUnoCtrl
&& SdrInventor::FmForm
== pUnoCtrl
->GetObjInventor())
350 const uno::Reference
< awt::XControlModel
>& xControlModel
= pUnoCtrl
->GetUnoControlModel();
352 OSL_ENSURE( xControlModel
.is(), "UNO-Control without Model" );
353 if( !xControlModel
.is() )
356 uno::Reference
< beans::XPropertySet
> xPropSet(xControlModel
, uno::UNO_QUERY
);
360 uno::Reference
< beans::XPropertySetInfo
> xInfo
= xPropSet
->getPropertySetInfo();
361 if(xInfo
->hasPropertyByName( "ButtonType" ))
363 aTmp
= xPropSet
->getPropertyValue( "ButtonType" );
364 form::FormButtonType eTmpButtonType
;
365 aTmp
>>= eTmpButtonType
;
366 if( form::FormButtonType_URL
== eTmpButtonType
)
369 aTmp
= xPropSet
->getPropertyValue( "Label" );
371 if( (aTmp
>>= uTmp
) && !uTmp
.isEmpty())
377 aTmp
= xPropSet
->getPropertyValue( "TargetURL" );
378 if( (aTmp
>>= uTmp
) && !uTmp
.isEmpty())
392 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */