OpenCores
URL https://opencores.org/ocsvn/or1k/or1k/trunk

Subversion Repositories or1k

[/] [or1k/] [trunk/] [insight/] [libgui/] [src/] [tkTable.h] - Blame information for rev 1765

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 578 markom
/*
2
 * tkTable.h --
3
 *
4
 *      This is the header file for the module that implements
5
 *      table widgets for the Tk toolkit.
6
 *
7
 * Copyright (c) 1997,1998 Jeffrey Hobbs
8
 *
9
 * See the file "license.terms" for information on usage and redistribution
10
 * of this file, and for a DISCLAIMER OF ALL WARRANTIES.
11
 *
12
 */
13
 
14
#ifndef _TKTABLE_H_
15
#define _TKTABLE_H_
16
 
17
#include <string.h>
18
#include <stdlib.h>
19
#include <tk.h>
20
#include <X11/Xatom.h>
21
 
22
#include "tkTableCmd.h"
23
 
24
#ifdef _WIN32
25
#   define WIN32_LEAN_AND_MEAN
26
#   include <windows.h>
27
#   undef WIN32_LEAN_AND_MEAN
28
 
29
/*
30
 * VC++ has an alternate entry point called DllMain, so we need to rename
31
 * our entry point.
32
 */
33
 
34
#   if defined(_MSC_VER)
35
#       define EXPORT(a,b) __declspec(dllexport) a b
36
#       define DllEntryPoint DllMain
37
#   else
38
#       if defined(__BORLANDC__)
39
#           define EXPORT(a,b) a _export b
40
#       else
41
#           define EXPORT(a,b) a b
42
#       endif
43
#   endif
44
 
45
/* Necessary to get XSync call defined */
46
#   include <tkInt.h>
47
 
48
#else   /* ! WIN32 */
49
#   define EXPORT(a,b) a b
50
#endif  /* WIN32 */
51
 
52
#ifdef INLINE
53
#undef INLINE
54
#endif
55
#ifdef __GNUC__
56
#    define INLINE inline
57
#else
58
#    if defined(_MSC_VER)
59
#       define INLINE __inline
60
#    else
61
#       define INLINE
62
#    endif
63
#endif
64
 
65
#ifndef NORMAL_BG
66
#       ifdef _WIN32
67
#               define NORMAL_BG        "SystemButtonFace"
68
#               define ACTIVE_BG        NORMAL_BG
69
#               define SELECT_BG        "SystemHighlight"
70
#               define DISABLED         "SystemDisabledText"
71
#               define HIGHLIGHT        "SystemWindowFrame"
72
#               define DEF_TABLE_FONT   "{MS Sans Serif} 8"
73
#       else
74
#               define NORMAL_BG        "#d9d9d9"
75
#               define ACTIVE_BG        "#fcfcfc"
76
#               define SELECT_BG        "#c3c3c3"
77
#               define DISABLED         "#a3a3a3"
78
#               define HIGHLIGHT        "Black"
79
#               define DEF_TABLE_FONT   "Helvetica -12"
80
#       endif
81
#endif
82
 
83
#define MAX(A,B)        (((A)>(B))?(A):(B))
84
#define MIN(A,B)        (((A)>(B))?(B):(A))
85
#define ARSIZE(A)       (sizeof(A)/sizeof(*A))
86
#define INDEX_BUFSIZE   64              /* max size of buffer for indices */
87
#define TEST_KEY        "#TEST KEY#"    /* index for testing array existence */
88
 
89
/*
90
 * Assigned bits of "flags" fields of Table structures, and what those
91
 * bits mean:
92
 *
93
 * REDRAW_PENDING:      Non-zero means a DoWhenIdle handler has
94
 *                      already been queued to redisplay the table.
95
 * REDRAW_BORDER:       Non-zero means 3-D border must be redrawn
96
 *                      around window during redisplay.  Normally
97
 *                      only text portion needs to be redrawn.
98
 * CURSOR_ON:           Non-zero means insert cursor is displayed at
99
 *                      present.  0 means it isn't displayed.
100
 * TEXT_CHANGED:        Non-zero means the active cell text is being edited.
101
 * HAS_FOCUS:           Non-zero means this window has the input focus.
102
 * HAS_ACTIVE:          Non-zero means the active cell is set.
103
 * HAS_ANCHOR:          Non-zero means the anchor cell is set.
104
 * BROWSE_CMD:          Non-zero means we're evaluating the -browsecommand.
105
 * VALIDATING:          Non-zero means we are in a valCmd
106
 * SET_ACTIVE:          About to set the active array element internally
107
 * ACTIVE_DISABLED:     Non-zero means the active cell is -state disabled
108
 * OVER_BORDER:         Non-zero means we are over a table cell border
109
 * REDRAW_ON_MAP:       Forces a redraw on the unmap
110
 *
111
 * FIX - consider adding UPDATE_SCROLLBAR a la entry
112
 */
113
#define REDRAW_PENDING          (1L<<0)
114
#define CURSOR_ON               (1L<<1)
115
#define HAS_FOCUS               (1L<<2)
116
#define TEXT_CHANGED            (1L<<3)
117
#define HAS_ACTIVE              (1L<<4)
118
#define HAS_ANCHOR              (1L<<5)
119
#define BROWSE_CMD              (1L<<6)
120
#define REDRAW_BORDER           (1L<<7)
121
#define VALIDATING              (1L<<8)
122
#define SET_ACTIVE              (1L<<9)
123
#define ACTIVE_DISABLED         (1L<<10)
124
#define OVER_BORDER             (1L<<11)
125
#define REDRAW_ON_MAP           (1L<<12)
126
 
127
/* Flags for TableInvalidate && TableRedraw */
128
#define ROW             (1L<<0)
129
#define COL             (1L<<1)
130
#define CELL            (ROW|COL)
131
#define INV_FILL        (1L<<3) /* use for Redraw when the affected
132
                                 * row/col will affect neighbors */
133
#define INV_FORCE       (1L<<4)
134
#define INV_HIGHLIGHT   (1L<<5)
135
 
136
/*
137
 * Definitions for tablePtr->dataSource, by bit
138
 */
139
#define DATA_NONE       0
140
#define DATA_CACHE      (1<<1)
141
#define DATA_ARRAY      (1<<2)
142
#define DATA_COMMAND    (1<<3)
143
 
144
typedef enum {
145
  STATE_UNUSED, STATE_UNKNOWN, STATE_HIDDEN,
146
  STATE_NORMAL, STATE_DISABLED, STATE_ACTIVE,
147
  STATE_LAST
148
} TableState;
149
 
150
/* The tag structure */
151
typedef struct {
152
  Tk_3DBorder   bg;             /* background color */
153
  Tk_3DBorder   fg;             /* foreground color */
154
  int           relief;         /* relief type */
155
  Tk_Font       tkfont;         /* Information about text font, or NULL. */
156
  Tk_Anchor     anchor;         /* default anchor point */
157
  char *        imageStr;       /* name of image */
158
  Tk_Image      image;          /* actual pointer to image, if any */
159
  TableState    state;          /* state of the cell */
160
  Tk_Justify    justify;        /* justification of text in the cell */
161
  int           multiline;      /* wrapping style of multiline text */
162
  int           wrap;           /* wrapping style of multiline text */
163
  int           showtext;       /* whether to display text over image */
164
} TableTag;
165
 
166
/*  The widget structure for the table Widget */
167
 
168
typedef struct {
169
  /* basic information about the window and the interpreter */
170
  Tk_Window tkwin;
171
  Display *display;
172
  Tcl_Interp *interp;
173
  Tcl_Command widgetCmd;        /* Token for entry's widget command. */
174
  /* Configurable Options */
175
  int autoClear;
176
  char *selectMode;             /* single, browse, multiple, or extended */
177
  int selectType;               /* row, col, both, or cell */
178
  int selectTitles;             /* whether to do automatic title selection */
179
  int rows, cols;               /* number of rows and columns */
180
  int defRowHeight;             /* default row height in chars (positive)
181
                                 * or pixels (negative) */
182
  int defColWidth;              /* default column width in chars (positive)
183
                                 * or pixels (negative) */
184
  int maxReqCols;               /* the requested # cols to display */
185
  int maxReqRows;               /* the requested # rows to display */
186
  int maxReqWidth;              /* the maximum requested width in pixels */
187
  int maxReqHeight;             /* the maximum requested height in pixels */
188
  char *arrayVar;               /* name of traced array variable */
189
  char *rowSep;                 /* separator string to place between
190
                                 * rows when getting selection */
191
  char *colSep;                 /* separator string to place between
192
                                 * cols when getting selection */
193
  int borderWidth;              /* internal borderwidth */
194
  TableTag defaultTag;          /* the default tag colors/fonts etc */
195
  char *yScrollCmd;             /* the y-scroll command */
196
  char *xScrollCmd;             /* the x-scroll command */
197
  char *browseCmd;              /* the command that is called when the
198
                                 * active cell changes */
199
  int caching;                  /* whether to cache values of table */
200
  char *command;                /* A command to eval when get/set occurs
201
                                 * for table values */
202
  int useCmd;                   /* Signals whether to use command or the
203
                                 * array variable, will be 0 if command errs */
204
  char *selCmd;                 /* the command that is called to when a
205
                                 * [selection get] call occurs for a table */
206
  char *valCmd;                 /* Command prefix to use when invoking
207
                                 * validate command.  NULL means don't
208
                                 * invoke commands.  Malloc'ed. */
209
  int validate;                 /* Non-zero means try to validate */
210
  Tk_3DBorder insertBg;         /* the cursor color */
211
  Tk_Cursor cursor;             /* the regular mouse pointer */
212
  Tk_Cursor bdcursor;           /* the mouse pointer when over borders */
213
  int exportSelection;          /* Non-zero means tie internal table
214
                                 * to X selection. */
215
  TableState state;             /* Normal or disabled.  Table is read-only
216
                                 * when disabled. */
217
  int insertWidth;              /* Total width of insert cursor. */
218
  int insertBorderWidth;        /* Width of 3-D border around insert cursor. */
219
  int insertOnTime;             /* Number of milliseconds cursor should spend
220
                                 * in "on" state for each blink. */
221
  int insertOffTime;            /* Number of milliseconds cursor should spend
222
                                 * in "off" state for each blink. */
223
  int invertSelected;           /* Whether to draw selected cells swapping
224
                                   foreground and background */
225
  int colStretch;               /* The way to stretch columns if the window
226
                                   is too large */
227
  int rowStretch;               /* The way to stretch rows if the window is
228
                                   too large */
229
  int colOffset;                /* X index of leftmost col in the display */
230
  int rowOffset;                /* Y index of topmost row in the display */
231
  int drawMode;                 /* The mode to use when redrawing */
232
  int flashMode;                /* Specifies whether flashing is enabled */
233
  int flashTime;                /* The number of ms to flash a cell for */
234
  int resize;                   /* -resizeborders option for interactive
235
                                 * resizing of borders */
236
  char *rowTagCmd, *colTagCmd;  /* script to eval for getting row/tag cmd */
237
  int highlightWidth;           /* Width in pixels of highlight to draw
238
                                 * around widget when it has the focus.
239
                                 * <= 0 means don't draw a highlight. */
240
  XColor *highlightBgColorPtr;  /* Color for drawing traversal highlight
241
                                 * area when highlight is off. */
242
  XColor *highlightColorPtr;    /* Color for drawing traversal highlight. */
243
  char *takeFocus;              /* Used only in Tcl to check if this
244
                                 * widget will accept focus */
245
  int padX, padY;               /* Extra space around text (pixels to leave
246
                                 * on each side).  Ignored for bitmaps and
247
                                 * images. */
248
 
249
  /* Cached Information */
250
  int titleRows, titleCols;     /* the number of rows|cols to use as a title */
251
  /* these are kept in real coords */
252
  int topRow, leftCol;          /* The topleft cell to display excluding the
253
                                 * fixed title rows.  This is just the
254
                                 * config request.  The actual cell used may
255
                                 * be different to keep the screen full */
256
  int anchorRow, anchorCol;     /* the row,col of the anchor cell */
257
  int activeRow, activeCol;     /* the row,col of the active cell */
258
  int oldTopRow, oldLeftCol;    /* cached by TableAdjustParams */
259
  int oldActRow, oldActCol;     /* cached by TableAdjustParams */
260
  int icursor;                  /* The index of the insertion cursor in the
261
                                   active cell */
262
  int flags;                    /* An or'ed combination of flags concerning
263
                                   redraw/cursor etc. */
264
  int dataSource;               /* where our data comes from:
265
                                 * DATA_{NONE,CACHE,ARRAY,COMMAND} */
266
  int maxWidth, maxHeight;      /* max width|height required in pixels */
267
  int charWidth, charHeight;    /* size of a character in the default font */
268
  int *colPixels;               /* Array of the pixel width of each column */
269
  int *rowPixels;               /* Array of the pixel height of each row */
270
  int *colStarts, *rowStarts;   /* Array of start pixels for rows|columns */
271
  int scanMarkX, scanMarkY;     /* Used by "scan" and "border" to mark */
272
  int scanMarkRow, scanMarkCol; /* necessary information for dragto */
273
  /* values in these are kept in user coords */
274
  Tcl_HashTable *cache;         /* value cache */
275
  /* colWidths and rowHeights are indexed from 0, so always adjust numbers
276
     by the appropriate *Offset factor */
277
  Tcl_HashTable *colWidths;     /* hash table of non default column widths */
278
  Tcl_HashTable *rowHeights;    /* hash table of non default row heights */
279
  Tcl_HashTable *tagTable;      /* table for style tags */
280
  Tcl_HashTable *winTable;      /* table for embedded windows */
281
  Tcl_HashTable *rowStyles;     /* table for row styles */
282
  Tcl_HashTable *colStyles;     /* table for col styles */
283
  Tcl_HashTable *cellStyles;    /* table for cell styles */
284
  Tcl_HashTable *flashCells;    /* table of flashing cells */
285
  Tcl_HashTable *selCells;      /* table of selected cells */
286
  Tcl_TimerToken cursorTimer;   /* timer token for the cursor blinking */
287
  Tcl_TimerToken flashTimer;    /* timer token for the cell flashing */
288
  char *activeBuf;              /* buffer where the selection is kept
289
                                   for editing the active cell */
290
  Tk_TextLayout activeLayout;   /* cache of active layout */
291
  int activeX, activeY;         /* cache offset of active layout in cell */
292
  /* The invalid rectangle if there is an update pending */
293
  int invalidX, invalidY, invalidWidth, invalidHeight;
294
  int seen[4];                  /* see TableUndisplay */
295
} Table;
296
 
297
/*
298
 * HEADERS FOR EMBEDDED WINDOWS
299
 */
300
 
301
/*
302
 * A structure of the following type holds information for each window
303
 * embedded in a table widget.
304
 */
305
 
306
typedef struct TableEmbWindow {
307
  Table *tablePtr;              /* Information about the overall table
308
                                 * widget. */
309
  Tk_Window tkwin;              /* Window for this segment.  NULL
310
                                 * means that the window hasn't
311
                                 * been created yet. */
312
  Tcl_HashEntry *hPtr;          /* entry into winTable */
313
  Tk_3DBorder bg;               /* background color */
314
  char *create;                 /* Script to create window on-demand.
315
                                 * NULL means no such script.
316
                                 * Malloc-ed. */
317
  int relief;                   /* relief type */
318
  int sticky;                   /* How to align window in space */
319
  int padX, padY;               /* Padding to leave around each side
320
                                 * of window, in pixels. */
321
  int displayed;                /* Non-zero means that the window
322
                                 * has been displayed on the screen
323
                                 * recently. */
324
} TableEmbWindow;
325
 
326
extern void     EmbWinDisplay _ANSI_ARGS_((Table *tablePtr, Drawable window,
327
                                           TableEmbWindow *ewPtr,
328
                                           TableTag *tagPtr, int x, int y,
329
                                           int width, int height));
330
extern void     EmbWinUnmap _ANSI_ARGS_((register Table *tablePtr,
331
                                         int rlo, int rhi,
332
                                         int clo, int chi));
333
extern void     EmbWinDelete _ANSI_ARGS_((register Table *tablePtr,
334
                                           TableEmbWindow *ewPtr));
335
extern int      TableWindowCmd _ANSI_ARGS_((Table *tablePtr,
336
                                            Tcl_Interp *interp,
337
                                            int argc, char *argv[]));
338
 
339
/*
340
 * HEADERS IN TKTABLETAG
341
 */
342
 
343
extern TableTag *TableNewTag _ANSI_ARGS_((void));
344
extern void     TableMergeTag _ANSI_ARGS_((TableTag *baseTag,
345
                                           TableTag *addTag));
346
extern void     TableInvertTag _ANSI_ARGS_((TableTag *baseTag));
347
extern void     TableInitTags _ANSI_ARGS_((Table *tablePtr));
348
extern TableTag *FindRowColTag _ANSI_ARGS_((Table *tablePtr,
349
                                             int cell, int type));
350
extern void     TableCleanupTag _ANSI_ARGS_((Table *tablePtr,
351
                                             TableTag *tagPtr));
352
extern int      TableTagCmd _ANSI_ARGS_((Table *tablePtr, Tcl_Interp *interp,
353
                                         int argc, char *argv[]));
354
 
355
/*
356
 * HEADERS IN TKTABLECELL
357
 */
358
 
359
extern void     TableCellCoords _ANSI_ARGS_((Table *tablePtr, int row,
360
                                             int col, int *rx, int *ry,
361
                                             int *rw, int *rh));
362
extern int      TableCellVCoords _ANSI_ARGS_((Table *tablePtr, int row,
363
                                              int col, int *rx, int *ry,
364
                                              int *rw, int *rh, int full));
365
extern void     TableWhatCell _ANSI_ARGS_((register Table *tablePtr,
366
                                           int x, int y, int *row, int *col));
367
extern int      TableAtBorder _ANSI_ARGS_((Table *tablePtr, int x, int y,
368
                                           int *row, int *col));
369
extern char *   TableGetCellValue _ANSI_ARGS_((Table *tablePtr, int r, int c));
370
extern int      TableSetCellValue _ANSI_ARGS_((Table *tablePtr, int r, int c,
371
                                               char *value));
372
extern char *   TableCellSort _ANSI_ARGS_((Table *tablePtr, char *str));
373
extern int      TableGetIcursor _ANSI_ARGS_((Table *tablePtr, char *arg,
374
                                             int *posn));
375
extern int      TableGetIndex _ANSI_ARGS_((register Table *tablePtr, char *str,
376
                                           int *row_p, int *col_p));
377
 
378
/*
379
 * HEADERS IN TKTABLE
380
 */
381
 
382
EXTERN EXPORT(int,Example_Init) _ANSI_ARGS_((Tcl_Interp *interp));
383
 
384
extern void     ExpandPercents _ANSI_ARGS_((Table *tablePtr, char *before,
385
                        int r, int c, char *old, char *new, int index,
386
                        Tcl_DString *dsPtr, int cmdType));
387
extern void     TableInvalidate _ANSI_ARGS_((Table *tablePtr, int x, int y,
388
                                             int width, int height,
389
                                             int force));
390
extern void     TableRefresh _ANSI_ARGS_((register Table *tablePtr,
391
                                          int arg1, int arg2, int mode));
392
 
393
#define TableInvalidateAll(tablePtr, flags)     \
394
        TableInvalidate((tablePtr), 0, 0, Tk_Width((tablePtr)->tkwin),\
395
                        Tk_Height((tablePtr)->tkwin), (flags))
396
 
397
     /*
398
      * Turn row/col into an index into the table
399
      */
400
#define TableMakeArrayIndex(r, c, i)    sprintf((i), "%d,%d", (r), (c))
401
 
402
     /*
403
      * Turn array index back into row/col
404
      * return the number of args parsed (should be two)
405
      */
406
#define TableParseArrayIndex(r, c, i)   sscanf((i), "%d,%d", (r), (c))
407
 
408
     /*
409
      * Macro for finding the last cell of the table
410
      */
411
#define TableGetLastCell(tablePtr, rowPtr, colPtr)      \
412
        TableWhatCell((tablePtr),\
413
                      Tk_Width((tablePtr)->tkwin)-(tablePtr)->highlightWidth,\
414
                      Tk_Height((tablePtr)->tkwin)-(tablePtr)->highlightWidth,\
415
                      (rowPtr), (colPtr))
416
 
417
#endif /* _TKTABLE_H_ */
418
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.