PDA

View Full Version : Add Menu to a view or dialog



David Martinko
3-Aug-2007, 11:42 PM
I started with code from Clayton Schirmer and added some extra stuff....
1) I converted the words to English.
2) I changed the popup menu to be a child of the main menu item
3) I changed how the menus are located by using the actual size instead of
calculating the size based on the number of characters in the label.
4) I changed how the popup appears so that it always appears directly below
and in-line with it's parent menu item. It used to locate based on the mouse
location when you click.... but not anymore.
5) Removed settting the size of the textbox since it auto-sizes by default.
6) Reduced the spacing between menu items from 4 to 2.

=Dave Martinko

Class cFloatingPopupMenu is a FloatingPopupMenu
Procedure Set GUILocation Integer iHi Integer iLow
Move (hi(Absolute_Guiorigin(parent(self)))) to iHi
Move (low(Absolute_Guiorigin(parent(self)))) to iLow
Add (hi(GUISize(Parent(Self)))) to iHi
Forward Set GUILocation to iHi iLow
End_Procedure // Set GUILocation
End_Class // cFloatingPopupMenu

#COMMAND Begin_Menu

Object !1_Menu is a TextBox
Set Label to ( " " + !2 + " ")
Set Transparent_State to True

Procedure End_Construct_Object
Forward Send End_Construct_Object
Handle hoObj
Integer iCol

Get phoLastMenuID to hoObj
If (hoObj<>0) Begin
Move (Low(Location(hoObj))+Low(Size(hoObj))) to iCol
End
Set Location to 1 (iCol+2)
Set phoLastMenuID to Self
End_Procedure


Procedure Mouse_Down
Register_Object !1_SubMenu
Set Border_Style to Border_StaticEdge
Send Popup of !1_SubMenu
Set Border_Style to Border_None
End_Procedure // OnClick

Object !1_SubMenu is a cFloatingPopupMenu
#ENDCOMMAND

#COMMAND End_Menu2
End_Object
End_Object
#ENDCOMMAND

#COMMAND Sub_Menu
On_Item !1 !2 !3 !4
#ENDCOMMAND

//In the view, create two properties:
//Property Integer pMenuCol Public 0
Property Handle phoLastMenuID Public 0

//Finally, the code to create the menu bar at the view:
Begin_Menu File '&File'
Sub_Menu '&Clear' Send Request_Clear
Sub_Menu '&Save' Send Request_Save
End_Menu2

Begin_Menu Teste '&Test'
Sub_Menu 'Test 1' Send None
Sub_Menu 'Test 2' Send None
Sub_Menu 'Test 3' Send None
Sub_Menu 'Test 4' Send None
End_Menu2