Skip to content

Commit

Permalink
1、CListTextElementUI支持按列设置颜色:通过SetTextColor或者IListCallbackUI设置
Browse files Browse the repository at this point in the history
2、例子中资源释放
3、Combo控件中shadow初始化错误的问题
  • Loading branch information
qdtroy committed Jun 30, 2020
1 parent 39a4313 commit 351345b
Show file tree
Hide file tree
Showing 13 changed files with 96 additions and 53 deletions.
2 changes: 1 addition & 1 deletion Demos/TroyBrowser/TroyBrowser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ void InitResource()
CResourceManager::GetInstance()->LoadResource(_T("res.xml"), NULL);
}
}
::FreeResource(hResource);
::FreeResource(hGlobal);
}
}
break;
Expand Down
2 changes: 1 addition & 1 deletion Demos/WkeBrowser/WkeDemo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ void InitResource()
CResourceManager::GetInstance()->LoadResource(_T("res.xml"), NULL);
}
}
::FreeResource(hResource);
::FreeResource(hGlobal);
}
}
break;
Expand Down
2 changes: 1 addition & 1 deletion Demos/bdwallpaper/BDWallPaper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ void InitResource()
CResourceManager::GetInstance()->LoadResource(_T("res.xml"), NULL);
}
}
::FreeResource(hResource);
::FreeResource(hGlobal);
}
}
break;
Expand Down
2 changes: 1 addition & 1 deletion Demos/duidemo/DuiDemo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ void InitResource()
CResourceManager::GetInstance()->LoadResource(_T("res.xml"), NULL);
}
}
::FreeResource(hResource);
::FreeResource(hGlobal);
}
}
break;
Expand Down
2 changes: 1 addition & 1 deletion Demos/gamebox/GameBox.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -445,7 +445,7 @@ void InitResource()
CResourceManager::GetInstance()->LoadResource(_T("res.xml"), NULL);
}
}
::FreeResource(hResource);
::FreeResource(hGlobal);
}
}
break;
Expand Down
2 changes: 1 addition & 1 deletion Demos/xlgamebox/XLGameBox.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ void InitResource()
CResourceManager::GetInstance()->LoadResource(_T("res.xml"), NULL);
}
}
::FreeResource(hResource);
::FreeResource(hGlobal);
}
}
break;
Expand Down
1 change: 1 addition & 0 deletions DuiLib/Control/UICombo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,7 @@ namespace DuiLib {
, m_iCurSel(-1)
, m_uButtonState(0)
, m_bScrollSelect(true)
, m_bShowShadow(false)
{
m_szDropBox = CDuiSize(0, 150);
::ZeroMemory(&m_rcTextPadding, sizeof(m_rcTextPadding));
Expand Down
65 changes: 51 additions & 14 deletions DuiLib/Control/UIList.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2432,6 +2432,27 @@ namespace DuiLib {
Invalidate();
}

DWORD CListTextElementUI::GetTextColor(int iIndex) const
{
TListInfoUI* pInfo = m_pOwner->GetListInfo();
if( iIndex < 0 || iIndex >= pInfo->nColumns || m_aTextColors.GetSize() <= 0 ) return pInfo->dwTextColor;

DWORD dwColor = (DWORD)m_aTextColors.GetAt(iIndex);
return dwColor;
}

void CListTextElementUI::SetTextColor(int iIndex, DWORD dwTextColor)
{
if( m_pOwner == NULL ) return;

TListInfoUI* pInfo = m_pOwner->GetListInfo();
if( iIndex < 0 || iIndex >= pInfo->nColumns ) return;
while( m_aTextColors.GetSize() < pInfo->nColumns ) { m_aTextColors.Add((LPVOID)pInfo->dwTextColor); }
m_aTextColors.SetAt(iIndex, (LPVOID)dwTextColor);

Invalidate();
}

void CListTextElementUI::SetOwner(CControlUI* pOwner)
{
CListElementUI::SetOwner(pOwner);
Expand Down Expand Up @@ -2509,20 +2530,9 @@ namespace DuiLib {
void CListTextElementUI::DrawItemText(HDC hDC, const RECT& rcItem)
{
if( m_pOwner == NULL ) return;
TListInfoUI* pInfo = m_pOwner->GetListInfo();
DWORD iTextColor = pInfo->dwTextColor;

if( (m_uButtonState & UISTATE_HOT) != 0 ) {
iTextColor = pInfo->dwHotTextColor;
}
if( IsSelected() ) {
iTextColor = pInfo->dwSelectedTextColor;
}
if( !IsEnabled() ) {
iTextColor = pInfo->dwDisabledTextColor;
}
TListInfoUI* pInfo = m_pOwner->GetListInfo();
IListCallbackUI* pCallback = m_pOwner->GetTextCallback();

m_nLinks = 0;
int nLinks = lengthof(m_rcLinks);
for( int i = 0; i < pInfo->nColumns; i++ )
Expand All @@ -2533,10 +2543,37 @@ namespace DuiLib {
rcItem.top += pInfo->rcTextPadding.top;
rcItem.bottom -= pInfo->rcTextPadding.bottom;

DWORD iTextColor = pInfo->dwTextColor;
CDuiString strText;
if( pCallback ) strText = pCallback->GetItemText(this, m_iIndex, i);
else strText.Assign(GetText(i));
if( pCallback ) {
strText = pCallback->GetItemText(this, m_iIndex, i);
int iState = 0;
if( (m_uButtonState & UISTATE_HOT) != 0 ) {
iState = 1;
}
if( IsSelected() ) {
iState = 2;
}
if( !IsEnabled() ) {
iState = 3;
}
iTextColor = pCallback->GetItemTextColor(this, m_iIndex, i, iState);
}
else {
strText.Assign(GetText(i));

iTextColor = GetTextColor(i);
if( (m_uButtonState & UISTATE_HOT) != 0 ) {
iTextColor = pInfo->dwHotTextColor;
}
if( IsSelected() ) {
iTextColor = pInfo->dwSelectedTextColor;
}
if( !IsEnabled() ) {
iTextColor = pInfo->dwDisabledTextColor;
}

}
if( pInfo->bShowHtml )
CRenderEngine::DrawHtmlText(hDC, m_pManager, rcItem, strText.GetData(), iTextColor, \
&m_rcLinks[m_nLinks], &m_sLinks[m_nLinks], nLinks, pInfo->nFont, pInfo->uTextStyle);
Expand Down
5 changes: 5 additions & 0 deletions DuiLib/Control/UIList.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ namespace DuiLib {
{
public:
virtual LPCTSTR GetItemText(CControlUI* pList, int iItem, int iSubItem) = 0;
virtual DWORD GetItemTextColor(CControlUI* pList, int iItem, int iSubItem, int iState) = 0;// iState:0-正常、1-激活、2-选择、3-禁用
};

class IListOwnerUI
Expand Down Expand Up @@ -447,6 +448,9 @@ namespace DuiLib {
LPCTSTR GetText(int iIndex) const;
void SetText(int iIndex, LPCTSTR pstrText);

DWORD GetTextColor(int iIndex) const;
void SetTextColor(int iIndex, DWORD dwTextColor);

void SetOwner(CControlUI* pOwner);
CDuiString* GetLinkContent(int iIndex);

Expand All @@ -463,6 +467,7 @@ namespace DuiLib {
int m_nHoverLink;
IListUI* m_pOwner;
CStdPtrArray m_aTexts;
CStdPtrArray m_aTextColors;
};

/////////////////////////////////////////////////////////////////////////////////////
Expand Down
2 changes: 1 addition & 1 deletion DuiLib/Core/UIDlgBuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ namespace DuiLib {

m_pCallback = pCallback;
if( !m_xml.LoadFromMem((BYTE*)::LockResource(hGlobal), ::SizeofResource(dll_instence, hResource) )) return NULL;
::FreeResource(hResource);
::FreeResource(hGlobal);
m_pstrtype = type;
}

Expand Down
4 changes: 2 additions & 2 deletions DuiLib/Core/UIRender.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -365,7 +365,7 @@ namespace DuiLib {
if( dwSize == 0 ) break;
pData = new BYTE[ dwSize ];
::CopyMemory(pData, (LPBYTE)::LockResource(hGlobal), dwSize);
::FreeResource(hResource);
::FreeResource(hGlobal);
}
} while (0);

Expand Down Expand Up @@ -545,7 +545,7 @@ namespace DuiLib {
if( dwSize == 0 ) break;
pData = new BYTE[ dwSize ];
::CopyMemory(pData, (LPBYTE)::LockResource(hGlobal), dwSize);
::FreeResource(hResource);
::FreeResource(hGlobal);
}
} while (0);

Expand Down
2 changes: 1 addition & 1 deletion DuiLib/Core/UIResourceManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ namespace DuiLib {
if( !m_xml.LoadFromMem((BYTE*)::LockResource(hGlobal), ::SizeofResource(CPaintManagerUI::GetResourceDll(), hResource) )) {
return NULL;
}
::FreeResource(hResource);
::FreeResource(hGlobal);
}

return LoadResource(m_xml.GetRoot());
Expand Down
Loading

0 comments on commit 351345b

Please sign in to comment.