~cfuhrman/+junk/netbsd-othersrc-trunk

« back to all changes in this revision

Viewing changes to dist/cdk/examples/buttonbox_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="buttonbox_ex";
 
5
#endif
 
6
 
 
7
static BINDFN_PROTO(entryCB);
 
8
 
 
9
/*
 
10
 * This program demonstrates the Cdk buttonbox widget.
 
11
 */
 
12
int main (void)
 
13
{
 
14
   /* Declare variables. */
 
15
   CDKSCREEN *cdkscreen         = 0;
 
16
   CDKBUTTONBOX *buttonWidget   = 0;
 
17
   CDKENTRY *entry              = 0;
 
18
   WINDOW *cursesWin            = 0;
 
19
   char *buttons[]              = {" OK ", " Cancel "};
 
20
   char *info                   = 0;
 
21
   int exitType;
 
22
   int selection;
 
23
 
 
24
   /* Set up CDK. */
 
25
   cursesWin = initscr();
 
26
   cdkscreen = initCDKScreen (cursesWin);
 
27
 
 
28
   /* Start color. */
 
29
   initCDKColor();
 
30
 
 
31
   /* Create the entry widget. */
 
32
   entry = newCDKEntry (cdkscreen, CENTER, CENTER,
 
33
                        "<C>Enter a name\n<R>This is an entry box!\n<L>This is an entry box!", "Name:", A_NORMAL, '.', vMIXED,
 
34
                        40, 0, 256, TRUE, FALSE);
 
35
 
 
36
   /* Create the button box widget. */
 
37
   buttonWidget = newCDKButtonbox (cdkscreen,
 
38
                        getbegx(entry->win),
 
39
                        getbegy(entry->win) + entry->boxHeight - 1,
 
40
                        1, entry->boxWidth,
 
41
                        "<R>This is a button box!\n<L>This is a button box!", 1, 2,
 
42
                        buttons, 2, A_REVERSE,
 
43
                        TRUE, TRUE);
 
44
 
 
45
   /* Set the lower left and right characters of the box. */
 
46
   setCDKEntryLLChar (entry, ACS_LTEE);
 
47
   setCDKEntryLRChar (entry, ACS_RTEE);
 
48
   setCDKButtonboxULChar (buttonWidget, ACS_LTEE);
 
49
   setCDKButtonboxURChar (buttonWidget, ACS_RTEE);
 
50
 
 
51
  /*
 
52
   * Bind the Tab key in the entry field to send a
 
53
   * Tab key to the button box widget.
 
54
   */
 
55
   bindCDKObject (vENTRY, entry, KEY_TAB, entryCB, buttonWidget);
 
56
 
 
57
   /* Activate the entry field. */
 
58
   drawCDKButtonbox (buttonWidget, TRUE);
 
59
   activateCDKEntry (entry, 0);
 
60
   exitType = entry->exitType;
 
61
   selection = buttonWidget->currentButton;
 
62
   if (exitType == vNORMAL)
 
63
   {
 
64
      info = copyChar (entry->info);
 
65
   }
 
66
 
 
67
   /* Clean up. */
 
68
   destroyCDKButtonbox (buttonWidget);
 
69
   destroyCDKEntry (entry);
 
70
   destroyCDKScreen (cdkscreen);
 
71
   delwin (cursesWin);
 
72
   endCDK();
 
73
 
 
74
   /* Spit out some info. */
 
75
   if (exitType == vESCAPE_HIT)
 
76
   {
 
77
      printf ("You pressed escape.\n");
 
78
   }
 
79
   else if (exitType == vNORMAL)
 
80
   {
 
81
      printf ("You typed in (%s) and selected button (%s)\n", info, buttons[selection]);
 
82
   }
 
83
   free (info);
 
84
   exit (0);
 
85
}
 
86
 
 
87
static void entryCB (EObjectType cdktype GCC_UNUSED, void *object GCC_UNUSED, void *clientData, chtype key)
 
88
{
 
89
   CDKBUTTONBOX *buttonbox = (CDKBUTTONBOX *)clientData;
 
90
 
 
91
   injectCDKButtonbox (buttonbox, key);
 
92
}