Attempted to add focus change support to the new GTK+ high-order click code like we do on Windows; it isn't working quite yet but I'll mark it as a TODO for now.

This commit is contained in:
Pietro Gagliardi 2014-05-23 23:38:14 -04:00
parent dbeccfa922
commit f4afa2a951
2 changed files with 22 additions and 0 deletions

View File

@ -15,6 +15,7 @@ import (
// extern gboolean our_area_button_press_event_callback(GtkWidget *, GdkEvent *, gpointer);
// extern gboolean our_area_button_release_event_callback(GtkWidget *, GdkEvent *, gpointer);
// extern gboolean our_area_motion_notify_event_callback(GtkWidget *, GdkEvent *, gpointer);
// extern gboolean our_area_focus_event_callback(GtkWidget *, GdkEvent *, gpointer);
// extern gboolean our_area_key_press_event_callback(GtkWidget *, GdkEvent *, gpointer);
// extern gboolean our_area_key_release_event_callback(GtkWidget *, GdkEvent *, gpointer);
// /* because cgo doesn't like ... */
@ -36,6 +37,12 @@ func gtkAreaNew() *C.GtkWidget {
// and we need to allow focusing on a GtkDrawingArea to enable keyboard events
C.gtk_widget_set_can_focus(drawingarea, C.TRUE)
scrollarea := C.gtk_scrolled_window_new((*C.GtkAdjustment)(nil), (*C.GtkAdjustment)(nil))
// see below about focus events
// TODO can this be part of the gtk_widget_add_events() somehow?
// TODO this doesn't work properly; it complains that this isn't actually a window (????)
gdkwindow := C.gtk_widget_get_window(drawingarea)
C.gdk_window_set_events(gdkwindow,
C.gdk_window_get_events(gdkwindow) | C.GDK_FOCUS_CHANGE_MASK)
// need a viewport because GtkDrawingArea isn't natively scrollable
C.gtk_scrolled_window_add_with_viewport((*C.GtkScrolledWindow)(unsafe.Pointer(scrollarea)), drawingarea)
return scrollarea
@ -212,6 +219,19 @@ func our_area_motion_notify_event_callback(widget *C.GtkWidget, event *C.GdkEven
var area_motion_notify_event_callback = C.GCallback(C.our_area_motion_notify_event_callback)
// we want switching away from the control to reset the double-click counter, like with WM_ACTIVATE on Windows; from what I can gather about the Windows version of GDK this is correct
// differentiating between focus-in-event and focus-out-event is unimportant
// TODO make sure this actually works
//export our_area_focus_event_callback
func our_area_focus_event_callback(widget *C.GtkWidget, event *C.GdkEvent, data C.gpointer) C.gboolean {
s := (*sysData)(unsafe.Pointer(data))
s.clickCounter.reset()
return C.FALSE // TODO really false?
}
var area_focus_event_callback = C.GCallback(C.our_area_focus_event_callback)
// shared code for doing a key event
func doKeyEvent(widget *C.GtkWidget, event *C.GdkEvent, data C.gpointer, up bool) bool {
var ke KeyEvent

View File

@ -104,6 +104,8 @@ var classTypes = [nctypes]*classData{
"button-press-event": area_button_press_event_callback,
"button-release-event": area_button_release_event_callback,
"motion-notify-event": area_motion_notify_event_callback,
"focus-in-event": area_focus_event_callback,
"focus-out-event": area_focus_event_callback,
"key-press-event": area_key_press_event_callback,
"key-release-event": area_key_release_event_callback,
},