]> git.sesse.net Git - vlc/blob - modules/gui/skins2/controls/ctrl_tree.hpp
* all: new handling of vout controls to allow serveral layouts/windows
[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., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, 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, tree_update*>,
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                   VarBool *pFlat );
55         virtual ~CtrlTree();
56
57         /// Handle an event on the control
58         virtual void handleEvent( EvtGeneric &rEvent );
59
60         /// Check whether coordinates are inside the control
61         virtual bool mouseOver( int x, int y ) const;
62
63         /// Draw the control on the given graphics
64         virtual void draw( OSGraphics &rImage, int xDest, int yDest );
65
66         /// Called when the layout is resized
67         virtual void onResize();
68
69         /// Return true if the control can gain the focus
70         virtual bool isFocusable() const { return true; }
71
72         /// Get the type of control (custom RTTI)
73         virtual string getType() const { return "tree"; }
74
75         /// Make sure an item is visible
76         /// \param item an iterator to a tree item
77         /// \return true if it changed the position
78         bool ensureVisible( VarTree::Iterator item );
79
80         /// Make sure an item is visible
81         /// \param itemIndex the absolute index in the tree
82         /// \return true if it changed the position
83         bool ensureVisible( int itemIndex );
84
85     private:
86         /// Tree associated to the control
87         VarTree &m_rTree;
88         /// Font
89         const GenericFont &m_rFont;
90         /// Background bitmap
91         const GenericBitmap *m_pBgBitmap;
92         /// Item (leaf) bitmap
93         // (TODO : add different bitmaps for different item types
94         //         like in the wx playlist)
95         const GenericBitmap *m_pItemBitmap;
96         /// Open (expanded) node bitmap
97         const GenericBitmap *m_pOpenBitmap;
98         /// Closed node bitmap
99         const GenericBitmap *m_pClosedBitmap;
100         /// Color of normal test
101         uint32_t m_fgColor;
102         /// Color of the playing item
103         uint32_t m_playColor;
104         /// Background colors, used when no background bitmap is given
105         uint32_t m_bgColor1, m_bgColor2;
106         /// Background of selected items
107         uint32_t m_selColor;
108         /// Pointer on the last selected item in the tree
109         VarTree *m_pLastSelected;
110         /// Image of the control
111         OSGraphics *m_pImage;
112         /// First item in the visible area
113         VarTree::Iterator m_firstPos;
114
115         /// Don't move if the position variable is updated
116         bool m_dontMove;
117
118         /// Do we want to "flaten" the tree ?
119         bool m_flat;
120
121         /// Method called when the tree variable is modified
122         virtual void onUpdate( Subject<VarTree, tree_update*> &rTree ,
123                                tree_update *);
124
125         // Method called when the position variable of the tree is modified
126         virtual void onUpdate( Subject<VarPercent, void *> &rPercent , void *);
127
128         /// Called when the position is set
129         virtual void onPositionChange();
130
131         /// Compute the number of lines that can be displayed
132         int maxItems();
133
134         /// Compute the item's height (depends on fonts and images used)
135         int itemHeight();
136
137         /// Compute the width of an item's bitmap
138         int itemImageWidth();
139
140         /// Check if the tree must be scrolled
141         void autoScroll();
142
143         /// Draw the image of the control
144         void makeImage();
145
146         /// Return the n'th displayed item (starting at position 0)
147         /**
148          *  Return m_rTree.end() if such an item cannot be found (n < 0, or
149          *  n too big)
150          */
151         VarTree::Iterator findItemAtPos( int n );
152 };
153
154 #endif