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 #include <windows.h>
00039 #include <windowsx.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, UINT codeNotify)
00054 {
00055   CPlugin * pPlugin = (CPlugin *)GetWindowLong(hWnd, DWL_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       Edit_GetText(GetDlgItem(hWnd, IDC_EDIT_SCRIPT_FILE_NAME), szString, sizeof(szString));
00067       int iLen = strlen(szString);
00068       EnableWindow(GetDlgItem(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       Edit_SetText(GetDlgItem(GetParent(hWnd), 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       ShowWindow(GetDlgItem(hWnd, IDC_BUTTON_GO), SW_SHOW);
00096       ShowWindow(GetDlgItem(hWnd, IDC_BUTTON_STOP), SW_HIDE);
00097       break;
00098     */
00099     case IDC_BUTTON_GO:
00100     {
00101       pLogger->blockDumpToFile(FALSE);
00102 
00103       //ShowWindow(GetDlgItem(hWnd, IDC_BUTTON_GO), SW_HIDE);
00104       //ShowWindow(GetDlgItem(hWnd, IDC_BUTTON_STOP), SW_SHOW);
00105       //UpdateWindow(GetDlgItem(hWnd, IDC_BUTTON_STOP));
00106       EnableWindowNow(GetDlgItem(hWnd, IDC_BUTTON_GO), FALSE);
00107 
00108       EnableWindowNow(GetDlgItem(hWnd, IDC_EDIT_SCRIPT_FILE_NAME), FALSE);
00109       EnableWindowNow(GetDlgItem(GetParent(hWnd), IDC_EDIT_LOG_FILE_NAME), FALSE);
00110       EnableWindowNow(GetDlgItem(GetParent(hWnd), IDC_CHECK_SHOW_LOG), FALSE);
00111       EnableWindowNow(GetDlgItem(GetParent(hWnd), IDC_CHECK_LOG_TO_FRAME), FALSE);
00112       EnableWindowNow(GetDlgItem(GetParent(hWnd), IDC_CHECK_LOG_TO_FILE), FALSE);
00113       BOOL bFlashWasEnabled = FALSE;
00114       if(IsWindowEnabled(GetDlgItem(GetParent(hWnd), IDC_BUTTON_FLUSH)))
00115       {
00116         bFlashWasEnabled = TRUE;
00117         EnableWindowNow(GetDlgItem(GetParent(hWnd), IDC_BUTTON_FLUSH), FALSE);
00118       }
00119       EnableWindowNow(GetDlgItem(GetParent(hWnd), IDC_BUTTON_CLEAR), FALSE);
00120       EnableWindowNow(GetDlgItem(GetParent(hWnd), IDC_RADIO_MODE_MANUAL), FALSE);
00121       EnableWindowNow(GetDlgItem(GetParent(hWnd), 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       Edit_GetText(GetDlgItem(hWnd, IDC_EDIT_SCRIPT_FILE_NAME), szFile, sizeof(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(GetDlgItem(hWnd, IDC_STATIC_REPETITIONS_LABEL), SW_SHOW);
00147         char szLeft[256];
00148 
00149         for(int i = 0; i < iRepetitions; i++)
00150         {
00151           wsprintf(szLeft, "%i", iRepetitions - i);
00152           Static_SetText(GetDlgItem(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         MessageBox(hWnd, "Script file not found or invalid", "", MB_OK | MB_ICONERROR);
00168       }
00169 
00170       delete pScripter;
00171       pScripter = NULL;
00172 
00173       Static_SetText(GetDlgItem(hWnd, IDC_STATIC_REPETITIONS_LEFT), "");
00174       ShowWindow(GetDlgItem(hWnd, IDC_STATIC_REPETITIONS_LABEL), SW_HIDE);
00175 
00176       //ShowWindow(GetDlgItem(hWnd, IDC_BUTTON_GO), SW_SHOW);
00177       //ShowWindow(GetDlgItem(hWnd, IDC_BUTTON_STOP), SW_HIDE);
00178       EnableWindow(GetDlgItem(hWnd, IDC_BUTTON_GO), TRUE);
00179 
00180       EnableWindow(GetDlgItem(hWnd, IDC_EDIT_SCRIPT_FILE_NAME), TRUE);
00181       EnableWindow(GetDlgItem(GetParent(hWnd), IDC_EDIT_LOG_FILE_NAME), TRUE);
00182       EnableWindow(GetDlgItem(GetParent(hWnd), IDC_CHECK_SHOW_LOG), TRUE);
00183       EnableWindow(GetDlgItem(GetParent(hWnd), IDC_CHECK_LOG_TO_FRAME), TRUE);
00184       EnableWindow(GetDlgItem(GetParent(hWnd), IDC_CHECK_LOG_TO_FILE), TRUE);
00185       if(bFlashWasEnabled)
00186         EnableWindow(GetDlgItem(GetParent(hWnd), IDC_BUTTON_FLUSH), TRUE);
00187       EnableWindow(GetDlgItem(GetParent(hWnd), IDC_BUTTON_CLEAR), TRUE);
00188       EnableWindow(GetDlgItem(GetParent(hWnd), IDC_RADIO_MODE_MANUAL), TRUE);
00189       EnableWindow(GetDlgItem(GetParent(hWnd), IDC_RADIO_MODE_AUTO), TRUE);
00190       break;
00191     }
00192     default:
00193       break;
00194   }
00195 }
00196 
00197 static BOOL onInitDialog(HWND hWnd, HWND hWndFocus, LPARAM lParam)
00198 {
00199   CPlugin * pPlugin = (CPlugin *)lParam;
00200   SetWindowLong(hWnd, DWL_USER, (long)pPlugin);
00201 
00202   int iTopMargin = 188;
00203   SetWindowPos(hWnd, NULL, 0,iTopMargin, 0,0, SWP_NOZORDER | SWP_NOSIZE);
00204 
00205   if (pPlugin)
00206     Edit_SetText(GetDlgItem(hWnd, IDC_EDIT_SCRIPT_FILE_NAME), (LPCSTR)pPlugin->m_Pref_szScriptFile);
00207 
00208   Static_SetText(GetDlgItem(hWnd, IDC_STATIC_REPETITIONS_LEFT), "");
00209   ShowWindow(GetDlgItem(hWnd, IDC_STATIC_REPETITIONS_LABEL), SW_HIDE);
00210 
00211   ShowWindow(GetDlgItem(hWnd, IDC_BUTTON_GO), SW_SHOW);
00212   ShowWindow(GetDlgItem(hWnd, IDC_BUTTON_STOP), SW_HIDE);
00213 
00214   return TRUE;
00215 }
00216 
00217 static void onDestroy(HWND hWnd)
00218 {
00219   if(pScripter != NULL)
00220   {
00221     delete pScripter;
00222     pScripter = NULL;
00223   }
00224 }
00225 
00226 BOOL CALLBACK NP_LOADDS AutoDlgProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
00227 {
00228   switch(msg)
00229   {
00230     case WM_INITDIALOG:
00231       return (BOOL)HANDLE_WM_INITDIALOG(hWnd, wParam, lParam, onInitDialog);
00232     case WM_COMMAND:
00233       HANDLE_WM_COMMAND(hWnd, wParam, lParam, onCommand);
00234       break;
00235     case WM_DESTROY:
00236       HANDLE_WM_DESTROY(hWnd, wParam, lParam, onDestroy);
00237       break;
00238 
00239     default:
00240       return FALSE;
00241   }
00242   return TRUE;
00243 }