static void gdl_dock_tablabel_get_preferred_height (GtkWidget *widget, gint *minimum, gint *natural) { GtkBin *bin; gint child_min, child_nat; GdlDockTablabel *tablabel; guint border_width; g_return_if_fail (widget != NULL); g_return_if_fail (GDL_IS_DOCK_TABLABEL (widget)); tablabel = GDL_DOCK_TABLABEL (widget); bin = GTK_BIN (widget); *minimum = *natural = 0; if (gtk_bin_get_child (bin)) gtk_widget_get_preferred_height (gtk_bin_get_child (bin), &child_min, &child_nat); else child_min = child_nat = 0; *minimum = child_min; *natural = child_nat; border_width = gtk_container_get_border_width (GTK_CONTAINER (widget)); *minimum += border_width * 2; *natural += border_width * 2; }
static void gdl_dock_tablabel_get_preferred_width (GtkWidget *widget, gint *minimum, gint *natural) { GtkBin *bin; gint child_min, child_nat; GdlDockTablabel *tablabel; guint border_width; g_return_if_fail (widget != NULL); g_return_if_fail (GDL_IS_DOCK_TABLABEL (widget)); tablabel = GDL_DOCK_TABLABEL (widget); bin = GTK_BIN (widget); *minimum = *natural = tablabel->drag_handle_size; if (gtk_bin_get_child (bin)) gtk_widget_get_preferred_width (gtk_bin_get_child (bin), &child_min, &child_nat); else child_min = child_nat = 0; *minimum += child_min + border_width * 2; *natural += child_nat + border_width * 2; }
static void gdl_dock_tablabel_size_request (GtkWidget *widget, GtkRequisition *requisition) { GtkBin *bin; GtkRequisition child_req; GdlDockTablabel *tablabel; g_return_if_fail (widget != NULL); g_return_if_fail (GDL_IS_DOCK_TABLABEL (widget)); g_return_if_fail (requisition != NULL); tablabel = GDL_DOCK_TABLABEL (widget); bin = GTK_BIN (widget); requisition->width = tablabel->drag_handle_size; requisition->height = 0; if (bin->child) gtk_widget_size_request (bin->child, &child_req); else child_req.width = child_req.height = 0; requisition->width += child_req.width; requisition->height += child_req.height; requisition->width += GTK_CONTAINER (widget)->border_width * 2; requisition->height += GTK_CONTAINER (widget)->border_width * 2; widget->requisition = *requisition; }
static gboolean gdl_dock_tablabel_motion_event (GtkWidget *widget, GdkEventMotion *event) { GdlDockTablabel *tablabel; GtkAllocation widget_allocation; gboolean event_handled; g_return_val_if_fail (widget != NULL, FALSE); g_return_val_if_fail (GDL_IS_DOCK_TABLABEL (widget), FALSE); g_return_val_if_fail (event != NULL, FALSE); tablabel = GDL_DOCK_TABLABEL (widget); event_handled = FALSE; if (event->window != tablabel->event_window) return FALSE; if (tablabel->pre_drag) { if (gtk_drag_check_threshold (widget, tablabel->drag_start_event.x, tablabel->drag_start_event.y, event->x, event->y)) { tablabel->pre_drag = FALSE; g_signal_emit (widget, dock_tablabel_signals [BUTTON_PRESSED_HANDLE], 0, &tablabel->drag_start_event); event_handled = TRUE; } } if (!event_handled) { /* propagate the event to the parent's gdkwindow */ GdkEventMotion e; e = *event; e.window = gtk_widget_get_parent_window (widget); gtk_widget_get_allocation (widget, &widget_allocation); e.x += widget_allocation.x; e.y += widget_allocation.y; gdk_event_put ((GdkEvent *) &e); }; return event_handled; }
static gboolean gdl_dock_tablabel_draw (GtkWidget *widget, cairo_t *cr) { g_return_val_if_fail (widget != NULL, FALSE); g_return_val_if_fail (GDL_IS_DOCK_TABLABEL (widget), FALSE); g_return_val_if_fail (cr != NULL, FALSE); if (gtk_widget_get_visible (widget) && gtk_widget_get_mapped (widget)) { GTK_WIDGET_CLASS (gdl_dock_tablabel_parent_class)->draw (widget, cr); gdl_dock_tablabel_paint (widget, cr); }; return FALSE; }
static gint gdl_dock_tablabel_expose (GtkWidget *widget, GdkEventExpose *event) { g_return_val_if_fail (widget != NULL, FALSE); g_return_val_if_fail (GDL_IS_DOCK_TABLABEL (widget), FALSE); g_return_val_if_fail (event != NULL, FALSE); if (gtk_widget_get_visible (widget) && gtk_widget_get_mapped (widget)) { GDL_CALL_PARENT_GBOOLEAN(GTK_WIDGET_CLASS, expose_event, (widget,event)); gdl_dock_tablabel_paint (widget, event); }; return FALSE; }
static void gdl_dock_tablabel_size_allocate (GtkWidget *widget, GtkAllocation *allocation) { GtkBin *bin; GtkAllocation widget_allocation; GdlDockTablabel *tablabel; gint border_width; g_return_if_fail (widget != NULL); g_return_if_fail (GDL_IS_DOCK_TABLABEL (widget)); g_return_if_fail (allocation != NULL); bin = GTK_BIN (widget); tablabel = GDL_DOCK_TABLABEL (widget); border_width = gtk_container_get_border_width (GTK_CONTAINER (widget)); gtk_widget_set_allocation (widget, allocation); if (gtk_widget_get_realized (widget)) gdk_window_move_resize (tablabel->event_window, allocation->x, allocation->y, allocation->width, allocation->height); if (gtk_bin_get_child (bin) && gtk_widget_get_visible (gtk_bin_get_child (bin))) { GtkAllocation child_allocation; gtk_widget_get_allocation (widget, &widget_allocation); child_allocation.x = widget_allocation.x + border_width; child_allocation.y = widget_allocation.y + border_width; allocation->width = MAX (1, (int) allocation->width - (int) tablabel->drag_handle_size); child_allocation.x += tablabel->drag_handle_size; child_allocation.width = MAX (1, (int) allocation->width - 2 * border_width); child_allocation.height = MAX (1, (int) allocation->height - 2 * border_width); gtk_widget_size_allocate (gtk_bin_get_child (bin), &child_allocation); } }
static gboolean gdl_dock_tablabel_button_event (GtkWidget *widget, GdkEventButton *event) { GdlDockTablabel *tablabel; GtkAllocation widget_allocation; gboolean event_handled; g_return_val_if_fail (widget != NULL, FALSE); g_return_val_if_fail (GDL_IS_DOCK_TABLABEL (widget), FALSE); g_return_val_if_fail (event != NULL, FALSE); tablabel = GDL_DOCK_TABLABEL (widget); event_handled = FALSE; if (event->window != tablabel->event_window) return FALSE; switch (event->type) { case GDK_BUTTON_PRESS: if (tablabel->active) { gboolean in_handle; gint rel_x, rel_y; guint border_width; GtkBin *bin; bin = GTK_BIN (widget); border_width = gtk_container_get_border_width (GTK_CONTAINER (widget)); rel_x = event->x - border_width; rel_y = event->y - border_width; /* Check if user clicked on the drag handle. */ in_handle = (rel_x < tablabel->drag_handle_size * HANDLE_RATIO) && (rel_x > 0); if (event->button == 1) { tablabel->pre_drag = TRUE; tablabel->drag_start_event = *event; } else { g_signal_emit (widget, dock_tablabel_signals [BUTTON_PRESSED_HANDLE], 0, event); } event_handled = TRUE; } break; case GDK_BUTTON_RELEASE: tablabel->pre_drag = FALSE; break; default: break; } if (!event_handled) { /* propagate the event to the parent's gdkwindow */ GdkEventButton e; e = *event; e.window = gtk_widget_get_parent_window (widget); gtk_widget_get_allocation (widget, &widget_allocation); e.x += widget_allocation.x; e.y += widget_allocation.y; gdk_event_put ((GdkEvent *) &e); }; return event_handled; }