~ubuntu-branches/ubuntu/lucid/libcdk5/lucid

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
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
#include <cdk_int.h>

/*
 * $Author: tom $
 * $Date: 2006/05/05 00:27:44 $
 * $Revision: 1.79 $
 */

static int createList (CDKITEMLIST *itemlist, char **item, int count);
static int createFieldWin (CDKITEMLIST *itemlist, int ypos, int xpos);
static int maximumFieldWidth (CDKITEMLIST *itemlist);
static void updateFieldWidth (CDKITEMLIST *itemlist);

DeclareCDKObjects(ITEMLIST, Itemlist, setCdk, Int);

/*
 * This creates a pointer to an itemlist widget.
 */
CDKITEMLIST *newCDKItemlist (CDKSCREEN *cdkscreen, int xplace, int yplace, char *title, char *label, char **item, int count, int defaultItem, boolean Box, boolean shadow)
{
   /* Set up some variables.  */
   CDKITEMLIST *itemlist = 0;
   int parentWidth	= getmaxx(cdkscreen->window);
   int parentHeight	= getmaxy(cdkscreen->window);
   int boxWidth		= 0;
   int boxHeight;
   int fieldWidth	= 0;
   int xpos		= xplace;
   int ypos		= yplace;
   int junk;

   if ((itemlist = newCDKObject(CDKITEMLIST, &my_funcs)) == 0
    || !createList(itemlist, item, count))
   {
      destroyCDKObject (itemlist);
      return (0);
   }

   setCDKItemlistBox (itemlist, Box);
   boxHeight		= (BorderOf(itemlist) * 2) + 1;

   /* Set some basic values of the itemlist. */
   itemlist->label	= 0;
   itemlist->labelLen	= 0;
   itemlist->labelWin	= 0;

   /* Translate the label char *pointer to a chtype pointer. */
   if (label != 0)
   {
      itemlist->label = char2Chtype (label, &itemlist->labelLen, &junk);
   }

   /*
    * Set the box width.  Allow an extra char in field width for cursor
    */
   fieldWidth = maximumFieldWidth (itemlist) + 1;
   boxWidth = fieldWidth + itemlist->labelLen + 2 * BorderOf(itemlist);

   boxWidth = setCdkTitle(ObjOf(itemlist), title, boxWidth);

   boxHeight += TitleLinesOf(itemlist);

   /*
    * Make sure we didn't extend beyond the dimensions of the window.
    */
   itemlist->boxWidth = MINIMUM(boxWidth, parentWidth);
   itemlist->boxHeight = MINIMUM(boxHeight, parentHeight);
   updateFieldWidth (itemlist);

   /* Rejustify the x and y positions if we need to. */
   alignxy (cdkscreen->window, &xpos, &ypos, boxWidth, boxHeight);

   /* Make the window. */
   itemlist->win = newwin(boxHeight, boxWidth, ypos, xpos);
   if (itemlist->win == 0)
   {
      destroyCDKObject (itemlist);
      return (0);
   }

   /* Make the label window if there was a label. */
   if (itemlist->label != 0)
   {
      itemlist->labelWin = subwin (itemlist->win,
				   1,
				   itemlist->labelLen,
				   ypos + BorderOf(itemlist) + TitleLinesOf(itemlist),
				   xpos + BorderOf(itemlist));
      if (itemlist->labelWin == 0)
      {
	 destroyCDKObject (itemlist);
	 return (0);
      }
   }

   keypad (itemlist->win, TRUE);

   /* Make the field window */
   if (!createFieldWin (itemlist, 
			ypos + BorderOf(itemlist) + TitleLinesOf(itemlist),
			xpos + itemlist->labelLen + BorderOf(itemlist)))
   {
      destroyCDKObject (itemlist);
      return (0);
   }

   /* Set up the rest of the structure. */
   ScreenOf(itemlist)			= cdkscreen;
   itemlist->parent			= cdkscreen->window;
   itemlist->shadowWin			= 0;
   initExitType(itemlist);
   ObjOf(itemlist)->acceptsFocus	= TRUE;
   itemlist->shadow			= shadow;

   setCDKItemlistBox (itemlist, Box);

   /* Set then default item. */
   if (defaultItem >= 0 && defaultItem < itemlist->listSize)
   {
      itemlist->currentItem	= defaultItem;
      itemlist->defaultItem	= defaultItem;
   }
   else
   {
      itemlist->currentItem	= 0;
      itemlist->defaultItem	= 0;
   }

   /* Do we want a shadow??? */
   if (shadow)
   {
      itemlist->shadowWin = newwin (boxHeight, boxWidth, ypos + 1, xpos + 1);
      if (itemlist->shadowWin == 0)
      {
	 destroyCDKObject (itemlist);
	 return (0);
      }
   }

   /* Register this baby.		 */
   registerCDKObject (cdkscreen, vITEMLIST, itemlist);

   /* Return the pointer to the structure */
   return (itemlist);
}

/*
 * This allows the user to play with the widget.
 */
int activateCDKItemlist (CDKITEMLIST *itemlist, chtype *actions)
{
   /* Declare local variables. */
   int ret = -1;

   /* Draw the widget. */
   drawCDKItemlist (itemlist, ObjOf(itemlist)->box);
   drawCDKItemlistField(itemlist, TRUE);

   if (actions == 0)
   {
      chtype input = 0;
      boolean functionKey;

      for (;;)
      {
	 input = getchCDKObject (ObjOf(itemlist), &functionKey);

	 /* Inject the character into the widget. */
	 ret = injectCDKItemlist (itemlist, input);
	 if (itemlist->exitType != vEARLY_EXIT)
	 {
	    return ret;
	 }
      }
   }
   else
   {
      int length = chlen (actions);
      int x = 0;

      /* Inject each character one at a time. */
      for (x=0; x < length; x++)
      {
	 ret = injectCDKItemlist (itemlist, actions[x]);
	 if (itemlist->exitType != vEARLY_EXIT)
	 {
	    return ret;
	 }
      }
   }

   /* Set the exit type and exit. */
   setExitType(itemlist, 0);
   return ret;
}

/*
 * This injects a single character into the widget.
 */
static int _injectCDKItemlist (CDKOBJS *object, chtype input)
{
   CDKITEMLIST *itemlist = (CDKITEMLIST *)object;
   /* Declare local variables. */
   int ppReturn = 1;
   int ret = unknownInt;
   bool complete = FALSE;

   /* Set the exit type. */
   setExitType(itemlist, 0);

   /* Draw the itemlist field. */
   drawCDKItemlistField (itemlist,TRUE);

   /* Check if there is a pre-process function to be called. */
   if (PreProcessFuncOf(itemlist) != 0)
   {
      /* Call the pre-process function. */
      ppReturn = PreProcessFuncOf(itemlist) (vITEMLIST, itemlist, PreProcessDataOf(itemlist), input);
   }

   /* Should we continue? */
   if (ppReturn != 0)
   {
      /* Check a predefined binding. */
      if (checkCDKObjectBind (vITEMLIST, itemlist, input) != 0)
      {
	 checkEarlyExit(itemlist);
	 complete = TRUE;
      }
      else
      {
	 switch (input)
	 {
	    case KEY_UP : case KEY_RIGHT : case SPACE : case '+' : case 'n' :
		 if (itemlist->currentItem < itemlist->listSize - 1)
		 {
		    itemlist->currentItem++;
		 }
		 else
		 {
		    itemlist->currentItem = 0;
		 }
		 break;

	    case KEY_DOWN : case KEY_LEFT : case '-' : case 'p' :
		 if (itemlist->currentItem > 0)
		 {
		    itemlist->currentItem--;
		 }
		 else
		 {
		    itemlist->currentItem = itemlist->listSize - 1;
		 }
		 break;

	    case 'd' : case 'D' :
		 itemlist->currentItem = itemlist->defaultItem;
		 break;

	    case '0' :
		 itemlist->currentItem = 0;
		 break;

	    case '$' :
		 itemlist->currentItem = itemlist->listSize - 1;
		 break;

	    case KEY_ESC :
		 setExitType(itemlist, input);
		 complete = TRUE;
		 break;

	    case KEY_TAB : case KEY_ENTER :
		 setExitType(itemlist, input);
		 ret = itemlist->currentItem;
		 complete = TRUE;
		 break;

	    case CDK_REFRESH :
		 eraseCDKScreen (ScreenOf(itemlist));
		 refreshCDKScreen (ScreenOf(itemlist));
		 break;

	    default :
		 Beep();
		 break;
	 }
      }

      /* Should we call a post-process? */
      if (!complete && (PostProcessFuncOf(itemlist) != 0))
      {
	 PostProcessFuncOf(itemlist) (vITEMLIST, itemlist, PostProcessDataOf(itemlist), input);
      }
   }

   if (!complete)
   {
      drawCDKItemlistField (itemlist,TRUE);
      setExitType(itemlist, 0);
   }

   ResultOf(itemlist).valueInt = ret;
   return (ret != unknownInt);
}

/*
 * This moves the itemlist field to the given location.
 */
static void _moveCDKItemlist (CDKOBJS *object, int xplace, int yplace, boolean relative, boolean refresh_flag)
{
   CDKITEMLIST *itemlist = (CDKITEMLIST *)object;
   /* Declare local variables. */
   int currentX = getbegx(itemlist->win);
   int currentY = getbegy(itemlist->win);
   int xpos	= xplace;
   int ypos	= yplace;
   int xdiff	= 0;
   int ydiff	= 0;

   /*
    * If this is a relative move, then we will adjust where we want
    * to move to.
    */
   if (relative)
   {
      xpos = getbegx(itemlist->win) + xplace;
      ypos = getbegy(itemlist->win) + yplace;
   }

   /* Adjust the window if we need to. */
   alignxy (WindowOf(itemlist), &xpos, &ypos, itemlist->boxWidth, itemlist->boxHeight);

   /* Get the difference. */
   xdiff = currentX - xpos;
   ydiff = currentY - ypos;

   /* Move the window to the new location. */
   moveCursesWindow(itemlist->win, -xdiff, -ydiff);
   moveCursesWindow(itemlist->fieldWin, -xdiff, -ydiff);
   moveCursesWindow(itemlist->labelWin, -xdiff, -ydiff);
   moveCursesWindow(itemlist->shadowWin, -xdiff, -ydiff);

   /* Touch the windows so they 'move'. */
   refreshCDKWindow (WindowOf(itemlist));

   /* Redraw the window, if they asked for it. */
   if (refresh_flag)
   {
      drawCDKItemlist (itemlist, ObjOf(itemlist)->box);
   }
}

/*
 * This draws the widget on the screen.
 */
static void _drawCDKItemlist (CDKOBJS *object, int Box)
{
   CDKITEMLIST *itemlist = (CDKITEMLIST *)object;

   /* Did we ask for a shadow? */
   if (itemlist->shadowWin != 0)
   {
      drawShadow (itemlist->shadowWin);
   }

   /* Box the widget if asked. */
   if (Box)
   {
      drawObjBox (itemlist->win, ObjOf(itemlist));
   }

   drawCdkTitle (itemlist->win, object);

   /* Draw in the label to the widget. */
   if (itemlist->labelWin != 0)
   {
      writeChtype (itemlist->labelWin,
		0,
		0,
		itemlist->label,
		HORIZONTAL,
		0,
		chlen(itemlist->label));
   }

   wrefresh (itemlist->win);

   /* Draw in the field. */
   drawCDKItemlistField(itemlist, FALSE);
}

/*
 * This sets the background attribute of the widget.
 */
static void _setBKattrItemlist (CDKOBJS *object, chtype attrib)
{
   if (object != 0)
   {
      CDKITEMLIST *widget = (CDKITEMLIST *) object;

      wbkgd (widget->win, attrib);
      wbkgd (widget->fieldWin, attrib);
      if (widget->labelWin != 0)
      {
	 wbkgd (widget->labelWin, attrib);
      }
   }
}

/*
 * This function draws the contents of the field.
 */
void drawCDKItemlistField (CDKITEMLIST *itemlist, boolean highlight)
{
   /* Declare local vars. */
   int currentItem = itemlist->currentItem;
   int len;
   int x;

   /* Determine how much we have to draw. */
   len = MINIMUM (itemlist->itemLen[currentItem], itemlist->fieldWidth);

   /* Erase the field window. */
   werase (itemlist->fieldWin);

   /* Draw in the current item in the field. */
   for (x=0; x < len; x++)
   {
      chtype c = itemlist->item[currentItem][x];

      if (highlight)
      {
	c = CharOf(c) | A_REVERSE;
      }

      mvwaddch (itemlist->fieldWin, 0,
		x + itemlist->itemPos[currentItem],
		c);
   }

   /* Redraw the field window. */
   wrefresh (itemlist->fieldWin);
}

/*
 * This function removes the widget from the screen.
 */
static void _eraseCDKItemlist (CDKOBJS *object)
{
   if (validCDKObject (object))
   {
      CDKITEMLIST *itemlist = (CDKITEMLIST *)object;

      eraseCursesWindow (itemlist->fieldWin);
      eraseCursesWindow (itemlist->labelWin);
      eraseCursesWindow (itemlist->win);
      eraseCursesWindow (itemlist->shadowWin);
   }
}

static void destroyInfo (CDKITEMLIST *widget)
{
   widget->listSize = 0;

   CDKfreeChtypes (widget->item);
   widget->item = 0;

   freeAndNull (widget->itemPos);
   freeAndNull (widget->itemLen);
}

/*
 * This function destroys the widget and all the memory it used.
 */
static void _destroyCDKItemlist (CDKOBJS *object)
{
   if (object != 0)
   {
      CDKITEMLIST *itemlist = (CDKITEMLIST *)object;

      cleanCdkTitle (object);
      freeChtype (itemlist->label);
      destroyInfo (itemlist);

      /* Delete the windows. */
      deleteCursesWindow (itemlist->fieldWin);
      deleteCursesWindow (itemlist->labelWin);
      deleteCursesWindow (itemlist->shadowWin);
      deleteCursesWindow (itemlist->win);

      /* Clean the key bindings. */
      cleanCDKObjectBindings (vITEMLIST, itemlist);

      /* Unregister this object. */
      unregisterCDKObject (vITEMLIST, itemlist);
   }
}

/*
 * This sets multiple attributes of the widget.
 */
void setCDKItemlist (CDKITEMLIST *itemlist, char **list, int count, int current, boolean Box)
{
   setCDKItemlistValues (itemlist, list, count, current);
   setCDKItemlistBox (itemlist, Box);
}

/*
 * This function sets the contents of the list.
 */
void setCDKItemlistValues (CDKITEMLIST *itemlist, char **item, int count, int defaultItem)
{
   if (createList(itemlist, item, count))
   {
      int oldWidth = itemlist->fieldWidth;

      /* Set the default item. */
      if ((defaultItem >= 0) && (defaultItem < itemlist->listSize))
      {
	 itemlist->currentItem = defaultItem;
	 itemlist->defaultItem = defaultItem;
      }

      /*
       * This will not resize the outer windows but can still make a usable
       * field width if the title made the outer window wide enough.
       */
      updateFieldWidth (itemlist);
      if (itemlist->fieldWidth > oldWidth)
      {
	 createFieldWin (itemlist,
			 getbegy(itemlist->fieldWin),
			 getbegx(itemlist->fieldWin));
      }

      /* Draw the field. */
      eraseCDKItemlist (itemlist);
      drawCDKItemlist (itemlist, ObjOf(itemlist)->box);
   }
}
chtype **getCDKItemlistValues (CDKITEMLIST *itemlist, int *size)
{
   (*size) = itemlist->listSize;
   return itemlist->item;
}

/*
 * This sets the default/current item of the itemlist.
 */
void setCDKItemlistCurrentItem (CDKITEMLIST *itemlist, int currentItem)
{
   /* Set the default item. */
   if ((currentItem >= 0) && (currentItem < itemlist->listSize))
   {
      itemlist->currentItem = currentItem;
   }
}
int getCDKItemlistCurrentItem (CDKITEMLIST *itemlist)
{
   return itemlist->currentItem;
}

/*
 * This sets the default item in the list.
 */
void setCDKItemlistDefaultItem (CDKITEMLIST *itemlist, int defaultItem)
{
   /* Make sure the item is in the correct range. */
   if (defaultItem < 0)
   {
      itemlist->defaultItem = 0;
   }
   else if (defaultItem >= itemlist->listSize)
   {
      itemlist->defaultItem = itemlist->listSize - 1;
   }
   else
   {
      itemlist->defaultItem = defaultItem;
   }
}
int getCDKItemlistDefaultItem (CDKITEMLIST *itemlist)
{
   return itemlist->defaultItem;
}

/*
 * This sets the box attribute of the itemlist widget.
 */
void setCDKItemlistBox (CDKITEMLIST *itemlist, boolean Box)
{
   ObjOf(itemlist)->box = Box;
   ObjOf(itemlist)->borderSize = Box ? 1 : 0;
}
boolean getCDKItemlistBox (CDKITEMLIST *itemlist)
{
   return ObjOf(itemlist)->box;
}

static void _focusCDKItemlist(CDKOBJS *object)
{
   CDKITEMLIST *itemlist = (CDKITEMLIST *)object;

   drawCDKItemlistField (itemlist,TRUE);
}

static void _unfocusCDKItemlist(CDKOBJS *object)
{
   CDKITEMLIST *itemlist = (CDKITEMLIST *)object;

   drawCDKItemlistField (itemlist,FALSE);
}

#if 0
static void _refreshDataCDKItemlist(CDKOBJS *object)
{
   CDKITEMLIST *itemlist = (CDKITEMLIST *)object;

   if (ReturnOf(itemlist))
   {
      switch (DataTypeOf(itemlist))
      {
      default:
      case DataTypeInt:
	 itemlist->currentItem = *((int*)ReturnOf(itemlist));
	 break;
      case DataTypeDouble:
	 itemlist->currentItem = *((double*)ReturnOf(itemlist));
	 break;
      case DataTypeFloat:
	 itemlist->currentItem = *((float*)ReturnOf(itemlist));
	 break;
      case DataTypeString:
	 {
	    int i;

	    for (i=0; i < itemlist->listSize; ++i)
	       if (!cmpStrChstr((char*)ReturnOf(itemlist),itemlist->item[i]))
	       {
		  itemlist->currentItem = i;
		  break;
	       }
	    itemlist->currentItem = itemlist->defaultItem;
	    break;
	 }
      }
      drawCDKItemlistField(itemlist, FALSE);
   }
}

static void _saveDataCDKItemlist(CDKOBJS *object)
{
   CDKITEMLIST *itemlist = (CDKITEMLIST *)object;

   if (ReturnOf(itemlist))
   {
      switch (DataTypeOf(itemlist))
      {
      default:
      case DataTypeInt:
	 *((int*)ReturnOf(itemlist)) = itemlist->currentItem;
	 break;
      case DataTypeFloat:
	 *((float*)ReturnOf(itemlist)) = itemlist->currentItem;
	 break;
      case DataTypeDouble:
	 *((double*)ReturnOf(itemlist)) = itemlist->currentItem;
	 break;
      case DataTypeString:
	 chstrncpy((char*)ReturnOf(itemlist), itemlist->item[itemlist->currentItem], 9999);
	 break;
      }
   }
}
#else
dummyRefreshData(Itemlist)
dummySaveData(Itemlist)
#endif

static int createList (CDKITEMLIST *itemlist, char **item, int count)
{
   int status = 0;

   if (count > 0)
   {
      chtype **newItems = typeCallocN(chtype*, count + 1);
      int *newPos = typeCallocN(int, count + 1);
      int *newLen = typeCallocN(int, count + 1);
      int x;
      int fieldWidth = 0;

      if (newItems != 0
	 && newPos != 0
	 && newLen != 0)
      {
	 /* Go through the list and determine the widest item. */
	 status = 1;
	 for (x=0; x < count; x++)
	 {
	    /* Copy the item to the list. */
	    newItems[x] = char2Chtype (item[x], &newLen[x], &newPos[x]);
	    if (newItems[x] == 0)
	    {
	       status = 0;
	       break;
	    }
	    fieldWidth = MAXIMUM (fieldWidth, newLen[x]);
	 }

	 /* Now we need to justify the strings. */
	 for (x=0; x < count; x++)
	 {
	    newPos[x] = justifyString (fieldWidth + 1, newLen[x], newPos[x]);
	 }
      }

      if (status)
      {
	 destroyInfo (itemlist);

	 /* Copy in the new information. */
	 itemlist->listSize = count;
	 itemlist->item = newItems;
	 itemlist->itemPos = newPos;
	 itemlist->itemLen = newLen;
      }
      else
      {
	 CDKfreeChtypes (newItems);
	 freeChecked (newPos);
	 freeChecked (newLen);
      }
   }
   else
   {
      destroyInfo (itemlist);
      status = TRUE;
   }

   return status;
}

/* Go through the list and determine the widest item. */
static int maximumFieldWidth (CDKITEMLIST *itemlist)
{
   int x;
   int maxWidth	= INT_MIN;

   for (x=0; x < itemlist->listSize; x++)
   {
      maxWidth = MAXIMUM (maxWidth, itemlist->itemLen[x]);
   }
   maxWidth = MAXIMUM (maxWidth, 0);

   return maxWidth;
}

static void updateFieldWidth (CDKITEMLIST *itemlist)
{
   int want = maximumFieldWidth (itemlist) + 1;
   int have = itemlist->boxWidth - itemlist->labelLen - 2 * BorderOf(itemlist);
   itemlist->fieldWidth = MINIMUM(want, have);
}

/* Make the field window */
static int createFieldWin (CDKITEMLIST *itemlist, int ypos, int xpos)
{
   itemlist->fieldWin = subwin (itemlist->win,
				1,
				itemlist->fieldWidth,
				ypos,
				xpos);
   if (itemlist->fieldWin != 0)
   {
      keypad (itemlist->fieldWin, TRUE);
      ObjOf(itemlist)->inputWindow = itemlist->fieldWin;
      return 1;
   }
   return 0;
}