Пример #1
0
static void
query_size (GtkStyleContext *context,
            gint            *width,
            gint            *height)
{
  GtkBorder margin, border, padding;
  int min_width, min_height;

  gtk_style_context_get_margin (context, &margin);
  gtk_style_context_get_border (context, &border);
  gtk_style_context_get_padding (context, &padding);

  gtk_style_context_get (context,
                         "min-width", &min_width,
                         "min-height", &min_height,
                         NULL);

  min_width += margin.left + margin.right + border.left + border.right + padding.left + padding.right;
  min_height += margin.top + margin.bottom + border.top + border.bottom + padding.top + padding.bottom;

  if (width)
    *width = MAX (*width, min_width);
  if (height)
    *height = MAX (*height, min_height);
}
Пример #2
0
static void
gd_tagged_entry_tag_get_margin (GdTaggedEntryTag *tag,
                                GdTaggedEntry *entry,
                                GtkBorder *margin)
{
    GtkStyleContext *context;

    context = gd_tagged_entry_tag_get_context (tag, entry);
    gtk_style_context_get_margin (context, 0, margin);
    g_object_unref (context);
}
Пример #3
0
static void
update_border_and_margin (GstyleColorWidget *self)
{
  GtkStyleContext *style_context;
  GtkStateFlags state;

  g_assert (GSTYLE_IS_COLOR_WIDGET (self));

  style_context = gtk_widget_get_style_context (GTK_WIDGET (self));
  state = gtk_style_context_get_state (style_context);

  gtk_style_context_get_margin (style_context, state, &self->cached_margin);
  gtk_style_context_get_border (style_context, state, &self->cached_border);
}
Пример #4
0
static void
xfce_arrow_button_get_thickness (GtkStyleContext *context, xfce_arrow_button_thickness *thickness)
{
    GtkBorder border;
    GtkBorder margin;
    GtkBorder padding;
    gint xthickness;
    gint ythickness;

    gtk_style_context_get_border (context, GTK_STATE_FLAG_NORMAL, &border);
    gtk_style_context_get_margin (context, GTK_STATE_FLAG_NORMAL, &margin);
    gtk_style_context_get_padding (context, GTK_STATE_FLAG_NORMAL, &padding);

    thickness->x = MAX (border.left + margin.left + padding.left,
                        border.right + margin.right + padding.right);
    thickness->y = MAX (border.top + margin.top + padding.top,
                        border.bottom + margin.bottom + padding.bottom);
}
Пример #5
0
static void
draw_style_common (GtkStyleContext *context,
                   cairo_t         *cr,
                   gint             x,
                   gint             y,
                   gint             width,
                   gint             height,
                   gint            *contents_x,
                   gint            *contents_y,
                   gint            *contents_width,
                   gint            *contents_height)
{
  GtkBorder margin, border, padding;
  int min_width, min_height;

  gtk_style_context_get_margin (context, &margin);
  gtk_style_context_get_border (context, &border);
  gtk_style_context_get_padding (context, &padding);

  gtk_style_context_get (context,
                         "min-width", &min_width,
                         "min-height", &min_height,
                         NULL);
  x += margin.left;
  y += margin.top;
  width -= margin.left + margin.right;
  height -= margin.top + margin.bottom;

  width = MAX (width, min_width);
  height = MAX (height, min_height);

  gtk_render_background (context, cr, x, y, width, height);
  gtk_render_frame (context, cr, x, y, width, height);

  if (contents_x)
    *contents_x = x + border.left + padding.left;
  if (contents_y)
    *contents_y = y + border.top + padding.top;
  if (contents_width)
    *contents_width = width - border.left - border.right - padding.left - padding.right;
  if (contents_height)
    *contents_height = height - border.top - border.bottom - padding.top - padding.bottom;
}
Пример #6
0
static void
gtk_level_bar_get_min_block_size (GtkLevelBar *self,
                                  gint        *block_width,
                                  gint        *block_height)
{
  GtkWidget *widget = GTK_WIDGET (self);
  GtkStyleContext *context;
  GtkStateFlags state;
  GtkBorder border, tmp, tmp2;
  gint min_width, min_height;

  context = gtk_widget_get_style_context (widget);
  gtk_style_context_save_to_node (context, self->priv->block_node[0]);
  state = gtk_style_context_get_state (context);
  gtk_style_context_get_border (context, state, &border);
  gtk_style_context_get_padding (context, state, &tmp);
  gtk_style_context_get_margin (context, state, &tmp2);
  gtk_style_context_restore (context);

  gtk_style_context_get_style (context,
                               "min-block-width", &min_width,
                               "min-block-height", &min_height,
                               NULL);

  border.top += tmp.top;
  border.right += tmp.right;
  border.bottom += tmp.bottom;
  border.left += tmp.left;

  border.top += tmp2.top;
  border.right += tmp2.right;
  border.bottom += tmp2.bottom;
  border.left += tmp2.left;

  if (block_width)
    *block_width = MAX (border.left + border.right, min_width);
  if (block_height)
    *block_height = MAX (border.top + border.bottom, min_height);
}
Пример #7
0
static void
gtk_level_bar_get_min_block_size (GtkLevelBar *self,
                                  gint        *block_width,
                                  gint        *block_height)
{
  GtkWidget *widget = GTK_WIDGET (self);
  GtkStyleContext *context = gtk_widget_get_style_context (widget);
  GtkStateFlags flags = gtk_widget_get_state_flags (widget);
  GtkBorder border, tmp, tmp2;
  gint min_width, min_height;

  gtk_style_context_save (context);
  gtk_style_context_add_class (context, STYLE_CLASS_FILL_BLOCK);
  gtk_style_context_get_border (context, flags, &border);
  gtk_style_context_get_padding (context, flags, &tmp);
  gtk_style_context_get_margin (context, flags, &tmp2);
  gtk_style_context_restore (context);

  gtk_style_context_get_style (context,
                               "min-block-width", &min_width,
                               "min-block-height", &min_height,
                               NULL);

  border.top += tmp.top;
  border.right += tmp.right;
  border.bottom += tmp.bottom;
  border.left += tmp.left;

  border.top += tmp2.top;
  border.right += tmp2.right;
  border.bottom += tmp2.bottom;
  border.left += tmp2.left;

  if (block_width)
    *block_width = MAX (border.left + border.right, min_width);
  if (block_height)
    *block_height = MAX (border.top + border.bottom, min_height);
}
Пример #8
0
static gint
gd_tagged_entry_tag_get_width (GdTaggedEntryTag *tag,
                               GdTaggedEntry *entry)
{
    GtkBorder button_padding, button_border, button_margin;
    GtkStyleContext *context;
    GtkStateFlags state;
    gint layout_width;
    gint button_width;
    gint scale_factor;

    gd_tagged_entry_tag_ensure_layout (tag, entry);
    pango_layout_get_pixel_size (tag->layout, &layout_width, NULL);

    context = gd_tagged_entry_tag_get_context (tag, entry);
    state = gd_tagged_entry_tag_get_state (tag, entry);

    gtk_style_context_get_padding (context, state, &button_padding);
    gtk_style_context_get_border (context, state, &button_border);
    gtk_style_context_get_margin (context, state, &button_margin);

    gd_tagged_entry_tag_ensure_close_surface (tag, context);

    g_object_unref (context);

    button_width = 0;
    if (entry->button_visible && tag->has_close_button)
    {
        scale_factor = gtk_widget_get_scale_factor (GTK_WIDGET (entry));
        button_width = cairo_image_surface_get_width (tag->close_surface) / scale_factor +
                       BUTTON_INTERNAL_SPACING;
    }

    return layout_width + button_padding.left + button_padding.right +
           button_border.left + button_border.right +
           button_margin.left + button_margin.right +
           button_width;
}
Пример #9
0
static void
gtk_level_bar_draw_fill_discrete (GtkLevelBar           *self,
                                  cairo_t               *cr,
                                  gboolean               inverted,
                                  cairo_rectangle_int_t *fill_area)
{
  GtkWidget *widget = GTK_WIDGET (self);
  GtkStyleContext *context = gtk_widget_get_style_context (widget);
  GtkStateFlags flags = gtk_widget_get_state_flags (widget);
  gint num_blocks, num_filled, idx;
  gint block_width, block_height;
  gint block_draw_width, block_draw_height;
  GtkBorder block_margin;
  cairo_rectangle_int_t block_area;

  gtk_level_bar_get_min_block_size (self, &block_width, &block_height);

  block_area = *fill_area;
  num_blocks = gtk_level_bar_get_num_blocks (self);
  num_filled = (gint) round (self->priv->cur_value) - (gint) round (self->priv->min_value);

  if (self->priv->orientation == GTK_ORIENTATION_HORIZONTAL)
    block_width = MAX (block_width, (gint) floor (block_area.width / num_blocks));
  else
    block_height = MAX (block_height, (gint) floor (block_area.height / num_blocks));

  gtk_style_context_save (context);
  gtk_style_context_add_class (context, STYLE_CLASS_FILL_BLOCK);
  gtk_style_context_get_margin (context, flags, &block_margin);

  block_draw_width = block_width - block_margin.left - block_margin.right;
  block_draw_height = block_height - block_margin.top - block_margin.bottom;

  if (self->priv->orientation == GTK_ORIENTATION_HORIZONTAL)
    {
      block_draw_height = MAX (block_draw_height, block_area.height - block_margin.top - block_margin.bottom);
      block_area.y += block_margin.top;

      if (inverted)
        block_area.x += block_area.width - block_draw_width;
    }
  else
    {
      block_draw_width = MAX (block_draw_width, block_area.width - block_margin.left - block_margin.right);
      block_area.x += block_margin.left;

      if (inverted)
        block_area.y += block_area.height - block_draw_height;
    }

  for (idx = 0; idx < num_blocks; idx++)
    {
      if (self->priv->orientation == GTK_ORIENTATION_HORIZONTAL)
        {
          if (inverted)
            block_area.x -= block_margin.right;
          else
            block_area.x += block_margin.left;
        }
      else
        {
          if (inverted)
            block_area.y -= block_margin.bottom;
          else
            block_area.y += block_margin.top;
        }

      if (idx > num_filled - 1)
        gtk_style_context_add_class (context, STYLE_CLASS_EMPTY_FILL_BLOCK);

      gtk_render_background (context, cr,
                             block_area.x, block_area.y,
                             block_draw_width, block_draw_height);
      gtk_render_frame (context, cr,
                        block_area.x, block_area.y,
                        block_draw_width, block_draw_height);

      if (self->priv->orientation == GTK_ORIENTATION_HORIZONTAL)
        {
          if (inverted)
            block_area.x -= block_draw_width + block_margin.left;
          else
            block_area.x += block_draw_width + block_margin.right;
        }
      else
        {
          if (inverted)
            block_area.y -= block_draw_height + block_margin.top;
          else
            block_area.y += block_draw_height + block_margin.bottom;
        }
    }

  gtk_style_context_restore (context);
}
Пример #10
0
static void
gtk_level_bar_draw_fill_continuous (GtkLevelBar           *self,
                                    cairo_t               *cr,
                                    gboolean               inverted,
                                    cairo_rectangle_int_t *fill_area)
{
  GtkWidget *widget = GTK_WIDGET (self);
  GtkStyleContext *context = gtk_widget_get_style_context (widget);
  GtkStateFlags flags = gtk_widget_get_state_flags (widget);
  cairo_rectangle_int_t base_area, block_area;
  GtkBorder block_margin;
  gdouble fill_percentage;

  gtk_style_context_save (context);
  gtk_style_context_add_class (context, STYLE_CLASS_FILL_BLOCK);
  gtk_style_context_get_margin (context, flags, &block_margin);

  /* render the empty (unfilled) part */
  base_area = *fill_area;
  base_area.x += block_margin.left;
  base_area.y += block_margin.top;
  base_area.width -= block_margin.left + block_margin.right;
  base_area.height -= block_margin.top + block_margin.bottom;

  gtk_style_context_add_class (context, STYLE_CLASS_EMPTY_FILL_BLOCK);

  gtk_render_background (context, cr, base_area.x, base_area.y,
                         base_area.width, base_area.height);
  gtk_render_frame (context, cr, base_area.x, base_area.y,
                    base_area.width, base_area.height);

  gtk_style_context_remove_class (context, STYLE_CLASS_EMPTY_FILL_BLOCK);

  /* now render the filled part on top of it */
  block_area = base_area;

  fill_percentage = (self->priv->cur_value - self->priv->min_value) /
    (self->priv->max_value - self->priv->min_value);

  if (self->priv->orientation == GTK_ORIENTATION_HORIZONTAL)
    {
      block_area.width = (gint) floor (block_area.width * fill_percentage);

      if (inverted)
        block_area.x += base_area.width - block_area.width;
    }
  else
    {
      block_area.height = (gint) floor (block_area.height * fill_percentage);

      if (inverted)
        block_area.y += base_area.height - block_area.height;
    }

  gtk_render_background (context, cr, block_area.x, block_area.y,
                         block_area.width, block_area.height);
  gtk_render_frame (context, cr, block_area.x, block_area.y,
                    block_area.width, block_area.height);

  gtk_style_context_restore (context);
}
Пример #11
0
static void
gtk_level_bar_draw_fill_discrete (GtkLevelBar           *self,
                                  cairo_t               *cr,
                                  cairo_rectangle_int_t *fill_area)
{
  GtkWidget *widget = GTK_WIDGET (self);
  GtkStyleContext *context;
  gint num_blocks, i;
  gint block_width, block_height;
  gint block_draw_width, block_draw_height;
  GtkBorder block_margin;
  cairo_rectangle_int_t block_area;

  context = gtk_widget_get_style_context (widget);
  gtk_level_bar_get_min_block_size (self, &block_width, &block_height);

  block_area = *fill_area;
  num_blocks = (gint) round (self->priv->max_value) - (gint) round (self->priv->min_value);

  if (self->priv->orientation == GTK_ORIENTATION_HORIZONTAL)
    block_width = MAX (block_width, (gint) floor (block_area.width / num_blocks));
  else
    block_height = MAX (block_height, (gint) floor (block_area.height / num_blocks));

  gtk_style_context_save_to_node (context, self->priv->block_node[0]);
  gtk_style_context_get_margin (context, gtk_style_context_get_state (context), &block_margin);
  gtk_style_context_restore (context);

  block_draw_width = block_width - block_margin.left - block_margin.right;
  block_draw_height = block_height - block_margin.top - block_margin.bottom;

  if (self->priv->orientation == GTK_ORIENTATION_HORIZONTAL)
    {
      block_draw_height = MAX (block_draw_height, block_area.height - block_margin.top - block_margin.bottom);
      block_area.y += block_margin.top;
    }
  else
    {
      block_draw_width = MAX (block_draw_width, block_area.width - block_margin.left - block_margin.right);
      block_area.x += block_margin.left;
    }

  for (i = 0; i < num_blocks; i++)
    {
      if (self->priv->orientation == GTK_ORIENTATION_HORIZONTAL)
        block_area.x += block_margin.left;
      else
        block_area.y += block_margin.top;

      gtk_style_context_save_to_node (context, self->priv->block_node[i]);

      gtk_render_background (context, cr,
                             block_area.x, block_area.y,
                             block_draw_width, block_draw_height);
      gtk_render_frame (context, cr,
                        block_area.x, block_area.y,
                        block_draw_width, block_draw_height);

      gtk_style_context_restore (context);

      if (self->priv->orientation == GTK_ORIENTATION_HORIZONTAL)
        block_area.x += block_draw_width + block_margin.right;
      else
        block_area.y += block_draw_height + block_margin.bottom;
    }
}
Пример #12
0
static void
gtk_level_bar_draw_fill_continuous (GtkLevelBar           *self,
                                    cairo_t               *cr,
                                    cairo_rectangle_int_t *fill_area)
{
  GtkWidget *widget = GTK_WIDGET (self);
  GtkStyleContext *context;
  cairo_rectangle_int_t base_area, block_area;
  GtkBorder block_margin;
  gdouble fill_percentage;
  gboolean inverted;

  inverted = self->priv->inverted;
  if (gtk_widget_get_direction (GTK_WIDGET (self)) == GTK_TEXT_DIR_RTL)
    {
      if (self->priv->orientation == GTK_ORIENTATION_HORIZONTAL)
        inverted = !inverted;
    }

  context = gtk_widget_get_style_context (widget);

  /* render the empty (unfilled) part */
  gtk_style_context_save_to_node (context, self->priv->block_node[inverted ? 0 : 1]);
  gtk_style_context_get_margin (context, gtk_style_context_get_state (context), &block_margin);

  base_area = *fill_area;
  base_area.x += block_margin.left;
  base_area.y += block_margin.top;
  base_area.width -= block_margin.left + block_margin.right;
  base_area.height -= block_margin.top + block_margin.bottom;

  gtk_render_background (context, cr, base_area.x, base_area.y,
                         base_area.width, base_area.height);
  gtk_render_frame (context, cr, base_area.x, base_area.y,
                    base_area.width, base_area.height);

  gtk_style_context_restore (context);

  /* now render the filled part on top of it */

  block_area = base_area;

  fill_percentage = (self->priv->cur_value - self->priv->min_value) /
    (self->priv->max_value - self->priv->min_value);

  if (self->priv->orientation == GTK_ORIENTATION_HORIZONTAL)
    {
      block_area.width = (gint) floor (block_area.width * fill_percentage);

      if (inverted)
        block_area.x += base_area.width - block_area.width;
    }
  else
    {
      block_area.height = (gint) floor (block_area.height * fill_percentage);

      if (inverted)
        block_area.y += base_area.height - block_area.height;
    }

  gtk_style_context_save_to_node (context, self->priv->block_node[inverted ? 1 : 0]);

  gtk_render_background (context, cr, block_area.x, block_area.y,
                         block_area.width, block_area.height);
  gtk_render_frame (context, cr, block_area.x, block_area.y,
                    block_area.width, block_area.height);

  gtk_style_context_restore (context);
}
Пример #13
0
static void
gd_tagged_entry_tag_get_relative_allocations (GdTaggedEntryTag *tag,
        GdTaggedEntry *entry,
        GtkStyleContext *context,
        GtkAllocation *background_allocation_out,
        GtkAllocation *layout_allocation_out,
        GtkAllocation *button_allocation_out)
{
    GtkAllocation background_allocation, layout_allocation, button_allocation;
    gint width, height, x, y, pix_width, pix_height;
    gint layout_width, layout_height;
    gint scale_factor;
    GtkBorder padding, border;
    GtkStateFlags state;

    width = gdk_window_get_width (tag->window);
    height = gdk_window_get_height (tag->window);
    scale_factor = gdk_window_get_scale_factor (tag->window);

    state = gd_tagged_entry_tag_get_state (tag, entry);
    gtk_style_context_get_margin (context, state, &padding);

    width -= padding.left + padding.right;
    height -= padding.top + padding.bottom;
    x = padding.left;
    y = padding.top;

    background_allocation.x = x;
    background_allocation.y = y;
    background_allocation.width = width;
    background_allocation.height = height;

    layout_allocation = button_allocation = background_allocation;

    gtk_style_context_get_padding (context, state, &padding);
    gtk_style_context_get_border (context, state, &border);

    gd_tagged_entry_tag_ensure_layout (tag, entry);
    pango_layout_get_pixel_size (tag->layout, &layout_width, &layout_height);

    layout_allocation.x += border.left + padding.left;
    layout_allocation.y += (layout_allocation.height - layout_height) / 2;

    if (entry->button_visible && tag->has_close_button)
    {
        pix_width = cairo_image_surface_get_width (tag->close_surface) / scale_factor;
        pix_height = cairo_image_surface_get_height (tag->close_surface) / scale_factor;
    }
    else
    {
        pix_width = 0;
        pix_height = 0;
    }

    button_allocation.x += width - pix_width - border.right - padding.right;
    button_allocation.y += (height - pix_height) / 2;
    button_allocation.width = pix_width;
    button_allocation.height = pix_height;

    if (background_allocation_out)
        *background_allocation_out = background_allocation;
    if (layout_allocation_out)
        *layout_allocation_out = layout_allocation;
    if (button_allocation_out)
        *button_allocation_out = button_allocation;
}