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 #include "xp.h"
00039 
00040 #include <windowsx.h>
00041 
00042 #include "resource.h"
00043 
00044 #include "plugin.h"
00045 #include "logger.h"
00046 
00047 extern CLogger * pLogger;
00048 
00049 static void onCommand(HWND hWnd, int id, HWND hWndCtl, UINT codeNotify)
00050 {
00051   CPlugin * pPlugin = (CPlugin *)GetWindowLong(hWnd, DWL_USER);
00052   if(!pPlugin)
00053     return;
00054 
00055   switch (id)
00056   {
00057     case IDC_RADIO_MODE_MANUAL:
00058       if((codeNotify == BN_CLICKED) && (IsDlgButtonChecked(hWnd, IDC_RADIO_MODE_MANUAL) == BST_CHECKED))
00059       {
00060         pPlugin->showGUI(sg_manual);
00061         pPlugin->updatePrefs(gp_mode, sg_manual);
00062       }
00063       break;
00064     case IDC_EDIT_LOG_FILE_NAME:
00065       if(codeNotify == EN_CHANGE)
00066       {
00067         char szString[256];
00068         Edit_GetText(GetDlgItem(hWnd, IDC_EDIT_LOG_FILE_NAME), szString, sizeof(szString));
00069         pPlugin->updatePrefs(gp_logfile, FALSE, szString);
00070       }
00071     case IDC_RADIO_MODE_AUTO:
00072       if((codeNotify == BN_CLICKED) && (IsDlgButtonChecked(hWnd, IDC_RADIO_MODE_AUTO) == BST_CHECKED))
00073       {
00074         pPlugin->showGUI(sg_auto);
00075         pPlugin->updatePrefs(gp_mode, sg_auto);
00076       }
00077       break;
00078     case IDC_BUTTON_FLUSH:
00079       pLogger->clearTarget();
00080       pLogger->dumpLogToTarget();
00081       break;
00082     case IDC_BUTTON_CLEAR:
00083       pLogger->clearTarget();
00084       pLogger->clearLog();
00085       break;
00086       break;
00087     case IDC_CHECK_LOG_TO_FILE:
00088       if(codeNotify == BN_CLICKED)
00089       {
00090         pPlugin->updatePrefs(gp_tofile, BST_CHECKED == IsDlgButtonChecked(hWnd, IDC_CHECK_LOG_TO_FILE));
00091         EnableWindow(GetDlgItem(hWnd, IDC_EDIT_LOG_FILE_NAME), (BST_CHECKED == IsDlgButtonChecked(hWnd, IDC_CHECK_LOG_TO_FILE)));
00092         pPlugin->onLogToFile(BST_CHECKED == IsDlgButtonChecked(hWnd, IDC_CHECK_LOG_TO_FILE));
00093       }
00094       break;
00095     case IDC_CHECK_LOG_TO_FRAME:
00096       if(codeNotify == BN_CLICKED)
00097       {
00098         pPlugin->updatePrefs(gp_toframe, BST_CHECKED == IsDlgButtonChecked(hWnd, IDC_CHECK_LOG_TO_FRAME));
00099         EnableWindow(GetDlgItem(hWnd, IDC_BUTTON_FLUSH), (BST_UNCHECKED == IsDlgButtonChecked(hWnd, IDC_CHECK_SHOW_LOG))
00100                                                         && (BST_CHECKED == IsDlgButtonChecked(hWnd, IDC_CHECK_LOG_TO_FRAME)));
00101         EnableWindow(GetDlgItem(hWnd, IDC_BUTTON_CLEAR), (BST_CHECKED == IsDlgButtonChecked(hWnd, IDC_CHECK_LOG_TO_FRAME)));
00102         EnableWindow(GetDlgItem(hWnd, IDC_CHECK_SHOW_LOG), (BST_CHECKED == IsDlgButtonChecked(hWnd, IDC_CHECK_LOG_TO_FRAME)));
00103         pLogger->setLogToFrameFlag(BST_CHECKED == IsDlgButtonChecked(hWnd, IDC_CHECK_LOG_TO_FRAME));
00104       }
00105       break;
00106     case IDC_CHECK_SHOW_LOG:
00107       if(codeNotify == BN_CLICKED)
00108       {
00109         pPlugin->updatePrefs(gp_flush, IsDlgButtonChecked(hWnd, IDC_CHECK_SHOW_LOG) == BST_CHECKED);
00110         EnableWindow(GetDlgItem(hWnd, IDC_BUTTON_FLUSH), (BST_UNCHECKED == IsDlgButtonChecked(hWnd, IDC_CHECK_SHOW_LOG))
00111                                                         && (BST_CHECKED == IsDlgButtonChecked(hWnd, IDC_CHECK_LOG_TO_FRAME)));
00112         pLogger->setShowImmediatelyFlag(IsDlgButtonChecked(hWnd, IDC_CHECK_SHOW_LOG) == BST_CHECKED);
00113       }
00114       break;
00115     case IDC_CHECK_REMEMBER_LAST:
00116       if(codeNotify == BN_CLICKED)
00117         pPlugin->updatePrefs(gp_rememberlast, IsDlgButtonChecked(hWnd, IDC_CHECK_REMEMBER_LAST) == BST_CHECKED);
00118       break;
00119     default:
00120       break;
00121   }
00122 }
00123 
00124 BOOL CALLBACK NP_LOADDS ManualDlgProc(HWND, UINT, WPARAM, LPARAM);
00125 BOOL CALLBACK NP_LOADDS AutoDlgProc(HWND, UINT, WPARAM, LPARAM);
00126 
00127 static BOOL onInitDialog(HWND hWnd, HWND hWndFocus, LPARAM lParam)
00128 {
00129   CPlugin * pPlugin = (CPlugin *)lParam;
00130 
00131   SetWindowLong(hWnd, DWL_USER, (long)pPlugin);
00132 
00133   SetWindowPos(hWnd, NULL, 0,0, 0,0, SWP_NOZORDER | SWP_NOSIZE);
00134 
00135   HINSTANCE hInst = pPlugin->getInstance();
00136   HWND hWndManual = CreateDialogParam(hInst, MAKEINTRESOURCE(IDD_DIALOG_MANUAL), hWnd, (DLGPROC)ManualDlgProc, (LPARAM)pPlugin);
00137   HWND hWndAuto = CreateDialogParam(hInst, MAKEINTRESOURCE(IDD_DIALOG_AUTO), hWnd, (DLGPROC)AutoDlgProc, (LPARAM)pPlugin);
00138 
00139   CheckRadioButton(hWnd, IDC_RADIO_MODE_MANUAL, IDC_RADIO_MODE_AUTO, 
00140                   (pPlugin->m_Pref_ShowGUI == sg_manual) ? IDC_RADIO_MODE_MANUAL : IDC_RADIO_MODE_AUTO);
00141 
00142   Edit_SetText(GetDlgItem(hWnd, IDC_EDIT_LOG_FILE_NAME), pPlugin->m_Pref_szLogFile);
00143 
00144   CheckDlgButton(hWnd, IDC_CHECK_LOG_TO_FILE, (pPlugin->m_Pref_bToFile) ? BST_CHECKED : BST_UNCHECKED);
00145   EnableWindow(GetDlgItem(hWnd, IDC_EDIT_LOG_FILE_NAME), (BST_CHECKED == IsDlgButtonChecked(hWnd, IDC_CHECK_LOG_TO_FILE)));
00146 
00147   CheckDlgButton(hWnd, IDC_CHECK_LOG_TO_FRAME, (pPlugin->m_Pref_bToFrame) ? BST_CHECKED : BST_UNCHECKED);
00148   EnableWindow(GetDlgItem(hWnd, IDC_BUTTON_CLEAR), (BST_CHECKED == IsDlgButtonChecked(hWnd, IDC_CHECK_LOG_TO_FRAME)));
00149   EnableWindow(GetDlgItem(hWnd, IDC_CHECK_SHOW_LOG), (BST_CHECKED == IsDlgButtonChecked(hWnd, IDC_CHECK_LOG_TO_FRAME)));
00150 
00151   CheckDlgButton(hWnd, IDC_CHECK_SHOW_LOG, (pPlugin->m_Pref_bFlushNow) ? BST_CHECKED : BST_UNCHECKED);
00152   CheckDlgButton(hWnd, IDC_CHECK_REMEMBER_LAST, (pPlugin->m_Pref_bRememberLastCall) ? BST_CHECKED : BST_UNCHECKED);
00153 
00154   EnableWindow(GetDlgItem(hWnd, IDC_BUTTON_FLUSH), (BST_UNCHECKED == IsDlgButtonChecked(hWnd, IDC_CHECK_SHOW_LOG))
00155                                                   && (BST_CHECKED == IsDlgButtonChecked(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 *)GetWindowLong(hWnd, DWL_USER);
00167   pPlugin->onDestroy();
00168 }
00169 
00170 BOOL CALLBACK NP_LOADDS TesterDlgProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
00171 {
00172   switch(msg)
00173   {
00174     case WM_INITDIALOG:
00175       return (BOOL)HANDLE_WM_INITDIALOG(hWnd, wParam, lParam, onInitDialog);
00176     case WM_COMMAND:
00177       HANDLE_WM_COMMAND(hWnd, wParam, lParam, onCommand);
00178       break;
00179     case WM_DESTROY:
00180       HANDLE_WM_DESTROY(hWnd, wParam, lParam, onDestroy);
00181       break;
00182 
00183     default:
00184       return FALSE;
00185   }
00186   return TRUE;
00187 }