## wxOwnerDrawnComboBox

wxOwnerDrawnComboBox is a combobox with owner-drawn list items. In essence, it is a wxComboCtrl with wxVListBox popup and wxControlWithItems interface.

Implementing item drawing and measuring is similar to wxVListBox. Application needs to subclass wxOwnerDrawnComboBox and implement OnDrawItem(), OnMeasureItem() and OnMeasureItemWidth().

Derived from

wxComboCtrl
wxControlWithItems
wxControl
wxWindow
wxEvtHandler
wxObject

Include files

<odcombo.h>

Window styles

wxODCB_DCLICK_CYCLES | Double-clicking cycles item if wxCB_READONLY is also used. Synonymous with wxCC_SPECIAL_DCLICK.
wxODCB_STD_CONTROL_PAINT | Control itself is not custom painted using OnDrawItem. Even if this style is not used, writable wxOwnerDrawnComboBox is never custom painted unless SetCustomPaintWidth is called.

See also wxComboCtrl window styles and base window styles overview.

Event handling

EVT_COMBOBOX(id, func) | Process a wxEVT_COMMAND_COMBOBOX_SELECTED event, when an item on the list is selected. Note that calling GetValue returns the new value of selection.

See also events emitted by wxComboCtrl.

See also

wxComboCtrl, wxComboBox, wxVListBox, wxCommandEvent

Members

wxOwnerDrawnComboBox::wxOwnerDrawnComboBox
wxOwnerDrawnComboBox::~wxOwnerDrawnComboBox
wxOwnerDrawnComboBox::Create
wxOwnerDrawnComboBox::GetWidestItem
wxOwnerDrawnComboBox::GetWidestItemWidth
wxOwnerDrawnComboBox::OnDrawBackground
wxOwnerDrawnComboBox::OnDrawItem
wxOwnerDrawnComboBox::OnMeasureItem
wxOwnerDrawnComboBox::OnMeasureItemWidth

### wxOwnerDrawnComboBox::wxOwnerDrawnComboBox

wxOwnerDrawnComboBox()

Default constructor.

wxOwnerDrawnComboBox(wxWindow* parent, wxWindowID id, const wxString& value = "", const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxDefaultSize, int n = 0, const wxString choices[] = NULL, long style = 0, const wxValidator& validator = wxDefaultValidator, const wxString& name = "comboBox")

wxOwnerDrawnComboBox(wxWindow* parent, wxWindowID id, const wxString& value, const wxPoint& pos, const wxSize& size, const wxArrayString& choices, long style = 0, const wxValidator& validator = wxDefaultValidator, const wxString& name = "comboBox")

Constructor, creating and showing a owner-drawn combobox.

Parameters

parent

Parent window. Must not be NULL.

id

Window identifier. A value of -1 indicates a default value.

value

Initial selection string. An empty string indicates no selection.

pos

Window position.

size

Window size. If the default size (-1, -1) is specified then the window is sized appropriately.

n

Number of strings with which to initialise the control.

choices

An array of strings with which to initialise the control.

style

Window style. See wxOwnerDrawnComboBox.

validator

Window validator.

name

Window name.

See also

wxOwnerDrawnComboBox::Create, wxValidator

### wxOwnerDrawnComboBox::~wxOwnerDrawnComboBox

~wxOwnerDrawnComboBox()

Destructor, destroying the owner-drawn combobox.

### wxOwnerDrawnComboBox::Create

bool Create(wxWindow* parent, wxWindowID id, const wxString& value = "", const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxDefaultSize, int n, const wxString choices[], long style = 0, const wxValidator& validator = wxDefaultValidator, const wxString& name = "comboBox")

bool Create(wxWindow* parent, wxWindowID id, const wxString& value, const wxPoint& pos, const wxSize& size, const wxArrayString& choices, long style = 0, const wxValidator& validator = wxDefaultValidator, const wxString& name = "comboBox")

Creates the combobox for two-step construction. Derived classes should call or replace this function. See wxOwnerDrawnComboBox::wxOwnerDrawnComboBox for further details.

### wxOwnerDrawnComboBox::GetWidestItem

int GetWidestItem() const

Returns index to the widest item in the list.

### wxOwnerDrawnComboBox::GetWidestItemWidth

int GetWidestItemWidth() const

Returns width of the widest item in the list.

### wxOwnerDrawnComboBox::OnDrawBackground

void OnDrawBackground(wxDC& dc, const wxRect& rect, int item, int flags) const

This method is used to draw the items background and, maybe, a border around it.

The base class version implements a reasonable default behaviour which consists in drawing the selected item with the standard background colour and drawing a border around the item if it is either selected or current.

Remarks

flags has the same meaning as with OnDrawItem.

### wxOwnerDrawnComboBox::OnDrawItem

void OnDrawItem(wxDC& dc, const wxRect& rect, int item, int flags) const

The derived class may implement this function to actually draw the item with the given index on the provided DC. If function is not implemented, the item text is simply drawn, as if the control was a normal combobox.

Parameters

dc

The device context to use for drawing

rect

The bounding rectangle for the item being drawn (DC clipping region is set to this rectangle before calling this function)

item

The index of the item to be drawn

flags

Combines any of the following flag values:

`wxODCB_PAINTING_CONTROL` | Combo control is being painted, instead of a list item. Argument item may be wxNOT_FOUND in this case.
`wxODCB_PAINTING_SELECTED` | An item with selection background is being painted. DC text colour should already be correct.

### wxOwnerDrawnComboBox::OnMeasureItem

wxCoord OnMeasureItem(size_t item) const

The derived class may implement this method to return the height of the specified item (in pixels).

The default implementation returns text height, as if this control was a normal combobox.

### wxOwnerDrawnComboBox::OnMeasureItemWidth

wxCoord OnMeasureItemWidth(size_t item) const

The derived class may implement this method to return the width of the specified item (in pixels). If -1 is returned, then the item text width is used.

The default implementation returns -1.