Bug Summary

File:home/maarten/src/libreoffice/core/include/rtl/ref.hxx
Warning:line 192, column 9
Use of memory after it is freed

Annotated Source Code

Press '?' to see keyboard shortcuts

clang -cc1 -cc1 -triple x86_64-unknown-linux-gnu -analyze -disable-free -disable-llvm-verifier -discard-value-names -main-file-name viewshel.cxx -analyzer-store=region -analyzer-opt-analyze-nested-blocks -analyzer-checker=core -analyzer-checker=apiModeling -analyzer-checker=unix -analyzer-checker=deadcode -analyzer-checker=cplusplus -analyzer-checker=security.insecureAPI.UncheckedReturn -analyzer-checker=security.insecureAPI.getpw -analyzer-checker=security.insecureAPI.gets -analyzer-checker=security.insecureAPI.mktemp -analyzer-checker=security.insecureAPI.mkstemp -analyzer-checker=security.insecureAPI.vfork -analyzer-checker=nullability.NullPassedToNonnull -analyzer-checker=nullability.NullReturnedFromNonnull -analyzer-output plist -w -setup-static-analyzer -mrelocation-model pic -pic-level 2 -mframe-pointer=all -fmath-errno -fno-rounding-math -mconstructor-aliases -munwind-tables -target-cpu x86-64 -fno-split-dwarf-inlining -debugger-tuning=gdb -resource-dir /usr/lib64/clang/11.0.0 -isystem /usr/include/libxml2 -isystem /usr/include/dbus-1.0 -isystem /usr/lib64/dbus-1.0/include -D BOOST_ERROR_CODE_HEADER_ONLY -D BOOST_SYSTEM_NO_DEPRECATED -D CPPU_ENV=gcc3 -D LINUX -D OSL_DEBUG_LEVEL=1 -D SAL_LOG_INFO -D SAL_LOG_WARN -D UNIX -D UNX -D X86_64 -D _PTHREADS -D _REENTRANT -D SD_DLLIMPLEMENTATION -D SDUI_DLL_NAME="libsduilo.so" -D SYSTEM_LIBXML -D ENABLE_SDREMOTE -D ENABLE_SDREMOTE_BLUETOOTH -D EXCEPTIONS_ON -D LIBO_INTERNAL_ONLY -I /home/maarten/src/libreoffice/core/workdir/UnpackedTarball/icu/source -I /home/maarten/src/libreoffice/core/workdir/UnpackedTarball/icu/source/i18n -I /home/maarten/src/libreoffice/core/workdir/UnpackedTarball/icu/source/common -I /home/maarten/src/libreoffice/core/external/boost/include -I /home/maarten/src/libreoffice/core/workdir/UnpackedTarball/boost -I /home/maarten/src/libreoffice/core/external/bluez_bluetooth/inc -I /home/maarten/src/libreoffice/core/include -I /usr/lib/jvm/java-11-openjdk-11.0.9.10-0.0.ea.fc33.x86_64/include -I /usr/lib/jvm/java-11-openjdk-11.0.9.10-0.0.ea.fc33.x86_64/include/linux -I /home/maarten/src/libreoffice/core/config_host -I /home/maarten/src/libreoffice/core/sd/inc -I /home/maarten/src/libreoffice/core/sd/source/ui/inc -I /home/maarten/src/libreoffice/core/sd/source/ui/slidesorter/inc -I /home/maarten/src/libreoffice/core/workdir/SdiTarget/sd/sdi -I /home/maarten/src/libreoffice/core/workdir/CustomTarget/officecfg/registry -I /home/maarten/src/libreoffice/core/workdir/CustomTarget/oox/generated -I /home/maarten/src/libreoffice/core/workdir/UnoApiHeadersTarget/udkapi/normal -I /home/maarten/src/libreoffice/core/workdir/UnoApiHeadersTarget/offapi/normal -I /usr/include/glib-2.0 -I /usr/lib64/glib-2.0/include -internal-isystem /usr/bin/../lib/gcc/x86_64-redhat-linux/10/../../../../include/c++/10 -internal-isystem /usr/bin/../lib/gcc/x86_64-redhat-linux/10/../../../../include/c++/10/x86_64-redhat-linux -internal-isystem /usr/bin/../lib/gcc/x86_64-redhat-linux/10/../../../../include/c++/10/backward -internal-isystem /usr/local/include -internal-isystem /usr/lib64/clang/11.0.0/include -internal-externc-isystem /include -internal-externc-isystem /usr/include -O0 -Wno-missing-braces -std=c++17 -fdeprecated-macro -fdebug-compilation-dir /home/maarten/src/libreoffice/core -ferror-limit 19 -fvisibility hidden -fvisibility-inlines-hidden -stack-protector 2 -fgnuc-version=4.2.1 -fcxx-exceptions -fexceptions -debug-info-kind=constructor -analyzer-output=html -faddrsig -o /home/maarten/tmp/wis/scan-build-libreoffice/output/report/2020-10-07-141433-9725-1 -x c++ /home/maarten/src/libreoffice/core/sd/source/ui/view/viewshel.cxx

/home/maarten/src/libreoffice/core/sd/source/ui/view/viewshel.cxx

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 <memory>
21#include <ViewShell.hxx>
22#include <ViewShellImplementation.hxx>
23#include <createtableobjectbar.hxx>
24
25#include <ViewShellBase.hxx>
26#include <ShellFactory.hxx>
27#include <DrawController.hxx>
28#include <LayerTabBar.hxx>
29
30#include <sal/log.hxx>
31#include <sfx2/viewfrm.hxx>
32#include <sfx2/bindings.hxx>
33#include <sfx2/dispatch.hxx>
34#include <vcl/commandevent.hxx>
35#include <vcl/scrbar.hxx>
36#include <svl/eitem.hxx>
37#include <svx/ruler.hxx>
38#include <svx/svxids.hrc>
39#include <svx/fmshell.hxx>
40#include <WindowUpdater.hxx>
41#include <sdxfer.hxx>
42
43#include <app.hrc>
44
45#include <OutlineView.hxx>
46#include <DrawViewShell.hxx>
47#include <DrawDocShell.hxx>
48#include <slideshow.hxx>
49#include <drawdoc.hxx>
50#include <sdpage.hxx>
51#include <zoomlist.hxx>
52#include <FrameView.hxx>
53#include <BezierObjectBar.hxx>
54#include <TextObjectBar.hxx>
55#include <GraphicObjectBar.hxx>
56#include <MediaObjectBar.hxx>
57#include <SlideSorter.hxx>
58#include <SlideSorterViewShell.hxx>
59#include <ViewShellManager.hxx>
60#include <FormShellManager.hxx>
61#include <svx/extrusionbar.hxx>
62#include <svx/fontworkbar.hxx>
63#include <svx/svdoutl.hxx>
64#include <tools/svborder.hxx>
65#include <comphelper/lok.hxx>
66
67#include <svl/slstitm.hxx>
68#include <sfx2/request.hxx>
69#include <SpellDialogChildWindow.hxx>
70#include <controller/SlideSorterController.hxx>
71#include <controller/SlsPageSelector.hxx>
72#include <controller/SlsSelectionObserver.hxx>
73#include <view/SlideSorterView.hxx>
74
75#include <basegfx/utils/zoomtools.hxx>
76
77#include <Window.hxx>
78#include <fupoor.hxx>
79#include <futext.hxx>
80
81#include <editeng/numitem.hxx>
82#include <editeng/eeitem.hxx>
83#include <editeng/editview.hxx>
84#include <editeng/editeng.hxx>
85#include <svl/intitem.hxx>
86#include <svl/poolitem.hxx>
87#include <strings.hxx>
88#include <sdmod.hxx>
89#include <AccessibleDocumentViewBase.hxx>
90
91using namespace ::com::sun::star;
92using namespace ::com::sun::star::uno;
93using namespace ::com::sun::star::presentation;
94
95namespace {
96
97class ViewShellObjectBarFactory
98 : public ::sd::ShellFactory<SfxShell>
99{
100public:
101 explicit ViewShellObjectBarFactory (::sd::ViewShell& rViewShell);
102 virtual SfxShell* CreateShell( ::sd::ShellId nId ) override;
103 virtual void ReleaseShell (SfxShell* pShell) override;
104private:
105 ::sd::ViewShell& mrViewShell;
106};
107
108} // end of anonymous namespace
109
110namespace sd {
111
112bool ViewShell::IsPageFlipMode() const
113{
114 return dynamic_cast< const DrawViewShell *>( this ) != nullptr && mpContentWindow &&
115 mpContentWindow->GetVisibleHeight() >= 1.0;
116}
117
118SfxViewFrame* ViewShell::GetViewFrame() const
119{
120 const SfxViewShell* pViewShell = GetViewShell();
121 if (pViewShell != nullptr)
122 {
123 return pViewShell->GetViewFrame();
124 }
125 else
126 {
127 OSL_ASSERT (GetViewShell()!=nullptr)do { if (true && (!(GetViewShell()!=nullptr))) { sal_detail_logFormat
((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.osl"), ("/home/maarten/src/libreoffice/core/sd/source/ui/view/viewshel.cxx"
":" "127" ": "), "OSL_ASSERT: %s", "GetViewShell()!=nullptr"
); } } while (false)
;
128 return nullptr;
129 }
130}
131
132/// declare SFX-Slotmap and standard interface
133
134ViewShell::ViewShell( vcl::Window* pParentWindow, ViewShellBase& rViewShellBase)
135: SfxShell(&rViewShellBase)
136, mpParentWindow(pParentWindow)
137{
138 construct();
139}
140
141ViewShell::~ViewShell()
142{
143 // Keep the content window from accessing in its destructor the
144 // WindowUpdater.
145 if (mpContentWindow)
1
Taking false branch
146 mpContentWindow->SetViewShell(nullptr);
147
148 mpZoomList.reset();
149
150 mpLayerTabBar.disposeAndClear();
2
Calling 'VclPtr::disposeAndClear'
151
152 if (mpImpl->mpSubShellFactory)
153 GetViewShellBase().GetViewShellManager()->RemoveSubShellFactory(
154 this,mpImpl->mpSubShellFactory);
155
156 if (mpContentWindow)
157 {
158 SAL_INFO(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() << "destroying mpContentWindow at "
<< mpContentWindow.get() << " with parent " <<
mpContentWindow->GetParent()) == 1) { ::sal_detail_log( (
::SAL_DETAIL_LOG_LEVEL_INFO), ("sd.view"), ("/home/maarten/src/libreoffice/core/sd/source/ui/view/viewshel.cxx"
":" "161" ": "), ::sal::detail::unwrapStream( ::sal::detail::
StreamStart() << "destroying mpContentWindow at " <<
mpContentWindow.get() << " with parent " << mpContentWindow
->GetParent()), 0); } else { ::std::ostringstream sal_detail_stream
; sal_detail_stream << "destroying mpContentWindow at "
<< mpContentWindow.get() << " with parent " <<
mpContentWindow->GetParent(); ::sal::detail::log( (::SAL_DETAIL_LOG_LEVEL_INFO
), ("sd.view"), ("/home/maarten/src/libreoffice/core/sd/source/ui/view/viewshel.cxx"
":" "161" ": "), sal_detail_stream, 0); }; break; case SAL_DETAIL_LOG_ACTION_FATAL
: if (sizeof ::sal::detail::getResult( ::sal::detail::StreamStart
() << "destroying mpContentWindow at " << mpContentWindow
.get() << " with parent " << mpContentWindow->
GetParent()) == 1) { ::sal_detail_log( (::SAL_DETAIL_LOG_LEVEL_INFO
), ("sd.view"), ("/home/maarten/src/libreoffice/core/sd/source/ui/view/viewshel.cxx"
":" "161" ": "), ::sal::detail::unwrapStream( ::sal::detail::
StreamStart() << "destroying mpContentWindow at " <<
mpContentWindow.get() << " with parent " << mpContentWindow
->GetParent()), 0); } else { ::std::ostringstream sal_detail_stream
; sal_detail_stream << "destroying mpContentWindow at "
<< mpContentWindow.get() << " with parent " <<
mpContentWindow->GetParent(); ::sal::detail::log( (::SAL_DETAIL_LOG_LEVEL_INFO
), ("sd.view"), ("/home/maarten/src/libreoffice/core/sd/source/ui/view/viewshel.cxx"
":" "161" ": "), sal_detail_stream, 0); }; std::abort(); break
; } } } while (false)
159 "sd.view",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() << "destroying mpContentWindow at "
<< mpContentWindow.get() << " with parent " <<
mpContentWindow->GetParent()) == 1) { ::sal_detail_log( (
::SAL_DETAIL_LOG_LEVEL_INFO), ("sd.view"), ("/home/maarten/src/libreoffice/core/sd/source/ui/view/viewshel.cxx"
":" "161" ": "), ::sal::detail::unwrapStream( ::sal::detail::
StreamStart() << "destroying mpContentWindow at " <<
mpContentWindow.get() << " with parent " << mpContentWindow
->GetParent()), 0); } else { ::std::ostringstream sal_detail_stream
; sal_detail_stream << "destroying mpContentWindow at "
<< mpContentWindow.get() << " with parent " <<
mpContentWindow->GetParent(); ::sal::detail::log( (::SAL_DETAIL_LOG_LEVEL_INFO
), ("sd.view"), ("/home/maarten/src/libreoffice/core/sd/source/ui/view/viewshel.cxx"
":" "161" ": "), sal_detail_stream, 0); }; break; case SAL_DETAIL_LOG_ACTION_FATAL
: if (sizeof ::sal::detail::getResult( ::sal::detail::StreamStart
() << "destroying mpContentWindow at " << mpContentWindow
.get() << " with parent " << mpContentWindow->
GetParent()) == 1) { ::sal_detail_log( (::SAL_DETAIL_LOG_LEVEL_INFO
), ("sd.view"), ("/home/maarten/src/libreoffice/core/sd/source/ui/view/viewshel.cxx"
":" "161" ": "), ::sal::detail::unwrapStream( ::sal::detail::
StreamStart() << "destroying mpContentWindow at " <<
mpContentWindow.get() << " with parent " << mpContentWindow
->GetParent()), 0); } else { ::std::ostringstream sal_detail_stream
; sal_detail_stream << "destroying mpContentWindow at "
<< mpContentWindow.get() << " with parent " <<
mpContentWindow->GetParent(); ::sal::detail::log( (::SAL_DETAIL_LOG_LEVEL_INFO
), ("sd.view"), ("/home/maarten/src/libreoffice/core/sd/source/ui/view/viewshel.cxx"
":" "161" ": "), sal_detail_stream, 0); }; std::abort(); break
; } } } while (false)
160 "destroying mpContentWindow at " << mpContentWindow.get()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() << "destroying mpContentWindow at "
<< mpContentWindow.get() << " with parent " <<
mpContentWindow->GetParent()) == 1) { ::sal_detail_log( (
::SAL_DETAIL_LOG_LEVEL_INFO), ("sd.view"), ("/home/maarten/src/libreoffice/core/sd/source/ui/view/viewshel.cxx"
":" "161" ": "), ::sal::detail::unwrapStream( ::sal::detail::
StreamStart() << "destroying mpContentWindow at " <<
mpContentWindow.get() << " with parent " << mpContentWindow
->GetParent()), 0); } else { ::std::ostringstream sal_detail_stream
; sal_detail_stream << "destroying mpContentWindow at "
<< mpContentWindow.get() << " with parent " <<
mpContentWindow->GetParent(); ::sal::detail::log( (::SAL_DETAIL_LOG_LEVEL_INFO
), ("sd.view"), ("/home/maarten/src/libreoffice/core/sd/source/ui/view/viewshel.cxx"
":" "161" ": "), sal_detail_stream, 0); }; break; case SAL_DETAIL_LOG_ACTION_FATAL
: if (sizeof ::sal::detail::getResult( ::sal::detail::StreamStart
() << "destroying mpContentWindow at " << mpContentWindow
.get() << " with parent " << mpContentWindow->
GetParent()) == 1) { ::sal_detail_log( (::SAL_DETAIL_LOG_LEVEL_INFO
), ("sd.view"), ("/home/maarten/src/libreoffice/core/sd/source/ui/view/viewshel.cxx"
":" "161" ": "), ::sal::detail::unwrapStream( ::sal::detail::
StreamStart() << "destroying mpContentWindow at " <<
mpContentWindow.get() << " with parent " << mpContentWindow
->GetParent()), 0); } else { ::std::ostringstream sal_detail_stream
; sal_detail_stream << "destroying mpContentWindow at "
<< mpContentWindow.get() << " with parent " <<
mpContentWindow->GetParent(); ::sal::detail::log( (::SAL_DETAIL_LOG_LEVEL_INFO
), ("sd.view"), ("/home/maarten/src/libreoffice/core/sd/source/ui/view/viewshel.cxx"
":" "161" ": "), sal_detail_stream, 0); }; std::abort(); break
; } } } while (false)
161 << " with parent " << mpContentWindow->GetParent())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() << "destroying mpContentWindow at "
<< mpContentWindow.get() << " with parent " <<
mpContentWindow->GetParent()) == 1) { ::sal_detail_log( (
::SAL_DETAIL_LOG_LEVEL_INFO), ("sd.view"), ("/home/maarten/src/libreoffice/core/sd/source/ui/view/viewshel.cxx"
":" "161" ": "), ::sal::detail::unwrapStream( ::sal::detail::
StreamStart() << "destroying mpContentWindow at " <<
mpContentWindow.get() << " with parent " << mpContentWindow
->GetParent()), 0); } else { ::std::ostringstream sal_detail_stream
; sal_detail_stream << "destroying mpContentWindow at "
<< mpContentWindow.get() << " with parent " <<
mpContentWindow->GetParent(); ::sal::detail::log( (::SAL_DETAIL_LOG_LEVEL_INFO
), ("sd.view"), ("/home/maarten/src/libreoffice/core/sd/source/ui/view/viewshel.cxx"
":" "161" ": "), sal_detail_stream, 0); }; break; case SAL_DETAIL_LOG_ACTION_FATAL
: if (sizeof ::sal::detail::getResult( ::sal::detail::StreamStart
() << "destroying mpContentWindow at " << mpContentWindow
.get() << " with parent " << mpContentWindow->
GetParent()) == 1) { ::sal_detail_log( (::SAL_DETAIL_LOG_LEVEL_INFO
), ("sd.view"), ("/home/maarten/src/libreoffice/core/sd/source/ui/view/viewshel.cxx"
":" "161" ": "), ::sal::detail::unwrapStream( ::sal::detail::
StreamStart() << "destroying mpContentWindow at " <<
mpContentWindow.get() << " with parent " << mpContentWindow
->GetParent()), 0); } else { ::std::ostringstream sal_detail_stream
; sal_detail_stream << "destroying mpContentWindow at "
<< mpContentWindow.get() << " with parent " <<
mpContentWindow->GetParent(); ::sal::detail::log( (::SAL_DETAIL_LOG_LEVEL_INFO
), ("sd.view"), ("/home/maarten/src/libreoffice/core/sd/source/ui/view/viewshel.cxx"
":" "161" ": "), sal_detail_stream, 0); }; std::abort(); break
; } } } while (false)
;
162 mpContentWindow.disposeAndClear();
163 }
164
165 mpScrollBarBox.disposeAndClear();
166 mpVerticalRuler.disposeAndClear();
167 mpHorizontalRuler.disposeAndClear();
168 mpVerticalScrollBar.disposeAndClear();
169 mpHorizontalScrollBar.disposeAndClear();
170}
171
172/**
173 * common initialization part of both constructors
174 */
175void ViewShell::construct()
176{
177 mbHasRulers = false;
178 mpActiveWindow = nullptr;
179 mpView = nullptr;
180 mpFrameView = nullptr;
181 mpZoomList = nullptr;
182 mbStartShowWithDialog = false;
183 mnPrintedHandoutPageNum = 1;
184 mnPrintedHandoutPageCount = 0;
185 mpWindowUpdater.reset( new ::sd::WindowUpdater() );
186 mpImpl.reset(new Implementation(*this));
187 meShellType = ST_NONE;
188
189 OSL_ASSERT (GetViewShell()!=nullptr)do { if (true && (!(GetViewShell()!=nullptr))) { sal_detail_logFormat
((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.osl"), ("/home/maarten/src/libreoffice/core/sd/source/ui/view/viewshel.cxx"
":" "189" ": "), "OSL_ASSERT: %s", "GetViewShell()!=nullptr"
); } } while (false)
;
190
191 if (IsMainViewShell())
192 GetDocSh()->Connect (this);
193
194 mpZoomList.reset( new ZoomList( this ) );
195
196 mpContentWindow.reset(VclPtr< ::sd::Window >::Create(GetParentWindow()));
197 SetActiveWindow (mpContentWindow.get());
198
199 GetParentWindow()->SetBackground (Wallpaper());
200 mpContentWindow->SetBackground (Wallpaper());
201 mpContentWindow->SetCenterAllowed(true);
202 mpContentWindow->SetViewShell(this);
203 mpContentWindow->SetPosSizePixel(
204 GetParentWindow()->GetPosPixel(),GetParentWindow()->GetSizePixel());
205
206 if ( ! GetDocSh()->IsPreview())
207 {
208 // Create scroll bars and the filler between the scroll bars.
209 mpHorizontalScrollBar.reset (VclPtr<ScrollBar>::Create(GetParentWindow(), WinBits(WB_HSCROLL | WB_DRAG)));
210 mpHorizontalScrollBar->EnableRTL (false);
211 mpHorizontalScrollBar->SetRange(Range(0, 32000));
212 mpHorizontalScrollBar->SetScrollHdl(LINK(this, ViewShell, HScrollHdl)::tools::detail::makeLink( ::tools::detail::castTo<ViewShell
*>(this), &ViewShell::LinkStubHScrollHdl)
);
213
214 mpVerticalScrollBar.reset (VclPtr<ScrollBar>::Create(GetParentWindow(), WinBits(WB_VSCROLL | WB_DRAG)));
215 mpVerticalScrollBar->SetRange(Range(0, 32000));
216 mpVerticalScrollBar->SetScrollHdl(LINK(this, ViewShell, VScrollHdl)::tools::detail::makeLink( ::tools::detail::castTo<ViewShell
*>(this), &ViewShell::LinkStubVScrollHdl)
);
217
218 mpScrollBarBox.reset(VclPtr<ScrollBarBox>::Create(GetParentWindow(), WB_SIZEABLE));
219 }
220
221 SetName ("ViewShell");
222
223 GetDoc()->StartOnlineSpelling(false);
224
225 mpWindowUpdater->SetDocument (GetDoc());
226
227 // Re-initialize the spell dialog.
228 ::sd::SpellDialogChildWindow* pSpellDialog =
229 static_cast< ::sd::SpellDialogChildWindow*> (
230 GetViewFrame()->GetChildWindow (
231 ::sd::SpellDialogChildWindow::GetChildWindowId()));
232 if (pSpellDialog != nullptr)
233 pSpellDialog->InvalidateSpellDialog();
234
235 // Register the sub shell factory.
236 mpImpl->mpSubShellFactory = std::make_shared<ViewShellObjectBarFactory>(*this);
237 GetViewShellBase().GetViewShellManager()->AddSubShellFactory(this,mpImpl->mpSubShellFactory);
238}
239
240void ViewShell::doShow()
241{
242 mpContentWindow->Show();
243 static_cast< vcl::Window*>(mpContentWindow.get())->Resize();
244 SAL_INFO(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() << "content window has size "
<< mpContentWindow->GetSizePixel().Width() <<
" " << mpContentWindow->GetSizePixel().Height()) ==
1) { ::sal_detail_log( (::SAL_DETAIL_LOG_LEVEL_INFO), ("sd.view"
), ("/home/maarten/src/libreoffice/core/sd/source/ui/view/viewshel.cxx"
":" "247" ": "), ::sal::detail::unwrapStream( ::sal::detail::
StreamStart() << "content window has size " << mpContentWindow
->GetSizePixel().Width() << " " << mpContentWindow
->GetSizePixel().Height()), 0); } else { ::std::ostringstream
sal_detail_stream; sal_detail_stream << "content window has size "
<< mpContentWindow->GetSizePixel().Width() <<
" " << mpContentWindow->GetSizePixel().Height(); ::
sal::detail::log( (::SAL_DETAIL_LOG_LEVEL_INFO), ("sd.view"),
("/home/maarten/src/libreoffice/core/sd/source/ui/view/viewshel.cxx"
":" "247" ": "), sal_detail_stream, 0); }; break; case SAL_DETAIL_LOG_ACTION_FATAL
: if (sizeof ::sal::detail::getResult( ::sal::detail::StreamStart
() << "content window has size " << mpContentWindow
->GetSizePixel().Width() << " " << mpContentWindow
->GetSizePixel().Height()) == 1) { ::sal_detail_log( (::SAL_DETAIL_LOG_LEVEL_INFO
), ("sd.view"), ("/home/maarten/src/libreoffice/core/sd/source/ui/view/viewshel.cxx"
":" "247" ": "), ::sal::detail::unwrapStream( ::sal::detail::
StreamStart() << "content window has size " << mpContentWindow
->GetSizePixel().Width() << " " << mpContentWindow
->GetSizePixel().Height()), 0); } else { ::std::ostringstream
sal_detail_stream; sal_detail_stream << "content window has size "
<< mpContentWindow->GetSizePixel().Width() <<
" " << mpContentWindow->GetSizePixel().Height(); ::
sal::detail::log( (::SAL_DETAIL_LOG_LEVEL_INFO), ("sd.view"),
("/home/maarten/src/libreoffice/core/sd/source/ui/view/viewshel.cxx"
":" "247" ": "), sal_detail_stream, 0); }; std::abort(); break
; } } } while (false)
245 "sd.view",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() << "content window has size "
<< mpContentWindow->GetSizePixel().Width() <<
" " << mpContentWindow->GetSizePixel().Height()) ==
1) { ::sal_detail_log( (::SAL_DETAIL_LOG_LEVEL_INFO), ("sd.view"
), ("/home/maarten/src/libreoffice/core/sd/source/ui/view/viewshel.cxx"
":" "247" ": "), ::sal::detail::unwrapStream( ::sal::detail::
StreamStart() << "content window has size " << mpContentWindow
->GetSizePixel().Width() << " " << mpContentWindow
->GetSizePixel().Height()), 0); } else { ::std::ostringstream
sal_detail_stream; sal_detail_stream << "content window has size "
<< mpContentWindow->GetSizePixel().Width() <<
" " << mpContentWindow->GetSizePixel().Height(); ::
sal::detail::log( (::SAL_DETAIL_LOG_LEVEL_INFO), ("sd.view"),
("/home/maarten/src/libreoffice/core/sd/source/ui/view/viewshel.cxx"
":" "247" ": "), sal_detail_stream, 0); }; break; case SAL_DETAIL_LOG_ACTION_FATAL
: if (sizeof ::sal::detail::getResult( ::sal::detail::StreamStart
() << "content window has size " << mpContentWindow
->GetSizePixel().Width() << " " << mpContentWindow
->GetSizePixel().Height()) == 1) { ::sal_detail_log( (::SAL_DETAIL_LOG_LEVEL_INFO
), ("sd.view"), ("/home/maarten/src/libreoffice/core/sd/source/ui/view/viewshel.cxx"
":" "247" ": "), ::sal::detail::unwrapStream( ::sal::detail::
StreamStart() << "content window has size " << mpContentWindow
->GetSizePixel().Width() << " " << mpContentWindow
->GetSizePixel().Height()), 0); } else { ::std::ostringstream
sal_detail_stream; sal_detail_stream << "content window has size "
<< mpContentWindow->GetSizePixel().Width() <<
" " << mpContentWindow->GetSizePixel().Height(); ::
sal::detail::log( (::SAL_DETAIL_LOG_LEVEL_INFO), ("sd.view"),
("/home/maarten/src/libreoffice/core/sd/source/ui/view/viewshel.cxx"
":" "247" ": "), sal_detail_stream, 0); }; std::abort(); break
; } } } while (false)
246 "content window has size " << mpContentWindow->GetSizePixel().Width()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() << "content window has size "
<< mpContentWindow->GetSizePixel().Width() <<
" " << mpContentWindow->GetSizePixel().Height()) ==
1) { ::sal_detail_log( (::SAL_DETAIL_LOG_LEVEL_INFO), ("sd.view"
), ("/home/maarten/src/libreoffice/core/sd/source/ui/view/viewshel.cxx"
":" "247" ": "), ::sal::detail::unwrapStream( ::sal::detail::
StreamStart() << "content window has size " << mpContentWindow
->GetSizePixel().Width() << " " << mpContentWindow
->GetSizePixel().Height()), 0); } else { ::std::ostringstream
sal_detail_stream; sal_detail_stream << "content window has size "
<< mpContentWindow->GetSizePixel().Width() <<
" " << mpContentWindow->GetSizePixel().Height(); ::
sal::detail::log( (::SAL_DETAIL_LOG_LEVEL_INFO), ("sd.view"),
("/home/maarten/src/libreoffice/core/sd/source/ui/view/viewshel.cxx"
":" "247" ": "), sal_detail_stream, 0); }; break; case SAL_DETAIL_LOG_ACTION_FATAL
: if (sizeof ::sal::detail::getResult( ::sal::detail::StreamStart
() << "content window has size " << mpContentWindow
->GetSizePixel().Width() << " " << mpContentWindow
->GetSizePixel().Height()) == 1) { ::sal_detail_log( (::SAL_DETAIL_LOG_LEVEL_INFO
), ("sd.view"), ("/home/maarten/src/libreoffice/core/sd/source/ui/view/viewshel.cxx"
":" "247" ": "), ::sal::detail::unwrapStream( ::sal::detail::
StreamStart() << "content window has size " << mpContentWindow
->GetSizePixel().Width() << " " << mpContentWindow
->GetSizePixel().Height()), 0); } else { ::std::ostringstream
sal_detail_stream; sal_detail_stream << "content window has size "
<< mpContentWindow->GetSizePixel().Width() <<
" " << mpContentWindow->GetSizePixel().Height(); ::
sal::detail::log( (::SAL_DETAIL_LOG_LEVEL_INFO), ("sd.view"),
("/home/maarten/src/libreoffice/core/sd/source/ui/view/viewshel.cxx"
":" "247" ": "), sal_detail_stream, 0); }; std::abort(); break
; } } } while (false)
247 << " " << mpContentWindow->GetSizePixel().Height())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() << "content window has size "
<< mpContentWindow->GetSizePixel().Width() <<
" " << mpContentWindow->GetSizePixel().Height()) ==
1) { ::sal_detail_log( (::SAL_DETAIL_LOG_LEVEL_INFO), ("sd.view"
), ("/home/maarten/src/libreoffice/core/sd/source/ui/view/viewshel.cxx"
":" "247" ": "), ::sal::detail::unwrapStream( ::sal::detail::
StreamStart() << "content window has size " << mpContentWindow
->GetSizePixel().Width() << " " << mpContentWindow
->GetSizePixel().Height()), 0); } else { ::std::ostringstream
sal_detail_stream; sal_detail_stream << "content window has size "
<< mpContentWindow->GetSizePixel().Width() <<
" " << mpContentWindow->GetSizePixel().Height(); ::
sal::detail::log( (::SAL_DETAIL_LOG_LEVEL_INFO), ("sd.view"),
("/home/maarten/src/libreoffice/core/sd/source/ui/view/viewshel.cxx"
":" "247" ": "), sal_detail_stream, 0); }; break; case SAL_DETAIL_LOG_ACTION_FATAL
: if (sizeof ::sal::detail::getResult( ::sal::detail::StreamStart
() << "content window has size " << mpContentWindow
->GetSizePixel().Width() << " " << mpContentWindow
->GetSizePixel().Height()) == 1) { ::sal_detail_log( (::SAL_DETAIL_LOG_LEVEL_INFO
), ("sd.view"), ("/home/maarten/src/libreoffice/core/sd/source/ui/view/viewshel.cxx"
":" "247" ": "), ::sal::detail::unwrapStream( ::sal::detail::
StreamStart() << "content window has size " << mpContentWindow
->GetSizePixel().Width() << " " << mpContentWindow
->GetSizePixel().Height()), 0); } else { ::std::ostringstream
sal_detail_stream; sal_detail_stream << "content window has size "
<< mpContentWindow->GetSizePixel().Width() <<
" " << mpContentWindow->GetSizePixel().Height(); ::
sal::detail::log( (::SAL_DETAIL_LOG_LEVEL_INFO), ("sd.view"),
("/home/maarten/src/libreoffice/core/sd/source/ui/view/viewshel.cxx"
":" "247" ": "), sal_detail_stream, 0); }; std::abort(); break
; } } } while (false)
;
248
249 if ( ! GetDocSh()->IsPreview())
250 {
251 // Show scroll bars
252 mpHorizontalScrollBar->Show();
253
254 mpVerticalScrollBar->Show();
255 maScrBarWH = Size(
256 mpVerticalScrollBar->GetSizePixel().Width(),
257 mpHorizontalScrollBar->GetSizePixel().Height());
258
259 mpScrollBarBox->Show();
260 }
261
262 GetParentWindow()->Show();
263}
264
265void ViewShell::Init (bool bIsMainViewShell)
266{
267 mpImpl->mbIsInitialized = true;
268 SetIsMainViewShell(bIsMainViewShell);
269 if (bIsMainViewShell)
270 SetActiveWindow (mpContentWindow.get());
271}
272
273void ViewShell::Exit()
274{
275 sd::View* pView = GetView();
276 if (pView!=nullptr && pView->IsTextEdit())
277 {
278 pView->SdrEndTextEdit();
279 pView->UnmarkAll();
280 }
281
282 Deactivate (true);
283
284 if (IsMainViewShell())
285 GetDocSh()->Disconnect(this);
286
287 SetIsMainViewShell(false);
288}
289
290/**
291 * set focus to working window
292 */
293void ViewShell::Activate(bool bIsMDIActivate)
294{
295 // Do not forward to SfxShell::Activate()
296
297 /* According to MI, nobody is allowed to call GrabFocus, who does not
298 exactly know from which window the focus is grabbed. Since Activate()
299 is sent sometimes asynchronous, it can happen, that the wrong window
300 gets the focus. */
301
302 if (mpHorizontalRuler)
303 mpHorizontalRuler->SetActive();
304 if (mpVerticalRuler)
305 mpVerticalRuler->SetActive();
306
307 if (bIsMDIActivate)
308 {
309 // thus, the Navigator will also get a current status
310 SfxBoolItem aItem( SID_NAVIGATOR_INIT(27000 +289), true );
311 if (GetDispatcher() != nullptr)
312 GetDispatcher()->ExecuteList(
313 SID_NAVIGATOR_INIT(27000 +289),
314 SfxCallMode::ASYNCHRON | SfxCallMode::RECORD,
315 { &aItem });
316
317 SfxViewShell* pViewShell = GetViewShell();
318 OSL_ASSERT (pViewShell!=nullptr)do { if (true && (!(pViewShell!=nullptr))) { sal_detail_logFormat
((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.osl"), ("/home/maarten/src/libreoffice/core/sd/source/ui/view/viewshel.cxx"
":" "318" ": "), "OSL_ASSERT: %s", "pViewShell!=nullptr"); }
} while (false)
;
319 SfxBindings& rBindings = pViewShell->GetViewFrame()->GetBindings();
320 rBindings.Invalidate( SID_3D_STATE( 10000 + 645 ), true );
321
322 rtl::Reference< SlideShow > xSlideShow( SlideShow::GetSlideShow( GetViewShellBase() ) );
323 if (xSlideShow.is() && xSlideShow->isRunning())
324 {
325 bool bSuccess = xSlideShow->activate(GetViewShellBase());
326 assert(bSuccess && "can only return false with a PresentationViewShell")(static_cast <bool> (bSuccess && "can only return false with a PresentationViewShell"
) ? void (0) : __assert_fail ("bSuccess && \"can only return false with a PresentationViewShell\""
, "/home/maarten/src/libreoffice/core/sd/source/ui/view/viewshel.cxx"
, 326, __extension__ __PRETTY_FUNCTION__))
; (void)bSuccess;
327 }
328
329 if(HasCurrentFunction())
330 GetCurrentFunction()->Activate();
331
332 if(!GetDocSh()->IsUIActive())
333 UpdatePreview( GetActualPage() );
334 }
335
336 ReadFrameViewData( mpFrameView );
337
338 if (IsMainViewShell())
339 GetDocSh()->Connect(this);
340}
341
342void ViewShell::UIActivating( SfxInPlaceClient* )
343{
344 OSL_ASSERT (GetViewShell()!=nullptr)do { if (true && (!(GetViewShell()!=nullptr))) { sal_detail_logFormat
((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.osl"), ("/home/maarten/src/libreoffice/core/sd/source/ui/view/viewshel.cxx"
":" "344" ": "), "OSL_ASSERT: %s", "GetViewShell()!=nullptr"
); } } while (false)
;
345 GetViewShellBase().GetToolBarManager()->ToolBarsDestroyed();
346}
347
348void ViewShell::UIDeactivated( SfxInPlaceClient* )
349{
350 OSL_ASSERT (GetViewShell()!=nullptr)do { if (true && (!(GetViewShell()!=nullptr))) { sal_detail_logFormat
((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.osl"), ("/home/maarten/src/libreoffice/core/sd/source/ui/view/viewshel.cxx"
":" "350" ": "), "OSL_ASSERT: %s", "GetViewShell()!=nullptr"
); } } while (false)
;
351 GetViewShellBase().GetToolBarManager()->ToolBarsDestroyed();
352 if ( GetDrawView() )
353 GetViewShellBase().GetToolBarManager()->SelectionHasChanged(*this, *GetDrawView());
354}
355
356void ViewShell::Deactivate(bool bIsMDIActivate)
357{
358 // remove view from a still active drag'n'drop session
359 SdTransferable* pDragTransferable = SD_MOD()( static_cast<SdModule*>(SfxApplication::GetModule(SfxToolsModule
::Draw)) )
->pTransferDrag;
360
361 if (IsMainViewShell())
362 GetDocSh()->Disconnect(this);
363
364 if( pDragTransferable )
365 pDragTransferable->SetView( nullptr );
366
367 OSL_ASSERT (GetViewShell()!=nullptr)do { if (true && (!(GetViewShell()!=nullptr))) { sal_detail_logFormat
((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.osl"), ("/home/maarten/src/libreoffice/core/sd/source/ui/view/viewshel.cxx"
":" "367" ": "), "OSL_ASSERT: %s", "GetViewShell()!=nullptr"
); } } while (false)
;
368
369 // remember view attributes of FrameView
370 WriteFrameViewData();
371
372 if (bIsMDIActivate)
373 {
374 rtl::Reference< SlideShow > xSlideShow( SlideShow::GetSlideShow( GetViewShellBase() ) );
375 if(xSlideShow.is() && xSlideShow->isRunning() )
376 xSlideShow->deactivate();
377
378 if(HasCurrentFunction())
379 GetCurrentFunction()->Deactivate();
380 }
381
382 if (mpHorizontalRuler)
383 mpHorizontalRuler->SetActive(false);
384 if (mpVerticalRuler)
385 mpVerticalRuler->SetActive(false);
386
387 SfxShell::Deactivate(bIsMDIActivate);
388}
389
390void ViewShell::Shutdown()
391{
392 Exit ();
393}
394
395bool ViewShell::KeyInput(const KeyEvent& rKEvt, ::sd::Window* pWin)
396{
397 bool bReturn(false);
398
399 if(pWin)
400 SetActiveWindow(pWin);
401
402 // give key input first to SfxViewShell to give CTRL+Key
403 // (e.g. CTRL+SHIFT+'+', to front) priority.
404 OSL_ASSERT(GetViewShell() != nullptr)do { if (true && (!(GetViewShell() != nullptr))) { sal_detail_logFormat
((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.osl"), ("/home/maarten/src/libreoffice/core/sd/source/ui/view/viewshel.cxx"
":" "404" ": "), "OSL_ASSERT: %s", "GetViewShell() != nullptr"
); } } while (false)
;
405 bReturn = GetViewShell()->KeyInput(rKEvt);
406
407 const size_t OriCount = GetView()->GetMarkedObjectList().GetMarkCount();
408 if(!bReturn)
409 {
410 rtl::Reference< SlideShow > xSlideShow( SlideShow::GetSlideShow( GetViewShellBase() ) );
411 if(xSlideShow.is() && xSlideShow->isRunning())
412 {
413 bReturn = xSlideShow->keyInput(rKEvt);
414 }
415 else
416 {
417 bool bConsumed = false;
418 if( GetView() )
419 bConsumed = GetView()->getSmartTags().KeyInput(rKEvt);
420
421 if( !bConsumed )
422 {
423 rtl::Reference< sdr::SelectionController > xSelectionController( GetView()->getSelectionController() );
424 if( !xSelectionController.is() || !xSelectionController->onKeyInput( rKEvt, pWin ) )
425 {
426 if(HasCurrentFunction())
427 bReturn = GetCurrentFunction()->KeyInput(rKEvt);
428 }
429 else
430 {
431 bReturn = true;
432 if (HasCurrentFunction())
433 {
434 FuText* pTextFunction = dynamic_cast<FuText*>(GetCurrentFunction().get());
435 if(pTextFunction != nullptr)
436 pTextFunction->InvalidateBindings();
437 }
438 }
439 }
440 }
441 }
442 const size_t EndCount = GetView()->GetMarkedObjectList().GetMarkCount();
443 // Here, oriCount or endCount must have one value=0, another value > 0, then to switch focus between Document and shape objects
444 if(bReturn && (OriCount + EndCount > 0) && (OriCount * EndCount == 0))
445 SwitchActiveViewFireFocus();
446
447 if(!bReturn && GetActiveWindow())
448 {
449 vcl::KeyCode aKeyCode = rKEvt.GetKeyCode();
450
451 if (aKeyCode.IsMod1() && aKeyCode.IsShift()
452 && aKeyCode.GetCode() == KEY_R)
453 {
454 InvalidateWindows();
455 bReturn = true;
456 }
457 }
458
459 return bReturn;
460}
461
462void ViewShell::MouseButtonDown(const MouseEvent& rMEvt, ::sd::Window* pWin)
463{
464 // We have to lock tool bar updates while the mouse button is pressed in
465 // order to prevent the shape under the mouse to be moved (this happens
466 // when the number of docked tool bars changes as result of a changed
467 // selection; this changes the window size and thus the mouse position
468 // in model coordinates: with respect to model coordinates the mouse
469 // moves.)
470 OSL_ASSERT(mpImpl->mpUpdateLockForMouse.expired())do { if (true && (!(mpImpl->mpUpdateLockForMouse.expired
()))) { sal_detail_logFormat((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.osl"
), ("/home/maarten/src/libreoffice/core/sd/source/ui/view/viewshel.cxx"
":" "470" ": "), "OSL_ASSERT: %s", "mpImpl->mpUpdateLockForMouse.expired()"
); } } while (false)
;
471 mpImpl->mpUpdateLockForMouse = ViewShell::Implementation::ToolBarManagerLock::Create(
472 GetViewShellBase().GetToolBarManager());
473
474 if ( pWin && !pWin->HasFocus() )
475 {
476 pWin->GrabFocus();
477 SetActiveWindow(pWin);
478 }
479
480 // insert MouseEvent into E3dView
481 if (GetView() != nullptr)
482 GetView()->SetMouseEvent(rMEvt);
483
484 bool bConsumed = false;
485 if( GetView() )
486 bConsumed = GetView()->getSmartTags().MouseButtonDown( rMEvt );
487
488 if( bConsumed )
489 return;
490
491 rtl::Reference< sdr::SelectionController > xSelectionController( GetView()->getSelectionController() );
492 if( !xSelectionController.is() || !xSelectionController->onMouseButtonDown( rMEvt, pWin ) )
493 {
494 if(HasCurrentFunction())
495 GetCurrentFunction()->MouseButtonDown(rMEvt);
496 }
497 else
498 {
499 if (HasCurrentFunction())
500 {
501 FuText* pTextFunction = dynamic_cast<FuText*>(GetCurrentFunction().get());
502 if (pTextFunction != nullptr)
503 pTextFunction->InvalidateBindings();
504 }
505 }
506}
507
508void ViewShell::SetCursorMm100Position(const Point& rPosition, bool bPoint, bool bClearMark)
509{
510 if (SdrView* pSdrView = GetView())
511 {
512 rtl::Reference<sdr::SelectionController> xSelectionController(GetView()->getSelectionController());
513 if (!xSelectionController.is() || !xSelectionController->setCursorLogicPosition(rPosition, bPoint))
514 {
515 if (pSdrView->GetTextEditObject())
516 {
517 EditView& rEditView = pSdrView->GetTextEditOutlinerView()->GetEditView();
518 rEditView.SetCursorLogicPosition(rPosition, bPoint, bClearMark);
519 }
520 }
521 }
522}
523
524uno::Reference<datatransfer::XTransferable> ViewShell::GetSelectionTransferrable() const
525{
526 SdrView* pSdrView = GetView();
527 if (!pSdrView)
528 return uno::Reference<datatransfer::XTransferable>();
529
530 if (!pSdrView->GetTextEditObject())
531 return uno::Reference<datatransfer::XTransferable>();
532
533 EditView& rEditView = pSdrView->GetTextEditOutlinerView()->GetEditView();
534 return rEditView.GetEditEngine()->CreateTransferable(rEditView.GetSelection());
535}
536
537void ViewShell::SetGraphicMm100Position(bool bStart, const Point& rPosition)
538{
539 if (bStart)
540 {
541 MouseEvent aClickEvent(rPosition, 1, MouseEventModifiers::SIMPLECLICK, MOUSE_LEFT(sal_uInt16(0x0001)));
542 MouseButtonDown(aClickEvent, mpActiveWindow);
543 MouseEvent aMoveEvent(Point(rPosition.getX(), rPosition.getY()), 0, MouseEventModifiers::SIMPLEMOVE, MOUSE_LEFT(sal_uInt16(0x0001)));
544 MouseMove(aMoveEvent, mpActiveWindow);
545 }
546 else
547 {
548 MouseEvent aMoveEvent(Point(rPosition.getX(), rPosition.getY()), 0, MouseEventModifiers::SIMPLEMOVE, MOUSE_LEFT(sal_uInt16(0x0001)));
549 MouseMove(aMoveEvent, mpActiveWindow);
550 MouseEvent aClickEvent(rPosition, 1, MouseEventModifiers::SIMPLECLICK, MOUSE_LEFT(sal_uInt16(0x0001)));
551 MouseButtonUp(aClickEvent, mpActiveWindow);
552 }
553}
554
555void ViewShell::MouseMove(const MouseEvent& rMEvt, ::sd::Window* pWin)
556{
557 if (rMEvt.IsLeaveWindow())
558 {
559 if ( ! mpImpl->mpUpdateLockForMouse.expired())
560 {
561 std::shared_ptr<ViewShell::Implementation::ToolBarManagerLock> pLock(
562 mpImpl->mpUpdateLockForMouse);
563 if (pLock != nullptr)
564 pLock->Release();
565 }
566 }
567
568 if ( pWin )
569 {
570 SetActiveWindow(pWin);
571 }
572
573 // insert MouseEvent into E3dView
574 if (GetView() != nullptr)
575 GetView()->SetMouseEvent(rMEvt);
576
577 if(HasCurrentFunction())
578 {
579 rtl::Reference< sdr::SelectionController > xSelectionController( GetView()->getSelectionController() );
580 if( !xSelectionController.is() || !xSelectionController->onMouseMove( rMEvt, pWin ) )
581 {
582 if(HasCurrentFunction())
583 GetCurrentFunction()->MouseMove(rMEvt);
584 }
585 }
586}
587
588void ViewShell::MouseButtonUp(const MouseEvent& rMEvt, ::sd::Window* pWin)
589{
590 if ( pWin )
591 SetActiveWindow(pWin);
592
593 // insert MouseEvent into E3dView
594 if (GetView() != nullptr)
595 GetView()->SetMouseEvent(rMEvt);
596
597 if( HasCurrentFunction())
598 {
599 rtl::Reference< sdr::SelectionController > xSelectionController( GetView()->getSelectionController() );
600 if( !xSelectionController.is() || !xSelectionController->onMouseButtonUp( rMEvt, pWin ) )
601 {
602 if(HasCurrentFunction())
603 GetCurrentFunction()->MouseButtonUp(rMEvt);
604 }
605 else
606 {
607 if (HasCurrentFunction())
608 {
609 FuText* pTextFunction = dynamic_cast<FuText*>(GetCurrentFunction().get());
610 if (pTextFunction != nullptr)
611 pTextFunction->InvalidateBindings();
612 }
613 }
614 }
615
616 if ( ! mpImpl->mpUpdateLockForMouse.expired())
617 {
618 std::shared_ptr<ViewShell::Implementation::ToolBarManagerLock> pLock(
619 mpImpl->mpUpdateLockForMouse);
620 if (pLock != nullptr)
621 pLock->Release();
622 }
623}
624
625void ViewShell::Command(const CommandEvent& rCEvt, ::sd::Window* pWin)
626{
627 bool bDone = HandleScrollCommand (rCEvt, pWin);
628
629 if( bDone )
630 return;
631
632 if( rCEvt.GetCommand() == CommandEventId::InputLanguageChange )
633 {
634 //#i42732# update state of fontname if input language changes
635 GetViewFrame()->GetBindings().Invalidate( SID_ATTR_CHAR_FONT( 10000 + 7 ) );
636 GetViewFrame()->GetBindings().Invalidate( SID_ATTR_CHAR_FONTHEIGHT( 10000 + 15 ) );
637 }
638 else
639 {
640 bool bConsumed = false;
641 if( GetView() )
642 bConsumed = GetView()->getSmartTags().Command(rCEvt);
643
644 if( !bConsumed && HasCurrentFunction())
645 GetCurrentFunction()->Command(rCEvt);
646 }
647}
648
649bool ViewShell::Notify(NotifyEvent const & rNEvt, ::sd::Window* pWin)
650{
651 // handle scroll commands when they arrived at child windows
652 bool bRet = false;
653 if( rNEvt.GetType() == MouseNotifyEvent::COMMAND )
654 {
655 // note: dynamic_cast is not possible as GetData() returns a void*
656 CommandEvent* pCmdEvent = static_cast< CommandEvent* >(rNEvt.GetData());
657 bRet = HandleScrollCommand(*pCmdEvent, pWin);
658 }
659 return bRet;
660}
661
662bool ViewShell::HandleScrollCommand(const CommandEvent& rCEvt, ::sd::Window* pWin)
663{
664 bool bDone = false;
665
666 switch( rCEvt.GetCommand() )
667 {
668 case CommandEventId::Swipe:
669 {
670 rtl::Reference< SlideShow > xSlideShow( SlideShow::GetSlideShow( GetViewShellBase() ) );
671 if (xSlideShow.is())
672 {
673 const CommandSwipeData* pSwipeData = rCEvt.GetSwipeData();
674 bDone = xSlideShow->swipe(*pSwipeData);
675 }
676 }
677 break;
678 case CommandEventId::LongPress:
679 {
680 rtl::Reference< SlideShow > xSlideShow( SlideShow::GetSlideShow( GetViewShellBase() ) );
681 if (xSlideShow.is())
682 {
683 const CommandLongPressData* pLongPressData = rCEvt.GetLongPressData();
684 bDone = xSlideShow->longpress(*pLongPressData);
685 }
686 }
687 break;
688
689 case CommandEventId::Wheel:
690 {
691 Reference< XSlideShowController > xSlideShowController( SlideShow::GetSlideShowController(GetViewShellBase() ) );
692 if( xSlideShowController.is() )
693 {
694 // We ignore zooming with control+mouse wheel.
695 const CommandWheelData* pData = rCEvt.GetWheelData();
696 if( pData && !pData->GetModifier() && ( pData->GetMode() == CommandWheelMode::SCROLL ) && !pData->IsHorz() )
697 {
698 long nDelta = pData->GetDelta();
699 if( nDelta > 0 )
700 xSlideShowController->gotoPreviousSlide();
701 else if( nDelta < 0 )
702 xSlideShowController->gotoNextEffect();
703 }
704 break;
705 }
706 }
707 [[fallthrough]];
708 case CommandEventId::StartAutoScroll:
709 case CommandEventId::AutoScroll:
710 {
711 const CommandWheelData* pData = rCEvt.GetWheelData();
712
713 if (pData != nullptr)
714 {
715 if (pData->IsMod1())
716 {
717 if( !GetDocSh()->IsUIActive() )
718 {
719 const long nOldZoom = GetActiveWindow()->GetZoom();
720 long nNewZoom;
721 Point aOldMousePos = GetActiveWindow()->PixelToLogic(rCEvt.GetMousePosPixel());
722
723 if( pData->GetDelta() < 0 )
724 nNewZoom = std::max<long>( pWin->GetMinZoom(), basegfx::zoomtools::zoomOut( nOldZoom ));
725 else
726 nNewZoom = std::min<long>( pWin->GetMaxZoom(), basegfx::zoomtools::zoomIn( nOldZoom ));
727
728 SetZoom( nNewZoom );
729 // Keep mouse at same doc point before zoom
730 Point aNewMousePos = GetActiveWindow()->PixelToLogic(rCEvt.GetMousePosPixel());
731 SetWinViewPos(GetWinViewPos() - (aNewMousePos - aOldMousePos));
732
733 Invalidate( SID_ATTR_ZOOMTypedWhichId<SvxZoomItem>(10000 + 0) );
734 Invalidate( SID_ATTR_ZOOMSLIDER( 10000 + 1065 ) );
735
736 bDone = true;
737 }
738 }
739 else
740 {
741 if( mpContentWindow.get() == pWin )
742 {
743 sal_uLong nScrollLines = pData->GetScrollLines();
744 if(IsPageFlipMode())
745 nScrollLines = COMMAND_WHEEL_PAGESCROLL(sal_uLong(0xFFFFFFFF));
746 CommandWheelData aWheelData( pData->GetDelta(),pData->GetNotchDelta(),
747 nScrollLines,pData->GetMode(),pData->GetModifier(),pData->IsHorz() );
748 CommandEvent aReWrite( rCEvt.GetMousePosPixel(),rCEvt.GetCommand(),
749 rCEvt.IsMouseEvent(),static_cast<const void *>(&aWheelData) );
750 bDone = pWin->HandleScrollCommand( aReWrite,
751 mpHorizontalScrollBar.get(),
752 mpVerticalScrollBar.get());
753 }
754 }
755 }
756 }
757 break;
758
759 default:
760 break;
761 }
762
763 return bDone;
764}
765
766void ViewShell::SetupRulers()
767{
768 if(!mbHasRulers || !mpContentWindow || SlideShow::IsRunning(GetViewShellBase()))
769 return;
770
771 long nHRulerOfs = 0;
772
773 if ( !mpVerticalRuler )
774 {
775 mpVerticalRuler.reset(CreateVRuler(GetActiveWindow()));
776 if ( mpVerticalRuler )
777 {
778 nHRulerOfs = mpVerticalRuler->GetSizePixel().Width();
779 mpVerticalRuler->SetActive();
780 mpVerticalRuler->Show();
781 }
782 }
783 if ( !mpHorizontalRuler )
784 {
785 mpHorizontalRuler.reset(CreateHRuler(GetActiveWindow()));
786 if ( mpHorizontalRuler )
787 {
788 mpHorizontalRuler->SetWinPos(nHRulerOfs);
789 mpHorizontalRuler->SetActive();
790 mpHorizontalRuler->Show();
791 }
792 }
793}
794
795const SfxPoolItem* ViewShell::GetNumBulletItem(SfxItemSet& aNewAttr, sal_uInt16& nNumItemId)
796{
797 const SfxPoolItem* pTmpItem = nullptr;
798
799 if(aNewAttr.GetItemState(nNumItemId, false, &pTmpItem) == SfxItemState::SET)
800 {
801 return pTmpItem;
802 }
803 else
804 {
805 nNumItemId = aNewAttr.GetPool()->GetWhich(SID_ATTR_NUMBERING_RULE( 10000 + 855 ));
806 SfxItemState eState = aNewAttr.GetItemState(nNumItemId, false, &pTmpItem);
807 if (eState == SfxItemState::SET)
808 return pTmpItem;
809 else
810 {
811 bool bOutliner = false;
812 bool bTitle = false;
813
814 if( mpView )
815 {
816 const SdrMarkList& rMarkList = mpView->GetMarkedObjectList();
817 const size_t nCount = rMarkList.GetMarkCount();
818
819 for(size_t nNum = 0; nNum < nCount; ++nNum)
820 {
821 SdrObject* pObj = rMarkList.GetMark(nNum)->GetMarkedSdrObj();
822 if( pObj->GetObjInventor() == SdrInventor::Default )
823 {
824 switch(pObj->GetObjIdentifier())
825 {
826 case OBJ_TITLETEXT:
827 bTitle = true;
828 break;
829 case OBJ_OUTLINETEXT:
830 bOutliner = true;
831 break;
832 }
833 }
834 }
835 }
836
837 const SvxNumBulletItem *pItem = nullptr;
838 if(bOutliner)
839 {
840 SfxStyleSheetBasePool* pSSPool = mpView->GetDocSh()->GetStyleSheetPool();
841 SfxStyleSheetBase* pFirstStyleSheet = pSSPool->Find( STR_LAYOUT_OUTLINE"Gliederung" " 1", SfxStyleFamily::Pseudo);
842 if( pFirstStyleSheet )
843 pFirstStyleSheet->GetItemSet().GetItemState(EE_PARA_NUMBULLET, false, reinterpret_cast<const SfxPoolItem**>(&pItem));
844 }
845
846 if( pItem == nullptr )
847 pItem = aNewAttr.GetPool()->GetSecondaryPool()->GetPoolDefaultItem(EE_PARA_NUMBULLET);
848
849 aNewAttr.Put(pItem->CloneSetWhich(EE_PARA_NUMBULLET));
850
851 if(bTitle && aNewAttr.GetItemState(EE_PARA_NUMBULLET) == SfxItemState::SET )
852 {
853 const SvxNumBulletItem* pBulletItem = aNewAttr.GetItem(EE_PARA_NUMBULLET);
854 SvxNumRule* pRule = pBulletItem->GetNumRule();
855 if(pRule)
856 {
857 SvxNumRule aNewRule( *pRule );
858 aNewRule.SetFeatureFlag( SvxNumRuleFlags::NO_NUMBERS );
859
860 SvxNumBulletItem aNewItem( aNewRule, EE_PARA_NUMBULLET );
861 aNewAttr.Put(aNewItem);
862 }
863 }
864
865 SfxItemState eNumState = aNewAttr.GetItemState(nNumItemId, false, &pTmpItem);
866 if (eNumState == SfxItemState::SET)
867 return pTmpItem;
868
869 }
870 }
871 return pTmpItem;
872}
873
874void ViewShell::Resize()
875{
876 SetupRulers ();
877
878 if (mpParentWindow == nullptr)
879 return;
880
881 // Make sure that the new size is not degenerate.
882 const Size aSize (mpParentWindow->GetSizePixel());
883 if (aSize.IsEmpty())
884 return;
885
886 // Remember the new position and size.
887 maViewPos = Point(0,0);
888 maViewSize = aSize;
889
890 // Rearrange the UI elements to take care of the new position and size.
891 ArrangeGUIElements ();
892 // end of included AdjustPosSizePixel.
893
894 ::sd::View* pView = GetView();
895
896 if (pView)
897 pView->VisAreaChanged(GetActiveWindow());
898}
899
900SvBorder ViewShell::GetBorder()
901{
902 SvBorder aBorder;
903
904 // Horizontal scrollbar.
905 if (mpHorizontalScrollBar
906 && mpHorizontalScrollBar->IsVisible())
907 {
908 aBorder.Bottom() = maScrBarWH.Height();
909 }
910
911 // Vertical scrollbar.
912 if (mpVerticalScrollBar
913 && mpVerticalScrollBar->IsVisible())
914 {
915 aBorder.Right() = maScrBarWH.Width();
916 }
917
918 // Place horizontal ruler below tab bar.
919 if (mbHasRulers && mpContentWindow)
920 {
921 SetupRulers();
922 if (mpHorizontalRuler)
923 aBorder.Top() = mpHorizontalRuler->GetSizePixel().Height();
924 if (mpVerticalRuler)
925 aBorder.Left() = mpVerticalRuler->GetSizePixel().Width();
926 }
927
928 return aBorder;
929}
930
931void ViewShell::ArrangeGUIElements()
932{
933 if (mpImpl->mbArrangeActive)
934 return;
935 if (maViewSize.IsEmpty())
936 return;
937 mpImpl->mbArrangeActive = true;
938
939 // Calculate border for in-place editing.
940 long nLeft = maViewPos.X();
941 long nTop = maViewPos.Y();
942 long nRight = maViewPos.X() + maViewSize.Width();
943 long nBottom = maViewPos.Y() + maViewSize.Height();
944
945 // Horizontal scrollbar.
946 if (mpHorizontalScrollBar
947 && mpHorizontalScrollBar->IsVisible())
948 {
949 nBottom -= maScrBarWH.Height();
950 if (mpLayerTabBar && mpLayerTabBar->IsVisible())
951 nBottom -= mpLayerTabBar->GetSizePixel().Height();
952 mpHorizontalScrollBar->SetPosSizePixel (
953 Point(nLeft, nBottom),
954 Size(nRight - nLeft - maScrBarWH.Width(), maScrBarWH.Height()));
955 }
956
957 // Vertical scrollbar.
958 if (mpVerticalScrollBar
959 && mpVerticalScrollBar->IsVisible())
960 {
961 nRight -= maScrBarWH.Width();
962 mpVerticalScrollBar->SetPosSizePixel (
963 Point(nRight,nTop),
964 Size (maScrBarWH.Width(), nBottom-nTop));
965 }
966
967 // Filler in the lower right corner.
968 if (mpScrollBarBox)
969 {
970 if (mpHorizontalScrollBar
971 && mpHorizontalScrollBar->IsVisible()
972 && mpVerticalScrollBar
973 && mpVerticalScrollBar->IsVisible())
974 {
975 mpScrollBarBox->Show();
976 mpScrollBarBox->SetPosSizePixel(Point(nRight, nBottom), maScrBarWH);
977 }
978 else
979 mpScrollBarBox->Hide();
980 }
981
982 // Place horizontal ruler below tab bar.
983 if (mbHasRulers && mpContentWindow)
984 {
985 if (mpHorizontalRuler)
986 {
987 Size aRulerSize = mpHorizontalRuler->GetSizePixel();
988 aRulerSize.setWidth( nRight - nLeft );
989 mpHorizontalRuler->SetPosSizePixel (
990 Point(nLeft,nTop), aRulerSize);
991 if (mpVerticalRuler)
992 mpHorizontalRuler->SetBorderPos(
993 mpVerticalRuler->GetSizePixel().Width()-1);
994 nTop += aRulerSize.Height();
995 }
996 if (mpVerticalRuler)
997 {
998 Size aRulerSize = mpVerticalRuler->GetSizePixel();
999 aRulerSize.setHeight( nBottom - nTop );
1000 mpVerticalRuler->SetPosSizePixel (
1001 Point (nLeft,nTop), aRulerSize);
1002 nLeft += aRulerSize.Width();
1003 }
1004 }
1005
1006 rtl::Reference< SlideShow > xSlideShow( SlideShow::GetSlideShow( GetViewShellBase() ) );
1007
1008 // The size of the window of the center pane is set differently from
1009 // that of the windows in the docking windows.
1010 bool bSlideShowActive = (xSlideShow.is() && xSlideShow->isRunning()) && !xSlideShow->isFullScreen() && xSlideShow->getAnimationMode() == ANIMATIONMODE_SHOW;
1011 if ( !bSlideShowActive)
1012 {
1013 OSL_ASSERT (GetViewShell()!=nullptr)do { if (true && (!(GetViewShell()!=nullptr))) { sal_detail_logFormat
((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.osl"), ("/home/maarten/src/libreoffice/core/sd/source/ui/view/viewshel.cxx"
":" "1013" ": "), "OSL_ASSERT: %s", "GetViewShell()!=nullptr"
); } } while (false)
;
1014
1015 if (mpContentWindow)
1016 mpContentWindow->SetPosSizePixel(
1017 Point(nLeft,nTop),
1018 Size(nRight-nLeft,nBottom-nTop));
1019 }
1020
1021 // Windows in the center and rulers at the left and top side.
1022 maAllWindowRectangle = ::tools::Rectangle(
1023 maViewPos,
1024 Size(maViewSize.Width()-maScrBarWH.Width(),
1025 maViewSize.Height()-maScrBarWH.Height()));
1026
1027 if (mpContentWindow)
1028 mpContentWindow->UpdateMapOrigin();
1029
1030 UpdateScrollBars();
1031
1032 mpImpl->mbArrangeActive = false;
1033}
1034
1035void ViewShell::SetUIUnit(FieldUnit eUnit)
1036{
1037 // Set unit at horizontal and vertical rulers.
1038 if (mpHorizontalRuler)
1039 mpHorizontalRuler->SetUnit(eUnit);
1040
1041 if (mpVerticalRuler)
1042 mpVerticalRuler->SetUnit(eUnit);
1043}
1044
1045/**
1046 * set DefTab at horizontal rulers
1047 */
1048void ViewShell::SetDefTabHRuler( sal_uInt16 nDefTab )
1049{
1050 if (mpHorizontalRuler)
1051 mpHorizontalRuler->SetDefTabDist( nDefTab );
1052}
1053
1054/** Tell the FmFormShell that the view shell is closing. Give it the
1055 opportunity to prevent that.
1056*/
1057bool ViewShell::PrepareClose (bool bUI)
1058{
1059 bool bResult = true;
1060
1061 FmFormShell* pFormShell = GetViewShellBase().GetFormShellManager()->GetFormShell();
1062 if (pFormShell != nullptr)
1063 bResult = pFormShell->PrepareClose (bUI);
1064
1065 return bResult;
1066}
1067
1068void ViewShell::UpdatePreview (SdPage*)
1069{
1070 // Do nothing. After the actual preview has been removed,
1071 // OutlineViewShell::UpdatePreview() is the place where something
1072 // useful is still done.
1073}
1074
1075SfxUndoManager* ViewShell::ImpGetUndoManager() const
1076{
1077 const ViewShell* pMainViewShell = GetViewShellBase().GetMainViewShell().get();
1078
1079 if( pMainViewShell == nullptr )
1080 pMainViewShell = this;
1081
1082 ::sd::View* pView = pMainViewShell->GetView();
1083
1084 // check for text edit our outline view
1085 if( pView )
1086 {
1087 if( pMainViewShell->GetShellType() == ViewShell::ST_OUTLINE )
1088 {
1089 OutlineView* pOlView = dynamic_cast< OutlineView* >( pView );
1090 if( pOlView )
1091 {
1092 ::Outliner& rOutl = pOlView->GetOutliner();
1093 return &rOutl.GetUndoManager();
1094 }
1095 }
1096 else if( pView->IsTextEdit() )
1097 {
1098 SdrOutliner* pOL = pView->GetTextEditOutliner();
1099 if( pOL )
1100 return &pOL->GetUndoManager();
1101 }
1102 }
1103
1104 if( GetDocSh() )
1105 return GetDocSh()->GetUndoManager();
1106
1107 return nullptr;
1108}
1109
1110void ViewShell::ImpGetUndoStrings(SfxItemSet &rSet) const
1111{
1112 SfxUndoManager* pUndoManager = ImpGetUndoManager();
1113 if(!pUndoManager)
1114 return;
1115
1116 sal_uInt16 nCount(pUndoManager->GetUndoActionCount());
1117 if(nCount)
1118 {
1119 // prepare list
1120 std::vector<OUString> aStringList;
1121 aStringList.reserve(nCount);
1122 for (sal_uInt16 a = 0; a < nCount; ++a)
1123 {
1124 // generate one String in list per undo step
1125 aStringList.push_back( pUndoManager->GetUndoActionComment(a) );
1126 }
1127
1128 // set item
1129 rSet.Put(SfxStringListItem(SID_GETUNDOSTRINGS( 10000 + 923 ), &aStringList));
1130 }
1131 else
1132 {
1133 rSet.DisableItem(SID_GETUNDOSTRINGS( 10000 + 923 ));
1134 }
1135}
1136
1137void ViewShell::ImpGetRedoStrings(SfxItemSet &rSet) const
1138{
1139 SfxUndoManager* pUndoManager = ImpGetUndoManager();
1140 if(!pUndoManager)
1141 return;
1142
1143 sal_uInt16 nCount(pUndoManager->GetRedoActionCount());
1144 if(nCount)
1145 {
1146 // prepare list
1147 ::std::vector< OUString > aStringList;
1148 aStringList.reserve(nCount);
1149 for(sal_uInt16 a = 0; a < nCount; a++)
1150 // generate one String in list per undo step
1151 aStringList.push_back( pUndoManager->GetRedoActionComment(a) );
1152
1153 // set item
1154 rSet.Put(SfxStringListItem(SID_GETREDOSTRINGS( 10000 + 924 ), &aStringList));
1155 }
1156 else
1157 {
1158 rSet.DisableItem(SID_GETREDOSTRINGS( 10000 + 924 ));
1159 }
1160}
1161
1162namespace {
1163
1164class KeepSlideSorterInSyncWithPageChanges
1165{
1166 sd::slidesorter::view::SlideSorterView::DrawLock m_aDrawLock;
1167 sd::slidesorter::controller::SlideSorterController::ModelChangeLock m_aModelLock;
1168 sd::slidesorter::controller::PageSelector::UpdateLock m_aUpdateLock;
1169 sd::slidesorter::controller::SelectionObserver::Context m_aContext;
1170
1171public:
1172 explicit KeepSlideSorterInSyncWithPageChanges(sd::slidesorter::SlideSorter const & rSlideSorter)
1173 : m_aDrawLock(rSlideSorter)
1174 , m_aModelLock(rSlideSorter.GetController())
1175 , m_aUpdateLock(rSlideSorter)
1176 , m_aContext(rSlideSorter)
1177 {
1178 }
1179};
1180
1181}
1182
1183void ViewShell::ImpSidUndo(SfxRequest& rReq)
1184{
1185 //The xWatcher keeps the SlideSorter selection in sync
1186 //with the page insertions/deletions that Undo may introduce
1187 std::unique_ptr<KeepSlideSorterInSyncWithPageChanges, o3tl::default_delete<KeepSlideSorterInSyncWithPageChanges>> xWatcher;
1188 slidesorter::SlideSorterViewShell* pSlideSorterViewShell
1189 = slidesorter::SlideSorterViewShell::GetSlideSorter(GetViewShellBase());
1190 if (pSlideSorterViewShell)
1191 xWatcher.reset(new KeepSlideSorterInSyncWithPageChanges(pSlideSorterViewShell->GetSlideSorter()));
1192
1193 SfxUndoManager* pUndoManager = ImpGetUndoManager();
1194 sal_uInt16 nNumber(1);
1195 const SfxItemSet* pReqArgs = rReq.GetArgs();
1196 bool bRepair = false;
1197
1198 if(pReqArgs)
1199 {
1200 const SfxUInt16Item* pUIntItem = static_cast<const SfxUInt16Item*>(&pReqArgs->Get(SID_UNDO(5000 + 701)));
1201 nNumber = pUIntItem->GetValue();
1202
1203 // Repair mode: allow undo/redo of all undo actions, even if access would
1204 // be limited based on the view shell ID.
1205 const SfxPoolItem* pRepairItem;
1206 if (pReqArgs->GetItemState(SID_REPAIRPACKAGE(5000 + 1683), false, &pRepairItem) == SfxItemState::SET)
1207 bRepair = static_cast<const SfxBoolItem*>(pRepairItem)->GetValue();
1208 }
1209
1210 if(nNumber && pUndoManager)
1211 {
1212 sal_uInt16 nCount(pUndoManager->GetUndoActionCount());
1213 if(nCount >= nNumber)
1214 {
1215 if (comphelper::LibreOfficeKit::isActive() && !bRepair)
1216 {
1217 // If another view created the first undo action, prevent redoing it from this view.
1218 const SfxUndoAction* pAction = pUndoManager->GetUndoAction();
1219 if (pAction->GetViewShellId() != GetViewShellBase().GetViewShellId())
1220 {
1221 rReq.SetReturnValue(SfxUInt32Item(SID_UNDO(5000 + 701), static_cast<sal_uInt32>(SID_REPAIRPACKAGE(5000 + 1683))));
1222 return;
1223 }
1224 }
1225
1226 try
1227 {
1228 // when UndoStack is cleared by ModifyPageUndoAction
1229 // the nCount may have changed, so test GetUndoActionCount()
1230 while(nNumber-- && pUndoManager->GetUndoActionCount())
1231 pUndoManager->Undo();
1232 }
1233 catch( const Exception& )
1234 {
1235 // no need to handle. By definition, the UndoManager handled this by clearing the
1236 // Undo/Redo stacks
1237 }
1238 }
1239
1240 // refresh rulers, maybe UNDO was move of TAB marker in ruler
1241 if (mbHasRulers)
1242 Invalidate(SID_ATTR_TABSTOP( 10000 + 2 ));
1243 }
1244
1245 // This one is corresponding to the default handling
1246 // of SID_UNDO in sfx2
1247 GetViewFrame()->GetBindings().InvalidateAll(false);
1248
1249 rReq.Done();
1250}
1251
1252void ViewShell::ImpSidRedo(SfxRequest& rReq)
1253{
1254 //The xWatcher keeps the SlideSorter selection in sync
1255 //with the page insertions/deletions that Undo may introduce
1256 std::unique_ptr<KeepSlideSorterInSyncWithPageChanges, o3tl::default_delete<KeepSlideSorterInSyncWithPageChanges>> xWatcher;
1257 slidesorter::SlideSorterViewShell* pSlideSorterViewShell
1258 = slidesorter::SlideSorterViewShell::GetSlideSorter(GetViewShellBase());
1259 if (pSlideSorterViewShell)
1260 xWatcher.reset(new KeepSlideSorterInSyncWithPageChanges(pSlideSorterViewShell->GetSlideSorter()));
1261
1262 SfxUndoManager* pUndoManager = ImpGetUndoManager();
1263 sal_uInt16 nNumber(1);
1264 const SfxItemSet* pReqArgs = rReq.GetArgs();
1265 bool bRepair = false;
1266
1267 if(pReqArgs)
1268 {
1269 const SfxUInt16Item* pUIntItem = static_cast<const SfxUInt16Item*>(&pReqArgs->Get(SID_REDO(5000 + 700)));
1270 nNumber = pUIntItem->GetValue();
1271 // Repair mode: allow undo/redo of all undo actions, even if access would
1272 // be limited based on the view shell ID.
1273 const SfxPoolItem* pRepairItem;
1274 if (pReqArgs->GetItemState(SID_REPAIRPACKAGE(5000 + 1683), false, &pRepairItem) == SfxItemState::SET)
1275 bRepair = static_cast<const SfxBoolItem*>(pRepairItem)->GetValue();
1276 }
1277
1278 if(nNumber && pUndoManager)
1279 {
1280 sal_uInt16 nCount(pUndoManager->GetRedoActionCount());
1281 if(nCount >= nNumber)
1282 {
1283 if (comphelper::LibreOfficeKit::isActive() && !bRepair)
1284 {
1285 // If another view created the first undo action, prevent redoing it from this view.
1286 const SfxUndoAction* pAction = pUndoManager->GetRedoAction();
1287 if (pAction->GetViewShellId() != GetViewShellBase().GetViewShellId())
1288 {
1289 rReq.SetReturnValue(SfxUInt32Item(SID_REDO(5000 + 700), static_cast<sal_uInt32>(SID_REPAIRPACKAGE(5000 + 1683))));
1290 return;
1291 }
1292 }
1293
1294 try
1295 {
1296 // when UndoStack is cleared by ModifyPageRedoAction
1297 // the nCount may have changed, so test GetRedoActionCount()
1298 while(nNumber-- && pUndoManager->GetRedoActionCount())
1299 pUndoManager->Redo();
1300 }
1301 catch( const Exception& )
1302 {
1303 // no need to handle. By definition, the UndoManager handled this by clearing the
1304 // Undo/Redo stacks
1305 }
1306 }
1307
1308 // refresh rulers, maybe REDO was move of TAB marker in ruler
1309 if (mbHasRulers)
1310 {
1311 Invalidate(SID_ATTR_TABSTOP( 10000 + 2 ));
1312 }
1313 }
1314
1315 // This one is corresponding to the default handling
1316 // of SID_UNDO in sfx2
1317 GetViewFrame()->GetBindings().InvalidateAll(false);
1318
1319 rReq.Done();
1320}
1321
1322void ViewShell::ExecReq( SfxRequest& rReq )
1323{
1324 sal_uInt16 nSlot = rReq.GetSlot();
1325 switch( nSlot )
1326 {
1327 case SID_MAIL_SCROLLBODY_PAGEDOWN(5000 + 1588):
1328 {
1329 rtl::Reference<FuPoor> xFunc( GetCurrentFunction() );
1330 if( xFunc.is() )
1331 ScrollLines( 0, -1 );
1332
1333 rReq.Done();
1334 }
1335 break;
1336
1337 case SID_OUTPUT_QUALITY_COLOR(27000 +366):
1338 case SID_OUTPUT_QUALITY_GRAYSCALE(27000 +367):
1339 case SID_OUTPUT_QUALITY_BLACKWHITE(27000 +368):
1340 case SID_OUTPUT_QUALITY_CONTRAST(27000 +400):
1341 {
1342 DrawModeFlags nMode = OUTPUT_DRAWMODE_COLOR;
1343
1344 switch( nSlot )
1345 {
1346 case SID_OUTPUT_QUALITY_COLOR(27000 +366): nMode = OUTPUT_DRAWMODE_COLOR; break;
1347 case SID_OUTPUT_QUALITY_GRAYSCALE(27000 +367): nMode = OUTPUT_DRAWMODE_GRAYSCALE; break;
1348 case SID_OUTPUT_QUALITY_BLACKWHITE(27000 +368): nMode = OUTPUT_DRAWMODE_BLACKWHITE; break;
1349 case SID_OUTPUT_QUALITY_CONTRAST(27000 +400): nMode = OUTPUT_DRAWMODE_CONTRAST; break;
1350 }
1351
1352 GetActiveWindow()->SetDrawMode( nMode );
1353 mpFrameView->SetDrawMode( nMode );
1354
1355 GetActiveWindow()->Invalidate();
1356
1357 Invalidate();
1358 rReq.Done();
1359 break;
1360 }
1361 }
1362}
1363
1364/** This default implementation returns only an empty reference. See derived
1365 classes for more interesting examples.
1366*/
1367css::uno::Reference<css::accessibility::XAccessible>
1368ViewShell::CreateAccessibleDocumentView (::sd::Window* )
1369{
1370 OSL_FAIL("ViewShell::CreateAccessibleDocumentView should not be called!, perhaps Meyers, 3rd edition, Item 9:")do { if (true && (((sal_Bool)1))) { sal_detail_logFormat
((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.osl"), ("/home/maarten/src/libreoffice/core/sd/source/ui/view/viewshel.cxx"
":" "1370" ": "), "%s", "ViewShell::CreateAccessibleDocumentView should not be called!, perhaps Meyers, 3rd edition, Item 9:"
); } } while (false)
;
1371
1372 return css::uno::Reference<css::accessibility::XAccessible> ();
1373}
1374
1375::sd::WindowUpdater* ViewShell::GetWindowUpdater() const
1376{
1377 return mpWindowUpdater.get();
1378}
1379
1380ViewShellBase& ViewShell::GetViewShellBase() const
1381{
1382 return *static_cast<ViewShellBase*>(GetViewShell());
1383}
1384
1385ViewShell::ShellType ViewShell::GetShellType() const
1386{
1387 return meShellType;
1388}
1389
1390DrawDocShell* ViewShell::GetDocSh() const
1391{
1392 return GetViewShellBase().GetDocShell();
1393}
1394
1395SdDrawDocument* ViewShell::GetDoc() const
1396{
1397 return GetViewShellBase().GetDocument();
1398}
1399
1400ErrCode ViewShell::DoVerb (long )
1401{
1402 return ERRCODE_NONEErrCode(0);
1403}
1404
1405void ViewShell::SetCurrentFunction( const rtl::Reference<FuPoor>& xFunction)
1406{
1407 if( mxCurrentFunction.is() && (mxOldFunction != mxCurrentFunction) )
1408 mxCurrentFunction->Dispose();
1409 rtl::Reference<FuPoor> xDisposeAfterNewOne( mxCurrentFunction );
1410 mxCurrentFunction = xFunction;
1411}
1412
1413void ViewShell::SetOldFunction(const rtl::Reference<FuPoor>& xFunction)
1414{
1415 if( mxOldFunction.is() && (xFunction != mxOldFunction) && (mxCurrentFunction != mxOldFunction) )
1416 mxOldFunction->Dispose();
1417
1418 rtl::Reference<FuPoor> xDisposeAfterNewOne( mxOldFunction );
1419 mxOldFunction = xFunction;
1420}
1421
1422/** this method deactivates the current function. If an old function is
1423 saved, this will become activated and current function.
1424*/
1425void ViewShell::Cancel()
1426{
1427 if(mxCurrentFunction.is() && (mxCurrentFunction != mxOldFunction ))
1428 {
1429 rtl::Reference<FuPoor> xTemp( mxCurrentFunction );
1430 mxCurrentFunction.clear();
1431 xTemp->Deactivate();
1432 xTemp->Dispose();
1433 }
1434
1435 if(mxOldFunction.is())
1436 {
1437 mxCurrentFunction = mxOldFunction;
1438 mxCurrentFunction->Activate();
1439 }
1440}
1441
1442void ViewShell::DeactivateCurrentFunction( bool bPermanent /* == false */ )
1443{
1444 if( mxCurrentFunction.is() )
1445 {
1446 if(bPermanent && (mxOldFunction == mxCurrentFunction))
1447 mxOldFunction.clear();
1448
1449 mxCurrentFunction->Deactivate();
1450 if( mxCurrentFunction != mxOldFunction )
1451 mxCurrentFunction->Dispose();
1452
1453 rtl::Reference<FuPoor> xDisposeAfterNewOne( mxCurrentFunction );
1454 mxCurrentFunction.clear();
1455 }
1456}
1457
1458void ViewShell::DisposeFunctions()
1459{
1460 if(mxCurrentFunction.is())
1461 {
1462 rtl::Reference<FuPoor> xTemp( mxCurrentFunction );
1463 mxCurrentFunction.clear();
1464 xTemp->Deactivate();
1465 xTemp->Dispose();
1466 }
1467
1468 if(mxOldFunction.is())
1469 {
1470 rtl::Reference<FuPoor> xDisposeAfterNewOne( mxOldFunction );
1471 mxOldFunction->Dispose();
1472 mxOldFunction.clear();
1473 }
1474}
1475
1476bool ViewShell::IsMainViewShell() const
1477{
1478 return mpImpl->mbIsMainViewShell;
1479}
1480
1481void ViewShell::SetIsMainViewShell (bool bIsMainViewShell)
1482{
1483 if (bIsMainViewShell != mpImpl->mbIsMainViewShell)
1484 {
1485 mpImpl->mbIsMainViewShell = bIsMainViewShell;
1486 if (bIsMainViewShell)
1487 GetDocSh()->Connect (this);
1488 else
1489 GetDocSh()->Disconnect (this);
1490 }
1491}
1492
1493void ViewShell::PrePaint()
1494{
1495}
1496
1497void ViewShell::Paint (const ::tools::Rectangle&, ::sd::Window* )
1498{
1499}
1500
1501void ViewShell::ShowUIControls (bool bVisible)
1502{
1503 if (mbHasRulers)
1504 {
1505 if (mpHorizontalRuler)
1506 mpHorizontalRuler->Show( bVisible );
1507
1508 if (mpVerticalRuler)
1509 mpVerticalRuler->Show( bVisible );
1510 }
1511
1512 if (mpVerticalScrollBar)
1513 mpVerticalScrollBar->Show( bVisible );
1514
1515 if (mpHorizontalScrollBar)
1516 mpHorizontalScrollBar->Show( bVisible );
1517
1518 if (mpScrollBarBox)
1519 mpScrollBarBox->Show(bVisible);
1520
1521 if (mpContentWindow)
1522 mpContentWindow->Show( bVisible );
1523}
1524
1525bool ViewShell::RelocateToParentWindow (vcl::Window* pParentWindow)
1526{
1527 mpParentWindow = pParentWindow;
1528
1529 mpParentWindow->SetBackground (Wallpaper());
1530
1531 if (mpContentWindow)
1532 mpContentWindow->SetParent(pParentWindow);
1533
1534 if (mpHorizontalScrollBar)
1535 mpHorizontalScrollBar->SetParent(mpParentWindow);
1536 if (mpVerticalScrollBar)
1537 mpVerticalScrollBar->SetParent(mpParentWindow);
1538 if (mpScrollBarBox)
1539 mpScrollBarBox->SetParent(mpParentWindow);
1540
1541 return true;
1542}
1543
1544void ViewShell::SwitchViewFireFocus(const css::uno::Reference< css::accessibility::XAccessible >& xAcc )
1545{
1546 if (xAcc)
1547 {
1548 ::accessibility::AccessibleDocumentViewBase* pBase = static_cast< ::accessibility::AccessibleDocumentViewBase* >(xAcc.get());
1549 if (pBase)
1550 pBase->SwitchViewActivated();
1551 }
1552}
1553void ViewShell::SwitchActiveViewFireFocus()
1554{
1555 if (mpContentWindow)
1556 {
1557 SwitchViewFireFocus(mpContentWindow->GetAccessible(false));
1558 }
1559}
1560// move these two methods from DrawViewShell.
1561void ViewShell::fireSwitchCurrentPage(sal_Int32 pageIndex)
1562{
1563 GetViewShellBase().GetDrawController().fireSwitchCurrentPage(pageIndex);
1564}
1565void ViewShell::NotifyAccUpdate( )
1566{
1567 GetViewShellBase().GetDrawController().NotifyAccUpdate();
1568}
1569
1570weld::Window* ViewShell::GetFrameWeld() const
1571{
1572 return mpActiveWindow ? mpActiveWindow->GetFrameWeld() : nullptr;
1573}
1574
1575sd::Window* ViewShell::GetContentWindow() const
1576{
1577 return mpContentWindow.get();
1578}
1579
1580} // end of namespace sd
1581
1582//===== ViewShellObjectBarFactory =============================================
1583
1584namespace {
1585
1586ViewShellObjectBarFactory::ViewShellObjectBarFactory (
1587 ::sd::ViewShell& rViewShell)
1588 : mrViewShell (rViewShell)
1589{
1590}
1591
1592SfxShell* ViewShellObjectBarFactory::CreateShell( ::sd::ShellId nId )
1593{
1594 SfxShell* pShell = nullptr;
1595
1596 ::sd::View* pView = mrViewShell.GetView();
1597 switch (nId)
1598 {
1599 case ToolbarId::Bezier_Toolbox_Sd:
1600 pShell = new ::sd::BezierObjectBar(&mrViewShell, pView);
1601 break;
1602
1603 case ToolbarId::Draw_Text_Toolbox_Sd:
1604 pShell = new ::sd::TextObjectBar(
1605 &mrViewShell, mrViewShell.GetDoc()->GetPool(), pView);
1606 break;
1607
1608 case ToolbarId::Draw_Graf_Toolbox:
1609 pShell = new ::sd::GraphicObjectBar(&mrViewShell, pView);
1610 break;
1611
1612 case ToolbarId::Draw_Media_Toolbox:
1613 pShell = new ::sd::MediaObjectBar(&mrViewShell, pView);
1614 break;
1615
1616 case ToolbarId::Draw_Table_Toolbox:
1617 pShell = ::sd::ui::table::CreateTableObjectBar( mrViewShell, pView );
1618 break;
1619
1620 case ToolbarId::Svx_Extrusion_Bar:
1621 pShell = new svx::ExtrusionBar(
1622 &mrViewShell.GetViewShellBase());
1623 break;
1624
1625 case ToolbarId::Svx_Fontwork_Bar:
1626 pShell = new svx::FontworkBar(
1627 &mrViewShell.GetViewShellBase());
1628 break;
1629
1630 default:
1631 pShell = nullptr;
1632 break;
1633 }
1634
1635 return pShell;
1636}
1637
1638void ViewShellObjectBarFactory::ReleaseShell (SfxShell* pShell)
1639{
1640 delete pShell;
1641}
1642
1643} // end of anonymous namespace
1644
1645/* vim:set shiftwidth=4 softtabstop=4 expandtab: */

/home/maarten/src/libreoffice/core/include/vcl/vclptr.hxx

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
36class VclReferenceBase;
37
38namespace vcl::detail {
39
40template<typename>
41constexpr bool isIncompleteOrDerivedFromVclReferenceBase(...) { return true; }
42
43template<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 */
56template <class reference_type>
57class 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
66public:
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);
3
Calling copy constructor for 'Reference<sd::LayerTabBar>'
6
Returning from copy constructor for 'Reference<sd::LayerTabBar>'
204 m_rInnerRef.clear(); // we should use some 'swap' method ideally ;-)
7
Calling 'Reference::clear'
14
Returning; memory was released
205 if (aTmp.get()) {
15
Calling 'Reference::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
218template<typename T1, typename T2>
219inline bool operator ==(VclPtr<T1> const & p1, VclPtr<T2> const & p2) {
220 return p1.get() == p2.get();
221}
222
223template<typename T> inline bool operator ==(VclPtr<T> const & p1, T const * p2)
224{
225 return p1.get() == p2;
226}
227
228template<typename T> inline bool operator ==(VclPtr<T> const & p1, T * p2) {
229 return p1.get() == p2;
230}
231
232template<typename T> inline bool operator ==(T const * p1, VclPtr<T> const & p2)
233{
234 return p1 == p2.get();
235}
236
237template<typename T> inline bool operator ==(T * p1, VclPtr<T> const & p2) {
238 return p1 == p2.get();
239}
240
241template<typename T1, typename T2>
242inline bool operator !=(VclPtr<T1> const & p1, VclPtr<T2> const & p2) {
243 return !(p1 == p2);
244}
245
246template<typename T> inline bool operator !=(VclPtr<T> const & p1, T const * p2)
247{
248 return !(p1 == p2);
249}
250
251template<typename T> inline bool operator !=(VclPtr<T> const & p1, T * p2) {
252 return !(p1 == p2);
253}
254
255template<typename T> inline bool operator !=(T const * p1, VclPtr<T> const & p2)
256{
257 return !(p1 == p2);
258}
259
260template<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 */
274template <class reference_type>
275class SAL_WARN_UNUSED__attribute__((warn_unused)) VclPtrInstance final : public VclPtr<reference_type>
276{
277public:
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
290template <class reference_type>
291class ScopedVclPtr : public VclPtr<reference_type>
292{
293public:
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
378private:
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
387protected:
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
406template <class reference_type>
407class SAL_WARN_UNUSED__attribute__((warn_unused)) ScopedVclPtrInstance final : public ScopedVclPtr<reference_type>
408{
409public:
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
421private:
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: */

/home/maarten/src/libreoffice/core/include/rtl/ref.hxx

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
34namespace rtl
35{
36
37/** Template reference class for reference type.
38*/
39template <class reference_type>
40class Reference
41{
42 /** The <b>reference_type</b> body pointer.
43 */
44 reference_type * m_pBody;
45
46
47public:
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)
4
Assuming field 'm_pBody' is non-null
5
Taking true branch
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
7.1
Field 'm_pBody' is non-null
7.1
Field 'm_pBody' is non-null
7.1
Field 'm_pBody' is non-null
7.1
Field 'm_pBody' is non-null
)
8
Taking true branch
177 {
178 reference_type * const pOld = m_pBody;
179 m_pBody = NULL__null;
180 pOld->release();
9
Calling 'VclReferenceBase::release'
13
Returning; memory was released
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;
16
Use of memory after it is freed
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
277namespace 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*/
286template<typename T>
287struct 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: */

/home/maarten/src/libreoffice/core/include/vcl/vclreferencebase.hxx

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
25class VCL_DLLPUBLIC__attribute__ ((visibility("default"))) VclReferenceBase
26{
27 mutable oslInterlockedCount mnRefCnt;
28
29 template<typename T> friend class VclPtr;
30
31public:
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)
10
Assuming the condition is true
11
Taking true branch
40 delete this;
12
Memory is released
41 }
42#ifdef DBG_UTIL
43#ifndef _WIN32
44 sal_Int32 getRefCount() const { return mnRefCnt; }
45#endif
46#endif
47
48
49private:
50 VclReferenceBase(const VclReferenceBase&) = delete;
51 VclReferenceBase& operator=(const VclReferenceBase&) = delete;
52
53 bool mbDisposed : 1;
54
55protected:
56 VclReferenceBase();
57protected:
58 virtual ~VclReferenceBase();
59
60protected:
61 virtual void dispose();
62
63public:
64 void disposeOnce();
65 bool isDisposed() const { return mbDisposed; }
66
67};
68#endif