A Problem with MenuItems (or Me!)

A Problem with MenuItems (or Me!)

Postby xProgrammer » Sun Sep 07, 2008 12:13 pm

Hi Antonio

I am trying to Disable() / Enable() menuitems as they become valid depending upon what else has happened in a program.

The problem is that

MENUITEM <oItem> PROMPT <cPrompt> ACTION <uAction> is setting <oItem> to nil rather than the new menu item. I have modified tutor04.prg to demonstrate the problem:

Code: Select all  Expand view
#include "FiveLinux.ch"

static oWnd

function Main()

   local lVal := .t., cName := "Hello", cItem, cLbx, nVal := 100, oBar

   DEFINE WINDOW oWnd TITLE "Testing controls" ;
      MENU BuildMenu()

   DEFINE BUTTONBAR oBar OF oWnd

   DEFINE BUTTON OF oBar RESOURCE "gtk-new" ACTION MsgInfo( "New" )

   DEFINE BUTTON OF oBar RESOURCE "gtk-open" ACTION MsgInfo( "Open" )

   DEFINE BUTTON OF oBar RESOURCE "gtk-save" ;
      ACTION MsgInfo( "Save" ) GROUP

   DEFINE BUTTON OF oBar RESOURCE "gtk-quit" ACTION oWnd:End()

   @ 9,  1 SAY "A Say" OF oWnd

   @ 12, 2 CHECKBOX lVal PROMPT "Click me" OF oWnd

   @ 15, 2 GET cName OF oWnd

   @ 18, 2 COMBOBOX cItem OF oWnd ITEMS { "one", "two", "three" }

   @ 9, 22 LISTBOX cLbx OF oWnd ITEMS { "one", "two", "three", "four", "five", "six", "seven", "eight", "nine", "ten", "eleven", "twelve" }

   @ 21, 2 METER nVal TOTAL 200 OF oWnd

   @ 24, 2 IMAGE FILENAME "flh.gif" OF oWnd

   @ 26, 30 BUTTON "" OF oWnd ACTION MsgInfo( cLbx ) RESOURCE "gtk-ok"

   @ 26, 39 BUTTON "" OF oWnd ACTION MsgInfo( cItem ) RESOURCE "gtk-cancel"

   SET MSGBAR OF oWnd TO " FiveLinux - (c) FiveTech Software 2008"

   ACTIVATE WINDOW oWnd ;
      VALID MsgYesNo( "Are you sure ?" ) ;
      ON RIGHT CLICK MsgInfo( "right click" )

return nil

function BuildMenu()

   local oMenu
   local m2        // I added this variable

   MENU oMenu
      MENUITEM "One"
      MENU
         MENUITEM "First"  RESOURCE "gtk-new"  ACTION MsgInfo( "New" )
    MENU
       MENUITEM "One"
       MENUITEM  m2 PROMPT "Two"  // and modified this line so that m2 should be this menu item
       SEPARATOR
       MENUITEM "Three"
    ENDMENU
    MENUITEM "Second" RESOURCE "gtk-quit" ACTION oWnd:End()
      ENDMENU

      MENUITEM "Two"     ACTION MsgInfo( "Two" )
      MENUITEM "Three"   ACTION MsgInfo( "Three" )
   ENDMENU
   MsgInfo( ValType( m2 ) )    // I added this MsgInfo which tells us that m2 is Undefined.  Why?
   m2:Disable()                // so this line produces an error.

return oMenu


When I look at FiveLinux.ch I see that the MENUITEM command is being preprocessed into a call to MenuAddItem()

Code: Select all  Expand view
#xcommand MENUITEM [ <oMenuItem> PROMPT ] [<cPrompt>] ;
                [ ACTION <uAction> ] ;
                [ <resource: RESOURCE, NAME, RESNAME> <cResName> ] ;
             => ;
                [ <oMenuItem> := ] MenuAddItem( <cPrompt>,;
                [ \{|o| <uAction> \} ], <cResName> )


I can't find MenuAddItem() but my guess is it must be returning nil. As I can't find it I can't attempt to fix it.

But, as always, my diagnosis could be wrong.

Regards
Doug
User avatar
xProgrammer
 
Posts: 464
Joined: Tue May 16, 2006 7:47 am
Location: Australia

Postby Antonio Linares » Sun Sep 07, 2008 4:51 pm

Doug,

You are right. There is a bug in FiveLinux\source\classes\pdmenu.prg.

function MenuAddItem() has to be modified this way:
Code: Select all  Expand view
function MenuAddItem( cPrompt, bAction, cResName )

   local oItem

   ATail( aMenus ):Add( oItem := TMenuItem():New( cPrompt, bAction, cResName ) )

return oItem

Thanks for your feedback :-)
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 41274
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Postby xProgrammer » Sun Sep 07, 2008 9:32 pm

Hi Antonio

Thanks so much for the prompt response and bug fix. I still can't achieve what I want. I now realise that TMenu and TMenuItem aren't subclasses of TControl and hence of TWindow. As a result they don't support Disable() or Enable().

It would be nice to be able to enable or disable menu items. Failing that to add or delete them.I'm sure I did it in FiveWin. (Don't have the source handy). I did look at the FiveWin documentation and saw that MENUITEM has [ ENABLED | DISABLED ] support.

Regards
Doug
User avatar
xProgrammer
 
Posts: 464
Joined: Tue May 16, 2006 7:47 am
Location: Australia


Return to FiveLinux / FiveDroid (Android)

Who is online

Users browsing this forum: No registered users and 2 guests