ClassicFileDialog.cs :  » GUI » Paint.net » PaintDotNet » SystemLayer » C# / CSharp Open Source

Home
C# / CSharp Open Source
1.2.6.4 mono .net core
2.2.6.4 mono core
3.Aspect Oriented Frameworks
4.Bloggers
5.Build Systems
6.Business Application
7.Charting Reporting Tools
8.Chat Servers
9.Code Coverage Tools
10.Content Management Systems CMS
11.CRM ERP
12.Database
13.Development
14.Email
15.Forum
16.Game
17.GIS
18.GUI
19.IDEs
20.Installers Generators
21.Inversion of Control Dependency Injection
22.Issue Tracking
23.Logging Tools
24.Message
25.Mobile
26.Network Clients
27.Network Servers
28.Office
29.PDF
30.Persistence Frameworks
31.Portals
32.Profilers
33.Project Management
34.RSS RDF
35.Rule Engines
36.Script
37.Search Engines
38.Sound Audio
39.Source Control
40.SQL Clients
41.Template Engines
42.Testing
43.UML
44.Web Frameworks
45.Web Service
46.Web Testing
47.Wiki Engines
48.Windows Presentation Foundation
49.Workflows
50.XML Parsers
C# / C Sharp
C# / C Sharp by API
C# / CSharp Tutorial
C# / CSharp Open Source » GUI » Paint.net 
Paint.net » PaintDotNet » SystemLayer » ClassicFileDialog.cs
/////////////////////////////////////////////////////////////////////////////////
// Paint.NET                                                                   //
// Copyright (C) dotPDN LLC, Rick Brewster, Tom Jackson, and contributors.     //
// Portions Copyright (C) Microsoft Corporation. All Rights Reserved.          //
// See src/Resources/Files/License.txt for full licensing and attribution      //
// details.                                                                    //
// .                                                                           //
/////////////////////////////////////////////////////////////////////////////////

using PaintDotNet;
using System;
using System.Reflection;
using System.Windows.Forms;

namespace PaintDotNet.SystemLayer{
    internal abstract class ClassicFileDialog
        : IFileDialog
    {
        private FileDialog fileDialog;

        protected FileDialog FileDialog
        {
            get
            {
                return this.fileDialog;
            }
        }

        public bool CheckPathExists
        {
            get
            {
                return this.fileDialog.CheckPathExists;
            }

            set
            {
                this.fileDialog.CheckPathExists = value;
            }
        }

        public bool DereferenceLinks
        {
            get
            {
                return this.fileDialog.DereferenceLinks;
            }
            set
            {
                this.fileDialog.DereferenceLinks = value;
            }
        }

        public string Filter
        {
            get
            {
                return this.fileDialog.Filter;
            }

            set
            {
                this.fileDialog.Filter = value;
            }
        }

        public int FilterIndex
        {
            get
            {
                return this.fileDialog.FilterIndex;
            }

            set
            {
                this.fileDialog.FilterIndex = value;
            }
        }

        public string InitialDirectory
        {
            get
            {
                return this.fileDialog.InitialDirectory;
            }

            set
            {
                this.fileDialog.InitialDirectory = value;
            }
        }

        public string Title
        {
            set
            {
                this.fileDialog.Title = value;
            }
        }

        // This is a major hack to get the .NET's OFD to show with Thumbnail view by default!
        // Luckily for us this is a covert hack, and not one where we're working around a bug
        // in the framework or OS.
        // This hack works by retrieving a private property of the OFD class after it has shown
        // the dialog box.
        // Based off code found here: http://vbnet.mvps.org/index.html?code/hooks/fileopensavedlghooklvview.htm
        private static void EnableThumbnailView(FileDialog ofd)
        {
            // HACK: Must verify this still works with each new revision of .NET
            try
            {
                Type ofdType = typeof(FileDialog);
                FieldInfo fi = ofdType.GetField("dialogHWnd", BindingFlags.Instance | BindingFlags.NonPublic);

                if (fi != null)
                {
                    object dialogHWndObject = fi.GetValue(ofd);
                    IntPtr dialogHWnd = (IntPtr)dialogHWndObject;
                    IntPtr hwndLV = SafeNativeMethods.FindWindowExW(dialogHWnd, IntPtr.Zero, "SHELLDLL_DefView", null);

                    if (hwndLV != IntPtr.Zero)
                    {
                        SafeNativeMethods.SendMessageW(hwndLV, NativeConstants.WM_COMMAND, new IntPtr(NativeConstants.SHVIEW_THUMBNAIL), IntPtr.Zero);
                    }
                }
            }

            catch (Exception)
            {
                // Ignore.
            }
        }

        public DialogResult ShowDialog(IWin32Window owner, IFileDialogUICallbacks uiCallbacks)
        {
            Control ownerAsControl = owner as Control;

            if (uiCallbacks == null)
            {
                throw new ArgumentNullException("uiCallbacks");
            }

            Cursor.Current = Cursors.WaitCursor;

            if ((Control.ModifierKeys & Keys.Shift) != 0)
            {
                UI.InvokeThroughModalTrampoline(
                    owner,
                    delegate(IWin32Window modalOwner)
                    {
                        while ((Control.ModifierKeys & Keys.Shift) != 0)
                        {
                            System.Threading.Thread.Sleep(1);
                            Application.DoEvents();
                        }
                    });
            }

            Cursor.Current = Cursors.Default;

            DialogResult result = DialogResult.Cancel;

            UI.InvokeThroughModalTrampoline(
                owner,
                delegate(IWin32Window modalOwner)
                {
                    if (ownerAsControl != null && ownerAsControl.IsHandleCreated)
                    {
                        ownerAsControl.BeginInvoke(new Procedure<FileDialog>(EnableThumbnailView), new object[] { this.fileDialog });
                    }

                    result = this.fileDialog.ShowDialog(modalOwner);
                });

            return result;
        }

        protected ClassicFileDialog(FileDialog fileDialog)
        {
            this.fileDialog = fileDialog;
            this.fileDialog.RestoreDirectory = true;
            this.fileDialog.ShowHelp = false;
            this.fileDialog.ValidateNames = true;
        }

        ~ClassicFileDialog()
        {
            Dispose(false);
        }

        public void Dispose()
        {
            Dispose(true);
            GC.SuppressFinalize(this);
        }

        protected virtual void Dispose(bool disposing)
        {
            if (disposing)
            {
                if (this.fileDialog != null)
                {
                    this.fileDialog.Dispose();
                    this.fileDialog = null;
                }
            }
        }
    }
}
www.java2v.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.