1 /*****************************************************************************
3 *****************************************************************************
4 * Copyright (C) 2003 the VideoLAN team
7 * Authors: Antoine Cellerier <dionoea@videolan.org>
8 * Clément Stenac <zorglub@videolan.org>
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 *****************************************************************************/
28 #include "ctrl_generic.hpp"
29 #include "../utils/observer.hpp"
30 #include "../utils/var_tree.hpp"
36 /// Class for control tree
37 class CtrlTree: public CtrlGeneric, public Observer<VarTree, tree_update>,
38 public Observer<VarPercent>
41 CtrlTree( intf_thread_t *pIntf,
43 const GenericFont &rFont,
44 const GenericBitmap *pBgBitmap,
45 const GenericBitmap *pItemBitmap,
46 const GenericBitmap *pOpenBitmap,
47 const GenericBitmap *pClosedBitmap,
58 /// Handle an event on the control
59 virtual void handleEvent( EvtGeneric &rEvent );
61 /// Check whether coordinates are inside the control
62 virtual bool mouseOver( int x, int y ) const;
64 /// Draw the control on the given graphics
65 virtual void draw( OSGraphics &rImage, int xDest, int yDest, int w, int h );
67 /// Called when the layout is resized
68 virtual void onResize();
70 /// Return true if the control can gain the focus
71 virtual bool isFocusable() const { return true; }
73 /// Get the type of control (custom RTTI)
74 virtual string getType() const { return "tree"; }
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 );
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 );
87 /// Tree associated to the control
90 const GenericFont &m_rFont;
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
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
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;
116 /// Don't move if the position variable is updated
119 /// Do we want to "flaten" the tree ?
122 /// Method called when the tree variable is modified
123 virtual void onUpdate( Subject<VarTree, tree_update> &rTree ,
126 // Method called when the position variable of the tree is modified
127 virtual void onUpdate( Subject<VarPercent> &rPercent , void *);
129 /// Called when the position is set
130 virtual void onPositionChange();
132 /// Compute the number of lines that can be displayed
135 /// Compute the item's height (depends on fonts and images used)
138 /// Compute the width of an item's bitmap
139 int itemImageWidth();
141 /// Check if the tree must be scrolled
144 /// Draw the image of the control
147 /// Return the n'th displayed item (starting at position 0)
149 * Return m_rTree.end() if such an item cannot be found (n < 0, or
152 VarTree::Iterator findItemAtPos( int n );