| 1 | #include <stdio.h> |
|---|
| 2 | #include <string.h> |
|---|
| 3 | #include <memory.h> |
|---|
| 4 | #include <arbdb.h> |
|---|
| 5 | #include <aw_root.hxx> |
|---|
| 6 | #include <aw_device.hxx> |
|---|
| 7 | #include <aw_window.hxx> |
|---|
| 8 | // PJ vectorfont stuff: |
|---|
| 9 | //#include <aw_xfig.hxx> |
|---|
| 10 | //#include <aw_xfigfont.hxx> |
|---|
| 11 | |
|---|
| 12 | #ifdef _ARB_AWT |
|---|
| 13 | #include "awt.hxx" |
|---|
| 14 | #endif |
|---|
| 15 | |
|---|
| 16 | #include <stdarg.h> |
|---|
| 17 | #include <stdlib.h> |
|---|
| 18 | |
|---|
| 19 | #include "aw_preset.hxx" |
|---|
| 20 | |
|---|
| 21 | #ifdef _ARB_WINDOW |
|---|
| 22 | |
|---|
| 23 | void AW_save_defaults( AW_window *aw ) { |
|---|
| 24 | aw->get_root()->save_default( "window/font" ); |
|---|
| 25 | } |
|---|
| 26 | |
|---|
| 27 | void aw_message_reload(AW_root *){ |
|---|
| 28 | aw_message( "Sorry, to activate new colors:\n" |
|---|
| 29 | " save properties\n" |
|---|
| 30 | " and restart application"); |
|---|
| 31 | } |
|---|
| 32 | char *aw_glob_font_awar_name = 0; |
|---|
| 33 | |
|---|
| 34 | void aw_set_color(AW_window *aww,const char *color_name){ |
|---|
| 35 | aww->get_root()->awar(aw_glob_font_awar_name)->write_string(color_name); |
|---|
| 36 | } |
|---|
| 37 | |
|---|
| 38 | // -------------------------------------------------------------------------------- |
|---|
| 39 | // static int hex2dez(char c) |
|---|
| 40 | // -------------------------------------------------------------------------------- |
|---|
| 41 | static int hex2dez(char c) { |
|---|
| 42 | if (c>='0' && c<='9') return c-'0'; |
|---|
| 43 | if (c>='A' && c<='F') return c-'A'+10; |
|---|
| 44 | if (c>='a' && c<='f') return c-'a'+10; |
|---|
| 45 | return -1; |
|---|
| 46 | } |
|---|
| 47 | |
|---|
| 48 | // -------------------------------------------------------------------------------- |
|---|
| 49 | // void aw_incdec_color(AW_window *aww,const char *action) |
|---|
| 50 | // -------------------------------------------------------------------------------- |
|---|
| 51 | void aw_incdec_color(AW_window *aww,const char *action){ |
|---|
| 52 | // action is sth like "r+" "b-" "g++" "r--" |
|---|
| 53 | AW_awar *awar = aww->get_root()->awar(aw_glob_font_awar_name); |
|---|
| 54 | char *color = awar->read_string(); |
|---|
| 55 | AW_BOOL err = AW_TRUE; |
|---|
| 56 | |
|---|
| 57 | fprintf(stderr, "current color is '%s'\n", color); |
|---|
| 58 | |
|---|
| 59 | if (color[0]=='#') { |
|---|
| 60 | int len = strlen(color); |
|---|
| 61 | if (len==4 || len==7) { |
|---|
| 62 | len = (len-1)/3; // len of one color channel (1 or 2) |
|---|
| 63 | gb_assert(len==1 || len==2); |
|---|
| 64 | |
|---|
| 65 | int diff = action[2]==action[1] ? 7 : 1; |
|---|
| 66 | |
|---|
| 67 | int channel[3]; |
|---|
| 68 | for (int c=0; c<3; ++c) { |
|---|
| 69 | if (len==2) channel[c] = hex2dez(color[c*len+1])*16+hex2dez(color[c*len+2]); |
|---|
| 70 | else channel[c] = hex2dez(color[c*len+1])*16; |
|---|
| 71 | } |
|---|
| 72 | |
|---|
| 73 | int rgb; |
|---|
| 74 | for (rgb=0; rgb<3;++rgb) { |
|---|
| 75 | if (action[0]=="rgb"[rgb] || action[0]=='a') { |
|---|
| 76 | if (action[1]=='+') { channel[rgb] += diff; if (channel[rgb]>255) channel[rgb]=255; } |
|---|
| 77 | else { channel[rgb] -= diff; if (channel[rgb]<0) channel[rgb]=0; } |
|---|
| 78 | } |
|---|
| 79 | } |
|---|
| 80 | |
|---|
| 81 | sprintf(color, "#%2.2X%2.2X%2.2X", channel[0], channel[1], channel[2]); |
|---|
| 82 | |
|---|
| 83 | err = AW_FALSE; |
|---|
| 84 | awar->write_string(color); |
|---|
| 85 | } |
|---|
| 86 | } |
|---|
| 87 | |
|---|
| 88 | if (err) { |
|---|
| 89 | aw_message("Only color values in #rgb- or #rrggbb-style \n" |
|---|
| 90 | "can be modified by these buttons. \n" |
|---|
| 91 | "Choose a color below and try again."); |
|---|
| 92 | } |
|---|
| 93 | } |
|---|
| 94 | |
|---|
| 95 | #define AWAR_GLOBAL_COLOR_NAME "tmp/aw/color_label" |
|---|
| 96 | |
|---|
| 97 | void aw_create_color_chooser_window(AW_window *aww, const char *awar_name,const char *label_name){ |
|---|
| 98 | AW_root *awr = aww->get_root(); |
|---|
| 99 | static AW_window_simple *aws = 0; |
|---|
| 100 | if (!aws){ |
|---|
| 101 | int x1, y1, x2, y2; |
|---|
| 102 | |
|---|
| 103 | awr->awar_string(AWAR_GLOBAL_COLOR_NAME); |
|---|
| 104 | aws = new AW_window_simple; |
|---|
| 105 | aws->init(awr, "COLORS", "COLORS", 400, 300); |
|---|
| 106 | aws->at(10, 10); |
|---|
| 107 | aws->auto_space(3, 3); |
|---|
| 108 | aws->callback ( AW_POPDOWN ); |
|---|
| 109 | aws->create_button( "CLOSE","CLOSE", "C" ); |
|---|
| 110 | aws->get_at_position(&x1, &y1); |
|---|
| 111 | aws->at_newline(); |
|---|
| 112 | |
|---|
| 113 | aws->button_length(20); |
|---|
| 114 | aws->create_button( "LABEL",AWAR_GLOBAL_COLOR_NAME, "A" ); |
|---|
| 115 | aws->get_at_position(&x2, &y2); |
|---|
| 116 | aws->at_newline(); |
|---|
| 117 | |
|---|
| 118 | x1 = x1>x2 ? x1 : x2; |
|---|
| 119 | |
|---|
| 120 | int red,green,blue; |
|---|
| 121 | |
|---|
| 122 | for (int minus = 0; minus<=1; ++minus) { |
|---|
| 123 | aws->at(x1, minus==0 ? y1 : y2); |
|---|
| 124 | for (int rgb=0; rgb<4; ++rgb) { |
|---|
| 125 | for (int big=0; big<=1; ++big) { |
|---|
| 126 | aws->button_length(2+big); |
|---|
| 127 | |
|---|
| 128 | char action[4] = "xxx"; |
|---|
| 129 | action[0] = "rgba"[rgb]; |
|---|
| 130 | action[1] = "+-"[minus]; |
|---|
| 131 | action[2] = big ? action[1] : 0; |
|---|
| 132 | |
|---|
| 133 | char color_name[10]; |
|---|
| 134 | sprintf(color_name, "#%2.2X%2.2X%2.2X", rgb==0 ? 0xff : 0x55, rgb==1 ? 0xff : 0x55, rgb==2 ? 0xff : 0x55); |
|---|
| 135 | aws->set_background(color_name); |
|---|
| 136 | aws->callback((AW_CB1)aw_incdec_color, (AW_CL)strdup(action)); |
|---|
| 137 | aws->create_button(action, action+1); |
|---|
| 138 | } |
|---|
| 139 | } |
|---|
| 140 | } |
|---|
| 141 | |
|---|
| 142 | aws->button_length(2); |
|---|
| 143 | aws->at_newline(); |
|---|
| 144 | |
|---|
| 145 | for (red = 0; red <= 255; red += 255/3){ |
|---|
| 146 | for (green = 0; green <= 255; green += 255/3){ |
|---|
| 147 | for (blue = 0; blue <= 255; blue += 255/3){ |
|---|
| 148 | char color_name[256]; |
|---|
| 149 | sprintf(color_name,"#%2.2X%2.2X%2.2X", red, green,blue); |
|---|
| 150 | aws->set_background(color_name); |
|---|
| 151 | aws->callback((AW_CB1)aw_set_color,(AW_CL)strdup(color_name)); |
|---|
| 152 | aws->create_button(color_name,"="); |
|---|
| 153 | } |
|---|
| 154 | } |
|---|
| 155 | aws->at_newline(); |
|---|
| 156 | } |
|---|
| 157 | for (red = 0; red <= 256; red += 256/16){ // grey buttons |
|---|
| 158 | char color_name[256]; |
|---|
| 159 | sprintf(color_name,"#%2.2X%2.2X%2.2X", (red==256)?255:red, (red>=256)?255:red,(red>=256)?255:red); |
|---|
| 160 | aws->set_background(color_name); |
|---|
| 161 | aws->callback((AW_CB1)aw_set_color,(AW_CL)strdup(color_name)); |
|---|
| 162 | aws->create_button(color_name,"="); |
|---|
| 163 | } |
|---|
| 164 | aws->at_newline(); |
|---|
| 165 | |
|---|
| 166 | aws->window_fit(); |
|---|
| 167 | } |
|---|
| 168 | awr->awar(AWAR_GLOBAL_COLOR_NAME)->write_string(label_name); |
|---|
| 169 | delete aw_glob_font_awar_name; |
|---|
| 170 | aw_glob_font_awar_name = strdup(awar_name); |
|---|
| 171 | aws->show(); |
|---|
| 172 | } |
|---|
| 173 | |
|---|
| 174 | |
|---|
| 175 | |
|---|
| 176 | void AW_preset_create_color_chooser(AW_window *aws, const char *awar, const char *label,int message_reload) |
|---|
| 177 | { |
|---|
| 178 | if (message_reload){ |
|---|
| 179 | aws->get_root()->awar(awar)->add_callback(aw_message_reload); |
|---|
| 180 | } |
|---|
| 181 | aws->callback((AW_CB)aw_create_color_chooser_window,(AW_CL)strdup(awar),(AW_CL)strdup(label)); |
|---|
| 182 | aws->create_button("SELECT A COLOR","S"); |
|---|
| 183 | } |
|---|
| 184 | |
|---|
| 185 | void AW_preset_create_font_chooser(AW_window *aws, const char *awar, const char *label,int message_reload) |
|---|
| 186 | { |
|---|
| 187 | if (message_reload){ |
|---|
| 188 | aws->get_root()->awar(awar)->add_callback(aw_message_reload); |
|---|
| 189 | } |
|---|
| 190 | |
|---|
| 191 | aws->create_option_menu( awar, label ); |
|---|
| 192 | aws->insert_option ( "5x8", "5", "5x8" ); |
|---|
| 193 | aws->insert_option ( "6x10", "6", "6x10" ); |
|---|
| 194 | aws->insert_option ( "7x13", "7", "7x13" ); |
|---|
| 195 | aws->insert_option ( "7x13bold", "7", "7x13bold" ); |
|---|
| 196 | aws->insert_option ( "8x13", "8", "8x13" ); |
|---|
| 197 | aws->insert_option ( "8x13bold", "8", "8x13bold" ); |
|---|
| 198 | aws->insert_option ( "9x15", "9", "9x15" ); |
|---|
| 199 | aws->insert_option ( "9x15bold", "9", "9x15bold" ); |
|---|
| 200 | aws->insert_option ( "helvetica-12", "9", "helvetica-12" ); |
|---|
| 201 | aws->insert_option ( "helvetica-bold-12", "9", "helvetica-bold-12" ); |
|---|
| 202 | aws->insert_option ( "helvetica-13", "9", "helvetica-13" ); |
|---|
| 203 | aws->insert_option ( "helvetica-bold-13", "9", "helvetica-bold-13" ); |
|---|
| 204 | aws->insert_default_option( "other", "o", "" ); |
|---|
| 205 | aws->update_option_menu(); |
|---|
| 206 | } |
|---|
| 207 | |
|---|
| 208 | //PJ - vectorfont stuff - user may set a factor for global scaling |
|---|
| 209 | void AW_preset_create_scale_chooser(AW_window *aws, char *awar, char *label) |
|---|
| 210 | { |
|---|
| 211 | char buffer[2]; buffer[0] = label[0]; buffer[1] = 0; |
|---|
| 212 | aws->create_option_menu( awar, label, buffer ); |
|---|
| 213 | aws->insert_option ( "0.5", " ", (float) 0.5); |
|---|
| 214 | aws->insert_option ( "0.8", "0", (float) 0.8); |
|---|
| 215 | aws->insert_option ( "1.0", "1", (float) 1.0); |
|---|
| 216 | aws->insert_default_option( "other", "o", (float) 1.0 ); |
|---|
| 217 | aws->update_option_menu(); |
|---|
| 218 | } |
|---|
| 219 | |
|---|
| 220 | struct AW_MGC_awar_cb_struct; |
|---|
| 221 | struct AW_MGC_cb_struct { // one for each window |
|---|
| 222 | AW_MGC_cb_struct(AW_window *awi, |
|---|
| 223 | void (*g)(AW_window*,AW_CL ,AW_CL), AW_CL cd1i, AW_CL cd2i); |
|---|
| 224 | AW_window *aw; |
|---|
| 225 | void (*f)(AW_window*,AW_CL ,AW_CL); |
|---|
| 226 | AW_CL cd1; |
|---|
| 227 | AW_CL cd2; |
|---|
| 228 | char *window_awar_name; |
|---|
| 229 | AW_device *device; |
|---|
| 230 | struct AW_MGC_awar_cb_struct *next_drag; |
|---|
| 231 | }; |
|---|
| 232 | |
|---|
| 233 | AW_MGC_cb_struct::AW_MGC_cb_struct( AW_window *awi, |
|---|
| 234 | void (*g)(AW_window*,AW_CL,AW_CL), AW_CL cd1i, AW_CL cd2i ) { |
|---|
| 235 | memset((char*)this,0,sizeof(AW_MGC_cb_struct)); |
|---|
| 236 | aw = awi; |
|---|
| 237 | f = g; |
|---|
| 238 | cd1 = cd1i; |
|---|
| 239 | cd2 = cd2i; |
|---|
| 240 | window_awar_name = GBS_string_2_key(awi->get_window_title()); |
|---|
| 241 | } |
|---|
| 242 | |
|---|
| 243 | struct AW_MGC_awar_cb_struct { // one for each awar |
|---|
| 244 | struct AW_MGC_cb_struct *cbs; |
|---|
| 245 | const char *fontbasename; |
|---|
| 246 | const char *colorbasename; |
|---|
| 247 | short gc; |
|---|
| 248 | short gc_drag; |
|---|
| 249 | short colorindex; |
|---|
| 250 | struct AW_MGC_awar_cb_struct *next; |
|---|
| 251 | }; |
|---|
| 252 | |
|---|
| 253 | struct aw_gc_manager { |
|---|
| 254 | const char *field; |
|---|
| 255 | const char *default_value; |
|---|
| 256 | struct aw_gc_manager *next; |
|---|
| 257 | }; |
|---|
| 258 | |
|---|
| 259 | void aw_gc_changed_cb(AW_root *awr,AW_MGC_awar_cb_struct *cbs, long mode) |
|---|
| 260 | { |
|---|
| 261 | // mode == -1 -> no callback |
|---|
| 262 | char awar_name[256]; |
|---|
| 263 | int font; |
|---|
| 264 | int size; |
|---|
| 265 | |
|---|
| 266 | sprintf(awar_name,AWP_FONTNAME_TEMPLATE,cbs->cbs->window_awar_name,cbs->fontbasename); |
|---|
| 267 | font = (int)awr->awar(awar_name)->read_int(); |
|---|
| 268 | |
|---|
| 269 | sprintf(awar_name,AWP_FONTSIZE_TEMPLATE,cbs->cbs->window_awar_name,cbs->fontbasename); |
|---|
| 270 | size = (int)awr->awar(awar_name)->read_int(); |
|---|
| 271 | |
|---|
| 272 | cbs->cbs->device->set_font(cbs->gc,font,size); |
|---|
| 273 | cbs->cbs->device->set_font(cbs->gc_drag,font,size); |
|---|
| 274 | if (mode != -1) cbs->cbs->f(cbs->cbs->aw,cbs->cbs->cd1,cbs->cbs->cd2); |
|---|
| 275 | } |
|---|
| 276 | |
|---|
| 277 | void aw_gc_color_changed_cb(AW_root *root,AW_MGC_awar_cb_struct *cbs, long mode) |
|---|
| 278 | { |
|---|
| 279 | char awar_name[256]; |
|---|
| 280 | char *colorname; |
|---|
| 281 | |
|---|
| 282 | sprintf(awar_name,AWP_COLORNAME_TEMPLATE,cbs->cbs->window_awar_name,cbs->colorbasename); |
|---|
| 283 | colorname = root->awar(awar_name)->read_string(); |
|---|
| 284 | AW_color color = (AW_color)cbs->colorindex; |
|---|
| 285 | cbs->cbs->aw->alloc_named_data_color(color,colorname); |
|---|
| 286 | if (color != AW_DATA_BG) { |
|---|
| 287 | cbs->cbs->device->set_foreground_color(cbs->gc,color); |
|---|
| 288 | cbs->cbs->device->set_foreground_color(cbs->gc_drag,color); |
|---|
| 289 | }else{ |
|---|
| 290 | struct AW_MGC_awar_cb_struct *acbs; |
|---|
| 291 | for (acbs = cbs->cbs->next_drag; acbs; acbs=acbs->next){ |
|---|
| 292 | cbs->cbs->device->set_foreground_color(acbs->gc_drag,(AW_color)acbs->colorindex); |
|---|
| 293 | } |
|---|
| 294 | } |
|---|
| 295 | if (mode != -1) { |
|---|
| 296 | cbs->cbs->f(cbs->cbs->aw,cbs->cbs->cd1,cbs->cbs->cd2); |
|---|
| 297 | } |
|---|
| 298 | delete colorname; |
|---|
| 299 | } |
|---|
| 300 | |
|---|
| 301 | |
|---|
| 302 | |
|---|
| 303 | AW_gc_manager AW_manage_GC(AW_window *aww, |
|---|
| 304 | AW_device *device, int base_gc, int base_drag, AW_GCM_AREA area, |
|---|
| 305 | void (*changecb)(AW_window*,AW_CL,AW_CL), AW_CL cd1, AW_CL cd2, |
|---|
| 306 | const char *default_background_color, |
|---|
| 307 | ...){ |
|---|
| 308 | /* |
|---|
| 309 | * Parameter: aww: base window |
|---|
| 310 | * device: screen device |
|---|
| 311 | * base_gc: first gc number |
|---|
| 312 | * base_drag: one after last gc |
|---|
| 313 | * area: middle,top ... |
|---|
| 314 | * changecb: cb if changed |
|---|
| 315 | * cd1,cd2: free Parameters to changecb |
|---|
| 316 | * |
|---|
| 317 | * ...: NULL terminated list of \0 terminated strings: |
|---|
| 318 | * |
|---|
| 319 | * first GC is fixed: '-background' |
|---|
| 320 | * |
|---|
| 321 | * optionsSTRING name of GC and AWAR |
|---|
| 322 | * options: # fixed fonts only |
|---|
| 323 | * - no fonts |
|---|
| 324 | * = no color selector |
|---|
| 325 | * + append in same line |
|---|
| 326 | * |
|---|
| 327 | * $color at end of string => define default color value |
|---|
| 328 | */ |
|---|
| 329 | AW_root *aw_root = aww->get_root(); |
|---|
| 330 | AW_default aw_def = AW_ROOT_DEFAULT; |
|---|
| 331 | const char *id; |
|---|
| 332 | va_list parg; |
|---|
| 333 | va_start(parg,default_background_color); |
|---|
| 334 | AW_font def_font; |
|---|
| 335 | struct aw_gc_manager *gcmgrlast=0,*gcmgr2=0,*gcmgrfirst=0; |
|---|
| 336 | |
|---|
| 337 | AW_MGC_cb_struct *mcbs = new AW_MGC_cb_struct(aww,changecb,cd1,cd2); |
|---|
| 338 | mcbs->device = device; |
|---|
| 339 | |
|---|
| 340 | int col = AW_WINDOW_BG; |
|---|
| 341 | if (area == AW_GCM_DATA_AREA) { |
|---|
| 342 | col = AW_DATA_BG; |
|---|
| 343 | } |
|---|
| 344 | AW_BOOL first = AW_TRUE; |
|---|
| 345 | |
|---|
| 346 | aww->main_drag_gc = base_drag; |
|---|
| 347 | gcmgrfirst = gcmgrlast = new aw_gc_manager; |
|---|
| 348 | gcmgrfirst->next =0; |
|---|
| 349 | gcmgrfirst->field = mcbs->window_awar_name; |
|---|
| 350 | const char *old_font_base_name = "default"; |
|---|
| 351 | |
|---|
| 352 | // char *awar_background_name = 0; |
|---|
| 353 | |
|---|
| 354 | char background[50]; |
|---|
| 355 | gb_assert(default_background_color[0]); |
|---|
| 356 | |
|---|
| 357 | sprintf(background, "-background$%s", default_background_color); |
|---|
| 358 | |
|---|
| 359 | for (id = background; id; id=va_arg(parg,char *)){ // "-background$#3be" |
|---|
| 360 | AW_BOOL flag_fixed_fonts_only = AW_FALSE; |
|---|
| 361 | AW_BOOL flag_no_color_selector = AW_FALSE; |
|---|
| 362 | AW_BOOL flag_append_in_same_line = AW_FALSE; |
|---|
| 363 | AW_BOOL flag_no_fonts = AW_FALSE; |
|---|
| 364 | |
|---|
| 365 | AW_MGC_awar_cb_struct *acbs = 0; |
|---|
| 366 | { |
|---|
| 367 | char * id_copy = strdup(id); |
|---|
| 368 | char *color = strchr(id_copy, '$'); // search color def |
|---|
| 369 | if (color) { |
|---|
| 370 | *color++ = 0; |
|---|
| 371 | } |
|---|
| 372 | else { |
|---|
| 373 | if (first) color = "white"; |
|---|
| 374 | else color = "navy"; |
|---|
| 375 | } |
|---|
| 376 | |
|---|
| 377 | gcmgr2 = new aw_gc_manager; |
|---|
| 378 | gcmgr2->field = strdup(id_copy); |
|---|
| 379 | gcmgr2->default_value = color ? strdup(color) : 0; |
|---|
| 380 | gcmgr2->next = 0; |
|---|
| 381 | gcmgrlast->next = gcmgr2; |
|---|
| 382 | gcmgrlast = gcmgr2; |
|---|
| 383 | |
|---|
| 384 | acbs = new AW_MGC_awar_cb_struct; |
|---|
| 385 | acbs->cbs = mcbs; |
|---|
| 386 | acbs->colorbasename = GBS_string_2_key(id_copy); |
|---|
| 387 | acbs->gc = base_gc; |
|---|
| 388 | acbs->gc_drag = base_drag; |
|---|
| 389 | if (!first) { |
|---|
| 390 | acbs->next = mcbs->next_drag; |
|---|
| 391 | mcbs->next_drag = acbs; |
|---|
| 392 | } |
|---|
| 393 | |
|---|
| 394 | int offset = 0; |
|---|
| 395 | while (1){ |
|---|
| 396 | switch( id_copy[offset] ){ |
|---|
| 397 | case '#': flag_fixed_fonts_only = AW_TRUE; offset++; continue; |
|---|
| 398 | case '-': flag_no_fonts = AW_TRUE; offset++; continue; |
|---|
| 399 | case '=': flag_no_color_selector = AW_TRUE; offset++; continue; |
|---|
| 400 | case '+': flag_append_in_same_line = AW_TRUE; offset++; continue; |
|---|
| 401 | default: break; |
|---|
| 402 | } |
|---|
| 403 | break; |
|---|
| 404 | } |
|---|
| 405 | |
|---|
| 406 | free(id_copy); id_copy = 0; |
|---|
| 407 | } |
|---|
| 408 | |
|---|
| 409 | if (flag_fixed_fonts_only) def_font = AW_LUCIDA_SANS_TYPEWRITER; |
|---|
| 410 | else def_font = AW_LUCIDA_SANS; |
|---|
| 411 | |
|---|
| 412 | if ((area != AW_GCM_DATA_AREA) || !first) { |
|---|
| 413 | device->new_gc(base_gc); |
|---|
| 414 | device->set_line_attributes(base_gc,0.0,AW_SOLID); |
|---|
| 415 | device->set_function(base_gc,AW_COPY); |
|---|
| 416 | |
|---|
| 417 | device->new_gc(base_drag); |
|---|
| 418 | device->set_line_attributes(base_drag,0.0,AW_SOLID); |
|---|
| 419 | device->set_function(base_drag,AW_XOR); |
|---|
| 420 | } |
|---|
| 421 | |
|---|
| 422 | char awar_name[256]; memset(awar_name,0,256); |
|---|
| 423 | sprintf(awar_name,AWP_COLORNAME_TEMPLATE,mcbs->window_awar_name,acbs->colorbasename); |
|---|
| 424 | acbs->colorindex = col; |
|---|
| 425 | |
|---|
| 426 | // if (first) { |
|---|
| 427 | // awar_background_name = strdup(awar_name); |
|---|
| 428 | |
|---|
| 429 | // fprintf(stderr, "%s=%s\n", awar_name, aw_root->awar_string(awar_name)->read_string()); |
|---|
| 430 | // } |
|---|
| 431 | |
|---|
| 432 | // if (!first) { |
|---|
| 433 | // aw_root->awar_string(awar_name,"yellow",aw_def); |
|---|
| 434 | // }else{ |
|---|
| 435 | // aw_root->awar_string(awar_name,"navy",aw_def); |
|---|
| 436 | // } |
|---|
| 437 | |
|---|
| 438 | aw_root->awar_string(awar_name, gcmgr2->default_value, aw_def); |
|---|
| 439 | aw_root->awar(awar_name)->add_callback( (AW_RCB)aw_gc_color_changed_cb,(AW_CL)acbs,(AW_CL)0); |
|---|
| 440 | |
|---|
| 441 | aw_gc_color_changed_cb(aw_root,acbs,-1); |
|---|
| 442 | |
|---|
| 443 | if (!flag_no_fonts) { |
|---|
| 444 | old_font_base_name = acbs->fontbasename = acbs->colorbasename; |
|---|
| 445 | }else{ |
|---|
| 446 | acbs->fontbasename = old_font_base_name; |
|---|
| 447 | } |
|---|
| 448 | |
|---|
| 449 | sprintf(awar_name,AWP_FONTNAME_TEMPLATE,mcbs->window_awar_name,acbs->fontbasename); |
|---|
| 450 | aw_root->awar_int(awar_name,def_font,aw_def)->add_callback((AW_RCB)aw_gc_changed_cb,(AW_CL)acbs,(AW_CL)0); |
|---|
| 451 | |
|---|
| 452 | sprintf(awar_name,AWP_FONTSIZE_TEMPLATE, mcbs->window_awar_name,acbs->fontbasename); |
|---|
| 453 | aw_root->awar_int(awar_name,12,aw_def)->add_callback((AW_RCB)aw_gc_changed_cb,(AW_CL)acbs,(AW_CL)0); |
|---|
| 454 | |
|---|
| 455 | if (!first) { |
|---|
| 456 | aw_gc_changed_cb(aw_root,acbs,-1); |
|---|
| 457 | base_gc++; |
|---|
| 458 | base_drag++; |
|---|
| 459 | } |
|---|
| 460 | col++; |
|---|
| 461 | first = AW_FALSE; |
|---|
| 462 | } |
|---|
| 463 | |
|---|
| 464 | // if (awar_background_name) { |
|---|
| 465 | // char *content = aw_root->awar(awar_background_name)->read_string(); |
|---|
| 466 | // fprintf(stderr, "content='%s'\n", content); |
|---|
| 467 | |
|---|
| 468 | // AW_awar *awar = aw_root->awar(awar_background_name); |
|---|
| 469 | // awar->write_string("#000"); |
|---|
| 470 | // awar->write_string("#f00"); // rot zum testen @@@ |
|---|
| 471 | |
|---|
| 472 | // free(awar_background_name); |
|---|
| 473 | // } |
|---|
| 474 | |
|---|
| 475 | return (AW_gc_manager)gcmgrfirst; |
|---|
| 476 | } |
|---|
| 477 | |
|---|
| 478 | AW_window *AW_create_gc_window(AW_root * aw_root, AW_gc_manager id_par) |
|---|
| 479 | { |
|---|
| 480 | //crazy simple function |
|---|
| 481 | // The window has already been created |
|---|
| 482 | AW_window_simple * aws = new AW_window_simple; |
|---|
| 483 | aws->init(aw_root, "PROPS_GC", "COLORS AND FONTS", 400, 300); |
|---|
| 484 | |
|---|
| 485 | aw_gc_manager *gcmgr = (aw_gc_manager *) id_par; |
|---|
| 486 | |
|---|
| 487 | aws->at(10, 10); |
|---|
| 488 | aws->auto_space(5, 5); |
|---|
| 489 | |
|---|
| 490 | aws->callback((AW_CB0) AW_POPDOWN); |
|---|
| 491 | aws->create_button("CLOSE","CLOSE", "C"); |
|---|
| 492 | aws->at_newline(); |
|---|
| 493 | AW_BOOL first = AW_TRUE; |
|---|
| 494 | const char *window_awar_name = gcmgr->field; |
|---|
| 495 | |
|---|
| 496 | for (gcmgr = gcmgr->next; gcmgr; gcmgr = gcmgr->next) { |
|---|
| 497 | const char *id = gcmgr->field; |
|---|
| 498 | |
|---|
| 499 | AW_BOOL flag_fixed_fonts_only = AW_FALSE; |
|---|
| 500 | AW_BOOL flag_no_color_selector = AW_FALSE; |
|---|
| 501 | AW_BOOL flag_append_in_same_line = AW_FALSE; |
|---|
| 502 | AW_BOOL flag_no_fonts = AW_FALSE; |
|---|
| 503 | while (1){ |
|---|
| 504 | switch( id[0] ){ |
|---|
| 505 | case '#': flag_fixed_fonts_only = AW_TRUE; id++; continue; |
|---|
| 506 | case '-': flag_no_fonts = AW_TRUE; id++; continue; |
|---|
| 507 | case '=': flag_no_color_selector = AW_TRUE; id++; continue; |
|---|
| 508 | case '+': flag_append_in_same_line = AW_TRUE; id++; continue; |
|---|
| 509 | default: break; |
|---|
| 510 | } |
|---|
| 511 | break; |
|---|
| 512 | } |
|---|
| 513 | char *fontbasename = GBS_string_2_key(id); |
|---|
| 514 | char awar_name[256]; |
|---|
| 515 | sprintf(awar_name, AWP_COLORNAME_TEMPLATE,window_awar_name, fontbasename); |
|---|
| 516 | aws->label_length(15); |
|---|
| 517 | |
|---|
| 518 | |
|---|
| 519 | aws->label(id); |
|---|
| 520 | if (!flag_no_color_selector){ |
|---|
| 521 | aws->button_length(2); |
|---|
| 522 | AW_preset_create_color_chooser(aws, awar_name, id); |
|---|
| 523 | } |
|---|
| 524 | aws->create_input_field(awar_name, 10); |
|---|
| 525 | |
|---|
| 526 | if (!flag_no_fonts) { |
|---|
| 527 | |
|---|
| 528 | sprintf(awar_name, AWP_FONTNAME_TEMPLATE,window_awar_name, fontbasename); |
|---|
| 529 | aws->label_length(5); |
|---|
| 530 | aws->create_option_menu(awar_name, "Font", 0);{ |
|---|
| 531 | int font_nr; |
|---|
| 532 | const char *font_string; |
|---|
| 533 | for (font_nr = 0;; font_nr++) { |
|---|
| 534 | font_string = aw_root->font_2_ascii((AW_font) font_nr); |
|---|
| 535 | if (!font_string) |
|---|
| 536 | break; |
|---|
| 537 | |
|---|
| 538 | if (flag_fixed_fonts_only && aw_root->font_2_xfig((AW_font) font_nr) >= 0) |
|---|
| 539 | continue; |
|---|
| 540 | aws->insert_option(font_string, 0, (int) font_nr); |
|---|
| 541 | } |
|---|
| 542 | aws->update_option_menu(); |
|---|
| 543 | } |
|---|
| 544 | |
|---|
| 545 | sprintf(awar_name, AWP_FONTSIZE_TEMPLATE,window_awar_name, fontbasename); |
|---|
| 546 | aws->label_length(5); |
|---|
| 547 | |
|---|
| 548 | aws->create_option_menu(awar_name, "size", 0); |
|---|
| 549 | int size; |
|---|
| 550 | char ssize[20]; |
|---|
| 551 | for (size = 2; size < 25; size++) { |
|---|
| 552 | sprintf(ssize, "%i", size); |
|---|
| 553 | aws->insert_option(ssize, 0, (int) size); |
|---|
| 554 | } |
|---|
| 555 | aws->update_option_menu(); |
|---|
| 556 | |
|---|
| 557 | } |
|---|
| 558 | if (!flag_append_in_same_line) aws->at_newline(); |
|---|
| 559 | first = AW_FALSE; |
|---|
| 560 | delete fontbasename; |
|---|
| 561 | } |
|---|
| 562 | aws->window_fit(); |
|---|
| 563 | return (AW_window *) aws; |
|---|
| 564 | } |
|---|
| 565 | #endif //ifdef _ARB_WINDOW |
|---|
| 566 | |
|---|
| 567 | |
|---|
| 568 | #ifdef _ARB_AWT |
|---|
| 569 | // callback to reset to default font |
|---|
| 570 | void awt_xfig_font_resetfont_cb(AW_window *aws){ |
|---|
| 571 | AW_root *aw_root = aws->get_root(); |
|---|
| 572 | aw_root->awar("vectorfont/file_name")->write_string("lib/pictures/fontgfx.vfont"); |
|---|
| 573 | //AW_POPDOWN(aws); |
|---|
| 574 | } |
|---|
| 575 | |
|---|
| 576 | void awt_xfig_font_create_filerequest(AW_window *aw) { |
|---|
| 577 | static AW_window_simple *aws = 0; |
|---|
| 578 | AW_root *aw_root = aw->get_root(); |
|---|
| 579 | |
|---|
| 580 | if (!aws) { |
|---|
| 581 | // called *ONCE* to open the window |
|---|
| 582 | aws = new AW_window_simple; |
|---|
| 583 | aws->init( aw_root, "SELECT_VECTORFONT", "Select Xfig Vectorfont Resource", 10, 10 ); |
|---|
| 584 | aws->load_xfig("fontgfx_request.fig"); |
|---|
| 585 | aws->at("close");aws->callback((AW_CB0)AW_POPDOWN); |
|---|
| 586 | aws->create_button("CLOSE","CLOSE","C"); |
|---|
| 587 | aws->at("reset");aws->callback((AW_CB0)awt_xfig_font_resetfont_cb); |
|---|
| 588 | aws->create_button("RESET","RESET","R"); |
|---|
| 589 | // AWT_sel_boxes.cxx |
|---|
| 590 | awt_create_selection_box((AW_window *)aws,"vectorfont","","ARBHOME"); |
|---|
| 591 | } |
|---|
| 592 | aw_root->awar("vectorfont/file_name")->write_string(aw_root->vectorfont_name); |
|---|
| 593 | aws->show(); |
|---|
| 594 | } |
|---|
| 595 | AW_window *AWT_preset_window( AW_root *root ) |
|---|
| 596 | #else |
|---|
| 597 | AW_window *AW_preset_window( AW_root *root ) |
|---|
| 598 | #endif |
|---|
| 599 | { |
|---|
| 600 | AW_window_simple *aws = new AW_window_simple; |
|---|
| 601 | const int tabstop = 400; |
|---|
| 602 | aws->init( root, "PROPS_FRAME", "WINDOW_PROPERTIES", 400, 300 ); |
|---|
| 603 | |
|---|
| 604 | aws->label_length( 25 ); |
|---|
| 605 | aws->button_length( 20 ); |
|---|
| 606 | |
|---|
| 607 | aws->at ( 10,10 ); |
|---|
| 608 | aws->auto_space(10,10); |
|---|
| 609 | aws->callback ( AW_POPDOWN ); |
|---|
| 610 | aws->create_button( "CLOSE","CLOSE", "C" ); |
|---|
| 611 | |
|---|
| 612 | aws->at_newline(); |
|---|
| 613 | |
|---|
| 614 | //PJ vectorfont stuff |
|---|
| 615 | aws->label("Vectorfont Resource"); |
|---|
| 616 | #ifdef _ARB_AWT |
|---|
| 617 | aws->callback( (AW_CB0) awt_xfig_font_create_filerequest); |
|---|
| 618 | #endif |
|---|
| 619 | aws->create_button( "SELECT VECTORFONT", "Vectorfont Select", "V" ); |
|---|
| 620 | aws->at_x(tabstop); |
|---|
| 621 | aws->create_input_field( "vectorfont/file_name",20); |
|---|
| 622 | aws->at_newline(); |
|---|
| 623 | |
|---|
| 624 | AW_preset_create_font_chooser(aws,"window/font", "Main Menu Font", 1); |
|---|
| 625 | aws->at_x(tabstop); |
|---|
| 626 | aws->create_input_field( "window/font", 12 ); |
|---|
| 627 | aws->at_newline(); |
|---|
| 628 | |
|---|
| 629 | AW_preset_create_color_chooser(aws,"window/background", "Window Background", 1 ); |
|---|
| 630 | aws->at_x(tabstop); |
|---|
| 631 | aws->create_input_field( "window/background", 12 ); |
|---|
| 632 | aws->at_newline(); |
|---|
| 633 | |
|---|
| 634 | AW_preset_create_color_chooser(aws,"window/foreground", "Window Foreground", 1 ); |
|---|
| 635 | aws->at_x(tabstop); |
|---|
| 636 | aws->create_input_field( "window/foreground", 12 ); |
|---|
| 637 | aws->at_newline(); |
|---|
| 638 | |
|---|
| 639 | |
|---|
| 640 | AW_preset_create_color_chooser(aws,"window/color_1", "COLOR 1", 1 ); |
|---|
| 641 | aws->at_x(tabstop); |
|---|
| 642 | aws->create_input_field( "window/color_1", 12 ); |
|---|
| 643 | aws->at_newline(); |
|---|
| 644 | |
|---|
| 645 | AW_preset_create_color_chooser(aws,"window/color_2", "COLOR 2", 1 ); |
|---|
| 646 | aws->at_x(tabstop); |
|---|
| 647 | aws->create_input_field( "window/color_2", 12 ); |
|---|
| 648 | aws->at_newline(); |
|---|
| 649 | |
|---|
| 650 | AW_preset_create_color_chooser(aws,"window/color_3", "COLOR 3", 1 ); |
|---|
| 651 | aws->at_x(tabstop); |
|---|
| 652 | aws->create_input_field( "window/color_3", 12 ); |
|---|
| 653 | aws->at_newline(); |
|---|
| 654 | |
|---|
| 655 | |
|---|
| 656 | aws->window_fit(); |
|---|
| 657 | return (AW_window *)aws; |
|---|
| 658 | |
|---|
| 659 | } |
|---|