]> git.sesse.net Git - vlc/blob - modules/gui/skins2/controls/ctrl_generic.hpp
551fd2eb0a986e13ca204fa26051baa6e152486b
[vlc] / modules / gui / skins2 / controls / ctrl_generic.hpp
1 /*****************************************************************************
2  * ctrl_generic.hpp
3  *****************************************************************************
4  * Copyright (C) 2003 the VideoLAN team
5  * $Id$
6  *
7  * Authors: Cyril Deguet     <asmax@via.ecp.fr>
8  *          Olivier Teulière <ipkiss@via.ecp.fr>
9  *
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.
14  *
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.
19  *
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  *****************************************************************************/
24
25 #ifndef CTRL_GENERIC_HPP
26 #define CTRL_GENERIC_HPP
27
28 #include "../src/skin_common.hpp"
29 #include "../utils/pointer.hpp"
30 #include "../utils/ustring.hpp"
31 #include "../utils/observer.hpp"
32 #include "../commands/cmd_generic.hpp"
33
34 class EvtGeneric;
35 class OSGraphics;
36 class GenericLayout;
37 class Position;
38 class TopWindow;
39 class VarBool;
40
41
42 /// Base class for controls
43 class CtrlGeneric: public SkinObject, public Observer<VarBool>
44 {
45     public:
46         virtual ~CtrlGeneric();
47
48         /// Handle an event on the control
49         virtual void handleEvent( EvtGeneric &rEvent ) {}
50
51         /// Check whether coordinates are inside the control
52         virtual bool mouseOver( int x, int y ) const { return false; }
53
54         /// Draw the control on the given graphics
55         virtual void draw( OSGraphics &rImage, int xDest, int yDest ) {}
56
57         /// Set the position and the associated layout of the control
58         virtual void setLayout( GenericLayout *pLayout,
59                                 const Position &rPosition );
60
61         /// Get the position of the control in the layout, if any
62         virtual const Position *getPosition() const { return m_pPosition; }
63
64         /// Get the text of the tooltip
65         virtual UString getTooltipText() const
66             { return UString( getIntf(), "" ); }
67
68         /// Overload this method if you want to do something special when
69         /// the layout is resized
70         virtual void onResize() {}
71
72         /// Get the help text
73         virtual const UString &getHelpText() const { return m_help; }
74
75         /// Return true if the control can gain the focus
76         virtual bool isFocusable() const { return false; }
77
78         /// Return true if the control is visible
79         virtual bool isVisible() const;
80
81         /// Get the type of control (custom RTTI)
82         virtual string getType() const { return ""; }
83
84     protected:
85         // If pVisible is NULL, the control is always visible
86         CtrlGeneric( intf_thread_t *pIntf, const UString &rHelp,
87                      VarBool *pVisible = NULL );
88
89         /// Tell the layout when the image has changed, with the size of the
90         /// rectangle to repaint and its offset.
91         /// Use the default values to repaint the whole window
92         virtual void notifyLayout( int witdh = -1, int height = -1,
93                                    int xOffSet = 0, int yOffSet = 0 ) const;
94
95         /// Same as notifyLayout(), but takes optional images as parameters.
96         /// The maximum size(s) of the images will be used for repainting.
97         void notifyLayoutMaxSize( const OSGraphics *pImg1 = NULL,
98                                   const OSGraphics *pImg2 = NULL );
99
100         /// Ask the layout to capture the mouse
101         virtual void captureMouse() const;
102
103         /// Ask the layout to release the mouse
104         virtual void releaseMouse() const;
105
106         /// Notify the window the tooltip has changed
107         virtual void notifyTooltipChange() const;
108
109         /// Get the associated window, if any
110         virtual TopWindow *getWindow() const;
111
112         /// Overload this method if you want to do something special when
113         /// the Position object is set
114         virtual void onPositionChange() {}
115
116         /// Overload this method to get notified of bool variable changes
117         virtual void onVarBoolUpdate( VarBool &rVar ) {}
118
119     private:
120         /// Associated layout
121         GenericLayout *m_pLayout;
122         /// Position in the layout
123         Position *m_pPosition;
124         /// Help text
125         UString m_help;
126         /// Visibilty variable
127         VarBool *m_pVisible;
128
129         /// Method called when an observed bool variable is changed
130         virtual void onUpdate( Subject<VarBool> &rVariable );
131 };
132
133 typedef CountedPtr<CtrlGeneric> CtrlGenericPtr;
134
135
136 #endif