LibreOffice Module sd (master) 1
SlideSorter.cxx
Go to the documentation of this file.
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 <SlideSorter.hxx>
21
22#include <com/sun/star/frame/XController.hpp>
23
28#include <o3tl/deleter.hxx>
30#include <view/SlsTheme.hxx>
32
33#include <ViewShell.hxx>
34#include <ViewShellBase.hxx>
35#include <Window.hxx>
36
37#include <tools/debug.hxx>
38#include <vcl/svapp.hxx>
39#include <vcl/settings.hxx>
40
41using namespace ::com::sun::star::uno;
42using namespace ::com::sun::star;
43
44namespace sd::slidesorter {
45
46//===== SlideSorter ===========================================================
47
48std::shared_ptr<SlideSorter> SlideSorter::CreateSlideSorter(
49 ViewShell& rViewShell,
50 sd::Window* pContentWindow,
51 ScrollAdaptor* pHorizontalScrollBar,
52 ScrollAdaptor* pVerticalScrollBar)
53{
54 std::shared_ptr<SlideSorter> pSlideSorter(
55 new SlideSorter(
56 rViewShell,
57 pContentWindow,
58 pHorizontalScrollBar,
59 pVerticalScrollBar),
61 pSlideSorter->Init();
62 return pSlideSorter;
63}
64
66 ViewShell& rViewShell,
67 sd::Window* pContentWindow,
68 ScrollAdaptor* pHorizontalScrollBar,
69 ScrollAdaptor* pVerticalScrollBar)
70 : mpViewShell(&rViewShell),
71 mpViewShellBase(&rViewShell.GetViewShellBase()),
72 mpContentWindow(pContentWindow),
73 mpHorizontalScrollBar(pHorizontalScrollBar),
74 mpVerticalScrollBar(pVerticalScrollBar),
75 mpProperties(std::make_shared<controller::Properties>()),
76 mpTheme(std::make_shared<view::Theme>(mpProperties))
77{
78}
79
81{
82 if (mpViewShellBase != nullptr)
84
85 // Reinitialize colors in Properties with window specific values.
87 {
88 mpProperties->SetBackgroundColor(
89 mpContentWindow->GetSettings().GetStyleSettings().GetWindowColor());
90 mpProperties->SetSelectionColor(
91 mpContentWindow->GetSettings().GetStyleSettings().GetMenuHighlightColor());
92 }
93
95
97
98 // Initialize the window.
99 sd::Window *pContentWindow = GetContentWindow().get();
100 if (!pContentWindow)
101 return;
102
103 vcl::Window* pParentWindow = pContentWindow->GetParent();
104 if (pParentWindow != nullptr)
105 pParentWindow->SetBackground(Application::GetSettings().GetStyleSettings().GetFaceColor());
106 pContentWindow->SetBackground(Wallpaper());
107 pContentWindow->SetViewOrigin (Point(0,0));
108 // We do our own scrolling while dragging a page selection.
109 pContentWindow->SetUseDropScroll (false);
110 // Change the winbits so that the active window accepts the focus.
111 pContentWindow->SetStyle ((pContentWindow->GetStyle() & ~WB_DIALOGCONTROL) | WB_TABSTOP);
112 pContentWindow->Hide();
113
114 // Set view pointer of base class.
116}
117
119{
121
122 // Dispose model, view and controller to avoid calls between them when
123 // they are being destructed and one or two of them are already gone.
124 mpSlideSorterController->Dispose();
125 mpSlideSorterView->Dispose();
126 mpSlideSorterModel->Dispose();
127
128 // Reset the auto pointers explicitly to control the order of destruction.
130 mpSlideSorterView.reset();
131 mpSlideSorterModel.reset();
132
135}
136
138{
139 assert(mpSlideSorterModel);
140 return *mpSlideSorterModel;
141}
142
144{
145 assert(mpSlideSorterView);
146 return *mpSlideSorterView;
147}
148
150{
153}
154
155Reference<frame::XController> SlideSorter::GetXController() const
156{
157 Reference<frame::XController> xController(mxControllerWeak);
158 return xController;
159}
160
162{
163 GetVerticalScrollBar()->Show();
164}
165
167{
168 sd::Window *pWindow = GetContentWindow().get();
169 if (pWindow)
170 {
171 vcl::Window* pParentWindow = pWindow->GetParent();
172 if (pParentWindow != nullptr)
173 pParentWindow->AddEventListener(
174 LINK(
177 WindowEventHandler));
178 pWindow->AddEventListener(
179 LINK(
182 WindowEventHandler));
183 }
185 LINK(
188 ApplicationEventHandler));
189
190 mpSlideSorterController->GetScrollBarManager().Connect();
191}
192
194{
195 mpSlideSorterController->GetScrollBarManager().Disconnect();
196
197 sd::Window *pWindow (GetContentWindow().get());
198 if (pWindow)
199 {
200 pWindow->RemoveEventListener(
203 WindowEventHandler));
204
205 vcl::Window* pParentWindow = pWindow->GetParent();
206 if (pParentWindow != nullptr)
207 pParentWindow->RemoveEventListener(
210 WindowEventHandler));
211 }
215 ApplicationEventHandler));
216}
217
219{
221 DBG_ASSERT(mpSlideSorterModel != nullptr, "Can not create model for slide browser");
222
223 mpSlideSorterView.reset(new view::SlideSorterView (*this));
225
226 // Now that model, view, and controller are constructed, do the
227 // initialization that relies on all three being in place.
229 mpSlideSorterView->Init();
230}
231
233{
234 // Get pointers to the document.
235 ViewShellBase* pViewShellBase = GetViewShellBase();
236 if (pViewShellBase != nullptr)
237 {
238 assert (pViewShellBase->GetDocument() != nullptr);
239
240 return new model::SlideSorterModel(*this);
241 }
242 else
243 return nullptr;
244}
245
247 const Point& rOffset,
248 const Size& rSize)
249{
250 Point aOrigin (rOffset);
251
252 if (rSize.Width()>0
253 && rSize.Height()>0
255 && GetContentWindow()->IsVisible())
256 {
257 // Prevent untimely redraws while the view is not yet correctly
258 // resized.
260 GetContentWindow()->EnablePaint (false);
261
262 mpSlideSorterController->Resize (::tools::Rectangle(aOrigin, rSize));
263
264 GetContentWindow()->EnablePaint (true);
265 }
266}
267
269{
270 // Stop all animations for they have been started for the old window.
271 mpSlideSorterController->GetAnimator()->RemoveAllAnimations();
272
274
275 if (mpViewShell)
276 {
277 mpViewShell->ViewShell::RelocateToParentWindow(pParentWindow);
278 }
279
282
283 // For accessibility we have to shortly hide the content window. This
284 // triggers the construction of a new accessibility object for the new
285 // view shell. (One is created earlier while the constructor of the base
286 // class is executed. But because at that time the correct
287 // accessibility object can not be constructed we do that now.)
288 if (mpContentWindow)
289 {
290 mpContentWindow->Hide();
291 mpContentWindow->Show();
292 }
293}
294
296{
297 if (GetViewShell() != nullptr)
298 {
299 GetViewShell()->SetCurrentFunction(rpFunction);
300 GetViewShell()->SetOldFunction(rpFunction);
301 }
302}
303
304std::shared_ptr<controller::Properties> const & SlideSorter::GetProperties() const
305{
306 assert(mpProperties);
307 return mpProperties;
308}
309
310std::shared_ptr<view::Theme> const & SlideSorter::GetTheme() const
311{
312 assert(mpTheme);
313 return mpTheme;
314}
315
316} // end of namespace ::sd::slidesorter
317
318/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
static void AddEventListener(const Link< VclSimpleEvent &, void > &rEventListener)
static const AllSettings & GetSettings()
static void RemoveEventListener(const Link< VclSimpleEvent &, void > &rEventListener)
css::uno::Reference< css::frame::XController > GetController() const
constexpr tools::Long Height() const
constexpr tools::Long Width() const
void reset(reference_type *pBody)
reference_type * get() const
SfxViewShell descendant that the stacked Draw/Impress shells are based on.
SdDrawDocument * GetDocument() const
Base class of the stacked shell hierarchy.
Definition: ViewShell.hxx:92
void SetOldFunction(const rtl::Reference< FuPoor > &xFunction)
Definition: viewshel.cxx:1430
void SetCurrentFunction(const rtl::Reference< FuPoor > &xFunction)
Definition: viewshel.cxx:1422
An SdWindow contains the actual working area of ViewShell.
Definition: Window.hxx:45
void SetUseDropScroll(bool bUseDropScroll)
The DropScroll() method is used by AcceptDrop() to scroll the content of the window while dragging an...
Definition: sdwindow.cxx:910
void SetViewOrigin(const Point &rPnt)
Set origin of the representation in respect to the whole working area.
Definition: sdwindow.cxx:312
static std::shared_ptr< SlideSorter > CreateSlideSorter(ViewShell &rViewShell, sd::Window *pContentWindow, ScrollAdaptor *pHorizontalScrollBar, ScrollAdaptor *pVerticalScrollBar)
Create a new slide sorter that is strongly coupled to the given view shell.
Definition: SlideSorter.cxx:48
model::SlideSorterModel * CreateModel()
Create the model for the view shell.
void SetupListeners()
This method is usually called exactly one time from the constructor.
std::shared_ptr< controller::Properties > const & GetProperties() const
Return a collection of properties that are used throughout the slide sorter.
VclPtr< ScrollAdaptor > mpHorizontalScrollBar
VclPtr< sd::Window > mpContentWindow
std::unique_ptr< model::SlideSorterModel > mpSlideSorterModel
css::uno::WeakReference< css::frame::XController > mxControllerWeak
SlideSorter(const SlideSorter &)=delete
Forbid copy construction and copy assignment.
css::uno::Reference< css::frame::XController > GetXController() const
Return the XController object of the main view.
std::unique_ptr< view::SlideSorterView > mpSlideSorterView
std::shared_ptr< controller::Properties > mpProperties
Some slide sorter wide properties that are used in different classes.
void SetupControls()
Create the controls for the slide sorter.
ViewShellBase * mpViewShellBase
std::shared_ptr< view::Theme > const & GetTheme() const
Return the active theme which gives access to colors and fonts.
void ArrangeGUIElements(const Point &rOffset, const Size &rSize)
Place and size the controls and windows.
void ReleaseListeners()
Release the listeners that have been installed in SetupListeners().
SD_DLLPUBLIC controller::SlideSorterController & GetController() const
ViewShell * GetViewShell() const
Return the view shell that was given at construction.
std::unique_ptr< controller::SlideSorterController > mpSlideSorterController
void RelocateToWindow(vcl::Window *pWindow)
const VclPtr< ScrollAdaptor > & GetVerticalScrollBar() const
Return the control of the vertical scroll bar.
Definition: SlideSorter.hxx:90
void SetCurrentFunction(const rtl::Reference< FuPoor > &rpFunction)
Set the current function at the view shell or, when it is not present, set it at the content window.
ViewShellBase * GetViewShellBase() const
Return the ViewShellBase object.
const VclPtr< sd::Window > & GetContentWindow() const
Return the content window.
Definition: SlideSorter.hxx:99
model::SlideSorterModel & GetModel() const
std::shared_ptr< view::Theme > mpTheme
view::SlideSorterView & GetView() const
void CreateModelViewController()
This virtual method makes it possible to create a specialization of the slide sorter view shell that ...
VclPtr< ScrollAdaptor > mpVerticalScrollBar
The model of the slide sorter gives access to the slides that are to be displayed in the slide sorter...
void SetStyle(WinBits nStyle)
vcl::Window * GetParent() const
void RemoveEventListener(const Link< VclWindowEvent &, void > &rEventListener)
WinBits GetStyle() const
void AddEventListener(const Link< VclWindowEvent &, void > &rEventListener)
void SetBackground()
#define DBG_ASSERT(sCon, aError)
std::shared_ptr< T > make_shared(Args &&... args)
css::uno::Reference< css::linguistic2::XProofreadingIterator > get(css::uno::Reference< css::uno::XComponentContext > const &context)
Reference< XController > xController
WinBits const WB_DIALOGCONTROL
WinBits const WB_TABSTOP