ctrl_checkbox.hpp

Go to the documentation of this file.
00001 /*****************************************************************************
00002  * ctrl_checkbox.hpp
00003  *****************************************************************************
00004  * Copyright (C) 2003 the VideoLAN team
00005  * $Id: 7342bf0ae0e9b9ae8ad4ecb72ff36c19873ba75b $
00006  *
00007  * Authors: Cyril Deguet     <asmax@via.ecp.fr>
00008  *          Olivier Teulière <ipkiss@via.ecp.fr>
00009  *
00010  * This program is free software; you can redistribute it and/or modify
00011  * it under the terms of the GNU General Public License as published by
00012  * the Free Software Foundation; either version 2 of the License, or
00013  * (at your option) any later version.
00014  *
00015  * This program is distributed in the hope that it will be useful,
00016  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00017  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00018  * GNU General Public License for more details.
00019  *
00020  * You should have received a copy of the GNU General Public License along
00021  * with this program; if not, write to the Free Software Foundation, Inc.,
00022  * 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
00023  *****************************************************************************/
00024 
00025 #ifndef CTRL_CHECKBOX_HPP
00026 #define CTRL_CHECKBOX_HPP
00027 
00028 #include "ctrl_generic.hpp"
00029 #include "../utils/fsm.hpp"
00030 #include "../utils/observer.hpp"
00031 #include "../src/anim_bitmap.hpp"
00032 
00033 class GenericBitmap;
00034 class OSGraphics;
00035 class CmdGeneric;
00036 
00037 
00038 /// Base class for checkbox controls
00039 class CtrlCheckbox: public CtrlGeneric, public Observer<AnimBitmap>
00040 {
00041 public:
00042     /// Create a checkbox with 6 images
00043     CtrlCheckbox( intf_thread_t *pIntf,
00044                   const GenericBitmap &rBmpUp1,
00045                   const GenericBitmap &rBmpOver1,
00046                   const GenericBitmap &rBmpDown1,
00047                   const GenericBitmap &rBmpUp2,
00048                   const GenericBitmap &rBmpOver2,
00049                   const GenericBitmap &rBmpDown2,
00050                   CmdGeneric &rCommand1, CmdGeneric &rCommand2,
00051                   const UString &rTooltip1, const UString &rTooltip2,
00052                   VarBool &rVariable, const UString &rHelp,
00053                   VarBool *pVisible);
00054 
00055     virtual ~CtrlCheckbox();
00056 
00057     /// Handle an event
00058     virtual void handleEvent( EvtGeneric &rEvent );
00059 
00060     /// Check whether coordinates are inside the control
00061     virtual bool mouseOver( int x, int y ) const;
00062 
00063     /// Draw the control on the given graphics
00064     virtual void draw( OSGraphics &rImage, int xDest, int yDest );
00065 
00066     /// Get the text of the tooltip XXX
00067     virtual UString getTooltipText() const { return *m_pTooltip; }
00068 
00069     /// Get the type of control (custom RTTI)
00070     virtual string getType() const { return "checkbox"; }
00071 
00072 private:
00073     /// Finite state machine of the control
00074     FSM m_fsm;
00075     /// Observed variable
00076     VarBool &m_rVariable;
00077     /// Commands for the 2 states
00078     CmdGeneric &m_rCommand1, &m_rCommand2;
00079     /// Current command
00080     CmdGeneric *m_pCommand;
00081     /// Tooltip texts for the 2 states
00082     const UString m_tooltip1, m_tooltip2;
00083     /// Current tooltip
00084     const UString *m_pTooltip;
00085      /// Images of the checkbox in the different states
00086     AnimBitmap m_imgUp1, m_imgOver1, m_imgDown1;
00087     AnimBitmap m_imgUp2, m_imgOver2, m_imgDown2;
00088     /// Current set of images (pointing to 1 or 2)
00089     /// In fact, we consider here that a checkbox acts like 2 buttons, in a
00090     /// symetric way; this is a small trick to avoid multiplicating the
00091     /// callbacks (and it could be extended easily to support 3 buttons or
00092     /// more...)
00093     AnimBitmap *m_pImgUp, *m_pImgOver, *m_pImgDown;
00094     /// Current image
00095     AnimBitmap *m_pImgCurrent;
00096 
00097     /// Callback objects
00098     DEFINE_CALLBACK( CtrlCheckbox, UpOverDownOver )
00099     DEFINE_CALLBACK( CtrlCheckbox, DownOverUpOver )
00100     DEFINE_CALLBACK( CtrlCheckbox, DownOverDown )
00101     DEFINE_CALLBACK( CtrlCheckbox, DownDownOver )
00102     DEFINE_CALLBACK( CtrlCheckbox, UpOverUp )
00103     DEFINE_CALLBACK( CtrlCheckbox, UpUpOver )
00104     DEFINE_CALLBACK( CtrlCheckbox, DownUp )
00105     DEFINE_CALLBACK( CtrlCheckbox, UpHidden )
00106     DEFINE_CALLBACK( CtrlCheckbox, HiddenUp )
00107 
00108     /// Method called when the observed variable is modified
00109     virtual void onVarBoolUpdate( VarBool &rVariable );
00110 
00111     /// Method called when an animated bitmap changes
00112     virtual void onUpdate( Subject<AnimBitmap> &rBitmap, void* );
00113 
00114     /// Change the current image
00115     void setImage( AnimBitmap *pImg );
00116 
00117     /// Helper function to update the current state of images
00118     void changeButton();
00119 };
00120 
00121 
00122 #endif

Generated on Tue May 25 08:04:58 2010 for VLC by  doxygen 1.5.6