X-Git-Url: https://git.stderr.nl/gitweb?a=blobdiff_plain;f=libchimara%2Fstyle.c;h=3826ebfc4d1fcf482de4fc8c8ee7cb81f97166f6;hb=d5610e149e0384a24d00727a5815df12e85de026;hp=3219d265c547401f49a78e02f2131afbf516820f;hpb=78d02a76a689c3efadc3139688261d010bb6a938;p=projects%2Fchimara%2Fchimara.git diff --git a/libchimara/style.c b/libchimara/style.c index 3219d26..3826ebf 100644 --- a/libchimara/style.c +++ b/libchimara/style.c @@ -1,25 +1,30 @@ #include "style.h" -extern ChimaraGlkPrivate *glk_data; +extern GPrivate *glk_data_key; /** * glk_set_style: - * @styl The style to apply + * @styl: The style to apply * - * This changes the style of the current output stream. After a style change, - * new text which is printed to that stream will be given the new style. For a - * window stream, the text will appear in that style. For other types of - * streams, this has no effect. + * Changes the style of the current output stream. @styl should be one of the + * style_ constants listed above. However, any value is actually + * legal; if the interpreter does not recognize the style value, it will treat + * it as %style_Normal. + * + * This policy allows for the future definition of styles without breaking old + * Glk libraries. + * */ void -glk_set_style(glui32 style) +glk_set_style(glui32 styl) { + ChimaraGlkPrivate *glk_data = g_private_get(glk_data_key); g_return_if_fail(glk_data->current_stream != NULL); - glk_set_style_stream(glk_data->current_stream, style); + glk_set_style_stream(glk_data->current_stream, styl); } /* Internal function: mapping from style enum to tag name */ -gchar* +static gchar * get_tag_name(glui32 style) { switch(style) { @@ -40,9 +45,16 @@ get_tag_name(glui32 style) return "normal"; } +/** + * glk_set_style_stream: + * @str: Output stream to change the style of + * @styl: The style to apply + * + * This changes the style of the stream @str. See glk_set_style(). + */ void -glk_set_style_stream(strid_t stream, glui32 style) { - stream->style = get_tag_name(style); +glk_set_style_stream(strid_t str, glui32 styl) { + str->style = get_tag_name(styl); } /* Internal function: call this to initialize the default styles to a textbuffer. */ @@ -51,11 +63,13 @@ style_init_textbuffer(GtkTextBuffer *buffer) { g_return_if_fail(buffer != NULL); + ChimaraGlkPrivate *glk_data = g_private_get(glk_data_key); + gtk_text_buffer_create_tag(buffer, "normal", NULL); gtk_text_buffer_create_tag(buffer, "emphasized", "style", PANGO_STYLE_ITALIC, NULL); gtk_text_buffer_create_tag(buffer, "preformatted", "font-desc", glk_data->monospace_font_desc, NULL); - gtk_text_buffer_create_tag(buffer, "header", "size-points", 16.0, "weight", PANGO_WEIGHT_BOLD, NULL); - gtk_text_buffer_create_tag(buffer, "subheader", "size-points", 12.0, "weight", PANGO_WEIGHT_BOLD, NULL); + gtk_text_buffer_create_tag(buffer, "header", "size-points", 18.0, "weight", PANGO_WEIGHT_BOLD, NULL); + gtk_text_buffer_create_tag(buffer, "subheader", "size-points", 14.0, "weight", PANGO_WEIGHT_BOLD, NULL); gtk_text_buffer_create_tag(buffer, "alert", "foreground", "#aa0000", "weight", PANGO_WEIGHT_BOLD, NULL); gtk_text_buffer_create_tag(buffer, "note", "foreground", "#aaaa00", "weight", PANGO_WEIGHT_BOLD, NULL); gtk_text_buffer_create_tag(buffer, "block-quote", "justification", GTK_JUSTIFY_CENTER, "style", PANGO_STYLE_ITALIC, NULL); @@ -64,7 +78,7 @@ style_init_textbuffer(GtkTextBuffer *buffer) gtk_text_buffer_create_tag(buffer, "user2", NULL); } -void +static void color_format(glui32 val, gchar *buffer) { sprintf(buffer, "#%02X%02X%02X", @@ -75,11 +89,12 @@ color_format(glui32 val, gchar *buffer) } /* Internal function: changes a GTK tag to correspond with the given style. */ -void +static void apply_stylehint_to_tag(GtkTextTag *tag, glui32 hint, glsi32 val) { g_return_if_fail(tag != NULL); + ChimaraGlkPrivate *glk_data = g_private_get(glk_data_key); GObject *tag_object = G_OBJECT(tag); gint reverse_color = 0; @@ -173,11 +188,25 @@ apply_stylehint_to_tag(GtkTextTag *tag, glui32 hint, glsi32 val) } } +/** + * glk_stylehint_set: + * @wintype: The window type to set a style hint on, or %wintype_AllTypes. + * @styl: The style to set a hint for. + * @hint: The type of style hint, one of the stylehint_ constants. + * @val: The style hint. The meaning of this depends on @hint. + * + * Sets a hint about the appearance of one style for a particular type of + * window. You can also set wintype to %wintype_AllTypes, which sets a hint for + * all types of window. + * + * There is no equivalent constant to set a hint for all styles of a single + * window type. + * + */ void -glk_stylehint_set(glui32 wintype, glui32 style, glui32 hint, glsi32 val) +glk_stylehint_set(glui32 wintype, glui32 styl, glui32 hint, glsi32 val) { - - gchar *tag_name = get_tag_name(style); + gchar *tag_name = get_tag_name(styl); /* Iterate over all the window and update their styles if nessecary */ winid_t win = glk_window_iterate(NULL, NULL); @@ -199,4 +228,10 @@ glk_stylehint_set(glui32 wintype, glui32 style, glui32 hint, glsi32 val) void glk_stylehint_clear(glui32 wintype, glui32 styl, glui32 hint) { -} \ No newline at end of file +} + +glui32 +glk_style_distinguish(winid_t win, glui32 styl1, glui32 styl2) +{ + return styl1 != styl2; +}