Style is a GObject now

master
Yevgen Muntyan 2007-06-18 07:40:31 -05:00
parent d23348e170
commit 6e4202e4c5
17 changed files with 500 additions and 270 deletions

View File

@ -34,7 +34,7 @@
</configure>
</optimized>
</configurations>
<file_selector_dir>/home/muntyan/projects/moo/po-gsv/</file_selector_dir>
<file_selector_dir>/home/muntyan/projects/moo/moo/mooedit/</file_selector_dir>
<run>
<args>--new-app</args>
<exe>medit/medit</exe>

View File

@ -31,6 +31,7 @@ upstream_sources = \
upstream/gtksourcelanguage.h \
upstream/gtksourcelanguage-private.h \
upstream/gtksourcelanguagemanager.h \
upstream/gtksourcestyle-private.h \
upstream/gtksourcestyle.h \
upstream/gtksourcestylemanager.h \
upstream/gtksourcestylescheme.h \
@ -52,6 +53,7 @@ gtksourceview_sources = \
gtksourceengine-mangled.h \
gtksourceiter-mangled.h \
gtksourcelanguagemanager-mangled.h \
gtksourcestyle-private-mangled.h \
gtksourcestyle-mangled.h \
gtksourcestylemanager-mangled.h \
gtksourcestylescheme-mangled.h \

View File

@ -6,6 +6,7 @@
#include "mooedit/gtksourceview/gtksourcelanguagemanager-mangled.h"
#include "mooedit/gtksourceview/gtksourcestylemanager-mangled.h"
#include "mooedit/gtksourceview/gtksourceiter-mangled.h"
#include "mooedit/gtksourceview/gtksourcestyle-private-mangled.h"
#define GtkSourceLanguage MooGtkSourceLanguage
#define GtkSourceLanguageClass MooGtkSourceLanguageClass
@ -41,7 +42,8 @@
#define gtk_source_style_scheme_get_id _moo_gtk_source_style_scheme_get_id
#define gtk_source_style_scheme_get_name _moo_gtk_source_style_scheme_get_name
#define gtk_source_style_scheme_get_style _moo_gtk_source_style_scheme_get_style
#define gtk_source_style_free _moo_gtk_source_style_free
#define gtk_source_style_scheme_get_current_line_color _moo_gtk_source_style_scheme_get_current_line_color
#define _gtk_source_style_scheme_apply _moo_gtk_source_style_scheme_apply
#define _gtk_source_style_apply _moo_gtk_source_style_apply

View File

@ -17,6 +17,7 @@ upstream_sources = \
gtksourcelanguage-private.h \
gtksourcelanguagemanager.h \
gtksourcestyle.h \
gtksourcestyle-private.h \
gtksourcestylemanager.h \
gtksourcestylescheme.h \
gtktextregion.h \

View File

@ -24,6 +24,7 @@
#include "gtktextregion.h"
#include "gtksourcelanguage-private.h"
#include "gtksourcebuffer.h"
#include "gtksourcestyle-private.h"
#include <glib/gregex.h>
#include <errno.h>
#include <string.h>
@ -564,7 +565,7 @@ set_tag_style (GtkSourceContextEngine *ce,
if (style != NULL)
{
_gtk_source_style_apply (style, tag);
gtk_source_style_free (style);
g_object_unref (style);
}
}

View File

@ -49,6 +49,10 @@ struct _GtkSourceLanguage
struct _GtkSourceLanguageClass
{
GObjectClass parent_class;
/* Padding for future expansion */
void (*_gtk_source_reserved1) (void);
void (*_gtk_source_reserved2) (void);
};
GType gtk_source_language_get_type (void) G_GNUC_CONST;

View File

@ -0,0 +1,59 @@
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8; coding: utf-8 -*-
* gtksourcestyle-private.h
*
* Copyright (C) 2003 - Paolo Maggi <paolo.maggi@polito.it>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU Library 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 Library General Public License for more details.
*
* You should have received a copy of the GNU Library 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.
*/
#ifndef __GTK_SOURCE_STYLE_PRIVATE_H__
#define __GTK_SOURCE_STYLE_PRIVATE_H__
#include "gtksourcestyle.h"
G_BEGIN_DECLS
#define GTK_SOURCE_STYLE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GTK_TYPE_SOURCE_STYLE, GtkSourceStyleClass))
#define GTK_IS_SOURCE_STYLE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GTK_TYPE_SOURCE_STYLE))
#define GTK_SOURCE_STYLE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GTK_TYPE_SOURCE_STYLE, GtkSourceStyleClass))
enum {
GTK_SOURCE_STYLE_USE_BACKGROUND = 1 << 0, /*< nick=use_background >*/
GTK_SOURCE_STYLE_USE_FOREGROUND = 1 << 1, /*< nick=use_foreground >*/
GTK_SOURCE_STYLE_USE_ITALIC = 1 << 2, /*< nick=use_italic >*/
GTK_SOURCE_STYLE_USE_BOLD = 1 << 3, /*< nick=use_bold >*/
GTK_SOURCE_STYLE_USE_UNDERLINE = 1 << 4, /*< nick=use_underline >*/
GTK_SOURCE_STYLE_USE_STRIKETHROUGH = 1 << 5 /*< nick=use_strikethrough >*/
};
struct _GtkSourceStyle
{
GObject base_instance;
const gchar *foreground;
const gchar *background;
guint italic : 1;
guint bold : 1;
guint underline : 1;
guint strikethrough : 1;
guint mask : 12;
};
void _gtk_source_style_apply (const GtkSourceStyle *style,
GtkTextTag *tag);
G_END_DECLS
#endif /* __GTK_SOURCE_STYLE_PRIVATE_H__ */

View File

@ -18,77 +18,341 @@
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#include "gtksourcestyle.h"
#include "gtksourcestyle-private.h"
#include "gtksourceview-i18n.h"
GType
gtk_source_style_get_type (void)
static void gtk_source_style_set_property (GObject *object,
guint prop_id,
const GValue *value,
GParamSpec *pspec);
static void gtk_source_style_get_property (GObject *object,
guint prop_id,
GValue *value,
GParamSpec *pspec);
typedef GObjectClass GtkSourceStyleClass;
G_DEFINE_TYPE (GtkSourceStyle, gtk_source_style, G_TYPE_OBJECT)
enum {
PROP_0,
PROP_BACKGROUND,
PROP_BACKGROUND_SET,
PROP_FOREGROUND,
PROP_FOREGROUND_SET,
PROP_BOLD,
PROP_BOLD_SET,
PROP_ITALIC,
PROP_ITALIC_SET,
PROP_UNDERLINE,
PROP_UNDERLINE_SET,
PROP_STRIKETHROUGH,
PROP_STRIKETHROUGH_SET
};
static void
gtk_source_style_class_init (GtkSourceStyleClass *klass)
{
static GType type;
GObjectClass *object_class = G_OBJECT_CLASS (klass);
if (G_UNLIKELY (type == 0))
type = g_boxed_type_register_static ("GtkSourceStyle",
(GBoxedCopyFunc) gtk_source_style_copy,
(GBoxedFreeFunc) gtk_source_style_free);
object_class->set_property = gtk_source_style_set_property;
object_class->get_property = gtk_source_style_get_property;
return type;
g_object_class_install_property (object_class,
PROP_BACKGROUND,
g_param_spec_string ("background",
_("Background"),
_("Background color"),
NULL,
G_PARAM_READWRITE));
g_object_class_install_property (object_class,
PROP_FOREGROUND,
g_param_spec_string ("foreground",
_("Foreground"),
_("Foreground color"),
NULL,
G_PARAM_READWRITE));
g_object_class_install_property (object_class,
PROP_BOLD,
g_param_spec_boolean ("bold",
_("Bold"),
_("Bold"),
FALSE,
G_PARAM_READWRITE));
g_object_class_install_property (object_class,
PROP_ITALIC,
g_param_spec_boolean ("italic",
_("Italic"),
_("Italic"),
FALSE,
G_PARAM_READWRITE));
g_object_class_install_property (object_class,
PROP_UNDERLINE,
g_param_spec_boolean ("underline",
_("Underline"),
_("Underline"),
FALSE,
G_PARAM_READWRITE));
g_object_class_install_property (object_class,
PROP_STRIKETHROUGH,
g_param_spec_boolean ("strikethrough",
_("Strikethrough"),
_("Strikethrough"),
FALSE,
G_PARAM_READWRITE));
g_object_class_install_property (object_class,
PROP_FOREGROUND_SET,
g_param_spec_boolean ("foreground-set",
_("Foreground set"),
_("Whether foreground color is set"),
FALSE,
G_PARAM_READWRITE));
g_object_class_install_property (object_class,
PROP_BACKGROUND_SET,
g_param_spec_boolean ("background-set",
_("Background set"),
_("Whether background color is set"),
FALSE,
G_PARAM_READWRITE));
g_object_class_install_property (object_class,
PROP_BOLD_SET,
g_param_spec_boolean ("bold-set",
_("Bold set"),
_("Whether bold attribute is set"),
FALSE,
G_PARAM_READWRITE));
g_object_class_install_property (object_class,
PROP_ITALIC_SET,
g_param_spec_boolean ("italic-set",
_("Italic set"),
_("Whether italic attribute is set"),
FALSE,
G_PARAM_READWRITE));
g_object_class_install_property (object_class,
PROP_UNDERLINE_SET,
g_param_spec_boolean ("underline-set",
_("Underline set"),
_("Whether underline attribute is set"),
FALSE,
G_PARAM_READWRITE));
g_object_class_install_property (object_class,
PROP_STRIKETHROUGH_SET,
g_param_spec_boolean ("strikethrough-set",
_("Strikethrough set"),
_("Whether strikethrough attribute is set"),
FALSE,
G_PARAM_READWRITE));
}
static void
gtk_source_style_init (G_GNUC_UNUSED GtkSourceStyle *style)
{
}
#define SET_MASK(style,name) (style)->mask |= (GTK_SOURCE_STYLE_USE_##name)
#define UNSET_MASK(style,name) (style)->mask &= (GTK_SOURCE_STYLE_USE_##name)
#define MODIFY_MASK(style,value,name) \
G_STMT_START { \
if (g_value_get_boolean (value)) \
SET_MASK (style, name); \
else \
UNSET_MASK (style, name); \
} G_STMT_END
#define GET_MASK(style,value,name) \
g_value_set_boolean (value, ((style)->mask & GTK_SOURCE_STYLE_USE_##name) != 0)
static void
gtk_source_style_set_property (GObject *object,
guint prop_id,
const GValue *value,
GParamSpec *pspec)
{
GtkSourceStyle *style = GTK_SOURCE_STYLE (object);
const gchar *string;
switch (prop_id)
{
case PROP_FOREGROUND:
string = g_value_get_string (value);
if (string != NULL)
style->foreground = g_intern_string (string);
else
style->foreground = NULL;
SET_MASK (style, FOREGROUND);
break;
case PROP_BACKGROUND:
string = g_value_get_string (value);
if (string != NULL)
style->background = g_intern_string (string);
else
style->background = NULL;
SET_MASK (style, BACKGROUND);
break;
case PROP_BOLD:
style->bold = g_value_get_boolean (value) != 0;
SET_MASK (style, BOLD);
break;
case PROP_ITALIC:
style->italic = g_value_get_boolean (value) != 0;
SET_MASK (style, ITALIC);
break;
case PROP_UNDERLINE:
style->underline = g_value_get_boolean (value) != 0;
SET_MASK (style, UNDERLINE);
break;
case PROP_STRIKETHROUGH:
style->strikethrough = g_value_get_boolean (value) != 0;
SET_MASK (style, STRIKETHROUGH);
break;
case PROP_FOREGROUND_SET:
MODIFY_MASK (style, value, FOREGROUND);
break;
case PROP_BACKGROUND_SET:
MODIFY_MASK (style, value, BACKGROUND);
break;
case PROP_BOLD_SET:
MODIFY_MASK (style, value, BOLD);
break;
case PROP_ITALIC_SET:
MODIFY_MASK (style, value, ITALIC);
break;
case PROP_UNDERLINE_SET:
MODIFY_MASK (style, value, UNDERLINE);
break;
case PROP_STRIKETHROUGH_SET:
MODIFY_MASK (style, value, STRIKETHROUGH);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
}
}
static void
gtk_source_style_get_property (GObject *object,
guint prop_id,
GValue *value,
GParamSpec *pspec)
{
GtkSourceStyle *style = GTK_SOURCE_STYLE (object);
switch (prop_id)
{
case PROP_FOREGROUND:
g_value_set_string (value, style->foreground);
break;
case PROP_BACKGROUND:
g_value_set_string (value, style->background);
break;
case PROP_BOLD:
g_value_set_boolean (value, style->bold);
break;
case PROP_ITALIC:
g_value_set_boolean (value, style->italic);
break;
case PROP_UNDERLINE:
g_value_set_boolean (value, style->underline);
break;
case PROP_STRIKETHROUGH:
g_value_set_boolean (value, style->strikethrough);
break;
case PROP_FOREGROUND_SET:
GET_MASK (style, value, FOREGROUND);
break;
case PROP_BACKGROUND_SET:
GET_MASK (style, value, BACKGROUND);
break;
case PROP_BOLD_SET:
GET_MASK (style, value, BOLD);
break;
case PROP_ITALIC_SET:
GET_MASK (style, value, ITALIC);
break;
case PROP_UNDERLINE_SET:
GET_MASK (style, value, UNDERLINE);
break;
case PROP_STRIKETHROUGH_SET:
GET_MASK (style, value, STRIKETHROUGH);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
}
}
/**
* gtk_source_style_new:
* @mask: a #GtkSourceStyleMask which defines what fields will be used.
*
* Creates new #GtkSourceStyle structure.
*
* <example id="gtk_source_style_new"><title>Using gtk_source_style_new</title>
* <programlisting><![CDATA[
* GtkSourceStyle *style;
* style = gtk_source_style_new (GTK_SOURCE_STYLE_USE_FOREGROUND | GTK_SOURCE_STYLE_USE_BOLD);
* style->bold = TRUE;
* gdk_color_parse ("green", &style->foreground);
* style = gtk_source_style_new ();
* g_object_set (style, "bold", TRUE, "foreground", "green", NULL);
* ...
* gtk_source_style_free (style);]]>
* g_object_unref (style);]]>
* </programlisting></example>
*
* Returns: newly allocated #GtkSourceStyle structure, free with
* gtk_source_style_free().
* Returns: newly allocated #GtkSourceStyle structure, call g_object_unref()
* when you are done with it.
*
* Since: 2.0
*/
GtkSourceStyle *
gtk_source_style_new (GtkSourceStyleMask mask)
gtk_source_style_new (void)
{
GtkSourceStyle *style = g_new0 (GtkSourceStyle, 1);
style->mask = mask;
return style;
return g_object_new (GTK_TYPE_SOURCE_STYLE, NULL);
}
/**
* gtk_source_style_copy:
* @style: a #GtkSourceStyle structure to copy.
*
* Returns: copy of @style, free it with gtk_source_style_free().
* Creates a copy of @style, that is a new #GtkSourceStyle instance which
* has the same attributes set.
*
* Returns: copy of @style, call g_object_unref() when you are done with it.
*
* Since: 2.0
*/
GtkSourceStyle *
gtk_source_style_copy (const GtkSourceStyle *style)
{
return g_memdup (style, sizeof (GtkSourceStyle));
}
GtkSourceStyle *copy;
/**
* gtk_source_style_free:
* @style: a #GtkSourceStyle structure to free.
*
* Frees #GtkSourceStyle structure allocated with gtk_source_style_new() or
* gtk_source_style_copy().
*
* Since: 2.0
*/
void
gtk_source_style_free (GtkSourceStyle *style)
{
g_free (style);
g_return_val_if_fail (style != NULL, NULL);
copy = g_object_new (GTK_TYPE_SOURCE_STYLE, NULL);
copy->foreground = style->foreground;
copy->background = style->background;
copy->italic = style->italic;
copy->bold = style->bold;
copy->underline = style->underline;
copy->strikethrough = style->strikethrough;
copy->mask = style->mask;
return copy;
}
/**
@ -113,9 +377,9 @@ _gtk_source_style_apply (const GtkSourceStyle *style,
g_object_freeze_notify (G_OBJECT (tag));
if (style->mask & GTK_SOURCE_STYLE_USE_BACKGROUND)
g_object_set (tag, "background-gdk", &style->background, NULL);
g_object_set (tag, "background", style->background, NULL);
if (style->mask & GTK_SOURCE_STYLE_USE_FOREGROUND)
g_object_set (tag, "foreground-gdk", &style->foreground, NULL);
g_object_set (tag, "foreground", style->foreground, NULL);
if (style->mask & GTK_SOURCE_STYLE_USE_ITALIC)
g_object_set (tag, "style", style->italic ? PANGO_STYLE_ITALIC : PANGO_STYLE_NORMAL, NULL);
if (style->mask & GTK_SOURCE_STYLE_USE_BOLD)

View File

@ -25,40 +25,17 @@
G_BEGIN_DECLS
#define GTK_TYPE_SOURCE_STYLE (gtk_source_style_get_type ())
#define GTK_SOURCE_STYLE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GTK_TYPE_SOURCE_STYLE, GtkSourceStyle))
#define GTK_IS_SOURCE_STYLE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GTK_TYPE_SOURCE_STYLE))
typedef struct _GtkSourceStyle GtkSourceStyle;
typedef enum {
GTK_SOURCE_STYLE_USE_BACKGROUND = 1 << 0, /*< nick=use_background >*/
GTK_SOURCE_STYLE_USE_FOREGROUND = 1 << 1, /*< nick=use_foreground >*/
GTK_SOURCE_STYLE_USE_ITALIC = 1 << 2, /*< nick=use_italic >*/
GTK_SOURCE_STYLE_USE_BOLD = 1 << 3, /*< nick=use_bold >*/
GTK_SOURCE_STYLE_USE_UNDERLINE = 1 << 4, /*< nick=use_underline >*/
GTK_SOURCE_STYLE_USE_STRIKETHROUGH = 1 << 5 /*< nick=use_strikethrough >*/
} GtkSourceStyleMask;
struct _GtkSourceStyle
{
GtkSourceStyleMask mask;
GdkColor foreground;
GdkColor background;
guint italic : 1;
guint bold : 1;
guint underline : 1;
guint strikethrough : 1;
};
#define GTK_TYPE_SOURCE_STYLE (gtk_source_style_get_type ())
GType gtk_source_style_get_type (void) G_GNUC_CONST;
GtkSourceStyle *gtk_source_style_new (GtkSourceStyleMask mask);
GtkSourceStyle *gtk_source_style_new (void);
GtkSourceStyle *gtk_source_style_copy (const GtkSourceStyle *style);
void gtk_source_style_free (GtkSourceStyle *style);
void _gtk_source_style_apply (const GtkSourceStyle *style,
GtkTextTag *tag);
G_END_DECLS

View File

@ -22,12 +22,10 @@
#include "gtksourcestylemanager.h"
#include "gtksourceview.h"
#include "gtksourcelanguage-private.h"
#include "gtksourcestyle-private.h"
#include <libxml/parser.h>
#include <string.h>
#define STYLE_HAS_FOREGROUND(s) ((s) && ((s)->mask & GTK_SOURCE_STYLE_USE_FOREGROUND))
#define STYLE_HAS_BACKGROUND(s) ((s) && ((s)->mask & GTK_SOURCE_STYLE_USE_BACKGROUND))
#define STYLE_TEXT "text"
#define STYLE_SELECTED "text-selected"
#define STYLE_BRACKET_MATCH "bracket-match"
@ -177,7 +175,7 @@ gtk_source_style_scheme_init (GtkSourceStyleScheme *scheme)
scheme->priv = G_TYPE_INSTANCE_GET_PRIVATE (scheme, GTK_TYPE_SOURCE_STYLE_SCHEME,
GtkSourceStyleSchemePrivate);
scheme->priv->styles = g_hash_table_new_full (g_str_hash, g_str_equal, g_free,
(GDestroyNotify) gtk_source_style_free);
(GDestroyNotify) g_object_unref);
}
/**
@ -242,8 +240,8 @@ _gtk_source_style_scheme_new (const gchar *id,
* @style_name: style name to find.
*
* Returns: style which corresponds to @style_name in the @scheme,
* or %NULL when no style with this name found. Free it with
* gtk_source_style_free().
* or %NULL when no style with this name found. Call g_object_unref()
* when you are done with it.
*
* Since: 2.0
*/
@ -296,7 +294,7 @@ gtk_source_style_scheme_set_style (GtkSourceStyleScheme *scheme,
* @scheme: a #GtkSourceStyleScheme.
*
* Returns: style which corresponds to "bracket-match" name, to use
* in an editor. Free it with gtk_source_style_free().
* in an editor. Call g_object_unref() when you are done with it.
*
* Since: 2.0
*/
@ -307,6 +305,43 @@ gtk_source_style_scheme_get_matching_brackets_style (GtkSourceStyleScheme *schem
return gtk_source_style_scheme_get_style (scheme, STYLE_BRACKET_MATCH);
}
static gboolean
get_color (GtkSourceStyle *style,
gboolean foreground,
GdkColor *dest)
{
const gchar *color;
guint mask;
if (style == NULL)
return FALSE;
if (foreground)
{
color = style->foreground;
mask = GTK_SOURCE_STYLE_USE_FOREGROUND;
}
else
{
color = style->background;
mask = GTK_SOURCE_STYLE_USE_BACKGROUND;
}
if (style->mask & mask)
{
if (color == NULL || !gdk_color_parse (color, dest))
{
g_warning ("%s: invalid color '%s'", G_STRLOC,
color != NULL ? color : "(null)");
return FALSE;
}
return TRUE;
}
return FALSE;
}
/**
* gtk_source_style_scheme_get_current_line_color:
* @scheme: a #GtkSourceStyleScheme.
@ -329,13 +364,11 @@ gtk_source_style_scheme_get_current_line_color (GtkSourceStyleScheme *scheme,
style = gtk_source_style_scheme_get_style (scheme, STYLE_CURRENT_LINE);
if (STYLE_HAS_FOREGROUND (style))
{
*color = style->foreground;
ret = TRUE;
}
ret = get_color (style, FALSE, color);
if (style != NULL)
g_object_unref (style);
gtk_source_style_free (style);
return ret;
}
@ -344,21 +377,22 @@ set_text_style (GtkWidget *widget,
GtkSourceStyle *style,
GtkStateType state)
{
GdkColor *color;
GdkColor color;
GdkColor *color_ptr;
if (style != NULL && STYLE_HAS_BACKGROUND (style))
color = &style->background;
if (get_color (style, FALSE, &color))
color_ptr = &color;
else
color = NULL;
color_ptr = NULL;
gtk_widget_modify_base (widget, state, color);
gtk_widget_modify_base (widget, state, color_ptr);
if (style != NULL && STYLE_HAS_FOREGROUND (style))
color = &style->foreground;
if (get_color (style, TRUE, &color))
color_ptr = &color;
else
color = NULL;
color_ptr = NULL;
gtk_widget_modify_text (widget, state, color);
gtk_widget_modify_text (widget, state, color_ptr);
}
static void
@ -366,18 +400,20 @@ set_line_numbers_style (GtkWidget *widget,
GtkSourceStyle *style)
{
gint i;
GdkColor *fg = NULL;
GdkColor *bg = NULL;
GdkColor *fg_ptr = NULL;
GdkColor *bg_ptr = NULL;
GdkColor fg;
GdkColor bg;
if (style != NULL && STYLE_HAS_FOREGROUND (style))
fg = &style->foreground;
if (style != NULL && STYLE_HAS_BACKGROUND (style))
bg = &style->background;
if (get_color (style, TRUE, &fg))
fg_ptr = &fg;
if (get_color (style, FALSE, &bg))
bg_ptr = &bg;
for (i = 0; i < 5; ++i)
{
gtk_widget_modify_fg (widget, i, fg);
gtk_widget_modify_bg (widget, i, bg);
gtk_widget_modify_fg (widget, i, fg_ptr);
gtk_widget_modify_bg (widget, i, bg_ptr);
}
}
@ -435,22 +471,22 @@ update_cursor_colors (GtkWidget *widget,
GtkSourceStyle *style_primary,
GtkSourceStyle *style_secondary)
{
GdkColor color;
GdkColor primary_color, secondary_color;
GdkColor *primary = NULL, *secondary = NULL;
if (style_primary != NULL && STYLE_HAS_FOREGROUND (style_primary))
primary = &style_primary->foreground;
if (get_color (style_primary, TRUE, &primary_color))
primary = &primary_color;
if (style_secondary != NULL && STYLE_HAS_FOREGROUND (style_secondary))
secondary = &style_secondary->foreground;
if (get_color (style_secondary, TRUE, &secondary_color))
secondary = &secondary_color;
if (primary != NULL && secondary == NULL)
{
GdkColor tmp = widget->style->base[GTK_STATE_NORMAL];
color.red = ((gint) tmp.red + primary->red) / 2;
color.green = ((gint) tmp.green + primary->green) / 2;
color.blue = ((gint) tmp.blue + primary->blue) / 2;
secondary = &color;
secondary_color = widget->style->base[GTK_STATE_NORMAL];
secondary_color.red = ((gint) secondary_color.red + primary->red) / 2;
secondary_color.green = ((gint) secondary_color.green + primary->green) / 2;
secondary_color.blue = ((gint) secondary_color.blue + primary->blue) / 2;
secondary = &secondary_color;
}
if (primary != NULL)
@ -486,21 +522,26 @@ _gtk_source_style_scheme_apply (GtkSourceStyleScheme *scheme,
set_text_style (widget, style, GTK_STATE_ACTIVE);
set_text_style (widget, style, GTK_STATE_PRELIGHT);
set_text_style (widget, style, GTK_STATE_INSENSITIVE);
gtk_source_style_free (style);
if (style != NULL)
g_object_unref (style);
style = gtk_source_style_scheme_get_style (scheme, STYLE_SELECTED);
set_text_style (widget, style, GTK_STATE_SELECTED);
gtk_source_style_free (style);
if (style != NULL)
g_object_unref (style);
style = gtk_source_style_scheme_get_style (scheme, STYLE_LINE_NUMBERS);
set_line_numbers_style (widget, style);
gtk_source_style_free (style);
if (style != NULL)
g_object_unref (style);
style = gtk_source_style_scheme_get_style (scheme, STYLE_CURSOR);
style2 = gtk_source_style_scheme_get_style (scheme, STYLE_SECONDARY_CURSOR);
update_cursor_colors (widget, style, style2);
gtk_source_style_free (style2);
gtk_source_style_free (style);
if (style2 != NULL)
g_object_unref (style2);
if (style != NULL)
g_object_unref (style);
}
else
{
@ -524,11 +565,11 @@ typedef struct {
#define ERROR_QUARK (g_quark_from_static_string ("gtk-source-style-scheme-parser-error"))
static void
get_bool (xmlNode *node,
const char *propname,
GtkSourceStyleMask *mask,
GtkSourceStyleMask mask_value,
gboolean *value)
get_bool (xmlNode *node,
const char *propname,
guint *mask,
guint mask_value,
gboolean *value)
{
xmlChar *tmp = xmlGetProp (node, BAD_CAST propname);
@ -554,7 +595,7 @@ parse_style (GtkSourceStyleScheme *scheme,
GtkSourceStyle *result = NULL;
xmlChar *fg = NULL, *bg = NULL;
gchar *style_name = NULL;
GtkSourceStyleMask mask = 0;
guint mask = 0;
gboolean bold = FALSE;
gboolean italic = FALSE;
gboolean underline = FALSE;
@ -579,7 +620,7 @@ parse_style (GtkSourceStyleScheme *scheme,
"in style '%s': duplicated use-style attribute",
style_name);
g_free (style_name);
gtk_source_style_free (use_style);
g_object_unref (use_style);
return FALSE;
}
@ -610,7 +651,7 @@ parse_style (GtkSourceStyleScheme *scheme,
g_set_error (error, ERROR_QUARK, 0,
"in style '%s': style attributes used along with use-style",
style_name);
gtk_source_style_free (use_style);
g_object_unref (use_style);
g_free (style_name);
xmlFree (fg);
xmlFree (bg);
@ -622,8 +663,9 @@ parse_style (GtkSourceStyleScheme *scheme,
}
else
{
result = gtk_source_style_new (mask);
result = gtk_source_style_new ();
result->mask = mask;
result->bold = bold;
result->italic = italic;
result->underline = underline;
@ -631,20 +673,14 @@ parse_style (GtkSourceStyleScheme *scheme,
if (fg != NULL)
{
if (gdk_color_parse ((char*) fg, &result->foreground))
result->mask |= GTK_SOURCE_STYLE_USE_FOREGROUND;
else
g_warning ("in style '%s': invalid color '%s'",
style_name, fg);
result->foreground = g_intern_string ((char*) fg);
result->mask |= GTK_SOURCE_STYLE_USE_FOREGROUND;
}
if (bg != NULL)
{
if (gdk_color_parse ((char*) bg, &result->background))
result->mask |= GTK_SOURCE_STYLE_USE_BACKGROUND;
else
g_warning ("in style '%s': invalid color '%s'",
style_name, bg);
result->background = g_intern_string ((char*) bg);
result->mask |= GTK_SOURCE_STYLE_USE_BACKGROUND;
}
}

View File

@ -60,7 +60,7 @@ GtkSourceStyleScheme *_gtk_source_style_scheme_new (const gchar *id,
const gchar *gtk_source_style_scheme_get_id (GtkSourceStyleScheme *scheme);
const gchar *gtk_source_style_scheme_get_name (GtkSourceStyleScheme *scheme);
/* Return value must be freed with gtk_source_style_free */
/* Return value must be freed with g_object_unref */
GtkSourceStyle *gtk_source_style_scheme_get_style (GtkSourceStyleScheme *scheme,
const gchar *style_name);
GtkSourceStyle *gtk_source_style_scheme_get_matching_brackets_style

View File

@ -31,6 +31,7 @@ sed -e 's/#include \"gtksourcecontextengine.h\"/#include \"gtksourcecontextengin
-e 's/#include \"gtksourcestyle.h\"/#include \"gtksourcestyle-mangled.h\"/' \
-e 's/#include \"gtksourcestylemanager.h\"/#include \"gtksourcestylemanager-mangled.h\"/' \
-e 's/#include \"gtksourcestylescheme.h\"/#include \"gtksourcestylescheme-mangled.h\"/' \
-e 's/#include \"gtksourcestyle-private.h\"/#include \"gtksourcestyle-private-mangled.h\"/' \
-e 's/#include \"gtktextregion.h\"/#include \"gtktextregion-mangled.h\"/' \
-e 's/#include \"gtksourceview-utils.h\"/#include \"gtksourceview-utils-mangled.h\"/' \
\

View File

@ -23,7 +23,7 @@
<style-scheme id="kate" _name="Kate">
<author>GtkSourceView team</author>
<_description>Color scheme used in Kate text editor</_description>
<style name="current-line" foreground="#EEF6FF"/>
<style name="current-line" background="#EEF6FF"/>
<style name="bracket-match" background="#FFFF99" bold="true"/>
<style name="bracket-mismatch" background="#FF0000" bold="true"/>

View File

@ -200,7 +200,7 @@ moo_text_buffer_class_init (MooTextBufferClass *klass)
g_object_class_install_property (gobject_class,
PROP_BRACKET_MATCH_STYLE,
g_param_spec_boxed ("bracket-match-style",
g_param_spec_object ("bracket-match-style",
"bracket-match-style",
"bracket-match-style",
MOO_TYPE_TEXT_STYLE,
@ -208,7 +208,7 @@ moo_text_buffer_class_init (MooTextBufferClass *klass)
g_object_class_install_property (gobject_class,
PROP_BRACKET_MISMATCH_STYLE,
g_param_spec_boxed ("bracket-mismatch-style",
g_param_spec_object ("bracket-mismatch-style",
"bracket-mismatch-style",
"bracket-mismatch-style",
MOO_TYPE_TEXT_STYLE,
@ -856,11 +856,11 @@ moo_text_buffer_set_property (GObject *object,
break;
case PROP_BRACKET_MATCH_STYLE:
moo_text_buffer_set_bracket_match_style (buffer, g_value_get_boxed (value));
moo_text_buffer_set_bracket_match_style (buffer, g_value_get_object (value));
break;
case PROP_BRACKET_MISMATCH_STYLE:
moo_text_buffer_set_bracket_mismatch_style (buffer, g_value_get_boxed (value));
moo_text_buffer_set_bracket_mismatch_style (buffer, g_value_get_object (value));
break;
case PROP_LANG:
@ -1243,13 +1243,8 @@ static void
moo_text_buffer_set_bracket_match_style (MooTextBuffer *buffer,
const MooTextStyle *style)
{
static MooTextStyle empty;
g_return_if_fail (MOO_IS_TEXT_BUFFER (buffer));
if (!style)
style = &empty;
if (!buffer->priv->correct_match_tag)
buffer->priv->correct_match_tag =
gtk_text_buffer_create_tag (GTK_TEXT_BUFFER (buffer), NULL, NULL);
@ -1263,13 +1258,8 @@ static void
moo_text_buffer_set_bracket_mismatch_style (MooTextBuffer *buffer,
const MooTextStyle *style)
{
static MooTextStyle empty;
g_return_if_fail (MOO_IS_TEXT_BUFFER (buffer));
if (!style)
style = &empty;
if (!buffer->priv->incorrect_match_tag)
buffer->priv->incorrect_match_tag =
gtk_text_buffer_create_tag (GTK_TEXT_BUFFER (buffer), NULL, NULL);

View File

@ -21,38 +21,14 @@ G_BEGIN_DECLS
#define MOO_TYPE_TEXT_STYLE (moo_text_style_get_type ())
#define MOO_TEXT_STYLE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), MOO_TYPE_TEXT_STYLE, MooTextStyle))
#define MOO_IS_TEXT_STYLE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), MOO_TYPE_TEXT_STYLE))
typedef struct _MooTextStyle MooTextStyle;
/* must be the same as GtkSourceStyleMask */
typedef enum
{
MOO_TEXT_STYLE_USE_BACKGROUND = 1 << 0, /*< nick=use_background >*/
MOO_TEXT_STYLE_USE_FOREGROUND = 1 << 1, /*< nick=use_foreground >*/
MOO_TEXT_STYLE_USE_ITALIC = 1 << 2, /*< nick=use_italic >*/
MOO_TEXT_STYLE_USE_BOLD = 1 << 3, /*< nick=use_bold >*/
MOO_TEXT_STYLE_USE_UNDERLINE = 1 << 4, /*< nick=use_underline >*/
MOO_TEXT_STYLE_USE_STRIKETHROUGH = 1 << 5 /*< nick=use_strikethrough >*/
} MooTextStyleMask;
/* must be the same as GtkSourceStyle */
struct _MooTextStyle
{
MooTextStyleMask mask;
GdkColor foreground;
GdkColor background;
guint italic : 1;
guint bold : 1;
guint underline : 1;
guint strikethrough : 1;
};
GType moo_text_style_get_type (void) G_GNUC_CONST;
MooTextStyle *moo_text_style_new (MooTextStyleMask mask);
MooTextStyle *moo_text_style_new (void);
MooTextStyle *moo_text_style_copy (const MooTextStyle *style);
void moo_text_style_free (MooTextStyle *style);

View File

@ -53,9 +53,9 @@ moo_text_style_get_type (void)
}
MooTextStyle *
moo_text_style_new (MooTextStyleMask mask)
moo_text_style_new (void)
{
return (MooTextStyle*) gtk_source_style_new (mask);
return (MooTextStyle*) gtk_source_style_new ();
}
MooTextStyle *
@ -68,7 +68,7 @@ void
moo_text_style_free (MooTextStyle *style)
{
if (style)
gtk_source_style_free ((GtkSourceStyle*) style);
g_object_unref (style);
}
@ -117,87 +117,22 @@ _moo_text_style_scheme_lookup_style (MooTextStyleScheme *scheme,
}
static void
set_text_style (GtkWidget *widget,
GtkSourceStyle *style,
GtkStateType state)
{
GdkColor *color;
if (STYLE_HAS_BACKGROUND (style))
color = &style->background;
else
color = NULL;
gtk_widget_modify_base (widget, state, color);
if (STYLE_HAS_FOREGROUND (style))
color = &style->foreground;
else
color = NULL;
gtk_widget_modify_text (widget, state, color);
}
static void
set_line_numbers_style (GtkWidget *widget,
GtkSourceStyle *style)
{
gint i;
GdkColor *fg = NULL;
GdkColor *bg = NULL;
if (style != NULL && STYLE_HAS_FOREGROUND (style))
fg = &style->foreground;
if (style != NULL && STYLE_HAS_BACKGROUND (style))
bg = &style->background;
for (i = 0; i < 5; ++i)
{
gtk_widget_modify_fg (widget, i, fg);
gtk_widget_modify_bg (widget, i, bg);
}
}
void
_moo_text_style_scheme_apply (MooTextStyleScheme *scheme,
GtkWidget *widget)
{
GtkSourceStyle *style, *style2;
g_return_if_fail (MOO_IS_TEXT_STYLE_SCHEME (scheme));
g_return_if_fail (GTK_IS_WIDGET (widget));
gtk_widget_ensure_style (widget);
style = gtk_source_style_scheme_get_style (GTK_SOURCE_STYLE_SCHEME (scheme), STYLE_TEXT);
set_text_style (widget, style, GTK_STATE_NORMAL);
set_text_style (widget, style, GTK_STATE_ACTIVE);
set_text_style (widget, style, GTK_STATE_PRELIGHT);
set_text_style (widget, style, GTK_STATE_INSENSITIVE);
gtk_source_style_free (style);
style = gtk_source_style_scheme_get_style (GTK_SOURCE_STYLE_SCHEME (scheme), STYLE_SELECTED);
set_text_style (widget, style, GTK_STATE_SELECTED);
gtk_source_style_free (style);
style = gtk_source_style_scheme_get_style (GTK_SOURCE_STYLE_SCHEME (scheme), STYLE_LINE_NUMBERS);
set_line_numbers_style (widget, style);
gtk_source_style_free (style);
_gtk_source_style_scheme_apply (GTK_SOURCE_STYLE_SCHEME (scheme), widget);
if (MOO_IS_TEXT_VIEW (widget))
{
style = gtk_source_style_scheme_get_style (GTK_SOURCE_STYLE_SCHEME (scheme), STYLE_CURSOR);
style2 = gtk_source_style_scheme_get_style (GTK_SOURCE_STYLE_SCHEME (scheme), STYLE_SECONDARY_CURSOR);
moo_text_view_set_cursor_colors (MOO_TEXT_VIEW (widget),
style ? &style->foreground : NULL,
style2 ? &style2->foreground : NULL);
gtk_source_style_free (style2);
gtk_source_style_free (style);
style = gtk_source_style_scheme_get_style (GTK_SOURCE_STYLE_SCHEME (scheme), STYLE_CURRENT_LINE);
moo_text_view_set_current_line_color (MOO_TEXT_VIEW (widget), style ? &style->foreground : NULL);
gtk_source_style_free (style);
GdkColor color;
if (gtk_source_style_scheme_get_current_line_color (GTK_SOURCE_STYLE_SCHEME (scheme), &color))
moo_text_view_set_current_line_color (MOO_TEXT_VIEW (widget), &color);
else
moo_text_view_set_current_line_color (MOO_TEXT_VIEW (widget), NULL);
}
}

View File

@ -119,20 +119,11 @@
(gtype-id "MOO_TYPE_TEXT_STYLE_SCHEME")
)
(define-boxed TextStyle
(define-object TextStyle
(in-module "Moo")
(parent "GObject")
(c-name "MooTextStyle")
(gtype-id "MOO_TYPE_TEXT_STYLE")
(fields
'("MooTextStyleMask" "mask")
'("GdkColor" "foreground")
'("GdkColor" "background")
'("gboolean" "bold")
'("gboolean" "italic")
'("gboolean" "underline")
'("gboolean" "strikethrough")
)
)
@ -172,12 +163,6 @@
(gtype-id "MOO_TYPE_TEXT_REPLACE_RESPONSE")
)
(define-flags TextStyleMask
(in-module "Moo")
(c-name "MooTextStyleMask")
(gtype-id "MOO_TYPE_TEXT_STYLE_MASK")
)
(define-enum TextSelectionType
(in-module "Moo")
(c-name "MooTextSelectionType")
@ -971,9 +956,6 @@
(c-name "moo_text_style_new")
(is-constructor-of "MooTextStyle")
(return-type "MooTextStyle*")
(parameters
'("MooTextStyleMask" "mask" (null-ok) (default "0"))
)
)
(define-method moo_text_style_copy