Changing the Toolbar content

Changing the Toolbar content

Postby codemaker » Tue Feb 07, 2012 11:43 pm

I have for example a toolbar with initial button images on top and on the left I have outlook style butons.

Image

What I need is to dynamicaly change the set of icons on the toolbar when I click some button on any of the vertical left buttons.
The program initialy starts for example with 7 buttons (each has a specific ACTION assigned) in the toolbar and the first button on vertical left is activated.

Now I want to click on the 3rd button on the left and I need to change all the toolbar icons and their coresponding ACTIONs, because the new set of icons will do another set of jobs.
Then later, I need to be able to click on the left on some other button and again, all set of toolbar buttons (and ACTIONS) must change.

Is this possible or I need to do some coding by replacing the each button image in toolbar and assign a new ACTION to it? And also, hide the rest of the buttons etc...

I just started to use Toolbars and I might ask some stupid question, but the documentation for Toolbars is not extensive so I need some help

Thanks
User avatar
codemaker
 
Posts: 208
Joined: Wed Dec 03, 2008 4:48 pm
Location: Belgrade, Serbia

Re: Changing the Toolbar content

Postby ukoenig » Wed Feb 08, 2012 10:34 am

Hello Codemaker,

A Sample to show the Logic changing BMP's and using the same Button with different Actions:

1. define a Array for the used BMP's
2. use => ACTION oButt3:SetFile( aBtn[4][1], aBtn[4][2] ) ;
That will replace on Button-action 2 the Button 3 ( TRASH.BMP )
with the defined BMP's in Arrayelement 4 ( PENDRIVE.BMP )

To use different Actions with on Button,
You need another Array => .T. or .F. for each Button.
With the BMP-change change the Status as well.
It means : .T. = Action 1, .F. = Action 2

In this sample, Button 3 shows on Action the Message : Action 1 ( aAct[3] := .T. ).
After the BMP-change the Action shows the Message : Action 2 ( aAct[3] := .F. defined in Button 2-action ).

Maybe You want to show a BMP disabled as well ?
The Array can be : aBtn[5][4] => BTN_UP, BTN_DOWN, BTN_DISABLE, BTN_OVERMOUSE

FUNCTION changed in FWH 12.01 !!! ( Drive is included )
c_path := GETCURDIR() + "\"
maybe You have to use :
c_path := CURDRIVE() + ":\" + GETCURDIR() + "\"

Image

Code: Select all  Expand view

#include "FiveWin.ch"

static oWnd, oBar, oBrush, cFile, oButtFont, oCursorHand

FUNCTION Main()
LOCAL hDCo, oButt1, oButt2, oButt3, oButt4, oButt5, oButt6
LOCAL aBtn[5][2], aAct[5]

c_path := GETCURDIR() + "\"

// can be : aBtn[5][4] => BTN_UP, BTN_DOWN, BTN_DISABLE, BTN_OVERMOUSE

aBtn[1][1] := c_path + "
\project\ICHAT.BMP"
aBtn[1][2] := c_path + "
\project\ICHAT.BMP"
aAct[1] := .T.

aBtn[2][1] := c_path + "
\project\EXPLORER.BMP"
aBtn[2][2] := c_path + "
\project\EXPLORER.BMP"
aAct[2] := .T.

aBtn[3][1] := c_path + "
\project\TRASH.BMP"
aBtn[3][2] := c_path + "
\project\TRASH.BMP"
aAct[3] := .T.

aBtn[4][1] := c_path + "
\project\PENDRIVE.BMP"
aBtn[4][2] := c_path + "
\project\PENDRIVE.BMP"
aAct[4] := .T.

aBtn[5][1] := c_path + "
\project\PALM.BMP"
aBtn[5][2] := c_path + "
\project\PALM.BMP"
aAct[5] := .T.

oDlgFont := TFont():New("
Arial", ,-14,.F.,.F.,,,,.F.)
oButtFont := TFont():New("
Arial",,-14,.F.,.F.,,,,.F.)
DEFINE CURSOR oCursorHand HAND
SetBalloon( .T. )

// Style
// -------
DEFINE BRUSH oBrush  STYLE "
BRICKS"

DEFINE WINDOW oWnd TITLE "
Testing Source of Bar-Tools"  ;
MENU TMenu():New() BRUSH oBrush

DEFINE BUTTONBAR oBar OF oWnd SIZE 100,80 3DLOOK 2007 LEFT

oBar:oFont := oButtFont
oBar:SetColor( 0)

oBar:bClrGrad = { | lInvert | If( ! lInvert, ;
   { { 0.80,14853684,16314573 }, ;
     { 0.80,16314573,14853684 } }, ;
   { { 0.80,14853684,14853684 }, ;
     { 0.80,14853684,14853684 } } ) }

DEFINE BUTTON oButt1 OF oBar FILE aBtn[1][1], aBtn[1][2] ;
MESSAGE "
Button 1" ;
ACTION MsgAlert( "
Button 1","Attention" ) ;
PROMPT "
Button 1"

oButt1:cToolTip := { "
" + CRLF + "Button 1", "1. Button", 1, 0, 128 }

DEFINE BUTTON oButt2 OF oBar FILE aBtn[2][1], aBtn[2][2] ;
MESSAGE "
Button 2" ;
ACTION ( oButt3:SetFile( aBtn[4][1], aBtn[4][2] ), aAct[3] := .F. ) ;
PROMPT "
Button 2"

oButt2:cToolTip := { "
" + CRLF + "Button 2", "2. Button", 1, 0, 128 }

DEFINE BUTTON oButt3 OF oBar FILE aBtn[3][1], aBtn[3][2] ;
MESSAGE "
Button 3" ;
ACTION ( oButt2:Enable(), ;
                 IIF( aAct[3] = .T., MsgAlert( "
Action 1" ), MsgAlert( "Action 2" ) ) ) ;
PROMPT "
Button 3"

oButt3:cToolTip := { "
" + CRLF + "Button 3", "3. Button", 1, 0, 128 }

DEFINE BUTTON oButt4 OF oBar FILE aBtn[4][1], aBtn[4][2] ;
MESSAGE "
Button 4" ;
ACTION oButt2:Disable() ;
PROMPT "
Button 4"

oButt4:cToolTip := { "
" + CRLF + "Button 4", "4. Button", 1, 0, 128 }

DEFINE BUTTON oButt5 OF oBar FILE aBtn[5][1], aBtn[5][2] ;
MESSAGE "
Button 5" ;
ACTION MsgAlert( "
Button 5","Attention" ) ;
PROMPT "
Button 5"

oButt5:cToolTip := { "
" + CRLF + "Button 5", "5. Button", 1, 0, 128 }


DEFINE BUTTON oButt6 OF oBar FILE c_path + "
\project\Stop.bmp"  MESSAGE "Close" ;
ACTION ( oWnd:End() ) ;
PROMPT "
Close"

oButt6:cToolTip := { "
" + CRLF + "Close BarTools", "Close", 1, 0, 128 }

AEval( oWnd:aControls, { | o | o:oCursor := oCursorHand } )

SET MESSAGE OF oWnd TO "
Bar-Test" ;
CENTERED CLOCK KEYBOARD 2007

ACTIVATE WINDOW oWnd MAXIMIZED ;

RETURN NIL


It seems, FWH is getting more and more popular.
I noticed sometimes more than 20 Guests online.


Best Regards
Uwe :lol:
Since 1995 ( the first release of FW 1.9 )
i work with FW.
If you have any questions about special functions, maybe i can help.
User avatar
ukoenig
 
Posts: 4043
Joined: Wed Dec 19, 2007 6:40 pm
Location: Germany

Re: Changing the Toolbar content

Postby codemaker » Wed Feb 08, 2012 12:59 pm

Thank you Uwe, I apreciate your attention.

I am on FW and this and old forum since the version 1.9.2 and as far as I can tell, the xHB/FWH combination is one of the best for middle sized projects. Even for bigger projects, because we can connect to SQL databases, so there is no much limitation. I use FWH all those years up to now and have no reason to switch to any other language. The only problem is that every new FWH version nakes me trouble in compatibility with xHB.... Have no idea why is that so, but this is a huge problem for me, because I don't have always time to spent days and days adjusting xHB and FWH...
And yes, FWH is very popular because of its efficiency and simplicity of use, giving us a very complex and useful resulting applications.

Regarding the problem I have, I probably was not clear anough, my fault.
I understand the sample you showed to me and this kind of logic works fine on my testings.
As you see I have a vertical array of buttons on the left and when I click on any of these vertical buttons, I need the upper horizontal Toolbar to completely redraw, this time with complete new buttons and actions.
I can use buton image replacements and assigning the new actions to each, but this will be my last option.

- For example, the first vertical button is related to road transportation. When clicked, the upper horizontal Toolbar will show buttons with images for road transport (cars, trucks etc...) and the actions will trigger dialogs about each vechicle in road transport.
- The second button is related to water transportation. When clicked, the upper horisontal Toolbar will show buttons with images for water transport (boats, ferry, ship etc...) and the actions will trigger dialogs about each vechicle in water transport.
- The hird button is related to air transportation. When clicked, the upper horisontal Toolbar will show buttons with images for air transport (planes, helicopters etc...) and the actions will trigger dialogs about each vechicle in air transport.

The problem is that each kind of transport can have different number of buttons. If road transport has 8 buttons in horizontal Toolbar, when the toolbar needs to show air transport which has 5 buttons, I ned to figure out how to "hide" and disable the 3 buttons which are left.
Also if the water transport needs 11 buttons, how can I show them because I am couple of buttons short regarding the road and air transport....

I thought maybe there is a way to ":END()" the existing horizontal toolbar and programatically redefine and show the new toolbar "on the fly" with new images and actions after each button is clicked, depending of the transportation selected.

Maybe I was now more precise, my english is probably not good enough to express myself clearely

Thanks
Boris
User avatar
codemaker
 
Posts: 208
Joined: Wed Dec 03, 2008 4:48 pm
Location: Belgrade, Serbia

Re: Changing the Toolbar content

Postby ukoenig » Wed Feb 08, 2012 1:07 pm

At first, Your English is fine and I understand Your Problem.
Maybe a complete replacement will be a Solution.
I will have a closer look at Your posted Problem.

Best regards
Uwe :lol:
Since 1995 ( the first release of FW 1.9 )
i work with FW.
If you have any questions about special functions, maybe i can help.
User avatar
ukoenig
 
Posts: 4043
Joined: Wed Dec 19, 2007 6:40 pm
Location: Germany

Re: Changing the Toolbar content

Postby Antonio Linares » Wed Feb 08, 2012 2:01 pm

Boris,

You can create and manage as many toolbars as needed :-)

To switch from one toolbar to another is as easy as:
Code: Select all  Expand view

         MENUITEM "&ToolBar1..." ACTION If( oWnd:oTop == oToolBar2, ( oWnd:oTop := oToolBar1, oToolBar2:Hide(), oToolBar1:Show() ), ) MESSAGE "ToolBar 1"
         MENUITEM "T&oolBar2..." ACTION If( oWnd:oTop == oToolBar1, ( oWnd:oTop := oToolBar2, oToolBar1:Hide(), oToolBar2:Show() ), ) MESSAGE "ToolBar 2"
 


Here you have a complete working example:
Code: Select all  Expand view

// Switching toolbars

#include "FiveWin.ch"

static oWnd, oToolBar1, oToolBar2

function Main()

   DEFINE WINDOW oWnd TITLE "FWH - Switching toolsbars" ;
      MENU BuildMenu()

   oToolBar1 = BuildToolBar1( oWnd )
   oToolBar2 = BuildToolBar2( oWnd )
   oToolBar2:Hide()
   oWnd:oTop = oToolBar1

   DEFINE STATUSBAR OF oWnd PROMPT "Toolbars test"

   ACTIVATE WINDOW oWnd MAXIMIZED ;
      ON INIT ( oToolBar2:nWidth := oToolBar1:nWidth )
   
   oToolBar1:oImageList:End()
   oToolBar2:oImageList:End()

return nil

function BuildMenu()

   local oMenu

   MENU oMenu
      MENUITEM "&Project"
      MENU
         MENUITEM "&ToolBar1..." ACTION If( oWnd:oTop == oToolBar2, ( oWnd:oTop := oToolBar1, oToolBar2:Hide(), oToolBar1:Show() ), ) MESSAGE "ToolBar 1"
         MENUITEM "T&oolBar2..." ACTION If( oWnd:oTop == oToolBar1, ( oWnd:oTop := oToolBar2, oToolBar1:Hide(), oToolBar2:Show() ), ) MESSAGE "ToolBar 2"
         SEPARATOR
         MENUITEM "&Exit..." ACTION oWnd:End() MESSAGE "Exit"
      ENDMENU

      MENUITEM "&Edit"
      MENU
         MENUITEM "&Search..." ACTION MsgInfo( "Search" )
         MENUITEM "&Print..." ACTION MsgInfo( "Print" )
      ENDMENU

      MENUITEM "&Utilities"
      MENU
         MENUITEM "&Disable button..." ACTION oToolBar:EnableButton( 3, .f. )
         MENUITEM "&Enable button..." ACTION oToolBar:EnableButton( 3, .t. )
      ENDMENU
   ENDMENU

return oMenu

function BuildToolBar1( oWnd )

   local oToolBar, oImageList
   
   DEFINE IMAGELIST oImageList SIZE 32, 32

   DEFINE IMGBITMAP OF oImageList NAME "new"      COLOR nRGB( 255, 0, 255 )
   DEFINE IMGBITMAP OF oImageList NAME "open"     COLOR nRGB( 255, 0, 255 )
   DEFINE IMGBITMAP OF oImageList NAME "check"    COLOR nRGB( 255, 0, 255 )
   DEFINE IMGBITMAP OF oImageList NAME "search"   COLOR nRGB( 255, 0, 255 )

   DEFINE TOOLBAR oToolBar OF oWnd SIZE 50, 58 ; // 50, 50 ;
      IMAGELIST oImageList BALLOON // tooltips balloon style
   
   oToolBar:SetTextRows( 2 )
   
   DEFINE TBBUTTON OF oToolBar ;
      ACTION  oToolbar:SetText( 1, "Hello" ) ; // Modify first button text
      TOOLTIP "New" ;
      PROMPT  "&New project" ;
      MESSAGE "New"
   
   DEFINE TBBUTTON OF oToolBar ;
      ACTION  oToolBar:SetChecked( 2, .t. ) ; // Set pressed the second button
      TOOLTIP "Open" ;
      PROMPT  "Open project" ;
      MESSAGE "Open"
     
   DEFINE TBSEPARATOR OF oToolBar
   
   DEFINE TBMENU OF oToolBar ;
      ACTION  MsgInfo( "Menu" ) ;
      TOOLTIP "Menu" ;
      PROMPT  "Menu" ;
      MENU    BuildPopup()
   
   DEFINE TBBUTTON OF oToolBar ;
      ACTION  oToolBar:SetChecked( 2, .f. ) ; // MsgInfo( "Search" ) ;
      TOOLTIP "Search" ;
      PROMPT  "Search"

return oToolBar

function BuildToolBar2( oWnd )

   local oToolBar, oImageList
   
   DEFINE IMAGELIST oImageList SIZE 32, 32

   DEFINE IMGBITMAP OF oImageList NAME "print"    COLOR nRGB( 255, 0, 255 )
   DEFINE IMGBITMAP OF oImageList NAME "internet" COLOR nRGB( 255, 0, 255 )
   DEFINE IMGBITMAP OF oImageList NAME "keys"     COLOR nRGB( 255, 0, 255 )
   DEFINE IMGBITMAP OF oImageList NAME "quit"     COLOR nRGB( 255, 0, 255 )

   DEFINE TOOLBAR oToolBar OF oWnd SIZE 50, 58 ; // 50, 50 ;
      IMAGELIST oImageList BALLOON // tooltips balloon style
   
   oToolBar:SetTextRows( 2 )
   
   DEFINE TBBUTTON OF oToolBar ;
      ACTION  MsgInfo( "Print" ) ;
      TOOLTIP "Print a report" ;
      PROMPT  "Print a report"

   DEFINE TBSEPARATOR OF oToolBar
     
   DEFINE TBBUTTON OF oToolBar ;
      ACTION  MsgInfo( "Upgrade" ) ;
      TOOLTIP "Search for new versions" ;
      PROMPT  "Upgrade"
     
   DEFINE TBBUTTON OF oToolBar ;
      ACTION MsgInfo( "Users" ) ;
      TOOLTIP "Users management" ;
      PROMPT "Users"  

   DEFINE TBSEPARATOR OF oToolBar

   DEFINE TBBUTTON OF oToolBar ;
      ACTION  oWnd:End() ;
      TOOLTIP "End Application" ;
      PROMPT  "Exit"
     
return oToolBar

function BuildPopup()

   local oMenu
   
   MENU oMenu POPUP
      MENUITEM "One"   ACTION MsgInfo( "One" )
      MENUITEM "Two"   ACTION MsgInfo( "Two" )
      MENUITEM "Three" ACTION MsgInfo( "Three" )
   ENDMENU
   
return oMenu      
 
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 42087
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Re: Changing the Toolbar content

Postby frose » Wed Feb 08, 2012 2:50 pm

Codemaker,

done it this way:

Code: Select all  Expand view

...
// Define the maximal number of buttons and disable them
   nBtnMax  := 40
   FOR i := nBtnFree TO nBtnMax
      oBtn := TBtnBmp():NewBar(,,,,,, IIf( i == nBtnFree, .T., .F. ), oBar, .F.,,, .F.,,,, "B." + AllTrim( Str( i ) ),,,,,, Upper( "BOTTOM" ),,, .F. )
      oBtn:Disable()
   NEXT i
...
// Define the buttons for the actual modul
         DO WHILE .T.
            IF n <= nBtnMax
               oBar:aControls[ n ]:Enable()
               oBar:aControls[ n ] :cCaption := ...
               oBar:aControls[ n ] :cToolTip := ...
               oBar:aControls[ n ] :cAction := ...
               oBar:aControls[ n ] :bAction := ..
               n ++
            ELSE
               EXIT
            ENDIF
            // Next button
         ENDDO
...
// delete all buttons if swichting the modul
      FOR n := 1 TO nBtnMax
         oBar:aControls[ n ]:Disable()
         oBar:aControls[ n ] :cCaption := ""
         oBar:aControls[ n ] :cToolTip := ""
         oBar:aControls[ n ] :cAction := ""
         oBar:aControls[ n ] :bAction := { || NIL }
      NEXT n
// Define the buttons for the actual modul
...

HTH
Windows 11 Pro 22H2 22621.1848
Microsoft (R) Windows (R) Resource Compiler Version 10.0.10011.16384
Harbour 3.2.0dev (r2008190002)
FWH 23.10 x86
User avatar
frose
 
Posts: 392
Joined: Tue Mar 10, 2009 11:54 am
Location: Germany, Rietberg

Re: Changing the Toolbar content

Postby codemaker » Wed Feb 08, 2012 8:41 pm

Antonio Linares wrote:Boris,

You can create and manage as many toolbars as needed :-)

To switch from one toolbar to another is as easy as:
Code: Select all  Expand view

         MENUITEM "&ToolBar1..." ACTION If( oWnd:oTop == oToolBar2, ( oWnd:oTop := oToolBar1, oToolBar2:Hide(), oToolBar1:Show() ), ) MESSAGE "ToolBar 1"
         MENUITEM "T&oolBar2..." ACTION If( oWnd:oTop == oToolBar1, ( oWnd:oTop := oToolBar2, oToolBar1:Hide(), oToolBar2:Show() ), ) MESSAGE "ToolBar 2"
 



Antonio, thank you for this solution, it is exactly what I need.
Now I can move on :)

BTW: thanks to Uwe and frose too
User avatar
codemaker
 
Posts: 208
Joined: Wed Dec 03, 2008 4:48 pm
Location: Belgrade, Serbia


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: Otto and 86 guests