forked from mbert/elvis
/
gwopts.c
executable file
·342 lines (281 loc) · 8.11 KB
/
gwopts.c
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
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
/*
** gwopts.c -- options processing for MS-Windows elvis.
**
** Copyright 1996, Serge Pirotte
*/
#define CHAR Char
#include "elvis.h"
#undef CHAR
#undef ELVBOOL
#if defined (GUI_WIN32)
#include <windows.h>
#include "winelvis.h"
#include "elvisres.h"
/* --------------------------------------------------------------------
**
** opt_parse_font -- parse a font option.
*/
void opt_parse_font(unsigned char *option, LOGFONT *plf)
{
register int i = 0;
int font_size = 0;
HDC dc;
/* get face name */
while (*option != '\0') {
if (*option == '*') {
option++;
break;
}
plf->lfFaceName[i++] = *option++;
}
plf->lfFaceName[i] = '\0';
/* get font size */
while (*option) {
if (*option == '*') {
option++;
if (*option && (*option == 'o' || *option == 'O')) {
plf->lfCharSet = OEM_CHARSET;
}
break;
}
font_size = (font_size * 10) + (*option - '0');
option++;
}
dc = GetDC (NULL);
plf->lfHeight = -MulDiv (font_size, GetDeviceCaps (dc, LOGPIXELSY), 72);
ReleaseDC (NULL, dc);
}
/* --------------------------------------------------------------------
**
** optstoresb -- store a scrollbar option.
*/
int optstoresb (OPTDESC *opt, OPTVAL *val, Char *newval)
{
GUI_WINDOW *gwp;
ELVBOOL value = calctrue(newval) ? ElvTrue : ElvFalse;
if (val->value.boolean == value)
return 0;
val->value.boolean = value;
if ((gwp = gw_find_client (GetFocus ())) != NULL) {
ShowScrollBar (gwp->clientHWnd, SB_VERT, value ? TRUE : FALSE);
SendMessage (gwp->frameHWnd, WM_SIZE, 0, 0);
}
return 1;
}
/* --------------------------------------------------------------------
**
** optstoretb -- store a toolbar option.
*/
int optstoretb (OPTDESC *opt, OPTVAL *val, Char *newval)
{
GUI_WINDOW *gwp;
ELVBOOL value = calctrue(newval) ? ElvTrue : ElvFalse;
if (val->value.boolean == value)
return 0;
val->value.boolean = value;
if ((gwp = gw_find_client (GetFocus ())) != NULL) {
if (value)
gw_create_toolbar (gwp);
else
gw_destroy_toolbar (gwp);
SendMessage (gwp->frameHWnd, WM_SIZE, 0, 0);
}
return 1;
}
/* --------------------------------------------------------------------
**
** optstorestb -- store a statusbar option.
*/
int optstorestb (OPTDESC *opt, OPTVAL *val, Char *newval)
{
GUI_WINDOW *gwp;
ELVBOOL value = calctrue(newval) ? ElvTrue : ElvFalse;
if (val->value.boolean == value)
return 0;
val->value.boolean = value;
if ((gwp = gw_find_client (GetFocus ())) != NULL) {
if (value)
gw_create_status_bar (gwp);
else
gw_destroy_status_bar (gwp);
SendMessage (gwp->frameHWnd, WM_SIZE, 0, 0);
}
return 1;
}
/* --------------------------------------------------------------------
**
** optstoremnu -- store a menubar option.
*/
int optstoremnu (OPTDESC *opt, OPTVAL *val, Char *newval)
{
GUI_WINDOW *gwp;
ELVBOOL value = calctrue(newval) ? ElvTrue : ElvFalse;
if (val->value.boolean == value)
return 0;
val->value.boolean = value;
if ((gwp = gw_find_client (GetFocus ())) != NULL) {
if (value)
gwp->menuHndl = LoadMenu (hInst, MAKEINTRESOURCE (IDM_ELVIS));
else if (gwp->menuHndl != NULL)
DestroyMenu (gwp->menuHndl);
SetMenu (gwp->frameHWnd, gwp->menuHndl);
DrawMenuBar (gwp->frameHWnd);
SendMessage (gwp->frameHWnd, WM_SIZE, 0, 0);
}
return 1;
}
/* --------------------------------------------------------------------
**
** optisfont -- validate a font option.
*/
int optisfont (OPTDESC *opt, OPTVAL *val, Char *newval)
{
GUI_WINDOW *gwp;
LOGFONT lf;
HFONT hFont;
Char *p;
if (strcmp (val->value.string, newval) == 0)
return 0;
memset (&lf, 0, sizeof (LOGFONT));
opt_parse_font (newval, &lf);
if ((hFont = CreateFontIndirect (&lf)) == NULL)
return -1;
DeleteObject (hFont);
p = CHARdup(newval);
safefree (val->value.string);
val->value.string = p;
if ((gwp = gw_find_client (GetFocus ())) != NULL) {
HideCaret (gwp->clientHWnd);
DestroyCaret ();
gw_del_fonts (gwp);
gw_set_fonts (gwp);
gw_get_win_size (gwp);
gw_set_cursor (gwp, ElvTrue);
ShowCaret (gwp->clientHWnd);
eventresize ((GUIWIN *)gwp, gwp->numrows, gwp->numcols);
InvalidateRect (gwp->clientHWnd, NULL, TRUE);
}
return 1;
}
/* --------------------------------------------------------------------
**
** optstoreattr -- store a font attribute option.
*/
int optstoreattr (OPTDESC *opt, OPTVAL *val, Char *newval)
{
GUI_WINDOW *gwp;
Char *p;
p = CHARdup(newval);
safefree (val->value.string);
val->value.string = p;
if ((gwp = gw_find_client (GetFocus ())) != NULL) {
gw_del_fonts (gwp);
gw_set_fonts (gwp);
InvalidateRect (gwp->clientHWnd, NULL, TRUE);
}
return 1;
}
/* --------------------------------------------------------------------
**
** optiswinsize -- check if LINES or COLUMNS options are valid.
*/
int optiswinsize (OPTDESC *opt, OPTVAL *val, Char *newval)
{
GUI_WINDOW *gwp;
long value = atoi ((char *)newval);
long saved_val;
/* any positive number will fit. */
if (value <= 0)
return -1;
/* check if same value */
if (value == val->value.number)
return 0;
/* save new value */
saved_val = val->value.number;
val->value.number = value;
/* if a view is active, check if validi */
if ((gwp = gw_find_client (GetFocus ())) != NULL) {
if (gw_set_win_size (gwp, 1) == 0) {
val->value.number = saved_val;
return -1;
}
}
return 1;
}
/* Change the icon image */
int optisicon (OPTDESC *opt, OPTVAL *val, Char *newval)
{
#ifdef FEATURE_IMAGE
GUI_WINDOW *gwp;
HBITMAP hbmColor, hbmMask;
HICON hicon;
ICONINFO iconinfo;
char *fullname;
char xpmname[400];
#endif
/* if same value, then do nothing */
if (val->value.string ? !CHARcmp(newval, val->value.string)
: *newval == '\0')
return 0;
#ifdef FEATURE_IMAGE
if (*newval)
{
/* locate the file, if not in current directory */
fullname = tochar8(newval);
if (dirperm(fullname) < DIR_READONLY)
{
strcpy(xpmname, "icons/");
strcat(xpmname, tochar8(newval));
fullname = iopath(tochar8(o_elvispath), xpmname, ElvFalse);
if (!fullname)
{
strcat(xpmname, ".xpm");
fullname = iopath(tochar8(o_elvispath), xpmname, ElvFalse);
}
}
if (!fullname)
{
msg(MSG_ERROR, "[s]can't find icon $1", newval);
return -1;
}
/* load the new pixmap, and convert it to an icon */
hbmColor = gw_load_xpm(fullname, -1L, NULL, &hbmMask);
if (!hbmColor)
{
msg(MSG_ERROR, "[s]can't load image from $1", fullname);
return -1;
}
memset(&iconinfo, 0, sizeof iconinfo);
iconinfo.fIcon = TRUE;
iconinfo.hbmColor = hbmColor;
iconinfo.hbmMask = hbmMask;
hicon = CreateIconIndirect(&iconinfo);
gw_unload_xpm(hbmColor);
gw_unload_xpm(hbmMask);
}
else /* setting to "" */
{
/* use the default icon */
hicon = LoadIcon (hInst, MAKEINTRESOURCE (IDI_ELVIS));
}
/* store it as an icon */
if ((gwp = gw_find_client (GetFocus ())) != NULL)
SetClassLong(gwp->frameHWnd, GCL_HICON, (long)hicon);
/* free the old icon, and remember the new one */
if (gwcustomicon)
DestroyIcon(gwcustomicon);
if (*newval)
gwcustomicon = hicon;
else
gwcustomicon = NULL;
#endif
/* free the old name, if any */
if (val->value.string)
safefree(val->value.string);
/* store the new name */
val->value.string = *newval ? CHARdup(newval) : NULL;
/* the icon was successfully changed */
return 1;
}
#endif
/* ex:se ts=4 sw=4: */