00001 /* 00002 ClanGUI, copyrights by various people. Have a look in the CREDITS file. 00003 00004 This sourcecode is distributed using the Library GNU Public Licence, 00005 version 2 or (at your option) any later version. Please read LICENSE 00006 for details. 00007 */ 00008 00009 #ifndef header_listbox_generic 00010 #define header_listbox_generic 00011 00012 #include <string> 00013 #include <list> 00014 00015 #include <API/Display/Input/key.h> 00016 #include <API/Display/Input/inputdevice.h> 00017 #include <API/Core/Math/rect.h> 00018 #include <API/signals.h> 00019 00020 class CL_ListBox; 00021 class CL_ScrollBar; 00022 class CL_Component; 00023 class CL_ComponentOptions; 00024 class CL_StyleManager; 00025 00026 class CL_ListBox_Generic 00027 { 00028 // Construction: 00029 public: 00030 static CL_ComponentOptions create_options( 00031 const CL_Rect &pos); 00032 00033 CL_ListBox_Generic(CL_ListBox *self, const CL_ComponentOptions &options, CL_StyleManager *style); 00034 ~CL_ListBox_Generic() {}; 00035 00036 // Attributes: 00037 public: 00038 int get_count() const; 00039 00040 std::list<std::string> &get_items(); 00041 std::string get_text(int index) const; 00042 std::string get_current_text() const; 00043 int get_current_item() const; 00044 bool is_selected(int index) const; 00045 00046 int get_item_height() const; 00047 int get_top_item() const; 00048 00049 int max_visible_items; 00050 00051 CL_Component *client_area; 00052 00053 // Operations: 00054 public: 00055 int insert_item(const std::string &text, int index); 00056 void remove_item(int index); 00057 void change_item(const std::string &text, int index); 00058 00059 void set_current_item(int index); 00060 void clear_selection(); 00061 00062 void set_item_height(int height); 00063 void set_max_visible_items(int count); 00064 void set_top_item(int index); 00065 00066 void sort(bool ascending); 00067 00068 void clear(); 00069 00070 // Signals: 00071 public: 00072 CL_Signal_v1<int> sig_highlighted; 00073 CL_Signal_v1<int> sig_activated; 00074 00075 // Slots: 00076 private: 00077 CL_Slot slot_on_key_down; 00078 CL_Slot slot_on_scroll_change; 00079 CL_Slot slot_child_add, slot_child_remove; 00080 00081 // Callbacks: 00082 private: 00083 void on_key_down(CL_Component *comp, CL_InputDevice *device, CL_Key key); 00084 void on_scroll_change(int new_offset); 00085 void on_child_add(CL_Component *child); 00086 void on_child_remove(CL_Component *child); 00087 00088 // Implementation: 00089 protected: 00090 void update_scrollbar(); 00091 00092 int highlighted_item; 00093 int item_height; 00094 int scroll_offset; 00095 00096 bool has_scrollbar; 00097 00098 CL_ListBox *listbox; 00099 CL_ScrollBar *scrollbar; 00100 00101 std::list<std::string> items; 00102 }; 00103 00104 #endif
1.2.6 written by Dimitri van Heesch,
© 1997-2001