105 CColor(
void) : m_textColor(::GetSysColor(COLOR_WINDOWTEXT)), m_backColor(::GetSysColor(COLOR_WINDOW))
113 CColor(COLORREF textColor, COLORREF backColor) : m_textColor(textColor), m_backColor(backColor)
140 void Add(INDEX pos,
size_t len, COLORREF textColor = CLR_INVALID, COLORREF backColor = CLR_INVALID)
142 if ( ! IS_RGBVALUE(textColor) )
144 textColor = m_textColor;
146 if ( ! IS_RGBVALUE(backColor) )
148 backColor = m_backColor;
150 if ( pos + len >= m_infos.
GetSize() )
152 TInfo pa(m_textColor, m_backColor);
158 TInfo pa(textColor, backColor);
161 m_infos.
Set(pos + i, pa);
178 TParam pa = { 100000, m_textColor, m_backColor };
187 if ( m_infos[i].textColor != m_infos[i + 1].textColor || m_infos[i].backColor != m_infos[i + 1].backColor )
190 TParam pa = { ll, m_infos[i].textColor, m_infos[i].backColor };
196 INDEX i = m_infos.
GetSize() - 1;
197 TParam pa = { ll, m_infos[i].textColor, m_infos[i].backColor };
199 TParam pa2 = { 100000, m_textColor, m_backColor };
213 TInfo(COLORREF text = 0, COLORREF back = 0)
214 : textColor(text), backColor(back)
220 COLORREF m_textColor;
221 COLORREF m_backColor;
226 : _super(), m_iItemHeight(-1), m_iItemWidth(-1), m_margin(0), m_isView(true), m_postCount(-1), m_oneCharWidth(-1)
243 m_currentColor = color;
254 if ( m_colors.
GetSize() > nIndex )
256 m_colors[nIndex]->color = color;
280 m_postCount = isDelayMode ? 0 : -1;
309 if ( ! ::IsWindow(m_hWnd) )
313 TParam* P =
new TParam;
316 if ( ! _super::PostMessage(WM_CLB_POSTSTRING, nIndex,
reinterpret_cast<LPARAM
>(P)) )
334 return _super::InsertString(nIndex, lpszItem);
347 return _super::AddString(lpszItem);
356 virtual void DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct)
358 if ( lpDrawItemStruct->CtlType != ODT_LISTBOX || lpDrawItemStruct->hwndItem != _super::GetSafeHwnd() )
362 UINT nIndex = lpDrawItemStruct->itemID;
364 if (
static_cast<UINT
>(m_colors.
GetSize()) <= nIndex )
368 CString strText = m_colors[nIndex]->item;
369 CRect rcItem = lpDrawItemStruct->rcItem;
370 const CColor& colors = m_colors[nIndex]->color;
374 bi.
Set(rcItem.Width(), rcItem.Height());
377 rect.OffsetRect(-rect.left, -rect.top);
384 rect.top += m_margin;
385 COLORREF colorText = 0;
386 COLORREF colorBack = 0;
390 CString s = strText.Left(
ToInt(v.
len));
393 if ( (lpDrawItemStruct->itemState & ODS_SELECTED) != 0 )
400 rect.right = rect.left;
404 dc.DrawText(s, &rect, DT_SINGLELINE | DT_NOPREFIX | DT_CALCRECT);
405 dc.FillSolidRect(&rect, colorBack);
407 dc.DrawText(s, &rect, DT_SINGLELINE | DT_NOPREFIX);
408 rect.left = rect.right;
410 rect.right = lpDrawItemStruct->rcItem.right;
411 if ( strText.GetLength() >
ToInt(v.
len) )
413 strText = strText.Mid(
ToInt(v.
len));
420 dc.FillSolidRect(&rect, colorBack);
421 if ( ! strText.IsEmpty() )
424 dc.DrawText(strText, &rect, DT_SINGLELINE | DT_NOPREFIX);
427 if ( (lpDrawItemStruct->itemState & ODS_FOCUS) != 0 )
430 dc.DrawFocusRect(&rc2);
433 bi.
Draw(lpDrawItemStruct->hDC, rcItem.left, rcItem.top);
442 if ( lpMeasureItemStruct->CtlType != ODT_LISTBOX ||
ToInt(lpMeasureItemStruct->CtlID) != _super::GetDlgCtrlID() )
446 if ( m_iItemHeight < 0 )
449 GetFont()->GetLogFont(&lf);
450 m_iItemHeight = lf.lfHeight;
451 if ( m_iItemHeight < 0 )
453 m_iItemHeight = -m_iItemHeight;
455 m_iItemHeight += m_margin * 2;
457 lpMeasureItemStruct->itemHeight = m_iItemHeight;
472 virtual LRESULT
WindowProc(UINT message, WPARAM wParam, LPARAM lParam)
474 int iIndex =
ToInt(wParam);
480 dc.Attach(
reinterpret_cast<HDC
>(wParam));
483 int y = (GetCount() - GetTopIndex()) * m_iItemHeight;
484 int h = rect.Height();
491 CBrush* B = dc.GetCurrentBrush();
492 dc.FillRect(CRect(0, y, rect.Width(), h), B);
509 return m_colors[iIndex]->item.GetLength();
517 STRLIB::Copy(
reinterpret_cast<TCHAR*
>(lParam), m_colors[iIndex]->item);
520 case LB_DELETESTRING:
525 delete m_colors[iIndex];
533 ASSERTLIB(
ToInt(m_colors.
GetSize()) == _super::GetCount() );
535 TParam* P =
new TParam;
536 P->item =
reinterpret_cast<LPCTSTR
>(lParam);
537 P->color = m_currentColor;
539 m_CheckWidth(P->item);
541 lParam =
reinterpret_cast<LPARAM
>(_T(
""));
543 case LB_INSERTSTRING:
549 ASSERTLIB(
ToInt(m_colors.
GetSize()) == _super::GetCount() );
550 TParam* P =
new TParam;
551 P->item =
reinterpret_cast<LPCTSTR
>(lParam);
552 P->color = m_currentColor;
554 m_CheckWidth(P->item);
559 TParam* P =
new TParam;
560 P->item =
reinterpret_cast<LPCTSTR
>(lParam);
561 P->color = m_currentColor;
562 m_colors.
Insert(iIndex, P);
563 m_CheckWidth(P->item);
565 lParam =
reinterpret_cast<LPARAM
>(_T(
""));
567 case LB_RESETCONTENT:
572 _super::SetHorizontalExtent(m_iItemWidth);
575 if ( wParam == TIMERID_SETTOPINDEX )
577 KillTimer(TIMERID_SETTOPINDEX);
579 _super::SetTopIndex(m_lastPostIndex);
582 case WM_CLB_POSTSTRING:
584 TParam* P =
reinterpret_cast<TParam*
>(lParam);
585 if ( ! P->color.IsEmpty() )
587 m_currentColor = P->color;
589 if ( ::IsWindow(m_hWnd) )
594 LRESULT r = _super::InsertString(iIndex, P->item);
595 KillTimer(TIMERID_SETTOPINDEX);
598 if ( m_postCount < 0 )
600 _super::SetTopIndex(
ToInt(r));
602 else if ( ++m_postCount > 4 )
605 _super::SetTopIndex(
ToInt(r));
609 m_lastPostIndex =
ToInt(r);
610 SetTimer(TIMERID_SETTOPINDEX, 100, NULL);
621 while ( ::PeekMessage(&msg, m_hWnd, WM_CLB_POSTSTRING, WM_CLB_POSTSTRING, PM_REMOVE) )
623 if ( msg.message == WM_CLB_POSTSTRING )
625 TParam* P =
reinterpret_cast<TParam*
>(msg.lParam);
632 return _super::WindowProc(message, wParam, lParam);
642 DWORD dwStyle = _super::GetStyle();
643 ASSERT( dwStyle & LBS_OWNERDRAWVARIABLE );
644 ASSERT( dwStyle & LBS_EXTENDEDSEL );
645 ASSERT( dwStyle & LBS_HASSTRINGS );
646 ASSERT( m_colors.
GetSize() == 0 );
648 _super::PreSubclassWindow();
658 _super::PostNcDestroy();
662 enum { TIMERID_SETTOPINDEX = 1 };
671 CColor m_currentColor;
680 DWORD m_lastPostIndex;
683 void m_ColorsRemoveAll(
void)
695 void m_CheckWidth(
const CString& strItem)
697 if ( m_oneCharWidth < 0 )
700 CFont* pFont = _super::GetFont();
701 CFont* pFontOld = pDC->SelectObject(pFont);
702 m_oneCharWidth = pDC->GetTextExtent(
"W").cx;
703 pDC->SelectObject(pFontOld);
706 int l = strItem.GetLength() * m_oneCharWidth;
707 if ( m_iItemWidth < l )
710 _super::SetHorizontalExtent(m_iItemWidth);
#define loop(VAR, CNT)
loop構文.
bool Set(int cx, int cy, COLORREF color=CLR_INVALID)
[設定] イメージ設定.
bool Draw(HDC hdc, int x=0, int y=0) const
[処理] イメージ描画.
void SetTextColor(COLORREF c)
[設定] 文字色設定.
void SetBkMode(int mode)
[設定] 背景モード設定.
void SelectFont(HFONT font)
[選択] フォント選択.
virtual size_t GetSize(void) const
[取得] サイズ取得
virtual bool Insert(INDEX index, const TYP &t)
[追加] 要素一つ挿入
virtual bool Remove(INDEX index)
[削除] 要素一つ削除.
virtual bool RemoveAll(void)
[削除] 空化
virtual INDEX Add(const TYP &t)
[追加] 要素一つ追加.
virtual bool Set(INDEX index, const TYP &t)
[設定] 要素の設定.
void Add(INDEX pos, size_t len, COLORREF textColor=CLR_INVALID, COLORREF backColor=CLR_INVALID)
[追加] 色情報追加.
bool IsEmpty(void) const
[確認] 空っぽ?
void RemoveAll(void)
[消去] 全消去.
CColor(COLORREF textColor, COLORREF backColor)
コンストラクタ
const CVectorT< TParam > & GetParam(void) const
[取得] 情報一覧取得.
CColorfulListBox(void)
コンストラクタ
void PostString(int nIndex, LPCTSTR lpszItem)
[追加] 文字列追加.
void SetColor(INDEX nIndex, const CColorfulListBox::CColor &color)
[設定] 文字色設定.
virtual void DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct)
[通知] オーナードロー通知.
void PostString(int nIndex, LPCTSTR lpszItem, const CColorfulListBox::CColor &color)
[追加] 文字列追加.
virtual void MeasureItem(LPMEASUREITEMSTRUCT lpMeasureItemStruct)
[通知] オーナードロー計算通知.
virtual void PostNcDestroy(void)
破棄
void SetMargin(DWORD m)
[設定] マージン設定
virtual void PreSubclassWindow(void)
[通知] subclassing/unsubclassing functions.
int InsertString(int nIndex, LPCTSTR lpszItem)
[追加] 文字列追加.
virtual LRESULT WindowProc(UINT message, WPARAM wParam, LPARAM lParam)
[通知] for processing Windows messages.
void SetPostViewMode(bool isView, bool isDelayMode=false)
[設定] PostString表示モード設定.
void SetCurrentColor(const CColorfulListBox::CColor &color)
[設定] 文字色設定.
~CColorfulListBox(void)
デストラクタ
int AddString(LPCTSTR lpszItem)
[追加] 文字列追加.
void Copy(LPSTR _dst, LPCSTR src)
[複製] 文字列コピー(ASCII/SJIS用)
int ToInt(LPCSTR lpsz, int iBase=10)
[変換] INT変換(ASCII/SJIS用).
bool IsInRange(INDEX value, size_t size)
[確認] 範囲チェック.
bool IsEmpty(void) const
[確認] 要素の有無確認.