source: tags/arb_5.3/WINDOW/aw_root.hxx

Last change on this file was 6149, checked in by westram, 15 years ago
  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 15.3 KB
Line 
1#ifndef AW_ROOT_HXX
2#define AW_ROOT_HXX
3
4#ifndef _STDIO_H
5#include <stdio.h>
6#endif
7
8#ifndef aw_assert
9#ifndef ARB_ASSERT_H
10#include <arb_assert.h>
11#endif
12#define aw_assert(bed) arb_assert(bed)
13#endif
14
15#ifndef ATTRIBUTES_H
16#include <attributes.h>
17#endif
18#ifndef ARBDB_BASE_H
19#include <arbdb_base.h>
20#endif
21
22
23#define AW_ROOT_DEFAULT (aw_main_root_default)
24class        AW_root;
25class        AW_window;
26typedef long AW_CL;             // generic client data type (void *)
27
28typedef void (*AW_RCB)(AW_root*,AW_CL,AW_CL);
29typedef void (*AW_RCB0)(AW_root*);
30typedef void (*AW_RCB1)(AW_root*,AW_CL);
31typedef void (*AW_RCB2)(AW_root*,AW_CL,AW_CL);
32typedef AW_window *(*AW_PPP)(AW_root*,AW_CL,AW_CL);
33
34typedef const char *AWAR;
35typedef long        AW_bitset;
36typedef double      AW_pos;
37typedef float       AW_grey_level;                  // <0 dont fill  0.0 white 1.0 black
38typedef GBDATA     *AW_default;
39typedef AW_bitset   AW_active;                      // bits to activate/inactivate buttons
40typedef int         AW_font;
41
42typedef const char             *GB_ERROR;
43typedef struct gbs_hash_struct  GB_HASH;
44
45extern AW_default aw_main_root_default;
46
47typedef struct _WidgetRec *Widget;
48
49// #define AWUSE(variable) variable = variable
50#if defined(DEBUG) && defined(DEVEL_RALF) && 0
51#define AWUSE(variable) (void)variable; int DONT_USE_AWUSE_FOR_##variable
52#else
53#define AWUSE(variable) (void)variable
54#endif // DEBUG
55// AWUSE is a obsolete way to get rid of unused-warnings. Will be removed in the future - do not use!
56// If your warning is about a parameter, skip the parameters name.
57// If your warning is about a variable, the variable is superfluous and should most likely be removed.
58
59
60#if defined(DEBUG)
61#define legal_mask(m) (((m)&AWM_ALL) == (m))
62#endif // DEBUG
63
64typedef enum {
65    AW_NONE    = 0,
66    AW_BIT     = 1,
67    AW_BYTE    = 2,
68    AW_INT     = 3,
69    AW_FLOAT   = 4,
70    AW_POINTER = 5, 
71    AW_BITS    = 6,
72    // 7 is unused
73    AW_BYTES   = 8,
74    AW_INTS    = 9,
75    AW_FLOATS  = 10,
76    AW_STRING  = 12,
77    // 13 is reserved (GB_STRING_SHRT)
78    // 14 is unused
79    AW_DB      = 15,
80
81    // keep AW_VARIABLE_TYPE consistent with GB_TYPES
82    // see ../ARBDB/arbdb.h@sync_GB_TYPES_AW_VARIABLE_TYPE
83
84    AW_TYPE_MAX = 16
85} AW_VARIABLE_TYPE;
86
87typedef struct {
88    int t, b, l, r;
89} AW_rectangle;
90
91typedef struct {
92    AW_pos t, b, l, r;
93} AW_world;
94
95typedef char *AW_error;
96
97int  aw_question  (const char *msg, const char *buttons, bool fixedSizeButtons = true, const char *helpfile = 0);
98bool aw_ask_sure  (const char *msg, bool fixedSizeButtons = true, const char *helpfile = 0);
99void aw_popup_ok  (const char *msg, bool fixedSizeButtons = true, const char *helpfile = 0);
100void aw_popup_exit(const char *msg, bool fixedSizeButtons = true, const char *helpfile = 0) __ATTR__NORETURN;
101
102// asynchronous messages:
103extern char AW_ERROR_BUFFER[1024];
104
105void aw_set_local_message();                                           // no message window, AWAR_ERROR_MESSAGES instead
106void aw_message(const char *msg);
107void aw_message();                                                     // prints AW_ERROR_BUFFER;
108void aw_macro_message(const char *temp, ...) __ATTR__FORMAT(1);        // gives control to the user
109
110// Read a string from the user :
111char *aw_input(const char *title, const char *prompt, const char *default_input);
112char *aw_input(const char *prompt, const char *default_input);
113inline char *aw_input(const char *prompt) { return aw_input(prompt, NULL); }
114
115char *aw_input2awar(const char *title, const char *prompt, const char *awar_value);
116char *aw_input2awar(const char *prompt, const char *awar_value);
117
118char *aw_string_selection     (const char *title, const char *prompt, const char *default_value, const char *value_list, const char *buttons, char *(*check_fun)(const char*));
119char *aw_string_selection2awar(const char *title, const char *prompt, const char *awar_name,     const char *value_list, const char *buttons, char *(*check_fun)(const char*));
120
121int aw_string_selection_button();   // returns index of last selected button (destroyed by aw_string_selection and aw_input)
122
123void AW_ERROR(const char *templat, ...) __ATTR__FORMAT(1);
124
125void aw_initstatus( void );     // call this function only once as early as possible
126void aw_openstatus( const char *title ); // show status
127void aw_closestatus( void );    // hide status
128
129int aw_status( const char *text );      // return 1 if exit button is pressed + set statustext
130
131#ifdef __cplusplus
132extern "C" {
133#endif
134
135    int aw_status( double gauge );  // return 1 if exit button is pressed + set statusslider
136
137#ifdef __cplusplus
138}
139#endif
140
141int aw_status( void );      // return 1 if exit button is pressed
142
143void aw_error( const char *text, const char *text2 );   // internal error: asks for core
144
145class  AW_root_Motif;
146class  AW_awar;
147struct AW_var_callback;
148struct AW_xfig_vectorfont;
149
150typedef enum  {
151    NO_EVENT     = 0,
152    KEY_PRESSED  = 2,
153    KEY_RELEASED = 3
154} AW_ProcessEventType;
155
156class AW_root {
157public:
158    static  AW_root *THIS;
159    AW_root_Motif   *prvt;                          // Do not use !!!
160    bool             value_changed;
161    long             changer_of_variable;
162    int              y_correction_for_input_labels;
163    AW_active        global_mask;
164    GB_HASH         *hash_table_for_variables;
165    bool             variable_set_by_toggle_field;
166    int              number_of_toggle_fields;
167    int              number_of_option_menues;
168    char            *program_name;
169
170    void            *get_aw_var_struct(char *awar);
171    void            *get_aw_var_struct_no_error(char *awar);
172
173    bool                    disable_callbacks;
174    struct AW_var_callback *focus_callback_list;
175
176    int  active_windows;
177    void window_show();         // a window is set to screen
178    void window_hide();
179
180    /********************* the read only  public section ***********************/
181    AW_default  application_database;
182    short       font_width;
183    short       font_height;
184    short       font_ascent;
185    GB_HASH    *hash_for_windows;
186
187    /* PJ - vectorfont stuff */
188    float  vectorfont_userscale; // user scaling
189    char  *vectorfont_name;     // name of font
190    int    vectorfont_zoomtext; // zoomtext calls: 0 = Xfont, 1 = vectorfont
191   
192    AW_xfig_vectorfont *vectorfont_lines; // graphic data of the font
193
194    /************************* the real public section *************************/
195
196    AW_root();
197    ~AW_root();
198    enum { AW_MONO_COLOR, AW_RGB_COLOR }    color_mode;
199
200    void init_variables( AW_default database );
201    void init_root( const char *programmname , bool no_exit);
202    void main_loop(void);
203    void process_events(void); // might block
204    void process_pending_events(void); // non-blocking
205    AW_ProcessEventType peek_key_event(AW_window *);
206
207    void add_timed_callback               (int ms, AW_RCB2 f, AW_CL cd1, AW_CL cd2);
208    void add_timed_callback_never_disabled(int ms, AW_RCB2 f, AW_CL cd1, AW_CL cd2);
209
210    void add_timed_callback               (int ms, AW_RCB1 f, AW_CL cd1) { add_timed_callback               (ms, (AW_RCB2)f, cd1, 0); }
211    void add_timed_callback_never_disabled(int ms, AW_RCB1 f, AW_CL cd1) { add_timed_callback_never_disabled(ms, (AW_RCB2)f, cd1, 0); }
212
213    void add_timed_callback               (int ms, AW_RCB0 f) { add_timed_callback               (ms, (AW_RCB2)f, 0, 0); }
214    void add_timed_callback_never_disabled(int ms, AW_RCB0 f) { add_timed_callback_never_disabled(ms, (AW_RCB2)f, 0, 0); }
215
216    void set_focus_callback(void(*f)(class AW_root*, AW_CL, AW_CL), AW_CL cd1, AW_CL cd2); /* any focus callback in any window */
217
218    AW_awar *awar(const char *awar);
219    AW_awar *awar_no_error(const char *awar);
220
221    AW_awar *awar_string (const char *var_name, const char *default_value = "", AW_default default_file = AW_ROOT_DEFAULT);
222    AW_awar *awar_int    (const char *var_name, long default_value = 0,         AW_default default_file = AW_ROOT_DEFAULT);
223    AW_awar *awar_float  (const char *var_name, float default_value = 0.0,      AW_default default_file = AW_ROOT_DEFAULT);
224    AW_awar *awar_pointer(const char *var_name, void *default_value = NULL,     AW_default default_file = AW_ROOT_DEFAULT);
225
226    AW_awar *label_is_awar(const char *label); // returns awar, if label refers to one (used by buttons, etc.)
227
228    void unlink_awars_from_DB(GBDATA *gb_main);     // use before calling GB_close for 'gb_main', if you have AWARs in DB
229
230    AW_default  open_default(const char *default_name, bool create_if_missing = true);
231    AW_error   *save_default( const char *awar_name );
232    AW_error   *save_default( const char *awar_name, const char *file_name );
233    AW_error   *save_default(AW_default aw_default, const char *file_name);
234    AW_default  get_default(const char *varname);
235    AW_default  get_gbdata(const char *varname);
236
237    // ************** Set and clear sensitivity of buttons and menus  *********
238    void apply_sensitivity(AW_active mask);
239    void make_sensitive(Widget w, AW_active mask);
240
241    GB_ERROR start_macro_recording(const char *file,const char *application_id, const char *stop_action_name);
242    GB_ERROR stop_macro_recording();
243    GB_ERROR execute_macro(const char *file);
244    void     stop_execute_macro(); // Starts macro window main loop, delayed return
245    GB_ERROR enable_execute_macro(FILE *mfile,const char *mname); // leave macro window main loop, returns stop_execute_macro
246
247    void define_remote_command(struct AW_cb_struct *cbs);
248    GB_ERROR check_for_remote_command(AW_default gb_main,const char *rm_base);
249
250    /*************************************************************************
251                                          Fonts
252    *************************************************************************/
253    const char  *font_2_ascii(AW_font font_nr); // converts fontnr to string
254    // returns 0 if font is not available
255    int font_2_xfig(AW_font font_nr);   // converts fontnr to xfigid
256    // negative values indicate monospaced f.
257
258#if defined(DEBUG)
259    size_t callallcallbacks(int mode);
260#endif // DEBUG
261};
262
263
264/*************************************************************************
265                AWARS
266*************************************************************************/
267struct AW_var_callback;
268struct AW_var_target;
269
270typedef void (*Awar_CB)(AW_root *, AW_CL, AW_CL);
271typedef void (*Awar_CB2)(AW_root *, AW_CL, AW_CL);
272typedef void (*Awar_CB1)(AW_root *, AW_CL);
273typedef void (*Awar_CB0)(AW_root *);
274
275typedef struct gb_data_base_type GBDATA;
276
277class AW_awar {
278    struct {
279        struct {
280            float min;
281            float max;
282        } f;
283        const char *srt;
284    } pp;
285
286    struct AW_var_callback *callback_list;
287    struct AW_var_target   *target_list;
288
289#if defined(DEBUG)
290    bool is_global;
291#endif // DEBUG
292
293    void remove_all_callbacks();
294    void remove_all_target_vars();
295    bool unlink_from_DB(GBDATA *gb_main);
296
297    friend long AW_unlink_awar_from_DB(const char *key, long cl_awar, void *cl_gb_main);
298    friend void AW_var_gbdata_callback_delete_intern(GBDATA *gbd, int *cl);
299
300public:
301    // read only
302    class AW_root *root;
303
304    GBDATA *gb_var;                                 // if unmapped, points to same DB elem as 'gb_origin'
305    GBDATA *gb_origin;                              // this is set ONCE on creation of awar
306
307    // read only
308
309    AW_VARIABLE_TYPE  variable_type;                // type of the awar
310    char             *awar_name;                    // name of the awar
311
312    void run_callbacks();
313    void update_target(AW_var_target*pntr);
314    void update_targets();
315   
316    AW_awar( AW_VARIABLE_TYPE var_type, const char *var_name, const char *var_value, double var_double_value, AW_default default_file, AW_root *root );
317
318    AW_awar *add_callback(Awar_CB2 f, AW_CL cd1, AW_CL cd2);
319    AW_awar *add_callback(Awar_CB1 f, AW_CL cd1);
320    AW_awar *add_callback(Awar_CB0 f);
321
322    AW_awar *remove_callback( Awar_CB2 f, AW_CL cd1, AW_CL cd2 ); // remove a callback
323    AW_awar *remove_callback( Awar_CB1 f, AW_CL cd1 );
324    AW_awar *remove_callback( Awar_CB0 f);
325
326    AW_awar *add_target_var( char **ppchr);
327    AW_awar *add_target_var( long *pint);
328    AW_awar *add_target_var( float *pfloat);
329    void    update();       // awar has changed
330
331    AW_awar *set_minmax(float min, float max);
332    AW_awar *set_srt(const char *srt);
333
334    AW_awar *map(const char *awarn) { return this->map(root->awar(awarn)); }
335    AW_awar *map(AW_default dest); /* map to new address */
336    AW_awar *map(AW_awar *dest); /* map to new address */
337    AW_awar *unmap();           /* map to original address */
338
339    void get(char **p_string )  { freeset(*p_string, read_string()); } /* deletes existing targets !!!*/
340    void get(long *p_int )      { *p_int =  (long)read_int(); }
341    void get(double *p_double ) { *p_double =  read_float(); }
342    void get(float *p_float )   { *p_float = read_float(); }
343
344    AW_VARIABLE_TYPE get_type();
345
346    char       *read_string();
347    const char *read_char_pntr();
348    char       *read_as_string();
349    long        read_int();
350    double      read_float();
351    void       *read_pointer();
352
353    GB_ERROR write_string(const char *aw_string);
354    GB_ERROR write_as_string(const char *aw_string);
355    GB_ERROR write_int(long aw_int);
356    GB_ERROR write_float(double aw_double);
357    GB_ERROR write_pointer(void *aw_pointer);
358
359    GB_ERROR write_as(char *aw_value) { return write_as_string(aw_value);};
360
361    // same as write_-versions above, but always touches the database field
362    GB_ERROR rewrite_string(const char *aw_string);
363    GB_ERROR rewrite_as_string(const char *aw_string);
364    GB_ERROR rewrite_int(long aw_int);
365    GB_ERROR rewrite_float(double aw_double);
366    GB_ERROR rewrite_pointer(void *aw_pointer);
367   
368    GB_ERROR rewrite_as(char *aw_value) { return rewrite_as_string(aw_value);};
369
370    GB_ERROR toggle_toggle();   /* switches between 1/0 */
371    void     touch(void);
372
373    GB_ERROR make_global() __ATTR__USERESULT;       // should be used by ARB_init_global_awars only
374};
375
376bool ARB_global_awars_initialized();
377GB_ERROR ARB_init_global_awars(AW_root *aw_root, AW_default aw_def, GBDATA *gb_main) __ATTR__USERESULT;
378
379// ----------------------------------
380//      class Awar_Callback_Info
381// ----------------------------------
382
383class Awar_Callback_Info {
384    // this structure is used to store all information on an awar callback
385    // and can be used to remove or remap awar callback w/o knowing anything else
386
387    AW_root *awr;
388    Awar_CB  callback;
389    AW_CL    cd1, cd2;
390    char    *awar_name;
391    char    *org_awar_name;
392
393    void init (AW_root *awr_, const char *awar_name_, Awar_CB2 callback_, AW_CL cd1_, AW_CL cd2_);
394
395public:
396    Awar_Callback_Info(AW_root *awr_, const char *awar_name_, Awar_CB2 callback_, AW_CL cd1_, AW_CL cd2_)   { init(awr_, awar_name_, callback_, cd1_, cd2_); }
397    Awar_Callback_Info(AW_root *awr_, const char *awar_name_, Awar_CB1 callback_, AW_CL cd1_)               { init(awr_, awar_name_, (Awar_CB2)callback_, cd1_, 0); }
398    Awar_Callback_Info(AW_root *awr_, const char *awar_name_, Awar_CB0 callback_)                           { init(awr_, awar_name_, (Awar_CB2)callback_, 0, 0); }
399
400    ~Awar_Callback_Info() {
401        delete awar_name;
402        delete org_awar_name;
403    }
404
405    void add_callback() { awr->awar(awar_name)->add_callback(callback, cd1, cd2); }
406    void remove_callback() { awr->awar(awar_name)->remove_callback(callback, cd1, cd2); }
407
408    void remap(const char *new_awar);
409
410    const char *get_awar_name() const { return awar_name; }
411    const char *get_org_awar_name() const { return org_awar_name; }
412    AW_root *get_root() { return awr; }
413};
414
415#else
416#error aw_root.hxx included twice
417#endif
Note: See TracBrowser for help on using the repository browser.