1 /* $Id: dialog_ex.c,v 1.14 2016/12/04 15:22:16 tom Exp $ */
2
3 #include <cdk_test.h>
4
5 #ifdef HAVE_XCURSES
6 char *XCursesProgramName = "dialog_ex";
7 #endif
8
9 /*
10 * This program demonstrates the Cdk dialog widget.
11 */
main(int argc,char ** argv)12 int main (int argc, char **argv)
13 {
14 /* *INDENT-EQLS* */
15 CDKSCREEN *cdkscreen = 0;
16 CDKDIALOG *question = 0;
17 const char *buttons[] =
18 {"</B/24>Ok", "</B16>Cancel"};
19 const char *message[10];
20 const char *mesg[3];
21 char temp[100];
22 int selection;
23
24 CDK_PARAMS params;
25
26 CDKparseParams (argc, argv, ¶ms, CDK_MIN_PARAMS);
27
28 cdkscreen = initCDKScreen (NULL);
29
30 /* Start color. */
31 initCDKColor ();
32
33 /* Create the message within the dialog box. */
34 message[0] = "<C></U>Dialog Widget Demo";
35 message[1] = " ";
36 message[2] = "<C>The dialog widget allows the programmer to create";
37 message[3] = "<C>a popup dialog box with buttons. The dialog box";
38 message[4] = "<C>can contain </B/32>colours<!B!32>, </R>character attributes<!R>";
39 message[5] = "<R>and even be right justified.";
40 message[6] = "<L>and left.";
41
42 /* Create the dialog box. */
43 question = newCDKDialog (cdkscreen,
44 CDKparamValue (¶ms, 'X', CENTER),
45 CDKparamValue (¶ms, 'Y', CENTER),
46 (CDK_CSTRING2) message, 7,
47 (CDK_CSTRING2) buttons, 2,
48 COLOR_PAIR (2) | A_REVERSE,
49 TRUE,
50 CDKparamValue (¶ms, 'N', TRUE),
51 CDKparamValue (¶ms, 'S', FALSE));
52
53 /* Check if we got a null value back. */
54 if (question == 0)
55 {
56 /* Shut down Cdk. */
57 destroyCDKScreen (cdkscreen);
58 endCDK ();
59
60 printf ("Cannot create the dialog box. Is the window too small?\n");
61 ExitProgram (EXIT_FAILURE);
62 }
63
64 /* Activate the dialog box. */
65 selection = activateCDKDialog (question, 0);
66
67 /* Tell them what was selected. */
68 if (question->exitType == vESCAPE_HIT)
69 {
70 mesg[0] = "<C>You hit escape. No button selected.";
71 mesg[1] = "";
72 mesg[2] = "<C>Press any key to continue.";
73 popupLabel (cdkscreen, (CDK_CSTRING2) mesg, 3);
74 }
75 else if (question->exitType == vNORMAL)
76 {
77 sprintf (temp, "<C>You selected button #%d", selection);
78 mesg[0] = temp;
79 mesg[1] = "";
80 mesg[2] = "<C>Press any key to continue.";
81 popupLabel (cdkscreen, (CDK_CSTRING2) mesg, 3);
82 }
83
84 /* Clean up. */
85 destroyCDKDialog (question);
86 destroyCDKScreen (cdkscreen);
87 endCDK ();
88 ExitProgram (EXIT_SUCCESS);
89 }
90