]> git.sur5r.net Git - glabels/blobdiff - src/view-line.c
Imported Upstream version 3.0.0
[glabels] / src / view-line.c
index 8c3996588d0e9275ba89aae5246c83b2e5be7ceb..9da709e1ba99e3b4a64047b4c5c3be004b17c6a0 100644 (file)
@@ -1,54 +1,47 @@
-/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- */
-
 /*
- *  (GLABELS) Label and Business Card Creation program for GNOME
- *
- *  view_line.c:  GLabels label line object view
+ *  view-line.c
+ *  Copyright (C) 2001-2009  Jim Evins <evins@snaught.com>.
  *
- *  Copyright (C) 2001-2007  Jim Evins <evins@snaught.com>.
+ *  This file is part of gLabels.
  *
- *  This program is free software; you can redistribute it and/or modify
+ *  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 2 of the License, or
+ *  the Free Software Foundation, either version 3 of the License, or
  *  (at your option) any later version.
  *
- *  This program is distributed in the hope that it will be useful,
+ *  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 this program; if not, write to the Free Software
- *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
+ *  along with gLabels.  If not, see <http://www.gnu.org/licenses/>.
  */
+
 #include <config.h>
 
 #include "view-line.h"
 
-#include <glib/gi18n.h>
-#include <glib/gmem.h>
-
-#include "color.h"
-#include "object-editor.h"
-#include "stock.h"
+#include <gdk-pixbuf/gdk-pixdata.h>
 
-#include "pixmaps/cursor_line.xbm"
-#include "pixmaps/cursor_line_mask.xbm"
+#include "label-line.h"
+#include "cursors/cursor_pixdata.h"
 
 #include "debug.h"
 
+
 /*========================================================*/
 /* Private macros and constants.                          */
 /*========================================================*/
 
+#define X_HOTSPOT 7
+#define Y_HOTSPOT 7
+
 
 /*========================================================*/
 /* Private types.                                         */
 /*========================================================*/
 
-struct _glViewLinePrivate {
-        int place_holder; /* Place holder for future private data. */
-};
 
 /*========================================================*/
 /* Private globals.                                       */
@@ -59,299 +52,6 @@ struct _glViewLinePrivate {
 /* Private function prototypes.                           */
 /*========================================================*/
 
-static void       gl_view_line_finalize             (GObject          *object);
-
-static GtkWidget *construct_properties_editor       (glViewObject     *view_object);
-
-static void       update_object_from_editor_cb      (glObjectEditor   *editor,
-                                                    glLabelObject    *object);
-
-static void       update_editor_from_object_cb      (glLabelObject    *object,
-                                                    glObjectEditor   *editor);
-
-static void       update_editor_from_move_cb        (glLabelObject    *object,
-                                                    gdouble           dx,
-                                                    gdouble           dy,
-                                                    glObjectEditor   *editor);
-
-static gboolean   object_at                         (glViewObject     *view_object,
-                                                     cairo_t          *cr,
-                                                     gdouble           x,
-                                                     gdouble           y);
-
-
-\f
-/*****************************************************************************/
-/* Boilerplate object stuff.                                                 */
-/*****************************************************************************/
-G_DEFINE_TYPE (glViewLine, gl_view_line, GL_TYPE_VIEW_OBJECT);
-
-
-static void
-gl_view_line_class_init (glViewLineClass *class)
-{
-       GObjectClass      *object_class      = G_OBJECT_CLASS (class);
-       glViewObjectClass *view_object_class = GL_VIEW_OBJECT_CLASS (class);
-
-       gl_debug (DEBUG_VIEW, "START");
-
-       gl_view_line_parent_class = g_type_class_peek_parent (class);
-
-       object_class->finalize = gl_view_line_finalize;
-
-       view_object_class->construct_editor = construct_properties_editor;
-       view_object_class->object_at        = object_at;
-
-       gl_debug (DEBUG_VIEW, "END");
-}
-
-static void
-gl_view_line_init (glViewLine *view_line)
-{
-       gl_debug (DEBUG_VIEW, "START");
-
-       view_line->priv = g_new0 (glViewLinePrivate, 1);
-
-       gl_debug (DEBUG_VIEW, "END");
-}
-
-static void
-gl_view_line_finalize (GObject *object)
-{
-        glViewLine *view_line = GL_VIEW_LINE (object);
-
-       gl_debug (DEBUG_VIEW, "START");
-
-       g_return_if_fail (object && GL_IS_VIEW_LINE (object));
-
-        g_free (view_line->priv);
-
-       G_OBJECT_CLASS (gl_view_line_parent_class)->finalize (object);
-
-       gl_debug (DEBUG_VIEW, "END");
-}
-
-/*****************************************************************************/
-/* NEW line object view.                                                  */
-/*****************************************************************************/
-glViewObject *
-gl_view_line_new (glLabelLine *object,
-                  glView     *view)
-{
-       glViewLine         *view_line;
-
-       gl_debug (DEBUG_VIEW, "START");
-
-       g_return_val_if_fail (object && GL_IS_LABEL_LINE (object), NULL);
-       g_return_val_if_fail (view && GL_IS_VIEW (view), NULL);
-       
-       view_line = g_object_new (gl_view_line_get_type(), NULL);
-
-       gl_view_object_set_object (GL_VIEW_OBJECT(view_line),
-                                  GL_LABEL_OBJECT(object),
-                                  GL_VIEW_OBJECT_HANDLES_LINE);
-       gl_view_object_set_view (GL_VIEW_OBJECT(view_line), view);
-
-       gl_debug (DEBUG_VIEW, "END");
-
-       return GL_VIEW_OBJECT (view_line);
-}
-
-/*****************************************************************************/
-/* Create a properties dialog for a line object.                             */
-/*****************************************************************************/
-static GtkWidget *
-construct_properties_editor (glViewObject *view_object)
-{
-       GtkWidget          *editor;
-       glViewLine         *view_line = (glViewLine *)view_object;
-       glLabelObject      *object;
-
-       gl_debug (DEBUG_VIEW, "START");
-
-       object = gl_view_object_get_object (GL_VIEW_OBJECT(view_line));
-
-       /* Build editor. */
-       editor = gl_object_editor_new (GL_STOCK_LINE, _("Line object properties"),
-                                       object->parent,
-                                      GL_OBJECT_EDITOR_SHADOW_PAGE,
-                                      GL_OBJECT_EDITOR_POSITION_PAGE,
-                                      GL_OBJECT_EDITOR_SIZE_LINE_PAGE,
-                                      GL_OBJECT_EDITOR_LINE_PAGE,
-                                      0);
-       
-       /* Update */
-       update_editor_from_object_cb (object, GL_OBJECT_EDITOR(editor));
-       update_editor_from_move_cb (object, 0, 0, GL_OBJECT_EDITOR(editor));
-
-       /* Connect signals. */
-       g_signal_connect (G_OBJECT (editor), "changed",
-                         G_CALLBACK(update_object_from_editor_cb), object);
-       g_signal_connect (G_OBJECT (object), "changed",
-                         G_CALLBACK (update_editor_from_object_cb), editor);
-       g_signal_connect (G_OBJECT (object), "moved",
-                         G_CALLBACK (update_editor_from_move_cb), editor);
-
-       gl_debug (DEBUG_VIEW, "END");
-
-       return editor;
-}
-
-/*---------------------------------------------------------------------------*/
-/* PRIVATE.  editor "changed" callback.                                      */
-/*---------------------------------------------------------------------------*/
-static void
-update_object_from_editor_cb (glObjectEditor *editor,
-                             glLabelObject  *object)
-{
-       gdouble            x, y, w, h;
-       glColorNode       *line_color_node;
-       gdouble            line_width;
-       gboolean           shadow_state;
-       gdouble            shadow_x, shadow_y;
-       glColorNode       *shadow_color_node;
-       gdouble            shadow_opacity;
-       
-
-       gl_debug (DEBUG_VIEW, "START");
-
-       g_signal_handlers_block_by_func (G_OBJECT(object),
-                                        update_editor_from_object_cb,
-                                        editor);
-       g_signal_handlers_block_by_func (G_OBJECT(object),
-                                        update_editor_from_move_cb,
-                                        editor);
-
-       gl_object_editor_get_position (editor, &x, &y);
-       gl_label_object_set_position (object, x, y);
-
-       gl_object_editor_get_lsize (editor, &w, &h);
-       gl_label_object_set_size (object, w, h);
-
-       line_color_node = gl_object_editor_get_line_color (editor);
-       gl_label_object_set_line_color (object, line_color_node);
-       gl_color_node_free (&line_color_node);
-
-       line_width = gl_object_editor_get_line_width (editor);
-       gl_label_object_set_line_width (object, line_width);
-
-       shadow_state = gl_object_editor_get_shadow_state (editor);
-       gl_label_object_set_shadow_state (object, shadow_state);
-
-       gl_object_editor_get_shadow_offset (editor, &shadow_x, &shadow_y);
-       gl_label_object_set_shadow_offset (object, shadow_x, shadow_y);
-
-       shadow_color_node = gl_object_editor_get_shadow_color (editor);
-       gl_label_object_set_shadow_color (object, shadow_color_node);
-       gl_color_node_free (&shadow_color_node);
-
-       shadow_opacity = gl_object_editor_get_shadow_opacity (editor);
-       gl_label_object_set_shadow_opacity (object, shadow_opacity);
-
-       g_signal_handlers_unblock_by_func (G_OBJECT(object),
-                                          update_editor_from_object_cb,
-                                          editor);
-       g_signal_handlers_unblock_by_func (G_OBJECT(object),
-                                          update_editor_from_move_cb,
-                                          editor);
-
-       gl_debug (DEBUG_VIEW, "END");
-}
-
-/*---------------------------------------------------------------------------*/
-/* PRIVATE. label object "changed" callback.                                 */
-/*---------------------------------------------------------------------------*/
-static void
-update_editor_from_object_cb (glLabelObject  *object,
-                             glObjectEditor *editor)
-{
-       gdouble            w, h;
-       glColorNode       *line_color_node;
-       gdouble            line_width;
-       gboolean           shadow_state;
-       gdouble            shadow_x, shadow_y;
-       glColorNode       *shadow_color_node;
-       gdouble            shadow_opacity;
-       glMerge           *merge;
-
-       gl_debug (DEBUG_VIEW, "START");
-
-       gl_label_object_get_size (object, &w, &h);
-       gl_object_editor_set_lsize (editor, w, h);
-       merge = gl_label_get_merge (GL_LABEL(object->parent));
-       
-       line_color_node = gl_label_object_get_line_color (GL_LABEL_OBJECT(object));
-       gl_object_editor_set_line_color (editor, (merge != NULL), line_color_node);
-       gl_color_node_free (&line_color_node);
-
-       line_width = gl_label_object_get_line_width (GL_LABEL_OBJECT(object));
-       gl_object_editor_set_line_width (editor, line_width);
-
-       shadow_state = gl_label_object_get_shadow_state (object);
-       gl_object_editor_set_shadow_state (editor, shadow_state);
-
-       gl_label_object_get_shadow_offset (object, &shadow_x, &shadow_y);
-       gl_object_editor_set_shadow_offset (editor, shadow_x, shadow_y);
-
-       shadow_color_node = gl_label_object_get_shadow_color (object);
-       gl_object_editor_set_shadow_color (editor, (merge != NULL), shadow_color_node);
-       gl_color_node_free (&shadow_color_node);
-
-       shadow_opacity = gl_label_object_get_shadow_opacity (object);
-       gl_object_editor_set_shadow_opacity (editor, shadow_opacity);
-
-       gl_debug (DEBUG_VIEW, "END");
-}
-
-/*---------------------------------------------------------------------------*/
-/* PRIVATE. label object "moved" callback.                                   */
-/*---------------------------------------------------------------------------*/
-static void
-update_editor_from_move_cb (glLabelObject    *object,
-                           gdouble           dx,
-                           gdouble           dy,
-                           glObjectEditor   *editor)
-{
-       gdouble            x, y;
-
-       gl_debug (DEBUG_VIEW, "START");
-
-       gl_label_object_get_position (object, &x, &y);
-       gl_object_editor_set_position (editor, x, y);
-
-       gl_debug (DEBUG_VIEW, "END");
-}
-
-/*****************************************************************************/
-/* Is object at (x,y)?                                                       */
-/*****************************************************************************/
-static gboolean
-object_at (glViewObject  *view_object,
-           cairo_t       *cr,
-           gdouble        x,
-           gdouble        y)
-{
-       glLabelObject    *object;
-        gdouble           w, h;
-        gdouble           line_width;
-
-        object = gl_view_object_get_object (view_object);
-
-        gl_label_object_get_size (object, &w, &h);
-
-        cairo_move_to (cr, 0.0, 0.0);
-        cairo_line_to (cr, w, h);
-
-        line_width = gl_label_object_get_line_width (object);
-        cairo_set_line_width (cr, line_width);
-        if (cairo_in_stroke (cr, x, y))
-        {
-                return TRUE;
-        }
-
-        return FALSE;
-}
-
 
 /*****************************************************************************/
 /* Return apropos cursor for create object mode.                             */
@@ -360,29 +60,20 @@ GdkCursor *
 gl_view_line_get_create_cursor (void)
 {
        GdkCursor       *cursor = NULL;
-       GdkPixmap       *pixmap_data, *pixmap_mask;
-       GdkColor         fg = { 0, 0, 0, 0 };
-       GdkColor         bg = { 0, 65535, 65535, 65535 };
+       GdkPixbuf       *pixbuf;
 
        gl_debug (DEBUG_VIEW, "START");
 
-        pixmap_data = gdk_bitmap_create_from_data (NULL,
-                                                   (gchar *)cursor_line_bits,
-                                                   cursor_line_width,
-                                                   cursor_line_height);
-        pixmap_mask = gdk_bitmap_create_from_data (NULL,
-                                                   (gchar *)cursor_line_mask_bits,
-                                                   cursor_line_mask_width,
-                                                   cursor_line_mask_height);
-        cursor = gdk_cursor_new_from_pixmap (pixmap_data, pixmap_mask, &fg,
-                                             &bg, cursor_line_x_hot,
-                                             cursor_line_y_hot);
+        pixbuf = gdk_pixbuf_from_pixdata (&cursor_line_pixdata, FALSE, NULL);
+        cursor = gdk_cursor_new_from_pixbuf (gdk_display_get_default (), pixbuf, X_HOTSPOT, Y_HOTSPOT);
+        g_object_unref (pixbuf);
 
        gl_debug (DEBUG_VIEW, "END");
 
        return cursor;
 }
 
+
 /*****************************************************************************/
 /* Object creation handler: button press event.                              */
 /*****************************************************************************/
@@ -392,28 +83,20 @@ gl_view_line_create_button_press_event   (glView *view,
                                           gdouble y)
 {
        GObject             *object;
-       glColorNode         *line_color_node;
 
-        gl_view_unselect_all (view);
+        gl_label_unselect_all (view->label);
 
-        line_color_node = gl_color_node_new_default ();
-               
-        object = gl_label_line_new (view->label);
-        gl_label_object_set_position (GL_LABEL_OBJECT(object), x, y);
-        gl_label_object_set_size (GL_LABEL_OBJECT(object), 0.0, 0.0);
-        line_color_node->color = gl_color_set_opacity (gl_view_get_default_line_color(view), 0.5);
-        gl_label_object_set_line_width (GL_LABEL_OBJECT(object),
-                                        gl_view_get_default_line_width(view));
-        gl_label_object_set_line_color (GL_LABEL_OBJECT(object),
-                                        line_color_node);
+        object = gl_label_line_new (view->label, TRUE);
 
-        gl_color_node_free (&line_color_node);
+        gl_label_object_set_position (GL_LABEL_OBJECT(object), x, y, FALSE);
+        gl_label_object_set_size (GL_LABEL_OBJECT(object), 0.0, 0.0, FALSE);
 
         view->create_object = GL_LABEL_OBJECT (object);
         view->create_x0 = x;
         view->create_y0 = y;
 }
 
+
 /*****************************************************************************/
 /* Object creation handler: motion event.                                    */
 /*****************************************************************************/
@@ -426,9 +109,10 @@ gl_view_line_create_motion_event     (glView *view,
 
         w = x - view->create_x0;
         h = y - view->create_y0;
-        gl_label_object_set_size (GL_LABEL_OBJECT(view->create_object), w, h);
+        gl_label_object_set_size (GL_LABEL_OBJECT(view->create_object), w, h, FALSE);
 }
 
+
 /*****************************************************************************/
 /* Object creation handler: button relesase event.                           */
 /*****************************************************************************/
@@ -437,20 +121,24 @@ gl_view_line_create_button_release_event (glView *view,
                                           gdouble x,
                                           gdouble y)
 {
-       glColorNode         *line_color_node;
         gdouble              w, h;
 
-        line_color_node = gl_color_node_new_default ();
-               
         if ((view->create_x0 == x) && (view->create_y0 == y)) {
                 x = view->create_x0 + 36.0;
                 y = view->create_y0 + 36.0;
         }
         w = x - view->create_x0;
         h = y - view->create_y0;
-        gl_label_object_set_size (GL_LABEL_OBJECT(view->create_object), w, h);
-        line_color_node->color = gl_view_get_default_line_color(view);
-        gl_label_object_set_line_color (GL_LABEL_OBJECT(view->create_object), line_color_node);
-        gl_color_node_free (&line_color_node);
+        gl_label_object_set_size (GL_LABEL_OBJECT(view->create_object), w, h, FALSE);
 }
 
+
+
+/*
+ * Local Variables:       -- emacs
+ * mode: C                -- emacs
+ * c-basic-offset: 8      -- emacs
+ * tab-width: 8           -- emacs
+ * indent-tabs-mode: nil  -- emacs
+ * End:                   -- emacs
+ */