Page 1 of 1

Minha solucao para menus popup em toolbar

Posted: Mon Apr 23, 2007 10:03 pm
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
   ...

Posted: Wed Apr 25, 2007 6:40 am
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.

Posted: Wed Apr 25, 2007 6:58 pm
by Rochinha
Obrigado Amigo!