void wxStaticBox::GetBordersForSizer(int *borderTop, int *borderOther) const { GtkWidget* label = gtk_frame_get_label_widget(GTK_FRAME(m_widget)); #ifdef __WXGTK3__ *borderOther = 0; *borderTop = 0; if (label) { int nat_width; gtk_widget_get_preferred_width(label, NULL, &nat_width); gtk_widget_get_preferred_height_for_width(label, nat_width, borderTop, NULL); } #else gtk_widget_ensure_style(m_widget); const int border_width = GTK_CONTAINER(m_widget)->border_width; *borderOther = border_width + m_widget->style->xthickness; *borderTop = border_width; if (label) { GtkRequisition req; gtk_widget_size_request(label, &req); *borderTop += req.height; } else *borderTop += m_widget->style->ythickness; #endif }
static void gtk_application_window_real_size_allocate (GtkWidget *widget, GtkAllocation *allocation) { GtkApplicationWindow *window = GTK_APPLICATION_WINDOW (widget); if (window->priv->menubar != NULL) { GtkAllocation menubar_allocation; GtkAllocation child_allocation; gint menubar_height; GtkWidget *child; _gtk_window_set_allocation (GTK_WINDOW (widget), allocation, &child_allocation); menubar_allocation = child_allocation; gtk_widget_get_preferred_height_for_width (window->priv->menubar, menubar_allocation.width, &menubar_height, NULL); menubar_allocation.height = menubar_height; gtk_widget_size_allocate (window->priv->menubar, &menubar_allocation); child_allocation.y += menubar_height; child_allocation.height -= menubar_height; child = gtk_bin_get_child (GTK_BIN (window)); if (child != NULL && gtk_widget_get_visible (child)) gtk_widget_size_allocate (child, &child_allocation); } else GTK_WIDGET_CLASS (gtk_application_window_parent_class) ->size_allocate (widget, allocation); }
static void gtk_revealer_get_child_allocation (GtkRevealer *revealer, GtkAllocation *allocation, GtkAllocation *child_allocation) { GtkWidget *child; GtkRevealerTransitionType transition; g_return_if_fail (revealer != NULL); g_return_if_fail (allocation != NULL); child_allocation->x = 0; child_allocation->y = 0; child_allocation->width = allocation->width; child_allocation->height = allocation->height; child = gtk_bin_get_child (GTK_BIN (revealer)); if (child != NULL && gtk_widget_get_visible (child)) { transition = effective_transition (revealer); if (transition == GTK_REVEALER_TRANSITION_TYPE_SLIDE_LEFT || transition == GTK_REVEALER_TRANSITION_TYPE_SLIDE_RIGHT) gtk_widget_get_preferred_width_for_height (child, child_allocation->height, NULL, &child_allocation->width); else gtk_widget_get_preferred_height_for_width (child, child_allocation->width, NULL, &child_allocation->height); } }
/** * gtk_cell_view_get_size_of_row: * @cell_view: a #GtkCellView * @path: a #GtkTreePath * @requisition: (out): return location for the size * * Sets @requisition to the size needed by @cell_view to display * the model row pointed to by @path. * * Return value: %TRUE * * Since: 2.6 * * Deprecated: 3.0: Combo box formerly used this to calculate the * sizes for cellviews, now you can achieve this by either using * the #GtkCellView:fit-model property or by setting the currently * displayed row of the #GtkCellView and using gtk_widget_get_preferred_size(). */ gboolean gtk_cell_view_get_size_of_row (GtkCellView *cell_view, GtkTreePath *path, GtkRequisition *requisition) { GtkTreeRowReference *tmp; GtkRequisition req; g_return_val_if_fail (GTK_IS_CELL_VIEW (cell_view), FALSE); g_return_val_if_fail (path != NULL, FALSE); tmp = cell_view->priv->displayed_row; cell_view->priv->displayed_row = gtk_tree_row_reference_new (cell_view->priv->model, path); gtk_widget_get_preferred_width (GTK_WIDGET (cell_view), &req.width, NULL); gtk_widget_get_preferred_height_for_width (GTK_WIDGET (cell_view), req.width, &req.height, NULL); gtk_tree_row_reference_free (cell_view->priv->displayed_row); cell_view->priv->displayed_row = tmp; if (requisition) *requisition = req; return TRUE; }
static gint columns_gtk3_get_natfw_height(ColumnsChild *child) { gint ret; gtk_widget_get_preferred_height_for_width( child->widget, child->w, NULL, &ret); return ret; }
wxSize wxControl::DoGetBestSize() const { // Do not return any arbitrary default value... wxASSERT_MSG( m_widget, wxT("DoGetBestSize called before creation") ); wxSize best; if (m_wxwindow) { // this is not a native control, size_request is likely to be (0,0) best = wxControlBase::DoGetBestSize(); } else { GtkRequisition req; #ifdef __WXGTK3__ if (gtk_widget_get_request_mode(m_widget) != GTK_SIZE_REQUEST_HEIGHT_FOR_WIDTH) { gtk_widget_get_preferred_height(m_widget, NULL, &req.height); gtk_widget_get_preferred_width_for_height(m_widget, req.height, NULL, &req.width); } else { gtk_widget_get_preferred_width(m_widget, NULL, &req.width); gtk_widget_get_preferred_height_for_width(m_widget, req.width, NULL, &req.height); } #else GTK_WIDGET_GET_CLASS(m_widget)->size_request(m_widget, &req); #endif best.Set(req.width, req.height); } CacheBestSize(best); return best; }
/** * gtk_widget_get_preferred_size: * @widget: a #GtkWidget instance * @minimum_size: (out) (allow-none): location for storing the minimum size, or %NULL * @natural_size: (out) (allow-none): location for storing the natural size, or %NULL * * Retrieves the minimum and natural size of a widget, taking * into account the widget's preference for height-for-width management. * * This is used to retrieve a suitable size by container widgets which do * not impose any restrictions on the child placement. It can be used * to deduce toplevel window and menu sizes as well as child widgets in * free-form containers such as GtkLayout. * * <note><para>Handle with care. Note that the natural height of a height-for-width * widget will generally be a smaller size than the minimum height, since the required * height for the natural width is generally smaller than the required height for * the minimum width.</para></note> * * Since: 3.0 */ void gtk_widget_get_preferred_size (GtkWidget *widget, GtkRequisition *minimum_size, GtkRequisition *natural_size) { gint min_width, nat_width; gint min_height, nat_height; g_return_if_fail (GTK_IS_WIDGET (widget)); if (gtk_widget_get_request_mode (widget) == GTK_SIZE_REQUEST_HEIGHT_FOR_WIDTH) { gtk_widget_get_preferred_width (widget, &min_width, &nat_width); if (minimum_size) { minimum_size->width = min_width; gtk_widget_get_preferred_height_for_width (widget, min_width, &minimum_size->height, NULL); } if (natural_size) { natural_size->width = nat_width; gtk_widget_get_preferred_height_for_width (widget, nat_width, NULL, &natural_size->height); } } else /* GTK_SIZE_REQUEST_WIDTH_FOR_HEIGHT or CONSTANT_SIZE */ { gtk_widget_get_preferred_height (widget, &min_height, &nat_height); if (minimum_size) { minimum_size->height = min_height; gtk_widget_get_preferred_width_for_height (widget, min_height, &minimum_size->width, NULL); } if (natural_size) { natural_size->height = nat_height; gtk_widget_get_preferred_width_for_height (widget, nat_height, NULL, &natural_size->width); } } }
static void notebook_page_notify_cb (GtkNotebook *notebook, GParamSpec *spec, CinnamonControlCenterPrivate *priv) { int nat_height; GtkWidget *child; child = notebook_get_selected_page (GTK_WIDGET (notebook)); if (child == priv->scrolled_window || child == priv->search_scrolled) { gtk_widget_hide (W (priv->builder, "lock-button")); if (!g_strcmp0(g_getenv("XDG_CURRENT_DESKTOP"), "Unity")) gtk_widget_get_preferred_height_for_width (GTK_WIDGET (priv->main_vbox), UNITY_FIXED_WIDTH, NULL, &nat_height); else gtk_widget_get_preferred_height_for_width (GTK_WIDGET (priv->main_vbox), FIXED_WIDTH, NULL, &nat_height); gtk_scrolled_window_set_min_content_height (GTK_SCROLLED_WINDOW (priv->scrolled_window), priv->small_screen == SMALL_SCREEN_TRUE ? SMALL_SCREEN_FIXED_HEIGHT : nat_height); } else { /* set the scrolled window small so that it doesn't force the window to be larger than this panel */ if (!g_strcmp0(g_getenv("XDG_CURRENT_DESKTOP"), "Unity")) { gtk_widget_get_preferred_height_for_width (GTK_WIDGET (priv->window), UNITY_FIXED_WIDTH, NULL, &nat_height); gtk_scrolled_window_set_min_content_height (GTK_SCROLLED_WINDOW (priv->scrolled_window), MIN_ICON_VIEW_HEIGHT); gtk_window_resize (GTK_WINDOW (priv->window), UNITY_FIXED_WIDTH, nat_height); } else { gtk_widget_get_preferred_height_for_width (GTK_WIDGET (priv->window), FIXED_WIDTH, NULL, &nat_height); gtk_scrolled_window_set_min_content_height (GTK_SCROLLED_WINDOW (priv->scrolled_window), MIN_ICON_VIEW_HEIGHT); gtk_window_resize (GTK_WINDOW (priv->window), FIXED_WIDTH, nat_height); } } }
static void notebook_page_notify_cb (GtkNotebook *notebook, GParamSpec *spec, GnomeControlCenterPrivate *priv) { #if 0 int nat_height; #endif GtkWidget *child; child = notebook_get_selected_page (GTK_WIDGET (notebook)); /* make sure the home button is shown on all pages except the overview page */ if (child == priv->scrolled_window || child == priv->search_scrolled) { gtk_widget_hide (W (priv->builder, "home-button")); gtk_widget_show (W (priv->builder, "search-entry")); gtk_widget_hide (W (priv->builder, "lock-button")); gtk_scrolled_window_set_min_content_height (GTK_SCROLLED_WINDOW (priv->scrolled_window), priv->small_screen == SMALL_SCREEN_TRUE ? SMALL_SCREEN_FIXED_HEIGHT : YAST_FIXED_HEIGHT); #if 0 gtk_widget_get_preferred_height_for_width (GTK_WIDGET (priv->main_vbox), FIXED_WIDTH, NULL, &nat_height); gtk_scrolled_window_set_min_content_height (GTK_SCROLLED_WINDOW (priv->scrolled_window), priv->small_screen == SMALL_SCREEN_TRUE ? SMALL_SCREEN_FIXED_HEIGHT : nat_height); #endif } else { gtk_widget_show (W (priv->builder, "home-button")); gtk_widget_hide (W (priv->builder, "search-entry")); gtk_scrolled_window_set_min_content_height (GTK_SCROLLED_WINDOW (priv->scrolled_window), MIN_ICON_VIEW_HEIGHT); #if 0 /* set the scrolled window small so that it doesn't force the window to be larger than this panel */ gtk_widget_get_preferred_height_for_width (GTK_WIDGET (priv->window), FIXED_WIDTH, NULL, &nat_height); gtk_scrolled_window_set_min_content_height (GTK_SCROLLED_WINDOW (priv->scrolled_window), MIN_ICON_VIEW_HEIGHT); gtk_window_resize (GTK_WINDOW (priv->window), FIXED_WIDTH, nat_height); #endif } }
static void gd_notification_get_preferred_height_for_width (GtkWidget *widget, gint width, gint *minimum_height, gint *natural_height) { GdNotification *notification = GD_NOTIFICATION (widget); GdNotificationPrivate *priv = notification->priv; GtkBin *bin = GTK_BIN (widget); gint child_min, child_nat, child_width, button_width = 0; GtkWidget *child; GtkBorder padding; gint minimum = 0, natural = 0; get_padding_and_border (notification, &padding); if (priv->show_close_button) { gtk_widget_get_preferred_height (priv->close_button, &minimum, &natural); gtk_widget_get_preferred_width (priv->close_button, NULL, &button_width); } child = gtk_bin_get_child (bin); if (child && gtk_widget_get_visible (child)) { child_width = width - button_width - 2 * SHADOW_OFFSET_X - padding.left - padding.right; gtk_widget_get_preferred_height_for_width (child, child_width, &child_min, &child_nat); minimum = MAX (minimum, child_min); natural = MAX (natural, child_nat); } minimum += padding.top + padding.bottom + SHADOW_OFFSET_Y; natural += padding.top + padding.bottom + SHADOW_OFFSET_Y; if (minimum_height) *minimum_height = minimum; if (natural_height) *natural_height = natural; }
static void gtk_application_window_real_get_preferred_height_for_width (GtkWidget *widget, gint width, gint *minimum_height, gint *natural_height) { GtkApplicationWindow *window = GTK_APPLICATION_WINDOW (widget); GTK_WIDGET_CLASS (gtk_application_window_parent_class) ->get_preferred_height_for_width (widget, width, minimum_height, natural_height); if (window->priv->menubar != NULL) { gint menubar_min_height, menubar_nat_height; gtk_widget_get_preferred_height_for_width (window->priv->menubar, width, &menubar_min_height, &menubar_nat_height); *minimum_height += menubar_min_height; *natural_height += menubar_nat_height; } }
/* Like get_group_sizes(), but gets height for width or width for height */ static GtkRequestedSize * get_group_sizes_for_sizes(PSquare *self, GtkOrientation direction, GtkRequestedSize *perpendicular_sizes, unsigned n_groups) { PSquarePrivate *priv = P_SQUARE_PRIVATE(self); /* Allocate an array for the size of each column/row */ GtkRequestedSize *sizes = g_new0(GtkRequestedSize, n_groups); /* Get each child's size; set the width of each group * to the maximum size of each child in that group */ unsigned count = 0; GList *iter; for(iter = priv->children; iter; iter = g_list_next(iter)) { if(!gtk_widget_get_visible(iter->data)) continue; int child_minimal, child_natural; unsigned group_num; if(direction == GTK_ORIENTATION_HORIZONTAL) { gtk_widget_get_preferred_width_for_height(iter->data, perpendicular_sizes[count / n_groups].minimum_size, &child_minimal, &child_natural); group_num = count % n_groups; } else { gtk_widget_get_preferred_height_for_width(iter->data, perpendicular_sizes[count % n_groups].minimum_size, &child_minimal, &child_natural); group_num = count / n_groups; } sizes[group_num].minimum_size = MAX(child_minimal, sizes[group_num].minimum_size); sizes[group_num].natural_size = MAX(child_natural, sizes[group_num].natural_size); count++; } return sizes; }
static void gd_stack_get_preferred_height_for_width (GtkWidget* widget, gint width, gint *minimum_height, gint *natural_height) { GdStack *stack = GD_STACK (widget); GdStackPrivate *priv = stack->priv; GdStackChildInfo *child_info; GtkWidget *child; gint child_min, child_nat; GList *l; *minimum_height = 0; *natural_height = 0; for (l = priv->children; l != NULL; l = l->next) { child_info = l->data; child = child_info->widget; if (!priv->homogeneous && (priv->visible_child != child_info && priv->last_visible_child != child_info)) continue; if (gtk_widget_get_visible (child)) { gtk_widget_get_preferred_height_for_width (child, width, &child_min, &child_nat); *minimum_height = MAX (*minimum_height, child_min); *natural_height = MAX (*natural_height, child_nat); } } if (priv->last_visible_surface != NULL) { *minimum_height = MAX (*minimum_height, priv->last_visible_surface_allocation.height); *natural_height = MAX (*natural_height, priv->last_visible_surface_allocation.height); } }
static void gtk_revealer_get_child_allocation (GtkRevealer *revealer, GtkAllocation *allocation, GtkAllocation *child_allocation) { GtkWidget *child; GtkRevealerTransitionType transition; GtkBorder padding; gint vertical_padding, horizontal_padding; g_return_if_fail (revealer != NULL); g_return_if_fail (allocation != NULL); /* See explanation on gtk_revealer_real_size_allocate */ gtk_revealer_get_padding (revealer, &padding); vertical_padding = padding.top + padding.bottom; horizontal_padding = padding.left + padding.right; child_allocation->x = 0; child_allocation->y = 0; child_allocation->width = 0; child_allocation->height = 0; child = gtk_bin_get_child (GTK_BIN (revealer)); if (child != NULL && gtk_widget_get_visible (child)) { transition = effective_transition (revealer); if (transition == GTK_REVEALER_TRANSITION_TYPE_SLIDE_LEFT || transition == GTK_REVEALER_TRANSITION_TYPE_SLIDE_RIGHT) gtk_widget_get_preferred_width_for_height (child, MAX (0, allocation->height - vertical_padding), NULL, &child_allocation->width); else gtk_widget_get_preferred_height_for_width (child, MAX (0, allocation->width - horizontal_padding), NULL, &child_allocation->height); } child_allocation->width = MAX (child_allocation->width, allocation->width - horizontal_padding); child_allocation->height = MAX (child_allocation->height, allocation->height - vertical_padding); }
static void egg_scrolled_window_get_preferred_height_for_width (GtkWidget *widget, gint width, gint *minimum_height, gint *natural_height) { EggScrolledWindow *self = (EggScrolledWindow *)widget; EggScrolledWindowPrivate *priv = egg_scrolled_window_get_instance_private (self); g_return_if_fail (EGG_IS_SCROLLED_WINDOW (self)); GTK_WIDGET_CLASS (egg_scrolled_window_parent_class)->get_preferred_height_for_width (widget, width, minimum_height, natural_height); if (natural_height) { if (priv->max_content_height > -1) { GtkWidget *child; GtkStyleContext *style; GtkBorder border; gint child_min_height; gint child_nat_height; gint additional; if (!(child = gtk_bin_get_child (GTK_BIN (widget)))) return; style = gtk_widget_get_style_context (widget); gtk_style_context_get_border (style, gtk_style_context_get_state (style), &border); additional = border.top + border.bottom; gtk_widget_get_preferred_height_for_width (child, width, &child_min_height, &child_nat_height); if ((child_nat_height > *natural_height) && (priv->max_content_height > *natural_height)) *natural_height = MIN (priv->max_content_height, child_nat_height) + additional; } } }
static void gtk_application_window_real_size_allocate (GtkWidget *widget, GtkAllocation *allocation) { GtkApplicationWindow *window = GTK_APPLICATION_WINDOW (widget); if (window->priv->menubar != NULL) { GtkAllocation menubar_allocation = *allocation; gint menubar_height; GtkWidget *child; _gtk_window_set_allocation (GTK_WINDOW (widget), allocation); gtk_widget_get_preferred_height_for_width (window->priv->menubar, allocation->width, &menubar_height, NULL); menubar_allocation.height = menubar_height; gtk_widget_size_allocate (window->priv->menubar, &menubar_allocation); child = gtk_bin_get_child (GTK_BIN (window)); if (child != NULL && gtk_widget_get_visible (child)) { GtkAllocation child_allocation = *allocation; gint border_width; border_width = gtk_container_get_border_width (GTK_CONTAINER (window)); child_allocation.x += border_width; child_allocation.y += border_width + menubar_height; child_allocation.width = MAX (1, child_allocation.width - border_width * 2); child_allocation.height = MAX (1, child_allocation.height - border_width * 2 - menubar_height); gtk_widget_size_allocate (child, &child_allocation); } } else GTK_WIDGET_CLASS (gtk_application_window_parent_class) ->size_allocate (widget, allocation); }