source: tags/arb-7.0/EDIT4/ED4_terminal.cxx

Last change on this file was 18352, checked in by westram, 4 years ago
  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 48.3 KB
Line 
1// =============================================================== //
2//                                                                 //
3//   File      : ED4_terminal.cxx                                  //
4//   Purpose   :                                                   //
5//                                                                 //
6//   Institute of Microbiology (Technical University Munich)       //
7//   http://www.arb-home.de/                                       //
8//                                                                 //
9// =============================================================== //
10
11#include <ed4_extern.hxx>
12#include "ed4_class.hxx"
13#include "ed4_awars.hxx"
14#include "ed4_edit_string.hxx"
15#include "ed4_block.hxx"
16#include "ed4_nds.hxx"
17#include "ed4_ProteinViewer.hxx"
18#include "ed4_seq_colors.hxx"
19#include "ed4_flags.hxx"
20
21#include <arbdbt.h>
22#include <items.h>
23
24#include <aw_preset.hxx>
25#include <aw_awar.hxx>
26#include <aw_awar_defs.hxx>
27#include <aw_msg.hxx>
28#include <aw_root.hxx>
29#include <aw_question.hxx>
30
31#include <st_window.hxx>
32
33// -----------------------------------
34//      static terminal properties
35
36static ED4_objspec tree_terminal_spec(
37    PROP_IS_TERMINAL,  // static props
38    LEV_TREE,           // level
39    LEV_NONE,           // allowed children level
40    LEV_NONE,           // handled object
41    LEV_NONE            // restriction level
42    );
43
44static ED4_objspec bracket_terminal_spec(
45    PROP_IS_TERMINAL,  // static props
46    LEV_BRACKET,        // level
47    LEV_NONE,           // allowed children level
48    LEV_NONE,           // handled object
49    LEV_NONE            // restriction level
50    );
51
52static ED4_objspec species_name_terminal_spec(
53    ED4_properties(PROP_IS_TERMINAL | PROP_DYNA_RESIZE),  // static props
54    LEV_SPECIES_NAME,   // level
55    LEV_NONE,           // allowed children level
56    LEV_SPECIES,        // handled object
57    LEV_NONE            // restriction level
58    );
59
60static ED4_objspec flag_header_spec(
61    ED4_properties(PROP_IS_TERMINAL | PROP_DYNA_RESIZE),  // static props
62    LEV_FLAG_HEADER,    // level
63    LEV_NONE,           // allowed children level
64    LEV_NONE,           // handled object
65    LEV_NONE            // restriction level
66    );
67
68static ED4_objspec flag_spec(
69    ED4_properties(PROP_IS_TERMINAL | PROP_DYNA_RESIZE), // static props
70    LEV_FLAG,           // level
71    LEV_NONE,           // allowed children level
72    LEV_NONE,           // handled object
73    LEV_NONE            // restriction level
74    );
75
76static ED4_objspec sequence_info_terminal_spec(
77    ED4_properties(PROP_IS_TERMINAL | PROP_DYNA_RESIZE),  // static props
78    LEV_SEQUENCE_INFO,  // level
79    LEV_NONE,           // allowed children level
80    LEV_SEQUENCE,       // handled object
81    LEV_NONE            // restriction level
82    );
83
84static ED4_objspec sequence_terminal_spec(
85    PROP_IS_TERMINAL,     // static props
86    LEV_SEQUENCE_STRING,   // level
87    LEV_NONE,              // allowed children level
88    LEV_NONE,              // handled object
89    LEV_NONE               // restriction level
90    );
91
92static ED4_objspec orf_terminal_spec(
93    PROP_IS_TERMINAL,     // static props
94    LEV_ORF,               // level
95    LEV_NONE,              // allowed children level
96    LEV_NONE,              // handled object
97    LEV_NONE               // restriction level
98    );
99
100static ED4_objspec pure_text_terminal_spec(
101    PROP_IS_TERMINAL,     // static props
102    LEV_PURE_TEXT,         // level
103    LEV_NONE,              // allowed children level
104    LEV_NONE,              // handled object
105    LEV_NONE               // restriction level
106    );
107
108static ED4_objspec spacer_terminal_spec(
109    ED4_properties(PROP_IS_TERMINAL | PROP_DYNA_RESIZE), // static props
110    LEV_SPACER,            // level
111    LEV_NONE,              // allowed children level
112    LEV_NONE,              // handled object
113    LEV_NONE               // restriction level
114    );
115
116static ED4_objspec line_terminal_spec(
117    ED4_properties(PROP_IS_TERMINAL | PROP_DYNA_RESIZE), // static props
118    LEV_LINE,              // level
119    LEV_NONE,              // allowed children level
120    LEV_NONE,              // handled object
121    LEV_NONE               // restriction level
122    );
123
124static ED4_objspec column_stat_terminal_spec(
125    PROP_IS_TERMINAL,     // static props
126    LEV_COL_STAT,          // level
127    LEV_NONE,              // allowed children level
128    LEV_NONE,              // handled object
129    LEV_NONE               // restriction level
130    );
131
132
133char *ED4_terminal::resolve_pointer_to_string_copy(int *str_len) const {
134    int         len;
135    const char *s = resolve_pointer_to_char_pntr(&len);
136    char       *t = ARB_strduplen(s, len); // space for zero byte is allocated by ARB_strduplen
137
138    if (str_len) *str_len = len;
139    return t;
140}
141
142const char *ED4_terminal::resolve_pointer_to_char_pntr(int *str_len) const {
143    const char *result     = NULp;
144    GBDATA     *gbd        = get_species_pointer();
145    bool        detect_len = true;
146
147    if (!gbd) {
148        result = id; // if we don't have a link to the database we (have to) use our id
149    }
150    else {
151        GB_transaction ta(ED4_ROOT->get_gb_main());
152
153        switch (GB_read_type(gbd)) {
154            case GB_STRING:
155                result = GB_read_char_pntr(gbd);
156                if (str_len) {
157                    *str_len   = GB_read_string_count(gbd);
158                    detect_len = false;
159                }
160                break;
161            case GB_BITS:
162                result = GB_read_bits_pntr(gbd, '.', '+');
163                if (str_len) {
164                    *str_len = GB_read_bits_count(gbd);
165                    detect_len = false;
166                }
167                break;
168            case GB_BYTES:
169                result = GB_read_bytes_pntr(gbd);
170                if (str_len) {
171                    *str_len = GB_read_bytes_count(gbd);
172                    detect_len = false;
173                }
174                break;
175
176            case GB_DB:     result = "GB_DB";     break;
177            case GB_INT:    result = "GB_INT";    break;
178            case GB_INTS:   result = "GB_INTS";   break;
179            case GB_FLOAT:  result = "GB_FLOAT";  break;
180            case GB_FLOATS: result = "GB_FLOATS"; break;
181
182            default:
183                result = "Unknown data type\n";
184                e4_assert(0);
185                break;
186        }
187    }
188
189    if (str_len) {
190        if (detect_len) {
191            *str_len = result ? strlen(result) : 0;
192        }
193        else {
194            e4_assert(*str_len == (int)strlen(result));
195        }
196    }
197
198    return result;
199}
200
201GB_ERROR ED4_terminal::write_sequence(const char *seq, int seq_len) {
202    GB_ERROR  err = NULp;
203    GBDATA   *gbd = get_species_pointer();
204    e4_assert(gbd); // we must have a link to the database!
205
206    GBDATA *gb_main = ED4_ROOT->get_gb_main();
207    GB_push_transaction(gb_main);
208
209    int   old_seq_len;
210    char *old_seq = resolve_pointer_to_string_copy(&old_seq_len);
211
212    bool allow_write_data = true;
213    if (ED4_ROOT->aw_root->awar(ED4_AWAR_ANNOUNCE_CHECKSUM_CHANGES)->read_int()) {
214        long old_checksum = GBS_checksum(old_seq, 1, "-.");
215        long new_checksum = GBS_checksum(seq, 1, "-.");
216
217        if (old_checksum != new_checksum) {
218            if (aw_question(NULp, "Checksum changed!", "Allow, Reject") == 1) {
219                allow_write_data = false;
220            }
221
222        }
223    }
224
225    if (allow_write_data) {
226        GB_TYPES gb_type = GB_read_type(gbd);
227        switch (gb_type) {
228            case GB_STRING: {
229                err = GB_write_string(gbd, seq);
230                break;
231            }
232            case GB_BITS: {
233                err = GB_write_bits(gbd, seq, seq_len, ".-");
234                break;
235            }
236            default: {
237                e4_assert(0);
238                break;
239            }
240        }
241    }
242
243    GB_pop_transaction(gb_main);
244
245    if (!err && has_property(PROP_CONSENSUS_RELEVANT)) {
246        if (old_seq) {
247            curr_timestamp = GB_read_clock(gb_main);
248
249            get_parent(LEV_MULTI_SPECIES)->to_multi_species_manager()
250                ->update_bases_and_rebuild_consensi(old_seq, old_seq_len, get_parent(LEV_SPECIES)->to_species_manager(), ED4_U_UP); // bases_check
251        }
252        else {
253            aw_message("Couldn't read old sequence data");
254        }
255
256        request_refresh();
257    }
258
259    if (old_seq) free(old_seq);
260
261    return err;
262}
263
264
265void ED4_terminal::remove_callbacks() {
266    if (get_species_pointer()) {
267        set_species_pointer(NULp);
268        tflag.deleted = 1; // @@@ why ?
269        clr_property(PROP_CURSOR_ALLOWED);
270        request_refresh();
271    }
272}
273
274#if 0
275static ARB_ERROR ed4_remove_species_manager_callbacks(ED4_base *base) { // @@@ unused since [8286]
276    if (base->is_species_manager()) {
277        base->to_species_manager()->remove_all_callbacks();
278    }
279    return NULp;
280}
281#endif
282
283inline void remove_from_consensus(ED4_manager *group_or_species_man) {
284    GB_transaction ta(ED4_ROOT->get_gb_main());
285    ED4_manager *parent_manager = group_or_species_man->parent;
286    parent_manager->update_consensus(parent_manager, NULp, group_or_species_man);
287    parent_manager->rebuild_consensi(parent_manager, ED4_U_UP);
288}
289
290ED4_returncode ED4_terminal::kill_object() {
291    ED4_species_manager *species_manager = get_parent(LEV_SPECIES)->to_species_manager();
292
293    if (species_manager->is_consensus_manager()) { // kill whole group
294        if (ED4_find_MoreSequences_manager()==species_manager->parent) {
295            aw_message("This group has to exist - deleting it isn't allowed");
296            return ED4_R_IMPOSSIBLE;
297        }
298
299        ED4_manager *group_manager = species_manager->get_parent(LEV_GROUP)->to_group_manager();
300        remove_from_consensus(group_manager);
301        group_manager->Delete();
302    }
303    else { // kill single species/SAI
304        remove_from_consensus(species_manager);
305        species_manager->Delete();
306    }
307
308    return ED4_R_OK;
309}
310
311ED4_returncode ED4_terminal::draw_drag_box(AW_pos x, AW_pos y, GB_CSTR text, int cursor_y) {
312    // draws drag box of object at location abs_x, abs_y
313
314    if (cursor_y!=-1) {
315        ED4_base *drag_target = NULp;
316        {
317            ED4_extension location;
318            location.position[X_POS] = 0;
319            location.position[Y_POS] = (AW_pos)cursor_y;           // cursor_y is already in world coordinates
320
321            ED4_ROOT->get_device_manager()->search_target_species(&location, PROP_HORIZONTAL, &drag_target, LEV_NONE);
322        }
323
324        if (drag_target) {
325            AW_pos target_x, target_y;
326
327            drag_target->calc_world_coords (&target_x, &target_y);
328            current_ed4w()->world_to_win_coords(&target_x, &target_y);
329
330#define ARROW_LENGTH 3
331            AW_pos drag_line_x0[3], drag_line_y0[3];
332            AW_pos drag_line_x1[3], drag_line_y1[3];
333
334            drag_line_x0[0] = target_x + 5;                                                 // horizontal
335            drag_line_y0[0] = target_y + drag_target->extension.size[HEIGHT];
336            drag_line_x1[0] = drag_line_x0[0] + 50;
337            drag_line_y1[0] = target_y + drag_target->extension.size[HEIGHT];
338
339            drag_line_x0[1] = drag_line_x0[0] -ARROW_LENGTH;                                // arrow
340            drag_line_y0[1] = drag_line_y0[0] -ARROW_LENGTH;
341            drag_line_x1[1] = drag_line_x0[0];
342            drag_line_y1[1] = drag_line_y0[0];
343
344            drag_line_x0[2] = drag_line_x0[0] -ARROW_LENGTH;                                // arrow
345            drag_line_y0[2] = drag_line_y0[0] + ARROW_LENGTH;
346            drag_line_x1[2] = drag_line_x0[0];
347            drag_line_y1[2] = drag_line_y0[0];
348#undef ARROW_LENGTH
349
350            for (ED4_index i = 0; i <= 2; i++) {
351                current_device()->line(ED4_G_DRAG, drag_line_x0[i], drag_line_y0[i], drag_line_x1[i], drag_line_y1[i], AW_SCREEN);
352            }
353        }
354    }
355
356    if (text) {
357        current_device()->text(ED4_G_DRAG, text, (x + 20), (y + INFO_TERM_TEXT_YOFFSET), 0, AW_SCREEN);
358    }
359
360    return ED4_R_OK;
361}
362
363void ED4_multi_species_manager::toggle_selected_species() {
364    if (all_are_selected()) deselect_all_species_and_SAI();
365    else select_all(false); // species and SAI
366
367    ED4_correctBlocktypeAfterSelection();
368}
369
370#if defined(DEBUG) && 1
371static inline void dumpEvent(const char *where, AW_event *event) {
372    printf("%s: x=%i y=%i\n", where, event->x, event->y);
373}
374#else
375#define dumpEvent(w, e)
376#endif
377
378ED4_returncode ED4_terminal::event_sent_by_parent(AW_event *event, AW_window *aww) {
379    // handles an input event coming from parent
380
381    // static data to move terminal:
382    static ED4_species_name_terminal *dragged_name_terminal = NULp;
383
384    static bool pressed_left_button  = false;
385    static int  other_x, other_y;                                    // coordinates of last event
386    static bool dragged_was_selected = false;                        // the dragged terminal is temp. added to selected
387
388    // ----------------------------
389    //      drag/drop terminal
390    if (dragged_name_terminal) {
391        if (event->button == AW_BUTTON_LEFT) {
392            switch (event->type) {
393                case AW_Mouse_Drag: {
394                    ED4_selection_entry *sel_info = dragged_name_terminal->selection_info;
395
396                    if (pressed_left_button) {
397                        AW_pos world_x, world_y;
398
399                        dragged_name_terminal->calc_world_coords(&world_x, &world_y);
400                        current_ed4w()->world_to_win_coords(&world_x, &world_y);
401
402                        sel_info->drag_old_x = world_x;
403                        sel_info->drag_old_y = world_y;
404                        sel_info->drag_off_x = world_x-other_x;
405                        sel_info->drag_off_y = world_y-other_y;
406                        sel_info->old_event_y = -1;
407
408                        pressed_left_button = false;
409                    }
410
411                    GB_CSTR text = dragged_name_terminal->get_displayed_text();
412
413                    if (dragged_name_terminal->dragged) {
414                        dragged_name_terminal->draw_drag_box(sel_info->drag_old_x, sel_info->drag_old_y, text, sel_info->old_event_y);
415                    }
416
417                    AW_pos new_x = sel_info->drag_off_x + event->x;
418                    AW_pos new_y = sel_info->drag_off_y + event->y;
419
420                    dragged_name_terminal->draw_drag_box(new_x, new_y, text, event->y); // @@@ event->y ist falsch, falls vertikal gescrollt ist!
421
422                    sel_info->drag_old_x = new_x;
423                    sel_info->drag_old_y = new_y;
424                    sel_info->old_event_y = event->y;
425
426                    dragged_name_terminal->dragged = true;
427                    break;
428                }
429                case AW_Mouse_Release: {
430                    if (dragged_name_terminal->dragged) {
431                        {
432                            char                *db_pointer = dragged_name_terminal->resolve_pointer_to_string_copy();
433                            ED4_selection_entry *sel_info   = dragged_name_terminal->selection_info;
434
435                            dragged_name_terminal->draw_drag_box(sel_info->drag_old_x, sel_info->drag_old_y, db_pointer, sel_info->old_event_y);
436                            dragged_name_terminal->dragged = false;
437
438                            free(db_pointer);
439                        }
440                        {
441                            ED4_move_info mi;
442
443                            mi.object = dragged_name_terminal;
444                            mi.end_x = event->x;
445                            mi.end_y = event->y;
446                            mi.mode = ED4_M_FREE;
447                            mi.preferred_parent = LEV_NONE;
448
449                            dragged_name_terminal->parent->move_requested_by_child(&mi);
450                        }
451                        {
452                            ED4_device_manager *device_manager = ED4_ROOT->get_device_manager();
453
454                            for (int i=0; i<device_manager->members(); i++) { // when moving species numbers have to be recalculated
455                                ED4_base *member = device_manager->member(i);
456
457                                if (member->is_area_manager()) {
458                                    member->to_area_manager()->get_multi_species_manager()->update_requested_by_child();
459                                }
460                            }
461                        }
462                    }
463                    if (!dragged_was_selected) {
464                        ED4_ROOT->remove_from_selected(dragged_name_terminal);
465                    }
466
467                    pressed_left_button   = false;
468                    dragged_name_terminal = NULp;
469                    break;
470                }
471                default:
472                    break;
473            }
474        }
475    }
476    else {
477        switch (event->button) {
478            case AW_BUTTON_LEFT: {
479                if (is_species_name_terminal()) {
480                    switch (ED4_ROOT->species_mode) {
481                        case ED4_SM_KILL: {
482                            if (event->type == AW_Mouse_Press) {
483                                if (containing_species_manager()->is_selected()) ED4_ROOT->remove_from_selected(this->to_species_name_terminal());
484                                kill_object();
485                                return ED4_R_BREAK;
486                            }
487                            break;
488                        }
489                        case ED4_SM_MOVE: {
490                            if (event->type == AW_Mouse_Press) {
491                                dragged_name_terminal = to_species_name_terminal();
492                                pressed_left_button   = true;
493
494                                other_x = event->x;
495                                other_y = event->y;
496
497                                dragged_was_selected = containing_species_manager()->is_selected();
498                                if (!dragged_was_selected) {
499                                    ED4_ROOT->add_to_selected(dragged_name_terminal);
500                                    ED4_trigger_instant_refresh();
501                                }
502                            }
503                            break;
504                        }
505                        case ED4_SM_INFO:
506                        case ED4_SM_MARK: {
507                            static ED4_species_manager *prev_clicked_species_man = NULp;
508                            ED4_species_manager        *species_man              = get_parent(LEV_SPECIES)->to_species_manager();
509
510                            GBDATA *gbd = species_man->get_species_pointer();
511                            if (gbd) {
512                                bool       acceptClick = false;
513                                static int markHow     = -1;  // -1=invert, 0=unmark, 1=mark
514                                {
515                                    switch (event->type) {
516                                        case AW_Mouse_Press:
517                                            acceptClick = true;
518                                            markHow     = -1;
519                                            break;
520
521                                        case AW_Mouse_Drag:
522                                            acceptClick = prev_clicked_species_man != species_man;
523                                            break;
524
525                                        case AW_Mouse_Release:
526                                            acceptClick              = prev_clicked_species_man != species_man;
527                                            prev_clicked_species_man = NULp;
528                                            break;
529
530                                        case AW_Keyboard_Press:
531                                        case AW_Keyboard_Release:
532                                            e4_assert(0); // impossible
533                                            break;
534                                    }
535                                }
536
537                                if (acceptClick) {
538                                    if (ED4_ROOT->species_mode == ED4_SM_MARK) {
539                                        if (markHow<0) markHow = !GB_read_flag(gbd);
540                                        GB_write_flag(gbd, markHow);
541                                        request_refresh();
542                                        if (ED4_ROOT->alignment_type ==  GB_AT_DNA) PV_RefreshWindow(aww->get_root()); // ProtView: Refreshing orf terminals (@@@ weird place to perform refresh)
543                                    }
544                                    else {
545                                        e4_assert(ED4_ROOT->species_mode == ED4_SM_INFO);
546
547                                        const char *name = GBT_get_name(gbd);
548                                        if (name) {
549                                            const char *awar_select = species_man->inside_SAI_manager() ? AWAR_SAI_NAME : AWAR_SPECIES_NAME;
550                                            ED4_ROOT->aw_root->awar(awar_select)->write_string(name);
551                                        }
552                                    }
553                                    prev_clicked_species_man = species_man;
554                                }
555                            }
556                            else {
557                                prev_clicked_species_man = NULp;
558                            }
559                            break;
560                        }
561                    }
562                }
563                else if (is_bracket_terminal()) { // fold/unfold group
564                    if (event->type == AW_Mouse_Press) {
565                        to_bracket_terminal()->toggle_folding();
566                    }
567                }
568                else if (is_sequence_terminal()) {
569                    if (has_property(PROP_CURSOR_ALLOWED)) {
570                        ED4_no_dangerous_modes();
571                        current_cursor().show_clicked_cursor(event->x, this);
572                    }
573                }
574                else if (is_flag_terminal()) {
575                    if (event->type == AW_Mouse_Press) {
576                        to_flag_terminal()->handle_left_click(current_ed4w()->world_to_win_coords(AW::Position(event->x, event->y)));
577                    }
578                }
579
580                break;
581            }
582            case AW_BUTTON_RIGHT: {
583                // static data for block-selection:
584                static bool select_started_on_seqterm = false;
585
586                switch (event->type) {
587                    case AW_Mouse_Press: {
588                        select_started_on_seqterm = false;
589                        if (is_species_name_terminal()) {
590                            ED4_species_manager *species_man = get_parent(LEV_SPECIES)->to_species_manager();
591
592                            if (species_man->is_consensus_manager()) { // click on consensus-name
593                                ED4_multi_species_manager *multi_man = species_man->get_parent(LEV_MULTI_SPECIES)->to_multi_species_manager();
594                                multi_man->toggle_selected_species();
595                            }
596                            else { // click on species or SAI name
597                                if (!species_man->is_selected()) { // select if not selected
598                                    if (ED4_ROOT->add_to_selected(this->to_species_name_terminal()) == ED4_R_OK) ED4_correctBlocktypeAfterSelection();
599                                }
600                                else { // deselect if already selected
601                                    ED4_ROOT->remove_from_selected(this->to_species_name_terminal());
602                                    ED4_correctBlocktypeAfterSelection();
603                                }
604                            }
605                        }
606                        else if (is_bracket_terminal()) {
607                            ED4_base *group = get_parent(LEV_GROUP);
608                            if (group) {
609                                group->to_group_manager()->get_multi_species_manager()->toggle_selected_species();
610                            }
611                        }
612                        else if (is_sequence_terminal()) {
613                            ED4_no_dangerous_modes();
614                            ED4_setColumnblockCorner(event, to_sequence_terminal()); // mark columnblock
615                            select_started_on_seqterm = true;
616                        }
617                        break;
618                    }
619
620                    case AW_Mouse_Drag:
621                    case AW_Mouse_Release:
622                        if (select_started_on_seqterm && is_sequence_terminal()) {
623                            ED4_no_dangerous_modes();
624                            ED4_setColumnblockCorner(event, to_sequence_terminal()); // mark columnblock
625                        }
626                        break;
627
628                    default:
629                        break;
630                }
631                break;
632            }
633
634            default: break;
635        }
636    }
637
638    return ED4_R_OK;
639}
640
641void ED4_terminal::update_requested_children() {}
642
643bool ED4_terminal::calc_bounding_box() {
644    // calculates the smallest rectangle containing the object.
645    // requests refresh and returns true if bounding box has changed.
646
647    bool bb_changed = false;
648
649    if (width_link) {
650        bb_changed = extension.set_size_does_change(WIDTH, width_link->extension.size[WIDTH]) || bb_changed;
651    }
652
653    if (height_link) {
654        bb_changed = extension.set_size_does_change(HEIGHT, height_link->extension.size[HEIGHT]) || bb_changed;
655    }
656
657
658    if (bb_changed) {
659        request_resize_of_linked();
660        request_refresh();
661    }
662    return bb_changed;
663}
664
665void ED4_terminal::resize_requested_children() {
666    if (update_info.resize) { // likes to resize?
667        if (calc_bounding_box()) request_resize();
668    }
669}
670
671
672void ED4_terminal::request_refresh(int clear) {
673    update_info.set_refresh(1);
674    update_info.set_clear_at_refresh(clear);
675    if (parent) parent->refresh_requested_by_child();
676}
677
678
679ED4_base* ED4_terminal::search_ID(const char *temp_id) {
680    if (id && strcmp(temp_id, id) == 0) return this;
681    return NULp;
682}
683
684void ED4_terminal::Show(bool IF_ASSERTION_USED(refresh_all), bool is_cleared) {
685    e4_assert(update_info.refresh || refresh_all);
686    current_device()->push_clip_scale();
687    if (adjust_clipping_rectangle()) {
688        if (update_info.clear_at_refresh && !is_cleared) {
689            clear_background();
690        }
691        draw();
692    }
693    current_device()->pop_clip_scale();
694}
695
696ED4_terminal::ED4_terminal(const ED4_objspec& spec_, GB_CSTR temp_id, AW_pos width, AW_pos height, ED4_manager *temp_parent) :
697    ED4_base(spec_, temp_id, width, height, temp_parent)
698{
699    memset((char*)&tflag, 0, sizeof(tflag));
700    curr_timestamp = 0;
701}
702
703
704ED4_terminal::~ED4_terminal() {
705    for (ED4_window *window = ED4_ROOT->first_window; window; window=window->next) {
706        ED4_cursor& cursor = window->cursor;
707        if (this == cursor.owner_of_cursor) {
708            cursor.init();
709        }
710    }
711}
712
713ED4_tree_terminal::ED4_tree_terminal(const char *temp_id, AW_pos width, AW_pos height, ED4_manager *temp_parent)
714    : ED4_terminal(tree_terminal_spec, temp_id, width, height, temp_parent)
715{}
716
717void ED4_tree_terminal::draw() {
718    AW_pos  x, y;
719    AW_pos  text_x, text_y;
720    char   *db_pointer;
721
722    calc_world_coords(&x, &y);
723    current_ed4w()->world_to_win_coords(&x, &y);
724
725    text_x = x + CHARACTEROFFSET;                           // don't change
726    text_y = y + SEQ_TERM_TEXT_YOFFSET;
727
728    db_pointer = resolve_pointer_to_string_copy();
729    current_device()->text(ED4_G_STANDARD, db_pointer, text_x, text_y, 0, AW_SCREEN);
730    free(db_pointer);
731}
732
733ED4_bracket_terminal::ED4_bracket_terminal(const char *temp_id, AW_pos width, AW_pos height, ED4_manager *temp_parent)
734    : ED4_terminal(bracket_terminal_spec, temp_id, width, height, temp_parent)
735{}
736
737void ED4_bracket_terminal::draw() {
738    using namespace AW;
739
740    Rectangle  term_area = get_win_area(current_ed4w());
741    AW_device *device    = current_device();
742
743    ED4_multi_species_manager *multi_man = get_parent(LEV_GROUP)->to_group_manager()->get_multi_species_manager();
744    if (multi_man->get_no_of_selected_species()) {  // if multi_species_manager contains selected species
745#if defined(DEBUG) && 0
746        static bool toggle = false;
747        toggle             = !toggle;
748        device->box(toggle ? ED4_G_SELECTED : ED4_G_SELECTED+1, AW::FillStyle::SOLID, term_area);
749#else // !defined(DEBUG)
750        device->box(ED4_G_SELECTED, AW::FillStyle::SOLID, term_area);
751#endif
752    }
753
754    e4_assert(parent->is_group_manager());
755    if (parent->has_property(PROP_IS_FOLDED)) { // for folded group, paint triangle pointing rightwards
756        Position t = term_area.upper_left_corner()+Vector(4,4);
757        Position b = t+Vector(0,12);
758
759        for (int i = 0; i<6; ++i) {
760            device->line(ED4_G_STANDARD, t, b, AW_SCREEN);
761            t += Vector(1,  1);
762            b += Vector(1, -1);
763        }
764        e4_assert(nearlyEqual(t, b));
765        device->line(ED4_G_STANDARD, t, b, AW_SCREEN); // arrowhead
766    }
767    else { // for unfolded group, paint triangle pointing downwards
768        Position l = term_area.upper_left_corner()+Vector(4,5);
769        Position r = l+Vector(6,0);
770
771        for (int i = 0; i<3; ++i) {
772            device->line(ED4_G_STANDARD, l, r, AW_SCREEN);
773            l += Vector( 0, 1);
774            r += Vector( 0, 1);
775            device->line(ED4_G_STANDARD, l, r, AW_SCREEN);
776            l += Vector( 1, 1);
777            r += Vector(-1, 1);
778        }
779        e4_assert(nearlyEqual(l, r));
780        device->line(ED4_G_STANDARD, l, r+Vector(0,1), AW_SCREEN); // arrowhead
781    }
782
783    {
784        Rectangle bracket(term_area.upper_left_corner()+Vector(2,2), term_area.diagonal()+Vector(-2,-4));
785
786        device->line(ED4_G_STANDARD, bracket.upper_edge(), AW_SCREEN);
787        device->line(ED4_G_STANDARD, bracket.lower_edge(), AW_SCREEN);
788        device->line(ED4_G_STANDARD, bracket.left_edge(), AW_SCREEN);
789    }
790}
791
792ED4_species_name_terminal::ED4_species_name_terminal(GB_CSTR temp_id, AW_pos width, AW_pos height, ED4_manager *temp_parent) :
793    ED4_text_terminal(species_name_terminal_spec, temp_id, width, height, temp_parent),
794    selection_info(NULp),
795    dragged(false)
796{}
797
798#define MAXNAMELEN MAXNAME_WIDTH // @@@ seems wrong (MAXNAME_WIDTH contains pixel)
799#define BUFFERSIZE (MAXNAMELEN<<1)
800GB_CSTR ED4_species_name_terminal::get_displayed_text() const {
801    static char *real_name;
802    static int allocatedSize;
803
804    if (!real_name || allocatedSize<(BUFFERSIZE+1)) {
805        free(real_name);
806        allocatedSize = BUFFERSIZE+1;
807        ARB_alloc(real_name, allocatedSize);
808    }
809    memset(real_name, 0, allocatedSize);
810
811    ED4_species_manager *spec_man = get_parent(LEV_SPECIES)->to_species_manager();
812
813    if (spec_man->is_consensus_manager()) {
814        char *db_pointer = resolve_pointer_to_string_copy();
815        char *bracket = strchr(db_pointer, '(');
816
817        if (bracket) {
818            int bracket_len = strlen(bracket);
819            int name_len = bracket-db_pointer;
820
821            if (bracket[-1]==' ') {
822                name_len--;
823            }
824
825            if ((name_len+1+bracket_len)<=MAXNAMELEN) {
826                strcpy(real_name, db_pointer);
827            }
828            else {
829                int short_name_len = MAXNAMELEN-bracket_len-1;
830
831                memcpy(real_name, db_pointer, short_name_len);
832                real_name[short_name_len] = ' ';
833                strcpy(real_name+short_name_len+1, bracket);
834            }
835        }
836        else {
837            strncpy(real_name, db_pointer, BUFFERSIZE);
838        }
839
840        free(db_pointer);
841    }
842    else if (spec_man->is_SAI_manager()) {
843        char *db_pointer = resolve_pointer_to_string_copy();
844
845        strcpy(real_name, "SAI: ");
846        if (strcmp(db_pointer, "ECOLI")==0) {
847            const char *name_for_ecoli = ED4_ROOT->aw_root->awar(ED4_AWAR_NDS_ECOLI_NAME)->read_char_pntr();
848            if (name_for_ecoli[0]==0) name_for_ecoli = db_pointer;
849            strncpy(real_name+5, name_for_ecoli, BUFFERSIZE-5);
850        }
851        else {
852            strncpy(real_name+5, db_pointer, BUFFERSIZE-5);
853        }
854        free(db_pointer);
855    }
856    else { // normal species
857        char *result = ED4_get_NDS_text(spec_man);
858        strncpy(real_name, result, BUFFERSIZE);
859        free(result);
860    }
861
862    return real_name;
863}
864#undef MAXNAMELEN
865#undef BUFFERSIZE
866
867
868ED4_sequence_info_terminal::ED4_sequence_info_terminal(const char *temp_id, AW_pos width, AW_pos height, ED4_manager *temp_parent)
869    : ED4_text_terminal(sequence_info_terminal_spec, temp_id, width, height, temp_parent)
870{}
871
872ED4_consensus_sequence_terminal::ED4_consensus_sequence_terminal(const char *temp_id, AW_pos width, AW_pos height, ED4_manager *temp_parent)
873    : ED4_sequence_terminal(temp_id, width, height, temp_parent, false),
874      temp_cons_seq(NULp)
875{
876    species_name = NULp;
877}
878
879int ED4_consensus_sequence_terminal::get_length() const {
880    return get_char_table().size();
881}
882
883
884ED4_abstract_sequence_terminal::ED4_abstract_sequence_terminal(const ED4_objspec& spec_, const char *temp_id, AW_pos width, AW_pos height, ED4_manager *temp_parent)
885    : ED4_text_terminal(spec_, temp_id, width, height, temp_parent)
886{
887    species_name = NULp;
888}
889
890ED4_abstract_sequence_terminal::~ED4_abstract_sequence_terminal() {
891    free(species_name);
892}
893
894ED4_orf_terminal::ED4_orf_terminal(const char *temp_id, AW_pos width, AW_pos height, ED4_manager *temp_parent)
895    : ED4_abstract_sequence_terminal(orf_terminal_spec, temp_id, width, height, temp_parent)
896{
897    aaSequence   = NULp;
898    aaSeqLen     = 0;
899    aaColor      = NULp;
900    aaStartPos   = 0;
901    aaStrandType = 0;
902}
903
904ED4_orf_terminal::~ED4_orf_terminal() {
905    free(aaSequence);
906    free(aaColor);
907}
908
909ED4_sequence_terminal::ED4_sequence_terminal(const char *temp_id, AW_pos width, AW_pos height, ED4_manager *temp_parent, bool shall_display_secstruct_info_)
910    : ED4_abstract_sequence_terminal(sequence_terminal_spec, temp_id, width, height, temp_parent),
911      shall_display_secstruct_info(shall_display_secstruct_info_)
912{
913    st_ml_node = NULp;
914}
915
916ED4_pure_text_terminal::ED4_pure_text_terminal(const char *temp_id, AW_pos width, AW_pos height, ED4_manager *temp_parent)
917    : ED4_text_terminal(pure_text_terminal_spec, temp_id, width, height, temp_parent)
918{}
919
920#if defined(DEVEL_RALF) && 0
921// # define DEBUG_SPACER_TERMINALS 0 // show placeholder-spacers (normally not drawn)
922// # define DEBUG_SPACER_TERMINALS 1 // show erasing spacers (normally area gets erased)
923# define DEBUG_SPACER_TERMINALS 2 // show all spacers
924#endif
925
926void ED4_spacer_terminal::Show(bool /*refresh_all*/, bool is_cleared) {
927#if defined(DEBUG_SPACER_TERMINALS)
928    if (DEBUG_SPACER_TERMINALS == 1) {
929        if (shallDraw) {
930            draw();
931        }
932        else if (update_info.clear_at_refresh && !is_cleared) {
933            clear_background(0);
934        }
935    }
936    else {
937        draw();
938    }
939#else // !DEBUG_SPACER_TERMINALS
940    if (shallDraw || (update_info.clear_at_refresh && !is_cleared)) {
941        draw();
942    }
943#endif
944}
945
946
947void ED4_spacer_terminal::draw() {
948    int gc = 0;
949#if defined(DEBUG_SPACER_TERMINALS)
950    const int GC_COUNT = ED4_G_LAST_COLOR_GROUP - ED4_G_FIRST_COLOR_GROUP + 1;
951    gc                 = ((long(this)/32)%GC_COUNT)+ED4_G_FIRST_COLOR_GROUP; // draw colored spacers to make them visible
952
953    if (DEBUG_SPACER_TERMINALS != 2) {
954        bool highlight     = bool(DEBUG_SPACER_TERMINALS) == shallDraw;
955        if (!highlight) gc = 0;
956    }
957#endif // DEBUG_SPACER_TERMINALS
958    clear_background(gc);
959}
960
961ED4_spacer_terminal::ED4_spacer_terminal(const char *temp_id, bool shallDraw_, AW_pos width, AW_pos height, ED4_manager *temp_parent)
962    : ED4_terminal(spacer_terminal_spec, temp_id, width, height, temp_parent),
963      shallDraw(shallDraw_)
964{
965    // 'shallDraw_'==true is only needed in very special cases,
966    // eg. for 'Top_Middle_Spacer' (to remove overlapping relicts from half-displayed species below)
967}
968
969void ED4_line_terminal::draw() {
970    AW_pos x1, y1;
971    calc_world_coords(&x1, &y1);
972    current_ed4w()->world_to_win_coords(&x1, &y1);
973
974    AW_pos x2 = x1+extension.size[WIDTH]-1;
975    AW_pos y2 = y1+extension.size[HEIGHT]-1;
976
977    AW_device *device = current_device();
978
979    device->line(ED4_G_STANDARD, x1, y1, x2, y1);
980#if defined(DEBUG)
981    device->box(ED4_G_MARKED, AW::FillStyle::SOLID, x1, y1+1, x2-x1+1, y2-y1-1);
982#else
983    device->clear_part(x1, y1+1, x2-x1+1, y2-y1-1, AW_ALL_DEVICES);
984#endif // DEBUG
985    device->line(ED4_G_STANDARD, x1, y2, x2, y2);
986}
987
988ED4_line_terminal::ED4_line_terminal(const char *temp_id, AW_pos width, AW_pos height, ED4_manager *temp_parent)
989    : ED4_terminal(line_terminal_spec, temp_id, width, height, temp_parent)
990{}
991
992// ---------------------------------
993//      ED4_columnStat_terminal
994
995inline char stat2display(int val, bool is_upper_digit) {
996    if (val<0) {
997        e4_assert(val==-1); // -1 indicates that no statistic is existing for that column
998        return '?';
999    }
1000    if (val==20) return ' '; // value if ACGT and - are distributed equally
1001    if (val==100) return '^'; // we have only 2 characters to display likelihood (100 cannot be displayed)
1002
1003    e4_assert(val>=0 && val<100);
1004
1005    return '0' + (is_upper_digit ? (val/10) : (val%10));
1006}
1007
1008inline int find_significant_positions(int sig, int like_A, int like_C, int like_G, int like_TU, int *sumPtr) {
1009    // result == 0      -> no base-char has a significant likelihood (>=sig)
1010    // result == 1, 2, 4, 8     -> A, C, G, T/U has a significant likelihood
1011    // else             -> the sum two of the likelihoods >= sig (bit-or-ed as in line above)
1012
1013    int like[4];
1014    like[0] = like_A;
1015    like[1] = like_C;
1016    like[2] = like_G;
1017    like[3] = like_TU;
1018
1019    int bestSum = 0;
1020    int bestResult = 0;
1021
1022    int b, c;
1023    for (b=0; b<4; b++) {
1024        int sum = like[b];
1025        if (sum>=sig && sum>=bestSum) {
1026            bestSum = sum;
1027            bestResult = 1<<b;
1028        }
1029    }
1030
1031    if (!bestResult) {
1032        for (b=0; b<4; b++) {
1033            for (c=b+1; c<4; c++) {
1034                int sum = like[b]+like[c];
1035                if (sum>=sig && sum>=bestSum) {
1036                    bestSum = sum;
1037                    bestResult = (1<<b)|(1<<c);
1038                }
1039            }
1040        }
1041    }
1042
1043    if (bestResult) {
1044        if (sumPtr) *sumPtr = bestSum;
1045        return bestResult;
1046    }
1047
1048    return 0;
1049}
1050
1051void ED4_columnStat_terminal::draw() {
1052    AW_pos x, y;
1053    calc_world_coords(&x, &y);
1054    current_ed4w()->world_to_win_coords(&x, &y);
1055
1056    AW_pos term_height = extension.size[HEIGHT];
1057    AW_pos font_height = ED4_ROOT->font_group.get_height(ED4_G_SEQUENCES);
1058    AW_pos font_width  = ED4_ROOT->font_group.get_width(ED4_G_SEQUENCES);
1059
1060    AW_pos text_x = x + CHARACTEROFFSET;
1061    AW_pos text_y = y + term_height - font_height;
1062
1063    AW_device *device = current_device();
1064
1065    if (!update_likelihood()) {
1066        const char *warning = "Failed to calculate likelihood";
1067
1068        device->text(ED4_G_STANDARD, warning, text_x, text_y, 0, AW_SCREEN);
1069        return;
1070    }
1071
1072    ED4_sequence_terminal *seq_term = corresponding_sequence_terminal();
1073    const ED4_remap       *rm       = ED4_ROOT->root_group_man->remap();
1074
1075    PosRange index_range = rm->clip_screen_range(seq_term->calc_update_interval());
1076    {
1077        int max_seq_len = seq_term->get_length();
1078        int max_seq_pos = rm->sequence_to_screen(max_seq_len);
1079
1080        index_range = ExplicitRange(index_range, max_seq_pos);
1081        if (index_range.is_empty()) return; // nothing to draw
1082    }
1083
1084    const int left  = index_range.start();
1085    const int right = index_range.end();
1086
1087    char *sbuffer = new char[right+2];  // used to build displayed terminal content  (values = '0'-'9')
1088    memset(sbuffer, ' ', right+1);
1089    sbuffer[right+1] = 0; // eos
1090
1091    AW_pos y2;
1092    int r;
1093
1094    // Set background:
1095    {
1096        int significance = int(get_threshold());
1097        // normal columns are colored in ED4_G_STANDARD
1098        // all columns with one (or sum of two) probability above 'significance' are back-colored in ED4_G_CBACK_0
1099        // the responsible probabilities (one or two) are back-colored in ED4_G_CBACK_1..ED4_G_CBACK_9
1100
1101        int old_color = ED4_G_STANDARD;
1102
1103        AW_pos x2     = text_x + font_width*left + 1;
1104        AW_pos old_x2 = x2;
1105
1106        PosRange selection;
1107        bool     is_selected = ED4_get_selected_range(seq_term, selection);
1108
1109        for (int i=left; i<=right; i++, x2+=font_width) { // colorize significant columns in ALL rows
1110            int p     = rm->screen_to_sequence(i);
1111            int found = find_significant_positions(significance, likelihood[0][p], likelihood[1][p], likelihood[2][p], likelihood[3][p], NULp);
1112
1113            int color;
1114            if (is_selected && selection.contains(p)) {
1115                color = ED4_G_SELECTED;
1116            }
1117            else {
1118                color = found ? ED4_G_CBACK_0 : ED4_G_STANDARD;
1119            }
1120
1121            if (color!=old_color) {
1122                if (x2>old_x2 && old_color!=ED4_G_STANDARD) {
1123                    device->box(old_color, AW::FillStyle::SOLID, old_x2, y, x2-old_x2, term_height);
1124                }
1125                old_color = color;
1126                old_x2 = x2;
1127            }
1128        }
1129        if (x2>old_x2 && old_color!=ED4_G_STANDARD) {
1130            device->box(old_color, AW::FillStyle::SOLID, old_x2, y, x2-old_x2, term_height);
1131        }
1132
1133        x2 = text_x + font_width*left + 1;
1134
1135        for (int i=left; i<=right; i++, x2+=font_width) { // colorize significant columns in SINGLE rows
1136            int p = rm->screen_to_sequence(i);
1137            int sum;
1138            int found = find_significant_positions(significance, likelihood[0][p], likelihood[1][p], likelihood[2][p], likelihood[3][p], &sum);
1139
1140            if (found && significance<100) {
1141                e4_assert(sum>=significance && sum<=100);
1142                int color = ED4_G_CBACK_1+((sum-significance)*(ED4_G_CBACK_9-ED4_G_CBACK_1))/(100-significance);
1143                e4_assert(color>=ED4_G_CBACK_1 && color<=ED4_G_CBACK_9);
1144
1145                if (color!=ED4_G_STANDARD) {
1146                    int bit;
1147
1148                    for (r=3, y2=text_y+1, bit=1<<3;
1149                         r>=0;
1150                         r--, y2-=COLUMN_STAT_ROW_HEIGHT(font_height), bit>>=1)
1151                    {
1152                        if (found&bit) {
1153                            device->box(color, AW::FillStyle::SOLID, x2, y2-2*font_height+1, font_width, 2*font_height);
1154                        }
1155                    }
1156                }
1157            }
1158        }
1159    }
1160
1161    // Draw text:
1162    for (r=3, y2=text_y;
1163         r>=0;
1164         r--, y2-=COLUMN_STAT_ROW_HEIGHT(font_height)) { // 4 rows (one for T/U, G, C and A)
1165
1166        int gc = ED4_ROOT->sequence_colors->char_2_gc[(unsigned char)"ACGU"[r]];
1167        int i;
1168        for (i=left; i<=right; i++) {
1169            int p = rm->screen_to_sequence(i);
1170            int val = likelihood[r][p];
1171            sbuffer[i] = stat2display(val, 0); // calc lower digit
1172        }
1173
1174        device->text(gc, SizedCstr(sbuffer, right), text_x+font_width*0.2, y2, 0, AW_SCREEN); // draw lower-significant digit (shifted a bit to the right)
1175
1176        for (i=left; i<=right; i++) {
1177            int p = rm->screen_to_sequence(i);
1178            int val = likelihood[r][p];
1179            sbuffer[i] = stat2display(val, 1); // calc upper digit
1180        }
1181        device->text(gc, SizedCstr(sbuffer, right), text_x, y2-font_height, 0, AW_SCREEN); // draw higher-significant digit
1182    }
1183
1184    delete [] sbuffer;
1185}
1186
1187int ED4_columnStat_terminal::update_likelihood() {
1188    ED4_sequence_terminal *seq_term = corresponding_sequence_terminal();
1189
1190    return STAT_update_ml_likelihood(ED4_ROOT->st_ml, likelihood, latest_update, NULp, seq_term->st_ml_node);
1191}
1192
1193ED4_columnStat_terminal::ED4_columnStat_terminal(GB_CSTR temp_id, AW_pos width, AW_pos height, ED4_manager *temp_parent) :
1194    ED4_text_terminal(column_stat_terminal_spec, temp_id, width, height, temp_parent)
1195{
1196    for (int i=0; i<4; i++) likelihood[i] = NULp;
1197    latest_update = 0;
1198}
1199
1200ED4_columnStat_terminal::~ED4_columnStat_terminal() {
1201    for (int i=0; i<4; i++) free(likelihood[i]);
1202}
1203
1204// ------------------------
1205//      flag terminals
1206
1207ED4_flag_header_terminal::ED4_flag_header_terminal(GB_CSTR id_, AW_pos width, AW_pos height, ED4_manager *parent_) :
1208    ED4_text_terminal(flag_header_spec, id_, width, height, parent_)
1209{}
1210
1211GB_CSTR ED4_flag_header_terminal::get_displayed_text() const {
1212    return SpeciesFlags::instance().get_header_text();
1213}
1214int ED4_flag_header_terminal::get_length() const {
1215    return SpeciesFlags::instance().get_header_length();
1216}
1217
1218ED4_flag_terminal::ED4_flag_terminal(const char *id_, AW_pos width, AW_pos height, ED4_manager *parent_) :
1219    ED4_terminal(flag_spec, id_, width, height, parent_)
1220{}
1221
1222using namespace AW;
1223
1224class FlagLayout {
1225    double    flag_centerx; // flag x-position relative to terminal
1226    Rectangle box;          // box at flag_centerx
1227
1228public:
1229    FlagLayout(const Rectangle& area, const SpeciesFlags& flags) {
1230        double boxsize = std::max(1.0, std::min(double(flags.get_min_flag_distance()), area.height()*0.95));
1231        Vector box_diag(boxsize, -boxsize);
1232
1233        SpeciesFlagCiter curr_flag  = flags.begin();
1234        flag_centerx                = curr_flag->center_xpos();
1235        Position         box_center = area.left_edge().centroid() + Vector(flag_centerx, 0);
1236        box                         = Rectangle(box_center-box_diag/2, box_diag);
1237    }
1238
1239    void move_box(double new_flag_centerx) {
1240        box.move(Vector(new_flag_centerx - flag_centerx, 0));
1241        flag_centerx = new_flag_centerx;
1242    }
1243
1244    const Rectangle& get_box() const { return box; }
1245};
1246
1247void ED4_flag_terminal::draw() {
1248    const SpeciesFlags& flags = SpeciesFlags::instance();
1249
1250    int boxes = flags.size();
1251    if (boxes>0) {
1252        FlagLayout layout(get_win_area(current_ed4w()), flags);
1253
1254        SpeciesFlagCiter curr_flag = flags.begin();
1255        SpeciesFlagCiter end       = flags.end();
1256
1257        AW_device *device = current_device();
1258
1259        GBDATA   *gb_species = get_species();
1260        GB_ERROR  error      = NULp;
1261
1262        for (int b = 0; b<boxes && !error; ++b) {
1263            bool filled = false;
1264            {
1265                GBDATA *gb_field = GB_entry(gb_species, curr_flag->get_fieldname().c_str());
1266                if (gb_field) {
1267                    uint8_t as_byte  = GB_read_lossless_byte(gb_field, error);
1268                    if (error) error = GBS_global_string("Failed to read flag value (Reason: %s)", error);
1269                    else    filled   = as_byte;
1270                }
1271            }
1272
1273            if (filled) device->box(ED4_G_FLAG_FILL,  FillStyle::SOLID, layout.get_box(), AW_SCREEN); // filled?
1274            device->box(            ED4_G_FLAG_FRAME, FillStyle::EMPTY, layout.get_box(), AW_SCREEN); // frame
1275
1276            ++curr_flag;
1277            if (curr_flag != end) layout.move_box(curr_flag->center_xpos());
1278        }
1279
1280        aw_message_if(error);
1281    }
1282}
1283
1284void ED4_flag_terminal::handle_left_click(const Position& click) {
1285    const SpeciesFlags& flags = SpeciesFlags::instance();
1286
1287    int boxes = flags.size();
1288    if (boxes>0) {
1289        FlagLayout layout(get_win_area(current_ed4w()), flags);
1290
1291        SpeciesFlagCiter curr_flag = flags.begin();
1292        SpeciesFlagCiter end       = flags.end();
1293
1294        for (int b = 0; b<boxes; ++b) {
1295            if (layout.get_box().contains(click)) break;
1296            ++curr_flag;
1297            if (curr_flag != end) layout.move_box(curr_flag->center_xpos());
1298        }
1299
1300        if (curr_flag != end) {
1301            GBDATA   *gb_species = get_species();
1302            GBDATA   *gb_field   = GB_entry(gb_species, curr_flag->get_fieldname().c_str());
1303            GB_ERROR  error      = GB_incur_error_if(!gb_field);
1304
1305            if (!error && !gb_field) {
1306                const char *key   = curr_flag->prepare_itemfield(); // impl using prepare_and_get_selected_itemfield
1307                if (key) gb_field = GBT_searchOrCreate_itemfield_according_to_changekey(gb_species, key, SPECIES_get_selector().change_key_path);
1308                error             = GB_incur_error_if(!gb_field);
1309            }
1310
1311            if (gb_field) {
1312                uint8_t val       = GB_read_lossless_byte(gb_field, error);
1313                if (!error) error = GB_write_lossless_byte(gb_field, !val);
1314            }
1315
1316            aw_message_if(error);
1317            if (!error) request_refresh();
1318        }
1319    }
1320}
1321
1322// ---------------------------------
1323//      ED4_reference_terminals
1324
1325void ED4_reference_terminals::clear() {
1326    delete ref_sequence_info;
1327    delete ref_sequence;
1328    delete ref_column_stat;
1329    delete ref_column_stat_info;
1330    null();
1331}
1332
1333void ED4_reference_terminals::init(ED4_sequence_info_terminal *ref_sequence_info_,
1334                                   ED4_sequence_terminal *ref_sequence_,
1335                                   ED4_sequence_info_terminal *ref_column_stat_info_,
1336                                   ED4_columnStat_terminal *ref_column_stat_)
1337{
1338    clear();
1339    ref_sequence_info    = ref_sequence_info_;
1340    ref_sequence     = ref_sequence_;
1341    ref_column_stat_info = ref_column_stat_info_;
1342    ref_column_stat      = ref_column_stat_;
1343}
Note: See TracBrowser for help on using the repository browser.