Fix typo in license headers
[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()
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(w)
315 Widget w;
316 {
317     if (! XtIsManaged(w))
318         XtManageChild(w);
319     else
320         XRaiseWindow(XtDisplayOfObject(w), XtWindow(XtParent(w)));
321 }
322
323 void
324 xlfdPopdownDialog(w)
325 Widget w;
326 {
327     if (XtIsManaged(w)){
328         XtUnmanageChild(w);
329     }
330 }
331
332
333 /*
334 * get pixel width
335 */
336 Dimension
337 GetPixelWidth( w, columns, width )
338 Widget          w ;
339 int             columns ;
340 Dimension       *width ;
341 {
342         Arg             args[1] ;
343         XtSetArg( args[0], XmNwidth, width ) ;
344         XtGetValues( w , args, 1 ) ;
345         return( *width / (Dimension)columns ) ;
346 }
347
348
349 /****************************************************************
350  * callbacks                                                    *
351  ***************************************************************/
352
353 void quit(w, client_data, call_data)
354 Widget  w;
355 caddr_t *client_data, *call_data;
356 {
357     char        *msg;
358     int         ans;
359
360     msg = GETMESSAGE(6, 2, "Do you want to terminate udcexchange?");
361
362     AskUser(ed->toplevel, ed, msg, &ans, "question");
363     if (ans == 1) {/* terminate ok */
364         FalxFreeCodeList( CodeList ) ;
365         FalxFreeStyleList( StyleList ) ;
366         FalxFreeSizeList( SizeList ) ;
367         FalxFreeFontList( font_L ) ;
368         excterminate(ed);
369     }
370 }
371
372
373 /*
374  * Unmanage widgets
375  */
376 int
377 ClearText( num, slctBText ) 
378 int     num ;
379 Widget  *slctBText ;
380 {
381         int     i ;
382         /* toggle button unset */
383         for( i=0; i<BUTTONITEMS; i++ ){
384             if( i>num ){
385                 XmTextSetString( slctBText[i], "" );
386             }
387         }
388         return ;
389 }
390
391 int
392 ClearButtons( num, slctButton ) 
393 int     num ;
394 Widget  *slctButton ;
395 {
396         int     i, cnt ;
397         Boolean isSet ;
398         Arg     args[5] ;
399         /* toggle button unset */
400         for( i=0; i<BUTTONITEMS; i++ ){
401             if( i != num ){
402                 cnt = 0;
403                 XtSetArg( args[cnt], XmNset, &isSet );  cnt++;
404                 XtGetValues( slctButton[i], args, cnt );
405                 if( isSet == True ){
406                     cnt = 0;
407                     XtSetArg( args[cnt], XmNset, False );       cnt++;
408                     XtSetValues( slctButton[i], args, cnt );
409                 }
410             }
411         }
412         return ;
413 }
414
415
416
417 /* 
418  * get text field position
419  */
420 int
421 GetPositionOfLists( num, xlfdDialog, listPop, slctBText, x, y ) 
422 int     num ; 
423 Widget  xlfdDialog ; 
424 Widget  *listPop ;
425 Widget  *slctBText ; 
426 Position        *x ; 
427 Position        *y ; 
428 {
429         int             i ;
430         Position        tbx, tby, tx, ty ;
431         Dimension       theight ;
432         Arg     args[10] ;
433
434         i = 0;
435         XtSetArg(args[i], XmNx, &tbx ); i++;
436         XtSetArg(args[i], XmNy, &tby ); i++;
437         XtGetValues( xlfdDialog, args, i);
438         i = 0;
439         XtSetArg(args[i], XmNx, &tx );  i++;
440         XtSetArg(args[i], XmNy, &ty );  i++;
441         XtSetArg(args[i], XmNheight, &theight );        i++;
442         if( num==BUTTONITEMS-1 )
443             XtGetValues( slctBText[num], args, i ) ;
444         else
445             XtGetValues( XtParent(slctBText[num]), args, i ) ;  /* ScrolledText */
446         /*  determine the position of list */
447         *x = tx + tbx + CX ;
448         if( num==BUTTONITEMS-1 ){
449         *y = ty + tby + (Position)theight + 14 + CY ;
450         }else{
451         *y = ty + tby + (Position)theight + CY ;
452         }
453
454         for( i=0; i<BUTTONITEMS; i++ ){
455             if( XtIsManaged( listPop[i] ) )     XtUnmanageChild( listPop[i] );
456         }
457         if( !XtIsManaged( listPop[num] ) )      XtManageChild( listPop[num] );
458
459         return ;
460 }
461
462
463
464
465 void listEH(w, num, event)
466 Widget  w ;
467 int     num ;
468 XButtonEvent    *event;
469 {
470         int             i, j, ITEM_COUNT;
471         Arg             args[10];
472         XmString        *xms ;
473         char            *str ;
474
475         int             rtn ;
476         Position        x, y ;
477
478         /*
479          *      get list items 
480          */
481         ITEM_COUNT = 0;
482         rtn = GetItemsToDisplay( num, &ITEM_COUNT, &xms ) ;
483         switch( rtn ){
484             case FALX_TRY_NEXT :
485                 fprintf( stderr, "There are no fonts that was required.\n" ) ;
486                 XmTextSetString( slctBText[0], " " );
487                 ClearText( -1, slctBText ) ;
488                 FalxFreeDataBuff( FALX_ALL, &KeyBuff ) ;
489                 getmask = 0 ;
490                 return ;
491             case 0 :
492                 break ;
493             default :
494                 fprintf( stderr, "GetItemsToDisplay() error.\n" ) ;
495                 exit(-1) ;
496         }
497
498         if( num == 0 && ITEM_COUNT == 1 ){
499
500             str = (char *) _XmStringUngenerate((XmString) xms[0], NULL,
501                                         XmMULTIBYTE_TEXT, XmMULTIBYTE_TEXT);
502             if (str)
503                XmTextSetString(slctBText[num], str );
504             return ;
505         }
506         if( ITEM_COUNT < 0 ){
507             exit(-1) ;
508         }
509
510
511         /* 
512          * get text field position
513          */
514         GetPositionOfLists( num, xlfdDialog, listPop, slctBText, &x, &y ) ;
515
516         i = 0;
517         XtSetArg(args[i], XmNx, x  ) ;  i++;
518         XtSetArg(args[i], XmNy, y  ) ;  i++;
519         XtSetValues(listPop[num], args, i );
520
521         /*
522          *      set list items 
523          */
524         i = 0;
525         XtSetArg (args[i], XmNitems, xms ); i++;
526         XtSetArg (args[i], XmNitemCount, ITEM_COUNT ); i++;
527         XtSetValues(listW[num], args, i );
528
529         /*
530          * pop up list
531          */
532         XtPopup( listPop[num], XtGrabNone );
533
534 }
535
536
537
538
539 void listPrintCB(w, num, call_data)
540 Widget                  w;
541 int                     num ;
542 XmListCallbackStruct    *call_data;
543 {
544         char    *str ;
545
546         /* clear text fields and unset buttons */
547         ClearButtons( num, slctButton ) ;
548
549
550         str = (char *) _XmStringUngenerate((XmString) call_data->item, NULL,
551                                         XmMULTIBYTE_TEXT, XmMULTIBYTE_TEXT);
552         if (str) {
553             XmTextSetString(slctBText[num], str);
554         }
555
556 #if 0
557         /* set key data         */
558         if( SetKeyBuff( num, str ) ){
559             exit(-1) ;
560         }
561 #endif  /* 0 */
562
563         if( XtIsManaged( listPop[num] ) )       XtUnmanageChild( listPop[num] );
564
565 }
566
567
568
569
570
571 void OpenWindow(w, client_data, call_data)
572 Widget  w;
573 caddr_t client_data, *call_data;
574 {
575     int         r ;
576     int         i ;
577     int         ans;
578     char        *msg;
579     char        *msg1;
580     char        *msg2;
581     char        *msg3;
582     char        *str, buff[512] ;
583
584     msg = GETMESSAGE(6, 4, "No UDCs exist in this font");
585     msg1 = GETMESSAGE(6, 6, "XLFD name isn't selected");
586     msg2 = GETMESSAGE(6, 8, "Can't open the font file");
587     msg3 = GETMESSAGE(6, 10, "The font file is used by other UDC client.");
588
589     /* get font file name (str:  XLFD name)     */
590     str = XmTextGetString( slctBText[0] );
591     if (( str == NULL ) || (strcmp(str, "") == 0)) {
592         AskUser(w, ed, msg1, &ans, "error");
593         return;
594     }
595     if( fullPathName != NULL ){
596         free( fullPathName ) ;
597     }
598     SelectedOffset = FalxSearchFontFileName( str, font_L, buff ) ;
599     if( SelectedOffset < 0 ){
600         exit(-1) ;
601     }
602     if( (fullPathName = strdup( buff )) == NULL ){
603         exit(-1) ;
604     }
605     UdcAreaCount = FalxGetGlyphIndexInfo( str, font_L, &UdcArea ) ;
606     if( UdcAreaCount < 0 ){
607         exit(-1) ;
608     }
609
610     if( fullPathName != NULL ){
611         Dprintf( stderr, "OpenWindow() : full path name = %s\n", fullPathName );
612     }
613     for( i=0; i<UdcAreaCount; i++ ){
614         Dprintf( stderr, "OpenWindow() : start(%d) = 0x%x\n", i, UdcArea[i].udc_start );
615         Dprintf( stderr, "OpenWindow() : end  (%d) = 0x%x\n", i, UdcArea[i].udc_end );
616     }
617     if ((ed->xlfdname = strdup(str)) == NULL) {
618         exit (-1);
619     }
620     if ((ed->fontfile = strdup(fullPathName)) == NULL) {
621         exit (-1);
622     }
623 /*    getxlfd(ed);*/
624 /* initialize ld */
625     if ((ld = (ListData *) malloc(sizeof(ListData))) == NULL) {
626         excerror(ed, EXCERRMALLOC, "selcharcd", "exit");
627     }
628     memset(ld, 0x00, sizeof(ListData));
629     ld->ed = ed;
630
631     if (ed->function == EXPORT) {
632         r = fontcheck(ed->fontfile, "r");
633         if (r == -1) { /* file open error */
634             AskUser(ld->ed->toplevel, ld->ed, msg2, &ans, "error");
635             return;
636         } else if (r == 1) { /* file is being editted by other UDC client */
637             AskUser(ld->ed->toplevel, ld->ed, msg3, &ans, "error");
638             return;
639         }
640         /* get existing UDC code */
641         getexistcode(ld);
642         if (ld->existcode_num == 0) {
643             AskUser(ld->ed->toplevel, ld->ed, msg, &ans, "error");
644             return;
645         }
646         XtUnmanageChild(xlfdDialog);
647         selcharcd(ed);
648     } else if (ed->function == IMPORT) {
649         r = fontcheck(ed->fontfile, "w");
650         if (r == -1) { /* file open error */
651             AskUser(ld->ed->toplevel, ld->ed, msg2, &ans, "error");
652             return;
653         } else if (r == 1) { /* file is being editted by other UDC client */
654             AskUser(ld->ed->toplevel, ld->ed, msg3, &ans, "error");
655             return;
656         }
657         /* get existing UDC code */
658         getexistcode(ld);
659
660         XtUnmanageChild(xlfdDialog);
661         getcharcd(ed);
662     }
663 }
664
665
666
667 /****************************************************************
668  * functions for create window view
669 ****************************************************************/
670
671 #define SetLabel( cnt ){ \
672         switch( cnt ){ \
673             case 0 : buf = resource.xlfd_label ; break ; \
674             case 1 : buf = resource.code_label ; break ; \
675             case 2 : buf = resource.style_label; break ; \
676             case 3 : buf = resource.size_label ; break ; \
677         } \
678         xms = XmStringCreateLocalized( buf ); \
679 }
680
681
682 int
683 CreateXLFDLabelAndText( owner, slctBLabel, slctBText, slctButton )
684 Widget  owner ;
685 Widget  *slctBLabel ;
686 Widget  *slctBText ;
687 Widget  *slctButton ;
688 {
689
690         Widget  _slctBLabel ;
691         Widget  _slctBText ;
692         Widget  _slctButton ;
693         int             i, j;
694         Arg             args[16];
695         char            *buf ;
696         XmString        xms ;
697
698         /*
699         *  create XLFD titles
700         */
701         i = 0;
702         XtSetArg( args[i], XmNx,            20 ) ;      i++ ;
703         XtSetArg( args[i], XmNheight,       20 ) ;      i++ ;
704         XtSetArg( args[i], XmNtopAttachment, XmATTACH_FORM ) ; i++ ;
705         XtSetArg( args[i], XmNtopOffset,    20 ) ;      i++ ;
706 /*
707         _slctBLabel = XmCreateLabelGadget( owner , "xlfdlabel", args, i );
708 */
709         _slctBLabel = XmCreateLabel( owner , "xlfdlabel", args, i );
710
711         XtManageChild( _slctBLabel );
712
713         /*
714         *  create text fields to display XLFD font name
715         */
716         i = 0;
717         XtSetArg( args[i], XmNleftAttachment,   XmATTACH_FORM ) ; i++ ;
718         XtSetArg( args[i], XmNleftOffset,       20 ) ;          i++ ;
719         XtSetArg( args[i], XmNtopAttachment,    XmATTACH_WIDGET ); i++ ;
720         XtSetArg( args[i], XmNtopOffset,        5 ) ;           i++ ;
721         XtSetArg (args[i], XmNtopWidget,        _slctBLabel );  i++;
722         XtSetArg( args[i], XmNcolumns,          XLFD_COLUMNS ) ;        i++ ;
723         XtSetArg( args[i], XmNspacing,          0 ) ;           i++ ;
724         XtSetArg( args[i], XmNeditMode, XmSINGLE_LINE_EDIT ) ;  i++ ;
725         XtSetArg( args[i], XmNscrollBarDisplayPolicy,   XmAS_NEEDED ) ; i++ ;
726         XtSetArg( args[i], XmNscrollingPolicy,   XmAPPLICATION_DEFINED ) ;  i++ ;
727 /*
728         XtSetArg( args[i], XmNscrollingPolicy,   XmAUTOMATIC ) ;  i++ ;
729         XtSetArg( args[i], XmNlistSizePolicy,   XmCONSTANT ) ;  i++ ;
730
731         XtSetArg( args[i], XmNwidth, 600 ) ;                    i++ ;
732         XtSetArg( args[i], XmNfontList, fixed ) ;       i++ ;
733         XtSetArg( args[i], XmNeditable, True ) ;       i++ ;
734         XtSetArg( args[i], XmNlistSizePolicy,   XmVARIABLE ) ;  i++ ;
735 */
736         _slctBText = XmCreateScrolledText( owner , "xlfdtext", args, i );
737
738         XtManageChild( _slctBText );
739
740         /*
741         *  create XLFD select buttons
742         */
743         i = 0;
744         XtSetArg( args[i], XmNindicatorType,    XmONE_OF_MANY ) ;       i++ ;
745         XtSetArg (args[i], XmNtopWidget,        _slctBText );           i++;
746         XtSetArg( args[i], XmNtopAttachment,    XmATTACH_OPPOSITE_WIDGET ) ;    i++ ;
747         XtSetArg( args[i], XmNtopOffset,        15  ) ;                 i++ ;
748         XtSetArg( args[i], XmNleftAttachment,   XmATTACH_WIDGET ) ;     i++ ;
749         XtSetArg( args[i], XmNleftWidget,       _slctBText ) ;          i++ ;
750         XtSetArg( args[i], XmNleftOffset,       5 ) ;           i++ ;   /* WIDTH */
751         XtSetArg( args[i], XmNrightAttachment, XmATTACH_FORM ) ;      i++ ;
752         XtSetArg( args[i], XmNrightOffset,      5 ) ;           i++ ;   /* WIDTH */
753         xms = XmStringCreateLocalized( "" );
754         XtSetArg( args[i], XmNlabelString,     xms ) ;      i++ ;
755 /*
756         _slctButton = XmCreateToggleButtonGadget( owner , "xlfdbtn", args, i);
757 */
758         _slctButton = XmCreateToggleButton( owner , "xlfdbtn", args, i);
759
760         XtManageChild( _slctButton );
761
762         *slctBLabel = _slctBLabel ;
763         *slctBText  = _slctBText ;
764         *slctButton = _slctButton ;
765
766 }
767         
768
769
770
771 int
772 CreateOtherLabelAndText( num, owner, baseForm,
773                          slctBLabel, topW, slctBText, slctButton )
774 int     num ;
775 Widget  owner ;
776 Widget  baseForm ;
777 Widget  *slctBLabel ;
778 Widget  topW ;
779 Widget  *slctBText ;
780 Widget  *slctButton ;
781 {
782
783         Widget  _slctBLabel ;
784         Widget  _slctBText ;
785         Widget  _slctButton ;
786         int             i, j;
787         Arg             args[16];
788         char            *buf ;
789         XmString        xms ;
790
791
792         if( num < 1 )   return(0) ;
793
794         /*
795         *  create key titles
796         */
797         i = 0;
798         XtSetArg ( args[i], XmNtopWidget,
799                 (num==1) ? baseForm : topW ); i++;
800         XtSetArg( args[i], XmNx,            20 ) ;      i++ ;
801         XtSetArg( args[i], XmNheight,       20 ) ;      i++ ;
802         XtSetArg( args[i], XmNtopAttachment, XmATTACH_WIDGET ) ; i++ ;
803 /* DEBUG
804         XtSetArg( args[i], XmNtopOffset,    20 ) ;      i++ ;
805 */
806         XtSetArg( args[i], XmNtopOffset,    36 ) ;      i++ ;
807         SetLabel(num) ;
808         XtSetArg( args[i], XmNlabelString,      xms ) ; i++ ;
809 /*
810         _slctBLabel = XmCreateLabelGadget( owner , "label", args, i);
811 */
812         _slctBLabel = XmCreateLabel( owner , "label", args, i);
813
814         XtManageChild( _slctBLabel );
815
816         /*
817         *  create text fields to display selected keys
818         */
819         i = 0;
820         XtSetArg( args[i], XmNtopAttachment, XmATTACH_OPPOSITE_WIDGET ) ;       i++ ;
821         XtSetArg( args[i], XmNtopOffset,        -5 ) ;          i++ ;
822         XtSetArg (args[i], XmNtopWidget,        _slctBLabel );  i++;
823         XtSetArg( args[i], XmNrightAttachment,  XmATTACH_OPPOSITE_WIDGET ) ; i++ ;
824         XtSetArg( args[i], XmNrightOffset,      0 ) ;           i++ ;
825         XtSetArg (args[i], XmNrightWidget,      baseForm );     i++;
826         XtSetArg( args[i], XmNcolumns,          KEY_COLUMNS ) ;         i++ ;
827         XtSetArg( args[i], XmNspacing,          0 ) ;           i++ ;
828         XtSetArg( args[i], XmNeditMode,         XmSINGLE_LINE_EDIT ) ;  i++ ;
829         XtSetArg( args[i], XmNscrollBarDisplayPolicy,   XmAS_NEEDED ) ; i++ ;
830         XtSetArg( args[i], XmNscrollingPolicy,   XmAPPLICATION_DEFINED ) ;  i++ ;
831         /*
832         XtSetArg( args[i], XmNscrollingPolicy,   XmAUTOMATIC ) ;        i++ ;
833         XtSetArg( args[i], XmNlistSizePolicy,   XmCONSTANT ) ;  i++ ;
834
835         XtSetArg( args[i], XmNfontList, fixed ) ;               i++ ;
836         XtSetArg( args[i], XmNlistSizePolicy,   XmVARIABLE ) ;  i++ ;
837         */
838         if( num==BUTTONITEMS-1 )
839             _slctBText = XmCreateText( owner , "text" , args, i );
840         else
841             _slctBText = XmCreateScrolledText( owner , "text" , args, i );
842
843         XtManageChild( _slctBText );
844
845         /*
846         *  create select buttons
847         */
848         i = 0;
849         XtSetArg( args[i], XmNindicatorType,    XmONE_OF_MANY ) ; i++ ;
850         XtSetArg( args[i], XmNtopAttachment,    XmATTACH_OPPOSITE_WIDGET ) ;    i++ ;
851         XtSetArg( args[i], XmNtopOffset,        5  ) ;          i++ ;
852         XtSetArg (args[i], XmNtopWidget,        _slctBLabel );  i++;
853         XtSetArg( args[i], XmNleftAttachment,   XmATTACH_WIDGET ) ;     i++ ;
854         XtSetArg( args[i], XmNleftWidget,       _slctBText  ) ;         i++ ;
855         XtSetArg( args[i], XmNleftOffset,       5 ) ;           i++ ;   /* WIDTH */
856         xms = XmStringCreateLocalized( "" );
857         XtSetArg( args[i], XmNlabelString,     xms ) ;          i++ ;
858 /*
859         _slctButton = XmCreateToggleButtonGadget( owner , "button", args, i);
860 */
861         _slctButton = XmCreateToggleButton( owner , "button", args, i);
862
863         XtManageChild( _slctButton );
864
865         *slctBLabel = _slctBLabel ;
866         *slctBText  = _slctBText ;
867         *slctButton = _slctButton ;
868 }
869
870
871
872 /*
873 * create pop up lists
874 */
875
876
877 Widget
878 xlfdCreateScrolledList ( owner, name, args, n )
879 Widget  owner ;
880 char    *name ;
881 Arg     *args ;
882 int     n ;
883 {
884         Widget          listW ;
885
886         XtSetArg( args[n], XmNselectionPolicy,          XmSINGLE_SELECT ) ;n++ ;
887         XtSetArg( args[n], XmNlistSpacing,              4 ) ;           n++ ;
888         XtSetArg( args[n], XmNlistSizePolicy,           XmCONSTANT ) ;  n++ ;
889         XtSetArg( args[n], XmNscrollBarDisplayPolicy,   XmAS_NEEDED ) ; n++ ;
890         listW = XmCreateScrolledList( owner, name, args, n );
891
892         XtManageChild( listW );
893
894
895         return( listW );
896 }
897
898
899
900 /*
901 * create selection window view
902 */
903 void
904 PopupSelectXLFD( top )
905 Widget  top ;
906 {
907
908     int         n, i, j;
909     Arg         args[16];
910     char                *buf ;
911     XmString    xms ;
912     Dimension   pix, xwidth, kwidth ;
913
914     if( xlfdDialog == NULL ){
915         /*
916         *  create base window
917         */
918         n = 0 ;
919         XtSetArg( args[n], XmNautoUnmanage, False ) ;           n++ ;
920         XtSetArg( args[n], XmNtitle, maintitle ) ;              n++ ;
921         XtSetArg( args[n], XmNnoResize, True ) ;                n++ ;
922         xms = XmStringCreateLocalized( resource.exec_label ) ;
923         XtSetArg( args[n], XmNokLabelString, xms ) ;            n++ ;
924         xms = XmStringCreateLocalized( resource.quit_label) ;
925         XtSetArg( args[n], XmNhelpLabelString, xms ) ;          n++ ;
926 Dprintf( stdout, "(PopupSelectXLFD)XmCreateTemplateDialog: start\n" ) ;
927         xlfdDialog = XmCreateTemplateDialog( top, "SelectDialog", args, n );
928 Dprintf( stdout, "(PopupSelectXLFD)XmCreateTemplateDialog: end\n" ) ;
929
930         n = 0 ;
931         xlfdWform  = XmCreateForm( xlfdDialog, "BaseForm", args, n );
932         XtManageChild( xlfdWform );
933
934
935         /*
936         *  create XLFD columns
937         */
938 Dprintf( stdout, "(PopupSelectXLFD)CreateXLFDLabelAndText : start\n" ) ;
939         CreateXLFDLabelAndText( xlfdWform ,
940                                  &slctBLabel[0], &slctBText[0], &slctButton[0] ) ;
941         n = 0 ;
942         SetLabel(0) ;
943         XtSetArg( args[n], XmNlabelString,      xms ) ; n++ ;
944         XtSetValues( slctBLabel[0], args, n ) ;
945 Dprintf( stdout, "(PopupSelectXLFD)CreateXLFDLabelAndText : end\n" ) ;
946
947         /*
948         *  create other key columns
949         */
950 Dprintf( stdout, "(PopupSelectXLFD)CreateOtherLabelAndText :start\n" ) ;
951         for( j=1; j<BUTTONITEMS; j++ ){
952             CreateOtherLabelAndText( j, xlfdWform, slctBText[0],
953                  &slctBLabel[j], slctBLabel[j-1], &slctBText[j], &slctButton[j] ) ;
954         }
955 Dprintf( stdout, "(PopupSelectXLFD)CreateOtherLabelAndText : end\n" ) ;
956
957         /* set bottom offsets */
958         n = 0 ;
959         XtSetArg( args[n], XmNbottomAttachment, XmATTACH_FORM ) ; n++ ;
960         XtSetArg( args[n], XmNbottomOffset,     36 ) ;          n++ ;
961         XtSetValues( slctBLabel[BUTTONITEMS-1], args, n ) ;
962
963         /* get pixel size */
964         pix = GetPixelWidth( slctBText[0], XLFD_COLUMNS, &xwidth ) ;
965         /* xwidth += pix / 2 ; */
966         kwidth = pix * KEY_COLUMNS + pix / 2 ;
967
968         /*
969         *  create popup shells
970         */
971         for( j=0; j<BUTTONITEMS; j++ ) {
972             n = 0;
973             listPop[j] = XtCreatePopupShell( shell_n[j], overrideShellWidgetClass,  
974                                              xlfdWform , args, n );
975         }
976
977         /*
978         *  create popup lists
979         */
980         for( j=0; j<BUTTONITEMS; j++ ) {
981             n = 0 ;
982             XtSetArg( args[n], XmNvisibleItemCount, (j==0)? 10 : 5 ) ;  n++ ;
983             if( j==0 ){
984                 XtSetArg( args[n], XmNwidth,   xwidth ) ;               n++ ;
985             }else{
986                 XtSetArg( args[n], XmNwidth,   kwidth ) ;               n++ ;
987                 XtSetArg( args[n], XmNlistMarginWidth,   0 ) ;          n++ ;
988             }
989             listW[j] = xlfdCreateScrolledList( listPop[j], list_n[j], args, n );
990         }
991
992         /*  
993          * Error_Messege
994          */
995 #if 0
996         n = 0 ;
997         XtSetArg( args[n], XmNokLabelString,    "OK" ) ;    n++ ;
998         XtSetArg( args[n], XmNcancelLabelString,"Cancel" ) ;    n++ ;
999         errorMD = XmCreateMessageDialog(toplevel, "ed0", NULL, 0);
1000
1001         msgBox = XmMessageBoxGetChild(errorMD, XmDIALOG_HELP_BUTTON);
1002         XtUnmanageChild(msgBox);
1003 #endif  /* 0 */
1004
1005         /*
1006          * add callbacks
1007          */
1008         for( i=0; i<BUTTONITEMS; i++ )
1009             XtAddEventHandler( slctButton[i], ButtonReleaseMask, False, (XtEventHandler) listEH, (XtPointer) i );
1010
1011         for( i=0; i<BUTTONITEMS; i++ )
1012             XtAddCallback(listW[i], XmNsingleSelectionCallback, (XtCallbackProc) listPrintCB, (XtPointer) i );
1013
1014         XtAddCallback( xlfdDialog, XmNokCallback, (XtCallbackProc) OpenWindow, NULL );
1015         XtAddCallback( xlfdDialog, XmNhelpCallback,(XtCallbackProc) quit,NULL );
1016
1017 #if 0
1018         XtAddCallback( errorMD, XmNcancelCallback, (XtCallbackProc) quit, NULL);
1019 #endif  /* 0 */
1020
1021     }
1022     /*
1023      * pop up select window
1024      */
1025 Dprintf( stdout, "(PopupSelectXLFD)xlfdPopupDialog : start\n" ) ;
1026     xlfdPopupDialog( xlfdDialog );
1027 Dprintf( stdout, "(PopupSelectXLFD)xlfdPopupDialog : end\n" ) ;
1028 Dprintf( stdout, " : end\n" ) ;
1029
1030 }
1031
1032
1033
1034 #undef SetLabel