]>
Commit | Line | Data |
---|---|---|
4ed7af08 | 1 | ///////////////////////////////////////////////////////////////////////////// |
f554a14b | 2 | // Name: src/generic/datavgen.cpp |
4ed7af08 RR |
3 | // Purpose: wxDataViewCtrl generic implementation |
4 | // Author: Robert Roebling | |
87f0efe2 | 5 | // Modified by: Francesco Montorsi, Guru Kathiresan, Otto Wyss |
4ed7af08 RR |
6 | // Id: $Id$ |
7 | // Copyright: (c) 1998 Robert Roebling | |
8 | // Licence: wxWindows licence | |
9 | ///////////////////////////////////////////////////////////////////////////// | |
10 | ||
11 | // For compilers that support precompilation, includes "wx.h". | |
12 | #include "wx/wxprec.h" | |
13 | ||
ed4b0fdc WS |
14 | #ifdef __BORLANDC__ |
15 | #pragma hdrstop | |
16 | #endif | |
17 | ||
4ed7af08 RR |
18 | #if wxUSE_DATAVIEWCTRL |
19 | ||
20 | #include "wx/dataview.h" | |
21 | ||
22 | #ifdef wxUSE_GENERICDATAVIEWCTRL | |
23 | ||
f554a14b | 24 | #ifndef WX_PRECOMP |
57bd4c60 | 25 | #ifdef __WXMSW__ |
87f0efe2 | 26 | #include "wx/msw/private.h" |
57bd4c60 | 27 | #include "wx/msw/wrapwin.h" |
87f0efe2 | 28 | #include "wx/msw/wrapcctl.h" // include <commctrl.h> "properly" |
57bd4c60 | 29 | #endif |
f554a14b WS |
30 | #include "wx/sizer.h" |
31 | #include "wx/log.h" | |
ed4b0fdc | 32 | #include "wx/dcclient.h" |
c0badb70 | 33 | #include "wx/timer.h" |
9eddec69 | 34 | #include "wx/settings.h" |
8d0ca292 | 35 | #include "wx/msgdlg.h" |
f554a14b WS |
36 | #endif |
37 | ||
4ed7af08 | 38 | #include "wx/stockitem.h" |
4ed7af08 RR |
39 | #include "wx/calctrl.h" |
40 | #include "wx/popupwin.h" | |
4ed7af08 | 41 | #include "wx/renderer.h" |
2e992e06 | 42 | #include "wx/dcbuffer.h" |
2586d4a1 | 43 | #include "wx/icon.h" |
4ed7af08 | 44 | |
4ed7af08 RR |
45 | //----------------------------------------------------------------------------- |
46 | // classes | |
47 | //----------------------------------------------------------------------------- | |
48 | ||
49 | class wxDataViewCtrl; | |
50 | ||
9861f022 RR |
51 | static const int SCROLL_UNIT_X = 15; |
52 | ||
53 | // the cell padding on the left/right | |
54 | static const int PADDING_RIGHTLEFT = 3; | |
55 | ||
56 | // the cell padding on the top/bottom | |
57 | static const int PADDING_TOPBOTTOM = 1; | |
58 | ||
59 | ||
a0f3af5f RR |
60 | //----------------------------------------------------------------------------- |
61 | // wxDataViewHeaderWindow | |
62 | //----------------------------------------------------------------------------- | |
4ed7af08 | 63 | |
87f0efe2 RR |
64 | #define USE_NATIVE_HEADER_WINDOW 1 |
65 | ||
c741d33f VZ |
66 | // NB: for some reason, this class must be dllexport'ed or we get warnings from |
67 | // MSVC in DLL build | |
68 | class WXDLLIMPEXP_ADV wxDataViewHeaderWindowBase : public wxControl | |
87f0efe2 RR |
69 | { |
70 | public: | |
71 | wxDataViewHeaderWindowBase() | |
72 | { m_owner = NULL; } | |
73 | ||
74 | bool Create(wxDataViewCtrl *parent, wxWindowID id, | |
c741d33f | 75 | const wxPoint &pos, const wxSize &size, |
87f0efe2 RR |
76 | const wxString &name) |
77 | { | |
78 | return wxWindow::Create(parent, id, pos, size, wxNO_BORDER, name); | |
79 | } | |
80 | ||
81 | void SetOwner( wxDataViewCtrl* owner ) { m_owner = owner; } | |
82 | wxDataViewCtrl *GetOwner() { return m_owner; } | |
83 | ||
84 | // called on column addition/removal | |
85 | virtual void UpdateDisplay() { /* by default, do nothing */ } | |
86 | ||
87f0efe2 | 87 | // returns the n-th column |
9861f022 | 88 | virtual wxDataViewColumn *GetColumn(unsigned int n) |
87f0efe2 RR |
89 | { |
90 | wxASSERT(m_owner); | |
c741d33f | 91 | wxDataViewColumn *ret = m_owner->GetColumn(n); |
87f0efe2 RR |
92 | wxASSERT(ret); |
93 | ||
c741d33f | 94 | return ret; |
87f0efe2 RR |
95 | } |
96 | ||
97 | protected: | |
98 | wxDataViewCtrl *m_owner; | |
99 | ||
100 | // sends an event generated from the n-th wxDataViewColumn | |
101 | void SendEvent(wxEventType type, unsigned int n); | |
102 | }; | |
103 | ||
104 | // on wxMSW the header window (only that part however) can be made native! | |
105 | #if defined(__WXMSW__) && USE_NATIVE_HEADER_WINDOW | |
106 | ||
9861f022 | 107 | #define COLUMN_WIDTH_OFFSET 2 |
87f0efe2 RR |
108 | #define wxDataViewHeaderWindowMSW wxDataViewHeaderWindow |
109 | ||
110 | class wxDataViewHeaderWindowMSW : public wxDataViewHeaderWindowBase | |
4ed7af08 RR |
111 | { |
112 | public: | |
87f0efe2 RR |
113 | |
114 | wxDataViewHeaderWindowMSW( wxDataViewCtrl *parent, | |
9861f022 RR |
115 | wxWindowID id, |
116 | const wxPoint &pos = wxDefaultPosition, | |
117 | const wxSize &size = wxDefaultSize, | |
118 | const wxString &name = wxT("wxdataviewctrlheaderwindow") ) | |
c741d33f | 119 | { |
87f0efe2 RR |
120 | Create(parent, id, pos, size, name); |
121 | } | |
4ed7af08 | 122 | |
87f0efe2 | 123 | bool Create(wxDataViewCtrl *parent, wxWindowID id, |
c741d33f | 124 | const wxPoint &pos, const wxSize &size, |
87f0efe2 RR |
125 | const wxString &name); |
126 | ||
127 | ~wxDataViewHeaderWindowMSW(); | |
128 | ||
9861f022 RR |
129 | // called when any column setting is changed and/or changed |
130 | // the column count | |
87f0efe2 RR |
131 | virtual void UpdateDisplay(); |
132 | ||
133 | // called when the main window gets scrolled | |
134 | virtual void ScrollWindow(int dx, int dy, const wxRect *rect = NULL); | |
135 | ||
136 | protected: | |
137 | virtual bool MSWOnNotify(int idCtrl, WXLPARAM lParam, WXLPARAM *result); | |
9861f022 RR |
138 | virtual void DoSetSize(int x, int y, int width, int height, int sizeFlags); |
139 | ||
140 | unsigned int GetColumnIdxFromHeader(NMHEADER *nmHDR); | |
141 | ||
142 | wxDataViewColumn *GetColumnFromHeader(NMHEADER *nmHDR) | |
143 | { return GetColumn(GetColumnIdxFromHeader(nmHDR)); } | |
144 | ||
87f0efe2 RR |
145 | private: |
146 | DECLARE_DYNAMIC_CLASS(wxDataViewHeaderWindowMSW) | |
147 | }; | |
148 | ||
149 | #else // !defined(__WXMSW__) | |
150 | ||
151 | #define HEADER_WINDOW_HEIGHT 25 | |
9861f022 RR |
152 | #define HEADER_HORIZ_BORDER 5 |
153 | #define HEADER_VERT_BORDER 3 | |
87f0efe2 RR |
154 | #define wxGenericDataViewHeaderWindow wxDataViewHeaderWindow |
155 | ||
156 | class wxGenericDataViewHeaderWindow : public wxDataViewHeaderWindowBase | |
157 | { | |
158 | public: | |
159 | wxGenericDataViewHeaderWindow( wxDataViewCtrl *parent, | |
160 | wxWindowID id, | |
161 | const wxPoint &pos = wxDefaultPosition, | |
162 | const wxSize &size = wxDefaultSize, | |
163 | const wxString &name = wxT("wxdataviewctrlheaderwindow") ) | |
c741d33f | 164 | { |
87f0efe2 RR |
165 | Init(); |
166 | Create(parent, id, pos, size, name); | |
167 | } | |
168 | ||
169 | bool Create(wxDataViewCtrl *parent, wxWindowID id, | |
c741d33f | 170 | const wxPoint &pos, const wxSize &size, |
87f0efe2 RR |
171 | const wxString &name); |
172 | ||
173 | ~wxGenericDataViewHeaderWindow() | |
174 | { | |
175 | delete m_resizeCursor; | |
176 | } | |
177 | ||
178 | // event handlers: | |
4ed7af08 | 179 | |
a0f3af5f RR |
180 | void OnPaint( wxPaintEvent &event ); |
181 | void OnMouse( wxMouseEvent &event ); | |
182 | void OnSetFocus( wxFocusEvent &event ); | |
f554a14b | 183 | |
87f0efe2 RR |
184 | |
185 | protected: | |
186 | ||
187 | // vars used for column resizing: | |
188 | ||
a0f3af5f | 189 | wxCursor *m_resizeCursor; |
87f0efe2 RR |
190 | const wxCursor *m_currentCursor; |
191 | bool m_isDragging; | |
192 | ||
193 | bool m_dirty; // needs refresh? | |
194 | int m_column; // index of the column being resized | |
195 | int m_currentX; // divider line position in logical (unscrolled) coords | |
c741d33f | 196 | int m_minX; // minimal position beyond which the divider line |
87f0efe2 RR |
197 | // can't be dragged in logical coords |
198 | ||
9861f022 RR |
199 | // the pen used to draw the current column width drag line |
200 | // when resizing the columsn | |
201 | wxPen m_penCurrent; | |
202 | ||
203 | ||
87f0efe2 RR |
204 | // internal utilities: |
205 | ||
206 | void Init() | |
207 | { | |
208 | m_currentCursor = (wxCursor *) NULL; | |
209 | m_resizeCursor = new wxCursor( wxCURSOR_SIZEWE ); | |
210 | ||
211 | m_isDragging = false; | |
212 | m_dirty = false; | |
213 | ||
214 | m_column = wxNOT_FOUND; | |
215 | m_currentX = 0; | |
216 | m_minX = 0; | |
9861f022 RR |
217 | |
218 | wxColour col = wxSystemSettings::GetColour(wxSYS_COLOUR_3DLIGHT); | |
219 | m_penCurrent = wxPen(col, 1, wxSOLID); | |
87f0efe2 RR |
220 | } |
221 | ||
222 | void DrawCurrent(); | |
223 | void AdjustDC(wxDC& dc); | |
f554a14b | 224 | |
a0f3af5f | 225 | private: |
87f0efe2 | 226 | DECLARE_DYNAMIC_CLASS(wxGenericDataViewHeaderWindow) |
a0f3af5f RR |
227 | DECLARE_EVENT_TABLE() |
228 | }; | |
4ed7af08 | 229 | |
87f0efe2 RR |
230 | #endif // defined(__WXMSW__) |
231 | ||
0fcce6b9 RR |
232 | //----------------------------------------------------------------------------- |
233 | // wxDataViewRenameTimer | |
234 | //----------------------------------------------------------------------------- | |
235 | ||
236 | class wxDataViewRenameTimer: public wxTimer | |
237 | { | |
238 | private: | |
239 | wxDataViewMainWindow *m_owner; | |
240 | ||
241 | public: | |
242 | wxDataViewRenameTimer( wxDataViewMainWindow *owner ); | |
243 | void Notify(); | |
244 | }; | |
245 | ||
246 | //----------------------------------------------------------------------------- | |
247 | // wxDataViewTextCtrlWrapper: wraps a wxTextCtrl for inline editing | |
248 | //----------------------------------------------------------------------------- | |
249 | ||
250 | class wxDataViewTextCtrlWrapper : public wxEvtHandler | |
251 | { | |
252 | public: | |
253 | // NB: text must be a valid object but not Create()d yet | |
254 | wxDataViewTextCtrlWrapper( wxDataViewMainWindow *owner, | |
255 | wxTextCtrl *text, | |
256 | wxDataViewListModel *model, | |
0a71f9e9 | 257 | unsigned int col, unsigned int row, |
0fcce6b9 RR |
258 | wxRect cellLabel ); |
259 | ||
260 | wxTextCtrl *GetText() const { return m_text; } | |
261 | ||
262 | void AcceptChangesAndFinish(); | |
263 | ||
264 | protected: | |
265 | void OnChar( wxKeyEvent &event ); | |
266 | void OnKeyUp( wxKeyEvent &event ); | |
267 | void OnKillFocus( wxFocusEvent &event ); | |
268 | ||
269 | bool AcceptChanges(); | |
270 | void Finish(); | |
271 | ||
272 | private: | |
273 | wxDataViewMainWindow *m_owner; | |
274 | wxTextCtrl *m_text; | |
275 | wxString m_startValue; | |
276 | wxDataViewListModel *m_model; | |
0a71f9e9 RR |
277 | unsigned int m_col; |
278 | unsigned int m_row; | |
0fcce6b9 RR |
279 | bool m_finished; |
280 | bool m_aboutToFinish; | |
281 | ||
282 | DECLARE_EVENT_TABLE() | |
283 | }; | |
284 | ||
a0f3af5f RR |
285 | //----------------------------------------------------------------------------- |
286 | // wxDataViewMainWindow | |
287 | //----------------------------------------------------------------------------- | |
4ed7af08 | 288 | |
c741d33f | 289 | WX_DEFINE_SORTED_USER_EXPORTED_ARRAY_SIZE_T(unsigned int, wxDataViewSelection, |
87f0efe2 | 290 | WXDLLIMPEXP_ADV); |
cab07038 | 291 | |
a0f3af5f | 292 | class wxDataViewMainWindow: public wxWindow |
4ed7af08 | 293 | { |
a0f3af5f RR |
294 | public: |
295 | wxDataViewMainWindow( wxDataViewCtrl *parent, | |
296 | wxWindowID id, | |
297 | const wxPoint &pos = wxDefaultPosition, | |
298 | const wxSize &size = wxDefaultSize, | |
299 | const wxString &name = wxT("wxdataviewctrlmainwindow") ); | |
d3c7fc99 | 300 | virtual ~wxDataViewMainWindow(); |
4ed7af08 | 301 | |
a0f3af5f RR |
302 | // notifications from wxDataViewListModel |
303 | bool RowAppended(); | |
304 | bool RowPrepended(); | |
0a71f9e9 RR |
305 | bool RowInserted( unsigned int before ); |
306 | bool RowDeleted( unsigned int row ); | |
307 | bool RowChanged( unsigned int row ); | |
308 | bool ValueChanged( unsigned int col, unsigned int row ); | |
309 | bool RowsReordered( unsigned int *new_order ); | |
a0f3af5f | 310 | bool Cleared(); |
4ed7af08 | 311 | |
a0f3af5f RR |
312 | void SetOwner( wxDataViewCtrl* owner ) { m_owner = owner; } |
313 | wxDataViewCtrl *GetOwner() { return m_owner; } | |
9861f022 | 314 | const wxDataViewCtrl *GetOwner() const { return m_owner; } |
4ed7af08 | 315 | |
a0f3af5f | 316 | void OnPaint( wxPaintEvent &event ); |
0a71f9e9 | 317 | void OnArrowChar(unsigned int newCurrent, const wxKeyEvent& event); |
cab07038 | 318 | void OnChar( wxKeyEvent &event ); |
a0f3af5f RR |
319 | void OnMouse( wxMouseEvent &event ); |
320 | void OnSetFocus( wxFocusEvent &event ); | |
cab07038 | 321 | void OnKillFocus( wxFocusEvent &event ); |
f554a14b | 322 | |
a0f3af5f RR |
323 | void UpdateDisplay(); |
324 | void RecalculateDisplay(); | |
325 | void OnInternalIdle(); | |
f554a14b | 326 | |
0fcce6b9 RR |
327 | void OnRenameTimer(); |
328 | void FinishEditing( wxTextCtrl *text ); | |
329 | ||
9861f022 | 330 | void ScrollWindow( int dx, int dy, const wxRect *rect = NULL ); |
120b9b05 | 331 | |
0a71f9e9 RR |
332 | bool HasCurrentRow() { return m_currentRow != (unsigned int)-1; } |
333 | void ChangeCurrentRow( unsigned int row ); | |
120b9b05 | 334 | |
cab07038 RR |
335 | bool IsSingleSel() const { return !GetParent()->HasFlag(wxDV_MULTIPLE); }; |
336 | bool IsEmpty() { return GetRowCount() == 0; } | |
120b9b05 | 337 | |
9861f022 RR |
338 | int GetCountPerPage() const; |
339 | int GetEndOfLastCol() const; | |
340 | unsigned int GetFirstVisibleRow() const; | |
341 | unsigned int GetLastVisibleRow() const; | |
342 | unsigned int GetRowCount() const; | |
120b9b05 | 343 | |
87f0efe2 | 344 | void Select( const wxArrayInt& aSelections ); |
cab07038 | 345 | void SelectAllRows( bool on ); |
0a71f9e9 RR |
346 | void SelectRow( unsigned int row, bool on ); |
347 | void SelectRows( unsigned int from, unsigned int to, bool on ); | |
348 | void ReverseRowSelection( unsigned int row ); | |
349 | bool IsRowSelected( unsigned int row ); | |
120b9b05 | 350 | |
0a71f9e9 RR |
351 | void RefreshRow( unsigned int row ); |
352 | void RefreshRows( unsigned int from, unsigned int to ); | |
353 | void RefreshRowsAfter( unsigned int firstRow ); | |
120b9b05 | 354 | |
9861f022 RR |
355 | // returns the colour to be used for drawing the rules |
356 | wxColour GetRuleColour() const | |
357 | { | |
358 | return wxSystemSettings::GetColour(wxSYS_COLOUR_3DLIGHT); | |
359 | } | |
360 | ||
361 | //void EnsureVisible( unsigned int row ); | |
362 | wxRect GetLineRect( unsigned int row ) const; | |
363 | ||
a0f3af5f | 364 | private: |
0fcce6b9 RR |
365 | wxDataViewCtrl *m_owner; |
366 | int m_lineHeight; | |
367 | bool m_dirty; | |
120b9b05 | 368 | |
0fcce6b9 | 369 | wxDataViewColumn *m_currentCol; |
0a71f9e9 | 370 | unsigned int m_currentRow; |
cab07038 | 371 | wxDataViewSelection m_selection; |
120b9b05 | 372 | |
0fcce6b9 RR |
373 | wxDataViewRenameTimer *m_renameTimer; |
374 | wxDataViewTextCtrlWrapper *m_textctrlWrapper; | |
375 | bool m_lastOnSame; | |
f554a14b | 376 | |
cab07038 RR |
377 | bool m_hasFocus; |
378 | ||
e21f75bd RR |
379 | int m_dragCount; |
380 | wxPoint m_dragStart; | |
381 | ||
382 | // for double click logic | |
0a71f9e9 | 383 | unsigned int m_lineLastClicked, |
e21f75bd RR |
384 | m_lineBeforeLastClicked, |
385 | m_lineSelectSingleOnUp; | |
cab07038 | 386 | |
9861f022 RR |
387 | // the pen used to draw horiz/vertical rules |
388 | wxPen m_penRule; | |
389 | ||
a0f3af5f RR |
390 | private: |
391 | DECLARE_DYNAMIC_CLASS(wxDataViewMainWindow) | |
392 | DECLARE_EVENT_TABLE() | |
393 | }; | |
4ed7af08 | 394 | |
f554a14b | 395 | // --------------------------------------------------------- |
a0f3af5f | 396 | // wxGenericDataViewListModelNotifier |
f554a14b | 397 | // --------------------------------------------------------- |
a0f3af5f RR |
398 | |
399 | class wxGenericDataViewListModelNotifier: public wxDataViewListModelNotifier | |
4ed7af08 | 400 | { |
a0f3af5f RR |
401 | public: |
402 | wxGenericDataViewListModelNotifier( wxDataViewMainWindow *mainWindow ) | |
403 | { m_mainWindow = mainWindow; } | |
f554a14b | 404 | |
a0f3af5f RR |
405 | virtual bool RowAppended() |
406 | { return m_mainWindow->RowAppended(); } | |
407 | virtual bool RowPrepended() | |
408 | { return m_mainWindow->RowPrepended(); } | |
0a71f9e9 | 409 | virtual bool RowInserted( unsigned int before ) |
a0f3af5f | 410 | { return m_mainWindow->RowInserted( before ); } |
0a71f9e9 | 411 | virtual bool RowDeleted( unsigned int row ) |
a0f3af5f | 412 | { return m_mainWindow->RowDeleted( row ); } |
0a71f9e9 | 413 | virtual bool RowChanged( unsigned int row ) |
a0f3af5f | 414 | { return m_mainWindow->RowChanged( row ); } |
0a71f9e9 | 415 | virtual bool ValueChanged( unsigned int col, unsigned int row ) |
a0f3af5f | 416 | { return m_mainWindow->ValueChanged( col, row ); } |
0a71f9e9 | 417 | virtual bool RowsReordered( unsigned int *new_order ) |
a0f3af5f RR |
418 | { return m_mainWindow->RowsReordered( new_order ); } |
419 | virtual bool Cleared() | |
420 | { return m_mainWindow->Cleared(); } | |
f554a14b | 421 | |
a0f3af5f RR |
422 | wxDataViewMainWindow *m_mainWindow; |
423 | }; | |
4ed7af08 | 424 | |
f554a14b | 425 | // --------------------------------------------------------- |
baa9ebc4 | 426 | // wxDataViewRenderer |
f554a14b | 427 | // --------------------------------------------------------- |
4ed7af08 | 428 | |
baa9ebc4 | 429 | IMPLEMENT_ABSTRACT_CLASS(wxDataViewRenderer, wxDataViewRendererBase) |
4ed7af08 | 430 | |
c741d33f | 431 | wxDataViewRenderer::wxDataViewRenderer( const wxString &varianttype, |
9861f022 RR |
432 | wxDataViewCellMode mode, |
433 | int align) : | |
434 | wxDataViewRendererBase( varianttype, mode, align ) | |
4ed7af08 | 435 | { |
3d9d7cc4 | 436 | m_dc = NULL; |
9861f022 RR |
437 | m_align = align; |
438 | m_mode = mode; | |
4ed7af08 RR |
439 | } |
440 | ||
baa9ebc4 | 441 | wxDataViewRenderer::~wxDataViewRenderer() |
3d9d7cc4 RR |
442 | { |
443 | if (m_dc) | |
444 | delete m_dc; | |
445 | } | |
446 | ||
baa9ebc4 | 447 | wxDC *wxDataViewRenderer::GetDC() |
3d9d7cc4 RR |
448 | { |
449 | if (m_dc == NULL) | |
450 | { | |
451 | if (GetOwner() == NULL) | |
452 | return NULL; | |
453 | if (GetOwner()->GetOwner() == NULL) | |
454 | return NULL; | |
455 | m_dc = new wxClientDC( GetOwner()->GetOwner() ); | |
456 | } | |
f554a14b | 457 | |
3d9d7cc4 RR |
458 | return m_dc; |
459 | } | |
460 | ||
9861f022 | 461 | |
f554a14b | 462 | // --------------------------------------------------------- |
baa9ebc4 | 463 | // wxDataViewCustomRenderer |
f554a14b | 464 | // --------------------------------------------------------- |
3d9d7cc4 | 465 | |
baa9ebc4 | 466 | IMPLEMENT_ABSTRACT_CLASS(wxDataViewCustomRenderer, wxDataViewRenderer) |
3d9d7cc4 | 467 | |
baa9ebc4 | 468 | wxDataViewCustomRenderer::wxDataViewCustomRenderer( const wxString &varianttype, |
9861f022 RR |
469 | wxDataViewCellMode mode, int align ) : |
470 | wxDataViewRenderer( varianttype, mode, align ) | |
3d9d7cc4 RR |
471 | { |
472 | } | |
473 | ||
f554a14b | 474 | // --------------------------------------------------------- |
baa9ebc4 | 475 | // wxDataViewTextRenderer |
f554a14b | 476 | // --------------------------------------------------------- |
4ed7af08 | 477 | |
baa9ebc4 | 478 | IMPLEMENT_CLASS(wxDataViewTextRenderer, wxDataViewCustomRenderer) |
4ed7af08 | 479 | |
c741d33f | 480 | wxDataViewTextRenderer::wxDataViewTextRenderer( const wxString &varianttype, |
9861f022 RR |
481 | wxDataViewCellMode mode, int align ) : |
482 | wxDataViewCustomRenderer( varianttype, mode, align ) | |
4ed7af08 RR |
483 | { |
484 | } | |
485 | ||
baa9ebc4 | 486 | bool wxDataViewTextRenderer::SetValue( const wxVariant &value ) |
4ed7af08 | 487 | { |
90675b95 | 488 | m_text = value.GetString(); |
f554a14b | 489 | |
90675b95 | 490 | return true; |
4ed7af08 RR |
491 | } |
492 | ||
9861f022 | 493 | bool wxDataViewTextRenderer::GetValue( wxVariant& WXUNUSED(value) ) const |
4ed7af08 RR |
494 | { |
495 | return false; | |
496 | } | |
497 | ||
87f0efe2 | 498 | bool wxDataViewTextRenderer::Render( wxRect cell, wxDC *dc, int state ) |
3d9d7cc4 | 499 | { |
87f0efe2 RR |
500 | wxDataViewCtrl *view = GetOwner()->GetOwner(); |
501 | wxColour col = (state & wxDATAVIEW_CELL_SELECTED) ? | |
502 | wxSystemSettings::GetColour(wxSYS_COLOUR_HIGHLIGHTTEXT) : | |
503 | view->GetForegroundColour(); | |
504 | ||
505 | dc->SetTextForeground(col); | |
90675b95 RR |
506 | dc->DrawText( m_text, cell.x, cell.y ); |
507 | ||
508 | return true; | |
3d9d7cc4 RR |
509 | } |
510 | ||
9861f022 | 511 | wxSize wxDataViewTextRenderer::GetSize() const |
3d9d7cc4 | 512 | { |
9861f022 | 513 | const wxDataViewCtrl *view = GetView(); |
87f0efe2 RR |
514 | if (!m_text.empty()) |
515 | { | |
516 | int x,y; | |
517 | view->GetTextExtent( m_text, &x, &y ); | |
518 | return wxSize( x, y ); | |
519 | } | |
3d9d7cc4 RR |
520 | return wxSize(80,20); |
521 | } | |
522 | ||
2586d4a1 | 523 | // --------------------------------------------------------- |
baa9ebc4 | 524 | // wxDataViewBitmapRenderer |
2586d4a1 RR |
525 | // --------------------------------------------------------- |
526 | ||
baa9ebc4 | 527 | IMPLEMENT_CLASS(wxDataViewBitmapRenderer, wxDataViewCustomRenderer) |
2586d4a1 | 528 | |
c741d33f | 529 | wxDataViewBitmapRenderer::wxDataViewBitmapRenderer( const wxString &varianttype, |
9861f022 RR |
530 | wxDataViewCellMode mode, int align ) : |
531 | wxDataViewCustomRenderer( varianttype, mode, align ) | |
2586d4a1 RR |
532 | { |
533 | } | |
534 | ||
baa9ebc4 | 535 | bool wxDataViewBitmapRenderer::SetValue( const wxVariant &value ) |
2586d4a1 RR |
536 | { |
537 | if (value.GetType() == wxT("wxBitmap")) | |
538 | m_bitmap << value; | |
539 | if (value.GetType() == wxT("wxIcon")) | |
540 | m_icon << value; | |
541 | ||
542 | return true; | |
543 | } | |
544 | ||
9861f022 | 545 | bool wxDataViewBitmapRenderer::GetValue( wxVariant& WXUNUSED(value) ) const |
2586d4a1 RR |
546 | { |
547 | return false; | |
548 | } | |
549 | ||
baa9ebc4 | 550 | bool wxDataViewBitmapRenderer::Render( wxRect cell, wxDC *dc, int WXUNUSED(state) ) |
2586d4a1 RR |
551 | { |
552 | if (m_bitmap.Ok()) | |
553 | dc->DrawBitmap( m_bitmap, cell.x, cell.y ); | |
554 | else if (m_icon.Ok()) | |
555 | dc->DrawIcon( m_icon, cell.x, cell.y ); | |
556 | ||
557 | return true; | |
558 | } | |
559 | ||
9861f022 | 560 | wxSize wxDataViewBitmapRenderer::GetSize() const |
2586d4a1 RR |
561 | { |
562 | if (m_bitmap.Ok()) | |
563 | return wxSize( m_bitmap.GetWidth(), m_bitmap.GetHeight() ); | |
564 | else if (m_icon.Ok()) | |
565 | return wxSize( m_icon.GetWidth(), m_icon.GetHeight() ); | |
566 | ||
567 | return wxSize(16,16); | |
568 | } | |
569 | ||
f554a14b | 570 | // --------------------------------------------------------- |
baa9ebc4 | 571 | // wxDataViewToggleRenderer |
f554a14b | 572 | // --------------------------------------------------------- |
4ed7af08 | 573 | |
baa9ebc4 | 574 | IMPLEMENT_ABSTRACT_CLASS(wxDataViewToggleRenderer, wxDataViewCustomRenderer) |
4ed7af08 | 575 | |
baa9ebc4 | 576 | wxDataViewToggleRenderer::wxDataViewToggleRenderer( const wxString &varianttype, |
9861f022 RR |
577 | wxDataViewCellMode mode, int align ) : |
578 | wxDataViewCustomRenderer( varianttype, mode, align ) | |
4ed7af08 | 579 | { |
90675b95 | 580 | m_toggle = false; |
4ed7af08 RR |
581 | } |
582 | ||
baa9ebc4 | 583 | bool wxDataViewToggleRenderer::SetValue( const wxVariant &value ) |
4ed7af08 | 584 | { |
90675b95 | 585 | m_toggle = value.GetBool(); |
f554a14b | 586 | |
a8461d31 | 587 | return true; |
4ed7af08 RR |
588 | } |
589 | ||
9861f022 | 590 | bool wxDataViewToggleRenderer::GetValue( wxVariant &WXUNUSED(value) ) const |
4ed7af08 RR |
591 | { |
592 | return false; | |
593 | } | |
f554a14b | 594 | |
baa9ebc4 | 595 | bool wxDataViewToggleRenderer::Render( wxRect cell, wxDC *dc, int WXUNUSED(state) ) |
4ed7af08 | 596 | { |
90675b95 | 597 | // User wxRenderer here |
f554a14b | 598 | |
90675b95 RR |
599 | wxRect rect; |
600 | rect.x = cell.x + cell.width/2 - 10; | |
601 | rect.width = 20; | |
602 | rect.y = cell.y + cell.height/2 - 10; | |
603 | rect.height = 20; | |
120b9b05 | 604 | |
862d8041 | 605 | int flags = 0; |
90675b95 | 606 | if (m_toggle) |
862d8041 RR |
607 | flags |= wxCONTROL_CHECKED; |
608 | if (GetMode() != wxDATAVIEW_CELL_ACTIVATABLE) | |
609 | flags |= wxCONTROL_DISABLED; | |
610 | ||
90b903c2 | 611 | wxRendererNative::Get().DrawCheckBox( |
862d8041 RR |
612 | GetOwner()->GetOwner(), |
613 | *dc, | |
614 | rect, | |
615 | flags ); | |
f554a14b | 616 | |
90675b95 | 617 | return true; |
4ed7af08 RR |
618 | } |
619 | ||
c741d33f VZ |
620 | bool wxDataViewToggleRenderer::Activate( wxRect WXUNUSED(cell), |
621 | wxDataViewListModel *model, | |
87f0efe2 | 622 | unsigned int col, unsigned int row ) |
0fdc2321 RR |
623 | { |
624 | bool value = !m_toggle; | |
625 | wxVariant variant = value; | |
626 | model->SetValue( variant, col, row ); | |
f554a14b | 627 | model->ValueChanged( col, row ); |
0fdc2321 RR |
628 | return true; |
629 | } | |
630 | ||
9861f022 | 631 | wxSize wxDataViewToggleRenderer::GetSize() const |
4ed7af08 | 632 | { |
3d9d7cc4 | 633 | return wxSize(20,20); |
4ed7af08 RR |
634 | } |
635 | ||
f554a14b | 636 | // --------------------------------------------------------- |
baa9ebc4 | 637 | // wxDataViewProgressRenderer |
f554a14b | 638 | // --------------------------------------------------------- |
4ed7af08 | 639 | |
baa9ebc4 | 640 | IMPLEMENT_ABSTRACT_CLASS(wxDataViewProgressRenderer, wxDataViewCustomRenderer) |
4ed7af08 | 641 | |
baa9ebc4 | 642 | wxDataViewProgressRenderer::wxDataViewProgressRenderer( const wxString &label, |
9861f022 RR |
643 | const wxString &varianttype, wxDataViewCellMode mode, int align ) : |
644 | wxDataViewCustomRenderer( varianttype, mode, align ) | |
4ed7af08 RR |
645 | { |
646 | m_label = label; | |
647 | m_value = 0; | |
648 | } | |
649 | ||
baa9ebc4 | 650 | wxDataViewProgressRenderer::~wxDataViewProgressRenderer() |
4ed7af08 RR |
651 | { |
652 | } | |
653 | ||
baa9ebc4 | 654 | bool wxDataViewProgressRenderer::SetValue( const wxVariant &value ) |
4ed7af08 RR |
655 | { |
656 | m_value = (long) value; | |
f554a14b | 657 | |
4ed7af08 RR |
658 | if (m_value < 0) m_value = 0; |
659 | if (m_value > 100) m_value = 100; | |
f554a14b | 660 | |
4ed7af08 RR |
661 | return true; |
662 | } | |
f554a14b | 663 | |
9861f022 RR |
664 | bool wxDataViewProgressRenderer::GetValue( wxVariant &value ) const |
665 | { | |
666 | value = (long) m_value; | |
667 | return true; | |
668 | } | |
669 | ||
baa9ebc4 | 670 | bool wxDataViewProgressRenderer::Render( wxRect cell, wxDC *dc, int WXUNUSED(state) ) |
4ed7af08 RR |
671 | { |
672 | double pct = (double)m_value / 100.0; | |
673 | wxRect bar = cell; | |
674 | bar.width = (int)(cell.width * pct); | |
675 | dc->SetPen( *wxTRANSPARENT_PEN ); | |
676 | dc->SetBrush( *wxBLUE_BRUSH ); | |
677 | dc->DrawRectangle( bar ); | |
678 | ||
679 | dc->SetBrush( *wxTRANSPARENT_BRUSH ); | |
680 | dc->SetPen( *wxBLACK_PEN ); | |
681 | dc->DrawRectangle( cell ); | |
f554a14b | 682 | |
4ed7af08 RR |
683 | return true; |
684 | } | |
685 | ||
9861f022 | 686 | wxSize wxDataViewProgressRenderer::GetSize() const |
4ed7af08 RR |
687 | { |
688 | return wxSize(40,12); | |
689 | } | |
f554a14b WS |
690 | |
691 | // --------------------------------------------------------- | |
baa9ebc4 | 692 | // wxDataViewDateRenderer |
f554a14b | 693 | // --------------------------------------------------------- |
4ed7af08 | 694 | |
21ead767 VZ |
695 | #define wxUSE_DATE_RENDERER_POPUP (wxUSE_CALENDARCTRL && wxUSE_POPUPWIN) |
696 | ||
697 | #if wxUSE_DATE_RENDERER_POPUP | |
8d0ca292 | 698 | |
baa9ebc4 | 699 | class wxDataViewDateRendererPopupTransient: public wxPopupTransientWindow |
4ed7af08 | 700 | { |
f554a14b | 701 | public: |
baa9ebc4 | 702 | wxDataViewDateRendererPopupTransient( wxWindow* parent, wxDateTime *value, |
0a71f9e9 | 703 | wxDataViewListModel *model, unsigned int col, unsigned int row ) : |
4ed7af08 RR |
704 | wxPopupTransientWindow( parent, wxBORDER_SIMPLE ) |
705 | { | |
706 | m_model = model; | |
707 | m_col = col; | |
708 | m_row = row; | |
f554a14b | 709 | m_cal = new wxCalendarCtrl( this, wxID_ANY, *value ); |
4ed7af08 RR |
710 | wxBoxSizer *sizer = new wxBoxSizer( wxHORIZONTAL ); |
711 | sizer->Add( m_cal, 1, wxGROW ); | |
712 | SetSizer( sizer ); | |
713 | sizer->Fit( this ); | |
714 | } | |
f554a14b | 715 | |
4ed7af08 | 716 | void OnCalendar( wxCalendarEvent &event ); |
f554a14b | 717 | |
4ed7af08 | 718 | wxCalendarCtrl *m_cal; |
f554a14b | 719 | wxDataViewListModel *m_model; |
0a71f9e9 RR |
720 | unsigned int m_col; |
721 | unsigned int m_row; | |
f554a14b | 722 | |
a8461d31 PC |
723 | protected: |
724 | virtual void OnDismiss() | |
725 | { | |
726 | } | |
727 | ||
4ed7af08 RR |
728 | private: |
729 | DECLARE_EVENT_TABLE() | |
730 | }; | |
731 | ||
baa9ebc4 RR |
732 | BEGIN_EVENT_TABLE(wxDataViewDateRendererPopupTransient,wxPopupTransientWindow) |
733 | EVT_CALENDAR( wxID_ANY, wxDataViewDateRendererPopupTransient::OnCalendar ) | |
4ed7af08 RR |
734 | END_EVENT_TABLE() |
735 | ||
baa9ebc4 | 736 | void wxDataViewDateRendererPopupTransient::OnCalendar( wxCalendarEvent &event ) |
4ed7af08 RR |
737 | { |
738 | wxDateTime date = event.GetDate(); | |
739 | wxVariant value = date; | |
740 | m_model->SetValue( value, m_col, m_row ); | |
741 | m_model->ValueChanged( m_col, m_row ); | |
742 | DismissAndNotify(); | |
743 | } | |
744 | ||
21ead767 | 745 | #endif // wxUSE_DATE_RENDERER_POPUP |
8d0ca292 | 746 | |
baa9ebc4 | 747 | IMPLEMENT_ABSTRACT_CLASS(wxDataViewDateRenderer, wxDataViewCustomRenderer) |
4ed7af08 | 748 | |
baa9ebc4 | 749 | wxDataViewDateRenderer::wxDataViewDateRenderer( const wxString &varianttype, |
9861f022 RR |
750 | wxDataViewCellMode mode, int align ) : |
751 | wxDataViewCustomRenderer( varianttype, mode, align ) | |
4ed7af08 RR |
752 | { |
753 | } | |
f554a14b | 754 | |
baa9ebc4 | 755 | bool wxDataViewDateRenderer::SetValue( const wxVariant &value ) |
4ed7af08 RR |
756 | { |
757 | m_date = value.GetDateTime(); | |
f554a14b | 758 | |
4ed7af08 RR |
759 | return true; |
760 | } | |
761 | ||
9861f022 RR |
762 | bool wxDataViewDateRenderer::GetValue( wxVariant &value ) const |
763 | { | |
764 | value = m_date; | |
765 | return true; | |
766 | } | |
767 | ||
baa9ebc4 | 768 | bool wxDataViewDateRenderer::Render( wxRect cell, wxDC *dc, int WXUNUSED(state) ) |
4ed7af08 RR |
769 | { |
770 | dc->SetFont( GetOwner()->GetOwner()->GetFont() ); | |
771 | wxString tmp = m_date.FormatDate(); | |
772 | dc->DrawText( tmp, cell.x, cell.y ); | |
773 | ||
774 | return true; | |
775 | } | |
776 | ||
9861f022 | 777 | wxSize wxDataViewDateRenderer::GetSize() const |
4ed7af08 | 778 | { |
9861f022 | 779 | const wxDataViewCtrl* view = GetView(); |
4ed7af08 RR |
780 | wxString tmp = m_date.FormatDate(); |
781 | wxCoord x,y,d; | |
782 | view->GetTextExtent( tmp, &x, &y, &d ); | |
783 | return wxSize(x,y+d); | |
784 | } | |
785 | ||
c741d33f | 786 | bool wxDataViewDateRenderer::Activate( wxRect WXUNUSED(cell), wxDataViewListModel *model, |
87f0efe2 | 787 | unsigned int col, unsigned int row ) |
4ed7af08 RR |
788 | { |
789 | wxVariant variant; | |
790 | model->GetValue( variant, col, row ); | |
791 | wxDateTime value = variant.GetDateTime(); | |
792 | ||
21ead767 | 793 | #if wxUSE_DATE_RENDERER_POPUP |
baa9ebc4 | 794 | wxDataViewDateRendererPopupTransient *popup = new wxDataViewDateRendererPopupTransient( |
4ed7af08 RR |
795 | GetOwner()->GetOwner()->GetParent(), &value, model, col, row ); |
796 | wxPoint pos = wxGetMousePosition(); | |
797 | popup->Move( pos ); | |
798 | popup->Layout(); | |
799 | popup->Popup( popup->m_cal ); | |
21ead767 | 800 | #else // !wxUSE_DATE_RENDERER_POPUP |
8d0ca292 | 801 | wxMessageBox(value.Format()); |
21ead767 | 802 | #endif // wxUSE_DATE_RENDERER_POPUP/!wxUSE_DATE_RENDERER_POPUP |
4ed7af08 RR |
803 | return true; |
804 | } | |
805 | ||
f554a14b | 806 | // --------------------------------------------------------- |
4ed7af08 | 807 | // wxDataViewColumn |
f554a14b | 808 | // --------------------------------------------------------- |
4ed7af08 RR |
809 | |
810 | IMPLEMENT_ABSTRACT_CLASS(wxDataViewColumn, wxDataViewColumnBase) | |
811 | ||
c741d33f | 812 | wxDataViewColumn::wxDataViewColumn( const wxString &title, wxDataViewRenderer *cell, |
87f0efe2 RR |
813 | unsigned int model_column, |
814 | int width, wxAlignment align, int flags ) : | |
815 | wxDataViewColumnBase( title, cell, model_column, width, align, flags ) | |
4ed7af08 | 816 | { |
9861f022 RR |
817 | SetAlignment(align); |
818 | SetTitle(title); | |
819 | SetFlags(flags); | |
820 | ||
821 | Init(width < 0 ? wxDVC_DEFAULT_WIDTH : width); | |
4ed7af08 RR |
822 | } |
823 | ||
c741d33f | 824 | wxDataViewColumn::wxDataViewColumn( const wxBitmap &bitmap, wxDataViewRenderer *cell, |
87f0efe2 RR |
825 | unsigned int model_column, |
826 | int width, wxAlignment align, int flags ) : | |
827 | wxDataViewColumnBase( bitmap, cell, model_column, width, align, flags ) | |
07a84e7b | 828 | { |
9861f022 RR |
829 | SetAlignment(align); |
830 | SetFlags(flags); | |
831 | ||
832 | Init(width < 0 ? wxDVC_TOGGLE_DEFAULT_WIDTH : width); | |
07a84e7b RR |
833 | } |
834 | ||
9861f022 RR |
835 | wxDataViewColumn::~wxDataViewColumn() |
836 | { | |
837 | } | |
838 | ||
839 | void wxDataViewColumn::Init( int width ) | |
47cef10f | 840 | { |
87f0efe2 | 841 | m_width = width; |
9861f022 | 842 | m_minWidth = wxDVC_DEFAULT_MINWIDTH; |
47cef10f RR |
843 | } |
844 | ||
9861f022 | 845 | void wxDataViewColumn::SetResizeable( bool resizeable ) |
31fb32e1 | 846 | { |
9861f022 RR |
847 | if (resizeable) |
848 | m_flags |= wxDATAVIEW_COL_RESIZABLE; | |
849 | else | |
850 | m_flags &= ~wxDATAVIEW_COL_RESIZABLE; | |
851 | } | |
852 | ||
853 | void wxDataViewColumn::SetHidden( bool hidden ) | |
854 | { | |
855 | if (hidden) | |
856 | m_flags |= wxDATAVIEW_COL_HIDDEN; | |
857 | else | |
858 | m_flags &= ~wxDATAVIEW_COL_HIDDEN; | |
859 | ||
860 | // tell our owner to e.g. update its scrollbars: | |
861 | if (GetOwner()) | |
862 | GetOwner()->OnColumnChange(); | |
863 | } | |
864 | ||
865 | void wxDataViewColumn::SetSortable( bool sortable ) | |
866 | { | |
867 | if (sortable) | |
868 | m_flags |= wxDATAVIEW_COL_SORTABLE; | |
869 | else | |
870 | m_flags &= ~wxDATAVIEW_COL_SORTABLE; | |
31fb32e1 RR |
871 | } |
872 | ||
47cef10f RR |
873 | void wxDataViewColumn::SetSortOrder( bool WXUNUSED(ascending) ) |
874 | { | |
875 | // TODO | |
876 | } | |
877 | ||
87f0efe2 | 878 | bool wxDataViewColumn::IsSortOrderAscending() const |
31fb32e1 RR |
879 | { |
880 | // TODO | |
881 | return true; | |
882 | } | |
883 | ||
9861f022 | 884 | void wxDataViewColumn::SetInternalWidth( int width ) |
4ed7af08 | 885 | { |
9861f022 | 886 | m_width = width; |
f554a14b | 887 | |
9861f022 RR |
888 | // the scrollbars of the wxDataViewCtrl needs to be recalculated! |
889 | if (m_owner && m_owner->m_clientArea) | |
890 | m_owner->m_clientArea->RecalculateDisplay(); | |
4ed7af08 RR |
891 | } |
892 | ||
9861f022 | 893 | void wxDataViewColumn::SetWidth( int width ) |
47cef10f | 894 | { |
9861f022 | 895 | m_owner->m_headerArea->UpdateDisplay(); |
47cef10f | 896 | |
9861f022 | 897 | SetInternalWidth(width); |
47cef10f RR |
898 | } |
899 | ||
533544f2 | 900 | |
4ed7af08 | 901 | //----------------------------------------------------------------------------- |
87f0efe2 | 902 | // wxDataViewHeaderWindowBase |
4ed7af08 RR |
903 | //----------------------------------------------------------------------------- |
904 | ||
87f0efe2 RR |
905 | void wxDataViewHeaderWindowBase::SendEvent(wxEventType type, unsigned int n) |
906 | { | |
907 | wxWindow *parent = GetParent(); | |
908 | wxDataViewEvent le(type, parent->GetId()); | |
909 | ||
910 | le.SetEventObject(parent); | |
911 | le.SetColumn(n); | |
912 | le.SetDataViewColumn(GetColumn(n)); | |
913 | le.SetModel(GetOwner()->GetModel()); | |
914 | ||
915 | // for events created by wxDataViewHeaderWindow the | |
916 | // row / value fields are not valid | |
917 | ||
918 | parent->GetEventHandler()->ProcessEvent(le); | |
919 | } | |
920 | ||
921 | #if defined(__WXMSW__) && USE_NATIVE_HEADER_WINDOW | |
922 | ||
87f0efe2 | 923 | // implemented in msw/listctrl.cpp: |
a68962fc | 924 | int WXDLLIMPEXP_CORE wxMSWGetColumnClicked(NMHDR *nmhdr, POINT *ptClick); |
87f0efe2 | 925 | |
5d3f234b | 926 | IMPLEMENT_ABSTRACT_CLASS(wxDataViewHeaderWindowMSW, wxWindow) |
87f0efe2 RR |
927 | |
928 | bool wxDataViewHeaderWindowMSW::Create( wxDataViewCtrl *parent, wxWindowID id, | |
c741d33f | 929 | const wxPoint &pos, const wxSize &size, |
87f0efe2 RR |
930 | const wxString &name ) |
931 | { | |
932 | m_owner = parent; | |
933 | ||
934 | if ( !CreateControl(parent, id, pos, size, 0, wxDefaultValidator, name) ) | |
935 | return false; | |
936 | ||
937 | int x = pos.x == wxDefaultCoord ? 0 : pos.x, | |
938 | y = pos.y == wxDefaultCoord ? 0 : pos.y, | |
939 | w = size.x == wxDefaultCoord ? 1 : size.x, | |
940 | h = size.y == wxDefaultCoord ? 22 : size.y; | |
941 | ||
942 | // create the native WC_HEADER window: | |
943 | WXHWND hwndParent = (HWND)parent->GetHandle(); | |
944 | WXDWORD msStyle = WS_CHILD | HDS_BUTTONS | HDS_HORZ | HDS_HOTTRACK | HDS_FULLDRAG; | |
c741d33f VZ |
945 | m_hWnd = CreateWindowEx(0, |
946 | WC_HEADER, | |
947 | (LPCTSTR) NULL, | |
87f0efe2 RR |
948 | msStyle, |
949 | x, y, w, h, | |
c741d33f VZ |
950 | (HWND)hwndParent, |
951 | (HMENU)-1, | |
952 | wxGetInstance(), | |
87f0efe2 | 953 | (LPVOID) NULL); |
c741d33f | 954 | if (m_hWnd == NULL) |
87f0efe2 RR |
955 | { |
956 | wxLogLastError(_T("CreateWindowEx")); | |
957 | return false; | |
958 | } | |
959 | ||
5d3f234b | 960 | // we need to subclass the m_hWnd to force wxWindow::HandleNotify |
87f0efe2 | 961 | // to call wxDataViewHeaderWindow::MSWOnNotify |
5d3f234b | 962 | SubclassWin(m_hWnd); |
87f0efe2 | 963 | |
c741d33f | 964 | // the following is required to get the default win's font for |
9861f022 RR |
965 | // header windows and must be done befor sending the HDM_LAYOUT msg |
966 | SetFont(GetFont()); | |
87f0efe2 | 967 | |
9861f022 RR |
968 | RECT rcParent; |
969 | HDLAYOUT hdl; | |
970 | WINDOWPOS wp; | |
87f0efe2 | 971 | |
c741d33f VZ |
972 | // Retrieve the bounding rectangle of the parent window's |
973 | // client area, and then request size and position values | |
974 | // from the header control. | |
975 | ::GetClientRect((HWND)hwndParent, &rcParent); | |
976 | ||
977 | hdl.prc = &rcParent; | |
978 | hdl.pwpos = ℘ | |
979 | if (!SendMessage((HWND)m_hWnd, HDM_LAYOUT, 0, (LPARAM) &hdl)) | |
87f0efe2 RR |
980 | { |
981 | wxLogLastError(_T("SendMessage")); | |
982 | return false; | |
983 | } | |
c741d33f VZ |
984 | |
985 | // Set the size, position, and visibility of the header control. | |
986 | SetWindowPos((HWND)m_hWnd, | |
987 | wp.hwndInsertAfter, | |
988 | wp.x, wp.y, | |
989 | wp.cx, wp.cy, | |
87f0efe2 RR |
990 | wp.flags | SWP_SHOWWINDOW); |
991 | ||
992 | // set our size hints: wxDataViewCtrl will put this wxWindow inside | |
993 | // a wxBoxSizer and in order to avoid super-big header windows, | |
994 | // we need to set our height as fixed | |
995 | SetMinSize(wxSize(-1, wp.cy)); | |
996 | SetMaxSize(wxSize(-1, wp.cy)); | |
997 | ||
87f0efe2 RR |
998 | return true; |
999 | } | |
1000 | ||
1001 | wxDataViewHeaderWindowMSW::~wxDataViewHeaderWindow() | |
1002 | { | |
5d3f234b | 1003 | UnsubclassWin(); |
87f0efe2 RR |
1004 | } |
1005 | ||
1006 | void wxDataViewHeaderWindowMSW::UpdateDisplay() | |
1007 | { | |
1008 | // remove old columns | |
914e6945 | 1009 | for (int j=0, max=Header_GetItemCount((HWND)m_hWnd); j < max; j++) |
87f0efe2 | 1010 | Header_DeleteItem((HWND)m_hWnd, 0); |
c741d33f | 1011 | |
87f0efe2 | 1012 | // add the updated array of columns to the header control |
9861f022 RR |
1013 | unsigned int cols = GetOwner()->GetColumnCount(); |
1014 | unsigned int added = 0; | |
87f0efe2 RR |
1015 | for (unsigned int i = 0; i < cols; i++) |
1016 | { | |
1017 | wxDataViewColumn *col = GetColumn( i ); | |
1018 | if (col->IsHidden()) | |
1019 | continue; // don't add it! | |
1020 | ||
1021 | HDITEM hdi; | |
1022 | hdi.mask = HDI_TEXT | HDI_FORMAT | HDI_WIDTH; | |
fab3f50e | 1023 | hdi.pszText = (wxChar *) col->GetTitle().wx_str(); |
87f0efe2 RR |
1024 | hdi.cxy = col->GetWidth(); |
1025 | hdi.cchTextMax = sizeof(hdi.pszText)/sizeof(hdi.pszText[0]); | |
1026 | hdi.fmt = HDF_LEFT | HDF_STRING; | |
9861f022 RR |
1027 | |
1028 | // lParam is reserved for application's use: | |
1029 | // we store there the column index to use it later in MSWOnNotify | |
1030 | // (since columns may have been hidden) | |
1031 | hdi.lParam = (LPARAM)i; | |
1032 | ||
1033 | // the native wxMSW implementation of the header window | |
c741d33f | 1034 | // draws the column separator COLUMN_WIDTH_OFFSET pixels |
9861f022 RR |
1035 | // on the right: to correct this effect we make the column |
1036 | // exactly COLUMN_WIDTH_OFFSET wider (for the first column): | |
1037 | if (i == 0) | |
1038 | hdi.cxy += COLUMN_WIDTH_OFFSET; | |
1039 | ||
1040 | switch (col->GetAlignment()) | |
1041 | { | |
1042 | case wxALIGN_LEFT: | |
1043 | hdi.fmt |= HDF_LEFT; | |
1044 | break; | |
1045 | case wxALIGN_CENTER: | |
1046 | case wxALIGN_CENTER_HORIZONTAL: | |
1047 | hdi.fmt |= HDF_CENTER; | |
1048 | break; | |
1049 | case wxALIGN_RIGHT: | |
1050 | hdi.fmt |= HDF_RIGHT; | |
1051 | break; | |
5d3f234b RR |
1052 | |
1053 | default: | |
1054 | // such alignment is not allowed for the column header! | |
1055 | wxFAIL; | |
9861f022 | 1056 | } |
c741d33f VZ |
1057 | |
1058 | SendMessage((HWND)m_hWnd, HDM_INSERTITEM, | |
1059 | (WPARAM)added, (LPARAM)&hdi); | |
9861f022 | 1060 | added++; |
87f0efe2 RR |
1061 | } |
1062 | } | |
1063 | ||
9861f022 RR |
1064 | unsigned int wxDataViewHeaderWindowMSW::GetColumnIdxFromHeader(NMHEADER *nmHDR) |
1065 | { | |
1066 | unsigned int idx; | |
1067 | ||
1068 | // NOTE: we don't just return nmHDR->iItem because when there are | |
1069 | // hidden columns, nmHDR->iItem may be different from | |
1070 | // nmHDR->pitem->lParam | |
1071 | ||
1072 | if (nmHDR->pitem && nmHDR->pitem->mask & HDI_LPARAM) | |
1073 | { | |
1074 | idx = (unsigned int)nmHDR->pitem->lParam; | |
1075 | return idx; | |
1076 | } | |
1077 | ||
1078 | HDITEM item; | |
1079 | item.mask = HDI_LPARAM; | |
1080 | Header_GetItem((HWND)m_hWnd, nmHDR->iItem, &item); | |
1081 | ||
1082 | return (unsigned int)item.lParam; | |
1083 | } | |
1084 | ||
87f0efe2 RR |
1085 | bool wxDataViewHeaderWindowMSW::MSWOnNotify(int idCtrl, WXLPARAM lParam, WXLPARAM *result) |
1086 | { | |
1087 | NMHDR *nmhdr = (NMHDR *)lParam; | |
1088 | ||
1089 | // is it a message from the header? | |
1090 | if ( nmhdr->hwndFrom != (HWND)m_hWnd ) | |
1091 | return wxWindow::MSWOnNotify(idCtrl, lParam, result); | |
1092 | ||
1093 | NMHEADER *nmHDR = (NMHEADER *)nmhdr; | |
1094 | switch ( nmhdr->code ) | |
1095 | { | |
1096 | case HDN_BEGINTRACK: | |
1097 | // user has started to resize a column: | |
1098 | // do we need to veto it? | |
1099 | if (!GetColumn(nmHDR->iItem)->IsResizeable()) | |
1100 | { | |
1101 | // veto it! | |
1102 | *result = TRUE; | |
1103 | } | |
1104 | break; | |
1105 | ||
1106 | case HDN_BEGINDRAG: | |
1107 | // user has started to reorder a column | |
1108 | break; | |
1109 | ||
9861f022 | 1110 | case HDN_ITEMCHANGING: |
c741d33f | 1111 | if (nmHDR->pitem != NULL && |
9861f022 RR |
1112 | (nmHDR->pitem->mask & HDI_WIDTH) != 0) |
1113 | { | |
1114 | int minWidth = GetColumnFromHeader(nmHDR)->GetMinWidth(); | |
1115 | if (nmHDR->pitem->cxy < minWidth) | |
1116 | { | |
c741d33f | 1117 | // do not allow the user to resize this column under |
9861f022 RR |
1118 | // its minimal width: |
1119 | *result = TRUE; | |
1120 | } | |
1121 | } | |
1122 | break; | |
1123 | ||
87f0efe2 RR |
1124 | case HDN_ITEMCHANGED: // user is resizing a column |
1125 | case HDN_ENDTRACK: // user has finished resizing a column | |
1126 | case HDN_ENDDRAG: // user has finished reordering a column | |
1127 | ||
1128 | // update the width of the modified column: | |
c741d33f | 1129 | if (nmHDR->pitem != NULL && |
9861f022 RR |
1130 | (nmHDR->pitem->mask & HDI_WIDTH) != 0) |
1131 | { | |
1132 | unsigned int idx = GetColumnIdxFromHeader(nmHDR); | |
1133 | unsigned int w = nmHDR->pitem->cxy; | |
1134 | wxDataViewColumn *col = GetColumn(idx); | |
1135 | ||
1136 | // see UpdateDisplay() for more info about COLUMN_WIDTH_OFFSET | |
1137 | if (idx == 0 && w > COLUMN_WIDTH_OFFSET) | |
1138 | w -= COLUMN_WIDTH_OFFSET; | |
1139 | ||
1140 | if (w >= (unsigned)col->GetMinWidth()) | |
1141 | col->SetInternalWidth(w); | |
1142 | } | |
87f0efe2 RR |
1143 | break; |
1144 | ||
1145 | case HDN_ITEMCLICK: | |
1146 | { | |
9861f022 | 1147 | unsigned int idx = GetColumnIdxFromHeader(nmHDR); |
c741d33f | 1148 | wxEventType evt = nmHDR->iButton == 0 ? |
87f0efe2 RR |
1149 | wxEVT_COMMAND_DATAVIEW_COLUMN_HEADER_CLICK : |
1150 | wxEVT_COMMAND_DATAVIEW_COLUMN_HEADER_RIGHT_CLICK; | |
9861f022 | 1151 | SendEvent(evt, idx); |
87f0efe2 RR |
1152 | } |
1153 | break; | |
1154 | ||
1155 | case NM_RCLICK: | |
1156 | { | |
1157 | // NOTE: for some reason (i.e. for a bug in Windows) | |
1158 | // the HDN_ITEMCLICK notification is not sent on | |
1159 | // right clicks, so we need to handle NM_RCLICK | |
1160 | ||
1161 | POINT ptClick; | |
9861f022 | 1162 | int column = wxMSWGetColumnClicked(nmhdr, &ptClick); |
87f0efe2 | 1163 | if (column != wxNOT_FOUND) |
9861f022 RR |
1164 | { |
1165 | HDITEM item; | |
1166 | item.mask = HDI_LPARAM; | |
1167 | Header_GetItem((HWND)m_hWnd, column, &item); | |
1168 | ||
1169 | // 'idx' may be different from 'column' if there are | |
1170 | // hidden columns... | |
1171 | unsigned int idx = (unsigned int)item.lParam; | |
87f0efe2 | 1172 | SendEvent(wxEVT_COMMAND_DATAVIEW_COLUMN_HEADER_RIGHT_CLICK, |
9861f022 RR |
1173 | idx); |
1174 | } | |
87f0efe2 RR |
1175 | } |
1176 | break; | |
1177 | ||
1178 | case HDN_GETDISPINFOW: | |
1179 | // see wxListCtrl::MSWOnNotify for more info! | |
1180 | break; | |
1181 | ||
1182 | case HDN_ITEMDBLCLICK: | |
1183 | { | |
9861f022 | 1184 | unsigned int idx = GetColumnIdxFromHeader(nmHDR); |
87f0efe2 RR |
1185 | int w = GetOwner()->GetBestColumnWidth(idx); |
1186 | ||
1187 | // update the native control: | |
1188 | HDITEM hd; | |
1189 | ZeroMemory(&hd, sizeof(hd)); | |
1190 | hd.mask = HDI_WIDTH; | |
1191 | hd.cxy = w; | |
c741d33f | 1192 | Header_SetItem(GetHwnd(), |
9861f022 RR |
1193 | nmHDR->iItem, // NOTE: we don't want 'idx' here! |
1194 | &hd); | |
87f0efe2 RR |
1195 | |
1196 | // update the wxDataViewColumn class: | |
9861f022 | 1197 | GetColumn(idx)->SetInternalWidth(w); |
87f0efe2 RR |
1198 | } |
1199 | break; | |
1200 | ||
1201 | default: | |
1202 | return wxWindow::MSWOnNotify(idCtrl, lParam, result); | |
1203 | } | |
1204 | ||
1205 | return true; | |
1206 | } | |
1207 | ||
c741d33f | 1208 | void wxDataViewHeaderWindowMSW::ScrollWindow(int WXUNUSED(dx), int WXUNUSED(dy), |
87f0efe2 RR |
1209 | const wxRect *WXUNUSED(rect)) |
1210 | { | |
1211 | wxSize ourSz = GetClientSize(); | |
1212 | wxSize ownerSz = m_owner->GetClientSize(); | |
1213 | ||
1214 | // where should the (logical) origin of this window be placed? | |
1215 | int x1 = 0, y1 = 0; | |
1216 | m_owner->CalcUnscrolledPosition(0, 0, &x1, &y1); | |
4ed7af08 | 1217 | |
c741d33f VZ |
1218 | // put this window on top of our parent and |
1219 | SetWindowPos((HWND)m_hWnd, HWND_TOP, -x1, 0, | |
1220 | ownerSz.GetWidth() + x1, ourSz.GetHeight(), | |
87f0efe2 RR |
1221 | SWP_SHOWWINDOW); |
1222 | } | |
1223 | ||
c741d33f VZ |
1224 | void wxDataViewHeaderWindowMSW::DoSetSize(int WXUNUSED(x), int WXUNUSED(y), |
1225 | int WXUNUSED(w), int WXUNUSED(h), | |
9861f022 RR |
1226 | int WXUNUSED(f)) |
1227 | { | |
1228 | // the wxDataViewCtrl's internal wxBoxSizer will call this function when | |
1229 | // the wxDataViewCtrl window gets resized: the following dummy call | |
1230 | // to ScrollWindow() is required in order to get this header window | |
1231 | // correctly repainted when it's (horizontally) scrolled: | |
1232 | ||
1233 | ScrollWindow(0, 0); | |
1234 | } | |
1235 | ||
87f0efe2 RR |
1236 | #else // !defined(__WXMSW__) |
1237 | ||
1238 | IMPLEMENT_ABSTRACT_CLASS(wxGenericDataViewHeaderWindow, wxWindow) | |
1239 | BEGIN_EVENT_TABLE(wxGenericDataViewHeaderWindow, wxWindow) | |
1240 | EVT_PAINT (wxGenericDataViewHeaderWindow::OnPaint) | |
1241 | EVT_MOUSE_EVENTS (wxGenericDataViewHeaderWindow::OnMouse) | |
1242 | EVT_SET_FOCUS (wxGenericDataViewHeaderWindow::OnSetFocus) | |
4ed7af08 RR |
1243 | END_EVENT_TABLE() |
1244 | ||
87f0efe2 | 1245 | bool wxGenericDataViewHeaderWindow::Create(wxDataViewCtrl *parent, wxWindowID id, |
c741d33f VZ |
1246 | const wxPoint &pos, const wxSize &size, |
1247 | const wxString &name ) | |
4ed7af08 | 1248 | { |
87f0efe2 | 1249 | m_owner = parent; |
4b3feaa7 | 1250 | |
87f0efe2 RR |
1251 | if (!wxDataViewHeaderWindowBase::Create(parent, id, pos, size, name)) |
1252 | return false; | |
f554a14b | 1253 | |
4ed7af08 | 1254 | wxVisualAttributes attr = wxPanel::GetClassDefaultAttributes(); |
2e992e06 | 1255 | SetBackgroundStyle( wxBG_STYLE_CUSTOM ); |
4ed7af08 RR |
1256 | SetOwnForegroundColour( attr.colFg ); |
1257 | SetOwnBackgroundColour( attr.colBg ); | |
1258 | if (!m_hasFont) | |
1259 | SetOwnFont( attr.font ); | |
4ed7af08 | 1260 | |
87f0efe2 RR |
1261 | // set our size hints: wxDataViewCtrl will put this wxWindow inside |
1262 | // a wxBoxSizer and in order to avoid super-big header windows, | |
1263 | // we need to set our height as fixed | |
1264 | SetMinSize(wxSize(-1, HEADER_WINDOW_HEIGHT)); | |
1265 | SetMaxSize(wxSize(-1, HEADER_WINDOW_HEIGHT)); | |
1266 | ||
1267 | return true; | |
4ed7af08 RR |
1268 | } |
1269 | ||
87f0efe2 | 1270 | void wxGenericDataViewHeaderWindow::OnPaint( wxPaintEvent &WXUNUSED(event) ) |
4ed7af08 | 1271 | { |
4b3feaa7 RR |
1272 | int w, h; |
1273 | GetClientSize( &w, &h ); | |
1274 | ||
2e992e06 VZ |
1275 | wxAutoBufferedPaintDC dc( this ); |
1276 | ||
1277 | dc.SetBackground(GetBackgroundColour()); | |
1278 | dc.Clear(); | |
f554a14b | 1279 | |
4ed7af08 RR |
1280 | int xpix; |
1281 | m_owner->GetScrollPixelsPerUnit( &xpix, NULL ); | |
1282 | ||
1283 | int x; | |
1284 | m_owner->GetViewStart( &x, NULL ); | |
1285 | ||
1286 | // account for the horz scrollbar offset | |
1287 | dc.SetDeviceOrigin( -x * xpix, 0 ); | |
f554a14b | 1288 | |
4ed7af08 | 1289 | dc.SetFont( GetFont() ); |
f554a14b | 1290 | |
9861f022 | 1291 | unsigned int cols = GetOwner()->GetColumnCount(); |
0a71f9e9 | 1292 | unsigned int i; |
4b3feaa7 RR |
1293 | int xpos = 0; |
1294 | for (i = 0; i < cols; i++) | |
1295 | { | |
87f0efe2 RR |
1296 | wxDataViewColumn *col = GetColumn( i ); |
1297 | if (col->IsHidden()) | |
9861f022 | 1298 | continue; // skip it! |
f554a14b | 1299 | |
87f0efe2 | 1300 | int cw = col->GetWidth(); |
4b3feaa7 | 1301 | int ch = h; |
4b3feaa7 RR |
1302 | |
1303 | wxRendererNative::Get().DrawHeaderButton | |
1304 | ( | |
1305 | this, | |
1306 | dc, | |
72664514 | 1307 | wxRect(xpos, 0, cw, ch-1), |
4b3feaa7 RR |
1308 | m_parent->IsEnabled() ? 0 |
1309 | : (int)wxCONTROL_DISABLED | |
1310 | ); | |
1311 | ||
9861f022 RR |
1312 | // align as required the column title: |
1313 | int x = xpos; | |
1314 | wxSize titleSz = dc.GetTextExtent(col->GetTitle()); | |
1315 | switch (col->GetAlignment()) | |
1316 | { | |
1317 | case wxALIGN_LEFT: | |
1318 | x += HEADER_HORIZ_BORDER; | |
1319 | break; | |
1320 | case wxALIGN_CENTER: | |
1321 | case wxALIGN_CENTER_HORIZONTAL: | |
1322 | x += (cw - titleSz.GetWidth() - 2 * HEADER_HORIZ_BORDER)/2; | |
1323 | break; | |
1324 | case wxALIGN_RIGHT: | |
1325 | x += cw - titleSz.GetWidth() - HEADER_HORIZ_BORDER; | |
1326 | break; | |
1327 | } | |
1328 | ||
1329 | // always center the title vertically: | |
1330 | int y = wxMax((ch - titleSz.GetHeight()) / 2, HEADER_VERT_BORDER); | |
1331 | ||
c741d33f | 1332 | dc.SetClippingRegion( xpos+HEADER_HORIZ_BORDER, |
9861f022 RR |
1333 | HEADER_VERT_BORDER, |
1334 | wxMax(cw - 2 * HEADER_HORIZ_BORDER, 1), // width | |
1335 | wxMax(ch - 2 * HEADER_VERT_BORDER, 1)); // height | |
1336 | dc.DrawText( col->GetTitle(), x, y ); | |
1337 | dc.DestroyClippingRegion(); | |
f554a14b | 1338 | |
87f0efe2 | 1339 | xpos += cw; |
4b3feaa7 | 1340 | } |
4ed7af08 RR |
1341 | } |
1342 | ||
87f0efe2 | 1343 | void wxGenericDataViewHeaderWindow::OnSetFocus( wxFocusEvent &event ) |
4ed7af08 | 1344 | { |
87f0efe2 RR |
1345 | GetParent()->SetFocus(); |
1346 | event.Skip(); | |
4ed7af08 RR |
1347 | } |
1348 | ||
87f0efe2 | 1349 | void wxGenericDataViewHeaderWindow::OnMouse( wxMouseEvent &event ) |
4ed7af08 | 1350 | { |
87f0efe2 RR |
1351 | // we want to work with logical coords |
1352 | int x; | |
1353 | m_owner->CalcUnscrolledPosition(event.GetX(), 0, &x, NULL); | |
1354 | int y = event.GetY(); | |
1355 | ||
1356 | if (m_isDragging) | |
1357 | { | |
c741d33f | 1358 | // we don't draw the line beyond our window, |
87f0efe2 RR |
1359 | // but we allow dragging it there |
1360 | int w = 0; | |
1361 | GetClientSize( &w, NULL ); | |
1362 | m_owner->CalcUnscrolledPosition(w, 0, &w, NULL); | |
1363 | w -= 6; | |
1364 | ||
1365 | // erase the line if it was drawn | |
c741d33f | 1366 | if (m_currentX < w) |
87f0efe2 RR |
1367 | DrawCurrent(); |
1368 | ||
c741d33f | 1369 | if (event.ButtonUp()) |
87f0efe2 RR |
1370 | { |
1371 | m_isDragging = false; | |
c741d33f | 1372 | if (HasCapture()) |
87f0efe2 RR |
1373 | ReleaseMouse(); |
1374 | ||
1375 | m_dirty = true; | |
1376 | ||
9861f022 | 1377 | GetColumn(m_column)->SetWidth(m_currentX - m_minX); |
87f0efe2 RR |
1378 | |
1379 | Refresh(); | |
1380 | GetOwner()->Refresh(); | |
1381 | } | |
1382 | else | |
1383 | { | |
1384 | m_currentX = wxMax(m_minX + 7, x); | |
1385 | ||
1386 | // draw in the new location | |
1387 | if (m_currentX < w) DrawCurrent(); | |
1388 | } | |
1389 | ||
1390 | } | |
1391 | else // not dragging | |
1392 | { | |
1393 | m_minX = 0; | |
1394 | m_column = wxNOT_FOUND; | |
1395 | ||
1396 | bool hit_border = false; | |
1397 | ||
1398 | // end of the current column | |
1399 | int xpos = 0; | |
1400 | ||
1401 | // find the column where this event occured | |
9861f022 | 1402 | int countCol = m_owner->GetColumnCount(); |
c741d33f | 1403 | for (int column = 0; column < countCol; column++) |
87f0efe2 RR |
1404 | { |
1405 | wxDataViewColumn *p = GetColumn(column); | |
1406 | ||
c741d33f | 1407 | if (p->IsHidden()) |
87f0efe2 RR |
1408 | continue; // skip if not shown |
1409 | ||
1410 | xpos += p->GetWidth(); | |
1411 | m_column = column; | |
c741d33f | 1412 | if ((abs(x-xpos) < 3) && (y < 22)) |
87f0efe2 RR |
1413 | { |
1414 | hit_border = true; | |
1415 | break; | |
1416 | } | |
1417 | ||
c741d33f | 1418 | if (x < xpos) |
87f0efe2 RR |
1419 | { |
1420 | // inside the column | |
1421 | break; | |
1422 | } | |
1423 | ||
1424 | m_minX = xpos; | |
1425 | } | |
1426 | ||
1427 | if (m_column == wxNOT_FOUND) | |
1428 | return; | |
1429 | ||
1430 | bool resizeable = GetColumn(m_column)->IsResizeable(); | |
1431 | if (event.LeftDClick() && resizeable) | |
1432 | { | |
9861f022 | 1433 | GetColumn(m_column)->SetWidth(GetOwner()->GetBestColumnWidth(m_column)); |
87f0efe2 RR |
1434 | Refresh(); |
1435 | } | |
1436 | else if (event.LeftDown() || event.RightUp()) | |
1437 | { | |
c741d33f | 1438 | if (hit_border && event.LeftDown() && resizeable) |
87f0efe2 RR |
1439 | { |
1440 | m_isDragging = true; | |
1441 | CaptureMouse(); | |
1442 | m_currentX = x; | |
1443 | DrawCurrent(); | |
1444 | } | |
1445 | else // click on a column | |
1446 | { | |
c741d33f | 1447 | wxEventType evt = event.LeftDown() ? |
87f0efe2 RR |
1448 | wxEVT_COMMAND_DATAVIEW_COLUMN_HEADER_CLICK : |
1449 | wxEVT_COMMAND_DATAVIEW_COLUMN_HEADER_RIGHT_CLICK; | |
1450 | SendEvent(evt, m_column); | |
1451 | } | |
1452 | } | |
1453 | else if (event.Moving()) | |
1454 | { | |
c741d33f | 1455 | if (hit_border && resizeable) |
87f0efe2 RR |
1456 | m_currentCursor = m_resizeCursor; |
1457 | else | |
1458 | m_currentCursor = wxSTANDARD_CURSOR; | |
1459 | ||
1460 | SetCursor(*m_currentCursor); | |
1461 | } | |
1462 | } | |
1463 | } | |
1464 | ||
1465 | void wxGenericDataViewHeaderWindow::DrawCurrent() | |
1466 | { | |
1467 | int x1 = m_currentX; | |
1468 | int y1 = 0; | |
1469 | ClientToScreen (&x1, &y1); | |
1470 | ||
1471 | int x2 = m_currentX-1; | |
1472 | #ifdef __WXMSW__ | |
1473 | ++x2; // but why ???? | |
1474 | #endif | |
1475 | int y2 = 0; | |
1476 | m_owner->GetClientSize( NULL, &y2 ); | |
1477 | m_owner->ClientToScreen( &x2, &y2 ); | |
1478 | ||
1479 | wxScreenDC dc; | |
9861f022 RR |
1480 | dc.SetLogicalFunction(wxINVERT); |
1481 | dc.SetPen(m_penCurrent); | |
1482 | dc.SetBrush(*wxTRANSPARENT_BRUSH); | |
87f0efe2 | 1483 | AdjustDC(dc); |
9861f022 | 1484 | dc.DrawLine(x1, y1, x2, y2); |
87f0efe2 RR |
1485 | } |
1486 | ||
1487 | void wxGenericDataViewHeaderWindow::AdjustDC(wxDC& dc) | |
1488 | { | |
1489 | int xpix, x; | |
1490 | ||
1491 | m_owner->GetScrollPixelsPerUnit( &xpix, NULL ); | |
1492 | m_owner->GetViewStart( &x, NULL ); | |
1493 | ||
1494 | // shift the DC origin to match the position of the main window horizontal | |
1495 | // scrollbar: this allows us to always use logical coords | |
1496 | dc.SetDeviceOrigin( -x * xpix, 0 ); | |
4ed7af08 RR |
1497 | } |
1498 | ||
87f0efe2 RR |
1499 | #endif // defined(__WXMSW__) |
1500 | ||
0fcce6b9 RR |
1501 | //----------------------------------------------------------------------------- |
1502 | // wxDataViewRenameTimer | |
1503 | //----------------------------------------------------------------------------- | |
1504 | ||
1505 | wxDataViewRenameTimer::wxDataViewRenameTimer( wxDataViewMainWindow *owner ) | |
1506 | { | |
1507 | m_owner = owner; | |
1508 | } | |
1509 | ||
1510 | void wxDataViewRenameTimer::Notify() | |
1511 | { | |
1512 | m_owner->OnRenameTimer(); | |
1513 | } | |
1514 | ||
1515 | //----------------------------------------------------------------------------- | |
1516 | // wxDataViewTextCtrlWrapper: wraps a wxTextCtrl for inline editing | |
1517 | //----------------------------------------------------------------------------- | |
1518 | ||
1519 | BEGIN_EVENT_TABLE(wxDataViewTextCtrlWrapper, wxEvtHandler) | |
1520 | EVT_CHAR (wxDataViewTextCtrlWrapper::OnChar) | |
1521 | EVT_KEY_UP (wxDataViewTextCtrlWrapper::OnKeyUp) | |
1522 | EVT_KILL_FOCUS (wxDataViewTextCtrlWrapper::OnKillFocus) | |
1523 | END_EVENT_TABLE() | |
1524 | ||
1525 | wxDataViewTextCtrlWrapper::wxDataViewTextCtrlWrapper( | |
1526 | wxDataViewMainWindow *owner, | |
1527 | wxTextCtrl *text, | |
1528 | wxDataViewListModel *model, | |
0a71f9e9 | 1529 | unsigned int col, unsigned int row, |
0fcce6b9 RR |
1530 | wxRect rectLabel ) |
1531 | { | |
1532 | m_owner = owner; | |
1533 | m_model = model; | |
1534 | m_row = row; | |
1535 | m_col = col; | |
120b9b05 WS |
1536 | m_text = text; |
1537 | ||
0fcce6b9 RR |
1538 | m_finished = false; |
1539 | m_aboutToFinish = false; | |
120b9b05 | 1540 | |
0fcce6b9 RR |
1541 | wxVariant value; |
1542 | model->GetValue( value, col, row ); | |
1543 | m_startValue = value.GetString(); | |
120b9b05 | 1544 | |
0fcce6b9 RR |
1545 | m_owner->GetOwner()->CalcScrolledPosition( |
1546 | rectLabel.x, rectLabel.y, &rectLabel.x, &rectLabel.y ); | |
1547 | ||
1548 | m_text->Create( owner, wxID_ANY, m_startValue, | |
1549 | wxPoint(rectLabel.x-2,rectLabel.y-2), | |
1550 | wxSize(rectLabel.width+7,rectLabel.height+4) ); | |
1551 | m_text->SetFocus(); | |
120b9b05 | 1552 | |
0fcce6b9 RR |
1553 | m_text->PushEventHandler(this); |
1554 | } | |
1555 | ||
1556 | void wxDataViewTextCtrlWrapper::AcceptChangesAndFinish() | |
1557 | { | |
1558 | m_aboutToFinish = true; | |
1559 | ||
1560 | // Notify the owner about the changes | |
1561 | AcceptChanges(); | |
1562 | ||
1563 | // Even if vetoed, close the control (consistent with MSW) | |
1564 | Finish(); | |
1565 | } | |
1566 | ||
1567 | void wxDataViewTextCtrlWrapper::OnChar( wxKeyEvent &event ) | |
1568 | { | |
1569 | switch ( event.m_keyCode ) | |
1570 | { | |
1571 | case WXK_RETURN: | |
1572 | AcceptChangesAndFinish(); | |
1573 | break; | |
1574 | ||
1575 | case WXK_ESCAPE: | |
1576 | // m_owner->OnRenameCancelled( m_itemEdited ); | |
1577 | Finish(); | |
1578 | break; | |
1579 | ||
1580 | default: | |
1581 | event.Skip(); | |
1582 | } | |
1583 | } | |
1584 | ||
1585 | void wxDataViewTextCtrlWrapper::OnKeyUp( wxKeyEvent &event ) | |
1586 | { | |
1587 | if (m_finished) | |
1588 | { | |
1589 | event.Skip(); | |
1590 | return; | |
1591 | } | |
1592 | ||
1593 | // auto-grow the textctrl | |
1594 | wxSize parentSize = m_owner->GetSize(); | |
1595 | wxPoint myPos = m_text->GetPosition(); | |
1596 | wxSize mySize = m_text->GetSize(); | |
1597 | int sx, sy; | |
1598 | m_text->GetTextExtent(m_text->GetValue() + _T("MM"), &sx, &sy); | |
1599 | if (myPos.x + sx > parentSize.x) | |
1600 | sx = parentSize.x - myPos.x; | |
1601 | if (mySize.x > sx) | |
1602 | sx = mySize.x; | |
1603 | m_text->SetSize(sx, wxDefaultCoord); | |
1604 | ||
1605 | event.Skip(); | |
1606 | } | |
1607 | ||
1608 | void wxDataViewTextCtrlWrapper::OnKillFocus( wxFocusEvent &event ) | |
1609 | { | |
1610 | if ( !m_finished && !m_aboutToFinish ) | |
1611 | { | |
1612 | AcceptChanges(); | |
1613 | //if ( !AcceptChanges() ) | |
1614 | // m_owner->OnRenameCancelled( m_itemEdited ); | |
120b9b05 | 1615 | |
0fcce6b9 RR |
1616 | Finish(); |
1617 | } | |
1618 | ||
1619 | // We must let the native text control handle focus | |
1620 | event.Skip(); | |
1621 | } | |
1622 | ||
1623 | bool wxDataViewTextCtrlWrapper::AcceptChanges() | |
1624 | { | |
1625 | const wxString value = m_text->GetValue(); | |
1626 | ||
1627 | if ( value == m_startValue ) | |
1628 | // nothing changed, always accept | |
1629 | return true; | |
1630 | ||
1631 | // if ( !m_owner->OnRenameAccept(m_itemEdited, value) ) | |
1632 | // vetoed by the user | |
1633 | // return false; | |
1634 | ||
1635 | // accepted, do rename the item | |
1636 | wxVariant variant; | |
1637 | variant = value; | |
1638 | m_model->SetValue( variant, m_col, m_row ); | |
1639 | m_model->ValueChanged( m_col, m_row ); | |
1640 | ||
1641 | return true; | |
1642 | } | |
1643 | ||
1644 | void wxDataViewTextCtrlWrapper::Finish() | |
1645 | { | |
1646 | if ( !m_finished ) | |
1647 | { | |
1648 | m_finished = true; | |
1649 | ||
1650 | m_text->RemoveEventHandler(this); | |
1651 | m_owner->FinishEditing(m_text); | |
1652 | ||
1653 | // delete later | |
1654 | wxPendingDelete.Append( this ); | |
1655 | } | |
1656 | } | |
1657 | ||
4ed7af08 RR |
1658 | //----------------------------------------------------------------------------- |
1659 | // wxDataViewMainWindow | |
1660 | //----------------------------------------------------------------------------- | |
1661 | ||
0a71f9e9 | 1662 | int LINKAGEMODE wxDataViewSelectionCmp( unsigned int row1, unsigned int row2 ) |
cab07038 RR |
1663 | { |
1664 | if (row1 > row2) return 1; | |
1665 | if (row1 == row2) return 0; | |
1666 | return -1; | |
1667 | } | |
1668 | ||
1669 | ||
45778c96 | 1670 | IMPLEMENT_ABSTRACT_CLASS(wxDataViewMainWindow, wxWindow) |
4ed7af08 RR |
1671 | |
1672 | BEGIN_EVENT_TABLE(wxDataViewMainWindow,wxWindow) | |
1673 | EVT_PAINT (wxDataViewMainWindow::OnPaint) | |
1674 | EVT_MOUSE_EVENTS (wxDataViewMainWindow::OnMouse) | |
1675 | EVT_SET_FOCUS (wxDataViewMainWindow::OnSetFocus) | |
cab07038 RR |
1676 | EVT_KILL_FOCUS (wxDataViewMainWindow::OnKillFocus) |
1677 | EVT_CHAR (wxDataViewMainWindow::OnChar) | |
4ed7af08 RR |
1678 | END_EVENT_TABLE() |
1679 | ||
1680 | wxDataViewMainWindow::wxDataViewMainWindow( wxDataViewCtrl *parent, wxWindowID id, | |
1681 | const wxPoint &pos, const wxSize &size, const wxString &name ) : | |
72664514 | 1682 | wxWindow( parent, id, pos, size, wxWANTS_CHARS, name ), |
cab07038 | 1683 | m_selection( wxDataViewSelectionCmp ) |
120b9b05 | 1684 | |
4ed7af08 RR |
1685 | { |
1686 | SetOwner( parent ); | |
f554a14b | 1687 | |
0fcce6b9 RR |
1688 | m_lastOnSame = false; |
1689 | m_renameTimer = new wxDataViewRenameTimer( this ); | |
1690 | m_textctrlWrapper = NULL; | |
120b9b05 | 1691 | |
0fcce6b9 RR |
1692 | // TODO: user better initial values/nothing selected |
1693 | m_currentCol = NULL; | |
1694 | m_currentRow = 0; | |
1695 | ||
1696 | // TODO: we need to calculate this smartly | |
c741d33f | 1697 | m_lineHeight = |
87f0efe2 RR |
1698 | #ifdef __WXMSW__ |
1699 | 17; | |
1700 | #else | |
1701 | 20; | |
1702 | #endif | |
9861f022 | 1703 | wxASSERT(m_lineHeight > 2*PADDING_TOPBOTTOM); |
e21f75bd RR |
1704 | |
1705 | m_dragCount = 0; | |
1706 | m_dragStart = wxPoint(0,0); | |
0a71f9e9 RR |
1707 | m_lineLastClicked = (unsigned int) -1; |
1708 | m_lineBeforeLastClicked = (unsigned int) -1; | |
1709 | m_lineSelectSingleOnUp = (unsigned int) -1; | |
120b9b05 | 1710 | |
cab07038 | 1711 | m_hasFocus = false; |
f554a14b | 1712 | |
2e992e06 | 1713 | SetBackgroundStyle( wxBG_STYLE_CUSTOM ); |
72664514 RR |
1714 | SetBackgroundColour( *wxWHITE ); |
1715 | ||
9861f022 RR |
1716 | m_penRule = wxPen(GetRuleColour(), 1, wxSOLID); |
1717 | ||
4b3feaa7 | 1718 | UpdateDisplay(); |
4ed7af08 RR |
1719 | } |
1720 | ||
1721 | wxDataViewMainWindow::~wxDataViewMainWindow() | |
1722 | { | |
0fcce6b9 RR |
1723 | delete m_renameTimer; |
1724 | } | |
1725 | ||
1726 | void wxDataViewMainWindow::OnRenameTimer() | |
1727 | { | |
1728 | // We have to call this here because changes may just have | |
1729 | // been made and no screen update taken place. | |
1730 | if ( m_dirty ) | |
1731 | wxSafeYield(); | |
1732 | ||
1733 | ||
1734 | int xpos = 0; | |
9861f022 | 1735 | unsigned int cols = GetOwner()->GetColumnCount(); |
0a71f9e9 | 1736 | unsigned int i; |
0fcce6b9 RR |
1737 | for (i = 0; i < cols; i++) |
1738 | { | |
1739 | wxDataViewColumn *c = GetOwner()->GetColumn( i ); | |
9861f022 RR |
1740 | if (c->IsHidden()) |
1741 | continue; // skip it! | |
1742 | ||
0fcce6b9 RR |
1743 | if (c == m_currentCol) |
1744 | break; | |
1745 | xpos += c->GetWidth(); | |
1746 | } | |
c741d33f | 1747 | wxRect labelRect( xpos, m_currentRow * m_lineHeight, |
87f0efe2 | 1748 | m_currentCol->GetWidth(), m_lineHeight ); |
0fcce6b9 RR |
1749 | |
1750 | wxClassInfo *textControlClass = CLASSINFO(wxTextCtrl); | |
1751 | ||
1752 | wxTextCtrl * const text = (wxTextCtrl *)textControlClass->CreateObject(); | |
120b9b05 | 1753 | m_textctrlWrapper = new wxDataViewTextCtrlWrapper(this, text, GetOwner()->GetModel(), |
0fcce6b9 RR |
1754 | m_currentCol->GetModelColumn(), m_currentRow, labelRect ); |
1755 | } | |
1756 | ||
1757 | void wxDataViewMainWindow::FinishEditing( wxTextCtrl *text ) | |
1758 | { | |
1759 | delete text; | |
1760 | m_textctrlWrapper = NULL; | |
1761 | SetFocus(); | |
1762 | // SetFocusIgnoringChildren(); | |
4ed7af08 RR |
1763 | } |
1764 | ||
a0f3af5f RR |
1765 | bool wxDataViewMainWindow::RowAppended() |
1766 | { | |
1767 | return false; | |
1768 | } | |
1769 | ||
1770 | bool wxDataViewMainWindow::RowPrepended() | |
1771 | { | |
1772 | return false; | |
1773 | } | |
1774 | ||
0a71f9e9 | 1775 | bool wxDataViewMainWindow::RowInserted( unsigned int WXUNUSED(before) ) |
a0f3af5f RR |
1776 | { |
1777 | return false; | |
1778 | } | |
1779 | ||
0a71f9e9 | 1780 | bool wxDataViewMainWindow::RowDeleted( unsigned int WXUNUSED(row) ) |
a0f3af5f RR |
1781 | { |
1782 | return false; | |
1783 | } | |
1784 | ||
0a71f9e9 | 1785 | bool wxDataViewMainWindow::RowChanged( unsigned int WXUNUSED(row) ) |
a0f3af5f RR |
1786 | { |
1787 | return false; | |
1788 | } | |
1789 | ||
0a71f9e9 | 1790 | bool wxDataViewMainWindow::ValueChanged( unsigned int WXUNUSED(col), unsigned int row ) |
a0f3af5f | 1791 | { |
9861f022 RR |
1792 | // NOTE: to be valid, we cannot use e.g. INT_MAX - 1 |
1793 | #define MAX_VIRTUAL_WIDTH 100000 | |
1794 | ||
1795 | wxRect rect( 0, row*m_lineHeight, MAX_VIRTUAL_WIDTH, m_lineHeight ); | |
0fdc2321 RR |
1796 | m_owner->CalcScrolledPosition( rect.x, rect.y, &rect.x, &rect.y ); |
1797 | Refresh( true, &rect ); | |
1798 | ||
1799 | return true; | |
a0f3af5f RR |
1800 | } |
1801 | ||
0a71f9e9 | 1802 | bool wxDataViewMainWindow::RowsReordered( unsigned int *WXUNUSED(new_order) ) |
a0f3af5f | 1803 | { |
0fcce6b9 | 1804 | Refresh(); |
120b9b05 | 1805 | |
0fcce6b9 | 1806 | return true; |
a0f3af5f RR |
1807 | } |
1808 | ||
1809 | bool wxDataViewMainWindow::Cleared() | |
1810 | { | |
1811 | return false; | |
1812 | } | |
1813 | ||
4b3feaa7 RR |
1814 | void wxDataViewMainWindow::UpdateDisplay() |
1815 | { | |
1816 | m_dirty = true; | |
1817 | } | |
1818 | ||
1819 | void wxDataViewMainWindow::OnInternalIdle() | |
1820 | { | |
1821 | wxWindow::OnInternalIdle(); | |
f554a14b | 1822 | |
4b3feaa7 RR |
1823 | if (m_dirty) |
1824 | { | |
1825 | RecalculateDisplay(); | |
1826 | m_dirty = false; | |
1827 | } | |
1828 | } | |
1829 | ||
1830 | void wxDataViewMainWindow::RecalculateDisplay() | |
1831 | { | |
1832 | wxDataViewListModel *model = GetOwner()->GetModel(); | |
1833 | if (!model) | |
1834 | { | |
1835 | Refresh(); | |
1836 | return; | |
1837 | } | |
f554a14b | 1838 | |
9861f022 RR |
1839 | int width = GetEndOfLastCol(); |
1840 | int height = model->GetRowCount() * m_lineHeight; | |
4b3feaa7 RR |
1841 | |
1842 | SetVirtualSize( width, height ); | |
1843 | GetOwner()->SetScrollRate( 10, m_lineHeight ); | |
f554a14b | 1844 | |
4b3feaa7 RR |
1845 | Refresh(); |
1846 | } | |
1847 | ||
1848 | void wxDataViewMainWindow::ScrollWindow( int dx, int dy, const wxRect *rect ) | |
1849 | { | |
1850 | wxWindow::ScrollWindow( dx, dy, rect ); | |
9861f022 RR |
1851 | |
1852 | if (GetOwner()->m_headerArea) | |
1853 | GetOwner()->m_headerArea->ScrollWindow( dx, 0 ); | |
4b3feaa7 RR |
1854 | } |
1855 | ||
f554a14b | 1856 | void wxDataViewMainWindow::OnPaint( wxPaintEvent &WXUNUSED(event) ) |
4ed7af08 | 1857 | { |
9861f022 | 1858 | wxDataViewListModel *model = GetOwner()->GetModel(); |
2e992e06 VZ |
1859 | wxAutoBufferedPaintDC dc( this ); |
1860 | ||
9861f022 | 1861 | // prepare the DC |
2e992e06 VZ |
1862 | dc.SetBackground(GetBackgroundColour()); |
1863 | dc.Clear(); | |
4b3feaa7 | 1864 | GetOwner()->PrepareDC( dc ); |
4ed7af08 | 1865 | dc.SetFont( GetFont() ); |
90675b95 RR |
1866 | |
1867 | wxRect update = GetUpdateRegion().GetBox(); | |
1868 | m_owner->CalcUnscrolledPosition( update.x, update.y, &update.x, &update.y ); | |
f554a14b | 1869 | |
9861f022 | 1870 | // compute which items needs to be redrawn |
0a71f9e9 | 1871 | unsigned int item_start = wxMax( 0, (update.y / m_lineHeight) ); |
c741d33f | 1872 | unsigned int item_count = |
87f0efe2 | 1873 | wxMin( (int)(((update.y + update.height) / m_lineHeight) - item_start + 1), |
9861f022 RR |
1874 | (int)(model->GetRowCount() - item_start) ); |
1875 | unsigned int item_last = item_start + item_count; | |
1876 | ||
1877 | // compute which columns needs to be redrawn | |
1878 | unsigned int cols = GetOwner()->GetColumnCount(); | |
1879 | unsigned int col_start = 0; | |
1880 | unsigned int x_start = 0; | |
1881 | for (x_start = 0; col_start < cols; col_start++) | |
1882 | { | |
1883 | wxDataViewColumn *col = GetOwner()->GetColumn(col_start); | |
1884 | if (col->IsHidden()) | |
1885 | continue; // skip it! | |
1886 | ||
1887 | unsigned int w = col->GetWidth(); | |
1888 | if (x_start+w >= (unsigned int)update.x) | |
1889 | break; | |
1890 | ||
1891 | x_start += w; | |
1892 | } | |
90675b95 | 1893 | |
9861f022 RR |
1894 | unsigned int col_last = col_start; |
1895 | unsigned int x_last = x_start; | |
1896 | for (; col_last < cols; col_last++) | |
1897 | { | |
1898 | wxDataViewColumn *col = GetOwner()->GetColumn(col_last); | |
1899 | if (col->IsHidden()) | |
1900 | continue; // skip it! | |
1901 | ||
1902 | if (x_last > (unsigned int)update.GetRight()) | |
1903 | break; | |
1904 | ||
1905 | x_last += col->GetWidth(); | |
1906 | } | |
1907 | ||
1908 | // Draw horizontal rules if required | |
1909 | if ( m_owner->HasFlag(wxDV_HORIZ_RULES) ) | |
1910 | { | |
1911 | dc.SetPen(m_penRule); | |
1912 | dc.SetBrush(*wxTRANSPARENT_BRUSH); | |
1913 | ||
1914 | for (unsigned int i = item_start; i <= item_last+1; i++) | |
1915 | { | |
1916 | int y = i * m_lineHeight; | |
1917 | dc.DrawLine(x_start, y, x_last, y); | |
1918 | } | |
1919 | } | |
1920 | ||
1921 | // Draw vertical rules if required | |
1922 | if ( m_owner->HasFlag(wxDV_VERT_RULES) ) | |
1923 | { | |
1924 | dc.SetPen(m_penRule); | |
1925 | dc.SetBrush(*wxTRANSPARENT_BRUSH); | |
1926 | ||
1927 | int x = x_start; | |
1928 | for (unsigned int i = col_start; i < col_last; i++) | |
1929 | { | |
1930 | wxDataViewColumn *col = GetOwner()->GetColumn(i); | |
1931 | if (col->IsHidden()) | |
1932 | continue; // skip it | |
1933 | ||
1934 | dc.DrawLine(x, item_start * m_lineHeight, | |
1935 | x, item_last * m_lineHeight); | |
1936 | ||
1937 | x += col->GetWidth(); | |
1938 | } | |
1939 | ||
1940 | // Draw last vertical rule | |
c741d33f | 1941 | dc.DrawLine(x, item_start * m_lineHeight, |
9861f022 RR |
1942 | x, item_last * m_lineHeight); |
1943 | } | |
1944 | ||
1945 | // redraw the background for the items which are selected/current | |
1946 | for (unsigned int item = item_start; item < item_last; item++) | |
cab07038 | 1947 | { |
87f0efe2 RR |
1948 | bool selected = m_selection.Index( item ) != wxNOT_FOUND; |
1949 | if (selected || item == m_currentRow) | |
cab07038 | 1950 | { |
5d3f234b | 1951 | int flags = selected ? (int)wxCONTROL_SELECTED : 0; |
daebb44c RR |
1952 | if (item == m_currentRow) |
1953 | flags |= wxCONTROL_CURRENT; | |
1954 | if (m_hasFocus) | |
1955 | flags |= wxCONTROL_FOCUSED; | |
9861f022 RR |
1956 | |
1957 | wxRect rect( x_start, item*m_lineHeight, x_last, m_lineHeight ); | |
daebb44c RR |
1958 | wxRendererNative::Get().DrawItemSelectionRect |
1959 | ( | |
1960 | this, | |
1961 | dc, | |
1962 | rect, | |
1963 | flags | |
1964 | ); | |
1965 | } | |
cab07038 | 1966 | } |
120b9b05 | 1967 | |
9861f022 | 1968 | // redraw all cells for all rows which must be repainted and for all columns |
90675b95 | 1969 | wxRect cell_rect; |
9861f022 RR |
1970 | cell_rect.x = x_start; |
1971 | cell_rect.height = m_lineHeight; // -1 is for the horizontal rules | |
1972 | for (unsigned int i = col_start; i < col_last; i++) | |
90675b95 RR |
1973 | { |
1974 | wxDataViewColumn *col = GetOwner()->GetColumn( i ); | |
baa9ebc4 | 1975 | wxDataViewRenderer *cell = col->GetRenderer(); |
90675b95 | 1976 | cell_rect.width = col->GetWidth(); |
f554a14b | 1977 | |
87f0efe2 RR |
1978 | if (col->IsHidden()) |
1979 | continue; // skipt it! | |
1980 | ||
9861f022 | 1981 | for (unsigned int item = item_start; item < item_last; item++) |
90675b95 | 1982 | { |
87f0efe2 | 1983 | // get the cell value and set it into the renderer |
90675b95 RR |
1984 | wxVariant value; |
1985 | model->GetValue( value, col->GetModelColumn(), item ); | |
1986 | cell->SetValue( value ); | |
87f0efe2 RR |
1987 | |
1988 | // update the y offset | |
9861f022 | 1989 | cell_rect.y = item * m_lineHeight; |
87f0efe2 | 1990 | |
4064f7de | 1991 | // cannot be bigger than allocated space |
87f0efe2 | 1992 | wxSize size = cell->GetSize(); |
9861f022 RR |
1993 | size.x = wxMin( size.x + 2*PADDING_RIGHTLEFT, cell_rect.width ); |
1994 | size.y = wxMin( size.y + 2*PADDING_TOPBOTTOM, cell_rect.height ); | |
87f0efe2 RR |
1995 | |
1996 | wxRect item_rect(cell_rect.GetTopLeft(), size); | |
9861f022 | 1997 | int align = cell->GetAlignment(); |
87f0efe2 RR |
1998 | |
1999 | // horizontal alignment: | |
9861f022 RR |
2000 | item_rect.x = cell_rect.x; |
2001 | if (align & wxALIGN_CENTER_HORIZONTAL) | |
2002 | item_rect.x = cell_rect.x + (cell_rect.width / 2) - (size.x / 2); | |
2003 | else if (align & wxALIGN_RIGHT) | |
87f0efe2 RR |
2004 | item_rect.x = cell_rect.x + cell_rect.width - size.x; |
2005 | //else: wxALIGN_LEFT is the default | |
2006 | ||
2007 | // vertical alignment: | |
9861f022 RR |
2008 | item_rect.y = cell_rect.y; |
2009 | if (align & wxALIGN_CENTER_VERTICAL) | |
87f0efe2 | 2010 | item_rect.y = cell_rect.y + (cell_rect.height / 2) - (size.y / 2); |
9861f022 | 2011 | else if (align & wxALIGN_BOTTOM) |
87f0efe2 RR |
2012 | item_rect.y = cell_rect.y + cell_rect.height - size.y; |
2013 | //else: wxALIGN_TOP is the default | |
2014 | ||
9861f022 RR |
2015 | // add padding |
2016 | item_rect.x += PADDING_RIGHTLEFT; | |
2017 | item_rect.y += PADDING_TOPBOTTOM; | |
2018 | item_rect.width = size.x - 2 * PADDING_RIGHTLEFT; | |
2019 | item_rect.height = size.y - 2 * PADDING_TOPBOTTOM; | |
64b3c262 VZ |
2020 | |
2021 | int state = 0; | |
87f0efe2 | 2022 | if (m_selection.Index(item) != wxNOT_FOUND) |
64b3c262 | 2023 | state |= wxDATAVIEW_CELL_SELECTED; |
87f0efe2 | 2024 | |
9861f022 RR |
2025 | // TODO: it would be much more efficient to create a clipping |
2026 | // region for the entire column being rendered (in the OnPaint | |
2027 | // of wxDataViewMainWindow) instead of a single clip region for | |
2028 | // each cell. However it would mean that each renderer should | |
2029 | // respect the given wxRect's top & bottom coords, eventually | |
2030 | // violating only the left & right coords - however the user can | |
2031 | // make its own renderer and thus we cannot be sure of that. | |
2032 | dc.SetClippingRegion( item_rect ); | |
64b3c262 | 2033 | cell->Render( item_rect, &dc, state ); |
9861f022 | 2034 | dc.DestroyClippingRegion(); |
90675b95 | 2035 | } |
f554a14b | 2036 | |
90675b95 RR |
2037 | cell_rect.x += cell_rect.width; |
2038 | } | |
4ed7af08 RR |
2039 | } |
2040 | ||
9861f022 | 2041 | int wxDataViewMainWindow::GetCountPerPage() const |
cab07038 RR |
2042 | { |
2043 | wxSize size = GetClientSize(); | |
2044 | return size.y / m_lineHeight; | |
2045 | } | |
2046 | ||
9861f022 | 2047 | int wxDataViewMainWindow::GetEndOfLastCol() const |
e21f75bd RR |
2048 | { |
2049 | int width = 0; | |
0a71f9e9 | 2050 | unsigned int i; |
9861f022 | 2051 | for (i = 0; i < GetOwner()->GetColumnCount(); i++) |
e21f75bd | 2052 | { |
c741d33f | 2053 | const wxDataViewColumn *c = |
9861f022 RR |
2054 | wx_const_cast(wxDataViewCtrl*, GetOwner())->GetColumn( i ); |
2055 | ||
2056 | if (!c->IsHidden()) | |
2057 | width += c->GetWidth(); | |
e21f75bd RR |
2058 | } |
2059 | return width; | |
2060 | } | |
2061 | ||
9861f022 | 2062 | unsigned int wxDataViewMainWindow::GetFirstVisibleRow() const |
72664514 RR |
2063 | { |
2064 | int x = 0; | |
2065 | int y = 0; | |
2066 | m_owner->CalcUnscrolledPosition( x, y, &x, &y ); | |
120b9b05 | 2067 | |
72664514 RR |
2068 | return y / m_lineHeight; |
2069 | } | |
2070 | ||
9861f022 | 2071 | unsigned int wxDataViewMainWindow::GetLastVisibleRow() const |
72664514 RR |
2072 | { |
2073 | wxSize client_size = GetClientSize(); | |
c741d33f | 2074 | m_owner->CalcUnscrolledPosition( client_size.x, client_size.y, |
87f0efe2 | 2075 | &client_size.x, &client_size.y ); |
72664514 | 2076 | |
5637e131 | 2077 | return wxMin( GetRowCount()-1, ((unsigned)client_size.y/m_lineHeight)+1 ); |
72664514 RR |
2078 | } |
2079 | ||
9861f022 | 2080 | unsigned int wxDataViewMainWindow::GetRowCount() const |
cab07038 | 2081 | { |
9861f022 | 2082 | return wx_const_cast(wxDataViewCtrl*, GetOwner())->GetModel()->GetRowCount(); |
cab07038 RR |
2083 | } |
2084 | ||
0a71f9e9 | 2085 | void wxDataViewMainWindow::ChangeCurrentRow( unsigned int row ) |
e21f75bd RR |
2086 | { |
2087 | m_currentRow = row; | |
120b9b05 | 2088 | |
e21f75bd RR |
2089 | // send event |
2090 | } | |
2091 | ||
cab07038 RR |
2092 | void wxDataViewMainWindow::SelectAllRows( bool on ) |
2093 | { | |
4a851b11 VZ |
2094 | if (IsEmpty()) |
2095 | return; | |
120b9b05 | 2096 | |
cab07038 RR |
2097 | if (on) |
2098 | { | |
72664514 | 2099 | m_selection.Clear(); |
0a71f9e9 | 2100 | for (unsigned int i = 0; i < GetRowCount(); i++) |
cab07038 | 2101 | m_selection.Add( i ); |
72664514 RR |
2102 | Refresh(); |
2103 | } | |
2104 | else | |
2105 | { | |
0a71f9e9 RR |
2106 | unsigned int first_visible = GetFirstVisibleRow(); |
2107 | unsigned int last_visible = GetLastVisibleRow(); | |
2108 | unsigned int i; | |
72664514 | 2109 | for (i = 0; i < m_selection.GetCount(); i++) |
120b9b05 | 2110 | { |
0a71f9e9 | 2111 | unsigned int row = m_selection[i]; |
72664514 RR |
2112 | if ((row >= first_visible) && (row <= last_visible)) |
2113 | RefreshRow( row ); | |
2114 | } | |
2115 | m_selection.Clear(); | |
cab07038 | 2116 | } |
cab07038 RR |
2117 | } |
2118 | ||
0a71f9e9 | 2119 | void wxDataViewMainWindow::SelectRow( unsigned int row, bool on ) |
cab07038 RR |
2120 | { |
2121 | if (m_selection.Index( row ) == wxNOT_FOUND) | |
2122 | { | |
2123 | if (on) | |
2124 | { | |
2125 | m_selection.Add( row ); | |
2126 | RefreshRow( row ); | |
2127 | } | |
2128 | } | |
2129 | else | |
2130 | { | |
2131 | if (!on) | |
2132 | { | |
2133 | m_selection.Remove( row ); | |
2134 | RefreshRow( row ); | |
2135 | } | |
2136 | } | |
2137 | } | |
2138 | ||
0a71f9e9 | 2139 | void wxDataViewMainWindow::SelectRows( unsigned int from, unsigned int to, bool on ) |
cab07038 RR |
2140 | { |
2141 | if (from > to) | |
2142 | { | |
0a71f9e9 | 2143 | unsigned int tmp = from; |
cab07038 RR |
2144 | from = to; |
2145 | to = tmp; | |
2146 | } | |
2147 | ||
0a71f9e9 | 2148 | unsigned int i; |
cab07038 RR |
2149 | for (i = from; i <= to; i++) |
2150 | { | |
2151 | if (m_selection.Index( i ) == wxNOT_FOUND) | |
2152 | { | |
2153 | if (on) | |
2154 | m_selection.Add( i ); | |
2155 | } | |
2156 | else | |
2157 | { | |
2158 | if (!on) | |
2159 | m_selection.Remove( i ); | |
2160 | } | |
2161 | } | |
2162 | RefreshRows( from, to ); | |
2163 | } | |
2164 | ||
87f0efe2 RR |
2165 | void wxDataViewMainWindow::Select( const wxArrayInt& aSelections ) |
2166 | { | |
2167 | for (size_t i=0; i < aSelections.GetCount(); i++) | |
2168 | { | |
2169 | int n = aSelections[i]; | |
2170 | ||
2171 | m_selection.Add( n ); | |
2172 | RefreshRow( n ); | |
2173 | } | |
2174 | } | |
2175 | ||
0a71f9e9 | 2176 | void wxDataViewMainWindow::ReverseRowSelection( unsigned int row ) |
cab07038 RR |
2177 | { |
2178 | if (m_selection.Index( row ) == wxNOT_FOUND) | |
2179 | m_selection.Add( row ); | |
2180 | else | |
2181 | m_selection.Remove( row ); | |
120b9b05 | 2182 | RefreshRow( row ); |
cab07038 RR |
2183 | } |
2184 | ||
0a71f9e9 | 2185 | bool wxDataViewMainWindow::IsRowSelected( unsigned int row ) |
cab07038 RR |
2186 | { |
2187 | return (m_selection.Index( row ) != wxNOT_FOUND); | |
2188 | } | |
2189 | ||
0a71f9e9 | 2190 | void wxDataViewMainWindow::RefreshRow( unsigned int row ) |
cab07038 | 2191 | { |
e21f75bd | 2192 | wxRect rect( 0, row*m_lineHeight, GetEndOfLastCol(), m_lineHeight ); |
cab07038 | 2193 | m_owner->CalcScrolledPosition( rect.x, rect.y, &rect.x, &rect.y ); |
120b9b05 | 2194 | |
cab07038 RR |
2195 | wxSize client_size = GetClientSize(); |
2196 | wxRect client_rect( 0, 0, client_size.x, client_size.y ); | |
2197 | wxRect intersect_rect = client_rect.Intersect( rect ); | |
2198 | if (intersect_rect.width > 0) | |
2199 | Refresh( true, &intersect_rect ); | |
2200 | } | |
2201 | ||
0a71f9e9 | 2202 | void wxDataViewMainWindow::RefreshRows( unsigned int from, unsigned int to ) |
cab07038 RR |
2203 | { |
2204 | if (from > to) | |
2205 | { | |
0a71f9e9 | 2206 | unsigned int tmp = to; |
cab07038 RR |
2207 | to = from; |
2208 | from = tmp; | |
2209 | } | |
2210 | ||
e21f75bd | 2211 | wxRect rect( 0, from*m_lineHeight, GetEndOfLastCol(), (to-from+1) * m_lineHeight ); |
cab07038 | 2212 | m_owner->CalcScrolledPosition( rect.x, rect.y, &rect.x, &rect.y ); |
120b9b05 | 2213 | |
cab07038 RR |
2214 | wxSize client_size = GetClientSize(); |
2215 | wxRect client_rect( 0, 0, client_size.x, client_size.y ); | |
2216 | wxRect intersect_rect = client_rect.Intersect( rect ); | |
2217 | if (intersect_rect.width > 0) | |
2218 | Refresh( true, &intersect_rect ); | |
2219 | } | |
2220 | ||
0a71f9e9 | 2221 | void wxDataViewMainWindow::RefreshRowsAfter( unsigned int firstRow ) |
cab07038 | 2222 | { |
0a71f9e9 | 2223 | unsigned int count = GetRowCount(); |
4a851b11 VZ |
2224 | if (firstRow > count) |
2225 | return; | |
120b9b05 | 2226 | |
e21f75bd | 2227 | wxRect rect( 0, firstRow*m_lineHeight, GetEndOfLastCol(), count * m_lineHeight ); |
cab07038 | 2228 | m_owner->CalcScrolledPosition( rect.x, rect.y, &rect.x, &rect.y ); |
120b9b05 | 2229 | |
cab07038 RR |
2230 | wxSize client_size = GetClientSize(); |
2231 | wxRect client_rect( 0, 0, client_size.x, client_size.y ); | |
2232 | wxRect intersect_rect = client_rect.Intersect( rect ); | |
2233 | if (intersect_rect.width > 0) | |
2234 | Refresh( true, &intersect_rect ); | |
2235 | } | |
2236 | ||
0a71f9e9 | 2237 | void wxDataViewMainWindow::OnArrowChar(unsigned int newCurrent, const wxKeyEvent& event) |
cab07038 | 2238 | { |
4a851b11 | 2239 | wxCHECK_RET( newCurrent < GetRowCount(), |
cab07038 RR |
2240 | _T("invalid item index in OnArrowChar()") ); |
2241 | ||
2242 | // if there is no selection, we cannot move it anywhere | |
2243 | if (!HasCurrentRow()) | |
2244 | return; | |
2245 | ||
0a71f9e9 | 2246 | unsigned int oldCurrent = m_currentRow; |
cab07038 RR |
2247 | |
2248 | // in single selection we just ignore Shift as we can't select several | |
2249 | // items anyhow | |
e21f75bd | 2250 | if ( event.ShiftDown() && !IsSingleSel() ) |
cab07038 RR |
2251 | { |
2252 | RefreshRow( oldCurrent ); | |
120b9b05 | 2253 | |
e21f75bd | 2254 | ChangeCurrentRow( newCurrent ); |
cab07038 RR |
2255 | |
2256 | // select all the items between the old and the new one | |
2257 | if ( oldCurrent > newCurrent ) | |
2258 | { | |
2259 | newCurrent = oldCurrent; | |
2260 | oldCurrent = m_currentRow; | |
2261 | } | |
2262 | ||
2263 | SelectRows( oldCurrent, newCurrent, true ); | |
2264 | } | |
2265 | else // !shift | |
2266 | { | |
72664514 | 2267 | RefreshRow( oldCurrent ); |
120b9b05 | 2268 | |
cab07038 RR |
2269 | // all previously selected items are unselected unless ctrl is held |
2270 | if ( !event.ControlDown() ) | |
2271 | SelectAllRows(false); | |
2272 | ||
e21f75bd | 2273 | ChangeCurrentRow( newCurrent ); |
cab07038 RR |
2274 | |
2275 | if ( !event.ControlDown() ) | |
2276 | SelectRow( m_currentRow, true ); | |
72664514 RR |
2277 | else |
2278 | RefreshRow( m_currentRow ); | |
cab07038 RR |
2279 | } |
2280 | ||
9861f022 RR |
2281 | //EnsureVisible( m_currentRow ); |
2282 | } | |
2283 | ||
2284 | wxRect wxDataViewMainWindow::GetLineRect( unsigned int row ) const | |
2285 | { | |
2286 | wxRect rect; | |
2287 | rect.x = 0; | |
2288 | rect.y = m_lineHeight * row; | |
2289 | rect.width = GetEndOfLastCol(); | |
2290 | rect.height = m_lineHeight; | |
2291 | ||
2292 | return rect; | |
cab07038 RR |
2293 | } |
2294 | ||
2295 | void wxDataViewMainWindow::OnChar( wxKeyEvent &event ) | |
2296 | { | |
2297 | if (event.GetKeyCode() == WXK_TAB) | |
2298 | { | |
2299 | wxNavigationKeyEvent nevent; | |
2300 | nevent.SetWindowChange( event.ControlDown() ); | |
2301 | nevent.SetDirection( !event.ShiftDown() ); | |
2302 | nevent.SetEventObject( GetParent()->GetParent() ); | |
2303 | nevent.SetCurrentFocus( m_parent ); | |
2304 | if (GetParent()->GetParent()->GetEventHandler()->ProcessEvent( nevent )) | |
2305 | return; | |
2306 | } | |
2307 | ||
2308 | // no item -> nothing to do | |
2309 | if (!HasCurrentRow()) | |
2310 | { | |
2311 | event.Skip(); | |
2312 | return; | |
2313 | } | |
120b9b05 | 2314 | |
cab07038 RR |
2315 | // don't use m_linesPerPage directly as it might not be computed yet |
2316 | const int pageSize = GetCountPerPage(); | |
2317 | wxCHECK_RET( pageSize, _T("should have non zero page size") ); | |
2318 | ||
2319 | switch ( event.GetKeyCode() ) | |
2320 | { | |
2321 | case WXK_UP: | |
2322 | if ( m_currentRow > 0 ) | |
2323 | OnArrowChar( m_currentRow - 1, event ); | |
2324 | break; | |
2325 | ||
2326 | case WXK_DOWN: | |
4a851b11 | 2327 | if ( m_currentRow < GetRowCount() - 1 ) |
cab07038 RR |
2328 | OnArrowChar( m_currentRow + 1, event ); |
2329 | break; | |
2330 | ||
2331 | case WXK_END: | |
2332 | if (!IsEmpty()) | |
2333 | OnArrowChar( GetRowCount() - 1, event ); | |
2334 | break; | |
2335 | ||
2336 | case WXK_HOME: | |
2337 | if (!IsEmpty()) | |
2338 | OnArrowChar( 0, event ); | |
2339 | break; | |
2340 | ||
2341 | case WXK_PAGEUP: | |
2342 | { | |
2343 | int steps = pageSize - 1; | |
2344 | int index = m_currentRow - steps; | |
2345 | if (index < 0) | |
2346 | index = 0; | |
2347 | ||
2348 | OnArrowChar( index, event ); | |
2349 | } | |
2350 | break; | |
2351 | ||
2352 | case WXK_PAGEDOWN: | |
2353 | { | |
2354 | int steps = pageSize - 1; | |
0a71f9e9 RR |
2355 | unsigned int index = m_currentRow + steps; |
2356 | unsigned int count = GetRowCount(); | |
cab07038 RR |
2357 | if ( index >= count ) |
2358 | index = count - 1; | |
2359 | ||
2360 | OnArrowChar( index, event ); | |
2361 | } | |
2362 | break; | |
2363 | ||
2364 | default: | |
2365 | event.Skip(); | |
2366 | } | |
2367 | } | |
2368 | ||
4ed7af08 RR |
2369 | void wxDataViewMainWindow::OnMouse( wxMouseEvent &event ) |
2370 | { | |
e21f75bd RR |
2371 | if (event.GetEventType() == wxEVT_MOUSEWHEEL) |
2372 | { | |
2373 | // let the base handle mouse wheel events. | |
2374 | event.Skip(); | |
2375 | return; | |
2376 | } | |
2377 | ||
0fdc2321 RR |
2378 | int x = event.GetX(); |
2379 | int y = event.GetY(); | |
2380 | m_owner->CalcUnscrolledPosition( x, y, &x, &y ); | |
2381 | ||
2382 | wxDataViewColumn *col = NULL; | |
2383 | ||
2384 | int xpos = 0; | |
9861f022 | 2385 | unsigned int cols = GetOwner()->GetColumnCount(); |
0a71f9e9 | 2386 | unsigned int i; |
0fdc2321 RR |
2387 | for (i = 0; i < cols; i++) |
2388 | { | |
2389 | wxDataViewColumn *c = GetOwner()->GetColumn( i ); | |
9861f022 RR |
2390 | if (c->IsHidden()) |
2391 | continue; // skip it! | |
2392 | ||
0fdc2321 RR |
2393 | if (x < xpos + c->GetWidth()) |
2394 | { | |
2395 | col = c; | |
2396 | break; | |
2397 | } | |
2398 | xpos += c->GetWidth(); | |
2399 | } | |
f554a14b | 2400 | if (!col) |
0fdc2321 | 2401 | return; |
baa9ebc4 | 2402 | wxDataViewRenderer *cell = col->GetRenderer(); |
f554a14b | 2403 | |
0a71f9e9 | 2404 | unsigned int current = y / m_lineHeight; |
120b9b05 | 2405 | |
e21f75bd RR |
2406 | if ((current > GetRowCount()) || (x > GetEndOfLastCol())) |
2407 | { | |
2408 | // Unselect all if below the last row ? | |
2409 | return; | |
2410 | } | |
f554a14b | 2411 | |
0fdc2321 RR |
2412 | wxDataViewListModel *model = GetOwner()->GetModel(); |
2413 | ||
e21f75bd RR |
2414 | if (event.Dragging()) |
2415 | { | |
2416 | if (m_dragCount == 0) | |
2417 | { | |
2418 | // we have to report the raw, physical coords as we want to be | |
2419 | // able to call HitTest(event.m_pointDrag) from the user code to | |
2420 | // get the item being dragged | |
2421 | m_dragStart = event.GetPosition(); | |
2422 | } | |
2423 | ||
2424 | m_dragCount++; | |
2425 | ||
2426 | if (m_dragCount != 3) | |
2427 | return; | |
2428 | ||
2429 | if (event.LeftIsDown()) | |
2430 | { | |
2431 | // Notify cell about drag | |
2432 | } | |
2433 | return; | |
2434 | } | |
2435 | else | |
2436 | { | |
2437 | m_dragCount = 0; | |
2438 | } | |
2439 | ||
2440 | bool forceClick = false; | |
2441 | ||
0fcce6b9 RR |
2442 | if (event.ButtonDClick()) |
2443 | { | |
2444 | m_renameTimer->Stop(); | |
2445 | m_lastOnSame = false; | |
2446 | } | |
2447 | ||
0fdc2321 RR |
2448 | if (event.LeftDClick()) |
2449 | { | |
e21f75bd | 2450 | if ( current == m_lineLastClicked ) |
0fdc2321 | 2451 | { |
e21f75bd RR |
2452 | if (cell->GetMode() == wxDATAVIEW_CELL_ACTIVATABLE) |
2453 | { | |
2454 | wxVariant value; | |
2455 | model->GetValue( value, col->GetModelColumn(), current ); | |
2456 | cell->SetValue( value ); | |
c741d33f | 2457 | wxRect cell_rect( xpos, current * m_lineHeight, |
87f0efe2 | 2458 | col->GetWidth(), m_lineHeight ); |
e21f75bd RR |
2459 | cell->Activate( cell_rect, model, col->GetModelColumn(), current ); |
2460 | } | |
2461 | return; | |
2462 | } | |
2463 | else | |
2464 | { | |
2465 | // The first click was on another item, so don't interpret this as | |
2466 | // a double click, but as a simple click instead | |
2467 | forceClick = true; | |
0fdc2321 | 2468 | } |
120b9b05 | 2469 | } |
f554a14b | 2470 | |
0fcce6b9 RR |
2471 | if (event.LeftUp()) |
2472 | { | |
0a71f9e9 | 2473 | if (m_lineSelectSingleOnUp != (unsigned int)-1) |
e21f75bd RR |
2474 | { |
2475 | // select single line | |
2476 | SelectAllRows( false ); | |
2477 | SelectRow( m_lineSelectSingleOnUp, true ); | |
2478 | } | |
120b9b05 | 2479 | |
0fcce6b9 RR |
2480 | if (m_lastOnSame) |
2481 | { | |
a8461d31 | 2482 | if ((col == m_currentCol) && (current == m_currentRow) && |
0fcce6b9 RR |
2483 | (cell->GetMode() == wxDATAVIEW_CELL_EDITABLE) ) |
2484 | { | |
2485 | m_renameTimer->Start( 100, true ); | |
2486 | } | |
2487 | } | |
2488 | ||
2489 | m_lastOnSame = false; | |
0a71f9e9 | 2490 | m_lineSelectSingleOnUp = (unsigned int)-1; |
120b9b05 | 2491 | } |
e21f75bd RR |
2492 | else |
2493 | { | |
2494 | // This is necessary, because after a DnD operation in | |
2495 | // from and to ourself, the up event is swallowed by the | |
2496 | // DnD code. So on next non-up event (which means here and | |
2497 | // now) m_lineSelectSingleOnUp should be reset. | |
0a71f9e9 | 2498 | m_lineSelectSingleOnUp = (unsigned int)-1; |
e21f75bd RR |
2499 | } |
2500 | ||
2501 | if (event.RightDown()) | |
2502 | { | |
2503 | m_lineBeforeLastClicked = m_lineLastClicked; | |
2504 | m_lineLastClicked = current; | |
2505 | ||
2506 | // If the item is already selected, do not update the selection. | |
2507 | // Multi-selections should not be cleared if a selected item is clicked. | |
2508 | if (!IsRowSelected(current)) | |
2509 | { | |
2510 | SelectAllRows(false); | |
2511 | ChangeCurrentRow(current); | |
2512 | SelectRow(m_currentRow,true); | |
2513 | } | |
2514 | ||
2515 | // notify cell about right click | |
2516 | // cell->... | |
120b9b05 | 2517 | |
e21f75bd RR |
2518 | // Allow generation of context menu event |
2519 | event.Skip(); | |
2520 | } | |
2521 | else if (event.MiddleDown()) | |
2522 | { | |
2523 | // notify cell about middle click | |
2524 | // cell->... | |
2525 | } | |
2526 | if (event.LeftDown() || forceClick) | |
0fcce6b9 | 2527 | { |
72664514 RR |
2528 | #ifdef __WXMSW__ |
2529 | SetFocus(); | |
2530 | #endif | |
120b9b05 | 2531 | |
e21f75bd RR |
2532 | m_lineBeforeLastClicked = m_lineLastClicked; |
2533 | m_lineLastClicked = current; | |
2534 | ||
0a71f9e9 | 2535 | unsigned int oldCurrentRow = m_currentRow; |
e21f75bd RR |
2536 | bool oldWasSelected = IsRowSelected(m_currentRow); |
2537 | ||
2538 | bool cmdModifierDown = event.CmdDown(); | |
2539 | if ( IsSingleSel() || !(cmdModifierDown || event.ShiftDown()) ) | |
2540 | { | |
2541 | if ( IsSingleSel() || !IsRowSelected(current) ) | |
2542 | { | |
2543 | SelectAllRows( false ); | |
2544 | ||
2545 | ChangeCurrentRow(current); | |
2546 | ||
2547 | SelectRow(m_currentRow,true); | |
2548 | } | |
2549 | else // multi sel & current is highlighted & no mod keys | |
2550 | { | |
2551 | m_lineSelectSingleOnUp = current; | |
2552 | ChangeCurrentRow(current); // change focus | |
2553 | } | |
2554 | } | |
2555 | else // multi sel & either ctrl or shift is down | |
2556 | { | |
2557 | if (cmdModifierDown) | |
2558 | { | |
2559 | ChangeCurrentRow(current); | |
2560 | ||
2561 | ReverseRowSelection(m_currentRow); | |
2562 | } | |
2563 | else if (event.ShiftDown()) | |
2564 | { | |
2565 | ChangeCurrentRow(current); | |
2566 | ||
0a71f9e9 | 2567 | unsigned int lineFrom = oldCurrentRow, |
e21f75bd RR |
2568 | lineTo = current; |
2569 | ||
2570 | if ( lineTo < lineFrom ) | |
2571 | { | |
2572 | lineTo = lineFrom; | |
2573 | lineFrom = m_currentRow; | |
2574 | } | |
2575 | ||
2576 | SelectRows(lineFrom, lineTo, true); | |
2577 | } | |
2578 | else // !ctrl, !shift | |
2579 | { | |
2580 | // test in the enclosing if should make it impossible | |
2581 | wxFAIL_MSG( _T("how did we get here?") ); | |
2582 | } | |
2583 | } | |
2584 | ||
72664514 RR |
2585 | if (m_currentRow != oldCurrentRow) |
2586 | RefreshRow( oldCurrentRow ); | |
e21f75bd | 2587 | |
0fcce6b9 | 2588 | wxDataViewColumn *oldCurrentCol = m_currentCol; |
120b9b05 | 2589 | |
0fcce6b9 RR |
2590 | // Update selection here... |
2591 | m_currentCol = col; | |
120b9b05 | 2592 | |
c741d33f | 2593 | m_lastOnSame = !forceClick && ((col == oldCurrentCol) && |
87f0efe2 | 2594 | (current == oldCurrentRow)) && oldWasSelected; |
0fdc2321 | 2595 | } |
4ed7af08 RR |
2596 | } |
2597 | ||
2598 | void wxDataViewMainWindow::OnSetFocus( wxFocusEvent &event ) | |
2599 | { | |
cab07038 | 2600 | m_hasFocus = true; |
120b9b05 | 2601 | |
cab07038 RR |
2602 | if (HasCurrentRow()) |
2603 | Refresh(); | |
120b9b05 | 2604 | |
cab07038 RR |
2605 | event.Skip(); |
2606 | } | |
2607 | ||
2608 | void wxDataViewMainWindow::OnKillFocus( wxFocusEvent &event ) | |
2609 | { | |
2610 | m_hasFocus = false; | |
120b9b05 | 2611 | |
cab07038 RR |
2612 | if (HasCurrentRow()) |
2613 | Refresh(); | |
120b9b05 | 2614 | |
4ed7af08 RR |
2615 | event.Skip(); |
2616 | } | |
2617 | ||
2618 | //----------------------------------------------------------------------------- | |
2619 | // wxDataViewCtrl | |
2620 | //----------------------------------------------------------------------------- | |
2621 | ||
2622 | IMPLEMENT_DYNAMIC_CLASS(wxDataViewCtrl, wxDataViewCtrlBase) | |
2623 | ||
4b3feaa7 RR |
2624 | BEGIN_EVENT_TABLE(wxDataViewCtrl, wxDataViewCtrlBase) |
2625 | EVT_SIZE(wxDataViewCtrl::OnSize) | |
2626 | END_EVENT_TABLE() | |
2627 | ||
4ed7af08 RR |
2628 | wxDataViewCtrl::~wxDataViewCtrl() |
2629 | { | |
2630 | if (m_notifier) | |
2631 | GetModel()->RemoveNotifier( m_notifier ); | |
2632 | } | |
2633 | ||
2634 | void wxDataViewCtrl::Init() | |
2635 | { | |
2636 | m_notifier = NULL; | |
2637 | } | |
2638 | ||
2639 | bool wxDataViewCtrl::Create(wxWindow *parent, wxWindowID id, | |
f554a14b | 2640 | const wxPoint& pos, const wxSize& size, |
4ed7af08 RR |
2641 | long style, const wxValidator& validator ) |
2642 | { | |
c741d33f | 2643 | if (!wxControl::Create( parent, id, pos, size, |
87f0efe2 | 2644 | style | wxScrolledWindowStyle|wxSUNKEN_BORDER, validator)) |
4b3feaa7 RR |
2645 | return false; |
2646 | ||
4ed7af08 | 2647 | Init(); |
f554a14b | 2648 | |
4ed7af08 RR |
2649 | #ifdef __WXMAC__ |
2650 | MacSetClipChildren( true ) ; | |
2651 | #endif | |
2652 | ||
f554a14b | 2653 | m_clientArea = new wxDataViewMainWindow( this, wxID_ANY ); |
9861f022 RR |
2654 | |
2655 | if (HasFlag(wxDV_NO_HEADER)) | |
2656 | m_headerArea = NULL; | |
2657 | else | |
2658 | m_headerArea = new wxDataViewHeaderWindow( this, wxID_ANY ); | |
f554a14b | 2659 | |
4ed7af08 | 2660 | SetTargetWindow( m_clientArea ); |
f554a14b | 2661 | |
4ed7af08 | 2662 | wxBoxSizer *sizer = new wxBoxSizer( wxVERTICAL ); |
9861f022 RR |
2663 | if (m_headerArea) |
2664 | sizer->Add( m_headerArea, 0, wxGROW ); | |
4ed7af08 RR |
2665 | sizer->Add( m_clientArea, 1, wxGROW ); |
2666 | SetSizer( sizer ); | |
2667 | ||
2668 | return true; | |
2669 | } | |
2670 | ||
2671 | #ifdef __WXMSW__ | |
2672 | WXLRESULT wxDataViewCtrl::MSWWindowProc(WXUINT nMsg, | |
2673 | WXWPARAM wParam, | |
2674 | WXLPARAM lParam) | |
2675 | { | |
b910a8ad | 2676 | WXLRESULT rc = wxDataViewCtrlBase::MSWWindowProc(nMsg, wParam, lParam); |
4ed7af08 RR |
2677 | |
2678 | #ifndef __WXWINCE__ | |
2679 | // we need to process arrows ourselves for scrolling | |
2680 | if ( nMsg == WM_GETDLGCODE ) | |
2681 | { | |
2682 | rc |= DLGC_WANTARROWS; | |
2683 | } | |
2684 | #endif | |
2685 | ||
2686 | return rc; | |
2687 | } | |
2688 | #endif | |
2689 | ||
f554a14b | 2690 | void wxDataViewCtrl::OnSize( wxSizeEvent &WXUNUSED(event) ) |
4ed7af08 | 2691 | { |
4b3feaa7 RR |
2692 | // We need to override OnSize so that our scrolled |
2693 | // window a) does call Layout() to use sizers for | |
2694 | // positioning the controls but b) does not query | |
2695 | // the sizer for their size and use that for setting | |
2696 | // the scrollable area as set that ourselves by | |
2697 | // calling SetScrollbar() further down. | |
2698 | ||
2699 | Layout(); | |
2700 | ||
2701 | AdjustScrollbars(); | |
4ed7af08 RR |
2702 | } |
2703 | ||
2704 | bool wxDataViewCtrl::AssociateModel( wxDataViewListModel *model ) | |
2705 | { | |
2706 | if (!wxDataViewCtrlBase::AssociateModel( model )) | |
2707 | return false; | |
2708 | ||
a0f3af5f | 2709 | m_notifier = new wxGenericDataViewListModelNotifier( m_clientArea ); |
4ed7af08 | 2710 | |
f554a14b | 2711 | model->AddNotifier( m_notifier ); |
4ed7af08 | 2712 | |
4b3feaa7 | 2713 | m_clientArea->UpdateDisplay(); |
f554a14b | 2714 | |
4ed7af08 RR |
2715 | return true; |
2716 | } | |
2717 | ||
2718 | bool wxDataViewCtrl::AppendColumn( wxDataViewColumn *col ) | |
2719 | { | |
2720 | if (!wxDataViewCtrlBase::AppendColumn(col)) | |
2721 | return false; | |
f554a14b | 2722 | |
9861f022 | 2723 | OnColumnChange(); |
4ed7af08 RR |
2724 | return true; |
2725 | } | |
2726 | ||
9861f022 RR |
2727 | void wxDataViewCtrl::OnColumnChange() |
2728 | { | |
2729 | if (m_headerArea) | |
2730 | m_headerArea->UpdateDisplay(); | |
2731 | ||
2732 | m_clientArea->UpdateDisplay(); | |
2733 | } | |
2734 | ||
87f0efe2 | 2735 | void wxDataViewCtrl::SetSelection( int row ) |
6ff7eee7 | 2736 | { |
87f0efe2 | 2737 | m_clientArea->SelectRow(row, true); |
6ff7eee7 RR |
2738 | } |
2739 | ||
87f0efe2 | 2740 | void wxDataViewCtrl::SetSelectionRange( unsigned int from, unsigned int to ) |
6ff7eee7 | 2741 | { |
87f0efe2 | 2742 | m_clientArea->SelectRows(from, to, true); |
6ff7eee7 RR |
2743 | } |
2744 | ||
87f0efe2 | 2745 | void wxDataViewCtrl::SetSelections( const wxArrayInt& aSelections ) |
6ff7eee7 | 2746 | { |
87f0efe2 | 2747 | m_clientArea->Select(aSelections); |
6ff7eee7 | 2748 | } |
df387169 WS |
2749 | |
2750 | void wxDataViewCtrl::Unselect( unsigned int WXUNUSED(row) ) | |
fc211fe5 | 2751 | { |
df387169 | 2752 | // FIXME - TODO |
fc211fe5 RR |
2753 | } |
2754 | ||
df387169 | 2755 | bool wxDataViewCtrl::IsSelected( unsigned int WXUNUSED(row) ) const |
6ff7eee7 | 2756 | { |
df387169 WS |
2757 | // FIXME - TODO |
2758 | ||
6ff7eee7 RR |
2759 | return false; |
2760 | } | |
2761 | ||
2762 | int wxDataViewCtrl::GetSelection() const | |
2763 | { | |
df387169 WS |
2764 | // FIXME - TODO |
2765 | ||
6ff7eee7 RR |
2766 | return -1; |
2767 | } | |
2768 | ||
df387169 | 2769 | int wxDataViewCtrl::GetSelections(wxArrayInt& WXUNUSED(aSelections) ) const |
6ff7eee7 | 2770 | { |
df387169 WS |
2771 | // FIXME - TODO |
2772 | ||
6ff7eee7 RR |
2773 | return 0; |
2774 | } | |
2775 | ||
f554a14b | 2776 | #endif |
4ed7af08 RR |
2777 | // !wxUSE_GENERICDATAVIEWCTRL |
2778 | ||
f554a14b | 2779 | #endif |
4ed7af08 | 2780 | // wxUSE_DATAVIEWCTRL |