medit/moo/mooedit/mootextstylescheme.c

160 lines
4.5 KiB
C
Raw Normal View History

/*
* mootextstylescheme.c
*
* Copyright (C) 2004-2006 by Yevgen Muntyan <muntyan@math.tamu.edu>
*
* 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.
*
* See COPYING file that comes with this distribution.
*/
#define MOOEDIT_COMPILATION
#include "mooedit/mootextstylescheme.h"
#include "mooedit/mootextview.h"
2006-08-26 02:46:29 -07:00
#include "mooutils/mooi18n.h"
#include "mooedit/gtksourceview/gtksourceview-api.h"
2006-08-26 02:46:29 -07: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))
2006-08-26 02:46:29 -07:00
#define STYLE_TEXT "text"
#define STYLE_SELECTED "text-selected"
#define STYLE_BRACKET_MATCH "bracket-match"
#define STYLE_BRACKET_MISMATCH "bracket-mismatch"
#define STYLE_CURSOR "cursor"
#define STYLE_CURRENT_LINE "current-line"
2006-08-26 02:46:29 -07:00
GType
moo_text_style_scheme_get_type (void)
{
2006-08-26 02:46:29 -07:00
static GType type = 0;
2006-12-30 20:18:14 -08:00
if (G_UNLIKELY (!type))
2006-08-26 02:46:29 -07:00
type = GTK_TYPE_SOURCE_STYLE_SCHEME;
2006-08-26 02:46:29 -07:00
return type;
}
2006-08-26 02:46:29 -07:00
GType
moo_text_style_get_type (void)
{
2006-08-26 02:46:29 -07:00
static GType type = 0;
2006-12-30 20:18:14 -08:00
if (G_UNLIKELY (!type))
2006-08-26 02:46:29 -07:00
type = GTK_TYPE_SOURCE_STYLE;
2006-08-26 02:46:29 -07:00
return type;
}
2006-08-26 02:46:29 -07:00
void
moo_text_style_free (MooTextStyle *style)
{
2006-08-26 02:46:29 -07:00
if (style)
gtk_source_style_free ((GtkSourceStyle*) style);
}
2006-08-26 02:46:29 -07: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));
}
2006-08-26 02:46:29 -07:00
const char *
moo_text_style_scheme_get_name (MooTextStyleScheme *scheme)
{
2006-08-26 02:46:29 -07: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));
}
2006-08-26 02:46:29 -07:00
MooTextStyle *
moo_text_style_scheme_get_bracket_match_style (MooTextStyleScheme *scheme)
{
2006-08-26 02:46:29 -07: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);
}
2006-08-26 02:46:29 -07:00
MooTextStyle *
moo_text_style_scheme_get_bracket_mismatch_style (MooTextStyleScheme *scheme)
{
2006-08-26 02:46:29 -07: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);
}
2006-08-26 02:46:29 -07:00
static void
set_text_style (GtkWidget *widget,
GtkSourceStyle *style,
GtkStateType state)
{
GdkColor *color;
2006-08-26 02:46:29 -07:00
if (STYLE_HAS_BACKGROUND (style))
color = &style->background;
else
color = NULL;
2006-08-26 02:46:29 -07:00
gtk_widget_modify_base (widget, state, color);
2006-08-26 02:46:29 -07:00
if (STYLE_HAS_FOREGROUND (style))
color = &style->foreground;
else
color = NULL;
2006-08-26 02:46:29 -07:00
gtk_widget_modify_text (widget, state, color);
}
void
2006-08-26 02:46:29 -07:00
_moo_text_style_scheme_apply (MooTextStyleScheme *scheme,
GtkWidget *widget)
{
2006-08-26 02:46:29 -07:00
GtkSourceStyle *style;
2006-08-26 02:46:29 -07:00
g_return_if_fail (MOO_IS_TEXT_STYLE_SCHEME (scheme));
g_return_if_fail (GTK_IS_WIDGET (widget));
2006-08-26 02:46:29 -07:00
gtk_widget_ensure_style (widget);
2006-08-26 02:46:29 -07:00
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);
2006-08-26 02:46:29 -07:00
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);
2006-08-26 02:46:29 -07:00
if (MOO_IS_TEXT_VIEW (widget))
{
2006-08-26 02:46:29 -07:00
style = gtk_source_style_scheme_get_style (GTK_SOURCE_STYLE_SCHEME (scheme), STYLE_CURSOR);
moo_text_view_set_cursor_color (MOO_TEXT_VIEW (widget), style ? &style->foreground : NULL);
gtk_source_style_free (style);
2006-09-01 01:47:55 -07:00
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);
}
}
void
2006-08-26 02:46:29 -07:00
_moo_text_style_apply_to_tag (const MooTextStyle *style,
GtkTextTag *tag)
{
_gtk_source_style_apply (NULL, tag);
2006-08-26 02:46:29 -07:00
_gtk_source_style_apply ((GtkSourceStyle*) style, tag);
}