-// ----------------------------------------------------------------------------
-// wxComboPopup is the interface which must be implemented by a control to be
-// used as a popup by wxComboControl
-// ----------------------------------------------------------------------------
-
-class WXDLLEXPORT wxComboPopup
-{
-public:
- wxComboPopup(wxComboControl *combo) { m_combo = combo; }
- virtual ~wxComboPopup() {}
-
- // we must have an associated control which is subclassed by the combobox
- virtual wxControl *GetControl() = 0;
-
- // called before showing the control to set the initial selection - notice
- // that the text passed to this method might not correspond to any valid
- // item (if the user edited it directly), in which case the method should
- // just return false but not emit any errors
- virtual bool SetSelection(const wxString& value) = 0;
-
- // called immediately after the control is shown
- virtual void OnShow() = 0;
-
- virtual wxCoord GetBestWidth() const {return 0; }
-
-protected:
- wxComboControl *m_combo;
-};
-
-// ----------------------------------------------------------------------------
-// wxComboControl: a combination of a (single line) text control with a button
-// opening a popup window which contains the control from which the user can
-// choose the value directly.
-// ----------------------------------------------------------------------------
-
-class WXDLLEXPORT wxComboControl : public wxControl
-{
-public:
- // construction
- wxComboControl()
- {
- Init();
- }
-
- wxComboControl(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)
- {
- Init();
-
- (void)Create(parent, id, value, pos, size, 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);
-
- virtual ~wxComboControl();
-
- // a combo control needs a control for popup window it displays
- void SetPopupControl(wxComboPopup *popup);
- wxComboPopup *GetPopupControl() const { return m_popup; }
-
- // show/hide popup window
- void ShowPopup();
- void HidePopup();
-
- // return true if the popup is currently shown
- bool IsPopupShown() const { return m_isPopupShown; }
-
- // get the popup window containing the popup control
- wxPopupComboWindow *GetPopupWindow() const { return m_winPopup; }
-
- // get the text control which is part of the combobox
- wxTextCtrl *GetText() const { return m_text; }
-
- // implementation only from now on
- // -------------------------------
-
- // notifications from wxComboPopup (shouldn't be called by anybody else)
-
- // called when the user selects something in the popup: this normally hides
- // the popup and sets the text to the new value
- virtual void OnSelect(const wxString& value);
-
- // called when the user dismisses the popup
- virtual void OnDismiss();
-
- // forward these functions to all subcontrols
- virtual bool Enable(bool enable = true);
- virtual bool Show(bool show = true);
-
-#if wxUSE_TOOLTIPS
- virtual void DoSetToolTip( wxToolTip *tip );
-#endif // wxUSE_TOOLTIPS
-
- // we have our own input handler and our own actions
- virtual bool PerformAction(const wxControlAction& action,
- long numArg = 0l,
- const wxString& strArg = wxEmptyString);
-
-protected:
- // override the base class virtuals involved into geometry calculations
- virtual wxSize DoGetBestClientSize() const;
- virtual void DoMoveWindow(int x, int y, int width, int height);
- virtual void DoSetSize(int x, int y,
- int width, int height,
- int sizeFlags = wxSIZE_AUTO);
-
- // event handlers
- void OnKey(wxKeyEvent& event);
-
- // common part of all ctors
- void Init();
-
-private:
- // the text control and button we show all the time
- wxTextCtrl *m_text;
- wxButton *m_btn;
-
- // the popup control
- wxComboPopup *m_popup;
-
- // and the popup window containing it
- wxPopupComboWindow *m_winPopup;
-
- // the height of the combobox popup as calculated in Create()
- wxCoord m_heightPopup;
-
- // is the popup window currenty shown?
- bool m_isPopupShown;
-
- DECLARE_EVENT_TABLE()
-};