File: Notebook1.c

package info (click to toggle)
motif 2.3.4-13
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 81,160 kB
  • ctags: 51,769
  • sloc: ansic: 596,938; cpp: 3,951; yacc: 2,854; makefile: 2,070; csh: 1,199; sh: 1,070; lex: 455
file content (442 lines) | stat: -rw-r--r-- 9,751 bytes parent folder | download | duplicates (3)
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
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
/* $XConsortium: Notebook1.c /main/5 1995/07/15 21:07:16 drk $ */
/*
 * Motif
 *
 * Copyright (c) 1987-2012, The Open Group. All rights reserved.
 *
 * These libraries and programs are free software; you can
 * redistribute them and/or modify them under the terms of the GNU
 * Lesser General Public License as published by the Free Software
 * Foundation; either version 2 of the License, or (at your option)
 * any later version.
 *
 * These libraries and programs are distributed in the hope that
 * they will be useful, but WITHOUT ANY WARRANTY; without even the
 * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
 * PURPOSE. See the GNU Lesser General Public License for more
 * details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with these librararies and programs; if not, write
 * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
 * Floor, Boston, MA 02110-1301 USA
 */
/*
 * HISTORY
 */


/* This test takes all its resources from the resource file Notebook.defaults
   in the ./tests/Toolkit/Notebook directory. The test should be passed
   a flag (a number from 1-5), which will determine the XT name of the
   NoteBook widget created. This name then determines what resources
   are set for the Notebook. The resource file contains 5 set of resources
   for this test */

#include <Xm/NotebookP.h>
#include <testlib.h>



#define match(a,b) strcmp(a,b)==0

#define NUM_PAGE 6
#define NUM_MAJOR_TAB 2
#define NUM_MINOR_TAB 3



void
CreateGetValuesPanel();


void
GetBackPageNumber(Widget,XtPointer,XtPointer);


void
GetBackPageSize (Widget,XtPointer,XtPointer);

void
GetBindingWidth (Widget,XtPointer,XtPointer);

void
GetFrameShadowThickness(Widget,XtPointer,XtPointer);

void
GetInnerMarginWidth(Widget,XtPointer,XtPointer);


void
GetInnerMarginHeight(Widget,XtPointer,XtPointer);

void
GetMajorTabSpacing(Widget,XtPointer,XtPointer);

void
GetMinorTabSpacing(Widget,XtPointer,XtPointer);

void
PageChanged (Widget, XtPointer, XtPointer);



Widget Notebook;


void
main (int argc, char **argv)
{
	Widget Parent;
	Widget Page[NUM_PAGE];
	Widget MajorTab[NUM_MINOR_TAB];
	Widget MinorTab[NUM_MINOR_TAB];
	Widget PageScr;
	Widget StatusArea;
	char buf[16];
	int i,a;
	Arg args[10];

	CommonTestInit(argc,argv);

	/* User specifies an integer from 1-5  which determines the Xt name of
	   the Notebook widget. */

	if (UserData == NULL)
          a = 1;
	else

	if (match (UserData,"1")) 
	  a=1;
	else if (match (UserData,"2")) 
	  a=2;
	else if (match (UserData,"3")) 
	  a=3;
	else if (match (UserData,"4")) 
	  a=4;
	else if (match (UserData,"5")) 
	  a=5;
        else if (match (UserData, "6"))
          a=6;

	
	/* determine Xt Name of Parent and create Parent */
	sprintf (buf, "Parent%d", a);
	Parent = XmCreateFrame(Shell1, buf, NULL, 0);
	XtManageChild (Parent);


	/* determine Xt Name of Notebook and create Notebook */

	sprintf (buf, "Notebook%d", a);
	Notebook  = XmCreateNotebook (Parent, buf, NULL, 0);
	XtManageChild (Notebook);
	XtAddCallback (Notebook, XmNpageChangedCallback, PageChanged, 
		       (XtPointer)NULL);



	/* Create children of Notebook : Pages, Minor Tabs, Major Tabs,
	   a Page Scroller and a Status Area. */

        for (i=0; i< NUM_PAGE; i++)
	  {
	    sprintf (buf, "Page%d", i+1);
	    Page[i] = XmCreateLabel (Notebook,buf,NULL,0);
	  }
	    XtManageChildren (Page,NUM_PAGE);


	for (i=0; i< NUM_MAJOR_TAB; i++)
	  {
	    sprintf (buf, "MajorTab%d", i+1);
	    MajorTab[i] = XmCreatePushButton (Notebook,buf,NULL,0);
	  }
	    XtManageChildren (MajorTab, NUM_MAJOR_TAB);


	for (i=0; i< NUM_MINOR_TAB; i++)
	  {
	    sprintf (buf, "MinorTab%d", i+1);
	    MinorTab[i] = XmCreatePushButton (Notebook,buf,NULL,0);
	  }

	XtManageChildren (MinorTab,NUM_MINOR_TAB);

	PageScr = XmCreateScrollBar (Notebook, "PageScr", NULL, 0);
	XtManageChild (PageScr);

	StatusArea = XmCreateLabel (Notebook, "StatusArea", NULL, 0);
	XtManageChild (StatusArea);

	CreateGetValuesPanel();
	XtRealizeWidget (Shell1);

	CommonPause();
	CommonPause();


	XtAppMainLoop (app_context);
      }




void
CreateGetValuesPanel()
{

  Widget BBDialog1;
  Widget RowCol1;
  Widget GetValuesPB[8], Label1;
  int i,n;
  Arg args[10];
  static char *get_values[] = { "backPageNumber", 
                       "backPageSize",
		       "bindingWidth",
		       "frameShadowThickness",
		       "innerMarginHeight",
		       "innerMarginWidth",
		       "minorTabSpacing",
		       "majorTabSpacing"};
  XmString GetValuesLabel;


  n=0;
  BBDialog1 = XmCreateBulletinBoardDialog (Shell1, "BBDialog1", args, n);
  XtManageChild (BBDialog1);

  n=0;
  XtSetArg (args[n], XmNpacking, XmPACK_COLUMN); n++;
  XtSetArg (args[n], XmNnumColumns, 1); n++;
  RowCol1 = XmCreateRowColumn (BBDialog1, "RowCol1", args, n);
  XtManageChild (RowCol1);

  n=0;
  GetValuesLabel = XmStringCreate ("Get Resource Values", XmFONTLIST_DEFAULT_TAG);
  XtSetArg (args[n], XmNlabelString, GetValuesLabel); n++;
  Label1 = XmCreateLabel (RowCol1, "Label1", args, n);
  XtManageChild (Label1);

  for (i=0; i < 8; i++)
    {
      n=0;
      GetValuesPB[i] = XmCreatePushButton (RowCol1, get_values[i], args, n);
    }
   XtManageChildren (GetValuesPB,8);


  XtAddCallback (GetValuesPB[0], XmNactivateCallback, GetBackPageNumber, 
		 (XtPointer)NULL);

  XtAddCallback (GetValuesPB[1], XmNactivateCallback, GetBackPageSize, 
		 (XtPointer)NULL); 

  XtAddCallback (GetValuesPB[2], XmNactivateCallback, GetBindingWidth,
		 (XtPointer)NULL);

  XtAddCallback (GetValuesPB[3], XmNactivateCallback, GetFrameShadowThickness,
		 (XtPointer)NULL);

  XtAddCallback (GetValuesPB[4], XmNactivateCallback, GetInnerMarginHeight,
		 (XtPointer)NULL);

  XtAddCallback (GetValuesPB[5], XmNactivateCallback, GetInnerMarginWidth,
		 (XtPointer)NULL);

  XtAddCallback (GetValuesPB[6], XmNactivateCallback, GetMinorTabSpacing,
		 (XtPointer)NULL);

  XtAddCallback (GetValuesPB[7], XmNactivateCallback, GetMajorTabSpacing,
		 (XtPointer)NULL);

}



void
GetBackPageNumber (Widget w, XtPointer client_data, XtPointer call_data)
{
  Cardinal back_page_number;
  Arg args[10];
  int n;


  n=0;
  XtSetArg (args[n], XmNbackPageNumber, &back_page_number); n++;
  XtGetValues (Notebook,args,n);

  printf ("backPageNumber is %d\n", back_page_number);

}


void
GetBackPageSize (Widget w, XtPointer client_data, XtPointer call_data)
{
  Dimension back_page_size;
  Arg args[10];
  int n;


  n=0;
  XtSetArg (args[n], XmNbackPageSize, &back_page_size); n++;
  XtGetValues (Notebook,args,n);

  printf ("backPageSize is %d\n", back_page_size);

}


void
GetBindingWidth (Widget w, XtPointer client_data, XtPointer call_data)
{
  Dimension binding_width;
  Arg args[10];
  int n;


  n=0;
  XtSetArg (args[n], XmNbindingWidth, &binding_width); n++;
  XtGetValues (Notebook,args,n);

  printf ("binding width is %d\n", binding_width);

}

void
GetFrameShadowThickness (Widget w, XtPointer client_data, 
			 XtPointer call_data)
{
  Dimension frame_shadow_thickness;
  Arg args[10];
  int n;


  n=0;
  XtSetArg (args[n], XmNframeShadowThickness, &frame_shadow_thickness); n++;
  XtGetValues (Notebook,args,n);

  printf ("frame shadow thickness is %d\n", frame_shadow_thickness);

}


void
GetInnerMarginWidth (Widget w, XtPointer client_data, 
			 XtPointer call_data)
{
  Dimension inner_margin_width;
  Arg args[10];
  int n;


  n=0;
  XtSetArg (args[n], XmNinnerMarginWidth, &inner_margin_width); n++;
  XtGetValues (Notebook,args,n);

  printf ("inner margin width is %d\n", inner_margin_width);

}

void
GetInnerMarginHeight (Widget w, XtPointer client_data, 
			 XtPointer call_data)
{
  Dimension inner_margin_height;
  Arg args[10];
  int n;


  n=0;
  XtSetArg (args[n], XmNinnerMarginHeight, &inner_margin_height); n++;
  XtGetValues (Notebook,args,n);

  printf ("inner margin height is %d\n", inner_margin_height);

}


void
GetMinorTabSpacing (Widget w, XtPointer client_data, 
			 XtPointer call_data)
{
  Dimension minor_tab_spacing;
  Arg args[10];
  int n;


  n=0;
  XtSetArg (args[n], XmNminorTabSpacing, &minor_tab_spacing); n++;
  XtGetValues (Notebook,args,n);

  printf ("minor tab spacing is %d\n", minor_tab_spacing);

}

void
GetMajorTabSpacing (Widget w, XtPointer client_data, 
			 XtPointer call_data)
{
  Dimension major_tab_spacing;
  Arg args[10];
  int n;


  n=0;
  XtSetArg (args[n], XmNmajorTabSpacing, &major_tab_spacing); n++;
  XtGetValues (Notebook,args,n);

  printf ("major tab spacing is %d\n", major_tab_spacing);

}






void
PageChanged (Widget w, XtPointer client_data, XtPointer call_data)
{

   int want_page_no,current_page_no,reason;

  if (call_data == NULL)
    printf ("Current page has been changed\n");
  else
    {
      want_page_no = ((XmNotebookCallbackStruct *)call_data)->page_number;
      current_page_no = ((XmNotebookCallbackStruct *)call_data)->prev_page_number;
      reason = ((XmNotebookCallbackStruct *)call_data)->reason;
      printf ("Page has been changed\n");

   switch (reason)
        {
        case XmCR_MAJOR_TAB:
          printf ("Reason is XmCR_MAJOR_TAB\n");
          break;
        case XmCR_MINOR_TAB:
          printf ("Reason is XmCR_MINOR_TAB\n");
          break;
        case XmCR_PAGE_SCROLLER_DECREMENT:
          printf ("Reason is XmCR_PAGE_SCROLLER_DECREMENT\n");
          break;
        case XmCR_PAGE_SCROLLER_INCREMENT:
          printf ("Reason is XmCR_PAGE_SCROLLER_INCREMENT\n");
          break;
        case XmCR_NONE:
          printf ("Reason is XmCR_NONE\n");
          break;
        default:
          printf ("Invalid reason\n");
          break;
        }
      printf ("Current page is %d\n",current_page_no);
      printf ("Desired page is %d\n\n\n",want_page_no);
    }

}