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
|
#include <cdk_int.h>
/*
* Default method-functions for CDK objects.
*
* $Author: tom $
* $Date: 2005/04/15 22:08:58 $
* $Revision: 1.12 $
*/
/*
* Set the object's upper-left-corner line-drawing character.
*/
void setCdkULchar (CDKOBJS *obj, chtype ch)
{
obj->ULChar = ch;
}
/*
* Set the object's upper-right-corner line-drawing character.
*/
void setCdkURchar (CDKOBJS *obj, chtype ch)
{
obj->URChar = ch;
}
/*
* Set the object's lower-left-corner line-drawing character.
*/
void setCdkLLchar (CDKOBJS *obj, chtype ch)
{
obj->LLChar = ch;
}
/*
* Set the object's upper-right-corner line-drawing character.
*/
void setCdkLRchar (CDKOBJS *obj, chtype ch)
{
obj->LRChar = ch;
}
/*
* Set the object's horizontal line-drawing character.
*/
void setCdkHZchar (CDKOBJS *obj, chtype ch)
{
obj->HZChar = ch;
}
/*
* Set the object's vertical line-drawing character.
*/
void setCdkVTchar (CDKOBJS *obj, chtype ch)
{
obj->VTChar = ch;
}
/*
* Set the object's box-attributes.
*/
void setCdkBXattr (CDKOBJS *obj, chtype ch)
{
obj->BXAttr = ch;
}
/*
* This sets the background color of the widget.
*/
void setCDKObjectBackgroundColor (CDKOBJS *obj, char *color)
{
chtype *holder = 0;
int junk1, junk2;
/* Make sure the color isn't null. */
if (color == 0)
{
return;
}
/* Convert the value of the environment variable to a chtype. */
holder = char2Chtype (color, &junk1, &junk2);
/* Set the widget's background color. */
SetBackAttrObj(obj, holder[0]);
/* Clean up. */
freeChtype (holder);
}
/*
* Set the widget's title.
*/
int setCdkTitle (CDKOBJS *obj, char *title, int boxWidth)
{
if (obj != 0)
{
cleanCdkTitle (obj);
if (title != 0)
{
chtype *holder;
char **temp = 0;
int titleWidth;
int x;
int len;
int align;
int maxWidth = 0;
/* We need to split the title on \n. */
temp = CDKsplitString (title, '\n');
obj->titleLines = CDKcountStrings (temp);
obj->title = typeCallocN (chtype *, obj->titleLines + 1);
obj->titlePos = typeCallocN (int, obj->titleLines + 1);
obj->titleLen = typeCallocN (int, obj->titleLines + 1);
if (boxWidth >= 0)
{
/* We need to determine the widest title line. */
for (x = 0; x < obj->titleLines; x++)
{
holder = char2Chtype (temp[x], &len, &align);
maxWidth = MAXIMUM (maxWidth, len);
freeChtype (holder);
}
boxWidth = MAXIMUM (boxWidth, maxWidth + 2 * obj->borderSize);
}
else
{
boxWidth = -(boxWidth - 1);
}
/* For each line in the title, convert from char * to chtype * */
titleWidth = boxWidth - (2 * obj->borderSize);
for (x = 0; x < obj->titleLines; x++)
{
obj->title[x] = char2Chtype (temp[x], &obj->titleLen[x],
&obj->titlePos[x]);
obj->titlePos[x] = justifyString (titleWidth, obj->titleLen[x],
obj->titlePos[x]);
}
CDKfreeStrings (temp);
}
}
return boxWidth;
}
/*
* Draw the widget's title.
*/
void drawCdkTitle (WINDOW *win, CDKOBJS *obj)
{
if (obj != 0)
{
int x;
for (x = 0; x < obj->titleLines; x++)
{
writeChtype (win,
obj->titlePos[x] + obj->borderSize,
x + obj->borderSize,
obj->title[x],
HORIZONTAL, 0,
obj->titleLen[x]);
}
}
}
/*
* Remove storage for the widget's title.
*/
void cleanCdkTitle (CDKOBJS *obj)
{
if (obj != 0)
{
CDKfreeChtypes (obj->title);
obj->title = 0;
freeAndNull (obj->titlePos);
freeAndNull (obj->titleLen);
obj->titleLines = 0;
}
}
/*
* Set data for preprocessing.
*/
void setCDKObjectPreProcess (CDKOBJS *obj, PROCESSFN fn, void *data)
{
obj->preProcessFunction = fn;
obj->preProcessData = data;
}
/*
* Set data for postprocessing.
*/
void setCDKObjectPostProcess (CDKOBJS *obj, PROCESSFN fn, void *data)
{
obj->postProcessFunction = fn;
obj->postProcessData = data;
}
/*
* Set the object's exit-type based on the input.
* The .exitType field should have been part of the CDKOBJS struct, but it
* is used too pervasively in older applications to move (yet).
*/
void setCdkExitType (CDKOBJS *obj, EExitType *type, chtype ch)
{
switch (ch)
{
case KEY_ESC:
*type = vESCAPE_HIT;
break;
case KEY_TAB:
case KEY_ENTER:
*type = vNORMAL;
break;
case 0:
*type = vEARLY_EXIT;
break;
}
/* make the result available via ExitTypeOf(obj) */
obj->exitType = *type;
}
|