MySQL Workbench  6.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
view.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2008, 2014, 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 _MFORMS_VIEW_H_
21 #define _MFORMS_VIEW_H_
22 
23 #include <boost/signals2.hpp>
24 
25 #include "mforms/base.h"
26 #include "mforms/utilities.h"
27 
28 #include "base/geometry.h"
29 #include "base/trackable.h"
30 #include "base/drawing.h"
31 
32 namespace mforms {
33 
34  // Predefined drag formats used during a drag session. Custom definitions are possible too.
35  const std::string DragFormatText = "com.mysql.workbench.text"; // UTF-8 encoded text.
36  const std::string DragFormatFileName = "com.mysql.workbench.file"; // A plain file name (UTF-8 encoded).
37 
38  class View;
39 
40  enum Alignment
41  {
52 
53  //
55  };
56 
58  {
59 #ifndef SWIG
60  bool bold;
61  bool italic;
62  base::Color color;
63  TextAttributes() : bold(false), italic(false), color(base::Color::Invalid()) {}
64 #endif
65  TextAttributes(const std::string &c, bool b, bool i) : bold(b), italic(i), color(base::Color::parse(c)) {}
66  };
67 
68  // Mouse button indicators for mouse handling routines.
69  enum MouseButton {
73 
74  MouseButtonNone = 0x80, // Sometimes the values for the mouse buttons are hard coded, so better use a high value for this.
75  // TODO: identify hard coded values and replace them.
76  };
77 
82  };
83 
84  struct DragDetails {
85  base::Point location; // Position of the mouse in client coordinates.
86  DragOperation allowedOperations; // A combination of flags that determine the allowed actions.
87 
88  cairo_surface_t *image; // The drag image to show (owned by the initiator of the operation.
89  // This must be an image surface in ARGB32 format.
90  // When doing text dragging this image can be NULL in which case
91  // the platforms generate a drag image from the given text.
92  base::Point hotspot; // The position of the mouse within the drag image.
93 
95  {
96  location = base::Point();
98  image = NULL;
99  hotspot = base::Point();
100  }
101  };
102 
103 #ifndef SWIG
104 
112  {
113  public:
120  virtual DragOperation drag_over(View *sender, base::Point p, const std::vector<std::string> &formats) = 0;
121 
128  virtual DragOperation files_dropped(View *sender, base::Point p, const std::vector<std::string> &file_names) { return DragOperationNone; };
129 
134  virtual DragOperation text_dropped(View *sender, base::Point p, const std::string &text) { return DragOperationNone; };
135 
143  virtual DragOperation data_dropped(View *sender, base::Point p, void *data, const std::string &format) { return DragOperationNone; };
144 
145  };
146 #endif
147 
148 #ifndef DOXYGEN_SHOULD_SKIP_THIS
149 #ifndef SWIG
150  struct ViewImplPtrs
151  {
152  void (*destroy)(View *self);
153 
154  int (*get_width)(View *self);
155  int (*get_height)(View *self);
156  int (*get_preferred_width)(View *self);
157  int (*get_preferred_height)(View *self);
158  void (*set_size)(View *self, int, int);
159  void (*set_padding)(View *self, int, int, int, int); // left, top, right, bottom
160 
161  int (*get_x)(View *self);
162  int (*get_y)(View *self);
163  void (*set_position)(View *self, int, int);
164  std::pair<int, int> (*client_to_screen)(View *self, int, int);
165  std::pair<int, int> (*screen_to_client)(View *self, int, int);
166 
167  void (*show)(View *self, bool);
168  bool (*is_shown)(View *self);
169  bool (*is_fully_visible)(View *self);
170 
171  void (*set_tooltip)(View *self, const std::string&);
172  void (*set_name)(View *self, const std::string&);
173  void (*set_font)(View *self, const std::string&);
174 
175  void (*set_enabled)(View *self, bool);
176  bool (*is_enabled)(View *self);
177  void (*relayout)(View *self);
178  void (*set_needs_repaint)(View *self);
179 
180  void (*suspend_layout)(View *self, bool);
181  void (*set_front_color)(View *self, const std::string&);
182  std::string (*get_front_color)(View *self);
183  void (*set_back_color)(View *self, const std::string&);
184  std::string (*get_back_color)(View *self);
185  // for containers only
186  void (*set_back_image)(View *self, const std::string&, Alignment alignment);
187 
188  void (*flush_events)(View *self);
189  void (*focus)(View *self);
190 
191  void (*register_drop_formats)(View *self, DropDelegate *target, const std::vector<std::string>&);
192  DragOperation (*drag_text)(View *self, DragDetails details, const std::string &text);
193  DragOperation (*drag_data)(View *self, DragDetails details, void *data,
194  const std::string &format);
195  };
196 #endif
197 #endif
198 
199  class Form;
200 
201  class MFORMS_EXPORT View : public Object, public base::trackable
202  {
203  friend class ControlFactory;
204 
205  private:
206  std::string _name;
208 
209  boost::signals2::signal<void ()> _signal_resized;
210 
211  protected:
212  View();
213 
214  ViewImplPtrs *_view_impl;
216  std::vector<std::pair<View*, bool> > _subviews;
217 
218  void cache_view(View *sv);
219  virtual void remove_from_cache(View *sv);
220  int get_subview_index(View *sv);
221  View *get_subview_at_index(int index);
222 
223  // This works only for containers so is made public in the Container subclass
224  virtual void set_back_image(const std::string& path, Alignment alignment);
225  public:
226  virtual ~View();
227 
228  virtual void set_managed();
229 
230  View *find_subview(const std::string &name);
231  bool contains_subview(View* subview);
232  void clear_subviews();
233 
234  void set_name(const std::string &name);
235  void set_tooltip(const std::string &text);
236  void set_font(const std::string &fontDescription); // e.g. "Trebuchet MS bold 9"
237  std::string get_name();
238  void set_parent(View *parent);
239  View *get_parent() const;
240  Form *get_parent_form() const;
241  virtual int get_width();
242  virtual int get_height();
243  virtual int get_preferred_width();
244  virtual int get_preferred_height();
245  virtual int get_x();
246  virtual int get_y();
247  virtual void set_position(int x, int y);
248  virtual void set_size(int width, int height);
249 
250  std::pair<int, int>client_to_screen(int x, int y);
251  std::pair<int, int>screen_to_client(int x, int y);
252 
256  void show(bool flag= true);
257 
261  bool is_shown();
262 
266  bool is_fully_visible();
267 
271  void set_enabled(bool flag);
272 
276  bool is_enabled();
277 
281  void set_needs_repaint();
282 
283  virtual void relayout();
284  virtual void set_layout_dirty(bool value);
285  virtual bool is_layout_dirty();
286 
291  void suspend_layout();
292 
296  void resume_layout();
297 
301  void set_front_color(const std::string& color);
302 
306  std::string get_front_color();
307 
311  void set_back_color(const std::string& color);
312 
316  std::string get_back_color();
317 
318 
319  //Below code is used only for debug purpose.
320  //It's using the object::retain_count.
321 #ifdef _0
322  void show_retain_counts(int depth=0);
323 #endif
324 
328  virtual std::string get_string_value() { return ""; }
329 
333  virtual int get_int_value() { return 0; }
334 
338  virtual bool get_bool_value() { return false; }
339 
343  virtual void flush_events();
344 
348  virtual void focus();
349 
350 #ifndef SWIG
351 
357  void register_drop_formats(DropDelegate *target, const std::vector<std::string> &drop_formats);
358 
363  DragOperation do_drag_drop(DragDetails details, const std::string &text);
364  DragOperation do_drag_drop(DragDetails details, void *data, const std::string &format);
365 #endif
366 
367 #ifndef DOXYGEN_SHOULD_SKIP_THIS
368 #ifndef SWIG
369  // Events called by the platform code. Returns a bool value to indicate if the event was handled.
370  // False means the platform should do whatever it needs with that event.
371  // Note: these functions are only called if the platform control supports this type of mouse handling.
372  // Examples are: all containers (Panel, ScrollPanel, Box, Table) and DrawBox.
373  virtual bool mouse_down(MouseButton button, int x, int y) { return false; }
374  virtual bool mouse_up(MouseButton button, int x, int y) { return false; }
375  virtual bool mouse_click(MouseButton button, int x, int y) { return false; }
376  virtual bool mouse_double_click(MouseButton button, int x, int y) { return false; }
377  virtual bool mouse_enter() { return false; }
378  virtual bool mouse_leave() { return false; }
379  virtual bool mouse_move(MouseButton button, int x, int y) { return false; }
380 #endif
381 #endif
382 
383  void focus_changed();
384 
386  virtual void resize();
387 
388  boost::signals2::signal<void ()>* signal_resized() { return &_signal_resized; }
389  };
390 };
391 
392 #endif
virtual bool get_bool_value()
Get bool value from the view if it's holding some.
Definition: view.h:338
Delegate class for events caused by a drop operation.
Definition: view.h:111
std::string _name
Definition: view.h:206
base::Point location
Definition: view.h:85
boost::signals2::signal< void()> * signal_resized()
Definition: view.h:388
A standalone, top-level window.
Definition: form.h:72
virtual int get_int_value()
Get int value from the view if it's holding some.
Definition: view.h:333
TextAttributes(const std::string &c, bool b, bool i)
Definition: view.h:65
DragOperation
Definition: view.h:78
MouseButton
Definition: view.h:69
#define MFORMS_EXPORT
Definition: base.h:33
DragOperation allowedOperations
Definition: view.h:86
boost::signals2::signal< void()> _signal_resized
Definition: view.h:209
ViewImplPtrs * _view_impl
Definition: view.h:214
std::vector< std::pair< View *, bool > > _subviews
Definition: view.h:216
Alignment
Definition: view.h:40
const std::string DragFormatFileName
Definition: view.h:36
virtual DragOperation data_dropped(View *sender, base::Point p, void *data, const std::string &format)
Called when any custom data was dropped on the receiver (only called if drag_over returned true)...
Definition: view.h:143
virtual DragOperation files_dropped(View *sender, base::Point p, const std::vector< std::string > &file_names)
Called when files were dropped on the receiver (only called if drag_over returned true)...
Definition: view.h:128
base::Color color
Definition: view.h:62
bool _layout_dirty
Definition: view.h:207
virtual DragOperation text_dropped(View *sender, base::Point p, const std::string &text)
Called when text was dropped on the receiver (only called if drag_over returned true).
Definition: view.h:134
View * _parent
Definition: view.h:215
base::Point hotspot
Definition: view.h:92
cairo_surface_t * image
Definition: view.h:88
virtual std::string get_string_value()
Get string value from the view if it's holding some.
Definition: view.h:328
const std::string DragFormatText
Definition: view.h:35
MySQL Workbench 6.1 documentation