3
* Copyright (C) 2007 Murray Cumming
5
* This program is free software; you can redistribute it and/or
6
* modify it under the terms of the GNU General Public License as
7
* published by the Free Software Foundation; either version 2 of the
8
* License, or (at your option) any later version.
10
* This program is distributed in the hope that it will be useful, but
11
* WITHOUT ANY WARRANTY; without even the implied warranty of
12
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13
* General Public License for more details.
15
* You should have received a copy of the GNU General Public
16
* License along with this program; if not, write to the
17
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18
* Boston, MA 02111-1307, USA.
21
#ifndef GLOM_UTILITY_WIDGETS_CANVAS_ITEM_MOVABLE_H
22
#define GLOM_UTILITY_WIDGETS_CANVAS_ITEM_MOVABLE_H
24
#include "canvas_item_movable.h"
25
#include "canvas_group_grid.h"
26
#include <goocanvasmm/item.h>
27
#include <gdkmm/cursor.h>
32
class CanvasItemMovable : virtual public Glib::ObjectBase
36
virtual ~CanvasItemMovable();
40
/* Get the position of the item.
41
* For some items, this is an arbitrary part of the item,
42
* such as the top-left of a rectangle,
43
* or the first point in a line.
45
virtual void get_xy(double& x, double& y) const = 0;
48
* This should be the same arbitrary part of the item that is used by get_xy().
49
* All other parts of the item will move by the same offset.
51
virtual void set_xy(double x, double y) = 0;
55
virtual void get_width_height(double& width, double& height) const = 0;
59
virtual void set_width_height(double width, double height) = 0;
61
void set_drag_cursor(Gdk::CursorType cursor);
62
void set_drag_cursor(const Gdk::Cursor& cursor);
64
typedef sigc::signal<void> type_signal_moved;
66
/// This signal is emitted when the canvas item is moved by the user.
67
type_signal_moved signal_moved();
69
/** void on_show_context(guint button, guint32 activate_time);
71
typedef sigc::signal<void, guint, guint32> type_signal_show_context;
72
type_signal_show_context signal_show_context();
74
/** Provide information about a grid or rules,
75
* to which the item should snap when moving:
77
* @param grid: This must exist for as long as the canvas item.
79
virtual void set_grid(const Glib::RefPtr<const CanvasGroupGrid>& grid);
81
/** Restrict drag movement (via dragging) to the x axis or the y axis,
82
* or prevent all drag movement.
84
void set_movement_allowed(bool vertical = true, bool horizontal = true);
86
///A convenience function, to avoid repeating a large if/else block.
87
static Glib::RefPtr<CanvasItemMovable> cast_to_movable(const Glib::RefPtr<Goocanvas::Item>& item);
88
static Glib::RefPtr<const CanvasItemMovable> cast_const_to_movable(const Glib::RefPtr<const Goocanvas::Item>& item);
90
static Glib::RefPtr<Goocanvas::Item> cast_to_item(const Glib::RefPtr<CanvasItemMovable>& item);
91
static Glib::RefPtr<const Goocanvas::Item> cast_const_to_item(const Glib::RefPtr<const CanvasItemMovable>& item);
95
virtual Goocanvas::Canvas* get_parent_canvas_widget() = 0;
97
virtual void snap_position(double& x, double& y) const;
99
void set_cursor(const Gdk::Cursor& cursor);
103
//These should really be protected, but the compiler doesn't allow it:
104
bool on_button_press_event(const Glib::RefPtr<Goocanvas::Item>& target, GdkEventButton* event);
105
bool on_motion_notify_event(const Glib::RefPtr<Goocanvas::Item>& target, GdkEventMotion* event);
106
bool on_button_release_event(const Glib::RefPtr<Goocanvas::Item>& target, GdkEventButton* event);
107
bool on_enter_notify_event(const Glib::RefPtr<Goocanvas::Item>& target, GdkEventCrossing* event);
108
bool on_leave_notify_event(const Glib::RefPtr<Goocanvas::Item>& target, GdkEventCrossing* event);
112
bool m_dragging_vertical_only, m_dragging_horizontal_only; //Set by using Ctrl while dragging.
113
double m_drag_start_cursor_x, m_drag_start_cursor_y;
114
double m_drag_start_position_x, m_drag_start_position_y;
115
Gdk::Cursor m_drag_cursor;
117
Glib::RefPtr<const CanvasGroupGrid> m_grid;
119
bool m_allow_vertical_movement, m_allow_horizontal_movement;
121
type_signal_moved m_signal_moved;
122
type_signal_show_context m_signal_show_context;
127
#endif //GLOM_UTILITY_WIDGETS_CANVAS_ITEM_MOVABLE_H