cwidget  0.5.17
table.h
1 // table.h -*-c++-*-
2 
3 #ifndef TABLE_H
4 #define TABLE_H
5 
6 #include "passthrough.h"
7 #include <list>
8 #include <vector>
9 
10 #include <sigc++/connection.h>
11 
12 namespace cwidget
13 {
14  namespace widgets
15  {
16  class keybindings;
17 
18  class table:public passthrough
19  {
20  public:
21  // Options for laying out the widget..
22  static const int EXPAND=0x1, SHRINK=0x2, FILL=0x4;
23  static const int ALIGN_LEFT=0x8, ALIGN_RIGHT=0x10;
24  static const int ALIGN_CENTER=ALIGN_LEFT|ALIGN_RIGHT;
25  static const int IGNORE_SIZE_REQUEST=0x20;
26  private:
27  struct child_info
28  {
29  // The widget itself
30  widget_ref w;
31 
32  // The upper-left corner of this widget
33  int row_start, col_start;
34 
35  // How big is it?
36  int row_span, col_span;
37 
41  int alloc_w, alloc_h;
42 
46  int request_w, request_h;
47 
48  sigc::connection shown_conn, hidden_conn;
49 
51  bool expand_x:1, expand_y:1;
52 
56  bool fill_x:1, fill_y:1;
57 
59  bool shrink_x:1, shrink_y:1;
60 
64  bool align_left_x:1, align_left_y:1, align_right_x:1, align_right_y:1;
65 
69  bool ignore_size_x:1, ignore_size_y:1;
70 
71  child_info(const widget_ref &_w, int _row_start, int _col_start,
72  int _row_span, int _col_span, int xopts, int yopts,
73  sigc::connection &_shown_conn, sigc::connection &_hidden_conn);
74  };
75 
76  bool lies_on_axis(const child_info &base,
77  bool horizontal,
78  const child_info &c);
79  class better_fit;
80  class nrow_lt;
81  class ncol_lt;
82 
83  typedef std::list<child_info> childlist;
84 
85  // Tables have an automatic behavior similar to dialogs in other widget
86  // sets -- they can give the focus to any widget that can handle it.
87  //
88  // Widgets are given focus in the order in which they are added to the
89  // table (cyclically)
90  childlist children;
91  childlist::iterator focus;
92 
93  // Separation between rows/columns; initially 0.
94  int rowsep, colsep;
95 
97  void calc_dimensions();
98 
100  int num_rows;
101 
103  int num_cols;
104 
105  void layout_me();
106 
107  // Focus-handling stuff
108  widget_ref get_focus();
109  void hide_widget(const widget_ref &w);
110  void hide_widget_bare(widget &w);
111  void show_widget(const widget_ref &w);
112  void show_widget_bare(widget &w);
113 
119  void get_row_contents(std::vector<std::vector<child_info *> > row_contents);
120 
126  void get_col_contents(std::vector<std::vector<child_info *> > col_contents);
127 
128  void alloc_ideal_widths(std::vector<int> &col_sizes);
129  void expand_widths(std::vector<int> &col_sizes, int target_w);
130  void shrink_widths(std::vector<int> &col_sizes, int target_w);
131  void alloc_ideal_heights(std::vector<int> &row_sizes,
132  const std::vector<int> &col_sizes);
133  void expand_heights(std::vector<int> &row_sizes, int target_h);
134  void shrink_heights(std::vector<int> &row_sizes, int target_h);
135  void alloc_child_sizes(const std::vector<int> &col_sizes,
136  const std::vector<int> &row_sizes);
137 
138 
139 
140  void got_focus();
141  void lost_focus();
142 
143  // Moves the focus in the given direction
144  childlist::iterator find_best_focus(childlist::iterator start,
145  int dx,
146  int dy);
147 
148  protected:
149  bool handle_key(const config::key &k);
150  table();
151 
152  public:
153  static util::ref_ptr<table> create()
154  {
155  util::ref_ptr<table> rval(new table);
156  rval->decref();
157  return rval;
158  }
159 
160  ~table();
161 
162  void destroy();
163 
164  void add_widget_opts(const widget_ref &w, int row_start, int col_start, int row_span, int col_span, int xopts, int yopts);
165  void add_widget_opts_bare(widget &w, int row_start, int col_start, int row_span, int col_span, int xopts, int yopts);
166 
167  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);
168  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);
169 
170  void add_widget(const widget_ref &w);
171 
172  void rem_widget(const widget_ref &w);
173 
174  void focus_widget(const widget_ref &w);
175  void focus_widget_bare(widget &w);
176 
180  void set_rowsep(int n);
181 
185  void set_colsep(int n);
186 
187  void show_all();
188 
193  int width_request();
194 
202  int height_request(int w);
203 
204  void paint(const style &st);
205  void dispatch_mouse(short id, int x, int y, int z, mmask_t bstate);
206 
207  static config::keybindings *bindings;
208  static void init_bindings();
209  };
210 
212  }
213 }
214 
215 #endif
A "style" is a setting to be applied to a display element (widget, text, etc).
Definition: style.h:51
Stores the keys bound to various functions.
Definition: keybindings.h:87
int width_request()
Calculates the requested width of the entire table.
Definition: table.cc:1372
bool handle_key(const config::key &k)
Handles a keypress in this widget.
Definition: table.cc:568
void paint(const style &st)
Display this widget.
Definition: table.cc:1427
void show_all()
Display this widget and all its subwidgets.
Definition: table.cc:387
The namespace containing everything defined by cwidget.
Definition: columnify.cc:26
void destroy()
Destroys the visible representation of this widget and disconnects it from any children that it may h...
Definition: table.cc:74
The basic widget interface.
Definition: widget.h:107
Definition: table.h:18
Represents a keystroke as seen by curses.
Definition: keybindings.h:42
Definition: passthrough.h:15
void set_rowsep(int n)
Set the separation between adjacent rows to the given number of characters.
Definition: table.cc:84
int height_request(int w)
Calculates the requested height of the entire table.
Definition: table.cc:1385
void set_colsep(int n)
Set the separation between adjacent rows to the given number of characters.
Definition: table.cc:96