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>
40 typedef VarTree::IteratorVisible Iterator;
42 CtrlTree( intf_thread_t *pIntf,
44 const GenericFont &rFont,
45 const GenericBitmap *pBgBitmap,
46 const GenericBitmap *pItemBitmap,
47 const GenericBitmap *pOpenBitmap,
48 const GenericBitmap *pClosedBitmap,
59 /// Handle an event on the control
60 virtual void handleEvent( EvtGeneric &rEvent );
62 /// Check whether coordinates are inside the control
63 virtual bool mouseOver( int x, int y ) const;
65 /// Draw the control on the given graphics
66 virtual void draw( OSGraphics &rImage, int xDest, int yDest, int w, int h );
68 /// Called when the layout is resized
69 virtual void onResize();
71 /// Return true if the control can gain the focus
72 virtual bool isFocusable() const { return true; }
74 /// Return true if the control can be scrollable
75 virtual bool isScrollable() const { return true; }
77 /// Get the type of control (custom RTTI)
78 virtual string getType() const { return "tree"; }
80 /// Make sure an item is visible
81 /// \param item an iterator to a tree item
82 /// \return true if it changed the position
83 bool ensureVisible( const Iterator& it );
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;
101 GenericBitmap *m_pScaledBitmap;
102 /// Image of the control
103 OSGraphics *m_pImage;
105 /// Color of normal test
107 /// Color of the playing item
108 uint32_t m_playColor;
109 /// Background colors, used when no background bitmap is given
110 uint32_t m_bgColor1, m_bgColor2;
111 /// Background of selected items
114 /// First item in the visible area
116 /// Pointer on the last clicked item in the tree
117 Iterator m_lastClicked;
121 /// Do we want to "flaten" the tree ?
123 /// Number of visible lines
125 /// flag for item deletion
126 bool m_bRefreshOnDelete;
128 /// Method called when the tree variable is modified
129 virtual void onUpdate( Subject<VarTree, tree_update> &rTree,
132 /// Called when the position is set
133 virtual void onPositionChange();
135 /// Compute the number of lines that can be displayed
138 /// Compute the item's height (depends on fonts and images used)
141 /// Compute the width of an item's bitmap
142 int itemImageWidth();
144 /// Draw the image of the control
147 /// Return the n'th displayed item (starting at position 0)
148 Iterator findItemAtPos( int n );
150 /// return the nearest item
151 Iterator getNearestItem( const Iterator& it );
153 /// return whether the item is visible or not
154 bool isItemVisible( const Iterator& it );
156 void setSliderFromFirst();
157 Iterator getFirstFromSlider();
158 void setScrollStep();