Line data Source code
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 :
21 : #include "SlideSorter.hxx"
22 :
23 : #include "SlideSorterChildWindow.hrc"
24 : #include "SlideSorterViewShell.hxx"
25 : #include "controller/SlideSorterController.hxx"
26 : #include "controller/SlsScrollBarManager.hxx"
27 : #include "controller/SlsProperties.hxx"
28 : #include "controller/SlsAnimator.hxx"
29 : #include "view/SlideSorterView.hxx"
30 : #include "view/SlsTheme.hxx"
31 : #include "model/SlideSorterModel.hxx"
32 :
33 : #include "glob.hrc"
34 : #include "DrawController.hxx"
35 : #include "ViewShellBase.hxx"
36 : #include "ViewShellManager.hxx"
37 : #include "Window.hxx"
38 :
39 : #include <vcl/scrbar.hxx>
40 : #include <vcl/svapp.hxx>
41 :
42 : #include <sfx2/dispatch.hxx>
43 : #include "sdresid.hxx"
44 :
45 : using namespace ::com::sun::star::uno;
46 : using namespace ::com::sun::star;
47 :
48 :
49 : namespace sd { namespace slidesorter {
50 :
51 : namespace {
52 : class ContentWindow : public ::sd::Window
53 : {
54 : public:
55 : ContentWindow(::Window& rParent, SlideSorter& rSlideSorter);
56 : ~ContentWindow (void);
57 : void SetCurrentFunction (const FunctionReference& rpFunction);
58 : virtual void Paint(const Rectangle& rRect);
59 : virtual void KeyInput (const KeyEvent& rEvent);
60 : virtual void MouseMove (const MouseEvent& rEvent);
61 : virtual void MouseButtonUp (const MouseEvent& rEvent);
62 : virtual void MouseButtonDown (const MouseEvent& rEvent);
63 : virtual void Command (const CommandEvent& rEvent);
64 : virtual long Notify (NotifyEvent& rEvent);
65 :
66 : private:
67 : SlideSorter& mrSlideSorter;
68 : FunctionReference mpCurrentFunction;
69 : };
70 : }
71 :
72 :
73 :
74 :
75 : //===== SlideSorter ===========================================================
76 :
77 0 : ::boost::shared_ptr<SlideSorter> SlideSorter::CreateSlideSorter(
78 : ViewShell& rViewShell,
79 : const ::boost::shared_ptr<sd::Window>& rpContentWindow,
80 : const ::boost::shared_ptr<ScrollBar>& rpHorizontalScrollBar,
81 : const ::boost::shared_ptr<ScrollBar>& rpVerticalScrollBar,
82 : const ::boost::shared_ptr<ScrollBarBox>& rpScrollBarBox)
83 : {
84 : ::boost::shared_ptr<SlideSorter> pSlideSorter(
85 : new SlideSorter(
86 : rViewShell,
87 : rpContentWindow,
88 : rpHorizontalScrollBar,
89 : rpVerticalScrollBar,
90 0 : rpScrollBarBox));
91 0 : pSlideSorter->Init();
92 0 : return pSlideSorter;
93 : }
94 :
95 :
96 :
97 :
98 0 : ::boost::shared_ptr<SlideSorter> SlideSorter::CreateSlideSorter (
99 : ViewShellBase& rBase,
100 : ViewShell* pViewShell,
101 : ::Window& rParentWindow)
102 : {
103 : ::boost::shared_ptr<SlideSorter> pSlideSorter(
104 : new SlideSorter(
105 : rBase,
106 : pViewShell,
107 0 : rParentWindow));
108 0 : pSlideSorter->Init();
109 0 : return pSlideSorter;
110 : }
111 :
112 :
113 :
114 :
115 0 : SlideSorter::SlideSorter (
116 : ViewShell& rViewShell,
117 : const ::boost::shared_ptr<sd::Window>& rpContentWindow,
118 : const ::boost::shared_ptr<ScrollBar>& rpHorizontalScrollBar,
119 : const ::boost::shared_ptr<ScrollBar>& rpVerticalScrollBar,
120 : const ::boost::shared_ptr<ScrollBarBox>& rpScrollBarBox)
121 : : mbIsValid(false),
122 : mpSlideSorterController(),
123 : mpSlideSorterModel(),
124 : mpSlideSorterView(),
125 : mxControllerWeak(),
126 : mpViewShell(&rViewShell),
127 0 : mpViewShellBase(&rViewShell.GetViewShellBase()),
128 : mpContentWindow(rpContentWindow),
129 : mbOwnesContentWindow(false),
130 : mpHorizontalScrollBar(rpHorizontalScrollBar),
131 : mpVerticalScrollBar(rpVerticalScrollBar),
132 : mpScrollBarBox(rpScrollBarBox),
133 : mbLayoutPending(true),
134 0 : mpProperties(new controller::Properties()),
135 0 : mpTheme(new view::Theme(mpProperties))
136 : {
137 0 : }
138 :
139 :
140 :
141 :
142 0 : SlideSorter::SlideSorter (
143 : ViewShellBase& rBase,
144 : ViewShell* pViewShell,
145 : ::Window& rParentWindow)
146 : : mbIsValid(false),
147 : mpSlideSorterController(),
148 : mpSlideSorterModel(),
149 : mpSlideSorterView(),
150 : mxControllerWeak(),
151 : mpViewShell(pViewShell),
152 : mpViewShellBase(&rBase),
153 0 : mpContentWindow(new ContentWindow(rParentWindow,*this )),
154 : mbOwnesContentWindow(true),
155 0 : mpHorizontalScrollBar(new ScrollBar(&rParentWindow,WinBits(WB_HSCROLL | WB_DRAG))),
156 0 : mpVerticalScrollBar(new ScrollBar(&rParentWindow,WinBits(WB_VSCROLL | WB_DRAG))),
157 0 : mpScrollBarBox(new ScrollBarBox(&rParentWindow)),
158 : mbLayoutPending(true),
159 0 : mpProperties(new controller::Properties()),
160 0 : mpTheme(new view::Theme(mpProperties))
161 : {
162 0 : }
163 :
164 :
165 :
166 :
167 0 : void SlideSorter::Init (void)
168 : {
169 0 : if (mpViewShellBase != NULL)
170 0 : mxControllerWeak = mpViewShellBase->GetController();
171 :
172 : // Reinitialize colors in Properties with window specific values.
173 0 : if (mpContentWindow)
174 : {
175 : mpProperties->SetBackgroundColor(
176 0 : mpContentWindow->GetSettings().GetStyleSettings().GetWindowColor());
177 : mpProperties->SetTextColor(
178 0 : mpContentWindow->GetSettings().GetStyleSettings().GetWindowTextColor());
179 : mpProperties->SetSelectionColor(
180 0 : mpContentWindow->GetSettings().GetStyleSettings().GetMenuHighlightColor());
181 : mpProperties->SetHighlightColor(
182 0 : mpContentWindow->GetSettings().GetStyleSettings().GetMenuHighlightColor());
183 : }
184 :
185 0 : CreateModelViewController ();
186 :
187 0 : SetupListeners ();
188 :
189 : // Initialize the window.
190 0 : SharedSdWindow pContentWindow (GetContentWindow());
191 0 : if (pContentWindow)
192 : {
193 0 : ::Window* pParentWindow = pContentWindow->GetParent();
194 0 : if (pParentWindow != NULL)
195 0 : pParentWindow->SetBackground(Wallpaper());
196 0 : pContentWindow->SetBackground(Wallpaper());
197 0 : pContentWindow->SetViewOrigin (Point(0,0));
198 : // We do our own scrolling while dragging a page selection.
199 0 : pContentWindow->SetUseDropScroll (false);
200 : // Change the winbits so that the active window accepts the focus.
201 0 : pContentWindow->SetStyle ((pContentWindow->GetStyle() & ~WB_DIALOGCONTROL) | WB_TABSTOP);
202 0 : pContentWindow->Hide();
203 :
204 : // Set view pointer of base class.
205 0 : SetupControls(pParentWindow);
206 :
207 0 : mbIsValid = true;
208 0 : }
209 0 : }
210 :
211 :
212 :
213 :
214 0 : SlideSorter::~SlideSorter (void)
215 : {
216 0 : mbIsValid = false;
217 :
218 0 : ReleaseListeners();
219 :
220 : // Dispose model, view and controller to avoid calls between them when
221 : // they are being destructed and one or two of them are already gone.
222 0 : mpSlideSorterController->Dispose();
223 0 : mpSlideSorterView->Dispose();
224 0 : mpSlideSorterModel->Dispose();
225 :
226 : // Reset the auto pointers explicitly to control the order of destruction.
227 0 : mpSlideSorterController.reset();
228 0 : mpSlideSorterView.reset();
229 0 : mpSlideSorterModel.reset();
230 :
231 0 : mpHorizontalScrollBar.reset();
232 0 : mpVerticalScrollBar.reset();
233 0 : mpScrollBarBox.reset();
234 :
235 0 : if (mbOwnesContentWindow)
236 : {
237 : OSL_ASSERT(mpContentWindow.unique());
238 : }
239 : else
240 : {
241 : // Assume that outside this class only the owner holds a reference
242 : // to the content window.
243 : OSL_ASSERT(mpContentWindow.use_count()==2);
244 : }
245 0 : mpContentWindow.reset();
246 0 : }
247 :
248 :
249 :
250 :
251 0 : bool SlideSorter::IsValid (void) const
252 : {
253 0 : return mbIsValid;
254 : }
255 :
256 :
257 :
258 :
259 0 : ::boost::shared_ptr<ScrollBar> SlideSorter::GetVerticalScrollBar (void) const
260 : {
261 0 : return mpVerticalScrollBar;
262 : }
263 :
264 :
265 :
266 :
267 :
268 0 : ::boost::shared_ptr<ScrollBar> SlideSorter::GetHorizontalScrollBar (void) const
269 : {
270 0 : return mpHorizontalScrollBar;
271 : }
272 :
273 :
274 :
275 :
276 0 : ::boost::shared_ptr<ScrollBarBox> SlideSorter::GetScrollBarFiller (void) const
277 : {
278 0 : return mpScrollBarBox;
279 : }
280 :
281 :
282 :
283 :
284 0 : model::SlideSorterModel& SlideSorter::GetModel (void) const
285 : {
286 : OSL_ASSERT(mpSlideSorterModel.get()!=NULL);
287 0 : return *mpSlideSorterModel;
288 : }
289 :
290 :
291 :
292 :
293 0 : view::SlideSorterView& SlideSorter::GetView (void) const
294 : {
295 : OSL_ASSERT(mpSlideSorterView.get()!=NULL);
296 0 : return *mpSlideSorterView;
297 : }
298 :
299 :
300 :
301 :
302 0 : controller::SlideSorterController& SlideSorter::GetController (void) const
303 : {
304 : OSL_ASSERT(mpSlideSorterController.get()!=NULL);
305 0 : return *mpSlideSorterController;
306 : }
307 :
308 :
309 :
310 :
311 0 : Reference<frame::XController> SlideSorter::GetXController (void) const
312 : {
313 0 : Reference<frame::XController> xController(mxControllerWeak);
314 0 : return xController;
315 : }
316 :
317 :
318 :
319 :
320 0 : void SlideSorter::Paint (const Rectangle& rRepaintArea)
321 : {
322 0 : GetController().Paint(
323 : rRepaintArea,
324 0 : GetContentWindow().get());
325 0 : }
326 :
327 :
328 :
329 :
330 0 : ::SharedSdWindow SlideSorter::GetContentWindow (void) const
331 : {
332 0 : return mpContentWindow;
333 : }
334 :
335 :
336 :
337 :
338 0 : ViewShellBase* SlideSorter::GetViewShellBase (void) const
339 : {
340 0 : return mpViewShellBase;
341 : }
342 :
343 :
344 :
345 :
346 0 : ViewShell* SlideSorter::GetViewShell (void) const
347 : {
348 0 : return mpViewShell;
349 : }
350 :
351 :
352 :
353 :
354 0 : void SlideSorter::SetupControls (::Window* )
355 : {
356 0 : GetVerticalScrollBar()->Show();
357 0 : mpSlideSorterController->GetScrollBarManager().LateInitialization();
358 0 : }
359 :
360 :
361 :
362 :
363 0 : void SlideSorter::SetupListeners (void)
364 : {
365 0 : SharedSdWindow pWindow (GetContentWindow());
366 0 : if (pWindow)
367 : {
368 0 : ::Window* pParentWindow = pWindow->GetParent();
369 0 : if (pParentWindow != NULL)
370 : pParentWindow->AddEventListener(
371 0 : LINK(
372 : mpSlideSorterController.get(),
373 : controller::SlideSorterController,
374 0 : WindowEventHandler));
375 0 : pWindow->AddEventListener(
376 0 : LINK(
377 : mpSlideSorterController.get(),
378 : controller::SlideSorterController,
379 0 : WindowEventHandler));
380 : }
381 : Application::AddEventListener(
382 0 : LINK(
383 : mpSlideSorterController.get(),
384 : controller::SlideSorterController,
385 0 : WindowEventHandler));
386 :
387 0 : mpSlideSorterController->GetScrollBarManager().Connect();
388 0 : }
389 :
390 :
391 :
392 :
393 0 : void SlideSorter::ReleaseListeners (void)
394 : {
395 0 : mpSlideSorterController->GetScrollBarManager().Disconnect();
396 :
397 0 : SharedSdWindow pWindow (GetContentWindow());
398 0 : if (pWindow)
399 : {
400 0 : pWindow->RemoveEventListener(
401 0 : LINK(mpSlideSorterController.get(),
402 : controller::SlideSorterController,
403 0 : WindowEventHandler));
404 :
405 0 : ::Window* pParentWindow = pWindow->GetParent();
406 0 : if (pParentWindow != NULL)
407 : pParentWindow->RemoveEventListener(
408 0 : LINK(mpSlideSorterController.get(),
409 : controller::SlideSorterController,
410 0 : WindowEventHandler));
411 : }
412 : Application::RemoveEventListener(
413 0 : LINK(mpSlideSorterController.get(),
414 : controller::SlideSorterController,
415 0 : WindowEventHandler));
416 0 : }
417 :
418 :
419 :
420 :
421 0 : void SlideSorter::CreateModelViewController (void)
422 : {
423 0 : mpSlideSorterModel.reset(CreateModel());
424 : DBG_ASSERT (mpSlideSorterModel.get()!=NULL,
425 : "Can not create model for slide browser");
426 :
427 0 : mpSlideSorterView.reset(CreateView());
428 : DBG_ASSERT (mpSlideSorterView.get()!=NULL,
429 : "Can not create view for slide browser");
430 :
431 0 : mpSlideSorterController.reset(CreateController());
432 : DBG_ASSERT (mpSlideSorterController.get()!=NULL,
433 : "Can not create controller for slide browser");
434 :
435 : // Now that model, view, and controller are constructed, do the
436 : // initialization that relies on all three being in place.
437 0 : mpSlideSorterModel->Init();
438 0 : mpSlideSorterController->Init();
439 0 : mpSlideSorterView->Init();
440 0 : }
441 :
442 :
443 :
444 :
445 0 : model::SlideSorterModel* SlideSorter::CreateModel (void)
446 : {
447 : // Get pointers to the document.
448 0 : ViewShellBase* pViewShellBase = GetViewShellBase();
449 0 : if (pViewShellBase != NULL)
450 : {
451 : OSL_ASSERT (pViewShellBase->GetDocument() != NULL);
452 :
453 0 : return new model::SlideSorterModel(*this);
454 : }
455 : else
456 0 : return NULL;
457 : }
458 :
459 :
460 :
461 :
462 0 : view::SlideSorterView* SlideSorter::CreateView (void)
463 : {
464 0 : return new view::SlideSorterView (*this);
465 : }
466 :
467 :
468 :
469 :
470 0 : controller::SlideSorterController* SlideSorter::CreateController (void)
471 : {
472 : controller::SlideSorterController* pController
473 0 : = new controller::SlideSorterController (*this);
474 0 : return pController;
475 : }
476 :
477 :
478 :
479 :
480 0 : void SlideSorter::ArrangeGUIElements (
481 : const Point& rOffset,
482 : const Size& rSize)
483 : {
484 0 : Point aOrigin (rOffset);
485 :
486 0 : if (rSize.Width()>0
487 0 : && rSize.Height()>0
488 0 : && GetContentWindow()
489 0 : && GetContentWindow()->IsVisible())
490 : {
491 : // Prevent untimely redraws while the view is not yet correctly
492 : // resized.
493 0 : view::SlideSorterView::DrawLock aLock (*this);
494 0 : GetContentWindow()->EnablePaint (sal_False);
495 :
496 0 : mpSlideSorterController->Resize (Rectangle(aOrigin, rSize));
497 :
498 0 : GetContentWindow()->EnablePaint (sal_True);
499 :
500 0 : mbLayoutPending = false;
501 : }
502 0 : }
503 :
504 :
505 :
506 :
507 0 : SvBorder SlideSorter::GetBorder (void)
508 : {
509 0 : SvBorder aBorder;
510 :
511 0 : ::boost::shared_ptr<ScrollBar> pScrollBar = GetVerticalScrollBar();
512 0 : if (pScrollBar.get() != NULL && pScrollBar->IsVisible())
513 0 : aBorder.Right() = pScrollBar->GetOutputSizePixel().Width();
514 :
515 0 : pScrollBar = GetHorizontalScrollBar();
516 0 : if (pScrollBar.get() != NULL && pScrollBar->IsVisible())
517 0 : aBorder.Bottom() = pScrollBar->GetOutputSizePixel().Height();
518 :
519 0 : return aBorder;
520 : }
521 :
522 :
523 :
524 :
525 0 : bool SlideSorter::RelocateToWindow (::Window* pParentWindow)
526 : {
527 : // Stop all animations for they have been started for the old window.
528 0 : mpSlideSorterController->GetAnimator()->RemoveAllAnimations();
529 :
530 0 : ReleaseListeners();
531 :
532 0 : if (mpViewShell != NULL)
533 0 : mpViewShell->ViewShell::RelocateToParentWindow(pParentWindow);
534 :
535 0 : SetupControls(mpViewShell->GetParentWindow());
536 0 : SetupListeners();
537 :
538 : // For accessibility we have to shortly hide the content window. This
539 : // triggers the construction of a new accessibility object for the new
540 : // view shell. (One is created earlier while the construtor of the base
541 : // class is executed. But because at that time the correct
542 : // accessibility object can not be constructed we do that now.)
543 0 : if (mpContentWindow.get() !=NULL)
544 : {
545 0 : mpContentWindow->Hide();
546 0 : mpContentWindow->Show();
547 : }
548 :
549 0 : return true;
550 : }
551 :
552 :
553 :
554 :
555 0 : void SlideSorter::SetCurrentFunction (const FunctionReference& rpFunction)
556 : {
557 0 : if (GetViewShell() != NULL)
558 : {
559 0 : GetViewShell()->SetCurrentFunction(rpFunction);
560 0 : GetViewShell()->SetOldFunction(rpFunction);
561 : }
562 : else
563 : {
564 0 : ContentWindow* pWindow = dynamic_cast<ContentWindow*>(GetContentWindow().get());
565 0 : if (pWindow != NULL)
566 0 : pWindow->SetCurrentFunction(rpFunction);
567 : }
568 0 : }
569 :
570 :
571 :
572 :
573 0 : ::boost::shared_ptr<controller::Properties> SlideSorter::GetProperties (void) const
574 : {
575 : OSL_ASSERT(mpProperties);
576 0 : return mpProperties;
577 : }
578 :
579 :
580 :
581 :
582 0 : ::boost::shared_ptr<view::Theme> SlideSorter::GetTheme (void) const
583 : {
584 : OSL_ASSERT(mpTheme);
585 0 : return mpTheme;
586 : }
587 :
588 :
589 :
590 :
591 : //===== ContentWindow =========================================================
592 :
593 : namespace {
594 :
595 0 : ContentWindow::ContentWindow(
596 : ::Window& rParent,
597 : SlideSorter& rSlideSorter)
598 : : ::sd::Window(&rParent),
599 : mrSlideSorter(rSlideSorter),
600 0 : mpCurrentFunction()
601 : {
602 0 : SetDialogControlFlags(GetDialogControlFlags() & ~WINDOW_DLGCTRL_WANTFOCUS);
603 0 : SetStyle(GetStyle() | WB_NOPOINTERFOCUS);
604 0 : }
605 :
606 :
607 :
608 :
609 0 : ContentWindow::~ContentWindow (void)
610 : {
611 0 : }
612 :
613 :
614 :
615 :
616 0 : void ContentWindow::SetCurrentFunction (const FunctionReference& rpFunction)
617 : {
618 0 : mpCurrentFunction = rpFunction;
619 0 : }
620 :
621 :
622 :
623 :
624 0 : void ContentWindow::Paint (const Rectangle& rRect)
625 : {
626 0 : mrSlideSorter.Paint(rRect);
627 0 : }
628 :
629 :
630 :
631 :
632 0 : void ContentWindow::KeyInput (const KeyEvent& rEvent)
633 : {
634 0 : if (mpCurrentFunction.is())
635 0 : mpCurrentFunction->KeyInput(rEvent);
636 0 : }
637 :
638 :
639 :
640 :
641 0 : void ContentWindow::MouseMove (const MouseEvent& rEvent)
642 : {
643 0 : if (mpCurrentFunction.is())
644 0 : mpCurrentFunction->MouseMove(rEvent);
645 0 : }
646 :
647 :
648 :
649 :
650 0 : void ContentWindow::MouseButtonUp(const MouseEvent& rEvent)
651 : {
652 0 : if (mpCurrentFunction.is())
653 0 : mpCurrentFunction->MouseButtonUp(rEvent);
654 0 : }
655 :
656 :
657 :
658 :
659 0 : void ContentWindow::MouseButtonDown(const MouseEvent& rEvent)
660 : {
661 0 : if (mpCurrentFunction.is())
662 0 : mpCurrentFunction->MouseButtonDown(rEvent);
663 0 : }
664 :
665 :
666 :
667 :
668 0 : void ContentWindow::Command(const CommandEvent& rEvent)
669 : {
670 0 : if (mpCurrentFunction.is())
671 0 : mpCurrentFunction->Command(rEvent);
672 0 : }
673 :
674 :
675 :
676 :
677 0 : long ContentWindow::Notify (NotifyEvent& rEvent)
678 : {
679 : (void)rEvent;
680 0 : return 0;
681 : }
682 :
683 :
684 :
685 : } // end of anonymous namespace
686 :
687 :
688 :
689 :
690 :
691 : } } // end of namespace ::sd::slidesorter
692 :
693 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|