2005-10-17 05:23:40 +00:00
|
|
|
/*
|
|
|
|
* mootextstylescheme.c
|
|
|
|
*
|
2010-12-21 20:15:45 -08:00
|
|
|
* Copyright (C) 2004-2010 by Yevgen Muntyan <emuntyan@users.sourceforge.net>
|
2005-10-17 05:23:40 +00:00
|
|
|
*
|
2008-09-05 17:20:50 -05:00
|
|
|
* This file is part of medit. medit is free software; you can
|
|
|
|
* redistribute it and/or modify it under the terms of the
|
|
|
|
* GNU Lesser General Public License as published by the
|
|
|
|
* Free Software Foundation; either version 2.1 of the License,
|
|
|
|
* or (at your option) any later version.
|
2005-10-17 05:23:40 +00:00
|
|
|
*
|
2008-09-05 17:20:50 -05:00
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with medit. If not, see <http://www.gnu.org/licenses/>.
|
2005-10-17 05:23:40 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "mooedit/mootextstylescheme.h"
|
|
|
|
#include "mooedit/mootextview.h"
|
2006-08-26 04:46:29 -05:00
|
|
|
#include "mooutils/mooi18n.h"
|
2010-08-30 22:19:58 -07:00
|
|
|
#include "gtksourceview/gtksourceview-api.h"
|
2005-10-17 05:23:40 +00:00
|
|
|
|
2006-08-26 04:46:29 -05:00
|
|
|
#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))
|
2005-10-17 05:23:40 +00:00
|
|
|
|
2006-08-26 04:46:29 -05:00
|
|
|
#define STYLE_BRACKET_MATCH "bracket-match"
|
|
|
|
#define STYLE_BRACKET_MISMATCH "bracket-mismatch"
|
2007-07-17 11:19:25 -05:00
|
|
|
#define STYLE_CURRENT_LINE "current-line"
|
|
|
|
#define STYLE_RIGHT_MARGIN "right-margin"
|
2005-10-17 05:23:40 +00:00
|
|
|
|
2006-08-26 04:46:29 -05:00
|
|
|
GType
|
|
|
|
moo_text_style_scheme_get_type (void)
|
2005-10-17 05:23:40 +00:00
|
|
|
{
|
2006-08-26 04:46:29 -05:00
|
|
|
static GType type = 0;
|
2005-10-17 05:23:40 +00:00
|
|
|
|
2006-12-30 22:18:14 -06:00
|
|
|
if (G_UNLIKELY (!type))
|
2006-08-26 04:46:29 -05:00
|
|
|
type = GTK_TYPE_SOURCE_STYLE_SCHEME;
|
2005-10-17 05:23:40 +00:00
|
|
|
|
2006-08-26 04:46:29 -05:00
|
|
|
return type;
|
2005-10-17 05:23:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-08-26 04:46:29 -05:00
|
|
|
GType
|
|
|
|
moo_text_style_get_type (void)
|
2005-10-17 05:23:40 +00:00
|
|
|
{
|
2006-08-26 04:46:29 -05:00
|
|
|
static GType type = 0;
|
2005-10-17 05:23:40 +00:00
|
|
|
|
2006-12-30 22:18:14 -06:00
|
|
|
if (G_UNLIKELY (!type))
|
2006-08-26 04:46:29 -05:00
|
|
|
type = GTK_TYPE_SOURCE_STYLE;
|
2005-10-17 05:23:40 +00:00
|
|
|
|
2006-08-26 04:46:29 -05:00
|
|
|
return type;
|
2005-10-17 05:23:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-08-26 04:46:29 -05:00
|
|
|
const char *
|
|
|
|
moo_text_style_scheme_get_id (MooTextStyleScheme *scheme)
|
|
|
|
{
|
|
|
|
g_return_val_if_fail (MOO_IS_TEXT_STYLE_SCHEME (scheme), NULL);
|
|
|
|
return gtk_source_style_scheme_get_id (GTK_SOURCE_STYLE_SCHEME (scheme));
|
2005-10-17 05:23:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-08-26 04:46:29 -05:00
|
|
|
const char *
|
|
|
|
moo_text_style_scheme_get_name (MooTextStyleScheme *scheme)
|
2005-10-17 05:23:40 +00:00
|
|
|
{
|
2006-08-26 04:46:29 -05:00
|
|
|
g_return_val_if_fail (MOO_IS_TEXT_STYLE_SCHEME (scheme), NULL);
|
|
|
|
return gtk_source_style_scheme_get_name (GTK_SOURCE_STYLE_SCHEME (scheme));
|
2005-10-17 05:23:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-08-26 04:46:29 -05:00
|
|
|
MooTextStyle *
|
2007-02-27 22:32:54 -06:00
|
|
|
_moo_text_style_scheme_get_bracket_match_style (MooTextStyleScheme *scheme)
|
2005-10-17 05:23:40 +00:00
|
|
|
{
|
2006-08-26 04:46:29 -05:00
|
|
|
g_return_val_if_fail (MOO_IS_TEXT_STYLE_SCHEME (scheme), NULL);
|
|
|
|
return (MooTextStyle*) gtk_source_style_scheme_get_style (GTK_SOURCE_STYLE_SCHEME (scheme),
|
|
|
|
STYLE_BRACKET_MATCH);
|
2005-10-17 05:23:40 +00:00
|
|
|
}
|
|
|
|
|
2006-08-26 04:46:29 -05:00
|
|
|
|
|
|
|
MooTextStyle *
|
2007-02-27 22:32:54 -06:00
|
|
|
_moo_text_style_scheme_get_bracket_mismatch_style (MooTextStyleScheme *scheme)
|
2005-10-17 05:23:40 +00:00
|
|
|
{
|
2006-08-26 04:46:29 -05:00
|
|
|
g_return_val_if_fail (MOO_IS_TEXT_STYLE_SCHEME (scheme), NULL);
|
|
|
|
return (MooTextStyle*) gtk_source_style_scheme_get_style (GTK_SOURCE_STYLE_SCHEME (scheme),
|
|
|
|
STYLE_BRACKET_MISMATCH);
|
|
|
|
}
|
2005-10-17 05:23:40 +00:00
|
|
|
|
|
|
|
|
2007-02-27 22:32:54 -06:00
|
|
|
MooTextStyle *
|
|
|
|
_moo_text_style_scheme_lookup_style (MooTextStyleScheme *scheme,
|
|
|
|
const char *name)
|
|
|
|
{
|
|
|
|
g_return_val_if_fail (MOO_IS_TEXT_STYLE_SCHEME (scheme), NULL);
|
|
|
|
g_return_val_if_fail (name != NULL, NULL);
|
|
|
|
return (MooTextStyle*) gtk_source_style_scheme_get_style (GTK_SOURCE_STYLE_SCHEME (scheme),
|
|
|
|
name);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-07-15 04:51:58 -05:00
|
|
|
static const char *
|
|
|
|
get_color (GtkSourceStyleScheme *scheme,
|
|
|
|
const char *name)
|
|
|
|
{
|
|
|
|
GtkSourceStyle *style;
|
|
|
|
|
|
|
|
style = gtk_source_style_scheme_get_style (scheme, name);
|
|
|
|
|
|
|
|
if (style && (style->mask & GTK_SOURCE_STYLE_USE_BACKGROUND))
|
|
|
|
return style->background;
|
|
|
|
else
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2007-11-27 22:22:57 -06:00
|
|
|
const char *
|
|
|
|
_moo_text_style_get_bg_color (const MooTextStyle *style)
|
|
|
|
{
|
|
|
|
g_return_val_if_fail (style != NULL, NULL);
|
|
|
|
|
|
|
|
if (((GtkSourceStyle*)style)->mask & GTK_SOURCE_STYLE_USE_BACKGROUND)
|
|
|
|
return ((GtkSourceStyle*)style)->background;
|
|
|
|
else
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2005-10-17 05:23:40 +00:00
|
|
|
void
|
2006-08-26 04:46:29 -05:00
|
|
|
_moo_text_style_scheme_apply (MooTextStyleScheme *scheme,
|
|
|
|
GtkWidget *widget)
|
2005-10-17 05:23:40 +00:00
|
|
|
{
|
2007-07-15 04:51:58 -05:00
|
|
|
g_return_if_fail (MOO_IS_TEXT_STYLE_SCHEME (scheme));
|
|
|
|
g_return_if_fail (GTK_IS_WIDGET (widget));
|
|
|
|
|
|
|
|
_gtk_source_style_scheme_apply (GTK_SOURCE_STYLE_SCHEME (scheme), widget);
|
|
|
|
|
|
|
|
if (MOO_IS_TEXT_VIEW (widget))
|
|
|
|
{
|
|
|
|
const char *color;
|
|
|
|
|
2007-07-17 11:19:25 -05:00
|
|
|
color = get_color (GTK_SOURCE_STYLE_SCHEME (scheme), STYLE_CURRENT_LINE);
|
2007-07-15 04:51:58 -05:00
|
|
|
moo_text_view_set_current_line_color (MOO_TEXT_VIEW (widget), color);
|
|
|
|
|
2007-07-17 11:19:25 -05:00
|
|
|
color = get_color (GTK_SOURCE_STYLE_SCHEME (scheme), STYLE_RIGHT_MARGIN);
|
2007-07-15 04:51:58 -05:00
|
|
|
moo_text_view_set_right_margin_color (MOO_TEXT_VIEW (widget), color);
|
|
|
|
}
|
2005-10-17 05:23:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
2006-08-26 04:46:29 -05:00
|
|
|
_moo_text_style_apply_to_tag (const MooTextStyle *style,
|
|
|
|
GtkTextTag *tag)
|
2005-10-17 05:23:40 +00:00
|
|
|
{
|
2006-11-02 00:39:54 -06:00
|
|
|
_gtk_source_style_apply (NULL, tag);
|
2006-08-26 04:46:29 -05:00
|
|
|
_gtk_source_style_apply ((GtkSourceStyle*) style, tag);
|
2005-10-17 05:23:40 +00:00
|
|
|
}
|