/*========================================================================= * * SEClDias.cpp : List Dialogs - Implementation file * * * Version 1.0 * Creation date * Revision date * * Shaitan *=======================================================================*/ #include "stdafx.h" #include "acp_base.h" #include "SECTint.hpp" #include "SEClDias.hpp" #include "SECmodif.hpp" #include "..\Main\Inc\_EditID.h" #include "TUT.h" #define C_uiCopyEntry 1 #define C_uiPasteEntry 2 //################################################################################# // DIALOGBASE //################################################################################# /*---------------------------------------- ----------------------------------------*/ SECT_DialogBase::SECT_DialogBase(CWnd* pParent) : CFormView(SECT_DialogBase::IDD) { //{{AFX_DATA_INIT(SECT_DialogBase) //}}AFX_DATA_INIT } /*---------------------------------------- ----------------------------------------*/ void SECT_DialogBase::DoDataExchange(CDataExchange* pDX) { CFormView::DoDataExchange(pDX); //{{AFX_DATA_MAP(SECT_DialogBase) DDX_Control(pDX, SECT_IDC_SYMETRIC, m_cSymetric); DDX_Control(pDX, SECT_IDC_LISTPARAMS, m_cListParams); //}}AFX_DATA_MAP } /*---------------------------------------- ----------------------------------------*/ BEGIN_MESSAGE_MAP(SECT_DialogBase, CFormView) //{{AFX_MSG_MAP(SECT_DialogBase) ON_LBN_SELCHANGE(SECT_IDC_SORTEDLISTBOX, OnSelchangeSectorList) ON_LBN_DBLCLK(SECT_IDC_SORTEDLISTBOX, OnDblClkSectorList) ON_BN_CLICKED(SECT_IDC_SYMETRIC, OnSymetric) ON_WM_DRAWITEM() ON_WM_SIZE() ON_WM_DESTROY() //}}AFX_MSG_MAP END_MESSAGE_MAP() /*=========================================================================== *=========================================================================*/ void SECT_DialogBase::fn_vInitDialog (Sector_Interface *p_oDLL, CWnd *pParent, const CString csTag, BOOL bShowListParams) { // create the dialog m_bInitialised = FALSE; m_pSectorInterface = p_oDLL; CFormView::Create(NULL, "", AFX_WS_DEFAULT_VIEW, CRect(0,0,120,180), pParent, AFX_IDW_PANE_FIRST, NULL); // init data for dialog CFormView::UpdateData(FALSE); // FOR TUTORIAL TUT_M_vGetTutDll(); TUT_M_vRegisterControl (m_cSymetric.m_hWnd, "OSC_DLIST" + csTag + "_BUTTON_SYMETRIC", TUT_e_Button); TUT_M_vRegisterControl (m_cListParams.m_hWnd, "OSC_DLIST" + csTag + "_LIST_PARAMS", TUT_e_ListBox); TUT_M_vRegisterControlID(SECT_IDC_SORTEDLISTBOX, "OSC_DLIST" + csTag + "_LIST_SECTORS", TUT_e_ListBox); // END TUTORIAL m_pSectorList = NULL; m_pSelectedElem = NULL; // init list params m_bShowListParams = bShowListParams; m_cListParams.EnableWindow(m_bShowListParams); m_cListParams.ShowWindow((m_bShowListParams) ? SW_SHOW : SW_HIDE); m_bInitialised = TRUE; } /*=========================================================================== *=========================================================================*/ void SECT_DialogBase::fn_vReinitDialog (SECT_ListBase *pSectorList) { // init list m_pSectorList = pSectorList; // init sorted listbox fn_vInitSectorList(pSectorList); m_cListParams.EnableWindow(m_bShowListParams); m_cListParams.ShowWindow(m_bShowListParams ? SW_SHOW : SW_HIDE); } /*=========================================================================== *=========================================================================*/ void SECT_DialogBase::fn_vInitSectorList (SECT_ListBase *pSectorList) { GetSectorList()->fn_vInitSectorList(pSectorList); // init selection m_pSelectedElem = NULL; // update list params fn_vReinitListParams(); } /*=========================================================================== *=========================================================================*/ void SECT_DialogBase::fn_vUpdateSelection (CPA_SuperObject *pSector) { int iIndex; // no list => no change if (!m_pSectorList) return; // get coresponding element m_pSelectedElem = m_pSectorList->GetElementWithSector(pSector); // set selection iIndex = GetSectorList()->GetCorrespondingIndex((DWORD) m_pSelectedElem); GetSectorList()->SetCurSel(iIndex); // update list params fn_vReinitListParams(); } /*---------------------------------------- ----------------------------------------*/ void SECT_DialogBase::OnSelchangeSectorList() { int iIndex; // select the object corresponding to the choice in the list box iIndex = GetSectorList()->GetCurSel(); if (iIndex > -1) m_pSelectedElem = (SECT_ElementBase *) GetSectorList()->GetItemData(iIndex); else m_pSelectedElem = NULL; // update editor if ((m_pSelectedElem)&&(m_pSectorInterface->GetEditMode() == E_em_EditSector)) m_pSectorInterface->fn_vSelectNewSector(m_pSelectedElem->GetSector()); } /*---------------------------------------- ----------------------------------------*/ void SECT_DialogBase::OnDblClkSectorList() { int iIndex; // select the object corresponding to the choice in the list box iIndex = GetSectorList()->GetCurSel(); if (iIndex > -1) m_pSelectedElem = (SECT_ElementBase *) GetSectorList()->GetItemData(iIndex); else m_pSelectedElem = NULL; // update selection in editor if ((m_pSelectedElem)&&(m_pSectorInterface->GetEditMode() == E_em_EditSector)) m_pSectorInterface->fn_vSelectNewSector(m_pSelectedElem->GetSector()); } /*---------------------------------------- ----------------------------------------*/ void SECT_DialogBase::OnSymetric() { SECT_ModifSymetricLinks *pModif; pModif = new SECT_ModifSymetricLinks(m_pSectorInterface, E_tm_SymetricLinks, m_pSectorInterface->GetEditedSector(), m_eType); m_pSectorInterface->M_GetEditManager()->AskFor(pModif); } /*---------------------------------------- ----------------------------------------*/ void SECT_DialogBase::OnSize (UINT nFlags, int cx, int cy) { RECT WindowPosition; int lcx, lcy; if (!m_bInitialised) return; GetWindowRect(&WindowPosition); // calculate list position lcx = WindowPosition.right - WindowPosition.left - 10; lcy = WindowPosition.bottom - WindowPosition.top - 25; lcx = (lcx < 50) ? 50 : lcx; lcy = (lcy < 0) ? 0 : lcy; m_cSymetric.MoveWindow(lcx-40, 2, 45, 16); if (m_bShowListParams) { lcx = lcx - 10; GetSectorList()->MoveWindow(5, 20, lcx/2, lcy); m_cListParams.MoveWindow(lcx/2+10, 20, lcx/2, lcy); } else GetSectorList()->MoveWindow(5, 20, lcx, lcy); } /*---------------------------------------- ----------------------------------------*/ void SECT_DialogBase::OnDestroy (void) { // FOR TUTORIAL TUT_M_vGetTutDll(); TUT_M_vUnregisterControl (m_cSymetric.m_hWnd); TUT_M_vUnregisterControl (m_cListParams.m_hWnd); TUT_M_vUnregisterControlID (SECT_IDC_SORTEDLISTBOX); // END TUTORIAL CFormView::OnDestroy(); } /*---------------------------------------- ----------------------------------------*/ void SECT_DialogBase::OnDrawItem (int nIDCtl, LPDRAWITEMSTRUCT lpDIS) { // not interested => default handling if (lpDIS->itemID == LB_ERR) return; if (nIDCtl == SECT_IDC_SORTEDLISTBOX) { if ((!GetSectorList())||(!GetSectorList()->IsWindowEnabled())) return; // draw item GetSectorList()->fn_vDrawListItem(nIDCtl, lpDIS); } } //################################################################################# // SORTED LIST BOX //################################################################################# BEGIN_MESSAGE_MAP(SECT_CustomListBox, CListBox) ON_WM_RBUTTONDOWN() ON_WM_KEYDOWN() END_MESSAGE_MAP() /*---------------------------------------- ----------------------------------------*/ SECT_CustomListBox::SECT_CustomListBox (void) { // init dialog parameters m_pDialog = NULL; m_pSectorInterface = NULL; } /*---------------------------------------- ----------------------------------------*/ void SECT_CustomListBox::fn_vInitDialogParameters (SECT_DialogBase *pDialog) { m_pDialog = pDialog; m_pSectorInterface = m_pDialog->GetSectorInterface(); } /*---------------------------------------- ----------------------------------------*/ void SECT_CustomListBox::OnKeyDown (UINT nChar, UINT nRepCnt, UINT nFlags) { m_pSectorInterface->fn_vOnKeyDownInSectorList(m_pDialog, nChar); } /*---------------------------------------- ----------------------------------------*/ void SECT_CustomListBox::OnRButtonDown (UINT nFlags, CPoint point) { BOOL bCopy; ClientToScreen( &point ); // create popup menu CMenu oMenu; oMenu.CreatePopupMenu(); // check if there is already a copy bCopy = (m_pSectorInterface->GetCopyOfSectorList()->GetCount() > 0); // Add Entry oMenu.AppendMenu(MF_STRING | MF_ENABLED, C_uiCopyEntry, "Copy List"); oMenu.AppendMenu(MF_STRING | (bCopy) ? MF_ENABLED : MF_GRAYED, C_uiPasteEntry, "Paste List"); oMenu.TrackPopupMenu(TPM_LEFTALIGN | TPM_RIGHTBUTTON, point.x, point.y, this); // destroy menus oMenu.DestroyMenu(); } /*---------------------------------------- ----------------------------------------*/ BOOL SECT_CustomListBox::OnCommand (WPARAM wParam, LPARAM lParam) { // command from a menu ? if (HIWORD(wParam) == 0) { // ID of menu item ? switch (LOWORD(wParam)) { // column headers case C_uiCopyEntry: m_pSectorInterface->fn_vCopySectorList(m_pSectorInterface->GetEditedSector(), m_pDialog->GetListType()); break; case C_uiPasteEntry: m_pSectorInterface->fn_vPasteSectorList(m_pSectorInterface->GetEditedSector(), m_pDialog->GetListType()); break; } } return CListBox::OnCommand(wParam, lParam); } /*---------------------------------------- ----------------------------------------*/ void SECT_CustomListBox::fn_vInitSectorList (SECT_ListBase *pSectorList) { SECT_ElementBase *pElem; POSITION pos; CString csText; int iPos; // RAZ ResetContent(); if (!pSectorList) return; // add items to list for (pElem = pSectorList->GetHeadElementBase(pos); pElem; pElem = pSectorList->GetNextElementBase(pos)) { csText = (pElem->GetSector() != NULL) ? pElem->GetSector()->GetName() : "All Sectors"; iPos = AddString(csText); SetItemData(iPos, (DWORD)pElem); } } /*---------------------------------------- ----------------------------------------*/ int SECT_CustomListBox::GetCorrespondingIndex (DWORD pElem) { DWORD pData; int iIndex; for (iIndex = 0; iIndex < GetCount(); iIndex++) { pData = GetItemData(iIndex); if (pData == pElem) return iIndex; } return -1; } //################################################################################# // ACTIVITY //################################################################################# /*---------------------------------------- ----------------------------------------*/ void SECT_ActivityListBox::fn_vDrawListItem (int nIDCtl, LPDRAWITEMSTRUCT lpDIS) { SECT_ActivityElement *pElem; COLORREF cTextColor; COLORREF cRectColor; BOOL bSelected; CDC *pDC; if (!m_pDialog) return; // init parameters pElem = (SECT_ActivityElement *) GetItemData(lpDIS->itemID); bSelected = (lpDIS->itemState & ODS_SELECTED); // drawing rect pDC = CDC::FromHandle(lpDIS->hDC); // selected sector => blue if (bSelected) { cRectColor = RGB (0, 0, 200); cTextColor = RGB (254, 254, 254); } // normal sector => black else { cRectColor = GetSysColor(COLOR_WINDOW); cTextColor = RGB (0, 0, 0); } // draw item pDC->FillSolidRect(&lpDIS->rcItem, cRectColor); pDC->SetBkMode(TRANSPARENT); lpDIS->rcItem.left += 2; pDC->SetTextColor(cTextColor); pDC->DrawText(pElem->GetSector()->GetNameToDraw(), &lpDIS->rcItem, DT_SINGLELINE | DT_LEFT | DT_VCENTER); } /*=========================================================================== *=========================================================================*/ SECT_DialogActiv::SECT_DialogActiv (CWnd* pParent) { m_eType = E_Activity; } /*---------------------------------------- ----------------------------------------*/ void SECT_DialogActiv::DoDataExchange(CDataExchange* pDX) { SECT_DialogBase::DoDataExchange(pDX); //{{AFX_DATA_MAP(SECT_DialogList) DDX_Control(pDX, SECT_IDC_SORTEDLISTBOX, m_cSectorList); //}}AFX_DATA_MAP m_cSectorList.fn_vInitDialogParameters(this); } //################################################################################# // COLLISION //################################################################################# /*---------------------------------------- ----------------------------------------*/ void SECT_CollisionListBox::fn_vDrawListItem (int nIDCtl, LPDRAWITEMSTRUCT lpDIS) { SECT_CollisionElement *pElem; COLORREF cTextColor; COLORREF cRectColor; BOOL bSelected; CDC *pDC; if (!m_pDialog) return; // init parameters pElem = (SECT_CollisionElement *) GetItemData(lpDIS->itemID); bSelected = (lpDIS->itemState & ODS_SELECTED); // drawing rect pDC = CDC::FromHandle(lpDIS->hDC); // selected sector => blue if (bSelected) { cRectColor = RGB (0, 0, 200); cTextColor = RGB (254, 254, 254); } // normal sector => black else { cRectColor = GetSysColor(COLOR_WINDOW); cTextColor = RGB (0, 0, 0); } // draw item pDC->FillSolidRect(&lpDIS->rcItem, cRectColor); pDC->SetBkMode(TRANSPARENT); lpDIS->rcItem.left += 2; pDC->SetTextColor(cTextColor); pDC->DrawText(pElem->GetSector()->GetNameToDraw(), &lpDIS->rcItem, DT_SINGLELINE | DT_LEFT | DT_VCENTER); } /*=========================================================================== *=========================================================================*/ SECT_DialogColls::SECT_DialogColls (CWnd* pParent) { m_eType = E_Collision; } /*---------------------------------------- ----------------------------------------*/ void SECT_DialogColls::DoDataExchange(CDataExchange* pDX) { SECT_DialogBase::DoDataExchange(pDX); //{{AFX_DATA_MAP(SECT_DialogList) DDX_Control(pDX, SECT_IDC_SORTEDLISTBOX, m_cSectorList); //}}AFX_DATA_MAP m_cSectorList.fn_vInitDialogParameters(this); } //################################################################################# // GRAPHIC //################################################################################# /*---------------------------------------- ----------------------------------------*/ void SECT_GraphicListBox::fn_vDrawListItem (int nIDCtl, LPDRAWITEMSTRUCT lpDIS) { SECT_GraphicElement *pGraphicElem; COLORREF cTextColor; COLORREF cRectColor; CString csText; BOOL bSelected; CDC *pDC; long lWidth; if (!m_pDialog) return; // init parameters pGraphicElem = (SECT_GraphicElement *) GetItemData(lpDIS->itemID); bSelected = (lpDIS->itemState & ODS_SELECTED); lWidth = (lpDIS->rcItem.right < lpDIS->rcItem.left + 24) ? 0 : 22; // drawing rect pDC = CDC::FromHandle(lpDIS->hDC); // selected sector => blue if (bSelected) { cRectColor = RGB (0, 0, 200); cTextColor = RGB (254, 254, 254); } // normal sector => black else { cRectColor = GetSysColor(COLOR_WINDOW); cTextColor = RGB (0, 0, 0); } // draw rect pDC->FillSolidRect(&lpDIS->rcItem, cRectColor); pDC->SetBkMode(TRANSPARENT); pDC->SetTextColor(cTextColor); // draw sector name lpDIS->rcItem.left += 1; lpDIS->rcItem.right -= lWidth; pDC->DrawText(pGraphicElem->GetSector()->GetNameToDraw(), &lpDIS->rcItem, DT_SINGLELINE | DT_LEFT | DT_VCENTER); // draw level lpDIS->rcItem.left = lpDIS->rcItem.right + 1; lpDIS->rcItem.right = lpDIS->rcItem.left + lWidth / 2; csText.Format("%d", pGraphicElem->GetGraphicLevel()); pDC->DrawText(csText, &lpDIS->rcItem, DT_SINGLELINE | DT_LEFT | DT_VCENTER); // draw mode lpDIS->rcItem.left = lpDIS->rcItem.right + 1; lpDIS->rcItem.right = lpDIS->rcItem.left + lWidth / 2; csText = (pGraphicElem->GetGraphicMode() == C_SECT_ModeLookOnly) ? "L" : " "; pDC->DrawText(csText, &lpDIS->rcItem, DT_SINGLELINE | DT_LEFT | DT_VCENTER); } /*=========================================================================== *=========================================================================*/ SECT_DialogGraph::SECT_DialogGraph (CWnd* pParent) { m_eType = E_Graphic; } /*---------------------------------------- ----------------------------------------*/ void SECT_DialogGraph::DoDataExchange(CDataExchange* pDX) { SECT_DialogBase::DoDataExchange(pDX); //{{AFX_DATA_MAP(SECT_DialogList) DDX_Control(pDX, SECT_IDC_SORTEDLISTBOX, m_cSectorList); //}}AFX_DATA_MAP m_cSectorList.fn_vInitDialogParameters(this); } //################################################################################# // SOUND //################################################################################# /*---------------------------------------- ----------------------------------------*/ void SECT_SoundListBox::fn_vDrawListItem (int nIDCtl, LPDRAWITEMSTRUCT lpDIS) { SECT_SoundElement *pSoundElem; COLORREF cTextColor; COLORREF cRectColor; CString csText; BOOL bSelected; CDC *pDC; long lWidth; if (!m_pDialog) return; // init parameters pSoundElem = (SECT_SoundElement *) GetItemData(lpDIS->itemID); bSelected = (lpDIS->itemState & ODS_SELECTED); lWidth = (lpDIS->rcItem.right < lpDIS->rcItem.left + 22) ? 0 : 21; // drawing rect pDC = CDC::FromHandle(lpDIS->hDC); // selected sector => blue if (bSelected) { cRectColor = RGB (0, 0, 200); cTextColor = RGB (254, 254, 254); } // normal sector => black else { cRectColor = GetSysColor(COLOR_WINDOW); cTextColor = RGB (0, 0, 0); } // draw item pDC->FillSolidRect(&lpDIS->rcItem, cRectColor); pDC->SetBkMode(TRANSPARENT); pDC->SetTextColor(cTextColor); // draw sector name lpDIS->rcItem.left += 1; lpDIS->rcItem.right -= lWidth; pDC->DrawText(pSoundElem->GetSector()->GetNameToDraw(), &lpDIS->rcItem, DT_SINGLELINE | DT_LEFT | DT_VCENTER); // draw level lpDIS->rcItem.left = lpDIS->rcItem.right + 1; lpDIS->rcItem.right = lpDIS->rcItem.left + lWidth; csText.Format("%d", pSoundElem->GetSoundLevel()); pDC->DrawText(csText, &lpDIS->rcItem, DT_SINGLELINE | DT_LEFT | DT_VCENTER); } /*=========================================================================== *=========================================================================*/ SECT_DialogSound::SECT_DialogSound (CWnd* pParent) { m_eType = E_Sound; } /*---------------------------------------- ----------------------------------------*/ void SECT_DialogSound::DoDataExchange(CDataExchange* pDX) { SECT_DialogBase::DoDataExchange(pDX); //{{AFX_DATA_MAP(SECT_DialogList) DDX_Control(pDX, SECT_IDC_SORTEDLISTBOX, m_cSectorList); //}}AFX_DATA_MAP m_cSectorList.fn_vInitDialogParameters(this); } //################################################################################# // SOUND EVENT //################################################################################# /*---------------------------------------- ----------------------------------------*/ void SECT_SoundEventListBox::fn_vDrawListItem (int nIDCtl, LPDRAWITEMSTRUCT lpDIS) { SECT_SoundEventElement *pElem; COLORREF cTextColor; COLORREF cRectColor; CString csText; BOOL bSelected; CDC *pDC; if (!m_pDialog) return; // init parameters pElem = (SECT_SoundEventElement *) GetItemData(lpDIS->itemID); bSelected = (lpDIS->itemState & ODS_SELECTED); // drawing rect pDC = CDC::FromHandle(lpDIS->hDC); // selected sector => blue if (bSelected) { cRectColor = RGB (0, 0, 200); cTextColor = RGB (254, 254, 254); } // normal sector => black else { cRectColor = GetSysColor(COLOR_WINDOW); cTextColor = RGB (0, 0, 0); } // draw item pDC->FillSolidRect(&lpDIS->rcItem, cRectColor); pDC->SetBkMode(TRANSPARENT); lpDIS->rcItem.left += 2; pDC->SetTextColor(cTextColor); csText = (pElem->GetSector() != NULL) ? pElem->GetSector()->GetNameToDraw() : "All Sectors"; pDC->DrawText(csText, &lpDIS->rcItem, DT_SINGLELINE | DT_LEFT | DT_VCENTER); } /*=========================================================================== *=========================================================================*/ SECT_DialogSoundEvent::SECT_DialogSoundEvent (CWnd* pParent) { m_eType = E_SoundEvent; } /*---------------------------------------- ----------------------------------------*/ void SECT_DialogSoundEvent::DoDataExchange(CDataExchange* pDX) { SECT_DialogBase::DoDataExchange(pDX); //{{AFX_DATA_MAP(SECT_DialogList) DDX_Control(pDX, SECT_IDC_SORTEDLISTBOX, m_cSectorList); //}}AFX_DATA_MAP m_cSectorList.fn_vInitDialogParameters(this); } /*---------------------------------------- ----------------------------------------*/ void SECT_DialogSoundEvent::fn_vReinitListParams (void) { SECT_SoundEventElement *pSoundEventElem; SECT_SndEvtEngineElem *pElem; SECT_SoundEvent *pSoundEvent; POSITION pos; int iInd; // RAZ m_cListParams.ResetContent(); if (!m_pSelectedElem) return; pSoundEventElem = (SECT_SoundEventElement *) m_pSelectedElem; // fill list with sector sound events for (pElem = pSoundEventElem->GetSndEvtList()->GetHeadElement(pos); pElem; pElem = pSoundEventElem->GetSndEvtList()->GetNextElement(pos)) { pSoundEvent = pElem->GetSoundEvent(); if (pSoundEvent) iInd = m_cListParams.AddString(pSoundEvent->GetName()); else iInd = m_cListParams.AddString("Unknown"); m_cListParams.SetItemData(iInd, (DWORD) pSoundEvent); } // current selection => none m_cListParams.SetCurSel(-1); }