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 /* @ManagedEvents=Manual */
104 class MediaBase
: public FrameworkElement
{
106 static void set_source_async (EventObject
*user_data
);
107 void SetSourceAsyncCallback ();
111 Downloader
*downloader
;
116 Downloader
*downloader
;
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
; }
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 */
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
{
177 void DownloadProgress ();
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
);
191 /* @PropertyType=ImageSource,AutoCreator=Image::CreateDefaultImageSource,GenerateAccessors */
192 const static int SourceProperty
;
194 /* @DelegateType=EventHandler<ExceptionRoutedEventArgs> */
195 const static int ImageFailedEvent
;
197 /* @GenerateCBinding,GeneratePInvoke */
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__ */