示例#1
0
void CLegoBrickPropertiesWnd::Update()
{
	m_wndPropList.RemoveAll();

	CMainFrame* pFrame = (CMainFrame*) AfxGetMainWnd();
	HTREEITEM hSelected = pFrame->GetClassView()->GetTreeView()->GetSelectedItem();
	if (hSelected == NULL) {
		m_wndPropList.RedrawWindow();
		return;
	}

	CString str = pFrame->GetClassView()->GetTreeView()->GetItemText(hSelected);

	CString str1 = pFrame->GetClassView()->GetTreeView()->GetItemText(pFrame->GetClassView()->hRoot1);
	CString str2 = pFrame->GetClassView()->GetTreeView()->GetItemText(pFrame->GetClassView()->hRoot2);

	if (str == str1 || str == str2) {
		m_wndPropList.RedrawWindow();
		return;
	}

	LBInfoNode* pBrickNode = (LBInfoNode*)pFrame->GetClassView()->GetTreeView()->GetItemData(hSelected);
	BricksInfo* pBrick = &(pBrickNode->bi);

	CMFCPropertyGridProperty* pG = new CMFCPropertyGridProperty(_T("Lego"));
	pGroup = pG;

	int i;
	for (i=0; i<NUMOFBRICKTYPE; i++) {
		if (strmap[i].bt == pBrick->brick.type)
			break;
	}

	CMFCPropertyGridProperty* pT = new CMFCPropertyGridProperty(_T("brick type"), strmap[i].str, _T("brick type"));
	pPropType = pT;

	for (i=0; i<NUMOFBRICKTYPE; i++)
		pT->AddOption(strmap[i].str, TRUE);  //TRUE to add the list item only if it does not already exist; 


//	CClientDC dc(&m_wndPropList);
//	pT->OnDrawValue(&dc, NULL);




	pT->AllowEdit(FALSE);
	pG->AddSubItem(pT);

/*	
//	CMFCPropertyGridColorProperty *pC = new CMFCPropertyGridColorProperty(_T("Color"), RGB(255, 0, 0), NULL, _T("set LEGO brick color"));
	CMFCPropertyGridColorProperty *pC = new CMFCPropertyGridColorProperty(_T("Color"), pBrick->brick.color, NULL, _T("set LEGO brick color"));
	pPropColor = pC;

//	pC->AddOption(_T("Lego Color"), TRUE);	// no use
	pC->EnableOtherButton(_T("Other color"));

//	pC->EnableAutomaticButton(_T("Default"), ::GetSysColor(COLOR_3DFACE));
	pC->SetColor(RGB(255,0,0));
	pC->SetColumnsNumber(6);

//	pPropColor->EnableAutomaticButton(_T("預設"), ::GetSysColor(COLOR_3DFACE));
	pG->AddSubItem(pC);
*/

	CPHPropertyGridColorProperty *pPH;
	if (pBrick->brick.pLegoColor != NULL)
		pPH = new CPHPropertyGridColorProperty(_T("Color"), pBrick->brick.pLegoColor->rgb);
	else
		pPH = new CPHPropertyGridColorProperty(_T("Color"), pBrick->brick.color);
	pPropColor = pPH;
	pG->AddSubItem(pPH);



	CMFCPropertyGridProperty *pN = new CMFCPropertyGridProperty(_T("num bricks"), (_variant_t) pBrick->numBricks, _T("number of bricks: -1 for unlimited"));
	pPropNum = pN;
	pG->AddSubItem(pN);
	

	m_wndPropList.AddProperty(pG);
//	m_wndPropList.RedrawWindow();

	return;
}
示例#2
0
LRESULT CLegoBrickPropertiesWnd::OnPropertyChanged (WPARAM,LPARAM lParam)
{    
	CMFCPropertyGridProperty* pProp = (CMFCPropertyGridProperty*) lParam;

	//do something 
	CMainFrame* pFrame = (CMainFrame*) AfxGetMainWnd();
	HTREEITEM hSelected = pFrame->GetClassView()->GetTreeView()->GetSelectedItem();
	LBInfoNode* pBrickNode = (LBInfoNode*)pFrame->GetClassView()->GetTreeView()->GetItemData(hSelected);

	CString str;
	if (pProp == pPropType) {
		CString strType = (LPCTSTR)(_bstr_t)pProp->GetValue();
		for (int i=0; i<NUMOFBRICKTYPE; i++) {
			if (strType == strmap[i].str)
				pBrickNode->bi.brick.type = strmap[i].bt;
		}

		int idxImage, idxSelImage;

		CViewTree* pTreeCtrl = pFrame->GetClassView()->GetTreeView();
		pTreeCtrl->GetItemImage(hSelected, idxImage, idxSelImage);
		DWORD_PTR data = pTreeCtrl->GetItemData(hSelected);

		str = pFrame->GetClassView()->MakeLegoBrickString(&(pBrickNode->bi));

		HTREEITEM hNewItem;	

		// notype
		if (pBrickNode->bi.brick.type == NOTYPE) {
			hNewItem = pTreeCtrl->InsertItem(str, idxImage, idxSelImage,
				TVI_ROOT, TVI_LAST);
			pTreeCtrl->SetItemData(hNewItem, data);
		}

		// one row brick
		else if (pBrickNode->bi.brick.type >= ONE_BY_ONE && pBrickNode->bi.brick.type <= ONE_BY_TWELVE) {
			hNewItem = pTreeCtrl->InsertItem(str, idxImage, idxSelImage, 
				pFrame->GetClassView()->hRoot1, TVI_SORT);
			pTreeCtrl->SetItemData(hNewItem, data);
			pTreeCtrl->Expand(pFrame->GetClassView()->hRoot1, TVE_EXPAND);
		}
		// two row brick
		else {
			hNewItem = pTreeCtrl->InsertItem(str, idxImage, idxSelImage, 
				pFrame->GetClassView()->hRoot2, TVI_SORT);
			pTreeCtrl->SetItemData(hNewItem, data);
			pTreeCtrl->Expand(pFrame->GetClassView()->hRoot2, TVE_EXPAND);
		}
		pTreeCtrl->DeleteItem(hSelected);
		pTreeCtrl->SelectItem(hNewItem);
	
//		pFrame->GetClassView()->GetTreeView()->SetItemText(hSelected, str);
	}

	if (pProp == pPropColor) {
//		pBrickNode->bi.brick.color = ((CMFCPropertyGridColorProperty*)pProp)->GetColor();
		pBrickNode->bi.brick.color = ((CPHPropertyGridColorProperty*)pProp)->GetColor();

		// Get LEGO Color, if NULL -> Not a LEGO color
		pBrickNode->bi.brick.pLegoColor = ((CPHPropertyGridColorProperty*)pProp)->GetLegoColor();


		CBitmap bmp;
		BYTE bits[960];		// typedef unsigned char BTTE;   4*16*15 = 960
		BYTE bits2[960];	// for selected
		pFrame->GetClassView()->BuildTwoBitsBlocks(pBrickNode->bi.brick.color, bits, bits2);
			
		bmp.CreateBitmap(16, 15, 1, 32, bits /*Points to a short-integer array */);
		int idxImage, idxSelImage;
		pFrame->GetClassView()->GetTreeView()->GetItemImage(hSelected, idxImage, idxSelImage);
		pFrame->GetClassView()->GetImageList()->Replace(idxImage, &bmp, NULL); 

		bmp.SetBitmapBits(960, bits2);
		pFrame->GetClassView()->GetImageList()->Replace(idxSelImage, &bmp, NULL); 

		pFrame->GetClassView()->GetTreeView()->SetImageList(
			pFrame->GetClassView()->GetImageList(), TVSIL_NORMAL);

		str = pFrame->GetClassView()->MakeLegoBrickString(&(pBrickNode->bi));
		pFrame->GetClassView()->GetTreeView()->SetItemText(hSelected, str);
	}

	if (pProp == pPropNum) {
		pBrickNode->bi.numBricks = (int) pProp->GetValue().intVal;

		str = pFrame->GetClassView()->MakeLegoBrickString(&(pBrickNode->bi));
		pFrame->GetClassView()->GetTreeView()->SetItemText(hSelected, str);
	}
	if (&(pBrickNode->bi) != NULL)
		pBrickNode->bi.brick.SetID();

	return 0;   
}