]> git.saurik.com Git - wxWidgets.git/blame - include/wx/generic/dataview.h
Use wxGetTranslation() instead of _() in the public headers.
[wxWidgets.git] / include / wx / generic / dataview.h
CommitLineData
4ed7af08
RR
1/////////////////////////////////////////////////////////////////////////////
2// Name: wx/generic/dataview.h
3// Purpose: wxDataViewCtrl generic implementation header
4// Author: Robert Roebling
b7e9f8b1 5// Modified By: Bo Yang
4ed7af08
RR
6// Copyright: (c) 1998 Robert Roebling
7// Licence: wxWindows licence
8/////////////////////////////////////////////////////////////////////////////
9
10#ifndef __GENERICDATAVIEWCTRLH__
11#define __GENERICDATAVIEWCTRLH__
12
13#include "wx/defs.h"
14#include "wx/object.h"
15#include "wx/list.h"
16#include "wx/control.h"
9d14de69 17#include "wx/scrolwin.h"
2586d4a1 18#include "wx/icon.h"
d0154e3a 19#include "wx/vector.h"
4ed7af08 20
b5dbe15d
VS
21class WXDLLIMPEXP_FWD_ADV wxDataViewMainWindow;
22class WXDLLIMPEXP_FWD_ADV wxDataViewHeaderWindow;
4ed7af08 23
f554a14b 24// ---------------------------------------------------------
4ed7af08 25// wxDataViewColumn
f554a14b 26// ---------------------------------------------------------
4ed7af08 27
56873923 28class WXDLLIMPEXP_ADV wxDataViewColumn : public wxDataViewColumnBase
4ed7af08
RR
29{
30public:
e2bfe673
VZ
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
5d9e1605 55 virtual void SetTitle(const wxString& title) { m_title = title; UpdateDisplay(); }
e2bfe673
VZ
56 virtual wxString GetTitle() const { return m_title; }
57
5d9e1605 58 virtual void SetWidth(int width) { m_width = width; UpdateDisplay(); }
d0154e3a 59 virtual int GetWidth() const;
e2bfe673 60
5d9e1605 61 virtual void SetMinWidth(int minWidth) { m_minWidth = minWidth; UpdateDisplay(); }
e2bfe673
VZ
62 virtual int GetMinWidth() const { return m_minWidth; }
63
5d9e1605 64 virtual void SetAlignment(wxAlignment align) { m_align = align; UpdateDisplay(); }
e2bfe673
VZ
65 virtual wxAlignment GetAlignment() const { return m_align; }
66
5d9e1605 67 virtual void SetFlags(int flags) { m_flags = flags; UpdateDisplay(); }
e2bfe673
VZ
68 virtual int GetFlags() const { return m_flags; }
69
e2bfe673
VZ
70 virtual bool IsSortKey() const { return m_sort; }
71
732a176c 72 virtual void UnsetAsSortKey();
aadbdd16 73
15b8afdc 74 virtual void SetSortOrder(bool ascending);
aadbdd16 75
e2bfe673 76 virtual bool IsSortOrderAscending() const { return m_sortAscending; }
4ed7af08 77
5d9e1605
RR
78 virtual void SetBitmap( const wxBitmap& bitmap ) { wxDataViewColumnBase::SetBitmap(bitmap); UpdateDisplay(); }
79
80
56873923 81private:
e2bfe673 82 // common part of all ctors
5d9e1605 83 void Init(int width, wxAlignment align, int flags);
ce00f59b 84
5d9e1605 85 void UpdateDisplay();
e2bfe673 86
e2bfe673
VZ
87 wxString m_title;
88 int m_width,
89 m_minWidth;
90 wxAlignment m_align;
91 int m_flags;
92 bool m_sort,
93 m_sortAscending;
94
56873923
VZ
95 friend class wxDataViewHeaderWindowBase;
96 friend class wxDataViewHeaderWindow;
97 friend class wxDataViewHeaderWindowMSW;
4ed7af08
RR
98};
99
f554a14b 100// ---------------------------------------------------------
4ed7af08 101// wxDataViewCtrl
f554a14b 102// ---------------------------------------------------------
4ed7af08 103
4660b556
VZ
104WX_DECLARE_LIST_WITH_DECL(wxDataViewColumn, wxDataViewColumnList,
105 class WXDLLIMPEXP_ADV);
afebb87b 106
938161a6
VZ
107class WXDLLIMPEXP_ADV wxDataViewCtrl : public wxDataViewCtrlBase,
108 public wxScrollHelper
4ed7af08 109{
87f0efe2
RR
110 friend class wxDataViewMainWindow;
111 friend class wxDataViewHeaderWindowBase;
112 friend class wxDataViewHeaderWindow;
113 friend class wxDataViewHeaderWindowMSW;
9861f022 114 friend class wxDataViewColumn;
87f0efe2 115
4ed7af08 116public:
938161a6 117 wxDataViewCtrl() : wxScrollHelper(this)
4ed7af08
RR
118 {
119 Init();
120 }
f554a14b 121
4ed7af08
RR
122 wxDataViewCtrl( wxWindow *parent, wxWindowID id,
123 const wxPoint& pos = wxDefaultPosition,
124 const wxSize& size = wxDefaultSize, long style = 0,
62e9285a 125 const wxValidator& validator = wxDefaultValidator,
346f3fd6 126 const wxString& name = wxDataViewCtrlNameStr )
938161a6 127 : wxScrollHelper(this)
4ed7af08 128 {
62e9285a 129 Create(parent, id, pos, size, style, validator, name);
4ed7af08
RR
130 }
131
132 virtual ~wxDataViewCtrl();
133
134 void Init();
135
136 bool Create(wxWindow *parent, wxWindowID id,
bc4f1ff2
FM
137 const wxPoint& pos = wxDefaultPosition,
138 const wxSize& size = wxDefaultSize, long style = 0,
62e9285a
VZ
139 const wxValidator& validator = wxDefaultValidator,
140 const wxString& name = wxDataViewCtrlNameStr);
4ed7af08 141
aba9bfd0 142 virtual bool AssociateModel( wxDataViewModel *model );
e2bfe673 143
4ed7af08 144 virtual bool AppendColumn( wxDataViewColumn *col );
736fe67c 145 virtual bool PrependColumn( wxDataViewColumn *col );
19723525 146 virtual bool InsertColumn( unsigned int pos, wxDataViewColumn *col );
f554a14b 147
3b6280be
RR
148 virtual void DoSetExpanderColumn();
149 virtual void DoSetIndent();
150
afebb87b
RR
151 virtual unsigned int GetColumnCount() const;
152 virtual wxDataViewColumn* GetColumn( unsigned int pos ) const;
153 virtual bool DeleteColumn( wxDataViewColumn *column );
154 virtual bool ClearColumns();
453091c2 155 virtual int GetColumnPosition( const wxDataViewColumn *column ) const;
afebb87b 156
21f47fb9 157 virtual wxDataViewColumn *GetSortingColumn() const;
e2bfe673 158
fa93d732 159 virtual int GetSelectedItemsCount() const;
b7e9f8b1
RR
160 virtual int GetSelections( wxDataViewItemArray & sel ) const;
161 virtual void SetSelections( const wxDataViewItemArray & sel );
162 virtual void Select( const wxDataViewItem & item );
163 virtual void Unselect( const wxDataViewItem & item );
164 virtual bool IsSelected( const wxDataViewItem & item ) const;
165
66e09788
RR
166 virtual void SelectAll();
167 virtual void UnselectAll();
168
169 virtual void EnsureVisible( const wxDataViewItem & item,
fbda518c 170 const wxDataViewColumn *column = NULL );
03647350 171 virtual void HitTest( const wxPoint & point, wxDataViewItem & item,
bc4f1ff2 172 wxDataViewColumn* &column ) const;
03647350 173 virtual wxRect GetItemRect( const wxDataViewItem & item,
bc4f1ff2 174 const wxDataViewColumn *column = NULL ) const;
66e09788 175
bbfd4548
VZ
176 virtual bool SetRowHeight( int rowHeight );
177
afebb87b
RR
178 virtual void Expand( const wxDataViewItem & item );
179 virtual void Collapse( const wxDataViewItem & item );
739a8399 180 virtual bool IsExpanded( const wxDataViewItem & item ) const;
e2bfe673 181
788432e3 182 virtual void SetFocus();
9adeb77a 183
1af67319
VZ
184 virtual bool SetFont(const wxFont & font);
185
9adeb77a 186#if wxUSE_DRAG_AND_DROP
821baf7d
RR
187 virtual bool EnableDragSource( const wxDataFormat &format );
188 virtual bool EnableDropTarget( const wxDataFormat &format );
9adeb77a 189#endif // wxUSE_DRAG_AND_DROP
afebb87b 190
3fdf86f9
RR
191 virtual wxBorder GetDefaultBorder() const;
192
907f09f4 193 virtual void EditItem(const wxDataViewItem& item, const wxDataViewColumn *column);
c937344c 194
4bdc891f
VZ
195 // These methods are specific to generic wxDataViewCtrl implementation and
196 // should not be used in portable code.
197 wxColour GetAlternateRowColour() const { return m_alternateRowColour; }
198 void SetAlternateRowColour(const wxColour& colour);
199
66e09788 200protected:
fbda518c 201 virtual void EnsureVisible( int row, int column );
b7e9f8b1 202
b0272c60
VZ
203 // Notice that row here may be invalid (i.e. >= GetRowCount()), this is not
204 // an error and this function simply returns an invalid item in this case.
b7e9f8b1
RR
205 virtual wxDataViewItem GetItemByRow( unsigned int row ) const;
206 virtual int GetRowByItem( const wxDataViewItem & item ) const;
207
46234a03
VZ
208 int GetSortingColumnIndex() const { return m_sortingColumnIdx; }
209 void SetSortingColumnIndex(int idx) { m_sortingColumnIdx = idx; }
6ff7eee7 210
9861f022
RR
211public: // utility functions not part of the API
212
87f0efe2 213 // returns the "best" width for the idx-th column
d0154e3a 214 unsigned int GetBestColumnWidth(int idx) const;
87f0efe2 215
fc8c1a15
RR
216 // called by header window after reorder
217 void ColumnMoved( wxDataViewColumn* col, unsigned int new_pos );
218
aef252d9
VZ
219 // update the display after a change to an individual column
220 void OnColumnChange(unsigned int idx);
221
222 // update after a change to the number of columns
223 void OnColumnsCountChanged();
87f0efe2 224
1e510b1e 225 wxWindow *GetMainWindow() { return (wxWindow*) m_clientArea; }
99d471a5 226
702f5349
VZ
227 // return the index of the given column in m_cols
228 int GetColumnIndex(const wxDataViewColumn *column) const;
229
230 // return the column displayed at the given position in the control
231 wxDataViewColumn *GetColumnAt(unsigned int pos) const;
232
ee1377e1
VS
233 virtual wxDataViewColumn *GetCurrentColumn() const;
234
bed74e48
VS
235 virtual void OnInternalIdle();
236
4ed7af08 237private:
80ce465c
VZ
238 virtual wxDataViewItem DoGetCurrentItem() const;
239 virtual void DoSetCurrentItem(const wxDataViewItem& item);
240
bed74e48
VS
241 void InvalidateColBestWidths();
242 void InvalidateColBestWidth(int idx);
243 void UpdateColWidths();
d0154e3a 244
ad386793 245 wxDataViewColumnList m_cols;
840fc4d1 246 // cached column best widths information, values are for
d0154e3a 247 // respective columns from m_cols and the arrays have same size
840fc4d1
VS
248 struct CachedColWidthInfo
249 {
250 CachedColWidthInfo() : width(0), dirty(true) {}
251 int width; // cached width or 0 if not computed
252 bool dirty; // column was invalidated, header needs updating
253 };
254 wxVector<CachedColWidthInfo> m_colsBestWidths;
255 // This indicates that at least one entry in m_colsBestWidths has 'dirty'
256 // flag set. It's cheaper to check one flag in OnInternalIdle() than to
257 // iterate over m_colsBestWidths to check if anything needs to be done.
bed74e48
VS
258 bool m_colsDirty;
259
ad386793
RR
260 wxDataViewModelNotifier *m_notifier;
261 wxDataViewMainWindow *m_clientArea;
262 wxDataViewHeaderWindow *m_headerArea;
46234a03 263
4bdc891f
VZ
264 // user defined color to draw row lines, may be invalid
265 wxColour m_alternateRowColour;
266
46234a03
VZ
267 // the index of the column currently used for sorting or -1
268 int m_sortingColumnIdx;
f554a14b 269
4ed7af08 270private:
4b3feaa7 271 void OnSize( wxSizeEvent &event );
2571a33f 272 virtual wxSize GetSizeAvailableForScrollTarget(const wxSize& size);
f554a14b 273
4ed7af08
RR
274 // we need to return a special WM_GETDLGCODE value to process just the
275 // arrows but let the other navigation characters through
276#ifdef __WXMSW__
277 virtual WXLRESULT MSWWindowProc(WXUINT nMsg, WXWPARAM wParam, WXLPARAM lParam);
278#endif // __WXMSW__
279
280 WX_FORWARD_TO_SCROLL_HELPER()
4b3feaa7 281
4ed7af08
RR
282private:
283 DECLARE_DYNAMIC_CLASS(wxDataViewCtrl)
c0c133e1 284 wxDECLARE_NO_COPY_CLASS(wxDataViewCtrl);
4b3feaa7 285 DECLARE_EVENT_TABLE()
4ed7af08
RR
286};
287
288
289#endif // __GENERICDATAVIEWCTRLH__