-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathformwind.c
209 lines (183 loc) · 5.66 KB
/
formwind.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
#include <stdlib.h>
#include <stdio.h>
#include <gem.h>
#include "global.h"
typedef struct form_window * FORMWIND;
#define WINDOW_t FORMWIND
#include "Window.h"
#define IDENT_FORM WINDOW_IDENT('F','O','R','M')
struct form_window {
WINDOWBASE Base;
OBJECT * Tree;
GRECT * Work;
WORD EditObj;
WORD EditIdx;
/**/
BOOL (*handler)(OBJECT *, WORD obj);
};
static WINDOW vTab_destruct(FORMWIND);
static void vTab_evButton (FORMWIND, WORD bmask, PXY mouse, UWORD kstate, WORD);
static void vTab_evKeybrd (FORMWIND, WORD scan, WORD ascii, UWORD kstate);
static void vTab_drawWork (FORMWIND, const GRECT *);
static BOOL vTab_close (FORMWIND, UWORD kstate);
static void vTab_moved (FORMWIND);
static BOOL dummy_handler (OBJECT *, WORD obj);
/*============================================================================*/
static FORMWIND
new_formWind (OBJECT * tree, const char * title, BOOL modal)
{
FORMWIND This = (tree ? malloc (sizeof (struct form_window)) : NULL);
if (This) {
(void)title;
tree->ob_flags |= OF_FLAG15;
window_ctor (This, MOVER|CLOSER, IDENT_FORM, title, NULL, modal);
This->Tree = tree;
This->Work = (GRECT*)&tree->ob_x;
wind_calc_grect (WC_BORDER, This->Base.Widgets,
This->Work, &This->Base.Curr);
This->Base.destruct = vTab_destruct;
This->Base.evButton = vTab_evButton;
This->Base.evKeybrd = vTab_evKeybrd;
This->Base.drawWork = vTab_drawWork;
This->Base.close = vTab_close;
This->Base.moved = vTab_moved;
This->EditObj = 0;
This->EditIdx = 0;
This->handler = dummy_handler;
}
return This;
}
/*============================================================================*/
#define delete_formWind(FORMWIND) free((*(FORMWIND)->Base.destruct)(FORMWIND))
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
static WINDOW
vTab_destruct (FORMWIND This)
{
This->Tree->ob_flags &= ~OF_FLAG15;
return window_dtor(This);
}
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
static void
vTab_evButton (FORMWIND This, WORD bmask, PXY mouse, UWORD kstate, WORD clicks)
{
(void)kstate;
if (bmask == 0x01) {
WORD obj = objc_find (This->Tree, ROOT, MAX_DEPTH, mouse.p_x, mouse.p_y);
if (obj >= 0) {
WORD nxt = 0;
WORD ret = form_button (This->Tree, obj, clicks, &nxt);
if (nxt > 0 && nxt != This->EditObj
&& (This->Tree[nxt].ob_flags & OF_EDITABLE)) {
/* edit object selected */
if (This->EditObj > 0) {
objc_edit (This->Tree, This->EditObj, 0, &This->EditIdx, 3);
}
if (objc_edit (This->Tree, nxt, 0, &This->EditIdx, 1)) {
This->EditObj = nxt;
} else {
This->EditObj = 0;
}
}
if (ret == 0) {
/* exit object selected */
if ((*This->handler)(This->Tree, nxt)) {
delete_formWind (This);
}
}
}
}
}
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
static void
vTab_evKeybrd (FORMWIND This, WORD scan, WORD ascii, UWORD kstate)
{
(void)kstate;
if (This->EditObj > 0) {
WORD nxt = 0;
WORD chr = (scan<<8)|ascii;
if (form_keybd (This->Tree, This->EditObj, 0, chr, &nxt, &chr) == 0) {
/* return key: default object selected */
if ((*This->handler)(This->Tree, nxt)) {
delete_formWind (This);
}
} else if (nxt > 0) {
/* cursor or tab: next edit object selected */
objc_edit (This->Tree, This->EditObj, 0, &This->EditIdx, 3);
if (objc_edit (This->Tree, nxt, 0, &This->EditIdx, 1)) {
This->EditObj = nxt;
} else {
This->EditObj = 0;
}
} else {
/* normal key hit */
objc_edit (This->Tree, This->EditObj, chr, &This->EditIdx, 2);
}
}
}
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
static void
vTab_drawWork (FORMWIND This, const GRECT * clip)
{
objc_draw (This->Tree, ROOT, MAX_DEPTH,
clip->g_x, clip->g_y, clip->g_w, clip->g_h);
if (This->EditObj > 0) {
GRECT crsr;
objc_offset (This->Tree, This->EditObj, &crsr.g_x, &crsr.g_y);
crsr.g_x += This->EditIdx *8;
crsr.g_y -= 3;
crsr.g_w = 1;
crsr.g_h = This->Tree[This->EditObj].ob_height +6;
if (rc_intersect (clip, &crsr)) {
crsr.g_w += crsr.g_x -1;
crsr.g_h += crsr.g_y -1;
vs_clip_pxy (vdi_handle, (PXY*)&crsr);
vswr_mode (vdi_handle, MD_XOR);
v_hide_c (vdi_handle);
v_pline (vdi_handle, 2, &crsr.g_x);
v_show_c (vdi_handle, 1);
vswr_mode (vdi_handle, MD_TRANS);
vs_clip_off (vdi_handle);
}
}
}
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
static BOOL
vTab_close (FORMWIND This, UWORD kstate)
{
(void)kstate;
if ((*This->handler)(This->Tree, -1)) {
This->Tree->ob_flags &= ~OF_FLAG15;
return TRUE; /* to be deleted */
}
return FALSE;
}
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
static void
vTab_moved (FORMWIND This)
{
wind_get_grect (This->Base.Handle, WF_WORKXYWH, This->Work);
}
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
static BOOL
dummy_handler (OBJECT * tree, WORD obj)
{
printf ("dummy_handler(%i)\n", obj);
return (obj < 0 || (tree[obj].ob_flags & OF_DEFAULT));
}
/*============================================================================*/
WORD
formwind_do (OBJECT * tree, WORD start, const char * title,
BOOL modal, BOOL(*handler)(OBJECT*,WORD))
{
FORMWIND wind = NULL;
if (!tree || (tree->ob_flags & OF_FLAG15)
|| (wind = new_formWind (tree, title, modal)) == NULL) return -1;
if (handler) {
wind->handler = handler;
}
window_raise (&wind->Base, TRUE, &wind->Base.Curr);
if (start > 0 && objc_edit (wind->Tree, start, 0, &wind->EditIdx, 1)) {
wind->EditObj = start;
}
return wind->Base.Handle;
}