source: tags/ms_r16q3/EDIT4/ed4_class.hxx

Last change on this file was 15288, checked in by westram, 8 years ago
  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 88.8 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  move_requested_by_parent(ED4_move_info *mi)      = 0;
1044    virtual ED4_returncode  event_sent_by_parent(AW_event *event, AW_window *aww);
1045    virtual ED4_returncode  move_requested_by_child(ED4_move_info *moveinfo) = 0;
1046
1047
1048    virtual ED4_returncode  handle_move(ED4_move_info *moveinfo) = 0;
1049
1050    virtual ARB_ERROR route_down_hierarchy(const ED4_route_cb& cb);
1051
1052    int calc_group_depth();
1053
1054    // general purpose functions
1055    virtual ED4_base *search_ID(const char *id) = 0;
1056
1057    void  check_all();
1058    short in_border(AW_pos abs_x, AW_pos abs_y, ED4_movemode mode);
1059    ED4_returncode set_width();
1060
1061
1062    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
1063
1064    ED4_base *get_parent(ED4_level lev) const;
1065    void unlink_from_parent();
1066    bool has_parent(ED4_manager *Parent);
1067    bool is_child_of(ED4_manager *Parent) { return has_parent(Parent); }
1068
1069    virtual char       *resolve_pointer_to_string_copy(int *str_len = 0) const;
1070    virtual const char *resolve_pointer_to_char_pntr(int *str_len = 0) const;
1071
1072    ED4_group_manager  *is_in_folded_group() const;
1073    virtual bool is_hidden() const = 0;
1074
1075    char *get_name_of_species();                      // go from terminal to name of species
1076
1077    // functions which refer to the selected object(s), i.e. across the hierarchy
1078    virtual ED4_base        *get_competent_child(AW_pos x, AW_pos y, ED4_properties relevant_prop)=0;
1079    virtual ED4_base        *get_competent_clicked_child(AW_pos x, AW_pos y, ED4_properties relevant_prop)=0;
1080    virtual ED4_base        *search_spec_child_rek(ED4_level level);    // recursive search for level
1081
1082    ED4_terminal        *get_next_terminal();
1083    ED4_terminal        *get_prev_terminal();
1084
1085    void generate_configuration_string(GBS_strstruct& buffer);
1086
1087    virtual ED4_returncode  remove_callbacks();
1088   
1089    const ED4_terminal *get_consensus_relevant_terminal() const;
1090
1091    ED4_base(const ED4_objspec& spec_, GB_CSTR id, AW_pos width, AW_pos height, ED4_manager *parent);
1092    virtual ~ED4_base();
1093
1094    // use the following functions to test which derived class we have
1095
1096    int is_terminal()               const { e4_assert(knownNonNull(this)); return spec.static_prop & PROP_IS_TERMINAL; }
1097
1098    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); }
1099
1100    int is_species_name_terminal()  const { e4_assert(knownNonNull(this)); return spec.level & LEV_SPECIES_NAME; }
1101
1102    int is_sequence_info_terminal() const { e4_assert(knownNonNull(this)); return spec.level & LEV_SEQUENCE_INFO; }
1103    int is_sequence_terminal()      const { e4_assert(knownNonNull(this)); return spec.level & LEV_SEQUENCE_STRING; }
1104    int is_orf_terminal()           const { e4_assert(knownNonNull(this)); return spec.level & LEV_ORF; }
1105
1106    int is_pure_text_terminal()     const { e4_assert(knownNonNull(this)); return spec.level & LEV_PURE_TEXT; }
1107    int is_columnStat_terminal()    const { e4_assert(knownNonNull(this)); return spec.level & LEV_COL_STAT; }
1108
1109    int is_bracket_terminal()       const { e4_assert(knownNonNull(this)); return spec.level & LEV_BRACKET; }
1110    int is_spacer_terminal()        const { e4_assert(knownNonNull(this)); return spec.level & LEV_SPACER; }
1111    int is_line_terminal()          const { e4_assert(knownNonNull(this)); return spec.level & LEV_LINE; }
1112
1113    int is_flag_header_terminal()   const { e4_assert(knownNonNull(this)); return spec.level & LEV_FLAG_HEADER; }
1114    int is_flag_terminal()          const { e4_assert(knownNonNull(this)); return spec.level & LEV_FLAG; }
1115
1116    int is_manager()                const { e4_assert(knownNonNull(this)); return spec.static_prop & PROP_IS_MANAGER; }
1117
1118    int is_sequence_manager()       const { e4_assert(knownNonNull(this)); return spec.level & LEV_SEQUENCE; }
1119    int is_multi_name_manager()     const { e4_assert(knownNonNull(this)); return spec.level & LEV_MULTI_NAME; }
1120    int is_name_manager()           const { e4_assert(knownNonNull(this)); return spec.level & LEV_NAME_MANAGER; }
1121    int is_multi_species_manager()  const { e4_assert(knownNonNull(this)); return spec.level & LEV_MULTI_SPECIES; }
1122    int is_multi_sequence_manager() const { e4_assert(knownNonNull(this)); return spec.level & LEV_MULTI_SEQUENCE; }
1123    int is_device_manager()         const { e4_assert(knownNonNull(this)); return spec.level & LEV_DEVICE; }
1124
1125    int is_group_manager()          const { e4_assert(knownNonNull(this)); return spec.level & LEV_GROUP; }
1126    int is_root_group_manager()     const { e4_assert(knownNonNull(this)); return spec.level & LEV_ROOTGROUP; }
1127    int is_abstract_group_manager() const { e4_assert(knownNonNull(this)); return spec.level & (LEV_GROUP|LEV_ROOTGROUP); }
1128   
1129    int is_species_manager()        const { e4_assert(knownNonNull(this)); return spec.level & LEV_SPECIES; }
1130    int is_area_manager()           const { e4_assert(knownNonNull(this)); return spec.level & LEV_AREA; }
1131
1132    // use the following functions to cast ED4_base to derived classes:
1133
1134#define E4B_DECL_CASTOP_helper(Class,toName)            \
1135    inline const Class *toName() const;                 \
1136    inline Class *toName();
1137   
1138#define E4B_AVOID_CAST__helper(Class,toName,isName)     \
1139    const Class *toName() const;                        \
1140    Class *toName();                                    \
1141    int isName() const;
1142
1143#define E4B_IMPL_CASTOP_helper(Class,toName,isName)                             \
1144    const Class *ED4_base::toName() const {                                     \
1145        e4_assert(isName());                                                    \
1146        return DOWNCAST(const Class*, this);                                    \
1147    }                                                                           \
1148    Class *ED4_base::toName() {                                                 \
1149        return const_cast<Class*>(const_cast<const ED4_base*>(this)->toName()); \
1150    }
1151
1152#define E4B_DECL_CASTOP(name)          E4B_DECL_CASTOP_helper(concat(ED4_,name), concat(to_,name))
1153#define E4B_AVOID_UNNEEDED_CASTS(name) E4B_AVOID_CAST__helper(concat(ED4_,name), concat(to_,name), concat(is_,name))
1154#define E4B_IMPL_CASTOP(name)          E4B_IMPL_CASTOP_helper(concat(ED4_,name), concat(to_,name), concat(is_,name))
1155
1156    E4B_DECL_CASTOP(area_manager);                // to_area_manager
1157    E4B_DECL_CASTOP(abstract_group_manager);      // to_abstract_group_manager
1158    E4B_DECL_CASTOP(bracket_terminal);            // to_bracket_terminal
1159    E4B_DECL_CASTOP(columnStat_terminal);         // to_columnStat_terminal
1160    E4B_DECL_CASTOP(consensus_sequence_terminal); // to_consensus_sequence_terminal
1161    E4B_DECL_CASTOP(device_manager);              // to_device_manager
1162    E4B_DECL_CASTOP(group_manager);               // to_group_manager
1163    E4B_DECL_CASTOP(line_terminal);               // to_line_terminal
1164    E4B_DECL_CASTOP(manager);                     // to_manager
1165    E4B_DECL_CASTOP(multi_name_manager);          // to_multi_name_manager
1166    E4B_DECL_CASTOP(multi_sequence_manager);      // to_multi_sequence_manager
1167    E4B_DECL_CASTOP(multi_species_manager);       // to_multi_species_manager
1168    E4B_DECL_CASTOP(name_manager);                // to_name_manager
1169    E4B_DECL_CASTOP(orf_terminal);                // to_orf_terminal
1170    E4B_DECL_CASTOP(pure_text_terminal);          // to_pure_text_terminal
1171    E4B_DECL_CASTOP(root_group_manager);          // to_root_group_manager
1172    E4B_DECL_CASTOP(sequence_info_terminal);      // to_sequence_info_terminal
1173    E4B_DECL_CASTOP(sequence_manager);            // to_sequence_manager
1174    E4B_DECL_CASTOP(sequence_terminal);           // to_sequence_terminal
1175    E4B_DECL_CASTOP(spacer_terminal);             // to_spacer_terminal
1176    E4B_DECL_CASTOP(species_manager);             // to_species_manager
1177    E4B_DECL_CASTOP(species_name_terminal);       // to_species_name_terminal
1178    E4B_DECL_CASTOP(terminal);                    // to_terminal
1179    E4B_DECL_CASTOP(text_terminal);               // to_text_terminal
1180    E4B_DECL_CASTOP(flag_header_terminal);        // to_flag_header_terminal
1181    E4B_DECL_CASTOP(flag_terminal);               // to_flag_terminal
1182
1183    // simple access to containing managers
1184    inline ED4_species_manager *containing_species_manager() const;
1185
1186    // discriminate between different sequence managers:
1187
1188    inline bool is_consensus_manager() const;
1189    inline bool is_SAI_manager() const;
1190    inline bool is_species_seq_manager() const;
1191
1192    inline ED4_species_type get_species_type() const; // works for all items (recursively) contained in ED4_species_manager
1193
1194    inline bool inside_consensus_manager() const;
1195    inline bool inside_SAI_manager() const;
1196    inline bool inside_species_seq_manager() const;
1197
1198    inline bool is_consensus_terminal() const;
1199    inline bool is_SAI_terminal() const;
1200    inline bool is_species_seq_terminal() const;
1201
1202    inline bool is_consensus_sequence_terminal() const { // alias for CASTOP
1203        return is_consensus_terminal();
1204    }
1205};
1206
1207DECLARE_CBTYPE_FVV_AND_BUILDERS(ED4_basePredicate, bool, ED4_base*); // generates makeED4_basePredicate
1208
1209class ED4_manager : public ED4_base, public ED4_container { // derived from a Noncopyable
1210    ED4_cb_list<ED4_manager, ED4_managerCallback> delete_cbs;
1211public:
1212
1213    E4B_AVOID_UNNEEDED_CASTS(manager);
1214    DECLARE_DUMP_FOR_BASECLASS(ED4_manager, ED4_base);
1215
1216    void add_delete_callback(const ED4_managerCallback& cb) { delete_cbs.add_cb(cb); }
1217    void remove_delete_callback(const ED4_managerCallback& cb) { delete_cbs.remove_cb(cb); }
1218
1219    int refresh_flag_ok();
1220
1221    void changed_by_database() OVERRIDE;
1222    void deleted_from_database() OVERRIDE;
1223
1224    // functions concerned with graphics
1225    void Show(bool refresh_all, bool is_cleared) OVERRIDE;
1226    bool calc_bounding_box() OVERRIDE;
1227
1228    ED4_returncode distribute_children();
1229
1230    // top-down functions, means travelling down the hierarchy
1231    ED4_returncode event_sent_by_parent(AW_event *event, AW_window *aww) OVERRIDE;
1232
1233    void request_refresh(int clear=1) OVERRIDE;
1234    ED4_returncode clear_refresh();
1235
1236    void resize_requested_children() OVERRIDE;
1237
1238    void update_requested_children() OVERRIDE;
1239
1240    void delete_requested_children() OVERRIDE;
1241    void Delete() OVERRIDE;
1242
1243    ED4_returncode  move_requested_by_parent(ED4_move_info *mi) OVERRIDE;
1244
1245    void create_consensus(ED4_abstract_group_manager *upper_group_manager, arb_progress *progress);
1246
1247    ARB_ERROR route_down_hierarchy(const ED4_route_cb& cb) OVERRIDE;
1248
1249    ED4_base *find_first_that(ED4_level level, const ED4_basePredicate& fulfills_predicate);
1250
1251     // bottom-up functions
1252    ED4_returncode  move_requested_by_child(ED4_move_info *moveinfo) OVERRIDE;
1253    inline void resize_requested_by_child();
1254    ED4_returncode  refresh_requested_by_child();
1255    void delete_requested_by_child();
1256    void update_requested_by_child();
1257   
1258    ED4_base *get_defined_level(ED4_level lev) const;
1259
1260    // functions referring the consensus
1261
1262    void update_consensus(ED4_manager *old_parent, ED4_manager *new_parent, ED4_base *sequence);
1263    ED4_returncode rebuild_consensi(ED4_base *start_species, ED4_update_flag update_flag);
1264
1265    ED4_returncode  check_in_bases(ED4_base *added_base);
1266    ED4_returncode  check_out_bases(ED4_base *subbed_base);
1267
1268    ED4_returncode  update_bases(const ED4_base *old_base, const ED4_base *new_base, PosRange range = PosRange::whole());
1269    ED4_returncode  update_bases(const char *old_seq, int old_len, const char *new_seq, int new_len, PosRange range = PosRange::whole());
1270    ED4_returncode  update_bases(const char *old_seq, int old_len, const ED4_base *new_base, PosRange range = PosRange::whole());
1271    ED4_returncode  update_bases(const BaseFrequencies *old_table, const BaseFrequencies *new_table, PosRange range = PosRange::whole());
1272
1273    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());
1274
1275    // handle moves across the hierarchy
1276    ED4_returncode  handle_move(ED4_move_info *moveinfo) OVERRIDE;
1277
1278    ED4_base *get_competent_child(AW_pos x, AW_pos y, ED4_properties relevant_prop) OVERRIDE;
1279    ED4_base *get_competent_clicked_child(AW_pos x, AW_pos y, ED4_properties relevant_prop) OVERRIDE;
1280    ED4_base *search_spec_child_rek(ED4_level level) OVERRIDE;           // recursive search for level
1281
1282    // general purpose functions
1283    ED4_base        *search_ID(const char *id) OVERRIDE;
1284    ED4_returncode  remove_callbacks() OVERRIDE;
1285
1286    ED4_terminal *get_first_terminal(int start_index=0) const;
1287    ED4_terminal *get_last_terminal(int start_index=-1) const;
1288
1289    void hide_children();
1290    void unhide_children();
1291
1292    bool is_hidden() const OVERRIDE {
1293        if (flag.hidden) return true;
1294        if (!parent) return false;
1295        return parent->is_hidden();
1296    }
1297
1298    ED4_manager(const ED4_objspec& spec_, const char *id, AW_pos width, AW_pos height, ED4_manager *parent);
1299    ~ED4_manager() OVERRIDE;
1300};
1301
1302class ED4_terminal : public ED4_base { // derived from a Noncopyable
1303    E4B_AVOID_UNNEEDED_CASTS(terminal);
1304
1305public:
1306
1307    struct { unsigned int deleted : 1; } tflag; // @@@ go bool
1308
1309    long curr_timestamp;
1310
1311    DECLARE_DUMP_FOR_BASECLASS(ED4_terminal,ED4_base);
1312
1313    // callbacks
1314
1315    void changed_by_database() OVERRIDE;
1316    void deleted_from_database() OVERRIDE;
1317
1318    // functions concerning graphic output
1319    void Show(bool refresh_all, bool is_cleared) OVERRIDE;
1320    virtual void draw() = 0;
1321
1322    bool calc_bounding_box() OVERRIDE;
1323
1324    ED4_returncode draw_drag_box(AW_pos x, AW_pos y, GB_CSTR text = NULL, int cursor_y=-1);
1325
1326    // functions which concern the object as a child
1327    void request_refresh(int clear=1) OVERRIDE;
1328
1329    void resize_requested_children() OVERRIDE;
1330
1331    void update_requested_children() OVERRIDE;
1332    void delete_requested_children() OVERRIDE;
1333    void Delete() OVERRIDE;
1334
1335    ED4_returncode  move_requested_by_parent(ED4_move_info *mi) OVERRIDE;
1336    ED4_returncode  event_sent_by_parent(AW_event *event, AW_window *aww) OVERRIDE;
1337    ED4_base *get_competent_child(AW_pos x, AW_pos y, ED4_properties relevant_prop) OVERRIDE;
1338    ED4_base *get_competent_clicked_child(AW_pos x, AW_pos y, ED4_properties relevant_prop) OVERRIDE;
1339    ED4_returncode  move_requested_by_child(ED4_move_info *moveinfo) OVERRIDE;
1340    ED4_returncode  handle_move(ED4_move_info *moveinfo) OVERRIDE;
1341
1342    ED4_returncode kill_object();
1343
1344    // general purpose functions
1345    ED4_base *search_ID(const char *id) OVERRIDE;
1346    char          *resolve_pointer_to_string_copy(int *str_len = 0) const OVERRIDE;
1347    const char    *resolve_pointer_to_char_pntr(int *str_len = 0) const OVERRIDE;
1348    ED4_returncode remove_callbacks() OVERRIDE;
1349
1350    GB_ERROR write_sequence(const char *seq, int seq_len);
1351
1352    void scroll_into_view(ED4_window *ed4w);
1353    inline bool setCursorTo(ED4_cursor *cursor, int seq_pos, bool unfoldGroups, ED4_CursorJumpType jump_type);
1354
1355    bool is_hidden() const OVERRIDE { return parent && parent->is_hidden(); }
1356
1357    ED4_terminal(const ED4_objspec& spec_, GB_CSTR id, AW_pos width, AW_pos height, ED4_manager *parent);
1358    ~ED4_terminal() OVERRIDE;
1359};
1360
1361enum ED4_species_mode {
1362    ED4_SM_MOVE,
1363    ED4_SM_KILL,
1364    ED4_SM_MARK,
1365    ED4_SM_INFO // same functionality as AWT_MODE_INFO
1366};
1367
1368class ED4_reference_terminals : virtual Noncopyable {
1369    ED4_sequence_info_terminal *ref_sequence_info;
1370    ED4_sequence_terminal      *ref_sequence;
1371    ED4_sequence_info_terminal *ref_column_stat_info;
1372    ED4_columnStat_terminal    *ref_column_stat;
1373
1374    void null() { ref_sequence_info = 0; ref_sequence = 0; ref_column_stat = 0; ref_column_stat_info = 0; }
1375public:
1376    void clear();
1377    void init(ED4_sequence_info_terminal *, ED4_sequence_terminal *, ED4_sequence_info_terminal *, ED4_columnStat_terminal *);
1378
1379    ED4_sequence_terminal      *sequence()         { return ref_sequence; }
1380    ED4_sequence_info_terminal *sequence_info()    { return ref_sequence_info; }
1381    ED4_columnStat_terminal    *column_stat()      { return ref_column_stat; }
1382    ED4_sequence_info_terminal *column_stat_info() { return ref_column_stat_info; }
1383
1384    ED4_reference_terminals()  { null(); }
1385    ~ED4_reference_terminals() { clear(); }
1386};
1387
1388class ED4_WinContext {
1389    ED4_window *ed4w;
1390    AW_device  *device;
1391
1392    bool is_set() const { return ed4w; }
1393    void init(ED4_window *ew) {
1394        e4_assert(ew);
1395        ed4w   = ew;
1396        device = ed4w->get_device();
1397    }
1398
1399    void warn_missing_context() const;
1400    void expect_context() const { if (!is_set()) warn_missing_context(); }
1401
1402protected:
1403    ED4_WinContext() : ed4w(0), device(0) {}
1404    static ED4_WinContext current_context;
1405   
1406public:
1407    inline ED4_WinContext(AW_window *aww_);
1408    ED4_WinContext(ED4_window *ed4w_) { init(ed4w_); }
1409
1410    AW_device *get_device() const { expect_context(); return device; }
1411    ED4_window *get_ed4w() const { expect_context(); return ed4w; }
1412
1413    static const ED4_WinContext& get_current_context() { return current_context; }
1414    static bool have_context() { return current_context.is_set(); }
1415};
1416
1417// accessors for current context (see also ED4_WinContextFree)
1418inline AW_device *current_device() { return ED4_WinContext::get_current_context().get_device(); }
1419inline ED4_window *current_ed4w() { return ED4_WinContext::get_current_context().get_ed4w(); }
1420inline AW_window *current_aww() { return current_ed4w()->aww; }
1421inline ED4_cursor& current_cursor() { return current_ed4w()->cursor; }
1422
1423enum LoadableSaiState {
1424    LSAI_UNUSED,
1425    LSAI_UPTODATE,
1426    LSAI_OUTDATED,
1427};
1428
1429class ED4_root : virtual Noncopyable {
1430    void ED4_ROOT() const { e4_assert(0); } // avoid ED4_root-members use global ED4_ROOT
1431
1432    void refresh_window_simple(bool redraw);
1433    void handle_update_requests(bool& redraw);
1434
1435    ED4_window           *most_recently_used_window;
1436    ConsensusBuildParams *cons_param;
1437
1438public:
1439    char       *db_name;                            // name of Default Properties database (complete path)
1440    AW_root    *aw_root;                            // Points to 'AW-Window-Controller'
1441    AW_default  props_db;                           // Default Properties database
1442
1443    ED4_window              *first_window;          // Points to List of Main Windows of ED4
1444    ED4_main_manager        *main_manager;          // Points to Main manager of ED4
1445    ED4_area_manager        *middle_area_man;       // Points to middle area
1446    ED4_area_manager        *top_area_man;
1447    ED4_root_group_manager  *root_group_man;
1448    EDB_root_bact           *database;              // Points to Object which controls Data
1449    ED4_selected_list       *selected_objects;
1450    ED4_scroll_links         scroll_links;
1451    bool                     folding_action;        // flag tells whether action was folding action or not
1452    ED4_reference_terminals  ref_terminals;
1453    ED4_species_mode         species_mode;
1454    ED4_scroll_picture       scroll_picture;
1455    BI_ecoli_ref            *ecoli_ref;
1456    char                    *alignment_name;
1457    GB_alignment_type        alignment_type;
1458    ED4_reference           *reference;
1459    ED4_seq_colors          *sequence_colors;
1460    AW_gc_manager           *gc_manager;
1461    ST_ML                   *st_ml;
1462    AW_helix                *helix;
1463    int                      helix_spacing;
1464    long                     helix_add_spacing;
1465    long                     terminal_add_spacing;
1466    char                    *protstruct;            // protein structure summary
1467    long                     protstruct_len;        // protein structure summary
1468    ed_key                  *edk;
1469    ED4_Edit_String         *edit_string;
1470
1471    bool column_stat_activated;
1472    bool column_stat_initialized;
1473    bool visualizeSAI;
1474    bool visualizeSAI_allSpecies;
1475
1476    const ConsensusBuildParams& get_consensus_params();
1477    void reset_consensus_params();
1478
1479    LoadableSaiState loadable_SAIs; // maintain proper refresh of list of loadable SAIs
1480    void loadable_SAIs_may_have_changed() { if (loadable_SAIs == LSAI_UPTODATE) loadable_SAIs = LSAI_OUTDATED; }
1481
1482    int temp_gc;
1483    AW_font_group font_group;
1484
1485    void announce_useraction_in(AW_window *aww);
1486    ED4_window *get_most_recently_used_window() const {
1487        e4_assert(most_recently_used_window);
1488        return most_recently_used_window;
1489    }
1490
1491    inline ED4_device_manager *get_device_manager();
1492
1493    // Initializing functions
1494    ED4_returncode  create_hierarchy(const char *area_string_middle, const char *area_string_top);
1495    ARB_ERROR init_alignment();
1496    void recalc_font_group();
1497
1498    AW_window *create_first_window();
1499    ED4_returncode generate_window(AW_device **device, ED4_window **new_window);
1500    void copy_window_struct(ED4_window *source,   ED4_window *destination);
1501
1502    // functions concerned with global refresh and resize
1503    void resize_all_requesting_childs();
1504
1505    void special_window_refresh(bool handle_updates);
1506    ED4_returncode refresh_all_windows(bool redraw);
1507
1508    void request_refresh_for_all_terminals();
1509    void request_refresh_for_specific_terminals(ED4_level lev);
1510    void request_refresh_for_consensus_terminals();
1511    void request_refresh_for_sequence_terminals();
1512
1513    inline void announce_deletion(ED4_base *object); // before deleting an object, use this to announce
1514
1515     // functions concerned with list of selected objects
1516    ED4_returncode add_to_selected(ED4_species_name_terminal *object);
1517    void remove_from_selected(ED4_species_name_terminal *object);
1518    ED4_returncode deselect_all();
1519
1520    ED4_returncode get_area_rectangle(AW_screen_area *rect, AW_pos x, AW_pos y);
1521
1522    ED4_index pixel2pos(AW_pos click_x);
1523
1524    void remove_all_callbacks();
1525   
1526    ED4_root(int *argc, char*** argv);
1527    ~ED4_root();
1528};
1529
1530ED4_WinContext::ED4_WinContext(AW_window *aww_) { init(ED4_ROOT->first_window->get_matching_ed4w(aww_)); }
1531
1532struct ED4_LocalWinContext : private ED4_WinContext {
1533    ED4_LocalWinContext(AW_window *aww) : ED4_WinContext(current_context) { current_context = ED4_WinContext(aww); }
1534    ED4_LocalWinContext(ED4_window *ew) : ED4_WinContext(current_context) { current_context = ED4_WinContext(ew); }
1535    ~ED4_LocalWinContext() { current_context = *this; }
1536};
1537
1538class ED4_MostRecentWinContext : virtual Noncopyable { 
1539    ED4_LocalWinContext *most_recent;
1540public:
1541    ED4_MostRecentWinContext() : most_recent(0) {
1542        if (!ED4_WinContext::have_context()) {
1543            most_recent = new ED4_LocalWinContext(ED4_ROOT->get_most_recently_used_window());
1544        }
1545    }
1546    ~ED4_MostRecentWinContext() {
1547        delete most_recent;
1548    }
1549};
1550
1551inline void ED4_root::announce_deletion(ED4_base *object) {
1552    if (object->is_terminal()) {
1553        ED4_terminal *term = object->to_terminal();
1554        for (ED4_window *win = first_window; win; win = win->next) {
1555            ED4_LocalWinContext uses(win);
1556            win->announce_deletion(term);
1557        }
1558    }
1559}
1560
1561// ------------------------
1562//      manager classes
1563//
1564// All manager classes only differ in their static properties.
1565// This kind of construction was chosen for using a minimum of RAM
1566
1567class ED4_main_manager : public ED4_manager { // derived from a Noncopyable
1568    // first in hierarchy
1569
1570    E4B_AVOID_UNNEEDED_CASTS(main_manager);
1571
1572    // these terminals are redrawn after refresh (with increase clipping area)
1573    // to revert text from middle area drawn into top area:
1574    ED4_terminal *top_middle_line;
1575    ED4_terminal *top_middle_spacer;
1576
1577public:
1578    ED4_main_manager(const char *id, AW_pos width, AW_pos height, ED4_manager *parent);
1579
1580    void set_top_middle_spacer_terminal(ED4_terminal *top_middle_spacer_) { top_middle_spacer = top_middle_spacer_; }
1581    void set_top_middle_line_terminal(ED4_terminal *top_middle_line_) { top_middle_line = top_middle_line_; }
1582
1583    ED4_terminal *get_top_middle_spacer_terminal() const { return top_middle_spacer; }
1584    ED4_terminal *get_top_middle_line_terminal() const { return top_middle_line; }
1585
1586    DECLARE_DUMP_FOR_LEAFCLASS(ED4_manager);
1587
1588    void Show(bool refresh_all, bool is_cleared) OVERRIDE;
1589    void resize_requested_children() OVERRIDE;
1590   
1591    void clear_whole_background();
1592};
1593
1594struct ED4_device_manager : public ED4_manager {
1595    E4B_AVOID_UNNEEDED_CASTS(device_manager);
1596    ED4_device_manager  (const char *id, AW_pos width, AW_pos height, ED4_manager *parent);
1597    DECLARE_DUMP_FOR_LEAFCLASS(ED4_manager);
1598};
1599
1600struct ED4_area_manager : public ED4_manager {
1601    E4B_AVOID_UNNEEDED_CASTS(area_manager);
1602    ED4_area_manager(const char *id, AW_pos width, AW_pos height, ED4_manager *parent);
1603    DECLARE_DUMP_FOR_LEAFCLASS(ED4_manager);
1604
1605    ED4_multi_species_manager *get_multi_species_manager() const {
1606        return get_defined_level(LEV_MULTI_SPECIES)->to_multi_species_manager();
1607    }
1608};
1609
1610class ED4_multi_species_manager : public ED4_manager {
1611    E4B_AVOID_UNNEEDED_CASTS(multi_species_manager);
1612
1613    int species;          // # of species (-1 == unknown)
1614    int selected_species; // # of selected species (-1 == unknown)
1615
1616    void    set_species_counters(int no_of_species, int no_of_selected);
1617#ifdef DEBUG
1618    void    count_species(int *speciesPtr, int *selectedPtr) const;
1619#endif
1620    void    update_species_counters();
1621
1622public:
1623    ED4_multi_species_manager(const char *id, AW_pos width, AW_pos height, ED4_manager *parent);
1624
1625    DECLARE_DUMP_FOR_LEAFCLASS(ED4_manager);
1626
1627    void update_requested_children() OVERRIDE;
1628    void delete_requested_children() OVERRIDE;
1629
1630    int count_visible_children();           // is called by a multi_species_manager
1631
1632    ED4_species_manager       *get_consensus_manager() const;       // returns the consensus-manager or NULL
1633    ED4_species_name_terminal *get_consensus_name_terminal() const; // returns the consensus-name-terminal or NULL
1634
1635    // functions concerned with selection
1636    int get_no_of_selected_species();
1637    int get_no_of_species();
1638
1639    void update_group_id();
1640
1641    void invalidate_species_counters();
1642    int  has_valid_counters() const { return species != -1 && selected_species!=-1; }
1643    bool all_are_selected() const { e4_assert(has_valid_counters()); return species == selected_species; }
1644
1645    void select_all(bool only_species);
1646    void deselect_all_species_and_SAI();
1647    void invert_selection_of_all_species();
1648    void marked_species_select(bool select);
1649    void selected_species_mark(bool mark);
1650
1651    void toggle_selected_species();
1652};
1653
1654class ED4_abstract_group_manager : public ED4_manager {
1655    E4B_AVOID_UNNEEDED_CASTS(abstract_group_manager);
1656protected:
1657    BaseFrequencies my_table; // table concerning Consensusfunction
1658
1659public:
1660    ED4_abstract_group_manager(const ED4_objspec& spec_, const char *id, AW_pos width, AW_pos height, ED4_manager *parent);
1661
1662    DECLARE_DUMP_FOR_BASECLASS(ED4_abstract_group_manager, ED4_manager);
1663
1664    BaseFrequencies&       table()       { return my_table; }
1665    const BaseFrequencies& table() const { return my_table; }
1666
1667    ED4_multi_species_manager *get_multi_species_manager() const {
1668        return get_defined_level(LEV_MULTI_SPECIES)->to_multi_species_manager();
1669    }
1670
1671    char *build_consensus_string(PosRange range) const { return table().build_consensus_string(range, ED4_ROOT->get_consensus_params()); }
1672    char *build_consensus_string(int *cons_length = NULL) const {
1673        if (cons_length) *cons_length = table().size();
1674        return table().build_consensus_string(ED4_ROOT->get_consensus_params());
1675    }
1676};
1677
1678struct ED4_group_manager : public ED4_abstract_group_manager {
1679    E4B_AVOID_UNNEEDED_CASTS(group_manager);
1680    ED4_group_manager(const char *id, AW_pos width, AW_pos height, ED4_manager *parent);
1681    DECLARE_DUMP_FOR_LEAFCLASS(ED4_abstract_group_manager);
1682    void reinit_char_table();
1683
1684    void fold();
1685    void unfold();
1686    void toggle_folding();
1687};
1688
1689enum ED4_remap_mode {
1690    ED4_RM_NONE,                                    // no remapping (normal mode)
1691    ED4_RM_SHOW_ABOVE,                              // Show all positions, where xxx% of all edited sequences have any base
1692    ED4_RM_MAX_ALIGN,                               // ------------------------- any edited sequence has a base
1693    ED4_RM_MAX_EDIT,                                // like ED4_RM_MAX_ALIGN, but bases are pushed OVER remapped gaps (not INTO)
1694    ED4_RM_DYNAMIC_GAPS,                            // gaps shown as spaces (more gaps => more spaces)
1695
1696    ED4_RM_MODES
1697
1698};
1699
1700class ED4_remap : virtual Noncopyable {
1701
1702    ED4_remap_mode mode;
1703    int show_above_percent;     // used only for ED4_RM_SHOW_ABOVE
1704
1705    size_t sequence_table_len;      // allocated size of sequence_to_screen_tab
1706    size_t screen_table_len;        // allocated size of screen_to_sequence_tab
1707
1708    size_t sequence_len;        // size of recently compiled part of sequence_to_screen_tab
1709    size_t screen_len;          // size of recently compiled part of screen_to_sequence_tab
1710
1711    int *screen_to_sequence_tab;
1712    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
1713
1714    int changed;            // remap-table changed at last compile
1715    int update_needed;          // remapping should be recompiled
1716
1717    inline void set_sequence_to_screen(int pos, int newVal);
1718
1719public:
1720
1721    ED4_remap();
1722    ~ED4_remap();
1723
1724    int screen_to_sequence(int screen_pos) const;
1725
1726    int sequence_to_screen_PLAIN(int sequence_pos) const { 
1727        e4_assert(sequence_pos>=0 && size_t(sequence_pos)<=sequence_len);
1728        return sequence_to_screen_tab[sequence_pos];
1729    }
1730    int shown_sequence_to_screen(int sequence_pos) const {
1731        // as well works for sequence_pos == MAXSEQUENCECHARACTERLENGTH
1732        int screen_pos = sequence_to_screen_PLAIN(sequence_pos);
1733        e4_assert(screen_pos >= 0); // sequence_pos expected to be visible (i.e. not folded away)
1734        return screen_pos;
1735    }
1736
1737    int clipped_sequence_to_screen_PLAIN(int sequence_pos) const; 
1738    int sequence_to_screen(int sequence_pos) const;
1739
1740    PosRange sequence_to_screen(PosRange range) const {
1741        e4_assert(!range.is_empty());
1742        return PosRange(sequence_to_screen(range.start()), sequence_to_screen(range.end()));
1743    }
1744    PosRange screen_to_sequence(PosRange range) const {
1745        e4_assert(!range.is_empty());
1746        if (range.is_unlimited()) return PosRange::from(screen_to_sequence(range.start()));
1747        return PosRange(screen_to_sequence(range.start()), screen_to_sequence(range.end()));
1748    }
1749
1750    size_t get_max_screen_pos() const { return screen_len-1; }
1751
1752    void adjacent_screen_positions(int seq_pos, int& screen_pos_left, int& screen_pos_right);
1753
1754    ED4_remap_mode get_mode() const { return mode; }
1755    void set_mode(ED4_remap_mode Mode, int above_percent) {
1756        if (Mode<0 || Mode>=ED4_RM_MODES) {
1757            Mode = ED4_RM_NONE;
1758        }
1759        if (mode!=Mode) {
1760            mode = Mode;
1761            update_needed = 1;
1762        }
1763
1764        if (show_above_percent!=above_percent) {
1765            show_above_percent = above_percent;
1766            if (mode==ED4_RM_SHOW_ABOVE) {
1767                update_needed = 1;
1768            }
1769        }
1770    }
1771
1772    void mark_compile_needed();     // recompile if mode != none
1773    void mark_compile_needed_force();   // always recompile
1774    int compile_needed() const { return update_needed; }
1775
1776    GB_ERROR compile(ED4_root_group_manager *gm);
1777    int was_changed() const { return changed; }     // mapping changed by last compile ?
1778
1779    int is_shown(int seq_pos) const {
1780        int scr_pos = sequence_to_screen_PLAIN(seq_pos);
1781        if (scr_pos<0) return false;
1782        if (scr_pos>0) return true;
1783
1784        int seq_pos2    = screen_to_sequence_tab[0];
1785        return seq_pos == seq_pos2;
1786    }
1787
1788    ExplicitRange clip_screen_range(PosRange screen_range) const { return ExplicitRange(screen_range, screen_len-1); }
1789};
1790
1791class ED4_root_group_manager : public ED4_abstract_group_manager {
1792    E4B_AVOID_UNNEEDED_CASTS(root_group_manager);
1793    ED4_remap my_remap;
1794public:
1795    ED4_root_group_manager(const char *id, AW_pos width, AW_pos height, ED4_manager *parent);
1796
1797    bool update_remap(); // 'true' if mapping has changed
1798
1799    const ED4_remap *remap() const { return &my_remap; }
1800    ED4_remap *remap() { return &my_remap; }
1801
1802    void Show(bool refresh_all, bool is_cleared) OVERRIDE;
1803    void resize_requested_children() OVERRIDE;
1804
1805    DECLARE_DUMP_FOR_LEAFCLASS(ED4_abstract_group_manager);
1806};
1807
1808class ED4_species_manager : public ED4_manager {
1809    E4B_AVOID_UNNEEDED_CASTS(species_manager);
1810
1811    ED4_cb_list<ED4_species_manager, ED4_species_managerCallback> changed_cbs; // called when sequence changes
1812
1813    ED4_species_type type;
1814    bool selected;
1815
1816public:
1817    ED4_species_manager(ED4_species_type type_, const char *id, AW_pos width, AW_pos height, ED4_manager *parent);
1818    ~ED4_species_manager() OVERRIDE;
1819
1820    DECLARE_DUMP_FOR_LEAFCLASS(ED4_manager);
1821
1822    ED4_species_type get_type() const { return type; }
1823
1824    bool is_selected() const { return selected; }
1825    void set_selected(bool select) {
1826        // e4_assert(type != ED4_SP_CONSENSUS); // it's not allowed to select a consensus // @@@ happens atm when moving a group
1827        selected = select;
1828    }
1829
1830    bool setCursorTo(ED4_cursor *cursor, int seq_pos, bool unfold_groups, ED4_CursorJumpType jump_type);
1831
1832    void add_sequence_changed_cb(const ED4_species_managerCallback& cb) { changed_cbs.add_cb(cb); }
1833    void remove_sequence_changed_cb(const ED4_species_managerCallback& cb) { changed_cbs.remove_cb(cb); }
1834    void do_callbacks() { changed_cbs.call(this); }
1835
1836    ED4_species_name_terminal *get_name_terminal() const { return member(0)->to_species_name_terminal(); }
1837};
1838
1839inline ED4_species_manager *ED4_base::containing_species_manager() const {
1840    ED4_base *sman = get_parent(LEV_SPECIES);
1841    return sman ? sman->to_species_manager() : NULL;
1842}
1843
1844inline bool ED4_base::is_consensus_manager()    const { return is_species_manager() && to_species_manager()->get_type() == ED4_SP_CONSENSUS; }
1845inline bool ED4_base::is_SAI_manager()          const { return is_species_manager() && to_species_manager()->get_type() == ED4_SP_SAI; }
1846inline bool ED4_base::is_species_seq_manager()  const { return is_species_manager() && to_species_manager()->get_type() == ED4_SP_SPECIES; }
1847
1848inline ED4_species_type ED4_base::get_species_type() const {
1849    ED4_species_manager *sman = containing_species_manager();
1850    return sman ? sman->get_type() : ED4_SP_NONE;
1851}
1852
1853inline bool ED4_base::inside_consensus_manager()   const { return get_species_type() == ED4_SP_CONSENSUS; }
1854inline bool ED4_base::inside_SAI_manager()         const { return get_species_type() == ED4_SP_SAI; }
1855inline bool ED4_base::inside_species_seq_manager() const { return get_species_type() == ED4_SP_SPECIES; }
1856
1857inline bool ED4_base::is_consensus_terminal()   const { return is_sequence_terminal() && inside_consensus_manager(); }
1858inline bool ED4_base::is_SAI_terminal()         const { return is_sequence_terminal() && inside_SAI_manager(); }
1859inline bool ED4_base::is_species_seq_terminal() const { return is_sequence_terminal() && inside_species_seq_manager(); }
1860
1861inline bool ED4_cursor::in_species_seq_terminal() const { return owner_of_cursor && owner_of_cursor->is_species_seq_terminal(); }
1862inline bool ED4_cursor::in_consensus_terminal()   const { return owner_of_cursor && owner_of_cursor->is_consensus_terminal(); }
1863inline bool ED4_cursor::in_SAI_terminal()         const { return owner_of_cursor && owner_of_cursor->is_SAI_terminal(); }
1864
1865
1866struct ED4_multi_sequence_manager : public ED4_manager {
1867    E4B_AVOID_UNNEEDED_CASTS(multi_sequence_manager);
1868    ED4_multi_sequence_manager(const char *id, AW_pos width, AW_pos height, ED4_manager *parent);
1869    DECLARE_DUMP_FOR_LEAFCLASS(ED4_manager);
1870};
1871
1872struct ED4_sequence_manager : public ED4_manager {
1873    E4B_AVOID_UNNEEDED_CASTS(sequence_manager);
1874    ED4_sequence_manager(const char *id, AW_pos width, AW_pos height, ED4_manager *parent);
1875    DECLARE_DUMP_FOR_LEAFCLASS(ED4_manager);
1876};
1877
1878struct ED4_multi_name_manager : public ED4_manager {
1879    E4B_AVOID_UNNEEDED_CASTS(multi_name_manager);
1880    // member of ED4_species_manager (contains ED4_name_manager for name and info)
1881    ED4_multi_name_manager(const char *id, AW_pos width, AW_pos height, ED4_manager *parent);
1882    DECLARE_DUMP_FOR_LEAFCLASS(ED4_manager);
1883};
1884
1885
1886struct ED4_name_manager : public ED4_manager {
1887    E4B_AVOID_UNNEEDED_CASTS(name_manager);
1888    // member of ED4_multi_name_manager (contains speciesname or other info concerning the species)
1889    ED4_name_manager(const char *id, AW_pos width, AW_pos height, ED4_manager *parent);
1890    DECLARE_DUMP_FOR_LEAFCLASS(ED4_manager);
1891};
1892
1893
1894// -------------------------
1895//      terminal classes
1896
1897
1898struct ED4_tree_terminal : public ED4_terminal {
1899    E4B_AVOID_UNNEEDED_CASTS(tree_terminal);
1900   
1901    void draw() OVERRIDE;
1902
1903    ED4_tree_terminal(const char *id, AW_pos width, AW_pos height, ED4_manager *parent);
1904
1905    DECLARE_DUMP_FOR_LEAFCLASS(ED4_terminal);
1906};
1907
1908struct ED4_bracket_terminal : public ED4_terminal {
1909    E4B_AVOID_UNNEEDED_CASTS(bracket_terminal);
1910
1911    void draw() OVERRIDE;
1912
1913    void toggle_folding();
1914
1915    ED4_bracket_terminal(const char *id, AW_pos width, AW_pos height, ED4_manager *parent);
1916
1917    DECLARE_DUMP_FOR_LEAFCLASS(ED4_terminal);
1918};
1919
1920struct ED4_text_terminal : public ED4_terminal {
1921    E4B_AVOID_UNNEEDED_CASTS(text_terminal);
1922   
1923    // functions concerning graphic output
1924    void draw() OVERRIDE;
1925
1926    virtual int get_length() const = 0;
1927    void deleted_from_database() OVERRIDE;
1928
1929    ED4_text_terminal(const ED4_objspec& spec_, GB_CSTR id, AW_pos width, AW_pos height, ED4_manager *parent);
1930    ~ED4_text_terminal() OVERRIDE {}
1931
1932    DECLARE_DUMP_FOR_BASECLASS(ED4_text_terminal, ED4_terminal);
1933};
1934
1935class ED4_abstract_sequence_terminal : public ED4_text_terminal { // derived from a Noncopyable
1936
1937    PosRange pixel2index(PosRange pixel_range);
1938
1939    E4B_AVOID_UNNEEDED_CASTS(abstract_sequence_terminal);
1940public:
1941    char *species_name; // @@@ wrong place (may be member of ED4_sequence_manager)
1942
1943
1944    ED4_abstract_sequence_terminal(const ED4_objspec& spec_, const char *id, AW_pos width, AW_pos height, ED4_manager *parent);
1945    ~ED4_abstract_sequence_terminal() OVERRIDE;
1946
1947    virtual GB_alignment_type GetAliType() = 0;
1948    int get_length() const OVERRIDE { int len; resolve_pointer_to_char_pntr(&len); return len; }
1949
1950    ED4_species_name_terminal *corresponding_species_name_terminal() const {
1951        return get_parent(LEV_SPECIES)->search_spec_child_rek(LEV_SPECIES_NAME)->to_species_name_terminal();
1952    }
1953    PosRange calc_interval_displayed_in_rectangle(AW_screen_area *area_rect);
1954    PosRange calc_update_interval();
1955
1956    DECLARE_DUMP_FOR_BASECLASS(ED4_abstract_sequence_terminal, ED4_text_terminal);
1957};
1958
1959class ED4_orf_terminal : public ED4_abstract_sequence_terminal { // derived from a Noncopyable
1960    // NOTE: ED4_orf_terminal is a separate terminal class used to display Open Reading Frames (ORFs)
1961    //       for the corresponding gene (DNA) sequence. It is used in ProteinViewer Module and should not be
1962    //       used for drawing aminoacid sequence alone as in protein alignment. Aminoacid sequences are
1963    //       handled by the standard "ED4_sequence_terminal" class.
1964
1965    char *aaSequence;
1966    size_t aaSeqLen;
1967    char *aaColor;
1968    int   aaStartPos;
1969    int   aaStrandType;
1970
1971    void draw() OVERRIDE;
1972    E4B_AVOID_UNNEEDED_CASTS(orf_terminal);
1973public:
1974    ED4_orf_terminal(const char *id, AW_pos width, AW_pos height, ED4_manager *parent);
1975    ~ED4_orf_terminal() OVERRIDE;
1976
1977    GB_alignment_type GetAliType() OVERRIDE;
1978
1979    void SET_aaSeqFlags (int startPos, int strandType) { aaStartPos = startPos; aaStrandType = strandType; }
1980    void SET_aaSequence(const char *aaSeq) { freedup(aaSequence, aaSeq); aaSeqLen = strlen(aaSequence); }
1981    void SET_aaColor(const char *aaSeq) { freedup(aaColor, aaSeq); }
1982
1983    int GET_aaStartPos () { return aaStartPos; }
1984    int GET_aaStrandType () { return aaStrandType; }
1985
1986    DECLARE_DUMP_FOR_LEAFCLASS(ED4_abstract_sequence_terminal);
1987};
1988
1989class ED4_sequence_terminal : public ED4_abstract_sequence_terminal { // derived from a Noncopyable
1990    mutable ED4_SearchResults searchResults;
1991    bool shall_display_secstruct_info; // helix or protstruct
1992
1993    void draw() OVERRIDE;
1994
1995    E4B_AVOID_UNNEEDED_CASTS(sequence_terminal);
1996   
1997public:
1998
1999    AP_tree *st_ml_node;
2000
2001    ED4_sequence_terminal(const char *id, AW_pos width, AW_pos height, ED4_manager *parent, bool shall_display_secstruct_info_);
2002
2003    GB_alignment_type GetAliType() OVERRIDE;
2004
2005    void deleted_from_database() OVERRIDE;
2006    int get_length() const OVERRIDE { return ED4_abstract_sequence_terminal::get_length(); }
2007
2008    virtual char *get_sequence_copy(int *str_len = 0) const { return resolve_pointer_to_string_copy(str_len); }
2009
2010    void set_secstruct_display(bool show) { shall_display_secstruct_info = show; }
2011
2012    ED4_SearchResults& results() const { return searchResults; }
2013
2014    ED4_columnStat_terminal *corresponding_columnStat_terminal() const {
2015        ED4_base *col_term = get_parent(LEV_MULTI_SEQUENCE)->search_spec_child_rek(LEV_COL_STAT);
2016        return col_term ? col_term->to_columnStat_terminal() : 0;
2017    }
2018
2019    DECLARE_DUMP_FOR_MIDCLASS(ED4_sequence_terminal,ED4_abstract_sequence_terminal);
2020};
2021
2022class ED4_columnStat_terminal : public ED4_text_terminal { // derived from a Noncopyable
2023    char *likelihood[4];        // likelihood-array for each base (ACGU) [length of array = alignment_length]
2024    int   latest_update;
2025
2026    static double threshold;
2027
2028    int update_likelihood();
2029
2030    E4B_AVOID_UNNEEDED_CASTS(columnStat_terminal);
2031
2032public:
2033    // functions concerning graphic output
2034    void draw() OVERRIDE;
2035    int get_length() const OVERRIDE { return corresponding_sequence_terminal()->get_length(); }
2036
2037    static int threshold_is_set();
2038    static void set_threshold(double aThreshold);
2039    static double get_threshold() { return threshold; }
2040
2041    ED4_sequence_terminal *corresponding_sequence_terminal() const { return get_parent(LEV_MULTI_SEQUENCE)->search_spec_child_rek(LEV_SEQUENCE_STRING)->to_sequence_terminal(); }
2042
2043    ED4_columnStat_terminal(GB_CSTR id, AW_pos width, AW_pos height, ED4_manager *parent);
2044    ~ED4_columnStat_terminal() OVERRIDE;
2045
2046    DECLARE_DUMP_FOR_LEAFCLASS(ED4_text_terminal);
2047};
2048
2049class ED4_species_name_terminal : public ED4_text_terminal { // derived from a Noncopyable
2050    E4B_AVOID_UNNEEDED_CASTS(species_name_terminal);
2051    bool set_dynamic_size() OVERRIDE;
2052
2053public:
2054    ED4_species_name_terminal(GB_CSTR id, AW_pos width, AW_pos height, ED4_manager *parent);
2055    ~ED4_species_name_terminal() OVERRIDE { delete selection_info; }
2056
2057
2058    ED4_selection_entry *selection_info;            // Info about i.e. Position
2059    bool dragged;
2060
2061    GB_CSTR get_displayed_text() const;
2062    int get_length() const OVERRIDE { return strlen(get_displayed_text()); }
2063
2064    ED4_sequence_terminal *corresponding_sequence_terminal() const {
2065        ED4_base *seq_term = get_parent(LEV_SPECIES)->search_spec_child_rek(LEV_SEQUENCE_STRING);
2066        return seq_term ? seq_term->to_sequence_terminal() : 0;
2067    }
2068
2069    DECLARE_DUMP_FOR_LEAFCLASS(ED4_text_terminal);
2070};
2071
2072class ED4_flag_header_terminal : public ED4_text_terminal { // derived from a Noncopyable
2073    // displays header of flags
2074
2075    E4B_AVOID_UNNEEDED_CASTS(flag_header_terminal);
2076    bool set_dynamic_size() OVERRIDE;
2077
2078public:
2079    ED4_flag_header_terminal(GB_CSTR id, AW_pos width, AW_pos height, ED4_manager *parent);
2080
2081    GB_CSTR get_displayed_text() const;
2082    int get_length() const OVERRIDE;
2083
2084    DECLARE_DUMP_FOR_LEAFCLASS(ED4_text_terminal);
2085};
2086
2087class ED4_sequence_info_terminal : public ED4_text_terminal {
2088    E4B_AVOID_UNNEEDED_CASTS(sequence_info_terminal);
2089    bool set_dynamic_size() OVERRIDE;
2090
2091public:
2092    ED4_sequence_info_terminal(const char *id, AW_pos width, AW_pos height, ED4_manager *parent);
2093
2094    ED4_species_name_terminal *corresponding_species_name_terminal() const {
2095        return get_parent(LEV_SPECIES)->search_spec_child_rek(LEV_SPECIES_NAME)->to_species_name_terminal();
2096    }
2097
2098    void draw() OVERRIDE;
2099
2100    GBDATA *data() { return get_species_pointer(); } // DB-entry ("ali_xxx/data")
2101    const GBDATA *data() const { return get_species_pointer(); }
2102
2103    int get_length() const OVERRIDE { return 1+strlen(id); }
2104
2105    DECLARE_DUMP_FOR_LEAFCLASS(ED4_text_terminal);
2106};
2107
2108struct ED4_pure_text_terminal : public ED4_text_terminal {
2109    E4B_AVOID_UNNEEDED_CASTS(pure_text_terminal);
2110   
2111    ED4_pure_text_terminal(const char *id, AW_pos width, AW_pos height, ED4_manager *parent);
2112
2113    int get_length() const OVERRIDE { int len; resolve_pointer_to_char_pntr(&len); return len; }
2114
2115    DECLARE_DUMP_FOR_LEAFCLASS(ED4_text_terminal);
2116};
2117
2118class ED4_consensus_sequence_terminal : public ED4_sequence_terminal { // derived from a Noncopyable
2119    E4B_AVOID_UNNEEDED_CASTS(consensus_sequence_terminal);
2120
2121    void draw() OVERRIDE;
2122    const ED4_abstract_group_manager *get_group_manager() const  { return get_parent(LEV_GROUP)->to_group_manager(); }
2123    const BaseFrequencies& get_char_table() const { return get_group_manager()->table(); }
2124
2125public:
2126    char *temp_cons_seq; // used for editing consensus (normally NULL)
2127
2128    ED4_consensus_sequence_terminal(const char *id, AW_pos width, AW_pos height, ED4_manager *parent);
2129#if defined(ASSERTION_USED)
2130    virtual ~ED4_consensus_sequence_terminal() { e4_assert(!temp_cons_seq); }
2131#endif
2132
2133    int get_length() const OVERRIDE;
2134    char *get_sequence_copy(int *str_len = 0) const OVERRIDE;
2135
2136    DECLARE_DUMP_FOR_LEAFCLASS(ED4_sequence_terminal);
2137};
2138
2139class ED4_spacer_terminal : public ED4_terminal {
2140    E4B_AVOID_UNNEEDED_CASTS(spacer_terminal);
2141    bool shallDraw; // true -> spacer is really drawn (otherwise it's only a placeholder)
2142
2143    bool set_dynamic_size() OVERRIDE;
2144
2145public:
2146    void Show(bool refresh_all, bool is_cleared) OVERRIDE;
2147    void draw() OVERRIDE;
2148
2149    ED4_spacer_terminal(const char *id, bool shallDraw_, AW_pos width, AW_pos height, ED4_manager *parent);
2150
2151    DECLARE_DUMP_FOR_LEAFCLASS(ED4_terminal);
2152};
2153
2154class ED4_line_terminal : public ED4_terminal {
2155    E4B_AVOID_UNNEEDED_CASTS(line_terminal);
2156    bool set_dynamic_size() OVERRIDE;
2157
2158public:
2159    void draw() OVERRIDE;
2160
2161    ED4_line_terminal(const char *id, AW_pos width, AW_pos height, ED4_manager *parent);
2162
2163    DECLARE_DUMP_FOR_LEAFCLASS(ED4_terminal);
2164};
2165
2166class ED4_flag_terminal : public ED4_terminal {
2167    E4B_AVOID_UNNEEDED_CASTS(flag_terminal);
2168    bool set_dynamic_size() OVERRIDE;
2169
2170public:
2171    void draw() OVERRIDE;
2172
2173    ED4_flag_terminal(const char *id, AW_pos width, AW_pos height, ED4_manager *parent);
2174
2175    GBDATA *get_species() const { return get_parent(LEV_SPECIES)->get_species_pointer(); }
2176    void handle_left_click(const AW::Position& click);
2177
2178    DECLARE_DUMP_FOR_LEAFCLASS(ED4_terminal);
2179};
2180
2181
2182// ----------------------------------------------
2183//      inlines which need complete classdefs
2184
2185inline void ED4_base::set_update() { // @@@ rename into request_update
2186    if (!update_info.update_requested) {
2187        update_info.update_requested = 1;
2188        if (parent) parent->update_requested_by_child();
2189    }
2190}
2191
2192inline void ED4_base::request_resize() {
2193    update_info.set_resize(1);
2194    if (parent) parent->resize_requested_by_child();
2195}
2196
2197void ED4_manager::resize_requested_by_child() { 
2198    if (!update_info.resize) request_resize();
2199}
2200
2201inline bool ED4_terminal::setCursorTo(ED4_cursor *cursor, int seq_pos, bool unfoldGroups, ED4_CursorJumpType jump_type) {
2202    ED4_species_manager *sm = get_parent(LEV_SPECIES)->to_species_manager();
2203    return sm->setCursorTo(cursor, seq_pos, unfoldGroups, jump_type);
2204}
2205
2206E4B_IMPL_CASTOP(area_manager);                // to_area_manager
2207E4B_IMPL_CASTOP(abstract_group_manager);      // to_abstract_group_manager
2208E4B_IMPL_CASTOP(bracket_terminal);            // to_bracket_terminal
2209E4B_IMPL_CASTOP(columnStat_terminal);         // to_columnStat_terminal
2210E4B_IMPL_CASTOP(consensus_sequence_terminal); // to_consensus_sequence_terminal
2211E4B_IMPL_CASTOP(device_manager);              // to_device_manager
2212E4B_IMPL_CASTOP(group_manager);               // to_group_manager
2213E4B_IMPL_CASTOP(line_terminal);               // to_line_terminal
2214E4B_IMPL_CASTOP(manager);                     // to_manager
2215E4B_IMPL_CASTOP(multi_name_manager);          // to_multi_name_manager
2216E4B_IMPL_CASTOP(multi_sequence_manager);      // to_multi_sequence_manager
2217E4B_IMPL_CASTOP(multi_species_manager);       // to_multi_species_manager
2218E4B_IMPL_CASTOP(name_manager);                // to_name_manager
2219E4B_IMPL_CASTOP(orf_terminal);                // to_orf_terminal
2220E4B_IMPL_CASTOP(pure_text_terminal);          // to_pure_text_terminal
2221E4B_IMPL_CASTOP(root_group_manager);          // to_root_group_manager
2222E4B_IMPL_CASTOP(sequence_info_terminal);      // to_sequence_info_terminal
2223E4B_IMPL_CASTOP(sequence_manager);            // to_sequence_manager
2224E4B_IMPL_CASTOP(sequence_terminal);           // to_sequence_terminal
2225E4B_IMPL_CASTOP(spacer_terminal);             // to_spacer_terminal
2226E4B_IMPL_CASTOP(species_manager);             // to_species_manager
2227E4B_IMPL_CASTOP(species_name_terminal);       // to_species_name_terminal
2228E4B_IMPL_CASTOP(terminal);                    // to_terminal
2229E4B_IMPL_CASTOP(text_terminal);               // to_text_terminal
2230E4B_IMPL_CASTOP(flag_header_terminal);        // to_flag_header_terminal
2231E4B_IMPL_CASTOP(flag_terminal);               // to_flag_terminal
2232
2233inline ED4_device_manager *ED4_root::get_device_manager() {
2234    return main_manager->search_spec_child_rek(LEV_DEVICE)->to_device_manager();
2235}
2236
2237
2238inline ED4_species_name_terminal *ED4_multi_species_manager::get_consensus_name_terminal() const { 
2239    ED4_species_manager *consensus_man = get_consensus_manager();
2240    return consensus_man ? consensus_man->get_name_terminal() : NULL;
2241}
2242
2243// ----------------------------------------
2244
2245enum SpeciesCreationMode {
2246    CREATE_NEW_SPECIES,
2247    CREATE_FROM_CONSENSUS, // create new species from group consensus (of surrounding group)
2248    COPY_SPECIES,          // copy current species
2249};
2250
2251#if defined(ASSERTION_USED)
2252CONSTEXPR_RETURN inline bool valid(SpeciesCreationMode m) { return m>=CREATE_NEW_SPECIES && m<=COPY_SPECIES; }
2253#endif
2254
2255extern ST_ML *st_ml;
2256struct AlignDataAccess;
2257
2258// -------------------------------------------------
2259//      factory functions (hierarchy builders):
2260
2261ED4_group_manager *ED4_build_group_manager_start(ED4_manager                 *group_parent,
2262                                                 GB_CSTR                      group_name,
2263                                                 int                          group_depth,
2264                                                 bool                         is_folded,
2265                                                 ED4_reference_terminals&     refterms,
2266                                                 ED4_multi_species_manager*&  multi_species_manager);
2267
2268void ED4_build_group_manager_end(ED4_multi_species_manager *multi_species_manager);
2269
2270// -------------------------------------
2271//      hierarchy access functions:
2272
2273ED4_species_name_terminal *ED4_find_species_name_terminal(const char *species_name);
2274ED4_species_name_terminal *ED4_find_SAI_name_terminal(const char *sai_name);
2275ED4_species_name_terminal *ED4_find_species_or_SAI_name_terminal(const char *species_name);
2276
2277ED4_multi_species_manager *ED4_find_MoreSequences_manager();
2278
2279// --------------------------
2280//      other functions:
2281
2282void ED4_new_editor_window(AW_window *aww);
2283void ED4_with_all_edit_windows(void (*cb)(ED4_window *));
2284
2285void ED4_resize_all_extensions();
2286void ED4_calc_terminal_extentions();
2287
2288void ED4_input_cb(AW_window *aww);
2289void ED4_remote_event(AW_event *faked_event);
2290void ED4_motion_cb(AW_window *aww);
2291void ED4_vertical_change_cb(AW_window *aww);
2292void ED4_horizontal_change_cb(AW_window *aww);
2293void ED4_scrollbar_change_cb(AW_window *aww);
2294void ED4_trigger_instant_refresh();
2295void ED4_request_relayout();
2296void ED4_request_full_refresh();
2297void ED4_request_full_instant_refresh();
2298
2299void ED4_store_curpos(AW_window *aww);
2300void ED4_restore_curpos(AW_window *aww);
2301void ED4_clear_stored_curpos();
2302void ED4_helix_jump_opposite(AW_window *aww);
2303void ED4_jump_to_cursor_position(AW_window *aww, const char *awar_name, PositionType posType);
2304void ED4_remote_set_cursor_cb(AW_root *awr);
2305void ED4_change_cursor(AW_window *aww);
2306
2307void ED4_set_iupac(AW_window *aww, const char *awar_name);
2308void ED4_set_helixnr(AW_window *aww, const char *awar_name);
2309void ed4_changesecurity(AW_root *root);
2310void ed4_change_edit_mode(AW_root *root);
2311
2312void ED4_jump_to_current_species(AW_window *);
2313void ED4_get_and_jump_to_current(AW_window *);
2314void ED4_get_and_jump_to_species(GB_CSTR species_name);
2315
2316void ED4_get_marked_from_menu(AW_window *);
2317void ED4_selected_species_changed_cb(AW_root *aw_root);
2318
2319AW_window *ED4_create_loadSAI_window(AW_root *awr);
2320void       ED4_get_and_jump_to_selected_SAI(AW_window *aww);
2321void       ED4_selected_SAI_changed_cb(AW_root *aw_root);
2322
2323void ED4_init_notFoundMessage();
2324void ED4_finish_and_show_notFoundMessage();
2325
2326const AlignDataAccess *ED4_get_aligner_data_access();
2327
2328void ED4_popup_gc_window(AW_window *awp, AW_gc_manager *gcman);
2329void ED4_no_dangerous_modes();
2330
2331void       group_species_cb(AW_window *aww, bool use_fields);
2332AW_window *ED4_create_group_species_by_field_window(AW_root *aw_root);
2333
2334AW_window *ED4_create_loadConfiguration_window(AW_root *awr);
2335void       ED4_reloadConfiguration(AW_window *aww);
2336void       ED4_saveConfiguration(AW_window *aww, bool hide_aww);
2337AW_window *ED4_create_saveConfigurationAs_window(AW_root *awr);
2338
2339ARB_ERROR  rebuild_consensus(ED4_base *object);
2340
2341void       ED4_create_consensus_awars(AW_root *aw_root);
2342AW_window *ED4_create_consensus_definition_window(AW_root *root);
2343void       ED4_consensus_definition_changed(AW_root*);
2344void       ED4_consensus_display_changed(AW_root *root);
2345
2346AW_window *ED4_create_editor_options_window(AW_root *root);
2347void       ED4_compression_toggle_changed_cb(AW_root *root, bool hideChanged);
2348void       ED4_compression_changed_cb(AW_root *awr);
2349void       ED4_alignment_length_changed(GBDATA *gb_alignment_len, GB_CB_TYPE gbtype);
2350
2351AW_window *ED4_create_new_seq_window(AW_root *root, SpeciesCreationMode creation_mode);
2352
2353void ED4_quit_editor(AW_window *aww);
2354void ED4_exit() __ATTR__NORETURN;
2355
2356
2357#else
2358#error ed4_class included twice
2359#endif
2360
Note: See TracBrowser for help on using the repository browser.