X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/1e6feb95a79834836e88143b15d9f424ebe79621..c2d122aa7d8f2b8d76aef0440b75cd640b56c707:/include/wx/univ/listbox.h diff --git a/include/wx/univ/listbox.h b/include/wx/univ/listbox.h index 03f87df5c0..2edbdc1003 100644 --- a/include/wx/univ/listbox.h +++ b/include/wx/univ/listbox.h @@ -12,11 +12,9 @@ #ifndef _WX_UNIV_LISTBOX_H_ #define _WX_UNIV_LISTBOX_H_ -#ifdef __GNUG__ - #pragma implementation "univlistbox.h" -#endif - #include "wx/scrolwin.h" // for wxScrollHelper +#include "wx/dynarray.h" +#include "wx/arrstr.h" // ---------------------------------------------------------------------------- // the actions supported by this control @@ -50,11 +48,11 @@ // wxListBox: a list of selectable items // ---------------------------------------------------------------------------- -class wxListBox : public wxListBoxBase, public wxScrollHelper +class WXDLLEXPORT wxListBox : public wxListBoxBase, public wxScrollHelper { public: // ctors and such - wxListBox() { Init(); } + wxListBox() : wxScrollHelper(this) { Init(); } wxListBox(wxWindow *parent, wxWindowID id, const wxPoint& pos = wxDefaultPosition, @@ -63,11 +61,20 @@ public: long style = 0, const wxValidator& validator = wxDefaultValidator, const wxString& name = wxListBoxNameStr ) + : wxScrollHelper(this) { Init(); Create(parent, id, pos, size, n, choices, style, validator, name); } + wxListBox(wxWindow *parent, + wxWindowID id, + const wxPoint& pos, + const wxSize& size, + const wxArrayString& choices, + long style = 0, + const wxValidator& validator = wxDefaultValidator, + const wxString& name = wxListBoxNameStr ); virtual ~wxListBox(); @@ -79,34 +86,45 @@ public: long style = 0, const wxValidator& validator = wxDefaultValidator, const wxString& name = wxListBoxNameStr); + bool Create(wxWindow *parent, + wxWindowID id, + const wxPoint& pos, + const wxSize& size, + const wxArrayString& choices, + long style = 0, + const wxValidator& validator = wxDefaultValidator, + const wxString& name = wxListBoxNameStr); // implement the listbox interface defined by wxListBoxBase virtual void Clear(); - virtual void Delete(int n); + virtual void Delete(unsigned int n); - virtual int GetCount() const { return (int)m_strings.GetCount(); } - virtual wxString GetString(int n) const { return m_strings[n]; } - virtual void SetString(int n, const wxString& s); - virtual int FindString(const wxString& s) const - { return m_strings.Index(s); } + virtual unsigned int GetCount() const + { return (unsigned int)m_strings->GetCount(); } + virtual wxString GetString(unsigned int n) const + { return m_strings->Item(n); } + virtual void SetString(unsigned int n, const wxString& s); + virtual int FindString(const wxString& s, bool bCase = false) const + { return m_strings->Index(s, bCase); } virtual bool IsSelected(int n) const { return m_selections.Index(n) != wxNOT_FOUND; } - virtual void SetSelection(int n, bool select = TRUE); virtual int GetSelection() const; virtual int GetSelections(wxArrayInt& aSelections) const; protected: + virtual void DoSetSelection(int n, bool select); + virtual int DoAppendOnly(const wxString& item); virtual int DoAppend(const wxString& item); - virtual void DoInsertItems(const wxArrayString& items, int pos); + virtual void DoInsertItems(const wxArrayString& items, unsigned int pos); virtual void DoSetItems(const wxArrayString& items, void **clientData); virtual void DoSetFirstItem(int n); - virtual void DoSetItemClientData(int n, void* clientData); - virtual void* DoGetItemClientData(int n) const; - virtual void DoSetItemClientObject(int n, wxClientData* clientData); - virtual wxClientData* DoGetItemClientObject(int n) const; + virtual void DoSetItemClientData(unsigned int n, void* clientData); + virtual void* DoGetItemClientData(unsigned int n) const; + virtual void DoSetItemClientObject(unsigned int n, wxClientData* clientData); + virtual wxClientData* DoGetItemClientObject(unsigned int n) const; public: // override some more base class methods @@ -129,10 +147,10 @@ public: void Activate(int item = -1); // select or unselect the specified or current (if -1) item - void Select(bool sel = TRUE, int item = -1); + void DoSelect(int item = -1, bool sel = true); // more readable wrapper - void Unselect(int item) { Select(FALSE, item); } + void DoUnselect(int item) { DoSelect(item, false); } // select an item and send a notification about it void SelectAndNotify(int item); @@ -141,10 +159,10 @@ public: virtual void EnsureVisible(int n); // find the first item [strictly] after the current one which starts with - // the given string and make it the current one, return TRUE if the current + // the given string and make it the current one, return true if the current // item changed - bool FindItem(const wxString& prefix, bool strictlyAfter = FALSE); - bool FindNextItem(const wxString& prefix) { return FindItem(prefix, TRUE); } + bool FindItem(const wxString& prefix, bool strictlyAfter = false); + bool FindNextItem(const wxString& prefix) { return FindItem(prefix, true); } // extend the selection to span the range from the anchor (see below) to // the specified or current item @@ -165,8 +183,14 @@ public: long numArg = 0l, const wxString& strArg = wxEmptyString); - // let wxColourScheme choose the right colours for us - virtual bool IsContainerWindow() const { return TRUE; } + static wxInputHandler *GetStdInputHandler(wxInputHandler *handlerDef); + virtual wxInputHandler *DoGetStdInputHandler(wxInputHandler *handlerDef) + { + return GetStdInputHandler(handlerDef); + } + + // idle processing + virtual void OnInternalIdle(); protected: // geometry @@ -182,7 +206,6 @@ protected: void Init(); // event handlers - void OnIdle(wxIdleEvent& event); void OnSize(wxSizeEvent& event); // common part of Clear() and DoSetItems(): clears everything @@ -222,7 +245,7 @@ protected: // the array containing all items (it is sorted if the listbox has // wxLB_SORT style) - wxArrayString m_strings; + wxArrayString* m_strings; // this array contains the indices of the selected items (for the single // selection listboxes only the first element of it is used and contains @@ -274,60 +297,4 @@ private: DECLARE_DYNAMIC_CLASS(wxListBox) }; -// ---------------------------------------------------------------------------- -// wxStdListboxInputHandler: handles mouse and kbd in a single or multi -// selection listbox -// ---------------------------------------------------------------------------- - -class WXDLLEXPORT wxStdListboxInputHandler : public wxStdInputHandler -{ -public: - // if pressing the mouse button in a multiselection listbox should toggle - // the item under mouse immediately, then specify TRUE as the second - // parameter (this is the standard behaviour, under GTK the item is toggled - // only when the mouse is released in the multi selection listbox) - wxStdListboxInputHandler(wxInputHandler *inphand, - bool toggleOnPressAlways = TRUE); - - // base class methods - virtual bool HandleKey(wxControl *control, - const wxKeyEvent& event, - bool pressed); - virtual bool HandleMouse(wxControl *control, - const wxMouseEvent& event); - virtual bool HandleMouseMove(wxControl *control, - const wxMouseEvent& event); - -protected: - // return the item under mouse, 0 if the mouse is above the listbox or - // GetCount() if it is below it - int HitTest(const wxListBox *listbox, const wxMouseEvent& event); - - // parts of HitTest(): first finds the pseudo (because not in range) index - // of the item and the second one adjusts it if necessary - that is if the - // third one returns FALSE - int HitTestUnsafe(const wxListBox *listbox, const wxMouseEvent& event); - int FixItemIndex(const wxListBox *listbox, int item); - bool IsValidIndex(const wxListBox *listbox, int item); - - // init m_btnCapture and m_actionMouse - wxControlAction SetupCapture(wxListBox *lbox, - const wxMouseEvent& event, - int item); - - wxRenderer *m_renderer; - - // the button which initiated the mouse capture (currently 0 or 1) - int m_btnCapture; - - // the action to perform when the mouse moves while we capture it - wxControlAction m_actionMouse; - - // the ctor parameter toggleOnPressAlways (see comments near it) - bool m_toggleOnPressAlways; - - // do we track the mouse outside the window when it is captured? - bool m_trackMouseOutside; -}; - #endif // _WX_UNIV_LISTBOX_H_