Back to index

lightning-sunbird  0.9+nobinonly
HelperAppDlg.h
Go to the documentation of this file.
00001 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
00002 /* ***** BEGIN LICENSE BLOCK *****
00003  * Version: Mozilla-sample-code 1.0
00004  *
00005  * Copyright (c) 2002 Netscape Communications Corporation and
00006  * other contributors
00007  *
00008  * Permission is hereby granted, free of charge, to any person obtaining a
00009  * copy of this Mozilla sample software and associated documentation files
00010  * (the "Software"), to deal in the Software without restriction, including
00011  * without limitation the rights to use, copy, modify, merge, publish,
00012  * distribute, sublicense, and/or sell copies of the Software, and to permit
00013  * persons to whom the Software is furnished to do so, subject to the
00014  * following conditions:
00015  *
00016  * The above copyright notice and this permission notice shall be included
00017  * in all copies or substantial portions of the Software.
00018  *
00019  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
00020  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
00021  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
00022  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
00023  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
00024  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
00025  * DEALINGS IN THE SOFTWARE.
00026  *
00027  * Contributor(s):
00028  *   Chak Nanga <chak@netscape.com>
00029  *
00030  * ***** END LICENSE BLOCK ***** */
00031 
00032 #ifndef __HelperAppDlg_h
00033 #define __HelperAppDlg_h
00034 
00035 #include "nsError.h"
00036 #include "resource.h"
00037 #include "nsIFactory.h"
00038 #include "nsIExternalHelperAppService.h"
00039 #include "nsIHelperAppLauncherDialog.h"
00040 #include "nsIWebProgressListener.h"
00041 #include "nsWeakReference.h"
00042 #include "nsIWindowWatcher.h"
00043 
00044 // this component is for an MFC app; it's Windows. make sure this is defined.
00045 #ifndef XP_WIN
00046 #define XP_WIN
00047 #endif
00048 
00049 class CHelperAppLauncherDialogFactory : public nsIFactory {
00050 public:
00051     NS_DECL_ISUPPORTS
00052     NS_DECL_NSIFACTORY
00053 
00054     CHelperAppLauncherDialogFactory();
00055     virtual ~CHelperAppLauncherDialogFactory();
00056 };
00057 
00058 enum {
00059     CONTENT_SAVE_TO_DISK,
00060     CONTENT_LAUNCH_WITH_APP
00061 };
00062 
00063 // This class implements the nsIHelperAppLauncherDialog interface
00064 //
00065 class CHelperAppLauncherDialog : public nsIHelperAppLauncherDialog {
00066 public:
00067     CHelperAppLauncherDialog();
00068     virtual ~CHelperAppLauncherDialog();
00069 
00070     NS_DECL_ISUPPORTS
00071     NS_DECL_NSIHELPERAPPLAUNCHERDIALOG
00072 
00073     int m_HandleContentOp;
00074     CString m_FileName;
00075 
00076 private:
00077   nsCOMPtr<nsIWindowWatcher> mWWatch;
00078   CWnd* GetParentFromContext(nsISupports *aWindowContext);
00079 };
00080 
00081 // This class implements a download progress dialog
00082 // which displays the progress of a file download
00083 //
00084 class CProgressDlg : public CDialog, 
00085                      public nsIWebProgressListener,
00086                      public nsSupportsWeakReference
00087 {
00088 public:
00089     enum { IDD = IDD_PROGRESS_DIALOG };
00090 
00091     CProgressDlg(nsIHelperAppLauncher *aLauncher, int aHandleContentOp,
00092                 CString& aFileName, CWnd* pParent = NULL);
00093     virtual ~CProgressDlg();
00094 
00095     int m_HandleContentOp;
00096     CString m_FileName;
00097     CStatic   m_SavingFrom;
00098     CStatic   m_Action;
00099     CProgressCtrl m_ProgressCtrl;
00100 
00101     nsCOMPtr<nsIHelperAppLauncher> m_HelperAppLauncher;
00102 
00103     NS_DECL_ISUPPORTS
00104     NS_DECL_NSIWEBPROGRESSLISTENER
00105 
00106 protected:
00107     virtual void DoDataExchange(CDataExchange* pDX);
00108     virtual BOOL OnInitDialog();
00109     virtual void OnCancel();
00110 
00111        DECLARE_MESSAGE_MAP()
00112 };
00113 
00114 // This class implements a dialog box which gives the user
00115 // a choice of saving the content being downloaded to disk
00116 // or to open with an external application
00117 //
00118 class CChooseActionDlg : public CDialog
00119 {
00120 public:
00121     CChooseActionDlg(nsIHelperAppLauncher* aLauncher, CWnd* pParent = NULL);
00122 
00123     enum { IDD = IDD_CHOOSE_ACTION_DIALOG };
00124     CStatic   m_ContentType;
00125 
00126     int m_ActionChosen;
00127     CString m_OpenWithAppName;
00128     nsCOMPtr<nsIHelperAppLauncher> m_HelperAppLauncher;
00129 
00130 protected:
00131        virtual void DoDataExchange(CDataExchange* pDX);
00132 
00133 protected:
00134     virtual BOOL OnInitDialog();
00135     afx_msg void OnChooseAppClicked();
00136     virtual void OnOK();
00137     virtual void OnCancel();
00138     afx_msg void OnOpenUsingRadioBtnClicked();
00139     afx_msg void OnSaveToDiskRadioBtnClicked();
00140 
00141     void EnableAppName(BOOL bEnable);
00142     void EnableChooseBtn(BOOL bEnable);
00143     void InitWithPreferredAction(nsIMIMEInfo* aMimeInfo);
00144     void SelectSaveToDiskOption();
00145     void SelectOpenUsingAppOption();
00146     void UpdateAppNameField(CString& appName);
00147 
00148     DECLARE_MESSAGE_MAP()
00149 };
00150 
00151 #endif