GnuCash 2.4.99
basiccell.h
00001 /********************************************************************\
00002  * basiccell.h -- base class for editable cell in a table           *
00003  *                                                                  *
00004  * This program is free software; you can redistribute it and/or    *
00005  * modify it under the terms of the GNU General Public License as   *
00006  * published by the Free Software Foundation; either version 2 of   *
00007  * the License, or (at your option) any later version.              *
00008  *                                                                  *
00009  * This program is distributed in the hope that it will be useful,  *
00010  * but WITHOUT ANY WARRANTY; without even the implied warranty of   *
00011  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the    *
00012  * GNU General Public License for more details.                     *
00013  *                                                                  *
00014  * You should have received a copy of the GNU General Public License*
00015  * along with this program; if not, contact:                        *
00016  *                                                                  *
00017  * Free Software Foundation           Voice:  +1-617-542-5942       *
00018  * 51 Franklin Street, Fifth Floor    Fax:    +1-617-542-2652       *
00019  * Boston, MA  02110-1301,  USA       gnu@gnu.org                   *
00020  *                                                                  *
00021 \********************************************************************/
00022 
00023 /*
00024  * FILE:
00025  * basiccell.h
00026  *
00027  * FUNCTION:
00028  * The BasicCell class provides an abstract base class
00029  * defining the handling of the editing of a cell of a table.
00030  * Classes that provide the actual handling for different
00031  * cell types should inherit from this class.
00032  *
00033  * The BasicCell class encapsulates a single string value
00034  * which can be set & read by the programmer, and edited
00035  * by the "user".  In the text below, the "user" is the
00036  * person controlling the mouse and keyboard.  Thus, when
00037  * the user makes a move, it means that they have somehow
00038  * interacted with the cell, by clicking with mouse or by
00039  * typing at the keyboard.  This class provides three
00040  * callbacks which allow the programmer to understand what
00041  * the user is doing.
00042  *
00043  * The programmer can create a custom GUI for editing the
00044  * contents of the cell. There are three callbacks to allow
00045  * a custom GUI to be created, destroyed and moved about.
00046  *
00047  * Since this class is implemented in C not C++, there is
00048  * a "minor" problem with inheritance.  To emulate the
00049  * overloading of a virtual "SetValues" method, there is
00050  * a set_value() callback, which will be called whenever
00051  * the xaccSetBasicCellValue() subroutine is called.
00052  *
00053  * VIRTUAL/OVERLOADED METHODS:
00054  * The set_value() callback will be called whenever the
00055  * xaccSetBasicCellValue() method is called.  Derived
00056  * classes should provide a callback here if they need
00057  * to understand special cell formats.
00058  *
00059  * USER CALLBACKS:
00060  * The enter_cell() callback is called when the user first
00061  *    makes a move to enter a cell.  This might be by clicking
00062  *    on the cell with the mouse, by tabbing to it, using the
00063  *    arrow keys, or otherwise "selecting" it as the current
00064  *    cell to edit.
00065  *
00066  *    The callback may change the value of the cell. The callback
00067  *    should return true if the cell should allow direct editing
00068  *    by the user, FALSE otherwise.
00069  *
00070  *    The callback is also passed pointers to the cursor position
00071  *    and the start and end of the highlited region. If the callback
00072  *    returns NULL, it may also change these values and the GUI will
00073  *    update appropriately.
00074  *
00075  * The leave_cell() callback is called when the user exits
00076  *    a cell.  This can be by tabbing or arrow-keying away
00077  *    from it, or by using the mouse to specify a different
00078  *    cell, etc. The callback may change the value of the cell.
00079  *
00080  * The modify_verify() callback is called when a user makes a
00081  *    change to a cell.  It is called after every keystroke,
00082  *    (actually, after every X11 "input-method" type input,
00083  *    so that ctrl-alt-etc modifier keys are pre-processed in
00084  *    the usual X11 fashion).
00085  *
00086  *    The arguments passed in are :
00087  *    "add", the string the user is attempting to add
00088  *           (will be null if text is being deleted).
00089  *    "new", the string that would result is user's changes
00090  *           are accepted.
00091  *    "cursor_position", the position of the editing cursor
00092  *                       in the text. This may be modified by
00093  *                       the callback, in which case the GUI
00094  *                       will reflect the change. Set to -1
00095  *                       to make the cursor go to the end of
00096  *                       the text.
00097  *    "start_selection", the starting character of the highlited
00098  *                       selection.
00099  *    "end_selection",   the index immediately after the last
00100  *                       character in the selection. Set both
00101  *                       start and end to 0 for no selection.
00102  *                       Set the end to -1 to make the selection
00103  *                       go to the end of the text.
00104  *
00105  * The direct_update() callback is called to pass raw gui data
00106  *    to the cell. The exact format of the data is determined
00107  *    by the gui. The callback should return TRUE if the event
00108  *    was handled, i.e., there is no need to call the modify
00109  *    update. If the value needs to be changed, the cell should
00110  *    go ahead and change it.
00111  *
00112  *
00113  * GUI CALLBACKS:
00114  * The cell may have some specific GUI elements which need
00115  * to be initialized/positioned/etc.  There are three GUI
00116  * callbacks that allow the programmer to perform GUI-specific
00117  * initialization & changes.
00118  *
00119  * The gui_realize() callback will be called when GUI-specific
00120  *    initialization needs to be done. For Gnome, the second
00121  *    argument will be cast to the parent widget.
00122  *
00123  * The gui_destroy() callback will be called when the GUI associated
00124  *    with the cell needs to be destroyed.
00125  *
00126  * The gui_move() callback will be called when the GUI element needs
00127  *    to be positioned to a new location within the table grid.
00128  *    The second argument is the virtual location the GUI
00129  *    element should be moved to.
00130  *
00131  * The gui_private member may be used by the derived class to
00132  *    store any additional GUI-specific data.
00133  *
00134  * HISTORY:
00135  * Copyright (c) 1998 Linas Vepstas
00136  * Copyright (c) 2000 Dave Peticolas <dave@krondo.com>
00137  */
00138 
00139 #ifndef BASIC_CELL_H
00140 #define BASIC_CELL_H
00141 
00142 #include <gdk/gdk.h>
00143 #include <glib.h>
00144 #include <gtk/gtk.h>
00145 
00146 
00147 typedef struct basic_cell BasicCell;
00148 
00149 typedef BasicCell * (*CellCreateFunc) (void);
00150 
00151 typedef void (*CellSetValueFunc) (BasicCell *cell,
00152                                   const char * new_value);
00153 
00154 typedef gboolean (*CellEnterFunc) (BasicCell *cell,
00155                                    int *cursor_position,
00156                                    int *start_selection,
00157                                    int *end_selection);
00158 
00159 typedef void (*CellModifyVerifyFunc) (BasicCell *cell,
00160                                       const char *add_str,
00161                                       int add_str_len,
00162                                       const char *new_value,
00163                                       int new_value_len,
00164                                       int *cursor_position,
00165                                       int *start_selection,
00166                                       int *end_selection);
00167 
00168 typedef gboolean (*CellDirectUpdateFunc) (BasicCell *cell,
00169         int *cursor_position,
00170         int *start_selection,
00171         int *end_selection,
00172         gpointer gui_data);
00173 
00174 typedef void (*CellLeaveFunc) (BasicCell *cell);
00175 
00176 typedef void (*CellRealizeFunc) (BasicCell *cell, gpointer gui_handle);
00177 
00178 typedef void (*CellMoveFunc) (BasicCell *cell);
00179 
00180 typedef void (*CellDestroyFunc) (BasicCell *cell);
00181 
00182 typedef enum
00183 {
00184     CELL_ALIGN_RIGHT,
00185     CELL_ALIGN_CENTER,
00186     CELL_ALIGN_LEFT
00187 } CellAlignment;
00188 
00189 struct basic_cell
00190 {
00191     char * cell_name;
00192     gchar *cell_type_name;
00193     char * value;                  /* current value */
00194     guint value_chars;           /* number of characters in value */
00195 
00196     gboolean changed;               /* true if value modified */
00197     gboolean conditionally_changed; /* true if value modified conditionally */
00198 
00199     /* "virtual", overloaded methods */
00200     CellSetValueFunc set_value;
00201     CellDestroyFunc  destroy;
00202 
00203     /* cell-editing callbacks */
00204     CellEnterFunc        enter_cell;
00205     CellModifyVerifyFunc modify_verify;
00206     CellDirectUpdateFunc direct_update;
00207     CellLeaveFunc        leave_cell;
00208 
00209     /* private, GUI-specific callbacks */
00210     CellRealizeFunc gui_realize;
00211     CellMoveFunc    gui_move;
00212     CellDestroyFunc gui_destroy;
00213 
00214     /* GUI information */
00215     char *sample_text;       /* sample text for sizing purposes */
00216     CellAlignment alignment; /* horizontal alignment in column */
00217     gboolean expandable;     /* can fill with extra space */
00218     gboolean span;           /* can span multiple columns */
00219     gboolean is_popup;       /* is a popup widget */
00220 
00221     /* general hook for gui-private data */
00222     gpointer gui_private;
00223 };
00224 
00225 
00226 gboolean     gnc_cell_name_equal (const char * cell_name_1,
00227                                   const char * cell_name_2);
00228 
00229 BasicCell *  gnc_basic_cell_new (void);
00230 void         gnc_basic_cell_init (BasicCell *bcell);
00231 void         gnc_basic_cell_destroy (BasicCell *bcell);
00232 
00233 void         gnc_basic_cell_set_name (BasicCell *cell, const char *name);
00234 gboolean     gnc_basic_cell_has_name (BasicCell *cell, const char *name);
00235 void         gnc_basic_cell_set_type_name (BasicCell *cell, const gchar *type_name);
00236 gboolean     gnc_basic_cell_has_type_name (BasicCell *cell, const gchar *type_name);
00237 
00238 
00239 
00240 void         gnc_basic_cell_set_sample_text (BasicCell *cell,
00241         const char *sample_text);
00242 void         gnc_basic_cell_set_alignment (BasicCell *cell,
00243         CellAlignment alignment);
00244 void         gnc_basic_cell_set_expandable (BasicCell *cell,
00245         gboolean expandable);
00246 void         gnc_basic_cell_set_span (BasicCell *cell,
00247                                       gboolean span);
00248 
00249 const char * gnc_basic_cell_get_value (BasicCell *cell);
00250 void         gnc_basic_cell_set_value (BasicCell *bcell, const char *value);
00251 
00252 gboolean     gnc_basic_cell_get_changed (BasicCell *cell);
00253 gboolean     gnc_basic_cell_get_conditionally_changed (BasicCell *cell);
00254 
00255 void         gnc_basic_cell_set_changed (BasicCell *cell, gboolean changed);
00256 void         gnc_basic_cell_set_conditionally_changed (BasicCell *cell,
00257         gboolean changed);
00258 
00259 /* for sub-class use only */
00260 void         gnc_basic_cell_set_value_internal (BasicCell *bcell,
00261         const char *value);
00262 
00263 #endif /* BASIC_CELL_H */
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Defines