Esempio n. 1
0
BOOL SListBoxEx::SetItemCount(int nItems,LPCTSTR pszXmlTemplate)
{
    if(m_arrItems.GetCount()!=0) return FALSE;
    pugi::xml_document xmlDoc;
    pugi::xml_node xmlTemplate = m_xmlTempl.child(L"template");
    if(pszXmlTemplate)
    {
        SStringA strUtf8=S_CT2A(pszXmlTemplate,CP_UTF8);
        if(!xmlDoc.load_buffer((LPCSTR)strUtf8,strUtf8.GetLength(),pugi::parse_default,pugi::encoding_utf8)) return FALSE;
        xmlTemplate = xmlDoc.first_child();
    }
    if(!xmlTemplate) 
        return FALSE;
    
    
    m_arrItems.SetCount(nItems);
    for(int i=0;i<nItems;i++)
    {
        SItemPanel *pItemObj=SItemPanel::Create(this,xmlTemplate,this);
        pItemObj->Move(CRect(0,0,m_rcClient.Width(),m_nItemHei));
        if(m_pItemSkin) pItemObj->SetSkin(m_pItemSkin);
        pItemObj->SetColor(m_crItemBg,m_crItemSelBg);
        m_arrItems[i] = pItemObj;
        pItemObj->SetItemIndex(i);
    }
    
    CRect rcClient;
    SWindow::GetClientRect(&rcClient);
    CSize szView(rcClient.Width(),GetItemCount()*m_nItemHei);
    if(szView.cy>rcClient.Height()) szView.cx-=m_nSbWid;
    SetViewSize(szView);

    return TRUE;
}
Esempio n. 2
0
void SQrCtrl::CreateQrImg( SStringT strContent )
{
	CQR_Encode qrEncode;
	int nLevel = 3;
	int nVersion = 0;
	bool bAutoExtent = true;
	int nMaskingNo = -1;
	SStringA strContentA = S_CT2A(strContent, CP_UTF8);
	if (qrEncode.EncodeData(nLevel, nVersion, bAutoExtent, nMaskingNo, strContentA, strContentA.GetLength()))
	{

		if (m_pSkin == NULL)
		{
			int qrSize = qrEncode.m_nSymbleSize + (QR_MARGIN * 2);
			CAutoRefPtr<IBitmap> bmp;
			GETRENDERFACTORY->CreateBitmap(&bmp);
			bmp->Init(qrSize, qrSize);
			LPDWORD pBits = (LPDWORD)bmp->LockPixelBits();
			memset(pBits, 0xFF, qrSize*qrSize * 4);
			int nLineWid = qrSize;
			LPDWORD pLine = pBits + QR_MARGIN*nLineWid;
			for (int i = 0; i < qrEncode.m_nSymbleSize; i++)
			{
				LPDWORD pLineData = pLine + QR_MARGIN;
				for (int j = 0; j < qrEncode.m_nSymbleSize; j++)
				{
					if (qrEncode.m_byModuleData[i][j])
					{
						pLineData[j] = RGBA(0, 0, 0, 255);
					}
				}
				pLine += qrSize;
			}
			bmp->UnlockPixelBits(pBits);
			SetImage(bmp);
		}
		else
		{
			int qrSize = qrEncode.m_nSymbleSize + 2;
			CAutoRefPtr<IBitmap> bmp;
			GETRENDERFACTORY->CreateBitmap(&bmp);
			SIZE skinSize = m_pSkin->GetSkinSize();
			CRect rcWind = GetWindowRect();

			bmp->Init(rcWind.Width(), rcWind.Height());

			CAutoRefPtr<IBitmap> qrbmp;
			GETRENDERFACTORY->CreateBitmap(&qrbmp);
			qrbmp->Init(qrSize, qrSize);
			LPDWORD pBits = (LPDWORD)qrbmp->LockPixelBits();
			memset(pBits, 0x00, qrSize*qrSize * 4);
			int nLineWid = qrSize;
			LPDWORD pLine = pBits + nLineWid;
			for (int i = 0; i < qrEncode.m_nSymbleSize; i++)
			{
				LPDWORD pLineData = pLine + 1;
				for (int j = 0; j < qrEncode.m_nSymbleSize; j++)
				{
					if (qrEncode.m_byModuleData[i][j])
					{
						pLineData[j] = RGBA(0xFF, 0xFF, 0xFF, 0xFF);
					}
				}
				pLine += qrSize;
			}
			qrbmp->UnlockPixelBits(pBits);
			MakeCacheApha(m_pSkin, bmp, qrbmp);
			SetImage(bmp);
		}
	}
}