Commit | Line | Data |
---|---|---|
86530b38 AT |
1 | /* |
2 | * tixGrid.h -- | |
3 | * | |
4 | * Defines main data structures for tixGrid | |
5 | * | |
6 | * Copyright (c) 1996, Expert Interface Technologies | |
7 | * | |
8 | * See the file "license.terms" for information on usage and redistribution | |
9 | * of this file, and for a DISCLAIMER OF ALL WARRANTIES. | |
10 | * | |
11 | */ | |
12 | ||
13 | #ifndef _TIX_GRID_H_ | |
14 | #define _TIX_GRID_H_ | |
15 | #include "tkVMacro.h" | |
16 | ||
17 | #ifndef _TIX_GRID_DATA_H_ | |
18 | #include "tixGrData.h" | |
19 | #endif | |
20 | ||
21 | #define TIX_X 0 | |
22 | #define TIX_Y 1 | |
23 | ||
24 | ||
25 | #define TIX_S_MARGIN 0 | |
26 | #define TIX_X_MARGIN 1 | |
27 | #define TIX_Y_MARGIN 2 | |
28 | #define TIX_MAIN 3 | |
29 | ||
30 | #define TIX_SITE_NONE -1 | |
31 | ||
32 | typedef struct TixGrEntry { | |
33 | Tix_DItem * iPtr; | |
34 | Tcl_HashEntry * entryPtr[2]; /* The index of this entry in the | |
35 | * row/col tables */ | |
36 | } TixGrEntry; | |
37 | ||
38 | /*---------------------------------------------------------------------- | |
39 | * Render Block | |
40 | * | |
41 | * Before the Grid is rendered, information is filled into a pseudo 2D | |
42 | * array of RenderBlockElem's: | |
43 | * | |
44 | * (1) entries are placed in the appropriate (x,y) locations | |
45 | * (2) background and borders are formatted according | |
46 | * (3) highlights are formatted. | |
47 | * | |
48 | * The widget is redrawn using the render-block. This saves reformatting | |
49 | * the next time the widget is exposed. | |
50 | *---------------------------------------------------------------------- | |
51 | */ | |
52 | typedef struct RenderBlockElem { | |
53 | TixGrEntry * chPtr; /* not allocated, don't need to free */ | |
54 | int borderW[2][2]; | |
55 | int index[2]; | |
56 | ||
57 | unsigned int selected : 1; | |
58 | unsigned int filled : 1; | |
59 | } RenderBlockElem; | |
60 | ||
61 | ||
62 | /* ElmDispSize -- | |
63 | * | |
64 | * This structure stores the size information of the visible | |
65 | * rows (RenderBlock.dispSize[0][...]) and columns | |
66 | * (RenderBlock.dispSize[1][...]) | |
67 | */ | |
68 | typedef struct ElmDispSize { | |
69 | int preBorder; | |
70 | int size; | |
71 | int postBorder; | |
72 | ||
73 | int total; /* simple the sum of the above */ | |
74 | } ElmDispSize; | |
75 | ||
76 | typedef struct RenderBlock { | |
77 | int size[2]; /* num of rows and cols in the render block */ | |
78 | ||
79 | RenderBlockElem **elms; /* An Malloc'ed pseudo 2D array (you can do | |
80 | * things like elms[0][0]), Used for the | |
81 | * main body of the Grid. | |
82 | */ | |
83 | ElmDispSize *dispSize[2]; /* (dispSizes[0][x], dispSizes[1][y]) | |
84 | * will be the dimension of the element (x,y) | |
85 | * displayed on the screen (may be bigger | |
86 | * or smaller than its desired size). */ | |
87 | int visArea[2]; /* visible area (width times height) of | |
88 | * the visible cells on the screen */ | |
89 | } RenderBlock; | |
90 | ||
91 | /*---------------------------------------------------------------------- | |
92 | * RenderInfo | |
93 | * | |
94 | * This stores information for rendering from the RB into an X drawable. | |
95 | * | |
96 | *---------------------------------------------------------------------- | |
97 | */ | |
98 | typedef struct RenderInfo { | |
99 | Drawable drawable; | |
100 | int origin[2]; | |
101 | int offset[2]; | |
102 | int size[2]; /* width and height of the area to draw | |
103 | * (number of pixels starting from the offset) | |
104 | * if offset = (2,2) and size = (5,5) we have | |
105 | * to draw the rectangle ((2,2), (6,6)); | |
106 | */ | |
107 | struct { /* the current valid grid area for the */ | |
108 | int x1, x2, y1, y2; /* "format" command */ | |
109 | int whichArea; | |
110 | } fmt; | |
111 | } RenderInfo; | |
112 | ||
113 | typedef struct ExposedArea { | |
114 | int x1, y1, x2, y2; | |
115 | } ExposedArea, Rect; | |
116 | ||
117 | /*---------------------------------------------------------------------- | |
118 | * ColorInfo | |
119 | * | |
120 | * These colors are used by the format commands. They must be saved | |
121 | * or otherwise the colormap may be changed .. | |
122 | *---------------------------------------------------------------------- | |
123 | */ | |
124 | typedef struct ColorInfo { | |
125 | struct ColorInfo * next; | |
126 | int counter; | |
127 | int type; /* TK_CONFIG_BORDER or TK_CONFIG_COLOR */ | |
128 | long pixel; | |
129 | Tk_3DBorder border; | |
130 | XColor * color; | |
131 | } ColorInfo; | |
132 | ||
133 | /*---------------------------------------------------------------------- | |
134 | * SelectBlock | |
135 | * | |
136 | * These structures are arranged in a list and are used to determine | |
137 | * where a cell is selected. | |
138 | *---------------------------------------------------------------------- | |
139 | */ | |
140 | #define TIX_GR_CLEAR 1 | |
141 | #define TIX_GR_SET 2 | |
142 | #define TIX_GR_TOGGLE 3 | |
143 | ||
144 | #define TIX_GR_MAX 0x7fffffff | |
145 | ||
146 | #define TIX_GR_RESIZE 1 | |
147 | #define TIX_GR_REDRAW 2 | |
148 | ||
149 | ||
150 | typedef struct SelectBlock { | |
151 | struct SelectBlock * next; | |
152 | int range[2][2]; /* the top left and bottom right corners */ | |
153 | int type; /* TIX_GR_CLEAR, TIX_GR_SET, | |
154 | * TIX_GR_TOGGLE | |
155 | * | |
156 | * If several SelectBlock covers the same | |
157 | * cell, the last block in the wPtr->selList | |
158 | * determines whether this cell is selected | |
159 | * or not */ | |
160 | } SelectBlock; | |
161 | ||
162 | /*---------------------------------------------------------------------- | |
163 | * GrSortItem | |
164 | * | |
165 | * Used to sort the items in the grid | |
166 | *---------------------------------------------------------------------- | |
167 | */ | |
168 | typedef struct Tix_GrSortItem { | |
169 | Arg data; /* is usually a string, but | |
170 | * can be a pointer to an | |
171 | * arbitrary data in C API */ | |
172 | int index; /* row or column */ | |
173 | } Tix_GrSortItem; | |
174 | ||
175 | /*---------------------------------------------------------------------- | |
176 | * Data structure for iterating the cells inside the grid. | |
177 | * | |
178 | *---------------------------------------------------------------------- | |
179 | */ | |
180 | ||
181 | typedef struct Tix_GrDataRowSearch { | |
182 | struct TixGridRowCol * row; | |
183 | Tcl_HashSearch hashSearch; | |
184 | Tcl_HashEntry *hashPtr; | |
185 | } Tix_GrDataRowSearch; | |
186 | ||
187 | typedef struct Tix_GrDataCellSearch { | |
188 | char * data; | |
189 | Tcl_HashSearch hashSearch; | |
190 | Tcl_HashEntry *hashPtr; | |
191 | } Tix_GrDataCellSearch; | |
192 | ||
193 | /*---------------------------------------------------------------------- | |
194 | * | |
195 | * Main data structure of the grid widget. | |
196 | * | |
197 | *---------------------------------------------------------------------- | |
198 | */ | |
199 | typedef struct Tix_GridScrollInfo { | |
200 | LangCallback *command; | |
201 | ||
202 | int max; /* total size (width or height) of the widget*/ | |
203 | int offset; /* The top/left side of the scrolled widget */ | |
204 | int unit; /* How much should we scroll when the user */ | |
205 | ||
206 | double window; /* visible size, percentage of the total */ | |
207 | }Tix_GridScrollInfo; | |
208 | ||
209 | ||
210 | typedef struct GridStruct { | |
211 | Tix_DispData dispData; | |
212 | ||
213 | Tcl_Command widgetCmd; /* Token for button's widget command. */ | |
214 | ||
215 | /* | |
216 | * Information used when displaying widget: | |
217 | */ | |
218 | int reqSize[2]; /* For app programmer to request size */ | |
219 | ||
220 | /* | |
221 | * Information used when displaying widget: | |
222 | */ | |
223 | ||
224 | /* Border and general drawing */ | |
225 | int borderWidth; /* Width of 3-D borders. */ | |
226 | int selBorderWidth; /* Width of 3-D borders for selected items */ | |
227 | int relief; /* Indicates whether window as a whole is | |
228 | * raised, sunken, or flat. */ | |
229 | Tk_3DBorder border; /* Used for drawing the 3d border. */ | |
230 | Tk_3DBorder selectBorder; /* Used for selected background. */ | |
231 | XColor *normalFg; /* Normal foreground for text. */ | |
232 | XColor *normalBg; /* Normal background for text. */ | |
233 | XColor *selectFg; /* Color for drawing selected text. */ | |
234 | ||
235 | Tk_Uid state; /* State can only be normal or disabled. */ | |
236 | ||
237 | /* GC and stuff */ | |
238 | GC backgroundGC; /* GC for drawing background. */ | |
239 | GC selectGC; /* GC for drawing selected background. */ | |
240 | GC anchorGC; /* GC for drawing dotted anchor highlight. */ | |
241 | TixFont font; /* Default font used by the DItems. */ | |
242 | ||
243 | /* Text drawing */ | |
244 | Cursor cursor; /* Current cursor for window, or None. */ | |
245 | ||
246 | /* For highlights */ | |
247 | int highlightWidth; /* Width in pixels of highlight to draw | |
248 | * around widget when it has the focus. | |
249 | * <= 0 means don't draw a highlight. */ | |
250 | int bdPad; /* = highlightWidth + borderWidth */ | |
251 | XColor *highlightColorPtr; /* Color for drawing traversal highlight. */ | |
252 | GC highlightGC; /* For drawing traversal highlight. */ | |
253 | ||
254 | /* | |
255 | * default pad and gap values | |
256 | */ | |
257 | int padX, padY; | |
258 | ||
259 | Tk_Uid selectMode; /* Selection style: single, browse, multiple, | |
260 | * or extended. This value isn't used in C | |
261 | * code, but the Tcl bindings use it. */ | |
262 | Tk_Uid selectUnit; /* Selection unit: cell, row or column. | |
263 | * This value isn't used in C | |
264 | * code, but the Tcl bindings use it. */ | |
265 | ||
266 | /* | |
267 | * The following three sites are used according to the -selectunit. | |
268 | * if selectunit is: "cell", [0] and [1] are used; "row", only [0] | |
269 | * is used; "column", only [1] is used | |
270 | */ | |
271 | int anchor[2]; /* The current anchor unit */ | |
272 | int dropSite[2]; /* The current drop site */ | |
273 | int dragSite[2]; /* The current drop site */ | |
274 | ||
275 | /* | |
276 | * Callback commands. | |
277 | */ | |
278 | LangCallback *command; /* The command when user double-clicks */ | |
279 | LangCallback *browseCmd; /* The command to call when the selection | |
280 | * changes. */ | |
281 | LangCallback *editNotifyCmd; /* The command to call to determine whether | |
282 | * a cell is editable. */ | |
283 | LangCallback *editDoneCmd; /* The command to call when an entry has | |
284 | * been edited by the user.*/ | |
285 | LangCallback *formatCmd; /* The command to call when the Grid widget | |
286 | * needs to be reformatted (e.g, Exposure | |
287 | * events or when contents have been | |
288 | * changed). */ | |
289 | LangCallback *sizeCmd; /* The command to call when the size of | |
290 | * the listbox changes. E.g., when the user | |
291 | * add/deletes elements. Useful for auto- | |
292 | * scrollbar geometry managers */ | |
293 | ||
294 | /* | |
295 | * Info for lay-out | |
296 | */ | |
297 | char *takeFocus; /* Value of -takefocus option; not used in | |
298 | * the C code, but used by keyboard traversal | |
299 | * scripts. Malloc'ed, but may be NULL. */ | |
300 | ||
301 | int serial; /* this number is incremented before each time | |
302 | * the widget is redisplayed */ | |
303 | ||
304 | TixGridDataSet * dataSet; | |
305 | RenderBlock * mainRB; /* Malloc'ed */ | |
306 | ||
307 | int hdrSize[2]; /* number of rows (height of x header, index | |
308 | * [0]) and columns (width of y header, index | |
309 | * [1]) */ | |
310 | int floatRange[2]; /* Are the num of columns and rows floated? | |
311 | * (if floated, you can scroll past the max | |
312 | * element).*/ | |
313 | int gridSize[2]; /* the size of the grid where there is data */ | |
314 | Tix_DItemInfo * diTypePtr; /* Default item type */ | |
315 | ExposedArea expArea; | |
316 | ||
317 | RenderInfo * renderInfo; /* only points to stuff in stack */ | |
318 | Tix_GridScrollInfo scrollInfo[2]; | |
319 | int fontSize[2]; /* size of the "0" char of the -font option | |
320 | */ | |
321 | TixGridSize defSize[2]; | |
322 | Tix_LinkList colorInfo; | |
323 | Tix_LinkList selList; | |
324 | Tix_LinkList mappedWindows; | |
325 | int colorInfoCounter; | |
326 | ||
327 | unsigned int hasFocus : 1; | |
328 | ||
329 | unsigned int idleEvent : 1; | |
330 | unsigned int toResize : 1; /* idle event */ | |
331 | unsigned int toRedraw : 1; /* idle event */ | |
332 | ||
333 | unsigned int toResetRB : 1; /* Do we need to reset the render block */ | |
334 | unsigned int toComputeSel : 1; | |
335 | unsigned int toRedrawHighlight : 1; | |
336 | } Grid; | |
337 | ||
338 | typedef Grid WidgetRecord; | |
339 | typedef Grid * WidgetPtr; | |
340 | ||
341 | #define DEF_GRID_BG_COLOR NORMAL_BG | |
342 | #define DEF_GRID_BG_MONO WHITE | |
343 | #define DEF_GRID_BORDER_WIDTH "2" | |
344 | #define DEF_GRID_BROWSE_COMMAND "" | |
345 | #define DEF_GRID_COMMAND "" | |
346 | #define DEF_GRID_CURSOR "" | |
347 | #define DEF_GRID_DEFAULT_WIDTH "40" | |
348 | #define DEF_GRID_DEFAULT_HEIGHT "20" | |
349 | #define DEF_GRID_EDITDONE_COMMAND "" | |
350 | #define DEF_GRID_EDITNOTIFY_COMMAND "" | |
351 | #define DEF_GRID_FLOATING_ROWS "0" | |
352 | #define DEF_GRID_FLOATING_COLS "0" | |
353 | #define DEF_GRID_FONT "-Adobe-Helvetica-Bold-R-Normal--*-120-*" | |
354 | #define DEF_GRID_FG_COLOR BLACK | |
355 | #define DEF_GRID_FG_MONO BLACK | |
356 | #define DEF_GRID_FORMAT_COMMAND "" | |
357 | #define DEF_GRID_HEIGHT "10" | |
358 | #define DEF_GRID_HIGHLIGHT_COLOR BLACK | |
359 | #define DEF_GRID_HIGHLIGHT_MONO BLACK | |
360 | #define DEF_GRID_HIGHLIGHT_WIDTH "2" | |
361 | #define DEF_GRID_LEFT_MARGIN "1" | |
362 | #define DEF_GRID_ITEM_TYPE "text" | |
363 | #define DEF_GRID_RELIEF "sunken" | |
364 | #define DEF_GRID_PADX "2" | |
365 | #define DEF_GRID_PADY "2" | |
366 | #define DEF_GRID_SELECT_BG_COLOR ACTIVE_BG | |
367 | #define DEF_GRID_SELECT_FG_COLOR BLACK | |
368 | #define DEF_GRID_SELECT_BG_MONO BLACK | |
369 | #define DEF_GRID_SELECT_FG_MONO WHITE | |
370 | #define DEF_GRID_SELECT_MODE "single" | |
371 | #define DEF_GRID_SELECT_UNIT "row" | |
372 | #define DEF_GRID_SELECT_BORDERWIDTH "1" | |
373 | #define DEF_GRID_STATE "normal" | |
374 | #define DEF_GRID_SIZE_COMMAND "" | |
375 | #define DEF_GRID_TAKE_FOCUS "1" | |
376 | #define DEF_GRID_TOP_MARGIN "1" | |
377 | #define DEF_GRID_WIDTH "4" | |
378 | #define DEF_GRID_Y_SCROLL_COMMAND "" | |
379 | #define DEF_GRID_X_SCROLL_COMMAND "" | |
380 | ||
381 | /* | |
382 | * common functions | |
383 | */ | |
384 | ||
385 | EXTERN void Tix_GrAddChangedRect _ANSI_ARGS_(( | |
386 | WidgetPtr wPtr, int changedRect[2][2], | |
387 | int isSite)); | |
388 | EXTERN int Tix_GrConfigSize _ANSI_ARGS_((Tcl_Interp *interp, | |
389 | WidgetPtr wPtr, int argc, Tcl_Obj **objv, | |
390 | TixGridSize *sizePtr, char * argcErrorMsg, | |
391 | int *changed_ret)); | |
392 | EXTERN void Tix_GrDoWhenIdle _ANSI_ARGS_((WidgetPtr wPtr, | |
393 | int type)); | |
394 | EXTERN void Tix_GrCancelDoWhenIdle _ANSI_ARGS_((WidgetPtr wPtr)); | |
395 | EXTERN void Tix_GrFreeElem _ANSI_ARGS_((TixGrEntry * chPtr)); | |
396 | EXTERN void Tix_GrFreeUnusedColors _ANSI_ARGS_((WidgetPtr wPtr, | |
397 | int freeAll)); | |
398 | EXTERN void Tix_GrScrollPage _ANSI_ARGS_((WidgetPtr wPtr, | |
399 | int count, int axis)); | |
400 | ||
401 | /* | |
402 | * The dataset functions | |
403 | */ | |
404 | ||
405 | EXTERN int TixGridDataConfigRowColSize _ANSI_ARGS_(( | |
406 | Tcl_Interp * interp, WidgetPtr wPtr, | |
407 | TixGridDataSet * dataSet, int which, int index, | |
408 | int argc, Tcl_Obj **objv, char * argcErrorMsg, | |
409 | int *changed_ret)); | |
410 | EXTERN char * TixGridDataCreateEntry _ANSI_ARGS_(( | |
411 | TixGridDataSet * dataSet, int x, int y, | |
412 | char * defaultEntry)); | |
413 | EXTERN int TixGridDataDeleteEntry _ANSI_ARGS_(( | |
414 | TixGridDataSet * dataSet, int x, int y)); | |
415 | EXTERN void TixGridDataDeleteRange _ANSI_ARGS_((WidgetPtr wPtr, | |
416 | TixGridDataSet * dataSet, int which, | |
417 | int from, int to)); | |
418 | EXTERN void TixGridDataDeleteSearchedEntry _ANSI_ARGS_(( | |
419 | Tix_GrDataCellSearch * cellSearchPtr)); | |
420 | EXTERN char * TixGridDataFindEntry _ANSI_ARGS_(( | |
421 | TixGridDataSet * dataSet, int x, int y)); | |
422 | EXTERN int TixGrDataFirstCell _ANSI_ARGS_(( | |
423 | Tix_GrDataRowSearch * rowSearchPtr, | |
424 | Tix_GrDataCellSearch * cellSearchPtr)); | |
425 | EXTERN int TixGrDataFirstRow _ANSI_ARGS_(( | |
426 | TixGridDataSet* dataSet, | |
427 | Tix_GrDataRowSearch * rowSearchPtr)); | |
428 | EXTERN int TixGridDataGetRowColSize _ANSI_ARGS_(( | |
429 | WidgetPtr wPtr, TixGridDataSet * dataSet, | |
430 | int which, int index, TixGridSize * defSize, | |
431 | int *pad0, int * pad1)); | |
432 | EXTERN void TixGridDataGetGridSize _ANSI_ARGS_(( | |
433 | TixGridDataSet * dataSet, int *width_ret, | |
434 | int *height_ret)); | |
435 | EXTERN int TixGridDataGetIndex _ANSI_ARGS_(( | |
436 | Tcl_Interp * interp, WidgetPtr wPtr, | |
437 | Arg xStr, Arg yStr, int * xPtr, int * yPtr)); | |
438 | EXTERN void TixGridDataInsert _ANSI_ARGS_(( | |
439 | TixGridDataSet * dataSet, | |
440 | int x, int y, ClientData data)); | |
441 | EXTERN void TixGridDataMoveRange _ANSI_ARGS_((WidgetPtr wPtr, | |
442 | TixGridDataSet * dataSet, int which, | |
443 | int from, int to, int by)); | |
444 | EXTERN int TixGrDataNextCell _ANSI_ARGS_(( | |
445 | Tix_GrDataCellSearch * cellSearchPtr)); | |
446 | EXTERN int TixGrDataNextRow _ANSI_ARGS_(( | |
447 | Tix_GrDataRowSearch * rowSearchPtr)); | |
448 | EXTERN TixGridDataSet* TixGridDataSetInit _ANSI_ARGS_((void)); | |
449 | EXTERN void TixGridDataSetFree _ANSI_ARGS_(( | |
450 | TixGridDataSet* dataSet)); | |
451 | EXTERN int TixGridDataUpdateSort _ANSI_ARGS_(( | |
452 | TixGridDataSet * dataSet, int axis, | |
453 | int start, int end, Tix_GrSortItem *items)); | |
454 | ||
455 | #endif /*_TIX_GRID_H_*/ |