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., 59 Temple Place - Suite 330, Boston, MA 02111, 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>,
37 public Observer<VarPercent>
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,
56 /// Handle an event on the control
57 virtual void handleEvent( EvtGeneric &rEvent );
59 /// Check whether coordinates are inside the control
60 virtual bool mouseOver( int x, int y ) const;
62 /// Draw the control on the given graphics
63 virtual void draw( OSGraphics &rImage, int xDest, int yDest );
65 /// Called when the layout is resized
66 virtual void onResize();
68 /// Return true if the control can gain the focus
69 virtual bool isFocusable() const { return true; }
71 /// Get the type of control (custom RTTI)
72 virtual string getType() const { return "tree"; }
75 /// Tree associated to the control
78 const GenericFont &m_rFont;
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
91 /// Color of the playing item
93 /// Background colors, used when no background bitmap is given
94 uint32_t m_bgColor1, m_bgColor2;
95 /// Background of selected items
97 /// Pointer on the last selected item in the tree
98 VarTree *m_pLastSelected;
99 /// Image of the control
100 OSGraphics *m_pImage;
102 VarTree::Iterator m_lastPos;
104 /// Method called when the tree variable is modified
105 virtual void onUpdate( Subject<VarTree> &rTree );
107 // Method called when the position variable of the tree is modified
108 virtual void onUpdate( Subject<VarPercent> &rPercent );
110 /// Called when the position is set
111 virtual void onPositionChange();
113 /// Compute the number of lines that can be displayed
116 /// Compute the item's height (depends on fonts and images used)
119 /// Compute the width of an item's bitmap
120 int itemImageWidth();
122 /// Check if the tree must be scrolled
125 /// Draw the image of the control
128 /// Return the n'th displayed item (starting at position 0)
130 * Return m_rTree.end() if such an item cannot be found (n < 0, or
133 VarTree::Iterator findItemAtPos( int n );