SYCL: Avoid using no_init read accessor in rocFFT
[alexxy/gromacs.git] / src / programs / view / xdlgitem.cpp
1 /*
2  * This file is part of the GROMACS molecular simulation package.
3  *
4  * Copyright (c) 1991-2000, University of Groningen, The Netherlands.
5  * Copyright (c) 2001-2013, The GROMACS development team.
6  * Copyright (c) 2013,2014,2015,2017,2019,2020, by the GROMACS development team, led by
7  * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
8  * and including many others, as listed in the AUTHORS file in the
9  * top-level source directory and at http://www.gromacs.org.
10  *
11  * GROMACS is free software; you can redistribute it and/or
12  * modify it under the terms of the GNU Lesser General Public License
13  * as published by the Free Software Foundation; either version 2.1
14  * of the License, or (at your option) any later version.
15  *
16  * GROMACS is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
19  * Lesser General Public License for more details.
20  *
21  * You should have received a copy of the GNU Lesser General Public
22  * License along with GROMACS; if not, see
23  * http://www.gnu.org/licenses, or write to the Free Software Foundation,
24  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA.
25  *
26  * If you want to redistribute modifications to GROMACS, please
27  * consider that scientific software is very special. Version
28  * control is crucial - bugs must be traceable. We will be happy to
29  * consider code for inclusion in the official distribution, but
30  * derived work must not be called official GROMACS. Details are found
31  * in the README & COPYING files - if they are missing, get the
32  * official version at http://www.gromacs.org.
33  *
34  * To help us fund GROMACS development, we humbly ask that you cite
35  * the research papers on the package. Check out http://www.gromacs.org.
36  */
37 #include "gmxpre.h"
38
39 #include "xdlgitem.h"
40
41 #include <cctype>
42 #include <cstdio>
43 #include <cstring>
44
45 #include <algorithm>
46
47 #include "gromacs/utility/cstringutil.h"
48 #include "gromacs/utility/fatalerror.h"
49 #include "gromacs/utility/smalloc.h"
50
51 #include "Xstuff.h"
52
53 #define BUFSIZE 16
54
55 static t_dlgitem* newitem(void)
56 {
57     t_dlgitem* item;
58
59     snew(item, 1);
60
61     return item;
62 }
63
64 /*****************************
65  *
66  * Window Procedures and helpful functions
67  *
68  ****************************/
69 static void ShowCaret(t_x11* x11, t_dlgitem* dlgitem)
70 {
71     t_edittext* et;
72
73     if (dlgitem->type == edlgET)
74     {
75         int x, y1, y2;
76
77         et = &(dlgitem->u.edittext);
78         x  = XTextWidth(x11->font, dlgitem->win.text, std::strlen(dlgitem->win.text)) + XCARET
79             + XTextWidth(x11->font, (char*)&(et->buf[et->strbegin]), et->pos);
80         y1 = (dlgitem->win.height - XTextHeight(x11->font)) / 2;
81         y2 = (dlgitem->win.height - y1);
82         y1--, y2++;
83         XDrawLine(x11->disp, dlgitem->win.self, x11->gc, x - XCARET, y1, x + XCARET, y1);
84         XDrawLine(x11->disp, dlgitem->win.self, x11->gc, x, y1, x, y2);
85         XDrawLine(x11->disp, dlgitem->win.self, x11->gc, x - XCARET, y2, x + XCARET, y2);
86     }
87 }
88
89 static void HideCaret(t_x11* x11, t_dlgitem* dlgitem)
90 {
91     XSetForeground(x11->disp, x11->gc, x11->bg);
92     ShowCaret(x11, dlgitem);
93     XSetForeground(x11->disp, x11->gc, x11->fg);
94 }
95
96 static int DefWndProc(t_x11* x11, t_dlgitem* dlgitem, XEvent* event)
97 {
98     XComposeStatus status;
99     KeySym         keysym;
100     char           c[BUFSIZE + 1];
101
102 #ifdef DEBUG
103     std::printf("DefWndProc\n");
104 #endif
105     switch (event->type)
106     {
107         case Expose:
108         case ButtonPress:
109         case KeyPress:
110             if (HelpPressed(event))
111             {
112                 return HELPPRESSED;
113             }
114             else
115             {
116                 XLookupString(&(event->xkey), c, BUFSIZE, &keysym, &status);
117                 if ((keysym == XK_Return) || (keysym == XK_KP_Enter))
118                 {
119                     return ENTERPRESSED;
120                 }
121             }
122             break;
123         case EnterNotify:
124             dlgitem->win.bFocus = true;
125             ShowCaret(x11, dlgitem);
126             /*    LightBorder(x11->disp,dlgitem->win.self,x11->fg); */
127             break;
128         case LeaveNotify:
129             dlgitem->win.bFocus = false;
130             HideCaret(x11, dlgitem);
131             /*    LightBorder(x11->disp,dlgitem->win.self,x11->bg); */
132             break;
133         default: XBell(x11->disp, 50);
134     }
135     return ITEMOK;
136 }
137
138 static int WndProcBN(t_x11* x11, t_dlgitem* dlgitem, XEvent* event)
139 {
140     t_windata* win;
141     int        x, w, th;
142
143     if (dlgitem->type != edlgBN)
144     {
145         gmx_incons("button processing");
146     }
147     win = &(dlgitem->win);
148     w   = XTextWidth(x11->font, win->text, std::strlen(win->text));
149     x   = (win->width - w) / 2;
150     th  = XTextHeight(x11->font) + OFFS_Y;
151     switch (event->type)
152     {
153         case Expose:
154             RectWin(x11->disp, x11->gc, win, x11->fg);
155             TextInRect(x11, win->self, win->text, 0, 0, win->width, th, eXCenter, eYCenter);
156             break;
157         case ButtonPress: return BNPRESSED;
158         case EnterNotify: XDrawLine(x11->disp, win->self, x11->gc, x - 1, th, x + w, th); break;
159         case LeaveNotify:
160             XSetForeground(x11->disp, x11->gc, x11->bg);
161             XDrawLine(x11->disp, win->self, x11->gc, x - 1, th, x + w, th);
162             XSetForeground(x11->disp, x11->gc, x11->fg);
163             break;
164         default: return DefWndProc(x11, dlgitem, event);
165     }
166     return ITEMOK;
167 }
168
169 static int WndProcRB(t_x11* x11, t_dlgitem* dlgitem, XEvent* event)
170 {
171     t_radiobutton* rb;
172     t_windata*     win;
173     int            x, y, rad;
174
175     if (dlgitem->type != edlgRB)
176     {
177         gmx_incons("radiobutton processing");
178     }
179     rb  = &(dlgitem->u.radiobutton);
180     win = &(dlgitem->win);
181
182     rad = win->height / 3;
183     x   = rad;
184     y   = win->height / 2;
185     switch (event->type)
186     {
187         case Expose:
188             XClearArea(x11->disp, win->self, x - rad, y - rad, x + rad, y + rad, False);
189             if (rb->bSelect)
190             {
191                 /* Filled */
192                 XFillCircle(x11->disp, win->self, x11->gc, x, y, rad);
193             }
194             XDrawCircle(x11->disp, win->self, x11->gc, x, y, rad);
195             x += rad + OFFS_X;
196             TextInRect(x11, win->self, win->text, x, 0, win->width - x, win->height, eXLeft, eYCenter);
197             break;
198         case ButtonPress:
199             if (!rb->bSelect)
200             {
201                 return RBPRESSED;
202             }
203             XBell(x11->disp, 50);
204             break;
205         case EnterNotify:
206         case LeaveNotify: break;
207         default: return DefWndProc(x11, dlgitem, event);
208     }
209     return ITEMOK;
210 }
211
212 static int WndProcGB(t_x11* x11, t_dlgitem* dlgitem, XEvent* event)
213 {
214     t_windata* win;
215     int        x, y;
216
217     if (dlgitem->type != edlgGB)
218     {
219         gmx_incons("gb processing");
220     }
221     win = &(dlgitem->win);
222
223     x = XTextWidth(x11->font, win->text, std::strlen(win->text));
224     y = XTextHeight(x11->font);
225     switch (event->type)
226     {
227         case Expose:
228             XSetForeground(x11->disp, x11->gc, x11->fg);
229             XDrawRoundRect(
230                     x11->disp, win->self, x11->gc, 0, y / 2, win->width - 1, win->height - y / 2 - 1);
231             XClearArea(x11->disp, win->self, OFFS_X, 0, x + OFFS_X, y, False);
232             TextInRect(x11, win->self, win->text, 2 * OFFS_X, 0, x, y, eXCenter, eYCenter);
233             break;
234         case EnterNotify:
235         case LeaveNotify: break;
236         default: return DefWndProc(x11, dlgitem, event);
237     }
238     return ITEMOK;
239 }
240
241 static int WndProcCB(t_x11* x11, t_dlgitem* dlgitem, XEvent* event)
242 {
243     t_checkbox* cb;
244     t_windata*  win;
245     int         x, y, w, h;
246
247     if (dlgitem->type != edlgCB)
248     {
249         gmx_incons("check box processing");
250     }
251     cb  = &(dlgitem->u.checkbox);
252     win = &(dlgitem->win);
253
254     x = 0;
255     y = win->height / 7;
256     w = 5 * y;
257     h = 5 * y;
258     switch (event->type)
259     {
260         case Expose:
261             XSetForeground(x11->disp, x11->gc, x11->fg);
262             XClearArea(x11->disp, win->self, x, y, w, h, False);
263             XDrawRectangle(x11->disp, win->self, x11->gc, x, y, w, h);
264             if (cb->bChecked)
265             {
266                 XDrawLine(x11->disp, win->self, x11->gc, x, y, x + w, y + h);
267                 XDrawLine(x11->disp, win->self, x11->gc, x + w, y, x, y + h);
268             }
269             x = w + OFFS_X;
270             TextInRect(x11, win->self, win->text, x, 0, win->width - x, win->height, eXLeft, eYCenter);
271             break;
272         case ButtonPress: cb->bChecked = !cb->bChecked; return CBPRESSED;
273         case EnterNotify:
274         case LeaveNotify: break;
275         default: return DefWndProc(x11, dlgitem, event);
276     }
277     return ITEMOK;
278 }
279
280 static int WndProcST(t_x11* x11, t_dlgitem* dlgitem, XEvent* event)
281 {
282     t_statictext* st;
283     t_windata*    win;
284     int           i, dy;
285
286     if (dlgitem->type != edlgST)
287     {
288         gmx_incons("st processing");
289     }
290     st  = &(dlgitem->u.statictext);
291     win = &(dlgitem->win);
292
293     switch (event->type)
294     {
295         case Expose:
296             dy = XTextHeight(x11->font) + OFFS_Y;
297             for (i = 0; (i < st->nlines); i++)
298             {
299                 TextInRect(x11, win->self, st->lines[i], 0, OFFS_Y + i * dy, win->width, dy, eXLeft, eYCenter);
300             }
301             break;
302         default: return DefWndProc(x11, dlgitem, event);
303     }
304     return ITEMOK;
305 }
306
307 static bool insert(char* s, char c, int* pos)
308 {
309     int i, sl;
310
311     if (isprint(c))
312     {
313         sl = std::strlen(s);
314         /* +1 for zero termination */
315         for (i = sl + 1; (i > *pos); i--)
316         {
317             s[i + 1] = s[i];
318         }
319         s[*pos] = c;
320         (*pos)++;
321         return true;
322     }
323     return false;
324 }
325
326 static bool my_backspace(char* s, int* pos)
327 {
328     int i, sl;
329
330     sl = std::strlen(s);
331     if ((sl > 0) && ((*pos) > 0))
332     {
333         for (i = *pos - 1; (i < sl); i++)
334         {
335             s[i] = s[i + 1];
336         }
337         (*pos) = std::max(0, (*pos) - 1);
338         return true;
339     }
340     return false;
341 }
342
343 static bool my_delete(char* s, int* pos)
344 {
345     int i, sl;
346
347     sl = std::strlen(s);
348     if ((sl > 0) && ((*pos) < sl))
349     {
350         for (i = *pos; (i < sl); i++)
351         {
352             s[i] = s[i + 1];
353         }
354         return true;
355     }
356     return false;
357 }
358
359 static int WndProcET(t_x11* x11, t_dlgitem* dlgitem, XEvent* event)
360 {
361     t_edittext* et;
362     t_windata*  win;
363     KeySym      keysym;
364     char        c[BUFSIZE + 1], *bp;
365     char        scrbuf[STRLEN];
366     int         i;
367     int         xp, xtitle, ewidth;
368
369     if (dlgitem->type != edlgET)
370     {
371         gmx_incons("st processing");
372     }
373     et  = &(dlgitem->u.edittext);
374     win = &(dlgitem->win);
375
376     /* Copy string part that is visible into screen buffer */
377     for (i = 0; (i < et->buflen); i++)
378     {
379         scrbuf[i] = et->buf[i + et->strbegin];
380     }
381     scrbuf[i] = '\0';
382
383     switch (event->type)
384     {
385         case Expose:
386             XSetForeground(x11->disp, x11->gc, x11->fg);
387             xtitle = XTextWidth(x11->font, win->text, std::strlen(win->text));
388             ewidth = win->width - xtitle;
389             TextInRect(x11, win->self, win->text, 0, 0, xtitle - 1, win->height, eXLeft, eYCenter);
390             XClearArea(x11->disp, win->self, xtitle, 0, ewidth + XCARET, win->height, False);
391             TextInRect(x11, win->self, scrbuf, xtitle + XCARET, 0, ewidth, win->height, eXLeft, eYCenter);
392 #ifdef DEBUG
393             std::printf("Expose\n");
394 #endif
395             if (win->bFocus)
396             {
397                 ShowCaret(x11, dlgitem);
398             }
399             break;
400         case ButtonPress:
401             /* Calculate new position for caret */
402             et->pos = std::strlen(et->buf);
403             bp      = gmx_strdup(et->buf);
404             xp = event->xbutton.x - XTextWidth(x11->font, win->text, std::strlen(win->text)) - XCARET;
405             while ((et->pos > 0) && (XTextWidth(x11->font, bp, std::strlen(bp)) > xp))
406             {
407                 et->pos--;
408                 bp[et->pos] = '\0';
409             }
410             sfree(bp);
411             et->bChanged = true;
412             return ETCHANGED;
413         case KeyPress:
414             /* Check for HelpKey */
415             if (HelpPressed(event))
416             {
417                 return DefWndProc(x11, dlgitem, event);
418             }
419             XLookupString(&(event->xkey), c, BUFSIZE, &keysym, nullptr);
420 #ifdef DEBUG
421             std::printf("Keysym: %x\n", keysym);
422 #endif
423             switch (keysym)
424             {
425                 case XK_Delete:
426                     if (my_delete(et->buf, &(et->pos)))
427                     {
428                         et->bChanged = true;
429                         return ETCHANGED;
430                     }
431                     else
432                     {
433                         XBell(x11->disp, 50);
434                     }
435                     break;
436                 case XK_BackSpace:
437                     if (my_backspace(et->buf, &(et->pos)))
438                     {
439                         et->bChanged = true;
440                         return ETCHANGED;
441                     }
442                     else
443                     {
444                         XBell(x11->disp, 50);
445                     }
446                     break;
447                 case XK_KP_Enter:
448                 case XK_Return: return ENTERPRESSED;
449                 case XK_Home:
450                     et->pos      = 0;
451                     et->strbegin = 0;
452                     et->bChanged = true;
453                     return ETCHANGED;
454                 case XK_End:
455                     if (strlen(et->buf) <= (unsigned int)et->buflen)
456                     {
457                         et->pos = std::strlen(et->buf);
458                     }
459                     else
460                     {
461                         et->pos      = et->buflen;
462                         et->strbegin = std::strlen(et->buf) - et->buflen;
463                     }
464                     et->bChanged = true;
465                     return ETCHANGED;
466                 case XK_Left:
467                     et->pos      = std::max(0, et->pos - 1);
468                     et->strbegin = std::min(et->strbegin, et->pos);
469                     et->bChanged = true;
470                     return ETCHANGED;
471                 case XK_Right:
472                     if ((et->pos < et->buflen) && (et->strbegin + et->buflen > (int)strlen(et->buf)))
473                     {
474                         et->pos++;
475                     }
476                     else if ((et->buflen < (int)strlen(et->buf))
477                              && (et->strbegin < (int)strlen(et->buf) - et->buflen))
478                     {
479                         et->strbegin++;
480                     }
481                     else
482                     {
483                         break;
484                     }
485                     et->bChanged = true;
486                     return ETCHANGED;
487                 default:
488                     if (keysym < 256)
489                     {
490                         if (insert(et->buf, c[0], &(et->pos)))
491                         {
492                             et->bChanged = true;
493                             return ETCHANGED;
494                         }
495                     }
496                     XBell(x11->disp, 50);
497                     break;
498             }
499             break;
500         case LeaveNotify:
501             win->bFocus = false;
502             HideCaret(x11, dlgitem);
503             if (et->bChanged)
504             {
505                 et->bChanged = false;
506             }
507             break;
508         default: return DefWndProc(x11, dlgitem, event);
509     }
510     return ITEMOK;
511 }
512
513 /*****************************
514  *
515  * Routines to create dialog items, all items have an id
516  * which you can use to extract info. It is possible to have
517  * multiple items with the same id but it may then not be possible
518  * to extract information.
519  * All routines take the position relative to the parent dlg
520  * and the size and border width.
521  * If the width and height are set to zero initially, they will
522  * be calculated and set by the routine. With the dlgitem manipulation
523  * routines listed below, the application can then move the items around
524  * on the dlg box, and if wished resize them.
525  *
526  ****************************/
527 t_dlgitem*
528 CreateButton(t_x11* x11, const char* szLab, bool bDef, t_id id, t_id groupid, int x0, int y0, int w, int h, int bw)
529 {
530     t_dlgitem* dlgitem;
531     char*      lab;
532
533     dlgitem = newitem();
534     if (h == 0)
535     {
536         h = XTextHeight(x11->font) + 2 * OFFS_Y;
537     }
538     if (w == 0)
539     {
540         w = XTextWidth(x11->font, szLab, std::strlen(szLab)) + 2 * OFFS_X;
541     }
542     if (bDef)
543     {
544         snew(lab, std::strlen(szLab) + 7); /* 6 for >> << and 1 for \0 */
545         std::sprintf(lab, ">> %s <<", szLab);
546     }
547     else
548     {
549         lab = gmx_strdup(szLab);
550     }
551     InitWin(&(dlgitem->win), x0, y0, w, h, bw, szLab);
552     sfree(lab);
553     dlgitem->ID                = id;
554     dlgitem->GroupID           = groupid;
555     dlgitem->type              = edlgBN;
556     dlgitem->u.button.bDefault = bDef;
557     dlgitem->WndProc           = WndProcBN;
558
559     return dlgitem;
560 }
561
562 t_dlgitem*
563 CreateRadioButton(t_x11* x11, const char* szLab, bool bSet, t_id id, t_id groupid, int x0, int y0, int w, int h, int bw)
564 {
565     t_dlgitem* dlgitem;
566
567     dlgitem = newitem();
568     if (h == 0)
569     {
570         h = XTextHeight(x11->font) + OFFS_Y;
571     }
572     if (w == 0)
573     {
574         w = XTextWidth(x11->font, szLab, std::strlen(szLab)) + OFFS_X + h;
575     }
576     InitWin(&(dlgitem->win), x0, y0, w, h, bw, szLab);
577     dlgitem->ID                    = id;
578     dlgitem->GroupID               = groupid;
579     dlgitem->type                  = edlgRB;
580     dlgitem->u.radiobutton.bSelect = bSet;
581     dlgitem->WndProc               = WndProcRB;
582
583     return dlgitem;
584 }
585
586 t_dlgitem*
587 CreateGroupBox(t_x11* x11, const char* szLab, t_id id, int nitems, t_id items[], int x0, int y0, int w, int h, int bw)
588 {
589     t_dlgitem* dlgitem;
590
591     dlgitem = newitem();
592     if (h == 0)
593     {
594         h = XTextHeight(x11->font) + OFFS_Y;
595     }
596     if (w == 0)
597     {
598         w = XTextWidth(x11->font, szLab, std::strlen(szLab)) + 2 * OFFS_X;
599     }
600     InitWin(&(dlgitem->win), x0, y0, w, h, bw, szLab);
601     dlgitem->GroupID           = id;
602     dlgitem->ID                = id;
603     dlgitem->type              = edlgGB;
604     dlgitem->u.groupbox.nitems = nitems;
605     snew(dlgitem->u.groupbox.item, nitems);
606     std::memcpy((char*)dlgitem->u.groupbox.item, (char*)items, nitems * sizeof(items[0]));
607     dlgitem->WndProc = WndProcGB;
608
609     return dlgitem;
610 }
611
612 t_dlgitem* CreateCheckBox(t_x11*      x11,
613                           const char* szLab,
614                           bool        bCheckedInitial,
615                           t_id        id,
616                           t_id        groupid,
617                           int         x0,
618                           int         y0,
619                           int         w,
620                           int         h,
621                           int         bw)
622 {
623     t_dlgitem* dlgitem;
624
625     dlgitem = newitem();
626     if (h == 0)
627     {
628         h = XTextHeight(x11->font) + OFFS_Y;
629     }
630     if (w == 0)
631     {
632         w = XTextWidth(x11->font, szLab, std::strlen(szLab)) + OFFS_X + h;
633     }
634     InitWin(&(dlgitem->win), x0, y0, w, h, bw, szLab);
635     dlgitem->ID                  = id;
636     dlgitem->GroupID             = groupid;
637     dlgitem->type                = edlgCB;
638     dlgitem->u.checkbox.bChecked = bCheckedInitial;
639     dlgitem->WndProc             = WndProcCB;
640
641     return dlgitem;
642 }
643
644 t_dlgitem* CreatePixmap(Pixmap pm, t_id id, t_id /*groupid*/, int x0, int y0, int w, int h, int bw)
645 {
646     t_dlgitem* dlgitem;
647
648     dlgitem = newitem();
649     InitWin(&(dlgitem->win), x0, y0, w, h, bw, nullptr);
650     dlgitem->ID          = id;
651     dlgitem->type        = edlgPM;
652     dlgitem->u.pixmap.pm = pm;
653     dlgitem->WndProc     = DefWndProc;
654
655     return dlgitem;
656 }
657
658 t_dlgitem* CreateStaticText(t_x11*             x11,
659                             int                nlines,
660                             const char* const* lines,
661                             t_id               id,
662                             t_id               groupid,
663                             int                x0,
664                             int                y0,
665                             int                w,
666                             int                h,
667                             int                bw)
668 {
669     t_dlgitem* dlgitem;
670     int        i;
671
672     dlgitem = newitem();
673     if (h == 0)
674     {
675         h = (XTextHeight(x11->font) + OFFS_Y) * nlines + OFFS_Y;
676     }
677     if (w == 0)
678     {
679         for (i = 0; (i < nlines); i++)
680         {
681             w = std::max(w, XTextWidth(x11->font, lines[i], std::strlen(lines[i])));
682         }
683         w += 2 * OFFS_X;
684     }
685     InitWin(&(dlgitem->win), x0, y0, w, h, bw, nullptr);
686     dlgitem->ID                  = id;
687     dlgitem->GroupID             = groupid;
688     dlgitem->type                = edlgST;
689     dlgitem->u.statictext.nlines = nlines;
690     snew(dlgitem->u.statictext.lines, nlines);
691     for (i = 0; (i < nlines); i++)
692     {
693         dlgitem->u.statictext.lines[i] = gmx_strdup(lines[i]);
694     }
695     dlgitem->WndProc = WndProcST;
696
697     return dlgitem;
698 }
699
700 t_dlgitem* CreateEditText(t_x11*      x11,
701                           const char* title,
702                           int         screenbuf,
703                           char*       buf,
704                           t_id        id,
705                           t_id        groupid,
706                           int         x0,
707                           int         y0,
708                           int         w,
709                           int         h,
710                           int         bw)
711 {
712     t_dlgitem*  dlgitem;
713     t_edittext* et;
714
715     dlgitem = newitem();
716     if (h == 0)
717     {
718         h = XTextHeight(x11->font) + OFFS_Y;
719     }
720     if (w == 0)
721     {
722         char* test;
723
724         snew(test, screenbuf);
725         std::memset(test, 'w', screenbuf);
726         w = XTextWidth(x11->font, test, screenbuf)
727             + XTextWidth(x11->font, title, std::strlen(title)) + 2 * XCARET + 2 * OFFS_X;
728         sfree(test);
729     }
730     InitWin(&(dlgitem->win), x0, y0, w, h, bw, title);
731     dlgitem->ID      = id;
732     dlgitem->GroupID = groupid;
733     dlgitem->type    = edlgET;
734     et               = &(dlgitem->u.edittext);
735     snew(et->buf, STRLEN);
736     std::strcpy(et->buf, buf);
737     et->buflen       = screenbuf;
738     et->strbegin     = 0;
739     et->bChanged     = false;
740     dlgitem->WndProc = WndProcET;
741
742     return dlgitem;
743 }
744
745 #define SC(src) (strlen(src) ? gmx_strdup(src) : NULL)
746
747 void SetDlgitemOpts(t_dlgitem* dlgitem, bool bUseMon, char* set, char* get, char* help)
748 {
749     dlgitem->bUseMon = bUseMon;
750     dlgitem->set     = SC(set);
751     dlgitem->get     = SC(get);
752     dlgitem->help    = SC(help);
753 #ifdef DEBUG
754     std::printf("Help is: '%s'\n", dlgitem->help);
755 #endif
756 }