Back to index

lightning-sunbird  0.9+nobinonly
dialogs.cpp
Go to the documentation of this file.
00001 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
00002 /* ***** BEGIN LICENSE BLOCK *****
00003  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
00004  *
00005  * The contents of this file are subject to the Mozilla Public License Version
00006  * 1.1 (the "License"); you may not use this file except in compliance with
00007  * the License. You may obtain a copy of the License at
00008  * http://www.mozilla.org/MPL/
00009  *
00010  * Software distributed under the License is distributed on an "AS IS" basis,
00011  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
00012  * for the specific language governing rights and limitations under the
00013  * License.
00014  *
00015  * The Original Code is Mozilla Communicator client code.
00016  *
00017  * The Initial Developer of the Original Code is
00018  * Netscape Communications Corporation.
00019  * Portions created by the Initial Developer are Copyright (C) 1998
00020  * the Initial Developer. All Rights Reserved.
00021  *
00022  * Contributor(s):
00023  *
00024  * Alternatively, the contents of this file may be used under the terms of
00025  * either the GNU General Public License Version 2 or later (the "GPL"), or
00026  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
00027  * in which case the provisions of the GPL or the LGPL are applicable instead
00028  * of those above. If you wish to allow use of your version of this file only
00029  * under the terms of either the GPL or the LGPL, and not to allow others to
00030  * use your version of this file under the terms of the MPL, indicate your
00031  * decision by deleting the provisions above and replace them with the notice
00032  * and other provisions required by the GPL or the LGPL. If you do not delete
00033  * the provisions above, a recipient may use your version of this file under
00034  * the terms of any one of the MPL, the GPL or the LGPL.
00035  *
00036  * ***** END LICENSE BLOCK ***** */
00037 
00038 #include <windows.h>
00039 #include <windowsx.h>
00040 #include <assert.h>
00041 
00042 #include "resource.h"
00043 
00044 #include "plugin.h"
00045 #include "utils.h"
00046 
00047 static void onCommand(HWND hWnd, int id, HWND hWndCtl, UINT codeNotify)
00048 {
00049   CPlugin * pPlugin = (CPlugin *)GetWindowLong(hWnd, DWL_USER);
00050   switch (id)
00051   {
00052     case IDC_GET_PLUGIN:
00053       DestroyWindow(hWnd);
00054       if(pPlugin !=NULL)
00055       {
00056         pPlugin->m_hWndDialog = NULL;
00057         pPlugin->getPlugin();
00058       }
00059       break;
00060     case IDCANCEL:
00061     case IDC_BUTTON_CANCEL:
00062       DestroyWindow(hWnd);
00063       if(pPlugin !=NULL)
00064         pPlugin->m_hWndDialog = NULL;
00065       break;
00066     default:
00067       break;
00068   }
00069 }
00070 
00071 static BOOL onInitDialog(HWND hWnd, HWND hWndFocus, LPARAM lParam)
00072 {
00073   CPlugin * pPlugin = (CPlugin *)lParam;
00074   assert(pPlugin != NULL);
00075   if(pPlugin == NULL)
00076     return TRUE;
00077 
00078   SetWindowLong(hWnd, DWL_USER, (LONG)pPlugin);
00079 
00080   pPlugin->m_hWndDialog = hWnd;
00081   
00082   char szString[512];
00083   LoadString(hInst, IDS_TITLE, szString, sizeof(szString));
00084   SetWindowText(hWnd, szString);
00085 
00086   LoadString(hInst, IDS_INFO, szString, sizeof(szString));
00087   SetDlgItemText(hWnd, IDC_STATIC_INFO, szString);
00088 
00089   SetDlgItemText(hWnd, IDC_STATIC_INFOTYPE, (LPSTR)pPlugin->m_pNPMIMEType);
00090 
00091   LoadString(hInst, IDS_LOCATION, szString, sizeof(szString));
00092   SetDlgItemText(hWnd, IDC_STATIC_LOCATION, szString);
00093 
00094   char contentTypeIsJava = 0;
00095 
00096   if (NULL != pPlugin->m_pNPMIMEType) {
00097     contentTypeIsJava = (0 == strcmp("application/x-java-vm",
00098                                  pPlugin->m_pNPMIMEType)) ? 1 : 0;
00099   }
00100   
00101   if(pPlugin->m_szPageURL == NULL || contentTypeIsJava)
00102     LoadString(hInst, IDS_FINDER_PAGE, szString, sizeof(szString));
00103   else
00104     strncpy(szString, pPlugin->m_szPageURL,511); // defect #362738
00105   
00106   SetDlgItemTextWrapped(hWnd, IDC_STATIC_URL, szString);
00107 
00108   LoadString(hInst, IDS_QUESTION, szString, sizeof(szString));
00109   SetDlgItemText(hWnd, IDC_STATIC_QUESTION, szString);
00110 
00111   SetDlgItemText(hWnd, IDC_STATIC_WARNING, "");
00112 
00113   if(!pPlugin->m_bOnline)
00114   {
00115     EnableWindow(GetDlgItem(hWnd, IDC_GET_PLUGIN), FALSE);
00116     LoadString(hInst, IDS_WARNING_OFFLINE, szString, sizeof(szString));
00117     SetDlgItemText(hWnd, IDC_STATIC_WARNING, szString);
00118     SetDlgItemText(hWnd, IDC_STATIC_QUESTION, "");
00119     return TRUE;
00120   }
00121 
00122   if((!pPlugin->m_bJava) || (!pPlugin->m_bJavaScript) || (!pPlugin->m_bSmartUpdate))
00123   {
00124     LoadString(hInst, IDS_WARNING_JS, szString, sizeof(szString));
00125     SetDlgItemText(hWnd, IDC_STATIC_WARNING, szString);
00126     return TRUE;
00127   }
00128 
00129   ShowWindow(GetDlgItem(hWnd, IDC_STATIC_WARNING), SW_HIDE);
00130 
00131   RECT rc;
00132   GetWindowRect(GetDlgItem(hWnd, IDC_STATIC_WARNING), &rc);
00133   int iHeight = rc.bottom - rc.top;
00134   GetWindowRect(hWnd, &rc);
00135   SetWindowPos(hWnd, NULL, 0, 0, rc.right - rc.left, rc.bottom - rc.top - iHeight, SWP_NOZORDER | SWP_NOMOVE);
00136 
00137   HWND hWndQuestion = GetDlgItem(hWnd, IDC_STATIC_QUESTION);
00138   HWND hWndButtonGetPlugin = GetDlgItem(hWnd, IDC_GET_PLUGIN);
00139   HWND hWndButtonCancel = GetDlgItem(hWnd, IDC_BUTTON_CANCEL);
00140 
00141   POINT pt;
00142 
00143   GetWindowRect(hWndQuestion, &rc);
00144   pt.x = rc.left;
00145   pt.y = rc.top;
00146   ScreenToClient(hWnd, &pt);
00147   SetWindowPos(hWndQuestion, NULL, pt.x, pt.y - iHeight, 0, 0, SWP_NOZORDER | SWP_NOSIZE);
00148 
00149   GetWindowRect(hWndButtonGetPlugin, &rc);
00150   pt.x = rc.left;
00151   pt.y = rc.top;
00152   ScreenToClient(hWnd, &pt);
00153   SetWindowPos(hWndButtonGetPlugin, NULL, pt.x, pt.y - iHeight, 0, 0, SWP_NOZORDER | SWP_NOSIZE);
00154 
00155   GetWindowRect(hWndButtonCancel, &rc);
00156   pt.x = rc.left;
00157   pt.y = rc.top;
00158   ScreenToClient(hWnd, &pt);
00159   SetWindowPos(hWndButtonCancel, NULL, pt.x, pt.y - iHeight, 0, 0, SWP_NOZORDER | SWP_NOSIZE);
00160 
00161   if(pPlugin->m_bHidden)
00162     SetForegroundWindow(hWnd);
00163 
00164   return TRUE;
00165 }
00166 
00167 static void onClose(HWND hWnd)
00168 {
00169   DestroyWindow(hWnd);
00170 }
00171 
00172 static void onDestroy(HWND hWnd)
00173 {
00174 }
00175 
00176 BOOL CALLBACK NP_LOADDS GetPluginDialogProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
00177 {
00178   switch(uMsg)
00179   {
00180     case WM_INITDIALOG:
00181       return (BOOL)HANDLE_WM_INITDIALOG(hWnd, wParam, lParam, onInitDialog);
00182     case WM_COMMAND:
00183       HANDLE_WM_COMMAND(hWnd, wParam, lParam, onCommand);
00184       break;
00185     case WM_DESTROY:
00186       HANDLE_WM_DESTROY(hWnd, wParam, lParam, onDestroy);
00187       break;
00188     case WM_CLOSE:
00189       HANDLE_WM_CLOSE(hWnd, wParam, lParam, onClose);
00190       break;
00191 
00192     default:
00193       return FALSE;
00194   }
00195   return TRUE;
00196 }