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
);
86 /* @ManagedDependencyProperties=None */
87 /* @ManagedEvents=Manual */
88 class MediaBase
: public FrameworkElement
{
90 static void set_source_async (EventObject
*user_data
);
91 void SetSourceAsyncCallback ();
95 Downloader
*downloader
;
100 Downloader
*downloader
;
103 int allow_downloads
:1;
104 int source_changed
:1;
106 virtual ~MediaBase ();
108 virtual void DownloaderFailed (EventArgs
*args
);
109 virtual void DownloaderComplete ();
110 void DownloaderAbort ();
112 static void downloader_complete (EventObject
*sender
, EventArgs
*calldata
, gpointer closure
);
113 static void downloader_failed (EventObject
*sender
, EventArgs
*calldata
, gpointer closure
);
115 virtual void OnEmptySource () { }
117 void SetDownloadProgress (double progress
);
119 virtual DownloaderAccessPolicy
GetDownloaderPolicy (const char *uri
) { return MediaPolicy
; }
122 /* @PropertyType=string,AlwaysChange,GenerateAccessors */
123 const static int SourceProperty
;
124 /* @PropertyType=Stretch,DefaultValue=StretchUniform,GenerateAccessors */
125 const static int StretchProperty
;
126 /* @PropertyType=double,DefaultValue=0.0,GenerateAccessors */
127 const static int DownloadProgressProperty
;
129 const static int DownloadProgressChangedEvent
;
131 /* @GenerateCBinding,GeneratePInvoke */
134 virtual void SetSourceInternal (Downloader
*downloader
, char *PartName
);
135 virtual void SetSource (Downloader
*downloader
, const char *PartName
);
136 /* @GenerateCBinding,GeneratePInvoke */
137 void SetSource (const char *uri
);
139 void SetAllowDownloads (bool allow
);
140 bool AllowDownloads () { return allow_downloads
; }
142 virtual void OnPropertyChanged (PropertyChangedEventArgs
*args
, MoonError
*error
);
144 virtual void OnLoaded ();
147 // Property Accessors
149 double GetDownloadProgress ();
151 const char *GetSource ();
153 void SetStretch (Stretch stretch
);
154 Stretch
GetStretch ();
158 /* @Namespace=System.Windows.Controls */
159 class Image
: public MediaBase
{
161 void DownloadProgress ();
162 void ImageOpened (RoutedEventArgs
*args
);
163 void ImageFailed (ImageErrorEventArgs
*args
);
164 void SourcePixelDataChanged ();
166 static void download_progress (EventObject
*sender
, EventArgs
*calldata
, gpointer closure
);
167 static void image_opened (EventObject
*sender
, EventArgs
*calldata
, gpointer closure
);
168 static void image_failed (EventObject
*sender
, EventArgs
*calldata
, gpointer closure
);
169 static void source_pixel_data_changed (EventObject
*sender
, EventArgs
*calldata
, gpointer closure
);
175 /* @PropertyType=ImageSource,AutoCreator=Image::CreateDefaultImageSource,GenerateAccessors */
176 const static int SourceProperty
;
178 /* @DelegateType=EventHandler<ExceptionRoutedEventArgs> */
179 const static int ImageFailedEvent
;
181 /* @DelegateType=EventHandler<RoutedEventArgs> */
182 const static int ImageOpenedEvent
;
184 /* @GenerateCBinding,GeneratePInvoke */
187 virtual void Render (cairo_t
*cr
, Region
*region
, bool path_only
= false);
189 virtual void SetSourceInternal (Downloader
*downloader
, char *PartName
);
190 virtual void SetSource (Downloader
*downloader
, const char *PartName
);
192 virtual void OnPropertyChanged (PropertyChangedEventArgs
*args
, MoonError
*error
);
193 virtual void OnSubPropertyChanged (DependencyProperty
*prop
, DependencyObject
*obj
, PropertyChangedEventArgs
*subobj_args
);
195 int GetImageHeight () { return GetSource () ? GetSource ()->GetPixelHeight () : 0; };
196 int GetImageWidth () { return GetSource () ? GetSource ()->GetPixelWidth () : 0; };
198 virtual Rect
GetCoverageBounds ();
200 virtual Size
MeasureOverride (Size availableSize
);
201 virtual Size
ArrangeOverride (Size finalSize
);
202 virtual Size
ComputeActualSize ();
203 virtual bool CanFindElement () { return true; }
205 virtual bool InsideObject (cairo_t
*cr
, double x
, double y
);
207 /* @GenerateCBinding,GeneratePInvoke */
208 void SetSource (ImageSource
*source
);
209 ImageSource
*GetSource ();
211 static Value
*CreateDefaultImageSource (DependencyObject
*instance
, DependencyProperty
*property
);
214 #endif /* __MEDIA_H__ */