00001 #ifndef _FL_LISTVIEW_ITEM_H_
00002 #define _FL_LISTVIEW_ITEM_H_
00003
00004 #include "Fl_Image.h"
00005 #include "Fl_String.h"
00006 #include "Fl_Packed_Strings.h"
00007
00008 class Fl_ListView;
00009
00010 class FL_API Fl_ListView_Item {
00011 public:
00012 enum ItemTypes {
00013 NORMAL = 0,
00014 EXT = 1,
00015 CUSTOM = 1000
00016 };
00017
00018 Fl_ListView_Item(const char *label1=0,
00019 const char *label2=0,
00020 const char *label3=0,
00021 const char *label4=0,
00022 const char *label5=0);
00023 virtual ~Fl_ListView_Item();
00024
00025 virtual int type() { return NORMAL; }
00026
00027 const char *label() const;
00028 const char *label(unsigned col) const;
00029 void label(unsigned col, const char *text);
00030 void label(unsigned col, const Fl_String &text);
00031
00032 virtual void columns(unsigned count);
00033 virtual unsigned columns() const;
00034
00035
00036 virtual int preferred_width(unsigned col) const;
00037 virtual void width_changed(unsigned row, unsigned col);
00038 virtual void setup(unsigned row);
00039
00040 virtual void draw_cell(unsigned row, unsigned col, int width, int height);
00041
00042 void parent(Fl_ListView *p) { m_parent = p; }
00043 Fl_ListView *parent() const { return m_parent; }
00044
00045 void *user_data() { return m_user_data; }
00046 void user_data(void *d) { m_user_data = d; }
00047 long argument() const { return (long)m_user_data; }
00048 void argument(long v) { m_user_data = (void*)v; }
00049
00050 uchar damage() const { return m_damage; }
00051 void set_damage(uchar c) { m_damage = c; }
00052 void redraw(uchar c);
00053 void redraw() { redraw(FL_DAMAGE_ALL); }
00054
00055 void image(Fl_Image *im) { m_image = im; }
00056 void image(Fl_Image &im) { m_image = &im; }
00057 Fl_Image *image() { return m_image; }
00058 const Fl_Image *image() const { return m_image; }
00059 void image(unsigned col, Fl_Image &im) { image(im); }
00060 void image(unsigned col, Fl_Image *im) { image(im); }
00061
00062 virtual int compare(Fl_ListView_Item *other, int column, int sort_type);
00063
00065
00066
00067 void copy_label(unsigned col, const char *text) { label(col, text); }
00068
00069 protected:
00070 Fl_Packed_Strings strings;
00071
00072 int compare_strings(Fl_ListView_Item *other, int column, int sort_type) const;
00073 int compare_integers(Fl_ListView_Item *other, int column, int sort_type) const;
00074 int compare_floats(Fl_ListView_Item *other, int column, int sort_type) const;
00075 int compare_dates(Fl_ListView_Item *other, int column, int sort_type) const;
00076 int compare_datetimes(Fl_ListView_Item *other, int column, int sort_type) const;
00077
00078 private:
00079 Fl_ListView *m_parent;
00080 void *m_user_data;
00081 Fl_Image *m_image;
00082
00083 uchar m_damage;
00084 };
00085
00086 class FL_API Fl_ListView_ItemExt : public Fl_ListView_Item {
00087 public:
00088 Fl_ListView_ItemExt(const char *label1=0,
00089 const char *label2=0,
00090 const char *label3=0,
00091 const char *label4=0,
00092 const char *label5=0);
00093 virtual ~Fl_ListView_ItemExt();
00094
00095 virtual int type() { return EXT; }
00096
00097 virtual void columns(unsigned count);
00098 virtual unsigned columns() const { return Fl_ListView_Item::columns(); }
00099
00100
00101 virtual int preferred_width(unsigned col) const;
00102 virtual void width_changed(unsigned row, unsigned col);
00103 virtual void setup(unsigned row);
00104
00105 virtual void draw_cell(unsigned row, unsigned col, int width, int height);
00106
00107 int leading() const { return m_leading; }
00108 void leading(int l) { m_leading = l; }
00109
00110 Fl_Flags flags(unsigned col, Fl_Flags f);
00111 Fl_Flags flags(unsigned col) const ;
00112 Fl_Flags set_flag(unsigned col, Fl_Flags f);
00113 Fl_Flags clear_flag(unsigned col, Fl_Flags f);
00114 Fl_Flags invert_flag(unsigned col, Fl_Flags f);
00115
00116 int label_size(unsigned col) const;
00117 void label_size(unsigned col, int size);
00118
00119 Fl_Font label_font(unsigned col) const;
00120 void label_font(unsigned col, Fl_Font font);
00121
00122 Fl_Labeltype label_type(unsigned col) const;
00123 void label_type(unsigned col, Fl_Labeltype type);
00124
00125 Fl_Color label_color(unsigned col) const;
00126 void label_color(unsigned col, Fl_Color color);
00127
00128 void label_font(unsigned col, Fl_Font font, int size) { label_font(col, font); label_size(col, size); }
00129
00130 void image(unsigned col, Fl_Image *im);
00131 void image(unsigned col, Fl_Image &im);
00132 Fl_Image *image(unsigned col);
00133 const Fl_Image *image(unsigned col) const;
00134
00135 protected:
00136 void draw_label(unsigned col, const char *label, int X, int Y, int W, int H, Fl_Flags flags);
00137
00138 private:
00139 int m_leading;
00140 Fl_Ptr_List col_attrs;
00141 };
00142
00145
00146 class FL_API Fl_ListItem_List : public Fl_Ptr_List {
00147 public:
00148 Fl_ListItem_List() : Fl_Ptr_List() { }
00149 virtual ~Fl_ListItem_List() { clear(); }
00150
00151 void append(Fl_ListView_Item *item) { Fl_Ptr_List::append((void *)item); }
00152 void prepend(Fl_ListView_Item *item) { Fl_Ptr_List::prepend((void *)item); }
00153 void insert(uint pos, Fl_ListView_Item *item) { Fl_Ptr_List::insert(pos, (void *)item); }
00154 void replace(uint pos, Fl_ListView_Item *item) { Fl_Ptr_List::replace(pos, (void *)item); }
00155 void remove(uint pos) { Fl_Ptr_List::remove(pos); }
00156 bool remove(Fl_ListView_Item *item) { return Fl_Ptr_List::remove((void *)item); }
00157 int index_of(const Fl_ListView_Item *w) const { return Fl_Ptr_List::index_of((void*)w); }
00158 Fl_ListView_Item *item(uint index) const { return (Fl_ListView_Item*)Fl_Ptr_List::item(index); }
00159 Fl_ListView_Item **data() { return (Fl_ListView_Item**)items; }
00160 Fl_ListView_Item *operator [](uint ind) const { return (Fl_ListView_Item *)items[ind]; }
00161 protected:
00162 void free_item(Fl_Ptr_List_Item item) { delete (Fl_ListView_Item*)(item); }
00163 };
00164
00165 #endif