00001 #ifndef _FL_LISTVIEW_H_
00002 #define _FL_LISTVIEW_H_
00003
00004 #include "Fl_Table_Base.h"
00005 #include "Fl_ListView_Item.h"
00006 #include "Fl_ListView_Header.h"
00007 #include "Fl_ListView_Column.h"
00008
00012 class FL_API Fl_ListView : public Fl_Table_Base {
00013 public:
00014
00015
00016 enum ListViewFlags {
00017 SELECTED = 4,
00018 NON_SELECTABLE = 8,
00019 INACTIVE = 16
00020 };
00021
00022 enum TypeInModes {
00023 TYPE_IN_NONE = 0,
00024 TYPE_IN_SELECT,
00025 TYPE_IN_HIDE
00026 };
00027
00028 enum SortTypes {
00029 SORT_NONE = 0,
00030 SORT_ASC,
00031 SORT_DESC,
00032 SORT_LAST_TYPE
00033 };
00034
00035 static Fl_Named_Style* default_style;
00036 static Fl_ListView *current;
00037
00038
00039 enum TypeValues {
00040 MULTI_SELECTION = 16,
00041 WIDTH_CHANGED_NOTIFY = 32
00042 };
00043
00047 Fl_ListView(int X, int Y, int W, int H, const char *l=0);
00048
00052 Fl_ListView(const char *l = 0, int layout_size=30, Fl_Align layout_al=FL_ALIGN_TOP, int label_w=100);
00053
00055 virtual ~Fl_ListView();
00056
00057 void clear();
00058
00059 virtual void layout();
00060 virtual int handle(int event);
00061
00062 virtual void begin();
00063 virtual void end();
00064
00065 virtual void fill(Fl_Data_Source &ds, const char *user_data_column_name="");
00066
00067 int find(const Fl_ListView_Item *item) const;
00068 int find(const Fl_ListView_Item &item) const { return find(&item); }
00069
00070 void insert(Fl_ListView_Item &item, int pos);
00071 void add(Fl_ListView_Item &item);
00072 void remove(int index);
00073 void remove(Fl_ListView_Item &item) { remove(find(&item)); }
00074 void remove(Fl_ListView_Item *item) { remove(find(item)); }
00075
00076 unsigned children() const { return items.size(); }
00077 Fl_ListView_Item* child(unsigned n) const { return items.item(n); }
00078 Fl_ListItem_List &array() { return items; }
00079
00080 Fl_ListView_Header *header() { return m_header; }
00081 const Fl_ListView_Header *header() const { return m_header; }
00082
00083 bool multi() const { return ((type() & MULTI_SELECTION)==MULTI_SELECTION); }
00084 void multi(bool val) { if(val) type(type()|MULTI_SELECTION); else type(type()&~MULTI_SELECTION); }
00085
00086 bool draw_stripes() const { return m_draw_stripes; }
00087 void draw_stripes(bool v) { m_draw_stripes = v; }
00088
00089 void damage_item(Fl_ListView_Item *i) { i->redraw(); }
00090 void damage_row(unsigned row) { items[row]->redraw(); }
00091
00092
00093
00094
00095 void select_all_rows(int value=1);
00096 bool unselect_all();
00097
00098 void inactive_row(unsigned row, bool val);
00099 bool inactive_row(unsigned row) const { return (row_flags(row)&INACTIVE)==INACTIVE; }
00100 bool inactive(Fl_ListView_Item *w) const { return inactive_row(find(w)); }
00101
00102 void selectable_row(unsigned row, bool val);
00103 bool selectable_row(unsigned row) const { return !(row_flags(row)&NON_SELECTABLE); }
00104 bool selectable(Fl_ListView_Item *w) const { return selectable_row(find(w)); }
00105
00106 bool selected_row(unsigned row) const { return (row_flags(row) & SELECTED)==SELECTED; }
00107 bool selected(Fl_ListView_Item *w) const { return selected_row(find(w)); }
00108
00109 bool select_row(unsigned row, int value=1);
00110 bool select(Fl_ListView_Item *w, int value=1) { return select_row(find(w), value); }
00111
00112 bool select_only_row(unsigned row);
00113 bool select_only(Fl_ListView_Item *w) { return select_only_row(find(w)); }
00114
00115 void select_items(unsigned from, unsigned to);
00116
00117 int selected() const { return selection.count(); }
00118 Fl_ListItem_List &get_selection();
00119 const Fl_ListItem_List &get_selection() const;
00120
00121 void current_row(unsigned row) { cur_row = row; }
00122 unsigned current_row() const { return cur_row; }
00123
00124 Fl_ListView_Item *item(Fl_ListView_Item *i);
00125 Fl_ListView_Item *item() const { return items.item(cur_row); }
00126
00127 Fl_ListView_Item *item_at(int Y) const;
00128 int row_at(int Y) const;
00129
00130 bool show_item(Fl_ListView_Item *w);
00131
00132 Fl_ListView_Item* prev();
00133 Fl_ListView_Item* next();
00134
00135 int prev_row();
00136 int next_row();
00137
00138
00139
00140 virtual int sort(int column);
00141
00142 int sort_col() const { return m_sort_col; }
00143 void sort_col(int col) { m_sort_col = col; }
00144
00145 int sort_type() const { return m_sort_type; }
00146 void sort_type(int t) { m_sort_type = t; }
00147
00148
00149 Fl_ListView_Item *find_userdata(void *data, unsigned start_index=0, unsigned end_index=0) const;
00150 Fl_ListView_Item *find_text(const char *text, int column=-1, unsigned start_index=0, unsigned end_index=0) const;
00151
00152 int find_userdata_row(void *data, unsigned start_index=0, unsigned end_index=0) const;
00153 int find_text_row(const char *text, int column=-1, unsigned start_index=0, unsigned end_index=0) const;
00154
00155 int type_in_mode() const { return (int)m_type_in_mode; }
00156 void type_in_mode(int v) { m_type_in_mode = (uchar)v; }
00157
00158 void reset_search();
00159 const Fl_String &search_str() const { return m_search_str; }
00160
00161
00162 Fl_ListView_Column *add_column(const char *name, int width=-1, Fl_Variant_Type column_type=VAR_STRING);
00163 bool remove_column(const char *name);
00164 void remove_column(unsigned index);
00165 void clear_columns();
00166
00167 Fl_ListView_Column *column(unsigned c) { return m_columns.item(c); }
00168 const Fl_ListView_Column *column(unsigned c) const { return m_columns.item(c); }
00169 unsigned columns() const { return m_columns.size(); }
00170 void columns(unsigned count);
00171
00172
00173 void find_default_sizes();
00174 int preferred_col_width(int col);
00175
00176 bool width_changed_notify() const { return ((type() & WIDTH_CHANGED_NOTIFY)==WIDTH_CHANGED_NOTIFY); }
00177 void width_changed_notify(bool v) { if(v) type(type()|WIDTH_CHANGED_NOTIFY); else type(type()&~WIDTH_CHANGED_NOTIFY); }
00178
00179 void resetup();
00180
00182
00183
00184 Fl_ListView_Item *top() { return items.item(0); }
00185
00186 void clear_selection() { unselect_all(); }
00187
00188 void recalc_totalheight() { resetup(); }
00189
00190 void scroll_up(int pixels = 20) { int newy = yposition()-20; yposition((newy>0) ? newy : 0); }
00191 void scroll_down(int pixels = 20) { int newy = yposition()+20; yposition(newy); }
00192
00193 int column_width(int c) const { return col_width(c); }
00194 void column_width(int c, int w) { col_width(c, w); }
00195
00196 Fl_Variant_Type column_type(int c) const { return column(c)->type(); }
00197 void column_type(int c, Fl_Variant_Type t) { column(c)->type(t); }
00198
00199 const char *column_name(int c) const { return column(c)->label(); }
00200 void column_name(int c, const char *name) { column(c)->label(name); }
00201
00202 int column_flags(int c) const { return column(c)->flags(); }
00203 void column_flags(int c, int f) { column(c)->flags(f); }
00204
00205 const Fl_Image *column_image(int c) const { return column(c)->image(); }
00206 Fl_Image *column_image(int c) { return column(c)->image(); }
00207 void column_image(int c, Fl_Image *im) { column(c)->image(im); }
00208 void column_image(int c, Fl_Image &im) { column(c)->image(im); }
00209
00210 protected:
00211
00212 virtual void table_draw(TableContext context, unsigned R=0, unsigned C=0,
00213 int X=0, int Y=0, int W=0, int H=0);
00214 virtual void table_layout(TableContext context, unsigned row, unsigned col);
00215 virtual int table_handle(TableContext context, unsigned row, unsigned col, int event);
00216
00217 virtual void draw_row(unsigned row, int w, int h) const;
00218
00219 virtual int handle_key();
00220
00221
00222
00223 virtual bool match_text(const Fl_String &key, const char *text) const;
00224
00225 private:
00226 int cur_row;
00227
00228 Fl_ListColumn_List m_columns;
00229
00230 bool m_needsetup;
00231 bool m_draw_stripes;
00232
00233 int m_sort_type;
00234 int m_sort_col;
00235
00236 Fl_ListItem_List items;
00237 Fl_Int_List selection;
00238
00239
00240 Fl_ListItem_List stored_selection;
00241
00242 Fl_ListView_Header *m_header;
00243
00244 Fl_String m_search_str;
00245 uchar m_type_in_mode;
00246
00247 bool set_select_flag(unsigned row, int flag);
00248 void ctor_init();
00249 };
00250
00251 #endif