-
Notifications
You must be signed in to change notification settings - Fork 4
/
slider.c
282 lines (227 loc) · 5.62 KB
/
slider.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
/*
* Teradesk. Copyright (c) 1993 - 2002 W. Klaren,
* 2002 - 2003 H. Robbers,
* 2003 - 2008 Dj. Vukovic
*
* This file is part of Teradesk.
*
* Teradesk is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* Teradesk is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Teradesk; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1307 USA
*/
#include <library.h>
#include <xdialog.h>
#include <xscncode.h>
#include "resource.h"
#include "desk.h"
#include "events.h"
#include "lists.h"
#include "slider.h"
#include "file.h"
/*
* Set slider size and position
*/
void sl_set_slider(SLIDER *sl, XDINFO *info)
{
_WORD sh;
_WORD s;
_WORD sn = sl->n;
_WORD slines = sl->lines;
_WORD slh = sl->tree[sl->sparent].ob_height;
sl->line = ((sn < slines) || (sl->line < 0)) ? 0 : min(sl->line, sn - slines);
/* Determine slider size. Minimum size is equal to character height */
if (sn > slines)
{
sh = (_WORD) (((long) slines * (long) slh) / (long) sn);
if (sh < xd_fnt_h)
sh = xd_fnt_h;
} else
{
sh = slh;
}
/* Compensation for 3D effects */
sl->tree[sl->slider].ob_height = sh - 2 * aes_ver3d;
/* Determine slider position */
s = sn - slines;
sl->tree[sl->slider].ob_y =
aes_ver3d + ((s > 0) ? (_WORD) (((long) (slh - sh) * (long) (sl->line)) / (long) s) : 0);
if (info)
xd_drawdeep(info, sl->sparent);
}
/*
* Calculate to which item a slider points.
*/
_WORD calc_slpos(_WORD newpos, /* position (0:1000) */
long lines /* number of items */
)
{
return (_WORD) (((lines * newpos) / 1000L));
}
/*
* Calculate slider position (0:1000) for the first visible item
*/
_WORD calc_slmill(long pos, /* index of first item */
long lines /* number of items */
)
{
return (lines) ? (_WORD) ((1000L * pos) / lines) : 0;
}
static void do_slider(SLIDER *sl, XDINFO *info)
{
long lines;
_WORD newpos;
xd_begmctrl();
newpos = graf_slidebox(sl->tree, sl->sparent, sl->slider, 1);
xd_endmctrl();
/*
* Fix what seems to be a bug in graf_slidebox of Atari AES4.1 ?
* (wrong setting for small values of slider position)
*/
if (newpos < 40)
newpos = 0;
lines = sl->n - sl->lines;
sl->line = calc_slpos(newpos, lines);
sl_set_slider(sl, info);
}
/*
* This routine handles clicking on the slider parent object
* i.e. paging up or down through a list with a slider
*/
static void do_bar(SLIDER *sl, XDINFO *info)
{
_WORD my, oy;
_WORD dummy, old, maxi;
_WORD slines = sl->lines;
graf_mkstate(&dummy, &my, &dummy, &dummy);
objc_offset(sl->tree, sl->slider, &dummy, &oy);
do
{
old = sl->line;
if (my < oy)
{
maxi = sl->line;
sl->line -= slines;
} else
{
maxi = sl->n - slines;
sl->line += slines;
}
sl->line = minmax(0, sl->line, maxi);
if (sl->line != old)
{
sl_set_slider(sl, info);
sl->set_selector(sl, TRUE, info);
}
} while (xe_button_state() & 0x1);
}
/*
* This routine handles movement of the selected item in the selector
* with more than one items displayed. If some work gets done in this
* routine, it returns 1; if the work is to be done elsewhere, it returns 0.
* part of the code acctivated by j <> 0 is only for the use of keyfunc()
* in list_edit(); otherwise it is completely redundant
*/
_WORD keyfunc(XDINFO *info, SLIDER *sl, _WORD scancode)
{
_WORD k = 0;
_WORD j = 0;
_WORD selected;
switch ((unsigned short) scancode)
{
case CTL_CURUP:
if ((sl->type != 0) && ((selected = sl->findsel()) != 0))
k = -1;
else if (sl->line > 0)
j = -1;
break;
case CTL_CURDOWN:
if ((sl->type != 0) && ((selected = sl->findsel()) != (sl->lines - 1)))
k = 1;
else if (sl->line < (sl->n - sl->lines))
j = 1;
break;
default:
break;
}
if (k != 0)
{
selected += sl->first;
obj_deselect(sl->tree[selected]);
obj_select(sl->tree[selected + k]);
sl->set_selector(sl, TRUE, info);
return 1;
}
if (j != 0)
{
sl->line += j;
sl_set_slider(sl, info);
sl->set_selector(sl, TRUE, info);
return 1;
}
return 0;
}
/*
* This routine handles the pressed arrow buttons in a slider
*/
_WORD sl_handle_button(_WORD button, SLIDER *sl, XDINFO *info)
{
_WORD j = 0, button2 = button & 0x7FFF;
if (button2 == sl->up_arrow)
{
if (sl->line > 0)
j = -1;
} else if (button2 == sl->down_arrow)
{
if (sl->line < (sl->n - sl->lines))
j = 1;
} else if (button2 == sl->slider)
{
do_slider(sl, info);
sl->set_selector(sl, TRUE, info);
} else if (button2 == sl->sparent)
{
do_bar(sl, info);
} else
{
return FALSE;
}
if (j != 0)
{
sl->line += j;
sl_set_slider(sl, info);
sl->set_selector(sl, TRUE, info);
}
return TRUE;
}
/*
* Note: in case of a double click, bit 0x8000 is set in returned value
*/
_WORD sl_form_do(_WORD start, SLIDER *sl, XDINFO *info)
{
_WORD button;
do
{
button = xd_kform_do(info, start, (userkeys) keyfunc, sl);
} while (sl_handle_button(button, sl, info));
return button;
}
/*
* Initialize sizes and positions of the slider and its listbox.
* Note: this routine does -NOT- draw the elements because XDINFO
* is missing!
*/
void sl_init(SLIDER *slider)
{
slider->set_selector(slider, FALSE, NULL);
sl_set_slider(slider, NULL);
}