[Module] Extended ToolBar-Gadget (all OS / DPI)

Applications, Games, Tools, User libs and useful stuff coded in PureBasic
User avatar
Thorsten1867
Addict
Addict
Posts: 1366
Joined: Wed Aug 24, 2005 4:02 pm
Location: Germany

Re: [Module] Extended ToolBar-Gadget (all OS / DPI)

Post by Thorsten1867 »

Update: Toolbar::Disable()
Translated with http://www.DeepL.com/Translator

Download of PureBasic - Modules
Download of PureBasic - Programs

[Windows 11 x64] [PB V5.7x]
tatanas
Enthusiast
Enthusiast
Posts: 199
Joined: Wed Nov 06, 2019 10:28 am
Location: France

Re: [Module] Extended ToolBar-Gadget (all OS / DPI)

Post by tatanas »

I noticed that ImageButtons are redrawn continuously when mouse moves on them.
I have modified _MouseLeaveHandler()

Code: Select all

	Procedure _MouseLeaveHandler()
		Define.i GNum = EventGadget()
		
		If FindMapElement(TBEx(), Str(GNum))
			TBEx()\Buttons\Focus = #NoFocus
			TBEx()\LastFocus = -1 ; added
			DisableToolTip_()
			Draw_()
		EndIf  
		
	EndProcedure
and _MouseMoveHandler() to prevent this

Code: Select all

									; Focus
									TBEx()\Items()\State = #Focus
									TBEx()\Buttons\Focus = ItemIndex
									TBEx()\LastFocus     = TBEx()\Buttons\Focus

									If LastButtonFocus = ItemIndex : Continue : EndIf  ; added	

									; Tooltip available
									If TBEx()\Items()\ToolTip
										TBEx()\ToolTip = ItemIndex
										GadgetToolTip(TBEx()\CanvasNum, TBEx()\Items()\ToolTip)
									Else 
										DisableToolTip_()
									EndIf
									
									If TBEx()\Buttons\State <> #Click : DrawSingleButton_(ItemIndex) : EndIf
									
								EndIf
								
							Default
								
								TBEx()\Items()\State = #False
								TBEx()\Buttons\Focus = #NoFocus
								TBEx()\LastFocus = -1 ; added									
Last edited by tatanas on Wed Jun 22, 2022 10:01 am, edited 2 times in total.
Windows 10 Pro x64
PureBasic 6.04 x64
tatanas
Enthusiast
Enthusiast
Posts: 199
Joined: Wed Nov 06, 2019 10:28 am
Location: France

Re: [Module] Extended ToolBar-Gadget (all OS / DPI)

Post by tatanas »

Another tiny glitch hard to reproduce :
First, on your example move the toolbar in the middle of the window (Y=90).
Then move your mouse vertically (multiple times) above one button. Sometimes the button stays focused even if the mouse is not above it anymore.
Windows 10 Pro x64
PureBasic 6.04 x64
User avatar
Thorsten1867
Addict
Addict
Posts: 1366
Joined: Wed Aug 24, 2005 4:02 pm
Location: Germany

Re: [Module] Extended ToolBar-Gadget (all OS / DPI)

Post by Thorsten1867 »

Update: Optimisations
Translated with http://www.DeepL.com/Translator

Download of PureBasic - Modules
Download of PureBasic - Programs

[Windows 11 x64] [PB V5.7x]
tatanas
Enthusiast
Enthusiast
Posts: 199
Joined: Wed Nov 06, 2019 10:28 am
Location: France

Re: [Module] Extended ToolBar-Gadget (all OS / DPI)

Post by tatanas »

Thank you again for your reactivity.

In my pre-previous post, I added "TBEx()\LastFocus = -1" at the last line of the Default Case of _MouseMoveHandler() because when you move the cursor from an ImageButton to another item and go back on this ImageButton, it does not get the focus anymore.

And to fix the small glitch (previous post) I modified the _MouseLeaveHandler() procedure like this :

Code: Select all

  Procedure _MouseLeaveHandler()
    Define.i GNum = EventGadget()
    
    If FindMapElement(TBEx(), Str(GNum))
      TBEx()\Buttons\Focus = #NoFocus
      TBEx()\LastFocus     = #PB_Default

		ForEach TBEx()\Items()
			TBEx()\Items()\State = #False
		Next

      DisableToolTip_()
      Draw_()
    EndIf  
    
  EndProcedure

New glitch found when you click on an ImageButton then click again, the background stay as if the button is being pushed.
I removed "TBEx()\Items()\State = #False" in Case #EventType_ImageButton in _LeftButtonUpHandler() procedure

Code: Select all

              Case #EventType_ImageButton ;{ ImageButton clicked & released
                If TBEx()\Buttons\Focus = btIndex And TBEx()\Event\btIndex = btIndex
                  
                  If TBEx()\Items()\PopupMenu = #NotValid  ; Button without Popupmenu
                    
                    TBEx()\Event\Num = TBEx()\Items()\Event
                    TBEx()\Event\ID  = TBEx()\Items()\EventID
                    If IsWindow(TBEx()\Window\Num)
                      If TBEx()\PostEvent = #Event_Menu
                        PostEvent(#PB_Event_Menu, TBEx()\Window\Num, TBEx()\Items()\Event, #EventType_ImageButton, btIndex)
                      Else
                        PostEvent(#PB_Event_Gadget, TBEx()\Window\Num, TBEx()\CanvasNum, #EventType_ImageButton, btIndex)
                        PostEvent(#Event_Gadget, TBEx()\Window\Num, TBEx()\CanvasNum, #EventType_ImageButton, btIndex)
                      EndIf 
                    EndIf
                    
;                     TBEx()\Items()\State = #False

                    
                    DrawSingleButton_(btIndex)
and added "TBEx()\Items()\State = #Focus" in the DrawSingleButton_() procedure

Code: Select all

          ;{ Draw background
          Select TBEx()\Items()\State
            Case #Focus
              BackColor   = BlendColor_(TBEx()\Color\Focus, TBEx()\Color\Back, 20)
              BorderColor = BlendColor_(TBEx()\Color\Focus, TBEx()\Color\Back)
            Case #Click
              BackColor   = BlendColor_(TBEx()\Color\Focus, TBEx()\Color\Back, 32)
              BorderColor = BlendColor_(TBEx()\Color\Focus, TBEx()\Color\Back)
TBEx()\Items()\State = #Focus
            Default
              BackColor   = TBEx()\Color\Back
              BorderColor = #PB_Default
          EndSelect
Windows 10 Pro x64
PureBasic 6.04 x64
User avatar
Thorsten1867
Addict
Addict
Posts: 1366
Joined: Wed Aug 24, 2005 4:02 pm
Location: Germany

Re: [Module] Extended ToolBar-Gadget (all OS / DPI)

Post by Thorsten1867 »

Code: Select all

TBEx()\Items()\State = #Focus
The state is only set when the left mouse button is released. I have changed the rest.
Translated with http://www.DeepL.com/Translator

Download of PureBasic - Modules
Download of PureBasic - Programs

[Windows 11 x64] [PB V5.7x]
tatanas
Enthusiast
Enthusiast
Posts: 199
Joined: Wed Nov 06, 2019 10:28 am
Location: France

Re: [Module] Extended ToolBar-Gadget (all OS / DPI)

Post by tatanas »

Thanks.
I don't know if this is intended but when you click on an ImageButton, it loses its focus when released.
Windows 10 Pro x64
PureBasic 6.04 x64
User avatar
Thorsten1867
Addict
Addict
Posts: 1366
Joined: Wed Aug 24, 2005 4:02 pm
Location: Germany

Re: [Module] Extended ToolBar-Gadget (all OS / DPI)

Post by Thorsten1867 »

Added it in _LeftButtonUpHandler()
Translated with http://www.DeepL.com/Translator

Download of PureBasic - Modules
Download of PureBasic - Programs

[Windows 11 x64] [PB V5.7x]
tatanas
Enthusiast
Enthusiast
Posts: 199
Joined: Wed Nov 06, 2019 10:28 am
Location: France

Re: [Module] Extended ToolBar-Gadget (all OS / DPI)

Post by tatanas »

Thanks, it works fine.

Could you check the change of Arrow Direction of PopupMenu. It doesn't seem to work.
The arrow could get a "disabled" effect when the button is disabled.
And perhaps it's because my toolbar is inside a PanelGadget, but the PopupMenu position is wrong.

This code seems to fix the position error (in _LeftButtonUpHandler()) :

Code: Select all

X = GadgetX(TBEx()\CanvasNum, #PB_Gadget_ScreenCoordinate) + TBEx()\Items()\X
Y = GadgetY(TBEx()\CanvasNum, #PB_Gadget_ScreenCoordinate) + TBEx()\Items()\Y + GetButtonY_(#True)
Also, what do you think about adding a PostEvent() to button even if a PopupMenu is attached to it ? (I would like to put a check mark on PopupMenu items just after the click on ButtonImage and before the popupmenu appears)
Windows 10 Pro x64
PureBasic 6.04 x64
User avatar
Thorsten1867
Addict
Addict
Posts: 1366
Joined: Wed Aug 24, 2005 4:02 pm
Location: Germany

Re: [Module] Extended ToolBar-Gadget (all OS / DPI)

Post by Thorsten1867 »

Update:
  • Button-Events for all buttons
  • Pop-up menu arrows removed
Unfortunately, pop menus do not provide any useful events to reliably switch the arrows.
Translated with http://www.DeepL.com/Translator

Download of PureBasic - Modules
Download of PureBasic - Programs

[Windows 11 x64] [PB V5.7x]
tatanas
Enthusiast
Enthusiast
Posts: 199
Joined: Wed Nov 06, 2019 10:28 am
Location: France

Re: [Module] Extended ToolBar-Gadget (all OS / DPI)

Post by tatanas »

Hi,

There are problems with the button linked to the PopupMenu with #PB_Event_Menu or #PB_Event_Gadget events.
EventNumber() and EventID() triggered by the menu items are wrong.

Concerning ButtonImage (with PopupImage) event, the problem is the PostEvent() message priority. It is processed after the popup window appears (which stops the execution of the code like a messagerequester does)).
The only way I found was to use a SendMessage_() with custom event and process it inside a Window callback : WinProc(WindowID, Message, WParam, LParam).

About Arrows, maybe you could add a callback to handle open/close of popupmenu :

Code: Select all

	Global RootMenuClosed
	Procedure PopupCallback(hWnd, uMsg, wParam, lParam)
		Select uMsg
			Case #WM_INITMENUPOPUP
				If RootMenuClosed = 0
					RootMenuClosed = wParam
					Debug "- Menu opened -"
				EndIf
			Case #WM_UNINITMENUPOPUP
				If wParam = RootMenuClosed
					RootMenuClosed = 0
					Debug "- Menu closed -"
				EndIf
		EndSelect
		
		ProcedureReturn #PB_ProcessPureBasicEvents
	EndProcedure

Here is a working version with arrows (i'm using the previous version of your module). It is just a proof of concept, it is not clean :
https://file.io/YQecee0iNOBq
Windows 10 Pro x64
PureBasic 6.04 x64
User avatar
Thorsten1867
Addict
Addict
Posts: 1366
Joined: Wed Aug 24, 2005 4:02 pm
Location: Germany

Re: [Module] Extended ToolBar-Gadget (all OS / DPI)

Post by Thorsten1867 »

Please try it.
Translated with http://www.DeepL.com/Translator

Download of PureBasic - Modules
Download of PureBasic - Programs

[Windows 11 x64] [PB V5.7x]
tatanas
Enthusiast
Enthusiast
Posts: 199
Joined: Wed Nov 06, 2019 10:28 am
Location: France

Re: [Module] Extended ToolBar-Gadget (all OS / DPI)

Post by tatanas »

PopupMenu item events are ok. But ImageButtons keep the focus after a click on the button linked to the popup menu.

Did you test the PopupCallback() to possibly use it with Arrow ?


Example : https://file.io/iWZ5vW5h5CtF
(I have added a disabled effect on arrow. I use #WM_COMMAND message to handle the button click, it could be more customized...)
Windows 10 Pro x64
PureBasic 6.04 x64
User avatar
Thorsten1867
Addict
Addict
Posts: 1366
Joined: Wed Aug 24, 2005 4:02 pm
Location: Germany

Re: [Module] Extended ToolBar-Gadget (all OS / DPI)

Post by Thorsten1867 »

The solution is unfortunately Windows only
Translated with http://www.DeepL.com/Translator

Download of PureBasic - Modules
Download of PureBasic - Programs

[Windows 11 x64] [PB V5.7x]
tatanas
Enthusiast
Enthusiast
Posts: 199
Joined: Wed Nov 06, 2019 10:28 am
Location: France

Re: [Module] Extended ToolBar-Gadget (all OS / DPI)

Post by tatanas »

Here is a Windows version with Arrows and ImageButton click handler (pretty clean, I hope) :
https://file.io/XGAMOWFpN0jC
Windows 10 Pro x64
PureBasic 6.04 x64
Post Reply