Laxkit  0.0.7.1
aninterface.h
1 //
2 //
3 // The Laxkit, a windowing toolkit
4 // Please consult http://laxkit.sourceforge.net about where to send any
5 // correspondence about this software.
6 //
7 // This library is free software; you can redistribute it and/or
8 // modify it under the terms of the GNU Library General Public
9 // License as published by the Free Software Foundation; either
10 // version 2 of the License, or (at your option) any later version.
11 //
12 // This library is distributed in the hope that it will be useful,
13 // but WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 // Library General Public License for more details.
16 //
17 // You should have received a copy of the GNU Library General Public
18 // License along with this library; if not, write to the Free Software
19 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 //
21 // Copyright (C) 2004-2012 by Tom Lechner
22 //
23 #ifndef _LAX_ANINTERFACE_H
24 #define _LAX_ANINTERFACE_H
25 
26 #include <lax/displayer.h>
27 #include <lax/interfaces/somedata.h>
28 #include <lax/interfaces/viewportwindow.h>
29 #include <lax/menuinfo.h>
30 #include <lax/buttondowninfo.h>
31 #include <lax/shortcuts.h>
32 
33 
34 namespace LaxInterfaces {
35 
36 //for anInterface::interface_type:
37 enum anInterFaceStyles {
38  INTERFACE_Unknown=0,
39  INTERFACE_Overlay,
40  INTERFACE_Tool,
41  INTERFACE_Child,
42  INTERFACE_MAX
43 };
44 
45 class ViewportWindow;
46 class ObjectContext;
47 
48 //------------------------------ anInterface ------------------------------------------
49 class anInterface : virtual public Laxkit::EventReceiver,
50  virtual public LaxFiles::DumpUtility
51 {
52  protected:
53  Laxkit::ButtonDownInfo buttondown;
56 
57  public:
58  char *name;
59  int id;
60  unsigned long style;
62 
66 
67  int primary;
68  int needtodraw;
69 
70  anInterface();
71  anInterface(int nid);
72  anInterface(int nid,Laxkit::Displayer *ndp);
73  anInterface(anInterface *nowner,int nid);
74  anInterface(anInterface *nowner,int nid,Laxkit::Displayer *ndp);
75  virtual ~anInterface();
76  virtual anInterface *duplicate(anInterface *dup);
78  virtual int PerformAction(int actionnumber);
79 
80  virtual const char *IconId() { return ""; }
81  virtual const char *Name() { return "An Interface"; }
82  virtual const char *whattype() { return "anInterface"; }
83  virtual const char *whatdatatype() = 0;
84  virtual int draws(const char *atype) { return whatdatatype()!=NULL && !strcmp(whatdatatype(),atype); }
85 
86  virtual void Clear();
87  virtual int InterfaceOn() { return 0; }
88  virtual int InterfaceOff() { return 0; }
89  virtual int RemoveChild();
90  virtual int AddChild(LaxInterfaces::anInterface *ch, int absorbcount, int addbefore);
91 
92  virtual int Needtodraw() { return needtodraw; }
93  virtual int Needtodraw(int n) { return needtodraw|=n; }
94 
95  // return 0 if interface absorbs event, MouseMove never absorbs: must return 1;
96  virtual int LBDown(int x,int y,unsigned int state,int count, const Laxkit::LaxMouse *d) { return 1; }
97  virtual int MBDown(int x,int y,unsigned int state,int count, const Laxkit::LaxMouse *d) { return 1; }
98  virtual int RBDown(int x,int y,unsigned int state,int count, const Laxkit::LaxMouse *d) { return 1; }
99  virtual int LBUp(int x,int y,unsigned int state, const Laxkit::LaxMouse *d) { return 1; }
100  virtual int MBUp(int x,int y,unsigned int state, const Laxkit::LaxMouse *d) { return 1; }
101  virtual int RBUp(int x,int y,unsigned int state, const Laxkit::LaxMouse *d) { return 1; }
102  virtual int WheelUp (int x,int y,unsigned int state,int count, const Laxkit::LaxMouse *d) { return 1; }
103  virtual int WheelDown(int x,int y,unsigned int state,int count, const Laxkit::LaxMouse *d) { return 1; }
104  virtual int MouseMove(int x,int y,unsigned int state, const Laxkit::LaxMouse *d) { return 1; }
105  virtual int CharInput(unsigned int ch, const char *buffer,int len,unsigned int state, const Laxkit::LaxKeyboard *d) { return 1; }
106  virtual int KeyUp(unsigned int ch,unsigned int state, const Laxkit::LaxKeyboard *d) { return 1; }
107  virtual int DeviceChange(const Laxkit::DeviceEventData *e) { return 1; }
108 
109  virtual int Event(const Laxkit::EventData *e, const char *mes) { return 1; }
110  virtual void ExposeChange(Laxkit::ScreenEventData *e) { Needtodraw(1); }
111  virtual void ViewportResized() {}
112  virtual void Mapped() {}
113  virtual void Unmapped() {}
114  virtual int Refresh() { needtodraw=0; return 0; }
115  virtual void PostMessage(const char *message);
116 
117  virtual Laxkit::MenuInfo *ContextMenu(int x,int y,int deviceid) { return NULL; }
118 
119  virtual int UseThis(int id,int ndata) { return 0; }
120  virtual int UseThis(Laxkit::anObject *ndata,unsigned int mask=0) { return 0; }
121  virtual int UseThisObject(ObjectContext *oc) { return 0; }
122  virtual int DrawData(Laxkit::anObject *ndata,
123  Laxkit::anObject *a1=NULL,Laxkit::anObject *a2=NULL,int info=0) { return 1; }
124 
126 
127  //--- SomeData and Viewport oriented functions:
128  virtual void Clear(SomeData *d) = 0;
129  virtual ObjectContext *Context();
130  virtual void Dp(Laxkit::Displayer *ndp);
131  virtual int DrawDataDp(Laxkit::Displayer *tdp,SomeData *tdata,
132  Laxkit::anObject *a1=NULL,Laxkit::anObject *a2=NULL,int info=1);
133 
134  // if owning window can be cast to ViewportWindow, then these call corresponding funcs in it:
135  virtual flatpoint realtoscreen(flatpoint r);
136  virtual flatpoint screentoreal(int x,int y);
137  virtual double Getmag(int c=0);
138  virtual double GetVMag(int x,int y);
139 
140  //input and output
141  virtual void dump_out(FILE *f,int indent,int what,Laxkit::anObject *savecontext);
142  virtual void dump_in_atts(LaxFiles::Attribute *att,int flag,Laxkit::anObject *loadcontext);
143 };
144 
145 
146 } // namespace LaxInterfaces
147 
148 
149 #endif
150 

Mon Feb 17 2014 11:52:56, Laxkit