59 CColorListBox(
void) : _super(), m_itemHeight(-1), m_itemWidth(-1), m_margin(0), m_isView(true)
60 , m_currentTextColor(::GetSysColor(COLOR_WINDOWTEXT)), m_currentBackColor(::GetSysColor(COLOR_WINDOW))
72 _super::SetMaxLine(maxLine);
82 if ( m_backBrush.GetSafeHandle() != NULL )
84 m_backBrush.DeleteObject();
86 if ( IS_RGBVALUE(color) )
88 m_backBrush.CreateSolidBrush(color);
89 ASSERT( m_backBrush.GetSafeHandle() != NULL );
101 m_currentTextColor = textColor;
102 m_currentBackColor = backColor;
112 void SetColor(
int nIndex, COLORREF textColor, COLORREF backColor)
116 TParam& p = m_lineDatas[nIndex];
117 p.textColor = textColor;
118 p.backColor = backColor;
154 void PostString(
int nIndex, LPCTSTR lpszItem, COLORREF textColor = 0, COLORREF backColor = 0)
156 if ( ::IsWindow(m_hWnd) )
158 TParam* P =
new TParam(lpszItem, textColor, backColor);
159 if ( ! _super::PostMessage(WM_CLB_POSTSTRING, nIndex,
reinterpret_cast<LPARAM
>(P)) )
178 return _super::InsertString(nIndex, lpszItem);
191 return _super::AddString(lpszItem);
198 virtual void DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct)
200 if ( lpDrawItemStruct->CtlType != ODT_LISTBOX || lpDrawItemStruct->hwndItem != _super::GetSafeHwnd() )
204 UINT nIndex = lpDrawItemStruct->itemID;
209 const TParam& p = m_lineDatas[nIndex];
210 CString strText = p.viewItem;
211 COLORREF textColor = p.textColor;
212 COLORREF backColor = p.backColor;
213 if ( (lpDrawItemStruct->itemState & ODS_SELECTED) != 0 )
215 Swap(textColor, backColor);
219 dc.Attach(lpDrawItemStruct->hDC);
221 COLORREF currenttextColor = dc.SetTextColor(textColor);
222 int currentBkMode = dc.SetBkMode(TRANSPARENT);
224 dc.FillSolidRect(&(lpDrawItemStruct->rcItem), backColor);
225 RECT rect = lpDrawItemStruct->rcItem;
226 rect.top += m_margin;
227 dc.DrawText(strText, &rect, DT_SINGLELINE | DT_NOPREFIX);
228 if ( (lpDrawItemStruct->itemState & ODS_FOCUS) != 0 )
230 dc.DrawFocusRect(&(lpDrawItemStruct->rcItem));
232 dc.SetBkMode(currentBkMode);
233 dc.SetTextColor(currenttextColor);
243 if ( lpMeasureItemStruct->CtlType != ODT_LISTBOX ||
ToInt(lpMeasureItemStruct->CtlID) != _super::GetDlgCtrlID() )
247 if ( m_itemHeight < 0 )
250 GetFont()->GetLogFont(&lf);
251 m_itemHeight = lf.lfHeight;
252 if ( m_itemHeight < 0 )
254 m_itemHeight = -m_itemHeight;
256 m_itemHeight += m_margin * 2;
258 lpMeasureItemStruct->itemHeight = m_itemHeight;
273 virtual LRESULT
WindowProc(UINT message, WPARAM wParam, LPARAM lParam)
275 int index =
ToInt(wParam);
276 LPTSTR lpsz =
reinterpret_cast<LPTSTR
>(lParam);
281 if ( GetCount() == 0 )
290 dc.Attach(
reinterpret_cast<HDC
>(wParam));
293 int y = (GetCount() - GetTopIndex()) * m_itemHeight;
294 int h = rect.Height();
301 CBrush* B = &m_backBrush;
302 if ( B->GetSafeHandle() == NULL )
304 B = dc.GetCurrentBrush();
306 dc.FillRect(CRect(0, y, rect.Width(), h), B);
320 return m_lineDatas[index].item.GetLength();
328 CStr s = m_lineDatas[index].item;
333 case LB_DELETESTRING:
341 m_lineDatas.
Remove(index);
348 ASSERTLIB(
ToInt(m_lineDatas.
GetSize()) == _super::GetCount() );
349 TParam p(lpsz, m_currentTextColor, m_currentBackColor);
351 m_CheckWidth(p.item);
353 lParam =
reinterpret_cast<LPARAM
>(_T(
""));
355 case LB_INSERTSTRING:
361 TParam p(lpsz, m_currentTextColor, m_currentBackColor);
363 m_CheckWidth(p.item);
367 TParam p(lpsz, m_currentTextColor, m_currentBackColor);
368 m_lineDatas.
Insert(index, p);
369 m_CheckWidth(p.item);
371 lParam =
reinterpret_cast<LPARAM
>(_T(
""));
373 case LB_RESETCONTENT:
376 _super::SetHorizontalExtent(m_itemWidth);
378 case WM_CLB_POSTSTRING:
380 TParam* P =
reinterpret_cast<TParam*
>(lParam);
381 if ( P->textColor != P->backColor )
383 m_currentTextColor = P->textColor;
384 m_currentBackColor = P->backColor;
386 if ( ::IsWindow(m_hWnd) )
388 LRESULT r = _super::InsertString(index, P->item);
391 _super::SetTopIndex(
ToInt(r));
401 while ( ::PeekMessage(&msg, m_hWnd, WM_CLB_POSTSTRING, WM_CLB_POSTSTRING, PM_REMOVE) )
403 if ( msg.message == WM_CLB_POSTSTRING )
405 TParam* P =
reinterpret_cast<TParam*
>(msg.lParam);
412 return _super::WindowProc(message, wParam, lParam);
423 DWORD dwStyle = _super::GetStyle();
424 ASSERT( dwStyle & LBS_EXTENDEDSEL );
425 ASSERT( m_lineDatas.
GetSize() == 0 );
427 ASSERT( (dwStyle & LBS_OWNERDRAWVARIABLE) != 0 );
431 _super::PreSubclassWindow();
441 _super::PostNcDestroy();
453 TParam(LPCTSTR lpsz, COLORREF ct, COLORREF cb) : item(lpsz), textColor(ct), backColor(cb)
456 const int TABSTOP = 4;
459 INT_PTR tabPos = viewItem.
Find(
'\t');
464 CStr s = viewItem.
Mid(tabPos + 1);
465 viewItem = viewItem.
Left(tabPos)
473 COLORREF m_currentTextColor;
474 COLORREF m_currentBackColor;
479 DWORD m_lastPostIndex;
484 void m_CheckWidth(LPCTSTR lpszItem)
487 CFont* pFont = _super::GetFont();
488 CFont* pFontOld = pDC->SelectObject(pFont);
489 const CSize& size = pDC->GetTextExtent(lpszItem);
490 if ( m_itemWidth < size.cx )
492 m_itemWidth = size.cx;
493 _super::SetHorizontalExtent(m_itemWidth);
495 pDC->SelectObject(pFontOld);
virtual size_t GetSize(void) const
[取得] 要素数取得
void SetQueueSize(size_t size)
[設定] リングキューサイズ指定.
virtual bool Remove(INDEX index)
[削除] 要素一つ削除.
virtual size_t TakeElements(size_t size, TYP *P=NULL)
[取得] 複数要素取り出し.
virtual bool RemoveAll(void)
[削除] データ全削除.
virtual INDEX Add(const TYP &t)
[追加] 要素追加.
CStrT Left(size_t iSize) const
[作成] 範囲取得.
size_t GetLength(void) const
[取得] 文字列長
INT_PTR Find(TYP t, INDEX iFromIndex=0) const
[確認] 検索.
static CStrT Lineup(TCHAR t, size_t length)
[作成] 指定文字を並べた文字列作成
CStrT Mid(INDEX iOffset, size_t iSize=INVALID_SIZE) const
[作成] 範囲取得.
void SetMaxLine(int maxLine)
[設定] 最大ライン数設定.
void SetCurrentColor(COLORREF textColor, COLORREF backColor)
[設定] 文字色設定.
CColorListBox(void)
コンストラクタ
virtual void DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct)
[通知] オーナードロー通知.
virtual void MeasureItem(LPMEASUREITEMSTRUCT lpMeasureItemStruct)
[通知] オーナードロー計算通知.
void SetColor(int nIndex, COLORREF textColor, COLORREF backColor)
[設定] 文字色設定.
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)
[設定] PostString表示モード設定.
void SetBackColor(COLORREF color=CLR_AUTOSELECT)
[設定] 背景色設定.
int AddString(LPCTSTR lpszItem)
[追加] 文字列追加.
void PostString(int nIndex, LPCTSTR lpszItem, COLORREF textColor=0, COLORREF backColor=0)
[追加] 文字列追加.
void Copy(LPSTR _dst, LPCSTR src)
[複製] 文字列コピー(ASCII/SJIS用)
int ToInt(LPCSTR lpsz, int iBase=10)
[変換] INT変換(ASCII/SJIS用).
void Swap(T &t1, T &t2)
[変換] スワッパー.
bool IsInRange(INDEX value, size_t size)
[確認] 範囲チェック.
virtual bool Insert(INDEX index, const TYP &t)
[追加] 要素一つ挿入.
bool IsInRange(INDEX index) const
[確認] INDEXの有効確認.