1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include <SlideSorter.hxx>
22 #include <com/sun/star/frame/XController.hpp>
24 #include <controller/SlideSorterController.hxx>
25 #include <controller/SlsScrollBarManager.hxx>
26 #include <controller/SlsProperties.hxx>
27 #include <controller/SlsAnimator.hxx>
28 #include <o3tl/deleter.hxx>
29 #include <view/SlideSorterView.hxx>
30 #include <view/SlsTheme.hxx>
31 #include <model/SlideSorterModel.hxx>
33 #include <ViewShell.hxx>
34 #include <ViewShellBase.hxx>
37 #include <tools/debug.hxx>
38 #include <vcl/svapp.hxx>
39 #include <vcl/settings.hxx>
41 using namespace ::com::sun::star::uno
;
42 using namespace ::com::sun::star
;
44 namespace sd::slidesorter
{
46 //===== SlideSorter ===========================================================
48 std::shared_ptr
<SlideSorter
> SlideSorter::CreateSlideSorter(
49 ViewShell
& rViewShell
,
50 sd::Window
* pContentWindow
,
51 ScrollAdaptor
* pHorizontalScrollBar
,
52 ScrollAdaptor
* pVerticalScrollBar
)
54 std::shared_ptr
<SlideSorter
> pSlideSorter(
60 o3tl::default_delete
<SlideSorter
>());
65 SlideSorter::SlideSorter (
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
))
80 void SlideSorter::Init()
82 if (mpViewShellBase
!= nullptr)
83 mxControllerWeak
= mpViewShellBase
->GetController();
85 // Reinitialize colors in Properties with window specific values.
88 mpProperties
->SetBackgroundColor(
89 mpContentWindow
->GetSettings().GetStyleSettings().GetWindowColor());
90 mpProperties
->SetSelectionColor(
91 mpContentWindow
->GetSettings().GetStyleSettings().GetMenuHighlightColor());
94 CreateModelViewController ();
98 // Initialize the window.
99 sd::Window
*pContentWindow
= GetContentWindow().get();
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();
114 // Set view pointer of base class.
118 SlideSorter::~SlideSorter()
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();
128 // Reset the auto pointers explicitly to control the order of destruction.
129 mpSlideSorterController
.reset();
130 mpSlideSorterView
.reset();
131 mpSlideSorterModel
.reset();
133 mpHorizontalScrollBar
.reset();
134 mpVerticalScrollBar
.reset();
137 model::SlideSorterModel
& SlideSorter::GetModel() const
139 assert(mpSlideSorterModel
);
140 return *mpSlideSorterModel
;
143 view::SlideSorterView
& SlideSorter::GetView() const
145 assert(mpSlideSorterView
);
146 return *mpSlideSorterView
;
149 controller::SlideSorterController
& SlideSorter::GetController() const
151 assert(mpSlideSorterController
);
152 return *mpSlideSorterController
;
155 Reference
<frame::XController
> SlideSorter::GetXController() const
157 Reference
<frame::XController
> xController(mxControllerWeak
);
161 void SlideSorter::SetupControls()
163 GetVerticalScrollBar()->Show();
166 void SlideSorter::SetupListeners()
168 sd::Window
*pWindow
= GetContentWindow().get();
171 vcl::Window
* pParentWindow
= pWindow
->GetParent();
172 if (pParentWindow
!= nullptr)
173 pParentWindow
->AddEventListener(
175 mpSlideSorterController
.get(),
176 controller::SlideSorterController
,
177 WindowEventHandler
));
178 pWindow
->AddEventListener(
180 mpSlideSorterController
.get(),
181 controller::SlideSorterController
,
182 WindowEventHandler
));
184 Application::AddEventListener(
186 mpSlideSorterController
.get(),
187 controller::SlideSorterController
,
188 ApplicationEventHandler
));
190 mpSlideSorterController
->GetScrollBarManager().Connect();
193 void SlideSorter::ReleaseListeners()
195 mpSlideSorterController
->GetScrollBarManager().Disconnect();
197 sd::Window
*pWindow (GetContentWindow().get());
200 pWindow
->RemoveEventListener(
201 LINK(mpSlideSorterController
.get(),
202 controller::SlideSorterController
,
203 WindowEventHandler
));
205 vcl::Window
* pParentWindow
= pWindow
->GetParent();
206 if (pParentWindow
!= nullptr)
207 pParentWindow
->RemoveEventListener(
208 LINK(mpSlideSorterController
.get(),
209 controller::SlideSorterController
,
210 WindowEventHandler
));
212 Application::RemoveEventListener(
213 LINK(mpSlideSorterController
.get(),
214 controller::SlideSorterController
,
215 ApplicationEventHandler
));
218 void SlideSorter::CreateModelViewController()
220 mpSlideSorterModel
.reset(CreateModel());
221 DBG_ASSERT(mpSlideSorterModel
!= nullptr, "Can not create model for slide browser");
223 mpSlideSorterView
.reset(new view::SlideSorterView (*this));
224 mpSlideSorterController
.reset(new controller::SlideSorterController(*this));
226 // Now that model, view, and controller are constructed, do the
227 // initialization that relies on all three being in place.
228 mpSlideSorterController
->Init();
229 mpSlideSorterView
->Init();
232 model::SlideSorterModel
* SlideSorter::CreateModel()
234 // Get pointers to the document.
235 ViewShellBase
* pViewShellBase
= GetViewShellBase();
236 if (pViewShellBase
!= nullptr)
238 assert (pViewShellBase
->GetDocument() != nullptr);
240 return new model::SlideSorterModel(*this);
246 void SlideSorter::ArrangeGUIElements (
247 const Point
& rOffset
,
250 Point
aOrigin (rOffset
);
254 && GetContentWindow()
255 && GetContentWindow()->IsVisible())
257 // Prevent untimely redraws while the view is not yet correctly
259 view::SlideSorterView::DrawLock
aLock (*this);
260 GetContentWindow()->EnablePaint (false);
262 mpSlideSorterController
->Resize (::tools::Rectangle(aOrigin
, rSize
));
264 GetContentWindow()->EnablePaint (true);
268 void SlideSorter::RelocateToWindow (vcl::Window
* pParentWindow
)
270 // Stop all animations for they have been started for the old window.
271 mpSlideSorterController
->GetAnimator()->RemoveAllAnimations();
277 mpViewShell
->ViewShell::RelocateToParentWindow(pParentWindow
);
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.)
290 mpContentWindow
->Hide();
291 mpContentWindow
->Show();
295 void SlideSorter::SetCurrentFunction (const rtl::Reference
<FuPoor
>& rpFunction
)
297 if (GetViewShell() != nullptr)
299 GetViewShell()->SetCurrentFunction(rpFunction
);
300 GetViewShell()->SetOldFunction(rpFunction
);
304 std::shared_ptr
<controller::Properties
> const & SlideSorter::GetProperties() const
306 assert(mpProperties
);
310 std::shared_ptr
<view::Theme
> const & SlideSorter::GetTheme() const
316 } // end of namespace ::sd::slidesorter
318 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */