2009-10-20 Chris Toshok <toshok@ximian.com>
[moon.git] / src / collection.h
blob62ee994edb1a6dedeb0d5b45a338bcf1b8d334f2
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
2 /*
3 * collection.h: different types of collections
5 * Copyright 2007 Novell, Inc. (http://www.novell.com)
7 * See the LICENSE file included with the distribution for details.
8 *
9 */
11 #ifndef __MOON_COLLECTION_H__
12 #define __MOON_COLLECTION_H__
14 #include <glib.h>
16 #include "dependencyobject.h"
17 #include "eventargs.h"
18 #include "point.h"
20 class CollectionIterator;
23 // Collection: provides a collection that we can monitor for
24 // changes. We expose this collection in a few classes to
25 // the managed world, and when a change happens we get a
26 // chance to reflect the changes
28 /* @Namespace=System.Windows */
29 /* @ManagedName=PresentationFrameworkCollection`1 */
30 /* @ManagedDependencyProperties=Manual */
31 /* @ManagedEvents=Manual */
32 class Collection : public DependencyObject {
33 public:
34 /* @PropertyType=gint32,DefaultValue=0,GenerateAccessors */
35 const static int CountProperty;
37 /* @GenerateCBinding,GeneratePInvoke */
38 virtual Type::Kind GetElementType () = 0;
40 int Generation () { return generation; }
41 GPtrArray *Array () { return array; }
43 /* @GenerateCBinding,GeneratePInvoke */
44 virtual CollectionIterator *GetIterator ();
46 /* @GenerateCBinding,GeneratePInvoke */
47 virtual int GetCount ();
49 int Add (Value value);
50 int Add (Value *value);
52 /* @GenerateCBinding,GeneratePInvoke */
53 virtual bool Clear ();
55 /* @GenerateCBinding,GeneratePInvoke */
56 bool Contains (Value *value);
57 /* @GenerateCBinding,GeneratePInvoke */
58 int IndexOf (Value *value);
60 bool Insert (int index, Value value);
61 bool Insert (int index, Value *value);
63 bool Remove (Value value);
64 /* @GenerateCBinding,GeneratePInvoke */
65 bool Remove (Value *value);
67 bool RemoveAt (int index);
69 bool SetValueAt (int index, Value *value);
70 Value *GetValueAt (int index);
72 /* @GenerateCBinding,GeneratePInvoke,Version=2.0 */
73 virtual int AddWithError (Value *value, MoonError *error);
74 /* @GenerateCBinding,GeneratePInvoke,Version=2.0 */
75 virtual bool InsertWithError (int index, Value *value, MoonError *error);
76 /* @GenerateCBinding,GeneratePInvoke,Version=2.0 */
77 virtual Value *GetValueAtWithError (int index, MoonError *error);
78 /* @GenerateCBinding,GeneratePInvoke,Version=2.0 */
79 virtual bool SetValueAtWithError (int index, Value *value, MoonError *error);
80 /* @GenerateCBinding,GeneratePInvoke,Version=2.0 */
81 virtual bool RemoveAtWithError (int index, MoonError *error);
83 const static int ChangedEvent;
84 const static int ItemChangedEvent;
86 protected:
87 GPtrArray *array;
88 int generation;
90 void EmitChanged (CollectionChangedAction action, Value *new_value, Value *old_value, int index);
91 void EmitItemChanged (DependencyObject *object, DependencyProperty *property, Value *newValue, Value *oldValue);
93 virtual bool CanAdd (Value *value);
94 virtual bool AddedToCollection (Value *value, MoonError *error) { return true; }
95 virtual void RemovedFromCollection (Value *value) {}
97 void SetCount (int count);
99 virtual void CloneCore (Types *types, DependencyObject* fromObj);
101 Collection ();
102 virtual ~Collection ();
103 virtual void Dispose ();
107 /* @Namespace=None */
108 class DependencyObjectCollection : public Collection {
109 public:
110 /* @GenerateCBinding,GeneratePInvoke */
111 DependencyObjectCollection ();
113 virtual Type::Kind GetElementType () { return Type::DEPENDENCY_OBJECT; }
115 virtual void SetSurface (Surface *surface);
117 virtual void OnSubPropertyChanged (DependencyProperty *prop, DependencyObject *obj, PropertyChangedEventArgs *args);
118 virtual void UnregisterAllNamesRootedAt (NameScope *from_ns);
119 virtual void RegisterAllNamesRootedAt (NameScope *to_ns, MoonError *error);
121 protected:
122 virtual bool AddedToCollection (Value *value, MoonError *error);
123 virtual void RemovedFromCollection (Value *value);
125 virtual ~DependencyObjectCollection ();
128 /* @Namespace=System.Windows.Media */
129 class DoubleCollection : public Collection {
130 public:
131 /* @GenerateCBinding,GeneratePInvoke */
132 DoubleCollection ();
134 virtual Type::Kind GetElementType () { return Type::DOUBLE; }
136 static DoubleCollection* FromStr (const char *str);
138 protected:
139 virtual ~DoubleCollection ();
142 /* @Namespace=System.Windows.Media */
143 class PointCollection : public Collection {
144 public:
145 /* @GenerateCBinding,GeneratePInvoke */
146 PointCollection ();
148 virtual Type::Kind GetElementType () { return Type::POINT; }
150 static PointCollection* FromStr (const char *str);
152 protected:
153 virtual ~PointCollection ();
156 class CollectionIterator {
157 public:
158 CollectionIterator (Collection *c);
159 ~CollectionIterator ();
161 /* @GenerateCBinding,GeneratePInvoke */
162 int Next ();
164 /* @GenerateCBinding,GeneratePInvoke */
165 bool Reset ();
167 /* @GenerateCBinding,GeneratePInvoke */
168 Value* GetCurrent (int *error);
170 /* @GenerateCBinding,GeneratePInvoke */
171 static void Destroy (CollectionIterator *iterator);
173 private:
174 Collection *collection;
175 int generation;
176 int index;
179 enum VisualTreeWalkerDirection {
180 Logical,
181 ZForward,
182 ZReverse
185 class VisualTreeWalker {
186 public:
187 VisualTreeWalker (UIElement *item, VisualTreeWalkerDirection direction = Logical, Types *types = NULL);
189 ~VisualTreeWalker ();
191 UIElement *Step ();
192 int GetCount ();
194 protected:
195 DependencyObject *content;
196 Collection *collection;
197 Types *types;
198 int index;
199 VisualTreeWalkerDirection direction;
202 class DeepTreeWalker {
203 public:
204 DeepTreeWalker (UIElement *top, Types *types = NULL);
205 UIElement *Step ();
206 void SkipBranch ();
207 ~DeepTreeWalker ();
208 protected:
209 List *walk_list;
210 Types *types;
211 UIElement *last;
214 /* @Namespace=System.Windows */
215 class TriggerCollection : public DependencyObjectCollection {
216 protected:
217 virtual ~TriggerCollection ();
219 public:
220 /* @GenerateCBinding,GeneratePInvoke,ManagedAccess=Internal */
221 TriggerCollection ();
223 virtual Type::Kind GetElementType () { return Type::EVENTTRIGGER; }
226 /* @Namespace=System.Windows */
227 class TriggerActionCollection : public DependencyObjectCollection {
228 protected:
229 virtual ~TriggerActionCollection ();
231 public:
232 /* @GenerateCBinding,GeneratePInvoke */
233 TriggerActionCollection ();
235 /* this may seem wrong, but it's what the TriggerActionCollection mandates */
236 virtual Type::Kind GetElementType () { return Type::BEGINSTORYBOARD; }
239 /* @Namespace=System.Windows.Documents */
240 class InlineCollection : public DependencyObjectCollection {
241 protected:
242 virtual ~InlineCollection ();
244 public:
245 /* @GenerateCBinding,GeneratePInvoke,ManagedAccess=Internal */
246 InlineCollection ();
248 virtual Type::Kind GetElementType () { return Type::INLINE; }
250 bool Equals (InlineCollection *inlines);
253 /* @Namespace=System.Windows.Controls */
254 class UIElementCollection : public DependencyObjectCollection {
255 protected:
256 virtual ~UIElementCollection ();
258 public:
259 GPtrArray *z_sorted;
261 /* @GenerateCBinding,GeneratePInvoke,ManagedAccess=Internal */
262 UIElementCollection ();
264 virtual Type::Kind GetElementType () { return Type::UIELEMENT; }
266 virtual bool Clear ();
268 void ResortByZIndex ();
271 /* @Namespace=System.Windows.Controls */
272 class ItemCollection : public Collection {
273 protected:
274 virtual ~ItemCollection ();
276 public:
277 /* @GenerateCBinding,GeneratePInvoke,ManagedAccess=Internal */
278 ItemCollection ();
280 virtual Type::Kind GetElementType () { return Type::OBJECT; }
283 /* @Namespace=System.Windows.Controls */
284 class MultiScaleSubImageCollection : public DependencyObjectCollection {
285 public:
286 GPtrArray *z_sorted;
288 /* @GenerateCBinding,GeneratePInvoke,ManagedAccess=Internal */
289 MultiScaleSubImageCollection ();
291 virtual Type::Kind GetElementType () { return Type::MULTISCALESUBIMAGE; }
293 virtual bool Clear ();
295 void ResortByZIndex ();
297 protected:
298 virtual ~MultiScaleSubImageCollection ();
301 /* @Namespace=System.Windows.Controls */
302 class HitTestCollection : public UIElementCollection {
303 protected:
304 virtual bool AddedToCollection (Value *value, MoonError *error) { return true; }
305 virtual void RemovedFromCollection (Value *value) {}
306 virtual ~HitTestCollection () {}
307 public:
308 /* @GenerateCBinding,GeneratePInvoke,ManagedAccess=Internal */
309 HitTestCollection ();
312 /* @Namespace=System.Windows */
313 class ResourceDictionaryCollection : public DependencyObjectCollection {
314 protected:
315 virtual ~ResourceDictionaryCollection ();
317 public:
318 /* @GenerateCBinding,GeneratePInvoke */
319 ResourceDictionaryCollection ();
321 virtual Type::Kind GetElementType () { return Type::RESOURCE_DICTIONARY; }
324 G_BEGIN_DECLS
326 Collection *collection_new (Type::Kind kind);
328 G_END_DECLS
330 #endif /* __MOON_COLLECTION_H__ */