forked from Thomas-Mielke-Software/EasyCash
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathQuickList.cpp
More file actions
2224 lines (1802 loc) · 48.6 KB
/
QuickList.cpp
File metadata and controls
2224 lines (1802 loc) · 48.6 KB
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
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// QuickList.cpp : implementation file
//
// Diese Datei ist Bestandteil von EasyCash&Tax, der freien EÜR-Fibu
//
// Copyleft (GPLv3) 2020 Thomas Mielke
//
// Dies ist freie Software; Sie dürfen sie unter den Bedingungen der
// GNU General Public License, wie von der Free Software Foundation
// veröffentlicht, weiterverteilen und/oder modifizieren; entweder gemäß
// Version 3 der Lizenz oder (nach Ihrer Option) jeder späteren Version.
//
// Diese Software wird in der Hoffnung weiterverbreitet, dass sie nützlich
// sein wird, jedoch OHNE IRGENDEINE GARANTIE, auch ohne die implizierte
// Garantie der MARKTREIFE oder der VERWENDBARKEIT FÜR EINEN BESTIMMTEN ZWECK.
// Mehr Details finden Sie in der GNU Lesser General Public License.
//
// Sie sollten eine Kopie der GNU General Public License Version 3 zusammen mit
// dieser Software erhalten haben; falls nicht, schreiben Sie an die Free
// Software Foundation, Inc., 51 Franklin St, 5th Floor, Boston, MA 02110, USA.
#include "stdafx.h"
#include "QuickList.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CQuickList
//Constructor
CQuickList::CListItemData::CListItemData()
{
Reset();
}
//Get which item/row
int CQuickList::CListItemData::GetItem() const
{
return m_item;
}
//Get which subitem/column
int CQuickList::CListItemData::GetSubItem() const
{
return m_subitem;
}
//Is item selected?
bool CQuickList::CListItemData::IsSelected() const
{
return m_isSelected;
}
//Is item hot?
bool CQuickList::CListItemData::IsHot() const
{
return m_isHot;
}
//Reset settings.
void CQuickList::CListItemData::Reset()
{
m_text.Empty();
m_item = m_subitem = 0;
m_isSelected = false;
m_isHot = false;
m_noSelection = false;
#ifndef QUICKLIST_NOEDIT
m_allowEdit = false;
#endif
#ifndef QUICKLIST_NOTEXTSTYLE
m_textStyle.m_textPosition = DT_VCENTER | DT_SINGLELINE | DT_LEFT | DT_END_ELLIPSIS;
m_textStyle.m_bold = false;
m_textStyle.m_italic = false;
#endif
#ifndef QUICKLIST_NOIMAGE
m_image.m_imageID = -1;
m_image.m_imageList = NULL;
m_image.m_noSelection = true;
m_image.m_center = false;
m_image.m_blend = ILD_BLEND50;
#endif
#ifndef QUICKLIST_NOBUTTON
m_button.m_draw = false;
m_button.m_style = DFCS_BUTTONCHECK;
m_button.m_noSelection=true;
m_button.m_center=false;
#endif
#ifndef QUICKLIST_NOCOLORS
m_colors.m_backColor =
m_colors.m_selectedBackColor =
m_colors.m_selectedTextColor =
m_colors.m_selectedBackColorNoFocus =
m_colors.m_hotTextColor =
m_colors.m_textColor = DEFAULTCOLOR;
#ifndef QUICKLIST_NONAVIGATION
m_colors.m_navigatedTextColor =
m_colors.m_navigatedBackColor = DEFAULTCOLOR;
#endif
#endif
#ifndef QUICKLIST_NOPROGRESSBAR
m_progressBar.m_maxvalue = -1;
m_progressBar.m_value = 0;
m_progressBar.m_fillTextColor =
m_progressBar.m_fillColor = DEFAULTCOLOR;
m_progressBar.m_edge = EDGE_SUNKEN;
#endif
}
//Constructor
CQuickList::CQuickList()
{
#ifndef QUICKLIST_NOKEYFIND
#ifndef QUICKLIST_NONAVIGATION
m_keyFindColumn = KEYFIND_CURRENTCOLUMN;
#else
m_keyFindColumn = 0;
#endif
#endif
#ifndef QUICKLIST_NONAVIGATION
m_enableNavigation=true;
m_navigationColumn=0;
#endif
#ifndef QUICKLIST_NOEDIT
m_edit = NULL;
m_editOnEnter =
m_editOnF2 =
m_editOnDblclk = true;
m_editEndOnLostFocus = true;
m_editLastEndKey = 0;
#endif
m_lastget = new CListItemData;
#ifndef QUICKLIST_NOXPTHEME
m_theme = NULL;
#endif
}
//Destructor
CQuickList::~CQuickList()
{
delete m_lastget;
}
BEGIN_MESSAGE_MAP(CQuickList, CListCtrl)
//{{AFX_MSG_MAP(CQuickList)
ON_WM_PAINT()
ON_WM_KEYDOWN()
ON_WM_MOUSEWHEEL()
ON_NOTIFY_REFLECT(LVN_GETDISPINFO, OnGetdispinfo)
ON_WM_VSCROLL()
ON_WM_HSCROLL()
ON_WM_MOUSEMOVE()
ON_NOTIFY_REFLECT(NM_CUSTOMDRAW, OnCustomDraw)
//}}AFX_MSG_MAP
ON_NOTIFY_REFLECT(LVN_HOTTRACK, OnLvnHotTrack)
ON_NOTIFY_REFLECT_EX(NM_CLICK, OnClickEx)
ON_NOTIFY_REFLECT_EX(NM_DBLCLK, OnDblClickEx)
#ifndef QUICKLIST_NOKEYFIND
ON_NOTIFY_REFLECT_EX(LVN_ODFINDITEM, OnOdfinditem)
#endif
#ifndef QUICKLIST_NOTOOLTIP
ON_NOTIFY_EX_RANGE(TTN_NEEDTEXTW, 0, 0xFFFF, OnToolTipText)
ON_NOTIFY_EX_RANGE(TTN_NEEDTEXTA, 0, 0xFFFF, OnToolTipText)
#endif
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CQuickList message handlers
//Edit when enter is pressed
void CQuickList::SetEditOnEnter(const bool edit)
{
#ifndef QUICKLIST_NOEDIT
m_editOnEnter = edit;
#else
UNREFERENCED_PARAMETER(edit);
#endif
}
//Edit when F2 is pressed
void CQuickList::SetEditOnF2(const bool edit)
{
#ifndef QUICKLIST_NOEDIT
m_editOnF2 = edit;
#else
UNREFERENCED_PARAMETER(edit);
#endif
}
//Edit when double click
void CQuickList::SetEditOnDblclk(const bool edit)
{
#ifndef QUICKLIST_NOEDIT
m_editOnDblclk = edit;
#else
UNREFERENCED_PARAMETER(edit);
#endif
}
//End edit when edit box losing focus
void CQuickList::SetEndEditOnLostFocus(bool autoend)
{
#ifndef QUICKLIST_NOEDIT
m_editEndOnLostFocus = autoend;
if(m_edit != NULL)
m_edit->SetEndOnLostFocus(m_editEndOnLostFocus);
#else
UNREFERENCED_PARAMETER(autoend);
#endif
}
#ifndef QUICKLIST_NOXPTHEME
//Set which theme manager to use
void CQuickList::SetThemeManager(CTheme* theme)
{
m_theme = theme;
}
#endif
//Edit when edit box is losing focus?
bool CQuickList::GetEndEditOnLostFocus() const
{
#ifndef QUICKLIST_NOEDIT
return m_editEndOnLostFocus;
#else
return false;
#endif
}
//Return which key was pressed when edit box was closed
//0, VK_RETURN or VK_ESACPE
UINT CQuickList::GetLastEndEditKey() const
{
#ifndef QUICKLIST_NOEDIT
return m_editLastEndKey;
#else
return 0;
#endif
}
//Get current edit box
CEdit* CQuickList::GetEditBox() const
{
#ifndef QUICKLIST_NOEDIT
return m_edit;
#else
return NULL;
#endif
}
//Custom draw
void CQuickList::OnCustomDraw(NMHDR* pNMHDR, LRESULT* pResult)
{
NMLVCUSTOMDRAW* pLVCD = reinterpret_cast<NMLVCUSTOMDRAW*>( pNMHDR );
// *pResult = 0; return;
// If this is the beginning of the control's paint cycle, request
// notifications for each item.
if ( CDDS_PREPAINT == pLVCD->nmcd.dwDrawStage )
{
*pResult = CDRF_NOTIFYITEMDRAW;
}
else if ( CDDS_ITEMPREPAINT == pLVCD->nmcd.dwDrawStage )
{
// This is the pre-paint stage for an item. We need to make another
// request to be notified during the post-paint stage.
*pResult = CDRF_NOTIFYSUBITEMDRAW;;
}
else if ( (CDDS_ITEMPREPAINT| CDDS_SUBITEM) == pLVCD->nmcd.dwDrawStage )
{
CDC* pDC = CDC::FromHandle(pLVCD->nmcd.hdc);
DrawItem(static_cast<int> (pLVCD->nmcd.dwItemSpec),
pLVCD->iSubItem, pDC);
*pResult = CDRF_SKIPDEFAULT; // We've painted everything.
}
}
/*
About GetTextColor and GetBackColor:
Here you see why you shouldn't try to optimze your code :-)
*/
#ifndef COLOR_HOTLIGHT
#define COLOR_HOTLIGHT 26
#endif
//Get which text color to use
COLORREF CQuickList::GetTextColor(const CQuickList::CListItemData& id, const bool forceNoSelection, const bool forceSelection)
{
bool navigated = false;
#ifndef QUICKLIST_NONAVIGATION
if(id.GetSubItem() == m_navigationColumn && m_enableNavigation)
navigated = true;
#endif
if( (!forceNoSelection && id.IsSelected()) //IsSelected(id.m_item, id.m_subitem))
|| forceSelection)
{
#ifndef QUICKLIST_NOCOLORS
#ifndef QUICKLIST_NONAVIGATION
if(navigated && GetFocus() == this)
{
if(id.m_colors.m_navigatedTextColor!= DEFAULTCOLOR)
return id.m_colors.m_navigatedTextColor;
else
return ::GetSysColor(COLOR_HIGHLIGHTTEXT);
}
#endif
if(id.m_colors.m_selectedTextColor != DEFAULTCOLOR)
return id.m_colors.m_selectedTextColor;
else
{
if(GetFocus() == this)
return ::GetSysColor(COLOR_HIGHLIGHTTEXT);
else
return ::GetSysColor(COLOR_WINDOWTEXT);
}
#else
if(GetFocus() == this)
return ::GetSysColor(COLOR_HIGHLIGHTTEXT);
else
return ::GetSysColor(COLOR_WINDOWTEXT);
#endif
}
//Is item hot?
if( GetHotItem() == id.GetItem() )
{
#ifndef QUICKLIST_NOCOLORS
if(id.m_colors.m_hotTextColor != DEFAULTCOLOR)
return id.m_colors.m_hotTextColor;
else
#endif
return ::GetSysColor(COLOR_HOTLIGHT);
}
else
{
#ifndef QUICKLIST_NOCOLORS
if(id.m_colors.m_textColor != DEFAULTCOLOR)
return id.m_colors.m_textColor;
else
#endif
return ::GetSysColor(COLOR_WINDOWTEXT);
}
}
//Get which background color to use
COLORREF CQuickList::GetBackColor(const CQuickList::CListItemData& id, const bool forceNoSelection)
{
bool navigated = false;
#ifndef QUICKLIST_NONAVIGATION
if(id.GetSubItem() == m_navigationColumn && m_enableNavigation)
navigated = true;
#endif
bool hasFocus = (GetFocus() == this);
//Is selected
if(!forceNoSelection && id.IsSelected()) //IsSelected(id.m_item, id.m_subitem))
{
//Return selected color
#ifndef QUICKLIST_NOCOLORS
#ifndef QUICKLIST_NONAVIGATION
if(navigated && GetFocus() == this)
{
if(id.m_colors.m_navigatedBackColor!= DEFAULTCOLOR)
return id.m_colors.m_navigatedBackColor;
else
return ::GetSysColor(COLOR_HOTLIGHT);
}
#endif
if( (hasFocus && id.m_colors.m_selectedBackColor != DEFAULTCOLOR) ||
(!hasFocus && id.m_colors.m_selectedBackColorNoFocus != DEFAULTCOLOR) )
{
if(hasFocus)
return id.m_colors.m_selectedBackColor;
else
return id.m_colors.m_selectedBackColorNoFocus;
}
else
{
if(!IsColumnNavigationOn() && id.IsHot())
return ::GetSysColor(COLOR_HOTLIGHT);
if(hasFocus)
return ::GetSysColor(COLOR_HIGHLIGHT);
else
return ::GetSysColor(COLOR_BTNFACE);
}
#else
//Simple window colors
if(navigated && GetFocus() == this)
return ::GetSysColor(COLOR_HOTLIGHT);
else if(!IsColumnNavigationOn() && id.IsHot())
return ::GetSysColor(COLOR_HOTLIGHT);
else
{
if(GetFocus() == this)
return ::GetSysColor(COLOR_HIGHLIGHT);
else
return ::GetSysColor(COLOR_BTNFACE);
}
#endif
}
#ifndef QUICKLIST_NOCOLORS
if(id.m_colors.m_backColor != DEFAULTCOLOR)
return id.m_colors.m_backColor;
else
#endif
return ::GetSysColor(COLOR_WINDOW);
}
//Is item selected?
bool CQuickList::IsSelected(const int item, const int subitem)
{
if (GetItemState(item, LVIS_SELECTED))
{
if ( subitem == 0 || //First column or...
FullRowSelect() //full row select?
)
{
// has focus?
if (m_hWnd != ::GetFocus())
{
if (GetStyle() & LVS_SHOWSELALWAYS)
{
return true;
}
else
{
return false;
}
}
return true;
}
}
return false;
}
//On painting
void CQuickList::OnPaint()
{
Default();
#ifndef QUICKLIST_NOEMPTYMESSAGE
//Draw empty list message
if (GetItemCount() <= 0 && !m_emptyMessage.IsEmpty())
{
CDC* pDC = GetDC();
int nSavedDC = pDC->SaveDC();
CRect rc;
GetWindowRect(&rc);
ScreenToClient(&rc);
CHeaderCtrl* pHC = GetHeaderCtrl();
if (pHC != NULL)
{
CRect rcH;
pHC->GetItemRect(0, &rcH);
rc.top += rcH.bottom;
}
rc.top += 10;
COLORREF crText = CListCtrl::GetTextColor();
pDC->SetTextColor(crText);
int oldMode = pDC->SetBkMode(TRANSPARENT);
pDC->SelectStockObject(ANSI_VAR_FONT);
pDC->DrawText(m_emptyMessage, -1, rc, DT_CENTER | DT_WORDBREAK | DT_NOPREFIX | DT_NOCLIP);
pDC->SetBkMode(oldMode);
pDC->RestoreDC(nSavedDC);
ReleaseDC(pDC);
}
#endif
}
#ifndef QUICKLIST_NOEMPTYMESSAGE
//Set empty message
void CQuickList::SetEmptyMessage(const CString &message)
{
m_emptyMessage = message;
}
//Set empty message
void CQuickList::SetEmptyMessage(UINT ID)
{
CString temp;
temp.LoadString(ID);
SetEmptyMessage(temp);
}
#endif
//Get rect of subitem.
BOOL CQuickList::GetSubItemRect(int nItem,
int nSubItem,
int nArea,
CRect& rect)
{
ASSERT(nItem >= 0);
ASSERT(nItem < GetItemCount());
if ((nItem < 0) || nItem >= GetItemCount())
return FALSE;
ASSERT(nSubItem >= 0);
ASSERT(nSubItem < GetHeaderCtrl()->GetItemCount());
if ((nSubItem < 0) || nSubItem >= GetHeaderCtrl()->GetItemCount())
return FALSE;
BOOL bRC = CListCtrl::GetSubItemRect(nItem, nSubItem, nArea, rect);
// if nSubItem == 0, the rect returned by CListCtrl::GetSubItemRect
// is the entire row, so use left edge of second subitem
if (nSubItem == 0)
{
if (GetHeaderCtrl()->GetItemCount() > 1)
{
CRect rect1;
bRC = GetSubItemRect(nItem, 1, LVIR_BOUNDS, rect1);
rect.right = rect1.left;
}
}
return bRC;
}
//Get progress bar rect
//Return false if none
bool CQuickList::GetProgressRect(const int item, const int subitem, CRect& rect, bool interior)
{
CQuickList::CListItemData& data = GetItemData(item, subitem);
return GetProgressRect(data, rect, interior);
}
//Get progress bar rect
//Return false if none
bool CQuickList::GetProgressRect(CQuickList::CListItemData& id, CRect& rect, bool interior)
{
#ifdef QUICKLIST_NOPROGRESSBAR
UNREFERENCED_PARAMETER(id);
UNREFERENCED_PARAMETER(rect);
UNREFERENCED_PARAMETER(interior);
return false;
#else
if(id.m_progressBar.m_maxvalue <= 0)
return false;
//Pretty much as text box, so use this
GetTextRect(id, rect);
rect.top += 1;
rect.bottom -= 1;
rect.left += 1; // leave margin in case row is highlighted
rect.right -= 2;
//Shrink if interior and border is drawn
if(interior && (id.m_progressBar.m_edge != 0))
rect.DeflateRect(2, 2);
return true;
#endif
}
//Get text rect
//Return false if none
bool CQuickList::GetTextRect(const int item, const int subitem, CRect& rect)
{
CQuickList::CListItemData& data = GetItemData(item, subitem);
return GetTextRect(data, rect);
}
//Get text rect
//Return false if none
bool CQuickList::GetTextRect(CQuickList::CListItemData& id, CRect& rect)
{
GetSubItemRect(id.GetItem(), id.GetSubItem(), LVIR_BOUNDS, rect);
CRect temp;
//Move if image
if( GetImageRect(id, temp, false) )
rect.left = temp.right;
else if( GetCheckboxRect(id, temp, false) )
rect.left = temp.right;
return true;
}
//Get check box rect
//Return false if none
bool CQuickList::GetCheckboxRect(const int item, const int subitem, CRect& rect, bool checkOnly)
{
CQuickList::CListItemData& data = GetItemData(item, subitem);
return GetCheckboxRect(data, rect, checkOnly);
}
//Get check box rect
//Return false if none
bool CQuickList::GetCheckboxRect(CQuickList::CListItemData& id, CRect& rect, bool checkOnly)
{
#ifdef QUICKLIST_NOBUTTON
UNREFERENCED_PARAMETER(id);
UNREFERENCED_PARAMETER(rect);
return false;
#else
if(!id.m_button.m_draw)
return false;
CRect full;
GetSubItemRect(id.GetItem(), id.GetSubItem(), LVIR_BOUNDS, full);
rect = full;
int checkWidth = full.Height();
if(id.m_button.m_center)
{
rect.left = full.CenterPoint().x - (checkWidth)/2;
rect.right = full.CenterPoint().x + (checkWidth+1)/2;
}
else
rect.right = rect.left + checkWidth; // width = height
if(!checkOnly)
rect.left = full.left;
return true;
#endif
}
//Get image rect
//Return false if none
bool CQuickList::GetImageRect(const int item, const int subitem, CRect& rect, bool imageOnly)
{
CQuickList::CListItemData& data = GetItemData(item, subitem);
return GetImageRect(data, rect, imageOnly);
}
//Get image rect
//Return false if none
bool CQuickList::GetImageRect(CQuickList::CListItemData& id, CRect& rect, bool imageOnly)
{
#ifdef QUICKLIST_NOIMAGE
UNREFERENCED_PARAMETER(id);
UNREFERENCED_PARAMETER(rect);
UNREFERENCED_PARAMETER(imageOnly);
return false;
#else
if(id.m_image.m_imageID == -1)
return false;
GetSubItemRect(id.GetItem(), id.GetSubItem(), LVIR_BOUNDS, rect);
//If there is an image box we has to move the rect
int leftMarging = 1;
{
CRect chk;
if(GetCheckboxRect(id, chk, false))
{
leftMarging = 0;
rect.left = chk.right;
}
}
//Draw image?
if (id.m_image.m_imageList)
{
int nImage = id.m_image.m_imageID;
if (nImage < 0)
return false;
SIZE sizeImage;
sizeImage.cx = sizeImage.cy = 0;
IMAGEINFO info;
if (rect.Width() > 0 && id.m_image.m_imageList->GetImageInfo(nImage, &info))
{
//if imageOnly we only return the rect of the image.
//otherwise we also include area under and below image.
sizeImage.cx = info.rcImage.right - info.rcImage.left;
sizeImage.cy = info.rcImage.bottom - info.rcImage.top;
//Real size
SIZE size;
size.cx = rect.Width() < sizeImage.cx ? rect.Width() : sizeImage.cx;
size.cy = 1+rect.Height() < sizeImage.cy ? rect.Height() : sizeImage.cy;
POINT point;
point.y = rect.CenterPoint().y - (sizeImage.cy/2);
//Center image?
if(id.m_image.m_center)
point.x = rect.CenterPoint().x - (sizeImage.cx/2);
else
point.x = rect.left;
point.x += leftMarging;
//Out of area?
if(point.y<rect.top)
point.y = rect.top;
//
if( !imageOnly )
{
rect.right = point.x+sizeImage.cx;
}
else
//Make rect of point and size, and return this
rect = CRect(point, size);
return true;
}
}
return false;
#endif
}
//Draw an item in pDC
void CQuickList::DrawItem(int item, int subitem, CDC* pDC)
{
CListItemData id = GetItemData( item, subitem );
//Draw button?
#ifndef QUICKLIST_NOBUTTON
if(id.m_button.m_draw)
DrawButton(id, pDC);
#endif
//Draw image?
#ifndef QUICKLIST_NOIMAGE
if(id.m_image.m_imageID != -1)
DrawImage(id, pDC);
#endif
//Draw progressbar?
#ifndef QUICKLIST_NOPROGRESSBAR
if(id.m_progressBar.m_maxvalue > 0)
DrawProgressBar(id, pDC);
#endif
DrawText(id, pDC);
}
#ifndef QUICKLIST_NOIMAGE
//Draw image
void CQuickList::DrawImage( CQuickList::CListItemData& id,
CDC* pDC)
{
CRect imgRect;
if(GetImageRect(id, imgRect, false))
{
CImageList* pImageList = id.m_image.m_imageList;
COLORREF blendColor = GetBackColor(id);
// save image list background color
COLORREF rgb = pImageList->GetBkColor();
// set image list background color
pImageList->SetBkColor( GetBackColor(id, id.m_image.m_noSelection || id.m_noSelection));
//Fill background
FillSolidRect( pDC,
imgRect,
GetBackColor(id, id.m_image.m_noSelection || id.m_noSelection)
);
GetImageRect(id, imgRect, true);
if( id.m_noSelection ||
!id.IsSelected() ||
id.m_image.m_blend == 0 ||
blendColor == TRANSPARENTCOLOR)
{
pImageList->DrawIndirect( pDC,
id.m_image.m_imageID,
imgRect.TopLeft(),
imgRect.Size(),
CPoint(0, 0));
}
else
{
pImageList->DrawIndirect( pDC,
id.m_image.m_imageID,
imgRect.TopLeft(),
imgRect.Size(),
CPoint(0, 0),
ILD_NORMAL|id.m_image.m_blend,
SRCCOPY,
CLR_DEFAULT,
blendColor);
}
pImageList->SetBkColor(rgb);
}
return;
}
#endif
//Draw text
void CQuickList::DrawText( CQuickList::CListItemData& id,
CDC* pDC)
{
ASSERT(pDC);
CRect rect, fulltextrect;
#ifndef QUICKLIST_NOPROGRESSBAR
if(id.m_progressBar.m_maxvalue > 0)
GetProgressRect(id, rect, true);
else
#endif
{
GetTextRect(id, rect);
}
fulltextrect = rect;
if(id.m_text.IsEmpty())
{
//Just clean if no progress bar
#ifndef QUICKLIST_NOPROGRESSBAR
if(id.m_progressBar.m_maxvalue <= 0)
#endif
FillSolidRect( pDC,
fulltextrect,
GetBackColor(id, !FullRowSelect() || id.m_noSelection));
}
else
{
UINT textFormat=0;
#ifdef QUICKLIST_NOTEXTSTYLE
textFormat = DT_VCENTER | DT_SINGLELINE | DT_END_ELLIPSIS | GetTextJustify(id.GetSubItem());
#else
CFont *pOldFont = NULL;
CFont boldfont;
textFormat = id.m_textStyle.m_textPosition;
// check if bold specified for subitem
if (id.m_textStyle.m_bold || id.m_textStyle.m_italic)
{
CFont *font = pDC->GetCurrentFont();
if (font)
{
LOGFONT lf;
font->GetLogFont(&lf);
if(id.m_textStyle.m_bold)
lf.lfWeight = FW_BOLD;
if(id.m_textStyle.m_italic)
lf.lfItalic = TRUE;
boldfont.CreateFontIndirect(&lf);
pOldFont = pDC->SelectObject(&boldfont);
}
}
#endif
CString text = id.m_text;
//If we don't do this, character after & will be underlined.
text.Replace(_T("&"), _T("&&"));
#ifndef QUICKLIST_NOPROGRESSBAR
if(id.m_progressBar.m_maxvalue <= 0)
#endif
{
rect.left += 2;
pDC->SetTextColor( GetTextColor(id, id.m_noSelection) );
COLORREF backColor = GetBackColor(id, id.m_noSelection);
{
/* //Calculate rect area
CRect textRect=rect;
pDC->DrawText(text, &textRect, textFormat|DT_CALCRECT);
//Draw background, but exclude the text area
pDC->SaveDC();
pDC->ExcludeClipRect(textRect);
*/
FillSolidRect( pDC,
fulltextrect,
GetBackColor(id, !FullRowSelect() || id.m_noSelection)
);
// pDC->RestoreDC(-1);
}
if( backColor == TRANSPARENTCOLOR)
pDC->SetBkMode(TRANSPARENT);
else
{
pDC->SetBkMode(OPAQUE);
pDC->SetBkColor( backColor );
}
pDC->DrawText(text, &rect, textFormat);
}
#ifndef QUICKLIST_NOPROGRESSBAR
else
{
//Draw text in progress bar. We have to split the text in two parts
pDC->SetBkMode(TRANSPARENT);
CRect inRect = rect;
inRect.right = inRect.left + GetBarSize(id, inRect);
COLORREF fillText = id.m_progressBar.m_fillTextColor;
if(fillText == DEFAULTCOLOR)
fillText = ::GetSysColor(COLOR_HIGHLIGHTTEXT);
//Draw first text...
pDC->SaveDC();
pDC->IntersectClipRect(inRect);
pDC->SetTextColor( fillText ); //GetTextColor(id, false, true) );
pDC->DrawText(text, &rect, textFormat);
pDC->RestoreDC(-1);
pDC->SaveDC();
pDC->ExcludeClipRect(inRect);
pDC->SetTextColor( GetTextColor(id, true) );
pDC->DrawText(text, &rect, textFormat);
pDC->RestoreDC(-1);
}
#endif
#ifndef QUICKLIST_NOTEXTSTYLE
if (pOldFont)
pDC->SelectObject(pOldFont);
#endif
}
if( IsColumnNavigationOn() &&
GetNavigationColumn() == id.GetSubItem() &&