aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas White <taw@bitwiz.me.uk>2018-04-23 23:19:50 +0200
committerThomas White <taw@bitwiz.me.uk>2018-04-23 23:19:50 +0200
commita6af31fbaba86661985fd8767026ea3b1c5ae191 (patch)
treef0fda56d7d564d87b6a1cf26d9d846e549e02540
parent24589a64a3dfc28469ab8744eb9fcab72ed4ae94 (diff)
Initialise StylesheetEditor default font and fgcol
-rw-r--r--data/stylesheeteditor.ui4
-rw-r--r--src/stylesheet_editor.c58
-rw-r--r--src/stylesheet_editor.h8
3 files changed, 59 insertions, 11 deletions
diff --git a/data/stylesheeteditor.ui b/data/stylesheeteditor.ui
index a3ec7c8..62483db 100644
--- a/data/stylesheeteditor.ui
+++ b/data/stylesheeteditor.ui
@@ -103,7 +103,7 @@
</packing>
</child>
<child>
- <object class="GtkFontButton">
+ <object class="GtkFontButton" id="default_style_font">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
@@ -117,7 +117,7 @@
</packing>
</child>
<child>
- <object class="GtkColorButton">
+ <object class="GtkColorButton" id="default_style_fgcol">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
diff --git a/src/stylesheet_editor.c b/src/stylesheet_editor.c
index 85e053c..0d9845f 100644
--- a/src/stylesheet_editor.c
+++ b/src/stylesheet_editor.c
@@ -32,20 +32,29 @@
#include "stylesheet_editor.h"
#include "presentation.h"
+#include "sc_interp.h"
+
G_DEFINE_TYPE_WITH_CODE(StylesheetEditor, stylesheet_editor,
GTK_TYPE_DIALOG, NULL)
-struct stylesheet_editor_private
+struct _sspriv
{
- GtkDialog *default_style_ss;
+
+ struct presentation *p;
};
+static void revert_sig(GtkButton *button, StylesheetEditor *widget)
+{
+ printf("click revert!\n");
+}
+
+
static void stylesheet_editor_init(StylesheetEditor *se)
{
se->priv = G_TYPE_INSTANCE_GET_PRIVATE(se, COLLOQUIUM_TYPE_STYLESHEET_EDITOR,
- struct stylesheet_editor_private);
+ StylesheetEditorPrivate);
gtk_widget_init_template(GTK_WIDGET(se));
}
@@ -58,12 +67,44 @@ void stylesheet_editor_class_init(StylesheetEditorClass *klass)
gtk_widget_class_set_template_from_resource(widget_class,
"/uk/me/bitwiz/Colloquium/stylesheeteditor.ui");
- gtk_widget_class_bind_template_child(widget_class,
- struct stylesheet_editor_private,
+ g_type_class_add_private(gobject_class, sizeof(StylesheetEditorPrivate));
+
+ gtk_widget_class_bind_template_child(widget_class, StylesheetEditor,
default_style_ss);
+ gtk_widget_class_bind_template_child(widget_class, StylesheetEditor,
+ default_style_font);
+ gtk_widget_class_bind_template_child(widget_class, StylesheetEditor,
+ default_style_fgcol);
+
+ gtk_widget_class_bind_template_callback(widget_class, revert_sig);
+}
- g_type_class_add_private(gobject_class,
- sizeof(struct stylesheet_editor_private));
+
+static void set_values_from_presentation(StylesheetEditor *se)
+{
+ SCInterpreter *scin;
+ char *fontname;
+ PangoFontDescription *fontdesc;
+ double *col;
+ GdkRGBA rgba;
+
+ scin = sc_interp_new(NULL, NULL, NULL, NULL);
+ sc_interp_run_stylesheet(scin, se->priv->p->stylesheet); /* NULL stylesheet is OK */
+
+ /* Default style */
+ fontdesc = sc_interp_get_fontdesc(scin);
+ fontname = pango_font_description_to_string(fontdesc);
+ gtk_font_button_set_font_name(GTK_FONT_BUTTON(se->default_style_font), fontname);
+ g_free(fontname);
+
+ col = sc_interp_get_fgcol(scin);
+ rgba.red = col[0];
+ rgba.green = col[1];
+ rgba.blue = col[2];
+ rgba.alpha = col[3];
+ gtk_color_chooser_set_rgba(GTK_COLOR_CHOOSER(se->default_style_fgcol), &rgba);
+
+ sc_interp_destroy(scin);
}
@@ -74,6 +115,9 @@ StylesheetEditor *stylesheet_editor_new(struct presentation *p)
se = g_object_new(COLLOQUIUM_TYPE_STYLESHEET_EDITOR, NULL);
if ( se == NULL ) return NULL;
+ se->priv->p = p;
+ set_values_from_presentation(se);
+
return se;
}
diff --git a/src/stylesheet_editor.h b/src/stylesheet_editor.h
index ab2d65c..7883132 100644
--- a/src/stylesheet_editor.h
+++ b/src/stylesheet_editor.h
@@ -51,12 +51,16 @@
COLLOQUIUM_TYPE_STYLESHEET_EDITOR, \
StylesheetEditorClass))
-struct stylesheet_editor_private;
+
+typedef struct _sspriv StylesheetEditorPrivate;
struct _stylesheeteditor
{
GtkDialog parent_instance;
- struct stylesheet_editor_private *priv;
+ GtkWidget *default_style_font;
+ GtkWidget *default_style_fgcol;
+ GtkWidget *default_style_ss;
+ StylesheetEditorPrivate *priv;
};