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 -*- */ | ||||||||
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 <stdlib.h> | ||||||||
23 | #include <hintids.hxx> | ||||||||
24 | #include <comphelper/string.hxx> | ||||||||
25 | #include <o3tl/any.hxx> | ||||||||
26 | #include <officecfg/Office/Common.hxx> | ||||||||
27 | #include <vcl/graph.hxx> | ||||||||
28 | #include <vcl/inputctx.hxx> | ||||||||
29 | #include <svl/eitem.hxx> | ||||||||
30 | #include <unotools/configmgr.hxx> | ||||||||
31 | #include <unotools/lingucfg.hxx> | ||||||||
32 | #include <unotools/useroptions.hxx> | ||||||||
33 | #include <sfx2/dispatch.hxx> | ||||||||
34 | #include <sfx2/docfile.hxx> | ||||||||
35 | #include <sfx2/objface.hxx> | ||||||||
36 | #include <sfx2/request.hxx> | ||||||||
37 | #include <svx/ruler.hxx> | ||||||||
38 | #include <svx/srchdlg.hxx> | ||||||||
39 | #include <svx/fmshell.hxx> | ||||||||
40 | #include <svx/extrusionbar.hxx> | ||||||||
41 | #include <svx/fontworkbar.hxx> | ||||||||
42 | #include <svx/fmview.hxx> | ||||||||
43 | #include <unotxvw.hxx> | ||||||||
44 | #include <cmdid.h> | ||||||||
45 | #include <svl/hint.hxx> | ||||||||
46 | #include <swmodule.hxx> | ||||||||
47 | #include <inputwin.hxx> | ||||||||
48 | #include <uivwimp.hxx> | ||||||||
49 | #include <edtwin.hxx> | ||||||||
50 | #include <textsh.hxx> | ||||||||
51 | #include <listsh.hxx> | ||||||||
52 | #include <tabsh.hxx> | ||||||||
53 | #include <grfsh.hxx> | ||||||||
54 | #include <mediash.hxx> | ||||||||
55 | #include <docsh.hxx> | ||||||||
56 | #include <frmsh.hxx> | ||||||||
57 | #include <olesh.hxx> | ||||||||
58 | #include <drawsh.hxx> | ||||||||
59 | #include <drawbase.hxx> | ||||||||
60 | #include <drformsh.hxx> | ||||||||
61 | #include <drwtxtsh.hxx> | ||||||||
62 | #include <beziersh.hxx> | ||||||||
63 | #include <navsh.hxx> | ||||||||
64 | #include <globdoc.hxx> | ||||||||
65 | #include <scroll.hxx> | ||||||||
66 | #include <gloshdl.hxx> | ||||||||
67 | #include <usrpref.hxx> | ||||||||
68 | #include <srcview.hxx> | ||||||||
69 | #include <doc.hxx> | ||||||||
70 | #include <IDocumentUndoRedo.hxx> | ||||||||
71 | #include <IDocumentSettingAccess.hxx> | ||||||||
72 | #include <IDocumentDrawModelAccess.hxx> | ||||||||
73 | #include <DocumentFieldsManager.hxx> | ||||||||
74 | #include <IDocumentState.hxx> | ||||||||
75 | #include <IDocumentLayoutAccess.hxx> | ||||||||
76 | #include <drawdoc.hxx> | ||||||||
77 | #include <wdocsh.hxx> | ||||||||
78 | #include <wrtsh.hxx> | ||||||||
79 | #include <barcfg.hxx> | ||||||||
80 | #include <pview.hxx> | ||||||||
81 | #include <swdtflvr.hxx> | ||||||||
82 | #include <prtopt.hxx> | ||||||||
83 | #include <com/sun/star/frame/FrameSearchFlag.hpp> | ||||||||
84 | #include <com/sun/star/frame/XLayoutManager.hpp> | ||||||||
85 | #include <com/sun/star/scanner/ScannerContext.hpp> | ||||||||
86 | #include <com/sun/star/scanner/XScannerManager2.hpp> | ||||||||
87 | #include <toolkit/helper/vclunohelper.hxx> | ||||||||
88 | #include <sal/log.hxx> | ||||||||
89 | |||||||||
90 | #include <formatclipboard.hxx> | ||||||||
91 | #include <PostItMgr.hxx> | ||||||||
92 | #include <annotsh.hxx> | ||||||||
93 | #include <swruler.hxx> | ||||||||
94 | |||||||||
95 | #include <com/sun/star/document/XDocumentProperties.hpp> | ||||||||
96 | #include <com/sun/star/document/XDocumentPropertiesSupplier.hpp> | ||||||||
97 | |||||||||
98 | #include <comphelper/propertyvalue.hxx> | ||||||||
99 | #include <sfx2/lokhelper.hxx> | ||||||||
100 | #include <LibreOfficeKit/LibreOfficeKitEnums.h> | ||||||||
101 | #include <svtools/embedhlp.hxx> | ||||||||
102 | #include <tools/UnitConversion.hxx> | ||||||||
103 | |||||||||
104 | using namespace ::com::sun::star; | ||||||||
105 | using namespace ::com::sun::star::uno; | ||||||||
106 | using namespace ::com::sun::star::lang; | ||||||||
107 | using namespace ::com::sun::star::scanner; | ||||||||
108 | |||||||||
109 | #define SWVIEWFLAGSSfxViewShellFlags::HAS_PRINTOPTIONS SfxViewShellFlags::HAS_PRINTOPTIONS | ||||||||
110 | |||||||||
111 | // Statics. OMG. | ||||||||
112 | |||||||||
113 | bool bDocSzUpdated = true; | ||||||||
114 | |||||||||
115 | SvxSearchItem* SwView::s_pSrchItem = nullptr; | ||||||||
116 | |||||||||
117 | bool SwView::s_bExtra = false; | ||||||||
118 | bool SwView::s_bFound = false; | ||||||||
119 | bool SwView::s_bJustOpened = false; | ||||||||
120 | |||||||||
121 | std::unique_ptr<SearchAttrItemList> SwView::s_xSearchList; | ||||||||
122 | std::unique_ptr<SearchAttrItemList> SwView::s_xReplaceList; | ||||||||
123 | |||||||||
124 | SfxDispatcher &SwView::GetDispatcher() | ||||||||
125 | { | ||||||||
126 | return *GetViewFrame()->GetDispatcher(); | ||||||||
127 | } | ||||||||
128 | |||||||||
129 | void SwView::ImpSetVerb( SelectionType nSelType ) | ||||||||
130 | { | ||||||||
131 | bool bResetVerbs = m_bVerbsActive; | ||||||||
132 | if ( !GetViewFrame()->GetFrame().IsInPlace() && | ||||||||
133 | (SelectionType::Ole|SelectionType::Graphic) & nSelType ) | ||||||||
134 | { | ||||||||
135 | if ( m_pWrtShell->IsSelObjProtected(FlyProtectFlags::Content) == FlyProtectFlags::NONE ) | ||||||||
136 | { | ||||||||
137 | if ( nSelType & SelectionType::Ole ) | ||||||||
138 | { | ||||||||
139 | SetVerbs( GetWrtShell().GetOLEObject()->getSupportedVerbs() ); | ||||||||
140 | m_bVerbsActive = true; | ||||||||
141 | bResetVerbs = false; | ||||||||
142 | } | ||||||||
143 | } | ||||||||
144 | } | ||||||||
145 | if ( bResetVerbs ) | ||||||||
146 | { | ||||||||
147 | SetVerbs( Sequence< embed::VerbDescriptor >() ); | ||||||||
148 | m_bVerbsActive = false; | ||||||||
149 | } | ||||||||
150 | } | ||||||||
151 | |||||||||
152 | // Called by the SwEditWin when it gets the focus. | ||||||||
153 | |||||||||
154 | void SwView::GotFocus() const | ||||||||
155 | { | ||||||||
156 | // if we got the focus, and the form shell *is* on the top of the dispatcher | ||||||||
157 | // stack, then we need to rebuild the stack (the form shell doesn't belong to | ||||||||
158 | // the top then) | ||||||||
159 | const SfxDispatcher& rDispatcher = const_cast< SwView* >( this )->GetDispatcher(); | ||||||||
160 | SfxShell* pTopShell = rDispatcher.GetShell( 0 ); | ||||||||
161 | FmFormShell* pAsFormShell = dynamic_cast<FmFormShell*>( pTopShell ); | ||||||||
162 | if ( pAsFormShell ) | ||||||||
163 | { | ||||||||
164 | pAsFormShell->ForgetActiveControl(); | ||||||||
165 | const_cast< SwView* >( this )->AttrChangedNotify(nullptr); | ||||||||
166 | } | ||||||||
167 | else if ( m_pPostItMgr ) | ||||||||
168 | { | ||||||||
169 | SwAnnotationShell* pAsAnnotationShell = dynamic_cast<SwAnnotationShell*>( pTopShell ); | ||||||||
170 | if ( pAsAnnotationShell ) | ||||||||
171 | { | ||||||||
172 | m_pPostItMgr->SetActiveSidebarWin(nullptr); | ||||||||
173 | const_cast< SwView* >( this )->AttrChangedNotify(nullptr); | ||||||||
174 | } | ||||||||
175 | } | ||||||||
176 | if( GetWrtShellPtr() ) | ||||||||
177 | { | ||||||||
178 | SwWrtShell& rWrtShell = GetWrtShell(); | ||||||||
179 | rWrtShell.GetDoc()->getIDocumentLayoutAccess().SetCurrentViewShell( GetWrtShellPtr() ); | ||||||||
180 | rWrtShell.GetDoc()->getIDocumentSettingAccess().set( DocumentSettingId::BROWSE_MODE, | ||||||||
181 | rWrtShell.GetViewOptions()->getBrowseMode() ); | ||||||||
182 | } | ||||||||
183 | } | ||||||||
184 | |||||||||
185 | // called by the FormShell when a form control is focused. This is | ||||||||
186 | // a request to put the form shell on the top of the dispatcher stack | ||||||||
187 | |||||||||
188 | IMPL_LINK_NOARG(SwView, FormControlActivated, LinkParamNone*, void)void SwView::LinkStubFormControlActivated(void * instance, LinkParamNone * data) { return static_cast<SwView *>(instance)->FormControlActivated (data); } void SwView::FormControlActivated(__attribute__ ((unused )) LinkParamNone*) | ||||||||
189 | { | ||||||||
190 | // if a form control has been activated, and the form shell is not on the top | ||||||||
191 | // of the dispatcher stack, then we need to activate it | ||||||||
192 | const SfxDispatcher& rDispatcher = GetDispatcher(); | ||||||||
193 | const SfxShell* pTopShell = rDispatcher.GetShell( 0 ); | ||||||||
194 | const FmFormShell* pAsFormShell = dynamic_cast<const FmFormShell*>( pTopShell ); | ||||||||
195 | if ( !pAsFormShell ) | ||||||||
196 | { | ||||||||
197 | // if we're editing text currently, cancel this | ||||||||
198 | SdrView *pSdrView = m_pWrtShell ? m_pWrtShell->GetDrawView() : nullptr; | ||||||||
199 | if ( pSdrView && pSdrView->IsTextEdit() ) | ||||||||
200 | pSdrView->SdrEndTextEdit( true ); | ||||||||
201 | |||||||||
202 | AttrChangedNotify(nullptr); | ||||||||
203 | } | ||||||||
204 | } | ||||||||
205 | |||||||||
206 | namespace | ||||||||
207 | { | ||||||||
208 | uno::Reference<frame::XLayoutManager> getLayoutManager(const SfxViewFrame& rViewFrame) | ||||||||
209 | { | ||||||||
210 | uno::Reference<frame::XLayoutManager> xLayoutManager; | ||||||||
211 | uno::Reference<beans::XPropertySet> xPropSet(rViewFrame.GetFrame().GetFrameInterface(), | ||||||||
212 | uno::UNO_QUERY); | ||||||||
213 | if (xPropSet.is()) | ||||||||
214 | { | ||||||||
215 | try | ||||||||
216 | { | ||||||||
217 | xLayoutManager.set(xPropSet->getPropertyValue("LayoutManager"), uno::UNO_QUERY); | ||||||||
218 | } | ||||||||
219 | catch (const Exception& e) | ||||||||
220 | { | ||||||||
221 | SAL_WARN("sw.ui", "Failure getting layout manager: " + e.Message)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 () << "Failure getting layout manager: " + e.Message) == 1) { ::sal_detail_log( (::SAL_DETAIL_LOG_LEVEL_WARN), ("sw.ui" ), ("/home/maarten/src/libreoffice/core/sw/source/uibase/uiview/view.cxx" ":" "221" ": "), ::sal::detail::unwrapStream( ::sal::detail:: StreamStart() << "Failure getting layout manager: " + e .Message), 0); } else { ::std::ostringstream sal_detail_stream ; sal_detail_stream << "Failure getting layout manager: " + e.Message; ::sal::detail::log( (::SAL_DETAIL_LOG_LEVEL_WARN ), ("sw.ui"), ("/home/maarten/src/libreoffice/core/sw/source/uibase/uiview/view.cxx" ":" "221" ": "), sal_detail_stream, 0); }; break; case SAL_DETAIL_LOG_ACTION_FATAL : if (sizeof ::sal::detail::getResult( ::sal::detail::StreamStart () << "Failure getting layout manager: " + e.Message) == 1) { ::sal_detail_log( (::SAL_DETAIL_LOG_LEVEL_WARN), ("sw.ui" ), ("/home/maarten/src/libreoffice/core/sw/source/uibase/uiview/view.cxx" ":" "221" ": "), ::sal::detail::unwrapStream( ::sal::detail:: StreamStart() << "Failure getting layout manager: " + e .Message), 0); } else { ::std::ostringstream sal_detail_stream ; sal_detail_stream << "Failure getting layout manager: " + e.Message; ::sal::detail::log( (::SAL_DETAIL_LOG_LEVEL_WARN ), ("sw.ui"), ("/home/maarten/src/libreoffice/core/sw/source/uibase/uiview/view.cxx" ":" "221" ": "), sal_detail_stream, 0); }; std::abort(); break ; } } } while (false); | ||||||||
222 | } | ||||||||
223 | } | ||||||||
224 | return xLayoutManager; | ||||||||
225 | } | ||||||||
226 | } | ||||||||
227 | |||||||||
228 | void SwView::ShowUIElement(const OUString& sElementURL) const | ||||||||
229 | { | ||||||||
230 | if (auto xLayoutManager = getLayoutManager(*GetViewFrame())) | ||||||||
231 | { | ||||||||
232 | if (!xLayoutManager->getElement(sElementURL).is()) | ||||||||
233 | { | ||||||||
234 | xLayoutManager->createElement(sElementURL); | ||||||||
235 | xLayoutManager->showElement(sElementURL); | ||||||||
236 | } | ||||||||
237 | } | ||||||||
238 | } | ||||||||
239 | |||||||||
240 | void SwView::SelectShell() | ||||||||
241 | { | ||||||||
242 | // Attention: Maintain the SelectShell for the WebView additionally | ||||||||
243 | |||||||||
244 | if(m_bInDtor) | ||||||||
245 | return; | ||||||||
246 | |||||||||
247 | // Decision if the UpdateTable has to be called | ||||||||
248 | bool bUpdateTable = false; | ||||||||
249 | const SwFrameFormat* pCurTableFormat = m_pWrtShell->GetTableFormat(); | ||||||||
250 | if(pCurTableFormat && pCurTableFormat != m_pLastTableFormat) | ||||||||
251 | { | ||||||||
252 | bUpdateTable = true; // can only be executed later | ||||||||
253 | } | ||||||||
254 | m_pLastTableFormat = pCurTableFormat; | ||||||||
255 | |||||||||
256 | //SEL_TBL and SEL_TBL_CELLS can be ORed! | ||||||||
257 | SelectionType nNewSelectionType = m_pWrtShell->GetSelectionType() | ||||||||
258 | & ~SelectionType::TableCell; | ||||||||
259 | |||||||||
260 | if ( m_pFormShell && m_pFormShell->IsActiveControl() ) | ||||||||
261 | nNewSelectionType |= SelectionType::FormControl; | ||||||||
262 | |||||||||
263 | if ( nNewSelectionType == m_nSelectionType ) | ||||||||
264 | { | ||||||||
265 | GetViewFrame()->GetBindings().InvalidateAll( false ); | ||||||||
266 | if ( m_nSelectionType & SelectionType::Ole || | ||||||||
267 | m_nSelectionType & SelectionType::Graphic ) | ||||||||
268 | // For graphs and OLE the verb can be modified of course! | ||||||||
269 | ImpSetVerb( nNewSelectionType ); | ||||||||
270 | } | ||||||||
271 | else | ||||||||
272 | { | ||||||||
273 | |||||||||
274 | SfxDispatcher &rDispatcher = GetDispatcher(); | ||||||||
275 | SwToolbarConfigItem *pBarCfg = SW_MOD()( static_cast<SwModule*>(SfxApplication::GetModule(SfxToolsModule ::Writer)))->GetToolbarConfig(); | ||||||||
276 | |||||||||
277 | if ( m_pShell ) | ||||||||
278 | { | ||||||||
279 | rDispatcher.Flush(); // Really erase all cached shells | ||||||||
280 | //Remember to the old selection which toolbar was visible | ||||||||
281 | ToolbarId eId = rDispatcher.GetObjectBarId(SFX_OBJECTBAR_OBJECT1); | ||||||||
282 | if (eId != ToolbarId::None) | ||||||||
283 | pBarCfg->SetTopToolbar(m_nSelectionType, eId); | ||||||||
284 | |||||||||
285 | for ( sal_uInt16 i = 0; true; ++i ) | ||||||||
286 | { | ||||||||
287 | SfxShell *pSfxShell = rDispatcher.GetShell( i ); | ||||||||
288 | if ( dynamic_cast< const SwBaseShell *>( pSfxShell ) != nullptr | ||||||||
289 | || dynamic_cast< const SwDrawTextShell *>( pSfxShell ) != nullptr | ||||||||
290 | || dynamic_cast< const svx::ExtrusionBar*>( pSfxShell ) != nullptr | ||||||||
291 | || dynamic_cast< const svx::FontworkBar*>( pSfxShell ) != nullptr | ||||||||
292 | || dynamic_cast< const SwAnnotationShell *>( pSfxShell ) != nullptr | ||||||||
293 | ) | ||||||||
294 | { | ||||||||
295 | rDispatcher.Pop( *pSfxShell, SfxDispatcherPopFlags::POP_DELETE ); | ||||||||
296 | } | ||||||||
297 | else if ( dynamic_cast< const FmFormShell *>( pSfxShell ) != nullptr ) | ||||||||
298 | { | ||||||||
299 | rDispatcher.Pop( *pSfxShell ); | ||||||||
300 | } | ||||||||
301 | else | ||||||||
302 | break; | ||||||||
303 | } | ||||||||
304 | } | ||||||||
305 | |||||||||
306 | bool bInitFormShell = false; | ||||||||
307 | if (!m_pFormShell) | ||||||||
308 | { | ||||||||
309 | bInitFormShell = true; | ||||||||
310 | m_pFormShell = new FmFormShell( this ); | ||||||||
311 | m_pFormShell->SetControlActivationHandler( LINK( this, SwView, FormControlActivated )::tools::detail::makeLink( ::tools::detail::castTo<SwView * >(this), &SwView::LinkStubFormControlActivated) ); | ||||||||
312 | StartListening(*m_pFormShell); | ||||||||
313 | } | ||||||||
314 | |||||||||
315 | bool bSetExtInpCntxt = false; | ||||||||
316 | m_nSelectionType = nNewSelectionType; | ||||||||
317 | ShellMode eShellMode; | ||||||||
318 | |||||||||
319 | if ( !( m_nSelectionType & SelectionType::FormControl ) ) | ||||||||
320 | rDispatcher.Push( *m_pFormShell ); | ||||||||
321 | |||||||||
322 | m_pShell = new SwNavigationShell( *this ); | ||||||||
323 | rDispatcher.Push( *m_pShell ); | ||||||||
324 | |||||||||
325 | if ( m_nSelectionType & SelectionType::Ole ) | ||||||||
326 | { | ||||||||
327 | eShellMode = ShellMode::Object; | ||||||||
328 | m_pShell = new SwOleShell( *this ); | ||||||||
329 | rDispatcher.Push( *m_pShell ); | ||||||||
330 | } | ||||||||
331 | else if ( m_nSelectionType & SelectionType::Frame | ||||||||
332 | || m_nSelectionType & SelectionType::Graphic) | ||||||||
333 | { | ||||||||
334 | eShellMode = ShellMode::Frame; | ||||||||
335 | m_pShell = new SwFrameShell( *this ); | ||||||||
336 | rDispatcher.Push( *m_pShell ); | ||||||||
337 | if(m_nSelectionType & SelectionType::Graphic ) | ||||||||
338 | { | ||||||||
339 | eShellMode = ShellMode::Graphic; | ||||||||
340 | m_pShell = new SwGrfShell( *this ); | ||||||||
341 | rDispatcher.Push( *m_pShell ); | ||||||||
342 | } | ||||||||
343 | } | ||||||||
344 | else if ( m_nSelectionType & SelectionType::DrawObject ) | ||||||||
345 | { | ||||||||
346 | eShellMode = ShellMode::Draw; | ||||||||
347 | m_pShell = new SwDrawShell( *this ); | ||||||||
348 | rDispatcher.Push( *m_pShell ); | ||||||||
349 | |||||||||
350 | if ( m_nSelectionType & SelectionType::Ornament ) | ||||||||
351 | { | ||||||||
352 | eShellMode = ShellMode::Bezier; | ||||||||
353 | m_pShell = new SwBezierShell( *this ); | ||||||||
354 | rDispatcher.Push( *m_pShell ); | ||||||||
355 | } | ||||||||
356 | #if HAVE_FEATURE_AVMEDIA1 | ||||||||
357 | else if( m_nSelectionType & SelectionType::Media ) | ||||||||
358 | { | ||||||||
359 | eShellMode = ShellMode::Media; | ||||||||
360 | m_pShell = new SwMediaShell( *this ); | ||||||||
361 | rDispatcher.Push( *m_pShell ); | ||||||||
362 | } | ||||||||
363 | #endif | ||||||||
364 | if (m_nSelectionType & SelectionType::ExtrudedCustomShape) | ||||||||
365 | { | ||||||||
366 | eShellMode = ShellMode::ExtrudedCustomShape; | ||||||||
367 | m_pShell = new svx::ExtrusionBar(this); | ||||||||
368 | rDispatcher.Push( *m_pShell ); | ||||||||
369 | } | ||||||||
370 | if (m_nSelectionType & SelectionType::FontWork) | ||||||||
371 | { | ||||||||
372 | eShellMode = ShellMode::FontWork; | ||||||||
373 | m_pShell = new svx::FontworkBar(this); | ||||||||
374 | rDispatcher.Push( *m_pShell ); | ||||||||
375 | } | ||||||||
376 | } | ||||||||
377 | else if ( m_nSelectionType & SelectionType::DbForm ) | ||||||||
378 | { | ||||||||
379 | eShellMode = ShellMode::DrawForm; | ||||||||
380 | m_pShell = new SwDrawFormShell( *this ); | ||||||||
381 | |||||||||
382 | rDispatcher.Push( *m_pShell ); | ||||||||
383 | } | ||||||||
384 | else if ( m_nSelectionType & SelectionType::DrawObjectEditMode ) | ||||||||
385 | { | ||||||||
386 | bSetExtInpCntxt = true; | ||||||||
387 | eShellMode = ShellMode::DrawText; | ||||||||
388 | rDispatcher.Push( *(new SwBaseShell( *this )) ); | ||||||||
389 | m_pShell = new SwDrawTextShell( *this ); | ||||||||
390 | rDispatcher.Push( *m_pShell ); | ||||||||
391 | } | ||||||||
392 | else if ( m_nSelectionType & SelectionType::PostIt ) | ||||||||
393 | { | ||||||||
394 | eShellMode = ShellMode::PostIt; | ||||||||
395 | m_pShell = new SwAnnotationShell( *this ); | ||||||||
396 | rDispatcher.Push( *m_pShell ); | ||||||||
397 | } | ||||||||
398 | else | ||||||||
399 | { | ||||||||
400 | bSetExtInpCntxt = true; | ||||||||
401 | eShellMode = ShellMode::Text; | ||||||||
402 | if ( m_nSelectionType & SelectionType::NumberList ) | ||||||||
403 | { | ||||||||
404 | eShellMode = ShellMode::ListText; | ||||||||
405 | m_pShell = new SwListShell( *this ); | ||||||||
406 | rDispatcher.Push( *m_pShell ); | ||||||||
407 | } | ||||||||
408 | m_pShell = new SwTextShell(*this); | ||||||||
409 | rDispatcher.Push( *m_pShell ); | ||||||||
410 | if ( m_nSelectionType & SelectionType::Table ) | ||||||||
411 | { | ||||||||
412 | eShellMode = eShellMode == ShellMode::ListText ? ShellMode::TableListText | ||||||||
413 | : ShellMode::TableText; | ||||||||
414 | m_pShell = new SwTableShell( *this ); | ||||||||
415 | rDispatcher.Push( *m_pShell ); | ||||||||
416 | } | ||||||||
417 | } | ||||||||
418 | |||||||||
419 | if ( m_nSelectionType & SelectionType::FormControl ) | ||||||||
420 | rDispatcher.Push( *m_pFormShell ); | ||||||||
421 | |||||||||
422 | m_pViewImpl->SetShellMode(eShellMode); | ||||||||
423 | ImpSetVerb( m_nSelectionType ); | ||||||||
424 | |||||||||
425 | if( !GetDocShell()->IsReadOnly() ) | ||||||||
426 | { | ||||||||
427 | if( bSetExtInpCntxt && GetWrtShell().HasReadonlySel() ) | ||||||||
428 | bSetExtInpCntxt = false; | ||||||||
429 | |||||||||
430 | InputContext aCntxt( GetEditWin().GetInputContext() ); | ||||||||
431 | aCntxt.SetOptions( bSetExtInpCntxt | ||||||||
432 | ? (aCntxt.GetOptions() | | ||||||||
433 | ( InputContextFlags::Text | | ||||||||
434 | InputContextFlags::ExtText )) | ||||||||
435 | : (aCntxt.GetOptions() & ~ | ||||||||
436 | InputContextFlags( InputContextFlags::Text | | ||||||||
437 | InputContextFlags::ExtText )) ); | ||||||||
438 | GetEditWin().SetInputContext( aCntxt ); | ||||||||
439 | } | ||||||||
440 | |||||||||
441 | // Show Mail Merge toolbar initially for documents with Database fields | ||||||||
442 | if (!m_bInitOnceCompleted && GetWrtShell().IsAnyDatabaseFieldInDoc()) | ||||||||
443 | ShowUIElement("private:resource/toolbar/mailmerge"); | ||||||||
444 | |||||||||
445 | // Activate the toolbar to the new selection which also was active last time. | ||||||||
446 | // Before a flush () must be, but does not affect the UI according to MBA and | ||||||||
447 | // is not a performance problem. | ||||||||
448 | // TODO/LATER: maybe now the Flush() command is superfluous?! | ||||||||
449 | rDispatcher.Flush(); | ||||||||
450 | |||||||||
451 | Point aPnt = GetEditWin().OutputToScreenPixel(GetEditWin().GetPointerPosPixel()); | ||||||||
452 | aPnt = GetEditWin().PixelToLogic(aPnt); | ||||||||
453 | GetEditWin().UpdatePointer(aPnt); | ||||||||
454 | |||||||||
455 | SdrView* pDView = GetWrtShell().GetDrawView(); | ||||||||
456 | if ( bInitFormShell && pDView ) | ||||||||
457 | m_pFormShell->SetView(dynamic_cast<FmFormView*>( pDView) ); | ||||||||
458 | |||||||||
459 | } | ||||||||
460 | // Opportune time for the communication with OLE objects? | ||||||||
461 | if ( GetDocShell()->GetDoc()->IsOLEPrtNotifyPending() ) | ||||||||
462 | GetDocShell()->GetDoc()->PrtOLENotify( false ); | ||||||||
463 | |||||||||
464 | // now the table-update | ||||||||
465 | if(bUpdateTable) | ||||||||
466 | m_pWrtShell->UpdateTable(); | ||||||||
467 | |||||||||
468 | GetViewImpl()->GetUNOObject_Impl()->NotifySelChanged(); | ||||||||
469 | |||||||||
470 | m_bInitOnceCompleted = true; | ||||||||
471 | } | ||||||||
472 | |||||||||
473 | // Interaction: AttrChangedNotify() and TimeoutHdl. | ||||||||
474 | // No Update if actions are still open, since the cursor on the core side | ||||||||
475 | // can be somewhere in no man's land. | ||||||||
476 | // But since we can no longer supply status and we want instead lock | ||||||||
477 | // the dispatcher. | ||||||||
478 | |||||||||
479 | extern "C" | ||||||||
480 | { | ||||||||
481 | static int lcl_CmpIds( const void *pFirst, const void *pSecond) | ||||||||
482 | { | ||||||||
483 | return *static_cast<sal_uInt16 const *>(pFirst) - *static_cast<sal_uInt16 const *>(pSecond); | ||||||||
484 | } | ||||||||
485 | } | ||||||||
486 | |||||||||
487 | IMPL_LINK_NOARG(SwView, AttrChangedNotify, LinkParamNone*, void)void SwView::LinkStubAttrChangedNotify(void * instance, LinkParamNone * data) { return static_cast<SwView *>(instance)->AttrChangedNotify (data); } void SwView::AttrChangedNotify(__attribute__ ((unused )) LinkParamNone*) | ||||||||
488 | { | ||||||||
489 | if ( GetEditWin().IsChainMode() ) | ||||||||
490 | GetEditWin().SetChainMode( false ); | ||||||||
491 | |||||||||
492 | //Opt: Not if PaintLocked. During unlock a notify will be once more triggered. | ||||||||
493 | if( !m_pWrtShell->IsPaintLocked() && !g_bNoInterrupt && | ||||||||
494 | GetDocShell()->IsReadOnly() ) | ||||||||
495 | CheckReadonlyState(); | ||||||||
496 | |||||||||
497 | if( !m_pWrtShell->IsPaintLocked() && !g_bNoInterrupt ) | ||||||||
498 | CheckReadonlySelection(); | ||||||||
499 | |||||||||
500 | if( !m_bAttrChgNotified ) | ||||||||
501 | { | ||||||||
502 | if (m_pWrtShell->ActionPend() || g_bNoInterrupt || | ||||||||
503 | GetDispatcher().IsLocked() || //do not confuse the SFX | ||||||||
504 | GetViewFrame()->GetBindings().IsInUpdate() )//do not confuse the SFX | ||||||||
505 | { | ||||||||
506 | m_bAttrChgNotified = true; | ||||||||
507 | m_aTimer.Start(); | ||||||||
508 | |||||||||
509 | const SfxPoolItem *pItem; | ||||||||
510 | if ( SfxItemState::SET != GetObjectShell()->GetMedium()->GetItemSet()-> | ||||||||
511 | GetItemState( SID_HIDDEN(5000 + 534), false, &pItem ) || | ||||||||
512 | !static_cast<const SfxBoolItem*>(pItem)->GetValue() ) | ||||||||
513 | { | ||||||||
514 | GetViewFrame()->GetBindings().ENTERREGISTRATIONS()EnterRegistrations(); | ||||||||
515 | m_bAttrChgNotifiedWithRegistrations = true; | ||||||||
516 | } | ||||||||
517 | |||||||||
518 | } | ||||||||
519 | else | ||||||||
520 | SelectShell(); | ||||||||
521 | |||||||||
522 | } | ||||||||
523 | |||||||||
524 | // change ui if cursor is at a SwPostItField | ||||||||
525 | if (m_pPostItMgr) | ||||||||
526 | { | ||||||||
527 | // only perform the code that is needed to determine, if at the | ||||||||
528 | // actual cursor position is a post-it field | ||||||||
529 | m_pPostItMgr->SetShadowState( m_pWrtShell->GetPostItFieldAtCursor() ); | ||||||||
530 | } | ||||||||
531 | } | ||||||||
532 | |||||||||
533 | IMPL_LINK_NOARG(SwView, TimeoutHdl, Timer *, void)void SwView::LinkStubTimeoutHdl(void * instance, Timer * data ) { return static_cast<SwView *>(instance)->TimeoutHdl (data); } void SwView::TimeoutHdl(__attribute__ ((unused)) Timer *) | ||||||||
534 | { | ||||||||
535 | if (m_pWrtShell->ActionPend() || g_bNoInterrupt) | ||||||||
536 | { | ||||||||
537 | m_aTimer.Start(); | ||||||||
538 | return; | ||||||||
539 | } | ||||||||
540 | |||||||||
541 | if ( m_bAttrChgNotifiedWithRegistrations ) | ||||||||
542 | { | ||||||||
543 | GetViewFrame()->GetBindings().LEAVEREGISTRATIONS()LeaveRegistrations(); | ||||||||
544 | m_bAttrChgNotifiedWithRegistrations = false; | ||||||||
545 | } | ||||||||
546 | |||||||||
547 | CheckReadonlyState(); | ||||||||
548 | CheckReadonlySelection(); | ||||||||
549 | |||||||||
550 | bool bOldUndo = m_pWrtShell->DoesUndo(); | ||||||||
551 | m_pWrtShell->DoUndo( false ); | ||||||||
552 | SelectShell(); | ||||||||
553 | m_pWrtShell->DoUndo( bOldUndo ); | ||||||||
554 | m_bAttrChgNotified = false; | ||||||||
555 | GetViewImpl()->GetUNOObject_Impl()->NotifySelChanged(); | ||||||||
556 | } | ||||||||
557 | |||||||||
558 | void SwView::CheckReadonlyState() | ||||||||
559 | { | ||||||||
560 | SfxDispatcher &rDis = GetDispatcher(); | ||||||||
561 | // To be able to recognize if it is already disabled! | ||||||||
562 | SfxItemState eStateRO, eStateProtAll; | ||||||||
563 | const SfxPoolItem *pItem; | ||||||||
564 | // Query the status from a slot which is only known to us. | ||||||||
565 | // Otherwise the slot is known from other; like the BasicIde | ||||||||
566 | eStateRO = rDis.QueryState( FN_INSERT_BOOKMARK((20000 + 300) + 2 ), pItem ); | ||||||||
567 | eStateProtAll = rDis.QueryState( FN_EDIT_REGION((20000 + 100) + 65), pItem ); | ||||||||
568 | bool bChgd = false; | ||||||||
569 | |||||||||
570 | if ( !m_pWrtShell->IsCursorReadonly() ) | ||||||||
571 | { | ||||||||
572 | static sal_uInt16 aROIds[] = | ||||||||
573 | { | ||||||||
574 | SID_DELETE(5000 + 713), FN_BACKSPACE((20000 + 900) + 26), FN_SHIFT_BACKSPACE((20000 + 900) + 42), | ||||||||
575 | SID_UNDO(5000 + 701), | ||||||||
576 | SID_REDO(5000 + 700), SID_REPEAT(5000 + 702), SID_PASTE(5000 + 712), | ||||||||
577 | SID_PASTE_UNFORMATTED(5000 + 314), FN_PASTE_NESTED_TABLE((20000 + 1400) + 30), FN_TABLE_PASTE_ROW_BEFORE((20000 + 1400) + 31), | ||||||||
578 | FN_TABLE_PASTE_COL_BEFORE((20000 + 1400) + 32), SID_PASTE_SPECIAL(5000 + 311), SID_SBA_BRW_INSERT(((((((10000 + 1499) + 1) + 499) + 1) + 100) + 1)+101), | ||||||||
579 | SID_BACKGROUND_COLORTypedWhichId<SvxColorItem>( 10000 + 186 ), FN_INSERT_BOOKMARK((20000 + 300) + 2 ), SID_CHARMAP_CONTROL(5000 + 406), | ||||||||
580 | SID_CHARMAP((10000 + 500) + 3), SID_EMOJI_CONTROL(5000 + 405), FN_INSERT_SOFT_HYPHEN((20000 + 300) + 43), | ||||||||
581 | FN_INSERT_HARDHYPHEN((20000 + 300) + 85), FN_INSERT_HARD_SPACE((20000 + 300) + 44), FN_INSERT_NNBSP((20000 + 300) + 45), | ||||||||
582 | FN_INSERT_BREAK((20000 + 300) + 3), FN_INSERT_LINEBREAK((20000 + 300) + 18), FN_INSERT_COLUMN_BREAK((20000 + 300) + 5 ), | ||||||||
583 | FN_INSERT_BREAK_DLG((20000 + 300) + 4 ), | ||||||||
584 | FN_DELETE_SENT((20000 + 900) + 27), FN_DELETE_BACK_SENT((20000 + 900) + 28), FN_DELETE_WORD((20000 + 900) + 29), | ||||||||
585 | FN_DELETE_BACK_WORD((20000 + 900) + 30), FN_DELETE_LINE((20000 + 900) + 31), FN_DELETE_BACK_LINE((20000 + 900) + 32), | ||||||||
586 | FN_DELETE_PARA((20000 + 900) + 33), FN_DELETE_BACK_PARA((20000 + 900) + 34), FN_DELETE_WHOLE_LINE((20000 + 900) + 35), | ||||||||
587 | FN_CALCULATE((20000 + 600) + 15), FN_FORMAT_RESET((20000 + 400) + 69), | ||||||||
588 | FN_POSTIT((20000 + 300) + 29), FN_JAVAEDIT((20000 + 1400) + 10), SID_ATTR_PARA_ADJUST_LEFT( 10000 + 28 ), | ||||||||
589 | SID_ATTR_PARA_ADJUST_RIGHT( 10000 + 29 ), SID_ATTR_PARA_ADJUST_CENTER( 10000 + 30 ),SID_ATTR_PARA_ADJUST_BLOCK( 10000 + 31 ), | ||||||||
590 | SID_ATTR_PARA_LINESPACE_10( 10000 + 34 ), SID_ATTR_PARA_LINESPACE_15( 10000 + 35 ), SID_ATTR_PARA_LINESPACE_20( 10000 + 36 ), | ||||||||
591 | SID_ATTR_CHAR_FONT( 10000 + 7 ), SID_ATTR_CHAR_FONTHEIGHT( 10000 + 15 ), SID_ATTR_CHAR_COLOR_BACKGROUND(10000 + 489), | ||||||||
592 | SID_ATTR_CHAR_COLOR_BACKGROUND_EXT(10000 + 490), SID_ATTR_CHAR_COLOR_EXT(10000 + 488), | ||||||||
593 | SID_ATTR_CHAR_COLOR( 10000 + 17 ), SID_ATTR_CHAR_WEIGHT( 10000 + 9 ), SID_ATTR_CHAR_POSTURE( 10000 + 8 ), | ||||||||
594 | SID_ATTR_CHAR_OVERLINE( ((10000 + 1499) + 1) + 68 ), | ||||||||
595 | SID_ATTR_CHAR_UNDERLINE( 10000 + 14 ), SID_ATTR_FLASH( 10000 + 406 ), SID_ATTR_CHAR_STRIKEOUT( 10000 + 13 ), | ||||||||
596 | SID_ULINE_VAL_SINGLE(10000 + 1196), SID_ULINE_VAL_DOUBLE(10000 + 1197), SID_ULINE_VAL_DOTTED(10000 + 1198), | ||||||||
597 | SID_ATTR_CHAR_CONTOUR( 10000 + 12 ), SID_ATTR_CHAR_SHADOWED( 10000 + 10 ), | ||||||||
598 | SID_ATTR_CHAR_AUTOKERN( 10000 + 67 ), SID_ATTR_CHAR_ESCAPEMENT( 10000 + 21 ), FN_SET_SUPER_SCRIPT((20000 + 400) + 11), | ||||||||
599 | FN_SET_SUB_SCRIPT((20000 + 400) + 12), SID_ATTR_CHAR_CASEMAP( 10000 + 19 ), SID_ATTR_CHAR_LANGUAGE( 10000 + 20 ), | ||||||||
600 | SID_ATTR_CHAR_KERNING( 10000 + 18 ), SID_CHAR_DLG( 10000 + 296 ), SID_ATTR_CHAR_WORDLINEMODE( 10000 + 11 ), | ||||||||
601 | FN_GROW_FONT_SIZE((20000 + 400) + 3 ), FN_SHRINK_FONT_SIZE((20000 + 400) + 4 ), FN_TXTATR_INET((20000 + 1000) +29), | ||||||||
602 | FN_FORMAT_DROPCAPS((20000 + 400) + 54), SID_ATTR_PARA_ADJUST( 10000 + 27 ), SID_ATTR_PARA_LINESPACE( 10000 + 33 ), | ||||||||
603 | SID_ATTR_PARA_SPLIT( 10000 + 39 ), SID_ATTR_PARA_KEEP( 10000 + 66 ), SID_ATTR_PARA_WIDOWS( 10000 + 41 ), | ||||||||
604 | SID_ATTR_PARA_ORPHANS( 10000 + 40 ), | ||||||||
605 | SID_ATTR_PARA_MODEL( 10000 + 65 ), SID_PARA_DLG( 10000 + 297 ), | ||||||||
606 | FN_SELECT_PARA((20000 + 100) + 97), SID_DEC_INDENT( 10000 + 461 ), | ||||||||
607 | SID_INC_INDENT( 10000 + 462 ) | ||||||||
608 | }; | ||||||||
609 | static bool bFirst = true; | ||||||||
610 | if ( bFirst ) | ||||||||
611 | { | ||||||||
612 | qsort( static_cast<void*>(aROIds), SAL_N_ELEMENTS(aROIds)(sizeof(sal_n_array_size(aROIds))), sizeof(sal_uInt16), lcl_CmpIds ); | ||||||||
613 | bFirst = false; | ||||||||
614 | } | ||||||||
615 | if ( SfxItemState::DISABLED == eStateRO ) | ||||||||
616 | { | ||||||||
617 | rDis.SetSlotFilter( SfxSlotFilterState::ENABLED_READONLY, aROIds ); | ||||||||
618 | bChgd = true; | ||||||||
619 | } | ||||||||
620 | } | ||||||||
621 | else if( m_pWrtShell->IsAllProtect() ) | ||||||||
622 | { | ||||||||
623 | if ( SfxItemState::DISABLED == eStateProtAll ) | ||||||||
624 | { | ||||||||
625 | static sal_uInt16 aAllProtIds[] = { SID_SAVEDOC(5000 + 505), FN_EDIT_REGION((20000 + 100) + 65) }; | ||||||||
626 | static bool bAllProtFirst = true; | ||||||||
627 | if ( bAllProtFirst ) | ||||||||
628 | { | ||||||||
629 | qsort( static_cast<void*>(aAllProtIds), SAL_N_ELEMENTS(aAllProtIds)(sizeof(sal_n_array_size(aAllProtIds))), sizeof(sal_uInt16), lcl_CmpIds ); | ||||||||
630 | bAllProtFirst = false; | ||||||||
631 | } | ||||||||
632 | rDis.SetSlotFilter( SfxSlotFilterState::ENABLED_READONLY, aAllProtIds ); | ||||||||
633 | bChgd = true; | ||||||||
634 | } | ||||||||
635 | } | ||||||||
636 | else if ( SfxItemState::DISABLED != eStateRO || | ||||||||
637 | SfxItemState::DISABLED != eStateProtAll ) | ||||||||
638 | { | ||||||||
639 | bChgd = true; | ||||||||
640 | rDis.SetSlotFilter(); | ||||||||
641 | } | ||||||||
642 | if ( bChgd ) | ||||||||
643 | GetViewFrame()->GetBindings().InvalidateAll(true); | ||||||||
644 | } | ||||||||
645 | |||||||||
646 | void SwView::CheckReadonlySelection() | ||||||||
647 | { | ||||||||
648 | SfxDisableFlags nDisableFlags = SfxDisableFlags::NONE; | ||||||||
649 | SfxDispatcher &rDis = GetDispatcher(); | ||||||||
650 | |||||||||
651 | if( m_pWrtShell->HasReadonlySel() && | ||||||||
652 | ( !m_pWrtShell->GetDrawView() || | ||||||||
653 | !m_pWrtShell->GetDrawView()->GetMarkedObjectList().GetMarkCount() )) | ||||||||
654 | nDisableFlags |= SfxDisableFlags::SwOnProtectedCursor; | ||||||||
655 | |||||||||
656 | if( (SfxDisableFlags::SwOnProtectedCursor & nDisableFlags ) != | ||||||||
657 | (SfxDisableFlags::SwOnProtectedCursor & rDis.GetDisableFlags() ) ) | ||||||||
658 | { | ||||||||
659 | // Additionally move at the Window the InputContext, so that | ||||||||
660 | // in japanese / chinese versions the external input will be | ||||||||
661 | // turned on or off. This but only if the correct shell is on | ||||||||
662 | // the stack. | ||||||||
663 | switch( m_pViewImpl->GetShellMode() ) | ||||||||
664 | { | ||||||||
665 | case ShellMode::Text: | ||||||||
666 | case ShellMode::ListText: | ||||||||
667 | case ShellMode::TableText: | ||||||||
668 | case ShellMode::TableListText: | ||||||||
669 | { | ||||||||
670 | // Temporary solution!!! Should set the font of the current insertion point | ||||||||
671 | // at each cursor movement, so outside of this "if". But TH does not | ||||||||
672 | // evaluates the font at this time and the "purchase" appears to me | ||||||||
673 | // as too expensive. | ||||||||
674 | // Moreover, we don't have a font, but only attributes from which the | ||||||||
675 | // text formatting and the correct font will be build together. | ||||||||
676 | |||||||||
677 | InputContext aCntxt( GetEditWin().GetInputContext() ); | ||||||||
678 | aCntxt.SetOptions( SfxDisableFlags::SwOnProtectedCursor & nDisableFlags | ||||||||
679 | ? (aCntxt.GetOptions() & ~ | ||||||||
680 | InputContextFlags( InputContextFlags::Text | | ||||||||
681 | InputContextFlags::ExtText )) | ||||||||
682 | : (aCntxt.GetOptions() | | ||||||||
683 | ( InputContextFlags::Text | | ||||||||
684 | InputContextFlags::ExtText )) ); | ||||||||
685 | GetEditWin().SetInputContext( aCntxt ); | ||||||||
686 | } | ||||||||
687 | break; | ||||||||
688 | default: | ||||||||
689 | ; | ||||||||
690 | } | ||||||||
691 | |||||||||
692 | } | ||||||||
693 | |||||||||
694 | if( nDisableFlags != rDis.GetDisableFlags() ) | ||||||||
695 | { | ||||||||
696 | rDis.SetDisableFlags( nDisableFlags ); | ||||||||
697 | GetViewFrame()->GetBindings().InvalidateAll( true ); | ||||||||
698 | } | ||||||||
699 | } | ||||||||
700 | |||||||||
701 | SwView::SwView( SfxViewFrame *_pFrame, SfxViewShell* pOldSh ) | ||||||||
702 | : SfxViewShell( _pFrame, SWVIEWFLAGSSfxViewShellFlags::HAS_PRINTOPTIONS ), | ||||||||
703 | m_nNewPage(USHRT_MAX(32767 *2 +1)), | ||||||||
704 | m_nOldPageNum(0), | ||||||||
705 | m_pNumRuleNodeFromDoc(nullptr), | ||||||||
706 | m_pEditWin( VclPtr<SwEditWin>::Create( &_pFrame->GetWindow(), *this ) ), | ||||||||
707 | m_pShell(nullptr), | ||||||||
708 | m_pFormShell(nullptr), | ||||||||
709 | m_pHScrollbar(nullptr), | ||||||||
710 | m_pVScrollbar(nullptr), | ||||||||
711 | m_pScrollFill(VclPtr<ScrollBarBox>::Create( &_pFrame->GetWindow(), WB_SIZEABLE )), | ||||||||
712 | m_pVRuler(VclPtr<SvxRuler>::Create(&GetViewFrame()->GetWindow(), m_pEditWin, | ||||||||
713 | SvxRulerSupportFlags::TABS | SvxRulerSupportFlags::PARAGRAPH_MARGINS_VERTICAL| | ||||||||
714 | SvxRulerSupportFlags::BORDERS | SvxRulerSupportFlags::REDUCED_METRIC, | ||||||||
715 | GetViewFrame()->GetBindings(), | ||||||||
716 | WB_VSCROLL | WB_EXTRAFIELD | WB_BORDER )), | ||||||||
717 | m_pLastTableFormat(nullptr), | ||||||||
718 | m_pFormatClipboard(new SwFormatClipboard()), | ||||||||
719 | m_nSelectionType( SelectionType::All ), | ||||||||
720 | m_nPageCnt(0), | ||||||||
721 | m_nDrawSfxId( USHRT_MAX(32767 *2 +1) ), | ||||||||
722 | m_nFormSfxId( USHRT_MAX(32767 *2 +1) ), | ||||||||
723 | m_nLastPasteDestination( static_cast<SotExchangeDest>(0xFFFF) ), | ||||||||
724 | m_nLeftBorderDistance( 0 ), | ||||||||
725 | m_nRightBorderDistance( 0 ), | ||||||||
726 | m_eLastSearchCommand( static_cast<SvxSearchCmd>(0xFFFF) ), | ||||||||
727 | m_bWheelScrollInProgress(false), | ||||||||
728 | m_bCenterCursor(false), | ||||||||
729 | m_bTopCursor(false), | ||||||||
730 | m_bTabColFromDoc(false), | ||||||||
731 | m_bTabRowFromDoc(false), | ||||||||
732 | m_bSetTabColFromDoc(false), | ||||||||
733 | m_bSetTabRowFromDoc(false), | ||||||||
734 | m_bAttrChgNotified(false), | ||||||||
735 | m_bAttrChgNotifiedWithRegistrations(false), | ||||||||
736 | m_bVerbsActive(false), | ||||||||
737 | m_bDrawRotate(false), | ||||||||
738 | m_bDrawSelMode(true), | ||||||||
739 | m_bShowAtResize(true), | ||||||||
740 | m_bInOuterResizePixel(false), | ||||||||
741 | m_bInInnerResizePixel(false), | ||||||||
742 | m_bPasteState(false), | ||||||||
743 | m_bPasteSpecialState(false), | ||||||||
744 | m_bInMailMerge(false), | ||||||||
745 | m_bInDtor(false), | ||||||||
746 | m_bOldShellWasPagePreview(false), | ||||||||
747 | m_bIsPreviewDoubleClick(false), | ||||||||
748 | m_bMakeSelectionVisible(false), | ||||||||
749 | m_nLOKPageUpDownOffset(0) | ||||||||
750 | { | ||||||||
751 | static bool bRequestDoubleBuffering = getenv("VCL_DOUBLEBUFFERING_ENABLE"); | ||||||||
752 | if (bRequestDoubleBuffering) | ||||||||
753 | m_pEditWin->RequestDoubleBuffering(true); | ||||||||
754 | |||||||||
755 | // According to discussion with MBA and further | ||||||||
756 | // investigations, no old SfxViewShell will be set as parameter <pOldSh>, | ||||||||
757 | // if function "New Window" is performed to open an additional view beside | ||||||||
758 | // an already existing one. | ||||||||
759 | // If the view is switch from one to another, the 'old' view is given by | ||||||||
760 | // parameter <pOldSh>. | ||||||||
761 | |||||||||
762 | bDocSzUpdated = true; | ||||||||
763 | |||||||||
764 | CreateScrollbar( true ); | ||||||||
765 | CreateScrollbar( false ); | ||||||||
766 | |||||||||
767 | m_pViewImpl.reset(new SwView_Impl(this)); | ||||||||
768 | SetName("View"); | ||||||||
769 | SetWindow( m_pEditWin ); | ||||||||
770 | |||||||||
771 | m_aTimer.SetTimeout( 120 ); | ||||||||
772 | |||||||||
773 | SwDocShell& rDocSh = dynamic_cast<SwDocShell&>(*_pFrame->GetObjectShell()); | ||||||||
774 | bool bOldModifyFlag = rDocSh.IsEnableSetModified(); | ||||||||
775 | if (bOldModifyFlag) | ||||||||
776 | rDocSh.EnableSetModified( false ); | ||||||||
777 | // HACK: SwDocShell has some cached font info, VCL informs about font updates, | ||||||||
778 | // but loading of docs with embedded fonts happens after SwDocShell is created | ||||||||
779 | // but before SwEditWin (which handles the VCL event) is created. So update | ||||||||
780 | // manually. | ||||||||
781 | if (rDocSh.GetDoc()->getIDocumentSettingAccess().get( DocumentSettingId::EMBED_FONTS )) | ||||||||
782 | rDocSh.UpdateFontList(); | ||||||||
783 | bool bWebDShell = dynamic_cast<const SwWebDocShell*>(&rDocSh) != nullptr; | ||||||||
784 | |||||||||
785 | const SwMasterUsrPref *pUsrPref = SW_MOD()( static_cast<SwModule*>(SfxApplication::GetModule(SfxToolsModule ::Writer)))->GetUsrPref(bWebDShell); | ||||||||
786 | SwViewOption aUsrPref( *pUsrPref); | ||||||||
787 | |||||||||
788 | //! get lingu options without loading lingu DLL | ||||||||
789 | SvtLinguOptions aLinguOpt; | ||||||||
790 | SvtLinguConfig().GetOptions( aLinguOpt ); | ||||||||
791 | aUsrPref.SetOnlineSpell( aLinguOpt.bIsSpellAuto ); | ||||||||
792 | |||||||||
793 | bool bOldShellWasSrcView = false; | ||||||||
794 | |||||||||
795 | // determine if there is an existing view for | ||||||||
796 | // document | ||||||||
797 | SfxViewShell* pExistingSh = nullptr; | ||||||||
798 | if ( pOldSh ) | ||||||||
799 | { | ||||||||
800 | pExistingSh = pOldSh; | ||||||||
801 | // determine type of existing view | ||||||||
802 | if (SwPagePreview* pPagePreview = dynamic_cast<SwPagePreview *>(pExistingSh)) | ||||||||
803 | { | ||||||||
804 | m_sSwViewData = pPagePreview->GetPrevSwViewData(); | ||||||||
805 | m_sNewCursorPos = pPagePreview->GetNewCursorPos(); | ||||||||
806 | m_nNewPage = pPagePreview->GetNewPage(); | ||||||||
807 | m_bOldShellWasPagePreview = true; | ||||||||
808 | m_bIsPreviewDoubleClick = !m_sNewCursorPos.isEmpty() || m_nNewPage != USHRT_MAX(32767 *2 +1); | ||||||||
809 | } | ||||||||
810 | else if (dynamic_cast<const SwSrcView *>(pExistingSh) != nullptr) | ||||||||
811 | bOldShellWasSrcView = true; | ||||||||
812 | } | ||||||||
813 | |||||||||
814 | SAL_INFO( "sw.ui", "before create WrtShell" )do { if (true) { switch (sal_detail_log_report(::SAL_DETAIL_LOG_LEVEL_INFO , "sw.ui")) { case SAL_DETAIL_LOG_ACTION_IGNORE: break; case SAL_DETAIL_LOG_ACTION_LOG : if (sizeof ::sal::detail::getResult( ::sal::detail::StreamStart () << "before create WrtShell") == 1) { ::sal_detail_log ( (::SAL_DETAIL_LOG_LEVEL_INFO), ("sw.ui"), ("/home/maarten/src/libreoffice/core/sw/source/uibase/uiview/view.cxx" ":" "814" ": "), ::sal::detail::unwrapStream( ::sal::detail:: StreamStart() << "before create WrtShell"), 0); } else { ::std::ostringstream sal_detail_stream; sal_detail_stream << "before create WrtShell"; ::sal::detail::log( (::SAL_DETAIL_LOG_LEVEL_INFO ), ("sw.ui"), ("/home/maarten/src/libreoffice/core/sw/source/uibase/uiview/view.cxx" ":" "814" ": "), sal_detail_stream, 0); }; break; case SAL_DETAIL_LOG_ACTION_FATAL : if (sizeof ::sal::detail::getResult( ::sal::detail::StreamStart () << "before create WrtShell") == 1) { ::sal_detail_log ( (::SAL_DETAIL_LOG_LEVEL_INFO), ("sw.ui"), ("/home/maarten/src/libreoffice/core/sw/source/uibase/uiview/view.cxx" ":" "814" ": "), ::sal::detail::unwrapStream( ::sal::detail:: StreamStart() << "before create WrtShell"), 0); } else { ::std::ostringstream sal_detail_stream; sal_detail_stream << "before create WrtShell"; ::sal::detail::log( (::SAL_DETAIL_LOG_LEVEL_INFO ), ("sw.ui"), ("/home/maarten/src/libreoffice/core/sw/source/uibase/uiview/view.cxx" ":" "814" ": "), sal_detail_stream, 0); }; std::abort(); break ; } } } while (false); | ||||||||
815 | if (SwView *pView = dynamic_cast<SwView*>(pExistingSh)) | ||||||||
816 | { | ||||||||
817 | m_pWrtShell.reset(new SwWrtShell(*pView->m_pWrtShell, m_pEditWin, *this)); | ||||||||
818 | } | ||||||||
819 | else if (SwWrtShell *pWrtShell = dynamic_cast<SwWrtShell*>(rDocSh.GetDoc()->getIDocumentLayoutAccess().GetCurrentViewShell())) | ||||||||
820 | { | ||||||||
821 | m_pWrtShell.reset(new SwWrtShell(*pWrtShell, m_pEditWin, *this)); | ||||||||
822 | } | ||||||||
823 | else | ||||||||
824 | { | ||||||||
825 | SwDoc& rDoc = *rDocSh.GetDoc(); | ||||||||
826 | |||||||||
827 | if( !bOldShellWasSrcView && bWebDShell && !m_bOldShellWasPagePreview ) | ||||||||
828 | aUsrPref.setBrowseMode( true ); | ||||||||
829 | else | ||||||||
830 | aUsrPref.setBrowseMode( rDoc.getIDocumentSettingAccess().get(DocumentSettingId::BROWSE_MODE) ); | ||||||||
831 | |||||||||
832 | //For the BrowseMode we do not assume a factor. | ||||||||
833 | if( aUsrPref.getBrowseMode() && aUsrPref.GetZoomType() != SvxZoomType::PERCENT ) | ||||||||
834 | { | ||||||||
835 | aUsrPref.SetZoomType( SvxZoomType::PERCENT ); | ||||||||
836 | aUsrPref.SetZoom( 100 ); | ||||||||
837 | } | ||||||||
838 | if (rDocSh.IsPreview()) | ||||||||
839 | { | ||||||||
840 | aUsrPref.SetZoomType( SvxZoomType::WHOLEPAGE ); | ||||||||
841 | aUsrPref.SetViewLayoutBookMode( false ); | ||||||||
842 | aUsrPref.SetViewLayoutColumns( 1 ); | ||||||||
843 | } | ||||||||
844 | m_pWrtShell.reset(new SwWrtShell(rDoc, m_pEditWin, *this, &aUsrPref)); | ||||||||
845 | // creating an SwView from a SwPagePreview needs to | ||||||||
846 | // add the SwViewShell to the ring of the other SwViewShell(s) | ||||||||
847 | if(m_bOldShellWasPagePreview) | ||||||||
848 | { | ||||||||
849 | SwViewShell& rPreviewViewShell = *static_cast<SwPagePreview*>(pExistingSh)->GetViewShell(); | ||||||||
850 | m_pWrtShell->MoveTo(&rPreviewViewShell); | ||||||||
851 | // to update the field command et.al. if necessary | ||||||||
852 | const SwViewOption* pPreviewOpt = rPreviewViewShell.GetViewOptions(); | ||||||||
853 | if( pPreviewOpt->IsFieldName() != aUsrPref.IsFieldName() || | ||||||||
854 | pPreviewOpt->IsShowHiddenField() != aUsrPref.IsShowHiddenField() || | ||||||||
855 | pPreviewOpt->IsShowHiddenPara() != aUsrPref.IsShowHiddenPara() || | ||||||||
856 | pPreviewOpt->IsShowHiddenChar() != aUsrPref.IsShowHiddenChar() ) | ||||||||
857 | rPreviewViewShell.ApplyViewOptions(aUsrPref); | ||||||||
858 | // reset design mode at draw view for form | ||||||||
859 | // shell, if needed. | ||||||||
860 | if ( static_cast<SwPagePreview*>(pExistingSh)->ResetFormDesignMode() && | ||||||||
861 | m_pWrtShell->HasDrawView() ) | ||||||||
862 | { | ||||||||
863 | SdrView* pDrawView = m_pWrtShell->GetDrawView(); | ||||||||
864 | pDrawView->SetDesignMode( static_cast<SwPagePreview*>(pExistingSh)->FormDesignModeToReset() ); | ||||||||
865 | } | ||||||||
866 | } | ||||||||
867 | } | ||||||||
868 | SAL_INFO( "sw.ui", "after create WrtShell" )do { if (true) { switch (sal_detail_log_report(::SAL_DETAIL_LOG_LEVEL_INFO , "sw.ui")) { case SAL_DETAIL_LOG_ACTION_IGNORE: break; case SAL_DETAIL_LOG_ACTION_LOG : if (sizeof ::sal::detail::getResult( ::sal::detail::StreamStart () << "after create WrtShell") == 1) { ::sal_detail_log ( (::SAL_DETAIL_LOG_LEVEL_INFO), ("sw.ui"), ("/home/maarten/src/libreoffice/core/sw/source/uibase/uiview/view.cxx" ":" "868" ": "), ::sal::detail::unwrapStream( ::sal::detail:: StreamStart() << "after create WrtShell"), 0); } else { ::std::ostringstream sal_detail_stream; sal_detail_stream << "after create WrtShell"; ::sal::detail::log( (::SAL_DETAIL_LOG_LEVEL_INFO ), ("sw.ui"), ("/home/maarten/src/libreoffice/core/sw/source/uibase/uiview/view.cxx" ":" "868" ": "), sal_detail_stream, 0); }; break; case SAL_DETAIL_LOG_ACTION_FATAL : if (sizeof ::sal::detail::getResult( ::sal::detail::StreamStart () << "after create WrtShell") == 1) { ::sal_detail_log ( (::SAL_DETAIL_LOG_LEVEL_INFO), ("sw.ui"), ("/home/maarten/src/libreoffice/core/sw/source/uibase/uiview/view.cxx" ":" "868" ": "), ::sal::detail::unwrapStream( ::sal::detail:: StreamStart() << "after create WrtShell"), 0); } else { ::std::ostringstream sal_detail_stream; sal_detail_stream << "after create WrtShell"; ::sal::detail::log( (::SAL_DETAIL_LOG_LEVEL_INFO ), ("sw.ui"), ("/home/maarten/src/libreoffice/core/sw/source/uibase/uiview/view.cxx" ":" "868" ": "), sal_detail_stream, 0); }; std::abort(); break ; } } } while (false); | ||||||||
869 | m_pHRuler = VclPtr<SwCommentRuler>::Create(m_pWrtShell.get(), &GetViewFrame()->GetWindow(), m_pEditWin, | ||||||||
870 | SvxRulerSupportFlags::TABS | | ||||||||
871 | SvxRulerSupportFlags::PARAGRAPH_MARGINS | | ||||||||
872 | SvxRulerSupportFlags::BORDERS | | ||||||||
873 | SvxRulerSupportFlags::NEGATIVE_MARGINS| | ||||||||
874 | SvxRulerSupportFlags::REDUCED_METRIC, | ||||||||
875 | GetViewFrame()->GetBindings(), | ||||||||
876 | WB_STDRULER | WB_EXTRAFIELD | WB_BORDER); | ||||||||
877 | |||||||||
878 | // assure that modified state of document | ||||||||
879 | // isn't reset, if document is already modified. | ||||||||
880 | const bool bIsDocModified = m_pWrtShell->GetDoc()->getIDocumentState().IsModified(); | ||||||||
881 | |||||||||
882 | // Thus among other things, the HRuler is not displayed in the read-only case. | ||||||||
883 | aUsrPref.SetReadonly( m_pWrtShell->GetViewOptions()->IsReadonly() ); | ||||||||
884 | |||||||||
885 | // no margin for OLE! | ||||||||
886 | Size aBrwsBorder; | ||||||||
887 | if( SfxObjectCreateMode::EMBEDDED != rDocSh.GetCreateMode() ) | ||||||||
888 | aBrwsBorder = GetMargin(); | ||||||||
889 | |||||||||
890 | m_pWrtShell->SetBrowseBorder( aBrwsBorder ); | ||||||||
891 | |||||||||
892 | // In CTOR no shell changes may take place, which must be temporarily stored | ||||||||
893 | // with the timer. Otherwise, the SFX removes them from the stack! | ||||||||
894 | bool bOld = g_bNoInterrupt; | ||||||||
895 | g_bNoInterrupt = true; | ||||||||
896 | |||||||||
897 | m_pHRuler->SetActive(); | ||||||||
898 | m_pVRuler->SetActive(); | ||||||||
899 | |||||||||
900 | SfxViewFrame* pViewFrame = GetViewFrame(); | ||||||||
901 | |||||||||
902 | StartListening(*pViewFrame, DuplicateHandling::Prevent); | ||||||||
903 | StartListening(rDocSh, DuplicateHandling::Prevent); | ||||||||
904 | |||||||||
905 | // Set Zoom-factor from HRuler | ||||||||
906 | Fraction aZoomFract( aUsrPref.GetZoom(), 100 ); | ||||||||
907 | m_pHRuler->SetZoom( aZoomFract ); | ||||||||
908 | m_pVRuler->SetZoom( aZoomFract ); | ||||||||
909 | m_pHRuler->SetDoubleClickHdl(LINK( this, SwView, ExecRulerClick )::tools::detail::makeLink( ::tools::detail::castTo<SwView * >(this), &SwView::LinkStubExecRulerClick)); | ||||||||
910 | FieldUnit eMetric = pUsrPref->GetHScrollMetric(); | ||||||||
911 | m_pHRuler->SetUnit( eMetric ); | ||||||||
912 | |||||||||
913 | eMetric = pUsrPref->GetVScrollMetric(); | ||||||||
914 | m_pVRuler->SetUnit( eMetric ); | ||||||||
915 | |||||||||
916 | m_pHRuler->SetCharWidth( 371 ); // default character width | ||||||||
917 | m_pVRuler->SetLineHeight( 551 ); // default line height | ||||||||
918 | |||||||||
919 | // Set DocShell | ||||||||
920 | m_xGlueDocShell.reset(new SwViewGlueDocShell(*this, rDocSh)); | ||||||||
921 | m_pPostItMgr.reset(new SwPostItMgr(this)); | ||||||||
922 | |||||||||
923 | // Check and process the DocSize. Via the handler, the shell could not | ||||||||
924 | // be found, because the shell is not known in the SFX management | ||||||||
925 | // within the CTOR phase. | ||||||||
926 | DocSzChgd( m_pWrtShell->GetDocSize() ); | ||||||||
927 | |||||||||
928 | // Set AttrChangedNotify link | ||||||||
929 | m_pWrtShell->SetChgLnk(LINK(this, SwView, AttrChangedNotify)::tools::detail::makeLink( ::tools::detail::castTo<SwView * >(this), &SwView::LinkStubAttrChangedNotify)); | ||||||||
930 | |||||||||
931 | if (rDocSh.GetCreateMode() == SfxObjectCreateMode::EMBEDDED && | ||||||||
932 | !rDocSh.GetVisArea(ASPECT_CONTENT1).IsEmpty()) | ||||||||
933 | SetVisArea(rDocSh.GetVisArea(ASPECT_CONTENT1),false); | ||||||||
934 | |||||||||
935 | SAL_WARN_IF(do { if (true && (officecfg::Office::Common::Undo::Steps ::get() <= 0)) { 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 () << "/org.openoffice.Office.Common/Undo/Steps <= 0" ) == 1) { ::sal_detail_log( (::SAL_DETAIL_LOG_LEVEL_WARN), ("sw.ui" ), ("/home/maarten/src/libreoffice/core/sw/source/uibase/uiview/view.cxx" ":" "937" ": "), ::sal::detail::unwrapStream( ::sal::detail:: StreamStart() << "/org.openoffice.Office.Common/Undo/Steps <= 0" ), 0); } else { ::std::ostringstream sal_detail_stream; sal_detail_stream << "/org.openoffice.Office.Common/Undo/Steps <= 0"; ::sal::detail::log( (::SAL_DETAIL_LOG_LEVEL_WARN), ("sw.ui") , ("/home/maarten/src/libreoffice/core/sw/source/uibase/uiview/view.cxx" ":" "937" ": "), sal_detail_stream, 0); }; break; case SAL_DETAIL_LOG_ACTION_FATAL : if (sizeof ::sal::detail::getResult( ::sal::detail::StreamStart () << "/org.openoffice.Office.Common/Undo/Steps <= 0" ) == 1) { ::sal_detail_log( (::SAL_DETAIL_LOG_LEVEL_WARN), ("sw.ui" ), ("/home/maarten/src/libreoffice/core/sw/source/uibase/uiview/view.cxx" ":" "937" ": "), ::sal::detail::unwrapStream( ::sal::detail:: StreamStart() << "/org.openoffice.Office.Common/Undo/Steps <= 0" ), 0); } else { ::std::ostringstream sal_detail_stream; sal_detail_stream << "/org.openoffice.Office.Common/Undo/Steps <= 0"; ::sal::detail::log( (::SAL_DETAIL_LOG_LEVEL_WARN), ("sw.ui") , ("/home/maarten/src/libreoffice/core/sw/source/uibase/uiview/view.cxx" ":" "937" ": "), sal_detail_stream, 0); }; std::abort(); break ; } } } while (false) | ||||||||
936 | officecfg::Office::Common::Undo::Steps::get() <= 0,do { if (true && (officecfg::Office::Common::Undo::Steps ::get() <= 0)) { 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 () << "/org.openoffice.Office.Common/Undo/Steps <= 0" ) == 1) { ::sal_detail_log( (::SAL_DETAIL_LOG_LEVEL_WARN), ("sw.ui" ), ("/home/maarten/src/libreoffice/core/sw/source/uibase/uiview/view.cxx" ":" "937" ": "), ::sal::detail::unwrapStream( ::sal::detail:: StreamStart() << "/org.openoffice.Office.Common/Undo/Steps <= 0" ), 0); } else { ::std::ostringstream sal_detail_stream; sal_detail_stream << "/org.openoffice.Office.Common/Undo/Steps <= 0"; ::sal::detail::log( (::SAL_DETAIL_LOG_LEVEL_WARN), ("sw.ui") , ("/home/maarten/src/libreoffice/core/sw/source/uibase/uiview/view.cxx" ":" "937" ": "), sal_detail_stream, 0); }; break; case SAL_DETAIL_LOG_ACTION_FATAL : if (sizeof ::sal::detail::getResult( ::sal::detail::StreamStart () << "/org.openoffice.Office.Common/Undo/Steps <= 0" ) == 1) { ::sal_detail_log( (::SAL_DETAIL_LOG_LEVEL_WARN), ("sw.ui" ), ("/home/maarten/src/libreoffice/core/sw/source/uibase/uiview/view.cxx" ":" "937" ": "), ::sal::detail::unwrapStream( ::sal::detail:: StreamStart() << "/org.openoffice.Office.Common/Undo/Steps <= 0" ), 0); } else { ::std::ostringstream sal_detail_stream; sal_detail_stream << "/org.openoffice.Office.Common/Undo/Steps <= 0"; ::sal::detail::log( (::SAL_DETAIL_LOG_LEVEL_WARN), ("sw.ui") , ("/home/maarten/src/libreoffice/core/sw/source/uibase/uiview/view.cxx" ":" "937" ": "), sal_detail_stream, 0); }; std::abort(); break ; } } } while (false) | ||||||||
937 | "sw.ui", "/org.openoffice.Office.Common/Undo/Steps <= 0")do { if (true && (officecfg::Office::Common::Undo::Steps ::get() <= 0)) { 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 () << "/org.openoffice.Office.Common/Undo/Steps <= 0" ) == 1) { ::sal_detail_log( (::SAL_DETAIL_LOG_LEVEL_WARN), ("sw.ui" ), ("/home/maarten/src/libreoffice/core/sw/source/uibase/uiview/view.cxx" ":" "937" ": "), ::sal::detail::unwrapStream( ::sal::detail:: StreamStart() << "/org.openoffice.Office.Common/Undo/Steps <= 0" ), 0); } else { ::std::ostringstream sal_detail_stream; sal_detail_stream << "/org.openoffice.Office.Common/Undo/Steps <= 0"; ::sal::detail::log( (::SAL_DETAIL_LOG_LEVEL_WARN), ("sw.ui") , ("/home/maarten/src/libreoffice/core/sw/source/uibase/uiview/view.cxx" ":" "937" ": "), sal_detail_stream, 0); }; break; case SAL_DETAIL_LOG_ACTION_FATAL : if (sizeof ::sal::detail::getResult( ::sal::detail::StreamStart () << "/org.openoffice.Office.Common/Undo/Steps <= 0" ) == 1) { ::sal_detail_log( (::SAL_DETAIL_LOG_LEVEL_WARN), ("sw.ui" ), ("/home/maarten/src/libreoffice/core/sw/source/uibase/uiview/view.cxx" ":" "937" ": "), ::sal::detail::unwrapStream( ::sal::detail:: StreamStart() << "/org.openoffice.Office.Common/Undo/Steps <= 0" ), 0); } else { ::std::ostringstream sal_detail_stream; sal_detail_stream << "/org.openoffice.Office.Common/Undo/Steps <= 0"; ::sal::detail::log( (::SAL_DETAIL_LOG_LEVEL_WARN), ("sw.ui") , ("/home/maarten/src/libreoffice/core/sw/source/uibase/uiview/view.cxx" ":" "937" ": "), sal_detail_stream, 0); }; std::abort(); break ; } } } while (false); | ||||||||
938 | if (!utl::ConfigManager::IsFuzzing() && 0 < officecfg::Office::Common::Undo::Steps::get()) | ||||||||
939 | { | ||||||||
940 | m_pWrtShell->DoUndo(); | ||||||||
941 | } | ||||||||
942 | |||||||||
943 | const bool bBrowse = m_pWrtShell->GetViewOptions()->getBrowseMode(); | ||||||||
944 | // Disable "multiple window" | ||||||||
945 | SetNewWindowAllowed(!bBrowse); | ||||||||
946 | // End of disabled multiple window | ||||||||
947 | |||||||||
948 | m_bVScrollbarEnabled = aUsrPref.IsViewVScrollBar(); | ||||||||
949 | m_bHScrollbarEnabled = aUsrPref.IsViewHScrollBar(); | ||||||||
950 | m_pHScrollbar->SetAuto(bBrowse); | ||||||||
951 | if( aUsrPref.IsViewHRuler() ) | ||||||||
952 | CreateTab(); | ||||||||
953 | if( aUsrPref.IsViewVRuler() ) | ||||||||
954 | CreateVRuler(); | ||||||||
955 | |||||||||
956 | m_pWrtShell->SetUIOptions( aUsrPref ); | ||||||||
957 | m_pWrtShell->SetReadOnlyAvailable( aUsrPref.IsCursorInProtectedArea() ); | ||||||||
958 | m_pWrtShell->ApplyAccessibilityOptions(SW_MOD()( static_cast<SwModule*>(SfxApplication::GetModule(SfxToolsModule ::Writer)))->GetAccessibilityOptions()); | ||||||||
959 | |||||||||
960 | if( m_pWrtShell->GetDoc()->getIDocumentState().IsUpdateExpField() ) | ||||||||
961 | { | ||||||||
962 | if (m_pWrtShell->GetDoc()->GetDocumentFieldsManager().containsUpdatableFields()) | ||||||||
963 | { | ||||||||
964 | CurrShell aCurr(m_pWrtShell.get()); | ||||||||
965 | m_pWrtShell->StartAction(); | ||||||||
966 | m_pWrtShell->CalcLayout(); | ||||||||
967 | m_pWrtShell->GetDoc()->getIDocumentFieldsAccess().UpdateFields(false); | ||||||||
968 | m_pWrtShell->EndAction(); | ||||||||
969 | } | ||||||||
970 | m_pWrtShell->GetDoc()->getIDocumentState().SetUpdateExpFieldStat( false ); | ||||||||
971 | } | ||||||||
972 | |||||||||
973 | // Update all tables if necessary: | ||||||||
974 | if( m_pWrtShell->GetDoc()->IsUpdateTOX() ) | ||||||||
975 | { | ||||||||
976 | SfxRequest aSfxRequest( FN_UPDATE_TOX((20000 + 600) + 53), SfxCallMode::SLOT, GetPool() ); | ||||||||
977 | Execute( aSfxRequest ); | ||||||||
978 | m_pWrtShell->GetDoc()->SetUpdateTOX( false ); // reset again | ||||||||
979 | m_pWrtShell->SttEndDoc(true); | ||||||||
980 | } | ||||||||
981 | |||||||||
982 | // No ResetModified, if there is already a view to this doc. | ||||||||
983 | SfxViewFrame* pVFrame = GetViewFrame(); | ||||||||
984 | SfxViewFrame* pFirst = SfxViewFrame::GetFirst(&rDocSh); | ||||||||
985 | // Currently(360) the view is registered firstly after the CTOR, | ||||||||
986 | // the following expression is also working if this changes. | ||||||||
987 | // If the modification cannot be canceled by undo, then do NOT set | ||||||||
988 | // the modify back. | ||||||||
989 | // no reset of modified state, if document | ||||||||
990 | // was already modified. | ||||||||
991 | if (!m_pWrtShell->GetDoc()->GetIDocumentUndoRedo().IsUndoNoResetModified() && | ||||||||
992 | ( !pFirst || pFirst == pVFrame ) && | ||||||||
993 | !bIsDocModified ) | ||||||||
994 | { | ||||||||
995 | m_pWrtShell->ResetModified(); | ||||||||
996 | } | ||||||||
997 | |||||||||
998 | g_bNoInterrupt = bOld; | ||||||||
999 | |||||||||
1000 | // If a new GlobalDoc will be created, the navigator will also be generated. | ||||||||
1001 | if( dynamic_cast<const SwGlobalDocShell*>(&rDocSh) != nullptr && | ||||||||
1002 | !pVFrame->GetChildWindow( SID_NAVIGATOR(10000 + 366) )) | ||||||||
1003 | { | ||||||||
1004 | SfxBoolItem aNavi(SID_NAVIGATOR(10000 + 366), true); | ||||||||
1005 | GetDispatcher().ExecuteList(SID_NAVIGATOR(10000 + 366), SfxCallMode::ASYNCHRON, { &aNavi }); | ||||||||
1006 | } | ||||||||
1007 | |||||||||
1008 | uno::Reference< frame::XFrame > xFrame = pVFrame->GetFrame().GetFrameInterface(); | ||||||||
1009 | |||||||||
1010 | uno::Reference< frame::XFrame > xBeamerFrame = xFrame->findFrame( | ||||||||
1011 | "_beamer", frame::FrameSearchFlag::CHILDREN); | ||||||||
1012 | if(xBeamerFrame.is()) | ||||||||
1013 | { | ||||||||
1014 | SwDBData aData = m_pWrtShell->GetDBData(); | ||||||||
1015 | SwModule::ShowDBObj( *this, aData ); | ||||||||
1016 | } | ||||||||
1017 | |||||||||
1018 | // has anybody calls the attrchanged handler in the constructor? | ||||||||
1019 | if( m_bAttrChgNotifiedWithRegistrations ) | ||||||||
1020 | { | ||||||||
1021 | GetViewFrame()->GetBindings().LEAVEREGISTRATIONS()LeaveRegistrations(); | ||||||||
1022 | if( m_aTimer.IsActive() ) | ||||||||
1023 | m_aTimer.Stop(); | ||||||||
1024 | } | ||||||||
1025 | |||||||||
1026 | m_aTimer.SetInvokeHandler(LINK(this, SwView, TimeoutHdl)::tools::detail::makeLink( ::tools::detail::castTo<SwView * >(this), &SwView::LinkStubTimeoutHdl)); | ||||||||
1027 | m_aTimer.SetDebugName( "sw::SwView m_aTimer" ); | ||||||||
1028 | m_bAttrChgNotified = m_bAttrChgNotifiedWithRegistrations = false; | ||||||||
1029 | if (bOldModifyFlag) | ||||||||
1030 | rDocSh.EnableSetModified(); | ||||||||
1031 | InvalidateBorder(); | ||||||||
1032 | |||||||||
1033 | if( !m_pHScrollbar->IsVisible( true ) ) | ||||||||
1034 | ShowHScrollbar( false ); | ||||||||
1035 | if( !m_pVScrollbar->IsVisible( true ) ) | ||||||||
1036 | ShowVScrollbar( false ); | ||||||||
1037 | |||||||||
1038 | GetViewFrame()->GetWindow().AddChildEventListener( LINK( this, SwView, WindowChildEventListener )::tools::detail::makeLink( ::tools::detail::castTo<SwView * >(this), &SwView::LinkStubWindowChildEventListener) ); | ||||||||
1039 | } | ||||||||
1040 | |||||||||
1041 | SwViewGlueDocShell::SwViewGlueDocShell(SwView& rView, SwDocShell& rDocSh) | ||||||||
1042 | : m_rView(rView) | ||||||||
1043 | { | ||||||||
1044 | // Set DocShell | ||||||||
1045 | rDocSh.SetView(&m_rView); | ||||||||
1046 | SW_MOD()( static_cast<SwModule*>(SfxApplication::GetModule(SfxToolsModule ::Writer)))->SetView(&m_rView); | ||||||||
1047 | } | ||||||||
1048 | |||||||||
1049 | SwViewGlueDocShell::~SwViewGlueDocShell() | ||||||||
1050 | { | ||||||||
1051 | SwDocShell* pDocSh = m_rView.GetDocShell(); | ||||||||
1052 | if (pDocSh && pDocSh->GetView() == &m_rView) | ||||||||
1053 | pDocSh->SetView(nullptr); | ||||||||
1054 | if (SW_MOD()( static_cast<SwModule*>(SfxApplication::GetModule(SfxToolsModule ::Writer)))->GetView() == &m_rView) | ||||||||
1055 | SW_MOD()( static_cast<SwModule*>(SfxApplication::GetModule(SfxToolsModule ::Writer)))->SetView(nullptr); | ||||||||
1056 | } | ||||||||
1057 | |||||||||
1058 | SwView::~SwView() | ||||||||
1059 | { | ||||||||
1060 | // Notify other LOK views that we are going away. | ||||||||
1061 | SfxLokHelper::notifyOtherViews(this, LOK_CALLBACK_VIEW_CURSOR_VISIBLE, "visible", "false"); | ||||||||
1062 | SfxLokHelper::notifyOtherViews(this, LOK_CALLBACK_TEXT_VIEW_SELECTION, "selection", ""); | ||||||||
1063 | SfxLokHelper::notifyOtherViews(this, LOK_CALLBACK_GRAPHIC_VIEW_SELECTION, "selection", "EMPTY"); | ||||||||
1064 | |||||||||
1065 | // Need to remove activated field's button before disposing EditWin. | ||||||||
1066 | GetWrtShell().getIDocumentMarkAccess()->ClearFieldActivation(); | ||||||||
1067 | |||||||||
1068 | GetViewFrame()->GetWindow().RemoveChildEventListener( LINK( this, SwView, WindowChildEventListener )::tools::detail::makeLink( ::tools::detail::castTo<SwView * >(this), &SwView::LinkStubWindowChildEventListener) ); | ||||||||
1069 | m_pPostItMgr.reset(); | ||||||||
1070 | |||||||||
1071 | m_bInDtor = true; | ||||||||
1072 | m_pEditWin->Hide(); // prevent problems with painting | ||||||||
1073 | |||||||||
1074 | // Set pointer in SwDocShell to the view again | ||||||||
1075 | m_xGlueDocShell.reset(); | ||||||||
1076 | |||||||||
1077 | if( m_aTimer.IsActive() && m_bAttrChgNotifiedWithRegistrations ) | ||||||||
| |||||||||
1078 | GetViewFrame()->GetBindings().LEAVEREGISTRATIONS()LeaveRegistrations(); | ||||||||
1079 | |||||||||
1080 | // the last view must end the text edit | ||||||||
1081 | SdrView *pSdrView = m_pWrtShell ? m_pWrtShell->GetDrawView() : nullptr; | ||||||||
1082 | if( pSdrView
| ||||||||
1083 | pSdrView->SdrEndTextEdit( true ); | ||||||||
1084 | |||||||||
1085 | SetWindow( nullptr ); | ||||||||
1086 | |||||||||
1087 | m_pViewImpl->Invalidate(); | ||||||||
1088 | EndListening(*GetViewFrame()); | ||||||||
1089 | EndListening(*GetDocShell()); | ||||||||
1090 | m_pScrollFill.disposeAndClear(); | ||||||||
1091 | m_pWrtShell.reset(); // reset here so that it is not accessible by the following dtors. | ||||||||
1092 | m_pHScrollbar.disposeAndClear(); | ||||||||
1093 | m_pVScrollbar.disposeAndClear(); | ||||||||
1094 | m_pHRuler.disposeAndClear(); | ||||||||
1095 | m_pVRuler.disposeAndClear(); | ||||||||
1096 | m_pGlosHdl.reset(); | ||||||||
1097 | m_pViewImpl.reset(); | ||||||||
1098 | |||||||||
1099 | // If this was enabled in the ctor for the frame, then disable it here. | ||||||||
1100 | static bool bRequestDoubleBuffering = getenv("VCL_DOUBLEBUFFERING_ENABLE"); | ||||||||
1101 | if (bRequestDoubleBuffering) | ||||||||
1102 | m_pEditWin->RequestDoubleBuffering(false); | ||||||||
1103 | m_pEditWin.disposeAndClear(); | ||||||||
1104 | |||||||||
1105 | m_pFormatClipboard.reset(); | ||||||||
1106 | } | ||||||||
1107 | |||||||||
1108 | SwDocShell* SwView::GetDocShell() | ||||||||
1109 | { | ||||||||
1110 | SfxObjectShell* pDocShell = GetViewFrame()->GetObjectShell(); | ||||||||
1111 | return dynamic_cast<SwDocShell*>( pDocShell ); | ||||||||
1112 | } | ||||||||
1113 | |||||||||
1114 | // Remember CursorPos | ||||||||
1115 | |||||||||
1116 | void SwView::WriteUserData( OUString &rUserData, bool bBrowse ) | ||||||||
1117 | { | ||||||||
1118 | // The browse flag will be passed from Sfx when documents are browsed | ||||||||
1119 | // (not to be confused with the BrowseMode). | ||||||||
1120 | // Then that stored data are not persistent! | ||||||||
1121 | |||||||||
1122 | const SwRect& rRect = m_pWrtShell->GetCharRect(); | ||||||||
1123 | const tools::Rectangle& rVis = GetVisArea(); | ||||||||
1124 | |||||||||
1125 | rUserData = OUString::number( rRect.Left() ); | ||||||||
1126 | rUserData += ";"; | ||||||||
1127 | rUserData += OUString::number( rRect.Top() ); | ||||||||
1128 | rUserData += ";"; | ||||||||
1129 | rUserData += OUString::number( m_pWrtShell->GetViewOptions()->GetZoom() ); | ||||||||
1130 | rUserData += ";"; | ||||||||
1131 | rUserData += OUString::number( rVis.Left() ); | ||||||||
1132 | rUserData += ";"; | ||||||||
1133 | rUserData += OUString::number( rVis.Top() ); | ||||||||
1134 | rUserData += ";"; | ||||||||
1135 | rUserData += OUString::number( bBrowse ? SAL_MIN_INT32((sal_Int32) (-0x7FFFFFFF - 1)) : rVis.Right()); | ||||||||
1136 | rUserData += ";"; | ||||||||
1137 | rUserData += OUString::number( bBrowse ? SAL_MIN_INT32((sal_Int32) (-0x7FFFFFFF - 1)) : rVis.Bottom()); | ||||||||
1138 | rUserData += ";"; | ||||||||
1139 | rUserData += OUString::number( | ||||||||
1140 | static_cast<sal_uInt16>(m_pWrtShell->GetViewOptions()->GetZoomType()));//eZoom; | ||||||||
1141 | rUserData += ";"; | ||||||||
1142 | rUserData += FrameTypeFlags::NONE == m_pWrtShell->GetSelFrameType() ? OUStringLiteral(u"0") : OUStringLiteral(u"1"); | ||||||||
1143 | } | ||||||||
1144 | |||||||||
1145 | // Set CursorPos | ||||||||
1146 | |||||||||
1147 | static bool lcl_IsOwnDocument( SwView& rView ) | ||||||||
1148 | { | ||||||||
1149 | uno::Reference<document::XDocumentPropertiesSupplier> xDPS( | ||||||||
1150 | rView.GetDocShell()->GetModel(), uno::UNO_QUERY_THROW); | ||||||||
1151 | uno::Reference<document::XDocumentProperties> xDocProps | ||||||||
1152 | = xDPS->getDocumentProperties(); | ||||||||
1153 | OUString Created = xDocProps->getAuthor(); | ||||||||
1154 | OUString Changed = xDocProps->getModifiedBy(); | ||||||||
1155 | OUString FullName = SW_MOD()( static_cast<SwModule*>(SfxApplication::GetModule(SfxToolsModule ::Writer)))->GetUserOptions().GetFullName(); | ||||||||
1156 | return (!FullName.isEmpty() && | ||||||||
1157 | (!Changed.isEmpty() && Changed == FullName )) || | ||||||||
1158 | (Changed.isEmpty() && !Created.isEmpty() && Created == FullName ); | ||||||||
1159 | } | ||||||||
1160 | |||||||||
1161 | void SwView::ReadUserData( const OUString &rUserData, bool bBrowse ) | ||||||||
1162 | { | ||||||||
1163 | if ( !(rUserData.indexOf(';')>=0 && // more than one token | ||||||||
1164 | // For document without layout only in the onlinelayout or | ||||||||
1165 | // while forward/backward | ||||||||
1166 | (!m_pWrtShell->IsNewLayout() || m_pWrtShell->GetViewOptions()->getBrowseMode() || bBrowse)) ) | ||||||||
1167 | return; | ||||||||
1168 | |||||||||
1169 | bool bIsOwnDocument = lcl_IsOwnDocument( *this ); | ||||||||
1170 | |||||||||
1171 | CurrShell aCurr(m_pWrtShell.get()); | ||||||||
1172 | |||||||||
1173 | sal_Int32 nPos = 0; | ||||||||
1174 | |||||||||
1175 | // No it is *not* a good idea to call GetToken within Point constr. immediately, | ||||||||
1176 | // because which parameter is evaluated first? | ||||||||
1177 | long nX = rUserData.getToken( 0, ';', nPos ).toInt32(), | ||||||||
1178 | nY = rUserData.getToken( 0, ';', nPos ).toInt32(); | ||||||||
1179 | Point aCursorPos( nX, nY ); | ||||||||
1180 | |||||||||
1181 | sal_uInt16 nZoomFactor = | ||||||||
1182 | static_cast< sal_uInt16 >( rUserData.getToken(0, ';', nPos ).toInt32() ); | ||||||||
1183 | |||||||||
1184 | long nLeft = rUserData.getToken(0, ';', nPos ).toInt32(), | ||||||||
1185 | nTop = rUserData.getToken(0, ';', nPos ).toInt32(), | ||||||||
1186 | nRight = rUserData.getToken(0, ';', nPos ).toInt32(), | ||||||||
1187 | nBottom= rUserData.getToken(0, ';', nPos ).toInt32(); | ||||||||
1188 | |||||||||
1189 | const long nAdd = m_pWrtShell->GetViewOptions()->getBrowseMode() ? DOCUMENTBORDER284 : DOCUMENTBORDER284*2; | ||||||||
1190 | if ( nBottom > (m_pWrtShell->GetDocSize().Height()+nAdd) ) | ||||||||
1191 | return; | ||||||||
1192 | |||||||||
1193 | m_pWrtShell->EnableSmooth( false ); | ||||||||
1194 | |||||||||
1195 | const tools::Rectangle aVis( nLeft, nTop, nRight, nBottom ); | ||||||||
1196 | |||||||||
1197 | sal_Int32 nOff = 0; | ||||||||
1198 | SvxZoomType eZoom; | ||||||||
1199 | if( !m_pWrtShell->GetViewOptions()->getBrowseMode() ) | ||||||||
1200 | eZoom = static_cast<SvxZoomType>(static_cast<sal_uInt16>(rUserData.getToken(nOff, ';', nPos ).toInt32())); | ||||||||
1201 | else | ||||||||
1202 | { | ||||||||
1203 | eZoom = SvxZoomType::PERCENT; | ||||||||
1204 | ++nOff; | ||||||||
1205 | } | ||||||||
1206 | |||||||||
1207 | bool bSelectObj = (0 != rUserData.getToken( nOff, ';', nPos ).toInt32()) | ||||||||
1208 | && m_pWrtShell->IsObjSelectable( aCursorPos ); | ||||||||
1209 | |||||||||
1210 | // restore editing position | ||||||||
1211 | m_pViewImpl->SetRestorePosition(aCursorPos, bSelectObj); | ||||||||
1212 | // set flag value to avoid macro execution. | ||||||||
1213 | bool bSavedFlagValue = m_pWrtShell->IsMacroExecAllowed(); | ||||||||
1214 | m_pWrtShell->SetMacroExecAllowed( false ); | ||||||||
1215 | // os: changed: The user data has to be read if the view is switched back from page preview | ||||||||
1216 | // go to the last editing position when opening own files | ||||||||
1217 | if(m_bOldShellWasPagePreview || bIsOwnDocument) | ||||||||
1218 | { | ||||||||
1219 | m_pWrtShell->SwCursorShell::SetCursor( aCursorPos, !bSelectObj ); | ||||||||
1220 | if( bSelectObj ) | ||||||||
1221 | { | ||||||||
1222 | m_pWrtShell->SelectObj( aCursorPos ); | ||||||||
1223 | m_pWrtShell->EnterSelFrameMode( &aCursorPos ); | ||||||||
1224 | } | ||||||||
1225 | } | ||||||||
1226 | |||||||||
1227 | // reset flag value | ||||||||
1228 | m_pWrtShell->SetMacroExecAllowed( bSavedFlagValue ); | ||||||||
1229 | |||||||||
1230 | // set visible area before applying | ||||||||
1231 | // information from print preview. Otherwise, the applied information | ||||||||
1232 | // is lost. | ||||||||
1233 | // os: changed: The user data has to be read if the view is switched back from page preview | ||||||||
1234 | // go to the last editing position when opening own files | ||||||||
1235 | if(m_bOldShellWasPagePreview || bIsOwnDocument ) | ||||||||
1236 | { | ||||||||
1237 | if ( bBrowse ) | ||||||||
1238 | SetVisArea( aVis.TopLeft() ); | ||||||||
1239 | else | ||||||||
1240 | SetVisArea( aVis ); | ||||||||
1241 | } | ||||||||
1242 | |||||||||
1243 | //apply information from print preview - if available | ||||||||
1244 | if( !m_sNewCursorPos.isEmpty() ) | ||||||||
1245 | { | ||||||||
1246 | sal_Int32 nIdx{ 0 }; | ||||||||
1247 | const long nXTmp = m_sNewCursorPos.getToken( 0, ';', nIdx ).toInt32(); | ||||||||
1248 | const long nYTmp = m_sNewCursorPos.getToken( 0, ';', nIdx ).toInt32(); | ||||||||
1249 | Point aCursorPos2( nXTmp, nYTmp ); | ||||||||
1250 | bSelectObj = m_pWrtShell->IsObjSelectable( aCursorPos2 ); | ||||||||
1251 | |||||||||
1252 | m_pWrtShell->SwCursorShell::SetCursor( aCursorPos2 ); | ||||||||
1253 | if( bSelectObj ) | ||||||||
1254 | { | ||||||||
1255 | m_pWrtShell->SelectObj( aCursorPos2 ); | ||||||||
1256 | m_pWrtShell->EnterSelFrameMode( &aCursorPos2 ); | ||||||||
1257 | } | ||||||||
1258 | m_pWrtShell->MakeSelVisible(); | ||||||||
1259 | m_sNewCursorPos.clear(); | ||||||||
1260 | } | ||||||||
1261 | else if(USHRT_MAX(32767 *2 +1) != m_nNewPage) | ||||||||
1262 | { | ||||||||
1263 | m_pWrtShell->GotoPage(m_nNewPage, true); | ||||||||
1264 | m_nNewPage = USHRT_MAX(32767 *2 +1); | ||||||||
1265 | } | ||||||||
1266 | |||||||||
1267 | SelectShell(); | ||||||||
1268 | |||||||||
1269 | m_pWrtShell->StartAction(); | ||||||||
1270 | const SwViewOption* pVOpt = m_pWrtShell->GetViewOptions(); | ||||||||
1271 | if( pVOpt->GetZoom() != nZoomFactor || pVOpt->GetZoomType() != eZoom ) | ||||||||
1272 | SetZoom( eZoom, nZoomFactor); | ||||||||
1273 | |||||||||
1274 | m_pWrtShell->LockView( true ); | ||||||||
1275 | m_pWrtShell->EndAction(); | ||||||||
1276 | m_pWrtShell->LockView( false ); | ||||||||
1277 | m_pWrtShell->EnableSmooth( true ); | ||||||||
1278 | } | ||||||||
1279 | |||||||||
1280 | void SwView::ReadUserDataSequence ( const uno::Sequence < beans::PropertyValue >& rSequence ) | ||||||||
1281 | { | ||||||||
1282 | if(GetDocShell()->IsPreview()||m_bIsPreviewDoubleClick) | ||||||||
1283 | return; | ||||||||
1284 | bool bIsOwnDocument = lcl_IsOwnDocument( *this ); | ||||||||
1285 | if (!rSequence.hasElements()) | ||||||||
1286 | return; | ||||||||
1287 | |||||||||
1288 | CurrShell aCurr(m_pWrtShell.get()); | ||||||||
1289 | const SwRect& rRect = m_pWrtShell->GetCharRect(); | ||||||||
1290 | const tools::Rectangle &rVis = GetVisArea(); | ||||||||
1291 | const SwViewOption* pVOpt = m_pWrtShell->GetViewOptions(); | ||||||||
1292 | |||||||||
1293 | sal_Int64 nX = rRect.Left(), nY = rRect.Top(), nLeft = rVis.Left(), nTop = rVis.Top(); | ||||||||
1294 | sal_Int64 nRight = nLeft; | ||||||||
1295 | sal_Int64 nBottom = LONG_MIN(-9223372036854775807L -1L); | ||||||||
1296 | sal_Int16 nZoomType = static_cast< sal_Int16 >(pVOpt->GetZoomType()); | ||||||||
1297 | sal_Int16 nZoomFactor = static_cast < sal_Int16 > (pVOpt->GetZoom()); | ||||||||
1298 | bool bViewLayoutBookMode = pVOpt->IsViewLayoutBookMode(); | ||||||||
1299 | sal_Int16 nViewLayoutColumns = pVOpt->GetViewLayoutColumns(); | ||||||||
1300 | |||||||||
1301 | bool bSelectedFrame = ( m_pWrtShell->GetSelFrameType() != FrameTypeFlags::NONE ), | ||||||||
1302 | bGotVisibleLeft = false, | ||||||||
1303 | bGotVisibleTop = false, bGotVisibleRight = false, | ||||||||
1304 | bGotVisibleBottom = false, bGotZoomType = false, | ||||||||
1305 | bGotZoomFactor = false, bGotIsSelectedFrame = false, | ||||||||
1306 | bGotViewLayoutColumns = false, bGotViewLayoutBookMode = false, | ||||||||
1307 | bBrowseMode = false, bGotBrowseMode = false; | ||||||||
1308 | |||||||||
1309 | for (const beans::PropertyValue& rValue : rSequence) | ||||||||
1310 | { | ||||||||
1311 | if ( rValue.Name == "ViewLeft" ) | ||||||||
1312 | { | ||||||||
1313 | rValue.Value >>= nX; | ||||||||
1314 | nX = convertMm100ToTwip( nX ); | ||||||||
1315 | } | ||||||||
1316 | else if ( rValue.Name == "ViewTop" ) | ||||||||
1317 | { | ||||||||
1318 | rValue.Value >>= nY; | ||||||||
1319 | nY = convertMm100ToTwip( nY ); | ||||||||
1320 | } | ||||||||
1321 | else if ( rValue.Name == "VisibleLeft" ) | ||||||||
1322 | { | ||||||||
1323 | rValue.Value >>= nLeft; | ||||||||
1324 | nLeft = convertMm100ToTwip( nLeft ); | ||||||||
1325 | bGotVisibleLeft = true; | ||||||||
1326 | } | ||||||||
1327 | else if ( rValue.Name == "VisibleTop" ) | ||||||||
1328 | { | ||||||||
1329 | rValue.Value >>= nTop; | ||||||||
1330 | nTop = convertMm100ToTwip( nTop ); | ||||||||
1331 | bGotVisibleTop = true; | ||||||||
1332 | } | ||||||||
1333 | else if ( rValue.Name == "VisibleRight" ) | ||||||||
1334 | { | ||||||||
1335 | rValue.Value >>= nRight; | ||||||||
1336 | nRight = convertMm100ToTwip( nRight ); | ||||||||
1337 | bGotVisibleRight = true; | ||||||||
1338 | } | ||||||||
1339 | else if ( rValue.Name == "VisibleBottom" ) | ||||||||
1340 | { | ||||||||
1341 | rValue.Value >>= nBottom; | ||||||||
1342 | nBottom = convertMm100ToTwip( nBottom ); | ||||||||
1343 | bGotVisibleBottom = true; | ||||||||
1344 | } | ||||||||
1345 | else if ( rValue.Name == "ZoomType" ) | ||||||||
1346 | { | ||||||||
1347 | rValue.Value >>= nZoomType; | ||||||||
1348 | bGotZoomType = true; | ||||||||
1349 | } | ||||||||
1350 | else if ( rValue.Name == "ZoomFactor" ) | ||||||||
1351 | { | ||||||||
1352 | rValue.Value >>= nZoomFactor; | ||||||||
1353 | bGotZoomFactor = true; | ||||||||
1354 | } | ||||||||
1355 | else if ( rValue.Name == "ViewLayoutColumns" ) | ||||||||
1356 | { | ||||||||
1357 | rValue.Value >>= nViewLayoutColumns; | ||||||||
1358 | bGotViewLayoutColumns = true; | ||||||||
1359 | } | ||||||||
1360 | else if ( rValue.Name == "ViewLayoutBookMode" ) | ||||||||
1361 | { | ||||||||
1362 | bViewLayoutBookMode = *o3tl::doAccess<bool>(rValue.Value); | ||||||||
1363 | bGotViewLayoutBookMode = true; | ||||||||
1364 | } | ||||||||
1365 | else if ( rValue.Name == "IsSelectedFrame" ) | ||||||||
1366 | { | ||||||||
1367 | rValue.Value >>= bSelectedFrame; | ||||||||
1368 | bGotIsSelectedFrame = true; | ||||||||
1369 | } | ||||||||
1370 | else if (rValue.Name == "ShowOnlineLayout") | ||||||||
1371 | { | ||||||||
1372 | rValue.Value >>= bBrowseMode; | ||||||||
1373 | bGotBrowseMode = true; | ||||||||
1374 | } | ||||||||
1375 | // Fallback to common SdrModel processing | ||||||||
1376 | else | ||||||||
1377 | GetDocShell()->GetDoc()->getIDocumentDrawModelAccess().GetDrawModel()->ReadUserDataSequenceValue(&rValue); | ||||||||
1378 | } | ||||||||
1379 | if (bGotBrowseMode) | ||||||||
1380 | { | ||||||||
1381 | // delegate further | ||||||||
1382 | GetViewImpl()->GetUNOObject_Impl()->getViewSettings()->setPropertyValue("ShowOnlineLayout", uno::Any(bBrowseMode)); | ||||||||
1383 | } | ||||||||
1384 | |||||||||
1385 | SelectShell(); | ||||||||
1386 | |||||||||
1387 | if (!bGotVisibleBottom) | ||||||||
1388 | return; | ||||||||
1389 | |||||||||
1390 | Point aCursorPos( nX, nY ); | ||||||||
1391 | const long nAdd = m_pWrtShell->GetViewOptions()->getBrowseMode() ? DOCUMENTBORDER284 : DOCUMENTBORDER284*2; | ||||||||
1392 | if (nBottom > (m_pWrtShell->GetDocSize().Height()+nAdd) ) | ||||||||
1393 | return; | ||||||||
1394 | |||||||||
1395 | m_pWrtShell->EnableSmooth( false ); | ||||||||
1396 | const tools::Rectangle aVis( nLeft, nTop, nRight, nBottom ); | ||||||||
1397 | |||||||||
1398 | SvxZoomType eZoom; | ||||||||
1399 | if ( !m_pWrtShell->GetViewOptions()->getBrowseMode() ) | ||||||||
1400 | eZoom = static_cast < SvxZoomType > ( nZoomType ); | ||||||||
1401 | else | ||||||||
1402 | { | ||||||||
1403 | eZoom = SvxZoomType::PERCENT; | ||||||||
1404 | } | ||||||||
1405 | if (bGotIsSelectedFrame) | ||||||||
1406 | { | ||||||||
1407 | bool bSelectObj = bSelectedFrame && m_pWrtShell->IsObjSelectable( aCursorPos ); | ||||||||
1408 | |||||||||
1409 | // set flag value to avoid macro execution. | ||||||||
1410 | bool bSavedFlagValue = m_pWrtShell->IsMacroExecAllowed(); | ||||||||
1411 | m_pWrtShell->SetMacroExecAllowed( false ); | ||||||||
1412 | // os: changed: The user data has to be read if the view is switched back from page preview | ||||||||
1413 | // go to the last editing position when opening own files | ||||||||
1414 | m_pViewImpl->SetRestorePosition(aCursorPos, bSelectObj); | ||||||||
1415 | if(m_bOldShellWasPagePreview|| bIsOwnDocument) | ||||||||
1416 | { | ||||||||
1417 | m_pWrtShell->SwCursorShell::SetCursor( aCursorPos, !bSelectObj ); | ||||||||
1418 | |||||||||
1419 | // Update the shell to toggle Header/Footer edit if needed | ||||||||
1420 | bool bInHeader = true; | ||||||||
1421 | if ( m_pWrtShell->IsInHeaderFooter( &bInHeader ) ) | ||||||||
1422 | { | ||||||||
1423 | if ( !bInHeader ) | ||||||||
1424 | { | ||||||||
1425 | m_pWrtShell->SetShowHeaderFooterSeparator( FrameControlType::Footer, true ); | ||||||||
1426 | m_pWrtShell->SetShowHeaderFooterSeparator( FrameControlType::Header, false ); | ||||||||
1427 | } | ||||||||
1428 | else | ||||||||
1429 | { | ||||||||
1430 | m_pWrtShell->SetShowHeaderFooterSeparator( FrameControlType::Header, true ); | ||||||||
1431 | m_pWrtShell->SetShowHeaderFooterSeparator( FrameControlType::Footer, false ); | ||||||||
1432 | } | ||||||||
1433 | |||||||||
1434 | // Force repaint | ||||||||
1435 | m_pWrtShell->GetWin()->Invalidate(); | ||||||||
1436 | } | ||||||||
1437 | if ( m_pWrtShell->IsInHeaderFooter() != m_pWrtShell->IsHeaderFooterEdit() ) | ||||||||
1438 | m_pWrtShell->ToggleHeaderFooterEdit(); | ||||||||
1439 | |||||||||
1440 | if( bSelectObj ) | ||||||||
1441 | { | ||||||||
1442 | m_pWrtShell->SelectObj( aCursorPos ); | ||||||||
1443 | m_pWrtShell->EnterSelFrameMode( &aCursorPos ); | ||||||||
1444 | } | ||||||||
1445 | } | ||||||||
1446 | |||||||||
1447 | // reset flag value | ||||||||
1448 | m_pWrtShell->SetMacroExecAllowed( bSavedFlagValue ); | ||||||||
1449 | } | ||||||||
1450 | |||||||||
1451 | // Set ViewLayoutSettings | ||||||||
1452 | const bool bSetViewLayoutSettings = bGotViewLayoutColumns && bGotViewLayoutBookMode && | ||||||||
1453 | ( pVOpt->GetViewLayoutColumns() != nViewLayoutColumns || pVOpt->IsViewLayoutBookMode() != bViewLayoutBookMode ); | ||||||||
1454 | |||||||||
1455 | const bool bSetViewSettings = bGotZoomType && bGotZoomFactor && | ||||||||
1456 | ( pVOpt->GetZoom() != nZoomFactor || pVOpt->GetZoomType() != eZoom ); | ||||||||
1457 | |||||||||
1458 | // In case we have a 'fixed' view layout of 2 or more columns, | ||||||||
1459 | // we have to apply the view options *before* starting the action. | ||||||||
1460 | // Otherwise the SetZoom function cannot work correctly, because | ||||||||
1461 | // the view layout hasn't been calculated. | ||||||||
1462 | const bool bZoomNeedsViewLayout = bSetViewLayoutSettings && | ||||||||
1463 | 1 < nViewLayoutColumns && | ||||||||
1464 | bSetViewSettings && | ||||||||
1465 | eZoom != SvxZoomType::PERCENT; | ||||||||
1466 | |||||||||
1467 | if ( !bZoomNeedsViewLayout ) | ||||||||
1468 | m_pWrtShell->StartAction(); | ||||||||
1469 | |||||||||
1470 | if ( bSetViewLayoutSettings ) | ||||||||
1471 | SetViewLayout( nViewLayoutColumns, bViewLayoutBookMode, true ); | ||||||||
1472 | |||||||||
1473 | if ( bZoomNeedsViewLayout ) | ||||||||
1474 | m_pWrtShell->StartAction(); | ||||||||
1475 | |||||||||
1476 | if ( bSetViewSettings ) | ||||||||
1477 | SetZoom( eZoom, nZoomFactor, true ); | ||||||||
1478 | |||||||||
1479 | // os: changed: The user data has to be read if the view is switched back from page preview | ||||||||
1480 | // go to the last editing position when opening own files | ||||||||
1481 | if(m_bOldShellWasPagePreview||bIsOwnDocument) | ||||||||
1482 | { | ||||||||
1483 | if ( bGotVisibleLeft && bGotVisibleTop ) | ||||||||
1484 | { | ||||||||
1485 | Point aTopLeft(aVis.TopLeft()); | ||||||||
1486 | // make sure the document is still centered | ||||||||
1487 | const SwTwips lBorder = IsDocumentBorder() ? DOCUMENTBORDER284 : 2 * DOCUMENTBORDER284; | ||||||||
1488 | SwTwips nEditWidth = GetEditWin().GetOutputSize().Width(); | ||||||||
1489 | if(nEditWidth > (m_aDocSz.Width() + lBorder )) | ||||||||
1490 | aTopLeft.setX( ( m_aDocSz.Width() + lBorder - nEditWidth ) / 2 ); | ||||||||
1491 | else | ||||||||
1492 | { | ||||||||
1493 | //check if the values are possible | ||||||||
1494 | long nXMax = m_pHScrollbar->GetRangeMax() - m_pHScrollbar->GetVisibleSize(); | ||||||||
1495 | if( aTopLeft.X() > nXMax ) | ||||||||
1496 | aTopLeft.setX( nXMax < 0 ? 0 : nXMax ); | ||||||||
1497 | } | ||||||||
1498 | SetVisArea( aTopLeft ); | ||||||||
1499 | } | ||||||||
1500 | else if (bGotVisibleLeft && bGotVisibleTop && bGotVisibleRight && bGotVisibleBottom ) | ||||||||
1501 | SetVisArea( aVis ); | ||||||||
1502 | } | ||||||||
1503 | |||||||||
1504 | m_pWrtShell->LockView( true ); | ||||||||
1505 | m_pWrtShell->EndAction(); | ||||||||
1506 | m_pWrtShell->LockView( false ); | ||||||||
1507 | m_pWrtShell->EnableSmooth( true ); | ||||||||
1508 | |||||||||
1509 | } | ||||||||
1510 | |||||||||
1511 | void SwView::WriteUserDataSequence ( uno::Sequence < beans::PropertyValue >& rSequence ) | ||||||||
1512 | { | ||||||||
1513 | const SwRect& rRect = m_pWrtShell->GetCharRect(); | ||||||||
1514 | const tools::Rectangle& rVis = GetVisArea(); | ||||||||
1515 | |||||||||
1516 | std::vector<beans::PropertyValue> aVector; | ||||||||
1517 | |||||||||
1518 | sal_uInt16 nViewID( GetViewFrame()->GetCurViewId()); | ||||||||
1519 | aVector.push_back(comphelper::makePropertyValue("ViewId", "view" + OUString::number(nViewID))); | ||||||||
1520 | |||||||||
1521 | aVector.push_back(comphelper::makePropertyValue("ViewLeft", convertTwipToMm100 ( rRect.Left() ))); | ||||||||
1522 | |||||||||
1523 | aVector.push_back(comphelper::makePropertyValue("ViewTop", convertTwipToMm100 ( rRect.Top() ))); | ||||||||
1524 | |||||||||
1525 | auto visibleLeft = convertTwipToMm100 ( rVis.Left() ); | ||||||||
1526 | aVector.push_back(comphelper::makePropertyValue("VisibleLeft", visibleLeft)); | ||||||||
1527 | |||||||||
1528 | auto visibleTop = convertTwipToMm100 ( rVis.Top() ); | ||||||||
1529 | aVector.push_back(comphelper::makePropertyValue("VisibleTop", visibleTop)); | ||||||||
1530 | |||||||||
1531 | auto visibleRight = rVis.IsWidthEmpty() ? visibleLeft : convertTwipToMm100 ( rVis.Right() ); | ||||||||
1532 | aVector.push_back(comphelper::makePropertyValue("VisibleRight", visibleRight)); | ||||||||
1533 | |||||||||
1534 | auto visibleBottom = rVis.IsHeightEmpty() ? visibleTop : convertTwipToMm100 ( rVis.Bottom() ); | ||||||||
1535 | aVector.push_back(comphelper::makePropertyValue("VisibleBottom", visibleBottom)); | ||||||||
1536 | |||||||||
1537 | const sal_Int16 nZoomType = static_cast< sal_Int16 >(m_pWrtShell->GetViewOptions()->GetZoomType()); | ||||||||
1538 | aVector.push_back(comphelper::makePropertyValue("ZoomType", nZoomType)); | ||||||||
1539 | |||||||||
1540 | const sal_Int16 nViewLayoutColumns = static_cast< sal_Int16 >(m_pWrtShell->GetViewOptions()->GetViewLayoutColumns()); | ||||||||
1541 | aVector.push_back(comphelper::makePropertyValue("ViewLayoutColumns", nViewLayoutColumns)); | ||||||||
1542 | |||||||||
1543 | aVector.push_back(comphelper::makePropertyValue("ViewLayoutBookMode", m_pWrtShell->GetViewOptions()->IsViewLayoutBookMode())); | ||||||||
1544 | |||||||||
1545 | aVector.push_back(comphelper::makePropertyValue("ZoomFactor", static_cast < sal_Int16 > (m_pWrtShell->GetViewOptions()->GetZoom()))); | ||||||||
1546 | |||||||||
1547 | aVector.push_back(comphelper::makePropertyValue("IsSelectedFrame", FrameTypeFlags::NONE != m_pWrtShell->GetSelFrameType())); | ||||||||
1548 | |||||||||
1549 | rSequence = comphelper::containerToSequence(aVector); | ||||||||
1550 | |||||||||
1551 | // Common SdrModel processing | ||||||||
1552 | GetDocShell()->GetDoc()->getIDocumentDrawModelAccess().GetDrawModel()->WriteUserDataSequence(rSequence); | ||||||||
1553 | } | ||||||||
1554 | |||||||||
1555 | void SwView::ShowCursor( bool bOn ) | ||||||||
1556 | { | ||||||||
1557 | //don't scroll the cursor into the visible area | ||||||||
1558 | bool bUnlockView = !m_pWrtShell->IsViewLocked(); | ||||||||
1559 | m_pWrtShell->LockView( true ); //lock visible section | ||||||||
1560 | |||||||||
1561 | if( !bOn ) | ||||||||
1562 | m_pWrtShell->HideCursor(); | ||||||||
1563 | else if( !m_pWrtShell->IsFrameSelected() && !m_pWrtShell->IsObjSelected() ) | ||||||||
1564 | m_pWrtShell->ShowCursor(); | ||||||||
1565 | |||||||||
1566 | if( bUnlockView ) | ||||||||
1567 | m_pWrtShell->LockView( false ); | ||||||||
1568 | } | ||||||||
1569 | |||||||||
1570 | ErrCode SwView::DoVerb( long nVerb ) | ||||||||
1571 | { | ||||||||
1572 | if ( !GetViewFrame()->GetFrame().IsInPlace() ) | ||||||||
1573 | { | ||||||||
1574 | SwWrtShell &rSh = GetWrtShell(); | ||||||||
1575 | const SelectionType nSel = rSh.GetSelectionType(); | ||||||||
1576 | if ( nSel & SelectionType::Ole ) | ||||||||
1577 | rSh.LaunchOLEObj( nVerb ); | ||||||||
1578 | } | ||||||||
1579 | return ERRCODE_NONEErrCode(0); | ||||||||
1580 | } | ||||||||
1581 | |||||||||
1582 | // only return true for a text selection | ||||||||
1583 | |||||||||
1584 | bool SwView::HasSelection( bool bText ) const | ||||||||
1585 | { | ||||||||
1586 | return bText ? GetWrtShell().SwCursorShell::HasSelection() | ||||||||
1587 | : GetWrtShell().HasSelection(); | ||||||||
1588 | } | ||||||||
1589 | |||||||||
1590 | OUString SwView::GetSelectionText( bool bCompleteWrds ) | ||||||||
1591 | { | ||||||||
1592 | return GetSelectionTextParam( bCompleteWrds, true ); | ||||||||
1593 | } | ||||||||
1594 | |||||||||
1595 | OUString SwView::GetSelectionTextParam( bool bCompleteWrds, bool bEraseTrail ) | ||||||||
1596 | { | ||||||||
1597 | OUString sReturn; | ||||||||
1598 | if( bCompleteWrds && !GetWrtShell().HasSelection() ) | ||||||||
1599 | GetWrtShell().SelWrd(); | ||||||||
1600 | |||||||||
1601 | GetWrtShell().GetSelectedText( sReturn ); | ||||||||
1602 | if( bEraseTrail ) | ||||||||
1603 | sReturn = comphelper::string::stripEnd(sReturn, ' '); | ||||||||
1604 | return sReturn; | ||||||||
1605 | } | ||||||||
1606 | |||||||||
1607 | SwGlossaryHdl* SwView::GetGlosHdl() | ||||||||
1608 | { | ||||||||
1609 | if(!m_pGlosHdl) | ||||||||
1610 | m_pGlosHdl.reset(new SwGlossaryHdl(GetViewFrame(), m_pWrtShell.get())); | ||||||||
1611 | return m_pGlosHdl.get(); | ||||||||
1612 | } | ||||||||
1613 | |||||||||
1614 | void SwView::Notify( SfxBroadcaster& rBC, const SfxHint& rHint ) | ||||||||
1615 | { | ||||||||
1616 | bool bCallBase = true; | ||||||||
1617 | if(dynamic_cast<const FmDesignModeChangedHint*>(&rHint)) | ||||||||
1618 | { | ||||||||
1619 | bool bDesignMode = static_cast<const FmDesignModeChangedHint&>(rHint).GetDesignMode(); | ||||||||
1620 | if (!bDesignMode && GetDrawFuncPtr()) | ||||||||
1621 | { | ||||||||
1622 | GetDrawFuncPtr()->Deactivate(); | ||||||||
1623 | SetDrawFuncPtr(nullptr); | ||||||||
1624 | LeaveDrawCreate(); | ||||||||
1625 | AttrChangedNotify(nullptr); | ||||||||
1626 | } | ||||||||
1627 | } | ||||||||
1628 | else | ||||||||
1629 | { | ||||||||
1630 | SfxHintId nId = rHint.GetId(); | ||||||||
1631 | switch ( nId ) | ||||||||
1632 | { | ||||||||
1633 | // sub shells will be destroyed by the | ||||||||
1634 | // dispatcher, if the view frame is dying. Thus, reset member <pShell>. | ||||||||
1635 | case SfxHintId::Dying: | ||||||||
1636 | { | ||||||||
1637 | if ( &rBC == GetViewFrame() ) | ||||||||
1638 | { | ||||||||
1639 | ResetSubShell(); | ||||||||
1640 | } | ||||||||
1641 | } | ||||||||
1642 | break; | ||||||||
1643 | case SfxHintId::ModeChanged: | ||||||||
1644 | { | ||||||||
1645 | // Modal mode change-over? | ||||||||
1646 | bool bModal = GetDocShell()->IsInModalMode(); | ||||||||
1647 | m_pHRuler->SetActive( !bModal ); | ||||||||
1648 | m_pVRuler->SetActive( !bModal ); | ||||||||
1649 | } | ||||||||
1650 | |||||||||
1651 | [[fallthrough]]; | ||||||||
1652 | |||||||||
1653 | case SfxHintId::TitleChanged: | ||||||||
1654 | if ( GetDocShell()->IsReadOnly() != GetWrtShell().GetViewOptions()->IsReadonly() ) | ||||||||
1655 | { | ||||||||
1656 | SwWrtShell &rSh = GetWrtShell(); | ||||||||
1657 | rSh.SetReadonlyOption( GetDocShell()->IsReadOnly() ); | ||||||||
1658 | |||||||||
1659 | if ( rSh.GetViewOptions()->IsViewVRuler() ) | ||||||||
1660 | CreateVRuler(); | ||||||||
1661 | else | ||||||||
1662 | KillVRuler(); | ||||||||
1663 | if ( rSh.GetViewOptions()->IsViewHRuler() ) | ||||||||
1664 | CreateTab(); | ||||||||
1665 | else | ||||||||
1666 | KillTab(); | ||||||||
1667 | bool bReadonly = GetDocShell()->IsReadOnly(); | ||||||||
1668 | // if document is to be opened in alive-mode then this has to be | ||||||||
1669 | // regarded while switching from readonly-mode to edit-mode | ||||||||
1670 | if( !bReadonly ) | ||||||||
1671 | { | ||||||||
1672 | SwDrawModel * pDrawDoc = GetDocShell()->GetDoc()->getIDocumentDrawModelAccess().GetDrawModel(); | ||||||||
1673 | if (pDrawDoc) | ||||||||
1674 | { | ||||||||
1675 | if( !pDrawDoc->GetOpenInDesignMode() ) | ||||||||
1676 | break;// don't touch the design mode | ||||||||
1677 | } | ||||||||
1678 | } | ||||||||
1679 | SfxBoolItem aItem( SID_FM_DESIGN_MODE( 10000 + 629 ), !bReadonly); | ||||||||
1680 | GetDispatcher().ExecuteList(SID_FM_DESIGN_MODE( 10000 + 629 ), | ||||||||
1681 | SfxCallMode::ASYNCHRON, { &aItem }); | ||||||||
1682 | } | ||||||||
1683 | break; | ||||||||
1684 | |||||||||
1685 | case SfxHintId::SwDrawViewsCreated: | ||||||||
1686 | { | ||||||||
1687 | bCallBase = false; | ||||||||
1688 | if ( GetFormShell() ) | ||||||||
1689 | { | ||||||||
1690 | GetFormShell()->SetView(dynamic_cast<FmFormView*>(GetWrtShell().GetDrawView())); | ||||||||
1691 | SfxBoolItem aItem( SID_FM_DESIGN_MODE( 10000 + 629 ), !GetDocShell()->IsReadOnly()); | ||||||||
1692 | GetDispatcher().ExecuteList(SID_FM_DESIGN_MODE( 10000 + 629 ), | ||||||||
1693 | SfxCallMode::SYNCHRON, { &aItem }); | ||||||||
1694 | } | ||||||||
1695 | } | ||||||||
1696 | break; | ||||||||
1697 | case SfxHintId::RedlineChanged: | ||||||||
1698 | { | ||||||||
1699 | static sal_uInt16 const aSlotRedLine[] = { | ||||||||
1700 | FN_REDLINE_ACCEPT_DIRECT((20000 + 1800) + 37), | ||||||||
1701 | FN_REDLINE_REJECT_DIRECT((20000 + 1800) + 38), | ||||||||
1702 | FN_REDLINE_NEXT_CHANGE((20000 + 1800) + 41), | ||||||||
1703 | FN_REDLINE_PREV_CHANGE((20000 + 1800) + 42), | ||||||||
1704 | FN_REDLINE_ACCEPT_ALL((20000 + 1800) + 43), | ||||||||
1705 | FN_REDLINE_REJECT_ALL((20000 + 1800) + 44), | ||||||||
1706 | 0 | ||||||||
1707 | }; | ||||||||
1708 | GetViewFrame()->GetBindings().Invalidate(aSlotRedLine); | ||||||||
1709 | } | ||||||||
1710 | break; | ||||||||
1711 | |||||||||
1712 | default: break; | ||||||||
1713 | } | ||||||||
1714 | } | ||||||||
1715 | |||||||||
1716 | if ( bCallBase ) | ||||||||
1717 | SfxViewShell::Notify(rBC, rHint); | ||||||||
1718 | } | ||||||||
1719 | |||||||||
1720 | #if defined(_WIN32) || defined UNX1 | ||||||||
1721 | |||||||||
1722 | void SwView::ScannerEventHdl() | ||||||||
1723 | { | ||||||||
1724 | uno::Reference< XScannerManager2 > xScanMgr = SW_MOD()( static_cast<SwModule*>(SfxApplication::GetModule(SfxToolsModule ::Writer)))->GetScannerManager(); | ||||||||
1725 | if( xScanMgr.is() ) | ||||||||
1726 | { | ||||||||
1727 | const ScannerContext aContext( xScanMgr->getAvailableScanners().getConstArray()[ 0 ] ); | ||||||||
1728 | const ScanError eError = xScanMgr->getError( aContext ); | ||||||||
1729 | |||||||||
1730 | if( ScanError_ScanErrorNone == eError ) | ||||||||
1731 | { | ||||||||
1732 | const uno::Reference< awt::XBitmap > xBitmap( xScanMgr->getBitmap( aContext ) ); | ||||||||
1733 | |||||||||
1734 | if( xBitmap.is() ) | ||||||||
1735 | { | ||||||||
1736 | const BitmapEx aScanBmp( VCLUnoHelper::GetBitmap( xBitmap ) ); | ||||||||
1737 | |||||||||
1738 | if( !!aScanBmp ) | ||||||||
1739 | { | ||||||||
1740 | Graphic aGrf(aScanBmp); | ||||||||
1741 | m_pWrtShell->Insert( OUString(), OUString(), aGrf ); | ||||||||
1742 | } | ||||||||
1743 | } | ||||||||
1744 | } | ||||||||
1745 | } | ||||||||
1746 | SfxBindings& rBind = GetViewFrame()->GetBindings(); | ||||||||
1747 | rBind.Invalidate( SID_TWAIN_SELECT( 10000 + 331 ) ); | ||||||||
1748 | rBind.Invalidate( SID_TWAIN_TRANSFER( 10000 + 332 ) ); | ||||||||
1749 | } | ||||||||
1750 | #endif | ||||||||
1751 | |||||||||
1752 | void SwView::StopShellTimer() | ||||||||
1753 | { | ||||||||
1754 | if(m_aTimer.IsActive()) | ||||||||
1755 | { | ||||||||
1756 | m_aTimer.Stop(); | ||||||||
1757 | if ( m_bAttrChgNotifiedWithRegistrations ) | ||||||||
1758 | { | ||||||||
1759 | GetViewFrame()->GetBindings().LEAVEREGISTRATIONS()LeaveRegistrations(); | ||||||||
1760 | m_bAttrChgNotifiedWithRegistrations = false; | ||||||||
1761 | } | ||||||||
1762 | SelectShell(); | ||||||||
1763 | m_bAttrChgNotified = false; | ||||||||
1764 | } | ||||||||
1765 | } | ||||||||
1766 | |||||||||
1767 | bool SwView::PrepareClose( bool bUI ) | ||||||||
1768 | { | ||||||||
1769 | SfxViewFrame* pVFrame = GetViewFrame(); | ||||||||
1770 | pVFrame->SetChildWindow( SwInputChild::GetChildWindowId(), false ); | ||||||||
1771 | if( pVFrame->GetDispatcher()->IsLocked() ) | ||||||||
1772 | pVFrame->GetDispatcher()->Lock(false); | ||||||||
1773 | |||||||||
1774 | if ( m_pFormShell && !m_pFormShell->PrepareClose( bUI ) ) | ||||||||
1775 | { | ||||||||
1776 | return false; | ||||||||
1777 | } | ||||||||
1778 | return SfxViewShell::PrepareClose( bUI ); | ||||||||
1779 | } | ||||||||
1780 | |||||||||
1781 | // status methods for clipboard. | ||||||||
1782 | // Status changes now notified from the clipboard. | ||||||||
1783 | bool SwView::IsPasteAllowed() | ||||||||
1784 | { | ||||||||
1785 | SotExchangeDest nPasteDestination = SwTransferable::GetSotDestination( *m_pWrtShell ); | ||||||||
1786 | if( m_nLastPasteDestination != nPasteDestination ) | ||||||||
1787 | { | ||||||||
1788 | TransferableDataHelper aDataHelper( | ||||||||
1789 | TransferableDataHelper::CreateFromSystemClipboard( | ||||||||
1790 | &GetEditWin()) ); | ||||||||
1791 | if( aDataHelper.GetXTransferable().is() ) | ||||||||
1792 | { | ||||||||
1793 | m_bPasteState = SwTransferable::IsPaste( *m_pWrtShell, aDataHelper ); | ||||||||
1794 | m_bPasteSpecialState = SwTransferable::IsPasteSpecial( | ||||||||
1795 | *m_pWrtShell, aDataHelper ); | ||||||||
1796 | } | ||||||||
1797 | else | ||||||||
1798 | m_bPasteState = m_bPasteSpecialState = false; | ||||||||
1799 | |||||||||
1800 | if( static_cast<SotExchangeDest>(0xFFFF) == m_nLastPasteDestination ) // the init value | ||||||||
1801 | m_pViewImpl->AddClipboardListener(); | ||||||||
1802 | m_nLastPasteDestination = nPasteDestination; | ||||||||
1803 | } | ||||||||
1804 | return m_bPasteState; | ||||||||
1805 | } | ||||||||
1806 | |||||||||
1807 | bool SwView::IsPasteSpecialAllowed() | ||||||||
1808 | { | ||||||||
1809 | if ( m_pFormShell && m_pFormShell->IsActiveControl() ) | ||||||||
1810 | return false; | ||||||||
1811 | |||||||||
1812 | SotExchangeDest nPasteDestination = SwTransferable::GetSotDestination( *m_pWrtShell ); | ||||||||
1813 | if( m_nLastPasteDestination != nPasteDestination ) | ||||||||
1814 | { | ||||||||
1815 | TransferableDataHelper aDataHelper( | ||||||||
1816 | TransferableDataHelper::CreateFromSystemClipboard( | ||||||||
1817 | &GetEditWin()) ); | ||||||||
1818 | if( aDataHelper.GetXTransferable().is() ) | ||||||||
1819 | { | ||||||||
1820 | m_bPasteState = SwTransferable::IsPaste( *m_pWrtShell, aDataHelper ); | ||||||||
1821 | m_bPasteSpecialState = SwTransferable::IsPasteSpecial( | ||||||||
1822 | *m_pWrtShell, aDataHelper ); | ||||||||
1823 | } | ||||||||
1824 | else | ||||||||
1825 | m_bPasteState = m_bPasteSpecialState = false; | ||||||||
1826 | |||||||||
1827 | if( static_cast<SotExchangeDest>(0xFFFF) == m_nLastPasteDestination ) // the init value | ||||||||
1828 | m_pViewImpl->AddClipboardListener(); | ||||||||
1829 | } | ||||||||
1830 | return m_bPasteSpecialState; | ||||||||
1831 | } | ||||||||
1832 | |||||||||
1833 | bool SwView::IsPasteSpreadsheet(bool bHasOwnTableCopied) | ||||||||
1834 | { | ||||||||
1835 | TransferableDataHelper aDataHelper( | ||||||||
1836 | TransferableDataHelper::CreateFromSystemClipboard( | ||||||||
1837 | &GetEditWin()) ); | ||||||||
1838 | if( aDataHelper.GetXTransferable().is() ) | ||||||||
1839 | { | ||||||||
1840 | if (bHasOwnTableCopied && SwTransferable::IsPasteOwnFormat( aDataHelper )) | ||||||||
1841 | return true; | ||||||||
1842 | return aDataHelper.HasFormat( SotClipboardFormatId::SYLK ) || aDataHelper.HasFormat( SotClipboardFormatId::SYLK_BIGCAPS ); | ||||||||
1843 | } | ||||||||
1844 | return false; | ||||||||
1845 | } | ||||||||
1846 | |||||||||
1847 | void SwView::NotifyDBChanged() | ||||||||
1848 | { | ||||||||
1849 | GetViewImpl()->GetUNOObject_Impl()->NotifyDBChanged(); | ||||||||
1850 | } | ||||||||
1851 | |||||||||
1852 | // Printing | ||||||||
1853 | |||||||||
1854 | SfxObjectShellLock SwView::CreateTmpSelectionDoc() | ||||||||
1855 | { | ||||||||
1856 | SwXTextView *const pTempImpl = GetViewImpl()->GetUNOObject_Impl(); | ||||||||
1857 | return pTempImpl->BuildTmpSelectionDoc(); | ||||||||
1858 | } | ||||||||
1859 | |||||||||
1860 | void SwView::AddTransferable(SwTransferable& rTransferable) | ||||||||
1861 | { | ||||||||
1862 | GetViewImpl()->AddTransferable(rTransferable); | ||||||||
1863 | } | ||||||||
1864 | |||||||||
1865 | namespace sw { | ||||||||
1866 | |||||||||
1867 | void InitPrintOptionsFromApplication(SwPrintData & o_rData, bool const bWeb) | ||||||||
1868 | { | ||||||||
1869 | o_rData = *SW_MOD()( static_cast<SwModule*>(SfxApplication::GetModule(SfxToolsModule ::Writer)))->GetPrtOptions(bWeb); | ||||||||
1870 | } | ||||||||
1871 | |||||||||
1872 | } // namespace sw | ||||||||
1873 | |||||||||
1874 | /* 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 |