File: addrows.c

package info (click to toggle)
xbae 4.60.2-2
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k, lenny
  • size: 5,452 kB
  • ctags: 2,046
  • sloc: ansic: 21,858; sh: 8,195; makefile: 577; tcl: 1
file content (144 lines) | stat: -rw-r--r-- 4,742 bytes parent folder | download | duplicates (7)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
/* $Id: addrows.c,v 1.4 2004/12/04 14:54:19 dannybackx Exp $ */

#include <stdlib.h>
#include <stdio.h>

#include <X11/Intrinsic.h>
#include <Xm/Xm.h>

#include <Xbae/Matrix.h> /* for version info */
#include <Xm/Form.h>
#include <Xm/PushB.h>

#define	NUM_ARGS_PER_ROW	5

Widget form, mat;

void doit()
{
	int	num_cmds = 5;
	int	x, y, z;
	int	num_args_in_cmd = 5;
	char buff[30];
      
      char *cmd_labels[] = { "", "TIME",
                           "ARG1",  "ARG2",  "ARG3",  "ARG4",  "ARG5",
                           "ARG6",  "ARG7",  "ARG8",  "ARG9",  "ARG10",
                           "ARG11", "ARG12", "ARG13", "ARG14", "ARG15",
                           "ARG16", "ARG17", "ARG18", "ARG19", "ARG20",
                           "ARG21", "ARG22", "ARG23", "ARG24", "ARG25",
                           "ARG26", "ARG27", "ARG28", "ARG29", "ARG30", "ARG31"
                          };

      short cmd_widths[] = { 12, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
                                  7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
                                  7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7 };
#if 1
      mat = XtVaCreateWidget ("test_xbae",
                             xbaeMatrixWidgetClass,
                             form,
                             XmNtopAttachment,    XmATTACH_FORM,
                             XmNleftAttachment,   XmATTACH_FORM,
                             XmNbottomAttachment, XmATTACH_FORM,
                             XmNtopOffset, 10,
                             XmNbottomOffset, 100,
                             XmNleftOffset, 10,
                             XmNrightOffset, 10,
                             XmNrightAttachment,  XmATTACH_FORM,
                             XmNcolumns, XtNumber(cmd_labels),
                             XmNcolumnLabels, cmd_labels,
                             XmNcolumnWidths, cmd_widths,
                              XmNrows, 0,
                              NULL);
       XbaeMatrixAddRows(mat, 0, NULL, NULL, NULL, num_cmds); 
#else
      mat = XtVaCreateWidget ("test_xbae",
                             xbaeMatrixWidgetClass,
                             form,
                             XmNtopAttachment,    XmATTACH_FORM,
                             XmNleftAttachment,   XmATTACH_FORM,
                             XmNbottomAttachment, XmATTACH_FORM,
                             XmNtopOffset, 10,
                             XmNbottomOffset, 10,
                             XmNleftOffset, 10,
                             XmNrightOffset, 10,
                             XmNrightAttachment,  XmATTACH_FORM,
                             XmNcolumns, XtNumber(cmd_labels),
                             XmNcolumnLabels, cmd_labels,
                             XmNcolumnWidths, cmd_widths,
                              XmNrows, num_cmds,
                              NULL);
#endif
       for(x = 0; x < num_cmds; x++ )
       {
         printf ("Handling Command #%d\n", x);
     
          sprintf(buff, "Test %d", x);
         XbaeMatrixSetCell(mat, x, 0, buff); 
         sprintf(buff, "Delay %d", x);
         XbaeMatrixSetCell(mat, x, 1, buff); 
         for( y = 0; y < num_args_in_cmd; y++ )
         {
           XbaeMatrixSetCell(mat, x, y+2 , "XX"); 
         }

         for (z = y; z < NUM_ARGS_PER_ROW; z++)
         {
            XbaeMatrixSetCell(mat, x, z+2 , "---"); 
          }

       }
       XtManageChild(mat);
}

void push(Widget w, XtPointer client, XtPointer call)
{
	int	i, ncols;
	char	**str;

	ncols = XbaeMatrixNumColumns(mat);
	str = (char **)XtCalloc(ncols, sizeof(String));
	for (i=0; i<ncols; i++)
		str[i] = "xxx";
	for (i=0; i<100; i++) {
		XbaeMatrixAddRows(mat, XbaeMatrixNumRows(mat), str, NULL, NULL, 1);
		XbaeMatrixDeleteRows(mat, 0, 1);
	}
	XtFree((void *)str);
}

int
main (int argc, char **argv)
{
  Widget toplevel, pb;

  /* Print run-time version of libXbae to stdout */
  printf("Using Xbae %s\n", XbaeGetVersionTxt());
  printf("This example was built with %s\n", XbaeVersionTxt);

  /* Print compile-time version of libXm to stdout */
  printf("Xbae was built with %s\n", XbaeGetXmVersionTxt());
  printf("and is running with %s\n", XmVERSION_STRING);

  toplevel = XtInitialize (argv[0], "Test", NULL, 0, &argc, argv);
  form = XtVaCreateManagedWidget("form", xmFormWidgetClass, toplevel,
	XmNwidth, 	500,
	XmNheight,	400,
	NULL);

  doit();
  
  pb = XtVaCreateManagedWidget("add/delete rows", xmPushButtonWidgetClass, form,
	XmNtopAttachment,	XmATTACH_WIDGET,
	XmNtopWidget,		mat,
	XmNtopOffset,		10,
	XmNleftAttachment,	XmATTACH_FORM,
	XmNleftOffset,		10,
  	NULL);
  XtAddCallback(pb, XmNactivateCallback, push, NULL);
  
  XtRealizeWidget (toplevel);
  XtMainLoop ();

  return (EXIT_SUCCESS);
}