~ubuntu-branches/ubuntu/trusty/monodevelop/trusty-proposed

« back to all changes in this revision

Viewing changes to src/addins/WindowsPlatform/Dialogs/OpenFileDialogEx.cs

  • Committer: Package Import Robot
  • Author(s): Jo Shields
  • Date: 2013-05-12 09:46:03 UTC
  • mto: This revision was merged to the branch mainline in revision 29.
  • Revision ID: package-import@ubuntu.com-20130512094603-mad323bzcxvmcam0
Tags: upstream-4.0.5+dfsg
ImportĀ upstreamĀ versionĀ 4.0.5+dfsg

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
//  Copyright (c) 2006, Gustavo Franco
 
2
//  Email:  gustavo_franco@hotmail.com
 
3
//  All rights reserved.
 
4
 
 
5
//  Redistribution and use in source and binary forms, with or without modification, 
 
6
//  are permitted provided that the following conditions are met:
 
7
 
 
8
//  Redistributions of source code must retain the above copyright notice, 
 
9
//  this list of conditions and the following disclaimer. 
 
10
//  Redistributions in binary form must reproduce the above copyright notice, 
 
11
//  this list of conditions and the following disclaimer in the documentation 
 
12
//  and/or other materials provided with the distribution. 
 
13
 
 
14
//  THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY
 
15
//  KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
 
16
//  IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR
 
17
//  PURPOSE. IT CAN BE DISTRIBUTED FREE OF CHARGE AS LONG AS THIS HEADER 
 
18
//  REMAINS UNCHANGED.
 
19
 
 
20
using System;
 
21
using System.IO;
 
22
using System.Text;
 
23
using System.Data;
 
24
using System.Drawing;
 
25
using System.Threading;
 
26
using System.Windows.Forms;
 
27
using System.ComponentModel;
 
28
using System.Collections.Generic;
 
29
using System.Runtime.InteropServices;
 
30
 
 
31
using CustomControls.OS;
 
32
 
 
33
namespace CustomControls.Controls
 
34
{
 
35
    [Author("Franco, Gustavo")]
 
36
    public partial class OpenFileDialogEx : UserControl
 
37
    {
 
38
        #region delegates
 
39
        public delegate void FileNameChangedHandler(OpenFileDialogEx sender, string filePath);
 
40
        #endregion
 
41
 
 
42
        #region Events
 
43
        public event FileNameChangedHandler FileNameChanged;
 
44
        public event FileNameChangedHandler FolderNameChanged;
 
45
        public event EventHandler           ClosingDialog;
 
46
        #endregion
 
47
 
 
48
        #region Constants Declaration
 
49
                internal const SetWindowPosFlags UFLAGSHIDE = 
 
50
            SetWindowPosFlags.SWP_NOACTIVATE |
 
51
                        SetWindowPosFlags.SWP_NOOWNERZORDER |
 
52
                        SetWindowPosFlags.SWP_NOMOVE |
 
53
            SetWindowPosFlags.SWP_NOSIZE | 
 
54
            SetWindowPosFlags.SWP_HIDEWINDOW;
 
55
        #endregion
 
56
 
 
57
        #region Variables Declaration
 
58
        private AddonWindowLocation mStartLocation  = AddonWindowLocation.Right;
 
59
        private FolderViewMode      mDefaultViewMode= FolderViewMode.Default;
 
60
                private FileDialog                      fileDialog;
 
61
        private DummyForm           form;
 
62
        #endregion
 
63
 
 
64
        #region Constructors
 
65
                public OpenFileDialogEx () : this (new OpenFileDialog ())
 
66
                {
 
67
                }
 
68
                
 
69
        public OpenFileDialogEx (FileDialog fileDialog)
 
70
        {
 
71
                        if (fileDialog == null)
 
72
                                throw new ArgumentNullException ("fileDialog");
 
73
                        
 
74
            InitializeComponent();
 
75
//            dlgOpen.AutoUpgradeEnabled = false; 
 
76
            //SetStyle(ControlStyles.SupportsTransparentBackColor, true);
 
77
                        
 
78
                        this.fileDialog = fileDialog;
 
79
        }
 
80
        #endregion
 
81
 
 
82
        #region Properties
 
83
        public FileDialog FileDialog
 
84
        {
 
85
            get {return fileDialog;}
 
86
        }
 
87
 
 
88
        [DefaultValue(AddonWindowLocation.Right)]
 
89
        public AddonWindowLocation StartLocation
 
90
        {
 
91
            get {return mStartLocation;}
 
92
            set {mStartLocation = value;}
 
93
        }
 
94
 
 
95
        [DefaultValue(FolderViewMode.Default)]
 
96
        public FolderViewMode DefaultViewMode
 
97
        {
 
98
            get {return mDefaultViewMode;}
 
99
            set {mDefaultViewMode = value;}
 
100
        }
 
101
 
 
102
        protected Rectangle FileNameLabelRect
 
103
        {
 
104
            get {
 
105
                if (form == null || form.NativeDialog == null)
 
106
                    return Rectangle.Empty;
 
107
 
 
108
                return form.NativeDialog.FileNameLabelRect;
 
109
            }
 
110
        }
 
111
 
 
112
        protected Rectangle FileNameComboRect
 
113
        {
 
114
            get {
 
115
                if (form == null || form.NativeDialog == null)
 
116
                    return Rectangle.Empty;
 
117
 
 
118
                return form.NativeDialog.FileNameComboRect;
 
119
            }
 
120
        }
 
121
        #endregion
 
122
 
 
123
        #region Virtuals
 
124
        public virtual void OnFileNameChanged(string fileName)
 
125
        {
 
126
            if (FileNameChanged != null)
 
127
                FileNameChanged(this, fileName);
 
128
        }
 
129
 
 
130
        public virtual void OnFolderNameChanged(string folderName)
 
131
        {
 
132
            if (FolderNameChanged != null)
 
133
                FolderNameChanged(this, folderName);
 
134
        }
 
135
 
 
136
        public virtual void OnClosingDialog()
 
137
        {
 
138
            if (ClosingDialog != null)
 
139
                ClosingDialog(this, new EventArgs());
 
140
        }
 
141
 
 
142
        protected virtual void OnShow(EventArgs args)
 
143
        {
 
144
        }
 
145
        #endregion
 
146
 
 
147
        #region Methods
 
148
        public DialogResult ShowDialog()
 
149
        {
 
150
            return ShowDialog(null);
 
151
        }
 
152
 
 
153
        public DialogResult ShowDialog(IWin32Window owner)
 
154
        {
 
155
            form = new DummyForm(this);
 
156
            if (owner is Form)
 
157
                form.Icon = ((Form)owner).Icon; // Inherit the app/window icon
 
158
 
 
159
            form.Show(owner);
 
160
            Win32.SetWindowPos(form.Handle, IntPtr.Zero, 0, 0, 0, 0, UFLAGSHIDE);
 
161
            form.WatchForActivate = true;
 
162
            try
 
163
            {
 
164
                return fileDialog.ShowDialog(form);
 
165
            }
 
166
            catch (Exception ex)
 
167
            {
 
168
                MessageBox.Show(ex.Message);
 
169
                return DialogResult.Cancel;
 
170
            }
 
171
            finally
 
172
            {
 
173
                //form.Dispose();
 
174
                //form.Close();
 
175
            }
 
176
        }
 
177
        #endregion
 
178
 
 
179
        #region Helper Classes
 
180
        [Author("Franco, Gustavo")]
 
181
        private class OpenDialogNative : NativeWindow, IDisposable
 
182
        {
 
183
            #region Constants Declaration
 
184
                    private SetWindowPosFlags UFLAGSSIZE = 
 
185
                SetWindowPosFlags.SWP_NOACTIVATE |
 
186
                            SetWindowPosFlags.SWP_NOOWNERZORDER |
 
187
                            SetWindowPosFlags.SWP_NOMOVE;
 
188
                    private SetWindowPosFlags UFLAGSHIDE = 
 
189
                SetWindowPosFlags.SWP_NOACTIVATE |
 
190
                            SetWindowPosFlags.SWP_NOOWNERZORDER |
 
191
                            SetWindowPosFlags.SWP_NOMOVE |
 
192
                SetWindowPosFlags.SWP_NOSIZE | 
 
193
                SetWindowPosFlags.SWP_HIDEWINDOW;
 
194
                    private SetWindowPosFlags UFLAGSZORDER = 
 
195
                SetWindowPosFlags.SWP_NOACTIVATE |
 
196
                            SetWindowPosFlags.SWP_NOMOVE |
 
197
                SetWindowPosFlags.SWP_NOSIZE; 
 
198
            #endregion
 
199
 
 
200
            #region Variables Declaration
 
201
            private Size                mOriginalSize;
 
202
            private IntPtr              mOpenDialogHandle;
 
203
            private IntPtr              mListViewPtr;
 
204
            private WINDOWINFO          mListViewInfo;
 
205
            private BaseDialogNative    mBaseDialogNative;
 
206
            private IntPtr              mComboFolders;
 
207
            private WINDOWINFO          mComboFoldersInfo;
 
208
            private IntPtr              mGroupButtons;
 
209
            private WINDOWINFO          mGroupButtonsInfo;
 
210
            private IntPtr              mComboFileName;
 
211
            private WINDOWINFO          mComboFileNameInfo;
 
212
            private IntPtr              mComboExtensions;
 
213
            private WINDOWINFO          mComboExtensionsInfo;
 
214
            private IntPtr              mOpenButton;
 
215
            private WINDOWINFO          mOpenButtonInfo;
 
216
            private IntPtr              mCancelButton;
 
217
            private WINDOWINFO          mCancelButtonInfo;
 
218
            private IntPtr              mHelpButton;
 
219
            private WINDOWINFO          mHelpButtonInfo;
 
220
            private OpenFileDialogEx    mSourceControl;
 
221
            private IntPtr              mToolBarFolders;
 
222
            private WINDOWINFO          mToolBarFoldersInfo;
 
223
            private IntPtr              mLabelFileName;
 
224
            private WINDOWINFO          mLabelFileNameInfo;
 
225
            private IntPtr              mLabelFileType;
 
226
            private WINDOWINFO          mLabelFileTypeInfo;
 
227
            private IntPtr              mChkReadOnly;
 
228
            private WINDOWINFO          mChkReadOnlyInfo;
 
229
            private bool                mIsClosing          = false;
 
230
            private bool                mInitializated      = false;
 
231
            private WINDOWINFO          mOpenDialogWindowInfo;
 
232
            private RECT                mOpenDialogWindowRect = new RECT();
 
233
            private RECT                mOpenDialogClientRect = new RECT();
 
234
            #endregion
 
235
 
 
236
            #region Constructors
 
237
            public OpenDialogNative(IntPtr handle, OpenFileDialogEx sourceControl)
 
238
            {
 
239
                mOpenDialogHandle   = handle;
 
240
                mSourceControl      = sourceControl;
 
241
                AssignHandle(mOpenDialogHandle);
 
242
            }
 
243
            #endregion
 
244
 
 
245
            #region Events
 
246
            private void BaseDialogNative_FileNameChanged(BaseDialogNative sender, string filePath)
 
247
            {
 
248
                if (mSourceControl != null)
 
249
                    mSourceControl.OnFileNameChanged(filePath);
 
250
            }
 
251
 
 
252
            private void BaseDialogNative_FolderNameChanged(BaseDialogNative sender, string folderName)
 
253
            {
 
254
                if (mSourceControl != null)
 
255
                    mSourceControl.OnFolderNameChanged(folderName);
 
256
            }
 
257
            #endregion
 
258
 
 
259
            #region Properties
 
260
            public bool IsClosing
 
261
            {
 
262
                get {return mIsClosing;}
 
263
                set {mIsClosing = value;}
 
264
            }
 
265
 
 
266
            public Rectangle FileNameLabelRect
 
267
            {
 
268
                get {
 
269
                    return RectToDialogClient(mLabelFileNameInfo.rcWindow);
 
270
                }
 
271
            }
 
272
 
 
273
            public Rectangle FileNameComboRect
 
274
            {
 
275
                get {
 
276
                    return RectToDialogClient(mComboFileNameInfo.rcWindow);
 
277
                }
 
278
            }
 
279
            #endregion
 
280
 
 
281
            #region Methods
 
282
            public void Dispose()
 
283
            {
 
284
                ReleaseHandle();
 
285
                if (mBaseDialogNative != null)
 
286
                {
 
287
                    mBaseDialogNative.FileNameChanged -= new BaseDialogNative.FileNameChangedHandler(BaseDialogNative_FileNameChanged);
 
288
                    mBaseDialogNative.FolderNameChanged -= new BaseDialogNative.FileNameChangedHandler(BaseDialogNative_FolderNameChanged);
 
289
                    mBaseDialogNative.Dispose();
 
290
                }
 
291
            }
 
292
            #endregion
 
293
 
 
294
            #region Private Methods
 
295
            private Rectangle RectToDialogClient(RECT rect)
 
296
            {
 
297
                uint locX = mOpenDialogWindowRect.left + mOpenDialogWindowInfo.cxWindowBorders;
 
298
                uint locY = mOpenDialogWindowRect.top + mOpenDialogWindowInfo.cyWindowBorders;
 
299
 
 
300
                rect.left -= locX;
 
301
                rect.right -= locX;
 
302
                rect.bottom -= locY;
 
303
                rect.top -= locY;
 
304
 
 
305
                return new Rectangle ((int)rect.left, (int)rect.top,
 
306
                    (int)(rect.right - rect.left), (int)(rect.bottom - rect.top));
 
307
            }
 
308
 
 
309
            private void PopulateWindowsHandlers()
 
310
            {
 
311
                Win32.EnumChildWindows(mOpenDialogHandle, new Win32.EnumWindowsCallBack(OpenFileDialogEnumWindowCallBack), 0);
 
312
            }
 
313
 
 
314
            private bool OpenFileDialogEnumWindowCallBack(IntPtr hwnd, int lParam) 
 
315
            {
 
316
                StringBuilder className = new StringBuilder(256);
 
317
                Win32.GetClassName(hwnd, className, className.Capacity);
 
318
                int controlID = Win32.GetDlgCtrlID(hwnd);
 
319
                WINDOWINFO windowInfo;
 
320
                Win32.GetWindowInfo(hwnd, out windowInfo);
 
321
 
 
322
                // Dialog Window
 
323
                if (className.ToString().StartsWith("#32770"))
 
324
                {
 
325
                    mBaseDialogNative = new BaseDialogNative(hwnd);
 
326
                    mBaseDialogNative.FileNameChanged   += new BaseDialogNative.FileNameChangedHandler(BaseDialogNative_FileNameChanged);
 
327
                    mBaseDialogNative.FolderNameChanged += new BaseDialogNative.FileNameChangedHandler(BaseDialogNative_FolderNameChanged);
 
328
                    return true;
 
329
                }
 
330
 
 
331
                switch((ControlsID) controlID)
 
332
                {
 
333
                    case ControlsID.DefaultView:
 
334
                        mListViewPtr = hwnd;
 
335
                        Win32.GetWindowInfo(hwnd, out mListViewInfo);
 
336
                        if (mSourceControl.DefaultViewMode != FolderViewMode.Default)
 
337
                            Win32.SendMessage(mListViewPtr, (int) Msg.WM_COMMAND, (int) mSourceControl.DefaultViewMode, 0);
 
338
                        break;
 
339
                    case ControlsID.ComboFolder:
 
340
                        mComboFolders       = hwnd;
 
341
                        mComboFoldersInfo   = windowInfo;
 
342
                        break;
 
343
                    case ControlsID.ComboFileType:
 
344
                        mComboExtensions       = hwnd;
 
345
                        mComboExtensionsInfo   = windowInfo;
 
346
                        break;
 
347
                    case ControlsID.ComboFileName:
 
348
                        if (className.ToString().ToLower() == "comboboxex32")
 
349
                        {
 
350
                            mComboFileName          = hwnd;
 
351
                            mComboFileNameInfo      = windowInfo;
 
352
                        }
 
353
                        break;
 
354
                    case ControlsID.GroupFolder:
 
355
                        mGroupButtons       = hwnd;
 
356
                        mGroupButtonsInfo   = windowInfo;
 
357
                        break;
 
358
                    case ControlsID.LeftToolBar:
 
359
                        mToolBarFolders     = hwnd;
 
360
                        mToolBarFoldersInfo = windowInfo;
 
361
                        break;
 
362
                    case ControlsID.ButtonOpen:
 
363
                        mOpenButton         = hwnd;
 
364
                        mOpenButtonInfo     = windowInfo;
 
365
                        break;
 
366
                    case ControlsID.ButtonCancel:
 
367
                        mCancelButton       = hwnd;
 
368
                        mCancelButtonInfo   = windowInfo;
 
369
                        break;
 
370
                    case ControlsID.ButtonHelp:
 
371
                        mHelpButton         = hwnd;
 
372
                        mHelpButtonInfo     = windowInfo;
 
373
                        break;
 
374
                    case ControlsID.CheckBoxReadOnly:
 
375
                        mChkReadOnly        = hwnd;
 
376
                        mChkReadOnlyInfo    = windowInfo;
 
377
                        break;
 
378
                    case ControlsID.LabelFileName:
 
379
                        mLabelFileName      = hwnd;
 
380
                        mLabelFileNameInfo  = windowInfo;
 
381
                        break;
 
382
                    case ControlsID.LabelFileType:
 
383
                        mLabelFileType      = hwnd;
 
384
                        mLabelFileTypeInfo  = windowInfo;
 
385
                        break;
 
386
                }
 
387
 
 
388
                return true;
 
389
            }
 
390
 
 
391
            private void InitControls()
 
392
            {
 
393
                mInitializated = true;
 
394
 
 
395
                // Lets get information about the current open dialog
 
396
                Win32.GetClientRect(mOpenDialogHandle, ref mOpenDialogClientRect);
 
397
                Win32.GetWindowInfo(mOpenDialogHandle, out mOpenDialogWindowInfo);
 
398
                mOpenDialogWindowRect = mOpenDialogWindowInfo.rcWindow;
 
399
 
 
400
                // Lets borrow the Handles from the open dialog control
 
401
                PopulateWindowsHandlers();
 
402
 
 
403
                // Resize OpenDialog to make fit our extra form
 
404
                switch(mSourceControl.StartLocation)
 
405
                {
 
406
                    case AddonWindowLocation.Right:
 
407
                        // Now we transfer the control to the open dialog
 
408
                        mSourceControl.Location = new Point((int) (mOpenDialogClientRect.Width - mSourceControl.Width), 0);
 
409
 
 
410
                        // Everything is ready, now lets change the parent
 
411
                        Win32.SetParent(mSourceControl.Handle, mOpenDialogHandle);
 
412
 
 
413
                        // Send the control to the back
 
414
                        Win32.SetWindowPos(mSourceControl.Handle, (IntPtr) ZOrderPos.HWND_BOTTOM, 0, 0, 0, 0, UFLAGSZORDER);
 
415
                        break;
 
416
                    case AddonWindowLocation.Bottom:
 
417
                        // Now we transfer the control to the open dialog
 
418
                        mSourceControl.Location = new Point(0, (int) (mOpenDialogClientRect.Height - mSourceControl.Height));
 
419
 
 
420
                        // Everything is ready, now lets change the parent
 
421
                        Win32.SetParent(mSourceControl.Handle, mOpenDialogHandle);
 
422
 
 
423
                        // Send the control to the back
 
424
                        Win32.SetWindowPos(mSourceControl.Handle, (IntPtr) ZOrderPos.HWND_BOTTOM, 0, 0, 0, 0, UFLAGSZORDER);
 
425
                        break;
 
426
                    case AddonWindowLocation.None:
 
427
                        // We don't have to do too much in this case, but set parent must be the first call
 
428
                        // because else ZOrder won't worl
 
429
                        Win32.SetParent(mSourceControl.Handle, mOpenDialogHandle);
 
430
 
 
431
                        // Send the control to the back
 
432
                        Win32.SetWindowPos(mSourceControl.Handle, (IntPtr) ZOrderPos.HWND_BOTTOM, 0, 0, 0, 0, UFLAGSZORDER);
 
433
                        break;
 
434
                }
 
435
            }
 
436
            #endregion
 
437
 
 
438
            #region Overrides
 
439
            protected override void WndProc(ref Message m)
 
440
            {
 
441
                switch(m.Msg)
 
442
                {
 
443
                    case (int) Msg.WM_SHOWWINDOW:
 
444
                        mInitializated = true;
 
445
                        InitControls();
 
446
 
 
447
                        mSourceControl.OnShow(EventArgs.Empty);
 
448
                        break;
 
449
                    case (int) Msg.WM_WINDOWPOSCHANGING:
 
450
                        if (!mIsClosing)
 
451
                        {
 
452
                            if (!mInitializated)
 
453
                            {
 
454
                                WINDOWPOS pos = (WINDOWPOS) Marshal.PtrToStructure(m.LParam, typeof(WINDOWPOS));
 
455
                                if (mSourceControl.StartLocation == AddonWindowLocation.Right)
 
456
                                {
 
457
                                    if (pos.flags != 0 && ((pos.flags & (int) SWP_Flags.SWP_NOSIZE) != (int) SWP_Flags.SWP_NOSIZE))
 
458
                                    {
 
459
                                        mOriginalSize = new Size(pos.cx, pos.cy);
 
460
 
 
461
                                        pos.cx += mSourceControl.Width;
 
462
                                        Marshal.StructureToPtr(pos, m.LParam, true);
 
463
                                    }
 
464
                                }
 
465
 
 
466
                                if (mSourceControl.StartLocation == AddonWindowLocation.Bottom)
 
467
                                {
 
468
                                    if (pos.flags != 0 && ((pos.flags & (int) SWP_Flags.SWP_NOSIZE) != (int) SWP_Flags.SWP_NOSIZE))
 
469
                                    {
 
470
                                        mOriginalSize = new Size(pos.cx, pos.cy);
 
471
 
 
472
                                        pos.cy += mSourceControl.Height;
 
473
                                        Marshal.StructureToPtr(pos, m.LParam, true);
 
474
                                    }
 
475
                                }
 
476
                            }
 
477
 
 
478
                            RECT currentSize = new RECT();
 
479
                            Win32.GetClientRect(mOpenDialogHandle, ref currentSize);
 
480
 
 
481
                            switch(mSourceControl.StartLocation)
 
482
                            {
 
483
                                case AddonWindowLocation.Right: {
 
484
                                    var loc = new Point((int)(currentSize.Width - mSourceControl.Width), 0);
 
485
                                    if (mSourceControl.Location != loc)
 
486
                                        mSourceControl.Location = loc;
 
487
                                    if (mSourceControl.Height != (int) currentSize.Height)
 
488
                                        mSourceControl.Height = (int) currentSize.Height;
 
489
                                    break;
 
490
                                }
 
491
                                case AddonWindowLocation.Bottom: {
 
492
                                    var loc = new Point(0, (int)(currentSize.Height - mSourceControl.Height));
 
493
                                    if (mSourceControl.Location != loc)
 
494
                                        mSourceControl.Location = loc;
 
495
                                    if (mSourceControl.Width != (int) currentSize.Width)
 
496
                                        mSourceControl.Width = (int) currentSize.Width;
 
497
                                    break;
 
498
                                }
 
499
                                case AddonWindowLocation.None: {
 
500
                                    if (mSourceControl.Width != (int) currentSize.Width)
 
501
                                        mSourceControl.Width = (int) currentSize.Width;
 
502
                                    if (mSourceControl.Height != (int) currentSize.Height)
 
503
                                        mSourceControl.Height = (int) currentSize.Height;
 
504
                                    break;
 
505
                                }
 
506
                            }
 
507
                        }
 
508
                        break;
 
509
                    case (int) Msg.WM_IME_NOTIFY:
 
510
                        if (m.WParam == (IntPtr) ImeNotify.IMN_CLOSESTATUSWINDOW)
 
511
                        {
 
512
                            mIsClosing = true;
 
513
                            mSourceControl.OnClosingDialog();
 
514
 
 
515
                            Win32.SetWindowPos(mOpenDialogHandle, IntPtr.Zero, 0, 0, 0, 0, UFLAGSHIDE);
 
516
                            Win32.GetWindowRect(mOpenDialogHandle, ref mOpenDialogWindowRect);
 
517
                            Win32.SetWindowPos(mOpenDialogHandle, IntPtr.Zero, 
 
518
                                (int) (mOpenDialogWindowRect.left), 
 
519
                                (int) (mOpenDialogWindowRect.top), 
 
520
                                (int) (mOriginalSize.Width), 
 
521
                                (int) (mOriginalSize.Height), 
 
522
                                UFLAGSSIZE);
 
523
                        }
 
524
                        break;
 
525
                }
 
526
                base.WndProc(ref m);
 
527
            }
 
528
            #endregion
 
529
        }
 
530
 
 
531
        [Author("Franco, Gustavo")]
 
532
        private class BaseDialogNative : NativeWindow, IDisposable
 
533
        {
 
534
            #region delegates
 
535
            public delegate void FileNameChangedHandler(BaseDialogNative sender, string filePath);
 
536
            #endregion
 
537
 
 
538
            #region Events
 
539
            public event FileNameChangedHandler FileNameChanged;
 
540
            public event FileNameChangedHandler FolderNameChanged;
 
541
            #endregion
 
542
 
 
543
            #region Variables Declaration
 
544
            private IntPtr mhandle;
 
545
            #endregion
 
546
 
 
547
            #region Constructors
 
548
            public BaseDialogNative(IntPtr handle)
 
549
            {
 
550
                mhandle = handle;
 
551
                AssignHandle(handle);
 
552
            }
 
553
            #endregion
 
554
 
 
555
            #region Methods
 
556
            public void Dispose()
 
557
            {
 
558
                ReleaseHandle();
 
559
            }
 
560
            #endregion
 
561
 
 
562
            #region Overrides
 
563
            protected override void WndProc(ref Message m)
 
564
            {
 
565
                switch (m.Msg)
 
566
                {
 
567
                    case (int) Msg.WM_NOTIFY:
 
568
                        OFNOTIFY ofNotify = (OFNOTIFY) Marshal.PtrToStructure(m.LParam, typeof(OFNOTIFY));
 
569
                        if (ofNotify.hdr.code == (uint) DialogChangeStatus.CDN_SELCHANGE)
 
570
                        {
 
571
                            StringBuilder filePath = new StringBuilder(256);
 
572
                            Win32.SendMessage(Win32.GetParent(mhandle), (int) DialogChangeProperties.CDM_GETFILEPATH, (int) 256, filePath);
 
573
                            if (FileNameChanged != null)
 
574
                                FileNameChanged(this, filePath.ToString());
 
575
                        }
 
576
                        else if (ofNotify.hdr.code == (uint) DialogChangeStatus.CDN_FOLDERCHANGE)
 
577
                        {
 
578
                            StringBuilder folderPath = new StringBuilder(256);
 
579
                            Win32.SendMessage(Win32.GetParent(mhandle), (int) DialogChangeProperties.CDM_GETFOLDERPATH, (int) 256, folderPath);
 
580
                            if (FolderNameChanged != null)
 
581
                                FolderNameChanged(this, folderPath.ToString());
 
582
                        }
 
583
                        break;
 
584
                }
 
585
                base.WndProc(ref m);
 
586
            }
 
587
            #endregion
 
588
        }
 
589
 
 
590
        [Author("Franco, Gustavo")]
 
591
        private class DummyForm : Form
 
592
        {
 
593
            #region Variables Declaration
 
594
            private OpenDialogNative    mNativeDialog       = null;
 
595
            private OpenFileDialogEx    mFileDialogEx       = null;
 
596
            private bool                mWatchForActivate   = false;
 
597
            private IntPtr              mOpenDialogHandle   = IntPtr.Zero;
 
598
            #endregion
 
599
 
 
600
            #region Constructors
 
601
            public DummyForm(OpenFileDialogEx fileDialogEx)
 
602
            {
 
603
                mFileDialogEx = fileDialogEx;
 
604
                this.Text           = "";
 
605
                this.StartPosition  = FormStartPosition.Manual;
 
606
                this.Location       = new Point(-32000, -32000);
 
607
                this.ShowInTaskbar  = false;
 
608
            }
 
609
            #endregion
 
610
 
 
611
            #region Properties
 
612
            public bool WatchForActivate
 
613
            {
 
614
                get {return mWatchForActivate;}
 
615
                set {mWatchForActivate = value;}
 
616
            }
 
617
 
 
618
            public OpenDialogNative NativeDialog
 
619
            {
 
620
                get {return mNativeDialog;}
 
621
            }
 
622
            #endregion
 
623
 
 
624
            #region Overrides
 
625
            protected override void OnClosing(CancelEventArgs e)
 
626
            {
 
627
                if (mNativeDialog != null)
 
628
                    mNativeDialog.Dispose();
 
629
                base.OnClosing(e);
 
630
            }
 
631
 
 
632
            protected override void WndProc(ref Message m)
 
633
            {
 
634
                if (mWatchForActivate && m.Msg == (int) Msg.WM_ACTIVATE)
 
635
                {
 
636
                    mWatchForActivate   = false;
 
637
                    mOpenDialogHandle   = m.LParam;
 
638
                    mNativeDialog       = new OpenDialogNative(m.LParam, mFileDialogEx);
 
639
                }
 
640
                base.WndProc(ref m);
 
641
            }
 
642
            #endregion
 
643
        }
 
644
        #endregion
 
645
    }
 
646
 
 
647
    #region Enums
 
648
    public enum AddonWindowLocation
 
649
    {
 
650
        None    = 0,
 
651
        Right   = 1,
 
652
        Bottom  = 2
 
653
    }
 
654
 
 
655
    public enum ControlsID
 
656
    {
 
657
        ButtonOpen          = 0x1,
 
658
        ButtonCancel    = 0x2,
 
659
        ButtonHelp          = 0x40E,
 
660
        GroupFolder     = 0x440,
 
661
        LabelFileType   = 0x441,
 
662
        LabelFileName   = 0x442,
 
663
        LabelLookIn     = 0x443,
 
664
        DefaultView     = 0x461,
 
665
        LeftToolBar     = 0x4A0,
 
666
        ComboFileName   = 0x47c,
 
667
        ComboFileType   = 0x470,
 
668
        ComboFolder     = 0x471,
 
669
        CheckBoxReadOnly= 0x410
 
670
    }
 
671
    #endregion
 
672
}
 
673
 
 
674
[AttributeUsage(AttributeTargets.Class |
 
675
                AttributeTargets.Enum |
 
676
                AttributeTargets.Interface |
 
677
                AttributeTargets.Struct,
 
678
                AllowMultiple = true)]
 
679
[Author("Franco, Gustavo")]
 
680
internal class AuthorAttribute : Attribute
 
681
{
 
682
    #region Constructors
 
683
    public AuthorAttribute(string authorName)
 
684
    {
 
685
    }
 
686
    #endregion
 
687
}