Hello.
how can i add (at least) the change-event to a DateGadget?
LostFocus- or Change-Event for DateGadget?
Re: LostFocus- or Change-Event for DateGadget?
You currently can't implement the LostFocus and Change events with PureBASIC commands. You would have to use the GTK-API to detect these events. PB 4.41 only recognizes a click as EventType() = 0 (#PB_EventType_LeftClick). Unfortunately PB currently doesn't discriminate between left click, left double click, right click or right double click. But if you only want to detect changes in the CalendarGadget this code example might help you:
Code: Select all
If OpenWindow(0, 0, 0, 220, 200, "CalendarGadget", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
CalendarGadget(0, 10, 10, 200, 180)
PreviousDate = GetGadgetState(0)
Repeat
WindowEvent = WaitWindowEvent()
If WindowEvent = #PB_Event_Gadget
If EventGadget() = 0
If EventType() = #PB_EventType_LeftClick
CurrentDate = GetGadgetState(0)
If CurrentDate <> PreviousDate
Debug "Current date = " + FormatDate("%dd.%mm.%yyyy", CurrentDate)
PreviousDate = CurrentDate
EndIf
EndIf
EndIf
EndIf
Until WindowEvent = #PB_Event_CloseWindow
EndIf
Re: LostFocus- or Change-Event for DateGadget?
To detect whether the cursor is above the CalendarGadget is quite easy with GTK-API:
Code: Select all
Enumeration
#EnterGadgetEvent
#LeaveGadgetEvent
EndEnumeration
ProcedureC GadgetEvent(*Widget.GtkWidget, *Event.GdkEventMotion, UserData)
Select UserData
Case #EnterGadgetEvent
StatusBarText(0, 0, "Cursor above Calendar: YES")
Case #LeaveGadgetEvent
StatusBarText(0, 0, "Cursor above Calendar: NO")
EndSelect
EndProcedure
OpenWindow(0, 0, 0, 220, 195, "CalendarGadget", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
CalendarGadget(0, 2, 10, 216, 185)
CreateStatusBar(0, WindowID(0))
AddStatusBarField(#PB_Ignore)
gtk_widget_add_events_(GadgetID(0), #GDK_ENTER_NOTIFY_MASK | #GDK_LEAVE_NOTIFY_MASK)
g_signal_connect_data_(GadgetID(0), "enter-notify-event", @GadgetEvent(), #EnterGadgetEvent, 0, 0)
g_signal_connect_data_(GadgetID(0), "leave-notify-event", @GadgetEvent(), #LeaveGadgetEvent, 0, 0)
Repeat
Until WaitWindowEvent() = #PB_Event_CloseWindow
Re: LostFocus- or Change-Event for DateGadget?
Thank you, but the CalendarGadget is not what i am looking for. I use the DateGadget and there your example don't work.
Re: LostFocus- or Change-Event for DateGadget?
Oh, I am sorry, you are right, you wrote DateGadget. 
But if you click onto the Down arrow at the right side of the DateGadget, a CalendarGadget
is opened...
I have modified my EnterGadget/LeaveGadget example (which works with most gadgets) to
detect the mouse cursor over the DateGadget:

But if you click onto the Down arrow at the right side of the DateGadget, a CalendarGadget
is opened...

I have modified my EnterGadget/LeaveGadget example (which works with most gadgets) to
detect the mouse cursor over the DateGadget:
Code: Select all
Enumeration
#EnterGadgetEvent
#LeaveGadgetEvent
EndEnumeration
ProcedureC GadgetEvent(*Widget.GtkWidget, *Event.GdkEventMotion, UserData)
Select UserData
Case #EnterGadgetEvent
StatusBarText(0, 0, "Cursor above DateGadget: YES")
Case #LeaveGadgetEvent
StatusBarText(0, 0, "Cursor above DateGadget: NO")
EndSelect
EndProcedure
OpenWindow(0, 0, 0, 240, 54, "DateGadget", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
DateGadget(0, 2, 2, 236, 25, "Date: %mm/%dd/%yyyy Time: %hh:%ii")
CreateStatusBar(0, WindowID(0))
AddStatusBarField(#PB_Ignore)
gtk_widget_add_events_(GadgetID(0), #GDK_ENTER_NOTIFY_MASK | #GDK_LEAVE_NOTIFY_MASK)
g_signal_connect_data_(GadgetID(0), "enter-notify-event", @GadgetEvent(), #EnterGadgetEvent, 0, 0)
g_signal_connect_data_(GadgetID(0), "leave-notify-event", @GadgetEvent(), #LeaveGadgetEvent, 0, 0)
Repeat
Until WaitWindowEvent() = #PB_Event_CloseWindow
Re: LostFocus- or Change-Event for DateGadget?
Thank you again. this example works too. for some other purposes needful, in dead.
I would describe my problem as follow. if (after) the user change the date, some depending data records should be loaded/updated.
I would describe my problem as follow. if (after) the user change the date, some depending data records should be loaded/updated.