GnuCash  2.6.99
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
basiccell.h
1 /********************************************************************\
2  * basiccell.h -- base class for editable cell in a table *
3  * *
4  * This program is free software; you can redistribute it and/or *
5  * modify it under the terms of the GNU General Public License as *
6  * published by the Free Software Foundation; either version 2 of *
7  * the License, or (at your option) any later version. *
8  * *
9  * This program is distributed in the hope that it will be useful, *
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
12  * GNU General Public License for more details. *
13  * *
14  * You should have received a copy of the GNU General Public License*
15  * along with this program; if not, contact: *
16  * *
17  * Free Software Foundation Voice: +1-617-542-5942 *
18  * 51 Franklin Street, Fifth Floor Fax: +1-617-542-2652 *
19  * Boston, MA 02110-1301, USA [email protected] *
20  * *
21 \********************************************************************/
22 
23 /*
24  * FILE:
25  * basiccell.h
26  *
27  * FUNCTION:
28  * The BasicCell class provides an abstract base class
29  * defining the handling of the editing of a cell of a table.
30  * Classes that provide the actual handling for different
31  * cell types should inherit from this class.
32  *
33  * The BasicCell class encapsulates a single string value
34  * which can be set & read by the programmer, and edited
35  * by the "user". In the text below, the "user" is the
36  * person controlling the mouse and keyboard. Thus, when
37  * the user makes a move, it means that they have somehow
38  * interacted with the cell, by clicking with mouse or by
39  * typing at the keyboard. This class provides three
40  * callbacks which allow the programmer to understand what
41  * the user is doing.
42  *
43  * The programmer can create a custom GUI for editing the
44  * contents of the cell. There are three callbacks to allow
45  * a custom GUI to be created, destroyed and moved about.
46  *
47  * Since this class is implemented in C not C++, there is
48  * a "minor" problem with inheritance. To emulate the
49  * overloading of a virtual "SetValues" method, there is
50  * a set_value() callback, which will be called whenever
51  * the xaccSetBasicCellValue() subroutine is called.
52  *
53  * VIRTUAL/OVERLOADED METHODS:
54  * The set_value() callback will be called whenever the
55  * xaccSetBasicCellValue() method is called. Derived
56  * classes should provide a callback here if they need
57  * to understand special cell formats.
58  *
59  * USER CALLBACKS:
60  * The enter_cell() callback is called when the user first
61  * makes a move to enter a cell. This might be by clicking
62  * on the cell with the mouse, by tabbing to it, using the
63  * arrow keys, or otherwise "selecting" it as the current
64  * cell to edit.
65  *
66  * The callback may change the value of the cell. The callback
67  * should return true if the cell should allow direct editing
68  * by the user, FALSE otherwise.
69  *
70  * The callback is also passed pointers to the cursor position
71  * and the start and end of the highlited region. If the callback
72  * returns NULL, it may also change these values and the GUI will
73  * update appropriately.
74  *
75  * The leave_cell() callback is called when the user exits
76  * a cell. This can be by tabbing or arrow-keying away
77  * from it, or by using the mouse to specify a different
78  * cell, etc. The callback may change the value of the cell.
79  *
80  * The modify_verify() callback is called when a user makes a
81  * change to a cell. It is called after every keystroke,
82  * (actually, after every X11 "input-method" type input,
83  * so that ctrl-alt-etc modifier keys are pre-processed in
84  * the usual X11 fashion).
85  *
86  * The arguments passed in are :
87  * "add", the string the user is attempting to add
88  * (will be null if text is being deleted).
89  * "new", the string that would result is user's changes
90  * are accepted.
91  * "cursor_position", the position of the editing cursor
92  * in the text. This may be modified by
93  * the callback, in which case the GUI
94  * will reflect the change. Set to -1
95  * to make the cursor go to the end of
96  * the text.
97  * "start_selection", the starting character of the highlited
98  * selection.
99  * "end_selection", the index immediately after the last
100  * character in the selection. Set both
101  * start and end to 0 for no selection.
102  * Set the end to -1 to make the selection
103  * go to the end of the text.
104  *
105  * The direct_update() callback is called to pass raw gui data
106  * to the cell. The exact format of the data is determined
107  * by the gui. The callback should return TRUE if the event
108  * was handled, i.e., there is no need to call the modify
109  * update. If the value needs to be changed, the cell should
110  * go ahead and change it.
111  *
112  *
113  * GUI CALLBACKS:
114  * The cell may have some specific GUI elements which need
115  * to be initialized/positioned/etc. There are three GUI
116  * callbacks that allow the programmer to perform GUI-specific
117  * initialization & changes.
118  *
119  * The gui_realize() callback will be called when GUI-specific
120  * initialization needs to be done. For Gnome, the second
121  * argument will be cast to the parent widget.
122  *
123  * The gui_destroy() callback will be called when the GUI associated
124  * with the cell needs to be destroyed.
125  *
126  * The gui_move() callback will be called when the GUI element needs
127  * to be positioned to a new location within the table grid.
128  * The second argument is the virtual location the GUI
129  * element should be moved to.
130  *
131  * The gui_private member may be used by the derived class to
132  * store any additional GUI-specific data.
133  *
134  * HISTORY:
135  * Copyright (c) 1998 Linas Vepstas
136  * Copyright (c) 2000 Dave Peticolas <[email protected]>
137  */
138 
139 #ifndef BASIC_CELL_H
140 #define BASIC_CELL_H
141 
142 #include <gdk/gdk.h>
143 #include <glib.h>
144 #include <gtk/gtk.h>
145 
146 
147 typedef struct basic_cell BasicCell;
148 
149 typedef BasicCell * (*CellCreateFunc) (void);
150 
151 typedef void (*CellSetValueFunc) (BasicCell *cell,
152  const char * new_value);
153 
154 typedef gboolean (*CellEnterFunc) (BasicCell *cell,
155  int *cursor_position,
156  int *start_selection,
157  int *end_selection);
158 
159 typedef void (*CellModifyVerifyFunc) (BasicCell *cell,
160  const char *add_str,
161  int add_str_len,
162  const char *new_value,
163  int new_value_len,
164  int *cursor_position,
165  int *start_selection,
166  int *end_selection);
167 
168 typedef gboolean (*CellDirectUpdateFunc) (BasicCell *cell,
169  int *cursor_position,
170  int *start_selection,
171  int *end_selection,
172  gpointer gui_data);
173 
174 typedef void (*CellLeaveFunc) (BasicCell *cell);
175 
176 typedef void (*CellRealizeFunc) (BasicCell *cell, gpointer gui_handle);
177 
178 typedef void (*CellMoveFunc) (BasicCell *cell);
179 
180 typedef void (*CellDestroyFunc) (BasicCell *cell);
181 
182 typedef enum
183 {
184  CELL_ALIGN_RIGHT,
185  CELL_ALIGN_CENTER,
186  CELL_ALIGN_LEFT
187 } CellAlignment;
188 
190 {
191  char * cell_name;
192  gchar *cell_type_name;
193  char * value; /* current value */
194  guint value_chars; /* number of characters in value */
195 
196  gboolean changed; /* true if value modified */
197  gboolean conditionally_changed; /* true if value modified conditionally */
198 
199  /* "virtual", overloaded methods */
200  CellSetValueFunc set_value;
201  CellDestroyFunc destroy;
202 
203  /* cell-editing callbacks */
204  CellEnterFunc enter_cell;
205  CellModifyVerifyFunc modify_verify;
206  CellDirectUpdateFunc direct_update;
207  CellLeaveFunc leave_cell;
208 
209  /* private, GUI-specific callbacks */
210  CellRealizeFunc gui_realize;
211  CellMoveFunc gui_move;
212  CellDestroyFunc gui_destroy;
213 
214  /* GUI information */
215  char *sample_text; /* sample text for sizing purposes */
216  CellAlignment alignment; /* horizontal alignment in column */
217  gboolean expandable; /* can fill with extra space */
218  gboolean span; /* can span multiple columns */
219  gboolean is_popup; /* is a popup widget */
220 
221  /* general hook for gui-private data */
222  gpointer gui_private;
223 };
224 
225 
226 gboolean gnc_cell_name_equal (const char * cell_name_1,
227  const char * cell_name_2);
228 
229 BasicCell * gnc_basic_cell_new (void);
230 void gnc_basic_cell_init (BasicCell *bcell);
231 void gnc_basic_cell_destroy (BasicCell *bcell);
232 
233 void gnc_basic_cell_set_name (BasicCell *cell, const char *name);
234 gboolean gnc_basic_cell_has_name (BasicCell *cell, const char *name);
235 void gnc_basic_cell_set_type_name (BasicCell *cell, const gchar *type_name);
236 gboolean gnc_basic_cell_has_type_name (BasicCell *cell, const gchar *type_name);
237 
238 
239 
240 void gnc_basic_cell_set_sample_text (BasicCell *cell,
241  const char *sample_text);
242 void gnc_basic_cell_set_alignment (BasicCell *cell,
243  CellAlignment alignment);
244 void gnc_basic_cell_set_expandable (BasicCell *cell,
245  gboolean expandable);
246 void gnc_basic_cell_set_span (BasicCell *cell,
247  gboolean span);
248 
249 const char * gnc_basic_cell_get_value (BasicCell *cell);
250 void gnc_basic_cell_set_value (BasicCell *bcell, const char *value);
251 
252 gboolean gnc_basic_cell_get_changed (BasicCell *cell);
253 gboolean gnc_basic_cell_get_conditionally_changed (BasicCell *cell);
254 
255 void gnc_basic_cell_set_changed (BasicCell *cell, gboolean changed);
256 void gnc_basic_cell_set_conditionally_changed (BasicCell *cell,
257  gboolean changed);
258 
259 /* for sub-class use only */
260 void gnc_basic_cell_set_value_internal (BasicCell *bcell,
261  const char *value);
262 
263 #endif /* BASIC_CELL_H */