00001
00002
00003 #ifndef TABLE_H
00004 #define TABLE_H
00005
00006 #include "passthrough.h"
00007 #include <list>
00008 #include <vector>
00009
00010 #include <sigc++/connection.h>
00011
00012 namespace cwidget
00013 {
00014 namespace widgets
00015 {
00016 class keybindings;
00017
00018 class table:public passthrough
00019 {
00020 public:
00021
00022 static const int EXPAND=0x1, SHRINK=0x2, FILL=0x4;
00023 static const int ALIGN_LEFT=0x8, ALIGN_RIGHT=0x10;
00024 static const int ALIGN_CENTER=ALIGN_LEFT|ALIGN_RIGHT;
00025 static const int IGNORE_SIZE_REQUEST=0x20;
00026 private:
00027 struct child_info
00028 {
00029
00030 widget_ref w;
00031
00032
00033 int row_start, col_start;
00034
00035
00036 int row_span, col_span;
00037
00041 int alloc_w, alloc_h;
00042
00046 int request_w, request_h;
00047
00048 sigc::connection shown_conn, hidden_conn;
00049
00051 bool expand_x:1, expand_y:1;
00052
00056 bool fill_x:1, fill_y:1;
00057
00059 bool shrink_x:1, shrink_y:1;
00060
00064 bool align_left_x:1, align_left_y:1, align_right_x:1, align_right_y:1;
00065
00069 bool ignore_size_x:1, ignore_size_y:1;
00070
00071 child_info(const widget_ref &_w, int _row_start, int _col_start,
00072 int _row_span, int _col_span, int xopts, int yopts,
00073 sigc::connection &_shown_conn, sigc::connection &_hidden_conn);
00074 };
00075
00076 bool lies_on_axis(const child_info &base,
00077 bool horizontal,
00078 const child_info &c);
00079 class better_fit;
00080 class nrow_lt;
00081 class ncol_lt;
00082
00083 typedef std::list<child_info> childlist;
00084
00085
00086
00087
00088
00089
00090 childlist children;
00091 childlist::iterator focus;
00092
00093
00094 int rowsep, colsep;
00095
00097 void calc_dimensions();
00098
00100 int num_rows;
00101
00103 int num_cols;
00104
00105 void layout_me();
00106
00107
00108 widget_ref get_focus();
00109 void hide_widget(const widget_ref &w);
00110 void hide_widget_bare(widget &w);
00111 void show_widget(const widget_ref &w);
00112 void show_widget_bare(widget &w);
00113
00119 void get_row_contents(std::vector<std::vector<child_info *> > row_contents);
00120
00126 void get_col_contents(std::vector<std::vector<child_info *> > col_contents);
00127
00128 void alloc_ideal_widths(std::vector<int> &col_sizes);
00129 void expand_widths(std::vector<int> &col_sizes, int target_w);
00130 void shrink_widths(std::vector<int> &col_sizes, int target_w);
00131 void alloc_ideal_heights(std::vector<int> &row_sizes,
00132 const std::vector<int> &col_sizes);
00133 void expand_heights(std::vector<int> &row_sizes, int target_h);
00134 void shrink_heights(std::vector<int> &row_sizes, int target_h);
00135 void alloc_child_sizes(const std::vector<int> &col_sizes,
00136 const std::vector<int> &row_sizes);
00137
00138
00139
00140 void got_focus();
00141 void lost_focus();
00142
00143
00144 childlist::iterator find_best_focus(childlist::iterator start,
00145 int dx,
00146 int dy);
00147
00148 protected:
00149 bool handle_key(const config::key &k);
00150 table();
00151
00152 public:
00153 static util::ref_ptr<table> create()
00154 {
00155 util::ref_ptr<table> rval(new table);
00156 rval->decref();
00157 return rval;
00158 }
00159
00160 ~table();
00161
00162 void destroy();
00163
00164 void add_widget_opts(const widget_ref &w, int row_start, int col_start, int row_span, int col_span, int xopts, int yopts);
00165 void add_widget_opts_bare(widget &w, int row_start, int col_start, int row_span, int col_span, int xopts, int yopts);
00166
00167 void add_widget(const widget_ref &w, int row_start, int col_start, int row_span=1, int col_span=1, bool expand=true, bool shrink=true);
00168 void add_widget_bare(widget &w, int row_start, int col_start, int row_span=1, int col_span=1, bool expand=true, bool shrink=true);
00169
00170 void add_widget(const widget_ref &w);
00171
00172 void rem_widget(const widget_ref &w);
00173
00174 void focus_widget(const widget_ref &w);
00175 void focus_widget_bare(widget &w);
00176
00180 void set_rowsep(int n);
00181
00185 void set_colsep(int n);
00186
00187 void show_all();
00188
00193 int width_request();
00194
00202 int height_request(int w);
00203
00204 void paint(const style &st);
00205 void dispatch_mouse(short id, int x, int y, int z, mmask_t bstate);
00206
00207 static config::keybindings *bindings;
00208 static void init_bindings();
00209 };
00210
00211 typedef util::ref_ptr<table> table_ref;
00212 }
00213 }
00214
00215 #endif