MenuItem:SetCheck() and POPUP Menu ?

Post Reply
User avatar
Jimmy
Posts: 1740
Joined: Thu Sep 05, 2019 5:32 am
Location: Hamburg, Germany
Has thanked: 2 times

MenuItem:SetCheck() and POPUP Menu ?

Post by Jimmy »

hi,

does o:SetCheck() work when it is use as POPUP Menu :?:
if Yes, how :idea:
greeting,
Jimmy
User avatar
Antonio Linares
Site Admin
Posts: 42594
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain
Has thanked: 38 times
Been thanked: 86 times
Contact:

Re: MenuItem:SetCheck() and POPUP Menu ?

Post by Antonio Linares »

Dear Jimmy,

Please try to provide a small PRG that shows what you are trying to do

In this example, do you mean that you want to set the check on menuitem "One" ?

Code: Select all | Expand

#include "FiveWin.ch"

function Main()

   local oWnd 

   DEFINE WINDOW oWnd MENU BuildMenu()

   ACTIVATE WINDOW oWnd 

return nil   

function BuildMenu()

   local oMenu, oItem

   MENU oMenu
      MENUITEM "test"
      MENU 
         MENUITEM "One"
            MENU 
               MENUITEM "First" ACTION oItem:SetCheck( .T. )
               MENUITEM "Second"
            ENDMENU   
         MENUITEM oItem PROMPT "Two"
         MENUITEM "Three"
      ENDMENU   
   ENDMENU

return oMenu  
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Jimmy
Posts: 1740
Joined: Thu Sep 05, 2019 5:32 am
Location: Hamburg, Germany
Has thanked: 2 times

Re: MenuItem:SetCheck() and POPUP Menu ?

Post by Jimmy »

hi Antonio,

this is not exact what i try to make ( using 3 CLASS )
but it show what i mean when using POPUP Menu

Code: Select all | Expand

#include   "FiveWin.ch"
function Main()
local oWnd, oBtn

   DEFINE WINDOW oWnd MENU BuildMenu()

   oBtn := TButton() :new(10, 10, "press me", oBtn,, 500,200,,,, .T. )
   oBtn:bAction := { | oCtrl, nRow, nCol, nKeyFlags | ;
                    BUILDMENU2( oCtrl, nRow, nCol, nKeyFlags ) }

   ACTIVATE WINDOW oWnd

return   nil

function BuildMenu()
local oMenu, oItem

   MENU oMenu
      MENUITEM   "test"
      MENU
         MENUITEM   "One"
            MENU
               MENUITEM   "First"   ACTION IF(oItem:lChecked ,;
                                              oItem:SetCheck ( .F.) ,;
                                              oItem:SetCheck ( .T.)  )
               MENUITEM   "Second"
            ENDMENU
         MENUITEM oItem   PROMPT   "Two"
         MENUITEM   "Three"
      ENDMENU
   ENDMENU

return oMenu

function BuildMenu2(oCtrl, nRow, nCol)
local oMenu, oItem

   MENU oMenu POPUP
      MENUITEM   "test"
      MENU
         MENUITEM   "One"
            MENU
               MENUITEM   "First"   ACTION IF(oItem:lChecked ,;
                                              oItem:SetCheck ( .F.) ,;
                                              oItem:SetCheck ( .T.)  )
               MENUITEM   "Second"
            ENDMENU
         MENUITEM oItem   PROMPT   "Two"
         MENUITEM   "Three"
      ENDMENU
   ENDMENU

   ACTIVATE POPUP oMenu  OF oCtrl AT nRow, nCol

return oMenu
greeting,
Jimmy
User avatar
Enrico Maria Giordano
Posts: 8761
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia
Has thanked: 1 time
Been thanked: 5 times
Contact:

Re: MenuItem:SetCheck() and POPUP Menu ?

Post by Enrico Maria Giordano »

Jimmy wrote:hi,

does o:SetCheck() work when it is use as POPUP Menu :?:
Yes, but menu settings is lost when the POPUP menu closed. You have to keep the information yourself and apply it when you create the POPUP menu.
User avatar
Antonio Linares
Site Admin
Posts: 42594
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain
Has thanked: 38 times
Been thanked: 86 times
Contact:

Re: MenuItem:SetCheck() and POPUP Menu ?

Post by Antonio Linares »

Dear Jimmy,

Here you have your example modified to work as you want:

Code: Select all | Expand

#include   "FiveWin.ch"

static lChecked := .F.

function Main()

   local oWnd, oBtn

   DEFINE WINDOW oWnd MENU BuildMenu()

   oBtn := TButton() :new(10, 10, "press me", oBtn,, 500,200,,,, .T. )
   oBtn:bAction := { | oCtrl, nRow, nCol, nKeyFlags | ;
                    BUILDMENU2( oCtrl, nRow, nCol, nKeyFlags ) }

   ACTIVATE WINDOW oWnd

return   nil

function BuildMenu()
local oMenu, oItem

   MENU oMenu
      MENUITEM   "test"
      MENU
         MENUITEM   "One"
            MENU
               MENUITEM   "First"  ACTION oItem:SetCheck( ! oItem:lChecked )
               MENUITEM   "Second"
            ENDMENU
         MENUITEM oItem   PROMPT   "Two"
         MENUITEM   "Three"
      ENDMENU
   ENDMENU

return oMenu

function BuildMenu2(oCtrl, nRow, nCol)
local oMenu, oItem

   MENU oMenu POPUP
      MENUITEM   "test"
      MENU
         MENUITEM   "One"
            MENU
               MENUITEM   "First"   ACTION oItem:SetCheck( lChecked := ! lChecked )
               MENUITEM   "Second"
            ENDMENU
         if lChecked   
            MENUITEM oItem PROMPT "Two" CHECKED 
         else 
            MENUITEM oItem PROMPT "Two"
         endif      
         MENUITEM   "Three"
      ENDMENU
   ENDMENU

   ACTIVATE POPUP oMenu  OF oCtrl AT nRow, nCol

return oMenu
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Jimmy
Posts: 1740
Joined: Thu Sep 05, 2019 5:32 am
Location: Hamburg, Germany
Has thanked: 2 times

Re: MenuItem:SetCheck() and POPUP Menu ?

Post by Jimmy »

hi Antonio,

thx for your Sample.
Antonio Linares wrote:Here you have your example modified to work as you want:

Code: Select all | Expand

static lChecked := .F.

         if lChecked   
            MENUITEM oItem PROMPT "Two" CHECKED 
         else 
            MENUITEM oItem PROMPT "Two"
         endif      
 
to use static lChecked is clear
but Idea to use different MENUITEM ... GREAT :D
greeting,
Jimmy
Post Reply