2008-03-08 13:52:38 +00:00
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Name: odcombo.h
|
2008-03-10 15:24:38 +00:00
|
|
|
// Purpose: interface of wxOwnerDrawnComboBox
|
2008-03-08 13:52:38 +00:00
|
|
|
// Author: wxWidgets team
|
|
|
|
// RCS-ID: $Id$
|
2010-07-13 13:29:13 +00:00
|
|
|
// Licence: wxWindows licence
|
2008-03-08 13:52:38 +00:00
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2008-04-06 15:35:21 +00: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
|
|
|
|
};
|
|
|
|
|
2008-03-08 13:52:38 +00:00
|
|
|
/**
|
|
|
|
@class wxOwnerDrawnComboBox
|
2008-03-08 14:43:31 +00:00
|
|
|
|
2008-03-08 13:52:38 +00:00
|
|
|
wxOwnerDrawnComboBox is a combobox with owner-drawn list items.
|
2008-04-06 12:52:58 +00:00
|
|
|
In essence, it is a wxComboCtrl with wxVListBox popup and wxControlWithItems
|
2008-03-08 13:52:38 +00:00
|
|
|
interface.
|
2008-03-08 14:43:31 +00:00
|
|
|
|
2008-03-08 13:52:38 +00:00
|
|
|
Implementing item drawing and measuring is similar to wxVListBox.
|
|
|
|
Application needs to subclass wxOwnerDrawnComboBox and implement
|
2008-04-06 12:52:58 +00:00
|
|
|
OnDrawItem(), OnMeasureItem() and OnMeasureItemWidth().
|
2008-03-08 14:43:31 +00:00
|
|
|
|
2008-03-08 13:52:38 +00:00
|
|
|
@beginStyleTable
|
2008-04-06 14:43:04 +00:00
|
|
|
@style{wxODCB_DCLICK_CYCLES}
|
2008-03-08 13:52:38 +00:00
|
|
|
Double-clicking cycles item if wxCB_READONLY is also used.
|
|
|
|
Synonymous with wxCC_SPECIAL_DCLICK.
|
2008-04-06 14:43:04 +00:00
|
|
|
@style{wxODCB_STD_CONTROL_PAINT}
|
2008-03-08 13:52:38 +00:00
|
|
|
Control itself is not custom painted using OnDrawItem. Even if this
|
|
|
|
style is not used, writable wxOwnerDrawnComboBox is never custom
|
2008-04-06 12:52:58 +00:00
|
|
|
painted unless SetCustomPaintWidth() is called.
|
2008-03-08 13:52:38 +00:00
|
|
|
@endStyleTable
|
2008-03-08 14:43:31 +00:00
|
|
|
|
2008-04-06 15:35:21 +00:00
|
|
|
@see wxComboCtrl window styles and @ref overview_windowstyles.
|
|
|
|
|
2009-02-18 17:58:51 +00:00
|
|
|
@beginEventEmissionTable{wxCommandEvent}
|
2008-04-06 14:43:04 +00:00
|
|
|
@event{EVT_COMBOBOX(id, func)}
|
2008-03-08 13:52:38 +00:00
|
|
|
Process a wxEVT_COMMAND_COMBOBOX_SELECTED event, when an item on
|
2008-04-06 12:52:58 +00:00
|
|
|
the list is selected. Note that calling GetValue() returns the new
|
2008-03-08 13:52:38 +00:00
|
|
|
value of selection.
|
|
|
|
@endEventTable
|
2008-03-08 14:43:31 +00:00
|
|
|
|
2008-04-06 12:52:58 +00:00
|
|
|
@see Events emitted by wxComboCtrl.
|
|
|
|
|
2008-03-08 13:52:38 +00:00
|
|
|
@library{wxadv}
|
|
|
|
@category{ctrl}
|
2008-10-13 08:05:18 +00:00
|
|
|
@appearance{ownerdrawncombobox.png}
|
2008-03-08 14:43:31 +00:00
|
|
|
|
2008-03-10 15:24:38 +00:00
|
|
|
@see wxComboCtrl, wxComboBox, wxVListBox, wxCommandEvent
|
2008-03-08 13:52:38 +00:00
|
|
|
*/
|
|
|
|
class wxOwnerDrawnComboBox : public wxComboCtrl
|
|
|
|
{
|
|
|
|
public:
|
2008-04-06 12:52:58 +00:00
|
|
|
/**
|
|
|
|
Default constructor.
|
|
|
|
*/
|
|
|
|
wxOwnerDrawnComboBox();
|
2008-04-06 14:43:04 +00:00
|
|
|
|
2008-03-08 13:52:38 +00:00
|
|
|
/**
|
|
|
|
Constructor, creating and showing a owner-drawn combobox.
|
2008-03-20 13:45:17 +00:00
|
|
|
|
2008-03-08 14:43:31 +00:00
|
|
|
@param parent
|
2008-03-09 12:33:59 +00:00
|
|
|
Parent window. Must not be @NULL.
|
2008-03-08 14:43:31 +00:00
|
|
|
@param id
|
2008-04-06 12:52:58 +00:00
|
|
|
Window identifier. The value @c wxID_ANY indicates a default value.
|
2008-03-08 14:43:31 +00:00
|
|
|
@param value
|
2008-03-09 12:33:59 +00:00
|
|
|
Initial selection string. An empty string indicates no selection.
|
2008-03-08 14:43:31 +00:00
|
|
|
@param pos
|
2008-03-09 12:33:59 +00:00
|
|
|
Window position.
|
2008-03-08 14:43:31 +00:00
|
|
|
@param size
|
2008-04-06 15:35:21 +00:00
|
|
|
Window size.
|
|
|
|
If ::wxDefaultSize is specified then the window is sized appropriately.
|
2008-03-08 14:43:31 +00:00
|
|
|
@param n
|
2008-03-09 12:33:59 +00:00
|
|
|
Number of strings with which to initialise the control.
|
2008-03-08 14:43:31 +00:00
|
|
|
@param choices
|
2008-03-09 12:33:59 +00:00
|
|
|
An array of strings with which to initialise the control.
|
2008-03-08 14:43:31 +00:00
|
|
|
@param style
|
2008-03-09 12:33:59 +00:00
|
|
|
Window style. See wxOwnerDrawnComboBox.
|
2008-03-08 14:43:31 +00:00
|
|
|
@param validator
|
2008-03-09 12:33:59 +00:00
|
|
|
Window validator.
|
2008-03-08 14:43:31 +00:00
|
|
|
@param name
|
2008-03-09 12:33:59 +00:00
|
|
|
Window name.
|
2008-03-20 13:45:17 +00:00
|
|
|
|
2008-03-09 12:33:59 +00:00
|
|
|
@see Create(), wxValidator
|
2008-03-08 13:52:38 +00:00
|
|
|
*/
|
2008-03-08 14:43:31 +00:00
|
|
|
wxOwnerDrawnComboBox(wxWindow* parent, wxWindowID id,
|
2009-01-10 18:31:45 +00:00
|
|
|
const wxString& value = wxEmptyString,
|
2008-03-08 14:43:31 +00:00
|
|
|
const wxPoint& pos = wxDefaultPosition,
|
|
|
|
const wxSize& size = wxDefaultSize,
|
|
|
|
int n = 0,
|
2008-04-06 12:52:58 +00:00
|
|
|
const wxString[] choices = NULL,
|
2008-03-08 14:43:31 +00:00
|
|
|
long style = 0,
|
|
|
|
const wxValidator& validator = wxDefaultValidator,
|
|
|
|
const wxString& name = "comboBox");
|
2008-08-30 12:44:43 +00: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 14:43:31 +00: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 13:52:38 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
Destructor, destroying the owner-drawn combobox.
|
|
|
|
*/
|
2008-09-27 11:21:10 +00:00
|
|
|
virtual ~wxOwnerDrawnComboBox();
|
2008-03-08 13:52:38 +00:00
|
|
|
|
|
|
|
//@{
|
|
|
|
/**
|
2008-04-06 12:52:58 +00: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 13:52:38 +00:00
|
|
|
*/
|
2009-01-10 22:10:54 +00:00
|
|
|
bool Create(wxWindow *parent,
|
|
|
|
wxWindowID id,
|
2009-01-10 18:31:45 +00:00
|
|
|
const wxString& value = wxEmptyString,
|
2008-03-08 13:52:38 +00:00
|
|
|
const wxPoint& pos = wxDefaultPosition,
|
|
|
|
const wxSize& size = wxDefaultSize,
|
|
|
|
long style = 0,
|
|
|
|
const wxValidator& validator = wxDefaultValidator,
|
2009-01-10 22:10:54 +00: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 14:43:31 +00:00
|
|
|
const wxString& value,
|
|
|
|
const wxPoint& pos,
|
|
|
|
const wxSize& size,
|
|
|
|
const wxArrayString& choices,
|
|
|
|
long style = 0,
|
|
|
|
const wxValidator& validator = wxDefaultValidator,
|
2009-01-10 22:10:54 +00:00
|
|
|
const wxString& name = wxComboBoxNameStr);
|
2008-03-08 13:52:38 +00:00
|
|
|
//@}
|
|
|
|
|
|
|
|
/**
|
|
|
|
Returns index to the widest item in the list.
|
|
|
|
*/
|
2008-09-27 11:21:10 +00:00
|
|
|
virtual int GetWidestItem();
|
2008-03-08 13:52:38 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
Returns width of the widest item in the list.
|
|
|
|
*/
|
2008-09-27 11:21:10 +00:00
|
|
|
virtual int GetWidestItemWidth();
|
2008-03-08 13:52:38 +00:00
|
|
|
|
2008-10-29 18:55:57 +00:00
|
|
|
protected:
|
|
|
|
|
2008-03-08 13:52:38 +00:00
|
|
|
/**
|
|
|
|
This method is used to draw the items background and, maybe, a border around it.
|
2008-04-06 12:52:58 +00:00
|
|
|
|
2008-03-08 13:52:38 +00: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 13:45:17 +00:00
|
|
|
|
2008-04-06 12:52:58 +00:00
|
|
|
@remarks flags has the same meaning as with OnDrawItem().
|
2008-03-08 13:52:38 +00:00
|
|
|
*/
|
2008-10-27 21:26:54 +00:00
|
|
|
virtual void OnDrawBackground(wxDC& dc, const wxRect& rect, int item,
|
|
|
|
int flags) const;
|
2008-03-08 13:52:38 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
The derived class may implement this function to actually draw the item
|
2008-04-06 12:52:58 +00: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 13:45:17 +00:00
|
|
|
|
2008-03-08 14:43:31 +00:00
|
|
|
@param dc
|
2008-03-09 12:33:59 +00:00
|
|
|
The device context to use for drawing
|
2008-03-08 14:43:31 +00:00
|
|
|
@param rect
|
2008-03-09 12:33:59 +00:00
|
|
|
The bounding rectangle for the item being drawn (DC clipping
|
|
|
|
region is set to this rectangle before calling this function)
|
2008-03-08 14:43:31 +00:00
|
|
|
@param item
|
2008-03-09 12:33:59 +00:00
|
|
|
The index of the item to be drawn
|
2008-03-08 14:43:31 +00:00
|
|
|
@param flags
|
2008-04-06 15:35:21 +00:00
|
|
|
A combination of the ::wxOwnerDrawnComboBoxPaintingFlags enumeration values.
|
2008-03-08 13:52:38 +00:00
|
|
|
*/
|
2008-10-27 21:26:54 +00:00
|
|
|
virtual void OnDrawItem(wxDC& dc, const wxRect& rect, int item,
|
|
|
|
int flags) const;
|
2008-03-08 13:52:38 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
The derived class may implement this method to return the height of the
|
|
|
|
specified item (in pixels).
|
2008-04-06 12:52:58 +00:00
|
|
|
|
2008-03-08 13:52:38 +00:00
|
|
|
The default implementation returns text height, as if this control was
|
|
|
|
a normal combobox.
|
|
|
|
*/
|
2008-10-13 11:09:56 +00:00
|
|
|
virtual wxCoord OnMeasureItem(size_t item) const;
|
2008-03-08 13:52:38 +00: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 12:52:58 +00:00
|
|
|
|
2008-03-08 13:52:38 +00:00
|
|
|
The default implementation returns -1.
|
|
|
|
*/
|
2008-10-13 11:09:56 +00:00
|
|
|
virtual wxCoord OnMeasureItemWidth(size_t item) const;
|
2008-03-08 13:52:38 +00:00
|
|
|
};
|
2008-03-10 15:24:38 +00:00
|
|
|
|