ctrl_generic.hpp

Go to the documentation of this file.
00001 /*****************************************************************************
00002  * ctrl_generic.hpp
00003  *****************************************************************************
00004  * Copyright (C) 2003 the VideoLAN team
00005  * $Id: d1decf734f1bfb83110929063107a72c219567ca $
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_GENERIC_HPP
00026 #define CTRL_GENERIC_HPP
00027 
00028 #include "../src/skin_common.hpp"
00029 #include "../utils/pointer.hpp"
00030 #include "../utils/ustring.hpp"
00031 #include "../utils/observer.hpp"
00032 #include "../commands/cmd_generic.hpp"
00033 
00034 class Box;
00035 class EvtGeneric;
00036 class OSGraphics;
00037 class GenericLayout;
00038 class Position;
00039 class TopWindow;
00040 class VarBool;
00041 
00042 
00043 /// Base class for controls
00044 class CtrlGeneric: public SkinObject, public Observer<VarBool>
00045 {
00046 public:
00047     virtual ~CtrlGeneric();
00048 
00049     /// Handle an event on the control
00050     virtual void handleEvent( EvtGeneric &rEvent ) { }
00051 
00052     /// Check whether coordinates are inside the control
00053     virtual bool mouseOver( int x, int y ) const { return false; }
00054 
00055     /// Draw the control on the given graphics
00056     virtual void draw( OSGraphics &rImage, int xDest, int yDest ) { }
00057 
00058     /// Set the position and the associated layout of the control
00059     virtual void setLayout( GenericLayout *pLayout,
00060                             const Position &rPosition );
00061     virtual void unsetLayout();
00062 
00063     /// Get the position of the control in the layout, if any
00064     virtual const Position *getPosition() const { return m_pPosition; }
00065 
00066     /// Get the text of the tooltip
00067     virtual UString getTooltipText() const
00068         { return UString( getIntf(), "" ); }
00069 
00070     /**
00071      * Overload this method if you want to do something special when
00072      * the layout is resized
00073      */
00074     virtual void onResize() { }
00075 
00076     /// Get the help text
00077     virtual const UString &getHelpText() const { return m_help; }
00078 
00079     /// Return true if the control can gain the focus
00080     virtual bool isFocusable() const { return false; }
00081 
00082     /// Return true if the control is visible
00083     virtual bool isVisible() const;
00084 
00085     /// Get the type of control (custom RTTI)
00086     virtual string getType() const { return ""; }
00087 
00088 protected:
00089     // If pVisible is NULL, the control is always visible
00090     CtrlGeneric( intf_thread_t *pIntf, const UString &rHelp,
00091                  VarBool *pVisible = NULL );
00092 
00093     /**
00094      * Tell the layout when the image has changed, with the size of the
00095      * rectangle to repaint and its offset.
00096      * Use the default values to repaint the whole window
00097      */
00098     virtual void notifyLayout( int witdh = -1, int height = -1,
00099                                int xOffSet = 0, int yOffSet = 0 ) const;
00100 
00101     /**
00102      * Same as notifyLayout(), but takes optional images as parameters.
00103      * The maximum size(s) of the images will be used for repainting.
00104      */
00105     void notifyLayoutMaxSize( const Box *pImg1 = NULL,
00106                               const Box *pImg2 = NULL );
00107 
00108     /// Ask the layout to capture the mouse
00109     virtual void captureMouse() const;
00110 
00111     /// Ask the layout to release the mouse
00112     virtual void releaseMouse() const;
00113 
00114     /// Notify the window the tooltip has changed
00115     virtual void notifyTooltipChange() const;
00116 
00117     /// Get the associated window, if any
00118     virtual TopWindow *getWindow() const;
00119 
00120     /**
00121      * Overload this method if you want to do something special when
00122      * the Position object is set
00123      */
00124     virtual void onPositionChange() { }
00125 
00126     /// Overload this method to get notified of bool variable changes
00127     virtual void onVarBoolUpdate( VarBool &rVar ) { }
00128 
00129     /// Method called when an observed bool variable is changed
00130     virtual void onUpdate( Subject<VarBool> &rVariable , void* );
00131 
00132     /// Associated layout
00133     GenericLayout *m_pLayout;
00134 
00135     /// Visibility variable
00136     VarBool *m_pVisible;
00137 
00138 private:
00139     /// Position in the layout
00140     Position *m_pPosition;
00141     /// Help text
00142     UString m_help;
00143 
00144 };
00145 
00146 typedef CountedPtr<CtrlGeneric> CtrlGenericPtr;
00147 
00148 
00149 #endif

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