merge the formfield patch from ooo-build
[ooovba.git] / sd / source / ui / slidesorter / shell / SlideSorter.cxx
blob4d0280e433b583b42f9539efd8cb24d31e2ee963
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: SlideSorter.cxx,v $
10 * $Revision: 1.6 $
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"
42 #include "glob.hrc"
43 #include "DrawController.hxx"
44 #include "ViewShellBase.hxx"
45 #include "ViewShellManager.hxx"
46 #include "Window.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 {
60 namespace {
61 class ContentWindow : public ::sd::Window
63 public:
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);
75 private:
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(
94 new SlideSorter(
95 rViewShell,
96 rpContentWindow,
97 rpHorizontalScrollBar,
98 rpVerticalScrollBar,
99 rpScrollBarBox));
100 pSlideSorter->Init();
101 return pSlideSorter;
107 ::boost::shared_ptr<SlideSorter> SlideSorter::CreateSlideSorter (
108 ViewShellBase& rBase,
109 ViewShell* pViewShell,
110 ::Window& rParentWindow)
112 ::boost::shared_ptr<SlideSorter> pSlideSorter(
113 new SlideSorter(
114 rBase,
115 pViewShell,
116 rParentWindow));
117 pSlideSorter->Init();
118 return pSlideSorter;
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)
130 : mbIsValid(false),
131 mpSlideSorterController(),
132 mpSlideSorterModel(),
133 mpSlideSorterView(),
134 mxControllerWeak(),
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)
152 : mbIsValid(false),
153 mpSlideSorterController(),
154 mpSlideSorterModel(),
155 mpSlideSorterView(),
156 mxControllerWeak(),
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 ();
177 SetupListeners ();
179 // Initialize the window.
180 ::sd::Window* pWindow = GetActiveWindow();
181 if (pWindow != NULL)
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);
192 pWindow->Hide();
194 // Set view pointer of base class.
195 SetupControls(pParentWindow);
197 mbIsValid = true;
204 SlideSorter::~SlideSorter (void)
206 mbIsValid = false;
208 ReleaseListeners();
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
226 return mbIsValid;
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);
287 return xController;
293 void SlideSorter::Paint (const Rectangle& rRepaintArea)
295 GetController().Paint(
296 rRepaintArea,
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();
315 else
316 return mpContentWindow.get();
322 ViewShellBase* SlideSorter::GetViewShellBase (void) const
324 return mpViewShellBase;
330 ViewShell* SlideSorter::GetViewShell (void) const
332 return mpViewShell;
338 void SlideSorter::SetupControls (::Window* )
340 GetVerticalScrollBar()->Show();
341 mpSlideSorterController->GetScrollBarManager().LateInitialization();
347 void SlideSorter::SetupListeners (void)
349 ::sd::Window* pWindow = GetActiveWindow();
350 if (pWindow != NULL)
352 ::Window* pParentWindow = pWindow->GetParent();
353 if (pParentWindow != NULL)
354 pParentWindow->AddEventListener(
355 LINK(
356 mpSlideSorterController.get(),
357 controller::SlideSorterController,
358 WindowEventHandler));
359 pWindow->AddEventListener(
360 LINK(
361 mpSlideSorterController.get(),
362 controller::SlideSorterController,
363 WindowEventHandler));
365 Application::AddEventListener(
366 LINK(
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();
382 if (pWindow != NULL)
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);
435 else
436 return NULL;
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);
454 return pController;
460 void SlideSorter::ArrangeGUIElements (
461 const Point& rOffset,
462 const Size& rSize)
464 Point aOrigin (rOffset);
466 if (rSize.Width()!=0 && rSize.Height()!=0)
468 // Prevent untimely redraws while the view is not yet correctly
469 // resized.
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);
483 else
485 // maAllWindowRectangle = Rectangle();
492 SvBorder SlideSorter::GetBorder (void)
494 SvBorder aBorder;
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();
504 return aBorder;
510 bool SlideSorter::RelocateToWindow (::Window* pParentWindow)
512 ReleaseListeners();
514 if (mpViewShell != NULL)
515 mpViewShell->ViewShell::RelocateToParentWindow(pParentWindow);
517 SetupControls(mpViewShell->GetParentWindow());
518 SetupListeners();
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();
531 return true;
537 void SlideSorter::SetCurrentFunction (const FunctionReference& rpFunction)
539 if (GetViewShell() != NULL)
541 GetViewShell()->SetCurrentFunction(rpFunction);
542 GetViewShell()->SetOldFunction(rpFunction);
544 else
546 ::boost::shared_ptr<ContentWindow> pWindow
547 = ::boost::dynamic_pointer_cast<ContentWindow>(GetContentWindow());
548 if (pWindow.get() != NULL)
549 pWindow->SetCurrentFunction(rpFunction);
556 //===== ContentWindow =========================================================
558 namespace {
560 ContentWindow::ContentWindow(
561 ::Window& rParent,
562 SlideSorter& rSlideSorter)
563 : ::sd::Window(&rParent),
564 mrSlideSorter(rSlideSorter),
565 mpCurrentFunction()
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)
644 (void)rEvent;
645 return 0;
651 } // end of anonymous namespace
654 } } // end of namespace ::sd::slidesorter