Tagged files with gromacs 3.0 header and added some license info
[alexxy/gromacs.git] / src / ngmx / xdlg.c
1 /*
2  * $Id$
3  * 
4  *                This source code is part of
5  * 
6  *                 G   R   O   M   A   C   S
7  * 
8  *          GROningen MAchine for Chemical Simulations
9  * 
10  *                        VERSION 3.0
11  * 
12  * Copyright (c) 1991-2001
13  * BIOSON Research Institute, Dept. of Biophysical Chemistry
14  * University of Groningen, The Netherlands
15  * 
16  * This program is free software; you can redistribute it and/or
17  * modify it under the terms of the GNU General Public License
18  * as published by the Free Software Foundation; either version 2
19  * of the License, or (at your option) any later version.
20  * 
21  * If you want to redistribute modifications, please consider that
22  * scientific software is very special. Version control is crucial -
23  * bugs must be traceable. We will be happy to consider code for
24  * inclusion in the official distribution, but derived work must not
25  * be called official GROMACS. Details are found in the README & COPYING
26  * files - if they are missing, get the official version at www.gromacs.org.
27  * 
28  * To help us fund GROMACS development, we humbly ask that you cite
29  * the papers on the package - you can find them in the top README file.
30  * 
31  * Do check out http://www.gromacs.org , or mail us at gromacs@gromacs.org .
32  * 
33  * And Hey:
34  * Good gRace! Old Maple Actually Chews Slate
35  */
36 static char *SRCID_xdlg_c = "$Id$";
37 #include <stdio.h>
38 #include <stdlib.h>
39 #include <string.h>
40 #include "string2.h"
41 #include "assert.h"
42 #include "macros.h"
43 #include "smalloc.h"
44 #include "Xstuff.h"
45 #include "xutil.h"
46 #include "xdlg.h"
47 #include "xmb.h"
48 #include "fatal.h"
49 /*****************************
50  *
51  * Helpful routines
52  *
53  ****************************/
54 t_dlgitem *FindItem(t_dlg *dlg, t_id id)
55 {
56   int i;
57   
58   for(i=0; (i<dlg->nitem); i++)
59     if (dlg->dlgitem[i]->ID==id)
60       return dlg->dlgitem[i];
61   return NULL;
62 }
63
64 t_dlgitem *FindWin(t_dlg *dlg, Window win)
65 {
66   int i;
67   
68   for(i=0; (i<dlg->nitem); i++)
69     if (dlg->dlgitem[i]->win.self==win)
70       return dlg->dlgitem[i];
71   return NULL;
72 }
73
74 /*****************************
75  *
76  * Routines to manipulate items on a dialog box
77  *
78  ****************************/
79 bool QueryDlgItemSize(t_dlg *dlg,t_id id,int *w,int *h)
80 {
81   t_dlgitem *dlgitem;
82   
83   if ((dlgitem=FindItem(dlg,id)) != NULL) {
84     *w=dlgitem->win.width;
85     *h=dlgitem->win.height;
86     return TRUE;
87   }
88   return FALSE;
89 }
90
91 bool QueryDlgItemPos(t_dlg *dlg,t_id id,int *x0,int *y0)
92 {
93   t_dlgitem *dlgitem;
94   
95   if ((dlgitem=FindItem(dlg,id)) != NULL) {
96     *x0=dlgitem->win.x;
97     *y0=dlgitem->win.y;
98     return TRUE;
99   }
100   return FALSE;
101 }
102
103 int QueryDlgItemX(t_dlg *dlg, t_id id)
104 {
105   t_dlgitem *dlgitem;
106   
107   if ((dlgitem=FindItem(dlg,id)) != NULL) 
108     return dlgitem->win.x;
109   return 0;
110 }
111
112 int QueryDlgItemY(t_dlg *dlg, t_id id)
113 {
114   t_dlgitem *dlgitem;
115   
116   if ((dlgitem=FindItem(dlg,id)) != NULL) 
117     return dlgitem->win.y;
118   return 0;
119 }
120
121 int QueryDlgItemW(t_dlg *dlg, t_id id)
122 {
123   t_dlgitem *dlgitem;
124   
125   if ((dlgitem=FindItem(dlg,id)) != NULL) 
126     return dlgitem->win.width;
127   return 0;
128 }
129
130 int QueryDlgItemH(t_dlg *dlg, t_id id)
131 {
132   t_dlgitem *dlgitem;
133   
134   if ((dlgitem=FindItem(dlg,id)) != NULL) 
135     return dlgitem->win.height;
136   return 0;
137 }
138
139 bool SetDlgItemSize(t_dlg *dlg,t_id id,int w,int h)
140 {
141   t_dlgitem *dlgitem;
142 #ifdef DEBUG
143   int old_w, old_h;
144 #endif
145
146   if ((dlgitem=FindItem(dlg,id)) != NULL) {
147 #ifdef DEBUG
148     old_w=dlgitem->win.width;
149     old_h=dlgitem->win.height;
150 #endif
151     if (w)
152       dlgitem->win.width=w;
153     if (h)
154       dlgitem->win.height=h;
155 #ifdef DEBUG
156     fprintf(dlg->x11->console,
157             "Size window from: %dx%d to %dx%d\n",old_w,old_h,
158             dlgitem->win.width,dlgitem->win.height);
159     dlg->x11->Flush(dlg->x11);
160 #endif
161     if (dlgitem->win.self)
162       XResizeWindow(dlg->x11->disp,dlgitem->win.self,dlgitem->win.width,
163                     dlgitem->win.height);
164     if ((w) && (dlgitem->type==edlgGB)) {
165       int i;
166       t_id gid=dlgitem->GroupID;
167       t_id id=dlgitem->ID;
168       for (i=0; (i<dlg->nitem); i++) {
169         t_dlgitem *child=dlg->dlgitem[i];
170         if ((child->GroupID==gid) && (child->ID!=id))
171           SetDlgItemSize(dlg,child->ID,w-4*OFFS_X,0);
172       }
173     }
174     return TRUE;
175   }
176   return FALSE;
177 }
178
179 bool SetDlgItemPos(t_dlg *dlg,t_id id,int x0,int y0)
180 {
181   t_dlgitem *dlgitem;
182   int old_x,old_y;
183
184   if ((dlgitem=FindItem(dlg,id)) != NULL) {
185     old_x=dlgitem->win.x;
186     old_y=dlgitem->win.y;
187     dlgitem->win.x=x0;
188     dlgitem->win.y=y0;
189 #ifdef DEBUG
190     fprintf(dlg->x11->console,
191             "Move window from: %d,%d to %d,%d\n",old_x,old_y,x0,y0);
192     dlg->x11->Flush(dlg->x11);
193 #endif
194     if (dlgitem->win.self)
195       XMoveWindow(dlg->x11->disp,dlgitem->win.self,x0,y0);
196     if (dlgitem->type==edlgGB) {
197       int i,x,y;
198       t_id gid=dlgitem->GroupID;
199       t_id id=dlgitem->ID;
200       x=dlgitem->win.x+2*OFFS_X-old_x;
201       y=dlgitem->win.y+2*OFFS_Y-old_y;
202       for (i=0; (i<dlg->nitem); i++) {
203         t_dlgitem *child=dlg->dlgitem[i];
204         if ((child->GroupID==gid) && (child->ID!=id))
205           SetDlgItemPos(dlg,child->ID,child->win.x+x,child->win.y+y);
206       }
207     }
208     return TRUE;
209   }
210   return FALSE;
211 }
212
213 /*****************************
214  *
215  * Routines to extract information from the dlg proc
216  * after dlg is exec'ed
217  *
218  ****************************/
219 bool IsCBChecked(t_dlg *dlg,t_id id)
220 {
221   t_dlgitem *dlgitem;
222   
223   if ((dlgitem=FindItem(dlg,id)) != NULL)
224     if (dlgitem->type==edlgCB)
225       return dlgitem->u.checkbox.bChecked;
226   
227   return FALSE;
228 }
229
230 t_id RBSelected(t_dlg *dlg,int gid)
231 {
232   int i;
233   
234   for(i=0; (i<dlg->nitem); i++)
235     if ((dlg->dlgitem[i]->type==edlgRB) && 
236         (dlg->dlgitem[i]->u.radiobutton.bSelect) &&
237         (dlg->dlgitem[i]->GroupID==gid))
238       return dlg->dlgitem[i]->ID;
239   
240   return -1;
241 }
242
243 int EditTextLen(t_dlg *dlg,t_id id)
244 {
245   t_dlgitem *dlgitem;
246   
247   if ((dlgitem=FindItem(dlg,id)) != NULL)
248     if (dlgitem->type==edlgET)
249       return strlen(dlgitem->u.edittext.buf);
250   
251   return 0;
252 }
253
254 char *EditText(t_dlg *dlg,t_id id)
255 {
256   t_dlgitem *dlgitem;
257   
258   if ((dlgitem=FindItem(dlg,id)) != NULL)
259     if (dlgitem->type==edlgET)
260       return dlgitem->u.edittext.buf;
261   
262   return NULL;
263 }
264
265 /*****************************
266  *
267  * Exececute the dialog box procedure
268  * Returns when a button is pushed.
269  * return value is the ID of the button
270  *
271  ****************************/
272 void ShowDlg(t_dlg *dlg)
273 {
274   int i;
275   t_dlgitem *dlgitem;
276
277   XMapWindow(dlg->x11->disp,dlg->win.self);
278   XMapSubwindows(dlg->x11->disp,dlg->win.self);
279   for (i=0; (i<dlg->nitem); i++)
280     LightBorder(dlg->x11->disp,dlg->dlgitem[i]->win.self,dlg->bg);
281   XSetForeground(dlg->x11->disp,dlg->x11->gc,dlg->x11->fg);
282   for(i=0; (i<dlg->nitem); i++) {
283     dlgitem=dlg->dlgitem[i];
284     if ((dlgitem->type==edlgBN) &&
285         (dlgitem->u.button.bDefault)) {
286       PushMouse(dlg->x11->disp,dlgitem->win.self,
287                 dlgitem->win.width/2,dlgitem->win.height/2);
288       dlg->bPop=TRUE;
289       break;
290     }
291   }
292   dlg->bGrab=FALSE;
293 }
294
295 void HideDlg(t_dlg *dlg)
296 {
297   if (dlg->bPop)
298     PopMouse(dlg->x11->disp);
299
300   XUnmapSubwindows(dlg->x11->disp,dlg->win.self);
301   XUnmapWindow(dlg->x11->disp,dlg->win.self);
302 }
303
304 void NoHelp(t_dlg *dlg)
305 {
306   char **lines=NULL;
307
308   snew(lines,2);
309   lines[0]=strdup("Error");
310   lines[1]=strdup("No help for this item");
311   MessageBox(dlg->x11,dlg->wDad,"No Help",2,lines,
312              MB_OK | MB_ICONSTOP | MB_APPLMODAL,NULL,NULL);
313   sfree(lines[0]); 
314   sfree (lines[1]); 
315   sfree(lines);
316 }
317
318 void HelpDlg(t_dlg *dlg)
319 {
320   char *lines[] = {
321     "Place the cursor over one of the items",
322     "and press the F1 key to get more help.",
323     "First press the OK button."
324   };
325   MessageBox(dlg->x11,dlg->win.self,"Help Dialogbox",
326              3,lines,MB_OK | MB_ICONINFORMATION | MB_APPLMODAL,NULL,NULL);
327 }
328
329 void HelpNow(t_dlg *dlg, t_dlgitem *dlgitem)
330 {
331   char buf[80];
332   bool bCont=TRUE;
333   int  i,nlines=0;
334   char **lines=NULL;
335
336   if (!dlgitem->help) {
337     NoHelp(dlg);
338     return;
339   }
340
341   printf("%s\n",dlgitem->help);
342   do {
343     fgets2(buf,79,stdin);
344 #ifdef DEBUG
345     fprintf(dlg->x11->console,"buffer: '%s'\n",buf);
346     dlg->x11->Flush(dlg->x11);
347 #endif
348     if (strcasecmp(buf,"nok")==0) {
349       /* An error occurred */
350       for(i=0; (i<nlines); i++)
351         sfree(lines[i]);
352       sfree(lines);
353       NoHelp(dlg);
354       return;
355     }
356     else {
357       bCont=(strcasecmp(buf,"ok") != 0);
358       if (bCont) {
359         srenew(lines,++nlines);
360         lines[nlines-1]=strdup(buf);
361       }
362     }
363   } while (bCont);
364   MessageBox(dlg->x11,dlg->wDad,"Help",
365              nlines,lines,MB_OK | MB_ICONINFORMATION | MB_APPLMODAL,NULL,NULL);
366   for(i=0; (i<nlines); i++)
367     sfree(lines[i]);
368   sfree(lines);
369 }
370
371 static void EnterDlg(t_dlg *dlg)
372 {
373   if (dlg->flags & DLG_APPLMODAL)
374     dlg->bGrab=GrabOK(dlg->x11->console,
375                       XGrabPointer(dlg->x11->disp,dlg->win.self,
376                                    True,0,GrabModeAsync,GrabModeAsync,
377                                    dlg->win.self,None,CurrentTime));
378   dlg->x11->Flush(dlg->x11);
379 }
380
381 static void ExitDlg(t_dlg *dlg)
382 {
383   if (dlg->bGrab) {
384     XUngrabPointer(dlg->x11->disp,CurrentTime);
385     dlg->bGrab=FALSE;
386   }
387   HideDlg(dlg);
388   if (dlg->flags & DLG_FREEONBUTTON)
389     FreeDlg(dlg);
390 }
391
392 static bool DlgCB(t_x11 *x11,XEvent *event, Window w, void *data)
393 {
394   t_dlg     *dlg=(t_dlg *)data;
395   int       i,nWndProc;
396   t_dlgitem *dlgitem;
397   
398   if ((dlgitem=FindWin(dlg,w))!=NULL) {
399     nWndProc=(dlgitem->WndProc)(x11,dlgitem,event);
400 #ifdef DEBUG
401     fprintf(x11->console,
402             "window: %s, nWndProc: %d\n",dlgitem->win.text,nWndProc);
403     x11->Flush(x11);
404 #endif
405     switch (nWndProc) {
406     case ENTERPRESSED:
407       if ((dlgitem->type==edlgBN) && (dlgitem->u.button.bDefault)) {
408         if (dlg->cb)
409           dlg->cb(x11,DLG_EXIT,dlgitem->ID,dlgitem->win.text,dlg->data);
410         else
411           ExitDlg(dlg);
412       }
413       else {
414         for(i=0; (i<dlg->nitem); i++)
415           if ((dlg->dlgitem[i]->type==edlgBN) && 
416               (dlg->dlgitem[i]->u.button.bDefault)) {
417             PushMouse(x11->disp,dlg->dlgitem[i]->win.self,
418                       dlg->dlgitem[i]->win.width/2,
419                       dlg->dlgitem[i]->win.height/2);
420             break;
421           }
422       }
423       break;
424     case BNPRESSED:
425       if (dlg->cb)
426         dlg->cb(x11,DLG_EXIT,dlgitem->ID,dlgitem->win.text,dlg->data);
427       else 
428         ExitDlg(dlg);
429       break;
430     case RBPRESSED: {
431       int  gid=dlgitem->GroupID;
432       t_id tid=RBSelected(dlg,gid);
433 #ifdef DEBUG
434       fprintf(stderr,"RBPRESSED\n");
435 #endif
436       if (tid != -1) {
437         t_dlgitem *dit=FindItem(dlg,tid);
438         dit->u.radiobutton.bSelect=FALSE;
439         ExposeWin(x11->disp,dit->win.self);
440       }
441       else
442         fatal_error(0,"No RB Selected initially!\n");
443       dlgitem->u.radiobutton.bSelect=TRUE;
444       ExposeWin(x11->disp,dlgitem->win.self);
445       if (dlg->cb)
446         dlg->cb(x11,DLG_SET,dlgitem->ID,dlgitem->win.text,dlg->data);
447       break;
448     }
449     case CBPRESSED:
450       ExposeWin(x11->disp,dlgitem->win.self);
451       if (dlg->cb)
452         dlg->cb(x11,DLG_SET,dlgitem->ID,dlgitem->set,dlg->data);
453       break;
454     case ETCHANGED:
455       ExposeWin(x11->disp,dlgitem->win.self);
456       if (dlg->cb)
457         dlg->cb(x11,DLG_SET,dlgitem->ID,dlgitem->u.edittext.buf,dlg->data);
458       break;
459     case HELPPRESSED:
460       HelpNow(dlg,dlgitem);
461       break;
462     case ITEMOK:
463       break;
464     default:
465       fatal_error(0,"Invalid return code (%d) from wndproc\n",nWndProc);
466     }
467   }
468   else if (w==dlg->win.self) {
469     switch(event->type) {
470     case Expose:
471       EnterDlg(dlg);
472       break;
473     case ButtonPress:
474     case KeyPress:
475       if (HelpPressed(event))
476         HelpDlg(dlg);
477       else
478         XBell(x11->disp,50);
479       break;
480     default:
481       break;
482     }
483   }
484   return FALSE;
485 }
486
487 /*****************************
488  *
489  * Routine to add an item to the dialog box
490  * The pointer to the item is copied to the dlg struct,
491  * the item itself may not be freed until the dlg is done with
492  *
493  ****************************/
494 void DoCreateDlg(t_dlg *dlg)
495 {
496   XSizeHints           hints;
497   XSetWindowAttributes attr;
498   unsigned long Val;
499
500   attr.border_pixel=dlg->x11->fg;
501   attr.background_pixel=dlg->bg;
502   attr.override_redirect=False;
503   attr.save_under=True;
504   attr.cursor=XCreateFontCursor(dlg->x11->disp,XC_hand2);
505   Val=CWBackPixel | CWBorderPixel | CWOverrideRedirect | CWSaveUnder |
506     CWCursor;
507   dlg->win.self=XCreateWindow(dlg->x11->disp,dlg->wDad,
508                               dlg->win.x,dlg->win.y,
509                               dlg->win.width,dlg->win.height,
510                               dlg->win.bwidth,CopyFromParent,
511                               InputOutput,CopyFromParent,
512                               Val,&attr);
513   dlg->x11->RegisterCallback(dlg->x11,dlg->win.self,dlg->wDad,
514                              DlgCB,dlg);
515   dlg->x11->SetInputMask(dlg->x11,dlg->win.self, 
516                          ExposureMask | ButtonPressMask | KeyPressMask);
517
518   if (!CheckWindow(dlg->win.self))
519     exit(1);
520   hints.x=dlg->win.x;
521   hints.y=dlg->win.y;
522   hints.flags=PPosition;
523   XSetStandardProperties(dlg->x11->disp,dlg->win.self,dlg->title,
524                          dlg->title,None,NULL,0,&hints);
525 }
526
527 void AddDlgItem(t_dlg *dlg, t_dlgitem *new)
528 {
529 #define EnterLeaveMask (EnterWindowMask | LeaveWindowMask)
530 #define UserMask (ButtonPressMask | KeyPressMask)
531   static unsigned long InputMask[edlgNR] = {
532     ExposureMask | UserMask | EnterLeaveMask, /* edlgBN */ 
533     ExposureMask | UserMask | EnterLeaveMask, /* edlgRB */ 
534     ExposureMask,                             /* edlgGB */
535     ExposureMask | UserMask | EnterLeaveMask, /* edlgCB */ 
536     0,                                        /* edlgPM */ 
537     ExposureMask,                             /* edlgST */ 
538     ExposureMask | UserMask | EnterLeaveMask  /* edlgET */ 
539   };
540   
541   if (!dlg->win.self)
542     DoCreateDlg(dlg);
543   srenew(dlg->dlgitem,dlg->nitem+1);
544   assert(new);
545   new->win.self=
546     XCreateSimpleWindow(dlg->x11->disp,dlg->win.self,new->win.x,new->win.y,
547                         new->win.width,new->win.height,
548                         new->win.bwidth,dlg->x11->fg,dlg->x11->bg);
549   CheckWindow(new->win.self);
550
551   dlg->x11->RegisterCallback(dlg->x11,new->win.self,dlg->win.self,
552                              DlgCB,dlg);  
553   dlg->x11->SetInputMask(dlg->x11,new->win.self,InputMask[new->type]);
554
555   switch (new->type) {
556   case edlgPM:
557     XSetWindowBackgroundPixmap(dlg->x11->disp,new->win.self,new->u.pixmap.pm);
558     break;
559   default:
560     break;
561   }
562   dlg->dlgitem[dlg->nitem]=new;
563
564   dlg->nitem++;
565 }
566
567 void AddDlgItems(t_dlg *dlg,int nitem,t_dlgitem *new[])
568 {
569   int i;
570   
571   for(i=0; (i<nitem); i++) {
572 #ifdef DEBUG
573     fprintf(dlg->x11->console,
574             "Adding item: %d from group %d\n",new[i]->ID,new[i]->GroupID);
575     dlg->x11->Flush(dlg->x11);
576 #endif
577     AddDlgItem(dlg,new[i]);
578   }
579 }
580
581 void FreeDlgItem(t_dlg *dlg, t_id id)
582 {
583   t_dlgitem *dlgitem;
584   int i;
585
586   if ((dlgitem=FindItem(dlg,id)) != NULL) {
587     dlg->x11->UnRegisterCallback(dlg->x11,dlgitem->win.self);
588     if (dlgitem->win.self)
589       XDestroyWindow(dlg->x11->disp,dlgitem->win.self);
590     FreeWin(dlg->x11->disp,&(dlgitem->win));
591     switch(dlgitem->type) {
592     case edlgBN:
593     case edlgRB: 
594       break;
595     case edlgGB:
596       sfree(dlgitem->u.groupbox.item);
597       break;
598     case edlgCB:
599       break;
600     case edlgPM:
601       XFreePixmap(dlg->x11->disp,dlgitem->u.pixmap.pm);
602       break;
603     case edlgST:
604       for (i=0; (i<dlgitem->u.statictext.nlines); i++)
605         sfree(dlgitem->u.statictext.lines[i]);
606       sfree(dlgitem->u.statictext.lines);
607       break;
608     case edlgET:
609       sfree(dlgitem->u.edittext.buf);
610       break;
611     default:
612       break;
613     }
614   }
615 }
616
617 void FreeDlg(t_dlg *dlg)
618 {
619   int i;
620
621   if (dlg->dlgitem) {
622     HideDlg(dlg);
623     dlg->x11->UnRegisterCallback(dlg->x11,dlg->win.self);
624     for(i=0; (i<dlg->nitem); i++) {
625       FreeDlgItem(dlg,dlg->dlgitem[i]->ID);
626       if (dlg->dlgitem[i])
627         sfree(dlg->dlgitem[i]);
628     }
629     sfree(dlg->dlgitem);
630     if (dlg->win.self)
631       XDestroyWindow(dlg->x11->disp,dlg->win.self);
632     dlg->dlgitem=NULL;
633   }
634 }
635
636 /*****************************
637  *
638  * Routine to create the DLG structure, returns NULL on failure
639  *
640  ****************************/
641 t_dlg *CreateDlg(t_x11 *x11, Window Parent, char *title,
642                  int x0,int y0,int w,int h,int bw, unsigned long fg, unsigned long bg,
643                  DlgCallback *cb,void *data)
644 {
645   t_dlg   *dlg;
646   int     x=0,y=0;
647   
648   snew(dlg,1);
649   dlg->x11=x11;
650   dlg->cb=cb;
651   dlg->data=data;
652   if (title)
653     dlg->title=strdup(title);
654   else
655     dlg->title=NULL;
656   if (w==0) w=1;
657   if (h==0) h=1;
658   if (!Parent) {
659     Parent=x11->root;
660     dlg->xmax=DisplayWidth(x11->disp,x11->screen);
661     dlg->ymax=DisplayHeight(x11->disp,x11->screen);
662   }
663   else {
664     Window root;
665     unsigned int   dum;
666
667     XGetGeometry(x11->disp,Parent,&root,&x,&y,
668                  &(dlg->xmax),&(dlg->ymax),&dum,&dum);
669 #ifdef DEBUG
670     fprintf(x11->console,
671             "Daddy is %d x %d at %d, %d\n",dlg->xmax,dlg->ymax,x,y);
672     dlg->x11->Flush(dlg->x11);
673 #endif
674   }
675   if (x0) x=x0;
676   if (y0) y=y0;
677   InitWin(&(dlg->win),x,y,w,h,bw,NULL);
678   SetDlgSize(dlg,w,h,x0 || y0);
679
680   dlg->wDad=Parent;
681   dlg->fg=x11->fg;
682   dlg->bg=x11->bg;
683   dlg->nitem=0;
684   dlg->dlgitem=NULL;
685
686   DoCreateDlg(dlg);
687   return dlg;
688 }
689
690 void SetDlgSize(t_dlg *dlg,int w,int h, bool bAutoPosition)
691 {
692   if (bAutoPosition) {
693     int x,y;
694     
695     x=(dlg->xmax-w)/2;
696     y=(dlg->ymax-h)/2;
697     dlg->win.x=x;
698     dlg->win.y=y;
699   }
700   dlg->win.width=w;
701   dlg->win.height=h;
702   
703 #ifdef DEBUG
704   fprintf(dlg->x11->console,"SetDlgSize: Dialog is %dx%d, at %d,%d\n",
705           dlg->win.width,dlg->win.height,dlg->win.x,dlg->win.y);
706   dlg->x11->Flush(dlg->x11);
707 #endif
708   if (dlg->win.self) {
709     XMoveWindow(dlg->x11->disp,dlg->win.self,dlg->win.x,dlg->win.y);
710     XResizeWindow(dlg->x11->disp,dlg->win.self,w,h);
711   }
712 }
713