Minha solucao para menus popup em toolbar

Post Reply
Rochinha
Posts: 309
Joined: Sun Jan 08, 2006 10:09 pm
Location: Brasil - Sao Paulo
Contact:

Minha solucao para menus popup em toolbar

Post by Rochinha »

As modificacoes que fiz foram:

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
No metodo AddButton acresci o parametro oPopup

Code: Select all

...
METHOD AddButton( bAction, cToolTip, cText, bWhen, cMsg, ;
                  oPopup ) CLASS TToolBar //********************* KONECTIVA AUTOMACAO

   AAdd( ::aButtons, { bAction, cToolTip, cMsg, ;
                       oPopup } ) //********************* KONECTIVA AUTOMACAO
   ...
No metodo Command critico a existencia de um menu:

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
O teste foi efetivado usando o TOOLBAR1.PRG com as seguinte modificacoes:

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
   ...
User avatar
Antonio Linares
Site Admin
Posts: 37481
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain
Contact:

Post by Antonio Linares »

Rochinha,

De esa forma no puedes cambiar el contenido del Popup menú.

De la forma que lo hace FWH, sí puedes cambiar el popup menú cada vez que lo vas a usar.
regards, saludos

Antonio Linares
www.fivetechsoft.com
Rochinha
Posts: 309
Joined: Sun Jan 08, 2006 10:09 pm
Location: Brasil - Sao Paulo
Contact:

Post by Rochinha »

Obrigado Amigo!
Post Reply