1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: SlideSorter.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 #include "precompiled_sd.hxx"
33 #include "SlideSorter.hxx"
35 #include "SlideSorterChildWindow.hrc"
36 #include "SlideSorterViewShell.hxx"
37 #include "controller/SlideSorterController.hxx"
38 #include "controller/SlsScrollBarManager.hxx"
39 #include "view/SlideSorterView.hxx"
40 #include "model/SlideSorterModel.hxx"
43 #include "DrawController.hxx"
44 #include "ViewShellBase.hxx"
45 #include "ViewShellManager.hxx"
48 #include <vcl/scrbar.hxx>
49 #include <vcl/svapp.hxx>
51 #include <sfx2/dispatch.hxx>
52 #include "sdresid.hxx"
54 using namespace ::com::sun::star::uno
;
55 using namespace ::com::sun::star
;
58 namespace sd
{ namespace slidesorter
{
61 class ContentWindow
: public ::sd::Window
64 ContentWindow(::Window
& rParent
, SlideSorter
& rSlideSorter
);
65 ~ContentWindow (void);
66 void SetCurrentFunction (const FunctionReference
& rpFunction
);
67 virtual void Paint(const Rectangle
& rRect
);
68 virtual void KeyInput (const KeyEvent
& rEvent
);
69 virtual void MouseMove (const MouseEvent
& rEvent
);
70 virtual void MouseButtonUp (const MouseEvent
& rEvent
);
71 virtual void MouseButtonDown (const MouseEvent
& rEvent
);
72 virtual void Command (const CommandEvent
& rEvent
);
73 virtual long Notify (NotifyEvent
& rEvent
);
76 SlideSorter
& mrSlideSorter
;
77 FunctionReference mpCurrentFunction
;
84 //===== SlideSorter ===========================================================
86 ::boost::shared_ptr
<SlideSorter
> SlideSorter::CreateSlideSorter(
87 ViewShell
& rViewShell
,
88 const ::boost::shared_ptr
<sd::Window
>& rpContentWindow
,
89 const ::boost::shared_ptr
<ScrollBar
>& rpHorizontalScrollBar
,
90 const ::boost::shared_ptr
<ScrollBar
>& rpVerticalScrollBar
,
91 const ::boost::shared_ptr
<ScrollBarBox
>& rpScrollBarBox
)
93 ::boost::shared_ptr
<SlideSorter
> pSlideSorter(
97 rpHorizontalScrollBar
,
100 pSlideSorter
->Init();
107 ::boost::shared_ptr
<SlideSorter
> SlideSorter::CreateSlideSorter (
108 ViewShellBase
& rBase
,
109 ViewShell
* pViewShell
,
110 ::Window
& rParentWindow
)
112 ::boost::shared_ptr
<SlideSorter
> pSlideSorter(
117 pSlideSorter
->Init();
124 SlideSorter::SlideSorter (
125 ViewShell
& rViewShell
,
126 const ::boost::shared_ptr
<sd::Window
>& rpContentWindow
,
127 const ::boost::shared_ptr
<ScrollBar
>& rpHorizontalScrollBar
,
128 const ::boost::shared_ptr
<ScrollBar
>& rpVerticalScrollBar
,
129 const ::boost::shared_ptr
<ScrollBarBox
>& rpScrollBarBox
)
131 mpSlideSorterController(),
132 mpSlideSorterModel(),
135 mpViewShell(&rViewShell
),
136 mpViewShellBase(&rViewShell
.GetViewShellBase()),
137 mpContentWindow(rpContentWindow
),
138 mpHorizontalScrollBar(rpHorizontalScrollBar
),
139 mpVerticalScrollBar(rpVerticalScrollBar
),
140 mpScrollBarBox(rpScrollBarBox
),
141 mbLayoutPending(true)
148 SlideSorter::SlideSorter (
149 ViewShellBase
& rBase
,
150 ViewShell
* pViewShell
,
151 ::Window
& rParentWindow
)
153 mpSlideSorterController(),
154 mpSlideSorterModel(),
157 mpViewShell(pViewShell
),
158 mpViewShellBase(&rBase
),
159 mpContentWindow(new ContentWindow(rParentWindow
,*this )),
160 mpHorizontalScrollBar(new ScrollBar(&rParentWindow
,WinBits(WB_HSCROLL
| WB_DRAG
))),
161 mpVerticalScrollBar(new ScrollBar(&rParentWindow
,WinBits(WB_VSCROLL
| WB_DRAG
))),
162 mpScrollBarBox(new ScrollBarBox(&rParentWindow
)),
163 mbLayoutPending(true)
170 void SlideSorter::Init (void)
172 if (mpViewShellBase
!= NULL
)
173 mxControllerWeak
= mpViewShellBase
->GetController();
175 CreateModelViewController ();
179 // Initialize the window.
180 ::sd::Window
* pWindow
= GetActiveWindow();
183 ::Window
* pParentWindow
= pWindow
->GetParent();
184 if (pParentWindow
!= NULL
)
185 pParentWindow
->SetBackground(Wallpaper());
186 pWindow
->SetBackground(Wallpaper());
187 pWindow
->SetViewOrigin (Point(0,0));
188 // We do our own scrolling while dragging a page selection.
189 pWindow
->SetUseDropScroll (false);
190 // Change the winbits so that the active window accepts the focus.
191 pWindow
->SetStyle ((pWindow
->GetStyle() & ~WB_DIALOGCONTROL
) | WB_TABSTOP
);
194 // Set view pointer of base class.
195 SetupControls(pParentWindow
);
204 SlideSorter::~SlideSorter (void)
210 // Reset the auto pointers explicitly to control the order of destruction.
211 mpSlideSorterController
.reset();
212 mpSlideSorterView
.reset();
213 mpSlideSorterModel
.reset();
215 mpHorizontalScrollBar
.reset();
216 mpVerticalScrollBar
.reset();
217 mpScrollBarBox
.reset();
218 mpContentWindow
.reset();
224 bool SlideSorter::IsValid (void) const
232 ::boost::shared_ptr
<ScrollBar
> SlideSorter::GetVerticalScrollBar (void) const
234 return mpVerticalScrollBar
;
241 ::boost::shared_ptr
<ScrollBar
> SlideSorter::GetHorizontalScrollBar (void) const
243 return mpHorizontalScrollBar
;
249 ::boost::shared_ptr
<ScrollBarBox
> SlideSorter::GetScrollBarFiller (void) const
251 return mpScrollBarBox
;
257 model::SlideSorterModel
& SlideSorter::GetModel (void) const
259 OSL_ASSERT(mpSlideSorterModel
.get()!=NULL
);
260 return *mpSlideSorterModel
;
266 view::SlideSorterView
& SlideSorter::GetView (void) const
268 OSL_ASSERT(mpSlideSorterView
.get()!=NULL
);
269 return *mpSlideSorterView
;
275 controller::SlideSorterController
& SlideSorter::GetController (void) const
277 OSL_ASSERT(mpSlideSorterController
.get()!=NULL
);
278 return *mpSlideSorterController
;
284 Reference
<frame::XController
> SlideSorter::GetXController (void) const
286 Reference
<frame::XController
> xController(mxControllerWeak
);
293 void SlideSorter::Paint (const Rectangle
& rRepaintArea
)
295 GetController().Paint(
297 GetContentWindow().get());
303 ::boost::shared_ptr
<sd::Window
> SlideSorter::GetContentWindow (void) const
305 return mpContentWindow
;
311 ::sd::Window
* SlideSorter::GetActiveWindow (void) const
313 if (mpViewShell
!= NULL
)
314 return mpViewShell
->GetActiveWindow();
316 return mpContentWindow
.get();
322 ViewShellBase
* SlideSorter::GetViewShellBase (void) const
324 return mpViewShellBase
;
330 ViewShell
* SlideSorter::GetViewShell (void) const
338 void SlideSorter::SetupControls (::Window
* )
340 GetVerticalScrollBar()->Show();
341 mpSlideSorterController
->GetScrollBarManager().LateInitialization();
347 void SlideSorter::SetupListeners (void)
349 ::sd::Window
* pWindow
= GetActiveWindow();
352 ::Window
* pParentWindow
= pWindow
->GetParent();
353 if (pParentWindow
!= NULL
)
354 pParentWindow
->AddEventListener(
356 mpSlideSorterController
.get(),
357 controller::SlideSorterController
,
358 WindowEventHandler
));
359 pWindow
->AddEventListener(
361 mpSlideSorterController
.get(),
362 controller::SlideSorterController
,
363 WindowEventHandler
));
365 Application::AddEventListener(
367 mpSlideSorterController
.get(),
368 controller::SlideSorterController
,
369 WindowEventHandler
));
371 mpSlideSorterController
->GetScrollBarManager().Connect();
377 void SlideSorter::ReleaseListeners (void)
379 mpSlideSorterController
->GetScrollBarManager().Disconnect();
381 ::sd::Window
* pWindow
= GetActiveWindow();
385 pWindow
->RemoveEventListener(
386 LINK(mpSlideSorterController
.get(),
387 controller::SlideSorterController
,
388 WindowEventHandler
));
390 ::Window
* pParentWindow
= pWindow
->GetParent();
391 if (pParentWindow
!= NULL
)
392 pParentWindow
->RemoveEventListener(
393 LINK(mpSlideSorterController
.get(),
394 controller::SlideSorterController
,
395 WindowEventHandler
));
397 Application::RemoveEventListener(
398 LINK(mpSlideSorterController
.get(),
399 controller::SlideSorterController
,
400 WindowEventHandler
));
406 void SlideSorter::CreateModelViewController (void)
408 mpSlideSorterModel
.reset(CreateModel());
409 DBG_ASSERT (mpSlideSorterModel
.get()!=NULL
,
410 "Can not create model for slide browser");
412 mpSlideSorterView
.reset(CreateView());
413 DBG_ASSERT (mpSlideSorterView
.get()!=NULL
,
414 "Can not create view for slide browser");
416 mpSlideSorterController
.reset(CreateController());
417 DBG_ASSERT (mpSlideSorterController
.get()!=NULL
,
418 "Can not create controller for slide browser");
419 mpSlideSorterController
->Init();
425 model::SlideSorterModel
* SlideSorter::CreateModel (void)
427 // Get pointers to the document.
428 ViewShellBase
* pViewShellBase
= GetViewShellBase();
429 if (pViewShellBase
!= NULL
)
431 OSL_ASSERT (pViewShellBase
->GetDocument() != NULL
);
433 return new model::SlideSorterModel(*this);
442 view::SlideSorterView
* SlideSorter::CreateView (void)
444 return new view::SlideSorterView (*this);
450 controller::SlideSorterController
* SlideSorter::CreateController (void)
452 controller::SlideSorterController
* pController
453 = new controller::SlideSorterController (*this);
460 void SlideSorter::ArrangeGUIElements (
461 const Point
& rOffset
,
464 Point
aOrigin (rOffset
);
466 if (rSize
.Width()!=0 && rSize
.Height()!=0)
468 // Prevent untimely redraws while the view is not yet correctly
470 mpSlideSorterView
->LockRedraw (TRUE
);
471 if (GetActiveWindow() != NULL
)
472 GetActiveWindow()->EnablePaint (FALSE
);
474 // maAllWindowRectangle =
475 mpSlideSorterController
->Resize (Rectangle(aOrigin
, rSize
));
477 if (GetActiveWindow() != NULL
)
478 GetActiveWindow()->EnablePaint (TRUE
);
480 mbLayoutPending
= false;
481 mpSlideSorterView
->LockRedraw (FALSE
);
485 // maAllWindowRectangle = Rectangle();
492 SvBorder
SlideSorter::GetBorder (void)
496 ::boost::shared_ptr
<ScrollBar
> pScrollBar
= GetVerticalScrollBar();
497 if (pScrollBar
.get() != NULL
&& pScrollBar
->IsVisible())
498 aBorder
.Right() = pScrollBar
->GetOutputSizePixel().Width();
500 pScrollBar
= GetHorizontalScrollBar();
501 if (pScrollBar
.get() != NULL
&& pScrollBar
->IsVisible())
502 aBorder
.Bottom() = pScrollBar
->GetOutputSizePixel().Height();
510 bool SlideSorter::RelocateToWindow (::Window
* pParentWindow
)
514 if (mpViewShell
!= NULL
)
515 mpViewShell
->ViewShell::RelocateToParentWindow(pParentWindow
);
517 SetupControls(mpViewShell
->GetParentWindow());
520 // For accessibility we have to shortly hide the content window. This
521 // triggers the construction of a new accessibility object for the new
522 // view shell. (One is created earlier while the construtor of the base
523 // class is executed. At that time the correct accessibility object can
524 // not be constructed.)
525 if (mpContentWindow
.get() !=NULL
)
527 mpContentWindow
->Hide();
528 mpContentWindow
->Show();
537 void SlideSorter::SetCurrentFunction (const FunctionReference
& rpFunction
)
539 if (GetViewShell() != NULL
)
541 GetViewShell()->SetCurrentFunction(rpFunction
);
542 GetViewShell()->SetOldFunction(rpFunction
);
546 ::boost::shared_ptr
<ContentWindow
> pWindow
547 = ::boost::dynamic_pointer_cast
<ContentWindow
>(GetContentWindow());
548 if (pWindow
.get() != NULL
)
549 pWindow
->SetCurrentFunction(rpFunction
);
556 //===== ContentWindow =========================================================
560 ContentWindow::ContentWindow(
562 SlideSorter
& rSlideSorter
)
563 : ::sd::Window(&rParent
),
564 mrSlideSorter(rSlideSorter
),
567 SetDialogControlFlags(GetDialogControlFlags() & ~WINDOW_DLGCTRL_WANTFOCUS
);
568 SetStyle(GetStyle() | WB_NOPOINTERFOCUS
);
574 ContentWindow::~ContentWindow (void)
581 void ContentWindow::SetCurrentFunction (const FunctionReference
& rpFunction
)
583 mpCurrentFunction
= rpFunction
;
589 void ContentWindow::Paint (const Rectangle
& rRect
)
591 mrSlideSorter
.Paint(rRect
);
597 void ContentWindow::KeyInput (const KeyEvent
& rEvent
)
599 if (mpCurrentFunction
.is())
600 mpCurrentFunction
->KeyInput(rEvent
);
606 void ContentWindow::MouseMove (const MouseEvent
& rEvent
)
608 if (mpCurrentFunction
.is())
609 mpCurrentFunction
->MouseMove(rEvent
);
615 void ContentWindow::MouseButtonUp(const MouseEvent
& rEvent
)
617 if (mpCurrentFunction
.is())
618 mpCurrentFunction
->MouseButtonUp(rEvent
);
624 void ContentWindow::MouseButtonDown(const MouseEvent
& rEvent
)
626 if (mpCurrentFunction
.is())
627 mpCurrentFunction
->MouseButtonDown(rEvent
);
633 void ContentWindow::Command(const CommandEvent
& rEvent
)
635 if (mpCurrentFunction
.is())
636 mpCurrentFunction
->Command(rEvent
);
642 long ContentWindow::Notify (NotifyEvent
& rEvent
)
651 } // end of anonymous namespace
654 } } // end of namespace ::sd::slidesorter