File: get_index.c

package info (click to toggle)
libcdk5 5.0.20161210-1
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 3,440 kB
  • ctags: 2,833
  • sloc: ansic: 32,375; sh: 4,732; makefile: 1,122; sed: 43; cpp: 41
file content (71 lines) | stat: -rw-r--r-- 1,456 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
#include <cdk_int.h>

/*
 * $Author: tom $
 * $Date: 2012/03/22 00:43:33 $
 * $Revision: 1.3 $
 */

/*
 * This returns a selected value in a list.
 */
int getListIndex (CDKSCREEN *screen,
		  const char *title,
		  CDK_CSTRING2 list,
		  int listSize,
		  boolean numbers)
{
   /* *INDENT-EQLS* */
   CDKSCROLL *scrollp   = 0;
   int selected         = -1;
   int height           = 10;
   int width            = -1;
   int len              = 0;
   int x;

   /* Determine the height of the list. */
   if (listSize < 10)
   {
      height = listSize + (title == 0 ? 2 : 3);
   }

   /* Determine the width of the list. */
   for (x = 0; x < listSize; x++)
   {
      int temp = (int)strlen (list[x]) + 10;
      width = MAXIMUM (width, temp);
   }
   if (title != 0)
   {
      len = (int)strlen (title);
   }
   width = MAXIMUM (width, len);
   width += 5;

   /* Create the scrolling list. */
   scrollp = newCDKScroll (screen, CENTER, CENTER, RIGHT,
			   height, width, title,
			   (CDK_CSTRING2) list, listSize, numbers,
			   A_REVERSE, TRUE, FALSE);

   /* Check if we made the list. */
   if (scrollp == 0)
   {
      refreshCDKScreen (screen);
      return -1;
   }

   /* Let the user play. */
   selected = activateCDKScroll (scrollp, 0);

   /* Check how they exited. */
   if (scrollp->exitType != vNORMAL)
   {
      selected = -1;
   }

   /* Clean up. */
   destroyCDKScroll (scrollp);
   refreshCDKScreen (screen);
   return selected;
}