File: logWid.c

package info (click to toggle)
twlog 1.2-5
  • links: PTS
  • area: main
  • in suites: potato
  • size: 276 kB
  • ctags: 171
  • sloc: ansic: 1,246; makefile: 91; sh: 8
file content (425 lines) | stat: -rw-r--r-- 14,491 bytes parent folder | download | duplicates (2)
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
/*
 * twlog:  A basic ham loging program using Motif
 * Copyright (C) 1997 Ted Williams WA0EIR (ted@bluestone.com)
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License as
 * published by the Free Software Foundation; either version 2 of
 * the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be
 * useful, but WITHOUT ANY WARRANTY; without even the implied
 * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
 * PURPOSE.  See the GNU General Public License for more details.
 *
 * You should have recieved a copy of the GNU General Public
 * License along with this program; if not, write to the Free
 * Software Foundation, Inc., 675 Mass Ave, Cambridge. MA 02139,
 * USA. See the COPYING file in this directory.
 *
 * Versions: 1.2 -  Nov 1998 
 */

#include "twlog.h"

/*
 * build_widgets Function
 * Passed the main shell and the log_res resources array.
 * log_res is used for creating buttons on the option menus.
 */
void build_widgets (Widget logSH, LogRes log_res)
{
   int i, btn_cnt;
   Arg args[20];
   XmString xs[10];

   Widget form1, menuBar, rc1, fileMenu, helpMenu;
   Widget datePB, startPB,  callsignLabel;
   Widget bandLabel;
   Widget modeLabel;
   Widget pwrLabel;
   Widget rst1Label, rst2Label, endPB, notesLabel;
   Widget dateTF, startTF, callsignTF;
   Widget bandMenu, modeMenu, powerMenu;
   Widget rst1TF, rst2TF, endTF, notesTF;
   String transTable = "<Key>Return:  CRkey()";
   
   /* These are used to pass stuff around */
   static Cdata dateCdata, startCdata, endCdata;
   static Widget col_2_wids[10];
   
   /*
    * TOP FORM
    */
   form1 = XtVaCreateWidget ("form1", xmFormWidgetClass, logSH,
              NULL);
   /*
    * Make the main menu bar.
    */
   xs[0] = XmStringCreateLocalized ("File");
   xs[1] = XmStringCreateLocalized ("Help");
   menuBar = XmVaCreateSimpleMenuBar (form1, "menuBar",
                XmVaCASCADEBUTTON, xs[0], 'F', 
                XmVaCASCADEBUTTON, xs[1], 'H',
                NULL);
   XmStringFree (xs[0]);
   XmStringFree (xs[1]);
                   
   XtVaSetValues (menuBar,
      XmNleftAttachment, XmATTACH_FORM,
      XmNtopAttachment, XmATTACH_FORM,
      XmNrightAttachment, XmATTACH_FORM,
      XmNmenuAccelerator, "<KeyUp>F10",
      XmNmenuHelpWidget, XtNameToWidget(menuBar, "button_1"),
      NULL);

   /*
    * File Pulldown Menu
    * Creates the pulldown menu for the File button.  All callbacks
    * go to the fileCB() function.  Hangs the address of col_2_wids
    * on the userData of the menu rowColumn.  This will be used by
    * a callbacks.
    */
   xs[0] = XmStringCreateLocalized ("Append");
   xs[1] = XmStringCreateLocalized ("Edit Log");
   xs[2] = XmStringCreateLocalized ("Print Log");
   xs[3] = XmStringCreateLocalized ("New Log");
   xs[4] = XmStringCreateLocalized ("QRT");
   xs[5] = XmStringCreateLocalized ("Ctrl-A");
   xs[6] = XmStringCreateLocalized ("Ctrl-E");
   xs[7] = XmStringCreateLocalized ("Ctrl-P");
   xs[8] = XmStringCreateLocalized ("Ctrl-N");
   xs[9] = XmStringCreateLocalized ("Ctrl-Q");
   fileMenu = XmVaCreateSimplePulldownMenu (menuBar, "fileMenu", 0, fileCB,
                 XmVaPUSHBUTTON, xs[0], 'A', "Ctrl<Key>A", xs[5],
                 XmVaPUSHBUTTON, xs[1], 'E', "Ctrl<Key>E", xs[6],
                 XmVaPUSHBUTTON, xs[2], 'P', "Ctrl<Key>P", xs[7],
                 XmVaPUSHBUTTON, xs[3], 'N', "Ctrl<Key>N", xs[8],
                 XmVaSEPARATOR,
                 XmVaPUSHBUTTON, xs[4], 'Q', "Ctrl<Key>Q", xs[9],
                 NULL);
   XmStringFree (xs[0]);
   XmStringFree (xs[1]);
   XmStringFree (xs[2]);
   XmStringFree (xs[3]);
   XmStringFree (xs[4]);
   XmStringFree (xs[5]);
   XmStringFree (xs[6]);
   XmStringFree (xs[7]);
   XmStringFree (xs[8]);
   XmStringFree (xs[9]);

   XtVaSetValues (fileMenu,
          XmNuserData, &col_2_wids,
          NULL);

   /*
    * Help Pulldown Menu
    * Creates the pulldown menu for the File button. All callbacks go to
    * the helpCB() function.
    */
   xs[0] = XmStringCreateLocalized ("About");
   xs[1] = XmStringCreateLocalized ("Help");
   helpMenu = XmVaCreateSimplePulldownMenu (menuBar, "helpMenu", 1, helpCB,
                 XmVaPUSHBUTTON, xs[0], 'A', NULL, NULL,
                 XmVaPUSHBUTTON, xs[1], 'H', NULL, NULL,
                 NULL);
   XmStringFree (xs[0]);
   XmStringFree (xs[1]);

  /*
   * Data Entry Form
   * This is the data entry form for the log.  Column 1 (lefthand side
   * of the rowColumn) is pushbuttons and labels.  XS_CONVERT is a res
   * converter macro defined in twlog.h
   */
   rc1 = XtVaCreateWidget ("rc1",
            xmRowColumnWidgetClass, form1,
            XmNnumColumns, 2,
            XmNadjustLast, TRUE,
            XmNentryAlignment, XmALIGNMENT_CENTER,
            XmNpacking, XmPACK_COLUMN,
            XmNorientation, XmVERTICAL,
            XmNleftAttachment, XmATTACH_FORM,
            XmNbottomAttachment, XmATTACH_FORM,
            XmNrightAttachment, XmATTACH_FORM,
            XmNtopAttachment, XmATTACH_WIDGET,
            XmNtopWidget, menuBar,
            XmNisAligned, TRUE,
            NULL);

   /*
    * Column 1
    */
   datePB = XtVaCreateManagedWidget ("datePB",
               xmPushButtonWidgetClass, rc1,
               XmNnavigationType, XmTAB_GROUP,
               XS_CONVERT (XmNlabelString, "Date:"),
               NULL);
      
   startPB = XtVaCreateManagedWidget ("startPB",
                xmPushButtonWidgetClass, rc1,
                XmNnavigationType, XmTAB_GROUP,
                XS_CONVERT (XmNlabelString, "Start Time:"),
                NULL);

   callsignLabel = XtVaCreateManagedWidget ("callLabel",
                      xmLabelWidgetClass, rc1,
                      XS_CONVERT (XmNlabelString, "Call:"),
                      NULL);

   bandLabel = XtVaCreateManagedWidget ("bandLabel",
                  xmLabelWidgetClass, rc1,
                  XS_CONVERT (XmNlabelString, "Band:"),
                  NULL);

   modeLabel = XtVaCreateManagedWidget ("modeLabel",
                  xmLabelWidgetClass, rc1,
                  XS_CONVERT (XmNlabelString, "Mode:"),
                  NULL);

   pwrLabel = XtVaCreateManagedWidget ("pwrLabel",
                  xmLabelWidgetClass, rc1,
                  XS_CONVERT (XmNlabelString, "Power:"),
                  NULL);

   rst1Label = XtVaCreateManagedWidget ("rst1Label",
                  xmLabelWidgetClass, rc1,
                  XS_CONVERT (XmNlabelString, "His RST:"),
                  NULL);

   rst2Label = XtVaCreateManagedWidget ("rst2Label",
                  xmLabelWidgetClass, rc1,
                  XS_CONVERT (XmNlabelString, "My RST:"),
                  NULL);

   notesLabel = XtVaCreateManagedWidget ("notesLabel",
                   xmLabelWidgetClass, rc1,
                   XS_CONVERT (XmNlabelString, "Notes:"),
                   NULL);

   endPB = XtVaCreateManagedWidget ("endPB",
              xmPushButtonWidgetClass, rc1,
              XmNnavigationType, XmTAB_GROUP, 
              XS_CONVERT (XmNlabelString, "End Time:"),
              NULL);
   /*
    * End Column 1
    */
   
   /*
    * Column 2
    * The righthand side of the data entry form is textFields
    * and Option menus.
    */
   dateTF = XtVaCreateManagedWidget ("dateTF",
               xmTextFieldWidgetClass, rc1,
               XmNcolumns, NUMCOLS,
               NULL);   

   startTF = XtVaCreateManagedWidget ("startTF",
                xmTextFieldWidgetClass, rc1,
                XmNcolumns, NUMCOLS,
                NULL);   

   callsignTF = XtVaCreateManagedWidget ("callTF",
                   xmTextFieldWidgetClass, rc1,
                   XmNcolumns, NUMCOLS,
                   NULL);   

   /* 
    * Band Option Menu 
    * First count the number of bands listed in the bands property
    * of the resource file.  Then build the Args array to set the
    * properties when XmCreateSimpleOptionMenu creates the menu.
    */
   btn_cnt = 0;
   while (!XmStringEmpty (log_res.bands[btn_cnt]))
      {
      btn_cnt++;
      }

   i = 0;
   XtSetArg (args[i], XmNbuttons, log_res.bands); i++;
   XtSetArg (args[i], XmNbuttonCount, btn_cnt); i++;
   XtSetArg (args[i], XmNbuttonSet, log_res.default_band); i++;
   XtSetArg (args[i], XmNnavigationType, XmTAB_GROUP); i++;
   XtSetArg (args[i], XmNentryAlignment, XmALIGNMENT_CENTER); i++;
     
   bandMenu = XmCreateSimpleOptionMenu (rc1, "bandMenu", args, i);

   XtUnmanageChild (XmOptionLabelGadget (bandMenu));  /*No menu label pls*/
   XtManageChild (bandMenu);

   /*
    * End Band Option Menu 
    */

   /*
    * Mode Option Menu
    * Create the Mode menu the same way as the Band menu above.
    */
   btn_cnt = 0;
   while (!XmStringEmpty (log_res.modes[btn_cnt]))
      {
      btn_cnt++;
      }

   i = 0;
   XtSetArg (args[i], XmNbuttons, log_res.modes); i++;
   XtSetArg (args[i], XmNbuttonCount, btn_cnt); i++;
   XtSetArg (args[i], XmNbuttonSet, log_res.default_mode); i++;
   XtSetArg (args[i], XmNnavigationType, XmTAB_GROUP); i++;
   XtSetArg (args[i], XmNentryAlignment, XmALIGNMENT_CENTER); i++;

   modeMenu = XmCreateSimpleOptionMenu (rc1, "modeMenu", args, i);

   XtManageChild (modeMenu);
   XtUnmanageChild (XmOptionLabelGadget (modeMenu));  /*No menu label pls*/
   /*
    * End Mode Option Menu
    */

   /*
    * Power Option Menu
    * Create the Power menu the same way as the Band menu above.
    */
   btn_cnt = 0;
   while (!XmStringEmpty (log_res.power[btn_cnt]))
      {
      btn_cnt++;
      }

   i = 0;
   XtSetArg (args[i], XmNbuttons, log_res.power); i++;
   XtSetArg (args[i], XmNbuttonCount, btn_cnt); i++;
   XtSetArg (args[i], XmNbuttonSet, log_res.default_power); i++;
   XtSetArg (args[i], XmNnavigationType, XmTAB_GROUP); i++;
   XtSetArg (args[i], XmNentryAlignment, XmALIGNMENT_CENTER); i++;

   powerMenu = XmCreateSimpleOptionMenu (rc1, "powerMenu", args, i);

   XtManageChild (powerMenu);
   XtUnmanageChild (XmOptionLabelGadget (powerMenu));
   /*
    * End Power Option Menu
    */

   rst1TF = XtVaCreateManagedWidget ("rst1TF",
               xmTextFieldWidgetClass, rc1,
               XmNcolumns, NUMCOLS,
               NULL);   

   rst2TF = XtVaCreateManagedWidget ("rst2TF",
               xmTextFieldWidgetClass, rc1,
               XmNcolumns, NUMCOLS,
               NULL);   

   notesTF = XtVaCreateManagedWidget ("notesTF",
                xmTextFieldWidgetClass, rc1,
                XmNcolumns, NUMCOLS,
		XmNrows, 5,
		XmNeditMode, XmMULTI_LINE_EDIT,
                NULL);   

   endTF = XtVaCreateManagedWidget ("endTF",
              xmTextFieldWidgetClass, rc1,
              XmNcolumns, NUMCOLS,
              NULL);   
   /*
    * End Column 2
    */
/*
 * End Data Entry Form
 */

/*
 * Initialize argument structs
 * These are passed to some callbacks
 * Note: The notesTF is the last element in the array, but
 * appears as the next to the last widget in the rowColumn.
 */
   dateCdata.TF1 = dateTF;
   dateCdata.TF2 = NULL;
   dateCdata.next = startPB;

   startCdata.TF1 = dateTF;
   startCdata.TF2 = startTF;
   startCdata.next = callsignTF;

   endCdata.TF1 = endTF;
   endCdata.TF2 = NULL;
   endCdata.next = datePB;

   col_2_wids[0] = dateTF;
   col_2_wids[1] = startTF;
   col_2_wids[2] = callsignTF;
   col_2_wids[3] = bandMenu;
   col_2_wids[4] = modeMenu;
   col_2_wids[5] = powerMenu;
   col_2_wids[6] = rst1TF;
   col_2_wids[7] = rst2TF;
   col_2_wids[8] = endTF;
   col_2_wids[9] = notesTF;
    
   /*
    * Add callbacks
    * The first three callbacks registered are for the column 1
    * pushbuttons. The date and end PB's need to know their
    * coresponding textFields, which is passed as client data.  The
    * start PB client data is a pointer to an array holding the IDs of
    * the date and time TFs, so this callback can set both date and
    * start time.
    */
   XtAddCallback (datePB,  XmNactivateCallback, dateCB, (XtPointer) &dateCdata);
   XtAddCallback (startPB, XmNactivateCallback, startCB, (XtPointer) &startCdata);
   XtAddCallback (endPB,   XmNactivateCallback, endCB, (XtPointer) &endCdata);

   /*
    * Both callbacks go to the same function where they are identified.
    * The modify/verify callback changes all letters to upper case.  The
    * activate callback forces a traversal to the next tab group.
    */
   XtAddCallback (callsignTF,  XmNmodifyVerifyCallback, callsignCB, NULL);
   XtAddCallback (callsignTF,  XmNactivateCallback, callsignCB, NULL);
   XtAddCallback (rst1TF,  XmNactivateCallback, callsignCB, NULL);
   XtAddCallback (rst2TF,  XmNactivateCallback, callsignCB, NULL);
   XtAddCallback (notesTF, XmNactivateCallback, callsignCB, NULL);

   /* All the textFields call the focusCB() function.  As a widget gains
    * focus, its cursor is turned on.  As it looses focus, its cursor is
    * turned off. The cursor makes it hard to read the text sometimes,
    * and I got tired of looking at them. So there!
    */
   XtAddCallback (dateTF, XmNfocusCallback, focusCB, (XtPointer) NULL);
   XtAddCallback (dateTF, XmNlosingFocusCallback, focusCB, (XtPointer) NULL);
      
   XtAddCallback (startTF, XmNfocusCallback, focusCB, (XtPointer) NULL);
   XtAddCallback (startTF, XmNlosingFocusCallback, focusCB, (XtPointer) NULL);   
      
   XtAddCallback (callsignTF, XmNfocusCallback, focusCB, (XtPointer) NULL);
   XtAddCallback (callsignTF, XmNlosingFocusCallback, focusCB, (XtPointer) NULL);
   
   XtAddCallback (rst1TF, XmNfocusCallback, focusCB, (XtPointer) NULL);
   XtAddCallback (rst1TF, XmNlosingFocusCallback, focusCB, (XtPointer) NULL);
   
   XtAddCallback (rst2TF, XmNfocusCallback, focusCB, (XtPointer) NULL);
   XtAddCallback (rst2TF, XmNlosingFocusCallback, focusCB, (XtPointer) NULL);
   
   XtAddCallback (notesTF, XmNfocusCallback, focusCB, (XtPointer) NULL);
   XtAddCallback (notesTF, XmNlosingFocusCallback, focusCB, (XtPointer) NULL);
   
   XtAddCallback (endTF, XmNfocusCallback, focusCB, (XtPointer) NULL);
   XtAddCallback (endTF, XmNlosingFocusCallback, focusCB, (XtPointer) NULL);

   /*
    * Register Translations
    */
   XtOverrideTranslations (bandMenu, XtParseTranslationTable(transTable));
   XtOverrideTranslations (modeMenu, XtParseTranslationTable(transTable));
   XtOverrideTranslations (powerMenu,XtParseTranslationTable(transTable));
   
   XtManageChild (menuBar);
   XtManageChild (rc1);
   XtManageChild (form1);
}