#include "StdAfx.h" #include "../T2.h" #include "T2DLL.h" #include "T2ImageObj.h" #include "../T2MainWindow.h" #include "T2TemplatePluginList.h" #include "T2ToolDef.h" #include "T2ToolWindow.h" #include "../T2TowerDoc.h" #include "T2WorldDef.h" #ifdef _DEBUG #define new DEBUG_NEW #undef THIS_FILE static char THIS_FILE[] = __FILE__; #endif #line 16 IMPLEMENT_DYNCREATE(T2ToolWindow, CFrameWnd); T2ToolWindow::T2ToolWindow() { #line 20 mToolIconList = new T2ToolIconList; mDocument = NULL; mWorldDef = NULL; mSel = -1; mListCtrl = NULL; mTimerID = 0; for (int i = 0; i < 16; i++) _D8[i] = NULL; _118 = 1; } /*virtual*/ T2ToolWindow::~T2ToolWindow() { delete mToolIconList; } /*virtual*/ void T2ToolWindow::SetDocument(T2TowerDoc* inDoc) { mDocument = inDoc; mWorldDef = inDoc->mWorldDef; } BEGIN_MESSAGE_MAP(T2ToolWindow, CFrameWnd) ON_WM_QUERYNEWPALETTE() ON_WM_ERASEBKGND() ON_WM_CREATE() ON_WM_LBUTTONDOWN() ON_WM_LBUTTONUP() ON_WM_MOUSEMOVE() ON_WM_LBUTTONDBLCLK() ON_WM_TIMER() ON_WM_SIZE() ON_WM_DESTROY() ON_WM_CLOSE() END_MESSAGE_MAP() afx_msg BOOL T2ToolWindow::OnQueryNewPalette() { if (!mDocument || !mDocument->mWorldDef) return CFrameWnd::OnQueryNewPalette(); CDC *pDC = GetDC(); pDC->SaveDC(); pDC->SelectPalette(mDocument->mWorldDef->GetPalette(), false); pDC->RealizePalette(); pDC->RestoreDC(-1); ReleaseDC(pDC); return true; } afx_msg int T2ToolWindow::OnCreate(LPCREATESTRUCT lpCreateStruct) { if (CFrameWnd::OnCreate(lpCreateStruct) == -1) return -1; return OnCreateProc(lpCreateStruct); } /*virtual*/ int T2ToolWindow::GetSel() { return mSel; } /*virtual*/ void T2ToolWindow::SetSel(int inID) { if (SearchID(inID)) SelChange(inID); } /*virtual*/ CString* T2ToolWindow::GetIconName(int inID) { static CString defaultName = ""; POSITION pos = SearchID(inID); if (!pos) return &defaultName; return &mToolIconList->GetAt(pos)->mName; } /*virtual*/ T2TemplatePlugin* T2ToolWindow::GetIconPlugin(int inID) { POSITION pos = SearchID(inID); if (!pos) return NULL; return mToolIconList->GetAt(pos)->mPlugin; } /*virtual*/ DWORD T2ToolWindow::GetIconOption(int inID) { POSITION pos = SearchID(inID); if (!pos) return 0; return mToolIconList->GetAt(pos)->mOption; } /*virtual*/ unsigned int T2ToolWindow::GetIconValiation(int inID) { POSITION pos = SearchID(inID); if (!pos) return 0; return mToolIconList->GetAt(pos)->mValiation; } /*virtual*/ void T2ToolWindow::AddIcon(const char* inName, char* inStr2, unsigned int inValiation, DWORD inOption, T2ToolDef* inToolDef, int inFld18, unsigned short inSomeMask, T2ToolCallback* inToolCallback) { T2ToolIconItem *theToolIconItem; POSITION position = mToolIconList->GetHeadPosition(); while (position) { theToolIconItem = mToolIconList->GetNext(position); if (theToolIconItem->mName == inName && theToolIconItem->mValiation == inValiation) return; } #line 145 T2ToolIconItem *theItem = new T2ToolIconItem; theItem->mID = AssignNewID(); theItem->mName = inName; theItem->mValiation = inValiation; theItem->mOption = inOption; theItem->m18 = inFld18; theItem->m1C = inSomeMask; theItem->mToolCallback = inToolCallback; theItem->mToolDef = inToolDef; unsigned short mask = 1; if (mDocument->mViewMode == kOutView) mask = 2; if (inSomeMask & mask) theItem->m30 = 1; else theItem->m30 = 0; if (inStr2) theItem->m2C = inStr2; if (RefreshItem(theItem)) { mToolIconList->AddTail(theItem); ListUpdated(); } } /*virtual*/ void T2ToolWindow::AddIcon(const char* inName, unsigned short inSomeMask, char* inStr2, T2ToolCallback* inToolCallback) { AddIcon(inName, inStr2, 0, kToolOption0, NULL, 0, inSomeMask, inToolCallback); } /*virtual*/ void T2ToolWindow::RemoveIcon(const char* inName, unsigned int inValiation) { T2ToolIconItem *theToolIconItem; POSITION prevPos; POSITION pos = mToolIconList->GetHeadPosition(); while (pos) { prevPos = pos; theToolIconItem = mToolIconList->GetNext(pos); if (theToolIconItem->mName == inName && theToolIconItem->mValiation == inValiation) { RemoveItem(prevPos); mToolIconList->RemoveAt(prevPos); delete theToolIconItem; ListUpdated(); break; } } } /*virtual*/ void T2ToolWindow::RemoveAll() { delete mToolIconList; #line 204 mToolIconList = new T2ToolIconList; ListUpdated(); SelChange(1); } /*virtual*/ int T2ToolWindow::GetID(const char* inName, unsigned int inValiation) { T2ToolIconItem *theToolIconItem; POSITION pos = mToolIconList->GetHeadPosition(); while (pos) { theToolIconItem = mToolIconList->GetNext(pos); if (theToolIconItem->mName == inName && theToolIconItem->mValiation == inValiation) return theToolIconItem->mID; } return -1; } /*virtual*/ T2ToolIconItem* T2ToolWindow::GetItem(const char* inName, unsigned int inValiation) { T2ToolIconItem *theToolIconItem; POSITION pos = mToolIconList->GetHeadPosition(); while (pos) { theToolIconItem = mToolIconList->GetNext(pos); if (theToolIconItem->mName == inName && theToolIconItem->mValiation == inValiation) return theToolIconItem; } return NULL; } /*virtual*/ T2ToolIconItem* T2ToolWindow::GetItem(int inID) { T2ToolIconItem *theToolIconItem; POSITION pos = mToolIconList->GetHeadPosition(); while (pos) { theToolIconItem = mToolIconList->GetNext(pos); if (theToolIconItem->mID == inID) return theToolIconItem; } return NULL; } /*virtual*/ void T2ToolWindow::Refresh() { POSITION pos = mToolIconList->GetHeadPosition(); while (pos) { while (pos) { T2ToolIconItem *theToolIconItem = mToolIconList->GetNext(pos); if (!RefreshItem(theToolIconItem)) { pos = mToolIconList->GetHeadPosition(); break; } } } Updated(); } /*virtual*/ BOOL T2ToolWindow::RefreshItem(T2ToolIconItem* inItem) { #line 269 _ASSERT(mWorldDef != NULL); _ASSERT(mDocument != NULL); inItem->mPlugin = NULL; if (mDocument->mTenantTemplates) inItem->mPlugin = SearchPlugin(mDocument->mTenantTemplates, inItem->mName); if (!inItem->mPlugin && mDocument->mMoverTemplates) inItem->mPlugin = SearchPlugin(mDocument->mMoverTemplates, inItem->mName); if (!inItem->mPlugin && mDocument->mOuterObjTemplates) inItem->mPlugin = SearchPlugin(mDocument->mOuterObjTemplates, inItem->mName); if (!inItem->mPlugin && mWorldDef->m1D0->FindObject(inItem->mName) != -1) inItem->mPlugin = mWorldDef; if (!inItem->mPlugin) { POSITION pos = mToolIconList->Find(inItem); if (pos) { RemoveItem(pos); mToolIconList->RemoveAt(pos); } delete inItem; return false; } return true; } /*virtual*/ T2TemplatePlugin* T2ToolWindow::SearchPlugin(T2TemplatePluginList* inList, CString& inName) { LArrayIterator iterator(*inList); T2TemplatePlugin *thePlugin; while (iterator.Next(&thePlugin)) { if (thePlugin->mStr48 == inName) return thePlugin; } return NULL; } /*virtual*/ POSITION T2ToolWindow::SearchID(int inID) { T2ToolIconItem *theToolIconItem; POSITION prevPos; POSITION pos = mToolIconList->GetHeadPosition(); while (pos) { prevPos = pos; theToolIconItem = mToolIconList->GetNext(pos); if (theToolIconItem->mID == inID) return prevPos; } return NULL; } /*virtual*/ int T2ToolWindow::AssignNewID() { for (int id = 0; id < 10000; id++) { if (!SearchID(id)) return id; } return -1; } /*virtual*/ void T2ToolWindow::RemoveItem(POSITION inPos) { #line 334 _ASSERT(inPos != NULL); T2ToolIconItem *theToolIconItem = mToolIconList->GetAt(inPos); if (theToolIconItem->mID == mSel) { theToolIconItem = mToolIconList->GetAt(mToolIconList->GetHeadPosition()); ListUpdated(); SelChange(theToolIconItem->mID); } } /*virtual*/ void T2ToolWindow::SelChange(int inID) { mSel = inID; Updated(); } /*virtual*/ BOOL T2ToolWindow::EnableIcon(const char* inName, unsigned int inValiation, BOOL inFlag) { T2ToolIconItem *theToolIconItem; POSITION pos = mToolIconList->GetHeadPosition(); while (pos) { theToolIconItem = mToolIconList->GetNext(pos); if (theToolIconItem->mName == inName && theToolIconItem->mValiation == inValiation) { if (inFlag) theToolIconItem->mEnableCount--; else theToolIconItem->mEnableCount++; RedrawButton(); return true; } } return false; } /*virtual*/ void T2ToolWindow::EnableIcon(BOOL inFlag) { T2ToolIconItem *theToolIconItem; POSITION pos = mToolIconList->GetHeadPosition(); while (pos) { theToolIconItem = mToolIconList->GetNext(pos); if (inFlag) { if (theToolIconItem->mEnableCount) theToolIconItem->mEnableCount--; } else { theToolIconItem->mEnableCount++; } } RedrawButton(); } /*virtual*/ T2ToolIconItem* T2ToolWindow::EnableIcon(unsigned short inMask) { T2ToolIconItem *theToolIconItem; T2ToolIconItem *oldSelectedItem = NULL; T2ToolIconItem *selectedItem = NULL; POSITION pos = mToolIconList->GetHeadPosition(); while (pos) { theToolIconItem = mToolIconList->GetNext(pos); unsigned int flag = 0; if (theToolIconItem->m1C & inMask) flag = 1; theToolIconItem->m30 = flag; if (theToolIconItem->m24) { if (theToolIconItem->mOption == kToolOption4 || theToolIconItem->mOption == kToolOption0) { _D8[_118] = theToolIconItem; if (!flag) oldSelectedItem = theToolIconItem; } } } for (unsigned short what = 1; what < 16; what++) { if ((what & inMask) && _D8[what]) { theToolIconItem = _D8[what]; if (theToolIconItem->mOption == kToolOption4 || theToolIconItem->mOption == kToolOption0) { if (theToolIconItem->m30 && !theToolIconItem->m18) { theToolIconItem->m24 = true; selectedItem = theToolIconItem; if (oldSelectedItem) { oldSelectedItem->m24 = false; oldSelectedItem = NULL; } } } } } if (oldSelectedItem && oldSelectedItem->mOption == kToolOption4) { pos = mToolIconList->GetHeadPosition(); while (pos) { theToolIconItem = mToolIconList->GetNext(pos); if (theToolIconItem->m30 && theToolIconItem->mOption == kToolOption4 && !theToolIconItem->m18) { theToolIconItem->m24 = true; selectedItem = theToolIconItem; oldSelectedItem->m24 = false; oldSelectedItem = NULL; break; } } } if (oldSelectedItem) { pos = mToolIconList->GetHeadPosition(); while (pos) { theToolIconItem = mToolIconList->GetNext(pos); if (theToolIconItem->m30 && theToolIconItem->mOption == kToolOption0) { theToolIconItem->m24 = true; selectedItem = theToolIconItem; oldSelectedItem->m24 = false; oldSelectedItem = NULL; break; } } } if (selectedItem) SelChange(selectedItem->mID); RedrawButton(); Updated(); _118 = inMask & 0xF; return selectedItem; } /*virtual*/ void T2ToolWindow::RedrawButton() { } /*virtual*/ void T2ToolWindow::Updated() { } /*virtual*/ void T2ToolWindow::ListUpdated() { if (mListCtrl) { mListCtrl->DeleteAllItems(); POSITION pos = mToolIconList->GetHeadPosition(); T2ToolIconItem *theToolIconItem; int row = 0; CString text; while (pos) { theToolIconItem = mToolIconList->GetNext(pos); mListCtrl->InsertItem(row, theToolIconItem->mName); text.Format("%d", theToolIconItem->mValiation); mListCtrl->SetItemText(row, 1, text); text.Format("%d", theToolIconItem->mID); mListCtrl->SetItemText(row, 2, text); mListCtrl->SetItemText(row, 3, theToolIconItem->mPlugin->mStr48); mListCtrl->SetItemData(row, (DWORD) theToolIconItem->mID); row++; } } } void T2ToolWindow::StartTimer(UINT inDelay) { if (mTimerID) KillTimer(mTimerID); mTimerID = SetTimer(1, inDelay, NULL); } void T2ToolWindow::StopTimer() { if (mTimerID) KillTimer(mTimerID); mTimerID = 0; } afx_msg BOOL T2ToolWindow::OnEraseBkgnd(CDC* pDC) { return OnEraseBkgndProc(pDC); } afx_msg void T2ToolWindow::OnLButtonDown(UINT nFlags, CPoint point) { OnLButtonDownProc(nFlags, point); } afx_msg void T2ToolWindow::OnLButtonUp(UINT nFlags, CPoint point) { OnLButtonUpProc(nFlags, point); } afx_msg void T2ToolWindow::OnMouseMove(UINT nFlags, CPoint point) { CWinApp *theApp = AfxGetApp(); HCURSOR cursor = theApp->LoadStandardCursor(IDC_ARROW); if (cursor) SetCursor(cursor); OnMouseMoveProc(nFlags, point); } afx_msg void T2ToolWindow::OnLButtonDblClk(UINT nFlags, CPoint point) { OnLButtonDblClkProc(nFlags, point); } afx_msg void T2ToolWindow::OnTimer(UINT nIDEvent) { if (nIDEvent == 1) OnTimerProc(nIDEvent); CWnd::OnTimer(nIDEvent); } afx_msg void T2ToolWindow::OnSize(UINT nType, int cx, int cy) { OnSizeProc(nType, cx, cy); ListUpdated(); } afx_msg void T2ToolWindow::OnDestroy() { StopTimer(); if (mListCtrl) { mListCtrl->DestroyWindow(); delete mListCtrl; } if (gT2App->mMainWindow) gT2App->mMainWindow->mToolWindow = NULL; CFrameWnd::OnDestroy(); } /*virtual*/ int T2ToolWindow::OnCreateProc(LPCREATESTRUCT lpCreateStruct) { CRect listArea; listArea.SetRect(0, 0, 300, 400); CRect windowArea, clientArea; GetWindowRect(windowArea); GetClientRect(clientArea); SetWindowPos( NULL, 0, 100, listArea.Width() + windowArea.Width() - clientArea.Width(), listArea.Height() + windowArea.Height() - clientArea.Height(), SWP_NOZORDER ); #line 615 mListCtrl = new CListCtrl; mListCtrl->Create( LVS_REPORT | LVS_SINGLESEL | WS_VSCROLL | WS_VISIBLE | WS_CHILD, listArea, this, 100 ); mListCtrl->InsertColumn(0, "Name", LVCFMT_LEFT, 100); mListCtrl->InsertColumn(1, "Val", LVCFMT_LEFT, 40); mListCtrl->InsertColumn(2, "ID", LVCFMT_LEFT, 40); mListCtrl->InsertColumn(3, "Plugin", LVCFMT_LEFT, 120); Updated(); return 0; } /*virtual*/ BOOL T2ToolWindow::OnEraseBkgndProc(CDC* pDC) { return CFrameWnd::OnEraseBkgnd(pDC); } /*virtual*/ void T2ToolWindow::OnLButtonDownProc(UINT nFlags, CPoint point) { CWnd::OnLButtonDown(nFlags, point); } /*virtual*/ void T2ToolWindow::OnLButtonUpProc(UINT nFlags, CPoint point) { CWnd::OnLButtonUp(nFlags, point); } /*virtual*/ void T2ToolWindow::OnMouseMoveProc(UINT nFlags, CPoint point) { CWnd::OnMouseMove(nFlags, point); } /*virtual*/ void T2ToolWindow::OnLButtonDblClkProc(UINT nFlags, CPoint point) { CWnd::OnLButtonDblClk(nFlags, point); } /*virtual*/ void T2ToolWindow::OnTimerProc(UINT nIDEvent) { } /*virtual*/ void T2ToolWindow::OnSizeProc(UINT nType, int cx, int cy) { } afx_msg void T2ToolWindow::OnClose() { if (!mDocument) return; mDocument->towerDoc_vf198(kToolWindow); } /*virtual*/ BOOL T2ToolWindow::OnNotify(WPARAM wParam, LPARAM lParam, LRESULT* pResult) { if (wParam == 100 && ((LPNMHDR) lParam)->code == LVN_ITEMCHANGED && mListCtrl->GetSelectedCount() == 1) { int row, count; count = mListCtrl->GetItemCount(); for (row = 0; row < count; row++) { if (mListCtrl->GetItemState(row, LVIS_SELECTED)) break; } SelChange(row); } return CWnd::OnNotify(wParam, lParam, pResult); } T2ToolIconItem::T2ToolIconItem() { mPlugin = NULL; mName = ""; mValiation = 0; mOption = kToolOption0; mID = -1; m24 = false; mEnableCount = 0; m30 = 1; } /*virtual*/ T2ToolIconItem::~T2ToolIconItem() { } T2ToolIconList::T2ToolIconList() { } /*virtual*/ T2ToolIconList::~T2ToolIconList() { T2ToolIconItem *theToolIconItem; POSITION pos = GetHeadPosition(); while (pos) { theToolIconItem = GetNext(pos); delete theToolIconItem; } }