~ubuntu-branches/ubuntu/oneiric/monodevelop/oneiric-updates

« back to all changes in this revision

Viewing changes to src/addins/MonoDevelop.GtkCore/lib/stetic/libstetic/wrapper/Image.cs

  • Committer: Bazaar Package Importer
  • Author(s): Jo Shields
  • Date: 2009-02-18 08:40:51 UTC
  • mfrom: (1.2.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20090218084051-gh8m6ukvokbwj7cf
Tags: 1.9.2+dfsg-1ubuntu1
* Merge from Debian Experimental (LP: #330519), remaining Ubuntu changes:
  + debian/control:
    - Update for Gnome# 2.24
    - Add libmono-cairo1.0-cil to build-deps to fool pkg-config check

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
using System;
2
 
using System.Xml;
3
 
using System.Collections;
4
 
 
5
 
namespace Stetic.Wrapper {
6
 
 
7
 
        public class Image : Misc {
8
 
        
9
 
                ImageInfo imageInfo;
10
 
 
11
 
                public static new Gtk.Image CreateInstance ()
12
 
                {
13
 
                        return new Gtk.Image (Gtk.Stock.Execute, Gtk.IconSize.Dialog);
14
 
                }
15
 
                
16
 
                protected override void ReadProperties (ObjectReader reader, XmlElement elem)
17
 
                {
18
 
                        if (reader.Format == FileFormat.Glade) {
19
 
                                string file = (string)GladeUtils.ExtractProperty (elem, "pixbuf", "");
20
 
                                string stock = (string)GladeUtils.ExtractProperty (elem, "stock", "");
21
 
                                string iconSize = (string)GladeUtils.ExtractProperty (elem, "icon_size", "");
22
 
                                base.ReadProperties (reader, elem);
23
 
                                
24
 
                                if (stock != null && stock.Length > 0) {
25
 
                                        Pixbuf = ImageInfo.FromTheme (stock, (Gtk.IconSize) int.Parse (iconSize));
26
 
                                } else if (file != null && file != "") {
27
 
                                        Pixbuf = ImageInfo.FromFile (file);
28
 
                                }
29
 
                        } else
30
 
                                base.ReadProperties (reader, elem);
31
 
                }
32
 
                
33
 
                protected override XmlElement WriteProperties (ObjectWriter writer)
34
 
                {
35
 
                        XmlElement elem = base.WriteProperties (writer);
36
 
                        if (imageInfo != null) {
37
 
                                if (writer.Format == FileFormat.Glade) {
38
 
                                        // The generated pixbuf property doesn't have a valid value, it needs to be replaced.
39
 
                                        GladeUtils.ExtractProperty (elem, "pixbuf", "");
40
 
                                        switch (imageInfo.Source) {
41
 
                                                case ImageSource.File:
42
 
                                                        GladeUtils.SetProperty (elem, "pixbuf", imageInfo.Name);
43
 
                                                        break;
44
 
                                                case ImageSource.Theme:
45
 
                                                        GladeUtils.SetProperty (elem, "stock", imageInfo.Name);
46
 
                                                        GladeUtils.SetProperty (elem, "icon_size", ((int)imageInfo.ThemeIconSize).ToString ());
47
 
                                                        break;
48
 
                                                default:
49
 
                                                        throw new System.NotSupportedException ("Image source not supported by Glade.");
50
 
                                        }
51
 
                                }
52
 
                        }
53
 
                        return elem;
54
 
                }
55
 
 
56
 
                Gtk.Image image {
57
 
                        get {
58
 
                                return (Gtk.Image)Wrapped;
59
 
                        }
60
 
                }
61
 
 
62
 
                void BreakImage ()
63
 
                {
64
 
                        image.IconSize = (int)Gtk.IconSize.Button;
65
 
                        image.Stock = Gtk.Stock.MissingImage;
66
 
                }
67
 
 
68
 
                public ImageInfo Pixbuf {
69
 
                        get { return imageInfo; }
70
 
                        set {
71
 
                                imageInfo = value;
72
 
                                if (imageInfo == null)
73
 
                                        BreakImage ();
74
 
                                else
75
 
                                        image.Pixbuf = imageInfo.GetImage (Project);
76
 
                                EmitNotify ("Pixbuf");
77
 
                        }
78
 
                }
79
 
        }
80
 
}