Back to index

lightning-sunbird  0.9+nobinonly
Public Member Functions | Static Public Member Functions | Public Attributes | Protected Member Functions | Static Protected Member Functions | Protected Attributes | Static Protected Attributes | Private Member Functions | Static Private Attributes
nsFilePicker Class Reference

Native Mac FileSelector wrapper. More...

#include <nsFilePicker.h>

Inheritance diagram for nsFilePicker:
Inheritance graph
[legend]
Collaboration diagram for nsFilePicker:
Collaboration graph
[legend]

List of all members.

Public Member Functions

NS_DECL_ISUPPORTS nsFilePicker ()
virtual ~nsFilePicker ()
NS_IMETHOD GetDefaultString (nsAString &aDefaultString)
NS_IMETHOD SetDefaultString (const nsAString &aDefaultString)
NS_IMETHOD GetDefaultExtension (nsAString &aDefaultExtension)
NS_IMETHOD SetDefaultExtension (const nsAString &aDefaultExtension)
NS_IMETHOD GetFile (nsILocalFile **aFile)
NS_IMETHOD GetFileURL (nsIFileURL **aFileURL)
NS_IMETHOD GetFiles (nsISimpleEnumerator **aFiles)
NS_IMETHOD Show (PRInt16 *_retval)
NS_IMETHOD AppendFilter (const nsAString &aTitle, const nsAString &aFilter)
 nsFilePicker ()
virtual ~nsFilePicker ()
NS_DECL_ISUPPORTS NS_IMETHODIMP Init (nsIDOMWindow *aParent, const nsAString &aTitle, PRInt16 aMode)
NS_IMETHODIMP AppendFilters (PRInt32 aFilterMask)
NS_IMETHODIMP AppendFilter (const nsAString &aTitle, const nsAString &aFilter)
NS_IMETHODIMP SetDefaultString (const nsAString &aString)
NS_IMETHODIMP GetDefaultString (nsAString &aString)
NS_IMETHODIMP SetDefaultExtension (const nsAString &aExtension)
NS_IMETHODIMP GetDefaultExtension (nsAString &aExtension)
NS_IMETHODIMP GetFilterIndex (PRInt32 *aFilterIndex)
NS_IMETHODIMP SetFilterIndex (PRInt32 aFilterIndex)
NS_IMETHODIMP GetFile (nsILocalFile **aFile)
NS_IMETHODIMP GetFileURL (nsIFileURL **aFileURL)
NS_IMETHODIMP GetFiles (nsISimpleEnumerator **aFiles)
NS_IMETHODIMP Show (PRInt16 *aReturn)
virtual void InitNative (nsIWidget *aParent, const nsAString &aTitle, PRInt16 aMode)
 nsFilePicker ()
virtual ~nsFilePicker ()
NS_DECL_ISUPPORTS NS_IMETHOD GetDefaultString (nsAString &aDefaultString)
NS_IMETHOD SetDefaultString (const nsAString &aDefaultString)
NS_IMETHOD GetDefaultExtension (nsAString &aDefaultExtension)
NS_IMETHOD SetDefaultExtension (const nsAString &aDefaultExtension)
NS_IMETHOD GetFilterIndex (PRInt32 *aFilterIndex)
NS_IMETHOD SetFilterIndex (PRInt32 aFilterIndex)
NS_IMETHOD GetFile (nsILocalFile **aFile)
NS_IMETHOD GetFileURL (nsIFileURL **aFileURL)
NS_IMETHOD GetFiles (nsISimpleEnumerator **aFiles)
NS_IMETHOD Show (PRInt16 *_retval)
NS_IMETHOD AppendFilter (const nsAString &aTitle, const nsAString &aFilter)
 nsFilePicker ()
virtual ~nsFilePicker ()
NS_DECL_ISUPPORTS NS_IMETHOD GetDefaultString (nsAString &aDefaultString)
NS_IMETHOD SetDefaultString (const nsAString &aDefaultString)
NS_IMETHOD GetDefaultExtension (nsAString &aDefaultExtension)
NS_IMETHOD SetDefaultExtension (const nsAString &aDefaultExtension)
NS_IMETHOD GetFilterIndex (PRInt32 *aFilterIndex)
NS_IMETHOD SetFilterIndex (PRInt32 aFilterIndex)
NS_IMETHOD GetFile (nsILocalFile **aFile)
NS_IMETHOD GetFileURL (nsIFileURL **aFileURL)
NS_IMETHOD GetFiles (nsISimpleEnumerator **aFiles)
NS_IMETHOD Show (PRInt16 *_retval)
NS_IMETHOD AppendFilter (const nsAString &aTitle, const nsAString &aFilter)
 nsFilePicker ()
virtual ~nsFilePicker ()
NS_DECL_ISUPPORTS NS_IMETHOD GetDefaultString (nsAString &aDefaultString)
NS_IMETHOD SetDefaultString (const nsAString &aDefaultString)
NS_IMETHOD GetDefaultExtension (nsAString &aDefaultExtension)
NS_IMETHOD SetDefaultExtension (const nsAString &aDefaultExtension)
NS_IMETHOD GetFilterIndex (PRInt32 *aFilterIndex)
NS_IMETHOD SetFilterIndex (PRInt32 aFilterIndex)
NS_IMETHOD GetFile (nsILocalFile **aFile)
NS_IMETHOD GetFileURL (nsIFileURL **aFileURL)
NS_IMETHOD Show (PRInt16 *_retval)
NS_IMETHOD AppendFilter (const nsAString &aTitle, const nsAString &aFilter)
NS_IMETHOD GetFiles (nsISimpleEnumerator **aFiles)
 nsFilePicker ()
NS_DECL_ISUPPORTS NS_IMETHODIMP Init (nsIDOMWindow *parent, const nsAString &title, PRInt16 mode)
NS_IMETHODIMP AppendFilters (PRInt32 filterMask)
NS_IMETHODIMP AppendFilter (const nsAString &aTitle, const nsAString &aFilter)
NS_IMETHODIMP GetDefaultString (nsAString &aDefaultString)
NS_IMETHODIMP SetDefaultString (const nsAString &aDefaultString)
NS_IMETHODIMP GetDefaultExtension (nsAString &aDefaultExtension)
NS_IMETHODIMP SetDefaultExtension (const nsAString &aDefaultExtension)
NS_IMETHODIMP GetFilterIndex (PRInt32 *aFilterIndex)
NS_IMETHODIMP SetFilterIndex (PRInt32 aFilterIndex)
NS_IMETHODIMP GetFile (nsILocalFile **aFile)
NS_IMETHODIMP GetFileURL (nsIFileURL **aFileURL)
NS_IMETHODIMP GetFiles (nsISimpleEnumerator **aFiles)
NS_IMETHODIMP Show (PRInt16 *aReturn)
 nsFilePicker ()
virtual ~nsFilePicker ()
NS_DECL_ISUPPORTS NS_IMETHOD GetDefaultString (nsAString &aDefaultString)
NS_IMETHOD SetDefaultString (const nsAString &aDefaultString)
NS_IMETHOD GetDefaultExtension (nsAString &aDefaultExtension)
NS_IMETHOD SetDefaultExtension (const nsAString &aDefaultExtension)
NS_IMETHOD GetFilterIndex (PRInt32 *aFilterIndex)
NS_IMETHOD SetFilterIndex (PRInt32 aFilterIndex)
NS_IMETHOD GetFile (nsILocalFile **aFile)
NS_IMETHOD GetFileURL (nsIFileURL **aFileURL)
NS_IMETHOD GetFiles (nsISimpleEnumerator **aFiles)
NS_IMETHOD Show (PRInt16 *aReturnVal)
NS_IMETHOD ShowW (PRInt16 *aReturnVal)
NS_IMETHOD AppendFilter (const nsAString &aTitle, const nsAString &aFilter)
NS_IMETHOD GetDisplayDirectory (nsILocalFile **aDisplayDirectory)
NS_IMETHOD SetDisplayDirectory (nsILocalFile *aDisplayDirectory)
void init (in nsIDOMWindow parent, in AString title, in short mode)
 Initialize the file picker widget.
void appendFilters (in long filterMask)
 Append to the filter list with things from the predefined list.
void appendFilter (in AString title, in AString filter)
 Add a filter.
short show ()
 Show File Dialog.

Static Public Member Functions

static void Shutdown ()
static void ReleaseGlobals ()

Public Attributes

const short modeOpen = 0
const short modeSave = 1
const short modeGetFolder = 2
const short modeOpenMultiple = 3
const short returnOK = 0
const short returnCancel = 1
const short returnReplace = 2
const long filterAll = 0x01
const long filterHTML = 0x02
const long filterText = 0x04
const long filterImages = 0x08
const long filterXML = 0x10
const long filterXUL = 0x20
const long filterApps = 0x40
attribute AString defaultString
 The filename that should be suggested to the user as a default.
attribute AString defaultExtension
 The extension that should be associated with files of the type we want to work with.
attribute long filterIndex
 The filter which is currently selected in the File Picker dialog.
attribute nsILocalFile displayDirectory
 Set the directory that the file open/save dialog initially displays.
readonly attribute nsILocalFile file
 Get the nsILocalFile for the file or directory.
readonly attribute nsIFileURL fileURL
 Get the nsIFileURL for the file or directory.
readonly attribute
nsISimpleEnumerator 
files
 Get the enumerator for the selected files only works in the modeOpenMultiple mode.

Protected Member Functions

virtual void InitNative (nsIWidget *aParent, const nsAString &aTitle, PRInt16 aMode)
void GetFilterListArray (nsString &aFilterList)
void ReadValuesFromFileChooser (GtkWidget *file_chooser)
virtual void InitNative (nsIWidget *aParent, const nsAString &aTitle, PRInt16 aMode)
PRInt16 GetLocalFiles (const nsString &inTitle, PRBool inAllowMultiple, nsCOMArray< nsILocalFile > &outFiles)
PRInt16 GetLocalFolder (const nsString &inTitle, nsILocalFile **outFile)
PRInt16 PutLocalFile (const nsString &inTitle, const nsString &inDefaultName, nsILocalFile **outFile)
void MapFilterToFileTypes ()
void SetupFormatMenuItems (NavDialogCreationOptions *dialogCreateOptions)
Boolean IsTypeInFilterList (ResType inType)
Boolean IsExtensionInFilterList (StrFileName &inFileName)
void HandleShowPopupMenuSelect (NavCBRecPtr callBackParms)
virtual void InitNative (nsIWidget *aParent, const nsAString &aTitle, PRInt16 aMode)
void GetFilterListArray (nsString &aFilterList)
char * ConvertToFileSystemCharset (const nsAString &inString)
PRUnicharConvertFromFileSystemCharset (const char *inString)
virtual void InitNative (nsIWidget *aParent, const nsAString &aTitle, PRInt16 aMode)
void GetFilterListArray (nsString &aFilterList)
virtual void InitNative (nsIWidget *aParent, const nsAString &aTitle, PRInt16 aMode)
void GetFilterListArray (nsString &aFilterList)
nsIWidgetDOMWindowToWidget (nsIDOMWindow *dw)

Static Protected Member Functions

static nsresult LoadSymbolsGTK24 ()
static pascal void FileDialogEventHandlerProc (NavEventCallbackMessage msg, NavCBRecPtr cbRec, NavCallBackUserData callbackUD)
static pascal Boolean FileDialogFilterProc (AEDesc *theItem, void *info, NavCallBackUserData callbackUD, NavFilterModes filterMode)
static void GetFileSystemCharset (nsCString &fileSystemCharset)

Protected Attributes

BWindow * mParentWindow
nsString mTitle
PRInt16 mMode
nsCString mFile
nsString mDefault
nsString mFilterList
nsIUnicodeEncodermUnicodeEncoder
nsIUnicodeDecodermUnicodeDecoder
PRInt16 mSelectedType
nsCOMPtr< nsISupportsArraymFiles
nsCOMPtr< nsIWidgetmParentWidget
nsCOMArray< nsILocalFilemFiles
nsString mDefaultExtension
nsCStringArray mFilters
nsCStringArray mFilterNames
PRPackedBool mAllFilesDisplayed
PRPackedBool mApplicationsDisplayed
nsStringArray mFilters
nsStringArray mTitles
nsCStringArray mFlatFilters
NavTypeListPtr mTypeLists [kMaxTypeListCount]
PRInt32 mSelectedType
PRInt32 mTypeOffset
HWND mWnd
PtWidget_t * mParentWidget
QFileDialog * mDialog
nsString mUnicodeFile
nsCOMPtr< nsILocalFilemDisplayDirectory

Static Protected Attributes

static char mLastUsedDirectory [] = { 0 }
static OSType sCurrentProcessSignature = 0
static nsString mLastUsedUnicodeDirectory

Private Member Functions

 ~nsFilePicker ()
void InitNative (nsIWidget *, const nsAString &, short int)

Static Private Attributes

static nsILocalFilemPrevDisplayDirectory = nsnull
static PRLibrarymGTK24 = nsnull

Detailed Description

Native Mac FileSelector wrapper.

Native Windows FileSelector wrapper.

Definition at line 74 of file nsFilePicker.h.


Constructor & Destructor Documentation

virtual nsFilePicker::~nsFilePicker ( ) [virtual]
virtual nsFilePicker::~nsFilePicker ( ) [virtual]
virtual nsFilePicker::~nsFilePicker ( ) [virtual]
virtual nsFilePicker::~nsFilePicker ( ) [virtual]
virtual nsFilePicker::~nsFilePicker ( ) [virtual]

Member Function Documentation

NS_IMETHODIMP nsFilePicker::AppendFilter ( const nsAString &  aTitle,
const nsAString &  aFilter 
)
NS_IMETHODIMP nsFilePicker::AppendFilter ( const nsAString &  aTitle,
const nsAString &  aFilter 
)
NS_IMETHOD nsFilePicker::AppendFilter ( const nsAString &  aTitle,
const nsAString &  aFilter 
)
NS_IMETHOD nsFilePicker::AppendFilter ( const nsAString &  aTitle,
const nsAString &  aFilter 
)
NS_IMETHOD nsFilePicker::AppendFilter ( const nsAString &  aTitle,
const nsAString &  aFilter 
)
NS_IMETHOD nsFilePicker::AppendFilter ( const nsAString &  aTitle,
const nsAString &  aFilter 
)
NS_IMETHODIMP nsFilePicker::AppendFilter ( const nsAString &  aTitle,
const nsAString &  aFilter 
)

Definition at line 408 of file nsFilePicker.cpp.

{
       mFilterList.Append(aTitle);
       mFilterList.Append(PRUnichar('\0'));
       mFilterList.Append(aFilter);
       mFilterList.Append(PRUnichar('\0'));

       return NS_OK;
}
void nsIFilePicker::appendFilter ( in AString  title,
in AString  filter 
) [inherited]

Add a filter.

Parameters:
titlename of the filter
filterextensions to filter -- semicolon and space separated

Reimplemented from nsBaseFilePicker.

Reimplemented from nsBaseFilePicker.

Definition at line 336 of file nsFilePicker.cpp.

{
  return nsBaseFilePicker::AppendFilters(aFilterMask);
}
void nsIFilePicker::appendFilters ( in long  filterMask) [inherited]

Append to the filter list with things from the predefined list.

Parameters:
filtersmask of filters i.e. (filterAll | filterHTML)
PRUnichar * nsFilePicker::ConvertFromFileSystemCharset ( const char *  inString) [protected]

Definition at line 584 of file nsFilePicker.cpp.

{
  PRUnichar *outString = nsnull;
  nsresult rv = NS_OK;

  // get file system charset and create a unicode encoder
  if (nsnull == mUnicodeDecoder) {
    nsCAutoString fileSystemCharset;
    GetFileSystemCharset(fileSystemCharset);

    nsCOMPtr<nsICharsetConverterManager> ccm = 
             do_GetService(kCharsetConverterManagerCID, &rv); 
    if (NS_SUCCEEDED(rv)) {
      rv = ccm->GetUnicodeDecoderRaw(fileSystemCharset.get(), &mUnicodeDecoder);
    }
  }

  // converts from the file system charset to unicode
  if (NS_SUCCEEDED(rv)) {
    PRInt32 inLength = strlen(inString);
    PRInt32 outLength;
    rv = mUnicodeDecoder->GetMaxLength(inString, inLength, &outLength);
    if (NS_SUCCEEDED(rv)) {
      outString = NS_STATIC_CAST( PRUnichar*, nsMemory::Alloc( (outLength+1) * sizeof( PRUnichar ) ) );
      if (nsnull == outString) {
        return nsnull;
      }
      rv = mUnicodeDecoder->Convert(inString, &inLength, outString, &outLength);
      if (NS_SUCCEEDED(rv)) {
        outString[outLength] = 0;
      }
    }
  }

  NS_ASSERTION(NS_SUCCEEDED(rv), "error charset conversion");
  return NS_SUCCEEDED(rv) ? outString : nsnull;
}

Here is the call graph for this function:

char * nsFilePicker::ConvertToFileSystemCharset ( const nsAString &  inString) [protected]

Definition at line 541 of file nsFilePicker.cpp.

{
  char *outString = nsnull;
  nsresult rv = NS_OK;

  // get file system charset and create a unicode encoder
  if (nsnull == mUnicodeEncoder) {
    nsCAutoString fileSystemCharset;
    GetFileSystemCharset(fileSystemCharset);

    nsCOMPtr<nsICharsetConverterManager> ccm = 
             do_GetService(kCharsetConverterManagerCID, &rv); 
    if (NS_SUCCEEDED(rv)) {
      rv = ccm->GetUnicodeEncoderRaw(fileSystemCharset.get(), &mUnicodeEncoder);
    }
  }

  // converts from unicode to the file system charset
  if (NS_SUCCEEDED(rv)) {
    PRInt32 inLength = inString.Length();

    const nsAFlatString& flatInString = PromiseFlatString(inString);

    PRInt32 outLength;
    rv = mUnicodeEncoder->GetMaxLength(flatInString.get(), inLength,
                                       &outLength);
    if (NS_SUCCEEDED(rv)) {
      outString = NS_STATIC_CAST( char*, nsMemory::Alloc( outLength+1 ) );
      if (nsnull == outString) {
        return nsnull;
      }
      rv = mUnicodeEncoder->Convert(flatInString.get(), &inLength, outString,
                                    &outLength);
      if (NS_SUCCEEDED(rv)) {
        outString[outLength] = '\0';
      }
    }
  }
  
  return NS_SUCCEEDED(rv) ? outString : nsnull;
}

Here is the call graph for this function:

nsIWidget * nsBaseFilePicker::DOMWindowToWidget ( nsIDOMWindow dw) [protected, inherited]

Definition at line 78 of file nsBaseFilePicker.cpp.

{
  nsCOMPtr<nsIWidget> widget;

  nsCOMPtr<nsIScriptGlobalObject> sgo = do_QueryInterface(dw);
  if (sgo) {
    nsCOMPtr<nsIBaseWindow> baseWin(do_QueryInterface(sgo->GetDocShell()));

    while (!widget && baseWin) {
      baseWin->GetParentWidget(getter_AddRefs(widget));
      if (!widget) {
        nsCOMPtr<nsIDocShellTreeItem> docShellAsItem(do_QueryInterface(baseWin));
        if (!docShellAsItem)
          return nsnull;

        nsCOMPtr<nsIDocShellTreeItem> parent;
        docShellAsItem->GetSameTypeParent(getter_AddRefs(parent));

        sgo = do_GetInterface(parent);
        if (!sgo)
          return nsnull;

        baseWin = do_QueryInterface(sgo->GetDocShell());
      }
    }
  }

  // This will return a pointer that we're about to release, but
  // that's ok since the docshell (nsIBaseWindow) holds the widget
  // alive.
  return widget.get();
}

Here is the call graph for this function:

Here is the caller graph for this function:

pascal void nsFilePicker::FileDialogEventHandlerProc ( NavEventCallbackMessage  msg,
NavCBRecPtr  cbRec,
NavCallBackUserData  callbackUD 
) [static, protected]

Definition at line 228 of file nsFilePicker.cpp.

{
  nsFilePicker* self = NS_REINTERPRET_CAST(nsFilePicker*, callbackUD);
  switch (msg)
  {
    case kNavCBEvent:
      switch (cbRec->eventData.eventDataParms.event->what)
      {
        case updateEvt:
        {
          WindowPtr window = reinterpret_cast<WindowPtr>(cbRec->eventData.eventDataParms.event->message);
          nsCOMPtr<nsIEventSink> sink;
          nsToolkit::GetWindowEventSink (window, getter_AddRefs(sink));
          if (sink)
          {
            ::BeginUpdate(window);
            PRBool handled = PR_FALSE;
            sink->DispatchEvent(cbRec->eventData.eventDataParms.event, &handled);
            ::EndUpdate(window);           
          }        
        }
        break;
      }
      break;
    
    case kNavCBStart:
    {
      NavMenuItemSpec  menuItem;
      menuItem.version = kNavMenuItemSpecVersion;
      menuItem.menuType = self->mSelectedType + self->mTypeOffset;
      menuItem.menuCreator = self->mSelectedType + self->mTypeOffset;
      menuItem.menuItemName[0] = 0;
      (void)::NavCustomControl(cbRec->context, kNavCtlSelectCustomType, &menuItem);

      // Set the directory to mDisplayDirectory if available
      if (self->mDisplayDirectory != nsnull) {
        nsCOMPtr<nsILocalFileMac> localDisplay = do_QueryInterface(self->mDisplayDirectory);
        if (localDisplay) {
          FSRef displayFSRef;
          if (NS_SUCCEEDED(localDisplay->GetFSRef(&displayFSRef))) {
            AEDesc desc;
            OSErr status = ::AECreateDesc(typeFSRef, &displayFSRef, sizeof(displayFSRef), &desc);
            if (status == noErr) {
              (void)::NavCustomControl(cbRec->context, kNavCtlSetLocation, &desc);
              (void)::AEDisposeDesc(&desc);
            }
          }
        }
      }
    }
    break;
    
    case kNavCBPopupMenuSelect:
      // Format menu boinked - see what's happening
      if (self)
        self->HandleShowPopupMenuSelect(cbRec);
      break;
  }
}

Here is the call graph for this function:

pascal Boolean nsFilePicker::FileDialogFilterProc ( AEDesc *  theItem,
void info,
NavCallBackUserData  callbackUD,
NavFilterModes  filterMode 
) [static, protected]

Definition at line 341 of file nsFilePicker.cpp.

{
  Boolean shouldDisplay = true;
  nsFilePicker* self = NS_REINTERPRET_CAST(nsFilePicker*, callbackUD);
  if ( self && !self->mAllFilesDisplayed ) {
    if ( theItem->descriptorType == typeFSS ) {
      NavFileOrFolderInfo* info = NS_REINTERPRET_CAST ( NavFileOrFolderInfo*, theInfo );
      if ( !info->isFolder ) {
        // check it against our list. If that fails, check the extension directly
        if ( ! self->IsTypeInFilterList(info->fileAndFolder.fileInfo.finderInfo.fdType) ) {
          FSSpec fileSpec;
          if ( ::AEGetDescData(theItem, &fileSpec, sizeof(FSSpec)) == noErr )
            if ( ! self->IsExtensionInFilterList(fileSpec.name) )
              shouldDisplay = false;
        }
      } // if file isn't a folder
    } // if the item is an FSSpec
  }
  
  return shouldDisplay;
  
} // FileDialogFilterProc                                        

Here is the call graph for this function:

NS_IMETHODIMP nsFilePicker::GetDefaultExtension ( nsAString &  aDefaultExtension)
NS_IMETHOD nsFilePicker::GetDefaultExtension ( nsAString &  aDefaultExtension)
NS_IMETHODIMP nsFilePicker::GetDefaultExtension ( nsAString &  aExtension)
NS_IMETHOD nsFilePicker::GetDefaultExtension ( nsAString &  aDefaultExtension)
NS_IMETHOD nsFilePicker::GetDefaultExtension ( nsAString &  aDefaultExtension)
NS_IMETHOD nsFilePicker::GetDefaultExtension ( nsAString &  aDefaultExtension)
NS_IMETHODIMP nsFilePicker::GetDefaultExtension ( nsAString &  aDefaultExtension)

Definition at line 378 of file nsFilePicker.cpp.

{
       aExtension.Truncate();
       return NS_OK;
}
NS_IMETHODIMP nsFilePicker::GetDefaultString ( nsAString &  aDefaultString)
NS_IMETHODIMP nsFilePicker::GetDefaultString ( nsAString &  aDefaultString)

Definition at line 368 of file nsFilePicker.cpp.

{
       return NS_ERROR_FAILURE;
}
NS_IMETHODIMP nsBaseFilePicker::GetDisplayDirectory ( nsILocalFile **  aDisplayDirectory) [inherited]

Definition at line 241 of file nsBaseFilePicker.cpp.

{
  *aDirectory = nsnull;
  if (!mDisplayDirectory)
    return NS_OK;
  nsCOMPtr<nsIFile> directory;
  nsresult rv = mDisplayDirectory->Clone(getter_AddRefs(directory));
  if (NS_FAILED(rv))
    return rv;
  return CallQueryInterface(directory, aDirectory);
}

Here is the call graph for this function:

Definition at line 320 of file nsFilePicker.cpp.

{
       NS_ENSURE_ARG_POINTER(aFile);
       if (mFile.IsEmpty())
              return NS_OK;
       nsCOMPtr<nsILocalFile> file(do_CreateInstance("@mozilla.org/file/local;1"));
       NS_ENSURE_TRUE(file, NS_ERROR_FAILURE);
       file->InitWithNativePath(mFile);

       NS_ADDREF(*aFile = file);

       return NS_OK;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Reimplemented from nsBaseFilePicker.

Reimplemented from nsBaseFilePicker.

Reimplemented from nsBaseFilePicker.

Reimplemented from nsBaseFilePicker.

Reimplemented from nsBaseFilePicker.

Reimplemented from nsBaseFilePicker.

Reimplemented from nsBaseFilePicker.

Definition at line 334 of file nsFilePicker.cpp.

{
       NS_ENSURE_ARG_POINTER(aFiles);
       return NS_NewArrayEnumerator(aFiles, mFiles);
}

Here is the call graph for this function:

void nsFilePicker::GetFileSystemCharset ( nsCString fileSystemCharset) [static, protected]

Definition at line 523 of file nsFilePicker.cpp.

{
  static nsCAutoString aCharset;
  nsresult rv;

  if (aCharset.Length() < 1) {
    nsCOMPtr <nsIPlatformCharset> platformCharset = do_GetService(NS_PLATFORMCHARSET_CONTRACTID, &rv);
         if (NS_SUCCEEDED(rv)) 
                rv = platformCharset->GetCharset(kPlatformCharsetSel_FileName, aCharset);

    NS_ASSERTION(NS_SUCCEEDED(rv), "error getting platform charset");
         if (NS_FAILED(rv)) 
                aCharset.AssignLiteral("IBM850");
  }
  fileSystemCharset = aCharset;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 342 of file nsFilePicker.cpp.

Here is the call graph for this function:

Reimplemented from nsBaseFilePicker.

Reimplemented from nsBaseFilePicker.

Reimplemented from nsBaseFilePicker.

Definition at line 498 of file nsFilePicker.mm.

{
  *aFilterIndex = mSelectedType;
  return NS_OK;
}

Reimplemented from nsBaseFilePicker.

Reimplemented from nsBaseFilePicker.

Reimplemented from nsBaseFilePicker.

void nsFilePicker::GetFilterListArray ( nsString aFilterList) [protected]
void nsFilePicker::GetFilterListArray ( nsString aFilterList) [protected]
void nsFilePicker::GetFilterListArray ( nsString aFilterList) [protected]
void nsFilePicker::GetFilterListArray ( nsString aFilterList) [protected]
PRInt16 nsFilePicker::GetLocalFiles ( const nsString inTitle,
PRBool  inAllowMultiple,
nsCOMArray< nsILocalFile > &  outFiles 
) [protected]

Definition at line 166 of file nsFilePicker.mm.

{
  PRInt16 retVal = (PRInt16)returnCancel;
  NSOpenPanel *thePanel = [NSOpenPanel openPanel];

  // Get filters
  NSArray *filters = GenerateFilterList();

  // Set the options for how the get file dialog will appear
  SetDialogTitle(inTitle, thePanel);
  [thePanel setAllowsMultipleSelection:inAllowMultiple];
  [thePanel setCanSelectHiddenExtension:YES];
  [thePanel setCanChooseDirectories:NO];
  [thePanel setCanChooseFiles:YES];
  [thePanel setResolvesAliases:YES];        //this is default - probably doesn't need to be set
  // handle how we deal with packages. 
  if (filters)
    [thePanel setTreatsFilePackagesAsDirectories:NO];       

  // set up default directory
  NSString *theDir = PanelDefaultDirectory();
  int result = [thePanel runModalForDirectory:theDir file:nil types:filters];  
  
  if (result == NSFileHandlingPanelCancelButton)
    return retVal;
  
  // append each chosen file to our list
  for (unsigned int i = 0; i < [[thePanel URLs] count]; i ++)
  {
    NSURL *theURL = [[thePanel URLs] objectAtIndex:i];
    if (theURL)
    {
      nsCOMPtr<nsILocalFile> localFile;
      NS_NewLocalFile(EmptyString(), PR_TRUE, getter_AddRefs(localFile));
      nsCOMPtr<nsILocalFileMac> macLocalFile = do_QueryInterface(localFile);
      if (macLocalFile && NS_SUCCEEDED(macLocalFile->InitWithCFURL((CFURLRef)theURL)))
        outFiles.AppendObject(localFile);
    }
  }

  if (outFiles.Count() > 0)
    retVal = returnOK;

  return retVal;
} // GetFile

Here is the call graph for this function:

PRInt16 nsFilePicker::GetLocalFolder ( const nsString inTitle,
nsILocalFile **  outFile 
) [protected]

Definition at line 224 of file nsFilePicker.mm.

{
  NS_ENSURE_ARG(outFile);
  *outFile = nsnull;
  
  PRInt16 retVal = (PRInt16)returnCancel;
  NSOpenPanel *thePanel = [NSOpenPanel openPanel];

  // Set the options for how the get file dialog will appear
  SetDialogTitle(inTitle, thePanel);
  [thePanel setAllowsMultipleSelection:NO];   //this is default -probably doesn't need to be set
  [thePanel setCanSelectHiddenExtension:YES];
  [thePanel setCanChooseDirectories:YES];
  [thePanel setCanChooseFiles:NO];
  [thePanel setResolvesAliases:YES];          //this is default - probably doesn't need to be set
  [thePanel setTreatsFilePackagesAsDirectories:YES]; //sure, we can pick packages.  

  // set up default directory
  NSString *theDir = PanelDefaultDirectory();
  int result = [thePanel runModalForDirectory:theDir file:nil types:nil];  

  if (result == NSFileHandlingPanelCancelButton)
    return retVal;
    
  // get FSRef for folder (we allow just 1, so that's all we get)
  NSURL *theURL = [[thePanel URLs] objectAtIndex:0];
  if (theURL)
  {
    nsCOMPtr<nsILocalFile> localFile;
    NS_NewLocalFile(EmptyString(), PR_TRUE, getter_AddRefs(localFile));
    nsCOMPtr<nsILocalFileMac> macLocalFile = do_QueryInterface(localFile);
    if (macLocalFile && NS_SUCCEEDED(macLocalFile->InitWithCFURL((CFURLRef)theURL)))
    {
      *outFile = localFile;
      NS_ADDREF(*outFile);
      retVal = returnOK;
    }
  }

  return retVal;
} // GetFolder

Here is the call graph for this function:

void nsFilePicker::HandleShowPopupMenuSelect ( NavCBRecPtr  callBackParms) [protected]

Definition at line 194 of file nsFilePicker.cpp.

{
  if (callBackParms)
  {
    NavMenuItemSpec menuItemSpec = *(NavMenuItemSpec*)callBackParms->eventData.eventDataParms.param;
    PRUint32        numMenuItems = mTitles.Count();
    if (mTypeOffset && (numMenuItems != 0))
    { // Special case Nav Services prior to 2.0
      // Make sure the menu item selected was one of ours
      if ((menuItemSpec.menuType != menuItemSpec.menuCreator) ||
          ((PRInt32)menuItemSpec.menuType < mTypeOffset) ||
          (menuItemSpec.menuType > numMenuItems))
      { // Doesn't appear to be one of our items selected so force it to be
        NavMenuItemSpec  menuItem;
        menuItem.version = kNavMenuItemSpecVersion;
        menuItem.menuType = mSelectedType + mTypeOffset;
        menuItem.menuCreator = mSelectedType + mTypeOffset;
        menuItem.menuItemName[0] = 0;
        (void)::NavCustomControl(callBackParms->context, kNavCtlSelectCustomType, &menuItem);
      }
      else
        mSelectedType = menuItemSpec.menuType - mTypeOffset;
    }
    else
      mSelectedType = menuItemSpec.menuType;
  }
}
NS_DECL_ISUPPORTS NS_IMETHODIMP nsFilePicker::Init ( nsIDOMWindow parent,
const nsAString &  title,
PRInt16  mode 
)

Reimplemented from nsBaseFilePicker.

NS_IMETHODIMP nsFilePicker::Init ( nsIDOMWindow aParent,
const nsAString &  aTitle,
PRInt16  aMode 
)

Reimplemented from nsBaseFilePicker.

Definition at line 315 of file nsFilePicker.cpp.

{
  nsresult rv = LoadSymbolsGTK24();
  if (NS_FAILED(rv)) {
    return rv;
  }

  return nsBaseFilePicker::Init(aParent, aTitle, aMode);
}

Here is the call graph for this function:

void nsIFilePicker::init ( in nsIDOMWindow  parent,
in AString  title,
in short  mode 
) [inherited]

Initialize the file picker widget.

The file picker is not valid until this method is called.

Parameters:
parentnsIDOMWindow parent. This dialog will be dependent on this parent. parent must be non-null.
titleThe title for the file widget
modeload, save, or get folder
virtual void nsFilePicker::InitNative ( nsIWidget aParent,
const nsAString &  aTitle,
PRInt16  aMode 
) [virtual]

Implements nsBaseFilePicker.

void nsFilePicker::InitNative ( nsIWidget ,
const nsAString &  ,
short  int 
) [private, virtual]

Implements nsBaseFilePicker.

virtual void nsFilePicker::InitNative ( nsIWidget aParent,
const nsAString &  aTitle,
PRInt16  aMode 
) [protected, virtual]

Implements nsBaseFilePicker.

virtual void nsFilePicker::InitNative ( nsIWidget aParent,
const nsAString &  aTitle,
PRInt16  aMode 
) [protected, virtual]

Implements nsBaseFilePicker.

virtual void nsFilePicker::InitNative ( nsIWidget aParent,
const nsAString &  aTitle,
PRInt16  aMode 
) [protected, virtual]

Implements nsBaseFilePicker.

virtual void nsFilePicker::InitNative ( nsIWidget aParent,
const nsAString &  aTitle,
PRInt16  aMode 
) [protected, virtual]

Implements nsBaseFilePicker.

void nsFilePicker::InitNative ( nsIWidget aParent,
const nsAString &  aTitle,
PRInt16  aMode 
) [protected, virtual]

Implements nsBaseFilePicker.

Definition at line 390 of file nsFilePicker.cpp.

{
       mParentWindow = 0;

       BView *view = (BView *) aParent->GetNativeData(NS_NATIVE_WIDGET);
       if (view && view->LockLooper())
       {
              mParentWindow = view->Window();
              view->UnlockLooper();
       }

       mTitle.Assign(aTitle);
       mMode = aMode;
}

Here is the call graph for this function:

Boolean nsFilePicker::IsExtensionInFilterList ( StrFileName &  inFileName) [protected]

Definition at line 310 of file nsFilePicker.cpp.

{
  char extension[256];
  
  // determine the extension from the file name
  unsigned char* curr = &inFileName[inFileName[0]];
  while ( curr != inFileName && *curr-- != '.' ) ;
  if ( curr == inFileName )                         // no '.' in string, fails this check
    return false;
  ++curr;                                           // we took one too many steps back
  short extensionLen = (inFileName + inFileName[0]) - curr + 1;
  strncpy ( extension, (char*)curr, extensionLen);
  extension[extensionLen] = '\0';
  
  // see if it is in our list
  for ( int i = 0; i < mFlatFilters.Count(); ++i ) {
    if ( mFlatFilters[i]->Equals(extension) )
      return true;
  }
  return false;
}

Here is the call graph for this function:

Boolean nsFilePicker::IsTypeInFilterList ( ResType  inType) [protected]

Definition at line 295 of file nsFilePicker.cpp.

{
  for ( int i = 0; i < mFilters.Count(); ++i ) {
    for ( int j = 0; j < mTypeLists[i]->osTypeCount; ++j ) {
      if ( mTypeLists[i]->osType[j] == inType ) 
        return true;
    }  // foreach type w/in the group
  } // for each filter group
  
  return false;
  
} // IsFileInFilterList
nsresult nsFilePicker::LoadSymbolsGTK24 ( ) [static, protected]

Definition at line 155 of file nsFilePicker.cpp.

{
  static PRBool initialized;
  if (initialized) {
    return NS_OK;
  }

  #define GET_LIBGTK_FUNC_BASE(func, onerr)                  \
    PR_BEGIN_MACRO \
    _##func = (_##func##_fn) PR_FindFunctionSymbol(mGTK24, #func); \
    if (!_##func) { \
      NS_WARNING("Can't load gtk symbol " #func); \
      onerr \
    } \
    PR_END_MACRO

  #define GET_LIBGTK_FUNC(func) \
    GET_LIBGTK_FUNC_BASE(func, return NS_ERROR_NOT_AVAILABLE;)

  #define GET_LIBGTK_FUNC_OPT(func) \
    GET_LIBGTK_FUNC_BASE(func, ;)

  PRFuncPtr func = PR_FindFunctionSymbolAndLibrary("gtk_file_chooser_get_filename",
                                                   &mGTK24);
  if (mGTK24) {
    _gtk_file_chooser_get_filename = (_gtk_file_chooser_get_filename_fn)func;
  } else {
    // XXX hmm, this seems to fail when gtk 2.4 is already loaded...
    mGTK24 = LoadVersionedLibrary("gtk-2", ".4");
    if (!mGTK24) {
      return NS_ERROR_NOT_AVAILABLE;
    }
    GET_LIBGTK_FUNC(gtk_file_chooser_get_filename);
  }

  GET_LIBGTK_FUNC(gtk_file_chooser_get_filenames);
  GET_LIBGTK_FUNC(gtk_file_chooser_dialog_new);
  GET_LIBGTK_FUNC(gtk_file_chooser_set_select_multiple);
  GET_LIBGTK_FUNC_OPT(gtk_file_chooser_set_do_overwrite_confirmation);
  GET_LIBGTK_FUNC(gtk_file_chooser_set_current_name);
  GET_LIBGTK_FUNC(gtk_file_chooser_set_current_folder);
  GET_LIBGTK_FUNC(gtk_file_chooser_add_filter);
  GET_LIBGTK_FUNC(gtk_file_chooser_set_filter);
  GET_LIBGTK_FUNC(gtk_file_chooser_get_filter);
  GET_LIBGTK_FUNC(gtk_file_chooser_list_filters);
  GET_LIBGTK_FUNC(gtk_file_filter_new);
  GET_LIBGTK_FUNC(gtk_file_filter_add_pattern);
  GET_LIBGTK_FUNC(gtk_file_filter_set_name);

  initialized = PR_TRUE;

  // Woot.
  return NS_OK;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 688 of file nsFilePicker.cpp.

{
  nsCOMPtr<nsIInternetConfigService> icService ( do_GetService(NS_INTERNETCONFIGSERVICE_CONTRACTID) );
  NS_ASSERTION(icService, "Can't get InternetConfig Service, bailing out");
  if ( !icService ) {
    // We couldn't get the IC Service, bail. Since |mAllFilesDisplayed| is still
    // set, the dialog will allow selection of all files. 
    return;
  }
  
  if (mFilters.Count())
  {
    // First we allocate the memory for the Mac type lists
    for (PRInt32 loop1 = 0; loop1 < mFilters.Count() && loop1 < kMaxTypeListCount; loop1++)
    {
      mTypeLists[loop1] =
        (NavTypeListPtr)NewPtrClear(sizeof(NavTypeList) + kMaxTypesPerFilter * sizeof(OSType));     
      if ( !mTypeLists[loop1] )
        return;                     // don't worry, we'll clean up in the dtor
    }
    
    // Now loop through each of the filter strings
    for (PRInt32 loop1 = 0; loop1 < mFilters.Count() && loop1 < kMaxTypeListCount; loop1++)
    {
      const nsString& filterWide = *mFilters[loop1];
      char* filter = ToNewCString(filterWide);

      NS_ASSERTION ( filterWide.Length(), "Oops. filepicker.properties not correctly installed");       

      // look for the flag indicating applications
      if (filterWide.EqualsLiteral("..apps"))
        mApplicationsDisplayed = PR_TRUE;

      if ( filterWide.Length() && filter )
      {
        PRUint32 filterIndex = 0;         // Index into the filter string
        PRUint32 typeTempIndex = 0;       // Index into the temp string for a single filter type
        PRUint32 typesInThisFilter = 0;   // Count for # of types in this filter
        bool finishedThisFilter = false;  // Flag so we know when we're finsihed with the filter
        char typeTemp[256];
        char tempChar;           // char we're currently looking at

        // Loop through the characters of filter string. Every time we get to a
        // semicolon (or a null, meaning we've hit the end of the full string)
        // then we've found the filter and can pass it off to IC to get a macOS 
        // file type out of it.
        do
        {
          tempChar = filter[filterIndex];
          if ((tempChar == ';') || (tempChar == 0)) {   // End of filter type reached
            typeTemp[typeTempIndex] = '\0';             // null terminate
            
            // to make it easier to match file extensions while we're filtering, flatten
            // out the list. Ignore filters that are just "*" and also remove the
            // leading "*" from filters we do add.
            if ( strlen(typeTemp) > 1 )
              mFlatFilters.AppendCString ( nsCString((char*)&typeTemp[1]) );  // cut out the "*"
            
            // ask IC if it's not "all files" (designated by "*")
            if ( !(typeTemp[1] == '\0' && typeTemp[0] == '*') ) {
              mAllFilesDisplayed = PR_FALSE;
              
              nsCOMPtr<nsIMIMEInfo> icEntry;
              icService->GetMIMEInfoFromExtension(typeTemp, getter_AddRefs(icEntry));
              if ( icEntry )
              {
                bool addToList = true;
                OSType tempOSType;
                icEntry->GetMacType(NS_REINTERPRET_CAST(PRUint32*, (&tempOSType)));
                for (PRUint32 typeIndex = 0; typeIndex < typesInThisFilter; typeIndex++)
                {
                  if (mTypeLists[loop1]->osType[typeIndex] == tempOSType)
                  {
                    addToList = false;
                    break;
                  }
                }
                if (addToList && typesInThisFilter < kMaxTypesPerFilter)
                  mTypeLists[loop1]->osType[typesInThisFilter++] = tempOSType;
              }
            } // if not "*"
            
            typeTempIndex = 0;      // Reset the temp string for the type
            if (tempChar == '\0')
              finishedThisFilter = true;
          }
          else
          {
            // strip out whitespace as we go
            if ( tempChar != ' ' )
              typeTemp[typeTempIndex++] = tempChar;
          }
          
          filterIndex++;
        } while (!finishedThisFilter);
        
        // Set how many OSTypes we actually found
        mTypeLists[loop1]->osTypeCount = typesInThisFilter;
        
        nsMemory::Free ( NS_REINTERPRET_CAST(void*, filter) );
      }
    }
  }

} // MapFilterToFileTypes

Here is the call graph for this function:

PRInt16 nsFilePicker::PutLocalFile ( const nsString inTitle,
const nsString inDefaultName,
nsILocalFile **  outFile 
) [protected]

Definition at line 278 of file nsFilePicker.mm.

{
  NS_ENSURE_ARG(outFile);
  *outFile = nsnull;

  PRInt16 retVal = returnCancel;
  NSSavePanel *thePanel = [NSSavePanel savePanel];
  
  // set up save panel options & whatnot.
  SetDialogTitle(inTitle, thePanel);
  
  // set up default file name
  NSString* defaultFilename = [NSString stringWithCharacters:(const unichar*)inDefaultName.get() length:inDefaultName.Length()];

  // set up default directory
  NSString *theDir = PanelDefaultDirectory();
  
  // load the panel.
  int result = [thePanel runModalForDirectory:theDir file:defaultFilename];
  if (result == NSFileHandlingPanelCancelButton)
    return retVal;

  // Get the NSURL for the directory where the file to be saved
  NSURL *dirURL = [NSURL fileURLWithPath:[thePanel directory]];
  // append the filename
  NSURL *fileURL = [[NSURL alloc] initWithString:[thePanel filename] relativeToURL:dirURL];
  if (fileURL)
  { 
    nsCOMPtr<nsILocalFile> localFile;
    NS_NewLocalFile(EmptyString(), PR_TRUE, getter_AddRefs(localFile));
    nsCOMPtr<nsILocalFileMac> macLocalFile = do_QueryInterface(localFile);
    if (macLocalFile && NS_SUCCEEDED(macLocalFile->InitWithCFURL((CFURLRef)fileURL)))
    {
      *outFile = localFile;
      NS_ADDREF(*outFile);
      // XXX how can we tell if we're replacing? Need to return returnReplace
      retVal = returnOK;
    }

    [fileURL release];
  }      
  return retVal;    
}

Here is the call graph for this function:

void nsFilePicker::ReadValuesFromFileChooser ( GtkWidget *  file_chooser) [protected]

Definition at line 279 of file nsFilePicker.cpp.

{
  mFiles.Clear();

  if (mMode == nsIFilePicker::modeOpenMultiple) {
    mFile.Truncate();

    GSList *list = _gtk_file_chooser_get_filenames (GTK_FILE_CHOOSER(file_chooser));
    g_slist_foreach(list, ReadMultipleFiles, NS_STATIC_CAST(gpointer, &mFiles));
    g_slist_free(list);
  } else {
    gchar *filename = _gtk_file_chooser_get_filename (GTK_FILE_CHOOSER(file_chooser));
    mFile.Assign(filename);
    g_free(filename);
  }

  GtkFileFilter *filter = _gtk_file_chooser_get_filter (GTK_FILE_CHOOSER(file_chooser));
  GSList *filter_list = _gtk_file_chooser_list_filters (GTK_FILE_CHOOSER(file_chooser));

  mSelectedType = NS_STATIC_CAST(PRInt16, g_slist_index (filter_list, filter));
  g_slist_free(filter_list);

  // Remember last used directory.
  nsCOMPtr<nsILocalFile> file;
  GetFile(getter_AddRefs(file));
  if (file) {
    nsCOMPtr<nsIFile> dir;
    file->GetParent(getter_AddRefs(dir));
    nsCOMPtr<nsILocalFile> localDir(do_QueryInterface(dir));
    if (localDir) {
      localDir.swap(mPrevDisplayDirectory);
    }
  }
}

Here is the call graph for this function:

Definition at line 111 of file nsFilePicker.cpp.

Here is the caller graph for this function:

NS_IMETHODIMP nsFilePicker::SetDefaultExtension ( const nsAString &  aDefaultExtension)
NS_IMETHOD nsFilePicker::SetDefaultExtension ( const nsAString &  aDefaultExtension)
NS_IMETHOD nsFilePicker::SetDefaultExtension ( const nsAString &  aDefaultExtension)
NS_IMETHOD nsFilePicker::SetDefaultExtension ( const nsAString &  aDefaultExtension)
NS_IMETHOD nsFilePicker::SetDefaultExtension ( const nsAString &  aDefaultExtension)
NS_IMETHODIMP nsFilePicker::SetDefaultExtension ( const nsAString &  aDefaultExtension)

Definition at line 384 of file nsFilePicker.cpp.

{
       return NS_OK;
}
NS_IMETHODIMP nsFilePicker::SetDefaultString ( const nsAString &  aDefaultString)
NS_IMETHOD nsFilePicker::SetDefaultString ( const nsAString &  aDefaultString)
NS_IMETHOD nsFilePicker::SetDefaultString ( const nsAString &  aDefaultString)
NS_IMETHOD nsFilePicker::SetDefaultString ( const nsAString &  aDefaultString)
NS_IMETHOD nsFilePicker::SetDefaultString ( const nsAString &  aDefaultString)
NS_IMETHODIMP nsFilePicker::SetDefaultString ( const nsAString &  aDefaultString)

Definition at line 362 of file nsFilePicker.cpp.

{
       mDefault = aString;
       return NS_OK;
}

Definition at line 222 of file nsBaseFilePicker.cpp.

{
  if (!aDirectory) {
    mDisplayDirectory = nsnull;
    return NS_OK;
  }
  nsCOMPtr<nsIFile> directory;
  nsresult rv = aDirectory->Clone(getter_AddRefs(directory));
  if (NS_FAILED(rv))
    return rv;
  mDisplayDirectory = do_QueryInterface(directory, &rv);
  return rv;
}

Here is the call graph for this function:

Reimplemented from nsBaseFilePicker.

Reimplemented from nsBaseFilePicker.

Reimplemented from nsBaseFilePicker.

Definition at line 509 of file nsFilePicker.mm.

{
  mSelectedType = aFilterIndex;
  return NS_OK;
}

Reimplemented from nsBaseFilePicker.

Reimplemented from nsBaseFilePicker.

Reimplemented from nsBaseFilePicker.

void nsFilePicker::SetupFormatMenuItems ( NavDialogCreationOptions *  dialogCreateOptions) [protected]

Definition at line 800 of file nsFilePicker.cpp.

{
  PRInt32   numMenuItems = mTitles.Count();
  PRInt32   index;
  CFStringRef      itemStr = NULL;
  CFArrayCallBacks callBacks = kCFTypeArrayCallBacks;
  
  // Under NavServices 3.0 the popupExtension is actually a CFArray of CFStrings
  dialogCreateOptions->popupExtension = CFArrayCreateMutable(kCFAllocatorDefault, numMenuItems, &callBacks);
  
  if (dialogCreateOptions->popupExtension)
  {
    for (index = 0; index < numMenuItems; ++index)
    {
      const nsString& titleWide = *mTitles[index];
      itemStr = CFStringCreateWithCharacters(NULL, (const unsigned short *)titleWide.get(), titleWide.Length());
      CFArrayInsertValueAtIndex((CFMutableArrayRef)dialogCreateOptions->popupExtension, index, (void*)itemStr);
      CFRelease(itemStr);
    }
  }
}

Here is the call graph for this function:

Definition at line 98 of file nsFilePicker.cpp.

{
       PRBool result = PR_TRUE;
       nsFilePanelBeOS *ppanel;
       file_panel_mode panel_mode;
       bool allow_multiple_selection = false;
       uint32 node_flavors;

       if (mMode == modeGetFolder)
       {
              node_flavors = B_DIRECTORY_NODE;
              panel_mode = B_OPEN_PANEL;
       }
       else if (mMode == modeOpen)
       {
              node_flavors = B_FILE_NODE;
              panel_mode = B_OPEN_PANEL;
       }
       else if (mMode == modeOpenMultiple)
       {
              node_flavors = B_FILE_NODE;
              panel_mode = B_OPEN_PANEL;
              allow_multiple_selection = true;
       }
       else if (mMode == modeSave)
       {
              node_flavors = B_FILE_NODE;
              panel_mode = B_SAVE_PANEL;
       }
       else
       {
              printf("nsFilePicker::Show() wrong mode");
              return PR_FALSE;
       }

       ppanel = new nsFilePanelBeOS(
                            panel_mode, //file_panel_mode mode
                      node_flavors,  //uint32 node_flavors
                      allow_multiple_selection,  //bool allow_multiple_selection
                      false, //bool modal
                      true //bool hide_when_done
                            );
       if (!ppanel)
              return PR_FALSE;
       nsCOMPtr<nsIAppShell> appShell(do_CreateInstance(kAppShellCID));
       NS_ENSURE_TRUE(appShell, NS_ERROR_FAILURE);
       appShell->Create(0, nsnull);
       appShell->Spinup();
       // set title
       if (!mTitle.IsEmpty())
       {
              char *title_utf8 = ToNewUTF8String(mTitle);
              ppanel->Window()->SetTitle(title_utf8);
              Recycle(title_utf8);
       }

       // set default text
       if (!mDefault.IsEmpty() && panel_mode == B_SAVE_PANEL)
       {
              char *defaultText = ToNewUTF8String(mDefault);
              ppanel->SetSaveText(defaultText);
              Recycle(defaultText);
       }

       // set initial directory
       nsCAutoString initialDir;
       if (mDisplayDirectory)
              mDisplayDirectory->GetNativePath(initialDir);
       if(initialDir.IsEmpty())
       {
#ifdef FILEPICKER_SAVE_LAST_DIR           
              if (strlen(mLastUsedDirectory) < 2)
                     initialDir.Assign("/boot/home");
              else
                     initialDir.Assign(mLastUsedDirectory);
#else
              ppanel->SetPanelDirectory(initialDir.get());
#endif               
       }

#ifdef FILEPICKER_SAVE_LAST_DIR
       ppanel->SetPanelDirectory(initialDir.get());
#endif

       // set modal feel
       if (ppanel->LockLooper())
       {
              ppanel->Window()->SetFeel(B_MODAL_APP_WINDOW_FEEL);
              ppanel->UnlockLooper();
       }

       // Show File Panel
       ppanel->Show();
       while(!ppanel->SelectionDone())
       {
              void* data;
              PRBool isRealEvent;
              nsresult rv = NS_OK;
              if(mParentWindow)
              {
                     // flushing pending native drawing
                     mParentWindow->UpdateIfNeeded();
              }
              rv = appShell->GetNativeEvent(isRealEvent, data);
              if(NS_SUCCEEDED(rv))
              {
                     // ModalEventFilter always returns true in our implementation
                     // window->ModalEventFilter(isRealEvent, data, &processEvent);
                     appShell->DispatchNativeEvent(isRealEvent, data);
              }
       };

       if (ppanel->IsCancelSelected())
              result = PR_FALSE;

       if ((mMode == modeOpen || mMode == modeOpenMultiple || mMode == modeGetFolder) && ppanel->IsOpenSelected())
       {
              BList *list = ppanel->OpenRefs();
              uint32 numfiles = list->CountItems();
              if ((list) && numfiles >= 1)
              {
                     nsresult rv = NS_NewISupportsArray(getter_AddRefs(mFiles));
                     for (uint32 i = 0; i< numfiles; i++)
                     {
                            BPath *path = (BPath *)list->ItemAt(i);

                            if (path->InitCheck() == B_OK)
                            {
                                   mFile.Truncate();
                                   // Single and Multiple are exclusive now, though, maybe there is sense
                                   // to assign also first list element to mFile even in openMultiple case ?
                                   if (mMode == modeOpenMultiple)
                                   {
                                          nsCOMPtr<nsILocalFile> file = do_CreateInstance("@mozilla.org/file/local;1", &rv);
                                          NS_ENSURE_SUCCESS(rv,rv);
                                          rv = file->InitWithNativePath(nsDependentCString(path->Path()));
                                          NS_ENSURE_SUCCESS(rv,rv);
                                          rv = mFiles->AppendElement(file);
                                          NS_ENSURE_SUCCESS(rv,rv);
                                   }
                                   else
                                   {
                                          if (i == 0) mFile.Assign(path->Path());
                                   }
                            }
                            else
                            {
                                   printf("path.init failed \n");
                            }
                     }
              }
              else
              {
                     printf("list not init \n");
              }
       }
       else if (mMode == modeSave && ppanel->IsSaveSelected())
       {
              BString savefilename = ppanel->SaveFileName();
              entry_ref ref = ppanel->SaveDirRef();
              BPath path(&ref);
              if (path.InitCheck() == B_OK)
              {
                     path.Append(savefilename.String(), true);
                     mFile.Assign(path.Path());
              }
       }
       else
       {
              result = PR_FALSE;
       }

       // set current directory to mDisplayDirectory
       entry_ref dir_ref;
       ppanel->GetPanelDirectory(&dir_ref);
       BEntry dir_entry(&dir_ref);
       BPath dir_path;
       dir_entry.GetPath(&dir_path);
       if (!mDisplayDirectory)
              mDisplayDirectory = do_CreateInstance("@mozilla.org/file/local;1");
       if (mDisplayDirectory)
              mDisplayDirectory->InitWithNativePath(nsDependentCString(dir_path.Path()));

       if (ppanel->Lock())
              ppanel->Quit();

       if (result)
       {
              PRInt16 returnOKorReplace = returnOK;

#ifdef FILEPICKER_SAVE_LAST_DIR
              strncpy(mLastUsedDirectory, dir_path.Path(), B_PATH_NAME_LENGTH+1);
              if (mDisplayDirectory)
                     mDisplayDirectory->InitWithNativePath( nsDependentCString(mLastUsedDirectory) );
#endif

              if (mMode == modeSave)
              {
                     //   we must check if file already exists
                     PRBool exists = PR_FALSE;
                     nsCOMPtr<nsILocalFile> file(do_CreateInstance("@mozilla.org/file/local;1"));
                     NS_ENSURE_TRUE(file, NS_ERROR_FAILURE);

                     file->InitWithNativePath(mFile);
                     file->Exists(&exists);
                     if (exists)
                            returnOKorReplace = returnReplace;
              }
              *retval = returnOKorReplace;
       }
       else
       {
              *retval = returnCancel;
       }
       appShell->Spindown();
       return NS_OK;

       // TODO: implement filters
}

Here is the call graph for this function:

short nsIFilePicker::show ( ) [inherited]

Show File Dialog.

The dialog is displayed modally.

Returns:
returnOK if the user selects OK, returnCancel if the user selects cancel

Definition at line 125 of file nsFilePicker.cpp.

{
  NS_ENSURE_ARG_POINTER(aReturnVal);

  // suppress blur events
  if (mParentWidget) {
    nsIWidget *tmp = mParentWidget;
    nsWindow *parent = NS_STATIC_CAST(nsWindow *, tmp);
    parent->SuppressBlurEvents(PR_TRUE);
  }

  PRBool result = PR_FALSE;
  PRUnichar fileBuffer[FILE_BUFFER_SIZE+1];
  wcsncpy(fileBuffer,  mDefault.get(), FILE_BUFFER_SIZE);
  fileBuffer[FILE_BUFFER_SIZE] = '\0'; // null terminate in case copy truncated

  NS_NAMED_LITERAL_STRING(htmExt, "html");
  nsAutoString initialDir;
  if (mDisplayDirectory)
    mDisplayDirectory->GetPath(initialDir);

  // If no display directory, re-use the last one.
  if(initialDir.IsEmpty()) {
    // Allocate copy of last used dir.
    initialDir = mLastUsedUnicodeDirectory;
  }

  mUnicodeFile.Truncate();

#ifndef WINCE

  if (mMode == modeGetFolder) {
    PRUnichar dirBuffer[MAX_PATH+1];
    wcsncpy(dirBuffer, initialDir.get(), MAX_PATH);

    BROWSEINFOW browserInfo;
    browserInfo.hwndOwner      = (HWND)
      (mParentWidget.get() ? mParentWidget->GetNativeData(NS_NATIVE_WINDOW) : 0); 
    browserInfo.pidlRoot       = nsnull;
    browserInfo.pszDisplayName = (LPWSTR)dirBuffer;
    browserInfo.lpszTitle      = mTitle.get();
    browserInfo.ulFlags        = BIF_USENEWUI | BIF_RETURNONLYFSDIRS;
    if (initialDir.Length()) // convert folder path to native, the strdup copy will be released in BrowseCallbackProc
    {
      nsCAutoString nativeFolderPath;
      NS_CopyUnicodeToNative(initialDir, nativeFolderPath);
      browserInfo.lParam       = (LPARAM) nsCRT::strdup(nativeFolderPath.get()); 
      browserInfo.lpfn         = &BrowseCallbackProc;
    }
    else
    {
    browserInfo.lParam         = nsnull;
      browserInfo.lpfn         = nsnull;
    }
    browserInfo.iImage         = nsnull;

    // XXX UNICODE support is needed here --> DONE
    LPITEMIDLIST list = nsToolkit::mSHBrowseForFolder(&browserInfo);
    if (list != NULL) {
      result = nsToolkit::mSHGetPathFromIDList(list, (LPWSTR)fileBuffer);
      if (result) {
          mUnicodeFile.Assign(fileBuffer);
      }
  
      // free PIDL
      CoTaskMemFree(list);
    }
  }
  else 
#endif // WINCE
  {

    OPENFILENAMEW ofn;
    memset(&ofn, 0, sizeof(ofn));

    ofn.lStructSize = sizeof(ofn);

    nsString filterBuffer = mFilterList;
                                  
    if (!initialDir.IsEmpty()) {
      ofn.lpstrInitialDir = initialDir.get();
    }
    
    ofn.lpstrTitle   = (LPCWSTR)mTitle.get();
    ofn.lpstrFilter  = (LPCWSTR)filterBuffer.get();
    ofn.nFilterIndex = mSelectedType;
    ofn.hwndOwner    = (HWND)
      (mParentWidget.get() ? mParentWidget->GetNativeData(NS_NATIVE_WINDOW) : 0); 
    ofn.lpstrFile    = fileBuffer;
    ofn.nMaxFile     = FILE_BUFFER_SIZE;

    ofn.Flags = OFN_NOCHANGEDIR | OFN_SHAREAWARE | OFN_LONGNAMES | OFN_OVERWRITEPROMPT | OFN_HIDEREADONLY | OFN_PATHMUSTEXIST;

    if (!mDefaultExtension.IsEmpty()) {
      ofn.lpstrDefExt = mDefaultExtension.get();
    }
    else {
      // Get file extension from suggested filename
      //  to detect if we are saving an html file
      //XXX: nsIFile SHOULD HAVE A GetExtension() METHOD!
      PRInt32 extIndex = mDefault.RFind(".");
      if ( extIndex >= 0) {
        nsAutoString ext;
        mDefault.Right(ext, mDefault.Length() - extIndex);
        // Should we test for ".cgi", ".asp", ".jsp" and other
        // "generated" html pages?

        if ( ext.LowerCaseEqualsLiteral(".htm")  ||
             ext.LowerCaseEqualsLiteral(".html") ||
             ext.LowerCaseEqualsLiteral(".shtml") ) {
          // This is supposed to append ".htm" if user doesn't supply an extension
          //XXX Actually, behavior is sort of weird:
          //    often appends ".html" even if you have an extension
          //    It obeys your extension if you put quotes around name
          ofn.lpstrDefExt = htmExt.get();
        }
      }
    }

#ifndef WINCE
    try {
#endif
      if (mMode == modeOpen) {
        // FILE MUST EXIST!
        ofn.Flags |= OFN_FILEMUSTEXIST;
        result = nsToolkit::mGetOpenFileName(&ofn);
      }
      else if (mMode == modeOpenMultiple) {
        ofn.Flags |= OFN_FILEMUSTEXIST | OFN_ALLOWMULTISELECT | OFN_EXPLORER;
        result = nsToolkit::mGetOpenFileName(&ofn);
      }
      else if (mMode == modeSave) {
        ofn.Flags |= OFN_NOREADONLYRETURN;

        // Don't follow shortcuts when saving a shortcut, this can be used
        // to trick users (bug 271732)
        NS_ConvertUTF16toUTF8 ext(mDefault);
        ext.Trim(" .", PR_FALSE, PR_TRUE); // watch out for trailing space and dots
        ToLowerCase(ext);
        if (StringEndsWith(ext, NS_LITERAL_CSTRING(".lnk")) ||
            StringEndsWith(ext, NS_LITERAL_CSTRING(".pif")) ||
            StringEndsWith(ext, NS_LITERAL_CSTRING(".url")))
          ofn.Flags |= OFN_NODEREFERENCELINKS;

        result = nsToolkit::mGetSaveFileName(&ofn);
        if (!result) {
          // Error, find out what kind.
          if (::GetLastError() == ERROR_INVALID_PARAMETER ||
              ::CommDlgExtendedError() == FNERR_INVALIDFILENAME) {
            // probably the default file name is too long or contains illegal characters!
            // Try again, without a starting file name.
            ofn.lpstrFile[0] = 0;
            result = nsToolkit::mGetSaveFileName(&ofn);
          }
        }
      }
      else {
        NS_ASSERTION(0, "unsupported mode"); 
      }
#ifndef WINCE
    }
    catch(...) {
      MessageBox(ofn.hwndOwner,
                 0,
                 "The filepicker was unexpectedly closed by Windows.",
                 MB_ICONERROR);
      result = PR_FALSE;
    }
#endif
  
    if (result == PR_TRUE) {
      // Remember what filter type the user selected
      mSelectedType = (PRInt16)ofn.nFilterIndex;

      // Set user-selected location of file or directory
      if (mMode == modeOpenMultiple) {
        nsresult rv = NS_NewISupportsArray(getter_AddRefs(mFiles));
        NS_ENSURE_SUCCESS(rv,rv);
        
        // from msdn.microsoft.com, "Open and Save As Dialog Boxes" section:
        // If you specify OFN_EXPLORER,
        // The directory and file name strings are NULL separated, 
        // with an extra NULL character after the last file name. 
        // This format enables the Explorer-style dialog boxes
        // to return long file names that include spaces. 
        PRUnichar *current = fileBuffer;
        
        nsAutoString dirName(current);
        // sometimes dirName contains a trailing slash
        // and sometimes it doesn't.
        if (current[dirName.Length() - 1] != '\\')
          dirName.Append((PRUnichar)'\\');
        
        while (current && *current && *(current + nsCRT::strlen(current) + 1)) {
          current = current + nsCRT::strlen(current) + 1;
          
          nsCOMPtr<nsILocalFile> file = do_CreateInstance("@mozilla.org/file/local;1", &rv);
          NS_ENSURE_SUCCESS(rv,rv);
          
          rv = file->InitWithPath(dirName + nsDependentString(current));
          NS_ENSURE_SUCCESS(rv,rv);
          
          rv = mFiles->AppendElement(file);
          NS_ENSURE_SUCCESS(rv,rv);
        }
        
        // handle the case where the user selected just one
        // file.  according to msdn.microsoft.com:
        // If you specify OFN_ALLOWMULTISELECT and the user selects 
        // only one file, the lpstrFile string does not have 
        // a separator between the path and file name.
        if (current && *current && (current == fileBuffer)) {
          nsCOMPtr<nsILocalFile> file = do_CreateInstance("@mozilla.org/file/local;1", &rv);
          NS_ENSURE_SUCCESS(rv,rv);
          
          rv = file->InitWithPath(nsDependentString(current));
          NS_ENSURE_SUCCESS(rv,rv);
          
          rv = mFiles->AppendElement(file);
          NS_ENSURE_SUCCESS(rv,rv);
        }
      }
      else {
        // I think it also needs a conversion here (to unicode since appending to nsString) 
        // but doing that generates garbage file name, weird.
        mUnicodeFile.Assign(fileBuffer);
      }
    }

  }

  if (result) {
    PRInt16 returnOKorReplace = returnOK;

    // Remember last used directory.
    nsCOMPtr<nsILocalFile> file(do_CreateInstance("@mozilla.org/file/local;1"));
    NS_ENSURE_TRUE(file, NS_ERROR_FAILURE);

    // XXX  InitWithPath() will convert UCS2 to FS path !!!  corrupts unicode 
    file->InitWithPath(mUnicodeFile);
    nsCOMPtr<nsIFile> dir;
    if (NS_SUCCEEDED(file->GetParent(getter_AddRefs(dir)))) {
      mDisplayDirectory = do_QueryInterface(dir);
      if (mDisplayDirectory) {
        nsAutoString newDir;
        mDisplayDirectory->GetPath(newDir);
        if(!newDir.IsEmpty())
          mLastUsedUnicodeDirectory.Assign(newDir);
      }
    }

    if (mMode == modeSave) {
      // Windows does not return resultReplace,
      //   we must check if file already exists
      PRBool exists = PR_FALSE;
      file->Exists(&exists);

      if (exists)
        returnOKorReplace = returnReplace;
    }
    *aReturnVal = returnOKorReplace;
  }
  else {
    *aReturnVal = returnCancel;
  }
  if (mParentWidget) {
    nsIWidget *tmp = mParentWidget;
    nsWindow *parent = NS_STATIC_CAST(nsWindow *, tmp);
    parent->SuppressBlurEvents(PR_FALSE);
  }

  return NS_OK;
}

Here is the call graph for this function:

Definition at line 211 of file nsFilePicker.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:


Member Data Documentation

The extension that should be associated with files of the type we want to work with.

On some platforms, this extension will be automatically appended to filenames the user enters, if needed.

Definition at line 109 of file nsIFilePicker.idl.

The filename that should be suggested to the user as a default.

Exceptions:
NS_ERROR_FAILUREon attempts to get

Definition at line 102 of file nsIFilePicker.idl.

Set the directory that the file open/save dialog initially displays.

Parameters:
displayDirectorythe name of the directory

Definition at line 124 of file nsIFilePicker.idl.

Get the nsILocalFile for the file or directory.

Returns:
Returns the file currently selected

Definition at line 132 of file nsIFilePicker.idl.

Get the enumerator for the selected files only works in the modeOpenMultiple mode.

Returns:
Returns the files currently selected

Definition at line 147 of file nsIFilePicker.idl.

Get the nsIFileURL for the file or directory.

Returns:
Returns the file currently selected

Definition at line 139 of file nsIFilePicker.idl.

const long nsIFilePicker::filterAll = 0x01 [inherited]

Definition at line 59 of file nsIFilePicker.idl.

const long nsIFilePicker::filterApps = 0x40 [inherited]

Definition at line 65 of file nsIFilePicker.idl.

const long nsIFilePicker::filterHTML = 0x02 [inherited]

Definition at line 60 of file nsIFilePicker.idl.

Definition at line 62 of file nsIFilePicker.idl.

The filter which is currently selected in the File Picker dialog.

Returns:
Returns the index (0 based) of the selected filter in the filter list.

Definition at line 116 of file nsIFilePicker.idl.

const long nsIFilePicker::filterText = 0x04 [inherited]

Definition at line 61 of file nsIFilePicker.idl.

const long nsIFilePicker::filterXML = 0x10 [inherited]

Definition at line 63 of file nsIFilePicker.idl.

const long nsIFilePicker::filterXUL = 0x20 [inherited]

Definition at line 64 of file nsIFilePicker.idl.

Definition at line 108 of file nsFilePicker.h.

Definition at line 109 of file nsFilePicker.h.

Definition at line 105 of file nsFilePicker.h.

Definition at line 92 of file nsFilePicker.h.

QFileDialog* nsFilePicker::mDialog [protected]

Definition at line 79 of file nsFilePicker.h.

Definition at line 76 of file nsBaseFilePicker.h.

Definition at line 104 of file nsFilePicker.h.

Definition at line 85 of file nsFilePicker.h.

Definition at line 110 of file nsFilePicker.h.

Definition at line 106 of file nsFilePicker.h.

nsCStringArray nsFilePicker::mFilterNames [protected]

Definition at line 95 of file nsFilePicker.h.

nsCStringArray nsFilePicker::mFilters [protected]

Definition at line 94 of file nsFilePicker.h.

nsStringArray nsFilePicker::mFilters [protected]

Definition at line 115 of file nsFilePicker.h.

nsCStringArray nsFilePicker::mFlatFilters [protected]

Definition at line 117 of file nsFilePicker.h.

PRLibrary * nsFilePicker::mGTK24 = nsnull [static, private]

Definition at line 99 of file nsFilePicker.h.

static char nsFilePicker::mLastUsedDirectory = { 0 } [static, protected]

Definition at line 113 of file nsFilePicker.h.

Definition at line 99 of file nsFilePicker.h.

Definition at line 103 of file nsFilePicker.h.

const short nsIFilePicker::modeGetFolder = 2 [inherited]

Definition at line 52 of file nsIFilePicker.idl.

const short nsIFilePicker::modeOpen = 0 [inherited]

Definition at line 50 of file nsIFilePicker.idl.

const short nsIFilePicker::modeOpenMultiple = 3 [inherited]

Definition at line 53 of file nsIFilePicker.idl.

const short nsIFilePicker::modeSave = 1 [inherited]

Definition at line 51 of file nsIFilePicker.idl.

Definition at line 84 of file nsFilePicker.h.

PtWidget_t* nsFilePicker::mParentWidget [protected]

Definition at line 84 of file nsFilePicker.h.

BWindow* nsFilePicker::mParentWindow [protected]

Definition at line 101 of file nsFilePicker.h.

Definition at line 98 of file nsFilePicker.h.

Definition at line 109 of file nsFilePicker.h.

Definition at line 123 of file nsFilePicker.h.

Definition at line 102 of file nsFilePicker.h.

nsStringArray nsFilePicker::mTitles [protected]

Definition at line 116 of file nsFilePicker.h.

NavTypeListPtr nsFilePicker::mTypeLists[kMaxTypeListCount] [protected]

Definition at line 119 of file nsFilePicker.h.

Definition at line 124 of file nsFilePicker.h.

Definition at line 108 of file nsFilePicker.h.

Definition at line 107 of file nsFilePicker.h.

Definition at line 98 of file nsFilePicker.h.

HWND nsFilePicker::mWnd [protected]

Definition at line 89 of file nsFilePicker.h.

const short nsIFilePicker::returnCancel = 1 [inherited]

Definition at line 56 of file nsIFilePicker.idl.

const short nsIFilePicker::returnOK = 0 [inherited]

Definition at line 55 of file nsIFilePicker.idl.

const short nsIFilePicker::returnReplace = 2 [inherited]

Definition at line 57 of file nsIFilePicker.idl.

Definition at line 121 of file nsFilePicker.h.


The documentation for this class was generated from the following files: