1 /*****************************************************************************
3 *****************************************************************************
4 * Copyright (C) 2003 the VideoLAN team
7 * Authors: Cyril Deguet <asmax@via.ecp.fr>
8 * Olivier Teulière <ipkiss@via.ecp.fr>
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License along
21 * with this program; if not, write to the Free Software Foundation, Inc.,
22 * 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
23 *****************************************************************************/
25 #ifndef CTRL_CHECKBOX_HPP
26 #define CTRL_CHECKBOX_HPP
28 #include "ctrl_generic.hpp"
29 #include "../utils/fsm.hpp"
30 #include "../utils/observer.hpp"
31 #include "../src/anim_bitmap.hpp"
38 /// Base class for checkbox controls
39 class CtrlCheckbox: public CtrlGeneric, public Observer<AnimBitmap>
42 /// Create a checkbox with 6 images
43 CtrlCheckbox( intf_thread_t *pIntf,
44 const GenericBitmap &rBmpUp1,
45 const GenericBitmap &rBmpOver1,
46 const GenericBitmap &rBmpDown1,
47 const GenericBitmap &rBmpUp2,
48 const GenericBitmap &rBmpOver2,
49 const GenericBitmap &rBmpDown2,
50 CmdGeneric &rCommand1, CmdGeneric &rCommand2,
51 const UString &rTooltip1, const UString &rTooltip2,
52 VarBool &rVariable, const UString &rHelp,
55 virtual ~CtrlCheckbox();
58 virtual void handleEvent( EvtGeneric &rEvent );
60 /// Check whether coordinates are inside the control
61 virtual bool mouseOver( int x, int y ) const;
63 /// Draw the control on the given graphics
64 virtual void draw( OSGraphics &rImage, int xDest, int yDest, int w, int h );
66 /// Get the text of the tooltip XXX
67 virtual UString getTooltipText() const { return *m_pTooltip; }
69 /// Get the type of control (custom RTTI)
70 virtual string getType() const { return "checkbox"; }
73 /// Finite state machine of the control
77 /// Commands for the 2 states
78 CmdGeneric &m_rCommand1, &m_rCommand2;
80 CmdGeneric *m_pCommand;
81 /// Tooltip texts for the 2 states
82 const UString m_tooltip1, m_tooltip2;
84 const UString *m_pTooltip;
85 /// Images of the checkbox in the different states
86 AnimBitmap m_imgUp1, m_imgOver1, m_imgDown1;
87 AnimBitmap m_imgUp2, m_imgOver2, m_imgDown2;
88 /// Current set of images (pointing to 1 or 2)
89 /// In fact, we consider here that a checkbox acts like 2 buttons, in a
90 /// symetric way; this is a small trick to avoid multiplicating the
91 /// callbacks (and it could be extended easily to support 3 buttons or
93 AnimBitmap *m_pImgUp, *m_pImgOver, *m_pImgDown;
95 AnimBitmap *m_pImgCurrent;
98 DEFINE_CALLBACK( CtrlCheckbox, UpOverDownOver )
99 DEFINE_CALLBACK( CtrlCheckbox, DownOverUpOver )
100 DEFINE_CALLBACK( CtrlCheckbox, DownOverDown )
101 DEFINE_CALLBACK( CtrlCheckbox, DownDownOver )
102 DEFINE_CALLBACK( CtrlCheckbox, UpOverUp )
103 DEFINE_CALLBACK( CtrlCheckbox, UpUpOver )
104 DEFINE_CALLBACK( CtrlCheckbox, DownUp )
105 DEFINE_CALLBACK( CtrlCheckbox, UpHidden )
106 DEFINE_CALLBACK( CtrlCheckbox, HiddenUp )
108 /// Method called when the observed variable is modified
109 virtual void onVarBoolUpdate( VarBool &rVariable );
111 /// Method called when an animated bitmap changes
112 virtual void onUpdate( Subject<AnimBitmap> &rBitmap, void* );
114 /// Change the current image
115 void setImage( AnimBitmap *pImg );
117 /// Helper function to update the current state of images