//*******************************************************************************
CBCGPChartLegendCtrl* CBCGPChartView::EnableAdvancedLegend(BOOL bEnable, 
		BCGPChartLayout::LegendPosition position,
		BOOL bIsVerticalLayout,
		CBCGPChartLegendVisualObject::LegendAlignment horzAlign,
		CBCGPChartLegendVisualObject::LegendAlignment vertAlign,
		CRuntimeClass* pLegendRTC)
{
	SetRedraw(FALSE);

	if (m_pWndLegendCtrl->GetSafeHwnd() != NULL)
	{
		m_pWndLegendCtrl->DestroyWindow();
	}

	if (m_pWndLegendCtrl != NULL)
	{
		delete m_pWndLegendCtrl;
		m_pWndLegendCtrl = NULL;
	}

	if (bEnable)
	{
		m_pWndLegendCtrl = CreateLegend();

		if (pLegendRTC != NULL)
		{
			m_pWndLegendCtrl->CreateCustomLegend(pLegendRTC);
		}

		m_pWndLegendCtrl->Create(CBCGPRect(), this, ID_LEGEND_CTRL);

		CBCGPChartLegendVisualObject* pLegend = m_pWndLegendCtrl->GetLegend();
		pLegend->SetHorizontalAlignment(horzAlign, FALSE);
		pLegend->SetVerticalAlignment(vertAlign, FALSE);
		pLegend->SetVerticalLayout(bIsVerticalLayout, FALSE);

		pLegend->AddRelatedChart(GetChart());

		m_legendPosition = position;
	}

	CRect rect;
	GetClientRect(rect);
	AdjustLayout(rect.Width(), rect.Height());

	SetRedraw(TRUE);
	RedrawWindow(NULL, NULL, RDW_INVALIDATE | RDW_UPDATENOW | RDW_ERASE | RDW_ALLCHILDREN);

	return m_pWndLegendCtrl;

}
Пример #2
0
void CLegendDisplay::FileImport(LPCTSTR lpFilename)
{
	//m_FileName=lpFilename;
//------------------------------------------------------
	char str2[255];
	GetPrivateProfileString("ͼÀý","ͼֽÃû³Æ","",str2,255,lpFilename);

	CADMText* pMText;
	pMText=new CADMText();
	m_pGraphics->m_Entities.Add((CObject*)pMText);
	pMText->m_nLayer=m_pLayerGroup->indexOf("0");
	pMText->m_Align=AD_MTEXT_ATTACH_TOPCENTER;
	pMText->m_Text=str2;
	strcpy(pMText->m_Font,ENFONTNAME);
	pMText->m_Height=6;
	//pMText->m_Width=3;
	pMText->m_Location.x=m_FrameLeft+m_FrameWidth/2;
	pMText->m_Location.y=m_FrameTop-10;
//------------------------------------------------------
	int maxLen=10000;
	char str[10000];
	GetPrivateProfileString("ͼÀý","ÆÊÃæͼͼÀý","",str,maxLen,lpFilename);

	char* pszTemp = strtok(str, ",");
	int curRow=0,curCol=0;
	while(pszTemp)
	{
		CreateLegend(pszTemp,m_LegendRectLeft+m_LegendWidth*curCol+m_LegendSpaceX*curCol,m_LegendRectTop-m_LegendHeight*curRow-m_LegendSpaceY*curRow);
		curCol++;
		if(curCol==m_LegendRowNum){curCol=0;curRow++;}
		pszTemp=strtok(NULL, ",");
	}

	for (int i=0; i<m_pGraphics->m_Entities.GetSize();i++)
	{
		CADEntity* pEntity=(CADEntity*)m_pGraphics->m_Entities.GetAt(i);
		if (pEntity->GetType() != AD_ENT_HATCH)continue; 
		CADLayer* pLayer=m_pLayerGroup->GetLayer(pEntity->m_nLayer);
		if(pLayer==NULL)
		{
			m_pGraphics->m_Entities.RemoveAt(i);
			continue;
		}
		if (strcmp(pLayer->m_Name,"0")!=0)continue;
		if (!CreateHatch((CADHatch*)pEntity))
		{
			m_pGraphics->m_Entities.RemoveAt(i);
			continue;		
		}
	}
	GetPrivateProfileString("ͼÀý","ƽÃæͼͼÀý","",str,maxLen,lpFilename);
	pszTemp = strtok(str, ",");
	while(pszTemp)
	{
		CreateLegend_Layout(pszTemp,m_LegendRectLeft+m_LegendWidth*curCol+m_LegendSpaceX*curCol,m_LegendRectTop-m_LegendHeight*curRow-m_LegendSpaceY*curRow);
		curCol++;
		if(curCol==m_LegendRowNum){curCol=0;curRow++;}
		pszTemp=strtok(NULL, ",");
	}
	CreateChartFooter(lpFilename);
}