38#define COMBOBOX_INS_MASK (COMBOBOX_REPLACE | COMBOBOX_INSERT_BEFORE | COMBOBOX_INSERT_AFTER | COMBOBOX_INSERT_FIRST | COMBOBOX_INSERT_LAST)
39#define COMBOBOX_MASK (COMBOBOX_STATIC | COMBOBOX_INS_MASK)
65FXIMPLEMENT(
MFXIconComboBox, FXPacker, MFXIconComboBoxMap, ARRAYNUMBER(MFXIconComboBoxMap))
70 FXListItem(text, ic, ptr),
71 myBackGroundColor(backGroundColor) {
78 FXFont* font = myList->getFont();
81 ih = icon->getHeight();
84 th = font->getFontHeight();
87 dc.setForeground(myList->getSelBackColor());
91 dc.fillRectangle(xx, yy, ww, hh);
93 dc.drawFocusRectangle(xx + 1, yy + 1, ww - 2, hh - 2);
97 dc.drawIcon(icon, xx, yy + (hh - ih) / 2);
100 if (!label.empty()) {
103 dc.setForeground(makeShadowColor(myList->getBackColor()));
104 }
else if (isSelected()) {
105 dc.setForeground(myList->getSelTextColor());
107 dc.setForeground(myList->getTextColor());
109 dc.drawText(xx, yy + (hh - th) / 2 + font->getFontAscent(), label);
120 FXListItem(
"", nullptr),
121 myBackGroundColor(FXRGB(0, 0, 0)) {
125MFXIconComboBox::MFXIconComboBox(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):
126 FXPacker(p, opts, x, y, w, h, 0, 0, 0, 0, 0, 0),
127 myHaveIcons(haveIcons) {
128 flags |= FLAG_ENABLED;
131 myIconLabel =
new FXLabel(
this,
"",
nullptr, 0, 0, 0, 0, 0, pl, pr, pt, pb);
135 myTextFieldIcon =
new MFXTextFieldIcon(
this, cols,
this,
MFXIconComboBox::ID_TEXT, 0, 0, 0, 0, 0, pl, pr, pt, pb);
136 if (options & COMBOBOX_STATIC) {
139 myPane =
new FXPopup(
this, FRAME_LINE);
141 if (options & COMBOBOX_STATIC) {
142 myList->setScrollStyle(SCROLLERS_TRACK | HSCROLLING_OFF);
144 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);
147 flags &= ~FLAG_UPDATE;
212 pw =
myPane->getDefaultWidth();
213 return FXMAX(ww, pw);
222 return FXMAX(th, bh) + (border << 1);
228 const FXint itemHeight = height - (border << 1);
229 const FXint iconSize =
myHaveIcons ? itemHeight : 0;
230 const FXint buttonWidth =
myButton->getDefaultWidth();
231 const FXint textWidth = width - buttonWidth - iconSize - (border << 1);
232 myIconLabel->position(border, border, iconSize, iconSize);
233 myTextFieldIcon->position(border + iconSize, border, textWidth, itemHeight);
234 myButton->position(border + textWidth + iconSize, border, buttonWidth, itemHeight);
237 for (
int i = 0; i <
myList->getNumItems(); i++) {
238 if (
myList->getItemWidth(i) > size) {
239 size =
myList->getItemWidth(i);
243 flags &= ~FLAG_DIRTY;
279 return myList->getNumItems();
285 return myList->getNumVisible();
297 myList->setNumVisible(nvis);
305 return myList->isItemCurrent(index);
311 FXint current =
myList->getCurrentItem();
312 if (current != index) {
313 myList->setCurrentItem(index);
314 myList->makeItemVisible(index);
333 if (notify && target) {
334 target->tryHandle(
this, FXSEL(SEL_COMMAND, message), (
void*)
getText().text());
342 return myList->getCurrentItem();
348 return myList->getItem(index)->getText();
355 fxerror(
"%s::setItem: index out of range.\n", getClassName());
357 myList->setItem(index, text, NULL, ptr);
372 fxerror(
"%s::insertItem: index out of range.\n", getClassName());
374 myList->insertItem(index, text, NULL, ptr);
402 for (
int i = 0; i <
myList->getNumItems(); i++) {
406 if (item && (item->getText() == text) && (item->getIcon() == icon)) {
428 FXint index =
myList->prependItem(text, NULL, ptr);
442 if (newindex < 0 || myList->
getNumItems() <= newindex || oldindex < 0 || myList->
getNumItems() <= oldindex) {
443 fxerror(
"%s::moveItem: index out of range.\n", getClassName());
445 FXint current =
myList->getCurrentItem();
446 myList->moveItem(newindex, oldindex);
447 if (current !=
myList->getCurrentItem()) {
448 current =
myList->getCurrentItem();
464 FXint current =
myList->getCurrentItem();
465 myList->removeItem(index);
466 if (index == current) {
467 current =
myList->getCurrentItem();
490 return myList->findItem(text, start, flgs);
496 return myList->findItemByData(ptr, start, flgs);
502 return myList->getItemText(index);
508 myList->setItemData(index, ptr);
514 return myList->getItemData(index);
527 fxerror(
"%s::setFont: NULL font specified.\n", getClassName());
543 FXuint opts = (options & ~COMBOBOX_MASK) | (mode &
COMBOBOX_MASK);
544 if (opts != options) {
546 if (options & COMBOBOX_STATIC) {
548 myList->setScrollStyle(SCROLLERS_TRACK | HSCROLLING_OFF);
551 myList->setScrollStyle(SCROLLERS_TRACK | HSCROLLER_NEVER);
580 myList->setBackColor(clr);
593 myList->setTextColor(clr);
606 myList->setSelBackColor(clr);
619 myList->setSelTextColor(clr);
637 return myList->getSortFunc();
643 myList->setSortFunc(func);
673 return target && !
isPaneShown() && target->tryHandle(
this, FXSEL(SEL_UPDATE, message), NULL);
685 myButton->handle(
this, FXSEL(SEL_COMMAND, ID_UNPOST), NULL);
686 if (FXSELTYPE(sel) == SEL_COMMAND) {
696 if (!(options & COMBOBOX_STATIC)) {
701 target->tryHandle(
this, FXSEL(SEL_COMMAND, message), (
void*)
getText().text());
710 if (options & COMBOBOX_STATIC) {
712 myButton->handle(
this, FXSEL(SEL_COMMAND, ID_POST), NULL);
721 return target && target->tryHandle(
this, FXSEL(SEL_CHANGED, message), ptr);
727 FXint index =
myList->getCurrentItem();
728 if (!(options & COMBOBOX_STATIC)) {
730 case COMBOBOX_REPLACE:
735 case COMBOBOX_INSERT_BEFORE:
740 case COMBOBOX_INSERT_AFTER:
745 case COMBOBOX_INSERT_FIRST:
748 case COMBOBOX_INSERT_LAST:
757 return target && target->tryHandle(
this, FXSEL(SEL_COMMAND, message), ptr);
773 }
else if (0 < index) {
804 FXEvent*
event = (FXEvent*)ptr;
807 if (event->code < 0) {
813 }
else if (event->code > 0) {
816 }
else if (0 < index) {
830 myHaveIcons(false) {}
#define COMBOBOX_INS_MASK
FXDEFMAP(MFXIconComboBox) MFXIconComboBoxMap[]
void setSelBackColor(FXColor clr)
Change selected background color.
const FXString & getHelpText() const
Get the combobox help text.
FXColor getSelBackColor() const
Return selected background color.
virtual void create()
Create server-side resources.
const FXString & getTipText() const
Get the tool tip message for this combobox.
FXint findItem(const FXString &text, FXint start=-1, FXuint flags=SEARCH_FORWARD|SEARCH_WRAP) const
virtual ~MFXIconComboBox()
Destructor.
FXString getItem(FXint index) const
Return the item at the given index.
long onTextButton(FXObject *, FXSelector, void *)
long onUpdFmText(FXObject *, FXSelector, void *)
FXint getNumColumns() const
Get the number of columns.
virtual void detach()
Detach server-side resources.
MFXTextFieldIcon * myTextFieldIcon
textField with icon
FXbool isEditable() const
Return true if combobox is editable.
void setHelpText(const FXString &txt)
Set the combobox help text.
void setSelTextColor(FXColor clr)
Change selected text color.
FXString getText() const
Get the text.
long onTextCommand(FXObject *, FXSelector, void *)
void setItemData(FXint index, void *ptr) const
Set data pointer for specified item.
FXint getCurrentItem() const
Get the current item's index.
FXMenuButton * myButton
myButton
FXFont * getFont() const
Get text font.
void removeItem(FXint index)
Remove this item from the list.
long onFocusSelf(FXObject *, FXSelector, void *)
void setSortFunc(FXListSortFunc func)
Change sort function.
void setFont(FXFont *fnt)
Set text font.
virtual void enable()
Enable combo box.
long onMouseWheel(FXObject *, FXSelector, void *)
FXLabel * myIconLabel
label for icon
virtual void layout()
Perform layout.
FXint findItemByData(const void *ptr, FXint start=-1, FXuint flags=SEARCH_FORWARD|SEARCH_WRAP) const
FXbool isItemCurrent(FXint index) const
Return true if current item.
void setJustify(FXuint mode)
Change text justification mode; default is JUSTIFY_LEFT.
FXuint getComboStyle() const
Get the combobox style.
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.
FXint moveItem(FXint newindex, FXint oldindex)
Move item from oldindex to newindex.
FXint setIconItem(FXint index, const FXString &text, FXIcon *icon=nullptr, FXColor bgColor=FXRGB(255, 255, 255), void *ptr=nullptr)
Replace the item at index.
FXColor getSelTextColor() const
Return selected text color.
void setCurrentItem(FXint index, FXbool notify=FALSE)
Set the current item (index is zero-based)
void * getItemData(FXint index) const
Get data pointer for specified item.
void setTextColor(FXColor clr)
Change text color.
void sortItems()
Sort items using current sort function.
long onTextChanged(FXObject *, FXSelector, void *)
MFXIconComboBox()
FOX need this.
FXint prependItem(const FXString &text, void *ptr=NULL)
Prepend an item to the list.
virtual FXint getDefaultWidth()
Return default width.
const bool myHaveIcons
check if this iconComboBox have icons
long onFocusUp(FXObject *, FXSelector, void *)
Commands.
void clearItems()
Remove all items from the list.
void setComboStyle(FXuint mode)
Set the combobox style.
FXbool isPaneShown() const
Is the pane shown.
void setText(FXString text)
Set text.
FXListSortFunc getSortFunc() const
Return sort function.
FXString getItemText(FXint index) const
Get text for specified item.
long onFwdToText(FXObject *, FXSelector, void *)
FXuint getJustify() const
Return text justification mode.
FXint getNumVisible() const
Return the number of visible items.
virtual void destroy()
Destroy server-side resources.
void setEditable(FXbool edit=TRUE)
Set editable state.
FXint getNumItems() const
Return the number of items in the list.
void setNumVisible(FXint nvis)
Set the number of visible items in the drop down list.
virtual FXint getDefaultHeight()
Return default height.
void setCustomText(const FXString text)
set custom text
long onFocusDown(FXObject *, FXSelector, void *)
FXColor getTextColor() const
Return text color.
long onListClicked(FXObject *, FXSelector, void *)
void setNumColumns(FXint cols)
Set the number of columns.
bool setItem(const FXString &text, FXIcon *icon)
set Item
FXint appendIconItem(const FXString &text, FXIcon *icon=nullptr, FXColor bgColor=FXRGB(255, 255, 255), void *ptr=nullptr)
append icon
virtual void disable()
Disable combo box.
FXColor getBackColor() const
Get background color.
void setTipText(const FXString &txt)
Set the tool tip message for this combobox.
virtual void setBackColor(FXColor clr)
Set window background color.
A list item which allows for custom coloring.
void draw(const FXList *list, FXDC &dc, FXint x, FXint y, FXint w, FXint h)
draw MFXListItem
FXColor myBackGroundColor
backGround color
MFXListItem()
fox need this
const FXColor & getBackGroundColor() const
get background color
FXTextFieldIcon (based on FXTextFieldIcon)
void resetTextField()
reset textField