~cfuhrman/+junk/netbsd-othersrc-trunk

« back to all changes in this revision

Viewing changes to dist/cdk/examples/scale_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="scale_ex";
 
5
#endif
 
6
 
 
7
/*
 
8
 * This program demonstrates the Cdk scale widget.
 
9
 */
 
10
int main (int argc, char **argv)
 
11
{
 
12
   /* Declare variables. */
 
13
   CDKSCREEN *cdkscreen = 0;
 
14
   CDKSCALE *scale      = 0;
 
15
   WINDOW *cursesWin    = 0;
 
16
   char *title          = "<C>Select a value\n<R>scale\n<L>scale";
 
17
   char *label          = "</5>Current value";
 
18
   int low              = 0;
 
19
   int high             = 100;
 
20
   int inc              = 1;
 
21
   char temp[256], *mesg[5];
 
22
   int selection, ret;
 
23
 
 
24
   /* Parse up the command line.*/
 
25
   while (1)
 
26
   {
 
27
      ret = getopt (argc, argv, "l:h:i:");
 
28
 
 
29
      /* Are there any more command line options to parse. */
 
30
      if (ret == -1)
 
31
      {
 
32
         break;
 
33
      }
 
34
 
 
35
      switch (ret)
 
36
      {
 
37
         case 'l':
 
38
              low = atoi (optarg);
 
39
              break;
 
40
 
 
41
         case 'h':
 
42
              high = atoi (optarg);
 
43
              break;
 
44
 
 
45
         case 'i':
 
46
              inc = atoi (optarg);
 
47
              break;
 
48
      }
 
49
   }
 
50
 
 
51
   /* Set up CDK. */
 
52
   cursesWin = initscr();
 
53
   cdkscreen = initCDKScreen (cursesWin);
 
54
 
 
55
   /* Start CDK Colors. */
 
56
   initCDKColor();
 
57
 
 
58
   /* Create the scale. */
 
59
   scale = newCDKScale (cdkscreen, CENTER, CENTER,
 
60
                        title, label, A_NORMAL,
 
61
                        4, low, low, high,
 
62
                        inc, (inc*2), TRUE, TRUE);
 
63
 
 
64
   /* Is the scale null? */
 
65
   if (scale == 0)
 
66
   {
 
67
      /* Exit CDK. */
 
68
      destroyCDKScreen (cdkscreen);
 
69
      endCDK();
 
70
 
 
71
      /* Print out a message. */
 
72
      printf ("Oops. Can't make the scale widget. Is the window too small?\n");
 
73
      exit (1);
 
74
   }
 
75
 
 
76
   /* Activate the scale. */
 
77
   selection = activateCDKScale (scale, 0);
 
78
 
 
79
   /* Check the exit value of the scale widget. */
 
80
   if (scale->exitType == vESCAPE_HIT)
 
81
   {
 
82
      mesg[0] = "<C>You hit escape. No value selected.";
 
83
      mesg[1] = "",
 
84
      mesg[2] = "<C>Press any key to continue.";
 
85
      popupLabel (cdkscreen, mesg, 3);
 
86
   }
 
87
   else if (scale->exitType == vNORMAL)
 
88
   {
 
89
      sprintf (temp, "<C>You selected %d", selection);
 
90
      mesg[0] = copyChar (temp);
 
91
      mesg[1] = "",
 
92
      mesg[2] = "<C>Press any key to continue.";
 
93
      popupLabel (cdkscreen, mesg, 3);
 
94
      freeChar (mesg[0]);
 
95
   }
 
96
 
 
97
   /* Clean up. */
 
98
   destroyCDKScale (scale);
 
99
   destroyCDKScreen (cdkscreen);
 
100
   delwin (cursesWin);
 
101
   endCDK();
 
102
   exit (0);
 
103
}