MenuItem:SetCheck() and POPUP Menu ?

MenuItem:SetCheck() and POPUP Menu ?

Postby Jimmy » Mon Oct 31, 2022 4:44 am

hi,

does o:SetCheck() work when it is use as POPUP Menu :?:
if Yes, how :idea:
greeting,
Jimmy
User avatar
Jimmy
 
Posts: 1732
Joined: Thu Sep 05, 2019 5:32 am
Location: Hamburg, Germany

Re: MenuItem:SetCheck() and POPUP Menu ?

Postby Antonio Linares » Mon Oct 31, 2022 7:14 am

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 view  RUN
#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
Antonio Linares
Site Admin
 
Posts: 42120
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Re: MenuItem:SetCheck() and POPUP Menu ?

Postby Jimmy » Mon Oct 31, 2022 8:05 am

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 view  RUN
#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
Jimmy
 
Posts: 1732
Joined: Thu Sep 05, 2019 5:32 am
Location: Hamburg, Germany

Re: MenuItem:SetCheck() and POPUP Menu ?

Postby Enrico Maria Giordano » Mon Oct 31, 2022 8:40 am

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
Enrico Maria Giordano
 
Posts: 8718
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia

Re: MenuItem:SetCheck() and POPUP Menu ?

Postby Antonio Linares » Mon Oct 31, 2022 1:50 pm

Dear Jimmy,

Here you have your example modified to work as you want:
Code: Select all  Expand view  RUN
#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
Antonio Linares
Site Admin
 
Posts: 42120
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Re: MenuItem:SetCheck() and POPUP Menu ?

Postby Jimmy » Mon Oct 31, 2022 10:23 pm

hi Antonio,

thx for your Sample.
Antonio Linares wrote:Here you have your example modified to work as you want:
Code: Select all  Expand view  RUN
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
User avatar
Jimmy
 
Posts: 1732
Joined: Thu Sep 05, 2019 5:32 am
Location: Hamburg, Germany


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: Google [Bot] and 59 guests