~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/Bin.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.CodeDom;
3
 
using System.Reflection;
4
 
 
5
 
namespace Stetic.Wrapper
6
 
{
7
 
        public class Bin: Container
8
 
        {
9
 
                public static new Gtk.Bin CreateInstance (ClassDescriptor klass)
10
 
                {
11
 
                        if (klass.Name == "Gtk.Bin")
12
 
                                return new CustomWidget ();
13
 
                        else
14
 
                                return null;
15
 
                }
16
 
                
17
 
                internal protected override void GenerateBuildCode (GeneratorContext ctx, CodeExpression var)
18
 
                {
19
 
                        if (ClassDescriptor.WrappedTypeName == "Gtk.Bin") {
20
 
                        
21
 
                                // Gtk.Bin needs a helper class which handles child allocation.
22
 
                                // This class needs to be generated since Stetic won't be linked with
23
 
                                // the app.
24
 
                                
25
 
                                bool found = false;
26
 
                                foreach (CodeTypeDeclaration dec in ctx.GlobalCodeNamespace.Types) {
27
 
                                        if (dec.Name == "BinContainer") {
28
 
                                                found = true;
29
 
                                                break;
30
 
                                        }
31
 
                                }
32
 
                                
33
 
                                if (!found)
34
 
                                        GenerateHelperClass (ctx);
35
 
                                
36
 
                                CodeMethodInvokeExpression attachExp = new CodeMethodInvokeExpression (
37
 
                                        new CodeTypeReferenceExpression (ctx.GlobalCodeNamespace.Name + ".BinContainer"),
38
 
                                        "Attach",
39
 
                                        var
40
 
                                );
41
 
                                
42
 
                                // If the Bin has its own action groups, we need to register
43
 
                                // the resulting UIManager in the BinContainer, but it needs to be done
44
 
                                // after generating it. Right now, we only keep a reference to
45
 
                                // the BinContainer.
46
 
                                
47
 
                                string binContainerVar = null;
48
 
                                
49
 
                                if (IsTopLevel && LocalActionGroups.Count > 0) {
50
 
                                        binContainerVar = ctx.NewId ();
51
 
                                        ctx.Statements.Add (
52
 
                                                new CodeVariableDeclarationStatement (
53
 
                                                        ctx.GlobalCodeNamespace.Name + ".BinContainer", 
54
 
                                                        binContainerVar,
55
 
                                                        attachExp
56
 
                                                )
57
 
                                        );
58
 
                                } else {
59
 
                                        ctx.Statements.Add (attachExp);
60
 
                                }
61
 
                                
62
 
                                base.GenerateBuildCode (ctx, var);
63
 
                                
64
 
                                // Register the UIManager, if the Bin has one
65
 
                                
66
 
                                if (binContainerVar != null && UIManagerName != null) {
67
 
                                        ctx.Statements.Add (
68
 
                                                new CodeMethodInvokeExpression (
69
 
                                                        new CodeVariableReferenceExpression (binContainerVar),
70
 
                                                        "SetUiManager",
71
 
                                                        new CodeVariableReferenceExpression (UIManagerName)
72
 
                                                )
73
 
                                        );
74
 
                                }
75
 
                                
76
 
                        } else
77
 
                                base.GenerateBuildCode (ctx, var);
78
 
                }
79
 
                
80
 
                void GenerateHelperClass (GeneratorContext ctx)
81
 
                {
82
 
                        CodeTypeDeclaration type = new CodeTypeDeclaration ("BinContainer");
83
 
                        type.Attributes = MemberAttributes.Private;
84
 
                        type.TypeAttributes = TypeAttributes.NestedAssembly;
85
 
                        ctx.GlobalCodeNamespace.Types.Add (type);
86
 
                        
87
 
                        CodeMemberField field = new CodeMemberField ("Gtk.Widget", "child");
88
 
                        field.Attributes = MemberAttributes.Private;
89
 
                        type.Members.Add (field);
90
 
                        
91
 
                        field = new CodeMemberField ("Gtk.UIManager", "uimanager");
92
 
                        field.Attributes = MemberAttributes.Private;
93
 
                        type.Members.Add (field);
94
 
                        
95
 
                        CodeExpression child = new CodeFieldReferenceExpression (
96
 
                                new CodeThisReferenceExpression (),
97
 
                                "child"
98
 
                        );
99
 
                        
100
 
                        CodeExpression uimanager = new CodeFieldReferenceExpression (
101
 
                                new CodeThisReferenceExpression (),
102
 
                                "uimanager"
103
 
                        );
104
 
                        
105
 
                        // Attach method
106
 
                        
107
 
                        CodeMemberMethod met = new CodeMemberMethod ();
108
 
                        type.Members.Add (met);
109
 
                        met.Name = "Attach";
110
 
                        met.Attributes = MemberAttributes.Public | MemberAttributes.Static;
111
 
                        met.ReturnType = new CodeTypeReference ("BinContainer");
112
 
                        met.Parameters.Add (new CodeParameterDeclarationExpression ("Gtk.Bin", "bin"));
113
 
                        
114
 
                        CodeVariableDeclarationStatement bcDec = new CodeVariableDeclarationStatement ("BinContainer", "bc");
115
 
                        bcDec.InitExpression = new CodeObjectCreateExpression ("BinContainer");
116
 
                        met.Statements.Add (bcDec);
117
 
                        CodeVariableReferenceExpression bc = new CodeVariableReferenceExpression ("bc");
118
 
                        CodeArgumentReferenceExpression bin = new CodeArgumentReferenceExpression ("bin");
119
 
                        
120
 
                        met.Statements.Add (
121
 
                                new CodeAttachEventStatement (
122
 
                                        bin, 
123
 
                                        "SizeRequested",
124
 
                                        new CodeDelegateCreateExpression (
125
 
                                                new CodeTypeReference ("Gtk.SizeRequestedHandler"), bc, "OnSizeRequested"
126
 
                                        )
127
 
                                )
128
 
                        );
129
 
                        
130
 
                        met.Statements.Add (
131
 
                                new CodeAttachEventStatement (
132
 
                                        bin, 
133
 
                                        "SizeAllocated",
134
 
                                        new CodeDelegateCreateExpression (
135
 
                                                new CodeTypeReference ("Gtk.SizeAllocatedHandler"), bc, "OnSizeAllocated"
136
 
                                        )
137
 
                                )
138
 
                        );
139
 
                        
140
 
                        met.Statements.Add (
141
 
                                new CodeAttachEventStatement (
142
 
                                        bin, 
143
 
                                        "Added",
144
 
                                        new CodeDelegateCreateExpression (
145
 
                                                new CodeTypeReference ("Gtk.AddedHandler"), bc, "OnAdded"
146
 
                                        )
147
 
                                )
148
 
                        );
149
 
                        met.Statements.Add (new CodeMethodReturnStatement (bc));
150
 
                        
151
 
                        // OnSizeRequested override
152
 
                        
153
 
                        met = new CodeMemberMethod ();
154
 
                        type.Members.Add (met);
155
 
                        met.Name = "OnSizeRequested";
156
 
                        met.ReturnType = new CodeTypeReference (typeof(void));
157
 
                        met.Parameters.Add (new CodeParameterDeclarationExpression (typeof(object), "sender"));
158
 
                        met.Parameters.Add (new CodeParameterDeclarationExpression ("Gtk.SizeRequestedArgs", "args"));
159
 
                        
160
 
                        CodeConditionStatement cond = new CodeConditionStatement ();
161
 
                        cond.Condition = new CodeBinaryOperatorExpression (
162
 
                                                child,
163
 
                                                CodeBinaryOperatorType.IdentityInequality,
164
 
                                                new CodePrimitiveExpression (null)
165
 
                        );
166
 
                        cond.TrueStatements.Add (
167
 
                                new CodeAssignStatement (
168
 
                                        new CodePropertyReferenceExpression (
169
 
                                                new CodeArgumentReferenceExpression ("args"),
170
 
                                                "Requisition"
171
 
                                        ),
172
 
                                        new CodeMethodInvokeExpression (
173
 
                                                child,
174
 
                                                "SizeRequest"
175
 
                                        )
176
 
                                )
177
 
                        );
178
 
                        met.Statements.Add (cond);
179
 
                        
180
 
                        // OnSizeAllocated method
181
 
                        
182
 
                        met = new CodeMemberMethod ();
183
 
                        type.Members.Add (met);
184
 
                        met.Name = "OnSizeAllocated";
185
 
                        met.ReturnType = new CodeTypeReference (typeof(void));
186
 
                        met.Parameters.Add (new CodeParameterDeclarationExpression (typeof(object), "sender"));
187
 
                        met.Parameters.Add (new CodeParameterDeclarationExpression ("Gtk.SizeAllocatedArgs", "args"));
188
 
                        
189
 
                        cond = new CodeConditionStatement ();
190
 
                        cond.Condition = new CodeBinaryOperatorExpression (
191
 
                                                child,
192
 
                                                CodeBinaryOperatorType.IdentityInequality,
193
 
                                                new CodePrimitiveExpression (null)
194
 
                        );
195
 
                        cond.TrueStatements.Add (
196
 
                                new CodeAssignStatement (
197
 
                                        new CodePropertyReferenceExpression (
198
 
                                                child,
199
 
                                                "Allocation"
200
 
                                        ),
201
 
                                        new CodePropertyReferenceExpression (
202
 
                                                new CodeArgumentReferenceExpression ("args"),
203
 
                                                "Allocation"
204
 
                                        )
205
 
                                )
206
 
                        );
207
 
                        met.Statements.Add (cond);
208
 
                        
209
 
                        // OnAdded method
210
 
                        
211
 
                        met = new CodeMemberMethod ();
212
 
                        type.Members.Add (met);
213
 
                        met.Name = "OnAdded";
214
 
                        met.ReturnType = new CodeTypeReference (typeof(void));
215
 
                        met.Parameters.Add (new CodeParameterDeclarationExpression (typeof(object), "sender"));
216
 
                        met.Parameters.Add (new CodeParameterDeclarationExpression ("Gtk.AddedArgs", "args"));
217
 
                        
218
 
                        met.Statements.Add (
219
 
                                new CodeAssignStatement (
220
 
                                        child,
221
 
                                        new CodePropertyReferenceExpression (
222
 
                                                new CodeArgumentReferenceExpression ("args"),
223
 
                                                "Widget"
224
 
                                        )
225
 
                                )
226
 
                        );
227
 
                        
228
 
                        // SetUiManager method
229
 
                        
230
 
                        met = new CodeMemberMethod ();
231
 
                        type.Members.Add (met);
232
 
                        met.Name = "SetUiManager";
233
 
                        met.Attributes = MemberAttributes.Public | MemberAttributes.Final;
234
 
                        met.ReturnType = new CodeTypeReference (typeof(void));
235
 
                        met.Parameters.Add (new CodeParameterDeclarationExpression (typeof(Gtk.UIManager), "uim"));
236
 
                        
237
 
                        met.Statements.Add (
238
 
                                new CodeAssignStatement (
239
 
                                        uimanager,
240
 
                                        new CodeArgumentReferenceExpression ("uim")
241
 
                                )
242
 
                        );
243
 
                        met.Statements.Add (
244
 
                                new CodeAttachEventStatement (
245
 
                                        child, 
246
 
                                        "Realized",
247
 
                                        new CodeDelegateCreateExpression (
248
 
                                                new CodeTypeReference ("System.EventHandler"), new CodeThisReferenceExpression(), "OnRealized"
249
 
                                        )
250
 
                                )
251
 
                        );
252
 
                        
253
 
                        // OnRealized method
254
 
                        
255
 
                        met = new CodeMemberMethod ();
256
 
                        type.Members.Add (met);
257
 
                        met.Name = "OnRealized";
258
 
                        met.ReturnType = new CodeTypeReference (typeof(void));
259
 
                        met.Parameters.Add (new CodeParameterDeclarationExpression (typeof(object), "sender"));
260
 
                        met.Parameters.Add (new CodeParameterDeclarationExpression ("System.EventArgs", "args"));
261
 
                        
262
 
                        cond = new CodeConditionStatement ();
263
 
                        cond.Condition = new CodeBinaryOperatorExpression (
264
 
                                                uimanager,
265
 
                                                CodeBinaryOperatorType.IdentityInequality,
266
 
                                                new CodePrimitiveExpression (null)
267
 
                        );
268
 
                        
269
 
                        cond.TrueStatements.Add (
270
 
                                new CodeVariableDeclarationStatement (
271
 
                                        typeof(Gtk.Widget),
272
 
                                        "w"
273
 
                                )
274
 
                        );
275
 
                        
276
 
                        CodeExpression wexp = new CodeVariableReferenceExpression ("w");
277
 
                        
278
 
                        cond.TrueStatements.Add (
279
 
                                new CodeAssignStatement (
280
 
                                        wexp,
281
 
                                        new CodePropertyReferenceExpression (
282
 
                                                child,
283
 
                                                "Toplevel"
284
 
                                        )
285
 
                                )
286
 
                        );
287
 
                                                                
288
 
                        CodeConditionStatement cond2 = new CodeConditionStatement ();
289
 
                        cond2.Condition = new CodeBinaryOperatorExpression (
290
 
                                new CodeBinaryOperatorExpression (
291
 
                                        wexp,
292
 
                                        CodeBinaryOperatorType.IdentityInequality,
293
 
                                        new CodePrimitiveExpression (null)
294
 
                                ),
295
 
                                CodeBinaryOperatorType.BooleanAnd,
296
 
                                new CodeMethodInvokeExpression (
297
 
                                        new CodeTypeOfExpression ("Gtk.Window"),
298
 
                                        "IsInstanceOfType",
299
 
                                        wexp
300
 
                                )
301
 
                        );
302
 
                        
303
 
                        cond2.TrueStatements.Add (
304
 
                                new CodeMethodInvokeExpression (
305
 
                                        new CodeCastExpression ("Gtk.Window", wexp),
306
 
                                        "AddAccelGroup",
307
 
                                        new CodePropertyReferenceExpression (
308
 
                                                uimanager,
309
 
                                                "AccelGroup"
310
 
                                        )
311
 
                                )
312
 
                        );
313
 
                        cond2.TrueStatements.Add (
314
 
                                new CodeAssignStatement (
315
 
                                        uimanager,
316
 
                                        new CodePrimitiveExpression (null)
317
 
                                )
318
 
                        );
319
 
                        cond.TrueStatements.Add (cond2);
320
 
                        
321
 
                        met.Statements.Add (cond);
322
 
                }
323
 
        }
324
 
        
325
 
/*
326
 
         This is a model of what GenerateHelperClass generates:
327
 
        
328
 
        class BinContainer
329
 
        {
330
 
                Gtk.Widget child;
331
 
                UIManager uimanager;
332
 
                
333
 
                public static BinContainer Attach (Gtk.Bin bin)
334
 
                {
335
 
                        BinContainer bc = new BinContainer ();
336
 
                        bin.SizeRequested += new Gtk.SizeRequestedHandler (bc.OnSizeRequested);
337
 
                        bin.SizeAllocated += new Gtk.SizeAllocatedHandler (bc.OnSizeAllocated);
338
 
                        bin.Added += new Gtk.AddedHandler (bc.OnAdded);
339
 
                        return bin;
340
 
                }
341
 
                
342
 
                void OnSizeRequested (object s, Gtk.SizeRequestedArgs args)
343
 
                {
344
 
                        if (child != null)
345
 
                                args.Requisition = child.SizeRequest ();
346
 
                }
347
 
                
348
 
                void OnSizeAllocated (object s, Gtk.SizeAllocatedArgs args)
349
 
                {
350
 
                        if (child != null)
351
 
                                child.Allocation = args.Allocation;
352
 
                }
353
 
                
354
 
                void OnAdded (object s, Gtk.AddedArgs args)
355
 
                {
356
 
                        child = args.Widget;
357
 
                }
358
 
                
359
 
                public void SetUiManager (UIManager manager)
360
 
                {
361
 
                        uimanager = manager;
362
 
                        child.Realized += new System.EventHandler (OnRealized);
363
 
                }
364
 
                
365
 
                void OnRealized ()
366
 
                {
367
 
                        if (uimanager != null) {
368
 
                                Gtk.Widget w = child.Toplevel;
369
 
                                if (w != null && w is Gtk.Window) {
370
 
                                        ((Gtk.Window)w).AddAccelGroup (uimanager.AccelGroup);
371
 
                                        uimanager = null;
372
 
                                }
373
 
                        }
374
 
                }
375
 
        }
376
 
*/
377
 
 
378
 
}