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
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, 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"
37 /// Base class for checkbox controls
38 class CtrlCheckbox: public CtrlGeneric
41 /// Create a checkbox with 6 images
42 CtrlCheckbox( intf_thread_t *pIntf,
43 const GenericBitmap &rBmpUp1,
44 const GenericBitmap &rBmpOver1,
45 const GenericBitmap &rBmpDown1,
46 const GenericBitmap &rBmpUp2,
47 const GenericBitmap &rBmpOver2,
48 const GenericBitmap &rBmpDown2,
49 CmdGeneric &rCommand1, CmdGeneric &rCommand2,
50 const UString &rTooltip1, const UString &rTooltip2,
51 VarBool &rVariable, const UString &rHelp,
54 virtual ~CtrlCheckbox();
57 virtual void handleEvent( EvtGeneric &rEvent );
59 /// Check whether coordinates are inside the control
60 virtual bool mouseOver( int x, int y ) const;
62 /// Draw the control on the given graphics
63 virtual void draw( OSGraphics &rImage, int xDest, int yDest );
65 /// Get the text of the tooltip XXX
66 virtual UString getTooltipText() const { return *m_pTooltip; }
68 /// Get the type of control (custom RTTI)
69 virtual string getType() const { return "checkbox"; }
72 /// Finite state machine of the control
76 /// Commands for the 2 states
77 CmdGeneric &m_rCommand1, &m_rCommand2;
79 CmdGeneric *m_pCommand;
80 /// Tooltip texts for the 2 states
81 const UString m_tooltip1, m_tooltip2;
83 const UString *m_pTooltip;
84 /// Images of the checkbox in the different states
85 OSGraphics *m_pImgUp1, *m_pImgOver1, *m_pImgDown1;
86 OSGraphics *m_pImgUp2, *m_pImgOver2, *m_pImgDown2;
87 /// Current set of images (pointing to 1 or 2)
88 /// In fact, we consider here that a checkbox acts like 2 buttons, in a
89 /// symetric way; this is a small trick to avoid multiplicating the
90 /// callbacks (and it could be extended easily to support 3 buttons or
92 OSGraphics *m_pImgUp, *m_pImgOver, *m_pImgDown;
94 OSGraphics *m_pImgCurrent;
97 DEFINE_CALLBACK( CtrlCheckbox, UpOverDownOver )
98 DEFINE_CALLBACK( CtrlCheckbox, DownOverUpOver )
99 DEFINE_CALLBACK( CtrlCheckbox, DownOverDown )
100 DEFINE_CALLBACK( CtrlCheckbox, DownDownOver )
101 DEFINE_CALLBACK( CtrlCheckbox, UpOverUp )
102 DEFINE_CALLBACK( CtrlCheckbox, UpUpOver )
103 DEFINE_CALLBACK( CtrlCheckbox, DownUp )
104 DEFINE_CALLBACK( CtrlCheckbox, UpHidden )
105 DEFINE_CALLBACK( CtrlCheckbox, HiddenUp )
107 /// Method called when the observed variable is modified
108 virtual void onVarBoolUpdate( VarBool &rVariable );
110 /// Helper function to update the current state of images