xref: /AOO41X/main/sdext/source/presenter/PresenterScrollBar.cxx (revision c142477ce2bdb32de904d9995ebf0add7aef9609)
1*c142477cSAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*c142477cSAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*c142477cSAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*c142477cSAndrew Rist  * distributed with this work for additional information
6*c142477cSAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*c142477cSAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*c142477cSAndrew Rist  * "License"); you may not use this file except in compliance
9*c142477cSAndrew Rist  * with the License.  You may obtain a copy of the License at
10cdf0e10cSrcweir  *
11*c142477cSAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12cdf0e10cSrcweir  *
13*c142477cSAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*c142477cSAndrew Rist  * software distributed under the License is distributed on an
15*c142477cSAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*c142477cSAndrew Rist  * KIND, either express or implied.  See the License for the
17*c142477cSAndrew Rist  * specific language governing permissions and limitations
18*c142477cSAndrew Rist  * under the License.
19cdf0e10cSrcweir  *
20*c142477cSAndrew Rist  *************************************************************/
21*c142477cSAndrew Rist 
22*c142477cSAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_sdext.hxx"
26cdf0e10cSrcweir 
27cdf0e10cSrcweir #include "PresenterScrollBar.hxx"
28cdf0e10cSrcweir #include "PresenterBitmapContainer.hxx"
29cdf0e10cSrcweir #include "PresenterCanvasHelper.hxx"
30cdf0e10cSrcweir #include "PresenterComponent.hxx"
31cdf0e10cSrcweir #include "PresenterGeometryHelper.hxx"
32cdf0e10cSrcweir #include "PresenterPaintManager.hxx"
33cdf0e10cSrcweir #include "PresenterTimer.hxx"
34cdf0e10cSrcweir #include "PresenterUIPainter.hxx"
35cdf0e10cSrcweir #include <com/sun/star/awt/PosSize.hpp>
36cdf0e10cSrcweir #include <com/sun/star/awt/WindowAttribute.hpp>
37cdf0e10cSrcweir #include <com/sun/star/awt/XWindowPeer.hpp>
38cdf0e10cSrcweir #include <com/sun/star/awt/XToolkit.hpp>
39cdf0e10cSrcweir #include <com/sun/star/rendering/CompositeOperation.hpp>
40cdf0e10cSrcweir #include <com/sun/star/rendering/TexturingMode.hpp>
41cdf0e10cSrcweir #include <com/sun/star/rendering/XPolyPolygon2D.hpp>
42cdf0e10cSrcweir #include <boost/bind.hpp>
43cdf0e10cSrcweir #include <boost/enable_shared_from_this.hpp>
44cdf0e10cSrcweir #include <boost/weak_ptr.hpp>
45cdf0e10cSrcweir #include <math.h>
46cdf0e10cSrcweir 
47cdf0e10cSrcweir using namespace ::com::sun::star;
48cdf0e10cSrcweir using namespace ::com::sun::star::uno;
49cdf0e10cSrcweir using ::rtl::OUString;
50cdf0e10cSrcweir 
51cdf0e10cSrcweir #define A2S(pString) (::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(pString)))
52cdf0e10cSrcweir 
53cdf0e10cSrcweir const static double gnScrollBarGap (10);
54cdf0e10cSrcweir 
55cdf0e10cSrcweir namespace sdext { namespace presenter {
56cdf0e10cSrcweir 
57cdf0e10cSrcweir //===== PresenterScrollBar::MousePressRepeater ================================
58cdf0e10cSrcweir 
59cdf0e10cSrcweir class PresenterScrollBar::MousePressRepeater
60cdf0e10cSrcweir     : public ::boost::enable_shared_from_this<MousePressRepeater>
61cdf0e10cSrcweir {
62cdf0e10cSrcweir public:
63cdf0e10cSrcweir     MousePressRepeater (const ::rtl::Reference<PresenterScrollBar>& rpScrollBar);
64cdf0e10cSrcweir     void Dispose (void);
65cdf0e10cSrcweir     void Start (const PresenterScrollBar::Area& reArea);
66cdf0e10cSrcweir     void Stop (void);
67cdf0e10cSrcweir     void SetMouseArea (const PresenterScrollBar::Area& reArea);
68cdf0e10cSrcweir 
69cdf0e10cSrcweir private:
70cdf0e10cSrcweir     void Callback (const TimeValue& rCurrentTime);
71cdf0e10cSrcweir     void Execute (void);
72cdf0e10cSrcweir 
73cdf0e10cSrcweir     sal_Int32 mnMousePressRepeaterTaskId;
74cdf0e10cSrcweir     ::rtl::Reference<PresenterScrollBar> mpScrollBar;
75cdf0e10cSrcweir     PresenterScrollBar::Area meMouseArea;
76cdf0e10cSrcweir };
77cdf0e10cSrcweir 
78cdf0e10cSrcweir 
79cdf0e10cSrcweir 
80cdf0e10cSrcweir 
81cdf0e10cSrcweir //===== PresenterScrollBar ====================================================
82cdf0e10cSrcweir 
83cdf0e10cSrcweir boost::weak_ptr<PresenterBitmapContainer> PresenterScrollBar::mpSharedBitmaps;
84cdf0e10cSrcweir 
85cdf0e10cSrcweir PresenterScrollBar::PresenterScrollBar (
86cdf0e10cSrcweir     const Reference<XComponentContext>& rxComponentContext,
87cdf0e10cSrcweir     const Reference<awt::XWindow>& rxParentWindow,
88cdf0e10cSrcweir     const ::boost::shared_ptr<PresenterPaintManager>& rpPaintManager,
89cdf0e10cSrcweir     const ::boost::function<void(double)>& rThumbMotionListener)
90cdf0e10cSrcweir     : PresenterScrollBarInterfaceBase(m_aMutex),
91cdf0e10cSrcweir       mxComponentContext(rxComponentContext),
92cdf0e10cSrcweir       mxParentWindow(rxParentWindow),
93cdf0e10cSrcweir       mxWindow(),
94cdf0e10cSrcweir       mxCanvas(),
95cdf0e10cSrcweir       mxPresenterHelper(),
96cdf0e10cSrcweir       mpPaintManager(rpPaintManager),
97cdf0e10cSrcweir       mnThumbPosition(0),
98cdf0e10cSrcweir       mnTotalSize(0),
99cdf0e10cSrcweir       mnThumbSize(0),
100cdf0e10cSrcweir       mnLineHeight(10),
101cdf0e10cSrcweir       maDragAnchor(-1,-1),
102cdf0e10cSrcweir       maThumbMotionListener(rThumbMotionListener),
103cdf0e10cSrcweir       meButtonDownArea(None),
104cdf0e10cSrcweir       meMouseMoveArea(None),
105cdf0e10cSrcweir       mbIsNotificationActive(false),
106cdf0e10cSrcweir       mpBitmaps(),
107cdf0e10cSrcweir       mpPrevButtonDescriptor(),
108cdf0e10cSrcweir       mpNextButtonDescriptor(),
109cdf0e10cSrcweir       mpPagerStartDescriptor(),
110cdf0e10cSrcweir       mpPagerCenterDescriptor(),
111cdf0e10cSrcweir       mpPagerEndDescriptor(),
112cdf0e10cSrcweir       mpThumbStartDescriptor(),
113cdf0e10cSrcweir       mpThumbCenterDescriptor(),
114cdf0e10cSrcweir       mpThumbEndDescriptor(),
115cdf0e10cSrcweir       mpMousePressRepeater(new MousePressRepeater(this)),
116cdf0e10cSrcweir       mpBackgroundBitmap(),
117cdf0e10cSrcweir       mpCanvasHelper(new PresenterCanvasHelper())
118cdf0e10cSrcweir {
119cdf0e10cSrcweir     try
120cdf0e10cSrcweir     {
121cdf0e10cSrcweir         Reference<lang::XMultiComponentFactory> xFactory (rxComponentContext->getServiceManager());
122cdf0e10cSrcweir         if ( ! xFactory.is())
123cdf0e10cSrcweir             throw RuntimeException();
124cdf0e10cSrcweir 
125cdf0e10cSrcweir         mxPresenterHelper = Reference<drawing::XPresenterHelper>(
126cdf0e10cSrcweir             xFactory->createInstanceWithContext(
127cdf0e10cSrcweir                 OUString::createFromAscii("com.sun.star.comp.Draw.PresenterHelper"),
128cdf0e10cSrcweir                 rxComponentContext),
129cdf0e10cSrcweir             UNO_QUERY_THROW);
130cdf0e10cSrcweir 
131cdf0e10cSrcweir         if (mxPresenterHelper.is())
132cdf0e10cSrcweir             mxWindow = mxPresenterHelper->createWindow(rxParentWindow,
133cdf0e10cSrcweir                 sal_False,
134cdf0e10cSrcweir                 sal_False,
135cdf0e10cSrcweir                 sal_False,
136cdf0e10cSrcweir                 sal_False);
137cdf0e10cSrcweir 
138cdf0e10cSrcweir         // Make the background transparent.  The slide show paints its own background.
139cdf0e10cSrcweir         Reference<awt::XWindowPeer> xPeer (mxWindow, UNO_QUERY_THROW);
140cdf0e10cSrcweir         if (xPeer.is())
141cdf0e10cSrcweir         {
142cdf0e10cSrcweir             xPeer->setBackground(0xff000000);
143cdf0e10cSrcweir         }
144cdf0e10cSrcweir 
145cdf0e10cSrcweir         mxWindow->setVisible(sal_True);
146cdf0e10cSrcweir         mxWindow->addWindowListener(this);
147cdf0e10cSrcweir         mxWindow->addPaintListener(this);
148cdf0e10cSrcweir         mxWindow->addMouseListener(this);
149cdf0e10cSrcweir         mxWindow->addMouseMotionListener(this);
150cdf0e10cSrcweir     }
151cdf0e10cSrcweir     catch (RuntimeException&)
152cdf0e10cSrcweir     {
153cdf0e10cSrcweir     }
154cdf0e10cSrcweir }
155cdf0e10cSrcweir 
156cdf0e10cSrcweir 
157cdf0e10cSrcweir 
158cdf0e10cSrcweir 
159cdf0e10cSrcweir PresenterScrollBar::~PresenterScrollBar (void)
160cdf0e10cSrcweir {
161cdf0e10cSrcweir }
162cdf0e10cSrcweir 
163cdf0e10cSrcweir 
164cdf0e10cSrcweir 
165cdf0e10cSrcweir 
166cdf0e10cSrcweir void SAL_CALL PresenterScrollBar::disposing (void)
167cdf0e10cSrcweir {
168cdf0e10cSrcweir     mpMousePressRepeater->Dispose();
169cdf0e10cSrcweir 
170cdf0e10cSrcweir     if (mxWindow.is())
171cdf0e10cSrcweir     {
172cdf0e10cSrcweir         mxWindow->removeWindowListener(this);
173cdf0e10cSrcweir         mxWindow->removePaintListener(this);
174cdf0e10cSrcweir         mxWindow->removeMouseListener(this);
175cdf0e10cSrcweir         mxWindow->removeMouseMotionListener(this);
176cdf0e10cSrcweir 
177cdf0e10cSrcweir         Reference<lang::XComponent> xComponent (mxWindow, UNO_QUERY);
178cdf0e10cSrcweir         mxWindow = NULL;
179cdf0e10cSrcweir         if (xComponent.is())
180cdf0e10cSrcweir             xComponent->dispose();
181cdf0e10cSrcweir     }
182cdf0e10cSrcweir 
183cdf0e10cSrcweir     mpBitmaps.reset();
184cdf0e10cSrcweir }
185cdf0e10cSrcweir 
186cdf0e10cSrcweir 
187cdf0e10cSrcweir 
188cdf0e10cSrcweir 
189cdf0e10cSrcweir void PresenterScrollBar::SetVisible (const bool bIsVisible)
190cdf0e10cSrcweir {
191cdf0e10cSrcweir     if (mxWindow.is())
192cdf0e10cSrcweir         mxWindow->setVisible(bIsVisible);
193cdf0e10cSrcweir }
194cdf0e10cSrcweir 
195cdf0e10cSrcweir 
196cdf0e10cSrcweir 
197cdf0e10cSrcweir 
198cdf0e10cSrcweir void PresenterScrollBar::SetPosSize (const css::geometry::RealRectangle2D& rBox)
199cdf0e10cSrcweir {
200cdf0e10cSrcweir     if (mxWindow.is())
201cdf0e10cSrcweir     {
202cdf0e10cSrcweir         mxWindow->setPosSize(
203cdf0e10cSrcweir             sal_Int32(floor(rBox.X1)),
204cdf0e10cSrcweir             sal_Int32(ceil(rBox.Y1)),
205cdf0e10cSrcweir             sal_Int32(ceil(rBox.X2-rBox.X1)),
206cdf0e10cSrcweir             sal_Int32(floor(rBox.Y2-rBox.Y1)),
207cdf0e10cSrcweir             awt::PosSize::POSSIZE);
208cdf0e10cSrcweir         UpdateBorders();
209cdf0e10cSrcweir     }
210cdf0e10cSrcweir }
211cdf0e10cSrcweir 
212cdf0e10cSrcweir 
213cdf0e10cSrcweir 
214cdf0e10cSrcweir 
215cdf0e10cSrcweir void PresenterScrollBar::SetThumbPosition (
216cdf0e10cSrcweir     double nPosition,
217cdf0e10cSrcweir     const bool bAsynchronousUpdate)
218cdf0e10cSrcweir {
219cdf0e10cSrcweir     SetThumbPosition(nPosition, bAsynchronousUpdate, true, true);
220cdf0e10cSrcweir }
221cdf0e10cSrcweir 
222cdf0e10cSrcweir 
223cdf0e10cSrcweir 
224cdf0e10cSrcweir 
225cdf0e10cSrcweir void PresenterScrollBar::SetThumbPosition (
226cdf0e10cSrcweir     double nPosition,
227cdf0e10cSrcweir     const bool bAsynchronousUpdate,
228cdf0e10cSrcweir     const bool bValidate,
229cdf0e10cSrcweir     const bool bNotify)
230cdf0e10cSrcweir {
231cdf0e10cSrcweir     if (bValidate)
232cdf0e10cSrcweir         nPosition = ValidateThumbPosition(nPosition);
233cdf0e10cSrcweir 
234cdf0e10cSrcweir     if (nPosition != mnThumbPosition && ! mbIsNotificationActive)
235cdf0e10cSrcweir     {
236cdf0e10cSrcweir         mnThumbPosition = nPosition;
237cdf0e10cSrcweir 
238cdf0e10cSrcweir         UpdateBorders();
239cdf0e10cSrcweir         Repaint(GetRectangle(Total), bAsynchronousUpdate);
240cdf0e10cSrcweir         if (bNotify)
241cdf0e10cSrcweir             NotifyThumbPositionChange();
242cdf0e10cSrcweir     }
243cdf0e10cSrcweir }
244cdf0e10cSrcweir 
245cdf0e10cSrcweir 
246cdf0e10cSrcweir 
247cdf0e10cSrcweir 
248cdf0e10cSrcweir double PresenterScrollBar::GetThumbPosition (void) const
249cdf0e10cSrcweir {
250cdf0e10cSrcweir     return mnThumbPosition;
251cdf0e10cSrcweir }
252cdf0e10cSrcweir 
253cdf0e10cSrcweir 
254cdf0e10cSrcweir 
255cdf0e10cSrcweir 
256cdf0e10cSrcweir void PresenterScrollBar::SetTotalSize (const double nTotalSize)
257cdf0e10cSrcweir {
258cdf0e10cSrcweir     if (mnTotalSize != nTotalSize)
259cdf0e10cSrcweir     {
260cdf0e10cSrcweir         mnTotalSize = nTotalSize + 1;
261cdf0e10cSrcweir         UpdateBorders();
262cdf0e10cSrcweir         Repaint(GetRectangle(Total), false);
263cdf0e10cSrcweir     }
264cdf0e10cSrcweir }
265cdf0e10cSrcweir 
266cdf0e10cSrcweir 
267cdf0e10cSrcweir 
268cdf0e10cSrcweir 
269cdf0e10cSrcweir double PresenterScrollBar::GetTotalSize (void) const
270cdf0e10cSrcweir {
271cdf0e10cSrcweir     return mnTotalSize;
272cdf0e10cSrcweir }
273cdf0e10cSrcweir 
274cdf0e10cSrcweir 
275cdf0e10cSrcweir 
276cdf0e10cSrcweir 
277cdf0e10cSrcweir void PresenterScrollBar::SetThumbSize (const double nThumbSize)
278cdf0e10cSrcweir {
279cdf0e10cSrcweir     OSL_ASSERT(nThumbSize>=0);
280cdf0e10cSrcweir     if (mnThumbSize != nThumbSize)
281cdf0e10cSrcweir     {
282cdf0e10cSrcweir         mnThumbSize = nThumbSize;
283cdf0e10cSrcweir         UpdateBorders();
284cdf0e10cSrcweir         Repaint(GetRectangle(Total), false);
285cdf0e10cSrcweir     }
286cdf0e10cSrcweir }
287cdf0e10cSrcweir 
288cdf0e10cSrcweir 
289cdf0e10cSrcweir 
290cdf0e10cSrcweir 
291cdf0e10cSrcweir double PresenterScrollBar::GetThumbSize (void) const
292cdf0e10cSrcweir {
293cdf0e10cSrcweir     return mnThumbSize;
294cdf0e10cSrcweir }
295cdf0e10cSrcweir 
296cdf0e10cSrcweir 
297cdf0e10cSrcweir 
298cdf0e10cSrcweir 
299cdf0e10cSrcweir void PresenterScrollBar::SetLineHeight (const double nLineHeight)
300cdf0e10cSrcweir {
301cdf0e10cSrcweir     mnLineHeight = nLineHeight;
302cdf0e10cSrcweir }
303cdf0e10cSrcweir 
304cdf0e10cSrcweir 
305cdf0e10cSrcweir 
306cdf0e10cSrcweir 
307cdf0e10cSrcweir double PresenterScrollBar::GetLineHeight (void) const
308cdf0e10cSrcweir {
309cdf0e10cSrcweir     return mnLineHeight;
310cdf0e10cSrcweir }
311cdf0e10cSrcweir 
312cdf0e10cSrcweir 
313cdf0e10cSrcweir 
314cdf0e10cSrcweir 
315cdf0e10cSrcweir void PresenterScrollBar::SetCanvas (const Reference<css::rendering::XCanvas>& rxCanvas)
316cdf0e10cSrcweir {
317cdf0e10cSrcweir     if (mxCanvas != rxCanvas)
318cdf0e10cSrcweir     {
319cdf0e10cSrcweir         mxCanvas = rxCanvas;
320cdf0e10cSrcweir         if (mxCanvas.is())
321cdf0e10cSrcweir         {
322cdf0e10cSrcweir             if (mpBitmaps.get()==NULL)
323cdf0e10cSrcweir             {
324cdf0e10cSrcweir                 if (mpSharedBitmaps.expired())
325cdf0e10cSrcweir                 {
326cdf0e10cSrcweir                     try
327cdf0e10cSrcweir                     {
328cdf0e10cSrcweir                         mpBitmaps.reset(new PresenterBitmapContainer(
329cdf0e10cSrcweir                             OUString::createFromAscii("PresenterScreenSettings/ScrollBar/Bitmaps"),
330cdf0e10cSrcweir                             ::boost::shared_ptr<PresenterBitmapContainer>(),
331cdf0e10cSrcweir                             mxComponentContext,
332cdf0e10cSrcweir                             mxCanvas,
333cdf0e10cSrcweir                             PresenterComponent::GetBasePath(mxComponentContext)));
334cdf0e10cSrcweir                         mpSharedBitmaps = mpBitmaps;
335cdf0e10cSrcweir                     }
336cdf0e10cSrcweir                     catch(Exception&)
337cdf0e10cSrcweir                     {
338cdf0e10cSrcweir                         OSL_ASSERT(false);
339cdf0e10cSrcweir                     }
340cdf0e10cSrcweir                 }
341cdf0e10cSrcweir                 else
342cdf0e10cSrcweir                     mpBitmaps = ::boost::shared_ptr<PresenterBitmapContainer>(mpSharedBitmaps);
343cdf0e10cSrcweir                 UpdateBitmaps();
344cdf0e10cSrcweir                 UpdateBorders();
345cdf0e10cSrcweir             }
346cdf0e10cSrcweir 
347cdf0e10cSrcweir             Repaint(GetRectangle(Total), false);
348cdf0e10cSrcweir         }
349cdf0e10cSrcweir     }
350cdf0e10cSrcweir }
351cdf0e10cSrcweir 
352cdf0e10cSrcweir 
353cdf0e10cSrcweir 
354cdf0e10cSrcweir 
355cdf0e10cSrcweir void PresenterScrollBar::SetBackground (const SharedBitmapDescriptor& rpBackgroundBitmap)
356cdf0e10cSrcweir {
357cdf0e10cSrcweir     mpBackgroundBitmap = rpBackgroundBitmap;
358cdf0e10cSrcweir }
359cdf0e10cSrcweir 
360cdf0e10cSrcweir 
361cdf0e10cSrcweir 
362cdf0e10cSrcweir void PresenterScrollBar::CheckValues (void)
363cdf0e10cSrcweir {
364cdf0e10cSrcweir     mnThumbPosition = ValidateThumbPosition(mnThumbPosition);
365cdf0e10cSrcweir }
366cdf0e10cSrcweir 
367cdf0e10cSrcweir 
368cdf0e10cSrcweir 
369cdf0e10cSrcweir 
370cdf0e10cSrcweir double PresenterScrollBar::ValidateThumbPosition (double nPosition)
371cdf0e10cSrcweir {
372cdf0e10cSrcweir     if (nPosition + mnThumbSize > mnTotalSize)
373cdf0e10cSrcweir         nPosition = mnTotalSize - mnThumbSize;
374cdf0e10cSrcweir     if (nPosition < 0)
375cdf0e10cSrcweir         nPosition = 0;
376cdf0e10cSrcweir     return nPosition;
377cdf0e10cSrcweir }
378cdf0e10cSrcweir 
379cdf0e10cSrcweir 
380cdf0e10cSrcweir 
381cdf0e10cSrcweir 
382cdf0e10cSrcweir void PresenterScrollBar::Paint (
383cdf0e10cSrcweir     const awt::Rectangle& rUpdateBox,
384cdf0e10cSrcweir     const bool bNoClip)
385cdf0e10cSrcweir {
386cdf0e10cSrcweir     if ( ! mxCanvas.is() || ! mxWindow.is())
387cdf0e10cSrcweir     {
388cdf0e10cSrcweir         OSL_ASSERT(mxCanvas.is());
389cdf0e10cSrcweir         OSL_ASSERT(mxWindow.is());
390cdf0e10cSrcweir         return;
391cdf0e10cSrcweir     }
392cdf0e10cSrcweir 
393cdf0e10cSrcweir     if ( ! bNoClip)
394cdf0e10cSrcweir     {
395cdf0e10cSrcweir         if (PresenterGeometryHelper::AreRectanglesDisjoint (rUpdateBox, mxWindow->getPosSize()))
396cdf0e10cSrcweir             return;
397cdf0e10cSrcweir     }
398cdf0e10cSrcweir 
399cdf0e10cSrcweir     PaintBackground(rUpdateBox);
400cdf0e10cSrcweir     PaintComposite(rUpdateBox, PagerUp,
401cdf0e10cSrcweir         mpPagerStartDescriptor, mpPagerCenterDescriptor, SharedBitmapDescriptor());
402cdf0e10cSrcweir     PaintComposite(rUpdateBox, PagerDown,
403cdf0e10cSrcweir         SharedBitmapDescriptor(), mpPagerCenterDescriptor, mpPagerEndDescriptor);
404cdf0e10cSrcweir     PaintComposite(rUpdateBox, Thumb,
405cdf0e10cSrcweir         mpThumbStartDescriptor, mpThumbCenterDescriptor, mpThumbEndDescriptor);
406cdf0e10cSrcweir     PaintBitmap(rUpdateBox, PrevButton, mpPrevButtonDescriptor);
407cdf0e10cSrcweir     PaintBitmap(rUpdateBox, NextButton, mpNextButtonDescriptor);
408cdf0e10cSrcweir 
409cdf0e10cSrcweir     Reference<rendering::XSpriteCanvas> xSpriteCanvas (mxCanvas, UNO_QUERY);
410cdf0e10cSrcweir     if (xSpriteCanvas.is())
411cdf0e10cSrcweir         xSpriteCanvas->updateScreen(sal_False);
412cdf0e10cSrcweir }
413cdf0e10cSrcweir 
414cdf0e10cSrcweir 
415cdf0e10cSrcweir 
416cdf0e10cSrcweir 
417cdf0e10cSrcweir 
418cdf0e10cSrcweir 
419cdf0e10cSrcweir //----- XWindowListener -------------------------------------------------------
420cdf0e10cSrcweir 
421cdf0e10cSrcweir void SAL_CALL PresenterScrollBar::windowResized (const css::awt::WindowEvent& rEvent)
422cdf0e10cSrcweir     throw (css::uno::RuntimeException)
423cdf0e10cSrcweir {
424cdf0e10cSrcweir     (void)rEvent;
425cdf0e10cSrcweir }
426cdf0e10cSrcweir 
427cdf0e10cSrcweir 
428cdf0e10cSrcweir 
429cdf0e10cSrcweir 
430cdf0e10cSrcweir 
431cdf0e10cSrcweir void SAL_CALL PresenterScrollBar::windowMoved (const css::awt::WindowEvent& rEvent)
432cdf0e10cSrcweir     throw (css::uno::RuntimeException)
433cdf0e10cSrcweir {
434cdf0e10cSrcweir     (void)rEvent;
435cdf0e10cSrcweir }
436cdf0e10cSrcweir 
437cdf0e10cSrcweir 
438cdf0e10cSrcweir 
439cdf0e10cSrcweir 
440cdf0e10cSrcweir void SAL_CALL PresenterScrollBar::windowShown (const css::lang::EventObject& rEvent)
441cdf0e10cSrcweir     throw (css::uno::RuntimeException)
442cdf0e10cSrcweir {
443cdf0e10cSrcweir     (void)rEvent;
444cdf0e10cSrcweir }
445cdf0e10cSrcweir 
446cdf0e10cSrcweir 
447cdf0e10cSrcweir 
448cdf0e10cSrcweir 
449cdf0e10cSrcweir void SAL_CALL PresenterScrollBar::windowHidden (const css::lang::EventObject& rEvent)
450cdf0e10cSrcweir     throw (css::uno::RuntimeException)
451cdf0e10cSrcweir {
452cdf0e10cSrcweir     (void)rEvent;
453cdf0e10cSrcweir }
454cdf0e10cSrcweir 
455cdf0e10cSrcweir 
456cdf0e10cSrcweir 
457cdf0e10cSrcweir 
458cdf0e10cSrcweir //----- XPaintListener --------------------------------------------------------
459cdf0e10cSrcweir 
460cdf0e10cSrcweir void SAL_CALL PresenterScrollBar::windowPaint (const css::awt::PaintEvent& rEvent)
461cdf0e10cSrcweir     throw (css::uno::RuntimeException)
462cdf0e10cSrcweir {
463cdf0e10cSrcweir     if (mxWindow.is())
464cdf0e10cSrcweir     {
465cdf0e10cSrcweir         awt::Rectangle aRepaintBox (rEvent.UpdateRect);
466cdf0e10cSrcweir         const awt::Rectangle aWindowBox (mxWindow->getPosSize());
467cdf0e10cSrcweir         aRepaintBox.X += aWindowBox.X;
468cdf0e10cSrcweir         aRepaintBox.Y += aWindowBox.Y;
469cdf0e10cSrcweir         Paint(aRepaintBox);
470cdf0e10cSrcweir 
471cdf0e10cSrcweir         Reference<rendering::XSpriteCanvas> xSpriteCanvas (mxCanvas, UNO_QUERY);
472cdf0e10cSrcweir         if (xSpriteCanvas.is())
473cdf0e10cSrcweir             xSpriteCanvas->updateScreen(sal_False);
474cdf0e10cSrcweir     }
475cdf0e10cSrcweir }
476cdf0e10cSrcweir 
477cdf0e10cSrcweir 
478cdf0e10cSrcweir 
479cdf0e10cSrcweir 
480cdf0e10cSrcweir //----- XMouseListener --------------------------------------------------------
481cdf0e10cSrcweir 
482cdf0e10cSrcweir void SAL_CALL PresenterScrollBar::mousePressed (const css::awt::MouseEvent& rEvent)
483cdf0e10cSrcweir     throw(css::uno::RuntimeException)
484cdf0e10cSrcweir {
485cdf0e10cSrcweir     maDragAnchor.X = rEvent.X;
486cdf0e10cSrcweir     maDragAnchor.Y = rEvent.Y;
487cdf0e10cSrcweir     meButtonDownArea = GetArea(rEvent.X, rEvent.Y);
488cdf0e10cSrcweir 
489cdf0e10cSrcweir     mpMousePressRepeater->Start(meButtonDownArea);
490cdf0e10cSrcweir }
491cdf0e10cSrcweir 
492cdf0e10cSrcweir 
493cdf0e10cSrcweir 
494cdf0e10cSrcweir 
495cdf0e10cSrcweir void SAL_CALL PresenterScrollBar::mouseReleased (const css::awt::MouseEvent& rEvent)
496cdf0e10cSrcweir     throw(css::uno::RuntimeException)
497cdf0e10cSrcweir {
498cdf0e10cSrcweir     (void)rEvent;
499cdf0e10cSrcweir 
500cdf0e10cSrcweir     mpMousePressRepeater->Stop();
501cdf0e10cSrcweir 
502cdf0e10cSrcweir     if (mxPresenterHelper.is())
503cdf0e10cSrcweir         mxPresenterHelper->releaseMouse(mxWindow);
504cdf0e10cSrcweir }
505cdf0e10cSrcweir 
506cdf0e10cSrcweir 
507cdf0e10cSrcweir 
508cdf0e10cSrcweir 
509cdf0e10cSrcweir void SAL_CALL PresenterScrollBar::mouseEntered (const css::awt::MouseEvent& rEvent)
510cdf0e10cSrcweir     throw(css::uno::RuntimeException)
511cdf0e10cSrcweir {
512cdf0e10cSrcweir     (void)rEvent;
513cdf0e10cSrcweir }
514cdf0e10cSrcweir 
515cdf0e10cSrcweir 
516cdf0e10cSrcweir 
517cdf0e10cSrcweir 
518cdf0e10cSrcweir void SAL_CALL PresenterScrollBar::mouseExited (const css::awt::MouseEvent& rEvent)
519cdf0e10cSrcweir     throw(css::uno::RuntimeException)
520cdf0e10cSrcweir {
521cdf0e10cSrcweir     (void)rEvent;
522cdf0e10cSrcweir     if (meMouseMoveArea != None)
523cdf0e10cSrcweir     {
524cdf0e10cSrcweir         const Area eOldMouseMoveArea (meMouseMoveArea);
525cdf0e10cSrcweir         meMouseMoveArea = None;
526cdf0e10cSrcweir         Repaint(GetRectangle(eOldMouseMoveArea), true);
527cdf0e10cSrcweir     }
528cdf0e10cSrcweir     meButtonDownArea = None;
529cdf0e10cSrcweir     meMouseMoveArea = None;
530cdf0e10cSrcweir 
531cdf0e10cSrcweir     mpMousePressRepeater->Stop();
532cdf0e10cSrcweir }
533cdf0e10cSrcweir 
534cdf0e10cSrcweir 
535cdf0e10cSrcweir 
536cdf0e10cSrcweir 
537cdf0e10cSrcweir 
538cdf0e10cSrcweir //----- XMouseMotionListener --------------------------------------------------
539cdf0e10cSrcweir 
540cdf0e10cSrcweir void SAL_CALL PresenterScrollBar::mouseMoved (const css::awt::MouseEvent& rEvent)
541cdf0e10cSrcweir     throw (css::uno::RuntimeException)
542cdf0e10cSrcweir {
543cdf0e10cSrcweir     const Area eArea (GetArea(rEvent.X, rEvent.Y));
544cdf0e10cSrcweir     if (eArea != meMouseMoveArea)
545cdf0e10cSrcweir     {
546cdf0e10cSrcweir         const Area eOldMouseMoveArea (meMouseMoveArea);
547cdf0e10cSrcweir         meMouseMoveArea = eArea;
548cdf0e10cSrcweir         if (eOldMouseMoveArea != None)
549cdf0e10cSrcweir             Repaint(GetRectangle(eOldMouseMoveArea), meMouseMoveArea==None);
550cdf0e10cSrcweir         if (meMouseMoveArea != None)
551cdf0e10cSrcweir             Repaint(GetRectangle(meMouseMoveArea), true);
552cdf0e10cSrcweir     }
553cdf0e10cSrcweir     mpMousePressRepeater->SetMouseArea(eArea);
554cdf0e10cSrcweir }
555cdf0e10cSrcweir 
556cdf0e10cSrcweir 
557cdf0e10cSrcweir 
558cdf0e10cSrcweir 
559cdf0e10cSrcweir void SAL_CALL PresenterScrollBar::mouseDragged (const css::awt::MouseEvent& rEvent)
560cdf0e10cSrcweir     throw (css::uno::RuntimeException)
561cdf0e10cSrcweir {
562cdf0e10cSrcweir     if (meButtonDownArea != Thumb)
563cdf0e10cSrcweir         return;
564cdf0e10cSrcweir 
565cdf0e10cSrcweir     mpMousePressRepeater->Stop();
566cdf0e10cSrcweir 
567cdf0e10cSrcweir     if (mxPresenterHelper.is())
568cdf0e10cSrcweir         mxPresenterHelper->captureMouse(mxWindow);
569cdf0e10cSrcweir 
570cdf0e10cSrcweir     const double nDragDistance (GetDragDistance(rEvent.X,rEvent.Y));
571cdf0e10cSrcweir     UpdateDragAnchor(nDragDistance);
572cdf0e10cSrcweir     if (nDragDistance != 0)
573cdf0e10cSrcweir     {
574cdf0e10cSrcweir         SetThumbPosition(mnThumbPosition + nDragDistance, false, true, true);
575cdf0e10cSrcweir     }
576cdf0e10cSrcweir }
577cdf0e10cSrcweir 
578cdf0e10cSrcweir 
579cdf0e10cSrcweir 
580cdf0e10cSrcweir 
581cdf0e10cSrcweir //----- lang::XEventListener --------------------------------------------------
582cdf0e10cSrcweir 
583cdf0e10cSrcweir void SAL_CALL PresenterScrollBar::disposing (const css::lang::EventObject& rEvent)
584cdf0e10cSrcweir     throw (css::uno::RuntimeException)
585cdf0e10cSrcweir {
586cdf0e10cSrcweir     if (rEvent.Source == mxWindow)
587cdf0e10cSrcweir         mxWindow = NULL;
588cdf0e10cSrcweir }
589cdf0e10cSrcweir 
590cdf0e10cSrcweir 
591cdf0e10cSrcweir 
592cdf0e10cSrcweir 
593cdf0e10cSrcweir //-----------------------------------------------------------------------------
594cdf0e10cSrcweir 
595cdf0e10cSrcweir geometry::RealRectangle2D PresenterScrollBar::GetRectangle (const Area eArea) const
596cdf0e10cSrcweir {
597cdf0e10cSrcweir     OSL_ASSERT(eArea>=0 && eArea<__AreaCount__);
598cdf0e10cSrcweir 
599cdf0e10cSrcweir     return maBox[eArea];
600cdf0e10cSrcweir }
601cdf0e10cSrcweir 
602cdf0e10cSrcweir 
603cdf0e10cSrcweir 
604cdf0e10cSrcweir 
605cdf0e10cSrcweir void PresenterScrollBar::Repaint (
606cdf0e10cSrcweir     const geometry::RealRectangle2D aBox,
607cdf0e10cSrcweir     const bool bAsynchronousUpdate)
608cdf0e10cSrcweir {
609cdf0e10cSrcweir     if (mpPaintManager.get() != NULL)
610cdf0e10cSrcweir         mpPaintManager->Invalidate(
611cdf0e10cSrcweir             mxWindow,
612cdf0e10cSrcweir             PresenterGeometryHelper::ConvertRectangle(aBox),
613cdf0e10cSrcweir             bAsynchronousUpdate);
614cdf0e10cSrcweir }
615cdf0e10cSrcweir 
616cdf0e10cSrcweir 
617cdf0e10cSrcweir 
618cdf0e10cSrcweir 
619cdf0e10cSrcweir void PresenterScrollBar::PaintBackground(
620cdf0e10cSrcweir     const css::awt::Rectangle& rUpdateBox)
621cdf0e10cSrcweir {
622cdf0e10cSrcweir     if (mpBackgroundBitmap.get() == NULL)
623cdf0e10cSrcweir         return;
624cdf0e10cSrcweir 
625cdf0e10cSrcweir     const awt::Rectangle aWindowBox (mxWindow->getPosSize());
626cdf0e10cSrcweir     mpCanvasHelper->Paint(
627cdf0e10cSrcweir         mpBackgroundBitmap,
628cdf0e10cSrcweir         mxCanvas,
629cdf0e10cSrcweir         rUpdateBox,
630cdf0e10cSrcweir         aWindowBox,
631cdf0e10cSrcweir         awt::Rectangle());
632cdf0e10cSrcweir }
633cdf0e10cSrcweir 
634cdf0e10cSrcweir 
635cdf0e10cSrcweir 
636cdf0e10cSrcweir 
637cdf0e10cSrcweir void PresenterScrollBar::PaintBitmap(
638cdf0e10cSrcweir     const css::awt::Rectangle& rUpdateBox,
639cdf0e10cSrcweir     const Area eArea,
640cdf0e10cSrcweir     const SharedBitmapDescriptor& rpBitmaps)
641cdf0e10cSrcweir {
642cdf0e10cSrcweir     const geometry::RealRectangle2D aLocalBox (GetRectangle(eArea));
643cdf0e10cSrcweir     const awt::Rectangle aWindowBox (mxWindow->getPosSize());
644cdf0e10cSrcweir     geometry::RealRectangle2D aBox (aLocalBox);
645cdf0e10cSrcweir     aBox.X1 += aWindowBox.X;
646cdf0e10cSrcweir     aBox.Y1 += aWindowBox.Y;
647cdf0e10cSrcweir     aBox.X2 += aWindowBox.X;
648cdf0e10cSrcweir     aBox.Y2 += aWindowBox.Y;
649cdf0e10cSrcweir 
650cdf0e10cSrcweir     Reference<rendering::XBitmap> xBitmap (GetBitmap(eArea,rpBitmaps));
651cdf0e10cSrcweir 
652cdf0e10cSrcweir     if (xBitmap.is())
653cdf0e10cSrcweir     {
654cdf0e10cSrcweir         Reference<rendering::XPolyPolygon2D> xClipPolygon (
655cdf0e10cSrcweir             PresenterGeometryHelper::CreatePolygon(
656cdf0e10cSrcweir                 PresenterGeometryHelper::Intersection(rUpdateBox,
657cdf0e10cSrcweir                     PresenterGeometryHelper::ConvertRectangle(aBox)),
658cdf0e10cSrcweir                 mxCanvas->getDevice()));
659cdf0e10cSrcweir 
660cdf0e10cSrcweir         const rendering::ViewState aViewState (
661cdf0e10cSrcweir             geometry::AffineMatrix2D(1,0,0, 0,1,0),
662cdf0e10cSrcweir             xClipPolygon);
663cdf0e10cSrcweir 
664cdf0e10cSrcweir         const geometry::IntegerSize2D aBitmapSize (xBitmap->getSize());
665cdf0e10cSrcweir         rendering::RenderState aRenderState (
666cdf0e10cSrcweir             geometry::AffineMatrix2D(
667cdf0e10cSrcweir                 1,0,aBox.X1 + (aBox.X2-aBox.X1 - aBitmapSize.Width)/2,
668cdf0e10cSrcweir                 0,1,aBox.Y1 + (aBox.Y2-aBox.Y1 - aBitmapSize.Height)/2),
669cdf0e10cSrcweir             NULL,
670cdf0e10cSrcweir             Sequence<double>(4),
671cdf0e10cSrcweir             rendering::CompositeOperation::SOURCE);
672cdf0e10cSrcweir 
673cdf0e10cSrcweir         mxCanvas->drawBitmap(
674cdf0e10cSrcweir             xBitmap,
675cdf0e10cSrcweir             aViewState,
676cdf0e10cSrcweir             aRenderState);
677cdf0e10cSrcweir     }
678cdf0e10cSrcweir }
679cdf0e10cSrcweir 
680cdf0e10cSrcweir 
681cdf0e10cSrcweir 
682cdf0e10cSrcweir 
683cdf0e10cSrcweir void PresenterScrollBar::NotifyThumbPositionChange (void)
684cdf0e10cSrcweir {
685cdf0e10cSrcweir     if ( ! mbIsNotificationActive)
686cdf0e10cSrcweir     {
687cdf0e10cSrcweir         mbIsNotificationActive = true;
688cdf0e10cSrcweir 
689cdf0e10cSrcweir         try
690cdf0e10cSrcweir         {
691cdf0e10cSrcweir             maThumbMotionListener(mnThumbPosition);
692cdf0e10cSrcweir         }
693cdf0e10cSrcweir         catch (Exception&)
694cdf0e10cSrcweir         {
695cdf0e10cSrcweir         }
696cdf0e10cSrcweir 
697cdf0e10cSrcweir         mbIsNotificationActive = false;
698cdf0e10cSrcweir     }
699cdf0e10cSrcweir }
700cdf0e10cSrcweir 
701cdf0e10cSrcweir 
702cdf0e10cSrcweir 
703cdf0e10cSrcweir 
704cdf0e10cSrcweir PresenterScrollBar::Area PresenterScrollBar::GetArea (const double nX, const double nY) const
705cdf0e10cSrcweir {
706cdf0e10cSrcweir     const geometry::RealPoint2D aPoint(nX, nY);
707cdf0e10cSrcweir 
708cdf0e10cSrcweir     if (PresenterGeometryHelper::IsInside(GetRectangle(Pager), aPoint))
709cdf0e10cSrcweir     {
710cdf0e10cSrcweir         if (PresenterGeometryHelper::IsInside(GetRectangle(Thumb), aPoint))
711cdf0e10cSrcweir             return Thumb;
712cdf0e10cSrcweir         else if (PresenterGeometryHelper::IsInside(GetRectangle(PagerUp), aPoint))
713cdf0e10cSrcweir             return PagerUp;
714cdf0e10cSrcweir         else if (PresenterGeometryHelper::IsInside(GetRectangle(PagerDown), aPoint))
715cdf0e10cSrcweir             return PagerDown;
716cdf0e10cSrcweir     }
717cdf0e10cSrcweir     else if (PresenterGeometryHelper::IsInside(GetRectangle(PrevButton), aPoint))
718cdf0e10cSrcweir         return PrevButton;
719cdf0e10cSrcweir     else if (PresenterGeometryHelper::IsInside(GetRectangle(NextButton), aPoint))
720cdf0e10cSrcweir         return NextButton;
721cdf0e10cSrcweir 
722cdf0e10cSrcweir     return None;
723cdf0e10cSrcweir }
724cdf0e10cSrcweir 
725cdf0e10cSrcweir 
726cdf0e10cSrcweir 
727cdf0e10cSrcweir 
728cdf0e10cSrcweir void PresenterScrollBar::UpdateWidthOrHeight (
729cdf0e10cSrcweir     sal_Int32& rSize,
730cdf0e10cSrcweir     const SharedBitmapDescriptor& rpDescriptor)
731cdf0e10cSrcweir {
732cdf0e10cSrcweir     if (rpDescriptor.get() != NULL)
733cdf0e10cSrcweir     {
734cdf0e10cSrcweir         Reference<rendering::XBitmap> xBitmap (rpDescriptor->GetNormalBitmap());
735cdf0e10cSrcweir         if (xBitmap.is())
736cdf0e10cSrcweir         {
737cdf0e10cSrcweir             const geometry::IntegerSize2D aBitmapSize (xBitmap->getSize());
738cdf0e10cSrcweir             const sal_Int32 nBitmapSize = (sal_Int32)GetMinor(aBitmapSize.Width, aBitmapSize.Height);
739cdf0e10cSrcweir             if (nBitmapSize > rSize)
740cdf0e10cSrcweir                 rSize = nBitmapSize;
741cdf0e10cSrcweir         }
742cdf0e10cSrcweir     }
743cdf0e10cSrcweir }
744cdf0e10cSrcweir 
745cdf0e10cSrcweir 
746cdf0e10cSrcweir 
747cdf0e10cSrcweir 
748cdf0e10cSrcweir css::uno::Reference<css::rendering::XBitmap> PresenterScrollBar::GetBitmap (
749cdf0e10cSrcweir     const Area eArea,
750cdf0e10cSrcweir     const SharedBitmapDescriptor& rpBitmaps) const
751cdf0e10cSrcweir {
752cdf0e10cSrcweir     if (rpBitmaps.get() == NULL)
753cdf0e10cSrcweir         return NULL;
754cdf0e10cSrcweir     else
755cdf0e10cSrcweir         return rpBitmaps->GetBitmap(GetBitmapMode(eArea));
756cdf0e10cSrcweir }
757cdf0e10cSrcweir 
758cdf0e10cSrcweir 
759cdf0e10cSrcweir 
760cdf0e10cSrcweir 
761cdf0e10cSrcweir PresenterBitmapContainer::BitmapDescriptor::Mode PresenterScrollBar::GetBitmapMode (
762cdf0e10cSrcweir     const Area eArea) const
763cdf0e10cSrcweir {
764cdf0e10cSrcweir     if (IsDisabled(eArea))
765cdf0e10cSrcweir         return PresenterBitmapContainer::BitmapDescriptor::Disabled;
766cdf0e10cSrcweir     else if (eArea == meMouseMoveArea)
767cdf0e10cSrcweir         return PresenterBitmapContainer::BitmapDescriptor::MouseOver;
768cdf0e10cSrcweir     else
769cdf0e10cSrcweir         return PresenterBitmapContainer::BitmapDescriptor::Normal;
770cdf0e10cSrcweir }
771cdf0e10cSrcweir 
772cdf0e10cSrcweir 
773cdf0e10cSrcweir 
774cdf0e10cSrcweir 
775cdf0e10cSrcweir bool PresenterScrollBar::IsDisabled (const Area eArea) const
776cdf0e10cSrcweir {
777cdf0e10cSrcweir     OSL_ASSERT(eArea>=0 && eArea<__AreaCount__);
778cdf0e10cSrcweir 
779cdf0e10cSrcweir     return ! maEnabledState[eArea];
780cdf0e10cSrcweir }
781cdf0e10cSrcweir 
782cdf0e10cSrcweir 
783cdf0e10cSrcweir 
784cdf0e10cSrcweir 
785cdf0e10cSrcweir //===== PresenterVerticalScrollBar ============================================
786cdf0e10cSrcweir 
787cdf0e10cSrcweir PresenterVerticalScrollBar::PresenterVerticalScrollBar (
788cdf0e10cSrcweir     const Reference<XComponentContext>& rxComponentContext,
789cdf0e10cSrcweir     const Reference<awt::XWindow>& rxParentWindow,
790cdf0e10cSrcweir     const ::boost::shared_ptr<PresenterPaintManager>& rpPaintManager,
791cdf0e10cSrcweir     const ::boost::function<void(double)>& rThumbMotionListener)
792cdf0e10cSrcweir     : PresenterScrollBar(rxComponentContext, rxParentWindow, rpPaintManager, rThumbMotionListener),
793cdf0e10cSrcweir       mnScrollBarWidth(0)
794cdf0e10cSrcweir {
795cdf0e10cSrcweir }
796cdf0e10cSrcweir 
797cdf0e10cSrcweir 
798cdf0e10cSrcweir 
799cdf0e10cSrcweir 
800cdf0e10cSrcweir PresenterVerticalScrollBar::~PresenterVerticalScrollBar (void)
801cdf0e10cSrcweir {
802cdf0e10cSrcweir }
803cdf0e10cSrcweir 
804cdf0e10cSrcweir 
805cdf0e10cSrcweir 
806cdf0e10cSrcweir 
807cdf0e10cSrcweir double PresenterVerticalScrollBar::GetDragDistance (const sal_Int32 nX, const sal_Int32 nY) const
808cdf0e10cSrcweir {
809cdf0e10cSrcweir     (void)nX;
810cdf0e10cSrcweir     const double nDistance (nY - maDragAnchor.Y);
811cdf0e10cSrcweir     if (nDistance == 0)
812cdf0e10cSrcweir         return 0;
813cdf0e10cSrcweir     else
814cdf0e10cSrcweir     {
815cdf0e10cSrcweir         const awt::Rectangle aWindowBox (mxWindow->getPosSize());
816cdf0e10cSrcweir         const double nBarWidth (aWindowBox.Width);
817cdf0e10cSrcweir         const double nPagerHeight (aWindowBox.Height - 2*nBarWidth);
818cdf0e10cSrcweir         const double nDragDistance (mnTotalSize / nPagerHeight * nDistance);
819cdf0e10cSrcweir         if (nDragDistance + mnThumbPosition < 0)
820cdf0e10cSrcweir             return -mnThumbPosition;
821cdf0e10cSrcweir         else if (mnThumbPosition + nDragDistance > mnTotalSize-mnThumbSize)
822cdf0e10cSrcweir             return mnTotalSize-mnThumbSize-mnThumbPosition;
823cdf0e10cSrcweir         else
824cdf0e10cSrcweir             return nDragDistance;
825cdf0e10cSrcweir     }
826cdf0e10cSrcweir }
827cdf0e10cSrcweir 
828cdf0e10cSrcweir 
829cdf0e10cSrcweir 
830cdf0e10cSrcweir 
831cdf0e10cSrcweir void PresenterVerticalScrollBar::UpdateDragAnchor (const double nDragDistance)
832cdf0e10cSrcweir {
833cdf0e10cSrcweir     const awt::Rectangle aWindowBox (mxWindow->getPosSize());
834cdf0e10cSrcweir     const double nBarWidth (aWindowBox.Width);
835cdf0e10cSrcweir     const double nPagerHeight (aWindowBox.Height - 2*nBarWidth);
836cdf0e10cSrcweir     maDragAnchor.Y += nDragDistance * nPagerHeight /  mnTotalSize;
837cdf0e10cSrcweir }
838cdf0e10cSrcweir 
839cdf0e10cSrcweir 
840cdf0e10cSrcweir 
841cdf0e10cSrcweir 
842cdf0e10cSrcweir sal_Int32 PresenterVerticalScrollBar::GetSize (void) const
843cdf0e10cSrcweir {
844cdf0e10cSrcweir     return mnScrollBarWidth;
845cdf0e10cSrcweir }
846cdf0e10cSrcweir 
847cdf0e10cSrcweir 
848cdf0e10cSrcweir 
849cdf0e10cSrcweir 
850cdf0e10cSrcweir geometry::RealPoint2D PresenterVerticalScrollBar::GetPoint (
851cdf0e10cSrcweir     const double nMajor, const double nMinor) const
852cdf0e10cSrcweir {
853cdf0e10cSrcweir     return geometry::RealPoint2D(nMinor, nMajor);
854cdf0e10cSrcweir }
855cdf0e10cSrcweir 
856cdf0e10cSrcweir 
857cdf0e10cSrcweir 
858cdf0e10cSrcweir 
859cdf0e10cSrcweir double PresenterVerticalScrollBar::GetMajor (const double nX, const double nY) const
860cdf0e10cSrcweir {
861cdf0e10cSrcweir     (void)nX;
862cdf0e10cSrcweir     return nY;
863cdf0e10cSrcweir }
864cdf0e10cSrcweir 
865cdf0e10cSrcweir 
866cdf0e10cSrcweir 
867cdf0e10cSrcweir 
868cdf0e10cSrcweir double PresenterVerticalScrollBar::GetMinor (const double nX, const double nY) const
869cdf0e10cSrcweir {
870cdf0e10cSrcweir     (void)nY;
871cdf0e10cSrcweir     return nX;
872cdf0e10cSrcweir }
873cdf0e10cSrcweir 
874cdf0e10cSrcweir 
875cdf0e10cSrcweir 
876cdf0e10cSrcweir 
877cdf0e10cSrcweir void PresenterVerticalScrollBar::UpdateBorders (void)
878cdf0e10cSrcweir {
879cdf0e10cSrcweir     const awt::Rectangle aWindowBox (mxWindow->getPosSize());
880cdf0e10cSrcweir     double nBottom = aWindowBox.Height;
881cdf0e10cSrcweir 
882cdf0e10cSrcweir     if (mpNextButtonDescriptor.get() != NULL)
883cdf0e10cSrcweir     {
884cdf0e10cSrcweir         Reference<rendering::XBitmap> xBitmap (mpNextButtonDescriptor->GetNormalBitmap());
885cdf0e10cSrcweir         if (xBitmap.is())
886cdf0e10cSrcweir         {
887cdf0e10cSrcweir             geometry::IntegerSize2D aSize (xBitmap->getSize());
888cdf0e10cSrcweir             maBox[NextButton] = geometry::RealRectangle2D(
889cdf0e10cSrcweir                 0, nBottom - aSize.Height, aWindowBox.Width, nBottom);
890cdf0e10cSrcweir             nBottom -= aSize.Height + gnScrollBarGap;
891cdf0e10cSrcweir         }
892cdf0e10cSrcweir     }
893cdf0e10cSrcweir     if (mpPrevButtonDescriptor.get() != NULL)
894cdf0e10cSrcweir     {
895cdf0e10cSrcweir         Reference<rendering::XBitmap> xBitmap (mpPrevButtonDescriptor->GetNormalBitmap());
896cdf0e10cSrcweir         if (xBitmap.is())
897cdf0e10cSrcweir         {
898cdf0e10cSrcweir             geometry::IntegerSize2D aSize (xBitmap->getSize());
899cdf0e10cSrcweir             maBox[PrevButton] = geometry::RealRectangle2D(
900cdf0e10cSrcweir                 0, nBottom - aSize.Height, aWindowBox.Width, nBottom);
901cdf0e10cSrcweir             nBottom -= aSize.Height + gnScrollBarGap;
902cdf0e10cSrcweir         }
903cdf0e10cSrcweir     }
904cdf0e10cSrcweir     const double nPagerHeight (nBottom);
905cdf0e10cSrcweir     maBox[Pager] = geometry::RealRectangle2D(
906cdf0e10cSrcweir         0,0, aWindowBox.Width, nBottom);
907cdf0e10cSrcweir     if (mnTotalSize < 1)
908cdf0e10cSrcweir     {
909cdf0e10cSrcweir         maBox[Thumb] = maBox[Pager];
910cdf0e10cSrcweir 
911cdf0e10cSrcweir         // Set up the enabled/disabled states.
912cdf0e10cSrcweir         maEnabledState[PrevButton] = false;
913cdf0e10cSrcweir         maEnabledState[PagerUp] = false;
914cdf0e10cSrcweir         maEnabledState[NextButton] = false;
915cdf0e10cSrcweir         maEnabledState[PagerDown] = false;
916cdf0e10cSrcweir         maEnabledState[Thumb] = false;
917cdf0e10cSrcweir     }
918cdf0e10cSrcweir     else
919cdf0e10cSrcweir     {
920cdf0e10cSrcweir         const double nThumbSize = ::std::min(mnThumbSize,mnTotalSize);
921cdf0e10cSrcweir         const double nThumbPosition = ::std::min(::std::max(0.0,mnThumbPosition), mnTotalSize - nThumbSize);
922cdf0e10cSrcweir         maBox[Thumb] = geometry::RealRectangle2D(
923cdf0e10cSrcweir             0, nThumbPosition / mnTotalSize * nPagerHeight,
924cdf0e10cSrcweir             aWindowBox.Width,
925cdf0e10cSrcweir                 (nThumbPosition+nThumbSize) / mnTotalSize * nPagerHeight);
926cdf0e10cSrcweir 
927cdf0e10cSrcweir         // Set up the enabled/disabled states.
928cdf0e10cSrcweir         maEnabledState[PrevButton] = nThumbPosition>0;
929cdf0e10cSrcweir         maEnabledState[PagerUp] = nThumbPosition>0;
930cdf0e10cSrcweir         maEnabledState[NextButton] = nThumbPosition+nThumbSize < mnTotalSize;
931cdf0e10cSrcweir         maEnabledState[PagerDown] = nThumbPosition+nThumbSize < mnTotalSize;
932cdf0e10cSrcweir         maEnabledState[Thumb] = nThumbSize < mnTotalSize;
933cdf0e10cSrcweir     }
934cdf0e10cSrcweir     maBox[PagerUp] = geometry::RealRectangle2D(
935cdf0e10cSrcweir         maBox[Pager].X1, maBox[Pager].Y1, maBox[Pager].X2, maBox[Thumb].Y1-1);
936cdf0e10cSrcweir     maBox[PagerDown] = geometry::RealRectangle2D(
937cdf0e10cSrcweir         maBox[Pager].X1, maBox[Thumb].Y2+1, maBox[Pager].X2, maBox[Pager].Y2);
938cdf0e10cSrcweir     maBox[Total] = PresenterGeometryHelper::Union(
939cdf0e10cSrcweir         PresenterGeometryHelper::Union(maBox[PrevButton], maBox[NextButton]),
940cdf0e10cSrcweir         maBox[Pager]);
941cdf0e10cSrcweir }
942cdf0e10cSrcweir 
943cdf0e10cSrcweir 
944cdf0e10cSrcweir 
945cdf0e10cSrcweir 
946cdf0e10cSrcweir void PresenterVerticalScrollBar::UpdateBitmaps (void)
947cdf0e10cSrcweir {
948cdf0e10cSrcweir     if (mpBitmaps.get() != NULL)
949cdf0e10cSrcweir     {
950cdf0e10cSrcweir         mpPrevButtonDescriptor = mpBitmaps->GetBitmap(A2S("Up"));
951cdf0e10cSrcweir         mpNextButtonDescriptor = mpBitmaps->GetBitmap(A2S("Down"));
952cdf0e10cSrcweir         mpPagerStartDescriptor = mpBitmaps->GetBitmap(A2S("PagerTop"));
953cdf0e10cSrcweir         mpPagerCenterDescriptor = mpBitmaps->GetBitmap(A2S("PagerVertical"));
954cdf0e10cSrcweir         mpPagerEndDescriptor = mpBitmaps->GetBitmap(A2S("PagerBottom"));
955cdf0e10cSrcweir         mpThumbStartDescriptor = mpBitmaps->GetBitmap(A2S("ThumbTop"));
956cdf0e10cSrcweir         mpThumbCenterDescriptor = mpBitmaps->GetBitmap(A2S("ThumbVertical"));
957cdf0e10cSrcweir         mpThumbEndDescriptor = mpBitmaps->GetBitmap(A2S("ThumbBottom"));
958cdf0e10cSrcweir 
959cdf0e10cSrcweir         mnScrollBarWidth = 0;
960cdf0e10cSrcweir         UpdateWidthOrHeight(mnScrollBarWidth, mpPrevButtonDescriptor);
961cdf0e10cSrcweir         UpdateWidthOrHeight(mnScrollBarWidth, mpNextButtonDescriptor);
962cdf0e10cSrcweir         UpdateWidthOrHeight(mnScrollBarWidth, mpPagerStartDescriptor);
963cdf0e10cSrcweir         UpdateWidthOrHeight(mnScrollBarWidth, mpPagerCenterDescriptor);
964cdf0e10cSrcweir         UpdateWidthOrHeight(mnScrollBarWidth, mpPagerEndDescriptor);
965cdf0e10cSrcweir         UpdateWidthOrHeight(mnScrollBarWidth, mpThumbStartDescriptor);
966cdf0e10cSrcweir         UpdateWidthOrHeight(mnScrollBarWidth, mpThumbCenterDescriptor);
967cdf0e10cSrcweir         UpdateWidthOrHeight(mnScrollBarWidth, mpThumbEndDescriptor);
968cdf0e10cSrcweir         if (mnScrollBarWidth == 0)
969cdf0e10cSrcweir             mnScrollBarWidth = 20;
970cdf0e10cSrcweir     }
971cdf0e10cSrcweir }
972cdf0e10cSrcweir 
973cdf0e10cSrcweir 
974cdf0e10cSrcweir 
975cdf0e10cSrcweir 
976cdf0e10cSrcweir void PresenterVerticalScrollBar::PaintComposite(
977cdf0e10cSrcweir     const css::awt::Rectangle& rUpdateBox,
978cdf0e10cSrcweir     const Area eArea,
979cdf0e10cSrcweir     const SharedBitmapDescriptor& rpStartBitmaps,
980cdf0e10cSrcweir     const SharedBitmapDescriptor& rpCenterBitmaps,
981cdf0e10cSrcweir     const SharedBitmapDescriptor& rpEndBitmaps)
982cdf0e10cSrcweir {
983cdf0e10cSrcweir     const awt::Rectangle aWindowBox (mxWindow->getPosSize());
984cdf0e10cSrcweir     geometry::RealRectangle2D aBox (GetRectangle(eArea));
985cdf0e10cSrcweir     aBox.X1 += aWindowBox.X;
986cdf0e10cSrcweir     aBox.Y1 += aWindowBox.Y;
987cdf0e10cSrcweir     aBox.X2 += aWindowBox.X;
988cdf0e10cSrcweir     aBox.Y2 += aWindowBox.Y;
989cdf0e10cSrcweir 
990cdf0e10cSrcweir     // Get bitmaps and sizes.
991cdf0e10cSrcweir 
992cdf0e10cSrcweir     PresenterUIPainter::PaintVerticalBitmapComposite(
993cdf0e10cSrcweir         mxCanvas,
994cdf0e10cSrcweir         rUpdateBox,
995cdf0e10cSrcweir         (eArea == Thumb
996cdf0e10cSrcweir             ? PresenterGeometryHelper::ConvertRectangleWithConstantSize(aBox)
997cdf0e10cSrcweir             : PresenterGeometryHelper::ConvertRectangle(aBox)),
998cdf0e10cSrcweir         GetBitmap(eArea, rpStartBitmaps),
999cdf0e10cSrcweir         GetBitmap(eArea, rpCenterBitmaps),
1000cdf0e10cSrcweir         GetBitmap(eArea, rpEndBitmaps));
1001cdf0e10cSrcweir }
1002cdf0e10cSrcweir 
1003cdf0e10cSrcweir 
1004cdf0e10cSrcweir 
1005cdf0e10cSrcweir 
1006cdf0e10cSrcweir //===== PresenterHorizontalScrollBar ============================================
1007cdf0e10cSrcweir 
1008cdf0e10cSrcweir PresenterHorizontalScrollBar::PresenterHorizontalScrollBar (
1009cdf0e10cSrcweir     const Reference<XComponentContext>& rxComponentContext,
1010cdf0e10cSrcweir     const Reference<awt::XWindow>& rxParentWindow,
1011cdf0e10cSrcweir     const ::boost::shared_ptr<PresenterPaintManager>& rpPaintManager,
1012cdf0e10cSrcweir     const ::boost::function<void(double)>& rThumbMotionListener)
1013cdf0e10cSrcweir     : PresenterScrollBar(rxComponentContext, rxParentWindow, rpPaintManager, rThumbMotionListener),
1014cdf0e10cSrcweir       mnScrollBarHeight(0)
1015cdf0e10cSrcweir {
1016cdf0e10cSrcweir }
1017cdf0e10cSrcweir 
1018cdf0e10cSrcweir 
1019cdf0e10cSrcweir 
1020cdf0e10cSrcweir 
1021cdf0e10cSrcweir PresenterHorizontalScrollBar::~PresenterHorizontalScrollBar (void)
1022cdf0e10cSrcweir {
1023cdf0e10cSrcweir }
1024cdf0e10cSrcweir 
1025cdf0e10cSrcweir 
1026cdf0e10cSrcweir 
1027cdf0e10cSrcweir 
1028cdf0e10cSrcweir double PresenterHorizontalScrollBar::GetDragDistance (const sal_Int32 nX, const sal_Int32 nY) const
1029cdf0e10cSrcweir {
1030cdf0e10cSrcweir     (void)nY;
1031cdf0e10cSrcweir     const double nDistance (nX - maDragAnchor.X);
1032cdf0e10cSrcweir     if (nDistance == 0)
1033cdf0e10cSrcweir         return 0;
1034cdf0e10cSrcweir     else
1035cdf0e10cSrcweir     {
1036cdf0e10cSrcweir         const awt::Rectangle aWindowBox (mxWindow->getPosSize());
1037cdf0e10cSrcweir         const double nBarHeight (aWindowBox.Height);
1038cdf0e10cSrcweir         const double nPagerWidth (aWindowBox.Width - 2*nBarHeight);
1039cdf0e10cSrcweir         const double nDragDistance (mnTotalSize / nPagerWidth * nDistance);
1040cdf0e10cSrcweir         if (nDragDistance + mnThumbPosition < 0)
1041cdf0e10cSrcweir             return -mnThumbPosition;
1042cdf0e10cSrcweir         else if (mnThumbPosition + nDragDistance > mnTotalSize-mnThumbSize)
1043cdf0e10cSrcweir             return mnTotalSize-mnThumbSize-mnThumbPosition;
1044cdf0e10cSrcweir         else
1045cdf0e10cSrcweir             return nDragDistance;
1046cdf0e10cSrcweir     }
1047cdf0e10cSrcweir }
1048cdf0e10cSrcweir 
1049cdf0e10cSrcweir 
1050cdf0e10cSrcweir 
1051cdf0e10cSrcweir 
1052cdf0e10cSrcweir void PresenterHorizontalScrollBar::UpdateDragAnchor (const double nDragDistance)
1053cdf0e10cSrcweir {
1054cdf0e10cSrcweir     const awt::Rectangle aWindowBox (mxWindow->getPosSize());
1055cdf0e10cSrcweir         const double nBarHeight (aWindowBox.Height);
1056cdf0e10cSrcweir         const double nPagerWidth (aWindowBox.Width - 2*nBarHeight);
1057cdf0e10cSrcweir     maDragAnchor.X += nDragDistance * nPagerWidth /  mnTotalSize;
1058cdf0e10cSrcweir }
1059cdf0e10cSrcweir 
1060cdf0e10cSrcweir 
1061cdf0e10cSrcweir 
1062cdf0e10cSrcweir 
1063cdf0e10cSrcweir sal_Int32 PresenterHorizontalScrollBar::GetSize (void) const
1064cdf0e10cSrcweir {
1065cdf0e10cSrcweir     return mnScrollBarHeight;
1066cdf0e10cSrcweir }
1067cdf0e10cSrcweir 
1068cdf0e10cSrcweir 
1069cdf0e10cSrcweir 
1070cdf0e10cSrcweir 
1071cdf0e10cSrcweir 
1072cdf0e10cSrcweir geometry::RealPoint2D PresenterHorizontalScrollBar::GetPoint (
1073cdf0e10cSrcweir     const double nMajor, const double nMinor) const
1074cdf0e10cSrcweir {
1075cdf0e10cSrcweir     return geometry::RealPoint2D(nMajor, nMinor);
1076cdf0e10cSrcweir }
1077cdf0e10cSrcweir 
1078cdf0e10cSrcweir 
1079cdf0e10cSrcweir 
1080cdf0e10cSrcweir 
1081cdf0e10cSrcweir double PresenterHorizontalScrollBar::GetMajor (const double nX, const double nY) const
1082cdf0e10cSrcweir {
1083cdf0e10cSrcweir     (void)nY;
1084cdf0e10cSrcweir     return nX;
1085cdf0e10cSrcweir }
1086cdf0e10cSrcweir 
1087cdf0e10cSrcweir 
1088cdf0e10cSrcweir 
1089cdf0e10cSrcweir 
1090cdf0e10cSrcweir double PresenterHorizontalScrollBar::GetMinor (const double nX, const double nY) const
1091cdf0e10cSrcweir {
1092cdf0e10cSrcweir     (void)nX;
1093cdf0e10cSrcweir     return nY;
1094cdf0e10cSrcweir }
1095cdf0e10cSrcweir 
1096cdf0e10cSrcweir 
1097cdf0e10cSrcweir 
1098cdf0e10cSrcweir 
1099cdf0e10cSrcweir void PresenterHorizontalScrollBar::UpdateBorders (void)
1100cdf0e10cSrcweir {
1101cdf0e10cSrcweir     const awt::Rectangle aWindowBox (mxWindow->getPosSize());
1102cdf0e10cSrcweir     double nRight = aWindowBox.Width;
1103cdf0e10cSrcweir     const double nGap (2);
1104cdf0e10cSrcweir 
1105cdf0e10cSrcweir     if (mpNextButtonDescriptor.get() != NULL)
1106cdf0e10cSrcweir     {
1107cdf0e10cSrcweir         Reference<rendering::XBitmap> xBitmap (mpNextButtonDescriptor->GetNormalBitmap());
1108cdf0e10cSrcweir         if (xBitmap.is())
1109cdf0e10cSrcweir         {
1110cdf0e10cSrcweir             geometry::IntegerSize2D aSize (xBitmap->getSize());
1111cdf0e10cSrcweir             maBox[NextButton] = geometry::RealRectangle2D(
1112cdf0e10cSrcweir                 nRight - aSize.Width,0, nRight, aWindowBox.Height);
1113cdf0e10cSrcweir             nRight -= aSize.Width + nGap;
1114cdf0e10cSrcweir         }
1115cdf0e10cSrcweir     }
1116cdf0e10cSrcweir     if (mpPrevButtonDescriptor.get() != NULL)
1117cdf0e10cSrcweir     {
1118cdf0e10cSrcweir         Reference<rendering::XBitmap> xBitmap (mpPrevButtonDescriptor->GetNormalBitmap());
1119cdf0e10cSrcweir         if (xBitmap.is())
1120cdf0e10cSrcweir         {
1121cdf0e10cSrcweir             geometry::IntegerSize2D aSize (xBitmap->getSize());
1122cdf0e10cSrcweir             maBox[PrevButton] = geometry::RealRectangle2D(
1123cdf0e10cSrcweir                 nRight - aSize.Width,0, nRight, aWindowBox.Height);
1124cdf0e10cSrcweir             nRight -= aSize.Width + nGap;
1125cdf0e10cSrcweir         }
1126cdf0e10cSrcweir     }
1127cdf0e10cSrcweir 
1128cdf0e10cSrcweir     const double nPagerWidth (nRight);
1129cdf0e10cSrcweir     maBox[Pager] = geometry::RealRectangle2D(
1130cdf0e10cSrcweir         0,0, nRight, aWindowBox.Height);
1131cdf0e10cSrcweir     if (mnTotalSize == 0)
1132cdf0e10cSrcweir     {
1133cdf0e10cSrcweir         maBox[Thumb] = maBox[Pager];
1134cdf0e10cSrcweir 
1135cdf0e10cSrcweir         // Set up the enabled/disabled states.
1136cdf0e10cSrcweir         maEnabledState[PrevButton] = false;
1137cdf0e10cSrcweir         maEnabledState[PagerUp] = false;
1138cdf0e10cSrcweir         maEnabledState[NextButton] = false;
1139cdf0e10cSrcweir         maEnabledState[PagerDown] = false;
1140cdf0e10cSrcweir         maEnabledState[Thumb] = false;
1141cdf0e10cSrcweir     }
1142cdf0e10cSrcweir     else
1143cdf0e10cSrcweir     {
1144cdf0e10cSrcweir         const double nThumbSize = ::std::min(mnThumbSize,mnTotalSize);
1145cdf0e10cSrcweir         const double nThumbPosition = ::std::min(::std::max(0.0,mnThumbPosition), mnTotalSize - nThumbSize);
1146cdf0e10cSrcweir         maBox[Thumb] = geometry::RealRectangle2D(
1147cdf0e10cSrcweir             (nThumbPosition) / mnTotalSize * nPagerWidth, 0,
1148cdf0e10cSrcweir             (nThumbPosition+nThumbSize) / mnTotalSize * nPagerWidth, aWindowBox.Height);
1149cdf0e10cSrcweir 
1150cdf0e10cSrcweir         // Set up the enabled/disabled states.
1151cdf0e10cSrcweir         maEnabledState[PrevButton] = nThumbPosition>0;
1152cdf0e10cSrcweir         maEnabledState[PagerUp] = nThumbPosition>0;
1153cdf0e10cSrcweir         maEnabledState[NextButton] = nThumbPosition+nThumbSize < mnTotalSize;
1154cdf0e10cSrcweir         maEnabledState[PagerDown] = nThumbPosition+nThumbSize < mnTotalSize;
1155cdf0e10cSrcweir         maEnabledState[Thumb] = nThumbSize < mnTotalSize;
1156cdf0e10cSrcweir     }
1157cdf0e10cSrcweir     maBox[PagerUp] = geometry::RealRectangle2D(
1158cdf0e10cSrcweir         maBox[Pager].X1, maBox[Pager].Y1, maBox[Thumb].X1-1, maBox[Pager].Y2);
1159cdf0e10cSrcweir     maBox[PagerDown] = geometry::RealRectangle2D(
1160cdf0e10cSrcweir         maBox[Thumb].X2+1, maBox[Pager].Y1, maBox[Pager].X2, maBox[Pager].Y2);
1161cdf0e10cSrcweir     maBox[Total] = PresenterGeometryHelper::Union(
1162cdf0e10cSrcweir         PresenterGeometryHelper::Union(maBox[PrevButton], maBox[NextButton]),
1163cdf0e10cSrcweir         maBox[Pager]);
1164cdf0e10cSrcweir }
1165cdf0e10cSrcweir 
1166cdf0e10cSrcweir 
1167cdf0e10cSrcweir 
1168cdf0e10cSrcweir 
1169cdf0e10cSrcweir void PresenterHorizontalScrollBar::UpdateBitmaps (void)
1170cdf0e10cSrcweir {
1171cdf0e10cSrcweir     if (mpBitmaps.get() != NULL)
1172cdf0e10cSrcweir     {
1173cdf0e10cSrcweir         mpPrevButtonDescriptor = mpBitmaps->GetBitmap(A2S("Left"));
1174cdf0e10cSrcweir         mpNextButtonDescriptor = mpBitmaps->GetBitmap(A2S("Right"));
1175cdf0e10cSrcweir         mpPagerStartDescriptor = mpBitmaps->GetBitmap(A2S("PagerLeft"));
1176cdf0e10cSrcweir         mpPagerCenterDescriptor = mpBitmaps->GetBitmap(A2S("PagerHorizontal"));
1177cdf0e10cSrcweir         mpPagerEndDescriptor = mpBitmaps->GetBitmap(A2S("PagerRight"));
1178cdf0e10cSrcweir         mpThumbStartDescriptor = mpBitmaps->GetBitmap(A2S("ThumbLeft"));
1179cdf0e10cSrcweir         mpThumbCenterDescriptor = mpBitmaps->GetBitmap(A2S("ThumbHorizontal"));
1180cdf0e10cSrcweir         mpThumbEndDescriptor = mpBitmaps->GetBitmap(A2S("ThumbRight"));
1181cdf0e10cSrcweir 
1182cdf0e10cSrcweir         mnScrollBarHeight = 0;
1183cdf0e10cSrcweir         UpdateWidthOrHeight(mnScrollBarHeight, mpPrevButtonDescriptor);
1184cdf0e10cSrcweir         UpdateWidthOrHeight(mnScrollBarHeight, mpNextButtonDescriptor);
1185cdf0e10cSrcweir         UpdateWidthOrHeight(mnScrollBarHeight, mpPagerStartDescriptor);
1186cdf0e10cSrcweir         UpdateWidthOrHeight(mnScrollBarHeight, mpPagerCenterDescriptor);
1187cdf0e10cSrcweir         UpdateWidthOrHeight(mnScrollBarHeight, mpPagerEndDescriptor);
1188cdf0e10cSrcweir         UpdateWidthOrHeight(mnScrollBarHeight, mpThumbStartDescriptor);
1189cdf0e10cSrcweir         UpdateWidthOrHeight(mnScrollBarHeight, mpThumbCenterDescriptor);
1190cdf0e10cSrcweir         UpdateWidthOrHeight(mnScrollBarHeight, mpThumbEndDescriptor);
1191cdf0e10cSrcweir         if (mnScrollBarHeight == 0)
1192cdf0e10cSrcweir             mnScrollBarHeight = 20;
1193cdf0e10cSrcweir     }
1194cdf0e10cSrcweir }
1195cdf0e10cSrcweir 
1196cdf0e10cSrcweir 
1197cdf0e10cSrcweir 
1198cdf0e10cSrcweir void PresenterHorizontalScrollBar::PaintComposite(
1199cdf0e10cSrcweir     const css::awt::Rectangle& rUpdateBox,
1200cdf0e10cSrcweir     const Area eArea,
1201cdf0e10cSrcweir     const SharedBitmapDescriptor& rpStartBitmaps,
1202cdf0e10cSrcweir     const SharedBitmapDescriptor& rpCenterBitmaps,
1203cdf0e10cSrcweir     const SharedBitmapDescriptor& rpEndBitmaps)
1204cdf0e10cSrcweir {
1205cdf0e10cSrcweir     const awt::Rectangle aWindowBox (mxWindow->getPosSize());
1206cdf0e10cSrcweir     geometry::RealRectangle2D aBox (GetRectangle(eArea));
1207cdf0e10cSrcweir     aBox.X1 += aWindowBox.X;
1208cdf0e10cSrcweir     aBox.Y1 += aWindowBox.Y;
1209cdf0e10cSrcweir     aBox.X2 += aWindowBox.X;
1210cdf0e10cSrcweir     aBox.Y2 += aWindowBox.Y;
1211cdf0e10cSrcweir 
1212cdf0e10cSrcweir     PresenterUIPainter::PaintHorizontalBitmapComposite(
1213cdf0e10cSrcweir         mxCanvas,
1214cdf0e10cSrcweir         rUpdateBox,
1215cdf0e10cSrcweir         PresenterGeometryHelper::ConvertRectangle(aBox),
1216cdf0e10cSrcweir         GetBitmap(eArea, rpStartBitmaps),
1217cdf0e10cSrcweir         GetBitmap(eArea, rpCenterBitmaps),
1218cdf0e10cSrcweir         GetBitmap(eArea, rpEndBitmaps));
1219cdf0e10cSrcweir }
1220cdf0e10cSrcweir 
1221cdf0e10cSrcweir 
1222cdf0e10cSrcweir 
1223cdf0e10cSrcweir 
1224cdf0e10cSrcweir //===== PresenterScrollBar::MousePressRepeater ================================
1225cdf0e10cSrcweir 
1226cdf0e10cSrcweir PresenterScrollBar::MousePressRepeater::MousePressRepeater (
1227cdf0e10cSrcweir     const ::rtl::Reference<PresenterScrollBar>& rpScrollBar)
1228cdf0e10cSrcweir     : mnMousePressRepeaterTaskId(PresenterTimer::NotAValidTaskId),
1229cdf0e10cSrcweir       mpScrollBar(rpScrollBar),
1230cdf0e10cSrcweir       meMouseArea(PresenterScrollBar::None)
1231cdf0e10cSrcweir {
1232cdf0e10cSrcweir }
1233cdf0e10cSrcweir 
1234cdf0e10cSrcweir 
1235cdf0e10cSrcweir 
1236cdf0e10cSrcweir 
1237cdf0e10cSrcweir void PresenterScrollBar::MousePressRepeater::Dispose (void)
1238cdf0e10cSrcweir {
1239cdf0e10cSrcweir     Stop();
1240cdf0e10cSrcweir     mpScrollBar = NULL;
1241cdf0e10cSrcweir }
1242cdf0e10cSrcweir 
1243cdf0e10cSrcweir 
1244cdf0e10cSrcweir 
1245cdf0e10cSrcweir 
1246cdf0e10cSrcweir void PresenterScrollBar::MousePressRepeater::Start (const PresenterScrollBar::Area& reArea)
1247cdf0e10cSrcweir {
1248cdf0e10cSrcweir     meMouseArea = reArea;
1249cdf0e10cSrcweir 
1250cdf0e10cSrcweir     if (mnMousePressRepeaterTaskId == PresenterTimer::NotAValidTaskId)
1251cdf0e10cSrcweir     {
1252cdf0e10cSrcweir         // Execute key press operation at least this one time.
1253cdf0e10cSrcweir         Execute();
1254cdf0e10cSrcweir 
1255cdf0e10cSrcweir         // Schedule repeated executions.
1256cdf0e10cSrcweir         mnMousePressRepeaterTaskId = PresenterTimer::ScheduleRepeatedTask (
1257cdf0e10cSrcweir             ::boost::bind(&PresenterScrollBar::MousePressRepeater::Callback, shared_from_this(), _1),
1258cdf0e10cSrcweir             500000000,
1259cdf0e10cSrcweir             250000000);
1260cdf0e10cSrcweir     }
1261cdf0e10cSrcweir     else
1262cdf0e10cSrcweir     {
1263cdf0e10cSrcweir         // There is already an active repeating task.
1264cdf0e10cSrcweir     }
1265cdf0e10cSrcweir }
1266cdf0e10cSrcweir 
1267cdf0e10cSrcweir 
1268cdf0e10cSrcweir 
1269cdf0e10cSrcweir 
1270cdf0e10cSrcweir void PresenterScrollBar::MousePressRepeater::Stop (void)
1271cdf0e10cSrcweir {
1272cdf0e10cSrcweir     if (mnMousePressRepeaterTaskId != PresenterTimer::NotAValidTaskId)
1273cdf0e10cSrcweir     {
1274cdf0e10cSrcweir         const sal_Int32 nTaskId (mnMousePressRepeaterTaskId);
1275cdf0e10cSrcweir         mnMousePressRepeaterTaskId = PresenterTimer::NotAValidTaskId;
1276cdf0e10cSrcweir         PresenterTimer::CancelTask(nTaskId);
1277cdf0e10cSrcweir     }
1278cdf0e10cSrcweir }
1279cdf0e10cSrcweir 
1280cdf0e10cSrcweir 
1281cdf0e10cSrcweir 
1282cdf0e10cSrcweir 
1283cdf0e10cSrcweir void PresenterScrollBar::MousePressRepeater::SetMouseArea(const PresenterScrollBar::Area& reArea)
1284cdf0e10cSrcweir {
1285cdf0e10cSrcweir     if (meMouseArea != reArea)
1286cdf0e10cSrcweir     {
1287cdf0e10cSrcweir         if (mnMousePressRepeaterTaskId != PresenterTimer::NotAValidTaskId)
1288cdf0e10cSrcweir         {
1289cdf0e10cSrcweir             Stop();
1290cdf0e10cSrcweir         }
1291cdf0e10cSrcweir     }
1292cdf0e10cSrcweir }
1293cdf0e10cSrcweir 
1294cdf0e10cSrcweir 
1295cdf0e10cSrcweir 
1296cdf0e10cSrcweir 
1297cdf0e10cSrcweir void PresenterScrollBar::MousePressRepeater::Callback (const TimeValue& rCurrentTime)
1298cdf0e10cSrcweir {
1299cdf0e10cSrcweir     (void)rCurrentTime;
1300cdf0e10cSrcweir 
1301cdf0e10cSrcweir     if (mpScrollBar.get() == NULL)
1302cdf0e10cSrcweir     {
1303cdf0e10cSrcweir         Stop();
1304cdf0e10cSrcweir         return;
1305cdf0e10cSrcweir     }
1306cdf0e10cSrcweir 
1307cdf0e10cSrcweir     Execute();
1308cdf0e10cSrcweir }
1309cdf0e10cSrcweir 
1310cdf0e10cSrcweir 
1311cdf0e10cSrcweir 
1312cdf0e10cSrcweir 
1313cdf0e10cSrcweir void PresenterScrollBar::MousePressRepeater::Execute (void)
1314cdf0e10cSrcweir {
1315cdf0e10cSrcweir     const double nThumbPosition (mpScrollBar->GetThumbPosition());
1316cdf0e10cSrcweir     switch (meMouseArea)
1317cdf0e10cSrcweir     {
1318cdf0e10cSrcweir         case PrevButton:
1319cdf0e10cSrcweir             mpScrollBar->SetThumbPosition(nThumbPosition - mpScrollBar->GetLineHeight(), true);
1320cdf0e10cSrcweir             break;
1321cdf0e10cSrcweir 
1322cdf0e10cSrcweir         case NextButton:
1323cdf0e10cSrcweir             mpScrollBar->SetThumbPosition(nThumbPosition + mpScrollBar->GetLineHeight(), true);
1324cdf0e10cSrcweir             break;
1325cdf0e10cSrcweir 
1326cdf0e10cSrcweir         case PagerUp:
1327cdf0e10cSrcweir             mpScrollBar->SetThumbPosition(nThumbPosition - mpScrollBar->GetThumbSize()*0.8, true);
1328cdf0e10cSrcweir             break;
1329cdf0e10cSrcweir 
1330cdf0e10cSrcweir         case PagerDown:
1331cdf0e10cSrcweir             mpScrollBar->SetThumbPosition(nThumbPosition + mpScrollBar->GetThumbSize()*0.8, true);
1332cdf0e10cSrcweir             break;
1333cdf0e10cSrcweir 
1334cdf0e10cSrcweir         default:
1335cdf0e10cSrcweir             break;
1336cdf0e10cSrcweir     }
1337cdf0e10cSrcweir }
1338cdf0e10cSrcweir 
1339cdf0e10cSrcweir 
1340cdf0e10cSrcweir 
1341cdf0e10cSrcweir } } // end of namespace ::sdext::presenter
1342