2
* Copyright (c) 2007, 2011, Oracle and/or its affiliates. All rights reserved.
4
* This program is free software; you can redistribute it and/or
5
* modify it under the terms of the GNU General Public License as
6
* published by the Free Software Foundation; version 2 of the
9
* This program is distributed in the hope that it will be useful,
10
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
* GNU General Public License for more details.
14
* You should have received a copy of the GNU General Public License
15
* along with this program; if not, write to the Free Software
16
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20
#ifndef _MDC_CANVAS_VIEW_H_
21
#define _MDC_CANVAS_VIEW_H_
23
#include "mdc_canvas_public.h"
25
#include "mdc_layer.h"
26
#include "mdc_events.h"
27
#include "mdc_canvas_item.h"
28
#include "mdc_selection.h"
31
#include <glib/gthread.h>
48
class MYSQLCANVAS_PUBLIC_FUNC CanvasView
50
friend class BackLayer;
51
friend class CanvasViewExtras;
54
typedef std::list<Layer*> LayerList;
56
virtual ~CanvasView();
69
inline void set_user_data(void *data) { _user_data= data; }
70
void *get_user_data() { return _user_data; }
72
void set_tag(const std::string &tag);
73
std::string get_tag() const { return _tag; }
75
mdc::CanvasItem *find_item_with_tag(const std::string &tag);
77
void set_printout_mode(bool flag);
78
bool is_printout() { return _printout_mode; }
80
virtual void update_view_size(int width, int height)= 0;
82
void set_offset(const MySQL::Geometry::Point &offs);
83
virtual void scroll_to(const MySQL::Geometry::Point &offs);
85
void set_zoom(float zoom);
86
float get_zoom() const { return _zoom; };
88
void set_page_size(const MySQL::Geometry::Size &size);
89
MySQL::Geometry::Size get_page_size() const { return _page_size; };
90
void set_page_layout(Count xpages, Count ypages);
91
void get_page_layout(Count &xpages, Count &ypages) { xpages= _x_page_num; ypages= _y_page_num; }
94
MySQL::Geometry::Size get_total_view_size() const;
97
inline void get_view_size(int &w, int &h) const { w= _view_width; h= _view_height; }
99
MySQL::Geometry::Size get_viewable_size() const;
101
MySQL::Geometry::Rect get_viewport() const;
103
MySQL::Geometry::Rect get_viewport_range() const;
105
MySQL::Geometry::Rect get_content_bounds() const;
107
virtual MySQL::Geometry::Point window_to_canvas(int x, int y) const;
108
virtual MySQL::Geometry::Rect window_to_canvas(int x, int y, int w, int h) const;
109
virtual void canvas_to_window(const MySQL::Geometry::Point &pt, int &x, int &y) const;
110
virtual void canvas_to_window(const MySQL::Geometry::Rect &rect, int &x, int &y, int &w, int &h) const;
114
bool get_grid_shown();
116
void set_grid_snapping(bool flag);
117
bool get_grid_snapping();
119
MySQL::Geometry::Point snap_to_grid(const MySQL::Geometry::Point &pos);
120
MySQL::Geometry::Size snap_to_grid(const MySQL::Geometry::Size &size);
122
void set_draws_line_hops(bool flag);
124
Layer *new_layer(const std::string &name);
125
void set_current_layer(Layer *layer);
126
Layer *get_current_layer() const { return _current_layer; }
127
Layer *get_layer(const std::string &name);
128
BackLayer *get_background_layer() const { return _blayer; }
129
InteractionLayer *get_interaction_layer() const { return _ilayer; }
131
void add_layer(Layer *layer);
132
void remove_layer(Layer *layer);
133
virtual LayerList &get_layers();
135
void remove_item(mdc::CanvasItem *item);
137
virtual void raise_layer(Layer *layer, Layer *above= 0);
138
virtual void lower_layer(Layer *layer);
140
CanvasItem *get_item_at(int x, int y);
141
CanvasItem *get_item_at(const MySQL::Geometry::Point &point);
143
CanvasItem *get_leaf_item_at(int x, int y);
144
CanvasItem *get_leaf_item_at(const MySQL::Geometry::Point &point);
146
typedef boost::function<bool (CanvasItem*)> ItemCheckFunc;
147
std::list<CanvasItem*> get_items_bounded_by(const MySQL::Geometry::Rect &rect,
148
const ItemCheckFunc &pred= ItemCheckFunc());
151
void repaint(int x, int y, int width, int height);
153
void set_needs_repaint_all_items();
155
void queue_repaint();
156
void queue_repaint(const MySQL::Geometry::Rect &bounds);
158
virtual void handle_mouse_move(int x, int y, EventState state);
159
virtual void handle_mouse_button(MouseButton button, bool press, int x, int y, EventState state);
160
virtual void handle_mouse_double_click(MouseButton button, int x, int y, EventState state);
162
bool handle_key(const KeyInfo &key, bool press, EventState state);
164
void start_dragging_rectangle(const MySQL::Geometry::Point &pos);
165
MySQL::Geometry::Rect finish_dragging_rectangle();
168
bool focus_item(CanvasItem *item);
169
CanvasItem *get_focused_item();
171
void select_items_inside(const MySQL::Geometry::Rect &rect, SelectType type, Group *group= 0);
173
Selection *get_selection() const { return _selection; };
174
Selection::ContentType get_selected_items();
176
void update_line_crossings(Line *line);
178
virtual bool initialize();
180
const FontSpec &get_default_font();
181
MySQL::Drawing::Color get_selection_color() const { return MySQL::Drawing::Color(0.6, 0.85, 0.95, 1.0); }
182
MySQL::Drawing::Color get_highlight_color() const { return MySQL::Drawing::Color(1, 0.6, 0.0, 0.8); }
183
MySQL::Drawing::Color get_hover_color() const { return MySQL::Drawing::Color(0.85, 0.5, 0.5, 0.8); }
185
inline CairoCtx *cairoctx() const { return _cairo; }
186
virtual bool has_gl() const= 0;
188
virtual Surface *create_temp_surface(const MySQL::Geometry::Size &size) const;
190
void export_png(const std::string &filename, bool crop=false);
191
void export_pdf(const std::string &filename, const MySQL::Geometry::Size &size_in_pt);
192
void export_ps(const std::string &filename, const MySQL::Geometry::Size &size_in_pt);
193
void export_svg(const std::string &filename, const MySQL::Geometry::Size &size_in_pt);
195
void set_event_callbacks(const boost::function<bool (CanvasView*, MouseButton, bool, MySQL::Geometry::Point, EventState)> &button_handler,
196
const boost::function<bool (CanvasView*, MySQL::Geometry::Point, EventState)> &motion_handler,
197
const boost::function<bool (CanvasView*, KeyInfo, EventState, bool)> &key_handler);
200
boost::signals2::signal<void ()>* signal_resized() { return &_resized_signal; }
201
boost::signals2::signal<void (int,int,int,int)>* signal_repaint() { return &_need_repaint_signal; }
202
boost::signals2::signal<void ()>* signal_viewport_changed() { return &_viewport_changed_signal; }
203
boost::signals2::signal<void ()>* signal_zoom_changed() { return &_zoom_changed_signal; }
205
void enable_debug(bool flag) { _debug= flag; }
206
inline bool debug_enabled() { return _debug; }
208
double get_fps() { return _fps; }
209
inline void bookkeep_cache_mem(int amount) { _total_item_cache_mem+= amount; }
211
void paint_item_cache(CairoCtx *cr, double x, double y, cairo_surface_t *cached_item, double alpha=1.0);
217
cairo_surface_t *_crsurface;
219
cairo_matrix_t _trmatrix;
223
int _repaints_missed;
225
FontSpec _default_font;
229
InteractionLayer *_ilayer;
230
Layer *_current_layer;
232
CanvasItem *_focused_item;
234
Selection *_selection;
236
MySQL::Geometry::Size _page_size;
241
MySQL::Geometry::Point _offset;
242
MySQL::Geometry::Point _extra_offset;
249
bool _line_hop_rendering;
256
size_t _total_item_cache_mem;
258
boost::signals2::signal<void ()> _resized_signal;
259
boost::signals2::signal<void (int,int,int,int)> _need_repaint_signal;
260
boost::signals2::signal<void ()> _viewport_changed_signal;
261
boost::signals2::signal<void ()> _zoom_changed_signal;
263
boost::function<bool (CanvasView*, MouseButton, bool, MySQL::Geometry::Point, EventState)> _button_event_relay;
264
boost::function<bool (CanvasView*, MySQL::Geometry::Point, EventState)> _motion_event_relay;
265
boost::function<bool (CanvasView*, KeyInfo, EventState, bool)> _key_event_relay;
267
CanvasView(int width, int height);
269
virtual void begin_repaint(int wx, int wy, int ww, int wh)= 0;
270
virtual void end_repaint()= 0;
272
void repaint_area(const MySQL::Geometry::Rect &rect, int wx, int wy, int ww, int wh);
274
void update_offsets();
275
void apply_transformations();
276
void apply_transformations_gl();
277
void reset_transformations_gl();
278
void apply_transformations_for_conversion(cairo_matrix_t *matrix) const;
280
bool perform_auto_scroll(const MySQL::Geometry::Point &mouse_pos);
282
void render_for_export(const MySQL::Geometry::Rect &bounds, CairoCtx *cr);
286
MySQL::Geometry::Point pos;
289
EventState _event_state;
290
CanvasItem *_last_click_item;
291
CanvasItem *_last_over_item;
292
std::vector<ClickInfo> _last_click_info;
293
MySQL::Geometry::Point _last_mouse_pos;
295
GStaticRecMutex _lock;
297
static void *canvas_item_destroyed(void *data);
298
void set_last_click_item(CanvasItem *item);
299
void set_last_over_item(CanvasItem *item);
305
#endif /* _MDC_CANVAS_VIEW_H_ */