Convert uses of XKeycodeToKeysym (deprecated) to XkbKeycodeToKeysym
[oweals/cde.git] / cde / programs / dtudcexch / selectxlfd.c
1 /*
2  * CDE - Common Desktop Environment
3  *
4  * Copyright (c) 1993-2012, The Open Group. All rights reserved.
5  *
6  * These libraries and programs are free software; you can
7  * redistribute them and/or modify them under the terms of the GNU
8  * Lesser General Public License as published by the Free Software
9  * Foundation; either version 2 of the License, or (at your option)
10  * any later version.
11  *
12  * These libraries and programs are distributed in the hope that
13  * they will be useful, but WITHOUT ANY WARRANTY; without even the
14  * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15  * PURPOSE. See the GNU Lesser General Public License for more
16  * details.
17  *
18  * You should have received a copy of the GNU Lesser General Public
19  * License along with these libraries and programs; if not, write
20  * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
21  * Floor, Boston, MA 02110-1301 USA
22  */
23 /* $XConsortium: selectxlfd.c /main/3 1996/10/14 14:45:17 barstow $ */
24 /*
25  *  All Rights Reserved, Copyright (c) FUJITSU LIMITED 1995
26  */
27
28
29 #include <string.h>
30 #include <stdio.h>
31 #include <stdlib.h>
32 #include <math.h>
33 #include <nl_types.h>
34 #include <sys/types.h>
35 #include <sys/stat.h>
36 #include <fcntl.h>
37
38 #include<X11/Xlib.h>
39 #include<X11/Xutil.h>
40 #include<X11/Xatom.h>
41
42 #include <Xm/Xm.h>
43 #include <Xm/Form.h>
44 #include <Xm/PushB.h>
45 #include <Xm/Text.h>
46 #include <Xm/TextF.h>
47 #include <Xm/Label.h>
48 #include <Xm/SeparatoG.h>
49 #include <Xm/List.h>
50 #include <Xm/ToggleB.h>
51 #include <Xm/MessageB.h>
52
53 #include "FaLib.h"
54 #include "falxlfd.h"
55 #include "selectxlfd.h"
56 #include "excutil.h"
57
58 char *shell_n[] = { "pop0", "pop1", "pop2", "pop3" } ;
59 char *list_n[]  = { "list0", "list1", "list2", "list3" } ;
60
61 #ifdef DEBUG
62 #undef Dprintf
63 #define Dprintf fprintf
64 #else
65 #define Dprintf
66 #endif /* DEBUG */
67
68 /*
69  * There is no public header file for this function (only an
70  * internal header XmStringI.h).
71  */
72 extern XtPointer _XmStringUngenerate (XmString string,
73                         XmStringTag tag,
74                         XmTextType tag_type,
75                         XmTextType output_type);
76
77 extern Rsrc resource;
78 extern Exc_data *ed;
79 extern ListData *ld;
80 extern fal_utyerror;
81 extern fal_utyderror;
82 extern fal_utyexists;
83 extern char *maintitle;
84
85 FalFontID       fid;
86
87
88 /*
89  * parameters
90  */
91
92 char    *fullPathName   = NULL ;
93
94 FalFontDataList         *font_L ;
95 FalxCodeList            *CodeList ;
96 FalxStyleList           *StyleList ;
97 FalxSizeList            *SizeList ;
98 FalxUdcArea             *UdcArea ;
99 int                     SelectedOffset ;
100 int                     UdcAreaCount ;
101 int                     getmask ;
102
103 FalxFontDataBuff        KeyBuff ;
104
105
106 void    PopupSelectXLFD() ;
107
108 Widget  xlfdDialog, xlfdWform,
109         slctBLabel[BUTTONITEMS],slctBText[BUTTONITEMS], slctButton[BUTTONITEMS],
110         listPop[BUTTONITEMS],   listW[BUTTONITEMS],
111         separatorW, errorMD, msgBox ;
112 extern  Widget  cpyDialog ;
113
114 extern Widget toplevel;
115
116
117 /*
118  * tmp
119  */
120
121 int fontcheck(char *fontfile, char *mode)
122 /*
123  * If fontfile can't be opend, return -1.
124  * If fontfile is editted by other UDC client, return 1.
125  * normary return 0.
126  */
127 {
128     int chk_fd;
129
130     if (strcmp(mode, "r") == 0) {
131         if ((chk_fd = open(fontfile, O_RDONLY)) < 0) {
132             return (-1);
133         }
134     } else if (strcmp(mode, "w") == 0) {
135         if ((chk_fd = open(fontfile, O_RDWR)) < 0) {
136             return (-1);
137         }
138     }
139     if (isLock(chk_fd) == 1) {
140         close(chk_fd);
141         return(1);
142     }
143     close(chk_fd);
144     return (0);
145 }
146
147 void setallcode(ListData *ld)
148 {
149     int         i, code, codenum;
150     int         *codep;
151     int         code1, code2;
152
153     codenum = 0;
154     for (i = 0; i < UdcAreaCount; i++) {
155         codenum += (abs(UdcArea[i].udc_end - UdcArea[i].udc_start) + 1);
156     }
157
158     ld->allcode = (int *) calloc(codenum, sizeof(int));
159     ld->allcode_num = codenum;
160     codep = ld->allcode;
161     for (i = 0; i < UdcAreaCount; i++) {
162         code1 = smaller(UdcArea[i].udc_start, UdcArea[i].udc_end);
163         code2 = bigger(UdcArea[i].udc_start, UdcArea[i].udc_end);
164         for (code = code1; code <= code2; code++) {
165             *codep = code;
166             codep++;
167         }
168     }
169 }
170
171 FalFontID openfont(void)
172 {
173     int         protect_key = FAL_FONT_DISPLAY;
174     int         codeset;
175     FalFontID   fontid;
176
177     fontid = NULL;
178     codeset = font_L->list[0].cd_set;
179     if ((fontid = FalOpenFont(fullPathName, protect_key, codeset))
180         == FAL_ERROR) {
181         fprintf(stderr, "FalOpenFont error\n");
182         return ((FalFontID) NULL);
183     }
184     return (fontid);
185 }
186
187 void makelist(ListData *ld)
188 {
189     char        *pattern;
190     int         code;
191     int         *existcodep, *allcodep;
192     int         existcode_num;
193     int         i;
194 /*    FalFontinfo fontinfo;*/
195
196 /*    FalQueryFont(fid, &fontinfo);*/
197
198     ld->existcode = (int *) calloc(ld->allcode_num, sizeof(int));
199     existcodep = ld->existcode ;
200     allcodep = ld->allcode;
201     existcode_num = 0;
202     for (i = 0; i < ld->allcode_num; i++) {
203         code = *allcodep;
204         pattern = FalReadFont(fid, code, NULL, NULL);
205         if (fal_utyexists == 0) {
206             *existcodep = *allcodep;
207             existcodep++;
208             existcode_num++;
209         }
210         allcodep++;
211     }
212     ld->existcode_num = existcode_num;
213 }
214
215 void setexistcode(ListData *ld)
216 {
217     int *codep, *allcodep;
218     int i;
219
220 /* open font */
221     fid = openfont();
222
223     makelist(ld);
224
225 /* close font */
226     if (fid != NULL)
227         FalCloseFont(fid);
228 }
229
230
231 char i2c(int num)
232 {
233     char c;
234
235     if ((0 <= num) && (num <= 9))
236         c = '0' + num;
237     else if ((10 <= num) && (num <= 15))
238         c = 'a' + (num - 10);
239     else
240         fprintf(stderr,"error in i2c\n");
241     return c;
242 }
243
244 char *i2s(int code)
245 {
246     char        buf[8];
247     char        *number;
248     char        *cp;
249     int         i;
250     int         tmp;
251     int         len;
252
253     tmp = code;
254     for (i = 0; ; i++) {
255         if (tmp < 16) {
256             buf[i] = i2c(tmp);
257             buf[i+1] = NULL;
258             break;
259         }
260         buf[i] = i2c(tmp % 16);
261         tmp = tmp / 16;
262     }
263     len = strlen(buf);
264     number = (char *) calloc(len+3, sizeof(char));
265     cp = number;
266     memcpy(cp, "0x", 2);
267     cp += 2;
268     for (i = len - 1; i >= 0; i--) {
269         *cp = buf[i];
270         cp++;
271     }
272     *cp = NULL;
273     return (number);
274 }
275
276 void setexistcode_c(ListData *ld)
277 {
278     int         i;
279     char        **code_cp;
280     int         *codep;
281
282     if (ld->existcode_num == 0) {
283         return;
284     }
285
286     ld->existcode_c = (char **) calloc(ld->existcode_num, sizeof(char *));
287     code_cp = ld->existcode_c;
288     codep = ld->existcode;
289     for (i = 0; i < ld->existcode_num; i++) {
290         *code_cp = i2s(*codep);
291         code_cp++;
292         codep++;
293     }
294 }
295
296 void getexistcode(ListData *ld)
297 {
298     setallcode(ld);
299     setexistcode(ld);
300     setexistcode_c(ld);
301 }
302
303
304
305 /****************************************************************
306  * common functions                                             *
307  ***************************************************************/
308
309 /*
310  * pop up and down dialog box
311  */
312
313 void
314 xlfdPopupDialog(Widget w)
315 {
316     if (! XtIsManaged(w))
317         XtManageChild(w);
318     else
319         XRaiseWindow(XtDisplayOfObject(w), XtWindow(XtParent(w)));
320 }
321
322 void
323 xlfdPopdownDialog(Widget w)
324 {
325     if (XtIsManaged(w)){
326         XtUnmanageChild(w);
327     }
328 }
329
330
331 /*
332 * get pixel width
333 */
334 Dimension
335 GetPixelWidth(Widget w, int columns, Dimension *width)
336 {
337         Arg             args[1] ;
338         XtSetArg( args[0], XmNwidth, width ) ;
339         XtGetValues( w , args, 1 ) ;
340         return( *width / (Dimension)columns ) ;
341 }
342
343
344 /****************************************************************
345  * callbacks                                                    *
346  ***************************************************************/
347
348 void quit(Widget w, caddr_t *client_data, caddr_t *call_data)
349 {
350     char        *msg;
351     int         ans;
352
353     msg = GETMESSAGE(6, 2, "Do you want to terminate udcexchange?");
354
355     AskUser(ed->toplevel, ed, msg, &ans, "question");
356     if (ans == 1) {/* terminate ok */
357         FalxFreeCodeList( CodeList ) ;
358         FalxFreeStyleList( StyleList ) ;
359         FalxFreeSizeList( SizeList ) ;
360         FalxFreeFontList( font_L ) ;
361         excterminate(ed);
362     }
363 }
364
365
366 /*
367  * Unmanage widgets
368  */
369 int
370 ClearText(int num, Widget *slctBText)
371 {
372         int     i ;
373         /* toggle button unset */
374         for( i=0; i<BUTTONITEMS; i++ ){
375             if( i>num ){
376                 XmTextSetString( slctBText[i], "" );
377             }
378         }
379         return ;
380 }
381
382 int
383 ClearButtons(int num, Widget *slctButton)
384 {
385         int     i, cnt ;
386         Boolean isSet ;
387         Arg     args[5] ;
388         /* toggle button unset */
389         for( i=0; i<BUTTONITEMS; i++ ){
390             if( i != num ){
391                 cnt = 0;
392                 XtSetArg( args[cnt], XmNset, &isSet );  cnt++;
393                 XtGetValues( slctButton[i], args, cnt );
394                 if( isSet == True ){
395                     cnt = 0;
396                     XtSetArg( args[cnt], XmNset, False );       cnt++;
397                     XtSetValues( slctButton[i], args, cnt );
398                 }
399             }
400         }
401         return ;
402 }
403
404
405
406 /*
407  * get text field position
408  */
409 int
410 GetPositionOfLists(
411 int     num,
412 Widget  xlfdDialog,
413 Widget  *listPop,
414 Widget  *slctBText,
415 Position        *x,
416 Position        *y)
417 {
418         int             i ;
419         Position        tbx, tby, tx, ty ;
420         Dimension       theight ;
421         Arg     args[10] ;
422
423         i = 0;
424         XtSetArg(args[i], XmNx, &tbx ); i++;
425         XtSetArg(args[i], XmNy, &tby ); i++;
426         XtGetValues( xlfdDialog, args, i);
427         i = 0;
428         XtSetArg(args[i], XmNx, &tx );  i++;
429         XtSetArg(args[i], XmNy, &ty );  i++;
430         XtSetArg(args[i], XmNheight, &theight );        i++;
431         if( num==BUTTONITEMS-1 )
432             XtGetValues( slctBText[num], args, i ) ;
433         else
434             XtGetValues( XtParent(slctBText[num]), args, i ) ;  /* ScrolledText */
435         /*  determine the position of list */
436         *x = tx + tbx + CX ;
437         if( num==BUTTONITEMS-1 ){
438         *y = ty + tby + (Position)theight + 14 + CY ;
439         }else{
440         *y = ty + tby + (Position)theight + CY ;
441         }
442
443         for( i=0; i<BUTTONITEMS; i++ ){
444             if( XtIsManaged( listPop[i] ) )     XtUnmanageChild( listPop[i] );
445         }
446         if( !XtIsManaged( listPop[num] ) )      XtManageChild( listPop[num] );
447
448         return ;
449 }
450
451
452
453
454 void listEH(Widget w, int num, XButtonEvent *event)
455 {
456         int             i, j, ITEM_COUNT;
457         Arg             args[10];
458         XmString        *xms ;
459         char            *str ;
460
461         int             rtn ;
462         Position        x, y ;
463
464         /*
465          *      get list items
466          */
467         ITEM_COUNT = 0;
468         rtn = GetItemsToDisplay( num, &ITEM_COUNT, &xms ) ;
469         switch( rtn ){
470             case FALX_TRY_NEXT :
471                 fprintf( stderr, "There are no fonts that was required.\n" ) ;
472                 XmTextSetString( slctBText[0], " " );
473                 ClearText( -1, slctBText ) ;
474                 FalxFreeDataBuff( FALX_ALL, &KeyBuff ) ;
475                 getmask = 0 ;
476                 return ;
477             case 0 :
478                 break ;
479             default :
480                 fprintf( stderr, "GetItemsToDisplay() error.\n" ) ;
481                 exit(-1) ;
482         }
483
484         if( num == 0 && ITEM_COUNT == 1 ){
485
486             str = (char *) _XmStringUngenerate((XmString) xms[0], NULL,
487                                         XmMULTIBYTE_TEXT, XmMULTIBYTE_TEXT);
488             if (str)
489                XmTextSetString(slctBText[num], str );
490             return ;
491         }
492         if( ITEM_COUNT < 0 ){
493             exit(-1) ;
494         }
495
496
497         /*
498          * get text field position
499          */
500         GetPositionOfLists( num, xlfdDialog, listPop, slctBText, &x, &y ) ;
501
502         i = 0;
503         XtSetArg(args[i], XmNx, x  ) ;  i++;
504         XtSetArg(args[i], XmNy, y  ) ;  i++;
505         XtSetValues(listPop[num], args, i );
506
507         /*
508          *      set list items
509          */
510         i = 0;
511         XtSetArg (args[i], XmNitems, xms ); i++;
512         XtSetArg (args[i], XmNitemCount, ITEM_COUNT ); i++;
513         XtSetValues(listW[num], args, i );
514
515         /*
516          * pop up list
517          */
518         XtPopup( listPop[num], XtGrabNone );
519
520 }
521
522
523
524
525 void listPrintCB(Widget w, int num, XmListCallbackStruct *call_data)
526 {
527         char    *str ;
528
529         /* clear text fields and unset buttons */
530         ClearButtons( num, slctButton ) ;
531
532
533         str = (char *) _XmStringUngenerate((XmString) call_data->item, NULL,
534                                         XmMULTIBYTE_TEXT, XmMULTIBYTE_TEXT);
535         if (str) {
536             XmTextSetString(slctBText[num], str);
537         }
538
539 #if 0
540         /* set key data         */
541         if( SetKeyBuff( num, str ) ){
542             exit(-1) ;
543         }
544 #endif  /* 0 */
545
546         if( XtIsManaged( listPop[num] ) )       XtUnmanageChild( listPop[num] );
547
548 }
549
550
551
552
553
554 void OpenWindow(Widget w, caddr_t client_data, caddr_t *call_data)
555 {
556     int         r ;
557     int         i ;
558     int         ans;
559     char        *msg;
560     char        *msg1;
561     char        *msg2;
562     char        *msg3;
563     char        *str, buff[512] ;
564
565     msg = GETMESSAGE(6, 4, "No UDCs exist in this font");
566     msg1 = GETMESSAGE(6, 6, "XLFD name isn't selected");
567     msg2 = GETMESSAGE(6, 8, "Can't open the font file");
568     msg3 = GETMESSAGE(6, 10, "The font file is used by other UDC client.");
569
570     /* get font file name (str:  XLFD name)     */
571     str = XmTextGetString( slctBText[0] );
572     if (( str == NULL ) || (strcmp(str, "") == 0)) {
573         AskUser(w, ed, msg1, &ans, "error");
574         return;
575     }
576     if( fullPathName != NULL ){
577         free( fullPathName ) ;
578     }
579     SelectedOffset = FalxSearchFontFileName( str, font_L, buff ) ;
580     if( SelectedOffset < 0 ){
581         exit(-1) ;
582     }
583     if( (fullPathName = strdup( buff )) == NULL ){
584         exit(-1) ;
585     }
586     UdcAreaCount = FalxGetGlyphIndexInfo( str, font_L, &UdcArea ) ;
587     if( UdcAreaCount < 0 ){
588         exit(-1) ;
589     }
590
591     if( fullPathName != NULL ){
592         Dprintf( stderr, "OpenWindow() : full path name = %s\n", fullPathName );
593     }
594     for( i=0; i<UdcAreaCount; i++ ){
595         Dprintf( stderr, "OpenWindow() : start(%d) = 0x%x\n", i, UdcArea[i].udc_start );
596         Dprintf( stderr, "OpenWindow() : end  (%d) = 0x%x\n", i, UdcArea[i].udc_end );
597     }
598     if ((ed->xlfdname = strdup(str)) == NULL) {
599         exit (-1);
600     }
601     if ((ed->fontfile = strdup(fullPathName)) == NULL) {
602         exit (-1);
603     }
604 /*    getxlfd(ed);*/
605 /* initialize ld */
606     if ((ld = (ListData *) malloc(sizeof(ListData))) == NULL) {
607         excerror(ed, EXCERRMALLOC, "selcharcd", "exit");
608     }
609     memset(ld, 0x00, sizeof(ListData));
610     ld->ed = ed;
611
612     if (ed->function == EXPORT) {
613         r = fontcheck(ed->fontfile, "r");
614         if (r == -1) { /* file open error */
615             AskUser(ld->ed->toplevel, ld->ed, msg2, &ans, "error");
616             return;
617         } else if (r == 1) { /* file is being editted by other UDC client */
618             AskUser(ld->ed->toplevel, ld->ed, msg3, &ans, "error");
619             return;
620         }
621         /* get existing UDC code */
622         getexistcode(ld);
623         if (ld->existcode_num == 0) {
624             AskUser(ld->ed->toplevel, ld->ed, msg, &ans, "error");
625             return;
626         }
627         XtUnmanageChild(xlfdDialog);
628         selcharcd(ed);
629     } else if (ed->function == IMPORT) {
630         r = fontcheck(ed->fontfile, "w");
631         if (r == -1) { /* file open error */
632             AskUser(ld->ed->toplevel, ld->ed, msg2, &ans, "error");
633             return;
634         } else if (r == 1) { /* file is being editted by other UDC client */
635             AskUser(ld->ed->toplevel, ld->ed, msg3, &ans, "error");
636             return;
637         }
638         /* get existing UDC code */
639         getexistcode(ld);
640
641         XtUnmanageChild(xlfdDialog);
642         getcharcd(ed);
643     }
644 }
645
646
647
648 /****************************************************************
649  * functions for create window view
650 ****************************************************************/
651
652 #define SetLabel( cnt ){ \
653         switch( cnt ){ \
654             case 0 : buf = resource.xlfd_label ; break ; \
655             case 1 : buf = resource.code_label ; break ; \
656             case 2 : buf = resource.style_label; break ; \
657             case 3 : buf = resource.size_label ; break ; \
658         } \
659         xms = XmStringCreateLocalized( buf ); \
660 }
661
662
663 int
664 CreateXLFDLabelAndText(
665 Widget  owner,
666 Widget  *slctBLabel,
667 Widget  *slctBText,
668 Widget  *slctButton)
669 {
670
671         Widget  _slctBLabel ;
672         Widget  _slctBText ;
673         Widget  _slctButton ;
674         int             i, j;
675         Arg             args[16];
676         char            *buf ;
677         XmString        xms ;
678
679         /*
680         *  create XLFD titles
681         */
682         i = 0;
683         XtSetArg( args[i], XmNx,            20 ) ;      i++ ;
684         XtSetArg( args[i], XmNheight,       20 ) ;      i++ ;
685         XtSetArg( args[i], XmNtopAttachment, XmATTACH_FORM ) ; i++ ;
686         XtSetArg( args[i], XmNtopOffset,    20 ) ;      i++ ;
687 /*
688         _slctBLabel = XmCreateLabelGadget( owner , "xlfdlabel", args, i );
689 */
690         _slctBLabel = XmCreateLabel( owner , "xlfdlabel", args, i );
691
692         XtManageChild( _slctBLabel );
693
694         /*
695         *  create text fields to display XLFD font name
696         */
697         i = 0;
698         XtSetArg( args[i], XmNleftAttachment,   XmATTACH_FORM ) ; i++ ;
699         XtSetArg( args[i], XmNleftOffset,       20 ) ;          i++ ;
700         XtSetArg( args[i], XmNtopAttachment,    XmATTACH_WIDGET ); i++ ;
701         XtSetArg( args[i], XmNtopOffset,        5 ) ;           i++ ;
702         XtSetArg (args[i], XmNtopWidget,        _slctBLabel );  i++;
703         XtSetArg( args[i], XmNcolumns,          XLFD_COLUMNS ) ;        i++ ;
704         XtSetArg( args[i], XmNspacing,          0 ) ;           i++ ;
705         XtSetArg( args[i], XmNeditMode, XmSINGLE_LINE_EDIT ) ;  i++ ;
706         XtSetArg( args[i], XmNscrollBarDisplayPolicy,   XmAS_NEEDED ) ; i++ ;
707         XtSetArg( args[i], XmNscrollingPolicy,   XmAPPLICATION_DEFINED ) ;  i++ ;
708 /*
709         XtSetArg( args[i], XmNscrollingPolicy,   XmAUTOMATIC ) ;  i++ ;
710         XtSetArg( args[i], XmNlistSizePolicy,   XmCONSTANT ) ;  i++ ;
711
712         XtSetArg( args[i], XmNwidth, 600 ) ;                    i++ ;
713         XtSetArg( args[i], XmNfontList, fixed ) ;       i++ ;
714         XtSetArg( args[i], XmNeditable, True ) ;       i++ ;
715         XtSetArg( args[i], XmNlistSizePolicy,   XmVARIABLE ) ;  i++ ;
716 */
717         _slctBText = XmCreateScrolledText( owner , "xlfdtext", args, i );
718
719         XtManageChild( _slctBText );
720
721         /*
722         *  create XLFD select buttons
723         */
724         i = 0;
725         XtSetArg( args[i], XmNindicatorType,    XmONE_OF_MANY ) ;       i++ ;
726         XtSetArg (args[i], XmNtopWidget,        _slctBText );           i++;
727         XtSetArg( args[i], XmNtopAttachment,    XmATTACH_OPPOSITE_WIDGET ) ;    i++ ;
728         XtSetArg( args[i], XmNtopOffset,        15  ) ;                 i++ ;
729         XtSetArg( args[i], XmNleftAttachment,   XmATTACH_WIDGET ) ;     i++ ;
730         XtSetArg( args[i], XmNleftWidget,       _slctBText ) ;          i++ ;
731         XtSetArg( args[i], XmNleftOffset,       5 ) ;           i++ ;   /* WIDTH */
732         XtSetArg( args[i], XmNrightAttachment, XmATTACH_FORM ) ;      i++ ;
733         XtSetArg( args[i], XmNrightOffset,      5 ) ;           i++ ;   /* WIDTH */
734         xms = XmStringCreateLocalized( "" );
735         XtSetArg( args[i], XmNlabelString,     xms ) ;      i++ ;
736 /*
737         _slctButton = XmCreateToggleButtonGadget( owner , "xlfdbtn", args, i);
738 */
739         _slctButton = XmCreateToggleButton( owner , "xlfdbtn", args, i);
740
741         XtManageChild( _slctButton );
742
743         *slctBLabel = _slctBLabel ;
744         *slctBText  = _slctBText ;
745         *slctButton = _slctButton ;
746
747 }
748
749
750
751
752 int
753 CreateOtherLabelAndText(
754 int     num,
755 Widget  owner,
756 Widget  baseForm,
757 Widget  *slctBLabel,
758 Widget  topW,
759 Widget  *slctBText,
760 Widget  *slctButton)
761 {
762
763         Widget  _slctBLabel ;
764         Widget  _slctBText ;
765         Widget  _slctButton ;
766         int             i, j;
767         Arg             args[16];
768         char            *buf ;
769         XmString        xms ;
770
771
772         if( num < 1 )   return(0) ;
773
774         /*
775         *  create key titles
776         */
777         i = 0;
778         XtSetArg ( args[i], XmNtopWidget,
779                 (num==1) ? baseForm : topW ); i++;
780         XtSetArg( args[i], XmNx,            20 ) ;      i++ ;
781         XtSetArg( args[i], XmNheight,       20 ) ;      i++ ;
782         XtSetArg( args[i], XmNtopAttachment, XmATTACH_WIDGET ) ; i++ ;
783 /* DEBUG
784         XtSetArg( args[i], XmNtopOffset,    20 ) ;      i++ ;
785 */
786         XtSetArg( args[i], XmNtopOffset,    36 ) ;      i++ ;
787         SetLabel(num) ;
788         XtSetArg( args[i], XmNlabelString,      xms ) ; i++ ;
789 /*
790         _slctBLabel = XmCreateLabelGadget( owner , "label", args, i);
791 */
792         _slctBLabel = XmCreateLabel( owner , "label", args, i);
793
794         XtManageChild( _slctBLabel );
795
796         /*
797         *  create text fields to display selected keys
798         */
799         i = 0;
800         XtSetArg( args[i], XmNtopAttachment, XmATTACH_OPPOSITE_WIDGET ) ;       i++ ;
801         XtSetArg( args[i], XmNtopOffset,        -5 ) ;          i++ ;
802         XtSetArg (args[i], XmNtopWidget,        _slctBLabel );  i++;
803         XtSetArg( args[i], XmNrightAttachment,  XmATTACH_OPPOSITE_WIDGET ) ; i++ ;
804         XtSetArg( args[i], XmNrightOffset,      0 ) ;           i++ ;
805         XtSetArg (args[i], XmNrightWidget,      baseForm );     i++;
806         XtSetArg( args[i], XmNcolumns,          KEY_COLUMNS ) ;         i++ ;
807         XtSetArg( args[i], XmNspacing,          0 ) ;           i++ ;
808         XtSetArg( args[i], XmNeditMode,         XmSINGLE_LINE_EDIT ) ;  i++ ;
809         XtSetArg( args[i], XmNscrollBarDisplayPolicy,   XmAS_NEEDED ) ; i++ ;
810         XtSetArg( args[i], XmNscrollingPolicy,   XmAPPLICATION_DEFINED ) ;  i++ ;
811         /*
812         XtSetArg( args[i], XmNscrollingPolicy,   XmAUTOMATIC ) ;        i++ ;
813         XtSetArg( args[i], XmNlistSizePolicy,   XmCONSTANT ) ;  i++ ;
814
815         XtSetArg( args[i], XmNfontList, fixed ) ;               i++ ;
816         XtSetArg( args[i], XmNlistSizePolicy,   XmVARIABLE ) ;  i++ ;
817         */
818         if( num==BUTTONITEMS-1 )
819             _slctBText = XmCreateText( owner , "text" , args, i );
820         else
821             _slctBText = XmCreateScrolledText( owner , "text" , args, i );
822
823         XtManageChild( _slctBText );
824
825         /*
826         *  create select buttons
827         */
828         i = 0;
829         XtSetArg( args[i], XmNindicatorType,    XmONE_OF_MANY ) ; i++ ;
830         XtSetArg( args[i], XmNtopAttachment,    XmATTACH_OPPOSITE_WIDGET ) ;    i++ ;
831         XtSetArg( args[i], XmNtopOffset,        5  ) ;          i++ ;
832         XtSetArg (args[i], XmNtopWidget,        _slctBLabel );  i++;
833         XtSetArg( args[i], XmNleftAttachment,   XmATTACH_WIDGET ) ;     i++ ;
834         XtSetArg( args[i], XmNleftWidget,       _slctBText  ) ;         i++ ;
835         XtSetArg( args[i], XmNleftOffset,       5 ) ;           i++ ;   /* WIDTH */
836         xms = XmStringCreateLocalized( "" );
837         XtSetArg( args[i], XmNlabelString,     xms ) ;          i++ ;
838 /*
839         _slctButton = XmCreateToggleButtonGadget( owner , "button", args, i);
840 */
841         _slctButton = XmCreateToggleButton( owner , "button", args, i);
842
843         XtManageChild( _slctButton );
844
845         *slctBLabel = _slctBLabel ;
846         *slctBText  = _slctBText ;
847         *slctButton = _slctButton ;
848 }
849
850
851
852 /*
853 * create pop up lists
854 */
855
856
857 Widget
858 xlfdCreateScrolledList (Widget owner, char *name, Arg *args, int n)
859 {
860         Widget          listW ;
861
862         XtSetArg( args[n], XmNselectionPolicy,          XmSINGLE_SELECT ) ;n++ ;
863         XtSetArg( args[n], XmNlistSpacing,              4 ) ;           n++ ;
864         XtSetArg( args[n], XmNlistSizePolicy,           XmCONSTANT ) ;  n++ ;
865         XtSetArg( args[n], XmNscrollBarDisplayPolicy,   XmAS_NEEDED ) ; n++ ;
866         listW = XmCreateScrolledList( owner, name, args, n );
867
868         XtManageChild( listW );
869
870
871         return( listW );
872 }
873
874
875
876 /*
877 * create selection window view
878 */
879 void
880 PopupSelectXLFD(Widget top)
881 {
882
883     int         n, i, j;
884     Arg         args[16];
885     char                *buf ;
886     XmString    xms ;
887     Dimension   pix, xwidth, kwidth ;
888
889     if( xlfdDialog == NULL ){
890         /*
891         *  create base window
892         */
893         n = 0 ;
894         XtSetArg( args[n], XmNautoUnmanage, False ) ;           n++ ;
895         XtSetArg( args[n], XmNtitle, maintitle ) ;              n++ ;
896         XtSetArg( args[n], XmNnoResize, True ) ;                n++ ;
897         xms = XmStringCreateLocalized( resource.exec_label ) ;
898         XtSetArg( args[n], XmNokLabelString, xms ) ;            n++ ;
899         xms = XmStringCreateLocalized( resource.quit_label) ;
900         XtSetArg( args[n], XmNhelpLabelString, xms ) ;          n++ ;
901 Dprintf( stdout, "(PopupSelectXLFD)XmCreateTemplateDialog: start\n" ) ;
902         xlfdDialog = XmCreateTemplateDialog( top, "SelectDialog", args, n );
903 Dprintf( stdout, "(PopupSelectXLFD)XmCreateTemplateDialog: end\n" ) ;
904
905         n = 0 ;
906         xlfdWform  = XmCreateForm( xlfdDialog, "BaseForm", args, n );
907         XtManageChild( xlfdWform );
908
909
910         /*
911         *  create XLFD columns
912         */
913 Dprintf( stdout, "(PopupSelectXLFD)CreateXLFDLabelAndText : start\n" ) ;
914         CreateXLFDLabelAndText( xlfdWform ,
915                                  &slctBLabel[0], &slctBText[0], &slctButton[0] ) ;
916         n = 0 ;
917         SetLabel(0) ;
918         XtSetArg( args[n], XmNlabelString,      xms ) ; n++ ;
919         XtSetValues( slctBLabel[0], args, n ) ;
920 Dprintf( stdout, "(PopupSelectXLFD)CreateXLFDLabelAndText : end\n" ) ;
921
922         /*
923         *  create other key columns
924         */
925 Dprintf( stdout, "(PopupSelectXLFD)CreateOtherLabelAndText :start\n" ) ;
926         for( j=1; j<BUTTONITEMS; j++ ){
927             CreateOtherLabelAndText( j, xlfdWform, slctBText[0],
928                  &slctBLabel[j], slctBLabel[j-1], &slctBText[j], &slctButton[j] ) ;
929         }
930 Dprintf( stdout, "(PopupSelectXLFD)CreateOtherLabelAndText : end\n" ) ;
931
932         /* set bottom offsets */
933         n = 0 ;
934         XtSetArg( args[n], XmNbottomAttachment, XmATTACH_FORM ) ; n++ ;
935         XtSetArg( args[n], XmNbottomOffset,     36 ) ;          n++ ;
936         XtSetValues( slctBLabel[BUTTONITEMS-1], args, n ) ;
937
938         /* get pixel size */
939         pix = GetPixelWidth( slctBText[0], XLFD_COLUMNS, &xwidth ) ;
940         /* xwidth += pix / 2 ; */
941         kwidth = pix * KEY_COLUMNS + pix / 2 ;
942
943         /*
944         *  create popup shells
945         */
946         for( j=0; j<BUTTONITEMS; j++ ) {
947             n = 0;
948             listPop[j] = XtCreatePopupShell( shell_n[j], overrideShellWidgetClass,
949                                              xlfdWform , args, n );
950         }
951
952         /*
953         *  create popup lists
954         */
955         for( j=0; j<BUTTONITEMS; j++ ) {
956             n = 0 ;
957             XtSetArg( args[n], XmNvisibleItemCount, (j==0)? 10 : 5 ) ;  n++ ;
958             if( j==0 ){
959                 XtSetArg( args[n], XmNwidth,   xwidth ) ;               n++ ;
960             }else{
961                 XtSetArg( args[n], XmNwidth,   kwidth ) ;               n++ ;
962                 XtSetArg( args[n], XmNlistMarginWidth,   0 ) ;          n++ ;
963             }
964             listW[j] = xlfdCreateScrolledList( listPop[j], list_n[j], args, n );
965         }
966
967         /*
968          * Error_Messege
969          */
970 #if 0
971         n = 0 ;
972         XtSetArg( args[n], XmNokLabelString,    "OK" ) ;    n++ ;
973         XtSetArg( args[n], XmNcancelLabelString,"Cancel" ) ;    n++ ;
974         errorMD = XmCreateMessageDialog(toplevel, "ed0", NULL, 0);
975
976         msgBox = XmMessageBoxGetChild(errorMD, XmDIALOG_HELP_BUTTON);
977         XtUnmanageChild(msgBox);
978 #endif  /* 0 */
979
980         /*
981          * add callbacks
982          */
983         for( i=0; i<BUTTONITEMS; i++ )
984             XtAddEventHandler( slctButton[i], ButtonReleaseMask, False, (XtEventHandler) listEH, (XtPointer) i );
985
986         for( i=0; i<BUTTONITEMS; i++ )
987             XtAddCallback(listW[i], XmNsingleSelectionCallback, (XtCallbackProc) listPrintCB, (XtPointer) i );
988
989         XtAddCallback( xlfdDialog, XmNokCallback, (XtCallbackProc) OpenWindow, NULL );
990         XtAddCallback( xlfdDialog, XmNhelpCallback,(XtCallbackProc) quit,NULL );
991
992 #if 0
993         XtAddCallback( errorMD, XmNcancelCallback, (XtCallbackProc) quit, NULL);
994 #endif  /* 0 */
995
996     }
997     /*
998      * pop up select window
999      */
1000 Dprintf( stdout, "(PopupSelectXLFD)xlfdPopupDialog : start\n" ) ;
1001     xlfdPopupDialog( xlfdDialog );
1002 Dprintf( stdout, "(PopupSelectXLFD)xlfdPopupDialog : end\n" ) ;
1003 Dprintf( stdout, " : end\n" ) ;
1004
1005 }
1006
1007
1008
1009 #undef SetLabel