Back to index

lightning-sunbird  0.9+nobinonly
nsFilePicker.h
Go to the documentation of this file.
00001 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
00002  *
00003  * ***** BEGIN LICENSE BLOCK *****
00004  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
00005  *
00006  * The contents of this file are subject to the Mozilla Public License Version
00007  * 1.1 (the "License"); you may not use this file except in compliance with
00008  * the License. You may obtain a copy of the License at
00009  * http://www.mozilla.org/MPL/
00010  *
00011  * Software distributed under the License is distributed on an "AS IS" basis,
00012  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
00013  * for the specific language governing rights and limitations under the
00014  * License.
00015  *
00016  * The Original Code is the Mozilla browser.
00017  *
00018  * The Initial Developer of the Original Code is
00019  * Netscape Communications Corporation.
00020  * Portions created by the Initial Developer are Copyright (C) 2001
00021  * the Initial Developer. All Rights Reserved.
00022  *
00023  * Contributor(s):
00024  *   Makoto Hamanaka <VYA04230@nifty.com>
00025  *   Paul Ashford <arougthopher@lizardland.net>
00026  *   Sergei Dolgov <sergei_d@fi.tartu.ee>
00027  *
00028  * Alternatively, the contents of this file may be used under the terms of
00029  * either the GNU General Public License Version 2 or later (the "GPL"), or
00030  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
00031  * in which case the provisions of the GPL or the LGPL are applicable instead
00032  * of those above. If you wish to allow use of your version of this file only
00033  * under the terms of either the GPL or the LGPL, and not to allow others to
00034  * use your version of this file under the terms of the MPL, indicate your
00035  * decision by deleting the provisions above and replace them with the notice
00036  * and other provisions required by the GPL or the LGPL. If you do not delete
00037  * the provisions above, a recipient may use your version of this file under
00038  * the terms of any one of the MPL, the GPL or the LGPL.
00039  *
00040  * ***** END LICENSE BLOCK ***** */
00041 
00042 #ifndef nsFilePicker_h__
00043 #define nsFilePicker_h__
00044 
00045 #ifndef DEBUG
00046 // XXX adding mLastUsedDirectory and code for handling last used folder on File Open/Save
00047 // caused crashes in DEBUG builds on some machines - see comments for bug 177720 
00048 // works well on "normal" builds
00049 #define FILEPICKER_SAVE_LAST_DIR 1
00050 #endif
00051 
00052 #include "nsICharsetConverterManager.h"
00053 #include "nsBaseFilePicker.h"
00054 #include "nsString.h"
00055 #include "nsdefs.h"
00056 #include "nsIFileChannel.h"
00057 #include "nsILocalFile.h"
00058 #include "nsISimpleEnumerator.h"
00059 #include "nsISupportsArray.h"
00060 #include "nsIAppShell.h"
00061 #include "nsIAppShellService.h"
00062 #include "nsIServiceManager.h"
00063 
00064 //
00065 // Native BeOS FileSelector wrapper
00066 //
00067 
00068 #include <StorageKit.h>
00069 #include <Message.h>
00070 #include <Window.h>
00071 #include <String.h>
00072 class BButton;
00073 
00074 class nsFilePicker : public nsBaseFilePicker, public BLooper
00075 {
00076 public:
00077   NS_DECL_ISUPPORTS
00078 
00079   nsFilePicker();
00080   virtual ~nsFilePicker();
00081 
00082   // nsIFilePicker (less what's in nsBaseFilePicker)
00083   NS_IMETHOD GetDefaultString(nsAString& aDefaultString);
00084   NS_IMETHOD SetDefaultString(const nsAString& aDefaultString);
00085   NS_IMETHOD GetDefaultExtension(nsAString& aDefaultExtension);
00086   NS_IMETHOD SetDefaultExtension(const nsAString& aDefaultExtension);
00087   NS_IMETHOD GetFile(nsILocalFile * *aFile);
00088   NS_IMETHOD GetFileURL(nsIFileURL * *aFileURL);
00089   NS_IMETHOD GetFiles(nsISimpleEnumerator **aFiles);
00090   NS_IMETHOD Show(PRInt16 *_retval);
00091   NS_IMETHOD AppendFilter(const nsAString& aTitle, const nsAString& aFilter);
00092 
00093 protected:
00094   // method from nsBaseFilePicker
00095   virtual void InitNative(nsIWidget *aParent, const nsAString& aTitle,
00096                           PRInt16 aMode);
00097 
00098 
00099   void GetFilterListArray(nsString& aFilterList);
00100 
00101   BWindow*                      mParentWindow;
00102   nsString                      mTitle;
00103   PRInt16                       mMode;
00104   nsCString                     mFile;
00105   nsString                      mDefault;
00106   nsString                      mFilterList;
00107   nsIUnicodeEncoder*            mUnicodeEncoder;
00108   nsIUnicodeDecoder*            mUnicodeDecoder;
00109   PRInt16                       mSelectedType;
00110   nsCOMPtr <nsISupportsArray>   mFiles;
00111 
00112 #ifdef FILEPICKER_SAVE_LAST_DIR
00113   static char                      mLastUsedDirectory[];
00114 #endif
00115 };
00116 
00117 class nsFilePanelBeOS : public BLooper, public BFilePanel
00118 {
00119 public:
00120   nsFilePanelBeOS(file_panel_mode mode,
00121                   uint32 node_flavors,
00122                   bool allow_multiple_selection,
00123                   bool modal,
00124                   bool hide_when_done);
00125   virtual ~nsFilePanelBeOS();
00126 
00127   virtual void MessageReceived(BMessage *message);
00128   virtual bool SelectionDone();
00129 
00130   virtual void SelectionChanged();
00131 
00132   virtual bool IsOpenSelected() {
00133     return (SelectedActivity() == OPEN_SELECTED);
00134   }
00135   virtual bool IsSaveSelected() {
00136     return (SelectedActivity() == SAVE_SELECTED);
00137   }
00138   virtual bool IsCancelSelected() {
00139     return (SelectedActivity() == CANCEL_SELECTED);
00140   }
00141   virtual uint32 SelectedActivity();
00142 
00143   virtual BList *OpenRefs() { return &mOpenRefs; }
00144   virtual BString SaveFileName() { return mSaveFileName; }
00145   virtual entry_ref SaveDirRef() { return mSaveDirRef; }
00146 
00147   enum {
00148       NOT_SELECTED    = 0,
00149       OPEN_SELECTED   = 1,
00150       SAVE_SELECTED   = 2,
00151       CANCEL_SELECTED = 3
00152   };
00153 
00154 protected:
00155   BButton *mDirectoryButton;
00156   uint32 mSelectedActivity;
00157   bool mIsSelected;
00158   BString mSaveFileName;
00159   entry_ref mSaveDirRef;
00160   BList mOpenRefs;
00161 };
00162 
00163 #endif // nsFilePicker_h__