2 * CDE - Common Desktop Environment
4 * Copyright (c) 1993-2012, The Open Group. All rights reserved.
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)
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
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
23 /* selectx.c 1.23 - Fujitsu source for CDEnext 96/10/30 13:13:45 */
24 /* $XConsortium: selectx.c /main/7 1996/11/08 01:54:18 cde-fuj $ */
26 * (c) Copyright 1995 FUJITSU LIMITED
27 * This is source code modified by FUJITSU LIMITED under the Joint
28 * Development Agreement for the CDEnext PST.
29 * This is unpublished proprietary source code of FUJITSU LIMITED
48 #include <Xm/SeparatoG.h>
50 #include <Xm/ToggleB.h>
51 #include <Xm/MessageB.h>
52 #include <Xm/RowColumn.h>
57 * There is no public header file for this function (only an
58 * internal header XmStringI.h).
60 extern XtPointer _XmStringUngenerate (XmString string,
63 XmTextType output_type);
66 #include "xoakufont.h"
67 #include "selectxlfd.h"
69 extern Resource resource ;
75 FalFontData fullFontData;
77 void PopupSelectXLFD(Widget top) ;
78 static Widget CreateSelectXLFD(Widget top) ;
80 extern void xlfdPopupDialog(Widget w);
82 extern void ReadCB(Widget w, XtPointer client_data, XtPointer call_data);
86 static Widget xlfdWform;
88 #define CS0 "Codeset 0"
89 #define CS1 "Codeset 1"
90 #define CS2 "Codeset 2"
91 #define CS3 "Codeset 3"
93 #define FAL_ERROR_STR resource.falerrmsg[((fal_utyerrno & 0xff) > 25) ? 0 : (fal_utyerrno & 0xff)]
95 static Widget pull1, pull2, pull3, pull4, scrolllist;
96 static int xlf_count = 0;
97 static XmString *xlf=NULL;
98 static int udc_count = 0;
99 static Boolean udc_flag = False;
100 static int *udc=NULL;
102 static int sty_count = 0;
103 static Boolean sty_flag = False;
104 static char **sty=NULL;
105 static char *sty_val=NULL;
106 static int wls_count = 0;
107 static Boolean wls_flag = False;
108 static int *wls=NULL;
110 static int hls_count = 0;
111 static Boolean hls_flag = False;
112 static int *hls=NULL;
114 static Widget *button1=NULL;
115 static Widget *button2=NULL;
116 static Widget *button3=NULL;
117 static Widget *button4=NULL;
119 /****************************************************************
121 ***************************************************************/
124 spc(char *str, char ch, int count)
127 p = str + strlen(str);
128 for(;count && (str < p);p--) {
138 static void OpenWindowCB(void)
143 XtVaGetValues(scrolllist, XmNselectedItems, &st, NULL);
145 fullFontData.xlfdname = NULL;
148 str = (char *) _XmStringUngenerate(st[0], NULL, XmMULTIBYTE_TEXT, XmMULTIBYTE_TEXT);
150 p = spc(str, '-', 4);
153 if (*p == 'p' || *p == 'P') {
154 fullFontData.xlfdname = (char *)-1;
158 fullFontData.xlfdname = str;
160 fullFontData.cd_set = udc_val;
162 fullFontData.cd_set = -1;
166 ** contents : "Cancel" button callback
167 ** ------------------------
174 OpenCancelCB(Widget widget, caddr_t clientData, caddr_t callData)
176 extern void ForcePopdownDialog();
180 ForcePopdownDialog(xlfdDialog);
185 * create selection window view
188 PopupSelectXLFD(Widget top)
191 if( xlfdDialog == NULL ){
192 if( (xlfdDialog = CreateSelectXLFD( top )) == NULL ){
196 /* pop up select window */
197 xlfdPopupDialog( xlfdDialog );
204 int mask = FAL_FONT_MASK_DEFINED | FAL_FONT_MASK_UNDEFINED;
206 FalFontDataList *fontlist;
210 if (udc_flag == True) {
211 key.cd_set = udc_val;
212 mask |= FAL_FONT_MASK_CODE_SET;
214 if (sty_flag == True) {
215 key.style.name = sty_val;
216 mask |= FAL_FONT_MASK_STYLE_NAME;
218 if (wls_flag == True) {
219 key.size.w = wls_val;
220 mask |= FAL_FONT_MASK_SIZE_W;
222 if (hls_flag == True) {
223 key.size.h = hls_val;
224 mask |= FAL_FONT_MASK_SIZE_H;
227 if (FalGetFontList(&key, mask, &fontlist) == FAL_ERROR) {
230 if(fontlist->num == 0) {
231 FalFreeFontList(fontlist);
235 for (i=0; i < xlf_count; i++) {
236 XmStringFree(xlf[i]);
240 xlf = (XmString *)XtMalloc(sizeof(XmString) * fontlist->num);
241 for (i=0, f=fontlist->list; i < fontlist->num; i++, f++) {
242 xlf[xlf_count++] = XmStringCreateLocalized(f->xlfdname);
244 FalFreeFontList(fontlist);
252 XtVaGetValues(w, XmNlabelString, &label, NULL);
253 moji = (char *) _XmStringUngenerate(label, NULL, XmMULTIBYTE_TEXT, XmMULTIBYTE_TEXT);
254 if(strncmp(moji, "*", 1) == 0) {
256 } else if(strcmp(moji, CS0) == 0) {
257 udc_val = FAL_FONT_CS0;
259 } else if(strcmp(moji, CS1) == 0) {
260 udc_val = FAL_FONT_CS1;
262 } else if(strcmp(moji, CS2) == 0) {
263 udc_val = FAL_FONT_CS2;
265 } else if(strcmp(moji, CS3) == 0) {
266 udc_val = FAL_FONT_CS3;
273 XtVaSetValues(scrolllist, XmNitems, xlf, XmNitemCount, xlf_count, NULL);
285 XtVaGetValues(w, XmNlabelString, &label, NULL);
286 moji = (char *) _XmStringUngenerate(label, NULL, XmMULTIBYTE_TEXT, XmMULTIBYTE_TEXT);
287 if(strncmp(moji, "*", 1) == 0) {
291 sty_val = XtMalloc(sizeof(char) * (strlen(moji) + 1));
292 strcpy(sty_val, moji);
297 XtVaSetValues(scrolllist, XmNitems, xlf, XmNitemCount, xlf_count, NULL);
305 XtVaGetValues(w, XmNlabelString, &label, NULL);
306 moji = (char *) _XmStringUngenerate(label, NULL, XmMULTIBYTE_TEXT, XmMULTIBYTE_TEXT);
307 if(strncmp(moji, "*", 1) == 0) {
311 wls_val = atoi(moji);
317 XtVaSetValues(scrolllist, XmNitems, xlf, XmNitemCount, xlf_count, NULL);
325 XtVaGetValues(w, XmNlabelString, &label, NULL);
326 moji = (char *) _XmStringUngenerate(label, NULL, XmMULTIBYTE_TEXT, XmMULTIBYTE_TEXT);
327 if(strncmp(moji, "*", 1) == 0) {
331 hls_val = atoi(moji);
337 XtVaSetValues(scrolllist, XmNitems, xlf, XmNitemCount, xlf_count, NULL);
344 int mask = FAL_FONT_MASK_DEFINED | FAL_FONT_MASK_UNDEFINED;
346 FalFontDataList *fontlist;
350 if (sty_flag == True) {
351 key.style.name = sty_val;
352 mask |= FAL_FONT_MASK_STYLE_NAME;
354 if (wls_flag == True) {
355 key.size.w = wls_val;
356 mask |= FAL_FONT_MASK_SIZE_W;
358 if (hls_flag == True) {
359 key.size.h = hls_val;
360 mask |= FAL_FONT_MASK_SIZE_H;
362 if (FalGetFontList(&key, mask, &fontlist) == FAL_ERROR) {
363 for (j=0; j<udc_count; j++)
364 XtSetSensitive(button1[j], False);
367 if(fontlist->num == 0) {
368 for (j=0; j<udc_count; j++)
369 XtSetSensitive(button1[j], False);
370 FalFreeFontList(fontlist);
374 for (j=0; j<udc_count; j++) {
375 for (i=0, f=fontlist->list, found=False; i < fontlist->num; i++, f++) {
376 if(udc[j] == f->cd_set) {
382 XtSetSensitive(button1[j], False);
384 XtSetSensitive(button1[j], True);
386 FalFreeFontList(fontlist);
393 int mask = FAL_FONT_MASK_DEFINED | FAL_FONT_MASK_UNDEFINED;
395 FalFontDataList *fontlist;
399 if (udc_flag == True) {
400 key.cd_set = udc_val;
401 mask |= FAL_FONT_MASK_CODE_SET;
403 if (wls_flag == True) {
404 key.size.w = wls_val;
405 mask |= FAL_FONT_MASK_SIZE_W;
407 if (hls_flag == True) {
408 key.size.h = hls_val;
409 mask |= FAL_FONT_MASK_SIZE_H;
411 if (FalGetFontList(&key, mask, &fontlist) == FAL_ERROR) {
412 for (j=0; j<sty_count; j++)
413 XtSetSensitive(button2[j], False);
416 if(fontlist->num == 0) {
417 for (j=0; j<sty_count; j++)
418 XtSetSensitive(button2[j], False);
419 FalFreeFontList(fontlist);
423 for (j=0; j<sty_count; j++) {
424 for (i=0, f=fontlist->list, found=False; i < fontlist->num; i++, f++) {
425 if(strcmp(sty[j], f->style.name) == 0) {
431 XtSetSensitive(button2[j], False);
433 XtSetSensitive(button2[j], True);
435 FalFreeFontList(fontlist);
442 int mask = FAL_FONT_MASK_DEFINED | FAL_FONT_MASK_UNDEFINED;
444 FalFontDataList *fontlist;
448 if (udc_flag == True) {
449 key.cd_set = udc_val;
450 mask |= FAL_FONT_MASK_CODE_SET;
452 if (sty_flag == True) {
453 key.style.name = sty_val;
454 mask |= FAL_FONT_MASK_STYLE_NAME;
456 if (hls_flag == True) {
457 key.size.h = hls_val;
458 mask |= FAL_FONT_MASK_SIZE_H;
460 if (FalGetFontList(&key, mask, &fontlist) == FAL_ERROR) {
461 for (j=0; j<wls_count; j++)
462 XtSetSensitive(button3[j], False);
465 if(fontlist->num == 0) {
466 for (j=0; j<wls_count; j++)
467 XtSetSensitive(button3[j], False);
468 FalFreeFontList(fontlist);
472 for (j=0; j<wls_count; j++) {
473 for (i=0, f=fontlist->list, found=False; i < fontlist->num; i++, f++) {
474 if(wls[j] == f->size.w) {
480 XtSetSensitive(button3[j], False);
482 XtSetSensitive(button3[j], True);
484 FalFreeFontList(fontlist);
491 int mask = FAL_FONT_MASK_DEFINED | FAL_FONT_MASK_UNDEFINED;
493 FalFontDataList *fontlist;
497 if (udc_flag == True) {
498 key.cd_set = udc_val;
499 mask |= FAL_FONT_MASK_CODE_SET;
501 if (sty_flag == True) {
502 key.style.name = sty_val;
503 mask |= FAL_FONT_MASK_STYLE_NAME;
505 if (wls_flag == True) {
506 key.size.w = wls_val;
507 mask |= FAL_FONT_MASK_SIZE_W;
509 if (FalGetFontList(&key, mask, &fontlist) == FAL_ERROR) {
510 for (j=0; j<hls_count; j++)
511 XtSetSensitive(button4[j], False);
514 if(fontlist->num == 0) {
515 for (j=0; j<hls_count; j++)
516 XtSetSensitive(button4[j], False);
517 FalFreeFontList(fontlist);
521 for (j=0; j<hls_count; j++) {
522 for (i=0, f=fontlist->list, found=False; i < fontlist->num; i++, f++) {
523 if(hls[j] == f->size.h) {
529 XtSetSensitive(button4[j], False);
531 XtSetSensitive(button4[j], True);
533 FalFreeFontList(fontlist);
537 data_sort(int *data, int count)
539 int *p1, *p2, tmp, i;
541 for (; count; count--) {
542 for (i=1, p1=data, p2=data+1; i < count; i++, p1++, p2++) {
556 FalFontDataList *fontlist;
563 extern void Error_message();
565 xlf_count = udc_count = sty_count = wls_count = hls_count = 0;
566 if (FalGetFontList(NULL, FAL_FONT_MASK_DEFINED |
567 FAL_FONT_MASK_UNDEFINED, &fontlist) == FAL_ERROR) {
568 strcpy(err, FAL_ERROR_STR);
569 Error_message((Widget)NULL, err);
572 if(fontlist->num == 0) {
573 FalFreeFontList(fontlist);
574 strcpy(err, resource.mn_no_font);
575 Error_message((Widget)NULL, err);
578 udc = (int *)XtMalloc(sizeof(int) * fontlist->num);
579 sty = (char **)XtMalloc(sizeof(char *) * fontlist->num);
580 wls = (int *)XtMalloc(sizeof(int) * fontlist->num);
581 hls = (int *)XtMalloc(sizeof(int) * fontlist->num);
582 for (i=0, f=fontlist->list; i < fontlist->num; i++, f++) {
583 for (j=0,found=False; j<udc_count; j++) {
584 if(udc[j] == f->cd_set) {
589 if (found == False) {
590 udc[udc_count++] = f->cd_set;
592 for (j=0,found=False; j<sty_count; j++) {
593 if(strcmp(sty[j], f->style.name) == 0) {
598 if (found == False) {
599 sty[sty_count] = XtMalloc(sizeof(char) * (strlen(f->style.name) + 1));
600 strcpy(sty[sty_count++], f->style.name);
602 if (f->size.w != -1) {
603 for (j=0,found=False; j<wls_count; j++) {
604 if(wls[j] == f->size.w) {
609 if (found == False) {
610 wls[wls_count++] = f->size.w;
613 for (j=0,found=False; j<hls_count; j++) {
614 if(hls[j] == f->size.h) {
619 if (found == False) {
620 hls[hls_count++] = f->size.h;
623 FalFreeFontList(fontlist);
625 data_sort(udc, udc_count);
626 data_sort(wls, wls_count);
627 data_sort(hls, hls_count);
629 button1 = (Widget *) XtMalloc(sizeof(Widget) * udc_count);
630 button2 = (Widget *) XtMalloc(sizeof(Widget) * sty_count);
631 button3 = (Widget *) XtMalloc(sizeof(Widget) * wls_count);
632 button4 = (Widget *) XtMalloc(sizeof(Widget) * hls_count);
634 button = XmCreatePushButton(pull1, "*", NULL, 0);
635 XtManageChild(button);
636 XtAddCallback(button, XmNactivateCallback,
637 (XtCallbackProc)udc_call, NULL);
638 for (i=0; i < udc_count; i++) {
639 if(udc[i] == FAL_FONT_CS0)
641 else if(udc[i] == FAL_FONT_CS1)
643 else if(udc[i] == FAL_FONT_CS2)
645 else if(udc[i] == FAL_FONT_CS3)
648 sprintf(tmp, "Codeset %x?", udc[i]);
649 button1[i] = XmCreatePushButton(pull1, tmp, NULL, 0);
650 XtManageChild(button1[i]);
651 XtAddCallback(button1[i], XmNactivateCallback,
652 (XtCallbackProc)udc_call, NULL);
655 button = XmCreatePushButton(pull2, "*", NULL, 0);
656 XtManageChild(button);
657 XtAddCallback(button, XmNactivateCallback,
658 (XtCallbackProc)sty_call, NULL);
659 for (i=0; i < sty_count; i++) {
660 button2[i] = XmCreatePushButton(pull2, sty[i], NULL, 0);
661 XtManageChild(button2[i]);
662 XtAddCallback(button2[i], XmNactivateCallback,
663 (XtCallbackProc)sty_call, NULL);
666 button = XmCreatePushButton(pull3, "*", NULL, 0);
667 XtManageChild(button);
668 XtAddCallback(button, XmNactivateCallback,
669 (XtCallbackProc)wls_call, NULL);
670 for (i=0; i < wls_count; i++) {
671 sprintf(tmp, "%d", wls[i]);
672 button3[i] = XmCreatePushButton(pull3, tmp, NULL, 0);
673 XtManageChild(button3[i]);
674 XtAddCallback(button3[i], XmNactivateCallback,
675 (XtCallbackProc)wls_call, NULL);
678 button = XmCreatePushButton(pull4, "*", NULL, 0);
679 XtManageChild(button);
680 XtAddCallback(button, XmNactivateCallback,
681 (XtCallbackProc)hls_call, NULL);
682 for (i=0; i < hls_count; i++) {
683 sprintf(tmp, "%d", hls[i]);
684 button4[i] = XmCreatePushButton(pull4, tmp, NULL, 0);
685 XtManageChild(button4[i]);
686 XtAddCallback(button4[i], XmNactivateCallback,
687 (XtCallbackProc)hls_call, NULL);
693 CreateSelectXLFD(Widget top)
700 Widget frame, row1, label1, row2, cas1, cas2, cas3, cas4;
702 udc_flag = sty_flag = wls_flag = hls_flag = False;
708 XtSetArg( args[n], XmNautoUnmanage, False ) ; n++ ;
709 XtSetArg( args[n], XmNnoResize, True ) ; n++ ;
710 XtSetArg( args[n], XmNminimizeButtons, True ) ; n++ ;
711 xms = XmStringCreateLocalized( resource.exec_label ) ;
712 XtSetArg( args[n], XmNokLabelString, xms ) ; n++ ;
713 xms1 = XmStringCreateLocalized( resource.quit_label) ;
714 XtSetArg( args[n], XmNhelpLabelString, xms1 ) ; n++ ;
715 XtSetArg( args[n], XmNtitle, resource.l_open_title ) ; n++ ;
716 editW = XmCreateTemplateDialog( top, "open_dialog", args, n );
718 XmStringFree( xms ) ;
719 XmStringFree( xms1 ) ;
722 pull1 = XmCreatePulldownMenu(toplevel, "pull", args, n);
723 pull2 = XmCreatePulldownMenu(toplevel, "pull", args, n);
724 pull3 = XmCreatePulldownMenu(toplevel, "pull", args, n);
725 pull4 = XmCreatePulldownMenu(toplevel, "pull", args, n);
728 xlfdWform = XmCreateRowColumn( editW, "BaseForm", args, n );
729 XtManageChild( xlfdWform );
732 frame = XmCreateFrame( xlfdWform, "frame", args, n);
733 XtManageChild( frame );
736 row1 = XmCreateRowColumn( frame, "row", args, n );
737 XtManageChild( row1 );
740 str = XmStringCreateLocalized(resource.l_selectitem) ;
741 XtSetArg(args[n], XmNlabelString, str); n++;
742 label1 = XmCreateLabel( row1, "SelectItems", args, n);
743 XtManageChild( label1 );
747 row2 = XmCreateRowColumn( row1, "row", args, n );
748 XtManageChild( row2 );
751 str = XmStringCreateLocalized(resource.l_codeset) ;
752 XtSetArg(args[n], XmNlabelString, str); n++;
753 XtSetArg(args[n], XmNsubMenuId, pull1); n++;
754 cas1 = XmCreateOptionMenu( row2, "CodeSet", args, n );
755 XtManageChild( cas1 );
756 XtAddCallback(XmOptionButtonGadget(cas1), XmNcascadingCallback,
757 (XtCallbackProc)button_set1, NULL);
761 str = XmStringCreateLocalized(resource.l_style) ;
762 XtSetArg(args[n], XmNlabelString, str); n++;
763 XtSetArg(args[n], XmNsubMenuId, pull2); n++;
764 cas2 = XmCreateOptionMenu( row2, "Style", args, n );
765 XtAddCallback(XmOptionButtonGadget(cas2), XmNcascadingCallback,
766 (XtCallbackProc)button_set2, NULL);
767 XtManageChild( cas2 );
771 str = XmStringCreateLocalized(resource.l_width) ;
772 XtSetArg(args[n], XmNlabelString, str); n++;
773 XtSetArg(args[n], XmNsubMenuId, pull3); n++;
774 cas3 = XmCreateOptionMenu( row2, "Width", args, n );
775 XtManageChild( cas3 );
776 XtAddCallback(XmOptionButtonGadget(cas3), XmNcascadingCallback,
777 (XtCallbackProc)button_set3, NULL);
781 str = XmStringCreateLocalized(resource.l_height) ;
782 XtSetArg(args[n], XmNlabelString, str); n++;
783 XtSetArg(args[n], XmNsubMenuId, pull4); n++;
784 cas4 = XmCreateOptionMenu( row2, "Height", args, n );
785 XtManageChild( cas4 );
786 XtAddCallback(XmOptionButtonGadget(cas4), XmNcascadingCallback,
787 (XtCallbackProc)button_set4, NULL);
794 XtSetArg(args[n], XmNvisibleItemCount, 10) ; n++ ;
795 XtSetArg(args[n], XmNlistSizePolicy, XmCONSTANT) ; n++ ;
796 XtSetArg(args[n], XmNscrollBarDisplayPolicy, XmSTATIC) ; n++ ;
797 XtSetArg(args[n], XmNselectionPolicy, XmSINGLE_SELECT) ; n++ ;
798 XtSetArg(args[n], XmNitems, xlf) ; n++ ;
799 XtSetArg(args[n], XmNitemCount, xlf_count) ; n++ ;
800 scrolllist = XmCreateScrolledList(xlfdWform, "scrolllist", args, n);
801 XtManageChild(scrolllist);
807 XtAddCallback(editW, XmNokCallback, (XtCallbackProc)OpenWindowCB, NULL);
808 XtAddCallback(editW, XmNokCallback, (XtCallbackProc)ReadCB, NULL);
809 XtAddCallback(editW, XmNhelpCallback,
810 (XtCallbackProc)OpenCancelCB, NULL);