FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin for Harbour/xHarbour MenuItem:SetCheck() and POPUP Menu ?
Posts: 1772
Joined: Thu Sep 05, 2019 05:32 AM
MenuItem:SetCheck() and POPUP Menu ?
Posted: Mon Oct 31, 2022 04:44 AM
hi,

does o:SetCheck() work when it is use as POPUP Menu :?:
if Yes, how :idea:
greeting,

Jimmy
Posts: 44162
Joined: Thu Oct 06, 2005 05:47 PM
Re: MenuItem:SetCheck() and POPUP Menu ?
Posted: Mon Oct 31, 2022 07: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 (fw): Select all Collapse
#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
Posts: 1772
Joined: Thu Sep 05, 2019 05:32 AM
Re: MenuItem:SetCheck() and POPUP Menu ?
Posted: Mon Oct 31, 2022 08: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 (fw): Select all Collapse
#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
Posts: 9022
Joined: Thu Oct 06, 2005 08:17 PM
Re: MenuItem:SetCheck() and POPUP Menu ?
Posted: Mon Oct 31, 2022 08: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.
Posts: 44162
Joined: Thu Oct 06, 2005 05:47 PM
Re: MenuItem:SetCheck() and POPUP Menu ?
Posted: Mon Oct 31, 2022 01:50 PM
Dear Jimmy,

Here you have your example modified to work as you want:
Code (fw): Select all Collapse
#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
Posts: 1772
Joined: Thu Sep 05, 2019 05:32 AM
Re: MenuItem:SetCheck() and POPUP Menu ?
Posted: 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 (fw): Select all Collapse
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

Continue the discussion