Page 1 of 2
ButtonImageGadget disappears
Posted: Sun Apr 14, 2013 10:05 am
by Lord
Hello everyone!
I just stumbled over this:
I've got 2 Button in a ToolBar. One ButtonGadget and one
ImageButtonGadget.
If I leave the window, enter it again an press one of the
following buttons, the ButtonImageGadget disappears:
TAB, SHIFT left, CTRL left, ALT,
ALT Gr, CTRL right, SHIFT right
The button reappears, if I hoover over the button.
Why disappears the ImageButton and how can I prevent
this?
Code: Select all
EnableExplicit
Enumeration
#MainWindow
EndEnumeration
Enumeration
#Toolbar
EndEnumeration
Enumeration
#myImgButton
#myNrmButton
EndEnumeration
Define Quit.i, Event.i
OpenWindow(#MainWindow, 10, 10, 300, 300, "Test")
CreateToolBar(#Toolbar, WindowID(#MainWindow))
ButtonImageGadget(#myImgButton, WindowWidth(#MainWindow)-30, 1, 24, 24, 0, #PB_Button_Toggle)
SetParent_(GadgetID(#myImgButton), ToolBarID(#Toolbar))
ButtonGadget(#myNrmButton, WindowWidth(#MainWindow)-60, 1, 24, 24, "", #PB_Button_Toggle)
SetParent_(GadgetID(#myNrmButton), ToolBarID(#Toolbar))
Quit=0
Repeat
Event=WaitWindowEvent()
Select Event
Case #PB_Event_CloseWindow
Quit=#True
EndSelect
Until Quit
End
Re: ButtonImageGadget disappears
Posted: Sun Apr 14, 2013 2:48 pm
by Lord
I did some more testing.
It seems, that there has been something changed since PB v5.0,
which causes the above mentioned disappearing of the gadget.
I tested versions 4.51, 4.60, 4.61, 5.0 and 5.11. All with x86 and
x64.
The ButtonImageGadget stays stable with versions 4.51 to 4.61.
In 5.0 and 5.11 (I didn't test 5.1) the gadget disappears.
My system is a Win7, x64 machine.
So the question is wether this is a bug or not. Any recommendations?
Re: ButtonImageGadget disappears
Posted: Sun Apr 14, 2013 3:00 pm
by Kiffi
confirmed.
Test1:
* Starting your snippet
* Pressing <Tab>
-> The second buttons doesn't disappears.
Test2:
* Starting your snippet
* Moving the window to the center of my screen
* Pressing <Tab>
-> The second buttons disappears.
* Pressing <Tab> again
-> The second buttons reappears (and stays).
curious...
Greetings ... Kiffi
Re: ButtonImageGadget disappears
Posted: Sun Apr 14, 2013 3:17 pm
by RASHAD
Workaround
Code: Select all
EnableExplicit
Enumeration
#MainWindow
EndEnumeration
Enumeration
#Toolbar
EndEnumeration
Enumeration
#myImgButton
#myNrmButton
EndEnumeration
Define Quit.i, Event.i
OpenWindow(#MainWindow, 10, 10, 300, 300, "Test")
CreateToolBar(#Toolbar, WindowID(#MainWindow))
ButtonImageGadget(#myImgButton, WindowWidth(#MainWindow)-30, 1, 24, 24, 0, #PB_Button_Toggle)
SetParent_(GadgetID(#myImgButton), ToolBarID(#Toolbar))
ButtonGadget(#myNrmButton, WindowWidth(#MainWindow)-60, 1, 24, 24, "", #PB_Button_Toggle)
SetParent_(GadgetID(#myNrmButton), ToolBarID(#Toolbar))
Quit=0
Repeat
Event=WaitWindowEvent()
Select Event
Case #PB_Event_CloseWindow
Quit=#True
Case #WM_KEYDOWN
InvalidateRect_(WindowID(0),0,1)
EndSelect
Until Quit
End
Re: ButtonImageGadget disappears
Posted: Sun Apr 14, 2013 3:33 pm
by Lord
@ Kiffi
Thanks for your confirmation.
@ Rashad
Thanks for your workaround.
But this doesn't work. At least fo me. The gadget still disappears.
@ all
I did another test in a vmware XP environmet.
I run the exe from my PB v5.11, Win7 system.
There the gadget does not disappear.
So it has to do something with Win7 in conjuction with PB v5.xx.
Can I consider this a bug?
Re: ButtonImageGadget disappears
Posted: Sun Apr 14, 2013 4:09 pm
by MachineCode
Lord wrote:Can I consider this a bug?
No, because the team has said in the past that overlapping items are not supported. You're putting buttons over a toolbar. This should be mentioned in the manual, though, so you don't have to find out in the forum like this.
Re: ButtonImageGadget disappears
Posted: Sun Apr 14, 2013 5:19 pm
by infratec
Hi,
it's not only a Win7 problem.
I can confirm this behaviour for Win XP 32bit.
If it is a bug or not ....
I think only Fred, who knows the internals, can decide if it is a bug or not.
Bernd
Re: ButtonImageGadget disappears
Posted: Sun Apr 14, 2013 9:24 pm
by netmaestro
Use ToolBarImageButton() with the toggle flag, it's supported and will work.
Re: ButtonImageGadget disappears
Posted: Sun Apr 14, 2013 10:22 pm
by Lord
netmaestro wrote:Use ToolBarImageButton() with the toggle flag, it's supported and will work.
I know. But how can I place the button to the far right
and keep it there when resizing the window?
Re: ButtonImageGadget disappears
Posted: Sun Apr 14, 2013 11:33 pm
by ts-soft
Workaround:
Use a ContainerGadget and no Toolbar. Add your buttons with:
http://www.purebasic.fr/english/viewtop ... 12&t=53623
but Toogle is not supported!
Greetings - Thomas
Re: ButtonImageGadget disappears
Posted: Sun Apr 14, 2013 11:54 pm
by rrpl
Lord wrote:
I know. But how can I place the button to the far right
and keep it there when resizing the window?
Code: Select all
EnableExplicit
Global Window_0,Container_0,ButtonImage_0, ButtonImage_1
Procedure OpenWindow_0()
Window_0 = OpenWindow(#PB_Any, 0, 0, 600, 400, "", #PB_Window_SystemMenu|#PB_Window_SizeGadget)
Container_0 = ContainerGadget(#PB_Any,WindowWidth(Window_0)-60, 0, 60, 25)
ButtonImage_0 = ButtonImageGadget(#PB_Any, 0, 1, 24, 24, 0,#PB_Button_Toggle)
ButtonImage_1 = ButtonImageGadget(#PB_Any, 30, 1, 24, 24, 0,#PB_Button_Toggle)
CloseGadgetList()
EndProcedure
Define Quit.i, Event.i
OpenWindow_0()
Quit=0
Repeat
Event=WaitWindowEvent()
Select Event
Case #PB_Event_CloseWindow
Quit=#True
Case #PB_Event_SizeWindow
ResizeGadget(Container_0,WindowWidth(Window_0)-60,#PB_Ignore,#PB_Ignore,#PB_Ignore)
EndSelect
Until Quit
End
Re: ButtonImageGadget disappears
Posted: Mon Apr 15, 2013 7:49 am
by Lord
Hi rrpl!
Thanks for your reply.
With your snippet the button stays on the window. Thats right.
But the problem was a ButtonImageGadget on a toolbar.
I already tried a ContainerGadget:
EnableExplicit
Enumeration
#myWindow
EndEnumeration
Enumeration
#myToolbar
EndEnumeration
Enumeration
#myContainer
#myButton1
#myButton2
EndEnumeration
Define Quit.i, Event.i
OpenWindow(#myWindow, 0, 0, 600, 400, "", #PB_Window_SystemMenu|#PB_Window_SizeGadget)
CreateToolBar(#myToolbar, WindowID(#myWindow))
ToolBarStandardButton(#myToolbar,#PB_ToolBarIcon_New)
ContainerGadget(#myContainer,WindowWidth(#myWindow)-60, 0, 60, 25)
ButtonImageGadget(#myButton1, 0, 1, 24, 24, 0,#PB_Button_Toggle)
ButtonImageGadget(#myButton2, 30, 1, 24, 24, 0,#PB_Button_Toggle)
CloseGadgetList()
SetParent_(GadgetID(#myContainer), ToolBarID(#myToolbar))
Quit=0
Repeat
Event=WaitWindowEvent()
Select Event
Case #PB_Event_SizeWindow
ResizeGadget(#myContainer,WindowWidth(#myWindow)-60,#PB_Ignore,#PB_Ignore,#PB_Ignore)
Case #PB_Event_CloseWindow
Quit=#True
EndSelect
Until Quit
End
I think, I have to fall back to PB v4.61. Even if I loose PostEvent()

, but
get also rid of autocasting

.
Re: ButtonImageGadget disappears
Posted: Mon Apr 15, 2013 10:49 am
by rrpl
You could make the rest of the toolbar out of gadgets also, but only if it suits your purpose.
Code: Select all
EnableExplicit
Enumeration
#myWindow
EndEnumeration
Enumeration
#myContainer
#myButton0
#myButton1
#myButton2
EndEnumeration
Define Quit.i, Event.i
OpenWindow(#myWindow, 0, 0, 600, 400, "", #PB_Window_SystemMenu|#PB_Window_SizeGadget)
ButtonImageGadget(#myButton0, 1, 1, 24, 24, 0,#PB_Button_Toggle)
ContainerGadget(#myContainer,WindowWidth(#myWindow)-60, 0, 60, 25)
ButtonImageGadget(#myButton1, 0, 1, 24, 24, 0,#PB_Button_Toggle)
ButtonImageGadget(#myButton2, 30, 1, 24, 24, 0,#PB_Button_Toggle)
CloseGadgetList()
Quit=0
Repeat
Event=WaitWindowEvent()
Select Event
Case #PB_Event_SizeWindow
ResizeGadget(#myContainer,WindowWidth(#myWindow)-60,#PB_Ignore,#PB_Ignore,#PB_Ignore)
Case #PB_Event_CloseWindow
Quit=#True
EndSelect
Until Quit
End
Must admit I have used the same toolbar/gadgets combination before in my own apps, so its a shame if it no longer works properly.
Re: ButtonImageGadget disappears
Posted: Mon Apr 15, 2013 4:45 pm
by Lord
@ts-soft:
Sorry ts-soft, I didn't want to ignore you.
I just didn't notice your posting.
That would be a almost a complete rewrite of a grown program.
And toggle ist a must. Thanks anyway.
@rrpl:
Hi rrpl!
rrpl wrote:You could make the rest of the toolbar out of gadgets also, but only if it suits your purpose.
...
Must admit I have used the same toolbar/gadgets combination before in my own apps, so its a shame if it no longer works properly.
Thanks for your recommendations, but I think I will stick
with PB v4.61 for this program. And yes, it is a shame,
also because a "normal" ButtonGadget still works that way.
Re: ButtonImageGadget disappears
Posted: Thu Apr 18, 2013 2:47 pm
by Lord
I couldn't resist.
Code: Select all
EnableExplicit
Enumeration
#MainWindow
#ButtonWindow
EndEnumeration
Enumeration
#xImage
#oImage
EndEnumeration
Enumeration
#Toolbar
#TBB1
#TBB2
#TBB3
EndEnumeration
Enumeration
#myImageButton
EndEnumeration
Procedure MakeImages()
CreateImage(#xImage, 24, 24)
StartDrawing(ImageOutput(#xImage))
Box(0, 0, 24, 24, $F0F0F0)
LineXY(0,0, 23,23, $0000FF)
LineXY(0,23, 23,0, $0000FF)
StopDrawing()
CreateImage(#oImage, 24, 24)
StartDrawing(ImageOutput(#oImage))
Box(0, 0, 24, 24, $F0F0F0)
DrawingMode(#PB_2DDrawing_Outlined)
Circle(12, 12, 4, $0000FF)
StopDrawing()
EndProcedure
Procedure PinWindow(hWnd, Event, wParam, lParam)
If Event = #WM_WINDOWPOSCHANGED
ResizeWindow(#ButtonWindow,
WindowX(#MainWindow, #PB_Window_InnerCoordinate)+WindowWidth(#MainWindow)-30,
WindowY(#MainWindow, #PB_Window_InnerCoordinate)+2,
#PB_Ignore, #PB_Ignore)
EndIf
ProcedureReturn #PB_ProcessPureBasicEvents
EndProcedure
MakeImages(); Because I want to use ButtonImageGadget()
OpenWindow(#MainWindow, 10, 10, 300, 300, "",#PB_Window_SizeGadget|#PB_Window_SystemMenu)
CreateToolBar(#Toolbar, WindowID(#MainWindow))
ToolBarStandardButton(#TBB1, #PB_ToolBarIcon_New)
ToolBarStandardButton(#TBB2, #PB_ToolBarIcon_Open)
ToolBarStandardButton(#TBB3, #PB_ToolBarIcon_Save)
OpenWindow(#ButtonWindow,
WindowX(#MainWindow, #PB_Window_InnerCoordinate)+WindowWidth(#MainWindow)-30,
WindowY(#MainWindow, #PB_Window_InnerCoordinate)+2,
24, 24,"", #PB_Window_BorderLess, WindowID(#MainWindow))
ButtonImageGadget(#myImageButton, 0, 1, 24, 24, ImageID(#oImage), #PB_Button_Toggle)
SetGadgetAttribute(#myImageButton, #PB_Button_PressedImage, ImageID(#xImage))
WindowBounds(#MainWindow, GadgetWidth(#myImageButton)+4+#TBB3*24, GadgetHeight(#myImageButton)+4, #PB_Ignore, #PB_Ignore)
SetWindowCallback(@PinWindow(), #MainWindow); 'synchronize' #ButtonWindow with #MainWindow
Define Quit.i=#False
Define Event.i
Define EventGadget.i
Define EventType.i
Repeat
Event=WaitWindowEvent()
EventGadget=EventGadget()
EventType=EventType()
Select Event
Case #PB_Event_Gadget
Select EventGadget
Case #myImageButton
SetActiveWindow(#MainWindow)
Select GetGadgetState(#myImageButton)
Case 0
; Do what you want
Case 1
;Do what you want
EndSelect
EndSelect
Case #PB_Event_CloseWindow
Quit=#True
EndSelect
Until Quit
End
This works for me, as it did before PB v5.x.
The only(?) annoyance is the 'flash' of the main window,
when the button is pressed.