diff options
author | Thomas White <taw@bitwiz.org.uk> | 2011-08-10 22:03:52 +0200 |
---|---|---|
committer | Thomas White <taw@bitwiz.org.uk> | 2011-08-10 22:03:52 +0200 |
commit | 87d1c1c339768b8c9cde14e40b955e618ee4540f (patch) | |
tree | bae3f229a48a526f2f1d788cff3db204068e555f | |
parent | 394b051daacb63c661dba0a8c57ec04ad1ae73cf (diff) |
Plug in style and layout stuff to UI
-rw-r--r-- | data/colloquium.ui | 4 | ||||
-rw-r--r-- | src/mainwindow.c | 78 | ||||
-rw-r--r-- | src/objects.c | 22 | ||||
-rw-r--r-- | src/objects.h | 7 | ||||
-rw-r--r-- | src/presentation.h | 6 | ||||
-rw-r--r-- | src/slide_render.c | 3 | ||||
-rw-r--r-- | src/stylesheet.c | 16 | ||||
-rw-r--r-- | src/stylesheet.h | 16 |
8 files changed, 125 insertions, 27 deletions
diff --git a/data/colloquium.ui b/data/colloquium.ui index d4fb27c..f52500d 100644 --- a/data/colloquium.ui +++ b/data/colloquium.ui @@ -48,8 +48,10 @@ <separator /> <toolitem name="select" action="ButtonToolSelectAction" /> <toolitem name="text" action="ButtonToolTextAction" /> + <separator /> + <toolitem name="select" action="ButtonToolSelectAction" /> + <toolitem name="text" action="ButtonToolTextAction" /> </toolbar> - </ui> diff --git a/src/mainwindow.c b/src/mainwindow.c index d6d98f4..fe31ad4 100644 --- a/src/mainwindow.c +++ b/src/mainwindow.c @@ -211,6 +211,7 @@ static gint open_stylesheet_sig(GtkWidget *widget, struct presentation *p) return FALSE; } + static gint set_tool_sig(GtkWidget *widget, GtkRadioAction *action, struct presentation *p) { @@ -226,9 +227,44 @@ static gint set_tool_sig(GtkWidget *widget, GtkRadioAction *action, } +static void layout_changed_sig(GtkComboBox *combo, struct presentation *p) +{ + int n; + + if ( p->editing_object != NULL ) { + printf("Can't change layout element!\n"); + return; + } + + n = gtk_combo_box_get_active(GTK_COMBO_BOX(combo)); + p->cur_layout = p->ss->layout_elements[n]; + + +} + + +static void text_style_changed_sig(GtkComboBox *combo, struct presentation *p) +{ + int n; + + n = gtk_combo_box_get_active(GTK_COMBO_BOX(combo)); + p->cur_style = p->ss->text_styles[n]; + + if ( p->editing_object != NULL ) { + set_text_style(p->editing_object, p->cur_style); + gdk_window_invalidate_rect(p->drawingarea->window, NULL, FALSE); + } +} + + static void add_menu_bar(struct presentation *p, GtkWidget *vbox) { GError *error = NULL; + GtkWidget *label; + GtkWidget *combo; + GtkToolItem *titem; + GtkWidget *box; + int i; GtkActionEntry entries[] = { { "FileAction", NULL, "_File", NULL, NULL, NULL }, @@ -314,6 +350,44 @@ static void add_menu_bar(struct presentation *p, GtkWidget *vbox) gtk_ui_manager_get_accel_group(p->ui)); gtk_ui_manager_ensure_update(p->ui); + p->toolbar = gtk_ui_manager_get_widget(p->ui, + "/ui/displaywindowtoolbar"); + + titem = gtk_separator_tool_item_new(); + gtk_toolbar_insert(GTK_TOOLBAR(p->toolbar), titem, -1); + + box = gtk_vbox_new(FALSE, 0.0); + p->tbox = gtk_hbox_new(FALSE, 0.0); + titem = gtk_tool_item_new(); + gtk_box_pack_start(GTK_BOX(box), p->tbox, FALSE, FALSE, 5.0); + gtk_container_add(GTK_CONTAINER(titem), box); + gtk_toolbar_insert(GTK_TOOLBAR(p->toolbar), titem, -1); + label = gtk_label_new("Layout element:"); + gtk_misc_set_alignment(GTK_MISC(label), 1.0, 0.5); + gtk_box_pack_start(GTK_BOX(p->tbox), label, FALSE, FALSE, 5.0); + combo = gtk_combo_box_new_text(); + for ( i=0; i<p->ss->n_layout_elements; i++ ) { + gtk_combo_box_append_text(GTK_COMBO_BOX(combo), + p->ss->layout_elements[i]->name); + } + gtk_box_pack_start(GTK_BOX(p->tbox), combo, FALSE, FALSE, 5.0); + g_signal_connect(G_OBJECT(combo), "changed", + G_CALLBACK(layout_changed_sig), p); + gtk_combo_box_set_active(GTK_COMBO_BOX(combo), 0); + + label = gtk_label_new("Text style:"); + gtk_misc_set_alignment(GTK_MISC(label), 1.0, 0.5); + gtk_box_pack_start(GTK_BOX(p->tbox), label, FALSE, FALSE, 5.0); + combo = gtk_combo_box_new_text(); + for ( i=0; i<p->ss->n_text_styles; i++ ) { + gtk_combo_box_append_text(GTK_COMBO_BOX(combo), + p->ss->text_styles[i]->name); + } + gtk_box_pack_start(GTK_BOX(p->tbox), combo, FALSE, FALSE, 5.0); + g_signal_connect(G_OBJECT(combo), "changed", + G_CALLBACK(text_style_changed_sig), p); + gtk_combo_box_set_active(GTK_COMBO_BOX(combo), 0); + update_toolbar(p); } @@ -454,7 +528,9 @@ static gboolean button_press_sig(GtkWidget *da, GdkEventButton *event, case TOOL_TEXT : if ( !clicked ) { struct object *n; - n = add_text_object(p->view_slide, x, y); + n = add_text_object(p->view_slide, x, y, + p->cur_layout, + p->cur_style); p->editing_object = n; } else { p->editing_object = clicked; diff --git a/src/objects.c b/src/objects.c index cb921f3..6b99005 100644 --- a/src/objects.c +++ b/src/objects.c @@ -33,7 +33,7 @@ #include "objects.h" -static struct object *new_object(enum objtype t) +static struct object *new_object(enum objtype t, struct layout_element *le) { struct object *new; @@ -43,9 +43,7 @@ static struct object *new_object(enum objtype t) new->type = t; new->empty = 1; new->parent = NULL; - - new->layout = NULL; - new->fontdesc = NULL; + new->le = NULL; return new; } @@ -59,11 +57,12 @@ static void free_object(struct object *o) } -struct object *add_text_object(struct slide *s, double x, double y) +struct object *add_text_object(struct slide *s, double x, double y, + struct layout_element *el, struct text_style *ts) { struct object *new; - new = new_object(TEXT); + new = new_object(TEXT, el); if ( add_object_to_slide(s, new) ) { free_object(new); return NULL; @@ -76,6 +75,9 @@ struct object *add_text_object(struct slide *s, double x, double y) new->text[0] = '\0'; new->text_len = 1; new->insertion_point = 0; + new->style = ts; + new->layout = NULL; + new->fontdesc = NULL; s->object_seq++; @@ -127,6 +129,14 @@ void insert_text(struct object *o, char *t) } +void set_text_style(struct object *o, struct text_style *ts) +{ + assert(o->type == TEXT); + o->style = ts; + o->parent->object_seq++; +} + + static int find_prev_index(const char *t, int p) { int i, nback; diff --git a/src/objects.h b/src/objects.h index bc65979..32ac4ee 100644 --- a/src/objects.h +++ b/src/objects.h @@ -38,6 +38,7 @@ struct object { enum objtype type; struct slide *parent; + struct layout_element *le; /* Position of corner of object */ double x; @@ -55,11 +56,15 @@ struct object int insertion_point; PangoLayout *layout; PangoFontDescription *fontdesc; + struct text_style *style; }; -extern struct object *add_text_object(struct slide *s, double x, double y); +extern struct object *add_text_object(struct slide *s, double x, double y, + struct layout_element *el, + struct text_style *ts); extern void insert_text(struct object *o, char *t); +extern void set_text_style(struct object *o, struct text_style *ts); extern void handle_text_backspace(struct object *o); extern void move_cursor_left(struct object *o); extern void move_cursor_right(struct object *o); diff --git a/src/presentation.h b/src/presentation.h index a3e831d..60751d5 100644 --- a/src/presentation.h +++ b/src/presentation.h @@ -64,9 +64,13 @@ struct presentation GtkUIManager *ui; GtkActionGroup *action_group; GtkIMContext *im_context; + GtkWidget *toolbar; + GtkWidget *tbox; /* Stylesheet */ - StyleSheet *ss; + StyleSheet *ss; + struct text_style *cur_style; + struct layout_element *cur_layout; /* Dialogue boxes */ StylesheetWindow *stylesheetwindow; diff --git a/src/slide_render.c b/src/slide_render.c index 6dec16f..c4cd55c 100644 --- a/src/slide_render.c +++ b/src/slide_render.c @@ -32,6 +32,7 @@ #include "slide_render.h" #include "presentation.h" #include "objects.h" +#include "stylesheet.h" static void render_text_object(cairo_t *cr, struct object *o) @@ -40,7 +41,7 @@ static void render_text_object(cairo_t *cr, struct object *o) o->layout = pango_cairo_create_layout(cr); pango_layout_set_text(o->layout, o->text, -1); - o->fontdesc = pango_font_description_from_string("Sans 30"); + o->fontdesc = pango_font_description_from_string(o->style->font); pango_layout_set_font_description(o->layout, o->fontdesc); pango_cairo_update_layout(cr, o->layout); diff --git a/src/stylesheet.c b/src/stylesheet.c index 126bbd2..3905865 100644 --- a/src/stylesheet.c +++ b/src/stylesheet.c @@ -61,22 +61,6 @@ struct _stylesheetwindow }; -struct _stylesheet -{ - /* Slide layout */ - struct layout_element **layout_elements; - int n_layout_elements; - - /* Normal text styles */ - struct text_style **text_styles; - int n_text_styles; - - /* Background stuff */ - - /* Image styles */ -}; - - static void text_changed_sig(GtkComboBox *combo, struct _stylesheetwindow *s) { diff --git a/src/stylesheet.h b/src/stylesheet.h index b2640a7..8f9733e 100644 --- a/src/stylesheet.h +++ b/src/stylesheet.h @@ -73,6 +73,22 @@ struct layout_element }; +struct _stylesheet +{ + /* Slide layout */ + struct layout_element **layout_elements; + int n_layout_elements; + + /* Normal text styles */ + struct text_style **text_styles; + int n_text_styles; + + /* Background stuff */ + + /* Image styles */ +}; + + typedef struct _stylesheetwindow StylesheetWindow; typedef struct _stylesheet StyleSheet; struct presentation; |