Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members

FXObject.h
1 /********************************************************************************
2 * *
3 * T o p l e v e l O b j e c t *
4 * *
5 *********************************************************************************
6 * Copyright (C) 1997,2024 by Jeroen van der Zijp. All Rights Reserved. *
7 *********************************************************************************
8 * This library is free software; you can redistribute it and/or modify *
9 * it under the terms of the GNU Lesser General Public License as published by *
10 * the Free Software Foundation; either version 3 of the License, or *
11 * (at your option) any later version. *
12 * *
13 * This library is distributed in the hope that it will be useful, *
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
16 * GNU Lesser General Public License for more details. *
17 * *
18 * You should have received a copy of the GNU Lesser General Public License *
19 * along with this program. If not, see <http://www.gnu.org/licenses/> *
20 ********************************************************************************/
21 #ifndef FXOBJECT_H
22 #define FXOBJECT_H
23 
24 #ifndef FXCALLBACK_H
25 #include "FXCallback.h"
26 #endif
27 
28 namespace FX {
29 
30 
31 class FXStream;
32 
33 
35 enum {
36  MINTYPE = 0,
37  MAXTYPE = 65535
38  };
39 
41 enum {
42  MINKEY = 0,
43  MAXKEY = 65535
44  };
45 
46 
48 #define FXDECLARE(classname) \
49  public: \
50  struct FXMapEntry { FX::FXSelector keylo; FX::FXSelector keyhi; long (classname::* func)(FX::FXObject*,FX::FXSelector,void*); }; \
51  static const FX::FXMetaClass metaClass; \
52  static FX::FXObject* manufacture(); \
53  virtual const FX::FXMetaClass* getMetaClass() const; \
54  virtual long handle(FX::FXObject* sender,FX::FXSelector sel,void* ptr); \
55  private:
56 
57 
59 #define FXIMPLEMENT(classname,baseclassname,mapping,nmappings) \
60  FX::FXObject* classname::manufacture(){return new classname;} \
61  const FX::FXMetaClass classname::metaClass(#classname,classname::manufacture,&baseclassname::metaClass,mapping,nmappings,sizeof(classname::FXMapEntry)); \
62  const FX::FXMetaClass* classname::getMetaClass() const { return &classname::metaClass; } \
63  long classname::handle(FX::FXObject* sender,FX::FXSelector sel,void* ptr){ \
64  const FXMapEntry* me=(const FXMapEntry*)metaClass.search(sel); \
65  return me ? (this->* me->func)(sender,sel,ptr) : baseclassname::handle(sender,sel,ptr); \
66  }
67 
68 
70 #define FXDECLARE_ABSTRACT(classname) \
71  public: \
72  struct FXMapEntry { FX::FXSelector keylo; FX::FXSelector keyhi; long (classname::* func)(FX::FXObject*,FX::FXSelector,void*); }; \
73  static const FX::FXMetaClass metaClass; \
74  virtual const FX::FXMetaClass* getMetaClass() const; \
75  virtual long handle(FX::FXObject* sender,FX::FXSelector sel,void* ptr); \
76  private:
77 
78 
80 #define FXIMPLEMENT_ABSTRACT(classname,baseclassname,mapping,nmappings) \
81  const FX::FXMetaClass classname::metaClass(#classname,FX::FXMetaClass::nullObject,&baseclassname::metaClass,mapping,nmappings,sizeof(classname::FXMapEntry)); \
82  const FX::FXMetaClass* classname::getMetaClass() const { return &classname::metaClass; } \
83  long classname::handle(FX::FXObject* sender,FX::FXSelector sel,void* ptr){ \
84  const FXMapEntry* me=(const FXMapEntry*)metaClass.search(sel); \
85  return me ? (this->* me->func)(sender,sel,ptr) : baseclassname::handle(sender,sel,ptr); \
86  }
87 
88 
90 #define FXMETACLASS(classname) (&classname::metaClass)
91 
92 
94 #define FXDEFMAP(classname) static const classname::FXMapEntry
95 
97 #define FXMAPTYPES(typelo,typehi,func) {FXSEL(typelo,FX::MINKEY),FXSEL(typehi,FX::MAXKEY),&func}
98 
100 #define FXMAPTYPE(type,func) {FXSEL(type,FX::MINKEY),FXSEL(type,FX::MAXKEY),&func}
101 
103 #define FXMAPFUNCS(type,keylo,keyhi,func) {FXSEL(type,keylo),FXSEL(type,keyhi),&func}
104 
106 #define FXMAPFUNC(type,key,func) {FXSEL(type,key),FXSEL(type,key),&func}
107 
108 
109 //#define NEWMAP 1
110 #if defined(NEWMAP)
111 
112 typedef FXCallback<long (FXObject*,FXSelector,FXptr)> FXMessageCallback;
113 
114 
115 typedef FXMessageCallback::Method FXMessageCallbackWrapper;
116 
117 struct NewMapEntry {
118  FX::FXSelector keylo;
119  FX::FXSelector keyhi;
120  FX::FXMessageCallbackWrapper method;
121  };
122 
123 #endif
124 
134 class FXAPI FXObject {
135  FXDECLARE(FXObject)
136 public:
137 
139  const FXchar* getClassName() const;
140 
142  FXbool isMemberOf(const FXMetaClass* metaclass) const;
143 
145  virtual long tryHandle(FXObject* sender,FXSelector sel,void* ptr);
146 
148  virtual long onDefault(FXObject*,FXSelector,void*);
149 
151  virtual void save(FXStream& store) const;
152 
154  virtual void load(FXStream& store);
155 
157  virtual ~FXObject();
158  };
159 
160 }
161 
162 #endif
Describes a FOX object.
Definition: FXMetaClass.h:34
A stream is a way to serialize data and objects into a byte stream.
Definition: FXStream.h:81
Definition: FX4Splitter.h:28
Object is the base class for all objects in FOX; in order to receive messages from the user interface...
Definition: FXObject.h:134

Copyright © 1997-2022 Jeroen van der Zijp