home *** CD-ROM | disk | FTP | other *** search
/ Amiga Elysian Archive / AmigaElysianArchive.iso / wp_dtp / xdme1821.lha / XDME / menu_dme.c < prev    next >
C/C++ Source or Header  |  1993-02-26  |  9KB  |  387 lines

  1. /******************************************************************************
  2.  
  3.     MODUL
  4.     menu_dme.c
  5.  
  6.     DESCRIPTION
  7.     [X]DME enhancements to menubase.c
  8.  
  9.     NOTES
  10.     that is only a fast hack derived from the original
  11.     menu.c, that supports one menu on all Windows
  12.  
  13.     es ist beabsichtigt, in zukunft nur noch 1 fenster
  14.     mit menues zuzulassen aber dafuer museen erst einmal alle
  15.     windowswitches im [X]DME ueber ene zentrale fktion laufen,
  16.     die dann menu_strip on/off waehlt
  17.  
  18.     BUGS
  19.  
  20.     TODO
  21.     0 make the module compilable
  22.     1 rewrite fixmenu for subs
  23.     2 I intend to use a Menu only for the actual Window
  24.     3 We must support multiple Menues
  25.     4 we need another MenuToMacro without that damned MENUSTRIP for access from vars
  26.     5 use menubase.fix_items (not ready yet)
  27.  
  28.  
  29.     EXAMPLES
  30.  
  31.     SEE ALSO
  32.  
  33.     INDEX
  34.  
  35.     HISTORY
  36.     20 Dec 1992 b_null created
  37.  
  38. ******************************************************************************/
  39.  
  40. /**************************************
  41.         Includes
  42. **************************************/
  43. #include "defs.h"
  44. #include "menubase.h"
  45.  
  46. #include <libraries/gadtools.h>
  47. #include <clib/gadtools_protos.h>
  48.  
  49. /**************************************
  50.         Globale Variable
  51. **************************************/
  52. Prototype void menuon        (MENUSTRIP * ms, struct Window * win);
  53. Prototype void menuoff        (MENUSTRIP * ms, struct Window * win);
  54. Prototype void menu_strip   (MENUSTRIP * ms, struct Window * Win);
  55. Prototype void menuload     (MENUSTRIP * ms,  char * fname);
  56. Prototype void menusave     (MENUSTRIP * ms,  char * fname);
  57. Prototype void fixmenu        (MENUSTRIP * ms, struct Window * win);
  58.  
  59.  
  60. /**************************************
  61.       Interne Defines & Strukturen
  62. **************************************/
  63.  
  64.  
  65. /**************************************
  66.         Interne Variable
  67. **************************************/
  68.  
  69.  
  70. /**************************************
  71.        Interne Prototypes
  72. **************************************/
  73.  
  74.  
  75. /*****************************************************************************
  76.  
  77.     NAME
  78.     menuon
  79.  
  80.     PARAMETER
  81.     MENUSTRIP    * ms
  82.     struct Window    * win
  83.  
  84.     RESULT
  85.     -/-
  86.  
  87.     RETURN
  88.     void
  89.  
  90.     DESCRIPTION
  91.     activates the menu definitions of a program; each
  92.     call to menuon eliminates a PRIOR call to menuoff.
  93.  
  94.     NOTES
  95.     Window is not dummy-parameter any more
  96.  
  97.     BUGS
  98.  
  99.     EXAMPLES
  100.  
  101.     SEE ALSO
  102.  
  103.     INTERNALS
  104.     Win war ein Dummy, der schon einmal eingebaut wurde,
  105.     da ich beabsichtige, nur noch fuer das aktuelle Fenster
  106.     den Menubar zuzulassen;
  107.     das heisst unter anderem, dass ALLE fenster-manipulationen
  108.     eine spezielle Function aufrufen muessen, die dafuer sogrt,
  109.     dass von einem alten Fenster die Menuleiste abgetrennt wird
  110.     (dafuer bietet sich menu_strip an)
  111.  
  112.     zur zeit verwenden wir als default-menustrip jedesmal get_menustip(NULL);
  113.     dies ist zu beruecksichtigen
  114.  
  115.     HISTORY
  116.     20 Dec 1992 b_null  created
  117.  
  118. ******************************************************************************/
  119.  
  120. void menuon (MENUSTRIP * ms, struct Window * win)
  121. {
  122.     ED * ed;
  123.     int  def_too;
  124.  
  125.     if (ms) {
  126.     def_too = (get_menustrip(NULL) == ms);
  127.     if (ms->data && ms->offCount == 1) {
  128.         fixmenu (ms, win); /* !!! we use win here !!! */
  129.  
  130.         /* attach menues */
  131.         for (ed = (ED *)GetHead (&DBase); ed; ed = (ED *)GetSucc ((struct Node *)ed)) {
  132.          // if (ed->Package == Package)    /* <-PATCH_PACK */
  133.         if ((ed->menustrip == ms) || (def_too && (ed->menustrip == NULL)))    /* <- PATCH_NEW */
  134.         {
  135.             if (!ed->iconmode) {
  136.             SetMenuStrip (ed->win, ms->data);
  137.  
  138.             Forbid();
  139.             ed->win->Flags &= ~WFLG_RMBTRAP;
  140.             Permit();
  141.             } /* if */
  142.         } /* if */
  143.         } /* for all texts */
  144.     } /* if to be displayed */
  145.  
  146.     if (ms->offCount>0) {
  147.         ms->offCount --;
  148.     } else {
  149.         ms->offCount = 0;
  150.     } /* if menues are off */
  151.     } /* if sensefully called */
  152. } /* menuon */
  153.  
  154.  
  155. /*****************************************************************************
  156.  
  157.     NAME
  158.     menuoff
  159.  
  160.     PARAMETER
  161.     MENUSTRIP    * ms
  162.     struct Window    * win
  163.  
  164.     RESULT
  165.     -/-
  166.  
  167.     RETURN
  168.     void
  169.  
  170.     DESCRIPTION
  171.     inactivates the menudefinitions of a program
  172.     menuoff is stackable that means
  173.     calling menuoff twice needs also two calls to menon
  174.     to be erased
  175.  
  176.     NOTES
  177.     Window is not dummy-parameter any more
  178.  
  179.     BUGS
  180.  
  181.     EXAMPLES
  182.     state a menuoff state b menuon    -> state a
  183.     state a menuon    state a menuoff -> state a
  184.  
  185.     SEE ALSO
  186.  
  187.     INTERNALS
  188.     Win war ein Dummy, der schon einmal eingebaut wurde,
  189.     da ich beabsichtige, nur noch fuer das aktuelle Fenster
  190.     den Menubar zuzulassen;
  191.     das heisst unter anderem, dass ALLE fenster-manipulationen
  192.     eine spezialle Function aufrufen muessen, die dafuer sogrt,
  193.     dass von einem alten Fenster die Menuleiste abgetrennt wird
  194.     (dafuer bietet sich menu_strip an)
  195.  
  196.     zur zeit verwenden wir als default-menustrip jedesmal get_menustip(NULL);
  197.     dies ist zu beruecksichtigen
  198.  
  199.     HISTORY
  200.     20 Dec 1992 b_null  created
  201.  
  202. ******************************************************************************/
  203.  
  204. void menuoff (MENUSTRIP * ms, struct Window * win)
  205. {
  206.     ED * ed;
  207.     int  def_too;
  208.  
  209.     if (ms) {
  210.     def_too = (get_menustrip(NULL) == ms);
  211.     if (ms->offCount == 0) {
  212.         /* detach menues */
  213.         for (ed = (ED *)GetHead(&DBase); ed; ed = (ED *)GetSucc((struct Node *)ed)) {
  214.          // if (ed->Package == Package)    /* <-PATCH_PACK */
  215.         if ((ed->menustrip == ms) || (def_too && (ed->menustrip == NULL)))    /* <- PATCH_NEW */
  216.         {
  217.             ClearMenuStrip (ed->win);
  218.             Forbid ();
  219.             ed->win->Flags |= WFLG_RMBTRAP;
  220.             Permit ();
  221.         } /* if */
  222.         } /* for */
  223.     } /* if first menuoff */
  224.     ++ms->offCount;
  225.     } /* if */
  226. } /* menuoff */
  227.  
  228.  
  229. /*****************************************************************************
  230.  
  231.     NAME
  232.     menu_strip
  233.  
  234.     PARAMETER
  235.     MENUSTRIP    * ms
  236.     struct Window    * Win
  237.  
  238.     RESULT
  239.     -/-
  240.  
  241.     RETURN
  242.     void
  243.  
  244.     DESCRIPTION
  245.     that function binds a menustrip to a window
  246.     (or after menuoff, binds no menustrip to a window)
  247.  
  248.     NOTES
  249.       ! in naher Zunkunft wird diese Funktion wohl einen
  250.       ! weiteren Parameter erhalten : status = OFF|ON
  251.     (iconmode ist schliesslich offiziell nicht sichtbar)
  252.  
  253.     BUGS
  254.  
  255.     EXAMPLES
  256.  
  257.     SEE ALSO
  258.  
  259.     INTERNALS
  260.  
  261.     HISTORY
  262.     20 Dec 1992 b_null  created
  263.  
  264. ******************************************************************************/
  265.  
  266. void menu_strip (MENUSTRIP * ms, struct Window * Win)
  267. {
  268.     if (!ms->offCount && ms->data && !Ep->iconmode) {
  269.     SetMenuStrip (Win, ms->data);
  270.  
  271.     Forbid ();
  272.     Win->Flags &= ~WFLG_RMBTRAP;
  273.     Permit ();
  274.     } else {
  275.     Forbid ();
  276.     Win->Flags |= WFLG_RMBTRAP;
  277.     Permit ();
  278.     } /* if */
  279. } /* menu_strip */
  280.  
  281.  
  282. /*
  283. **  Die Folgenden functionen haben noch keine Header
  284. **  und sind teilweise noch nicht fertig
  285. */
  286.  
  287.  
  288. void menusave (MENUSTRIP * ms, char * name)
  289. {
  290.     FILE * fo = NULL;
  291.  
  292.     if (fo = fopen (name, "w")) {
  293.     savemenus (ms, fo);
  294.     fclose      (fo);
  295.     } else {
  296.     error  ("%s:\nCan't open file %s for output", CommandName(), name);
  297.     } /* if */
  298. } /* menusave */
  299.  
  300.  
  301.  
  302. void menuload (MENUSTRIP * ms, char * name)
  303. {
  304.     FILE * fi      = NULL;
  305.     int    lineno = 0;
  306.  
  307.     if (fi = fopen (name, "r")) {
  308.     menuoff   (ms, NULL);
  309.     menuclear (ms);
  310.  
  311.     loadmenus (ms, fi, &lineno);
  312.     menuon      (ms, NULL);
  313.     fclose      (fi);
  314.     } else {
  315.     error ("%s:\nCan't open file %s for input", CommandName(), name);
  316.     } /* if */
  317. } /* menuload */
  318.  
  319.  
  320. /*****************************************************************************
  321.  
  322.     NAME
  323.     fixmenu
  324.  
  325.     PARAMETER
  326.     MENUSTRIP     * ms
  327.     struct Window * win
  328.  
  329.     RESULT
  330.     -/-
  331.  
  332.     RETURN
  333.     void
  334.  
  335.     DESCRIPTION
  336.     recalculate the sizes & positions of a menustrip
  337.  
  338.     NOTES
  339.     that function uses GadTools.library
  340.  
  341.     BUGS
  342.  
  343.     EXAMPLES
  344.  
  345.     SEE ALSO
  346.     GadTools/LayoutMenu
  347.  
  348.     INTERNALS
  349.     (ursprueglich liessen wir den kram komplett berechnen, (spagetti)
  350.     dann wurden separate functionen eingefuehrt, die die menuitems
  351.     bzw die subitems rekursiv abarbeiteten)
  352.  
  353.     vorhin las ich jedoch, dass GadTools mit "normalen"
  354.     intuition-menues arbeitet - also kann LayoutMenu() auch
  355.     einen NON-GadTools menustrip verwenden!
  356.  
  357.     wenn aber nun GadToolsnormals IntuitionMenues verwendet, dann
  358.     kann die verwendete VisualInfo nur als Informationsquelle
  359.     dienen, also kann sie temporaer verwaltet werden
  360.  
  361.     (die Verwendung von GadTools spart > 1/2 kB  oder 130 LoC !)
  362.  
  363.     Aaron warum hast Du mir nict vorher dir RKM empfohlen ?!
  364.  
  365.     HISTORY
  366.     03 Feb 1993 b_null rewritten for use of GadTools
  367.  
  368. ******************************************************************************/
  369.  
  370. void fixmenu (MENUSTRIP * ms, struct Window * win)
  371. {
  372.     APTR       vi;                /* VisualInfo for GadTools - probably to get Info 'bout screensize a.s.o. */
  373.     struct TagItem tags[1] = {TAG_END, 0};  /* empty tags list for GadTools - varargs stuff is not visible with -mRR */
  374.  
  375.     vi = GetVisualInfoA (win->WScreen, tags);
  376.     LayoutMenusA (ms->data, vi, tags);
  377.     FreeVisualInfo (vi);
  378. } /* fixmenu */
  379.  
  380.  
  381.  
  382.  
  383. /******************************************************************************
  384. *****  ENDE menu_dme.c
  385. ******************************************************************************/
  386.  
  387.