www.pudn.com > uoth_src.zip > ManageCharactersDlg.cpp
//----------------------------------------------------------------------------- // // @doc // // @module ManageCharactersDlg.cpp - Allow user to manage characters | // // This module contains the definition the character 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: ManageCharactersDlg.h $ // //----------------------------------------------------------------------------- #include "stdafx.h" #include "resource.h" #include "ManageCharactersDlg.h" #include "Character.h" #include "CharacterDlg.h" //----------------------------------------------------------------------------- // // @mfuncconstructor. // // @rdesc None. // //----------------------------------------------------------------------------- CManageCharactersDlg::CManageCharactersDlg () { } //----------------------------------------------------------------------------- // // @mfunc destructor. // // @rdesc None. // //----------------------------------------------------------------------------- CManageCharactersDlg::~CManageCharactersDlg () { } //----------------------------------------------------------------------------- // // @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 CManageCharactersDlg::OnInitDialog (UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL &bHandled) { // // Center the dialog // CenterWindow (); // // Get the controls // m_lb = GetDlgItem (IDC_CHARACTER_LIST); m_btnDelete = GetDlgItem (IDC_CHARACTER_DELETE); m_btnModify = GetDlgItem (IDC_CHARACTER_MODIFY); m_btnNew = GetDlgItem (IDC_CHARACTER_NEW); // // Populate the listbox // for (int ic = 0; ic < CCharacter::gm_vCharacters .GetCount (); ++ic) m_lb .AddString (CCharacter::gm_vCharacters [ic] .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 CManageCharactersDlg::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 CManageCharactersDlg::OnDblClkList (WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL &bHandled) { return OnModify (wNotifyCode, wID, hWndCtl, bHandled); } //----------------------------------------------------------------------------- // // @mfunc Create a new character // // @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 CManageCharactersDlg::OnNew (WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL &bHandled) { // // Get the current focus // HWND hWndFocus = ::GetFocus (); // // New character // CCharacterDlg dlg (NULL); if (dlg .DoModal () == IDOK) { int nSel = m_lb .AddString (dlg .m_pCharacter ->m_strName); m_lb .SetCurSel (nSel); } // // Restore the focus // if (hWndFocus) ::SetFocus (hWndFocus); // // Update the window // UpdateWindow (); return TRUE; } //----------------------------------------------------------------------------- // // @mfunc Delete a character // // @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 CManageCharactersDlg::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 character to be deleted // CString strCharacter; m_lb .GetText (nSel, strCharacter); CCharacter *pCharacter = CCharacter::Find (strCharacter); if (pCharacter == NULL) //hmmmm return TRUE; // // Delete the character // CCharacter::Delete (pCharacter); m_lb .DeleteString (nSel); // // Update the window // UpdateWindow (); return TRUE; } //----------------------------------------------------------------------------- // // @mfunc Modify a character // // @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 CManageCharactersDlg::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 character to be deleted // CString strCharacter; m_lb .GetText (nSel, strCharacter); CCharacter *pCharacter = CCharacter::Find (strCharacter); if (pCharacter == NULL) //hmmmm return TRUE; // // Get the current focus // HWND hWndFocus = ::GetFocus (); // // New character // CCharacterDlg dlg (pCharacter); if (dlg .DoModal () == IDOK) { m_lb .DeleteString (nSel); nSel = m_lb .AddString (dlg .m_pCharacter ->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 CManageCharactersDlg::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); } }