36 #define SIDE_SPACING 6
37 #define ICON_SPACING 4
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)
40 #define ICON_HEIGHT 20
65 FXIMPLEMENT(
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)) {
125 MFXIconComboBox::MFXIconComboBox(FXComposite* p, FXint cols, 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 flags |= FLAG_ENABLED;
130 myIconLabel =
new FXLabel(
this,
"",
nullptr, 0, 0, 0, 0, 0, pl, pr, pt, pb);
131 myTextFieldIcon =
new MFXTextFieldIcon(
this, cols,
this,
MFXIconComboBox::ID_TEXT, 0, 0, 0, 0, 0, pl, pr, pt, pb);
132 if (options & COMBOBOX_STATIC) {
135 myPane =
new FXPopup(
this, FRAME_LINE);
137 if (options & COMBOBOX_STATIC) {
138 myList->setScrollStyle(SCROLLERS_TRACK | HSCROLLING_OFF);
140 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);
143 flags &= ~FLAG_UPDATE;
204 pw =
myPane->getDefaultWidth();
205 return FXMAX(ww, pw);
214 return FXMAX(th, bh) + (border << 1);
220 FXint buttonWidth, textWidth, itemHeight, iconSize;
221 itemHeight = height - (border << 1);
222 iconSize = itemHeight;
223 buttonWidth =
myButton->getDefaultWidth();
224 textWidth = width - buttonWidth - iconSize - (border << 1);
225 myIconLabel->position(border, border, iconSize, iconSize);
226 myTextFieldIcon->position(border + iconSize, border, textWidth, itemHeight);
227 myButton->position(border + textWidth + iconSize, border, buttonWidth, itemHeight);
229 flags &= ~FLAG_DIRTY;
265 return myList->getNumItems();
271 return myList->getNumVisible();
277 myList->setNumVisible(nvis);
285 return myList->isItemCurrent(index);
291 FXint current =
myList->getCurrentItem();
292 if (current != index) {
293 myList->setCurrentItem(index);
294 myList->makeItemVisible(index);
313 if (notify && target) {
314 target->tryHandle(
this, FXSEL(SEL_COMMAND, message), (
void*)
getText().text());
322 return myList->getCurrentItem();
328 return myList->getItem(index)->getText();
335 fxerror(
"%s::setItem: index out of range.\n", getClassName());
337 myList->setItem(index, text, NULL, ptr);
352 fxerror(
"%s::insertItem: index out of range.\n", getClassName());
354 myList->insertItem(index, text, NULL, ptr);
382 for (
int i = 0; i <
myList->getNumItems(); i++) {
386 if (item && (item->getText() == text) && (item->getIcon() == icon)) {
387 myList->setCurrentItem(i, FALSE);
397 FXint index =
myList->prependItem(text, NULL, ptr);
411 if (newindex < 0 || myList->
getNumItems() <= newindex || oldindex < 0 || myList->
getNumItems() <= oldindex) {
412 fxerror(
"%s::moveItem: index out of range.\n", getClassName());
414 FXint current =
myList->getCurrentItem();
415 myList->moveItem(newindex, oldindex);
416 if (current !=
myList->getCurrentItem()) {
417 current =
myList->getCurrentItem();
433 FXint current =
myList->getCurrentItem();
434 myList->removeItem(index);
435 if (index == current) {
436 current =
myList->getCurrentItem();
459 return myList->findItem(text, start, flgs);
465 return myList->findItemByData(ptr, start, flgs);
471 return myList->getItemText(index);
477 myList->setItemData(index, ptr);
483 return myList->getItemData(index);
496 fxerror(
"%s::setFont: NULL font specified.\n", getClassName());
513 if (opts != options) {
515 if (options & COMBOBOX_STATIC) {
517 myList->setScrollStyle(SCROLLERS_TRACK | HSCROLLING_OFF);
520 myList->setScrollStyle(SCROLLERS_TRACK | HSCROLLER_NEVER);
549 myList->setBackColor(clr);
562 myList->setTextColor(clr);
575 myList->setSelBackColor(clr);
588 myList->setSelTextColor(clr);
606 return myList->getSortFunc();
612 myList->setSortFunc(func);
642 return target && !
isPaneShown() && target->tryHandle(
this, FXSEL(SEL_UPDATE, message), NULL);
654 myButton->handle(
this, FXSEL(SEL_COMMAND, ID_UNPOST), NULL);
655 if (FXSELTYPE(sel) == SEL_COMMAND) {
665 if (!(options & COMBOBOX_STATIC)) {
670 target->tryHandle(
this, FXSEL(SEL_COMMAND, message), (
void*)
getText().text());
679 if (options & COMBOBOX_STATIC) {
681 myButton->handle(
this, FXSEL(SEL_COMMAND, ID_POST), NULL);
690 return target && target->tryHandle(
this, FXSEL(SEL_CHANGED, message), ptr);
696 FXint index =
myList->getCurrentItem();
697 if (!(options & COMBOBOX_STATIC)) {
699 case COMBOBOX_REPLACE:
704 case COMBOBOX_INSERT_BEFORE:
709 case COMBOBOX_INSERT_AFTER:
714 case COMBOBOX_INSERT_FIRST:
717 case COMBOBOX_INSERT_LAST:
726 return target && target->tryHandle(
this, FXSEL(SEL_COMMAND, message), ptr);
742 }
else if (0 < index) {
773 FXEvent*
event = (FXEvent*)ptr;
776 if (event->code < 0) {
782 }
else if (event->code > 0) {
785 }
else if (0 < index) {
#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.
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.
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.
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