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 <comphelper/processfactory.hxx> | |||
21 | ||||
22 | #include <ViewShellBase.hxx> | |||
23 | #include <algorithm> | |||
24 | #include <EventMultiplexer.hxx> | |||
25 | #include <cache/SlsPageCacheManager.hxx> | |||
26 | #include <app.hrc> | |||
27 | #include <slideshow.hxx> | |||
28 | #include <unokywds.hxx> | |||
29 | #include <svx/svxids.hrc> | |||
30 | #include <DrawDocShell.hxx> | |||
31 | #include <ViewShellManager.hxx> | |||
32 | #include <DrawController.hxx> | |||
33 | #include <FrameView.hxx> | |||
34 | #include <ViewTabBar.hxx> | |||
35 | #include <sfx2/event.hxx> | |||
36 | #include <drawdoc.hxx> | |||
37 | #include <sdpage.hxx> | |||
38 | #include <sfx2/dispatch.hxx> | |||
39 | #include <sfx2/request.hxx> | |||
40 | #include <sfx2/printer.hxx> | |||
41 | #include <DrawViewShell.hxx> | |||
42 | #include <FormShellManager.hxx> | |||
43 | #include <ToolBarManager.hxx> | |||
44 | #include <Window.hxx> | |||
45 | #include <framework/ConfigurationController.hxx> | |||
46 | #include <DocumentRenderer.hxx> | |||
47 | #include <optsitem.hxx> | |||
48 | #include <sdmod.hxx> | |||
49 | ||||
50 | #include <com/sun/star/document/XViewDataSupplier.hpp> | |||
51 | #include <com/sun/star/container/XIndexAccess.hpp> | |||
52 | #include <com/sun/star/drawing/XDrawPagesSupplier.hpp> | |||
53 | #include <com/sun/star/drawing/XMasterPagesSupplier.hpp> | |||
54 | #include <com/sun/star/drawing/framework/XControllerManager.hpp> | |||
55 | #include <com/sun/star/drawing/framework/XConfigurationController.hpp> | |||
56 | #include <com/sun/star/drawing/framework/ResourceId.hpp> | |||
57 | #include <framework/FrameworkHelper.hxx> | |||
58 | ||||
59 | #include <sal/log.hxx> | |||
60 | #include <rtl/ref.hxx> | |||
61 | #include <sfx2/msg.hxx> | |||
62 | #include <sfx2/objface.hxx> | |||
63 | #include <sfx2/viewfrm.hxx> | |||
64 | #include <svl/whiter.hxx> | |||
65 | #include <vcl/commandinfoprovider.hxx> | |||
66 | #include <vcl/settings.hxx> | |||
67 | #include <vcl/svapp.hxx> | |||
68 | ||||
69 | #include <sfx2/notebookbar/SfxNotebookBar.hxx> | |||
70 | ||||
71 | #include <tools/diagnose_ex.h> | |||
72 | #include <sfx2/lokhelper.hxx> | |||
73 | #include <LibreOfficeKit/LibreOfficeKitEnums.h> | |||
74 | #include <editeng/editview.hxx> | |||
75 | #include <tools/svborder.hxx> | |||
76 | ||||
77 | #include <fubullet.hxx> | |||
78 | #include <drawview.hxx> | |||
79 | ||||
80 | using namespace sd; | |||
81 | #define ShellClass_ViewShellBase | |||
82 | #include <sdslots.hxx> | |||
83 | ||||
84 | using ::sd::framework::FrameworkHelper; | |||
85 | ||||
86 | using namespace com::sun::star; | |||
87 | using namespace com::sun::star::beans; | |||
88 | using namespace com::sun::star::container; | |||
89 | using namespace com::sun::star::drawing::framework; | |||
90 | using namespace com::sun::star::lang; | |||
91 | using namespace com::sun::star::uno; | |||
92 | ||||
93 | namespace { | |||
94 | ||||
95 | class CurrentPageSetter | |||
96 | { | |||
97 | public: | |||
98 | explicit CurrentPageSetter (ViewShellBase& rBase); | |||
99 | void operator () (bool); | |||
100 | private: | |||
101 | ViewShellBase& mrBase; | |||
102 | }; | |||
103 | ||||
104 | } // end of anonymous namespace | |||
105 | ||||
106 | namespace sd { | |||
107 | ||||
108 | class ViewShellBase::Implementation | |||
109 | { | |||
110 | public: | |||
111 | /** Main controller of the view shell. During the switching from one | |||
112 | stacked shell to another this pointer may be NULL. | |||
113 | */ | |||
114 | ::rtl::Reference<DrawController> mpController; | |||
115 | ||||
116 | /** The view tab bar is the control for switching between different | |||
117 | views in one pane. | |||
118 | */ | |||
119 | ::rtl::Reference<ViewTabBar> mpViewTabBar; | |||
120 | ||||
121 | // contains the complete area of the current view relative to the frame window | |||
122 | ::tools::Rectangle maClientArea; | |||
123 | ||||
124 | // This is set to true when PrepareClose() is called. | |||
125 | bool mbIsClosing; | |||
126 | ||||
127 | /** The view window is the parent of all UI elements that belong to the | |||
128 | view or ViewShell. This comprises the rulers, the scroll bars, and | |||
129 | the content window. | |||
130 | It does not include the ViewTabBar. | |||
131 | */ | |||
132 | VclPtr<vcl::Window> mpViewWindow; | |||
133 | std::shared_ptr<ToolBarManager> mpToolBarManager; | |||
134 | std::shared_ptr<ViewShellManager> mpViewShellManager; | |||
135 | std::shared_ptr<tools::EventMultiplexer> mpEventMultiplexer; | |||
136 | std::shared_ptr<FormShellManager> mpFormShellManager; | |||
137 | ||||
138 | explicit Implementation (ViewShellBase& rBase); | |||
139 | ~Implementation(); | |||
140 | ||||
141 | void LateInit(); | |||
142 | ||||
143 | /** Show or hide the ViewTabBar. | |||
144 | @param bShow | |||
145 | When <TRUE/> then the ViewTabBar is shown, otherwise it is hidden. | |||
146 | */ | |||
147 | void ShowViewTabBar (bool bShow); | |||
148 | ||||
149 | void SetUserWantsTabBar(bool inValue); | |||
150 | bool GetUserWantsTabBar() const { return mbUserWantsTabBar; } | |||
151 | ||||
152 | /** Common code of ViewShellBase::OuterResizePixel() and | |||
153 | ViewShellBase::InnerResizePixel(). | |||
154 | */ | |||
155 | void ResizePixel ( | |||
156 | const Point& rOrigin, | |||
157 | const Size& rSize, | |||
158 | bool bOuterResize); | |||
159 | ||||
160 | /** Show or hide the specified pane. The visibility state is taken | |||
161 | from the given request. | |||
162 | @param rRequest | |||
163 | The request determines the new visibility state. The state can | |||
164 | either be toggled or be set to a given value. | |||
165 | @param rsPaneURL | |||
166 | This URL specifies the pane whose visibility state to set. | |||
167 | @param rsViewURL | |||
168 | When the pane becomes visible then this view URL specifies which | |||
169 | type of view to show in it. | |||
170 | */ | |||
171 | void SetPaneVisibility ( | |||
172 | const SfxRequest& rRequest, | |||
173 | const OUString& rsPaneURL, | |||
174 | const OUString& rsViewURL); | |||
175 | ||||
176 | void GetSlotState (SfxItemSet& rSet); | |||
177 | ||||
178 | void ProcessRestoreEditingViewSlot(); | |||
179 | ||||
180 | private: | |||
181 | ViewShellBase& mrBase; | |||
182 | bool mbUserWantsTabBar; | |||
183 | bool mbTabBarShouldBeVisible; | |||
184 | /** Hold a reference to the page cache manager of the slide sorter in | |||
185 | order to ensure that it stays alive while the ViewShellBase is | |||
186 | alive. | |||
187 | */ | |||
188 | std::shared_ptr<slidesorter::cache::PageCacheManager> mpPageCacheManager; | |||
189 | }; | |||
190 | ||||
191 | namespace { | |||
192 | /** The only task of this window is to forward key presses to the content | |||
193 | window of the main view shell. With the key press it forwards the focus | |||
194 | so that it is not called very often. | |||
195 | */ | |||
196 | class FocusForwardingWindow : public vcl::Window | |||
197 | { | |||
198 | public: | |||
199 | FocusForwardingWindow (vcl::Window& rParentWindow, ViewShellBase& rBase); | |||
200 | virtual ~FocusForwardingWindow() override; | |||
201 | virtual void dispose() override; | |||
202 | virtual void KeyInput (const KeyEvent& rEvent) override; | |||
203 | virtual void Command (const CommandEvent& rEvent) override; | |||
204 | ||||
205 | private: | |||
206 | ViewShellBase& mrBase; | |||
207 | }; | |||
208 | } // end of anonymous namespace | |||
209 | ||||
210 | //===== ViewShellBase ========================================================= | |||
211 | ||||
212 | ||||
213 | // We have to expand the SFX_IMPL_VIEWFACTORY macro to call LateInit() after a | |||
214 | // new ViewShellBase object has been constructed. | |||
215 | ||||
216 | SFX_IMPL_SUPERCLASS_INTERFACE(ViewShellBase, SfxViewShell)SfxInterface* ViewShellBase::pInterface = nullptr; SfxInterface * ViewShellBase::GetStaticInterface() { if ( !pInterface ) { pInterface = new SfxInterface( "ViewShellBase", true, GetInterfaceId(), SfxViewShell::GetStaticInterface(), aViewShellBaseSlots_Impl [0], sal_uInt16(sizeof(aViewShellBaseSlots_Impl) / sizeof(SfxSlot ) ) ); InitInterface_Impl(); } return pInterface; } SfxInterface * ViewShellBase::GetInterface() const { return GetStaticInterface (); } void ViewShellBase::RegisterInterface(const SfxModule* pMod ) { GetStaticInterface()->Register(pMod); } | |||
217 | ||||
218 | void ViewShellBase::InitInterface_Impl() | |||
219 | { | |||
220 | } | |||
221 | ||||
222 | ViewShellBase::ViewShellBase ( | |||
223 | SfxViewFrame* _pFrame, | |||
224 | SfxViewShell*) | |||
225 | : SfxViewShell (_pFrame, SfxViewShellFlags::HAS_PRINTOPTIONS), | |||
226 | mpImpl(), | |||
227 | mpDocShell (nullptr), | |||
228 | mpDocument (nullptr) | |||
229 | { | |||
230 | mpImpl.reset(new Implementation(*this)); | |||
231 | mpImpl->mpViewWindow = VclPtr<FocusForwardingWindow>::Create(_pFrame->GetWindow(),*this); | |||
232 | mpImpl->mpViewWindow->SetBackground(Wallpaper()); | |||
233 | ||||
234 | _pFrame->GetWindow().SetBackground(Application::GetSettings().GetStyleSettings().GetLightColor()); | |||
235 | ||||
236 | // Set up the members in the correct order. | |||
237 | if (nullptr != dynamic_cast< DrawDocShell *>( GetViewFrame()->GetObjectShell() )) | |||
238 | mpDocShell = static_cast<DrawDocShell*>( | |||
239 | GetViewFrame()->GetObjectShell()); | |||
240 | if (mpDocShell != nullptr) | |||
241 | mpDocument = mpDocShell->GetDoc(); | |||
242 | mpImpl->mpViewShellManager = std::make_shared<ViewShellManager>(*this); | |||
243 | ||||
244 | SetWindow(mpImpl->mpViewWindow.get()); | |||
245 | ||||
246 | // Hide the window to avoid complaints from Sfx...SwitchViewShell... | |||
247 | _pFrame->GetWindow().Hide(); | |||
248 | } | |||
249 | ||||
250 | /** In this destructor the order in which some of the members are destroyed | |||
251 | (and/or being prepared to being destroyed) is important. Change it only | |||
252 | when you know what you are doing. | |||
253 | */ | |||
254 | ViewShellBase::~ViewShellBase() | |||
255 | { | |||
256 | // Notify other LOK views that we are going away. | |||
257 | SfxLokHelper::notifyOtherViews(this, LOK_CALLBACK_VIEW_CURSOR_VISIBLE, "visible", "false"); | |||
258 | SfxLokHelper::notifyOtherViews(this, LOK_CALLBACK_TEXT_VIEW_SELECTION, "selection", ""); | |||
259 | SfxLokHelper::notifyOtherViews(this, LOK_CALLBACK_GRAPHIC_VIEW_SELECTION, "selection", "EMPTY"); | |||
260 | ||||
261 | sfx2::SfxNotebookBar::CloseMethod(GetFrame()->GetBindings()); | |||
262 | ||||
263 | rtl::Reference<SlideShow> xSlideShow(SlideShow::GetSlideShow(*this)); | |||
264 | if (xSlideShow.is() && xSlideShow->dependsOn(this)) | |||
265 | SlideShow::Stop(*this); | |||
266 | xSlideShow.clear(); | |||
267 | ||||
268 | // Tell the controller that the ViewShellBase is not available anymore. | |||
269 | if (mpImpl->mpController) | |||
270 | mpImpl->mpController->ReleaseViewShellBase(); | |||
271 | ||||
272 | // We have to hide the main window to prevent SFX complaining after a | |||
273 | // reload about it being already visible. | |||
274 | ViewShell* pShell = GetMainViewShell().get(); | |||
275 | if (pShell!=nullptr | |||
276 | && pShell->GetActiveWindow()!=nullptr | |||
277 | && pShell->GetActiveWindow()->GetParent()!=nullptr) | |||
278 | { | |||
279 | pShell->GetActiveWindow()->GetParent()->Hide(); | |||
280 | } | |||
281 | ||||
282 | mpImpl->mpToolBarManager->Shutdown(); | |||
283 | mpImpl->mpViewShellManager->Shutdown(); | |||
284 | ||||
285 | EndListening(*GetViewFrame()); | |||
286 | EndListening(*GetDocShell()); | |||
287 | ||||
288 | SetWindow(nullptr); | |||
289 | ||||
290 | mpImpl->mpFormShellManager.reset(); | |||
291 | } | |||
292 | ||||
293 | void ViewShellBase::LateInit (const OUString& rsDefaultView) | |||
294 | { | |||
295 | StartListening(*GetViewFrame(), DuplicateHandling::Prevent); | |||
296 | StartListening(*GetDocShell(), DuplicateHandling::Prevent); | |||
297 | mpImpl->LateInit(); | |||
298 | InitializeFramework(); | |||
299 | ||||
300 | mpImpl->mpEventMultiplexer = std::make_shared<tools::EventMultiplexer>(*this); | |||
301 | ||||
302 | mpImpl->mpFormShellManager = std::make_shared<FormShellManager>(*this); | |||
303 | ||||
304 | mpImpl->mpToolBarManager = ToolBarManager::Create( | |||
305 | *this, | |||
306 | mpImpl->mpEventMultiplexer, | |||
307 | mpImpl->mpViewShellManager); | |||
308 | ||||
309 | try | |||
310 | { | |||
311 | Reference<XControllerManager> xControllerManager (GetDrawController(), UNO_QUERY_THROW); | |||
312 | Reference<XConfigurationController> xConfigurationController ( | |||
313 | xControllerManager->getConfigurationController()); | |||
314 | if (xConfigurationController.is()) | |||
315 | { | |||
316 | OUString sView (rsDefaultView); | |||
317 | if (sView.isEmpty()) | |||
318 | sView = GetInitialViewShellType(); | |||
319 | ||||
320 | FrameworkHelper::Instance(*this); | |||
321 | ||||
322 | // Create the resource ids for the center pane and view. | |||
323 | const Reference<drawing::framework::XResourceId> xCenterPaneId ( | |||
324 | FrameworkHelper::CreateResourceId(FrameworkHelper::msCenterPaneURL)); | |||
325 | const Reference<drawing::framework::XResourceId> xCenterViewId ( | |||
326 | FrameworkHelper::CreateResourceId(sView, xCenterPaneId)); | |||
327 | ||||
328 | // Request center pane and view. | |||
329 | xConfigurationController->requestResourceActivation(xCenterPaneId, ResourceActivationMode_ADD); | |||
330 | xConfigurationController->requestResourceActivation(xCenterViewId, ResourceActivationMode_REPLACE); | |||
331 | ||||
332 | // Process configuration events synchronously until the center view | |||
333 | // has been created. | |||
334 | sd::framework::ConfigurationController* pConfigurationController | |||
335 | = dynamic_cast<sd::framework::ConfigurationController*>(xConfigurationController.get()); | |||
336 | if (pConfigurationController != nullptr) | |||
337 | { | |||
338 | while ( | |||
339 | ! pConfigurationController->getResource(xCenterViewId).is() | |||
340 | && pConfigurationController->hasPendingRequests()) | |||
341 | { | |||
342 | pConfigurationController->ProcessEvent(); | |||
343 | } | |||
344 | } | |||
345 | } | |||
346 | } | |||
347 | catch (const RuntimeException&) | |||
348 | { | |||
349 | } | |||
350 | ||||
351 | // AutoLayouts have to be ready. | |||
352 | GetDocument()->StopWorkStartupDelay(); | |||
353 | ||||
354 | UpdateBorder(); | |||
355 | ||||
356 | // Remember the type of the current main view shell in the frame view. | |||
357 | ViewShell* pViewShell = GetMainViewShell().get(); | |||
358 | if (pViewShell != nullptr) | |||
359 | { | |||
360 | FrameView* pFrameView = pViewShell->GetFrameView(); | |||
361 | if (pFrameView != nullptr) | |||
362 | pFrameView->SetViewShellTypeOnLoad(pViewShell->GetShellType()); | |||
363 | } | |||
364 | // Show/Hide the TabBar | |||
365 | SdOptions* pOptions = SD_MOD()( static_cast<SdModule*>(SfxApplication::GetModule(SfxToolsModule ::Draw)) )->GetSdOptions(GetDocument()->GetDocumentType()); | |||
366 | bool bIsTabBarVisible = pOptions->IsTabBarVisible(); | |||
367 | mpImpl->SetUserWantsTabBar( bIsTabBarVisible ); | |||
368 | } | |||
369 | ||||
370 | std::shared_ptr<ViewShellManager> const & ViewShellBase::GetViewShellManager() const | |||
371 | { | |||
372 | return mpImpl->mpViewShellManager; | |||
373 | } | |||
374 | ||||
375 | std::shared_ptr<ViewShell> ViewShellBase::GetMainViewShell() const | |||
376 | { | |||
377 | std::shared_ptr<ViewShell> pMainViewShell ( | |||
378 | framework::FrameworkHelper::Instance(*const_cast<ViewShellBase*>(this)) | |||
379 | ->GetViewShell(framework::FrameworkHelper::msCenterPaneURL)); | |||
380 | if (pMainViewShell == nullptr) | |||
381 | pMainViewShell = framework::FrameworkHelper::Instance(*const_cast<ViewShellBase*>(this)) | |||
382 | ->GetViewShell(framework::FrameworkHelper::msFullScreenPaneURL); | |||
383 | return pMainViewShell; | |||
384 | } | |||
385 | ||||
386 | ViewShellBase* ViewShellBase::GetViewShellBase (SfxViewFrame const * pViewFrame) | |||
387 | { | |||
388 | ViewShellBase* pBase = nullptr; | |||
389 | ||||
390 | if (pViewFrame != nullptr) | |||
391 | { | |||
392 | // Get the view shell for the frame and cast it to | |||
393 | // sd::ViewShellBase. | |||
394 | SfxViewShell* pSfxViewShell = pViewFrame->GetViewShell(); | |||
395 | pBase = dynamic_cast< ::sd::ViewShellBase *>( pSfxViewShell ); | |||
396 | } | |||
397 | ||||
398 | return pBase; | |||
399 | } | |||
400 | ||||
401 | void ViewShellBase::Notify(SfxBroadcaster& rBC, const SfxHint& rHint) | |||
402 | { | |||
403 | SfxViewShell::Notify(rBC, rHint); | |||
404 | ||||
405 | const SfxEventHint* pEventHint = dynamic_cast<const SfxEventHint*>(&rHint); | |||
406 | if (pEventHint) | |||
407 | { | |||
408 | switch (pEventHint->GetEventId()) | |||
409 | { | |||
410 | case SfxEventHintId::OpenDoc: | |||
411 | if( GetDocument() && GetDocument()->IsStartWithPresentation() ) | |||
412 | { | |||
413 | if( GetViewFrame() ) | |||
414 | { | |||
415 | GetViewFrame()->GetDispatcher()->Execute( | |||
416 | SID_PRESENTATION( 10000 + 157 ), SfxCallMode::ASYNCHRON ); | |||
417 | } | |||
418 | } | |||
419 | break; | |||
420 | ||||
421 | default: | |||
422 | break; | |||
423 | } | |||
424 | } | |||
425 | else | |||
426 | { | |||
427 | const SfxHintId nSlot = rHint.GetId(); | |||
428 | switch ( nSlot ) | |||
429 | { | |||
430 | case SfxHintId::LanguageChanged: | |||
431 | { | |||
432 | GetViewFrame()->GetBindings().Invalidate(SID_LANGUAGE_STATUS( 10000 + 1067 )); | |||
433 | } | |||
434 | break; | |||
435 | ||||
436 | default: | |||
437 | break; | |||
438 | } | |||
439 | } | |||
440 | } | |||
441 | ||||
442 | void ViewShellBase::InitializeFramework() | |||
443 | { | |||
444 | } | |||
445 | ||||
446 | OUString ViewShellBase::GetSelectionText(bool bCompleteWords) | |||
447 | { | |||
448 | std::shared_ptr<ViewShell> const pMainShell(GetMainViewShell()); | |||
449 | DrawViewShell *const pDrawViewShell( | |||
450 | dynamic_cast<DrawViewShell*>(pMainShell.get())); | |||
451 | return pDrawViewShell | |||
452 | ? pDrawViewShell->GetSelectionText(bCompleteWords) | |||
453 | : SfxViewShell::GetSelectionText(bCompleteWords); | |||
454 | } | |||
455 | ||||
456 | bool ViewShellBase::HasSelection(bool bText) const | |||
457 | { | |||
458 | std::shared_ptr<ViewShell> const pMainShell(GetMainViewShell()); | |||
459 | DrawViewShell *const pDrawViewShell( | |||
460 | dynamic_cast<DrawViewShell*>(pMainShell.get())); | |||
461 | return pDrawViewShell | |||
462 | ? pDrawViewShell->HasSelection(bText) | |||
463 | : SfxViewShell::HasSelection(bText); | |||
464 | } | |||
465 | ||||
466 | void ViewShellBase::InnerResizePixel (const Point& rOrigin, const Size &rSize, bool) | |||
467 | { | |||
468 | Size aObjSize = GetObjectShell()->GetVisArea().GetSize(); | |||
469 | if ( !aObjSize.IsEmpty() ) | |||
470 | { | |||
471 | SvBorder aBorder( GetBorderPixel() ); | |||
472 | Size aSize( rSize ); | |||
473 | aSize.AdjustWidth( -(aBorder.Left() + aBorder.Right()) ); | |||
474 | aSize.AdjustHeight( -(aBorder.Top() + aBorder.Bottom()) ); | |||
475 | Size aObjSizePixel = mpImpl->mpViewWindow->LogicToPixel(aObjSize, MapMode(MapUnit::Map100thMM)); | |||
476 | SfxViewShell::SetZoomFactor( | |||
477 | Fraction( aSize.Width(), std::max( aObjSizePixel.Width(), static_cast<long int>(1) ) ), | |||
478 | Fraction( aSize.Height(), std::max( aObjSizePixel.Height(), static_cast<long int>(1)) ) ); | |||
479 | } | |||
480 | ||||
481 | mpImpl->ResizePixel(rOrigin, rSize, false); | |||
482 | } | |||
483 | ||||
484 | void ViewShellBase::OuterResizePixel (const Point& rOrigin, const Size &rSize) | |||
485 | { | |||
486 | mpImpl->ResizePixel (rOrigin, rSize, true); | |||
487 | } | |||
488 | ||||
489 | void ViewShellBase::Rearrange() | |||
490 | { | |||
491 | OSL_ASSERT(GetViewFrame()!=nullptr)do { if (true && (!(GetViewFrame()!=nullptr))) { sal_detail_logFormat ((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.osl"), ("/home/maarten/src/libreoffice/core/sd/source/ui/view/ViewShellBase.cxx" ":" "491" ": "), "OSL_ASSERT: %s", "GetViewFrame()!=nullptr" ); } } while (false); | |||
492 | ||||
493 | // There is a bug in the communication between embedded objects and the | |||
494 | // framework::LayoutManager that leads to missing resize updates. The | |||
495 | // following workaround enforces such an update by cycling the border to | |||
496 | // zero and back to the current value. | |||
497 | if (GetWindow() != nullptr) | |||
498 | { | |||
499 | SetBorderPixel(SvBorder()); | |||
500 | UpdateBorder(true); | |||
501 | } | |||
502 | else | |||
503 | { | |||
504 | SAL_WARN("sd.view", "Rearrange: window missing")do { if (true) { switch (sal_detail_log_report(::SAL_DETAIL_LOG_LEVEL_WARN , "sd.view")) { case SAL_DETAIL_LOG_ACTION_IGNORE: break; case SAL_DETAIL_LOG_ACTION_LOG: if (sizeof ::sal::detail::getResult ( ::sal::detail::StreamStart() << "Rearrange: window missing" ) == 1) { ::sal_detail_log( (::SAL_DETAIL_LOG_LEVEL_WARN), ("sd.view" ), ("/home/maarten/src/libreoffice/core/sd/source/ui/view/ViewShellBase.cxx" ":" "504" ": "), ::sal::detail::unwrapStream( ::sal::detail:: StreamStart() << "Rearrange: window missing"), 0); } else { ::std::ostringstream sal_detail_stream; sal_detail_stream << "Rearrange: window missing"; ::sal::detail::log( (::SAL_DETAIL_LOG_LEVEL_WARN ), ("sd.view"), ("/home/maarten/src/libreoffice/core/sd/source/ui/view/ViewShellBase.cxx" ":" "504" ": "), sal_detail_stream, 0); }; break; case SAL_DETAIL_LOG_ACTION_FATAL : if (sizeof ::sal::detail::getResult( ::sal::detail::StreamStart () << "Rearrange: window missing") == 1) { ::sal_detail_log ( (::SAL_DETAIL_LOG_LEVEL_WARN), ("sd.view"), ("/home/maarten/src/libreoffice/core/sd/source/ui/view/ViewShellBase.cxx" ":" "504" ": "), ::sal::detail::unwrapStream( ::sal::detail:: StreamStart() << "Rearrange: window missing"), 0); } else { ::std::ostringstream sal_detail_stream; sal_detail_stream << "Rearrange: window missing"; ::sal::detail::log( (::SAL_DETAIL_LOG_LEVEL_WARN ), ("sd.view"), ("/home/maarten/src/libreoffice/core/sd/source/ui/view/ViewShellBase.cxx" ":" "504" ": "), sal_detail_stream, 0); }; std::abort(); break ; } } } while (false); | |||
505 | } | |||
506 | ||||
507 | GetViewFrame()->Resize(true); | |||
508 | } | |||
509 | ||||
510 | ErrCode ViewShellBase::DoVerb (long nVerb) | |||
511 | { | |||
512 | ErrCode aResult = ERRCODE_NONEErrCode(0); | |||
513 | ||||
514 | ::sd::ViewShell* pShell = GetMainViewShell().get(); | |||
515 | if (pShell != nullptr) | |||
516 | aResult = pShell->DoVerb (nVerb); | |||
517 | ||||
518 | return aResult; | |||
519 | } | |||
520 | ||||
521 | Reference<view::XRenderable> ViewShellBase::GetRenderable() | |||
522 | { | |||
523 | // Create a new DocumentRenderer on every call. It observes the life | |||
524 | // time of this ViewShellBase object. | |||
525 | return Reference<view::XRenderable>(new DocumentRenderer(*this)); | |||
526 | } | |||
527 | ||||
528 | SfxPrinter* ViewShellBase::GetPrinter (bool bCreate) | |||
529 | { | |||
530 | OSL_ASSERT(mpImpl != nullptr)do { if (true && (!(mpImpl != nullptr))) { sal_detail_logFormat ((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.osl"), ("/home/maarten/src/libreoffice/core/sd/source/ui/view/ViewShellBase.cxx" ":" "530" ": "), "OSL_ASSERT: %s", "mpImpl != nullptr"); } } while (false); | |||
531 | ||||
532 | return GetDocShell()->GetPrinter (bCreate); | |||
533 | } | |||
534 | ||||
535 | sal_uInt16 ViewShellBase::SetPrinter ( | |||
536 | SfxPrinter* pNewPrinter, | |||
537 | SfxPrinterChangeFlags nDiffFlags) | |||
538 | { | |||
539 | OSL_ASSERT(mpImpl != nullptr)do { if (true && (!(mpImpl != nullptr))) { sal_detail_logFormat ((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.osl"), ("/home/maarten/src/libreoffice/core/sd/source/ui/view/ViewShellBase.cxx" ":" "539" ": "), "OSL_ASSERT: %s", "mpImpl != nullptr"); } } while (false); | |||
540 | ||||
541 | GetDocShell()->SetPrinter(pNewPrinter); | |||
542 | ||||
543 | if ( (nDiffFlags & SfxPrinterChangeFlags::CHG_ORIENTATION || | |||
544 | nDiffFlags & SfxPrinterChangeFlags::CHG_SIZE) && pNewPrinter ) | |||
545 | { | |||
546 | MapMode aMap = pNewPrinter->GetMapMode(); | |||
547 | aMap.SetMapUnit(MapUnit::Map100thMM); | |||
548 | MapMode aOldMap = pNewPrinter->GetMapMode(); | |||
549 | pNewPrinter->SetMapMode(aMap); | |||
550 | Size aNewSize = pNewPrinter->GetOutputSize(); | |||
551 | ||||
552 | std::shared_ptr<DrawViewShell> pDrawViewShell ( | |||
553 | std::dynamic_pointer_cast<DrawViewShell>(GetMainViewShell())); | |||
554 | if (pDrawViewShell) | |||
555 | { | |||
556 | SdPage* pPage = GetDocument()->GetSdPage( | |||
557 | 0, PageKind::Standard ); | |||
558 | pDrawViewShell->SetPageSizeAndBorder ( | |||
559 | pDrawViewShell->GetPageKind(), | |||
560 | aNewSize, | |||
561 | -1,-1,-1,-1, | |||
562 | false/*bScaleAll*/, | |||
563 | pNewPrinter->GetOrientation(), | |||
564 | pPage->GetPaperBin(), | |||
565 | pPage->IsBackgroundFullSize()); | |||
566 | } | |||
567 | ||||
568 | pNewPrinter->SetMapMode(aOldMap); | |||
569 | } | |||
570 | ||||
571 | return 0; | |||
572 | } | |||
573 | ||||
574 | void ViewShellBase::UIActivating( SfxInPlaceClient* pClient ) | |||
575 | { | |||
576 | mpImpl->ShowViewTabBar(false); | |||
577 | ||||
578 | ViewShell* pViewShell = GetMainViewShell().get(); | |||
579 | if ( pViewShell ) | |||
580 | pViewShell->UIActivating( pClient ); | |||
581 | ||||
582 | SfxViewShell::UIActivating( pClient ); | |||
583 | } | |||
584 | ||||
585 | void ViewShellBase::UIDeactivated( SfxInPlaceClient* pClient ) | |||
586 | { | |||
587 | SfxViewShell::UIDeactivated( pClient ); | |||
588 | ||||
589 | mpImpl->ShowViewTabBar(true); | |||
590 | ||||
591 | ViewShell* pViewShell = GetMainViewShell().get(); | |||
592 | if ( pViewShell ) | |||
593 | pViewShell->UIDeactivated( pClient ); | |||
594 | } | |||
595 | ||||
596 | SvBorder ViewShellBase::GetBorder (bool ) | |||
597 | { | |||
598 | int nTop = 0; | |||
599 | if (mpImpl->mpViewTabBar.is() && mpImpl->mpViewTabBar->GetTabControl()->IsVisible()) | |||
600 | nTop = mpImpl->mpViewTabBar->GetHeight(); | |||
601 | return SvBorder(0,nTop,0,0); | |||
602 | } | |||
603 | ||||
604 | void ViewShellBase::Execute (SfxRequest& rRequest) | |||
605 | { | |||
606 | sal_uInt16 nSlotId = rRequest.GetSlot(); | |||
607 | ||||
608 | switch (nSlotId) | |||
609 | { | |||
610 | case SID_SWITCH_SHELL(27000 +406): | |||
611 | { | |||
612 | Reference<XControllerManager> xControllerManager (GetController(), UNO_QUERY); | |||
613 | if (xControllerManager.is()) | |||
614 | { | |||
615 | Reference<XConfigurationController> xConfigurationController ( | |||
616 | xControllerManager->getConfigurationController()); | |||
617 | if (xConfigurationController.is()) | |||
618 | xConfigurationController->update(); | |||
619 | } | |||
620 | } | |||
621 | break; | |||
622 | ||||
623 | case SID_LEFT_PANE_DRAW(27000 +415): | |||
624 | mpImpl->SetPaneVisibility( | |||
625 | rRequest, | |||
626 | framework::FrameworkHelper::msLeftDrawPaneURL, | |||
627 | framework::FrameworkHelper::msSlideSorterURL); | |||
628 | break; | |||
629 | ||||
630 | case SID_LEFT_PANE_IMPRESS(27000 +414): | |||
631 | mpImpl->SetPaneVisibility( | |||
632 | rRequest, | |||
633 | framework::FrameworkHelper::msLeftImpressPaneURL, | |||
634 | framework::FrameworkHelper::msSlideSorterURL); | |||
635 | break; | |||
636 | ||||
637 | case SID_TOGGLE_TABBAR_VISIBILITY(27000 +13): | |||
638 | { | |||
639 | SdOptions* pOptions = SD_MOD()( static_cast<SdModule*>(SfxApplication::GetModule(SfxToolsModule ::Draw)) )->GetSdOptions(GetDocument()->GetDocumentType()); | |||
640 | bool bIsTabBarVisible = pOptions->IsTabBarVisible(); | |||
641 | pOptions->SetTabBarVisible( !bIsTabBarVisible ); | |||
642 | mpImpl->SetUserWantsTabBar( !bIsTabBarVisible ); | |||
643 | rRequest.Done(); | |||
644 | } | |||
645 | break; | |||
646 | ||||
647 | // draw | |||
648 | case SID_DRAWINGMODE(27000 +9): | |||
649 | // impress normal | |||
650 | case SID_NORMAL_MULTI_PANE_GUI(27000 +420): | |||
651 | case SID_NOTES_MODE(27000 +69): | |||
652 | case SID_OUTLINE_MODE(27000 +10): | |||
653 | case SID_SLIDE_SORTER_MULTI_PANE_GUI(27000 +421): | |||
654 | case SID_SLIDE_SORTER_MODE(27000 +11): | |||
655 | // impress master | |||
656 | case SID_SLIDE_MASTER_MODE(27000 +348): | |||
657 | case SID_NOTES_MASTER_MODE(27000 +350): | |||
658 | case SID_HANDOUT_MASTER_MODE(27000 +70): | |||
659 | framework::FrameworkHelper::Instance(*this)->HandleModeChangeSlot(nSlotId, rRequest); | |||
660 | break; | |||
661 | ||||
662 | case SID_WIN_FULLSCREEN(5000 + 627): | |||
663 | // The full screen mode is not supported. Ignore the request. | |||
664 | break; | |||
665 | ||||
666 | case SID_RESTORE_EDITING_VIEW(5000 + 1663): | |||
667 | mpImpl->ProcessRestoreEditingViewSlot(); | |||
668 | break; | |||
669 | ||||
670 | default: | |||
671 | // Ignore any other slot. | |||
672 | rRequest.Ignore (); | |||
673 | break; | |||
674 | } | |||
675 | } | |||
676 | ||||
677 | void ViewShellBase::GetState (SfxItemSet& rSet) | |||
678 | { | |||
679 | mpImpl->GetSlotState(rSet); | |||
680 | ||||
681 | FuBullet::GetSlotState( rSet, nullptr, GetViewFrame() ); | |||
682 | } | |||
683 | ||||
684 | void ViewShellBase::WriteUserDataSequence ( | |||
685 | css::uno::Sequence< css::beans::PropertyValue >& rSequence) | |||
686 | { | |||
687 | // Forward call to main sub shell. | |||
688 | ViewShell* pShell = GetMainViewShell().get(); | |||
689 | if (pShell != nullptr) | |||
690 | pShell->WriteUserDataSequence (rSequence); | |||
691 | } | |||
692 | ||||
693 | void ViewShellBase::ReadUserDataSequence ( | |||
694 | const css::uno::Sequence< css::beans::PropertyValue >& rSequence) | |||
695 | { | |||
696 | // Forward call to main sub shell. | |||
697 | ViewShell* pShell = GetMainViewShell().get(); | |||
698 | if (pShell == nullptr) | |||
699 | return; | |||
700 | ||||
701 | pShell->ReadUserDataSequence (rSequence); | |||
702 | ||||
703 | // For certain shell types ReadUserDataSequence may have changed the | |||
704 | // type to another one. Make sure that the center pane shows the | |||
705 | // right view shell. | |||
706 | switch (pShell->GetShellType()) | |||
707 | { | |||
708 | case ViewShell::ST_IMPRESS: | |||
709 | case ViewShell::ST_NOTES: | |||
710 | case ViewShell::ST_HANDOUT: | |||
711 | { | |||
712 | OUString sViewURL; | |||
713 | switch (dynamic_cast<DrawViewShell&>(*pShell).GetPageKind()) | |||
714 | { | |||
715 | default: | |||
716 | case PageKind::Standard: | |||
717 | sViewURL = framework::FrameworkHelper::msImpressViewURL; | |||
718 | break; | |||
719 | case PageKind::Notes: | |||
720 | sViewURL = framework::FrameworkHelper::msNotesViewURL; | |||
721 | break; | |||
722 | case PageKind::Handout: | |||
723 | sViewURL = framework::FrameworkHelper::msHandoutViewURL; | |||
724 | break; | |||
725 | } | |||
726 | if (!sViewURL.isEmpty()) | |||
727 | framework::FrameworkHelper::Instance(*this)->RequestView( | |||
728 | sViewURL, | |||
729 | framework::FrameworkHelper::msCenterPaneURL); | |||
730 | } | |||
731 | break; | |||
732 | ||||
733 | default: | |||
734 | break; | |||
735 | } | |||
736 | } | |||
737 | ||||
738 | void ViewShellBase::Activate (bool bIsMDIActivate) | |||
739 | { | |||
740 | SfxViewShell::Activate(bIsMDIActivate); | |||
741 | ||||
742 | Reference<XControllerManager> xControllerManager (GetController(), UNO_QUERY); | |||
743 | if (xControllerManager.is()) | |||
744 | { | |||
745 | Reference<XConfigurationController> xConfigurationController ( | |||
746 | xControllerManager->getConfigurationController()); | |||
747 | if (xConfigurationController.is()) | |||
748 | xConfigurationController->update(); | |||
749 | } | |||
750 | GetToolBarManager()->RequestUpdate(); | |||
751 | } | |||
752 | ||||
753 | void ViewShellBase::SetZoomFactor ( | |||
754 | const Fraction &rZoomX, | |||
755 | const Fraction &rZoomY) | |||
756 | { | |||
757 | SfxViewShell::SetZoomFactor (rZoomX, rZoomY); | |||
758 | // Forward call to main sub shell. | |||
759 | ViewShell* pShell = GetMainViewShell().get(); | |||
760 | if (pShell != nullptr) | |||
761 | pShell->SetZoomFactor (rZoomX, rZoomY); | |||
762 | } | |||
763 | ||||
764 | bool ViewShellBase::PrepareClose (bool bUI) | |||
765 | { | |||
766 | bool bResult = SfxViewShell::PrepareClose (bUI); | |||
767 | ||||
768 | if (bResult) | |||
769 | { | |||
770 | mpImpl->mbIsClosing = true; | |||
771 | ||||
772 | // Forward call to main sub shell. | |||
773 | ViewShell* pShell = GetMainViewShell().get(); | |||
774 | if (pShell != nullptr) | |||
775 | bResult = pShell->PrepareClose (bUI); | |||
776 | } | |||
777 | ||||
778 | return bResult; | |||
779 | } | |||
780 | ||||
781 | void ViewShellBase::WriteUserData (OUString& rString, bool bBrowse) | |||
782 | { | |||
783 | SfxViewShell::WriteUserData (rString, bBrowse); | |||
784 | ||||
785 | // Forward call to main sub shell. | |||
786 | ViewShell* pShell = GetMainViewShell().get(); | |||
787 | if (pShell != nullptr) | |||
788 | pShell->WriteUserData(); | |||
789 | } | |||
790 | ||||
791 | void ViewShellBase::ReadUserData (const OUString& rString, bool bBrowse) | |||
792 | { | |||
793 | SfxViewShell::ReadUserData (rString, bBrowse); | |||
794 | ||||
795 | // Forward call to main sub shell. | |||
796 | ViewShell* pShell = GetMainViewShell().get(); | |||
797 | if (pShell != nullptr) | |||
798 | pShell->ReadUserData(); | |||
799 | } | |||
800 | ||||
801 | SdrView* ViewShellBase::GetDrawView() const | |||
802 | { | |||
803 | // Forward call to main sub shell. | |||
804 | ViewShell* pShell = GetMainViewShell().get(); | |||
805 | if (pShell != nullptr) | |||
806 | return pShell->GetDrawView (); | |||
807 | else | |||
808 | return SfxViewShell::GetDrawView(); | |||
809 | } | |||
810 | ||||
811 | void ViewShellBase::SetBusyState (bool bBusy) | |||
812 | { | |||
813 | if (GetDocShell() != nullptr) | |||
814 | GetDocShell()->SetWaitCursor (bBusy); | |||
815 | } | |||
816 | ||||
817 | void ViewShellBase::UpdateBorder ( bool bForce /* = false */ ) | |||
818 | { | |||
819 | // The following calls to SetBorderPixel() and InvalidateBorder() are | |||
820 | // made only for the main view shell. This not only avoids unnecessary | |||
821 | // calls for the views in side panes but prevents calling an already | |||
822 | // dying SfxViewShell base class. | |||
823 | // We have to check the existence of the window, too. | |||
824 | // The SfxViewFrame accesses the window without checking it. | |||
825 | ViewShell* pMainViewShell = GetMainViewShell().get(); | |||
826 | if (pMainViewShell == nullptr || GetWindow()==nullptr) | |||
827 | return; | |||
828 | ||||
829 | SvBorder aCurrentBorder (GetBorderPixel()); | |||
830 | bool bOuterResize ( ! GetDocShell()->IsInPlaceActive()); | |||
831 | SvBorder aBorder (GetBorder(bOuterResize)); | |||
832 | aBorder += pMainViewShell->GetBorder(); | |||
833 | ||||
834 | if (bForce || (aBorder != aCurrentBorder)) | |||
835 | { | |||
836 | SetBorderPixel (aBorder); | |||
837 | InvalidateBorder(); | |||
838 | } | |||
839 | } | |||
840 | ||||
841 | void ViewShellBase::ShowUIControls (bool bVisible) | |||
842 | { | |||
843 | mpImpl->ShowViewTabBar(bVisible); | |||
844 | ||||
845 | ViewShell* pMainViewShell = GetMainViewShell().get(); | |||
846 | if (pMainViewShell != nullptr) | |||
847 | pMainViewShell->ShowUIControls (bVisible); | |||
848 | ||||
849 | UpdateBorder(); | |||
850 | if (bVisible) | |||
851 | Rearrange(); | |||
852 | } | |||
853 | ||||
854 | OUString ViewShellBase::GetInitialViewShellType() const | |||
855 | { | |||
856 | OUString sRequestedView (FrameworkHelper::msImpressViewURL); | |||
857 | ||||
858 | do | |||
859 | { | |||
860 | Reference<document::XViewDataSupplier> xViewDataSupplier ( | |||
861 | GetDocShell()->GetModel(), UNO_QUERY); | |||
862 | if ( ! xViewDataSupplier.is()) | |||
863 | break; | |||
864 | ||||
865 | Reference<container::XIndexAccess> xViewData (xViewDataSupplier->getViewData()); | |||
866 | if ( ! xViewData.is()) | |||
867 | break; | |||
868 | if (xViewData->getCount() == 0) | |||
869 | break; | |||
870 | ||||
871 | css::uno::Any aAny = xViewData->getByIndex(0); | |||
872 | Sequence<beans::PropertyValue> aProperties; | |||
873 | if ( ! (aAny >>= aProperties)) | |||
874 | break; | |||
875 | ||||
876 | // Search the properties for the one that tells us what page kind to | |||
877 | // use. | |||
878 | auto pProperty = std::find_if(aProperties.begin(), aProperties.end(), | |||
879 | [](const beans::PropertyValue& rProperty) { return rProperty.Name == sUNO_View_PageKind; }); | |||
880 | if (pProperty != aProperties.end()) | |||
881 | { | |||
882 | sal_Int16 nPageKind = 0; | |||
883 | pProperty->Value >>= nPageKind; | |||
884 | switch (static_cast<PageKind>(nPageKind)) | |||
885 | { | |||
886 | case PageKind::Standard: | |||
887 | sRequestedView = FrameworkHelper::msImpressViewURL; | |||
888 | break; | |||
889 | ||||
890 | case PageKind::Handout: | |||
891 | sRequestedView = FrameworkHelper::msHandoutViewURL; | |||
892 | break; | |||
893 | ||||
894 | case PageKind::Notes: | |||
895 | sRequestedView = FrameworkHelper::msNotesViewURL; | |||
896 | break; | |||
897 | ||||
898 | default: | |||
899 | // The page kind is invalid. This is probably an | |||
900 | // error by the caller. We use the standard type to | |||
901 | // keep things going. | |||
902 | SAL_WARN( "sd.view", "ViewShellBase::GetInitialViewShellType: invalid page kind")do { if (true) { switch (sal_detail_log_report(::SAL_DETAIL_LOG_LEVEL_WARN , "sd.view")) { case SAL_DETAIL_LOG_ACTION_IGNORE: break; case SAL_DETAIL_LOG_ACTION_LOG: if (sizeof ::sal::detail::getResult ( ::sal::detail::StreamStart() << "ViewShellBase::GetInitialViewShellType: invalid page kind" ) == 1) { ::sal_detail_log( (::SAL_DETAIL_LOG_LEVEL_WARN), ("sd.view" ), ("/home/maarten/src/libreoffice/core/sd/source/ui/view/ViewShellBase.cxx" ":" "902" ": "), ::sal::detail::unwrapStream( ::sal::detail:: StreamStart() << "ViewShellBase::GetInitialViewShellType: invalid page kind" ), 0); } else { ::std::ostringstream sal_detail_stream; sal_detail_stream << "ViewShellBase::GetInitialViewShellType: invalid page kind" ; ::sal::detail::log( (::SAL_DETAIL_LOG_LEVEL_WARN), ("sd.view" ), ("/home/maarten/src/libreoffice/core/sd/source/ui/view/ViewShellBase.cxx" ":" "902" ": "), sal_detail_stream, 0); }; break; case SAL_DETAIL_LOG_ACTION_FATAL : if (sizeof ::sal::detail::getResult( ::sal::detail::StreamStart () << "ViewShellBase::GetInitialViewShellType: invalid page kind" ) == 1) { ::sal_detail_log( (::SAL_DETAIL_LOG_LEVEL_WARN), ("sd.view" ), ("/home/maarten/src/libreoffice/core/sd/source/ui/view/ViewShellBase.cxx" ":" "902" ": "), ::sal::detail::unwrapStream( ::sal::detail:: StreamStart() << "ViewShellBase::GetInitialViewShellType: invalid page kind" ), 0); } else { ::std::ostringstream sal_detail_stream; sal_detail_stream << "ViewShellBase::GetInitialViewShellType: invalid page kind" ; ::sal::detail::log( (::SAL_DETAIL_LOG_LEVEL_WARN), ("sd.view" ), ("/home/maarten/src/libreoffice/core/sd/source/ui/view/ViewShellBase.cxx" ":" "902" ": "), sal_detail_stream, 0); }; std::abort(); break ; } } } while (false); | |||
903 | sRequestedView = FrameworkHelper::msImpressViewURL; | |||
904 | break; | |||
905 | } | |||
906 | } | |||
907 | } | |||
908 | while (false); | |||
909 | ||||
910 | return sRequestedView; | |||
911 | } | |||
912 | ||||
913 | std::shared_ptr<tools::EventMultiplexer> const & ViewShellBase::GetEventMultiplexer() const | |||
914 | { | |||
915 | OSL_ASSERT(mpImpl != nullptr)do { if (true && (!(mpImpl != nullptr))) { sal_detail_logFormat ((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.osl"), ("/home/maarten/src/libreoffice/core/sd/source/ui/view/ViewShellBase.cxx" ":" "915" ": "), "OSL_ASSERT: %s", "mpImpl != nullptr"); } } while (false); | |||
916 | OSL_ASSERT(mpImpl->mpEventMultiplexer != nullptr)do { if (true && (!(mpImpl->mpEventMultiplexer != nullptr ))) { sal_detail_logFormat((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.osl" ), ("/home/maarten/src/libreoffice/core/sd/source/ui/view/ViewShellBase.cxx" ":" "916" ": "), "OSL_ASSERT: %s", "mpImpl->mpEventMultiplexer != nullptr" ); } } while (false); | |||
917 | ||||
918 | return mpImpl->mpEventMultiplexer; | |||
919 | } | |||
920 | ||||
921 | const ::tools::Rectangle& ViewShellBase::getClientRectangle() const | |||
922 | { | |||
923 | return mpImpl->maClientArea; | |||
924 | } | |||
925 | ||||
926 | std::shared_ptr<ToolBarManager> const & ViewShellBase::GetToolBarManager() const | |||
927 | { | |||
928 | OSL_ASSERT(mpImpl != nullptr)do { if (true && (!(mpImpl != nullptr))) { sal_detail_logFormat ((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.osl"), ("/home/maarten/src/libreoffice/core/sd/source/ui/view/ViewShellBase.cxx" ":" "928" ": "), "OSL_ASSERT: %s", "mpImpl != nullptr"); } } while (false); | |||
929 | OSL_ASSERT(mpImpl->mpToolBarManager != nullptr)do { if (true && (!(mpImpl->mpToolBarManager != nullptr ))) { sal_detail_logFormat((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.osl" ), ("/home/maarten/src/libreoffice/core/sd/source/ui/view/ViewShellBase.cxx" ":" "929" ": "), "OSL_ASSERT: %s", "mpImpl->mpToolBarManager != nullptr" ); } } while (false); | |||
930 | ||||
931 | return mpImpl->mpToolBarManager; | |||
932 | } | |||
933 | ||||
934 | std::shared_ptr<FormShellManager> const & ViewShellBase::GetFormShellManager() const | |||
935 | { | |||
936 | OSL_ASSERT(mpImpl != nullptr)do { if (true && (!(mpImpl != nullptr))) { sal_detail_logFormat ((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.osl"), ("/home/maarten/src/libreoffice/core/sd/source/ui/view/ViewShellBase.cxx" ":" "936" ": "), "OSL_ASSERT: %s", "mpImpl != nullptr"); } } while (false); | |||
937 | OSL_ASSERT(mpImpl->mpFormShellManager != nullptr)do { if (true && (!(mpImpl->mpFormShellManager != nullptr ))) { sal_detail_logFormat((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.osl" ), ("/home/maarten/src/libreoffice/core/sd/source/ui/view/ViewShellBase.cxx" ":" "937" ": "), "OSL_ASSERT: %s", "mpImpl->mpFormShellManager != nullptr" ); } } while (false); | |||
938 | ||||
939 | return mpImpl->mpFormShellManager; | |||
940 | } | |||
941 | ||||
942 | DrawController& ViewShellBase::GetDrawController() const | |||
943 | { | |||
944 | OSL_ASSERT(mpImpl != nullptr)do { if (true && (!(mpImpl != nullptr))) { sal_detail_logFormat ((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.osl"), ("/home/maarten/src/libreoffice/core/sd/source/ui/view/ViewShellBase.cxx" ":" "944" ": "), "OSL_ASSERT: %s", "mpImpl != nullptr"); } } while (false); | |||
945 | ||||
946 | return *mpImpl->mpController; | |||
947 | } | |||
948 | ||||
949 | void ViewShellBase::SetViewTabBar (const ::rtl::Reference<ViewTabBar>& rViewTabBar) | |||
950 | { | |||
951 | OSL_ASSERT(mpImpl != nullptr)do { if (true && (!(mpImpl != nullptr))) { sal_detail_logFormat ((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.osl"), ("/home/maarten/src/libreoffice/core/sd/source/ui/view/ViewShellBase.cxx" ":" "951" ": "), "OSL_ASSERT: %s", "mpImpl != nullptr"); } } while (false); | |||
952 | ||||
953 | mpImpl->mpViewTabBar = rViewTabBar; | |||
954 | } | |||
955 | ||||
956 | vcl::Window* ViewShellBase::GetViewWindow() | |||
957 | { | |||
958 | OSL_ASSERT(mpImpl != nullptr)do { if (true && (!(mpImpl != nullptr))) { sal_detail_logFormat ((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.osl"), ("/home/maarten/src/libreoffice/core/sd/source/ui/view/ViewShellBase.cxx" ":" "958" ": "), "OSL_ASSERT: %s", "mpImpl != nullptr"); } } while (false); | |||
959 | ||||
960 | return mpImpl->mpViewWindow.get(); | |||
961 | } | |||
962 | ||||
963 | OUString ViewShellBase::RetrieveLabelFromCommand( const OUString& aCmdURL ) const | |||
964 | { | |||
965 | OUString aModuleName(vcl::CommandInfoProvider::GetModuleIdentifier(GetMainViewShell()->GetViewFrame()->GetFrame().GetFrameInterface())); | |||
966 | auto aProperties = vcl::CommandInfoProvider::GetCommandProperties(aCmdURL, aModuleName); | |||
967 | return vcl::CommandInfoProvider::GetLabelForCommand(aProperties); | |||
968 | } | |||
969 | ||||
970 | int ViewShellBase::getPart() const | |||
971 | { | |||
972 | ViewShell* pViewShell = framework::FrameworkHelper::Instance(*const_cast<ViewShellBase*>(this))->GetViewShell(FrameworkHelper::msCenterPaneURL).get(); | |||
973 | ||||
974 | if (DrawViewShell* pDrawViewShell = dynamic_cast<DrawViewShell*>(pViewShell)) | |||
975 | { | |||
976 | return pDrawViewShell->GetCurPagePos(); | |||
977 | } | |||
978 | ||||
979 | return 0; | |||
980 | } | |||
981 | ||||
982 | void ViewShellBase::NotifyCursor(SfxViewShell* pOtherShell) const | |||
983 | { | |||
984 | ViewShell* pThisShell = framework::FrameworkHelper::Instance(*const_cast<ViewShellBase*>(this))->GetViewShell(FrameworkHelper::msCenterPaneURL).get(); | |||
985 | ||||
986 | DrawViewShell* pDrawViewShell = dynamic_cast<DrawViewShell*>(pThisShell); | |||
987 | if (!pDrawViewShell) | |||
988 | return; | |||
989 | ||||
990 | if (this == pOtherShell) | |||
991 | return; | |||
992 | ||||
993 | DrawView* pDrawView = pDrawViewShell->GetDrawView(); | |||
994 | if (!pDrawView) | |||
995 | return; | |||
996 | ||||
997 | if (pDrawView->GetTextEditObject()) | |||
998 | { | |||
999 | // Blinking cursor. | |||
1000 | EditView& rEditView = pDrawView->GetTextEditOutlinerView()->GetEditView(); | |||
1001 | rEditView.RegisterOtherShell(pOtherShell); | |||
1002 | rEditView.ShowCursor(); | |||
1003 | rEditView.RegisterOtherShell(nullptr); | |||
1004 | // Text selection, if any. | |||
1005 | rEditView.DrawSelectionXOR(pOtherShell); | |||
1006 | ||||
1007 | // Shape text lock. | |||
1008 | if (OutlinerView* pOutlinerView = pDrawView->GetTextEditOutlinerView()) | |||
1009 | { | |||
1010 | ::tools::Rectangle aRectangle = pOutlinerView->GetOutputArea(); | |||
1011 | vcl::Window* pWin = pThisShell->GetActiveWindow(); | |||
1012 | if (pWin && pWin->GetMapMode().GetMapUnit() == MapUnit::Map100thMM) | |||
1013 | aRectangle = OutputDevice::LogicToLogic(aRectangle, MapMode(MapUnit::Map100thMM), MapMode(MapUnit::MapTwip)); | |||
1014 | OString sRectangle = aRectangle.toString(); | |||
1015 | SfxLokHelper::notifyOtherView(&pDrawViewShell->GetViewShellBase(), pOtherShell, LOK_CALLBACK_VIEW_LOCK, "rectangle", sRectangle); | |||
1016 | } | |||
1017 | } | |||
1018 | else | |||
1019 | { | |||
1020 | // Graphic selection. | |||
1021 | pDrawView->AdjustMarkHdl(pOtherShell); | |||
1022 | } | |||
1023 | } | |||
1024 | ||||
1025 | //===== ViewShellBase::Implementation ========================================= | |||
1026 | ||||
1027 | ViewShellBase::Implementation::Implementation (ViewShellBase& rBase) | |||
1028 | : mpController(), | |||
1029 | mpViewTabBar(), | |||
1030 | maClientArea(), | |||
1031 | mbIsClosing(false), | |||
1032 | mpViewWindow(), | |||
1033 | mpToolBarManager(), | |||
1034 | mpViewShellManager(), | |||
1035 | mpEventMultiplexer(), | |||
1036 | mpFormShellManager(), | |||
1037 | mrBase(rBase), | |||
1038 | mbUserWantsTabBar(false), | |||
1039 | mbTabBarShouldBeVisible(true), | |||
1040 | mpPageCacheManager(slidesorter::cache::PageCacheManager::Instance()) | |||
1041 | { | |||
1042 | } | |||
1043 | ||||
1044 | ViewShellBase::Implementation::~Implementation() | |||
1045 | { | |||
1046 | mpController = nullptr; | |||
1047 | mpViewTabBar = nullptr; | |||
1048 | mpViewWindow.disposeAndClear(); | |||
| ||||
1049 | mpToolBarManager.reset(); | |||
1050 | } | |||
1051 | ||||
1052 | void ViewShellBase::Implementation::LateInit() | |||
1053 | { | |||
1054 | mpController = new DrawController(mrBase); | |||
1055 | } | |||
1056 | ||||
1057 | void ViewShellBase::Implementation::ProcessRestoreEditingViewSlot() | |||
1058 | { | |||
1059 | ViewShell* pViewShell = mrBase.GetMainViewShell().get(); | |||
1060 | if (pViewShell == nullptr) | |||
1061 | return; | |||
1062 | ||||
1063 | FrameView* pFrameView = pViewShell->GetFrameView(); | |||
1064 | if (pFrameView == nullptr) | |||
1065 | return; | |||
1066 | ||||
1067 | // Set view shell, edit mode, and page kind. | |||
1068 | // pFrameView->SetViewShEditMode( | |||
1069 | // pFrameView->GetViewShEditModeOnLoad(), | |||
1070 | // pFrameView->GetPageKindOnLoad()); | |||
1071 | pFrameView->SetViewShEditMode( | |||
1072 | pFrameView->GetViewShEditModeOnLoad() ); | |||
1073 | pFrameView->SetPageKind( | |||
1074 | pFrameView->GetPageKindOnLoad()); | |||
1075 | std::shared_ptr<FrameworkHelper> pHelper (FrameworkHelper::Instance(mrBase)); | |||
1076 | pHelper->RequestView( | |||
1077 | FrameworkHelper::GetViewURL(pFrameView->GetViewShellTypeOnLoad()), | |||
1078 | FrameworkHelper::msCenterPaneURL); | |||
1079 | pHelper->RunOnConfigurationEvent("ConfigurationUpdateEnd", CurrentPageSetter(mrBase)); | |||
1080 | } | |||
1081 | ||||
1082 | void ViewShellBase::Implementation::SetUserWantsTabBar(bool inValue) | |||
1083 | { | |||
1084 | mbUserWantsTabBar = inValue; | |||
1085 | // Call ShowViewTabBar to refresh the TabBar visibility | |||
1086 | ShowViewTabBar(mbTabBarShouldBeVisible); | |||
1087 | } | |||
1088 | ||||
1089 | void ViewShellBase::Implementation::ShowViewTabBar (bool bShow) | |||
1090 | { | |||
1091 | mbTabBarShouldBeVisible = bShow; | |||
1092 | bShow = bShow && mbUserWantsTabBar; | |||
1093 | ||||
1094 | if (mpViewTabBar.is() | |||
1095 | && mpViewTabBar->GetTabControl()->IsVisible() != bShow) | |||
1096 | { | |||
1097 | mpViewTabBar->GetTabControl()->Show(bShow); | |||
1098 | mrBase.Rearrange(); | |||
1099 | } | |||
1100 | } | |||
1101 | ||||
1102 | void ViewShellBase::Implementation::ResizePixel ( | |||
1103 | const Point& rOrigin, | |||
1104 | const Size &rSize, | |||
1105 | bool bOuterResize) | |||
1106 | { | |||
1107 | if (mbIsClosing) | |||
1108 | return; | |||
1109 | ||||
1110 | // Forward the call to both the base class and the main stacked sub | |||
1111 | // shell only when main sub shell exists. | |||
1112 | ViewShell* pMainViewShell = mrBase.GetMainViewShell().get(); | |||
1113 | ||||
1114 | // Set the ViewTabBar temporarily to full size so that, when asked | |||
1115 | // later, it can return its true height. | |||
1116 | mrBase.SetWindow (mpViewWindow.get()); | |||
1117 | if (mpViewTabBar.is() && mpViewTabBar->GetTabControl()->IsVisible()) | |||
1118 | mpViewTabBar->GetTabControl()->SetPosSizePixel (rOrigin, rSize); | |||
1119 | ||||
1120 | // Calculate and set the border before the controls are placed. | |||
1121 | SvBorder aBorder; | |||
1122 | if (pMainViewShell != nullptr) | |||
1123 | aBorder = pMainViewShell->GetBorder(); | |||
1124 | aBorder += mrBase.GetBorder(bOuterResize); | |||
1125 | if (mrBase.GetBorderPixel() != aBorder) | |||
1126 | mrBase.SetBorderPixel(aBorder); | |||
1127 | ||||
1128 | // Place the ViewTabBar at the top. It is part of the border. | |||
1129 | SvBorder aBaseBorder; | |||
1130 | if (mpViewTabBar.is() && mpViewTabBar->GetTabControl()->IsVisible()) | |||
1131 | { | |||
1132 | aBaseBorder.Top() = mpViewTabBar->GetHeight(); | |||
1133 | mpViewTabBar->GetTabControl()->SetPosSizePixel( | |||
1134 | rOrigin, Size(rSize.Width(),aBaseBorder.Top())); | |||
1135 | } | |||
1136 | ||||
1137 | // The view window gets the remaining space. | |||
1138 | Point aViewWindowPosition ( | |||
1139 | rOrigin.X()+aBaseBorder.Left(), | |||
1140 | rOrigin.Y()+aBaseBorder.Top()); | |||
1141 | ||||
1142 | Size aViewWindowSize ( | |||
1143 | rSize.Width() - aBaseBorder.Left() - aBaseBorder.Right(), | |||
1144 | rSize.Height() - aBaseBorder.Top() - aBaseBorder.Bottom()); | |||
1145 | mpViewWindow->SetPosSizePixel(aViewWindowPosition, aViewWindowSize); | |||
1146 | ||||
1147 | maClientArea = ::tools::Rectangle(Point(0,0), aViewWindowSize); | |||
1148 | } | |||
1149 | ||||
1150 | void ViewShellBase::Implementation::SetPaneVisibility ( | |||
1151 | const SfxRequest& rRequest, | |||
1152 | const OUString& rsPaneURL, | |||
1153 | const OUString& rsViewURL) | |||
1154 | { | |||
1155 | try | |||
1156 | { | |||
1157 | Reference<XControllerManager> xControllerManager (mrBase.GetController(), UNO_QUERY_THROW); | |||
1158 | ||||
1159 | const Reference< XComponentContext > xContext( | |||
1160 | ::comphelper::getProcessComponentContext() ); | |||
1161 | Reference<XResourceId> xPaneId (ResourceId::create( | |||
1162 | xContext, rsPaneURL)); | |||
1163 | Reference<XResourceId> xViewId (ResourceId::createWithAnchorURL( | |||
1164 | xContext, rsViewURL, rsPaneURL)); | |||
1165 | ||||
1166 | // Determine the new visibility state. | |||
1167 | const SfxItemSet* pArguments = rRequest.GetArgs(); | |||
1168 | bool bShowChildWindow; | |||
1169 | sal_uInt16 nSlotId = rRequest.GetSlot(); | |||
1170 | if (pArguments != nullptr) | |||
1171 | bShowChildWindow = static_cast<const SfxBoolItem&>( | |||
1172 | pArguments->Get(nSlotId)).GetValue(); | |||
1173 | else | |||
1174 | { | |||
1175 | Reference<XConfigurationController> xConfigurationController ( | |||
1176 | xControllerManager->getConfigurationController()); | |||
1177 | if ( ! xConfigurationController.is()) | |||
1178 | throw RuntimeException(); | |||
1179 | Reference<XConfiguration> xConfiguration ( | |||
1180 | xConfigurationController->getRequestedConfiguration()); | |||
1181 | if ( ! xConfiguration.is()) | |||
1182 | throw RuntimeException(); | |||
1183 | ||||
1184 | bShowChildWindow = ! xConfiguration->hasResource(xPaneId); | |||
1185 | } | |||
1186 | ||||
1187 | // Set the desired visibility state at the current configuration | |||
1188 | // and update it accordingly. | |||
1189 | Reference<XConfigurationController> xConfigurationController ( | |||
1190 | xControllerManager->getConfigurationController()); | |||
1191 | if ( ! xConfigurationController.is()) | |||
1192 | throw RuntimeException(); | |||
1193 | if (bShowChildWindow) | |||
1194 | { | |||
1195 | xConfigurationController->requestResourceActivation( | |||
1196 | xPaneId, | |||
1197 | ResourceActivationMode_ADD); | |||
1198 | xConfigurationController->requestResourceActivation( | |||
1199 | xViewId, | |||
1200 | ResourceActivationMode_REPLACE); | |||
1201 | } | |||
1202 | else | |||
1203 | xConfigurationController->requestResourceDeactivation( | |||
1204 | xPaneId); | |||
1205 | } | |||
1206 | catch (const Exception&) | |||
1207 | { | |||
1208 | DBG_UNHANDLED_EXCEPTION("sd.view")DbgUnhandledException( DbgGetCaughtException(), __func__, "/home/maarten/src/libreoffice/core/sd/source/ui/view/ViewShellBase.cxx" ":" "1208" ": ", "sd.view" );; | |||
1209 | } | |||
1210 | } | |||
1211 | ||||
1212 | void ViewShellBase::Implementation::GetSlotState (SfxItemSet& rSet) | |||
1213 | { | |||
1214 | try | |||
1215 | { | |||
1216 | // Get some frequently used values. | |||
1217 | Reference<XControllerManager> xControllerManager (mrBase.GetController(), UNO_QUERY_THROW); | |||
1218 | Reference<XConfigurationController> xConfigurationController ( | |||
1219 | xControllerManager->getConfigurationController()); | |||
1220 | if ( ! xConfigurationController.is()) | |||
1221 | throw RuntimeException(); | |||
1222 | Reference<XConfiguration> xConfiguration ( | |||
1223 | xConfigurationController->getRequestedConfiguration()); | |||
1224 | if ( ! xConfiguration.is()) | |||
1225 | throw RuntimeException(); | |||
1226 | ||||
1227 | const Reference< XComponentContext > xContext( | |||
1228 | ::comphelper::getProcessComponentContext() ); | |||
1229 | SfxWhichIter aSetIterator (rSet); | |||
1230 | sal_uInt16 nItemId (aSetIterator.FirstWhich()); | |||
1231 | ||||
1232 | while (nItemId > 0) | |||
1233 | { | |||
1234 | bool bState (false); | |||
1235 | Reference<XResourceId> xResourceId; | |||
1236 | try | |||
1237 | { | |||
1238 | // Check if the right view is active | |||
1239 | switch (nItemId) | |||
1240 | { | |||
1241 | case SID_LEFT_PANE_IMPRESS(27000 +414): | |||
1242 | xResourceId = ResourceId::create( | |||
1243 | xContext, FrameworkHelper::msLeftImpressPaneURL); | |||
1244 | bState = xConfiguration->hasResource(xResourceId); | |||
1245 | break; | |||
1246 | ||||
1247 | case SID_LEFT_PANE_DRAW(27000 +415): | |||
1248 | xResourceId = ResourceId::create( | |||
1249 | xContext, FrameworkHelper::msLeftDrawPaneURL); | |||
1250 | bState = xConfiguration->hasResource(xResourceId); | |||
1251 | break; | |||
1252 | ||||
1253 | case SID_DRAWINGMODE(27000 +9): | |||
1254 | case SID_NORMAL_MULTI_PANE_GUI(27000 +420): | |||
1255 | case SID_SLIDE_MASTER_MODE(27000 +348): | |||
1256 | xResourceId = ResourceId::createWithAnchorURL( | |||
1257 | xContext, FrameworkHelper::msImpressViewURL, | |||
1258 | FrameworkHelper::msCenterPaneURL); | |||
1259 | bState = xConfiguration->hasResource(xResourceId); | |||
1260 | break; | |||
1261 | ||||
1262 | case SID_SLIDE_SORTER_MULTI_PANE_GUI(27000 +421): | |||
1263 | case SID_SLIDE_SORTER_MODE(27000 +11): | |||
1264 | xResourceId = ResourceId::createWithAnchorURL( | |||
1265 | xContext, | |||
1266 | FrameworkHelper::msSlideSorterURL, | |||
1267 | FrameworkHelper::msCenterPaneURL); | |||
1268 | bState = xConfiguration->hasResource(xResourceId); | |||
1269 | break; | |||
1270 | ||||
1271 | case SID_OUTLINE_MODE(27000 +10): | |||
1272 | xResourceId = ResourceId::createWithAnchorURL( | |||
1273 | xContext, | |||
1274 | FrameworkHelper::msOutlineViewURL, | |||
1275 | FrameworkHelper::msCenterPaneURL); | |||
1276 | bState = xConfiguration->hasResource(xResourceId); | |||
1277 | break; | |||
1278 | ||||
1279 | case SID_HANDOUT_MASTER_MODE(27000 +70): | |||
1280 | xResourceId = ResourceId::createWithAnchorURL( | |||
1281 | xContext, FrameworkHelper::msHandoutViewURL, | |||
1282 | FrameworkHelper::msCenterPaneURL); | |||
1283 | bState = xConfiguration->hasResource(xResourceId); | |||
1284 | break; | |||
1285 | ||||
1286 | case SID_NOTES_MODE(27000 +69): | |||
1287 | case SID_NOTES_MASTER_MODE(27000 +350): | |||
1288 | xResourceId = ResourceId::createWithAnchorURL( | |||
1289 | xContext, FrameworkHelper::msNotesViewURL, | |||
1290 | FrameworkHelper::msCenterPaneURL); | |||
1291 | bState = xConfiguration->hasResource(xResourceId); | |||
1292 | break; | |||
1293 | ||||
1294 | case SID_TOGGLE_TABBAR_VISIBILITY(27000 +13): | |||
1295 | bState = GetUserWantsTabBar(); | |||
1296 | break; | |||
1297 | ||||
1298 | default: | |||
1299 | // Ignore all other items. They are not meant to be | |||
1300 | // handled by us. | |||
1301 | break; | |||
1302 | } | |||
1303 | } | |||
1304 | catch (const DeploymentException&) | |||
1305 | { | |||
1306 | } | |||
1307 | ||||
1308 | // Check if edit mode fits too | |||
1309 | if (bState) | |||
1310 | { | |||
1311 | ViewShell* const pCenterViewShell = FrameworkHelper::Instance(mrBase)->GetViewShell( | |||
1312 | FrameworkHelper::msCenterPaneURL).get(); | |||
1313 | DrawViewShell* const pShell = dynamic_cast<DrawViewShell*>(pCenterViewShell); | |||
1314 | if (pShell) | |||
1315 | { | |||
1316 | switch (nItemId) | |||
1317 | { | |||
1318 | case SID_DRAWINGMODE(27000 +9): | |||
1319 | case SID_NORMAL_MULTI_PANE_GUI(27000 +420): | |||
1320 | case SID_NOTES_MODE(27000 +69): | |||
1321 | bState = pShell->GetEditMode() == EditMode::Page; | |||
1322 | break; | |||
1323 | case SID_SLIDE_MASTER_MODE(27000 +348): | |||
1324 | case SID_NOTES_MASTER_MODE(27000 +350): | |||
1325 | bState = pShell->GetEditMode() == EditMode::MasterPage; | |||
1326 | break; | |||
1327 | } | |||
1328 | } | |||
1329 | } | |||
1330 | ||||
1331 | // And finally set the state. | |||
1332 | rSet.Put(SfxBoolItem(nItemId, bState)); | |||
1333 | ||||
1334 | nItemId = aSetIterator.NextWhich(); | |||
1335 | } | |||
1336 | } | |||
1337 | catch (const RuntimeException&) | |||
1338 | { | |||
1339 | DBG_UNHANDLED_EXCEPTION("sd.view")DbgUnhandledException( DbgGetCaughtException(), __func__, "/home/maarten/src/libreoffice/core/sd/source/ui/view/ViewShellBase.cxx" ":" "1339" ": ", "sd.view" );; | |||
1340 | } | |||
1341 | ||||
1342 | } | |||
1343 | ||||
1344 | } // end of namespace sd | |||
1345 | ||||
1346 | //===== CurrentPageSetter =========================================== | |||
1347 | ||||
1348 | namespace { | |||
1349 | ||||
1350 | CurrentPageSetter::CurrentPageSetter (ViewShellBase& rBase) | |||
1351 | : mrBase(rBase) | |||
1352 | { | |||
1353 | } | |||
1354 | ||||
1355 | void CurrentPageSetter::operator() (bool) | |||
1356 | { | |||
1357 | FrameView* pFrameView = nullptr; | |||
1358 | ||||
1359 | if (mrBase.GetMainViewShell() != nullptr) | |||
1360 | { | |||
1361 | pFrameView = mrBase.GetMainViewShell()->GetFrameView(); | |||
1362 | } | |||
1363 | ||||
1364 | if (pFrameView==nullptr) | |||
1365 | return; | |||
1366 | ||||
1367 | try | |||
1368 | { | |||
1369 | // Get the current page either from the DrawPagesSupplier or the | |||
1370 | // MasterPagesSupplier. | |||
1371 | Any aPage; | |||
1372 | if (pFrameView->GetViewShEditModeOnLoad() == EditMode::Page) | |||
1373 | { | |||
1374 | Reference<drawing::XDrawPagesSupplier> xPagesSupplier ( | |||
1375 | mrBase.GetController()->getModel(), UNO_QUERY_THROW); | |||
1376 | Reference<container::XIndexAccess> xPages ( | |||
1377 | xPagesSupplier->getDrawPages(), UNO_QUERY_THROW); | |||
1378 | aPage = xPages->getByIndex(pFrameView->GetSelectedPageOnLoad()); | |||
1379 | } | |||
1380 | else | |||
1381 | { | |||
1382 | Reference<drawing::XMasterPagesSupplier> xPagesSupplier ( | |||
1383 | mrBase.GetController()->getModel(), UNO_QUERY_THROW); | |||
1384 | Reference<container::XIndexAccess> xPages ( | |||
1385 | xPagesSupplier->getMasterPages(), UNO_QUERY_THROW); | |||
1386 | aPage = xPages->getByIndex(pFrameView->GetSelectedPageOnLoad()); | |||
1387 | } | |||
1388 | // Switch to the page last edited by setting the CurrentPage | |||
1389 | // property. | |||
1390 | Reference<beans::XPropertySet> xSet (mrBase.GetController(), UNO_QUERY_THROW); | |||
1391 | xSet->setPropertyValue ("CurrentPage", aPage); | |||
1392 | } | |||
1393 | catch (const RuntimeException&) | |||
1394 | { | |||
1395 | // We have not been able to set the current page at the main view. | |||
1396 | // This is sad but still leaves us in a valid state. Therefore, | |||
1397 | // this exception is silently ignored. | |||
1398 | } | |||
1399 | catch (const beans::UnknownPropertyException&) | |||
1400 | { | |||
1401 | SAL_WARN("sd.view", "CurrentPage property unknown")do { if (true) { switch (sal_detail_log_report(::SAL_DETAIL_LOG_LEVEL_WARN , "sd.view")) { case SAL_DETAIL_LOG_ACTION_IGNORE: break; case SAL_DETAIL_LOG_ACTION_LOG: if (sizeof ::sal::detail::getResult ( ::sal::detail::StreamStart() << "CurrentPage property unknown" ) == 1) { ::sal_detail_log( (::SAL_DETAIL_LOG_LEVEL_WARN), ("sd.view" ), ("/home/maarten/src/libreoffice/core/sd/source/ui/view/ViewShellBase.cxx" ":" "1401" ": "), ::sal::detail::unwrapStream( ::sal::detail ::StreamStart() << "CurrentPage property unknown"), 0); } else { ::std::ostringstream sal_detail_stream; sal_detail_stream << "CurrentPage property unknown"; ::sal::detail::log( (::SAL_DETAIL_LOG_LEVEL_WARN), ("sd.view"), ("/home/maarten/src/libreoffice/core/sd/source/ui/view/ViewShellBase.cxx" ":" "1401" ": "), sal_detail_stream, 0); }; break; case SAL_DETAIL_LOG_ACTION_FATAL : if (sizeof ::sal::detail::getResult( ::sal::detail::StreamStart () << "CurrentPage property unknown") == 1) { ::sal_detail_log ( (::SAL_DETAIL_LOG_LEVEL_WARN), ("sd.view"), ("/home/maarten/src/libreoffice/core/sd/source/ui/view/ViewShellBase.cxx" ":" "1401" ": "), ::sal::detail::unwrapStream( ::sal::detail ::StreamStart() << "CurrentPage property unknown"), 0); } else { ::std::ostringstream sal_detail_stream; sal_detail_stream << "CurrentPage property unknown"; ::sal::detail::log( (::SAL_DETAIL_LOG_LEVEL_WARN), ("sd.view"), ("/home/maarten/src/libreoffice/core/sd/source/ui/view/ViewShellBase.cxx" ":" "1401" ": "), sal_detail_stream, 0); }; std::abort(); break ; } } } while (false); | |||
1402 | } | |||
1403 | } | |||
1404 | ||||
1405 | } // end of anonymous namespace | |||
1406 | ||||
1407 | //===== FocusForwardingWindow ================================================= | |||
1408 | ||||
1409 | namespace sd { | |||
1410 | namespace { | |||
1411 | ||||
1412 | FocusForwardingWindow::FocusForwardingWindow ( | |||
1413 | vcl::Window& rParentWindow, | |||
1414 | ViewShellBase& rBase) | |||
1415 | : vcl::Window(&rParentWindow, WinBits(WB_CLIPCHILDREN | WB_DIALOGCONTROL)), | |||
1416 | mrBase(rBase) | |||
1417 | { | |||
1418 | SAL_INFO("sd.view", "created FocusForwardingWindow at " << this)do { if (true) { switch (sal_detail_log_report(::SAL_DETAIL_LOG_LEVEL_INFO , "sd.view")) { case SAL_DETAIL_LOG_ACTION_IGNORE: break; case SAL_DETAIL_LOG_ACTION_LOG: if (sizeof ::sal::detail::getResult ( ::sal::detail::StreamStart() << "created FocusForwardingWindow at " << this) == 1) { ::sal_detail_log( (::SAL_DETAIL_LOG_LEVEL_INFO ), ("sd.view"), ("/home/maarten/src/libreoffice/core/sd/source/ui/view/ViewShellBase.cxx" ":" "1418" ": "), ::sal::detail::unwrapStream( ::sal::detail ::StreamStart() << "created FocusForwardingWindow at " << this), 0); } else { ::std::ostringstream sal_detail_stream; sal_detail_stream << "created FocusForwardingWindow at " << this; :: sal::detail::log( (::SAL_DETAIL_LOG_LEVEL_INFO), ("sd.view"), ("/home/maarten/src/libreoffice/core/sd/source/ui/view/ViewShellBase.cxx" ":" "1418" ": "), sal_detail_stream, 0); }; break; case SAL_DETAIL_LOG_ACTION_FATAL : if (sizeof ::sal::detail::getResult( ::sal::detail::StreamStart () << "created FocusForwardingWindow at " << this ) == 1) { ::sal_detail_log( (::SAL_DETAIL_LOG_LEVEL_INFO), ("sd.view" ), ("/home/maarten/src/libreoffice/core/sd/source/ui/view/ViewShellBase.cxx" ":" "1418" ": "), ::sal::detail::unwrapStream( ::sal::detail ::StreamStart() << "created FocusForwardingWindow at " << this), 0); } else { ::std::ostringstream sal_detail_stream; sal_detail_stream << "created FocusForwardingWindow at " << this; :: sal::detail::log( (::SAL_DETAIL_LOG_LEVEL_INFO), ("sd.view"), ("/home/maarten/src/libreoffice/core/sd/source/ui/view/ViewShellBase.cxx" ":" "1418" ": "), sal_detail_stream, 0); }; std::abort(); break ; } } } while (false); | |||
1419 | } | |||
1420 | ||||
1421 | FocusForwardingWindow::~FocusForwardingWindow() | |||
1422 | { | |||
1423 | disposeOnce(); | |||
1424 | } | |||
1425 | ||||
1426 | void FocusForwardingWindow::dispose() | |||
1427 | { | |||
1428 | SAL_INFO("sd.view", "destroyed FocusForwardingWindow at " << this)do { if (true) { switch (sal_detail_log_report(::SAL_DETAIL_LOG_LEVEL_INFO , "sd.view")) { case SAL_DETAIL_LOG_ACTION_IGNORE: break; case SAL_DETAIL_LOG_ACTION_LOG: if (sizeof ::sal::detail::getResult ( ::sal::detail::StreamStart() << "destroyed FocusForwardingWindow at " << this) == 1) { ::sal_detail_log( (::SAL_DETAIL_LOG_LEVEL_INFO ), ("sd.view"), ("/home/maarten/src/libreoffice/core/sd/source/ui/view/ViewShellBase.cxx" ":" "1428" ": "), ::sal::detail::unwrapStream( ::sal::detail ::StreamStart() << "destroyed FocusForwardingWindow at " << this), 0); } else { ::std::ostringstream sal_detail_stream ; sal_detail_stream << "destroyed FocusForwardingWindow at " << this; ::sal::detail::log( (::SAL_DETAIL_LOG_LEVEL_INFO ), ("sd.view"), ("/home/maarten/src/libreoffice/core/sd/source/ui/view/ViewShellBase.cxx" ":" "1428" ": "), sal_detail_stream, 0); }; break; case SAL_DETAIL_LOG_ACTION_FATAL : if (sizeof ::sal::detail::getResult( ::sal::detail::StreamStart () << "destroyed FocusForwardingWindow at " << this ) == 1) { ::sal_detail_log( (::SAL_DETAIL_LOG_LEVEL_INFO), ("sd.view" ), ("/home/maarten/src/libreoffice/core/sd/source/ui/view/ViewShellBase.cxx" ":" "1428" ": "), ::sal::detail::unwrapStream( ::sal::detail ::StreamStart() << "destroyed FocusForwardingWindow at " << this), 0); } else { ::std::ostringstream sal_detail_stream ; sal_detail_stream << "destroyed FocusForwardingWindow at " << this; ::sal::detail::log( (::SAL_DETAIL_LOG_LEVEL_INFO ), ("sd.view"), ("/home/maarten/src/libreoffice/core/sd/source/ui/view/ViewShellBase.cxx" ":" "1428" ": "), sal_detail_stream, 0); }; std::abort(); break ; } } } while (false); | |||
1429 | vcl::Window::dispose(); | |||
1430 | } | |||
1431 | ||||
1432 | void FocusForwardingWindow::KeyInput (const KeyEvent& rKEvt) | |||
1433 | { | |||
1434 | std::shared_ptr<ViewShell> pViewShell = mrBase.GetMainViewShell(); | |||
1435 | if (pViewShell != nullptr) | |||
1436 | { | |||
1437 | vcl::Window* pWindow = pViewShell->GetActiveWindow(); | |||
1438 | if (pWindow != nullptr) | |||
1439 | { | |||
1440 | // Forward the focus so that the window is called directly the | |||
1441 | // next time. | |||
1442 | pWindow->GrabFocus(); | |||
1443 | // Forward the key press as well. | |||
1444 | pWindow->KeyInput(rKEvt); | |||
1445 | } | |||
1446 | } | |||
1447 | } | |||
1448 | ||||
1449 | void FocusForwardingWindow::Command (const CommandEvent& rEvent) | |||
1450 | { | |||
1451 | std::shared_ptr<ViewShell> pViewShell = mrBase.GetMainViewShell(); | |||
1452 | if (pViewShell != nullptr) | |||
1453 | { | |||
1454 | vcl::Window* pWindow = pViewShell->GetActiveWindow(); | |||
1455 | if (pWindow != nullptr) | |||
1456 | { | |||
1457 | pWindow->Command(rEvent); | |||
1458 | } | |||
1459 | } | |||
1460 | } | |||
1461 | ||||
1462 | } // end of anonymous namespace | |||
1463 | ||||
1464 | } // end of namespace sd | |||
1465 | ||||
1466 | /* 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 |