#include "glkunix.h"
#include "init.h"
#include "magic.h"
+#include "style.h"
#define CHIMARA_GLK_MIN_WIDTH 0
#define CHIMARA_GLK_MIN_HEIGHT 0
g_async_queue_push(priv->line_input_queue, g_strdup(text));
event_throw(glk, evtype_ForcedLineInput, NULL, 0, 0);
}
+
+/**
+ * chimara_glk_get_tag:
+ * @glk: a #ChimarGlk widget
+ * @window: The type of window to retrieve the tag for
+ * @name: The name of the tag to retrieve
+ *
+ * Use this function to get a #GtkTextTag so style properties can be changed.
+ * See also #chimara_glk_set_css_from_string.
+ *
+ * The layout of the text in Chimara is controlled by two sets of tags: one set
+ * describing the style in text buffers and one for text grids. See also the
+ * GLK specification for the difference between the two. The main narrative of
+ * a game is usually rendered in text buffers, whereas text grids are mostly
+ * used for status bars and in game menus.
+ *
+ * The following tag names are supported:
+ * <itemizedlist>
+ * <listitem><para>normal</para></listitem>
+ * <listitem><para>emphasized</para></listitem>
+ * <listitem><para>preformatted</para></listitem>
+ * <listitem><para>header</para></listitem>
+ * <listitem><para>subheader</para></listitem>
+ * <listitem><para>alert</para></listitem>
+ * <listitem><para>note</para></listitem>
+ * <listitem><para>block-quote</para></listitem>
+ * <listitem><para>input</para></listitem>
+ * <listitem><para>user1</para></listitem>
+ * <listitem><para>user2</para></listitem>
+ * <listitem><para>hyperlink</para></listitem>
+ * <listitem><para>pager</para></listitem>
+ * </itenizedlist>
+ */
+GtkTextTag*
+chimara_glk_get_tag(ChimaraGlk *glk, ChimaraGlkWindowType window, const gchar *name)
+{
+ CHIMARA_GLK_USE_PRIVATE(glk, priv);
+
+ switch(window) {
+ case CHIMARA_GLK_TEXT_BUFFER:
+ return GTK_TEXT_TAG( g_hash_table_lookup(priv->styles->text_buffer, name) );
+ break;
+ case CHIMARA_GLK_TEXT_GRID:
+ return GTK_TEXT_TAG( g_hash_table_lookup(priv->styles->text_grid, name) );
+ break;
+ default:
+ ILLEGAL_PARAM("Unknown window type: %u", window);
+ return NULL;
+ }
+}
+
+/**
+ * chimara_glk_get_tag:
+ * @glk: a #ChimarGlk widget
+ *
+ * Retrieves the possible tag names to use in #chimara_glk_get_tag.
+ */
+const gchar**
+chimara_glk_get_tag_names(ChimaraGlk *glk)
+{
+ return style_get_tag_names();
+}
+
+/**
+ * chimara_glk_get_num_tag_names:
+ * @glk: a #ChimaraGlk widget
+ *
+ * Retrieves the number of style tags returned by #chimara_glk_get_tag_names.
+ */
+gint
+chimara_glk_get_num_tag_names(ChimaraGlk *glk)
+{
+ return CHIMARA_NUM_STYLES;
+}
+
+/**
+ * chimara_glk_update_style:
+ * @glk: a #ChimaraGlk widget
+ *
+ * Processes style updates and updates the widget to reflect the new style.
+ * Call this every time you change a property of a #GtkTextTag retrieved by
+ * #chimara_glk_get_tag.
+ */
+void
+chimara_glk_update_style(ChimaraGlk *glk)
+{
+ CHIMARA_GLK_USE_PRIVATE(glk, priv);
+ style_update(glk);
+
+ /* Schedule a redraw */
+ g_mutex_lock(priv->arrange_lock);
+ priv->needs_rearrange = TRUE;
+ priv->ignore_next_arrange_event = TRUE;
+ g_mutex_unlock(priv->arrange_lock);
+ gtk_widget_queue_resize( GTK_WIDGET(priv->self) );
+}
void(* iliad_screen_update) (ChimaraGlk *self, gboolean typing);
} ChimaraGlkClass;
+typedef enum {
+ CHIMARA_GLK_TEXT_BUFFER,
+ CHIMARA_GLK_TEXT_GRID
+} ChimaraGlkWindowType;
+
/**
* ChimaraError:
* @CHIMARA_LOAD_MODULE_ERROR: There was an error opening the plugin containing
gboolean chimara_glk_get_running(ChimaraGlk *glk);
void chimara_glk_feed_char_input(ChimaraGlk *glk, guint32 keyval);
void chimara_glk_feed_line_input(ChimaraGlk *glk, const gchar *text);
+GtkTextTag *chimara_glk_get_tag(ChimaraGlk *glk, ChimaraGlkWindowType window, const gchar *name);
+const gchar **chimara_glk_get_tag_names(ChimaraGlk *glk);
+gint chimara_glk_get_num_tag_names(ChimaraGlk *glk);
+void chimara_glk_update_style(ChimaraGlk *glk);
G_END_DECLS
glk_set_style_stream(glk_data->current_stream, styl);
}
-#define NUM_STYLES 13
static const gchar* TAG_NAMES[] = {
"normal",
"emphasized",
"glk-user2"
};
+const gchar**
+style_get_tag_names()
+{
+ return TAG_NAMES;
+}
+
/* Internal function: mapping from style enum to tag name */
-static gchar*
+static const gchar*
get_tag_name(glui32 style)
{
- if(style >= NUM_STYLES) {
+ if(style >= CHIMARA_NUM_STYLES) {
WARNING("Unsupported style");
return "normal";
} else {
}
/* Internal function: mapping from glk style enum to tag name */
-static gchar*
+static const gchar*
get_glk_tag_name(glui32 style)
{
if(style >= style_NUMSTYLES) {
return;
flush_window_buffer(str->window);
- str->style = get_tag_name(styl);
- str->glk_style = get_glk_tag_name(styl);
+ str->style = (gchar*) get_tag_name(styl);
+ str->glk_style = (gchar*) get_glk_tag_name(styl);
}
/* Internal function: call this to initialize the layout of the 'more' prompt. */
);
}
}
+
+/* Update pager and reverse video tags */
+void
+style_update(ChimaraGlk *glk)
+{
+ CHIMARA_GLK_USE_PRIVATE(glk, priv);
+
+ GtkTextTag *pager_tag = GTK_TEXT_TAG( g_hash_table_lookup(priv->styles->text_buffer, "pager") );
+ text_tag_to_attr_list(pager_tag, priv->pager_attr_list);
+}
G_GNUC_INTERNAL void style_init_textgrid(GtkTextBuffer *buffer);
G_GNUC_INTERNAL void style_init_more_prompt(winid_t win);
G_GNUC_INTERNAL void style_init(ChimaraGlk *glk);
+G_GNUC_INTERNAL void style_update(ChimaraGlk *glk);
+G_GNUC_INTERNAL const gchar** style_get_tag_names();
G_GNUC_INTERNAL void reset_default_styles(ChimaraGlk *glk);
/*G_GNUC_INTERNAL void copy_default_styles_to_current_styles(ChimaraGlk *glk);*/
G_GNUC_INTERNAL GScanner *create_css_file_scanner(void);
GHashTable *text_buffer;
} StyleSet;
+#define CHIMARA_NUM_STYLES 13
+
#endif
if TARGET_ILIAD
-chimara_iliad_SOURCES = iliad.c
+chimara_iliad_SOURCES = iliad.c xepdmgrclient.c xepdmgrclient.h
chimara_iliad_CFLAGS = @TEST_CFLAGS@ $(AM_CFLAGS)
chimara_iliad_LDADD = @TEST_LIBS@ $(top_builddir)/libchimara/libchimara.la
dist_pkgdata_DATA = chimara.ui chimara.menus style.css
bin_PROGRAMS = chimara
-chimara_SOURCES = main.c callbacks.c error.c error.h
+chimara_SOURCES = main.c callbacks.c preferences.c preferences.h error.c error.h
chimara_CPPFLAGS = $(AM_CPPFLAGS) \
-DPACKAGE_LOCALE_DIR=\""$(prefix)/$(DATADIRNAME)/locale"\" \
-DPACKAGE_SRC_DIR=\""$(srcdir)"\" \
<?xml version="1.0"?>
<interface>
- <!-- interface-requires gtk+ 2.12 -->
+ <requires lib="gtk+" version="2.16"/>
<!-- interface-naming-policy toplevel-contextual -->
<object class="GtkWindow" id="chimara">
<property name="title" translatable="yes">Chimara</property>
<child>
<object class="GtkVBox" id="vbox">
<property name="visible">True</property>
- <property name="orientation">vertical</property>
<child>
<placeholder/>
</child>
</object>
<object class="GtkRecentAction" id="recent">
<property name="label">Open _Recent</property>
- <property name="limit">10</property>
<property name="sort_type">mru</property>
+ <property name="limit">10</property>
<signal name="item_activated" handler="on_recent_item_activated"/>
</object>
<object class="GtkAction" id="undo">
<child internal-child="vbox">
<object class="GtkVBox" id="dialog-vbox1">
<property name="visible">True</property>
- <property name="orientation">vertical</property>
<property name="spacing">2</property>
<child>
<placeholder/>
<child internal-child="vbox">
<object class="GtkVBox" id="dialog-vbox2">
<property name="visible">True</property>
- <property name="orientation">vertical</property>
<property name="spacing">9</property>
<child>
- <object class="GtkVBox" id="vbox1">
+ <object class="GtkNotebook" id="notebook1">
<property name="visible">True</property>
- <property name="orientation">vertical</property>
- <property name="spacing">12</property>
+ <property name="can_focus">True</property>
+ <child>
+ <object class="GtkFixed" id="fixed1">
+ <property name="visible">True</property>
+ </object>
+ </child>
+ <child type="tab">
+ <object class="GtkLabel" id="label1">
+ <property name="visible">True</property>
+ <property name="label" translatable="yes">Environment</property>
+ </object>
+ <packing>
+ <property name="tab_fill">False</property>
+ </packing>
+ </child>
<child>
- <object class="GtkFrame" id="frame1">
+ <object class="GtkVBox" id="vbox1">
<property name="visible">True</property>
- <property name="label_xalign">0</property>
- <property name="shadow_type">none</property>
<child>
- <object class="GtkAlignment" id="alignment1">
+ <object class="GtkTable" id="table1">
<property name="visible">True</property>
- <property name="left_padding">12</property>
+ <property name="n_columns">2</property>
<child>
- <object class="GtkVBox" id="vbox2">
+ <object class="GtkLabel" id="label5">
<property name="visible">True</property>
- <property name="orientation">vertical</property>
- <property name="spacing">8</property>
- <child>
- <object class="GtkCheckButton" id="checkbutton1">
- <property name="label" translatable="yes">_Awesome mode</property>
- <property name="visible">True</property>
- <property name="can_focus">True</property>
- <property name="receives_default">False</property>
- <property name="use_underline">True</property>
- <property name="draw_indicator">True</property>
- </object>
- <packing>
- <property name="expand">False</property>
- <property name="fill">False</property>
- <property name="position">0</property>
- </packing>
- </child>
- <child>
- <object class="GtkCheckButton" id="checkbutton2">
- <property name="label" translatable="yes">_Super-awesome mode</property>
- <property name="visible">True</property>
- <property name="can_focus">True</property>
- <property name="receives_default">False</property>
- <property name="use_underline">True</property>
- <property name="draw_indicator">True</property>
- </object>
- <packing>
- <property name="expand">False</property>
- <property name="fill">False</property>
- <property name="position">1</property>
- </packing>
- </child>
- <child>
- <object class="GtkCheckButton" id="checkbutton3">
- <property name="label" translatable="yes">_Ludicrous mode</property>
- <property name="visible">True</property>
- <property name="can_focus">True</property>
- <property name="receives_default">False</property>
- <property name="use_underline">True</property>
- <property name="draw_indicator">True</property>
- </object>
- <packing>
- <property name="expand">False</property>
- <property name="fill">False</property>
- <property name="position">2</property>
- </packing>
- </child>
+ <property name="xalign">1</property>
+ <property name="xpad">5</property>
+ <property name="label" translatable="yes">Load layout from this CSS file:</property>
+ </object>
+ <packing>
+ <property name="x_options">GTK_FILL</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkFileChooserButton" id="css-filechooser">
+ <property name="width_request">250</property>
+ <property name="visible">True</property>
+ <property name="title" translatable="yes">Select A CSS File</property>
</object>
+ <packing>
+ <property name="left_attach">1</property>
+ <property name="right_attach">2</property>
+ </packing>
</child>
</object>
+ <packing>
+ <property name="expand">False</property>
+ <property name="position">0</property>
+ </packing>
</child>
- <child type="label">
- <object class="GtkLabel" id="label1">
+ <child>
+ <object class="GtkHSeparator" id="hseparator1">
<property name="visible">True</property>
- <property name="label" translatable="yes"><b>Miscellaneous options</b></property>
- <property name="use_markup">True</property>
</object>
+ <packing>
+ <property name="expand">False</property>
+ <property name="padding">5</property>
+ <property name="position">1</property>
+ </packing>
</child>
- </object>
- <packing>
- <property name="position">0</property>
- </packing>
- </child>
- <child>
- <object class="GtkFrame" id="frame2">
- <property name="visible">True</property>
- <property name="label_xalign">0</property>
- <property name="shadow_type">none</property>
<child>
- <object class="GtkAlignment" id="alignment2">
+ <object class="GtkVBox" id="vbox3">
<property name="visible">True</property>
- <property name="left_padding">12</property>
<child>
- <object class="GtkVBox" id="vbox3">
+ <object class="GtkLabel" id="label9">
+ <property name="visible">True</property>
+ <property name="xalign">0</property>
+ <property name="xpad">5</property>
+ <property name="label" translatable="yes">Select a style to edit:</property>
+ </object>
+ <packing>
+ <property name="expand">False</property>
+ <property name="position">0</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkHBox" id="hbox1">
<property name="visible">True</property>
- <property name="orientation">vertical</property>
<child>
<object class="GtkScrolledWindow" id="scrolledwindow1">
+ <property name="width_request">163</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
- <property name="hscrollbar_policy">automatic</property>
+ <property name="hscrollbar_policy">never</property>
<property name="vscrollbar_policy">automatic</property>
<child>
- <object class="GtkTreeView" id="treeview1">
+ <object class="GtkTreeView" id="style-treeview">
<property name="visible">True</property>
<property name="can_focus">True</property>
+ <property name="headers_visible">False</property>
+ <property name="headers_clickable">False</property>
</object>
</child>
</object>
</packing>
</child>
<child>
- <object class="GtkHButtonBox" id="hbuttonbox1">
+ <object class="GtkVBox" id="vbox4">
<property name="visible">True</property>
- <property name="spacing">7</property>
- <property name="layout_style">end</property>
<child>
- <object class="GtkButton" id="button2">
- <property name="label">gtk-add</property>
+ <object class="GtkHBox" id="hbox2">
<property name="visible">True</property>
- <property name="can_focus">True</property>
- <property name="receives_default">True</property>
- <property name="use_stock">True</property>
+ <child>
+ <object class="GtkLabel" id="label6">
+ <property name="visible">True</property>
+ <property name="label" translatable="yes">Font:</property>
+ </object>
+ <packing>
+ <property name="expand">False</property>
+ <property name="padding">5</property>
+ <property name="position">0</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkFontButton" id="fontbutton1">
+ <property name="visible">True</property>
+ <property name="can_focus">True</property>
+ <property name="receives_default">True</property>
+ <signal name="font_set" handler="on_font_set"/>
+ </object>
+ <packing>
+ <property name="position">1</property>
+ </packing>
+ </child>
</object>
<packing>
<property name="expand">False</property>
- <property name="fill">False</property>
<property name="position">0</property>
</packing>
</child>
<child>
- <object class="GtkButton" id="button3">
- <property name="label">gtk-remove</property>
+ <object class="GtkFixed" id="fixed2">
+ <property name="height_request">130</property>
<property name="visible">True</property>
- <property name="can_focus">True</property>
- <property name="receives_default">True</property>
- <property name="use_stock">True</property>
+ <child>
+ <object class="GtkColorButton" id="colorbutton1">
+ <property name="width_request">40</property>
+ <property name="height_request">30</property>
+ <property name="visible">True</property>
+ <property name="can_focus">True</property>
+ <property name="receives_default">True</property>
+ <property name="color">#000000000000</property>
+ <signal name="color_set" handler="on_foreground_color_set"/>
+ </object>
+ <packing>
+ <property name="x">125</property>
+ <property name="y">10</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkLabel" id="label7">
+ <property name="visible">True</property>
+ <property name="xpad">5</property>
+ <property name="label" translatable="yes">Foreground color:</property>
+ </object>
+ <packing>
+ <property name="x">4</property>
+ <property name="y">17</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkLabel" id="label8">
+ <property name="visible">True</property>
+ <property name="label" translatable="yes">Background color:</property>
+ </object>
+ <packing>
+ <property name="x">6</property>
+ <property name="y">52</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkColorButton" id="colorbutton2">
+ <property name="width_request">40</property>
+ <property name="height_request">30</property>
+ <property name="visible">True</property>
+ <property name="can_focus">True</property>
+ <property name="receives_default">True</property>
+ <property name="color">#ffffffffffff</property>
+ <signal name="color_set" handler="on_background_color_set"/>
+ </object>
+ <packing>
+ <property name="x">125</property>
+ <property name="y">45</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkToolbar" id="style-toolbar">
+ <property name="width_request">283</property>
+ <property name="height_request">50</property>
+ <property name="visible">True</property>
+ <property name="toolbar_style">icons</property>
+ <child>
+ <object class="GtkToggleToolButton" id="toolbutton-left">
+ <property name="visible">True</property>
+ <property name="related_action">align-left</property>
+ <property name="use_action_appearance">True</property>
+ <property name="label" translatable="yes">Align _left</property>
+ <property name="use_underline">True</property>
+ <property name="stock_id">gtk-justify-left</property>
+ </object>
+ <packing>
+ <property name="expand">False</property>
+ <property name="homogeneous">True</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkToggleToolButton" id="toolbutton-center">
+ <property name="visible">True</property>
+ <property name="related_action">align-center</property>
+ <property name="label" translatable="yes">Align _center</property>
+ <property name="use_underline">True</property>
+ <property name="stock_id">gtk-justify-center</property>
+ </object>
+ <packing>
+ <property name="expand">False</property>
+ <property name="homogeneous">True</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkToggleToolButton" id="toolbutton-right">
+ <property name="visible">True</property>
+ <property name="related_action">align-right</property>
+ <property name="use_action_appearance">True</property>
+ <property name="label" translatable="yes">Align _right</property>
+ <property name="use_underline">True</property>
+ <property name="stock_id">gtk-justify-right</property>
+ </object>
+ <packing>
+ <property name="expand">False</property>
+ <property name="homogeneous">True</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkToggleToolButton" id="toolbutton-justify">
+ <property name="visible">True</property>
+ <property name="related_action">align-justify</property>
+ <property name="use_action_appearance">True</property>
+ <property name="label" translatable="yes">Align _justify</property>
+ <property name="use_underline">True</property>
+ <property name="stock_id">gtk-justify-fill</property>
+ </object>
+ <packing>
+ <property name="expand">False</property>
+ <property name="homogeneous">True</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkSeparatorToolItem" id="toolbutton4">
+ <property name="visible">True</property>
+ </object>
+ <packing>
+ <property name="expand">False</property>
+ <property name="homogeneous">True</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkToggleToolButton" id="toolbutton-bold">
+ <property name="visible">True</property>
+ <property name="related_action">bold</property>
+ <property name="use_action_appearance">True</property>
+ <property name="label" translatable="yes">_Bold</property>
+ <property name="use_underline">True</property>
+ <property name="stock_id">gtk-bold</property>
+ </object>
+ <packing>
+ <property name="expand">False</property>
+ <property name="homogeneous">True</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkToggleToolButton" id="toolbutton-italic">
+ <property name="visible">True</property>
+ <property name="related_action">italic</property>
+ <property name="use_action_appearance">True</property>
+ <property name="label" translatable="yes">_Italic</property>
+ <property name="use_underline">True</property>
+ <property name="stock_id">gtk-italic</property>
+ </object>
+ <packing>
+ <property name="expand">False</property>
+ <property name="homogeneous">True</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkToggleToolButton" id="toolbutton-underline">
+ <property name="visible">True</property>
+ <property name="related_action">underline</property>
+ <property name="use_action_appearance">True</property>
+ <property name="label" translatable="yes">_Underline</property>
+ <property name="use_underline">True</property>
+ <property name="stock_id">gtk-underline</property>
+ </object>
+ <packing>
+ <property name="expand">False</property>
+ <property name="homogeneous">True</property>
+ </packing>
+ </child>
+ </object>
+ <packing>
+ <property name="y">86</property>
+ </packing>
+ </child>
</object>
<packing>
- <property name="expand">False</property>
- <property name="fill">False</property>
<property name="position">1</property>
</packing>
</child>
</packing>
</child>
</object>
+ <packing>
+ <property name="padding">5</property>
+ <property name="position">1</property>
+ </packing>
</child>
</object>
+ <packing>
+ <property name="padding">5</property>
+ <property name="position">2</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkLabel" id="label4">
+ <property name="height_request">30</property>
+ <property name="visible">True</property>
+ <property name="xalign">0</property>
+ <property name="yalign">1</property>
+ <property name="xpad">5</property>
+ <property name="label" translatable="yes">Example text:</property>
+ </object>
+ <packing>
+ <property name="expand">False</property>
+ <property name="position">3</property>
+ </packing>
</child>
- <child type="label">
- <object class="GtkLabel" id="label2">
+ <child>
+ <object class="GtkTextView" id="example-textview">
+ <property name="height_request">100</property>
<property name="visible">True</property>
- <property name="label" translatable="yes"><b>Styles</b></property>
- <property name="use_markup">True</property>
+ <property name="can_focus">True</property>
+ <property name="editable">False</property>
+ <property name="wrap_mode">word-char</property>
+ <property name="left_margin">10</property>
+ <property name="right_margin">10</property>
</object>
+ <packing>
+ <property name="position">4</property>
+ </packing>
</child>
</object>
<packing>
<property name="position">1</property>
</packing>
</child>
+ <child type="tab">
+ <object class="GtkLabel" id="label2">
+ <property name="visible">True</property>
+ <property name="label" translatable="yes">Layout</property>
+ </object>
+ <packing>
+ <property name="position">1</property>
+ <property name="tab_fill">False</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkVBox" id="vbox2">
+ <property name="visible">True</property>
+ <child>
+ <placeholder/>
+ </child>
+ <child>
+ <placeholder/>
+ </child>
+ <child>
+ <placeholder/>
+ </child>
+ </object>
+ <packing>
+ <property name="position">2</property>
+ </packing>
+ </child>
+ <child type="tab">
+ <object class="GtkLabel" id="label3">
+ <property name="visible">True</property>
+ <property name="label" translatable="yes">Interpreters</property>
+ </object>
+ <packing>
+ <property name="position">2</property>
+ <property name="tab_fill">False</property>
+ </packing>
+ </child>
</object>
<packing>
- <property name="position">1</property>
+ <property name="position">2</property>
</packing>
</child>
<child internal-child="action_area">
<property name="layout_style">end</property>
<child>
<object class="GtkButton" id="button1">
+ <property name="label">gtk-save</property>
+ <property name="visible">True</property>
+ <property name="can_focus">True</property>
+ <property name="receives_default">True</property>
+ <property name="use_stock">True</property>
+ </object>
+ <packing>
+ <property name="expand">False</property>
+ <property name="fill">False</property>
+ <property name="position">0</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkButton" id="button2">
+ <property name="label" translatable="yes">Reset</property>
+ <property name="visible">True</property>
+ <property name="can_focus">True</property>
+ <property name="receives_default">True</property>
+ </object>
+ <packing>
+ <property name="expand">False</property>
+ <property name="fill">False</property>
+ <property name="position">1</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkButton" id="button-close">
<property name="label">gtk-close</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<packing>
<property name="expand">False</property>
<property name="fill">False</property>
- <property name="position">0</property>
+ <property name="position">2</property>
</packing>
</child>
</object>
</child>
<action-widgets>
<action-widget response="0">button1</action-widget>
+ <action-widget response="0">button2</action-widget>
+ <action-widget response="0">button-close</action-widget>
</action-widgets>
</object>
+ <object class="GtkActionGroup" id="style-actiongroup"/>
+ <object class="GtkToggleAction" id="align-left">
+ <property name="label">Align _left</property>
+ <property name="short_label">Align _left</property>
+ <property name="tooltip">Align text to the left</property>
+ <property name="stock_id">gtk-justify-left</property>
+ <signal name="toggled" handler="on_toggle_left"/>
+ </object>
+ <object class="GtkToggleAction" id="align-justify">
+ <property name="label">Align _justify</property>
+ <property name="short_label">Align _justify</property>
+ <property name="tooltip">Justify the text</property>
+ <property name="stock_id">gtk-justify-fill</property>
+ <signal name="toggled" handler="on_toggle_justify"/>
+ </object>
+ <object class="GtkToggleAction" id="align-right">
+ <property name="label">Align _right</property>
+ <property name="short_label">Align _right</property>
+ <property name="tooltip">Align text to the right</property>
+ <property name="stock_id">gtk-justify-right</property>
+ <signal name="toggled" handler="on_toggle_right"/>
+ </object>
+ <object class="GtkToggleAction" id="bold">
+ <property name="label">_Bold</property>
+ <property name="short_label">_Bold</property>
+ <property name="tooltip">Make the text bold</property>
+ <property name="stock_id">gtk-bold</property>
+ <signal name="toggled" handler="on_toggle_bold"/>
+ </object>
+ <object class="GtkToggleAction" id="italic">
+ <property name="label">_Italic</property>
+ <property name="short_label">_Italic</property>
+ <property name="tooltip">Print the text in italics</property>
+ <property name="stock_id">gtk-italic</property>
+ <signal name="toggled" handler="on_toggle_italic"/>
+ </object>
+ <object class="GtkToggleAction" id="underline">
+ <property name="label">_Underline</property>
+ <property name="short_label">_Underline</property>
+ <property name="tooltip">Underline the text</property>
+ <property name="stock_id">gtk-underline</property>
+ <signal name="toggled" handler="on_toggle_underline"/>
+ </object>
+ <object class="GtkToggleAction" id="align-center">
+ <property name="stock_id">gtk-justify-center</property>
+ <signal name="toggled" handler="on_toggle_center"/>
+ </object>
</interface>
#include <libchimara/chimara-glk.h>
#include <libchimara/chimara-if.h>
+#include "preferences.h"
+
/* Static global pointers to widgets */
-static GtkBuilder *builder = NULL;
static GtkUIManager *uimanager = NULL;
static GtkWidget *window = NULL;
static GtkWidget *glk = NULL;
/* Global global pointers */
+GtkBuilder *builder = NULL;
GtkWidget *aboutwindow = NULL;
GtkWidget *prefswindow = NULL;
-static GObject *
+GObject *
load_object(const gchar *name)
{
GObject *retval;
aboutwindow = GTK_WIDGET(load_object("aboutwindow"));
prefswindow = GTK_WIDGET(load_object("prefswindow"));
GtkActionGroup *actiongroup = GTK_ACTION_GROUP(load_object("actiongroup"));
+ GtkActionGroup *style_actiongroup = GTK_ACTION_GROUP(load_object("style-actiongroup"));
/* Add all the actions to the action group. This for-loop is a temporary fix
and can be removed once Glade supports adding actions and accelerators to an
"about", "",
NULL
};
+ const gchar *style_actions[] = {
+ "align-left",
+ "align-justify",
+ "align-right",
+ "bold",
+ "italic",
+ "underline",
+ NULL
+ };
const gchar **ptr;
for(ptr = actions; *ptr; ptr += 2)
gtk_action_group_add_action_with_accel(actiongroup, GTK_ACTION(load_object(ptr[0])), ptr[1]);
+ for(ptr = style_actions; *ptr; ptr ++)
+ gtk_action_group_add_action(style_actiongroup, GTK_ACTION(load_object(*ptr)));
GtkRecentFilter *filter = gtk_recent_filter_new();
/* TODO: Use mimetypes and construct the filter dynamically depending on
what plugins are installed */
gtk_ui_manager_insert_action_group(uimanager, actiongroup, 0);
GtkWidget *menubar = gtk_ui_manager_get_widget(uimanager, "/menubar");
- GtkWidget *toolbar = gtk_ui_manager_get_widget(uimanager, "/toolbar");
+ //GtkWidget *toolbar = gtk_ui_manager_get_widget(uimanager, "/toolbar");
gtk_box_pack_end(vbox, glk, TRUE, TRUE, 0);
gtk_box_pack_start(vbox, menubar, FALSE, FALSE, 0);
- gtk_box_pack_start(vbox, toolbar, FALSE, FALSE, 0);
+ //gtk_box_pack_start(vbox, toolbar, FALSE, FALSE, 0);
gtk_builder_connect_signals(builder, glk);
g_signal_connect(glk, "notify::program-name", G_CALLBACK(change_window_title), window);
g_signal_connect(glk, "notify::story-name", G_CALLBACK(change_window_title), window);
+
+ /* Create preferences window */
+ preferences_create(CHIMARA_GLK(glk));
}
int
create_window();
gtk_widget_show_all(window);
- g_object_unref( G_OBJECT(builder) );
g_object_unref( G_OBJECT(uimanager) );
if(argc >= 2) {
chimara_glk_stop(CHIMARA_GLK(glk));
chimara_glk_wait(CHIMARA_GLK(glk));
+ g_object_unref( G_OBJECT(builder) );
+
return 0;
}
--- /dev/null
+/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 4; tab-width: 4 -*- */
+/*
+ * callbacks.c
+ * Copyright (C) Philip en Marijn 2008 <>
+ *
+ * preferences.c is free software copyrighted by Philip en Marijn.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name ``Philip en Marijn'' nor the name of any other
+ * contributor may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * preferences.c IS PROVIDED BY Philip en Marijn ``AS IS'' AND ANY EXPRESS
+ * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL Philip en Marijn OR ANY OTHER CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
+ * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
+ * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <glib.h>
+#include <glib/gi18n.h>
+#include <gtk/gtk.h>
+#include <libchimara/chimara-glk.h>
+#include <libchimara/chimara-if.h>
+#include <config.h>
+#include "error.h"
+
+GObject *load_object(const gchar *name);
+static GtkTextTag *current_tag;
+
+static void style_tree_select_callback(GtkTreeSelection *selection, ChimaraGlk *glk);
+
+/* Create the preferences dialog. */
+void
+preferences_create(ChimaraGlk *glk)
+{
+ /* Initialize the tree of style names */
+ GtkTreeStore *style_list = gtk_tree_store_new(1, G_TYPE_STRING);
+ GtkTreeIter buffer, grid, buffer_child, grid_child;
+
+ gtk_tree_store_append(style_list, &buffer, NULL);
+ gtk_tree_store_append(style_list, &grid, NULL);
+ gtk_tree_store_set(style_list, &buffer, 0, "Text buffer", -1);
+ gtk_tree_store_set(style_list, &grid, 0, "Text grid", -1);
+
+ int i;
+ gint num_tags = chimara_glk_get_num_tag_names(glk);
+ const gchar **tag_names = chimara_glk_get_tag_names(glk);
+ for(i=0; i<num_tags; i++) {
+ gtk_tree_store_append(style_list, &buffer_child, &buffer);
+ gtk_tree_store_append(style_list, &grid_child, &grid);
+ gtk_tree_store_set(style_list, &buffer_child, 0, tag_names[i], -1);
+ gtk_tree_store_set(style_list, &grid_child, 0, tag_names[i], -1);
+ }
+
+ /* Attach the model to the treeview */
+ GtkTreeView *view = GTK_TREE_VIEW( load_object("style-treeview") );
+ gtk_tree_view_set_model(view, GTK_TREE_MODEL(style_list));
+ g_object_unref(style_list);
+
+ /* Set the columns */
+ GtkTreeViewColumn *column = gtk_tree_view_column_new();
+ gtk_tree_view_column_set_title(column, "Style Name");
+ gtk_tree_view_append_column(view, column);
+
+ /* Set the renderers */
+ GtkCellRenderer *renderer = gtk_cell_renderer_text_new();
+ gtk_tree_view_column_pack_start(column, renderer, TRUE);
+ gtk_tree_view_column_add_attribute(column, renderer, "text", 0);
+
+ /* Set selection mode to single select */
+ GtkTreeSelection *selection = gtk_tree_view_get_selection(view);
+ gtk_tree_selection_set_mode(selection, GTK_SELECTION_SINGLE);
+
+ g_signal_connect(selection, "changed", G_CALLBACK(style_tree_select_callback), glk);
+}
+
+static void
+style_tree_select_callback(GtkTreeSelection *selection, ChimaraGlk *glk)
+{
+ GtkTreeIter child, parent;
+ gchar *child_name, *parent_name;
+ GtkTreeModel *model;
+
+ if( !gtk_tree_selection_get_selected(selection, &model, &child) )
+ return;
+
+ gtk_tree_model_get(model, &child, 0, &child_name, -1);
+
+ if( !gtk_tree_model_iter_parent(model, &parent, &child) )
+ return;
+
+ gtk_tree_model_get(model, &parent, 0, &parent_name, -1);
+ if( !strcmp(parent_name, "Text buffer") )
+ current_tag = chimara_glk_get_tag(glk, CHIMARA_GLK_TEXT_BUFFER, child_name);
+ else
+ current_tag = chimara_glk_get_tag(glk, CHIMARA_GLK_TEXT_GRID, child_name);
+}
+
+void
+on_toggle_left(GtkToggleAction *action, ChimaraGlk *glk) {
+ /* No nothing if the button is deactivated */
+ if( !gtk_toggle_action_get_active(action) )
+ return;
+
+ /* Untoggle other alignment options */
+ GtkToggleToolButton *center = GTK_TOGGLE_TOOL_BUTTON(load_object("toolbutton-center"));
+ GtkToggleToolButton *right = GTK_TOGGLE_TOOL_BUTTON(load_object("toolbutton-right"));
+ GtkToggleToolButton *justify = GTK_TOGGLE_TOOL_BUTTON(load_object("toolbutton-justify"));
+ gtk_toggle_tool_button_set_active(center, FALSE);
+ gtk_toggle_tool_button_set_active(right, FALSE);
+ gtk_toggle_tool_button_set_active(justify, FALSE);
+
+ g_object_set(current_tag, "justification", GTK_JUSTIFY_LEFT, "justification-set", TRUE, NULL);
+ chimara_glk_update_style(glk);
+}
+
+void
+on_toggle_center(GtkToggleAction *action, ChimaraGlk *glk) {
+ if( !gtk_toggle_action_get_active(action) )
+ return;
+
+ /* Untoggle other alignment options */
+ GtkToggleToolButton *left = GTK_TOGGLE_TOOL_BUTTON(load_object("toolbutton-left"));
+ GtkToggleToolButton *right = GTK_TOGGLE_TOOL_BUTTON(load_object("toolbutton-right"));
+ GtkToggleToolButton *justify = GTK_TOGGLE_TOOL_BUTTON(load_object("toolbutton-justify"));
+ gtk_toggle_tool_button_set_active(left, FALSE);
+ gtk_toggle_tool_button_set_active(right, FALSE);
+ gtk_toggle_tool_button_set_active(justify, FALSE);
+
+ g_object_set(current_tag, "justification", GTK_JUSTIFY_CENTER, "justification-set", TRUE, NULL);
+ chimara_glk_update_style(glk);
+}
+
+void
+on_toggle_right(GtkToggleAction *action, ChimaraGlk *glk) {
+ if( !gtk_toggle_action_get_active(action) )
+ return;
+
+ /* Untoggle other alignment options */
+ GtkToggleToolButton *left = GTK_TOGGLE_TOOL_BUTTON(load_object("toolbutton-left"));
+ GtkToggleToolButton *center = GTK_TOGGLE_TOOL_BUTTON(load_object("toolbutton-center"));
+ GtkToggleToolButton *justify = GTK_TOGGLE_TOOL_BUTTON(load_object("toolbutton-justify"));
+ gtk_toggle_tool_button_set_active(left, FALSE);
+ gtk_toggle_tool_button_set_active(center, FALSE);
+ gtk_toggle_tool_button_set_active(justify, FALSE);
+
+ g_object_set(current_tag, "justification", GTK_JUSTIFY_RIGHT, "justification-set", TRUE, NULL);
+ chimara_glk_update_style(glk);
+}
+
+void
+on_toggle_justify(GtkToggleAction *action, ChimaraGlk *glk) {
+ if( !gtk_toggle_action_get_active(action) )
+ return;
+
+ /* Untoggle other alignment options */
+ GtkToggleToolButton *left = GTK_TOGGLE_TOOL_BUTTON(load_object("toolbutton-left"));
+ GtkToggleToolButton *center = GTK_TOGGLE_TOOL_BUTTON(load_object("toolbutton-center"));
+ GtkToggleToolButton *right = GTK_TOGGLE_TOOL_BUTTON(load_object("toolbutton-right"));
+ gtk_toggle_tool_button_set_active(left, FALSE);
+ gtk_toggle_tool_button_set_active(center, FALSE);
+ gtk_toggle_tool_button_set_active(right, FALSE);
+
+ g_object_set(current_tag, "justification", GTK_JUSTIFY_FILL, "justification-set", TRUE, NULL);
+ chimara_glk_update_style(glk);
+}
+
+void
+on_toggle_bold(GtkToggleAction *action, ChimaraGlk *glk) {
+ if( gtk_toggle_action_get_active(action) )
+ g_object_set(current_tag, "weight", PANGO_WEIGHT_BOLD, "weight-set", TRUE, NULL);
+ else
+ g_object_set(current_tag, "weight", PANGO_WEIGHT_NORMAL, "weight-set", TRUE, NULL);
+
+ chimara_glk_update_style(glk);
+}
+
+void
+on_toggle_italic(GtkToggleAction *action, ChimaraGlk *glk) {
+ if( gtk_toggle_action_get_active(action) )
+ g_object_set(current_tag, "style", PANGO_STYLE_ITALIC, "style-set", TRUE, NULL);
+ else
+ g_object_set(current_tag, "style", PANGO_STYLE_NORMAL, "style-set", TRUE, NULL);
+
+ chimara_glk_update_style(glk);
+}
+
+void
+on_toggle_underline(GtkToggleAction *action, ChimaraGlk *glk) {
+ if( gtk_toggle_action_get_active(action) )
+ g_object_set(current_tag, "underline", PANGO_UNDERLINE_SINGLE, "underline-set", TRUE, NULL);
+ else
+ g_object_set(current_tag, "underline", PANGO_UNDERLINE_NONE, "underline-set", TRUE, NULL);
+
+ chimara_glk_update_style(glk);
+}
+
+void
+on_foreground_color_set(GtkColorButton *button, ChimaraGlk *glk)
+{
+ GdkColor color;
+ gtk_color_button_get_color(button, &color);
+ g_object_set(current_tag, "foreground-gdk", &color, "foreground-set", TRUE, NULL);
+ chimara_glk_update_style(glk);
+}
+
+void
+on_background_color_set(GtkColorButton *button, ChimaraGlk *glk)
+{
+ GdkColor color;
+ gtk_color_button_get_color(button, &color);
+ g_object_set(current_tag, "background-gdk", &color, "background-set", TRUE, NULL);
+ chimara_glk_update_style(glk);
+}
+
+void
+on_font_set(GtkFontButton *button, ChimaraGlk *glk)
+{
+ const gchar *font_name = gtk_font_button_get_font_name(button);
+ PangoFontDescription *font_description = pango_font_description_from_string(font_name);
+ g_object_set(current_tag, "font-desc", font_description, NULL);
+ chimara_glk_update_style(glk);
+}
--- /dev/null
+#ifndef PREFERENCES_H
+#define PREFERENCES_H
+
+#include <gtk/gtk.h>
+#include <libchimara/chimara-glk.h>
+
+G_GNUC_INTERNAL void preferences_create(ChimaraGlk *glk);
+
+#endif