GTWVG - BuildMainMenu() some explanations needed

159 views
Skip to first unread message

Zoran Sibinovic

unread,
Jan 20, 2012, 4:11:47 PM1/20/12
to Harbour Users
Hi,

in demowvg.prg we have a main menu built with BuildMainMenu()
I want to insert a new item and disable a item in the example below
As an example, this needed actions are taken from MENU1(1)
depending on some circumstances.

I have tried some variants but without success.

please for an explanation of how to use the adequate methods.

*******************
Main()
.....
BuildMainMenu()
...

*********************************
FUNCTION BuildMainMenu()
LOCAL oMenu,cSection, i

LOCAL g_oMenuBar := WvgSetAppWindow():menuBar()

oMenu := WvgMenu():new( g_oMenuBar, , .t. ):create()
oMenu:caption := "Unosi"

oMenu:AddItem( "Knjizenje" , {|| MENU1(1) } )
oMenu:AddItem( "Uknjizavanje naloga", {|| MENU1(2) } )
oMenu:AddItem( "Unos", {|| MENU1(3) } ) // insert new item
oMenu:AddItem( "Promena , {|| MENU1(4) } ) // between
oMenu:AddItem( "Unos/Promena pozicija" , {|| MENU1(5) } )
oMenu:AddItem( "Vracanje naloga", {|| MENU1(7) } )
g_oMenuBar:addItem( { oMenu, "Unosi" } )

oMenu := WvgMenu():new( g_oMenuBar, , .t. ):create()
oMenu:caption := "Pregledi i Stampe"
oMenu:AddItem( "Kartica" , { || MENU1(7) } ) // make this disabled
oMenu:AddItem( "Glavna knjiga", { || PREGGK() } )
oMenu:AddItem( "IOS" , { || IOS1() } )
g_oMenuBar:addItem( { oMenu, "Pregledi i Stampe" } )

RETURN nil

Thanks

Zoran

Pritpal Bedi

unread,
Jan 20, 2012, 4:33:52 PM1/20/12
to Harbour Users
Hi

> please for an explanation of how to use the adequate methods.

FUNCTION Main()
LOCAL aMenus := BuildMainMenu()

// If you are adding a new item in prompt 1 of menubar
aMenus[ 1 ]:addItem( "Promena , {|| MENU1(4) } )

// If you are to insert a new item in prompt 1 of menubar
//
// NOT IMPLEMENTED YET
aMenus[ 1 ]:insItem( "Promena , {|| MENU1(4) } )

// If you want to disable prompt number 1 of prompt 2 of menubar
aMenus[ 2 ]:disableItem( 1 ) // Prompts ordinal position

RETURN NIL

 FUNCTION BuildMainMenu()
  LOCAL oMenu,oMenu1,cSection, i

 LOCAL g_oMenuBar := WvgSetAppWindow():menuBar()

 oMenu := WvgMenu():new( g_oMenuBar, , .t. ):create()
oMenu:caption := "Unosi"

oMenu:AddItem( "Knjizenje"  , {|| MENU1(1) } )
oMenu:AddItem( "Uknjizavanje naloga", {|| MENU1(2) } )
oMenu:AddItem( "Unos/Promena pozicija" , {|| MENU1(5) } )
oMenu:AddItem( "Vracanje naloga", {|| MENU1(7) } )
g_oMenuBar:addItem( { oMenu, "Unosi" } )

oMenu1 := WvgMenu():new( g_oMenuBar, , .t. ):create()
oMenu1:caption := "Pregledi i Stampe"
 oMenu1:AddItem( "Kartica" , { || MENU1(7) } )   // make this disabled
oMenu1:AddItem( "Glavna knjiga", { || PREGGK() } )
oMenu1:AddItem( "IOS" , { || IOS1()  } )
g_oMenuBar:addItem( { oMenu1, "Pregledi i Stampe" } )

Return { oMenu, oMenu1 }


Hope it will solve your issue.

Pritpal Bedi

Zoran Sibinovic

unread,
Jan 20, 2012, 5:26:12 PM1/20/12
to Harbour Users
Hi Pritpal,

thanks for the answer

all the things work

I already saw that the :insItem method
wasn't implemented yet.
It will be nice, when you will have time.

In this moment I think to try some :deleteall method
and then readd the items as resorted with the one "inserted".

Thanks again

Zoran




José M. C. Quintas

unread,
Jan 20, 2012, 6:56:55 PM1/20/12
to harbou...@googlegroups.com
I make my menus, in console, in the style below.
Time ago I convert to gtwvg, but lost source that I put in harbour folder (I
restore original Harbour and don't save my folders)
Source below is not tested.
I would like to store procedure name in menu, but I don't know how make
this.
Parts with comments in last 2 functions: MakeMenu() and ActivateMenu()

It's a good way to control by password, because options are only an array,
an have name of procedure.
After change array, create the menu.
I think it is an good sample to insert into gtwvg/tests folder (when
completed).

oMenu := CreateMainMenu()
SetColor( "N/W,N/GR*,,,N/W*" )
Wvt_SetMenu( oMenu:hMenu )
.....


Function CompleteMenu()

Local aMenu := {}
Private mMenuLevel := 0, mMenuOpt := {}
mMenuLevel := 0
mMenuOpt := {}
MenuOption("Option 1")
MenuDrop()
MenuOption("Option 1.1","test11")
MenuOption("Option 1.2","test12")
MenuUnDrop()
MenuOption("Option 2")
MenuDrop()
MenuOption("Option 2.1","test21")
MenuOption("Option 2.2")
MenuDrop()
MenuOption("Option 2.2.1","test221")
MenuUnDrop()
MenuUnDrop()
Return aMenu

Static Function MenuOption(mPrompt,mProg)
Local nCont
Local mNow := mMenuOpt
For nCont = 1 to mMenuLevel
mNow := mNow[Len(mNow)]
If ValType(mNow[2]) # "A"
mNow[2] := {}
Endif
mNow := mNow[2]
Next
Aadd(mNow,{mPrompt,{},mProg})
Return NIL

Static Function MenuDrop()
memvar mMenuLevel
mMenuLevel++
return NIL

Static Function MenuUnDrop()
memvar mMenuLevel
mMenuLevel--
return NIL

Function CreateMainMenu()
aMenu := CompleteMenu()
// CheckPassword(aMenu,user,password)
oMenu := wvtMenu():New():Create
MakeMenu(oMenu,aMenu)
Return oMenu

Static Function MakeMenu(oMenu,aMenu)
Local ThisOption, nCont
For nCont = 1 To Len(aMenu)
If Len(aMenu[nCont,2]) > 0 // if have an submenu
ThisOption := wvtMenu():New():Create
ThisOption:Caption := aMenu[nCont,1]
MakeMenu(ThisOption,aMenu[nCont,2])
oMenu:AddItem("",ThisOption)
Else
oMenu:AddItem(aMenu[nCont,1],aMenu[nCont,3] ) // string???
Endif
Next
Return oMenu

Static Function ActivateMenu( oMenu ) // from sample in
harbour/contrib/gtwvg/tests
LOCAL nMenu := Wvt_GetLastMenuEvent()
LOCAL aMenuItem
IF !EMPTY( nMenu )
IF HB_ISOBJECT( oMenu )
IF !EMPTY( aMenuItem := oMenu:FindMenuItemById( nMenu ) )
if .Not. Empty[ WVT_MENU_ACTION]) // string???
do &(aMenuItem[ WVT_MENU_ACTION] //
Endif
//
// IF HB_ISBLOCK( aMenuItem[ WVT_MENU_ACTION ] )
// EVAL( aMenuItem[ WVT_MENU_ACTION ] )
// ENDIF
ENDIF
ENDIF
ENDIF

RETURN NIL


Jos� M. C. Quintas

Zoran Sibinovic

unread,
Jan 24, 2012, 4:31:15 AM1/24/12
to Harbour Users
Hi,

the improvements in the menu are all ok,

another question

It is possible, with some methods, to change the menu items text
on the already built menu?

I've already looked in the class, but haven't find some way to do
that.

Thanks

Zoran

Pritpal Bedi

unread,
Jan 24, 2012, 2:24:06 PM1/24/12
to Harbour Users
Hi

> It is possible, with some methods, to change the menu items text
> on the already built menu?

It seems possible.
Will implement shortly.

Pritpal Bedi
Reply all
Reply to author
Forward
0 new messages