summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChris Wilson <chris@chris-wilson.co.uk>2008-11-05 01:24:12 +0000
committerChris Wilson <chris@chris-wilson.co.uk>2008-11-05 01:24:12 +0000
commit5087e0420821687a0c8d6bd9e648cc9fc10ab181 (patch)
treefe7168672eaf69abe603aff44a29fad14ad6ccb1
parent0f57262e739af7584f072a100f58fa8b67eff9f4 (diff)
Make the view permanent.
-rw-r--r--src/cairoscript.lang7
-rw-r--r--src/main.c129
-rw-r--r--src/sphinx.h13
3 files changed, 89 insertions, 60 deletions
diff --git a/src/cairoscript.lang b/src/cairoscript.lang
index 9b8e4b5..e6ae1f3 100644
--- a/src/cairoscript.lang
+++ b/src/cairoscript.lang
@@ -128,8 +128,12 @@
<keyword>scale</keyword>
<keyword>set_antialias</keyword>
<keyword>set_dash</keyword>
- <keyword>set_fill_rule</keyword>
<keyword>set_device_offset</keyword>
+ <keyword>set_extend</keyword>
+ <keyword>set_filter</keyword>
+ <keyword>set_fill_rule</keyword>
+ <keyword>set_font_face</keyword>
+ <keyword>set_font_matrix</keyword>
<keyword>set_line_cap</keyword>
<keyword>set_line_join</keyword>
<keyword>set_line_width</keyword>
@@ -138,6 +142,7 @@
<keyword>set_matrix</keyword>
<keyword>set_scaled_font</keyword>
<keyword>set_source</keyword>
+ <keyword>set_source_image</keyword>
<keyword>show_glyphs</keyword>
<keyword>show_text_glyphs</keyword>
<keyword>stroke\+?</keyword>
diff --git a/src/main.c b/src/main.c
index 4bfed54..517835d 100644
--- a/src/main.c
+++ b/src/main.c
@@ -509,16 +509,6 @@ _create_surface (void *closure,
return cairo_image_surface_create (CAIRO_FORMAT_ARGB32, width, height);
}
-typedef struct _SurfaceView {
- GtkWidget widget;
-
- cairo_surface_t *surface;
-} SurfaceView;
-
-typedef struct _SurfaceViewClass {
- GtkWidgetClass parent_class;
-} SurfaceViewClass;
-
static GType surface_view_get_type (void);
G_DEFINE_TYPE (SurfaceView, surface_view, GTK_TYPE_WIDGET)
@@ -545,8 +535,11 @@ surface_view_size_request (GtkWidget *w, GtkRequisition *req)
{
SurfaceView *self = (SurfaceView *) w;
- req->width = cairo_image_surface_get_width (self->surface);
- req->height = cairo_image_surface_get_height (self->surface);
+ if (self->surface != NULL) {
+ req->width = cairo_image_surface_get_width (self->surface);
+ req->height = cairo_image_surface_get_height (self->surface);
+ } else
+ req->width = req->height = 1;
}
static void
@@ -582,6 +575,7 @@ _delete_surface (GtkWidget *w, GdkEvent *ev, sphinx_t *sphinx)
{
gtk_widget_destroy (w);
sphinx_run_continue (sphinx);
+ sphinx->view = NULL;
return TRUE;
}
@@ -593,26 +587,17 @@ close_view_cb (GtkAction *action, GtkWidget *window)
}
static void
+continue_cb (GtkAction *action, GtkWidget *window)
+{
+ sphinx_run_continue (g_object_get_data (G_OBJECT (window), "sphinx"));
+}
+
+static void
_destroy_surface (void *closure,
cairo_surface_t *surface,
csi_object_t *dictionary)
{
- const gchar *ui_xml =
- "<ui>"
- " <toolbar name='ToolBar'>"
- " <toolitem action='Close'/>"
- " </toolbar>"
- "</ui>";
- GtkActionEntry action_entries[] = {
- { "Close", GTK_STOCK_CLOSE, "_Close", "<control>W",
- "Close the view", G_CALLBACK (close_view_cb) },
- };
sphinx_t *sphinx = closure;
- GtkWidget *window, *vbox, *w;
- SurfaceView *sv;
- GtkUIManager *ui_manager;
- GtkActionGroup *action_group;
- GError *error = NULL;
if (cairo_image_surface_get_width (surface) == 0 ||
cairo_image_surface_get_height (surface) == 0)
@@ -621,43 +606,68 @@ _destroy_surface (void *closure,
}
sphinx_run_break (sphinx);
- 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 (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);
+ }
- 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));
- 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);
- 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);
- sv = g_object_new (surface_view_get_type (), NULL);
- sv->surface = cairo_surface_reference (surface);
- gtk_box_pack_start (GTK_BOX (vbox), &sv->widget, TRUE, TRUE, 0);
- gtk_widget_show (&sv->widget);
+ gtk_window_present (GTK_WINDOW (window));
+ sphinx->view = sv;
+ }
- gtk_window_present (GTK_WINDOW (window));
+ cairo_surface_destroy (sphinx->view->surface);
+ sphinx->view->surface = cairo_surface_reference (surface);
+ gtk_widget_queue_resize (&sphinx->view->widget);
}
static void
@@ -813,6 +823,7 @@ sphinx_new (void)
gtk_widget_show (sw);
w = gtk_source_view_new ();
+ gtk_widget_set_size_request (w, 80*14, -1);
gtk_text_view_set_wrap_mode (GTK_TEXT_VIEW (w), GTK_WRAP_WORD_CHAR);
gtk_source_view_set_show_line_numbers (GTK_SOURCE_VIEW (w), TRUE);
gtk_source_view_set_show_line_marks (GTK_SOURCE_VIEW (w), TRUE);
diff --git a/src/sphinx.h b/src/sphinx.h
index e6fa306..f4e1051 100644
--- a/src/sphinx.h
+++ b/src/sphinx.h
@@ -27,6 +27,17 @@
G_BEGIN_DECLS
+typedef struct _SurfaceView {
+ GtkWidget widget;
+
+ cairo_surface_t *surface;
+} SurfaceView;
+
+typedef struct _SurfaceViewClass {
+ GtkWidgetClass parent_class;
+} SurfaceViewClass;
+
+
typedef struct _sphinx {
GtkWidget *window;
@@ -44,6 +55,8 @@ typedef struct _sphinx {
GtkTextIter run_start;
GtkTextIter run_end;
guint run_continue;
+
+ SurfaceView *view;
} sphinx_t;
G_END_DECLS