~ubuntu-branches/ubuntu/quantal/mysql-workbench/quantal

« back to all changes in this revision

Viewing changes to library/canvas/src/mdc_canvas_view.h

  • Committer: Package Import Robot
  • Author(s): Dmitry Smirnov
  • Date: 2012-03-01 21:57:30 UTC
  • Revision ID: package-import@ubuntu.com-20120301215730-o7y8av8y38n162ro
Tags: upstream-5.2.38+dfsg
ImportĀ upstreamĀ versionĀ 5.2.38+dfsg

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* 
 
2
 * Copyright (c) 2007, 2011, Oracle and/or its affiliates. All rights reserved.
 
3
 *
 
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
 
7
 * License.
 
8
 * 
 
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.
 
13
 * 
 
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
 
17
 * 02110-1301  USA
 
18
 */
 
19
 
 
20
#ifndef _MDC_CANVAS_VIEW_H_
 
21
#define _MDC_CANVAS_VIEW_H_
 
22
 
 
23
#include "mdc_canvas_public.h"
 
24
 
 
25
#include "mdc_layer.h"
 
26
#include "mdc_events.h"
 
27
#include "mdc_canvas_item.h"
 
28
#include "mdc_selection.h"
 
29
 
 
30
#ifndef _WIN32
 
31
#include <glib/gthread.h>
 
32
#endif
 
33
 
 
34
BEGIN_MDC_DECLS
 
35
 
 
36
class Line;
 
37
 
 
38
class BackLayer;
 
39
 
 
40
 
 
41
enum SelectType
 
42
{
 
43
  SelectSet,
 
44
  SelectAdd,
 
45
  SelectToggle
 
46
};
 
47
 
 
48
class MYSQLCANVAS_PUBLIC_FUNC CanvasView
 
49
{
 
50
  friend class BackLayer;
 
51
  friend class CanvasViewExtras;
 
52
 
 
53
public:
 
54
  typedef std::list<Layer*> LayerList;
 
55
 
 
56
  virtual ~CanvasView();
 
57
 
 
58
  void lock_ui();
 
59
  void unlock_ui();
 
60
 
 
61
  void lock();
 
62
  void unlock();
 
63
 
 
64
  void lock_redraw();
 
65
  void unlock_redraw();
 
66
 
 
67
  void pre_destroy();
 
68
 
 
69
  inline void set_user_data(void *data) { _user_data= data; }
 
70
  void *get_user_data() { return _user_data; }
 
71
  
 
72
  void set_tag(const std::string &tag);
 
73
  std::string get_tag() const { return _tag; }
 
74
 
 
75
  mdc::CanvasItem *find_item_with_tag(const std::string &tag);
 
76
  
 
77
  void set_printout_mode(bool flag);
 
78
  bool is_printout() { return _printout_mode; }
 
79
 
 
80
  virtual void update_view_size(int width, int height)= 0;
 
81
 
 
82
  void set_offset(const MySQL::Geometry::Point &offs);
 
83
  virtual void scroll_to(const MySQL::Geometry::Point &offs);
 
84
 
 
85
  void set_zoom(float zoom);
 
86
  float get_zoom() const { return _zoom; };
 
87
 
 
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; }
 
92
 
 
93
  // logical view size
 
94
  MySQL::Geometry::Size get_total_view_size() const;
 
95
  
 
96
  // physical view size
 
97
  inline void get_view_size(int &w, int &h) const { w= _view_width; h= _view_height; }
 
98
 
 
99
  MySQL::Geometry::Size get_viewable_size() const;
 
100
  
 
101
  MySQL::Geometry::Rect get_viewport() const;
 
102
 
 
103
  MySQL::Geometry::Rect get_viewport_range() const;
 
104
  
 
105
  MySQL::Geometry::Rect get_content_bounds() const;
 
106
 
 
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;
 
111
 
 
112
  void show_grid();
 
113
  void hide_grid();
 
114
  bool get_grid_shown();
 
115
 
 
116
  void set_grid_snapping(bool flag);
 
117
  bool get_grid_snapping();
 
118
  
 
119
  MySQL::Geometry::Point snap_to_grid(const MySQL::Geometry::Point &pos);
 
120
  MySQL::Geometry::Size snap_to_grid(const MySQL::Geometry::Size &size);
 
121
 
 
122
  void set_draws_line_hops(bool flag);
 
123
 
 
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; }
 
130
 
 
131
  void add_layer(Layer *layer);
 
132
  void remove_layer(Layer *layer);
 
133
  virtual LayerList &get_layers();
 
134
  
 
135
  void remove_item(mdc::CanvasItem *item);
 
136
 
 
137
  virtual void raise_layer(Layer *layer, Layer *above= 0);
 
138
  virtual void lower_layer(Layer *layer);
 
139
 
 
140
  CanvasItem *get_item_at(int x, int y);
 
141
  CanvasItem *get_item_at(const MySQL::Geometry::Point &point);
 
142
  
 
143
  CanvasItem *get_leaf_item_at(int x, int y);
 
144
  CanvasItem *get_leaf_item_at(const MySQL::Geometry::Point &point);
 
145
  
 
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());
 
149
 
 
150
  void repaint();
 
151
  void repaint(int x, int y, int width, int height);
 
152
 
 
153
  void set_needs_repaint_all_items();
 
154
 
 
155
  void queue_repaint();
 
156
  void queue_repaint(const MySQL::Geometry::Rect &bounds);
 
157
 
 
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);
 
161
 
 
162
  bool handle_key(const KeyInfo &key, bool press, EventState state);
 
163
 
 
164
  void start_dragging_rectangle(const MySQL::Geometry::Point &pos);
 
165
  MySQL::Geometry::Rect finish_dragging_rectangle();
 
166
 
 
167
 
 
168
  bool focus_item(CanvasItem *item);
 
169
  CanvasItem *get_focused_item();
 
170
  
 
171
  void select_items_inside(const MySQL::Geometry::Rect &rect, SelectType type, Group *group= 0);
 
172
  
 
173
  Selection *get_selection() const { return _selection; };
 
174
  Selection::ContentType get_selected_items();
 
175
 
 
176
  void update_line_crossings(Line *line);
 
177
 
 
178
  virtual bool initialize();
 
179
 
 
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); }
 
184
 
 
185
  inline CairoCtx *cairoctx() const { return _cairo; }
 
186
  virtual bool has_gl() const= 0;
 
187
 
 
188
  virtual Surface *create_temp_surface(const MySQL::Geometry::Size &size) const;
 
189
 
 
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);
 
194
 
 
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);
 
198
 
 
199
 
 
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; }
 
204
 
 
205
  void enable_debug(bool flag) { _debug= flag; }
 
206
  inline bool debug_enabled() { return _debug; }
 
207
 
 
208
  double get_fps() { return _fps; }
 
209
  inline void bookkeep_cache_mem(int amount) { _total_item_cache_mem+= amount; }
 
210
 
 
211
  void paint_item_cache(CairoCtx *cr, double x, double y, cairo_surface_t *cached_item, double alpha=1.0);
 
212
 
 
213
protected:
 
214
  void *_user_data;
 
215
  std::string _tag;
 
216
 
 
217
  cairo_surface_t *_crsurface;
 
218
  CairoCtx *_cairo;
 
219
  cairo_matrix_t _trmatrix;
 
220
 
 
221
  int _ui_lock;
 
222
  int _repaint_lock;
 
223
  int _repaints_missed;
 
224
 
 
225
  FontSpec _default_font;
 
226
 
 
227
  LayerList _layers;
 
228
  BackLayer *_blayer;
 
229
  InteractionLayer *_ilayer;
 
230
  Layer *_current_layer;
 
231
 
 
232
  CanvasItem *_focused_item;
 
233
 
 
234
  Selection *_selection;
 
235
 
 
236
  MySQL::Geometry::Size _page_size;
 
237
  Count _x_page_num;
 
238
  Count _y_page_num;
 
239
 
 
240
  float _zoom;
 
241
  MySQL::Geometry::Point _offset;
 
242
  MySQL::Geometry::Point _extra_offset;
 
243
  int _view_width;
 
244
  int _view_height;
 
245
 
 
246
  float _grid_size;
 
247
  bool _grid_snapping;
 
248
  bool _printout_mode;
 
249
  bool _line_hop_rendering;
 
250
 
 
251
  bool _destroying;
 
252
  bool _debug;
 
253
 
 
254
  double _fps;
 
255
 
 
256
  size_t _total_item_cache_mem;
 
257
  
 
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;
 
262
  
 
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;
 
266
 
 
267
  CanvasView(int width, int height);
 
268
 
 
269
  virtual void begin_repaint(int wx, int wy, int ww, int wh)= 0;
 
270
  virtual void end_repaint()= 0;
 
271
 
 
272
  void repaint_area(const MySQL::Geometry::Rect &rect, int wx, int wy, int ww, int wh);
 
273
 
 
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;
 
279
 
 
280
  bool perform_auto_scroll(const MySQL::Geometry::Point &mouse_pos);
 
281
  
 
282
  void render_for_export(const MySQL::Geometry::Rect &bounds, CairoCtx *cr);
 
283
  
 
284
private:
 
285
  struct ClickInfo {
 
286
    MySQL::Geometry::Point pos;
 
287
  };
 
288
 
 
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;
 
294
  
 
295
  GStaticRecMutex _lock;
 
296
 
 
297
  static void *canvas_item_destroyed(void *data);
 
298
  void set_last_click_item(CanvasItem *item);
 
299
  void set_last_over_item(CanvasItem *item);
 
300
};
 
301
 
 
302
 
 
303
END_MDC_DECLS
 
304
 
 
305
#endif /* _MDC_CANVAS_VIEW_H_ */