1 /*
2  * Copyright(c) 1992 Bell Communications Research, Inc. (Bellcore)
3  * Copyright(c) 1995-99 Andrew Lister
4  *                        All rights reserved
5  * Permission to use, copy, modify and distribute this material for
6  * any purpose and without fee is hereby granted, provided that the
7  * above copyright notice and this permission notice appear in all
8  * copies, and that the name of Bellcore not be used in advertising
9  * or publicity pertaining to this material without the specific,
10  * prior written permission of an authorized representative of
11  * Bellcore.
12  *
13  * BELLCORE MAKES NO REPRESENTATIONS AND EXTENDS NO WARRANTIES, EX-
14  * PRESS OR IMPLIED, WITH RESPECT TO THE SOFTWARE, INCLUDING, BUT
15  * NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
16  * FITNESS FOR ANY PARTICULAR PURPOSE, AND THE WARRANTY AGAINST IN-
17  * FRINGEMENT OF PATENTS OR OTHER INTELLECTUAL PROPERTY RIGHTS.  THE
18  * SOFTWARE IS PROVIDED "AS IS", AND IN NO EVENT SHALL BELLCORE OR
19  * ANY OF ITS AFFILIATES BE LIABLE FOR ANY DAMAGES, INCLUDING ANY
20  * LOST PROFITS OR OTHER INCIDENTAL OR CONSEQUENTIAL DAMAGES RELAT-
21  * ING TO THE SOFTWARE.
22  *
23  * MatrixWidget Author: Andrew Wason, Bellcore, aw@bae.bellcore.com
24  *
25  * $Id: MatrixP.h,v 1.1 1999/09/11 01:25:38 fnevgeny Exp $
26  */
27 
28 /*
29  * MatrixP.h - Private definitions for Matrix widget
30  */
31 
32 #ifndef _Xbae_MatrixP_h
33 #define _Xbae_MatrixP_h
34 
35 #if XmVersion <= 1001
36 #	include <Xm/XmP.h>
37 #else
38 #	include <Xm/ManagerP.h>
39 #endif
40 
41 #include <Xbae/Matrix.h>
42 
43 #ifndef P
44 #if defined(__STDC__) || defined (__cplusplus)
45 #define P(x)		x
46 #else
47 #define P(x)		()
48 #define const
49 #define volatile
50 #endif
51 #endif
52 
53 /*
54  * A few definitions we like to use, but those with R4 won't have.
55  * From Xfuncproto.h in R5.
56  */
57 
58 #ifndef XlibSpecificationRelease
59 # ifndef _XFUNCPROTOBEGIN
60 #   ifdef __cplusplus                      /* for C++ V2.0 */
61 #     define _XFUNCPROTOBEGIN extern "C" {   /* do not leave open across includes */
62 #     define _XFUNCPROTOEND }
63 #   else
64 #     define _XFUNCPROTOBEGIN
65 #     define _XFUNCPROTOEND
66 #   endif
67 # endif /* _XFUNCPROTOBEGIN */
68 #else
69 #include <X11/Xfuncproto.h>
70 #endif
71 
72 /*
73  * New types for the class methods
74  */
75 _XFUNCPROTOBEGIN
76 
77 typedef void (*XbaeMatrixSetCellProc) P((XbaeMatrixWidget, int, int,
78 					 const String, Boolean));
79 
80 typedef String (*XbaeMatrixGetCellProc) P((XbaeMatrixWidget, int, int));
81 
82 typedef void (*XbaeMatrixEditCellProc) P((XbaeMatrixWidget, XEvent *,
83 					  int, int, String *, Cardinal));
84 
85 typedef void (*XbaeMatrixSelectCellProc) P((XbaeMatrixWidget, int, int));
86 
87 typedef void (*XbaeMatrixSelectRowProc) P((XbaeMatrixWidget, int));
88 
89 typedef void (*XbaeMatrixSelectColumnProc) P((XbaeMatrixWidget, int));
90 
91 typedef void (*XbaeMatrixDeselectAllProc) P((XbaeMatrixWidget));
92 
93 typedef void (*XbaeMatrixSelectAllProc) P((XbaeMatrixWidget));
94 
95 typedef void (*XbaeMatrixDeselectCellProc) P((XbaeMatrixWidget, int, int));
96 
97 typedef void (*XbaeMatrixDeselectRowProc) P((XbaeMatrixWidget, int));
98 
99 typedef void (*XbaeMatrixDeselectColumnProc) P((XbaeMatrixWidget, int));
100 
101 typedef Boolean (*XbaeMatrixCommitEditProc) P((XbaeMatrixWidget, XEvent *,
102 					       Boolean));
103 
104 typedef void (*XbaeMatrixCancelEditProc) P((XbaeMatrixWidget, Boolean));
105 
106 typedef void (*XbaeMatrixAddRowsProc) P((XbaeMatrixWidget, int, String *,
107 					 String *, Pixel *, Pixel *, int));
108 
109 typedef void (*XbaeMatrixDeleteRowsProc) P((XbaeMatrixWidget, int, int));
110 
111 typedef void (*XbaeMatrixAddColumnsProc) P((XbaeMatrixWidget, int, String *,
112 					    String *, short *, int *,
113 					    unsigned char*, unsigned char *,
114 					    Pixel *, Pixel *, int));
115 
116 typedef void (*XbaeMatrixDeleteColumnsProc) P((XbaeMatrixWidget, int, int));
117 
118 typedef void (*XbaeMatrixSetRowColorsProc) P((XbaeMatrixWidget, int, Pixel *,
119 					      int, Boolean));
120 
121 typedef void (*XbaeMatrixSetColumnColorsProc) P((XbaeMatrixWidget, int,
122 						 Pixel *, int, Boolean));
123 
124 typedef void (*XbaeMatrixSetCellColorProc) P((XbaeMatrixWidget, int, int,
125 					      Pixel, Boolean));
126 
127 _XFUNCPROTOEND
128 
129 /*
130  * Different than the traversal directions in Xm.h
131  */
132 #define NOT_TRAVERSING	-1
133 
134 /*
135  * New fields for the Matrix widget class record
136  */
137 typedef struct {
138     XbaeMatrixSetCellProc		set_cell;
139     XbaeMatrixGetCellProc		get_cell;
140     XbaeMatrixEditCellProc		edit_cell;
141     XbaeMatrixSelectCellProc		select_cell;
142     XbaeMatrixSelectRowProc		select_row;
143     XbaeMatrixSelectColumnProc		select_column;
144     XbaeMatrixDeselectAllProc		deselect_all;
145     XbaeMatrixSelectAllProc		select_all;
146     XbaeMatrixDeselectCellProc		deselect_cell;
147     XbaeMatrixDeselectRowProc		deselect_row;
148     XbaeMatrixDeselectColumnProc	deselect_column;
149     XbaeMatrixCommitEditProc		commit_edit;
150     XbaeMatrixCancelEditProc		cancel_edit;
151     XbaeMatrixAddRowsProc		add_rows;
152     XbaeMatrixDeleteRowsProc		delete_rows;
153     XbaeMatrixAddColumnsProc		add_columns;
154     XbaeMatrixDeleteColumnsProc		delete_columns;
155     XbaeMatrixSetRowColorsProc		set_row_colors;
156     XbaeMatrixSetColumnColorsProc	set_column_colors;
157     XbaeMatrixSetCellColorProc		set_cell_color;
158     XtPointer				extension;
159 } XbaeMatrixClassPart;
160 
161 /*
162  * Full class record declaration
163  */
164 typedef struct _XbaeMatrixClassRec {
165     CoreClassPart		core_class;
166     CompositeClassPart		composite_class;
167     ConstraintClassPart		constraint_class;
168     XmManagerClassPart		manager_class;
169     XbaeMatrixClassPart		matrix_class;
170 } XbaeMatrixClassRec;
171 
172 externalref XbaeMatrixClassRec xbaeMatrixClassRec;
173 
174 
175 /*
176  * Inheritance constants for set/get/edit methods
177  */
178 #define XbaeInheritGetCell ((XbaeMatrixGetCellProc) _XtInherit)
179 #define XbaeInheritSetCell ((XbaeMatrixSetCellProc) _XtInherit)
180 #define XbaeInheritEditCell ((XbaeMatrixEditCellProc) _XtInherit)
181 #define XbaeInheritSelectCell ((XbaeMatrixSelectCellProc) _XtInherit)
182 #define XbaeInheritSelectRow ((XbaeMatrixSelectRowProc) _XtInherit)
183 #define XbaeInheritSelectColumn ((XbaeMatrixSelectColumnProc) _XtInherit)
184 #if XmVersion >= 1002
185 #define XbaeInheritHighlightCell ((XbaeMatrixHighlightCellProc) _XtInherit)
186 #define XbaeInheritHighlightRow ((XbaeMatrixHighlightRowProc) _XtInherit)
187 #define XbaeInheritHighlightColumn ((XbaeMatrixHighlightColumnProc) _XtInherit)
188 #endif
189 #define XbaeInheritDeselectAll ((XbaeMatrixDeselectAllProc) _XtInherit)
190 #define XbaeInheritSelectAll ((XbaeMatrixSelectAllProc) _XtInherit)
191 #define XbaeInheritDeselectCell ((XbaeMatrixDeselectCellProc) _XtInherit)
192 #define XbaeInheritDeselectRow ((XbaeMatrixDeselectRowProc) _XtInherit)
193 #define XbaeInheritDeselectColumn ((XbaeMatrixDeselectColumnProc) _XtInherit)
194 #define XbaeInheritCommitEdit ((XbaeMatrixCommitEditProc) _XtInherit)
195 #define XbaeInheritCancelEdit ((XbaeMatrixCancelEditProc) _XtInherit)
196 #define XbaeInheritAddRows ((XbaeMatrixAddRowsProc) _XtInherit)
197 #define XbaeInheritDeleteRows ((XbaeMatrixDeleteRowsProc) _XtInherit)
198 #define XbaeInheritAddColumns ((XbaeMatrixAddColumnsProc) _XtInherit)
199 #define XbaeInheritDeleteColumns ((XbaeMatrixDeleteColumnsProc)_XtInherit)
200 #define XbaeInheritSetRowColors ((XbaeMatrixSetRowColorsProc)_XtInherit)
201 #define XbaeInheritSetColumnColors ((XbaeMatrixSetColumnColorsProc)_XtInherit)
202 #define XbaeInheritSetCellColor ((XbaeMatrixSetCellColorProc)_XtInherit)
203 
204 /*
205  * New data structures for the ScrollMgr code
206  */
207 typedef struct _SmScrollNode {
208     int x;
209     int y;
210     struct _SmScrollNode *next;
211     struct _SmScrollNode *prev;
212 } SmScrollNodeRec, *SmScrollNode;
213 
214 typedef struct _SmScrollMgr {
215     int offset_x;
216     int offset_y;
217     int scroll_count;
218     SmScrollNode scroll_queue;
219     Boolean scrolling;
220 } SmScrollMgrRec, *SmScrollMgr;
221 
222 /*
223  * Rectangle struct used for internal calculations.  (x1,y1) are the upper
224  * left corner, (x2,y2) are the lower right.
225  */
226 typedef struct _Rectangle
227 {
228     int x1, y1;
229     int x2, y2;
230 }
231 Rectangle;
232 
233 /*
234  * Data structure for column labels
235  */
236 typedef struct _ColumnLabelLines {
237     int lines;
238     int *lengths;
239 } ColumnLabelLinesRec, *ColumnLabelLines;
240 
241 /*
242  * New fields for the Matrix widget record
243  */
244 typedef struct {
245     /*
246      * resources
247      */
248     Boolean	allow_column_resize;	/* can columns dynamically resize?   */
249     Boolean	bold_labels;		/* draw bold row/column labels?	     */
250     Boolean	button_labels;		/* draw labels as buttons?	     */
251     Boolean	fill;			/* fill available space?	     */
252     Boolean	trailing_attached_right;  /* trailing columns fixed to right */
253     Boolean	trailing_attached_bottom; /* trailing rows fixed to bottom   */
254     Boolean	reverse_select;		/* reverse colours - selected cells? */
255     Boolean	scroll_select;		/* flag to scroll a selected cell    */
256     Boolean	**selected_cells;	/* 2D array of selected cells	     */
257     Boolean	show_arrows;	        /* sow arrows when text obscured?    */
258     Boolean     *column_button_labels;  /* which column labels are butons */
259     Boolean     *row_button_labels;     /* which row labels are butons */
260     Boolean	traverse_fixed;		/* allow traversal to fixed cells?   */
261     Boolean	calc_cursor_position;	/* calculate insert pos from click   */
262     unsigned char cell_shadow_type;	/* cell shadow type		     */
263     unsigned char **cell_shadow_types;	/* 2D array of per cell shadow type  */
264     unsigned char *column_alignments;	/* alignment of each column	     */
265     unsigned char *column_label_alignments;/* alignment of each column label */
266     unsigned char *column_shadow_types;	/* 1D array of per col shadow types  */
267     unsigned char grid_type;		/* shadowed in/shadowed out/plain    */
268     unsigned char hsb_display_policy;	/* horiz scroll bar display policy   */
269     unsigned char row_label_alignment;	/* alignment of row labels	     */
270     unsigned char *row_shadow_types;	/* 1D array of per row shadow types  */
271     unsigned char scrollbar_placement;	/* placement of the scrollbars	     */
272     unsigned char selection_policy;	/* as for XmList */
273     unsigned char shadow_type;		/* matrix window shadow type	     */
274 #if XmVersion >= 1002
275     unsigned char **highlighted_cells;	/* 2D array of highlighted cells     */
276 #endif
277     unsigned char vsb_display_policy;	/* vert scroll bar display policy    */
278 
279     String	**cells;		/* 2D array of strings		     */
280     String	*column_labels;		/* array of labels above each column */
281     String	*row_labels;		/* array of labels next to each row  */
282 
283     XtPointer	**cell_user_data;	/* 2D array of per cell user data    */
284     XtPointer	*column_user_data;	/* 1D array of per column user data  */
285     XtPointer	*row_user_data;		/* 1D array of per row user data     */
286 
287     short	*column_widths;		/* width of each column in chars     */
288     short	row_label_width;	/* max width of row labels in chars  */
289 
290     int		alt_row_count;		/* # of rows for e/o background	     */
291     int		columns;		/* number of cells per row	     */
292     int		*column_max_lengths;	/* max length of each col in chars   */
293     int         double_click_interval;	/* interval between clicks	     */
294     int         left_column;		/* horizontal origin (in col space)  */
295     int		rows;			/* number of rows per column	     */
296     int		top_row;		/* vertical origin (in row space)    */
297 
298     Dimension	cell_highlight_thickness; /* hilite thickness for textField  */
299     Dimension	cell_margin_height;	/* margin height for textField	     */
300     Dimension	cell_margin_width;	/* margin width for textField	     */
301     Dimension	cell_shadow_thickness;	/* shadow thickness for each cell    */
302     Dimension	fixed_columns;		/* number of leading fixed columns   */
303     Dimension	fixed_rows;		/* number of leading fixed rows	     */
304     Dimension	space;			/* spacing for scrollbars	     */
305     Dimension	text_shadow_thickness;	/* shadow thickness for text field   */
306     Dimension	trailing_fixed_columns;	/* number of trailing fixed columns  */
307     Dimension	trailing_fixed_rows;	/* number of trailing fixed rows     */
308     Dimension	visible_columns;	/* number of columns to make visible */
309     Dimension	visible_rows;		/* number of rows to make visible    */
310 
311     Pixel	button_label_background; /* color of button label background */
312     Pixel	**cell_background;	/* 2D array of Pixels		     */
313     Pixel	**colors;		/* 2D array of Pixels		     */
314     Pixel	column_label_color;	/* color of column label	     */
315     Pixel	even_row_background;	/* even row background color	     */
316     Pixel	grid_line_color;	/* color of grid, for XmGrid_LINE    */
317     Pixel       odd_row_background;	/* odd row background color	     */
318     Pixel	row_label_color;	/* color of row label		     */
319     Pixel	selected_background;	/* background for selected cells     */
320     Pixel	selected_foreground;	/* foreground for selected cells     */
321     Pixel	text_background;	/* background for the "text" field   */
322 
323     XtTranslations text_translations;	/* translations for textField widget */
324 
325     XtCallbackList default_action_callback; /* called for a double click     */
326     XtCallbackList draw_cell_callback;	/* called when a cell is drawn	     */
327     XtCallbackList enter_cell_callback;	/* called when a cell is entered     */
328     XtCallbackList label_activate_callback; /* called when label pressed     */
329     XtCallbackList leave_cell_callback;	/* called when a cell is left	     */
330     XtCallbackList modify_verify_callback; /* verify change to textField     */
331 					/* and a draw_cell_callback is set   */
332 #if XmVersion > 1001
333     XtCallbackList process_drag_callback; /* called when a drag is initiated */
334 #endif
335     XtCallbackList resize_callback;	/* called when Matrix is resized     */
336     XtCallbackList resize_column_callback; /* called when column is resized  */
337     XtCallbackList select_cell_callback; /* called when cells are selected   */
338     XtCallbackList traverse_cell_callback; /* next cell to traverse to	     */
339     XtCallbackList write_cell_callback;	/*called when a cell needs to be set*/
340 
341     XmFontList	font_list;		/* fontList of widget and textField  */
342     XmFontList	label_font_list;	/* fontList of labels		     */
343 
344 
345     /*
346      * private state
347      */
348 #if XmVersion >= 1002
349     unsigned char highlight_location;	/* What is being highlighted	     */
350 #endif
351     short	first_row_offset;	/* hidden first row */
352     int		cell_visible_height;	/* height of visible cells in pixels */
353     int		column_label_maxlines;	/* max # lines in column labels	     */
354     int		*column_positions;	/* pixel position of each column     */
355     int		current_column;		/* column of the text field	     */
356     int		current_row;		/* row of the text field	     */
357     int		horiz_origin;		/* horiz origin (in pixel space)     */
358     int		label_baseline;		/* baseline of label		     */
359     int		last_column;		/* The last selected column	     */
360     int		last_row;		/* The last selected row	     */
361     int		num_selected_cells;	/* The number selected cells	     */
362     int		text_baseline;		/* baseline of text in each cell     */
363     int		traversing;		/* direction we are traversing	     */
364 
365     unsigned int non_fixed_total_width;	/* width of cell area in pixels	     */
366     unsigned int current_clip;		/* current clip mask setting	     */
367     unsigned int disable_redisplay;	/* disable redisplay counter	     */
368 
369     Dimension	desired_height;		/* height widget wants to be	     */
370     Dimension	desired_width;		/* width widget wants to be	     */
371 
372     Time	last_click_time;	/* when last ButtonPress occurred    */
373 
374     Widget	text_field;		/* the text field		     */
375     Widget	horizontal_sb;		/* the horizontal scrollbar	     */
376     Widget      vertical_sb;		/* the vertical scrollbar	     */
377     Widget	clip_window;		/* the clip child		     */
378     Widget	left_clip;		/* clips for scrolling fixed cells   */
379     Widget	right_clip;
380     Widget	top_clip;
381     Widget	bottom_clip;
382     Widget	current_parent;		/* Current textField parent window   */
383 #if CELL_WIDGETS
384     Widget	**cell_widgets;		/* array of widgets for cells	     */
385 #endif
386 
387     GC		cell_bottom_shadow_clip_gc; /* GC for clipped bottom shadow  */
388     GC          cell_grid_line_gc;
389     GC		cell_top_shadow_clip_gc; /* GC for clipped top shadow	     */
390     GC		draw_gc;		/* GC for drawing cells		     */
391     GC          grid_line_gc;		/* GC for grid line		     */
392     GC		label_clip_gc;		/* GC for clipped labels	     */
393     GC		label_gc;		/* GC for drawing labels	     */
394     GC		pixmap_gc;		/* GC for drawing pixmap cells	     */
395     GC		resize_bottom_shadow_gc;
396     GC		resize_top_shadow_gc;
397 
398     ColumnLabelLines column_label_lines; /* structs for multi line labels    */
399 
400     XFontStruct	*font_struct;		/* fontStruct from fontList	     */
401     XFontStruct	*label_font_struct;	/* fontStruct from fontList	     */
402 
403     SmScrollMgr clip_scroll_mgr;	/* ScrollMgr for Clip		     */
404     SmScrollMgr matrix_scroll_mgr;	/* ScrollMgr for Matrix		     */
405 
406     XFontSet	font_set;		/* fontSet from fontList	     */
407     short	font_y;
408     short	font_width;
409     short	font_height;
410     Font	fid;
411     XFontSet	label_font_set;		/* fontSet from fontList	     */
412     short	label_font_y;
413     short	label_font_width;
414     short	label_font_height;
415     Font	label_fid;
416 
417 } XbaeMatrixPart;
418 
419 /*
420  * Full instance record declaration
421  */
422 typedef struct _XbaeMatrixRec {
423     CorePart		core;
424     CompositePart	composite;
425     ConstraintPart	constraint;
426     XmManagerPart	manager;
427     XbaeMatrixPart	matrix;
428 } XbaeMatrixRec;
429 
430 /* provide clean-up for those with R4 */
431 #ifndef XlibSpecificationRelease
432 # undef _Xconst
433 # undef _XFUNCPROTOBEGIN
434 # undef _XFUNCPROTOEND
435 #endif
436 
437 #undef P
438 #endif /* _Xbae_MatrixP_h */
439