Back to index

lightning-sunbird  0.9+nobinonly
dlgtstr.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 
00039 #define INCL_WIN
00040 #include <os2.h>
00041 
00042 #include "xp.h"
00043 #include "resource.h"
00044 
00045 #include "plugin.h"
00046 #include "logger.h"
00047 
00048 extern CLogger * pLogger;
00049 
00050 static void onCommand(HWND hWnd, int id, HWND hWndCtl, USHORT codeNotify)
00051 {
00052   CPlugin * pPlugin = (CPlugin *)WinQueryWindowULong(hWnd, QWL_USER);
00053   if(!pPlugin)
00054     return;
00055 
00056   switch (id)
00057   {
00058     case IDC_RADIO_MODE_MANUAL:
00059       if((codeNotify == BN_CLICKED) && (WinQueryButtonCheckstate(hWnd, IDC_RADIO_MODE_MANUAL) == BST_CHECKED))
00060       {
00061         pPlugin->showGUI(sg_manual);
00062         pPlugin->updatePrefs(gp_mode, sg_manual);
00063       }
00064       break;
00065     case IDC_EDIT_LOG_FILE_NAME:
00066       if(codeNotify == EN_CHANGE)
00067       {
00068         char szString[256];
00069         WinQueryWindowText(WinWindowFromID(hWnd, IDC_EDIT_LOG_FILE_NAME), sizeof(szString), szString);
00070         pPlugin->updatePrefs(gp_logfile, FALSE, szString);
00071       }
00072     case IDC_RADIO_MODE_AUTO:
00073       if((codeNotify == BN_CLICKED) && (WinQueryButtonCheckstate(hWnd, IDC_RADIO_MODE_AUTO) == BST_CHECKED))
00074       {
00075         pPlugin->showGUI(sg_auto);
00076         pPlugin->updatePrefs(gp_mode, sg_auto);
00077       }
00078       break;
00079     case IDC_BUTTON_FLUSH:
00080       pLogger->clearTarget();
00081       pLogger->dumpLogToTarget();
00082       break;
00083     case IDC_BUTTON_CLEAR:
00084       pLogger->clearTarget();
00085       pLogger->clearLog();
00086       break;
00087       break;
00088     case IDC_CHECK_LOG_TO_FILE:
00089       if(codeNotify == BN_CLICKED)
00090       {
00091         pPlugin->updatePrefs(gp_tofile, BST_CHECKED == WinQueryButtonCheckstate(hWnd, IDC_CHECK_LOG_TO_FILE));
00092         WinEnableWindow(WinWindowFromID(hWnd, IDC_EDIT_LOG_FILE_NAME), (BST_CHECKED == WinQueryButtonCheckstate(hWnd, IDC_CHECK_LOG_TO_FILE)));
00093         pPlugin->onLogToFile(BST_CHECKED == WinQueryButtonCheckstate(hWnd, IDC_CHECK_LOG_TO_FILE));
00094       }
00095       break;
00096     case IDC_CHECK_LOG_TO_FRAME:
00097       if(codeNotify == BN_CLICKED)
00098       {
00099         pPlugin->updatePrefs(gp_toframe, BST_CHECKED == WinQueryButtonCheckstate(hWnd, IDC_CHECK_LOG_TO_FRAME));
00100         WinEnableWindow(WinWindowFromID(hWnd, IDC_BUTTON_FLUSH), (BST_UNCHECKED == WinQueryButtonCheckstate(hWnd, IDC_CHECK_SHOW_LOG))
00101                                                         && (BST_CHECKED == WinQueryButtonCheckstate(hWnd, IDC_CHECK_LOG_TO_FRAME)));
00102         WinEnableWindow(WinWindowFromID(hWnd, IDC_BUTTON_CLEAR), (BST_CHECKED == WinQueryButtonCheckstate(hWnd, IDC_CHECK_LOG_TO_FRAME)));
00103         WinEnableWindow(WinWindowFromID(hWnd, IDC_CHECK_SHOW_LOG), (BST_CHECKED == WinQueryButtonCheckstate(hWnd, IDC_CHECK_LOG_TO_FRAME)));
00104         pLogger->setLogToFrameFlag(BST_CHECKED == WinQueryButtonCheckstate(hWnd, IDC_CHECK_LOG_TO_FRAME));
00105       }
00106       break;
00107     case IDC_CHECK_SHOW_LOG:
00108       if(codeNotify == BN_CLICKED)
00109       {
00110         pPlugin->updatePrefs(gp_flush, WinQueryButtonCheckstate(hWnd, IDC_CHECK_SHOW_LOG) == BST_CHECKED);
00111         WinEnableWindow(WinWindowFromID(hWnd, IDC_BUTTON_FLUSH), (BST_UNCHECKED == WinQueryButtonCheckstate(hWnd, IDC_CHECK_SHOW_LOG))
00112                                                         && (BST_CHECKED == WinQueryButtonCheckstate(hWnd, IDC_CHECK_LOG_TO_FRAME)));
00113         pLogger->setShowImmediatelyFlag(WinQueryButtonCheckstate(hWnd, IDC_CHECK_SHOW_LOG) == BST_CHECKED);
00114       }
00115       break;
00116     case IDC_CHECK_REMEMBER_LAST:
00117       if(codeNotify == BN_CLICKED)
00118         pPlugin->updatePrefs(gp_rememberlast, WinQueryButtonCheckstate(hWnd, IDC_CHECK_REMEMBER_LAST) == BST_CHECKED);
00119       break;
00120     default:
00121       break;
00122   }
00123 }
00124 
00125 MRESULT EXPENTRY NP_LOADDS ManualDlgProc(HWND, ULONG, MPARAM, MPARAM);
00126 MRESULT EXPENTRY NP_LOADDS AutoDlgProc(HWND, ULONG, MPARAM, MPARAM);
00127 
00128 static BOOL onInitDialog(HWND hWnd, HWND hWndFocus, MPARAM lParam)
00129 {
00130   CPlugin * pPlugin = (CPlugin *)lParam;
00131 
00132   WinSetWindowULong(hWnd, QWL_USER, (ULONG)pPlugin);
00133 
00134   WinSetWindowPos(hWnd, NULL, 0, 0, 0, 0, SWP_SHOW ); 
00135 
00136   HMODULE hInst = pPlugin->getInstance();
00137   HWND hWndManual = WinLoadDlg(hWnd, hWnd, (PFNWP)ManualDlgProc, hInst, IDD_DIALOG_MANUAL, (PVOID)pPlugin);
00138   HWND hWndAuto = WinLoadDlg(hWnd, hWnd, (PFNWP)AutoDlgProc, hInst, IDD_DIALOG_AUTO, (PVOID)pPlugin);
00139 
00140   WinCheckButton(hWnd, (pPlugin->m_Pref_ShowGUI == sg_manual) ? IDC_RADIO_MODE_MANUAL : IDC_RADIO_MODE_AUTO, BST_CHECKED);
00141 
00142   WinSetWindowText(WinWindowFromID(hWnd, IDC_EDIT_LOG_FILE_NAME), pPlugin->m_Pref_szLogFile);
00143 
00144   WinCheckButton(hWnd, IDC_CHECK_LOG_TO_FILE, (pPlugin->m_Pref_bToFile) ? BST_CHECKED : BST_UNCHECKED);
00145   WinEnableWindow(WinWindowFromID(hWnd, IDC_EDIT_LOG_FILE_NAME), (BST_CHECKED == WinQueryButtonCheckstate(hWnd, IDC_CHECK_LOG_TO_FILE)));
00146 
00147   WinCheckButton(hWnd, IDC_CHECK_LOG_TO_FRAME, (pPlugin->m_Pref_bToFrame) ? BST_CHECKED : BST_UNCHECKED);
00148   WinEnableWindow(WinWindowFromID(hWnd, IDC_BUTTON_CLEAR), (BST_CHECKED == WinQueryButtonCheckstate(hWnd, IDC_CHECK_LOG_TO_FRAME)));
00149   WinEnableWindow(WinWindowFromID(hWnd, IDC_CHECK_SHOW_LOG), (BST_CHECKED == WinQueryButtonCheckstate(hWnd, IDC_CHECK_LOG_TO_FRAME)));
00150 
00151   WinCheckButton(hWnd, IDC_CHECK_SHOW_LOG, (pPlugin->m_Pref_bFlushNow) ? BST_CHECKED : BST_UNCHECKED);
00152   WinCheckButton(hWnd, IDC_CHECK_REMEMBER_LAST, (pPlugin->m_Pref_bRememberLastCall) ? BST_CHECKED : BST_UNCHECKED);
00153 
00154   WinEnableWindow(WinWindowFromID(hWnd, IDC_BUTTON_FLUSH), (BST_UNCHECKED == WinQueryButtonCheckstate(hWnd, IDC_CHECK_SHOW_LOG))
00155                                                   && (BST_CHECKED == WinQueryButtonCheckstate(hWnd, IDC_CHECK_LOG_TO_FRAME)));
00156 
00157   pPlugin->onInit(hWnd, hWndManual, hWndAuto);
00158 
00159   pPlugin->showGUI(pPlugin->m_Pref_ShowGUI);
00160 
00161   return TRUE;
00162 }
00163 
00164 static void onDestroy(HWND hWnd)
00165 {
00166   CPlugin * pPlugin = (CPlugin *)WinQueryWindowULong(hWnd, QWL_USER);
00167   pPlugin->onDestroy();
00168 }
00169 
00170 MRESULT EXPENTRY NP_LOADDS TesterDlgProc(HWND hWnd, ULONG msg, MPARAM mp1, MPARAM mp2)
00171 {
00172   switch(msg)
00173   {
00174     case WM_INITDLG:
00175       onInitDialog(hWnd, 0, mp2);
00176       return (MRESULT) FALSE;
00177     case WM_COMMAND:
00178     case WM_CONTROL:
00179       onCommand(hWnd, SHORT1FROMMP(mp1), 0, SHORT2FROMMP(mp1));
00180       break;
00181     case WM_DESTROY:
00182       onDestroy(hWnd);
00183       break;
00184 
00185     default:
00186       return WinDefDlgProc(hWnd, msg, mp1, mp2);
00187   }
00188   return (MRESULT)TRUE;
00189 }