www.pudn.com > uoth_src.zip > RegionWnd.cpp
//----------------------------------------------------------------------------- // // @doc // // @module RegionWnd.cpp - Main window | // // This module contains the main window. // // 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: Cnf.cpp $ // //----------------------------------------------------------------------------- #include "stdafx.h" #include "resource.h" #include "RegionWnd.h" #include "MainWnd.h" #include "uoth.h" #include "AddRemoveMapDlg.h" #include "Treasure.h" #include "Region.h" #include "Filter.h" #include "TreasureInfoDlg.h" #include "Scroll.h" // // Debug NEW // #if defined (_DEBUG) #define new DEBUG_NEW #undef THIS_FILE static char THIS_FILE[] = __FILE__; #endif // // Global variables // extern TCHAR g_szAppName []; extern HCURSOR g_hcurMagnify; extern bool g_fPrettyDrawing; extern CSize g_sizeSmallMap; extern CFilter g_sFilter; // // External sizing definitions // extern CPoint g_ptTackHead; // // Sizing values // CSize g_sizeSmallMap (246, 262); CSize g_sizeLargeMap (480, 440); //----------------------------------------------------------------------------- // // @mfuncconstructor. // // @rdesc None. // //----------------------------------------------------------------------------- CRegionWnd::CRegionWnd () : m_scrollRight (ScrollBorder_Thick, true, RGB (232, 204, 148)), m_scrollName (ScrollBorder_Thin, true, RGB (232, 204, 148)), m_scrollCoords (ScrollBorder_Thin, true, RGB (232, 204, 148)), m_scrollLeft (ScrollBorder_Thick, true, RGB (232, 204, 148)) { static const CSize sizeSmallName (211, 50); static const CSize sizeSmallCoords (276, 50); // // Basic initialization // m_nTreasure = 0; m_nOverTreasure = 0; m_panTreasures = new int [CTreasure::gm_vTreasures .GetCount ()]; // // Get the pane rects // m_rectLeftPane = CRect (0, 0, 280, 440); m_rectRightPane = CRect (CPoint (m_rectLeftPane .right, 0), g_sizeLargeMap); // // Compute the margin for the scrolls // int nMargin = (m_rectLeftPane .Height () - g_sizeSmallMap .cy) / 2 - sizeSmallName .cy - 10; // // Initialize the scroll rects // m_scrollRight .SetScrollRect (m_rectRightPane); m_scrollName .SetScrollRect (CRect ( CPoint ((m_rectLeftPane .Width () - sizeSmallName .cx) / 2, nMargin), sizeSmallName)); m_scrollCoords .SetScrollRect (CRect ( CPoint ((m_rectLeftPane .Width () - sizeSmallCoords .cx) / 2, m_rectLeftPane .Height () - nMargin - sizeSmallCoords .cy), sizeSmallCoords)); m_scrollLeft .SetScrollRect (CRect ( CPoint ((m_rectLeftPane .Width () - g_sizeSmallMap .cx) / 2, (m_rectLeftPane .Height () - g_sizeSmallMap .cy) / 2), g_sizeSmallMap)); } //----------------------------------------------------------------------------- // // @mfunc destructor. // // @rdesc None. // //----------------------------------------------------------------------------- CRegionWnd::~CRegionWnd () { delete [] m_panTreasures; } //----------------------------------------------------------------------------- // // @mfunc Create the window // // @parm CMainWnd * | pMainWnd | Pointer to the main window // // @rdesc Handle of the window // //----------------------------------------------------------------------------- HWND CRegionWnd::Create (CMainWnd *pMainWnd) { // // Save the window pointer // m_pMainWnd = pMainWnd; // // Create this window // DWORD dwExStyle = WS_EX_CLIENTEDGE; DWORD dwStyle = WS_CHILD | WS_CLIPCHILDREN; HWND hWnd = CScrollWindowImpl ::Create (pMainWnd ->m_hWnd, rcDefault, _T ( "Map Window"), dwStyle, dwExStyle, 1, NULL); if (hWnd == NULL) return NULL; // // Return the window handle // return hWnd; } //----------------------------------------------------------------------------- // // @mfunc Initialize the window // // @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 CRegionWnd::OnCreate (UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL &bHandled) { // // Load the regions // SetRegion (0, 0); // // Set the scroll size // SetScrollOffset (0, 0, FALSE); SetScrollSize (m_rectRightPane .right, m_rectRightPane .bottom); // // Return FALSE // bHandled = FALSE; return false; } //----------------------------------------------------------------------------- // // @mfunc Paint the window // // @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 CRegionWnd::OnPaint (UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL &bHandled) { // // Get the DC // PAINTSTRUCT ps; BeginPaint (&ps); HDC hdcDraw = ps .hdc; // // Get the clip rect and compute the real rect being drawn // CRect rectClip; ::GetClipBox (ps .hdc, &rectClip); CRect rect (rectClip); ::OffsetRect (&rect, m_ptOffset .x, m_ptOffset .y); rect .NormalizeRect (); // // Create a bitmap to use for drawing // Offset origin more because bitmap is just piece of the whole drawing // HDC hDC = NULL; HBITMAP hbitmap = NULL; HGDIOBJ hbmOld = NULL; if (g_fPrettyDrawing) { hDC = ::CreateCompatibleDC (ps .hdc); if (hDC) { hbitmap = ::CreateCompatibleBitmap ( ps .hdc, rect .Width (), rect .Height ()); if (hbitmap != NULL) { hdcDraw = hDC; ::OffsetViewportOrgEx (hDC, -rect .left, -rect .top, NULL); hbmOld = ::SelectObject (hDC, hbitmap); } } } // // Draw // Draw (hdcDraw); // // If the bitmap was used, copy the bitmap to the window // if (hdcDraw != ps .hdc) { ::BitBlt (ps .hdc, rectClip .left, rectClip .top, rectClip .Width (), rectClip .Height (), hDC, rect .left, rect .top, SRCCOPY); ::SelectObject (hDC, hbmOld); ::DeleteObject (hbitmap); } if (hDC != NULL) ::DeleteDC (hDC); // // End painting // EndPaint (&ps); return TRUE; } //----------------------------------------------------------------------------- // // @mfunc Draw the window // // @parm HDC | hDC | Destination DC // // @rdesc None. // //----------------------------------------------------------------------------- void CRegionWnd::Draw (HDC hDC) { static const CSize sizeSmallName (211, 50); static const CSize sizeSmallCoords (276, 50); // // Compute the margin // int nMargin = (m_rectLeftPane .Height () - g_sizeSmallMap .cy) / 2 - sizeSmallName .cy - 10; // // Set the background color // ::SetBkColor (hDC, m_scrollRight .GetBackgroundColor ()); ::SetBkMode (hDC, TRANSPARENT); // // Draw the right side map // m_scrollRight .DrawMap (hDC, m_rectRegionMap, m_panTreasures, m_nTreasures, true, &g_sFilter, false); // // Erase the left hand side // ::ExtTextOut (hDC, 0, 0, ETO_OPAQUE, &m_rectLeftPane, NULL, 0, NULL); // // Draw the treasure name // { TCHAR szText [128]; if (m_nTreasure > 0) { _sntprintf (szText, _countof (szText), _T ( "%d - %s"), m_nTreasure, (LPCTSTR) CTreasure::gm_vTreasures [m_nTreasure] .m_strName); } else szText [0] = 0; m_scrollName .DrawText (hDC, szText); } // // Draw the treasure map // { if (m_nTreasure > 0) { m_scrollLeft .DrawMap (hDC, m_rectTreasureMap, &m_nTreasure, 1, false, &g_sFilter, false); } else m_scrollLeft .Draw (hDC); } // // Draw the treasure coords // { // // Generate the text // TCHAR szText [128]; if (m_nTreasure > 0) { FormatCoords ( CTreasure::gm_vTreasures [m_nTreasure] .m_x, CTreasure::gm_vTreasures [m_nTreasure] .m_y, szText, _countof (szText)); } else szText [0] = 0; // // Draw the text // m_scrollCoords .DrawText (hDC, szText); } // // Draw the border if needed // CRect rect; GetClientRect (&rect); if (rect .right > m_rectRightPane .right) { CRect rect2 (m_rectRightPane .right, 0, rect .right, rect .bottom); ::ExtTextOut (hDC, 0, 0, ETO_OPAQUE, &rect2, NULL, 0, NULL); } if (rect .bottom > m_rectRightPane .bottom) { CRect rect2 (0, m_rectRightPane .bottom, m_rectRightPane .right, rect .bottom); ::ExtTextOut (hDC, 0, 0, ETO_OPAQUE, &rect2, NULL, 0, NULL); } } //----------------------------------------------------------------------------- // // @mfunc Handle window mouse move // // @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 CRegionWnd::OnMouseMove (UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL &bHandled) { // // Test what the mouse is over // CPoint pt ( LOWORD (lParam) + m_ptOffset .x, HIWORD (lParam) + m_ptOffset .y); int nOverTreasure = TreasureHitTest (pt); if (m_nOverTreasure != nOverTreasure) { // // Update the treasure // m_nOverTreasure = nOverTreasure; // // Update the status bar // if (m_nOverTreasure == 0) { m_pMainWnd ->SetStatusBarText (NULL); } else { CString str; str .Format (IDS_TREASURE_STATUS, m_nOverTreasure, (LPCTSTR) CTreasure::gm_vTreasures [m_nOverTreasure] .m_strName); m_pMainWnd ->SetStatusBarText (str); } } return TRUE; } //----------------------------------------------------------------------------- // // @mfunc Handle window mouse leaving client area // // @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 CRegionWnd::OnMouseLeave (UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL &bHandled) { // // Clear over // m_nOverTreasure = 0; // // Set the status text // m_pMainWnd ->SetStatusBarText (NULL); return TRUE; } //----------------------------------------------------------------------------- // // @mfunc Handle cursor query // // @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 CRegionWnd::OnSetCursor (UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL &bHandled) { if (m_nOverTreasure > 0) { ::SetCursor (g_hcurMagnify); return TRUE; } else return DefWindowProc (uMsg, wParam, lParam); } //----------------------------------------------------------------------------- // // @mfunc Set the region // // @parm int | nRegion | Region number // // @parm int | nTreasure | Treasure number // // @rdesc None. // //----------------------------------------------------------------------------- void CRegionWnd::SetRegion (int nRegion, int nTreasure) { // // Save the region number // m_nRegion = nRegion; // // Get the map // m_scrollRight .GetRegionMap (m_nRegion, &m_nTreasures, m_panTreasures, &m_rectRegionMap); // // Reset the treasure // SetTreasure (nTreasure); m_nOverTreasure = 0; // // Invalidate the rect // if (m_hWnd) { InvalidateRect (&m_rectRightPane, FALSE); } } //----------------------------------------------------------------------------- // // @mfunc Set the treasure // // @parm int | nTreasure | Treasure number // // @rdesc None. // //----------------------------------------------------------------------------- void CRegionWnd::SetTreasure (int nTreasure) { // // Get a default treasure // if (nTreasure != 0) nTreasure = GetDefaultTreasure (nTreasure); // // Save the treasure // m_nTreasure = nTreasure; // // If we have a treasure, compute the rect // if (m_nTreasure > 0) { // // Get the map rect // CPoint pt ( CTreasure::gm_vTreasures [m_nTreasure] .m_x, CTreasure::gm_vTreasures [m_nTreasure] .m_y); CScroll::GetMapAt (ScrollBorder_Thick, pt, g_sizeSmallMap, &m_rectTreasureMap); } // // Invalidate the rect // if (m_hWnd) { InvalidateRect (&m_rectLeftPane, FALSE); InvalidateRect (&m_rectRightPane, FALSE); } } //----------------------------------------------------------------------------- // // @mfunc Do a treasure hit test // // @parm POINT | pt | Point // // @rdesc Index of the region or -1 // //----------------------------------------------------------------------------- int CRegionWnd::TreasureHitTest (POINT pt) { // // Get the rectangle for the map // CRect rectRight (m_rectRightPane); m_scrollRight .DeflateRect (&rectRight); // // Adjust the point for the rectangle and tack error // CPoint ptTackError (0, 0); CScroll::AdjustForTackError (&ptTackError); pt .x -= (rectRight .left + ptTackError .x); pt .y -= (rectRight .top + ptTackError .y); // // Loop through the labels // CPoint ptLabel ( pt .x + m_rectRegionMap .left, pt .y + m_rectRegionMap .top); for (int i = 0; i < m_nTreasures; i++) { if (g_sFilter .IsTackFilterEnabled () && !g_sFilter .DoesTreasureHaveMap (m_panTreasures [i])) continue; CTreasure *pTreasure = &CTreasure::gm_vTreasures [m_panTreasures [i]]; if (::PtInRect (&pTreasure ->m_rectLabel, ptLabel)) return pTreasure ->m_nIndex; } // // Loop through making the tests // CPoint ptTack ( pt .x - g_ptTackHead .x, pt .y - g_ptTackHead .y); int nBest = 0; int nBestDist = 8 * 8; for (int i = 0; i < m_nTreasures; i++) { CTreasure *pTreasure = &CTreasure::gm_vTreasures [m_panTreasures [i]]; CPoint ptTreasure ( ((pTreasure ->m_x / 2) - m_rectRegionMap .left), ((pTreasure ->m_y / 2) - m_rectRegionMap .top)); int nDX = ptTack .x - ptTreasure .x; int nDY = ptTack .y - ptTreasure .y; int nDist = (nDX * nDX) + (nDY * nDY); if (nBestDist > nDist) { nBest = pTreasure ->m_nIndex; nBestDist = nDist; } } return nBest; } //----------------------------------------------------------------------------- // // @mfunc Handle window mouse left button down // // @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 CRegionWnd::OnLButtonDown (UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL &bHandled) { // // Test what the mouse is over // CPoint pt ( LOWORD (lParam) + m_ptOffset .x, HIWORD (lParam) + m_ptOffset .y); m_nOverTreasureClick = TreasureHitTest (pt); // // Capture the mouse // SetCapture (); return TRUE; } //----------------------------------------------------------------------------- // // @mfunc Handle window mouse left button up // // @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 CRegionWnd::OnLButtonUp (UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL &bHandled) { // // If nothing going on, return // if (GetCapture () != m_hWnd) return TRUE; ReleaseCapture (); // // Test what the mouse is over // CPoint pt ( LOWORD (lParam) + m_ptOffset .x, HIWORD (lParam) + m_ptOffset .y); int nOverTreasureClick = TreasureHitTest (pt); if (nOverTreasureClick == m_nOverTreasureClick && nOverTreasureClick > 0) { SetTreasure (nOverTreasureClick); } return TRUE; } //----------------------------------------------------------------------------- // // @mfunc Handle idle processing // // @parm CUpdateUIBase * | pUpdateUI | Pointer to update UI object // // @rdesc Idle return status. // //----------------------------------------------------------------------------- BOOL CRegionWnd::OnIdle (CUpdateUIBase *pUpdateUI) { pUpdateUI ->UIEnable (ID_EDIT_COPY, m_nTreasure != 0); pUpdateUI ->UIEnable (ID_EDIT_NEXT_REGION, CRegion::GetNext (m_nRegion, true, &g_sFilter)); pUpdateUI ->UIEnable (ID_EDIT_PREVIOUS_REGION, CRegion::GetNext (m_nRegion, false, &g_sFilter)); pUpdateUI ->UIEnable (ID_EDIT_NEXT_TREASURE, CTreasure::GetNext (m_nTreasure, true, &g_sFilter)); pUpdateUI ->UIEnable (ID_EDIT_PREVIOUS_TREASURE, CTreasure::GetNext (m_nTreasure, false, &g_sFilter)); return FALSE; } //----------------------------------------------------------------------------- // // @mfunc View the treasure information // // @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 CRegionWnd::OnViewTreasureInformation (WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL &bHandled) { // // Get the selected treasure // int nTreasure = GetDefaultTreasure (m_nTreasure); // // Display the dialog // CTreasureInfoDlg::Show (nTreasure); return TRUE; } //----------------------------------------------------------------------------- // // @mfunc Edit treasure map counts // // @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 CRegionWnd::OnEditIJustGot (WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL &bHandled) { // // Display the dialog // CAddRemoveMapDlg dlg (m_nTreasure, wID == ID_EDIT_I_JUST_GOT); dlg .DoModal (); return TRUE; } //----------------------------------------------------------------------------- // // @mfunc Handle a key down // // @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 CRegionWnd::OnKeyDown (UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL &bHandled) { // // Not handled // bHandled = FALSE; // // If no treasure, return // if (m_nTreasure == 0) return FALSE; #if ENABLE_DATA_EDIT // // ... // bool fMoved = false; if (GetKeyState (VK_SHIFT) & 0x80) { if (wParam == VK_UP) { CTreasure::gm_vTreasures [m_nTreasure] .m_yLabel -= 2; fMoved = true; } else if (wParam == VK_DOWN) { CTreasure::gm_vTreasures [m_nTreasure] .m_yLabel += 2; fMoved = true; } else if (wParam == VK_LEFT) { CTreasure::gm_vTreasures [m_nTreasure] .m_xLabel -= 2; fMoved = true; } else if (wParam == VK_RIGHT) { CTreasure::gm_vTreasures [m_nTreasure] .m_xLabel += 2; fMoved = true; } } else { if (wParam == VK_UP) { CTreasure::gm_vTreasures [m_nTreasure] .m_y -= 1; fMoved = true; } else if (wParam == VK_DOWN) { CTreasure::gm_vTreasures [m_nTreasure] .m_y += 1; fMoved = true; } else if (wParam == VK_LEFT) { CTreasure::gm_vTreasures [m_nTreasure] .m_x -= 1; fMoved = true; } else if (wParam == VK_RIGHT) { CTreasure::gm_vTreasures [m_nTreasure] .m_x += 1; fMoved = true; } } // // ... // if (fMoved) { CTreasure::InitializeTacks (m_hWnd); InvalidateRect (&m_rectLeftPane, FALSE); InvalidateRect (&m_rectRightPane, FALSE); } #endif return FALSE; } //----------------------------------------------------------------------------- // // @mfunc Copy the treasure information to the clipboard // // @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 CRegionWnd::OnEditCopy (WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL &bHandled) { // // Return if we don't have a treasure // if (m_nTreasure == 0) return TRUE; // // Invoke the helper routine // CTreasure::gm_vTreasures [m_nTreasure] .CopyToClipboard (); return TRUE; } //----------------------------------------------------------------------------- // // @mfunc Handle a change in show state // // @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 CRegionWnd::OnShowWindow (UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL &bHandled) { // // If we are being shown // if (wParam) { // // Clear the over status and the status bar // m_nOverTreasure = 0; m_pMainWnd ->SetStatusBarText (NULL); // // Get the cursor pos and do a dummy hit test // CPoint pt; ::GetCursorPos (&pt); ScreenToClient (&pt); BOOL bHandled = TRUE; OnMouseMove (WM_MOUSEMOVE, 0, MAKELPARAM (pt .x, pt .y), bHandled); } // // Return FALSE // bHandled = FALSE; return false; } //----------------------------------------------------------------------------- // // @mfunc Handle a next region // // @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 CRegionWnd::OnEditNextRegion (WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled) { // // If we have a region, then set // int nRegion = CRegion::GetNext (m_nRegion, true, &g_sFilter); if (nRegion > 0) SetRegion (nRegion, -1); return TRUE; } //----------------------------------------------------------------------------- // // @mfunc Handle a previous region // // @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 CRegionWnd::OnEditPreviousRegion (WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled) { // // If we have a region, then set // int nRegion = CRegion::GetNext (m_nRegion, false, &g_sFilter); if (nRegion > 0) SetRegion (nRegion, -1); return TRUE; } //----------------------------------------------------------------------------- // // @mfunc Handle a next treasure // // @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 CRegionWnd::OnEditNextTreasure (WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled) { // // If we have a treasure, then set // int nTreasure = CTreasure::GetNext (m_nTreasure, true, &g_sFilter); if (nTreasure > 0) { if (CTreasure::gm_vTreasures [nTreasure] .m_nRegion != m_nRegion) SetRegion (CTreasure::gm_vTreasures [nTreasure] .m_nRegion, nTreasure); else SetTreasure (nTreasure); } return TRUE; } //----------------------------------------------------------------------------- // // @mfunc Handle a previous treasure // // @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 CRegionWnd::OnEditPreviousTreasure (WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled) { // // If we have a treasure, then set // int nTreasure = CTreasure::GetNext (m_nTreasure, false, &g_sFilter); if (nTreasure > 0) { if (CTreasure::gm_vTreasures [nTreasure] .m_nRegion != m_nRegion) SetRegion (CTreasure::gm_vTreasures [nTreasure] .m_nRegion, nTreasure); else SetTreasure (nTreasure); } return TRUE; } //----------------------------------------------------------------------------- // // @mfunc Get a default treasure // // @parm int | nTreasure | The requested treasure number // // @rdesc Default treasure number or the given treasure if it is valid // //----------------------------------------------------------------------------- int CRegionWnd::GetDefaultTreasure (int nTreasure) { // // Loop through the treasures // bool fFound = false; int nBestTreasure = (int) CTreasure::gm_vTreasures .GetCount (); for (int i = 0; i < m_nTreasures; i++) { if (m_panTreasures [i] == nTreasure) return nTreasure; if (m_panTreasures [i] < nBestTreasure) nBestTreasure = m_panTreasures [i]; } // // Return the results // if (nBestTreasure < CTreasure::gm_vTreasures .GetCount ()) return nBestTreasure; else return 0; }