bump product version to 5.0.4.1
[LibreOffice.git] / sd / source / ui / slidesorter / shell / SlideSorter.cxx
bloba97135c718a2343556e8934cc2e26ffdb87d8913
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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 "SlideSorterViewShell.hxx"
23 #include "controller/SlideSorterController.hxx"
24 #include "controller/SlsScrollBarManager.hxx"
25 #include "controller/SlsProperties.hxx"
26 #include "controller/SlsAnimator.hxx"
27 #include "view/SlideSorterView.hxx"
28 #include "view/SlsTheme.hxx"
29 #include "model/SlideSorterModel.hxx"
31 #include "glob.hrc"
32 #include "DrawController.hxx"
33 #include "ViewShellBase.hxx"
34 #include "ViewShellManager.hxx"
35 #include "Window.hxx"
37 #include <vcl/scrbar.hxx>
38 #include <vcl/svapp.hxx>
39 #include <vcl/settings.hxx>
41 #include <sfx2/dispatch.hxx>
42 #include "sdresid.hxx"
44 using namespace ::com::sun::star::uno;
45 using namespace ::com::sun::star;
47 namespace sd { namespace slidesorter {
49 namespace {
50 class ContentWindow : public ::sd::Window
52 public:
53 ContentWindow(vcl::Window& rParent, SlideSorter& rSlideSorter);
54 virtual ~ContentWindow();
55 void SetCurrentFunction (const rtl::Reference<FuPoor>& rpFunction);
56 virtual void Paint(vcl::RenderContext& /*rRenderContext*/, const Rectangle& rRect) SAL_OVERRIDE;
57 virtual void KeyInput (const KeyEvent& rEvent) SAL_OVERRIDE;
58 virtual void MouseMove (const MouseEvent& rEvent) SAL_OVERRIDE;
59 virtual void MouseButtonUp (const MouseEvent& rEvent) SAL_OVERRIDE;
60 virtual void MouseButtonDown (const MouseEvent& rEvent) SAL_OVERRIDE;
61 virtual void Command (const CommandEvent& rEvent) SAL_OVERRIDE;
62 virtual bool Notify (NotifyEvent& rEvent) SAL_OVERRIDE;
64 private:
65 SlideSorter& mrSlideSorter;
66 rtl::Reference<FuPoor> mpCurrentFunction;
70 //===== SlideSorter ===========================================================
72 ::boost::shared_ptr<SlideSorter> SlideSorter::CreateSlideSorter(
73 ViewShell& rViewShell,
74 sd::Window* pContentWindow,
75 ScrollBar* pHorizontalScrollBar,
76 ScrollBar* pVerticalScrollBar,
77 ScrollBarBox* pScrollBarBox)
79 ::boost::shared_ptr<SlideSorter> pSlideSorter(
80 new SlideSorter(
81 rViewShell,
82 pContentWindow,
83 pHorizontalScrollBar,
84 pVerticalScrollBar,
85 pScrollBarBox));
86 pSlideSorter->Init();
87 return pSlideSorter;
90 ::boost::shared_ptr<SlideSorter> SlideSorter::CreateSlideSorter (
91 ViewShellBase& rBase,
92 ViewShell* pViewShell,
93 vcl::Window& rParentWindow)
95 ::boost::shared_ptr<SlideSorter> pSlideSorter(
96 new SlideSorter(
97 rBase,
98 pViewShell,
99 rParentWindow));
100 pSlideSorter->Init();
101 return pSlideSorter;
104 SlideSorter::SlideSorter (
105 ViewShell& rViewShell,
106 sd::Window* pContentWindow,
107 ScrollBar* pHorizontalScrollBar,
108 ScrollBar* pVerticalScrollBar,
109 ScrollBarBox* pScrollBarBox)
110 : mbIsValid(false),
111 mpSlideSorterController(),
112 mpSlideSorterModel(),
113 mpSlideSorterView(),
114 mxControllerWeak(),
115 mpViewShell(&rViewShell),
116 mpViewShellBase(&rViewShell.GetViewShellBase()),
117 mpContentWindow(pContentWindow),
118 mbOwnesContentWindow(false),
119 mpHorizontalScrollBar(pHorizontalScrollBar),
120 mpVerticalScrollBar(pVerticalScrollBar),
121 mpScrollBarBox(pScrollBarBox),
122 mbLayoutPending(true),
123 mpProperties(new controller::Properties()),
124 mpTheme(new view::Theme(mpProperties))
128 SlideSorter::SlideSorter (
129 ViewShellBase& rBase,
130 ViewShell* pViewShell,
131 vcl::Window& rParentWindow)
132 : mbIsValid(false),
133 mpSlideSorterController(),
134 mpSlideSorterModel(),
135 mpSlideSorterView(),
136 mxControllerWeak(),
137 mpViewShell(pViewShell),
138 mpViewShellBase(&rBase),
139 mpContentWindow(VclPtr<ContentWindow>::Create(rParentWindow,*this )),
140 mbOwnesContentWindow(true),
141 mpHorizontalScrollBar(VclPtr<ScrollBar>::Create(&rParentWindow,WinBits(WB_HSCROLL | WB_DRAG))),
142 mpVerticalScrollBar(VclPtr<ScrollBar>::Create(&rParentWindow,WinBits(WB_VSCROLL | WB_DRAG))),
143 mpScrollBarBox(VclPtr<ScrollBarBox>::Create(&rParentWindow)),
144 mbLayoutPending(true),
145 mpProperties(new controller::Properties()),
146 mpTheme(new view::Theme(mpProperties))
150 void SlideSorter::Init()
152 if (mpViewShellBase != NULL)
153 mxControllerWeak = mpViewShellBase->GetController();
155 // Reinitialize colors in Properties with window specific values.
156 if (mpContentWindow)
158 mpProperties->SetBackgroundColor(
159 mpContentWindow->GetSettings().GetStyleSettings().GetWindowColor());
160 mpProperties->SetTextColor(
161 mpContentWindow->GetSettings().GetStyleSettings().GetWindowTextColor());
162 mpProperties->SetSelectionColor(
163 mpContentWindow->GetSettings().GetStyleSettings().GetMenuHighlightColor());
164 mpProperties->SetHighlightColor(
165 mpContentWindow->GetSettings().GetStyleSettings().GetMenuHighlightColor());
168 CreateModelViewController ();
170 SetupListeners ();
172 // Initialize the window.
173 sd::Window *pContentWindow (GetContentWindow());
174 if (pContentWindow)
176 vcl::Window* pParentWindow = pContentWindow->GetParent();
177 if (pParentWindow != NULL)
178 pParentWindow->SetBackground(Wallpaper());
179 pContentWindow->SetBackground(Wallpaper());
180 pContentWindow->SetViewOrigin (Point(0,0));
181 // We do our own scrolling while dragging a page selection.
182 pContentWindow->SetUseDropScroll (false);
183 // Change the winbits so that the active window accepts the focus.
184 pContentWindow->SetStyle ((pContentWindow->GetStyle() & ~WB_DIALOGCONTROL) | WB_TABSTOP);
185 pContentWindow->Hide();
187 // Set view pointer of base class.
188 SetupControls(pParentWindow);
190 mbIsValid = true;
194 SlideSorter::~SlideSorter()
196 mbIsValid = false;
198 ReleaseListeners();
200 // Dispose model, view and controller to avoid calls between them when
201 // they are being destructed and one or two of them are already gone.
202 mpSlideSorterController->Dispose();
203 mpSlideSorterView->Dispose();
204 mpSlideSorterModel->Dispose();
206 // Reset the auto pointers explicitly to control the order of destruction.
207 mpSlideSorterController.reset();
208 mpSlideSorterView.reset();
209 mpSlideSorterModel.reset();
211 mpHorizontalScrollBar.reset();
212 mpVerticalScrollBar.reset();
213 mpScrollBarBox.reset();
216 model::SlideSorterModel& SlideSorter::GetModel() const
218 OSL_ASSERT(mpSlideSorterModel.get()!=NULL);
219 return *mpSlideSorterModel;
222 view::SlideSorterView& SlideSorter::GetView() const
224 OSL_ASSERT(mpSlideSorterView.get()!=NULL);
225 return *mpSlideSorterView;
228 controller::SlideSorterController& SlideSorter::GetController() const
230 OSL_ASSERT(mpSlideSorterController.get()!=NULL);
231 return *mpSlideSorterController;
234 Reference<frame::XController> SlideSorter::GetXController() const
236 Reference<frame::XController> xController(mxControllerWeak);
237 return xController;
240 void SlideSorter::Paint (const Rectangle& rRepaintArea)
242 GetController().Paint(
243 rRepaintArea,
244 GetContentWindow());
247 void SlideSorter::SetupControls (vcl::Window* )
249 GetVerticalScrollBar()->Show();
252 void SlideSorter::SetupListeners()
254 sd::Window *pWindow (GetContentWindow());
255 if (pWindow)
257 vcl::Window* pParentWindow = pWindow->GetParent();
258 if (pParentWindow != NULL)
259 pParentWindow->AddEventListener(
260 LINK(
261 mpSlideSorterController.get(),
262 controller::SlideSorterController,
263 WindowEventHandler));
264 pWindow->AddEventListener(
265 LINK(
266 mpSlideSorterController.get(),
267 controller::SlideSorterController,
268 WindowEventHandler));
270 Application::AddEventListener(
271 LINK(
272 mpSlideSorterController.get(),
273 controller::SlideSorterController,
274 WindowEventHandler));
276 mpSlideSorterController->GetScrollBarManager().Connect();
279 void SlideSorter::ReleaseListeners()
281 mpSlideSorterController->GetScrollBarManager().Disconnect();
283 sd::Window *pWindow (GetContentWindow());
284 if (pWindow)
286 pWindow->RemoveEventListener(
287 LINK(mpSlideSorterController.get(),
288 controller::SlideSorterController,
289 WindowEventHandler));
291 vcl::Window* pParentWindow = pWindow->GetParent();
292 if (pParentWindow != NULL)
293 pParentWindow->RemoveEventListener(
294 LINK(mpSlideSorterController.get(),
295 controller::SlideSorterController,
296 WindowEventHandler));
298 Application::RemoveEventListener(
299 LINK(mpSlideSorterController.get(),
300 controller::SlideSorterController,
301 WindowEventHandler));
304 void SlideSorter::CreateModelViewController()
306 mpSlideSorterModel.reset(CreateModel());
307 DBG_ASSERT (mpSlideSorterModel.get()!=NULL,
308 "Can not create model for slide browser");
310 mpSlideSorterView.reset(CreateView());
311 DBG_ASSERT (mpSlideSorterView.get()!=NULL,
312 "Can not create view for slide browser");
314 mpSlideSorterController.reset(CreateController());
315 DBG_ASSERT (mpSlideSorterController.get()!=NULL,
316 "Can not create controller for slide browser");
318 // Now that model, view, and controller are constructed, do the
319 // initialization that relies on all three being in place.
320 mpSlideSorterController->Init();
321 mpSlideSorterView->Init();
324 model::SlideSorterModel* SlideSorter::CreateModel()
326 // Get pointers to the document.
327 ViewShellBase* pViewShellBase = GetViewShellBase();
328 if (pViewShellBase != NULL)
330 OSL_ASSERT (pViewShellBase->GetDocument() != NULL);
332 return new model::SlideSorterModel(*this);
334 else
335 return NULL;
338 view::SlideSorterView* SlideSorter::CreateView()
340 return new view::SlideSorterView (*this);
343 controller::SlideSorterController* SlideSorter::CreateController()
345 controller::SlideSorterController* pController
346 = new controller::SlideSorterController (*this);
347 return pController;
350 void SlideSorter::ArrangeGUIElements (
351 const Point& rOffset,
352 const Size& rSize)
354 Point aOrigin (rOffset);
356 if (rSize.Width()>0
357 && rSize.Height()>0
358 && GetContentWindow()
359 && GetContentWindow()->IsVisible())
361 // Prevent untimely redraws while the view is not yet correctly
362 // resized.
363 view::SlideSorterView::DrawLock aLock (*this);
364 GetContentWindow()->EnablePaint (false);
366 mpSlideSorterController->Resize (Rectangle(aOrigin, rSize));
368 GetContentWindow()->EnablePaint (true);
370 mbLayoutPending = false;
374 bool SlideSorter::RelocateToWindow (vcl::Window* pParentWindow)
376 // Stop all animations for they have been started for the old window.
377 mpSlideSorterController->GetAnimator()->RemoveAllAnimations();
379 ReleaseListeners();
381 vcl::Window *pNewWindow = NULL;
382 if (mpViewShell)
384 mpViewShell->ViewShell::RelocateToParentWindow(pParentWindow);
385 pNewWindow = mpViewShell->GetParentWindow();
387 else
388 pNewWindow = NULL;
390 SetupControls(pNewWindow);
391 SetupListeners();
393 // For accessibility we have to shortly hide the content window. This
394 // triggers the construction of a new accessibility object for the new
395 // view shell. (One is created earlier while the construtor of the base
396 // class is executed. But because at that time the correct
397 // accessibility object can not be constructed we do that now.)
398 if (mpContentWindow.get() !=NULL)
400 mpContentWindow->Hide();
401 mpContentWindow->Show();
404 return true;
407 void SlideSorter::SetCurrentFunction (const rtl::Reference<FuPoor>& rpFunction)
409 if (GetViewShell() != NULL)
411 GetViewShell()->SetCurrentFunction(rpFunction);
412 GetViewShell()->SetOldFunction(rpFunction);
414 else
416 ContentWindow* pWindow = dynamic_cast<ContentWindow*>(GetContentWindow().get());
417 if (pWindow != NULL)
418 pWindow->SetCurrentFunction(rpFunction);
422 ::boost::shared_ptr<controller::Properties> SlideSorter::GetProperties() const
424 OSL_ASSERT(mpProperties);
425 return mpProperties;
428 ::boost::shared_ptr<view::Theme> SlideSorter::GetTheme() const
430 OSL_ASSERT(mpTheme);
431 return mpTheme;
434 //===== ContentWindow =========================================================
436 namespace {
438 ContentWindow::ContentWindow(
439 vcl::Window& rParent,
440 SlideSorter& rSlideSorter)
441 : ::sd::Window(&rParent),
442 mrSlideSorter(rSlideSorter),
443 mpCurrentFunction()
445 SetDialogControlFlags(GetDialogControlFlags() & ~WINDOW_DLGCTRL_WANTFOCUS);
446 SetStyle(GetStyle() | WB_NOPOINTERFOCUS);
449 ContentWindow::~ContentWindow()
453 void ContentWindow::SetCurrentFunction (const rtl::Reference<FuPoor>& rpFunction)
455 mpCurrentFunction = rpFunction;
458 void ContentWindow::Paint (vcl::RenderContext& /*rRenderContext*/, const Rectangle& rRect)
460 mrSlideSorter.Paint(rRect);
463 void ContentWindow::KeyInput (const KeyEvent& rEvent)
465 if (mpCurrentFunction.is())
466 mpCurrentFunction->KeyInput(rEvent);
469 void ContentWindow::MouseMove (const MouseEvent& rEvent)
471 if (mpCurrentFunction.is())
472 mpCurrentFunction->MouseMove(rEvent);
475 void ContentWindow::MouseButtonUp(const MouseEvent& rEvent)
477 if (mpCurrentFunction.is())
478 mpCurrentFunction->MouseButtonUp(rEvent);
481 void ContentWindow::MouseButtonDown(const MouseEvent& rEvent)
483 if (mpCurrentFunction.is())
484 mpCurrentFunction->MouseButtonDown(rEvent);
487 void ContentWindow::Command(const CommandEvent& rEvent)
489 if (mpCurrentFunction.is())
490 mpCurrentFunction->Command(rEvent);
493 bool ContentWindow::Notify (NotifyEvent&)
495 return false;
498 } // end of anonymous namespace
500 } } // end of namespace ::sd::slidesorter
502 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */