]> git.sur5r.net Git - glabels/commitdiff
2009-09-02 Jim Evins <evins@snaught.com>
authorJim Evins <evins@snaught.com>
Thu, 3 Sep 2009 02:47:51 +0000 (02:47 +0000)
committerJim Evins <evins@snaught.com>
Thu, 3 Sep 2009 02:47:51 +0000 (02:47 +0000)
* src/Makefile.am:
* src/wdgt-mini-preview.c:
* src/wdgt-mini-preview.h:
* src/mini-preview.h:
* src/mini-preview.c:
- Renamed WdgtMiniPreview to MiniPreview.
- Style cleanup.
- Modified to draw to parent window to be effectively transparent.
- Updated license notification to gpl3+.
* src/template-designer.c: (construct_layout_page),
(layout_page_prepare_cb), (layout_page_changed_cb):
* src/wdgt-print-copies.c: (gl_wdgt_print_copies_construct),
(sheets_radio_cb), (first_spin_cb), (last_spin_cb),
(preview_pressed):
* src/wdgt-print-merge.c: (gl_wdgt_print_merge_construct),
(spin_cb), (preview_clicked), (gl_wdgt_print_merge_set_copies):
- Reconciled with rename above.

git-svn-id: https://glabels.svn.sourceforge.net/svnroot/glabels/trunk@868 f5e0f49d-192f-0410-a22d-a8d8700d0965

glabels2/ChangeLog
glabels2/src/Makefile.am
glabels2/src/mini-preview.c [new file with mode: 0644]
glabels2/src/mini-preview.h [new file with mode: 0644]
glabels2/src/template-designer.c
glabels2/src/wdgt-mini-preview.c [deleted file]
glabels2/src/wdgt-mini-preview.h [deleted file]
glabels2/src/wdgt-print-copies.c
glabels2/src/wdgt-print-merge.c

index bffc82fd3220fa6aeb8deadf5f6f955f1ca3088f..2db7c97598330193811f82202f79ce03958cc878 100644 (file)
@@ -1,3 +1,23 @@
+2009-09-02  Jim Evins  <evins@snaught.com>
+
+       * src/Makefile.am:
+       * src/wdgt-mini-preview.c:
+       * src/wdgt-mini-preview.h:
+       * src/mini-preview.h:
+       * src/mini-preview.c:
+               - Renamed WdgtMiniPreview to MiniPreview.
+               - Style cleanup.
+               - Modified to draw to parent window to be effectively transparent.
+               - Updated license notification to gpl3+.
+       * src/template-designer.c: (construct_layout_page),
+       (layout_page_prepare_cb), (layout_page_changed_cb):
+       * src/wdgt-print-copies.c: (gl_wdgt_print_copies_construct),
+       (sheets_radio_cb), (first_spin_cb), (last_spin_cb),
+       (preview_pressed):
+       * src/wdgt-print-merge.c: (gl_wdgt_print_merge_construct),
+       (spin_cb), (preview_clicked), (gl_wdgt_print_merge_set_copies):
+               - Reconciled with rename above.
+
 2009-09-01  Jim Evins  <evins@snaught.com>
 
        * data/builder/object-editor.builder:
index da5c4de8373f4c8516470d8790cbc41f7b37cf84..bbe278fadff352d58e2c0b6fb65d2924df4b1048 100644 (file)
@@ -171,8 +171,8 @@ glabels_SOURCES =                   \
        wdgt-print-merge.h              \
        wdgt-media-select.c             \
        wdgt-media-select.h             \
-       wdgt-mini-preview.c             \
-       wdgt-mini-preview.h             \
+       mini-preview.c                  \
+       mini-preview.h                  \
        wdgt-rotate-label.c             \
        wdgt-rotate-label.h             \
        wdgt-chain-button.c             \
@@ -268,8 +268,8 @@ glabels_batch_SOURCES =             \
        wdgt-print-copies.h             \
        wdgt-print-merge.c              \
        wdgt-print-merge.h              \
-       wdgt-mini-preview.c             \
-       wdgt-mini-preview.h             \
+       mini-preview.c                  \
+       mini-preview.h                  \
        hig.h                           \
        cairo-label-path.c              \
        cairo-label-path.h              \
diff --git a/glabels2/src/mini-preview.c b/glabels2/src/mini-preview.c
new file mode 100644 (file)
index 0000000..26ff50c
--- /dev/null
@@ -0,0 +1,777 @@
+/*
+ *  mini-preview.c
+ *  Copyright (C) 2001-2009  Jim Evins <evins@snaught.com>.
+ *
+ *  This file is part of gLabels.
+ *
+ *  gLabels is free software: you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation, either version 3 of the License, or
+ *  (at your option) any later version.
+ *
+ *  gLabels is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with gLabels.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include <config.h>
+
+#include "mini-preview.h"
+
+#include <math.h>
+
+#include "libglabels/db.h"
+#include "cairo-label-path.h"
+#include "marshal.h"
+#include "color.h"
+
+#include "debug.h"
+
+
+/*===========================================*/
+/* Private macros and constants.             */
+/*===========================================*/
+
+#define PAPER_RGB_ARGS          1.0,   1.0,   1.0
+#define PAPER_OUTLINE_RGB_ARGS  0.0,   0.0,   0.0
+#define LABEL_OUTLINE_RGB_ARGS  0.5,   0.5,   0.5
+
+#define SHADOW_X_OFFSET 5
+#define SHADOW_Y_OFFSET 5
+
+
+/*===========================================*/
+/* Private types                             */
+/*===========================================*/
+
+enum {
+       CLICKED,
+       PRESSED,
+       LAST_SIGNAL
+};
+
+typedef struct {
+       gdouble x;
+       gdouble y;
+} LabelCenter;
+
+struct _glMiniPreviewPrivate {
+
+        GtkWidget      *canvas;
+
+       gint            height;
+       gint            width;
+
+       lglTemplate    *template;
+       gdouble         scale;
+       gdouble         offset_x;
+       gdouble         offset_y;
+       gint            labels_per_sheet;
+       LabelCenter    *centers;
+
+       gint            highlight_first;
+       gint            highlight_last;
+
+       gboolean        dragging;
+       gint            first_i;
+       gint            last_i;
+       gint            prev_i;
+};
+
+
+/*===========================================*/
+/* Private globals                           */
+/*===========================================*/
+
+static gint mini_preview_signals[LAST_SIGNAL] = { 0 };
+
+
+/*===========================================*/
+/* Local function prototypes                 */
+/*===========================================*/
+
+static void     gl_mini_preview_finalize       (GObject                *object);
+
+static void     gl_mini_preview_construct      (glMiniPreview          *this,
+                                               gint                    height,
+                                               gint                    width);
+
+static gboolean button_press_event_cb          (GtkWidget              *widget,
+                                               GdkEventButton         *event);
+static gboolean motion_notify_event_cb         (GtkWidget              *widget,
+                                               GdkEventMotion         *event);
+static gboolean button_release_event_cb        (GtkWidget              *widget,
+                                               GdkEventButton         *event);
+
+
+static gboolean expose_event_cb                (GtkWidget              *widget,
+                                               GdkEventExpose         *event,
+                                                glMiniPreview          *this);
+static void     style_set_cb                   (GtkWidget              *widget,
+                                               GtkStyle               *previous_style,
+                                                glMiniPreview          *this);
+
+static void     redraw                         (glMiniPreview          *this);
+static void     draw                           (glMiniPreview          *this,
+                                               cairo_t                *cr);
+
+static void     draw_shadow                    (glMiniPreview          *this,
+                                               cairo_t                *cr,
+                                               gdouble                 x,
+                                               gdouble                 y,
+                                               gdouble                 width,
+                                               gdouble                 height);
+static void     draw_paper                     (glMiniPreview          *this,
+                                               cairo_t                *cr,
+                                               gdouble                 width,
+                                               gdouble                 height,
+                                               gdouble                 line_width);
+static void     draw_labels                    (glMiniPreview          *this,
+                                               cairo_t                *cr,
+                                               lglTemplate            *template,
+                                               gdouble                 line_width);
+
+static gint     find_closest_label             (glMiniPreview          *this,
+                                               gdouble                 x,
+                                               gdouble                 y);
+
+
+/****************************************************************************/
+/* Object infrastructure.                                                   */
+/****************************************************************************/
+G_DEFINE_TYPE (glMiniPreview, gl_mini_preview, GTK_TYPE_EVENT_BOX);
+
+
+/*****************************************************************************/
+/* Class Init Function.                                                      */
+/*****************************************************************************/
+static void
+gl_mini_preview_class_init (glMiniPreviewClass *class)
+{
+       GObjectClass   *object_class = G_OBJECT_CLASS (class);
+       GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (class);
+
+       gl_debug (DEBUG_MINI_PREVIEW, "START");
+
+       gl_mini_preview_parent_class = g_type_class_peek_parent (class);
+
+       object_class->finalize = gl_mini_preview_finalize;
+
+       widget_class->button_press_event   = button_press_event_cb;
+       widget_class->motion_notify_event  = motion_notify_event_cb;
+       widget_class->button_release_event = button_release_event_cb;
+
+       mini_preview_signals[CLICKED] =
+           g_signal_new ("clicked",
+                         G_OBJECT_CLASS_TYPE(object_class),
+                         G_SIGNAL_RUN_LAST,
+                         G_STRUCT_OFFSET (glMiniPreviewClass, clicked),
+                         NULL, NULL,
+                         gl_marshal_VOID__INT,
+                         G_TYPE_NONE, 1, G_TYPE_INT);
+
+       mini_preview_signals[PRESSED] =
+           g_signal_new ("pressed",
+                         G_OBJECT_CLASS_TYPE(object_class),
+                         G_SIGNAL_RUN_LAST,
+                         G_STRUCT_OFFSET (glMiniPreviewClass, pressed),
+                         NULL, NULL,
+                         gl_marshal_VOID__INT_INT,
+                         G_TYPE_NONE, 2, G_TYPE_INT, G_TYPE_INT);
+
+       gl_debug (DEBUG_MINI_PREVIEW, "END");
+}
+
+
+/*****************************************************************************/
+/* Object Instance Init Function.                                            */
+/*****************************************************************************/
+static void
+gl_mini_preview_init (glMiniPreview *this)
+{
+       gl_debug (DEBUG_MINI_PREVIEW, "START");
+
+       this->priv = g_new0 (glMiniPreviewPrivate, 1);
+
+       gtk_widget_add_events (GTK_WIDGET (this),
+                              GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK |
+                              GDK_POINTER_MOTION_MASK);
+
+        gtk_event_box_set_visible_window (GTK_EVENT_BOX (this), FALSE);
+
+        this->priv->canvas = gtk_drawing_area_new ();
+        GTK_WIDGET_SET_FLAGS (this->priv->canvas, GTK_NO_WINDOW);
+        gtk_container_add (GTK_CONTAINER (this), this->priv->canvas);
+
+        g_signal_connect (G_OBJECT (this->priv->canvas), "expose-event",
+                          G_CALLBACK (expose_event_cb), this);
+        g_signal_connect (G_OBJECT (this->priv->canvas), "style-set",
+                          G_CALLBACK (style_set_cb), this);
+
+       gl_debug (DEBUG_MINI_PREVIEW, "END");
+}
+
+
+/*****************************************************************************/
+/* Finalize Method.                                                          */
+/*****************************************************************************/
+static void
+gl_mini_preview_finalize (GObject *object)
+{
+       glMiniPreview *this = GL_MINI_PREVIEW (object);
+
+       gl_debug (DEBUG_MINI_PREVIEW, "START");
+
+       g_return_if_fail (object != NULL);
+       g_return_if_fail (GL_IS_MINI_PREVIEW (object));
+
+       lgl_template_free (this->priv->template);
+       g_free (this->priv->centers);
+       g_free (this->priv);
+
+       G_OBJECT_CLASS (gl_mini_preview_parent_class)->finalize (object);
+
+       gl_debug (DEBUG_MINI_PREVIEW, "END");
+}
+
+
+/*****************************************************************************/
+/** New Object Generator.                                                    */
+/*****************************************************************************/
+GtkWidget *
+gl_mini_preview_new (gint height,
+                     gint width)
+{
+       glMiniPreview *this;
+
+       gl_debug (DEBUG_MINI_PREVIEW, "START");
+
+       this = g_object_new (gl_mini_preview_get_type (), NULL);
+
+       gl_mini_preview_construct (this, height, width);
+
+       gl_debug (DEBUG_MINI_PREVIEW, "END");
+
+       return GTK_WIDGET (this);
+}
+
+
+/*--------------------------------------------------------------------------*/
+/* Construct composite widget.                                              */
+/*--------------------------------------------------------------------------*/
+static void
+gl_mini_preview_construct (glMiniPreview *this,
+                           gint           height,
+                           gint           width)
+{
+       gl_debug (DEBUG_MINI_PREVIEW, "START");
+
+       this->priv->height = height;
+       this->priv->width  = width;
+
+       gtk_widget_set_size_request (GTK_WIDGET (this->priv->canvas), width, height);
+
+       gl_debug (DEBUG_MINI_PREVIEW, "END");
+}
+
+
+/****************************************************************************/
+/* Set label for mini-preview to determine geometry.                        */
+/****************************************************************************/
+void
+gl_mini_preview_set_label_by_name (glMiniPreview *this,
+                                   const gchar   *name)
+{
+       lglTemplate *template;
+
+       gl_debug (DEBUG_MINI_PREVIEW, "START");
+
+       /* Fetch template */
+       template = lgl_db_lookup_template_from_name (name);
+
+       gl_mini_preview_set_template (this, template);
+
+       lgl_template_free (template);
+
+       gl_debug (DEBUG_MINI_PREVIEW, "END");
+}
+
+
+/****************************************************************************/
+/* Set label for mini-preview to determine geometry.                        */
+/****************************************************************************/
+void
+gl_mini_preview_set_template (glMiniPreview     *this,
+                              const lglTemplate *template)
+{
+       const lglTemplateFrame    *frame;
+       lglTemplateOrigin         *origins;
+       gdouble                    w, h;
+       gint                       i;
+
+       gl_debug (DEBUG_MINI_PREVIEW, "START");
+
+        frame = (lglTemplateFrame *)template->frames->data;
+
+       /*
+        * Set template
+        */
+       lgl_template_free (this->priv->template);
+       this->priv->template = lgl_template_dup (template);
+
+       /*
+        * Set scale and offsets
+        */
+       w = this->priv->width - 4 - 2*SHADOW_X_OFFSET;
+       h = this->priv->height - 4 - 2*SHADOW_Y_OFFSET;
+       if ( (w/template->page_width) > (h/template->page_height) ) {
+               this->priv->scale = h / template->page_height;
+       } else {
+               this->priv->scale = w / template->page_width;
+       }
+       this->priv->offset_x = (this->priv->width/this->priv->scale - template->page_width) / 2.0;
+       this->priv->offset_y = (this->priv->height/this->priv->scale - template->page_height) / 2.0;
+
+       /*
+        * Set labels per sheet
+        */
+       this->priv->labels_per_sheet = lgl_template_frame_get_n_labels (frame);
+
+       /*
+        * Initialize centers
+        */
+       g_free (this->priv->centers);
+       this->priv->centers = g_new0 (LabelCenter, this->priv->labels_per_sheet);
+       origins = lgl_template_frame_get_origins (frame);
+       lgl_template_frame_get_size (frame, &w, &h);
+       for ( i=0; i<this->priv->labels_per_sheet; i++ )
+       {
+               this->priv->centers[i].x = origins[i].x + w/2.0;
+               this->priv->centers[i].y = origins[i].y + h/2.0;
+       }
+       g_free (origins);
+
+       /*
+        * Redraw modified preview
+        */
+       redraw (this);
+
+       gl_debug (DEBUG_MINI_PREVIEW, "END");
+}
+
+
+/****************************************************************************/
+/* Highlight given label outlines.                                          */
+/****************************************************************************/
+void
+gl_mini_preview_highlight_range (glMiniPreview *this,
+                                 gint           first_label,
+                                 gint           last_label)
+{
+       gl_debug (DEBUG_MINI_PREVIEW, "START");
+
+       this->priv->highlight_first = first_label;
+       this->priv->highlight_last =  last_label;
+
+       redraw (this);
+
+       gl_debug (DEBUG_MINI_PREVIEW, "END");
+}
+
+
+/*--------------------------------------------------------------------------*/
+/* Button press event handler                                               */
+/*--------------------------------------------------------------------------*/
+static gboolean
+button_press_event_cb (GtkWidget      *widget,
+                      GdkEventButton *event)
+{
+       glMiniPreview     *this = GL_MINI_PREVIEW (widget);
+       cairo_t           *cr;
+       gdouble            x, y;
+       gint               i;
+
+       gl_debug (DEBUG_MINI_PREVIEW, "START");
+
+       if ( event->button == 1 )
+       {
+               cr = gdk_cairo_create (GTK_WIDGET (this->priv->canvas)->window);
+
+               /* Set transformation. */
+               cairo_scale (cr, this->priv->scale, this->priv->scale);
+               cairo_translate (cr, this->priv->offset_x, this->priv->offset_y);
+
+               x = event->x;
+               y = event->y;
+               cairo_device_to_user (cr, &x, &y);
+
+               i = find_closest_label (this, x, y);
+
+               g_signal_emit (G_OBJECT(this),
+                              mini_preview_signals[CLICKED],
+                              0, i);
+
+               this->priv->first_i = i;
+               this->priv->last_i  = i;
+               g_signal_emit (G_OBJECT(this),
+                              mini_preview_signals[PRESSED],
+                              0, this->priv->first_i, this->priv->last_i);
+
+               this->priv->dragging = TRUE;
+               this->priv->prev_i   = i;
+
+               cairo_destroy (cr);
+       }
+
+       gl_debug (DEBUG_MINI_PREVIEW, "END");
+       return FALSE;
+}
+
+
+/*--------------------------------------------------------------------------*/
+/* Motion notify event handler                                              */
+/*--------------------------------------------------------------------------*/
+static gboolean
+motion_notify_event_cb (GtkWidget      *widget,
+                       GdkEventMotion *event)
+{
+       glMiniPreview *this = GL_MINI_PREVIEW (widget);
+       cairo_t           *cr;
+       gdouble            x, y;
+       gint               i;
+
+       gl_debug (DEBUG_MINI_PREVIEW, "START");
+
+       if (this->priv->dragging)
+       {
+               cr = gdk_cairo_create (GTK_WIDGET (this->priv->canvas)->window);
+
+               /* Set transformation. */
+               cairo_scale (cr, this->priv->scale, this->priv->scale);
+               cairo_translate (cr, this->priv->offset_x, this->priv->offset_y);
+
+               x = event->x;
+               y = event->y;
+               cairo_device_to_user (cr, &x, &y);
+
+               i = find_closest_label (this, x, y);
+
+               if ( i != this->priv->prev_i )
+               {
+                       this->priv->last_i = i;
+
+                       g_signal_emit (G_OBJECT(this),
+                                      mini_preview_signals[PRESSED],
+                                      0,
+                                      MIN (this->priv->first_i, this->priv->last_i),
+                                      MAX (this->priv->first_i, this->priv->last_i));
+
+                       this->priv->prev_i = i;
+               }
+               cairo_destroy (cr);
+       }
+
+       gl_debug (DEBUG_MINI_PREVIEW, "END");
+       return FALSE;
+}
+
+
+/*--------------------------------------------------------------------------*/
+/* Button release event handler                                             */
+/*--------------------------------------------------------------------------*/
+static gboolean
+button_release_event_cb (GtkWidget      *widget,
+                        GdkEventButton *event)
+{
+       glMiniPreview *this = GL_MINI_PREVIEW (widget);
+       
+       gl_debug (DEBUG_MINI_PREVIEW, "START");
+
+       if ( event->button == 1 )
+       {
+               this->priv->dragging = FALSE;
+
+       }
+
+       gl_debug (DEBUG_MINI_PREVIEW, "END");
+       return FALSE;
+}
+
+
+/*--------------------------------------------------------------------------*/
+/* Find index+1 of label closest to given coordinates.                      */
+/*--------------------------------------------------------------------------*/
+static gint
+find_closest_label (glMiniPreview      *this,
+                   gdouble             x,
+                   gdouble             y)
+{
+       gint    i;
+       gint    min_i;
+       gdouble dx, dy, d2, min_d2;
+
+       dx = x - this->priv->centers[0].x;
+       dy = y - this->priv->centers[0].y;
+       min_d2 = dx*dx + dy*dy;
+       min_i = 0;
+
+       for ( i=1; i<this->priv->labels_per_sheet; i++ )
+       {
+               dx = x - this->priv->centers[i].x;
+               dy = y - this->priv->centers[i].y;
+               d2 = dx*dx + dy*dy;
+
+               if ( d2 < min_d2 )
+               {
+                       min_d2 = d2;
+                       min_i  = i;
+               }
+       }
+
+       return min_i + 1;
+}
+
+
+/*--------------------------------------------------------------------------*/
+/* Expose event handler.                                                    */
+/*--------------------------------------------------------------------------*/
+static gboolean
+expose_event_cb (GtkWidget       *widget,
+                GdkEventExpose  *event,
+                 glMiniPreview   *this)
+{
+       cairo_t       *cr;
+
+       gl_debug (DEBUG_MINI_PREVIEW, "START");
+
+       cr = gdk_cairo_create (widget->window);
+
+       cairo_rectangle (cr,
+                       event->area.x, event->area.y,
+                       event->area.width, event->area.height);
+       cairo_clip (cr);
+        cairo_translate (cr, widget->allocation.x, widget->allocation.y);
+       
+       draw (this, cr);
+
+       cairo_destroy (cr);
+
+       gl_debug (DEBUG_MINI_PREVIEW, "END");
+       return FALSE;
+}
+
+
+/*--------------------------------------------------------------------------*/
+/* Style set handler (updates colors when style/theme changes).             */
+/*--------------------------------------------------------------------------*/
+static void
+style_set_cb (GtkWidget        *widget,
+             GtkStyle         *previous_style,
+              glMiniPreview    *this)
+{
+       gl_debug (DEBUG_MINI_PREVIEW, "START");
+
+       redraw (this);
+
+       gl_debug (DEBUG_MINI_PREVIEW, "END");
+}
+
+
+/*--------------------------------------------------------------------------*/
+/* Redraw.                                                                  */
+/*--------------------------------------------------------------------------*/
+static void
+redraw (glMiniPreview      *this)
+{
+       GdkRegion *region;
+       
+       gl_debug (DEBUG_MINI_PREVIEW, "START");
+
+       if (GTK_WIDGET (this->priv->canvas)->window)
+       {
+
+               region = gdk_drawable_get_clip_region (GTK_WIDGET (this->priv->canvas)->window);
+
+               gdk_window_invalidate_region (GTK_WIDGET (this->priv->canvas)->window, region, TRUE);
+               gdk_window_process_updates (GTK_WIDGET (this->priv->canvas)->window, TRUE);
+
+               gdk_region_destroy (region);
+       }
+
+       gl_debug (DEBUG_MINI_PREVIEW, "END");
+}
+
+
+/*--------------------------------------------------------------------------*/
+/* Draw mini preview.                                                       */
+/*--------------------------------------------------------------------------*/
+static void
+draw (glMiniPreview  *this,
+      cairo_t        *cr)
+{
+       lglTemplate *template = this->priv->template;
+       gdouble      shadow_x, shadow_y;
+
+       gl_debug (DEBUG_MINI_PREVIEW, "START");
+
+       if (template)
+       {
+
+               /* Set transformation. */
+               cairo_scale (cr, this->priv->scale, this->priv->scale);
+               cairo_translate (cr, this->priv->offset_x, this->priv->offset_y);
+
+
+               /* update shadow */
+               shadow_x = SHADOW_X_OFFSET/this->priv->scale;
+               shadow_y = SHADOW_Y_OFFSET/this->priv->scale;
+
+               draw_shadow (this, cr,
+                            shadow_x, shadow_y,
+                            template->page_width, template->page_height);
+
+               draw_paper (this, cr,
+                           template->page_width, template->page_height,
+                           1.0/this->priv->scale);
+
+               draw_labels (this, cr, template, 1.0/this->priv->scale);
+                            
+       }
+
+       gl_debug (DEBUG_MINI_PREVIEW, "END");
+
+}
+
+
+/*--------------------------------------------------------------------------*/
+/* Draw page shadow                                                         */
+/*--------------------------------------------------------------------------*/
+static void
+draw_shadow (glMiniPreview      *this,
+            cairo_t            *cr,
+            gdouble             x,
+            gdouble             y,
+            gdouble             width,
+            gdouble             height)
+{
+       GtkStyle *style;
+       guint     shadow_color;
+
+        gl_debug (DEBUG_MINI_PREVIEW, "START");
+
+       cairo_save (cr);
+
+       cairo_rectangle (cr, x, y, width, height);
+
+       style = gtk_widget_get_style (GTK_WIDGET(this));
+       shadow_color = gl_color_from_gdk_color (&style->bg[GTK_STATE_ACTIVE]);
+       cairo_set_source_rgb (cr, GL_COLOR_RGB_ARGS (shadow_color));
+
+        cairo_fill (cr);
+
+        cairo_restore (cr);
+
+        gl_debug (DEBUG_MINI_PREVIEW, "END");
+}
+
+
+/*--------------------------------------------------------------------------*/
+/* Draw page                                                                */
+/*--------------------------------------------------------------------------*/
+static void
+draw_paper (glMiniPreview      *this,
+           cairo_t            *cr,
+           gdouble             width,
+           gdouble             height,
+           gdouble             line_width)
+{
+       cairo_save (cr);
+
+        gl_debug (DEBUG_MINI_PREVIEW, "START");
+
+       cairo_rectangle (cr, 0.0, 0.0, width, height);
+
+       cairo_set_source_rgb (cr, PAPER_RGB_ARGS);
+        cairo_fill_preserve (cr);
+
+       cairo_set_source_rgb (cr, PAPER_OUTLINE_RGB_ARGS);
+       cairo_set_line_width (cr, line_width);
+        cairo_stroke (cr);
+
+        cairo_restore (cr);
+
+        gl_debug (DEBUG_MINI_PREVIEW, "END");
+}
+
+
+/*--------------------------------------------------------------------------*/
+/* Draw labels                                                              */
+/*--------------------------------------------------------------------------*/
+static void
+draw_labels (glMiniPreview *this,
+            cairo_t       *cr,
+            lglTemplate   *template,
+            gdouble        line_width)
+{
+        const lglTemplateFrame    *frame;
+        gint                       i, n_labels;
+        lglTemplateOrigin         *origins;
+       GtkStyle                  *style;
+       guint                      highlight_color;
+
+        gl_debug (DEBUG_MINI_PREVIEW, "START");
+
+        frame = (lglTemplateFrame *)template->frames->data;
+
+        n_labels = lgl_template_frame_get_n_labels (frame);
+        origins  = lgl_template_frame_get_origins (frame);
+
+       style = gtk_widget_get_style (GTK_WIDGET(this));
+       highlight_color = gl_color_from_gdk_color (&style->base[GTK_STATE_SELECTED]);
+
+        for ( i=0; i < n_labels; i++ ) {
+
+               cairo_save (cr);
+
+                cairo_translate (cr, origins[i].x, origins[i].y);
+                gl_cairo_label_path (cr, template, FALSE, FALSE);
+
+               if ( ((i+1) >= this->priv->highlight_first) &&
+                    ((i+1) <= this->priv->highlight_last) )
+               {
+                       cairo_set_source_rgb (cr, GL_COLOR_RGB_ARGS (highlight_color));
+               }
+               else
+               {
+                       cairo_set_source_rgb (cr, PAPER_RGB_ARGS);
+               }
+               cairo_set_fill_rule (cr, CAIRO_FILL_RULE_EVEN_ODD);
+               cairo_fill_preserve (cr);
+
+               cairo_set_line_width (cr, line_width);
+               cairo_set_source_rgb (cr, LABEL_OUTLINE_RGB_ARGS);
+               cairo_stroke (cr);
+
+               cairo_restore (cr);
+
+        }
+
+        g_free (origins);
+
+        gl_debug (DEBUG_MINI_PREVIEW, "END");
+}
+
+
+
+/*
+ * Local Variables:       -- emacs
+ * mode: C                -- emacs
+ * c-basic-offset: 8      -- emacs
+ * tab-width: 8           -- emacs
+ * indent-tabs-mode: nil  -- emacs
+ * End:                   -- emacs
+ */
diff --git a/glabels2/src/mini-preview.h b/glabels2/src/mini-preview.h
new file mode 100644 (file)
index 0000000..4eaccd0
--- /dev/null
@@ -0,0 +1,93 @@
+/*
+ *  mini-preview.h
+ *  Copyright (C) 2001-2009  Jim Evins <evins@snaught.com>.
+ *
+ *  This file is part of gLabels.
+ *
+ *  gLabels is free software: you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation, either version 3 of the License, or
+ *  (at your option) any later version.
+ *
+ *  gLabels is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with gLabels.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef __MINI_PREVIEW_H__
+#define __MINI_PREVIEW_H__
+
+#include <gtk/gtk.h>
+#include "label.h"
+
+
+G_BEGIN_DECLS
+
+#define GL_TYPE_MINI_PREVIEW (gl_mini_preview_get_type ())
+#define GL_MINI_PREVIEW(obj) \
+        (G_TYPE_CHECK_INSTANCE_CAST((obj), GL_TYPE_MINI_PREVIEW, glMiniPreview ))
+#define GL_MINI_PREVIEW_CLASS(klass) \
+        (G_TYPE_CHECK_CLASS_CAST ((klass), GL_TYPE_MINI_PREVIEW, glMiniPreviewClass))
+#define GL_IS_MINI_PREVIEW(obj) \
+        (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GL_TYPE_MINI_PREVIEW))
+#define GL_IS_MINI_PREVIEW_CLASS(klass) \
+        (G_TYPE_CHECK_CLASS_TYPE ((klass), GL_TYPE_MINI_PREVIEW))
+
+
+typedef struct _glMiniPreview        glMiniPreview;
+typedef struct _glMiniPreviewPrivate glMiniPreviewPrivate;
+typedef struct _glMiniPreviewClass   glMiniPreviewClass;
+
+struct _glMiniPreview {
+       GtkEventBox           parent;
+
+       glMiniPreviewPrivate *priv;
+};
+
+struct _glMiniPreviewClass {
+       GtkEventBoxClass      parent_class;
+
+       void (*clicked) (glMiniPreview *this,
+                        gint           index,
+                        gpointer       user_data);
+
+       void (*pressed) (glMiniPreview *this,
+                        gint           index1,
+                        gint           index2,
+                        gpointer       user_data);
+};
+
+
+GType      gl_mini_preview_get_type          (void) G_GNUC_CONST;
+
+GtkWidget *gl_mini_preview_new               (gint               height,
+                                              gint               width);
+
+void       gl_mini_preview_set_label_by_name (glMiniPreview     *this,
+                                              const gchar       *name);
+
+void       gl_mini_preview_set_template      (glMiniPreview     *this,
+                                              const lglTemplate *template);
+
+void       gl_mini_preview_highlight_range   (glMiniPreview     *this,
+                                              gint               first_label,
+                                              gint               last_label);
+
+G_END_DECLS
+
+#endif
+
+
+
+/*
+ * Local Variables:       -- emacs
+ * mode: C                -- emacs
+ * c-basic-offset: 8      -- emacs
+ * tab-width: 8           -- emacs
+ * indent-tabs-mode: nil  -- emacs
+ * End:                   -- emacs
+ */
index 5777de527e329012dba2a12ae1d257c579cc3b60..0848cc9eeb1cd70f8a86c50b5d942aa84f8e099e 100644 (file)
@@ -33,7 +33,7 @@
 
 #include "prefs.h"
 #include <libglabels/db.h>
-#include "wdgt-mini-preview.h"
+#include "mini-preview.h"
 #include "mini-preview-pixbuf-cache.h"
 #include "print-op.h"
 #include "util.h"
@@ -972,7 +972,7 @@ construct_layout_page (glTemplateDesigner      *dialog,
                                      "layout_test_button",    &dialog->priv->layout_test_button,
                                      NULL);
 
-        dialog->priv->layout_mini_preview = gl_wdgt_mini_preview_new (175, 200);
+        dialog->priv->layout_mini_preview = gl_mini_preview_new (175, 200);
         gtk_container_add (GTK_CONTAINER (dialog->priv->mini_preview_vbox),
                            dialog->priv->layout_mini_preview);
 
@@ -1573,8 +1573,8 @@ layout_page_prepare_cb (glTemplateDesigner *dialog)
        }
 
        template = build_template (dialog);
-       gl_wdgt_mini_preview_set_template (GL_WDGT_MINI_PREVIEW(dialog->priv->layout_mini_preview),
-                                          template);
+       gl_mini_preview_set_template (GL_MINI_PREVIEW(dialog->priv->layout_mini_preview),
+                                      template);
        lgl_template_free (template);
 
 
@@ -1595,8 +1595,8 @@ layout_page_changed_cb (glTemplateDesigner *dialog)
 
        template = build_template (dialog);
 
-       gl_wdgt_mini_preview_set_template (GL_WDGT_MINI_PREVIEW(dialog->priv->layout_mini_preview),
-                                          template);
+       gl_mini_preview_set_template (GL_MINI_PREVIEW(dialog->priv->layout_mini_preview),
+                                      template);
 
        lgl_template_free (template);
 
diff --git a/glabels2/src/wdgt-mini-preview.c b/glabels2/src/wdgt-mini-preview.c
deleted file mode 100644 (file)
index 13c03b3..0000000
+++ /dev/null
@@ -1,724 +0,0 @@
-/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- */
-
-/*
- *  (GLABELS) Label and Business Card Creation program for GNOME
- *
- *  wdgt_mini_preview.c:  mini preview widget module
- *
- *  Copyright (C) 2001-2007  Jim Evins <evins@snaught.com>.
- *
- *  This program is free software; you can redistribute it and/or modify
- *  it under the terms of the GNU General Public License as published by
- *  the Free Software Foundation; either version 2 of the License, or
- *  (at your option) any later version.
- *
- *  This program is distributed in the hope that it will be useful,
- *  but WITHOUT ANY WARRANTY; without even the implied warranty of
- *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- *  GNU General Public License for more details.
- *
- *  You should have received a copy of the GNU General Public License
- *  along with this program; if not, write to the Free Software
- *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
- */
-
-#include <config.h>
-
-#include "wdgt-mini-preview.h"
-
-#include <math.h>
-
-#include "libglabels/db.h"
-#include "cairo-label-path.h"
-#include "marshal.h"
-#include "color.h"
-
-#include "debug.h"
-
-/*===========================================*/
-/* Private macros and constants.             */
-/*===========================================*/
-
-#define PAPER_RGB_ARGS          1.0,   1.0,   1.0
-#define PAPER_OUTLINE_RGB_ARGS  0.0,   0.0,   0.0
-#define LABEL_OUTLINE_RGB_ARGS  0.5,   0.5,   0.5
-
-#define SHADOW_X_OFFSET 5
-#define SHADOW_Y_OFFSET 5
-
-/*===========================================*/
-/* Private types                             */
-/*===========================================*/
-
-enum {
-       CLICKED,
-       PRESSED,
-       LAST_SIGNAL
-};
-
-typedef struct {
-       gdouble x;
-       gdouble y;
-} LabelCenter;
-
-struct _glWdgtMiniPreviewPrivate {
-
-       gint            height;
-       gint            width;
-
-       lglTemplate    *template;
-       gdouble         scale;
-       gdouble         offset_x;
-       gdouble         offset_y;
-       gint            labels_per_sheet;
-       LabelCenter    *centers;
-
-       gint            highlight_first;
-       gint            highlight_last;
-
-       gboolean        dragging;
-       gint            first_i;
-       gint            last_i;
-       gint            prev_i;
-};
-
-/*===========================================*/
-/* Private globals                           */
-/*===========================================*/
-
-static gint wdgt_mini_preview_signals[LAST_SIGNAL] = { 0 };
-
-/*===========================================*/
-/* Local function prototypes                 */
-/*===========================================*/
-
-static void gl_wdgt_mini_preview_finalize      (GObject                *object);
-
-static void gl_wdgt_mini_preview_construct     (glWdgtMiniPreview      *preview,
-                                               gint                    height,
-                                               gint                    width);
-
-static gboolean expose_event_cb                (GtkWidget              *widget,
-                                               GdkEventExpose         *event);
-static void style_set_cb                       (GtkWidget              *widget,
-                                               GtkStyle               *previous_style);
-static gboolean button_press_event_cb          (GtkWidget              *widget,
-                                               GdkEventButton         *event);
-static gboolean motion_notify_event_cb         (GtkWidget              *widget,
-                                               GdkEventMotion         *event);
-static gboolean button_release_event_cb        (GtkWidget              *widget,
-                                               GdkEventButton         *event);
-
-
-static void redraw                             (GtkWidget              *widget);
-static void draw                               (glWdgtMiniPreview      *preview,
-                                               cairo_t                *cr);
-
-static void draw_shadow                        (glWdgtMiniPreview      *preview,
-                                               cairo_t                *cr,
-                                               gdouble                      x,
-                                               gdouble                 y,
-                                               gdouble                 width,
-                                               gdouble                 height);
-static void draw_paper                         (glWdgtMiniPreview      *preview,
-                                               cairo_t                *cr,
-                                               gdouble                 width,
-                                               gdouble                 height,
-                                               gdouble                 line_width);
-static void draw_labels                        (glWdgtMiniPreview      *preview,
-                                               cairo_t                *cr,
-                                               lglTemplate            *template,
-                                               gdouble                 line_width);
-
-static gint find_closest_label                 (glWdgtMiniPreview      *preview,
-                                               gdouble                 x,
-                                               gdouble                 y);
-
-
-\f
-/****************************************************************************/
-/* Boilerplate Object stuff.                                                */
-/****************************************************************************/
-G_DEFINE_TYPE (glWdgtMiniPreview, gl_wdgt_mini_preview, GTK_TYPE_DRAWING_AREA);
-
-
-static void
-gl_wdgt_mini_preview_class_init (glWdgtMiniPreviewClass *class)
-{
-       GObjectClass   *object_class = G_OBJECT_CLASS (class);
-       GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (class);
-
-       gl_debug (DEBUG_MINI_PREVIEW, "START");
-
-       gl_wdgt_mini_preview_parent_class = g_type_class_peek_parent (class);
-
-       object_class->finalize = gl_wdgt_mini_preview_finalize;
-
-       widget_class->expose_event         = expose_event_cb;
-       widget_class->style_set            = style_set_cb;
-       widget_class->button_press_event   = button_press_event_cb;
-       widget_class->motion_notify_event  = motion_notify_event_cb;
-       widget_class->button_release_event = button_release_event_cb;
-
-       wdgt_mini_preview_signals[CLICKED] =
-           g_signal_new ("clicked",
-                         G_OBJECT_CLASS_TYPE(object_class),
-                         G_SIGNAL_RUN_LAST,
-                         G_STRUCT_OFFSET (glWdgtMiniPreviewClass, clicked),
-                         NULL, NULL,
-                         gl_marshal_VOID__INT,
-                         G_TYPE_NONE, 1, G_TYPE_INT);
-
-       wdgt_mini_preview_signals[PRESSED] =
-           g_signal_new ("pressed",
-                         G_OBJECT_CLASS_TYPE(object_class),
-                         G_SIGNAL_RUN_LAST,
-                         G_STRUCT_OFFSET (glWdgtMiniPreviewClass, pressed),
-                         NULL, NULL,
-                         gl_marshal_VOID__INT_INT,
-                         G_TYPE_NONE, 2, G_TYPE_INT, G_TYPE_INT);
-
-       gl_debug (DEBUG_MINI_PREVIEW, "END");
-}
-
-static void
-gl_wdgt_mini_preview_init (glWdgtMiniPreview *preview)
-{
-       gl_debug (DEBUG_MINI_PREVIEW, "START");
-
-       preview->priv = g_new0 (glWdgtMiniPreviewPrivate, 1);
-
-       gtk_widget_add_events (GTK_WIDGET (preview),
-                              GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK |
-                              GDK_POINTER_MOTION_MASK);
-
-       gl_debug (DEBUG_MINI_PREVIEW, "END");
-}
-
-static void
-gl_wdgt_mini_preview_finalize (GObject *object)
-{
-       glWdgtMiniPreview *preview = GL_WDGT_MINI_PREVIEW (object);
-
-       gl_debug (DEBUG_MINI_PREVIEW, "START");
-
-       g_return_if_fail (object != NULL);
-       g_return_if_fail (GL_IS_WDGT_MINI_PREVIEW (object));
-
-       lgl_template_free (preview->priv->template);
-       g_free (preview->priv->centers);
-       g_free (preview->priv);
-
-       G_OBJECT_CLASS (gl_wdgt_mini_preview_parent_class)->finalize (object);
-
-       gl_debug (DEBUG_MINI_PREVIEW, "END");
-}
-
-GtkWidget *
-gl_wdgt_mini_preview_new (gint height,
-                         gint width)
-{
-       glWdgtMiniPreview *preview;
-
-       gl_debug (DEBUG_MINI_PREVIEW, "START");
-
-       preview = g_object_new (gl_wdgt_mini_preview_get_type (), NULL);
-
-       gl_wdgt_mini_preview_construct (preview, height, width);
-
-       gl_debug (DEBUG_MINI_PREVIEW, "END");
-
-       return GTK_WIDGET (preview);
-}
-
-/*--------------------------------------------------------------------------*/
-/* Construct composite widget.                                              */
-/*--------------------------------------------------------------------------*/
-static void
-gl_wdgt_mini_preview_construct (glWdgtMiniPreview *preview,
-                               gint               height,
-                               gint               width)
-{
-       gl_debug (DEBUG_MINI_PREVIEW, "START");
-
-       preview->priv->height = height;
-       preview->priv->width  = width;
-
-       gtk_widget_set_size_request (GTK_WIDGET (preview), width, height);
-
-       gl_debug (DEBUG_MINI_PREVIEW, "END");
-}
-
-/****************************************************************************/
-/* Set label for mini-preview to determine geometry.                        */
-/****************************************************************************/
-void gl_wdgt_mini_preview_set_label_by_name (glWdgtMiniPreview *preview,
-                                            const gchar       *name)
-{
-       lglTemplate *template;
-
-       gl_debug (DEBUG_MINI_PREVIEW, "START");
-
-       /* Fetch template */
-       template = lgl_db_lookup_template_from_name (name);
-
-       gl_wdgt_mini_preview_set_template (preview, template);
-
-       lgl_template_free (template);
-
-       gl_debug (DEBUG_MINI_PREVIEW, "END");
-}
-
-/****************************************************************************/
-/* Set label for mini-preview to determine geometry.                        */
-/****************************************************************************/
-void gl_wdgt_mini_preview_set_template (glWdgtMiniPreview *preview,
-                                       const lglTemplate *template)
-{
-       const lglTemplateFrame    *frame;
-       lglTemplateOrigin         *origins;
-       gdouble                    w, h;
-       gint                       i;
-
-       gl_debug (DEBUG_MINI_PREVIEW, "START");
-
-        frame = (lglTemplateFrame *)template->frames->data;
-
-       /*
-        * Set template
-        */
-       lgl_template_free (preview->priv->template);
-       preview->priv->template = lgl_template_dup (template);
-
-       /*
-        * Set scale and offsets
-        */
-       w = preview->priv->width - 4 - 2*SHADOW_X_OFFSET;
-       h = preview->priv->height - 4 - 2*SHADOW_Y_OFFSET;
-       if ( (w/template->page_width) > (h/template->page_height) ) {
-               preview->priv->scale = h / template->page_height;
-       } else {
-               preview->priv->scale = w / template->page_width;
-       }
-       preview->priv->offset_x = (preview->priv->width/preview->priv->scale - template->page_width) / 2.0;
-       preview->priv->offset_y = (preview->priv->height/preview->priv->scale - template->page_height) / 2.0;
-
-       /*
-        * Set labels per sheet
-        */
-       preview->priv->labels_per_sheet = lgl_template_frame_get_n_labels (frame);
-
-       /*
-        * Initialize centers
-        */
-       g_free (preview->priv->centers);
-       preview->priv->centers = g_new0 (LabelCenter, preview->priv->labels_per_sheet);
-       origins = lgl_template_frame_get_origins (frame);
-       lgl_template_frame_get_size (frame, &w, &h);
-       for ( i=0; i<preview->priv->labels_per_sheet; i++ )
-       {
-               preview->priv->centers[i].x = origins[i].x + w/2.0;
-               preview->priv->centers[i].y = origins[i].y + h/2.0;
-       }
-       g_free (origins);
-
-       /*
-        * Redraw modified preview
-        */
-       redraw( GTK_WIDGET (preview));
-
-       gl_debug (DEBUG_MINI_PREVIEW, "END");
-}
-
-/****************************************************************************/
-/* Highlight given label outlines.                                          */
-/****************************************************************************/
-void
-gl_wdgt_mini_preview_highlight_range (glWdgtMiniPreview *preview,
-                                     gint               first_label,
-                                     gint               last_label)
-{
-       gl_debug (DEBUG_MINI_PREVIEW, "START");
-
-       preview->priv->highlight_first = first_label;
-       preview->priv->highlight_last =  last_label;
-
-       redraw( GTK_WIDGET (preview));
-
-       gl_debug (DEBUG_MINI_PREVIEW, "END");
-}
-
-
-/*--------------------------------------------------------------------------*/
-/* Expose event handler.                                                    */
-/*--------------------------------------------------------------------------*/
-static gboolean
-expose_event_cb (GtkWidget       *widget,
-                GdkEventExpose  *event)
-{
-       cairo_t *cr;
-
-       gl_debug (DEBUG_MINI_PREVIEW, "START");
-
-       cr = gdk_cairo_create (widget->window);
-
-       cairo_rectangle (cr,
-                       event->area.x, event->area.y,
-                       event->area.width, event->area.height);
-       cairo_clip (cr);
-       
-       draw (GL_WDGT_MINI_PREVIEW (widget), cr);
-
-       cairo_destroy (cr);
-
-       gl_debug (DEBUG_MINI_PREVIEW, "END");
-       return FALSE;
-}
-
-/*--------------------------------------------------------------------------*/
-/* Button press event handler                                               */
-/*--------------------------------------------------------------------------*/
-static gboolean
-button_press_event_cb (GtkWidget      *widget,
-                      GdkEventButton *event)
-{
-       glWdgtMiniPreview *preview = GL_WDGT_MINI_PREVIEW (widget);
-       cairo_t           *cr;
-       gdouble            x, y;
-       gint               i;
-
-       gl_debug (DEBUG_MINI_PREVIEW, "START");
-
-       if ( event->button == 1 )
-       {
-               cr = gdk_cairo_create (widget->window);
-
-               /* Set transformation. */
-               cairo_identity_matrix (cr);
-               cairo_scale (cr, preview->priv->scale, preview->priv->scale);
-               cairo_translate (cr, preview->priv->offset_x, preview->priv->offset_y);
-
-               x = event->x;
-               y = event->y;
-               cairo_device_to_user (cr, &x, &y);
-
-               i = find_closest_label (preview, x, y);
-
-               g_signal_emit (G_OBJECT(preview),
-                              wdgt_mini_preview_signals[CLICKED],
-                              0, i);
-
-               preview->priv->first_i = i;
-               preview->priv->last_i  = i;
-               g_signal_emit (G_OBJECT(preview),
-                              wdgt_mini_preview_signals[PRESSED],
-                              0, preview->priv->first_i, preview->priv->last_i);
-
-               preview->priv->dragging = TRUE;
-               preview->priv->prev_i   = i;
-
-               cairo_destroy (cr);
-       }
-
-       gl_debug (DEBUG_MINI_PREVIEW, "END");
-       return FALSE;
-}
-
-/*--------------------------------------------------------------------------*/
-/* Motion notify event handler                                              */
-/*--------------------------------------------------------------------------*/
-static gboolean
-motion_notify_event_cb (GtkWidget      *widget,
-                       GdkEventMotion *event)
-{
-       glWdgtMiniPreview *preview = GL_WDGT_MINI_PREVIEW (widget);
-       cairo_t           *cr;
-       gdouble            x, y;
-       gint               i;
-
-       gl_debug (DEBUG_MINI_PREVIEW, "START");
-
-       if (preview->priv->dragging)
-       {
-               cr = gdk_cairo_create (widget->window);
-
-               /* Set transformation. */
-               cairo_identity_matrix (cr);
-               cairo_scale (cr, preview->priv->scale, preview->priv->scale);
-               cairo_translate (cr, preview->priv->offset_x, preview->priv->offset_y);
-
-               x = event->x;
-               y = event->y;
-               cairo_device_to_user (cr, &x, &y);
-
-               i = find_closest_label (preview, x, y);
-
-               if ( i != preview->priv->prev_i )
-               {
-                       preview->priv->last_i = i;
-
-                       g_signal_emit (G_OBJECT(preview),
-                                      wdgt_mini_preview_signals[PRESSED],
-                                      0,
-                                      MIN (preview->priv->first_i, preview->priv->last_i),
-                                      MAX (preview->priv->first_i, preview->priv->last_i));
-
-                       preview->priv->prev_i = i;
-               }
-               cairo_destroy (cr);
-       }
-
-       gl_debug (DEBUG_MINI_PREVIEW, "END");
-       return FALSE;
-}
-
-/*--------------------------------------------------------------------------*/
-/* Button release event handler                                             */
-/*--------------------------------------------------------------------------*/
-static gboolean
-button_release_event_cb (GtkWidget      *widget,
-                        GdkEventButton *event)
-{
-       glWdgtMiniPreview *preview = GL_WDGT_MINI_PREVIEW (widget);
-       
-       gl_debug (DEBUG_MINI_PREVIEW, "START");
-
-       if ( event->button == 1 )
-       {
-               preview->priv->dragging = FALSE;
-
-       }
-
-       gl_debug (DEBUG_MINI_PREVIEW, "END");
-       return FALSE;
-}
-
-/*--------------------------------------------------------------------------*/
-/* Style set handler (updates colors when style/theme changes).             */
-/*--------------------------------------------------------------------------*/
-static void
-style_set_cb (GtkWidget        *widget,
-             GtkStyle         *previous_style)
-{
-       gl_debug (DEBUG_MINI_PREVIEW, "START");
-
-       redraw( widget );
-
-       gl_debug (DEBUG_MINI_PREVIEW, "END");
-}
-
-/*--------------------------------------------------------------------------*/
-/* Redraw.                                                                  */
-/*--------------------------------------------------------------------------*/
-static void
-redraw (GtkWidget *widget)
-{
-       GdkRegion *region;
-       
-       gl_debug (DEBUG_MINI_PREVIEW, "START");
-
-       if (widget->window)
-       {
-
-               region = gdk_drawable_get_clip_region (widget->window);
-
-               gdk_window_invalidate_region (widget->window, region, TRUE);
-               gdk_window_process_updates (widget->window, TRUE);
-
-               gdk_region_destroy (region);
-       }
-
-       gl_debug (DEBUG_MINI_PREVIEW, "END");
-}
-
-/*--------------------------------------------------------------------------*/
-/* Find index+1 of label closest to given coordinates.                      */
-/*--------------------------------------------------------------------------*/
-static gint
-find_closest_label (glWdgtMiniPreview      *preview,
-                   gdouble                 x,
-                   gdouble                 y)
-{
-       gint    i;
-       gint    min_i;
-       gdouble dx, dy, d2, min_d2;
-
-       dx = x - preview->priv->centers[0].x;
-       dy = y - preview->priv->centers[0].y;
-       min_d2 = dx*dx + dy*dy;
-       min_i = 0;
-
-       for ( i=1; i<preview->priv->labels_per_sheet; i++ )
-       {
-               dx = x - preview->priv->centers[i].x;
-               dy = y - preview->priv->centers[i].y;
-               d2 = dx*dx + dy*dy;
-
-               if ( d2 < min_d2 )
-               {
-                       min_d2 = d2;
-                       min_i  = i;
-               }
-       }
-
-       return min_i + 1;
-}
-
-/*--------------------------------------------------------------------------*/
-/* Draw mini preview.                                                       */
-/*--------------------------------------------------------------------------*/
-static void
-draw (glWdgtMiniPreview  *preview,
-      cairo_t            *cr)
-{
-       lglTemplate *template = preview->priv->template;
-       gdouble      shadow_x, shadow_y;
-
-       gl_debug (DEBUG_MINI_PREVIEW, "START");
-
-       if (template)
-       {
-
-               /* Set transformation. */
-               cairo_identity_matrix (cr);
-               cairo_scale (cr, preview->priv->scale, preview->priv->scale);
-               cairo_translate (cr, preview->priv->offset_x, preview->priv->offset_y);
-
-
-               /* update shadow */
-               shadow_x = SHADOW_X_OFFSET/preview->priv->scale;
-               shadow_y = SHADOW_Y_OFFSET/preview->priv->scale;
-
-               draw_shadow (preview, cr,
-                            shadow_x, shadow_y,
-                            template->page_width, template->page_height);
-
-               draw_paper (preview, cr,
-                           template->page_width, template->page_height,
-                           1.0/preview->priv->scale);
-
-               draw_labels (preview, cr, template, 1.0/preview->priv->scale);
-                            
-       }
-
-       gl_debug (DEBUG_MINI_PREVIEW, "END");
-
-}
-
-
-/*--------------------------------------------------------------------------*/
-/* Draw page shadow                                                         */
-/*--------------------------------------------------------------------------*/
-static void
-draw_shadow (glWdgtMiniPreview      *preview,
-            cairo_t                *cr,
-            gdouble                 x,
-            gdouble                 y,
-            gdouble                 width,
-            gdouble                 height)
-{
-       GtkStyle *style;
-       guint     shadow_color;
-
-        gl_debug (DEBUG_MINI_PREVIEW, "START");
-
-       cairo_save (cr);
-
-       cairo_rectangle (cr, x, y, width, height);
-
-       style = gtk_widget_get_style (GTK_WIDGET(preview));
-       shadow_color = gl_color_from_gdk_color (&style->bg[GTK_STATE_ACTIVE]);
-       cairo_set_source_rgb (cr, GL_COLOR_RGB_ARGS (shadow_color));
-
-        cairo_fill (cr);
-
-        cairo_restore (cr);
-
-        gl_debug (DEBUG_MINI_PREVIEW, "END");
-}
-
-/*--------------------------------------------------------------------------*/
-/* Draw page                                                                */
-/*--------------------------------------------------------------------------*/
-static void
-draw_paper (glWdgtMiniPreview      *preview,
-           cairo_t                *cr,
-           gdouble                 width,
-           gdouble                 height,
-           gdouble                 line_width)
-{
-       cairo_save (cr);
-
-        gl_debug (DEBUG_MINI_PREVIEW, "START");
-
-       cairo_rectangle (cr, 0.0, 0.0, width, height);
-
-       cairo_set_source_rgb (cr, PAPER_RGB_ARGS);
-        cairo_fill_preserve (cr);
-
-       cairo_set_source_rgb (cr, PAPER_OUTLINE_RGB_ARGS);
-       cairo_set_line_width (cr, line_width);
-        cairo_stroke (cr);
-
-        cairo_restore (cr);
-
-        gl_debug (DEBUG_MINI_PREVIEW, "END");
-}
-
-/*--------------------------------------------------------------------------*/
-/* Draw labels                                                              */
-/*--------------------------------------------------------------------------*/
-static void
-draw_labels (glWdgtMiniPreview *preview,
-            cairo_t           *cr,
-            lglTemplate       *template,
-            gdouble            line_width)
-{
-        const lglTemplateFrame    *frame;
-        gint                       i, n_labels;
-        lglTemplateOrigin         *origins;
-       GtkStyle                  *style;
-       guint                      highlight_color;
-
-        gl_debug (DEBUG_MINI_PREVIEW, "START");
-
-        frame = (lglTemplateFrame *)template->frames->data;
-
-        n_labels = lgl_template_frame_get_n_labels (frame);
-        origins  = lgl_template_frame_get_origins (frame);
-
-       style = gtk_widget_get_style (GTK_WIDGET(preview));
-       highlight_color = gl_color_from_gdk_color (&style->base[GTK_STATE_SELECTED]);
-
-        for ( i=0; i < n_labels; i++ ) {
-
-               cairo_save (cr);
-
-                cairo_translate (cr, origins[i].x, origins[i].y);
-                gl_cairo_label_path (cr, template, FALSE, FALSE);
-
-               if ( ((i+1) >= preview->priv->highlight_first) &&
-                    ((i+1) <= preview->priv->highlight_last) )
-               {
-                       cairo_set_source_rgb (cr, GL_COLOR_RGB_ARGS (highlight_color));
-               }
-               else
-               {
-                       cairo_set_source_rgb (cr, PAPER_RGB_ARGS);
-               }
-               cairo_set_fill_rule (cr, CAIRO_FILL_RULE_EVEN_ODD);
-               cairo_fill_preserve (cr);
-
-               cairo_set_line_width (cr, line_width);
-               cairo_set_source_rgb (cr, LABEL_OUTLINE_RGB_ARGS);
-               cairo_stroke (cr);
-
-               cairo_restore (cr);
-
-        }
-
-        g_free (origins);
-
-        gl_debug (DEBUG_MINI_PREVIEW, "END");
-}
-
diff --git a/glabels2/src/wdgt-mini-preview.h b/glabels2/src/wdgt-mini-preview.h
deleted file mode 100644 (file)
index 6796879..0000000
+++ /dev/null
@@ -1,83 +0,0 @@
-/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- */
-
-/*
- *  (GLABELS) Label and Business Card Creation program for GNOME
- *
- *  wdgt_mini_preview.h:  mini-preview widget module header file
- *
- *  Copyright (C) 2001-2007  Jim Evins <evins@snaught.com>.
- *
- *  This program is free software; you can redistribute it and/or modify
- *  it under the terms of the GNU General Public License as published by
- *  the Free Software Foundation; either version 2 of the License, or
- *  (at your option) any later version.
- *
- *  This program is distributed in the hope that it will be useful,
- *  but WITHOUT ANY WARRANTY; without even the implied warranty of
- *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- *  GNU General Public License for more details.
- *
- *  You should have received a copy of the GNU General Public License
- *  along with this program; if not, write to the Free Software
- *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
- */
-
-#ifndef __WDGT_MINI_PREVIEW_H__
-#define __WDGT_MINI_PREVIEW_H__
-
-#include <gtk/gtk.h>
-#include "label.h"
-
-G_BEGIN_DECLS
-
-#define GL_TYPE_WDGT_MINI_PREVIEW (gl_wdgt_mini_preview_get_type ())
-#define GL_WDGT_MINI_PREVIEW(obj) \
-        (G_TYPE_CHECK_INSTANCE_CAST((obj), GL_TYPE_WDGT_MINI_PREVIEW, glWdgtMiniPreview ))
-#define GL_WDGT_MINI_PREVIEW_CLASS(klass) \
-        (G_TYPE_CHECK_CLASS_CAST ((klass), GL_TYPE_WDGT_MINI_PREVIEW, glWdgtMiniPreviewClass))
-#define GL_IS_WDGT_MINI_PREVIEW(obj) \
-        (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GL_TYPE_WDGT_MINI_PREVIEW))
-#define GL_IS_WDGT_MINI_PREVIEW_CLASS(klass) \
-        (G_TYPE_CHECK_CLASS_TYPE ((klass), GL_TYPE_WDGT_MINI_PREVIEW))
-
-typedef struct _glWdgtMiniPreview        glWdgtMiniPreview;
-typedef struct _glWdgtMiniPreviewPrivate glWdgtMiniPreviewPrivate;
-typedef struct _glWdgtMiniPreviewClass   glWdgtMiniPreviewClass;
-
-struct _glWdgtMiniPreview {
-       GtkDrawingArea            parent_widget;
-
-       glWdgtMiniPreviewPrivate *priv;
-};
-
-struct _glWdgtMiniPreviewClass {
-       GtkDrawingAreaClass       parent_class;
-
-       void (*clicked) (glWdgtMiniPreview *preview,
-                        gint index,
-                        gpointer user_data);
-
-       void (*pressed) (glWdgtMiniPreview *preview,
-                        gint index1,
-                        gint index2,
-                        gpointer user_data);
-};
-
-GType      gl_wdgt_mini_preview_get_type          (void) G_GNUC_CONST;
-
-GtkWidget *gl_wdgt_mini_preview_new               (gint               height,
-                                                  gint               width);
-
-void       gl_wdgt_mini_preview_set_label_by_name (glWdgtMiniPreview *preview,
-                                                  const gchar       *name);
-
-void       gl_wdgt_mini_preview_set_template      (glWdgtMiniPreview *preview,
-                                                  const lglTemplate *template);
-
-void       gl_wdgt_mini_preview_highlight_range   (glWdgtMiniPreview *preview,
-                                                  gint               first_label,
-                                                  gint               last_label);
-
-G_END_DECLS
-
-#endif
index 023d71262a3e2436d91d7b531ebf3720f709d482..0a7b77037a54252eec7b3af1ddcd3112e2cd2955 100644 (file)
 #include <gtk/gtkvbox.h>
 
 #include "hig.h"
-#include "wdgt-mini-preview.h"
+#include "mini-preview.h"
 #include "marshal.h"
 
 #include "debug.h"
 
-#define WDGT_MINI_PREVIEW_HEIGHT 175
-#define WDGT_MINI_PREVIEW_WIDTH  150
+#define MINI_PREVIEW_HEIGHT 175
+#define MINI_PREVIEW_WIDTH  150
 
 /*===========================================*/
 /* Private globals                           */
@@ -63,7 +63,7 @@ static void last_spin_cb                       (GtkSpinButton * spinbutton,
                                                gpointer user_data);
 
 static void
-preview_pressed (glWdgtMiniPreview *mini_preview,
+preview_pressed (glMiniPreview *mini_preview,
                 gint first, gint last, gpointer user_data);
 
 \f
@@ -137,10 +137,10 @@ gl_wdgt_print_copies_construct (glWdgtPrintCopies *copies,
        copies->labels_per_sheet = lgl_template_frame_get_n_labels (frame);
 
        /* mini_preview canvas */
-       copies->mini_preview = gl_wdgt_mini_preview_new (WDGT_MINI_PREVIEW_HEIGHT,
-                                                   WDGT_MINI_PREVIEW_WIDTH);
-       gl_wdgt_mini_preview_set_template (GL_WDGT_MINI_PREVIEW(copies->mini_preview),
-                                          label->template);
+       copies->mini_preview = gl_mini_preview_new (MINI_PREVIEW_HEIGHT,
+                                                   MINI_PREVIEW_WIDTH);
+       gl_mini_preview_set_template (GL_MINI_PREVIEW(copies->mini_preview),
+                                      label->template);
        gtk_box_pack_start (GTK_BOX(whbox), copies->mini_preview, FALSE, FALSE, 0);
 
        wvbox = gtk_vbox_new (FALSE, GL_HIG_PAD1);
@@ -156,8 +156,8 @@ gl_wdgt_print_copies_construct (glWdgtPrintCopies *copies,
        copies->sheets_spin = gtk_spin_button_new (GTK_ADJUSTMENT (adjust),
                                                   1.0, 0);
        gtk_box_pack_start (GTK_BOX(whbox1), copies->sheets_spin, FALSE, FALSE, 0);
-       gl_wdgt_mini_preview_highlight_range (GL_WDGT_MINI_PREVIEW(copies->mini_preview),
-                                             1, copies->labels_per_sheet);
+       gl_mini_preview_highlight_range (GL_MINI_PREVIEW(copies->mini_preview),
+                                         1, copies->labels_per_sheet);
 
        /* Blank line */
        gtk_box_pack_start (GTK_BOX(wvbox), gtk_label_new (""), FALSE, FALSE, 0);
@@ -213,8 +213,8 @@ sheets_radio_cb (GtkToggleButton * togglebutton,
                gtk_widget_set_sensitive (copies->first_spin, FALSE);
                gtk_widget_set_sensitive (copies->last_spin, FALSE);
 
-               gl_wdgt_mini_preview_highlight_range (GL_WDGT_MINI_PREVIEW(copies->mini_preview),
-                                       1, copies->labels_per_sheet);
+               gl_mini_preview_highlight_range (GL_MINI_PREVIEW(copies->mini_preview),
+                                                 1, copies->labels_per_sheet);
 
        } else {
 
@@ -228,7 +228,7 @@ sheets_radio_cb (GtkToggleButton * togglebutton,
                last =
                    gtk_spin_button_get_value_as_int (GTK_SPIN_BUTTON
                                                      (copies->last_spin));
-               gl_wdgt_mini_preview_highlight_range (GL_WDGT_MINI_PREVIEW(copies->mini_preview),
+               gl_mini_preview_highlight_range (GL_MINI_PREVIEW(copies->mini_preview),
                                                 first, last);
 
        }
@@ -254,7 +254,7 @@ first_spin_cb (GtkSpinButton * spinbutton,
        gtk_spin_button_get_adjustment (GTK_SPIN_BUTTON (copies->last_spin))->
            lower = first;
 
-       gl_wdgt_mini_preview_highlight_range (GL_WDGT_MINI_PREVIEW(copies->mini_preview),
+       gl_mini_preview_highlight_range (GL_MINI_PREVIEW(copies->mini_preview),
                                         first, last);
 }
 
@@ -278,7 +278,7 @@ last_spin_cb (GtkSpinButton * spinbutton,
        gtk_spin_button_get_adjustment (GTK_SPIN_BUTTON (copies->first_spin))->
            upper = last;
 
-       gl_wdgt_mini_preview_highlight_range (GL_WDGT_MINI_PREVIEW(copies->mini_preview),
+       gl_mini_preview_highlight_range (GL_MINI_PREVIEW(copies->mini_preview),
                                         first, last);
 }
 
@@ -286,7 +286,7 @@ last_spin_cb (GtkSpinButton * spinbutton,
 /* PRIVATE.  Canvas event handler, select first and last items.             */
 /*--------------------------------------------------------------------------*/
 static void
-preview_pressed (glWdgtMiniPreview *mini_preview,
+preview_pressed (glMiniPreview *mini_preview,
                 gint first,
                 gint last,
                 gpointer user_data)
index da093f2779a34b835582dc4c7107e69efc221bc6..c5e0b97f5ad02b3b5ddbc3cdfb7a4a2a2040270d 100644 (file)
@@ -35,7 +35,7 @@
 #include <gtk/gtkvbox.h>
 
 #include "hig.h"
-#include "wdgt-mini-preview.h"
+#include "mini-preview.h"
 #include "marshal.h"
 
 #include "pixmaps/collate.xpm"
@@ -43,8 +43,8 @@
 
 #include "debug.h"
 
-#define WDGT_MINI_PREVIEW_HEIGHT 175
-#define WDGT_MINI_PREVIEW_WIDTH  150
+#define MINI_PREVIEW_HEIGHT 175
+#define MINI_PREVIEW_WIDTH  150
 
 /*===========================================*/
 /* Private globals                           */
@@ -59,7 +59,7 @@ static void gl_wdgt_print_merge_finalize      (GObject * object);
 static void gl_wdgt_print_merge_construct     (glWdgtPrintMerge * merge,
                                               glLabel * label);
 
-static void preview_clicked                   (glWdgtMiniPreview *mini_preview,
+static void preview_clicked                   (glMiniPreview *mini_preview,
                                               gint i_label,
                                               gpointer user_data);
 
@@ -136,13 +136,13 @@ gl_wdgt_print_merge_construct (glWdgtPrintMerge * merge,
        merge->labels_per_sheet = lgl_template_frame_get_n_labels (frame);
 
        /* mini_preview canvas */
-       merge->mini_preview = gl_wdgt_mini_preview_new (WDGT_MINI_PREVIEW_HEIGHT,
-                                                       WDGT_MINI_PREVIEW_WIDTH);
-       gl_wdgt_mini_preview_set_template( GL_WDGT_MINI_PREVIEW (merge->mini_preview),
-                                          label->template );
+       merge->mini_preview = gl_mini_preview_new (MINI_PREVIEW_HEIGHT,
+                                                   MINI_PREVIEW_WIDTH);
+       gl_mini_preview_set_template( GL_MINI_PREVIEW (merge->mini_preview),
+                                      label->template );
        gtk_box_pack_start (GTK_BOX(whbox), merge->mini_preview, FALSE, FALSE, 0);
-       gl_wdgt_mini_preview_highlight_range (GL_WDGT_MINI_PREVIEW(merge->mini_preview),
-                                             1, 1);
+       gl_mini_preview_highlight_range (GL_MINI_PREVIEW(merge->mini_preview),
+                                         1, 1);
 
        wvbox = gtk_vbox_new (FALSE, GL_HIG_PAD1);
        gtk_box_pack_start (GTK_BOX(whbox), wvbox, FALSE, FALSE, 0);
@@ -236,7 +236,7 @@ spin_cb (GtkSpinButton * spinbutton,
            gtk_spin_button_get_value_as_int (GTK_SPIN_BUTTON
                                              (merge->copies_spin));
        last = first + (n_copies * merge->n_records) - 1;
-       gl_wdgt_mini_preview_highlight_range (GL_WDGT_MINI_PREVIEW(merge->mini_preview),
+       gl_mini_preview_highlight_range (GL_MINI_PREVIEW(merge->mini_preview),
                                         first, last );
 
        gtk_widget_set_sensitive (merge->collate_check, (n_copies > 1));
@@ -247,7 +247,7 @@ spin_cb (GtkSpinButton * spinbutton,
 /* PRIVATE.  Canvas event handler, select first and last items.             */
 /*--------------------------------------------------------------------------*/
 static void
-preview_clicked (glWdgtMiniPreview *mini_preview,
+preview_clicked (glMiniPreview *mini_preview,
                 gint first,
                 gpointer user_data)
 {
@@ -261,7 +261,7 @@ preview_clicked (glWdgtMiniPreview *mini_preview,
            gtk_spin_button_get_value_as_int (GTK_SPIN_BUTTON
                                              (merge->copies_spin));
        last = first + (n_copies * merge->n_records) - 1;
-       gl_wdgt_mini_preview_highlight_range (GL_WDGT_MINI_PREVIEW (merge->mini_preview),
+       gl_mini_preview_highlight_range (GL_MINI_PREVIEW (merge->mini_preview),
                                         first, last);
 
 }
@@ -311,6 +311,6 @@ gl_wdgt_print_merge_set_copies (glWdgtPrintMerge * merge,
                                      collate_flag);
 
        last_label = first_label + (n_copies * n_records) - 1;
-       gl_wdgt_mini_preview_highlight_range (GL_WDGT_MINI_PREVIEW (merge->mini_preview),
+       gl_mini_preview_highlight_range (GL_MINI_PREVIEW (merge->mini_preview),
                                         first_label, last_label );
 }