~ubuntu-branches/debian/sid/f-spot/sid

« back to all changes in this revision

Viewing changes to lib/unique-sharp/generator/StructBase.cs

  • Committer: Bazaar Package Importer
  • Author(s): Iain Lane
  • Date: 2010-05-17 11:59:58 UTC
  • mfrom: (2.4.6 sid)
  • Revision ID: james.westby@ubuntu.com-20100517115958-rplbws9ddda5ikcp
* New upstream release 0.6.2:
 + Stable release before starting large cleanup refactorings, mostly 
   usability, bug fixes and translations as well as some modernization.
   A large part of this comes from the Ubuntu one hundred papercuts effort.
 + Replaced the old slow slideshow code with new fast SlideShow
   (Gabriel Burt)
 + Wording changes for clarity (Edit Tag) (Jeffrey Finkelstein)
 + Fix version selection tooltip (Lorenzo Milesi)
 + Add gconf schema (Jeffrey Stedfast)
 + Added a border to filmstrip thumbnails (Matt Perry) (LP: #513036)
 + Fix display names of color profiles (Pascal de Bruijn)
 + Fix histogram colors on theme change (Paul Wellner Bou)
 + Always update ImageView adjustments when scaling.
   (Wojciech Dzierżanowski)
 + Correctly set attributes on copying (Yann Leprince)
 + Correct mnemonics in create tag dialog (Yves Kurz)
 + Provide sane defaults for image resize size (Yves Kurz)
 + Updates to the build system, including fixes for distcheck
   (Ruben Vermeersch)
 + Fix wording for duplicate hashing (Matt Perry)
 + Fix wording for imported tags tag (Ian Churcher)
 + Fix label alignment in preferences dialog (Pascal de Bruijn)
 + Add unique# and use it to handle our activation (Stephane Delcroix)
 + Stop bundling Mono.Addins (Stephane Delcroix)
 + Avoid leakage in straighten and softfocus editor (Stephane Delcroix)
 + Allow to copy files to clipboard (Stephane Delcroix)
 + Large number of color management related fixes (Stephane Delcroix)
 + Removed the Beagle plugin at the request of the openSUSE team
   (Ruben Vermeersch)
 + A pile of other cleanups and fixes (Ruben Vermeersch)
   - Including '"Import tags" category sounds like an action' (LP: #488784)
 + Two performance improvement patches for our database interaction
   (Michal Nánási)
 + Fix the longstanding issue of F-Spot changing photo timestamps
   (Paul Wellner Bou) (Closes: #445511) (LP: #175191)
 + Tons of translation updates (seriously)
* debian/control, debian/rules: Drop gnome-screensaver build-dep and set
  variables at configure time. Should reduce the BD chain significantly. 
* debian/control: Increase minimum version on libgphoto2-dev BD in line with
  configure requirements.
* debian/control: Add build-dependency on libunique-dev to build new
  unique-sharp bindings which f-spot now uses to handle activation.
* debian/patches/debian_link-system-mono-addins.patch: Drop, now upstream 
* debian/patches/*: Refresh to apply to new upstream version 
* debian/rules: Pass include directories to autoreconf to have the correct
  macros in scope for the new build system 
* debian/patches/ubuntu*: Steal patches from Ubuntu package to improve
  --view mode and add an undo/redo stack. Rebase on new upstream version.
  Thanks to Chris Halse Rogers.
* debian/patches/ubuntu_fname_quote_percent.patch: Drop, now upstream.
* debian/patches/git_transition_duration.patch: Cherrypick patch from
  upstream to reduce the transition duration when entering fullscreen to
  600ms. 
* debian/rules: Incorporate Ubuntu specific changes, and guard by a call to
  dpkg-vendor.
* debian/rules: Don't try to install the gconf schemas when building 

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// GtkSharp.Generation.StructBase.cs - The Structure/Boxed Base Class.
 
2
//
 
3
// Author: Mike Kestner <mkestner@speakeasy.net>
 
4
//
 
5
// Copyright (c) 2001-2003 Mike Kestner
 
6
//
 
7
// This program is free software; you can redistribute it and/or
 
8
// modify it under the terms of version 2 of the GNU General Public
 
9
// License as published by the Free Software Foundation.
 
10
//
 
11
// This program is distributed in the hope that it will be useful,
 
12
// but WITHOUT ANY WARRANTY; without even the implied warranty of
 
13
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 
14
// General Public License for more details.
 
15
//
 
16
// You should have received a copy of the GNU General Public
 
17
// License along with this program; if not, write to the
 
18
// Free Software Foundation, Inc., 59 Temple Place - Suite 330,
 
19
// Boston, MA 02111-1307, USA.
 
20
 
 
21
 
 
22
namespace GtkSharp.Generation {
 
23
 
 
24
        using System;
 
25
        using System.Collections;
 
26
        using System.IO;
 
27
        using System.Text.RegularExpressions;
 
28
        using System.Xml;
 
29
 
 
30
        public abstract class StructBase : ClassBase, IManualMarshaler {
 
31
        
 
32
                new ArrayList fields = new ArrayList ();
 
33
                bool need_read_native = false;
 
34
 
 
35
                protected StructBase (XmlElement ns, XmlElement elem) : base (ns, elem)
 
36
                {
 
37
                        foreach (XmlNode node in elem.ChildNodes) {
 
38
 
 
39
                                if (!(node is XmlElement)) continue;
 
40
                                XmlElement member = (XmlElement) node;
 
41
 
 
42
                                switch (node.Name) {
 
43
                                case "field":
 
44
                                        fields.Add (new StructField (member, this));
 
45
                                        break;
 
46
 
 
47
                                case "callback":
 
48
                                        Statistics.IgnoreCount++;
 
49
                                        break;
 
50
 
 
51
                                default:
 
52
                                        if (!IsNodeNameHandled (node.Name))
 
53
                                                Console.WriteLine ("Unexpected node " + node.Name + " in " + CName);
 
54
                                        break;
 
55
                                }
 
56
                        }
 
57
                }
 
58
 
 
59
                public override string DefaultValue {
 
60
                        get {
 
61
                                return QualifiedName + ".Zero";
 
62
                        }
 
63
                }
 
64
 
 
65
                public override string MarshalType {
 
66
                        get {
 
67
                                return "IntPtr";
 
68
                        }
 
69
                }
 
70
 
 
71
                public override string AssignToName {
 
72
                        get { throw new NotImplementedException (); }
 
73
                }
 
74
 
 
75
                public override string CallByName ()
 
76
                {
 
77
                        return "this_as_native";
 
78
                }
 
79
 
 
80
                public override string CallByName (string var)
 
81
                {
 
82
                        return var + "_as_native";
 
83
                }
 
84
 
 
85
                public override string FromNative (string var)
 
86
                {
 
87
                        if (DisableNew)
 
88
                                return var + " == IntPtr.Zero ? " + QualifiedName + ".Zero : (" + QualifiedName + ") System.Runtime.InteropServices.Marshal.PtrToStructure (" + var + ", typeof (" + QualifiedName + "))";
 
89
                        else
 
90
                                return QualifiedName + ".New (" + var + ")";
 
91
                }
 
92
                
 
93
                public string AllocNative (string var)
 
94
                {
 
95
                        return "GLib.Marshaller.StructureToPtrAlloc (" + var + ")";
 
96
                }
 
97
 
 
98
                public string ReleaseNative (string var)
 
99
                {
 
100
                        return "Marshal.FreeHGlobal (" +var + ")";
 
101
                }
 
102
 
 
103
                private bool DisableNew {
 
104
                        get {
 
105
                                return Elem.HasAttribute ("disable_new");
 
106
                        }
 
107
                }
 
108
 
 
109
                protected new void GenFields (GenerationInfo gen_info)
 
110
                {
 
111
                        int bitfields = 0;
 
112
                        bool need_field = true;
 
113
 
 
114
                        foreach (StructField field in fields) {
 
115
                                if (field.IsBitfield) {
 
116
                                        if (need_field) {
 
117
                                                StreamWriter sw = gen_info.Writer;
 
118
 
 
119
                                                sw.WriteLine ("\t\tprivate uint _bitfield{0};\n", bitfields++);
 
120
                                                need_field = false;
 
121
                                        }
 
122
                                } else
 
123
                                        need_field = true;
 
124
                                field.Generate (gen_info, "\t\t");
 
125
                        }
 
126
                }
 
127
 
 
128
                public override bool Validate ()
 
129
                {
 
130
                        foreach (StructField field in fields) {
 
131
                                if (!field.Validate ()) {
 
132
                                        Console.WriteLine ("in Struct " + QualifiedName);
 
133
                                        if (!field.IsPointer)
 
134
                                                return false;
 
135
                                }
 
136
                        }
 
137
 
 
138
                        return base.Validate ();
 
139
                }
 
140
 
 
141
                public override void Generate (GenerationInfo gen_info)
 
142
                {
 
143
                        bool need_close = false;
 
144
                        if (gen_info.Writer == null) {
 
145
                                gen_info.Writer = gen_info.OpenStream (Name);
 
146
                                need_close = true;
 
147
                        }
 
148
 
 
149
                        StreamWriter sw = gen_info.Writer;
 
150
                        
 
151
                        sw.WriteLine ("namespace " + NS + " {");
 
152
                        sw.WriteLine ();
 
153
                        sw.WriteLine ("\tusing System;");
 
154
                        sw.WriteLine ("\tusing System.Collections;");
 
155
                        sw.WriteLine ("\tusing System.Runtime.InteropServices;");
 
156
                        sw.WriteLine ();
 
157
                        
 
158
                        sw.WriteLine ("#region Autogenerated code");
 
159
                        if (IsDeprecated)
 
160
                                sw.WriteLine ("\t[Obsolete]");
 
161
                        sw.WriteLine ("\t[StructLayout(LayoutKind.Sequential)]");
 
162
                        string access = IsInternal ? "internal" : "public";
 
163
                        sw.WriteLine ("\t" + access + " struct " + Name + " {");
 
164
                        sw.WriteLine ();
 
165
 
 
166
                        need_read_native = false;
 
167
                        GenFields (gen_info);
 
168
                        sw.WriteLine ();
 
169
                        GenCtors (gen_info);
 
170
                        GenMethods (gen_info, null, this);
 
171
                        if (need_read_native)
 
172
                                GenReadNative (sw);
 
173
 
 
174
                        if (!need_close)
 
175
                                return;
 
176
 
 
177
                        sw.WriteLine ("#endregion");
 
178
                        AppendCustom(sw, gen_info.CustomDir);
 
179
                        
 
180
                        sw.WriteLine ("\t}");
 
181
                        sw.WriteLine ("}");
 
182
                        sw.Close ();
 
183
                        gen_info.Writer = null;
 
184
                }
 
185
                
 
186
                protected override void GenCtors (GenerationInfo gen_info)
 
187
                {
 
188
                        StreamWriter sw = gen_info.Writer;
 
189
 
 
190
                        sw.WriteLine ("\t\tpublic static {0} Zero = new {0} ();", QualifiedName);
 
191
                        sw.WriteLine();
 
192
                        if (!DisableNew) {
 
193
                                sw.WriteLine ("\t\tpublic static " + QualifiedName + " New(IntPtr raw) {");
 
194
                                sw.WriteLine ("\t\t\tif (raw == IntPtr.Zero)");
 
195
                                sw.WriteLine ("\t\t\t\treturn {0}.Zero;", QualifiedName);
 
196
                                sw.WriteLine ("\t\t\treturn ({0}) Marshal.PtrToStructure (raw, typeof ({0}));", QualifiedName);
 
197
                                sw.WriteLine ("\t\t}");
 
198
                                sw.WriteLine ();
 
199
                        }
 
200
 
 
201
                        foreach (Ctor ctor in Ctors)
 
202
                                ctor.IsStatic = true;
 
203
 
 
204
                        base.GenCtors (gen_info);
 
205
                }
 
206
 
 
207
                void GenReadNative (StreamWriter sw)
 
208
                {
 
209
                        sw.WriteLine ("\t\tstatic void ReadNative (IntPtr native, ref {0} target)", QualifiedName);
 
210
                        sw.WriteLine ("\t\t{");
 
211
                        sw.WriteLine ("\t\t\ttarget = New (native);");
 
212
                        sw.WriteLine ("\t\t}");
 
213
                        sw.WriteLine ();
 
214
                }
 
215
 
 
216
                public override void Prepare (StreamWriter sw, string indent)
 
217
                {
 
218
                        sw.WriteLine (indent + "IntPtr this_as_native = System.Runtime.InteropServices.Marshal.AllocHGlobal (System.Runtime.InteropServices.Marshal.SizeOf (this));");
 
219
                        sw.WriteLine (indent + "System.Runtime.InteropServices.Marshal.StructureToPtr (this, this_as_native, false);");
 
220
                }
 
221
 
 
222
                public override void Finish (StreamWriter sw, string indent)
 
223
                {
 
224
                        need_read_native = true;
 
225
                        sw.WriteLine (indent + "ReadNative (this_as_native, ref this);");
 
226
                        sw.WriteLine (indent + "System.Runtime.InteropServices.Marshal.FreeHGlobal (this_as_native);");
 
227
                }
 
228
        }
 
229
}
 
230