~ubuntu-branches/ubuntu/breezy/koffice/breezy

« back to all changes in this revision

Viewing changes to lib/kscript/kscript_object.h

  • Committer: Bazaar Package Importer
  • Author(s): Ben Burton
  • Date: 2004-05-09 11:33:00 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20040509113300-vfrdadqsvjfuhn3b
Tags: 1:1.3.1-1
* New upstream bugfix release.
* Built against newer imagemagick (closes: #246623).
* Made koffice-libs/kformula recommend/depend on latex-xft-fonts, which
  provides mathematical fonts that the formula editor can use.  Also
  patched the kformula part to make these fonts the default.
* Changed kword menu hint from "WordProcessors" to "Word processors"
  (closes: #246209).
* Spellchecker configuration is now fixed (closes: #221256, #227568).

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#ifndef __KSCRIPT_OBJECT_H__
2
 
#define __KSCRIPT_OBJECT_H__
3
 
 
4
 
#include <qshared.h>
5
 
#include <qmap.h>
6
 
#include <qlist.h>
7
 
#include <qstring.h>
8
 
 
9
 
#include "kscript_ptr.h"
10
 
#include "kscript_context.h"
11
 
#include "kscript_class.h"
12
 
#include "kscript_func.h"
13
 
#include "kscript_struct.h"
14
 
#include "kscript_proxy.h"
15
 
#include "kscript_qobject.h"
16
 
 
17
 
#include <string.h>
18
 
 
19
 
class KSObject : public QShared
20
 
{
21
 
public:
22
 
  typedef KSSharedPtr<KSObject> Ptr;
23
 
 
24
 
  enum Status { Dead, Alive };
25
 
 
26
 
  KSObject( KSClass* c );
27
 
  virtual ~KSObject();
28
 
 
29
 
  virtual bool kill();
30
 
 
31
 
  KSModule* module() { return m_class->module(); }
32
 
  KSSubScope* scope() { return &m_scope; }
33
 
  KSNamespace* instanceNameSpace() { return &m_space; }
34
 
  const KSNamespace* instanceNameSpace() const { return &m_space; }
35
 
 
36
 
  const KSClass* getClass() const { return m_class; }
37
 
  KSClass* getClass() { return m_class; }
38
 
 
39
 
  Status status() { return m_status; }
40
 
  void setStatus( Status s ) { m_status = s; }
41
 
 
42
 
  bool connect( const QString& sig, KSObject* r, KSValue* s );
43
 
  void disconnect();
44
 
  void disconnect( KSObject* o );
45
 
  void disconnect( KSObject* o, KSValue* _slot );
46
 
  bool emitSignal( const QString& name, KSContext& context );
47
 
 
48
 
  void removeSender( KSObject* o ) { m_sender.removeRef( o ); }
49
 
  void appendSender( KSObject* o ) { m_sender.append( o ); }
50
 
 
51
 
  /**
52
 
   * Implements a KScript function of the same name.
53
 
   */
54
 
  bool disconnect( KSContext& context );
55
 
  /**
56
 
   * Implements a KScript function of the same name.
57
 
   */
58
 
  bool inherits( KSContext& context );
59
 
  /**
60
 
   * Implements a KScript function of the same name.
61
 
   */
62
 
  bool isA( KSContext& context );
63
 
 
64
 
  /**
65
 
   * If @ref KSContext::leftExpr retruns TRUE for the given context,
66
 
   * then a new member is added to the object if it did not exist.
67
 
   * Otherwise 0 is returned for a non existing member.
68
 
   * This function may nevertheless set a exception if a member is known but if
69
 
   * it could not be read for some reason.
70
 
   */
71
 
  virtual KSValue::Ptr member( KSContext&, const QString& name );
72
 
  /**
73
 
   * May set a exception if the member could not be set.
74
 
   */
75
 
  virtual bool setMember( KSContext&, const QString& name, const KSValue::Ptr& v );
76
 
 
77
 
  /**
78
 
   * When getting a pointer to a KSObject via @ref KSValue::objectValue this function
79
 
   * helps to do some dynamic casting.
80
 
   */
81
 
  virtual bool inherits( const char* name ) { return ( strcmp( name, "KSObject" ) == 0 ); }
82
 
 
83
 
protected:
84
 
  struct Signal
85
 
  {
86
 
    KSObject* m_receiver;
87
 
    KSValue::Ptr m_slot;
88
 
  };
89
 
 
90
 
  typedef QValueList<Signal> SignalList;
91
 
  typedef QMap<QString,SignalList> SignalMap;
92
 
 
93
 
  SignalList* findSignal( const QString& name, bool insert = false );
94
 
 
95
 
  virtual bool destructor();
96
 
 
97
 
private:
98
 
  /**
99
 
   * This namespace holds the variables of this instance.
100
 
   */
101
 
  KSNamespace m_space;
102
 
  /**
103
 
   * This scope holds all namespaces of base classes and the local
104
 
   * namespace.
105
 
   */
106
 
  KSSubScope m_scope;
107
 
  /**
108
 
   * This objects class.
109
 
   */
110
 
  KSClass* m_class;
111
 
  Status m_status;
112
 
 
113
 
  SignalMap m_signals;
114
 
  QList<KSObject> m_sender;
115
 
};
116
 
 
117
 
class KSScriptObject : public KSObject
118
 
{
119
 
public:
120
 
  KSScriptObject( KSClass* c ) : KSObject( c ) { }
121
 
  ~KSScriptObject();
122
 
 
123
 
  bool inherits( const char* name ) { return ( strcmp( name, "KSScriptObject" ) == 0 || KSObject::inherits( name ) ); }
124
 
 
125
 
protected:
126
 
  virtual bool destructor();
127
 
};
128
 
 
129
 
/**
130
 
 * A method holds a reference to some instance and some function. The function
131
 
 * may be of the type @ref KSFunction, KSBuiltinFunction or KSStructBuiltinFunction.
132
 
 * The instance may be a @ref KSObject or @ref KSStruct or derived types.
133
 
 */
134
 
class KSMethod : public QShared
135
 
{
136
 
public:
137
 
  KSMethod( KSModule* m, const KSValue::Ptr& obj, const KSValue::Ptr& func ) : QShared(), m_object( obj ), m_func( func ), m_module( m ) { }
138
 
  /**
139
 
   * Use this method if the function is KSBuiltinFunction or KSStructBuiltinFunction.
140
 
   * In this case we pass the name of the method. No copy of this name is made and the
141
 
   * destructor does not free the string. So you should only pass constants here.
142
 
   */
143
 
  KSMethod( KSModule* m, const KSValue::Ptr& obj, const KSValue::Ptr& func, const QString& name )
144
 
      : QShared(), m_object( obj ), m_func( func ), m_module( m ), m_methodName( name ) { }
145
 
  virtual ~KSMethod() { }
146
 
 
147
 
  bool call( KSContext& context );
148
 
 
149
 
  KSValue* object() { return m_object; }
150
 
  KSValue* function() { return m_func; }
151
 
 
152
 
  KSModule* module() { return m_module; }
153
 
 
154
 
  QString name() { return ( m_methodName.isEmpty() ? m_func->functionValue()->name() : m_methodName ); }
155
 
 
156
 
private:
157
 
  KSValue::Ptr m_object;
158
 
  KSValue::Ptr m_func;
159
 
  KSModule* m_module;
160
 
 
161
 
  QString m_methodName;
162
 
};
163
 
 
164
 
class KSProperty : public QShared
165
 
{
166
 
public:
167
 
  KSProperty( const KSObject::Ptr& obj, const QString& name ) { m_obj = obj; m_name = name; }
168
 
  KSProperty( const KSStruct::Ptr& struc, const QString& name ) { m_struct = struc; m_name = name; }
169
 
  KSProperty( const KSProxy::Ptr& proxy, const QString& name ) { m_proxy = proxy; m_name = name; }
170
 
  KSProperty( const KSModule::Ptr& m, const QString& name ) { m_module = m; m_name = name; }
171
 
  KSProperty( const KSQObject::Ptr& m, const QString& name ) { m_qobject = m; m_name = name; }
172
 
    
173
 
  virtual ~KSProperty() { }
174
 
 
175
 
  QString name() { return m_name; }
176
 
 
177
 
  virtual bool set( KSContext&, const KSValue::Ptr& v );
178
 
 
179
 
private:
180
 
  KSObject::Ptr m_obj;
181
 
  KSStruct::Ptr m_struct;
182
 
  KSProxy::Ptr m_proxy;
183
 
  KSModule::Ptr m_module;
184
 
  KSQObject::Ptr m_qobject;
185
 
  QString m_name;
186
 
};
187
 
 
188
 
#endif