~cfuhrman/+junk/netbsd-othersrc-trunk

« back to all changes in this revision

Viewing changes to dist/cdk/examples/selection_ex.c

  • Committer: garbled
  • Date: 2001-01-04 19:59:48 UTC
  • Revision ID: svn-v4:288d5a72-fed7-e111-8680-000c29dcf8fe:trunk:174
Initial import of CDK 4.9.9.  The work to port this was performed by
Charles Hannum, and that is the version being imported:
cdk-4.9.9-20000407-myc3

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#include <cdk.h>
 
2
 
 
3
#ifdef HAVE_XCURSES
 
4
char *XCursesProgramName="selection_ex";
 
5
#endif
 
6
 
 
7
int main (void)
 
8
{
 
9
   /* Declare variables. */
 
10
   CDKSCREEN *cdkscreen         = 0;
 
11
   CDKSELECTION *selection      = 0;
 
12
   WINDOW *cursesWin            = 0;
 
13
   //char *title                        = "<C></5>Pick one or more accounts.\n<R>selection\n<L>selection";
 
14
   char *title                  = "<C></5>selection\n<R>selection\n<L>selection";
 
15
   char *choices[]              = {"   ", "-->"};
 
16
   char *item[400], temp[256], *mesg[200];
 
17
   struct passwd *ent;
 
18
   int count, x, y;
 
19
 
 
20
   /* Set up CDK. */
 
21
   cursesWin = initscr();
 
22
   cdkscreen = initCDKScreen (cursesWin);
 
23
 
 
24
   /* Set up CDK Colors. */
 
25
   initCDKColor();
 
26
 
 
27
   /* Use the account names to create a list. */
 
28
   count = 0;
 
29
   while ((ent = getpwent ()) != 0)
 
30
   {
 
31
      item[count++] = copyChar (ent->pw_name);
 
32
   }
 
33
   count--;
 
34
 
 
35
   /* Create the selection list. */
 
36
   selection = newCDKSelection (cdkscreen, CENTER, CENTER, LEFT,
 
37
                                        10, 13, title, item, count, choices, 2,
 
38
                                        A_REVERSE, TRUE, TRUE);
 
39
 
 
40
   /* Is the selection list null? */
 
41
   if (selection == 0)
 
42
   {
 
43
      /* Exit CDK. */
 
44
      destroyCDKScreen (cdkscreen);
 
45
      endCDK();
 
46
 
 
47
      /* Print out a message and exit. */
 
48
      printf ("Oops. Can;t seem to create the selection list. Is the window too small?\n");
 
49
      exit (1);
 
50
   }
 
51
 
 
52
   /* Activate the selection list. */
 
53
   activateCDKSelection (selection, 0);
 
54
 
 
55
   /* Check the exit status of the widget. */
 
56
   if (selection->exitType == vESCAPE_HIT)
 
57
   {
 
58
      mesg[0] = "<C>You hit escape. No items selected.";
 
59
      mesg[1] = "",
 
60
      mesg[2] = "<C>Press any key to continue.";
 
61
      popupLabel (cdkscreen, mesg, 3);
 
62
   }
 
63
   else if (selection->exitType == vNORMAL)
 
64
   {
 
65
      mesg[0] = "<C>Here are the accounts you selected.";
 
66
      y = 1;
 
67
      for (x=0; x < count; x++)
 
68
      {
 
69
         if (selection->selections[x] == 1)
 
70
         {
 
71
            sprintf (temp, "<C></5>%s", item[x]);
 
72
            mesg[y++] = copyChar (temp);
 
73
         }
 
74
      }
 
75
      popupLabel (cdkscreen, mesg, y);
 
76
 
 
77
      /* Clean up. */
 
78
      for (x=1; x < y; x++)
 
79
      {
 
80
          freeChar (mesg[x]);
 
81
      }
 
82
   }
 
83
 
 
84
   /* Clean up. */
 
85
   destroyCDKSelection (selection);
 
86
   destroyCDKScreen (cdkscreen);
 
87
   delwin (cursesWin);
 
88
   endCDK();
 
89
   exit (0);
 
90
}