24#define MULTIPLESEL (LBS_MULTIPLESEL | LBS_EXTENDEDSEL)
60 return SelIndices->Size();
88 ItemDatas->Add(itemData);
98 if (index != LB_ERR && SelIndices->Find(index) == SelIndices->NPOS)
99 SelIndices->Add(index);
108 for (
uint i = 0; i < Strings->Size(); i++)
109 if (
_tcscmp((*Strings)[i].c_str(), str) == 0) {
123 static_cast<int>((*Strings)[(*SelIndices)[index]].length()) :
134 if (bufferSize > 0) {
139 _tcsncpy(buffer, (*Strings)[(*SelIndices)[index]].c_str(), bufferSize-1);
140 buffer[bufferSize - 1] = 0;
152 str = (*Strings)[(*SelIndices)[index]];
177 int x,
int y,
int w,
int h,
180 TControl(parent, id, nullptr, x, y, w, h, module)
182 Attr.Style |= LBS_STANDARD;
195 TControl(parent, resourceId, module)
229 if (!buffer && direction !=
tdSizeData)
return 0;
237 listBoxData->
Clear();
244 for (i = 0; i < count; i++) {
246 if (strLen > maxStrLen)
272 int* selections =
new int[selCount];
278 for (
int selIndex = 0; selIndex < selCount; selIndex++)
279 listBoxData->
Select(selections[selIndex]);
290 const int noSelection = -1;
292 int selIndex = noSelection;
297 if(i < listBoxData->GetItemDatas().Size())
300 for (
uint j = 0; j < selCount; j++)
301 if (listBoxData->
GetSelIndices()[j] ==
static_cast<int>(i)) {
313 if (selIndex != noSelection && index <= selIndex)
317 if (selIndex != noSelection && !(style &
MULTIPLESEL))
339TListBox::FindExactString(LPCTSTR findStr,
int startIndex)
const
342 int firstMatch = indexStart =
FindString(findStr, startIndex);
344 if (startIndex > -1) {
349 if (
_tcscmp(tmpStr, findStr) == 0)
354 }
while (!found && startIndex != firstMatch);
356 return found ? startIndex : -1;
379 if (maxChars >= length)
431 int* selections =
new int[maxCount];
435 for (
int selIndex = 0; selIndex < maxCount; selIndex++) {
438 if (maxChars >= tmpStrLen)
439 GetString(strs[selIndex], selections[selIndex]);
441 else if(tmpStrLen > 0) {
444 _tcsncpy(strs[selIndex], tmpStr, maxChars);
460 for (
int i = 0; i !=
static_cast<int>(selections.
size()); ++i)
498 if (numSelections < 0)
499 return SetSel(-1, shouldSet);
502 for (
int i = 0; i < numSelections; i++) {
504 if ((selIndex =
FindString(strs[i], -1)) > -1)
505 if (
SetSel(selIndex, shouldSet) > -1)
521 for (
int i = 0; i < static_cast<int>(strs.
size()); i++)
525 if (
SetSel(selIndex, shouldSet) > -1)
573 std::vector<int> buf(selCount);
574 int n =
GetSelIndexes(&buf[0],
static_cast<int>(buf.size()));
575 CHECK(n ==
static_cast<int>(buf.size()));
576 for (
int i = 0; i != n; ++i)
577 selections.
Add(buf[i]);
592 return static_cast<int>(
SendMessage(LB_SETCURSEL, index));
613 if (numSelections < 0)
614 return static_cast<int>(
SendMessage(LB_SETSEL, shouldSet, -1));
617 for (
int i = 0; i < numSelections; i++)
618 if (
static_cast<int>(
SendMessage(LB_SETSEL, shouldSet, indexes[i])) > -1)
634 for (
int i = 0; i < static_cast<int>(indexes.
size()); i++)
635 if (
static_cast<int>(
SendMessage(LB_SETSEL, shouldSet, indexes[i])) > -1)
656 return (
SetSelIndex(selected ? index : -1) >= 0) || (index == -1) || !selected;
679struct TListBoxGetString
683 TListBoxGetString(
const TListBox& c,
int index_) : listbox(c), index(index_) {}
685 int operator()(LPTSTR buf,
int buf_size)
717#if OWL_PERSISTENT_STREAMS
733TListBox::Streamer::Write(opstream& os)
const
#define PRECONDITION(condition)
Pointer to an array of type T.
TControl unifies its derived control classes, such as TScrollBar, TControlGadget, and TButton.
TControl(TWindow *parent, int id, LPCTSTR title, int x, int y, int w, int h, TModule *module=nullptr)
Invokes TWindow's constructor, passing it parent (parent window), title (caption text),...
Used to transfer the contents of a list box.
TIntArray & GetSelIndices()
Returns a reference to the SelIndices array.
void AddString(LPCTSTR str, bool isSelected=false)
Adds the specified string to Strings.
TStringArray & GetStrings()
Returns a reference to a TStringArray object containing the strings.
void Clear()
Resets the list box by flushing the ItemDatas and Strings arrays and calling ResetSelections.
~TListBoxData()
Deletes the space allocated for Strings and SelStrings.
TListBoxData()
Constructs Strings and SelStrings. Initializes SelCount to 0.
TLParamArray & GetItemDatas()
Returns a reference to the ItemDatas array.
int GetSelCount() const
Returns the number of items in SelIndices.
void AddStringItem(LPCTSTR str, LPARAM itemData, bool isSelected=false)
Adds a string to the Strings array, optionally selects it, and adds itemData to the ItemDatas array.
int GetSelStringLength(int index=0) const
Returns the length (excluding the terminating NULL) of the string at the specified index in SelIndice...
void SelectString(LPCTSTR str)
Adds the index of the string matching str to SelIndices.
void Select(int index)
Selects the string at the given index.
void GetSelString(TCHAR *buffer, int bufferSize, int index=0) const
Locates the string at the specified index in SelIndices and copies it into buffer.
void ResetSelections()
Flushes SelIndices.
An interface object that represents a corresponding list box element.
virtual int SetItemData(int index, LPARAM itemData)
Sets the custom value associated with the list box item at the specified index position.
virtual int ReplaceString(LPCTSTR str, int index)
Replaces the item in the list at the position supplied in index, and returns that item's actual posit...
virtual LPARAM GetItemData(int index) const
Returns the custom value associated with the item at index set by SetItemData.
tstring GetSelString() const
String-aware overload.
virtual int SetSelIndex(int index)
For single-selection list boxes.
virtual int AddString(LPCTSTR str)
Adds str to the list box, returning its position in the list (0 is the first position).
virtual int GetStringLen(int index) const
Returns the string length (excluding the terminating NULL) of the item at the position index supplied...
void Transfer(TListBoxData &data, TTransferDirection direction)
int GetSelIndexes(int *indexes, int maxCount) const
For multiple-selection list boxes.
int SetSelIndexes(int *indexes, int numSelections, bool shouldSet)
For multiple-selection list boxes.
virtual int FindString(LPCTSTR str, int startIndex=-1) const
Returns the index of the first string in the associated listbox which begins with the passed string.
virtual int InsertString(LPCTSTR str, int index)
Inserts str in the list box at the position supplied in index, and returns the item's actual position...
virtual int GetCount() const
Returns the number of items in the list box, or a negative value if an error occurs.
TListBox(TWindow *parent, int id, int x, int y, int w, int h, TModule *module=0)
Constructs a list box object with the supplied parent window (parent) library ID (module),...
virtual int DeleteString(int index)
Deletes the item in the list at the position (starting at 0) supplied in index.
bool IsSelected(int index) const
Returns true if the index is selected.
TIntArray GetSelIndexes() const
Container-aware overload.
virtual auto GetWindowClassName() -> TWindowClassName
Returns the name of TListBox's registration class, "LISTBOX".
int GetSelCount() const
Returns the number of selected items in the single- or multiple-selection list box or combo box.
virtual void ClearList()
Clears all the entries in the associated listbox.
int SetSel(int index, bool select)
For multiple-selection list boxes.
bool SetSelected(int index, bool selected=true)
Sets the selection state for the item at the specified index, and returns true if successful.
virtual int GetString(TCHAR *str, int index) const
Retrieves the contents of the string at the passed index of the associated listbox.
virtual int SetSelString(LPCTSTR str, int startIndex=-1)
For single-selection list boxes.
TStringArray GetSelStrings() const
Container-aware overload.
int SetSelStrings(LPCTSTR *prefixes, int numSelections, bool shouldSet)
For multiple-selection list boxes, selects the strings in the associated list box that begin with the...
virtual int GetSelIndex() const
For single-selection list boxes.
ObjectWindows dynamic-link libraries (DLLs) construct an instance of TModule, which acts as an object...
Type-safe encapsulation of a Windows class name, a union between ATOM and LPCTSTR.
TWindow, derived from TEventHandler and TStreamableBase, provides window-specific behavior and encaps...
uint32 GetStyle() const
Gets the style bits of the underlying window or the 'Style' member of the attribute structure associa...
TResult SendMessage(TMsgId, TParam1=0, TParam2=0) const
Sends a message (msg) to a specified window or windows.
HWND THandle
TWindow encapsulates an HWND.
HWND GetHandle() const
Returns the handle of the window.
ipstream, a specialized input stream derivative of pstream, is the base class for reading (extracting...
void ReadBaseObject(Base *base, ipstream &in)
void WriteBaseObject(Base *base, opstream &out)
TTransferDirection
The TTransferDirection enum describes the constants that the transfer function uses to determine how ...
@ tdSizeData
Return the size of data transferred by the class.
@ tdSetData
Set data from the buffer into the window.
@ tdGetData
Get data from the window into the buffer.
Definition of class TListBox and TlistBoxData.
Object Windows Library (OWLNext Core).
TTypedArray< int, int, TStandardAllocator > TIntArray
TObjectArray< tstring > TStringArray
LPARAM TParam2
Second parameter type.
tstring CopyText(int size, TGetText get_text)
Copies text from a C-string (null-terminated character array) into a string object,...
WPARAM TParam1
First parameter type.
TTypedArray< LPARAM, LPARAM, TStandardAllocator > TLParamArray
IMPLEMENT_STREAMABLE1(TApplication, TModule)
#define CONST_CAST(targetType, object)