diff options
author | Thomas White <taw@bitwiz.org.uk> | 2011-06-02 00:11:29 +0200 |
---|---|---|
committer | Thomas White <taw@bitwiz.org.uk> | 2011-06-02 00:11:29 +0200 |
commit | d3019050bb94994bc6301b5c1ce057e0d10ea22b (patch) | |
tree | 9ba8ab7a9b2cde71dc2632c257ea4e853dd1dc4c | |
parent | 40d60e8d85bfb6809df06c331cceab955c416751 (diff) |
Tool switching machinery
-rw-r--r-- | TODO | 3 | ||||
-rw-r--r-- | src/mainwindow.c | 49 | ||||
-rw-r--r-- | src/presentation.h | 10 |
3 files changed, 48 insertions, 14 deletions
@@ -4,9 +4,6 @@ Text selection Paste into text Set font and size -Switch tools - Select/drag - Text Drag objects around Cursors diff --git a/src/mainwindow.c b/src/mainwindow.c index 289e875..d5c0374 100644 --- a/src/mainwindow.c +++ b/src/mainwindow.c @@ -201,6 +201,21 @@ static gint last_slide_sig(GtkWidget *widget, struct presentation *p) } +static gint set_tool_sig(GtkWidget *widget, GtkRadioAction *action, + struct presentation *p) +{ + switch ( gtk_radio_action_get_current_value(action) ) + { + case 0 : p->tool = TOOL_SELECT; break; + case 1 : p->tool = TOOL_TEXT; break; + } + p->editing_object = NULL; + gdk_window_invalidate_rect(p->drawingarea->window, NULL, FALSE); + + return 0; +} + + static void add_menu_bar(struct presentation *p, GtkWidget *vbox) { GError *error = NULL; @@ -230,16 +245,22 @@ static void add_menu_bar(struct presentation *p, GtkWidget *vbox) NULL, NULL, G_CALLBACK(next_slide_sig) }, { "ButtonLastSlideAction", GTK_STOCK_GOTO_LAST, "Last Slide", NULL, NULL, G_CALLBACK(last_slide_sig) }, - { "ButtonToolSelectAction", "colloquium-select", "Select", - NULL, NULL, NULL }, - { "ButtonToolTextAction", "colloquium-text", "Text", - NULL, NULL, NULL }, }; guint n_entries = G_N_ELEMENTS(entries); + GtkRadioActionEntry tools[] = { + { "ButtonToolSelectAction", "colloquium-select", "Select", + NULL, NULL, TOOL_SELECT }, + { "ButtonToolTextAction", "colloquium-text", "Text", + NULL, NULL, TOOL_TEXT }, + }; + guint n_tools = G_N_ELEMENTS(tools); p->action_group = gtk_action_group_new("mainwindow"); gtk_action_group_add_actions(p->action_group, entries, n_entries, p); + gtk_action_group_add_radio_actions(p->action_group, tools, n_tools, + TOOL_SELECT, + G_CALLBACK(set_tool_sig), p); p->ui = gtk_ui_manager_new(); gtk_ui_manager_insert_action_group(p->ui, p->action_group, 0); @@ -354,14 +375,20 @@ static gboolean button_press_sig(GtkWidget *da, GdkEventButton *event, && (y>0.0) && (y<p->view_slide->slide_height) ) { clicked = find_object_at_position(p->view_slide, x, y); - if ( !clicked ) { - p->editing_object = add_text_object(p->view_slide, - x, y); - } else { - p->editing_object = clicked; - position_caret(clicked, x, y); + switch ( p->tool ) { + case TOOL_SELECT : + break; + case TOOL_TEXT : + if ( !clicked ) { + struct object *n; + n = add_text_object(p->view_slide, x, y); + p->editing_object = n; + } else { + p->editing_object = clicked; + position_caret(clicked, x, y); + } + break; } - } gtk_widget_grab_focus(GTK_WIDGET(da)); diff --git a/src/presentation.h b/src/presentation.h index fe0abd2..4acc005 100644 --- a/src/presentation.h +++ b/src/presentation.h @@ -45,6 +45,13 @@ struct slide }; +enum tool +{ + TOOL_SELECT, + TOOL_TEXT, +}; + + struct presentation { char *titlebar; @@ -73,6 +80,9 @@ struct presentation struct slide *view_slide; struct object *editing_object; + /* Tool status */ + enum tool tool; + unsigned int num_slides; struct slide **slides; }; |