jdk/src/windows/native/sun/jkernel/DownloadDialog.h
changeset 8197 e45f21c2a40b
parent 7867 f83cd8bd35c6
child 8198 aca2f99e4b52
equal deleted inserted replaced
7867:f83cd8bd35c6 8197:e45f21c2a40b
     1 /*
       
     2  * Copyright (c) 2008, 2009, Oracle and/or its affiliates. All rights reserved.
       
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
       
     4  *
       
     5  * This code is free software; you can redistribute it and/or modify it
       
     6  * under the terms of the GNU General Public License version 2 only, as
       
     7  * published by the Free Software Foundation.  Oracle designates this
       
     8  * particular file as subject to the "Classpath" exception as provided
       
     9  * by Oracle in the LICENSE file that accompanied this code.
       
    10  *
       
    11  * This code is distributed in the hope that it will be useful, but WITHOUT
       
    12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
       
    13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
       
    14  * version 2 for more details (a copy is included in the LICENSE file that
       
    15  * accompanied this code).
       
    16  *
       
    17  * You should have received a copy of the GNU General Public License version
       
    18  * 2 along with this work; if not, write to the Free Software Foundation,
       
    19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
       
    20  *
       
    21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
       
    22  * or visit www.oracle.com if you need additional information or have any
       
    23  * questions.
       
    24  */
       
    25 
       
    26 //
       
    27 // DownloadDialog.h : Declaration of the CDownloadDialog
       
    28 //
       
    29 
       
    30 #ifndef __DOWNLOADDIALOG_H_
       
    31 #define __DOWNLOADDIALOG_H_
       
    32 
       
    33 #include "resource.h"       // main symbols
       
    34 #include <time.h>
       
    35 #include "jni.h"
       
    36 
       
    37 #ifndef BUFFER_SIZE
       
    38 #define BUFFER_SIZE 2048
       
    39 #endif
       
    40 
       
    41 #define iTimerID    1000
       
    42 #define destroyWindowTimerID    2000
       
    43 
       
    44 #define E_JDHELPER_TIMEOUT               12002
       
    45 #define E_JDHELPER_NAME_NOT_RESOLVED     12007
       
    46 #define E_JDHELPER_CANNOT_CONNECT        12029
       
    47 
       
    48 /* Following lines were copied from the new version of commctrl.h
       
    49    These definitions are not available in default version of
       
    50    this header file in VS 2003 but they are needed to use
       
    51    new Vista task dialog API.
       
    52 */
       
    53 #ifndef TD_ERROR_ICON
       
    54 
       
    55 /* These modifiers have sense with new VS only,
       
    56    reset them to get code to compile */
       
    57 #define __in
       
    58 #define __in_opt
       
    59 #define __out_opt
       
    60 
       
    61 #ifdef _WIN32
       
    62 #include <pshpack1.h>
       
    63 #endif
       
    64 
       
    65 
       
    66 typedef HRESULT (CALLBACK *PFTASKDIALOGCALLBACK)(HWND hwnd, __in UINT msg, __in WPARAM wParam, __in LPARAM lParam, __in LONG_PTR lpRefData);
       
    67 
       
    68 enum _TASKDIALOG_FLAGS
       
    69 {
       
    70     TDF_ENABLE_HYPERLINKS               = 0x0001,
       
    71     TDF_USE_HICON_MAIN                  = 0x0002,
       
    72     TDF_USE_HICON_FOOTER                = 0x0004,
       
    73     TDF_ALLOW_DIALOG_CANCELLATION       = 0x0008,
       
    74     TDF_USE_COMMAND_LINKS               = 0x0010,
       
    75     TDF_USE_COMMAND_LINKS_NO_ICON       = 0x0020,
       
    76     TDF_EXPAND_FOOTER_AREA              = 0x0040,
       
    77     TDF_EXPANDED_BY_DEFAULT             = 0x0080,
       
    78     TDF_VERIFICATION_FLAG_CHECKED       = 0x0100,
       
    79     TDF_SHOW_PROGRESS_BAR               = 0x0200,
       
    80     TDF_SHOW_MARQUEE_PROGRESS_BAR       = 0x0400,
       
    81     TDF_CALLBACK_TIMER                  = 0x0800,
       
    82     TDF_POSITION_RELATIVE_TO_WINDOW     = 0x1000,
       
    83     TDF_RTL_LAYOUT                      = 0x2000,
       
    84     TDF_NO_DEFAULT_RADIO_BUTTON         = 0x4000,
       
    85     TDF_CAN_BE_MINIMIZED                = 0x8000
       
    86 };
       
    87 typedef int TASKDIALOG_FLAGS;                         // Note: _TASKDIALOG_FLAGS is an int
       
    88 
       
    89 typedef enum _TASKDIALOG_MESSAGES
       
    90 {
       
    91     TDM_NAVIGATE_PAGE                   = WM_USER+101,
       
    92     TDM_CLICK_BUTTON                    = WM_USER+102, // wParam = Button ID
       
    93     TDM_SET_MARQUEE_PROGRESS_BAR        = WM_USER+103, // wParam = 0 (nonMarque) wParam != 0 (Marquee)
       
    94     TDM_SET_PROGRESS_BAR_STATE          = WM_USER+104, // wParam = new progress state
       
    95     TDM_SET_PROGRESS_BAR_RANGE          = WM_USER+105, // lParam = MAKELPARAM(nMinRange, nMaxRange)
       
    96     TDM_SET_PROGRESS_BAR_POS            = WM_USER+106, // wParam = new position
       
    97     TDM_SET_PROGRESS_BAR_MARQUEE        = WM_USER+107, // wParam = 0 (stop marquee), wParam != 0 (start marquee), lparam = speed (milliseconds between repaints)
       
    98     TDM_SET_ELEMENT_TEXT                = WM_USER+108, // wParam = element (TASKDIALOG_ELEMENTS), lParam = new element text (LPCWSTR)
       
    99     TDM_CLICK_RADIO_BUTTON              = WM_USER+110, // wParam = Radio Button ID
       
   100     TDM_ENABLE_BUTTON                   = WM_USER+111, // lParam = 0 (disable), lParam != 0 (enable), wParam = Button ID
       
   101     TDM_ENABLE_RADIO_BUTTON             = WM_USER+112, // lParam = 0 (disable), lParam != 0 (enable), wParam = Radio Button ID
       
   102     TDM_CLICK_VERIFICATION              = WM_USER+113, // wParam = 0 (unchecked), 1 (checked), lParam = 1 (set key focus)
       
   103     TDM_UPDATE_ELEMENT_TEXT             = WM_USER+114, // wParam = element (TASKDIALOG_ELEMENTS), lParam = new element text (LPCWSTR)
       
   104     TDM_SET_BUTTON_ELEVATION_REQUIRED_STATE = WM_USER+115, // wParam = Button ID, lParam = 0 (elevation not required), lParam != 0 (elevation required)
       
   105     TDM_UPDATE_ICON                     = WM_USER+116  // wParam = icon element (TASKDIALOG_ICON_ELEMENTS), lParam = new icon (hIcon if TDF_USE_HICON_* was set, PCWSTR otherwise)
       
   106 } TASKDIALOG_MESSAGES;
       
   107 
       
   108 typedef enum _TASKDIALOG_NOTIFICATIONS
       
   109 {
       
   110     TDN_CREATED                         = 0,
       
   111     TDN_NAVIGATED                       = 1,
       
   112     TDN_BUTTON_CLICKED                  = 2,            // wParam = Button ID
       
   113     TDN_HYPERLINK_CLICKED               = 3,            // lParam = (LPCWSTR)pszHREF
       
   114     TDN_TIMER                           = 4,            // wParam = Milliseconds since dialog created or timer reset
       
   115     TDN_DESTROYED                       = 5,
       
   116     TDN_RADIO_BUTTON_CLICKED            = 6,            // wParam = Radio Button ID
       
   117     TDN_DIALOG_CONSTRUCTED              = 7,
       
   118     TDN_VERIFICATION_CLICKED            = 8,             // wParam = 1 if checkbox checked, 0 if not, lParam is unused and always 0
       
   119     TDN_HELP                            = 9,
       
   120     TDN_EXPANDO_BUTTON_CLICKED          = 10            // wParam = 0 (dialog is now collapsed), wParam != 0 (dialog is now expanded)
       
   121 } TASKDIALOG_NOTIFICATIONS;
       
   122 
       
   123 typedef struct _TASKDIALOG_BUTTON
       
   124 {
       
   125     int     nButtonID;
       
   126     PCWSTR  pszButtonText;
       
   127 } TASKDIALOG_BUTTON;
       
   128 
       
   129 typedef enum _TASKDIALOG_ELEMENTS
       
   130 {
       
   131     TDE_CONTENT,
       
   132     TDE_EXPANDED_INFORMATION,
       
   133     TDE_FOOTER,
       
   134     TDE_MAIN_INSTRUCTION
       
   135 } TASKDIALOG_ELEMENTS;
       
   136 
       
   137 typedef enum _TASKDIALOG_ICON_ELEMENTS
       
   138 {
       
   139     TDIE_ICON_MAIN,
       
   140     TDIE_ICON_FOOTER
       
   141 } TASKDIALOG_ICON_ELEMENTS;
       
   142 
       
   143 #define TD_WARNING_ICON         MAKEINTRESOURCEW(-1)
       
   144 #define TD_ERROR_ICON           MAKEINTRESOURCEW(-2)
       
   145 #define TD_INFORMATION_ICON     MAKEINTRESOURCEW(-3)
       
   146 #define TD_SHIELD_ICON          MAKEINTRESOURCEW(-4)
       
   147 
       
   148 
       
   149 enum _TASKDIALOG_COMMON_BUTTON_FLAGS
       
   150 {
       
   151     TDCBF_OK_BUTTON            = 0x0001, // selected control return value IDOK
       
   152     TDCBF_YES_BUTTON           = 0x0002, // selected control return value IDYES
       
   153     TDCBF_NO_BUTTON            = 0x0004, // selected control return value IDNO
       
   154     TDCBF_CANCEL_BUTTON        = 0x0008, // selected control return value IDCANCEL
       
   155     TDCBF_RETRY_BUTTON         = 0x0010, // selected control return value IDRETRY
       
   156     TDCBF_CLOSE_BUTTON         = 0x0020  // selected control return value IDCLOSE
       
   157 };
       
   158 typedef int TASKDIALOG_COMMON_BUTTON_FLAGS;           // Note: _TASKDIALOG_COMMON_BUTTON_FLAGS is an int
       
   159 
       
   160 typedef struct _TASKDIALOGCONFIG
       
   161 {
       
   162     UINT        cbSize;
       
   163     HWND        hwndParent;
       
   164     HINSTANCE   hInstance;                              // used for MAKEINTRESOURCE() strings
       
   165     TASKDIALOG_FLAGS                dwFlags;            // TASKDIALOG_FLAGS (TDF_XXX) flags
       
   166     TASKDIALOG_COMMON_BUTTON_FLAGS  dwCommonButtons;    // TASKDIALOG_COMMON_BUTTON (TDCBF_XXX) flags
       
   167     PCWSTR      pszWindowTitle;                         // string or MAKEINTRESOURCE()
       
   168     union
       
   169     {
       
   170         HICON   hMainIcon;
       
   171         PCWSTR  pszMainIcon;
       
   172     };
       
   173     PCWSTR      pszMainInstruction;
       
   174     PCWSTR      pszContent;
       
   175     UINT        cButtons;
       
   176     const TASKDIALOG_BUTTON  *pButtons;
       
   177     int         nDefaultButton;
       
   178     UINT        cRadioButtons;
       
   179     const TASKDIALOG_BUTTON  *pRadioButtons;
       
   180     int         nDefaultRadioButton;
       
   181     PCWSTR      pszVerificationText;
       
   182     PCWSTR      pszExpandedInformation;
       
   183     PCWSTR      pszExpandedControlText;
       
   184     PCWSTR      pszCollapsedControlText;
       
   185     union
       
   186     {
       
   187         HICON   hFooterIcon;
       
   188         PCWSTR  pszFooterIcon;
       
   189     };
       
   190     PCWSTR      pszFooter;
       
   191     PFTASKDIALOGCALLBACK pfCallback;
       
   192     LONG_PTR    lpCallbackData;
       
   193     UINT        cxWidth;                                // width of the Task Dialog's client area in DLU's. If 0, Task Dialog will calculate the ideal width.
       
   194 } TASKDIALOGCONFIG;
       
   195 
       
   196 WINCOMMCTRLAPI HRESULT WINAPI TaskDialogIndirect(const TASKDIALOGCONFIG *pTaskConfig, __out_opt int *pnButton, __out_opt int *pnRadioButton, __out_opt BOOL *pfVerificationFlagChecked);
       
   197 WINCOMMCTRLAPI HRESULT WINAPI TaskDialog(__in_opt HWND hwndParent, __in_opt HINSTANCE hInstance, __in_opt PCWSTR pszWindowTitle, __in_opt PCWSTR pszMainInstruction, __in_opt PCWSTR pszContent, TASKDIALOG_COMMON_BUTTON_FLAGS dwCommonButtons, __in_opt PCWSTR pszIcon, __out_opt int *pnButton);
       
   198 
       
   199 #ifdef _WIN32
       
   200 #include <poppack.h>
       
   201 #endif
       
   202 
       
   203 #endif /* end of copy from commctrl.h */
       
   204 
       
   205 typedef HRESULT (WINAPI *TaskDialogIndirectFn) (const TASKDIALOGCONFIG *pTaskConfig, __out_opt int *pnButton, __out_opt int *pnRadioButton, __out_opt BOOL *pfVerificationFlagChecked);
       
   206 
       
   207 typedef enum {
       
   208     DIALOG_ERROR_RETRYCANCEL = 0,
       
   209     DIALOG_WARNING_CANCELOK
       
   210 } DialogType;
       
   211 
       
   212 
       
   213 /////////////////////////////////////////////////////////////////////////////
       
   214 // CDownloadDialog
       
   215 class CDownloadDialog :
       
   216         public CAxDialogImpl<CDownloadDialog>
       
   217 {
       
   218 public:
       
   219         CDownloadDialog();
       
   220         ~CDownloadDialog();
       
   221 
       
   222         enum { IDD = IDD_DOWNLOAD_DIALOG };
       
   223 
       
   224 BEGIN_MSG_MAP(CDownloadDialog)
       
   225         MESSAGE_HANDLER(WM_INITDIALOG, OnInitDialog)
       
   226         MESSAGE_HANDLER(WM_TIMER, OnTimer)
       
   227         MESSAGE_HANDLER(WM_CTLCOLORSTATIC, OnCtlColorStatic)
       
   228         COMMAND_ID_HANDLER(IDOK, OnOK)
       
   229         COMMAND_ID_HANDLER(IDCANCEL, OnCancel)
       
   230 END_MSG_MAP()
       
   231 
       
   232         LRESULT OnInitDialog(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
       
   233         LRESULT OnOK(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled);
       
   234         LRESULT OnCancel(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled);
       
   235         LRESULT OnTimer(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
       
   236         LRESULT OnCtlColorStatic(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
       
   237 
       
   238         STDMETHODIMP OnStartBinding();
       
   239 
       
   240         STDMETHODIMP OnProgress(ULONG ulProgress);
       
   241 
       
   242         void initDialogText(LPCTSTR pszDownloadURL, LPCTSTR pszBundleName);
       
   243 
       
   244         BOOL isDownloading();
       
   245         BOOL isDownloadCancelled();
       
   246 
       
   247         void addToTotalContentLength(DWORD contentLength);
       
   248 
       
   249         void decrementProgressMax(ULONG contentLength, ULONG readSoFar);
       
   250 
       
   251         void bundleInstallStart();
       
   252         void bundleInstallComplete();
       
   253 
       
   254         void waitUntilInitialized();
       
   255 
       
   256         void log(char *msg);
       
   257         void logProgress();
       
   258 
       
   259         void setFile(LPCTSTR pszFileName)
       
   260         {
       
   261             m_pszFileName = pszFileName;
       
   262         }
       
   263 
       
   264         void setURL(LPCTSTR pszURL)
       
   265         {
       
   266             m_pszURL = pszURL;
       
   267         }
       
   268 
       
   269         void setNameText(LPTSTR pszNameText)
       
   270         {
       
   271             m_pszNameText = pszNameText;
       
   272         }
       
   273 
       
   274 
       
   275         JNIEnv* getJNIEnv();
       
   276 
       
   277 
       
   278         void setJavaVM(JavaVM *jvm)
       
   279         {
       
   280             m_jvm = jvm;
       
   281         }
       
   282 
       
   283 
       
   284         HRESULT DownloadConfiguration(LPTSTR pszConfigURL, LPTSTR pszConfigFile);
       
   285 
       
   286         void delayedDoModal();
       
   287 
       
   288         int SafeMessageBox(UINT details, UINT mainInstruction, UINT caption,
       
   289                            DialogType type, LPCWSTR instructionArg = NULL,
       
   290                            LPCWSTR detailsArg = NULL);
       
   291 
       
   292         void destroyDialog();
       
   293 
       
   294     private:
       
   295 
       
   296         HFONT CreateDialogFont (HDC hdc, LPCTSTR lpszFaceName, int ptSize, int isBold = 0);
       
   297         void  FreeGDIResources ();
       
   298 
       
   299         BOOL                    m_feedbackOnCancel;
       
   300         TaskDialogIndirectFn    taskDialogFn;
       
   301         LPCTSTR                 m_pszFileName;
       
   302         LPCTSTR                 m_pszURL;
       
   303         time_t                  m_startTime;
       
   304         ULONG                   m_ulProgress;
       
   305         ULONG                   m_ulProgressMax;
       
   306         int                     m_iProgressFactor;
       
   307         int                     m_iMaxProgressFactor;
       
   308         int                     m_numDownloadThreadsRunning;
       
   309         BOOL            m_destroyWindowTimerStarted;
       
   310         volatile BOOL           m_dialogUp;
       
   311         CComAutoCriticalSection m_csDownload;
       
   312         CComAutoCriticalSection m_csNumDownloadThreads;
       
   313         HANDLE                  m_hCancelEvent;
       
   314         HANDLE                  m_hDownloadThreadExitEvent;
       
   315         HANDLE                  m_hDialogInitializedEvent;
       
   316         HFONT                   m_hMastheadFont;
       
   317         HFONT                   m_hDialogFont;
       
   318         HFONT                   m_hSixPointFont;
       
   319         LPTSTR                  m_pszNameText;
       
   320         BITMAP                  m_bmMasthead;
       
   321         HBITMAP                 m_hBitmap;
       
   322         HDC                     m_hMemDC;
       
   323         TCHAR                   m_szUrlPath[BUFFER_SIZE];
       
   324         TCHAR                   m_szHostName[BUFFER_SIZE];
       
   325         JavaVM*                 m_jvm;
       
   326         CComAutoCriticalSection m_csMessageBox;
       
   327 };
       
   328 
       
   329 #endif //__DOWNLOADDIALOG_H_