Page 1 of 1

LostFocus- or Change-Event for DateGadget?

Posted: Mon May 10, 2010 8:41 am
by lnxque
Hello.

how can i add (at least) the change-event to a DateGadget?

Re: LostFocus- or Change-Event for DateGadget?

Posted: Tue May 11, 2010 2:05 pm
by Shardik
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?

Posted: Tue May 11, 2010 3:20 pm
by Shardik
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?

Posted: Wed May 12, 2010 1:27 pm
by lnxque
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?

Posted: Wed May 12, 2010 5:43 pm
by Shardik
Oh, I am sorry, you are right, you wrote DateGadget. :oops:
But if you click onto the Down arrow at the right side of the DateGadget, a CalendarGadget
is opened... :wink:

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?

Posted: Fri May 14, 2010 8:26 am
by lnxque
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.