]> git.sesse.net Git - vlc/blob - modules/gui/skins2/controls/ctrl_tree.hpp
Layout for album art
[vlc] / modules / gui / skins2 / controls / ctrl_tree.hpp
1 /*****************************************************************************
2  * ctrl_tree.hpp
3  *****************************************************************************
4  * Copyright (C) 2003 the VideoLAN team
5  * $Id$
6  *
7  * Authors: Antoine Cellerier <dionoea@videolan.org>
8  *          ClĂ©ment Stenac <zorglub@videolan.org>
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
21  * along with this program; if not, write to the Free Software
22  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
23  *****************************************************************************/
24
25 #ifndef CTRL_TREE_HPP
26 #define CTRL_TREE_HPP
27
28 #include "ctrl_generic.hpp"
29 #include "../utils/observer.hpp"
30 #include "../utils/var_tree.hpp"
31
32 class OSGraphics;
33 class GenericFont;
34 class GenericBitmap;
35
36 /// Class for control tree
37 class CtrlTree: public CtrlGeneric, public Observer<VarTree, tree_update>,
38     public Observer<VarPercent>
39 {
40     public:
41         CtrlTree( intf_thread_t *pIntf,
42                   VarTree &rTree,
43                   const GenericFont &rFont,
44                   const GenericBitmap *pBgBitmap,
45                   const GenericBitmap *pItemBitmap,
46                   const GenericBitmap *pOpenBitmap,
47                   const GenericBitmap *pClosedBitmap,
48                   uint32_t fgColor,
49                   uint32_t playColor,
50                   uint32_t bgColor1,
51                   uint32_t bgColor2,
52                   uint32_t selColor,
53                   const UString &rHelp,
54                   VarBool *pVisible,
55                   VarBool *pFlat );
56         virtual ~CtrlTree();
57
58         /// Handle an event on the control
59         virtual void handleEvent( EvtGeneric &rEvent );
60
61         /// Check whether coordinates are inside the control
62         virtual bool mouseOver( int x, int y ) const;
63
64         /// Draw the control on the given graphics
65         virtual void draw( OSGraphics &rImage, int xDest, int yDest );
66
67         /// Called when the layout is resized
68         virtual void onResize();
69
70         /// Return true if the control can gain the focus
71         virtual bool isFocusable() const { return true; }
72
73         /// Get the type of control (custom RTTI)
74         virtual string getType() const { return "tree"; }
75
76         /// Make sure an item is visible
77         /// \param item an iterator to a tree item
78         /// \return true if it changed the position
79         bool ensureVisible( VarTree::Iterator item );
80
81         /// Make sure an item is visible
82         /// \param itemIndex the absolute index in the tree
83         /// \return true if it changed the position
84         bool ensureVisible( int itemIndex );
85
86     private:
87         /// Tree associated to the control
88         VarTree &m_rTree;
89         /// Font
90         const GenericFont &m_rFont;
91         /// Background bitmap
92         const GenericBitmap *m_pBgBitmap;
93         /// Item (leaf) bitmap
94         // (TODO : add different bitmaps for different item types
95         //         like in the wx playlist)
96         const GenericBitmap *m_pItemBitmap;
97         /// Open (expanded) node bitmap
98         const GenericBitmap *m_pOpenBitmap;
99         /// Closed node bitmap
100         const GenericBitmap *m_pClosedBitmap;
101         /// Color of normal test
102         uint32_t m_fgColor;
103         /// Color of the playing item
104         uint32_t m_playColor;
105         /// Background colors, used when no background bitmap is given
106         uint32_t m_bgColor1, m_bgColor2;
107         /// Background of selected items
108         uint32_t m_selColor;
109         /// Pointer on the last selected item in the tree
110         VarTree *m_pLastSelected;
111         /// Image of the control
112         OSGraphics *m_pImage;
113         /// First item in the visible area
114         VarTree::Iterator m_firstPos;
115
116         /// Don't move if the position variable is updated
117         bool m_dontMove;
118
119         /// Do we want to "flaten" the tree ?
120         bool m_flat;
121
122         /// Method called when the tree variable is modified
123         virtual void onUpdate( Subject<VarTree, tree_update> &rTree ,
124                                tree_update *);
125
126         // Method called when the position variable of the tree is modified
127         virtual void onUpdate( Subject<VarPercent> &rPercent , void *);
128
129         /// Called when the position is set
130         virtual void onPositionChange();
131
132         /// Compute the number of lines that can be displayed
133         int maxItems();
134
135         /// Compute the item's height (depends on fonts and images used)
136         int itemHeight();
137
138         /// Compute the width of an item's bitmap
139         int itemImageWidth();
140
141         /// Check if the tree must be scrolled
142         void autoScroll();
143
144         /// Draw the image of the control
145         void makeImage();
146
147         /// Return the n'th displayed item (starting at position 0)
148         /**
149          *  Return m_rTree.end() if such an item cannot be found (n < 0, or
150          *  n too big)
151          */
152         VarTree::Iterator findItemAtPos( int n );
153 };
154
155 #endif