Login
Username:

Password:

Remember me



Lost Password?

Register now!

Sections

Who's Online
97 user(s) are online (81 user(s) are browsing Forums)

Members: 0
Guests: 97

more...

Support us!

Recent OS4 Files
OS4Depot.net

Report message:*
 

Re: Assigned: ReAction menu.class project

Subject: Re: Assigned: ReAction menu.class project
by trixie on 2014/7/1 10:04:56

OK, after first experiments with the implementation one thing has become rather clear. Going the MUI way, i.e. having separate classes for each menu type (the strip, the menu, the item), is quite an overkill. The menustrip.class and the menu.class are virtually empty - they are there only to provide object-oriented access to them.

I guess this can be done in a more straightforward way. As the menu represents a hierarchy, I have taken inspiration from the Layout Gadget. Now, in my still-tentative design, there is only one class - the menu.class. Each object of this class can take children to form a hierarchy. The actual meaning of the object (i.e. whether it is a menu, a submenu, an item, an item in a submenu etc.) is decided by the class based on the position of the object in the hierarchy. So the very first menu object is interpreted as the menu strip, its first child is the first menu, etc. It's all rather easy and there is really no need for several class types.

The following code snippet will give you an idea. In order not to scare you off I've added some handy macros that make the example easier to follow:

/* ReAction-style macros to make this example more readable. */
#define MenuObject IIntuition->NewObject(MenuClass, NULL
#define End        TAG_END)      

/* Menu identifiers. */
enum {
   
MID_STRIP,
   
MID_PROJECT,
   
MID_NEW,
   
MID_OPEN,
   
MID_RECENT,
   
MID_FIRST,
   
MID_SECOND,
   
MID_INVALID,
   
MID_QUIT,
   
MID_LAST
};

Object *menu[MID_LAST];

menu[MID_STRIP] = MenuObject,
   
/* Project menu */
   
MENU_AddChildmenu[MID_PROJECT] = MenuObject,
      
MENU_Label"Project",
      
/* "New" menu item */
      
MENU_AddChildmenu[MID_NEW] = MenuObject,
         
MENU_Label"New",
         
MENU_CommKey"n",
      
End,
      
/* "Open" menu item */
      
MENU_AddChildmenu[MID_OPEN] = MenuObject,
         
MENU_Label"Open",
         
MENU_CommKey"o",
      
End,
      
/* "Open Recent" submenu */
      
MENU_AddChildmenu[MID_RECENT] = MenuObject,
         
MENU_Label"Open Recent",
         
MENU_AddChildmenu[MID_FIRST] = MenuObject,
            
MENU_Label"First in the list of recent files",
         
End,        
         
MENU_AddChildmenu[MID_SECOND] = MenuObject,
            
MENU_Label"Second in the list of recent files",
            
/* Invalid submenu level. This item will be ignored by the class
               until Intuition supports deeper menu hierarchies.*/
            
MENU_AddChildmenu[MID_INVALID] = MenuObject,
               
MENU_Label"Why is everybody ignoring me, Doc?",
            
End,
         
End
      
End,
      
/* "Quit" menu item */
      
MENU_AddChildmenu[MID_QUIT] = MenuObject,
         
MENU_Label"Quit",
         
MENU_CommKey"q",
      
End,
   
End,
End;


So each item in the menu is an object and can be accessed via BOOPSI methods. For example, it you wanted to remove the entire Project menu, you'd invoke a remove method over the menu[MID_PROJECT] object. If you wanted to disable the Open Recent submenu, you'd SetAttrs() the disable attribute for menu[MID_RECENT], etc.

Comments welcome.

Powered by XOOPS 2.0 © 2001-2016 The XOOPS Project