File: scroll_ex.c

package info (click to toggle)
libcdk5 5.0.20050424-2
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 2,504 kB
  • ctags: 2,620
  • sloc: ansic: 29,645; sh: 4,283; makefile: 634; cpp: 42; sed: 40
file content (163 lines) | stat: -rw-r--r-- 4,140 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
/* $Id: scroll_ex.c,v 1.20 2005/04/15 19:44:43 tom Exp $ */

#include <cdk.h>

#ifdef HAVE_XCURSES
char *XCursesProgramName = "scroll_ex";
#endif

static char *newLabel (char *prefix)
{
   static int count;
   static char result[80];
   sprintf (result, "%s%d", prefix, ++count);
   return result;
}

static int addItemCB (EObjectType cdktype GCC_UNUSED, void *object,
		      void *clientData GCC_UNUSED,
		      chtype input GCC_UNUSED)
{
   CDKSCROLL *s = (CDKSCROLL *)object;

   addCDKScrollItem (s, newLabel ("add"));

   refreshCDKScreen (ScreenOf (s));

   return (TRUE);
}

static int insItemCB (EObjectType cdktype GCC_UNUSED, void *object,
		      void *clientData GCC_UNUSED,
		      chtype input GCC_UNUSED)
{
   CDKSCROLL *s = (CDKSCROLL *)object;

   insertCDKScrollItem (s, newLabel ("insert"));

   refreshCDKScreen (ScreenOf (s));

   return (TRUE);
}

static int delItemCB (EObjectType cdktype GCC_UNUSED, void *object,
		      void *clientData GCC_UNUSED,
		      chtype input GCC_UNUSED)
{
   CDKSCROLL *s = (CDKSCROLL *)object;

   deleteCDKScrollItem (s, getCDKScrollCurrent (s));

   refreshCDKScreen (ScreenOf (s));

   return (TRUE);
}

/*
 * This program demonstrates the Cdk scrolling list widget.
 */
int main (int argc, char **argv)
{
   /* Declare variables. */
   CDKSCREEN *cdkscreen = 0;
   CDKSCROLL *scrollList = 0;
   WINDOW *cursesWin = 0;
   char *title = "<C></5>Pick a file";
   char **item = 0;
   char *mesg[5], temp[256];
   int selection, count;

   CDK_PARAMS params;

   CDKparseParams (argc, argv, &params, "s:t:" CDK_CLI_PARAMS);

   /* Set up CDK. */
   cursesWin = initscr ();
   cdkscreen = initCDKScreen (cursesWin);

   /* Set up CDK Colors. */
   initCDKColor ();

   /* Use the current diretory list to fill the radio list. */
   count = CDKgetDirectoryContents (".", &item);

   /* Create the scrolling list. */
   scrollList = newCDKScroll (cdkscreen,
			      CDKparamValue (&params, 'X', CENTER),
			      CDKparamValue (&params, 'Y', CENTER),
			      CDKparsePosition(CDKparamString2(&params, 's', "RIGHT")),
			      CDKparamValue (&params, 'H', 10),
			      CDKparamValue (&params, 'W', 50),
			      CDKparamString2(&params, 't', title),
			      item, count,
			      TRUE,
			      A_REVERSE,
			      CDKparamValue (&params, 'N', TRUE),
			      CDKparamValue (&params, 'S', FALSE));

   /* Is the scrolling list null? */
   if (scrollList == 0)
   {
      /* Exit CDK. */
      destroyCDKScreen (cdkscreen);
      endCDK ();

      /* Print out a message and exit. */
      printf
	      ("Oops. Could not make scrolling list. Is the window too small?\n");
      exit (EXIT_FAILURE);
   }

#if 0
   drawCDKScroll (scrollList, 1);

   setCDKScrollPosition (scrollList, 10);
   drawCDKScroll (scrollList, 1);
   sleep (3);

   setCDKScrollPosition (scrollList, 20);
   drawCDKScroll (scrollList, 1);
   sleep (3);

   setCDKScrollPosition (scrollList, 30);
   drawCDKScroll (scrollList, 1);
   sleep (3);

   setCDKScrollPosition (scrollList, 70);
   drawCDKScroll (scrollList, 1);
   sleep (3);
#endif
   bindCDKObject (vSCROLL, scrollList, 'a', addItemCB, NULL);
   bindCDKObject (vSCROLL, scrollList, 'i', insItemCB, NULL);
   bindCDKObject (vSCROLL, scrollList, 'd', delItemCB, NULL);

   /* Activate the scrolling list. */

   selection = activateCDKScroll (scrollList, 0);

   /* Determine how the widget was exited. */
   if (scrollList->exitType == vESCAPE_HIT)
   {
      mesg[0] = "<C>You hit escape. No file selected.";
      mesg[1] = "",
	 mesg[2] = "<C>Press any key to continue.";
      popupLabel (cdkscreen, mesg, 3);
   }
   else if (scrollList->exitType == vNORMAL)
   {
      char *theItem = chtype2Char (scrollList->item[selection]);
      mesg[0] = "<C>You selected the following file";
      sprintf (temp, "<C>%.*s", (int)(sizeof (temp) - 20), theItem);
      mesg[1] = temp;
      mesg[2] = "<C>Press any key to continue.";
      popupLabel (cdkscreen, mesg, 3);
      freeChar (theItem);
   }

   /* Clean up. */
   CDKfreeStrings (item);
   destroyCDKScroll (scrollList);
   destroyCDKScreen (cdkscreen);
   endCDK ();
   exit (EXIT_SUCCESS);
}