Initialise StylesheetEditor default font and fgcol
authorThomas White <taw@bitwiz.me.uk>
Mon, 23 Apr 2018 21:19:50 +0000 (23:19 +0200)
committerThomas White <taw@bitwiz.me.uk>
Mon, 23 Apr 2018 21:19:50 +0000 (23:19 +0200)
data/stylesheeteditor.ui
src/stylesheet_editor.c
src/stylesheet_editor.h

index a3ec7c8..62483db 100644 (file)
                       </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>
                       </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>
index 85e053c..0d9845f 100644 (file)
 
 #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;
 }
 
index ab2d65c..7883132 100644 (file)
                                                         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;
 };