2009-08-26 Chris Toshok <toshok@ximian.com>
[moon.git] / src / media.h
blob17dfad03c2b5b30ece30f5e884780a066be5064d
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 class MediaBase : public FrameworkElement {
104 private:
105 static void set_source_async (EventObject *user_data);
106 void SetSourceAsyncCallback ();
108 protected:
109 struct {
110 Downloader *downloader;
111 char *part_name;
112 bool queued;
113 } source;
115 Downloader *downloader;
116 char *part_name;
118 int allow_downloads:1;
119 int source_changed:1;
121 virtual ~MediaBase ();
123 virtual void DownloaderFailed (EventArgs *args);
124 virtual void DownloaderComplete ();
125 void DownloaderAbort ();
127 static void downloader_complete (EventObject *sender, EventArgs *calldata, gpointer closure);
128 static void downloader_failed (EventObject *sender, EventArgs *calldata, gpointer closure);
130 virtual void OnEmptySource () { }
132 void SetDownloadProgress (double progress);
134 virtual DownloaderAccessPolicy GetDownloaderPolicy (const char *uri) { return MediaPolicy; }
136 public:
137 /* @PropertyType=string,AlwaysChange,GenerateAccessors */
138 const static int SourceProperty;
139 /* @PropertyType=Stretch,DefaultValue=StretchUniform,GenerateAccessors */
140 const static int StretchProperty;
141 /* @PropertyType=double,DefaultValue=0.0,GenerateAccessors */
142 const static int DownloadProgressProperty;
144 const static int DownloadProgressChangedEvent;
146 /* @GenerateCBinding,GeneratePInvoke */
147 MediaBase ();
149 virtual void SetSourceInternal (Downloader *downloader, char *PartName);
150 virtual void SetSource (Downloader *downloader, const char *PartName);
151 /* @GenerateCBinding,GeneratePInvoke */
152 void SetSource (const char *uri);
154 void SetAllowDownloads (bool allow);
155 bool AllowDownloads () { return allow_downloads; }
157 virtual void OnPropertyChanged (PropertyChangedEventArgs *args, MoonError *error);
159 virtual void OnLoaded ();
162 // Property Accessors
164 double GetDownloadProgress ();
166 const char *GetSource ();
168 void SetStretch (Stretch stretch);
169 Stretch GetStretch ();
173 /* @Namespace=System.Windows.Controls */
174 class Image : public MediaBase {
175 private:
176 void DownloadProgress ();
177 void ImageOpened ();
178 void ImageFailed ();
179 void SourcePixelDataChanged ();
181 static void download_progress (EventObject *sender, EventArgs *calldata, gpointer closure);
182 static void image_opened (EventObject *sender, EventArgs *calldata, gpointer closure);
183 static void image_failed (EventObject *sender, EventArgs *calldata, gpointer closure);
184 static void source_pixel_data_changed (EventObject *sender, EventArgs *calldata, gpointer closure);
186 protected:
187 virtual ~Image ();
189 public:
190 /* @PropertyType=ImageSource,AutoCreator=Image::CreateDefaultImageSource,GenerateAccessors */
191 const static int SourceProperty;
193 const static int ImageFailedEvent;
195 /* @GenerateCBinding,GeneratePInvoke */
196 Image ();
198 virtual void Render (cairo_t *cr, Region *region, bool path_only = false);
200 virtual void SetSourceInternal (Downloader *downloader, char *PartName);
201 virtual void SetSource (Downloader *downloader, const char *PartName);
203 virtual void OnPropertyChanged (PropertyChangedEventArgs *args, MoonError *error);
205 int GetImageHeight () { return GetSource () ? GetSource ()->GetPixelHeight () : 0; };
206 int GetImageWidth () { return GetSource () ? GetSource ()->GetPixelWidth () : 0; };
208 virtual Rect GetCoverageBounds ();
210 virtual Size MeasureOverride (Size availableSize);
211 virtual Size ArrangeOverride (Size finalSize);
212 virtual Size ComputeActualSize ();
214 virtual bool InsideObject (cairo_t *cr, double x, double y);
216 /* @GenerateCBinding,GeneratePInvoke */
217 void SetSource (ImageSource *source);
218 ImageSource *GetSource ();
220 static Value *CreateDefaultImageSource (DependencyObject *instance, DependencyProperty *property);
223 #endif /* __MEDIA_H__ */