2001-06-26 16:59:19 -04:00
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Name: wx/univ/listbox.h
|
|
|
|
// Purpose: the universal listbox
|
|
|
|
// Author: Vadim Zeitlin
|
|
|
|
// Modified by:
|
|
|
|
// Created: 30.08.00
|
|
|
|
// RCS-ID: $Id$
|
2001-07-04 14:07:15 -04:00
|
|
|
// Copyright: (c) 2000 Vadim Zeitlin <zeitlin@dptmaths.ens-cachan.fr>
|
2004-05-23 16:53:33 -04:00
|
|
|
// Licence: wxWindows licence
|
2001-06-26 16:59:19 -04:00
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
#ifndef _WX_UNIV_LISTBOX_H_
|
|
|
|
#define _WX_UNIV_LISTBOX_H_
|
|
|
|
|
|
|
|
#include "wx/scrolwin.h" // for wxScrollHelper
|
2003-02-10 16:07:36 -05:00
|
|
|
#include "wx/dynarray.h"
|
2003-09-13 08:14:20 -04:00
|
|
|
#include "wx/arrstr.h"
|
2001-06-26 16:59:19 -04:00
|
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// the actions supported by this control
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
// 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
|
|
|
|
|
|
|
|
// 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
|
|
|
|
|
|
|
|
// 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
|
|
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// wxListBox: a list of selectable items
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
2001-10-10 18:18:19 -04:00
|
|
|
class WXDLLEXPORT wxListBox : public wxListBoxBase, public wxScrollHelper
|
2001-06-26 16:59:19 -04:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
// ctors and such
|
2005-10-18 07:13:34 -04:00
|
|
|
wxListBox() : wxScrollHelper(this) { Init(); }
|
2001-06-26 16:59:19 -04:00
|
|
|
wxListBox(wxWindow *parent,
|
|
|
|
wxWindowID id,
|
|
|
|
const wxPoint& pos = wxDefaultPosition,
|
|
|
|
const wxSize& size = wxDefaultSize,
|
|
|
|
int n = 0, const wxString choices[] = (const wxString *) NULL,
|
|
|
|
long style = 0,
|
|
|
|
const wxValidator& validator = wxDefaultValidator,
|
2004-01-15 08:49:22 -05:00
|
|
|
const wxString& name = wxListBoxNameStr )
|
2005-10-18 07:13:34 -04:00
|
|
|
: wxScrollHelper(this)
|
2004-01-15 08:49:22 -05:00
|
|
|
{
|
|
|
|
Init();
|
|
|
|
|
|
|
|
Create(parent, id, pos, size, n, choices, style, validator, name);
|
|
|
|
}
|
2004-01-31 13:21:45 -05:00
|
|
|
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 );
|
2001-06-26 16:59:19 -04:00
|
|
|
|
|
|
|
virtual ~wxListBox();
|
|
|
|
|
|
|
|
bool Create(wxWindow *parent,
|
|
|
|
wxWindowID id,
|
|
|
|
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 = wxListBoxNameStr);
|
2004-01-31 13:21:45 -05:00
|
|
|
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);
|
2001-06-26 16:59:19 -04:00
|
|
|
|
|
|
|
// implement the listbox interface defined by wxListBoxBase
|
|
|
|
virtual void Clear();
|
2006-03-23 17:05:23 -05:00
|
|
|
virtual void Delete(unsigned int n);
|
2001-06-26 16:59:19 -04:00
|
|
|
|
2006-03-23 17:05:23 -05:00
|
|
|
virtual unsigned int GetCount() const
|
|
|
|
{ return (unsigned int)m_strings->GetCount(); }
|
|
|
|
virtual wxString GetString(unsigned int n) const
|
2004-11-19 15:38:04 -05:00
|
|
|
{ return m_strings->Item(n); }
|
2006-03-23 17:05:23 -05:00
|
|
|
virtual void SetString(unsigned int n, const wxString& s);
|
2005-09-27 12:54:43 -04:00
|
|
|
virtual int FindString(const wxString& s, bool bCase = false) const
|
|
|
|
{ return m_strings->Index(s, bCase); }
|
2001-06-26 16:59:19 -04:00
|
|
|
|
|
|
|
virtual bool IsSelected(int n) const
|
|
|
|
{ return m_selections.Index(n) != wxNOT_FOUND; }
|
|
|
|
virtual int GetSelection() const;
|
|
|
|
virtual int GetSelections(wxArrayInt& aSelections) const;
|
|
|
|
|
|
|
|
protected:
|
2006-02-08 16:47:09 -05:00
|
|
|
virtual void DoSetSelection(int n, bool select);
|
2004-11-19 15:38:04 -05:00
|
|
|
virtual int DoAppendOnly(const wxString& item);
|
2001-06-26 16:59:19 -04:00
|
|
|
virtual int DoAppend(const wxString& item);
|
2006-03-23 17:05:23 -05:00
|
|
|
virtual void DoInsertItems(const wxArrayString& items, unsigned int pos);
|
2001-06-26 16:59:19 -04:00
|
|
|
virtual void DoSetItems(const wxArrayString& items, void **clientData);
|
|
|
|
|
|
|
|
virtual void DoSetFirstItem(int n);
|
|
|
|
|
2006-03-23 17:05:23 -05:00
|
|
|
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;
|
2001-06-26 16:59:19 -04:00
|
|
|
|
|
|
|
public:
|
|
|
|
// override some more base class methods
|
|
|
|
virtual bool SetFont(const wxFont& font);
|
|
|
|
|
|
|
|
// the wxUniversal-specific methods
|
|
|
|
// --------------------------------
|
|
|
|
|
|
|
|
// the current item is the same as the selected one for wxLB_SINGLE
|
|
|
|
// listboxes but for the other ones it is just the focused item which may
|
|
|
|
// be selected or not
|
|
|
|
int GetCurrentItem() const { return m_current; }
|
|
|
|
void SetCurrentItem(int n);
|
|
|
|
|
|
|
|
// select the item which is diff items below the current one
|
|
|
|
void ChangeCurrent(int diff);
|
|
|
|
|
|
|
|
// activate (i.e. send a LISTBOX_DOUBLECLICKED message) the specified or
|
|
|
|
// current (if -1) item
|
|
|
|
void Activate(int item = -1);
|
|
|
|
|
|
|
|
// select or unselect the specified or current (if -1) item
|
2004-08-10 09:08:43 -04:00
|
|
|
void DoSelect(int item = -1, bool sel = true);
|
2001-06-26 16:59:19 -04:00
|
|
|
|
|
|
|
// more readable wrapper
|
2004-08-10 09:08:43 -04:00
|
|
|
void DoUnselect(int item) { DoSelect(item, false); }
|
2001-06-26 16:59:19 -04:00
|
|
|
|
|
|
|
// select an item and send a notification about it
|
|
|
|
void SelectAndNotify(int item);
|
|
|
|
|
|
|
|
// ensure that the given item is visible by scrolling it into view
|
|
|
|
virtual void EnsureVisible(int n);
|
|
|
|
|
|
|
|
// find the first item [strictly] after the current one which starts with
|
2004-08-10 09:08:43 -04:00
|
|
|
// the given string and make it the current one, return true if the current
|
2001-06-26 16:59:19 -04:00
|
|
|
// item changed
|
2004-08-10 09:08:43 -04:00
|
|
|
bool FindItem(const wxString& prefix, bool strictlyAfter = false);
|
|
|
|
bool FindNextItem(const wxString& prefix) { return FindItem(prefix, true); }
|
2001-06-26 16:59:19 -04:00
|
|
|
|
|
|
|
// extend the selection to span the range from the anchor (see below) to
|
|
|
|
// the specified or current item
|
|
|
|
void ExtendSelection(int itemTo = -1);
|
|
|
|
|
|
|
|
// make this item the new selection anchor: extending selection with
|
|
|
|
// ExtendSelection() will work with it
|
|
|
|
void AnchorSelection(int itemFrom) { m_selAnchor = itemFrom; }
|
|
|
|
|
|
|
|
// get, calculating it if necessary, the number of items per page, the
|
|
|
|
// height of each line and the max width of an item
|
|
|
|
int GetItemsPerPage() const;
|
|
|
|
wxCoord GetLineHeight() const;
|
|
|
|
wxCoord GetMaxWidth() const;
|
|
|
|
|
|
|
|
// override the wxControl virtual methods
|
|
|
|
virtual bool PerformAction(const wxControlAction& action,
|
|
|
|
long numArg = 0l,
|
|
|
|
const wxString& strArg = wxEmptyString);
|
|
|
|
|
2003-07-09 06:15:21 -04:00
|
|
|
// idle processing
|
|
|
|
virtual void OnInternalIdle();
|
2003-10-16 05:39:22 -04:00
|
|
|
|
2001-06-26 16:59:19 -04:00
|
|
|
protected:
|
|
|
|
// geometry
|
|
|
|
virtual wxSize DoGetBestClientSize() const;
|
|
|
|
virtual void DoSetSize(int x, int y,
|
|
|
|
int width, int height,
|
|
|
|
int sizeFlags = wxSIZE_AUTO);
|
|
|
|
|
|
|
|
virtual void DoDraw(wxControlRenderer *renderer);
|
|
|
|
virtual wxBorder GetDefaultBorder() const;
|
|
|
|
|
|
|
|
// 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);
|
|
|
|
void RefreshFromItemToEnd(int n);
|
|
|
|
void RefreshAll();
|
|
|
|
|
|
|
|
// send an event of the given type (using m_current by default)
|
|
|
|
bool SendEvent(wxEventType type, int item = -1);
|
|
|
|
|
|
|
|
// calculate the number of items per page using our current size
|
|
|
|
void CalcItemsPerPage();
|
|
|
|
|
|
|
|
// can/should we have a horz scrollbar?
|
|
|
|
bool HasHorzScrollbar() const
|
|
|
|
{ return (m_windowStyle & wxLB_HSCROLL) != 0; }
|
|
|
|
|
|
|
|
// redraw the items in the given range only: called from DoDraw()
|
|
|
|
virtual void DoDrawRange(wxControlRenderer *renderer,
|
|
|
|
int itemFirst, int itemLast);
|
|
|
|
|
|
|
|
// update the scrollbars and then ensure that the item is visible
|
|
|
|
void DoEnsureVisible(int n);
|
|
|
|
|
|
|
|
// mark horz scrollbar for updating
|
|
|
|
void RefreshHorzScrollbar();
|
|
|
|
|
|
|
|
// update (show/hide/adjust) the scrollbars
|
|
|
|
void UpdateScrollbars();
|
|
|
|
|
|
|
|
// refresh the items specified by m_updateCount and m_updateFrom
|
|
|
|
void UpdateItems();
|
|
|
|
|
|
|
|
// the array containing all items (it is sorted if the listbox has
|
2004-11-19 15:38:04 -05:00
|
|
|
// wxLB_SORT style)
|
|
|
|
wxArrayString* m_strings;
|
2001-06-26 16:59:19 -04:00
|
|
|
|
|
|
|
// this array contains the indices of the selected items (for the single
|
|
|
|
// selection listboxes only the first element of it is used and contains
|
|
|
|
// the current selection)
|
|
|
|
wxArrayInt m_selections;
|
|
|
|
|
|
|
|
// and this one the client data (either void or wxClientData)
|
|
|
|
wxArrayPtrVoid m_itemsClientData;
|
|
|
|
|
|
|
|
// the current item
|
|
|
|
int m_current;
|
|
|
|
|
|
|
|
private:
|
|
|
|
// the range of elements which must be updated: if m_updateCount is 0 no
|
|
|
|
// update is needed, if it is -1 everything must be updated, otherwise
|
|
|
|
// m_updateCount items starting from m_updateFrom have to be redrawn
|
|
|
|
int m_updateFrom,
|
|
|
|
m_updateCount;
|
|
|
|
|
|
|
|
// the height of one line in the listbox (all lines have the same height)
|
|
|
|
wxCoord m_lineHeight;
|
|
|
|
|
|
|
|
// the maximal width of a listbox item and the item which has it
|
|
|
|
wxCoord m_maxWidth;
|
|
|
|
int m_maxWidthItem;
|
|
|
|
|
|
|
|
// the extents of horz and vert scrollbars
|
|
|
|
int m_scrollRangeX,
|
|
|
|
m_scrollRangeY;
|
|
|
|
|
|
|
|
// the number of items per page
|
|
|
|
size_t m_itemsPerPage;
|
|
|
|
|
|
|
|
// if the number of items has changed we may need to show/hide the
|
|
|
|
// scrollbar
|
|
|
|
bool m_updateScrollbarX, m_updateScrollbarY,
|
|
|
|
m_showScrollbarX, m_showScrollbarY;
|
|
|
|
|
|
|
|
// if the current item has changed, we might need to scroll if it went out
|
|
|
|
// of the window
|
|
|
|
bool m_currentChanged;
|
|
|
|
|
|
|
|
// the anchor from which the selection is extended for the listboxes with
|
|
|
|
// wxLB_EXTENDED style - this is set to the last item which was selected
|
|
|
|
// by not extending the selection but by choosing it directly
|
|
|
|
int m_selAnchor;
|
|
|
|
|
|
|
|
DECLARE_EVENT_TABLE()
|
|
|
|
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
|
2004-08-10 09:08:43 -04:00
|
|
|
// the item under mouse immediately, then specify true as the second
|
2001-06-26 16:59:19 -04:00
|
|
|
// 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,
|
2004-08-10 09:08:43 -04:00
|
|
|
bool toggleOnPressAlways = true);
|
2001-06-26 16:59:19 -04:00
|
|
|
|
|
|
|
// base class methods
|
2001-09-22 07:56:04 -04:00
|
|
|
virtual bool HandleKey(wxInputConsumer *consumer,
|
2001-06-26 16:59:19 -04:00
|
|
|
const wxKeyEvent& event,
|
|
|
|
bool pressed);
|
2001-09-22 07:56:04 -04:00
|
|
|
virtual bool HandleMouse(wxInputConsumer *consumer,
|
2001-06-26 16:59:19 -04:00
|
|
|
const wxMouseEvent& event);
|
2001-09-22 07:56:04 -04:00
|
|
|
virtual bool HandleMouseMove(wxInputConsumer *consumer,
|
2001-06-26 16:59:19 -04:00
|
|
|
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
|
2004-08-10 09:08:43 -04:00
|
|
|
// third one returns false
|
2001-06-26 16:59:19 -04:00
|
|
|
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_
|