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