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 #define INCL_WIN
00039 #include <os2.h>
00040 #include <string.h>
00041 #include <assert.h>
00042 
00043 #include "npnulos2.h"
00044 
00045 #include "plugin.h"
00046 #include "utils.h"
00047 
00048 static void onCommand(HWND hWnd, int id, HWND hWndCtl, UINT codeNotify)
00049 {
00050   CPlugin * pPlugin = (CPlugin *)WinQueryWindowPtr(hWnd, QWL_USER);
00051   switch (id)
00052   {
00053     case IDC_GET_PLUGIN:
00054       WinDismissDlg(hWnd, IDC_GET_PLUGIN);
00055       if(pPlugin !=NULL)
00056         pPlugin->m_hWndDialog = NULL;
00057       break;
00058     case DID_CANCEL:
00059       WinDismissDlg(hWnd, DID_CANCEL);
00060       if(pPlugin !=NULL)
00061         pPlugin->m_hWndDialog = NULL;
00062       break;
00063     default:
00064       break;
00065   }
00066 }
00067 
00068 static BOOL onInitDialog(HWND hWnd, HWND hWndFocus, MPARAM mParam)
00069 {
00070   CPlugin * pPlugin = (CPlugin *)mParam;
00071   assert(pPlugin != NULL);
00072   if(pPlugin == NULL)
00073     return TRUE;
00074 
00075   WinSetWindowPtr(hWnd, QWL_USER, (PVOID)pPlugin);
00076 
00077   pPlugin->m_hWndDialog = hWnd;
00078   
00079   char szString[512];
00080   WinLoadString((HAB)0, hInst, IDS_TITLE, sizeof(szString), szString);
00081   WinSetWindowText(hWnd, szString);
00082 
00083   WinLoadString((HAB)0, hInst, IDS_INFO, sizeof(szString), szString);
00084   WinSetDlgItemText(hWnd, IDC_STATIC_INFO, szString);
00085 
00086   WinSetDlgItemText(hWnd, IDC_STATIC_INFOTYPE, pPlugin->m_pNPMIMEType);
00087 
00088   WinLoadString((HAB)0, hInst, IDS_LOCATION, sizeof(szString), szString);
00089   WinSetDlgItemText(hWnd, IDC_STATIC_LOCATION, szString);
00090 
00091   char contentTypeIsJava = 0;
00092 
00093   if (NULL != pPlugin->m_pNPMIMEType) {
00094     contentTypeIsJava = (0 == strcmp("application/x-java-vm",
00095                                  pPlugin->m_pNPMIMEType)) ? 1 : 0;
00096   }
00097   
00098   if(pPlugin->m_szPageURL == NULL || contentTypeIsJava)
00099     WinLoadString((HAB)0, hInst, IDS_FINDER_PAGE, sizeof(szString), szString);
00100   else
00101     strncpy(szString, pPlugin->m_szPageURL,511); // defect #362738
00102   
00103   SetDlgItemTextWrapped(hWnd, IDC_STATIC_URL, szString);
00104 
00105   WinLoadString((HAB)0, hInst, IDS_QUESTION, sizeof(szString), szString);
00106   WinSetDlgItemText(hWnd, IDC_STATIC_QUESTION, szString);
00107 
00108   WinSetDlgItemText(hWnd, IDC_STATIC_WARNING, "");
00109 
00110   if(!pPlugin->m_bOnline)
00111   {
00112     WinEnableWindow(WinWindowFromID(hWnd, IDC_GET_PLUGIN), FALSE);
00113     WinLoadString((HAB)0, hInst, IDS_WARNING_OFFLINE, sizeof(szString), szString);
00114     WinSetDlgItemText(hWnd, IDC_STATIC_WARNING, szString);
00115     WinSetDlgItemText(hWnd, IDC_STATIC_QUESTION, "");
00116     return TRUE;
00117   }
00118 
00119   if((!pPlugin->m_bJava) || (!pPlugin->m_bJavaScript) || (!pPlugin->m_bSmartUpdate))
00120   {
00121     WinLoadString((HAB)0, hInst, IDS_WARNING_JS, sizeof(szString), szString);
00122     WinSetDlgItemText(hWnd, IDC_STATIC_WARNING, szString);
00123     return TRUE;
00124   }
00125 
00126   WinShowWindow(WinWindowFromID(hWnd, IDC_STATIC_WARNING), FALSE);
00127 
00128   RECTL rc;
00129 
00130   WinQueryWindowRect(WinWindowFromID(hWnd, IDC_STATIC_WARNING), &rc);
00131   int iHeight = rc.yTop - rc.yBottom;
00132   WinQueryWindowRect(hWnd, &rc);
00133   WinSetWindowPos(hWnd, 0, 0, 0, rc.xRight - rc.xLeft, rc.yTop - rc.yBottom - iHeight, SWP_SIZE);
00134 
00135   HWND hWndQuestion = WinWindowFromID(hWnd, IDC_STATIC_QUESTION);
00136   HWND hWndButtonGetPlugin = WinWindowFromID(hWnd, IDC_GET_PLUGIN);
00137   HWND hWndButtonCancel = WinWindowFromID(hWnd, IDC_BUTTON_CANCEL);
00138 
00139   POINTL pt;
00140 
00141   WinQueryWindowRect(hWndQuestion, &rc);
00142   pt.x = rc.xLeft;
00143   pt.y = rc.yBottom;
00144 //  ScreenToClient(hWnd, &pt);
00145   WinSetWindowPos(hWndQuestion, 0, pt.x, pt.y - iHeight, 0, 0, SWP_MOVE);
00146 
00147   WinQueryWindowRect(hWndButtonGetPlugin, &rc);
00148   pt.x = rc.xLeft;
00149   pt.y = rc.yBottom;
00150 //  ScreenToClient(hWnd, &pt);
00151   WinSetWindowPos(hWndButtonGetPlugin, 0, pt.x, pt.y - iHeight, 0, 0, SWP_MOVE);
00152 
00153   WinQueryWindowRect(hWndButtonCancel, &rc);
00154   pt.x = rc.xLeft;
00155   pt.y = rc.yBottom;
00156 //  ScreenToClient(hWnd, &pt);
00157   WinSetWindowPos(hWndButtonCancel, 0, pt.x, pt.y - iHeight, 0, 0, SWP_MOVE);
00158 
00159   if(pPlugin->m_bHidden)
00160     WinSetActiveWindow(HWND_DESKTOP, hWnd);
00161 
00162   return TRUE;
00163 }
00164 
00165 static void onClose(HWND hWnd)
00166 {
00167   WinDismissDlg(hWnd, DID_CANCEL);
00168   CPlugin * pPlugin = (CPlugin *)WinQueryWindowPtr(hWnd, QWL_USER);
00169   if(pPlugin !=NULL)
00170     pPlugin->m_hWndDialog = NULL;
00171 }
00172 
00173 static void onDestroy(HWND hWnd)
00174 {
00175 }
00176 
00177 MRESULT EXPENTRY NP_LOADDS GetPluginDialogProc(HWND hWnd, ULONG uMsg, MPARAM mp1, MPARAM mp2)
00178 {
00179   switch(uMsg)
00180   {
00181     case WM_INITDLG:
00182       onInitDialog(hWnd,0,mp2);
00183       return (MRESULT)FALSE;
00184    case WM_COMMAND:
00185       onCommand(hWnd, SHORT1FROMMP(mp1),0,0);
00186       break;
00187    case WM_DESTROY:
00188       onDestroy(hWnd);
00189       break;
00190    case WM_CLOSE:
00191       onClose(hWnd);
00192       break;
00193 
00194     default:
00195       return WinDefDlgProc(hWnd, uMsg, mp1, mp2);
00196   }
00197   return (MRESULT)TRUE;
00198 }