📄 skin.cpp
字号:
//////////////////////////////////////////////////////////////////////
// CSkin toolbars
BOOL CSkin::CreateToolBar(LPCTSTR pszName, CCoolBarCtrl* pBar)
{
if ( pszName == NULL ) return FALSE;
for ( CWnd* pChild = pBar->GetWindow( GW_CHILD ) ; pChild ; pChild = pChild->GetNextWindow() )
{
pChild->ShowWindow( SW_HIDE );
}
CString strPath = pszName;
strPath += _T(".Toolbar");
if ( m_pWatermarks.Lookup( strPath, strPath ) )
{
HBITMAP hBitmap = LoadBitmap( strPath );
pBar->SetWatermark( hBitmap );
}
else
{
pBar->SetWatermark( NULL );
}
pBar->Clear();
LPCTSTR* pszModeSuffix = m_pszModeSuffix[ Settings.General.GUIMode ];
CCoolBarCtrl* pBase = NULL;
CString strName( pszName );
for ( int nModeTry = 0 ; pszModeSuffix[ nModeTry ] ; nModeTry++ )
{
if ( m_pToolbars.Lookup( strName + pszModeSuffix[ nModeTry ], (void*&)pBase ) ) break;
}
if ( pBase != NULL )
{
pBar->Copy( pBase );
return TRUE;
}
else
{
return FALSE;
}
}
BOOL CSkin::LoadToolbars(CXMLElement* pBase)
{
for ( POSITION pos = pBase->GetElementIterator() ; pos ; )
{
CXMLElement* pXML = pBase->GetNextElement( pos );
if ( pXML->IsNamed( _T("toolbar") ) && ! CreateToolBar( pXML ) ) return FALSE;
}
return TRUE;
}
BOOL CSkin::CreateToolBar(CXMLElement* pBase)
{
CCoolBarCtrl* pBar = new CCoolBarCtrl();
for ( POSITION pos = pBase->GetElementIterator() ; pos ; )
{
CXMLElement* pXML = pBase->GetNextElement( pos );
if ( pXML->IsNamed( _T("button") ) )
{
if ( UINT nID = LookupCommandID( pXML ) )
{
CCoolBarItem* pItem = pBar->Add( nID, pXML->GetAttributeValue( _T("text") ) );
CString strTemp = pXML->GetAttributeValue( _T("colour") );
if ( strTemp.GetLength() == 6 )
{
int nRed, nGreen, nBlue;
_stscanf( strTemp.Mid( 0, 2 ), _T("%x"), &nRed );
_stscanf( strTemp.Mid( 2, 2 ), _T("%x"), &nGreen );
_stscanf( strTemp.Mid( 4, 2 ), _T("%x"), &nBlue );
pItem->m_crText = RGB( nRed, nGreen, nBlue );
}
strTemp = pXML->GetAttributeValue( _T("tip") );
if ( strTemp.GetLength() ) pItem->SetTip( strTemp );
strTemp = pXML->GetAttributeValue( _T("visible") );
if ( strTemp.GetLength() ) pItem->Show( FALSE );
}
}
else if ( pXML->IsNamed( _T("separator") ) )
{
pBar->Add( ID_SEPARATOR );
}
else if ( pXML->IsNamed( _T("rightalign") ) )
{
pBar->Add( ID_RIGHTALIGN );
}
else if ( pXML->IsNamed( _T("control") ) )
{
UINT nID, nWidth, nHeight = 0;
CString strTemp;
strTemp = pXML->GetAttributeValue( _T("id") );
if ( _stscanf( strTemp, _T("%lu"), &nID ) == 1 )
{
strTemp = pXML->GetAttributeValue( _T("width") );
if ( _stscanf( strTemp, _T("%lu"), &nWidth ) == 1 )
{
strTemp = pXML->GetAttributeValue( _T("height") );
_stscanf( strTemp, _T("%lu"), &nHeight );
pBar->Add( nID, nWidth, nHeight );
}
}
}
else if ( pXML->IsNamed( _T("label") ) )
{
CCoolBarItem* pItem = pBar->Add( 1, pXML->GetAttributeValue( _T("text") ) );
pItem->m_crText = 0;
pItem->SetTip( pXML->GetAttributeValue( _T("tip") ) );
}
}
CString strName = pBase->GetAttributeValue( _T("name") );
CCoolBarCtrl* pOld = NULL;
if ( m_pToolbars.Lookup( strName, (void*&)pOld ) && pOld ) delete pOld;
m_pToolbars.SetAt( strName, pBar );
return TRUE;
}
//////////////////////////////////////////////////////////////////////
// CSkin documents
BOOL CSkin::LoadDocuments(CXMLElement* pBase)
{
for ( POSITION posDoc = pBase->GetElementIterator() ; posDoc ; )
{
CXMLElement* pDoc = pBase->GetNextElement( posDoc );
if ( ! pDoc->IsNamed( _T("document") ) ) continue;
CString strName = pDoc->GetAttributeValue( _T("name") );
CXMLElement* pOld = NULL;
if ( m_pDocuments.Lookup( strName, (void*&)pOld ) ) delete pOld;
m_pDocuments.SetAt( strName, pDoc->Detach() );
}
return TRUE;
}
CXMLElement* CSkin::GetDocument(LPCTSTR pszName)
{
CXMLElement* pXML = NULL;
if ( m_pDocuments.Lookup( pszName, (void*&)pXML ) ) return pXML;
return NULL;
}
//////////////////////////////////////////////////////////////////////
// CSkin watermarks
HBITMAP CSkin::GetWatermark(LPCTSTR pszName)
{
CString strPath;
if ( m_pWatermarks.Lookup( pszName, strPath ) ) return LoadBitmap( strPath );
return NULL;
}
BOOL CSkin::GetWatermark(CBitmap* pBitmap, LPCTSTR pszName)
{
ASSERT( pBitmap != NULL );
if ( pBitmap->m_hObject != NULL ) pBitmap->DeleteObject();
HBITMAP hBitmap = GetWatermark( pszName );
if ( hBitmap != NULL ) pBitmap->Attach( hBitmap );
return ( hBitmap != NULL );
}
BOOL CSkin::LoadWatermarks(CXMLElement* pSub, const CString& strPath)
{
for ( POSITION posMark = pSub->GetElementIterator() ; posMark ; )
{
CXMLElement* pMark = pSub->GetNextElement( posMark );
if ( pMark->IsNamed( _T("watermark") ) )
{
CString strName = pMark->GetAttributeValue( _T("target") );
CString strFile = pMark->GetAttributeValue( _T("path") );
if ( strName.GetLength() && strFile.GetLength() )
{
strFile = strPath + strFile;
m_pWatermarks.SetAt( strName, strFile );
}
}
}
return TRUE;
}
//////////////////////////////////////////////////////////////////////
// CSkin list column translations
BOOL CSkin::Translate(LPCTSTR pszName, CHeaderCtrl* pCtrl)
{
CString strEdit;
if ( ! m_pLists.Lookup( pszName, strEdit ) ) return FALSE;
TCHAR szColumn[128];
HD_ITEM pColumn;
pColumn.mask = HDI_TEXT;
pColumn.pszText = szColumn;
pColumn.cchTextMax = 126;
for ( int nItem = 0 ; nItem < pCtrl->GetItemCount() ; nItem++ )
{
pCtrl->GetItem( nItem, &pColumn );
_tcscat( szColumn, _T("=") );
LPCTSTR pszFind = _tcsistr( strEdit, szColumn );
if ( pszFind )
{
pszFind += _tcslen( szColumn );
CString strNew = pszFind;
strNew = strNew.SpanExcluding( _T("|") );
_tcscpy( szColumn, strNew );
pCtrl->SetItem( nItem, &pColumn );
}
}
return TRUE;
}
BOOL CSkin::LoadListColumns(CXMLElement* pBase)
{
for ( POSITION pos = pBase->GetElementIterator() ; pos ; )
{
CXMLElement* pXML = pBase->GetNextElement( pos );
if ( ! pXML->IsNamed( _T("list") ) ) continue;
CString strName = pXML->GetAttributeValue( _T("name") );
if ( strName.IsEmpty() ) continue;
CString strEdit;
for ( POSITION posCol = pXML->GetElementIterator() ; posCol ; )
{
CXMLElement* pCol = pXML->GetNextElement( posCol );
if ( ! pCol->IsNamed( _T("column") ) ) continue;
CString strFrom = pCol->GetAttributeValue( _T("from") );
CString strTo = pCol->GetAttributeValue( _T("to") );
if ( strFrom.IsEmpty() || strTo.IsEmpty() ) continue;
if ( strEdit.GetLength() ) strEdit += '|';
strEdit += strFrom;
strEdit += '=';
strEdit += strTo;
}
m_pLists.SetAt( strName, strEdit );
}
return TRUE;
}
//////////////////////////////////////////////////////////////////////
// CSkin dialogs
BOOL CSkin::Apply(LPCTSTR pszName, CDialog* pDialog, UINT nIconID)
{
if ( nIconID )
{
HICON hIcon = CoolInterface.ExtractIcon( nIconID );
if ( hIcon == NULL )
{
hIcon = (HICON)LoadImage( AfxGetInstanceHandle(),
MAKEINTRESOURCE( nIconID ), IMAGE_ICON, 16, 16, 0 );
}
if ( hIcon != NULL ) pDialog->SetIcon( hIcon, FALSE );
}
CString strName;
if ( pszName == NULL )
strName = pDialog->GetRuntimeClass()->m_lpszClassName;
else
strName = pszName;
CWnd* pWnd = pDialog->GetWindow( GW_CHILD );
CString strCaption;
for ( int nCount = 0 ; pWnd ; nCount++, pWnd = pWnd->GetNextWindow() )
{
TCHAR szClass[3] = { 0, 0, 0 };
GetClassName( pWnd->GetSafeHwnd(), szClass, 3 );
strCaption += szClass;
}
if ( theApp.GetProfileInt( _T(""), _T("DialogScan"), FALSE ) )
{
USES_CONVERSION;
LPCSTR pszOutput;
CFile pFile;
if ( pFile.Open( _T("\\Dialog.xml"), CFile::modeReadWrite ) )
{
pFile.Seek( 0, CFile::end );
}
else if ( ! pFile.Open( _T("\\Dialog.xml"), CFile::modeWrite|CFile::modeCreate ) )
{
return FALSE;
}
pFile.Write( "<dialog name=\"", 14 );
pszOutput = T2A(strName);
pFile.Write( pszOutput, strlen(pszOutput) );
pFile.Write( "\" cookie=\"", 10 );
pszOutput = T2A(strCaption);
pFile.Write( pszOutput, strlen(pszOutput) );
pFile.Write( "\" caption=\"", 11 );
pDialog->GetWindowText( strCaption );
pszOutput = T2A(strCaption);
pFile.Write( pszOutput, strlen(pszOutput) );
pFile.Write( "\">\r\n", 4 );
for ( pWnd = pDialog->GetWindow( GW_CHILD ) ; pWnd ; pWnd = pWnd->GetNextWindow() )
{
TCHAR szClass[64];
GetClassName( pWnd->GetSafeHwnd(), szClass, 64 );
strCaption.Empty();
if ( _tcsistr( szClass, _T("Static") ) ||
_tcsistr( szClass, _T("Button") ) )
{
pWnd->GetWindowText( strCaption );
}
if ( strCaption.GetLength() )
{
Replace( strCaption, _T("&"), _T("_") );
Replace( strCaption, _T("\""), _T(""") );
pFile.Write( "\t<control caption=\"", 19 );
pszOutput = T2A(strCaption);
pFile.Write( pszOutput, strlen(pszOutput) );
pFile.Write( "\"/>\r\n", 5 );
}
else
{
pFile.Write( "\t<control/>\r\n", 10+3 );
}
}
pFile.Write( "</dialog>\r\n\r\n", 13 );
pFile.Close();
return TRUE;
}
CXMLElement* pBase = NULL;
if ( ! m_pDialogs.Lookup( strName, (void*&)pBase ) ) return FALSE;
if ( strCaption != pBase->GetAttributeValue( _T("cookie") ) ) return FALSE;
strCaption = pBase->GetAttributeValue( _T("caption") );
if ( strCaption.GetLength() ) pDialog->SetWindowText( strCaption );
pWnd = pDialog->GetWindow( GW_CHILD );
for ( POSITION pos = pBase->GetElementIterator() ; pos && pWnd ; )
{
CXMLElement* pXML = pBase->GetNextElement( pos );
if ( pXML->IsNamed( _T("control") ) )
{
strCaption = pXML->GetAttributeValue( _T("caption") );
Replace( strCaption, _T("{n}"), _T("\r\n") );
if ( strCaption.GetLength() )
{
int nPos = strCaption.Find( '_' );
if ( nPos >= 0 ) strCaption.SetAt( nPos, '&' );
pWnd->SetWindowText( strCaption );
}
pWnd = pWnd->GetNextWindow();
}
}
return TRUE;
}
CString CSkin::GetDialogCaption(LPCTSTR pszName)
{
CXMLElement* pBase = NULL;
CString strCaption;
if ( m_pDialogs.Lookup( pszName, (void*&)pBase ) )
{
strCaption = pBase->GetAttributeValue( _T("caption") );
}
return strCaption;
}
BOOL CSkin::LoadDialogs(CXMLElement* pBase)
{
for ( POSITION pos = pBase->GetElementIterator() ; pos ; )
{
CXMLElement* pXML = pBase->GetNextElement( pos );
if ( pXML->IsNamed( _T("dialog") ) )
{
CString strName = pXML->GetAttributeValue( _T("name") );
CXMLElement* pOld;
if ( m_pDialogs.Lookup( strName, (void*&)pOld ) ) delete pOld;
pXML->Detach();
m_pDialogs.SetAt( strName, pXML );
}
}
return TRUE;
}
//////////////////////////////////////////////////////////////////////
// CSkin window skins
CSkinWindow* CSkin::GetWindowSkin(LPCTSTR pszWindow, LPCTSTR pszAppend)
{
CString strWindow;
strWindow.Format( _T("|%s%s|"), pszWindow, pszAppend ? pszAppend : _T("") );
for ( POSITION pos = m_pSkins.GetHeadPosition() ; pos ; )
{
CSkinWindow* pSkin = (CSkinWindow*)m_pSkins.GetNext( pos );
if ( pSkin->m_sTargets.Find( strWindow ) >= 0 ) return pSkin;
}
return NULL;
}
CSkinWindow* CSkin::GetWindowSkin(CWnd* pWnd)
{
LPCTSTR* pszModeSuffix = m_pszModeSuffix[ Settings.General.GUIMode ];
BOOL bPanel = FALSE;
if ( pWnd->IsKindOf( RUNTIME_CLASS(CChildWnd) ) )
{
CChildWnd* pChild = (CChildWnd*)pWnd;
bPanel = pChild->m_bPanelMode;
}
for ( CRuntimeClass* pClass = pWnd->GetRuntimeClass() ; pClass ; pClass = pClass->m_pBaseClass )
{
if ( bPanel )
{
CSkinWindow* pSkin = GetWindowSkin( CString( pClass->m_lpszClassName ), _T(".Panel") );
if ( pSkin != NULL ) return pSkin;
}
for ( int nSuffix = 0 ; pszModeSuffix[ nSuffix ] != NULL ; nSuffix ++ )
{
if ( pszModeSuffix[ nSuffix ][0] != 0 || ! bPanel )
{
CSkinWindow* pSkin = GetWindowSkin(
CString( pClass->m_lpszClassName ), pszModeSuffix[ nSuffix ] );
if ( pSkin != NULL ) return pSkin;
}
}
}
return NULL;
}
BOOL CSkin::LoadWindowSkins(CXMLElement* pSub, const CString& strPath)
{
for ( POSITION posSkin = pSub->GetElementIterator() ; posSkin ; )
{
CXMLElement* pSkinElement = pSub->GetNextElement( posSkin );
if ( pSkinElement->IsNamed( _T("windowSkin") ) )
{
CSkinWindow* pSkin = new CSkinWindow();
if ( pSkin->Parse( pSkinElement, strPath ) )
{
m_pSkins.AddHead( pSkin );
}
else
{
delete pSkin;
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -