Is it possible to add a resize event to the list of events supported by the canvas gadget?
To be fired if the canvas gadget is resized!
This will be added in next version see this post
http://www.purebasic.fr/english/viewtop ... 13&t=67255
regards
cd
Resize Event for canvas gadget[Resolved]
-
- Addict
- Posts: 1310
- Joined: Fri Aug 28, 2015 6:10 pm
- Location: Portugal
Resize Event for canvas gadget[Resolved]
Last edited by collectordave on Sat Jan 28, 2017 8:35 am, edited 2 times in total.
Any intelligent fool can make things bigger and more complex. It takes a touch of genius — and a lot of courage to move in the opposite direction.
Re: Resize Event for canvas gadget
for windows
Code: Select all
;-
;- Resize MODULE
;-
;-
Enumeration #PB_EventType_FirstCustomValue
#PB_EventType_Size
#PB_EventType_Move
EndEnumeration
;-
Procedure IDGadget( GadgetID )
CompilerSelect #PB_Compiler_OS
CompilerCase #PB_OS_Windows
ProcedureReturn GetProp_( GadgetID, "PB_GadgetID") - 1
CompilerCase #PB_OS_Linux
g_object_get_data_( GadgetID, "PB_GadgetID") - 1
CompilerEndSelect
EndProcedure
;-
Procedure SetIDGadget( Gadget )
CompilerSelect #PB_Compiler_OS
CompilerCase #PB_OS_Windows
If GetProp_( GadgetID( Gadget ), "PB_GadgetID" ) = 0
ProcedureReturn SetProp_( GadgetID( Gadget ), "PB_GadgetID", Gadget + (1))
EndIf
CompilerCase #PB_OS_Linux
If g_object_get_data_( GadgetID( Gadget ), "PB_GadgetID" ) = 0
ProcedureReturn g_object_set_data_( GadgetID( Gadget ), "PB_GadgetID", Gadget + (1))
EndIf
CompilerEndSelect
EndProcedure
CompilerSelect #PB_Compiler_OS
CompilerCase #PB_OS_Windows
Procedure Resize_CallBack(GadgetID, Msg, wParam, lParam)
Protected *Func = GetProp_( GadgetID, "Resize_Event_CallBack")
Protected *Gadget = IDGadget( GadgetID )
Protected *Window = GetActiveWindow()
Select Msg
Case #WM_SIZE : PostEvent( #PB_Event_Gadget, *Window, *Gadget , #PB_EventType_Size )
Case #WM_MOVE : PostEvent( #PB_Event_Gadget, *Window, *Gadget , #PB_EventType_Move )
Default
ProcedureReturn CallWindowProc_(*Func, GadgetID, Msg, wParam, lParam)
EndSelect
EndProcedure
CompilerCase #PB_OS_Linux
ProcedureC Resize_CallBack( *Event.GdkEventAny, *Handle )
Protected *Widget.GtkWidget = gtk_get_event_widget_(*Event)
Protected *Gadget = IDGadget( *Widget )
If *Widget
Debug PeekS( gtk_widget_get_name_( (*Widget)), -1, #PB_UTF8 ) + " " + Str(*Gadget)
EndIf
If *Widget And *Widget = g_object_get_data_(*Widget, "Resize_Event_CallBack")
Select *Event\type
Case #GDK_CONFIGURE
; PostEvent( #PB_Event_Gadget, *Window, *Gadget , #PB_EventType_Size )
; PostEvent( #PB_Event_Gadget, *Window, *Gadget , #PB_EventType_Move )
Case #GDK_UNMAP
gdk_event_handler_set_( 0, 0, 0 )
Default
gtk_main_do_event_( *Event )
EndSelect
Else
gtk_main_do_event_( *Event )
EndIf
EndProcedure
CompilerEndSelect
;-
Procedure ResizeGadgetEvents( Gadget )
Protected GadgetID, GadgetID1, GadgetID2, GadgetID3, GadgetID4
If IsGadget( Gadget ) : SetIDGadget( Gadget )
GadgetID = GadgetID( Gadget )
CompilerSelect #PB_Compiler_OS
CompilerCase #PB_OS_Linux
g_object_set_data_( GadgetID, "PB_GadgetID", Gadget + 1 )
g_object_set_data_( GadgetID, "Resize_Event_CallBack", GadgetID )
gdk_event_handler_set_( @Resize_CallBack(), GadgetID, 0 )
CompilerCase #PB_OS_Windows
If GadgetID And GetProp_( GadgetID, "Resize_Event_CallBack") = #False
SetProp_( GadgetID, "Resize_Event_CallBack", SetWindowLong_(GadgetID, #GWL_WNDPROC, @Resize_CallBack()))
EndIf
CompilerEndSelect
EndIf
EndProcedure
Procedure GadgetEvents()
Define CurrentGadget.i
Select EventType()
Case #PB_EventType_MouseEnter
Debug "Mouse Entered Gadget " + Str(EventGadget())
ResizeGadget( EventGadget(), #PB_Ignore, #PB_Ignore, 155, #PB_Ignore)
Case #PB_EventType_MouseLeave
Debug "Mouse Left Gadget " + Str(EventGadget())
ResizeGadget( EventGadget(), #PB_Ignore, #PB_Ignore, 135, #PB_Ignore)
Case #PB_EventType_Size
Debug "#PB_EventType_Size " + Str(EventGadget())
EndSelect
EndProcedure
Procedure CustomGadget(Gadget, X,Y,Width,Height)
Protected ID
;Create The Canvas For The Gadget
ID = CanvasGadget(Gadget, X,Y,Width,Height)
If IsGadget(ID) : Gadget = ID : EndIf
;Bind This gadgets Events
BindGadgetEvent(Gadget, @GadgetEvents())
ResizeGadgetEvents( Gadget )
EndProcedure
; then a little programme To test so far:-
;
; winMain.pb
;
; Code:
; IncludeFile "CustomGadget.pbi"
Global Window_0
Window_0 = OpenWindow(#PB_Any, 0, 0, 600, 400, "", #PB_Window_SystemMenu)
CustomGadget(#PB_Any,250, 40, 130, 80)
CustomGadget(23,100, 40, 130, 80)
CustomGadget(#PB_Any,100, 240, 130, 80)
CustomGadget(#PB_Any,250, 240, 130, 80)
Repeat
Event = WaitWindowEvent()
Select Event
Case #PB_Event_CloseWindow
End
Case #PB_Event_Gadget
Select EventGadget()
EndSelect
EndSelect
ForEver
Last edited by mestnyi on Mon Dec 19, 2016 7:03 pm, edited 1 time in total.
Re: Resize Event for canvas gadget
I was thinking about posting a solution but the feature request does hold value for cross-platform use cases.
-
- Addict
- Posts: 1310
- Joined: Fri Aug 28, 2015 6:10 pm
- Location: Portugal
Re: Resize Event for canvas gadget
Hi
Thanks for the replies. I think it holds a lot of merit for cross platform work and it is only in the single resizegadget() procedure any message sent to the canvas gadget to say something has happened would be good enough.
However in the meantime I have added @mestnyi's code to the module and it all seems to work ok with just a few small changes. So code needed for cross platform is all contained in the module great. Thanks mestnyi.
Once i do a few more tests I will repost on http://www.purebasic.fr/english/viewtop ... 13&t=67227
I cannot think of anymore events that it needs. If anyone can please post here.
Regards
cd
Thanks for the replies. I think it holds a lot of merit for cross platform work and it is only in the single resizegadget() procedure any message sent to the canvas gadget to say something has happened would be good enough.
However in the meantime I have added @mestnyi's code to the module and it all seems to work ok with just a few small changes. So code needed for cross platform is all contained in the module great. Thanks mestnyi.
Once i do a few more tests I will repost on http://www.purebasic.fr/english/viewtop ... 13&t=67227
I cannot think of anymore events that it needs. If anyone can please post here.
Regards
cd
Any intelligent fool can make things bigger and more complex. It takes a touch of genius — and a lot of courage to move in the opposite direction.