1 /////////////////////////////////////////////////////////////////////////////
2 // Name:        wx/gtk/listbox.h
3 // Purpose:     wxListBox class declaration
4 // Author:      Robert Roebling
5 // Copyright:   (c) 1998 Robert Roebling
6 // Licence:     wxWindows licence
7 /////////////////////////////////////////////////////////////////////////////
8 
9 #ifndef _WX_GTK_LISTBOX_H_
10 #define _WX_GTK_LISTBOX_H_
11 
12 struct _wxTreeEntry;
13 struct _GtkTreeIter;
14 
15 //-----------------------------------------------------------------------------
16 // wxListBox
17 //-----------------------------------------------------------------------------
18 
19 class WXDLLIMPEXP_CORE wxListBox : public wxListBoxBase
20 {
21 public:
22     // ctors and such
wxListBox()23     wxListBox()
24     {
25         Init();
26     }
27     wxListBox( wxWindow *parent, wxWindowID id,
28             const wxPoint& pos = wxDefaultPosition,
29             const wxSize& size = wxDefaultSize,
30             int n = 0, const wxString choices[] = (const wxString *) NULL,
31             long style = 0,
32             const wxValidator& validator = wxDefaultValidator,
33             const wxString& name = wxListBoxNameStr )
34     {
35         Init();
36         Create(parent, id, pos, size, n, choices, style, validator, name);
37     }
38     wxListBox( wxWindow *parent, wxWindowID id,
39             const wxPoint& pos,
40             const wxSize& size,
41             const wxArrayString& choices,
42             long style = 0,
43             const wxValidator& validator = wxDefaultValidator,
44             const wxString& name = wxListBoxNameStr )
45     {
46         Init();
47         Create(parent, id, pos, size, choices, style, validator, name);
48     }
49     virtual ~wxListBox();
50 
51     bool Create(wxWindow *parent, wxWindowID id,
52                 const wxPoint& pos = wxDefaultPosition,
53                 const wxSize& size = wxDefaultSize,
54                 int n = 0, const wxString choices[] = (const wxString *) NULL,
55                 long style = 0,
56                 const wxValidator& validator = wxDefaultValidator,
57                 const wxString& name = wxListBoxNameStr);
58     bool Create(wxWindow *parent, wxWindowID id,
59                 const wxPoint& pos,
60                 const wxSize& size,
61                 const wxArrayString& choices,
62                 long style = 0,
63                 const wxValidator& validator = wxDefaultValidator,
64                 const wxString& name = wxListBoxNameStr);
65 
66     virtual unsigned int GetCount() const;
67     virtual wxString GetString(unsigned int n) const;
68     virtual void SetString(unsigned int n, const wxString& s);
69     virtual int FindString(const wxString& s, bool bCase = false) const;
70 
71     virtual bool IsSelected(int n) const;
72     virtual int GetSelection() const;
73     virtual int GetSelections(wxArrayInt& aSelections) const;
74 
75     virtual void EnsureVisible(int n);
76 
77     virtual void Update();
78 
79     static wxVisualAttributes
80     GetClassDefaultAttributes(wxWindowVariant variant = wxWINDOW_VARIANT_NORMAL);
81 
82     // implementation from now on
83 
84     virtual GtkWidget *GetConnectWidget();
85 
86     struct _GtkTreeView   *m_treeview;
87     struct _GtkListStore  *m_liststore;
88 
89 #if wxUSE_CHECKLISTBOX
90     bool       m_hasCheckBoxes;
91 #endif // wxUSE_CHECKLISTBOX
92 
93     struct _wxTreeEntry* GTKGetEntry(unsigned pos) const;
94 
95     void GTKDisableEvents();
96     void GTKEnableEvents();
97 
98     void GTKOnSelectionChanged();
99     void GTKOnActivated(int item);
100 
101 protected:
102     virtual void DoClear();
103     virtual void DoDeleteOneItem(unsigned int n);
104     virtual wxSize DoGetBestSize() const;
105     virtual void DoApplyWidgetStyle(GtkRcStyle *style);
106     virtual GdkWindow *GTKGetWindow(wxArrayGdkWindows& windows) const;
107 
108     virtual void DoSetSelection(int n, bool select);
109 
110     virtual int DoInsertItems(const wxArrayStringsAdapter& items,
111                               unsigned int pos,
112                               void **clientData, wxClientDataType type);
113     virtual int DoInsertOneItem(const wxString& item, unsigned int pos);
114 
115     virtual void DoSetFirstItem(int n);
116     virtual void DoSetItemClientData(unsigned int n, void* clientData);
117     virtual void* DoGetItemClientData(unsigned int n) const;
118     virtual int DoListHitTest(const wxPoint& point) const;
119 
120     // get the iterator for the given index, returns false if invalid
121     bool GTKGetIteratorFor(unsigned pos, _GtkTreeIter *iter) const;
122 
123     // get the index for the given iterator, return wxNOT_FOUND on failure
124     int GTKGetIndexFor(_GtkTreeIter& iter) const;
125 
126     // common part of DoSetFirstItem() and EnsureVisible()
127     void DoScrollToCell(int n, float alignY, float alignX);
128 
129 private:
130     void Init(); //common construction
131 
132     DECLARE_DYNAMIC_CLASS(wxListBox)
133 };
134 
135 #endif // _WX_GTK_LISTBOX_H_
136