1 | // ============================================================ // |
---|
2 | // // |
---|
3 | // File : info_window.cxx // |
---|
4 | // Purpose : // |
---|
5 | // // |
---|
6 | // Coded by Ralf Westram (coder@reallysoft.de) in July 2013 // |
---|
7 | // Institute of Microbiology (Technical University Munich) // |
---|
8 | // http://www.arb-home.de/ // |
---|
9 | // // |
---|
10 | // ============================================================ // |
---|
11 | |
---|
12 | #include "info_window.h" |
---|
13 | #include <dbui.h> |
---|
14 | #include <arb_str.h> |
---|
15 | #include <aw_msg.hxx> |
---|
16 | |
---|
17 | InfoWindowRegistry InfoWindowRegistry::infowin; |
---|
18 | |
---|
19 | // ------------------------------------------------ |
---|
20 | // item-independent info window callbacks |
---|
21 | |
---|
22 | static void map_item_cb(AW_root *, const InfoWindow *infoWin) { |
---|
23 | infoWin->map_selected_item(); |
---|
24 | } |
---|
25 | |
---|
26 | static void store_unused_detached_info_window_cb(AW_window *aw_detached) { |
---|
27 | const InfoWindow *infoWin = InfoWindowRegistry::infowin.find(aw_detached); |
---|
28 | arb_assert(infoWin); // forgot to registerInfoWindow? |
---|
29 | if (infoWin) { |
---|
30 | arb_assert(infoWin->is_used()); |
---|
31 | infoWin->set_used(false); |
---|
32 | infoWin->map_item(NULp); |
---|
33 | } |
---|
34 | } |
---|
35 | |
---|
36 | void DBUI::init_info_window(AW_root *aw_root, AW_window_simple_menu *aws, const ItemSelector& itemType, int detach_id) { |
---|
37 | char *window_id; |
---|
38 | char *window_title; |
---|
39 | { |
---|
40 | const char *itemname = itemType.item_name; |
---|
41 | char *ITEMNAME = ARB_strupper(strdup(itemname)); |
---|
42 | |
---|
43 | if (detach_id == InfoWindow::MAIN_WINDOW) { |
---|
44 | char *Itemname = strdup(itemname); Itemname[0] = ITEMNAME[0]; |
---|
45 | window_id = GBS_global_string_copy("%s_INFORMATION", ITEMNAME); |
---|
46 | window_title = GBS_global_string_copy("%s information", Itemname); |
---|
47 | free(Itemname); |
---|
48 | } |
---|
49 | else { |
---|
50 | window_id = GBS_global_string_copy("%s_INFODETACH_%i", ITEMNAME, detach_id); |
---|
51 | window_title = strdup("<detaching>"); |
---|
52 | } |
---|
53 | free(ITEMNAME); |
---|
54 | } |
---|
55 | |
---|
56 | aws->init(aw_root, window_id, window_title); |
---|
57 | |
---|
58 | free(window_title); |
---|
59 | free(window_id); |
---|
60 | |
---|
61 | if (!detach_id == InfoWindow::MAIN_WINDOW) { |
---|
62 | aws->on_hide(store_unused_detached_info_window_cb); |
---|
63 | } |
---|
64 | } |
---|
65 | |
---|
66 | void InfoWindow::bind_to_selected_item() const { |
---|
67 | arb_assert(is_maininfo()); |
---|
68 | getSelector().add_selection_changed_cb(get_root(), makeRootCallback(map_item_cb, this)); |
---|
69 | } |
---|
70 | |
---|
71 | void InfoWindow::display_selected_item() const { |
---|
72 | arb_assert(is_detached()); |
---|
73 | attach_selected_item(); |
---|
74 | if (!get_selected_item()) { |
---|
75 | aw_message(GBS_global_string("Please select a %s, afterwards retry to attach it here", itemname())); |
---|
76 | } |
---|
77 | } |
---|
78 | |
---|
79 | void InfoWindow::detach_selected_item(detached_uppopper popup_detached_cb) const { |
---|
80 | if (get_selected_item()) { |
---|
81 | popup_detached_cb(aww, this); |
---|
82 | } |
---|
83 | else { |
---|
84 | aw_message(GBS_global_string("Please select a %s, afterwards retry to detach it", itemname())); |
---|
85 | } |
---|
86 | } |
---|
87 | |
---|
88 | static void detach_selected_item_cb(AW_window *, InfoWindow::detached_uppopper popup_detached_cb, const InfoWindow *infoWin) { |
---|
89 | infoWin->detach_selected_item(popup_detached_cb); |
---|
90 | } |
---|
91 | static void display_selected_item_cb(AW_window *, const InfoWindow *infoWin) { |
---|
92 | infoWin->display_selected_item(); |
---|
93 | } |
---|
94 | static void unlock_detached_cb(AW_window *, const InfoWindow *infoWin) { |
---|
95 | arb_assert(infoWin->is_detached()); |
---|
96 | |
---|
97 | const InfoWindow *mainInfo = InfoWindowRegistry::infowin.find_maininfo_of_same_type_as(*infoWin); |
---|
98 | arb_assert(mainInfo); |
---|
99 | if (mainInfo) { |
---|
100 | mainInfo->reactivate(); |
---|
101 | infoWin->hide(); |
---|
102 | } |
---|
103 | } |
---|
104 | |
---|
105 | void InfoWindow::add_detach_area(detached_uppopper popup_detached_cb) const { |
---|
106 | aww->auto_space(5, 5); |
---|
107 | |
---|
108 | if (is_maininfo()) { |
---|
109 | bind_to_selected_item(); |
---|
110 | |
---|
111 | aww->callback(makeWindowCallback(detach_selected_item_cb, popup_detached_cb, this)); |
---|
112 | aww->create_autosize_button("DETACH", "Lock view", "L"); |
---|
113 | } |
---|
114 | else { |
---|
115 | aww->callback(makeWindowCallback(display_selected_item_cb, this)); |
---|
116 | aww->create_autosize_button("GET", "Update", "U"); |
---|
117 | } |
---|
118 | |
---|
119 | aww->button_length(20); |
---|
120 | aww->create_button(NULp, scanner->get_mapped_itemID_awarname(), NULp, is_maininfo() ? "+" : "#fc8"); |
---|
121 | |
---|
122 | if (!is_maininfo()) { |
---|
123 | aww->callback(makeWindowCallback(unlock_detached_cb, this)); |
---|
124 | aww->create_autosize_button("UNLOCK", "Unlock", "k"); |
---|
125 | } |
---|
126 | } |
---|
127 | |
---|