home *** CD-ROM | disk | FTP | other *** search
/ System Booster / System Booster.iso / Texteditors / XDME / Src / Menu / Menu_DME.c next >
Encoding:
C/C++ Source or Header  |  1996-09-27  |  10.0 KB  |  459 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.     $Date: 94/07/06 12:06:48 $ last update
  38.  
  39. ******************************************************************************/
  40.  
  41. /**************************************
  42.         Includes
  43. **************************************/
  44. #define  MENU_INTERNAL            /* PATCH_NULL < 24-06-94 */
  45. #include "defs.h"
  46. #include "menubase.h"
  47.  
  48. #include <libraries/gadtools.h>
  49. #include <clib/gadtools_protos.h>
  50. #include <proto/gadtools.h>
  51.  
  52. /**************************************
  53.         Globale Variable
  54. **************************************/
  55. Prototype void    menuon         (MENUSTRIP * ms, struct Window * win);
  56. Prototype void    menuoff      (MENUSTRIP * ms, struct Window * win);
  57. Prototype void    menu_strip   (MENUSTRIP * ms, struct Window * Win);
  58. Prototype void    menuload     (MENUSTRIP * ms,  char * fname);
  59. Prototype void    menusave     (MENUSTRIP * ms,  char * fname);
  60. Prototype void    fixmenu      (MENUSTRIP * ms, struct Window * win);
  61.  
  62. Prototype void* currentmenu  (void);
  63. Prototype void* currentwindow(void);
  64.  
  65. /**************************************
  66.       Interne Defines & Strukturen
  67. **************************************/
  68.  
  69.  
  70. /**************************************
  71.         Interne Variable
  72. **************************************/
  73.  
  74.  
  75. /**************************************
  76.        Interne Prototypes
  77. **************************************/
  78.  
  79.  
  80. /*****************************************************************************
  81.  
  82.     NAME
  83.     menuon
  84.  
  85.     PARAMETER
  86.     MENUSTRIP    * ms
  87.     struct Window    * win
  88.  
  89.     RESULT
  90.     -/-
  91.  
  92.     RETURN
  93.     void
  94.  
  95.     DESCRIPTION
  96.     activates the menu definitions of a program; each
  97.     call to menuon eliminates a PRIOR call to menuoff.
  98.  
  99.     NOTES
  100.     Window is not dummy-parameter any more
  101.  
  102.     BUGS
  103.  
  104.     EXAMPLES
  105.  
  106.     SEE ALSO
  107.  
  108.     INTERNALS
  109.     Win war ein Dummy, der schon einmal eingebaut wurde,
  110.     da ich beabsichtige, nur noch fuer das aktuelle Fenster
  111.     den Menubar zuzulassen;
  112.     das heisst unter anderem, dass ALLE fenster-manipulationen
  113.     eine spezielle Function aufrufen muessen, die dafuer sogrt,
  114.     dass von einem alten Fenster die Menuleiste abgetrennt wird
  115.     (dafuer bietet sich menu_strip an)
  116.  
  117.     zur zeit verwenden wir als default-menustrip jedesmal get_menustip(NULL);
  118.     dies ist zu beruecksichtigen
  119.  
  120.     HISTORY
  121.     20 Dec 1992 b_null  created
  122.  
  123. ******************************************************************************/
  124.  
  125. void menuon (MENUSTRIP * ms, struct Window * win)
  126. {
  127.     ED * ed;
  128.     int  def_too;
  129.  
  130.     if (ms) {
  131.     def_too = (get_menustrip(NULL) == ms);
  132.     if (ms->data && ms->offCount == 1) {
  133.         fixmenu (ms, win); /* !!! we use win here !!! */
  134.  
  135.         /* attach menues */
  136.         for (ed = (ED *)GetHead (&DBase); ed; ed = (ED *)GetSucc ((struct Node *)ed)) {
  137.          /* if (ed->Package == Package)    *//* <-PATCH_PACK */
  138.         if ((ed->menustrip == ms) || (def_too && (ed->menustrip == NULL)))    /* <- PATCH_NEW */
  139.         {
  140.             if (!ed->iconmode) {
  141.             SetMenuStrip (ed->win, ms->data);
  142.  
  143.             Forbid();
  144.             ed->win->Flags &= ~WFLG_RMBTRAP;
  145.             Permit();
  146.             } /* if */
  147.         } /* if */
  148.         } /* for all texts */
  149.     } /* if to be displayed */
  150.  
  151.     if (ms->offCount>0) {
  152.         ms->offCount --;
  153.     } else {
  154.         ms->offCount = 0;
  155.     } /* if menues are off */
  156.     } /* if sensefully called */
  157. } /* menuon */
  158.  
  159.  
  160. /*****************************************************************************
  161.  
  162.     NAME
  163.     menuoff
  164.  
  165.     PARAMETER
  166.     MENUSTRIP    * ms
  167.     struct Window    * win
  168.  
  169.     RESULT
  170.     -/-
  171.  
  172.     RETURN
  173.     void
  174.  
  175.     DESCRIPTION
  176.     inactivates the menudefinitions of a program
  177.     menuoff is stackable that means
  178.     calling menuoff twice needs also two calls to menon
  179.     to be erased
  180.  
  181.     NOTES
  182.     Window is not dummy-parameter any more
  183.  
  184.     BUGS
  185.  
  186.     EXAMPLES
  187.     state a menuoff state b menuon    -> state a
  188.     state a menuon    state a menuoff -> state a
  189.  
  190.     SEE ALSO
  191.  
  192.     INTERNALS
  193.     Win war ein Dummy, der schon einmal eingebaut wurde,
  194.     da ich beabsichtige, nur noch fuer das aktuelle Fenster
  195.     den Menubar zuzulassen;
  196.     das heisst unter anderem, dass ALLE fenster-manipulationen
  197.     eine spezialle Function aufrufen muessen, die dafuer sogrt,
  198.     dass von einem alten Fenster die Menuleiste abgetrennt wird
  199.     (dafuer bietet sich menu_strip an)
  200.  
  201.     zur zeit verwenden wir als default-menustrip jedesmal get_menustip(NULL);
  202.     dies ist zu beruecksichtigen
  203.  
  204.     HISTORY
  205.     20 Dec 1992 b_null  created
  206.  
  207. ******************************************************************************/
  208.  
  209. void menuoff (MENUSTRIP * ms, struct Window * win)
  210. {
  211.     ED * ed;
  212.     int  def_too;
  213.  
  214.     if (ms) {
  215.     def_too = (get_menustrip(NULL) == ms);
  216.     if (ms->offCount == 0) {
  217.         /* detach menues */
  218.         for (ed = (ED *)GetHead(&DBase); ed; ed = (ED *)GetSucc((struct Node *)ed)) {
  219.          /* if (ed->Package == Package)    *//* <-PATCH_PACK */
  220.         if ((ed->menustrip == ms) || (def_too && (ed->menustrip == NULL)))    /* <- PATCH_NEW */
  221.         {
  222.             ClearMenuStrip (ed->win);
  223.             Forbid ();
  224.             ed->win->Flags |= WFLG_RMBTRAP;
  225.             Permit ();
  226.         } /* if */
  227.         } /* for */
  228.     } /* if first menuoff */
  229.     ++ms->offCount;
  230.     } /* if */
  231. } /* menuoff */
  232.  
  233.  
  234. /*****************************************************************************
  235.  
  236.     NAME
  237.     menu_strip
  238.  
  239.     PARAMETER
  240.     MENUSTRIP    * ms
  241.     struct Window    * Win
  242.  
  243.     RESULT
  244.     -/-
  245.  
  246.     RETURN
  247.     void
  248.  
  249.     DESCRIPTION
  250.     that function binds a menustrip to a window
  251.     (or after menuoff, binds no menustrip to a window)
  252.  
  253.     NOTES
  254.       ! in naher Zunkunft wird diese Funktion wohl einen
  255.       ! weiteren Parameter erhalten : status = OFF|ON
  256.     (iconmode ist schliesslich offiziell nicht sichtbar)
  257.  
  258.     BUGS
  259.  
  260.     EXAMPLES
  261.  
  262.     SEE ALSO
  263.  
  264.     INTERNALS
  265.  
  266.     HISTORY
  267.     20 Dec 1992 b_null  created
  268.  
  269. ******************************************************************************/
  270.  
  271. void menu_strip (MENUSTRIP * ms, struct Window * Win)
  272. {
  273.     if (!ms->offCount && ms->data && !Ep->iconmode) {
  274.     SetMenuStrip (Win, ms->data);
  275.  
  276.     Forbid ();
  277.     Win->Flags &= ~WFLG_RMBTRAP;
  278.     Permit ();
  279.     } else {
  280.     Forbid ();
  281.     Win->Flags |= WFLG_RMBTRAP;
  282.     Permit ();
  283.     } /* if */
  284. } /* menu_strip */
  285.  
  286.  
  287. /*
  288. **  Die Folgenden functionen haben noch keine Header
  289. **  und sind teilweise noch nicht fertig
  290. */
  291.  
  292.  
  293. void menusave (MENUSTRIP * ms, char * name)
  294. {
  295.     FILE * fo = NULL;
  296.  
  297.     if ((fo = fopen (name, "w"))) {
  298.     savemenus (ms, fo);
  299.     fclose      (fo);
  300.     } else {
  301.     error  ("%s:\nCan't open file %s for output", CommandName(), name);
  302.     } /* if */
  303. } /* menusave */
  304.  
  305.  
  306.  
  307. void menuload (MENUSTRIP * ms, char * name)
  308. {
  309.     FILE * fi      = NULL;
  310.     int    lineno = 0;
  311.  
  312.     if ((fi = fopen (name, "r"))) {
  313.     menuoff   (ms, NULL);
  314.     menuclear (ms);
  315.  
  316.     loadmenus (ms, fi, &lineno);
  317.     menuon      (ms, NULL);
  318.     fclose      (fi);
  319.     } else {
  320.     error ("%s:\nCan't open file %s for input", CommandName(), name);
  321.     } /* if */
  322. } /* menuload */
  323.  
  324.  
  325. /*****************************************************************************
  326.  
  327.     NAME
  328.     fixmenu
  329.  
  330.     PARAMETER
  331.     MENUSTRIP     * ms
  332.     struct Window * win
  333.  
  334.     RESULT
  335.     -/-
  336.  
  337.     RETURN
  338.     void
  339.  
  340.     DESCRIPTION
  341.     recalculate the sizes & positions of a menustrip
  342.  
  343.     NOTES
  344.     that function uses GadTools.library
  345.  
  346.     BUGS
  347.  
  348.     EXAMPLES
  349.  
  350.     SEE ALSO
  351.     GadTools/LayoutMenu
  352.  
  353.     INTERNALS
  354.     (ursprueglich liessen wir den kram komplett berechnen, (spagetti)
  355.     dann wurden separate functionen eingefuehrt, die die menuitems
  356.     bzw die subitems rekursiv abarbeiteten)
  357.  
  358.     vorhin las ich jedoch, dass GadTools mit "normalen"
  359.     intuition-menues arbeitet - also kann LayoutMenu() auch
  360.     einen NON-GadTools menustrip verwenden!
  361.  
  362.     wenn aber nun GadToolsnormals IntuitionMenues verwendet, dann
  363.     kann die verwendete VisualInfo nur als Informationsquelle
  364.     dienen, also kann sie temporaer verwaltet werden
  365.  
  366.     (die Verwendung von GadTools spart > 1/2 kB  oder 130 LoC !)
  367.  
  368.     Aaron warum hast Du mir nict vorher dir RKM empfohlen ?!
  369.  
  370.     HISTORY
  371.     03 Feb 1993 b_null rewritten for use of GadTools
  372.  
  373. ******************************************************************************/
  374.  
  375. void fixmenu (MENUSTRIP * ms, struct Window * win)
  376. {
  377.     APTR       vi;                /* VisualInfo for GadTools - probably to get Info 'bout screensize a.s.o. */
  378.     struct TagItem tags[1] = {{TAG_END,0}}; /* empty tags list for GadTools - varargs stuff is not visible with -mRR */
  379.  
  380.     vi = GetVisualInfoA (win->WScreen, tags);
  381.     LayoutMenusA (ms->data, vi, tags);
  382.     FreeVisualInfo (vi);
  383. } /* fixmenu */
  384.  
  385.  
  386.  
  387.  
  388. /*****************************************************************************
  389.  
  390.     NAME
  391.     currentwindow
  392.  
  393.     PARAMETER
  394.     void;
  395.  
  396.     RESULT
  397.     the current window's menustrip
  398.  
  399.     RETURN
  400.     void*
  401.  
  402.     DESCRIPTION
  403.     An interface to the current ED's menustrip
  404.  
  405.     NOTES
  406.     This function could easiliy be replaced by a macro
  407.  
  408.     HISTORY
  409.     26-08-93    b_noll  created
  410.  
  411. ******************************************************************************/
  412.  
  413. void * currentmenu (void)
  414. {
  415.     if ((Ep == NULL) || (Ep->menustrip == NULL)) {
  416.     return (get_menustrip (NULL));
  417.     } /* if */
  418.     return (Ep->menustrip);
  419. } /* currentmenu */
  420.  
  421.  
  422. /*****************************************************************************
  423.  
  424.     NAME
  425.     currentmenu
  426.  
  427.     PARAMETER
  428.     void;
  429.  
  430.     RESULT
  431.     the current window
  432.  
  433.     RETURN
  434.     void*
  435.  
  436.     DESCRIPTION
  437.     An interface to the current ED's window
  438.  
  439.     NOTES
  440.     This function should better be replaced by a macro
  441.  
  442.     HISTORY
  443.     26-08-93    b_noll  created
  444.  
  445. ******************************************************************************/
  446.  
  447. void * currentwindow (void)
  448. {
  449.     return (Ep->win);
  450. } /* currentwindow */
  451.  
  452.  
  453.  
  454.  
  455. /******************************************************************************
  456. *****  ENDE menu_dme.c
  457. ******************************************************************************/
  458.  
  459.