static void
gtk_label_layoutable_size_allocate (GtkLayoutable        *layoutable,
                                    GtkAllocation        *allocation)
{
  GtkLabel *label = GTK_LABEL (layoutable);

  if (gtk_label_get_line_wrap (label))
    {
      PangoLayout *layout;
      PangoRectangle rect;

      /* Make it span the entire line.  */
      layout = gtk_label_get_layout (label);
      pango_layout_set_width (layout, allocation->width * PANGO_SCALE);
      pango_layout_get_extents (layout, NULL, &rect);

      allocation->width = rect.width / PANGO_SCALE + label->misc.xpad * 2;
      allocation->height = rect.height / PANGO_SCALE + label->misc.ypad * 2;

      gtk_misc_set_alignment (&label->misc, 0.0, 0.0);
      gtk_widget_size_allocate (GTK_WIDGET (label), allocation);
    }

  else
    (gtk_label_parent_layoutable_iface->size_allocate) (layoutable, allocation);
}
static void
gtk_label_layoutable_size_request (GtkLayoutable        *layoutable,
                                   GtkRequisition       *requisition)
{
  GtkLabel *label = GTK_LABEL (layoutable);

  if (gtk_label_get_line_wrap (label))
    requisition->width = requisition->height = 0;
  else
    gtk_widget_size_request (GTK_WIDGET (label), requisition);
}
Exemple #3
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;
}
Exemple #4
0
static gint columns_compute_width(Columns *cols, widget_dim_fn_t get_width)
{
  ColumnsChild *child;
  GList *children;
  gint i, ncols, colspan, retwidth, childwidth;
  const gint *percentages;
  static const gint onecol[] = {100};

#ifdef COLUMNS_WIDTH_DIAGNOSTICS
  printf("compute_width(%p): start\n", cols);
#endif

  retwidth = 0;

  ncols = 1;
  percentages = onecol;

  for (children = cols->children; children && (child = children->data);
       children = children->next) {

    if (!child->widget) {
      /* Column reconfiguration. */
      ncols = child->ncols;
      percentages = child->percentages;
      continue;
    }

    /* Only take visible widgets into account. */
    if (!gtk_widget_get_visible(child->widget))
      continue;

    childwidth = get_width(child);
    colspan = child->colspan ? child->colspan : ncols - child->colstart;

#ifdef COLUMNS_WIDTH_DIAGNOSTICS
    printf("compute_width(%p): ", cols);
    if (GTK_IS_LABEL(child->widget))
      printf("label %p '%s' wrap=%s: ",
             child->widget,
             gtk_label_get_text(GTK_LABEL(child->widget)),
             (gtk_label_get_line_wrap(GTK_LABEL(child->widget)) ? "TRUE"
                                                                : "FALSE"));
    else
      printf("widget %p: ", child->widget);
    {
      gint min, nat;
      gtk_widget_get_preferred_width(child->widget, &min, &nat);
      printf("minwidth=%d natwidth=%d ", min, nat);
    }
    printf("thiswidth=%d span=%d\n", childwidth, colspan);
#endif

    /*
     * To compute width: we know that childwidth + cols->spacing
     * needs to equal a certain percentage of the full width of
     * the container. So we work this value out, figure out how
     * wide the container will need to be to make that percentage
     * of it equal to that width, and ensure our returned width is
     * at least that much. Very simple really.
     */
    {
      int percent, thiswid, fullwid;

      percent = 0;
      for (i = 0; i < colspan; i++)
        percent += percentages[child->colstart + i];

      thiswid = childwidth + cols->spacing;
      /*
       * Since childwidth is (at least sometimes) the _minimum_
       * size the child needs, we must ensure that it gets _at
       * least_ that size. Hence, when scaling thiswid up to
       * fullwid, we must round up, which means adding percent-1
       * before dividing by percent.
       */
      fullwid = (thiswid * 100 + percent - 1) / percent;
#ifdef COLUMNS_WIDTH_DIAGNOSTICS
      printf("compute_width(%p): after %p, thiswid=%d fullwid=%d\n",
             cols,
             child->widget,
             thiswid,
             fullwid);
#endif

      /*
       * The above calculation assumes every widget gets
       * cols->spacing on the right. So we subtract
       * cols->spacing here to account for the extra load of
       * spacing on the right.
       */
      if (retwidth < fullwid - cols->spacing)
        retwidth = fullwid - cols->spacing;
    }
  }

  retwidth += 2 * gtk_container_get_border_width(GTK_CONTAINER(cols));

#ifdef COLUMNS_WIDTH_DIAGNOSTICS
  printf("compute_width(%p): done, returning %d\n", cols, retwidth);
#endif

  return retwidth;
}
Php::Value GtkLabel_::get_line_wrap()
{
	gboolean ret = gtk_label_get_line_wrap (GTK_LABEL(instance));

	return ret;
}