- Your Widget Set For OpenGL
Main Page | Namespace List | Class Hierarchy | Class List | File List | Class Members | Related Pages

ulistbox.hpp

00001 /*************************************************************************** 00002 LibUFO - UI For OpenGL 00003 copyright : (C) 2001-2005 by Johannes Schmidt 00004 email : schmidtjf at users.sourceforge.net 00005 ------------------- 00006 00007 file : include/ufo/widgets/ulistbox.hpp 00008 begin : Tue Jun 18 2002 00009 $Id: ulistbox.hpp,v 1.15 2005/09/15 10:13:21 schmidtjf Exp $ 00010 ***************************************************************************/ 00011 00012 /*************************************************************************** 00013 * This library is free software; you can redistribute it and/or * 00014 * modify it under the terms of the GNU Lesser General Public * 00015 * License as published by the Free Software Foundation; either * 00016 * version 2.1 of the License, or (at your option) any later version. * 00017 * * 00018 * This library is distributed in the hope that it will be useful, * 00019 * but WITHOUT ANY WARRANTY; without even the implied warranty of * 00020 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * 00021 * Lesser General Public License for more details. * 00022 * * 00023 * You should have received a copy of the GNU Lesser General Public * 00024 * License along with this library; if not, write to the Free Software * 00025 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * 00026 ***************************************************************************/ 00027 00028 #ifndef ULISTBOX_HPP 00029 #define ULISTBOX_HPP 00030 00031 #include "uscrollablewidget.hpp" 00032 00033 #include "../util/ucolor.hpp" 00034 00035 namespace ufo { 00036 00037 class UItem; 00038 class UIcon; 00039 class UColor; 00040 00048 class UFO_EXPORT UListBox : public UScrollableWidget { 00049 UFO_DECLARE_DYNAMIC_CLASS(UListBox) 00050 UFO_UI_CLASS(UListBoxUI) 00051 UFO_STYLE_TYPE(UStyle::CE_ListBox) 00052 public: // Public Types 00057 enum SelectionMode { 00058 SingleSelection, 00059 MultipleSelection, 00060 NoSelection 00061 }; 00062 public: // Public constructors 00063 UListBox(); 00064 UListBox(const std::vector<UString> & listDataA); 00065 00066 public: // overrides UScrollableWidget 00067 virtual int getUnitIncrement(Orientation orientation = Horizontal) const; 00068 virtual int getBlockIncrement(Orientation orientation = Horizontal) const; 00069 00070 virtual UDimension getPreferredViewportSize() const; 00071 00072 public: // Item accessing methods 00077 void addList(const std::vector<UString> & listData); 00080 void addItem(UItem * itemA, int index = -1); 00083 void addItem(const UString & itemA, int index = -1); 00086 void addItem(UIcon * itemA, int index = -1); 00087 00089 void removeItem(unsigned int index); 00090 void removeAllItems(); 00091 00092 UItem * getItemAt(unsigned int n) const; 00093 const std::vector<UItem *> & getItems() const; 00094 00095 unsigned int getItemCount() const; 00096 00097 public: // Selection methods 00098 SelectionMode getSelectionMode() const; 00099 void setSelectionMode(SelectionMode modeA); 00100 00101 int getSelectedIndex() const; 00102 void setSelectedIndex(int indexA); 00103 00104 void invertSelection(); 00105 void selectAll(); 00106 00107 std::vector<unsigned int> getSelectedIndices() const; 00108 void setSelectedIndices(const std::vector<unsigned int> & indicesA); 00109 00110 bool isSelectedIndex(unsigned int indexA); 00111 00112 UItem * getSelectedItem(); 00113 std::vector<UItem*> getSelectedItems(); 00114 00115 public: // Other methods 00119 void setVisibleRowCount(int visibleRowCountA); 00120 int getVisibleRowCount() const; 00121 00123 UPoint indexToLocation(unsigned int indexA); 00126 int locationToIndex(const UPoint & locationA); 00127 00128 protected: // Overrides UWidget 00129 virtual void paintWidget(UGraphics * g); 00130 virtual UDimension getContentsSize(const UDimension & maxSize) const; 00131 virtual void processMouseEvent(UMouseEvent * e); 00132 virtual void processKeyEvent(UKeyEvent * e); 00133 virtual void processWidgetEvent(UWidgetEvent * e); 00134 00135 public: // Public signals 00137 typedef USignal3<UListBox*, int, int> sig_selection_change_t; 00138 sig_selection_change_t & sigSelectionChanged(); 00139 00140 protected: // Protected methods 00141 void addItemImpl(UItem * itemA, int index); 00142 00143 void fireSelectionEvent(int firstIndexA, int lastIndexA); 00144 00145 private: // Private attributes 00146 SelectionMode m_selectionMode; 00147 00148 std::vector<UItem *> m_items; 00149 std::vector<unsigned int> m_indices; 00150 00151 int m_visRowCount; 00152 private: // Private signals 00153 sig_selection_change_t m_sigSelectionChanged; 00154 }; 00155 00156 // 00157 // inline implementation 00158 // 00159 inline UListBox::sig_selection_change_t & 00160 UListBox::sigSelectionChanged() { 00161 return m_sigSelectionChanged; 00162 } 00163 00167 /* 00168 class UFO_EXPORT UListBoxItem : public virtual UCollectable { 00169 UFO_DECLARE_DYNAMIC_CLASS(UListBoxItem) 00170 public: 00171 virtual void paintItem(UListBox * listBoxA, int x, int y, 00172 bool isSelectedA, bool hasFocusA) = 0; 00173 virtual UDimension getItemSize(const UListBox * listBoxA) const = 0; 00174 */ 00180 /* 00181 virtual void notify(UListBox * listBox, bool b) = 0; 00182 }; 00183 */ 00184 00185 } // namespace ufo 00186 00187 #endif // ULISTBOX_HPP

The libUFO Project - written by Johannes Schmidt