source: tags/cvs_2_svn/WINDOW/aw_root.hxx

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