diff --git a/GM/DlgMedt.cpp b/GM/DlgMedt.cpp index 87a500b..d367742 100644 --- a/GM/DlgMedt.cpp +++ b/GM/DlgMedt.cpp @@ -180,8 +180,7 @@ void CMarkerEditDialog::OnDblclkMarkers(wxCommandEvent& /*event*/) bool CMarkerEditDialog::TransferDataToWindow() { ASSERT(m_pDoc); - m_pMMgr = m_pDoc->GetMarkManager(); - ASSERT(m_pMMgr); + m_pMMgr = &m_pDoc->GetMarkManager(); m_listMarks->SetDocument(m_pDoc); @@ -196,8 +195,7 @@ bool CMarkerEditDialog::TransferDataToWindow() WORD wMarkFlags = m_pMMgr->GetMark(m_mid).m_flags; m_chkPromptText->SetValue(wMarkFlags & MarkDef::flagPromptText); - m_pTMgr = m_pDoc->GetTileManager(); - ASSERT(m_pTMgr); + m_pTMgr = &m_pDoc->GetTileManager(); m_listTiles->SetDocument(m_pDoc); diff --git a/GM/DlgMnew.cpp b/GM/DlgMnew.cpp index a285848..c25c51c 100644 --- a/GM/DlgMnew.cpp +++ b/GM/DlgMnew.cpp @@ -161,13 +161,11 @@ void CMarkerCreateDialog::OnCreateMarker(wxCommandEvent& event) void CMarkerCreateDialog::OnInitDialog(wxInitDialogEvent& event) { ASSERT(m_pDoc); - m_pMMgr = m_pDoc->GetMarkManager(); - ASSERT(m_pMMgr); + m_pMMgr = &m_pDoc->GetMarkManager(); m_listMarks->SetDocument(m_pDoc); - m_pTMgr = m_pDoc->GetTileManager(); - ASSERT(m_pTMgr); + m_pTMgr = &m_pDoc->GetTileManager(); m_listTiles->SetDocument(m_pDoc); diff --git a/GM/DlgPedt.cpp b/GM/DlgPedt.cpp index 7e13953..498e1d7 100644 --- a/GM/DlgPedt.cpp +++ b/GM/DlgPedt.cpp @@ -57,8 +57,8 @@ CPieceEditDialog::CPieceEditDialog(CGamDoc& doc, PieceID pid, wxWindow* parent / m_pDoc(&doc), m_pid(pid), m_tbl(1, m_pid), - m_pTMgr(*m_pDoc->GetTileManager()), - m_pPMgr(m_pDoc->GetPieceManager()) + m_pTMgr(m_pDoc->GetTileManager()), + m_pPMgr(&m_pDoc->GetPieceManager()) { } diff --git a/GM/DlgPnew.cpp b/GM/DlgPnew.cpp index ed46004..4e68c96 100644 --- a/GM/DlgPnew.cpp +++ b/GM/DlgPnew.cpp @@ -58,8 +58,8 @@ CPieceNewDialog::CPieceNewDialog(CGamDoc& doc, size_t nPSet, wxWindow* parent /* CB_XRC_END_CTRLS_DEFN(), m_pDoc(&doc), m_nPSet(nPSet), - m_pTMgr(*m_pDoc->GetTileManager()), - m_pPMgr(m_pDoc->GetPieceManager()) + m_pTMgr(m_pDoc->GetTileManager()), + m_pPMgr(&m_pDoc->GetPieceManager()) { wxSize editSize = m_editQty->GetSizeFromText("999"); m_editQty->SetInitialSize(editSize); diff --git a/GM/FrmBited.cpp b/GM/FrmBited.cpp index e1a0c9e..0fc1dc8 100644 --- a/GM/FrmBited.cpp +++ b/GM/FrmBited.cpp @@ -39,7 +39,8 @@ static char THIS_FILE[] = __FILE__; IMPLEMENT_DYNCREATE(CBitEditFrame, CMDIChildWndEx) -CBitEditFrame::CBitEditFrame() +CBitEditFrame::CBitEditFrame() : + CB::wxNativeContainerWindowMixin(static_cast(*this)) { } diff --git a/GM/FrmBited.h b/GM/FrmBited.h index ef99377..454ba83 100644 --- a/GM/FrmBited.h +++ b/GM/FrmBited.h @@ -27,7 +27,8 @@ class CTileSelView; ///////////////////////////////////////////////////////////////////////////// // CBitEditFrame frame -class CBitEditFrame : public CMDIChildWndEx +class CBitEditFrame : public CMDIChildWndEx, + public CB::wxNativeContainerWindowMixin { DECLARE_DYNCREATE(CBitEditFrame) protected: diff --git a/GM/FrmBxdoc.cpp b/GM/FrmBxdoc.cpp index c45cce1..8363b74 100644 --- a/GM/FrmBxdoc.cpp +++ b/GM/FrmBxdoc.cpp @@ -38,7 +38,8 @@ static char THIS_FILE[] = __FILE__; IMPLEMENT_DYNCREATE(CDocFrame, CMDIChildWndEx) -CDocFrame::CDocFrame() +CDocFrame::CDocFrame() : + CB::wxNativeContainerWindowMixin(static_cast(*this)) { } @@ -67,7 +68,7 @@ BOOL CDocFrame::PreCreateWindow(CREATESTRUCT& cs) void CDocFrame::OnUpdateFrameTitle(BOOL bAddToTitle) { - CGamDoc* pDoc = (CGamDoc*)GetActiveDocument(); + CDocument* pDoc = GetActiveDocument(); CB::string str = pDoc->GetTitle(); str += " - "; CB::string strType = CB::string::LoadString(IDS_PROJTYPE_GAMEBOX); @@ -78,5 +79,5 @@ void CDocFrame::OnUpdateFrameTitle(BOOL bAddToTitle) void CDocFrame::OnClose() { // Close the document when the main document window is closed. - ((CGamDoc*)GetActiveDocument())->OnFileClose(); + GetActiveDocument()->OnCmdMsg(ID_FILE_CLOSE, CN_COMMAND, nullptr, nullptr); } diff --git a/GM/FrmBxdoc.h b/GM/FrmBxdoc.h index 1013dfd..e2cdbf6 100644 --- a/GM/FrmBxdoc.h +++ b/GM/FrmBxdoc.h @@ -28,7 +28,8 @@ ///////////////////////////////////////////////////////////////////////////// // CDocFrame frame -class CDocFrame : public CMDIChildWndEx +class CDocFrame : public CMDIChildWndEx, + public CB::wxNativeContainerWindowMixin { DECLARE_DYNCREATE(CDocFrame) protected: diff --git a/GM/FrmMain.cpp b/GM/FrmMain.cpp index 0da727b..18b5efc 100644 --- a/GM/FrmMain.cpp +++ b/GM/FrmMain.cpp @@ -121,20 +121,6 @@ int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct) if (CMDIFrameWndEx::OnCreate(lpCreateStruct) == -1) return -1; - /* KLUDGE: apparently wxNativeContainerWindow doesn't let - MFC receive WM_SIZE, but no WM_SIZE means no layout - update */ - wxWindow* pThis = *this; - pThis->Bind(wxEVT_SIZE, - [this](wxSizeEvent& event) - { - /* wx args don't match WM_SIZE, but it looks - like specific args aren't critical */ - CMDIFrameWndExCb::OnSize(0, 0, 0); - event.Skip(); - } - ); - CMDITabInfo mdiTabParams; mdiTabParams.m_style = CMFCTabCtrl::STYLE_3D_VS2005; // other styles available... mdiTabParams.m_bActiveTabCloseButton = TRUE; // set to FALSE to place close button at right of tab area diff --git a/GM/FrmView.cpp b/GM/FrmView.cpp index e29940d..37bb8ff 100644 --- a/GM/FrmView.cpp +++ b/GM/FrmView.cpp @@ -36,7 +36,8 @@ static char THIS_FILE[] = __FILE__; IMPLEMENT_DYNCREATE(CViewFrame, CMDIChildWndEx) -CViewFrame::CViewFrame() +CViewFrame::CViewFrame() : + CB::wxNativeContainerWindowMixin(static_cast(*this)) { } diff --git a/GM/FrmView.h b/GM/FrmView.h index 255e9ae..97acdd1 100644 --- a/GM/FrmView.h +++ b/GM/FrmView.h @@ -28,7 +28,8 @@ ///////////////////////////////////////////////////////////////////////////// // CViewFrame frame -class CViewFrame : public CMDIChildWndEx +class CViewFrame : public CMDIChildWndEx, + public CB::wxNativeContainerWindowMixin { DECLARE_DYNCREATE(CViewFrame) protected: diff --git a/GM/Gm.cpp b/GM/Gm.cpp index 963f25e..32dec77 100644 --- a/GM/Gm.cpp +++ b/GM/Gm.cpp @@ -329,6 +329,8 @@ namespace { wxXmlResource::Get()->InitAllHandlers(); wxCHECK(wxXmlResource::Get()->LoadFile(wxStandardPaths::Get().GetDataDir() + "/CBDesign.xrc"), false); + static OwnerPtr docManager = MakeOwner(); + return true; } }; @@ -399,16 +401,16 @@ BOOL CGmApp::InitInstance() // Register the application's document templates. Document templates // serve as the connection between documents, frame windows and views. AddDocTemplate(new CMultiDocTemplate(IDR_GAMEBOX, - RUNTIME_CLASS(CGamDoc), + RUNTIME_CLASS(CGamDocMfc), RUNTIME_CLASS(CDocFrame), RUNTIME_CLASS(CGbxProjViewContainer))); m_pMapViewTmpl = new CMultiDocTemplate(IDR_BOARDVIEW, - RUNTIME_CLASS(CGamDoc), RUNTIME_CLASS(CViewFrame), + RUNTIME_CLASS(CGamDocMfc), RUNTIME_CLASS(CViewFrame), RUNTIME_CLASS(CBrdEditViewContainer)); m_pTileEditTmpl = new CMultiDocTemplate(IDR_BITEDITOR, - RUNTIME_CLASS(CGamDoc), RUNTIME_CLASS(CBitEditFrame), + RUNTIME_CLASS(CGamDocMfc), RUNTIME_CLASS(CBitEditFrame), RUNTIME_CLASS(CBitEditViewContainer)); EnableLoadWindowPlacement(FALSE); @@ -629,10 +631,9 @@ BOOL CGmApp::OnIdle(LONG lCount) POSITION pos2 = pTemplate->GetFirstDocPosition(); while (pos2) { - CGamDoc* pDoc = (CGamDoc*)pTemplate->GetNextDoc(pos2); - ASSERT(pDoc != NULL); - ASSERT(pDoc->IsKindOf(RUNTIME_CLASS(CGamDoc))); - pDoc->OnIdle(bAppVisible && pDoc == pCurDoc); + CGamDoc* pDoc = CB::ToCGamDoc(pTemplate->GetNextDoc(pos2)); + wxASSERT(pDoc != NULL); + pDoc->OnIdle(bAppVisible && pDoc == CB::ToCGamDoc(pCurDoc)); } } diff --git a/GM/GmDoc.cpp b/GM/GmDoc.cpp index aacff9e..9f9f8b4 100644 --- a/GM/GmDoc.cpp +++ b/GM/GmDoc.cpp @@ -68,7 +68,7 @@ Features CGamDoc::c_fileFeatures; static char THIS_FILE[] = __FILE__; #endif -IMPLEMENT_DYNCREATE(CGamDoc, CDocument) +IMPLEMENT_DYNCREATE(CGamDocMfc, CDocument) IMPLEMENT_DYNCREATE(CGmBoxHint, CObject) #ifdef _DEBUG @@ -94,23 +94,33 @@ void SetFileFeatures(Features&& fs) /////////////////////////////////////////////////////////////////////// // CGamDoc - message dispatch table -BEGIN_MESSAGE_MAP(CGamDoc, CDocument) - ON_COMMAND(ID_EDIT_GBOXPROPERTIES, OnEditGbxProperties) - ON_COMMAND(ID_EDIT_CREATEBOARD, OnEditCreateBoard) - ON_COMMAND(ID_EDIT_CREATETILEGROUP, OnEditCreateTileGroup) - ON_COMMAND(ID_EDIT_CREATEPIECEGROUP, OnEditCreatePieceGroup) - ON_COMMAND(ID_EDIT_CREATEMARKGROUP, OnEditCreateMarkGroup) - ON_COMMAND(ID_PROJECT_CHGID, OnProjectChangeFingerPrint) - ON_COMMAND(ID_STICKY_DRAWTOOLS, OnStickyDrawTools) - ON_UPDATE_COMMAND_UI(ID_STICKY_DRAWTOOLS, OnUpdateStickyDrawTools) - ON_COMMAND(ID_DUMP_TILEDATA, OnDumpTileData) - ON_COMMAND(ID_BUGFIX_DUMPBADTILES, OnBugFixDumpBadTiles) - ON_COMMAND(ID_EXPORT_GAMEBOX, OnExportGamebox) -END_MESSAGE_MAP() +wxBEGIN_EVENT_TABLE(CGamDoc, wxDocument) + EVT_MENU(XRCID("ID_EDIT_GBOXPROPERTIES"), OnEditGbxProperties) + EVT_UPDATE_UI(XRCID("ID_EDIT_GBOXPROPERTIES"), OnUpdateEnable) + EVT_MENU(XRCID("ID_EDIT_CREATEBOARD"), OnEditCreateBoard) + EVT_UPDATE_UI(XRCID("ID_EDIT_CREATEBOARD"), OnUpdateEnable) + EVT_MENU(XRCID("ID_EDIT_CREATETILEGROUP"), OnEditCreateTileGroup) + EVT_UPDATE_UI(XRCID("ID_EDIT_CREATETILEGROUP"), OnUpdateEnable) + EVT_MENU(XRCID("ID_EDIT_CREATEPIECEGROUP"), OnEditCreatePieceGroup) + EVT_UPDATE_UI(XRCID("ID_EDIT_CREATEPIECEGROUP"), OnUpdateEnable) + EVT_MENU(XRCID("ID_EDIT_CREATEMARKGROUP"), OnEditCreateMarkGroup) + EVT_UPDATE_UI(XRCID("ID_EDIT_CREATEMARKGROUP"), OnUpdateEnable) + EVT_MENU(XRCID("ID_PROJECT_CHGID"), OnProjectChangeFingerPrint) + EVT_UPDATE_UI(XRCID("ID_PROJECT_CHGID"), OnUpdateEnable) + EVT_MENU(XRCID("ID_STICKY_DRAWTOOLS"), OnStickyDrawTools) + EVT_UPDATE_UI(XRCID("ID_STICKY_DRAWTOOLS"), OnUpdateStickyDrawTools) + EVT_MENU(XRCID("ID_DUMP_TILEDATA"), OnDumpTileData) + EVT_UPDATE_UI(XRCID("ID_DUMP_TILEDATA"), OnUpdateEnable) + EVT_MENU(XRCID("ID_BUGFIX_DUMPBADTILES"), OnBugFixDumpBadTiles) + EVT_UPDATE_UI(XRCID("ID_BUGFIX_DUMPBADTILES"), OnUpdateEnable) + EVT_MENU(XRCID("ID_EXPORT_GAMEBOX"), OnExportGamebox) + EVT_UPDATE_UI(XRCID("ID_EXPORT_GAMEBOX"), OnUpdateEnable) +wxEND_EVENT_TABLE() /////////////////////////////////////////////////////////////////////// -CGamDoc::CGamDoc() +CGamDoc::CGamDoc(CGamDocMfc& md) : + mfcDoc(&md) { m_pBMgr = NULL; m_pTMgr = NULL; @@ -140,21 +150,6 @@ CGamDoc::CGamDoc() m_pCustomColors = CColorPalette::CustomColorsAllocate(); } -CGamDoc::~CGamDoc() -{ - if (m_pTMgr) delete &*m_pTMgr; - if (m_pBMgr) delete m_pBMgr; - if (m_pPMgr) delete m_pPMgr; - if (m_pMMgr) delete m_pMMgr; -} - -///////////////////////////////////////////////////////////////////////////// - -void CGamDoc::OnCloseDocument() -{ - CDocument::OnCloseDocument(); -} - ///////////////////////////////////////////////////////////////////////////// static const CRuntimeClass *tblBrd[] = { @@ -177,6 +172,7 @@ void CGamDoc::OnIdle(BOOL bActive) void CGamDoc::UpdateAllViews(CView* pSender, LPARAM lHint, CObject* pHint) { + CPP20_TRACE("{}({}, {}, {})\n", __func__, static_cast(pSender), lHint, static_cast(pHint)); WORD wHint = LOWORD(lHint); if ( ((wHint & HINT_TILEGROUP) && !(wHint & ~HINT_TILEGROUP)) || @@ -185,21 +181,27 @@ void CGamDoc::UpdateAllViews(CView* pSender, LPARAM lHint, CObject* pHint) wHint == HINT_ALWAYSUPDATE ) m_palTile->UpdatePaletteContents(); - CDocument::UpdateAllViews(pSender, lHint, pHint); + mfcDoc->CDocument::UpdateAllViews(pSender, lHint, pHint); +} + +// wxWidgets +void CGamDoc::UpdateAllViews(wxView* sender /*= nullptr*/, wxObject* hint /*= nullptr*/) +{ + CPP20_TRACE("{}({}, {})\n", __func__, static_cast(sender), static_cast(hint)); } /////////////////////////////////////////////////////////////////////// -BOOL CGamDoc::OnNewDocument() +bool CGamDoc::OnNewDocument() { - if (!CDocument::OnNewDocument()) + if (!mfcDoc->CDocument::OnNewDocument()) return FALSE; return SetupBlankBoard(); } -BOOL CGamDoc::OnOpenDocument(LPCTSTR lpszPathName) +bool CGamDoc::OnOpenDocument(const wxString& lpszPathName) { - BOOL bOK = CDocument::OnOpenDocument(lpszPathName); + BOOL bOK = wxDocument::OnOpenDocument(lpszPathName); // If the game loaded OK, check if it's password protected. if (bOK) { @@ -225,11 +227,11 @@ BOOL CGamDoc::OnOpenDocument(LPCTSTR lpszPathName) return bOK; } -BOOL CGamDoc::OnSaveDocument(LPCTSTR pszPathName) +bool CGamDoc::OnSaveDocument(const wxString& pszPathName) { // Make sure tile edits are saved. UpdateAllViews(NULL, HINT_FORCETILEUPDATE, NULL); - if (std::filesystem::exists(pszPathName)) + if (std::filesystem::exists(CB::string(pszPathName))) { CB::string szTmp = SetFileExt(pszPathName, "gb_"); if (_access(szTmp, 0) != -1) // Remove previous backup @@ -248,18 +250,14 @@ BOOL CGamDoc::OnSaveDocument(LPCTSTR pszPathName) } CFile::Rename(pszPathName, szTmp); } - return CDocument::OnSaveDocument(pszPathName); + return wxDocument::OnSaveDocument(pszPathName); } -void CGamDoc::DeleteContents() +bool CGamDoc::DeleteContents() { - if (m_pTMgr) delete &*m_pTMgr; m_pTMgr = NULL; - if (m_pBMgr) delete m_pBMgr; m_pBMgr = NULL; - if (m_pPMgr) delete m_pPMgr; m_pPMgr = NULL; - if (m_pMMgr) delete m_pMMgr; m_pMMgr = NULL; if (m_palTile) { @@ -273,6 +271,23 @@ void CGamDoc::DeleteContents() m_bMajorRevIncd = FALSE; CColorPalette::CustomColorsClear(m_pCustomColors); + + mfcDoc->CDocument::DeleteContents(); + return wxDocument::DeleteContents(); +} + +// wxDocument +// Called by OnSaveDocument and OnOpenDocument to implement standard +// Save/Load behaviour. Re-implement in derived class for custom +// behaviour. +bool CGamDoc::DoSaveDocument(const wxString& file) +{ + return mfcDoc->CDocument::OnSaveDocument(file); +} + +bool CGamDoc::DoOpenDocument(const wxString& file) +{ + return mfcDoc->CDocument::OnOpenDocument(file); } /////////////////////////////////////////////////////////////////////// @@ -291,20 +306,20 @@ void CGamDoc::SetCustomColors(const std::vector& pCustColors) /////////////////////////////////////////////////////////////////////// // Support for new unique views on this document -BOOL CGamDoc::CreateNewFrame(CDocTemplate* pTemplate, const CB::string& pszTitle, +BOOL CGamDoc::CreateNewFrame(CDocTemplate& pTemplate, const CB::string& pszTitle, LPVOID lpvCreateParam) { CMDIChildWndEx* pNewFrame - = (CMDIChildWndEx*)(pTemplate->CreateNewFrame(this, NULL)); + = static_cast(pTemplate.CreateNewFrame(*this, NULL)); if (pNewFrame == NULL) return FALSE; // Not created - ASSERT(pNewFrame->IsKindOf(RUNTIME_CLASS(CMDIChildWndEx))); - CB::string str = GetTitle(); + wxASSERT(pNewFrame->IsKindOf(RUNTIME_CLASS(CMDIChildWndEx))); + CB::string str = GetUserReadableName(); str += " - "; str += pszTitle; pNewFrame->SetWindowText(str); m_lpvCreateParam = lpvCreateParam; - pTemplate->InitialUpdateFrame(pNewFrame, this); + pTemplate.InitialUpdateFrame(pNewFrame, *this); // KLUDGE: work around https://github.com/CyberBoardPBEM/cbwindows/issues/23 GetMainFrame()->RedrawWindow(NULL, NULL, RDW_ALLCHILDREN | RDW_INVALIDATE); m_lpvCreateParam = NULL; @@ -374,12 +389,12 @@ DWORD CGamDoc::IssueGameBoxID() /////////////////////////////////////////////////////////////////////// -CView* CGamDoc::FindTileEditorView(TileID tid) +CView* CGamDoc::FindTileEditorView(TileID tid) const { - POSITION pos = GetFirstViewPosition(); + POSITION pos = mfcDoc->GetFirstViewPosition(); while (pos != NULL) { - CTileSelViewContainer* pView = (CTileSelViewContainer*)GetNextView(pos); + CTileSelViewContainer* pView = static_cast(mfcDoc->GetNextView(pos)); if (pView->IsKindOf(RUNTIME_CLASS(CTileSelViewContainer))) { if (pView->GetChild().GetTileID() == tid) @@ -389,12 +404,12 @@ CView* CGamDoc::FindTileEditorView(TileID tid) return NULL; } -CView* CGamDoc::FindBoardEditorView(const CBoard& pBoard) +CView* CGamDoc::FindBoardEditorView(const CBoard& pBoard) const { - POSITION pos = GetFirstViewPosition(); + POSITION pos = mfcDoc->GetFirstViewPosition(); while (pos != NULL) { - CBrdEditViewContainer* pView = (CBrdEditViewContainer*)GetNextView(pos); + CBrdEditViewContainer* pView = static_cast(mfcDoc->GetNextView(pos)); if (pView->IsKindOf(RUNTIME_CLASS(CBrdEditViewContainer))) { if (&pView->GetChild().GetBoard() == &pBoard) @@ -524,13 +539,13 @@ BOOL CGamDoc::DoBoardPropertyDialog(CBoard& pBoard) /////////////////////////////////////////////////////////////////////// -TileID CGamDoc::CreateTileFromDib(CDib* pDib, size_t nTSet) +TileID CGamDoc::CreateTileFromDib(const CDib& pDib, size_t nTSet) { - int xTile = pDib->Width(); - int yTile = pDib->Height(); + int xTile = pDib.Width(); + int yTile = pDib.Height(); TileID tid = m_pTMgr->CreateTile(nTSet, CSize(xTile, yTile), CSize(xTile/2, yTile/2), RGB(255, 255, 255)); - OwnerPtr pBMap = pDib->DIBToBitmap(); + OwnerPtr pBMap = pDib.DIBToBitmap(); OwnerPtr bmHalf = CloneScaledBitmap(*pBMap, CSize(xTile/2, yTile/2)); CTileUpdatable tile = m_pTMgr->GetTile(tid, fullScale); @@ -546,7 +561,7 @@ TileID CGamDoc::CreateTileFromDib(CDib* pDib, size_t nTSet) void CGamDoc::Serialize(CArchive& ar) { - ar.m_pDocument = this; + ar.m_pDocument = &*mfcDoc; if (ar.IsStoring()) { // File Header @@ -567,10 +582,10 @@ void CGamDoc::Serialize(CArchive& ar) /* these features are global in the sense that, if any ID needs 32 bits, then we store all IDs in 32 bit format */ - if (GetBoardManager()->Needs32BitIDs() || - GetTileManager()->Needs32BitIDs() || - GetPieceManager()->Needs32BitIDs() || - GetMarkManager()->Needs32BitIDs()) + if (GetBoardManager().Needs32BitIDs() || + GetTileManager().Needs32BitIDs() || + GetPieceManager().Needs32BitIDs() || + GetMarkManager().Needs32BitIDs()) { if (!GetCBFeatures().Check(ftrId32Bit)) { @@ -819,12 +834,12 @@ void CGamDoc::Serialize(CArchive& ar) #ifdef _DEBUG void CGamDoc::AssertValid() const { - CDocument::AssertValid(); + mfcDoc->CDocument::AssertValid(); } void CGamDoc::Dump(CDumpContext& dc) const { - CDocument::Dump(dc); + mfcDoc->CDocument::Dump(dc); } #endif //_DEBUG @@ -862,7 +877,7 @@ void CGamDoc::OnEditGbxProperties() // Do an MD5 hash of the password, append the box ID and // hash it again. This value is the password key used to // allow editing of the gamebox. -std::array CGamDoc::ComputeGameboxPasskey(const CB::string& pszPassword) +std::array CGamDoc::ComputeGameboxPasskey(const CB::string& pszPassword) const { CB::string strPassword = pszPassword; strPassword += KEY_PASS_POSTFIX; @@ -895,12 +910,12 @@ void CGamDoc::OnEditCreateBoard() if (dlg.ShowModal() == wxID_OK) { // Create a Game Board - CBoardManager* pBMgr = GetBoardManager(); + CBoardManager& pBMgr = GetBoardManager(); CBoard* pBoard = new CBoard; - pBoard->SetSerialNumber(pBMgr->IssueSerialNumber()); + pBoard->SetSerialNumber(pBMgr.IssueSerialNumber()); pBoard->SetName(dlg.m_strBoardName); - OwnerOrNullPtr pBrdAry = MakeOwner(CheckedDeref(GetTileManager())); + OwnerOrNullPtr pBrdAry = MakeOwner(GetTileManager()); if (dlg.m_nBoardType == cformRect) { @@ -915,7 +930,7 @@ void CGamDoc::OnEditCreateBoard() pBoard->SetBoardArray(std::move(pBrdAry)); pBoard->SetBkColor(RGB(255, 255, 255)); - pBMgr->Add(pBoard); + pBMgr.Add(pBoard); pBoard->SetMaxDrawLayer(LAYER_TOP); SetModifiedFlag(); @@ -929,7 +944,7 @@ void CGamDoc::OnEditCreateTileGroup() CCreateTSet dlg; if (dlg.ShowModal() == wxID_OK) { - GetTileManager()->CreateTileSet(dlg.m_strTSName); + GetTileManager().CreateTileSet(dlg.m_strTSName); UpdateAllViews(NULL, HINT_UPDATEPROJVIEW); SetModifiedFlag(); } @@ -940,7 +955,7 @@ void CGamDoc::OnEditCreatePieceGroup() CPieceGroupNameDialog dlg; if (dlg.ShowModal() == wxID_OK) { - GetPieceManager()->CreatePieceSet(dlg.m_strName); + GetPieceManager().CreatePieceSet(dlg.m_strName); UpdateAllViews(NULL, HINT_UPDATEPROJVIEW); SetModifiedFlag(); } @@ -951,14 +966,14 @@ void CGamDoc::OnEditCreateMarkGroup() CMarkGroupNewDialog dlg; if (dlg.ShowModal() == wxID_OK) { - GetMarkManager()->CreateMarkSet(dlg.m_strName); + GetMarkManager().CreateMarkSet(dlg.m_strName); UpdateAllViews(NULL, HINT_UPDATEPROJVIEW); SetModifiedFlag(); } } -void CGamDoc::OnProjectChangeFingerPrint() +void CGamDoc::OnProjectChangeFingerPrint(wxCommandEvent& /*event*/) { if (AfxMessageBox(IDP_WARN_CHGID, MB_YESNO | MB_DEFBUTTON2 | MB_ICONEXCLAMATION) != IDYES) @@ -971,39 +986,44 @@ void CGamDoc::OnProjectChangeFingerPrint() SetModifiedFlag(); } -void CGamDoc::OnStickyDrawTools() +void CGamDoc::OnStickyDrawTools(wxCommandEvent& /*event*/) { m_bStickyDrawTools = !m_bStickyDrawTools; } -void CGamDoc::OnUpdateStickyDrawTools(CCmdUI* pCmdUI) +void CGamDoc::OnUpdateStickyDrawTools(wxUpdateUIEvent& pCmdUI) { - pCmdUI->SetCheck(m_bStickyDrawTools); + pCmdUI.Check(m_bStickyDrawTools); } -void CGamDoc::OnDumpTileData() +void CGamDoc::OnDumpTileData(wxCommandEvent& /*event*/) { CFileDialog dlg(FALSE, "txt"_cbstring, NULL, OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT, "Text Files (*.txt)|*.txt|All Files (*.*)|*.*||"_cbstring, NULL, 0); if (dlg.DoModal() == IDOK) { - GetTileManager()->DumpTileDatabaseInfoToFile(dlg.GetPathName(), TRUE); + GetTileManager().DumpTileDatabaseInfoToFile(dlg.GetPathName(), TRUE); } } -void CGamDoc::OnBugFixDumpBadTiles() +void CGamDoc::OnBugFixDumpBadTiles(wxCommandEvent& /*event*/) { if (AfxMessageBox("This is a secret function that will attempt to remove illegal tiles " "assigned to tile sheet 255. It can also trash your GameBox. Therefore, only Dale Larson and his " "appropriately blessed holy minions should use it. You have been WARNED!"_cbstring, MB_OKCANCEL | MB_ICONEXCLAMATION) == IDOK) { - if (GetTileManager()->PruneTilesOnSheet255()) + if (GetTileManager().PruneTilesOnSheet255()) SetModifiedFlag(); } } -void CGamDoc::OnExportGamebox() +void CGamDoc::OnUpdateEnable(wxUpdateUIEvent& pCmdUI) +{ + pCmdUI.Enable(true); +} + +void CGamDoc::OnExportGamebox(wxCommandEvent& /*event*/) { //TBD??? Formally used as experimental XML exporter. } diff --git a/GM/GmDoc.h b/GM/GmDoc.h index 1c3419e..f93b6e1 100644 --- a/GM/GmDoc.h +++ b/GM/GmDoc.h @@ -183,19 +183,30 @@ class CGmBoxHint : public CObject class CDib; class CPieceManager; class CMarkManager; +class CGamDocMfc; -class CGamDoc : public CDocument +class CGamDoc : public wxDocument { +// impersonate CDocument +public: + operator const CGamDocMfc&() const { return *mfcDoc; } + operator CGamDocMfc&() { return *mfcDoc; } + operator const CGamDocMfc*() const { return &*mfcDoc; } + operator CGamDocMfc*() { return &*mfcDoc; } + void SetModifiedFlag(BOOL b = TRUE) { Modify(b); } + +private: friend class CGbxProjView; -protected: - CGamDoc(); + CGamDoc(CGamDocMfc& md); +#if 0 DECLARE_DYNCREATE(CGamDoc) +#endif // Class Global Attributes public: static CFontTbl m_fontTbl; - static CFontTbl* GetFontManager() { return &m_fontTbl; } + static CFontTbl& GetFontManager() { return m_fontTbl; } // Version of file being loaded static int c_fileVersion; // load and save can't be simultaneous, so use for both @@ -203,7 +214,7 @@ class CGamDoc : public CDocument // Attributes public: - void ExportGamebox(const CB::string& pszPathName); + void ExportGamebox(const CB::string& pszPathName) const; static void SetLoadingVersion(int ver) { c_fileVersion = ver; } using SetLoadingVersionGuard = ::SetLoadingVersionGuard; @@ -212,31 +223,31 @@ class CGamDoc : public CDocument static void SetFileFeatures(const Features& feat) { SetFileFeatures(Features(feat)); } static const Features& GetFileFeatures() { return c_fileFeatures; } // -------- // - DWORD GetGameBoxID() { return m_dwGameID; } + DWORD GetGameBoxID() const { return m_dwGameID; } // -------- // - CBoardManager* GetBoardManager() { return m_pBMgr; } - const CTileManager* GetTileManager() const { return &*m_pTMgr; } - CTileManager* GetTileManager() { return const_cast(std::as_const(*this).GetTileManager()); } - const CPieceManager* GetPieceManager() const { return m_pPMgr; } - CPieceManager* GetPieceManager() { return const_cast(std::as_const(*this).GetPieceManager()); } - CMarkManager* GetMarkManager() { return m_pMMgr; } - const CTilePalette* GetTilePalWnd() const { return m_palTile.get(); } + CBoardManager& GetBoardManager() { return CheckedDeref(m_pBMgr); } + const CTileManager& GetTileManager() const { return CheckedDeref(m_pTMgr); } + CTileManager& GetTileManager() { return const_cast(std::as_const(*this).GetTileManager()); } + const CPieceManager& GetPieceManager() const { return CheckedDeref(m_pPMgr); } + CPieceManager& GetPieceManager() { return const_cast(std::as_const(*this).GetPieceManager()); } + CMarkManager& GetMarkManager() { return CheckedDeref(m_pMMgr); } + const CTilePalette& GetTilePalWnd() const { return CheckedDeref(m_palTile); } // -------- // - BOOL GetStickyDrawTools() { return m_bStickyDrawTools; } + BOOL GetStickyDrawTools() const { return m_bStickyDrawTools; } // -------- // void IncrMajorRevLevel(); - DWORD IssueGameBoxID(); + static DWORD IssueGameBoxID(); // If you need to pass a pointer to the views to be created, // bracket the view can call the GetCreateParameter() method. // It is only valid during the InitialUpdate() method. - LPVOID GetCreateParameter() { return m_lpvCreateParam; } + LPVOID GetCreateParameter() const { return m_lpvCreateParam; } // Operations public: BOOL SetupBlankBoard(); - BOOL CreateNewFrame(CDocTemplate* pTemplate, const CB::string& pszTitle, + BOOL CreateNewFrame(CDocTemplate& pTemplate, const CB::string& pszTitle, LPVOID lpvCreateParam = NULL); BOOL NotifyTileDatabaseChange(BOOL bPurgeScan = TRUE); @@ -244,9 +255,9 @@ class CGamDoc : public CDocument BOOL QueryTileInUse(TileID tid) const; BOOL QueryAnyOfTheseTilesInUse(const std::vector& tbl) const; - TileID CreateTileFromDib(CDib* pDib, size_t nTSet); - CView* FindTileEditorView(TileID tid); - CView* FindBoardEditorView(const CBoard& pBoard); + TileID CreateTileFromDib(const CDib& pDib, size_t nTSet); + CView* FindTileEditorView(TileID tid) const; + CView* FindBoardEditorView(const CBoard& pBoard) const; // Support for strings associated with game elements (pieces, markers) CB::string GetGameElementString(GameElement gelem) const; @@ -260,7 +271,7 @@ class CGamDoc : public CDocument void DoCreatePieceGroup() { OnEditCreatePieceGroup(); } void DoCreateMarkGroup() { OnEditCreateMarkGroup(); } - int GetCompressLevel() { return (int)m_wCompressLevel; } + int GetCompressLevel() const { return (int)m_wCompressLevel; } void SetCompressLevel(int nCompressLevel) { m_wCompressLevel = (WORD)nCompressLevel; } const std::vector& GetCustomColors() const; @@ -269,11 +280,9 @@ class CGamDoc : public CDocument const CGameElementStringMap& GetGameStringMap() const { return m_mapStrings; } CGameElementStringMap& GetGameStringMap() { return const_cast(std::as_const(*this).GetGameStringMap()); } - std::array ComputeGameboxPasskey(const CB::string& pszPassword); + std::array ComputeGameboxPasskey(const CB::string& pszPassword) const; void ClearGameboxPasskey(); - void OnFileClose() { CDocument::OnFileClose(); } // Expose protected - // OnIdle is called by the App object to inform // documents of idle condition. A flag indicates if // this is the active document. @@ -283,6 +292,13 @@ class CGamDoc : public CDocument void UpdateAllViews(CView* pSender, LPARAM lHint = 0L, CObject* pHint = NULL); + // wxWidgets + // lifetime is controlled by MFC (not wx), so override: + // Called after a view is added or removed. The default implementation + // deletes the document if this is there are no more views. + void OnChangedViewList() override {} + void UpdateAllViews(wxView* sender = nullptr, wxObject* hint = nullptr) override; + // Implementation protected: BYTE m_abyteBoxID[16];// Special hashed UUID assigned to this gamebox. @@ -301,10 +317,10 @@ class CGamDoc : public CDocument WORD m_wCompressLevel;// Amount of compression to apply to bitmaps and such CGameElementStringMap m_mapStrings; // Mapping of pieces and markers to strings. std::vector m_pCustomColors; // Container for custom edit colors - CB::propagate_const m_pTMgr; // Tiles - CBoardManager* m_pBMgr; // Playing boards - CPieceManager* m_pPMgr; // Playing pieces - CMarkManager* m_pMMgr; // Annotation markers + OwnerOrNullPtr m_pTMgr; // Tiles + OwnerOrNullPtr m_pBMgr; // Playing boards + OwnerOrNullPtr m_pPMgr; // Playing pieces + OwnerOrNullPtr m_pMMgr; // Annotation markers BOOL m_bStickyDrawTools; // If TRUE, don't select the select tool after drawing BOOL m_bMajorRevIncd;// Major rev number was increased. @@ -322,37 +338,103 @@ class CGamDoc : public CDocument LPVOID m_lpvCreateParam; // Used to pass parameters to new views public: - virtual ~CGamDoc(); - virtual void Serialize(CArchive& ar); // overridden for document i/o + virtual ~CGamDoc() = default; + void Serialize(CArchive& ar); #ifdef _DEBUG - virtual void AssertValid() const; - virtual void Dump(CDumpContext& dc) const; + void AssertValid() const; + void Dump(CDumpContext& dc) const; #endif protected: - virtual BOOL OnNewDocument(); - virtual BOOL OnOpenDocument(LPCTSTR lpszPathName) override; - virtual BOOL OnSaveDocument(LPCTSTR pszPathName) override; - virtual void DeleteContents(); - virtual void OnCloseDocument(); + bool OnNewDocument() override; + bool OnOpenDocument(const wxString& lpszPathName) override; + bool OnSaveDocument(const wxString& lpszPathName) override; + bool DeleteContents() override; + + // wxDocument + // Called by OnSaveDocument and OnOpenDocument to implement standard + // Save/Load behaviour. Re-implement in derived class for custom + // behaviour. + bool DoSaveDocument(const wxString& file) override; + bool DoOpenDocument(const wxString& file) override; -// Generated message map functions protected: - afx_msg void OnEditGbxProperties(); - afx_msg void OnEditCreateBoard(); - afx_msg void OnEditCreateTileGroup(); - afx_msg void OnEditCreatePieceGroup(); - afx_msg void OnEditCreateMarkGroup(); - afx_msg void OnProjectChangeFingerPrint(); - afx_msg void OnStickyDrawTools(); - afx_msg void OnUpdateStickyDrawTools(CCmdUI* pCmdUI); - afx_msg void OnDumpTileData(); - afx_msg void OnBugFixDumpBadTiles(); - - DECLARE_MESSAGE_MAP() + void OnEditGbxProperties(); + void OnEditGbxProperties(wxCommandEvent& /*event*/) { OnEditGbxProperties(); } + void OnEditCreateBoard(); + void OnEditCreateBoard(wxCommandEvent& /*event*/) { OnEditCreateBoard(); } + void OnEditCreateTileGroup(); + void OnEditCreateTileGroup(wxCommandEvent& /*event*/) { OnEditCreateTileGroup(); } + void OnEditCreatePieceGroup(); + void OnEditCreatePieceGroup(wxCommandEvent& /*event*/) { OnEditCreatePieceGroup(); } + void OnEditCreateMarkGroup(); + void OnEditCreateMarkGroup(wxCommandEvent& /*event*/) { OnEditCreateMarkGroup(); } + void OnProjectChangeFingerPrint(wxCommandEvent& event); + void OnStickyDrawTools(wxCommandEvent& event); + void OnUpdateStickyDrawTools(wxUpdateUIEvent& pCmdUI); + void OnDumpTileData(wxCommandEvent& event); + void OnBugFixDumpBadTiles(wxCommandEvent& event); + void OnUpdateEnable(wxUpdateUIEvent& pCmdUI); + + wxDECLARE_EVENT_TABLE(); public: - afx_msg void OnExportGamebox(); + void OnExportGamebox(wxCommandEvent& event); + +private: + RefPtr mfcDoc; + + friend CGamDocMfc; }; +class CGamDocMfc : public CDocument +{ +public: + operator const CGamDoc&() const { return *wxDoc; } + operator CGamDoc&() { return *wxDoc; } + operator const CGamDoc*() const { return &*wxDoc; } + operator CGamDoc*() { return &*wxDoc; } + +protected: + CGamDocMfc() = default; + ~CGamDocMfc() override = default; + DECLARE_DYNCREATE(CGamDocMfc) + +public: + // Forced override of this (note not virtual) + void UpdateAllViews(CView* pSender, LPARAM lHint = 0L, + CObject* pHint = NULL) { wxASSERT(!"Do not use! (use CGamDoc)"); } + + virtual void Serialize(CArchive& ar) override // overridden for document i/o + { wxDoc->Serialize(ar); } +#ifdef _DEBUG + virtual void AssertValid() const override + { wxDoc->AssertValid(); } + virtual void Dump(CDumpContext& dc) const override + { wxDoc->Dump(dc); } +#endif + +protected: + virtual BOOL OnNewDocument() override + { return wxDoc->OnNewDocument(); } + virtual BOOL OnOpenDocument(LPCTSTR lpszPathName) override + { return wxDoc->OnOpenDocument(lpszPathName); } + virtual BOOL OnSaveDocument(LPCTSTR pszPathName) override + { return wxDoc->OnSaveDocument(pszPathName); } + virtual void DeleteContents() override + { CB_VERIFY(wxDoc->DeleteContents()); } + +private: + OwnerPtr wxDoc = new CGamDoc(*this); +}; + +inline const CGamDoc* CB::ToCGamDoc(const CDocument* p) +{ + if (!p) + { + return nullptr; + } + return dynamic_cast(*p); +} + #endif diff --git a/GM/LBoxTile.cpp b/GM/LBoxTile.cpp index 7301cd5..1963d7c 100644 --- a/GM/LBoxTile.cpp +++ b/GM/LBoxTile.cpp @@ -51,11 +51,10 @@ CTileListBox::CTileListBox() CSize CTileListBox::OnItemSize(size_t nIndex) const { ASSERT(m_pDoc != NULL); - const CTileManager* pTMgr = m_pDoc->GetTileManager(); - ASSERT(pTMgr != NULL); + const CTileManager& pTMgr = m_pDoc->GetTileManager(); TileID tid = MapIndexToItem(nIndex); - CTile tile = pTMgr->GetTile(tid, fullScale); + CTile tile = pTMgr.GetTile(tid, fullScale); LONG nHt = 2 * tileBorder + tile.GetHeight(); if (m_bDisplayIDs) // See if we're drawing PieceIDs @@ -78,7 +77,7 @@ CSize CTileListBox::OnItemSize(size_t nIndex) const if (m_bDrawAllScales) { - CTile tileHalf = pTMgr->GetTile(tid, halfScale); + CTile tileHalf = pTMgr.GetTile(tid, halfScale); x += tileHalf.GetWidth() + 2 * tileBorder; x += 8; } @@ -96,12 +95,11 @@ void CTileListBox::OnItemDraw(CDC& pDC, size_t nIndex, UINT nAction, UINT nState if (nAction & (ODA_DRAWENTIRE | ODA_SELECT)) { ASSERT(m_pDoc != NULL); - const CTileManager* pTMgr = m_pDoc->GetTileManager(); - ASSERT(pTMgr != NULL); + const CTileManager& pTMgr = m_pDoc->GetTileManager(); TileID tid = MapIndexToItem(nIndex); - CTile tile = pTMgr->GetTile(tid, fullScale); + CTile tile = pTMgr.GetTile(tid, fullScale); pDC.SaveDC(); @@ -137,11 +135,11 @@ void CTileListBox::OnItemDraw(CDC& pDC, size_t nIndex, UINT nAction, UINT nState { x += tile.GetWidth() + 2 * tileBorder; y += tile.GetHeight() / 4; - CTile tileHalf = pTMgr->GetTile(tid, halfScale); + CTile tileHalf = pTMgr.GetTile(tid, halfScale); tileHalf.BitBlt(pDC, x, y); x += tileHalf.GetWidth() + 2 * tileBorder; y = rctItem.CenterPoint().y - 4; - CTile tileSmall = pTMgr->GetTile(tid, smallScale); + CTile tileSmall = pTMgr.GetTile(tid, smallScale); CBrush brSmall(tileSmall.GetSmallColor()); CRect rctSmall(x, y, x + 8, y + 8); pDC.FillRect(&rctSmall, &brSmall); // Fill background color @@ -186,11 +184,10 @@ CTileListBoxWx::CTileListBoxWx() wxSize CTileListBoxWx::GetItemSize(size_t nIndex) const { wxASSERT(m_pDoc != NULL); - const CTileManager* pTMgr = m_pDoc->GetTileManager(); - wxASSERT(pTMgr != NULL); + const CTileManager& pTMgr = m_pDoc->GetTileManager(); TileID tid = MapIndexToItem(nIndex); - CTile tile = pTMgr->GetTile(tid, fullScale); + CTile tile = pTMgr.GetTile(tid, fullScale); LONG nHt = 2 * tileBorder + tile.GetHeight(); if (m_bDisplayIDs) // See if we're drawing PieceIDs @@ -210,7 +207,7 @@ wxSize CTileListBoxWx::GetItemSize(size_t nIndex) const if (m_bDrawAllScales) { - CTile tileHalf = pTMgr->GetTile(tid, halfScale); + CTile tileHalf = pTMgr.GetTile(tid, halfScale); x += tileHalf.GetWidth() + 2 * tileBorder; x += 8; } @@ -221,12 +218,11 @@ wxSize CTileListBoxWx::GetItemSize(size_t nIndex) const void CTileListBoxWx::OnDrawItem(wxDC& pDC, const wxRect& rctItem, size_t nIndex) const { wxASSERT(m_pDoc != NULL); - const CTileManager* pTMgr = m_pDoc->GetTileManager(); - wxASSERT(pTMgr != NULL); + const CTileManager& pTMgr = m_pDoc->GetTileManager(); TileID tid = MapIndexToItem(nIndex); - CTile tile = pTMgr->GetTile(tid, fullScale); + CTile tile = pTMgr.GetTile(tid, fullScale); pDC.SetClippingRegion(rctItem); @@ -251,11 +247,11 @@ void CTileListBoxWx::OnDrawItem(wxDC& pDC, const wxRect& rctItem, size_t nIndex) { x += tile.GetWidth() + 2 * tileBorder; y += tile.GetHeight() / 4; - CTile tileHalf = pTMgr->GetTile(tid, halfScale); + CTile tileHalf = pTMgr.GetTile(tid, halfScale); tileHalf.BitBlt(pDC, CalcScrolledX(x), y); x += tileHalf.GetWidth() + 2 * tileBorder; y = rctItem.GetTop() + rctItem.GetHeight()/2 - 4; - CTile tileSmall = pTMgr->GetTile(tid, smallScale); + CTile tileSmall = pTMgr.GetTile(tid, smallScale); wxPen penSmall(CB::Convert(tileSmall.GetSmallColor())); wxDCPenChanger setPen(pDC, penSmall); wxBrush brSmall(CB::Convert(tileSmall.GetSmallColor())); diff --git a/GM/PalTile.cpp b/GM/PalTile.cpp index 3e8dff6..4d459ca 100644 --- a/GM/PalTile.cpp +++ b/GM/PalTile.cpp @@ -104,12 +104,11 @@ void CTilePalette::Serialize(CArchive& ar) void CTilePalette::LoadTileNameList() { - const CTileManager* pTMgr = m_pDoc.GetTileManager(); - ASSERT(pTMgr != NULL); + const CTileManager& pTMgr = m_pDoc.GetTileManager(); m_comboTGrp->Clear(); - for (size_t i = size_t(0); i < pTMgr->GetNumTileSets(); i++) - m_comboTGrp->Append(pTMgr->GetTileSet(i).GetName()); + for (size_t i = size_t(0); i < pTMgr.GetNumTileSets(); i++) + m_comboTGrp->Append(pTMgr.GetTileSet(i).GetName()); m_comboTGrp->SetSelection(0); UpdateTileList(); } @@ -131,8 +130,7 @@ void CTilePalette::UpdatePaletteContents() void CTilePalette::UpdateTileList() { - const CTileManager* pTMgr = m_pDoc.GetTileManager(); - ASSERT(pTMgr != NULL); + const CTileManager& pTMgr = m_pDoc.GetTileManager(); int nSel = m_comboTGrp->GetSelection(); if (nSel == wxNOT_FOUND) @@ -140,7 +138,7 @@ void CTilePalette::UpdateTileList() m_listTile->SetItemMap(NULL); return; } - const std::vector& pPieceTbl = pTMgr->GetTileSet(value_preserving_cast(nSel)).GetTileIDTable(); + const std::vector& pPieceTbl = pTMgr.GetTileSet(value_preserving_cast(nSel)).GetTileIDTable(); m_listTile->SetItemMap(&pPieceTbl); } @@ -155,7 +153,7 @@ void CTilePalette::OnTileNameCbnSelchange(wxCommandEvent& /*event*/) void CTilePalette::OnGetDragSize(GetDragSizeEvent& event) { TileID tid = GetCurrentTileID(); - CTile tile = m_pDoc.GetTileManager()->GetTile(tid, fullScale); + CTile tile = m_pDoc.GetTileManager().GetTile(tid, fullScale); CSize size = tile.GetSize(); event.SetSize(wxSize(size.cx, size.cy)); } diff --git a/GM/ToolObjs.cpp b/GM/ToolObjs.cpp index a4af192..b3b2f9a 100644 --- a/GM/ToolObjs.cpp +++ b/GM/ToolObjs.cpp @@ -822,7 +822,7 @@ wxCursor CPaintTool::OnSetCursor(const CBrdEditView& pView, wxPoint /*point*/) c void CTileTool::OnLButtonDown(CBrdEditView& pView, int nMods, wxPoint point) { - TileID tid = pView.GetDocument().GetTilePalWnd()->GetCurrentTileID(); + TileID tid = pView.GetDocument().GetTilePalWnd().GetCurrentTileID(); if (pView.GetBoard().GetMaxDrawLayer() == LAYER_GRID) pView.SetCellTile(tid, point, TRUE); else @@ -837,7 +837,7 @@ void CTileTool::OnMouseMove(CBrdEditView& pView, int nMods, int nButs, wxPoint p if ((nButs & wxMOUSE_BTN_LEFT) != 0 && pView.GetBoard().GetMaxDrawLayer() == LAYER_GRID) { - TileID tid = pView.GetDocument().GetTilePalWnd()->GetCurrentTileID(); + TileID tid = pView.GetDocument().GetTilePalWnd().GetCurrentTileID(); pView.SetCellTile(tid, point, TRUE); } } diff --git a/GM/VwBitedt.cpp b/GM/VwBitedt.cpp index 64b4efa..3274ced 100644 --- a/GM/VwBitedt.cpp +++ b/GM/VwBitedt.cpp @@ -34,6 +34,7 @@ #include "DlgBmask.h" #include "DlgPaste.h" #include "CDib.h" +#include "FrmMain.h" // TODO: remove? #ifdef _DEBUG #undef THIS_FILE @@ -49,7 +50,10 @@ const size_t maxUndoLevels = size_t(8); ///////////////////////////////////////////////////////////////////////////// -wxBEGIN_EVENT_TABLE(CBitEditView, wxScrolledCanvas) +namespace { + typedef wxDocChildFrameAny>, wxWindow> NoCommas; +} +wxBEGIN_EVENT_TABLE(CBitEditView, NoCommas) EVT_MENU(XRCID("ID_IMAGE_GRIDLINES"), OnImageGridLines) EVT_MENU(XRCID("ID_ITOOL_PENCIL"), OnToolPalette) EVT_SETCOLOR(OnSetColor) @@ -112,7 +116,6 @@ wxEND_EVENT_TABLE() BEGIN_MESSAGE_MAP(CBitEditViewContainer, CView) ON_WM_CREATE() - ON_WM_SIZE() ON_WM_SETFOCUS() END_MESSAGE_MAP() @@ -123,7 +126,7 @@ IMPLEMENT_DYNCREATE(CBitEditViewContainer, CView) CBitEditView::CBitEditView(CBitEditViewContainer& p) : parent(&p), - document(dynamic_cast(parent->GetDocument())) + document(CB::ToCGamDoc(parent->GetDocument())) { m_pSelView = NULL; m_nZoom = 6; @@ -138,6 +141,8 @@ CBitEditView::CBitEditView(CBitEditViewContainer& p) : m_nLastToolID = XRCID("ID_ITOOL_PENCIL"); m_bSelectCapture = FALSE; wxScrolledCanvas::Create(*parent, 0); + wxView->SetDocument(&*document); + wxView->SetFrame(this); } CBitEditView::~CBitEditView() @@ -149,11 +154,13 @@ CBitEditView::~CBitEditView() void CBitEditView::OnInitialUpdate() { + CB_VERIFY(Create(&GetDocument(), &*wxView, *GetMainFrame(), wxID_ANY, "dummy")); + wxSizer* sizer = new wxBoxSizer(wxVERTICAL); SetSizer(sizer); sizer->Add(100, 100); SetScrollRate(4, 4); - m_pTMgr = GetDocument().GetTileManager(); + m_pTMgr = &GetDocument().GetTileManager(); UpdateFontInfo(); RecalcScrollLimits(); } @@ -232,7 +239,15 @@ void CBitEditView::OnDraw(wxDC& pDC) void CBitEditViewContainer::OnActivateView(BOOL bActivate, CView *pActivateView, CView* pDeactivateView) { - CView::OnActivateView(bActivate, pActivateView, pDeactivateView); + CB::OnCmdMsgOverride::OnActivateView(bActivate, pActivateView, pDeactivateView); + + // KLUDGE: often get deactivate w/o activate + if (bActivate) + { + wxActivateEvent event(wxEVT_ACTIVATE, bActivate); + child->ProcessWindowEvent(event); + } + if (pActivateView == pDeactivateView) return; // if (m_nCurToolID == ID_ITOOL_TEXT) @@ -1068,13 +1083,13 @@ void CBitEditView::OnUpdateLineWidth(wxUpdateUIEvent& pCmdUI) void CBitEditView::OnImageBoardMask(wxCommandEvent& /*event*/) { - CBoardManager* pBMgr = GetDocument().GetBoardManager(); + CBoardManager& pBMgr = GetDocument().GetBoardManager(); - CBoardMaskDialog dlg(CheckedDeref(pBMgr)); + CBoardMaskDialog dlg(pBMgr); if (dlg.ShowModal() != wxID_OK || dlg.m_nBrdNum == Invalid_v) return; - CBoard& pBoard = pBMgr->GetBoard(value_preserving_cast(dlg.m_nBrdNum)); + CBoard& pBoard = pBMgr.GetBoard(value_preserving_cast(dlg.m_nBrdNum)); const CCellForm& pcf = pBoard.GetBoardArray(). GetCellForm(m_pSelView->GetCurrentScale()); @@ -1112,7 +1127,7 @@ void CBitEditView::OnImageBoardMask(wxCommandEvent& /*event*/) void CBitEditView::OnUpdateImageBoardMask(wxUpdateUIEvent& pCmdUI) { pCmdUI.Enable(m_pSelView->GetCurrentScale() != smallScale && - !GetDocument().GetBoardManager()->IsEmpty()); + !GetDocument().GetBoardManager().IsEmpty()); } void CBitEditView::OnUpdateViewZoomIn(wxUpdateUIEvent& pCmdUI) @@ -1313,17 +1328,14 @@ int CBitEditViewContainer::OnCreate(LPCREATESTRUCT lpCreateStruct) return -1; } + static_cast(*GetMainFrame()).AddChild(*this); + wxASSERT(static_cast(*this).GetParent() == *GetMainFrame()); + child = new CBitEditView(*this); return 0; } -void CBitEditViewContainer::OnSize(UINT nType, int cx, int cy) -{ - child->SetSize(0, 0, cx, cy); - return CView::OnSize(nType, cx, cy); -} - // MFC puts the focus here, so move it to the useful window void CBitEditViewContainer::OnSetFocus(CWnd* pOldWnd) { diff --git a/GM/VwBitedt.h b/GM/VwBitedt.h index 37f8c14..a9066f7 100644 --- a/GM/VwBitedt.h +++ b/GM/VwBitedt.h @@ -39,7 +39,7 @@ class CTileSelView; -class CBitEditView : public CB::ProcessEventOverride +class CBitEditView : public wxDocChildFrameAny>, wxWindow> { friend class CBitEditViewContainer; friend class CTileSelViewContainer; @@ -236,6 +236,7 @@ class CBitEditView : public CB::ProcessEventOverride RefPtr parent; RefPtr document; + OwnerPtr wxView = MakeOwner(*this); }; class CBitEditViewContainer : public CB::OnCmdMsgOverride, @@ -260,7 +261,6 @@ class CBitEditViewContainer : public CB::OnCmdMsgOverride, DECLARE_DYNCREATE(CBitEditViewContainer) afx_msg int OnCreate(LPCREATESTRUCT lpCreateStruct); - afx_msg void OnSize(UINT nType, int cx, int cy); afx_msg void OnSetFocus(CWnd* pOldWnd); DECLARE_MESSAGE_MAP() diff --git a/GM/VwEdtbrd.cpp b/GM/VwEdtbrd.cpp index b38ddc5..92fd3d9 100644 --- a/GM/VwEdtbrd.cpp +++ b/GM/VwEdtbrd.cpp @@ -51,7 +51,10 @@ static char THIS_FILE[] = __FILE__; IMPLEMENT_DYNCREATE(CBrdEditViewContainer, CView) -wxBEGIN_EVENT_TABLE(CBrdEditView, wxScrolledCanvas) +namespace { + typedef wxDocChildFrameAny>, wxWindow> NoCommas; +} +wxBEGIN_EVENT_TABLE(CBrdEditView, NoCommas) #if 0 ON_WM_MOUSEWHEEL() #endif @@ -161,7 +164,7 @@ END_MESSAGE_MAP() CBrdEditView::CBrdEditView(CBrdEditViewContainer& p) : m_selList(*this), parent(&p), - document(dynamic_cast(parent->GetDocument())), + document(CB::ToCGamDoc(parent->GetDocument())), timer(this) { m_bOffScreen = TRUE; @@ -175,6 +178,8 @@ CBrdEditView::CBrdEditView(CBrdEditViewContainer& p) : SetSizer(sizer); sizer->Add(0, 0); wxScrolledCanvas::Create(*parent, 0); + wxView->SetDocument(&*document); + wxView->SetFrame(this); } CBrdEditView::~CBrdEditView() @@ -197,7 +202,9 @@ BOOL CBrdEditView::PreCreateWindow(CREATESTRUCT& cs) void CBrdEditView::OnInitialUpdate() { - m_pBMgr = GetDocument().GetBoardManager(); + CB_VERIFY(Create(&GetDocument(), &*wxView, *GetMainFrame(), wxID_ANY, "dummy")); + + m_pBMgr = &GetDocument().GetBoardManager(); m_pBoard = static_cast(GetDocument().GetCreateParameter()); RecalcScrollLimits(); } @@ -945,12 +952,12 @@ void CBrdEditView::OnDragTileItem(DragDropEvent& event) void CBrdEditView::SetDrawingTile(CDrawList& pDwg, TileID tid, wxPoint pnt, BOOL bUpdate) { - CTileManager* pTMgr = GetDocument().GetTileManager(); + CTileManager& pTMgr = GetDocument().GetTileManager(); { OwnerPtr pTileImage(MakeOwner(pTMgr)); // Center the image on the drop point. - CTile tile = pTMgr->GetTile(tid); + CTile tile = pTMgr.GetTile(tid); wxRect rct(pnt, CB::Convert(tile.GetSize())); rct.Offset(-rct.GetWidth() / 2, -rct.GetHeight() / 2); AdjustRect(rct); @@ -1066,7 +1073,7 @@ void CBrdEditView::DoCreateTextDrawingObject(wxPoint point) return; // No text here! CTextObjDialog dlg; - dlg.m_pFontMgr = CGamDoc::GetFontManager(); + dlg.m_pFontMgr = &CGamDoc::GetFontManager(); dlg.SetFontID(m_pBMgr->GetFontID()); if (dlg.ShowModal() == wxID_OK) @@ -1084,7 +1091,7 @@ void CBrdEditView::DoEditTextDrawingObject(CText& pDObj) { CTextObjDialog dlg; dlg.m_strText = wxString(pDObj.m_text); - dlg.m_pFontMgr = CGamDoc::GetFontManager(); + dlg.m_pFontMgr = &CGamDoc::GetFontManager(); dlg.SetFontID(pDObj.m_fontID); if (dlg.ShowModal() == wxID_OK) @@ -1378,7 +1385,7 @@ void CBrdEditView::OnUpdateToolPalette(wxUpdateUIEvent& pCmdUI) if (pCmdUI.GetId() == XRCID("ID_TOOL_TILE")) { - tid = GetDocument().GetTilePalWnd()->GetCurrentTileID(); + tid = GetDocument().GetTilePalWnd().GetCurrentTileID(); bEnable = tid != nullTid; if (tid == nullTid && m_nCurToolID == XRCID("ID_TOOL_TILE")) { @@ -2350,6 +2357,18 @@ void CBrdEditViewContainer::OnUpdate(CView* pSender, LPARAM lHint, CObject* pHin child->OnUpdate(pSender, lHint, pHint); } +void CBrdEditViewContainer::OnActivateView(BOOL bActivate, CView* pActivateView, CView* pDeactiveView) +{ + CB::OnCmdMsgOverride::OnActivateView(bActivate, pActivateView, pDeactiveView); + + // KLUDGE: often get deactivate w/o activate + if (bActivate) + { + wxActivateEvent event(wxEVT_ACTIVATE, bActivate); + child->ProcessWindowEvent(event); + } +} + CBrdEditViewContainer::CBrdEditViewContainer() : CB::wxNativeContainerWindowMixin(static_cast(*this)) { @@ -2362,6 +2381,9 @@ int CBrdEditViewContainer::OnCreate(LPCREATESTRUCT lpCreateStruct) return -1; } + static_cast(*GetMainFrame()).AddChild(*this); + wxASSERT(static_cast(*this).GetParent() == *GetMainFrame()); + child = new CBrdEditView(*this); return 0; diff --git a/GM/VwEdtbrd.h b/GM/VwEdtbrd.h index 2b05a52..aa1a98b 100644 --- a/GM/VwEdtbrd.h +++ b/GM/VwEdtbrd.h @@ -34,7 +34,7 @@ class CBrdEditViewContainer; -class CBrdEditView : public CB::ProcessEventOverride +class CBrdEditView : public wxDocChildFrameAny>, wxWindow> { protected: // create from serialization only CBrdEditView(CBrdEditViewContainer& p); @@ -307,6 +307,7 @@ class CBrdEditView : public CB::ProcessEventOverride RefPtr parent; RefPtr document; + OwnerPtr wxView = MakeOwner(*this); wxTimer timer; wxOverlay overlay; @@ -331,6 +332,7 @@ class CBrdEditViewContainer : public CB::OnCmdMsgOverride, void OnDraw(CDC* pDC) override; void OnInitialUpdate() override; void OnUpdate(CView* pSender, LPARAM lHint, CObject* pHint) override; + void OnActivateView(BOOL bActivate, CView* pActivateView, CView* pDeactiveView) override; private: CBrdEditViewContainer(); // used by dynamic creation diff --git a/GM/VwPrjgb1.cpp b/GM/VwPrjgb1.cpp index 89b7897..97b79e5 100644 --- a/GM/VwPrjgb1.cpp +++ b/GM/VwPrjgb1.cpp @@ -94,7 +94,7 @@ void CGbxProjView::DoBoardProperty() wxASSERT(m_listProj->GetItemGroupCode(value_preserving_cast(nSel)) == grpBrd); size_t nBrd = m_listProj->GetItemSourceCode(value_preserving_cast(nSel)); - CBoard& pBoard = pDoc.GetBoardManager()->GetBoard(nBrd); + CBoard& pBoard = pDoc.GetBoardManager().GetBoard(nBrd); if (pDoc.DoBoardPropertyDialog(pBoard)) { @@ -118,9 +118,9 @@ void CGbxProjView::DoBoardDelete() wxYES_NO | wxICON_EXCLAMATION) == wxYES) { CGmBoxHint hint; - hint.GetArgs().m_pBoard = &pDoc.GetBoardManager()->GetBoard(nBrd); + hint.GetArgs().m_pBoard = &pDoc.GetBoardManager().GetBoard(nBrd); - pDoc.GetBoardManager()->DeleteBoard(nBrd); + pDoc.GetBoardManager().DeleteBoard(nBrd); // Make sure any views on the board are closed. pDoc.UpdateAllViews(NULL, HINT_BOARDDELETED, &hint); @@ -138,24 +138,24 @@ void CGbxProjView::DoBoardClone() wxASSERT(m_listProj->GetItemGroupCode(value_preserving_cast(nSel)) == grpBrd); size_t nBrd = m_listProj->GetItemSourceCode(value_preserving_cast(nSel)); - CBoardManager* pBMgr = pDoc.GetBoardManager(); + CBoardManager& pBMgr = pDoc.GetBoardManager(); - wxASSERT(nBrd < pBMgr->GetNumBoards()); - CBoard& pOrigBoard = pBMgr->GetBoard(nBrd); + wxASSERT(nBrd < pBMgr.GetNumBoards()); + CBoard& pOrigBoard = pBMgr.GetBoard(nBrd); TRY { CGamDoc::SetLoadingVersionGuard setLoadingVersionGuard(NumVersion(fileGbxVerMajor, fileGbxVerMinor)); CMemFile file; CArchive arSave(&file, CArchive::store); - arSave.m_pDocument = &pDoc; + arSave.m_pDocument = pDoc; SetFileFeaturesGuard setFileFeaturesGuard(arSave, GetCBFeatures()); pOrigBoard.Serialize(arSave); // Make a copy of the board arSave.Close(); file.SeekToBegin(); CArchive arRestore(&file, CArchive::load); - arRestore.m_pDocument = &pDoc; + arRestore.m_pDocument = pDoc; OwnerPtr pNewBoard = new CBoard(); pNewBoard->Serialize(arRestore); @@ -164,10 +164,10 @@ void CGbxProjView::DoBoardClone() CB::string strNewName = CB::string::LoadString(IDS_COPY_OF); strNewName += pNewBoard->GetName(); pNewBoard->SetName(strNewName); - pNewBoard->SetSerialNumber(pBMgr->IssueSerialNumber()); + pNewBoard->SetSerialNumber(pBMgr.IssueSerialNumber()); // Add it to the board list - pBMgr->Add(std::move(pNewBoard)); + pBMgr.Add(std::move(pNewBoard)); } CATCH_ALL(e) { @@ -187,7 +187,7 @@ void CGbxProjView::DoBoardEdit() wxASSERT(m_listProj->GetItemGroupCode(value_preserving_cast(nSel)) == grpBrd); size_t nBrd = m_listProj->GetItemSourceCode(value_preserving_cast(nSel)); - CBoard& pBoard = pDoc.GetBoardManager()->GetBoard(nBrd); + CBoard& pBoard = pDoc.GetBoardManager().GetBoard(nBrd); CView* pView = pDoc.FindBoardEditorView(pBoard); if (pView != NULL) { @@ -199,7 +199,7 @@ void CGbxProjView::DoBoardEdit() else { CB::string strTitle = m_listProj->GetItemText(value_preserving_cast(nSel)); - pDoc.CreateNewFrame(GetApp()->m_pMapViewTmpl, strTitle, &pBoard); + pDoc.CreateNewFrame(CheckedDeref(GetApp()->m_pMapViewTmpl), strTitle, &pBoard); } } @@ -238,14 +238,14 @@ void CGbxProjView::DoTileGroupProperty() size_t nGrp = m_listProj->GetItemSourceCode(value_preserving_cast(nSel)); CTSetPropDialog dlg; - CTileManager* pTMgr = pDoc.GetTileManager(); - dlg.m_crTrans = CB::Convert(pTMgr->GetTransparentColor()); - dlg.m_strName = wxString(pTMgr->GetTileSet(nGrp).GetName()); + CTileManager& pTMgr = pDoc.GetTileManager(); + dlg.m_crTrans = CB::Convert(pTMgr.GetTransparentColor()); + dlg.m_strName = wxString(pTMgr.GetTileSet(nGrp).GetName()); if (dlg.ShowModal() == wxID_OK) { - pTMgr->SetTransparentColor(CB::Convert(dlg.m_crTrans)); - pTMgr->GetTileSet(nGrp).SetName(dlg.m_strName); + pTMgr.SetTransparentColor(CB::Convert(dlg.m_crTrans)); + pTMgr.GetTileSet(nGrp).SetName(dlg.m_strName); pDoc.UpdateAllViews(NULL, HINT_TILESETPROPCHANGE, NULL); pDoc.SetModifiedFlag(); } @@ -266,7 +266,7 @@ void CGbxProjView::DoTileGroupDelete() CB::GetAppName(), wxYES_NO | wxICON_EXCLAMATION) == wxYES) { - pDoc.GetTileManager()->DeleteTileSet(nGrp); + pDoc.GetTileManager().DeleteTileSet(nGrp); // Make sure no TileID references survive pDoc.NotifyTileDatabaseChange(); @@ -290,20 +290,20 @@ void CGbxProjView::DoTileNew() size_t nGrp = m_listProj->GetItemSourceCode(value_preserving_cast(nSel)); CNewTileDialog dlg; - dlg.m_pBMgr = pDoc.GetBoardManager(); + dlg.m_pBMgr = &pDoc.GetBoardManager(); - CTileManager* pTMgr = pDoc.GetTileManager(); + CTileManager& pTMgr = pDoc.GetTileManager(); if (dlg.ShowModal() == wxID_OK) { - TileID tidNew = pTMgr->CreateTile(nGrp, + TileID tidNew = pTMgr.CreateTile(nGrp, CSize(dlg.m_nWidth, dlg.m_nHeight), CSize(dlg.m_nHalfWidth, dlg.m_nHalfHeight), RGB(255, 255, 255)); CGmBoxHint hint; hint.GetArgs().m_tid = tidNew; pDoc.UpdateAllViews(NULL, HINT_TILECREATED, &hint); - pDoc.CreateNewFrame(GetApp()->m_pTileEditTmpl, "Tile Editor", + pDoc.CreateNewFrame(CheckedDeref(GetApp()->m_pTileEditTmpl), "Tile Editor", reinterpret_cast(value_preserving_cast(tidNew))); pDoc.SetModifiedFlag(); } @@ -320,7 +320,6 @@ void CGbxProjView::DoTileEdit() if (m_listTiles->GetSelectedCount() <= 0) return; std::vector tidtbl = m_listTiles->GetCurMappedItemList(); - CTileManager* pTMgr = pDoc.GetTileManager(); for (size_t i = 0; i < tidtbl.size(); i++) { @@ -336,7 +335,7 @@ void CGbxProjView::DoTileEdit() } else { - pDoc.CreateNewFrame(GetApp()->m_pTileEditTmpl, "Tile Editor", + pDoc.CreateNewFrame(CheckedDeref(GetApp()->m_pTileEditTmpl), "Tile Editor", reinterpret_cast(value_preserving_cast(tid))); } } @@ -354,32 +353,32 @@ void CGbxProjView::DoTileClone() if (m_listTiles->GetSelectedCount() <= 0) return; std::vector tidtbl = m_listTiles->GetCurMappedItemList(); - CTileManager* pTMgr = pDoc.GetTileManager(); + CTileManager& pTMgr = pDoc.GetTileManager(); for (size_t i = 0; i < tidtbl.size(); i++) { TileID tid = tidtbl[i]; - CTileUpdatable tileFull = pTMgr->GetTile(tid, fullScale); - CTileUpdatable tileHalf = pTMgr->GetTile(tid, halfScale); - CTile tileSmall = pTMgr->GetTile(tid, smallScale); + CTileUpdatable tileFull = pTMgr.GetTile(tid, fullScale); + CTileUpdatable tileHalf = pTMgr.GetTile(tid, halfScale); + CTile tileSmall = pTMgr.GetTile(tid, smallScale); - TileID tidNew = pTMgr->CreateTile(nGrp, tileFull.GetSize(), + TileID tidNew = pTMgr.CreateTile(nGrp, tileFull.GetSize(), tileHalf.GetSize(), tileSmall.GetSmallColor()); OwnerPtr bmap = tileFull.CreateBitmapOfTile(); - tileFull = pTMgr->GetTile(tidNew, fullScale); + tileFull = pTMgr.GetTile(tidNew, fullScale); tileFull.Update(*bmap); bmap = tileHalf.CreateBitmapOfTile(); - tileHalf = pTMgr->GetTile(tidNew, halfScale); + tileHalf = pTMgr.GetTile(tidNew, halfScale); tileHalf.Update(*bmap); CGmBoxHint hint; hint.GetArgs().m_tid = tidNew; pDoc.UpdateAllViews(NULL, HINT_TILECREATED, &hint); - pDoc.CreateNewFrame(GetApp()->m_pTileEditTmpl, "Tile Editor", + pDoc.CreateNewFrame(CheckedDeref(GetApp()->m_pTileEditTmpl), "Tile Editor", reinterpret_cast(value_preserving_cast(tidNew))); } pDoc.SetModifiedFlag(); @@ -405,10 +404,10 @@ void CGbxProjView::DoTileDelete() wxYES_NO | wxICON_EXCLAMATION | wxNO_DEFAULT) != wxYES) return; } - CTileManager* pTMgr = pDoc.GetTileManager(); + CTileManager& pTMgr = pDoc.GetTileManager(); for (size_t i = size_t(0); i < tidtbl.size(); i++) { - pTMgr->DeleteTile(tidtbl[i]); + pTMgr.DeleteTile(tidtbl[i]); CGmBoxHint hint; hint.GetArgs().m_tid = tidtbl[i]; pDoc.UpdateAllViews(NULL, HINT_TILEDELETED, &hint); @@ -434,7 +433,7 @@ void CGbxProjView::DoUpdateTileList() wxASSERT(m_listProj->GetItemGroupCode(value_preserving_cast(nSel)) == grpTile); size_t nGrp = m_listProj->GetItemSourceCode(value_preserving_cast(nSel)); - const CTileSet& pTSet = pDoc.GetTileManager()->GetTileSet(nGrp); + const CTileSet& pTSet = pDoc.GetTileManager().GetTileSet(nGrp); const std::vector& pLstMap = pTSet.GetTileIDTable(); m_listTiles->SetItemMap(&pLstMap); } @@ -456,14 +455,14 @@ void CGbxProjView::DoPieceGroupProperty() wxASSERT(m_listProj->GetItemGroupCode(value_preserving_cast(nSel)) == grpPce); size_t nGrp = m_listProj->GetItemSourceCode(value_preserving_cast(nSel)); - CPieceManager* pPMgr = pDoc.GetPieceManager(); + CPieceManager& pPMgr = pDoc.GetPieceManager(); CPiecePropDialog dlg; - dlg.m_strName = wxString(pPMgr->GetPieceSet(nGrp).GetName()); + dlg.m_strName = wxString(pPMgr.GetPieceSet(nGrp).GetName()); if (dlg.ShowModal() == wxID_OK) { - pPMgr->GetPieceSet(nGrp).SetName(dlg.m_strName); + pPMgr.GetPieceSet(nGrp).SetName(dlg.m_strName); pDoc.UpdateAllViews(NULL, HINT_PIECESETPROPCHANGE, NULL); pDoc.SetModifiedFlag(); } @@ -483,7 +482,7 @@ void CGbxProjView::DoPieceGroupDelete() CB::GetAppName(), wxYES_NO | wxICON_EXCLAMATION) == wxYES) { - pDoc.GetPieceManager()->DeletePieceSet(nGrp, &pDoc.GetGameStringMap()); + pDoc.GetPieceManager().DeletePieceSet(nGrp, &pDoc.GetGameStringMap()); // Make sure any views on the tileset informed. CGmBoxHint hint; @@ -542,7 +541,7 @@ void CGbxProjView::DoPieceEdit() for (size_t i = size_t(0) ; i < tblSel.size() ; ++i) { pids[i] = m_listPieces->MapIndexToItem(value_preserving_cast(tblSel[i])); - pDefs.push_back(&pDoc.GetPieceManager()->GetPiece(pids[i])); + pDefs.push_back(&pDoc.GetPieceManager().GetPiece(pids[i])); sides = CB::max(sides, pDefs[i]->GetSides()); } @@ -600,7 +599,7 @@ void CGbxProjView::DoPieceDelete() m_listPieces->SetItemMap(NULL); for (size_t i = size_t(0); i < pieces.size(); i++) - pDoc.GetPieceManager()->DeletePiece(pieces[i], &pDoc.GetGameStringMap()); + pDoc.GetPieceManager().DeletePiece(pieces[i], &pDoc.GetGameStringMap()); pDoc.UpdateAllViews(NULL, HINT_PIECEDELETED, NULL); pDoc.SetModifiedFlag(); @@ -622,7 +621,7 @@ void CGbxProjView::DoUpdatePieceList() wxASSERT(m_listProj->GetItemGroupCode(value_preserving_cast(nSel)) == grpPce); size_t nGrp = m_listProj->GetItemSourceCode(value_preserving_cast(nSel)); - CPieceSet& pPSet = pDoc.GetPieceManager()->GetPieceSet(nGrp); + CPieceSet& pPSet = pDoc.GetPieceManager().GetPieceSet(nGrp); const std::vector& pLstMap = pPSet.GetPieceIDTable(); m_listPieces->SetItemMap(&pLstMap); } @@ -644,8 +643,8 @@ void CGbxProjView::DoMarkGroupProperty() wxASSERT(m_listProj->GetItemGroupCode(value_preserving_cast(nSel)) == grpMark); size_t nGrp = m_listProj->GetItemSourceCode(value_preserving_cast(nSel)); - CMarkManager* pMMgr = pDoc.GetMarkManager(); - CMarkSet& pMSet = pMMgr->GetMarkSet(nGrp); + CMarkManager& pMMgr = pDoc.GetMarkManager(); + CMarkSet& pMSet = pMMgr.GetMarkSet(nGrp); CMarkerPropDialog dlg; dlg.m_strName = wxString(pMSet.GetName()); @@ -675,7 +674,7 @@ void CGbxProjView::DoMarkGroupDelete() CB::GetAppName(), wxYES_NO | wxICON_EXCLAMATION) == wxYES) { - pDoc.GetMarkManager()->DeleteMarkSet(nGrp, &pDoc.GetGameStringMap()); + pDoc.GetMarkManager().DeleteMarkSet(nGrp, &pDoc.GetGameStringMap()); CGmBoxHint hint; hint.GetArgs().m_markSet = nGrp; @@ -732,7 +731,7 @@ void CGbxProjView::DoMarkEdit() for (size_t i = size_t(0) ; i < tblSel.size() ; ++i) { MarkID mid = m_listMarks->MapIndexToItem(tblSel[i]); - MarkDef& pDef = pDoc.GetMarkManager()->GetMark(mid); + MarkDef& pDef = pDoc.GetMarkManager().GetMark(mid); // Process "prompt for text" change if (dlg.m_bPromptForText != wxCHK_UNDETERMINED) { @@ -771,7 +770,7 @@ void CGbxProjView::DoMarkDelete() m_listMarks->SetItemMap(NULL); for (size_t i = size_t(0); i < markers.size(); i++) - pDoc.GetMarkManager()->DeleteMark(markers[i], &pDoc.GetGameStringMap()); + pDoc.GetMarkManager().DeleteMark(markers[i], &pDoc.GetGameStringMap()); pDoc.UpdateAllViews(NULL, HINT_MARKERDELETED, NULL); pDoc.SetModifiedFlag(); @@ -793,7 +792,7 @@ void CGbxProjView::DoUpdateMarkList() wxASSERT(m_listProj->GetItemGroupCode(value_preserving_cast(nSel)) == grpMark); size_t nGrp = m_listProj->GetItemSourceCode(value_preserving_cast(nSel)); - CMarkSet& pMSet = pDoc.GetMarkManager()->GetMarkSet(nGrp); + CMarkSet& pMSet = pDoc.GetMarkManager().GetMarkSet(nGrp); const std::vector& pLstMap = pMSet.GetMarkIDTable(); m_listMarks->SetItemMap(&pLstMap); } diff --git a/GM/VwPrjgbx.cpp b/GM/VwPrjgbx.cpp index 67ba335..1f999b2 100644 --- a/GM/VwPrjgbx.cpp +++ b/GM/VwPrjgbx.cpp @@ -34,6 +34,7 @@ #include "VwPrjgbx.h" #include "LibMfc.h" +#include "FrmMain.h" // TODO: remove? #ifdef _DEBUG #undef THIS_FILE @@ -102,7 +103,10 @@ static UINT * btnGroupTbl[nNumGroups + 1] = ///////////////////////////////////////////////////////////////////////////// -wxBEGIN_EVENT_TABLE(CGbxProjView, wxPanel) +namespace { + typedef wxDocChildFrameAny, wxWindow> NoCommas; +} +wxBEGIN_EVENT_TABLE(CGbxProjView, NoCommas) #if 0 ON_WM_SIZE() ON_WM_CREATE() @@ -183,7 +187,7 @@ CGbxProjView::CGbxProjView(CGbxProjViewContainer& p) : CB_XRC_CTRL(m_btnItmD) CB_XRC_END_CTRLS_DEFN(), parent(&p), - document(dynamic_cast(parent->GetDocument())) + document(CB::ToCGamDoc(parent->GetDocument())) { m_nLastSel = -1; m_nLastGrp = -1; @@ -192,6 +196,8 @@ CGbxProjView::CGbxProjView(CGbxProjViewContainer& p) : m_listTiles->EnableDrag(); m_listTiles->EnableSelfDrop(); m_listTiles->EnableDropScroll(); + wxView->SetDocument(&*document); + wxView->SetFrame(this); } CGbxProjView::~CGbxProjView() @@ -271,6 +277,8 @@ int CGbxProjView::OnCreate(LPCREATESTRUCT lpCreateStruct) void CGbxProjView::OnInitialUpdate() { + CB_VERIFY(Create(&GetDocument(), &*wxView, *GetMainFrame(), wxID_ANY, "dummy")); + m_listTiles->SetDocument(&GetDocument()); m_listPieces->SetDocument(GetDocument()); m_listMarks->SetDocument(&GetDocument()); @@ -484,8 +492,8 @@ void CGbxProjView::OnDragItem(DragDropEvent& event) m_listProj->GetItemGroupCode(value_preserving_cast(nProjSel)) == grpTile); size_t nGrpSel = m_listProj->GetItemSourceCode(value_preserving_cast(nProjSel)); - CTileManager* pTMgr = pDoc.GetTileManager(); - const CTileSet& pTGrp = pTMgr->GetTileSet(nGrpSel); + CTileManager& pTMgr = pDoc.GetTileManager(); + const CTileSet& pTGrp = pTMgr.GetTileSet(nGrpSel); // Force selection of item under the mouse m_listTiles->SetSelFromPoint(pdi.m_point); @@ -504,7 +512,7 @@ void CGbxProjView::OnDragItem(DragDropEvent& event) nSel++; } - pTMgr->MoveTileIDsToTileSet(nGrpSel, *pdi.GetSubInfo().m_tileIDList, value_preserving_cast(nSel)); + pTMgr.MoveTileIDsToTileSet(nGrpSel, *pdi.GetSubInfo().m_tileIDList, value_preserving_cast(nSel)); DoUpdateTileList(); pDoc.NotifyTileDatabaseChange(); m_listTiles->SetCurSelsMapped(*pdi.GetSubInfo().m_tileIDList); @@ -607,21 +615,20 @@ void CGbxProjView::DoUpdateProjectList(BOOL bUpdateItem /* = TRUE */) str = CB::string::LoadString(IDS_PHEAD_BOARDS); m_listProj->AddItem(grpBHdr, str); - CBoardManager* pBMgr = pDoc.GetBoardManager(); - wxASSERT(pBMgr); - for (size_t i = size_t(0); i < pBMgr->GetNumBoards(); i++) + CBoardManager& pBMgr = pDoc.GetBoardManager(); + for (size_t i = size_t(0); i < pBMgr.GetNumBoards(); i++) { static int bDisplayIDs = -1; if (bDisplayIDs == -1) { bDisplayIDs = GetApp()->GetProfileInt("Settings"_cbstring, "DisplayIDs"_cbstring, 0); } - str = pBMgr->GetBoard(i).GetName(); + str = pBMgr.GetBoard(i).GetName(); if (bDisplayIDs) { CB::string strTmp = std::move(str); str = std::format(L"[{}] {}", - pBMgr->GetBoard(i).GetSerialNumber(), strTmp); + pBMgr.GetBoard(i).GetSerialNumber(), strTmp); } m_listProj->AddItem(grpBrd, str, i); } @@ -630,28 +637,25 @@ void CGbxProjView::DoUpdateProjectList(BOOL bUpdateItem /* = TRUE */) str = CB::string::LoadString(IDS_PHEAD_TILES); m_listProj->AddItem(grpTHdr, str); - CTileManager* pTMgr = pDoc.GetTileManager(); - wxASSERT(pTMgr); - for (size_t i = size_t(0); i < pTMgr->GetNumTileSets(); i++) - m_listProj->AddItem(grpTile, pTMgr->GetTileSet(i).GetName(), i); + CTileManager& pTMgr = pDoc.GetTileManager(); + for (size_t i = size_t(0); i < pTMgr.GetNumTileSets(); i++) + m_listProj->AddItem(grpTile, pTMgr.GetTileSet(i).GetName(), i); // Pieces.... str = CB::string::LoadString(IDS_PHEAD_PIECES); m_listProj->AddItem(grpPHdr, str); - CPieceManager* pPMgr = pDoc.GetPieceManager(); - wxASSERT(pPMgr); - for (size_t i = size_t(0); i < pPMgr->GetNumPieceSets(); i++) - m_listProj->AddItem(grpPce, pPMgr->GetPieceSet(i).GetName(), i); + CPieceManager& pPMgr = pDoc.GetPieceManager(); + for (size_t i = size_t(0); i < pPMgr.GetNumPieceSets(); i++) + m_listProj->AddItem(grpPce, pPMgr.GetPieceSet(i).GetName(), i); // Marks.... str = CB::string::LoadString(IDS_PHEAD_MARKS); m_listProj->AddItem(grpMHdr, str); - CMarkManager* pMMgr = pDoc.GetMarkManager(); - wxASSERT(pMMgr); - for (size_t i = size_t(0); i < pMMgr->GetNumMarkSets(); i++) - m_listProj->AddItem(grpMark, pMMgr->GetMarkSet(i).GetName(), i); + CMarkManager& pMMgr = pDoc.GetMarkManager(); + for (size_t i = size_t(0); i < pMMgr.GetNumMarkSets(); i++) + m_listProj->AddItem(grpMark, pMMgr.GetMarkSet(i).GetName(), i); // OK...Show the updates } @@ -844,7 +848,7 @@ void CGbxProjView::OnEditCopy(wxCommandEvent& /*event*/) #endif CGamDoc& pDoc = GetDocument(); - CTileManager* pTMgr = pDoc.GetTileManager(); + CTileManager& pTMgr = pDoc.GetTileManager(); std::vector tidtbl = m_listTiles->GetCurMappedItemList(); @@ -853,7 +857,7 @@ void CGbxProjView::OnEditCopy(wxCommandEvent& /*event*/) { CMemFile file; CArchive ar(&file, CArchive::store); - pTMgr->CopyTileImagesToArchive(ar, tidtbl); + pTMgr.CopyTileImagesToArchive(ar, tidtbl); ar.Close(); CMemFile file2; @@ -921,7 +925,7 @@ void CGbxProjView::OnEditPaste(wxCommandEvent& event) size_t nGrp = m_listProj->GetItemSourceCode(value_preserving_cast(nSel)); CGamDoc& pDoc = GetDocument(); - CTileManager* pTMgr = pDoc.GetTileManager(); + CTileManager& pTMgr = pDoc.GetTileManager(); wxBusyCursor busyCursor; TRY @@ -939,7 +943,7 @@ void CGbxProjView::OnEditPaste(wxCommandEvent& event) CArchive ar(&file, CArchive::load); int nCurSel = m_listTiles->GetTopSelectedItem(); size_t nCurSel2 = nCurSel == wxNOT_FOUND ? Invalid_v : value_preserving_cast(nCurSel); - pTMgr->CreateTilesFromTileImageArchive(ar, nGrp, &tidtbl, nCurSel2); + pTMgr.CreateTilesFromTileImageArchive(ar, nGrp, &tidtbl, nCurSel2); ar.Close(); } DoUpdateTileList(); @@ -972,7 +976,7 @@ void CGbxProjView::OnEditMove(wxCommandEvent& event) size_t nGrp = m_listProj->GetItemSourceCode(value_preserving_cast(nSel)); CGamDoc& pDoc = GetDocument(); - CTileManager* pTMgr = pDoc.GetTileManager(); + CTileManager& pTMgr = pDoc.GetTileManager(); wxBusyCursor busyCursor; TRY @@ -1006,7 +1010,7 @@ void CGbxProjView::OnEditMove(wxCommandEvent& event) ar.Close(); int nCurSel = m_listTiles->GetTopSelectedItem(); size_t nCurSel2 = nCurSel == LB_ERR ? Invalid_v : value_preserving_cast(nCurSel); - pTMgr->MoveTileIDsToTileSet(nGrp, tidtbl, nCurSel2); + pTMgr.MoveTileIDsToTileSet(nGrp, tidtbl, nCurSel2); DoUpdateTileList(); pDoc.NotifyTileDatabaseChange(); m_listTiles->SetCurSelsMapped(tidtbl); @@ -1071,7 +1075,7 @@ void CGbxProjView::OnProjectSaveTileFile(wxCommandEvent& /*event*/) #endif CGamDoc& pDoc = GetDocument(); - CTileManager* pTMgr = pDoc.GetTileManager(); + CTileManager& pTMgr = pDoc.GetTileManager(); CB::string strFilter = CB::string::LoadString(IDS_GTL_FILTER); CB::string strTitle = CB::string::LoadString(IDS_SEL_SAVETILELIBRARY); @@ -1103,7 +1107,7 @@ void CGbxProjView::OnProjectSaveTileFile(wxCommandEvent& /*event*/) ar.Write(FILEGTLSIGNATURE, 4); // TODO: if new format ever needed, use Features ar << (WORD)NumVersion(fileGtlVerMajor, fileGtlVerMinor); - pTMgr->CopyTileImagesToArchive(ar, tidtbl); + pTMgr.CopyTileImagesToArchive(ar, tidtbl); ar.Close(); file.Close(); } @@ -1130,7 +1134,7 @@ void CGbxProjView::OnProjectLoadTileFile(wxCommandEvent& /*event*/) size_t nGrp = m_listProj->GetItemSourceCode(value_preserving_cast(nSel)); CGamDoc& pDoc = GetDocument(); - CTileManager* pTMgr = pDoc.GetTileManager(); + CTileManager& pTMgr = pDoc.GetTileManager(); CB::string strFilter = CB::string::LoadString(IDS_GTL_FILTER); CB::string strTitle = CB::string::LoadString(IDS_SEL_LOADTILELIBRARY); @@ -1183,7 +1187,7 @@ void CGbxProjView::OnProjectLoadTileFile(wxCommandEvent& /*event*/) std::vector tidtbl; int nCurSel = m_listTiles->GetTopSelectedItem(); size_t nCurSel2 = nCurSel == wxNOT_FOUND ? Invalid_v : value_preserving_cast(nCurSel); - pTMgr->CreateTilesFromTileImageArchive(ar, nGrp, &tidtbl, nCurSel2); + pTMgr.CreateTilesFromTileImageArchive(ar, nGrp, &tidtbl, nCurSel2); ar.Close(); DoUpdateTileList(); @@ -1450,6 +1454,18 @@ void CGbxProjViewContainer::OnUpdate(CView* pSender, LPARAM lHint, CObject* pHin CB::OnCmdMsgOverride::OnUpdate(pSender, lHint, pHint); } +void CGbxProjViewContainer::OnActivateView(BOOL bActivate, CView* pActivateView, CView* pDeactiveView) +{ + CB::OnCmdMsgOverride::OnActivateView(bActivate, pActivateView, pDeactiveView); + + // KLUDGE: often get deactivate w/o activate + if (bActivate) + { + wxActivateEvent event(wxEVT_ACTIVATE, bActivate); + child->ProcessWindowEvent(event); + } +} + CGbxProjViewContainer::CGbxProjViewContainer() : CB::wxNativeContainerWindowMixin(static_cast(*this)) { @@ -1462,6 +1478,9 @@ int CGbxProjViewContainer::OnCreate(LPCREATESTRUCT lpCreateStruct) return -1; } + static_cast(*GetMainFrame()).AddChild(*this); + wxASSERT(static_cast(*this).GetParent() == *GetMainFrame()); + child = new CGbxProjView(*this); return 0; diff --git a/GM/VwPrjgbx.h b/GM/VwPrjgbx.h index b5ad560..c553dac 100644 --- a/GM/VwPrjgbx.h +++ b/GM/VwPrjgbx.h @@ -75,7 +75,7 @@ class CProjListBoxGm : public CProjListBoxWx, wxWindow>, private CB::Impl::CGbxProjViewBase { protected: CGbxProjView(CGbxProjViewContainer& p); @@ -250,6 +250,7 @@ class CGbxProjView : public wxPanel, private CB::Impl::CGbxProjViewBase private: RefPtr parent; RefPtr document; + OwnerPtr wxView = MakeOwner(*this); friend class CGbxProjViewContainer; }; @@ -266,6 +267,7 @@ class CGbxProjViewContainer : public CB::OnCmdMsgOverride, void OnDraw(CDC* pDC) override; void OnInitialUpdate() override; void OnUpdate(CView* pSender, LPARAM lHint, CObject* pHint) override; + void OnActivateView(BOOL bActivate, CView* pActivateView, CView* pDeactiveView) override; private: CGbxProjViewContainer(); // used by dynamic creation diff --git a/GM/VwTilesl.cpp b/GM/VwTilesl.cpp index d1c3a3e..bf7dfc1 100644 --- a/GM/VwTilesl.cpp +++ b/GM/VwTilesl.cpp @@ -29,6 +29,7 @@ #include "VwTilesl.h" #include "VwBitedt.h" #include "DlgTilsz.h" +#include "FrmMain.h" // TODO: remove? #ifdef _DEBUG #undef THIS_FILE @@ -46,22 +47,26 @@ IMPLEMENT_DYNCREATE(CTileSelViewContainer, CView) CTileSelView::CTileSelView(CTileSelViewContainer& p) : parent(&p), - document(dynamic_cast(parent->GetDocument())) + document(CB::ToCGamDoc(parent->GetDocument())) { m_pTileMgr = NULL; m_pEditView = NULL; m_tid = nullTid; m_bNoUpdate = FALSE; wxScrolledCanvas::Create(*parent, 0); + wxView->SetDocument(&*document); + wxView->SetFrame(this); } -wxBEGIN_EVENT_TABLE(CTileSelView, wxScrolledCanvas) +namespace { + typedef wxDocChildFrameAny, wxWindow> NoCommas; +} +wxBEGIN_EVENT_TABLE(CTileSelView, NoCommas) EVT_LEFT_DOWN(OnLButtonDown) wxEND_EVENT_TABLE() BEGIN_MESSAGE_MAP(CTileSelViewContainer, CView) ON_WM_CREATE() - ON_WM_SIZE() ON_MESSAGE(WM_SETCOLOR, OnSetColor) ON_MESSAGE(WM_SETCUSTOMCOLOR, OnSetCustomColors) ON_MESSAGE(WM_SETLINEWIDTH, OnSetLineWidth) @@ -104,8 +109,9 @@ END_MESSAGE_MAP() void CTileSelView::OnInitialUpdate() { - m_pTileMgr = GetDocument().GetTileManager(); - ASSERT(m_pTileMgr != NULL); + CB_VERIFY(Create(&GetDocument(), &*wxView, *GetMainFrame(), wxID_ANY, "dummy")); + + m_pTileMgr = &GetDocument().GetTileManager(); m_tid = static_cast(reinterpret_cast(GetDocument().GetCreateParameter())); ASSERT(m_tid != nullTid); @@ -275,7 +281,7 @@ void CTileSelView::DoTileResizeDialog() { CResizeTileDialog dlg; GetActiveBitmap() = CloneBitmap(m_pEditView->GetCurrentViewBitmap()); - dlg.m_pBMgr = GetDocument().GetBoardManager(); + dlg.m_pBMgr = &GetDocument().GetBoardManager(); dlg.m_bRescaleBMaps = true; dlg.m_nWidth = m_sizeFull.x; dlg.m_nHeight = m_sizeFull.y; @@ -679,6 +685,9 @@ void CTileSelViewContainer::OnActivateView(BOOL bActivate, wxWindow& bitEditParent = CheckedDeref(bitEdit.GetParent()); CView& view = CheckedDeref(dynamic_cast(CB::ToCWnd(bitEditParent))); GetParentFrame()->SetActiveView(&view); + + wxActivateEvent event(wxEVT_ACTIVATE, bActivate); + bitEdit.ProcessWindowEvent(event); } } @@ -699,13 +708,10 @@ int CTileSelViewContainer::OnCreate(LPCREATESTRUCT lpCreateStruct) return -1; } + static_cast(*GetMainFrame()).AddChild(*this); + wxASSERT(static_cast(*this).GetParent() == *GetMainFrame()); + child = new CTileSelView(*this); return 0; } - -void CTileSelViewContainer::OnSize(UINT nType, int cx, int cy) -{ - child->SetSize(0, 0, cx, cy); - return CView::OnSize(nType, cx, cy); -} diff --git a/GM/VwTilesl.h b/GM/VwTilesl.h index f2e185c..20ba3cd 100644 --- a/GM/VwTilesl.h +++ b/GM/VwTilesl.h @@ -35,7 +35,7 @@ class CBitEditView; class CTileSelViewContainer; -class CTileSelView : public wxScrolledCanvas +class CTileSelView : public wxDocChildFrameAny, wxWindow> { friend class CBitEditFrame; friend class CTileSelViewContainer; @@ -118,6 +118,7 @@ class CTileSelView : public wxScrolledCanvas private: RefPtr parent; RefPtr document; + OwnerPtr wxView = MakeOwner(*this); }; class CTileSelViewContainer : public CView, @@ -143,7 +144,6 @@ class CTileSelViewContainer : public CView, DECLARE_DYNCREATE(CTileSelViewContainer) afx_msg int OnCreate(LPCREATESTRUCT lpCreateStruct); - afx_msg void OnSize(UINT nType, int cx, int cy); afx_msg LRESULT OnSetColor(WPARAM wParam, LPARAM lParam); afx_msg LRESULT OnSetCustomColors(WPARAM wParam, LPARAM lParam); afx_msg LRESULT OnSetLineWidth(WPARAM wParam, LPARAM lParam); diff --git a/GP/DlgItray.cpp b/GP/DlgItray.cpp index 7b43086..d258798 100644 --- a/GP/DlgItray.cpp +++ b/GP/DlgItray.cpp @@ -1,6 +1,6 @@ // DlgITray.cpp : implementation file // -// Copyright (c) 1994-2020 By Dale L. Larson, All Rights Reserved. +// Copyright (c) 1994-2024 By Dale L. Larson & William Su, All Rights Reserved. // // Permission is hereby granted, free of charge, to any person obtaining // a copy of this software and associated documentation files (the @@ -91,17 +91,17 @@ BOOL CImportTraysDlg::OnInitDialog() ASSERT(m_pDoc != NULL); // MUST BE SET CDialog::OnInitDialog(); - const CPieceManager* pPMgr = m_pDoc->GetPieceManager(); + const CPieceManager& pPMgr = m_pDoc->GetPieceManager(); CTrayManager* pYMgr = m_pDoc->GetTrayManager(); - ASSERT(pYMgr != NULL && pPMgr != NULL); + ASSERT(pYMgr != NULL); // Loop through all the piece groups in the gamebox. If a group // already doesn't exist as a tray in the scenario, add it to the // listbox. - for (size_t nPSet = 0; nPSet < pPMgr->GetNumPieceSets(); nPSet++) + for (size_t nPSet = size_t(0); nPSet < pPMgr.GetNumPieceSets(); nPSet++) { - CB::string strName = pPMgr->GetPieceSet(nPSet).GetName(); + CB::string strName = pPMgr.GetPieceSet(nPSet).GetName(); size_t nTray; for (nTray = size_t(0); nTray < pYMgr->GetNumTraySets(); nTray++) { @@ -123,7 +123,7 @@ BOOL CImportTraysDlg::OnInitDialog() void CImportTraysDlg::OnOK() { - const CPieceManager* pPMgr = m_pDoc->GetPieceManager(); + const CPieceManager& pPMgr = m_pDoc->GetPieceManager(); CTrayManager* pYMgr = m_pDoc->GetTrayManager(); CPieceTable* pPTbl = m_pDoc->GetPieceTable(); ASSERT(pPTbl != NULL); @@ -133,7 +133,7 @@ void CImportTraysDlg::OnOK() if (m_listGroups.GetCheck(i) > 0) { size_t nPSet = value_preserving_cast(m_listGroups.GetItemData(i)); - const CPieceSet& pPSet = pPMgr->GetPieceSet(nPSet); + const CPieceSet& pPSet = pPMgr.GetPieceSet(nPSet); // Create tray and add pieces... size_t nTray = pYMgr->CreateTraySet(pPSet.GetName()); diff --git a/GP/DlgNewGeoBoard.cpp b/GP/DlgNewGeoBoard.cpp index 4960fdc..66f2eda 100644 --- a/GP/DlgNewGeoBoard.cpp +++ b/GP/DlgNewGeoBoard.cpp @@ -1,6 +1,6 @@ // DlgNewGeoBoard.cpp : implementation file // -// Copyright (c) 1994-2023 By Dale L. Larson & William Su, All Rights Reserved. +// Copyright (c) 1994-2024 By Dale L. Larson & William Su, All Rights Reserved. // // Permission is hereby granted, free of charge, to any person obtaining // a copy of this software and associated documentation files (the @@ -110,11 +110,11 @@ void CCreateGeomorphicBoardDialog::LoadBoardListWithCompliantBoards() // All boards must use hexes and have an odd number of columns // or rows along the flat side of the hex. // New option: cformRect - CBoardManager* pBMgr = m_pDoc->GetBoardManager(); + CBoardManager& pBMgr = m_pDoc->GetBoardManager(); - for (size_t i = 0; i < pBMgr->GetNumBoards(); i++) + for (size_t i = size_t(0); i < pBMgr.GetNumBoards(); i++) { - CBoard& pBrd = pBMgr->GetBoard(i); + CBoard& pBrd = pBMgr.GetBoard(i); CBoardArray& pBArray = pBrd.GetBoardArray(); const CCellForm& pCellForm = pBArray.GetCellForm(fullScale); @@ -141,7 +141,7 @@ void CCreateGeomorphicBoardDialog::LoadBoardListWithCompliantBoards() } std::unique_ptr ge(new CGeoBoardElement(Invalid_v, Invalid_v, pBrd.GetSerialNumber(), r)); - const CBoard& pBrd = pBMgr->Get(*ge); + const CBoard& pBrd = pBMgr.Get(*ge); const CBoardArray& pBArray = pBrd.GetBoardArray(); const CCellForm& pCellForm = pBArray.GetCellForm(fullScale); @@ -149,7 +149,7 @@ void CCreateGeomorphicBoardDialog::LoadBoardListWithCompliantBoards() { // Already have at least one map selected. The rest must // comply with the geometry of the root one. - const CBoard& rootBoard = pBMgr->Get(*m_pRootBoard); + const CBoard& rootBoard = pBMgr.Get(*m_pRootBoard); const CBoardArray& rootBArray = rootBoard.GetBoardArray(); const CCellForm& rootCellForm = rootBArray.GetCellForm(fullScale); if (!rootCellForm.CompareEqual(pCellForm)) @@ -247,8 +247,8 @@ void CCreateGeomorphicBoardDialog::OnBtnPressedAddBoard() { ASSERT(m_listBoard.GetCurSel() >= 0); CGeoBoardElement& ge = *static_cast(m_listBoard.GetItemDataPtr(m_listBoard.GetCurSel())); - CBoardManager* pBMgr = m_pDoc->GetBoardManager(); - const CBoard& pBrd = pBMgr->Get(ge); + CBoardManager& pBMgr = m_pDoc->GetBoardManager(); + const CBoard& pBrd = pBMgr.Get(ge); const CBoardArray& pBArray = pBrd.GetBoardArray(); m_pRootBoard.reset(new CGeoBoardElement(ge)); diff --git a/GP/FrmPbrd.cpp b/GP/FrmPbrd.cpp index 31e1b60..eda068c 100644 --- a/GP/FrmPbrd.cpp +++ b/GP/FrmPbrd.cpp @@ -121,7 +121,7 @@ BOOL CPlayBoardFrame::PreCreateWindow(CREATESTRUCT& cs) void CPlayBoardFrame::OnUpdateFrameTitle(BOOL bAddToTitle) { - CGamDoc* pDoc = (CGamDoc*)GetActiveDocument(); + CGamDoc* pDoc = CB::ToCGamDoc(GetActiveDocument()); CB::string str = pDoc->GetTitle(); CB::string strBoardName = m_pPBoard->GetBoard()->GetName(); @@ -144,7 +144,7 @@ void CPlayBoardFrame::OnUpdateFrameTitle(BOOL bAddToTitle) BOOL CPlayBoardFrame::OnCreateClient(LPCREATESTRUCT lpcs, CCreateContext* pContext) { - CGamDoc* pDoc = (CGamDoc*)pContext->m_pCurrentDoc; + CGamDoc* pDoc = CB::ToCGamDoc(pContext->m_pCurrentDoc); m_pPBoard = (CPlayBoard*)pDoc->GetNewViewParameter(); ASSERT(m_pPBoard != NULL); diff --git a/GP/FrmProj.cpp b/GP/FrmProj.cpp index dcf0795..b85a8e6 100644 --- a/GP/FrmProj.cpp +++ b/GP/FrmProj.cpp @@ -69,7 +69,7 @@ BOOL CProjFrame::PreCreateWindow(CREATESTRUCT& cs) void CProjFrame::OnUpdateFrameTitle(BOOL bAddToTitle) { - CGamDoc* pDoc = (CGamDoc*)GetActiveDocument(); + CGamDoc* pDoc = CB::ToCGamDoc(GetActiveDocument()); CB::string str = pDoc->GetTitle(); str += " - "; CB::string strType; @@ -92,7 +92,7 @@ void CProjFrame::OnSysCommand(UINT nID, LPARAM lParam) if (pView->IsKindOf(RUNTIME_CLASS(CGsnProjView)) || pView->IsKindOf(RUNTIME_CLASS(CGamProjView))) { - ((CGamDoc*)GetActiveDocument())->OnFileClose(); + CB::ToCGamDoc(GetActiveDocument())->OnFileClose(); return; } } @@ -103,5 +103,5 @@ void CProjFrame::OnSysCommand(UINT nID, LPARAM lParam) void CProjFrame::OnClose() { // Close the document when the main document window is closed. - ((CGamDoc*)GetActiveDocument())->OnFileClose(); + CB::ToCGamDoc(GetActiveDocument())->OnFileClose(); } diff --git a/GP/GamDoc.cpp b/GP/GamDoc.cpp index f1ca80d..dd61cd7 100644 --- a/GP/GamDoc.cpp +++ b/GP/GamDoc.cpp @@ -1,6 +1,6 @@ // GamDoc.cpp // -// Copyright (c) 1994-2023 By Dale L. Larson & William Su, All Rights Reserved. +// Copyright (c) 1994-2024 By Dale L. Larson & William Su, All Rights Reserved. // // Permission is hereby granted, free of charge, to any person obtaining // a copy of this software and associated documentation files (the @@ -367,10 +367,10 @@ void CGamDoc::DeleteContents() delete m_pTileFacingMap; m_pTileFacingMap = NULL; - if (m_pGbx != NULL) delete m_pGbx; - m_pGbx = NULL; if (m_pPBMgr != NULL) delete m_pPBMgr; m_pPBMgr = NULL; + if (m_pGbx != NULL) delete m_pGbx; + m_pGbx = NULL; if (m_pYMgr != NULL) delete m_pYMgr; m_pYMgr = NULL; if (m_pPTbl != NULL) delete m_pPTbl; @@ -956,28 +956,24 @@ DWORD CGamDoc::IssueScenarioID() ///////////////////////////////////////////////////////////////////////////// -const CTileManager* CGamDoc::GetTileManager() const +const CTileManager& CGamDoc::GetTileManager() const { - if (m_pGbx == NULL) return NULL; - return m_pGbx->GetTileManager(); + return CheckedDeref(CheckedDeref(m_pGbx).GetTileManager()); } -CMarkManager* CGamDoc::GetMarkManager() +CMarkManager& CGamDoc::GetMarkManager() { - if (m_pGbx == NULL) return NULL; - return m_pGbx->GetMarkManager(); + return CheckedDeref(CheckedDeref(m_pGbx).GetMarkManager()); } -const CBoardManager* CGamDoc::GetBoardManager() const +const CBoardManager& CGamDoc::GetBoardManager() const { - if (m_pGbx == NULL) return NULL; - return m_pGbx->GetBoardManager(); + return CheckedDeref(CheckedDeref(m_pGbx).GetBoardManager()); } -const CPieceManager* CGamDoc::GetPieceManager() const +const CPieceManager& CGamDoc::GetPieceManager() const { - if (m_pGbx == NULL) return NULL; - return m_pGbx->GetPieceManager(); + return CheckedDeref(CheckedDeref(m_pGbx).GetPieceManager()); } //////////////////////////////////////////////////////////////////////// @@ -990,7 +986,7 @@ CTileFacingMap* CGamDoc::GetFacingMap() return m_pTileFacingMap; else { - m_pTileFacingMap = new CTileFacingMap(GetTileManager()); + m_pTileFacingMap = new CTileFacingMap(&GetTileManager()); return m_pTileFacingMap; } } diff --git a/GP/GamDoc.h b/GP/GamDoc.h index b3f5080..3804187 100644 --- a/GP/GamDoc.h +++ b/GP/GamDoc.h @@ -1,6 +1,6 @@ // GamDoc.h // -// Copyright (c) 1994-2023 By Dale L. Larson & William Su, All Rights Reserved. +// Copyright (c) 1994-2024 By Dale L. Larson & William Su, All Rights Reserved. // // Permission is hereby granted, free of charge, to any person obtaining // a copy of this software and associated documentation files (the @@ -268,7 +268,7 @@ class CGamDoc : public CDocument static Features c_fileFeatures; public: - static CFontTbl* GetFontManager() + static CFontTbl& GetFontManager() { return CGameBox::GetFontManager(); } static void SetLoadingVersion(int ver) { c_fileVersion = ver; } using SetLoadingVersionGuard = ::SetLoadingVersionGuard; @@ -314,15 +314,15 @@ class CGamDoc : public CDocument void* GetNewViewParameter() { return m_pvParam; } // Major game related objects... - const CTileManager* GetTileManager() const; - CTileManager* GetTileManager() { return const_cast(std::as_const(*this).GetTileManager()); } - CMarkManager* GetMarkManager(); - const CBoardManager* GetBoardManager() const; - CBoardManager* GetBoardManager() + const CTileManager& GetTileManager() const; + CTileManager& GetTileManager() { return const_cast(std::as_const(*this).GetTileManager()); } + CMarkManager& GetMarkManager(); + const CBoardManager& GetBoardManager() const; + CBoardManager& GetBoardManager() { - return const_cast(std::as_const(*this).GetBoardManager()); + return const_cast(std::as_const(*this).GetBoardManager()); } - const CPieceManager* GetPieceManager() const; + const CPieceManager& GetPieceManager() const; const CPieceTable* GetPieceTable() const { return m_pPTbl; } CPieceTable* GetPieceTable() { return const_cast(std::as_const(*this).GetPieceTable()); } const CTrayManager* GetTrayManager() const { return m_pYMgr; } @@ -818,6 +818,15 @@ class CGamDoc : public CDocument DECLARE_MESSAGE_MAP() }; +inline const CGamDoc* CB::ToCGamDoc(const CDocument* p) +{ + if (!p) + { + return nullptr; + } + return dynamic_cast(p); +} + ///////////////////////////////////////////////////////////////////////////// #endif // _GAMDOC_H diff --git a/GP/GamDoc1.cpp b/GP/GamDoc1.cpp index 0d99370..7560e73 100644 --- a/GP/GamDoc1.cpp +++ b/GP/GamDoc1.cpp @@ -719,14 +719,13 @@ CDrawObj& CGamDoc::CreateMarkerObject(CPlayBoard* pPBrd, MarkID mid, CPoint pnt, if (dwObjID == ObjectID()) dwObjID = CreateObjectID(CDrawObj::drawMarkObj); - CMarkManager* pMMgr = GetMarkManager(); - ASSERT(pMMgr != NULL); + CMarkManager& pMMgr = GetMarkManager(); - MarkDef& pMark = pMMgr->GetMark(mid); + MarkDef& pMark = pMMgr.GetMark(mid); ASSERT(pMark.m_tid != nullTid); // Marker is centered on point. - CTile tile = GetTileManager()->GetTile(pMark.m_tid, fullScale); + CTile tile = GetTileManager().GetTile(pMark.m_tid, fullScale); CRect rct(pnt, tile.GetSize()); rct -= CPoint(tile.GetWidth() / 2, tile.GetHeight() / 2); pPBrd->LimitRectToBoard(rct); diff --git a/GP/GamDoc3.cpp b/GP/GamDoc3.cpp index 6aaabbe..b82ee53 100644 --- a/GP/GamDoc3.cpp +++ b/GP/GamDoc3.cpp @@ -1,6 +1,6 @@ // GamDoc3.cpp -- serialization support for the document. // -// Copyright (c) 1994-2023 By Dale L. Larson & William Su, All Rights Reserved. +// Copyright (c) 1994-2024 By Dale L. Larson & William Su, All Rights Reserved. // // Permission is hereby granted, free of charge, to any person obtaining // a copy of this software and associated documentation files (the @@ -128,10 +128,10 @@ void CGamDoc::SerializeMoveSet(CArchive& ar, CHistRecord*& pHist) /* these features are global in the sense that, if any ID needs 32 bits, then we store all IDs in 32 bit format */ - if (GetBoardManager()->Needs32BitIDs() || - GetTileManager()->Needs32BitIDs() || - GetPieceManager()->Needs32BitIDs() || - GetMarkManager()->Needs32BitIDs()) + if (GetBoardManager().Needs32BitIDs() || + GetTileManager().Needs32BitIDs() || + GetPieceManager().Needs32BitIDs() || + GetMarkManager().Needs32BitIDs()) { if (!GetCBFeatures().Check(ftrId32Bit)) { @@ -139,7 +139,7 @@ void CGamDoc::SerializeMoveSet(CArchive& ar, CHistRecord*& pHist) } c_fileFeatures.Add(ftrId32Bit); } - if (GetPieceManager()->Needs100SidePieces()) + if (GetPieceManager().Needs100SidePieces()) { if (!GetCBFeatures().Check(ftrPiece100Sides)) { @@ -606,10 +606,10 @@ void CGamDoc::SerializeScenarioOrGame(CArchive& ar, uint64_t& offsetOffsetFeatur /* these features are global in the sense that, if any ID needs 32 bits, then we store all IDs in 32 bit format */ - if (GetBoardManager()->Needs32BitIDs() || - GetTileManager()->Needs32BitIDs() || - GetPieceManager()->Needs32BitIDs() || - GetMarkManager()->Needs32BitIDs()) + if (GetBoardManager().Needs32BitIDs() || + GetTileManager().Needs32BitIDs() || + GetPieceManager().Needs32BitIDs() || + GetMarkManager().Needs32BitIDs()) { if (!GetCBFeatures().Check(ftrId32Bit)) { @@ -617,7 +617,7 @@ void CGamDoc::SerializeScenarioOrGame(CArchive& ar, uint64_t& offsetOffsetFeatur } c_fileFeatures.Add(ftrId32Bit); } - if (GetPieceManager()->Needs100SidePieces()) + if (GetPieceManager().Needs100SidePieces()) { if (!GetCBFeatures().Check(ftrPiece100Sides)) { diff --git a/GP/GamState.cpp b/GP/GamState.cpp index b37fc89..c03b813 100644 --- a/GP/GamState.cpp +++ b/GP/GamState.cpp @@ -125,9 +125,9 @@ void CGameState::Serialize(CArchive& ar) { Clear(); - CGamDoc& doc = CheckedDeref(static_cast(ar.m_pDocument)); + CGamDoc& doc = CheckedDeref(CB::ToCGamDoc(ar.m_pDocument)); m_pPBMgr = new CPBoardManager(doc); - m_pPTbl = new CPieceTable(*doc.GetPieceManager(), doc); + m_pPTbl = new CPieceTable(doc.GetPieceManager(), doc); if (CGamDoc::GetLoadingVersion() >= NumVersion(2, 0)) m_mapString.Serialize(ar); // V2.0 diff --git a/GP/GameBox.h b/GP/GameBox.h index 4b8943b..c914dfd 100644 --- a/GP/GameBox.h +++ b/GP/GameBox.h @@ -53,7 +53,7 @@ class CGameBox // Static class functions public: - static CFontTbl* GetFontManager() { return &m_fontTbl; } + static CFontTbl& GetFontManager() { return m_fontTbl; } static void SetLoadingVersion(int ver) { c_gbxFileVersion = ver; } static int GetLoadingVersion() { return c_gbxFileVersion; } diff --git a/GP/GeoBoard.cpp b/GP/GeoBoard.cpp index f2c1ccb..0aa1152 100644 --- a/GP/GeoBoard.cpp +++ b/GP/GeoBoard.cpp @@ -1,6 +1,6 @@ // GeoBoard.cpp // -// Copyright (c) 1994-2023 By Dale L. Larson & William Su, All Rights Reserved. +// Copyright (c) 1994-2024 By Dale L. Larson & William Su, All Rights Reserved. // // Permission is hereby granted, free of charge, to any person obtaining // a copy of this software and associated documentation files (the @@ -218,7 +218,7 @@ OwnerPtr CGeomorphicBoard::CreateBoard() // CBoard::Rotate() requires unrotated source const CGeoBoardElement& gbe = GetBoardElt(size_t(0), size_t(0)); - CBoardManager& boardMgr = CheckedDeref(m_pDoc->GetBoardManager()); + CBoardManager& boardMgr = m_pDoc->GetBoardManager(); size_t index = boardMgr.FindBoardBySerial(gbe.m_nBoardSerialNum); const CBoard& pBrd0 = boardMgr.GetBoard(index); OwnerPtr pBrdNew = pBrd0.Clone(*m_pDoc, gbe.m_rotation); @@ -396,12 +396,9 @@ OwnerPtr CGeomorphicBoard::CreateBoard() void CGeomorphicBoard::DeleteFromBoardManager() { - CBoardManager* pBMgr = m_pDoc->GetBoardManager(); - if (pBMgr != NULL) - { - size_t nBrd = pBMgr->FindBoardBySerial(GetSerialNumber()); - pBMgr->DeleteBoard(nBrd); - } + CBoardManager& pBMgr = m_pDoc->GetBoardManager(); + size_t nBrd = pBMgr.FindBoardBySerial(GetSerialNumber()); + pBMgr.DeleteBoard(nBrd); } size_t CTileManager::GetSpecialTileSet() @@ -430,7 +427,7 @@ void CGeomorphicBoard::CopyCells(CBoardArray& pBArryTo, bool mergeTop = NeedsMerge(gbeFrom, Edge::Top); bool mergeLeft = NeedsMerge(gbeFrom, Edge::Left); - CTileManager* pTMgr = m_pDoc->GetTileManager(); + CTileManager& pTMgr = m_pDoc->GetTileManager(); for (size_t nRow = size_t(0) ; nRow < pBArryFrom.GetRows() ; ++nRow) { for (size_t nCol = size_t(0) ; nCol < pBArryFrom.GetCols() ; ++nCol) @@ -528,16 +525,16 @@ void CGeomorphicBoard::CopyCells(CBoardArray& pBArryTo, COLORREF crSmall; if (pCellTo.IsTileID()) { - CTile tile = pTMgr->GetTile(pCellTo.GetTID(), smallScale); + CTile tile = pTMgr.GetTile(pCellTo.GetTID(), smallScale); crSmall = tile.GetSmallColor(); } else crSmall = pCellTo.GetColor(); CSize sizeFull = pBArryTo.GetCellSize(fullScale); CSize sizeHalf = pBArryTo.GetCellSize(halfScale); - TileID tidNew = pTMgr->CreateTile(pTMgr->GetSpecialTileSet(), + TileID tidNew = pTMgr.CreateTile(pTMgr.GetSpecialTileSet(), sizeFull, sizeHalf, crSmall); - pTMgr->UpdateTile(tidNew, *bmapFull, *bmapHalf, crSmall); + pTMgr.UpdateTile(tidNew, *bmapFull, *bmapHalf, crSmall); pCellTo.SetTID(tidNew); } else @@ -627,7 +624,7 @@ OwnerPtr CGeomorphicBoard::CreateBitmap(CSize size) const OwnerPtr retval = CreateRGBDIBSection(size.cx, size.cy); CBitmap* prvBMap = dc.SelectObject(&*retval); - CBrush brush(m_pDoc->GetTileManager()->GetTransparentColor()); + CBrush brush(m_pDoc->GetTileManager().GetTransparentColor()); CBrush* prvBrush = dc.SelectObject(&brush); dc.PatBlt(0, 0, size.cx, size.cy, PATCOPY); @@ -756,7 +753,7 @@ const CGeoBoardElement& CGeomorphicBoard::GetBoardElt(size_t nBoardRow, size_t n const CBoard& CGeomorphicBoard::GetBoard(const CGeoBoardElement& geo) const { - return m_pDoc->GetBoardManager()->Get(geo); + return m_pDoc->GetBoardManager().Get(geo); } namespace @@ -1159,7 +1156,7 @@ void CGeomorphicBoard::Serialize(CArchive& ar) CB::string CGeomorphicBoard::GetCellNumberStr(CPoint pnt, TileScale eScale) const { // find sub-board containing pnt - const CBoardManager& brdMgr = CheckedDeref(m_pDoc->GetBoardManager()); + const CBoardManager& brdMgr = m_pDoc->GetBoardManager(); size_t index = brdMgr.FindBoardBySerial(m_nSerialNum); const CBoard& brd = brdMgr.GetBoard(index); const CBoardArray& ba = brd.GetBoardArray(); diff --git a/GP/Gp.cpp b/GP/Gp.cpp index 498de4e..3acd21e 100644 --- a/GP/Gp.cpp +++ b/GP/Gp.cpp @@ -479,7 +479,7 @@ BOOL CGpApp::OnIdle(LONG lCount) POSITION pos2 = pTemplate->GetFirstDocPosition(); while (pos2) { - CGamDoc* pDoc = (CGamDoc*)pTemplate->GetNextDoc(pos2); + CGamDoc* pDoc = CB::ToCGamDoc(pTemplate->GetNextDoc(pos2)); ASSERT(pDoc != NULL); ASSERT(pDoc->IsKindOf(RUNTIME_CLASS(CGamDoc))); pDoc->OnIdle(bAppVisible && pDoc == pCurDoc); diff --git a/GP/LBoxSlct.cpp b/GP/LBoxSlct.cpp index 3d7c047..fe3ac12 100644 --- a/GP/LBoxSlct.cpp +++ b/GP/LBoxSlct.cpp @@ -65,7 +65,7 @@ END_MESSAGE_MAP() const CTileManager& CSelectListBox::GetTileManager() const { ASSERT(m_pDoc != NULL); - return CheckedDeref(m_pDoc->GetTileManager()); + return m_pDoc->GetTileManager(); } ///////////////////////////////////////////////////////////////////////////// @@ -398,8 +398,6 @@ CB::string CSelectListBox::OnGetItemDebugString(size_t nIndex) const CSize CSelectListBox::OnItemSize(size_t nIndex) const { ASSERT(m_pDoc != NULL); - CTileManager* pTMgr = m_pDoc->GetTileManager(); - ASSERT(pTMgr != NULL); std::vector tids = GetTileIDs(nIndex); ASSERT(!tids.empty() && tids[size_t(0)] != nullTid); @@ -439,7 +437,7 @@ std::vector CSelectListBox::GetTileIDs(size_t nIndex) const return retval; } - const PieceDef& pPce = m_pDoc->GetPieceManager()->GetPiece(pid); + const PieceDef& pPce = m_pDoc->GetPieceManager().GetPiece(pid); std::vector retval; if ((pPce.m_flags & PieceDef::flagShowOnlyVisibleSide) && @@ -461,7 +459,7 @@ std::vector CSelectListBox::GetTileIDs(size_t nIndex) const else if (pDObj.GetType() == CDrawObj::drawMarkObj) { MarkID mid = static_cast(pDObj).m_mid; - CMarkManager& pMMgr = CheckedDeref(m_pDoc->GetMarkManager()); + CMarkManager& pMMgr = m_pDoc->GetMarkManager(); std::vector retval; retval.push_back(pMMgr.GetMark(mid).m_tid); return retval; diff --git a/GP/LBoxTray.cpp b/GP/LBoxTray.cpp index 428094f..4f82632 100644 --- a/GP/LBoxTray.cpp +++ b/GP/LBoxTray.cpp @@ -60,7 +60,7 @@ CTrayListBox::CTrayListBox(CGamDoc& pDoc) : const CTileManager& CTrayListBox::GetTileManager() const { - return CheckedDeref(m_pDoc.GetTileManager()); + return m_pDoc.GetTileManager(); } BOOL CTrayListBox::IsShowingTileImages() const @@ -328,7 +328,7 @@ BOOL CTrayListBox::OnDragSetup(DragInfo& pDI) const bool CTrayListBox::IsShowAllSides(PieceID pid) const { const CPieceTable& pPTbl = CheckedDeref(m_pDoc.GetPieceTable()); - const PieceDef& pPce = m_pDoc.GetPieceManager()->GetPiece(pid); + const PieceDef& pPce = m_pDoc.GetPieceManager().GetPiece(pid); BOOL bIsOwnedByCurrentPlayer = m_pDoc.HasPlayers() && pPTbl.IsPieceOwnedBy(pid, m_pDoc.GetCurrentPlayerMask()); diff --git a/GP/MoveMgr.cpp b/GP/MoveMgr.cpp index e318b9f..d918b3f 100644 --- a/GP/MoveMgr.cpp +++ b/GP/MoveMgr.cpp @@ -2463,7 +2463,7 @@ void CMoveList::Serialize(CArchive& ar, BOOL bSaveUndo) block of moves involving the same hidden board(s) */ /* need to examine moves in original context, so push current state */ - CGamDoc& doc = CheckedDeref((CGamDoc*)ar.m_pDocument); + CGamDoc& doc = CheckedDeref(CB::ToCGamDoc(ar.m_pDocument)); class PushGameState { public: diff --git a/GP/PBoard.cpp b/GP/PBoard.cpp index ce59164..a546508 100644 --- a/GP/PBoard.cpp +++ b/GP/PBoard.cpp @@ -1,6 +1,6 @@ // PBoard.cpp // -// Copyright (c) 1994-2023 By Dale L. Larson & William Su, All Rights Reserved. +// Copyright (c) 1994-2024 By Dale L. Larson & William Su, All Rights Reserved. // // Permission is hereby granted, free of charge, to any person obtaining // a copy of this software and associated documentation files (the @@ -79,7 +79,7 @@ CPlayBoard::CPlayBoard(CGamDoc& doc) : m_nLineWidth = 1; m_crTextColor = RGB(0, 0, 0); m_crTextBoxColor = RGB(255, 255, 255); - m_fontID = CGameBox::GetFontManager()->AddFont( + m_fontID = CGameBox::GetFontManager().AddFont( TenthPointsToScreenPixels(100), taBold, uint8_t(FF_SWISS), "Arial"); m_bLockedDrawnBeneath = TRUE; @@ -146,8 +146,7 @@ void CPlayBoard::Draw(CDC& pDC, const CRect& pDrawRct, TileScale eScale) CPieceObj& CPlayBoard::AddPiece(CPoint pnt, PieceID pid) { - CTileManager* pTMgr = m_pDoc->GetTileManager(); - ASSERT(pTMgr); + CTileManager& pTMgr = m_pDoc->GetTileManager(); CPieceTable* pPTbl = m_pDoc->GetPieceTable(); ASSERT(pPTbl); TileID tid = pPTbl->GetActiveTileID(pid); @@ -156,7 +155,7 @@ CPieceObj& CPlayBoard::AddPiece(CPoint pnt, PieceID pid) if (IsOwned()) pPTbl->SetOwnerMask(pid, GetOwnerMask());// Force piece to be owned by this player - CTile tile = pTMgr->GetTile(tid, fullScale); + CTile tile = pTMgr.GetTile(tid, fullScale); CRect rct(pnt, tile.GetSize()); rct -= CPoint(tile.GetWidth() / 2, tile.GetHeight() / 2); LimitRectToBoard(rct); @@ -243,7 +242,7 @@ CBoard& CPlayBoard::CreateGeoBoard() ASSERT(m_pGeoBoard); OwnerPtr pBrd = m_pGeoBoard->CreateBoard(); CBoard& retval = *pBrd; - m_pDoc->GetBoardManager()->Add(std::move(pBrd)); + m_pDoc->GetBoardManager().Add(std::move(pBrd)); return retval; } @@ -341,8 +340,8 @@ void CPlayBoard::Serialize(CArchive& ar) ar << (DWORD)m_crTextColor; ar << (DWORD)m_crTextBoxColor; - CFontTbl* pFontMgr = CGamDoc::GetFontManager(); - pFontMgr->Archive(ar, m_fontID); + CFontTbl& pFontMgr = CGamDoc::GetFontManager(); + pFontMgr.Archive(ar, m_fontID); ar << (WORD)m_bGridRectCenters; ar << (WORD)m_bSnapMovePlot; @@ -397,15 +396,14 @@ void CPlayBoard::Serialize(CArchive& ar) ar >> m_nSerialNum; - CBoardManager* pBMgr = m_pDoc->GetBoardManager(); - ASSERT(pBMgr); - size_t nBrdNum = pBMgr->FindBoardBySerial(m_nSerialNum); + CBoardManager& pBMgr = m_pDoc->GetBoardManager(); + size_t nBrdNum = pBMgr.FindBoardBySerial(m_nSerialNum); if (nBrdNum == Invalid_v) { AfxMessageBox(IDS_ERR_BOARDMISSING, MB_OK | MB_ICONSTOP); AfxThrowArchiveException(CArchiveException::genericException); } - CBoard& pBrd = pBMgr->GetBoard(nBrdNum); + CBoard& pBrd = pBMgr.GetBoard(nBrdNum); SetBoard(pBrd); ar >> wTmp; m_bGridSnap = (BOOL)wTmp; @@ -458,9 +456,9 @@ void CPlayBoard::Serialize(CArchive& ar) ar >> dwTmp; m_crTextColor = (COLORREF)dwTmp; ar >> dwTmp; m_crTextBoxColor = (COLORREF)dwTmp; - CFontTbl* pFontMgr = CGamDoc::GetFontManager(); + CFontTbl& pFontMgr = CGamDoc::GetFontManager(); m_fontID = 0; - pFontMgr->Archive(ar, m_fontID); + pFontMgr.Archive(ar, m_fontID); ar >> wTmp; m_bGridRectCenters = (BOOL)wTmp; ar >> wTmp; m_bSnapMovePlot = (BOOL)wTmp; @@ -619,7 +617,7 @@ void CPBoardManager::SetPBoardList(const std::vector& tblBrds) void CPBoardManager::AddBoard(BoardID nSerialNum, BOOL bInheritSettings) { - CBoardManager& m_pBMgr = CheckedDeref(m_pDoc->GetBoardManager()); + CBoardManager& m_pBMgr = m_pDoc->GetBoardManager(); size_t nBrd = m_pBMgr.FindBoardBySerial(nSerialNum); ASSERT(nBrd != Invalid_v); CBoard& pBoard = m_pBMgr.GetBoard(nBrd); diff --git a/GP/PBoard.h b/GP/PBoard.h index 9d62be6..7193e3e 100644 --- a/GP/PBoard.h +++ b/GP/PBoard.h @@ -227,7 +227,7 @@ class CPBoardManager : private std::vector> // Attributes public: - const CBoardManager* GetBoardManager() const { return m_pDoc->GetBoardManager(); } + const CBoardManager* GetBoardManager() const { return &m_pDoc->GetBoardManager(); } size_t GetNumPBoards() const { return size(); } bool IsEmpty() const { return empty(); } const CPlayBoard& GetPBoard(size_t nBrd) const { return *at(nBrd); } diff --git a/GP/PPieces.cpp b/GP/PPieces.cpp index e35f504..67f1121 100644 --- a/GP/PPieces.cpp +++ b/GP/PPieces.cpp @@ -306,13 +306,13 @@ void CPieceTable::SetOwnerMask(PieceID pid, uint32_t dwMask) CSize CPieceTable::GetPieceSize(PieceID pid) const { - CTile tile = m_pDoc->GetTileManager()->GetTile(GetActiveTileID(pid)); + CTile tile = m_pDoc->GetTileManager().GetTile(GetActiveTileID(pid)); return tile.GetSize(); } CSize CPieceTable::GetPieceSize(PieceID pid, BOOL bWithFacing) { - CTile tile = m_pDoc->GetTileManager()->GetTile(GetActiveTileID(pid, bWithFacing)); + CTile tile = m_pDoc->GetTileManager().GetTile(GetActiveTileID(pid, bWithFacing)); return tile.GetSize(); } @@ -398,7 +398,7 @@ TileID CPieceTable::GetFrontTileID(PieceID pid, BOOL bWithFacing) BOOL CPieceTable::IsPieceInvisible(PieceID pid) const { TileID tid = GetActiveTileID(pid); - CTile tile = m_pDoc->GetTileManager()->GetTile(tid, smallScale); + CTile tile = m_pDoc->GetTileManager().GetTile(tid, smallScale); return tile.GetTransparent() == tile.GetSmallColor(); } diff --git a/GP/PalMark.cpp b/GP/PalMark.cpp index 2b3ad2c..312f3d1 100644 --- a/GP/PalMark.cpp +++ b/GP/PalMark.cpp @@ -1,6 +1,6 @@ // PalMark.cpp : implementation file // -// Copyright (c) 1994-2020 By Dale L. Larson, All Rights Reserved. +// Copyright (c) 1994-2024 By Dale L. Larson & William Su, All Rights Reserved. // // Permission is hereby granted, free of charge, to any person obtaining // a copy of this software and associated documentation files (the @@ -191,8 +191,8 @@ LRESULT CMarkerPalette::OnOverrideSelectedItem(WPARAM wParam, LPARAM lParam) if (nSel == Invalid_v) return (LRESULT)0; - CMarkManager* pMMgr = m_pDoc->GetMarkManager(); - CMarkSet& pMSet = pMMgr->GetMarkSet(nSel); + CMarkManager& pMMgr = m_pDoc->GetMarkManager(); + CMarkSet& pMSet = pMMgr.GetMarkSet(nSel); if (pMSet.IsRandomMarkerPull()) { COverrideInfo& oi = *reinterpret_cast*>(wParam); @@ -219,8 +219,8 @@ LRESULT CMarkerPalette::OnGetDragSize(WPARAM wParam, LPARAM /*lParam*/) ASSERT(!"bad tray"); return 0; } - CMarkManager* pMMgr = m_pDoc->GetMarkManager(); - CMarkSet& pMSet = pMMgr->GetMarkSet(nSel); + CMarkManager& pMMgr = m_pDoc->GetMarkManager(); + CMarkSet& pMSet = pMMgr.GetMarkSet(nSel); std::vector items; if (pMSet.IsRandomMarkerPull()) @@ -236,12 +236,12 @@ LRESULT CMarkerPalette::OnGetDragSize(WPARAM wParam, LPARAM /*lParam*/) items.push_back(m_listMark.GetCurSel()); } - CTileManager& tileMgr = CheckedDeref(m_pDoc->GetTileManager()); + CTileManager& tileMgr = m_pDoc->GetTileManager(); CSize retval(0, 0); for (int item : items) { MarkID mid = m_listMark.MapIndexToItem(value_preserving_cast(item)); - MarkDef& pMark = pMMgr->GetMark(mid); + MarkDef& pMark = pMMgr.GetMark(mid); ASSERT(pMark.m_tid != nullTid); CSize size = tileMgr.GetTile(pMark.m_tid).GetSize(); retval.cx = std::max(retval.cx, size.cx); @@ -256,7 +256,7 @@ LRESULT CMarkerPalette::OnGetDragSize(WPARAM wParam, LPARAM /*lParam*/) void CMarkerPalette::SelectMarker(MarkID mid) { - size_t nGrp = m_pDoc->GetMarkManager()->FindMarkInMarkSet(mid); + size_t nGrp = m_pDoc->GetMarkManager().FindMarkInMarkSet(mid); ASSERT(nGrp != Invalid_v); size_t nSel = GetSelectedMarkerGroup(); if (nSel != nGrp) @@ -323,13 +323,12 @@ void CMarkerPalette::SetDocument(CGamDoc *pDoc) void CMarkerPalette::LoadMarkerNameList() { ASSERT(m_pDoc); - CMarkManager* pMMgr = m_pDoc->GetMarkManager(); - ASSERT(pMMgr != NULL); + CMarkManager& pMMgr = m_pDoc->GetMarkManager(); m_comboMGrp.ResetContent(); - for (size_t i = 0; i < pMMgr->GetNumMarkSets(); i++) + for (size_t i = size_t(0); i < pMMgr.GetNumMarkSets(); i++) { - int nIdx = m_comboMGrp.AddString(pMMgr->GetMarkSet(i).GetName()); + int nIdx = m_comboMGrp.AddString(pMMgr.GetMarkSet(i).GetName()); m_comboMGrp.SetItemData(nIdx, value_preserving_cast(i)); // Store the marker index in the data item } m_comboMGrp.SetCurSel(0); @@ -354,8 +353,7 @@ void CMarkerPalette::UpdatePaletteContents() void CMarkerPalette::UpdateMarkerList() { ASSERT(m_pDoc); - CMarkManager* pMMgr = m_pDoc->GetMarkManager(); - ASSERT(pMMgr != NULL); + CMarkManager& pMMgr = m_pDoc->GetMarkManager(); size_t nSel = GetSelectedMarkerGroup(); if (nSel == Invalid_v) @@ -364,7 +362,7 @@ void CMarkerPalette::UpdateMarkerList() return; } - CMarkSet& pMSet = pMMgr->GetMarkSet(nSel); + CMarkSet& pMSet = pMMgr.GetMarkSet(nSel); const std::vector* pMarkTbl = &pMSet.GetMarkIDTable(); CB::string str = ""; diff --git a/GP/PalTray.cpp b/GP/PalTray.cpp index 7188061..fb05114 100644 --- a/GP/PalTray.cpp +++ b/GP/PalTray.cpp @@ -423,7 +423,7 @@ LRESULT CTrayPalette::OnGetDragSize(WPARAM wParam, LPARAM /*lParam*/) // check all sides of all items CPieceTable& pieceTable = CheckedDeref(m_pDoc->GetPieceTable()); - CTileManager& tileMgr = CheckedDeref(m_pDoc->GetTileManager()); + CTileManager& tileMgr = m_pDoc->GetTileManager(); DWORD player = m_pDoc->GetCurrentPlayerMask(); CSize retval(0, 0); for (int item : items) diff --git a/GP/VwPbrd.cpp b/GP/VwPbrd.cpp index 4b955fe..df6641f 100644 --- a/GP/VwPbrd.cpp +++ b/GP/VwPbrd.cpp @@ -648,7 +648,7 @@ LRESULT CPlayBoardView::DoDragMarker(DragInfo& pdi) } else if (pdi.m_phase == PhaseDrag::Drop) { - CMarkManager* pMMgr = pDoc->GetMarkManager(); + CMarkManager& pMMgr = pDoc->GetMarkManager(); CPoint pnt = pdi.m_point; MarkID mid = pdi.GetSubInfo().m_markID; ClientToWorkspace(pnt); @@ -666,7 +666,7 @@ LRESULT CPlayBoardView::DoDragMarker(DragInfo& pdi) ASSERT(nMrkGrp != Invalid_v); if (nMrkGrp == Invalid_v) goto NASTY_GOTO_TARGET; - CMarkSet& pMSet = pMMgr->GetMarkSet(nMrkGrp); + CMarkSet& pMSet = pMMgr.GetMarkSet(nMrkGrp); CMarkerCountDialog dlg; dlg.m_nMarkerCount = 2; @@ -696,7 +696,7 @@ LRESULT CPlayBoardView::DoDragMarker(DragInfo& pdi) int i; for (i = 0; i < dlg.m_nMarkerCount; i++) { - CSize size = pMMgr->GetMarkSize(tblMarks[value_preserving_cast(i)]); + CSize size = pMMgr.GetMarkSize(tblMarks[value_preserving_cast(i)]); sizeMin.cx += size.cx; sizeMin.cy = CB::max(sizeMin.cy, size.cy); if (i < dlg.m_nMarkerCount - 1) @@ -713,7 +713,7 @@ LRESULT CPlayBoardView::DoDragMarker(DragInfo& pdi) // corresponding to left to right. for (i = dlg.m_nMarkerCount - 1; i >= 0; i--) { - CSize size = pMMgr->GetMarkSize(tblMarks[value_preserving_cast(i)]); + CSize size = pMMgr.GetMarkSize(tblMarks[value_preserving_cast(i)]); CDrawObj& pObj = pDoc->CreateMarkerObject(m_pPBoard.get(), tblMarks[value_preserving_cast(i)], CPoint(x - size.cx / 2, y), ObjectID()); x -= size.cx + MARKER_DROP_GAP_X; @@ -726,7 +726,7 @@ LRESULT CPlayBoardView::DoDragMarker(DragInfo& pdi) NASTY_GOTO_TARGET: m_selList.PurgeList(); // If the snap grid is on, adjust the point. - CSize sz = pMMgr->GetMarkSize(mid); + CSize sz = pMMgr.GetMarkSize(mid); ASSERT(sz.cx != 0 && sz.cy != 0); CRect rct(CPoint(pnt.x - sz.cx/2, pnt.y - sz.cy/2), sz); AdjustRect(rct); @@ -737,7 +737,7 @@ LRESULT CPlayBoardView::DoDragMarker(DragInfo& pdi) // If marker is set to prompt for text on drop, show the // dialog. - if (pMMgr->GetMark(mid).m_flags & MarkDef::flagPromptText) + if (pMMgr.GetMark(mid).m_flags & MarkDef::flagPromptText) { CEditElementTextDialog dlg; @@ -993,8 +993,9 @@ void CPlayBoardView::RestoreDrawListDC(CDC& pDC) const #ifdef _DEBUG const CGamDoc* CPlayBoardView::GetDocument() const // non-debug version is inline { - ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CGamDoc))); - return (CGamDoc*)m_pDocument; + const CGamDoc* retval = CB::ToCGamDoc(m_pDocument); + wxASSERT(retval); + return retval; } #endif //_DEBUG @@ -1736,11 +1737,11 @@ void CPlayBoardView::OnActRotate() // ** TEST CODE ** // CGamDoc* pDoc = GetDocument(); m_selList.LoadTableWithPieceIDs(tbl); TileID tid = pDoc->GetPieceTable()->GetActiveTileID(tbl.front()); - CTile tile = pDoc->GetTileManager()->GetTile(tid); + CTile tile = pDoc->GetTileManager().GetTile(tid); OwnerPtr bmap = tile.CreateBitmapOfTile(); CRotateDialog dlg; dlg.m_pBMap = &*bmap; - dlg.m_crTrans = pDoc->GetTileManager()->GetTransparentColor(); + dlg.m_crTrans = pDoc->GetTileManager().GetTransparentColor(); dlg.DoModal(); } @@ -2115,14 +2116,14 @@ void CPlayBoardView::OnUpdateSelectGroupMarkers(CCmdUI* pCmdUI, UINT nID) { if (pCmdUI->m_pSubMenu != NULL) { - CMarkManager* pMgr = GetDocument()->GetMarkManager(); - if (pMgr->IsEmpty()) + CMarkManager& pMgr = GetDocument()->GetMarkManager(); + if (pMgr.IsEmpty()) return; std::vector tbl; - tbl.reserve(pMgr->GetNumMarkSets()); - for (size_t i = size_t(0) ; i < pMgr->GetNumMarkSets() ; ++i) + tbl.reserve(pMgr.GetNumMarkSets()); + for (size_t i = size_t(0) ; i < pMgr.GetNumMarkSets() ; ++i) { - tbl.push_back(pMgr->GetMarkSet(i).GetName()); + tbl.push_back(pMgr.GetMarkSet(i).GetName()); } CMenu menu; VERIFY(menu.CreatePopupMenu()); diff --git a/GP/VwPbrd.h b/GP/VwPbrd.h index 6461cce..51d17c8 100644 --- a/GP/VwPbrd.h +++ b/GP/VwPbrd.h @@ -283,7 +283,7 @@ class CPlayBoardView : public CScrollView #ifndef _DEBUG // debug version in vwmbrd.cpp inline const CGamDoc* CPlayBoardView::GetDocument() const - { return (const CGamDoc*)m_pDocument; } + { return CB::ToCGamDoc(m_pDocument); } #endif ///////////////////////////////////////////////////////////////////////////// diff --git a/GP/VwPbrd1.cpp b/GP/VwPbrd1.cpp index a876749..a235c50 100644 --- a/GP/VwPbrd1.cpp +++ b/GP/VwPbrd1.cpp @@ -377,7 +377,7 @@ void CPlayBoardView::SelectAllMarkers() void CPlayBoardView::SelectMarkersInGroup(size_t nGroup) { CDrawList& pDwg = CheckedDeref(m_pPBoard->GetPieceList()); - CMarkManager& pMgr = CheckedDeref(GetDocument()->GetMarkManager()); + CMarkManager& pMgr = GetDocument()->GetMarkManager(); m_selList.PurgeList(); diff --git a/GP/VwPrjgam.h b/GP/VwPrjgam.h index 3c10f46..ad14805 100644 --- a/GP/VwPrjgam.h +++ b/GP/VwPrjgam.h @@ -68,7 +68,7 @@ class CGamProjView : public CView, private CB::Impl::CGamProjViewBase // Attributes public: - const CGamDoc* GetDocument() const { return (const CGamDoc*)m_pDocument; } + const CGamDoc* GetDocument() const { return CB::ToCGamDoc(m_pDocument); } CGamDoc* GetDocument() { return const_cast(std::as_const(*this).GetDocument()); diff --git a/GP/VwPrjgsn.h b/GP/VwPrjgsn.h index 5ef6a5d..44f7ff5 100644 --- a/GP/VwPrjgsn.h +++ b/GP/VwPrjgsn.h @@ -67,7 +67,7 @@ class CGsnProjView : public CView, private CB::Impl::CGsnProjViewBase // Attributes public: - CGamDoc* GetDocument() { return (CGamDoc*)m_pDocument; } + CGamDoc* GetDocument() { return CB::ToCGamDoc(m_pDocument); } // Various controls... CProjListBox m_listProj; // Main project box diff --git a/GP/VwSelpce.cpp b/GP/VwSelpce.cpp index 249878a..edc71c7 100644 --- a/GP/VwSelpce.cpp +++ b/GP/VwSelpce.cpp @@ -184,8 +184,9 @@ BOOL CSelectedPieceView::OnEraseBkgnd(CDC* pDC) #ifdef _DEBUG CGamDoc* CSelectedPieceView::GetDocument() // non-debug version is inline { - ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CGamDoc))); - return (CGamDoc*)m_pDocument; + CGamDoc* retval = CB::ToCGamDoc(m_pDocument); + wxASSERT(retval); + return retval; } #endif //_DEBUG diff --git a/GP/VwSelpce.h b/GP/VwSelpce.h index 1324875..e4bc742 100644 --- a/GP/VwSelpce.h +++ b/GP/VwSelpce.h @@ -77,6 +77,6 @@ class CSelectedPieceView : public CView #ifndef _DEBUG // debug version in vwselpce.cpp inline CGamDoc* CSelectedPieceView::GetDocument() - { return (CGamDoc*)m_pDocument; } + { return CB::ToCGamDoc(m_pDocument); } #endif diff --git a/GP/VwTbrd.cpp b/GP/VwTbrd.cpp index 421ef39..4cab291 100644 --- a/GP/VwTbrd.cpp +++ b/GP/VwTbrd.cpp @@ -307,8 +307,9 @@ void CTinyBoardView::ClientToWorkspace(CPoint& pnt) #ifdef _DEBUG CGamDoc* CTinyBoardView::GetDocument() // non-debug version is inline { - ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CGamDoc))); - return (CGamDoc*)m_pDocument; + CGamDoc* retval = CB::ToCGamDoc(m_pDocument); + wxASSERT(retval); + return retval; } #endif //_DEBUG diff --git a/GP/VwTbrd.h b/GP/VwTbrd.h index c5cb49d..22ac9a8 100644 --- a/GP/VwTbrd.h +++ b/GP/VwTbrd.h @@ -77,7 +77,7 @@ class CTinyBoardView : public CScrollView #ifndef _DEBUG // debug version in vwmbrd.cpp inline CGamDoc* CTinyBoardView::GetDocument() - { return (CGamDoc*)m_pDocument; } + { return CB::ToCGamDoc(m_pDocument); } #endif diff --git a/GP/WStateGp.h b/GP/WStateGp.h index e1ef246..4268a56 100644 --- a/GP/WStateGp.h +++ b/GP/WStateGp.h @@ -34,7 +34,7 @@ class CGpWinStateMgr : public CWinStateManager public: protected: - CGamDoc* GetDocument() { return (CGamDoc*)m_pDoc; } + CGamDoc* GetDocument() { return CB::ToCGamDoc(m_pDoc); } virtual CWnd* OnGetFrameForWinStateElement(const CWinStateElement& pWse) override; virtual void OnAnnotateWinStateElement(CWinStateElement& pState, CWnd *pWnd) override; diff --git a/GShr/Board.cpp b/GShr/Board.cpp index a01badd..c4fb418 100644 --- a/GShr/Board.cpp +++ b/GShr/Board.cpp @@ -590,8 +590,8 @@ void CBoard::Serialize(CArchive& ar) ar >> wTmp; if (wTmp != 0) { - CGamDoc& doc = CheckedDeref((CGamDoc*)ar.m_pDocument); - m_pBrdAry = new CBoardArray(CheckedDeref(doc.GetTileManager())); + CGamDoc& doc = CheckedDeref(CB::ToCGamDoc(ar.m_pDocument)); + m_pBrdAry = new CBoardArray(doc.GetTileManager()); m_pBrdAry->Serialize(ar); } ar >> wTmp; @@ -723,7 +723,7 @@ void CBoardBase::Serialize(CArchive& ar) } else { - m_pTMgr = ((CGamDoc*)ar.m_pDocument)->GetTileManager(); + m_pTMgr = &CheckedDeref(CB::ToCGamDoc(ar.m_pDocument)).GetTileManager(); m_pBaseDwg = NULL; uint16_t wTmp; uint32_t dwTmp; @@ -801,7 +801,7 @@ CBoardManager::CBoardManager(CGamDoc& doc) SetForeColor(RGB(0, 0, 0)); SetBackColor(RGB(255, 255, 255)); SetLineWidth(3); - m_fontID = CGamDoc::GetFontManager()->AddFont(TenthPointsToScreenPixels(100), + m_fontID = CGamDoc::GetFontManager().AddFont(TenthPointsToScreenPixels(100), taBold, uint8_t(FF_SWISS), "Arial"); // ------ // m_wReserved1 = 0; @@ -885,8 +885,8 @@ void CBoardManager::Serialize(CArchive& ar) ar << (DWORD)m_crBack; ar << (WORD)m_nLineWidth; - CFontTbl* pFontMgr = CGamDoc::GetFontManager(); - pFontMgr->Archive(ar, m_fontID); + CFontTbl& pFontMgr = CGamDoc::GetFontManager(); + pFontMgr.Archive(ar, m_fontID); ar << m_wReserved1; ar << m_wReserved2; @@ -918,8 +918,8 @@ void CBoardManager::Serialize(CArchive& ar) ar >> dwTmp; m_crBack = (COLORREF)dwTmp; ar >> wTmp; m_nLineWidth = (UINT)wTmp; - CFontTbl* pFontMgr = CGamDoc::GetFontManager(); - pFontMgr->Archive(ar, m_fontID); + CFontTbl& pFontMgr = CGamDoc::GetFontManager(); + pFontMgr.Archive(ar, m_fontID); ar >> m_wReserved1; ar >> m_wReserved2; diff --git a/GShr/CyberBoard.h b/GShr/CyberBoard.h index 3fd1e64..348399e 100644 --- a/GShr/CyberBoard.h +++ b/GShr/CyberBoard.h @@ -72,6 +72,7 @@ #include #include #include +#include #include "wx/dcprint.h" #include #include @@ -1904,7 +1905,7 @@ namespace CB public: // avoid multiple wxWindow for single CWnd wxNativeContainerWindowMixin(const wxNativeContainerWindowMixin&) = delete; - wxNativeContainerWindowMixin(CWnd& w) : mfcWnd(w) {} + wxNativeContainerWindowMixin(CWnd& w) : mfcWnd(&w) {} operator const wxNativeContainerWindow*() const; operator wxNativeContainerWindow*() @@ -1922,10 +1923,10 @@ namespace CB } private: - CWnd& mfcWnd; + RefPtr mfcWnd; /* N.B.: wx deletes this when HWND is destroyed, BUT does not tell us! */ - mutable wxNativeContainerWindow* wxWnd = nullptr; + mutable propagate_const wxWnd = nullptr; }; /* if mfcWnd has @@ -1945,6 +1946,69 @@ namespace CB const std::type_info& GetPublicTypeid(const wxWindow& w); } +// helpers for providing wx/docview +namespace CB +{ + // satisfy wxDocChildFrameAny<> requirements + template + class PseudoFrame : public BASE + { + public: + bool Create(wxWindow* parent, + wxWindowID id, + const wxString& title, + const wxPoint& pos = wxDefaultPosition, + const wxSize& size = wxDefaultSize, + long style = wxDEFAULT_FRAME_STYLE, + const wxString& name = wxASCII_STR(wxFrameNameStr)) + { + return true; + } + + // from wxTopLevelWindowBase: + // this should go away, but for now it's called from docview.cpp, + // so should be there for all platforms + void OnActivate(wxActivateEvent& WXUNUSED(event)) { } + }; + + /* wxView must be separate from wxWindow + (see https://groups.google.com/g/wx-dev/c/xMK4zYT3FFQ/m/kR9JmczbBAAJ) */ + class wxView : public ::wxView + { + public: + wxView(wxWindow& v) : + window(&v) + { + } + + ~wxView() + { + // wnd dtor deletes this, so avoid wx trying to delete wnd + SetDocChildFrame(nullptr); + } + + void OnDraw(wxDC* dc) override + { + CPP20_TRACE("{}({})\n", __func__, typeid(*window).name()); + wxASSERT(!"not impl"); + } + + private: + RefPtr window; + }; +} + +// CGamDoc is currently a wxDoc in GM, CDoc in GP, so need workaround +class CGamDoc; +namespace CB +{ + const CGamDoc* ToCGamDoc(const CDocument* p); + inline CGamDoc* ToCGamDoc(CDocument* p) + { + return const_cast(ToCGamDoc(static_cast(p))); + } +} + /* AfxGetApp() docs say it may return NULL during process startup, so declare a function that we will guarantee returns an object during startup */ diff --git a/GShr/DrawObj.cpp b/GShr/DrawObj.cpp index 1768d1a..8d851e8 100644 --- a/GShr/DrawObj.cpp +++ b/GShr/DrawObj.cpp @@ -1316,7 +1316,7 @@ void CBitmapImage::Serialize(CArchive& ar) CDib dib(m_bitmap); #ifndef GPLAY - dib.SetCompressLevel(((CGamDoc*)ar.m_pDocument)->GetCompressLevel()); + dib.SetCompressLevel(CB::ToCGamDoc(ar.m_pDocument)->GetCompressLevel()); #endif ar << dib; } @@ -1448,7 +1448,7 @@ void CTileImage::Serialize(CArchive& ar) } else { - m_pTMgr = ((CGamDoc*)ar.m_pDocument)->GetTileManager(); + m_pTMgr = &CB::ToCGamDoc(ar.m_pDocument)->GetTileManager(); ar >> m_tid; } } @@ -1465,7 +1465,7 @@ void CText::Draw(CDC& pDC, TileScale eScale) if (eScale == smallScale && m_rctExtent.Height() < 16) return; - HFONT hFont = CGamDoc::GetFontManager()->GetFontHandle(m_fontID, m_geoRot); + HFONT hFont = CGamDoc::GetFontManager().GetFontHandle(m_fontID, m_geoRot); CFont* pPrvFont = pDC.SelectObject(CFont::FromHandle(hFont)); pDC.SetBkMode(TRANSPARENT); COLORREF crPrev = pDC.SetTextColor(m_crText); @@ -1501,11 +1501,11 @@ void CText::SetText(int x, int y, const CB::string& pszText, FontID fntID, BOOL CText::SetFont(FontID fid) { - CFontTbl* pFontMgr = CGamDoc::GetFontManager(); + CFontTbl& pFontMgr = CGamDoc::GetFontManager(); m_fontID = fid; - HFONT hFont = pFontMgr->GetFontHandle(m_fontID); + HFONT hFont = pFontMgr.GetFontHandle(m_fontID); CFont* pPrvFont = g_gt.mDC1.SelectObject(CFont::FromHandle(hFont)); // Compute (new) dimensions @@ -1578,8 +1578,6 @@ CDrawObj::OwnerPtr CText::Clone() const void CText::CopyAttributes(const CText& source) { - CFontTbl* pFontMgr = CGamDoc::GetFontManager(); - CDrawObj_SimplRctExtent::CopyAttributes(source); m_nAngle = source.m_nAngle; @@ -1595,7 +1593,7 @@ void CText::CopyAttributes(const CText& source) void CText::Serialize(CArchive& ar) { CDrawObj::Serialize(ar); - CFontTbl* pFontMgr = CGamDoc::GetFontManager(); + CFontTbl& pFontMgr = CGamDoc::GetFontManager(); if (ar.IsStoring()) { if (m_geoRot) @@ -1606,7 +1604,7 @@ void CText::Serialize(CArchive& ar) ar << (WORD)m_nAngle; ar << (DWORD)m_crText; ar << m_text; - pFontMgr->Archive(ar, m_fontID); + pFontMgr.Archive(ar, m_fontID); } else { @@ -1616,7 +1614,7 @@ void CText::Serialize(CArchive& ar) ar >> wTmp; m_nAngle = (int)wTmp; ar >> dwTmp; m_crText = (COLORREF)dwTmp; ar >> m_text; - pFontMgr->Archive(ar, m_fontID); + pFontMgr.Archive(ar, m_fontID); } } @@ -1678,8 +1676,7 @@ void CPieceObj::SetRect(const CRect& rct) void CPieceObj::Draw(CDC& pDC, TileScale eScale) { ASSERT(m_pDoc != NULL); - CTileManager* pTMgr = m_pDoc->GetTileManager(); - ASSERT(pTMgr != NULL); + CTileManager& pTMgr = m_pDoc->GetTileManager(); CPieceTable* pPTbl = m_pDoc->GetPieceTable(); ASSERT(pPTbl != NULL); @@ -1693,13 +1690,13 @@ void CPieceObj::Draw(CDC& pDC, TileScale eScale) ASSERT(tid != nullTid); CPoint pnt = GetRect().TopLeft(); - DrawObjTile(pDC, pnt, pTMgr, tid, eScale); + DrawObjTile(pDC, pnt, &pTMgr, tid, eScale); } void CPieceObj::Draw(wxDC& pDC, TileScale eScale) { wxASSERT(m_pDoc != NULL); - CTileManager& pTMgr = CheckedDeref(m_pDoc->GetTileManager()); + CTileManager& pTMgr = m_pDoc->GetTileManager(); CPieceTable& pPTbl = CheckedDeref(m_pDoc->GetPieceTable()); TileID tid; @@ -1756,8 +1753,7 @@ void CPieceObj::SetPiece(const CRect& rct, PieceID pid) CSize CPieceObj::GetSize() const { ASSERT(m_pDoc != NULL); - CTileManager* pTMgr = m_pDoc->GetTileManager(); - ASSERT(pTMgr != NULL); + CTileManager& pTMgr = m_pDoc->GetTileManager(); CPieceTable* pPTbl = m_pDoc->GetPieceTable(); ASSERT(pPTbl != NULL); @@ -1770,7 +1766,7 @@ CSize CPieceObj::GetSize() const tid = pPTbl->GetActiveTileID(m_pid, TRUE); ASSERT(tid != nullTid); - CTile tile = pTMgr->GetTile(tid); + CTile tile = pTMgr.GetTile(tid); return tile.GetSize(); } @@ -1818,7 +1814,7 @@ void CPieceObj::Serialize(CArchive& ar) } else { - m_pDoc = (CGamDoc*)ar.m_pDocument; + m_pDoc = CB::ToCGamDoc(ar.m_pDocument); ar >> m_pid; } } @@ -1829,19 +1825,18 @@ void CPieceObj::Serialize(CArchive& ar) void CMarkObj::Draw(CDC& pDC, TileScale eScale) { ASSERT(m_pDoc != NULL); - CTileManager* pTMgr = m_pDoc->GetTileManager(); - ASSERT(pTMgr != NULL); + CTileManager& pTMgr = m_pDoc->GetTileManager(); TileID tid = GetCurrentTileID(); CPoint pnt = m_rctExtent.TopLeft(); - DrawObjTile(pDC, pnt, pTMgr, tid, eScale); + DrawObjTile(pDC, pnt, &pTMgr, tid, eScale); } void CMarkObj::Draw(wxDC& pDC, TileScale eScale) { wxASSERT(m_pDoc != NULL); - CTileManager& pTMgr = CheckedDeref(m_pDoc->GetTileManager()); + CTileManager& pTMgr = m_pDoc->GetTileManager(); TileID tid = GetCurrentTileID(); wxPoint pnt = CB::Convert(m_rctExtent).GetTopLeft(); @@ -1858,12 +1853,10 @@ void CMarkObj::SetMark(CRect& rct, MarkID mid) TileID CMarkObj::GetCurrentTileID() { ASSERT(m_pDoc != NULL); - CMarkManager* pMMgr = m_pDoc->GetMarkManager(); - ASSERT(pMMgr != NULL); - CTileManager* pTMgr = m_pDoc->GetTileManager(); - ASSERT(pTMgr != NULL); + CMarkManager& pMMgr = m_pDoc->GetMarkManager(); + CTileManager& pTMgr = m_pDoc->GetTileManager(); - MarkDef& pMark = pMMgr->GetMark(m_mid); + MarkDef& pMark = pMMgr.GetMark(m_mid); ASSERT(pMark.m_tid != nullTid); if (m_nFacingDegCW != 0) @@ -1882,13 +1875,12 @@ TileID CMarkObj::GetCurrentTileID() void CMarkObj::ResyncExtentRect() { - CTileManager* pTMgr = m_pDoc->GetTileManager(); - ASSERT(pTMgr != NULL); + CTileManager& pTMgr = m_pDoc->GetTileManager(); TileID tid = GetCurrentTileID(); ASSERT(tid != nullTid); - CTile tile = pTMgr->GetTile(tid); + CTile tile = pTMgr.GetTile(tid); CPoint pnt = m_rctExtent.CenterPoint(); pnt.x -= tile.GetWidth() / 2; pnt.y -= tile.GetHeight() / 2; @@ -1947,7 +1939,7 @@ void CMarkObj::Serialize(CArchive& ar) } else { - m_pDoc = ((CGamDoc*)ar.m_pDocument); + m_pDoc = CB::ToCGamDoc(ar.m_pDocument); ar >> m_dwObjectID; ar >> m_mid; if (CGamDoc::GetLoadingVersion() >= NumVersion(2, 0)) //Ver2.0 diff --git a/GShr/DrawObj.h b/GShr/DrawObj.h index 856fafa..5b17be0 100644 --- a/GShr/DrawObj.h +++ b/GShr/DrawObj.h @@ -913,7 +913,7 @@ class CTileImage : public CDrawObj_SimplRctExtent // Constructors public: CTileImage() : m_tid(nullTid) { m_pTMgr = NULL; } - CTileImage(CTileManager* pTMgr) : m_tid(nullTid) { m_pTMgr = pTMgr; } + CTileImage(CTileManager& pTMgr) : m_tid(nullTid) { m_pTMgr = &pTMgr; } // Attributes public: TileID m_tid; diff --git a/GShr/Font.cpp b/GShr/Font.cpp index ead511b..758be02 100644 --- a/GShr/Font.cpp +++ b/GShr/Font.cpp @@ -199,7 +199,7 @@ bool CbFont::operator==(const CbFont& rhs) const wxFont ToWxFont(FontID fid) { LOGFONT lf; - CFontTbl& pFontTbl = CheckedDeref(CGamDoc::GetFontManager()); + CFontTbl& pFontTbl = CGamDoc::GetFontManager(); pFontTbl.FillLogFontStruct(fid, &lf); wxNativeFontInfo nfi; @@ -297,6 +297,6 @@ FontID ToFontID(wxFont f) CB::string name = f.GetFaceName(); - CFontTbl& pFontTbl = CheckedDeref(CGamDoc::GetFontManager()); + CFontTbl& pFontTbl = CGamDoc::GetFontManager(); return pFontTbl.AddFont(size, flags, family, name); } diff --git a/GShr/GdiTools.cpp b/GShr/GdiTools.cpp index f8b0633..d8d8228 100644 --- a/GShr/GdiTools.cpp +++ b/GShr/GdiTools.cpp @@ -47,8 +47,8 @@ FontID DoFontDialog(FontID fid, CWnd *pParentWnd, BOOL bScreenOK) ASSERT(fid != 0); LOGFONT lf; - CFontTbl* pFontTbl = CGamDoc::GetFontManager(); - pFontTbl->FillLogFontStruct(fid, &lf); + CFontTbl& pFontTbl = CGamDoc::GetFontManager(); + pFontTbl.FillLogFontStruct(fid, &lf); CFontDialog dlg(&lf, CF_SCREENFONTS | (bScreenOK ? 0 : CF_SCALABLEONLY) | CF_NOVECTORFONTS, @@ -56,7 +56,7 @@ FontID DoFontDialog(FontID fid, CWnd *pParentWnd, BOOL bScreenOK) if (dlg.DoModal() != IDOK) return (FontID)0; - return pFontTbl->AddFont(TenthPointsToScreenPixels(dlg.GetSize()), + return pFontTbl.AddFont(TenthPointsToScreenPixels(dlg.GetSize()), (dlg.IsBold()?taBold:0)|(dlg.IsItalic()?taItalic:0), static_cast(lf.lfPitchAndFamily & 0xF0), dlg.GetFaceName()); } diff --git a/GShr/LBoxMark.cpp b/GShr/LBoxMark.cpp index 3ce5f16..30b9b61 100644 --- a/GShr/LBoxMark.cpp +++ b/GShr/LBoxMark.cpp @@ -67,7 +67,7 @@ CMarkListBox::CMarkListBox() const CTileManager& CMarkListBox::GetTileManager() const { ASSERT(m_pDoc != NULL); - return CheckedDeref(m_pDoc->GetTileManager()); + return m_pDoc->GetTileManager(); } ///////////////////////////////////////////////////////////////////////////// @@ -91,10 +91,10 @@ GameElement CMarkListBox::OnGetHitItemCodeAtPoint(CPoint point, CRect& rct) cons if (nIndex >= 65535 || GetCount() <= 0) return Invalid_v; - CMarkManager* pMMgr = m_pDoc->GetMarkManager(); + CMarkManager& pMMgr = m_pDoc->GetMarkManager(); MarkID mid = MapIndexToItem(value_preserving_cast(nIndex)); - MarkDef& pMark = pMMgr->GetMark(mid); + MarkDef& pMark = pMMgr.GetMark(mid); std::vector tids; tids.push_back(pMark.m_tid); @@ -172,9 +172,8 @@ CSize CMarkListBox::OnItemSize(size_t nIndex) const { if (m_eTrayViz == mtrayVizNormal) { - CMarkManager* pMMgr = m_pDoc->GetMarkManager(); - ASSERT(pMMgr); - MarkDef& pMark = pMMgr->GetMark(MapIndexToItem(nIndex)); + CMarkManager& pMMgr = m_pDoc->GetMarkManager(); + MarkDef& pMark = pMMgr.GetMark(MapIndexToItem(nIndex)); ASSERT(pMark.m_tid != nullTid); std::vector tids; @@ -209,13 +208,9 @@ void CMarkListBox::OnItemDraw(CDC& pDC, size_t nIndex, UINT nAction, UINT nState if (m_pDoc == NULL) return; - CMarkManager* pMMgr = m_pDoc->GetMarkManager(); - if (pMMgr == NULL) - { - return; - } + CMarkManager& pMMgr = m_pDoc->GetMarkManager(); - MarkDef& pMark = pMMgr->GetMark(MapIndexToItem(nIndex)); + MarkDef& pMark = pMMgr.GetMark(MapIndexToItem(nIndex)); ASSERT(pMark.m_tid != nullTid); std::vector tids; @@ -273,7 +268,7 @@ CMarkListBoxWx::CMarkListBoxWx() const CTileManager& CMarkListBoxWx::GetTileManager() const { ASSERT(m_pDoc != NULL); - return CheckedDeref(m_pDoc->GetTileManager()); + return m_pDoc->GetTileManager(); } ///////////////////////////////////////////////////////////////////////////// @@ -298,10 +293,10 @@ GameElement CMarkListBoxWx::OnGetHitItemCodeAtPoint(wxPoint point, wxRect& rct) return Invalid_v; } - CMarkManager* pMMgr = m_pDoc->GetMarkManager(); + CMarkManager& pMMgr = m_pDoc->GetMarkManager(); MarkID mid = MapIndexToItem(value_preserving_cast(nIndex)); - MarkDef& pMark = pMMgr->GetMark(mid); + MarkDef& pMark = pMMgr.GetMark(mid); std::vector tids; tids.push_back(pMark.m_tid); @@ -381,9 +376,8 @@ wxSize CMarkListBoxWx::GetItemSize(size_t nIndex) const { if (m_eTrayViz == mtrayVizNormal) { - CMarkManager* pMMgr = m_pDoc->GetMarkManager(); - wxASSERT(pMMgr); - MarkDef& pMark = pMMgr->GetMark(MapIndexToItem(nIndex)); + CMarkManager& pMMgr = m_pDoc->GetMarkManager(); + MarkDef& pMark = pMMgr.GetMark(MapIndexToItem(nIndex)); ASSERT(pMark.m_tid != nullTid); std::vector tids; @@ -410,13 +404,9 @@ void CMarkListBoxWx::OnDrawItem(wxDC& pDC, const wxRect& rctItem, size_t nIndex) if (m_pDoc == NULL) return; - CMarkManager* pMMgr = m_pDoc->GetMarkManager(); - if (pMMgr == NULL) - { - return; - } + CMarkManager& pMMgr = m_pDoc->GetMarkManager(); - MarkDef& pMark = pMMgr->GetMark(MapIndexToItem(nIndex)); + MarkDef& pMark = pMMgr.GetMark(MapIndexToItem(nIndex)); ASSERT(pMark.m_tid != nullTid); std::vector tids; diff --git a/GShr/LBoxPiec.cpp b/GShr/LBoxPiec.cpp index a5b80e7..1d75949 100644 --- a/GShr/LBoxPiec.cpp +++ b/GShr/LBoxPiec.cpp @@ -68,13 +68,13 @@ void CPieceListBox::SetDocument(CGamDoc& pDoc) CGrafixListBoxData::SetDocument(pDoc); ResetContent(); m_pDoc = &pDoc; - m_pPMgr = pDoc.GetPieceManager(); + m_pPMgr = &pDoc.GetPieceManager(); } const CTileManager& CPieceListBox::GetTileManager() const { ASSERT(m_pDoc != NULL); - return CheckedDeref(m_pDoc->GetTileManager()); + return m_pDoc->GetTileManager(); } ///////////////////////////////////////////////////////////////////////////// @@ -221,13 +221,13 @@ void CPieceListBoxWx::SetDocument(CGamDoc& pDoc) CGrafixListBoxDataWx::SetDocument(pDoc); Clear(); m_pDoc = &pDoc; - m_pPMgr = pDoc.GetPieceManager(); + m_pPMgr = &pDoc.GetPieceManager(); } const CTileManager& CPieceListBoxWx::GetTileManager() const { wxASSERT(m_pDoc != NULL); - return CheckedDeref(m_pDoc->GetTileManager()); + return m_pDoc->GetTileManager(); } ///////////////////////////////////////////////////////////////////////////// diff --git a/GShr/LibMfc.cpp b/GShr/LibMfc.cpp index 91baf42..84a98cb 100644 --- a/GShr/LibMfc.cpp +++ b/GShr/LibMfc.cpp @@ -773,9 +773,9 @@ void CB::string::Serialize(CArchive& ar) #endif } -CB::wxNativeContainerWindowMixin::operator const wxNativeContainerWindow* () const +CB::wxNativeContainerWindowMixin::operator const wxNativeContainerWindow*() const { - if (!mfcWnd.m_hWnd) + if (!mfcWnd->m_hWnd) { /* N.B.: wx deletes this when HWND is destroyed, BUT does not tell us! */ @@ -784,9 +784,53 @@ CB::wxNativeContainerWindowMixin::operator const wxNativeContainerWindow* () con } else if (!wxWnd) { - wxWnd = new wxNativeContainerWindow(mfcWnd.m_hWnd); + wxWnd = new wxNativeContainerWindow(mfcWnd->m_hWnd); + + // N.B.: this is a dirty hack + wxNativeContainerWindowMixin* ncThis = const_cast(this); + wxWindow& rThis = const_cast(*ncThis); + + // fill in wx children list + for (CWnd* mfcChild = mfcWnd->GetWindow(GW_CHILD) ; + mfcChild ; + mfcChild = mfcChild->GetWindow(GW_HWNDNEXT)) + { + wxWindow* wxChild = CB::GetWxWindow(*mfcChild); + if (wxChild) + { + rThis.AddChild(wxChild); + wxASSERT(wxChild->GetParent() == &rThis); + } + } + + /* in some cases, wx Layout() won't do anything, + so we may need to resize child ourselves */ + rThis.Bind(wxEVT_SIZE, + [ncThis](wxSizeEvent& event) + { + if (!ncThis->mfcWnd->IsKindOf(RUNTIME_CLASS(CMDIFrameWndExCb))) + { + wxWindowList& children = ncThis->wxWnd->GetChildren(); + if (children.size() == size_t(1) && + children.front()->IsTopLevel()) + { + wxSize size = ncThis->wxWnd->GetClientSize(); + wxWindow& child = CheckedDeref(children.front()); + child.SetSize(0, 0, size.x, size.y); + } + } + else + { + /* wx args don't match WM_SIZE, but it looks + like specific args aren't critical */ + CMDIFrameWndExCb& mfcMdiWnd = static_cast(*ncThis->mfcWnd); + mfcMdiWnd.OnSize(0, 0, 0); + } + event.Skip(); + } + ); } - return wxWnd; + return &*wxWnd; } /* if mfcWnd has @@ -1160,6 +1204,8 @@ namespace CB #else switch (id) { + case ID_BUGFIX_DUMPBADTILES: + return XRCID("ID_BUGFIX_DUMPBADTILES"); case ID_COLOR_FOREGROUND: return XRCID("ID_COLOR_FOREGROUND"); case ID_COLOR_BACKGROUND: @@ -1168,6 +1214,8 @@ namespace CB return XRCID("ID_COLOR_TRANSPARENT"); case ID_COLOR_CUSTOM: return XRCID("ID_COLOR_CUSTOM"); + case ID_DUMP_TILEDATA: + return XRCID("ID_DUMP_TILEDATA"); case ID_DWG_DRAWABOVEGRID: return XRCID("ID_DWG_DRAWABOVEGRID"); case ID_DWG_FONT: @@ -1176,6 +1224,16 @@ namespace CB return XRCID("ID_DWG_TOBACK"); case ID_DWG_TOFRONT: return XRCID("ID_DWG_TOFRONT"); + case ID_EDIT_CREATEBOARD: + return XRCID("ID_EDIT_CREATEBOARD"); + case ID_EDIT_CREATEMARKGROUP: + return XRCID("ID_EDIT_CREATEMARKGROUP"); + case ID_EDIT_CREATEPIECEGROUP: + return XRCID("ID_EDIT_CREATEPIECEGROUP"); + case ID_EDIT_CREATETILEGROUP: + return XRCID("ID_EDIT_CREATETILEGROUP"); + case ID_EDIT_GBOXPROPERTIES: + return XRCID("ID_EDIT_GBOXPROPERTIES"); case ID_EDIT_LAYER_BASE: return XRCID("ID_EDIT_LAYER_BASE"); case ID_EDIT_LAYER_TILE: @@ -1186,6 +1244,8 @@ namespace CB return XRCID("ID_EDIT_MOVE"); case ID_EDIT_PASTEBITMAPFROMFILE: return XRCID("ID_EDIT_PASTEBITMAPFROMFILE"); + case ID_EXPORT_GAMEBOX: + return XRCID("ID_EXPORT_GAMEBOX"); case ID_IMAGE_BOARDMASK: return XRCID("ID_IMAGE_BOARDMASK"); case ID_IMAGE_GRIDLINES: @@ -1218,10 +1278,14 @@ namespace CB return XRCID("ID_ITOOL_COLORCHANGE"); case ID_LINE_WIDTH: return XRCID("ID_LINE_WIDTH"); - case ID_PROJECT_SAVETILEFILE: - return XRCID("ID_PROJECT_SAVETILEFILE"); + case ID_PROJECT_CHGID: + return XRCID("ID_PROJECT_CHGID"); case ID_PROJECT_LOADTILEFILE: return XRCID("ID_PROJECT_LOADTILEFILE"); + case ID_PROJECT_SAVETILEFILE: + return XRCID("ID_PROJECT_SAVETILEFILE"); + case ID_STICKY_DRAWTOOLS: + return XRCID("ID_STICKY_DRAWTOOLS"); case ID_TOOL_ARROW: return XRCID("ID_TOOL_ARROW"); case ID_TOOL_DROPPER: diff --git a/GShr/LibMfc.h b/GShr/LibMfc.h index 9e3594f..b99795b 100644 --- a/GShr/LibMfc.h +++ b/GShr/LibMfc.h @@ -59,6 +59,9 @@ class CMDIFrameWndExCb : public CMDIFrameWndEx { DECLARE_DYNAMIC(CMDIFrameWndExCb) +public: + using CMDIFrameWndExCb::OnSize; + protected: CMDIFrameWndExCb(); diff --git a/GShr/Marks.cpp b/GShr/Marks.cpp index 1df0548..51111ab 100644 --- a/GShr/Marks.cpp +++ b/GShr/Marks.cpp @@ -64,7 +64,7 @@ void CMarkManager::Clear() /////////////////////////////////////////////////////////////////////// -MarkDef& CMarkManager::GetMark(MarkID mid) +const MarkDef& CMarkManager::GetMark(MarkID mid) const { ASSERT(m_pMarkTbl != NULL); ASSERT(m_pMarkTbl.Valid(mid)); @@ -82,11 +82,11 @@ CSize CMarkManager::GetMarkSize(MarkID mid) /////////////////////////////////////////////////////////////////////// -BOOL CMarkManager::IsTileInUse(TileID tid) +BOOL CMarkManager::IsTileInUse(TileID tid) const { for (size_t i = 0; i < m_pMarkTbl.GetSize(); i++) { - MarkDef& pDef = GetMark(static_cast(i)); + const MarkDef& pDef = GetMark(static_cast(i)); if (pDef.m_tid == tid) return TRUE; } diff --git a/GShr/Marks.h b/GShr/Marks.h index ada024a..aa5ea38 100644 --- a/GShr/Marks.h +++ b/GShr/Marks.h @@ -156,7 +156,11 @@ class CMarkManager // Operations public: - MarkDef& GetMark(MarkID mid); + const MarkDef& GetMark(MarkID mid) const; + MarkDef& GetMark(MarkID mid) + { + return const_cast(std::as_const(*this).GetMark(mid)); + } BOOL IsMarkIDValid(MarkID mid) const; MarkID CreateMark(size_t nMSet, TileID tid, WORD wFlags = 0); void DeleteMark(MarkID mid, CGameElementStringMap* pMapString = NULL, @@ -166,7 +170,7 @@ class CMarkManager size_t FindMarkInMarkSet(MarkID mid) const; // ------- // BOOL PurgeMissingTileIDs(CGameElementStringMap* pMapString = NULL); - BOOL IsTileInUse(TileID tid); + BOOL IsTileInUse(TileID tid) const; // ------- // CSize GetMarkSize(MarkID mid); // ------- // diff --git a/GShr/TileMgr.cpp b/GShr/TileMgr.cpp index 266f173..90ed95c 100644 --- a/GShr/TileMgr.cpp +++ b/GShr/TileMgr.cpp @@ -1,6 +1,6 @@ // TileMgr.cpp // -// Copyright (c) 1994-2023 By Dale L. Larson & William Su, All Rights Reserved. +// Copyright (c) 1994-2024 By Dale L. Larson & William Su, All Rights Reserved. // // Permission is hereby granted, free of charge, to any person obtaining // a copy of this software and associated documentation files (the @@ -55,7 +55,7 @@ CTileManager::CTileManager() SetForeColor(RGB(0, 0, 0)); SetBackColor(RGB(255, 255, 255)); SetLineWidth(1); - m_fontID = CGamDoc::GetFontManager()->AddFont(TenthPointsToScreenPixels(80), + m_fontID = CGamDoc::GetFontManager().AddFont(TenthPointsToScreenPixels(80), 0, uint8_t(FF_SWISS), "Arial"); // --------- // m_wReserved1 = 0; @@ -426,8 +426,8 @@ void CTileManager::Serialize(CArchive& ar) ar << (DWORD)m_crFore; ar << (DWORD)m_crBack; ar << (WORD)m_nLineWidth; - CFontTbl* pFontMgr = CGamDoc::GetFontManager(); - pFontMgr->Archive(ar, m_fontID); + CFontTbl& pFontMgr = CGamDoc::GetFontManager(); + pFontMgr.Archive(ar, m_fontID); ar << m_wReserved1; ar << m_wReserved2; @@ -453,8 +453,8 @@ void CTileManager::Serialize(CArchive& ar) reference */ FontID tempRef = std::move(m_fontID); - CFontTbl* pFontMgr = CGamDoc::GetFontManager(); - pFontMgr->Archive(ar, m_fontID); + CFontTbl& pFontMgr = CGamDoc::GetFontManager(); + pFontMgr.Archive(ar, m_fontID); ar >> m_wReserved1; ar >> m_wReserved2; diff --git a/GShr/TileSht.cpp b/GShr/TileSht.cpp index c4808fb..f5bc4d2 100644 --- a/GShr/TileSht.cpp +++ b/GShr/TileSht.cpp @@ -68,7 +68,7 @@ void CTileSheet::Serialize(CArchive& ar) { ar << (WORD)1; // Store "HasBitmap" flag #ifndef GPLAY - dib.SetCompressLevel(((CGamDoc*)ar.m_pDocument)-> + dib.SetCompressLevel(CB::ToCGamDoc(ar.m_pDocument)-> GetCompressLevel()); #endif ar << dib;