2009-12-07 Rolf Bjarne Kvinge <RKvinge@novell.com>
[moon.git] / src / collection.h
blob23db8d45d21b4083e98d4c559b92c79ef8fa14b7
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 SetIsAttached (bool value);
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 virtual bool Next (MoonError *error);
164 /* @GenerateCBinding,GeneratePInvoke */
165 virtual bool Reset ();
167 /* @GenerateCBinding,GeneratePInvoke */
168 virtual Value *GetCurrent (MoonError *error);
170 /* @GenerateCBinding,GeneratePInvoke */
171 static void Destroy (CollectionIterator *iterator);
173 protected:
174 Collection *collection;
175 int generation;
176 int index;
179 enum VisualTreeWalkerDirection {
180 Logical,
181 LogicalReverse,
182 ZForward,
183 ZReverse
186 class VisualTreeWalker {
187 public:
188 VisualTreeWalker (UIElement *item, VisualTreeWalkerDirection direction = Logical, Types *types = NULL);
190 ~VisualTreeWalker ();
192 UIElement *Step ();
193 int GetCount ();
195 protected:
196 DependencyObject *content;
197 Collection *collection;
198 Types *types;
199 int index;
200 VisualTreeWalkerDirection direction;
203 class DeepTreeWalker {
204 public:
205 DeepTreeWalker (UIElement *top, VisualTreeWalkerDirection direction = Logical, Types *types = NULL);
206 UIElement *Step ();
207 void SkipBranch ();
208 ~DeepTreeWalker ();
209 protected:
210 List *walk_list;
211 Types *types;
212 UIElement *last;
213 VisualTreeWalkerDirection direction;
216 /* @Namespace=System.Windows */
217 class TriggerCollection : public DependencyObjectCollection {
218 protected:
219 virtual ~TriggerCollection ();
221 public:
222 /* @GenerateCBinding,GeneratePInvoke,ManagedAccess=Internal */
223 TriggerCollection ();
225 virtual Type::Kind GetElementType () { return Type::EVENTTRIGGER; }
228 /* @Namespace=System.Windows */
229 class TriggerActionCollection : public DependencyObjectCollection {
230 protected:
231 virtual ~TriggerActionCollection ();
233 public:
234 /* @GenerateCBinding,GeneratePInvoke */
235 TriggerActionCollection ();
237 /* this may seem wrong, but it's what the TriggerActionCollection mandates */
238 virtual Type::Kind GetElementType () { return Type::BEGINSTORYBOARD; }
241 /* @Namespace=System.Windows.Documents */
242 class InlineCollection : public DependencyObjectCollection {
243 protected:
244 virtual ~InlineCollection ();
246 public:
247 /* @GenerateCBinding,GeneratePInvoke,ManagedAccess=Internal */
248 InlineCollection ();
250 virtual Type::Kind GetElementType () { return Type::INLINE; }
252 bool Equals (InlineCollection *inlines);
255 /* @Namespace=System.Windows.Controls */
256 class UIElementCollection : public DependencyObjectCollection {
257 protected:
258 virtual ~UIElementCollection ();
260 public:
261 GPtrArray *z_sorted;
263 /* @GenerateCBinding,GeneratePInvoke,ManagedAccess=Internal */
264 UIElementCollection ();
266 virtual Type::Kind GetElementType () { return Type::UIELEMENT; }
268 virtual bool Clear ();
270 void ResortByZIndex ();
273 /* @Namespace=System.Windows.Controls */
274 class ItemCollection : public Collection {
275 protected:
276 virtual ~ItemCollection ();
278 public:
279 /* @GenerateCBinding,GeneratePInvoke,ManagedAccess=Internal */
280 ItemCollection ();
282 virtual Type::Kind GetElementType () { return Type::OBJECT; }
285 /* @Namespace=System.Windows.Controls */
286 class MultiScaleSubImageCollection : public DependencyObjectCollection {
287 public:
288 GPtrArray *z_sorted;
290 /* @GenerateCBinding,GeneratePInvoke,ManagedAccess=Internal */
291 MultiScaleSubImageCollection ();
293 virtual Type::Kind GetElementType () { return Type::MULTISCALESUBIMAGE; }
295 virtual bool Clear ();
297 void ResortByZIndex ();
299 protected:
300 virtual ~MultiScaleSubImageCollection ();
303 /* @Namespace=System.Windows.Controls */
304 class HitTestCollection : public UIElementCollection {
305 protected:
306 virtual bool AddedToCollection (Value *value, MoonError *error) { return true; }
307 virtual void RemovedFromCollection (Value *value) {}
308 virtual ~HitTestCollection () {}
309 public:
310 /* @GenerateCBinding,GeneratePInvoke,ManagedAccess=Internal */
311 HitTestCollection ();
314 /* @Namespace=System.Windows */
315 class ResourceDictionaryCollection : public DependencyObjectCollection {
316 protected:
317 virtual ~ResourceDictionaryCollection ();
319 public:
320 /* @GenerateCBinding,GeneratePInvoke */
321 ResourceDictionaryCollection ();
323 virtual Type::Kind GetElementType () { return Type::RESOURCE_DICTIONARY; }
326 G_BEGIN_DECLS
328 Collection *collection_new (Type::Kind kind);
330 G_END_DECLS
332 #endif /* __MOON_COLLECTION_H__ */