/* * CDE - Common Desktop Environment * * Copyright (c) 1993-2012, The Open Group. All rights reserved. * * These libraries and programs are free software; you can * redistribute them and/or modify them under the terms of the GNU * Lesser General Public License as published by the Free Software * Foundation; either version 2 of the License, or (at your option) * any later version. * * These libraries and programs are distributed in the hope that * they will be useful, but WITHOUT ANY WARRANTY; without even the * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR * PURPOSE. See the GNU Lesser General Public License for more * details. * * You should have received a copy of the GNU Lesser General Public * License along with these libraries and programs; if not, write * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth * Floor, Boston, MA 02110-1301 USA */ /* $XConsortium: selectxlfd.c /main/3 1996/10/14 14:45:17 barstow $ */ /* * All Rights Reserved, Copyright (c) FUJITSU LIMITED 1995 */ #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include "FaLib.h" #include "falxlfd.h" #include "selectxlfd.h" #include "excutil.h" char *shell_n[] = { "pop0", "pop1", "pop2", "pop3" } ; char *list_n[] = { "list0", "list1", "list2", "list3" } ; #ifdef DEBUG #undef Dprintf #define Dprintf fprintf #else #define Dprintf #endif /* DEBUG */ /* * There is no public header file for this function (only an * internal header XmStringI.h). */ extern XtPointer _XmStringUngenerate (XmString string, XmStringTag tag, XmTextType tag_type, XmTextType output_type); extern Rsrc resource; extern Exc_data *ed; extern ListData *ld; extern fal_utyerror; extern fal_utyderror; extern fal_utyexists; extern char *maintitle; FalFontID fid; /* * parameters */ char *fullPathName = NULL ; FalFontDataList *font_L ; FalxCodeList *CodeList ; FalxStyleList *StyleList ; FalxSizeList *SizeList ; FalxUdcArea *UdcArea ; int SelectedOffset ; int UdcAreaCount ; int getmask ; FalxFontDataBuff KeyBuff ; void PopupSelectXLFD() ; Widget xlfdDialog, xlfdWform, slctBLabel[BUTTONITEMS],slctBText[BUTTONITEMS], slctButton[BUTTONITEMS], listPop[BUTTONITEMS], listW[BUTTONITEMS], separatorW, errorMD, msgBox ; extern Widget cpyDialog ; extern Widget toplevel; /* * tmp */ int fontcheck(char *fontfile, char *mode) /* * If fontfile can't be opend, return -1. * If fontfile is editted by other UDC client, return 1. * normary return 0. */ { int chk_fd; if (strcmp(mode, "r") == 0) { if ((chk_fd = open(fontfile, O_RDONLY)) < 0) { return (-1); } } else if (strcmp(mode, "w") == 0) { if ((chk_fd = open(fontfile, O_RDWR)) < 0) { return (-1); } } if (isLock(chk_fd) == 1) { close(chk_fd); return(1); } close(chk_fd); return (0); } void setallcode(ListData *ld) { int i, code, codenum; int *codep; int code1, code2; codenum = 0; for (i = 0; i < UdcAreaCount; i++) { codenum += (abs(UdcArea[i].udc_end - UdcArea[i].udc_start) + 1); } ld->allcode = (int *) calloc(codenum, sizeof(int)); ld->allcode_num = codenum; codep = ld->allcode; for (i = 0; i < UdcAreaCount; i++) { code1 = smaller(UdcArea[i].udc_start, UdcArea[i].udc_end); code2 = bigger(UdcArea[i].udc_start, UdcArea[i].udc_end); for (code = code1; code <= code2; code++) { *codep = code; codep++; } } } FalFontID openfont(void) { int protect_key = FAL_FONT_DISPLAY; int codeset; FalFontID fontid; fontid = NULL; codeset = font_L->list[0].cd_set; if ((fontid = FalOpenFont(fullPathName, protect_key, codeset)) == FAL_ERROR) { fprintf(stderr, "FalOpenFont error\n"); return ((FalFontID) NULL); } return (fontid); } void makelist(ListData *ld) { char *pattern; int code; int *existcodep, *allcodep; int existcode_num; int i; /* FalFontinfo fontinfo;*/ /* FalQueryFont(fid, &fontinfo);*/ ld->existcode = (int *) calloc(ld->allcode_num, sizeof(int)); existcodep = ld->existcode ; allcodep = ld->allcode; existcode_num = 0; for (i = 0; i < ld->allcode_num; i++) { code = *allcodep; pattern = FalReadFont(fid, code, NULL, NULL); if (fal_utyexists == 0) { *existcodep = *allcodep; existcodep++; existcode_num++; } allcodep++; } ld->existcode_num = existcode_num; } void setexistcode(ListData *ld) { int *codep, *allcodep; int i; /* open font */ fid = openfont(); makelist(ld); /* close font */ if (fid != NULL) FalCloseFont(fid); } char i2c(int num) { char c; if ((0 <= num) && (num <= 9)) c = '0' + num; else if ((10 <= num) && (num <= 15)) c = 'a' + (num - 10); else fprintf(stderr,"error in i2c\n"); return c; } char *i2s(int code) { char buf[8]; char *number; char *cp; int i; int tmp; int len; tmp = code; for (i = 0; ; i++) { if (tmp < 16) { buf[i] = i2c(tmp); buf[i+1] = NULL; break; } buf[i] = i2c(tmp % 16); tmp = tmp / 16; } len = strlen(buf); number = (char *) calloc(len+3, sizeof(char)); cp = number; memcpy(cp, "0x", 2); cp += 2; for (i = len - 1; i >= 0; i--) { *cp = buf[i]; cp++; } *cp = NULL; return (number); } void setexistcode_c(ListData *ld) { int i; char **code_cp; int *codep; if (ld->existcode_num == 0) { return; } ld->existcode_c = (char **) calloc(ld->existcode_num, sizeof(char *)); code_cp = ld->existcode_c; codep = ld->existcode; for (i = 0; i < ld->existcode_num; i++) { *code_cp = i2s(*codep); code_cp++; codep++; } } void getexistcode(ListData *ld) { setallcode(ld); setexistcode(ld); setexistcode_c(ld); } /**************************************************************** * common functions * ***************************************************************/ /* * pop up and down dialog box */ void xlfdPopupDialog(Widget w) { if (! XtIsManaged(w)) XtManageChild(w); else XRaiseWindow(XtDisplayOfObject(w), XtWindow(XtParent(w))); } void xlfdPopdownDialog(Widget w) { if (XtIsManaged(w)){ XtUnmanageChild(w); } } /* * get pixel width */ Dimension GetPixelWidth(Widget w, int columns, Dimension *width) { Arg args[1] ; XtSetArg( args[0], XmNwidth, width ) ; XtGetValues( w , args, 1 ) ; return( *width / (Dimension)columns ) ; } /**************************************************************** * callbacks * ***************************************************************/ void quit(Widget w, caddr_t *client_data, caddr_t *call_data) { char *msg; int ans; msg = GETMESSAGE(6, 2, "Do you want to terminate udcexchange?"); AskUser(ed->toplevel, ed, msg, &ans, "question"); if (ans == 1) {/* terminate ok */ FalxFreeCodeList( CodeList ) ; FalxFreeStyleList( StyleList ) ; FalxFreeSizeList( SizeList ) ; FalxFreeFontList( font_L ) ; excterminate(ed); } } /* * Unmanage widgets */ int ClearText(int num, Widget *slctBText) { int i ; /* toggle button unset */ for( i=0; inum ){ XmTextSetString( slctBText[i], "" ); } } return ; } int ClearButtons(int num, Widget *slctButton) { int i, cnt ; Boolean isSet ; Arg args[5] ; /* toggle button unset */ for( i=0; iitem, NULL, XmMULTIBYTE_TEXT, XmMULTIBYTE_TEXT); if (str) { XmTextSetString(slctBText[num], str); } #if 0 /* set key data */ if( SetKeyBuff( num, str ) ){ exit(-1) ; } #endif /* 0 */ if( XtIsManaged( listPop[num] ) ) XtUnmanageChild( listPop[num] ); } void OpenWindow(Widget w, caddr_t client_data, caddr_t *call_data) { int r ; int i ; int ans; char *msg; char *msg1; char *msg2; char *msg3; char *str, buff[512] ; msg = GETMESSAGE(6, 4, "No UDCs exist in this font"); msg1 = GETMESSAGE(6, 6, "XLFD name isn't selected"); msg2 = GETMESSAGE(6, 8, "Can't open the font file"); msg3 = GETMESSAGE(6, 10, "The font file is used by other UDC client."); /* get font file name (str: XLFD name) */ str = XmTextGetString( slctBText[0] ); if (( str == NULL ) || (strcmp(str, "") == 0)) { AskUser(w, ed, msg1, &ans, "error"); return; } if( fullPathName != NULL ){ free( fullPathName ) ; } SelectedOffset = FalxSearchFontFileName( str, font_L, buff ) ; if( SelectedOffset < 0 ){ exit(-1) ; } if( (fullPathName = strdup( buff )) == NULL ){ exit(-1) ; } UdcAreaCount = FalxGetGlyphIndexInfo( str, font_L, &UdcArea ) ; if( UdcAreaCount < 0 ){ exit(-1) ; } if( fullPathName != NULL ){ Dprintf( stderr, "OpenWindow() : full path name = %s\n", fullPathName ); } for( i=0; ixlfdname = strdup(str)) == NULL) { exit (-1); } if ((ed->fontfile = strdup(fullPathName)) == NULL) { exit (-1); } /* getxlfd(ed);*/ /* initialize ld */ if ((ld = (ListData *) malloc(sizeof(ListData))) == NULL) { excerror(ed, EXCERRMALLOC, "selcharcd", "exit"); } memset(ld, 0x00, sizeof(ListData)); ld->ed = ed; if (ed->function == EXPORT) { r = fontcheck(ed->fontfile, "r"); if (r == -1) { /* file open error */ AskUser(ld->ed->toplevel, ld->ed, msg2, &ans, "error"); return; } else if (r == 1) { /* file is being editted by other UDC client */ AskUser(ld->ed->toplevel, ld->ed, msg3, &ans, "error"); return; } /* get existing UDC code */ getexistcode(ld); if (ld->existcode_num == 0) { AskUser(ld->ed->toplevel, ld->ed, msg, &ans, "error"); return; } XtUnmanageChild(xlfdDialog); selcharcd(ed); } else if (ed->function == IMPORT) { r = fontcheck(ed->fontfile, "w"); if (r == -1) { /* file open error */ AskUser(ld->ed->toplevel, ld->ed, msg2, &ans, "error"); return; } else if (r == 1) { /* file is being editted by other UDC client */ AskUser(ld->ed->toplevel, ld->ed, msg3, &ans, "error"); return; } /* get existing UDC code */ getexistcode(ld); XtUnmanageChild(xlfdDialog); getcharcd(ed); } } /**************************************************************** * functions for create window view ****************************************************************/ #define SetLabel( cnt ){ \ switch( cnt ){ \ case 0 : buf = resource.xlfd_label ; break ; \ case 1 : buf = resource.code_label ; break ; \ case 2 : buf = resource.style_label; break ; \ case 3 : buf = resource.size_label ; break ; \ } \ xms = XmStringCreateLocalized( buf ); \ } int CreateXLFDLabelAndText( Widget owner, Widget *slctBLabel, Widget *slctBText, Widget *slctButton) { Widget _slctBLabel ; Widget _slctBText ; Widget _slctButton ; int i, j; Arg args[16]; char *buf ; XmString xms ; /* * create XLFD titles */ i = 0; XtSetArg( args[i], XmNx, 20 ) ; i++ ; XtSetArg( args[i], XmNheight, 20 ) ; i++ ; XtSetArg( args[i], XmNtopAttachment, XmATTACH_FORM ) ; i++ ; XtSetArg( args[i], XmNtopOffset, 20 ) ; i++ ; /* _slctBLabel = XmCreateLabelGadget( owner , "xlfdlabel", args, i ); */ _slctBLabel = XmCreateLabel( owner , "xlfdlabel", args, i ); XtManageChild( _slctBLabel ); /* * create text fields to display XLFD font name */ i = 0; XtSetArg( args[i], XmNleftAttachment, XmATTACH_FORM ) ; i++ ; XtSetArg( args[i], XmNleftOffset, 20 ) ; i++ ; XtSetArg( args[i], XmNtopAttachment, XmATTACH_WIDGET ); i++ ; XtSetArg( args[i], XmNtopOffset, 5 ) ; i++ ; XtSetArg (args[i], XmNtopWidget, _slctBLabel ); i++; XtSetArg( args[i], XmNcolumns, XLFD_COLUMNS ) ; i++ ; XtSetArg( args[i], XmNspacing, 0 ) ; i++ ; XtSetArg( args[i], XmNeditMode, XmSINGLE_LINE_EDIT ) ; i++ ; XtSetArg( args[i], XmNscrollBarDisplayPolicy, XmAS_NEEDED ) ; i++ ; XtSetArg( args[i], XmNscrollingPolicy, XmAPPLICATION_DEFINED ) ; i++ ; /* XtSetArg( args[i], XmNscrollingPolicy, XmAUTOMATIC ) ; i++ ; XtSetArg( args[i], XmNlistSizePolicy, XmCONSTANT ) ; i++ ; XtSetArg( args[i], XmNwidth, 600 ) ; i++ ; XtSetArg( args[i], XmNfontList, fixed ) ; i++ ; XtSetArg( args[i], XmNeditable, True ) ; i++ ; XtSetArg( args[i], XmNlistSizePolicy, XmVARIABLE ) ; i++ ; */ _slctBText = XmCreateScrolledText( owner , "xlfdtext", args, i ); XtManageChild( _slctBText ); /* * create XLFD select buttons */ i = 0; XtSetArg( args[i], XmNindicatorType, XmONE_OF_MANY ) ; i++ ; XtSetArg (args[i], XmNtopWidget, _slctBText ); i++; XtSetArg( args[i], XmNtopAttachment, XmATTACH_OPPOSITE_WIDGET ) ; i++ ; XtSetArg( args[i], XmNtopOffset, 15 ) ; i++ ; XtSetArg( args[i], XmNleftAttachment, XmATTACH_WIDGET ) ; i++ ; XtSetArg( args[i], XmNleftWidget, _slctBText ) ; i++ ; XtSetArg( args[i], XmNleftOffset, 5 ) ; i++ ; /* WIDTH */ XtSetArg( args[i], XmNrightAttachment, XmATTACH_FORM ) ; i++ ; XtSetArg( args[i], XmNrightOffset, 5 ) ; i++ ; /* WIDTH */ xms = XmStringCreateLocalized( "" ); XtSetArg( args[i], XmNlabelString, xms ) ; i++ ; /* _slctButton = XmCreateToggleButtonGadget( owner , "xlfdbtn", args, i); */ _slctButton = XmCreateToggleButton( owner , "xlfdbtn", args, i); XtManageChild( _slctButton ); *slctBLabel = _slctBLabel ; *slctBText = _slctBText ; *slctButton = _slctButton ; } int CreateOtherLabelAndText( int num, Widget owner, Widget baseForm, Widget *slctBLabel, Widget topW, Widget *slctBText, Widget *slctButton) { Widget _slctBLabel ; Widget _slctBText ; Widget _slctButton ; int i, j; Arg args[16]; char *buf ; XmString xms ; if( num < 1 ) return(0) ; /* * create key titles */ i = 0; XtSetArg ( args[i], XmNtopWidget, (num==1) ? baseForm : topW ); i++; XtSetArg( args[i], XmNx, 20 ) ; i++ ; XtSetArg( args[i], XmNheight, 20 ) ; i++ ; XtSetArg( args[i], XmNtopAttachment, XmATTACH_WIDGET ) ; i++ ; /* DEBUG XtSetArg( args[i], XmNtopOffset, 20 ) ; i++ ; */ XtSetArg( args[i], XmNtopOffset, 36 ) ; i++ ; SetLabel(num) ; XtSetArg( args[i], XmNlabelString, xms ) ; i++ ; /* _slctBLabel = XmCreateLabelGadget( owner , "label", args, i); */ _slctBLabel = XmCreateLabel( owner , "label", args, i); XtManageChild( _slctBLabel ); /* * create text fields to display selected keys */ i = 0; XtSetArg( args[i], XmNtopAttachment, XmATTACH_OPPOSITE_WIDGET ) ; i++ ; XtSetArg( args[i], XmNtopOffset, -5 ) ; i++ ; XtSetArg (args[i], XmNtopWidget, _slctBLabel ); i++; XtSetArg( args[i], XmNrightAttachment, XmATTACH_OPPOSITE_WIDGET ) ; i++ ; XtSetArg( args[i], XmNrightOffset, 0 ) ; i++ ; XtSetArg (args[i], XmNrightWidget, baseForm ); i++; XtSetArg( args[i], XmNcolumns, KEY_COLUMNS ) ; i++ ; XtSetArg( args[i], XmNspacing, 0 ) ; i++ ; XtSetArg( args[i], XmNeditMode, XmSINGLE_LINE_EDIT ) ; i++ ; XtSetArg( args[i], XmNscrollBarDisplayPolicy, XmAS_NEEDED ) ; i++ ; XtSetArg( args[i], XmNscrollingPolicy, XmAPPLICATION_DEFINED ) ; i++ ; /* XtSetArg( args[i], XmNscrollingPolicy, XmAUTOMATIC ) ; i++ ; XtSetArg( args[i], XmNlistSizePolicy, XmCONSTANT ) ; i++ ; XtSetArg( args[i], XmNfontList, fixed ) ; i++ ; XtSetArg( args[i], XmNlistSizePolicy, XmVARIABLE ) ; i++ ; */ if( num==BUTTONITEMS-1 ) _slctBText = XmCreateText( owner , "text" , args, i ); else _slctBText = XmCreateScrolledText( owner , "text" , args, i ); XtManageChild( _slctBText ); /* * create select buttons */ i = 0; XtSetArg( args[i], XmNindicatorType, XmONE_OF_MANY ) ; i++ ; XtSetArg( args[i], XmNtopAttachment, XmATTACH_OPPOSITE_WIDGET ) ; i++ ; XtSetArg( args[i], XmNtopOffset, 5 ) ; i++ ; XtSetArg (args[i], XmNtopWidget, _slctBLabel ); i++; XtSetArg( args[i], XmNleftAttachment, XmATTACH_WIDGET ) ; i++ ; XtSetArg( args[i], XmNleftWidget, _slctBText ) ; i++ ; XtSetArg( args[i], XmNleftOffset, 5 ) ; i++ ; /* WIDTH */ xms = XmStringCreateLocalized( "" ); XtSetArg( args[i], XmNlabelString, xms ) ; i++ ; /* _slctButton = XmCreateToggleButtonGadget( owner , "button", args, i); */ _slctButton = XmCreateToggleButton( owner , "button", args, i); XtManageChild( _slctButton ); *slctBLabel = _slctBLabel ; *slctBText = _slctBText ; *slctButton = _slctButton ; } /* * create pop up lists */ Widget xlfdCreateScrolledList (Widget owner, char *name, Arg *args, int n) { Widget listW ; XtSetArg( args[n], XmNselectionPolicy, XmSINGLE_SELECT ) ;n++ ; XtSetArg( args[n], XmNlistSpacing, 4 ) ; n++ ; XtSetArg( args[n], XmNlistSizePolicy, XmCONSTANT ) ; n++ ; XtSetArg( args[n], XmNscrollBarDisplayPolicy, XmAS_NEEDED ) ; n++ ; listW = XmCreateScrolledList( owner, name, args, n ); XtManageChild( listW ); return( listW ); } /* * create selection window view */ void PopupSelectXLFD(Widget top) { int n, i, j; Arg args[16]; char *buf ; XmString xms ; Dimension pix, xwidth, kwidth ; if( xlfdDialog == NULL ){ /* * create base window */ n = 0 ; XtSetArg( args[n], XmNautoUnmanage, False ) ; n++ ; XtSetArg( args[n], XmNtitle, maintitle ) ; n++ ; XtSetArg( args[n], XmNnoResize, True ) ; n++ ; xms = XmStringCreateLocalized( resource.exec_label ) ; XtSetArg( args[n], XmNokLabelString, xms ) ; n++ ; xms = XmStringCreateLocalized( resource.quit_label) ; XtSetArg( args[n], XmNhelpLabelString, xms ) ; n++ ; Dprintf( stdout, "(PopupSelectXLFD)XmCreateTemplateDialog: start\n" ) ; xlfdDialog = XmCreateTemplateDialog( top, "SelectDialog", args, n ); Dprintf( stdout, "(PopupSelectXLFD)XmCreateTemplateDialog: end\n" ) ; n = 0 ; xlfdWform = XmCreateForm( xlfdDialog, "BaseForm", args, n ); XtManageChild( xlfdWform ); /* * create XLFD columns */ Dprintf( stdout, "(PopupSelectXLFD)CreateXLFDLabelAndText : start\n" ) ; CreateXLFDLabelAndText( xlfdWform , &slctBLabel[0], &slctBText[0], &slctButton[0] ) ; n = 0 ; SetLabel(0) ; XtSetArg( args[n], XmNlabelString, xms ) ; n++ ; XtSetValues( slctBLabel[0], args, n ) ; Dprintf( stdout, "(PopupSelectXLFD)CreateXLFDLabelAndText : end\n" ) ; /* * create other key columns */ Dprintf( stdout, "(PopupSelectXLFD)CreateOtherLabelAndText :start\n" ) ; for( j=1; j