Exemplo n.º 1
0
static void
anjuta_tabber_get_preferred_width (GtkWidget* widget, 
                                    gint* minimum,
                                    gint* preferred)
{
	g_return_if_fail (ANJUTA_IS_TABBER (widget));

	AnjutaTabber* tabber = ANJUTA_TABBER (widget);
	GtkStyleContext* context;
	GList* child;
	gint focus_width;
	gint focus_pad;
	gint tab_curvature;
	gint tab_overlap;

	*minimum = 0;
	*preferred = 0;
	
	gtk_widget_style_get (GTK_WIDGET (tabber->priv->notebook),
	                      "focus-line-width", &focus_width,
	                      "focus-padding", &focus_pad,
	                      "tab-curvature", &tab_curvature,
	                      "tab-overlap", &tab_overlap,
	                      NULL);

	context = gtk_widget_get_style_context (widget);

	for (child = tabber->priv->children; child != NULL; child = g_list_next (child))
	{
		GtkStateFlags state;
		GtkBorder tab_padding;
		gint xpadding;
		gint child_min;
		gint child_preferred;
		gint extra_space = 2 * (tab_curvature - tab_overlap);

		/* Get the padding of the tab */
		gtk_style_context_save (context);
		anjuta_tabber_setup_style_context (tabber, context, child, &state, NULL);
		gtk_style_context_get_padding (context, state, &tab_padding);
		gtk_style_context_restore (context);

		xpadding =  2 * (focus_width + focus_pad) + tab_padding.left + tab_padding.right;
		
		if (child->prev == NULL)
			extra_space += tab_overlap;
		if (child->next == NULL)
			extra_space += tab_overlap;
		
		gtk_widget_get_preferred_width (GTK_WIDGET (child->data), &child_min, &child_preferred);
		if (minimum)
		{
			*minimum += child_min + xpadding + extra_space;
		}
		if (preferred)
		{
			*preferred += child_preferred + xpadding + extra_space;
		}
	}
}
Exemplo n.º 2
0
static void
gtk_image_menu_item_get_preferred_width (GtkWidget        *widget,
        gint             *minimum,
        gint             *natural)
{
    GtkImageMenuItem *image_menu_item = GTK_IMAGE_MENU_ITEM (widget);
    GtkImageMenuItemPrivate *priv = image_menu_item->priv;
    GtkPackDirection pack_dir;
    GtkWidget *parent;

    parent = gtk_widget_get_parent (widget);

    if (GTK_IS_MENU_BAR (parent))
        pack_dir = gtk_menu_bar_get_child_pack_direction (GTK_MENU_BAR (parent));
    else
        pack_dir = GTK_PACK_DIRECTION_LTR;

    GTK_WIDGET_CLASS (gtk_image_menu_item_parent_class)->get_preferred_width (widget, minimum, natural);

    if ((pack_dir == GTK_PACK_DIRECTION_TTB || pack_dir == GTK_PACK_DIRECTION_BTT) &&
            priv->image &&
            gtk_widget_get_visible (priv->image))
    {
        gint child_minimum, child_natural;

        gtk_widget_get_preferred_width (priv->image, &child_minimum, &child_natural);

        *minimum = MAX (*minimum, child_minimum);
        *natural = MAX (*natural, child_natural);
    }
}
Exemplo n.º 3
0
Arquivo: gdl-dock.c Projeto: vldm/gdl
static void
gdl_dock_get_size (GtkWidget     *widget,
                   GtkOrientation orientation,
                   gint          *minimum,
                   gint          *natural)
{
    GdlDock       *dock;
    GtkContainer  *container;

    g_return_if_fail (widget != NULL);
    g_return_if_fail (GDL_IS_DOCK (widget));

    dock = GDL_DOCK (widget);
    container = GTK_CONTAINER (widget);

    *minimum = *natural = 0;

    /* make request to root */
    if (dock->priv->root && gtk_widget_get_visible (GTK_WIDGET (dock->priv->root))) {
        if (orientation == GTK_ORIENTATION_HORIZONTAL) {
            gtk_widget_get_preferred_width (GTK_WIDGET (dock->priv->root), minimum, natural);
        }
        else {
            gtk_widget_get_preferred_height (GTK_WIDGET (dock->priv->root), minimum, natural);
        }
    }
}
Exemplo n.º 4
0
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
}
Exemplo n.º 5
0
static void
gb_slider_get_preferred_width (GtkWidget *widget,
                                gint      *min_width,
                                gint      *nat_width)
{
  GbSlider *self = (GbSlider *)widget;
  GbSliderPrivate *priv = gb_slider_get_instance_private (self);
  gint real_min_width = 0;
  gint real_nat_width = 0;
  gsize i;

  g_assert (GB_IS_SLIDER (self));

  for (i = 0; i < priv->children->len; i++)
    {
      GbSliderChild *child;
      gint child_min_width = 0;
      gint child_nat_width = 0;

      child = g_ptr_array_index (priv->children, i);

      if ((child->position == GB_SLIDER_NONE) && gtk_widget_get_visible (child->widget))
        {
          gtk_widget_get_preferred_width (child->widget, &child_min_width, &child_nat_width);
          real_min_width = MAX (real_min_width, child_min_width);
          real_nat_width = MAX (real_nat_width, child_nat_width);
        }
    }

  *min_width = real_min_width;
  *nat_width = real_nat_width;
}
Exemplo n.º 6
0
static void
pnl_dock_revealer_get_child_preferred_width (PnlDockRevealer *self,
                                             gint            *min_width,
                                             gint            *nat_width)
{
  PnlDockRevealerPrivate *priv = pnl_dock_revealer_get_instance_private (self);
  GtkWidget *child;

  g_assert (PNL_IS_DOCK_REVEALER (self));
  g_assert (min_width != NULL);
  g_assert (nat_width != NULL);

  *min_width = 0;
  *nat_width = 0;

  if (NULL == (child = gtk_bin_get_child (GTK_BIN (self))))
    return;

  if (!gtk_widget_get_child_visible (child) || !gtk_widget_get_visible (child))
    return;

  gtk_widget_get_preferred_width (child, min_width, nat_width);

  if (IS_HORIZONTAL (priv->transition_type) && priv->position_set)
    {
      if (priv->position > *min_width)
        *nat_width = priv->position;
      else
        *nat_width = *min_width;
    }
}
Exemplo n.º 7
0
/**
 * 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 void
gtk_application_window_real_get_preferred_width (GtkWidget *widget,
                                                 gint      *minimum_width,
                                                 gint      *natural_width)
{
  GtkApplicationWindow *window = GTK_APPLICATION_WINDOW (widget);

  GTK_WIDGET_CLASS (gtk_application_window_parent_class)
    ->get_preferred_width (widget, minimum_width, natural_width);

  if (window->priv->menubar != NULL)
    {
      gint menubar_min_width, menubar_nat_width;
      gint border_width;
      GtkBorder border = { 0 };

      gtk_widget_get_preferred_width (window->priv->menubar, &menubar_min_width, &menubar_nat_width);

      border_width = gtk_container_get_border_width (GTK_CONTAINER (widget));
      _gtk_window_get_shadow_width (GTK_WINDOW (widget), &border);

      menubar_min_width += 2 * border_width + border.left + border.right;
      menubar_nat_width += 2 * border_width + border.left + border.right;

      *minimum_width = MAX (*minimum_width, menubar_min_width);
      *natural_width = MAX (*natural_width, menubar_nat_width);
    }
}
Exemplo n.º 9
0
void wxFrame::DoGetClientSize( int *width, int *height ) const
{
    wxASSERT_MSG( (m_widget != NULL), wxT("invalid frame") );

    wxFrameBase::DoGetClientSize(width, height);

    if (m_useCachedClientSize)
        return;

    if (height)
    {
#if wxUSE_MENUS_NATIVE
        // menu bar
        if (m_frameMenuBar && m_frameMenuBar->IsShown())
        {
            int h;
            gtk_widget_get_preferred_height(m_frameMenuBar->m_widget, NULL, &h);
#if !wxUSE_LIBHILDON && !wxUSE_LIBHILDON2
            *height -= h;
#endif
        }
#endif // wxUSE_MENUS_NATIVE

#if wxUSE_STATUSBAR
        // status bar
        if (m_frameStatusBar && m_frameStatusBar->IsShown())
            *height -= m_frameStatusBar->m_height;
#endif // wxUSE_STATUSBAR
    }

#if wxUSE_TOOLBAR
    // tool bar
    if (m_frameToolBar && m_frameToolBar->IsShown())
    {
        if (m_frameToolBar->IsVertical())
        {
            if (width)
            {
                int w;
                gtk_widget_get_preferred_width(m_frameToolBar->m_widget, NULL, &w);
                *width -= w;
            }
        }
        else
        {
            if (height)
            {
                int h;
                gtk_widget_get_preferred_height(m_frameToolBar->m_widget, NULL, &h);
                *height -= h;
            }
        }
    }
#endif // wxUSE_TOOLBAR

    if (width != NULL && *width < 0)
        *width = 0;
    if (height != NULL && *height < 0)
        *height = 0;
}
Exemplo n.º 10
0
static void
gstyle_color_widget_get_preferred_width (GtkWidget *widget,
                                         gint      *min_width,
                                         gint      *nat_width)
{
  GstyleColorWidget *self = (GstyleColorWidget *)widget;
  GtkWidget *child;
  gint spacing;

  g_assert (GSTYLE_IS_COLOR_WIDGET (self));

  *min_width = 1;
  *nat_width = 1;

  update_border_and_margin (self);

  child = gtk_bin_get_child (GTK_BIN (self));
  if (child && gtk_widget_get_visible (child))
    gtk_widget_get_preferred_width (child, min_width, nat_width);

  spacing = self->cached_border.left +
            self->cached_border.right +
            self->cached_margin.left +
            self->cached_margin.right;

  *min_width += spacing;
  *nat_width += spacing;
}
Exemplo n.º 11
0
static gint
cpufreq_applet_get_max_perc_width (CPUFreqApplet *applet)
{
	GtkWidget      *label;
#if GTK_CHECK_VERSION (3, 0, 0)
	gint            width;
#else
	GtkRequisition  req;
#endif

	if (applet->max_perc_width > 0)
		return applet->max_perc_width;

	label = gtk_label_new ("100%");
#if GTK_CHECK_VERSION (3, 0, 0)
	gtk_widget_get_preferred_width (applet->label, &width,&width);
	applet->max_perc_width = width +20; /*for some reason width always comes up 2 characters*/
#else
	gtk_widget_size_request (label, &req);
	applet->max_perc_width = req.width;
#endif
	gtk_widget_destroy (label);

	return applet->max_perc_width;
}
Exemplo n.º 12
0
static void
gtk_bubble_window_get_preferred_width (GtkWidget *widget,
                                       gint      *minimum_width,
                                       gint      *natural_width)
{
  GtkBubbleWindowPrivate *priv;
  GtkWidget *child;
  gint min, nat;
  GtkBorder border;

  priv = GTK_BUBBLE_WINDOW (widget)->priv;
  child = gtk_bin_get_child (GTK_BIN (widget));
  min = nat = 0;

  if (child)
    gtk_widget_get_preferred_width (child, &min, &nat);

  get_padding_and_border (widget, &border);
  min += border.left + border.right;
  nat += border.left + border.right;

  if (!POS_IS_VERTICAL (priv->final_position))
    {
      min += TAIL_HEIGHT;
      nat += TAIL_HEIGHT;
    }

  if (minimum_width)
    *minimum_width = MAX (min, TAIL_GAP_WIDTH);

  if (natural_width)
    *natural_width = MAX (nat, TAIL_GAP_WIDTH);
}
Exemplo n.º 13
0
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;
}
Exemplo n.º 14
0
static void
apply_background_to_window (GSManager *manager,
                            GSWindow  *window)
{
	cairo_surface_t *surface;
	int              width;
	int              height;

        mate_bg_load_from_preferences (manager->priv->bg);

	if (manager->priv->bg == NULL)
	{
		gs_debug ("No background available");
		gs_window_set_background_surface (window, NULL);
	}

	gtk_widget_get_preferred_width (GTK_WIDGET (window), &width, NULL);
	gtk_widget_get_preferred_height (GTK_WIDGET (window), &height, NULL);
	gs_debug ("Creating background w:%d h:%d", width, height);
	surface = mate_bg_create_surface (manager->priv->bg,
	                                  gs_window_get_gdk_window (window),
	                                  width,
	                                  height,
	                                  FALSE);
	gs_window_set_background_surface (window, surface);
	cairo_surface_destroy (surface);
}
Exemplo n.º 15
0
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;
}
Exemplo n.º 16
0
cpufreq_applet_size_request (GtkWidget *widget, GtkRequisition *requisition)
#endif
{
	CPUFreqApplet *applet;
	gint           labels_width = 0;
	gint           width;

	applet = CPUFREQ_APPLET (widget);

#if !GTK_CHECK_VERSION (3, 0, 0)
	GTK_WIDGET_CLASS (cpufreq_applet_parent_class)->size_request (widget, requisition);
#endif

	if (applet->orient == MATE_PANEL_APPLET_ORIENT_LEFT ||
	    applet->orient == MATE_PANEL_APPLET_ORIENT_RIGHT)
		return;


 	if (applet->show_freq) {
		labels_width += cpufreq_applet_get_max_label_width (applet) + 2;
 	}
 
 	if (applet->show_perc) {
		labels_width += cpufreq_applet_get_max_perc_width (applet);
 	}
 
 	if (applet->show_unit) {
		labels_width += cpufreq_applet_get_max_unit_width (applet);
	}

	if (applet->show_icon) {
#if GTK_CHECK_VERSION (3, 0, 0)
		gint icon_width;

		gtk_widget_get_preferred_width (applet->icon, &icon_width, NULL);
		width = gtk_orientable_get_orientation (GTK_ORIENTABLE (applet->box)) == GTK_ORIENTATION_HORIZONTAL ?
			labels_width + icon_width + 2 :
			MAX (labels_width, icon_width + 2);
#else
		GtkRequisition req;

		gtk_widget_size_request (applet->icon, &req);
		width = GTK_IS_HBOX (applet->box) ?
			labels_width + req.width + 2 :
			MAX (labels_width, req.width + 2);
#endif
	} else {
		width = labels_width;
	}

#if GTK_CHECK_VERSION (3, 0, 0)
	*minimum_width = *natural_width = width;
#else
	requisition->width = width;
#endif
}
Exemplo n.º 17
0
static void
gd_notification_get_preferred_width (GtkWidget *widget, gint *minimum_size, gint *natural_size)
{
  GdNotification *notification = GD_NOTIFICATION (widget);
  GdNotificationPrivate *priv = notification->priv;
  GtkBin *bin = GTK_BIN (widget);
  gint child_min, child_nat;
  GtkWidget *child;
  GtkBorder padding;
  gint minimum, natural;

  get_padding_and_border (notification, &padding);

  minimum = 0;
  natural = 0;

  child = gtk_bin_get_child (bin);
  if (child && gtk_widget_get_visible (child))
    {
      gtk_widget_get_preferred_width (child,
                                      &child_min, &child_nat);
      minimum += child_min;
      natural += child_nat;
    }

  if (priv->show_close_button)
    {
      gtk_widget_get_preferred_width (priv->close_button,
                                      &child_min, &child_nat);
      minimum += child_min;
      natural += child_nat;
    }

  minimum += padding.left + padding.right + 2 * SHADOW_OFFSET_X;
  natural += padding.left + padding.right + 2 * SHADOW_OFFSET_X;

 if (minimum_size)
    *minimum_size = minimum;

  if (natural_size)
    *natural_size = natural;
}
Exemplo n.º 18
0
static void
hd_status_plugin_item_get_preferred_width (GtkWidget *widget,
                                           gint      *minimal_width,
                                           gint      *natural_width)
{
  GtkWidget *child;

  child = gtk_bin_get_child (GTK_BIN (widget));

  if (child)
    gtk_widget_get_preferred_width (child, minimal_width, natural_width);
}
Exemplo n.º 19
0
static gint
cpufreq_applet_get_max_unit_width (CPUFreqApplet *applet)
{
	GtkWidget     *label;
	gint           w1, w2;

	if (applet->max_unit_width > 0)
		return applet->max_unit_width;

	label = gtk_label_new ("GHz");
        gtk_widget_get_preferred_width (label, &w1, NULL);

	gtk_label_set_text (GTK_LABEL (label), "MHz");
        gtk_widget_get_preferred_width (label, &w2, NULL);

	gtk_widget_destroy (label);

	applet->max_unit_width = MAX (w1, w2);

	return applet->max_unit_width;
}
Exemplo n.º 20
0
static void
color_swatch_get_preferred_width (GtkWidget *widget,
                                  gint *minimum_width,
                                  gint *natural_width)
{
	GtkhtmlColorSwatchPrivate *priv;

	priv = GTKHTML_COLOR_SWATCH (widget)->priv;

	gtk_widget_get_preferred_width (
		priv->frame, minimum_width, natural_width);
}
Exemplo n.º 21
0
static void
anjuta_tabber_get_preferred_width (GtkWidget* widget, 
                                    gint* minimum,
                                    gint* preferred)
{
	g_return_if_fail (ANJUTA_IS_TABBER (widget));

	AnjutaTabber* tabber = ANJUTA_TABBER (widget);
	GList* child;
	gint xthickness;
	gint focus_width;
	gint tab_curvature;
	gint tab_overlap;
	gint padding;
	
	GtkStyle* style = gtk_widget_get_style (widget);

	xthickness = style->xthickness;

	*minimum = 0;
	*preferred = 0;
	
	gtk_widget_style_get (GTK_WIDGET (tabber->priv->notebook),
	                      "focus-line-width", &focus_width,
	                      "tab-curvature", &tab_curvature,
	                      "tab-overlap", &tab_overlap,
	                      NULL);

	padding = xthickness + focus_width + tabber->priv->tab_hborder;
	
	for (child = tabber->priv->children; child != NULL; child = g_list_next (child))
	{
		gint child_min;
		gint child_preferred;
		gint extra_space = 2 * (tab_curvature - tab_overlap);
		
		if (child == g_list_first (tabber->priv->children))
			extra_space += tab_overlap;
		if (child == g_list_last (tabber->priv->children))
			extra_space += tab_overlap;
		
		gtk_widget_get_preferred_width (GTK_WIDGET (child->data), &child_min, &child_preferred);
		if (minimum)
		{
			*minimum += child_min + 2 * padding + extra_space;
		}
		if (preferred)
		{
			*preferred += child_preferred + 2 * padding + extra_space;
		}
	}
}
Exemplo n.º 22
0
static void
panel_applet_get_preferred_width (GtkWidget *widget,
                                  int       *minimum_width,
                                  int       *natural_width)
{
	PanelApplet *applet       = PANEL_APPLET (widget);
	GtkBin      *bin          = GTK_BIN (widget);
	GtkWidget   *child        = NULL;
	gint         focus_width  = 0;
	guint        border_width = 0;

	if (!applet->priv->has_handle) {
		GTK_WIDGET_CLASS (panel_applet_parent_class)->get_preferred_width (widget, minimum_width, natural_width);
	} else {
		child = gtk_bin_get_child (bin);

		if (child && gtk_widget_get_visible (child))
			gtk_widget_get_preferred_width (child, minimum_width, natural_width);

		border_width = gtk_container_get_border_width (GTK_CONTAINER (widget));
		*minimum_width += border_width;
		*natural_width += border_width;

		switch (panel_applet_get_orient (applet)) {
			case PANEL_APPLET_ORIENT_UP:
			case PANEL_APPLET_ORIENT_DOWN:
				*minimum_width += HANDLE_SIZE;
				*natural_width += HANDLE_SIZE;
				break;
			case PANEL_APPLET_ORIENT_LEFT:
			case PANEL_APPLET_ORIENT_RIGHT:
				break;
			default:
				g_assert_not_reached ();
				break;
		}
	}

	if (!panel_applet_can_focus (widget))
		return;

	/* We are deliberately ignoring focus-padding here to
	 * save valuable panel real estate.
	 */
	gtk_widget_style_get (widget, "focus-line-width", &focus_width, NULL);

	*minimum_width += 2 * focus_width;
	*natural_width += 2 * focus_width;
}
Exemplo n.º 23
0
static gint columns_gtk3_get_nat_width(ColumnsChild *child)
{
  gint ret;

  if ((GTK_IS_LABEL(child->widget) &&
       gtk_label_get_line_wrap(GTK_LABEL(child->widget))) ||
      GTK_IS_ENTRY(child->widget)) {
    /*
     * We treat wrapping GtkLabels as a special case in this
     * layout class, because the whole point of those is that I
     * _don't_ want them to take up extra horizontal space for
     * long text, but instead to wrap it to whatever size is used
     * by the rest of the layout.
     *
     * GtkEntry gets similar treatment, because in OS X GTK I've
     * found that it requests a natural width regardless of the
     * output of gtk_entry_set_width_chars.
     */
    gtk_widget_get_preferred_width(child->widget, &ret, NULL);
  } else {
    gtk_widget_get_preferred_width(child->widget, NULL, &ret);
  }
  return ret;
}
Exemplo n.º 24
0
static gint
cpufreq_applet_get_max_unit_width (CPUFreqApplet *applet)
{
	GtkWidget     *label;
#if !GTK_CHECK_VERSION (3, 0, 0)
	GtkRequisition req;
#endif
	gint           w1, w2;

	if (applet->max_unit_width > 0)
		return applet->max_unit_width;

	label = gtk_label_new ("GHz");
#if GTK_CHECK_VERSION (3, 0, 0)
	gtk_widget_get_preferred_width (applet->label, &w1, NULL);
#else
	gtk_widget_size_request (label, &req);
	w1 = req.width;
#endif

	gtk_label_set_text (GTK_LABEL (label), "MHz");
#if GTK_CHECK_VERSION (3, 0, 0)
	gtk_widget_get_preferred_width (applet->label, &w2, NULL);
#else
	gtk_widget_size_request (label, &req);
	w2 = req.width;
#endif

	gtk_widget_destroy (label);
#if GTK_CHECK_VERSION (3, 0, 0)
	applet->max_unit_width = MAX (w1, w2)-1;
#else
	applet->max_unit_width = MAX (w1, w2);
#endif
	return applet->max_unit_width;
}
Exemplo n.º 25
0
static void sp_button_get_preferred_width(GtkWidget *widget, gint *minimal_width, gint *natural_width)
{
    GtkWidget *child = gtk_bin_get_child(GTK_BIN(widget));
    GtkStyle *style = gtk_widget_get_style(widget);

    if (child) {
        gtk_widget_get_preferred_width(GTK_WIDGET(child), minimal_width, natural_width);
    } else {
        *minimal_width = 0;
        *natural_width = 0;
    }

    *minimal_width += 2 + 2 * MAX(2, style->xthickness);
    *natural_width += 2 + 2 * MAX(2, style->xthickness);
}
Exemplo n.º 26
0
static gint
cpufreq_applet_get_max_label_width (CPUFreqApplet *applet)
{
	GList *available_freqs;
	gint   width = 0;

	if (applet->max_label_width > 0)
		return applet->max_label_width;

	if (!CPUFREQ_IS_MONITOR (applet->monitor))
		return 0;

	available_freqs = cpufreq_monitor_get_available_frequencies (applet->monitor);
	while (available_freqs) {
		GtkWidget     *label;
#if GTK_CHECK_VERSION (3, 0, 0)
		gint           label_width;
#else
		GtkRequisition req;
#endif
		const gchar   *text;
		gchar         *freq_text;
		gint           freq;

		text = (const gchar *) available_freqs->data;
		freq = atoi (text);

		freq_text = cpufreq_utils_get_frequency_label (freq);
		label = gtk_label_new (freq_text);
#if GTK_CHECK_VERSION (3, 0, 0)
		gtk_widget_get_preferred_width (applet->label, &label_width, NULL);
		width = MAX (width, label_width); 
#endif
#if !GTK_CHECK_VERSION (3, 0, 0)
		gtk_widget_size_request (label, &req);
		width = MAX (width, req.width);
#endif

		g_free (freq_text);
		gtk_widget_destroy (label);

		available_freqs = g_list_next (available_freqs);
	}

	applet->max_label_width = width;

	return width;
}
Exemplo n.º 27
0
static gint
cpufreq_applet_get_max_perc_width (CPUFreqApplet *applet)
{
	GtkWidget *label;
        gint       width;

	if (applet->max_perc_width > 0)
		return applet->max_perc_width;

	label = gtk_label_new ("100%");
        gtk_widget_get_preferred_width (label, &width, NULL);
	applet->max_perc_width = width;
	gtk_widget_destroy (label);

	return applet->max_perc_width;
}
Exemplo n.º 28
0
/**
 * 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);
	}
    }
}
Exemplo n.º 29
0
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;
}
Exemplo n.º 30
0
static void
gtk_application_window_real_get_preferred_width (GtkWidget *widget,
                                                 gint      *minimum_width,
                                                 gint      *natural_width)
{
  GtkApplicationWindow *window = GTK_APPLICATION_WINDOW (widget);

  GTK_WIDGET_CLASS (gtk_application_window_parent_class)
    ->get_preferred_width (widget, minimum_width, natural_width);

  if (window->priv->menubar != NULL)
    {
      gint menubar_min_width, menubar_nat_width;

      gtk_widget_get_preferred_width (window->priv->menubar, &menubar_min_width, &menubar_nat_width);
      *minimum_width = MAX (*minimum_width, menubar_min_width);
      *natural_width = MAX (*natural_width, menubar_nat_width);
    }
}