00001
00002
00003
00004
00005 #include "win.h"
00006
00007 extern lux_wins *get_currentwin();
00008 extern lux_wins *lux_allocwin();
00009
00010 extern XFontStruct *font_info;
00011 extern unsigned long BLACK_COLOR, WHITE_COLOR;
00012 extern unsigned long lux_get_fgcolor();
00013 extern unsigned long lux_get_bgcolor();
00014
00015
00016 lux_highlight(win)
00017 Window win;
00018 {
00019 register lux_wins *current, *parent;
00020 XGCValues values;
00021
00022
00023 current = get_currentwin(win);
00024 parent = get_currentwin(current->win.parent);
00025
00026 XGetGCValues(parent->win.display, parent->win.gc,
00027 GCLineWidth | GCLineStyle | GCForeground | GCBackground |
00028 GCCapStyle | GCJoinStyle,
00029 &values);
00030
00031 XSetLineAttributes(parent->win.display, parent->win.gc, 1, LineSolid,
00032 CapButt, JoinBevel);
00033
00034 XSetForeground(parent->win.display, parent->win.gc, BLACK_COLOR);
00035
00036 XDrawRectangle(parent->win.display, parent->win.window, parent->win.gc,
00037 current->win.x-1, current->win.y-1,
00038 current->win.width+3, current->win.height+3);
00039
00040 XSetLineAttributes(parent->win.display, parent->win.gc,
00041 values.line_width, values.line_style,
00042 values.cap_style, values.join_style);
00043
00044 XSetForeground(parent->win.display, parent->win.gc, values.foreground);
00045
00046 }
00047
00048 lux_unhighlight(win)
00049 Window win;
00050 {
00051 register lux_wins *current, *parent;
00052 XGCValues values;
00053
00054
00055 current = get_currentwin(win);
00056 parent = get_currentwin(current->win.parent);
00057
00058 XGetGCValues(parent->win.display, parent->win.gc,
00059 GCLineWidth | GCLineStyle | GCForeground | GCBackground |
00060 GCCapStyle | GCJoinStyle,
00061 &values);
00062
00063 XSetLineAttributes(parent->win.display, parent->win.gc, 1, LineSolid,
00064 CapButt, JoinBevel);
00065
00066 XSetForeground(parent->win.display, parent->win.gc, values.background);
00067
00068 XDrawRectangle(parent->win.display, parent->win.window, parent->win.gc,
00069 current->win.x-1, current->win.y-1,
00070 current->win.width+3, current->win.height+3);
00071
00072 XSetLineAttributes(parent->win.display, parent->win.gc,
00073 values.line_width, values.line_style,
00074 values.cap_style, values.join_style);
00075
00076 XSetForeground(parent->win.display, parent->win.gc, values.foreground);
00077
00078 }
00079
00080 Window lux_open_dialog(x, y, width, height)
00081 unsigned int x, y, width, height;
00082 {
00083 register lux_wins *mywin;
00084 static int status = 0;
00085
00086 if ( !status ) {
00087 lux_xinit();
00088 status = 1;
00089 }
00090
00091 if ((mywin = lux_allocwin()) == (lux_wins *)NULL ) return((Window)NULL);
00092
00093 mywin->win.type = DIALOG_WINDOW;
00094 mywin->win.window_name = "Dialog Window";
00095
00096 mywin->win.x = x;
00097 mywin->win.y = y;
00098 mywin->win.width = width;
00099 mywin->win.height = height;
00100 mywin->win.old_width = width;
00101 mywin->win.old_height = height;
00102 mywin->win.user_width = width;
00103 mywin->win.user_height = height;
00104 mywin->win.xresizefactor = 1.0;
00105 mywin->win.yresizefactor = 1.0;
00106
00107 mywin->win.fxorg = 0.0;
00108 mywin->win.fyorg = 0.0;
00109 mywin->win.fxsize = 10.0;
00110 mywin->win.fysize = 10.0;
00111 mywin->win.xfactor = 1.0;
00112 mywin->win.yfactor = 1.0;
00113 mywin->win.xmin = 0.0;
00114 mywin->win.xmax = width;
00115 mywin->win.ymin = 0.0;
00116 mywin->win.ymax = height;
00117 mywin->win.xsize = width;
00118 mywin->win.ysize = height;
00119 mywin->win.xorg = 0;
00120 mywin->win.yorg = 0;
00121
00122 lux_createwin(&mywin->win);
00123
00124 return(mywin->win.window);
00125 }
00126
00127 lux_set_item(dialog, num, type, subtype, x, y, length, def_value)
00128 Window dialog;
00129 int num, subtype, type, x, y, length;
00130 char *def_value;
00131 {
00132 register lux_wins *mywin;
00133 register lux_wins *diawin;
00134 static int status = 0;
00135
00136
00137
00138 switch(type) {
00139
00140 case TEXT_WINDOW:
00141 lux_draw_string(dialog, (float)x, (float)y, 0.0, def_value, -1);
00142 break;
00143
00144 case BUTTON_WINDOW:
00145 case INPUT_WINDOW:
00146
00147 if ((mywin = lux_allocwin()) == (lux_wins *)NULL ) return((Window)NULL);
00148 mywin->win.type = type;
00149 mywin->win.subtype = subtype;
00150 mywin->win.parent = dialog;
00151 mywin->win.serial = num;
00152
00153 diawin = get_currentwin(dialog);
00154
00155 mywin->win.x = x;
00156 mywin->win.y = diawin->win.height - y -
00157 (font_info->ascent + font_info->descent);
00158 if (subtype == CHECK_BUTTON)
00159 mywin->win.width=mywin->win.height=font_info->ascent+font_info->descent;
00160 else {
00161 mywin->win.width = length * XTextWidth(font_info, "X", 1)+4;
00162 mywin->win.height = font_info->ascent + font_info->descent + 4;
00163 }
00164 mywin->win.old_width = mywin->win.user_width = mywin->win.width;
00165 mywin->win.old_height = mywin->win.user_height = mywin->win.height;
00166 mywin->win.xresizefactor = 1.0;
00167 mywin->win.yresizefactor = 1.0;
00168
00169 mywin->win.fxorg = 0.0;
00170 mywin->win.fyorg = 0.0;
00171 mywin->win.fxsize = 10.0;
00172 mywin->win.fysize = 10.0;
00173 mywin->win.xfactor = 1.0;
00174 mywin->win.yfactor = 1.0;
00175 mywin->win.xmin = 0.0;
00176 mywin->win.xmax = mywin->win.width;
00177 mywin->win.ymin = 0.0;
00178 mywin->win.ymax = mywin->win.height;
00179 mywin->win.xsize = mywin->win.width;
00180 mywin->win.ysize = mywin->win.height;
00181 mywin->win.xorg = 0;
00182 mywin->win.yorg = 0;
00183
00184 lux_createwin(&mywin->win);
00185
00186 if (type == BUTTON_WINDOW) {
00187 if (subtype == OK_BUTTON || subtype == OK_KEEP_BUTTON
00188 || subtype == CANCEL_BUTTON)
00189 lux_draw_string(mywin->win.window, mywin->win.width/2.0,
00190 4.0, 0.0, def_value, 0);
00191 else if (subtype == CHECK_BUTTON) {
00192 if (def_value[0] == 1) {
00193 lux_draw_line(mywin->win.window, 0, 0,
00194 mywin->win.width, mywin->win.height);
00195 lux_draw_line(mywin->win.window, 0, mywin->win.height,
00196 mywin->win.width, 0);
00197 }
00198 mywin->win.msg[1] = mywin->win.msg[0] = def_value[0];
00199
00200 }
00201 }
00202 else if (type == INPUT_WINDOW) {
00203 lux_draw_string(mywin->win.window, 2.0, 4.0, 0.0, def_value, -1);
00204 {
00205 char *new;
00206 int i;
00207 new = (char *)malloc(255);
00208 new[0] = (char)NULL; mywin->win.msg[0] = (char)NULL;
00209 for(i=0;i<sizeof(float)*3+1;i++)
00210 new[i] = mywin->win.data->data.b[i];
00211 new[i] = (char)NULL;
00212 strcat(&new[i],&(mywin->win.data->data.b[i]));
00213 strcat(mywin->win.msg,&(mywin->win.data->data.b[i]));
00214 free(mywin->win.data->data.b);
00215 mywin->win.data->data.b = new;
00216 }
00217 }
00218 break;
00219
00220 default:
00221 fprintf(stderr, "\n Something not expected in create item!\n ");
00222 break;
00223 }
00224
00225 return(1);
00226 }
00227
00228 lux_draw_palette(dialog)
00229 Window dialog;
00230 {
00231 register lux_wins *current;
00232 register unsigned long i;
00233 unsigned long c;
00234
00235 current = get_currentwin(dialog);
00236
00237 c = lux_get_fgcolor(dialog);
00238 for(i=0;i<256;i++) {
00239 lux_set_color(dialog, i);
00240 lux_draw_line(dialog, 0, (int)(i*2), 20, (int)(i*2));
00241 lux_draw_line(dialog, 0, (int)(i*2+1), 20, (int)(i*2+1));
00242 }
00243 lux_set_color(dialog,c);
00244 lux_draw_line(dialog, 20, 0, 20, 512);
00245 }
00246
00247 lux_update_itemvalue(dialog, num, type, subtype, value)
00248 Window dialog;
00249 int num, type, subtype;
00250 char *value;
00251 {
00252 register lux_wins *current, *old;
00253
00254 old = current = get_currentwin(dialog);
00255
00256 while(current->win.parent != dialog || current->win.serial != num ||
00257 current->win.type != type || current->win.subtype != subtype ) {
00258 current = current->next;
00259 if (old == current) {
00260 fprintf(stderr, "lux_update_itemvalue: dialog item not found\n");
00261 return(0);
00262 }
00263 }
00264
00265 switch(current->win.type) {
00266 case INPUT_WINDOW:
00267 current->win.msg[0] = 0;
00268 strcat(current->win.msg, value);
00269 current->win.data->data.b[sizeof(float)*3+1] = 0;
00270 strcat(&(current->win.data->data.b[sizeof(float)*3+1]), value);
00271 redraw(current->win.window,1);
00272 break;
00273 case BUTTON_WINDOW:
00274 if (current->win.subtype == CHECK_BUTTON) {
00275 if (current->win.msg[0] == 0 && value[0] == 1) {
00276 lux_draw_line(current->win.window, 0, 0,
00277 current->win.width, current->win.height);
00278 lux_draw_line(current->win.window, 0, current->win.height,
00279 current->win.width, 0);
00280 }
00281 else if (current->win.msg[0] == 1 && value[0] == 0)
00282 lux_reset_window(current->win.window);
00283 current->win.msg[1] = current->win.msg[0] = value[0];
00284 }
00285 break;
00286 default:
00287 break;
00288 }
00289 return(1);
00290 }
00291
00292 lux_get_itemvalue(dialog, num, type, subtype, value)
00293 Window dialog;
00294 int num, type, subtype;
00295 char *value;
00296 {
00297 register lux_wins *current, *old;
00298
00299 old = current = get_currentwin(dialog);
00300
00301 value[0] = (char)NULL;
00302
00303 while(current->win.parent != dialog || current->win.serial != num ||
00304 current->win.type != type || current->win.subtype != subtype ) {
00305 current = current->next;
00306 if (old == current) {
00307 fprintf(stderr, "lux_get_itemvalue: dialog item not found\n");
00308 return(0);
00309 }
00310 }
00311
00312 switch(current->win.type) {
00313 case INPUT_WINDOW:
00314 strcat(value, current->win.msg);
00315 break;
00316 case BUTTON_WINDOW:
00317 if (current->win.subtype == CHECK_BUTTON)
00318 value[0] = current->win.msg[0];
00319 break;
00320 default:
00321 break;
00322 }
00323 return(1);
00324 }
00325
00326
00327 lux_show_dialog(win)
00328 Window win;
00329 {
00330 register lux_wins *current, *old;
00331
00332 old = current = get_currentwin(win);
00333
00334 while(current->win.type != DIALOG_WINDOW
00335 ) {
00336 current = current->next;
00337 if (old == current) {
00338 fprintf(stderr, "No dialog window opened!\n");
00339 return(0);
00340 }
00341
00342 }
00343
00344 XMapWindow(current->win.display, current->win.window);
00345
00346 return(1);
00347 }
00348
00349 lux_hide_dialog(dia)
00350 Window dia;
00351 {
00352 register lux_wins *current;
00353
00354 current = get_currentwin(dia);
00355
00356 XUnmapWindow(current->win.display, current->win.window);
00357 return(1);
00358 }
00359
00360 lux_ok_data(dialog)
00361 Window dialog;
00362 {
00363
00364 register lux_wins *current, *old;
00365
00366 old = current = get_currentwin(dialog);
00367
00368 current = current->next;
00369 while(old != current) {
00370 if (current->win.parent != dialog ||
00371 (current->win.type != INPUT_WINDOW &&
00372 current->win.type != BUTTON_WINDOW)) {
00373 current = current->next;continue;
00374 }
00375 if (current->win.type == INPUT_WINDOW )
00376
00377 strcpy(current->win.msg,
00378 &(current->win.data->data.b[3*sizeof(float)+1]));
00379 else
00380 switch(current->win.subtype) {
00381 case CHECK_BUTTON:
00382 current->win.msg[1] = current->win.msg[0];
00383 break;
00384 case OK_BUTTON:
00385 case OK_KEEP_BUTTON:
00386 case CANCEL_BUTTON:
00387 default:
00388 break;
00389 }
00390 current = current->next;
00391 }
00392 }
00393
00394 lux_cancel_data(dialog)
00395 Window dialog;
00396 {
00397 register lux_wins *current, *old;
00398
00399 old = current = get_currentwin(dialog);
00400
00401 current = current->next;
00402 while(old != current) {
00403 if (current->win.parent != dialog ||
00404 (current->win.type != INPUT_WINDOW &&
00405 current->win.type != BUTTON_WINDOW)) {
00406 current = current->next; continue;
00407 }
00408 if (current->win.type == INPUT_WINDOW) {
00409 strcpy(&(current->win.data->data.b[3*sizeof(float)+1]),
00410 current->win.msg);
00411 }
00412 else
00413 switch(current->win.subtype) {
00414 case CHECK_BUTTON:
00415 if (current->win.msg[1] == 0 && current->win.msg[0] == 1)
00416 lux_reset_window(current->win.window);
00417 else if (current->win.msg[1] == 1 && current->win.msg[0] == 0) {
00418 lux_draw_line(current->win.window, 0, 0,
00419 current->win.width, current->win.height);
00420 lux_draw_line(current->win.window, 0, current->win.height,
00421 current->win.width, 0);
00422 }
00423 current->win.msg[0] = current->win.msg[1];
00424 break;
00425 case OK_BUTTON:
00426 case OK_KEEP_BUTTON:
00427 case CANCEL_BUTTON:
00428 default:
00429 break;
00430 }
00431 current = current->next;
00432 }
00433 }
00434
00435