source: tags/ms_r16q3/WINDOW/aw_root.hxx

Last change on this file was 14885, checked in by westram, 8 years ago
  • add short font descriptions to motif version
    • display them on font-selection-buttons
    • runtime check vs duplicate names/specs (DEBUG)
  • move font interface from aw_root.hxx → aw_xfont.hxx (=restrict use to WINDOW library)
  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 6.5 KB
Line 
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
28typedef char *AW_error;
29
30// asynchronous messages:
31extern char AW_ERROR_BUFFER[1024];
32
33void aw_set_local_message(); // no message window, AWAR_ERROR_MESSAGES instead (used by EDIT4)
34
35// Read a string from the user :
36char *aw_input(const char *title, const char *prompt, const char *default_input);
37char *aw_input(const char *prompt, const char *default_input);
38inline char *aw_input(const char *prompt) { return aw_input(prompt, NULL); }
39
40char *aw_file_selection(const char *title, const char *dir, const char *def_name, const char *suffix);
41
42class  AW_root_Motif;
43class  AW_awar;
44struct AW_buttons_struct;
45class  AW_root_cblist;
46struct GB_HASH;
47class  AW_cb;
48
49enum AW_ProcessEventType {
50    NO_EVENT     = 0,
51    KEY_PRESSED  = 2,
52    KEY_RELEASED = 3
53};
54
55void aw_initstatus();
56
57// ---------------------------
58//      UserActionTracker
59
60class UserActionTracker : virtual Noncopyable {
61    bool tracking;
62
63protected:
64    void set_tracking(bool track) { tracking = track; }
65
66public:
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};
76class NullTracker : public UserActionTracker {
77public:
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
86class 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
101public:
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, int* argc, char*** argv);
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 = NULL,   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 = NULL) __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 track_action(const char *action_id) { tracker->track_action(action_id); }
175    void track_awar_change(AW_awar *changed_awar) { tracker->track_awar_change(changed_awar); }
176
177    bool is_tracking() const { return tracker->is_tracking(); }
178    UserActionTracker *get_tracker() { return tracker; }
179
180    void define_remote_command(class AW_cb *cbs);
181    AW_cb *search_remote_command(const char *action);
182
183#if defined(DEBUG)
184    size_t callallcallbacks(int mode);
185    class ConstStrArray *get_action_ids();
186#endif // DEBUG
187};
188
189bool ARB_global_awars_initialized();
190bool ARB_in_expert_mode(AW_root *awr);
191inline bool ARB_in_novice_mode(AW_root *awr) { return !ARB_in_expert_mode(awr); }
192
193void ARB_declare_global_awars(AW_root *aw_root, AW_default aw_def);
194GB_ERROR ARB_bind_global_awars(GBDATA *gb_main) __ATTR__USERESULT;
195
196__ATTR__USERESULT_TODO inline GB_ERROR ARB_init_global_awars(AW_root *aw_root, AW_default aw_def, GBDATA *gb_main) {
197    ARB_declare_global_awars(aw_root, aw_def);
198    return ARB_bind_global_awars(gb_main);
199}
200
201inline AW_default get_AW_ROOT_DEFAULT() { return AW_root::SINGLETON->check_properties(NULL); }
202
203#else
204#error aw_root.hxx included twice
205#endif
206
207
Note: See TracBrowser for help on using the repository browser.