File: | home/maarten/src/libreoffice/core/include/rtl/ref.hxx |
Warning: | line 192, column 9 Use of memory after it is freed |
Press '?' to see keyboard shortcuts
Keyboard shortcuts:
1 | /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */ | |||
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 <config_features.h> | |||
21 | ||||
22 | #include <com/sun/star/drawing/ModuleDispatcher.hpp> | |||
23 | #include <com/sun/star/frame/DispatchHelper.hpp> | |||
24 | #include <ooo/vba/word/XDocument.hpp> | |||
25 | #include <comphelper/fileformat.h> | |||
26 | #include <comphelper/processfactory.hxx> | |||
27 | ||||
28 | #include <sal/log.hxx> | |||
29 | #include <edtwin.hxx> | |||
30 | #include <tools/urlobj.hxx> | |||
31 | #include <unotools/tempfile.hxx> | |||
32 | #include <unotools/configmgr.hxx> | |||
33 | #include <vcl/errinf.hxx> | |||
34 | #include <vcl/svapp.hxx> | |||
35 | #include <vcl/weld.hxx> | |||
36 | #include <svl/eitem.hxx> | |||
37 | #include <svl/macitem.hxx> | |||
38 | #include <svl/zforlist.hxx> | |||
39 | #include <unotools/pathoptions.hxx> | |||
40 | #include <vcl/transfer.hxx> | |||
41 | #include <sfx2/dinfdlg.hxx> | |||
42 | #include <sfx2/request.hxx> | |||
43 | #include <sfx2/dispatch.hxx> | |||
44 | #include <sfx2/new.hxx> | |||
45 | #include <sfx2/notebookbar/SfxNotebookBar.hxx> | |||
46 | #include <sfx2/filedlghelper.hxx> | |||
47 | #include <sfx2/printer.hxx> | |||
48 | #include <sfx2/evntconf.hxx> | |||
49 | #include <sfx2/docfile.hxx> | |||
50 | #include <sfx2/docfilt.hxx> | |||
51 | #include <svx/dialogs.hrc> | |||
52 | #include <svx/drawitem.hxx> | |||
53 | #include <editeng/svxacorr.hxx> | |||
54 | #include <svx/fmshell.hxx> | |||
55 | #include <sfx2/linkmgr.hxx> | |||
56 | #include <sfx2/classificationhelper.hxx> | |||
57 | #include <sfx2/watermarkitem.hxx> | |||
58 | ||||
59 | #include <svtools/htmlcfg.hxx> | |||
60 | #include <svx/ofaitem.hxx> | |||
61 | #include <SwSmartTagMgr.hxx> | |||
62 | #include <sfx2/app.hxx> | |||
63 | #include <basic/sbstar.hxx> | |||
64 | #include <basic/basmgr.hxx> | |||
65 | #include <comphelper/classids.hxx> | |||
66 | #include <fmtcol.hxx> | |||
67 | #include <view.hxx> | |||
68 | #include <docsh.hxx> | |||
69 | #include <docary.hxx> | |||
70 | #include <wrtsh.hxx> | |||
71 | #include <fldbas.hxx> | |||
72 | #include <viewopt.hxx> | |||
73 | #include <globdoc.hxx> | |||
74 | #include <fldwrap.hxx> | |||
75 | #include <redlndlg.hxx> | |||
76 | #include <doc.hxx> | |||
77 | #include <IDocumentUndoRedo.hxx> | |||
78 | #include <IDocumentSettingAccess.hxx> | |||
79 | #include <IDocumentDeviceAccess.hxx> | |||
80 | #include <IDocumentLinksAdministration.hxx> | |||
81 | #include <IDocumentFieldsAccess.hxx> | |||
82 | #include <IDocumentStatistics.hxx> | |||
83 | #include <IDocumentLayoutAccess.hxx> | |||
84 | #include <IDocumentState.hxx> | |||
85 | #include <shellio.hxx> | |||
86 | #include <pview.hxx> | |||
87 | #include <srcview.hxx> | |||
88 | #include <wdocsh.hxx> | |||
89 | #include <unotxdoc.hxx> | |||
90 | #include <acmplwrd.hxx> | |||
91 | #include <swmodule.hxx> | |||
92 | #include <unobaseclass.hxx> | |||
93 | #include <swwait.hxx> | |||
94 | #include <swcli.hxx> | |||
95 | ||||
96 | #include <cmdid.h> | |||
97 | #include <helpids.h> | |||
98 | #include <strings.hrc> | |||
99 | #include <com/sun/star/ui/dialogs/XFilePicker3.hpp> | |||
100 | #include <com/sun/star/ui/dialogs/XFilePickerControlAccess.hpp> | |||
101 | #include <com/sun/star/ui/dialogs/ExtendedFilePickerElementIds.hpp> | |||
102 | #include <com/sun/star/ui/dialogs/ListboxControlActions.hpp> | |||
103 | #include <com/sun/star/ui/dialogs/CommonFilePickerElementIds.hpp> | |||
104 | #include <com/sun/star/ui/dialogs/TemplateDescription.hpp> | |||
105 | #include <com/sun/star/script/vba/XVBAEventProcessor.hpp> | |||
106 | #include <com/sun/star/script/vba/VBAEventId.hpp> | |||
107 | #include <editeng/acorrcfg.hxx> | |||
108 | #include <officecfg/Office/Security.hxx> | |||
109 | ||||
110 | #include <sfx2/fcontnr.hxx> | |||
111 | #include <svx/ClassificationDialog.hxx> | |||
112 | #include <svtools/embedhlp.hxx> | |||
113 | ||||
114 | #include <swabstdlg.hxx> | |||
115 | #include <watermarkdialog.hxx> | |||
116 | ||||
117 | #include <ndtxt.hxx> | |||
118 | #include <iodetect.hxx> | |||
119 | ||||
120 | #include <memory> | |||
121 | ||||
122 | using namespace ::com::sun::star::ui::dialogs; | |||
123 | using namespace ::com::sun::star::lang; | |||
124 | using namespace ::com::sun::star::uno; | |||
125 | using namespace ::com::sun::star; | |||
126 | using namespace ::sfx2; | |||
127 | ||||
128 | // create DocInfo (virtual) | |||
129 | std::shared_ptr<SfxDocumentInfoDialog> SwDocShell::CreateDocumentInfoDialog(weld::Window* pParent, const SfxItemSet &rSet) | |||
130 | { | |||
131 | std::shared_ptr<SfxDocumentInfoDialog> xDlg = std::make_shared<SfxDocumentInfoDialog>(pParent, rSet); | |||
132 | //only with statistics, when this document is being shown, not | |||
133 | //from within the Doc-Manager | |||
134 | SwDocShell* pDocSh = static_cast<SwDocShell*>( SfxObjectShell::Current()); | |||
135 | if( pDocSh == this ) | |||
136 | { | |||
137 | //Not for SourceView. | |||
138 | SfxViewShell *pVSh = SfxViewShell::Current(); | |||
139 | if ( pVSh && dynamic_cast< const SwSrcView *>( pVSh ) == nullptr ) | |||
140 | { | |||
141 | SwAbstractDialogFactory* pFact = SwAbstractDialogFactory::Create(); | |||
142 | xDlg->AddFontTabPage(); | |||
143 | xDlg->AddTabPage("writerstats", SwResId(STR_DOC_STATreinterpret_cast<char const *>("STR_DOC_STAT" "\004" u8"Statistics" )), pFact->GetTabPageCreatorFunc(RID_SW_TP_DOC_STAT((10000 +6900) + 252))); | |||
144 | } | |||
145 | } | |||
146 | return xDlg; | |||
147 | } | |||
148 | ||||
149 | void SwDocShell::ToggleLayoutMode(SwView* pView) | |||
150 | { | |||
151 | OSL_ENSURE( pView, "SwDocShell::ToggleLayoutMode, pView is null." )do { if (true && (!(pView))) { sal_detail_logFormat(( SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.osl"), ("/home/maarten/src/libreoffice/core/sw/source/uibase/app/docsh2.cxx" ":" "151" ": "), "%s", "SwDocShell::ToggleLayoutMode, pView is null." ); } } while (false); | |||
152 | ||||
153 | const SwViewOption& rViewOptions = *pView->GetWrtShell().GetViewOptions(); | |||
154 | ||||
155 | //TODO: Should HideWhitespace flag be saved in the document settings? | |||
156 | GetDoc()->getIDocumentSettingAccess().set(DocumentSettingId::BROWSE_MODE, rViewOptions.getBrowseMode()); | |||
157 | UpdateFontList(); // Why is this necessary here? | |||
158 | ||||
159 | pView->GetViewFrame()->GetBindings().Invalidate(FN_SHADOWCURSOR((20000 + 2200) + 4)); | |||
160 | if( !GetDoc()->getIDocumentDeviceAccess().getPrinter( false ) ) | |||
161 | pView->SetPrinter( GetDoc()->getIDocumentDeviceAccess().getPrinter( false ), SfxPrinterChangeFlags::PRINTER | SfxPrinterChangeFlags::JOBSETUP ); | |||
162 | GetDoc()->CheckDefaultPageFormat(); | |||
163 | SfxViewFrame *pTmpFrame = SfxViewFrame::GetFirst(this, false); | |||
164 | while (pTmpFrame) | |||
165 | { | |||
166 | if( pTmpFrame != pView->GetViewFrame() ) | |||
167 | { | |||
168 | pTmpFrame->DoClose(); | |||
169 | pTmpFrame = SfxViewFrame::GetFirst(this, false); | |||
170 | } | |||
171 | else | |||
172 | pTmpFrame = SfxViewFrame::GetNext(*pTmpFrame, this, false); | |||
173 | } | |||
174 | ||||
175 | pView->GetWrtShell().InvalidateLayout(true); | |||
176 | ||||
177 | pView->RecheckBrowseMode(); | |||
178 | ||||
179 | pView->SetNewWindowAllowed(!rViewOptions.getBrowseMode()); | |||
180 | } | |||
181 | ||||
182 | // update text fields on document properties changes | |||
183 | void SwDocShell::DoFlushDocInfo() | |||
184 | { | |||
185 | if (!m_xDoc) | |||
186 | return; | |||
187 | ||||
188 | bool bUnlockView(true); | |||
189 | if (m_pWrtShell) | |||
190 | { | |||
191 | bUnlockView = !m_pWrtShell->IsViewLocked(); | |||
192 | m_pWrtShell->LockView( true ); // lock visible section | |||
193 | m_pWrtShell->StartAllAction(); | |||
194 | } | |||
195 | ||||
196 | m_xDoc->getIDocumentStatistics().DocInfoChgd(IsEnableSetModified()); | |||
197 | ||||
198 | if (m_pWrtShell) | |||
199 | { | |||
200 | m_pWrtShell->EndAllAction(); | |||
201 | if (bUnlockView) | |||
202 | { | |||
203 | m_pWrtShell->LockView( false ); | |||
204 | } | |||
205 | } | |||
206 | } | |||
207 | ||||
208 | static void lcl_processCompatibleSfxHint( const uno::Reference< script::vba::XVBAEventProcessor >& xVbaEvents, const SfxHint& rHint ) | |||
209 | { | |||
210 | using namespace com::sun::star::script::vba::VBAEventId; | |||
211 | const SfxEventHint* pSfxEventHint = dynamic_cast<const SfxEventHint*>(&rHint); | |||
212 | if ( !pSfxEventHint ) | |||
213 | return; | |||
214 | ||||
215 | uno::Sequence< uno::Any > aArgs; | |||
216 | switch( pSfxEventHint->GetEventId() ) | |||
217 | { | |||
218 | case SfxEventHintId::CreateDoc: | |||
219 | xVbaEvents->processVbaEvent( DOCUMENT_NEW, aArgs ); | |||
220 | break; | |||
221 | case SfxEventHintId::OpenDoc: | |||
222 | xVbaEvents->processVbaEvent( DOCUMENT_OPEN, aArgs ); | |||
223 | break; | |||
224 | default: break; | |||
225 | } | |||
226 | } | |||
227 | ||||
228 | // Notification on DocInfo changes | |||
229 | void SwDocShell::Notify( SfxBroadcaster&, const SfxHint& rHint ) | |||
230 | { | |||
231 | if (!m_xDoc) | |||
232 | { | |||
233 | return ; | |||
234 | } | |||
235 | ||||
236 | uno::Reference< script::vba::XVBAEventProcessor > const xVbaEvents = | |||
237 | m_xDoc->GetVbaEventProcessor(); | |||
238 | if( xVbaEvents.is() ) | |||
239 | lcl_processCompatibleSfxHint( xVbaEvents, rHint ); | |||
240 | ||||
241 | if ( const SfxEventHint* pSfxEventHint = dynamic_cast<const SfxEventHint*>(&rHint) ) | |||
242 | { | |||
243 | switch( pSfxEventHint->GetEventId() ) | |||
244 | { | |||
245 | case SfxEventHintId::ActivateDoc: | |||
246 | case SfxEventHintId::CreateDoc: | |||
247 | case SfxEventHintId::OpenDoc: | |||
248 | { | |||
249 | uno::Sequence< css::uno::Any > aArgs; | |||
250 | SW_MOD()( static_cast<SwModule*>(SfxApplication::GetModule(SfxToolsModule ::Writer)))->CallAutomationApplicationEventSinks( "DocumentChange", aArgs ); | |||
251 | break; | |||
252 | } | |||
253 | default: | |||
254 | break; | |||
255 | } | |||
256 | ||||
257 | switch( pSfxEventHint->GetEventId() ) | |||
258 | { | |||
259 | case SfxEventHintId::CreateDoc: | |||
260 | { | |||
261 | uno::Any aDocument; | |||
262 | aDocument <<= mxAutomationDocumentObject; | |||
263 | uno::Sequence< uno::Any > aArgs(1); | |||
264 | aArgs[0] = aDocument; | |||
265 | SW_MOD()( static_cast<SwModule*>(SfxApplication::GetModule(SfxToolsModule ::Writer)))->CallAutomationApplicationEventSinks( "NewDocument", aArgs ); | |||
266 | } | |||
267 | break; | |||
268 | case SfxEventHintId::OpenDoc: | |||
269 | { | |||
270 | uno::Any aDocument; | |||
271 | aDocument <<= mxAutomationDocumentObject; | |||
272 | uno::Sequence< uno::Any > aArgs(1); | |||
273 | aArgs[0] = aDocument; | |||
274 | SW_MOD()( static_cast<SwModule*>(SfxApplication::GetModule(SfxToolsModule ::Writer)))->CallAutomationApplicationEventSinks( "DocumentOpen", aArgs ); | |||
275 | } | |||
276 | break; | |||
277 | default: | |||
278 | break; | |||
279 | } | |||
280 | } | |||
281 | ||||
282 | sal_uInt16 nAction = 0; | |||
283 | auto pEventHint = dynamic_cast<const SfxEventHint*>(&rHint); | |||
284 | if( pEventHint && pEventHint->GetEventId() == SfxEventHintId::LoadFinished ) | |||
285 | { | |||
286 | // #i38126# - own action id | |||
287 | nAction = 3; | |||
288 | } | |||
289 | else | |||
290 | { | |||
291 | // switch for more actions | |||
292 | if( rHint.GetId() == SfxHintId::TitleChanged) | |||
293 | { | |||
294 | if( GetMedium() ) | |||
295 | nAction = 2; | |||
296 | } | |||
297 | } | |||
298 | ||||
299 | if( !nAction ) | |||
300 | return; | |||
301 | ||||
302 | bool bUnlockView = true; //initializing prevents warning | |||
303 | if (m_pWrtShell) | |||
304 | { | |||
305 | bUnlockView = !m_pWrtShell->IsViewLocked(); | |||
306 | m_pWrtShell->LockView( true ); //lock visible section | |||
307 | m_pWrtShell->StartAllAction(); | |||
308 | } | |||
309 | switch( nAction ) | |||
310 | { | |||
311 | case 2: | |||
312 | m_xDoc->getIDocumentFieldsAccess().GetSysFieldType( SwFieldIds::Filename )->UpdateFields(); | |||
313 | break; | |||
314 | // #i38126# - own action for event LOADFINISHED | |||
315 | // in order to avoid a modified document. | |||
316 | // #i41679# - Also for the instance of <SwDoc> | |||
317 | // it has to be assured, that it's not modified. | |||
318 | // Perform the same as for action id 1, but disable <SetModified>. | |||
319 | case 3: | |||
320 | { | |||
321 | const bool bResetModified = IsEnableSetModified(); | |||
322 | if ( bResetModified ) | |||
323 | EnableSetModified( false ); | |||
324 | // #i41679# | |||
325 | const bool bIsDocModified = m_xDoc->getIDocumentState().IsModified(); | |||
326 | // TODO: is the ResetModified() below because of only the direct call from DocInfoChgd, or does UpdateFields() set it too? | |||
327 | ||||
328 | m_xDoc->getIDocumentStatistics().DocInfoChgd(false); | |||
329 | ||||
330 | // #i41679# | |||
331 | if ( !bIsDocModified ) | |||
332 | m_xDoc->getIDocumentState().ResetModified(); | |||
333 | if ( bResetModified ) | |||
334 | EnableSetModified(); | |||
335 | } | |||
336 | break; | |||
337 | } | |||
338 | ||||
339 | if (m_pWrtShell) | |||
340 | { | |||
341 | m_pWrtShell->EndAllAction(); | |||
342 | if( bUnlockView ) | |||
343 | m_pWrtShell->LockView( false ); | |||
344 | } | |||
345 | } | |||
346 | ||||
347 | // Notification Close Doc | |||
348 | bool SwDocShell::PrepareClose( bool bUI ) | |||
349 | { | |||
350 | bool bRet = SfxObjectShell::PrepareClose( bUI ); | |||
351 | ||||
352 | // If we are going to close it at this point, let potential DocumentBeforeClose event handlers | |||
353 | // in Automation clients veto it. | |||
354 | if (bRet && m_xDoc && IsInPrepareClose()) | |||
355 | { | |||
356 | uno::Any aDocument; | |||
357 | aDocument <<= mxAutomationDocumentObject; | |||
358 | ||||
359 | uno::Sequence< uno::Any > aArgs(2); | |||
360 | // Arg 0: Document | |||
361 | aArgs[0] = aDocument; | |||
362 | // Arg 1: Cancel | |||
363 | aArgs[1] <<= false; | |||
364 | ||||
365 | SW_MOD()( static_cast<SwModule*>(SfxApplication::GetModule(SfxToolsModule ::Writer)))->CallAutomationApplicationEventSinks( "DocumentBeforeClose", aArgs ); | |||
366 | ||||
367 | // If the Cancel argument was set to True by an event handler, return false. | |||
368 | bool bCancel(false); | |||
369 | aArgs[1] >>= bCancel; | |||
370 | if (bCancel) | |||
371 | bRet = false; | |||
372 | } | |||
373 | ||||
374 | if( bRet ) | |||
375 | EndListening( *this ); | |||
376 | ||||
377 | if (m_xDoc && IsInPrepareClose()) | |||
378 | { | |||
379 | uno::Reference< script::vba::XVBAEventProcessor > const xVbaEvents = | |||
380 | m_xDoc->GetVbaEventProcessor(); | |||
381 | if( xVbaEvents.is() ) | |||
382 | { | |||
383 | using namespace com::sun::star::script::vba::VBAEventId; | |||
384 | uno::Sequence< uno::Any > aNoArgs; | |||
385 | xVbaEvents->processVbaEvent( DOCUMENT_CLOSE, aNoArgs ); | |||
386 | } | |||
387 | } | |||
388 | return bRet; | |||
389 | } | |||
390 | ||||
391 | void SwDocShell::Execute(SfxRequest& rReq) | |||
392 | { | |||
393 | const SfxItemSet* pArgs = rReq.GetArgs(); | |||
394 | const SfxPoolItem* pItem; | |||
395 | sal_uInt16 nWhich = rReq.GetSlot(); | |||
396 | bool bDone = false; | |||
397 | switch ( nWhich ) | |||
| ||||
398 | { | |||
399 | case SID_AUTO_CORRECT_DLG(10000 + 424): | |||
400 | { | |||
401 | SvxSwAutoFormatFlags* pAFlags = &SvxAutoCorrCfg::Get().GetAutoCorrect()->GetSwFlags(); | |||
402 | SwAutoCompleteWord& rACW = SwDoc::GetAutoCompleteWords(); | |||
403 | ||||
404 | bool bOldLocked = rACW.IsLockWordLstLocked(), | |||
405 | bOldAutoCmpltCollectWords = pAFlags->bAutoCmpltCollectWords; | |||
406 | ||||
407 | rACW.SetLockWordLstLocked( true ); | |||
408 | ||||
409 | editeng::SortedAutoCompleteStrings aTmpLst( rACW.GetWordList().createNonOwningCopy() ); | |||
410 | pAFlags->m_pAutoCompleteList = &aTmpLst; | |||
411 | ||||
412 | SfxApplication* pApp = SfxGetpApp(); | |||
413 | SfxRequest aAppReq(SID_AUTO_CORRECT_DLG(10000 + 424), SfxCallMode::SYNCHRON, pApp->GetPool()); | |||
414 | SfxBoolItem aSwOptions( SID_AUTO_CORRECT_DLG(10000 + 424), true ); | |||
415 | aAppReq.AppendItem(aSwOptions); | |||
416 | ||||
417 | pAFlags->pSmartTagMgr = &SwSmartTagMgr::Get(); | |||
418 | ||||
419 | SfxItemSet aSet( pApp->GetPool(), svl::Items<SID_AUTO_CORRECT_DLG(10000 + 424), SID_AUTO_CORRECT_DLG(10000 + 424), SID_OPEN_SMARTTAGOPTIONS(10000 + 1062), SID_OPEN_SMARTTAGOPTIONS(10000 + 1062)>{} ); | |||
420 | aSet.Put( aSwOptions ); | |||
421 | ||||
422 | const SfxPoolItem* pOpenSmartTagOptionsItem = nullptr; | |||
423 | if( pArgs && SfxItemState::SET == pArgs->GetItemState( SID_OPEN_SMARTTAGOPTIONS(10000 + 1062), false, &pOpenSmartTagOptionsItem ) ) | |||
424 | aSet.Put( *static_cast<const SfxBoolItem*>(pOpenSmartTagOptionsItem) ); | |||
425 | ||||
426 | SfxAbstractDialogFactory* pFact = SfxAbstractDialogFactory::Create(); | |||
427 | VclPtr<SfxAbstractTabDialog> pDlg = pFact->CreateAutoCorrTabDialog(GetView()->GetFrameWeld(), &aSet); | |||
428 | pDlg->Execute(); | |||
429 | pDlg.disposeAndClear(); | |||
430 | ||||
431 | ||||
432 | rACW.SetLockWordLstLocked( bOldLocked ); | |||
433 | ||||
434 | SwEditShell::SetAutoFormatFlags( pAFlags ); | |||
435 | rACW.SetMinWordLen( pAFlags->nAutoCmpltWordLen ); | |||
436 | rACW.SetMaxCount( pAFlags->nAutoCmpltListLen ); | |||
437 | if (pAFlags->m_pAutoCompleteList) // any changes? | |||
438 | { | |||
439 | rACW.CheckChangedList( aTmpLst ); | |||
440 | // clear the temp WordList pointer | |||
441 | pAFlags->m_pAutoCompleteList = nullptr; | |||
442 | } | |||
443 | ||||
444 | if( !bOldAutoCmpltCollectWords && bOldAutoCmpltCollectWords != | |||
445 | pAFlags->bAutoCmpltCollectWords ) | |||
446 | { | |||
447 | // call on all Docs the idle formatter to start | |||
448 | // the collection of Words | |||
449 | for( SwDocShell *pDocSh = static_cast<SwDocShell*>(SfxObjectShell::GetFirst(checkSfxObjectShell<SwDocShell>)); | |||
450 | pDocSh; | |||
451 | pDocSh = static_cast<SwDocShell*>(SfxObjectShell::GetNext( *pDocSh, checkSfxObjectShell<SwDocShell> )) ) | |||
452 | { | |||
453 | SwDoc* pTmp = pDocSh->GetDoc(); | |||
454 | if ( pTmp->getIDocumentLayoutAccess().GetCurrentViewShell() ) | |||
455 | pTmp->InvalidateAutoCompleteFlag(); | |||
456 | } | |||
457 | } | |||
458 | } | |||
459 | break; | |||
460 | ||||
461 | case SID_PRINTPREVIEW(5000 + 325): | |||
462 | { | |||
463 | bool bSet = false; | |||
464 | bool bFound = false, bOnly = true; | |||
465 | SfxViewFrame *pTmpFrame = SfxViewFrame::GetFirst(this); | |||
466 | SfxViewShell* pViewShell = SfxViewShell::Current(); | |||
467 | SwView* pCurrView = dynamic_cast< SwView *> ( pViewShell ); | |||
468 | bool bCurrent = typeid(SwPagePreview) == typeid( pViewShell ); | |||
469 | ||||
470 | while( pTmpFrame ) // search Preview | |||
471 | { | |||
472 | if( typeid(SwView) == typeid( pTmpFrame->GetViewShell()) ) | |||
473 | bOnly = false; | |||
474 | else if( typeid(SwPagePreview) == typeid( pTmpFrame->GetViewShell())) | |||
475 | { | |||
476 | pTmpFrame->GetFrame().Appear(); | |||
477 | bFound = true; | |||
478 | } | |||
479 | if( bFound && !bOnly ) | |||
480 | break; | |||
481 | pTmpFrame = SfxViewFrame::GetNext(*pTmpFrame, this); | |||
482 | } | |||
483 | ||||
484 | if( pArgs && SfxItemState::SET == | |||
485 | pArgs->GetItemState( SID_PRINTPREVIEW(5000 + 325), false, &pItem )) | |||
486 | bSet = static_cast<const SfxBoolItem*>(pItem)->GetValue(); | |||
487 | else | |||
488 | bSet = !bCurrent; | |||
489 | ||||
490 | sal_uInt16 nSlotId = 0; | |||
491 | if( bSet && !bFound ) // Nothing found, so create new Preview | |||
492 | nSlotId = SID_VIEWSHELL1(5000 + 631); | |||
493 | else if( bFound && !bSet ) | |||
494 | nSlotId = bOnly ? SID_VIEWSHELL0(5000 + 630) : SID_VIEWSHELL1(5000 + 631); | |||
495 | ||||
496 | if( nSlotId ) | |||
497 | { | |||
498 | // PagePreview in the WebDocShell | |||
499 | // is found under Id VIEWSHELL2. | |||
500 | if( dynamic_cast< const SwWebDocShell *>( this ) != nullptr && SID_VIEWSHELL1(5000 + 631) == nSlotId ) | |||
501 | nSlotId = SID_VIEWSHELL2(5000 + 632); | |||
502 | ||||
503 | if( pCurrView && pCurrView->GetDocShell() == this ) | |||
504 | pTmpFrame = pCurrView->GetViewFrame(); | |||
505 | else | |||
506 | pTmpFrame = SfxViewFrame::GetFirst( this ); | |||
507 | ||||
508 | if (pTmpFrame) | |||
509 | pTmpFrame->GetDispatcher()->Execute( nSlotId, SfxCallMode::ASYNCHRON ); | |||
510 | } | |||
511 | ||||
512 | rReq.SetReturnValue(SfxBoolItem(SID_PRINTPREVIEW(5000 + 325), bSet )); | |||
513 | } | |||
514 | break; | |||
515 | case SID_TEMPLATE_LOAD(5000 + 663): | |||
516 | { | |||
517 | OUString aFileName; | |||
518 | static bool bText = true; | |||
519 | static bool bFrame = false; | |||
520 | static bool bPage = false; | |||
521 | static bool bNum = false; | |||
522 | static bool bMerge = false; | |||
523 | ||||
524 | SfxTemplateFlags nFlags = bFrame ? SfxTemplateFlags::LOAD_FRAME_STYLES : SfxTemplateFlags::NONE; | |||
525 | if(bPage) | |||
526 | nFlags |= SfxTemplateFlags::LOAD_PAGE_STYLES; | |||
527 | if(bNum) | |||
528 | nFlags |= SfxTemplateFlags::LOAD_NUM_STYLES; | |||
529 | if(nFlags == SfxTemplateFlags::NONE || bText) | |||
530 | nFlags |= SfxTemplateFlags::LOAD_TEXT_STYLES; | |||
531 | if(bMerge) | |||
532 | nFlags |= SfxTemplateFlags::MERGE_STYLES; | |||
533 | ||||
534 | if ( pArgs ) | |||
535 | { | |||
536 | const SfxStringItem* pTemplateItem = rReq.GetArg<SfxStringItem>(SID_TEMPLATE_NAME(5000 + 660)); | |||
537 | if ( pTemplateItem ) | |||
538 | { | |||
539 | aFileName = pTemplateItem->GetValue(); | |||
540 | const SfxInt32Item* pFlagsItem = rReq.GetArg<SfxInt32Item>(SID_TEMPLATE_LOAD(5000 + 663)); | |||
541 | if ( pFlagsItem ) | |||
542 | nFlags = static_cast<SfxTemplateFlags>(static_cast<sal_uInt16>(pFlagsItem->GetValue())); | |||
543 | } | |||
544 | } | |||
545 | ||||
546 | if ( aFileName.isEmpty() ) | |||
547 | { | |||
548 | SvtPathOptions aPathOpt; | |||
549 | SfxNewFileDialog aNewFileDlg(GetView()->GetFrameWeld(), SfxNewFileDialogMode::LoadTemplate); | |||
550 | aNewFileDlg.SetTemplateFlags(nFlags); | |||
551 | ||||
552 | sal_uInt16 nRet = aNewFileDlg.run(); | |||
553 | if(RET_TEMPLATE_LOAD100 == nRet) | |||
554 | { | |||
555 | FileDialogHelper aDlgHelper(TemplateDescription::FILEOPEN_SIMPLE, | |||
556 | FileDialogFlags::NONE, GetView()->GetFrameWeld()); | |||
557 | uno::Reference < XFilePicker3 > xFP = aDlgHelper.GetFilePicker(); | |||
558 | ||||
559 | xFP->setDisplayDirectory( aPathOpt.GetWorkPath() ); | |||
560 | ||||
561 | SfxObjectFactory &rFact = GetFactory(); | |||
562 | SfxFilterMatcher aMatcher( rFact.GetFactoryName() ); | |||
563 | SfxFilterMatcherIter aIter( aMatcher ); | |||
564 | std::shared_ptr<const SfxFilter> pFlt = aIter.First(); | |||
565 | while( pFlt ) | |||
566 | { | |||
567 | // --> OD #i117339# | |||
568 | if( pFlt && pFlt->IsAllowedAsTemplate() && | |||
569 | ( pFlt->GetUserData() == "CXML" || | |||
570 | pFlt->GetUserData() == "CXMLV" ) ) | |||
571 | { | |||
572 | const OUString sWild = pFlt->GetWildcard().getGlob(); | |||
573 | xFP->appendFilter( pFlt->GetUIName(), sWild ); | |||
574 | } | |||
575 | pFlt = aIter.Next(); | |||
576 | } | |||
577 | bool bWeb = dynamic_cast< SwWebDocShell *>( this ) != nullptr; | |||
578 | std::shared_ptr<const SfxFilter> pOwnFlt = | |||
579 | SwDocShell::Factory().GetFilterContainer()-> | |||
580 | GetFilter4FilterName("writer8"); | |||
581 | ||||
582 | // make sure the default file format is also available | |||
583 | if(bWeb) | |||
584 | { | |||
585 | const OUString sWild = pOwnFlt->GetWildcard().getGlob(); | |||
586 | xFP->appendFilter( pOwnFlt->GetUIName(), sWild ); | |||
587 | } | |||
588 | ||||
589 | bool bError = false; | |||
590 | // catch exception if wrong filter is selected - should not happen anymore | |||
591 | try | |||
592 | { | |||
593 | xFP->setCurrentFilter( pOwnFlt->GetUIName() ); | |||
594 | } | |||
595 | catch (const uno::Exception&) | |||
596 | { | |||
597 | bError = true; | |||
598 | } | |||
599 | ||||
600 | if( !bError && ERRCODE_NONEErrCode(0) == aDlgHelper.Execute() ) | |||
601 | { | |||
602 | aFileName = xFP->getSelectedFiles().getConstArray()[0]; | |||
603 | } | |||
604 | } | |||
605 | else if( RET_OK == nRet) | |||
606 | { | |||
607 | aFileName = aNewFileDlg.GetTemplateFileName(); | |||
608 | } | |||
609 | ||||
610 | nFlags = aNewFileDlg.GetTemplateFlags(); | |||
611 | rReq.AppendItem( SfxStringItem( SID_TEMPLATE_NAME(5000 + 660), aFileName ) ); | |||
612 | rReq.AppendItem( SfxInt32Item( SID_TEMPLATE_LOAD(5000 + 663), static_cast<long>(nFlags) ) ); | |||
613 | } | |||
614 | ||||
615 | if( !aFileName.isEmpty() ) | |||
616 | { | |||
617 | SwgReaderOption aOpt; | |||
618 | bText = bool(nFlags & SfxTemplateFlags::LOAD_TEXT_STYLES ); | |||
619 | aOpt.SetTextFormats(bText); | |||
620 | bFrame = bool(nFlags & SfxTemplateFlags::LOAD_FRAME_STYLES); | |||
621 | aOpt.SetFrameFormats(bFrame); | |||
622 | bPage = bool(nFlags & SfxTemplateFlags::LOAD_PAGE_STYLES ); | |||
623 | aOpt.SetPageDescs(bPage); | |||
624 | bNum = bool(nFlags & SfxTemplateFlags::LOAD_NUM_STYLES ); | |||
625 | aOpt.SetNumRules(bNum); | |||
626 | //different meaning between SFX_MERGE_STYLES and aOpt.SetMerge! | |||
627 | bMerge = bool(nFlags & SfxTemplateFlags::MERGE_STYLES); | |||
628 | aOpt.SetMerge( !bMerge ); | |||
629 | ||||
630 | SetError(LoadStylesFromFile(aFileName, aOpt, false)); | |||
631 | if ( !GetError() ) | |||
632 | rReq.Done(); | |||
633 | } | |||
634 | } | |||
635 | break; | |||
636 | case SID_SOURCEVIEW(5000 + 675): | |||
637 | { | |||
638 | SfxViewShell* pViewShell = GetView() | |||
639 | ? static_cast<SfxViewShell*>(GetView()) | |||
640 | : SfxViewShell::Current(); | |||
641 | SfxViewFrame* pViewFrame = pViewShell->GetViewFrame(); | |||
642 | SwSrcView* pSrcView = dynamic_cast< SwSrcView *>( pViewShell ); | |||
643 | if(!pSrcView) | |||
644 | { | |||
645 | // 3 possible state: | |||
646 | // 1 - file unsaved -> save as HTML | |||
647 | // 2 - file modified and HTML filter active -> save | |||
648 | // 3 - file saved in non-HTML -> QueryBox to save as HTML | |||
649 | std::shared_ptr<const SfxFilter> pHtmlFlt = | |||
650 | SwIoSystem::GetFilterOfFormat( | |||
651 | "HTML", | |||
652 | SwWebDocShell::Factory().GetFilterContainer() ); | |||
653 | bool bLocalHasName = HasName(); | |||
654 | if(bLocalHasName) | |||
655 | { | |||
656 | //check for filter type | |||
657 | std::shared_ptr<const SfxFilter> pFlt = GetMedium()->GetFilter(); | |||
658 | if(!pFlt || pFlt->GetUserData() != pHtmlFlt->GetUserData()) | |||
659 | { | |||
660 | std::unique_ptr<weld::Builder> xBuilder(Application::CreateBuilder(pViewFrame->GetWindow().GetFrameWeld(), "modules/swriter/ui/saveashtmldialog.ui")); | |||
661 | std::unique_ptr<weld::MessageDialog> xQuery(xBuilder->weld_message_dialog("SaveAsHTMLDialog")); | |||
662 | if (RET_YES == xQuery->run()) | |||
663 | bLocalHasName = false; | |||
664 | else | |||
665 | break; | |||
666 | } | |||
667 | } | |||
668 | if(!bLocalHasName) | |||
669 | { | |||
670 | FileDialogHelper aDlgHelper(TemplateDescription::FILESAVE_AUTOEXTENSION, | |||
671 | FileDialogFlags::NONE, | |||
672 | GetView()->GetFrameWeld()); | |||
673 | aDlgHelper.AddFilter( pHtmlFlt->GetFilterName(), pHtmlFlt->GetDefaultExtension() ); | |||
674 | aDlgHelper.SetCurrentFilter( pHtmlFlt->GetFilterName() ); | |||
675 | if( ERRCODE_NONEErrCode(0) != aDlgHelper.Execute()) | |||
676 | { | |||
677 | break; | |||
678 | } | |||
679 | OUString sPath = aDlgHelper.GetPath(); | |||
680 | SfxStringItem aName(SID_FILE_NAME(5000 + 507), sPath); | |||
681 | SfxStringItem aFilter(SID_FILTER_NAME(5000 + 530), pHtmlFlt->GetName()); | |||
682 | const SfxBoolItem* pBool = static_cast<const SfxBoolItem*>( | |||
683 | pViewFrame->GetDispatcher()->ExecuteList( | |||
684 | SID_SAVEASDOC(5000 + 502), SfxCallMode::SYNCHRON, | |||
685 | { &aName, &aFilter })); | |||
686 | if(!pBool || !pBool->GetValue()) | |||
687 | break; | |||
688 | } | |||
689 | } | |||
690 | ||||
691 | OSL_ENSURE(dynamic_cast<SwWebDocShell*>(this),do { if (true && (!(dynamic_cast<SwWebDocShell*> (this)))) { sal_detail_logFormat((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.osl"), ("/home/maarten/src/libreoffice/core/sw/source/uibase/app/docsh2.cxx" ":" "692" ": "), "%s", "SourceView only in WebDocShell"); } } while (false) | |||
692 | "SourceView only in WebDocShell")do { if (true && (!(dynamic_cast<SwWebDocShell*> (this)))) { sal_detail_logFormat((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.osl"), ("/home/maarten/src/libreoffice/core/sw/source/uibase/app/docsh2.cxx" ":" "692" ": "), "%s", "SourceView only in WebDocShell"); } } while (false); | |||
693 | ||||
694 | // the SourceView is not the 1 for SwWebDocShell | |||
695 | sal_uInt16 nSlot = SID_VIEWSHELL1(5000 + 631); | |||
696 | bool bSetModified = false; | |||
697 | VclPtr<SfxPrinter> pSavePrinter; | |||
698 | if( nullptr != pSrcView) | |||
699 | { | |||
700 | SfxPrinter* pTemp = GetDoc()->getIDocumentDeviceAccess().getPrinter( false ); | |||
701 | if(pTemp) | |||
702 | pSavePrinter = VclPtr<SfxPrinter>::Create(*pTemp); | |||
703 | bSetModified = IsModified() || pSrcView->IsModified(); | |||
704 | if(pSrcView->IsModified()||pSrcView->HasSourceSaved()) | |||
705 | { | |||
706 | utl::TempFile aTempFile; | |||
707 | aTempFile.EnableKillingFile(); | |||
708 | pSrcView->SaveContent(aTempFile.GetURL()); | |||
709 | bDone = true; | |||
710 | SvxMacro aMac(OUString(), OUString(), STARBASIC); | |||
711 | SfxEventConfiguration::ConfigureEvent(GlobalEventConfig::GetEventName( GlobalEventId::OPENDOC ), aMac, this); | |||
712 | SfxEventConfiguration::ConfigureEvent(GlobalEventConfig::GetEventName( GlobalEventId::PREPARECLOSEDOC ), aMac, this); | |||
713 | SfxEventConfiguration::ConfigureEvent(GlobalEventConfig::GetEventName( GlobalEventId::ACTIVATEDOC ), aMac, this); | |||
714 | SfxEventConfiguration::ConfigureEvent(GlobalEventConfig::GetEventName( GlobalEventId::DEACTIVATEDOC ), aMac, this); | |||
715 | ReloadFromHtml(aTempFile.GetURL(), pSrcView); | |||
716 | nSlot = 0; | |||
717 | } | |||
718 | else | |||
719 | { | |||
720 | nSlot = SID_VIEWSHELL0(5000 + 630); | |||
721 | } | |||
722 | } | |||
723 | if(nSlot) | |||
724 | pViewFrame->GetDispatcher()->Execute(nSlot, SfxCallMode::SYNCHRON); | |||
725 | if(bSetModified) | |||
726 | GetDoc()->getIDocumentState().SetModified(); | |||
727 | if(pSavePrinter) | |||
728 | { | |||
729 | GetDoc()->getIDocumentDeviceAccess().setPrinter( pSavePrinter, true, true); | |||
730 | //pSavePrinter must not be deleted again | |||
731 | } | |||
732 | pViewFrame->GetBindings().SetState(SfxBoolItem(SID_SOURCEVIEW(5000 + 675), false)); // not SID_VIEWSHELL2 | |||
733 | pViewFrame->GetBindings().Invalidate( SID_NEWWINDOW(5000 + 620) ); | |||
734 | pViewFrame->GetBindings().Invalidate( SID_BROWSER_MODE(5000 + 1313) ); | |||
735 | pViewFrame->GetBindings().Invalidate( FN_PRINT_LAYOUT((20000 + 200) + 37) ); | |||
736 | } | |||
737 | break; | |||
738 | case SID_GET_COLORLIST( 10000 + 441 ): | |||
739 | { | |||
740 | const SvxColorListItem* pColItem = GetItem(SID_COLOR_TABLETypedWhichId<SvxColorListItem>( 10000 + 179 )); | |||
741 | const XColorListRef& pList = pColItem->GetColorList(); | |||
742 | rReq.SetReturnValue(OfaRefItem<XColorList>(SID_GET_COLORLIST( 10000 + 441 ), pList)); | |||
743 | } | |||
744 | break; | |||
745 | case FN_ABSTRACT_STARIMPRESS((20000 + 1600) + 13): | |||
746 | case FN_ABSTRACT_NEWDOC((20000 + 1600) + 12): | |||
747 | { | |||
748 | SwAbstractDialogFactory* pFact = SwAbstractDialogFactory::Create(); | |||
749 | ScopedVclPtr<AbstractSwInsertAbstractDlg> pDlg(pFact->CreateSwInsertAbstractDlg(GetView()->GetFrameWeld())); | |||
750 | if(RET_OK == pDlg->Execute()) | |||
751 | { | |||
752 | sal_uInt8 nLevel = pDlg->GetLevel(); | |||
753 | sal_uInt8 nPara = pDlg->GetPara(); | |||
754 | SwDoc* pSmryDoc = new SwDoc(); | |||
755 | SfxObjectShellLock xDocSh(new SwDocShell(*pSmryDoc, SfxObjectCreateMode::STANDARD)); | |||
756 | xDocSh->DoInitNew(); | |||
757 | ||||
758 | bool bImpress = FN_ABSTRACT_STARIMPRESS((20000 + 1600) + 13) == nWhich; | |||
759 | m_xDoc->Summary(*pSmryDoc, nLevel, nPara, bImpress); | |||
760 | if( bImpress ) | |||
761 | { | |||
762 | WriterRef xWrt; | |||
763 | // mba: looks as if relative URLs don't make sense here | |||
764 | ::GetRTFWriter(OUString(), OUString(), xWrt); | |||
765 | SvMemoryStream *pStrm = new SvMemoryStream(); | |||
766 | pStrm->SetBufferSize( 16348 ); | |||
767 | SwWriter aWrt( *pStrm, *pSmryDoc ); | |||
768 | ErrCode eErr = aWrt.Write( xWrt ); | |||
769 | if( !eErr.IgnoreWarning() ) | |||
770 | { | |||
771 | uno::Reference< uno::XComponentContext > xContext = ::comphelper::getProcessComponentContext(); | |||
772 | uno::Reference< frame::XDispatchProvider > xProv = drawing::ModuleDispatcher::create( xContext ); | |||
773 | ||||
774 | uno::Reference< frame::XDispatchHelper > xHelper( frame::DispatchHelper::create(xContext) ); | |||
775 | pStrm->Seek( STREAM_SEEK_TO_END((sal_uInt64) 0xFFFFFFFFFFFFFFFFul) ); | |||
776 | pStrm->WriteChar( '\0' ); | |||
777 | pStrm->Seek( STREAM_SEEK_TO_BEGIN0L ); | |||
778 | ||||
779 | // Transfer ownership of stream to a lockbytes object | |||
780 | SvLockBytes aLockBytes( pStrm, true ); | |||
781 | SvLockBytesStat aStat; | |||
782 | if ( aLockBytes.Stat( &aStat ) == ERRCODE_NONEErrCode(0) ) | |||
783 | { | |||
784 | sal_uInt32 nLen = aStat.nSize; | |||
785 | std::size_t nRead = 0; | |||
786 | uno::Sequence< sal_Int8 > aSeq( nLen ); | |||
787 | aLockBytes.ReadAt( 0, aSeq.getArray(), nLen, &nRead ); | |||
788 | ||||
789 | uno::Sequence< beans::PropertyValue > aArgs(1); | |||
790 | aArgs[0].Name = "RtfOutline"; | |||
791 | aArgs[0].Value <<= aSeq; | |||
792 | xHelper->executeDispatch( xProv, "SendOutlineToImpress", OUString(), 0, aArgs ); | |||
793 | } | |||
794 | } | |||
795 | else | |||
796 | ErrorHandler::HandleError( eErr ); | |||
797 | } | |||
798 | else | |||
799 | { | |||
800 | // Create new document | |||
801 | SfxViewFrame *pFrame = SfxViewFrame::LoadDocument( *xDocSh, SFX_INTERFACE_NONE ); | |||
802 | SwView *pCurrView = static_cast<SwView*>( pFrame->GetViewShell()); | |||
803 | ||||
804 | // Set document's title | |||
805 | OUString aTmp = SwResId(STR_ABSTRACT_TITLEreinterpret_cast<char const *>("STR_ABSTRACT_TITLE" "\004" u8"Abstract: ")) + GetTitle(); | |||
806 | xDocSh->SetTitle( aTmp ); | |||
807 | pCurrView->GetWrtShell().SetNewDoc(); | |||
808 | pFrame->Show(); | |||
809 | pSmryDoc->getIDocumentState().SetModified(); | |||
810 | } | |||
811 | ||||
812 | } | |||
813 | } | |||
814 | break; | |||
815 | case FN_OUTLINE_TO_CLIPBOARD(20000 + 37): | |||
816 | case FN_OUTLINE_TO_IMPRESS(20000 + 36): | |||
817 | { | |||
818 | bool bEnable = IsEnableSetModified(); | |||
819 | EnableSetModified( false ); | |||
820 | WriterRef xWrt; | |||
821 | // mba: looks as if relative URLs don't make sense here | |||
822 | ::GetRTFWriter( OUString('O'), OUString(), xWrt ); | |||
823 | std::unique_ptr<SvMemoryStream> pStrm (new SvMemoryStream()); | |||
824 | pStrm->SetBufferSize( 16348 ); | |||
825 | SwWriter aWrt( *pStrm, *GetDoc() ); | |||
826 | ErrCode eErr = aWrt.Write( xWrt ); | |||
827 | EnableSetModified( bEnable ); | |||
828 | if( !eErr.IgnoreWarning() ) | |||
829 | { | |||
830 | pStrm->Seek( STREAM_SEEK_TO_END((sal_uInt64) 0xFFFFFFFFFFFFFFFFul) ); | |||
831 | pStrm->WriteChar( '\0' ); | |||
832 | pStrm->Seek( STREAM_SEEK_TO_BEGIN0L ); | |||
833 | if ( nWhich == FN_OUTLINE_TO_IMPRESS(20000 + 36) ) | |||
834 | { | |||
835 | uno::Reference< uno::XComponentContext > xContext = ::comphelper::getProcessComponentContext(); | |||
836 | uno::Reference< frame::XDispatchProvider > xProv = drawing::ModuleDispatcher::create( xContext ); | |||
837 | ||||
838 | uno::Reference< frame::XDispatchHelper > xHelper( frame::DispatchHelper::create(xContext) ); | |||
839 | pStrm->Seek( STREAM_SEEK_TO_END((sal_uInt64) 0xFFFFFFFFFFFFFFFFul) ); | |||
840 | pStrm->WriteChar( '\0' ); | |||
841 | pStrm->Seek( STREAM_SEEK_TO_BEGIN0L ); | |||
842 | ||||
843 | // Transfer ownership of stream to a lockbytes object | |||
844 | SvLockBytes aLockBytes( pStrm.release(), true ); | |||
845 | SvLockBytesStat aStat; | |||
846 | if ( aLockBytes.Stat( &aStat ) == ERRCODE_NONEErrCode(0) ) | |||
847 | { | |||
848 | sal_uInt32 nLen = aStat.nSize; | |||
849 | std::size_t nRead = 0; | |||
850 | uno::Sequence< sal_Int8 > aSeq( nLen ); | |||
851 | aLockBytes.ReadAt( 0, aSeq.getArray(), nLen, &nRead ); | |||
852 | ||||
853 | uno::Sequence< beans::PropertyValue > aArgs(1); | |||
854 | aArgs[0].Name = "RtfOutline"; | |||
855 | aArgs[0].Value <<= aSeq; | |||
856 | xHelper->executeDispatch( xProv, "SendOutlineToImpress", OUString(), 0, aArgs ); | |||
857 | } | |||
858 | } | |||
859 | else | |||
860 | { | |||
861 | rtl::Reference<TransferDataContainer> pClipCntnr = new TransferDataContainer; | |||
862 | ||||
863 | pClipCntnr->CopyAnyData( SotClipboardFormatId::RTF, static_cast<char const *>( | |||
864 | pStrm->GetData()), pStrm->GetEndOfData() ); | |||
865 | pClipCntnr->CopyToClipboard( | |||
866 | GetView()? &GetView()->GetEditWin() : nullptr ); | |||
867 | } | |||
868 | } | |||
869 | else | |||
870 | ErrorHandler::HandleError( eErr ); | |||
871 | } | |||
872 | break; | |||
873 | case SID_SPELLCHECKER_CHANGED( 10000 + 446 ): | |||
874 | //! false, true, true is on the save side but a probably overdone | |||
875 | SwModule::CheckSpellChanges(false, true, true, false ); | |||
876 | break; | |||
877 | ||||
878 | case SID_MAIL_PREPAREEXPORT(5000 + 385): | |||
879 | { | |||
880 | //pWrtShell is not set in page preview | |||
881 | if (m_pWrtShell) | |||
882 | m_pWrtShell->StartAllAction(); | |||
883 | m_xDoc->getIDocumentFieldsAccess().UpdateFields( false ); | |||
884 | m_xDoc->getIDocumentLinksAdministration().EmbedAllLinks(); | |||
885 | m_IsRemovedInvisibleContent | |||
886 | = officecfg::Office::Security::HiddenContent::RemoveHiddenContent::get(); | |||
887 | if (m_IsRemovedInvisibleContent) | |||
888 | m_xDoc->RemoveInvisibleContent(); | |||
889 | if (m_pWrtShell) | |||
890 | m_pWrtShell->EndAllAction(); | |||
891 | } | |||
892 | break; | |||
893 | ||||
894 | case SID_MAIL_EXPORT_FINISHED(5000 + 388): | |||
895 | { | |||
896 | if (m_pWrtShell) | |||
897 | m_pWrtShell->StartAllAction(); | |||
898 | //try to undo the removal of invisible content | |||
899 | if (m_IsRemovedInvisibleContent) | |||
900 | m_xDoc->RestoreInvisibleContent(); | |||
901 | if (m_pWrtShell) | |||
902 | m_pWrtShell->EndAllAction(); | |||
903 | } | |||
904 | break; | |||
905 | case FN_NEW_HTML_DOC(20000 + 40 ): | |||
906 | case FN_NEW_GLOBAL_DOC(20000 + 4 ): | |||
907 | { | |||
908 | bDone = false; | |||
909 | bool bCreateHtml = FN_NEW_HTML_DOC(20000 + 40 ) == nWhich; | |||
910 | ||||
911 | bool bCreateByOutlineLevel = false; | |||
912 | sal_Int32 nTemplateOutlineLevel = 0; | |||
913 | ||||
914 | OUString aFileName, aTemplateName; | |||
915 | if( pArgs && SfxItemState::SET == pArgs->GetItemState( nWhich, false, &pItem ) ) | |||
916 | { | |||
917 | aFileName = static_cast<const SfxStringItem*>(pItem)->GetValue(); | |||
918 | const SfxStringItem* pTemplItem = SfxItemSet::GetItem<SfxStringItem>(pArgs, SID_TEMPLATE_NAME(5000 + 660), false); | |||
919 | if ( pTemplItem ) | |||
920 | aTemplateName = pTemplItem->GetValue(); | |||
921 | } | |||
922 | if ( aFileName.isEmpty() ) | |||
923 | { | |||
924 | bool bError = false; | |||
925 | ||||
926 | FileDialogHelper aDlgHelper(TemplateDescription::FILESAVE_AUTOEXTENSION_TEMPLATE, FileDialogFlags::NONE, | |||
927 | GetView()->GetFrameWeld()); | |||
928 | ||||
929 | const sal_Int16 nControlIds[] = { | |||
930 | CommonFilePickerElementIds::PUSHBUTTON_OK, | |||
931 | CommonFilePickerElementIds::PUSHBUTTON_CANCEL, | |||
932 | CommonFilePickerElementIds::LISTBOX_FILTER, | |||
933 | CommonFilePickerElementIds::CONTROL_FILEVIEW, | |||
934 | CommonFilePickerElementIds::EDIT_FILEURL, | |||
935 | ExtendedFilePickerElementIds::CHECKBOX_AUTOEXTENSION, | |||
936 | ExtendedFilePickerElementIds::LISTBOX_TEMPLATE, | |||
937 | 0 | |||
938 | }; | |||
939 | ||||
940 | if (bCreateHtml) | |||
941 | { | |||
942 | const char* aHTMLHelpIds[] = | |||
943 | { | |||
944 | HID_SEND_HTML_CTRL_PUSHBUTTON_OK"SW_HID_SEND_HTML_CTRL_PUSHBUTTON_OK", | |||
945 | HID_SEND_HTML_CTRL_PUSHBUTTON_CANCEL"SW_HID_SEND_HTML_CTRL_PUSHBUTTON_CANCEL", | |||
946 | HID_SEND_HTML_CTRL_LISTBOX_FILTER"SW_HID_SEND_HTML_CTRL_LISTBOX_FILTER", | |||
947 | HID_SEND_HTML_CTRL_CONTROL_FILEVIEW"SW_HID_SEND_HTML_CTRL_CONTROL_FILEVIEW", | |||
948 | HID_SEND_HTML_CTRL_EDIT_FILEURL"SW_HID_SEND_HTML_CTRL_EDIT_FILEURL", | |||
949 | HID_SEND_HTML_CTRL_CHECKBOX_AUTOEXTENSION"SW_HID_SEND_HTML_CTRL_CHECKBOX_AUTOEXTENSION", | |||
950 | HID_SEND_HTML_CTRL_LISTBOX_TEMPLATE"SW_HID_SEND_HTML_CTRL_LISTBOX_TEMPLATE", | |||
951 | "" | |||
952 | }; | |||
953 | aDlgHelper.SetControlHelpIds( nControlIds, aHTMLHelpIds ); | |||
954 | } | |||
955 | else | |||
956 | { | |||
957 | const char* aMasterHelpIds[] = | |||
958 | { | |||
959 | HID_SEND_MASTER_CTRL_PUSHBUTTON_OK"SW_HID_SEND_MASTER_CTRL_PUSHBUTTON_OK", | |||
960 | HID_SEND_MASTER_CTRL_PUSHBUTTON_CANCEL"SW_HID_SEND_MASTER_CTRL_PUSHBUTTON_CANCEL", | |||
961 | HID_SEND_MASTER_CTRL_LISTBOX_FILTER"SW_HID_SEND_MASTER_CTRL_LISTBOX_FILTER", | |||
962 | HID_SEND_MASTER_CTRL_CONTROL_FILEVIEW"SW_HID_SEND_MASTER_CTRL_CONTROL_FILEVIEW", | |||
963 | HID_SEND_MASTER_CTRL_EDIT_FILEURL"SW_HID_SEND_MASTER_CTRL_EDIT_FILEURL", | |||
964 | HID_SEND_MASTER_CTRL_CHECKBOX_AUTOEXTENSION"SW_HID_SEND_MASTER_CTRL_CHECKBOX_AUTOEXTENSION", | |||
965 | HID_SEND_MASTER_CTRL_LISTBOX_TEMPLATE"SW_HID_SEND_MASTER_CTRL_LISTBOX_TEMPLATE", | |||
966 | "" | |||
967 | }; | |||
968 | aDlgHelper.SetControlHelpIds( nControlIds, aMasterHelpIds ); | |||
969 | } | |||
970 | uno::Reference < XFilePicker3 > xFP = aDlgHelper.GetFilePicker(); | |||
971 | ||||
972 | std::shared_ptr<const SfxFilter> pFlt; | |||
973 | const char* pStrId; | |||
974 | ||||
975 | if( bCreateHtml ) | |||
976 | { | |||
977 | // for HTML there is only one filter!! | |||
978 | pFlt = SwIoSystem::GetFilterOfFormat( | |||
979 | "HTML", | |||
980 | SwWebDocShell::Factory().GetFilterContainer() ); | |||
981 | pStrId = STR_LOAD_HTML_DOCreinterpret_cast<char const *>("STR_LOAD_HTML_DOC" "\004" u8"Name and Path of the HTML Document"); | |||
982 | } | |||
983 | else | |||
984 | { | |||
985 | // for Global-documents we now only offer the current one. | |||
986 | pFlt = SwGlobalDocShell::Factory().GetFilterContainer()-> | |||
987 | GetFilter4Extension( "odm" ); | |||
988 | pStrId = STR_LOAD_GLOBAL_DOCreinterpret_cast<char const *>("STR_LOAD_GLOBAL_DOC" "\004" u8"Name and Path of Master Document"); | |||
989 | } | |||
990 | ||||
991 | if( pFlt ) | |||
992 | { | |||
993 | const OUString sWild = pFlt->GetWildcard().getGlob(); | |||
994 | xFP->appendFilter( pFlt->GetUIName(), sWild ); | |||
995 | try | |||
996 | { | |||
997 | xFP->setCurrentFilter( pFlt->GetUIName() ) ; | |||
998 | } | |||
999 | catch (const uno::Exception&) | |||
1000 | { | |||
1001 | bError = true; | |||
1002 | } | |||
1003 | } | |||
1004 | if(!bError) | |||
1005 | { | |||
1006 | uno::Reference<XFilePickerControlAccess> xCtrlAcc(xFP, UNO_QUERY); | |||
1007 | ||||
1008 | bool bOutline[MAXLEVEL] = {false}; | |||
1009 | const SwOutlineNodes& rOutlNds = m_xDoc->GetNodes().GetOutLineNds(); | |||
1010 | for( size_t n = 0; n < rOutlNds.size(); ++n ) | |||
1011 | { | |||
1012 | const int nLevel = rOutlNds[n]->GetTextNode()->GetAttrOutlineLevel(); | |||
1013 | if( nLevel > 0 && ! bOutline[nLevel-1] ) | |||
1014 | { | |||
1015 | bOutline[nLevel-1] = true; | |||
1016 | } | |||
1017 | } | |||
1018 | ||||
1019 | const sal_uInt16 nStyleCount = m_xDoc->GetTextFormatColls()->size(); | |||
1020 | Sequence<OUString> aListBoxEntries( MAXLEVEL + nStyleCount); | |||
1021 | OUString* pEntries = aListBoxEntries.getArray(); | |||
1022 | sal_Int32 nIdx = 0 ; | |||
1023 | ||||
1024 | OUString sOutline( SwResId(STR_FDLG_OUTLINE_LEVELreinterpret_cast<char const *>("STR_FDLG_OUTLINE_LEVEL" "\004" u8"Outline: Level ")) ); | |||
1025 | for( sal_uInt16 i = 0; i < MAXLEVEL; ++i ) | |||
1026 | { | |||
1027 | if( bOutline[i] ) | |||
1028 | pEntries[nIdx++] = sOutline + OUString::number( i+1 ); | |||
1029 | } | |||
1030 | ||||
1031 | OUString sStyle( SwResId(STR_FDLG_STYLEreinterpret_cast<char const *>("STR_FDLG_STYLE" "\004" u8"Style: " )) ); | |||
1032 | for(sal_uInt16 i = 0; i < nStyleCount; ++i) | |||
1033 | { | |||
1034 | SwTextFormatColl &rTextColl = *(*m_xDoc->GetTextFormatColls())[ i ]; | |||
1035 | if( !rTextColl.IsDefault() && rTextColl.IsAtDocNodeSet() ) | |||
1036 | { | |||
1037 | pEntries[nIdx++] = sStyle + rTextColl.GetName(); | |||
1038 | } | |||
1039 | } | |||
1040 | ||||
1041 | aListBoxEntries.realloc(nIdx); | |||
1042 | sal_Int16 nSelect = 0; | |||
1043 | ||||
1044 | try | |||
1045 | { | |||
1046 | Any aTemplates(&aListBoxEntries, cppu::UnoType<decltype(aListBoxEntries)>::get()); | |||
1047 | ||||
1048 | xCtrlAcc->setValue( ExtendedFilePickerElementIds::LISTBOX_TEMPLATE, | |||
1049 | ListboxControlActions::ADD_ITEMS , aTemplates ); | |||
1050 | Any aSelectPos(&nSelect, cppu::UnoType<decltype(nSelect)>::get()); | |||
1051 | xCtrlAcc->setValue( ExtendedFilePickerElementIds::LISTBOX_TEMPLATE, | |||
1052 | ListboxControlActions::SET_SELECT_ITEM, aSelectPos ); | |||
1053 | xCtrlAcc->setLabel( ExtendedFilePickerElementIds::LISTBOX_TEMPLATE, | |||
1054 | SwResId( STR_FDLG_TEMPLATE_NAMEreinterpret_cast<char const *>("STR_FDLG_TEMPLATE_NAME" "\004" u8"separated by: ") )); | |||
1055 | } | |||
1056 | catch (const Exception&) | |||
1057 | { | |||
1058 | OSL_FAIL("control access failed")do { if (true && (((sal_Bool)1))) { sal_detail_logFormat ((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.osl"), ("/home/maarten/src/libreoffice/core/sw/source/uibase/app/docsh2.cxx" ":" "1058" ": "), "%s", "control access failed"); } } while ( false); | |||
1059 | } | |||
1060 | ||||
1061 | xFP->setTitle(SwResId(pStrId)); | |||
1062 | SvtPathOptions aPathOpt; | |||
1063 | xFP->setDisplayDirectory( aPathOpt.GetWorkPath() ); | |||
1064 | if( ERRCODE_NONEErrCode(0) == aDlgHelper.Execute()) | |||
1065 | { | |||
1066 | aFileName = xFP->getSelectedFiles().getConstArray()[0]; | |||
1067 | Any aTemplateValue = xCtrlAcc->getValue( | |||
1068 | ExtendedFilePickerElementIds::LISTBOX_TEMPLATE, | |||
1069 | ListboxControlActions::GET_SELECTED_ITEM ); | |||
1070 | OUString sTmpl; | |||
1071 | aTemplateValue >>= sTmpl; | |||
1072 | ||||
1073 | OUString aStyle(SwResId(STR_FDLG_STYLEreinterpret_cast<char const *>("STR_FDLG_STYLE" "\004" u8"Style: " ))); | |||
1074 | OUString aOutline(SwResId(STR_FDLG_OUTLINE_LEVELreinterpret_cast<char const *>("STR_FDLG_OUTLINE_LEVEL" "\004" u8"Outline: Level "))); | |||
1075 | ||||
1076 | if ( sTmpl.startsWith(aStyle) ) | |||
1077 | { | |||
1078 | aTemplateName = sTmpl.copy( aStyle.getLength() ); //get string behind "Style: " | |||
1079 | } | |||
1080 | else if ( sTmpl.startsWith(aOutline) ) | |||
1081 | { | |||
1082 | nTemplateOutlineLevel = sTmpl.copy(aOutline.getLength()).toInt32(); //get string behind "Outline: Level "; | |||
1083 | bCreateByOutlineLevel = true; | |||
1084 | } | |||
1085 | ||||
1086 | if ( !aFileName.isEmpty() ) | |||
1087 | { | |||
1088 | rReq.AppendItem( SfxStringItem( nWhich, aFileName ) ); | |||
1089 | if( !aTemplateName.isEmpty() ) | |||
1090 | rReq.AppendItem( SfxStringItem( SID_TEMPLATE_NAME(5000 + 660), aTemplateName ) ); | |||
1091 | } | |||
1092 | } | |||
1093 | } | |||
1094 | } | |||
1095 | ||||
1096 | if( !aFileName.isEmpty() ) | |||
1097 | { | |||
1098 | if( PrepareClose( false ) ) | |||
1099 | { | |||
1100 | SwWait aWait( *this, true ); | |||
1101 | ||||
1102 | if ( bCreateByOutlineLevel ) | |||
1103 | { | |||
1104 | bDone = bCreateHtml | |||
1105 | ? m_xDoc->GenerateHTMLDoc( aFileName, nTemplateOutlineLevel ) | |||
1106 | : m_xDoc->GenerateGlobalDoc( aFileName, nTemplateOutlineLevel ); | |||
1107 | } | |||
1108 | else | |||
1109 | { | |||
1110 | const SwTextFormatColl* pSplitColl = nullptr; | |||
1111 | if ( !aTemplateName.isEmpty() ) | |||
1112 | pSplitColl = m_xDoc->FindTextFormatCollByName(aTemplateName); | |||
1113 | bDone = bCreateHtml | |||
1114 | ? m_xDoc->GenerateHTMLDoc( aFileName, pSplitColl ) | |||
1115 | : m_xDoc->GenerateGlobalDoc( aFileName, pSplitColl ); | |||
1116 | } | |||
1117 | if( bDone ) | |||
1118 | { | |||
1119 | SfxStringItem aName( SID_FILE_NAME(5000 + 507), aFileName ); | |||
1120 | SfxStringItem aReferer(SID_REFERER(5000 + 654), OUString()); | |||
1121 | SfxViewShell* pViewShell = SfxViewShell::GetFirst(); | |||
1122 | while(pViewShell) | |||
1123 | { | |||
1124 | //search for the view that created the call | |||
1125 | if(pViewShell->GetObjectShell() == this && pViewShell->GetDispatcher()) | |||
1126 | { | |||
1127 | std::unique_ptr<SfxFrameItem> pFrameItem(new SfxFrameItem( SID_DOCFRAME(5000 + 598), | |||
1128 | pViewShell->GetViewFrame() )); | |||
1129 | SfxDispatcher* pDispatch = pViewShell->GetDispatcher(); | |||
1130 | pDispatch->ExecuteList(SID_OPENDOC(5000 + 501), | |||
1131 | SfxCallMode::ASYNCHRON, | |||
1132 | { &aName, &aReferer, pFrameItem.get() }); | |||
1133 | break; | |||
1134 | } | |||
1135 | pViewShell = SfxViewShell::GetNext(*pViewShell); | |||
1136 | } | |||
1137 | } | |||
1138 | } | |||
1139 | if( !bDone && !rReq.IsAPI() ) | |||
1140 | { | |||
1141 | std::unique_ptr<weld::MessageDialog> xInfoBox(Application::CreateMessageDialog(nullptr, | |||
1142 | VclMessageType::Info, VclButtonsType::Ok, | |||
1143 | SwResId(STR_CANTCREATEreinterpret_cast<char const *>("STR_CANTCREATE" "\004" u8"Can't create document." )))); | |||
1144 | xInfoBox->run(); | |||
1145 | } | |||
1146 | } | |||
1147 | } | |||
1148 | rReq.SetReturnValue(SfxBoolItem( nWhich, bDone )); | |||
1149 | if (bDone) | |||
1150 | rReq.Done(); | |||
1151 | else | |||
1152 | rReq.Ignore(); | |||
1153 | break; | |||
1154 | ||||
1155 | case SID_ATTR_YEAR2000(((((10000 + 1499) + 1) + 499) + 1) + 87): | |||
1156 | if ( pArgs && SfxItemState::SET == pArgs->GetItemState( nWhich , false, &pItem )) | |||
1157 | { | |||
1158 | OSL_ENSURE(dynamic_cast< const SfxUInt16Item *>( pItem ) != nullptr, "wrong Item")do { if (true && (!(dynamic_cast< const SfxUInt16Item *>( pItem ) != nullptr))) { sal_detail_logFormat((SAL_DETAIL_LOG_LEVEL_WARN ), ("legacy.osl"), ("/home/maarten/src/libreoffice/core/sw/source/uibase/app/docsh2.cxx" ":" "1158" ": "), "%s", "wrong Item"); } } while (false); | |||
1159 | sal_uInt16 nYear2K = static_cast<const SfxUInt16Item*>(pItem)->GetValue(); | |||
1160 | // iterate over Views and put the State to FormShells | |||
1161 | ||||
1162 | SfxViewFrame* pVFrame = SfxViewFrame::GetFirst( this ); | |||
1163 | SfxViewShell* pViewShell = pVFrame ? pVFrame->GetViewShell() : nullptr; | |||
1164 | SwView* pCurrView = dynamic_cast< SwView* >( pViewShell ); | |||
1165 | while(pCurrView) | |||
1166 | { | |||
1167 | FmFormShell* pFormShell = pCurrView->GetFormShell(); | |||
1168 | if(pFormShell) | |||
1169 | pFormShell->SetY2KState(nYear2K); | |||
1170 | pVFrame = SfxViewFrame::GetNext( *pVFrame, this ); | |||
1171 | pViewShell = pVFrame ? pVFrame->GetViewShell() : nullptr; | |||
1172 | pCurrView = dynamic_cast<SwView*>( pViewShell ); | |||
1173 | } | |||
1174 | m_xDoc->GetNumberFormatter()->SetYear2000(nYear2K); | |||
1175 | } | |||
1176 | break; | |||
1177 | case FN_OPEN_FILE(20000 + 7 ): | |||
1178 | { | |||
1179 | SfxViewShell* pViewShell = GetView(); | |||
1180 | if (!pViewShell) | |||
1181 | pViewShell = SfxViewShell::Current(); | |||
1182 | ||||
1183 | if (!pViewShell) | |||
1184 | // Ok. I did my best. | |||
1185 | break; | |||
1186 | ||||
1187 | SfxStringItem aApp(SID_DOC_SERVICE(5000 + 511), "com.sun.star.text.TextDocument"); | |||
1188 | SfxStringItem aTarget(SID_TARGETNAME(5000 + 560), "_blank"); | |||
1189 | pViewShell->GetDispatcher()->ExecuteList(SID_OPENDOC(5000 + 501), | |||
1190 | SfxCallMode::API|SfxCallMode::SYNCHRON, | |||
1191 | { &aApp, &aTarget }); | |||
1192 | } | |||
1193 | break; | |||
1194 | case SID_CLASSIFICATION_APPLY(5000 + 672): | |||
1195 | { | |||
1196 | if (pArgs && pArgs->GetItemState(nWhich, false, &pItem) == SfxItemState::SET) | |||
1197 | { | |||
1198 | SwWrtShell* pSh = GetWrtShell(); | |||
1199 | const OUString& rValue = static_cast<const SfxStringItem*>(pItem)->GetValue(); | |||
1200 | auto eType = SfxClassificationPolicyType::IntellectualProperty; | |||
1201 | if (pArgs->GetItemState(SID_TYPE_NAME(5000 + 533), false, &pItem) == SfxItemState::SET) | |||
1202 | { | |||
1203 | const OUString& rType = static_cast<const SfxStringItem*>(pItem)->GetValue(); | |||
1204 | eType = SfxClassificationHelper::stringToPolicyType(rType); | |||
1205 | } | |||
1206 | pSh->SetClassification(rValue, eType); | |||
1207 | } | |||
1208 | else | |||
1209 | SAL_WARN("sw.ui", "missing parameter for SID_CLASSIFICATION_APPLY")do { if (true) { switch (sal_detail_log_report(::SAL_DETAIL_LOG_LEVEL_WARN , "sw.ui")) { case SAL_DETAIL_LOG_ACTION_IGNORE: break; case SAL_DETAIL_LOG_ACTION_LOG : if (sizeof ::sal::detail::getResult( ::sal::detail::StreamStart () << "missing parameter for SID_CLASSIFICATION_APPLY") == 1) { ::sal_detail_log( (::SAL_DETAIL_LOG_LEVEL_WARN), ("sw.ui" ), ("/home/maarten/src/libreoffice/core/sw/source/uibase/app/docsh2.cxx" ":" "1209" ": "), ::sal::detail::unwrapStream( ::sal::detail ::StreamStart() << "missing parameter for SID_CLASSIFICATION_APPLY" ), 0); } else { ::std::ostringstream sal_detail_stream; sal_detail_stream << "missing parameter for SID_CLASSIFICATION_APPLY"; :: sal::detail::log( (::SAL_DETAIL_LOG_LEVEL_WARN), ("sw.ui"), ( "/home/maarten/src/libreoffice/core/sw/source/uibase/app/docsh2.cxx" ":" "1209" ": "), sal_detail_stream, 0); }; break; case SAL_DETAIL_LOG_ACTION_FATAL : if (sizeof ::sal::detail::getResult( ::sal::detail::StreamStart () << "missing parameter for SID_CLASSIFICATION_APPLY") == 1) { ::sal_detail_log( (::SAL_DETAIL_LOG_LEVEL_WARN), ("sw.ui" ), ("/home/maarten/src/libreoffice/core/sw/source/uibase/app/docsh2.cxx" ":" "1209" ": "), ::sal::detail::unwrapStream( ::sal::detail ::StreamStart() << "missing parameter for SID_CLASSIFICATION_APPLY" ), 0); } else { ::std::ostringstream sal_detail_stream; sal_detail_stream << "missing parameter for SID_CLASSIFICATION_APPLY"; :: sal::detail::log( (::SAL_DETAIL_LOG_LEVEL_WARN), ("sw.ui"), ( "/home/maarten/src/libreoffice/core/sw/source/uibase/app/docsh2.cxx" ":" "1209" ": "), sal_detail_stream, 0); }; std::abort(); break ; } } } while (false); | |||
1210 | } | |||
1211 | break; | |||
1212 | case SID_CLASSIFICATION_DIALOG( 10000 + 1171 ): | |||
1213 | { | |||
1214 | auto xDialog = std::make_shared<svx::ClassificationDialog>(GetView()->GetFrameWeld(), false); | |||
1215 | ||||
1216 | SwWrtShell* pShell = GetWrtShell(); | |||
1217 | std::vector<svx::ClassificationResult> aInput = pShell->CollectAdvancedClassification(); | |||
1218 | xDialog->setupValues(aInput); | |||
1219 | ||||
1220 | weld::DialogController::runAsync(xDialog, [xDialog, pShell](sal_Int32 nResult){ | |||
1221 | if (RET_OK == nResult) | |||
1222 | pShell->ApplyAdvancedClassification(xDialog->getResult()); | |||
1223 | }); | |||
1224 | } | |||
1225 | break; | |||
1226 | case SID_PARAGRAPH_SIGN_CLASSIFY_DLG( 10000 + 1170 ): | |||
1227 | { | |||
1228 | SwWrtShell* pShell = GetWrtShell(); | |||
1229 | auto xDialog = std::make_shared<svx::ClassificationDialog>(GetView()->GetFrameWeld(), true, [pShell]() | |||
1230 | { | |||
1231 | pShell->SignParagraph(); | |||
1232 | }); | |||
1233 | ||||
1234 | std::vector<svx::ClassificationResult> aInput = pShell->CollectParagraphClassification(); | |||
1235 | xDialog->setupValues(aInput); | |||
1236 | ||||
1237 | weld::DialogController::runAsync(xDialog, [xDialog, pShell](sal_Int32 nResult){ | |||
1238 | if (RET_OK == nResult) | |||
1239 | pShell->ApplyParagraphClassification(xDialog->getResult()); | |||
1240 | }); | |||
1241 | } | |||
1242 | break; | |||
1243 | case SID_WATERMARK(5000 + 676): | |||
1244 | { | |||
1245 | SwWrtShell* pSh = GetWrtShell(); | |||
1246 | if ( pSh ) | |||
1247 | { | |||
1248 | if (pArgs && pArgs->GetItemState( SID_WATERMARK(5000 + 676), false, &pItem ) == SfxItemState::SET) | |||
1249 | { | |||
1250 | SfxWatermarkItem aItem; | |||
1251 | aItem.SetText( static_cast<const SfxStringItem*>( pItem )->GetValue() ); | |||
1252 | ||||
1253 | if ( pArgs->GetItemState( SID_WATERMARK_FONT(5000 + 677), false, &pItem ) == SfxItemState::SET ) | |||
1254 | aItem.SetFont( static_cast<const SfxStringItem*>( pItem )->GetValue() ); | |||
1255 | if ( pArgs->GetItemState( SID_WATERMARK_ANGLE(5000 + 807), false, &pItem ) == SfxItemState::SET ) | |||
1256 | aItem.SetAngle( static_cast<const SfxInt16Item*>( pItem )->GetValue() ); | |||
1257 | if ( pArgs->GetItemState( SID_WATERMARK_TRANSPARENCY(5000 + 805), false, &pItem ) == SfxItemState::SET ) | |||
1258 | aItem.SetTransparency( static_cast<const SfxInt16Item*>( pItem )->GetValue() ); | |||
1259 | if ( pArgs->GetItemState( SID_WATERMARK_COLOR(5000 + 806), false, &pItem ) == SfxItemState::SET ) | |||
1260 | aItem.SetColor( Color(static_cast<const SfxUInt32Item*>( pItem )->GetValue()) ); | |||
1261 | ||||
1262 | pSh->SetWatermark( aItem ); | |||
1263 | } | |||
1264 | else | |||
1265 | { | |||
1266 | SfxViewShell* pViewShell = GetView() ? GetView() : SfxViewShell::Current(); | |||
1267 | SfxBindings& rBindings( pViewShell->GetViewFrame()->GetBindings() ); | |||
1268 | auto xDlg = std::make_shared<SwWatermarkDialog>(pViewShell->GetViewFrame()->GetWindow().GetFrameWeld(), | |||
1269 | rBindings); | |||
1270 | weld::DialogController::runAsync(xDlg, [](sal_Int32 /*nResult*/){}); | |||
1271 | } | |||
1272 | } | |||
1273 | } | |||
1274 | break; | |||
1275 | case SID_NOTEBOOKBAR(10000 + 338): | |||
1276 | { | |||
1277 | const SfxStringItem* pFile = rReq.GetArg<SfxStringItem>( SID_NOTEBOOKBAR(10000 + 338) ); | |||
1278 | SfxViewShell* pViewShell = GetView()? GetView(): SfxViewShell::Current(); | |||
1279 | SfxBindings& rBindings( pViewShell->GetViewFrame()->GetBindings() ); | |||
1280 | ||||
1281 | if ( SfxNotebookBar::IsActive() ) | |||
1282 | sfx2::SfxNotebookBar::ExecMethod( rBindings, pFile ? pFile->GetValue() : "" ); | |||
1283 | else | |||
1284 | { | |||
1285 | sfx2::SfxNotebookBar::CloseMethod( rBindings ); | |||
1286 | } | |||
1287 | } | |||
1288 | break; | |||
1289 | case FN_REDLINE_ACCEPT_ALL((20000 + 1800) + 43): | |||
1290 | case FN_REDLINE_REJECT_ALL((20000 + 1800) + 44): | |||
1291 | { | |||
1292 | IDocumentRedlineAccess& rRedlineAccess = GetDoc()->getIDocumentRedlineAccess(); | |||
1293 | SwWrtShell *pWrtShell = dynamic_cast<SwWrtShell*>(GetDoc()->getIDocumentLayoutAccess().GetCurrentViewShell()); | |||
1294 | ||||
1295 | if (rRedlineAccess.GetRedlineTable().empty()) | |||
1296 | { | |||
1297 | break; | |||
1298 | } | |||
1299 | ||||
1300 | if (pWrtShell) | |||
1301 | { | |||
1302 | pWrtShell->StartAllAction(); | |||
1303 | } | |||
1304 | ||||
1305 | rRedlineAccess.AcceptAllRedline(nWhich == FN_REDLINE_ACCEPT_ALL((20000 + 1800) + 43)); | |||
1306 | ||||
1307 | if (pWrtShell) | |||
1308 | { | |||
1309 | pWrtShell->EndAllAction(); | |||
1310 | } | |||
1311 | ||||
1312 | Broadcast(SfxHint(SfxHintId::RedlineChanged)); | |||
1313 | rReq.Done(); | |||
1314 | } | |||
1315 | break; | |||
1316 | ||||
1317 | default: OSL_FAIL("wrong Dispatcher")do { if (true && (((sal_Bool)1))) { sal_detail_logFormat ((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.osl"), ("/home/maarten/src/libreoffice/core/sw/source/uibase/app/docsh2.cxx" ":" "1317" ": "), "%s", "wrong Dispatcher"); } } while (false ); | |||
1318 | } | |||
1319 | } | |||
1320 | ||||
1321 | #if defined(_WIN32) | |||
1322 | bool SwDocShell::DdeGetData( const OUString& rItem, const OUString& rMimeType, | |||
1323 | uno::Any & rValue ) | |||
1324 | { | |||
1325 | return m_xDoc->getIDocumentLinksAdministration().GetData( rItem, rMimeType, rValue ); | |||
1326 | } | |||
1327 | ||||
1328 | bool SwDocShell::DdeSetData( const OUString& rItem, const OUString& /*rMimeType*/, | |||
1329 | const uno::Any & /*rValue*/ ) | |||
1330 | { | |||
1331 | m_xDoc->getIDocumentLinksAdministration().SetData( rItem ); | |||
1332 | return false; | |||
1333 | } | |||
1334 | ||||
1335 | #endif | |||
1336 | ||||
1337 | ::sfx2::SvLinkSource* SwDocShell::DdeCreateLinkSource( const OUString& rItem ) | |||
1338 | { | |||
1339 | return m_xDoc->getIDocumentLinksAdministration().CreateLinkSource( rItem ); | |||
1340 | } | |||
1341 | ||||
1342 | void SwDocShell::ReconnectDdeLink(SfxObjectShell& rServer) | |||
1343 | { | |||
1344 | if (m_xDoc) | |||
1345 | { | |||
1346 | ::sfx2::LinkManager& rLinkManager = m_xDoc->getIDocumentLinksAdministration().GetLinkManager(); | |||
1347 | rLinkManager.ReconnectDdeLink(rServer); | |||
1348 | } | |||
1349 | } | |||
1350 | ||||
1351 | void SwDocShell::FillClass( SvGlobalName * pClassName, | |||
1352 | SotClipboardFormatId * pClipFormat, | |||
1353 | OUString * pLongUserName, | |||
1354 | sal_Int32 nVersion, | |||
1355 | bool bTemplate /* = false */) const | |||
1356 | { | |||
1357 | if (nVersion == SOFFICE_FILEFORMAT_606200) | |||
1358 | { | |||
1359 | *pClassName = SvGlobalName( SO3_SW_CLASSID_600x8BC6B165, 0xB1B2, 0x4EDD, 0xAA, 0x47, 0xDA, 0xE2, 0xEE, 0x68 , 0x9D, 0xD6 ); | |||
1360 | *pClipFormat = SotClipboardFormatId::STARWRITER_60; | |||
1361 | *pLongUserName = SwResId(STR_WRITER_DOCUMENT_FULLTYPEreinterpret_cast<char const *>("STR_WRITER_DOCUMENT_FULLTYPE" "\004" u8"%PRODUCTNAME %PRODUCTVERSION Text Document")); | |||
1362 | } | |||
1363 | else if (nVersion == SOFFICE_FILEFORMAT_86800) | |||
1364 | { | |||
1365 | *pClassName = SvGlobalName( SO3_SW_CLASSID_600x8BC6B165, 0xB1B2, 0x4EDD, 0xAA, 0x47, 0xDA, 0xE2, 0xEE, 0x68 , 0x9D, 0xD6 ); | |||
1366 | *pClipFormat = bTemplate ? SotClipboardFormatId::STARWRITER_8_TEMPLATE : SotClipboardFormatId::STARWRITER_8; | |||
1367 | *pLongUserName = SwResId(STR_WRITER_DOCUMENT_FULLTYPEreinterpret_cast<char const *>("STR_WRITER_DOCUMENT_FULLTYPE" "\004" u8"%PRODUCTNAME %PRODUCTVERSION Text Document")); | |||
1368 | } | |||
1369 | // #FIXME check with new Event handling | |||
1370 | #if 0 | |||
1371 | uno::Reference< document::XVbaEventsHelper > xVbaEventsHelper = m_xDoc->GetVbaEventsHelper(); | |||
1372 | if( xVbaEventsHelper.is() ) | |||
1373 | lcl_processCompatibleSfxHint( xVbaEventsHelper, rHint ); | |||
1374 | #endif | |||
1375 | } | |||
1376 | ||||
1377 | void SwDocShell::SetModified( bool bSet ) | |||
1378 | { | |||
1379 | if (utl::ConfigManager::IsFuzzing()) | |||
1380 | return; | |||
1381 | SfxObjectShell::SetModified( bSet ); | |||
1382 | if( !IsEnableSetModified()) | |||
1383 | return; | |||
1384 | ||||
1385 | if (!m_xDoc->getIDocumentState().IsInCallModified()) | |||
1386 | { | |||
1387 | EnableSetModified( false ); | |||
1388 | if( bSet ) | |||
1389 | { | |||
1390 | bool const bOld = m_xDoc->getIDocumentState().IsModified(); | |||
1391 | m_xDoc->getIDocumentState().SetModified(); | |||
1392 | if( !bOld ) | |||
1393 | { | |||
1394 | m_xDoc->GetIDocumentUndoRedo().SetUndoNoResetModified(); | |||
1395 | } | |||
1396 | } | |||
1397 | else | |||
1398 | m_xDoc->getIDocumentState().ResetModified(); | |||
1399 | ||||
1400 | EnableSetModified(); | |||
1401 | } | |||
1402 | ||||
1403 | UpdateChildWindows(); | |||
1404 | Broadcast(SfxHint(SfxHintId::DocChanged)); | |||
1405 | } | |||
1406 | ||||
1407 | void SwDocShell::UpdateChildWindows() | |||
1408 | { | |||
1409 | // if necessary newly initialize Fielddlg (i.e. for TYP_SETVAR) | |||
1410 | if(!GetView()) | |||
1411 | return; | |||
1412 | SfxViewFrame* pVFrame = GetView()->GetViewFrame(); | |||
1413 | SwFieldDlgWrapper *pWrp = static_cast<SwFieldDlgWrapper*>(pVFrame-> | |||
1414 | GetChildWindow( SwFieldDlgWrapper::GetChildWindowId() )); | |||
1415 | if( pWrp ) | |||
1416 | pWrp->ReInitDlg( this ); | |||
1417 | ||||
1418 | // if necessary newly initialize RedlineDlg | |||
1419 | SwRedlineAcceptChild *pRed = static_cast<SwRedlineAcceptChild*>(pVFrame-> | |||
1420 | GetChildWindow( SwRedlineAcceptChild::GetChildWindowId() )); | |||
1421 | if( pRed ) | |||
1422 | pRed->ReInitDlg( this ); | |||
1423 | } | |||
1424 | ||||
1425 | namespace { | |||
1426 | ||||
1427 | // #i48748# | |||
1428 | class SwReloadFromHtmlReader : public SwReader | |||
1429 | { | |||
1430 | public: | |||
1431 | SwReloadFromHtmlReader( SfxMedium& _rTmpMedium, | |||
1432 | const OUString& _rFilename, | |||
1433 | SwDoc* _pDoc ) | |||
1434 | : SwReader( _rTmpMedium, _rFilename, _pDoc ) | |||
1435 | { | |||
1436 | SetBaseURL( _rFilename ); | |||
1437 | } | |||
1438 | }; | |||
1439 | ||||
1440 | } | |||
1441 | ||||
1442 | void SwDocShell::ReloadFromHtml( const OUString& rStreamName, SwSrcView* pSrcView ) | |||
1443 | { | |||
1444 | bool bModified = IsModified(); | |||
1445 | ||||
1446 | // The HTTP-Header fields have to be removed, otherwise | |||
1447 | // there are some from Meta-Tags duplicated or triplicated afterwards. | |||
1448 | ClearHeaderAttributesForSourceViewHack(); | |||
1449 | ||||
1450 | #if HAVE_FEATURE_SCRIPTING1 | |||
1451 | // The Document-Basic also bites the dust ... | |||
1452 | // A EnterBasicCall is not needed here, because nothing is called and | |||
1453 | // there can't be any Dok-Basic, that has not yet been loaded inside | |||
1454 | // of an HTML document. | |||
1455 | SvxHtmlOptions& rHtmlOptions = SvxHtmlOptions::Get(); | |||
1456 | //#59620# HasBasic() shows, that there already is a BasicManager at the DocShell. | |||
1457 | // That was always generated in HTML-Import, when there are | |||
1458 | // Macros in the source code. | |||
1459 | if( rHtmlOptions.IsStarBasic() && HasBasic()) | |||
1460 | { | |||
1461 | BasicManager *pBasicMan = GetBasicManager(); | |||
1462 | if( pBasicMan && (pBasicMan != SfxApplication::GetBasicManager()) ) | |||
1463 | { | |||
1464 | sal_uInt16 nLibCount = pBasicMan->GetLibCount(); | |||
1465 | while( nLibCount ) | |||
1466 | { | |||
1467 | StarBASIC *pBasic = pBasicMan->GetLib( --nLibCount ); | |||
1468 | if( pBasic ) | |||
1469 | { | |||
1470 | // Notify the IDE | |||
1471 | SfxUnoAnyItem aShellItem( SID_BASICIDE_ARG_DOCUMENT_MODELTypedWhichId<SfxUnoAnyItem>( (30000 + 768) + 51 ), makeAny( GetModel() ) ); | |||
1472 | OUString aLibName( pBasic->GetName() ); | |||
1473 | SfxStringItem aLibNameItem( SID_BASICIDE_ARG_LIBNAMETypedWhichId<SfxStringItem>( (30000 + 768) + 34 ), aLibName ); | |||
1474 | pSrcView->GetViewFrame()->GetDispatcher()->ExecuteList( | |||
1475 | SID_BASICIDE_LIBREMOVED( (30000 + 768) + 28 ), | |||
1476 | SfxCallMode::SYNCHRON, | |||
1477 | { &aShellItem, &aLibNameItem }); | |||
1478 | ||||
1479 | // Only the modules are deleted from the standard-lib | |||
1480 | if( nLibCount ) | |||
1481 | pBasicMan->RemoveLib( nLibCount, true ); | |||
1482 | else | |||
1483 | pBasic->Clear(); | |||
1484 | } | |||
1485 | } | |||
1486 | ||||
1487 | OSL_ENSURE( pBasicMan->GetLibCount() <= 1,do { if (true && (!(pBasicMan->GetLibCount() <= 1))) { sal_detail_logFormat((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.osl" ), ("/home/maarten/src/libreoffice/core/sw/source/uibase/app/docsh2.cxx" ":" "1488" ": "), "%s", "Deleting Basics didn't work"); } } while (false) | |||
1488 | "Deleting Basics didn't work" )do { if (true && (!(pBasicMan->GetLibCount() <= 1))) { sal_detail_logFormat((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.osl" ), ("/home/maarten/src/libreoffice/core/sw/source/uibase/app/docsh2.cxx" ":" "1488" ": "), "%s", "Deleting Basics didn't work"); } } while (false); | |||
1489 | } | |||
1490 | } | |||
1491 | #endif | |||
1492 | bool bWasBrowseMode = m_xDoc->getIDocumentSettingAccess().get(DocumentSettingId::BROWSE_MODE); | |||
1493 | RemoveLink(); | |||
1494 | ||||
1495 | // now also the UNO-Model has to be informed about the new Doc #51535# | |||
1496 | uno::Reference<text::XTextDocument> xDoc(GetBaseModel(), uno::UNO_QUERY); | |||
1497 | text::XTextDocument* pxDoc = xDoc.get(); | |||
1498 | static_cast<SwXTextDocument*>(pxDoc)->InitNewDoc(); | |||
1499 | ||||
1500 | AddLink(); | |||
1501 | //#116402# update font list when new document is created | |||
1502 | UpdateFontList(); | |||
1503 | m_xDoc->getIDocumentSettingAccess().set(DocumentSettingId::BROWSE_MODE, bWasBrowseMode); | |||
1504 | pSrcView->SetPool(&GetPool()); | |||
1505 | ||||
1506 | const OUString& rMedname = GetMedium()->GetName(); | |||
1507 | ||||
1508 | // The HTML template still has to be set | |||
1509 | SetHTMLTemplate( *GetDoc() ); //Styles from HTML.vor | |||
1510 | ||||
1511 | SfxViewShell* pViewShell = GetView() ? static_cast<SfxViewShell*>(GetView()) | |||
1512 | : SfxViewShell::Current(); | |||
1513 | SfxViewFrame* pViewFrame = pViewShell->GetViewFrame(); | |||
1514 | pViewFrame->GetDispatcher()->Execute( SID_VIEWSHELL0(5000 + 630), SfxCallMode::SYNCHRON ); | |||
1515 | ||||
1516 | SubInitNew(); | |||
1517 | ||||
1518 | SfxMedium aMed( rStreamName, StreamMode::READ ); | |||
1519 | // #i48748# - use class <SwReloadFromHtmlReader>, because | |||
1520 | // the base URL has to be set to the filename of the document <rMedname> | |||
1521 | // and not to the base URL of the temporary file <aMed> in order to get | |||
1522 | // the URLs of the linked graphics correctly resolved. | |||
1523 | SwReloadFromHtmlReader aReader( aMed, rMedname, m_xDoc.get() ); | |||
1524 | ||||
1525 | aReader.Read( *ReadHTML ); | |||
1526 | ||||
1527 | const SwView* pCurrView = GetView(); | |||
1528 | //in print layout the first page(s) may have been formatted as a mix of browse | |||
1529 | //and print layout | |||
1530 | if(!bWasBrowseMode && pCurrView) | |||
1531 | { | |||
1532 | SwWrtShell& rWrtSh = pCurrView->GetWrtShell(); | |||
1533 | if( rWrtSh.GetLayout()) | |||
1534 | rWrtSh.InvalidateLayout( true ); | |||
1535 | } | |||
1536 | ||||
1537 | // Take HTTP-Header-Attributes over into the DocInfo again. | |||
1538 | // The Base-URL doesn't matter here because TLX uses the one from the document | |||
1539 | // for absolutization. | |||
1540 | SetHeaderAttributesForSourceViewHack(); | |||
1541 | ||||
1542 | if(bModified && !IsReadOnly()) | |||
1543 | SetModified(); | |||
1544 | else | |||
1545 | m_xDoc->getIDocumentState().ResetModified(); | |||
1546 | } | |||
1547 | ||||
1548 | ErrCode SwDocShell::LoadStylesFromFile(const OUString& rURL, SwgReaderOption& rOpt, bool bUnoCall) | |||
1549 | { | |||
1550 | ErrCode nErr = ERRCODE_NONEErrCode(0); | |||
1551 | ||||
1552 | // Set filter: | |||
1553 | SfxFilterMatcher aMatcher( SwDocShell::Factory().GetFactoryName() ); | |||
1554 | ||||
1555 | // search for filter in WebDocShell, too | |||
1556 | SfxMedium aMed( rURL, StreamMode::STD_READ ); | |||
1557 | if (rURL == "private:stream") | |||
1558 | aMed.setStreamToLoadFrom(rOpt.GetInputStream(), true); | |||
1559 | std::shared_ptr<const SfxFilter> pFlt; | |||
1560 | aMatcher.DetectFilter( aMed, pFlt ); | |||
1561 | if(!pFlt) | |||
1562 | { | |||
1563 | SfxFilterMatcher aWebMatcher( SwWebDocShell::Factory().GetFactoryName() ); | |||
1564 | aWebMatcher.DetectFilter( aMed, pFlt ); | |||
1565 | } | |||
1566 | // --> OD #i117339# - trigger import only for own formats | |||
1567 | bool bImport( false ); | |||
1568 | if ( aMed.IsStorage() ) | |||
1569 | { | |||
1570 | // As <SfxMedium.GetFilter().IsOwnFormat() resp. IsOwnTemplateFormat() | |||
1571 | // does not work correct (e.g., MS Word 2007 XML Template), | |||
1572 | // use workaround provided by MAV. | |||
1573 | uno::Reference< embed::XStorage > xStorage = aMed.GetStorage(); | |||
1574 | if ( xStorage.is() ) | |||
1575 | { | |||
1576 | // use <try-catch> on retrieving <MediaType> in order to check, | |||
1577 | // if the storage is one of our own ones. | |||
1578 | try | |||
1579 | { | |||
1580 | uno::Reference< beans::XPropertySet > xProps( xStorage, uno::UNO_QUERY_THROW ); | |||
1581 | xProps->getPropertyValue( "MediaType" ); | |||
1582 | bImport = true; | |||
1583 | } | |||
1584 | catch (const uno::Exception&) | |||
1585 | { | |||
1586 | bImport = false; | |||
1587 | } | |||
1588 | } | |||
1589 | } | |||
1590 | if ( bImport ) | |||
1591 | { | |||
1592 | Reader* pRead = ReadXML; | |||
1593 | SwReaderPtr pReader; | |||
1594 | std::unique_ptr<SwPaM> pPam; | |||
1595 | // the SW3IO - Reader need the pam/wrtshell, because only then he | |||
1596 | // insert the styles! | |||
1597 | if( bUnoCall ) | |||
1598 | { | |||
1599 | SwNodeIndex aIdx( m_xDoc->GetNodes().GetEndOfContent(), -1 ); | |||
1600 | pPam.reset(new SwPaM( aIdx )); | |||
1601 | pReader.reset(new SwReader( aMed, rURL, *pPam )); | |||
1602 | } | |||
1603 | else | |||
1604 | { | |||
1605 | pReader.reset(new SwReader( aMed, rURL, *m_pWrtShell->GetCursor() )); | |||
1606 | } | |||
1607 | ||||
1608 | pRead->GetReaderOpt().SetTextFormats( rOpt.IsTextFormats() ); | |||
1609 | pRead->GetReaderOpt().SetFrameFormats( rOpt.IsFrameFormats() ); | |||
1610 | pRead->GetReaderOpt().SetPageDescs( rOpt.IsPageDescs() ); | |||
1611 | pRead->GetReaderOpt().SetNumRules( rOpt.IsNumRules() ); | |||
1612 | pRead->GetReaderOpt().SetMerge( rOpt.IsMerge() ); | |||
1613 | ||||
1614 | if( bUnoCall ) | |||
1615 | { | |||
1616 | UnoActionContext aAction( m_xDoc.get() ); | |||
1617 | nErr = pReader->Read( *pRead ); | |||
1618 | } | |||
1619 | else | |||
1620 | { | |||
1621 | m_pWrtShell->StartAllAction(); | |||
1622 | nErr = pReader->Read( *pRead ); | |||
1623 | m_pWrtShell->EndAllAction(); | |||
1624 | } | |||
1625 | } | |||
1626 | ||||
1627 | return nErr; | |||
1628 | } | |||
1629 | ||||
1630 | // Get a client for an embedded object if possible. | |||
1631 | SfxInPlaceClient* SwDocShell::GetIPClient( const ::svt::EmbeddedObjectRef& xObjRef ) | |||
1632 | { | |||
1633 | SfxInPlaceClient* pResult = nullptr; | |||
1634 | ||||
1635 | SwWrtShell* pShell = GetWrtShell(); | |||
1636 | if ( pShell ) | |||
1637 | { | |||
1638 | pResult = pShell->GetView().FindIPClient( xObjRef.GetObject(), &pShell->GetView().GetEditWin() ); | |||
1639 | if ( !pResult ) | |||
1640 | pResult = new SwOleClient( &pShell->GetView(), &pShell->GetView().GetEditWin(), xObjRef ); | |||
1641 | } | |||
1642 | ||||
1643 | return pResult; | |||
1644 | } | |||
1645 | ||||
1646 | int SwFindDocShell( SfxObjectShellRef& xDocSh, | |||
1647 | SfxObjectShellLock& xLockRef, | |||
1648 | const OUString& rFileName, | |||
1649 | const OUString& rPasswd, | |||
1650 | const OUString& rFilter, | |||
1651 | sal_Int16 nVersion, | |||
1652 | SwDocShell* pDestSh ) | |||
1653 | { | |||
1654 | if ( rFileName.isEmpty() ) | |||
1655 | return 0; | |||
1656 | ||||
1657 | // 1. Does the file already exist in the list of all Documents? | |||
1658 | INetURLObject aTmpObj( rFileName ); | |||
1659 | aTmpObj.SetMark( OUString() ); | |||
1660 | ||||
1661 | // Iterate over the DocShell and get the ones with the name | |||
1662 | ||||
1663 | SfxObjectShell* pShell = pDestSh; | |||
1664 | bool bFirst = nullptr != pShell; | |||
1665 | ||||
1666 | if( !bFirst ) | |||
1667 | // No DocShell passed, starting with the first from the DocShell list | |||
1668 | pShell = SfxObjectShell::GetFirst( checkSfxObjectShell<SwDocShell> ); | |||
1669 | ||||
1670 | while( pShell ) | |||
1671 | { | |||
1672 | // We want this one | |||
1673 | SfxMedium* pMed = pShell->GetMedium(); | |||
1674 | if( pMed && pMed->GetURLObject() == aTmpObj ) | |||
1675 | { | |||
1676 | const SfxPoolItem* pItem; | |||
1677 | if( ( SfxItemState::SET == pMed->GetItemSet()->GetItemState( | |||
1678 | SID_VERSION(5000 + 1583), false, &pItem ) ) | |||
1679 | ? (nVersion == static_cast<const SfxInt16Item*>(pItem)->GetValue()) | |||
1680 | : !nVersion ) | |||
1681 | { | |||
1682 | // Found, thus return | |||
1683 | xDocSh = pShell; | |||
1684 | return 1; | |||
1685 | } | |||
1686 | } | |||
1687 | ||||
1688 | if( bFirst ) | |||
1689 | { | |||
1690 | bFirst = false; | |||
1691 | pShell = SfxObjectShell::GetFirst( checkSfxObjectShell<SwDocShell> ); | |||
1692 | } | |||
1693 | else | |||
1694 | pShell = SfxObjectShell::GetNext( *pShell, checkSfxObjectShell<SwDocShell> ); | |||
1695 | } | |||
1696 | ||||
1697 | // 2. Open the file ourselves | |||
1698 | std::unique_ptr<SfxMedium> xMed(new SfxMedium( aTmpObj.GetMainURL( | |||
1699 | INetURLObject::DecodeMechanism::NONE ), StreamMode::READ )); | |||
1700 | if( INetProtocol::File == aTmpObj.GetProtocol() ) | |||
1701 | xMed->Download(); // Touch the medium (download it) | |||
1702 | ||||
1703 | std::shared_ptr<const SfxFilter> pSfxFlt; | |||
1704 | if (!xMed->GetError()) | |||
1705 | { | |||
1706 | SfxFilterMatcher aMatcher( rFilter == "writerglobal8" | |||
1707 | ? SwGlobalDocShell::Factory().GetFactoryName() | |||
1708 | : SwDocShell::Factory().GetFactoryName() ); | |||
1709 | ||||
1710 | // No Filter, so search for it. Else test if the one passed is a valid one | |||
1711 | if( !rFilter.isEmpty() ) | |||
1712 | { | |||
1713 | pSfxFlt = aMatcher.GetFilter4FilterName( rFilter ); | |||
1714 | } | |||
1715 | ||||
1716 | if( nVersion ) | |||
1717 | xMed->GetItemSet()->Put( SfxInt16Item( SID_VERSION(5000 + 1583), nVersion )); | |||
1718 | ||||
1719 | if( !rPasswd.isEmpty() ) | |||
1720 | xMed->GetItemSet()->Put( SfxStringItem( SID_PASSWORD(((((10000 + 1499) + 1) + 499) + 1) + 36), rPasswd )); | |||
1721 | ||||
1722 | if( !pSfxFlt ) | |||
1723 | aMatcher.DetectFilter( *xMed, pSfxFlt ); | |||
1724 | ||||
1725 | if( pSfxFlt ) | |||
1726 | { | |||
1727 | // We cannot do anything without a Filter | |||
1728 | xMed->SetFilter( pSfxFlt ); | |||
1729 | ||||
1730 | // If the new shell is created, SfxObjectShellLock should be used to let it be closed later for sure | |||
1731 | SwDocShell *const pNew(new SwDocShell(SfxObjectCreateMode::INTERNAL)); | |||
1732 | xLockRef = pNew; | |||
1733 | xDocSh = static_cast<SfxObjectShell*>(xLockRef); | |||
1734 | if (xDocSh->DoLoad(xMed.release())) | |||
1735 | { | |||
1736 | return 2; | |||
1737 | } | |||
1738 | } | |||
1739 | } | |||
1740 | ||||
1741 | return 0; | |||
1742 | } | |||
1743 | ||||
1744 | /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |
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 | #ifndef INCLUDED_VCL_PTR_HXX |
21 | #define INCLUDED_VCL_PTR_HXX |
22 | |
23 | #include <sal/config.h> |
24 | |
25 | #include <rtl/ref.hxx> |
26 | |
27 | #include <utility> |
28 | #include <type_traits> |
29 | |
30 | #ifdef DBG_UTIL |
31 | #ifndef _WIN32 |
32 | #include <vcl/vclmain.hxx> |
33 | #endif |
34 | #endif |
35 | |
36 | class VclReferenceBase; |
37 | |
38 | namespace vcl::detail { |
39 | |
40 | template<typename> |
41 | constexpr bool isIncompleteOrDerivedFromVclReferenceBase(...) { return true; } |
42 | |
43 | template<typename T> constexpr bool isIncompleteOrDerivedFromVclReferenceBase( |
44 | int (*)[sizeof(T)]) |
45 | { return std::is_base_of<VclReferenceBase, T>::value; } |
46 | |
47 | } // namespace vcl::detail |
48 | |
49 | /** |
50 | * A thin wrapper around rtl::Reference to implement the acquire and dispose semantics we want for references to vcl::Window subclasses. |
51 | * |
52 | * For more details on the design please see vcl/README.lifecycle |
53 | * |
54 | * @param reference_type must be a subclass of vcl::Window |
55 | */ |
56 | template <class reference_type> |
57 | class VclPtr |
58 | { |
59 | static_assert( |
60 | vcl::detail::isIncompleteOrDerivedFromVclReferenceBase<reference_type>( |
61 | nullptr), |
62 | "template argument type must be derived from VclReferenceBase"); |
63 | |
64 | ::rtl::Reference<reference_type> m_rInnerRef; |
65 | |
66 | public: |
67 | /** Constructor... |
68 | */ |
69 | VclPtr() |
70 | : m_rInnerRef() |
71 | {} |
72 | |
73 | /** Constructor... |
74 | */ |
75 | VclPtr (reference_type * pBody) |
76 | : m_rInnerRef(pBody) |
77 | {} |
78 | |
79 | /** Constructor... that doesn't take a ref. |
80 | */ |
81 | VclPtr (reference_type * pBody, __sal_NoAcquire) |
82 | : m_rInnerRef(pBody, SAL_NO_ACQUIRE) |
83 | {} |
84 | |
85 | /** Up-casting conversion constructor: Copies interface reference. |
86 | |
87 | Does not work for up-casts to ambiguous bases. For the special case of |
88 | up-casting to Reference< XInterface >, see the corresponding conversion |
89 | operator. |
90 | |
91 | @param rRef another reference |
92 | */ |
93 | template< class derived_type > |
94 | VclPtr( |
95 | const VclPtr< derived_type > & rRef, |
96 | typename std::enable_if< |
97 | std::is_base_of<reference_type, derived_type>::value, int>::type |
98 | = 0 ) |
99 | : m_rInnerRef( static_cast<reference_type*>(rRef) ) |
100 | { |
101 | } |
102 | |
103 | #if defined(DBG_UTIL) && !defined(_WIN32) |
104 | virtual ~VclPtr() |
105 | { |
106 | assert(m_rInnerRef.get() == nullptr || vclmain::isAlive())(static_cast <bool> (m_rInnerRef.get() == nullptr || vclmain ::isAlive()) ? void (0) : __assert_fail ("m_rInnerRef.get() == nullptr || vclmain::isAlive()" , "/home/maarten/src/libreoffice/core/include/vcl/vclptr.hxx" , 106, __extension__ __PRETTY_FUNCTION__)); |
107 | // We can be one of the intermediate counts, but if we are the last |
108 | // VclPtr keeping this object alive, then something forgot to call dispose(). |
109 | assert((!m_rInnerRef.get() || m_rInnerRef->isDisposed() || m_rInnerRef->getRefCount() > 1)(static_cast <bool> ((!m_rInnerRef.get() || m_rInnerRef ->isDisposed() || m_rInnerRef->getRefCount() > 1) && "someone forgot to call dispose()") ? void (0) : __assert_fail ("(!m_rInnerRef.get() || m_rInnerRef->isDisposed() || m_rInnerRef->getRefCount() > 1) && \"someone forgot to call dispose()\"" , "/home/maarten/src/libreoffice/core/include/vcl/vclptr.hxx" , 110, __extension__ __PRETTY_FUNCTION__)) |
110 | && "someone forgot to call dispose()")(static_cast <bool> ((!m_rInnerRef.get() || m_rInnerRef ->isDisposed() || m_rInnerRef->getRefCount() > 1) && "someone forgot to call dispose()") ? void (0) : __assert_fail ("(!m_rInnerRef.get() || m_rInnerRef->isDisposed() || m_rInnerRef->getRefCount() > 1) && \"someone forgot to call dispose()\"" , "/home/maarten/src/libreoffice/core/include/vcl/vclptr.hxx" , 110, __extension__ __PRETTY_FUNCTION__)); |
111 | } |
112 | VclPtr(VclPtr const &) = default; |
113 | VclPtr(VclPtr &&) = default; |
114 | VclPtr & operator =(VclPtr const &) = default; |
115 | VclPtr & operator =(VclPtr &&) = default; |
116 | #endif |
117 | |
118 | /** |
119 | * A construction helper for VclPtr. Since VclPtr types are created |
120 | * with a reference-count of one - to help fit into the existing |
121 | * code-flow; this helps us to construct them easily. |
122 | * |
123 | * For more details on the design please see vcl/README.lifecycle |
124 | * |
125 | * @tparam reference_type must be a subclass of vcl::Window |
126 | */ |
127 | template<typename... Arg> [[nodiscard]] static VclPtr< reference_type > Create(Arg &&... arg) |
128 | { |
129 | return VclPtr< reference_type >( new reference_type(std::forward<Arg>(arg)...), SAL_NO_ACQUIRE ); |
130 | } |
131 | |
132 | /** Probably most common used: handle->someBodyOp(). |
133 | */ |
134 | reference_type * operator->() const |
135 | { |
136 | return m_rInnerRef.get(); |
137 | } |
138 | |
139 | /** Get the body. Can be used instead of operator->(). |
140 | I.e. handle->someBodyOp() and handle.get()->someBodyOp() |
141 | are the same. |
142 | */ |
143 | reference_type * get() const |
144 | { |
145 | return m_rInnerRef.get(); |
146 | } |
147 | |
148 | void set(reference_type *pBody) |
149 | { |
150 | m_rInnerRef.set(pBody); |
151 | } |
152 | |
153 | void reset(reference_type *pBody) |
154 | { |
155 | m_rInnerRef.set(pBody); |
156 | } |
157 | |
158 | /** Up-casting copy assignment operator. |
159 | |
160 | Does not work for up-casts to ambiguous bases. |
161 | |
162 | @param rRef another reference |
163 | */ |
164 | template<typename derived_type> |
165 | typename std::enable_if< |
166 | std::is_base_of<reference_type, derived_type>::value, |
167 | VclPtr &>::type |
168 | operator =(VclPtr<derived_type> const & rRef) |
169 | { |
170 | m_rInnerRef.set(rRef.get()); |
171 | return *this; |
172 | } |
173 | |
174 | VclPtr & operator =(reference_type * pBody) |
175 | { |
176 | m_rInnerRef.set(pBody); |
177 | return *this; |
178 | } |
179 | |
180 | operator reference_type * () const |
181 | { |
182 | return m_rInnerRef.get(); |
183 | } |
184 | |
185 | explicit operator bool () const |
186 | { |
187 | return m_rInnerRef.get() != nullptr; |
188 | } |
189 | |
190 | void clear() |
191 | { |
192 | m_rInnerRef.clear(); |
193 | } |
194 | |
195 | void reset() |
196 | { |
197 | m_rInnerRef.clear(); |
198 | } |
199 | |
200 | void disposeAndClear() |
201 | { |
202 | // hold it alive for the lifetime of this method |
203 | ::rtl::Reference<reference_type> aTmp(m_rInnerRef); |
204 | m_rInnerRef.clear(); // we should use some 'swap' method ideally ;-) |
205 | if (aTmp.get()) { |
206 | aTmp->disposeOnce(); |
207 | } |
208 | } |
209 | |
210 | /** Needed to place VclPtr's into STL collection. |
211 | */ |
212 | bool operator< (const VclPtr<reference_type> & handle) const |
213 | { |
214 | return (m_rInnerRef < handle.m_rInnerRef); |
215 | } |
216 | }; // class VclPtr |
217 | |
218 | template<typename T1, typename T2> |
219 | inline bool operator ==(VclPtr<T1> const & p1, VclPtr<T2> const & p2) { |
220 | return p1.get() == p2.get(); |
221 | } |
222 | |
223 | template<typename T> inline bool operator ==(VclPtr<T> const & p1, T const * p2) |
224 | { |
225 | return p1.get() == p2; |
226 | } |
227 | |
228 | template<typename T> inline bool operator ==(VclPtr<T> const & p1, T * p2) { |
229 | return p1.get() == p2; |
230 | } |
231 | |
232 | template<typename T> inline bool operator ==(T const * p1, VclPtr<T> const & p2) |
233 | { |
234 | return p1 == p2.get(); |
235 | } |
236 | |
237 | template<typename T> inline bool operator ==(T * p1, VclPtr<T> const & p2) { |
238 | return p1 == p2.get(); |
239 | } |
240 | |
241 | template<typename T1, typename T2> |
242 | inline bool operator !=(VclPtr<T1> const & p1, VclPtr<T2> const & p2) { |
243 | return !(p1 == p2); |
244 | } |
245 | |
246 | template<typename T> inline bool operator !=(VclPtr<T> const & p1, T const * p2) |
247 | { |
248 | return !(p1 == p2); |
249 | } |
250 | |
251 | template<typename T> inline bool operator !=(VclPtr<T> const & p1, T * p2) { |
252 | return !(p1 == p2); |
253 | } |
254 | |
255 | template<typename T> inline bool operator !=(T const * p1, VclPtr<T> const & p2) |
256 | { |
257 | return !(p1 == p2); |
258 | } |
259 | |
260 | template<typename T> inline bool operator !=(T * p1, VclPtr<T> const & p2) { |
261 | return !(p1 == p2); |
262 | } |
263 | |
264 | /** |
265 | * A construction helper for a temporary VclPtr. Since VclPtr types |
266 | * are created with a reference-count of one - to help fit into |
267 | * the existing code-flow; this helps us to construct them easily. |
268 | * see also VclPtr::Create and ScopedVclPtr |
269 | * |
270 | * For more details on the design please see vcl/README.lifecycle |
271 | * |
272 | * @param reference_type must be a subclass of vcl::Window |
273 | */ |
274 | template <class reference_type> |
275 | class SAL_WARN_UNUSED__attribute__((warn_unused)) VclPtrInstance final : public VclPtr<reference_type> |
276 | { |
277 | public: |
278 | template<typename... Arg> VclPtrInstance(Arg &&... arg) |
279 | : VclPtr<reference_type>( new reference_type(std::forward<Arg>(arg)...), SAL_NO_ACQUIRE ) |
280 | { |
281 | } |
282 | |
283 | /** |
284 | * Override and disallow this, to prevent people accidentally calling it and actually |
285 | * getting VclPtr::Create and getting a naked VclPtr<> instance |
286 | */ |
287 | template<typename... Arg> static VclPtrInstance< reference_type > Create(Arg &&... ) = delete; |
288 | }; |
289 | |
290 | template <class reference_type> |
291 | class ScopedVclPtr : public VclPtr<reference_type> |
292 | { |
293 | public: |
294 | /** Constructor... |
295 | */ |
296 | ScopedVclPtr() |
297 | : VclPtr<reference_type>() |
298 | {} |
299 | |
300 | /** Constructor |
301 | */ |
302 | ScopedVclPtr (reference_type * pBody) |
303 | : VclPtr<reference_type>(pBody) |
304 | {} |
305 | |
306 | /** Copy constructor... |
307 | */ |
308 | ScopedVclPtr (const VclPtr<reference_type> & handle) |
309 | : VclPtr<reference_type>(handle) |
310 | {} |
311 | |
312 | /** |
313 | Assignment that releases the last reference. |
314 | */ |
315 | void disposeAndReset(reference_type *pBody) |
316 | { |
317 | if (pBody != this->get()) { |
318 | VclPtr<reference_type>::disposeAndClear(); |
319 | VclPtr<reference_type>::set(pBody); |
320 | } |
321 | } |
322 | |
323 | /** |
324 | Assignment that releases the last reference. |
325 | */ |
326 | ScopedVclPtr<reference_type>& operator = (reference_type * pBody) |
327 | { |
328 | disposeAndReset(pBody); |
329 | return *this; |
330 | } |
331 | |
332 | /** Up-casting conversion constructor: Copies interface reference. |
333 | |
334 | Does not work for up-casts to ambiguous bases. For the special case of |
335 | up-casting to Reference< XInterface >, see the corresponding conversion |
336 | operator. |
337 | |
338 | @param rRef another reference |
339 | */ |
340 | template< class derived_type > |
341 | ScopedVclPtr( |
342 | const VclPtr< derived_type > & rRef, |
343 | typename std::enable_if< |
344 | std::is_base_of<reference_type, derived_type>::value, int>::type |
345 | = 0 ) |
346 | : VclPtr<reference_type>( rRef ) |
347 | { |
348 | } |
349 | |
350 | /** Up-casting assignment operator. |
351 | |
352 | Does not work for up-casts to ambiguous bases. |
353 | |
354 | @param rRef another VclPtr |
355 | */ |
356 | template<typename derived_type> |
357 | typename std::enable_if< |
358 | std::is_base_of<reference_type, derived_type>::value, |
359 | ScopedVclPtr &>::type |
360 | operator =(VclPtr<derived_type> const & rRef) |
361 | { |
362 | disposeAndReset(rRef.get()); |
363 | return *this; |
364 | } |
365 | |
366 | /** |
367 | * Override and disallow this, to prevent people accidentally calling it and actually |
368 | * getting VclPtr::Create and getting a naked VclPtr<> instance |
369 | */ |
370 | template<typename... Arg> static ScopedVclPtr< reference_type > Create(Arg &&... ) = delete; |
371 | |
372 | ~ScopedVclPtr() |
373 | { |
374 | VclPtr<reference_type>::disposeAndClear(); |
375 | assert(VclPtr<reference_type>::get() == nullptr)(static_cast <bool> (VclPtr<reference_type>::get( ) == nullptr) ? void (0) : __assert_fail ("VclPtr<reference_type>::get() == nullptr" , "/home/maarten/src/libreoffice/core/include/vcl/vclptr.hxx" , 375, __extension__ __PRETTY_FUNCTION__)); // make sure there are no lingering references |
376 | } |
377 | |
378 | private: |
379 | // Most likely we don't want this default copy-constructor. |
380 | ScopedVclPtr (const ScopedVclPtr<reference_type> &) = delete; |
381 | // And certainly we don't want a default assignment operator. |
382 | ScopedVclPtr<reference_type>& operator = (const ScopedVclPtr<reference_type> &) = delete; |
383 | // And disallow reset as that doesn't call disposeAndClear on the original reference |
384 | void reset() = delete; |
385 | void reset(reference_type *pBody) = delete; |
386 | |
387 | protected: |
388 | ScopedVclPtr (reference_type * pBody, __sal_NoAcquire) |
389 | : VclPtr<reference_type>(pBody, SAL_NO_ACQUIRE) |
390 | {} |
391 | }; |
392 | |
393 | /** |
394 | * A construction helper for ScopedVclPtr. Since VclPtr types are created |
395 | * with a reference-count of one - to help fit into the existing |
396 | * code-flow; this helps us to construct them easily. |
397 | * |
398 | * For more details on the design please see vcl/README.lifecycle |
399 | * |
400 | * @param reference_type must be a subclass of vcl::Window |
401 | */ |
402 | #if defined _MSC_VER |
403 | #pragma warning(push) |
404 | #pragma warning(disable: 4521) // " multiple copy constructors specified" |
405 | #endif |
406 | template <class reference_type> |
407 | class SAL_WARN_UNUSED__attribute__((warn_unused)) ScopedVclPtrInstance final : public ScopedVclPtr<reference_type> |
408 | { |
409 | public: |
410 | template<typename... Arg> ScopedVclPtrInstance(Arg &&... arg) |
411 | : ScopedVclPtr<reference_type>( new reference_type(std::forward<Arg>(arg)...), SAL_NO_ACQUIRE ) |
412 | { |
413 | } |
414 | |
415 | /** |
416 | * Override and disallow this, to prevent people accidentally calling it and actually |
417 | * getting VclPtr::Create and getting a naked VclPtr<> instance |
418 | */ |
419 | template<typename... Arg> static ScopedVclPtrInstance< reference_type > Create(Arg &&...) = delete; |
420 | |
421 | private: |
422 | // Prevent the above perfect forwarding ctor from hijacking (accidental) |
423 | // attempts at ScopedVclPtrInstance copy construction (where the hijacking |
424 | // would typically lead to somewhat obscure error messages); both non-const |
425 | // and const variants are needed here, as the ScopedVclPtr base class has a |
426 | // const--variant copy ctor, so the implicitly declared copy ctor for |
427 | // ScopedVclPtrInstance would also be the const variant, so non-const copy |
428 | // construction attempts would be hijacked by the perfect forwarding ctor; |
429 | // but if we only declared a non-const variant here, the const variant would |
430 | // no longer be implicitly declared (as there would already be an explicitly |
431 | // declared copy ctor), so const copy construction attempts would then be |
432 | // hijacked by the perfect forwarding ctor: |
433 | ScopedVclPtrInstance(ScopedVclPtrInstance &) = delete; |
434 | ScopedVclPtrInstance(ScopedVclPtrInstance const &) = delete; |
435 | }; |
436 | #if defined _MSC_VER |
437 | #pragma warning(pop) |
438 | #endif |
439 | |
440 | #endif // INCLUDED_VCL_PTR_HXX |
441 | |
442 | /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |
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 | #ifndef INCLUDED_RTL_REF_HXX | ||||||||
21 | #define INCLUDED_RTL_REF_HXX | ||||||||
22 | |||||||||
23 | #include "sal/config.h" | ||||||||
24 | |||||||||
25 | #include <cassert> | ||||||||
26 | #include <cstddef> | ||||||||
27 | #include <functional> | ||||||||
28 | #ifdef LIBO_INTERNAL_ONLY1 | ||||||||
29 | #include <type_traits> | ||||||||
30 | #endif | ||||||||
31 | |||||||||
32 | #include "sal/types.h" | ||||||||
33 | |||||||||
34 | namespace rtl | ||||||||
35 | { | ||||||||
36 | |||||||||
37 | /** Template reference class for reference type. | ||||||||
38 | */ | ||||||||
39 | template <class reference_type> | ||||||||
40 | class Reference | ||||||||
41 | { | ||||||||
42 | /** The <b>reference_type</b> body pointer. | ||||||||
43 | */ | ||||||||
44 | reference_type * m_pBody; | ||||||||
45 | |||||||||
46 | |||||||||
47 | public: | ||||||||
48 | /** Constructor... | ||||||||
49 | */ | ||||||||
50 | Reference() | ||||||||
51 | : m_pBody (NULL__null) | ||||||||
52 | {} | ||||||||
53 | |||||||||
54 | |||||||||
55 | /** Constructor... | ||||||||
56 | */ | ||||||||
57 | Reference (reference_type * pBody, __sal_NoAcquire) | ||||||||
58 | : m_pBody (pBody) | ||||||||
59 | { | ||||||||
60 | } | ||||||||
61 | |||||||||
62 | /** Constructor... | ||||||||
63 | */ | ||||||||
64 | Reference (reference_type * pBody) | ||||||||
65 | : m_pBody (pBody) | ||||||||
66 | { | ||||||||
67 | if (m_pBody) | ||||||||
68 | m_pBody->acquire(); | ||||||||
69 | } | ||||||||
70 | |||||||||
71 | /** Copy constructor... | ||||||||
72 | */ | ||||||||
73 | Reference (const Reference<reference_type> & handle) | ||||||||
74 | : m_pBody (handle.m_pBody) | ||||||||
75 | { | ||||||||
76 | if (m_pBody) | ||||||||
77 | m_pBody->acquire(); | ||||||||
78 | } | ||||||||
79 | |||||||||
80 | #ifdef LIBO_INTERNAL_ONLY1 | ||||||||
81 | /** Move constructor... | ||||||||
82 | */ | ||||||||
83 | Reference (Reference<reference_type> && handle) noexcept | ||||||||
84 | : m_pBody (handle.m_pBody) | ||||||||
85 | { | ||||||||
86 | handle.m_pBody = nullptr; | ||||||||
87 | } | ||||||||
88 | #endif | ||||||||
89 | |||||||||
90 | #if defined LIBO_INTERNAL_ONLY1 | ||||||||
91 | /** Up-casting conversion constructor: Copies interface reference. | ||||||||
92 | |||||||||
93 | Does not work for up-casts to ambiguous bases. | ||||||||
94 | |||||||||
95 | @param rRef another reference | ||||||||
96 | */ | ||||||||
97 | template< class derived_type > | ||||||||
98 | inline Reference( | ||||||||
99 | const Reference< derived_type > & rRef, | ||||||||
100 | std::enable_if_t<std::is_base_of_v<reference_type, derived_type>, int> = 0 ) | ||||||||
101 | : m_pBody (rRef.get()) | ||||||||
102 | { | ||||||||
103 | if (m_pBody) | ||||||||
104 | m_pBody->acquire(); | ||||||||
105 | } | ||||||||
106 | #endif | ||||||||
107 | |||||||||
108 | /** Destructor... | ||||||||
109 | */ | ||||||||
110 | ~Reference() COVERITY_NOEXCEPT_FALSE | ||||||||
111 | { | ||||||||
112 | if (m_pBody) | ||||||||
113 | m_pBody->release(); | ||||||||
114 | } | ||||||||
115 | |||||||||
116 | /** Set... | ||||||||
117 | Similar to assignment. | ||||||||
118 | */ | ||||||||
119 | Reference<reference_type> & | ||||||||
120 | SAL_CALL set (reference_type * pBody) | ||||||||
121 | { | ||||||||
122 | if (pBody) | ||||||||
123 | pBody->acquire(); | ||||||||
124 | reference_type * const pOld = m_pBody; | ||||||||
125 | m_pBody = pBody; | ||||||||
126 | if (pOld) | ||||||||
127 | pOld->release(); | ||||||||
128 | return *this; | ||||||||
129 | } | ||||||||
130 | |||||||||
131 | /** Assignment. | ||||||||
132 | Unbinds this instance from its body (if bound) and | ||||||||
133 | bind it to the body represented by the handle. | ||||||||
134 | */ | ||||||||
135 | Reference<reference_type> & | ||||||||
136 | SAL_CALL operator= (const Reference<reference_type> & handle) | ||||||||
137 | { | ||||||||
138 | return set( handle.m_pBody ); | ||||||||
139 | } | ||||||||
140 | |||||||||
141 | #ifdef LIBO_INTERNAL_ONLY1 | ||||||||
142 | /** Assignment. | ||||||||
143 | * Unbinds this instance from its body (if bound), | ||||||||
144 | * bind it to the body represented by the handle, and | ||||||||
145 | * set the body represented by the handle to nullptr. | ||||||||
146 | */ | ||||||||
147 | Reference<reference_type> & | ||||||||
148 | operator= (Reference<reference_type> && handle) | ||||||||
149 | { | ||||||||
150 | // self-movement guts ourself | ||||||||
151 | if (m_pBody) | ||||||||
152 | m_pBody->release(); | ||||||||
153 | m_pBody = handle.m_pBody; | ||||||||
154 | handle.m_pBody = nullptr; | ||||||||
155 | return *this; | ||||||||
156 | } | ||||||||
157 | #endif | ||||||||
158 | |||||||||
159 | /** Assignment... | ||||||||
160 | */ | ||||||||
161 | Reference<reference_type> & | ||||||||
162 | SAL_CALL operator= (reference_type * pBody) | ||||||||
163 | { | ||||||||
164 | return set( pBody ); | ||||||||
165 | } | ||||||||
166 | |||||||||
167 | /** Unbind the body from this handle. | ||||||||
168 | Note that for a handle representing a large body, | ||||||||
169 | "handle.clear().set(new body());" _might_ | ||||||||
170 | perform a little bit better than "handle.set(new body());", | ||||||||
171 | since in the second case two large objects exist in memory | ||||||||
172 | (the old body and the new body). | ||||||||
173 | */ | ||||||||
174 | Reference<reference_type> & SAL_CALL clear() | ||||||||
175 | { | ||||||||
176 | if (m_pBody
| ||||||||
177 | { | ||||||||
178 | reference_type * const pOld = m_pBody; | ||||||||
179 | m_pBody = NULL__null; | ||||||||
180 | pOld->release(); | ||||||||
181 | } | ||||||||
182 | return *this; | ||||||||
183 | } | ||||||||
184 | |||||||||
185 | |||||||||
186 | /** Get the body. Can be used instead of operator->(). | ||||||||
187 | I.e. handle->someBodyOp() and handle.get()->someBodyOp() | ||||||||
188 | are the same. | ||||||||
189 | */ | ||||||||
190 | reference_type * SAL_CALL get() const | ||||||||
191 | { | ||||||||
192 | return m_pBody; | ||||||||
| |||||||||
193 | } | ||||||||
194 | |||||||||
195 | |||||||||
196 | /** Probably most common used: handle->someBodyOp(). | ||||||||
197 | */ | ||||||||
198 | reference_type * SAL_CALL operator->() const | ||||||||
199 | { | ||||||||
200 | assert(m_pBody != NULL)(static_cast <bool> (m_pBody != __null) ? void (0) : __assert_fail ("m_pBody != NULL", "/home/maarten/src/libreoffice/core/include/rtl/ref.hxx" , 200, __extension__ __PRETTY_FUNCTION__)); | ||||||||
201 | return m_pBody; | ||||||||
202 | } | ||||||||
203 | |||||||||
204 | |||||||||
205 | /** Allows (*handle).someBodyOp(). | ||||||||
206 | */ | ||||||||
207 | reference_type & SAL_CALL operator*() const | ||||||||
208 | { | ||||||||
209 | assert(m_pBody != NULL)(static_cast <bool> (m_pBody != __null) ? void (0) : __assert_fail ("m_pBody != NULL", "/home/maarten/src/libreoffice/core/include/rtl/ref.hxx" , 209, __extension__ __PRETTY_FUNCTION__)); | ||||||||
210 | return *m_pBody; | ||||||||
211 | } | ||||||||
212 | |||||||||
213 | |||||||||
214 | /** Returns True if the handle does point to a valid body. | ||||||||
215 | */ | ||||||||
216 | bool SAL_CALL is() const | ||||||||
217 | { | ||||||||
218 | return (m_pBody != NULL__null); | ||||||||
219 | } | ||||||||
220 | |||||||||
221 | #if defined LIBO_INTERNAL_ONLY1 | ||||||||
222 | /** Returns True if the handle does point to a valid body. | ||||||||
223 | */ | ||||||||
224 | explicit operator bool() const | ||||||||
225 | { | ||||||||
226 | return is(); | ||||||||
227 | } | ||||||||
228 | #endif | ||||||||
229 | |||||||||
230 | /** Returns True if this points to pBody. | ||||||||
231 | */ | ||||||||
232 | bool SAL_CALL operator== (const reference_type * pBody) const | ||||||||
233 | { | ||||||||
234 | return (m_pBody == pBody); | ||||||||
235 | } | ||||||||
236 | |||||||||
237 | |||||||||
238 | /** Returns True if handle points to the same body. | ||||||||
239 | */ | ||||||||
240 | bool | ||||||||
241 | SAL_CALL operator== (const Reference<reference_type> & handle) const | ||||||||
242 | { | ||||||||
243 | return (m_pBody == handle.m_pBody); | ||||||||
244 | } | ||||||||
245 | |||||||||
246 | |||||||||
247 | /** Needed to place References into STL collection. | ||||||||
248 | */ | ||||||||
249 | bool | ||||||||
250 | SAL_CALL operator!= (const Reference<reference_type> & handle) const | ||||||||
251 | { | ||||||||
252 | return (m_pBody != handle.m_pBody); | ||||||||
253 | } | ||||||||
254 | |||||||||
255 | |||||||||
256 | /** Needed to place References into STL collection. | ||||||||
257 | */ | ||||||||
258 | bool | ||||||||
259 | SAL_CALL operator< (const Reference<reference_type> & handle) const | ||||||||
260 | { | ||||||||
261 | return (m_pBody < handle.m_pBody); | ||||||||
262 | } | ||||||||
263 | |||||||||
264 | |||||||||
265 | /** Needed to place References into STL collection. | ||||||||
266 | */ | ||||||||
267 | bool | ||||||||
268 | SAL_CALL operator> (const Reference<reference_type> & handle) const | ||||||||
269 | { | ||||||||
270 | return (m_pBody > handle.m_pBody); | ||||||||
271 | } | ||||||||
272 | }; | ||||||||
273 | |||||||||
274 | } // namespace rtl | ||||||||
275 | |||||||||
276 | #if defined LIBO_INTERNAL_ONLY1 | ||||||||
277 | namespace std | ||||||||
278 | { | ||||||||
279 | |||||||||
280 | /// @cond INTERNAL | ||||||||
281 | /** | ||||||||
282 | Make rtl::Reference hashable by default for use in STL containers. | ||||||||
283 | |||||||||
284 | @since LibreOffice 6.3 | ||||||||
285 | */ | ||||||||
286 | template<typename T> | ||||||||
287 | struct hash<::rtl::Reference<T>> | ||||||||
288 | { | ||||||||
289 | std::size_t operator()(::rtl::Reference<T> const & s) const | ||||||||
290 | { return std::size_t(s.get()); } | ||||||||
291 | }; | ||||||||
292 | /// @endcond | ||||||||
293 | |||||||||
294 | } | ||||||||
295 | |||||||||
296 | #endif | ||||||||
297 | |||||||||
298 | #endif /* ! INCLUDED_RTL_REF_HXX */ | ||||||||
299 | |||||||||
300 | /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |
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 | #ifndef INCLUDED_VCL_Reference_HXX |
20 | #define INCLUDED_VCL_Reference_HXX |
21 | |
22 | #include <vcl/dllapi.h> |
23 | #include <osl/interlck.h> |
24 | |
25 | class VCL_DLLPUBLIC__attribute__ ((visibility("default"))) VclReferenceBase |
26 | { |
27 | mutable oslInterlockedCount mnRefCnt; |
28 | |
29 | template<typename T> friend class VclPtr; |
30 | |
31 | public: |
32 | void acquire() const |
33 | { |
34 | osl_atomic_increment(&mnRefCnt)__sync_add_and_fetch((&mnRefCnt), 1); |
35 | } |
36 | |
37 | void release() const |
38 | { |
39 | if (osl_atomic_decrement(&mnRefCnt)__sync_sub_and_fetch((&mnRefCnt), 1) == 0) |
40 | delete this; |
41 | } |
42 | #ifdef DBG_UTIL |
43 | #ifndef _WIN32 |
44 | sal_Int32 getRefCount() const { return mnRefCnt; } |
45 | #endif |
46 | #endif |
47 | |
48 | |
49 | private: |
50 | VclReferenceBase(const VclReferenceBase&) = delete; |
51 | VclReferenceBase& operator=(const VclReferenceBase&) = delete; |
52 | |
53 | bool mbDisposed : 1; |
54 | |
55 | protected: |
56 | VclReferenceBase(); |
57 | protected: |
58 | virtual ~VclReferenceBase(); |
59 | |
60 | protected: |
61 | virtual void dispose(); |
62 | |
63 | public: |
64 | void disposeOnce(); |
65 | bool isDisposed() const { return mbDisposed; } |
66 | |
67 | }; |
68 | #endif |