37#define LIST_MASK (SELECT_MASK | LIST_AUTOSELECT)
71FXIMPLEMENT(
MFXListIcon, FXScrollArea, MFXListIconMap, ARRAYNUMBER(MFXListIconMap))
77MFXListIcon::
MFXListIcon(FXComposite* p, FXObject* tgt, FXSelector sel, FXuint opts, FXint x, FXint y, FXint w, FXint h):
78 FXScrollArea(p, opts, x, y, w, h) {
79 flags |= FLAG_ENABLED;
82 font = getApp()->getNormalFont();
83 textColor = getApp()->getForeColor();
84 selbackColor = getApp()->getSelbackColor();
85 seltextColor = getApp()->getSelforeColor();
90 getApp()->removeTimeout(
this, ID_TIPTIMER);
93 font = (FXFont*) - 1L;
99 FXScrollArea::create();
100 for (
const auto& item :
items) {
109 FXScrollArea::detach();
110 for (
const auto& item :
items) {
125 FXScrollArea::setFocus();
132 FXScrollArea::killFocus();
139 return FXScrollArea::getDefaultWidth();
155 FXScrollArea::recalc();
156 flags |= FLAG_RECALC;
175 if (flags & FLAG_RECALC) {
184 if (flags & FLAG_RECALC) {
194 FXScrollArea::layout();
198 horizontal->setLine(
itemFiltered[0]->getWidth(
this) / 10);
206 flags &= ~(FXuint)FLAG_DIRTY;
212 for (
int i = 0; i < (int)
items.size(); i++) {
223 return (0 < (pos_y + item->
y + item->
getHeight(
this))) && ((pos_y + item->
y) < viewport_h);
235 if (flags & FLAG_RECALC) {
240 if (viewport_h <= y + item->y + h) {
241 y = viewport_h - item->
y - h;
243 if (y + item->
y <= 0) {
247 setPosition(pos_x, y);
262 if ((index < 0) || ((
int)
itemFiltered.size() <= index)) {
263 fxerror(
"%s::isItemSelected: index out of range.\n", getClassName());
271 if ((index < 0) || ((
int)
itemFiltered.size() <= index)) {
272 fxerror(
"%s::isItemSelected: index out of range.\n", getClassName());
283 for (
int i = 0; i < (int)
items.size(); i++) {
301 for (
int i = 0; i < (int)
items.size(); i++) {
302 if (
items[i]->getText().text() == text) {
312 FXint ix, iy, hit = 0;
318 hit = item->
hitItem(
this, x - ix, y - iy);
336 if (notify && target) {
337 target->tryHandle(
this, FXSEL(SEL_SELECTED, message),
nullptr);
351 if (notify && target) {
352 target->tryHandle(
this, FXSEL(SEL_DESELECTED, message),
nullptr);
367 if (notify && target) {
368 target->tryHandle(
this, FXSEL(SEL_SELECTED, message),
nullptr);
373 if (notify && target) {
374 target->tryHandle(
this, FXSEL(SEL_DESELECTED, message),
nullptr);
383 FXbool changes = FALSE;
385 for (i = 0; i < (int)
items.size(); i++) {
386 if (
items[i]->isSelected()) {
387 items[i]->setSelected(FALSE);
390 if (notify && target) {
391 target->tryHandle(
this, FXSEL(SEL_DESELECTED, message), (
void*)(FXival)i);
401 FXScrollArea::onEnter(sender, sel, ptr);
402 getApp()->addTimeout(
this, ID_TIPTIMER, getApp()->getMenuPause());
410 FXScrollArea::onLeave(sender, sel, ptr);
411 getApp()->removeTimeout(
this, ID_TIPTIMER);
419 FXScrollArea::onFocusIn(sender, sel, ptr);
437 if (FXWindow::onQueryTip(sender, sel, ptr)) {
440 if (
cursor && (flags & FLAG_TIP) && !(options & LIST_AUTOSELECT)) {
442 sender->handle(
this, FXSEL(SEL_COMMAND, ID_SETSTRINGVALUE), (
void*) &
string);
451 if (FXWindow::onQueryHelp(sender, sel, ptr)) {
454 if ((flags & FLAG_HELP) && !
help.empty()) {
455 sender->handle(
this, FXSEL(SEL_COMMAND, ID_SETSTRINGVALUE), (
void*) &
help);
464 FXScrollArea::onFocusOut(sender, sel, ptr);
475 FXEvent*
event = (FXEvent*)ptr;
476 FXDCWindow dc(
this, event);
482 if (event->rect.y <= (y + h) && y < (
event->rect.y +
event->rect.h)) {
488 if (y < (event->rect.y + event->rect.h)) {
489 dc.setForeground(backColor);
490 dc.fillRectangle(event->rect.x, y, event->rect.w, event->rect.y + event->rect.h - y);
505 FXEvent*
event = (FXEvent*)ptr;
511 if (target && target->tryHandle(
this, FXSEL(SEL_KEYPRESS, message), ptr)) {
514 switch (event->code) {
521 if (flags & FLAG_DODRAG) {
522 handle(
this, FXSEL(SEL_DRAGGED, 0), ptr);
528 setPosition(pos_x, pos_y + verticalScrollBar()->getPage());
531 case KEY_KP_Page_Down:
533 setPosition(pos_x, pos_y - verticalScrollBar()->getPage());
554 if (0 <= index && index < (
int)
items.size()) {
559 if ((0 <= index) && (index < (
int)
itemFiltered.size())) {
564 handle(
this, FXSEL(SEL_CLICKED, 0), (
void*)
currentItem);
566 handle(
this, FXSEL(SEL_COMMAND, 0), (
void*)
currentItem);
576 handle(
this, FXSEL(SEL_CLICKED, 0), (
void*)
currentItem);
578 handle(
this, FXSEL(SEL_COMMAND, 0), (
void*)
currentItem);
584 handle(
this, FXSEL(SEL_DOUBLECLICKED, 0), (
void*)
currentItem);
586 handle(
this, FXSEL(SEL_COMMAND, 0), (
void*)
currentItem);
597 FXEvent*
event = (FXEvent*)ptr;
601 if (target && target->tryHandle(
this, FXSEL(SEL_KEYRELEASE, message), ptr)) {
604 switch (event->code) {
611 if (flags & FLAG_DODRAG) {
612 handle(
this, FXSEL(SEL_DRAGGED, 0), ptr);
628 FXEvent*
event = (FXEvent*)ptr;
636 getApp()->removeTimeout(
this, ID_TIPTIMER);
639 if (flags & FLAG_SCROLLING) {
640 setPosition(event->win_x -
grabx, event->win_y -
graby);
645 if (flags & FLAG_DODRAG) {
646 if (startAutoScroll(event, TRUE)) {
649 handle(
this, FXSEL(SEL_DRAGGED, 0), ptr);
654 if ((flags & FLAG_TRYDRAG) && event->moved) {
655 flags &= ~FLAG_TRYDRAG;
656 if (handle(
this, FXSEL(SEL_BEGINDRAG, 0), ptr)) {
657 flags |= FLAG_DODRAG;
663 if ((flags & FLAG_PRESSED) || (options & LIST_AUTOSELECT)) {
665 if (startAutoScroll(event, FALSE)) {
679 getApp()->addTimeout(
this, ID_TIPTIMER, getApp()->getMenuPause());
685 return (
cursor != oldcursor) || (flg & FLAG_TIP);
691 FXEvent*
event = (FXEvent*)ptr;
694 handle(
this, FXSEL(SEL_FOCUS_SELF, 0), ptr);
697 flags &= ~FLAG_UPDATE;
699 if (target && target->tryHandle(
this, FXSEL(SEL_LEFTBUTTONPRESS, message), ptr)) {
703 if (options & LIST_AUTOSELECT) {
709 if (item ==
nullptr) {
713 code =
hitItem(item, event->win_x, event->win_y);
717 state = item->isSelected();
718 if (item->isEnabled() && !
state) {
722 if (code && item->isSelected() && item->isDraggable()) {
723 flags |= FLAG_TRYDRAG;
725 flags |= FLAG_PRESSED;
734 FXEvent*
event = (FXEvent*)ptr;
739 flags |= FLAG_UPDATE;
740 flags &= ~(FLAG_PRESSED | FLAG_TRYDRAG | FLAG_DODRAG);
742 if (target && target->tryHandle(
this, FXSEL(SEL_LEFTBUTTONRELEASE, message), ptr)) {
746 if (!(flg & FLAG_PRESSED) && !(options & LIST_AUTOSELECT)) {
750 if (flg & FLAG_DODRAG) {
751 handle(
this, FXSEL(SEL_ENDDRAG, 0), ptr);
764 if (event->click_count == 1) {
765 handle(
this, FXSEL(SEL_CLICKED, 0), (
void*)
currentItem);
766 }
else if (event->click_count == 2) {
767 handle(
this, FXSEL(SEL_DOUBLECLICKED, 0), (
void*)
currentItem);
768 }
else if (event->click_count == 3) {
769 handle(
this, FXSEL(SEL_TRIPLECLICKED, 0), (
void*)
currentItem);
773 handle(
this, FXSEL(SEL_COMMAND, 0), (
void*)
currentItem);
783 FXEvent*
event = (FXEvent*)ptr;
785 handle(
this, FXSEL(SEL_FOCUS_SELF, 0), ptr);
788 flags &= ~FLAG_UPDATE;
789 if (target && target->tryHandle(
this, FXSEL(SEL_RIGHTBUTTONPRESS, message), ptr)) {
792 flags |= FLAG_SCROLLING;
793 grabx =
event->win_x - pos_x;
794 graby =
event->win_y - pos_y;
805 flags &= ~FLAG_SCROLLING;
806 flags |= FLAG_UPDATE;
807 if (target && target->tryHandle(
this, FXSEL(SEL_RIGHTBUTTONRELEASE, message), ptr)) {
818 FXScrollArea::onUngrabbed(sender, sel, ptr);
819 flags &= ~(FLAG_DODRAG | FLAG_TRYDRAG | FLAG_PRESSED | FLAG_CHANGED | FLAG_SCROLLING);
820 flags |= FLAG_UPDATE;
828 return target ? target->tryHandle(
this, FXSEL(SEL_COMMAND, message), ptr) : 0;
834 return target ? target->tryHandle(
this, FXSEL(SEL_CLICKED, message), ptr) : 0;
840 return target ? target->tryHandle(
this, FXSEL(SEL_DOUBLECLICKED, message), ptr) : 0;
846 return target ? target->tryHandle(
this, FXSEL(SEL_TRIPLECLICKED, message), ptr) : 0;
865 if (notify && target) {
866 target->tryHandle(
this, FXSEL(SEL_CHANGED, message), (
void*)
currentItem);
874 for (
int i = 0; i < (int)
items.size(); i++) {
887 for (
int i = 0; i < (int)
items.size(); i++) {
908 for (
int i = 0; i < (int)
items.size(); i++) {
909 if (
items[i] == item) {
939 if (index < 0 || (
int)
items.size() <= index) {
940 fxerror(
"%s::getItem: index out of range.\n", getClassName());
950 fxerror(
"%s::setItem: item is NULL.\n", getClassName());
953 if (index < 0 || (
int)
items.size() <= index) {
954 fxerror(
"%s::setItem: index out of range.\n", getClassName());
957 if (notify && target) {
958 target->tryHandle(
this, FXSEL(SEL_REPLACED, message), (
void*)(FXival)index);
983 fxerror(
"%s::insertItem: item is NULL.\n", getClassName());
986 if (index < 0 || (
int)
items.size() < index) {
987 fxerror(
"%s::insertItem: index out of range.\n", getClassName());
1008 if (notify && target) {
1009 target->tryHandle(
this, FXSEL(SEL_INSERTED, message), (
void*)(FXival)index);
1013 if (notify && target) {
1014 target->tryHandle(
this, FXSEL(SEL_CHANGED, message), (
void*)
currentItem);
1051 if ((index < 0) || ((
int)
items.size() <= index)) {
1052 fxerror(
"%s::removeItem: index out of range.\n", getClassName());
1055 if (notify && target) {
1056 target->tryHandle(
this, FXSEL(SEL_DELETED, message), (
void*)(FXival)index);
1059 delete items[index];
1079 if (notify && target) {
1080 target->tryHandle(
this, FXSEL(SEL_INSERTED, message), (
void*)(FXival)index);
1084 if (notify && target) {
1085 target->tryHandle(
this, FXSEL(SEL_CHANGED, message), (
void*)
currentItem);
1102 for (FXint index = (
int)
items.size() - 1; 0 <= index; index--) {
1103 if (notify && target) {
1104 target->tryHandle(
this, FXSEL(SEL_DELETED, message), (
void*)(FXival)index);
1106 delete items[index];
1115 if (notify && target) {
1116 target->tryHandle(
this, FXSEL(SEL_CHANGED, message), (
void*)(FXival) - 1);
1131 for (
int i = 0; i < (int)
items.size(); i++) {
1133 if (
items[i]->show) {
1139 if (!value.empty() && ((
int)
itemFiltered.size() == 0)) {
1169 for (
int i = 0; i < str.count(); i++) {
1170 result.append((
char)::tolower(str[i]));
1177 flags |= FLAG_ENABLED;
1178 font = (FXFont*) - 1L;
1193 w = item->getWidth(
this);
1194 h = item->getHeight(
this);
1201 flags &= ~(FXuint)FLAG_RECALC;
FXDEFMAP(MFXListIcon) MFXListIconMap[]
A list item which allows for custom coloring.
long onDoubleClicked(FXObject *, FXSelector, void *)
FXint listWidth
List width.
FXint getDefaultWidth()
Return default width.
void recalc()
Recalculate layout.
long onKeyRelease(FXObject *, FXSelector, void *)
long onRightBtnPress(FXObject *, FXSelector, void *)
long onCommand(FXObject *, FXSelector, void *)
FXint setItem(FXint index, MFXListIconItem *item, FXbool notify=FALSE)
Replace the item with a [possibly subclassed] item.
long onQueryTip(FXObject *, FXSelector, void *)
void setNumVisible(FXint nvis)
Change the number of visible items.
void makeItemVisible(MFXListIconItem *item)
Scroll to bring item into view.
long onAutoScroll(FXObject *, FXSelector, void *)
FXbool state
State of item.
long onClicked(FXObject *, FXSelector, void *)
FXint getDefaultHeight()
Return default height.
long onTripleClicked(FXObject *, FXSelector, void *)
FXint editItem(FXint index, const FXString &text, FXIcon *icon=NULL, void *ptr=NULL, FXbool notify=FALSE)
Replace items text, icon, and user-data pointer.
int findItem(const FXString &text) const
Search items by name (In all items)
MFXListIconItem * getCursorItem() const
Get item under the cursor, if any.
void updateItem(MFXListIconItem *item) const
Repaint item.
FXint getItemHeight(FXint index) const
Return item height.
FXString tolowerString(const FXString &str) const
tolower string
FXint getContentWidth()
Compute and return content width.
MFXListIconItem * cursor
Cursor item.
FXbool selectItem(MFXListIconItem *item, FXbool notify=FALSE)
Select item by index.
FXbool killSelection(FXbool notify=FALSE)
Deselect all items.
FXint appendItem(MFXListIconItem *item, FXbool notify=FALSE)
Append a [possibly subclassed] item to the list.
FXint getItemWidth(FXint index) const
Return item width.
std::vector< MFXListIconItem * > itemFiltered
Selected item list.
long onUngrabbed(FXObject *, FXSelector, void *)
bool canFocus() const
List widget can receive focus.
MFXListIconItem * createItem(const FXString &text, FXIcon *icon, void *ptr)
create item
void setFocus()
Move the focus to this window.
FXbool isItemCurrent(FXint index) const
Return TRUE if item is current.
void killFocus()
Remove the focus from this window.
long onLeftBtnPress(FXObject *, FXSelector, void *)
FXint hitItem(MFXListIconItem *item, FXint x, FXint y) const
Return item hit code: 0 no hit; 1 hit the icon; 2 hit the text.
long onEnter(FXObject *, FXSelector, void *)
FXint getCurrentItemIndex() const
Return current item, if any.
bool showItem(const FXString &itemName) const
check if filter element
long onLookupTimer(FXObject *, FXSelector, void *)
FXint getContentHeight()
Return content height.
long onLeave(FXObject *, FXSelector, void *)
long onTipTimer(FXObject *, FXSelector, void *)
FXint listHeight
List height.
FXint getAnchorItem() const
Return anchor item, if any.
MFXListIconItem * currentItem
Current item.
void recompute()
recompute list
FXint visible
Number of rows high.
void setHelpText(const FXString &text)
Set the status line help text for this list.
FXString lookup
Lookup string.
FXbool toggleItem(MFXListIconItem *item, FXbool notify=FALSE)
Toggle item selection state.
MFXListIconItem * viewable
Viewable item.
void setAnchorItem(MFXListIconItem *item)
Change anchor item.
void setFilter(const FXString &value, FXLabel *label)
filter items in list
MFXListIconItem * getItem(FXint index) const
Return the item at the given index.
FXbool deselectItem(MFXListIconItem *item, FXbool notify=FALSE)
Deselect item.
MFXListIcon()
FOX need this.
std::vector< MFXListIconItem * > items
Item list.
void detach()
Detach server-side resources.
long onPaint(FXObject *, FXSelector, void *)
long onRightBtnRelease(FXObject *, FXSelector, void *)
void setTextColor(FXColor clr)
Change normal text color.
void layout()
Perform layout.
~MFXListIcon()
Destructor.
long onKeyPress(FXObject *, FXSelector, void *)
void clearItems(FXbool notify=FALSE)
Remove all items from list.
FXbool isItemVisible(MFXListIconItem *item) const
Return TRUE if item is visible.
long onFocusOut(FXObject *, FXSelector, void *)
void removeItem(FXint index, FXbool notify=FALSE)
Remove node from list.
MFXListIconItem * getItemAt(FXint y) const
Return index of item at y, if any.
long onQueryHelp(FXObject *, FXSelector, void *)
void create()
Create server-side resources.
void setCurrentItem(MFXListIconItem *item, FXbool notify=FALSE)
Change current item.
long onLeftBtnRelease(FXObject *, FXSelector, void *)
FXint getViewableItem() const
Return viewable item, if any.
FXint insertItem(FXint index, MFXListIconItem *item, FXbool notify=FALSE)
Insert a new [possibly subclassed] item at the give index.
long onMotion(FXObject *, FXSelector, void *)
long onFocusIn(FXObject *, FXSelector, void *)
FXColor textColor
Text color.
FXbool isEnabled() const
Return true if this item is enabled.
FXint getHeight(const MFXListIcon *list) const
Return height of item as drawn in list.
void setSelected(FXbool selected)
Select item.
const FXString & getText() const
Return item's text label.
FXint hitItem(const MFXListIcon *list, FXint x, FXint y) const
hit item
FXbool isSelected() const
Return true if this item is selected.
void setFocus(FXbool focus)
Make item draw as focused.