Minha solucao para menus popup em toolbar
Posted: Mon Apr 23, 2007 10:03 pm
As modificacoes que fiz foram:
No metodo AddButton acresci o parametro oPopup
No metodo Command critico a existencia de um menu:
O teste foi efetivado usando o TOOLBAR1.PRG com as seguinte modificacoes:
Code: Select all
CLASS TToolBar FROM TControl
DATA nBtnWidth, nBtnHeight
DATA aButtons
DATA oImageList
DATA lTTBalloon
...
METHOD AddButton( bAction, cToolTip, cText, bWhen, cMsg, ;
oPopup ) //********************* KONECTIVA AUTOMACAO
Code: Select all
...
METHOD AddButton( bAction, cToolTip, cText, bWhen, cMsg, ;
oPopup ) CLASS TToolBar //********************* KONECTIVA AUTOMACAO
AAdd( ::aButtons, { bAction, cToolTip, cMsg, ;
oPopup } ) //********************* KONECTIVA AUTOMACAO
...
Code: Select all
METHOD Command( nWParam, nLParam ) CLASS TToolBar
local nNotifyCode, nID, hWndCtl
local bAction
#ifdef __CLIPPER__
nNotifyCode = nHiWord( nLParam )
nID = nWParam
hWndCtl = nLoWord( nLParam )
#else
nNotifyCode = nHiWord( nWParam )
nID = nLoWord( nWParam )
hWndCtl = nLParam
#endif
if GetClassName( hWndCtl ) == "ToolbarWindow32"
if ( bAction := ::aButtons[ nID ][ 1 ] ) != nil
if ::aButtons[ nID ][ 4 ] != nil
//********************* KONECTIVA AUTOMACAO
nTop := ::nBtnHeight
nLeft := (::nBtnWidth*(nID-1)) + ((::nBtnWidth/2.5)*(nID-1))
::aButtons[ nID ][ 4 ]:Activate( nTop, nLeft, ::oWnd, .f. )
::oWnd:oPopup := nil
//********************* KONECTIVA AUTOMACAO
else
Eval( bAction, Self )
endif
endif
endif
return nil
Code: Select all
#include "FiveWin.ch"
#xcommand DEFINE TBBUTTON ;
[ OF <oToolBar> ] ;
[ ACTION <uAction> ] ;
[ TOOLTIP <cToolTip> ] ;
[ PROMPT <cPrompt> ] ;
[ WHEN <uWhen> ] ;
[ MESSAGE <cMsg> ] ;
[ MENU <oPopup> ] ; //********************* KONECTIVA AUTOMACAO
=> ;
<oToolBar>:AddButton( [<{uAction}>], [<cToolTip>], [<cPrompt>],;
[<{uWhen}>], [<cMsg>],;
[<oPopup>] ) //********************* KONECTIVA AUTOMACAO
static oToolBar
function Main()
local oWnd, oImageList
DEFINE WINDOW oWnd TITLE "FWH - Testing Win32 Toolbars" ;
MENU BuildMenu()
// First we build an ImageList with all the bitmaps
oImageList = TImageList():New( 32, 32 ) // width and height of bitmaps
oImageList:AddMasked( TBitmap():Define( "new",, oWnd ), nRGB( 255, 0, 255 ) )
oImageList:AddMasked( TBitmap():Define( "open",, oWnd ), nRGB( 255, 0, 255 ) )
oImageList:AddMasked( TBitmap():Define( "search",, oWnd ), nRGB( 255, 0, 255 ) )
oImageList:AddMasked( TBitmap():Define( "print",, oWnd ), nRGB( 255, 0, 255 ) )
oImageList:AddMasked( TBitmap():Define( "internet",, oWnd ), nRGB( 255, 0, 255 ) )
oImageList:AddMasked( TBitmap():Define( "keys",, oWnd ), nRGB( 255, 0, 255 ) )
oImageList:AddMasked( TBitmap():Define( "quit",, oWnd ), nRGB( 255, 0, 255 ) )
// Now we create the toolbar and add the buttons
DEFINE TOOLBAR oToolBar OF oWnd SIZE 50, 50 ;
IMAGELIST oImageList BALLOON // tooltips balloon style
oToolBar:SetTextRows( 2 )
MENU oMenuBar1 POPUP //********************* KONECTIVA AUTOMACAO
MENUITEM "Lancar &Ordem producao" ACTION fun()
MENUITEM "&Carteira de O.P.s" ACTION fun()
ENDMENU
DEFINE TBBUTTON OF oToolBar ;
ACTION fun() ;
TOOLTIP "New" ;
PROMPT "&New project" ;
MENU oMenuBar1 //********************* KONECTIVA AUTOMACAO
...