/* ---------------------------------------------------------------- * * cxt_dbox.c * * Xlib - wrappers and convenience functions * * Christoph Birk, OCIW, Pasadena, CA (birk@obs.carnegiescience.edu) * * v4.00 2002-03-27 libcxt.a * 4.070 2015-02-03 use CXT_OpenMainWindow() * * ---------------------------------------------------------------- */ #define IS_CXTLIB_C /* DEFINEs -------------------------------------------------------- */ #ifndef DEBUG #define DEBUG 1 /* debug level */ #endif #ifdef FONTSIZE #define PXh FONTSIZE #else #define PXh 14 /* default fontsize */ #endif #define PXw (10+(PXh-14)/2) #define XXh (PXh+4) #define PREFUN __func__ /* INCLUDEs ------------------------------------------------------- */ #define _REENTRANT #include /* malloc() */ #include /* strcpy() */ #if (DEBUG > 0) #include /* fprintf() */ #endif #include "cxt.h" /* EXTERNs -------------------------------------------------------- */ extern int cbx_max (int,int); /* ---------------------------------------------------------------- */ /* Dialog Boxes */ /* ---------------------------------------------------------------- */ Bool CBX_MultiParBox(char* title,char** legend,char** answer,int* taboo) { MainWindow box; int i,n,w1,w2,w=12*PXw,h=3*PXh; const int OKw=3*PXw,CAw=6*PXw+PXw/2; int done=0; XSizeHints hint; XEvent event; Button okbut,cabut; EditWindow *pawin; w1 = cbx_max(3*PXw,(PXw*strlen(title))/3); w2 = cbx_max(5*PXw,(PXw*strlen(title))/2+PXw/2); w = cbx_max(w,w1+w2+3*PXw); for (n=0; *legend[n] != '\0'; n++) { w1 = cbx_max(w1, PXw*strlen(legend[n])); w2 = cbx_max(w2,2*PXw*strlen(answer[n])); } w = PXw/2+w1+PXw+w2+PXw; h = 3*PXh+n*(XXh+PXh/2); CXT_OpenMainWindow(&box,CBX_CENTER,w,h,&hint,title,"MParBox",True); for (n=0; *legend[n] != '\0'; n++) { w1 = cbx_max(w1, CBX_TextWidth(&box,legend[n])); w2 = cbx_max(w2,2*CBX_TextWidth(&box,answer[n])); } w = PXw/2+w1+PXw+w2+PXw; CBX_MoveResizeMainWindow(&box,CBX_CENTER,w,h); pawin = (EditWindow*)malloc(n*sizeof(EditWindow)); for (i=0; i 0) { /* OK */ for (i=0; i 1) fprintf(stderr,"%s(%s,%s,%s): %x\n",PREFUN,title,text,buttons,CXTLIB_VERSION); #endif strcpy(buffer,buttons); p = buffer; while ((s=strchr(p,'|')) != NULL) { *s = '\0'; btxt[n] = (char*)malloc(1+strlen(p)); strcpy(btxt[n],p); w += (strlen(p)+3)*PXw; n++; p = s+1; } btxt[n] = (char*)malloc(1+strlen(p)); strcpy(btxt[n],p); w += (strlen(p)+3)*PXw; n++; w = cbx_max(w,cbx_max(PXw*(strlen(title)+3),PXw*(strlen(text)+1))); CXT_OpenMainWindow(&box,CBX_CENTER,w,h,&hint,title,"Dialog",True); w = cbx_max(w,cbx_max(CBX_TextWidth(&box,title)+3*PXw, w2=CBX_TextWidth(&box,text)+PXw)); for (i=0,j=2; i 1) fprintf(stderr,"%s(%s): w=%d, h=%d\n",PREFUN,title,w,h); #endif CBX_MoveResizeMainWindow(&box,CBX_CENTER,w,h); do { /* event loop */ (void)CBX_WaitEvent(&box,&event,200); switch (event.type) { case Expose: /* expose event */ CBX_DrawString(&box,5+(w-w2)/2,PXh+PXh/2,text); for (i=0; i 0) { for (i=0; i 1) fprintf(stderr,"%s() w=%d, h=%d\n",PREFUN,w,h); #endif but = (Button*)malloc(n_items*sizeof(Button)); /* allocate button */ for (i=0; i 1) fprintf(stderr,"%s() but=%p\n",PREFUN,(void*)but); #endif while (done == 0) { /* event loop */ (void)CBX_WaitEvent(&box,&event,100); switch (event.type) { /* select event.type */ case Expose: /* expose events */ if (event.xexpose.count != 0) break; for (i=0; i 0) return(done-1); return(-1); } #undef Y /* ---------------------------------------------------------------- */ /* ---------------------------------------------------------------- */ /* ---------------------------------------------------------------- */