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 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 *****************************************************************************/
25 #ifndef CTRL_GENERIC_HPP
26 #define CTRL_GENERIC_HPP
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"
43 /// Base class for controls
44 class CtrlGeneric: public SkinObject, public Observer<VarBool>
47 virtual ~CtrlGeneric();
49 /// Handle an event on the control
50 virtual void handleEvent( EvtGeneric &rEvent ) { (void)rEvent; }
52 /// Check whether coordinates are inside the control
53 virtual bool mouseOver( int x, int y ) const
54 { (void)x; (void)y; return false; }
56 /// Draw the control on the given graphics
57 virtual void draw( OSGraphics &rImage, int xDest,
58 int yDest, int w, int h ) = 0;
60 /// Set the position and the associated layout of the control
61 virtual void setLayout( GenericLayout *pLayout,
62 const Position &rPosition );
63 virtual void unsetLayout();
65 /// Get the position of the control in the layout, if any
66 virtual const Position *getPosition() const { return m_pPosition; }
68 /// Get the text of the tooltip
69 virtual UString getTooltipText() const
70 { return UString( getIntf(), "" ); }
73 * Overload this method if you want to do something special when
74 * the layout is resized
76 virtual void onResize() { }
79 virtual const UString &getHelpText() const { return m_help; }
81 /// Return true if the control can gain the focus
82 virtual bool isFocusable() const { return false; }
84 /// Return true if the control can be scrollable
85 virtual bool isScrollable() const { return false; }
87 /// Return true if the control is visible
88 virtual bool isVisible() const;
90 /// Get the type of control (custom RTTI)
91 virtual string getType() const { return ""; }
94 // If pVisible is NULL, the control is always visible
95 CtrlGeneric( intf_thread_t *pIntf, const UString &rHelp,
96 VarBool *pVisible = NULL );
99 * Tell the layout when the image has changed, with the size of the
100 * rectangle to repaint and its offset.
101 * Use the default values to repaint the whole window
103 virtual void notifyLayout( int witdh = -1, int height = -1,
104 int xOffSet = 0, int yOffSet = 0 );
107 * Same as notifyLayout(), but takes optional images as parameters.
108 * The maximum size(s) of the images will be used for repainting.
110 void notifyLayoutMaxSize( const Box *pImg1 = NULL,
111 const Box *pImg2 = NULL );
113 /// Ask the layout to capture the mouse
114 virtual void captureMouse() const;
116 /// Ask the layout to release the mouse
117 virtual void releaseMouse() const;
119 /// Notify the window the tooltip has changed
120 virtual void notifyTooltipChange() const;
122 /// Get the associated window, if any
123 virtual TopWindow *getWindow() const;
126 * Overload this method if you want to do something special when
127 * the Position object is set
129 virtual void onPositionChange() { }
131 /// Overload this method to get notified of bool variable changes
132 virtual void onVarBoolUpdate( VarBool &rVar ) { (void)rVar; }
134 /// Method called when an observed bool variable is changed
135 virtual void onUpdate( Subject<VarBool> &rVariable , void* );
137 /// Associated layout
138 GenericLayout *m_pLayout;
140 /// Visibility variable
144 /// Position in the layout
145 Position *m_pPosition;
151 typedef CountedPtr<CtrlGeneric> CtrlGenericPtr;