Página 1 de 1

Menu Popup explanation

Publicado: Jue Mar 17, 2005 11:15 am
por Giuseppe Bogetti
Hi,
In the statusbar of my app I've added a panel to switch language of
application as you see in attached image.
In the OnInitialize event I use this code
// Status bar
WITH OBJECT ::oBackStatus
:oImageList:Add( "BMP_LANGUAGE" )
:oImageList:Add( "BMP_CHG_OFF" )
:oImageList:Add( "BMP_CHG_ON" )
:aItems[ tSTATUS_LANG ]:nImage := 1
:aItems[ tSTATUS_LANG ]:OnClick := { |oSender, x, y| ::FormLanguageSelect( oSender, x, y ) }
END WITH
This is the methods used to activate popup menu
METHOD FormLanguageSelect( oSender, x, y ) CLASS TBackup
LOCAL oMenu AS OBJECT
oMenu := GetLanguagePopupMenu( Self )
IF !( oMenu == NIL )
ACTIVATE POPUP oMenu OF Self AT y, x
ENDIF
RETURN Nil
These are the two functions that actually build the popup menu
//---------------------------------------------------------- --------------------
// Return language popup menu
//
FUNCTION GetLanguagePopupMenu( oDlg )
LOCAL aLang AS ARRAY
LOCAL oRetval AS OBJECT
LOCAL nI, nLen AS NUMERIC
aLang := GetLanguages()
nLen := Len( aLang )
IF ( nLen > 0 )
oRetval := TMenu():Create( oDlg, TRUE )
FOR nI := 1 TO nLen
WITH OBJECT TMenuItem():New( oRetval )
:cText := aLang[ nI, 2 ]
:OnClick := GetLanguagePopupMenuAction( oDlg, aLang[ nI, 2 ] )
:Create()
END WITH
NEXT
ENDIF
RETURN oRetval
//---------------------------------------------------------- --------------------
// Return language popup action for single language
//
FUNCTION GetLanguagePopupMenuAction( oDlg, nID )
RETURN {|| oDlg:BackLanguage( nID, FALSE ) }
If I trace through the debugger the popup menu is built correctly but the
call to ACTIVATE POPUP doesn't show anything and returns immediatly.
Any hints ? What am I doing wrong ?
--
Best regards,
Giuseppe Bogetti
B.G. Soft
Cuneo - Italy
--

Menu Popup explanation

Publicado: Jue Mar 17, 2005 11:35 am
por Giuseppe Bogetti
In data Thu, 17 Mar 2005 11:15:58 +0100, Giuseppe Bogetti ha scritto:
Hi,
I've found the error. There was an error in the function that build the
popup.
Now the popup is built but shown using coord of panel. But now I face a
couple of problems.
1) I need to convert panel coords to screen coords.
Can I use winApi ClientToScreen to do this convertion ? How ?
2) Using activate popup the associated action is not executed.
I've seen that the command is translated to a TrackPopupMenu() call with
TPM_RETURNCMD as flag and WIN32SDK API Docs says that using this style the
menu ID of the item selected is returned.
Is it right ?
How can I set the menu ID of each item ?
--
Best regards,
Giuseppe Bogetti
B.G. Soft
Cuneo - Italy

Menu Popup explanation

Publicado: Jue Mar 17, 2005 11:35 am
por Giuseppe Bogetti
In data Thu, 17 Mar 2005 11:15:58 +0100, Giuseppe Bogetti ha scritto:
Hi,
I've found the error. There was an error in the function that build the
popup.
Now the popup is built but shown using coord of panel. But now I face a
couple of problems.
1) I need to convert panel coords to screen coords.
Can I use winApi ClientToScreen to do this convertion ? How ?
2) Using activate popup the associated action is not executed.
I've seen that the command is translated to a TrackPopupMenu() call with
TPM_RETURNCMD as flag and WIN32SDK API Docs says that using this style the
menu ID of the item selected is returned.
Is it right ?
How can I set the menu ID of each item ?
--
Best regards,
Giuseppe Bogetti
B.G. Soft
Cuneo - Italy

Menu Popup explanation

Publicado: Jue Mar 17, 2005 12:39 pm
por ignacio
Giusseppe,
> 1) I need to convert panel coords to screen coords.
> Can I use winApi ClientToScreen to do this convertion ? How ?
METHOD ClientToScreen( @x, @y ) descedendt from TControl
OR
FUNCTION ClientToScreen( hWnd, @aPoint | @nX, @nY )
> 2) Using activate popup the associated action is not executed.
> I've seen that the command is translated to a TrackPopupMenu() call with
> TPM_RETURNCMD as flag and WIN32SDK API Docs says that using this style the
> menu ID of the item selected is returned.
Try to do it more simple, for example:
METHOD StatusBar1ContextMenu( oSender, nPosX, nPosY ) CLASS TForm1
local oPopup
MENU oPopup POPUP
MENUITEM "One" ACTION ...
MENUITEM "Two" ACTION ...
ENDMENU
oSender:ShowPopupMenu( oPopup, nPosX, nPosY )
RETURN Nil
Regards,

Menu Popup explanation

Publicado: Jue Mar 17, 2005 12:39 pm
por InvalidAccount
Giusseppe,
> 1) I need to convert panel coords to screen coords.
> Can I use winApi ClientToScreen to do this convertion ? How ?
METHOD ClientToScreen( @x, @y ) descedendt from TControl
OR
FUNCTION ClientToScreen( hWnd, @aPoint | @nX, @nY )
> 2) Using activate popup the associated action is not executed.
> I've seen that the command is translated to a TrackPopupMenu() call with
> TPM_RETURNCMD as flag and WIN32SDK API Docs says that using this style the
> menu ID of the item selected is returned.
Try to do it more simple, for example:
METHOD StatusBar1ContextMenu( oSender, nPosX, nPosY ) CLASS TForm1
local oPopup
MENU oPopup POPUP
MENUITEM "One" ACTION ...
MENUITEM "Two" ACTION ...
ENDMENU
oSender:ShowPopupMenu( oPopup, nPosX, nPosY )
RETURN Nil
Regards,

Menu Popup explanation

Publicado: Jue Mar 17, 2005 2:12 pm
por Giuseppe Bogetti
In data Thu, 17 Mar 2005 12:39:53 +0100, Ignacio Ortiz de Zúñiga ha
scritto:
Ignacio,
Thanks
> Try to do it more simple, for example:
It seems that I have the "gift" to always keep the longer road :-(
--
Best regards,
Giuseppe Bogetti
B.G. Soft
Cuneo - Italy

Menu Popup explanation

Publicado: Jue Mar 17, 2005 2:12 pm
por Giuseppe Bogetti
In data Thu, 17 Mar 2005 12:39:53 +0100, Ignacio Ortiz de Zúñiga ha
scritto:
Ignacio,
Thanks
> Try to do it more simple, for example:
It seems that I have the "gift" to always keep the longer road :-(
--
Best regards,
Giuseppe Bogetti
B.G. Soft
Cuneo - Italy