1 /*****************************************************************************
3 *****************************************************************************
4 * Copyright (C) 2003 VideoLAN
7 * Authors: Antoine Cellerier
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.
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.
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 *****************************************************************************/
27 #include "ctrl_generic.hpp"
28 #include "../utils/observer.hpp"
29 #include "../utils/var_tree.hpp"
35 /// Class for control tree
36 class CtrlTree: public CtrlGeneric, public Observer<VarTree, tree_update*>,
37 public Observer<VarPercent, void*>
40 CtrlTree( intf_thread_t *pIntf,
42 const GenericFont &rFont,
43 const GenericBitmap *pBgBitmap,
44 const GenericBitmap *pItemBitmap,
45 const GenericBitmap *pOpenBitmap,
46 const GenericBitmap *pClosedBitmap,
57 /// Handle an event on the control
58 virtual void handleEvent( EvtGeneric &rEvent );
60 /// Check whether coordinates are inside the control
61 virtual bool mouseOver( int x, int y ) const;
63 /// Draw the control on the given graphics
64 virtual void draw( OSGraphics &rImage, int xDest, int yDest );
66 /// Called when the layout is resized
67 virtual void onResize();
69 /// Return true if the control can gain the focus
70 virtual bool isFocusable() const { return true; }
72 /// Get the type of control (custom RTTI)
73 virtual string getType() const { return "tree"; }
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 );
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 );
86 /// Tree associated to the control
89 const GenericFont &m_rFont;
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
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
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;
115 /// Don't move if the position variable is updated
118 /// Do we want to "flaten" the tree ?
121 /// Method called when the tree variable is modified
122 virtual void onUpdate( Subject<VarTree, tree_update*> &rTree ,
125 // Method called when the position variable of the tree is modified
126 virtual void onUpdate( Subject<VarPercent, void *> &rPercent , void *);
128 /// Called when the position is set
129 virtual void onPositionChange();
131 /// Compute the number of lines that can be displayed
134 /// Compute the item's height (depends on fonts and images used)
137 /// Compute the width of an item's bitmap
138 int itemImageWidth();
140 /// Check if the tree must be scrolled
143 /// Draw the image of the control
146 /// Return the n'th displayed item (starting at position 0)
148 * Return m_rTree.end() if such an item cannot be found (n < 0, or
151 VarTree::Iterator findItemAtPos( int n );