selectxlfd.c 24 KB

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