34#define LIST_MASK (SELECT_MASK | LIST_AUTOSELECT)
68FXIMPLEMENT(
MFXListIcon, FXScrollArea, MFXListIconMap, ARRAYNUMBER(MFXListIconMap))
74MFXListIcon::
MFXListIcon(FXComposite* p, FXObject* tgt, FXSelector sel, FXuint opts, FXint x, FXint y, FXint w, FXint h):
75 FXScrollArea(p, opts, x, y, w, h) {
76 flags |= FLAG_ENABLED;
79 font = getApp()->getNormalFont();
80 textColor = getApp()->getForeColor();
81 selbackColor = getApp()->getSelbackColor();
82 seltextColor = getApp()->getSelforeColor();
87 getApp()->removeTimeout(
this, ID_TIPTIMER);
90 font = (FXFont*) - 1L;
96 FXScrollArea::create();
97 for (
const auto& item :
items) {
106 FXScrollArea::detach();
107 for (
const auto& item :
items) {
122 FXScrollArea::setFocus();
129 FXScrollArea::killFocus();
136 return FXScrollArea::getDefaultWidth();
152 FXScrollArea::recalc();
153 flags |= FLAG_RECALC;
172 if (flags & FLAG_RECALC) {
181 if (flags & FLAG_RECALC) {
191 FXScrollArea::layout();
195 horizontal->setLine(
itemFiltered[0]->getWidth(
this) / 10);
203 flags &= ~(FXuint)FLAG_DIRTY;
209 for (
int i = 0; i < (int)
items.size(); i++) {
220 return (0 < (pos_y + item->
y + item->
getHeight(
this))) && ((pos_y + item->
y) < viewport_h);
232 if (flags & FLAG_RECALC) {
237 if (viewport_h <= y + item->y + h) {
238 y = viewport_h - item->
y - h;
240 if (y + item->
y <= 0) {
244 setPosition(pos_x, y);
259 if ((index < 0) || ((
int)
itemFiltered.size() <= index)) {
260 fxerror(
"%s::isItemSelected: index out of range.\n", getClassName());
268 if ((index < 0) || ((
int)
itemFiltered.size() <= index)) {
269 fxerror(
"%s::isItemSelected: index out of range.\n", getClassName());
280 for (
int i = 0; i < (int)
items.size(); i++) {
298 for (
int i = 0; i < (int)
items.size(); i++) {
299 if (
items[i]->getText().text() == text) {
309 FXint ix, iy, hit = 0;
315 hit = item->
hitItem(
this, x - ix, y - iy);
333 if (notify && target) {
334 target->tryHandle(
this, FXSEL(SEL_SELECTED, message),
nullptr);
348 if (notify && target) {
349 target->tryHandle(
this, FXSEL(SEL_DESELECTED, message),
nullptr);
364 if (notify && target) {
365 target->tryHandle(
this, FXSEL(SEL_SELECTED, message),
nullptr);
370 if (notify && target) {
371 target->tryHandle(
this, FXSEL(SEL_DESELECTED, message),
nullptr);
380 FXbool changes = FALSE;
382 for (i = 0; i < (int)
items.size(); i++) {
383 if (
items[i]->isSelected()) {
384 items[i]->setSelected(FALSE);
387 if (notify && target) {
388 target->tryHandle(
this, FXSEL(SEL_DESELECTED, message), (
void*)(FXival)i);
398 FXScrollArea::onEnter(sender, sel, ptr);
399 getApp()->addTimeout(
this, ID_TIPTIMER, getApp()->getMenuPause());
407 FXScrollArea::onLeave(sender, sel, ptr);
408 getApp()->removeTimeout(
this, ID_TIPTIMER);
416 FXScrollArea::onFocusIn(sender, sel, ptr);
434 if (FXWindow::onQueryTip(sender, sel, ptr)) {
437 if (
cursor && (flags & FLAG_TIP) && !(options & LIST_AUTOSELECT)) {
439 sender->handle(
this, FXSEL(SEL_COMMAND, ID_SETSTRINGVALUE), (
void*) &
string);
448 if (FXWindow::onQueryHelp(sender, sel, ptr)) {
451 if ((flags & FLAG_HELP) && !
help.empty()) {
452 sender->handle(
this, FXSEL(SEL_COMMAND, ID_SETSTRINGVALUE), (
void*) &
help);
461 FXScrollArea::onFocusOut(sender, sel, ptr);
472 FXEvent*
event = (FXEvent*)ptr;
473 FXDCWindow dc(
this, event);
479 if (event->rect.y <= (y + h) && y < (
event->rect.y +
event->rect.h)) {
485 if (y < (event->rect.y + event->rect.h)) {
486 dc.setForeground(backColor);
487 dc.fillRectangle(event->rect.x, y, event->rect.w, event->rect.y + event->rect.h - y);
502 FXEvent*
event = (FXEvent*)ptr;
508 if (target && target->tryHandle(
this, FXSEL(SEL_KEYPRESS, message), ptr)) {
511 switch (event->code) {
518 if (flags & FLAG_DODRAG) {
519 handle(
this, FXSEL(SEL_DRAGGED, 0), ptr);
525 setPosition(pos_x, pos_y + verticalScrollBar()->getPage());
528 case KEY_KP_Page_Down:
530 setPosition(pos_x, pos_y - verticalScrollBar()->getPage());
551 if (0 <= index && index < (
int)
items.size()) {
556 if ((0 <= index) && (index < (
int)
itemFiltered.size())) {
561 handle(
this, FXSEL(SEL_CLICKED, 0), (
void*)
currentItem);
563 handle(
this, FXSEL(SEL_COMMAND, 0), (
void*)
currentItem);
573 handle(
this, FXSEL(SEL_CLICKED, 0), (
void*)
currentItem);
575 handle(
this, FXSEL(SEL_COMMAND, 0), (
void*)
currentItem);
581 handle(
this, FXSEL(SEL_DOUBLECLICKED, 0), (
void*)
currentItem);
583 handle(
this, FXSEL(SEL_COMMAND, 0), (
void*)
currentItem);
594 FXEvent*
event = (FXEvent*)ptr;
598 if (target && target->tryHandle(
this, FXSEL(SEL_KEYRELEASE, message), ptr)) {
601 switch (event->code) {
608 if (flags & FLAG_DODRAG) {
609 handle(
this, FXSEL(SEL_DRAGGED, 0), ptr);
625 FXEvent*
event = (FXEvent*)ptr;
633 getApp()->removeTimeout(
this, ID_TIPTIMER);
636 if (flags & FLAG_SCROLLING) {
637 setPosition(event->win_x -
grabx, event->win_y -
graby);
642 if (flags & FLAG_DODRAG) {
643 if (startAutoScroll(event, TRUE)) {
646 handle(
this, FXSEL(SEL_DRAGGED, 0), ptr);
651 if ((flags & FLAG_TRYDRAG) && event->moved) {
652 flags &= ~FLAG_TRYDRAG;
653 if (handle(
this, FXSEL(SEL_BEGINDRAG, 0), ptr)) {
654 flags |= FLAG_DODRAG;
660 if ((flags & FLAG_PRESSED) || (options & LIST_AUTOSELECT)) {
662 if (startAutoScroll(event, FALSE)) {
676 getApp()->addTimeout(
this, ID_TIPTIMER, getApp()->getMenuPause());
682 return (
cursor != oldcursor) || (flg & FLAG_TIP);
688 FXEvent*
event = (FXEvent*)ptr;
691 handle(
this, FXSEL(SEL_FOCUS_SELF, 0), ptr);
694 flags &= ~FLAG_UPDATE;
696 if (target && target->tryHandle(
this, FXSEL(SEL_LEFTBUTTONPRESS, message), ptr)) {
700 if (options & LIST_AUTOSELECT) {
706 if (item ==
nullptr) {
710 code =
hitItem(item, event->win_x, event->win_y);
714 state = item->isSelected();
715 if (item->isEnabled() && !
state) {
719 if (code && item->isSelected() && item->isDraggable()) {
720 flags |= FLAG_TRYDRAG;
722 flags |= FLAG_PRESSED;
731 FXEvent*
event = (FXEvent*)ptr;
736 flags |= FLAG_UPDATE;
737 flags &= ~(FLAG_PRESSED | FLAG_TRYDRAG | FLAG_DODRAG);
739 if (target && target->tryHandle(
this, FXSEL(SEL_LEFTBUTTONRELEASE, message), ptr)) {
743 if (!(flg & FLAG_PRESSED) && !(options & LIST_AUTOSELECT)) {
747 if (flg & FLAG_DODRAG) {
748 handle(
this, FXSEL(SEL_ENDDRAG, 0), ptr);
761 if (event->click_count == 1) {
762 handle(
this, FXSEL(SEL_CLICKED, 0), (
void*)
currentItem);
763 }
else if (event->click_count == 2) {
764 handle(
this, FXSEL(SEL_DOUBLECLICKED, 0), (
void*)
currentItem);
765 }
else if (event->click_count == 3) {
766 handle(
this, FXSEL(SEL_TRIPLECLICKED, 0), (
void*)
currentItem);
770 handle(
this, FXSEL(SEL_COMMAND, 0), (
void*)
currentItem);
780 FXEvent*
event = (FXEvent*)ptr;
782 handle(
this, FXSEL(SEL_FOCUS_SELF, 0), ptr);
785 flags &= ~FLAG_UPDATE;
786 if (target && target->tryHandle(
this, FXSEL(SEL_RIGHTBUTTONPRESS, message), ptr)) {
789 flags |= FLAG_SCROLLING;
790 grabx =
event->win_x - pos_x;
791 graby =
event->win_y - pos_y;
802 flags &= ~FLAG_SCROLLING;
803 flags |= FLAG_UPDATE;
804 if (target && target->tryHandle(
this, FXSEL(SEL_RIGHTBUTTONRELEASE, message), ptr)) {
815 FXScrollArea::onUngrabbed(sender, sel, ptr);
816 flags &= ~(FLAG_DODRAG | FLAG_TRYDRAG | FLAG_PRESSED | FLAG_CHANGED | FLAG_SCROLLING);
817 flags |= FLAG_UPDATE;
825 return target ? target->tryHandle(
this, FXSEL(SEL_COMMAND, message), ptr) : 0;
831 return target ? target->tryHandle(
this, FXSEL(SEL_CLICKED, message), ptr) : 0;
837 return target ? target->tryHandle(
this, FXSEL(SEL_DOUBLECLICKED, message), ptr) : 0;
843 return target ? target->tryHandle(
this, FXSEL(SEL_TRIPLECLICKED, message), ptr) : 0;
862 if (notify && target) {
863 target->tryHandle(
this, FXSEL(SEL_CHANGED, message), (
void*)
currentItem);
871 for (
int i = 0; i < (int)
items.size(); i++) {
884 for (
int i = 0; i < (int)
items.size(); i++) {
905 for (
int i = 0; i < (int)
items.size(); i++) {
906 if (
items[i] == item) {
936 if (index < 0 || (
int)
items.size() <= index) {
937 fxerror(
"%s::getItem: index out of range.\n", getClassName());
947 fxerror(
"%s::setItem: item is NULL.\n", getClassName());
950 if (index < 0 || (
int)
items.size() <= index) {
951 fxerror(
"%s::setItem: index out of range.\n", getClassName());
954 if (notify && target) {
955 target->tryHandle(
this, FXSEL(SEL_REPLACED, message), (
void*)(FXival)index);
980 fxerror(
"%s::insertItem: item is NULL.\n", getClassName());
983 if (index < 0 || (
int)
items.size() < index) {
984 fxerror(
"%s::insertItem: index out of range.\n", getClassName());
1005 if (notify && target) {
1006 target->tryHandle(
this, FXSEL(SEL_INSERTED, message), (
void*)(FXival)index);
1010 if (notify && target) {
1011 target->tryHandle(
this, FXSEL(SEL_CHANGED, message), (
void*)
currentItem);
1048 if ((index < 0) || ((
int)
items.size() <= index)) {
1049 fxerror(
"%s::removeItem: index out of range.\n", getClassName());
1052 if (notify && target) {
1053 target->tryHandle(
this, FXSEL(SEL_DELETED, message), (
void*)(FXival)index);
1056 delete items[index];
1076 if (notify && target) {
1077 target->tryHandle(
this, FXSEL(SEL_INSERTED, message), (
void*)(FXival)index);
1081 if (notify && target) {
1082 target->tryHandle(
this, FXSEL(SEL_CHANGED, message), (
void*)
currentItem);
1099 for (FXint index = (
int)
items.size() - 1; 0 <= index; index--) {
1100 if (notify && target) {
1101 target->tryHandle(
this, FXSEL(SEL_DELETED, message), (
void*)(FXival)index);
1103 delete items[index];
1112 if (notify && target) {
1113 target->tryHandle(
this, FXSEL(SEL_CHANGED, message), (
void*)(FXival) - 1);
1128 for (
int i = 0; i < (int)
items.size(); i++) {
1130 if (
items[i]->show) {
1136 if (!value.empty() && ((
int)
itemFiltered.size() == 0)) {
1166 for (
int i = 0; i < str.count(); i++) {
1167 result.append((
char)::tolower(str[i]));
1174 flags |= FLAG_ENABLED;
1175 font = (FXFont*) - 1L;
1190 w = item->getWidth(
this);
1191 h = item->getHeight(
this);
1198 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.