00001 /***************************************************************************** 00002 * ctrl_tree.hpp 00003 ***************************************************************************** 00004 * Copyright (C) 2003 the VideoLAN team 00005 * $Id$ 00006 * 00007 * Authors: Antoine Cellerier <dionoea@videolan.org> 00008 * Clément Stenac <zorglub@videolan.org> 00009 * 00010 * This program is free software; you can redistribute it and/or modify 00011 * it under the terms of the GNU General Public License as published by 00012 * the Free Software Foundation; either version 2 of the License, or 00013 * (at your option) any later version. 00014 * 00015 * This program is distributed in the hope that it will be useful, 00016 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00017 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00018 * GNU General Public License for more details. 00019 * 00020 * You should have received a copy of the GNU General Public License 00021 * along with this program; if not, write to the Free Software 00022 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA. 00023 *****************************************************************************/ 00024 00025 #ifndef CTRL_TREE_HPP 00026 #define CTRL_TREE_HPP 00027 00028 #include "ctrl_generic.hpp" 00029 #include "../utils/observer.hpp" 00030 #include "../utils/var_tree.hpp" 00031 00032 class OSGraphics; 00033 class GenericFont; 00034 class GenericBitmap; 00035 00036 /// Class for control tree 00037 class CtrlTree: public CtrlGeneric, public Observer<VarTree, tree_update>, 00038 public Observer<VarPercent> 00039 { 00040 public: 00041 CtrlTree( intf_thread_t *pIntf, 00042 VarTree &rTree, 00043 const GenericFont &rFont, 00044 const GenericBitmap *pBgBitmap, 00045 const GenericBitmap *pItemBitmap, 00046 const GenericBitmap *pOpenBitmap, 00047 const GenericBitmap *pClosedBitmap, 00048 uint32_t fgColor, 00049 uint32_t playColor, 00050 uint32_t bgColor1, 00051 uint32_t bgColor2, 00052 uint32_t selColor, 00053 const UString &rHelp, 00054 VarBool *pVisible, 00055 VarBool *pFlat ); 00056 virtual ~CtrlTree(); 00057 00058 /// Handle an event on the control 00059 virtual void handleEvent( EvtGeneric &rEvent ); 00060 00061 /// Check whether coordinates are inside the control 00062 virtual bool mouseOver( int x, int y ) const; 00063 00064 /// Draw the control on the given graphics 00065 virtual void draw( OSGraphics &rImage, int xDest, int yDest ); 00066 00067 /// Called when the layout is resized 00068 virtual void onResize(); 00069 00070 /// Return true if the control can gain the focus 00071 virtual bool isFocusable() const { return true; } 00072 00073 /// Get the type of control (custom RTTI) 00074 virtual string getType() const { return "tree"; } 00075 00076 /// Make sure an item is visible 00077 /// \param item an iterator to a tree item 00078 /// \return true if it changed the position 00079 bool ensureVisible( VarTree::Iterator item ); 00080 00081 /// Make sure an item is visible 00082 /// \param itemIndex the absolute index in the tree 00083 /// \return true if it changed the position 00084 bool ensureVisible( int itemIndex ); 00085 00086 private: 00087 /// Tree associated to the control 00088 VarTree &m_rTree; 00089 /// Font 00090 const GenericFont &m_rFont; 00091 /// Background bitmap 00092 const GenericBitmap *m_pBgBitmap; 00093 /// Item (leaf) bitmap 00094 // (TODO : add different bitmaps for different item types 00095 // like in the wx playlist) 00096 const GenericBitmap *m_pItemBitmap; 00097 /// Open (expanded) node bitmap 00098 const GenericBitmap *m_pOpenBitmap; 00099 /// Closed node bitmap 00100 const GenericBitmap *m_pClosedBitmap; 00101 /// Color of normal test 00102 uint32_t m_fgColor; 00103 /// Color of the playing item 00104 uint32_t m_playColor; 00105 /// Background colors, used when no background bitmap is given 00106 uint32_t m_bgColor1, m_bgColor2; 00107 /// Background of selected items 00108 uint32_t m_selColor; 00109 /// Pointer on the last selected item in the tree 00110 VarTree *m_pLastSelected; 00111 /// Image of the control 00112 OSGraphics *m_pImage; 00113 /// First item in the visible area 00114 VarTree::Iterator m_firstPos; 00115 00116 /// Don't move if the position variable is updated 00117 bool m_dontMove; 00118 00119 /// Do we want to "flaten" the tree ? 00120 bool m_flat; 00121 00122 /// Method called when the tree variable is modified 00123 virtual void onUpdate( Subject<VarTree, tree_update> &rTree , 00124 tree_update *); 00125 00126 // Method called when the position variable of the tree is modified 00127 virtual void onUpdate( Subject<VarPercent> &rPercent , void *); 00128 00129 /// Called when the position is set 00130 virtual void onPositionChange(); 00131 00132 /// Compute the number of lines that can be displayed 00133 int maxItems(); 00134 00135 /// Compute the item's height (depends on fonts and images used) 00136 int itemHeight(); 00137 00138 /// Compute the width of an item's bitmap 00139 int itemImageWidth(); 00140 00141 /// Check if the tree must be scrolled 00142 void autoScroll(); 00143 00144 /// Draw the image of the control 00145 void makeImage(); 00146 00147 /// Return the n'th displayed item (starting at position 0) 00148 /** 00149 * Return m_rTree.end() if such an item cannot be found (n < 0, or 00150 * n too big) 00151 */ 00152 VarTree::Iterator findItemAtPos( int n ); 00153 }; 00154 00155 #endif
1.5.1