2362N/A * Copyright (c) 2003, 2009, Oracle and/or its affiliates. All rights reserved. 0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 0N/A * This code is free software; you can redistribute it and/or modify it 0N/A * under the terms of the GNU General Public License version 2 only, as 2362N/A * published by the Free Software Foundation. Oracle designates this 0N/A * particular file as subject to the "Classpath" exception as provided 2362N/A * by Oracle in the LICENSE file that accompanied this code. 0N/A * This code is distributed in the hope that it will be useful, but WITHOUT 0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 0N/A * version 2 for more details (a copy is included in the LICENSE file that 0N/A * accompanied this code). 0N/A * You should have received a copy of the GNU General Public License version 0N/A * 2 along with this work; if not, write to the Free Software Foundation, 0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 2362N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 2362N/A * or visit www.oracle.com if you need additional information or have any 0N/A// NOTE: This class supersedes Win32ShellFolder, which was removed from 0N/A// distribution after version 1.4.2. 0N/A * Win32 Shell Folders 0N/A * There are two fundamental types of shell folders : file system folders 0N/A * and non-file system folders. File system folders are relatively easy 0N/A * to deal with. Non-file system folders are items such as My Computer, 0N/A * Network Neighborhood, and the desktop. Some of these non-file system 0N/A * folders have special values and properties. 0N/A * Win32 keeps two basic data structures for shell folders. The first 0N/A * of these is called an ITEMIDLIST. Usually a pointer, called an 0N/A * LPITEMIDLIST, or more frequently just "PIDL". This structure holds 0N/A * a series of identifiers and can be either relative to the desktop 0N/A * (an absolute PIDL), or relative to the shell folder that contains them. 0N/A * Some Win32 functions can take absolute or relative PIDL values, and 0N/A * others can only accept relative values. 0N/A * The second data structure is an IShellFolder COM interface. Using 0N/A * this interface, one can enumerate the relative PIDLs in a shell 0N/A * folder, get attributes, etc. 0N/A * All Win32ShellFolder2 objects which are folder types (even non-file 0N/A * system folders) contain an IShellFolder object. Files are named in 0N/A * directories via relative PIDLs. 0N/A * @author Michael Martak 0N/A * @author Leif Samuelsson 0N/A * @author Kenneth Russell 0N/A // Win32 Shell Folder Constants 0N/A // Win32 shell folder attributes 0N/A // IShellFolder::GetDisplayNameOf constants 0N/A // Values for system call LoadIcon() 0N/A * This is cached as a concession to getFolderType(), which needs 0N/A * We keep track of shell folders through the IShellFolder 0N/A * interface of their parents plus their relative PIDL. 0N/A * The following are for caching various shell folder properties. 0N/A * The following is to identify the My Documents folder as being special 0N/A * Create a system special shell folder, such as the 0N/A * desktop or Network Neighborhood. 0N/A // Desktop is parent of DRIVES and NETWORK, not necessarily 0N/A // other special shell folders. 1083N/A // At this point, the native method initSpecial() has set our relativePIDL 1083N/A // relative to the Desktop, which may not be our immediate parent. We need 1083N/A // to traverse this ID list and break it into a chain of shell folders from 1083N/A // the top, with each one having an immediate parent and a relativePIDL 1083N/A // relative to that parent. 1083N/A // Get a child pidl relative to 'parent' 1083N/A // Get a handle to the the rest of the ID list 1083N/A // i,e, parent's grandchilren and down 1083N/A // Now we know that parent isn't immediate to 'this' because it 1083N/A // has a continued ID list. Create a shell folder for this child 1083N/A // pidl and make it the new 'parent'. 1083N/A // No grandchildren means we have arrived at the parent of 'this', 1083N/A // and childPIDL is directly relative to parent. 0N/A * Create a system shell folder 0N/A * Creates a shell folder with a parent and relative PIDL 0N/A // Initializes the desktop shell folder 1083N/A // NOTE: this method uses COM and must be called on the 'COM thread'. See ComInvoker for the details 0N/A // Initializes a special, non-file system shell folder 0N/A // from one of the above constants 1083N/A // NOTE: this method uses COM and must be called on the 'COM thread'. See ComInvoker for the details 0N/A /** Marks this folder as being the My Documents (Personal) folder */ 0N/A * This method is implemented to make sure that no instances 0N/A * of <code>ShellFolder</code> are ever serialized. If <code>isFileSystem()</code> returns 0N/A * <code>true</code>, then the object is representable with an instance of 0N/A * <code>java.io.File</code> instead. If not, then the object depends 0N/A * on native PIDL state and should not be serialized. 344N/A * @return a <code>java.io.File</code> replacement object. If the folder 0N/A * is a not a normal directory, then returns the first non-removable 0N/A * drive (normally "C:\"). 1083N/A // Ouch, we have no hard drives. Return something "valid" anyway. 0N/A * Finalizer to clean up any COM objects or PIDLs used by this object. 0N/A // Given a (possibly multi-level) relative PIDL (with respect to 0N/A // the desktop, at least in all of the usage cases in this code), 0N/A // return a pointer to the next entry. Does not mutate the PIDL in 0N/A // any way. Returns 0 if the null terminator is reached. 0N/A // Needs to be accessible to Win32ShellFolderManager2 0N/A // Given a (possibly multi-level) relative PIDL (with respect to 0N/A // the desktop, at least in all of the usage cases in this code), 0N/A // copy the first entry into a newly-allocated PIDL. Returns 0 if 0N/A // the PIDL is at the end of the list. 0N/A // Needs to be accessible to Win32ShellFolderManager2 0N/A // Given a parent's absolute PIDL and our relative PIDL, build an absolute PIDL 0N/A // Release a PIDL object 0N/A // Needs to be accessible to Win32ShellFolderManager2 0N/A // Release an IShellFolder object 1083N/A // NOTE: this method uses COM and must be called on the 'COM thread'. See ComInvoker for the details 0N/A * Accessor for IShellFolder 1083N/A // We are a directory with a parent and a relative PIDL. 1083N/A // We want to bind to the parent so we get an 1083N/A // IShellFolder instance associated with us. 0N/A * Get the parent ShellFolder's IShellFolder interface 0N/A // Parent should only be null if this is the desktop, whose 0N/A // relativePIDL is relative to its own IShellFolder. 0N/A * Accessor for relative PIDL 0N/A // This is the desktop 0N/A * Helper function to return the desktop 0N/A * Helper function to return the desktop IShellFolder interface 0N/A // Same effective implementation as Win32FileSystem 0N/A * Check to see if two ShellFolder objects are the same 0N/A // Short-circuit circuitous delegation path 0N/A // Only folders with identical parents can be equal 1083N/A // NOTE: this method uses COM and must be called on the 'COM thread'. See ComInvoker for the details 0N/A * @return Whether this is a file system shell folder 0N/A * Return whether the given attribute flag is set for this object 1083N/A // Caching at this point doesn't seem to be cost efficient 0N/A * Returns the queried attributes specified in attrsMask. 0N/A * Could plausibly be used for attribute caching but have to be 0N/A * very careful not to touch network drives and file system roots 0N/A * with a full attrsMask 1083N/A * NOTE: this method uses COM and must be called on the 'COM thread'. See ComInvoker for the details 0N/A // Return the path to the underlying file system object 1453N/A // Should be called from the COM thread 0N/A // Needs to be accessible to Win32ShellFolderManager2 1083N/A // NOTE: this method uses COM and must be called on the 'COM thread'. See ComInvoker for the details 0N/A // Return whether the path is a network root. 0N/A // Path is assumed to be non-null 0N/A * @return The parent shell folder of this shell folder, null if 0N/A * there is no parent 0N/A // Folders with SFGAO_BROWSABLE have "shell extension" handlers and are 1560N/A // not traversable in JFileChooser. 0N/A * Functions for enumerating an IShellFolder's children 0N/A // Returns an IEnumIDList interface for an IShellFolder. The value 0N/A // returned must be released using releaseEnumObjects(). 0N/A // Returns an IEnumIDList interface for an IShellFolder. The value 0N/A // returned must be released using releaseEnumObjects(). 1083N/A // NOTE: this method uses COM and must be called on the 'COM thread'. See ComInvoker for the details 0N/A // Returns the next sequential child as a relative PIDL 0N/A // from an IEnumIDList interface. The value returned must 0N/A // be released using releasePIDL(). 1083N/A // NOTE: this method uses COM and must be called on the 'COM thread'. See ComInvoker for the details 0N/A // Releases the IEnumIDList interface 1083N/A // NOTE: this method uses COM and must be called on the 'COM thread'. See ComInvoker for the details 0N/A // Returns the IShellFolder of a child from a parent IShellFolder 0N/A // and a relative PIDL. The value returned must be released 0N/A // using releaseIShellFolder(). 1083N/A // NOTE: this method uses COM and must be called on the 'COM thread'. See ComInvoker for the details 0N/A * @return An array of shell folders that are children of this shell folder 0N/A * object. The array will be empty if the folder is empty. Returns 0N/A * <code>null</code> if this shellfolder does not denote a directory. 1453N/A // Links to directories are not directories and cannot be parents. 1453N/A // This does not apply to folders in My Network Places (NetHood) 1453N/A // because they are both links and real directories! 1453N/A // If we are a directory, we have a parent and (at least) a 1453N/A // relative PIDL. We must first ensure we are bound to the 1453N/A // parent so we have an IShellFolder to query. 1453N/A // Now we can enumerate the objects in this folder. 0N/A * Look for (possibly special) child folder by it's path 0N/A * @return The child shellfolder, or null if not found. 0N/A * @return Whether this shell folder is a link 0N/A * @return Whether this shell folder is marked as hidden 0N/A // Return the link location of a shell folder 1083N/A // NOTE: this method uses COM and must be called on the 'COM thread'. See ComInvoker for the details 0N/A * @return The shell folder linked to by this shell folder, or null 0N/A * if this shell folder is not a link or is a broken or invalid link 1083N/A // Could be a link to a non-bindable object, such as a network connection 1083N/A // TODO: getIShellFolder() should throw FileNotFoundException instead 0N/A // Parse a display name into a PIDL relative to the current IShellFolder. 1083N/A // NOTE: this method uses COM and must be called on the 'COM thread'. See ComInvoker for the details 0N/A // Return the display name of a shell folder 1083N/A // NOTE: this method uses COM and must be called on the 'COM thread'. See ComInvoker for the details 0N/A * @return The name used to display this shell folder 0N/A // Return the folder type of a shell folder 1083N/A // NOTE: this method uses COM and must be called on the 'COM thread'. See ComInvoker for the details 0N/A * @return The type of shell folder as a string 0N/A // Return the executable type of a file system shell folder 0N/A * @return The executable type as a string 1083N/A // NOTE: this method uses COM and must be called on the 'COM thread'. See ComInvoker for the details 1083N/A // NOTE: this method uses COM and must be called on the 'COM thread'. See ComInvoker for the details 0N/A // Return the icon of a file system shell folder in the form of an HICON 1083N/A // NOTE: this method uses COM and must be called on the 'COM thread'. See ComInvoker for the details 0N/A // Returns an icon from the Windows system icon list in the form of an HICON 0N/A // Note: useVGAColors is ignored on XP and later 0N/A // Return the bits from an HICON. This has a side effect of setting 0N/A // the imageHash variable for efficient caching / comparing. 0N/A // Dispose the HICON 1453N/A // Should be called from the COM thread 0N/A // Get the bits. This has the side effect of setting the imageHash value for this object. 0N/A * @return The icon image used to display this shell folder 1083N/A // These are cached per type (using the index in the system image list) 1083N/A // These are only cached per object 0N/A * Gets an icon from the Windows system icon list as an <code>Image</code> 0N/A * Gets an icon from the Windows system icon list as an <code>Image</code> 0N/A * Returns the canonical form of this abstract pathname. Equivalent to 0N/A * <code>new Win32ShellFolder2(getParentFile(), this.{@link java.io.File#getCanonicalPath}())</code>. 0N/A * @see java.io.File#getCanonicalFile 0N/A * Indicates whether this is a special folder (includes My Documents) 0N/A * Compares this object with the specified object for order. 0N/A * @see sun.awt.shell.ShellFolder#compareTo(File) 0N/A return -
1;
// Non-file shellfolders sort before files 0N/A // native constants from commctrl.h 1083N/A // NOTE: this method uses COM and must be called on the 'COM thread'. See ComInvoker for the details 1083N/A // NOTE: this method uses COM and must be called on the 'COM thread'. See ComInvoker for the details 1083N/A // NOTE: this method uses COM and must be called on the 'COM thread'. See ComInvoker for the details 1231N/A // To avoid loads of synchronizations with Invoker and improve performance we 1231N/A // synchronize the whole code of the sort method once 0N/A // compares 2 objects within this folder by the specified column 1083N/A // delegates comparison to native method