source: tags/ms_r17q3/EDIT4/ed4_class.hxx

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