ARB
ED4_window.cxx
Go to the documentation of this file.
1 // =============================================================== //
2 // //
3 // File : ED4_window.cxx //
4 // Purpose : //
5 // //
6 // Institute of Microbiology (Technical University Munich) //
7 // http://www.arb-home.de/ //
8 // //
9 // =============================================================== //
10 
11 #include <arbdb.h>
12 #include <ed4_extern.hxx>
13 #include "ed4_class.hxx"
14 #include "ed4_tools.hxx"
15 #include <aw_awar.hxx>
16 #include <aw_root.hxx>
17 
18 int ED4_window::no_of_windows = 0; // static variable has to be initialized only once
19 
21  scrolled_rect.reset(*this);
23 
26 
27  coords.top_area_x = 0;
28  coords.top_area_y = 0;
30 
33 
34  coords.window_width = 0;
36 
41 
47 
49 }
50 
51 
53  AW_pos x, y;
54  AW_screen_area area_size;
55 
57 
58  coords.top_area_x = (long) x;
59  coords.top_area_y = (long) y;
61 
63 
66 
67  aww->_get_area_size (AW_MIDDLE_AREA, &area_size);
68 
69  coords.window_width = area_size.r;
70  coords.window_height = area_size.b;
71 
72  // world coordinates
73  coords.window_upper_clip_point = coords.middle_area_y + aww->slider_pos_vertical; // coordinate of upper clipping point of middle area
75 
80  }
81 
82 #if defined(DEBUG) && 0
83  printf("left %d right %d (xdiff=%d) upper %d lower %d (ydiff=%d) width=%d height=%d\n",
92 #endif
93 }
94 
95 
96 
98  ED4_folding_line *fl = NULp;
99 
100  if (prop == PROP_VERTICAL || prop == PROP_HORIZONTAL) {
101  fl = new ED4_folding_line(world_pos, dimension);
102  fl->insertAs(prop == PROP_VERTICAL ? vertical_fl : horizontal_fl);
103  }
104  return fl;
105 }
106 
108  e4_assert(aw);
109 
110  ED4_window *window = ED4_ROOT->first_window;
111  while (window && window->aww != aw) {
112  window = window->next;
113  }
114 
115  e4_assert(window); // aw is not an edit-window
116  return window;
117 }
118 
119 
120 
122  if (prop == PROP_HORIZONTAL) {
123  horizontal_fl = horizontal_fl->delete_member(fl);
124  }
125  else {
126  e4_assert(prop == PROP_VERTICAL);
127  vertical_fl = vertical_fl->delete_member(fl);
128  }
129 }
130 
132  e4_assert(is_linked());
133 
134  AW_pos x, y, dummy;
135  x_link->calc_world_coords(&x, &dummy);
136  y_link->calc_world_coords(&dummy, &y);
137 
138  AW::Vector size(width_link->extension.size[WIDTH],
139  height_link->extension.size[HEIGHT]);
140 
141  return AW::Rectangle(AW::Position(x, y), size);
142 }
143 
145  if (scrolled_rect.exists()) {
147 
150 
151  // if slider positions stored in AW_window and ED4_window differ,
152  // we correct folding line dimensions:
153 
154  {
155  // update dimension and window position of folding lines at the borders of scrolled rectangle
158 
160  }
161 
162  AW_world rect = { 0, srect.height(), 0, srect.width() };
164 
165  const AW_screen_area& area_size = get_device()->get_area_size();
167 
168  update_window_coords(); // @@@ do at end of this function? (since it uses aww-slider_pos_horizontal,
169  // which might get modified by calculate_scrollbars below);
170 
171  // update window scrollbars
172  set_scrollbar_indents();
174 
175  check_valid_scrollbar_values(); // test that AW_window slider positions and folding line dimensions are in sync
176  }
177 
178  // store synced slider positions in ED4_window
181 }
182 
184  e4_assert(x_link);
185  e4_assert(y_link);
186  e4_assert(width_link);
187  e4_assert(height_link);
188 
189  scrolled_rect.destroy_folding_lines(*this); // first remove existing scrolled rectangle
190 
194  height_link->update_info.linked_to_scrolled_rectangle = 1;
195 
196  scrolled_rect.link(x_link, y_link, width_link, height_link);
197 
198  const AW_screen_area& area_size = get_device()->get_area_size();
199 
201  scrolled_rect.create_folding_lines(*this, rect, area_size.r, area_size.b);
202 
203  scrolled_rect.set_rect(rect);
204 
205  return ED4_R_OK;
206 }
207 
208 static inline void clear_and_update_rectangle(AW_pos x1, AW_pos y1, AW_pos x2, AW_pos y2) {
209  // clears and updates any range of the screen (in win coordinates)
210  // clipping range should be set correctly
211  AW_screen_area rect;
212 
213  rect.t = int(y1);
214  rect.b = int(y2);
215  rect.l = int(x1);
216  rect.r = int(x2);
218 
219 #if defined(DEBUG) && 0
220  static int toggle = 0;
221  current_device()->box(ED4_G_COLOR_2+toggle, true, x1, y1, x2-x1, y2-y1, AW_ALL_DEVICES_SCALED); // fill range with color (for testing)
222  toggle = (toggle+1)&7;
223 #else
224  current_device()->clear_part(x1, y1, x2-x1, y2-y1, AW_ALL_DEVICES);
225 #endif
226 
227  ED4_ROOT->main_manager->Show(true, true); // direct call to Show (critical)
228 }
229 
230 static inline void move_and_update_rectangle(AW_pos x1, AW_pos y1, AW_pos x2, AW_pos y2, int dx, int dy) {
231  // x1/y1=upper-left-corner (win coordinates)
232  // x2/y2=lower-right-corner
233  // dx/dy=movement
234  AW_pos fx = dx<0 ? x1-dx : x1; // move from position ..
235  AW_pos fy = dy<0 ? y1-dy : y1;
236  AW_pos tx = dx>0 ? x1+dx : x1; // ..to position ..
237  AW_pos ty = dy>0 ? y1+dy : y1;
238  int xs = int(x2-x1-abs(dx)); // ..size
239  int ys = int(y2-y1-abs(dy));
240 
241  {
242  AW_screen_area rect;
243  rect.t = int(ty);
244  rect.b = int(ty+ys-1);
245  rect.l = int(tx);
246  rect.r = int(tx+xs-1);
248  }
249 
250  AW_device *device = current_device();
251  device->move_region(fx, fy, xs, ys, tx, ty);
252 
253  if (dy<0) { // scroll to the top
254  device->set_top_font_overlap(true);
255  clear_and_update_rectangle(x1, y2+dy, x2, y2);
256  device->set_top_font_overlap(false);
257  }
258  else if (dy>0) { // scroll to the bottom
259  device->set_bottom_font_overlap(true);
260  clear_and_update_rectangle(x1, y1, x2, y1+dy);
261  device->set_bottom_font_overlap(false);
262  }
263 
264  int char_width = ED4_ROOT->font_group.get_max_width() * 2;
265  if (dx<0) { // scroll left
266  device->set_left_font_overlap(true);
267  clear_and_update_rectangle(x2+dx-char_width, y1, x2, y2);
268  device->set_left_font_overlap(false);
269  }
270  else if (dx>0) { // scroll right
271  device->set_right_font_overlap(true);
272  clear_and_update_rectangle(x1, y1, x1+dx+char_width, y2);
273  device->set_right_font_overlap(false);
274  }
275 }
276 
277 static inline void update_rectangle(AW_pos x1, AW_pos y1, AW_pos x2, AW_pos y2) {
278  // x1/y1=upper-left-corner
279  // x2/y2=lower-right-corner
280  AW_screen_area rect;
281  rect.t = int(y1);
282  rect.b = int(y2);
283  rect.l = int(x1);
284  rect.r = int(x2);
285 
287  clear_and_update_rectangle(x1, y1, x2, y2);
288 }
289 
290 
292  int skip_move;
293 
294  if (!dx && !dy) return ED4_R_OK; // scroll not
295 
297 
298  AW::Position ul = rect.upper_left_corner();
299  AW::Position lr = rect.lower_right_corner();
300 
301  AW_pos left_x = ul.xpos();
302  AW_pos top_y = ul.ypos();
303  AW_pos right_x = lr.xpos();
304  AW_pos bottom_y = lr.ypos();
305 
306  scrolled_rect.scroll(dx, dy);
307 
308  skip_move = (abs(int(dy)) > (bottom_y - top_y - 20)) || (abs(int(dx)) > (right_x - left_x - 20));
309 
310  AW_pos leftmost_x = coords.middle_area_x;
311  AW_pos toptop_y = coords.top_area_y;
312  AW_pos topbottom_y = toptop_y + coords.top_area_height - 1;
313 
315 
316  // main area
317 
318  if (skip_move) update_rectangle(left_x, top_y, right_x, bottom_y); // main area
319  else move_and_update_rectangle(left_x, top_y, right_x, bottom_y, int(dx), int(dy)); // main area
320 
321  // name area (scroll only vertically)
322 
323  if (dy) {
324  if (skip_move) update_rectangle(leftmost_x, top_y, left_x, bottom_y);
325  else move_and_update_rectangle(leftmost_x, top_y, left_x, bottom_y, 0, int(dy));
326  }
327 
328  // top area (scroll only horizontally)
329 
330  if (dx) {
331  if (skip_move) update_rectangle(left_x, toptop_y, right_x, topbottom_y);
332  else move_and_update_rectangle(left_x, toptop_y, right_x, topbottom_y, int(dx), 0);
333  }
334 
336 
337  return ED4_R_OK;
338 }
339 
340 void ED4_window::set_scrollbar_indents() {
341  if (scrolled_rect.exists()) {
345  }
346 }
347 
348 
350  // delete from window list
351  ED4_window *temp, *temp2;
352 
353  if (window == ED4_ROOT->first_window) {
354  temp = ED4_ROOT->first_window; // delete temp afterwards
356  }
357  else {
358  temp = temp2 = ED4_ROOT->first_window;
359 
360  while (temp != window) {
361  temp2 = temp;
362  temp = temp->next;
363  }
364 
365  temp2->next = temp->next;
366  }
367 
368  ED4_ROOT->aw_root->awar(temp->awar_path_for_cursor)->write_int(0); // save in database
373  delete temp;
374 }
375 
376 static void ED4_expose_cb(AW_window *aww) {
377  ED4_LocalWinContext uses(aww);
379 
381 
382  current_device()->reset();
384 }
385 
386 static void ED4_resize_cb(AW_window *aww) {
387  ED4_LocalWinContext uses(aww);
389 
390  current_device()->reset();
392 }
393 
394 
396  ED4_window *last, *temp;
397 
398  temp = ED4_ROOT->first_window; // append at end of window list
399  last = temp;
400  while (temp) {
401  last = temp;
402  temp = temp->next;
403  }
404 
405  temp = new ED4_window (new_aww);
406 
407  if (!ED4_ROOT->first_window) { // this is the first window
408  ED4_ROOT->first_window = temp;
409  }
410  else if (last) {
411  last->next = temp;
412  }
413 
414  // treat devices
415  new_aww->set_expose_callback(AW_MIDDLE_AREA, makeWindowCallback(ED4_expose_cb));
416  new_aww->set_resize_callback(AW_MIDDLE_AREA, makeWindowCallback(ED4_resize_cb));
417  new_aww->set_input_callback (AW_MIDDLE_AREA, makeWindowCallback(ED4_input_cb));
418  new_aww->set_motion_callback(AW_MIDDLE_AREA, makeWindowCallback(ED4_motion_cb));
419 
420  new_aww->set_horizontal_change_callback(makeWindowCallback(ED4_horizontal_change_cb));
421  new_aww->set_vertical_change_callback (makeWindowCallback(ED4_vertical_change_cb));
422 
424 
425  return temp;
426 }
427 
429  : aww(window),
430  next(NULp),
431  slider_pos_horizontal(0),
432  slider_pos_vertical(0),
433  id(++no_of_windows),
434  is_hidden(false),
435  cursor(this)
436 {
437  coords.clear();
438 
441 
444 
447 
448  sprintf(awar_path_for_IUPAC, AWAR_EDIT_IUPAC, id);
450 
453 }
454 
455 
457  delete aww;
458  no_of_windows --;
459 }
460 
#define AWAR_EDIT_BASE_POSITION
Definition: ed4_defs.hxx:100
AW_device * get_device() const
Definition: ed4_class.hxx:766
void set_resize_callback(AW_area area, const WindowCallback &wcb)
Definition: AW_window.cxx:813
AW_device * current_device()
Definition: ed4_class.hxx:1396
const char * id
Definition: AliAdmin.cxx:17
bool exists() const
Definition: ed4_class.hxx:441
void special_window_refresh(bool handle_updates)
Definition: ED4_root.cxx:158
AW_font_group font_group
Definition: ed4_class.hxx:1464
AW_pos size[2]
Definition: ed4_defs.hxx:261
const AW_screen_area & get_area_size() const
Definition: AW_device.cxx:57
static char * y[maxsp+1]
static void ED4_resize_cb(AW_window *aww)
Definition: ED4_window.cxx:386
long window_height
Definition: ed4_defs.hxx:323
ED4_area_manager * top_area_man
Definition: ed4_class.hxx:1429
void ED4_horizontal_change_cb(AW_window *aww)
ED4_scrolled_rectangle scrolled_rect
Definition: ed4_class.hxx:708
void update_window_coords()
Definition: ED4_window.cxx:52
virtual void clear_part(const AW::Rectangle &rect, AW_bitset filteri)
Definition: AW_device.cxx:317
void set_vertical_scrollbar_top_indent(int indent)
Definition: AW_window.cxx:849
#define AWAR_EDIT_SEQ_POSITION
Definition: ed4_defs.hxx:98
long
Definition: AW_awar.cxx:154
ED4_area_manager * middle_area_man
Definition: ed4_class.hxx:1428
#define SLIDER_OFFSET
Definition: ed4_defs.hxx:69
int slider_pos_horizontal
Definition: ed4_class.hxx:706
long top_area_height
Definition: ed4_defs.hxx:323
ED4_root * ED4_ROOT
Definition: ED4_main.cxx:48
char awar_path_for_IUPAC[50]
Definition: ed4_class.hxx:717
ED4_update_info update_info
Definition: ed4_class.hxx:924
ED4_window * get_matching_ed4w(AW_window *aww)
Definition: ED4_window.cxx:107
void update_scrolled_rectangle()
Definition: ED4_window.cxx:144
void _get_area_size(AW_area area, AW_screen_area *square)
Definition: AW_window.cxx:859
double top() const
const AW_bitset AW_ALL_DEVICES
Definition: aw_device.hxx:44
int slider_pos_horizontal
current position of the vertical slider
Definition: aw_window.hxx:339
#define AWAR_EDIT_IUPAC
Definition: ed4_defs.hxx:101
static ED4_window * insert_window(AW_window_menu_modes *new_aww)
Definition: ED4_window.cxx:395
ED4_folding_line * insert_folding_line(AW_pos pos, AW_pos dimension, ED4_properties prop)
Definition: ED4_window.cxx:97
char awar_path_for_basePos[50]
Definition: ed4_class.hxx:716
ED4_coords coords
Definition: ed4_class.hxx:710
#define e4_assert(bed)
Definition: ed4_class.hxx:11
const int WIDTH
void set_motion_callback(AW_area area, const WindowCallback &wcb)
Definition: AW_window.cxx:808
void scroll(int dx, int dy)
Definition: ed4_class.hxx:473
void ED4_motion_cb(AW_window *aww)
bool is_reset() const
Definition: ed4_class.hxx:344
const AW_bitset AW_ALL_DEVICES_SCALED
Definition: aw_device.hxx:45
double AW_pos
Definition: aw_base.hxx:29
void set_bottom_font_overlap(bool allow)
Definition: aw_device.hxx:254
bool is_linked() const
Definition: ed4_class.hxx:442
ED4_window * next
Definition: ed4_class.hxx:705
static void update_rectangle(AW_pos x1, AW_pos y1, AW_pos x2, AW_pos y2)
Definition: ED4_window.cxx:277
ED4_returncode
Definition: ed4_defs.hxx:160
void push_clip_scale()
Definition: AW_device.cxx:91
ED4_folding_line * delete_member(ED4_folding_line *fl)
Definition: ed4_class.hxx:294
#define AWAR_EDIT_HELIXNR
Definition: ed4_defs.hxx:102
long window_upper_clip_point
Definition: ed4_defs.hxx:323
const double & ypos() const
long window_lower_clip_point
Definition: ed4_defs.hxx:323
void link(ED4_base *x, ED4_base *y, ED4_base *w, ED4_base *h)
Definition: ed4_class.hxx:454
GBDATA * get_gb_main() const
Definition: ed4_class.hxx:1420
void check_valid_scrollbar_values()
Definition: ed4_class.hxx:758
void ED4_input_cb(AW_window *aww)
void calculate_scrollbars()
Definition: AW_window.cxx:870
static void move_and_update_rectangle(AW_pos x1, AW_pos y1, AW_pos x2, AW_pos y2, int dx, int dy)
Definition: ED4_window.cxx:230
long top_area_y
Definition: ed4_defs.hxx:323
#define false
Definition: ureadseq.h:13
void set_expose_callback(AW_area area, const WindowCallback &wcb)
Definition: AW_window.cxx:762
void pop_clip_scale()
Definition: AW_device.cxx:62
ED4_window * first_window
Definition: ed4_class.hxx:1426
void calc_bottomRight_folding_dimensions(int area_width, int area_height)
Definition: ed4_class.hxx:494
static void clear_and_update_rectangle(AW_pos x1, AW_pos y1, AW_pos x2, AW_pos y2)
Definition: ED4_window.cxx:208
void reset(ED4_foldable &owner)
Definition: ed4_class.hxx:433
ED4_window(AW_window_menu_modes *window)
Definition: ED4_window.cxx:428
int get_max_width() const
const Position & upper_left_corner() const
void reset_all_for_new_config()
Definition: ED4_window.cxx:20
char awar_path_for_cursor[50]
Definition: ed4_class.hxx:714
void destroy_folding_lines(ED4_foldable &owner)
Definition: ed4_class.hxx:543
ED4_main_manager * main_manager
Definition: ed4_class.hxx:1427
void calc_world_coords(AW_pos *x, AW_pos *y) const
Definition: ed4_class.hxx:982
AW_awar * awar(const char *awar)
Definition: AW_root.cxx:554
static void ED4_expose_cb(AW_window *aww)
Definition: ED4_window.cxx:376
void delete_window(ED4_window *window)
Definition: ED4_window.cxx:349
ED4_scroll_links scroll_links
Definition: ed4_class.hxx:1432
void set_top_font_overlap(bool allow)
Definition: aw_device.hxx:253
ED4_extension extension
Definition: ed4_class.hxx:923
void set_horizontal_scrollbar_left_indent(int indent)
Definition: AW_window.cxx:854
void ED4_vertical_change_cb(AW_window *aww)
AW::Rectangle get_world_rect() const
Definition: ED4_window.cxx:131
void tell_scrolled_picture_size(AW_screen_area rectangle)
Definition: AW_window.cxx:820
long middle_area_y
Definition: ed4_defs.hxx:323
double left() const
AW::Rectangle get_window_rect() const
Definition: ed4_class.hxx:480
AW_awar * awar_int(const char *var_name, long default_value=0, AW_default default_file=AW_ROOT_DEFAULT)
Definition: AW_root.cxx:580
#define ED4_IUPAC_EMPTY
Definition: ed4_tools.hxx:14
#define AWAR_EDIT_ECOLI_POSITION
Definition: ed4_defs.hxx:99
long window_width
Definition: ed4_defs.hxx:323
char awar_path_for_Ecoli[50]
Definition: ed4_class.hxx:715
void create_folding_lines(ED4_foldable &owner, const AW::Rectangle &rect, int area_width, int area_height)
Definition: ed4_class.hxx:530
char awar_path_for_helixNr[50]
Definition: ed4_class.hxx:718
void set_right_font_overlap(bool allow)
Definition: aw_device.hxx:256
void insertAs(ED4_folding_line *&ptr)
Definition: ed4_class.hxx:288
ED4_window * current_ed4w()
Definition: ed4_class.hxx:1397
AW_root * aw_root
Definition: ed4_class.hxx:1423
void reset()
Definition: AW_device.cxx:280
int slider_pos_vertical
Definition: ed4_class.hxx:707
long middle_area_x
Definition: ed4_defs.hxx:323
#define abs(x)
Definition: f2c.h:151
ED4_properties
Definition: ed4_defs.hxx:175
void add_to_top_left_dimension(int dx, int dy)
Definition: ed4_class.hxx:468
long window_right_clip_point
Definition: ed4_defs.hxx:323
ED4_returncode set_scrolled_rectangle(ED4_base *x_link, ED4_base *y_link, ED4_base *width_link, ED4_base *height_link)
Definition: ED4_window.cxx:183
ED4_returncode scroll_rectangle(int dx, int dy)
Definition: ED4_window.cxx:291
const double & xpos() const
#define NULp
Definition: cxxforward.h:97
long top_area_x
Definition: ed4_defs.hxx:323
void clear()
Definition: ed4_defs.hxx:338
GB_ERROR write_string(const char *aw_string)
void ED4_set_clipping_rectangle(AW_screen_area *rect)
Definition: ED4_tools.cxx:14
virtual void move_region(AW_pos src_x, AW_pos src_y, AW_pos width, AW_pos height, AW_pos dest_x, AW_pos dest_y)
Definition: AW_device.cxx:263
static int no_of_windows
Definition: ed4_class.hxx:712
void delete_folding_line(ED4_folding_line *fl, ED4_properties prop)
Definition: ED4_window.cxx:121
Position lower_right_corner() const
AW_window_menu_modes * aww
Definition: ed4_class.hxx:704
GB_transaction ta(gb_var)
void set_horizontal_change_callback(const WindowCallback &wcb)
Definition: AW_window.cxx:1046
bool box(int gc, AW::FillStyle filled, const AW::Rectangle &rect, AW_bitset filteri=AW_ALL_DEVICES_SCALED)
Definition: aw_device.hxx:471
void set_vertical_change_callback(const WindowCallback &wcb)
Definition: AW_window.cxx:1030
long window_left_clip_point
Definition: ed4_defs.hxx:323
AW_awar * awar_string(const char *var_name, const char *default_value="", AW_default default_file=AW_ROOT_DEFAULT)
Definition: AW_root.cxx:570
void set_left_font_overlap(bool allow)
Definition: aw_device.hxx:255
void set_rect(const AW::Rectangle &rect)
Definition: ed4_class.hxx:488
int slider_pos_vertical
window id
Definition: aw_window.hxx:338
#define HEIGHT
Definition: ed4_defs.hxx:75
void set_rect_and_update_folding_line_positions(const AW::Rectangle &rect)
Definition: ed4_class.hxx:489
#define AW_ROOT_DEFAULT
Definition: aw_base.hxx:106
void set_input_callback(AW_area area, const WindowCallback &wcb)
Definition: AW_window.cxx:803
GB_ERROR write_int(long aw_int)
unsigned int linked_to_scrolled_rectangle
Definition: ed4_defs.hxx:301