source: branches/profile/WINDOW/aw_root.hxx

Last change on this file was 12850, checked in by westram, 10 years ago
  • remove aw_string_selection and related code
  • fix signed warnings in new_input_window
  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 6.8 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    bool           variable_set_by_toggle_field;
112    int            number_of_toggle_fields;
113    int            number_of_option_menus;
114    char          *program_name;
115
116    bool            disable_callbacks;
117    AW_window      *current_modal_window;
118    AW_root_cblist *focus_callback_list;
119
120    int  active_windows;
121    void window_show();         // a window is set to screen
122    void window_hide(AW_window *aww);
123
124    // the read only public section:
125    short       font_width;
126    short       font_height;
127    short       font_ascent;
128    GB_HASH    *hash_for_windows;
129
130    // the real public section:
131    AW_root(const char *propertyFile, const char *program, bool no_exit, UserActionTracker *user_tracker, int* argc, char*** argv);
132#if defined(UNIT_TESTS) // UT_DIFF
133    AW_root(const char *properties); // fake-root for unit-tests (allows access to awar-subsystem)
134#endif
135    ~AW_root();
136
137    void setUserActionTracker(UserActionTracker *user_tracker);
138    UserActionTracker *getTracker() { return tracker; }
139
140    enum { AW_MONO_COLOR, AW_RGB_COLOR }    color_mode;
141
142    void main_loop();
143
144    void                process_events();           // might block
145    void                process_pending_events();   // non-blocking
146    AW_ProcessEventType peek_key_event(AW_window *);
147
148    void add_timed_callback(int ms, const TimedCallback& tcb);
149    void add_timed_callback_never_disabled(int ms, const TimedCallback& tcb);
150
151    bool is_focus_callback(AW_RCB fcb) const;
152
153    AW_awar *awar(const char *awar);
154    AW_awar *awar_no_error(const char *awar);
155
156    void dont_save_awars_with_default_value(GBDATA *gb_db);
157
158    AW_awar *awar_string (const char *var_name, const char *default_value = "", AW_default default_file = AW_ROOT_DEFAULT);
159    AW_awar *awar_int    (const char *var_name, long default_value = 0,         AW_default default_file = AW_ROOT_DEFAULT);
160    AW_awar *awar_float  (const char *var_name, float default_value = 0.0,      AW_default default_file = AW_ROOT_DEFAULT);
161    AW_awar *awar_pointer(const char *var_name, void *default_value = NULL,     AW_default default_file = AW_ROOT_DEFAULT);
162
163    AW_awar *label_is_awar(const char *label); // returns awar, if label refers to one (used by buttons, etc.)
164
165    void unlink_awars_from_DB(GBDATA *gb_main);     // use before calling GB_close for 'gb_main', if you have AWARs in DB
166
167    AW_default check_properties(AW_default aw_props) {
168        return aw_props ? aw_props : application_database;
169    }
170
171    GB_ERROR save_properties(const char *filename = NULL) __ATTR__USERESULT;
172
173    // Control sensitivity of buttons etc.:
174    void apply_sensitivity(AW_active mask);
175    void apply_focus_policy(bool follow_mouse);
176    void make_sensitive(Widget w, AW_active mask);
177    bool remove_button_from_sens_list(Widget button);
178
179    void track_action(const char *action_id) { tracker->track_action(action_id); }
180    void track_awar_change(AW_awar *changed_awar) { tracker->track_awar_change(changed_awar); }
181
182    bool is_tracking() const { return tracker->is_tracking(); }
183    UserActionTracker *get_tracker() { return tracker; }
184
185    void define_remote_command(class AW_cb *cbs);
186    AW_cb *search_remote_command(const char *action);
187
188#if defined(DEBUG)
189    size_t callallcallbacks(int mode);
190    class ConstStrArray *get_action_ids();
191#endif // DEBUG
192};
193
194const char *AW_font_2_ascii(AW_font font_nr);
195int         AW_font_2_xfig(AW_font font_nr);
196
197bool ARB_global_awars_initialized();
198bool ARB_in_expert_mode(AW_root *awr);
199inline bool ARB_in_novice_mode(AW_root *awr) { return !ARB_in_expert_mode(awr); }
200
201void ARB_declare_global_awars(AW_root *aw_root, AW_default aw_def);
202GB_ERROR ARB_bind_global_awars(GBDATA *gb_main) __ATTR__USERESULT;
203
204__ATTR__USERESULT_TODO inline GB_ERROR ARB_init_global_awars(AW_root *aw_root, AW_default aw_def, GBDATA *gb_main) {
205    ARB_declare_global_awars(aw_root, aw_def);
206    return ARB_bind_global_awars(gb_main);
207}
208
209inline AW_default get_AW_ROOT_DEFAULT() { return AW_root::SINGLETON->check_properties(NULL); }
210
211void AW_system(AW_window *aww, const char *command, const char *auto_help_file);
212
213#else
214#error aw_root.hxx included twice
215#endif
216
217
Note: See TracBrowser for help on using the repository browser.