1 | #ifndef AW_WINDOW_XM_HXX |
---|
2 | #define AW_WINDOW_XM_HXX |
---|
3 | |
---|
4 | #ifndef AW_DEVICE_HXX |
---|
5 | #include <aw_device.hxx> |
---|
6 | #endif |
---|
7 | #ifndef AW_KEYSYM_HXX |
---|
8 | #include <aw_keysym.hxx> |
---|
9 | #endif |
---|
10 | #ifndef _Xm_h |
---|
11 | #include <Xm/Xm.h> |
---|
12 | #endif |
---|
13 | #ifndef CB_H |
---|
14 | #include <cb.h> |
---|
15 | #endif |
---|
16 | #ifndef AW_SCALAR_HXX |
---|
17 | #include "aw_scalar.hxx" |
---|
18 | #endif |
---|
19 | #ifndef ARB_MSG_H |
---|
20 | #include <arb_msg.h> |
---|
21 | #endif |
---|
22 | |
---|
23 | // macro definitions |
---|
24 | #define p_r prvt |
---|
25 | #define p_global (root->prvt) |
---|
26 | #define p_aww(aww) (aww->p_w) |
---|
27 | |
---|
28 | #define MAP_ARAM(ar) p_w->areas[ar] |
---|
29 | |
---|
30 | #define INFO_WIDGET p_w->areas[AW_INFO_AREA]->get_area() |
---|
31 | #define INFO_FORM p_w->areas[AW_INFO_AREA]->get_form() |
---|
32 | #define MIDDLE_WIDGET p_w->areas[AW_MIDDLE_AREA]->get_area() |
---|
33 | #define BOTTOM_WIDGET p_w->areas[AW_BOTTOM_AREA]->get_area() |
---|
34 | |
---|
35 | #define AW_SCROLL_MAX 100 |
---|
36 | #define AW_MAX_MENU_DEEP 10 |
---|
37 | |
---|
38 | #define RES_CONVERT(res_name, res_value) \ |
---|
39 | XtVaTypedArg, (res_name), XmRString, (res_value), strlen(res_value) + 1 |
---|
40 | |
---|
41 | #define AW_MOTIF_LABEL |
---|
42 | |
---|
43 | class Label : virtual Noncopyable { |
---|
44 | char *label; |
---|
45 | int len; |
---|
46 | bool imageref; |
---|
47 | public: |
---|
48 | Label(const char *labeltext, AW_window *aww); |
---|
49 | ~Label() { free(label); } |
---|
50 | |
---|
51 | size_t length() const { return len; } |
---|
52 | const char *String() const { return label; } |
---|
53 | bool is_imageref() const { return imageref; } |
---|
54 | }; |
---|
55 | |
---|
56 | |
---|
57 | #define RES_LABEL_CONVERT(label) \ |
---|
58 | XmNlabelType, label.is_imageref() ? XmPIXMAP : XmSTRING, \ |
---|
59 | XtVaTypedArg, label.is_imageref() ? XmNlabelPixmap : XmNlabelString, \ |
---|
60 | XmRString, \ |
---|
61 | label.String(), \ |
---|
62 | label.length()+1 |
---|
63 | |
---|
64 | #define AW_JUSTIFY_LABEL(widget, corr) \ |
---|
65 | switch (corr) { \ |
---|
66 | case 1: XtVaSetValues(widget, XmNalignment, XmALIGNMENT_CENTER, NULp); break; \ |
---|
67 | case 2: XtVaSetValues(widget, XmNalignment, XmALIGNMENT_END, NULp); break; \ |
---|
68 | default: break; \ |
---|
69 | } |
---|
70 | |
---|
71 | |
---|
72 | struct AW_buttons_struct : virtual Noncopyable { |
---|
73 | AW_buttons_struct(AW_active maski, Widget w, AW_buttons_struct *next); |
---|
74 | ~AW_buttons_struct(); |
---|
75 | |
---|
76 | AW_active mask; |
---|
77 | Widget button; |
---|
78 | AW_buttons_struct *next; |
---|
79 | }; |
---|
80 | |
---|
81 | struct AW_widget_value_pair : virtual Noncopyable { |
---|
82 | template<typename T> explicit AW_widget_value_pair(T t, Widget w) : value(t), widget(w), next(NULp) {} |
---|
83 | ~AW_widget_value_pair() { aw_assert(!next); } // has to be unlinked from list BEFORE calling dtor |
---|
84 | |
---|
85 | AW_scalar value; |
---|
86 | Widget widget; |
---|
87 | |
---|
88 | AW_widget_value_pair *next; |
---|
89 | }; |
---|
90 | |
---|
91 | struct AW_option_menu_struct { |
---|
92 | AW_option_menu_struct(int numberi, const char *variable_namei, AW_VARIABLE_TYPE variable_typei, Widget label_widgeti, Widget menu_widgeti, AW_pos xi, AW_pos yi, int correct); |
---|
93 | |
---|
94 | int option_menu_number; |
---|
95 | char *variable_name; |
---|
96 | AW_VARIABLE_TYPE variable_type; |
---|
97 | Widget label_widget; |
---|
98 | Widget menu_widget; |
---|
99 | |
---|
100 | AW_widget_value_pair *first_choice; |
---|
101 | AW_widget_value_pair *last_choice; |
---|
102 | AW_widget_value_pair *default_choice; |
---|
103 | |
---|
104 | AW_pos x; |
---|
105 | AW_pos y; |
---|
106 | int correct_for_at_center_intern; // needed for centered and right justified menus (former member of AW_at) |
---|
107 | |
---|
108 | AW_option_menu_struct *next; |
---|
109 | }; |
---|
110 | |
---|
111 | |
---|
112 | struct AW_toggle_field_struct { |
---|
113 | AW_toggle_field_struct(int toggle_field_numberi, const char *variable_namei, AW_VARIABLE_TYPE variable_typei, Widget label_widgeti, int correct); |
---|
114 | |
---|
115 | int toggle_field_number; |
---|
116 | char *variable_name; |
---|
117 | AW_VARIABLE_TYPE variable_type; |
---|
118 | Widget label_widget; |
---|
119 | |
---|
120 | AW_widget_value_pair *first_toggle; |
---|
121 | AW_widget_value_pair *last_toggle; |
---|
122 | AW_widget_value_pair *default_toggle; |
---|
123 | |
---|
124 | int correct_for_at_center_intern; // needed for centered and right justified toggle fields (former member of AW_at) |
---|
125 | |
---|
126 | AW_toggle_field_struct *next; |
---|
127 | }; |
---|
128 | |
---|
129 | |
---|
130 | // ------------------------------------------- |
---|
131 | // area management: devices callbacks |
---|
132 | |
---|
133 | class AW_common_Xm; |
---|
134 | class AW_device_Xm; |
---|
135 | class AW_cb; |
---|
136 | |
---|
137 | class AW_area_management { |
---|
138 | Widget form; // for resizing |
---|
139 | Widget area; // for displaying additional information |
---|
140 | |
---|
141 | AW_common_Xm *common; |
---|
142 | |
---|
143 | AW_device_Xm *device; |
---|
144 | AW_device_size *size_device; |
---|
145 | AW_device_print *print_device; |
---|
146 | AW_device_click *click_device; |
---|
147 | |
---|
148 | AW_cb *expose_cb; |
---|
149 | AW_cb *resize_cb; |
---|
150 | AW_cb *double_click_cb; |
---|
151 | |
---|
152 | long click_time; |
---|
153 | |
---|
154 | public: |
---|
155 | AW_area_management(Widget form, Widget widget); |
---|
156 | |
---|
157 | Widget get_form() const { return form; } |
---|
158 | Widget get_area() const { return area; } |
---|
159 | |
---|
160 | AW_common_Xm *get_common() const { return common; } |
---|
161 | |
---|
162 | AW_device_Xm *get_screen_device(); |
---|
163 | AW_device_size *get_size_device(); |
---|
164 | AW_device_print *get_print_device(); |
---|
165 | AW_device_click *get_click_device(); |
---|
166 | |
---|
167 | void create_devices(AW_window *aww, AW_area ar); |
---|
168 | |
---|
169 | void set_expose_callback(AW_window *aww, const WindowCallback& cb); |
---|
170 | void set_resize_callback(AW_window *aww, const WindowCallback& cb); |
---|
171 | |
---|
172 | void set_input_callback(AW_window *aww, const WindowCallback& wcb); |
---|
173 | void set_double_click_callback(AW_window *aww, const WindowCallback& wcb); |
---|
174 | void set_motion_callback(AW_window *aww, const WindowCallback& wcb); |
---|
175 | |
---|
176 | bool is_expose_callback(AnyWinCB f); |
---|
177 | bool is_resize_callback(AnyWinCB f); |
---|
178 | |
---|
179 | void run_expose_callback(); |
---|
180 | void run_resize_callback(); |
---|
181 | |
---|
182 | AW_cb *get_double_click_cb() { return double_click_cb; } |
---|
183 | long get_click_time() const { return click_time; } |
---|
184 | void set_click_time(long click_time_) { click_time = click_time_; } |
---|
185 | }; |
---|
186 | |
---|
187 | class AW_selection_list; |
---|
188 | |
---|
189 | class AW_root_Motif : virtual Noncopyable { |
---|
190 | Widget last_widget; // last created (sensitive) widget |
---|
191 | public: |
---|
192 | Display *display; |
---|
193 | XtAppContext context; |
---|
194 | Widget toplevel_widget; |
---|
195 | Widget main_widget; |
---|
196 | class AW_window *main_aww; |
---|
197 | Widget message_shell; |
---|
198 | |
---|
199 | Pixel foreground; |
---|
200 | Pixel background; |
---|
201 | |
---|
202 | XmFontList fontlist; |
---|
203 | |
---|
204 | AW_option_menu_struct *option_menu_list; |
---|
205 | AW_option_menu_struct *last_option_menu; |
---|
206 | AW_option_menu_struct *current_option_menu; |
---|
207 | |
---|
208 | AW_toggle_field_struct *toggle_field_list; |
---|
209 | AW_toggle_field_struct *last_toggle_field; |
---|
210 | |
---|
211 | AW_selection_list *selection_list; |
---|
212 | AW_selection_list *last_selection_list; |
---|
213 | |
---|
214 | int screen_depth; |
---|
215 | AW_rgb *color_table; |
---|
216 | Colormap colormap; |
---|
217 | |
---|
218 | int help_active; |
---|
219 | Cursor clock_cursor; |
---|
220 | Cursor question_cursor; |
---|
221 | Display *old_cursor_display; |
---|
222 | Window old_cursor_window; |
---|
223 | bool no_exit; |
---|
224 | |
---|
225 | GB_HASH *action_hash; |
---|
226 | |
---|
227 | AW_root_Motif(); |
---|
228 | ~AW_root_Motif(); |
---|
229 | |
---|
230 | Widget get_last_widget() const { return last_widget; } |
---|
231 | void set_last_widget(Widget w) { last_widget = w; } |
---|
232 | |
---|
233 | void set_cursor(Display *d, Window w, Cursor c); |
---|
234 | void normal_cursor(); |
---|
235 | }; |
---|
236 | |
---|
237 | const int AW_NUMBER_OF_F_KEYS = 20; |
---|
238 | #define AW_CALC_OFFSET_ON_EXPOSE -12345 |
---|
239 | |
---|
240 | class AW_window_Motif : virtual Noncopyable { |
---|
241 | public: |
---|
242 | |
---|
243 | Widget shell; // for show, hide |
---|
244 | Widget scroll_bar_vertical; // for scrolling the |
---|
245 | Widget scroll_bar_horizontal; // draw area |
---|
246 | Widget menu_bar[AW_MAX_MENU_DEEP]; // for inserting topics to menu bar |
---|
247 | int menu_deep; |
---|
248 | Widget help_pull_down; // for inserting subtopics to the help pull_down |
---|
249 | Widget mode_area; // for inserting buttons to the mode area |
---|
250 | short number_of_modes; // holds number of mode buttons in window |
---|
251 | |
---|
252 | // ********** local modifiers ********** |
---|
253 | |
---|
254 | AW_cb **modes_f_callbacks; |
---|
255 | Widget *modes_widgets; |
---|
256 | int selected_mode; |
---|
257 | AW_cb *popup_cb; |
---|
258 | Widget frame; |
---|
259 | |
---|
260 | Widget toggle_field; |
---|
261 | Widget toggle_label; |
---|
262 | char *toggle_field_var_name; |
---|
263 | AW_VARIABLE_TYPE toggle_field_var_type; |
---|
264 | AW_key_mod keymodifier; |
---|
265 | |
---|
266 | AW_area_management *areas[AW_MAX_AREA]; |
---|
267 | |
---|
268 | int WM_top_offset; // correction between position set and position reported ( = size of window frame - in most cases!) |
---|
269 | int WM_left_offset; |
---|
270 | |
---|
271 | static int WM_max_top_offset; |
---|
272 | static int WM_max_left_offset; |
---|
273 | |
---|
274 | bool knows_WM_offset() const { return WM_top_offset != AW_CALC_OFFSET_ON_EXPOSE; } |
---|
275 | |
---|
276 | AW_window_Motif(); |
---|
277 | ~AW_window_Motif() {}; |
---|
278 | }; |
---|
279 | |
---|
280 | |
---|
281 | void aw_root_init_font(Display *tool_d); |
---|
282 | void AW_label_in_awar_list(AW_window *aww, Widget widget, const char *str); |
---|
283 | void AW_server_callback(Widget wgt, XtPointer aw_cb_struct, XtPointer call_data); |
---|
284 | |
---|
285 | // ------------------------------------------------------------ |
---|
286 | // do not use the following |
---|
287 | extern int aw_message_cb_result; |
---|
288 | #define AW_MESSAGE_LISTEN_DELAY 500 // look in ms whether a father died |
---|
289 | void message_cb(AW_window*, int result); |
---|
290 | void input_cb(AW_window *aw, int buttonNr); |
---|
291 | void input_history_cb(AW_window *aw, int mode); |
---|
292 | void file_selection_cb(AW_window *aw, int ok_cancel_flag); |
---|
293 | unsigned aw_message_timer_listen_event(AW_root *awr, AW_window *aww); |
---|
294 | // ------------------------------------------------------------ |
---|
295 | |
---|
296 | Widget aw_create_shell(AW_window *aww, bool allow_resize, bool allow_close, int width, int height, int posx, int posy); |
---|
297 | void aw_realize_widget(AW_window *aww); |
---|
298 | void aw_insert_default_help_entries(AW_window *aww); |
---|
299 | |
---|
300 | __ATTR__NORETURN inline void type_mismatch(const char *triedType, const char *intoWhat) { |
---|
301 | GBK_terminatef("Cannot insert %s into %s which uses a non-%s AWAR", triedType, intoWhat, triedType); |
---|
302 | } |
---|
303 | |
---|
304 | #else |
---|
305 | #error aw_window_Xm.hxx included twice |
---|
306 | #endif |
---|