source: tags/ms_r16q2/EDIT4/ed4_class.hxx

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