/** * Copyright Mikael Högdahl - triyana@users.sourceforge.net * * This source is distributed under the terms of the Q Public License version 1.0, * created by Trolltech (www.trolltech.com). */ #ifndef Fl_Table_Data_h #define Fl_Table_Data_h #include #include #include class Fl_Choice; class Fl_Dialog; class Fl_Widget; enum FL_TABLE_EDITOR { FL_NO_EDITOR = 0, FL_TEXT_EDITOR, FL_INTEGER_EDITOR, FL_FLOAT_EDITOR, FL_BOOL_EDITOR, FL_SECRET_EDITOR, FL_LIST_EDITOR, FL_DLG_LIST_EDITOR, FL_DLG_COLOR_EDITOR, FL_DLG_FILE_EDITOR, FL_DLG_DIR_EDITOR, FL_DLG_CUSTOM_EDITOR, }; enum FL_TABLE_ROWS { FL_NO_ROW = -4, FL_ACTIVE_ROW = -3, FL_LABEL_ROW = -2, FL_HEADER_ROW = -1, FL_ROW = 0, }; /** * Inherit form this interface to supply data to Fl_Table widget. * To be useful the value,cols,rows,editor,editor_type methods must be implemented. */ class Fl_Table_Data { public: Fl_Table_Data () {aHeader = true; aLabel = true; aDirty = false; aStripe = FL_WHITE; aBorder = true;} virtual ~Fl_Table_Data() {;} void border (bool d) {aBorder = d;} bool border () {return aBorder;} void dirty (bool d) {aDirty = d;} bool dirty () {return aDirty;} Fl_Widget* editor (int row, int col, bool force_editor) {return get_editor (editor_type (row, col, force_editor), row, col);} bool show_header () {return aHeader;} void show_header (bool header) {aHeader = header;} bool show_label () {return aLabel;} void show_label (bool label) {aLabel = label;} Fl_Color stripe () {return aStripe;} void stripe (Fl_Color c) {aStripe = c;} virtual void add () {;} virtual Fl_Align align (int row, int col) {return FL_ALIGN_LEFT;} virtual Fl_Color border_color (int row, int col); virtual Fl_Color box_color (int row, int col); virtual const char** choice (int row, int col, int& size, int& selected, char* label) {size = 0; selected = 0; strncpy (label, "Select Item", 20); return 0;} virtual int cols () = 0; virtual Fl_Dialog* custom_dialog (int row, int col) {return 0;} virtual FL_TABLE_EDITOR editor_type (int row, int col, bool force_custom) {return FL_TEXT_EDITOR;} virtual void erase (int row) {;} virtual void insert (int row) {;} virtual void* data () {return 0;} virtual int height (int row) {if (row == FL_LABEL_ROW) return 30; else if (row == FL_HEADER_ROW) return 24; else return 20;} virtual void reload (const char* message) {;} virtual int rows() = 0; virtual int save () {return -1;} virtual void sort (int col, bool ascent) {;} virtual Fl_Color textcolor (int row, int col) {return FL_BLACK;} virtual Fl_Font textfont (int row, int col) {if (row == FL_LABEL_ROW || row == FL_HEADER_ROW) return FL_HELVETICA_BOLD ; else return FL_HELVETICA;} virtual int textsize (int row, int col) {if (row == FL_LABEL_ROW) return 20; else if (row == FL_HEADER_ROW) return 12; else return 10;} virtual bool value (const char* data, int row, int col) {return true;} virtual const char* value (int row, int col) {if (row == FL_LABEL_ROW) return ""; else snprintf(aBuffer, 199, "%d - %d", row, col); return aBuffer;} virtual int width (int col) {return 100;} protected: Fl_Widget* get_editor (FL_TABLE_EDITOR type, int row, int col); private: char aBuffer[200]; char aDlgLabel[200]; char* aDefaultList[2]; Fl_Color aStripe; bool aDirty; bool aHeader; bool aBorder; bool aLabel; }; #endif