]> git.sesse.net Git - vlc/blob - modules/gui/skins2/controls/ctrl_tree.hpp
e8f13f5ee0143eee9defbd8bfe566601f581c48d
[vlc] / modules / gui / skins2 / controls / ctrl_tree.hpp
1 /*****************************************************************************
2  * ctrl_tree.hpp
3  *****************************************************************************
4  * Copyright (C) 2003 VideoLAN
5  * $Id$
6  *
7  * Authors: Antoine Cellerier
8  *
9  * This program is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation; either version 2 of the License, or
12  * (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program; if not, write to the Free Software
21  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
22  *****************************************************************************/
23
24 #ifndef CTRL_TREE_HPP
25 #define CTRL_TREE_HPP
26
27 #include "ctrl_generic.hpp"
28 #include "../utils/observer.hpp"
29 #include "../utils/var_tree.hpp"
30
31 class OSGraphics;
32 class GenericFont;
33 class GenericBitmap;
34
35 /// Class for control tree
36 class CtrlTree: public CtrlGeneric, public Observer<VarTree, int>,
37     public Observer<VarPercent, void*>
38 {
39     public:
40         CtrlTree( intf_thread_t *pIntf,
41                   VarTree &rTree,
42                   const GenericFont &rFont,
43                   const GenericBitmap *pBgBitmap,
44                   const GenericBitmap *pItemBitmap,
45                   const GenericBitmap *pOpenBitmap,
46                   const GenericBitmap *pClosedBitmap,
47                   uint32_t fgColor,
48                   uint32_t playColor,
49                   uint32_t bgColor1,
50                   uint32_t bgColor2,
51                   uint32_t selColor,
52                   const UString &rHelp,
53                   VarBool *pVisible );
54         virtual ~CtrlTree();
55
56         /// Handle an event on the control
57         virtual void handleEvent( EvtGeneric &rEvent );
58
59         /// Check whether coordinates are inside the control
60         virtual bool mouseOver( int x, int y ) const;
61
62         /// Draw the control on the given graphics
63         virtual void draw( OSGraphics &rImage, int xDest, int yDest );
64
65         /// Called when the layout is resized
66         virtual void onResize();
67
68         /// Return true if the control can gain the focus
69         virtual bool isFocusable() const { return true; }
70
71         /// Get the type of control (custom RTTI)
72         virtual string getType() const { return "tree"; }
73
74     private:
75         /// Tree associated to the control
76         VarTree &m_rTree;
77         /// Font
78         const GenericFont &m_rFont;
79         /// Background bitmap
80         const GenericBitmap *m_pBgBitmap;
81         /// Item (leaf) bitmap
82         // (TODO : add different bitmaps for different item types
83         //         like in the wx playlist)
84         const GenericBitmap *m_pItemBitmap;
85         /// Open (expanded) node bitmap
86         const GenericBitmap *m_pOpenBitmap;
87         /// Closed node bitmap
88         const GenericBitmap *m_pClosedBitmap;
89         /// Color of normal test
90         uint32_t m_fgColor;
91         /// Color of the playing item
92         uint32_t m_playColor;
93         /// Background colors, used when no background bitmap is given
94         uint32_t m_bgColor1, m_bgColor2;
95         /// Background of selected items
96         uint32_t m_selColor;
97         /// Pointer on the last selected item in the tree
98         VarTree *m_pLastSelected;
99         /// Image of the control
100         OSGraphics *m_pImage;
101         /// Last position
102         VarTree::Iterator m_lastPos;
103
104         /// Method called when the tree variable is modified
105         virtual void onUpdate( Subject<VarTree, int> &rTree , int);
106
107         // Method called when the position variable of the tree is modified
108         virtual void onUpdate( Subject<VarPercent, void *> &rPercent , void *);
109
110         /// Called when the position is set
111         virtual void onPositionChange();
112
113         /// Compute the number of lines that can be displayed
114         int maxItems();
115
116         /// Compute the item's height (depends on fonts and images used)
117         int itemHeight();
118
119         /// Compute the width of an item's bitmap
120         int itemImageWidth();
121
122         /// Check if the tree must be scrolled
123         void autoScroll();
124
125         /// Draw the image of the control
126         void makeImage();
127
128         /// Return the n'th displayed item (starting at position 0)
129         /**
130          *  Return m_rTree.end() if such an item cannot be found (n < 0, or
131          *  n too big)
132          */
133         VarTree::Iterator findItemAtPos( int n );
134 };
135
136 #endif