2009-10-09 Chris Toshok <toshok@ximian.com>
[moon.git] / src / dependencyproperty.h
blobfc8ebc944a7b7528c6504ce9d6df1ae6fcea181b
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
2 /*
3 * dependencypropery.cpp:
5 * Copyright 2007-2008 Novell, Inc. (http://www.novell.com)
7 * See the LICENSE file included with the distribution for details.
8 *
9 */
11 #ifndef __DEPENDENCY_PROPERTY_H__
12 #define __DEPENDENCY_PROPERTY_H__
14 #include <glib.h>
17 #include "value.h"
18 #include "enums.h"
19 #include "list.h"
21 class PropertyChangedEventArgs;
22 class MoonError;
24 typedef bool ValueValidator (DependencyObject *instance, DependencyProperty *property, Value *value, MoonError *error);
25 typedef Value* AutoCreator (DependencyObject *instance, DependencyProperty *property);
27 /* @CBindingRequisite */
28 typedef void (* PropertyChangeHandler) (DependencyObject *sender, PropertyChangedEventArgs *args, MoonError *error, gpointer closure);
31 // DependencyProperty
33 /* @IncludeInKinds */
34 /* @SkipValue */
35 class DependencyProperty {
36 public:
37 DependencyProperty (Type::Kind owner_type, const char *name, Value *default_value, Type::Kind property_type, bool attached, bool readonly, bool always_change, PropertyChangeHandler changed_callback, ValueValidator *validator, AutoCreator *autocreator, bool is_custom);
38 void Dispose ();
39 ~DependencyProperty ();
41 int GetId () { return id; }
42 void SetId (int value) { id = value; }
44 /* @GenerateCBinding,GeneratePInvoke */
45 const char *GetName() { return name; }
46 const char *GetHashKey ();
47 Type::Kind GetOwnerType() { return owner_type; }
48 /* @GenerateCBinding,GeneratePInvoke */
49 Type::Kind GetPropertyType() { return property_type; }
51 /* @GenerateCBinding,GeneratePInvoke */
52 bool IsNullable () { return is_nullable; }
53 /* @GenerateCBinding,GeneratePInvoke */
54 void SetIsNullable (bool value) { is_nullable = value; }
55 /* @GenerateCBinding,GeneratePInvoke */
56 bool IsReadOnly () { return is_readonly; }
57 /* @GenerateCBinding,GeneratePInvoke */
58 bool IsAttached () { return is_attached; }
59 bool IsAutoCreated () { return autocreator != NULL; }
60 AutoCreator* GetAutoCreator () { return autocreator; }
61 bool AlwaysChange () { return always_change; }
62 bool IsCustom () { return is_custom; }
63 PropertyChangeHandler GetChangedCallback () { return changed_callback; }
65 /* @GenerateCBinding,GeneratePInvoke,Version=2.0 */
66 Value *GetDefaultValue () { return default_value; }
68 bool Validate (DependencyObject *instance, Value *value, MoonError *error);
70 /* @GenerateCBinding,GeneratePInvoke,Version=2.0 */
71 void SetPropertyChangedCallback (PropertyChangeHandler changed_callback);
73 static int Register (Types *types, Type::Kind type, const char *name, bool is_custom, Value *default_value);
74 static int Register (Types *types, Type::Kind type, const char *name, bool is_custom, Type::Kind vtype);
75 static int Register (Types *types, Type::Kind type, const char *name, bool is_custom, Value *default_value, Type::Kind vtype);
76 static int RegisterFull (Types *types, Type::Kind type, const char *name, bool is_custom, Value *default_value, Type::Kind vtype, bool attached, bool read_only, bool always_change, PropertyChangeHandler changed_callback, ValueValidator *validator, AutoCreator* autocreator, bool is_nullable);
78 /* @GenerateCBinding,GeneratePInvoke,Version=2.0 */
79 static DependencyProperty *RegisterCustomProperty (const char *name, Type::Kind property_type, Type::Kind owner_type, Value *defaultValue, bool attached, bool read_only, PropertyChangeHandler callback);
80 /* @GenerateCBinding,GeneratePInvoke,Version=2.0 */
81 static DependencyProperty *RegisterCoreProperty (const char *name, Type::Kind property_type, Type::Kind owner_type, Value *defaultValue, bool attached, bool read_only, PropertyChangeHandler callback);
83 /* @GenerateCBinding,GeneratePInvoke */
84 static DependencyProperty *GetDependencyProperty (Type::Kind type, const char *name);
85 static DependencyProperty *GetDependencyProperty (Type::Kind type, const char *name, bool inherits);
86 static DependencyProperty *GetDependencyProperty (Type *type, const char *name, bool inherits);
88 /* @GenerateCBinding,GeneratePInvoke */
89 static DependencyProperty *GetDependencyPropertyFull (Type::Kind type, const char *name, bool inherits);
91 private:
92 int id;
94 AutoCreator* autocreator; // invoked by AutoCreatePropertyValueProvider to create values
95 bool is_readonly;
96 bool is_nullable;
97 bool is_attached;
98 bool always_change; // determines if SetValue will do something if the current and new values are equal.
99 bool is_custom; // If created using managed api
101 char *hash_key;
102 char *name;
104 Value *default_value;
105 ValueValidator *validator;
107 Type::Kind owner_type;
108 Type::Kind property_type;
109 PropertyChangeHandler changed_callback;
112 G_BEGIN_DECLS
114 DependencyProperty *resolve_property_path (DependencyObject **o, PropertyPath *propertypath, GHashTable *promoted_values);
116 G_END_DECLS
118 #endif /* __DEPENDENCY_PROPERTY_H__ */