home *** CD-ROM | disk | FTP | other *** search
/ Tools / WinSN5.0Ver.iso / NETSCAP.50 / WIN1998.ZIP / ns / cmd / xfe / menu.c < prev    next >
Encoding:
C/C++ Source or Header  |  1998-04-08  |  6.6 KB  |  244 lines

  1. /* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*-
  2.  *
  3.  * The contents of this file are subject to the Netscape Public License
  4.  * Version 1.0 (the "NPL"); you may not use this file except in
  5.  * compliance with the NPL.  You may obtain a copy of the NPL at
  6.  * http://www.mozilla.org/NPL/
  7.  *
  8.  * Software distributed under the NPL is distributed on an "AS IS" basis,
  9.  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
  10.  * for the specific language governing rights and limitations under the
  11.  * NPL.
  12.  *
  13.  * The Initial Developer of this code under the NPL is Netscape
  14.  * Communications Corporation.  Portions created by Netscape are
  15.  * Copyright (C) 1998 Netscape Communications Corporation.  All Rights
  16.  * Reserved.
  17.  */
  18. /* 
  19.    menu.c --- menu creating utilities
  20.    Created: Terry Weissman <terry@netscape.com>, 14-Jun-95.
  21.  */
  22.  
  23.  
  24. #include "mozilla.h"
  25. #include "xfe.h"
  26. #include "menu.h"
  27.  
  28. static void
  29. free_closure_cb(Widget w, XtPointer clientData, XtPointer callData)
  30. {
  31.     XP_FREE(clientData);
  32. }
  33.  
  34. int
  35. fe_CreateSubmenu(Widget menu, struct fe_button *buttons, MWContext *context,
  36.             XtPointer closure, XtPointer data)
  37. {
  38.     int            ac /*, ac1*/;
  39.     Arg            av[20] /*, av1[5]*/;
  40.     /*Widget            submenu;*/
  41.     Colormap        cmap;
  42.     Cardinal        depth;
  43.     Visual            *v;
  44.     int            w, step;
  45.  
  46.     if (!buttons || !buttons[0].name)
  47.     {
  48.         return 1;
  49.     }
  50.  
  51.     v = 0;
  52.     cmap = 0;
  53.     depth = 0;
  54.     w = 0;
  55.     while (buttons[w].name)
  56.     {
  57.         Widget menu_button = 0;
  58.         step = 1;
  59.         if (!*buttons[w].name) {    /* "" means do a line */
  60.         ac = 0;
  61.         menu_button = XmCreateSeparatorGadget(menu, "separator",
  62.                               av, ac);
  63.         }
  64. #ifdef __sgi
  65.         else if ((!strcmp("sgi", buttons[w].name) ||
  66.               !strcmp("adobe", buttons[w].name))
  67.              && !fe_VendorAnim) {
  68.         w++;
  69.         continue;
  70.         }
  71. #endif
  72.         else {
  73.         char *name = buttons[w].name;
  74.         /*void *arg;*/
  75.         ac = 0;
  76.  
  77.         /* don't fool the xfe2 code into thinking that the user data is a
  78.          * menu spec or something... */
  79.         XtSetArg(av[ac], XmNuserData, NULL); ac++;
  80.  
  81.         if (buttons[w].type == SELECTABLE ||
  82.               buttons[w].type == UNSELECTABLE) {
  83.             fe_button_closure *button_closure = XP_NEW_ZAP(fe_button_closure);
  84.             button_closure->context = context;
  85.             button_closure->userdata = buttons[w].userdata;
  86.  
  87.             if (buttons[w].type == UNSELECTABLE)
  88.                 XtSetArg(av[ac], XtNsensitive, False), ac++;
  89.  
  90.             menu_button = XmCreatePushButtonGadget(menu, name, av, ac);
  91.             
  92.             XtAddCallback(menu_button,
  93.                           XmNactivateCallback,
  94.                           buttons[w].callback,
  95.                           button_closure);
  96.             XtAddCallback(menu_button,
  97.                           XmNdestroyCallback,
  98.                           free_closure_cb, button_closure);
  99.         }
  100.         else if (buttons[w].type == TOGGLE ||
  101.              buttons[w].type == RADIO) {
  102.             XP_ASSERT(0);
  103.         }
  104.         else if (buttons[w].type == INTL_CASCADE) {
  105.             XP_ASSERT(0);
  106.         } else if (buttons[w].type == CASCADE) {
  107.             XP_ASSERT(0);
  108.         } else {
  109.             abort();
  110.         }
  111.         }
  112.         if (buttons[w].offset) {
  113.         Widget* foo = (Widget*)
  114.                 (((char*) data) + (int) (buttons[w].offset));
  115.         *foo = menu_button;
  116.         }
  117.         XtManageChild(menu_button);
  118.         w+=step;
  119.     }
  120.     return w+1;
  121. }
  122.  
  123.  
  124. Widget
  125. fe_PopulateMenubar(Widget parent, struct fe_button* buttons,
  126.            MWContext* context, void* closure, void* data,
  127.            XtCallbackProc pulldown_cb)
  128. {
  129.     Widget menubar;
  130.     Widget menu;
  131.     Widget menubar_button;
  132.     Widget kids[20];
  133.     int i;
  134.     Arg av[20];
  135.     int ac;
  136.     Visual *v = 0;
  137.     Colormap cmap = 0;
  138.     Cardinal depth = 0;
  139.     int w = 0;
  140.     int step;
  141.     char *menu_name;
  142.  
  143.     XtVaGetValues(XtParent(parent), XtNvisual, &v, XtNcolormap, &cmap,
  144.           XtNdepth, &depth, 0);
  145.     
  146.     ac = 0;
  147.     XtSetArg(av[ac], XmNskipAdjust, True); ac++;
  148.     XtSetArg(av[ac], XmNseparatorOn, False); ac++;
  149.     XtSetArg(av[ac], XmNvisual, v); ac++;
  150.     XtSetArg(av[ac], XmNdepth, depth); ac++;
  151.     XtSetArg(av[ac], XmNcolormap, cmap); ac++;
  152.     menubar = XmCreateMenuBar(parent, "menuBar", av, ac);
  153.  
  154.     i = 0;            /* Which menu we're on. */
  155.     while (buttons[w].name) {
  156.     menu_name = buttons[w].name;
  157.     ac = 0;
  158.     XtSetArg(av[ac], XmNvisual, v); ac++;
  159.     XtSetArg(av[ac], XmNcolormap, cmap); ac++;
  160.     XtSetArg(av[ac], XmNdepth, depth); ac++;
  161.     menu = XmCreatePulldownMenu(menubar, menu_name, av, ac);
  162.     ac = 0;
  163.     XtSetArg(av[ac], XmNsubMenuId, menu); ac++;
  164.  
  165. #if 1
  166.     /* Create XmCreateCascadeButton always as we want to call action
  167.        CleanupMenubar() later and this is available only with the
  168.        Button and not with the Gadget. */
  169.     menubar_button = XmCreateCascadeButton(menubar, menu_name, av, ac);
  170. #else /* 1 */
  171. #ifdef _HPUX_SOURCE
  172.     menubar_button = XmCreateCascadeButton      (menubar, menu_name, av, ac);
  173. #else /* !HPUX */
  174.     menubar_button = XmCreateCascadeButtonGadget(menubar, menu_name, av, ac);
  175. #endif /* !HPUX */
  176. #endif /* 1 */
  177.  
  178. #ifdef _HPUX_SOURCE
  179.     /* 
  180.        In order to break the legs off of the HP color management
  181.        garbage (which we needed to do in order to not get
  182.        brown-on-brown widgets) we had to put the application class
  183.        in all of the color specifications in the resource file.
  184.        BUT, that's not enough for the menubar, oh no.  HP uses a
  185.        different pallette for that, and consequently you can't set
  186.        the color of it using a resource no matter what you do -
  187.        even if the entire path to the RowColumn is fully
  188.        qualified.
  189.  
  190.        So on HPs, we make the buttons in the menubar be Widgets
  191.        instead of Gadgets (so that they can have a background
  192.        color) and then force the background color of the menubar
  193.        to be the background color of the first menu button on it.  */
  194.  
  195.     if (i == 0) {
  196.         Pixel bg = 0, tsc = 0, bsc = 0;
  197.         XtVaGetValues(menubar_button,
  198.               XmNbackground, &bg,
  199.               XmNtopShadowColor, &tsc,
  200.               XmNbottomShadowColor, &bsc,
  201.               0);
  202.         XtVaSetValues(menubar,
  203.               XmNbackground, bg,
  204.               XmNtopShadowColor, tsc,
  205.               XmNbottomShadowColor, bsc,
  206.               0);
  207.     }
  208. #endif
  209.  
  210.     if (buttons[w].offset) {
  211.         Widget* foo = (Widget*)
  212.         (((char*) data) + (int) (buttons[w].offset));
  213.         *foo = menu;
  214.     }
  215.  
  216.     XtAddCallback(menubar_button, XmNcascadingCallback,
  217.               pulldown_cb, (XtPointer) closure);
  218.  
  219.     /*
  220.      *    Allow menu by menu callbacks, instead of calling
  221.      *    back on every menu pulldown (slow).
  222.      */
  223.     if (buttons[w].callback)
  224.         XtAddCallback(
  225.               menubar_button,
  226.               XmNcascadingCallback,
  227.               buttons[w].callback,
  228.               (XtPointer)closure
  229.               );
  230.  
  231.     kids[i] = menubar_button;
  232.  
  233.     w++;
  234.     step = fe_CreateSubmenu(menu, &buttons[w], context, closure, data);
  235.     if (!strcmp("help", menu_name)) {
  236.         XtVaSetValues(menubar, XmNmenuHelpWidget, menubar_button, 0);
  237.     }
  238.     w+=step;
  239.     i++;
  240.     }
  241.     XtManageChildren(kids, i);
  242.     return menubar;
  243. }
  244.