1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
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.
17 #include <gdk/gdkpixbuf.h>
21 #include "frameworkelement.h"
23 #include "downloader.h"
25 #include "bitmapsource.h"
28 /* @Namespace=System.Windows.Media */
29 class MediaAttribute
: public DependencyObject
{
31 virtual ~MediaAttribute () {}
34 /* @PropertyType=string,GenerateAccessors */
35 const static int ValueProperty
;
37 /* @GenerateCBinding,GeneratePInvoke */
38 MediaAttribute () { SetObjectType (Type::MEDIAATTRIBUTE
); }
43 const char *GetValue();
44 void SetValue (const char *value
);
48 /* @Namespace=System.Windows.Media */
49 class MediaAttributeCollection
: public DependencyObjectCollection
{
51 virtual ~MediaAttributeCollection () {}
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
{
73 virtual ~TimelineMarkerCollection () {}
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
);
87 class MarkerReachedEventArgs
: public EventArgs
{
88 TimelineMarker
*marker
;
91 virtual ~MarkerReachedEventArgs ();
94 MarkerReachedEventArgs (TimelineMarker
*marker
);
96 /* @GenerateCBinding,GeneratePInvoke */
97 TimelineMarker
*GetMarker () { return marker
; }
101 /* @Namespace=None */
102 /* @ManagedDependencyProperties=None */
103 class MediaBase
: public FrameworkElement
{
105 static void set_source_async (EventObject
*user_data
);
106 void SetSourceAsyncCallback ();
110 Downloader
*downloader
;
115 Downloader
*downloader
;
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
; }
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 */
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
{
176 void DownloadProgress ();
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
);
190 /* @PropertyType=ImageSource,AutoCreator=Image::CreateDefaultImageSource,GenerateAccessors */
191 const static int SourceProperty
;
193 const static int ImageFailedEvent
;
195 /* @GenerateCBinding,GeneratePInvoke */
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__ */