diff options
Diffstat (limited to 'views/widget/widget_gtk.cc')
-rw-r--r-- | views/widget/widget_gtk.cc | 327 |
1 files changed, 61 insertions, 266 deletions
diff --git a/views/widget/widget_gtk.cc b/views/widget/widget_gtk.cc index 60422d7..91726afe 100644 --- a/views/widget/widget_gtk.cc +++ b/views/widget/widget_gtk.cc @@ -317,72 +317,75 @@ void WidgetGtk::Init(GtkWidget* parent, MessageLoopForUI::current()->AddObserver(this); - // TODO(beng): make these take this rather than NULL. g_signal_connect_after(G_OBJECT(window_contents_), "size_allocate", - G_CALLBACK(CallSizeAllocate), NULL); + G_CALLBACK(&OnSizeAllocateThunk), this); g_signal_connect(window_contents_, "expose_event", - G_CALLBACK(CallPaint), NULL); + G_CALLBACK(&OnPaintThunk), this); g_signal_connect(window_contents_, "enter_notify_event", - G_CALLBACK(CallEnterNotify), NULL); + G_CALLBACK(&OnEnterNotifyThunk), this); g_signal_connect(window_contents_, "leave_notify_event", - G_CALLBACK(CallLeaveNotify), NULL); + G_CALLBACK(&OnLeaveNotifyThunk), this); g_signal_connect(window_contents_, "motion_notify_event", - G_CALLBACK(CallMotionNotify), NULL); + G_CALLBACK(&OnMotionNotifyThunk), this); g_signal_connect(window_contents_, "button_press_event", - G_CALLBACK(CallButtonPress), NULL); + G_CALLBACK(&OnButtonPressThunk), this); g_signal_connect(window_contents_, "button_release_event", - G_CALLBACK(CallButtonRelease), NULL); + G_CALLBACK(&OnButtonReleaseThunk), this); g_signal_connect(window_contents_, "grab_broken_event", - G_CALLBACK(CallGrabBrokeEvent), NULL); + G_CALLBACK(&OnGrabBrokeEventThunk), this); g_signal_connect(window_contents_, "grab_notify", - G_CALLBACK(CallGrabNotify), NULL); + G_CALLBACK(&OnGrabNotifyThunk), this); g_signal_connect(window_contents_, "key_press_event", - G_CALLBACK(CallKeyPress), NULL); + G_CALLBACK(&OnKeyPressThunk), this); g_signal_connect(window_contents_, "key_release_event", - G_CALLBACK(CallKeyRelease), NULL); + G_CALLBACK(&OnKeyReleaseThunk), this); g_signal_connect(window_contents_, "scroll_event", - G_CALLBACK(CallScroll), NULL); + G_CALLBACK(&OnScrollThunk), this); g_signal_connect(window_contents_, "visibility_notify_event", - G_CALLBACK(CallVisibilityNotify), NULL); + G_CALLBACK(&OnVisibilityNotifyThunk), this); // In order to receive notification when the window is no longer the front // window, we need to install these on the widget. // NOTE: this doesn't work with focus follows mouse. g_signal_connect(widget_, "focus_in_event", - G_CALLBACK(CallFocusIn), NULL); + G_CALLBACK(&OnFocusInThunk), this); g_signal_connect(widget_, "focus_out_event", - G_CALLBACK(CallFocusOut), NULL); + G_CALLBACK(&OnFocusOutThunk), this); g_signal_connect(widget_, "destroy", - G_CALLBACK(CallDestroy), NULL); + G_CALLBACK(&OnDestroyThunk), this); + g_signal_connect(widget_, "show", + G_CALLBACK(&OnShowThunk), this); + g_signal_connect(widget_, "hide", + G_CALLBACK(&OnHideThunk), this); if (transparent_) { g_signal_connect(widget_, "expose_event", - G_CALLBACK(CallWindowPaint), this); + G_CALLBACK(&OnWindowPaintThunk), this); } // Drag and drop. gtk_drag_dest_set(window_contents_, static_cast<GtkDestDefaults>(0), NULL, 0, GDK_ACTION_COPY); g_signal_connect(window_contents_, "drag_motion", - G_CALLBACK(CallDragMotion), this); + G_CALLBACK(&OnDragMotionThunk), this); g_signal_connect(window_contents_, "drag_data_received", - G_CALLBACK(CallDragDataReceived), this); + G_CALLBACK(&OnDragDataReceivedThunk), this); g_signal_connect(window_contents_, "drag_drop", - G_CALLBACK(CallDragDrop), this); + G_CALLBACK(&OnDragDropThunk), this); g_signal_connect(window_contents_, "drag_leave", - G_CALLBACK(CallDragLeave), this); + G_CALLBACK(&OnDragLeaveThunk), this); g_signal_connect(window_contents_, "drag_data_get", - G_CALLBACK(CallDragDataGet), this); + G_CALLBACK(&OnDragDataGetThunk), this); g_signal_connect(window_contents_, "drag_end", - G_CALLBACK(CallDragEnd), this); + G_CALLBACK(&OnDragEndThunk), this); g_signal_connect(window_contents_, "drag_failed", - G_CALLBACK(CallDragFailed), this); + G_CALLBACK(&OnDragFailedThunk), this); tooltip_manager_.reset(new TooltipManagerGtk(this)); // Register for tooltips. g_object_set(G_OBJECT(window_contents_), "has-tooltip", TRUE, NULL); g_signal_connect(window_contents_, "query_tooltip", - G_CALLBACK(CallQueryTooltip), this); + G_CALLBACK(&OnQueryTooltipThunk), this); if (type_ == TYPE_CHILD) { if (parent) { @@ -702,11 +705,13 @@ void WidgetGtk::OnSizeAllocate(GtkWidget* widget, GtkAllocation* allocation) { root_view_->SchedulePaint(); } -void WidgetGtk::OnPaint(GtkWidget* widget, GdkEventExpose* event) { +gboolean WidgetGtk::OnPaint(GtkWidget* widget, GdkEventExpose* event) { root_view_->OnPaint(event); + return false; // False indicates other widgets should get the event as well. } -void WidgetGtk::OnDragDataGet(GdkDragContext* context, +void WidgetGtk::OnDragDataGet(GtkWidget* widget, + GdkDragContext* context, GtkSelectionData* data, guint info, guint time) { @@ -717,7 +722,8 @@ void WidgetGtk::OnDragDataGet(GdkDragContext* context, drag_data_->WriteFormatToSelection(info, data); } -void WidgetGtk::OnDragDataReceived(GdkDragContext* context, +void WidgetGtk::OnDragDataReceived(GtkWidget* widget, + GdkDragContext* context, gint x, gint y, GtkSelectionData* data, @@ -727,7 +733,8 @@ void WidgetGtk::OnDragDataReceived(GdkDragContext* context, drop_target_->OnDragDataReceived(context, x, y, data, info, time); } -gboolean WidgetGtk::OnDragDrop(GdkDragContext* context, +gboolean WidgetGtk::OnDragDrop(GtkWidget* widget, + GdkDragContext* context, gint x, gint y, guint time) { @@ -737,7 +744,7 @@ gboolean WidgetGtk::OnDragDrop(GdkDragContext* context, return FALSE; } -void WidgetGtk::OnDragEnd(GdkDragContext* context) { +void WidgetGtk::OnDragEnd(GtkWidget* widget, GdkDragContext* context) { if (!drag_data_) { // This indicates we didn't start a drag operation, and should never // happen. @@ -748,12 +755,14 @@ void WidgetGtk::OnDragEnd(GdkDragContext* context) { MessageLoop::current()->Quit(); } -gboolean WidgetGtk::OnDragFailed(GdkDragContext* context, +gboolean WidgetGtk::OnDragFailed(GtkWidget* widget, + GdkDragContext* context, GtkDragResult result) { return FALSE; } -void WidgetGtk::OnDragLeave(GdkDragContext* context, +void WidgetGtk::OnDragLeave(GtkWidget* widget, + GdkDragContext* context, guint time) { if (ignore_drag_leave_) { ignore_drag_leave_ = false; @@ -765,7 +774,8 @@ void WidgetGtk::OnDragLeave(GdkDragContext* context, } } -gboolean WidgetGtk::OnDragMotion(GdkDragContext* context, +gboolean WidgetGtk::OnDragMotion(GtkWidget* widget, + GdkDragContext* context, gint x, gint y, guint time) { @@ -886,13 +896,19 @@ gboolean WidgetGtk::OnKeyRelease(GtkWidget* widget, GdkEventKey* event) { return root_view_->ProcessKeyEvent(key_event); } -gboolean WidgetGtk::OnQueryTooltip(gint x, +gboolean WidgetGtk::OnQueryTooltip(GtkWidget* widget, + gint x, gint y, gboolean keyboard_mode, GtkTooltip* tooltip) { return tooltip_manager_->ShowTooltip(x, y, keyboard_mode, tooltip); } +gboolean WidgetGtk::OnVisibilityNotify(GtkWidget* widget, + GdkEventVisibility* event) { + return false; +} + gboolean WidgetGtk::OnGrabBrokeEvent(GtkWidget* widget, GdkEvent* event) { HandleGrabBroke(); return false; // To let other widgets get the event. @@ -903,7 +919,8 @@ void WidgetGtk::OnGrabNotify(GtkWidget* widget, gboolean was_grabbed) { HandleGrabBroke(); } -void WidgetGtk::OnDestroy() { +void WidgetGtk::OnDestroy(GtkWidget* object) { + // Note that this handler is hooked to GtkObject::destroy. widget_ = window_contents_ = NULL; if (delete_on_destroy_) { // Delays the deletion of this WidgetGtk as we want its children to have @@ -912,6 +929,12 @@ void WidgetGtk::OnDestroy() { } } +void WidgetGtk::OnShow(GtkWidget* widget) { +} + +void WidgetGtk::OnHide(GtkWidget* widget) { +} + void WidgetGtk::DoGrab() { has_capture_ = true; gtk_grab_add(window_contents_); @@ -936,7 +959,7 @@ RootView* WidgetGtk::CreateRootView() { return new RootView(this); } -void WidgetGtk::OnWindowPaint(GtkWidget* widget, GdkEventExpose* event) { +gboolean WidgetGtk::OnWindowPaint(GtkWidget* widget, GdkEventExpose* event) { // NOTE: for reasons I don't understand this code is never hit. It should // be hit when transparent_, but we never get the expose-event for the // window in this case, even though a stand alone test case triggers it. I'm @@ -952,6 +975,7 @@ void WidgetGtk::OnWindowPaint(GtkWidget* widget, GdkEventExpose* event) { cairo_set_source_rgba(cr, 0, 0, 0, 0); cairo_rectangle(cr, 0, 0, width, height); cairo_fill(cr); + return false; } bool WidgetGtk::ProcessMousePressed(GdkEventButton* event) { @@ -1037,235 +1061,6 @@ void WidgetGtk::SetRootViewForWidget(GtkWidget* widget, RootView* root_view) { } // static -gboolean WidgetGtk::CallButtonPress(GtkWidget* widget, GdkEventButton* event) { - WidgetGtk* widget_gtk = GetViewForNative(widget); - if (!widget_gtk) - return false; - - return widget_gtk->OnButtonPress(widget, event); -} - -// static -gboolean WidgetGtk::CallButtonRelease(GtkWidget* widget, - GdkEventButton* event) { - WidgetGtk* widget_gtk = GetViewForNative(widget); - if (!widget_gtk) - return false; - - return widget_gtk->OnButtonRelease(widget, event); -} - -// static -gboolean WidgetGtk::CallDragDrop(GtkWidget* widget, - GdkDragContext* context, - gint x, - gint y, - guint time, - WidgetGtk* host) { - return host->OnDragDrop(context, x, y, time); -} - -// static -gboolean WidgetGtk::CallDragFailed(GtkWidget* widget, - GdkDragContext* context, - GtkDragResult result, - WidgetGtk* host) { - return host->OnDragFailed(context, result); -} - -// static -gboolean WidgetGtk::CallDragMotion(GtkWidget* widget, - GdkDragContext* context, - gint x, - gint y, - guint time, - WidgetGtk* host) { - return host->OnDragMotion(context, x, y, time); -} - -// static -gboolean WidgetGtk::CallEnterNotify(GtkWidget* widget, - GdkEventCrossing* event) { - WidgetGtk* widget_gtk = GetViewForNative(widget); - if (!widget_gtk) - return false; - - return widget_gtk->OnEnterNotify(widget, event); -} - -// static -gboolean WidgetGtk::CallFocusIn(GtkWidget* widget, GdkEventFocus* event) { - WidgetGtk* widget_gtk = GetViewForNative(widget); - if (!widget_gtk) - return false; - - return widget_gtk->OnFocusIn(widget, event); -} - -// static -gboolean WidgetGtk::CallFocusOut(GtkWidget* widget, GdkEventFocus* event) { - WidgetGtk* widget_gtk = GetViewForNative(widget); - if (!widget_gtk) - return false; - - return widget_gtk->OnFocusOut(widget, event); -} - -// static -gboolean WidgetGtk::CallGrabBrokeEvent(GtkWidget* widget, GdkEvent* event) { - WidgetGtk* widget_gtk = GetViewForNative(widget); - if (!widget_gtk) - return false; - - return widget_gtk->OnGrabBrokeEvent(widget, event); -} - -// static -gboolean WidgetGtk::CallKeyPress(GtkWidget* widget, GdkEventKey* event) { - WidgetGtk* widget_gtk = GetViewForNative(widget); - if (!widget_gtk) - return false; - - return widget_gtk->OnKeyPress(widget, event); -} - -// static -gboolean WidgetGtk::CallKeyRelease(GtkWidget* widget, GdkEventKey* event) { - WidgetGtk* widget_gtk = GetViewForNative(widget); - if (!widget_gtk) - return false; - - return widget_gtk->OnKeyRelease(widget, event); -} - -// static -gboolean WidgetGtk::CallLeaveNotify(GtkWidget* widget, - GdkEventCrossing* event) { - WidgetGtk* widget_gtk = GetViewForNative(widget); - if (!widget_gtk) - return false; - - return widget_gtk->OnLeaveNotify(widget, event); -} - -// static -gboolean WidgetGtk::CallMotionNotify(GtkWidget* widget, GdkEventMotion* event) { - WidgetGtk* widget_gtk = GetViewForNative(widget); - if (!widget_gtk) - return false; - - return widget_gtk->OnMotionNotify(widget, event); -} - -// static -gboolean WidgetGtk::CallPaint(GtkWidget* widget, GdkEventExpose* event) { - WidgetGtk* widget_gtk = GetViewForNative(widget); - if (widget_gtk) - widget_gtk->OnPaint(widget, event); - return false; // False indicates other widgets should get the event as well. -} - -// static -gboolean WidgetGtk::CallQueryTooltip(GtkWidget* widget, - gint x, - gint y, - gboolean keyboard_mode, - GtkTooltip* tooltip, - WidgetGtk* host) { - return host->OnQueryTooltip(static_cast<int>(x), static_cast<int>(y), - keyboard_mode, tooltip); -} - -// static -gboolean WidgetGtk::CallScroll(GtkWidget* widget, GdkEventScroll* event) { - WidgetGtk* widget_gtk = GetViewForNative(widget); - if (!widget_gtk) - return false; - - return widget_gtk->OnScroll(widget, event); -} - -// static -gboolean WidgetGtk::CallVisibilityNotify(GtkWidget* widget, - GdkEventVisibility* event) { - WidgetGtk* widget_gtk = GetViewForNative(widget); - if (!widget_gtk) - return false; - - return widget_gtk->OnVisibilityNotify(widget, event); -} - -// static -gboolean WidgetGtk::CallWindowPaint(GtkWidget* widget, - GdkEventExpose* event, - WidgetGtk* widget_gtk) { - widget_gtk->OnWindowPaint(widget, event); - return false; // False indicates other widgets should get the event as well. -} - -// static -void WidgetGtk::CallDestroy(GtkObject* object) { - WidgetGtk* widget_gtk = GetViewForNative(GTK_WIDGET(object)); - if (widget_gtk) - widget_gtk->OnDestroy(); -} - -// static -void WidgetGtk::CallDragDataGet(GtkWidget* widget, - GdkDragContext* context, - GtkSelectionData* data, - guint info, - guint time, - WidgetGtk* host) { - host->OnDragDataGet(context, data, info, time); -} - -// static -void WidgetGtk::CallDragDataReceived(GtkWidget* widget, - GdkDragContext* context, - gint x, - gint y, - GtkSelectionData* data, - guint info, - guint time, - WidgetGtk* host) { - return host->OnDragDataReceived(context, x, y, data, info, time); -} - -// static -void WidgetGtk::CallDragEnd(GtkWidget* widget, - GdkDragContext* context, - WidgetGtk* host) { - host->OnDragEnd(context); -} - -// static -void WidgetGtk::CallDragLeave(GtkWidget* widget, - GdkDragContext* context, - guint time, - WidgetGtk* host) { - host->OnDragLeave(context, time); -} - -// static -void WidgetGtk::CallGrabNotify(GtkWidget* widget, gboolean was_grabbed) { - WidgetGtk* widget_gtk = GetViewForNative(widget); - if (!widget_gtk) - return; - - return widget_gtk->OnGrabNotify(widget, was_grabbed); -} - -// static -void WidgetGtk::CallSizeAllocate(GtkWidget* widget, GtkAllocation* allocation) { - WidgetGtk* widget_gtk = GetViewForNative(widget); - if (!widget_gtk) - return; - - widget_gtk->OnSizeAllocate(widget, allocation); -} - -// static Window* WidgetGtk::GetWindowImpl(GtkWidget* widget) { GtkWidget* parent = widget; while (parent) { |