www.pudn.com > uoth_src.zip > ManageRuneLibrariesDlg.cpp
//----------------------------------------------------------------------------- // // @doc // // @module ManageRuneLibrariesDlg.cpp - Allow user to manage rune libraries | // // This module contains the definition the rune library manager // // Copyright (c) 2002 - Descartes Systems Sciences, Inc. // // All rights reserved. // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are // met: // // 1. Redistributions of source code must retain the above copyright notice, // this list of conditions and the following disclaimer. // 2. Neither the name of Descartes Systems Sciences, Inc nor the names of // its contributors may be used to endorse or promote products derived // from this software without specific prior written permission. // // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED // TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. // // @end // // $History: ManageRuneLibrariesDlg.h $ // //----------------------------------------------------------------------------- #include "stdafx.h" #include "resource.h" #include "ManageRuneLibrariesDlg.h" #include "RuneLibrary.h" #include "RuneLibraryDlg.h" // // Externals // extern TCHAR g_szAppName []; //----------------------------------------------------------------------------- // // @mfuncconstructor. // // @rdesc None. // //----------------------------------------------------------------------------- CManageRuneLibrariesDlg::CManageRuneLibrariesDlg () { } //----------------------------------------------------------------------------- // // @mfunc destructor. // // @rdesc None. // //----------------------------------------------------------------------------- CManageRuneLibrariesDlg::~CManageRuneLibrariesDlg () { } //----------------------------------------------------------------------------- // // @mfunc Initialize the dialog // // @parm UINT | uMsg | Message // // @parm WPARAM | wParam | Message w-parameter // // @parm LPARAM | lParam | Message l-parameter // // @parm BOOL & | bHandled | If handled, set to true // // @rdesc Routine results // //----------------------------------------------------------------------------- LRESULT CManageRuneLibrariesDlg::OnInitDialog (UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL &bHandled) { // // Center the dialog // CenterWindow (); // // Get the controls // m_lb = GetDlgItem (IDC_RUNE_LIBRARY_LIST); m_btnDelete = GetDlgItem (IDC_RUNE_LIBRARY_DELETE); m_btnModify = GetDlgItem (IDC_RUNE_LIBRARY_MODIFY); m_btnNew = GetDlgItem (IDC_RUNE_LIBRARY_NEW); // // Populate the listbox // for (int irl = 0; irl < CRuneLibrary::gm_vRuneLibraries .GetCount (); ++irl) m_lb .AddString (CRuneLibrary::gm_vRuneLibraries [irl] .m_strName); // // Select the first lb item // m_lb .SetCurSel (0); UpdateWindow (); return TRUE; } //----------------------------------------------------------------------------- // // @mfunc Handle the user press Ok // // @parm WORD | wNotifyCode | Command notification code // // @parm WORD | wID | ID of the control // // @parm HWND | hWndCtl | Handle of the control // // @parm BOOL & | bHandled | If handled, set to true // // @rdesc Routine results // //----------------------------------------------------------------------------- LRESULT CManageRuneLibrariesDlg::OnClose (WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled) { EndDialog (IDOK); return TRUE; } //----------------------------------------------------------------------------- // // @mfunc Handle a selection double click // // @parm WORD | wNotifyCode | Command notification code // // @parm WORD | wID | ID of the control // // @parm HWND | hWndCtl | Handle of the control // // @parm BOOL & | bHandled | If handled, set to true // // @rdesc Routine results // //----------------------------------------------------------------------------- LRESULT CManageRuneLibrariesDlg::OnDblClkList (WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL &bHandled) { return OnModify (wNotifyCode, wID, hWndCtl, bHandled); } //----------------------------------------------------------------------------- // // @mfunc Create a new rune library // // @parm WORD | wNotifyCode | Command notification code // // @parm WORD | wID | ID of the control // // @parm HWND | hWndCtl | Handle of the control // // @parm BOOL & | bHandled | If handled, set to true // // @rdesc Routine results // //----------------------------------------------------------------------------- LRESULT CManageRuneLibrariesDlg::OnNew (WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL &bHandled) { // // Get the current focus // HWND hWndFocus = ::GetFocus (); // // New rune library // CRuneLibraryDlg dlg (NULL); if (dlg .DoModal () == IDOK) { int nSel = m_lb .AddString (dlg .m_pRuneLibrary ->m_strName); m_lb .SetCurSel (nSel); } // // Restore the focus // if (hWndFocus) ::SetFocus (hWndFocus); // // Update the window // UpdateWindow (); return TRUE; } //----------------------------------------------------------------------------- // // @mfunc Delete a rune library // // @parm WORD | wNotifyCode | Command notification code // // @parm WORD | wID | ID of the control // // @parm HWND | hWndCtl | Handle of the control // // @parm BOOL & | bHandled | If handled, set to true // // @rdesc Routine results // //----------------------------------------------------------------------------- LRESULT CManageRuneLibrariesDlg::OnDelete (WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL &bHandled) { // // Get the current selection // int nSel = m_lb .GetCurSel (); if (nSel < 0) return TRUE; // // Get the text of the rune library to be deleted // CString strRuneLibrary; m_lb .GetText (nSel, strRuneLibrary); CRuneLibrary *pRuneLibrary = CRuneLibrary::Find (strRuneLibrary); if (pRuneLibrary == NULL) //hmmmm return TRUE; // // Check for perm // if (pRuneLibrary ->m_fPerm) { CString str; str .Format (IDS_ERR_PERM_RUNE_LIBRARY); ::MessageBox (m_hWnd, str, g_szAppName, MB_OK); return TRUE; } // // Delete the rune library // CRuneLibrary::Delete (pRuneLibrary); m_lb .DeleteString (nSel); // // Update the window // UpdateWindow (); return TRUE; } //----------------------------------------------------------------------------- // // @mfunc Modify a rune library // // @parm WORD | wNotifyCode | Command notification code // // @parm WORD | wID | ID of the control // // @parm HWND | hWndCtl | Handle of the control // // @parm BOOL & | bHandled | If handled, set to true // // @rdesc Routine results // //----------------------------------------------------------------------------- LRESULT CManageRuneLibrariesDlg::OnModify (WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL &bHandled) { // // Get the current selection // int nSel = m_lb .GetCurSel (); if (nSel < 0) return TRUE; // // Get the text of the rune library to be deleted // CString strRuneLibrary; m_lb .GetText (nSel, strRuneLibrary); CRuneLibrary *pRuneLibrary = CRuneLibrary::Find (strRuneLibrary); if (pRuneLibrary == NULL) //hmmmm return TRUE; // // Check for perm // if (pRuneLibrary ->m_fPerm) { CString str; str .Format (IDS_ERR_PERM_RUNE_LIBRARY); ::MessageBox (m_hWnd, str, g_szAppName, MB_OK); return TRUE; } // // Get the current focus // HWND hWndFocus = ::GetFocus (); // // Edit rune library // CRuneLibraryDlg dlg (pRuneLibrary); if (dlg .DoModal () == IDOK) { m_lb .DeleteString (nSel); nSel = m_lb .AddString (dlg .m_pRuneLibrary ->m_strName); m_lb .SetCurSel (nSel); } // // Restore the focus // if (hWndFocus) ::SetFocus (hWndFocus); // // Update the window // UpdateWindow (); return TRUE; } //----------------------------------------------------------------------------- // // @mfunc Update the window controls // // @rdesc None. // //----------------------------------------------------------------------------- void CManageRuneLibrariesDlg::UpdateWindow () { // // Enable/Disable the toolbar buttons // if (m_lb .GetCurSel () >= 0) { m_btnDelete .EnableWindow (TRUE); m_btnModify .EnableWindow (TRUE); } else { m_btnDelete .EnableWindow (FALSE); m_btnModify .EnableWindow (FALSE); } }