N_COLS
};
-static void on_dwgarea_realize (GtkWidget *widget, gpointer data);
-
static gboolean
draw_callback (GtkWidget *widget, cairo_t *cr, gpointer data)
{
- struct psppire_output_view *view = data;
struct xr_rendering *r = g_object_get_data (G_OBJECT (widget), "rendering");
-
- const GtkStyle *style = gtk_widget_get_style (GTK_WIDGET (view->output));
-
- PangoFontDescription *font_desc;
- char *font_name;
-
- gchar *fgc =
- gdk_color_to_string (&style->text[gtk_widget_get_state (GTK_WIDGET (view->output))]);
-
- string_map_replace (&view->render_opts, "foreground-color", fgc);
-
- free (fgc);
-
- /* Use GTK+ default font as proportional font. */
- font_name = pango_font_description_to_string (style->font_desc);
- string_map_replace (&view->render_opts, "prop-font", font_name);
- g_free (font_name);
-
- /* Derived emphasized font from proportional font. */
- font_desc = pango_font_description_copy (style->font_desc);
- pango_font_description_set_style (font_desc, PANGO_STYLE_ITALIC);
- font_name = pango_font_description_to_string (font_desc);
- string_map_replace (&view->render_opts, "emph-font", font_name);
- g_free (font_name);
- pango_font_description_free (font_desc);
-
- xr_rendering_apply_options (r, &view->render_opts);
-
xr_rendering_draw_all (r, cr);
-
return TRUE;
}
static void
create_xr (struct psppire_output_view *view)
{
- const GtkStyle *style = gtk_widget_get_style (GTK_WIDGET (view->output));
struct text_item *text_item;
PangoFontDescription *font_desc;
struct xr_rendering *r;
cairo_t *cr;
gchar *fgc;
+ GtkStyleContext *context = gtk_widget_get_style_context (GTK_WIDGET (view->output));
+ GtkStateFlags state = gtk_widget_get_state_flags (GTK_WIDGET (view->output));
+ GdkRGBA *fg_color;
+
+ gtk_style_context_get (context, state,
+ "font", &font_desc, "color", &fg_color, NULL);
+
cr = gdk_cairo_create (gtk_widget_get_window (GTK_WIDGET (view->output)));
/* Set the widget's text color as the foreground color for the output driver */
- fgc = gdk_color_to_string (&style->text[gtk_widget_get_state (GTK_WIDGET (view->output))]);
-
+ /* gdk_rgba_to_string() would be perfect, but xr's parse_color does not */
+ /* understand the rgb(255,128,33) format. Therefore we do it ourself. */
+ fgc = xasprintf("#%4x%4x%4x",(int)(fg_color->red*0xffff),
+ (int)(fg_color->green*0xffff),(int)(fg_color->blue*0xffff));
string_map_insert (&view->render_opts, "foreground-color", fgc);
g_free (fgc);
+ gdk_rgba_free (fg_color);
/* Use GTK+ default font as proportional font. */
- font_name = pango_font_description_to_string (style->font_desc);
+ font_name = pango_font_description_to_string (font_desc);
string_map_insert (&view->render_opts, "prop-font", font_name);
g_free (font_name);
/* Derived emphasized font from proportional font. */
- font_desc = pango_font_description_copy (style->font_desc);
pango_font_description_set_style (font_desc, PANGO_STYLE_ITALIC);
font_name = pango_font_description_to_string (font_desc);
string_map_insert (&view->render_opts, "emph-font", font_name);
text_item = text_item_create (TEXT_ITEM_PARAGRAPH, "X");
r = xr_rendering_create (view->xr, text_item_super (text_item), cr);
xr_rendering_measure (r, &font_width, &view->font_height);
- /* xr_rendering_destroy (r); */
text_item_unref (text_item);
cairo_destroy (cr);
g_object_set_data_full (G_OBJECT (drawing_area),
"rendering", r, free_rendering);
- g_signal_connect (drawing_area, "realize",
- G_CALLBACK (on_dwgarea_realize), view);
g_signal_connect (drawing_area, "draw",
G_CALLBACK (draw_callback), view);
if (!view->n_items || !gtk_widget_get_window (GTK_WIDGET (view->output)))
return;
- string_map_clear (&view->render_opts);
- xr_driver_destroy (view->xr);
- create_xr (view);
-
cr = gdk_cairo_create (gtk_widget_get_window (GTK_WIDGET (view->output)));
view->y = 0;
}
static void
-copy_base_to_bg (GtkWidget *dest, GtkWidget *src)
-{
- int i;
- for (i = 0; i < 5; ++i)
- {
- gtk_widget_modify_bg (dest, i, >k_widget_get_style (src)->base[i]);
- gtk_widget_modify_fg (dest, i, >k_widget_get_style (src)->text[i]);
- }
-}
-
-/* Copy the base style from the parent widget to the container and all its
- children. We do this because the container's primary purpose is to display
- text. This way psppire appears to follow the chosen gnome theme. */
-static void
-on_style_set (GtkWidget *toplevel, GtkStyle *prev,
- struct psppire_output_view *view)
-{
- copy_base_to_bg (GTK_WIDGET (view->output), toplevel);
- gtk_container_foreach (GTK_CONTAINER (view->output),
- (GtkCallback) copy_base_to_bg, view->output);
-}
-
-static void
-on_dwgarea_realize (GtkWidget *dwg_area, gpointer data)
+on_style_updated (GtkWidget *toplevel, struct psppire_output_view *view)
{
- copy_base_to_bg (dwg_area, gtk_widget_get_toplevel (dwg_area));
+ if (!view->n_items || !gtk_widget_get_window (GTK_WIDGET (view->output)))
+ return;
+ string_map_clear (&view->render_opts);
+ xr_driver_destroy (view->xr);
+ create_xr (view);
+ rerender (view);
}
enum {
struct psppire_output_view *view)
{
int new_render_width = MAX (300, allocation->width);
+
if (view->render_width != new_render_width)
{
view->render_width = new_render_width;
view->print_n_pages = 0;
view->paginated = FALSE;
- g_signal_connect (view->toplevel, "style-set", G_CALLBACK (on_style_set), view);
+ g_signal_connect (output, "style-updated", G_CALLBACK (on_style_updated), view);
g_signal_connect (output, "size-allocate", G_CALLBACK (on_size_allocate), view);
+ gtk_style_context_add_class (gtk_widget_get_style_context (GTK_WIDGET (output)),
+ GTK_STYLE_CLASS_VIEW);
+
if (overview)
{
model = GTK_TREE_MODEL (gtk_tree_store_new (
if (!view)
return;
- g_signal_handlers_disconnect_by_func (view->toplevel,
- G_CALLBACK (on_style_set), view);
+ g_signal_handlers_disconnect_by_func (view->output,
+ G_CALLBACK (on_style_updated), view);
string_map_destroy (&view->render_opts);
view->items = NULL;
view->n_items = view->allocated_items = 0;
}
-\f
+
/* Export. */
void