📄 odcombo.h
字号:
#endif
// ----------------------------------------------------------------------------
// wxComboPopupInterface is the interface class that lies between
// the wxPGOwnerDrawnComboBox and its popup window.
// ----------------------------------------------------------------------------
// wxComboPopup internal flags
enum
{
wxPGCP_IFLAG_CREATED = 0x0001, // Set by wxComboControlBase after Create is called
};
class WXDLLEXPORT_PGODC wxPGComboPopup
{
friend class wxPGComboControlBase;
public:
wxPGComboPopup(wxPGComboControl *combo)
{
m_combo = combo;
m_iFlags = 0;
}
virtual ~wxPGComboPopup();
// Create the popup child control.
// Return true for success.
virtual bool Create(wxWindow* parent) = 0;
// We must have an associated control which is subclassed by the combobox.
virtual wxWindow *GetControl() = 0;
// Called immediately after the popup is shown
virtual void OnPopup();
// Called when popup is dismissed
virtual void OnDismiss();
// Called just prior to displaying popup.
// Default implementation does nothing.
virtual void SetStringValue( const wxString& value );
// Gets displayed string representation of the value.
virtual wxString GetStringValue() const = 0;
// This is called to custom paint in the combo control itself (ie. not the popup).
// Default implementation draws value as string.
virtual void PaintComboControl( wxDC& dc, const wxRect& rect );
// Receives key events from the parent wxComboControl.
// Events not handled should be skipped, as usual.
virtual void OnComboKeyEvent( wxKeyEvent& event );
// Implement if you need to support special action when user
// double-clicks on the parent wxComboControl.
virtual void OnComboDoubleClick();
// Return final size of popup. Called on every popup, just prior to OnShow.
// minWidth = preferred minimum width for window
// prefHeight = preferred height. Only applies if > 0,
// maxHeight = max height for window, as limited by screen size
// and should only be rounded down, if necessary.
virtual wxSize GetAdjustedSize( int minWidth, int prefHeight, int maxHeight );
// Return true if you want delay call to Create until the popup is shown
// for the first time. It is more efficient, but note that it is often
// more convenient to have the control created immediately.
// Default returns false.
virtual bool LazyCreate();
//
// Utilies
//
// Hides the popup
void Dismiss();
// Returns true if Create has been called.
inline bool IsCreated() const
{
return (m_iFlags & wxPGCP_IFLAG_CREATED) ? true : false;
}
protected:
wxPGComboControl* m_combo;
wxUint32 m_iFlags;
};
// New window styles for wxPGOwnerDrawnComboBox
enum
{
// Causes double-clicking to cycle the item instead of showing
// the popup. Shift-pressed causes cycling direction to reverse.
//wxODCB_DOUBLE_CLICK_CYCLES = wxPGCC_SPECIAL_DOUBLE_CLICK,
// 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 = 0x0400
};
//
// Callback flags
//
enum
{
// when set, we are painting the selected item in control,
// not in the popup
wxPGCC_PAINTING_CONTROL = 0x0001
};
//
// Callback arguments:
// pCb: combo box in question
// item: index of item drawn or measured
// dc: device context to draw on. NULL reference when measuring.
// rect: draw call: rectangle in device context to limit the drawing on. Use rect.x and rect.y
// as the origin.
// measure call: initially width and height are -1. You need to set rect.height to whatever
// is the height of the given item.
// flags: see above
/*
typedef void (wxEvtHandler::* wxComboPaintCallback)( wxPGComboControl* pCb,
int item,
wxDC& dc,
wxRect& rect,
int flags );
*/
#include "wx/vlbox.h"
// ----------------------------------------------------------------------------
// wxPGVListBoxComboPopup is a wxVListBox customized to act as a popup control.
//
// Notes:
// wxOwnerDrawnComboBox uses this as its popup. However, it always derives
// from native wxComboControl. If you need to use this popup with
// wxPGGenericComboControl, then remember that vast majority of item manipulation
// functionality is implemented in the wxPGVListBoxComboPopup class itself.
//
// ----------------------------------------------------------------------------
class wxPGVListBoxComboPopup : public wxVListBox, public wxPGComboPopup
{
friend class wxPGOwnerDrawnComboBox;
public:
// ctor and dtor
wxPGVListBoxComboPopup(wxPGComboControl* combo/*, wxComboPaintCallback callback*/);
virtual ~wxPGVListBoxComboPopup();
// required virtuals
virtual bool Create(wxWindow* parent);
virtual wxWindow *GetControl() { return this; }
virtual void SetStringValue( const wxString& value );
virtual wxString GetStringValue() const;
// more customization
virtual void OnPopup();
virtual wxSize GetAdjustedSize( int minWidth, int prefHeight, int maxHeight );
virtual void PaintComboControl( wxDC& dc, const wxRect& rect );
virtual void OnComboKeyEvent( wxKeyEvent& event );
virtual void OnComboDoubleClick();
//virtual bool CycleValue( bool forward );
//virtual bool OnComboDoubleClick();
virtual bool LazyCreate();
// Item management
void SetSelection( int item );
void Insert( const wxString& item, int pos );
int Append(const wxString& item);
void Clear();
void Delete( wxODCIndex item );
void SetItemClientData(wxODCIndex n, void* clientData, wxClientDataType clientDataItemsType);
void *GetItemClientData(wxODCIndex n) const;
void SetString( int item, const wxString& str );
wxString GetString( int item ) const;
wxODCCount GetCount() const;
int FindString(const wxString& s) const;
int GetSelection() const;
void Populate( int n, const wxString choices[] );
void ClearClientDatas();
// helpers
inline int GetItemAtPosition( const wxPoint& pos ) { return HitTest(pos); }
inline wxCoord GetTotalHeight() const { return EstimateTotalHeight(); }
inline wxCoord GetLineHeight(int line) const { return OnGetLineHeight(line); }
protected:
// Called by OnComboDoubleClick and OnComboKeyEvent
bool HandleKey( int keycode, bool saturate );
// sends combobox select event from the parent combo control
void SendComboBoxEvent( int selection );
void DismissWithEvent();
// Re-calculates width for given item
void CheckWidth( int pos );
// wxVListBox implementation
virtual void OnDrawItem(wxDC& dc, const wxRect& rect, size_t n) const;
virtual wxCoord OnMeasureItem(size_t n) const;
void OnDrawBackground(wxDC& dc, const wxRect& rect, size_t n) const;
// filter mouse move events happening outside the list box
// move selection with cursor
void OnMouseMove(wxMouseEvent& event);
void OnMouseWheel(wxMouseEvent& event);
void OnKey(wxKeyEvent& event);
void OnLeftClick(wxMouseEvent& event);
wxArrayString m_strings;
wxArrayPtrVoid m_clientDatas;
wxArrayInt m_widths; // cached line widths
wxString m_stringValue;
wxFont m_font;
int m_value; // selection
int m_itemHover; // on which item the cursor is
int m_widestWidth; // width of widest item thus far
int m_avgCharWidth;
int m_baseImageWidth; // how much per item drawn in addition to text
int m_itemHeight; // default item height (calculate from font size
// and used in the absence of callback)
wxClientDataType m_clientDataItemsType;
private:
// has the mouse been released on this control?
bool m_clicked;
DECLARE_EVENT_TABLE()
};
// ----------------------------------------------------------------------------
// wxPGOwnerDrawnComboBox: a generic wxComboBox that allows custom paint items.
//
// ----------------------------------------------------------------------------
class WXDLLEXPORT_PGODC wxPGOwnerDrawnComboBox : public wxPGComboControl, public wxItemContainer
{
friend class wxPGComboPopupWindow;
friend class wxPGComboControlBase;
public:
// ctors and such
wxPGOwnerDrawnComboBox() : wxPGComboControl() { Init(); }
wxPGOwnerDrawnComboBox(wxWindow *parent,
wxWindowID id,
const wxString& value,
const wxPoint& pos,
const wxSize& size,
int n,
const wxString choices[],
//wxComboPaintCallback callback,
long style = 0,
const wxValidator& validator = wxDefaultValidator,
const wxString& name = wxComboBoxNameStr)
: wxPGComboControl()
{
Init();
(void)Create(parent, id, value, pos, size, n, choices,
/*callback,*/ style, validator, name);
}
bool Create(wxWindow *parent,
wxWindowID id,
const wxString& value = wxEmptyString,
const wxPoint& pos = wxDefaultPosition,
const wxSize& size = wxDefaultSize,
long style = 0,
const wxValidator& validator = wxDefaultValidator,
const wxString& name = wxComboBoxNameStr);
wxPGOwnerDrawnComboBox(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 = wxComboBoxNameStr);
bool Create(wxWindow *parent,
wxWindowID id,
const wxString& value = wxEmptyString,
const wxPoint& pos = wxDefaultPosition,
const wxSize& size = wxDefaultSize,
int n = 0,
const wxString choices[] = (const wxString *) NULL,
long style = 0,
const wxValidator& validator = wxDefaultValidator,
const wxString& name = wxComboBoxNameStr);
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 = wxComboBoxNameStr);
virtual ~wxPGOwnerDrawnComboBox();
// wxControlWithItems methods
virtual void Clear();
virtual void Delete(wxODCIndex n);
virtual wxODCCount GetCount() const;
virtual wxString GetString(wxODCIndex n) const;
virtual void SetString(wxODCIndex n, const wxString& s);
virtual int FindString(const wxString& s) const;
virtual void Select(int n);
virtual int GetSelection() const;
void SetSelection(int n) { Select(n); }
wxCONTROL_ITEMCONTAINER_CLIENTDATAOBJECT_RECAST
protected:
// clears all allocated client datas
void ClearClientDatas();
virtual int DoAppend(const wxString& item);
virtual int DoInsert(const wxString& item, wxODCIndex pos);
virtual void DoSetItemClientData(wxODCIndex n, void* clientData);
virtual void* DoGetItemClientData(wxODCIndex n) const;
virtual void DoSetItemClientObject(wxODCIndex n, wxClientData* clientData);
virtual wxClientData* DoGetItemClientObject(wxODCIndex n) const;
// overload m_popupInterface member so we can access specific popup interface easier
wxPGVListBoxComboPopup* m_popupInterface;
private:
void Init();
DECLARE_EVENT_TABLE()
DECLARE_DYNAMIC_CLASS(wxPGOwnerDrawnComboBox)
};
#endif // _WX_PROPGRID_ODCOMBO_H_
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -