31#define COMBOBOX_INS_MASK (COMBOBOX_REPLACE | COMBOBOX_INSERT_BEFORE | COMBOBOX_INSERT_AFTER | COMBOBOX_INSERT_FIRST | COMBOBOX_INSERT_LAST)
32#define COMBOBOX_MASK (COMBOBOX_STATIC | COMBOBOX_INS_MASK)
59FXIMPLEMENT(
MFXComboBoxIcon, FXPacker, MFXComboBoxIconMap, ARRAYNUMBER(MFXComboBoxIconMap))
65MFXComboBoxIcon::
MFXComboBoxIcon(FXComposite* p, FXint cols, const
bool haveIcons, FXObject* tgt, FXSelector sel, FXuint opts, FXint x, FXint y, FXint w, FXint h, FXint pl, FXint pr, FXint pt, FXint pb):
66 FXPacker(p, opts, x, y, w, h, 0, 0, 0, 0, 0, 0),
67 myHaveIcons(haveIcons) {
68 flags |= FLAG_ENABLED;
71 myIconLabel =
new FXLabel(
this,
"",
nullptr, 0, 0, 0, 0, 0, pl, pr, pt, pb);
75 myTextFieldIcon =
new MFXTextFieldIcon(
this, cols,
this,
MFXComboBoxIcon::ID_TEXT, 0, 0, 0, 0, 0, pl, pr, pt, pb);
76 if (options & COMBOBOX_STATIC) {
77 myTextFieldIcon->setEditable(FALSE);
79 myPane =
new FXPopup(
this, FRAME_LINE);
81 if (options & COMBOBOX_STATIC) {
82 myList->setScrollStyle(SCROLLERS_TRACK | HSCROLLING_OFF);
84 myButton =
new FXMenuButton(
this, FXString::null, NULL, myPane, FRAME_RAISED | FRAME_THICK | MENUBUTTON_DOWN | MENUBUTTON_ATTACH_RIGHT, 0, 0, 0, 0, 0, 0, 0, 0);
85 myButton->setXOffset(border);
86 myButton->setYOffset(border);
87 flags &= ~FLAG_UPDATE;
152 pw =
myPane->getDefaultWidth();
153 return FXMAX(ww, pw);
162 return FXMAX(th, bh) + (border << 1);
168 const FXint itemHeight = height - (border << 1);
169 const FXint iconSize =
myHaveIcons ? itemHeight : 0;
170 const FXint buttonWidth =
myButton->getDefaultWidth();
171 const FXint textWidth = width - buttonWidth - iconSize - (border << 1);
172 myIconLabel->position(border, border, iconSize, iconSize);
173 myTextFieldIcon->position(border + iconSize, border, textWidth, itemHeight);
174 myButton->position(border + textWidth + iconSize, border, buttonWidth, itemHeight);
177 for (
int i = 0; i <
myList->getNumItems(); i++) {
178 if (
myList->getItemWidth(i) > size) {
179 size =
myList->getItemWidth(i);
183 flags &= ~FLAG_DIRTY;
219 return myList->getNumItems();
225 return myList->getNumVisible();
237 myList->setNumVisible(nvis);
243 return myList->isItemCurrent(index);
249 FXint current =
myList->getCurrentItem();
250 if (current != index) {
251 myList->setCurrentItem(index);
252 myList->makeItemVisible(index);
271 if (notify && target) {
272 target->tryHandle(
this, FXSEL(SEL_COMMAND, message), (
void*)
getText().text());
280 return myList->getCurrentItem();
286 return myList->getItem(index)->getText();
293 fxerror(
"%s::setItem: index out of range.\n", getClassName());
295 myList->setItem(index, text, NULL, ptr);
310 fxerror(
"%s::insertItem: index out of range.\n", getClassName());
312 myList->insertItem(index, text, NULL, ptr);
340 for (
int i = 0; i <
myList->getNumItems(); i++) {
344 if (item && (item->getText() == text) && (item->getIcon() == icon)) {
366 FXint index =
myList->prependItem(text, NULL, ptr);
380 if (newindex < 0 || myList->
getNumItems() <= newindex || oldindex < 0 || myList->
getNumItems() <= oldindex) {
381 fxerror(
"%s::moveItem: index out of range.\n", getClassName());
383 FXint current =
myList->getCurrentItem();
384 myList->moveItem(newindex, oldindex);
385 if (current !=
myList->getCurrentItem()) {
386 current =
myList->getCurrentItem();
402 FXint current =
myList->getCurrentItem();
403 myList->removeItem(index);
404 if (index == current) {
405 current =
myList->getCurrentItem();
428 return myList->findItem(text, start, flgs);
434 return myList->findItemByData(ptr, start, flgs);
440 return myList->getItemText(index);
446 myList->setItemData(index, ptr);
452 return myList->getItemData(index);
465 fxerror(
"%s::setFont: NULL font specified.\n", getClassName());
481 FXuint opts = (options & ~COMBOBOX_MASK) | (mode &
COMBOBOX_MASK);
482 if (opts != options) {
484 if (options & COMBOBOX_STATIC) {
486 myList->setScrollStyle(SCROLLERS_TRACK | HSCROLLING_OFF);
489 myList->setScrollStyle(SCROLLERS_TRACK | HSCROLLER_NEVER);
518 myList->setBackColor(clr);
531 myList->setTextColor(clr);
544 myList->setSelBackColor(clr);
557 myList->setSelTextColor(clr);
575 return myList->getSortFunc();
581 myList->setSortFunc(func);
611 return target && !
isPaneShown() && target->tryHandle(
this, FXSEL(SEL_UPDATE, message), NULL);
623 myButton->handle(
this, FXSEL(SEL_COMMAND, ID_UNPOST), NULL);
624 if (FXSELTYPE(sel) == SEL_COMMAND) {
634 if (!(options & COMBOBOX_STATIC)) {
639 target->tryHandle(
this, FXSEL(SEL_COMMAND, message), (
void*)
getText().text());
648 if (options & COMBOBOX_STATIC) {
650 myButton->handle(
this, FXSEL(SEL_COMMAND, ID_POST), NULL);
659 return target && target->tryHandle(
this, FXSEL(SEL_CHANGED, message), ptr);
665 FXint index =
myList->getCurrentItem();
666 if (!(options & COMBOBOX_STATIC)) {
668 case COMBOBOX_REPLACE:
673 case COMBOBOX_INSERT_BEFORE:
678 case COMBOBOX_INSERT_AFTER:
683 case COMBOBOX_INSERT_FIRST:
686 case COMBOBOX_INSERT_LAST:
695 return target && target->tryHandle(
this, FXSEL(SEL_COMMAND, message), ptr);
711 }
else if (0 < index) {
742 FXEvent*
event = (FXEvent*)ptr;
745 if (event->code < 0) {
751 }
else if (event->code > 0) {
754 }
else if (0 < index) {
768 myHaveIcons(false) {}
#define COMBOBOX_INS_MASK
FXDEFMAP(MFXComboBoxIcon) MFXComboBoxIconMap[]
FXbool isItemCurrent(FXint index) const
Return true if current item.
FXint findItemByData(const void *ptr, FXint start=-1, FXuint flags=SEARCH_FORWARD|SEARCH_WRAP) const
void setSelTextColor(FXColor clr)
Change selected text color.
FXint insertIconItem(FXint index, const FXString &text, FXIcon *icon=nullptr, FXColor bgColor=FXRGB(255, 255, 255), void *ptr=nullptr)
Insert a new item at index.
virtual void layout()
Perform layout.
FXuint getJustify() const
Return text justification mode.
FXint getCurrentItem() const
Get the current item's index.
void setItemData(FXint index, void *ptr) const
Set data pointer for specified item.
virtual void destroy()
Destroy server-side resources.
FXint getNumVisible() const
Return the number of visible items.
FXuint getComboStyle() const
Get the combobox style.
FXint findItem(const FXString &text, FXint start=-1, FXuint flags=SEARCH_FORWARD|SEARCH_WRAP) const
long onTextChanged(FXObject *, FXSelector, void *)
const FXString & getHelpText() const
Get the combobox help text.
void removeItem(FXint index)
Remove this item from the list.
long onFwdToText(FXObject *, FXSelector, void *)
void setCurrentItem(FXint index, FXbool notify=FALSE)
Set the current item (index is zero-based)
FXint getNumItems() const
Return the number of items in the list.
const FXString & getTipText() const
Get the tool tip message for this combobox.
long onMouseWheel(FXObject *, FXSelector, void *)
virtual FXint getDefaultWidth()
Return default width.
FXbool isEditable() const
Return true if combobox is editable.
FXString getItemText(FXint index) const
Get text for specified item.
void * getItemData(FXint index) const
Get data pointer for specified item.
virtual void setBackColor(FXColor clr)
Set window background color.
long onListClicked(FXObject *, FXSelector, void *)
FXFont * getFont() const
Get text font.
void setHelpText(const FXString &txt)
Set the combobox help text.
FXLabel * myIconLabel
label for icon
FXMenuButton * myButton
myButton
FXString getText() const
Get the text.
void setText(FXString text)
Set text.
FXColor getSelBackColor() const
Return selected background color.
void setNumColumns(FXint cols)
Set the number of columns.
void setTextColor(FXColor clr)
Change text color.
FXColor getSelTextColor() const
Return selected text color.
void setNumVisible(FXint nvis)
Set the number of visible items in the drop down list.
virtual ~MFXComboBoxIcon()
Destructor.
void clearItems()
Remove all items from the list.
void setSortFunc(FXListSortFunc func)
Change sort function.
virtual FXint getDefaultHeight()
Return default height.
FXString getItem(FXint index) const
Return the item at the given index.
long onTextButton(FXObject *, FXSelector, void *)
FXint prependItem(const FXString &text, void *ptr=NULL)
Prepend an item to the list.
void setTipText(const FXString &txt)
Set the tool tip message for this combobox.
void sortItems()
Sort items using current sort function.
FXbool isPaneShown() const
Is the pane shown.
FXint moveItem(FXint newindex, FXint oldindex)
Move item from oldindex to newindex.
virtual void disable()
Disable combo box.
FXColor getBackColor() const
Get background color.
void setSelBackColor(FXColor clr)
Change selected background color.
void setJustify(FXuint mode)
Change text justification mode; default is JUSTIFY_LEFT.
const bool myHaveIcons
check if this iconComboBox have icons
MFXComboBoxIcon()
FOX need this.
FXColor getTextColor() const
Return text color.
long onUpdFmText(FXObject *, FXSelector, void *)
FXint getNumColumns() const
Get the number of columns.
FXListSortFunc getSortFunc() const
Return sort function.
FXint appendIconItem(const FXString &text, FXIcon *icon=nullptr, FXColor bgColor=FXRGB(255, 255, 255), void *ptr=nullptr)
append icon
bool setItem(const FXString &text, FXIcon *icon)
set Item
virtual void enable()
Enable combo box.
MFXTextFieldIcon * myTextFieldIcon
textField with icon
void setComboStyle(FXuint mode)
Set the combobox style.
FXint setIconItem(FXint index, const FXString &text, FXIcon *icon=nullptr, FXColor bgColor=FXRGB(255, 255, 255), void *ptr=nullptr)
Replace the item at index.
long onTextCommand(FXObject *, FXSelector, void *)
void setEditable(FXbool edit=TRUE)
Set editable state.
void setFont(FXFont *fnt)
Set text font.
virtual void detach()
Detach server-side resources.
virtual void create()
Create server-side resources.
long onFocusDown(FXObject *, FXSelector, void *)
long onFocusSelf(FXObject *, FXSelector, void *)
void setCustomText(const FXString text)
set custom text
long onFocusUp(FXObject *, FXSelector, void *)
Commands.
A list item which allows for custom coloring.
A list item which allows for custom coloring.
const FXColor & getBackGroundColor() const
get background color
FXTextFieldIcon (based on FXTextFieldIcon)
void resetTextField()
reset textField
void setIcon(FXIcon *icon)
set icon