home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / x / volume8 / xfig2.8 / part05 / printfonts.c < prev   
Encoding:
C/C++ Source or Header  |  1990-07-02  |  5.2 KB  |  185 lines

  1. /* 
  2.  *    FIG : Facility for Interactive Generation of figures
  3.  *
  4.  *    Added by Brian V. Smith
  5.  *
  6.  *    %W%    %G%
  7. */
  8. #include "fig.h"
  9. #include "const.h"
  10. #include "resources.h"
  11. #include "func.h"
  12. #include "psfonts.h"    /* printer font names */
  13.  
  14. /********************  global variables  ***************************/
  15.  
  16. extern    int    font_button;        /* font number */
  17. extern    char    *font_menu_bits[];
  18. extern    Pixmap    font_menu_bitmaps[];
  19. extern    struct    _fstruct  fontnames[];    /* font names */
  20.  
  21. /* GLOBAL */
  22.  
  23. int    *font_sel;        /* pointer to store font selected from popup */
  24. TOOL    image_widget;        /* which widget to store image of font in */
  25.  
  26. /********************  local variables  ***************************/
  27.  
  28. static MENUITEM fontmenu_items[NUMFONTS];
  29.  
  30. static Arg    fontmenu_args[] =
  31. {
  32.     { XtNvSpace, (XtArgVal) 1 },
  33. };
  34.  
  35. extern void fontpane_select();
  36.  
  37. static XtCallbackRec    pane_callbacks[] =
  38. {
  39.     { fontpane_select, NULL },
  40.     { NULL, NULL },
  41. };
  42.  
  43. static Arg      main_pane_args[] =
  44. {
  45.     /* 0 */ { XtNlabel, (XtArgVal)"        " },
  46.     /* 1 */ { XtNwidth, (XtArgVal) FONT_PANE_WIDTH },
  47. };
  48.  
  49. static Arg      pane_args[] =
  50. {
  51.     /* 0 */ { XtNwidth, (XtArgVal) FONT_PANE_WIDTH },
  52.     /* 1 */ { XtNheight, (XtArgVal) 20 },
  53.     /* 2 */ { XtNcallback, (XtArgVal)pane_callbacks },
  54.     /* 3 */ { XtNbitmap, (XtArgVal) NULL },
  55.     /* 4 */ { XtNinternalWidth, (XtArgVal) 0 },    /* space between pixmap and edge */
  56.     /* 5 */ { XtNinternalHeight, (XtArgVal) 0 },
  57.     /* 6 */ { XtNresize, (XtArgVal) FALSE },    /* don't allow resize */
  58. };
  59.  
  60. static Arg      psfont_args[] =
  61. {
  62.     /* 0 */ { XtNwidth, (XtArgVal) FONT_PANE_WIDTH },
  63.     /* 1 */ { XtNheight, (XtArgVal) MSG_HEIGHT },    /* same height as message panel */
  64.     /* 2 */ { XtNfromHoriz, (XtArgVal) NULL },    /* left side of main form */
  65.     /* 3 */ { XtNhorizDistance, (XtArgVal) 1 },
  66.     /* 4 */ { XtNfromVert, (XtArgVal) NULL },
  67.     /* 5 */ { XtNvertDistance, (XtArgVal) -1 },    /* dist from canvas_sw window */
  68.     /* 6 */ { XtNbitmap, (XtArgVal) NULL },
  69.     /* 8 */ { XtNinternalWidth, (XtArgVal) 0 },    /* space between pixmap and edge */
  70.     /* 8 */ { XtNinternalHeight, (XtArgVal) 0 },
  71.     /* 9 */ { XtNleft, (XtArgVal) XtChainLeft },
  72.     /*10 */ { XtNright, (XtArgVal) XtChainLeft },
  73. };
  74.  
  75. static    TOOL    fontpanes;
  76. static    TOOL    fontpane[NUMFONTS];
  77.  
  78. init_fontmenu(tool)
  79.     TOOL            tool;
  80. {
  81.     TOOL            title;
  82.     register int        i;
  83.     register MENUITEM    *mi;
  84.     XtTranslations        popdown_actions, pane_actions;
  85.  
  86.     fontmenu = XtCreatePopupShell("font_menu", overrideShellWidgetClass, tool,
  87.         fontmenu_args, XtNumber(fontmenu_args));
  88.     popdown_actions = XtParseTranslationTable(
  89.         "<Btn1Up>:MenuPopdown()\n");
  90.     XtOverrideTranslations(fontmenu, popdown_actions);
  91.  
  92.     fontpanes = XtCreateManagedWidget("menu", boxWidgetClass, fontmenu, fontmenu_args,
  93.         XtNumber(fontmenu_args));
  94.     pane_actions = XtParseTranslationTable(
  95.         "<EnterWindow>:set()\n\
  96.         <Btn1Up>:notify()unset()\n");
  97.     for (i = 0; i < NUMFONTS; i++)
  98.     {
  99.         fontmenu_items[i].type = MENU_IMAGESTRING;    /* put the fontnames in menu */
  100.         fontmenu_items[i].label = fontnames[i].psfont;
  101.         fontmenu_items[i].info = (caddr_t) i;        /* index for font # */
  102.     }
  103.     
  104.     main_pane_args[0].value = (XtArgVal)"Printer Fonts";
  105.     title = XtCreateManagedWidget("title", labelWidgetClass,
  106.                    fontpanes, main_pane_args, XtNumber(main_pane_args));
  107.  
  108.     /* create the first pane */
  109.     mi = &fontmenu_items[0];
  110.     pane_callbacks[0].closure = (caddr_t)mi;
  111.  
  112.     fontpane[0] = XtCreateManagedWidget("pane", commandWidgetClass,
  113.                      fontpanes, pane_args, XtNumber(pane_args));
  114.     XtOverrideTranslations(fontpane[0], pane_actions);
  115.  
  116.  
  117.     for (i = 1; i < NUMFONTS; ++i)
  118.     {
  119.         mi = &fontmenu_items[i];
  120.         pane_callbacks[0].closure = (caddr_t)mi;
  121.         fontpane[i] = XtCreateManagedWidget("pane", commandWidgetClass,
  122.             fontpanes, pane_args, XtNumber(pane_args));
  123.         XtOverrideTranslations(fontpane[i], pane_actions);
  124.     }
  125.  
  126.     /* Now set up the font indicator window */
  127.  
  128.     /* position */
  129.     psfont_args[4].value = (XtArgVal)canvas_sw;    /* just below the canvas window */
  130.     psfont = XtCreateManagedWidget("font_indicator", labelWidgetClass, tool,
  131.         psfont_args, XtNumber(psfont_args));
  132.     return (1);
  133. }
  134.  
  135. /* create the bitmaps for the font menu */
  136.  
  137. setup_fontmenu()
  138.     {
  139.     register int    i;
  140.  
  141.     /* Create the bitmaps */
  142.  
  143.     for (i=0; i<NUMFONTS; i++)
  144.         font_menu_bitmaps[i] = XCreateBitmapFromData(tool_d,XtWindow(psfont),
  145.         font_menu_bits[i], FONT_PANE_WIDTH, FONT_PANE_HEIGHT);
  146.     psfont_args[6].value = (XtArgVal) font_menu_bitmaps[0];
  147.     XtSetValues(psfont, &psfont_args[6], 1);    /* show default font in window */
  148.  
  149.     /* Store the bitmaps in the menu panes */
  150.     for (i=0; i< NUMFONTS; i++)
  151.         {
  152.         pane_args[3].value = (XtArgVal) font_menu_bitmaps[i];
  153.         XtSetValues(fontpane[i], &pane_args[3], 1);    /* bitmap */
  154.         }
  155.     }
  156.  
  157. /* At this point (called from popup_fonts()), we have the font menu windows 
  158.    to work with so we can define the cursor */
  159.  
  160. static int cursinit = 0;
  161.  
  162. setup_fontmenu_cursor()
  163.     {
  164.     if (cursinit)        /* already defined */
  165.         return;
  166.     cursinit = 1;
  167.     /* Define the cursor for the main menu form */
  168.     XDefineCursor(tool_d, XtWindow(fontpanes), (Cursor)arrow_cursor.bitmap);
  169.     }
  170.     
  171. void fontpane_select(widget, mi)
  172. TOOL widget;
  173. MENUITEM *mi;
  174. {
  175.     char *    font_name = mi->label;
  176.     Arg    args[1];
  177.  
  178.     *font_sel = (int) mi->info;    /* set current font to one selected */
  179.     put_msg("Font: %s",font_name);
  180.     /* put image of font in indicator window */
  181.     XtSetArg(args[0], XtNbitmap, font_menu_bitmaps[*font_sel]);
  182.     XtSetValues(image_widget, args, ONE);
  183.     XtPopdown(fontmenu);
  184.     }
  185.