File: label.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 (316 lines) | stat: -rw-r--r-- 7,498 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
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
#include <cdk_int.h>

/*
 * $Author: tom $
 * $Date: 2004/08/30 00:21:35 $
 * $Revision: 1.81 $
 */

DeclareCDKObjects(LABEL, Label, setCdk, Unknown);

/*
 * This creates a label widget.
 */
CDKLABEL *newCDKLabel(CDKSCREEN *cdkscreen, int xplace, int yplace, char **mesg, int rows, boolean Box, boolean shadow)
{
   /* Maintain the label information. */
   CDKLABEL *label	= 0;
   int parentWidth	= getmaxx(cdkscreen->window);
   int parentHeight	= getmaxy(cdkscreen->window);
   int boxWidth		= INT_MIN;
   int boxHeight;
   int xpos		= xplace;
   int ypos		= yplace;
   int x		= 0;

   if (rows <= 0
    || (label = newCDKObject(CDKLABEL, &my_funcs)) == 0
    || (label->info    = typeCallocN(chtype *, rows + 1)) == 0
    || (label->infoLen = typeCallocN(int,      rows + 1)) == 0
    || (label->infoPos = typeCallocN(int,      rows + 1)) == 0)
   {
      destroyCDKObject(label);
      return (0);
   }

   setCDKLabelBox (label, Box);
   boxHeight		= rows + 2 * BorderOf(label);

   /* Determine the box width. */
   for (x=0; x < rows; x++)
   {
      /* Translate the char * to a chtype. */
      label->info[x] = char2Chtype (mesg[x], &label->infoLen[x], &label->infoPos[x]);
      boxWidth = MAXIMUM (boxWidth, label->infoLen[x]);
   }
   boxWidth += 2 * BorderOf(label);

   /* Create the string alignments. */
   for (x=0; x < rows; x++)
   {
      label->infoPos[x]	= justifyString (boxWidth - 2 * BorderOf(label), label->infoLen[x], label->infoPos[x]);
   }

  /*
   * Make sure we didn't extend beyond the dimensions of the window.
   */
   boxWidth = (boxWidth > parentWidth ? parentWidth : boxWidth);
   boxHeight = (boxHeight > parentHeight ? parentHeight : boxHeight);

   /* Rejustify the x and y positions if we need to. */
   alignxy (cdkscreen->window, &xpos, &ypos, boxWidth, boxHeight);

   /* Create the label. */
   ScreenOf(label)	= cdkscreen;
   label->parent	= cdkscreen->window;
   label->win		= newwin (boxHeight, boxWidth, ypos, xpos);
   label->shadowWin	= 0;
   label->xpos		= xpos;
   label->ypos		= ypos;
   label->rows		= rows;
   label->boxWidth	= boxWidth;
   label->boxHeight	= boxHeight;
   ObjOf(label)->inputWindow  = label->win;
   label->shadow	= shadow;

   /* Is the window null? */
   if (label->win == 0)
   {
      destroyCDKObject(label);
      return (0);
   }
   keypad (label->win, TRUE);

   /* If a shadow was requested, then create the shadow window. */
   if (shadow)
   {
      label->shadowWin	= newwin (boxHeight, boxWidth, ypos + 1, xpos + 1);
   }

   /* Register this baby. */
   registerCDKObject (cdkscreen, vLABEL, label);

   /* Return the label pointer. */
   return (label);
}

/*
 * This was added for the builder.
 */
void activateCDKLabel (CDKLABEL *label, chtype *actions GCC_UNUSED)
{
   drawCDKLabel (label, ObjOf(label)->box);
}

/*
 * This sets multiple attributes of the widget.
 */
void setCDKLabel (CDKLABEL *label, char **mesg, int lines, boolean Box)
{
   setCDKLabelMessage (label, mesg, lines);
   setCDKLabelBox (label, Box);
}

/*
 * This sets the information within the label.
 */
void setCDKLabelMessage (CDKLABEL *label, char **info, int infoSize)
{
   int x;

   /* Clean out the old message. */
   for (x=0; x < label->rows; x++)
   {
      freeChtype (label->info[x]);
      label->infoPos[x] = 0;
      label->infoLen[x] = 0;
   }
   label->rows = (infoSize < label->rows ? infoSize : label->rows);

   /* Copy in the new message. */
   for (x=0; x < label->rows; x++)
   {
      label->info[x]	= char2Chtype (info[x], &label->infoLen[x], &label->infoPos[x]);
      label->infoPos[x]	= justifyString (label->boxWidth - 2 * BorderOf(label), label->infoLen[x], label->infoPos[x]);
   }

   /* Redraw the label widget. */
   eraseCDKLabel (label);
   drawCDKLabel (label, ObjOf(label)->box);
}
chtype **getCDKLabelMessage (CDKLABEL *label, int *size)
{
   (*size) = label->rows;
   return label->info;
}

/*
 * This sets the box flag for the label widget.
 */
void setCDKLabelBox (CDKLABEL *label, boolean Box)
{
   ObjOf(label)->box = Box;
   ObjOf(label)->borderSize = Box ? 1 : 0;
}
boolean getCDKLabelBox (CDKLABEL *label)
{
   return ObjOf(label)->box;
}

/*
 * This sets the background attribute of the widget.
 */
static void _setBKattrLabel (CDKOBJS *object, chtype attrib)
{
   if (object != 0)
   {
      CDKLABEL *widget = (CDKLABEL *) object;

      wbkgd (widget->win, attrib);
   }
}

/*
 * This draws the label widget.
 */
static void _drawCDKLabel (CDKOBJS *object, boolean Box GCC_UNUSED)
{
   CDKLABEL *label = (CDKLABEL *)object;
   int x = 0;

   /* Is there a shadow? */
   if (label->shadowWin != 0)
   {
      drawShadow (label->shadowWin);
   }

   /* Box the widget if asked. */
   if (ObjOf(label)->box)
   {
      drawObjBox (label->win, ObjOf(label));
   }

   /* Draw in the message. */
   for (x=0; x < label->rows; x++)
   {
      writeChtype (label->win, label->infoPos[x] + BorderOf(label), x + BorderOf(label), label->info[x], HORIZONTAL, 0, label->infoLen[x]);
   }

   /* Refresh the window. */
   refreshCDKWindow (label->win);
}

/*
 * This erases the label widget.
 */
static void _eraseCDKLabel (CDKOBJS *object)
{
   if (validCDKObject (object))
   {
      CDKLABEL *label = (CDKLABEL *)object;

      eraseCursesWindow (label->win);
      eraseCursesWindow (label->shadowWin);
   }
}

/*
 * This moves the label field to the given location.
 */
static void _moveCDKLabel (CDKOBJS *object, int xplace, int yplace, boolean relative, boolean refresh_flag)
{
   CDKLABEL *label = (CDKLABEL *)object;
   int currentX = getbegx(label->win);
   int currentY = getbegy(label->win);
   int xpos	= xplace;
   int ypos	= yplace;
   int xdiff	= 0;
   int ydiff	= 0;

   /*
    * If this is a relative move, then we will adjust where we want
    * to move to.
    */
   if (relative)
   {
      xpos = getbegx(label->win) + xplace;
      ypos = getbegy(label->win) + yplace;
   }

   /* Adjust the window if we need to. */
   alignxy (WindowOf(label), &xpos, &ypos, label->boxWidth, label->boxHeight);

   /* Get the difference. */
   xdiff = currentX - xpos;
   ydiff = currentY - ypos;

   /* Move the window to the new location. */
   moveCursesWindow(label->win, -xdiff, -ydiff);
   moveCursesWindow(label->shadowWin, -xdiff, -ydiff);

   /* Touch the windows so they 'move'. */
   refreshCDKWindow (WindowOf(label));

   /* Redraw the window, if they asked for it. */
   if (refresh_flag)
   {
      drawCDKLabel (label, ObjOf(label)->box);
   }
}

/*
 * This destroys the label object pointer.
 */
static void _destroyCDKLabel (CDKOBJS *object)
{
   if (object != 0)
   {
      CDKLABEL *label = (CDKLABEL *)object;

      CDKfreeChtypes (label->info);
      freeChecked (label->infoLen);
      freeChecked (label->infoPos);

      /* Free up the window pointers. */
      deleteCursesWindow (label->shadowWin);
      deleteCursesWindow (label->win);

      /* Unregister the object. */
      unregisterCDKObject (vLABEL, label);
   }
}

/*
 * This pauses until a user hits a key...
 */
char waitCDKLabel (CDKLABEL *label, char key)
{
   /* If the key is null, we'll accept anything. */
   if ( key == 0 )
   {
      return (getcCDKObject (ObjOf(label)));
   }
   else
   {
      /* Only exit when a specific key is hit. */
      int code;
      for (;;)
      {
	 code = getcCDKObject(ObjOf(label));
	 if (code == key)
	 {
	    return ( code );
	 }
      }
   }
}

dummyInject(Label)

dummyFocus(Label)

dummyUnfocus(Label)

dummyRefreshData(Label)

dummySaveData(Label)