void gdl_dock_add_item (GdlDock *dock, GdlDockItem *item, GdlDockPlacement placement) { g_return_if_fail (dock != NULL); g_return_if_fail (item != NULL); if (placement == GDL_DOCK_FLOATING) /* Add the item to a new floating dock */ gdl_dock_add_floating_item (dock, item, 0, 0, -1, -1); else { GdlDockItem *best_dock_item; /* Non-floating item. */ if (dock->root) { GdlDockPlacement local_placement; GtkRequisition preferred_size; best_dock_item = gdl_dock_find_best_placement_item (GDL_DOCK_ITEM (dock->root), placement, 0); local_placement = gdl_dock_refine_placement (dock, best_dock_item, placement); if(local_placement != placement) gwarn("placement changed"); gdl_dock_object_dock (GDL_DOCK_OBJECT (best_dock_item), GDL_DOCK_OBJECT (item), local_placement, NULL); } else { gdl_dock_object_dock (GDL_DOCK_OBJECT (dock), GDL_DOCK_OBJECT (item), placement, NULL); } } }
/** * gdl_dock_add_item: * @dock: A #GdlDock widget * @item: A #GdlDockItem widget * @placement: A position for the widget * * Dock in @dock, the widget @item at the position defined by @placement. The * function takes care of finding the right parent widget eventually creating * it if needed. */ void gdl_dock_add_item (GdlDock *dock, GdlDockItem *item, GdlDockPlacement placement) { GdlDockObject *placeholder; GdlDockObject *parent = NULL; GdlDockPlacement place; g_return_if_fail (dock != NULL); g_return_if_fail (item != NULL); /* Check if a placeholder widget already exist in the same dock */ placeholder = gdl_dock_master_get_object (GDL_DOCK_MASTER (gdl_dock_object_get_master (GDL_DOCK_OBJECT (dock))), gdl_dock_object_get_name (GDL_DOCK_OBJECT (item))); if ((placeholder != GDL_DOCK_OBJECT (item)) && (placeholder != NULL)) { if (gdl_dock_object_get_toplevel (placeholder) == dock) { parent = gdl_dock_object_get_parent_object (placeholder); } else { gtk_widget_destroy (GTK_WIDGET (placeholder)); } } if (parent && gdl_dock_object_child_placement (parent, placeholder, &place)) { gdl_dock_object_freeze (GDL_DOCK_OBJECT (parent)); gtk_widget_destroy (GTK_WIDGET (placeholder)); gdl_dock_object_dock (GDL_DOCK_OBJECT (parent), GDL_DOCK_OBJECT (item), place, NULL); gdl_dock_object_thaw (GDL_DOCK_OBJECT (parent)); } else if (placement == GDL_DOCK_FLOATING) /* Add the item to a new floating dock */ gdl_dock_add_floating_item (dock, item, 0, 0, -1, -1); else { GdlDockItem *best_dock_item; /* Non-floating item. */ if (dock->priv->root) { GdlDockPlacement local_placement; GtkRequisition preferred_size; best_dock_item = gdl_dock_find_best_placement_item (GDL_DOCK_ITEM (dock->priv->root), placement, 0); local_placement = gdl_dock_refine_placement (dock, best_dock_item, placement); gdl_dock_object_dock (GDL_DOCK_OBJECT (best_dock_item), GDL_DOCK_OBJECT (item), local_placement, NULL); } else { gdl_dock_object_dock (GDL_DOCK_OBJECT (dock), GDL_DOCK_OBJECT (item), placement, NULL); } } }
static void gdl_dock_master_drag_end (GdlDockItem *item, gboolean cancelled, gpointer data) { GdlDockMaster *master; GdlDockRequest *request; g_return_if_fail (data != NULL); g_return_if_fail (item != NULL); master = GDL_DOCK_MASTER (data); request = master->_priv->drag_request; g_return_if_fail (GDL_DOCK_OBJECT (item) == request->applicant); /* Erase previously drawn rectangle */ if (master->_priv->rect_drawn) gdl_dock_master_xor_rect (master); /* cancel conditions */ if (cancelled || request->applicant == request->target) return; /* dock object to the requested position */ gdl_dock_object_dock (request->target, request->applicant, request->position, &request->extra); g_signal_emit (master, master_signals [LAYOUT_CHANGED], 0); }
static void gdl_dock_dock (GdlDockObject *object, GdlDockObject *requestor, GdlDockPlacement position, GValue *user_data) { GdlDock *dock; g_return_if_fail (GDL_IS_DOCK (object)); /* only dock items allowed at this time */ g_return_if_fail (GDL_IS_DOCK_ITEM (requestor)); dock = GDL_DOCK (object); if (position == GDL_DOCK_FLOATING) { GdlDockItem *item = GDL_DOCK_ITEM (requestor); gint x, y, width, height; if (user_data && G_VALUE_HOLDS (user_data, GDK_TYPE_RECTANGLE)) { GdkRectangle *rect; rect = g_value_get_boxed (user_data); x = rect->x; y = rect->y; width = rect->width; height = rect->height; } else { x = y = 0; width = height = -1; } gdl_dock_add_floating_item (dock, item, x, y, width, height); } else if (dock->root) { /* This is somewhat a special case since we know which item to pass the request on because we only have on child */ gdl_dock_object_dock (dock->root, requestor, position, NULL); gdl_dock_set_title (dock); } else { /* Item about to be added is root item. */ GtkWidget *widget = GTK_WIDGET (requestor); dock->root = requestor; GDL_DOCK_OBJECT_SET_FLAGS (requestor, GDL_DOCK_ATTACHED); gtk_widget_set_parent (widget, GTK_WIDGET (dock)); gdl_dock_item_show_grip (GDL_DOCK_ITEM (requestor)); /* Realize the item (create its corresponding GdkWindow) when GdlDock has been realized. */ if (GTK_WIDGET_REALIZED (dock)) gtk_widget_realize (widget); /* Map the widget if it's visible and the parent is visible and has been mapped. This is done to make sure that the GdkWindow is visible. */ if (GTK_WIDGET_VISIBLE (dock) && GTK_WIDGET_VISIBLE (widget)) { if (GTK_WIDGET_MAPPED (dock)) gtk_widget_map (widget); /* Make the widget resize. */ gtk_widget_queue_resize (widget); } gdl_dock_set_title (dock); } }