#include <gtk/gtk.h>
#include "clearlooks_style.h"
#include "clearlooks_rc_style.h"
#include "clearlooks_draw.h"
#include <math.h>
#include <string.h>
#include "bits.c"
#include "support.h"
//#include "config.h"
/* #define DEBUG 1 */
#define SCALE_SIZE 5
#define DETAIL(xx) ((detail) && (!strcmp(xx, detail)))
#define COMPARE_COLORS(a,b) (a.red == b.red && a.green == b.green && a.blue == b.blue)
#define DRAW_ARGS GtkStyle *style, \
GdkWindow *window, \
GtkStateType state_type, \
GtkShadowType shadow_type, \
GdkRectangle *area, \
GtkWidget *widget, \
const gchar *detail, \
gint x, \
gint y, \
gint width, \
gint height
static GdkGC *realize_color (GtkStyle * style, GdkColor * color);
static GtkStyleClass *parent_class;
static GList *progressbars = NULL;
static gint8 pboffset = 10;
static int timer_id = 0;
static void cl_progressbar_remove (gpointer data)
{
if (g_list_find (progressbars, data) == NULL)
return;
progressbars = g_list_remove (progressbars, data);
g_object_unref (data);
if (g_list_first(progressbars) == NULL) {
g_source_remove(timer_id);
timer_id = 0;
}
}
static void update_progressbar (gpointer data, gpointer user_data)
{
gfloat fraction;
if (data == NULL)
return;
fraction = gtk_progress_bar_get_fraction (GTK_PROGRESS_BAR (data));
/* update only if not filled */
if (fraction < 1.0)
gtk_widget_queue_resize ((GtkWidget*)data);
if (fraction >= 1.0 || GTK_PROGRESS (data)->activity_mode)
cl_progressbar_remove (data);
}
static gboolean timer_func (gpointer data)
{
g_list_foreach (progressbars, update_progressbar, NULL);
if (--pboffset < 0) pboffset = 9;
return (g_list_first(progressbars) != NULL);
}
static gboolean cl_progressbar_known(gconstpointer data)
{
return (g_list_find (progressbars, data) != NULL);
}
static void cl_progressbar_add (gpointer data)
{
if (!GTK_IS_PROGRESS_BAR (data))
return;
progressbars = g_list_append (progressbars, data);
g_object_ref (data);
g_signal_connect ((GObject*)data, "unrealize", G_CALLBACK (cl_progressbar_remove), data);
if (timer_id == 0)
timer_id = g_timeout_add (100, timer_func, NULL);
}
static GdkColor *
clearlooks_get_spot_color (ClearlooksRcStyle *clearlooks_rc)
{
GtkRcStyle *rc = GTK_RC_STYLE (clearlooks_rc);
if (clearlooks_rc->has_spot_color)
return &clearlooks_rc->spot_color;
else
return &rc->base[GTK_STATE_SELECTED];
}
/**************************************************************************/
/* used for optionmenus... */
static void
draw_tab (GtkStyle *style,
GdkWindow *window,
GtkStateType state_type,
GtkShadowType shadow_type,
GdkRectangle *area,
GtkWidget *widget,
const gchar *detail,
gint x,
gint y,
gint width,
gint height)
{
#define ARROW_SPACE 2
#define ARROW_LINE_HEIGHT 2
#define ARROW_LINE_WIDTH 5
ClearlooksStyle *clearlooks_style = CLEARLOOKS_STYLE (style);
GtkRequisition indicator_size;
GtkBorder indicator_spacing;
gint arrow_height;
option_menu_get_props (widget, &indicator_size, &indicator_spacing);
indicator_size.width += (indicator_size.width % 2) - 1;
arrow_height = indicator_size.width / 2 + 2;
x += (width - indicator_size.width) / 2;
y += height/2;
if (state_type == GTK_STATE_INSENSITIVE)
{
draw_arrow (window, style->light_gc[state_type], area,
GTK_ARROW_UP, 1+x, 1+y-arrow_height,
indicator_size.width, arrow_height);
draw_arrow (window, style->light_gc[state_type], area,
GTK_ARROW_DOWN, 1+x, 1+y+1,
indicator_size.width, arrow_height);
}
draw_arrow (window, style->fg_gc[state_type], area,
GTK_ARROW_UP, x, y-arrow_height,
indicator_size.width, arrow_height);
draw_arrow (window, style->fg_gc[state_type], area,
GTK_ARROW_DOWN, x, y+1,
indicator_size.width, arrow_height);
}
static void
clearlooks_draw_arrow (GtkStyle *style,
GdkWindow *window,
GtkStateType state,
GtkShadowType shadow,
GdkRectangle *area,
GtkWidget *widget,
const gchar *detail,
GtkArrowType arrow_type,
gboolean fill,
gint x,
gint y,
gint width,
gint height)
{
ClearlooksStyle *clearlooks_style = CLEARLOOKS_STYLE (style);
gint original_width, original_x;
GdkGC *gc;
sanitize_size (window, &width, &height);
if (is_combo_box (widget))
{
width = 7;
height = 5;
x+=2;
y+=4;
if (state == GTK_STATE_INSENSITIVE)
{
draw_arrow (window, style->light_gc[state], area,
GTK_ARROW_UP, 1+x, 1+y-height,
width, height);
draw_arrow (window, style->light_gc[state], area,
GTK_ARROW_DOWN, 1+x, 1+y+1,
width, height);
}
draw_arrow (window, style->fg_gc[state], area,
GTK_ARROW_UP, x, y-height,
width, height);
draw_arrow (window, style->fg_gc[state], area,
GTK_ARROW_DOWN, x, y+1,
width, height);
return;
}
original_width = width;
original_x = x;
/* Make spinbutton arrows and arrows in menus
* slightly larger to get the right pixels drawn */
if (DETAIL ("spinbutton"))
height += 1;
if (DETAIL("menuitem"))
{
width = 6;
height = 7;
}
/* Compensate arrow position for "sunken" look */
if (DETAIL ("spinbutton") && arrow_type == GTK_ARROW_DOWN &&
style->xthickness > 2 && style->ythickness > 2)
y -= 1;
if (widget && widget->parent && GTK_IS_COMBO (widget->parent->parent))
{
width -= 2;
height -=2;
x++;
}
calculate_arrow_geometry (arrow_type, &x, &y, &width, &height);
if (DETAIL ("menuitem"))
x = original_x + original_width - width;
if (DETAIL ("spinbutton") && (arrow_type == GTK_ARROW_DOWN))
y += 1;
if (state == GTK_STATE_INSENSITIVE)
draw_arrow (window, style->light_gc[state], area, arrow_type, x + 1, y + 1, width, height);
gc = style->fg_gc[state];
draw_arrow (window, gc, area, arrow_type, x, y, width, height);
}
static void
draw_flat_box (DRAW_ARGS)
{
ClearlooksStyle *clearlooks_style = CLEARLOOKS_STYLE (style);
g_return_if_fail (GTK_IS_STYLE (style));
g_return_if_fail (window != NULL);
sanitize_size (window, &width, &height);
if (detail &&
clearlooks_style->listviewitemstyle == 1 &&
state_type == GTK_STATE_SELECTED && (
!strncmp ("cell_even", detail, strlen ("cell_even")) ||
!strncmp ("cell_odd", detail, strlen ("cell_odd"))))
{
GdkGC *gc;
GdkColor lower_color;
GdkColor *upper_color;
if (GTK_WIDGET_HAS_FOCUS (widget))
{
gc = style->base_gc[state_type];
upper_color = &style->base[state_type];
}
else
{
gc = style->base_gc[GTK_STATE_ACTIVE];
upper_color = &style->base[GTK_STATE_ACTIVE];
}
if (GTK_IS_TREE_VIEW (widget) && 0)
{
GtkTreeSelection *sel = gtk_tree_view_get_selection (GTK_TREE_VIEW (widget));
if (gtk_tree_selection_count_selected_rows (sel) > 1)
{
parent_class->draw_flat_box (style, window, state_type, shadow_type,
area, widget, detail,
x, y, width, height);
return;
}
}
shade (upper_color, &lower_color, 0.8);
if (area)
gdk_gc_set_clip_rectangle (gc, area);
draw_hgradient (window, gc, style,
x, y, width, height, upper_color, &lower_color);
if (area)
gdk_gc_set_clip_rectangle (gc, NULL);
}
else
{
parent_class->draw_flat_b
评论0