Back to index

lightning-sunbird  0.9+nobinonly
dlgauto.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 "guihlp.h"
00045 #include "plugin.h"
00046 #include "scripter.h"
00047 #include "logger.h"
00048 #include "xp.h"
00049 
00050 extern CLogger * pLogger;
00051 static CScripter * pScripter = NULL;
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_EDIT_SCRIPT_FILE_NAME:
00062     {
00063       if(codeNotify != EN_CHANGE)
00064         break;
00065       char szString[256];
00066       WinQueryWindowText(WinWindowFromID(hWnd, IDC_EDIT_SCRIPT_FILE_NAME), sizeof(szString), szString);
00067       int iLen = strlen(szString);
00068       WinEnableWindow(WinWindowFromID(hWnd, IDC_BUTTON_GO), (iLen > 0));
00069       if(iLen <= 0)
00070         break;
00071 
00072       // synchronize log filename with current script filename
00073       char szLogFileName[256];
00074       char * p = strchr(szString, '.');
00075 
00076       if(p != NULL)
00077         *p = '\0';
00078 
00079       strcpy(szLogFileName, szString);
00080       strcat(szLogFileName, ".log");
00081       WinSetWindowText(WinWindowFromID(WinQueryWindow(hWnd, QW_PARENT), IDC_EDIT_LOG_FILE_NAME), szLogFileName);
00082 
00083       // restore
00084       if(p)
00085         *p = '.';
00086 
00087       pPlugin->updatePrefs(gp_scriptfile, FALSE, szString);
00088 
00089       break;
00090     }
00091     /*
00092     case IDC_BUTTON_STOP:
00093       assert(pScripter != NULL);
00094       pScripter->setStopAutoExecFlag(TRUE);
00095       WinShowWindow(WinWindowFromID(hWnd, IDC_BUTTON_GO), TRUE);
00096       WinShowWindow(WinWindowFromID(hWnd, IDC_BUTTON_STOP), FALSE);
00097       break;
00098     */
00099     case IDC_BUTTON_GO:
00100     {
00101       pLogger->blockDumpToFile(FALSE);
00102 
00103       //WinShowWindow(WinWindowFromID(hWnd, IDC_BUTTON_GO), FALSE);
00104       //WinShowWindow(WinWindowFromID(hWnd, IDC_BUTTON_STOP), TRUE);
00105       //UpdateWindow(WinWindowFromID(hWnd, IDC_BUTTON_STOP));
00106       EnableWindowNow(WinWindowFromID(hWnd, IDC_BUTTON_GO), FALSE);
00107 
00108       EnableWindowNow(WinWindowFromID(hWnd, IDC_EDIT_SCRIPT_FILE_NAME), FALSE);
00109       EnableWindowNow(WinWindowFromID(WinQueryWindow(hWnd, QW_PARENT), IDC_EDIT_LOG_FILE_NAME), FALSE);
00110       EnableWindowNow(WinWindowFromID(WinQueryWindow(hWnd, QW_PARENT), IDC_CHECK_SHOW_LOG), FALSE);
00111       EnableWindowNow(WinWindowFromID(WinQueryWindow(hWnd, QW_PARENT), IDC_CHECK_LOG_TO_FRAME), FALSE);
00112       EnableWindowNow(WinWindowFromID(WinQueryWindow(hWnd, QW_PARENT), IDC_CHECK_LOG_TO_FILE), FALSE);
00113       BOOL bFlashWasEnabled = FALSE;
00114       if(WinIsWindowEnabled(WinWindowFromID(WinQueryWindow(hWnd, QW_PARENT), IDC_BUTTON_FLUSH)))
00115       {
00116         bFlashWasEnabled = TRUE;
00117         EnableWindowNow(WinWindowFromID(WinQueryWindow(hWnd, QW_PARENT), IDC_BUTTON_FLUSH), FALSE);
00118       }
00119       EnableWindowNow(WinWindowFromID(WinQueryWindow(hWnd, QW_PARENT), IDC_BUTTON_CLEAR), FALSE);
00120       EnableWindowNow(WinWindowFromID(WinQueryWindow(hWnd, QW_PARENT), IDC_RADIO_MODE_MANUAL), FALSE);
00121       EnableWindowNow(WinWindowFromID(WinQueryWindow(hWnd, QW_PARENT), IDC_RADIO_MODE_AUTO), FALSE);
00122     
00123       if(pScripter != NULL)
00124         delete pScripter;
00125 
00126       pScripter = new CScripter();
00127       pScripter->associate(pPlugin);
00128 
00129       char szFileName[_MAX_PATH];
00130       pPlugin ->getModulePath(szFileName, sizeof(szFileName));
00131 
00132       char szFile[_MAX_PATH];
00133       WinQueryWindowText(WinWindowFromID(hWnd, IDC_EDIT_SCRIPT_FILE_NAME), sizeof(szFile), szFile);
00134       strcat(szFileName, szFile);
00135 
00136       if(pScripter->createScriptFromFile(szFileName))
00137       {
00138         int iRepetitions = pScripter->getCycleRepetitions();
00139         int iDelay = pScripter->getCycleDelay();
00140         if(iDelay < 0)
00141           iDelay = 0;
00142 
00143         assert(pLogger != NULL);
00144         pLogger->resetStartTime();
00145 
00146         ShowWindowNow(WinWindowFromID(hWnd, IDC_STATIC_REPETITIONS_LABEL), TRUE);
00147         char szLeft[256];
00148 
00149         for(int i = 0; i < iRepetitions; i++)
00150         {
00151           sprintf(szLeft, "%i", iRepetitions - i);
00152           WinSetWindowText(WinWindowFromID(hWnd, IDC_STATIC_REPETITIONS_LEFT), szLeft);
00153           pScripter->executeScript();
00154           /*
00155           if(pScripter->getStopAutoExecFlag())
00156           {
00157             pScripter->setStopAutoExecFlag(FALSE);
00158             break;
00159           }
00160           */
00161           if(iDelay != 0)
00162             XP_Sleep(iDelay);
00163         }
00164       }
00165       else
00166       {
00167         WinMessageBox(HWND_DESKTOP, hWnd, "Script file not found or invalid", "", 0, MB_OK | MB_ERROR);
00168       }
00169 
00170       delete pScripter;
00171       pScripter = NULL;
00172 
00173       WinSetWindowText(WinWindowFromID(hWnd, IDC_STATIC_REPETITIONS_LEFT), "");
00174       WinShowWindow(WinWindowFromID(hWnd, IDC_STATIC_REPETITIONS_LABEL), FALSE);
00175 
00176       //WinShowWindow(WinWindowFromID(hWnd, IDC_BUTTON_GO), TRUE);
00177       //WinShowWindow(WinWindowFromID(hWnd, IDC_BUTTON_STOP), FALSE);
00178       WinEnableWindow(WinWindowFromID(hWnd, IDC_BUTTON_GO), TRUE);
00179 
00180       WinEnableWindow(WinWindowFromID(hWnd, IDC_EDIT_SCRIPT_FILE_NAME), TRUE);
00181       WinEnableWindow(WinWindowFromID(WinQueryWindow(hWnd, QW_PARENT), IDC_EDIT_LOG_FILE_NAME), TRUE);
00182       WinEnableWindow(WinWindowFromID(WinQueryWindow(hWnd, QW_PARENT), IDC_CHECK_SHOW_LOG), TRUE);
00183       WinEnableWindow(WinWindowFromID(WinQueryWindow(hWnd, QW_PARENT), IDC_CHECK_LOG_TO_FRAME), TRUE);
00184       WinEnableWindow(WinWindowFromID(WinQueryWindow(hWnd, QW_PARENT), IDC_CHECK_LOG_TO_FILE), TRUE);
00185       if(bFlashWasEnabled)
00186         WinEnableWindow(WinWindowFromID(WinQueryWindow(hWnd, QW_PARENT), IDC_BUTTON_FLUSH), TRUE);
00187       WinEnableWindow(WinWindowFromID(WinQueryWindow(hWnd, QW_PARENT), IDC_BUTTON_CLEAR), TRUE);
00188       WinEnableWindow(WinWindowFromID(WinQueryWindow(hWnd, QW_PARENT), IDC_RADIO_MODE_MANUAL), TRUE);
00189       WinEnableWindow(WinWindowFromID(WinQueryWindow(hWnd, QW_PARENT), IDC_RADIO_MODE_AUTO), TRUE);
00190       break;
00191     }
00192     default:
00193       break;
00194   }
00195 }
00196 
00197 static BOOL onInitDialog(HWND hWnd, HWND hWndFocus, MPARAM mParam)
00198 {
00199   CPlugin * pPlugin = (CPlugin *)mParam;
00200   WinSetWindowPtr(hWnd, QWL_USER, (PVOID)pPlugin);
00201 
00202   int iTopMargin = 188;
00203   WinSetWindowPos(hWnd, NULL, 0, iTopMargin, 0, 0, SWP_SHOW );  
00204 
00205   WinSetWindowText(WinWindowFromID(hWnd, IDC_EDIT_SCRIPT_FILE_NAME), pPlugin->m_Pref_szScriptFile);
00206 
00207   WinSetWindowText(WinWindowFromID(hWnd, IDC_STATIC_REPETITIONS_LEFT), "");
00208   WinShowWindow(WinWindowFromID(hWnd, IDC_STATIC_REPETITIONS_LABEL), FALSE);
00209 
00210   WinShowWindow(WinWindowFromID(hWnd, IDC_BUTTON_GO), TRUE);
00211   WinShowWindow(WinWindowFromID(hWnd, IDC_BUTTON_STOP), FALSE);
00212 
00213   return TRUE;
00214 }
00215 
00216 static void onDestroy(HWND hWnd)
00217 {
00218   if(pScripter != NULL)
00219   {
00220     delete pScripter;
00221     pScripter = NULL;
00222   }
00223 }
00224 
00225 MRESULT EXPENTRY NP_LOADDS AutoDlgProc(HWND hWnd, ULONG msg, MPARAM mp1, MPARAM mp2)
00226 {
00227   switch(msg)
00228   {
00229     case WM_INITDLG:
00230       onInitDialog(hWnd, 0, mp2);
00231       return (MRESULT)FALSE;
00232     case WM_COMMAND:
00233     case WM_CONTROL:
00234       onCommand(hWnd, SHORT1FROMMP(mp1), 0, SHORT2FROMMP(mp1));
00235       break;
00236     case WM_DESTROY:
00237       onDestroy(hWnd);
00238       break;
00239 
00240     default:
00241       return WinDefDlgProc(hWnd, msg, mp1, mp2);
00242   }
00243   return (MRESULT)TRUE;
00244 }