| 1 | #ifndef AW_ROOT_HXX |
|---|
| 2 | #define AW_ROOT_HXX |
|---|
| 3 | |
|---|
| 4 | #ifndef ARBTOOLS_H |
|---|
| 5 | #include <arbtools.h> |
|---|
| 6 | #endif |
|---|
| 7 | #ifndef ARB_ERROR_H |
|---|
| 8 | #include <arb_error.h> |
|---|
| 9 | #endif |
|---|
| 10 | #ifndef CB_H |
|---|
| 11 | #include <cb.h> |
|---|
| 12 | #endif |
|---|
| 13 | #ifndef ATTRIBUTES_H |
|---|
| 14 | #include <attributes.h> |
|---|
| 15 | #endif |
|---|
| 16 | #ifndef AW_BASE_HXX |
|---|
| 17 | #include "aw_base.hxx" // @@@ remove later |
|---|
| 18 | #endif |
|---|
| 19 | |
|---|
| 20 | #ifndef aw_assert |
|---|
| 21 | #define aw_assert(bed) arb_assert(bed) |
|---|
| 22 | #endif |
|---|
| 23 | |
|---|
| 24 | #if defined(ASSERTION_USED) |
|---|
| 25 | #define legal_mask(m) (((m)&AWM_ALL) == (m)) |
|---|
| 26 | #endif // ASSERTION_USED |
|---|
| 27 | |
|---|
| 28 | typedef char *AW_error; |
|---|
| 29 | |
|---|
| 30 | // asynchronous messages: |
|---|
| 31 | extern char AW_ERROR_BUFFER[1024]; |
|---|
| 32 | |
|---|
| 33 | void aw_set_local_message(); // no message window, AWAR_ERROR_MESSAGES instead (used by EDIT4) |
|---|
| 34 | |
|---|
| 35 | // Read a string from the user : |
|---|
| 36 | char *aw_input(const char *title, const char *prompt, const char *default_input); |
|---|
| 37 | char *aw_input(const char *prompt, const char *default_input); |
|---|
| 38 | inline char *aw_input(const char *prompt) { return aw_input(prompt, NULp); } |
|---|
| 39 | |
|---|
| 40 | char *aw_file_selection(const char *title, const char *dir, const char *def_name, const char *suffix); |
|---|
| 41 | |
|---|
| 42 | class AW_root_Motif; |
|---|
| 43 | class AW_awar; |
|---|
| 44 | struct AW_buttons_struct; |
|---|
| 45 | class AW_root_cblist; |
|---|
| 46 | struct GB_HASH; |
|---|
| 47 | class AW_cb; |
|---|
| 48 | |
|---|
| 49 | enum AW_ProcessEventType { |
|---|
| 50 | NO_EVENT = 0, |
|---|
| 51 | KEY_PRESSED = 2, |
|---|
| 52 | KEY_RELEASED = 3 |
|---|
| 53 | }; |
|---|
| 54 | |
|---|
| 55 | void aw_initstatus(); |
|---|
| 56 | |
|---|
| 57 | // --------------------------- |
|---|
| 58 | // UserActionTracker |
|---|
| 59 | |
|---|
| 60 | class UserActionTracker : virtual Noncopyable { |
|---|
| 61 | bool tracking; |
|---|
| 62 | |
|---|
| 63 | protected: |
|---|
| 64 | void set_tracking(bool track) { tracking = track; } |
|---|
| 65 | |
|---|
| 66 | public: |
|---|
| 67 | UserActionTracker() : tracking(false) {} |
|---|
| 68 | virtual ~UserActionTracker() {} |
|---|
| 69 | |
|---|
| 70 | bool is_tracking() const { return tracking; } |
|---|
| 71 | |
|---|
| 72 | virtual void track_action(const char *action_id) = 0; |
|---|
| 73 | virtual void track_awar_change(AW_awar *awar) = 0; |
|---|
| 74 | virtual bool is_replaceable() const = 0; |
|---|
| 75 | }; |
|---|
| 76 | class NullTracker : public UserActionTracker { |
|---|
| 77 | public: |
|---|
| 78 | void track_action(const char */*action_id*/) OVERRIDE {} |
|---|
| 79 | void track_awar_change(AW_awar */*awar*/) OVERRIDE {} |
|---|
| 80 | bool is_replaceable() const OVERRIDE { return true; } |
|---|
| 81 | }; |
|---|
| 82 | |
|---|
| 83 | // ----------------- |
|---|
| 84 | // AW_root |
|---|
| 85 | |
|---|
| 86 | class AW_root : virtual Noncopyable { |
|---|
| 87 | AW_default application_database; |
|---|
| 88 | AW_buttons_struct *button_sens_list; |
|---|
| 89 | |
|---|
| 90 | UserActionTracker *tracker; |
|---|
| 91 | |
|---|
| 92 | void create_colormap(); |
|---|
| 93 | |
|---|
| 94 | void init_variables(AW_default database); |
|---|
| 95 | void exit_variables(); |
|---|
| 96 | |
|---|
| 97 | void init_root(const char *programname, bool no_exit); |
|---|
| 98 | void exit_root(); |
|---|
| 99 | AW_default load_properties(const char *default_name); |
|---|
| 100 | |
|---|
| 101 | public: |
|---|
| 102 | static AW_root *SINGLETON; |
|---|
| 103 | |
|---|
| 104 | AW_root_Motif *prvt; // Do not use !!! |
|---|
| 105 | bool value_changed; |
|---|
| 106 | Widget changer_of_variable; |
|---|
| 107 | int y_correction_for_input_labels; |
|---|
| 108 | AW_active global_mask; |
|---|
| 109 | bool focus_follows_mouse; |
|---|
| 110 | GB_HASH *hash_table_for_variables; |
|---|
| 111 | int number_of_toggle_fields; |
|---|
| 112 | int number_of_option_menus; |
|---|
| 113 | char *program_name; |
|---|
| 114 | bool disable_callbacks; |
|---|
| 115 | AW_window *current_modal_window; |
|---|
| 116 | int active_windows; |
|---|
| 117 | |
|---|
| 118 | void window_show(); // a window is set to screen |
|---|
| 119 | void window_hide(AW_window *aww); |
|---|
| 120 | |
|---|
| 121 | // the read only public section: |
|---|
| 122 | short font_width; |
|---|
| 123 | short font_height; |
|---|
| 124 | short font_ascent; |
|---|
| 125 | GB_HASH *hash_for_windows; |
|---|
| 126 | |
|---|
| 127 | // the real public section: |
|---|
| 128 | AW_root(const char *propertyFile, const char *program, bool no_exit, UserActionTracker *user_tracker); |
|---|
| 129 | #if defined(UNIT_TESTS) // UT_DIFF |
|---|
| 130 | AW_root(const char *properties); // fake-root for unit-tests (allows access to awar-subsystem) |
|---|
| 131 | #endif |
|---|
| 132 | ~AW_root(); |
|---|
| 133 | |
|---|
| 134 | void setUserActionTracker(UserActionTracker *user_tracker); |
|---|
| 135 | UserActionTracker *getTracker() { return tracker; } |
|---|
| 136 | |
|---|
| 137 | enum { AW_MONO_COLOR, AW_RGB_COLOR } color_mode; |
|---|
| 138 | |
|---|
| 139 | void main_loop(); |
|---|
| 140 | |
|---|
| 141 | void process_events(); // might block |
|---|
| 142 | void process_pending_events(); // non-blocking |
|---|
| 143 | AW_ProcessEventType peek_key_event(AW_window *); |
|---|
| 144 | |
|---|
| 145 | void add_timed_callback(int ms, const TimedCallback& tcb); |
|---|
| 146 | void add_timed_callback_never_disabled(int ms, const TimedCallback& tcb); |
|---|
| 147 | |
|---|
| 148 | AW_awar *awar(const char *awar); |
|---|
| 149 | AW_awar *awar_no_error(const char *awar); |
|---|
| 150 | |
|---|
| 151 | void dont_save_awars_with_default_value(GBDATA *gb_db); |
|---|
| 152 | |
|---|
| 153 | AW_awar *awar_string (const char *var_name, const char *default_value = "", AW_default default_file = AW_ROOT_DEFAULT); |
|---|
| 154 | AW_awar *awar_int (const char *var_name, long default_value = 0, AW_default default_file = AW_ROOT_DEFAULT); |
|---|
| 155 | AW_awar *awar_float (const char *var_name, float default_value = 0.0, AW_default default_file = AW_ROOT_DEFAULT); |
|---|
| 156 | AW_awar *awar_pointer(const char *var_name, GBDATA *default_value = NULp, AW_default default_file = AW_ROOT_DEFAULT); |
|---|
| 157 | |
|---|
| 158 | AW_awar *label_is_awar(const char *label); // returns awar, if label refers to one (used by buttons, etc.) |
|---|
| 159 | |
|---|
| 160 | void unlink_awars_from_DB(GBDATA *gb_main); // use before calling GB_close for 'gb_main', if you have AWARs in DB |
|---|
| 161 | |
|---|
| 162 | AW_default check_properties(AW_default aw_props) { |
|---|
| 163 | return aw_props ? aw_props : application_database; |
|---|
| 164 | } |
|---|
| 165 | |
|---|
| 166 | GB_ERROR save_properties(const char *filename = NULp) __ATTR__USERESULT; |
|---|
| 167 | |
|---|
| 168 | // Control sensitivity of buttons etc.: |
|---|
| 169 | void apply_sensitivity(AW_active mask); |
|---|
| 170 | void apply_focus_policy(bool follow_mouse); |
|---|
| 171 | void make_sensitive(Widget w, AW_active mask); |
|---|
| 172 | bool remove_button_from_sens_list(Widget button); |
|---|
| 173 | |
|---|
| 174 | void set_active(Widget w, bool active); |
|---|
| 175 | |
|---|
| 176 | void track_action(const char *action_id) { tracker->track_action(action_id); } |
|---|
| 177 | void track_awar_change(AW_awar *changed_awar) { tracker->track_awar_change(changed_awar); } |
|---|
| 178 | |
|---|
| 179 | bool is_tracking() const { return tracker->is_tracking(); } |
|---|
| 180 | UserActionTracker *get_tracker() { return tracker; } |
|---|
| 181 | |
|---|
| 182 | void define_remote_command(class AW_cb *cbs); |
|---|
| 183 | AW_cb *search_remote_command(const char *action); |
|---|
| 184 | |
|---|
| 185 | #if defined(DEBUG) |
|---|
| 186 | size_t callallcallbacks(int mode); |
|---|
| 187 | class ConstStrArray *get_action_ids(); |
|---|
| 188 | #endif // DEBUG |
|---|
| 189 | }; |
|---|
| 190 | |
|---|
| 191 | bool ARB_global_awars_initialized(); |
|---|
| 192 | bool ARB_in_expert_mode(AW_root *awr); |
|---|
| 193 | inline bool ARB_in_novice_mode(AW_root *awr) { return !ARB_in_expert_mode(awr); } |
|---|
| 194 | |
|---|
| 195 | void ARB_declare_global_awars(AW_root *aw_root, AW_default aw_def); |
|---|
| 196 | GB_ERROR ARB_bind_global_awars(GBDATA *gb_main) __ATTR__USERESULT; |
|---|
| 197 | |
|---|
| 198 | __ATTR__USERESULT_TODO inline GB_ERROR ARB_init_global_awars(AW_root *aw_root, AW_default aw_def, GBDATA *gb_main) { |
|---|
| 199 | ARB_declare_global_awars(aw_root, aw_def); |
|---|
| 200 | return ARB_bind_global_awars(gb_main); |
|---|
| 201 | } |
|---|
| 202 | |
|---|
| 203 | inline AW_default get_AW_ROOT_DEFAULT() { return AW_root::SINGLETON->check_properties(NULp); } |
|---|
| 204 | |
|---|
| 205 | #else |
|---|
| 206 | #error aw_root.hxx included twice |
|---|
| 207 | #endif |
|---|
| 208 | |
|---|
| 209 | |
|---|