root/trunk/EDIT4/ed4_class.hxx

Revision 8631, 91.9 KB (checked in by westram, 5 weeks ago)

merge from e4fix [8443] [8444] [8445] [8604]

  • new EDIY4-keys
    • fold/unfold group using ENTER key
    • ALT+up/down jumps between group consensi
    • Ctrl-M marks/unmarks current species or group
  • minor help-fixes
  • removed "[Ctrl-A]" from aligner menu entry (they do different things)
  • use ED4_terminal for owner_of_cursor and ED4_base_position
  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
Line 
1#ifndef ED4_CLASS_HXX
2#define ED4_CLASS_HXX
3
4#ifndef AW_FONT_GROUP_HXX
5#include <aw_font_group.hxx>
6#endif
7#ifndef POS_RANGE_H
8#include <pos_range.h>
9#endif
10
11#define e4_assert(bed) arb_assert(bed)
12
13#define concat(a,b) a##b
14
15#ifdef DEBUG
16# define IMPLEMENT_DUMP         // comment out this line to skip compilation of the dump() methods
17#endif
18
19#ifndef ARB_ERROR_H
20#include <arb_error.h>
21#endif
22#ifndef ED4_DEFS_HXX
23#include "ed4_defs.hxx"
24#endif
25#ifndef ED4_SEARCH_HXX
26#include "ed4_search.hxx"
27#endif
28#ifndef _GLIBCXX_SET
29#include <set>
30#endif
31#ifndef ATTRIBUTES_H
32#include <attributes.h>
33#endif
34#ifndef BI_BASEPOS_HXX
35#include <BI_basepos.hxx>
36#endif
37#ifndef DOWNCAST_H
38#include <downcast.h>
39#endif
40
41#if defined(IMPLEMENT_DUMP) // ------------------------------
42
43#if 0
44#define WARN(msg) void dummy_to_produce_a_warning(int msg) {}
45#else
46#define WARN(msg)
47#endif
48
49#define EMPTY_FUNCTION(name)         void name() const {}
50#define EMPTY_FUNCTION_VERBOSE(name) void name(int je_mappelle_##name) const {}
51
52#define DERIVABLEFROM(base) concat(prohibited_leafclass_derivation,base)
53
54#define COMMON_FOR_BASES()                      \
55    virtual void dump(size_t indent) const = 0; \
56
57#define COMMON_FOR_DERIVABLE(self)               \
58    void dump_base(size_t indent) const;         \
59    EMPTY_FUNCTION(DERIVABLEFROM(self));         \
60       
61#define COMMON_FOR_DERIVED(mybase)                                              \
62    void dump_my_base(size_t indent) const { mybase::dump_base(indent); }       \
63    virtual const char *baseclassname() const { return #mybase; }               \
64   
65#define COMMON_FOR_INSTANCIABLE(mybase)         \
66    virtual void dump(size_t indent) const;     \
67
68#define DECLARE_DUMP_FOR_ROOTCLASS(self)        \
69    COMMON_FOR_BASES();                         \
70    COMMON_FOR_DERIVABLE(self);                 \
71
72#define DECLARE_DUMP_FOR_BASECLASS(self,mybase) \
73    COMMON_FOR_BASES();                         \
74    COMMON_FOR_DERIVABLE(self);                 \
75    COMMON_FOR_DERIVED(mybase);                 \
76
77#define DECLARE_DUMP_FOR_MIDCLASS(self,mybase)  \
78    WARN(midclass_is_unwanted);                 \
79    COMMON_FOR_DERIVABLE(self);                 \
80    COMMON_FOR_DERIVED(mybase);                 \
81    COMMON_FOR_INSTANCIABLE(mybase);            \
82   
83#define DECLARE_DUMP_FOR_LEAFCLASS(mybase)              \
84    virtual void leaf() { DERIVABLEFROM(mybase)(); }    \
85    COMMON_FOR_DERIVED(mybase);                         \
86    COMMON_FOR_INSTANCIABLE(mybase);                    \
87
88#else
89#define DECLARE_DUMP_FOR_ROOTCLASS(self)
90#define DECLARE_DUMP_FOR_BASECLASS(self,mybase)
91#define DECLARE_DUMP_FOR_MIDCLASS(self,mybase)
92#define DECLARE_DUMP_FOR_LEAFCLASS(mybase)
93
94#endif // IMPLEMENT_DUMP ------------------------------
95
96
97
98// #define LIMIT_TOP_AREA_SPACE // if defined, top area is size-limited
99#ifdef LIMIT_TOP_AREA_SPACE
100#define MAX_TOP_AREA_SIZE 10    // size limit for top-area
101#endif
102
103#define ed4_beep() do { fputc(char(7), stdout); fflush(stdout); } while (0)
104
105enum PositionType {
106    ED4_POS_SEQUENCE, 
107    ED4_POS_ECOLI, 
108    ED4_POS_BASE, 
109};
110   
111// ****************************************
112// needed prototypes, definitions below
113// ****************************************
114
115class ED4_Edit_String;
116class ED4_area_manager;
117class ED4_abstract_group_manager;
118class ED4_base;
119class ED4_bases_table;
120class ED4_bracket_terminal;
121class ED4_char_table;
122class ED4_columnStat_terminal;
123class ED4_consensus_sequence_terminal;
124class ED4_cursor;
125class ED4_device_manager;
126class ED4_folding_line;
127class ED4_group_manager;
128class ED4_line_terminal;
129class ED4_main_manager;
130class ED4_manager;
131class ED4_members;
132class ED4_multi_name_manager;
133class ED4_multi_sequence_manager;
134class ED4_multi_species_manager;
135class ED4_name_manager;
136class ED4_pure_text_terminal;
137class ED4_remap;
138class ED4_root;
139class ED4_root_group_manager;
140class ED4_sequence_info_terminal;
141class ED4_sequence_manager;
142class ED4_sequence_terminal;
143class ED4_orf_terminal;
144class ED4_spacer_terminal;
145class ED4_species_manager;
146class ED4_species_name_terminal;
147class ED4_species_pointer;
148class ED4_terminal;
149class ED4_text_terminal;
150class ED4_tree_terminal;
151class ED4_window;
152
153class AP_tree;
154class AWT_reference;
155class AWT_seq_colors;
156class BI_ecoli_ref;
157class AW_helix;
158class arb_progress;
159class ST_ML;
160class ed_key;
161
162template <class T> class ED4_list;      // derived from Noncopyable
163template <class T> class ED4_list_elem; // derived from Noncopyable
164
165typedef ED4_list<ED4_base>      ED4_base_list;
166typedef ED4_list_elem<ED4_base> ED4_base_list_elem;
167
168typedef ED4_list<ED4_selection_entry>      ED4_selected_list;
169typedef ED4_list_elem<ED4_selection_entry> ED4_selected_elem;
170
171
172struct EDB_root_bact {
173    char *make_string();
174    char *make_top_bot_string();
175
176    void calc_no_of_all(char *string_to_scan,       // group gets the number of groups in string_to_scan,
177                        long *group,                // species gets the number of species in string_to_scan
178                        long *species);
179
180    ED4_returncode fill_species(ED4_multi_species_manager  *multi_species_manager,
181                                ED4_sequence_info_terminal *ref_sequence_info_terminal,
182                                ED4_sequence_terminal      *ref_sequence_terminal,
183                                char                       *string,
184                                int                        *index,
185                                ED4_index                  *y,
186                                ED4_index                   curr_local_position,
187                                ED4_index                  *length_of_terminals,
188                                int                         group_depth,
189                                arb_progress               *progress);
190
191    ED4_returncode fill_data(ED4_multi_species_manager  *multi_species_manager,
192                             ED4_sequence_info_terminal *ref_sequence_info_terminal,
193                             ED4_sequence_terminal      *ref_sequence_terminal,
194                             char                       *string,
195                             ED4_index                  *y,
196                             ED4_index                   curr_local_position,
197                             ED4_index                  *length_of_terminals,
198                             int                         group_depth,
199                             ED4_datamode                datamode); // flag only needed for loading a new configuration
200
201    ED4_returncode search_sequence_data_rek(ED4_multi_sequence_manager *multi_sequence_manager,
202                                            ED4_sequence_info_terminal *ref_sequence_info_terminal,
203                                            ED4_sequence_terminal      *ref_sequence_terminal,
204                                            GBDATA                     *gb_datamode,
205                                            int                         count_too,
206                                            ED4_index                  *seq_coords,
207                                            ED4_index                  *max_seq_terminal_length,
208                                            ED4_alignment               alignment_flag,
209                                            bool                        isSAI);
210
211    ED4_index scan_string(ED4_multi_species_manager  *parent,
212                          ED4_sequence_info_terminal *ref_sequence_info_terminal,
213                          ED4_sequence_terminal      *ref_sequence_terminal,
214                          char                       *string,
215                          int                        *index,
216                          ED4_index                  *y,
217                          arb_progress&               progress);
218
219    ED4_returncode create_group_header(ED4_multi_species_manager   *parent,
220                                       ED4_sequence_info_terminal  *ref_sequence_info_terminal,
221                                       ED4_sequence_terminal       *ref_sequence_terminal,
222                                       ED4_multi_species_manager  **multi_species_manager,
223                                       ED4_bracket_terminal       **bracket_terminal,
224                                       ED4_index                   *y,
225                                       char                        *groupname,
226                                       int                          group_depth,
227                                       bool                         is_folded,
228                                       ED4_index                    local_count_position);
229
230    char *generate_config_string(char *confname);
231
232
233    EDB_root_bact() {}
234};
235
236#define SPECIFIED_OBJECT_TYPES 21
237
238class ED4_objspec : public Noncopyable {
239    static bool object_specs_initialized;
240    static bool descendants_uptodate;
241
242    mutable ED4_level used_children;         // in any object of this type
243    mutable ED4_level possible_descendants;  // below any object of this type (depends on used_children)
244    mutable ED4_level allowed_descendants;   // below any object of this type (depends on allowed_children)
245
246    void calc_descendants() const;
247
248public:
249    ED4_properties static_prop;
250    ED4_level      level;
251    ED4_level      allowed_children;
252    ED4_level      handled_level;
253    ED4_level      restriction_level;
254
255    ED4_objspec(ED4_properties static_prop_, ED4_level level_, ED4_level allowed_children_, ED4_level handled_level_, ED4_level restriction_level_);
256
257#if defined(IMPLEMENT_DUMP)
258    void dump(size_t indent) const;
259#endif // IMPLEMENT_DUMP
260
261    static void init_object_specs();
262
263    bool is_manager() const { return static_prop & ED4_P_IS_MANAGER; }
264    bool is_terminal() const { return static_prop & ED4_P_IS_TERMINAL; }
265
266    bool allowed_to_contain(ED4_level child_level) const {
267        // e4_assert(object_specs_initialized); // @@@ cant check here.. but where
268        e4_assert(is_manager()); // terminals can't contain anything - your test is senseless
269        return allowed_children & child_level;
270    }
271
272    void announce_added(ED4_level child_level) const {
273        e4_assert(allowed_to_contain(child_level));
274        used_children          = ED4_level(used_children|child_level);
275        descendants_uptodate = false;
276    }
277
278    static void recalc_descendants();
279
280    ED4_level get_possible_descendants() const { 
281        e4_assert(is_manager());
282        if (!descendants_uptodate) recalc_descendants();
283        return possible_descendants;
284    }
285    ED4_level get_allowed_descendants() const { // (allowed = possible + those allowed to add, but not added anywhere)
286        e4_assert(is_manager());
287        if (!descendants_uptodate) recalc_descendants();
288        return allowed_descendants;
289    }
290};
291
292class ED4_folding_line : virtual Noncopyable {
293    AW_pos            dimension; // amount of pixel folded away
294    AW_pos            pos;       // window position of folding line (x or y, only owner knows which coordinate is folded)
295    ED4_folding_line *next;
296
297    ED4_folding_line *insert(ED4_folding_line *fl) {
298        e4_assert(!fl->next);
299        if (pos <= fl->pos) { // insert behind
300            next = next ? next->insert(fl) : fl;
301            return this;
302        }
303
304        fl->next = this;
305        return fl;
306    }
307
308public:
309
310    ED4_folding_line(AW_pos world, AW_pos dim) : dimension(dim), next(0) { set_pos(world-dimension); }
311
312    ~ED4_folding_line() { delete next; }
313
314    void insertAs(ED4_folding_line*& ptr) {
315        ED4_folding_line *other = ptr;
316        e4_assert(this);
317        ptr = other ? other->insert(this) : this;
318    }
319
320    ED4_folding_line *delete_member(ED4_folding_line *fl) {
321        ED4_folding_line *result = this;
322        if (this == fl) {
323            result = next;
324            next   = NULL;
325            delete this;
326        }
327        return result;
328    }
329
330    AW_pos get_dimension() const { return dimension; }
331    const ED4_folding_line *get_next() const { return next; }
332
333    void warn_illegal_dimension();
334
335    void set_dimension(AW_pos dim) { dimension = dim; warn_illegal_dimension(); }
336    void add_to_dimension(AW_pos offset) { dimension += offset; warn_illegal_dimension(); }
337
338    void set_pos(AW_pos p) { pos = p; }
339    AW_pos get_pos() const { return pos; }
340
341    AW_pos win2world(AW_pos win) const {
342        if (win<pos) return win;
343        return (next ? next->win2world(win) : win)+dimension;
344    }
345    AW_pos world2win(AW_pos world) const {
346        if (world<pos) return world;
347        world -= dimension;
348        if (!next) return world;
349        return next->world2win(world);
350    }
351};
352
353struct ED4_scroll_links {
354    ED4_base *link_for_hor_slider;
355    ED4_base *link_for_ver_slider;
356
357    ED4_scroll_links() : link_for_hor_slider(0), link_for_ver_slider(0) {}
358};
359
360class ED4_foldable : virtual Noncopyable {
361    ED4_folding_line *horizontal_fl;
362    ED4_folding_line *vertical_fl;
363protected:
364    void reset() {
365        delete horizontal_fl;
366        delete vertical_fl;
367        horizontal_fl = NULL;
368        vertical_fl   = NULL;
369    }
370    bool is_reset() const { return !horizontal_fl && !vertical_fl; }
371public:
372
373    ED4_foldable() : horizontal_fl(NULL), vertical_fl(NULL) {}
374    ~ED4_foldable() { reset(); }
375
376    const ED4_folding_line *get_horizontal_folding() { return horizontal_fl; }
377    const ED4_folding_line *get_vertical_folding() { return vertical_fl; }
378
379    void world_to_win_coords(AW_pos *xPtr, AW_pos *yPtr) const { // @@@ old style
380        // Calculates transformation from world to window coordinates in a given window.
381        // world-coordinates inside folded range result in window coordinates lower than folding line position.
382        e4_assert(!is_reset());
383        *xPtr = vertical_fl->world2win(*xPtr);
384        *yPtr = horizontal_fl->world2win(*yPtr);
385    }
386    void win_to_world_coords(AW_pos *xPtr, AW_pos *yPtr) const { // @@@ old style
387        // calculates transformation from window to world coordinates in a given window
388        e4_assert(!is_reset());
389        *xPtr = vertical_fl->win2world(*xPtr);
390        *yPtr = horizontal_fl->win2world(*yPtr);
391    }
392
393    AW::Position world_to_win_coords(const AW::Position& pos) const {
394        e4_assert(!is_reset());
395        return AW::Position(vertical_fl->world2win(pos.xpos()),
396                            horizontal_fl->world2win(pos.ypos()));
397    }
398    AW::Position win_to_world_coords(const AW::Position& pos) const {
399        e4_assert(!is_reset());
400        return AW::Position(vertical_fl->win2world(pos.xpos()),
401                            horizontal_fl->win2world(pos.ypos()));
402    }
403
404    ED4_folding_line *insert_folding_line(AW_pos pos, AW_pos dimension, ED4_properties prop);
405    void              delete_folding_line(ED4_folding_line *fl, ED4_properties prop);
406};
407
408
409class ED4_scrolled_rectangle : virtual Noncopyable {
410    ED4_folding_line *scroll_bottom;
411    ED4_folding_line *scroll_right;
412    ED4_folding_line *scroll_top;
413    ED4_folding_line *scroll_left;
414
415    ED4_base *x_link;
416    ED4_base *y_link;
417    ED4_base *width_link;
418    ED4_base *height_link;
419
420    AW::Rectangle world;
421
422    bool folding_dimensions_calculated; // flag to ensure calc_bottomRight_folding_dimensions is called before get_window_rect
423   
424    void init_links() {
425        x_link      = 0;
426        y_link      = 0;
427        width_link  = 0;
428        height_link = 0;
429    }
430
431    void init_folding_lines() {
432        scroll_top    = 0;
433        scroll_bottom = 0;
434        scroll_left   = 0;
435        scroll_right  = 0;
436
437        folding_dimensions_calculated = false;
438    }
439    void init_pos_size() { world = AW::Rectangle(AW::Origin, AW::ZeroVector); }
440
441    void init() {
442        init_folding_lines();
443        init_pos_size();
444        init_links();
445    }
446
447    void update_folding_line_positions() {
448        scroll_top->set_pos(world.top());
449        scroll_left->set_pos(world.left());
450    }
451
452public:
453
454    ED4_scrolled_rectangle() { init(); }
455
456    AW_pos bottom() const { return world.bottom(); }
457    AW_pos right() const { return world.right(); }
458
459    void reset(ED4_foldable& owner) {
460        destroy_folding_lines(owner);
461        init_pos_size();
462    }
463
464    AW_pos top_dim() const { return scroll_top->get_dimension(); }
465    AW_pos left_dim() const { return scroll_left->get_dimension(); }
466
467    bool exists() const { return scroll_top && scroll_bottom && scroll_left && scroll_right; }
468    bool is_linked() const {
469        if (x_link) {
470            e4_assert(y_link);
471            e4_assert(width_link);
472            e4_assert(height_link);
473            return true;
474        }
475        e4_assert(!y_link);
476        e4_assert(!width_link);
477        e4_assert(!height_link);
478        return false;
479    }
480    void link(ED4_base *x, ED4_base *y, ED4_base *w, ED4_base *h) {
481        e4_assert(x && y && w && h);
482
483        x_link      = x;
484        y_link      = y;
485        width_link  = w;
486        height_link = h;
487    }
488
489    void replace_x_width_link_to(ED4_base *old_link, ED4_base *new_link) {
490        if (x_link == old_link)     x_link     = new_link;
491        if (width_link == old_link) width_link = new_link;
492    }
493
494    void add_to_top_left_dimension(int dx, int dy) {
495        scroll_left->add_to_dimension(dx);
496        scroll_top->add_to_dimension(dy);
497    }
498
499    void scroll(int dx, int dy) {
500        scroll_left->add_to_dimension(-dx);
501        scroll_top->add_to_dimension(-dy);
502        scroll_right->add_to_dimension(dx);
503        scroll_bottom->add_to_dimension(dy);
504    }
505
506    AW::Rectangle get_window_rect() const {
507        e4_assert(folding_dimensions_calculated);
508        return AW::Rectangle(scroll_left->get_pos(), scroll_top->get_pos(),
509                             scroll_right->get_pos(), scroll_bottom->get_pos());
510    }
511
512    AW::Rectangle get_world_rect() const;
513
514    void set_rect(const AW::Rectangle& rect) { world = rect; }
515    void set_rect_and_update_folding_line_positions(const AW::Rectangle& rect) {
516        set_rect(rect);
517        update_folding_line_positions();
518    }
519
520    void calc_bottomRight_folding_dimensions(int area_width, int area_height) {
521        area_width  -= SLIDER_OFFSET;
522        area_height -= SLIDER_OFFSET;
523
524        AW_pos dim;
525        if (bottom() > area_height) {   // our world doesn't fit vertically in our window
526            dim = bottom()-area_height; // calc dimension of both horizontal folding lines
527            scroll_top->set_dimension(min(dim, scroll_top->get_dimension()));
528            scroll_bottom->set_dimension(max(0, int(dim - scroll_top->get_dimension())));
529        }
530        else {
531            dim = 0;
532            scroll_bottom->set_dimension(0);
533            scroll_top->set_dimension(0);
534        }
535
536        e4_assert(dim == (scroll_top->get_dimension()+scroll_bottom->get_dimension()));
537        scroll_bottom->set_pos(world.bottom()-dim+SLIDER_OFFSET);
538
539        if (right()>area_width) {     // our world doesn't fit horizontally in our window
540            dim = right()-area_width; // calc dimension of both vertical folding lines
541            scroll_left->set_dimension(min(dim, scroll_left->get_dimension()));
542            scroll_right->set_dimension(max(0, int(dim - scroll_left->get_dimension())));
543        }
544        else {
545            dim = 0;
546            scroll_right->set_dimension(0);
547            scroll_left->set_dimension(0);
548        }
549
550        e4_assert(dim == (scroll_left->get_dimension()+scroll_right->get_dimension()));
551        scroll_right->set_pos(world.right()-dim+SLIDER_OFFSET);
552
553        folding_dimensions_calculated = true;
554    }
555
556    void create_folding_lines(ED4_foldable& owner, const AW::Rectangle& rect, int area_width, int area_height) {
557        scroll_top  = owner.insert_folding_line(rect.top(), 0, ED4_P_HORIZONTAL);
558        scroll_left = owner.insert_folding_line(rect.left(), 0, ED4_P_VERTICAL);
559
560        AW_pos dim = 0;
561        if (rect.bottom() > area_height) dim = rect.bottom() - area_height;
562        scroll_bottom = owner.insert_folding_line(rect.bottom(), dim, ED4_P_HORIZONTAL);
563
564        dim = 0;
565        if (rect.right() > area_width) dim = rect.right() - area_width;
566        scroll_right = owner.insert_folding_line(rect.right(), dim, ED4_P_VERTICAL);
567    }
568
569    void destroy_folding_lines(ED4_foldable& owner) {
570        if (scroll_top)    owner.delete_folding_line(scroll_top,    ED4_P_HORIZONTAL);
571        if (scroll_bottom) owner.delete_folding_line(scroll_bottom, ED4_P_HORIZONTAL);
572        if (scroll_left)   owner.delete_folding_line(scroll_left,   ED4_P_VERTICAL);
573        if (scroll_right)  owner.delete_folding_line(scroll_right,  ED4_P_VERTICAL);
574
575        init_folding_lines();
576    }
577};
578
579class ED4_base_position : private BasePosition { // derived from a Noncopyable
580    const ED4_terminal *calced4term;
581
582    void calc4term(const ED4_terminal *term);
583    void set_term(const ED4_terminal *term) { if (calced4term != term) calc4term(term); }
584
585public:
586
587    ED4_base_position();
588    ~ED4_base_position();
589
590    void invalidate();
591
592    void announce_deletion(const ED4_terminal *term) {
593        if (term == calced4term) invalidate();
594        e4_assert(calced4term != term);
595    }
596
597    int get_base_position(const ED4_terminal *base, int sequence_position);
598    int get_sequence_position(const ED4_terminal *base, int base_position);
599
600    int get_base_count(const ED4_terminal *term) { set_term(term); return base_count(); }
601    int get_abs_len(const ED4_terminal *term) { set_term(term); return abs_count(); }
602};
603
604class ED4_CursorShape;
605
606
607enum ED4_CursorType {
608    ED4_RIGHT_ORIENTED_CURSOR,
609    ED4_RIGHT_ORIENTED_CURSOR_THIN,
610    ED4_TRADITIONAL_CURSOR,
611    ED4_TRADITIONAL_CURSOR_BOTTOM,
612    ED4_TRADITIONAL_CURSOR_CONNECTED,
613    ED4_FUCKING_BIG_CURSOR,
614
615    ED4_CURSOR_TYPES
616
617};
618
619extern bool ED4_update_global_cursor_awars_allowed; // update selected species/SAI/cursor position
620
621struct ED4_TerminalPredicate {
622    virtual ~ED4_TerminalPredicate() {}
623    virtual bool fulfilled_by(const ED4_terminal *) const = 0;
624};
625
626class ED4_WinContextFree { // denies usage of the following functions in classes derived from this
627    AW_device   *current_device();
628    ED4_window  *current_ed4w();
629    AW_window   *current_aww();
630    ED4_cursor&  current_cursor();
631public:
632    void avoid_warning() {}
633};
634
635class ED4_cursor : virtual Noncopyable, virtual ED4_WinContextFree {
636    ED4_window                *win;
637    ED4_index                  cursor_abs_x;    // absolute (to terminal) x-position of cursor (absolute world coordinate of edit window)
638    int                        screen_position; // number of displayed characters leading the cursor
639    mutable ED4_base_position  base_position;   // # of bases left of cursor
640    ED4_CursorType             ctype;
641    ED4_CursorShape           *cursor_shape;
642
643    ED4_returncode  draw_cursor(AW_pos x, AW_pos y);
644    ED4_returncode  delete_cursor(AW_pos del_mark,  ED4_base *target_terminal);
645
646    void updateAwars(bool new_term_selected);
647
648public:
649
650    bool          allowed_to_draw; // needed for cursor handling
651    ED4_terminal *owner_of_cursor;
652
653    bool is_partly_visible() const;
654    bool is_completely_visible() const;
655
656    bool is_hidden_inside_group() const;
657
658    void changeType(ED4_CursorType typ);
659    ED4_CursorType  getType() const { return ctype; }
660
661    void redraw() { changeType(getType()); }
662
663    ED4_returncode HideCursor(); // deletes cursor and does refresh
664    ED4_returncode move_cursor(AW_event *event);
665    ED4_returncode show_clicked_cursor(AW_pos click_xpos, ED4_terminal *target_terminal);
666    ED4_returncode show_cursor_at(ED4_terminal *target_terminal, ED4_index what_pos);
667    ED4_returncode ShowCursor(ED4_index offset_x, ED4_cursor_move move, int move_pos = 1);
668
669    int get_sequence_pos() const;
670    int get_screen_pos() const { return screen_position; }
671
672    long get_abs_x() const   { return cursor_abs_x; }
673    void set_abs_x();
674
675    int base2sequence_position(int base_pos) const { return base_position.get_sequence_position(owner_of_cursor, base_pos); }
676    int sequence2base_position(int seq_pos) const { return base_position.get_base_position(owner_of_cursor, seq_pos); }
677
678    int get_base_position() const { return sequence2base_position(get_sequence_pos()); }
679
680    void invalidate_base_position() { base_position.invalidate(); }
681
682    void jump_screen_pos(int screen_pos, ED4_CursorJumpType jump_type);
683    void jump_sequence_pos(int sequence_pos, ED4_CursorJumpType jump_type);
684    void jump_base_pos(int base_pos, ED4_CursorJumpType jump_type);
685
686    int get_screen_relative_pos() const;
687    void set_screen_relative_pos(int scroll_to_relpos);
688
689    void set_to_terminal(ED4_terminal *terminal, int seq_pos, ED4_CursorJumpType jump_type);
690
691    inline bool in_species_seq_terminal() const;
692    inline bool in_consensus_terminal() const;
693    inline bool in_SAI_terminal() const;
694   
695    void announce_deletion(ED4_terminal *object) {
696        base_position.announce_deletion(object);
697        if (object == owner_of_cursor) owner_of_cursor = NULL; // no need to delete the cursor (deletion triggers full redraw)
698    }
699
700    void init();
701
702    ED4_window *window() const { return win; }
703
704    ED4_cursor(ED4_window *win);
705    ~ED4_cursor();
706};
707
708class ED4_window : public ED4_foldable, virtual ED4_WinContextFree { // derived from Noncopyable
709    void set_scrollbar_indents();
710
711public:
712    AW_window              *aww;   // Points to Window
713    ED4_window             *next;
714    int                     slider_pos_horizontal;
715    int                     slider_pos_vertical;
716    ED4_scrolled_rectangle  scrolled_rect;
717    int                     id;    // unique id in window-list
718    ED4_coords              coords;
719
720    static int no_of_windows;
721
722    char awar_path_for_cursor[50];                  // position in current sequence, range = [1;len]
723    char awar_path_for_Ecoli[50];                   // position relative to ecoli
724    char awar_path_for_basePos[50];                 // base position in current sequence (# of bases left to cursor)
725    char awar_path_for_IUPAC[50];                   // IUPAC decoder content for current position
726    char awar_path_for_helixNr[50];                 // # of helix (or 0) for current position
727
728    bool       is_hidden;
729    ED4_cursor cursor;
730
731    // ED4_window controlling functions
732    static ED4_window *insert_window(AW_window *new_aww); // append to window list
733
734    void        delete_window(ED4_window *window);  // delete from window list
735    void        reset_all_for_new_config(); // reset structures for loading new config
736    ED4_window *get_matching_ed4w(AW_window *aww);
737
738    void announce_deletion(ED4_terminal *object) { cursor.announce_deletion(object); }
739   
740    // functions concerned the scrolled area
741    void update_scrolled_rectangle();
742    ED4_returncode scroll_rectangle(int dx, int dy);
743    ED4_returncode set_scrolled_rectangle(ED4_base *x_link, ED4_base *y_link, ED4_base *width_link, ED4_base *height_link);
744
745    bool scrollbars_and_scrolledRect_inSync() const {
746        // Scrolling in EDIT4 window uses redundant data
747        // - dimension of folding lines
748        // - slider positions in AW_window and ED4_window
749        // This function checks whether they are in sync.
750       
751        bool inSync                    = 
752            (scrolled_rect.top_dim()  == aww->slider_pos_vertical) &&
753            (scrolled_rect.left_dim() == aww->slider_pos_horizontal);
754
755#if defined(DEBUG)
756        if (!inSync) {
757            fputs("scrollbars not in sync with scrolled_rect:\n", stderr);
758            fprintf(stderr, "    aww->slider_pos_vertical  =%i scrolled_rect->top_dim() =%f\n", aww->slider_pos_vertical, scrolled_rect.top_dim());
759            fprintf(stderr, "    aww->slider_pos_horizontal=%i scrolled_rect->left_dim()=%f\n", aww->slider_pos_horizontal, scrolled_rect.left_dim());
760        }
761#endif
762
763        return inSync;
764    }
765
766    void check_valid_scrollbar_values() { e4_assert(scrollbars_and_scrolledRect_inSync()); }
767
768    bool shows_xpos(int x) const { return x >= coords.window_left_clip_point && x <= coords.window_right_clip_point; }
769    bool partly_shows(int x1, int y1, int x2, int y2) const;
770    bool completely_shows(int x1, int y1, int x2, int y2) const;
771   
772    void update_window_coords();
773
774    AW_device *get_device() const { return aww->get_device(AW_MIDDLE_AREA); }
775
776    ED4_window(AW_window *window);
777    ~ED4_window();
778};
779
780class ED4_members : virtual Noncopyable {
781    // contains children related functions from members of a manager
782
783    ED4_manager  *my_owner;     // who is controlling this object
784    ED4_base    **memberList;
785    ED4_index     no_of_members; // How much members are in the list
786    ED4_index     size_of_list;
787
788public:
789
790    ED4_manager* owner() const { return my_owner; }
791    ED4_base* member(ED4_index i) const { e4_assert(i>=0 && i<size_of_list); return memberList[i]; }
792    ED4_index members() const { return no_of_members; }
793
794    ED4_returncode  insert_member(ED4_base *new_member); // only used to move members with mouse
795    ED4_returncode  append_member(ED4_base *new_member);
796
797    // an array is chosen instead of a linked list, because destructorhandling is more comfortable in various destructors (manager-destructors)
798
799    ED4_returncode  remove_member(ED4_base *member);
800    ED4_index       search_member(ED4_extension *location, ED4_properties prop); // search member
801    ED4_returncode  shift_list(ED4_index start_index, int length);
802    // list has to be shifted because member_list is an array and not a linked list
803
804    ED4_returncode  search_target_species   (ED4_extension *location, ED4_properties prop, ED4_base **found_member, ED4_level return_level);
805
806    ED4_returncode  move_member     (ED4_index old_pos, ED4_index new_pos);
807
808#if defined(IMPLEMENT_DUMP)
809    void dump(size_t indent) const;
810#endif // IMPLEMENT_DUMP
811
812#if defined(ASSERTION_USED)
813    int members_ok() const;
814#endif // ASSERTION_USED
815
816    ED4_members(ED4_manager *the_owner);
817    ~ED4_members();
818};
819
820#ifdef DEBUG
821// # define TEST_BASES_TABLE
822#endif
823
824#define SHORT_TABLE_ELEM_SIZE 1
825#define SHORT_TABLE_MAX_VALUE 0xff
826#define LONG_TABLE_ELEM_SIZE  4
827
828class ED4_bases_table : virtual Noncopyable {
829    int table_entry_size;       // how many bytes are used for each element of 'no_of_bases' (1 or 4 bytes)
830    union {
831        unsigned char *shortTable;
832        int           *longTable;
833    } no_of_bases;      // counts bases for each sequence position
834    int no_of_entries;      // length of bases table
835
836    int legal(int offset) const { return offset>=0 && offset<no_of_entries; }
837
838    void set_elem_long(int offset, int value) {
839#ifdef TEST_BASES_TABLE
840        e4_assert(legal(offset));
841        e4_assert(table_entry_size==LONG_TABLE_ELEM_SIZE);
842#endif
843        no_of_bases.longTable[offset] = value;
844    }
845
846    void set_elem_short(int offset, int value) {
847#ifdef TEST_BASES_TABLE
848        e4_assert(legal(offset));
849        e4_assert(table_entry_size==SHORT_TABLE_ELEM_SIZE);
850        e4_assert(value>=0 && value<=SHORT_TABLE_MAX_VALUE);
851#endif
852        no_of_bases.shortTable[offset] = value;
853    }
854
855    int get_elem_long(int offset) const {
856#ifdef TEST_BASES_TABLE
857        e4_assert(legal(offset));
858        e4_assert(table_entry_size==LONG_TABLE_ELEM_SIZE);
859#endif
860        return no_of_bases.longTable[offset];
861    }
862
863    int get_elem_short(int offset) const {
864#ifdef TEST_BASES_TABLE
865        e4_assert(legal(offset));
866        e4_assert(table_entry_size==SHORT_TABLE_ELEM_SIZE);
867#endif
868        return no_of_bases.shortTable[offset];
869    }
870
871public:
872
873    ED4_bases_table(int maxseqlength);
874    ~ED4_bases_table();
875
876    void init(int length);
877    int size() const { return no_of_entries; }
878
879    int get_table_entry_size() const { return table_entry_size; }
880    void expand_table_entry_size();
881    int bigger_table_entry_size_needed(int new_no_of_sequences) { return table_entry_size==SHORT_TABLE_ELEM_SIZE ? (new_no_of_sequences>SHORT_TABLE_MAX_VALUE) : 0; }
882
883    int operator[](int offset) const { return table_entry_size==SHORT_TABLE_ELEM_SIZE ? get_elem_short(offset) : get_elem_long(offset); }
884
885    void inc_short(int offset)  {
886        int old = get_elem_short(offset);
887        e4_assert(old<255);
888        set_elem_short(offset, old+1);
889    }
890    void dec_short(int offset)  {
891        int old = get_elem_short(offset);
892        e4_assert(old>0);
893        set_elem_short(offset, old-1);
894    }
895    void inc_long(int offset)   {
896        int old = get_elem_long(offset);
897        set_elem_long(offset, old+1);
898    }
899    void dec_long(int offset)   {
900        int old = get_elem_long(offset);
901        e4_assert(old>0);
902        set_elem_long(offset, old-1);
903    }
904
905    int firstDifference(const ED4_bases_table& other, int start, int end, int *firstDifferentPos) const;
906    int lastDifference(const ED4_bases_table& other, int start, int end, int *lastDifferentPos) const;
907
908    void add(const ED4_bases_table& other, int start, int end);
909    void sub(const ED4_bases_table& other, int start, int end);
910    void sub_and_add(const ED4_bases_table& Sub, const ED4_bases_table& Add, PosRange range);
911
912    void change_table_length(int new_length, int default_entry);
913
914
915#ifdef ASSERTION_USED
916    int empty() const;
917#endif // ASSERTION_USED
918};
919
920typedef ED4_bases_table *ED4_bases_table_ptr;
921
922#if defined(DEBUG) && !defined(DEVEL_RELEASE)
923# define TEST_CHAR_TABLE_INTEGRITY // uncomment to remove tests for ED4_char_table
924#endif // DEBUG
925
926class ED4_char_table : virtual Noncopyable {
927    ED4_bases_table_ptr *bases_table;
928    int                  sequences; // # of sequences added to the table
929    int                  ignore; // this table will be ignored when calculating tables higher in hierarchy
930    // (used to suppress SAI in root_group_man tables)
931
932    // @@@ move statics into own class:
933    static bool               initialized;
934    static unsigned char      char_to_index_tab[MAXCHARTABLE];
935    static unsigned char     *upper_index_chars;
936    static unsigned char     *lower_index_chars;
937    static int                used_bases_tables; // size of 'bases_table'
938    static GB_alignment_type  ali_type;
939
940    static inline void set_char_to_index(unsigned char c, int index);
941
942    void add(const ED4_char_table& other, int start, int end);
943    void sub(const ED4_char_table& other, int start, int end);
944
945    void expand_tables();
946    int get_table_entry_size() const {
947        return linear_table(0).get_table_entry_size();
948    }
949    void prepare_to_add_elements(int new_sequences) {
950        e4_assert(used_bases_tables);
951        if (linear_table(0).bigger_table_entry_size_needed(sequences+new_sequences)) {
952            expand_tables();
953        }
954    }
955
956public:
957
958#if defined(TEST_CHAR_TABLE_INTEGRITY) || defined(ASSERTION_USED)
959    bool ok() const;
960    bool empty() const;
961#endif
962
963#if defined(TEST_CHAR_TABLE_INTEGRITY)
964    void test() const; // test if table is valid (dumps core if invalid)
965#else
966    void test() const {}
967#endif
968
969    ED4_char_table(int maxseqlength=0);
970    ~ED4_char_table();
971
972    static void initial_setup(const char *gap_chars, GB_alignment_type ali_type_);
973
974    void ignore_me() { ignore = 1; }
975    int is_ignored() const { return ignore; }
976
977    void init(int maxseqlength);
978    int size() const { return bases_table[0]->size(); }
979    int added_sequences() const { return sequences; }
980
981    void bases_and_gaps_at(int column, int *bases, int *gaps) const;
982
983    unsigned char index_to_upperChar(int index) const;
984    unsigned char index_to_lowerChar(int index) const;
985
986    // linear access to all tables
987    ED4_bases_table&        linear_table(int c)         { e4_assert(c<used_bases_tables); return *bases_table[c]; }
988    const ED4_bases_table&  linear_table(int c) const   { e4_assert(c<used_bases_tables); return *bases_table[c]; }
989
990    // access via character
991    ED4_bases_table&        table(int c)        { e4_assert(c>0 && c<MAXCHARTABLE); return linear_table(char_to_index_tab[c]); }
992    const ED4_bases_table&  table(int c) const  { e4_assert(c>0 && c<MAXCHARTABLE); return linear_table(char_to_index_tab[c]); }
993
994    const PosRange *changed_range(const ED4_char_table& other) const;
995    static const PosRange *changed_range(const char *string1, const char *string2, int min_len);
996
997    void add(const ED4_char_table& other);
998    void sub(const ED4_char_table& other);
999    void sub_and_add(const ED4_char_table& Sub, const ED4_char_table& Add);
1000    void sub_and_add(const ED4_char_table& Sub, const ED4_char_table& Add, PosRange range);
1001
1002    void add(const char *string, int len);
1003    void sub(const char *string, int len);
1004    void sub_and_add(const char *old_string, const char *new_string, PosRange range);
1005
1006    void build_consensus_string_to(char *buffer, ExplicitRange range) const;
1007    char *build_consensus_string(PosRange range) const;
1008    char *build_consensus_string() const { return build_consensus_string(PosRange::whole()); }
1009
1010    void change_table_length(int new_length);
1011};
1012
1013// ----------------------------
1014//      ED4_species_pointer
1015
1016class ED4_species_pointer : virtual Noncopyable {
1017    // @@@ shall be renamed into ED4_gbdata_pointer to reflect general usage
1018
1019    GBDATA *species_pointer;    // points to database
1020
1021    void add_callback(int *clientdata);
1022    void remove_callback(int *clientdata);
1023
1024public:
1025
1026    ED4_species_pointer();
1027    ~ED4_species_pointer();
1028
1029    GBDATA *Get() const { return species_pointer; } 
1030    void Set(GBDATA *gbd, int *clientdata);
1031    void notify_deleted() {
1032        species_pointer=0;
1033    }
1034};
1035
1036// -----------------
1037//      ED4_base
1038
1039class ED4_base;
1040typedef ARB_ERROR (*ED4_cb)(ED4_base *, AW_CL, AW_CL);
1041typedef ARB_ERROR (*ED4_cb1)(ED4_base *, AW_CL);
1042typedef ARB_ERROR (*ED4_cb0)(ED4_base *);
1043
1044enum ED4_species_type {
1045    ED4_SP_NONE, 
1046    ED4_SP_SPECIES, 
1047    ED4_SP_SAI, 
1048    ED4_SP_CONSENSUS,
1049};
1050
1051class ED4_base : virtual Noncopyable {
1052    // base object
1053
1054    ED4_species_pointer my_species_pointer;
1055
1056    // cache world coordinates:
1057
1058    static int           currTimestamp;
1059    mutable AW::Position lastPos;
1060    mutable int          timestamp;
1061
1062    ED4_base_list *linked_objects;                  // linked list of objects which are depending from this object
1063
1064public:
1065    const ED4_objspec& spec;           // contains information about Objectproperties
1066
1067    ED4_manager *parent;                            // Points to parent
1068
1069
1070    ED4_properties   dynamic_prop;                  // contains info about what i am, what i can do, what i should do
1071    char            *id;                            // globally unique name in hierarchy
1072    ED4_index        index;                         // defines the order of child objects
1073    ED4_base        *width_link;                    // concerning the hierarchy
1074    ED4_base        *height_link;                   // concerning the hierarchy
1075    ED4_extension    extension;                     // contains relative info about graphical properties
1076    ED4_update_info  update_info;                   // info about things to be done for the object, i.e. refresh; flag structure
1077    struct {
1078        unsigned int hidden : 1;                    // flag whether object is hidden or not
1079    } flag;
1080
1081    void draw_bb(int color);
1082
1083    DECLARE_DUMP_FOR_ROOTCLASS(ED4_base);
1084
1085    // function for species_pointer
1086
1087    GBDATA *get_species_pointer() const { return my_species_pointer.Get(); }
1088    void set_species_pointer(GBDATA *gbd) { my_species_pointer.Set(gbd, (int*)(this)); }
1089    int has_callback() const { return get_species_pointer()!=0; }
1090
1091    // callbacks
1092
1093    virtual void changed_by_database();
1094    virtual void deleted_from_database();
1095
1096    // functions concerned with graphic output
1097    int adjust_clipping_rectangle();
1098    virtual ED4_returncode  Show(int refresh_all=0, int is_cleared=0) = 0;
1099    virtual bool calc_bounding_box()                                  = 0;
1100
1101    ED4_returncode  clear_background(int color=0);
1102
1103    void set_links(ED4_base *width_link, ED4_base *height_link);
1104
1105    // functions concerned with special initialization
1106    void set_property(ED4_properties prop) { dynamic_prop = (ED4_properties) (dynamic_prop | prop); } 
1107    void clr_property(ED4_properties prop) { dynamic_prop = (ED4_properties) (dynamic_prop & ~prop); }
1108   
1109    // functions concerned with coordinate transformation
1110
1111    void calc_rel_coords(AW_pos *x, AW_pos *y);
1112
1113    void calc_world_coords(AW_pos *x, AW_pos *y) const {
1114        update_world_coords_cache();
1115        *x = lastPos.xpos();
1116        *y = lastPos.ypos();
1117    }
1118    const AW::Position& calc_world_coords() const {
1119        update_world_coords_cache();
1120        return lastPos;
1121    }
1122
1123    void update_world_coords_cache() const {
1124        bool cache_up_to_date = timestamp == currTimestamp;
1125        if (!cache_up_to_date) {
1126            if (parent) {
1127                ED4_base *pab = (ED4_base*)parent;
1128                lastPos = pab->calc_world_coords();
1129            }
1130            else {
1131                lastPos = AW::Origin;
1132            }
1133            lastPos.move(extension.get_parent_offset());
1134            timestamp = currTimestamp;
1135        }
1136    }
1137
1138    static void touch_world_cache() {
1139        currTimestamp++;
1140    }
1141
1142    AW::Rectangle get_win_area(ED4_window *ed4w) const {
1143        AW::Position pos = ed4w->world_to_win_coords(calc_world_coords());
1144        return AW::Rectangle(pos, extension.get_size()-AW::Vector(1, 1));
1145    }
1146
1147    // functions which refer to the object as a child, i.e. travelling down the hierarchy
1148    virtual void request_refresh(int clear=1) = 0;
1149
1150    inline void request_resize();
1151    void request_resize_of_linked();
1152    void resize_requested_by_link(ED4_base *link);
1153    virtual void resize_requested_children() = 0;
1154
1155    virtual void delete_requested_children() = 0;
1156    virtual void Delete()                    = 0;
1157
1158    inline void set_update();
1159    virtual void update_requested_children() = 0;
1160
1161    virtual ED4_returncode  move_requested_by_parent(ED4_move_info *mi)=0;
1162    virtual ED4_returncode  event_sent_by_parent(AW_event *event, AW_window *aww);
1163    virtual ED4_returncode  move_requested_by_child(ED4_move_info *moveinfo)=0;
1164
1165
1166    virtual ED4_returncode  handle_move(ED4_move_info *moveinfo) = 0;
1167
1168    virtual ARB_ERROR route_down_hierarchy(ED4_cb cb, AW_CL cd1, AW_CL cd2);
1169    virtual ARB_ERROR route_down_hierarchy(ED4_cb1 cb, AW_CL cd) { return route_down_hierarchy(ED4_cb(cb), cd, 0); }
1170    virtual ARB_ERROR route_down_hierarchy(ED4_cb0 cb) { return route_down_hierarchy(ED4_cb(cb), 0, 0); }
1171
1172    int calc_group_depth();
1173
1174    // general purpose functions
1175    virtual ED4_base *search_ID(const char *id) = 0;
1176
1177    void  check_all();
1178    short in_border(AW_pos abs_x, AW_pos abs_y, ED4_movemode mode);
1179    ED4_returncode set_width();
1180
1181
1182    ED4_AREA_LEVEL get_area_level(ED4_multi_species_manager **multi_species_manager=0) const; // returns area we belong to and the next multi species manager of the area
1183
1184    ED4_base *get_parent(ED4_level lev) const;
1185    void unlink_from_parent();
1186    bool has_parent(ED4_manager *Parent);
1187    bool is_child_of(ED4_manager *Parent) { return has_parent(Parent); }
1188
1189    virtual char       *resolve_pointer_to_string_copy(int *str_len = 0) const;
1190    virtual const char *resolve_pointer_to_char_pntr(int *str_len = 0) const;
1191
1192    ED4_group_manager  *is_in_folded_group() const;
1193    virtual bool is_hidden() const = 0;
1194
1195    char *get_name_of_species();                      // go from terminal to name of species
1196
1197    // functions which refer to the selected object(s), i.e. across the hierarchy
1198    virtual ED4_base        *get_competent_child(AW_pos x, AW_pos y, ED4_properties relevant_prop)=0;
1199    virtual ED4_base        *get_competent_clicked_child(AW_pos x, AW_pos y, ED4_properties relevant_prop)=0;
1200    virtual ED4_base        *search_spec_child_rek(ED4_level level);    // recursive search for level
1201
1202    ED4_terminal        *get_next_terminal();
1203    ED4_terminal        *get_prev_terminal();
1204
1205    ED4_returncode      generate_configuration_string(char **generated_string);
1206
1207    virtual ED4_returncode  remove_callbacks();
1208   
1209    const ED4_terminal *get_consensus_relevant_terminal() const;
1210
1211    ED4_base(const ED4_objspec& spec_, GB_CSTR id, AW_pos x, AW_pos y, AW_pos width, AW_pos height, ED4_manager *parent);
1212    virtual ~ED4_base();
1213
1214    // use the following functions to test which derived class we have
1215
1216    int is_terminal()               const { e4_assert(this); return spec.static_prop & ED4_P_IS_TERMINAL; }
1217
1218    int is_text_terminal()          const { e4_assert(this); return spec.level & (ED4_L_SPECIES_NAME|ED4_L_SEQUENCE_INFO|ED4_L_SEQUENCE_STRING|ED4_L_PURE_TEXT|ED4_L_COL_STAT); }
1219
1220    int is_species_name_terminal()  const { e4_assert(this); return spec.level & ED4_L_SPECIES_NAME; }
1221
1222    int is_sequence_info_terminal() const { e4_assert(this); return spec.level & ED4_L_SEQUENCE_INFO; }
1223    int is_sequence_terminal()      const { e4_assert(this); return spec.level & ED4_L_SEQUENCE_STRING; }
1224    int is_orf_terminal()           const { e4_assert(this); return spec.level & ED4_L_ORF; }
1225
1226    int is_pure_text_terminal()     const { e4_assert(this); return spec.level & ED4_L_PURE_TEXT; }
1227    int is_columnStat_terminal()    const { e4_assert(this); return spec.level & ED4_L_COL_STAT; }
1228
1229    int is_bracket_terminal()       const { e4_assert(this); return spec.level & ED4_L_BRACKET; }
1230    int is_spacer_terminal()        const { e4_assert(this); return spec.level & ED4_L_SPACER; }
1231    int is_line_terminal()          const { e4_assert(this); return spec.level & ED4_L_LINE; }
1232
1233    int is_manager()                const { e4_assert(this); return spec.static_prop & ED4_P_IS_MANAGER; }
1234
1235    int is_sequence_manager()       const { e4_assert(this); return spec.level & ED4_L_SEQUENCE; }
1236    int is_multi_name_manager()     const { e4_assert(this); return spec.level & ED4_L_MULTI_NAME; }
1237    int is_name_manager()           const { e4_assert(this); return spec.level & ED4_L_NAME_MANAGER; }
1238    int is_multi_species_manager()  const { e4_assert(this); return spec.level & ED4_L_MULTI_SPECIES; }
1239    int is_multi_sequence_manager() const { e4_assert(this); return spec.level & ED4_L_MULTI_SEQUENCE; }
1240    int is_device_manager()         const { e4_assert(this); return spec.level & ED4_L_DEVICE; }
1241
1242    int is_group_manager()          const { e4_assert(this); return spec.level & ED4_L_GROUP; }
1243    int is_root_group_manager()     const { e4_assert(this); return spec.level & ED4_L_ROOTGROUP; }
1244    int is_abstract_group_manager() const { e4_assert(this); return spec.level & (ED4_L_GROUP|ED4_L_ROOTGROUP); }
1245   
1246    int is_species_manager()        const { e4_assert(this); return spec.level & ED4_L_SPECIES; }
1247    int is_area_manager()           const { e4_assert(this); return spec.level & ED4_L_AREA; }
1248
1249    // use the following functions to cast ED4_base to derived classes:
1250
1251#define E4B_DECL_CASTOP_helper(Class,toName)            \
1252    inline const Class *toName() const;                 \
1253    inline Class *toName();
1254   
1255#define E4B_AVOID_CAST__helper(Class,toName,isName)     \
1256    const Class *toName() const;                        \
1257    Class *toName();                                    \
1258    int isName() const;
1259
1260#define E4B_IMPL_CASTOP_helper(Class,toName,isName)                             \
1261    const Class *ED4_base::toName() const {                                     \
1262        e4_assert(isName());                                                    \
1263        return DOWNCAST(const Class*, this);                                    \
1264    }                                                                           \
1265    Class *ED4_base::toName() {                                                 \
1266        return const_cast<Class*>(const_cast<const ED4_base*>(this)->toName()); \
1267    }
1268
1269#define E4B_DECL_CASTOP(name)          E4B_DECL_CASTOP_helper(concat(ED4_,name), concat(to_,name))
1270#define E4B_AVOID_UNNEEDED_CASTS(name) E4B_AVOID_CAST__helper(concat(ED4_,name), concat(to_,name), concat(is_,name))
1271#define E4B_IMPL_CASTOP(name)          E4B_IMPL_CASTOP_helper(concat(ED4_,name), concat(to_,name), concat(is_,name))
1272
1273    E4B_DECL_CASTOP(area_manager);           // to_area_manager
1274    E4B_DECL_CASTOP(abstract_group_manager); // to_abstract_group_manager
1275    E4B_DECL_CASTOP(bracket_terminal);       // to_bracket_terminal
1276    E4B_DECL_CASTOP(columnStat_terminal);    // to_columnStat_terminal
1277    E4B_DECL_CASTOP(device_manager);         // to_device_manager
1278    E4B_DECL_CASTOP(group_manager);          // to_group_manager
1279    E4B_DECL_CASTOP(line_terminal);          // to_line_terminal
1280    E4B_DECL_CASTOP(manager);                // to_manager
1281    E4B_DECL_CASTOP(multi_name_manager);     // to_multi_name_manager
1282    E4B_DECL_CASTOP(multi_sequence_manager); // to_multi_sequence_manager
1283    E4B_DECL_CASTOP(multi_species_manager);  // to_multi_species_manager
1284    E4B_DECL_CASTOP(name_manager);           // to_name_manager
1285    E4B_DECL_CASTOP(orf_terminal);           // to_orf_terminal
1286    E4B_DECL_CASTOP(pure_text_terminal);     // to_pure_text_terminal
1287    E4B_DECL_CASTOP(root_group_manager);     // to_root_group_manager
1288    E4B_DECL_CASTOP(sequence_info_terminal); // to_sequence_info_terminal
1289    E4B_DECL_CASTOP(sequence_manager);       // to_sequence_manager
1290    E4B_DECL_CASTOP(sequence_terminal);      // to_sequence_terminal
1291    E4B_DECL_CASTOP(spacer_terminal);        // to_spacer_terminal
1292    E4B_DECL_CASTOP(species_manager);        // to_species_manager
1293    E4B_DECL_CASTOP(species_name_terminal);  // to_species_name_terminal
1294    E4B_DECL_CASTOP(terminal);               // to_terminal
1295    E4B_DECL_CASTOP(text_terminal);          // to_text_terminal
1296
1297    // simple access to containing managers
1298    inline ED4_species_manager *containing_species_manager() const;
1299
1300    // discriminate between different sequence managers:
1301
1302    inline bool is_consensus_manager() const;
1303    inline bool is_SAI_manager() const;
1304    inline bool is_species_seq_manager() const;
1305
1306    inline ED4_species_type get_species_type() const; // works for all items (recursively) contained in ED4_species_manager
1307
1308    inline bool inside_consensus_manager() const;
1309    inline bool inside_SAI_manager() const;
1310    inline bool inside_species_seq_manager() const;
1311
1312    inline bool is_consensus_terminal() const;
1313    inline bool is_SAI_terminal() const;
1314    inline bool is_species_seq_terminal() const;
1315};
1316
1317struct ED4_manager : public ED4_base { // derived from a Noncopyable
1318    ED4_members *children;
1319
1320    E4B_AVOID_UNNEEDED_CASTS(manager);
1321    DECLARE_DUMP_FOR_BASECLASS(ED4_manager, ED4_base);
1322
1323    int refresh_flag_ok();
1324
1325    virtual void changed_by_database();
1326    virtual void deleted_from_database();
1327
1328    // functions concerned with graphics
1329    virtual ED4_returncode  Show(int refresh_all=0, int is_cleared=0);
1330    virtual bool calc_bounding_box();
1331
1332    ED4_returncode distribute_children();
1333
1334    // top-down functions, means travelling down the hierarchy
1335    virtual ED4_returncode event_sent_by_parent(AW_event *event, AW_window *aww);
1336
1337    virtual void request_refresh(int clear=1);
1338    ED4_returncode clear_refresh();
1339
1340    virtual void resize_requested_children();
1341
1342    virtual void update_requested_children();
1343
1344    virtual void delete_requested_children();
1345    virtual void Delete();
1346
1347    virtual ED4_returncode  move_requested_by_parent(ED4_move_info *mi);
1348
1349    void create_consensus(ED4_abstract_group_manager *upper_group_manager, arb_progress *progress);
1350
1351    virtual ARB_ERROR route_down_hierarchy(ED4_cb cb, AW_CL cd1, AW_CL cd2);
1352    virtual ARB_ERROR route_down_hierarchy(ED4_cb1 cb, AW_CL cd) { return route_down_hierarchy(ED4_cb(cb), cd, 0); }
1353    virtual ARB_ERROR route_down_hierarchy(ED4_cb0 cb) { return route_down_hierarchy(ED4_cb(cb), 0, 0); }
1354
1355    ED4_base* find_first_that(ED4_level level, bool (*condition)(ED4_base *to_test, AW_CL arg), AW_CL arg);
1356    ED4_base* find_first_that(ED4_level level, bool (*condition)(ED4_base *to_test)) {
1357        return find_first_that(level, (bool(*)(ED4_base*, AW_CL))condition, (AW_CL)0);
1358    }
1359
1360     // bottom-up functions
1361    virtual ED4_returncode  move_requested_by_child(ED4_move_info *moveinfo);
1362    inline void resize_requested_by_child();
1363    virtual ED4_returncode  refresh_requested_by_child();
1364    void delete_requested_by_child();
1365    void update_requested_by_child();
1366   
1367    ED4_base *get_defined_level(ED4_level lev) const;
1368
1369    // functions referring the consensus
1370
1371    ED4_returncode      create_group(ED4_group_manager **group_manager, GB_CSTR group_name);
1372
1373    void update_consensus(ED4_manager *old_parent, ED4_manager *new_parent, ED4_base *sequence);
1374    ED4_returncode rebuild_consensi(ED4_base *start_species, ED4_update_flag update_flag);
1375
1376    ED4_returncode  check_in_bases(ED4_base *added_base);
1377    ED4_returncode  check_out_bases(ED4_base *subbed_base);
1378
1379    ED4_returncode  update_bases(const ED4_base *old_base, const ED4_base *new_base, PosRange range = PosRange::whole());
1380    ED4_returncode  update_bases(const char *old_seq, int old_len, const char *new_seq, int new_len, PosRange range = PosRange::whole());
1381    ED4_returncode  update_bases(const char *old_seq, int old_len, const ED4_base *new_base, PosRange range = PosRange::whole());
1382    ED4_returncode  update_bases(const ED4_char_table *old_table, const ED4_char_table *new_table, PosRange range = PosRange::whole());
1383
1384    ED4_returncode  update_bases_and_rebuild_consensi(const char *old_seq, int old_len, ED4_base *species, ED4_update_flag update_flag, PosRange range = PosRange::whole());
1385
1386    // handle moves across the hierarchy
1387    virtual ED4_returncode  handle_move(ED4_move_info *moveinfo);
1388
1389    virtual ED4_base *get_competent_child(AW_pos x, AW_pos y, ED4_properties relevant_prop);
1390    virtual ED4_base *get_competent_clicked_child(AW_pos x, AW_pos y, ED4_properties relevant_prop);
1391    virtual ED4_base *search_spec_child_rek(ED4_level level);           // recursive search for level
1392
1393    // general purpose functions
1394    virtual ED4_base        *search_ID(const char *id);
1395    virtual ED4_returncode  remove_callbacks();
1396
1397    ED4_terminal *get_first_terminal(int start_index=0) const;
1398    ED4_terminal *get_last_terminal(int start_index=-1) const;
1399
1400    void hide_children();
1401    void unhide_children();
1402
1403    bool is_hidden() const {
1404        if (flag.hidden) return true;
1405        if (!parent) return false;
1406        return parent->is_hidden();
1407    }
1408
1409    ED4_manager(const ED4_objspec& spec_, const char *id, AW_pos x, AW_pos y, AW_pos width, AW_pos height, ED4_manager *parent);
1410    virtual ~ED4_manager();
1411};
1412
1413struct ED4_terminal : public ED4_base { // derived from a Noncopyable
1414    E4B_AVOID_UNNEEDED_CASTS(terminal);
1415
1416    struct { unsigned int deleted : 1; } tflag; // @@@ go bool
1417
1418    long curr_timestamp;
1419
1420    DECLARE_DUMP_FOR_BASECLASS(ED4_terminal,ED4_base);
1421
1422    // callbacks
1423
1424    virtual void changed_by_database();
1425    virtual void deleted_from_database();
1426
1427    // functions concerning graphic output
1428    virtual ED4_returncode Show(int refresh_all=0, int is_cleared=0) = 0;
1429    virtual ED4_returncode draw() = 0;
1430
1431    virtual bool calc_bounding_box();
1432
1433    ED4_returncode draw_drag_box(AW_pos x, AW_pos y, GB_CSTR text = NULL, int cursor_y=-1);
1434
1435    // functions which concern the object as a child
1436    virtual void request_refresh(int clear=1);
1437
1438    virtual void resize_requested_children();
1439
1440    virtual void update_requested_children();
1441    virtual void delete_requested_children();
1442    virtual void Delete();
1443
1444    virtual ED4_returncode  move_requested_by_parent(ED4_move_info *mi);
1445    virtual ED4_returncode  event_sent_by_parent(AW_event *event, AW_window *aww);
1446    virtual ED4_base *get_competent_child(AW_pos x, AW_pos y, ED4_properties relevant_prop);
1447    virtual ED4_base *get_competent_clicked_child(AW_pos x, AW_pos y, ED4_properties relevant_prop);
1448    virtual ED4_returncode  move_requested_by_child(ED4_move_info *moveinfo);
1449    virtual ED4_returncode  handle_move(ED4_move_info *moveinfo);
1450
1451    ED4_returncode kill_object();
1452
1453    // general purpose functions
1454    virtual ED4_base *search_ID(const char *id);
1455    virtual char          *resolve_pointer_to_string_copy(int *str_len = 0) const;
1456    virtual const char    *resolve_pointer_to_char_pntr(int *str_len = 0) const;
1457    virtual ED4_returncode remove_callbacks();
1458
1459    GB_ERROR write_sequence(const char *seq, int seq_len);
1460
1461    void scroll_into_view(ED4_window *ed4w);
1462    inline bool setCursorTo(ED4_cursor *cursor, int seq_pos, bool unfoldGroups, ED4_CursorJumpType jump_type);
1463
1464    bool is_hidden() const { return parent && parent->is_hidden(); }
1465
1466    ED4_terminal(const ED4_objspec& spec_, GB_CSTR id, AW_pos x, AW_pos y, AW_pos width, AW_pos height, ED4_manager *parent);
1467    virtual ~ED4_terminal();
1468};
1469
1470enum ED4_species_mode {
1471    ED4_SM_MOVE,
1472    ED4_SM_KILL,
1473    ED4_SM_MARK
1474};
1475
1476class ED4_reference_terminals : virtual Noncopyable {
1477    ED4_sequence_info_terminal *ref_sequence_info;
1478    ED4_sequence_terminal      *ref_sequence;
1479    ED4_sequence_info_terminal *ref_column_stat_info;
1480    ED4_columnStat_terminal    *ref_column_stat;
1481
1482    void null() { ref_sequence_info = 0; ref_sequence = 0; ref_column_stat = 0; ref_column_stat_info = 0; }
1483public:
1484    void clear();
1485    void init(ED4_sequence_info_terminal *, ED4_sequence_terminal *, ED4_sequence_info_terminal *, ED4_columnStat_terminal *);
1486
1487    ED4_sequence_info_terminal *get_ref_sequence_info()    { return ref_sequence_info; }
1488    ED4_sequence_terminal      *get_ref_sequence()         { return ref_sequence; }
1489    ED4_sequence_info_terminal *get_ref_column_stat_info() { return ref_column_stat_info; }
1490    ED4_columnStat_terminal    *get_ref_column_stat()      { return ref_column_stat; }
1491
1492    ED4_reference_terminals()  { null(); }
1493    ~ED4_reference_terminals() { clear(); }
1494};
1495
1496class ED4_WinContext {
1497    ED4_window *ed4w;
1498    AW_device  *device;
1499
1500    bool is_set() const { return ed4w; }
1501    void init(ED4_window *ew) {
1502        e4_assert(ew);
1503        ed4w   = ew;
1504        device = ed4w->get_device();
1505    }
1506
1507    void warn_missing_context() const;
1508    void expect_context() const { if (!is_set()) warn_missing_context(); }
1509
1510protected:
1511    ED4_WinContext() : ed4w(0), device(0) {}
1512    static ED4_WinContext current_context;
1513   
1514public:
1515    inline ED4_WinContext(AW_window *aww_);
1516    ED4_WinContext(ED4_window *ed4w_) { init(ed4w_); }
1517
1518    AW_device *get_device() const { expect_context(); return device; }
1519    ED4_window *get_ed4w() const { expect_context(); return ed4w; }
1520
1521    static const ED4_WinContext& get_current_context() { return current_context; }
1522    static bool have_context() { return current_context.is_set(); }
1523};
1524
1525// accessors for current context (see also ED4_WinContextFree)
1526inline AW_device *current_device() { return ED4_WinContext::get_current_context().get_device(); }
1527inline ED4_window *current_ed4w() { return ED4_WinContext::get_current_context().get_ed4w(); }
1528inline AW_window *current_aww() { return current_ed4w()->aww; }
1529inline ED4_cursor& current_cursor() { return current_ed4w()->cursor; }
1530
1531
1532class ED4_root : virtual Noncopyable {
1533    void ED4_ROOT() const { e4_assert(0); } // avoid ED4_root-members use global ED4_ROOT
1534
1535    void refresh_window_simple(bool redraw);
1536    void handle_update_requests(bool& redraw);
1537
1538    ED4_window *most_recently_used_window;
1539
1540public:
1541    char       *db_name;                            // name of Default Properties database (complete path)
1542    AW_root    *aw_root;                            // Points to 'AW-Window-Controller'
1543    AW_default  props_db;                           // Default Properties database
1544
1545    ED4_window              *first_window;          // Points to List of Main Windows of ED4
1546    ED4_main_manager        *main_manager;          // Points to Main manager of ED4
1547    ED4_area_manager        *middle_area_man;       // Points to middle area
1548    ED4_area_manager        *top_area_man;
1549    ED4_root_group_manager  *root_group_man;
1550    EDB_root_bact           *database;              // Points to Object which controls Data
1551    ED4_selected_list       *selected_objects;
1552    ED4_scroll_links         scroll_links;
1553    bool                     folding_action;        // flag tells whether action was folding action or not
1554    ED4_reference_terminals  ref_terminals;
1555    ED4_species_mode         species_mode;
1556    ED4_scroll_picture       scroll_picture;
1557    BI_ecoli_ref            *ecoli_ref;
1558    char                    *alignment_name;
1559    GB_alignment_type        alignment_type;
1560    AWT_reference           *reference;
1561    AWT_seq_colors          *sequence_colors;
1562    AW_gc_manager            aw_gc_manager;
1563    ST_ML                   *st_ml;
1564    AW_helix                *helix;
1565    int                      helix_spacing;
1566    long                     helix_add_spacing;
1567    long                     terminal_add_spacing;
1568    char                    *protstruct;            // protein structure summary
1569    long                     protstruct_len;        // protein structure summary
1570    ed_key                  *edk;
1571    ED4_Edit_String         *edit_string;
1572
1573    bool column_stat_activated;
1574    bool column_stat_initialized;
1575    bool visualizeSAI;
1576    bool visualizeSAI_allSpecies;
1577
1578    int temp_gc;
1579    AW_font_group font_group;
1580
1581    void announce_useraction_in(AW_window *aww);
1582    ED4_window *get_most_recently_used_window() const { return most_recently_used_window; }
1583
1584    inline ED4_device_manager *get_device_manager();
1585
1586    // Initializing functions
1587    ED4_returncode  create_hierarchy(char *area_string_middle, char *area_string_top);
1588    ED4_returncode  init_alignment();
1589    void recalc_font_group();
1590
1591    AW_window *create_new_window();
1592    ED4_returncode generate_window(AW_device **device, ED4_window **new_window);
1593    void copy_window_struct(ED4_window *source,   ED4_window *destination);
1594
1595    // functions concerned with global refresh and resize
1596    void resize_all();
1597
1598    void special_window_refresh(bool handle_updates);
1599    ED4_returncode refresh_all_windows(bool redraw);
1600
1601    void request_refresh_for_all_terminals();
1602    void request_refresh_for_specific_terminals(ED4_level lev);
1603    void request_refresh_for_consensus_terminals();
1604    void request_refresh_for_sequence_terminals();
1605
1606    inline void announce_deletion(ED4_base *object); // before deleting an object, use this to announce
1607
1608     // functions concerned with list of selected objects
1609    ED4_returncode add_to_selected(ED4_species_name_terminal *object);
1610    void remove_from_selected(ED4_species_name_terminal *object);
1611    ED4_returncode deselect_all();
1612
1613    ED4_returncode get_area_rectangle(AW_screen_area *rect, AW_pos x, AW_pos y);
1614
1615    ED4_index pixel2pos(AW_pos click_x);
1616
1617    void remove_all_callbacks();
1618   
1619    ED4_root();
1620    ~ED4_root();
1621};
1622
1623ED4_WinContext::ED4_WinContext(AW_window *aww_) { init(ED4_ROOT->first_window->get_matching_ed4w(aww_)); }
1624
1625struct ED4_LocalWinContext : private ED4_WinContext {
1626    ED4_LocalWinContext(AW_window *aww) : ED4_WinContext(current_context) { current_context = ED4_WinContext(aww); }
1627    ED4_LocalWinContext(ED4_window *ew) : ED4_WinContext(current_context) { current_context = ED4_WinContext(ew); }
1628    ~ED4_LocalWinContext() { current_context = *this; }
1629};
1630
1631class ED4_MostRecentWinContext : virtual Noncopyable { 
1632    ED4_LocalWinContext *most_recent;
1633public:
1634    ED4_MostRecentWinContext() : most_recent(0) {
1635        if (!ED4_WinContext::have_context()) {
1636            most_recent = new ED4_LocalWinContext(ED4_ROOT->get_most_recently_used_window());
1637        }
1638    }
1639    ~ED4_MostRecentWinContext() {
1640        delete most_recent;
1641    }
1642};
1643
1644inline void ED4_root::announce_deletion(ED4_base *object) {
1645    if (object->is_terminal()) {
1646        ED4_terminal *term = object->to_terminal();
1647        for (ED4_window *win = first_window; win; win = win->next) {
1648            ED4_LocalWinContext uses(win);
1649            win->announce_deletion(term);
1650        }
1651    }
1652}
1653
1654// ------------------------
1655//      manager classes
1656//
1657// All manager classes only differ in their static properties.
1658// This kind of construction was chosen for using a minimum of RAM
1659
1660class ED4_main_manager : public ED4_manager { // derived from a Noncopyable
1661    // first in hierarchy
1662
1663    E4B_AVOID_UNNEEDED_CASTS(main_manager);
1664
1665    // these terminals are redrawn after refresh (with increase clipping area)
1666    // to revert text from middle area drawn into top area:
1667    ED4_terminal *top_middle_line;
1668    ED4_terminal *top_middle_spacer;
1669
1670public:
1671    ED4_main_manager(const char *id, AW_pos x, AW_pos y, AW_pos width, AW_pos height, ED4_manager *parent);
1672
1673    void set_top_middle_spacer_terminal(ED4_terminal *top_middle_spacer_) { top_middle_spacer = top_middle_spacer_; }
1674    void set_top_middle_line_terminal(ED4_terminal *top_middle_line_) { top_middle_line = top_middle_line_; }
1675
1676    ED4_terminal *get_top_middle_spacer_terminal() const { return top_middle_spacer; }
1677    ED4_terminal *get_top_middle_line_terminal() const { return top_middle_line; }
1678
1679    DECLARE_DUMP_FOR_LEAFCLASS(ED4_manager);
1680
1681    virtual ED4_returncode Show(int refresh_all=0, int is_cleared=0);
1682    virtual void resize_requested_children();
1683   
1684    void clear_whole_background();
1685};
1686
1687struct ED4_device_manager : public ED4_manager {
1688    E4B_AVOID_UNNEEDED_CASTS(device_manager);
1689    ED4_device_manager  (const char *id, AW_pos x, AW_pos y, AW_pos width, AW_pos height, ED4_manager *parent);
1690    DECLARE_DUMP_FOR_LEAFCLASS(ED4_manager);
1691};
1692
1693struct ED4_area_manager : public ED4_manager {
1694    E4B_AVOID_UNNEEDED_CASTS(area_manager);
1695    ED4_area_manager(const char *id, AW_pos x, AW_pos y, AW_pos width, AW_pos height, ED4_manager *parent);
1696    DECLARE_DUMP_FOR_LEAFCLASS(ED4_manager);
1697
1698    ED4_multi_species_manager *get_multi_species_manager() const {
1699        return get_defined_level(ED4_L_MULTI_SPECIES)->to_multi_species_manager();
1700    }
1701};
1702
1703class ED4_multi_species_manager : public ED4_manager {
1704    E4B_AVOID_UNNEEDED_CASTS(multi_species_manager);
1705
1706    int species;          // # of species (-1 == unknown)
1707    int selected_species; // # of selected species (-1 == unknown)
1708
1709    void    set_species_counters(int no_of_species, int no_of_selected);
1710#ifdef DEBUG
1711    void    count_species(int *speciesPtr, int *selectedPtr) const;
1712#endif
1713    void    update_species_counters();
1714
1715public:
1716    ED4_multi_species_manager(const char *id, AW_pos x, AW_pos y, AW_pos width, AW_pos height, ED4_manager *parent);
1717
1718    DECLARE_DUMP_FOR_LEAFCLASS(ED4_manager);
1719
1720    virtual void update_requested_children();
1721    virtual void delete_requested_children();
1722
1723    int count_visible_children();           // is called by a multi_species_manager
1724
1725    ED4_species_manager       *get_consensus_manager() const;       // returns the consensus-manager or NULL
1726    ED4_species_name_terminal *get_consensus_name_terminal() const; // returns the consensus-name-terminal or NULL
1727
1728    // functions concerned with selection
1729    int get_no_of_selected_species();
1730    int get_no_of_species();
1731
1732    void update_group_id();
1733
1734    void invalidate_species_counters();
1735    int  has_valid_counters() const { return species != -1 && selected_species!=-1; }
1736    bool all_are_selected() const { e4_assert(has_valid_counters()); return species == selected_species; }
1737
1738    void select_all(bool only_species);
1739    void deselect_all_species_and_SAI();
1740    void invert_selection_of_all_species();
1741    void marked_species_select(bool select);
1742    void selected_species_mark(bool mark);
1743
1744    void toggle_selected_species();
1745};
1746
1747class ED4_abstract_group_manager : public ED4_manager {
1748    E4B_AVOID_UNNEEDED_CASTS(abstract_group_manager);
1749protected:
1750    ED4_char_table my_table; // table concerning Consensusfunction
1751
1752public:
1753    ED4_abstract_group_manager(const ED4_objspec& spec_, const char *id, AW_pos x, AW_pos y, AW_pos width, AW_pos height, ED4_manager *parent);
1754
1755    DECLARE_DUMP_FOR_BASECLASS(ED4_abstract_group_manager, ED4_manager);
1756
1757    ED4_char_table&         table() { return my_table; }
1758    const ED4_char_table&   table() const { return my_table; }
1759
1760    ED4_bases_table& table(unsigned char c) { return table().table(c); }
1761    const ED4_bases_table& table(unsigned char c) const { return table().table(c); }
1762
1763    ED4_multi_species_manager *get_multi_species_manager() const {
1764        return get_defined_level(ED4_L_MULTI_SPECIES)->to_multi_species_manager();
1765    }
1766};
1767
1768struct ED4_group_manager : public ED4_abstract_group_manager {
1769    E4B_AVOID_UNNEEDED_CASTS(group_manager);
1770    ED4_group_manager(const char *id, AW_pos x, AW_pos y, AW_pos width, AW_pos height, ED4_manager *parent);
1771    DECLARE_DUMP_FOR_LEAFCLASS(ED4_abstract_group_manager);
1772    void reinit_char_table();
1773};
1774
1775enum ED4_remap_mode {
1776    ED4_RM_NONE,                                    // no remapping (normal mode)
1777    ED4_RM_SHOW_ABOVE,                              // Show all positions, where xxx% of all edited sequences have any base
1778    ED4_RM_MAX_ALIGN,                               // ------------------------- any edited sequence has a base
1779    ED4_RM_MAX_EDIT,                                // like ED4_RM_MAX_ALIGN, but bases are pushed OVER remapped gaps (not INTO)
1780    ED4_RM_DYNAMIC_GAPS,                            // gaps shown as spaces (more gaps => more spaces)
1781
1782    ED4_RM_MODES
1783
1784};
1785
1786class ED4_remap : virtual Noncopyable {
1787
1788    ED4_remap_mode mode;
1789    int show_above_percent;     // used only for ED4_RM_SHOW_ABOVE
1790
1791    size_t sequence_table_len;      // allocated size of sequence_to_screen_tab
1792    size_t screen_table_len;        // allocated size of screen_to_sequence_tab
1793
1794    size_t sequence_len;        // size of recently compiled part of sequence_to_screen_tab
1795    size_t screen_len;          // size of recently compiled part of screen_to_sequence_tab
1796
1797    int *screen_to_sequence_tab;
1798    int *sequence_to_screen_tab;    // <0 means position is not mapped (last displayed sequence position)
1799
1800    int changed;            // remap-table changed at last compile
1801    int update_needed;          // remapping should be recompiled
1802
1803    inline void set_sequence_to_screen(int pos, int newVal);
1804
1805public:
1806
1807    ED4_remap();
1808    ~ED4_remap();
1809
1810    int screen_to_sequence(int screen_pos) const;
1811
1812    int sequence_to_screen_PLAIN(int sequence_pos) const { 
1813        e4_assert(sequence_pos>=0 && size_t(sequence_pos)<=sequence_len);
1814        return sequence_to_screen_tab[sequence_pos];
1815    }
1816    int shown_sequence_to_screen(int sequence_pos) const {
1817        // as well works for sequence_pos == MAXSEQUENCECHARACTERLENGTH
1818        int screen_pos = sequence_to_screen_PLAIN(sequence_pos);
1819        e4_assert(screen_pos >= 0); // sequence_pos expected to be visible (i.e. not folded away)
1820        return screen_pos;
1821    }
1822
1823    int clipped_sequence_to_screen_PLAIN(int sequence_pos) const; 
1824    int sequence_to_screen(int sequence_pos) const;
1825
1826    PosRange sequence_to_screen(PosRange range) const {
1827        e4_assert(!range.is_empty());
1828        return PosRange(sequence_to_screen(range.start()), sequence_to_screen(range.end()));
1829    }
1830    PosRange screen_to_sequence(PosRange range) const {
1831        e4_assert(!range.is_empty());
1832        if (range.is_unlimited()) return PosRange::from(screen_to_sequence(range.start()));
1833        return PosRange(screen_to_sequence(range.start()), screen_to_sequence(range.end()));
1834    }
1835
1836    size_t get_max_screen_pos() const { return screen_len-1; }
1837
1838    ED4_remap_mode get_mode() const { return mode; }
1839    void set_mode(ED4_remap_mode Mode, int above_percent) {
1840        if (Mode<0 || Mode>=ED4_RM_MODES) {
1841            Mode = ED4_RM_NONE;
1842        }
1843        if (mode!=Mode) {
1844            mode = Mode;
1845            update_needed = 1;
1846        }
1847
1848        if (show_above_percent!=above_percent) {
1849            show_above_percent = above_percent;
1850            if (mode==ED4_RM_SHOW_ABOVE) {
1851                update_needed = 1;
1852            }
1853        }
1854    }
1855
1856    void mark_compile_needed();     // recompile if mode != none
1857    void mark_compile_needed_force();   // always recompile
1858    int compile_needed() const { return update_needed; }
1859
1860    GB_ERROR compile(ED4_root_group_manager *gm);
1861    int was_changed() const { return changed; }     // mapping changed by last compile ?
1862
1863    int is_shown(int position) const { return sequence_to_screen_PLAIN(position)>=0; }
1864
1865    ExplicitRange clip_screen_range(PosRange screen_range) const { return ExplicitRange(screen_range, screen_len-1); }
1866};
1867
1868class ED4_root_group_manager : public ED4_abstract_group_manager {
1869    E4B_AVOID_UNNEEDED_CASTS(root_group_manager);
1870    ED4_remap my_remap;
1871public:
1872    ED4_root_group_manager(const char *id, AW_pos x, AW_pos y, AW_pos width, AW_pos height, ED4_manager *parent);
1873
1874    bool update_remap(); // 'true' if mapping has changed
1875
1876    const ED4_remap *remap() const { return &my_remap; }
1877    ED4_remap *remap() { return &my_remap; }
1878
1879    virtual ED4_returncode Show(int refresh_all=0, int is_cleared=0);
1880    virtual void resize_requested_children();
1881
1882    DECLARE_DUMP_FOR_LEAFCLASS(ED4_abstract_group_manager);
1883};
1884
1885typedef void (*ED4_species_manager_cb)(ED4_species_manager*, AW_CL);
1886
1887class ED4_species_manager_cb_data {
1888    ED4_species_manager_cb cb;
1889    AW_CL                  cd; // client data
1890
1891public:
1892    ED4_species_manager_cb_data(ED4_species_manager_cb cb_, AW_CL cd_) : cb(cb_), cd(cd_) {}
1893
1894    void call(ED4_species_manager *man) const { cb(man, cd); }
1895    bool operator<(const ED4_species_manager_cb_data& other) const {
1896        return (char*)cb < (char*)other.cb &&
1897            (char*)cd < (char*)other.cd;
1898    }
1899};
1900
1901class ED4_species_manager : public ED4_manager {
1902    E4B_AVOID_UNNEEDED_CASTS(species_manager);
1903   
1904    std::set<ED4_species_manager_cb_data> callbacks;
1905
1906    ED4_species_type type;
1907    bool selected;
1908
1909public:
1910    ED4_species_manager(ED4_species_type type_, const char *id, AW_pos x, AW_pos y, AW_pos width, AW_pos height, ED4_manager *parent);
1911    ~ED4_species_manager   ();
1912
1913    DECLARE_DUMP_FOR_LEAFCLASS(ED4_manager);
1914
1915    ED4_species_type get_type() const { return type; }
1916
1917    bool is_selected() const { return selected; }
1918    void set_selected(bool select) {
1919        // e4_assert(type != ED4_SP_CONSENSUS); // it's not allowed to select a consensus // @@@ happens atm when moving a group
1920        selected = select;
1921    }
1922
1923    bool setCursorTo(ED4_cursor *cursor, int seq_pos, bool unfold_groups, ED4_CursorJumpType jump_type);
1924
1925    void add_sequence_changed_cb(ED4_species_manager_cb cb, AW_CL cd);
1926    void remove_sequence_changed_cb(ED4_species_manager_cb cb, AW_CL cd);
1927    void remove_all_callbacks();
1928
1929    void do_callbacks();
1930
1931    ED4_species_name_terminal *get_name_terminal() const { return children->member(0)->to_species_name_terminal(); }
1932};
1933
1934inline ED4_species_manager *ED4_base::containing_species_manager() const {
1935    ED4_base *sman = get_parent(ED4_L_SPECIES);
1936    return sman ? sman->to_species_manager() : NULL;
1937}
1938
1939inline bool ED4_base::is_consensus_manager()    const { return is_species_manager() && to_species_manager()->get_type() == ED4_SP_CONSENSUS; }
1940inline bool ED4_base::is_SAI_manager()          const { return is_species_manager() && to_species_manager()->get_type() == ED4_SP_SAI; }
1941inline bool ED4_base::is_species_seq_manager()  const { return is_species_manager() && to_species_manager()->get_type() == ED4_SP_SPECIES; }
1942
1943inline ED4_species_type ED4_base::get_species_type() const {
1944    ED4_species_manager *sman = containing_species_manager();
1945    return sman ? sman->get_type() : ED4_SP_NONE;
1946}
1947
1948inline bool ED4_base::inside_consensus_manager()   const { return get_species_type() == ED4_SP_CONSENSUS; }
1949inline bool ED4_base::inside_SAI_manager()         const { return get_species_type() == ED4_SP_SAI; }
1950inline bool ED4_base::inside_species_seq_manager() const { return get_species_type() == ED4_SP_SPECIES; }
1951
1952inline bool ED4_base::is_consensus_terminal()   const { return is_sequence_terminal() && inside_consensus_manager(); }
1953inline bool ED4_base::is_SAI_terminal()         const { return is_sequence_terminal() && inside_SAI_manager(); }
1954inline bool ED4_base::is_species_seq_terminal() const { return is_sequence_terminal() && inside_species_seq_manager(); }
1955
1956inline bool ED4_cursor::in_species_seq_terminal() const { return owner_of_cursor && owner_of_cursor->is_species_seq_terminal(); }
1957inline bool ED4_cursor::in_consensus_terminal()   const { return owner_of_cursor && owner_of_cursor->is_consensus_terminal(); }
1958inline bool ED4_cursor::in_SAI_terminal()         const { return owner_of_cursor && owner_of_cursor->is_SAI_terminal(); }
1959
1960
1961struct ED4_multi_sequence_manager : public ED4_manager {
1962    E4B_AVOID_UNNEEDED_CASTS(multi_sequence_manager);
1963    ED4_multi_sequence_manager(const char *id, AW_pos x, AW_pos y, AW_pos width, AW_pos height, ED4_manager *parent);
1964    DECLARE_DUMP_FOR_LEAFCLASS(ED4_manager);
1965};
1966
1967struct ED4_sequence_manager : public ED4_manager {
1968    E4B_AVOID_UNNEEDED_CASTS(sequence_manager);
1969    ED4_sequence_manager(const char *id, AW_pos x, AW_pos y, AW_pos width, AW_pos height, ED4_manager *parent);
1970    DECLARE_DUMP_FOR_LEAFCLASS(ED4_manager);
1971};
1972
1973struct ED4_multi_name_manager : public ED4_manager {
1974    E4B_AVOID_UNNEEDED_CASTS(multi_name_manager);
1975    // member of ED4_species_manager (contains ED4_name_manager for name and info)
1976    ED4_multi_name_manager(const char *id, AW_pos x, AW_pos y, AW_pos width, AW_pos height, ED4_manager *parent);
1977    DECLARE_DUMP_FOR_LEAFCLASS(ED4_manager);
1978};
1979
1980
1981struct ED4_name_manager : public ED4_manager {
1982    E4B_AVOID_UNNEEDED_CASTS(name_manager);
1983    // member of ED4_multi_name_manager (contains speciesname or other info concerning the species)
1984    ED4_name_manager(const char *id, AW_pos x, AW_pos y, AW_pos width, AW_pos height, ED4_manager *parent);
1985    DECLARE_DUMP_FOR_LEAFCLASS(ED4_manager);
1986};
1987
1988
1989// -------------------------
1990//      terminal classes
1991
1992
1993struct ED4_tree_terminal : public ED4_terminal {
1994    E4B_AVOID_UNNEEDED_CASTS(tree_terminal);
1995   
1996    virtual ED4_returncode draw();
1997    virtual ED4_returncode Show(int refresh_all=0, int is_cleared=0);
1998
1999    ED4_tree_terminal(const char *id, AW_pos x, AW_pos y, AW_pos width, AW_pos height, ED4_manager *parent);
2000
2001    DECLARE_DUMP_FOR_LEAFCLASS(ED4_terminal);
2002};
2003
2004struct ED4_bracket_terminal : public ED4_terminal {
2005    E4B_AVOID_UNNEEDED_CASTS(bracket_terminal);
2006
2007    virtual ED4_returncode draw();
2008    virtual ED4_returncode Show(int refresh_all=0, int is_cleared=0);
2009
2010    void fold();
2011    void unfold();
2012
2013    ED4_bracket_terminal(const char *id, AW_pos x, AW_pos y, AW_pos width, AW_pos height, ED4_manager *parent);
2014
2015    DECLARE_DUMP_FOR_LEAFCLASS(ED4_terminal);
2016};
2017
2018struct ED4_text_terminal : public ED4_terminal {
2019    E4B_AVOID_UNNEEDED_CASTS(text_terminal);
2020   
2021    // functions concerning graphic output
2022    virtual ED4_returncode Show(int refresh_all=0, int is_cleared=0);
2023    virtual ED4_returncode draw();
2024
2025    virtual int get_length() const = 0;
2026    virtual void deleted_from_database();
2027
2028    ED4_text_terminal(const ED4_objspec& spec_, GB_CSTR id, AW_pos x, AW_pos y, AW_pos width, AW_pos height, ED4_manager *parent);
2029    virtual ~ED4_text_terminal() {}
2030
2031    DECLARE_DUMP_FOR_BASECLASS(ED4_text_terminal, ED4_terminal);
2032};
2033
2034class ED4_abstract_sequence_terminal : public ED4_text_terminal { // derived from a Noncopyable
2035
2036    PosRange pixel2index(PosRange pixel_range);
2037
2038    E4B_AVOID_UNNEEDED_CASTS(abstract_sequence_terminal);
2039public:
2040    char *species_name; // @@@ wrong place (may be member of ED4_sequence_manager)
2041
2042
2043    ED4_abstract_sequence_terminal(const ED4_objspec& spec_, const char *id, AW_pos x, AW_pos y, AW_pos width, AW_pos height, ED4_manager *parent);
2044    virtual ~ED4_abstract_sequence_terminal();
2045
2046    virtual GB_alignment_type GetAliType() = 0;
2047    virtual int get_length() const { int len; resolve_pointer_to_char_pntr(&len); return len; }
2048
2049    ED4_species_name_terminal *corresponding_species_name_terminal() const {
2050        return get_parent(ED4_L_SPECIES)->search_spec_child_rek(ED4_L_SPECIES_NAME)->to_species_name_terminal();
2051    }
2052    PosRange calc_interval_displayed_in_rectangle(AW_screen_area *area_rect);
2053    PosRange calc_update_interval();
2054
2055    DECLARE_DUMP_FOR_BASECLASS(ED4_abstract_sequence_terminal, ED4_text_terminal);
2056};
2057
2058class ED4_orf_terminal : public ED4_abstract_sequence_terminal { // derived from a Noncopyable
2059    // NOTE: ED4_orf_terminal is a separate terminal class used to display Open Reading Frames (ORFs)
2060    //       for the corresponding gene (DNA) sequence. It is used in ProteinViewer Module and should not be
2061    //       used for drawing aminoacid sequence alone as in protein alignment. Aminoacid sequences are
2062    //       handled by the standard "ED4_sequence_terminal" class.
2063
2064    char *aaSequence;
2065    size_t aaSeqLen;
2066    char *aaColor;
2067    int   aaStartPos;
2068    int   aaStrandType;
2069
2070    virtual ED4_returncode draw();
2071    E4B_AVOID_UNNEEDED_CASTS(orf_terminal);
2072public:
2073    ED4_orf_terminal(const char *id, AW_pos x, AW_pos y, AW_pos width, AW_pos height, ED4_manager *parent);
2074    virtual ~ED4_orf_terminal();
2075
2076    virtual GB_alignment_type GetAliType();
2077
2078    void SET_aaSeqFlags (int startPos, int strandType) { aaStartPos = startPos; aaStrandType = strandType; }
2079    void SET_aaSequence(const char *aaSeq) { freedup(aaSequence, aaSeq); aaSeqLen = strlen(aaSequence); }
2080    void SET_aaColor(const char *aaSeq) { freedup(aaColor, aaSeq); }
2081
2082    int GET_aaStartPos () { return aaStartPos; }
2083    int GET_aaStrandType () { return aaStrandType; }
2084
2085    DECLARE_DUMP_FOR_LEAFCLASS(ED4_abstract_sequence_terminal);
2086};
2087
2088class ED4_sequence_terminal : public ED4_abstract_sequence_terminal { // derived from a Noncopyable
2089    mutable ED4_SearchResults searchResults;
2090    bool shall_display_secstruct_info; // helix or protstruct
2091
2092    virtual ED4_returncode draw();
2093
2094    E4B_AVOID_UNNEEDED_CASTS(sequence_terminal);
2095   
2096public:
2097
2098    AP_tree *st_ml_node;
2099
2100    ED4_sequence_terminal(const char *id, AW_pos x, AW_pos y, AW_pos width, AW_pos height, ED4_manager *parent, bool shall_display_secstruct_info_);
2101
2102    virtual GB_alignment_type GetAliType();
2103
2104    virtual void deleted_from_database();
2105    virtual int get_length() const { return ED4_abstract_sequence_terminal::get_length(); }
2106
2107    void set_secstruct_display(bool show) { shall_display_secstruct_info = show; }
2108
2109    ED4_SearchResults& results() const { return searchResults; }
2110
2111    ED4_columnStat_terminal *corresponding_columnStat_terminal() const {
2112        ED4_base *col_term = get_parent(ED4_L_MULTI_SEQUENCE)->search_spec_child_rek(ED4_L_COL_STAT);
2113        return col_term ? col_term->to_columnStat_terminal() : 0;
2114    }
2115
2116    DECLARE_DUMP_FOR_MIDCLASS(ED4_sequence_terminal,ED4_abstract_sequence_terminal);
2117};
2118
2119class ED4_columnStat_terminal : public ED4_text_terminal { // derived from a Noncopyable
2120    char *likelihood[4];        // likelihood-array for each base (ACGU) [length of array = alignment_length]
2121    int   latest_update;
2122
2123    static double threshold;
2124
2125    int update_likelihood();
2126
2127    E4B_AVOID_UNNEEDED_CASTS(columnStat_terminal);
2128
2129public:
2130    // functions concerning graphic output
2131    virtual ED4_returncode Show(int refresh_all=0, int is_cleared=0);
2132    virtual ED4_returncode draw();
2133    virtual int get_length() const { return corresponding_sequence_terminal()->get_length(); }
2134
2135    static int threshold_is_set();
2136    static void set_threshold(double aThreshold);
2137    static double get_threshold() { return threshold; }
2138
2139    ED4_sequence_terminal *corresponding_sequence_terminal() const { return get_parent(ED4_L_MULTI_SEQUENCE)->search_spec_child_rek(ED4_L_SEQUENCE_STRING)->to_sequence_terminal(); }
2140
2141    GB_CSTR build_probe_match_string(PosRange range) const;
2142
2143    ED4_columnStat_terminal(GB_CSTR id, AW_pos x, AW_pos y, AW_pos width, AW_pos height, ED4_manager *parent);
2144    ~ED4_columnStat_terminal();
2145
2146    DECLARE_DUMP_FOR_LEAFCLASS(ED4_text_terminal);
2147};
2148
2149struct ED4_species_name_terminal : public ED4_text_terminal { // derived from a Noncopyable
2150    ED4_species_name_terminal(GB_CSTR id, AW_pos x, AW_pos y, AW_pos width, AW_pos height, ED4_manager *parent);
2151    ~ED4_species_name_terminal() { delete selection_info; }
2152
2153    E4B_AVOID_UNNEEDED_CASTS(species_name_terminal);
2154
2155    ED4_selection_entry *selection_info;            // Info about i.e. Position
2156    bool dragged;
2157
2158    GB_CSTR get_displayed_text() const;
2159    virtual int get_length() const { return strlen(get_displayed_text()); }
2160
2161    ED4_sequence_terminal *corresponding_sequence_terminal() const {
2162        ED4_base *seq_term = get_parent(ED4_L_SPECIES)->search_spec_child_rek(ED4_L_SEQUENCE_STRING);
2163        return seq_term ? seq_term->to_sequence_terminal() : 0;
2164    }
2165
2166    DECLARE_DUMP_FOR_LEAFCLASS(ED4_text_terminal);
2167};
2168
2169struct ED4_sequence_info_terminal : public ED4_text_terminal {
2170    E4B_AVOID_UNNEEDED_CASTS(sequence_info_terminal);
2171   
2172    ED4_sequence_info_terminal(const char *id, /* GBDATA *gbd, */ AW_pos x, AW_pos y, AW_pos width, AW_pos height, ED4_manager *parent);
2173
2174    ED4_species_name_terminal *corresponding_species_name_terminal() const {
2175        return get_parent(ED4_L_SPECIES)->search_spec_child_rek(ED4_L_SPECIES_NAME)->to_species_name_terminal();
2176    }
2177
2178    virtual ED4_returncode draw();
2179
2180    GBDATA *data() { return get_species_pointer(); } // DB-entry ("ali_xxx/data")
2181    const GBDATA *data() const { return get_species_pointer(); }
2182
2183    virtual int get_length() const { return 1+strlen(id); }
2184
2185    DECLARE_DUMP_FOR_LEAFCLASS(ED4_text_terminal);
2186};
2187
2188struct ED4_pure_text_terminal : public ED4_text_terminal {
2189    E4B_AVOID_UNNEEDED_CASTS(pure_text_terminal);
2190   
2191    ED4_pure_text_terminal(const char *id, AW_pos x, AW_pos y, AW_pos width, AW_pos height, ED4_manager *parent);
2192
2193    virtual int get_length() const { int len; resolve_pointer_to_char_pntr(&len); return len; }
2194
2195    DECLARE_DUMP_FOR_LEAFCLASS(ED4_text_terminal);
2196};
2197
2198class ED4_consensus_sequence_terminal : public ED4_sequence_terminal {
2199    E4B_AVOID_UNNEEDED_CASTS(consensus_sequence_terminal);
2200   
2201    virtual ED4_returncode draw();
2202    ED4_char_table& get_char_table() const { return get_parent(ED4_L_GROUP)->to_group_manager()->table(); }
2203public:
2204    ED4_consensus_sequence_terminal(const char *id, AW_pos x, AW_pos y, AW_pos width, AW_pos height, ED4_manager *parent);
2205
2206    virtual int get_length() const;
2207
2208    DECLARE_DUMP_FOR_LEAFCLASS(ED4_sequence_terminal);
2209};
2210
2211class ED4_spacer_terminal : public ED4_terminal {
2212    E4B_AVOID_UNNEEDED_CASTS(spacer_terminal);
2213    bool shallDraw; // true -> spacer is really drawn (otherwise it's only a placeholder)
2214
2215public:
2216    virtual ED4_returncode Show(int refresh_all=0, int is_cleared=0);
2217    virtual ED4_returncode draw();
2218
2219    ED4_spacer_terminal(const char *id, bool shallDraw_, AW_pos x, AW_pos y, AW_pos width, AW_pos height, ED4_manager *parent);
2220
2221    DECLARE_DUMP_FOR_LEAFCLASS(ED4_terminal);
2222};
2223
2224struct ED4_line_terminal : public ED4_terminal {
2225    E4B_AVOID_UNNEEDED_CASTS(line_terminal);
2226   
2227    virtual ED4_returncode Show(int refresh_all=0, int is_cleared=0);
2228    virtual ED4_returncode draw();
2229
2230    ED4_line_terminal(const char *id, AW_pos x, AW_pos y, AW_pos width, AW_pos height, ED4_manager *parent);
2231
2232    DECLARE_DUMP_FOR_LEAFCLASS(ED4_terminal);
2233};
2234
2235
2236// ----------------------------------------------
2237//      inlines which need complete classdefs
2238
2239inline void ED4_base::set_update() { // @@@ rename into request_update
2240    if (!update_info.update_requested) {
2241        update_info.update_requested = 1;
2242        if (parent) parent->update_requested_by_child();
2243    }
2244}
2245
2246inline void ED4_base::request_resize() {
2247    update_info.set_resize(1);
2248    if (parent) parent->resize_requested_by_child();
2249}
2250
2251void ED4_manager::resize_requested_by_child() { 
2252    if (!update_info.resize) request_resize();
2253}
2254
2255
2256inline bool ED4_terminal::setCursorTo(ED4_cursor *cursor, int seq_pos, bool unfoldGroups, ED4_CursorJumpType jump_type) {
2257    ED4_species_manager *sm = get_parent(ED4_L_SPECIES)->to_species_manager();
2258    return sm->setCursorTo(cursor, seq_pos, unfoldGroups, jump_type);
2259}
2260
2261E4B_IMPL_CASTOP(area_manager);           // to_area_manager
2262E4B_IMPL_CASTOP(abstract_group_manager); // to_abstract_group_manager
2263E4B_IMPL_CASTOP(bracket_terminal);       // to_bracket_terminal
2264E4B_IMPL_CASTOP(columnStat_terminal);    // to_columnStat_terminal
2265E4B_IMPL_CASTOP(device_manager);         // to_device_manager
2266E4B_IMPL_CASTOP(group_manager);          // to_group_manager
2267E4B_IMPL_CASTOP(line_terminal);          // to_line_terminal
2268E4B_IMPL_CASTOP(manager);                // to_manager
2269E4B_IMPL_CASTOP(multi_name_manager);     // to_multi_name_manager
2270E4B_IMPL_CASTOP(multi_sequence_manager); // to_multi_sequence_manager
2271E4B_IMPL_CASTOP(multi_species_manager);  // to_multi_species_manager
2272E4B_IMPL_CASTOP(name_manager);           // to_name_manager
2273E4B_IMPL_CASTOP(orf_terminal);           // to_orf_terminal
2274E4B_IMPL_CASTOP(pure_text_terminal);     // to_pure_text_terminal
2275E4B_IMPL_CASTOP(root_group_manager);     // to_root_group_manager
2276E4B_IMPL_CASTOP(sequence_info_terminal); // to_sequence_info_terminal
2277E4B_IMPL_CASTOP(sequence_manager);       // to_sequence_manager
2278E4B_IMPL_CASTOP(sequence_terminal);      // to_sequence_terminal
2279E4B_IMPL_CASTOP(spacer_terminal);        // to_spacer_terminal
2280E4B_IMPL_CASTOP(species_manager);        // to_species_manager
2281E4B_IMPL_CASTOP(species_name_terminal);  // to_species_name_terminal
2282E4B_IMPL_CASTOP(terminal);               // to_terminal
2283E4B_IMPL_CASTOP(text_terminal);          // to_text_terminal
2284
2285inline ED4_device_manager *ED4_root::get_device_manager() {
2286    return main_manager->search_spec_child_rek(ED4_L_DEVICE)->to_device_manager();
2287}
2288
2289inline ED4_species_name_terminal *ED4_multi_species_manager::get_consensus_name_terminal() const { 
2290    ED4_species_manager *consensus_man = get_consensus_manager();
2291    return consensus_man ? consensus_man->get_name_terminal() : NULL;
2292}
2293
2294// --------------------------------------------
2295//      Prototype functions without a class
2296
2297extern      ST_ML *st_ml;
2298
2299void ED4_with_all_edit_windows(void (*cb)(ED4_window *));
2300
2301void ED4_expose_recalculations();
2302void ED4_calc_terminal_extentions();
2303
2304void        ED4_input_cb            (AW_window *aww, AW_CL cd1, AW_CL cd2);
2305
2306void ED4_remote_event(AW_event *faked_event);
2307
2308void        ED4_quit(AW_window *aww, AW_CL cd1, AW_CL cd2);
2309
2310void        ED4_motion_cb           (AW_window *aww, AW_CL cd1, AW_CL cd2);
2311void        ED4_vertical_change_cb      (AW_window *aww, AW_CL cd1, AW_CL cd2);
2312void        ED4_horizontal_change_cb    (AW_window *aww, AW_CL cd1, AW_CL cd2);
2313void        ED4_scrollbar_change_cb     (AW_window *aww, AW_CL cd1, AW_CL cd2);
2314
2315void        ED4_no_dangerous_modes      ();
2316void        group_species_cb        (AW_window *aww, AW_CL cd1, AW_CL cd2);
2317AW_window   *ED4_create_group_species_by_field_window(AW_root *aw_root);
2318
2319void ED4_trigger_instant_refresh();
2320void ED4_request_relayout();
2321void ED4_request_full_refresh();
2322void ED4_request_full_instant_refresh();
2323
2324ARB_ERROR   update_terminal_extension(ED4_base *this_object);
2325
2326AW_window   *ED4_start_editor_on_old_configuration  (AW_root *awr);
2327void        ED4_restart_editor          (AW_window *aww, AW_CL, AW_CL);
2328void        ED4_save_configuration          (AW_window *aww, AW_CL close_flag);
2329AW_window   *ED4_save_configuration_as_open_window  (AW_root *awr);
2330
2331void        ED4_set_iupac           (AW_window *aww, char *awar_name, bool callback_flag);
2332void        ED4_set_helixnr         (AW_window *aww, char *awar_name, bool callback_flag);
2333void        ed4_changesecurity      (AW_root *root, AW_CL cd1);
2334void        ed4_change_edit_mode        (AW_root *root, AW_CL cd1);
2335
2336ARB_ERROR rebuild_consensus(ED4_base *object);
2337
2338void ED4_exit() __ATTR__NORETURN;
2339
2340void        ED4_quit_editor         (AW_window *aww, AW_CL cd1, AW_CL cd2);                 // Be Careful: Is this the last window?
2341
2342void        ED4_store_curpos        (AW_window *aww, AW_CL cd1, AW_CL cd2);
2343void        ED4_restore_curpos      (AW_window *aww, AW_CL cd1, AW_CL cd2);
2344void        ED4_clear_stored_curpos     (AW_window *aww, AW_CL cd1, AW_CL cd2);
2345void        ED4_helix_jump_opposite     (AW_window *aww, AW_CL /* cd1 */, AW_CL /* cd2 */);
2346void        ED4_jump_to_cursor_position (AW_window *aww, AW_CL cl_awar_name, AW_CL cl_pos_type);
2347void        ED4_remote_set_cursor_cb    (AW_root *awr, AW_CL, AW_CL);
2348void        ED4_change_cursor       (AW_window * /* aww */, AW_CL /* cd1 */, AW_CL /* cd2 */);
2349void        ED4_set_reference_species   (AW_window *aww, AW_CL cd1, AW_CL cd2);
2350
2351void        ED4_toggle_detailed_column_stats  (AW_window *aww, AW_CL, AW_CL);
2352void        ED4_set_col_stat_threshold  (AW_window *aww, AW_CL, AW_CL);
2353
2354void        ED4_new_editor_window       (AW_window *aww, AW_CL cd1, AW_CL cd2);
2355
2356AW_window   *ED4_create_consensus_definition_window (AW_root *root);
2357void        ED4_create_consensus_awars      (AW_root *aw_root);
2358void        ED4_consensus_definition_changed    (AW_root*, AW_CL, AW_CL);
2359void        ED4_consensus_display_changed       (AW_root*, AW_CL, AW_CL);
2360
2361AW_window   *ED4_create_level_1_options_window  (AW_root *root);
2362void        ED4_compression_toggle_changed_cb   (AW_root *root, AW_CL cd1, AW_CL cd2);
2363
2364AW_window   *ED4_create_new_seq_window      (AW_root *root, AW_CL cl_creation_mode);
2365
2366void ED4_jump_to_current_species     (AW_window *, AW_CL);
2367void ED4_get_and_jump_to_current      (AW_window *, AW_CL);
2368void ED4_get_and_jump_to_current_from_menu    (AW_window *aw, AW_CL cl, AW_CL);
2369void ED4_get_and_jump_to_species     (GB_CSTR species_name);
2370void ED4_get_marked_from_menu        (AW_window *, AW_CL, AW_CL);
2371void ED4_selected_species_changed_cb     (AW_root *aw_root);
2372void ED4_selected_SAI_changed_cb     (AW_root *aw_root);
2373
2374void ED4_init_notFoundMessage();
2375void ED4_finish_and_show_notFoundMessage();
2376
2377ED4_species_name_terminal *ED4_find_species_name_terminal(const char *species_name);
2378ED4_multi_species_manager *ED4_new_species_multi_species_manager();     // returns manager into which new species should be inserted
2379
2380void ED4_compression_changed_cb(AW_root *awr);
2381
2382// functions passed to external c-functions (i.e. as callbacks) have to be declared as 'extern "C"'
2383
2384extern "C" {
2385    void    ED4_alignment_length_changed(GBDATA *gb_alignment_len, int *dummy, GB_CB_TYPE gbtype);
2386}
2387
2388struct AlignDataAccess;
2389void ED4_init_aligner_data_access(AlignDataAccess *data_access);
2390
2391#else
2392#error ed4_class included twice
2393#endif
2394
Note: See TracBrowser for help on using the browser.