TNB Library
TnbMfcAbstractDrawingCtrl.h
[詳解]
1#pragma once
11#include "TnbMfcCommon.h"
13#include "TnbBitmapDrawer.h"
14#include "TnbSimpleVector.h"
15#include "TnbHandleHandle.h"
16
17
18
19//TNB Library
20namespace TNB {
21namespace MFC {
22
23
24
40{
41public:
44 {
47 };
48
49
50 //---------------------
51
52
58 void SetDefaultMarkDrawer(COLORREF base = ::GetSysColor(COLOR_WINDOW))
59 {
60 m_pBackgroundDrawer = new CBoxFillDrawer(base);
61 m_pSelectMarkDrawer = new CSelectedBeltDrawer(::GetSysColor(COLOR_HIGHLIGHT), base, true);
62 m_pNoActiveSelectMarkDrawer = new CSelectedBeltDrawer(::GetSysColor(COLOR_BTNFACE), base, true);
63 m_pFocusMarkDrawer = new CFocusFrameDrawer();
64 {
65 int c1 = ::GetSysColor(COLOR_WINDOW);
66 int c2 = ::GetSysColor(COLOR_BTNFACE);
67 int r1 = GetRValue(c1);
68 int r2 = GetRValue(c2);
69 int r = r2 - (r1 - r2);
70 r = (r < 0) ? 0 : r;
71 int g1 = GetGValue(c1);
72 int g2 = GetGValue(c2);
73 int g = g2 - (g1 - g2);
74 g = (g < 0) ? 0 : g;
75 int b1 = GetBValue(c1);
76 int b2 = GetBValue(c2);
77 int b = b2 - (b1 - b2);
78 b = (b < 0) ? 0 : b;
79 m_pDisabledStyleDrawer = new CSemitransparentBoxFillDrawer(RGB(r, g, b), 50);
80 }
81 m_selectMarkType = OVERLAP;
82 m_pTextDrawer.Null();
83 SetBackColor(base);
84 }
85
93 {
94 return m_SetDrawer(m_pBackgroundDrawer, draw);
95 }
96
106 {
107 m_selectMarkType = type;
108 bool r = m_SetDrawer(m_pSelectMarkDrawer, draw);
109 if ( r )
110 {
111 m_pNoActiveSelectMarkDrawer = m_pSelectMarkDrawer;
112 }
113 return r;
114 }
115
124 bool SetSelectMarkDrawer(const IDrawable& draw1, const IDrawable& draw2, ESelectMarkType type = OVERLAP)
125 {
126 if ( ! SetSelectMarkDrawer(draw1, type) ) { return false; }
127 return m_SetDrawer(m_pNoActiveSelectMarkDrawer, draw2);
128 }
129
137 {
138 return m_SetDrawer(m_pFocusMarkDrawer, draw);
139 }
140
149 {
150 return m_SetDrawer(m_pDisabledStyleDrawer, draw);
151 }
152
157 void SetBackColor(COLORREF color)
158 {
159 m_backColor = color;
160 if ( color == CLR_INVALID )
161 {
162 m_backColor = ::GetSysColor(COLOR_WINDOW);
163 }
164 m_backColorBrush.Null();
165 }
166
172 void SetTextDrawer(const CTextDrawer& text)
173 {
174 m_pTextDrawer = static_cast<CTextDrawer*>(text.Clone());
175 }
176
182 void AdditionRelatedHwnd(HWND hWnd)
183 {
184 m_wndList.Add(hWnd);
185 }
186
193 void PostMessageToRelatedHwnd(UINT message, WPARAM wParam = 0, LPARAM lParam = 0)
194 {
195 loop ( i, m_wndList.GetSize() )
196 {
197 ::PostMessage(m_wndList[i], message, wParam, lParam);
198 }
199 }
200
201protected:
202
204 CAbstractDrawingCtrl(void) : m_selectMarkType(OVERLAP), m_backColor(::GetSysColor(COLOR_WINDOW))
205 {
206 }
207
210 {
211 }
212
218 {
219 return m_selectMarkType;
220 }
221
226 COLORREF GetBackColor(void) const
227 {
228 return m_backColor;
229 }
230
238 void DrawSelectMark(HDC dc, const RECT& rect, bool isActive, LPARAM lParam = 0)
239 {
240 if ( isActive || m_pNoActiveSelectMarkDrawer.IsNull() )
241 {
242 m_DrawDrawer(m_pSelectMarkDrawer, dc, rect, lParam);
243 }
244 else
245 {
246 m_DrawDrawer(m_pNoActiveSelectMarkDrawer, dc, rect, lParam);
247 }
248 }
249
256 void DrawBackground(HDC dc, const RECT& rect, LPARAM lParam = 0)
257 {
258 m_DrawDrawer(m_pBackgroundDrawer, dc, rect, lParam);
259 }
260
267 void DrawFocusMark(HDC dc, const RECT& rect, LPARAM lParam = 0)
268 {
269 m_DrawDrawer(m_pFocusMarkDrawer, dc, rect, lParam);
270 }
271
279 void DrawDisabledStyle(HDC dc, const RECT& rect, LPARAM lParam = 0)
280 {
281 m_DrawDrawer(m_pDisabledStyleDrawer, dc, rect, lParam);
282 }
283
289 void DrawBackColor(HDC dc, const RECT& rect)
290 {
291 if ( (rect.bottom - rect.top) > 0 )
292 {
293 if ( m_backColorBrush.IsNull() )
294 {
295 m_backColorBrush = ::CreateSolidBrush(m_backColor);
296 }
297 ::FillRect(dc, &rect, m_backColorBrush);
298 }
299 }
300
308 void DrawText(HDC dc, const RECT& rect, LPCTSTR lpsz, LPARAM lParam = 0)
309 {
310 if ( ! m_pTextDrawer.IsNull() )
311 {
312 CSize sz = CRect(rect).Size();
313 m_pTextDrawer->Resize(sz - CSize(2, 0));
314 m_pTextDrawer->SetString(lpsz);
315 m_pTextDrawer->DrawEx(dc, rect.left + 1, rect.top, lParam);
316 }
317 }
318
327 void DrawText(HDC dc, const RECT& rect, LPCTSTR lpsz, DWORD drawStyle, LPARAM lParam = 0)
328 {
329 if ( ! m_pTextDrawer.IsNull() )
330 {
331 CSize sz = CRect(rect).Size();
332 m_pTextDrawer->SetDrawStyle(drawStyle);
333 m_pTextDrawer->Resize(sz - CSize(2, 0));
334 m_pTextDrawer->SetString(lpsz);
335 m_pTextDrawer->DrawEx(dc, rect.left + 1, rect.top, lParam);
336 }
337 }
338
343 DWORD GetTextDrawStyle(void) const
344 {
345 if ( ! m_pTextDrawer.IsNull() )
346 {
347 return m_pTextDrawer->GetDrawStyle();
348 }
349 return 0;
350 }
351
358 {
359 if ( m_pTextDrawer.IsNull() )
360 {
361 CFont* pFont = pWnd->GetFont();
362 m_pTextDrawer = new CTextDrawer(*pFont, CLR_AUTOSELECT, _T(""), DT_VCENTER | DT_SINGLELINE | DT_END_ELLIPSIS);
363 }
364 }
365
370 void BeginItemPaint(void)
371 {
372 loop ( i, m_wndList.GetSize() )
373 {
374 HWND h = m_wndList[i];
375 if ( ::IsWindow(h) )
376 {
378 }
379 }
380 }
381
388 bool EndItemPaint(void)
389 {
390 bool res = false;
391 for ( INT_PTR i = m_wndList.GetSize() - 1; i >= 0; i-- )
392 {
393 HWND h = m_wndList[i];
394 if ( ::IsWindow(h) )
395 {
396 BOOL r = MFCLIB::IsProcessingFlag(h);
397 if ( r )
398 {
400 }
401 if ( ::IsWindowVisible(h) != r )
402 {
403 ::ShowWindow(h, r ? SW_SHOW : SW_HIDE );
404 res = true;
405 }
406 }
407 else
408 {
409 m_wndList.Remove(i);
410 }
411 }
412 return res;
413 }
414
419 void AllReset(void)
420 {
421 m_selectMarkType = OVERLAP;
422 m_pSelectMarkDrawer.Null();
423 m_pNoActiveSelectMarkDrawer.Null();
424 m_pFocusMarkDrawer.Null();
425 m_pBackgroundDrawer.Null();
426 m_pDisabledStyleDrawer.Null();
427 //
428 m_backColorBrush.Null();
429 m_pTextDrawer.Null();
430 m_backColor = ::GetSysColor(COLOR_WINDOW);
431 //
432 m_wndList.RemoveAll();
433 }
434
435private:
437 bool m_SetDrawer(IDrawable::Ptr& _P, const IDrawable& draw)
438 {
439 _P = draw.Clone();
440 if ( ! _P.IsNull() )
441 {
442 if ( ! _P->Resize(CSize(1, 1)) )
443 {
444 _P.Null();
445 }
446 }
447 return ! _P.IsNull();
448 }
449 // 描画
450 void m_DrawDrawer(IDrawable::Ptr& _pDrawer, HDC dc, const RECT& rect, LPARAM lParam = 0)
451 {
452 if ( ! _pDrawer.IsNull() )
453 {
454 const CRect& rc = rect;
455 if ( ! rc.IsRectEmpty() )
456 {
457 _pDrawer->Resize(rc.Size());
458 _pDrawer->DrawEx(dc, rc.left, rc.top, lParam);
459 }
460 }
461 }
462 ESelectMarkType m_selectMarkType;
463 IDrawable::Ptr m_pSelectMarkDrawer;
464 IDrawable::Ptr m_pNoActiveSelectMarkDrawer;
465 IDrawable::Ptr m_pFocusMarkDrawer;
466 IDrawable::Ptr m_pBackgroundDrawer;
467 IDrawable::Ptr m_pDisabledStyleDrawer;
468 //
469 CBrushHandle m_backColorBrush;
470 CPointerHandleT<CTextDrawer> m_pTextDrawer;
471 COLORREF m_backColor;
472 //
473 CSimpleVectorT<HWND> m_wndList;
474};
475
476
477
478}; // MFC
479}; // TNB
ビットマップ描画関係のヘッダ
#define loop(VAR, CNT)
loop構文.
Definition: TnbDef.h:343
ハンドルハンドル関係のヘッダ
MFCコントロール共通のヘッダ
選択帯描画情報のヘッダ
簡易配列型情報管理関係のヘッダ
ウィンドウ管理.
四角塗りつぶし描画クラス
Definition: TnbDrawable.h:528
HBRUSH型ハンドルハンドル
フォーカスフレーム描画クラス
Definition: TnbDrawable.h:724
bool IsNull(void) const
[確認] NULLチェック
void Null(void)
[設定] 開放.
選択帯描画クラス
透過塗りつぶし描画クラス
void RemoveAll(void)
[削除] 空化
size_t GetSize(void) const
[取得] サイズ取得
bool Remove(INDEX index)
[削除] 要素一つ削除.
INDEX Add(const TYP &t)
[追加] 要素一つ追加.
テキスト描画クラス
Definition: TnbTextDrawer.h:52
virtual IDrawable * Clone(void) const
[作成] クローン作成.
Definition: TnbTextDrawer.h:90
描画情報コントロール抽象クラス
void SetTextDrawer(const CTextDrawer &text)
[設定] テキスト描画情報指定
void AdditionRelatedHwnd(HWND hWnd)
[追加] 関連Windowハンドル追加
CAbstractDrawingCtrl(void)
コンストラクタ
ESelectMarkType
セレクトマークタイプ
@ OVERLAP
アイテム描画上に描画
DWORD GetTextDrawStyle(void) const
[取得] 文字列描画スタイル取得.
void SetDefaultMarkDrawer(COLORREF base=::GetSysColor(COLOR_WINDOW))
[設定] デフォルトのマーク描画指定.
bool SetSelectMarkDrawer(const IDrawable &draw1, const IDrawable &draw2, ESelectMarkType type=OVERLAP)
[設定] 選択マーク描画指定.
virtual ~CAbstractDrawingCtrl(void)
デストラクタ
bool SetSelectMarkDrawer(const IDrawable &draw, ESelectMarkType type=OVERLAP)
[設定] 選択マーク描画指定.
void DrawText(HDC dc, const RECT &rect, LPCTSTR lpsz, DWORD drawStyle, LPARAM lParam=0)
[描画] 文字列描画
bool EndItemPaint(void)
[処理] 描画終了.
bool SetBackgroundDrawer(const IDrawable &draw)
[設定] 背景描画指定.
COLORREF GetBackColor(void) const
[取得] 背景色取得.
void DrawBackground(HDC dc, const RECT &rect, LPARAM lParam=0)
[描画] 背景表示
void DrawText(HDC dc, const RECT &rect, LPCTSTR lpsz, LPARAM lParam=0)
[描画] 文字列描画
void SetBackColor(COLORREF color)
[設定] 背景色設定.
void DrawSelectMark(HDC dc, const RECT &rect, bool isActive, LPARAM lParam=0)
[描画] 選択マーク表示
ESelectMarkType GetSelectMarkType(void) const
[取得] セレクトマークタイプ
bool SetFocusMarkDrawer(const IDrawable &draw)
[設定] フォーカスマーク描画指定.
void PostMessageToRelatedHwnd(UINT message, WPARAM wParam=0, LPARAM lParam=0)
[処理] 関連Windowハンドルへポスト
void DrawDisabledStyle(HDC dc, const RECT &rect, LPARAM lParam=0)
[描画] 無効状態描画.
void AllReset(void)
[設定] 全設定リセット.
void DrawFocusMark(HDC dc, const RECT &rect, LPARAM lParam=0)
[描画] フォーカスマーク表示
void BeginItemPaint(void)
[処理] 描画開始.
void DrawBackColor(HDC dc, const RECT &rect)
[描画] 背景色描画
void SetDefaultTextDrawer(CWnd *pWnd)
[設定] テキスト描画情報設定.
bool SetDisabledStyleDrawer(const IDrawable &draw)
[設定] 無効状態描画指定.
void SetProcessingFlag(HWND hWnd, bool isEnable)
[設定] 処理済フラグ操作.
Definition: TnbMfcCommon.h:427
bool IsProcessingFlag(HWND hWnd)
[取得] 処理済フラグ取得.
Definition: TnbMfcCommon.h:450
TNB Library
Definition: TnbDoxyTitle.txt:2
描画情報インターフェース
Definition: TnbDrawable.h:37
virtual bool Resize(const SIZE &size)=0
[設定] サイズ設定.
virtual IDrawable * Clone(void) const =0
[作成] クローン作成.
virtual void DrawEx(HDC dc, int x, int y, LPARAM lParam) const
[描画] 描画.
Definition: TnbDrawable.h:83