]> git.saurik.com Git - wxWidgets.git/blob - include/wx/generic/dataview.h
Only compile wxStd{Input,Output}Stream if wxUSE_STREAMS==1.
[wxWidgets.git] / include / wx / generic / dataview.h
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: wx/generic/dataview.h
3 // Purpose: wxDataViewCtrl generic implementation header
4 // Author: Robert Roebling
5 // Modified By: Bo Yang
6 // Id: $Id$
7 // Copyright: (c) 1998 Robert Roebling
8 // Licence: wxWindows licence
9 /////////////////////////////////////////////////////////////////////////////
10
11 #ifndef __GENERICDATAVIEWCTRLH__
12 #define __GENERICDATAVIEWCTRLH__
13
14 #include "wx/defs.h"
15 #include "wx/object.h"
16 #include "wx/list.h"
17 #include "wx/control.h"
18 #include "wx/scrolwin.h"
19 #include "wx/icon.h"
20
21 class WXDLLIMPEXP_FWD_ADV wxDataViewMainWindow;
22 class WXDLLIMPEXP_FWD_ADV wxDataViewHeaderWindow;
23
24 // ---------------------------------------------------------
25 // wxDataViewColumn
26 // ---------------------------------------------------------
27
28 class WXDLLIMPEXP_ADV wxDataViewColumn : public wxDataViewColumnBase
29 {
30 public:
31 wxDataViewColumn(const wxString& title,
32 wxDataViewRenderer *renderer,
33 unsigned int model_column,
34 int width = wxDVC_DEFAULT_WIDTH,
35 wxAlignment align = wxALIGN_CENTER,
36 int flags = wxDATAVIEW_COL_RESIZABLE)
37 : wxDataViewColumnBase(renderer, model_column),
38 m_title(title)
39 {
40 Init(width, align, flags);
41 }
42
43 wxDataViewColumn(const wxBitmap& bitmap,
44 wxDataViewRenderer *renderer,
45 unsigned int model_column,
46 int width = wxDVC_DEFAULT_WIDTH,
47 wxAlignment align = wxALIGN_CENTER,
48 int flags = wxDATAVIEW_COL_RESIZABLE)
49 : wxDataViewColumnBase(bitmap, renderer, model_column)
50 {
51 Init(width, align, flags);
52 }
53
54 // implement wxHeaderColumnBase methods
55 virtual void SetTitle(const wxString& title) { m_title = title; UpdateDisplay(); }
56 virtual wxString GetTitle() const { return m_title; }
57
58 virtual void SetWidth(int width) { m_width = width; UpdateDisplay(); }
59 virtual int GetWidth() const { return m_width; }
60
61 virtual void SetMinWidth(int minWidth) { m_minWidth = minWidth; UpdateDisplay(); }
62 virtual int GetMinWidth() const { return m_minWidth; }
63
64 virtual void SetAlignment(wxAlignment align) { m_align = align; UpdateDisplay(); }
65 virtual wxAlignment GetAlignment() const { return m_align; }
66
67 virtual void SetFlags(int flags) { m_flags = flags; UpdateDisplay(); }
68 virtual int GetFlags() const { return m_flags; }
69
70 virtual void SetAsSortKey(bool sort = true) { m_sort = sort; UpdateDisplay(); }
71 virtual bool IsSortKey() const { return m_sort; }
72
73 virtual void SetSortOrder(bool ascending) { m_sortAscending = ascending; UpdateDisplay(); }
74 virtual bool IsSortOrderAscending() const { return m_sortAscending; }
75
76 virtual void SetBitmap( const wxBitmap& bitmap ) { wxDataViewColumnBase::SetBitmap(bitmap); UpdateDisplay(); }
77
78
79 private:
80 // common part of all ctors
81 void Init(int width, wxAlignment align, int flags);
82
83 void UpdateDisplay();
84
85 wxString m_title;
86 int m_width,
87 m_minWidth;
88 wxAlignment m_align;
89 int m_flags;
90 bool m_sort,
91 m_sortAscending;
92
93 friend class wxDataViewHeaderWindowBase;
94 friend class wxDataViewHeaderWindow;
95 friend class wxDataViewHeaderWindowMSW;
96 };
97
98 // ---------------------------------------------------------
99 // wxDataViewCtrl
100 // ---------------------------------------------------------
101
102 WX_DECLARE_LIST_WITH_DECL(wxDataViewColumn, wxDataViewColumnList,
103 class WXDLLIMPEXP_ADV);
104
105 class WXDLLIMPEXP_ADV wxDataViewCtrl : public wxDataViewCtrlBase,
106 public wxScrollHelper
107 {
108 friend class wxDataViewMainWindow;
109 friend class wxDataViewHeaderWindowBase;
110 friend class wxDataViewHeaderWindow;
111 friend class wxDataViewHeaderWindowMSW;
112 friend class wxDataViewColumn;
113
114 public:
115 wxDataViewCtrl() : wxScrollHelper(this)
116 {
117 Init();
118 }
119
120 wxDataViewCtrl( wxWindow *parent, wxWindowID id,
121 const wxPoint& pos = wxDefaultPosition,
122 const wxSize& size = wxDefaultSize, long style = 0,
123 const wxValidator& validator = wxDefaultValidator )
124 : wxScrollHelper(this)
125 {
126 Create(parent, id, pos, size, style, validator );
127 }
128
129 virtual ~wxDataViewCtrl();
130
131 void Init();
132
133 bool Create(wxWindow *parent, wxWindowID id,
134 const wxPoint& pos = wxDefaultPosition,
135 const wxSize& size = wxDefaultSize, long style = 0,
136 const wxValidator& validator = wxDefaultValidator );
137
138 virtual bool AssociateModel( wxDataViewModel *model );
139
140 virtual bool AppendColumn( wxDataViewColumn *col );
141 virtual bool PrependColumn( wxDataViewColumn *col );
142 virtual bool InsertColumn( unsigned int pos, wxDataViewColumn *col );
143
144 virtual void DoSetExpanderColumn();
145 virtual void DoSetIndent();
146
147 virtual unsigned int GetColumnCount() const;
148 virtual wxDataViewColumn* GetColumn( unsigned int pos ) const;
149 virtual bool DeleteColumn( wxDataViewColumn *column );
150 virtual bool ClearColumns();
151 virtual int GetColumnPosition( const wxDataViewColumn *column ) const;
152
153 virtual wxDataViewColumn *GetSortingColumn() const;
154
155 virtual wxDataViewItem GetSelection() const;
156 virtual int GetSelections( wxDataViewItemArray & sel ) const;
157 virtual void SetSelections( const wxDataViewItemArray & sel );
158 virtual void Select( const wxDataViewItem & item );
159 virtual void Unselect( const wxDataViewItem & item );
160 virtual bool IsSelected( const wxDataViewItem & item ) const;
161
162 virtual void SelectAll();
163 virtual void UnselectAll();
164
165 virtual void EnsureVisible( const wxDataViewItem & item,
166 const wxDataViewColumn *column = NULL );
167 virtual void HitTest( const wxPoint & point, wxDataViewItem & item,
168 wxDataViewColumn* &column ) const;
169 virtual wxRect GetItemRect( const wxDataViewItem & item,
170 const wxDataViewColumn *column = NULL ) const;
171
172 virtual void Expand( const wxDataViewItem & item );
173 virtual void Collapse( const wxDataViewItem & item );
174 virtual bool IsExpanded( const wxDataViewItem & item ) const;
175
176 virtual void SetFocus();
177
178 #if wxUSE_DRAG_AND_DROP
179 virtual bool EnableDragSource( const wxDataFormat &format );
180 virtual bool EnableDropTarget( const wxDataFormat &format );
181 #endif // wxUSE_DRAG_AND_DROP
182
183 virtual wxBorder GetDefaultBorder() const;
184
185 void StartEditor( const wxDataViewItem & item, unsigned int column );
186
187 protected:
188 virtual int GetSelections( wxArrayInt & sel ) const;
189 virtual void SetSelections( const wxArrayInt & sel );
190 virtual void Select( int row );
191 virtual void Unselect( int row );
192 virtual bool IsSelected( int row ) const;
193 virtual void SelectRange( int from, int to );
194 virtual void UnselectRange( int from, int to );
195
196 virtual void EnsureVisible( int row, int column );
197
198 virtual wxDataViewItem GetItemByRow( unsigned int row ) const;
199 virtual int GetRowByItem( const wxDataViewItem & item ) const;
200
201 int GetSortingColumnIndex() const { return m_sortingColumnIdx; }
202 void SetSortingColumnIndex(int idx) { m_sortingColumnIdx = idx; }
203
204 public: // utility functions not part of the API
205
206 // returns the "best" width for the idx-th column
207 unsigned int GetBestColumnWidth(int WXUNUSED(idx)) const
208 {
209 return GetClientSize().GetWidth() / GetColumnCount();
210 }
211
212 // called by header window after reorder
213 void ColumnMoved( wxDataViewColumn* col, unsigned int new_pos );
214
215 // update the display after a change to an individual column
216 void OnColumnChange(unsigned int idx);
217
218 // update after a change to the number of columns
219 void OnColumnsCountChanged();
220
221 wxWindow *GetMainWindow() { return (wxWindow*) m_clientArea; }
222
223 // return the index of the given column in m_cols
224 int GetColumnIndex(const wxDataViewColumn *column) const;
225
226 // return the column displayed at the given position in the control
227 wxDataViewColumn *GetColumnAt(unsigned int pos) const;
228
229 private:
230 wxDataViewColumnList m_cols;
231 wxDataViewModelNotifier *m_notifier;
232 wxDataViewMainWindow *m_clientArea;
233 wxDataViewHeaderWindow *m_headerArea;
234
235 // the index of the column currently used for sorting or -1
236 int m_sortingColumnIdx;
237
238 private:
239 void OnSize( wxSizeEvent &event );
240 virtual wxSize GetSizeAvailableForScrollTarget(const wxSize& size);
241
242 // we need to return a special WM_GETDLGCODE value to process just the
243 // arrows but let the other navigation characters through
244 #ifdef __WXMSW__
245 virtual WXLRESULT MSWWindowProc(WXUINT nMsg, WXWPARAM wParam, WXLPARAM lParam);
246 #endif // __WXMSW__
247
248 WX_FORWARD_TO_SCROLL_HELPER()
249
250 private:
251 DECLARE_DYNAMIC_CLASS(wxDataViewCtrl)
252 wxDECLARE_NO_COPY_CLASS(wxDataViewCtrl);
253 DECLARE_EVENT_TABLE()
254 };
255
256
257 #endif // __GENERICDATAVIEWCTRLH__