Page 1 of 1

Place toolbars anywhere

Posted: Tue Jan 29, 2008 10:15 pm
by Trond
This lets you place a toolbar anywhere on a window, which is a simple way to get a bunch of flat image buttons.

Code: Select all

Procedure StopToolbarAutoAlign(Toolbar)
  T = ToolBarID(Toolbar)
  SetWindowLong_(T, #GWL_STYLE, GetWindowLong_(T, #GWL_STYLE) | #CCS_NODIVIDER)
  SetWindowLong_(T, #GWL_STYLE, GetWindowLong_(T, #GWL_STYLE) | #CCS_NOPARENTALIGN)
  SetWindowLong_(T, #GWL_STYLE, GetWindowLong_(T, #GWL_STYLE) | #CCS_NORESIZE)
EndProcedure

Procedure MakeToolbarVertical(Toolbar)
  Protected Count
  Protected hTB = ToolBarID(Toolbar)
  SetWindowLong_(hTB, #GWL_STYLE, GetWindowLong_(hTB, #GWL_STYLE) | #TBSTYLE_WRAPABLE | #CCS_NOPARENTALIGN)
  Count = SendMessage_(hTB, #TB_BUTTONCOUNT, 0, 0)
  SendMessage_(hTB, #TB_SETROWS, Count | 1 << 16, @tbr.RECT)
EndProcedure

OpenWindow(0, 0, 0, 512, 384, "", #PB_Window_ScreenCentered | #PB_Window_SystemMenu)
CreateGadgetList(WindowID(0))
CreateToolBar(0, WindowID(0))
ToolBarStandardButton(0, 0)
ToolBarStandardButton(0, 1)
ToolBarStandardButton(0, 2)
ToolBarStandardButton(0, 3)


StopToolbarAutoAlign(0)
T = ToolBarID(0)

MoveWindow_(ToolBarID(0), 0, 100, 512, 22, 1)

Repeat
  Select WaitWindowEvent()
    Case #PB_Event_CloseWindow
      Break
  EndSelect
ForEver

Support functions:

Code: Select all

Procedure ToolbarX(Toolbar)
  GetWindowRect_(ToolBarID(Toolbar), @R.RECT)
  W = GetParent_(ToolBarID(Toolbar))
  ScreenToClient_(W, @R)
  ProcedureReturn R\left
EndProcedure

Procedure ToolbarY(Toolbar)
  GetWindowRect_(ToolBarID(Toolbar), @R.RECT)
  W = GetParent_(ToolBarID(Toolbar))
  ScreenToClient_(W, @R)
  ProcedureReturn R\top
EndProcedure

Procedure ToolbarR(Toolbar)
  GetWindowRect_(ToolBarID(Toolbar), @R.RECT)
  W = GetParent_(ToolBarID(Toolbar))
  ScreenToClient_(W, @R+8)
  ProcedureReturn R\Right
EndProcedure

Procedure ToolbarB(Toolbar)
  GetWindowRect_(ToolBarID(Toolbar), @R.RECT)
  W = GetParent_(ToolBarID(Toolbar))
  ScreenToClient_(W, @R+8)
  ProcedureReturn R\Bottom
EndProcedure

Procedure ToolbarButtonSize(Toolbar, *S.SIZE)
  SendMessage_(ToolBarID(Toolbar), #TB_GETITEMRECT, 0, @R.RECT)
  *S\cx = R\right-r\left
  *S\cy = R\bottom-r\top
EndProcedure

Posted: Tue Jan 29, 2008 10:20 pm
by srod
Nice. I've always used containers to position toolbars, but not any longer! :wink:

Thanks.

Posted: Tue Jan 29, 2008 10:33 pm
by Trond
Oups, it gave me a strange redraw problem... I should have tested it a bit more.

Edit: I fixed it. It should work now.

Posted: Sun Feb 03, 2008 2:12 pm
by Trond
I added functions to get the position of the toolbar and the position of the right/bottom borders, and fixed a small error in the original function.

Also I added an adapted version of Sparkie's vertical toolbar.

Posted: Sun Feb 03, 2008 4:13 pm
by akj
Can

Code: Select all

MakeToolbarVertical(0)
be used in conjunction with

Code: Select all

StopToolbarAutoAlign(0)
and/or

Code: Select all

MoveWindow_(ToolBarID(0), 50, 100, 200, 22, 1)
?

I cannot seem to get a combination to work.

Posted: Sun Feb 03, 2008 7:13 pm
by Trond
For the toolbar to stay vertical you need to resize it to the correct dimensions. If you set the width to more than the width of one button it will become horizontal again. And if you set the height to 22 pixels it won't be very vertical either.

Use ToolbarButtonSize() to get the correct width for vertical toolbars.

Posted: Sun Feb 03, 2008 7:39 pm
by akj
@Trond
Thank you for your clues. The relevant code I produced is

Code: Select all

MakeToolbarVertical(0)
StopToolbarAutoAlign(0)
width = 40
MoveWindow_(ToolBarID(0), 50, 100, width, 200, 1)
Under Windows ME, the results of changing the width value are interesting:
Width 23 (or slightly less) .. 45 gives a vertical toolbar
Width 46 .. 68 gives a square toolbar
Width 69 .. 91 gives an L-shaped toolbar
Width >=92 gives a horizontal toolbar.

Posted: Thu Feb 07, 2008 9:16 pm
by Amnesty
I m too stupid to get the vertical toolbar work in combination with MDIGadget.

Is it possible ?

Posted: Fri Feb 08, 2008 2:30 pm
by Amnesty
Sorry, its possible, but only without Autosize...

Code: Select all

Procedure StopToolbarAutoAlign(Toolbar) 
  T = ToolBarID(Toolbar) 
  SetWindowLong_(T, #GWL_STYLE, GetWindowLong_(T, #GWL_STYLE) | #CCS_NODIVIDER) 
  SetWindowLong_(T, #GWL_STYLE, GetWindowLong_(T, #GWL_STYLE) | #CCS_NOPARENTALIGN) 
  SetWindowLong_(T, #GWL_STYLE, GetWindowLong_(T, #GWL_STYLE) | #CCS_NORESIZE) 
EndProcedure 

Procedure MakeToolbarVertical(Toolbar) 
  Protected Count 
  Protected hTB = ToolBarID(Toolbar) 
  SetWindowLong_(hTB, #GWL_STYLE, GetWindowLong_(hTB, #GWL_STYLE) | #TBSTYLE_WRAPABLE | #CCS_NOPARENTALIGN) 
  Count = SendMessage_(hTB, #TB_BUTTONCOUNT, 0, 0) 
  SendMessage_(hTB, #TB_SETROWS, Count | 1 << 16, @tbr.RECT) 
EndProcedure 

OpenWindow(0, 0, 0, 512, 384, "", #PB_Window_ScreenCentered | #PB_Window_SystemMenu) 
CreateGadgetList(WindowID(0)) 
CreateToolBar(0, WindowID(0)) 
ToolBarStandardButton(0, 0) 
ToolBarStandardButton(0, 1) 
ToolBarStandardButton(0, 2) 
ToolBarStandardButton(0, 3) 


StopToolbarAutoAlign(0) 
T = ToolBarID(0) 
maketoolbarvertical(0)
MDIGadget(0,25,0,WindowWidth(0) - 25,WindowHeight(0),0,0) ; Don't use #PB_MDI_AutoSize       
Repeat 
  Select WaitWindowEvent() 
    Case #PB_Event_CloseWindow 
      Break 
  EndSelect 
ForEver 

Posted: Wed Sep 03, 2008 6:42 am
by Mistrel
I'm not sure where you got the @R+8, Trond but I don't think it's correct.

Code: Select all

Procedure ToolbarX(ToolbarID)
  GetWindowRect_(ToolBarID(ToolbarID),@R.RECT)
  W=GetParent_(ToolBarID(ToolbarID))
  ScreenToClient_(W,@R)
  ProcedureReturn R\left
EndProcedure

Procedure ToolbarY(ToolbarID)
  GetWindowRect_(ToolBarID(ToolbarID),@R.RECT)
  W=GetParent_(ToolBarID(ToolbarID))
  ScreenToClient_(W,@R)
  ProcedureReturn R\top
EndProcedure

Procedure ToolbarW(ToolbarID)
  GetWindowRect_(ToolBarID(ToolbarID),@R.RECT)
  W=GetParent_(ToolBarID(ToolbarID))
  ProcedureReturn R\Right-R\Left
EndProcedure

Procedure ToolBarH(ToolbarID)
  GetWindowRect_(ToolBarID(ToolbarID),@R.RECT)
  W=GetParent_(ToolBarID(ToolbarID))
  ProcedureReturn R\Bottom-R\Top
EndProcedure

Procedure ToolbarButtonSize(ToolbarID, *S.SIZE)
  SendMessage_(ToolBarID(ToolbarID),#TB_GETITEMRECT,0,@R.RECT)
  *S\cx=R\right-r\left
  *S\cy=R\bottom-r\top
EndProcedure

Procedure StopToolbarAutoAlign(ToolbarID)
  T=ToolBarID(ToolbarID)
  SetWindowLong_(T,#GWL_STYLE,GetWindowLong_(T,#GWL_STYLE)|#CCS_NODIVIDER)
  SetWindowLong_(T,#GWL_STYLE,GetWindowLong_(T,#GWL_STYLE)|#CCS_NOPARENTALIGN)
  SetWindowLong_(T,#GWL_STYLE,GetWindowLong_(T,#GWL_STYLE)|#CCS_NORESIZE)
EndProcedure

Procedure MakeToolbarVertical(ToolbarID)
  Protected Count
  Protected hTB=ToolBarID(ToolbarID)
  SetWindowLong_(hTB,#GWL_STYLE,GetWindowLong_(hTB,#GWL_STYLE)|#TBSTYLE_WRAPABLE|#CCS_NOPARENTALIGN)
  Count=SendMessage_(hTB,#TB_BUTTONCOUNT,0,0)
  SendMessage_(hTB,#TB_SETROWS,Count|1<<16,@tbr.RECT)
EndProcedure

Posted: Sat Sep 13, 2008 9:40 am
by Trond
Mistrel wrote:I'm not sure where you got the @R+8, Trond but I don't think it's correct.
It is surely correct. ToolbarR() returns the position of the right edge of the toolbar inside the parent. ToolbarB() returns the position of the bottom edge inside the parent. They do not return the width/height.