source: branches/port5/WINDOW/AW_at.cxx

Last change on this file was 6126, checked in by westram, 16 years ago
  • do not reset at-mask-state in unset_at_commands()
  • renamed 'mask_for_next_button' into 'widget_mask'
  • corrected novice-mode for
    • field-admin
    • "Incremental phylogeny"
  • legal_mask()-check active 4all

fixes #199

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 14.5 KB
Line 
1#include <stdio.h>
2#include <stdlib.h>
3#include <string.h>
4#include <memory.h>
5#include <arbdb.h>
6#include "aw_root.hxx"
7#include "aw_device.hxx"
8#include "aw_at.hxx"
9#include "aw_window.hxx"
10#include "aw_xfig.hxx"
11
12/*******************************************************************************************************/
13/*******************************************************************************************************/
14/*******************************************************************************************************/
15
16AW_at::AW_at(void) {
17    memset((char*)this,0,sizeof(AW_at));
18
19    length_of_buttons = 10;
20    height_of_buttons = 0;
21    shadow_thickness  = 2;
22    widget_mask       = AWM_ALL;
23}
24
25
26void AW_window::shadow_width (int shadow_thickness ) { _at->shadow_thickness = shadow_thickness; }
27
28void AW_window::label_length( int length ) { _at->length_of_label_for_inputfield = length; }
29
30void AW_window::button_length( int length ) { _at->length_of_buttons = length; }
31void AW_window::button_height( int height ) { _at->height_of_buttons = height>1 ? height : 0; }
32int  AW_window::get_button_length() const { return _at->length_of_buttons; }
33int  AW_window::get_button_height() const { return _at->height_of_buttons; }
34
35void AW_window::highlight( void ) { _at->highlight = true; }
36
37void AW_window::auto_increment( int x, int y ) {
38    _at->auto_increment_x          = x;
39    _at->auto_increment_y          = y;
40    _at->x_for_newline             = _at->x_for_next_button;
41    _at->do_auto_space             = false;
42    _at->do_auto_increment         = true;
43    _at->biggest_height_of_buttons = 0;
44}
45
46
47void AW_window::auto_space( int x, int y ) {
48    _at->auto_space_x              = x;
49    _at->auto_space_y              = y;
50    _at->x_for_newline             = _at->x_for_next_button;
51    _at->do_auto_space             = true;
52    _at->do_auto_increment         = false;
53    _at->biggest_height_of_buttons = 0;
54}
55
56
57void AW_window::auto_off( void ) {
58    _at->do_auto_space     = false;
59    _at->do_auto_increment = false;
60}
61
62void AW_window::at_set_min_size(int xmin, int ymin) {
63    if (xmin > _at->max_x_size) _at->max_x_size = xmin; // this looks wrong, but its right!
64    if (ymin > _at->max_y_size) _at->max_y_size = ymin;
65
66    if (recalc_size_at_show) {
67        set_window_size(_at->max_x_size+1000, _at->max_y_size+1000);
68    }
69}
70
71
72/*******************************************************************************************************/
73/*******************************************************************************************************/
74/*******************************************************************************************************/
75
76void AW_window::help_text(const char *help_id ) {
77    delete _at->helptext_for_next_button;
78    _at->helptext_for_next_button   = strdup( help_id );
79}
80
81
82void AW_window::sens_mask( AW_active Mask ) {
83#if defined(DEVEL_RALF)
84#warning enable assertion below for all developers when tested   
85#endif // DEVEL_RALF
86    aw_assert(legal_mask(Mask));
87    _at->widget_mask = Mask;
88}
89
90
91void AW_window::callback( void (*f)(AW_window*,AW_CL,AW_CL), AW_CL cd1, AW_CL cd2 ) {
92    _callback = new AW_cb_struct(this,(AW_CB)f,cd1,cd2);
93}
94
95void AW_window::callback( void (*f)(AW_window*,AW_CL), AW_CL cd1 ) {
96    _callback = new AW_cb_struct(this,(AW_CB)f,cd1);
97}
98
99void AW_window::callback( void (*f)(AW_window*) ) {
100    _callback = new AW_cb_struct(this,(AW_CB)f);
101}
102void AW_window::callback( AW_cb_struct * /*owner*/awcbs ) {
103    _callback = awcbs;
104}
105
106void AW_window::d_callback( void (*f)(AW_window*,AW_CL,AW_CL), AW_CL cd1, AW_CL cd2 ) {
107    _d_callback = new AW_cb_struct(this,(AW_CB)f,cd1,cd2);
108}
109
110void AW_window::d_callback( void (*f)(AW_window*,AW_CL), AW_CL cd1 ) {
111    _d_callback = new AW_cb_struct(this,(AW_CB)f,cd1);
112}
113
114void AW_window::d_callback( void (*f)(AW_window*) ) {
115    _d_callback = new AW_cb_struct(this,(AW_CB)f);
116}
117void AW_window::d_callback( AW_cb_struct * /*owner*/awcbs ) {
118    _d_callback = awcbs;
119}
120
121void AW_window::label( const char *Label ) {
122    freedup(_at->label_for_inputfield, Label);
123}
124
125
126void AW_window::at( int x, int y ) {
127    at_x(x);
128    at_y(y);
129}
130
131void AW_window::at_x( int x ) {
132    if (_at->x_for_next_button > _at->max_x_size) _at->max_x_size = _at->x_for_next_button;
133    _at->x_for_next_button = x;
134    if (_at->x_for_next_button > _at->max_x_size) _at->max_x_size = _at->x_for_next_button;
135}
136
137
138void AW_window::at_y( int y ) {
139    if (_at->y_for_next_button + _at->biggest_height_of_buttons > _at->max_y_size)
140        _at->max_y_size = _at->y_for_next_button + _at->biggest_height_of_buttons;
141    _at->biggest_height_of_buttons = _at->biggest_height_of_buttons + _at->y_for_next_button - y;
142    if (_at->biggest_height_of_buttons<0){
143        _at->biggest_height_of_buttons = 0;
144        if (_at->max_y_size < y)    _at->max_y_size = y;
145    }
146    _at->y_for_next_button = y;
147}
148
149
150void AW_window::at_shift( int x, int y ) {
151    at(x+_at->x_for_next_button,y+_at->y_for_next_button);
152}
153
154void AW_window::at_newline( void ) {
155
156    if ( _at->do_auto_increment ) {
157        at_y(_at->auto_increment_y + _at->y_for_next_button);
158    }
159    else {
160        if ( _at->do_auto_space ) {
161            at_y(_at->y_for_next_button + _at->auto_space_y + _at->biggest_height_of_buttons);
162        }
163        else {
164            AW_ERROR("neither auto_space nor auto_increment activated while using at_newline");
165        }
166    }
167    at_x(_at->x_for_newline);
168}
169
170
171void AW_window::at( const char *at_id ) {
172    char to_position[100];memset(to_position,0,sizeof(to_position));
173    _at->attach_y              = _at->attach_x = false;
174    _at->attach_ly             = _at->attach_lx = false;
175    _at->attach_any            = false;
176    _at->correct_for_at_string = true;
177
178    if ( !xfig_data ) {
179        AW_ERROR( "no xfig file loaded " );
180        return;
181    }
182    AW_xfig *xfig = (AW_xfig *)xfig_data;
183    AW_xfig_pos *pos;
184
185    pos = (AW_xfig_pos*)GBS_read_hash(xfig->hash,at_id);
186
187    if (!pos){
188        sprintf( to_position, "X:%s", at_id ); pos = (AW_xfig_pos*)GBS_read_hash(xfig->hash,to_position);
189        if (pos) _at->attach_any = _at->attach_lx = true;
190    }
191    if (!pos){
192        sprintf( to_position, "Y:%s", at_id ); pos = (AW_xfig_pos*)GBS_read_hash(xfig->hash,to_position);
193        if (pos) _at->attach_any = _at->attach_ly = true;
194    }
195    if (!pos){
196        sprintf( to_position, "XY:%s", at_id );    pos = (AW_xfig_pos*)GBS_read_hash(xfig->hash,to_position);
197        if (pos) _at->attach_any = _at->attach_lx = _at->attach_ly = true;
198    }
199    if( !pos ) {
200        AW_ERROR(" ID '%s' does not exist in xfig file", at_id);
201        return;
202    }
203
204    at( (pos->x - xfig->minx), (pos->y - xfig->miny - this->get_root()->font_height - 9));
205    _at->correct_for_at_center = pos->center;
206
207    sprintf( to_position, "to:%s", at_id ); pos = (AW_xfig_pos*)GBS_read_hash(xfig->hash,to_position);
208
209    if (!pos) {
210        sprintf( to_position, "to:X:%s", at_id );  pos = (AW_xfig_pos*)GBS_read_hash(xfig->hash,to_position);
211        if (pos) _at->attach_any = _at->attach_x = true;
212    }
213    if (!pos) {
214        sprintf( to_position, "to:Y:%s", at_id );  pos = (AW_xfig_pos*)GBS_read_hash(xfig->hash,to_position);
215        if (pos) _at->attach_any = _at->attach_y = true;
216    }
217    if (!pos) {
218        sprintf( to_position, "to:XY:%s", at_id ); pos = (AW_xfig_pos*)GBS_read_hash(xfig->hash,to_position);
219        if (pos) _at->attach_any = _at->attach_x = _at->attach_y = true;
220    }
221
222    if( pos ) {
223        _at->to_position_exists = true;
224        _at->to_position_x = (pos->x - xfig->minx);
225        _at->to_position_y = (pos->y - xfig->miny);
226        _at->correct_for_at_center = 0; // always justify left when a to-position exists
227    }
228    else {
229        _at->to_position_exists = false;
230    }
231}
232
233
234// set "$XY:id" manually
235
236void AW_window::at_attach(bool attach_x, bool attach_y) {
237    aw_assert(0); // this does not work
238    _at->attach_lx  = attach_x;
239    _at->attach_ly  = attach_y;
240    _at->attach_any = attach_x || attach_y;
241}
242
243// set "$to:XY:id" manually
244// use negative offsets to set offset from right/lower border to to-position
245
246void AW_window::at_set_to(bool attach_x, bool attach_y, int xoff, int yoff) {
247//     aw_assert(attach_x || attach_y); // use at_unset_to() to un-attach
248
249    _at->attach_any = attach_x || attach_y;
250    _at->attach_x   = attach_x;
251    _at->attach_y   = attach_y;
252
253    _at->to_position_exists = true;
254    _at->to_position_x      = xoff >= 0 ? _at->x_for_next_button + xoff : _at->max_x_size+xoff;
255    _at->to_position_y      = yoff >= 0 ? _at->y_for_next_button + yoff : _at->max_y_size+yoff;
256
257    if (_at->to_position_x > _at->max_x_size) _at->max_x_size = _at->to_position_x;
258    if (_at->to_position_y > _at->max_y_size) _at->max_y_size = _at->to_position_y;
259
260    _at->correct_for_at_center = 0;
261
262//     _at->correct_for_at_center = xoff <= 0 ? 0 : 2; // justify left (=0) or right (=2)
263}
264
265void AW_window::at_unset_to() {
266    _at->attach_x   = _at->attach_y = _at->to_position_exists = false;
267    _at->attach_any = _at->attach_lx || _at->attach_ly;
268}
269
270bool AW_window::at_ifdef(const  char *at_id) {
271    if (!xfig_data) return false;
272    AW_xfig *xfig = (AW_xfig *)xfig_data;
273    char     buffer[100];
274
275#if defined(DEBUG)
276    int printed =
277#endif // DEBUG
278        sprintf(buffer,"XY:%s",at_id);
279#if defined(DEBUG)
280    aw_assert(printed<100);
281#endif // DEBUG
282
283    if (GBS_read_hash(xfig->hash,buffer+3)) return true; // "tag"
284    if (GBS_read_hash(xfig->hash,buffer+1)) return true; // "Y:tag"
285    if (GBS_read_hash(xfig->hash,buffer)) return true; // "XY:tag"
286    buffer[1] = 'X';
287    if (GBS_read_hash(xfig->hash,buffer+1)) return true; // "X:tag"
288
289    return false;
290}
291
292void AW_window::check_at_pos( void ) {
293    if (_at->x_for_next_button<10){
294        //  printf("X Position should be greater 10\n");
295    }
296}
297
298void AW_window::get_at_position(int *x, int *y) { *x = _at->x_for_next_button; *y = _at->y_for_next_button; }
299int AW_window::get_at_xposition() { return _at->x_for_next_button; }
300int AW_window::get_at_yposition() { return _at->y_for_next_button; }
301
302void AW_window::store_at_size_and_attach( AW_at_size *at_size ) {
303    at_size->store(_at);
304}
305
306void AW_window::restore_at_size_and_attach( const AW_at_size *at_size ) {
307    at_size->restore(_at);
308}
309
310void AW_window::unset_at_commands( void ) {
311    // _at->widget_mask = AWM_ALL; // disabled 2009/Aug/5, cause this resets expert-mask after creating widget
312
313    _callback   = NULL;
314    _d_callback = NULL;
315
316    _at->correct_for_at_string = false;
317    _at->correct_for_at_center = 0;
318    _at->to_position_exists    = false;
319    _at->highlight             = false;
320
321    freeset(_at->helptext_for_next_button, 0);
322    freeset(_at->label_for_inputfield, 0);
323   
324    _at->background_color = 0;
325}
326
327void AW_window::increment_at_commands( int width, int height ) {
328
329    at_shift(width,0);
330    at_shift(-width,0);         // set bounding box
331
332    if ( _at->do_auto_increment ) {
333        at_shift(_at->auto_increment_x,0);
334    }
335    if ( _at->do_auto_space ) {
336        at_shift(_at->auto_space_x + width,0);
337    }
338
339    if ( _at->biggest_height_of_buttons < height ) {
340        _at->biggest_height_of_buttons = height;
341    }
342
343    if ( _at->max_y_size < (_at->y_for_next_button +_at->biggest_height_of_buttons +3.0)) {
344        _at->max_y_size = _at->y_for_next_button +_at->biggest_height_of_buttons +3;
345    }
346
347    if ( _at->max_x_size < (_at->x_for_next_button + this->get_root()->font_width)) {
348        _at->max_x_size = _at->x_for_next_button + this->get_root()->font_width;
349    }
350}
351
352/*******************************************************************************************************/
353/*******************************************************************************************************/
354/*******************************************************************************************************/
355
356int AW_window::calculate_string_width( int columns ) {
357    if ( xfig_data ) {
358        AW_xfig *xfig = (AW_xfig *)xfig_data;
359        //return columns * this->get_root()->font_width;
360        return (int)(columns * xfig->font_scale * XFIG_DEFAULT_FONT_WIDTH);   /* stdfont 8x13 */
361    }else {
362        return columns * XFIG_DEFAULT_FONT_WIDTH; /* stdfont 8x13 */
363    }
364}
365
366int AW_window::calculate_string_height( int rows , int offset ) {
367    if ( xfig_data ) {
368        AW_xfig *xfig = (AW_xfig *)xfig_data;
369        return (int)((rows * XFIG_DEFAULT_FONT_HEIGHT + offset ) * xfig->font_scale); /* stdfont 8x13 */
370    }
371    else {
372        return (rows * XFIG_DEFAULT_FONT_HEIGHT + offset );   /* stdfont 8x13 */
373    }
374}
375
376
377char *AW_window::align_string(const char *label_text, int columns) {
378    // shortens or expands 'label_text' to 'columns' columns
379    // if label_text contains '\n', each "line" is handled separately
380
381    const char *lf     = strchr(label_text, '\n');
382    char       *result = 0;
383
384    if (!lf) {
385        result = (char*)malloc(columns+1);
386       
387        int len              = strlen(label_text);
388        if (len>columns) len = columns;
389
390        memcpy(result, label_text, len);
391        if (len<columns) memset(result+len, ' ', columns-len);
392        result[columns] = 0;
393    }
394    else {
395        char *part1    = GB_strpartdup(label_text, lf-1);
396        char *aligned1 = align_string(part1, columns);
397        char *aligned2 = align_string(lf+1, columns);
398
399        result = GBS_global_string_copy("%s\n%s", aligned1, aligned2);
400
401        free(aligned2);
402        free(aligned1);
403        free(part1);
404    }
405    return result;
406}
407
408/*******************************************************************************************************/
409/*******************************************************************************************************/
410/*******************************************************************************************************/
411
412void AW_at_size::store(const AW_at *at) {
413    to_position_exists = at->to_position_exists;
414    if (to_position_exists) {
415        to_offset_x = at->to_position_x - at->x_for_next_button;
416        to_offset_y = at->to_position_y - at->y_for_next_button;
417    }
418    attach_x   = at->attach_x;
419    attach_y   = at->attach_y;
420    attach_lx  = at->attach_lx;
421    attach_ly  = at->attach_ly;
422    attach_any = at->attach_any;
423}
424void AW_at_size::restore(AW_at *at) const {
425    at->to_position_exists = to_position_exists;
426    if (to_position_exists) {
427        at->to_position_x = at->x_for_next_button + to_offset_x;
428        at->to_position_y = at->y_for_next_button + to_offset_y;
429    }
430    at->attach_x   = attach_x;
431    at->attach_y   = attach_y;
432    at->attach_lx  = attach_lx;
433    at->attach_ly  = attach_ly;
434    at->attach_any = attach_any;
435}
436
437
438void AW_at_maxsize::store(const AW_at *at) {
439    maxx = at->max_x_size;
440    maxy = at->max_y_size;
441}
442void AW_at_maxsize::restore(AW_at *at) const {
443    at->max_x_size = maxx;
444    at->max_y_size = maxy;
445}
446
447
448
Note: See TracBrowser for help on using the repository browser.