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 #define INCL_WIN
00039 #include <os2.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 "os2utils.h"
00049 #include "xp.h"
00050 
00051 extern CLogger * pLogger;
00052 
00053 static void onCommand(HWND hWnd, int id, HWND hWndCtl, USHORT codeNotify)
00054 {
00055   CPlugin * pPlugin = (CPlugin *)WinQueryWindowULong(hWnd, QWL_USER);
00056   if (!pPlugin)
00057     return;
00058 
00059   switch (id)
00060   {
00061     case IDC_COMBO_API_CALL:
00062       if(codeNotify != CBN_LBSELECT)
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       SHORT iIndex = WinQueryLboxSelectedItem(WinWindowFromID(hWnd, IDC_COMBO_API_CALL));
00084       LONG maxchar = (LONG)WinSendMsg(WinWindowFromID(hWnd, IDC_COMBO_API_CALL), LM_QUERYITEMTEXTLENGTH, MPFROMSHORT(iIndex), (MPARAM)NULL);
00085       WinSendMsg(WinWindowFromID(hWnd, IDC_COMBO_API_CALL), LM_QUERYITEMTEXT, MPFROM2SHORT(iIndex, 80), (MPARAM)szString);
00086       if(   ((strcmp(szString, STRING_NPN_POSTURL) == 0) || (strcmp(szString, STRING_NPN_POSTURLNOTIFY) == 0))
00087          && (id == IDC_EDIT_ARG5)
00088          && (codeNotify == EN_CHANGE))
00089       {
00090         WinQueryWindowText(hWndCtl, sizeof(szEdit), szEdit);
00091         int iLength = strlen(szEdit);
00092         WinSetDlgItemShort(hWnd, IDC_EDIT_ARG4, iLength, FALSE);
00093       }
00094       if(   ((strcmp(szString, STRING_NPN_WRITE) == 0))
00095          && (id == IDC_EDIT_ARG4)
00096          && (codeNotify == EN_CHANGE))
00097       {
00098         WinQueryWindowText(hWndCtl, sizeof(szEdit), szEdit);
00099         int iLength = strlen(szEdit);
00100         WinSetDlgItemShort(hWnd, IDC_EDIT_ARG3, iLength, FALSE);
00101       }
00102 
00103       // save values of window size on the fly as we type it
00104       if(    (strcmp(szString, STRING_NPN_SETVALUE) == 0)
00105           && ((id == IDC_EDIT_ARG3) || (id == IDC_EDIT_ARG4)) 
00106           && (codeNotify == EN_CHANGE)
00107           && (hWndCtl == WinQueryFocus(HWND_DESKTOP)))
00108       {
00109         iIndex = WinQueryLboxSelectedItem(WinWindowFromID(hWnd, IDC_COMBO_ARG2));
00110         maxchar = (LONG)WinSendMsg(WinWindowFromID(hWnd, IDC_COMBO_ARG2), LM_QUERYITEMTEXTLENGTH, MPFROMSHORT(iIndex), (MPARAM)NULL);
00111         WinSendMsg(WinWindowFromID(hWnd, IDC_COMBO_ARG2), LM_QUERYITEMTEXT,  MPFROM2SHORT(iIndex, 80), (MPARAM)szString);
00112         if(strcmp(szString, "NPPVpluginWindowSize") == 0)
00113         {
00114           SHORT bTranslated;
00115           WinQueryDlgItemShort(hWnd, IDC_EDIT_ARG3, &bTranslated, TRUE);
00116           int iWidth = bTranslated;
00117           WinQueryDlgItemShort(hWnd, IDC_EDIT_ARG4, &bTranslated, TRUE);
00118           int iHeight = bTranslated;
00119 
00120           if(pPlugin->m_iWidth != iWidth)
00121             pPlugin->m_iWidth = iWidth;
00122           if(pPlugin->m_iHeight != iHeight)
00123             pPlugin->m_iHeight = iHeight;
00124         }
00125       }
00126       break;
00127     }
00128     case IDC_COMBO_ARG2:
00129     {
00130       if(codeNotify != CBN_LBSELECT)
00131         break;
00132 
00133       WinShowWindow(WinWindowFromID(hWnd, IDC_STATIC_ARG4), FALSE);
00134       WinShowWindow(WinWindowFromID(hWnd, IDC_EDIT_ARG4), FALSE);
00135       WinSetWindowText(WinWindowFromID(hWnd, IDC_STATIC_ARG3), "*value:");
00136       WinSetWindowText(WinWindowFromID(hWnd, IDC_EDIT_ARG3), "");
00137 
00138       char szString[80];
00139       SHORT iIndex = WinQueryLboxSelectedItem(WinWindowFromID(hWnd, IDC_COMBO_API_CALL));
00140       LONG maxchar = (LONG)WinSendMsg(WinWindowFromID(hWnd, IDC_COMBO_API_CALL), LM_QUERYITEMTEXTLENGTH, MPFROMSHORT(iIndex), (MPARAM)NULL);
00141       WinSendMsg(WinWindowFromID(hWnd, IDC_COMBO_API_CALL), LM_QUERYITEMTEXT,  MPFROM2SHORT(iIndex, 80), (MPARAM)szString);
00142       if(strcmp(szString, STRING_NPN_SETVALUE) == 0)
00143       {
00144         iIndex = WinQueryLboxSelectedItem(WinWindowFromID(hWnd, IDC_COMBO_ARG2));
00145         maxchar = (LONG)WinSendMsg(WinWindowFromID(hWnd, IDC_COMBO_ARG2), LM_QUERYITEMTEXTLENGTH, MPFROMSHORT(iIndex), (MPARAM)NULL);
00146         WinSendMsg(WinWindowFromID(hWnd, IDC_COMBO_ARG2), LM_QUERYITEMTEXT,  MPFROM2SHORT(iIndex, 80), (MPARAM)szString);
00147         if((strcmp(szString, "NPPVpluginWindowBool") == 0) ||
00148            (strcmp(szString, "NPPVpluginTransparentBool") == 0) ||
00149            (strcmp(szString, "NPPVpluginKeepLibraryInMemory") == 0))
00150         {
00151           HWND hWndCombo = WinWindowFromID(hWnd, IDC_COMBO_ARG3);
00152           WinSendMsg(hWndCombo, LM_DELETEALL, 0, 0);
00153           WinInsertLboxItem(hWndCombo, LIT_END, "TRUE");
00154           WinInsertLboxItem(hWndCombo, LIT_END, "FALSE");
00155           WinSendMsg(hWndCombo, LM_SELECTITEM, (MPARAM)0, (MPARAM)TRUE);
00156           WinShowWindow(WinWindowFromID(hWnd, IDC_EDIT_ARG3), FALSE);
00157           WinShowWindow(hWndCombo, TRUE);
00158         }
00159         else
00160         {
00161           WinShowWindow(WinWindowFromID(hWnd, IDC_EDIT_ARG3), TRUE);
00162           WinShowWindow(WinWindowFromID(hWnd, IDC_COMBO_ARG3), FALSE);
00163           if(strcmp(szString, "NPPVpluginWindowSize") == 0)
00164           {
00165             WinEnableWindow(WinWindowFromID(hWnd, IDC_EDIT_ARG4), TRUE);
00166             WinShowWindow(WinWindowFromID(hWnd, IDC_EDIT_ARG4), TRUE);
00167             WinShowWindow(WinWindowFromID(hWnd, IDC_STATIC_ARG4), TRUE);
00168             WinSetWindowText(WinWindowFromID(hWnd, IDC_STATIC_ARG3), "width:");
00169             WinSetWindowText(WinWindowFromID(hWnd, IDC_STATIC_ARG4), "height:");
00170             WinSetDlgItemShort(hWnd, IDC_EDIT_ARG3, pPlugin->m_iWidth, TRUE);
00171             WinSetDlgItemShort(hWnd, IDC_EDIT_ARG4, pPlugin->m_iHeight, TRUE);
00172           }
00173         }
00174       }
00175       break;
00176     }
00177     case IDC_BUTTON_PASTE:
00178       onPaste(pPlugin->m_hWndLastEditFocus);
00179       break;
00180     default:
00181       break;
00182   }
00183 }
00184 
00185 static BOOL onInitDialog(HWND hWnd, HWND hWndFocus, MPARAM lParam)
00186 {
00187   CPlugin * pPlugin = (CPlugin *)lParam;
00188   WinSetWindowULong(hWnd, QWL_USER, (ULONG)pPlugin);
00189 
00190   // look at the last used API call if needed
00191   int iSel = 0;
00192   if (pPlugin && pPlugin->m_Pref_bRememberLastCall) {
00193     char szFileName[_MAX_PATH];
00194     GetINIFileName(pPlugin->getInstance(), szFileName, sizeof(szFileName));
00195     iSel = XP_GetPrivateProfileInt(SECTION_PREFERENCES, KEY_LAST_API_CALL, 0, szFileName);
00196   }
00197   fillAPIComboBoxAndSetSel(WinWindowFromID(hWnd, IDC_COMBO_API_CALL), iSel);
00198   updateUI(hWnd);
00199 
00200   int iTopMargin = 188;
00201   WinSetWindowPos(hWnd, NULL, 0, iTopMargin, 0, 0, SWP_SHOW ); 
00202   return TRUE;
00203 }
00204 
00205 static void onDestroy(HWND hWnd)
00206 {
00207   CPlugin * pPlugin = (CPlugin *)WinQueryWindowULong(hWnd, QWL_USER);
00208   if(pPlugin && pPlugin->m_Pref_bRememberLastCall) {
00209     // save last API call if needed
00210     char szFileName[_MAX_PATH];
00211     GetINIFileName(pPlugin->getInstance(), szFileName, sizeof(szFileName));
00212     int iSel = WinQueryLboxSelectedItem(WinWindowFromID(hWnd, IDC_COMBO_API_CALL));
00213     XP_WritePrivateProfileInt(SECTION_PREFERENCES, KEY_LAST_API_CALL, iSel, szFileName);
00214   }
00215 }
00216 
00217 MRESULT EXPENTRY NP_LOADDS ManualDlgProc(HWND hWnd, ULONG msg, MPARAM mp1, MPARAM mp2)
00218 {
00219   switch(msg)
00220   {
00221     case WM_INITDLG:
00222       onInitDialog(hWnd, 0, mp2);
00223       return (MRESULT) FALSE;
00224     case WM_COMMAND:
00225     case WM_CONTROL:
00226       onCommand(hWnd, SHORT1FROMMP(mp1), WinWindowFromID(hWnd, SHORT1FROMMP(mp1)), SHORT2FROMMP(mp1));
00227       break;
00228     case WM_DESTROY:
00229       onDestroy(hWnd);
00230       break;
00231 
00232     default:
00233       return WinDefDlgProc(hWnd, msg, mp1, mp2);
00234   }
00235   return (MRESULT)TRUE;
00236 }