ARB
info_window.cxx
Go to the documentation of this file.
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 
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 
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) {
63  }
64 }
65 
68  getSelector().add_selection_changed_cb(get_root(), makeRootCallback(map_item_cb, this));
69 }
70 
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()) {
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 
#define arb_assert(cond)
Definition: arb_assert.h:245
const char * item_name
Definition: items.h:66
void button_length(int length)
Definition: AW_at.cxx:288
const InfoWindow * find_maininfo_of_same_type_as(const InfoWindow &other)
Definition: info_window.h:179
bool is_detached() const
Definition: info_window.h:81
const char * get_mapped_itemID_awarname() const
Definition: db_scanner.hxx:159
static void map_item_cb(AW_root *, const InfoWindow *infoWin)
Definition: info_window.cxx:22
void bind_to_selected_item() const
Definition: info_window.cxx:66
static const int MAIN_WINDOW
Definition: info_window.h:67
void on_hide(const WindowCallback &call_on_hide)
Definition: AW_window.cxx:1850
static void unlock_detached_cb(AW_window *, const InfoWindow *infoWin)
Definition: info_window.cxx:94
void(* add_selection_changed_cb)(AW_root *aw_root, const RootCallback &cb)
Definition: items.h:77
const char * GBS_global_string(const char *templat,...)
Definition: arb_msg.cxx:203
void hide() const
Definition: info_window.h:126
void(* detached_uppopper)(AW_window *, const InfoWindow *)
Definition: info_window.h:69
void init_info_window(AW_root *aw_root, AW_window_simple_menu *aws, const ItemSelector &itemType, int detach_id)
Definition: info_window.cxx:36
bool is_used() const
Definition: info_window.h:87
void map_selected_item() const
Definition: info_window.h:109
static InfoWindowRegistry infowin
Definition: info_window.h:187
void attach_selected_item() const
Definition: info_window.h:110
bool is_maininfo() const
Definition: info_window.h:82
const InfoWindow * find(AW_window *aww)
Definition: info_window.h:154
void detach_selected_item(detached_uppopper popup_detached_cb) const
Definition: info_window.cxx:79
static void store_unused_detached_info_window_cb(AW_window *aw_detached)
Definition: info_window.cxx:26
char * ARB_strupper(char *s)
Definition: arb_str.h:63
static void detach_selected_item_cb(AW_window *, InfoWindow::detached_uppopper popup_detached_cb, const InfoWindow *infoWin)
Definition: info_window.cxx:88
void create_autosize_button(const char *macro_name, AW_label label, const char *mnemonic=NULp, unsigned xtraSpace=1)
Definition: AW_button.cxx:421
void auto_space(int xspace, int yspace)
Definition: AW_at.cxx:259
void aw_message(const char *msg)
Definition: AW_status.cxx:1142
void add_detach_area(detached_uppopper popup_detached_cb) const
#define NULp
Definition: cxxforward.h:116
GBDATA * get_selected_item() const
Definition: info_window.h:100
void callback(const WindowCallback &cb)
Definition: AW_window.cxx:133
static void display_selected_item_cb(AW_window *, const InfoWindow *infoWin)
Definition: info_window.cxx:91
void display_selected_item() const
Definition: info_window.cxx:71
void init(AW_root *root, const char *wid, const char *windowname)
Definition: AW_window.cxx:2845
char * GBS_global_string_copy(const char *templat,...)
Definition: arb_msg.cxx:194
void map_item(GBDATA *gb_item) const
Definition: info_window.h:106
void set_used(bool used_) const
Definition: info_window.h:88
void create_button(const char *macro_name, AW_label label, const char *mnemonic=NULp, const char *color=NULp)
Definition: AW_button.cxx:448