~cfuhrman/+junk/netbsd-othersrc-trunk

« back to all changes in this revision

Viewing changes to dist/cdk/examples/preprocess_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="preprocess_ex";
 
5
#endif
 
6
 
 
7
int entryPreProcessCB (EObjectType cdkType, void *object, void *clientData, chtype input);
 
8
 
 
9
/*
 
10
 * This demonstrates the Cdk entry field widget.
 
11
 */
 
12
int main (void)
 
13
{
 
14
   /* Declare local variables. */
 
15
   CDKSCREEN *cdkscreen = 0;
 
16
   CDKENTRY *widget     = 0;
 
17
   WINDOW *cursesWin    = 0;
 
18
   char *title          = "<C>Type in anything you want\n<C>but the dreaded letter </B>G<!B>!";
 
19
   char *info, *mesg[10], temp[256];
 
20
 
 
21
   /* Set up CDK. */
 
22
   cursesWin = initscr();
 
23
   cdkscreen = initCDKScreen (cursesWin);
 
24
 
 
25
   /* Start CDK colors. */
 
26
   initCDKColor();
 
27
 
 
28
   /* Create the entry field widget. */
 
29
   widget = newCDKEntry (cdkscreen, CENTER, CENTER,
 
30
                                title, 0, A_NORMAL, '.', vMIXED,
 
31
                                40, 0, 256, TRUE, TRUE);
 
32
 
 
33
   /* Is the widget null? */
 
34
   if (widget == 0)
 
35
   {
 
36
      /* Clean up. */
 
37
      destroyCDKScreen (cdkscreen);
 
38
      endCDK();
 
39
 
 
40
      /* Print out a little message. */
 
41
      printf ("Oops. Can't seem to create the entry box. Is the window too small?\n");
 
42
      exit (1);
 
43
   }
 
44
 
 
45
   setCDKEntryPreProcess (widget, entryPreProcessCB, 0);
 
46
 
 
47
   /* Activate the entry field. */
 
48
   info = activateCDKEntry (widget, 0);
 
49
 
 
50
   /* Tell them what they typed. */
 
51
   if (widget->exitType == vESCAPE_HIT)
 
52
   {
 
53
      mesg[0] = "<C>You hit escape. No information passed back.";
 
54
      mesg[1] = "",
 
55
      mesg[2] = "<C>Press any key to continue.";
 
56
      popupLabel (cdkscreen, mesg, 3);
 
57
   }
 
58
   else if (widget->exitType == vNORMAL)
 
59
   {
 
60
      mesg[0] = "<C>You typed in the following";
 
61
      sprintf (temp, "<C>(%s)", info);
 
62
      mesg[1] = copyChar (temp);
 
63
      mesg[2] = "";
 
64
      mesg[3] = "<C>Press any key to continue.";
 
65
      popupLabel (cdkscreen, mesg, 4);
 
66
      freeChar (mesg[1]);
 
67
   }
 
68
 
 
69
   /* Clean up and exit. */
 
70
   destroyCDKEntry (widget);
 
71
   destroyCDKScreen (cdkscreen);
 
72
   delwin (cursesWin);
 
73
   endCDK();
 
74
   exit (0);
 
75
}
 
76
 
 
77
int entryPreProcessCB (EObjectType cdkType GCC_UNUSED, void *object, void *clientData GCC_UNUSED, chtype input)
 
78
{
 
79
   CDKENTRY *entry      = (CDKENTRY *)object;
 
80
   CDKDIALOG *widget    = 0;
 
81
   char *buttons[]      = {"OK"};
 
82
   int buttonCount      = 1;
 
83
   int lines            = 0;
 
84
   char *mesg[5];
 
85
 
 
86
   /* Check the input. */
 
87
   if ((input == 'g') || (input == 'G'))
 
88
   {
 
89
      mesg[lines++] = "<C><#HL(30)>";
 
90
      mesg[lines++] = "<C>I told you </B>NOT<!B> to type G";
 
91
      mesg[lines++] = "<C><#HL(30)>";
 
92
 
 
93
      widget = newCDKDialog (ScreenOf(entry), CENTER, CENTER,
 
94
                                mesg, lines, buttons, buttonCount,
 
95
                                A_REVERSE, FALSE, FALSE, FALSE);
 
96
      activateCDKDialog (widget, 0);
 
97
      destroyCDKDialog (widget);
 
98
      drawCDKEntry (entry, ObjOf(entry)->box);
 
99
      return 0;
 
100
   }
 
101
   return 1;
 
102
}