home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / x / volume19 / xfig / part08 / w_fontpanel.c < prev   
Encoding:
C/C++ Source or Header  |  1993-05-27  |  9.8 KB  |  299 lines

  1. /*
  2.  * FIG : Facility for Interactive Generation of figures
  3.  * Copyright (c) 1991 by Brian V. Smith
  4.  *
  5.  * "Permission to use, copy, modify, distribute, and sell this software and its
  6.  * documentation for any purpose is hereby granted without fee, provided that
  7.  * the above copyright notice appear in all copies and that both the copyright
  8.  * notice and this permission notice appear in supporting documentation. 
  9.  * No representations are made about the suitability of this software for 
  10.  * any purpose.  It is provided "as is" without express or implied warranty."
  11.  */
  12.  
  13. #include "fig.h"
  14. #include "figx.h"
  15. #include "resources.h"
  16. #include "u_fonts.h"        /* printer font names */
  17. #include "w_setup.h"
  18. #include "w_util.h"
  19.  
  20. /********************  global variables     ***************************/
  21.  
  22. extern char    *psfont_menu_bits[];
  23. extern char    *latexfont_menu_bits[];
  24. extern Pixmap    psfont_menu_bitmaps[];
  25. extern Pixmap    latexfont_menu_bitmaps[];
  26. extern Atom    wm_delete_window;
  27. extern struct _fstruct ps_fontinfo[];    /* font names */
  28. extern struct _fstruct latex_fontinfo[];    /* font names */
  29.  
  30. /* LOCAL VARIABLES */
  31.  
  32. static int     *font_ps_sel;    /* ptr to store selected ps font in */
  33. static int     *font_latex_sel; /* ptr to store selected latex font */
  34. static int     *flag_sel;    /* pointer to store ps/latex flag */
  35. static TOOL    font_widget;    /* widget adr to store font image in */
  36. static int    (*font_setimage) ();
  37.  
  38. /********************  local variables    ***************************/
  39.  
  40. static MenuItemRec ps_fontmenu_items[NUM_PS_FONTS + 1];
  41. static MenuItemRec latex_fontmenu_items[NUM_LATEX_FONTS];
  42.  
  43. static void    fontpane_select();
  44. static void    fontpane_cancel();
  45. static void    fontpane_swap();
  46.  
  47. static XtCallbackRec pane_callbacks[] =
  48. {
  49.     {fontpane_select, NULL},
  50.     {NULL, NULL},
  51. };
  52.  
  53. static String    fontpane_translations =
  54.     "<Message>WM_PROTOCOLS: FontPaneCancel()\n";
  55. static XtActionsRec    fontpane_actions[] =
  56. {
  57.     {"FontPaneCancel", (XtActionProc) fontpane_cancel},
  58. };
  59.  
  60. static TOOL    ps_fontpanes, ps_buttons;
  61. static TOOL    latex_fontpanes, latex_buttons;
  62. static TOOL    ps_fontpane[NUM_PS_FONTS + 1];
  63. static TOOL    latex_fontpane[NUM_LATEX_FONTS];
  64.  
  65. init_fontmenu(tool)
  66.     TOOL        tool;
  67. {
  68.     TOOL        tmp_but;
  69.     register int    i;
  70.     register MenuItemRec *mi;
  71.     XtTranslations  pane_actions;
  72.  
  73.     DeclareArgs(8);
  74.  
  75.     FirstArg(XtNborderWidth, POPUP_BW);
  76.     NextArg(XtNmappedWhenManaged, False);
  77.     NextArg(XtNtitle, "Xfig: Font menu");
  78.  
  79.     ps_fontmenu = XtCreatePopupShell("xfig_ps_font_menu",
  80.                      transientShellWidgetClass, tool,
  81.                      Args, ArgCount);
  82.     XtOverrideTranslations(ps_fontmenu,
  83.             XtParseTranslationTable(fontpane_translations));
  84.     latex_fontmenu = XtCreatePopupShell("xfig_latex_font_menu",
  85.                     transientShellWidgetClass, tool,
  86.                     Args, ArgCount);
  87.     XtOverrideTranslations(latex_fontmenu,
  88.             XtParseTranslationTable(fontpane_translations));
  89.     XtAppAddActions(tool_app, fontpane_actions, XtNumber(fontpane_actions));
  90.  
  91.     FirstArg(XtNvSpace, -INTERNAL_BW);
  92.     NextArg(XtNhSpace, 0);
  93.  
  94.     ps_fontpanes = XtCreateManagedWidget("menu", boxWidgetClass,
  95.                      ps_fontmenu, Args, ArgCount);
  96.     latex_fontpanes = XtCreateManagedWidget("menu", boxWidgetClass,
  97.                         latex_fontmenu, Args, ArgCount);
  98.  
  99.     for (i = 0; i < NUM_PS_FONTS + 1; i++) {
  100.     ps_fontmenu_items[i].type = MENU_IMAGESTRING;    /* put the fontnames in
  101.                              * menu */
  102.     ps_fontmenu_items[i].label = ps_fontinfo[i].name;
  103.     ps_fontmenu_items[i].info = (caddr_t) i - 1;    /* index for font # */
  104.     }
  105.  
  106.     for (i = 0; i < NUM_LATEX_FONTS; i++) {
  107.     latex_fontmenu_items[i].type = MENU_IMAGESTRING;    /* put the fontnames in
  108.                                  * menu */
  109.     latex_fontmenu_items[i].label = latex_fontinfo[i].name;
  110.     latex_fontmenu_items[i].info = (caddr_t) i;    /* index for font # */
  111.     }
  112.  
  113.     FirstArg(XtNwidth, PS_FONTPANE_WD);
  114.     NextArg(XtNdefaultDistance, INTERNAL_BW);
  115.     NextArg(XtNborderWidth, 0);
  116.     ps_buttons = XtCreateManagedWidget("buttons", formWidgetClass,
  117.                        ps_fontpanes, Args, ArgCount);
  118.     latex_buttons = XtCreateManagedWidget("buttons", formWidgetClass,
  119.                       latex_fontpanes, Args, ArgCount);
  120.  
  121.     i = (int) ((PS_FONTPANE_WD - INTERNAL_BW) / 3);
  122.     FirstArg(XtNwidth, i);
  123.     NextArg(XtNborderWidth, 0);
  124.     tmp_but = XtCreateManagedWidget("cancel", commandWidgetClass,
  125.                     ps_buttons, Args, ArgCount);
  126.     XtAddEventHandler(tmp_but, ButtonReleaseMask, (Boolean) 0,
  127.               fontpane_cancel, (XtPointer) NULL);
  128.  
  129.     FirstArg(XtNfromHoriz, tmp_but);
  130.     NextArg(XtNwidth, PS_FONTPANE_WD - INTERNAL_BW - i);
  131.     NextArg(XtNborderWidth, 0);
  132.     tmp_but = XtCreateManagedWidget("use_latex_fonts", commandWidgetClass,
  133.                     ps_buttons, Args, ArgCount);
  134.     XtAddEventHandler(tmp_but, ButtonReleaseMask, (Boolean) 0,
  135.               fontpane_swap, (XtPointer) NULL);
  136.  
  137.     FirstArg(XtNwidth, i);
  138.     NextArg(XtNborderWidth, 0);
  139.     tmp_but = XtCreateManagedWidget("cancel", commandWidgetClass,
  140.                     latex_buttons, Args, ArgCount);
  141.     XtAddEventHandler(tmp_but, ButtonReleaseMask, (Boolean) 0,
  142.               fontpane_cancel, (XtPointer) NULL);
  143.  
  144.     FirstArg(XtNfromHoriz, tmp_but);
  145.     NextArg(XtNwidth, PS_FONTPANE_WD - INTERNAL_BW - i);
  146.     NextArg(XtNborderWidth, 0);
  147.     tmp_but = XtCreateManagedWidget("use_postscript_fonts", commandWidgetClass,
  148.                     latex_buttons, Args, ArgCount);
  149.     XtAddEventHandler(tmp_but, ButtonReleaseMask, (Boolean) 0,
  150.               fontpane_swap, (XtPointer) NULL);
  151.  
  152.     pane_actions = XtParseTranslationTable("<EnterWindow>:set()\n\
  153.         <Btn1Up>:notify()unset()\n");
  154.  
  155.     FirstArg(XtNwidth, PS_FONTPANE_WD);
  156.     NextArg(XtNheight, PS_FONTPANE_HT);
  157.     NextArg(XtNcallback, pane_callbacks);
  158.     NextArg(XtNbitmap, NULL);
  159.     NextArg(XtNinternalWidth, 0);    /* space between pixmap and edge */
  160.     NextArg(XtNinternalHeight, 0);
  161.     NextArg(XtNborderWidth, INTERNAL_BW);
  162.     NextArg(XtNresize, False);    /* don't allow resize */
  163.  
  164.     for (i = 0; i < NUM_PS_FONTS + 1; ++i) {
  165.     mi = &ps_fontmenu_items[i];
  166.     pane_callbacks[0].closure = (caddr_t) mi;
  167.     ps_fontpane[i] = XtCreateManagedWidget("pane", commandWidgetClass,
  168.                            ps_fontpanes, Args, ArgCount);
  169.     XtOverrideTranslations(ps_fontpane[i], pane_actions);
  170.     }
  171.  
  172.     for (i = 0; i < NUM_LATEX_FONTS; ++i) {
  173.     mi = &latex_fontmenu_items[i];
  174.     pane_callbacks[0].closure = (caddr_t) mi;
  175.     latex_fontpane[i] = XtCreateManagedWidget("pane", commandWidgetClass,
  176.                        latex_fontpanes, Args, ArgCount);
  177.     XtOverrideTranslations(latex_fontpane[i], pane_actions);
  178.     }
  179.  
  180.     return (1);
  181. }
  182.  
  183. /* create the bitmaps for the font menu */
  184.  
  185. setup_fontmenu()
  186. {
  187.     register int    i;
  188.  
  189.     DeclareArgs(2);
  190.  
  191.     Pixel        bg, fg;
  192.  
  193.     /* get the foreground/background of the widget */
  194.     FirstArg(XtNforeground, &fg);
  195.     NextArg(XtNbackground, &bg);
  196.     GetValues(ps_fontpane[0]);
  197.  
  198.     /* Create the bitmaps */
  199.  
  200.     for (i = 0; i < NUM_PS_FONTS + 1; i++)
  201.     psfont_menu_bitmaps[i] = XCreatePixmapFromBitmapData(tool_d,
  202.                    XtWindow(ind_panel), (char *) psfont_menu_bits[i],
  203.                      PS_FONTPANE_WD, PS_FONTPANE_HT, fg, bg,
  204.                       XDefaultDepthOfScreen(tool_s));
  205.  
  206.     for (i = 0; i < NUM_LATEX_FONTS; i++)
  207.     latexfont_menu_bitmaps[i] = XCreatePixmapFromBitmapData(tool_d,
  208.                      XtWindow(ind_panel), (char *) latexfont_menu_bits[i],
  209.                       LATEX_FONTPANE_WD, LATEX_FONTPANE_HT, fg, bg,
  210.                        XDefaultDepthOfScreen(tool_s));
  211.  
  212.     /* Store the bitmaps in the menu panes */
  213.     for (i = 0; i < NUM_PS_FONTS + 1; i++) {
  214.     FirstArg(XtNbitmap, psfont_menu_bitmaps[i]);
  215.     SetValues(ps_fontpane[i]);
  216.     }
  217.     for (i = 0; i < NUM_LATEX_FONTS; i++) {
  218.     FirstArg(XtNbitmap, latexfont_menu_bitmaps[i]);
  219.     SetValues(latex_fontpane[i]);
  220.     }
  221.  
  222.     FirstArg(XtNbackground, BlackPixelOfScreen(tool_s));
  223.     SetValues(ps_buttons);
  224.     SetValues(latex_buttons);
  225.  
  226.     XtRealizeWidget(ps_fontmenu);
  227.     XtRealizeWidget(latex_fontmenu);
  228.     /* at this point the windows are realized but not drawn */
  229.     XDefineCursor(tool_d, XtWindow(ps_fontpanes), arrow_cursor);
  230.     XDefineCursor(tool_d, XtWindow(latex_fontpanes), arrow_cursor);
  231. }
  232.  
  233. void
  234. fontpane_popup(psfont_adr, latexfont_adr, psflag_adr, showfont_fn, show_widget)
  235.     int           *psfont_adr, *latexfont_adr, *psflag_adr;
  236.     int            (*showfont_fn) ();
  237.     Widget        show_widget;
  238.  
  239. {
  240.     DeclareArgs(2);
  241.     Position        xposn, yposn, dummy;
  242.  
  243.     font_ps_sel = psfont_adr;
  244.     font_latex_sel = latexfont_adr;
  245.     flag_sel = psflag_adr;
  246.     font_setimage = showfont_fn;
  247.     font_widget = show_widget;
  248.     XtTranslateCoords(show_widget, (Position) 0, (Position) 0, &xposn, &dummy);
  249.     XtTranslateCoords(tool, (Position) 0, (Position) 0, &dummy, &yposn);
  250.     FirstArg(XtNx, xposn);
  251.     NextArg(XtNy, yposn - 20);    /* up a little bit from top of tool */
  252.     SetValues(ps_fontmenu);
  253.     SetValues(latex_fontmenu);
  254.     XtPopup(*flag_sel ? ps_fontmenu : latex_fontmenu, XtGrabExclusive);
  255.     XSetWMProtocols(XtDisplay(*flag_sel ? ps_fontmenu : latex_fontmenu),
  256.                 XtWindow(*flag_sel ? ps_fontmenu : latex_fontmenu),
  257.             &wm_delete_window, 1);
  258. }
  259.  
  260. static void
  261. fontpane_select(w, closure, call_data)
  262.     Widget    w;
  263.     XtPointer closure;
  264.     XtPointer call_data;
  265. {
  266.     TOOL        widget = (TOOL) w;
  267.     MenuItemRec       *mi = (MenuItemRec *) closure;
  268.     char       *font_name = mi->label;
  269.  
  270.     if (*flag_sel)
  271.     *font_ps_sel = (int) mi->info;    /* set ps font to one selected */
  272.     else
  273.     *font_latex_sel = (int) mi->info;    /* set latex font to one
  274.                          * selected */
  275.     put_msg("Font: %s", font_name);
  276.     /* put image of font in indicator window */
  277.     (*font_setimage) (font_widget);
  278.     XtPopdown(*flag_sel ? ps_fontmenu : latex_fontmenu);
  279. }
  280.  
  281. static void
  282. fontpane_cancel()
  283. {
  284.     XtPopdown(*flag_sel ? ps_fontmenu : latex_fontmenu);
  285. }
  286.  
  287. static void
  288. fontpane_swap()
  289. {
  290.     XtPopdown(*flag_sel ? ps_fontmenu : latex_fontmenu);
  291.     *flag_sel = 1 - *flag_sel;
  292.     /* put image of font in indicator window */
  293.     (*font_setimage) (font_widget);
  294.     XtPopup(*flag_sel ? ps_fontmenu : latex_fontmenu, XtGrabExclusive);
  295.     XSetWMProtocols(XtDisplay(*flag_sel ? ps_fontmenu : latex_fontmenu),
  296.                 XtWindow(*flag_sel ? ps_fontmenu : latex_fontmenu),
  297.             &wm_delete_window, 1);
  298. }
  299.