Page 3 of 3

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

Posted: Tue Jun 21, 2022 3:20 pm
by Thorsten1867
Update: Toolbar::Disable()

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

Posted: Wed Jun 22, 2022 7:47 am
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									

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

Posted: Wed Jun 22, 2022 8:06 am
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.

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

Posted: Wed Jun 22, 2022 10:17 am
by Thorsten1867
Update: Optimisations

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

Posted: Wed Jun 22, 2022 11:48 am
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

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

Posted: Thu Jun 23, 2022 1:02 pm
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.

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

Posted: Thu Jun 23, 2022 1:15 pm
by tatanas
Thanks.
I don't know if this is intended but when you click on an ImageButton, it loses its focus when released.

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

Posted: Thu Jun 23, 2022 1:24 pm
by Thorsten1867
Added it in _LeftButtonUpHandler()

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

Posted: Fri Jun 24, 2022 8:25 am
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)

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

Posted: Fri Jun 24, 2022 3:09 pm
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.

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

Posted: Mon Jun 27, 2022 7:14 am
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

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

Posted: Mon Jun 27, 2022 12:46 pm
by Thorsten1867
Please try it.

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

Posted: Mon Jun 27, 2022 1:37 pm
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...)

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

Posted: Mon Jun 27, 2022 1:57 pm
by Thorsten1867
The solution is unfortunately Windows only

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

Posted: Tue Jun 28, 2022 12:43 pm
by tatanas
Here is a Windows version with Arrows and ImageButton click handler (pretty clean, I hope) :
https://file.io/XGAMOWFpN0jC