ctrl_generic.hpp 4.81 KB
Newer Older
1 2 3
/*****************************************************************************
 * ctrl_generic.hpp
 *****************************************************************************
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 11 12 13 14 15 16 17 18 19 20 21
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
Antoine Cellerier's avatar
Antoine Cellerier committed
22
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
23 24 25 26 27 28 29 30
 *****************************************************************************/

#ifndef CTRL_GENERIC_HPP
#define CTRL_GENERIC_HPP

#include "../src/skin_common.hpp"
#include "../utils/pointer.hpp"
#include "../utils/ustring.hpp"
31
#include "../utils/observer.hpp"
32
#include "../commands/cmd_generic.hpp"
33

34
class Box;
35 36 37 38
class EvtGeneric;
class OSGraphics;
class GenericLayout;
class Position;
39
class TopWindow;
40
class VarBool;
41 42 43


/// Base class for controls
44
class CtrlGeneric: public SkinObject, public Observer<VarBool, void*>
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78
{
    public:
        virtual ~CtrlGeneric();

        /// Handle an event on the control
        virtual void handleEvent( EvtGeneric &rEvent ) {}

        /// Check whether coordinates are inside the control
        virtual bool mouseOver( int x, int y ) const { return false; }

        /// Draw the control on the given graphics
        virtual void draw( OSGraphics &rImage, int xDest, int yDest ) {}

        /// Set the position and the associated layout of the control
        virtual void setLayout( GenericLayout *pLayout,
                                const Position &rPosition );

        /// Get the position of the control in the layout, if any
        virtual const Position *getPosition() const { return m_pPosition; }

        /// Get the text of the tooltip
        virtual UString getTooltipText() const
            { return UString( getIntf(), "" ); }

        /// Overload this method if you want to do something special when
        /// the layout is resized
        virtual void onResize() {}

        /// Get the help text
        virtual const UString &getHelpText() const { return m_help; }

        /// Return true if the control can gain the focus
        virtual bool isFocusable() const { return false; }

79 80 81
        /// Return true if the control is visible
        virtual bool isVisible() const;

82 83 84
        /// Get the type of control (custom RTTI)
        virtual string getType() const { return ""; }

85
    protected:
86 87 88
        // If pVisible is NULL, the control is always visible
        CtrlGeneric( intf_thread_t *pIntf, const UString &rHelp,
                     VarBool *pVisible = NULL );
89

90
        /// Tell the layout when the image has changed, with the size of the
91 92 93 94
        /// rectangle to repaint and its offset.
        /// Use the default values to repaint the whole window
        virtual void notifyLayout( int witdh = -1, int height = -1,
                                   int xOffSet = 0, int yOffSet = 0 ) const;
95 96 97

        /// Same as notifyLayout(), but takes optional images as parameters.
        /// The maximum size(s) of the images will be used for repainting.
98 99
        void notifyLayoutMaxSize( const Box *pImg1 = NULL,
                                  const Box *pImg2 = NULL );
100 101 102 103 104 105 106 107 108 109 110

        /// Ask the layout to capture the mouse
        virtual void captureMouse() const;

        /// Ask the layout to release the mouse
        virtual void releaseMouse() const;

        /// Notify the window the tooltip has changed
        virtual void notifyTooltipChange() const;

        /// Get the associated window, if any
111
        virtual TopWindow *getWindow() const;
112 113 114 115 116

        /// Overload this method if you want to do something special when
        /// the Position object is set
        virtual void onPositionChange() {}

117 118 119
        /// Overload this method to get notified of bool variable changes
        virtual void onVarBoolUpdate( VarBool &rVar ) {}

120 121 122 123 124 125 126
    private:
        /// Associated layout
        GenericLayout *m_pLayout;
        /// Position in the layout
        Position *m_pPosition;
        /// Help text
        UString m_help;
127 128 129 130
        /// Visibilty variable
        VarBool *m_pVisible;

        /// Method called when an observed bool variable is changed
131
        virtual void onUpdate( Subject<VarBool, void*> &rVariable , void* );
132 133 134 135 136 137
};

typedef CountedPtr<CtrlGeneric> CtrlGenericPtr;


#endif