00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #include "framework/gui/jed_btn.h"
00023 #include "lista.cc"
00024
00025 #include <stdio.h>
00026 #include <string.h>
00027 #include <stdlib.h>
00028
00029 #ifdef MOTIF_ENABLED
00030 #include <Xm/Xm.h>
00031 #include <Xm/Frame.h>
00032 #include <Xm/Label.h>
00033 #include <Xm/PushB.h>
00034 #include <Xm/RowColumnP.h>
00035 #include <Xm/ScrolledW.h>
00036 #include <Xm/Separator.h>
00037 #include <Xm/ToggleB.h>
00038 #include <Xm/ToggleBG.h>
00039
00040 #include "framework/gui/_motifcb.h"
00041 #endif
00042
00043 #define ESPERO_BOTONERA(tipo, msg) \
00044 if ( tipo_token != (tipo) ) { \
00045 fprintf(stderr,"<GUI_BOTONERA> ERROR: Esperaba %s y recibi [%s].\n", \
00046 (msg), cad); fflush(stderr); return FALSE; \
00047 }
00048
00049 #define ESPERO_SUB_BOTONERA(tipo, msg) \
00050 if ( tipo_token != (tipo) ) { \
00051 fprintf(stderr,"<GUI_BOTONERA> ERROR: Esperaba %s y recibi [%s].\n", \
00052 (msg), cad); fflush(stderr); return FALSE; \
00053 }
00054
00055
00056
00057
00058
00059 #ifdef MOTIF_ENABLED
00060
00061 void
00062 titlebot_callback(Widget , XtPointer data, XtPointer callData)
00063 {
00064 XmToggleButtonCallbackStruct *cbs =
00065 (XmToggleButtonCallbackStruct *) callData;
00066 Widget rcframe = (Widget)data;
00067
00068 if ( cbs->set ) {
00069 XtManageChild(rcframe);
00070 }
00071 else {
00072 XtUnmanageChild(rcframe);
00073 }
00074 }
00075
00076 #endif // MOTIF_ENABLED
00077
00078
00079
00080
00081
00082 GUI_BOTONERA::GUI_BOTONERA(LISTA<GUI_CONSTANTE_ENTERA *> *tabla_constantes,
00083 LISTA <GUI_COMANDO *> *Comandos)
00084 {
00085 Tabla_idcs = tabla_constantes;
00086 Lista_comandos = Comandos;
00087 _nombre = NULL;
00088
00089
00090 estilo = EGB_VERTICAL;
00091 botones_por_fila = 2;
00092 }
00093
00094 char *
00095 GUI_BOTONERA::nombre(void)
00096 {
00097 return _nombre;
00098 }
00099
00100 BOOLEAN
00101 GUI_BOTONERA::leer_estilo(TOKENIZADOR *Sabiondo)
00102 {
00103 char cad[1000];
00104 int tipo_token = TK_DESCONOCIDO, pos;
00105
00106 pos = 2;
00107 while ( tipo_token != TK_CERRAR) {
00108 tipo_token = Sabiondo->siguiente_token(cad);
00109 switch ( pos ) {
00110 case 2: ESPERO_BOTONERA(TK_ABRIR, "\"{\""); pos++; break;
00111 default:
00112 if ( tipo_token == TK_CERRAR ) break;
00113 ESPERO_BOTONERA(TK_IDENTIFICADOR, "un indicador de estilo");
00114
00115 if ( strcmp(cad, "HORIZONTAL") == 0 ) {
00116 estilo &= ~EGB_VERTICAL;
00117 }
00118 else if ( strcmp(cad, "CON_SEPARADOR") == 0 ) {
00119 estilo |= EGB_CON_SEPARADOR;
00120 }
00121 else if ( strcmp(cad, "CON_TITULO") == 0 ) {
00122 estilo |= EGB_CON_TITULO;
00123 }
00124 else if ( strcmp(cad, "ACTIVABLE") == 0 ) {
00125 estilo |= EGB_ACTIVABLE;
00126 }
00127 else if ( strcmp(cad, "tam") == 0 ) {
00128 tipo_token = Sabiondo->siguiente_token(cad);
00129 ESPERO_BOTONERA(TK_NUMERO, "un entero");
00130 botones_por_fila = atoi(cad);
00131
00132 if ( botones_por_fila < 1 ) {
00133 fprintf(stderr, "<GUI_BOTONERA> - Warning: "
00134 "tam debe ser al menos de 1!\n");
00135 fflush(stderr);
00136 botones_por_fila = 1;
00137 }
00138 if ( botones_por_fila > 4 ) {
00139 fprintf(stderr, "<GUI_BOTONERA> - Warning: "
00140 "tam debe ser maximo de %d!\n", 4);
00141 fflush(stderr);
00142 botones_por_fila = 4;
00143 }
00144 }
00145 else {
00146 fprintf(stderr,
00147 "<GUI_BOTONERA> - Warning: el estilo \"%s\" no es valido\n",
00148 cad);
00149 fflush(stderr);
00150 }
00151
00152 }
00153 }
00154
00155 return TRUE;
00156 }
00157
00158 BOOLEAN
00159 GUI_BOTONERA::leer(TOKENIZADOR *Sabiondo)
00160 {
00161 char cad[1000];
00162 int tipo_token = TK_DESCONOCIDO, pos;
00163 GUI_SUB_BOTONERA *Grupo;
00164
00165 pos = 1;
00166 while ( tipo_token != TK_CERRAR) {
00167 tipo_token = Sabiondo->siguiente_token(cad);
00168 switch ( pos ) {
00169 case 1:
00170 ESPERO_BOTONERA(TK_CADENA, "Un nombre de botonera"); pos++;
00171 des_comille(cad);
00172 _nombre = new char[strlen(cad) + 1];
00173 if ( !_nombre ) {
00174 fprintf(stderr, "<GUI_BOTONERA> - ERROR: No hay memoria para "
00175 "crear una cadenita!\n");
00176 fflush(stderr);
00177 return FALSE;
00178 }
00179 strcpy(_nombre, cad);
00180 break;
00181 case 2: ESPERO_BOTONERA(TK_ABRIR, "\"{\""); pos++; break;
00182 default:
00183 if ( tipo_token == TK_CERRAR ) break;
00184 ESPERO_BOTONERA(TK_IDENTIFICADOR, "una subbotonera, o atributo");
00185
00186 if ( strcmp(cad, "GRUPO") == 0 ) {
00187 Grupo = new GUI_SUB_BOTONERA(Tabla_idcs, Lista_comandos);
00188 if ( !Grupo ) {
00189 fprintf(stderr, "<GUI_BOTONERA> - ERROR: No hay memoria para "
00190 "crear una sub-botonera!\n");
00191 fflush(stderr);
00192 return FALSE;
00193 }
00194 Grupo->leer(Sabiondo);
00195 lista_grupos.anx(Grupo);
00196 }
00197 else if ( strcmp(cad, "ESTILO") == 0 ) {
00198 if ( !leer_estilo(Sabiondo) ) return FALSE;
00199 }
00200 else {
00201 fprintf(stderr,
00202 "<GUI_BOTONERA> - Error de sintaxis leyendo %s\n",cad);
00203 fflush(stderr);
00204 return FALSE;
00205 }
00206
00207 }
00208 }
00209
00210 return TRUE;
00211 }
00212
00213 void
00214 GUI_BOTONERA::imprimir(void)
00215 {
00216 int i;
00217
00218 printf(
00219 "- REPORTE DE BOTONERA ------------------------------------------------\n"
00220 "La botonera \"%s\" tiene %ld grupos:\n", _nombre, lista_grupos.tam());
00221
00222 for ( i = 0; i < lista_grupos.tam(); i++ ) {
00223 printf(" = GRUPO #%d: ", i);
00224 lista_grupos[i]->imprimir();
00225 }
00226
00227 printf("- Fin de reporte de botonera -\n");
00228 }
00229
00230 #ifdef MOTIF_ENABLED
00231
00232 Widget
00233 GUI_BOTONERA::crear_motif(Widget padre)
00234 {
00235 Widget org, columna;
00236 int i;
00237
00238 org = XtVaCreateManagedWidget("[BOTONERA]", xmScrolledWindowWidgetClass,
00239 padre, XmNscrollingPolicy, XmAUTOMATIC, XmNshadowThickness, 0,
00240 XmNscrollBarDisplayPolicy, XmSTATIC,
00241
00242 NULL);
00243
00244 columna = XtVaCreateManagedWidget("[RC]", xmRowColumnWidgetClass, org,
00245 XmNmarginHeight, 5, XmNmarginWidth, 5, XmNnumColumns, 1,
00246 XmNorientation, XmVERTICAL, XmNpacking, XmPACK_TIGHT,
00247 XmNresizeHeight, True, XmNresizeWidth, True, XmNspacing, 5,
00248 NULL);
00249
00250 for ( i = 0; i < lista_grupos.tam(); i++ ) {
00251 lista_grupos[i]->crear_motif(columna, estilo, botones_por_fila);
00252 }
00253
00254
00255 XtManageChild(columna);
00256
00257 Dimension x, y;
00258
00259 XtVaGetValues(columna, XmNwidth, &x, XmNheight, &y, NULL);
00260
00261 XtResizeWidget(org, x + 23, y, 0);
00262 XtManageChild(org);
00263
00264 return org;
00265 }
00266
00267 #endif // MOTIF_ENABLED
00268
00269
00270
00271
00272
00273 GUI_SUB_BOTONERA::GUI_SUB_BOTONERA(LISTA<GUI_CONSTANTE_ENTERA *> *tabla_constantes,
00274 LISTA <GUI_COMANDO *> *Comandos)
00275 {
00276 Tabla_idcs = tabla_constantes;
00277 Lista_comandos = Comandos;
00278 nombre = NULL;
00279 }
00280
00281 #ifdef MOTIF_ENABLED
00282
00283 Widget
00284 GUI_SUB_BOTONERA::crear_motif(Widget padre, BYTE estilo, int botones_por_fila)
00293 {
00294 Widget frame, form, rcframe, rowcolumn;
00295 Widget title, titlefr, boton, sep;
00296 int i;
00297 XmString xstr_tmp;
00298
00299
00300 frame = XtVaCreateManagedWidget("[Fr]", xmFrameWidgetClass, padre,
00301 XmNshadowType, XmSHADOW_IN, XmNshadowThickness, 1, NULL);
00302 form = XtVaCreateManagedWidget("[Fo]", xmFormWidgetClass, frame, NULL);
00303 rcframe = XtVaCreateManagedWidget("[Fr]", xmFrameWidgetClass, form,
00304 XmNshadowThickness, 0, XmNshadowType, XmSHADOW_OUT, NULL);
00305
00306 rowcolumn = XtVaCreateManagedWidget("[RC]",
00307 xmRowColumnWidgetClass, rcframe,
00308 XmNmarginWidth, 1, XmNmarginHeight, 1, XmNpacking, XmPACK_COLUMN,
00309 XmNspacing, 0, XmNrightAttachment, XmATTACH_FORM, XmNrightOffset, 2,
00310 XmNleftAttachment, XmATTACH_FORM, XmNleftOffset, 2,
00311 XmNnumColumns, botones_por_fila, NULL);
00312
00313 if ( estilo & EGB_VERTICAL ) {
00314 XtVaSetValues(rowcolumn, XmNorientation, XmVERTICAL, NULL);
00315 }
00316 else {
00317 XtVaSetValues(rowcolumn, XmNorientation, XmHORIZONTAL, NULL);
00318 }
00319
00320 if ( estilo & EGB_CON_TITULO ) {
00321 titlefr = XtVaCreateManagedWidget("[Fr]", xmFrameWidgetClass, form,
00322 XmNshadowType, XmSHADOW_OUT, XmNshadowThickness, 1,
00323 XmNtopAttachment, XmATTACH_FORM, XmNtopOffset, 0,
00324 XmNrightAttachment, XmATTACH_FORM, XmNrightOffset, 0,
00325 XmNleftAttachment, XmATTACH_FORM, XmNleftOffset, 0, NULL);
00326
00327
00328
00329
00330 if ( estilo & EGB_ACTIVABLE ) {
00331 title = XtVaCreateManagedWidget("Titulito",
00332 xmToggleButtonWidgetClass,
00333 titlefr, XmNshadowThickness, 0,
00334 XmNhighlightThickness, 1,
00335 NULL);
00336
00337 XtAddCallback(title, XmNvalueChangedCallback, titlebot_callback,
00338 rcframe);
00339
00340 XmToggleButtonSetState(title, True, False);
00341 }
00342 else {
00343 title = XtVaCreateManagedWidget("Titulillo",
00344 xmLabelWidgetClass,
00345 titlefr, XmNshadowThickness, 0,
00346 XmNhighlightThickness, 1, NULL);
00347 }
00348
00349 xstr_tmp = XmStringCreateLocalized(nombre);
00350 XtVaSetValues(title, XmNlabelString, xstr_tmp, NULL);
00351 XmStringFree(xstr_tmp);
00352
00353
00354 XtVaSetValues(rcframe, XmNtopAttachment, XmATTACH_WIDGET,
00355 XmNtopWidget, titlefr, XmNtopOffset, 0, NULL);
00356 }
00357 else {
00358 XtVaSetValues(rcframe, XmNtopAttachment, XmATTACH_FORM,
00359 XmNtopOffset, 1, NULL);
00360 }
00361
00362
00363 if ( estilo & EGB_CON_SEPARADOR ) {
00364 sep = XtVaCreateManagedWidget("---", xmSeparatorWidgetClass, form,
00365 XmNorientation, XmHORIZONTAL,
00366 XmNbottomAttachment, XmATTACH_FORM, XmNbottomOffset, 2,
00367 XmNrightAttachment, XmATTACH_FORM, XmNrightOffset, 2,
00368 XmNleftAttachment, XmATTACH_FORM, XmNleftOffset, 2, NULL);
00369 XtVaSetValues(rcframe, XmNbottomAttachment, XmATTACH_WIDGET,
00370 XmNbottomWidget, sep, XmNbottomOffset, 0, NULL);
00371 }
00372 else {
00373 XtVaSetValues(rcframe, XmNbottomAttachment, XmATTACH_FORM,
00374 XmNbottomOffset, 0, NULL);
00375 XtVaSetValues(rcframe, XmNshadowThickness, 1, NULL);
00376 }
00377
00378
00379 Pixmap pixmap = XmUNSPECIFIED_PIXMAP, arm_pixmap = XmUNSPECIFIED_PIXMAP;
00380 FILE *fd;
00381 IMAGEN_RGB imagen;
00382 char icono[256];
00383
00384 for ( i = 0; i < botones.tam(); i++ ) {
00385
00386 boton = XtVaCreateManagedWidget(botones[i]->nombre(),
00387 xmPushButtonWidgetClass, rowcolumn, XmNlabelType,
00388 XmPIXMAP, XmNshadowThickness, 1, XmNmarginHeight, 1,
00389 XmNmarginWidth, 1, XmNhighlightThickness,1,
00390 XmNfillOnArm, True, NULL);
00391
00392
00393 sprintf(icono, "./etc/icons/%s", botones[i]->archivo_icono());
00394 fd = fopen(icono, "rb");
00395
00396 if ( !fd || !imagen.importar_ppm(fd) ) {
00397 fprintf(stderr,
00398 "<GUI_SUB_BOTONERA> - Error: No puedo leer el icono \"%s\".\n",
00399 icono);
00400 fflush(stderr);
00401 }
00402 else {
00403 fclose(fd);
00404 pixmap = imagen.exportar_pixmap(
00405 XtDisplay(boton), XtScreen(boton), XtWindow(boton));
00406
00407
00408 arm_pixmap = pixmap;
00409 XtVaSetValues(boton, XmNlabelPixmap, pixmap,
00410 XmNarmPixmap, arm_pixmap, NULL);
00411 }
00412
00413
00414 XtAddCallback(boton,
00415 XmNactivateCallback, motif_ejecutor, (void *)idcs[i]);
00416 XtManageChild(boton);
00417 }
00418
00419
00420
00421 XtManageChild(rcframe);
00422 XtManageChild(frame);
00423
00424 return frame;
00425 }
00426
00427 #endif // MOTIF_ENABLED
00428
00429 BOOLEAN
00430 GUI_SUB_BOTONERA::leer(TOKENIZADOR *Sabiondo)
00431 {
00432 char cad[1000];
00433 int tipo_token = TK_DESCONOCIDO, pos, i, val = -666;
00434 int *ptr;
00435
00436 pos = 1;
00437 while ( tipo_token != TK_CERRAR) {
00438 tipo_token = Sabiondo->siguiente_token(cad);
00439 switch ( pos ) {
00440 case 1:
00441 ESPERO_SUB_BOTONERA(TK_CADENA, "Un nombre de botonera"); pos++;
00442 des_comille(cad);
00443 nombre = new char[strlen(cad) + 1];
00444 if ( !nombre ) {
00445 fprintf(stderr, "<GUI_BOTONERA> - ERROR: No hay memoria para "
00446 "crear una cadenita!\n");
00447 fflush(stderr);
00448 return FALSE;
00449 }
00450 strcpy(nombre, cad);
00451 break;
00452 case 2: ESPERO_SUB_BOTONERA(TK_ABRIR, "\"{\""); pos++; break;
00453 default:
00454 if ( tipo_token == TK_CERRAR ) break;
00455 ESPERO_SUB_BOTONERA(TK_IDENTIFICADOR,
00456 "un identificador de GUI_COMANDO");
00457
00458
00459 for ( i = 0; i < Tabla_idcs->tam(); i++ ) {
00460 if ( strcmp((*Tabla_idcs)[i]->nombre, cad) == 0 ) {
00461 val = (*Tabla_idcs)[i]->valor;
00462 break;
00463 }
00464 }
00465
00466
00467 if ( i >= Tabla_idcs->tam() ) {
00468 fprintf(stderr, "<GUI_SUB_BOTONERA> - Warning: "
00469 "la constante %s no esta definida.\n", cad);
00470 fflush(stderr);
00471 }
00472 else {
00473 for ( i = 0; i < Lista_comandos->tam(); i++ ) {
00474 if ( (*Lista_comandos)[i]->id() == val ) {
00475 botones.anx((*Lista_comandos)[i]);
00476 ptr = new int;
00477 (*ptr) = (*Lista_comandos)[i]->id();
00478 idcs.anx( ptr );
00479 break;
00480 }
00481 }
00482
00483 if ( i >= Lista_comandos->tam() ) {
00484 fprintf(stderr, "<GUI_SUB_BOTONERA> - Warning:\n"
00485 " La constante %s esta definida, pero no posee \n"
00486 " asociado comando alguno.\n", cad);
00487 fflush(stderr);
00488 }
00489 }
00490
00491 }
00492 }
00493
00494 return TRUE;
00495 }
00496
00497 void
00498 GUI_SUB_BOTONERA::imprimir(void)
00499 {
00500 int i;
00501
00502 printf("\"%s\", con %ld botones.\n", nombre, botones.tam());
00503
00504 for ( i = 0; i < botones.tam(); i++ ) {
00505 printf(" - %s\n", botones[i]->nombre());
00506 }
00507 }
00508
00509
00510
00511
00512