【VC开源代码栏目提醒】:本文主要为网学会员提供CONTROLSWND.CPP,希望对需要CONTROLSWND.CPP网友有所帮助,学习一下!
/************************************
REVISION LOG ENTRY
Revision By: Mihai Filimon
Revised on 10/16/98 1:42:43 PM
Comments: ControlsWnd.cpp: implementation of the CControlsWnd class and all derived classes
************************************/
#include "stdafx.h"
#include "xpropertieswnd.h"
#include "ControlsWnd.h"
#include "PageListCtrl.h"
#include "XPropertiesWndCtl.h"
#include "font.h"
#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif
#define _FreezeEvents m_nFreezeEvent++
#define _UnFreezeEvents m_nFreezeEvent--
#define _IsFrozen (m_nFreezeEvent != 0)
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
CAsControls CControlsWnd::m_asControl;
TMapPg2TMapIdx2Ctrl CControlsWnd::m_mapPg2CtrlCreated;
long CControlsWnd::m_nFreezeEvent = 0;
IMPLEMENT_DYNAMIC(CControlsWnd,CObject)
// Function name : CControlsWnd::CControlsWnd
// Description : Default constuctor
// Return type :
CControlsWnd::CControlsWnd()
{
m_pWnd = NULL;
m_pNotifyWnd = NULL;
m_nSelectedItem = -1;
m_nSelectedSubItem = -1;
}
// Function name : CControlsWnd::~CControlsWnd
// Description : virtual destructor
// Return type :
CControlsWnd::~CControlsWnd()
{
if (m_pWnd)
if (::IsWindow(m_pWnd->m_hWnd))
::DestroyWindow(m_pWnd->m_hWnd);
}
// Function name : CControlsWnd::IsVisible
// Description : return true if control is visible
// Return type : BOOL
BOOL CControlsWnd::IsVisible()
{
if (m_pWnd)
if (AfxIsValidAddress(m_pWnd, sizeof(CWnd)))
if (IsWindow(m_pWnd->m_hWnd))
return m_pWnd->IsWindowVisible();
return FALSE;
}
// Function name : CControlsWnd::LookupPage
// Description :
// Return type : TMapIdx2Ctrl*
// Argument : CPageListCtrl* pNotifyWnd
TMapIdx2Ctrl* CControlsWnd::LookupPage(CPageListCtrl* pNotifyWnd)
{
TMapIdx2Ctrl* pResult = NULL;
if (m_mapPg2CtrlCreated.Lookup(pNotifyWnd, pResult))
return pResult;
return NULL;
}
// Function name : CControlsWnd::Lookup
// Description : Lookup in m_mapPg2CtrlCreated if this control is alredy created
// Return type : CControlsWnd*
// Argument : CPageListCtrl *pNotifyWnd
// Argument : int nSelectedItem
CControlsWnd* CControlsWnd::LookupControl(CPageListCtrl *pNotifyWnd, int nSelectedItem)
{
CControlsWnd* pResult = NULL;
if (TMapIdx2Ctrl* pMap = LookupPage(pNotifyWnd))
if (pMap->Lookup(nSelectedItem, pResult))
if (AfxIsValidAddress(*(void**)pResult, sizeof(void*), FALSE))
return pResult;
return NULL;
}
// Function name : CControlsWnd::Add2NDelete
// Description : Append a new control to map of not deleted controls
// Return type : void
// Argument : CControlsWnd *pControl
void CControlsWnd::Add2NDelete(CControlsWnd *pControl)
{
//This control when is created, need to be not destroyable, so I will put into the m_mapPg2CtrlCreated
TMapIdx2Ctrl* pMap = LookupPage(pControl->GetWindowNotify());
if (!pMap)
m_mapPg2CtrlCreated[pControl->GetWindowNotify()] = (pMap = new TMapIdx2Ctrl());
(*pMap)[pControl->GetSelectedItem()] = pControl;
}
// Function name : CControlsWnd::Kill
// Description : Kill this
// Return type : void
void CControlsWnd::Kill()
{
GetWindowNotify()->m_pEditControl = NULL;
delete this;
}
// Function name : CControlsWnd::KillAll
// Description : This function is called when user want to kill the control
// Return type : void
void CControlsWnd::KillAll()
{
POSITION posMap = m_mapPg2CtrlCreated.GetStartPosition();
TMapIdx2Ctrl* pMap = NULL; CPageListCtrl* pPage = NULL;
while (posMap)
{
m_mapPg2CtrlCreated.GetNextAssoc(posMap, pPage, pMap);
if (pMap)
{
CControlsWnd* pControl = NULL;
long nSelectedItem = NULL;
POSITION posCtrl = pMap->GetStartPosition();
while (posCtrl)
{
pMap->GetNextAssoc(posCtrl, nSelectedItem, pControl);
delete pControl;
}
delete pMap;
}
}
m_mapPg2CtrlCreated.RemoveAll();
}
// Function name : CControlsWnd::Create
// Description :
// Return type : CControlsWnd*
// Argument : LPCTSTR lpszAs
CControlsWnd* CControlsWnd::Create(LPCTSTR lpszAs, CPageListCtrl* pNotifyWnd, int nSelectedItem, int nSelectedSubItem)
{
// If the control is already created we will return the control already created
if (CControlsWnd* pResult = LookupControl(pNotifyWnd, nSelectedItem))
return pResult;
// Create a new one control
CString className(_T("CControlsWnd_C"));
className += lpszAs;
if (CControlsWnd* pResult = CreateObject(className))
{
pResult->m_pNotifyWnd = pNotifyWnd;
pResult->m_nSelectedItem = nSelectedItem;
pResult->m_nSelectedSubItem = nSelectedSubItem;
if (pResult->m_pWnd = pResult->Create())
{
if (::IsWindow(pResult->m_pWnd->m_hWnd))
pResult->m_pWnd->SetFont(&pResult->m_pNotifyWnd->m_itemFont);
return pResult;
}
}
return NULL;
}
// Function name : CControlsWnd::Close
// Description :
// Return type : void
// Argument : BOOL bCancel
void CControlsWnd::Close(BOOL bCancel)
{
if (m_pWnd)
if (::IsWindow(m_pWnd->m_hWnd))
{
ReleaseCapture();
m_pWnd->ShowWindow(SW_HIDE);
}
GetWindowNotify()->CloseEditing();
RefreshColor();
};
// Function name : CControlsWnd::GetWindow
// Description : return the window
// Return type : CWnd*
CWnd* CControlsWnd::GetWindow()
{
return m_pWnd;
}
// Function name : CControlsWnd::GetWindowNotify
// Description : return the notify window
// Return type : CPageListCtrl*
CPageListCtrl* CControlsWnd::GetWindowNotify()
{
return m_pNotifyWnd;
}
// Function name : CControlsWnd::GetControl
// Description :
// Return type : CXPropertiesWndCtrl*
CXPropertiesWndCtrl* CControlsWnd::GetControl()
{
return GetWindowNotify()->GetControlWnd();
}
// Function name : CControlsWnd::Show
// Description : generate BeginEditProperty event
// Return type : void
// Argument : LPARAM lParam
void CControlsWnd::Show(LPARAM lParam)
{
if (::IsWindow(GetWindow()->GetSafeHwnd()))
GetWindow()->SetFont(&GetWindowNotify()->m_itemFont, TRUE);
RefreshColor();
GetControl()->FirePropertyChanging(GetControl()->_GetActivePage(), m_nSelectedItem);
}
// Function name : CControlsWnd::OnSelectItem
// Description : When user select a new item, change the value of edit control, or click the button
// Return type : void
// Argument : CString& newValue
// Argument : LPARAM lParam
void CControlsWnd::OnSelectItem(CString& newValue, LPARAM lParam)
{
CString sOldProperty = GetDefaultValue();
GetWindowNotify()->SetDefaultValue(m_nSelectedItem, (LPCTSTR)newValue);
CXPropertiesWndCtrl* pControl =
上一篇:
ControlSoundDlg.cpp
下一篇:
英语论文网([网学网]):英语专业本科生毕业论文写作