2006-10-01 18:30:10 -04:00
|
|
|
/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
|
|
|
|
|
2002-02-15 09:37:25 -05:00
|
|
|
/* Metacity theme preview widget */
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Copyright (C) 2002 Havoc Pennington
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License as
|
|
|
|
* published by the Free Software Foundation; either version 2 of the
|
|
|
|
* License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful, but
|
|
|
|
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
|
|
|
|
* 02111-1307, USA.
|
|
|
|
*/
|
|
|
|
|
2008-02-26 23:39:10 -05:00
|
|
|
#define _GNU_SOURCE
|
|
|
|
#define _XOPEN_SOURCE 600 /* for the maths routines over floats */
|
|
|
|
|
|
|
|
#include <math.h>
|
2008-11-11 22:43:51 -05:00
|
|
|
#include <gtk/gtk.h>
|
2011-03-05 19:29:12 -05:00
|
|
|
#include <meta/preview-widget.h>
|
|
|
|
#include "theme-private.h"
|
2002-02-15 09:37:25 -05:00
|
|
|
|
2010-11-03 19:06:08 -04:00
|
|
|
static void meta_preview_get_preferred_width (GtkWidget *widget,
|
|
|
|
gint *minimum,
|
|
|
|
gint *natural);
|
|
|
|
static void meta_preview_get_preferred_height (GtkWidget *widget,
|
|
|
|
gint *minimum,
|
|
|
|
gint *natural);
|
2002-02-15 09:37:25 -05:00
|
|
|
static void meta_preview_size_allocate (GtkWidget *widget,
|
|
|
|
GtkAllocation *allocation);
|
2010-09-24 07:30:40 -04:00
|
|
|
static gboolean meta_preview_draw (GtkWidget *widget,
|
|
|
|
cairo_t *cr);
|
2002-02-15 09:37:25 -05:00
|
|
|
static void meta_preview_finalize (GObject *object);
|
|
|
|
|
2010-06-26 11:08:53 -04:00
|
|
|
G_DEFINE_TYPE (MetaPreview, meta_preview, GTK_TYPE_BIN);
|
2002-02-15 09:37:25 -05:00
|
|
|
|
|
|
|
static void
|
|
|
|
meta_preview_class_init (MetaPreviewClass *class)
|
|
|
|
{
|
|
|
|
GObjectClass *gobject_class = G_OBJECT_CLASS (class);
|
|
|
|
GtkWidgetClass *widget_class;
|
|
|
|
|
|
|
|
widget_class = (GtkWidgetClass*) class;
|
|
|
|
|
|
|
|
gobject_class->finalize = meta_preview_finalize;
|
|
|
|
|
2010-09-24 07:30:40 -04:00
|
|
|
widget_class->draw = meta_preview_draw;
|
2010-11-03 19:06:08 -04:00
|
|
|
widget_class->get_preferred_width = meta_preview_get_preferred_width;
|
|
|
|
widget_class->get_preferred_height = meta_preview_get_preferred_height;
|
2002-02-15 09:37:25 -05:00
|
|
|
widget_class->size_allocate = meta_preview_size_allocate;
|
2010-11-03 19:06:08 -04:00
|
|
|
|
|
|
|
gtk_container_class_handle_border_width (GTK_CONTAINER_CLASS (class));
|
2002-02-15 09:37:25 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
meta_preview_init (MetaPreview *preview)
|
|
|
|
{
|
2002-10-03 22:28:57 -04:00
|
|
|
int i;
|
2010-04-11 14:30:44 -04:00
|
|
|
|
|
|
|
gtk_widget_set_has_window (GTK_WIDGET (preview), FALSE);
|
2002-02-15 09:37:25 -05:00
|
|
|
|
2002-10-03 22:28:57 -04:00
|
|
|
i = 0;
|
|
|
|
while (i < MAX_BUTTONS_PER_CORNER)
|
|
|
|
{
|
|
|
|
preview->button_layout.left_buttons[i] = META_BUTTON_FUNCTION_LAST;
|
|
|
|
preview->button_layout.right_buttons[i] = META_BUTTON_FUNCTION_LAST;
|
|
|
|
++i;
|
|
|
|
}
|
|
|
|
|
|
|
|
preview->button_layout.left_buttons[0] = META_BUTTON_FUNCTION_MENU;
|
|
|
|
|
|
|
|
preview->button_layout.right_buttons[0] = META_BUTTON_FUNCTION_MINIMIZE;
|
|
|
|
preview->button_layout.right_buttons[1] = META_BUTTON_FUNCTION_MAXIMIZE;
|
|
|
|
preview->button_layout.right_buttons[2] = META_BUTTON_FUNCTION_CLOSE;
|
|
|
|
|
2002-02-15 09:37:25 -05:00
|
|
|
preview->type = META_FRAME_TYPE_NORMAL;
|
|
|
|
preview->flags =
|
|
|
|
META_FRAME_ALLOWS_DELETE |
|
|
|
|
META_FRAME_ALLOWS_MENU |
|
|
|
|
META_FRAME_ALLOWS_MINIMIZE |
|
|
|
|
META_FRAME_ALLOWS_MAXIMIZE |
|
|
|
|
META_FRAME_ALLOWS_VERTICAL_RESIZE |
|
|
|
|
META_FRAME_ALLOWS_HORIZONTAL_RESIZE |
|
|
|
|
META_FRAME_HAS_FOCUS |
|
|
|
|
META_FRAME_ALLOWS_SHADE |
|
|
|
|
META_FRAME_ALLOWS_MOVE;
|
|
|
|
|
|
|
|
preview->left_width = -1;
|
|
|
|
preview->right_width = -1;
|
|
|
|
preview->top_height = -1;
|
|
|
|
preview->bottom_height = -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
GtkWidget*
|
|
|
|
meta_preview_new (void)
|
|
|
|
{
|
|
|
|
MetaPreview *preview;
|
|
|
|
|
2010-06-26 11:08:53 -04:00
|
|
|
preview = g_object_new (META_TYPE_PREVIEW, NULL);
|
2002-02-15 09:37:25 -05:00
|
|
|
|
|
|
|
return GTK_WIDGET (preview);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
meta_preview_finalize (GObject *object)
|
|
|
|
{
|
2007-10-28 15:55:37 -04:00
|
|
|
MetaPreview *preview;
|
|
|
|
|
|
|
|
preview = META_PREVIEW (object);
|
|
|
|
|
|
|
|
g_free (preview->title);
|
|
|
|
preview->title = NULL;
|
|
|
|
|
2010-06-26 11:08:53 -04:00
|
|
|
G_OBJECT_CLASS (meta_preview_parent_class)->finalize (object);
|
2002-02-15 09:37:25 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
ensure_info (MetaPreview *preview)
|
|
|
|
{
|
|
|
|
GtkWidget *widget;
|
|
|
|
|
|
|
|
widget = GTK_WIDGET (preview);
|
|
|
|
|
|
|
|
if (preview->layout == NULL)
|
|
|
|
{
|
|
|
|
PangoFontDescription *font_desc;
|
|
|
|
double scale;
|
|
|
|
PangoAttrList *attrs;
|
|
|
|
PangoAttribute *attr;
|
|
|
|
|
|
|
|
if (preview->theme)
|
|
|
|
scale = meta_theme_get_title_scale (preview->theme,
|
|
|
|
preview->type,
|
|
|
|
preview->flags);
|
|
|
|
else
|
|
|
|
scale = 1.0;
|
|
|
|
|
|
|
|
preview->layout = gtk_widget_create_pango_layout (widget,
|
|
|
|
preview->title);
|
|
|
|
|
2002-05-23 22:55:54 -04:00
|
|
|
font_desc = meta_gtk_widget_get_font_desc (widget, scale, NULL);
|
2002-02-15 09:37:25 -05:00
|
|
|
|
|
|
|
preview->text_height =
|
|
|
|
meta_pango_font_desc_get_text_height (font_desc,
|
|
|
|
gtk_widget_get_pango_context (widget));
|
|
|
|
|
|
|
|
attrs = pango_attr_list_new ();
|
|
|
|
|
|
|
|
attr = pango_attr_size_new (pango_font_description_get_size (font_desc));
|
|
|
|
attr->start_index = 0;
|
|
|
|
attr->end_index = G_MAXINT;
|
|
|
|
|
|
|
|
pango_attr_list_insert (attrs, attr);
|
|
|
|
|
|
|
|
pango_layout_set_attributes (preview->layout, attrs);
|
|
|
|
|
|
|
|
pango_attr_list_unref (attrs);
|
|
|
|
|
|
|
|
pango_font_description_free (font_desc);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (preview->top_height < 0)
|
|
|
|
{
|
|
|
|
if (preview->theme)
|
|
|
|
{
|
|
|
|
meta_theme_get_frame_borders (preview->theme,
|
|
|
|
preview->type,
|
|
|
|
preview->text_height,
|
|
|
|
preview->flags,
|
|
|
|
&preview->top_height,
|
|
|
|
&preview->bottom_height,
|
|
|
|
&preview->left_width,
|
|
|
|
&preview->right_width);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
preview->top_height = 0;
|
|
|
|
preview->bottom_height = 0;
|
|
|
|
preview->left_width = 0;
|
|
|
|
preview->right_width = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-09-24 07:30:40 -04:00
|
|
|
static gboolean
|
|
|
|
meta_preview_draw (GtkWidget *widget,
|
|
|
|
cairo_t *cr)
|
|
|
|
{
|
|
|
|
MetaPreview *preview = META_PREVIEW (widget);
|
|
|
|
GtkAllocation allocation;
|
|
|
|
|
|
|
|
gtk_widget_get_allocation (widget, &allocation);
|
2002-02-15 09:37:25 -05:00
|
|
|
|
|
|
|
if (preview->theme)
|
|
|
|
{
|
2010-09-24 07:30:40 -04:00
|
|
|
int client_width;
|
|
|
|
int client_height;
|
|
|
|
MetaButtonState button_states[META_BUTTON_TYPE_LAST] =
|
|
|
|
{
|
|
|
|
META_BUTTON_STATE_NORMAL,
|
|
|
|
META_BUTTON_STATE_NORMAL,
|
|
|
|
META_BUTTON_STATE_NORMAL,
|
|
|
|
META_BUTTON_STATE_NORMAL
|
|
|
|
};
|
|
|
|
|
|
|
|
ensure_info (preview);
|
2010-09-27 07:55:28 -04:00
|
|
|
cairo_save (cr);
|
2010-09-23 11:35:41 -04:00
|
|
|
|
2010-11-03 19:06:08 -04:00
|
|
|
client_width = allocation.width - preview->left_width - preview->right_width;
|
|
|
|
client_height = allocation.height - preview->top_height - preview->bottom_height;
|
2010-09-24 07:30:40 -04:00
|
|
|
|
|
|
|
if (client_width < 0)
|
|
|
|
client_width = 1;
|
|
|
|
if (client_height < 0)
|
|
|
|
client_height = 1;
|
|
|
|
|
2002-02-15 09:37:25 -05:00
|
|
|
meta_theme_draw_frame (preview->theme,
|
|
|
|
widget,
|
2010-09-23 11:35:41 -04:00
|
|
|
cr,
|
2002-02-15 09:37:25 -05:00
|
|
|
preview->type,
|
|
|
|
preview->flags,
|
|
|
|
client_width, client_height,
|
|
|
|
preview->layout,
|
|
|
|
preview->text_height,
|
2002-10-03 22:28:57 -04:00
|
|
|
&preview->button_layout,
|
2002-02-15 09:37:25 -05:00
|
|
|
button_states,
|
|
|
|
meta_preview_get_mini_icon (),
|
|
|
|
meta_preview_get_icon ());
|
2010-09-23 11:35:41 -04:00
|
|
|
|
2010-09-27 07:55:28 -04:00
|
|
|
cairo_restore (cr);
|
2002-02-15 09:37:25 -05:00
|
|
|
}
|
|
|
|
|
2010-09-24 07:30:40 -04:00
|
|
|
/* draw child */
|
|
|
|
return GTK_WIDGET_CLASS (meta_preview_parent_class)->draw (widget, cr);
|
2002-02-15 09:37:25 -05:00
|
|
|
}
|
|
|
|
|
2010-11-03 19:06:08 -04:00
|
|
|
#define NO_CHILD_WIDTH 80
|
|
|
|
#define NO_CHILD_HEIGHT 20
|
|
|
|
|
2002-02-15 09:37:25 -05:00
|
|
|
static void
|
2010-11-03 19:06:08 -04:00
|
|
|
meta_preview_get_preferred_width (GtkWidget *widget,
|
|
|
|
gint *minimum,
|
|
|
|
gint *natural)
|
2002-02-15 09:37:25 -05:00
|
|
|
{
|
|
|
|
MetaPreview *preview;
|
2010-04-11 14:30:44 -04:00
|
|
|
GtkWidget *child;
|
2002-02-15 09:37:25 -05:00
|
|
|
|
|
|
|
preview = META_PREVIEW (widget);
|
|
|
|
|
|
|
|
ensure_info (preview);
|
|
|
|
|
2010-11-03 19:06:08 -04:00
|
|
|
*minimum = *natural = preview->left_width + preview->right_width;
|
2010-04-11 14:30:44 -04:00
|
|
|
|
|
|
|
child = gtk_bin_get_child (GTK_BIN (preview));
|
|
|
|
if (child && gtk_widget_get_visible (child))
|
2002-02-15 09:37:25 -05:00
|
|
|
{
|
2010-11-03 19:06:08 -04:00
|
|
|
gint child_min, child_nat;
|
2002-02-15 09:37:25 -05:00
|
|
|
|
2010-11-03 19:06:08 -04:00
|
|
|
gtk_widget_get_preferred_width (child, &child_min, &child_nat);
|
2002-02-15 09:37:25 -05:00
|
|
|
|
2010-11-03 19:06:08 -04:00
|
|
|
*minimum += child_min;
|
|
|
|
*natural += child_nat;
|
2002-02-15 09:37:25 -05:00
|
|
|
}
|
2002-10-03 22:28:57 -04:00
|
|
|
else
|
|
|
|
{
|
2010-11-03 19:06:08 -04:00
|
|
|
*minimum += NO_CHILD_WIDTH;
|
|
|
|
*natural += NO_CHILD_WIDTH;
|
2002-10-03 22:28:57 -04:00
|
|
|
}
|
2010-11-03 19:06:08 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
meta_preview_get_preferred_height (GtkWidget *widget,
|
|
|
|
gint *minimum,
|
|
|
|
gint *natural)
|
|
|
|
{
|
|
|
|
MetaPreview *preview;
|
|
|
|
GtkWidget *child;
|
|
|
|
|
|
|
|
preview = META_PREVIEW (widget);
|
|
|
|
|
|
|
|
ensure_info (preview);
|
|
|
|
|
|
|
|
*minimum = *natural = preview->top_height + preview->bottom_height;
|
|
|
|
|
|
|
|
child = gtk_bin_get_child (GTK_BIN (preview));
|
|
|
|
if (child && gtk_widget_get_visible (child))
|
|
|
|
{
|
|
|
|
gint child_min, child_nat;
|
|
|
|
|
|
|
|
gtk_widget_get_preferred_height (child, &child_min, &child_nat);
|
2002-02-15 09:37:25 -05:00
|
|
|
|
2010-11-03 19:06:08 -04:00
|
|
|
*minimum += child_min;
|
|
|
|
*natural += child_nat;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
*minimum += NO_CHILD_HEIGHT;
|
|
|
|
*natural += NO_CHILD_HEIGHT;
|
|
|
|
}
|
2002-02-15 09:37:25 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
meta_preview_size_allocate (GtkWidget *widget,
|
|
|
|
GtkAllocation *allocation)
|
|
|
|
{
|
|
|
|
MetaPreview *preview;
|
2010-04-11 14:30:44 -04:00
|
|
|
GtkAllocation widget_allocation, child_allocation;
|
|
|
|
GtkWidget *child;
|
|
|
|
|
2002-02-15 09:37:25 -05:00
|
|
|
preview = META_PREVIEW (widget);
|
|
|
|
|
|
|
|
ensure_info (preview);
|
|
|
|
|
2010-04-11 14:30:44 -04:00
|
|
|
gtk_widget_set_allocation (widget, allocation);
|
|
|
|
|
|
|
|
child = gtk_bin_get_child (GTK_BIN (widget));
|
|
|
|
if (child && gtk_widget_get_visible (child))
|
2002-02-15 09:37:25 -05:00
|
|
|
{
|
2010-04-11 14:30:44 -04:00
|
|
|
gtk_widget_get_allocation (widget, &widget_allocation);
|
2010-11-03 19:06:08 -04:00
|
|
|
child_allocation.x = widget_allocation.x + preview->left_width;
|
|
|
|
child_allocation.y = widget_allocation.y + preview->top_height;
|
2002-02-15 09:37:25 -05:00
|
|
|
|
2010-11-03 19:06:08 -04:00
|
|
|
child_allocation.width = MAX (1, widget_allocation.width - preview->left_width - preview->right_width);
|
|
|
|
child_allocation.height = MAX (1, widget_allocation.height - preview->top_height - preview->bottom_height);
|
2002-02-15 09:37:25 -05:00
|
|
|
|
2010-04-11 14:30:44 -04:00
|
|
|
gtk_widget_size_allocate (child, &child_allocation);
|
2002-02-15 09:37:25 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
clear_cache (MetaPreview *preview)
|
|
|
|
{
|
|
|
|
if (preview->layout)
|
|
|
|
{
|
|
|
|
g_object_unref (G_OBJECT (preview->layout));
|
|
|
|
preview->layout = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
preview->left_width = -1;
|
|
|
|
preview->right_width = -1;
|
|
|
|
preview->top_height = -1;
|
|
|
|
preview->bottom_height = -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
meta_preview_set_theme (MetaPreview *preview,
|
|
|
|
MetaTheme *theme)
|
|
|
|
{
|
|
|
|
g_return_if_fail (META_IS_PREVIEW (preview));
|
|
|
|
|
|
|
|
preview->theme = theme;
|
|
|
|
|
|
|
|
clear_cache (preview);
|
|
|
|
|
|
|
|
gtk_widget_queue_resize (GTK_WIDGET (preview));
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
meta_preview_set_title (MetaPreview *preview,
|
|
|
|
const char *title)
|
|
|
|
{
|
|
|
|
g_return_if_fail (META_IS_PREVIEW (preview));
|
|
|
|
|
|
|
|
g_free (preview->title);
|
|
|
|
preview->title = g_strdup (title);
|
|
|
|
|
|
|
|
clear_cache (preview);
|
|
|
|
|
|
|
|
gtk_widget_queue_resize (GTK_WIDGET (preview));
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
meta_preview_set_frame_type (MetaPreview *preview,
|
|
|
|
MetaFrameType type)
|
|
|
|
{
|
|
|
|
g_return_if_fail (META_IS_PREVIEW (preview));
|
|
|
|
|
|
|
|
preview->type = type;
|
|
|
|
|
|
|
|
clear_cache (preview);
|
|
|
|
|
|
|
|
gtk_widget_queue_resize (GTK_WIDGET (preview));
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
meta_preview_set_frame_flags (MetaPreview *preview,
|
|
|
|
MetaFrameFlags flags)
|
|
|
|
{
|
|
|
|
g_return_if_fail (META_IS_PREVIEW (preview));
|
|
|
|
|
|
|
|
preview->flags = flags;
|
|
|
|
|
|
|
|
clear_cache (preview);
|
|
|
|
|
|
|
|
gtk_widget_queue_resize (GTK_WIDGET (preview));
|
|
|
|
}
|
|
|
|
|
2002-10-03 22:28:57 -04:00
|
|
|
void
|
|
|
|
meta_preview_set_button_layout (MetaPreview *preview,
|
|
|
|
const MetaButtonLayout *button_layout)
|
|
|
|
{
|
|
|
|
g_return_if_fail (META_IS_PREVIEW (preview));
|
|
|
|
|
|
|
|
preview->button_layout = *button_layout;
|
|
|
|
|
|
|
|
gtk_widget_queue_draw (GTK_WIDGET (preview));
|
|
|
|
}
|
|
|
|
|
2002-02-15 09:37:25 -05:00
|
|
|
GdkPixbuf*
|
|
|
|
meta_preview_get_icon (void)
|
|
|
|
{
|
|
|
|
static GdkPixbuf *default_icon = NULL;
|
|
|
|
|
|
|
|
if (default_icon == NULL)
|
|
|
|
{
|
2008-08-14 10:01:51 -04:00
|
|
|
GtkIconTheme *theme;
|
|
|
|
gboolean icon_exists;
|
2002-02-15 09:37:25 -05:00
|
|
|
|
2008-08-14 10:01:51 -04:00
|
|
|
theme = gtk_icon_theme_get_default ();
|
2002-02-15 09:37:25 -05:00
|
|
|
|
2008-08-14 10:01:51 -04:00
|
|
|
icon_exists = gtk_icon_theme_has_icon (theme, META_DEFAULT_ICON_NAME);
|
2002-02-15 09:37:25 -05:00
|
|
|
|
2008-08-14 10:01:51 -04:00
|
|
|
if (icon_exists)
|
|
|
|
default_icon = gtk_icon_theme_load_icon (theme,
|
|
|
|
META_DEFAULT_ICON_NAME,
|
|
|
|
META_ICON_WIDTH,
|
|
|
|
0,
|
|
|
|
NULL);
|
|
|
|
else
|
|
|
|
default_icon = gtk_icon_theme_load_icon (theme,
|
|
|
|
"gtk-missing-image",
|
|
|
|
META_ICON_WIDTH,
|
|
|
|
0,
|
|
|
|
NULL);
|
2002-02-15 09:37:25 -05:00
|
|
|
|
2008-08-14 10:01:51 -04:00
|
|
|
g_assert (default_icon);
|
2002-02-15 09:37:25 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
return default_icon;
|
|
|
|
}
|
|
|
|
|
|
|
|
GdkPixbuf*
|
|
|
|
meta_preview_get_mini_icon (void)
|
|
|
|
{
|
|
|
|
static GdkPixbuf *default_icon = NULL;
|
|
|
|
|
|
|
|
if (default_icon == NULL)
|
|
|
|
{
|
2008-08-14 10:01:51 -04:00
|
|
|
GtkIconTheme *theme;
|
|
|
|
gboolean icon_exists;
|
2002-02-15 09:37:25 -05:00
|
|
|
|
2008-08-14 10:01:51 -04:00
|
|
|
theme = gtk_icon_theme_get_default ();
|
2002-02-15 09:37:25 -05:00
|
|
|
|
2008-08-14 10:01:51 -04:00
|
|
|
icon_exists = gtk_icon_theme_has_icon (theme, META_DEFAULT_ICON_NAME);
|
2002-02-15 09:37:25 -05:00
|
|
|
|
2008-08-14 10:01:51 -04:00
|
|
|
if (icon_exists)
|
|
|
|
default_icon = gtk_icon_theme_load_icon (theme,
|
|
|
|
META_DEFAULT_ICON_NAME,
|
|
|
|
META_MINI_ICON_WIDTH,
|
|
|
|
0,
|
|
|
|
NULL);
|
|
|
|
else
|
|
|
|
default_icon = gtk_icon_theme_load_icon (theme,
|
|
|
|
"gtk-missing-image",
|
|
|
|
META_MINI_ICON_WIDTH,
|
|
|
|
0,
|
|
|
|
NULL);
|
2002-02-15 09:37:25 -05:00
|
|
|
|
2008-08-14 10:01:51 -04:00
|
|
|
g_assert (default_icon);
|
2002-02-15 09:37:25 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
return default_icon;
|
|
|
|
}
|
2008-02-25 10:39:49 -05:00
|
|
|
|
2010-10-18 11:32:50 -04:00
|
|
|
cairo_region_t *
|
2008-02-25 10:39:49 -05:00
|
|
|
meta_preview_get_clip_region (MetaPreview *preview, gint new_window_width, gint new_window_height)
|
|
|
|
{
|
2010-10-18 11:32:50 -04:00
|
|
|
cairo_rectangle_int_t xrect;
|
|
|
|
cairo_region_t *corners_xregion, *window_xregion;
|
2008-02-25 10:39:49 -05:00
|
|
|
gint flags;
|
|
|
|
MetaFrameLayout *fgeom;
|
|
|
|
MetaFrameStyle *frame_style;
|
|
|
|
|
2008-02-26 23:39:10 -05:00
|
|
|
g_return_val_if_fail (META_IS_PREVIEW (preview), NULL);
|
2008-02-25 10:39:49 -05:00
|
|
|
|
|
|
|
flags = (META_PREVIEW (preview)->flags);
|
|
|
|
|
2010-10-18 11:32:50 -04:00
|
|
|
window_xregion = cairo_region_create ();
|
2008-03-29 17:29:57 -04:00
|
|
|
|
|
|
|
xrect.x = 0;
|
|
|
|
xrect.y = 0;
|
|
|
|
xrect.width = new_window_width;
|
|
|
|
xrect.height = new_window_height;
|
|
|
|
|
2010-10-18 11:32:50 -04:00
|
|
|
cairo_region_union_rectangle (window_xregion, &xrect);
|
2008-03-29 17:29:57 -04:00
|
|
|
|
|
|
|
if (preview->theme == NULL)
|
|
|
|
return window_xregion;
|
|
|
|
|
|
|
|
/* Otherwise, we do have a theme, so calculate the corners */
|
2008-02-25 10:39:49 -05:00
|
|
|
frame_style = meta_theme_get_frame_style (preview->theme,
|
|
|
|
META_FRAME_TYPE_NORMAL, flags);
|
|
|
|
|
|
|
|
fgeom = frame_style->layout;
|
|
|
|
|
2010-10-18 11:32:50 -04:00
|
|
|
corners_xregion = cairo_region_create ();
|
2008-02-25 10:39:49 -05:00
|
|
|
|
|
|
|
if (fgeom->top_left_corner_rounded_radius != 0)
|
|
|
|
{
|
|
|
|
const int corner = fgeom->top_left_corner_rounded_radius;
|
|
|
|
const float radius = sqrt(corner) + corner;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i=0; i<corner; i++)
|
|
|
|
{
|
|
|
|
|
|
|
|
const int width = floor(0.5 + radius - sqrt(radius*radius - (radius-(i+0.5))*(radius-(i+0.5))));
|
|
|
|
xrect.x = 0;
|
|
|
|
xrect.y = i;
|
|
|
|
xrect.width = width;
|
|
|
|
xrect.height = 1;
|
|
|
|
|
2010-10-18 11:32:50 -04:00
|
|
|
cairo_region_union_rectangle (corners_xregion, &xrect);
|
2008-02-25 10:39:49 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (fgeom->top_right_corner_rounded_radius != 0)
|
|
|
|
{
|
|
|
|
const int corner = fgeom->top_right_corner_rounded_radius;
|
|
|
|
const float radius = sqrt(corner) + corner;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i=0; i<corner; i++)
|
|
|
|
{
|
|
|
|
const int width = floor(0.5 + radius - sqrt(radius*radius - (radius-(i+0.5))*(radius-(i+0.5))));
|
|
|
|
xrect.x = new_window_width - width;
|
|
|
|
xrect.y = i;
|
|
|
|
xrect.width = width;
|
|
|
|
xrect.height = 1;
|
|
|
|
|
2010-10-18 11:32:50 -04:00
|
|
|
cairo_region_union_rectangle (corners_xregion, &xrect);
|
2008-02-25 10:39:49 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (fgeom->bottom_left_corner_rounded_radius != 0)
|
|
|
|
{
|
|
|
|
const int corner = fgeom->bottom_left_corner_rounded_radius;
|
|
|
|
const float radius = sqrt(corner) + corner;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i=0; i<corner; i++)
|
|
|
|
{
|
|
|
|
const int width = floor(0.5 + radius - sqrt(radius*radius - (radius-(i+0.5))*(radius-(i+0.5))));
|
|
|
|
xrect.x = 0;
|
|
|
|
xrect.y = new_window_height - i - 1;
|
|
|
|
xrect.width = width;
|
|
|
|
xrect.height = 1;
|
|
|
|
|
2010-10-18 11:32:50 -04:00
|
|
|
cairo_region_union_rectangle (corners_xregion, &xrect);
|
2008-02-25 10:39:49 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (fgeom->bottom_right_corner_rounded_radius != 0)
|
|
|
|
{
|
|
|
|
const int corner = fgeom->bottom_right_corner_rounded_radius;
|
|
|
|
const float radius = sqrt(corner) + corner;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i=0; i<corner; i++)
|
|
|
|
{
|
|
|
|
const int width = floor(0.5 + radius - sqrt(radius*radius - (radius-(i+0.5))*(radius-(i+0.5))));
|
|
|
|
xrect.x = new_window_width - width;
|
|
|
|
xrect.y = new_window_height - i - 1;
|
|
|
|
xrect.width = width;
|
|
|
|
xrect.height = 1;
|
|
|
|
|
2010-10-18 11:32:50 -04:00
|
|
|
cairo_region_union_rectangle (corners_xregion, &xrect);
|
2008-02-25 10:39:49 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-10-18 11:32:50 -04:00
|
|
|
cairo_region_subtract (window_xregion, corners_xregion);
|
|
|
|
cairo_region_destroy (corners_xregion);
|
2008-02-25 10:39:49 -05:00
|
|
|
|
|
|
|
return window_xregion;
|
|
|
|
}
|
|
|
|
|
|
|
|
|