1c45d927aSAndrew Rist /**************************************************************
2*b7d2c847Smseidel  *
3c45d927aSAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4c45d927aSAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5c45d927aSAndrew Rist  * distributed with this work for additional information
6c45d927aSAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7c45d927aSAndrew Rist  * to you under the Apache License, Version 2.0 (the
8c45d927aSAndrew Rist  * "License"); you may not use this file except in compliance
9c45d927aSAndrew Rist  * with the License.  You may obtain a copy of the License at
10*b7d2c847Smseidel  *
11c45d927aSAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*b7d2c847Smseidel  *
13c45d927aSAndrew Rist  * Unless required by applicable law or agreed to in writing,
14c45d927aSAndrew Rist  * software distributed under the License is distributed on an
15c45d927aSAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16c45d927aSAndrew Rist  * KIND, either express or implied.  See the License for the
17c45d927aSAndrew Rist  * specific language governing permissions and limitations
18c45d927aSAndrew Rist  * under the License.
19*b7d2c847Smseidel  *
20c45d927aSAndrew Rist  *************************************************************/
21c45d927aSAndrew Rist 
22c45d927aSAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir #ifndef SD_SLIDESORTER_VIEW_BUTTON_BAR_HXX
25cdf0e10cSrcweir #define SD_SLIDESORTER_VIEW_BUTTON_BAR_HXX
26cdf0e10cSrcweir 
27cdf0e10cSrcweir #include "model/SlsSharedPageDescriptor.hxx"
28cdf0e10cSrcweir #include <tools/gen.hxx>
29cdf0e10cSrcweir #include <rtl/ustring.hxx>
30cdf0e10cSrcweir #include <vcl/bitmapex.hxx>
31cdf0e10cSrcweir #include <vcl/bmpacc.hxx>
32cdf0e10cSrcweir #include <boost/scoped_ptr.hpp>
33cdf0e10cSrcweir 
34cdf0e10cSrcweir namespace sd { namespace slidesorter {
35cdf0e10cSrcweir class SlideSorter;
36cdf0e10cSrcweir } }
37cdf0e10cSrcweir 
38cdf0e10cSrcweir 
39cdf0e10cSrcweir namespace sd { namespace slidesorter { namespace view {
40cdf0e10cSrcweir 
41cdf0e10cSrcweir class Theme;
42cdf0e10cSrcweir 
43cdf0e10cSrcweir class Button;
44cdf0e10cSrcweir typedef ::boost::shared_ptr<Button> SharedButton;
45cdf0e10cSrcweir 
46cdf0e10cSrcweir /** This is a container of buttons and a coordinating controller.
47cdf0e10cSrcweir     The last means that it receives mouse events and forwards them to
48cdf0e10cSrcweir     the right button.
49cdf0e10cSrcweir */
50cdf0e10cSrcweir class ButtonBar
51cdf0e10cSrcweir {
52cdf0e10cSrcweir public:
53cdf0e10cSrcweir     ButtonBar (SlideSorter& rSlideSorter);
54cdf0e10cSrcweir     ~ButtonBar (void);
55cdf0e10cSrcweir 
56cdf0e10cSrcweir     void ProcessButtonDownEvent (
57cdf0e10cSrcweir         const model::SharedPageDescriptor& rpDescriptor,
58cdf0e10cSrcweir         const Point aMouseModelLocation);
59cdf0e10cSrcweir     void ProcessButtonUpEvent (
60cdf0e10cSrcweir         const model::SharedPageDescriptor& rpDescriptor,
61cdf0e10cSrcweir         const Point aMouseModelLocation);
62cdf0e10cSrcweir     void ProcessMouseMotionEvent (
63cdf0e10cSrcweir         const model::SharedPageDescriptor& rpDescriptor,
64cdf0e10cSrcweir         const Point aMouseModelLocation,
65cdf0e10cSrcweir         const bool bIsMouseButtonDown);
66*b7d2c847Smseidel 
67cdf0e10cSrcweir     void ResetPage (void);
68cdf0e10cSrcweir 
69cdf0e10cSrcweir     /** Return the number of buttons that are to be displayed in page
70cdf0e10cSrcweir         objects which the mouse hovers over.
71cdf0e10cSrcweir         @param bIsExcluded
72cdf0e10cSrcweir             When this flag is <TRUE/> then return the number of
73cdf0e10cSrcweir             buttons that is to be displayed for pages that are
74cdf0e10cSrcweir             excluded from the slide show.
75cdf0e10cSrcweir     */
76cdf0e10cSrcweir     sal_Int32 GetButtonCount (const bool bIsExcluded) const;
77*b7d2c847Smseidel 
78cdf0e10cSrcweir     /** Return the specified button.
79cdf0e10cSrcweir         @param nIndex
80cdf0e10cSrcweir             Valid values lie in the range [0,GetButtonCount()).
81cdf0e10cSrcweir         @param bIsExcluded
82cdf0e10cSrcweir             When this flag is <TRUE/> then return a button that is to
83cdf0e10cSrcweir             be displayed for pages that are excluded from the slide
84cdf0e10cSrcweir             show.
85cdf0e10cSrcweir         @return
86cdf0e10cSrcweir             Returns an empty pointer when the given index is not valid.
87cdf0e10cSrcweir     */
88cdf0e10cSrcweir     ::boost::shared_ptr<Button> GetButton (
89cdf0e10cSrcweir         const bool bIsExcluded,
90cdf0e10cSrcweir         const sal_Int32 nIndex) const;
91cdf0e10cSrcweir 
92cdf0e10cSrcweir     bool IsMouseOverBar (void) const;
93cdf0e10cSrcweir 
94cdf0e10cSrcweir     /** Paint the specified page object.  When this is not the same as the
95cdf0e10cSrcweir         one under the mouse (mpDescriptor) then the buttons are all
96cdf0e10cSrcweir         painted in their normal state.
97cdf0e10cSrcweir     */
98cdf0e10cSrcweir     void Paint (
99cdf0e10cSrcweir         OutputDevice& rDevice,
100cdf0e10cSrcweir         const model::SharedPageDescriptor& rpPageDescriptor);
101cdf0e10cSrcweir 
102cdf0e10cSrcweir     bool IsMouseOverButton (void) const;
103cdf0e10cSrcweir 
104cdf0e10cSrcweir     void RequestLayout (void);
105cdf0e10cSrcweir 
106cdf0e10cSrcweir     /** Return the help text for the button under the mouse.
107cdf0e10cSrcweir         @return
108cdf0e10cSrcweir             When the mouse is not over a button then an empty string
109cdf0e10cSrcweir             is returned.
110cdf0e10cSrcweir     */
111cdf0e10cSrcweir     ::rtl::OUString GetButtonHelpText (void) const;
112cdf0e10cSrcweir 
113cdf0e10cSrcweir     /** Request the button bar to be shown.
114cdf0e10cSrcweir         @param bAnimate
115cdf0e10cSrcweir             This flag controls whether to just show the button bar (<FALSE/>)
116cdf0e10cSrcweir             or to fade it in smoothly (<TRUE/>.)
117cdf0e10cSrcweir     */
118cdf0e10cSrcweir     void RequestFadeIn (
119cdf0e10cSrcweir         const model::SharedPageDescriptor& rpDescriptor,
120cdf0e10cSrcweir         const bool bAnimate);
121cdf0e10cSrcweir 
122cdf0e10cSrcweir     /** Request the button bar to be hidden.
123cdf0e10cSrcweir         @param bAnimate
124cdf0e10cSrcweir             This flag controls whether to just hide the button bar (<FALSE/>)
125cdf0e10cSrcweir             or to fade it out smoothly (<TRUE/>.)
126cdf0e10cSrcweir     */
127cdf0e10cSrcweir     void RequestFadeOut (
128cdf0e10cSrcweir         const model::SharedPageDescriptor& rpDescriptor,
129cdf0e10cSrcweir         const bool bAnimate);
130cdf0e10cSrcweir 
131*b7d2c847Smseidel     /** Return whether the button bar is visible for the given descriptor (or
132*b7d2c847Smseidel         being faded in).
133cdf0e10cSrcweir     */
134cdf0e10cSrcweir     bool IsVisible (const model::SharedPageDescriptor& rpDescriptor);
135cdf0e10cSrcweir 
136cdf0e10cSrcweir     void HandleDataChangeEvent (void);
137cdf0e10cSrcweir 
138cdf0e10cSrcweir     class BackgroundTheme;
139cdf0e10cSrcweir 
140cdf0e10cSrcweir     /** While at least one Lock object exists the button bar will not be
141cdf0e10cSrcweir         displayed.  Used, e.g. during a mouse multiselection to avoid
142*b7d2c847Smseidel         confusing and unhelpful visual signals.
143cdf0e10cSrcweir     */
144cdf0e10cSrcweir     class Lock
145cdf0e10cSrcweir     {
146cdf0e10cSrcweir     public:
147cdf0e10cSrcweir         Lock (SlideSorter& rSlideSorter);
148cdf0e10cSrcweir         ~Lock (void);
149cdf0e10cSrcweir     private:
150cdf0e10cSrcweir         ButtonBar& mrButtonBar;
151cdf0e10cSrcweir     };
152*b7d2c847Smseidel 
153cdf0e10cSrcweir private:
154cdf0e10cSrcweir     SlideSorter& mrSlideSorter;
155cdf0e10cSrcweir     Size maPageObjectSize;
156cdf0e10cSrcweir     Rectangle maButtonBoundingBox;
157cdf0e10cSrcweir     Point maBackgroundLocation;
158cdf0e10cSrcweir     model::SharedPageDescriptor mpDescriptor;
159cdf0e10cSrcweir     bool mbIsExcluded;
160cdf0e10cSrcweir     boost::shared_ptr<Button> mpButtonUnderMouse;
161cdf0e10cSrcweir     // The button on which the mouse button was pressed.
162cdf0e10cSrcweir     boost::shared_ptr<Button> mpDownButton;
163cdf0e10cSrcweir     ::std::vector<SharedButton> maRegularButtons;
164cdf0e10cSrcweir     ::std::vector<SharedButton> maExcludedButtons;
165cdf0e10cSrcweir     BitmapEx maNormalBackground;
166cdf0e10cSrcweir     BitmapEx maButtonDownBackground;
167cdf0e10cSrcweir     bool mbIsMouseOverBar;
168cdf0e10cSrcweir     ::boost::scoped_ptr<BackgroundTheme> mpBackgroundTheme;
169cdf0e10cSrcweir     int mnLockCount;
170cdf0e10cSrcweir 
171cdf0e10cSrcweir     /** Remember the specified page.  If it differs from mpDescriptor then
172cdf0e10cSrcweir         the buttons are placed anew.
173cdf0e10cSrcweir         @return
17474cbd1f1SMatthias Seidel             The returned flag indicates whether the mpDescriptor member
175cdf0e10cSrcweir             is set to a new value.
176*b7d2c847Smseidel     */
177cdf0e10cSrcweir     bool SetPage (const model::SharedPageDescriptor& rpDescriptor);
178cdf0e10cSrcweir     SharedButton GetButtonAt (const Point aModelLocation);
179cdf0e10cSrcweir     bool SetButtonUnderMouse (const SharedButton& rButton = SharedButton());
180cdf0e10cSrcweir     void PaintButtonBackground (
181cdf0e10cSrcweir         OutputDevice& rDevice,
182cdf0e10cSrcweir         const model::SharedPageDescriptor& rpPageDescriptor,
183cdf0e10cSrcweir         const Point aOffset);
184cdf0e10cSrcweir     void LayoutButtons (const Size aPageModelSize);
185cdf0e10cSrcweir     bool LayoutButtons (void);
186cdf0e10cSrcweir     BitmapEx CreateBackground (
187cdf0e10cSrcweir         const OutputDevice& rTemplateDevice,
188cdf0e10cSrcweir         const bool bIsButtonDown) const;
189cdf0e10cSrcweir     bool IsMouseOverBar (const Point aModelLocation) const;
190cdf0e10cSrcweir     void StartFadeAnimation (
191cdf0e10cSrcweir         const model::SharedPageDescriptor& rpDescriptor,
192cdf0e10cSrcweir         const double nTargetAlpha,
193cdf0e10cSrcweir         const bool bFadeIn);
194cdf0e10cSrcweir 
195cdf0e10cSrcweir     void AcquireLock (void);
196cdf0e10cSrcweir     void ReleaseLock (void);
197cdf0e10cSrcweir };
198cdf0e10cSrcweir 
199cdf0e10cSrcweir 
200cdf0e10cSrcweir 
201cdf0e10cSrcweir 
202cdf0e10cSrcweir class Button
203cdf0e10cSrcweir {
204cdf0e10cSrcweir public:
205cdf0e10cSrcweir     Button (
206cdf0e10cSrcweir         SlideSorter& rSlideSorter,
207cdf0e10cSrcweir         const ::rtl::OUString& rsHelpText);
208cdf0e10cSrcweir     virtual ~Button (void);
209cdf0e10cSrcweir 
210cdf0e10cSrcweir     enum State { State_Normal, State_Hover, State_Down };
211cdf0e10cSrcweir     enum IconSize { IconSize_Large, IconSize_Medium, IconSize_Small };
212cdf0e10cSrcweir 
213cdf0e10cSrcweir     /** Set a new state.
214cdf0e10cSrcweir         @return
215cdf0e10cSrcweir             When the new state is different from the old state
216cdf0e10cSrcweir             then <TRUE/> is returned.
217cdf0e10cSrcweir     */
218cdf0e10cSrcweir     bool SetState (const State eState);
219cdf0e10cSrcweir     State GetState (void) const;
220cdf0e10cSrcweir 
221cdf0e10cSrcweir     virtual void Place (const Rectangle aButtonBarBox) = 0;
222cdf0e10cSrcweir     virtual void Paint (
223cdf0e10cSrcweir         OutputDevice& rDevice,
224cdf0e10cSrcweir         const Point aOffset,
225cdf0e10cSrcweir         const double nAlpha,
226cdf0e10cSrcweir         const ::boost::shared_ptr<Theme>& rpTheme) const = 0;
227cdf0e10cSrcweir     virtual void ProcessClick (const model::SharedPageDescriptor& rpDescriptor) = 0;
228cdf0e10cSrcweir 
229cdf0e10cSrcweir     /** Return the bounding box of the layouted button.
230cdf0e10cSrcweir     */
231cdf0e10cSrcweir     Rectangle GetBoundingBox (void) const;
232cdf0e10cSrcweir     /** Return the minimum size required to completely paint the
233cdf0e10cSrcweir         button.
234cdf0e10cSrcweir     */
235cdf0e10cSrcweir     virtual Size GetSize (void) const = 0;
236cdf0e10cSrcweir     virtual Size GetSize (const IconSize eIconSize) const = 0;
237cdf0e10cSrcweir     ::rtl::OUString GetHelpText (void) const;
238cdf0e10cSrcweir     bool IsDown (void) const;
239cdf0e10cSrcweir     void SetActiveState (const bool bIsActive);
240cdf0e10cSrcweir     bool IsActive (void) const;
241cdf0e10cSrcweir     void SetIconSize (const IconSize eIconSize);
242cdf0e10cSrcweir     IconSize GetIconSize (void) const;
243cdf0e10cSrcweir     /** By default a button is always enabled.  Override to change this.
244cdf0e10cSrcweir     */
245cdf0e10cSrcweir     virtual bool IsEnabled (void) const;
246cdf0e10cSrcweir 
247cdf0e10cSrcweir protected:
248cdf0e10cSrcweir     SlideSorter& mrSlideSorter;
249cdf0e10cSrcweir     State meState;
250cdf0e10cSrcweir     Rectangle maBoundingBox;
251cdf0e10cSrcweir     const ::rtl::OUString msHelpText;
252cdf0e10cSrcweir     // Buttons that lie (partly) outside the button bar are deactivated.
253cdf0e10cSrcweir     bool mbIsActive;
254cdf0e10cSrcweir     IconSize meIconSize;
255cdf0e10cSrcweir };
256cdf0e10cSrcweir 
257cdf0e10cSrcweir 
258cdf0e10cSrcweir 
259cdf0e10cSrcweir class TextButton : public Button
260cdf0e10cSrcweir {
261cdf0e10cSrcweir public:
262cdf0e10cSrcweir     TextButton (
263cdf0e10cSrcweir         SlideSorter& rSlideSorter,
264cdf0e10cSrcweir         const ::rtl::OUString& rsText,
265cdf0e10cSrcweir         const ::rtl::OUString& rsHelpText);
266cdf0e10cSrcweir 
267cdf0e10cSrcweir     virtual void Place (const Rectangle aButtonBarBox);
268cdf0e10cSrcweir     virtual void Paint (
269cdf0e10cSrcweir         OutputDevice& rDevice,
270cdf0e10cSrcweir         const Point aOffset,
271cdf0e10cSrcweir         const double nAlpha,
272cdf0e10cSrcweir         const ::boost::shared_ptr<Theme>& rpTheme) const;
273cdf0e10cSrcweir     virtual Size GetSize (void) const;
274cdf0e10cSrcweir     virtual Size GetSize (const IconSize eIconSize) const;
275cdf0e10cSrcweir 
276cdf0e10cSrcweir private:
277cdf0e10cSrcweir     const ::rtl::OUString msText;
278cdf0e10cSrcweir };
279cdf0e10cSrcweir 
280cdf0e10cSrcweir 
281cdf0e10cSrcweir 
282cdf0e10cSrcweir class ImageButton : public Button
283cdf0e10cSrcweir {
284cdf0e10cSrcweir public:
285cdf0e10cSrcweir     ImageButton (
286cdf0e10cSrcweir         SlideSorter& rSlideSorter,
287cdf0e10cSrcweir         const BitmapEx& rLargeIcon,
288cdf0e10cSrcweir         const BitmapEx& rLargeHoverIcon,
289cdf0e10cSrcweir         const BitmapEx& rMediumIcon,
290cdf0e10cSrcweir         const BitmapEx& rMediumHoverIcon,
291cdf0e10cSrcweir         const BitmapEx& rSmallIcon,
292cdf0e10cSrcweir         const BitmapEx& rSmallHoverIcon,
293cdf0e10cSrcweir         const ::rtl::OUString& rsHelpText);
294cdf0e10cSrcweir 
295cdf0e10cSrcweir     virtual void Place (const Rectangle aButtonBarBox);
296cdf0e10cSrcweir     virtual void Paint (
297cdf0e10cSrcweir         OutputDevice& rDevice,
298cdf0e10cSrcweir         const Point aOffset,
299cdf0e10cSrcweir         const double nAlpha,
300cdf0e10cSrcweir         const ::boost::shared_ptr<Theme>& rpTheme) const;
301cdf0e10cSrcweir     virtual Size GetSize (void) const;
302cdf0e10cSrcweir     virtual Size GetSize (const IconSize eIconSize) const;
303cdf0e10cSrcweir 
304cdf0e10cSrcweir private:
305cdf0e10cSrcweir     const BitmapEx maLargeIcon;
306cdf0e10cSrcweir     const BitmapEx maLargeHoverIcon;
307cdf0e10cSrcweir     const BitmapEx maMediumIcon;
308cdf0e10cSrcweir     const BitmapEx maMediumHoverIcon;
309cdf0e10cSrcweir     const BitmapEx maSmallIcon;
310cdf0e10cSrcweir     const BitmapEx maSmallHoverIcon;
311cdf0e10cSrcweir };
312cdf0e10cSrcweir 
313cdf0e10cSrcweir 
314cdf0e10cSrcweir class UnhideButton : public ImageButton
315cdf0e10cSrcweir {
316cdf0e10cSrcweir public:
317cdf0e10cSrcweir     UnhideButton (SlideSorter& rSlideSorter);
318cdf0e10cSrcweir 
319cdf0e10cSrcweir protected:
320cdf0e10cSrcweir     virtual void ProcessClick (const model::SharedPageDescriptor& rpDescriptor);
321cdf0e10cSrcweir };
322cdf0e10cSrcweir 
323cdf0e10cSrcweir 
324cdf0e10cSrcweir class StartShowButton : public ImageButton
325cdf0e10cSrcweir {
326cdf0e10cSrcweir public:
327cdf0e10cSrcweir     StartShowButton (SlideSorter& rSlideSorter);
328cdf0e10cSrcweir     virtual bool IsEnabled (void) const;
329cdf0e10cSrcweir 
330cdf0e10cSrcweir protected:
331cdf0e10cSrcweir     virtual void ProcessClick (const model::SharedPageDescriptor& rpDescriptor);
332cdf0e10cSrcweir };
333cdf0e10cSrcweir 
334cdf0e10cSrcweir 
335cdf0e10cSrcweir class HideButton : public ImageButton
336cdf0e10cSrcweir {
337cdf0e10cSrcweir public:
338cdf0e10cSrcweir     HideButton (SlideSorter& rSlideSorter);
339cdf0e10cSrcweir 
340cdf0e10cSrcweir protected:
341cdf0e10cSrcweir     virtual void ProcessClick (const model::SharedPageDescriptor& rpDescriptor);
342cdf0e10cSrcweir };
343cdf0e10cSrcweir 
344cdf0e10cSrcweir 
345cdf0e10cSrcweir class DuplicateButton : public ImageButton
346cdf0e10cSrcweir {
347cdf0e10cSrcweir public:
348cdf0e10cSrcweir     DuplicateButton (SlideSorter& rSlideSorter);
349cdf0e10cSrcweir     virtual bool IsEnabled (void) const;
350cdf0e10cSrcweir 
351cdf0e10cSrcweir protected:
352cdf0e10cSrcweir     virtual void ProcessClick (const model::SharedPageDescriptor& rpDescriptor);
353cdf0e10cSrcweir };
354cdf0e10cSrcweir 
355cdf0e10cSrcweir 
356cdf0e10cSrcweir } } } // end of namespace ::sd::slidesorter::view
357cdf0e10cSrcweir 
358cdf0e10cSrcweir #endif
359