1 | #include <stdio.h> |
---|
2 | #include <string.h> |
---|
3 | |
---|
4 | #include <arbdb.h> |
---|
5 | #include <aw_root.hxx> |
---|
6 | #include <aw_window.hxx> |
---|
7 | |
---|
8 | #include "ed4_class.hxx" |
---|
9 | #include "ed4_tools.hxx" |
---|
10 | |
---|
11 | int ED4_window::no_of_windows = 0; // static variable has to be initialized only once |
---|
12 | |
---|
13 | //***************************************** |
---|
14 | //* ED4_window Methods beginning * |
---|
15 | //***************************************** |
---|
16 | |
---|
17 | // void ED4_window::redraw() |
---|
18 | // { |
---|
19 | // if (ED4_ROOT->main_manager) { |
---|
20 | // AW_window *old_aww = ED4_ROOT->temp_aww; |
---|
21 | // AW_device *old_device = ED4_ROOT->temp_device; |
---|
22 | // ED4_window *old_window = ED4_ROOT->temp_ed4w; |
---|
23 | |
---|
24 | // ED4_ROOT->temp_aww = aww; |
---|
25 | // ED4_ROOT->temp_device = aww->get_device(AW_MIDDLE_AREA); |
---|
26 | // ED4_ROOT->temp_ed4w = this; |
---|
27 | |
---|
28 | // ED4_ROOT->main_manager->update_info.clear_at_refresh = 1; |
---|
29 | // ED4_ROOT->main_manager->Show(1); |
---|
30 | |
---|
31 | // ED4_ROOT->temp_aww = old_aww; |
---|
32 | // ED4_ROOT->temp_device = old_device; |
---|
33 | // ED4_ROOT->temp_ed4w = old_window; |
---|
34 | // } |
---|
35 | // } |
---|
36 | |
---|
37 | void ED4_window::reset_all_for_new_config() |
---|
38 | { |
---|
39 | horizontal_fl = NULL; |
---|
40 | vertical_fl = NULL; |
---|
41 | scrolled_rect.scroll_top = NULL; |
---|
42 | scrolled_rect.scroll_bottom = NULL; |
---|
43 | scrolled_rect.scroll_left = NULL; |
---|
44 | scrolled_rect.scroll_right = NULL; |
---|
45 | scrolled_rect.world_x = 0; |
---|
46 | scrolled_rect.world_y = 0; |
---|
47 | scrolled_rect.width = 0; |
---|
48 | scrolled_rect.height = 0; |
---|
49 | slider_pos_horizontal = 0; |
---|
50 | slider_pos_vertical = 0; |
---|
51 | coords.top_area_x = 0; |
---|
52 | coords.top_area_y = 0; |
---|
53 | coords.top_area_height = 0; |
---|
54 | coords.middle_area_x = 0; |
---|
55 | coords.middle_area_y = 0; |
---|
56 | coords.window_width = 0; |
---|
57 | coords.window_height = 0; |
---|
58 | coords.window_upper_clip_point = 0; |
---|
59 | coords.window_lower_clip_point = 0; |
---|
60 | coords.window_left_clip_point = 0; |
---|
61 | coords.window_right_clip_point = 0; |
---|
62 | |
---|
63 | ED4_ROOT->aw_root->awar(awar_path_for_cursor)->write_int(0); |
---|
64 | ED4_ROOT->aw_root->awar(awar_path_for_Ecoli)->write_int(0); |
---|
65 | ED4_ROOT->aw_root->awar(awar_path_for_basePos)->write_int(0); |
---|
66 | ED4_ROOT->aw_root->awar(awar_path_for_IUPAC)->write_string(IUPAC_EMPTY); |
---|
67 | ED4_ROOT->aw_root->awar(awar_path_for_helixNr)->write_int(0); |
---|
68 | |
---|
69 | if (next) next->reset_all_for_new_config(); |
---|
70 | } |
---|
71 | |
---|
72 | |
---|
73 | void ED4_window::update_window_coords() |
---|
74 | { |
---|
75 | AW_pos x,y; |
---|
76 | AW_rectangle area_size; |
---|
77 | |
---|
78 | ED4_ROOT->top_area_man->calc_world_coords( &x, &y ); |
---|
79 | |
---|
80 | coords.top_area_x = (long) x; |
---|
81 | coords.top_area_y = (long) y; |
---|
82 | coords.top_area_height = (long) ED4_ROOT->top_area_man->extension.size[HEIGHT]; |
---|
83 | |
---|
84 | ED4_ROOT->middle_area_man->calc_world_coords( &x, &y ); |
---|
85 | |
---|
86 | coords.middle_area_x = (long) x; |
---|
87 | coords.middle_area_y = (long) y; |
---|
88 | |
---|
89 | aww->_get_area_size (AW_MIDDLE_AREA, &area_size); |
---|
90 | |
---|
91 | coords.window_width = area_size.r; |
---|
92 | coords.window_height = area_size.b; |
---|
93 | // world coordinates |
---|
94 | coords.window_upper_clip_point = coords.middle_area_y + (long) aww->slider_pos_vertical; //coordinate of upper clipping point of middle area |
---|
95 | coords.window_lower_clip_point = coords.window_upper_clip_point + coords.window_height - coords.middle_area_y; |
---|
96 | |
---|
97 | if (ED4_ROOT->scroll_links.link_for_hor_slider) |
---|
98 | { |
---|
99 | ED4_ROOT->scroll_links.link_for_hor_slider->calc_world_coords( &x, &y ); |
---|
100 | coords.window_left_clip_point = (long) x + aww->slider_pos_horizontal; |
---|
101 | coords.window_right_clip_point = coords.window_left_clip_point + coords.window_width - (long) x; |
---|
102 | } |
---|
103 | |
---|
104 | #if defined(DEBUG) && 0 |
---|
105 | printf("left %d right %d (xdiff=%d) upper %d lower %d (ydiff=%d) width=%d height=%d\n", |
---|
106 | coords.window_left_clip_point, |
---|
107 | coords.window_right_clip_point, |
---|
108 | coords.window_right_clip_point-coords.window_left_clip_point, |
---|
109 | coords.window_upper_clip_point, |
---|
110 | coords.window_lower_clip_point, |
---|
111 | coords.window_lower_clip_point-coords.window_upper_clip_point, |
---|
112 | coords.window_width, |
---|
113 | coords.window_height); |
---|
114 | #endif |
---|
115 | } |
---|
116 | |
---|
117 | |
---|
118 | |
---|
119 | ED4_folding_line* ED4_window::insert_folding_line( AW_pos world_x, |
---|
120 | AW_pos world_y, |
---|
121 | AW_pos length, |
---|
122 | AW_pos dimension, |
---|
123 | ED4_base *link, |
---|
124 | ED4_properties prop ) |
---|
125 | { |
---|
126 | ED4_folding_line *fl, *current_fl, *previous_fl = NULL; |
---|
127 | AW_pos x, y; |
---|
128 | int rel_pos; |
---|
129 | |
---|
130 | fl = new ED4_folding_line; |
---|
131 | fl->link = link; |
---|
132 | |
---|
133 | if ( link != NULL ) { |
---|
134 | link->update_info.linked_to_folding_line = 1; |
---|
135 | link->calc_world_coords( &x, &y ); |
---|
136 | fl->world_pos[X_POS] = x; |
---|
137 | fl->world_pos[Y_POS] = y; |
---|
138 | |
---|
139 | if ( prop == ED4_P_VERTICAL ) { |
---|
140 | fl->length = link->extension.size[HEIGHT]; |
---|
141 | } |
---|
142 | else { |
---|
143 | fl->length = link->extension.size[WIDTH]; |
---|
144 | } |
---|
145 | } |
---|
146 | else |
---|
147 | { |
---|
148 | fl->world_pos[X_POS] = world_x; |
---|
149 | fl->world_pos[Y_POS] = world_y; |
---|
150 | fl->length = length; |
---|
151 | } |
---|
152 | |
---|
153 | fl->dimension = dimension; |
---|
154 | |
---|
155 | if ( prop == ED4_P_VERTICAL ) { |
---|
156 | fl->window_pos[X_POS] = fl->world_pos[X_POS] - dimension; |
---|
157 | fl->window_pos[Y_POS] = fl->world_pos[Y_POS]; |
---|
158 | |
---|
159 | if ( (current_fl = vertical_fl) == NULL ) { |
---|
160 | vertical_fl = fl; |
---|
161 | return ( fl ); |
---|
162 | } |
---|
163 | |
---|
164 | rel_pos = X_POS; |
---|
165 | } |
---|
166 | else { |
---|
167 | if ( prop == ED4_P_HORIZONTAL ) { |
---|
168 | fl->window_pos[Y_POS] = fl->world_pos[Y_POS] - dimension; |
---|
169 | fl->window_pos[X_POS] = fl->world_pos[X_POS]; |
---|
170 | |
---|
171 | if ( (current_fl = horizontal_fl) == NULL ) { |
---|
172 | horizontal_fl = fl; |
---|
173 | return ( fl ); |
---|
174 | } |
---|
175 | |
---|
176 | rel_pos = Y_POS; |
---|
177 | } |
---|
178 | else { |
---|
179 | return ( NULL ); |
---|
180 | } |
---|
181 | } |
---|
182 | |
---|
183 | while ( (current_fl != NULL) && (current_fl->world_pos[rel_pos] <= fl->world_pos[rel_pos]) ) { |
---|
184 | previous_fl = current_fl; |
---|
185 | current_fl = current_fl->next; |
---|
186 | } |
---|
187 | |
---|
188 | if (previous_fl){ |
---|
189 | previous_fl->next = fl; |
---|
190 | } |
---|
191 | fl->next = current_fl; |
---|
192 | |
---|
193 | return ( fl ); |
---|
194 | } |
---|
195 | |
---|
196 | ED4_window *ED4_window::get_matching_ed4w( AW_window *temp_aww ) |
---|
197 | { |
---|
198 | ED4_window *window; |
---|
199 | |
---|
200 | window = ED4_ROOT->first_window; |
---|
201 | while (window && window->aww != temp_aww) |
---|
202 | window = window->next; |
---|
203 | |
---|
204 | return window; |
---|
205 | } |
---|
206 | |
---|
207 | |
---|
208 | |
---|
209 | ED4_returncode ED4_window::delete_folding_line( ED4_folding_line *fl, ED4_properties prop ) |
---|
210 | { |
---|
211 | AWUSE(fl); |
---|
212 | AWUSE(prop); |
---|
213 | |
---|
214 | return ( ED4_R_OK ); |
---|
215 | } |
---|
216 | |
---|
217 | ED4_returncode ED4_window::update_scrolled_rectangle( void ) |
---|
218 | { |
---|
219 | AW_pos world_x, |
---|
220 | world_y, |
---|
221 | width, |
---|
222 | height, |
---|
223 | dummy, |
---|
224 | dim, |
---|
225 | delta; |
---|
226 | // ED4_properties scroll_prop; |
---|
227 | AW_world rect; |
---|
228 | AW_rectangle area_size; |
---|
229 | |
---|
230 | if ((scrolled_rect.scroll_top == NULL) || (scrolled_rect.scroll_bottom == NULL) || |
---|
231 | (scrolled_rect.scroll_left == NULL) || (scrolled_rect.scroll_right == NULL) ) |
---|
232 | return ED4_R_IMPOSSIBLE; |
---|
233 | |
---|
234 | world_x = scrolled_rect.world_x; |
---|
235 | world_y = scrolled_rect.world_y; |
---|
236 | width = scrolled_rect.scroll_right->world_pos[X_POS] - scrolled_rect.scroll_left->world_pos[X_POS] + 1; |
---|
237 | height = scrolled_rect.scroll_bottom->world_pos[Y_POS] - scrolled_rect.scroll_top->world_pos[Y_POS] + 1; |
---|
238 | |
---|
239 | |
---|
240 | if ( scrolled_rect.x_link != NULL ) // calculate possibly new world coordinates and extensions of existing links |
---|
241 | scrolled_rect.x_link->calc_world_coords( &world_x, &dummy ); |
---|
242 | |
---|
243 | if ( scrolled_rect.y_link != NULL ) |
---|
244 | scrolled_rect.y_link->calc_world_coords( &dummy, &world_y ); |
---|
245 | |
---|
246 | if ( scrolled_rect.width_link != NULL ) |
---|
247 | width = scrolled_rect.width_link->extension.size[WIDTH]; |
---|
248 | |
---|
249 | if ( scrolled_rect.height_link != NULL ) |
---|
250 | height = scrolled_rect.height_link->extension.size[HEIGHT]; |
---|
251 | |
---|
252 | scrolled_rect.scroll_top->world_pos[X_POS] = world_x; // set new world and window coordinates |
---|
253 | scrolled_rect.scroll_top->world_pos[Y_POS] = world_y; |
---|
254 | scrolled_rect.scroll_top->window_pos[X_POS] = world_x; |
---|
255 | scrolled_rect.scroll_top->window_pos[Y_POS] = world_y; |
---|
256 | |
---|
257 | if ( scrolled_rect.scroll_top->length != INFINITE ) |
---|
258 | scrolled_rect.scroll_top->length = width; |
---|
259 | |
---|
260 | scrolled_rect.scroll_bottom->world_pos[X_POS] = world_x; |
---|
261 | scrolled_rect.scroll_bottom->world_pos[Y_POS] = world_y + height - 1; |
---|
262 | |
---|
263 | if ( scrolled_rect.scroll_bottom->length != INFINITE ) |
---|
264 | scrolled_rect.scroll_bottom->length = width; |
---|
265 | |
---|
266 | scrolled_rect.scroll_left->world_pos[X_POS] = world_x; |
---|
267 | scrolled_rect.scroll_left->world_pos[Y_POS] = world_y; |
---|
268 | scrolled_rect.scroll_left->window_pos[X_POS] = world_x; |
---|
269 | scrolled_rect.scroll_left->window_pos[Y_POS] = world_y; |
---|
270 | |
---|
271 | if ( scrolled_rect.scroll_left->length != INFINITE ) |
---|
272 | scrolled_rect.scroll_left->length = height; |
---|
273 | |
---|
274 | scrolled_rect.scroll_right->world_pos[X_POS] = world_x + width - 1; |
---|
275 | scrolled_rect.scroll_right->world_pos[Y_POS] = world_y; |
---|
276 | |
---|
277 | if ( scrolled_rect.scroll_right->length != INFINITE ) |
---|
278 | scrolled_rect.scroll_right->length = height; |
---|
279 | |
---|
280 | scrolled_rect.world_x = world_x; |
---|
281 | scrolled_rect.world_y = world_y; |
---|
282 | scrolled_rect.width = width; |
---|
283 | scrolled_rect.height = height; |
---|
284 | |
---|
285 | rect.t = 0; // update window scrollbars |
---|
286 | rect.l = 0; |
---|
287 | rect.r = width - 1; |
---|
288 | rect.b = height - 1; |
---|
289 | |
---|
290 | set_scrollbar_indents(); |
---|
291 | aww->tell_scrolled_picture_size( rect ); |
---|
292 | aww->calculate_scrollbars(); |
---|
293 | |
---|
294 | delta = aww->slider_pos_horizontal - slider_pos_horizontal; // update dimension and window position of folding lines at |
---|
295 | scrolled_rect.scroll_left->dimension += delta; // the borders of scrolled rectangle |
---|
296 | delta = aww->slider_pos_vertical - slider_pos_vertical; |
---|
297 | scrolled_rect.scroll_top->dimension += delta; |
---|
298 | ED4_ROOT->temp_device->get_area_size( &area_size ); |
---|
299 | |
---|
300 | if ( scrolled_rect.height_link != NULL ) |
---|
301 | slider_pos_vertical = aww->slider_pos_vertical; |
---|
302 | |
---|
303 | if ( scrolled_rect.width_link != NULL ) |
---|
304 | slider_pos_horizontal = aww->slider_pos_horizontal; |
---|
305 | |
---|
306 | |
---|
307 | if ( (world_y + height - 1) > area_size.b ) // our world doesn't fit vertically in our window => |
---|
308 | { // determine dimension of bottom folding line |
---|
309 | dim = (world_y + height - 1) - area_size.b; |
---|
310 | scrolled_rect.scroll_bottom->dimension = max(0, int(dim - scrolled_rect.scroll_top->dimension)); |
---|
311 | } |
---|
312 | else |
---|
313 | { |
---|
314 | dim = 0; |
---|
315 | scrolled_rect.scroll_bottom->dimension = 0; |
---|
316 | scrolled_rect.scroll_top->dimension = 0; |
---|
317 | } |
---|
318 | |
---|
319 | scrolled_rect.scroll_bottom->window_pos[Y_POS] = world_y + height - 1 - dim; |
---|
320 | scrolled_rect.scroll_bottom->window_pos[X_POS] = world_x; |
---|
321 | |
---|
322 | if ( (world_x + width - 1) > area_size.r ) // our world doesn't fit horizontally in our window => |
---|
323 | { // determine dimension of right folding line |
---|
324 | dim = (world_x + width - 1) - area_size.r; |
---|
325 | scrolled_rect.scroll_right->dimension = max(0, int(dim - scrolled_rect.scroll_left->dimension)); |
---|
326 | } |
---|
327 | else |
---|
328 | { |
---|
329 | dim = 0; |
---|
330 | scrolled_rect.scroll_right->dimension = 0; |
---|
331 | scrolled_rect.scroll_left->dimension = 0; |
---|
332 | } |
---|
333 | |
---|
334 | scrolled_rect.scroll_right->window_pos[X_POS] = world_x + width - 1 - dim; |
---|
335 | scrolled_rect.scroll_right->window_pos[Y_POS] = world_y; |
---|
336 | |
---|
337 | update_window_coords(); |
---|
338 | |
---|
339 | // #if 0 |
---|
340 | // scroll_prop = (ED4_properties) ( ED4_P_SCROLL_HORIZONTAL | ED4_P_SCROLL_VERTICAL ); // set current scrolling update flags |
---|
341 | // ED4_ROOT->main_manager->set_scroll_refresh( world_x, world_y, width, height, scroll_prop ); |
---|
342 | |
---|
343 | // scroll_prop = ED4_P_SCROLL_HORIZONTAL; |
---|
344 | // ED4_ROOT->main_manager->set_scroll_refresh( world_x, 0, width, world_y, scroll_prop ); |
---|
345 | // ED4_ROOT->main_manager->set_scroll_refresh( world_x, (world_y + height), width, INFINITE, scroll_prop ); |
---|
346 | |
---|
347 | // scroll_prop = ED4_P_SCROLL_VERTICAL; |
---|
348 | // ED4_ROOT->main_manager->set_scroll_refresh( 0, world_y, world_x, height, scroll_prop ); |
---|
349 | // ED4_ROOT->main_manager->set_scroll_refresh( (world_x + width), world_y, INFINITE, height, scroll_prop ); |
---|
350 | |
---|
351 | // scroll_prop = ED4_P_NO_PROP; |
---|
352 | // ED4_ROOT->main_manager->set_scroll_refresh( 0, 0, world_x, world_y, scroll_prop ); |
---|
353 | // ED4_ROOT->main_manager->set_scroll_refresh( (world_x + width), world_y, INFINITE, height, scroll_prop ); |
---|
354 | // #endif |
---|
355 | |
---|
356 | return ( ED4_R_OK ); |
---|
357 | } |
---|
358 | |
---|
359 | ED4_returncode ED4_window::set_scrolled_rectangle( AW_pos world_x, AW_pos world_y, AW_pos width, AW_pos height, |
---|
360 | ED4_base *x_link, ED4_base *y_link, ED4_base *width_link, ED4_base *height_link ) |
---|
361 | { |
---|
362 | AW_pos x, y, dim; |
---|
363 | AW_rectangle area_size; |
---|
364 | |
---|
365 | if ( scrolled_rect.scroll_top != NULL ) // first of all remove existing scrolled rectangle |
---|
366 | delete_folding_line( scrolled_rect.scroll_top, ED4_P_HORIZONTAL ); |
---|
367 | |
---|
368 | if ( scrolled_rect.scroll_bottom != NULL ) |
---|
369 | delete_folding_line( scrolled_rect.scroll_bottom, ED4_P_HORIZONTAL ); |
---|
370 | |
---|
371 | if ( scrolled_rect.scroll_left != NULL ) |
---|
372 | delete_folding_line( scrolled_rect.scroll_left, ED4_P_VERTICAL ); |
---|
373 | |
---|
374 | if ( scrolled_rect.scroll_right != NULL ) |
---|
375 | delete_folding_line( scrolled_rect.scroll_right, ED4_P_VERTICAL ); |
---|
376 | |
---|
377 | if ( x_link != NULL ) |
---|
378 | { |
---|
379 | x_link->update_info.linked_to_scrolled_rectangle = 1; |
---|
380 | x_link->calc_world_coords( &x, &y ); |
---|
381 | world_x = x; |
---|
382 | } |
---|
383 | |
---|
384 | if ( y_link != NULL ) |
---|
385 | { |
---|
386 | y_link->update_info.linked_to_scrolled_rectangle = 1; |
---|
387 | y_link->calc_world_coords( &x, &y ); |
---|
388 | world_y = y; |
---|
389 | } |
---|
390 | |
---|
391 | if ( width_link != NULL ) |
---|
392 | { |
---|
393 | width_link->update_info.linked_to_scrolled_rectangle = 1; |
---|
394 | width = width_link->extension.size[WIDTH]; |
---|
395 | } |
---|
396 | |
---|
397 | if ( height_link != NULL ) |
---|
398 | { |
---|
399 | height_link->update_info.linked_to_scrolled_rectangle = 1; |
---|
400 | height = height_link->extension.size[HEIGHT]; |
---|
401 | } |
---|
402 | |
---|
403 | ED4_ROOT->temp_device->get_area_size( &area_size ); |
---|
404 | |
---|
405 | if ( (area_size.r <= world_x) || (area_size.b <= world_y) ) |
---|
406 | return ( ED4_R_IMPOSSIBLE ); |
---|
407 | |
---|
408 | scrolled_rect.scroll_top = insert_folding_line( world_x, world_y, INFINITE, 0, NULL, ED4_P_HORIZONTAL ); |
---|
409 | scrolled_rect.scroll_left = insert_folding_line( world_x, world_y, INFINITE, 0, NULL, ED4_P_VERTICAL ); |
---|
410 | |
---|
411 | dim = 0; |
---|
412 | if ( (world_y + height - 1) > area_size.b ) |
---|
413 | dim = (world_y + height - 1) - area_size.b; |
---|
414 | |
---|
415 | scrolled_rect.scroll_bottom = insert_folding_line( world_x, (world_y + height - 1), INFINITE, dim, NULL, ED4_P_HORIZONTAL ); |
---|
416 | |
---|
417 | dim = 0; |
---|
418 | if ( (world_x + width - 1) > area_size.r ) |
---|
419 | dim = (world_x + width - 1) - area_size.r; |
---|
420 | |
---|
421 | scrolled_rect.scroll_right = insert_folding_line( (world_x + width - 1), world_y, INFINITE, dim, NULL, ED4_P_VERTICAL ); |
---|
422 | scrolled_rect.x_link = x_link; |
---|
423 | scrolled_rect.y_link = y_link; |
---|
424 | scrolled_rect.width_link = width_link; |
---|
425 | scrolled_rect.height_link = height_link; |
---|
426 | scrolled_rect.world_x = world_x; |
---|
427 | scrolled_rect.world_y = world_y; |
---|
428 | scrolled_rect.width = width; |
---|
429 | scrolled_rect.height = height; |
---|
430 | |
---|
431 | return( ED4_R_OK ); |
---|
432 | } |
---|
433 | |
---|
434 | static inline void clear_and_update_rectangle(AW_pos x1, AW_pos y1, AW_pos x2, AW_pos y2) |
---|
435 | // clears and updates any range of the screen (in win coordinates) |
---|
436 | // clipping range should be set correctly |
---|
437 | { |
---|
438 | AW_rectangle rect; |
---|
439 | |
---|
440 | rect.t = int(y1); |
---|
441 | rect.b = int(y2); |
---|
442 | rect.l = int(x1); |
---|
443 | rect.r = int(x2); |
---|
444 | ED4_set_clipping_rectangle(&rect); |
---|
445 | |
---|
446 | #if defined(DEBUG) && 0 |
---|
447 | static int toggle = 0; |
---|
448 | ED4_ROOT->temp_device->box(ED4_G_COLOR_2+toggle, x1, y1, x2-x1+1, y2-y1+1, (AW_bitset)-1, 0, 0); // fill range with blue (for testing) |
---|
449 | toggle = (toggle+1)&3; |
---|
450 | #else |
---|
451 | ED4_ROOT->temp_device->clear_part(x1, y1, x2-x1+1, y2-y1+1); |
---|
452 | #endif |
---|
453 | |
---|
454 | // ED4_ROOT->main_manager->Show(1); |
---|
455 | ED4_ROOT->main_manager->to_manager()->Show(1,1); |
---|
456 | } |
---|
457 | |
---|
458 | static inline int abs(int i) |
---|
459 | { |
---|
460 | return i<0 ? -i : i; |
---|
461 | } |
---|
462 | |
---|
463 | static inline void move_and_update_rectangle(AW_pos x1, AW_pos y1, AW_pos x2, AW_pos y2, int dx, int dy) |
---|
464 | // x1/y1=upper-left-corner (win coordinates) |
---|
465 | // x2/y2=lower-right-corner |
---|
466 | // dx/dy=movement |
---|
467 | { |
---|
468 | AW_pos fx = dx<0 ? x1-dx : x1; // move from position .. |
---|
469 | AW_pos fy = dy<0 ? y1-dy : y1; |
---|
470 | AW_pos tx = dx>0 ? x1+dx : x1; // ..to position .. |
---|
471 | AW_pos ty = dy>0 ? y1+dy : y1; |
---|
472 | int xs = int(x2-x1-abs(dx)); // ..size |
---|
473 | int ys = int(y2-y1-abs(dy)); |
---|
474 | |
---|
475 | { |
---|
476 | AW_rectangle rect; |
---|
477 | rect.t = int(ty); |
---|
478 | rect.b = int(ty+ys-1); |
---|
479 | rect.l = int(tx); |
---|
480 | rect.r = int(tx+xs-1); |
---|
481 | ED4_set_clipping_rectangle(&rect); |
---|
482 | } |
---|
483 | ED4_ROOT->temp_device->move_region(fx, fy, xs, ys, tx, ty); |
---|
484 | |
---|
485 | if (dy<0) { // scroll to the top |
---|
486 | ED4_ROOT->temp_device->set_top_font_overlap(1); |
---|
487 | clear_and_update_rectangle(x1, y2+dy, x2, y2); |
---|
488 | ED4_ROOT->temp_device->set_top_font_overlap(0); |
---|
489 | } |
---|
490 | else if (dy>0) { // scroll to the bottom |
---|
491 | ED4_ROOT->temp_device->set_bottom_font_overlap(1); |
---|
492 | clear_and_update_rectangle(x1, y1, x2, y1+dy); |
---|
493 | ED4_ROOT->temp_device->set_bottom_font_overlap(0); |
---|
494 | } |
---|
495 | |
---|
496 | if (dx<0) { // scroll left |
---|
497 | ED4_ROOT->temp_device->set_left_font_overlap(1); |
---|
498 | clear_and_update_rectangle(x2+dx, y1, x2, y2); |
---|
499 | ED4_ROOT->temp_device->set_left_font_overlap(0); |
---|
500 | } |
---|
501 | else if (dx>0) { // scroll right |
---|
502 | ED4_ROOT->temp_device->set_right_font_overlap(1); |
---|
503 | clear_and_update_rectangle(x1, y1, x1+dx, y2); |
---|
504 | ED4_ROOT->temp_device->set_right_font_overlap(0); |
---|
505 | } |
---|
506 | |
---|
507 | } |
---|
508 | |
---|
509 | static inline void update_rectangle(AW_pos x1, AW_pos y1, AW_pos x2, AW_pos y2) // x1/y1=upper-left-corner x2/y2=lower-right-corner |
---|
510 | { |
---|
511 | AW_rectangle rect; |
---|
512 | rect.t = int(y1); |
---|
513 | rect.b = int(y2); |
---|
514 | rect.l = int(x1); |
---|
515 | rect.r = int(x2); |
---|
516 | |
---|
517 | ED4_set_clipping_rectangle(&rect); |
---|
518 | clear_and_update_rectangle(x1, y1, x2, y2); |
---|
519 | } |
---|
520 | |
---|
521 | |
---|
522 | ED4_returncode ED4_window::scroll_rectangle( int dx, int dy ) |
---|
523 | { |
---|
524 | int skip_move; |
---|
525 | |
---|
526 | if (!dx && !dy) return ED4_R_OK; // scroll not |
---|
527 | |
---|
528 | AW_pos left_x = scrolled_rect.scroll_left->window_pos[X_POS]; |
---|
529 | AW_pos top_y = scrolled_rect.scroll_top->window_pos[Y_POS]; |
---|
530 | AW_pos right_x = scrolled_rect.scroll_right->window_pos[X_POS]; |
---|
531 | AW_pos bottom_y = scrolled_rect.scroll_bottom->window_pos[Y_POS]; |
---|
532 | |
---|
533 | // e4_assert((scrolled_rect.scroll_left->dimension-dx)>=0); // if any of these asserts fails, dx or dy is set wrong |
---|
534 | // e4_assert((scrolled_rect.scroll_right->dimension+dx)>=0); |
---|
535 | // e4_assert((scrolled_rect.scroll_top->dimension-dy)>=0); |
---|
536 | // e4_assert((scrolled_rect.scroll_bottom->dimension+dy)>=0); |
---|
537 | |
---|
538 | scrolled_rect.scroll_left->dimension -= dx; |
---|
539 | scrolled_rect.scroll_top->dimension -= dy; |
---|
540 | scrolled_rect.scroll_right->dimension += dx; |
---|
541 | scrolled_rect.scroll_bottom->dimension += dy; |
---|
542 | |
---|
543 | // printf("top->dimension=%f bottom->dimension=%f dx=%f dy=%f\n", scrolled_rect.scroll_top->dimension, scrolled_rect.scroll_bottom->dimension, dx, dy); |
---|
544 | |
---|
545 | skip_move = (ABS(int(dy)) > (bottom_y - top_y - 20)) || (ABS(int(dx)) > (right_x - left_x - 20)); |
---|
546 | |
---|
547 | AW_pos leftmost_x = coords.middle_area_x; |
---|
548 | AW_pos toptop_y = coords.top_area_y; |
---|
549 | AW_pos topbottom_y = toptop_y + coords.top_area_height - 1; |
---|
550 | |
---|
551 | ED4_ROOT->temp_device->push_clip_scale(); |
---|
552 | |
---|
553 | // main area |
---|
554 | |
---|
555 | if (skip_move) update_rectangle(left_x, top_y, right_x, bottom_y); // main area |
---|
556 | else move_and_update_rectangle(left_x, top_y, right_x, bottom_y, int(dx), int(dy)); // main area |
---|
557 | |
---|
558 | // ED4_ROOT->temp_device->y_font_overlap = 0; |
---|
559 | |
---|
560 | // name area (scroll only vertically) |
---|
561 | |
---|
562 | if (dy) { |
---|
563 | if (skip_move) update_rectangle(leftmost_x, top_y, left_x, bottom_y); |
---|
564 | else move_and_update_rectangle(leftmost_x, top_y, left_x, bottom_y, 0, int(dy)); |
---|
565 | } |
---|
566 | |
---|
567 | // top area (scroll only horizontally) |
---|
568 | |
---|
569 | if (dx) { |
---|
570 | if (skip_move) update_rectangle(left_x, toptop_y, right_x, topbottom_y); |
---|
571 | else move_and_update_rectangle(left_x, toptop_y, right_x, topbottom_y, int(dx), 0); |
---|
572 | } |
---|
573 | |
---|
574 | ED4_ROOT->temp_device->pop_clip_scale(); |
---|
575 | |
---|
576 | return ( ED4_R_OK ); |
---|
577 | } |
---|
578 | |
---|
579 | ED4_returncode ED4_window::set_scrollbar_indents( void ) { |
---|
580 | int indent_y, indent_x; |
---|
581 | |
---|
582 | if ( (scrolled_rect.scroll_top == NULL) || |
---|
583 | (scrolled_rect.scroll_bottom == NULL) || |
---|
584 | (scrolled_rect.scroll_left == NULL) || |
---|
585 | (scrolled_rect.scroll_right == NULL) ) |
---|
586 | return ( ED4_R_IMPOSSIBLE ); |
---|
587 | |
---|
588 | indent_y = (int) scrolled_rect.world_y + SLIDER_OFFSET; |
---|
589 | aww->set_vertical_scrollbar_top_indent( indent_y ); |
---|
590 | indent_x = (int) scrolled_rect.world_x + SLIDER_OFFSET; |
---|
591 | aww->set_horizontal_scrollbar_left_indent( indent_x ); |
---|
592 | |
---|
593 | return ( ED4_R_OK ); |
---|
594 | } |
---|
595 | |
---|
596 | |
---|
597 | void ED4_window::delete_window( ED4_window *window) //delete from window list |
---|
598 | { |
---|
599 | ED4_window *temp, *temp2; |
---|
600 | |
---|
601 | |
---|
602 | if (window == ED4_ROOT->first_window) |
---|
603 | { |
---|
604 | temp = ED4_ROOT->first_window; //delete temp afterwards |
---|
605 | ED4_ROOT->first_window = ED4_ROOT->first_window->next; |
---|
606 | |
---|
607 | if (no_of_windows > 1) |
---|
608 | { |
---|
609 | ED4_ROOT->temp_ed4w = ED4_ROOT->first_window; |
---|
610 | ED4_ROOT->temp_aww = ED4_ROOT->temp_ed4w->aww; |
---|
611 | ED4_ROOT->temp_device = ED4_ROOT->temp_ed4w->aww->get_device ( AW_MIDDLE_AREA ); |
---|
612 | } |
---|
613 | } |
---|
614 | else |
---|
615 | { |
---|
616 | temp = temp2 = ED4_ROOT->first_window; |
---|
617 | |
---|
618 | while (temp != window) |
---|
619 | { |
---|
620 | temp2 = temp; |
---|
621 | temp = temp->next; |
---|
622 | } |
---|
623 | |
---|
624 | temp2->next = temp->next; |
---|
625 | |
---|
626 | ED4_ROOT->temp_ed4w = temp2; |
---|
627 | ED4_ROOT->temp_aww = ED4_ROOT->temp_ed4w->aww; |
---|
628 | ED4_ROOT->temp_device = ED4_ROOT->temp_ed4w->aww->get_device ( AW_MIDDLE_AREA ); |
---|
629 | } |
---|
630 | |
---|
631 | ED4_ROOT->aw_root->awar(temp->awar_path_for_cursor)->write_int(0); // save in database |
---|
632 | ED4_ROOT->aw_root->awar(temp->awar_path_for_Ecoli)->write_int(0); |
---|
633 | ED4_ROOT->aw_root->awar(temp->awar_path_for_basePos)->write_int(0); |
---|
634 | ED4_ROOT->aw_root->awar(temp->awar_path_for_IUPAC)->write_string(IUPAC_EMPTY); |
---|
635 | ED4_ROOT->aw_root->awar(temp->awar_path_for_helixNr)->write_int(0); |
---|
636 | delete temp; |
---|
637 | } |
---|
638 | |
---|
639 | |
---|
640 | ED4_window *ED4_window::insert_window( AW_window *new_aww ) |
---|
641 | { |
---|
642 | AW_device *device; |
---|
643 | ED4_window *last,*temp; |
---|
644 | |
---|
645 | temp = ED4_ROOT->first_window; //append at end of window list |
---|
646 | last = temp; |
---|
647 | while (temp) |
---|
648 | { |
---|
649 | last = temp; |
---|
650 | temp = temp->next; |
---|
651 | } |
---|
652 | |
---|
653 | temp = new ED4_window ( new_aww ); |
---|
654 | |
---|
655 | if ( ED4_ROOT->first_window == NULL ) //this is the first window |
---|
656 | ED4_ROOT->first_window = temp; |
---|
657 | else |
---|
658 | if ( last != NULL) |
---|
659 | last->next = temp; |
---|
660 | |
---|
661 | // treat devices |
---|
662 | device = new_aww->get_device ( AW_MIDDLE_AREA); |
---|
663 | new_aww->set_expose_callback ( AW_MIDDLE_AREA, ED4_expose_cb , 0, 0 ); |
---|
664 | new_aww->set_resize_callback ( AW_MIDDLE_AREA, ED4_resize_cb , 0, 0 ); |
---|
665 | new_aww->set_input_callback ( AW_MIDDLE_AREA, ED4_input_cb , 0, 0 ); |
---|
666 | new_aww->set_motion_callback ( AW_MIDDLE_AREA, ED4_motion_cb , 0, 0 ); |
---|
667 | new_aww->set_horizontal_change_callback( ED4_horizontal_change_cb , 0, 0 ); |
---|
668 | new_aww->set_vertical_change_callback ( ED4_vertical_change_cb , 0, 0 ); |
---|
669 | |
---|
670 | // set temporary variables in ED4_ROOT |
---|
671 | ED4_ROOT->temp_ed4w = temp; |
---|
672 | ED4_ROOT->temp_aww = new_aww; |
---|
673 | ED4_ROOT->temp_device = device; |
---|
674 | ED4_ROOT->temp_gc = ED4_G_STANDARD; |
---|
675 | |
---|
676 | return ( temp ); |
---|
677 | } |
---|
678 | |
---|
679 | ED4_window::ED4_window( AW_window *window ) |
---|
680 | { |
---|
681 | aww = window; |
---|
682 | next = 0; |
---|
683 | slider_pos_horizontal = 0; |
---|
684 | slider_pos_vertical = 0; |
---|
685 | horizontal_fl = 0; |
---|
686 | vertical_fl = 0; |
---|
687 | scrolled_rect.clear(); |
---|
688 | id = ++no_of_windows; |
---|
689 | coords.clear(); |
---|
690 | is_hidden = 0; |
---|
691 | |
---|
692 | sprintf(awar_path_for_cursor, AWAR_EDIT_SEQ_POSITION, id); |
---|
693 | ED4_ROOT->aw_root->awar_int(awar_path_for_cursor,0,AW_ROOT_DEFAULT)->set_minmax(0,99999); |
---|
694 | |
---|
695 | sprintf(awar_path_for_Ecoli, AWAR_EDIT_ECOLI_POSITION, id); |
---|
696 | ED4_ROOT->aw_root->awar_int(awar_path_for_Ecoli,0,AW_ROOT_DEFAULT)->set_minmax(0,99999); |
---|
697 | |
---|
698 | sprintf(awar_path_for_basePos, AWAR_EDIT_BASE_POSITION, id); |
---|
699 | ED4_ROOT->aw_root->awar_int(awar_path_for_basePos,0,AW_ROOT_DEFAULT)->set_minmax(0,99999); |
---|
700 | |
---|
701 | sprintf(awar_path_for_IUPAC, AWAR_EDIT_IUPAC, id); |
---|
702 | ED4_ROOT->aw_root->awar_string(awar_path_for_IUPAC,IUPAC_EMPTY,AW_ROOT_DEFAULT); |
---|
703 | |
---|
704 | sprintf(awar_path_for_helixNr, AWAR_EDIT_HELIXNR, id); |
---|
705 | ED4_ROOT->aw_root->awar_int(awar_path_for_helixNr,0,AW_ROOT_DEFAULT)->set_minmax(-99999,99999); |
---|
706 | } |
---|
707 | |
---|
708 | |
---|
709 | ED4_window::~ED4_window() |
---|
710 | { |
---|
711 | delete aww; |
---|
712 | delete horizontal_fl; // be careful, don't delete links to hierarchy in folding lines!!! |
---|
713 | delete vertical_fl; |
---|
714 | |
---|
715 | /* if (scrolled_rect.scroll_top) |
---|
716 | delete scrolled_rect.scroll_top; |
---|
717 | if (scrolled_rect.scroll_bottom) |
---|
718 | delete scrolled_rect.scroll_bottom; |
---|
719 | if (scrolled_rect.scroll_left) |
---|
720 | delete scrolled_rect.scroll_left; |
---|
721 | if (scrolled_rect.scroll_right) |
---|
722 | delete scrolled_rect.scroll_right; |
---|
723 | */ |
---|
724 | no_of_windows --; |
---|
725 | } |
---|
726 | |
---|
727 | //*********************************** |
---|
728 | //* ED4_window Methods end * |
---|
729 | //*********************************** |
---|
730 | |
---|
731 | |
---|
732 | |
---|