forked from alexfru/dflat20
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathcombobox.c
130 lines (125 loc) · 4.01 KB
/
combobox.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
/* -------------- combobox.c -------------- */
#include "dflat.h"
int ListProc(WINDOW, MESSAGE, PARAM, PARAM);
int ComboProc(WINDOW wnd, MESSAGE msg, PARAM p1, PARAM p2)
{
switch (msg) {
case CREATE_WINDOW:
wnd->extension = CreateWindow(
LISTBOX,
NULL,
wnd->rc.lf,wnd->rc.tp+1,
wnd->ht-1, wnd->wd+1,
NULL,
wnd,
ListProc,
HASBORDER | NOCLIP | SAVESELF);
((WINDOW)(wnd->extension))->ct->command =
wnd->ct->command;
wnd->ht = 1;
wnd->rc.bt = wnd->rc.tp;
break;
case PAINT:
foreground = WndBackground(wnd);
background = WndForeground(wnd);
wputch(wnd, DOWNSCROLLBOX, WindowWidth(wnd), 0);
break;
case KEYBOARD:
if ((int)p1 == DN) {
SendMessage(wnd->extension, SETFOCUS, TRUE, 0);
return TRUE;
}
break;
case LEFT_BUTTON:
if ((int)p1 == GetRight(wnd) + 1)
SendMessage(wnd->extension, SETFOCUS, TRUE, 0);
break;
case CLOSE_WINDOW:
SendMessage(wnd->extension, CLOSE_WINDOW, 0, 0);
break;
default:
break;
}
return BaseWndProc(COMBOBOX, wnd, msg, p1, p2);
}
int ListProc(WINDOW wnd, MESSAGE msg, PARAM p1, PARAM p2)
{
WINDOW pwnd = GetParent(GetParent(wnd));
DBOX *db = pwnd->extension;
WINDOW cwnd;
int rtn;
WINDOW currFocus;
char text[MAXCOLS]; //FIXME overrun possible
switch (msg) {
case CREATE_WINDOW:
wnd->ct = DFmalloc(sizeof(CTLWINDOW));
wnd->ct->setting = OFF;
wnd->WindowColors[FRAME_COLOR][FG] =
wnd->WindowColors[STD_COLOR][FG];
wnd->WindowColors[FRAME_COLOR][BG] =
wnd->WindowColors[STD_COLOR][BG];
rtn = DefaultWndProc(wnd, msg, p1, p2);
return rtn;
case SETFOCUS:
if ((int)p1 == FALSE) {
if (!wnd->isHelping) {
SendMessage(wnd, HIDE_WINDOW, 0, 0);
wnd->ct->setting = OFF;
}
}
else
wnd->ct->setting = ON;
break;
case SHOW_WINDOW:
if (wnd->ct->setting == OFF)
return TRUE;
break;
case BORDER:
currFocus = inFocus;
inFocus = NULL;
rtn = DefaultWndProc(wnd, msg, p1, p2);
inFocus = currFocus;
return rtn;
case LB_SELECTION:
cwnd = ControlWindow(db, wnd->ct->command);
rtn = DefaultWndProc(wnd, msg, p1, p2);
SendMessage(wnd, LB_GETTEXT,
(PARAM) text, wnd->selection);
PutItemText(pwnd, wnd->ct->command, text);
SendMessage(cwnd, PAINT, 0, 0);
cwnd->TextChanged = TRUE;
return rtn;
case KEYBOARD:
cwnd = ControlWindow(db, wnd->ct->command);
switch ((int) p1) {
case ESC:
case FWD:
case BS:
SendMessage(cwnd, SETFOCUS, TRUE, 0);
return TRUE;
default:
break;
}
break;
case LB_CHOOSE:
cwnd = ControlWindow(db, wnd->ct->command);
SendMessage(cwnd, SETFOCUS, TRUE, 0);
return TRUE;
case CLOSE_WINDOW:
if (wnd->ct != NULL)
free(wnd->ct);
wnd->ct = NULL;
break;
default:
break;
}
return DefaultWndProc(wnd, msg, p1, p2);
}
void PutComboListText(WINDOW wnd, enum commands cmd, char *text)
{
CTLWINDOW *ct = FindCommand(wnd->extension, cmd, COMBOBOX);
if (ct != NULL) {
WINDOW lwnd = ((WINDOW)(ct->wnd))->extension;
SendMessage(lwnd, ADDTEXT, (PARAM) text, 0);
}
}