Back to index

lightning-sunbird  0.9+nobinonly
dlgman.cpp
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: 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.org 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 "helpers.h"
00046 #include "guihlp.h"
00047 #include "guiprefs.h"
00048 #include "winutils.h"
00049 #include "xp.h"
00050 
00051 extern CLogger * pLogger;
00052 
00053 static void onCommand(HWND hWnd, int id, HWND hWndCtl, UINT codeNotify)
00054 {
00055   CPlugin * pPlugin = (CPlugin *)GetWindowLong(hWnd, DWL_USER);
00056   if (!pPlugin)
00057     return;
00058 
00059   switch (id)
00060   {
00061     case IDC_COMBO_API_CALL:
00062       if(codeNotify != CBN_SELCHANGE)
00063         break;
00064       updateUI(hWnd);
00065       break;
00066     case IDC_BUTTON_GO:
00067       pLogger->blockDumpToFile(FALSE);
00068       onGo(hWnd);
00069       break;
00070     case IDC_EDIT_ARG1:
00071     case IDC_EDIT_ARG2:
00072     case IDC_EDIT_ARG3:
00073     case IDC_EDIT_ARG4:
00074     case IDC_EDIT_ARG5:
00075     case IDC_EDIT_ARG6:
00076     case IDC_EDIT_ARG7:
00077     {
00078       if(codeNotify == EN_SETFOCUS)
00079         pPlugin->m_hWndLastEditFocus = hWndCtl;
00080 
00081       char szString[80];
00082       char szEdit[128];
00083       int iIndex = ComboBox_GetCurSel(GetDlgItem(hWnd, IDC_COMBO_API_CALL));
00084       ComboBox_GetLBText(GetDlgItem(hWnd, IDC_COMBO_API_CALL), iIndex, szString);
00085       if(   ((strcmp(szString, STRING_NPN_POSTURL) == 0) || (strcmp(szString, STRING_NPN_POSTURLNOTIFY) == 0))
00086          && (id == IDC_EDIT_ARG5)
00087          && (codeNotify == EN_CHANGE))
00088       {
00089         Edit_GetText(hWndCtl, szEdit, sizeof(szEdit));
00090         int iLength = strlen(szEdit);
00091         SetDlgItemInt(hWnd, IDC_EDIT_ARG4, iLength, FALSE);
00092       }
00093       if(   ((strcmp(szString, STRING_NPN_WRITE) == 0))
00094          && (id == IDC_EDIT_ARG4)
00095          && (codeNotify == EN_CHANGE))
00096       {
00097         Edit_GetText(hWndCtl, szEdit, sizeof(szEdit));
00098         int iLength = strlen(szEdit);
00099         SetDlgItemInt(hWnd, IDC_EDIT_ARG3, iLength, FALSE);
00100       }
00101 
00102       // save values of window size on the fly as we type it
00103       if(    (strcmp(szString, STRING_NPN_SETVALUE) == 0)
00104           && ((id == IDC_EDIT_ARG3) || (id == IDC_EDIT_ARG4)) 
00105           && (codeNotify == EN_CHANGE)
00106           && (hWndCtl == GetFocus()))
00107       {
00108         iIndex = ComboBox_GetCurSel(GetDlgItem(hWnd, IDC_COMBO_ARG2));
00109         ComboBox_GetLBText(GetDlgItem(hWnd, IDC_COMBO_ARG2), iIndex, szString);
00110         if(strcmp(szString, "NPPVpluginWindowSize") == 0)
00111         {
00112           BOOL bTranslated = FALSE;
00113           int iWidth = GetDlgItemInt(hWnd, IDC_EDIT_ARG3, &bTranslated, TRUE);
00114           int iHeight = GetDlgItemInt(hWnd, IDC_EDIT_ARG4, &bTranslated, TRUE);
00115 
00116           if(pPlugin->m_iWidth != iWidth)
00117             pPlugin->m_iWidth = iWidth;
00118           if(pPlugin->m_iHeight != iHeight)
00119             pPlugin->m_iHeight = iHeight;
00120         }
00121       }
00122       break;
00123     }
00124     case IDC_COMBO_ARG2:
00125     {
00126       if(codeNotify != CBN_SELCHANGE)
00127         break;
00128 
00129       ShowWindow(GetDlgItem(hWnd, IDC_STATIC_ARG4), SW_HIDE);
00130       ShowWindow(GetDlgItem(hWnd, IDC_EDIT_ARG4), SW_HIDE);
00131       Static_SetText(GetDlgItem(hWnd, IDC_STATIC_ARG3), "*value:");
00132       Edit_SetText(GetDlgItem(hWnd, IDC_EDIT_ARG3), "");
00133 
00134       char szString[80];
00135       int iIndex = ComboBox_GetCurSel(GetDlgItem(hWnd, IDC_COMBO_API_CALL));
00136       ComboBox_GetLBText(GetDlgItem(hWnd, IDC_COMBO_API_CALL), iIndex, szString);
00137       if(strcmp(szString, STRING_NPN_SETVALUE) == 0)
00138       {
00139         iIndex = ComboBox_GetCurSel(GetDlgItem(hWnd, IDC_COMBO_ARG2));
00140         ComboBox_GetLBText(GetDlgItem(hWnd, IDC_COMBO_ARG2), iIndex, szString);
00141         if((strcmp(szString, "NPPVpluginWindowBool") == 0) ||
00142            (strcmp(szString, "NPPVpluginTransparentBool") == 0) ||
00143            (strcmp(szString, "NPPVpluginKeepLibraryInMemory") == 0))
00144         {
00145           HWND hWndCombo = GetDlgItem(hWnd, IDC_COMBO_ARG3);
00146           ComboBox_ResetContent(hWndCombo);
00147           ComboBox_AddString(hWndCombo, "TRUE");
00148           ComboBox_AddString(hWndCombo, "FALSE");
00149           ComboBox_SetCurSel(hWndCombo, 0);
00150           ShowWindow(GetDlgItem(hWnd, IDC_EDIT_ARG3), SW_HIDE);
00151           ShowWindow(hWndCombo, SW_SHOW);
00152         }
00153         else
00154         {
00155           ShowWindow(GetDlgItem(hWnd, IDC_EDIT_ARG3), SW_SHOW);
00156           ShowWindow(GetDlgItem(hWnd, IDC_COMBO_ARG3), SW_HIDE);
00157           if(strcmp(szString, "NPPVpluginWindowSize") == 0)
00158           {
00159             EnableWindow(GetDlgItem(hWnd, IDC_EDIT_ARG4), TRUE);
00160             ShowWindow(GetDlgItem(hWnd, IDC_EDIT_ARG4), SW_SHOW);
00161             ShowWindow(GetDlgItem(hWnd, IDC_STATIC_ARG4), SW_SHOW);
00162             Static_SetText(GetDlgItem(hWnd, IDC_STATIC_ARG3), "width:");
00163             Static_SetText(GetDlgItem(hWnd, IDC_STATIC_ARG4), "height:");
00164             SetDlgItemInt(hWnd, IDC_EDIT_ARG3, pPlugin->m_iWidth, TRUE);
00165             SetDlgItemInt(hWnd, IDC_EDIT_ARG4, pPlugin->m_iHeight, TRUE);
00166           }
00167         }
00168       }
00169       break;
00170     }
00171     case IDC_BUTTON_PASTE:
00172       onPaste(pPlugin->m_hWndLastEditFocus);
00173       break;
00174     default:
00175       break;
00176   }
00177 }
00178 
00179 static BOOL onInitDialog(HWND hWnd, HWND hWndFocus, LPARAM lParam)
00180 {
00181   CPlugin * pPlugin = (CPlugin *)lParam;
00182   SetWindowLong(hWnd, DWL_USER, (long)pPlugin);
00183 
00184   // look at the last used API call if needed
00185   int iSel = 0;
00186   if (pPlugin && pPlugin->m_Pref_bRememberLastCall) {
00187     char szFileName[_MAX_PATH];
00188     GetINIFileName(pPlugin->getInstance(), szFileName, sizeof(szFileName));
00189     iSel = XP_GetPrivateProfileInt(SECTION_PREFERENCES, KEY_LAST_API_CALL, 0, szFileName);
00190   }
00191   fillAPIComboBoxAndSetSel(GetDlgItem(hWnd, IDC_COMBO_API_CALL), iSel);
00192   updateUI(hWnd);
00193 
00194   int iTopMargin = 188;
00195   SetWindowPos(hWnd, NULL, 0,iTopMargin, 0,0, SWP_NOZORDER | SWP_NOSIZE);
00196   return TRUE;
00197 }
00198 
00199 static void onDestroy(HWND hWnd)
00200 {
00201   CPlugin * pPlugin = (CPlugin *)GetWindowLong(hWnd, DWL_USER);
00202   if(pPlugin && pPlugin->m_Pref_bRememberLastCall) {
00203     // save last API call if needed
00204     char szFileName[_MAX_PATH];
00205     GetINIFileName(pPlugin->getInstance(), szFileName, sizeof(szFileName));
00206     int iSel = ComboBox_GetCurSel(GetDlgItem(hWnd, IDC_COMBO_API_CALL));
00207     XP_WritePrivateProfileInt(SECTION_PREFERENCES, KEY_LAST_API_CALL, iSel, szFileName);
00208   }
00209 }
00210 
00211 BOOL CALLBACK NP_LOADDS ManualDlgProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
00212 {
00213   switch(msg)
00214   {
00215     case WM_INITDIALOG:
00216       return (BOOL)HANDLE_WM_INITDIALOG(hWnd, wParam, lParam, onInitDialog);
00217     case WM_COMMAND:
00218       HANDLE_WM_COMMAND(hWnd, wParam, lParam, onCommand);
00219       break;
00220     case WM_DESTROY:
00221       HANDLE_WM_DESTROY(hWnd, wParam, lParam, onDestroy);
00222       break;
00223 
00224     default:
00225       return FALSE;
00226   }
00227   return TRUE;
00228 }