2009-11-08 Chris Toshok <toshok@ximian.com>
[moon.git] / src / media.h
blobc7360078e74a6bcd4f7645e922878ea423500bb5
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
2 /*
3 * media.h:
5 * Contact:
6 * Moonlight List (moonlight-list@lists.ximian.com)
8 * Copyright 2007 Novell, Inc. (http://www.novell.com)
10 * See the LICENSE file included with the distribution for details.
13 #ifndef __MEDIA_H__
14 #define __MEDIA_H__
16 #include <glib.h>
17 #include <gdk/gdkpixbuf.h>
19 #include "value.h"
20 #include "brush.h"
21 #include "frameworkelement.h"
22 #include "error.h"
23 #include "downloader.h"
24 #include "pipeline.h"
25 #include "bitmapsource.h"
28 /* @Namespace=System.Windows.Media */
29 class MediaAttribute : public DependencyObject {
30 protected:
31 virtual ~MediaAttribute () {}
33 public:
34 /* @PropertyType=string,GenerateAccessors */
35 const static int ValueProperty;
37 /* @GenerateCBinding,GeneratePInvoke */
38 MediaAttribute () { SetObjectType (Type::MEDIAATTRIBUTE); }
41 // Property Accessors
43 const char *GetValue();
44 void SetValue (const char *value);
48 /* @Namespace=System.Windows.Media */
49 class MediaAttributeCollection : public DependencyObjectCollection {
50 protected:
51 virtual ~MediaAttributeCollection () {}
53 public:
54 /* @GenerateCBinding,GeneratePInvoke */
55 MediaAttributeCollection () { SetObjectType (Type::MEDIAATTRIBUTE_COLLECTION); }
57 virtual Type::Kind GetElementType () { return Type::MEDIAATTRIBUTE; }
59 /* @GenerateCBinding,GeneratePInvoke */
60 MediaAttribute *GetItemByName (const char *name);
65 * This collection is always sorted by the time value of the markers.
66 * We override AddToList to add the node where it's supposed to be, keeping the
67 * collection sorted at all times.
68 * We also override Insert to ignore the index and behave just like Add.
70 /* @Namespace=System.Windows.Media */
71 class TimelineMarkerCollection : public DependencyObjectCollection {
72 protected:
73 virtual ~TimelineMarkerCollection () {}
75 public:
76 /* @GenerateCBinding,GeneratePInvoke */
77 TimelineMarkerCollection () { SetObjectType (Type::TIMELINEMARKER_COLLECTION); }
79 virtual Type::Kind GetElementType () { return Type::TIMELINEMARKER; }
81 virtual int AddWithError (Value *value, MoonError *error);
82 virtual bool InsertWithError (int index, Value *value, MoonError *error);
86 /* @Namespace=None */
87 class MarkerReachedEventArgs : public EventArgs {
88 TimelineMarker *marker;
90 protected:
91 virtual ~MarkerReachedEventArgs ();
93 public:
94 MarkerReachedEventArgs (TimelineMarker *marker);
96 /* @GenerateCBinding,GeneratePInvoke */
97 TimelineMarker *GetMarker () { return marker; }
101 /* @Namespace=None */
102 /* @ManagedDependencyProperties=None */
103 /* @ManagedEvents=Manual */
104 class MediaBase : public FrameworkElement {
105 private:
106 static void set_source_async (EventObject *user_data);
107 void SetSourceAsyncCallback ();
109 protected:
110 struct {
111 Downloader *downloader;
112 char *part_name;
113 bool queued;
114 } source;
116 Downloader *downloader;
117 char *part_name;
119 int allow_downloads:1;
120 int source_changed:1;
122 virtual ~MediaBase ();
124 virtual void DownloaderFailed (EventArgs *args);
125 virtual void DownloaderComplete ();
126 void DownloaderAbort ();
128 static void downloader_complete (EventObject *sender, EventArgs *calldata, gpointer closure);
129 static void downloader_failed (EventObject *sender, EventArgs *calldata, gpointer closure);
131 virtual void OnEmptySource () { }
133 void SetDownloadProgress (double progress);
135 virtual DownloaderAccessPolicy GetDownloaderPolicy (const char *uri) { return MediaPolicy; }
137 public:
138 /* @PropertyType=string,AlwaysChange,GenerateAccessors */
139 const static int SourceProperty;
140 /* @PropertyType=Stretch,DefaultValue=StretchUniform,GenerateAccessors */
141 const static int StretchProperty;
142 /* @PropertyType=double,DefaultValue=0.0,GenerateAccessors */
143 const static int DownloadProgressProperty;
145 const static int DownloadProgressChangedEvent;
147 /* @GenerateCBinding,GeneratePInvoke */
148 MediaBase ();
150 virtual void SetSourceInternal (Downloader *downloader, char *PartName);
151 virtual void SetSource (Downloader *downloader, const char *PartName);
152 /* @GenerateCBinding,GeneratePInvoke */
153 void SetSource (const char *uri);
155 void SetAllowDownloads (bool allow);
156 bool AllowDownloads () { return allow_downloads; }
158 virtual void OnPropertyChanged (PropertyChangedEventArgs *args, MoonError *error);
160 virtual void OnLoaded ();
163 // Property Accessors
165 double GetDownloadProgress ();
167 const char *GetSource ();
169 void SetStretch (Stretch stretch);
170 Stretch GetStretch ();
174 /* @Namespace=System.Windows.Controls */
175 class Image : public MediaBase {
176 private:
177 void DownloadProgress ();
178 void ImageOpened ();
179 void ImageFailed (ImageErrorEventArgs *args);
180 void SourcePixelDataChanged ();
182 static void download_progress (EventObject *sender, EventArgs *calldata, gpointer closure);
183 static void image_opened (EventObject *sender, EventArgs *calldata, gpointer closure);
184 static void image_failed (EventObject *sender, EventArgs *calldata, gpointer closure);
185 static void source_pixel_data_changed (EventObject *sender, EventArgs *calldata, gpointer closure);
187 protected:
188 virtual ~Image ();
190 public:
191 /* @PropertyType=ImageSource,AutoCreator=Image::CreateDefaultImageSource,GenerateAccessors */
192 const static int SourceProperty;
194 /* @DelegateType=EventHandler<ExceptionRoutedEventArgs> */
195 const static int ImageFailedEvent;
197 /* @GenerateCBinding,GeneratePInvoke */
198 Image ();
200 virtual void Render (cairo_t *cr, Region *region, bool path_only = false);
202 virtual void SetSourceInternal (Downloader *downloader, char *PartName);
203 virtual void SetSource (Downloader *downloader, const char *PartName);
205 virtual void OnPropertyChanged (PropertyChangedEventArgs *args, MoonError *error);
207 int GetImageHeight () { return GetSource () ? GetSource ()->GetPixelHeight () : 0; };
208 int GetImageWidth () { return GetSource () ? GetSource ()->GetPixelWidth () : 0; };
210 virtual Rect GetCoverageBounds ();
212 virtual Size MeasureOverride (Size availableSize);
213 virtual Size ArrangeOverride (Size finalSize);
214 virtual Size ComputeActualSize ();
216 virtual bool InsideObject (cairo_t *cr, double x, double y);
218 /* @GenerateCBinding,GeneratePInvoke */
219 void SetSource (ImageSource *source);
220 ImageSource *GetSource ();
222 static Value *CreateDefaultImageSource (DependencyObject *instance, DependencyProperty *property);
225 #endif /* __MEDIA_H__ */