The Gnome Chemistry Utils  0.12.13
tool.h
Go to the documentation of this file.
1 // -*- C++ -*-
2 
3 /*
4  * GChemPaint library
5  * tool.h
6  *
7  * Copyright (C) 2001-2009 Jean Bréfort <jean.brefort@normalesup.org>
8  *
9  * This program is free software; you can redistribute it and/or
10  * modify it under the terms of the GNU General Public License as
11  * published by the Free Software Foundation; either version 2 of the
12  * License, or (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program; if not, write to the Free Software
21  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301
22  * USA
23  */
24 
25 #ifndef GCHEMPAINT_TOOL_H
26 #define GCHEMPAINT_TOOL_H
27 
28 #include <gcu/macros.h>
29 #include <gtk/gtk.h>
30 #include <libxml/tree.h>
31 #include <vector>
32 #include <set>
33 #include <string>
34 
35 namespace gcu {
36  class Dialog;
37  class Object;
38 }
39 
40 namespace gccv {
41  class Item;
42 }
43 
45 namespace gcp {
46 
47 class Application;
48 class View;
49 class WidgetData;
50 class Operation;
51 
55 class Tool
56 {
57 public:
64  Tool (gcp::Application *App, std::string Id);
68  virtual ~Tool ();
69 
86  bool OnClicked (View* pView, gcu::Object* pObject, double x, double y, unsigned int state);
87 
96  void OnDrag (double x, double y, unsigned int state);
107  void OnMotion (View* pView, gcu::Object* pObject, double x, double y, unsigned int state);
115  void OnLeaveNotify (View* pView, unsigned int state);
124  void OnRelease (double x, double y, unsigned int state);
138  bool OnRightButtonClicked (View* pView, gcu::Object* pObject, double x, double y, GtkUIManager *UIManager);
146  bool Activate (bool bState);
150  std::string& GetName () {return name;}
159  virtual bool OnRightButtonClicked (GtkUIManager *UIManager);
165  virtual void Activate ();
172  virtual bool Deactivate ();
180  void OnKeyPressed (unsigned int code) {m_nState |= code; OnChangeState ();}
188  void OnKeyReleased (unsigned int code) {if (m_nState & code) m_nState -= code; OnChangeState ();}
195  virtual bool OnKeyPress (GdkEventKey *event);
202  virtual bool OnKeyRelease (GdkEventKey *event);
212  virtual bool NotifyViewChange ();
217  virtual bool DeleteSelection ();
222  virtual bool CopySelection (GtkClipboard *clipboard);
227  virtual bool CutSelection (GtkClipboard *clipboard);
232  virtual bool PasteSelection (GtkClipboard *clipboard);
237  virtual void AddSelection (WidgetData* data);
242  virtual bool OnReceive (GtkClipboard *clipboard, GtkSelectionData *data, int type);
248  virtual bool OnUndo ();
254  virtual bool OnRedo ();
260  virtual void PushNode (xmlNodePtr node);
266  virtual GtkWidget *GetPropertyPage ();
274  virtual char const *GetHelpTag () {return "";}
284  virtual void OnConfigChanged () {}
285 
286 protected:
296  virtual bool OnClicked ();
303  virtual void OnDrag ();
310  virtual void OnMotion ();
317  virtual void OnLeaveNotify ();
324  virtual void OnRelease ();
329  virtual void OnChangeState ();
330 
331 protected:
335  double m_x0;
339  double m_y0;
344  double m_x1;
349  double m_y1;
353  double m_x;
357  double m_y;
377  GtkWidget *m_pWidget;
394  unsigned int m_nState;
402  std::set<std::string> ModifiedObjects;
408 
409 private:
410  double lastx, lasty;
411  std::string name;
412  bool m_bPressed;
413 
420 GCU_PROT_PROP (bool, OwnStatus)
421 };
422 
423 } // namespace gcp
424 
425 #endif // GCHEMPAINT_TOOL_H