forked from sakura-editor/sakura
/
CDlgSameColor.cpp
497 lines (425 loc) · 13.4 KB
/
CDlgSameColor.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
/*! @file
@brief 文字色/背景色統一ダイアログ
@author ryoji
@date 2006/04/26 作成
*/
/*
Copyright (C) 2006, ryoji
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented;
you must not claim that you wrote the original software.
If you use this software in a product, an acknowledgment
in the product documentation would be appreciated but is
not required.
2. Altered source versions must be plainly marked as such,
and must not be misrepresented as being the original software.
3. This notice may not be removed or altered from any source
distribution.
*/
#include "StdAfx.h"
#include "CDlgSameColor.h"
#include "types/CType.h"
#include "view/colors/EColorIndexType.h"
#include "uiparts/CGraphics.h"
#include "util/shell.h"
#include "sakura_rc.h"
#include "sakura.hh"
static const DWORD p_helpids[] = { // 2006.10.10 ryoji
IDOK, HIDOK_SAMECOLOR, // OK
IDCANCEL, HIDCANCEL_SAMECOLOR, // キャンセル
IDC_BUTTON_HELP, HIDC_BUTTON_SAMECOLOR_HELP, // ヘルプ
IDC_LIST_COLORS, HIDC_LIST_SAMECOLOR_COLORS, // 変更対象の色
IDC_BUTTON_SELALL, HIDC_BUTTON_SAMECOLOR_SELALL, // 全チェック
IDC_BUTTON_SELNOTING, HIDC_BUTTON_SAMECOLOR_SELNOTING, // 全解除
IDC_LIST_ITEMINFO, HIDC_LIST_SAMECOLOR_ITEMINFO, // 選択中の色に対応する項目のリスト
IDC_STATIC_COLOR, HIDC_STATIC_COLOR, // 統一色
0, 0
};
LPVOID CDlgSameColor::GetHelpIdTable( void )
{
return (LPVOID)p_helpids;
}
CDlgSameColor::CDlgSameColor() :
m_wpColorStaticProc(NULL),
m_wpColorListProc(NULL),
m_wID(0),
m_pTypes(NULL),
m_cr(0)
{
return;
}
CDlgSameColor::~CDlgSameColor()
{
return;
}
/*!
標準以外のメッセージを捕捉する
*/
INT_PTR CDlgSameColor::DispatchEvent( HWND hWnd, UINT wMsg, WPARAM wParam, LPARAM lParam )
{
INT_PTR result;
result = CDialog::DispatchEvent( hWnd, wMsg, wParam, lParam );
switch( wMsg ){
case WM_COMMAND:
// 色選択リストボックスの選択が変更された場合の処理
if( IDC_LIST_COLORS == LOWORD(wParam) && LBN_SELCHANGE == HIWORD(wParam) ){
OnSelChangeListColors( (HWND)lParam );
}
break;
case WM_CTLCOLORLISTBOX:
{
// 項目リストの背景色を設定する処理
HWND hwndLB = (HWND)lParam;
if( IDC_LIST_ITEMINFO == ::GetDlgCtrlID( hwndLB ) ){
HDC hdcLB = (HDC)wParam;
::SetTextColor( hdcLB, ::GetSysColor( COLOR_WINDOWTEXT ) );
::SetBkMode( hdcLB, TRANSPARENT );
return (INT_PTR)::GetSysColorBrush( COLOR_BTNFACE );
}
}
break;
default:
break;
}
return result;
}
/*! モーダルダイアログの表示
@param wID [in] タイプ別設定ダイアログで押されたボタンID
@param pTypes [in,out] タイプ別設定データ
@param cr [in] 指定色
@date 2006.04.26 ryoji 新規作成
*/
int CDlgSameColor::DoModal( HINSTANCE hInstance, HWND hwndParent, WORD wID, STypeConfig* pTypes, COLORREF cr )
{
m_wID = wID;
m_pTypes = pTypes;
m_cr = cr;
(void)CDialog::DoModal( hInstance, hwndParent, IDD_SAMECOLOR, (LPARAM)NULL );
return TRUE;
}
/*! WM_INITDIALOG 処理
@date 2006.04.26 ryoji 新規作成
*/
BOOL CDlgSameColor::OnInitDialog( HWND hwndDlg, WPARAM wParam, LPARAM lParam )
{
BOOL bRet = CDialog::OnInitDialog( hwndDlg, wParam, lParam );
HWND hwndStatic = GetItemHwnd( IDC_STATIC_COLOR );
HWND hwndList = GetItemHwnd( IDC_LIST_COLORS );
// 指定色スタティック、色選択リストをサブクラス化
::SetWindowLongPtr( hwndStatic, GWLP_USERDATA, (LONG_PTR)this );
m_wpColorStaticProc = (WNDPROC)::SetWindowLongPtr( hwndStatic, GWLP_WNDPROC, (LONG_PTR)ColorStatic_SubclassProc );
::SetWindowLongPtr( hwndList, GWLP_USERDATA, (LONG_PTR)this );
m_wpColorListProc = (WNDPROC)::SetWindowLongPtr( hwndList, GWLP_WNDPROC, (LONG_PTR)ColorList_SubclassProc );
WCHAR szText[30];
int nItem;
int i;
switch( m_wID ) // タイプ別設定ダイアログで押されたボタンID
{
case IDC_BUTTON_SAMETEXTCOLOR:
// タイプ別設定から文字色を重複しないように取り出す
::SetWindowText( GetHwnd(), LS(STR_DLGSMCLR_BTN1) );
for( i = 0; i < COLORIDX_LAST; ++i ){
if( 0 != (g_ColorAttributeArr[i].fAttribute & COLOR_ATTRIB_NO_TEXT) )
continue;
if( m_cr != m_pTypes->m_ColorInfoArr[i].m_sColorAttr.m_cTEXT ){
_ultow( m_pTypes->m_ColorInfoArr[i].m_sColorAttr.m_cTEXT, szText, 10 );
if( LB_ERR == List_FindStringExact( hwndList, -1, szText ) ){
nItem = ::List_AddString( hwndList, szText );
List_SetItemData( hwndList, nItem, FALSE );
}
}
}
break;
case IDC_BUTTON_SAMEBKCOLOR:
// タイプ別設定から背景色を重複しないように取り出す
::SetWindowText( GetHwnd(), LS(STR_DLGSMCLR_BTN2) );
for( i = 0; i < COLORIDX_LAST; ++i ){
if( 0 != (g_ColorAttributeArr[i].fAttribute & COLOR_ATTRIB_NO_BACK) ) // 2006.12.18 ryoji フラグ利用で簡素化
continue;
if( m_cr != m_pTypes->m_ColorInfoArr[i].m_sColorAttr.m_cBACK ){
_ultow( m_pTypes->m_ColorInfoArr[i].m_sColorAttr.m_cBACK, szText, 10 );
if( LB_ERR == List_FindStringExact( hwndList, -1, szText ) ){
nItem = ::List_AddString( hwndList, szText );
List_SetItemData( hwndList, nItem, FALSE );
}
}
}
break;
default:
CloseDialog( IDCANCEL );
break;
}
if( 0 < List_GetCount( hwndList ) ){
List_SetCurSel( hwndList, 0 );
OnSelChangeListColors( hwndList );
}
return bRet;
}
/*! BN_CLICKED 処理
@date 2006.04.26 ryoji 新規作成
*/
BOOL CDlgSameColor::OnBnClicked( int wID )
{
HWND hwndList = GetItemHwnd( IDC_LIST_COLORS );
int nItemNum = List_GetCount( hwndList );
BOOL bCheck;
int i;
int j;
switch( wID ){
case IDC_BUTTON_HELP:
// ヘルプ // 2006.10.07 ryoji
MyWinHelp( GetHwnd(), HELP_CONTEXT, HLP000316 ); // 2006.10.10 ryoji MyWinHelpに変更に変更
return TRUE;
case IDC_BUTTON_SELALL:
case IDC_BUTTON_SELNOTING:
// 全選択/全解除の処理
bCheck = (wID == IDC_BUTTON_SELALL);
for( i = 0; i < nItemNum; ++i ){
List_SetItemData( hwndList, i, bCheck );
}
::InvalidateRect( hwndList, NULL, TRUE );
break;
case IDOK:
// タイプ別設定から選択色と同色のものを取り出して指定色に一括変更する
WCHAR szText[30];
LPWSTR pszStop;
COLORREF cr;
for( i = 0; i < nItemNum; ++i ){
bCheck = (BOOL)List_GetItemData( hwndList, i );
if( bCheck ){
List_GetText( hwndList, i, szText );
cr = wcstoul( szText, &pszStop, 10 );
switch( m_wID )
{
case IDC_BUTTON_SAMETEXTCOLOR:
for( j = 0; j < COLORIDX_LAST; ++j ){
if( cr == m_pTypes->m_ColorInfoArr[j].m_sColorAttr.m_cTEXT ){
m_pTypes->m_ColorInfoArr[j].m_sColorAttr.m_cTEXT = m_cr;
}
}
break;
case IDC_BUTTON_SAMEBKCOLOR:
for( j = 0; j < COLORIDX_LAST; ++j ){
if( cr == m_pTypes->m_ColorInfoArr[j].m_sColorAttr.m_cBACK ){
m_pTypes->m_ColorInfoArr[j].m_sColorAttr.m_cBACK = m_cr;
}
}
break;
default:
break;
}
}
}
break;
case IDCANCEL:
break;
}
return CDialog::OnBnClicked( wID );
}
/*! WM_DRAWITEM 処理
@date 2006.04.26 ryoji 新規作成
*/
BOOL CDlgSameColor::OnDrawItem( WPARAM wParam, LPARAM lParam )
{
LPDRAWITEMSTRUCT pDis = (LPDRAWITEMSTRUCT)lParam; // 項目描画情報
if( IDC_LIST_COLORS != pDis->CtlID ) // オーナー描画にしているのは色選択リストだけ
return TRUE;
//描画対象
CGraphics gr(pDis->hDC);
//
// 色選択リストの描画処理
//
RECT rc;
WCHAR szText[30];
LPWSTR pszStop;
COLORREF cr;
List_GetText( pDis->hwndItem, pDis->itemID, szText );
cr = wcstoul( szText, &pszStop, 10 );
rc = pDis->rcItem;
// アイテム矩形塗りつぶし
::MyFillRect( gr, pDis->rcItem, COLOR_WINDOW );
// アイテムが選択状態
if( pDis->itemState & ODS_SELECTED ){
rc = pDis->rcItem;
rc.left += (rc.bottom - rc.top);
::MyFillRect( gr, rc, COLOR_HIGHLIGHT );
}
// アイテムにフォーカスがある
if( pDis->itemState & ODS_FOCUS ){
::DrawFocusRect( gr, &pDis->rcItem );
}
// チェックボックス表示
rc = pDis->rcItem;
rc.top += 2;
rc.bottom -= 2;
rc.left += 2;
rc.right = rc.left + (rc.bottom - rc.top);
UINT uState = DFCS_BUTTONCHECK | DFCS_FLAT;
if( FALSE != (BOOL)pDis->itemData )
uState |= DFCS_CHECKED; // チェック状態
::DrawFrameControl( gr, &rc, DFC_BUTTON, uState );
// 色見本矩形
rc = pDis->rcItem;
rc.left += rc.bottom - rc.top + 2;
rc.top += 2;
rc.bottom -= 2;
rc.right -= 2;
gr.SetBrushColor( cr );
gr.SetPen( ::GetSysColor(COLOR_3DSHADOW) );
::RoundRect( gr, rc.left, rc.top, rc.right, rc.bottom , 5, 5 );
return TRUE;
}
/*! 色選択リストの LBN_SELCHANGE 処理
@date 2006.05.01 ryoji 新規作成
*/
BOOL CDlgSameColor::OnSelChangeListColors( HWND hwndCtl )
{
// 色選択リストで現在フォーカスのある色について
// タイプ別設定から同色の項目を取り出して項目リストに表示する
HWND hwndListInfo;
COLORREF cr;
WCHAR szText[30];
LPWSTR pszStop;
int i;
int j;
hwndListInfo = GetItemHwnd( IDC_LIST_ITEMINFO );
List_ResetContent( hwndListInfo );
i = List_GetCaretIndex( hwndCtl );
if( LB_ERR != i ){
List_GetText( hwndCtl, i, szText );
cr = wcstoul( szText, &pszStop, 10 );
switch( m_wID )
{
case IDC_BUTTON_SAMETEXTCOLOR:
for( j = 0; j < COLORIDX_LAST; ++j ){
if( 0 != (g_ColorAttributeArr[i].fAttribute & COLOR_ATTRIB_NO_TEXT) )
continue;
if( cr == m_pTypes->m_ColorInfoArr[j].m_sColorAttr.m_cTEXT ){
::List_AddString( hwndListInfo, m_pTypes->m_ColorInfoArr[j].m_szName);
}
}
break;
case IDC_BUTTON_SAMEBKCOLOR:
for( j = 0; j < COLORIDX_LAST; ++j ){
if( 0 != (g_ColorAttributeArr[j].fAttribute & COLOR_ATTRIB_NO_BACK) ) // 2006.12.18 ryoji フラグ利用で簡素化
continue;
if( cr == m_pTypes->m_ColorInfoArr[j].m_sColorAttr.m_cBACK ){
::List_AddString( hwndListInfo, m_pTypes->m_ColorInfoArr[j].m_szName);
}
}
break;
default:
break;
}
}
return TRUE;
}
/*! サブクラス化された指定色スタティックのウィンドウプロシージャ
@date 2006.04.26 ryoji 新規作成
*/
LRESULT CALLBACK CDlgSameColor::ColorStatic_SubclassProc( HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam )
{
HDC hDC;
RECT rc;
CDlgSameColor* pCDlgSameColor;
pCDlgSameColor = (CDlgSameColor*)::GetWindowLongPtr( hwnd, GWLP_USERDATA );
switch( uMsg ){
case WM_PAINT:
// ウィンドウ描画
PAINTSTRUCT ps;
hDC = ::BeginPaint( hwnd, &ps );
// 色見本矩形
::GetClientRect( hwnd, &rc );
rc.left += 2;
rc.top += 2;
rc.right -=2;
rc.bottom -= 2;
{
CGraphics gr(hDC);
gr.SetBrushColor( pCDlgSameColor->m_cr );
gr.SetPen( ::GetSysColor(COLOR_3DSHADOW) );
::RoundRect( gr, rc.left, rc.top, rc.right, rc.bottom, 5, 5 );
}
::EndPaint( hwnd, &ps );
return (LRESULT)0;
case WM_ERASEBKGND:
// 背景描画
hDC = (HDC)wParam;
::GetClientRect( hwnd, &rc );
// 親にWM_CTLCOLORSTATICを送って背景ブラシを取得し、背景描画する
{
HBRUSH hBrush = (HBRUSH)::SendMessageAny( GetParent( hwnd ), WM_CTLCOLORSTATIC, wParam, (LPARAM)hwnd );
::MyFillRect( hDC, rc, hBrush );
}
return (LRESULT)1;
case WM_DESTROY:
// サブクラス化解除
::SetWindowLongPtr( hwnd, GWLP_WNDPROC, (LONG_PTR)pCDlgSameColor->m_wpColorStaticProc );
pCDlgSameColor->m_wpColorStaticProc = NULL;
return (LRESULT)0;
default:
break;
}
return CallWindowProc( pCDlgSameColor->m_wpColorStaticProc, hwnd, uMsg, wParam, lParam );
}
/*! サブクラス化された色選択リストのウィンドウプロシージャ
@date 2006.04.26 ryoji 新規作成
*/
LRESULT CALLBACK CDlgSameColor::ColorList_SubclassProc( HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam )
{
POINT po;
RECT rcItem;
RECT rc;
int nItemNum;
int i;
CDlgSameColor* pCDlgSameColor;
pCDlgSameColor = (CDlgSameColor*)::GetWindowLongPtr( hwnd, GWLP_USERDATA );
switch( uMsg ){
case WM_LBUTTONUP:
// マウスボタン下にある項目の選択/選択解除をトグルする
po.x = LOWORD(lParam); // horizontal position of cursor
po.y = HIWORD(lParam); // vertical position of cursor
nItemNum = List_GetCount( hwnd );
for( i = 0; i < nItemNum; ++i ){
List_GetItemRect( hwnd, i, &rcItem );
rc = rcItem;
rc.top += 2;
rc.bottom -= 2;
rc.left += 2;
rc.right = rc.left + (rc.bottom - rc.top);
if( ::PtInRect( &rc, po ) ){
BOOL bCheck;
bCheck = !(BOOL)List_GetItemData( hwnd, i );
List_SetItemData( hwnd, i, bCheck );
::InvalidateRect( hwnd, &rcItem, TRUE );
break;
}
}
break;
case WM_KEYUP:
// フォーカス項目の選択/選択解除をトグルする
if( VK_SPACE == wParam ){
BOOL bCheck;
i = List_GetCaretIndex( hwnd );
if( LB_ERR != i ){
bCheck = !(BOOL)List_GetItemData( hwnd, i );
List_SetItemData( hwnd, i, bCheck );
::InvalidateRect( hwnd, NULL, TRUE );
}
}
break;
case WM_DESTROY:
// サブクラス化解除
::SetWindowLongPtr( hwnd, GWLP_WNDPROC, (LONG_PTR)pCDlgSameColor->m_wpColorListProc );
pCDlgSameColor->m_wpColorListProc = NULL;
return (LRESULT)0;
default:
break;
}
return ::CallWindowProc( pCDlgSameColor->m_wpColorListProc, hwnd, uMsg, wParam, lParam );
}