www.pudn.com > mischat.rar > PropertiesViewBar.cpp


// PropertiesViewBar.cpp: implementation of the CPropertiesViewBar class. 
// 
////////////////////////////////////////////////////////////////////// 
 
#include "stdafx.h" 
#include "mischat.h" 
#include "MainFrm.h" 
#include "PropertiesViewBar.h" 
#include "mischatDoc.h" 
#include "mischatView.h" 
#include "Draw.h" 
 
#include ".\propertiesviewbar.h" 
 
extern CmischatDoc* pDoc; 
 
#ifdef _DEBUG 
#undef THIS_FILE 
static char THIS_FILE[]=__FILE__; 
#define new DEBUG_NEW 
#endif 
 
///////////////////////////////////////////////////////////////////////////// 
// CResourceViewBar 
 
CPropertiesViewBar::CPropertiesViewBar() 
{ 
} 
 
CPropertiesViewBar::~CPropertiesViewBar() 
{ 
} 
 
 
BEGIN_MESSAGE_MAP(CPropertiesViewBar, CBCGPDockingControlBar) 
	//{{AFX_MSG_MAP(CPropertiesViewBar) 
	ON_WM_CREATE() 
	ON_WM_SIZE() 
	ON_COMMAND(ID_SORTINGPROP, OnSortingprop) 
	ON_UPDATE_COMMAND_UI(ID_SORTINGPROP, OnUpdateSortingprop) 
	ON_COMMAND(ID_EXPAND, OnExpand) 
	ON_UPDATE_COMMAND_UI(ID_EXPAND, OnUpdateExpand) 
	ON_WM_PAINT() 
	ON_WM_SETFOCUS() 
	ON_WM_SETTINGCHANGE() 
	ON_CBN_SELCHANGE(ID_PROPERTIES_COMBO,OnComboSelChange) 
	//}}AFX_MSG_MAP 
END_MESSAGE_MAP() 
 
 
///////////////////////////////////////////////////////////////////////////// 
// CResourceViewBar message handlers 
 
void CPropertiesViewBar::AdjustLayout () 
{ 
	if (GetSafeHwnd () == NULL) 
	{ 
		return; 
	} 
 
	CRect rectClient,rectCombo; 
	GetClientRect (rectClient); 
 
	m_wndObjectCombo.GetWindowRect (&rectCombo); 
 
	int cyCmb = rectCombo.Size ().cy; 
	int cyTlb = m_wndToolBar.CalcFixedLayout (FALSE, TRUE).cy; 
 
	m_wndObjectCombo.SetWindowPos (NULL, 
								   rectClient.left,  
								   rectClient.top, 
								   rectClient.Width (), 
								   200, 
								   SWP_NOACTIVATE | SWP_NOZORDER); 
 
	m_wndToolBar.SetWindowPos (NULL, 
							   rectClient.left,  
							   rectClient.top + cyCmb,  
							   rectClient.Width (), 
							   cyTlb, 
							   SWP_NOACTIVATE | SWP_NOZORDER); 
 
 
	m_wndPropList.SetWindowPos (NULL, 
									  rectClient.left + 1,  
									  rectClient.top + cyCmb + cyTlb + 1,  
									  rectClient.Width () - 2, 
									  rectClient.Height () - (cyCmb+cyTlb) - 2, 
									  SWP_NOACTIVATE | SWP_NOZORDER); 
} 
 
int CPropertiesViewBar::OnCreate(LPCREATESTRUCT lpCreateStruct)  
{ 
	if (CBCGPDockingControlBar::OnCreate(lpCreateStruct) == -1) 
		return -1; 
	 
	CRect rectDummy; 
	rectDummy.SetRectEmpty (); 
 
	// Create combo: 
	const DWORD dwViewStyle =	WS_CHILD | WS_VISIBLE | CBS_DROPDOWNLIST 
		| WS_BORDER | WS_CLIPSIBLINGS | WS_CLIPCHILDREN; 
	 
	if (!m_wndObjectCombo.Create (dwViewStyle, rectDummy, this, ID_PROPERTIES_COMBO)) 
	{ 
		TRACE0("Failed to create Properies Combo \n"); 
		return -1;      // fail to create 
	} 
 
	m_wndObjectCombo.AddString (_T("全局设置")); 
	m_wndObjectCombo.AddString (_T("当前对象")); 
 
	m_wndObjectCombo.SetFont (CFont::FromHandle ((HFONT) GetStockObject (DEFAULT_GUI_FONT))); 
 
	if (!m_wndPropList.Create (WS_VISIBLE | WS_CHILD, rectDummy, this, 2)) 
	{ 
		TRACE0("Failed to create Properies Grid \n"); 
		return -1;      // fail to create 
	} 
 
	SetPropListFont (); 
	m_wndPropList.EnableHeaderCtrl (FALSE); 
	m_wndPropList.EnableDesciptionArea (); 
	m_wndPropList.SetVSDotNetLook (); 
	InitPropList (); 
 
	m_wndToolBar.Create (this, dwDefaultToolbarStyle, IDR_PROPERTIES); 
	m_wndToolBar.LoadToolBar (IDR_PROPERTIES, 0, 0, TRUE /* Is locked */); 
 
	m_wndToolBar.SetBarStyle(m_wndToolBar.GetBarStyle() | 
		CBRS_TOOLTIPS | CBRS_FLYBY); 
		 
	m_wndToolBar.SetBarStyle ( 
		m_wndToolBar.GetBarStyle () &  
			~(CBRS_GRIPPER | CBRS_SIZE_DYNAMIC | CBRS_BORDER_TOP | CBRS_BORDER_BOTTOM | CBRS_BORDER_LEFT | CBRS_BORDER_RIGHT)); 
 
	m_wndToolBar.SetOwner (this); 
 
	// All commands will be routed via this control , not via the parent frame: 
	m_wndToolBar.SetRouteCommandsViaFrame (FALSE); 
 
	AdjustLayout (); 
	return 0; 
} 
 
void CPropertiesViewBar::OnSize(UINT nType, int cx, int cy)  
{ 
	CBCGPDockingControlBar::OnSize(nType, cx, cy); 
	AdjustLayout (); 
} 
 
void CPropertiesViewBar::OnSortingprop()  
{ 
	m_wndPropList.SetAlphabeticMode (); 
} 
 
void CPropertiesViewBar::OnUpdateSortingprop(CCmdUI* pCmdUI)  
{ 
	pCmdUI->SetCheck (m_wndPropList.IsAlphabeticMode ()); 
} 
 
void CPropertiesViewBar::OnExpand()  
{ 
	m_wndPropList.SetAlphabeticMode (FALSE); 
} 
 
void CPropertiesViewBar::OnUpdateExpand(CCmdUI* pCmdUI)  
{ 
	pCmdUI->SetCheck (!m_wndPropList.IsAlphabeticMode ()); 
} 
 
void CPropertiesViewBar::OnPaint()  
{ 
	CPaintDC dc(this); // device context for painting 
	 
	CRect rectList; 
	m_wndPropList.GetWindowRect (rectList); 
	ScreenToClient (rectList); 
 
	rectList.InflateRect (1, 1); 
	dc.Draw3dRect (rectList, ::GetSysColor (COLOR_3DSHADOW), ::GetSysColor (COLOR_3DSHADOW)); 
} 
 
void CPropertiesViewBar::InitPropList () 
{ 
	CBCGPProp* pProp; 
	CBCGPProp* pGroup; 
	CBCGPColorProp* pColorProp; 
 
	pGroup = new CBCGPProp (_T("服务器设置")); 
	pProp = new CBCGPProp (_T("监听端口"), (_variant_t)pDoc->m_ServerPort,_T("设置服务器监听端口(1025-9999)")); 
	pProp->EnableSpinControl (TRUE,1025,9999); 
	pGroup->AddSubItem (pProp); 
	pProp = new CBCGPProp (_T("允许连接数"), (_variant_t)pDoc->m_ConnectMax,_T("设置服务器允许连接数(5-50)")); 
	pProp->EnableSpinControl (TRUE,5,50); 
	pGroup->AddSubItem (pProp); 
	pProp = new CBCGPProp (_T("与会者权限"), (_variant_t)pDoc->ChatPrivilege,_T("设置与会者所允许和不允许做的事")); 
	pProp->AddOption (_T("文本")); 
	pProp->AddOption (_T("白板")); 
	pProp->AddOption (_T("语音")); 
	pProp->AddOption (_T("全部")); 
	pProp->AddOption (_T("禁止")); 
	pProp->AllowEdit (FALSE); 
	pGroup->AddSubItem (pProp); 
	m_wndPropList.AddProperty (pGroup); 
 
	pGroup = new CBCGPProp (_T("客户机设置")); 
	pProp = new CBCGPProp (_T("服务器IP地址"), (_variant_t)pDoc->m_strIP,_T("设置服务器IP地址(注意IP地址格式)")); 
	pGroup->AddSubItem (pProp); 
	pProp = new CBCGPProp (_T("连接端口"), (_variant_t)pDoc->m_ClientPort,_T("设置客户机连接端口(1025-9999)")); 
	pProp->EnableSpinControl (TRUE,1025,9999); 
	pGroup->AddSubItem (pProp); 
	pProp = new CBCGPProp (_T("用户呢称"), (_variant_t)pDoc->strName,_T("设置你的呢称,服务器能看到你的呢称,若你更改了呢称则下次连接才能生效")); 
	pGroup->AddSubItem (pProp); 
	m_wndPropList.AddProperty (pGroup); 
 
	pGroup = new CBCGPProp (_T("绘图特性")); 
	pProp = new CBCGPProp (_T("笔粗"), (_variant_t)pDoc->widthPen,_T("设置画笔粗细(1-10)")); 
	pProp->EnableSpinControl (TRUE, 1, 10); 
	pGroup->AddSubItem (pProp); 
 
	pColorProp = new CBCGPColorProp (_T("画笔颜色"),pDoc->corPen, NULL, _T("设置画笔颜色")); 
	pColorProp->EnableOtherButton (_T("其它...")); 
	pColorProp->EnableAutomaticButton (_T("缺省"),RGB(0, 0, 255)); 
	pGroup->AddSubItem (pColorProp); 
 
	pColorProp = new CBCGPColorProp (_T("画刷颜色"),pDoc->corBrush , NULL, _T("设置画刷颜色")); 
	pColorProp->EnableOtherButton (_T("其它...")); 
	pColorProp->EnableAutomaticButton (_T("缺省"),RGB(255,255,255)); 
	pGroup->AddSubItem (pColorProp); 
 
	pGroup->AddSubItem (new CBCGPFontProp (_T("字体"),pDoc->lf, CF_EFFECTS | CF_SCREENFONTS, _T("指定白板文本工具所使用的字体"))); 
	m_wndPropList.AddProperty (pGroup); 
} 
 
void CPropertiesViewBar::OnSetFocus(CWnd* pOldWnd)  
{ 
	CBCGPDockingControlBar::OnSetFocus(pOldWnd); 
	 
	m_wndPropList.SetFocus (); 
	 
} 
 
void CPropertiesViewBar::OnSettingChange(UINT uFlags, LPCTSTR lpszSection)  
{ 
	CBCGPDockingControlBar::OnSettingChange(uFlags, lpszSection); 
	SetPropListFont (); 
} 
 
void CPropertiesViewBar::SetPropListFont () 
{ 
	::DeleteObject (m_fntPropList.Detach ()); 
 
	LOGFONT lf; 
	globalData.fontRegular.GetLogFont (&lf); 
 
	NONCLIENTMETRICS info; 
	info.cbSize = sizeof(info); 
 
	::SystemParametersInfo (SPI_GETNONCLIENTMETRICS, sizeof(info), &info, 0); 
 
	lf.lfHeight = info.lfMenuFont.lfHeight; 
	lf.lfWeight = info.lfMenuFont.lfWeight; 
	lf.lfItalic = info.lfMenuFont.lfItalic; 
 
	m_fntPropList.CreateFontIndirect (&lf); 
 
	m_wndPropList.SetFont (&m_fntPropList); 
} 
 
void CMYBCGPPropList::OnPropertyChanged(CBCGPProp*pProp) const 
{ 
	CString strName; 
	strName=pProp->GetName (); 
 
	if(strName==_T("笔粗"))pDoc->widthPen=pProp->GetValue ().intVal; 
	if(strName==_T("画笔颜色"))pDoc->corPen=(COLORREF)pProp->GetValue ().lVal ; 
	if(strName==_T("画刷颜色"))pDoc->corBrush=(COLORREF)pProp->GetValue ().lVal ; 
	if(strName==_T("字体")){ 
		CBCGPFontProp* p=(CBCGPFontProp*)pProp; 
		pDoc->corText=p->GetColor (); 
		pDoc->lf=*p->GetLogFont (); 
	} 
 
	if(strName==_T("监听端口"))pDoc->m_ServerPort=pProp->GetValue ().intVal; 
	if(strName==_T("允许连接数"))pDoc->m_ConnectMax=pProp->GetValue ().intVal; 
	if(strName==_T("与会者权限"))pDoc->ChatPrivilege=pProp->GetValue ().bstrVal; 
 
	if(strName==_T("连接端口"))pDoc->m_ClientPort=pProp->GetValue ().intVal; 
	if(strName==_T("服务器IP地址"))pDoc->m_strIP=pProp->GetValue ().bstrVal; 
	if(strName==_T("用户呢称"))pDoc->strName=pProp->GetValue ().bstrVal; 
 
	if(strName==_T("对象笔粗") || strName==_T("对象颜色") ||strName==_T("对象填充色")||strName==_T("对象字体")||strName==_T("对象文字")) 
	pDoc->pView->SaveCurDraw(pProp); 
} 
 
void CPropertiesViewBar::RefreshPropList() 
{ 
	CString str; 
	m_wndObjectCombo.GetWindowText (str); 
	if(str==_T("全局设置")) return; 
	m_wndPropList.RemoveAll (); 
	CBCGPProp* pProp; 
	CBCGPProp* pGroup; 
	CBCGPColorProp* pColorProp; 
	pGroup = new CBCGPProp (_T("当前对象")); 
	CDraw * pdw=pDoc->pView->pDrawSelect; 
	if(pDoc->pView->isSelected && pdw!=NULL) 
	{			 
		if(pdw->IsKindOf (RUNTIME_CLASS(CCurve))) 
		{ 
			CCurve* p=(CCurve*)pdw; 
			pProp = new CBCGPProp (_T("对象笔粗"), (_variant_t)p->m_width,_T("当前对象画笔粗细(1-10)")); 
			pProp->EnableSpinControl (TRUE, 1, 10); 
			pGroup->AddSubItem (pProp); 
 
			pColorProp = new CBCGPColorProp (_T("对象颜色"),p->m_crColor, NULL, _T("当前对象画笔颜色")); 
			pColorProp->EnableOtherButton (_T("其它...")); 
			pColorProp->EnableAutomaticButton (_T("缺省"),RGB(0, 0, 255)); 
			pGroup->AddSubItem (pColorProp); 
		} 
		if(pdw->IsKindOf (RUNTIME_CLASS(CLine))) 
		{ 
			CLine* p=(CLine*)pdw; 
			pProp = new CBCGPProp (_T("对象笔粗"), (_variant_t)p->m_width,_T("当前对象画笔粗细(1-10)")); 
			pProp->EnableSpinControl (TRUE, 1, 10); 
			pGroup->AddSubItem (pProp); 
 
			pColorProp = new CBCGPColorProp (_T("对象颜色"),p->m_crColor, NULL, _T("当前对象画笔颜色")); 
			pColorProp->EnableOtherButton (_T("其它...")); 
			pColorProp->EnableAutomaticButton (_T("缺省"),RGB(0, 0, 255)); 
			pGroup->AddSubItem (pColorProp); 
		} 
		if(pdw->IsKindOf (RUNTIME_CLASS(CText))) 
		{ 
			CText* p=(CText*)pdw; 
			pProp = new CBCGPProp (_T("对象文字"), (_variant_t)p->m_strText,_T("当前对象的文字内容")); 
			pGroup->AddSubItem (pProp); 
			pGroup->AddSubItem (new CBCGPFontProp (_T("对象字体"),p->m_lf, CF_EFFECTS | CF_SCREENFONTS, _T("当前对象所使用的字体"))); 
		} 
		if(pdw->IsKindOf (RUNTIME_CLASS(CRectangle))) 
		{ 
			CRectangle * p=(CRectangle *) pdw; 
			pProp = new CBCGPProp (_T("对象笔粗"), (_variant_t)p->m_width,_T("当前对象画笔粗细(1-10)")); 
			pProp->EnableSpinControl (TRUE, 1, 10); 
			pGroup->AddSubItem (pProp); 
 
			pColorProp = new CBCGPColorProp (_T("对象颜色"),p->m_crPen, NULL, _T("当前对象画笔颜色")); 
			pColorProp->EnableOtherButton (_T("其它...")); 
			pColorProp->EnableAutomaticButton (_T("缺省"),RGB(0, 0, 255)); 
			pGroup->AddSubItem (pColorProp); 
 
			pColorProp = new CBCGPColorProp (_T("对象填充色"),p->m_crBrush, NULL, _T("当前对象填充色")); 
			pColorProp->EnableOtherButton (_T("其它...")); 
			pColorProp->EnableAutomaticButton (_T("缺省"),RGB(255,255,255)); 
 
			if(p->DrawShape==RECTANGLE || p->DrawShape==ROUNDRECT) pColorProp->Enable (FALSE);				 
			pGroup->AddSubItem (pColorProp); 
		} 
		if(pdw->IsKindOf (RUNTIME_CLASS(CEllipse))) 
		{ 
			CEllipse* p=(CEllipse *) pdw; 
			pProp = new CBCGPProp (_T("对象笔粗"), (_variant_t)p->m_width,_T("当前对象画笔粗细(1-10)")); 
			pProp->EnableSpinControl (TRUE, 1, 10); 
			pGroup->AddSubItem (pProp); 
 
			pColorProp = new CBCGPColorProp (_T("对象颜色"),p->m_crPen, NULL, _T("当前对象画笔颜色")); 
			pColorProp->EnableOtherButton (_T("其它...")); 
			pColorProp->EnableAutomaticButton (_T("缺省"),RGB(0, 0, 255)); 
			pGroup->AddSubItem (pColorProp); 
 
			pColorProp = new CBCGPColorProp (_T("对象填充色"),p->m_crBrush , NULL, _T("当前对象填充色")); 
			pColorProp->EnableOtherButton (_T("其它...")); 
			pColorProp->EnableAutomaticButton (_T("缺省"),RGB(255,255,255)); 
 
			if(p->DrawShape==ELLIPSE) pColorProp->Enable (FALSE);				 
			pGroup->AddSubItem (pColorProp); 
		} 
	} 
	m_wndPropList.AddProperty (pGroup); 
} 
 
void CPropertiesViewBar::OnComboSelChange() 
{ 
	CString str; 
	m_wndObjectCombo.GetWindowText (str); 
	if(str==_T("全局设置")) 
	{ 
		m_wndPropList.RemoveAll (); 
		InitPropList (); 
	} 
	else 
	{ 
		m_wndPropList.RemoveAll (); 
		CBCGPProp* pProp; 
		CBCGPProp* pGroup; 
		CBCGPColorProp* pColorProp; 
		pGroup = new CBCGPProp (_T("当前对象")); 
		CDraw * pdw=pDoc->pView->pDrawSelect; 
		if(pDoc->pView->isSelected && pdw!=NULL) 
		{			 
			if(pdw->IsKindOf (RUNTIME_CLASS(CCurve))) 
			{ 
				CCurve* p=(CCurve*)pdw; 
				pProp = new CBCGPProp (_T("对象笔粗"), (_variant_t)p->m_width,_T("当前对象画笔粗细(1-10)")); 
				pProp->EnableSpinControl (TRUE, 1, 10); 
				pGroup->AddSubItem (pProp); 
 
				pColorProp = new CBCGPColorProp (_T("对象颜色"),p->m_crColor, NULL, _T("当前对象画笔颜色")); 
				pColorProp->EnableOtherButton (_T("其它...")); 
				pColorProp->EnableAutomaticButton (_T("缺省"),RGB(0, 0, 255)); 
				pGroup->AddSubItem (pColorProp); 
			} 
			if(pdw->IsKindOf (RUNTIME_CLASS(CLine))) 
			{ 
				CLine* p=(CLine*)pdw; 
				pProp = new CBCGPProp (_T("对象笔粗"), (_variant_t)p->m_width,_T("当前对象画笔粗细(1-10)")); 
				pProp->EnableSpinControl (TRUE, 1, 10); 
				pGroup->AddSubItem (pProp); 
 
				pColorProp = new CBCGPColorProp (_T("对象颜色"),p->m_crColor, NULL, _T("当前对象画笔颜色")); 
				pColorProp->EnableOtherButton (_T("其它...")); 
				pColorProp->EnableAutomaticButton (_T("缺省"),RGB(0, 0, 255)); 
				pGroup->AddSubItem (pColorProp); 
			} 
			if(pdw->IsKindOf (RUNTIME_CLASS(CText))) 
			{ 
				CText* p=(CText*)pdw; 
				pProp = new CBCGPProp (_T("对象文字"), (_variant_t)p->m_strText,_T("当前对象的文字内容")); 
				pGroup->AddSubItem (pProp); 
				pGroup->AddSubItem (new CBCGPFontProp (_T("对象字体"),p->m_lf, CF_EFFECTS | CF_SCREENFONTS, _T("当前对象所使用的字体"))); 
			} 
			if(pdw->IsKindOf (RUNTIME_CLASS(CRectangle))) 
			{ 
				CRectangle * p=(CRectangle *) pdw; 
				pProp = new CBCGPProp (_T("对象笔粗"), (_variant_t)p->m_width,_T("当前对象画笔粗细(1-10)")); 
				pProp->EnableSpinControl (TRUE, 1, 10); 
				pGroup->AddSubItem (pProp); 
 
				pColorProp = new CBCGPColorProp (_T("对象颜色"),p->m_crPen, NULL, _T("当前对象画笔颜色")); 
				pColorProp->EnableOtherButton (_T("其它...")); 
				pColorProp->EnableAutomaticButton (_T("缺省"),RGB(0, 0, 255)); 
				pGroup->AddSubItem (pColorProp); 
 
				pColorProp = new CBCGPColorProp (_T("对象填充色"),p->m_crBrush, NULL, _T("当前对象填充色")); 
				pColorProp->EnableOtherButton (_T("其它...")); 
				pColorProp->EnableAutomaticButton (_T("缺省"),RGB(255,255,255)); 
 
				if(p->DrawShape==RECTANGLE || p->DrawShape==ROUNDRECT) pColorProp->Enable (FALSE);				 
				pGroup->AddSubItem (pColorProp); 
			} 
			if(pdw->IsKindOf (RUNTIME_CLASS(CEllipse))) 
			{ 
				CEllipse* p=(CEllipse *) pdw; 
				pProp = new CBCGPProp (_T("对象笔粗"), (_variant_t)p->m_width,_T("当前对象画笔粗细(1-10)")); 
				pProp->EnableSpinControl (TRUE, 1, 10); 
				pGroup->AddSubItem (pProp); 
 
				pColorProp = new CBCGPColorProp (_T("对象颜色"),p->m_crPen, NULL, _T("当前对象画笔颜色")); 
				pColorProp->EnableOtherButton (_T("其它...")); 
				pColorProp->EnableAutomaticButton (_T("缺省"),RGB(0, 0, 255)); 
				pGroup->AddSubItem (pColorProp); 
 
				pColorProp = new CBCGPColorProp (_T("对象填充色"),p->m_crBrush , NULL, _T("当前对象填充色")); 
				pColorProp->EnableOtherButton (_T("其它...")); 
				pColorProp->EnableAutomaticButton (_T("缺省"),RGB(255,255,255)); 
 
				if(p->DrawShape==ELLIPSE) pColorProp->Enable (FALSE);				 
				pGroup->AddSubItem (pColorProp); 
			} 
		} 
		m_wndPropList.AddProperty (pGroup); 
	} 
}