예제 #1
0
//creates the appropriate controls for a property
void CPropertyWnd::CreatePropertyControls(CPackerProperty* pProp, uint32 nProp, uint32 nID, const CRect& rOrigArea)
{
	ASSERT(pProp);

	//flags for all controls
	DWORD nBaseFlags = WS_CHILD | WS_VISIBLE | WS_TABSTOP;

	//a working area rectangle
	CRect rArea(rOrigArea);

	switch(pProp->GetType())
	{
	case PROPERTY_REAL:
		{
			//create the edit box for editing the number
			CEdit* pNewEdit = new CEdit;
			if(pNewEdit)
			{
				pNewEdit->CreateEx(WS_EX_CLIENTEDGE, "Edit", "", nBaseFlags | ES_AUTOHSCROLL, 
									rArea.left, rArea.top, rArea.Width(), rArea.Height(),
									GetSafeHwnd(), (HMENU)nID);

				CPackerRealProperty* pReal = (CPackerRealProperty*)pProp;

				//set the default
				CString sText;
				sText.Format((pReal->IsInteger()) ? "%.0f" : "%.2f", pReal->GetValue());
				pNewEdit->SetWindowText(sText);

				//save it in the list
				m_pPropControl[nProp][0] = pNewEdit;

				//setup the tooltip
				m_ToolTip.AddWindowTool(pNewEdit, pProp->GetHelp());
			}
		}
		break;
	case PROPERTY_STRING:
		{
			CPackerStringProperty* pString = (CPackerStringProperty*)pProp;

			//rectangle for the edit control
			CRect rEditArea(rArea);

			//see if this is going to be a filename
			if(pString->IsFilename())
			{
				rEditArea.DeflateRect(0, 0, BROWSE_BUTTON_WIDTH, 0);
			}

			//create the edit box for editing the string
			CEdit* pNewEdit = new CEdit;
			if(pNewEdit)
			{
				pNewEdit->CreateEx(WS_EX_CLIENTEDGE, "Edit", "", nBaseFlags | ES_AUTOHSCROLL, 
									rEditArea.left, rEditArea.top, 
									rEditArea.Width(), rEditArea.Height(),
									GetSafeHwnd(), (HMENU)nID);

				//set the default
				pNewEdit->SetWindowText(pString->GetValue());

				//save it in the list
				m_pPropControl[nProp][0] = pNewEdit;
			}

			//setup the tooltip
			m_ToolTip.AddWindowTool(pNewEdit, pProp->GetHelp());

			//create the browse button if needed
			if(pString->IsFilename())
			{
				CButton* pNewButton = new CButton;
				if(pNewButton)
				{
					pNewButton->Create("...", nBaseFlags, CRect(rEditArea.right, rArea.top, rArea.right, rArea.bottom), this, nID + 1);
					m_pPropControl[nProp][1] = pNewButton;

					//setup the button's tooltip
					m_ToolTip.AddWindowTool(pNewButton, IDS_TOOLTIP_BROWSE_FOR_FILE);
				}					
			}
		}
		break;
	case PROPERTY_ENUM:
		{
			//create the combo box for the drop down of selections
			CComboBox* pNewCombo = new CComboBox;
			if(pNewCombo)
			{
				CPackerEnumProperty* pEnum = (CPackerEnumProperty*)pProp;

				CRect rFullArea(rArea);
				rFullArea.InflateRect(0, 0, 0, PROPERTY_HEIGHT * min(3, pEnum->GetNumItems()));

				pNewCombo->Create(nBaseFlags | CBS_DROPDOWNLIST, rFullArea, this, nID);

				//add the items
				for(uint32 nCurrItem = 0; nCurrItem < pEnum->GetNumItems(); nCurrItem++)
				{
					pNewCombo->InsertString(nCurrItem, pEnum->GetItem(nCurrItem));
				}

				//select the item
				pNewCombo->SetCurSel(pEnum->GetSelection());

				//save it in the list
				m_pPropControl[nProp][0] = pNewCombo;

				//setup the tooltip
				m_ToolTip.AddWindowTool(pNewCombo, pProp->GetHelp());
			}
		}
		break;
	case PROPERTY_BOOL:
		{
			//create a check box for checking/unchecking items
			CButton* pNewButton = new CButton;
			if(pNewButton)
			{
				pNewButton->Create("", nBaseFlags | BS_AUTOCHECKBOX, rArea, this, nID); 
				m_pPropControl[nProp][0] = pNewButton;

				//init the default value
				CPackerBoolProperty* pBoolProp = (CPackerBoolProperty*)pProp;
				pNewButton->SetCheck(pBoolProp->GetValue() ? 1 : 0);
		
				//setup the tooltip
				m_ToolTip.AddWindowTool(pNewButton, pProp->GetHelp());
			}
		}
		break;
	case PROPERTY_INTERFACE:
		{
			CPackerInterfaceProperty* pIntf = (CPackerInterfaceProperty*)pProp;

			DWORD nTextStyle	= 0;
			bool  bDisplayName	= true;

			switch(pIntf->GetInterfaceType())
			{
			case CPackerInterfaceProperty::TEXT_LEFT:
				nTextStyle = SS_LEFT;
				break;
			case CPackerInterfaceProperty::TEXT_RIGHT:
				nTextStyle = SS_RIGHT;
				break;
			case CPackerInterfaceProperty::TEXT_CENTER:
				nTextStyle = SS_CENTER;
				break;
			case CPackerInterfaceProperty::SEPARATOR:
				nTextStyle = SS_GRAYFRAME;
				bDisplayName = false;
				rArea.bottom -= rArea.Height() * 3 / 4;
				break;
			default:
				break;
			}

			if(pIntf->GetInterfaceType() != CPackerInterfaceProperty::BLANK)
			{
				CStatic* pStatic = new CStatic;
				if(pStatic)
				{
					if(bDisplayName)
					{
						rArea.top = rArea.bottom - GetAbsoluteFontHeight();
					}

					pStatic->Create(bDisplayName ? pProp->GetName() : "", nBaseFlags | nTextStyle, rArea, this, nID); 
					m_pPropControl[nProp][0] = pStatic;
				}
			}
		}
		break;
	default:
		ASSERT(FALSE);
		break;
	}

	//setup the fonts for all the new properties
	for(uint32 nCurrCtrl = 0; nCurrCtrl < MAX_CONTROLS_PER_PROP; nCurrCtrl++)
	{
		if(m_pPropControl[nProp][nCurrCtrl])
		{
			m_pPropControl[nProp][nCurrCtrl]->SetFont(&m_Font);
		}
	}
}
예제 #2
0
BOOL CFormulaAddDialog::OnInitDialog() 
{
	CDialog::OnInitDialog();

    uiutils::setdlgsize(this, &m_ButtonCancel, &m_ButtonOK);

	queryMaterials();
	
	int mCount = this->materialCount;
	// TODO: Add extra initialization here
	int comboboxID = 1000;
	
	int comboLeft = 50;
	int comboTop = 100;
	int comboWidth =170;
	int comboBottom = 330;
	
	int editHeigh = 24;
	int editWidth = 100;
	int editID = 2000;
	int editLeft = 250;
	int editTop = 100;
	
	for(int i = 0; i < mCount ; ++i)
	{
		CString mTitle, pTitle;
		mTitle = (i >= 10) ? "材料名" : "";
		pTitle = (i >= 10) ? "百分比" : "";

		//m_MaterialSecond.SetWindowText(mTitle);
		//m_PercentageSecond.SetWindowText(pTitle);

		if (i == 10)
		{
			comboLeft = 400;
			editLeft = 620;
			comboTop = 100;
			editTop = 100;
		}
		
		CComboBox* testCombox = new CComboBox;
		testCombox->Create(CBS_DROPDOWNLIST|WS_VISIBLE |WS_VSCROLL ,
			CRect(comboLeft,comboTop,comboLeft + comboWidth,comboBottom),  this, comboboxID++);
		
		for (size_t j = 0; j < materialVector.size(); ++j)
		{
			testCombox->AddString(materialVector[j]);
		}

		testCombox->SetFont(SingletonHelper::getInstance()->defaultFont, TRUE);
		testCombox->SetCurSel(0);
		testCombox->ShowWindow(SW_SHOW);
		comboboxVector.push_back(testCombox);
		
		CEdit* testEdit = new CEdit;
		testEdit->CreateEx(WS_EX_CLIENTEDGE, "Edit", "", WS_CHILD|WS_VISIBLE|ES_LEFT,   
			CRect(editLeft,editTop,editLeft + editWidth,editTop + editHeigh), this, editID);
		testEdit->ShowWindow(SW_SHOW);
		editVector.push_back(testEdit);

		comboTop += 50;
		comboBottom += 50;
		editTop += 50;
	}
	
	return TRUE;  // return TRUE unless you set the focus to a control
	// EXCEPTION: OCX Property Pages should return FALSE
}