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

« back to all changes in this revision

Viewing changes to src/addins/MacPlatform/Framework/NavDialog.cs

  • Committer: Bazaar Package Importer
  • Author(s): Jo Shields
  • Date: 2011-06-27 17:03:13 UTC
  • mto: (1.8.1 upstream)
  • mto: This revision was merged to the branch mainline in revision 54.
  • Revision ID: james.westby@ubuntu.com-20110627170313-6cvz3s19x6e9hqe9
ImportĀ upstreamĀ versionĀ 2.5.92+dfsg

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
// 
2
 
// Carbon.cs
3
 
//  
4
 
// Author:
5
 
//       Michael Hutchinson <mhutchinson@novell.com>
6
 
// 
7
 
// Copyright (c) 2010 Novell, Inc. (http://www.novell.com)
8
 
// 
9
 
// Permission is hereby granted, free of charge, to any person obtaining a copy
10
 
// of this software and associated documentation files (the "Software"), to deal
11
 
// in the Software without restriction, including without limitation the rights
12
 
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13
 
// copies of the Software, and to permit persons to whom the Software is
14
 
// furnished to do so, subject to the following conditions:
15
 
// 
16
 
// The above copyright notice and this permission notice shall be included in
17
 
// all copies or substantial portions of the Software.
18
 
// 
19
 
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20
 
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21
 
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22
 
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23
 
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24
 
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
25
 
// THE SOFTWARE.
26
 
 
27
 
using System;
28
 
using System.Runtime.InteropServices;
29
 
using System.Collections.Generic;
30
 
using System.Diagnostics;
31
 
 
32
 
namespace OSXIntegration.Framework
33
 
{
34
 
        
35
 
        class NavDialog : IDisposable
36
 
        {
37
 
                IntPtr ptr;
38
 
                
39
 
                public static NavDialog CreateChooseFileDialog (NavDialogCreationOptions options)       
40
 
                {
41
 
                        NavDialog dialog = new NavDialog ();
42
 
                        CheckReturn (NavCreateChooseFileDialog (ref options.data, IntPtr.Zero, new NavEventUPP (), new NavPreviewUPP (),
43
 
                                                                            new NavObjectFilterUPP (), IntPtr.Zero, out dialog.ptr));
44
 
                        return dialog;
45
 
                }
46
 
                
47
 
                public static NavDialog CreateChooseFolderDialog (NavDialogCreationOptions options)     
48
 
                {
49
 
                        NavDialog dialog = new NavDialog ();
50
 
                        CheckReturn (NavCreateChooseFolderDialog (ref options.data, new NavEventUPP (),
51
 
                                                                            new NavObjectFilterUPP (), IntPtr.Zero, out dialog.ptr));
52
 
                        return dialog;
53
 
                }
54
 
                
55
 
                public static NavDialog CreatePutFileDialog (NavDialogCreationOptions options)  
56
 
                {
57
 
                        NavDialog dialog = new NavDialog ();
58
 
                        CheckReturn (NavCreatePutFileDialog (ref options.data, new OSType (), new OSType (),
59
 
                                                                         new NavEventUPP (), IntPtr.Zero, out dialog.ptr));
60
 
                        return dialog;
61
 
                }
62
 
                
63
 
                public static NavDialog CreateNewFolderDialog (NavDialogCreationOptions options)        
64
 
                {
65
 
                        NavDialog dialog = new NavDialog ();
66
 
                        CheckReturn (NavCreateNewFolderDialog (ref options.data, new NavEventUPP (),
67
 
                                                                           IntPtr.Zero, out dialog.ptr));
68
 
                        return dialog;
69
 
                }
70
 
                
71
 
                public NavUserAction Run ()
72
 
                {
73
 
                        CheckDispose ();
74
 
                        CheckReturn (NavDialogRun (ptr));
75
 
                        return NavDialogGetUserAction (ptr);
76
 
                }
77
 
                
78
 
                public NavReplyRecordRef GetReply ()
79
 
                {
80
 
                        CheckDispose ();
81
 
                        var record = new NavReplyRecordRef ();
82
 
                        CheckReturn (NavDialogGetReply (ptr, out record.value));
83
 
                        return record;
84
 
                }
85
 
                
86
 
                public void SetLocation (string location)
87
 
                {
88
 
                        CheckDispose ();
89
 
                        throw new NotImplementedException ();
90
 
                //      AEDesc desc = new AEDesc ();
91
 
                //      CheckReturn (NavCustomControl (ptr, NavCustomControlMessage.SetLocation, ref desc)); 
92
 
                }
93
 
                
94
 
                void CheckDispose ()
95
 
                {
96
 
                        if (ptr == IntPtr.Zero)
97
 
                                throw new ObjectDisposedException ("NavDialog");
98
 
                }
99
 
                
100
 
                public void Dispose ()
101
 
                {
102
 
                        if (ptr != IntPtr.Zero) {
103
 
                                NavDialogDispose (ptr);
104
 
                                ptr = IntPtr.Zero;
105
 
                                GC.SuppressFinalize (this);
106
 
                        }
107
 
                }
108
 
                
109
 
                ~NavDialog ()
110
 
                {
111
 
                        Console.WriteLine ("WARNING: NavDialog not disposed");
112
 
                }
113
 
                
114
 
                [DllImport (Carbon.CarbonLib)]
115
 
                static extern NavStatus NavCreateChooseFileDialog (ref NavDialogCreationOptionsData options, IntPtr inTypeList, 
116
 
                                                                   NavEventUPP inEventProc, NavPreviewUPP inPreviewProc, 
117
 
                                                                   NavObjectFilterUPP inFilterProc, IntPtr inClientData, out IntPtr navDialogRef);
118
 
                //intTypeList is a NavTypeListHandle, which apparently is a pointer to  NavTypeListPtr, which is a pointer to a NavTypeList
119
 
                
120
 
                [DllImport (Carbon.CarbonLib)]
121
 
                static extern NavStatus NavCreateChooseFolderDialog (ref NavDialogCreationOptionsData options, 
122
 
                                                                     NavEventUPP inEventProc, NavObjectFilterUPP inFilterProc,
123
 
                                                                     IntPtr inClientData, out IntPtr navDialogRef);
124
 
                
125
 
                [DllImport (Carbon.CarbonLib)]
126
 
                static extern NavStatus NavCreatePutFileDialog (ref NavDialogCreationOptionsData options, OSType inFileType,
127
 
                                                                OSType inFileCreator, NavEventUPP inEventProc,
128
 
                                                                IntPtr inClientData, out IntPtr navDialogRef);
129
 
 
130
 
                [DllImport (Carbon.CarbonLib)]
131
 
                static extern NavStatus NavCreateNewFolderDialog (ref NavDialogCreationOptionsData options, 
132
 
                                                                  NavEventUPP inEventProc, IntPtr inClientData, 
133
 
                                                                  out IntPtr navDialogRef);
134
 
                
135
 
                [DllImport (Carbon.CarbonLib)]
136
 
                public static extern NavStatus NavDialogRun (IntPtr navDialogRef);
137
 
                
138
 
                [DllImport (Carbon.CarbonLib)]
139
 
                static extern NavStatus NavDialogGetReply (IntPtr navDialogRef, out NavReplyRecord outReply);
140
 
                
141
 
                [DllImport (Carbon.CarbonLib)]
142
 
                static extern NavUserAction NavDialogGetUserAction (IntPtr navDialogRef);
143
 
                
144
 
                [DllImport (Carbon.CarbonLib)]
145
 
                static extern void NavDialogDispose (IntPtr navDialogRef);
146
 
                
147
 
                [DllImport (Carbon.CarbonLib)]
148
 
                static extern NavStatus NavCustomControl (IntPtr dialog, NavCustomControlMessage selector, IntPtr parms);
149
 
                
150
 
                [DllImport (Carbon.CarbonLib)]
151
 
                static extern NavStatus NavCustomControl (IntPtr dialog, NavCustomControlMessage selector, ref AEDesc parm);
152
 
                
153
 
                public static void CheckReturn (NavStatus status)
154
 
                {
155
 
                        CheckReturn (status);
156
 
                }
157
 
        }
158
 
        
159
 
        struct NavEventUPP { IntPtr ptr; }
160
 
        struct NavObjectFilterUPP { IntPtr ptr; }
161
 
        struct NavPreviewUPP { IntPtr ptr; }
162
 
        
163
 
        class NavDialogCreationOptions : IDisposable
164
 
        {
165
 
                internal NavDialogCreationOptionsData data;
166
 
                
167
 
                public static NavDialogCreationOptions NewFromDefaults ()
168
 
                {
169
 
                        var options = new NavDialogCreationOptions ();
170
 
                        NavDialog.CheckReturn (NavGetDefaultDialogCreationOptions (out options.data));
171
 
                        return options;
172
 
                }
173
 
                
174
 
                [DllImport (Carbon.CarbonLib)]
175
 
                static extern NavStatus NavGetDefaultDialogCreationOptions (out NavDialogCreationOptionsData options);
176
 
                
177
 
                public NavDialogOptionFlags OptionFlags {
178
 
                        get { return data.optionFlags; }
179
 
                        set { data.optionFlags = value; }
180
 
                }
181
 
                
182
 
                public Point Location {
183
 
                        get { return data.location; }
184
 
                        set { data.location = value; }
185
 
                }
186
 
                
187
 
                public string ClientName {
188
 
                        get { return CoreFoundation.FetchString (data.clientName); }
189
 
                        set { data.clientName = AddCFString (value); }
190
 
                }
191
 
                
192
 
                public string WindowTitle {
193
 
                        get { return CoreFoundation.FetchString (data.windowTitle); }
194
 
                        set { data.windowTitle = AddCFString (value); }
195
 
                }
196
 
                
197
 
                public string ActionButtonLabel {
198
 
                        get { return CoreFoundation.FetchString (data.actionButtonLabel); }
199
 
                        set { data.actionButtonLabel = AddCFString (value); }
200
 
                }
201
 
                
202
 
                public string CancelButtonLabel {
203
 
                        get { return CoreFoundation.FetchString (data.cancelButtonLabel); }
204
 
                        set { data.cancelButtonLabel = AddCFString (value); }
205
 
                }
206
 
                
207
 
                public string SaveFileName {
208
 
                        get { return CoreFoundation.FetchString (data.saveFileName); }
209
 
                        set { data.saveFileName = AddCFString (value); }
210
 
                }
211
 
                
212
 
                public string Message {
213
 
                        get { return CoreFoundation.FetchString (data.message); }
214
 
                        set { data.message = AddCFString (value); }
215
 
                }
216
 
                
217
 
                public uint PreferenceKey {
218
 
                        get { return data.preferenceKey; }
219
 
                        set { data.preferenceKey = value; }
220
 
                }
221
 
                
222
 
                public IntPtr PopupExtension {
223
 
                        get { return data.popupExtension; }
224
 
                        set { data.popupExtension = value; }
225
 
                }
226
 
                
227
 
                public WindowModality Modality {
228
 
                        get { return data.modality; }
229
 
                        set { data.modality = value; }
230
 
                }
231
 
                
232
 
                public IntPtr ParentWindow {
233
 
                        get { return data.parentWindow; }
234
 
                        set { data.parentWindow = value; }
235
 
                }
236
 
                
237
 
                List<IntPtr> toDispose;
238
 
                IntPtr AddCFString (string value)
239
 
                {
240
 
                        var ptr = CoreFoundation.CreateString (value);
241
 
                        if (toDispose == null)
242
 
                                toDispose = new List<IntPtr> ();
243
 
                        toDispose.Add (ptr);
244
 
                        return ptr;
245
 
                }
246
 
                
247
 
                public void Dispose ()
248
 
                {
249
 
                        if (toDispose != null) {
250
 
                                foreach (IntPtr ptr in toDispose)
251
 
                                        CoreFoundation.Release (ptr);
252
 
                                toDispose = null;
253
 
                                GC.SuppressFinalize (this);
254
 
                        }
255
 
                }
256
 
                
257
 
                ~NavDialogCreationOptions ()
258
 
                {
259
 
                        Console.WriteLine ("WARNING: Did not dispose NavDialogCreationOptions");
260
 
                }
261
 
        }
262
 
        
263
 
        [StructLayout(LayoutKind.Sequential, Pack = 2, Size = 66)]
264
 
        struct NavDialogCreationOptionsData
265
 
        {
266
 
                public ushort version;
267
 
                public NavDialogOptionFlags optionFlags;
268
 
                public Point location;
269
 
                public IntPtr clientName; //CFStringRef
270
 
                public IntPtr windowTitle; //CFStringRef
271
 
                public IntPtr actionButtonLabel; // CFStringRef
272
 
                public IntPtr cancelButtonLabel; // CFStringRef
273
 
                public IntPtr saveFileName; // CFStringRef
274
 
                public IntPtr message; // CFStringRef
275
 
                public uint preferenceKey;
276
 
                public IntPtr popupExtension; //CFArrayRef
277
 
                public WindowModality modality;
278
 
                public IntPtr parentWindow; //WindowRef
279
 
                public char reserved; //char[16]
280
 
        }
281
 
        
282
 
        [Flags]
283
 
        enum NavDialogOptionFlags : uint
284
 
        {
285
 
                Default = DontAddTranslateItems & AllowStationery & AllowPreviews & AllowMultipleFiles,
286
 
                NoTypePopup = 1,
287
 
                DontAutoTranslate = 1 << 1,
288
 
                DontAddTranslateItems = 1 << 2,
289
 
                AllFilesInPopup = 1 << 4,
290
 
                AllowStationery = 1 << 5,
291
 
                AllowPreviews = 1 << 6,
292
 
                AllowMultipleFiles = 1 << 7,
293
 
                AllowInvisibleFiles = 1 << 8,
294
 
                DontResolveAliases = 1 << 9,
295
 
                SelectDefaultLocation = 1 << 10,
296
 
                SelectAllReadableItem = 1 << 11,
297
 
                SupportPackages = 1 << 12,
298
 
                AllowOpenPackages = 1 << 13,
299
 
                DontAddRecents = 1 << 14,
300
 
                DontUseCustomFrame = 1 << 15,
301
 
                DontConfirmReplacement = 1 << 16,
302
 
                PreserveSaveFileExtension = 1 << 17
303
 
        }
304
 
        
305
 
        [StructLayout(LayoutKind.Sequential, Pack = 2)]
306
 
        struct Point
307
 
        {
308
 
                short v;
309
 
                short h;
310
 
                
311
 
                public Point (short v, short h)
312
 
                {
313
 
                        this.v = v;
314
 
                        this.h = h;
315
 
                }
316
 
                
317
 
                public short V { get { return v; } }
318
 
                public short H { get { return h; } }
319
 
        }
320
 
        
321
 
        [StructLayout(LayoutKind.Sequential, Pack = 2)]
322
 
        struct Rect
323
 
        {
324
 
                short top;
325
 
                short left;
326
 
                short bottom;
327
 
                short right;
328
 
                
329
 
                public short Top { get { return top; } }
330
 
                public short Left { get { return left; } }
331
 
                public short Bottom { get { return bottom; } }
332
 
                public short Right { get { return right; } }
333
 
        }
334
 
        
335
 
        enum WindowModality : uint
336
 
        {
337
 
                None = 0,
338
 
                SystemModal = 1,
339
 
                AppModal = 2,
340
 
                WindowModal = 3,
341
 
        }
342
 
        
343
 
        enum WindowPositionMethod : uint
344
 
        {
345
 
                CenterOnMainScreen = 1,
346
 
                CenterOnParentWindow = 2,
347
 
                CenterOnParentWindowScreen = 3,
348
 
                CascadeOnMainScreen = 4,
349
 
                CascadeOnParentWindow = 5,
350
 
                CascadeOnParentWindowScreen = 6,
351
 
                CascadeStartAtParentWindowScreen = 10,
352
 
                AlertPositionOnMainScreen = 7,
353
 
                AlertPositionOnParentWindow = 8,
354
 
                AlertPositionOnParentWindowScreen = 9,
355
 
        }
356
 
        
357
 
        enum NavStatus : int
358
 
        {
359
 
                Ok = 0,
360
 
                WrongDialogStateErr = -5694,
361
 
                WrongDialogClassErr = -5695,
362
 
                InvalidSystemConfigErr = -5696,
363
 
                CustomControlMessageFailedErr = -5697,
364
 
                InvalidCustomControlMessageErr = -5698,
365
 
                MissingKindStringErr = -5699,
366
 
        }
367
 
        
368
 
        enum NavEventCallbackMessage : int
369
 
        {
370
 
                Event = 0,
371
 
                Customize = 1,
372
 
                Start = 2,
373
 
                Terminate = 3,
374
 
                AdjustRect = 4,
375
 
                NewLocation = 5,
376
 
                ShowDesktop = 6,
377
 
                SelectEntry = 7,
378
 
                PopupMenuSelect = 8,
379
 
                Accept = 9,
380
 
                Cancel = 10,
381
 
                AdjustPreview = 11,
382
 
                UserAction = 12,
383
 
                OpenSelection = -2147483648, // unchecked 0x80000000
384
 
        }
385
 
        
386
 
        [StructLayout(LayoutKind.Sequential, Pack = 2, Size=254)]
387
 
        struct NavCBRec
388
 
        {
389
 
                ushort version;
390
 
                IntPtr context; // NavDialogRef
391
 
                IntPtr window; // WindowRef
392
 
                Rect customRect;
393
 
                Rect previewRect;
394
 
                NavEventData eventData;
395
 
                NavUserAction userAction;
396
 
                char reserved; //[218];
397
 
        }
398
 
        
399
 
        [StructLayout(LayoutKind.Sequential, Pack = 2)]
400
 
        struct NavEventData
401
 
        {
402
 
                IntPtr eventDataParms; // NavEventDataInfo union, usually a pointer to either a EventRecord or an AEDescList
403
 
                short itemHit;
404
 
        }
405
 
        
406
 
        enum NavUserAction : uint
407
 
        {
408
 
                None = 0,
409
 
                Cancel = 1,
410
 
                Open = 2,
411
 
                SaveAs = 3,
412
 
                Choose = 4,
413
 
                NewFolder = 5,
414
 
                SaveChanges = 6,
415
 
                DontSaveChanges = 7,
416
 
                DiscardChanges = 8,
417
 
                ReviewDocuments = 9,
418
 
                DiscardDocuments = 10
419
 
        }
420
 
        
421
 
        enum NavFilterModes : short
422
 
        {
423
 
                BrowserList = 0,
424
 
                Favorites = 1,
425
 
                Recents = 2,
426
 
                ShortCutVolumes = 3,
427
 
                LocationPopup = 4
428
 
        }
429
 
        
430
 
        [StructLayout(LayoutKind.Sequential, Pack = 2, Size=255)]
431
 
        struct NavReplyRecord
432
 
        {
433
 
                ushort version;
434
 
                [MarshalAs(UnmanagedType.U1)]
435
 
                bool validRecord;
436
 
                [MarshalAs(UnmanagedType.U1)]
437
 
                bool replacing;
438
 
                [MarshalAs(UnmanagedType.U1)]
439
 
                bool isStationery;
440
 
                [MarshalAs(UnmanagedType.U1)]
441
 
                bool translationNeeded;
442
 
                AEDesc selection; //actually an AEDescList
443
 
                short keyScript;
444
 
                //fileTranslation is a FileTranslationSpecArrayHandle, which apparently is a pointer to a FileTranslationSpecArrayPtr,
445
 
                //which is a pointer to a FileTranslationSpec
446
 
                IntPtr fileTranslation;
447
 
                uint reserved1;
448
 
                IntPtr saveFileName; //CFStringRef
449
 
                [MarshalAs(UnmanagedType.U1)]
450
 
                bool saveFileExtensionHidden;
451
 
                byte reserved2;
452
 
                char reserved; //size [225];
453
 
        }
454
 
        
455
 
        class NavReplyRecordRef : IDisposable
456
 
        {
457
 
                bool disposed;
458
 
                internal NavReplyRecord value;
459
 
                
460
 
                public void Dispose ()
461
 
                {
462
 
                        if (!disposed) {
463
 
                                disposed = true;
464
 
                                NavDisposeReply (ref value);
465
 
                                GC.SuppressFinalize (this);
466
 
                        }
467
 
                }
468
 
                
469
 
                ~NavReplyRecordRef ()
470
 
                {
471
 
                        Console.WriteLine ("WARNING: NavReplyRecordRef not disposed");
472
 
                }
473
 
                
474
 
                [DllImport (Carbon.CarbonLib)]
475
 
                static extern NavStatus NavDisposeReply (ref NavReplyRecord record);
476
 
        }
477
 
        
478
 
        enum NavCustomControlMessage : int
479
 
        {
480
 
                ShowDesktop = 0,
481
 
                SortBy = 1,
482
 
                SortOrder = 2,
483
 
                ScrollHome = 3,
484
 
                ScrollEnd = 4,
485
 
                PageUp = 5,
486
 
                PageDown = 6,
487
 
                GetLocation = 7,
488
 
                SetLocation = 8,
489
 
                GetSelection = 9,
490
 
                SetSelection = 10,
491
 
                ShowSelection = 11,
492
 
                OpenSelection = 12,
493
 
                EjectVolume = 13,
494
 
                NewFolder = 14,
495
 
                Cancel = 15,
496
 
                Accept = 16,
497
 
                IsPreviewShowing = 17,
498
 
                AddControl = 18,
499
 
                AddControlList = 19,
500
 
                GetFirstControlID = 20,
501
 
                SelectCustomType = 21,
502
 
                SelectAllType = 22,
503
 
                GetEditFileName = 23,
504
 
                SetEditFileName = 24,
505
 
                SelectEditFileName = 25,
506
 
                BrowserSelectAll = 26,
507
 
                GotoParent = 27,
508
 
                SetActionState = 28,
509
 
                BrowserRedraw = 29,
510
 
                Terminate = 30
511
 
        }
512
 
}