Esempio n. 1
0
BOOL CIconImgList::PickUpGroups( MSXML2::IXMLDOMElementPtr& piGroup, int& nIndex)
{
    MSXML2::IXMLDOMNodeListPtr piGroupList;
    piGroupList = piGroup->GetchildNodes();

    MSXML2::IXMLDOMElementPtr piNode;
    MSXML2::IXMLDOMElementPtr piChild;

    int nParent = nIndex;

    _bstr_t cBstr;
    _variant_t cVariant;
    long lCount = piGroupList->Getlength();
    for( long lIndex = 0; lIndex < lCount; lIndex++)
    {
        piNode = piGroupList->Getitem( lIndex);
        if( _bstr_t( _T( "GROUP")) == piNode->GetbaseName())
        {
            cBstr = piNode->getAttribute( _bstr_t( _T( "TITLE")));
            cVariant = piNode->getAttribute( _bstr_t( _T( "ENABLE")));
            cVariant.ChangeType( VT_BOOL);

            m_astGroupData[ nIndex] = ( GROUPDATA*)malloc( sizeof( GROUPDATA) + ( sizeof( TCHAR) * ( cBstr.length() + 1)));

            m_astGroupData[ nIndex]->nParent = nParent;
            if( 1 <= nIndex)
            {
                if( FALSE == m_astGroupData[ nParent]->blEnable)
                {
                    cVariant.boolVal = VARIANT_FALSE;
                }
            }
            m_astGroupData[ nIndex]->blEnable = ( VARIANT_FALSE == cVariant.boolVal) ? FALSE : TRUE;
            lstrcpy( m_astGroupData[ nIndex]->szName, cBstr);

            nIndex++;

            PickUpGroups( piNode, nIndex);
        }
        else if( _bstr_t( _T( "ITEM")) == piNode->GetbaseName())
        {
            cVariant = piNode->getAttribute( _bstr_t( _T( "REF")));
            cVariant.ChangeType( VT_I4);
            for( int nIndex = 0; nIndex < m_nEnableCount; nIndex++)
            {
                if( cVariant.intVal == ( m_astIconStatus[ nIndex].nID + 1))
                {
                    m_astIconStatus[ nIndex].nParent = nParent;
                }
            }
        }
    }

    return TRUE;
}
Esempio n. 2
0
BOOL CIconImgList::LoadIcons( MSXML2::IXMLDOMDocumentPtr& piDocument)
{
    BOOL blResult = FALSE;

    MSXML2::IXMLDOMElementPtr piRoot;
    piRoot = piDocument->GetdocumentElement();
    if( NULL == piRoot)
    {
        return FALSE;
    }

    MSXML2::IXMLDOMElementPtr piGroups;
    piGroups = piRoot->selectSingleNode( _bstr_t( _T( "GROUPS")));


    MSXML2::IXMLDOMElementPtr piIcons;
    piIcons = piRoot->selectSingleNode( _bstr_t( _T( "ICONS")));
    if( NULL == piIcons)
    {
        return FALSE;
    }

    MSXML2::IXMLDOMNodeListPtr piIconsList;
    piIconsList = piIcons->GetchildNodes();
    if( NULL == piIconsList)
    {
        return FALSE;
    }

    long lIconsCount;
    lIconsCount = piIconsList->Getlength();
    if( 0 >= lIconsCount)
    {
        return FALSE;
    }

    m_nCountExtend = lIconsCount;
    if( 0 < m_nCountExtend)
    {
        m_astIconStatus = new ICONSTATUS[ m_nCountExtend];
        if( NULL != m_astIconStatus)
        {
            /*
            ZeroMemory( m_astIconStatus, sizeof( ICONSTATUS) * m_nCountExtend);
            */
            for( int nIndex = 0; nIndex < m_nCountExtend; nIndex++)
            {
                m_astIconStatus[ m_nEnableCount].nID = 0;
                m_astIconStatus[ m_nEnableCount].blEnable = FALSE;
                m_astIconStatus[ m_nEnableCount].nParent = 0;
                m_astIconStatus[ m_nEnableCount].nPosition = 0;
                m_astIconStatus[ m_nEnableCount].cStrIconName.Empty();
            }

            int nHeight = ( m_nCountExtend / 10) + ( ( m_nCountExtend % 10) ? 1 : 0);

            m_hBmpExtend = ::CreateBitmap( _ICON_WIDTH * 10, _ICON_HEIGHT * nHeight, 1, 1, NULL);
            HDC hExtDC = ::CreateCompatibleDC( NULL);
            HDC hDefDC = ::CreateCompatibleDC( NULL);
            HDC hWorkDC = ::CreateCompatibleDC( NULL);
            HBITMAP hOldExtBmp = ( HBITMAP)::SelectObject( hExtDC, m_hBmpExtend);
            HBITMAP hOldDefBmp = ( HBITMAP)::SelectObject( hDefDC, m_hBmpDefault);

            m_nEnableCount = 0;
            CString cStrEntry;
            LPBYTE lpabyData;
            TCHAR szWork[ 64];
            MSXML2::IXMLDOMElementPtr piIcon;
            MSXML2::IXMLDOMElementPtr piImage;
            MSXML2::IXMLDOMElementPtr piParent;
            _variant_t cVariant;
            _bstr_t cBstr;
            CString strTitle;
            for( int nIndex = 0; nIndex < m_nCountExtend; nIndex++)
            {
                cVariant = VARIANT_TRUE;
                if( NULL != piGroups)
                {
                    wsprintf( szWork, _T( "//ITEM[@REF='%d']"), nIndex + 1);
                    piIcon = piGroups->selectSingleNode( _bstr_t( szWork));
                    if( NULL != piIcon)
                    {
                        cVariant = piIcon->getAttribute( _bstr_t( _T( "ENABLE")));
                        if( cVariant.vt != VT_NULL)
                        {
                            VariantChangeType( &cVariant, &cVariant, 0, VT_BOOL);
                        }
                        else
                        {
                            cVariant = VARIANT_TRUE;
                        }
                    }
                }

                if( VARIANT_FALSE != cVariant.boolVal)
                {
                    wsprintf( szWork, _T( "//ICON[@ID='%d']"), nIndex + 1);
                    piIcon = piRoot->selectSingleNode( _bstr_t( szWork));
                    if( NULL == piIcon)
                    {
                        continue;
                    }

                    cVariant = piIcon->getAttribute( _bstr_t( _T( "TITLE")));
                    if( cVariant.vt != VT_NULL)
                    {
                        strTitle = cVariant;
                    }
                    else
                    {
                        strTitle = _T( "NoTitle");
                    }

                    piImage = piIcon->selectSingleNode( _bstr_t( _T( "IMAGE")));
                    if( NULL == piImage)
                    {
                        continue;
                    }
                    cBstr = piImage->Gettext();
                    int nSize = Base64Decode( NULL, 0, cBstr);
                    lpabyData = new BYTE [ nSize];
                    Base64Decode( lpabyData, nSize, cBstr);

                    HBITMAP hWork = ::CreateBitmap( _ICON_WIDTH, _ICON_HEIGHT, 1, 1, lpabyData);

                    delete [] lpabyData;

                    HBITMAP hOldWorkBmp = ( HBITMAP)::SelectObject( hWorkDC, hWork);
                    ::BitBlt( hExtDC, ( nIndex % 10) * _ICON_WIDTH, ( nIndex / 10) * _ICON_HEIGHT, _ICON_WIDTH, _ICON_HEIGHT, hWorkDC, 0, 0, SRCCOPY);
                    ::SelectObject( hWorkDC, hOldWorkBmp);
                    ::DeleteObject( hWork);
                    m_astIconStatus[ m_nEnableCount].nID = nIndex;
                    m_astIconStatus[ m_nEnableCount].blEnable = TRUE;
                    m_astIconStatus[ m_nEnableCount].cStrIconName = strTitle;

                    m_nEnableCount++;
                    continue;
                }
                ::BitBlt( hExtDC, ( nIndex % 10) * _ICON_WIDTH, ( nIndex / 10) * _ICON_HEIGHT, _ICON_WIDTH, _ICON_HEIGHT, hDefDC, ( COUNT_DEFAULTICON) * _ICON_WIDTH, 0, SRCCOPY);
            }

            ::SelectObject( hExtDC, hOldExtBmp);
            ::SelectObject( hDefDC, hOldDefBmp);

            ::DeleteDC( hExtDC);
            ::DeleteDC( hDefDC);
            ::DeleteDC( hWorkDC);

            m_astIconStatus4Menu = new ICONSTATUS*[ m_nEnableCount];
            if( m_astIconStatus4Menu)
            {
                for( int nIndex = 0; nIndex < m_nEnableCount; nIndex++)
                {
                    m_astIconStatus4Menu[ nIndex] = &m_astIconStatus[ nIndex];
                }
                qsort( m_astIconStatus4Menu, m_nEnableCount, sizeof( ICONSTATUS*), IconCompare);

                blResult = TRUE;
            }
        }
    }

    return blResult;
}