X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/655719367ac5e131d9642e5783f3ecf64d1a3385..ddadf560da7ec1d7477a40ed5b9277b6468dc5e7:/include/wx/univ/listbox.h?ds=sidebyside diff --git a/include/wx/univ/listbox.h b/include/wx/univ/listbox.h index acc660541a..5431b7bd18 100644 --- a/include/wx/univ/listbox.h +++ b/include/wx/univ/listbox.h @@ -12,10 +12,6 @@ #ifndef _WX_UNIV_LISTBOX_H_ #define _WX_UNIV_LISTBOX_H_ -#if defined(__GNUG__) && !defined(NO_GCC_PRAGMA) - #pragma interface "univlistbox.h" -#endif - #include "wx/scrolwin.h" // for wxScrollHelper #include "wx/dynarray.h" #include "wx/arrstr.h" @@ -25,38 +21,38 @@ // ---------------------------------------------------------------------------- // change the current item -#define wxACTION_LISTBOX_SETFOCUS _T("setfocus") // select the item -#define wxACTION_LISTBOX_MOVEDOWN _T("down") // select item below -#define wxACTION_LISTBOX_MOVEUP _T("up") // select item above -#define wxACTION_LISTBOX_PAGEDOWN _T("pagedown") // go page down -#define wxACTION_LISTBOX_PAGEUP _T("pageup") // go page up -#define wxACTION_LISTBOX_START _T("start") // go to first item -#define wxACTION_LISTBOX_END _T("end") // go to last item -#define wxACTION_LISTBOX_FIND _T("find") // find item by 1st letter +#define wxACTION_LISTBOX_SETFOCUS wxT("setfocus") // select the item +#define wxACTION_LISTBOX_MOVEDOWN wxT("down") // select item below +#define wxACTION_LISTBOX_MOVEUP wxT("up") // select item above +#define wxACTION_LISTBOX_PAGEDOWN wxT("pagedown") // go page down +#define wxACTION_LISTBOX_PAGEUP wxT("pageup") // go page up +#define wxACTION_LISTBOX_START wxT("start") // go to first item +#define wxACTION_LISTBOX_END wxT("end") // go to last item +#define wxACTION_LISTBOX_FIND wxT("find") // find item by 1st letter // do something with the current item -#define wxACTION_LISTBOX_ACTIVATE _T("activate") // activate (choose) -#define wxACTION_LISTBOX_TOGGLE _T("toggle") // togglee selected state -#define wxACTION_LISTBOX_SELECT _T("select") // sel this, unsel others -#define wxACTION_LISTBOX_SELECTADD _T("selectadd") // add to selection -#define wxACTION_LISTBOX_UNSELECT _T("unselect") // unselect -#define wxACTION_LISTBOX_ANCHOR _T("selanchor") // anchor selection +#define wxACTION_LISTBOX_ACTIVATE wxT("activate") // activate (choose) +#define wxACTION_LISTBOX_TOGGLE wxT("toggle") // togglee selected state +#define wxACTION_LISTBOX_SELECT wxT("select") // sel this, unsel others +#define wxACTION_LISTBOX_SELECTADD wxT("selectadd") // add to selection +#define wxACTION_LISTBOX_UNSELECT wxT("unselect") // unselect +#define wxACTION_LISTBOX_ANCHOR wxT("selanchor") // anchor selection // do something with the selection globally (not for single selection ones) -#define wxACTION_LISTBOX_SELECTALL _T("selectall") // select all items -#define wxACTION_LISTBOX_UNSELECTALL _T("unselectall") // unselect all items -#define wxACTION_LISTBOX_SELTOGGLE _T("togglesel") // invert the selection -#define wxACTION_LISTBOX_EXTENDSEL _T("extend") // extend to item +#define wxACTION_LISTBOX_SELECTALL wxT("selectall") // select all items +#define wxACTION_LISTBOX_UNSELECTALL wxT("unselectall") // unselect all items +#define wxACTION_LISTBOX_SELTOGGLE wxT("togglesel") // invert the selection +#define wxACTION_LISTBOX_EXTENDSEL wxT("extend") // extend to item // ---------------------------------------------------------------------------- // wxListBox: a list of selectable items // ---------------------------------------------------------------------------- -class WXDLLEXPORT wxListBox : public wxListBoxBase, public wxScrollHelper +class WXDLLIMPEXP_CORE wxListBox : public wxListBoxBase, public wxScrollHelper { public: // ctors and such - wxListBox() { Init(); } + wxListBox() : wxScrollHelper(this) { Init(); } wxListBox(wxWindow *parent, wxWindowID id, const wxPoint& pos = wxDefaultPosition, @@ -65,6 +61,7 @@ public: long style = 0, const wxValidator& validator = wxDefaultValidator, const wxString& name = wxListBoxNameStr ) + : wxScrollHelper(this) { Init(); @@ -99,32 +96,34 @@ public: const wxString& name = wxListBoxNameStr); // implement the listbox interface defined by wxListBoxBase - virtual void Clear(); - virtual void Delete(int n); + virtual void DoClear(); + virtual void DoDeleteOneItem(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 IsSorted() ? m_stringsSorted->Index(s) : m_strings->Index(s); } + virtual unsigned int GetCount() const; + virtual wxString GetString(unsigned int n) const; + virtual void SetString(unsigned int n, const wxString& s); + virtual int FindString(const wxString& s, bool bCase = false) const; 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 int DoAppend(const wxString& item); - virtual void DoInsertItems(const wxArrayString& items, int pos); - virtual void DoSetItems(const wxArrayString& items, void **clientData); + virtual void DoSetSelection(int n, bool select); + + virtual int DoInsertItems(const wxArrayStringsAdapter& items, + unsigned int pos, + void **clientData, + wxClientDataType type); + + // universal wxComboBox implementation internally uses wxListBox + friend class WXDLLIMPEXP_FWD_CORE wxComboBox; 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; public: // override some more base class methods @@ -147,10 +146,10 @@ public: void Activate(int item = -1); // select or unselect the specified or current (if -1) item - void DoSelect(int item = -1, bool sel = TRUE); + void DoSelect(int item = -1, bool sel = true); // more readable wrapper - void DoUnselect(int item) { DoSelect(item, FALSE); } + void DoUnselect(int item) { DoSelect(item, false); } // select an item and send a notification about it void SelectAndNotify(int item); @@ -159,10 +158,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 @@ -183,6 +182,12 @@ public: long numArg = 0l, const wxString& strArg = wxEmptyString); + static wxInputHandler *GetStdInputHandler(wxInputHandler *handlerDef); + virtual wxInputHandler *DoGetStdInputHandler(wxInputHandler *handlerDef) + { + return GetStdInputHandler(handlerDef); + } + // idle processing virtual void OnInternalIdle(); @@ -196,15 +201,17 @@ protected: virtual void DoDraw(wxControlRenderer *renderer); virtual wxBorder GetDefaultBorder() const; + // special hook for wxCheckListBox which allows it to update its internal + // data when a new item is inserted into the listbox + virtual void OnItemInserted(unsigned int WXUNUSED(pos)) { } + + // common part of all ctors void Init(); // event handlers void OnSize(wxSizeEvent& event); - // common part of Clear() and DoSetItems(): clears everything - virtual void DoClear(); - // refresh the given item(s) or everything void RefreshItems(int from, int count); void RefreshItem(int n); @@ -238,14 +245,12 @@ protected: void UpdateItems(); // the array containing all items (it is sorted if the listbox has - // wxLB_SORT style). Note the evil trick: the pointers share the - // same location, hence we use m_strings when we don't care if the - // array is sorted or not, m_stringsSorted when we do + // wxLB_SORT style) union { - wxArrayString* m_strings; - wxSortedArrayString* m_stringsSorted; - }; + wxArrayString *unsorted; + wxSortedArrayString *sorted; + } 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 @@ -297,60 +302,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(wxInputConsumer *consumer, - const wxKeyEvent& event, - bool pressed); - virtual bool HandleMouse(wxInputConsumer *consumer, - const wxMouseEvent& event); - virtual bool HandleMouseMove(wxInputConsumer *consumer, - 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_