OWLNext    7.0
Borland's Object Windows Library for the modern age
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
listviewctrl.cpp
Go to the documentation of this file.
1//
2/// \file
3/// Implementation of TListViewCtrl and support classes
4//
5// Part of OWLNext - the next generation Object Windows Library
6// Copyright (c) 1995, 1996 by Borland International, All Rights Reserved
7// Copyright (c) 2011 Vidar Hasfjord
8//
9// For more information, including license details, see
10// http://owlnext.sourceforge.net
11//
12
13#include <owl/pch.h>
14
15#include <owl/listviewctrl.h>
16#include <owl/system.h>
17#include <algorithm>
18
19#if defined(__BORLANDC__)
20# pragma option -w-ccc // Disable "Condition is always true/false"
21#endif
22
23namespace owl {
24
26
27//----------------------------------------------------------------------------
28// TLvFindInfo
29
30//
31/// Constructs with an empty string and parameter.
32//
34{
35 flags = 0;
36 psz = nullptr;
37 lParam = 0;
38
39 Text.resize(0);
40}
41
42//
43/// Constructs a copy of another class instance.
44//
45/// @param[in] findInfo is the class instance to copy.
46//
48{
49 *static_cast<LVFINDINFO*>(this) = findInfo;
50 if ((flags & LVFI_STRING) || (flags & LVFI_PARTIAL))
51 {
52 Text = findInfo.psz;
53 psz = Text.c_str();
54 }
55}
56
57//
58/// Sets a string to be used for the search.
59//
60/// @param[in] text is the string to use.
61//
62/// \return none.
63//
64auto
66{
67 flags |= LVFI_STRING;
68 Text = text;
69 psz = Text.c_str();
70}
71
72//
73/// Sets a string to be used for an exact search.
74//
75/// @param[in] text is the string to use.
76//
77/// \return none.
78//
79auto
81{
82 flags &= ~LVFI_PARTIAL;
83 SetString(text);
84}
85
86//
87/// Sets a string to be used for a partial search.
88//
89/// @param[in] text is the string to use.
90//
91/// \return none.
92//
93auto
95{
96 flags |= LVFI_PARTIAL;
97 SetString(text);
98}
99
100//
101/// Sets the setting for wrap-around during a search.
102//
103/// @param[in] wrap specifies whether the search continues at the beginning when the end has been reached.
104//
105/// \return none.
106//
107auto
109{
110 if (wrap)
111 flags |= LVFI_WRAP;
112 else
113 flags &= ~LVFI_WRAP;
114}
115
116//
117/// Sets extra application-specific information.
118//
119/// @param[in] param is the extra information to set.
120//
121/// \return none.
122//
123auto
125{
126 flags |= LVFI_PARAM;
127 lParam = param;
128}
129
130//----------------------------------------------------------------------------
131// TLvItem
132
133//
134/// Constructs an empty parameter package.
135//
136/// This constructor is typically used to retrieve information about an existing item.
137/// For example,
138//
139/// \code
140/// TLvItem item;
141/// bool success = ListWindow.GetItem(item, index, subitemIndex);
142/// if (success && item.GetText()) ShowString(item.GetText());
143/// \endcode
144//
145/// @param[in] mask_ is the mask to use.
146/// @param[in] allocTextBuffer if true, then a character buffer is allocated, and pszText is set to point to it.
147/// @param[in] bufferSize is the size of the text characters to allocate and use if allocTextBuffer is true.
148//
150{
151 Init();
152 if (allocTextBuffer)
153 {
154 CHECK(bufferSize > 0);
155 Buffer.resize(bufferSize);
157 }
158 mask = mask_;
159}
160
161//
162/// Constructs a parameter package with the given text.
163//
164/// The given text is copied to the internal buffer, and pszText will point to the internal copy.
165/// For example,
166//
167/// \code
168/// TLvItem item("Item");
169/// ListWindow.AddItem(item);
170/// \endcode
171//
172/// @param[in] text is the string to use.
173/// @param[in] subitemIndex is the subitem index to use.
174//
181
182//
183/// Constructs a parameter package based on the item attributes of an existing control.
184//
185/// @param[in] ctl is an existing list-view control from which to copy.
186/// @param[in] index is the item index of the existing list-view control to use for copying.
187/// @param[in] subitemIndex is the subitem index to use.
188/// @param[in] mask_ is the mask to use for copying.
189/// @param[in] bufferSize is the size of the text characters to allocate and use, provided the mask includes LVIF_TEXT.
190//
192{
193 PRECONDITION(ctl.GetHandle());
194 Init();
195 mask = mask_;
196 if (mask_ & LVIF_TEXT)
197 {
198 CHECK(bufferSize > 0);
199 Buffer.resize(bufferSize);
201 }
202 ctl.GetItem(*this, index, subitemIndex);
203}
204
205//
206/// Constructs a parameter package from an existing parameter package.
207//
208/// A deep copy is performed; see the assignment operator for `const LVITEM&` for details.
209//
210/// @param[in] item is an existing list-view item class from which to copy.
211//
212TLvItem::TLvItem(const LVITEM& item)
213{
214 *this = item;
215}
216
217//
218/// Constructs a parameter package from an existing parameter package.
219//
220/// A deep copy is performed; see the copy assignment operator for details.
221//
222/// @param[in] item is an existing list-view item class from which to copy.
223//
225{
226 *this = item;
227}
228
229//
230/// Overloads the assignment operator to perform a deep copy using a separate string buffer if applicable.
231//
232/// @param[in] item is an existing list-view item class from which to copy.
233//
234auto
235TLvItem::operator =(const LVITEM& item) -> TLvItem&
236{
237 *static_cast<LVITEM*>(this) = item;
239 SetText(pszText);
240 return *this;
241}
242
243//
244/// Copies the given parameter package.
245//
246/// A deep copy is performed; see the assignment operator for `const LVITEM&` for details.
247//
248auto
250{
251 return operator =(static_cast<const LVITEM&>(item));
252}
253
254//
255/// Retrieves the current text for the item.
256//
257/// \note This might point to the internal text buffer, or to an external buffer.
258//
259/// \return a pointer to the text which will be nullptr if not used.
260//
261/// \sa SetTextBuffer.
262//
263auto
265{
266 // Return early if we have no text to return.
267 //
268 if (!(mask & LVIF_TEXT) || (pszText == LPSTR_TEXTCALLBACK) || (cchTextMax <= 0)) return nullptr;
269
270 // Check the length of the text; throw if it lacks termination within bounds.
271 //
272 LPTSTR i = std::find(pszText, pszText + cchTextMax, _T('\0'));
273 size_t n = i - pszText;
274 size_t m = static_cast<size_t>(cchTextMax);
275 CHECK(n <= m);
276 if (n == m) throw TXOwl(_T("TLvItem::GetText: Buffer overflow"));
277 return pszText;
278}
279
280//
281/// Copies the current text for the item.
282//
283/// @param[out] buffer upon return will contain the text string.
284/// @param[in] bufferSize specifies the maximum number of characters to copy;
285/// to determine an adequate size use (_tcslen(GetText()) + 1).
286//
287/// \return none.
288//
289auto
291{
293
294 // First, check that there is room in the buffer; if not, then throw.
295 // We could just return here, but that would leave the buffer in an undefined state,
296 // with no indication that there was a problem.
297 //
298 if (bufferSize == 0) throw TXOwl(_T("TLvItem::GetText: Buffer size is 0"));
299
300 // Now initialize the buffer, then return early if we have no text to copy.
301 //
302 buffer[0] = _T('\0');
303 LPCTSTR text = GetText();
304 if (!text) return;
305
306 // Finally, we are ready to copy.
307 // We give a warning if we truncate the result here (but, ideally, we should throw).
308 //
309 size_t textLength = _tcslen(pszText);
310 CHECK(textLength < static_cast<size_t>(cchTextMax));
311 WARN(textLength >= bufferSize, _T("TLvItem::GetText: Truncation"));
312 size_t n = std::min(textLength, bufferSize - 1);
313 std::copy(pszText, pszText + n, buffer);
314 buffer[n] = _T('\0');
315}
316
317//
318/// Overrides the internal buffer and assigns an external text buffer.
319//
320/// Sets the pszText and cchTextMax members of LVITEM, and enables the LVIF_TEXT flag.
321//
322/// \note This function does not copy the text!
323//
324/// @param[in] buffer pointer to a text string buffer to use.
325/// @param[in] bufferSize specifies the size of the text string buffer.
326//
327/// \return none.
328//
329auto
336
337//
338/// Copies the given text into the internal text buffer.
339//
340/// Sets the pszText and cchTextMax members of LVITEM, and enables the LVIF_TEXT flag.
341//
342/// \note If the string is larger than what can be represented by the class, i.e. INT_MAX, then
343/// a TXOwl exception is thrown.
344//
345/// @param[in] text is the string to copy.
346//
347/// \return none.
348//
349auto
351{
352 if (!IsRepresentable<int>(text.size() + 1))
353 throw TXOwl(_T("TLvItem::SetText: The text argument is too large (>INT_MAX)"));
354
355 Buffer.assign(text.begin(), text.end());
356 Buffer.push_back(_T('\0'));
357 SetTextBuffer(&Buffer[0], static_cast<int>(Buffer.size()));
358}
359
360//
361/// Retrieves the item index.
362//
363/// \return the item index.
364//
365auto
366TLvItem::GetIndex() const -> int
367{
368 return iItem;
369}
370
371//
372/// Sets the item index.
373//
374/// @param[in] index the item index.
375//
376/// \return none.
377//
378auto
379TLvItem::SetIndex(int index) -> void
380{
381 iItem = index;
382}
383
384//
385/// Retrieves the subitem index.
386//
387/// \return the subitem index.
388//
389auto
391{
392 return iSubItem;
393}
394
395//
396/// Sets the subitem index.
397//
398/// @param[in] subitemIndex the subitem index.
399//
400/// \return none.
401//
402auto
407
408//
409/// Retrieves the application-defined data.
410//
411/// \return the application-defined data, or 0 if not used.
412//
413auto
415{
416 return (mask & LVIF_PARAM) ? lParam : 0;
417}
418
419//
420/// Sets the application-defined data.
421//
422/// @param[in] param the application-defined data.
423//
424/// \return none.
425//
426auto
428{
429 mask |= LVIF_PARAM;
430 lParam = param;
431}
432
433//
434/// Retrieves the current image index used for the item.
435//
436/// \return the image index, or -1 if not used.
437//
438auto
440{
441 return (mask & LVIF_IMAGE) ? iImage : -1;
442}
443
444//
445/// Sets the image index within the image list to use.
446//
447/// @param[in] image is the image index to use.
448//
449/// \return none.
450//
451auto
453{
454 mask |= LVIF_IMAGE;
455 iImage = image;
456}
457
458//
459/// Retrieves the current state used for the item.
460//
461/// \return the state, or 0 if not used.
462//
463auto
464TLvItem::GetState() const -> int
465{
466 return (mask & LVIF_STATE) ? state : 0;
467}
468
469//
470/// Sets the state to use.
471//
472/// @param[in] newState is the state to use.
473//
474/// \return none.
475//
476auto
478{
479 mask |= LVIF_STATE;
480 stateMask |= state;
481 state = newState;
482}
483
484//
485/// Retrieves the current state image index used for the item.
486//
487/// \return the state image index, or -1 if not used.
488//
489auto
491{
492 return ((mask & LVIF_STATE) && (stateMask & LVIS_STATEIMAGEMASK)) ? (state >> 12) - 1 : -1;
493}
494
495//
496/// Sets the state image index to use.
497//
498/// @param[in] stateIndex is the state image index to use.
499//
500/// \return none.
501//
502auto
509
510//
511/// Retrieves the current number of image widths to indent the item.
512//
513/// \return the number of image widths, or -1 if not used.
514//
515auto
516TLvItem::GetIndent() const -> int
517{
518 return (mask & LVIF_INDENT) ? iIndent : -1;
519}
520
521//
522/// Sets the number of image widths to indent the item.
523//
524/// @param[in] indent the number of image widths to use.
525//
526/// \return none.
527//
528auto
530{
531 mask |= LVIF_INDENT;
532 iIndent = indent;
533}
534
535//
536/// Initializes member data; used by internal routines.
537//
538/// \return none.
539//
540auto
542{
543 memset(static_cast<LVITEM*>(this), 0, sizeof(LVITEM));
544}
545
546//----------------------------------------------------------------------------
547// TLvColumn
548
549//
550/// Constructs an empty parameter package.
551//
552/// This constructor is typically used to retrieve information about an existing column.
553/// For example,
554//
555/// \code
556/// TLvColumn col;
557/// bool success = ListWnd.GetColumn(1, col);
558/// if (success && col.GetText()) ShowString(col.GetText());
559/// \endcode
560//
561/// @param[in] mask_ is the mask to use.
562/// @param[in] subitemIndex is the subitem index to use.
563/// @param[in] bufferSize is the size of the text characters to allocate and use, provided the mask includes LVCF_TEXT.
564//
566{
567 Init();
568 mask = mask_;
570 if (mask_ & LVCF_TEXT)
571 {
572 CHECK(bufferSize > 0);
573 Buffer.resize(bufferSize);
575 }
576}
577
578//
579/// Constructs a parameter package based on the given text, width, format, and subitem.
580//
581/// @param[in] text is the string to use.
582/// @param[in] width is the pixel width to use the column; if 0, a width will be calculated by SetWidth.
583/// @param[in] how specifies the formatting to use for the string.
584/// @param[in] subitemIndex is the subitem index to use.
585//
587{
588 Init();
589 SetText(text);
590 SetWidth(width, text);
591 SetFormat(how);
593}
594
595//
596/// Constructs a parameter package based on the column attributes of an existing control.
597//
598/// @param[in] ctl is an existing list-view control from which to copy.
599/// @param[in] index is the item index of the existing list-view control to use for copying.
600/// @param[in] mask_ is the mask to use for copying.
601/// @param[in] subitemIndex is the subitem index to use.
602/// @param[in] bufferSize is the size of the text characters to allocate and use, provided the mask includes LVCF_TEXT.
603//
605{
606 PRECONDITION(ctl.GetHandle());
607 Init();
608 mask = mask_;
610 if (mask_ & LVCF_TEXT)
611 {
612 CHECK(bufferSize > 0);
613 Buffer.resize(bufferSize);
615 }
616 ctl.GetColumn(index, *this);
617}
618
619//
620/// Constructs a parameter package from an existing parameter package.
621//
622/// A deep copy is performed; see the assignment operator for `const LVCOLUMN&` for details.
623//
624/// @param[in] column is an existing list-view column class from which to copy.
625//
627{
628 *this = column;
629}
630
631//
632/// Constructs a parameter package from an existing parameter package.
633//
634/// A deep copy is performed; see the copy assignment operator for details.
635//
636/// @param[in] column is an existing list-view column class from which to copy.
637//
639{
640 *this = column;
641}
642
643//
644/// Overloads the assignment operator to perform a deep copy using a separate string buffer if applicable.
645//
646/// @param[in] column is an existing list-view column class from which to copy.
647//
648auto
650{
651 *static_cast<LVCOLUMN*>(this) = column;
652 if ((mask & LVCF_TEXT) && pszText)
653 SetText(pszText);
654 return *this;
655}
656
657//
658/// Copies the given parameter package.
659//
660/// A deep copy is performed; see the assignment operator for `const LVCOLUMN&` for details.
661//
662auto
664{
665 return operator =(static_cast<const LVCOLUMN&>(column));
666}
667
668//
669/// Overrides the internal buffer and assigns an external text buffer.
670//
671/// Sets the pszText and cchTextMax members of LVCOLUMN, and enables the LVCF_TEXT flag.
672//
673/// \note This function does not copy the text!
674//
675/// @param[in] buffer pointer to a text string buffer to use.
676/// @param[in] bufferSize specifies the size of the text string buffer.
677//
678/// \return none.
679//
680auto
687
688//
689/// Copies the given text into the internal text buffer.
690//
691/// Sets the pszText and cchTextMax members of LVCOLUMN, and enables the LVCF_TEXT flag.
692//
693/// \note If the string is larger than what can be represented by the class, i.e. INT_MAX, then
694/// a TXOwl exception is thrown.
695//
696/// @param[in] text is the string to copy.
697//
698/// \return none.
699//
700auto
702{
703 if (!IsRepresentable<int>(text.size() + 1))
704 throw TXOwl(_T("TLvColumn::SetText: The text argument is too large (>INT_MAX)"));
705
706 Buffer.assign(text.begin(), text.end());
707 Buffer.push_back(_T('\0'));
708 SetTextBuffer(&Buffer[0], static_cast<int>(Buffer.size()));
709}
710
711//
712/// Sets the alignment format for the column.
713//
714/// @param[in] how specifies the formatting to use for the string.
715//
716/// \return none.
717//
718auto
720{
721 if (how != Unspecified)
722 {
723 mask |= LVCF_FMT;
724 fmt = static_cast<int>(how);
725 }
726}
727
728//
729/// Sets the width of the column.
730//
731/// @param[in] width is the pixel width to use the column; if 0, a width will be calculated by
732/// using the default GUI system font for the string.
733/// @param[in] text is the string to use for calculating a width when width is 0.
734//
735/// \return none.
736//
737/// \sa TListViewCtrl::GetStringWidth(const tstring&) const
738/// \sa TListViewCtrl::CalculateColumnWidth(const tstring&, int padding) const
739//
740auto
741TLvColumn::SetWidth(int width, const tstring& text) -> void
742{
743 mask |= LVCF_WIDTH;
744 cx = (width || !text.length()) ? width : TDefaultGuiFont(TDefaultGuiFont::sfiIcon).GetTextExtent(text).cx;
745}
746
747//
748/// Sets the subitem index.
749//
750/// @param[in] subitemIndex is the subitem index to use.
751//
752/// \return none.
753//
754auto
760
761//
762/// Retrieves the current text for the column.
763//
764/// \return a pointer to the text which will be nullptr if not used.
765//
766auto
768{
769 return pszText;
770}
771
772//
773/// Retrieves the current alignment format for the column.
774//
775/// \return the alignment format.
776//
777auto
779{
780 return (mask & LVCF_FMT) ? TFormat(fmt) : Unspecified;
781}
782
783//
784/// Retrieves the current width for the column.
785//
786/// \return the pixel width, or -1 if not used.
787//
788auto
790{
791 return (mask & LVCF_WIDTH) ? cx : -1;
792}
793
794//
795/// Retrieves the current subitem used for the column.
796//
797/// \return the subitem index, or -1 if not used.
798//
799auto
801{
802 return (mask & LVCF_SUBITEM) ? iSubItem : -1;
803}
804
805//
806/// Retrieves the current image index used for the column.
807//
808/// \return the image index, or -1 if not used.
809//
810auto
812{
813 return (mask & LVCF_IMAGE) ? iImage : -1;
814}
815
816//
817/// Sets the image index within the image list to use.
818//
819/// @param[in] image is the image index to use.
820//
821/// \return none.
822//
823auto
825{
826 mask |= LVCF_IMAGE;
827 iImage = image;
828}
829
830//
831/// Retrieves the current column order offset used for the column.
832//
833/// \return the column order offset, or -1 if not used.
834//
835auto
837{
838 return (mask & LVCF_ORDER) ? iOrder : -1;
839}
840
841//
842/// Sets the column order offset.
843//
844/// @param[in] order is the zero-based left-to-right column offset to use.
845//
846/// \return none.
847//
848auto
850{
851 mask |= LVCF_ORDER;
852 iOrder = order;
853}
854
855//
856/// Initializes member data; used by internal routines.
857//
858/// \return none.
859//
860auto
862{
863 memset(static_cast<LVCOLUMN*>(this), 0, sizeof(LVCOLUMN));
864}
865
866//----------------------------------------------------------------------------
867// TLvTileViewInfo
868
869//
870/// Constructs an automatic-sized tile view.
871//
873{
874 cbSize = sizeof(LVTILEVIEWINFO);
875 dwMask = 0;
877 sizeTile = {0, 0};
878 cLines = 0;
879 rcLabelMargin = {0, 0, 0, 0};
880}
881
882//
883/// Constructs an automatic-sized tile view specified with
884/// the maximum number of text lines in each item label.
885//
886/// @param[in] lines the maximum number of text lines in each item label.
887//
889{
890 cbSize = sizeof(LVTILEVIEWINFO);
893 sizeTile = {0, 0};
894 cLines = lines;
895 rcLabelMargin = {0, 0, 0, 0};
896}
897
898//
899/// Constructs an automatic-sized tile view specified with
900/// the coordinates of the label margin.
901//
902/// @param[in] labelMargin the coordinates of the label margin.
903//
905{
906 cbSize = sizeof(LVTILEVIEWINFO);
909 sizeTile = {0, 0};
910 cLines = 0;
912}
913
914//
915/// Constructs an automatic-sized tile view specified with
916/// the maximum number of text lines in each item label
917/// and
918/// the coordinates of the label margin.
919//
920/// @param[in] lines the maximum number of text lines in each item label.
921/// @param[in] labelMargin the coordinates of the label margin.
922//
924{
925 cbSize = sizeof(LVTILEVIEWINFO);
928 sizeTile = {0, 0};
929 cLines = lines;
931}
932
933//
934/// Constructs an fixed-sized tile view.
935//
936/// @param[in] size the tile size.
937/// @param[in] fixedSize the fixed-size type.
938//
940{
941 cbSize = sizeof(LVTILEVIEWINFO);
943 dwFlags = static_cast<DWORD>(fixedSize);
944 sizeTile = size;
945 cLines = 0;
946 rcLabelMargin = {0, 0, 0, 0};
947}
948
949//
950/// Constructs an fixed-sized tile view specified with
951/// the maximum number of text lines in each item label.
952//
953/// @param[in] size the tile size.
954/// @param[in] fixedSize the fixed-size type.
955/// @param[in] lines the maximum number of text lines in each item label.
956//
958{
959 cbSize = sizeof(LVTILEVIEWINFO);
961 dwFlags = static_cast<DWORD>(fixedSize);
962 sizeTile = size;
963 cLines = lines;
964 rcLabelMargin = {0, 0, 0, 0};
965}
966
967//
968/// Constructs an fixed-sized tile view specified with
969/// the coordinates of the label margin.
970//
971/// @param[in] size the tile size.
972/// @param[in] fixedSize the fixed-size type.
973/// @param[in] labelMargin the coordinates of the label margin.
974//
976{
977 cbSize = sizeof(LVTILEVIEWINFO);
979 dwFlags = static_cast<DWORD>(fixedSize);
980 sizeTile = size;
981 cLines = 0;
983}
984
985//
986/// Constructs an fixed-sized tile view specified with
987/// the maximum number of text lines in each item label
988/// and
989/// the coordinates of the label margin.
990//
991/// @param[in] size the tile size.
992/// @param[in] fixedSize the fixed-size type.
993/// @param[in] lines the maximum number of text lines in each item label.
994/// @param[in] labelMargin the coordinates of the label margin.
995//
997{
998 cbSize = sizeof(LVTILEVIEWINFO);
1000 dwFlags = static_cast<DWORD>(fixedSize);
1001 sizeTile = size;
1002 cLines = lines;
1004}
1005
1006//
1007/// Sets the tile view size to automatic.
1008//
1009/// \return none.
1010//
1011auto
1017
1018//
1019/// Sets the tile view size to fixed-width and/or fixed-height.
1020//
1021/// @param[in] size the tile size.
1022/// @param[in] fixedSize the fixed-size type.
1023//
1024/// \return none.
1025//
1026auto
1028{
1029 dwFlags = static_cast<DWORD>(fixedSize);
1030 sizeTile = size;
1032}
1033
1034//
1035/// Sets the specified maximum number of text lines in each item label.
1036//
1037/// @param[in] lines the maximum number of text lines in each item label.
1038//
1039/// \return none.
1040//
1041auto
1047
1048//
1049/// Removes the specified maximum number of text lines in each item label.
1050//
1051/// \return none.
1052//
1053auto
1059
1060//
1061/// Sets the specified coordinates of the label margin.
1062//
1063/// @param[in] labelMargin the coordinates of the label margin.
1064//
1065/// \return none.
1066//
1067auto
1073
1074//
1075/// Removes the specified coordinates of the label margin.
1076//
1077/// \return none.
1078//
1079auto
1085
1086//
1087/// Sets the specified tile size.
1088//
1089/// @param[in] size the tile size.
1090//
1091/// \return none.
1092//
1093auto
1095{
1096 sizeTile = size;
1097}
1098
1099//----------------------------------------------------------------------------
1100// TListViewCtrl
1101
1102//
1103/// Constructor that simply passes the parameters to the parent
1104/// \link TControl::TControl(TWindow*, int, LPCTSTR, int, int, int, int, TModule*) \endlink
1105/// and adds the extended style WS_EX_CLIENTEDGE.
1106//
1107TListViewCtrl::TListViewCtrl(TWindow* parent, int id, int x, int y, int w, int h, TModule* module)
1108:
1109 TControl(parent, id, 0, x, y, w, h, module)
1110{
1112 Attr.ExStyle |= WS_EX_CLIENTEDGE;
1113}
1114
1115//
1116/// Constructor that simply passes the parameters to the parent
1117/// \link TControl::TControl(TWindow*, int, TModule*) \endlink.
1118//
1125
1126//
1127/// Inserts a new column in a list-view control.
1128//
1129/// @param[in] colNum is the column number.
1130/// @param[in] column contains the column attributes.
1131//
1132/// \note Columns are visible only in report (details) view.
1133//
1134/// \return column number if successful, otherwise -1.
1135//
1136/// \sa http://msdn.microsoft.com/en-us/library/windows/desktop/bb761101.aspx
1137//
1138auto
1140{
1141 PRECONDITION(GetHandle());
1142 return static_cast<int>(SendMessage(LVM_INSERTCOLUMN, TParam1(colNum), TParam2(&column)));
1143}
1144
1145//
1146/// Deletes a column in a list-view control.
1147//
1148/// @param[in] colNum is the column number.
1149//
1150/// \return true if successful.
1151//
1152/// \sa http://msdn.microsoft.com/en-us/library/windows/desktop/bb774894.aspx
1153//
1154auto
1156{
1157 PRECONDITION(GetHandle());
1158 return ToBool(SendMessage(LVM_DELETECOLUMN, TParam1(colNum)));
1159}
1160
1161//
1162/// Retrieves the attributes of a list-view control's column.
1163//
1164/// @param[in] colNum is the column number.
1165/// @param[out] column contains the column attributes.
1166//
1167/// \return true if successful.
1168//
1169/// \sa http://msdn.microsoft.com/en-us/library/windows/desktop/bb774911.aspx
1170//
1171auto
1173{
1174 PRECONDITION(GetHandle());
1175 return ToBool(SendMessage(LVM_GETCOLUMN, TParam1(colNum), TParam2(&column)));
1176}
1177
1178//
1179/// Retrieves the width of a column in report or list view.
1180//
1181/// @param[in] colNum is the column number.
1182//
1183/// \return the column width.
1184//
1185/// \sa http://msdn.microsoft.com/en-us/library/windows/desktop/bb774915.aspx
1186//
1187auto
1189{
1190 PRECONDITION(GetHandle());
1191 return static_cast<int>(SendMessage(LVM_GETCOLUMNWIDTH, TParam1(colNum)));
1192}
1193
1194//
1195/// Sets the attributes of a list-view control's column.
1196//
1197/// @param[in] colNum is the column number.
1198/// @param[in] column contains the column attributes.
1199//
1200/// \return true if successful.
1201//
1202/// \sa http://msdn.microsoft.com/en-us/library/windows/desktop/bb761159.aspx
1203//
1204auto
1206{
1207 PRECONDITION(GetHandle());
1208 return ToBool(SendMessage(LVM_SETCOLUMN, TParam1(colNum), TParam2(&column)));
1209}
1210
1211//
1212/// Sets the width of a column in report or list view.
1213//
1214/// @param[in] colNum is the column number.
1215/// @param[in] width is the new column width.
1216//
1217/// \return true if successful.
1218//
1219/// \sa http://msdn.microsoft.com/en-us/library/windows/desktop/bb761163.aspx
1220//
1221auto
1223{
1224 PRECONDITION(GetHandle());
1225 return ToBool(SendMessage(LVM_SETCOLUMNWIDTH, TParam1(colNum), width));
1226}
1227
1228//
1229/// Retrieves a list-view item's attributes.
1230//
1231/// @param[in,out] item specifies the attributes to retrieve, and upon return contains those attributes.
1232/// @param[in] index is the item index, which overrides the setting in item unless -1.
1233/// @param[in] subitemIndex is the subitem index, which overrides the setting in item unless -1.
1234//
1235/// \return true if successful.
1236//
1237/// \sa http://msdn.microsoft.com/en-us/library/windows/desktop/bb774953.aspx
1238//
1239auto
1240TListViewCtrl::GetItem(TLvItem& item, int index, int subitemIndex) const -> bool
1241{
1242 PRECONDITION(GetHandle());
1243 if (index != -1)
1244 item.iItem = index;
1245 if (subitemIndex != -1)
1246 item.iSubItem = subitemIndex;
1247 return ToBool(SendMessage(LVM_GETITEM, 0, TParam2(&item)));
1248}
1249
1250//
1251/// TLvItem return overload for \link GetItem(TLvItem&, int, int) const \endlink.
1252//
1253/// @param[in] index is the item index, which defaults to the first item if -1.
1254/// @param[in] subitemIndex is the subitem index, which defaults to no subitem if -1.
1255//
1256/// \return TLvItem.
1257//
1258auto
1260{
1261 TLvItem item;
1262 auto r = GetItem(item, index, subitemIndex);
1263 WARN(!r, _T("TListViewCtrl::GetItem failed for index ") << index << _T(".") << subitemIndex); InUse(r);
1264 return item;
1265}
1266
1267//
1268/// Sets a list-view item's attributes.
1269//
1270/// @param[in] item contains the attributes to set.
1271/// @param[in] index is the item index, which overrides the setting in item unless -1.
1272/// @param[in] subitemIndex is the subitem index, which overrides the setting in item unless -1.
1273//
1274/// \return true if successful.
1275//
1276/// \sa http://msdn.microsoft.com/en-us/library/windows/desktop/bb761186.aspx
1277//
1278auto
1279TListViewCtrl::SetItem(const TLvItem& item, int index, int subitemIndex) -> bool
1280{
1281 PRECONDITION(GetHandle());
1282
1283 if (index != -1 || subitemIndex != -1)
1284 {
1285 LVITEM temp = item; // Make s shallow copy, just to pass to LVM_SETITEM
1286
1287 if (index != -1)
1288 temp.iItem = index;
1289 if (subitemIndex != -1)
1290 temp.iSubItem = subitemIndex;
1291
1292 return ToBool(SendMessage(LVM_SETITEM, 0, TParam2(&temp)));
1293 }
1294 else
1295 return ToBool(SendMessage(LVM_SETITEM, 0, TParam2(&item)));
1296}
1297
1298//
1299/// Searches for a list-view item that has the specified properties and bears
1300/// the specified relationship to a specified item.
1301//
1302/// @param[in] index is the item index to begin the search; -1 specifies to find the first item.
1303/// @param[in] flags is a combination of TNextItemCode flags that specify the relationship to the item given by index.
1304//
1305/// \return item index if found, otherwise -1.
1306//
1307/// \sa http://msdn.microsoft.com/en-us/library/windows/desktop/bb761057.aspx, TListViewCtrl::TNextItemCode
1308//
1309auto
1310TListViewCtrl::GetNextItem(int index, uint flags) const -> int
1311{
1312 PRECONDITION(GetHandle());
1313 return static_cast<int>(SendMessage(LVM_GETNEXTITEM, TParam1(index), flags));
1314}
1315
1316//
1317/// Retrieves the number of items in the list-view control.
1318//
1319/// \return number of items.
1320//
1321/// \sa http://msdn.microsoft.com/en-us/library/windows/desktop/bb761044.aspx
1322//
1323auto
1325{
1327 return static_cast<int>(SendMessage(LVM_GETITEMCOUNT));
1328}
1329
1330//
1331/// Sets the number of items that the list-view control will ultimately contain.
1332//
1333/// Causes the list-view control to allocate memory for the number of items
1334/// specified in `numItems` or sets the virtual number of items for a virtual
1335/// list-view control depending on how the control was created, and returns
1336/// whether successful.
1337//
1338/// @param[in] numItems is the new number of items.
1339/// @param[in] behavior is the behavior of the list-view control after setting the item count.
1340//
1341/// \note
1342/// -# If the list-view control was created without the LVS_OWNERDATA style,
1343/// sending this message causes the control to allocate its internal data
1344/// structures for the specified number of items. This prevents the control from
1345/// having to allocate the data structures every time an item is added.
1346/// -# If the list-view control was created with the LVS_OWNERDATA style (a virtual
1347/// list-view), sending this message sets the virtual number of items that the
1348/// control contains.
1349/// -# The `behavior` parameter is intended only for controls
1350/// that use the LVS_OWNERDATA and LVS_REPORT or LVS_LIST styles.
1351//
1352/// \return true if successful.
1353//
1354/// \sa http://msdn.microsoft.com/en-us/library/windows/desktop/bb761188.aspx
1355//
1356auto
1358{
1359 PRECONDITION(GetHandle());
1360 return ToBool(SendMessage(LVM_SETITEMCOUNT, TParam1(numItems), behavior));
1361}
1362
1363//
1364/// Retrieves the position of a list-view item.
1365//
1366/// @param[in] index is the item index.
1367/// @param[out] pt is where the position will be stored.
1368//
1369/// \return true if successful.
1370//
1371/// \sa http://msdn.microsoft.com/en-us/library/windows/desktop/bb761048.aspx
1372//
1373auto
1374TListViewCtrl::GetItemPosition(int index, TPoint& pt) const -> bool
1375{
1376 PRECONDITION(GetHandle());
1377 return ToBool(SendMessage(LVM_GETITEMPOSITION, TParam1(index), TParam2(&pt)));
1378}
1379
1380//
1381/// TPoint return overload for \link GetItemPosition(int, TPoint&) const \endlink.
1382//
1383/// @param[in] index is the item index.
1384//
1385/// \return position of the list-view item.
1386//
1387auto
1389{
1390 TPoint pt;
1391 auto r = GetItemPosition(index, pt);
1392 WARN(!r, _T("TListViewCtrl::GetItemPosition failed for index ") << index); InUse(r);
1393 return pt;
1394}
1395
1396//
1397/// Sets the position of a list-view item.
1398//
1399/// @param[in] index is the item index.
1400/// @param[in] pt is the new item position.
1401//
1402/// \note If the coordinates are outside valid range, a TXOwl exception is thrown. Use
1403/// \link SetItemPosition32 \endlink to avoid this.
1404//
1405/// \return true if successful.
1406//
1407/// \sa http://msdn.microsoft.com/en-us/library/windows/desktop/bb761192.aspx
1408//
1409auto
1410TListViewCtrl::SetItemPosition(int index, const TPoint& pt) -> bool
1411{
1412 PRECONDITION(GetHandle());
1413 WARN(true, _T("TListViewCtrl::SetItemPosition: Use TListViewCtrl::SetItemPosition32 instead to avoid possible exception"));
1415 throw TXOwl(_T("TListViewCtrl:SetItemPosition: Argument is outside valid range"));
1416 return ToBool(SendMessage(LVM_SETITEMPOSITION, TParam1(index), MkParam2(pt.x, pt.y)));
1417}
1418
1419//
1420/// Sets the position of a list-view item.
1421//
1422/// \note Must be in icon or small icon view.
1423//
1424/// @param[in] index is the item index.
1425/// @param[in] pt is the new item position.
1426//
1427/// \return none.
1428//
1429/// \sa http://msdn.microsoft.com/en-us/library/windows/desktop/bb761194.aspx
1430//
1431auto
1433{
1434 PRECONDITION(GetHandle());
1435 SendMessage(LVM_SETITEMPOSITION32, TParam1(index), TParam2(&pt));
1436}
1437
1438//
1439/// Retrieves the bounding rectangle of a list-view item.
1440//
1441/// @param[in] index is the item index.
1442/// @param[out] rect will contain the bounding rectangle.
1443/// @param[in] type specifies the type of rectangle to retrieve.
1444//
1445/// \return true if successful.
1446//
1447/// \sa http://msdn.microsoft.com/en-us/library/windows/desktop/bb761049.aspx
1448//
1449auto
1451{
1452 PRECONDITION(GetHandle());
1453 rect.left = type;
1454 return ToBool(SendMessage(LVM_GETITEMRECT, TParam1(index), TParam2(&rect)));
1455}
1456
1457//
1458/// TRect return overload for \link GetItemRect(int, TRect&, TItemRectType) const \endlink.
1459//
1460/// @param[in] index is the item index.
1461/// @param[in] type specifies the type of rectangle to retrieve.
1462//
1463/// \return the bounding rectangle.
1464//
1465auto
1467{
1468 TRect rect;
1469 auto r = GetItemRect(index, rect, type);
1470 WARN(!r, _T("TListViewCtrl::GetItemRect failed for index ") << index); InUse(r);
1471 return rect;
1472}
1473
1474//
1475/// Retrieves the current state for an item.
1476//
1477/// @param[in] index is the item index.
1478/// @param[in] mask specifies which state attributes to return.
1479//
1480/// \return current state of the item.
1481//
1482/// \sa http://msdn.microsoft.com/en-us/library/windows/desktop/bb761053.aspx
1483//
1484auto
1486{
1487 PRECONDITION(GetHandle());
1488 return static_cast<TLvItem::TListState>(SendMessage(LVM_GETITEMSTATE, TParam1(index), TParam2(mask)));
1489}
1490
1491//
1492/// Sets the current state for an item.
1493//
1494/// @param[in] index is the item index.
1495/// @param[in] state is the new item state.
1496/// @param[in] mask specifies which state attributes to set.
1497//
1498/// \return true if successful.
1499//
1500/// \sa http://msdn.microsoft.com/en-us/library/windows/desktop/bb761196.aspx
1501//
1502auto
1504{
1505 LVITEM item;
1506 item.state = state;
1507 item.stateMask = mask;
1508 return ToBool(SendMessage(LVM_SETITEMSTATE, index, TParam2(&item)));
1509}
1510
1511//
1512/// Retrieves the text of the item.
1513//
1514/// @param[in] index is the item index.
1515/// @param[in,out] item is the class where the buffer, buffer size, and subitem
1516/// index are specified. Before calling this function:
1517/// -# call item.SetTextBuffer(buffer, bufferSize) to set the buffer and buffer size
1518/// where the text will get stored.
1519/// -# call item.SetSubItem(subitemIndex) where subitemIndex is 0 to retrieve the
1520/// item text rather than the text of a subitem.
1521//
1522/// \return length of the retrieved string.
1523//
1524/// \sa http://msdn.microsoft.com/en-us/library/windows/desktop/bb761055.aspx
1525//
1526auto
1527TListViewCtrl::GetItemText(int index, TLvItem& item) const -> int
1528{
1529 PRECONDITION(GetHandle());
1530 return static_cast<int>(SendMessage(LVM_GETITEMTEXT, TParam1(index), TParam2(&item)));
1531}
1532
1533//
1534/// C string overload for \link GetItemText(int, TLvItem&) const \endlink.
1535//
1536/// @param[in] index is the item index.
1537/// @param[in] subitemIndex is the subitem index; 0 specifies to retrieve the
1538/// item text rather than the text of a subitem.
1539/// @param[out] buffer points to a buffer to hold the retrieved text.
1540/// @param[in] bufferSize is the size of the buffer pointed to by text.
1541//
1542/// \return length of the retrieved string.
1543//
1544auto
1546{
1547 PRECONDITION(GetHandle());
1548 TLvItem item;
1551 return GetItemText(index, item);
1552}
1553
1554//
1555/// String return overload for \link GetItemText(int, TLvItem&) const \endlink.
1556//
1557/// @param[in] index is the item index.
1558/// @param[in] subitemIndex is the subitem index; 0 specifies to retrieve the
1559/// item text rather than the text of a subitem.
1560//
1561/// \return retrieved string.
1562//
1563auto
1565{
1566 PRECONDITION(GetHandle());
1567 TLvItem item;
1569 SendMessage(LVM_GETITEMTEXT, TParam1(index), TParam2(&item));
1570 return item.GetText();
1571}
1572
1573//
1574/// Sets the text of a list-view item or subitem.
1575//
1576/// @param[in] index is the item index.
1577/// @param[in] item is the class where the buffer, buffer size, and subitem
1578/// index are specified. Before calling this function:
1579/// -# call item.SetTextBuffer(buffer, bufferSize) to set the buffer and buffer size
1580/// of the text to set.
1581/// -# call item.SetSubItem(subitemIndex) where subitemIndex is 0 to set the
1582/// item text rather than the text of a subitem.
1583//
1584/// \return true if successful.
1585//
1586/// \sa http://msdn.microsoft.com/en-us/library/windows/desktop/bb761198.aspx
1587//
1588auto
1589TListViewCtrl::SetItemText(int index, const TLvItem& item) -> bool
1590{
1591 PRECONDITION(GetHandle());
1592 return ToBool(SendMessage(LVM_SETITEMTEXT, TParam1(index), TParam2(&item)));
1593}
1594
1595//
1596/// C string overload for \link SetItemText(int, const TLvItem&) \endlink.
1597//
1598/// @param[in] index is the item index.
1599/// @param[in] subitemIndex is the subitem index; 0 specifies to set the
1600/// item text rather than the text of a subitem.
1601/// @param[in] text is the text to set.
1602//
1603/// \return true if successful.
1604//
1605auto
1607{
1608 PRECONDITION(GetHandle());
1609 return SetItemText(index, TLvItem(text, subitemIndex));
1610}
1611
1612//
1613/// String overload for \link SetItemText(int, const TLvItem&) \endlink.
1614//
1615/// @param[in] index is the item index.
1616/// @param[in] subitemIndex is the subitem index; 0 specifies to set the
1617/// item text rather than the text of a subitem.
1618/// @param[in] text is the text to set.
1619//
1620/// \return true if successful.
1621//
1622auto
1624{
1625 PRECONDITION(GetHandle());
1626 return SetItemText(index, subitemIndex, text.c_str());
1627}
1628
1629//
1630/// Adds a new item to the end of the list.
1631//
1632/// @param[in] item is the class containing the item.
1633//
1634/// \return the index of the new item if successful, otherwise -1.
1635//
1636/// \sa http://msdn.microsoft.com/en-us/library/windows/desktop/bb761107.aspx
1637//
1638auto
1640{
1641 PRECONDITION(GetHandle());
1642 return InsertItem(item, GetItemCount());
1643}
1644
1645//
1646/// Adds a new item with the given text to the end of the list.
1647//
1648/// @param[in] text is the text to add.
1649//
1650/// \return the index of the new item if successful, otherwise -1.
1651//
1652/// \sa http://msdn.microsoft.com/en-us/library/windows/desktop/bb761107.aspx
1653//
1654
1655auto
1657{
1658 TLvItem item(text.c_str());
1659 item.iItem = GetItemCount();
1660 return InsertItem(item);
1661}
1662
1663//
1664/// Inserts a new item to the list.
1665//
1666/// @param[in] item is the class containing the item.
1667/// @param[in] index is the item index to place the new item, which overrides
1668/// the setting in item unless -1.
1669//
1670/// \return the index of the new item if successful, otherwise -1.
1671//
1672/// \sa http://msdn.microsoft.com/en-us/library/windows/desktop/bb761107.aspx
1673//
1674auto
1675TListViewCtrl::InsertItem(const TLvItem& item, int index) -> int
1676{
1677 PRECONDITION(GetHandle());
1678 if (index != -1)
1679 {
1680 LVITEM temp = item; // Make s shallow copy, just to pass to LVM_INSERTITEM
1681 temp.iItem = index;
1682 return static_cast<int>(SendMessage(LVM_INSERTITEM, 0, TParam2(&temp)));
1683 }
1684 else
1685 return static_cast<int>(SendMessage(LVM_INSERTITEM, 0, TParam2(&item)));
1686}
1687
1688//
1689/// Inserts a new item with the given text to the list.
1690//
1691/// @param[in] text is the text to add.
1692/// @param[in] index is the item index to place the new item.
1693//
1694/// \return the index of the new item if successful, otherwise -1.
1695//
1696/// \sa http://msdn.microsoft.com/en-us/library/windows/desktop/bb761107.aspx
1697//
1698auto
1699TListViewCtrl::InsertItem(const tstring& text, int index) -> int
1700{
1701 TLvItem item(text.c_str());
1702 item.iItem = index;
1703 return InsertItem(item);
1704}
1705
1706//
1707/// Deletes an item from the list.
1708//
1709/// @param[in] index is the item index to delete.
1710//
1711/// \return true if successful.
1712//
1713/// \sa http://msdn.microsoft.com/en-us/library/windows/desktop/bb774895.aspx
1714//
1715auto
1717{
1718 PRECONDITION(GetHandle());
1719 return ToBool(SendMessage(LVM_DELETEITEM, TParam1(index)));
1720}
1721
1722//
1723/// Deletes all items from the list.
1724//
1725/// \return true if successful.
1726//
1727/// \sa http://msdn.microsoft.com/en-us/library/windows/desktop/bb774891.aspx
1728//
1729auto
1731{
1732 PRECONDITION(GetHandle());
1733 return ToBool(SendMessage(LVM_DELETEALLITEMS));
1734}
1735
1736//
1737/// Searches for an item with the specified characteristics.
1738//
1739/// @param[in] index is the item index from where to begin the search,
1740/// non-inclusive. If -1 the search will start from the beginning.
1741/// @param[in] findInfo is the class containing the search characteristics.
1742//
1743/// \return the index of the item if found, otherwise -1.
1744//
1745/// \sa http://msdn.microsoft.com/en-us/library/windows/desktop/bb774903.aspx
1746//
1747auto
1748TListViewCtrl::FindItem(int index, const TLvFindInfo& findInfo) const -> int
1749{
1750 PRECONDITION(GetHandle());
1751 return static_cast<int>(SendMessage(LVM_FINDITEM, TParam1(index), TParam2(&findInfo)));
1752}
1753
1754// Hidden from public structure and function by using anonymous namespace.
1755//
1756namespace
1757{
1758
1759 //
1760 // Create a temporary structure to store additional information for the
1761 // comparison object.
1762 //
1763 struct TListCompareThunk
1764 {
1765 const TListViewCtrl::TCompareFunc* This;
1766 LPARAM ItemData;
1767 };
1768
1770 {
1771 TListCompareThunk* ct = reinterpret_cast<TListCompareThunk*>(lParam);
1772 return ct->This->Compare(itemData1, itemData2, ct->ItemData);
1773 }
1774
1775}
1776
1777//
1778/// Sorts the list items.
1779//
1780/// @param[in] comparator is an application-defined derived class of TCompareFunc that performs the comparison.
1781/// @param[in] lParam is an application-defined value that will be passed to the comparison function.
1782//
1783/// \return true if successful.
1784//
1785/// \note
1786/// -# The first two parameters passed to the comparison function are the values
1787/// returned by TLvItem::GetItemData for the two items to be compared.
1788/// -# During the sorting process, the list-view contents are unstable. If the
1789/// comparator class causes any messages to be sent to the list-view control
1790/// that modify the list-view contents, the results are unpredictable.
1791//
1792/// \sa SortItemsEx
1793/// \sa http://msdn.microsoft.com/en-us/library/windows/desktop/bb761227.aspx
1794//
1795auto
1797{
1798 TListCompareThunk ct;
1799 ct.This = &comparator;
1800 ct.ItemData = lParam;
1801 return ToBool(SendMessage(LVM_SORTITEMS, TParam1(&ct), TParam2(OwlListViewCompare)));
1802}
1803
1804//
1805/// Sorts the list items.
1806//
1807/// This function differs from \link SortItems \endlink only in that the first two
1808/// parameters passed to the comparison function are the item indexes for the two
1809/// items to be compared.
1810//
1811/// \sa http://msdn.microsoft.com/en-us/library/windows/desktop/bb761228.aspx
1812//
1813auto
1815{
1816 TListCompareThunk ct;
1817 ct.This = &comparator;
1818 ct.ItemData = lParam;
1819 return ToBool(SendMessage(LVM_SORTITEMSEX, TParam1(&ct), TParam2(OwlListViewCompare)));
1820}
1821
1822//
1823/// Arranges items in icon view.
1824//
1825/// @param[in] code is the class specifying the type of arrangement.
1826//
1827/// \return true if successful.
1828//
1829/// \sa http://msdn.microsoft.com/en-us/library/windows/desktop/bb774884.aspx
1830//
1831auto
1833{
1834 PRECONDITION(GetHandle());
1835 return ToBool(SendMessage(LVM_ARRANGE, TParam1(code)));
1836}
1837
1838//
1839/// Queries if an item is selected.
1840//
1841/// @param[in] index is the item index.
1842//
1843/// \return true if item is selected.
1844//
1845auto
1846TListViewCtrl::IsSelected(int index) const -> bool
1847{
1848 return GetItemState(index, LVIS_SELECTED);
1849}
1850
1851//
1852/// Searches for the next selected item after a given index.
1853//
1854/// @param[in] index is the item index to begin the search; -1 specifies to find the first item.
1855//
1856/// \return the item index of the next selected item, or -1 if there isn't one.
1857//
1858auto
1859TListViewCtrl::GetNextSelIndex(int index) const -> int
1860{
1861 return GetNextItem(index, static_cast<TNextItemCode>(MkParam2(LVNI_ALL | LVNI_SELECTED, 0)));
1862}
1863
1864//
1865/// Retrieves the selected item index.
1866//
1867/// \note If the list-view control does not have the LVS_SINGLESEL style, the
1868/// first selected item index is retrieved.
1869//
1870/// \return the item index of the selected item, or -1 if there isn't one.
1871//
1872auto
1874{
1875 return GetNextSelIndex();
1876}
1877
1878//
1879/// Retrieves the number of selected items.
1880//
1881/// \note Useful before calling \link GetSelIndexes \endlink and \link GetSelStrings \endlink.
1882//
1883/// \return the number of selected items, or -1 if there are no selected items.
1884//
1885/// \sa http://msdn.microsoft.com/en-us/library/windows/desktop/bb761069.aspx
1886//
1887auto
1889{
1890 return static_cast<int>(SendMessage(LVM_GETSELECTEDCOUNT));
1891}
1892
1893//
1894/// Retrieves the indexes of the selected items.
1895//
1896/// @param[out] indexes is an array where the item indexes will be stored.
1897/// @param[in] maxCount is the maximum number of indexes to retrieve.
1898//
1899/// \note If the list-view control has the LVS_SINGLESEL style, at most only one index will be retrieved.
1900//
1901/// \return the number of indexes retrieved, or -1 if there are no selected items.
1902//
1903/// \sa GetSelCount
1904//
1905auto
1907{
1908 // Set the index to get the first selected item.
1909 //
1910 int index = -1;
1911
1912 // Number of selected items found.
1913 //
1914 int count;
1915
1916 // Loop until count reached or no more selected items.
1917 //
1918 for (count = 0; count < maxCount; ++count)
1919 {
1920 // Get the next selected item.
1921 //
1922 index = GetNextSelIndex(index);
1923 if (index == -1) break;
1924 indexes[count] = index;
1925 }
1926 return count;
1927}
1928
1929//
1930/// Retrieves the selected item or item subitem text.
1931//
1932/// @param[out] str is a character array where the text string will be stored.
1933/// @param[in] maxChars is the maximum number of characters to store including the null terminator.
1934/// @param[in] subitemIndex is the subitem index, which if 0 specifies to retrieve the item text.
1935//
1936/// \note If the list-view control does not have the LVS_SINGLESEL style, at most
1937/// only the first selected item string will be retrieved.
1938//
1939/// \return true if an item is selected.
1940//
1941auto
1943{
1944 // Get the selected item.
1945 auto index = GetNextSelIndex();
1946 if (index == -1)
1947 return false;
1948
1949 // Get the selected string.
1950 GetItemText(index, subitemIndex, str, maxChars);
1951 return true;
1952}
1953
1954//
1955/// String overload for \link GetSelString(tchar*, int, int) const \endlink.
1956//
1957/// \return string of selected item, which will be empty if no item is selected.
1958//
1959auto
1961{
1962 // Get the selected item.
1963 auto index = GetNextSelIndex();
1964 if (index == -1)
1965 return tstring();
1966
1967 // Get the selected string.
1968 return GetItemText(index, subitemIndex);
1969}
1970
1971//
1972/// Retrieves the item or subitem strings of the selected items.
1973//
1974/// @param[out] strs is an array of text strings where the strings will be stored.
1975/// @param[in] maxCount is the maximum number of strings to retrieve.
1976/// @param[in] maxChars is the size of each string in the array including the null terminator.
1977/// @param[in] subitemIndex is the subitem index, which if 0 specifies to retrieve the item text.
1978//
1979/// \note If the list-view control has the LVS_SINGLESEL style, at most only one string will be retrieved.
1980//
1981/// \return the number of strings retrieved, or -1 if there are no selected items.
1982//
1983/// \sa GetSelCount
1984//
1985auto
1987{
1988 // Set the index to get the first selected item.
1989 //
1990 int index = -1;
1991
1992 // Number of selected items found.
1993 //
1994 int count;
1995
1996 // Loop until count reached or no more selected items.
1997 //
1998 for (count = 0; count < maxCount; ++count)
1999 {
2000 // Get the next selected item.
2001 //
2002 index = GetNextSelIndex(index);
2003 if (index == -1) break;
2004 GetItemText(index, subitemIndex, strs[count], maxChars);
2005 }
2006 return count;
2007}
2008
2009//
2010/// Selects or deselects an item.
2011//
2012/// @param[in] index is the item index.
2013/// @param[in] select specifies whether to select or deselect the item.
2014//
2015/// \return true if successful.
2016//
2017auto
2018TListViewCtrl::SetSel(int index, bool select) -> bool
2019{
2021}
2022
2023//
2024/// Selects or deselects items.
2025//
2026/// @param[in] indexes is the array of item indexes.
2027/// @param[in] count is the size of the item indexes array.
2028/// @param[in] select specifies whether to select or deselect the items.
2029//
2030/// \note If the list-view control has the LVS_SINGLESEL style, this function
2031/// will not succeed if multiple items are designated to be selected.
2032//
2033/// \return true if successful.
2034//
2035auto
2036TListViewCtrl::SetSelIndexes(int* indexes, int count, bool select) -> bool
2037{
2038 // Single-select list-views cannot select more than one.
2039 //
2040 if ((GetStyle() & LVS_SINGLESEL) && select && (count > 1))
2041 return false;
2042
2043 for (int i = 0; i < count; i++)
2044 if (!SetSel(indexes[i], select))
2045 return false;
2046
2047 return true;
2048}
2049
2050//
2051/// Selects or deselects a range of items.
2052//
2053/// @param[in] select specifies whether to select or deselect the items.
2054/// @param[in] first is the item index of the first item to select or deselect.
2055/// @param[in] last is the item index of the last item to select or deselect.
2056//
2057/// \note If the list-view control has the LVS_SINGLESEL style, this function
2058/// will not succeed if multiple items are designated to be selected.
2059//
2060/// \return true if successful.
2061//
2062auto
2063TListViewCtrl::SetSelItemRange(bool select, int first, int last) -> bool
2064{
2065 // Single-select list-views cannot select more than one.
2066 //
2067 if ((GetStyle() & LVS_SINGLESEL) && select && (first < last))
2068 return false;
2069
2070 for (int i = first; i <= last; i++)
2071 if (!SetSel(i, select))
2072 return false;
2073
2074 return true;
2075}
2076
2077//
2078/// Retrieves the currently selected column number.
2079//
2080/// \return the currently selected column number, or -1 if no column is selected.
2081//
2082/// \sa http://msdn.microsoft.com/en-us/library/windows/desktop/bb761067.aspx
2083//
2084auto
2086{
2088 return static_cast<int>(SendMessage(LVM_GETSELECTEDCOLUMN));
2089}
2090
2091//
2092/// Sets the selected column number.
2093//
2094/// @param[in] colNum is the column number to select; -1 specifies to not select a column.
2095//
2096/// \return none.
2097//
2098/// \sa http://msdn.microsoft.com/en-us/library/windows/desktop/bb761202.aspx
2099//
2100auto
2102{
2103 PRECONDITION(GetHandle());
2104 SendMessage(LVM_SETSELECTEDCOLUMN, TParam1(colNum));
2105}
2106
2107//
2108/// Creates a drag image list for an item.
2109//
2110/// @param[in] index is the item index.
2111/// @param[in] upLeft is the initial location of the upper-left corner of the image, in view coordinates.
2112//
2113/// \return the handle to the drag image list if successful, otherwise NULL.
2114//
2115/// \note The application is responsible for destroying the image list when it is no longer needed.
2116//
2117/// \sa http://msdn.microsoft.com/en-us/library/windows/desktop/bb774890.aspx
2118//
2119auto
2121{
2122 PRECONDITION(GetHandle());
2123 return reinterpret_cast<HIMAGELIST>(SendMessage(LVM_CREATEDRAGIMAGE, TParam1(index), TParam2(upLeft)));
2124}
2125
2126//
2127/// Retrieves the handle to an image list used for drawing list-view items.
2128//
2129/// @param[in] type specifies the type of image list to retrieve.
2130//
2131/// \return the handle to the image list if successful, otherwise NULL.
2132//
2133/// \sa http://msdn.microsoft.com/en-us/library/windows/desktop/bb774943.aspx
2134//
2135auto
2137{
2138 PRECONDITION(GetHandle());
2139 return reinterpret_cast<HIMAGELIST>(SendMessage(LVM_GETIMAGELIST, TParam1(type)));
2140}
2141
2142//
2143/// Assigns an image list to a list-view control.
2144//
2145/// @param[in] list the handle to the image list.
2146/// @param[in] type specifies the type of image list to set.
2147//
2148/// \return the handle to the image list previously associated with the control if successful, or NULL otherwise.
2149//
2150/// \sa http://msdn.microsoft.com/en-us/library/windows/desktop/bb761178.aspx
2151//
2152auto
2154{
2155 PRECONDITION(GetHandle());
2156 return reinterpret_cast<HIMAGELIST>(SendMessage(LVM_SETIMAGELIST, TParam1(type), TParam2(list)));
2157}
2158
2159//
2160/// Retrieves the background color of a list-view control.
2161//
2162/// \return the background color.
2163//
2164/// \sa http://msdn.microsoft.com/en-us/library/windows/desktop/bb774905.aspx
2165//
2166auto
2168{
2170 return static_cast<COLORREF>(SendMessage(LVM_GETBKCOLOR));
2171}
2172
2173//
2174/// Sets the background color of a list-view control.
2175//
2176/// @param[in] c the color to use.
2177//
2178/// \note Specify TColor::None for no background color.
2179//
2180/// \return true if successful.
2181//
2182/// \sa http://msdn.microsoft.com/en-us/library/windows/desktop/bb761153.aspx
2183//
2184auto
2186{
2187 PRECONDITION(GetHandle());
2188 return ToBool(SendMessage(LVM_SETBKCOLOR, 0, TParam2(c.GetValue())));
2189}
2190
2191//
2192/// Retrieves the text background color of a list-view control.
2193//
2194/// \return the text background color.
2195//
2196/// \sa http://msdn.microsoft.com/en-us/library/windows/desktop/bb761077.aspx
2197//
2198auto
2200{
2202 return static_cast<COLORREF>(SendMessage(LVM_GETTEXTBKCOLOR));
2203}
2204
2205//
2206/// Sets the background color of text in a list-view control.
2207//
2208/// @param[in] c the color to use.
2209//
2210/// \note Specify TColor::None for no text background color.
2211//
2212/// \return true if successful.
2213//
2214/// \sa http://msdn.microsoft.com/en-us/library/windows/desktop/bb761206.aspx
2215//
2216auto
2218{
2219 PRECONDITION(GetHandle());
2220 return ToBool(SendMessage(LVM_SETTEXTBKCOLOR, 0, TParam2(c.GetValue())));
2221}
2222
2223//
2224/// Retrieves the text color of a list-view control.
2225//
2226/// \return the text color.
2227//
2228/// \sa http://msdn.microsoft.com/en-us/library/windows/desktop/bb761079.aspx
2229//
2230auto
2232{
2234 return static_cast<COLORREF>(SendMessage(LVM_GETTEXTCOLOR));
2235}
2236
2237//
2238/// Sets the color of text in a list-view control.
2239//
2240/// @param[in] c the color to use.
2241//
2242/// \return true if successful.
2243//
2244/// \sa http://msdn.microsoft.com/en-us/library/windows/desktop/bb761208.aspx
2245//
2246auto
2248{
2249 PRECONDITION(GetHandle());
2250 return ToBool(SendMessage(LVM_SETTEXTCOLOR, 0, TParam2(c.GetValue())));
2251}
2252
2253//
2254/// Retrieves the callback mask for a list-view control.
2255//
2256/// \return the callback mask.
2257//
2258/// \sa http://msdn.microsoft.com/en-us/library/windows/desktop/bb774909.aspx
2259//
2260auto
2262{
2265}
2266
2267//
2268/// Sets the callback mask for a list-view control.
2269//
2270/// \note The callback mask of a list-view control specifies the item states for
2271/// which the application, rather than the control, stores the current data. The
2272/// callback mask applies to all of the control's items, unlike the callback item
2273/// designation, which applies to a specific item. The callback mask is Unspecified
2274/// by default, meaning that the list-view control stores all item state information.
2275//
2276/// \return true if successful.
2277//
2278/// \sa http://msdn.microsoft.com/en-us/library/windows/desktop/bb761157.aspx
2279//
2280auto
2282{
2283 PRECONDITION(GetHandle());
2284 return ToBool(SendMessage(LVM_SETCALLBACKMASK, mask));
2285}
2286
2287//
2288/// Retrieves the topmost visible item index when in list or report view.
2289//
2290/// \return the topmost visible item index if successful; 0 if the list-view control
2291/// is in icon or small icon view, or if the list-view control is in details view
2292/// with groups enabled.
2293//
2294/// \sa http://msdn.microsoft.com/en-us/library/windows/desktop/bb761087.aspx
2295//
2296auto
2298{
2300 return static_cast<int>(SendMessage(LVM_GETTOPINDEX));
2301}
2302
2303//
2304/// Begins in-place editing of the list-view item's text.
2305//
2306/// @param[in] index is the item index, or -1 to cancel editing.
2307//
2308/// \return the handle to the edit control that is used to edit the item text
2309/// if successful, otherwise NULL.
2310//
2311/// \sa http://msdn.microsoft.com/en-us/library/windows/desktop/bb774898.aspx
2312//
2313auto
2315{
2316 PRECONDITION(GetHandle());
2317 return reinterpret_cast<HWND>(SendMessage(LVM_EDITLABEL, TParam1(index)));
2318}
2319
2320//
2321/// Retrieves the handle to the edit control used to edit a list-view item's text.
2322//
2323/// \return the handle to the edit control if successful, otherwise NULL.
2324//
2325/// \sa http://msdn.microsoft.com/en-us/library/windows/desktop/bb774919.aspx
2326//
2327auto
2329{
2331 return reinterpret_cast<HWND>(SendMessage(LVM_GETEDITCONTROL));
2332}
2333
2334//
2335/// Cancels an item text editing operation.
2336//
2337/// \return none.
2338//
2339/// \sa http://msdn.microsoft.com/en-us/library/windows/desktop/bb774886.aspx
2340//
2341auto
2343{
2344 PRECONDITION(GetHandle());
2345 SendMessage(LVM_CANCELEDITLABEL);
2346}
2347
2348//
2349/// Updates a list-view item.
2350//
2351/// @param[in] index is the item index to update.
2352//
2353/// \note If the list window has LVS_AUTOARRANGE, the items are automatically
2354/// arranged to their proper locations.
2355//
2356/// \return true if successful.
2357//
2358/// \sa http://msdn.microsoft.com/en-us/library/windows/desktop/bb761230.aspx
2359//
2360auto
2361TListViewCtrl::Update(int index) -> bool
2362{
2363 PRECONDITION(GetHandle());
2364 return ToBool(SendMessage(LVM_UPDATE, TParam1(index)));
2365}
2366
2367//
2368/// Determines whether a list-view item is at a specified position.
2369//
2370/// @param[in,out] info is a class containing the position to check, and upon
2371/// return contains results of the test.
2372//
2373/// \return item index found at the specified position if any, otherwise -1.
2374//
2375/// \sa http://msdn.microsoft.com/en-us/library/windows/desktop/bb761099.aspx
2376//
2377auto
2379{
2380 PRECONDITION(GetHandle());
2381 return static_cast<int>(SendMessage(LVM_HITTEST, -1, TParam2(&info)));
2382}
2383
2384//
2385/// Functional-style overload
2386//
2388{
2389 auto r = TLvHitTestInfo{p};
2390 HitTest(r);
2391 return r;
2392}
2393
2394//
2395/// Scrolls the content of a list-view control.
2396//
2397/// @param[in] dx is the pixel amount of horizontal scrolling relative to the current position.
2398/// @param[in] dy is the pixel amount of vertical scrolling relative to the current position.
2399//
2400/// \note When the list-view control is in report view, the control can only be scrolled vertically
2401/// in whole line increments so the vertical scrolling amount will be rounded to the nearest number
2402/// of pixels that form a whole line increment.
2403//
2404/// \return true if successful.
2405//
2406/// \sa http://msdn.microsoft.com/en-us/library/windows/desktop/bb761151.aspx
2407//
2408auto
2409TListViewCtrl::Scroll(int dx, int dy) -> bool
2410{
2411 PRECONDITION(GetHandle());
2412 return ToBool(SendMessage(LVM_SCROLL, dx, dy));
2413}
2414
2415//
2416/// Retrieves the current view origin for a list-view control.
2417//
2418/// @param[out] pt upon return will contain the view origin.
2419//
2420/// \return true if successful.
2421//
2422/// \sa http://msdn.microsoft.com/en-us/library/windows/desktop/bb761063.aspx
2423//
2424auto
2426{
2427 PRECONDITION(GetHandle());
2428 return ToBool(SendMessage(LVM_GETORIGIN, 0, TParam2(&pt)));
2429}
2430
2431//
2432/// Calculates the exact width in pixels of the given string using the control's
2433/// current font.
2434//
2435/// @param[in] text is the string to analyze.
2436//
2437/// \note Use \link CalculateColumnWidth \endlink instead of this function to set
2438/// the column width using \link InsertColumn \endlink or \link SetColumnWidth \endlink
2439/// to avoid truncation.
2440//
2441/// \return pixel width of the string.
2442//
2443/// \sa http://msdn.microsoft.com/en-us/library/windows/desktop/bb761073.aspx
2444//
2445auto
2447{
2448 PRECONDITION(GetHandle());
2450 return static_cast<int>(SendMessage(LVM_GETSTRINGWIDTH, 0, TParam2(text)));
2451}
2452
2453//
2454/// String overload for \link GetStringWidth(LPCTSTR) const \endlink.
2455//
2456/// @param[in] text is the string to analyze.
2457//
2458/// \return pixel width of the string.
2459//
2460auto
2462{
2463 PRECONDITION(GetHandle());
2464 return GetStringWidth(text.c_str());
2465}
2466
2467//
2468/// Calculates a suitable column pixel width for the given string.
2469//
2470/// This value can be used to set a column width using \link InsertColumn \endlink
2471/// or \link SetColumnWidth \endlink.
2472//
2473/// @param[in] text is the string to analyze.
2474/// @param[in] padding is the number of pixels to add for a suitable column width.
2475//
2476/// \return column pixel width.
2477//
2478auto
2480{
2481 PRECONDITION(GetHandle());
2482
2483 // TODO: Ideally, we should calculate the correct column width based on the control's rendering
2484 // here, i.e. take account of the scale of its GUI elements. However, this information is not
2485 // readily available, so for now, we simply add the given padding to the width of the string.
2486 //
2487 return GetStringWidth(text) + padding;
2488}
2489
2490//
2491/// String overload for \link CalculateColumnWidth(LPCTSTR, int) const \endlink.
2492//
2493/// @param[in] text is the string to analyze.
2494/// @param[in] padding is the number of pixels to add for a suitable column width.
2495//
2496/// \return column pixel width.
2497//
2498auto
2500{
2501 PRECONDITION(GetHandle());
2502 return CalculateColumnWidth(text.c_str(), padding);
2503}
2504
2505//
2506/// Retrieves the bounding rectangle of all items in the list-view control when in icon or small icon view.
2507//
2508/// @param[out] rect upon return will contain the bounding rectangle.
2509//
2510/// \return true if successful.
2511//
2512/// \sa http://msdn.microsoft.com/en-us/library/windows/desktop/bb761093.aspx
2513//
2514auto
2516{
2517 PRECONDITION(GetHandle());
2518 return ToBool(SendMessage(LVM_GETVIEWRECT, 0, TParam2(&rect)));
2519}
2520
2521//
2522/// Queries whether an item is visible.
2523//
2524/// @param[in] index is the item index.
2525//
2526/// \return true if visible.
2527//
2528/// \sa http://msdn.microsoft.com/en-us/library/windows/desktop/bb761135.aspx
2529//
2530auto
2531TListViewCtrl::IsItemVisible(int index) const -> bool
2532{
2533 PRECONDITION(GetHandle());
2534 return ToBool(SendMessage(LVM_ISITEMVISIBLE, TParam1(index)));
2535}
2536
2537//
2538/// Ensures that a list-view item is either partially or entirely visible, scrolling
2539/// the list-view control if necessary.
2540//
2541/// @param[in] index is the item index.
2542/// @param[in] partialOk specifies whether to ensure partially or entirely visible.
2543//
2544/// \note The function will not succeed if the window style has LVS_NOSCROLL.
2545//
2546/// \return true if successful.
2547//
2548/// \sa http://msdn.microsoft.com/en-us/library/windows/desktop/bb774902.aspx
2549//
2550auto
2552{
2553 PRECONDITION(GetHandle());
2554 return ToBool(SendMessage(LVM_ENSUREVISIBLE, TParam1(index), TParam2(partialOk)));
2555}
2556
2557//
2558/// Forces a list-view control to redraw a range of items.
2559//
2560/// @param[in] startIndex is the first item index to redraw.
2561/// @param[in] endIndex is the last item index to redraw.
2562//
2563/// \note The items are not actually redrawn until the list-view window receives a
2564/// WM_PAINT message to repaint. To repaint immediately, call the UpdateWindow()
2565/// function after calling this function.
2566//
2567/// \return true if successful.
2568//
2569/// \sa http://msdn.microsoft.com/en-us/library/windows/desktop/bb761145.aspx
2570//
2571auto
2573{
2574 PRECONDITION(GetHandle());
2575 return ToBool(SendMessage(LVM_REDRAWITEMS, TParam1(startIndex), TParam2(endIndex)));
2576}
2577
2578//
2579/// Calculates the number of items that can fit vertically in the visible area
2580/// of a list-view control when in list or report view.
2581//
2582/// \return the number of fully visible items if successful; if in icon or small
2583/// icon view, the total number of items.
2584//
2585/// \sa http://msdn.microsoft.com/en-us/library/windows/desktop/bb774917.aspx
2586//
2587auto
2589{
2591 return static_cast<int>(SendMessage(LVM_GETCOUNTPERPAGE));
2592}
2593
2594//
2595/// Retrieves the incremental search string.
2596//
2597/// \return the incremental search string, which will be empty if the list-view
2598/// control is not in incremental search mode.
2599//
2600/// \sa http://msdn.microsoft.com/en-us/library/windows/desktop/bb774951.aspx
2601//
2602auto
2604{
2606 tstring s;
2607
2608 // Call to get size of string.
2609 //
2610 auto size = static_cast<int>(SendMessage(LVM_GETISEARCHSTRING));
2611 if (!size) return s;
2612
2613 // Resize so string is large enough, including null terminator.
2614 //
2615 s.resize(size + 1);
2616
2617 // Call to get string.
2618 //
2620
2621 // Return the string result.
2622 //
2623 return s;
2624}
2625
2626//
2627/// Retrieves the item index of the item that has the focus.
2628//
2629/// \return the item index, or -1 if no item has the focus.
2630//
2631auto
2633{
2634 auto n = GetItemCount();
2635 for (auto i = 0; i < n; ++i)
2636 if (GetItemState(i, TLvItem::Focus) == TLvItem::Focus) return i;
2637 return -1;
2638}
2639
2640//
2641/// Sets or removes the focus for an item.
2642//
2643/// @param[in] index is the item index.
2644/// @param[in] focused specifies whether the focus is set or removed.
2645//
2646/// \return true if successful.
2647//
2648auto
2649TListViewCtrl::SetFocusItem(int index, bool focused) -> bool
2650{
2651 return SetItemState(index, focused ? TLvItem::Focus : TLvItem::Unspecified, TLvItem::Focus);
2652}
2653
2654//
2655/// Calculates the approximate width and height required to display a given number of items.
2656//
2657/// @param[in] x is the proposed x-dimension of the list-view control; -1 specifies to use the current width.
2658/// @param[in] y is the proposed y-dimension of the list-view control; -1 specifies to use the current height.
2659/// @param[in] count is the number of items to be displayed in the list-view control; -1 specifies to use the
2660/// total number of items.
2661//
2662/// \note
2663/// -# Setting the size of the list-view control based on the dimensions provided by this message can optimize
2664/// redraw and reduce flicker.
2665/// -# If the coordinates are outside a valid range, a TXOwl exception is thrown.
2666//
2667/// \return the calculated size.
2668//
2669/// \sa http://msdn.microsoft.com/en-us/library/windows/desktop/bb774883.aspx
2670//
2671auto
2672TListViewCtrl::GetApproxRect(int x, int y, int count) const -> TSize
2673{
2674 PRECONDITION(GetHandle());
2675 if ((x != -1 && !IsRepresentable<uint16>(x)) || (y != -1 && !IsRepresentable<uint16>(y)))
2676 throw TXOwl(_T("TListViewCtrl:GetApproxRect: Argument is outside valid range"));
2677 TResult r = SendMessage(LVM_APPROXIMATEVIEWRECT, TParam1(count), MkParam2(x, y));
2678 return TPoint(static_cast<LPARAM>(r));
2679}
2680
2681//
2682/// Retrieves the current left-to-right order of columns in a list-view control.
2683//
2684/// @param[in] count is the number of columns to be retrieved.
2685/// @param[out] array is an array where the columns will be stored.
2686//
2687/// \return true if successful.
2688//
2689/// \sa http://msdn.microsoft.com/en-us/library/windows/desktop/bb774913.aspx
2690//
2691auto
2692TListViewCtrl::GetColumnOrder(int count, int* array) const -> bool
2693{
2694 PRECONDITION(GetHandle());
2695 return ToBool(SendMessage(LVM_GETCOLUMNORDERARRAY, TParam1(count), TParam2(array)));
2696}
2697
2698//
2699/// Sets the current left-to-right order of columns in a list-view control.
2700//
2701/// @param[in] count is the number of columns to be set.
2702/// @param[in] array is an array of columns to set.
2703//
2704/// \return true if successful.
2705//
2706/// \sa http://msdn.microsoft.com/en-us/library/windows/desktop/bb761161.aspx
2707//
2708auto
2709TListViewCtrl::SetColumnOrder(int count, const int* array) -> bool
2710{
2711 PRECONDITION(GetHandle());
2712 return ToBool(SendMessage(LVM_SETCOLUMNORDERARRAY, TParam1(count), TParam2(array)));
2713}
2714
2715//
2716/// Retrieves the extended styles that are currently in use for a given list-view control.
2717//
2718/// \return the extended styles.
2719//
2720/// \sa http://msdn.microsoft.com/en-us/library/windows/desktop/bb774923.aspx
2721//
2722auto
2728
2729//
2730/// Sets the extended styles to use for a given list-view control.
2731//
2732/// @param[in] mask specifies the styles that are to be affected in style; 0 means all the styles given.
2733/// @param[in] style specifies the styles.
2734//
2735/// \return the previously used extended styles.
2736//
2737/// \sa http://msdn.microsoft.com/en-us/library/windows/desktop/bb761165.aspx
2738//
2739auto
2741{
2742 PRECONDITION(GetHandle());
2743 return static_cast<uint32>(SendMessage(LVM_SETEXTENDEDLISTVIEWSTYLE, TParam1(mask), TParam2(style)));
2744}
2745
2746//
2747/// Retrieves the handle to the header control used by the list-view control.
2748//
2749/// \return the handle to the header control.
2750//
2751/// \sa http://msdn.microsoft.com/en-us/library/windows/desktop/bb774937.aspx
2752//
2753auto
2755{
2757 return reinterpret_cast<HWND>(SendMessage(LVM_GETHEADER));
2758}
2759
2760//
2761/// Retrieves the cursor handle used when the pointer is over an item while hot tracking is enabled.
2762//
2763/// \note A list-view control uses hot tracking and hover selection when the LVS_EX_TRACKSELECT style is set.
2764//
2765/// \return the handle to the cursor.
2766//
2767/// \sa http://msdn.microsoft.com/en-us/library/windows/desktop/bb774938.aspx
2768//
2769auto
2771{
2773 return reinterpret_cast<HCURSOR>(SendMessage(LVM_GETHOTCURSOR));
2774}
2775
2776//
2777/// Sets the cursor handle to use when the pointer is over an item while hot tracking is enabled.
2778//
2779/// @param[in] cur the new cursor handle to use.
2780//
2781/// \note A list-view control uses hot tracking and hover selection when the LVS_EX_TRACKSELECT style is set.
2782//
2783/// \return the previous cursor handle used.
2784//
2785/// \sa http://msdn.microsoft.com/en-us/library/windows/desktop/bb774938.aspx
2786//
2787auto
2789{
2790 PRECONDITION(GetHandle());
2791 return reinterpret_cast<HCURSOR>(SendMessage(LVM_SETHOTCURSOR, 0, TParam2(cur)));
2792}
2793
2794//
2795/// Retrieves the index of the hot item.
2796//
2797/// \return the hot item index.
2798//
2799/// \sa http://msdn.microsoft.com/en-us/library/windows/desktop/bb774939.aspx
2800//
2801auto
2803{
2805 return static_cast<int>(SendMessage(LVM_GETHOTITEM));
2806}
2807
2808//
2809/// Sets the index of the hot item.
2810//
2811/// \return the previous hot item index.
2812//
2813/// \sa http://msdn.microsoft.com/en-us/library/windows/desktop/bb761172.aspx
2814//
2815auto
2817{
2818 PRECONDITION(GetHandle());
2819 return static_cast<int>(SendMessage(LVM_SETHOTITEM, TParam1(index)));
2820}
2821
2822//
2823/// Retrieves the bounding rectangle for a subitem in a list-view control when in report view.
2824//
2825/// @param[out] rect upon return contains the bounding rectangle.
2826/// @param[in] subitemIndex the subitem index.
2827/// @param[in] index the item index.
2828/// @param[in] type the type of bountding rectangle to retrieve.
2829//
2830/// \return true if successful.
2831//
2832/// \sa http://msdn.microsoft.com/en-us/library/windows/desktop/bb761075.aspx
2833//
2834auto
2836{
2837 PRECONDITION(GetHandle());
2838
2839 // SelectBounds isn't allowed but is synonymous with Bounds in this context.
2840 //
2841 rect = { static_cast<int>((type == SelectBounds) ? Bounds : type), subitemIndex, 0, 0 };
2842 return ToBool(SendMessage(LVM_GETSUBITEMRECT, TParam1(index), TParam2(&rect)));
2843}
2844
2845//
2846/// Determines which list-view item or subitem is at a given position.
2847//
2848/// @param[in,out] info is a class containing the position to check, and upon
2849/// return contains results of the test.
2850//
2851/// \return item or subitem index found at the specified position if any, otherwise -1.
2852//
2853/// \sa http://msdn.microsoft.com/en-us/library/windows/desktop/bb761229.aspx
2854//
2855auto
2857{
2858 PRECONDITION(GetHandle());
2859 return static_cast<int>(SendMessage(LVM_SUBITEMHITTEST, -1, TParam2(&info)));
2860}
2861
2862//
2863/// Functional-style overload
2864//
2866{
2867 auto r = TLvHitTestInfo{p};
2868 SubItemHitTest(r);
2869 return r;
2870}
2871
2872//
2873/// Retrieves the amount of horizontal and vertical spacing between items.
2874//
2875/// @param[in] smallIcon if true, the spacing refers to small icon view rather
2876/// than normal icon view.
2877//
2878/// \return the item spacing.
2879//
2880/// \sa http://msdn.microsoft.com/en-us/library/windows/desktop/bb761051.aspx
2881//
2882auto
2884{
2885 PRECONDITION(GetHandle());
2886 TResult r = SendMessage(LVM_GETITEMSPACING, TParam1(smallIcon));
2887 return TSize(LoUint16(r), HiUint16(r));
2888}
2889
2890//
2891/// Sets the spacing between icons in list-view controls that have the LVS_ICON style.
2892//
2893/// @param[in] x is the horizontal spacing to use.
2894/// @param[in] y is the vertical spacing to use.
2895//
2896/// \note
2897/// -# The spacing values must include the icon size if overlapping is to be avoided.
2898/// -# If the spacing values are outside a valid range, a TXOwl exception is thrown.
2899//
2900/// \return the previous icon spacing used.
2901//
2902/// \sa http://msdn.microsoft.com/en-us/library/windows/desktop/bb761176.aspx
2903//
2904auto
2906{
2907 PRECONDITION(GetHandle());
2908 if ((y != -1) && ((x < 0) || (y < 0)))
2909 throw TXOwl(_T("TListViewCtrl:SetIconSpacing: Argument is outside valid range"));
2910 TResult r = SendMessage(LVM_SETICONSPACING, TParam1(x), y);
2911 return TSize(LoUint16(r), HiUint16(r));
2912}
2913
2914//
2915/// Retrieves the background image in a list-view control.
2916//
2917/// @param[out] bkimg is the class that will contain the background image information.
2918//
2919/// \return true if successful.
2920//
2921/// \sa http://msdn.microsoft.com/en-us/library/windows/desktop/bb774907.aspx
2922//
2923auto
2925{
2926 PRECONDITION(GetHandle());
2927 return ToBool(SendMessage(LVM_GETBKIMAGE, 0, TParam2(&bkimg)));
2928}
2929
2930//
2931/// Sets the background image in a list-view control.
2932//
2933/// @param[in] bkimg is the class containing the background image information.
2934//
2935/// \return true if successful and a background image is used.
2936//
2937/// \sa http://msdn.microsoft.com/en-us/library/windows/desktop/bb761155.aspx
2938//
2939auto
2941{
2942 PRECONDITION(GetHandle());
2943 return ToBool(SendMessage(LVM_SETBKIMAGE, 0, TParam2(&bkimg)));
2944}
2945
2946//
2947/// Retrieves the amount of time that the mouse cursor must hover over an item
2948/// before it is selected.
2949//
2950/// \note The hover time only affects list-view controls that have the
2951/// LVS_EX_TRACKSELECT, LVS_EX_ONECLICKACTIVATE, or LVS_EX_TWOCLICKACTIVATE
2952/// extended list-view style.
2953//
2954/// \return the amount of time in milliseconds, which is the maximum value for
2955/// this data type if the default time is used.
2956//
2957/// \sa http://msdn.microsoft.com/en-us/library/windows/desktop/bb774941.aspx
2958//
2959auto
2961{
2963 return static_cast<uint32>(SendMessage(LVM_GETHOVERTIME));
2964}
2965
2966//
2967/// Sets the amount of time that the mouse cursor must hover over an item
2968/// before it is selected.
2969//
2970/// @param[in] tm is the amount of time in milliseconds; if this is the maximum
2971/// value for this data type the default time is used.
2972//
2973/// \return the previous hover time used.
2974//
2975/// \sa http://msdn.microsoft.com/en-us/library/windows/desktop/bb761174.aspx
2976//
2977auto
2979{
2980 PRECONDITION(GetHandle());
2981 return static_cast<uint32>(SendMessage(LVM_SETHOVERTIME, 0, TParam2(tm)));
2982}
2983
2984//
2985/// Retrieves the number of working areas in a list-view control.
2986//
2987/// \return the number of working areas.
2988//
2989/// \sa http://msdn.microsoft.com/en-us/library/windows/desktop/bb761061.aspx
2990//
2991auto
2999
3000//
3001/// Retrieves the working areas from a list-view control.
3002//
3003/// @param[in] count is the maximum number of working areas to retrieve.
3004/// @param[out] areas upon return will contain the client coordinates of the working areas.
3005//
3006/// \return none.
3007//
3008/// \sa http://msdn.microsoft.com/en-us/library/windows/desktop/bb761095.aspx
3009//
3010auto
3011TListViewCtrl::GetWorkAreas(int count, TRect* areas) const -> void
3012{
3013 PRECONDITION(GetHandle());
3014 SendMessage(LVM_GETWORKAREAS, TParam1(count), TParam2(areas));
3015}
3016
3017//
3018/// Sets the working areas for a list-view control.
3019//
3020/// @param[in] count is the number of working areas.
3021/// @param[in] areas is the list of the client coordinates of the working areas;
3022/// if a null pointer is passed, the working area will be set to the client area
3023/// of the control.
3024//
3025/// \return none.
3026//
3027/// \sa http://msdn.microsoft.com/en-us/library/windows/desktop/bb761223.aspx
3028//
3029auto
3031{
3032 PRECONDITION(GetHandle());
3033 SendMessage(LVM_SETWORKAREAS, TParam1(count), TParam2(areas));
3034}
3035
3036//
3037/// Retrieves the selection mark from a list-view control.
3038//
3039/// The selection mark is the item index from which a multiple selection starts.
3040//
3041/// \return the zero-based selection mark, or -1 if there is no selection mark.
3042//
3043/// \sa http://msdn.microsoft.com/en-us/library/windows/desktop/bb761071.aspx
3044//
3045auto
3047{
3049 return static_cast<int>(SendMessage(LVM_GETSELECTIONMARK));
3050}
3051
3052//
3053/// Sets the selection mark for a list-view control.
3054//
3055/// The selection mark is the item index from which a multiple selection starts.
3056//
3057/// @param[in] index is the zero-based index of the new selection mark; if -1,
3058/// the selection mark is removed.
3059//
3060/// \return the previous selection mark, or -1 if there was no previous selection mark.
3061//
3062/// \sa http://msdn.microsoft.com/en-us/library/windows/desktop/bb761204.aspx
3063//
3064auto
3066{
3067 PRECONDITION(GetHandle());
3068 return static_cast<int>(SendMessage(LVM_SETSELECTIONMARK, 0, TParam2(index)));
3069}
3070
3071//
3072/// Sets the bounding rectangle for a subitem.
3073//
3074/// @param[in] index is the item index.
3075/// @param[in] group is the group number.
3076/// @param[in] subitemIndex is the subitem index.
3077/// @param[in] rect is the bounding rectangle to set.
3078/// @param[in] type specifies the type of rectangle to set.
3079//
3080/// \return true if successful.
3081//
3082/// \sa http://msdn.microsoft.com/en-us/library/windows/desktop/bb761046.aspx
3083//
3084auto
3086{
3087 PRECONDITION(GetHandle());
3088
3089 // SelectBounds isn't allowed but is synonymous with Bounds in this context.
3090 //
3091 rect = { static_cast<int>((type == SelectBounds) ? Bounds : type), subitemIndex, 0, 0 };
3092 LVITEMINDEX itemIndex = { index, group };
3093 return ToBool(SendMessage(LVM_GETITEMINDEXRECT, TParam1(&itemIndex), TParam2(&rect)));
3094}
3095
3096//
3097/// Searches for a list-view item that has the specified properties and bears
3098/// the specified relationship to a specified item.
3099//
3100/// @param[in] index is the item index to begin the search; -1 specifies to find the first item.
3101/// @param[in] group is the group number.
3102/// @param[in] flags is a combination of TNextItemCode flags that specify the relationship to the item given by index.
3103//
3104/// \return item index if found, otherwise -1.
3105//
3106/// \sa http://msdn.microsoft.com/en-us/library/windows/desktop/bb761059.aspx, TListViewCtrl::TNextItemCode
3107//
3108auto
3109TListViewCtrl::GetNextItemIndex(int index, int group, uint flags) const -> int
3110{
3111 PRECONDITION(GetHandle());
3112 LVITEMINDEX itemIndex = { index, group };
3113 return SendMessage(LVM_GETNEXTITEMINDEX, TParam1(&itemIndex), TParam2(flags)) != FALSE ? itemIndex.iItem : -1;
3114}
3115
3116//
3117/// Sets the state of a list-view item.
3118//
3119/// @param[in] item is the class containing the state attributes to set.
3120/// @param[in] index is the item index.
3121/// @param[in] group is the group number.
3122//
3123/// \return true if successful.
3124//
3125/// \sa http://msdn.microsoft.com/en-us/library/windows/desktop/bb761190.aspx
3126//
3127auto
3128TListViewCtrl::SetItemIndexState(const TLvItem& item, int index, int group) -> bool
3129{
3130 PRECONDITION(GetHandle());
3131 LVITEMINDEX itemIndex = { index, group };
3132 return SendMessage(LVM_SETITEMINDEXSTATE, TParam1(&itemIndex), TParam2(&item)) == S_OK;
3133}
3134
3135//
3136/// Retrieves the string to display when the list-view control appears empty.
3137//
3138/// \return the string to display.
3139//
3140/// \sa http://msdn.microsoft.com/en-us/library/windows/desktop/bb774921.aspx
3141//
3142auto
3144{
3146 tstring s;
3147
3148 // Resize arbitrarily so hopefully string is large enough, as Windows does
3149 // not provide a method for getting the needed size.
3150 //
3151 s.resize(1024);
3152
3153 // Call to get string.
3154 //
3155 SendMessage(LVM_GETEMPTYTEXT, TParam1(s.capacity()), TParam2(&s[0]));
3156
3157 // Return the string result.
3158 //
3159 return s;
3160}
3161
3162//
3163/// Retrieves information about the footer of a list-view control.
3164//
3165/// @param[in,out] info contains the information to retrieve on the footer and will contain those values upon return.
3166//
3167/// \return true if successful.
3168//
3169/// \sa http://msdn.microsoft.com/en-us/library/windows/desktop/bb774927.aspx
3170//
3171auto
3173{
3174 PRECONDITION(GetHandle());
3175 return ToBool(SendMessage(LVM_GETFOOTERINFO, 0, TParam2(&info)));
3176}
3177
3178//
3179/// Footer item count return overload for \link GetFooterInfo(TLvFooterInfo&) const \endlink.
3180//
3181auto
3183{
3185 info.mask = LVFF_ITEMCOUNT;
3186 auto r = GetFooterInfo(info);
3187 WARN(!r, _T("TListViewCtrl::GetFooterInfo failed")); InUse(r);
3188 return static_cast<int>(info.cItems);
3189}
3190
3191//
3192/// Retrieves information for a footer item in a list-view control.
3193//
3194/// @param[in] index is the item index.
3195/// @param[in,out] item contains the information to retrieve on a footer item and will contain those values upon return.
3196//
3197/// \return true if successful.
3198//
3199/// \sa http://msdn.microsoft.com/en-us/library/windows/desktop/bb774928.aspx
3200//
3201auto
3202TListViewCtrl::GetFooterItem(int index, TLvFooterItem& item) const -> bool
3203{
3204 PRECONDITION(GetHandle());
3205 return ToBool(SendMessage(LVM_GETFOOTERITEM, TParam1(index), TParam2(&item)));
3206}
3207
3208//
3209/// Footer item text string return overload for \link GetFooterItem(int, TLvFooterItem&) const \endlink.
3210/// Returns an empty string on failure.
3211//
3212auto
3213TListViewCtrl::GetFooterItemText(int index) const -> std::wstring
3214{
3215 // Allocate a string of arbitrary size ("large enough"), as Windows does
3216 // not provide a method for getting the needed size.
3217 //
3218 std::wstring s(1024, L'\0');
3219
3220 // Get the footer string, resize it and return it.
3221 //
3222 TLvFooterItem item;
3223 item.iItem = index;
3224 item.mask = LVFIF_TEXT;
3225 item.pszText = &s[0];
3226 item.cchTextMax = static_cast<int>(s.size());
3227 auto r = GetFooterItem(index, item);
3228 WARN(!r, _T("TListViewCtrl::GetFooterItem failed for index ") << index); InUse(r);
3229 s.resize(wcslen(s.data()));
3230 s.shrink_to_fit();
3231 return s;
3232}
3233
3234//
3235/// Footer item state return overload for \link GetFooterItem(int, TLvFooterItem&) const \endlink.
3236//
3237/// @param[in] mask contains the mask of state values to return.
3238//
3239auto
3241{
3242 TLvFooterItem item;
3243
3244 // Set Footer Item Attributes
3245 item.iItem = index;
3246 item.mask = LVFIF_STATE;
3247 item.stateMask = static_cast<UINT>(mask);
3248
3249 // Get state.
3250 //
3251 auto r = GetFooterItem(index, item);
3252 WARN(!r, _T("TListViewCtrl::GetFooterItem failed for index ") << index); InUse(r);
3253
3254 // Return state
3255 return static_cast<TLvFooterItem::TState>(item.state);
3256}
3257
3258//
3259/// Retrieves the coordinates of a footer for an item in a list-view control.
3260//
3261/// @param[in] index is the item index.
3262/// @param[out] rect contains the coordinates of the footer upon return.
3263//
3264/// \return true if successful.
3265//
3266/// \sa http://msdn.microsoft.com/en-us/library/windows/desktop/bb774929.aspx
3267//
3268auto
3270{
3271 PRECONDITION(GetHandle());
3272 return ToBool(SendMessage(LVM_GETFOOTERITEMRECT, TParam1(index), TParam2(&rect)));
3273}
3274
3275//
3276/// TRect return overload for \link GetFooterItemRect(int, TRect&) const \endlink.
3277//
3278auto
3280{
3281 TRect rect;
3282 auto r = GetFooterItemRect(index, rect);
3283 WARN(!r, _T("TListViewCtrl::GetFooterItemRect failed for index ") << index); InUse(r);
3284 return rect;
3285}
3286
3287//
3288/// Retrieves the coordinates of the footer for a list-view control.
3289//
3290/// @param[out] rect contains the coordinates of the footer upon return.
3291//
3292/// \return true if successful.
3293//
3294/// \sa http://msdn.microsoft.com/en-us/library/windows/desktop/bb774930.aspx
3295//
3296auto
3298{
3299 PRECONDITION(GetHandle());
3300 return ToBool(SendMessage(LVM_GETFOOTERRECT, 0, TParam2(&rect)));
3301}
3302
3303//
3304/// TRect return overload for \link GetFooterRect(TRect&) const \endlink.
3305//
3306auto
3308{
3309 TRect rect;
3310 auto r = GetFooterRect(rect);
3311 WARN(!r, _T("TListViewCtrl::GetFooterRect failed")); InUse(r);
3312 return rect;
3313}
3314
3315//
3316/// Gets group information.
3317//
3318/// @param[in] mask determines which fields to retrieve (optional).
3319//
3320/// \sa http://docs.microsoft.com/en-us/windows/desktop/Controls/lvm-getgroupinfo
3321//
3323{
3324 auto g = LVGROUP{sizeof(LVGROUP), mask};
3325 const auto r = static_cast<int>(SendMessage(LVM_GETGROUPINFO, groupId, reinterpret_cast<TParam2>(&g)));
3326 WARN(r < 0, _T("TListViewCtrl::GetGroupInfo failed")); InUse(r);
3327 return g;
3328}
3329
3330//
3331/// Queries whether the Unicode character set is being used instead of ANSI.
3332//
3333/// \return true if Unicode is being used.
3334//
3335/// \sa http://msdn.microsoft.com/en-us/library/windows/desktop/bb761089.aspx
3336//
3337auto
3343
3344//
3345/// Sets whether the Unicode character set is being used instead of ANSI.
3346//
3347/// @param[in] useUnicode if true, Unicode will be used.
3348//
3349/// \return the previous setting.
3350//
3351/// \sa http://msdn.microsoft.com/en-us/library/windows/desktop/bb761218.aspx
3352//
3353auto
3355{
3356 PRECONDITION(GetHandle());
3357 return ToBool(SendMessage(LVM_SETUNICODEFORMAT, TParam1(useUnicode)));
3358}
3359
3360//
3361/// Associates a unique identifier with an item.
3362//
3363/// List-view controls internally track items by index which can present
3364/// problems because indexes can change during the control's lifetime.
3365/// Using a unique identifier allows an item to be easily referenced
3366/// independent of index changes.
3367//
3368/// @param[in] index is the item index.
3369//
3370/// \note In a multithreaded environment, the index is only guaranteed on
3371/// the thread that hosts the list-view control, not on background threads.
3372/// Not supported under the LVS_OWNERDATA style.
3373//
3374/// \return a unique identifier for the item.
3375//
3376/// \sa http://msdn.microsoft.com/en-us/library/windows/desktop/bb761139.aspx
3377//
3378auto
3380{
3381 PRECONDITION(GetHandle());
3382 return SendMessage(LVM_MAPINDEXTOID, TParam1(index));
3383}
3384
3385//
3386/// Retrieves the current index for the item with the given unique identifier.
3387//
3388/// @param[in] id is the unique identifier for the item.
3389//
3390/// \note In a multithreaded environment, the index is only guaranteed on
3391/// the thread that hosts the list-view control, not on background threads.
3392/// Not supported under the LVS_OWNERDATA style.
3393//
3394/// \return the item index.
3395//
3396/// \sa http://msdn.microsoft.com/en-us/library/windows/desktop/bb761137.aspx
3397//
3398auto
3400{
3401 PRECONDITION(GetHandle());
3402 return static_cast<int>(SendMessage(LVM_MAPIDTOINDEX, TParam1(id)));
3403}
3404
3405//
3406/// Retrieves the handle of the tooltip control that the list-view control uses
3407/// to display tooltips.
3408//
3409/// \return the handle of the tooltip control.
3410//
3411/// \sa http://msdn.microsoft.com/en-us/library/windows/desktop/bb761085.aspx
3412//
3413auto
3415{
3417 return reinterpret_cast<HWND>(SendMessage(LVM_GETTOOLTIPS));
3418}
3419
3420//
3421/// Sets the handle of the tooltip control that the list-view control uses
3422/// to display tooltips.
3423//
3424/// @param[in] handle is the handle of the tooltip control to use.
3425//
3426/// \return the handle of the previous tooltip control that was used.
3427//
3428/// \sa http://msdn.microsoft.com/en-us/library/windows/desktop/bb761216.aspx
3429//
3430auto
3432{
3433 PRECONDITION(GetHandle());
3435 return reinterpret_cast<HWND>(SendMessage(LVM_SETTOOLTIPS, TParam1(handle)));
3436}
3437
3438//
3439/// Sets tooltip text in delayed response to the LVN_GETINFOTIP notification.
3440//
3441/// This function lets an application calculate infotips in the background by
3442/// performing the following steps:
3443/// -# In response to the LVN_GETINFOTIP notification, set the `pszText` member
3444/// of the `TLvGetInfoTip` structure to an empty string and return 0.
3445/// -# In the background, compute the infotip.
3446/// -# After computing the infotip, call this function with the infotip and item
3447/// and sub-item indexes to which the infotip applies.
3448//
3449/// \note The intotip appears only if the specified item and sub-item are still
3450/// in a state that requires an infotip.
3451//
3452/// @param[in] text is the wide-char tooltip text to set; a null pointer results
3453/// in an empty string used.
3454/// @param[in] index is the item index.
3455/// @param[in] subitemIndex is the subitem index.
3456//
3457/// \return true if successful.
3458//
3459/// \sa http://msdn.microsoft.com/en-us/library/windows/desktop/bb761180.aspx
3460//
3461auto
3463{
3464 PRECONDITION(GetHandle());
3465 LVSETINFOTIP lvSetInfoTip = { sizeof(LVSETINFOTIP), 0, const_cast<LPWSTR>(text ? text : L""), index, subitemIndex };
3466 return ToBool(SendMessage(LVM_SETINFOTIP, 0, TParam2(&lvSetInfoTip)));
3467}
3468
3469//
3470/// C single-byte string overload for \link SetInfoTip(LPCWSTR, int, int) \endlink.
3471//
3472auto
3474{
3475 PRECONDITION(GetHandle());
3476
3477 // Define wide-char string to use.
3478 //
3479 LPWSTR wtext = nullptr;
3480
3481 // Convert to wide-char if single-byte string is not null.
3482 //
3483 if (text && *text)
3484 {
3485 // Compute buffer size needed.
3486 //
3487 auto wsize = ::MultiByteToWideChar(CP_ACP, 0, text, -1, nullptr, 0);
3488 if (!wsize)
3489 {
3490 WARN(true, _T("TListViewCtrl::SetInfoTip ::MultiByteToWideChar returned zero size for text string"));
3491 return false;
3492 }
3493
3494 // Allocate buffer.
3495 //
3496 wtext = new wchar_t [wsize];
3497 if (!wtext)
3498 {
3499 WARN(true, _T("TListViewCtrl::SetInfoTip Memory for wide char buffer failed"));
3500 return false;
3501 }
3502
3503 // Convert to wide-char string.
3504 //
3506 {
3507 WARN(true, _T("TListViewCtrl::SetInfoTip ::MultiByteToWideChar conversion failed for text string"));
3508 delete [] wtext;
3509 return false;
3510 }
3511 }
3512
3513 // Set the infotip.
3514 //
3515 auto ret = SetInfoTip(wtext, index, subitemIndex);
3516
3517 // Release wide-char string if created.
3518 //
3519 if (wtext) delete [] wtext;
3520
3521 // Return result.
3522 //
3523 return ret;
3524}
3525
3526//
3527/// String overload for \link SetInfoTip(LPCWSTR, int, int) \endlink.
3528//
3529auto
3531{
3532 PRECONDITION(GetHandle());
3533 return SetInfoTip(text.c_str(), index, subitemIndex);
3534}
3535
3536//
3537/// Retrieves the view type.
3538//
3539/// \return the view type.
3540//
3541/// \sa http://msdn.microsoft.com/en-us/library/windows/desktop/bb761091.aspx
3542//
3543auto
3545{
3547 return static_cast<TViewType>(SendMessage(LVM_GETVIEW));
3548}
3549
3550//
3551/// Sets the view type.
3552//
3553/// @param[in] viewType is the view type ot set.
3554//
3555/// \return true if successful.
3556//
3557/// \sa http://msdn.microsoft.com/en-us/library/windows/desktop/bb761220.aspx
3558//
3559auto
3561{
3562 PRECONDITION(GetHandle());
3563 return ToBool(SendMessage(LVM_SETVIEW, TParam1(viewType)));
3564}
3565
3566//
3567/// Retrieves information about a tile in a list-view control.
3568//
3569/// @param[in,out] lvTileInfo is the class which specifies the tile item
3570/// information to retrieve, and upon return will contain the tile information.
3571//
3572/// \return none.
3573//
3574/// \note This function is not supported under the LVS_OWNERDATA style.
3575//
3576/// \sa http://msdn.microsoft.com/en-us/library/windows/desktop/bb761081.aspx
3577/// \sa http://msdn.microsoft.com/en-us/library/windows/desktop/bb774766.aspx
3578//
3579auto
3581{
3582 PRECONDITION(GetHandle());
3584 SendMessage(LVM_GETTILEINFO, 0, TParam2(lvTileInfo));
3585}
3586
3587//
3588/// Reference overload for \link GetTileInfo(PLVTILEINFO) const \endlink.
3589//
3590auto
3592{
3593 GetTileInfo(&lvTileInfo);
3594}
3595
3596//
3597/// Sets information about a tile in a list-view control.
3598//
3599/// @param[in] lvTileInfo is the class containing the tile information to set.
3600//
3601/// \note This function is not supported under the LVS_OWNERDATA style.
3602//
3603/// \return true if successful.
3604//
3605/// \sa http://msdn.microsoft.com/en-us/library/windows/desktop/bb761210.aspx
3606/// \sa http://msdn.microsoft.com/en-us/library/windows/desktop/bb774766.aspx
3607//
3608auto
3610{
3611 PRECONDITION(GetHandle());
3613 return ToBool(SendMessage(LVM_SETTILEINFO, 0, TParam2(lvTileInfo)));
3614}
3615
3616//
3617/// Reference overload for \link SetTileInfo(PLVTILEINFO) \endlink.
3618//
3619auto
3621{
3622 return SetTileInfo(&lvTileInfo);
3623}
3624
3625//
3626/// Retrieves tile view information.
3627//
3628/// @param[in,out] tileViewInfo is the class which specifies the tile view item
3629/// information to retrieve, and upon return will contain the tile view information.
3630//
3631/// \return none.
3632//
3633/// \sa http://msdn.microsoft.com/en-us/library/windows/desktop/bb761083.aspx
3634//
3635auto
3637{
3638 PRECONDITION(GetHandle());
3639 SendMessage(LVM_GETTILEVIEWINFO, 0, TParam2(&tileViewInfo));
3640}
3641
3642//
3643/// Sets tile view information.
3644//
3645/// @param[in] tileViewInfo is the class containing the tile view information to set.
3646//
3647/// \return true if successful.
3648//
3649/// \sa http://msdn.microsoft.com/en-us/library/windows/desktop/bb761212.aspx
3650//
3651auto
3653{
3654 PRECONDITION(GetHandle());
3655 return ToBool(SendMessage(LVM_SETTILEVIEWINFO, 0, TParam2(&tileViewInfo)));
3656}
3657
3658//
3659/// Retrieves the list-view control border color.
3660//
3661/// \note Only valid if the LVS_EX_BORDERSELECT extended window style is set.
3662//
3663/// \return the control border color.
3664//
3665/// \sa http://msdn.microsoft.com/en-us/library/windows/desktop/bb761065.aspx
3666//
3667auto
3673
3674//
3675/// Sets the list-view control border color.
3676//
3677/// @param[in] color is the color to set.
3678//
3679/// \note Only valid if the LVS_EX_BORDERSELECT extended window style is set.
3680//
3681/// \return the control border color.
3682//
3683/// \sa http://msdn.microsoft.com/en-us/library/windows/desktop/bb761200.aspx
3684//
3685auto
3687{
3688 PRECONDITION(GetHandle());
3689 return TColor(static_cast<COLORREF>(SendMessage(LVM_SETOUTLINECOLOR, 0, TParam2(COLORREF(color)))));
3690}
3691
3692// OWL version 5 compatibility; pointers to references
3693//
3694#if defined(OWL5_COMPAT)
3695
3696auto
3697TListViewCtrl::GetOrigin(POINT* p) const -> bool
3698{
3699 PRECONDITION(GetHandle());
3700 return ToBool(SendMessage(LVM_GETORIGIN, 0, TParam2(p)));
3701}
3702
3703auto
3704TListViewCtrl::GetViewRect(RECT* r) const -> bool
3705{
3706 PRECONDITION(GetHandle());
3707 return ToBool(SendMessage(LVM_GETVIEWRECT, 0, TParam2(r)));
3708}
3709
3710auto
3711TListViewCtrl::GetColumn(int index, LVCOLUMN* column) const -> bool
3712{
3714 PRECONDITION(GetHandle());
3715 return ToBool(SendMessage(LVM_GETCOLUMN, TParam1(index), TParam2(column)));
3716}
3717
3718auto
3719TListViewCtrl::GetItemPosition(int index, POINT* p) const -> bool
3720{
3721 PRECONDITION(GetHandle());
3722 return ToBool(SendMessage(LVM_GETITEMPOSITION, TParam1(index), TParam2(p)));
3723}
3724
3725auto
3726TListViewCtrl::GetItemRect(int index, RECT* r, TItemRectType type) const -> bool
3727{
3728 PRECONDITION(GetHandle());
3729 r->left = type;
3730 return ToBool(SendMessage(LVM_GETITEMRECT, TParam1(index), TParam2(r)));
3731}
3732
3733auto
3734TListViewCtrl::FindItem(int index, const TLvFindInfo* findInfo) const -> int
3735{
3737 return FindItem(index, *findInfo);
3738}
3739
3740#endif
3741
3746
3747} // OWL namespace
3748
#define CHECK(condition)
Definition checks.h:239
#define WARN(condition, message)
Definition checks.h:273
#define PRECONDITION(condition)
Definition checks.h:227
Class wrapper for management of color values.
Definition color.h:245
TControl unifies its derived control classes, such as TScrollBar, TControlGadget, and TButton.
Definition control.h:38
Encapsulates the system font used for a specific GUI element, e.g. icon, caption, menu,...
Definition gdiobjec.h:380
@ sfiIcon
Represents ICONMETRICS::lfFont.
Definition gdiobjec.h:389
TSize GetTextExtent(const tstring &text) const
Returns the extent of a given string using this particular font.
Definition font.cpp:194
Pure virtual base class for comparing sort items.
Encapsulates the ListView control, a window that displays a collection of items, each item consisting...
auto GetNextItem(int index, uint flags=TNextItemCode::All) const -> int
Searches for a list-view item that has the specified properties and bears the specified relationship ...
auto GetHoverTime() const -> uint32
Retrieves the amount of time that the mouse cursor must hover over an item before it is selected.
auto GetSubItemRect(TRect &rect, int subitemIndex=0, int index=0, TItemRectType type=Bounds) const -> bool
Retrieves the bounding rectangle for a subitem in a list-view control when in report view.
auto EditLabel(int index) -> HWND
Begins in-place editing of the list-view item's text.
auto DeleteAllItems() -> bool
Deletes all items from the list.
auto GetFocusItem() -> int
Retrieves the item index of the item that has the focus.
auto GetTopIndex() const -> int
Retrieves the topmost visible item index when in list or report view.
auto GetNextSelIndex(int index=-1) const -> int
Searches for the next selected item after a given index.
auto SetColumnOrder(int count, const int *array) -> bool
Sets the current left-to-right order of columns in a list-view control.
auto SetSelIndexes(int *indexes, int numSelections, bool select) -> bool
Selects or deselects items.
auto CalculateColumnWidth(LPCTSTR text, int padding=12) const -> int
Calculates a suitable column pixel width for the given string.
auto DeleteItem(int index) -> bool
Deletes an item from the list.
auto GetUnicodeFormat() const -> bool
Queries whether the Unicode character set is being used instead of ANSI.
auto GetApproxRect(int x=-1, int y=-1, int count=-1) const -> TSize
Calculates the approximate width and height required to display a given number of items.
auto GetItemIndexRect(int index, int group, int subitemIndex, TRect &rect, TItemRectType type) const -> bool
Sets the bounding rectangle for a subitem.
auto IsItemVisible(int index) const -> bool
Queries whether an item is visible.
auto GetNextItemIndex(int index, int group, uint flags=TNextItemCode::All) const -> int
Searches for a list-view item that has the specified properties and bears the specified relationship ...
auto GetNumOfWorkAreas() const -> uint
Retrieves the number of working areas in a list-view control.
auto GetSelIndexes(int *indexes, int maxCount) const -> int
Retrieves the indexes of the selected items.
auto GetViewRect(TRect &rect) const -> bool
Retrieves the bounding rectangle of all items in the list-view control when in icon or small icon vie...
auto GetISearchString() const -> tstring
Retrieves the incremental search string.
auto GetExtStyle() const -> uint32
Retrieves the extended styles that are currently in use for a given list-view control.
auto GetCountPerPage() const -> int
Calculates the number of items that can fit vertically in the visible area of a list-view control whe...
auto SetItemIndexState(const TLvItem &item, int index, int group) -> bool
Sets the state of a list-view item.
auto SetTileViewInfo(const TLvTileViewInfo &tileViewInfo) -> bool
Sets tile view information.
auto GetStringWidth(LPCTSTR text) const -> int
Calculates the exact width in pixels of the given string using the control's current font.
auto GetBkColor() const -> TColor
Retrieves the background color of a list-view control.
auto SetItemCount(int numItems, TSetItemCountBehavior behavior=Unspecified) -> bool
Sets the number of items that the list-view control will ultimately contain.
auto GetSelIndex() const -> int
Retrieves the selected item index.
auto GetEmptyText() const -> tstring
Retrieves the string to display when the list-view control appears empty.
auto GetTileViewInfo(TLvTileViewInfo &tileViewInfo) const -> void
Retrieves tile view information.
auto GetEditControl() const -> HWND
Retrieves the handle to the edit control used to edit a list-view item's text.
auto SortItemsEx(const TCompareFunc &Comparator, LPARAM lParam=0) -> bool
Sorts the list items.
auto GetItemPosition(int index, TPoint &pt) const -> bool
Retrieves the position of a list-view item.
auto AddItem(const TLvItem &item) -> int
Adds a new item to the end of the list.
auto GetFooterRect() const -> TRect
TRect return overload for GetFooterRect(TRect&) const .
auto GetHotItem() const -> int
Retrieves the index of the hot item.
auto SetItemPosition(int index, const TPoint &pt) -> bool
Sets the position of a list-view item.
auto Arrange(TArrangeCode code) -> bool
Arranges items in icon view.
TViewType
Describes the type of views.
auto GetItemCount() const -> int
Retrieves the number of items in the list-view control.
TImageListType
Describes the type of image list for use with the list window control.
auto SetFocusItem(int index, bool focused=true) -> bool
Sets or removes the focus for an item.
auto GetImageList(TImageListType type) const -> HIMAGELIST
Retrieves the handle to an image list used for drawing list-view items.
virtual auto GetWindowClassName() -> TWindowClassName
auto GetColumnOrder(int count, int *array) const -> bool
Retrieves the current left-to-right order of columns in a list-view control.
auto GetSelString(tchar *str, int maxChars, int subitemIndex=0) const -> bool
Retrieves the selected item or item subitem text.
auto GetSelectionMark() const -> int
Retrieves the selection mark from a list-view control.
auto GetSelCount(void) const -> int
Retrieves the number of selected items.
auto SortItems(const TCompareFunc &Comparator, LPARAM lParam=0) -> bool
Sorts the list items.
auto GetItemState(int index, uint mask) const -> TLvItem::TListState
Retrieves the current state for an item.
auto FindItem(int index, const TLvFindInfo &findInfo) const -> int
Searches for an item with the specified characteristics.
auto SetColumn(int colNum, const TLvColumn &column) -> bool
Sets the attributes of a list-view control's column.
auto GetToolTips() const -> HWND
Retrieves the handle of the tooltip control that the list-view control uses to display tooltips.
auto InsertItem(const TLvItem &item, int index=-1) -> int
Inserts a new item to the list.
TSetItemCountBehavior
Describes the behavior for the control when setting the item count.
auto SetIconSpacing(int x, int y) -> TSize
Sets the spacing between icons in list-view controls that have the LVS_ICON style.
TArrangeCode
TArrangeCode is used to describe how to arrange the items in a list window control.
auto GetColumnWidth(int colNum) const -> int
Retrieves the width of a column in report or list view.
auto GetOutlineColor() const -> TColor
Retrieves the list-view control border color.
auto SubItemHitTest(TLvHitTestInfo &info) const -> int
Determines which list-view item or subitem is at a given position.
auto SetTextBkColor(const TColor &c) -> bool
Sets the background color of text in a list-view control.
auto GetFooterItemText(int index) const -> std::wstring
Footer item text string return overload for GetFooterItem(int, TLvFooterItem&) const .
TListViewCtrl(TWindow *parent, int id, int x, int y, int w, int h, TModule *module=0)
Constructor that simply passes the parameters to the parent TControl::TControl(TWindow*,...
auto HitTest(TLvHitTestInfo &) const -> int
Determines whether a list-view item is at a specified position.
auto GetGroupInfo(int groupId, uint mask=0xFFFFFFFF) -> LVGROUP
Gets group information.
auto SetHotItem(int index) -> int
Sets the index of the hot item.
auto Update(int index) -> bool
Updates a list-view item.
auto GetTileInfo(PLVTILEINFO lvTileInfo) const -> void
Retrieves information about a tile in a list-view control.
auto SetTileInfo(PLVTILEINFO lvTileInfo) -> bool
Sets information about a tile in a list-view control.
auto GetTextBkColor() const -> TColor
Retrieves the text background color of a list-view control.
auto GetOrigin(TPoint &pt) const -> bool
Retrieves the current view origin for a list-view control.
auto CancelEditLabel() -> void
Cancels an item text editing operation.
auto GetFooterInfo(TLvFooterInfo &info) const -> bool
Retrieves information about the footer of a list-view control.
auto SetItemState(int index, TLvItem::TListState state, uint mask) -> bool
Sets the current state for an item.
auto SetTextColor(const TColor &c) -> bool
Sets the color of text in a list-view control.
auto SetSel(int index, bool select) -> bool
Selects or deselects an item.
TItemRectType
Describes the type of rectangle boundaries to retrieve.
auto SetExtStyle(uint32 mask, uint32 style) -> uint32
Sets the extended styles to use for a given list-view control.
auto SetImageList(HIMAGELIST list, TImageListType type) -> HIMAGELIST
Assigns an image list to a list-view control.
auto MapIndexToId(int index) const -> TItemId
Associates a unique identifier with an item.
auto Scroll(int dx, int dy) -> bool
Scrolls the content of a list-view control.
auto DeleteColumn(int colNum) -> bool
Deletes a column in a list-view control.
auto SetInfoTip(LPCWSTR text, int index, int subitemIndex=0) -> bool
Sets tooltip text in delayed response to the LVN_GETINFOTIP notification.
auto SetBkColor(const TColor &c) -> bool
Sets the background color of a list-view control.
auto GetView() const -> TViewType
Retrieves the view type.
auto RedrawItems(int startIndex, int endIndex) -> bool
Forces a list-view control to redraw a range of items.
auto IsSelected(int index) const -> bool
Queries if an item is selected.
auto SetSelItemRange(bool select, int first, int last) -> bool
Selects or deselects a range of items.
auto SetBkImage(const TLvBkImage &bkimg) -> bool
Sets the background image in a list-view control.
auto GetItemText(int index, TLvItem &item) const -> int
Retrieves the text of the item.
auto GetSelStrings(tchar **strs, int maxCount, int maxChars, int subitemIndex=0) const -> int
Retrieves the item or subitem strings of the selected items.
auto GetHotCursor() const -> HCURSOR
Retrieves the cursor handle used when the pointer is over an item while hot tracking is enabled.
auto MapIdToIndex(TItemId id) const -> int
Retrieves the current index for the item with the given unique identifier.
auto SetToolTips(THandle handle) -> HWND
Sets the handle of the tooltip control that the list-view control uses to display tooltips.
auto GetColumn(int colNum, TLvColumn &column) const -> bool
Retrieves the attributes of a list-view control's column.
auto GetSelectedColumn() const -> int
Retrieves the currently selected column number.
auto GetCallBackMask() const -> TLvItem::TListState
Retrieves the callback mask for a list-view control.
auto EnsureVisible(int index, bool partialOk) -> bool
Ensures that a list-view item is either partially or entirely visible, scrolling the list-view contro...
auto SetSelectedColumn(int colNum) -> void
Sets the selected column number.
auto SetOutlineColor(const TColor &color) -> TColor
Sets the list-view control border color.
auto SetWorkAreas(int count, TRect *areas) -> void
Sets the working areas for a list-view control.
auto GetItemSpacing(bool smallIcon) const -> TSize
Retrieves the amount of horizontal and vertical spacing between items.
auto GetWorkAreas(int count, TRect *areas) const -> void
Retrieves the working areas from a list-view control.
auto GetFooterItem(int index, TLvFooterItem &item) const -> bool
Retrieves information for a footer item in a list-view control.
auto GetItemRect(int index, TRect &rect, TItemRectType type) const -> bool
Retrieves the bounding rectangle of a list-view item.
TParam1 TItemId
Defines the type of a unique identifier for an item.
auto InsertColumn(int colNum, const TLvColumn &column) -> int
Inserts a new column in a list-view control.
auto SetItemPosition32(int index, const TPoint &pt) -> void
Sets the position of a list-view item.
auto SetHotCursor(HCURSOR cur) -> HCURSOR
Sets the cursor handle to use when the pointer is over an item while hot tracking is enabled.
auto GetTextColor() const -> TColor
Retrieves the text color of a list-view control.
auto SetColumnWidth(int colNum, int width) -> bool
Sets the width of a column in report or list view.
auto SetView(TViewType viewType) -> bool
Sets the view type.
auto SetItemText(int index, const TLvItem &item) -> bool
Sets the text of a list-view item or subitem.
TNextItemCode
Describes the next item to retrieve from the current item.
auto GetItem(TLvItem &item, int index=-1, int subitemIndex=-1) const -> bool
Retrieves a list-view item's attributes.
auto GetBkImage(TLvBkImage &bkimg) const -> bool
Retrieves the background image in a list-view control.
auto GetFooterItemState(int index, TLvFooterItem::TState mask=TLvFooterItem::All) const -> TLvFooterItem::TState
Footer item state return overload for GetFooterItem(int, TLvFooterItem&) const .
auto GetHeaderCtrl() const -> HWND
Retrieves the handle to the header control used by the list-view control.
auto SetUnicodeFormat(bool useUnicode=true) -> bool
Sets whether the Unicode character set is being used instead of ANSI.
auto SetSelectionMark(int index) -> int
Sets the selection mark for a list-view control.
auto GetFooterItems() const -> int
Footer item count return overload for GetFooterInfo(TLvFooterInfo&) const .
auto SetCallBackMask(TLvItem::TListState mask) -> bool
Sets the callback mask for a list-view control.
auto CreateDragImage(int index, TPoint *upLeft) -> HIMAGELIST
Creates a drag image list for an item.
auto SetItem(const TLvItem &item, int index=-1, int subitemIndex=-1) -> bool
Sets a list-view item's attributes.
auto SetHoverTime(uint32 tm) -> uint32
Sets the amount of time that the mouse cursor must hover over an item before it is selected.
auto GetFooterItemRect(int index, TRect &rect) const -> bool
Retrieves the coordinates of a footer for an item in a list-view control.
Encapsulates structure LVCOLUMN, used to pass or retrieve column attributes in a TListViewCtrl.
auto SetText(const tstring &text) -> void
Copies the given text into the internal text buffer.
TLvColumn(uint mask_=lvcfAll, int subitemIndex=0, int bufferSize=1000)
Constructs an empty parameter package.
auto operator=(const LVCOLUMN &column) -> TLvColumn &
Overloads the assignment operator to perform a deep copy using a separate string buffer if applicable...
auto GetWidth() const -> int
Retrieves the current width for the column.
auto GetFormat() const -> TFormat
Retrieves the current alignment format for the column.
auto SetTextBuffer(TCHAR *buffer, int bufferSize) -> void
Overrides the internal buffer and assigns an external text buffer.
TFormat
TFormat is used to describe the alignment of a column in a list window.
@ Unspecified
Unspecified.
auto GetImage() const -> int
Retrieves the current image index used for the column.
auto GetSubItem() const -> int
Retrieves the current subitem used for the column.
auto SetSubItem(int subitemIndex) -> void
Sets the subitem index.
auto SetOrder(int order) -> void
Sets the column order offset.
auto SetFormat(TFormat how) -> void
Sets the alignment format for the column.
auto SetWidth(int width, const tstring &text=tstring()) -> void
Sets the width of the column.
auto SetImage(int image) -> void
Sets the image index within the image list to use.
auto Init() -> void
Initializes member data; used by internal routines.
auto GetOrder() const -> int
Retrieves the current column order offset used for the column.
auto GetText() const -> LPCTSTR
Retrieves the current text for the column.
Encapsulates structure LVFINDINFO, used to find an item in a TListViewCtrl.
auto SetPartial(const tstring &text) -> void
Sets a string to be used for a partial search.
auto SetString(const tstring &text) -> void
Sets a string to be used for the search.
tstring Text
String used for searching.
auto SetData(LPARAM param) -> void
Sets extra application-specific information.
TLvFindInfo()
Constructs with an empty string and parameter.
auto SetSubstring(const tstring &text) -> void
Sets a string to be used for an exact search.
auto SetWrap(bool wrap=true) -> void
Sets the setting for wrap-around during a search.
Encapsulates structure LVHITTESTINFO, used to contain information about a hit test in a TListViewCtrl...
Encapsulates structure LVITEM, used to describe an item in a TListViewCtrl.
auto GetState() const -> int
Retrieves the current state used for the item.
auto SetItemData(LPARAM param) -> void
Sets the application-defined data.
auto SetImageIndex(int image) -> void
Sets the image index within the image list to use.
auto SetIndent(int indent) -> void
Sets the number of image widths to indent the item.
auto GetText() const -> LPCTSTR
Retrieves the current text for the item.
TListState
TListState is used to describe the state of an item.
@ Focus
Only one item has focus.
@ Unspecified
Unspecified state.
@ Selected
Marked as selected.
TLvItem(uint mask_=lvifAll, bool allocTextBuffer=true, int bufferSize=1000)
Constructs an empty parameter package.
auto GetStateImage() const -> int
Retrieves the current state image index used for the item.
auto SetText(const tstring &text) -> void
Copies the given text into the internal text buffer.
auto SetTextBuffer(TCHAR *buffer, int bufferSize) -> void
Overrides the internal buffer and assigns an external text buffer.
auto GetIndent() const -> int
Retrieves the current number of image widths to indent the item.
auto SetSubItem(int subitemIndex) -> void
Sets the subitem index.
void Init()
Initializes member data; used by internal routines.
auto GetIndex() const -> int
Retrieves the item index.
auto GetItemData() const -> LPARAM
Retrieves the application-defined data.
auto SetStateImage(int stateIndex) -> void
Sets the state image index to use.
auto SetState(TListState state) -> void
Sets the state to use.
auto GetImageIndex() const -> int
Retrieves the current image index used for the item.
auto operator=(const LVITEM &item) -> TLvItem &
Overloads the assignment operator to perform a deep copy using a separate string buffer if applicable...
auto SetIndex(int index) -> void
Sets the item index.
auto GetSubItem() const -> int
Retrieves the subitem index.
Encapsulates structure LVTILEVIEWINFO, used to pass or retrieve tile view information in a TListViewC...
auto SetMaxTextLines(int lines) -> void
Sets the specified maximum number of text lines in each item label.
TTileSize
TTileSize describes the sizing of tiles in a list view control.
auto SetSizeAutomatic() -> void
Sets the tile view size to automatic.
auto SetLabelMargin(const TRect &labelMargin) -> void
Sets the specified coordinates of the label margin.
TLvTileViewInfo()
Constructs an automatic-sized tile view.
auto RemoveLabelMargin() -> void
Removes the specified coordinates of the label margin.
auto RemoveMaxTextLines() -> void
Removes the specified maximum number of text lines in each item label.
auto SetTileSize(const TSize &size) -> void
Sets the specified tile size.
auto SetSizeFixed(const TSize &size, TTileSize fixedSize) -> void
Sets the tile view size to fixed-width and/or fixed-height.
ObjectWindows dynamic-link libraries (DLLs) construct an instance of TModule, which acts as an object...
Definition module.h:75
TPoint is a support class, derived from tagPOINT.
Definition geometry.h:87
TRect is a mathematical class derived from tagRect.
Definition geometry.h:308
The tagSIZE struct is defined as.
Definition geometry.h:234
Type-safe encapsulation of a Windows class name, a union between ATOM and LPCTSTR.
Definition module.h:47
TWindow, derived from TEventHandler and TStreamableBase, provides window-specific behavior and encaps...
Definition window.h:414
TResult SendMessage(TMsgId, TParam1=0, TParam2=0) const
Sends a message (msg) to a specified window or windows.
Definition window.cpp:3288
HWND THandle
TWindow encapsulates an HWND.
Definition window.h:418
HWND GetHandle() const
Returns the handle of the window.
Definition window.h:2020
TXOwl is root class of the ObjectWindows exception hierarchy.
Definition except.h:38
size_t __stdcall wcslen(const wchar_t *str)
#define _tcslen
Definition cygwin.h:74
#define _T(x)
Definition cygwin.h:51
Definition of TListViewCtrl class.
Object Windows Library (OWLNext Core)
Definition animctrl.h:22
void InitializeCommonControls(uint controlFlags)
Wrapper for the Windows API function InitCommmonControlsEx.
Definition commctrl.cpp:19
uint16 HiUint16(LRESULT r)
Definition defs.h:270
unsigned long uint32
Definition number.h:34
char tchar
Definition defs.h:77
void InUse(const T &arg)
Handy utility to avoid compiler warnings about unused parameters.
Definition defs.h:299
LPARAM TParam2
Second parameter type.
Definition dispatch.h:55
bool ToBool(const T &t)
Definition defs.h:291
WPARAM TParam1
First parameter type.
Definition dispatch.h:54
uint16 LoUint16(LRESULT r)
Definition defs.h:264
TParam2 MkParam2(const T1 &lo, const T2 &hi)
Definition dispatch.h:65
OWL_DIAGINFO
Definition animctrl.cpp:14
std::string tstring
Definition defs.h:79
unsigned int uint
Definition number.h:25
Definition of TSystem, a system information provider class.
#define WS_EX_CLIENTEDGE
Definition wsysinc.h:33