android: Update app-specific/MIME type icons
[LibreOffice.git] / sw / source / uibase / wrtsh / wrtsh3.cxx
blob0907794d7c2cb3c9fb5567692b772ab559904660
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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>
37 #include <wrtsh.hxx>
38 #include <view.hxx>
39 #include <IMark.hxx>
40 #include <doc.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)
51 addCurrentPosition();
52 (this->*m_fnKillSel)( nullptr, false );
54 bool bRet = true;
55 switch(eFuncId)
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() )
65 UnSelectFrame();
66 LeaveSelFrameMode();
68 if( IsSelection() )
70 m_fnKillSel = &SwWrtShell::ResetSelect;
71 m_fnSetCursor = &SwWrtShell::SetCursorKillSel;
73 return bRet;
76 bool SwWrtShell::GotoField( const SwFormatField& rField )
78 (this->*m_fnKillSel)( nullptr, false );
80 bool bRet = SwCursorShell::GotoFormatField( rField );
81 if( bRet && IsSelFrameMode() )
83 UnSelectFrame();
84 LeaveSelFrameMode();
87 if( IsSelection() )
89 m_fnKillSel = &SwWrtShell::ResetSelect;
90 m_fnSetCursor = &SwWrtShell::SetCursorKillSel;
93 return bRet;
96 bool SwWrtShell::GotoContentControl(const SwFormatContentControl& rContentControl,
97 bool bOnlyRefresh)
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,
113 pJson);
115 else
117 GetView().GetViewFrame().GetDispatcher()->Execute(SID_CHANGE_PICTURE,
118 SfxCallMode::SYNCHRON);
120 pContentControl->SetShowingPlaceHolder(false);
122 return true;
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();
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();
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);
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);
156 GetIDocumentUndoRedo().EndUndo(SwUndoId::REPLACE, &aRewriter);
157 LockView(/*bViewLocked=*/false);
158 ShowCursor();
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);
175 DelLeft();
176 pContentControl->SetSelectedListItem(std::nullopt);
177 Insert(aNewState);
178 pContentControl->SetReadWrite(false);
180 GetIDocumentUndoRedo().EndUndo(SwUndoId::REPLACE, &aRewriter);
181 LockView(/*bViewLocked=*/false);
182 ShowCursor();
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.
201 DelLeft();
202 Insert(aNewState);
204 GetIDocumentUndoRedo().EndUndo(SwUndoId::REPLACE, &aRewriter);
205 LockView(/*bViewLocked=*/false);
206 ShowCursor();
209 if (bRet && IsSelFrameMode())
211 UnSelectFrame();
212 LeaveSelFrameMode();
215 if (IsSelection())
217 m_fnKillSel = &SwWrtShell::ResetSelect;
218 m_fnSetCursor = &SwWrtShell::SetCursorKillSel;
221 return bRet;
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() )
230 UnSelectFrame();
231 LeaveSelFrameMode();
233 if( IsSelection() )
235 m_fnKillSel = &SwWrtShell::ResetSelect;
236 m_fnSetCursor = &SwWrtShell::SetCursorKillSel;
238 return bRet;
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())
268 return;
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 );
282 return false;
284 LockView( true );
285 bool bRet = MoveBookMark( BOOKMARK_NEXT );
286 if ( !bRet )
288 MoveBookMark( BOOKMARK_INDEX, *getIDocumentMarkAccess()->getBookmarksBegin() );
289 SvxSearchDialogWrapper::SetSearchLabel( SearchLabel::EndWrapped );
291 else
292 SvxSearchDialogWrapper::SetSearchLabel( SearchLabel::Empty );
293 LockView( false );
294 ShowCursor();
295 return true;
298 bool SwWrtShell::GoPrevBookmark()
300 if ( !getIDocumentMarkAccess()->getBookmarksCount() )
302 SvxSearchDialogWrapper::SetSearchLabel( SearchLabel::NavElementNotFound );
303 return false;
305 LockView( true );
306 bool bRet = MoveBookMark( BOOKMARK_PREV );
307 if ( !bRet )
309 MoveBookMark( BOOKMARK_INDEX, *( getIDocumentMarkAccess()->getBookmarksEnd() - 1 ) );
310 SvxSearchDialogWrapper::SetSearchLabel( SearchLabel::StartWrapped );
312 else
313 SvxSearchDialogWrapper::SetSearchLabel( SearchLabel::Empty );
314 LockView( false );
315 ShowCursor();
316 return true;
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,
329 bool bChkPtr)
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
338 bool bRet = false;
339 const SdrView *pDView = GetDrawView();
340 if( pDView )
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() )
354 return bRet;
356 uno::Reference< beans::XPropertySet > xPropSet(xControlModel, uno::UNO_QUERY);
358 uno::Any aTmp;
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)
368 // Label
369 aTmp = xPropSet->getPropertyValue( "Label" );
370 OUString uTmp;
371 if( (aTmp >>= uTmp) && !uTmp.isEmpty())
373 rDescr = uTmp;
376 // util::URL
377 aTmp = xPropSet->getPropertyValue( "TargetURL" );
378 if( (aTmp >>= uTmp) && !uTmp.isEmpty())
380 rURL = uTmp;
382 bRet = true;
389 return bRet;
392 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */