Menu usando browse

Projeto HwGui - Biblioteca visual para Harbour/xHarbour

Moderador: Moderadores

Avatar do usuário
JoséQuintas
Administrador
Administrador
Mensagens: 20267
Registrado em: 26 Fev 2007 11:59
Localização: São Paulo-SP

Menu usando browse

Mensagem por JoséQuintas »

teste.png
Só teste.
left click vai em frente, right click volta.
Se não tiver nível, apenas mostra qual seria o módulo, mas poderia executar.

Código: Selecionar todos

#include "hwgui.ch"
#define DEFAULT_FONTNAME "MS Sans Serif"
#define WND_TOP 0
#define WND_BOTTOM 1

PROCEDURE Main

   LOCAL oFont
   LOCAL xDlg, cTitle := "test"
   LOCAL aList := MenuCria()

   oFont := HFont():Add( DEFAULT_FONTNAME, 0, -11 )
   INIT DIALOG xDlg ;
      CLIPPER ;
      FONT oFont ;
      NOEXIT ;
      TITLE     cTitle ;
      AT       0, 0 ;
      SIZE      1024, 768
      // BACKCOLOR COLOR_WHITE

   xDlg:cargo := {}
   BrowseMenuBr( xDlg, 10, 10, aList, "PRINCIPAL", 0 )
   ACTIVATE DIALOG xDlg CENTER

   RETURN

STATIC FUNCTION BrowseMenuBr( xDlg, nRow, nCol, aList, cTitulo, nStack )

   LOCAL xBrowse, aBrowseList := {}, aItem, xDlgMenu

   hb_Default( @nRow, 0 )
   hb_Default( @nCol, 0 )
   nStack += 1
   FOR EACH aItem IN aList
      AAdd( aBrowseList, { aItem[1] } )
   NEXT
   IF nStack != 1
      INIT DIALOG xDlgMenu AT nCol, nRow SIZE 200, ( Len( aList ) + 4 ) * 20
   ENDIF
   @ 0, 0 BROWSE xBrowse OF xDlgMenu ;
      ARRAY ;
      SIZE 200, (Len(aList)+2)*20 ;
      STYLE WS_BORDER + WS_VSCROLL + WS_HSCROLL ;
      ON CLICK { || browse_click( xDlg, xBrowse, aList, nRow, nCol, nStack ) } ;
      ON RIGHTCLICK { || BrowseDestroy( xDlg, xBrowse, xDlgMenu, nStack ) }

   AAdd( xDlg:Cargo, { xBrowse, xDlgMenu } )
   hwg_CREATEARLIST( xBrowse, aBrowseList )

   xBrowse:aColumns[1]:Heading := cTitulo
   xBrowse:aColumns[1]:length := 50
   xBrowse:SetFocus()
   IF nStack != 1
      xDlgMenu:Activate()
   ENDIF

   RETURN Nil

STATIC FUNCTION Browse_click( xDlg, xBrowse, aList, nRow, nCol, nStack )

   LOCAL nItem

   DO WHILE nStack < Len( xDlg:Cargo )
      Atail( xDlg:Cargo )[ 2 ]:Close()
      aSize( xDlg:Cargo, Len( xDlg:Cargo ) - 1 )
   ENDDO
   nItem := xBrowse:nCurrent
   IF Empty( aList[ nItem, 2 ] )
      hwg_MsgInfo( aList[ nItem, 3 ] )
   ELSE
      BrowseMenuBr( xDlg, nRow + 10, nCol + 50, aList[ nItem, 2 ], aList[ nItem, 1 ], nStack )
   ENDIF
   (xDlg);(xBrowse);(aList)

   RETURN Nil

FUNCTION BrowseDestroy( xDlg, xBrowse, xDlgMenu, nStack )

   IF ValType( xDlgMenu ) == "O" .AND. nStack > 1
      xDlgMenu:Close()
   ENDIF
   (xDlg);(xBrowse)

   RETURN Nil
Não tem o fonte da criação do array do menu, é que está muito grande.
Basicamente é { "texto", {}, "modulo", { || modulo() } )
Elemento 1: nome que vai no menu
Elemento 2: possível submenu com mesma estrutura
Elemento 3: nome do modulo, pode ser chamado com Do( modulo )
Elemento 4: não precisa, é mais pra forçar compilação do módulo, caso esteja em lib.
Uma variável com todo menu, e os browses encima disso.
José M. C. Quintas
Harbour 3.2, mingw, gtwvg mt, fivewin 25.04, multithread, dbfcdx, MySQL, ADOClass, PDFClass, SefazClass, (hwgui mt), (hmg3), (hmg extended), (oohg), PNotepad, ASP, stored procedure, stored function, Linux (Flagship/harbour 3.2)
"The world is full of kings and queens, who blind our eyes and steal our dreams Its Heaven and Hell"

https://github.com/JoseQuintas/
Responder