1 /*
2  * Copyright(c) 1992 Bell Communications Research, Inc. (Bellcore)
3  *                        All rights reserved
4  *
5  * Copyright � 2001 by the LessTif Developers.
6  *
7  * Permission to use, copy, modify and distribute this material for
8  * any purpose and without fee is hereby granted, provided that the
9  * above copyright notice and this permission notice appear in all
10  * copies, and that the name of Bellcore not be used in advertising
11  * or publicity pertaining to this material without the specific,
12  * prior written permission of an authorized representative of
13  * Bellcore.
14  *
15  * BELLCORE MAKES NO REPRESENTATIONS AND EXTENDS NO WARRANTIES, EX-
16  * PRESS OR IMPLIED, WITH RESPECT TO THE SOFTWARE, INCLUDING, BUT
17  * NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
18  * FITNESS FOR ANY PARTICULAR PURPOSE, AND THE WARRANTY AGAINST IN-
19  * FRINGEMENT OF PATENTS OR OTHER INTELLECTUAL PROPERTY RIGHTS.  THE
20  * SOFTWARE IS PROVIDED "AS IS", AND IN NO EVENT SHALL BELLCORE OR
21  * ANY OF ITS AFFILIATES BE LIABLE FOR ANY DAMAGES, INCLUDING ANY
22  * LOST PROFITS OR OTHER INCIDENTAL OR CONSEQUENTIAL DAMAGES RELAT-
23  * ING TO THE SOFTWARE.
24  *
25  * $Id: dynamic.c,v 1.7 2001/03/30 07:52:02 dannybackx Exp $
26  */
27 
28 #ifdef HAVE_CONFIG_H
29 #include <XbaeConfig.h>
30 #endif
31 #include <stdlib.h>
32 #ifdef USE_EDITRES
33 #include <X11/Intrinsic.h>
34 #include <X11/Xmu/Editres.h>
35 #endif
36 #include <Xm/RowColumn.h>
37 #include <Xm/Label.h>
38 #include <Xm/PushB.h>
39 #include <Xbae/Matrix.h>
40 
41 static String fallback[] = {
42 	"Dynamic*mw.rows:			6",
43 	"Dynamic*mw.columns:			5",
44 	"Dynamic*mw.columnWidths:		5, 15, 10, 10, 15",
45 	"Dynamic*mw.rowLabels:			Row1, Row2, Row3, Row4, Row5, RowSix",
46 	"Dynamic*mw.columnLabels:		Col1, Col2, Col3, Col4, ColFive",
47 	"Dynamic*mw.visibleRows:		6",
48 	NULL
49 };
50 
51 /*
52  * Dynamically expand the matrix when tabbing past the last row or column.
53  */
54 
55 
56 void TraverseCB(Widget w, XtPointer client_data, XbaeMatrixTraverseCellCallbackStruct *call_data);
57 
58 int
main(int argc,char * argv[])59 main(int argc, char *argv[])
60 {
61     Widget toplevel, mw;
62     XtAppContext app;
63 
64     toplevel = XtVaAppInitialize(&app, "Dynamic",
65 				 NULL, 0,
66 				 &argc, argv,
67 				 fallback,
68 				 NULL);
69 #ifdef USE_EDITRES
70     XtAddEventHandler( toplevel, (EventMask)0, True,
71                        _XEditResCheckMessages, NULL);
72 #endif
73 
74     mw = XtVaCreateManagedWidget("mw",
75 				 xbaeMatrixWidgetClass,	toplevel,
76 				 NULL);
77     XtAddCallback(mw, XmNtraverseCellCallback, (XtCallbackProc)TraverseCB, NULL);
78 
79     XtRealizeWidget(toplevel);
80     XtAppMainLoop(app);
81     /*NOTREACHED*/
82     return 0;
83 }
84 
85 /* ARGSUSED */
86 void
TraverseCB(Widget w,XtPointer client_data,XbaeMatrixTraverseCellCallbackStruct * call_data)87 TraverseCB(Widget w, XtPointer client_data, XbaeMatrixTraverseCellCallbackStruct *call_data)
88 {
89     static XrmQuark QRight = NULLQUARK;
90     static XrmQuark QDown = NULLQUARK;
91 
92     /*
93      * Get the Quarks we care about
94      */
95     if (QRight == NULLQUARK) {
96 	QRight = XrmStringToQuark("Right");
97 	QDown = XrmStringToQuark("Down");
98     }
99 
100     /*
101      * If we are moving down, and we are at the last row, add a new row
102      * and traverse to it.
103      */
104     if (call_data->qparam == QDown &&
105 	call_data->row == call_data->num_rows - 1) {
106 	XbaeMatrixAddRows(w, call_data->num_rows, NULL, NULL, NULL, 1);
107 	call_data->next_row = call_data->num_rows;
108 	call_data->next_column = call_data->column;
109     }
110     /*
111      * If we are moving right, and we are at the last column, add a new column
112      * and traverse to it.
113      */
114     else if (call_data->qparam == QRight &&
115 	call_data->column == call_data->num_columns - 1) {
116 	short width = 10;
117 	XbaeMatrixAddColumns(w, call_data->num_columns, NULL, NULL,
118 			     &width, NULL, NULL, NULL, NULL, 1);
119 	call_data->next_column = call_data->num_columns;
120 	call_data->next_row = call_data->row;
121     }
122 }
123