diff options
author | Chris Wilson <chris@chris-wilson.co.uk> | 2008-11-05 14:33:08 +0000 |
---|---|---|
committer | Chris Wilson <chris@chris-wilson.co.uk> | 2008-11-05 14:33:08 +0000 |
commit | 78bc3c8a3c48f09aa753eaee17cdd99bde9e0fa0 (patch) | |
tree | bb5f6581617fb4e87e7ad2a8fdaa0971cd6ee6cb | |
parent | 5087e0420821687a0c8d6bd9e648cc9fc10ab181 (diff) |
Update view after context undef.
-rw-r--r-- | src/main.c | 224 | ||||
-rw-r--r-- | src/sphinx.h | 5 |
2 files changed, 169 insertions, 60 deletions
@@ -445,6 +445,30 @@ numbers_toggled_cb (GtkToggleAction *action, sphinx_t *sphinx) } static void +break_surface_cb (GtkToggleAction *action, sphinx_t *sphinx) +{ + sphinx->break_on_surface_undef = gtk_toggle_action_get_active (action); +} + +static void +break_context_cb (GtkToggleAction *action, sphinx_t *sphinx) +{ + sphinx->break_on_context_undef = gtk_toggle_action_get_active (action); +} + +static void +watch_surface_cb (GtkToggleAction *action, sphinx_t *sphinx) +{ + sphinx->watch_surfaces = gtk_toggle_action_get_active (action); +} + +static void +watch_context_cb (GtkToggleAction *action, sphinx_t *sphinx) +{ + sphinx->watch_contexts = gtk_toggle_action_get_active (action); +} + +static void run_interpreter_cb (GtkAction *action, sphinx_t *sphinx) { GtkTextIter start, end; @@ -570,6 +594,33 @@ surface_view_init (SurfaceView *self) GTK_WIDGET_SET_FLAGS (self, GTK_NO_WINDOW); } +static void +surface_view_set_surface (SurfaceView *self, cairo_surface_t *surface) +{ + gint old_width, old_height; + + if (surface == self->surface) + return; + + old_width = old_height = 0; + if (self->surface != NULL) { + old_width = cairo_image_surface_get_width (self->surface); + old_height = cairo_image_surface_get_height (self->surface); + cairo_surface_destroy (self->surface); + } + + self->surface = cairo_surface_reference (surface); + if (old_width != cairo_image_surface_get_width (self->surface) || + old_height != cairo_image_surface_get_height (self->surface)) + { + gtk_widget_queue_resize (&self->widget); + } + else + { + gtk_widget_queue_draw (&self->widget); + } +} + static gboolean _delete_surface (GtkWidget *w, GdkEvent *ev, sphinx_t *sphinx) { @@ -592,6 +643,68 @@ continue_cb (GtkAction *action, GtkWidget *window) sphinx_run_continue (g_object_get_data (G_OBJECT (window), "sphinx")); } +static SurfaceView * +_create_surface_view (sphinx_t *sphinx) +{ + const gchar *ui_xml = + "<ui>" + " <toolbar name='ToolBar'>" + " <toolitem action='Close'/>" + " <toolitem action='Continue'/>" + " </toolbar>" + "</ui>"; + GtkActionEntry action_entries[] = { + { "Continue", GTK_STOCK_GO_FORWARD, "_Continue", "F9", + "Continue", G_CALLBACK (continue_cb) }, + { "Close", GTK_STOCK_CLOSE, "_Close", "<control>W", + "Close the view", G_CALLBACK (close_view_cb) }, + }; + GtkWidget *window, *vbox, *w; + SurfaceView *sv; + GtkUIManager *ui_manager; + GtkActionGroup *action_group; + GError *error = NULL; + + window = gtk_window_new (GTK_WINDOW_TOPLEVEL); + g_object_set_data (G_OBJECT (window), "sphinx", sphinx); + gtk_window_set_transient_for (GTK_WINDOW (window), + GTK_WINDOW (sphinx->window)); + gtk_window_set_default_size (GTK_WINDOW (window), 128, 128); + g_signal_connect (window, "delete-event", + G_CALLBACK (_delete_surface), sphinx); + + vbox = gtk_vbox_new (FALSE, 0); + gtk_container_add (GTK_CONTAINER (window), vbox); + gtk_widget_show (vbox); + + action_group = gtk_action_group_new ("ViewActions"); + gtk_action_group_add_actions (action_group, action_entries, + G_N_ELEMENTS (action_entries), window); + + ui_manager = gtk_ui_manager_new (); + gtk_ui_manager_insert_action_group (ui_manager, action_group, 0); + g_object_unref (action_group); + + if (! gtk_ui_manager_add_ui_from_string (ui_manager, ui_xml, -1, &error)) { + g_error ("%s", error->message); + } + + gtk_window_add_accel_group (GTK_WINDOW (sphinx->window), + gtk_ui_manager_get_accel_group (ui_manager)); + + w = gtk_ui_manager_get_widget (ui_manager, "/ToolBar"); + gtk_box_pack_start (GTK_BOX (vbox), w, FALSE, FALSE, 0); + gtk_widget_show (w); + + sv = g_object_new (surface_view_get_type (), NULL); + gtk_box_pack_start (GTK_BOX (vbox), &sv->widget, TRUE, TRUE, 0); + gtk_widget_show (&sv->widget); + + gtk_window_present (GTK_WINDOW (window)); + + return sv; +} + static void _destroy_surface (void *closure, cairo_surface_t *surface, @@ -605,69 +718,41 @@ _destroy_surface (void *closure, return; } - sphinx_run_break (sphinx); - if (sphinx->view == NULL) { - const gchar *ui_xml = - "<ui>" - " <toolbar name='ToolBar'>" - " <toolitem action='Close'/>" - " <toolitem action='Continue'/>" - " </toolbar>" - "</ui>"; - GtkActionEntry action_entries[] = { - { "Continue", GTK_STOCK_GO_FORWARD, "_Continue", "F9", - "Continue", G_CALLBACK (continue_cb) }, - { "Close", GTK_STOCK_CLOSE, "_Close", "<control>W", - "Close the view", G_CALLBACK (close_view_cb) }, - }; - GtkWidget *window, *vbox, *w; - SurfaceView *sv; - GtkUIManager *ui_manager; - GtkActionGroup *action_group; - GError *error = NULL; - - window = gtk_window_new (GTK_WINDOW_TOPLEVEL); - g_object_set_data (G_OBJECT (window), "sphinx", sphinx); - gtk_window_set_transient_for (GTK_WINDOW (window), - GTK_WINDOW (sphinx->window)); - gtk_window_set_default_size (GTK_WINDOW (window), 128, 128); - g_signal_connect (window, "delete-event", - G_CALLBACK (_delete_surface), sphinx); - - vbox = gtk_vbox_new (FALSE, 0); - gtk_container_add (GTK_CONTAINER (window), vbox); - gtk_widget_show (vbox); - - action_group = gtk_action_group_new ("ViewActions"); - gtk_action_group_add_actions (action_group, action_entries, - G_N_ELEMENTS (action_entries), window); - - ui_manager = gtk_ui_manager_new (); - gtk_ui_manager_insert_action_group (ui_manager, action_group, 0); - g_object_unref (action_group); - - if (! gtk_ui_manager_add_ui_from_string (ui_manager, ui_xml, -1, &error)) { - g_error ("%s", error->message); - } + GDK_THREADS_ENTER (); - gtk_window_add_accel_group (GTK_WINDOW (sphinx->window), - gtk_ui_manager_get_accel_group (ui_manager)); + if (sphinx->watch_surfaces) { + if (sphinx->view == NULL) + sphinx->view = _create_surface_view (sphinx); - w = gtk_ui_manager_get_widget (ui_manager, "/ToolBar"); - gtk_box_pack_start (GTK_BOX (vbox), w, FALSE, FALSE, 0); - gtk_widget_show (w); + surface_view_set_surface (sphinx->view, surface); + } - sv = g_object_new (surface_view_get_type (), NULL); - gtk_box_pack_start (GTK_BOX (vbox), &sv->widget, TRUE, TRUE, 0); - gtk_widget_show (&sv->widget); + if (sphinx->break_on_surface_undef) + sphinx_run_break (sphinx); - gtk_window_present (GTK_WINDOW (window)); - sphinx->view = sv; + GDK_THREADS_LEAVE (); +} + +static void +_destroy_context (void *closure, + cairo_t *cr, + csi_object_t *dictionary) +{ + sphinx_t *sphinx = closure; + + GDK_THREADS_ENTER (); + + if (sphinx->watch_contexts) { + if (sphinx->view == NULL) + sphinx->view = _create_surface_view (sphinx); + + surface_view_set_surface (sphinx->view, cairo_get_target (cr)); } - cairo_surface_destroy (sphinx->view->surface); - sphinx->view->surface = cairo_surface_reference (surface); - gtk_widget_queue_resize (&sphinx->view->widget); + if (sphinx->break_on_context_undef) + sphinx_run_break (sphinx); + + GDK_THREADS_LEAVE (); } static void @@ -716,6 +801,11 @@ sphinx_new (void) " <menuitem action='Stop'/>" " <menuitem action='Step'/>" " <menuitem action='Reset'/>" + " <separator/>" + " <menuitem action='BreakSurface'/>" + " <menuitem action='BreakContext'/>" + " <menuitem action='WatchSurfaces'/>" + " <menuitem action='WatchContexts'/>" " </menu>" " </menubar>" "</ui>"; @@ -753,6 +843,14 @@ sphinx_new (void) GtkToggleActionEntry toggle_entries[] = { { "ViewNumbers", NULL, "Show line _numbers", NULL, "", G_CALLBACK (numbers_toggled_cb), TRUE }, + { "BreakSurface", NULL, "Break after Surface undef", NULL, + "", G_CALLBACK (break_surface_cb), FALSE}, + { "BreakContext", NULL, "Break after Context undef", NULL, + "", G_CALLBACK (break_context_cb), FALSE }, + { "WatchSurfaces", NULL, "Update view after Surface undef", NULL, + "", G_CALLBACK (watch_surface_cb), FALSE}, + { "WatchContexts", NULL, "Update view after Context undef", NULL, + "", G_CALLBACK (watch_context_cb), TRUE }, }; sphinx_t *sphinx; @@ -773,6 +871,11 @@ sphinx_new (void) sphinx->csi = csi_create (); csi_set_surface_create_function (sphinx->csi, _create_surface, sphinx); csi_set_surface_destroy_function (sphinx->csi, _destroy_surface, sphinx); + csi_set_context_destroy_function (sphinx->csi, _destroy_context, sphinx); + sphinx->break_on_surface_undef = FALSE; + sphinx->break_on_context_undef = FALSE; + sphinx->watch_surfaces = FALSE; + sphinx->watch_contexts = TRUE; sphinx->gconf = gconf_client_get_default (); gconf_client_add_dir (sphinx->gconf, GCONF_DIR, @@ -1119,9 +1222,6 @@ sphinx_run_step (sphinx_t *sphinx) sphinx->run_start = sphinx->run_end; } - gtk_text_view_scroll_to_iter (GTK_TEXT_VIEW (sphinx->tv), &iter, .0, - TRUE, 0., 1.); - str = gtk_text_iter_get_text (&iter, &sphinx->run_start); csi_feed_string (sphinx->csi, str, -1); g_free (str); @@ -1167,6 +1267,10 @@ sphinx_run_break (sphinx_t *sphinx) g_source_remove (sphinx->run_continue); sphinx->run_continue = 0; } + + gtk_text_view_scroll_to_iter (GTK_TEXT_VIEW (sphinx->tv), + &sphinx->run_start, .0, + TRUE, 0., 1.); } int diff --git a/src/sphinx.h b/src/sphinx.h index f4e1051..a4eede1 100644 --- a/src/sphinx.h +++ b/src/sphinx.h @@ -56,6 +56,11 @@ typedef struct _sphinx { GtkTextIter run_end; guint run_continue; + gboolean break_on_surface_undef; + gboolean break_on_context_undef; + gboolean watch_surfaces; + gboolean watch_contexts; + SurfaceView *view; } sphinx_t; |