2008-03-08 08:52:38 -05:00
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Name: odcombo.h
|
2008-03-10 11:24:38 -04:00
|
|
|
// Purpose: interface of wxOwnerDrawnComboBox
|
2008-03-08 08:52:38 -05:00
|
|
|
// Author: wxWidgets team
|
2010-07-13 09:29:13 -04:00
|
|
|
// Licence: wxWindows licence
|
2008-03-08 08:52:38 -05:00
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2008-04-06 11:35:21 -04:00
|
|
|
|
|
|
|
enum wxOwnerDrawnComboBoxPaintingFlags
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
Combo control is being painted, instead of a list item.
|
|
|
|
Argument item may be @c wxNOT_FOUND in this case.
|
|
|
|
*/
|
|
|
|
wxODCB_PAINTING_CONTROL = 0x0001,
|
|
|
|
|
|
|
|
/**
|
|
|
|
An item with selection background is being painted.
|
|
|
|
DC text colour should already be correct.
|
|
|
|
*/
|
|
|
|
wxODCB_PAINTING_SELECTED = 0x0002
|
|
|
|
};
|
|
|
|
|
2012-06-05 17:26:48 -04:00
|
|
|
|
|
|
|
/**
|
|
|
|
New window styles for wxOwnerDrawnComboBox
|
|
|
|
*/
|
|
|
|
enum
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
Double-clicking cycles item if wxCB_READONLY is also used.
|
|
|
|
*/
|
|
|
|
wxODCB_DCLICK_CYCLES = wxCC_SPECIAL_DCLICK,
|
|
|
|
|
|
|
|
/**
|
|
|
|
If used, control itself is not custom paint using callback.
|
|
|
|
Even if this is not used, writable combo is never custom paint
|
|
|
|
until SetCustomPaintWidth is called
|
|
|
|
*/
|
|
|
|
wxODCB_STD_CONTROL_PAINT = 0x1000
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
2008-03-08 08:52:38 -05:00
|
|
|
/**
|
|
|
|
@class wxOwnerDrawnComboBox
|
2008-03-08 09:43:31 -05:00
|
|
|
|
2008-03-08 08:52:38 -05:00
|
|
|
wxOwnerDrawnComboBox is a combobox with owner-drawn list items.
|
2008-04-06 08:52:58 -04:00
|
|
|
In essence, it is a wxComboCtrl with wxVListBox popup and wxControlWithItems
|
2008-03-08 08:52:38 -05:00
|
|
|
interface.
|
2008-03-08 09:43:31 -05:00
|
|
|
|
2008-03-08 08:52:38 -05:00
|
|
|
Implementing item drawing and measuring is similar to wxVListBox.
|
|
|
|
Application needs to subclass wxOwnerDrawnComboBox and implement
|
2008-04-06 08:52:58 -04:00
|
|
|
OnDrawItem(), OnMeasureItem() and OnMeasureItemWidth().
|
2008-03-08 09:43:31 -05:00
|
|
|
|
2008-03-08 08:52:38 -05:00
|
|
|
@beginStyleTable
|
2008-04-06 10:43:04 -04:00
|
|
|
@style{wxODCB_DCLICK_CYCLES}
|
2008-03-08 08:52:38 -05:00
|
|
|
Double-clicking cycles item if wxCB_READONLY is also used.
|
|
|
|
Synonymous with wxCC_SPECIAL_DCLICK.
|
2008-04-06 10:43:04 -04:00
|
|
|
@style{wxODCB_STD_CONTROL_PAINT}
|
2008-03-08 08:52:38 -05:00
|
|
|
Control itself is not custom painted using OnDrawItem. Even if this
|
|
|
|
style is not used, writable wxOwnerDrawnComboBox is never custom
|
2008-04-06 08:52:58 -04:00
|
|
|
painted unless SetCustomPaintWidth() is called.
|
2008-03-08 08:52:38 -05:00
|
|
|
@endStyleTable
|
2008-03-08 09:43:31 -05:00
|
|
|
|
2008-04-06 11:35:21 -04:00
|
|
|
@see wxComboCtrl window styles and @ref overview_windowstyles.
|
|
|
|
|
2009-02-18 12:58:51 -05:00
|
|
|
@beginEventEmissionTable{wxCommandEvent}
|
2008-04-06 10:43:04 -04:00
|
|
|
@event{EVT_COMBOBOX(id, func)}
|
2013-04-25 06:11:03 -04:00
|
|
|
Process a wxEVT_COMBOBOX event, when an item on
|
2008-04-06 08:52:58 -04:00
|
|
|
the list is selected. Note that calling GetValue() returns the new
|
2008-03-08 08:52:38 -05:00
|
|
|
value of selection.
|
|
|
|
@endEventTable
|
2008-03-08 09:43:31 -05:00
|
|
|
|
2008-04-06 08:52:58 -04:00
|
|
|
@see Events emitted by wxComboCtrl.
|
|
|
|
|
2008-03-08 08:52:38 -05:00
|
|
|
@library{wxadv}
|
|
|
|
@category{ctrl}
|
2012-11-03 14:32:50 -04:00
|
|
|
@appearance{ownerdrawncombobox}
|
2008-03-08 09:43:31 -05:00
|
|
|
|
2008-03-10 11:24:38 -04:00
|
|
|
@see wxComboCtrl, wxComboBox, wxVListBox, wxCommandEvent
|
2008-03-08 08:52:38 -05:00
|
|
|
*/
|
2012-06-05 22:06:24 -04:00
|
|
|
class wxOwnerDrawnComboBox : public wxComboCtrl, public wxItemContainer
|
2008-03-08 08:52:38 -05:00
|
|
|
{
|
|
|
|
public:
|
2008-04-06 08:52:58 -04:00
|
|
|
/**
|
|
|
|
Default constructor.
|
|
|
|
*/
|
|
|
|
wxOwnerDrawnComboBox();
|
2008-04-06 10:43:04 -04:00
|
|
|
|
2008-03-08 08:52:38 -05:00
|
|
|
/**
|
|
|
|
Constructor, creating and showing a owner-drawn combobox.
|
2008-03-20 09:45:17 -04:00
|
|
|
|
2008-03-08 09:43:31 -05:00
|
|
|
@param parent
|
2008-03-09 08:33:59 -04:00
|
|
|
Parent window. Must not be @NULL.
|
2008-03-08 09:43:31 -05:00
|
|
|
@param id
|
2008-04-06 08:52:58 -04:00
|
|
|
Window identifier. The value @c wxID_ANY indicates a default value.
|
2008-03-08 09:43:31 -05:00
|
|
|
@param value
|
2008-03-09 08:33:59 -04:00
|
|
|
Initial selection string. An empty string indicates no selection.
|
2008-03-08 09:43:31 -05:00
|
|
|
@param pos
|
2008-03-09 08:33:59 -04:00
|
|
|
Window position.
|
2008-03-08 09:43:31 -05:00
|
|
|
@param size
|
2008-04-06 11:35:21 -04:00
|
|
|
Window size.
|
|
|
|
If ::wxDefaultSize is specified then the window is sized appropriately.
|
2008-03-08 09:43:31 -05:00
|
|
|
@param n
|
2008-03-09 08:33:59 -04:00
|
|
|
Number of strings with which to initialise the control.
|
2008-03-08 09:43:31 -05:00
|
|
|
@param choices
|
2008-03-09 08:33:59 -04:00
|
|
|
An array of strings with which to initialise the control.
|
2008-03-08 09:43:31 -05:00
|
|
|
@param style
|
2008-03-09 08:33:59 -04:00
|
|
|
Window style. See wxOwnerDrawnComboBox.
|
2008-03-08 09:43:31 -05:00
|
|
|
@param validator
|
2008-03-09 08:33:59 -04:00
|
|
|
Window validator.
|
2008-03-08 09:43:31 -05:00
|
|
|
@param name
|
2008-03-09 08:33:59 -04:00
|
|
|
Window name.
|
2008-03-20 09:45:17 -04:00
|
|
|
|
2008-03-09 08:33:59 -04:00
|
|
|
@see Create(), wxValidator
|
2008-03-08 08:52:38 -05:00
|
|
|
*/
|
2008-03-08 09:43:31 -05:00
|
|
|
wxOwnerDrawnComboBox(wxWindow* parent, wxWindowID id,
|
2009-01-10 13:31:45 -05:00
|
|
|
const wxString& value = wxEmptyString,
|
2008-03-08 09:43:31 -05:00
|
|
|
const wxPoint& pos = wxDefaultPosition,
|
|
|
|
const wxSize& size = wxDefaultSize,
|
|
|
|
int n = 0,
|
2012-02-15 10:40:07 -05:00
|
|
|
const wxString choices[] = NULL,
|
2008-03-08 09:43:31 -05:00
|
|
|
long style = 0,
|
|
|
|
const wxValidator& validator = wxDefaultValidator,
|
|
|
|
const wxString& name = "comboBox");
|
2008-08-30 08:44:43 -04:00
|
|
|
/**
|
|
|
|
Constructor, creating and showing a owner-drawn combobox.
|
|
|
|
|
|
|
|
@param parent
|
|
|
|
Parent window. Must not be @NULL.
|
|
|
|
@param id
|
|
|
|
Window identifier. The value @c wxID_ANY indicates a default value.
|
|
|
|
@param value
|
|
|
|
Initial selection string. An empty string indicates no selection.
|
|
|
|
@param pos
|
|
|
|
Window position.
|
|
|
|
@param size
|
|
|
|
Window size.
|
|
|
|
If ::wxDefaultSize is specified then the window is sized appropriately.
|
|
|
|
@param choices
|
|
|
|
An array of strings with which to initialise the control.
|
|
|
|
@param style
|
|
|
|
Window style. See wxOwnerDrawnComboBox.
|
|
|
|
@param validator
|
|
|
|
Window validator.
|
|
|
|
@param name
|
|
|
|
Window name.
|
|
|
|
|
|
|
|
@see Create(), wxValidator
|
|
|
|
*/
|
2008-03-08 09:43:31 -05:00
|
|
|
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");
|
2008-03-08 08:52:38 -05:00
|
|
|
|
|
|
|
/**
|
|
|
|
Destructor, destroying the owner-drawn combobox.
|
|
|
|
*/
|
2008-09-27 07:21:10 -04:00
|
|
|
virtual ~wxOwnerDrawnComboBox();
|
2008-03-08 08:52:38 -05:00
|
|
|
|
|
|
|
//@{
|
|
|
|
/**
|
2008-04-06 08:52:58 -04:00
|
|
|
Creates the combobox for two-step construction.
|
|
|
|
See wxOwnerDrawnComboBox() for further details.
|
|
|
|
|
|
|
|
@remarks Derived classes should call or replace this function.
|
2008-03-08 08:52:38 -05:00
|
|
|
*/
|
2009-01-10 17:10:54 -05:00
|
|
|
bool Create(wxWindow *parent,
|
|
|
|
wxWindowID id,
|
2009-01-10 13:31:45 -05:00
|
|
|
const wxString& value = wxEmptyString,
|
2008-03-08 08:52:38 -05:00
|
|
|
const wxPoint& pos = wxDefaultPosition,
|
|
|
|
const wxSize& size = wxDefaultSize,
|
|
|
|
long style = 0,
|
|
|
|
const wxValidator& validator = wxDefaultValidator,
|
2009-01-10 17:10:54 -05:00
|
|
|
const wxString& name = wxComboBoxNameStr);
|
|
|
|
bool Create(wxWindow *parent,
|
|
|
|
wxWindowID id,
|
|
|
|
const wxString& value,
|
|
|
|
const wxPoint& pos,
|
|
|
|
const wxSize& size,
|
|
|
|
int n,
|
|
|
|
const wxString choices[],
|
|
|
|
long style = 0,
|
|
|
|
const wxValidator& validator = wxDefaultValidator,
|
|
|
|
const wxString& name = wxComboBoxNameStr);
|
|
|
|
bool Create(wxWindow *parent,
|
|
|
|
wxWindowID id,
|
2008-03-08 09:43:31 -05:00
|
|
|
const wxString& value,
|
|
|
|
const wxPoint& pos,
|
|
|
|
const wxSize& size,
|
|
|
|
const wxArrayString& choices,
|
|
|
|
long style = 0,
|
|
|
|
const wxValidator& validator = wxDefaultValidator,
|
2009-01-10 17:10:54 -05:00
|
|
|
const wxString& name = wxComboBoxNameStr);
|
2008-03-08 08:52:38 -05:00
|
|
|
//@}
|
|
|
|
|
2014-10-13 08:08:10 -04:00
|
|
|
/**
|
|
|
|
IsEmpty() is not available in this class.
|
|
|
|
|
|
|
|
This method is documented here only to notice that it can't be used
|
|
|
|
with this class because of the ambiguity between the methods with the
|
|
|
|
same name inherited from wxItemContainer and wxTextEntry base classes.
|
|
|
|
|
|
|
|
Because of this, any attempt to call it results in a compilation error
|
|
|
|
and you should use either IsListEmpty() or IsTextEmpty() depending on
|
|
|
|
what exactly do you want to test.
|
|
|
|
*/
|
|
|
|
bool IsEmpty() const;
|
|
|
|
|
|
|
|
/**
|
|
|
|
Returns true if the list of combobox choices is empty.
|
|
|
|
|
|
|
|
Use this method instead of (not available in this class) IsEmpty() to
|
|
|
|
test if the list of items is empty.
|
|
|
|
|
|
|
|
@since 3.1.0
|
|
|
|
*/
|
|
|
|
bool IsListEmpty() const;
|
|
|
|
|
|
|
|
/**
|
|
|
|
Returns true if the text of the combobox is empty.
|
|
|
|
|
|
|
|
Use this method instead of (not available in this class) IsEmpty() to
|
|
|
|
test if the text currently entered into the combobox is empty.
|
|
|
|
|
|
|
|
@since 3.1.0
|
|
|
|
*/
|
|
|
|
bool IsTextEmpty() const;
|
|
|
|
|
2008-03-08 08:52:38 -05:00
|
|
|
/**
|
|
|
|
Returns index to the widest item in the list.
|
|
|
|
*/
|
2008-09-27 07:21:10 -04:00
|
|
|
virtual int GetWidestItem();
|
2008-03-08 08:52:38 -05:00
|
|
|
|
|
|
|
/**
|
|
|
|
Returns width of the widest item in the list.
|
|
|
|
*/
|
2008-09-27 07:21:10 -04:00
|
|
|
virtual int GetWidestItemWidth();
|
2008-03-08 08:52:38 -05:00
|
|
|
|
2008-10-29 14:55:57 -04:00
|
|
|
protected:
|
|
|
|
|
2008-03-08 08:52:38 -05:00
|
|
|
/**
|
|
|
|
This method is used to draw the items background and, maybe, a border around it.
|
2008-04-06 08:52:58 -04:00
|
|
|
|
2008-03-08 08:52:38 -05:00
|
|
|
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.
|
2008-03-20 09:45:17 -04:00
|
|
|
|
2008-04-06 08:52:58 -04:00
|
|
|
@remarks flags has the same meaning as with OnDrawItem().
|
2008-03-08 08:52:38 -05:00
|
|
|
*/
|
2008-10-27 17:26:54 -04:00
|
|
|
virtual void OnDrawBackground(wxDC& dc, const wxRect& rect, int item,
|
|
|
|
int flags) const;
|
2008-03-08 08:52:38 -05:00
|
|
|
|
|
|
|
/**
|
|
|
|
The derived class may implement this function to actually draw the item
|
2008-04-06 08:52:58 -04:00
|
|
|
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.
|
2008-03-20 09:45:17 -04:00
|
|
|
|
2008-03-08 09:43:31 -05:00
|
|
|
@param dc
|
2008-03-09 08:33:59 -04:00
|
|
|
The device context to use for drawing
|
2008-03-08 09:43:31 -05:00
|
|
|
@param rect
|
2008-03-09 08:33:59 -04:00
|
|
|
The bounding rectangle for the item being drawn (DC clipping
|
|
|
|
region is set to this rectangle before calling this function)
|
2008-03-08 09:43:31 -05:00
|
|
|
@param item
|
2008-03-09 08:33:59 -04:00
|
|
|
The index of the item to be drawn
|
2008-03-08 09:43:31 -05:00
|
|
|
@param flags
|
2008-04-06 11:35:21 -04:00
|
|
|
A combination of the ::wxOwnerDrawnComboBoxPaintingFlags enumeration values.
|
2008-03-08 08:52:38 -05:00
|
|
|
*/
|
2008-10-27 17:26:54 -04:00
|
|
|
virtual void OnDrawItem(wxDC& dc, const wxRect& rect, int item,
|
|
|
|
int flags) const;
|
2008-03-08 08:52:38 -05:00
|
|
|
|
|
|
|
/**
|
|
|
|
The derived class may implement this method to return the height of the
|
|
|
|
specified item (in pixels).
|
2008-04-06 08:52:58 -04:00
|
|
|
|
2008-03-08 08:52:38 -05:00
|
|
|
The default implementation returns text height, as if this control was
|
|
|
|
a normal combobox.
|
|
|
|
*/
|
2008-10-13 07:09:56 -04:00
|
|
|
virtual wxCoord OnMeasureItem(size_t item) const;
|
2008-03-08 08:52:38 -05:00
|
|
|
|
|
|
|
/**
|
|
|
|
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.
|
2008-04-06 08:52:58 -04:00
|
|
|
|
2008-03-08 08:52:38 -05:00
|
|
|
The default implementation returns -1.
|
|
|
|
*/
|
2008-10-13 07:09:56 -04:00
|
|
|
virtual wxCoord OnMeasureItemWidth(size_t item) const;
|
2008-03-08 08:52:38 -05:00
|
|
|
};
|
2008-03-10 11:24:38 -04:00
|
|
|
|