]>
Commit | Line | Data |
---|---|---|
c801d85f | 1 | ///////////////////////////////////////////////////////////////////////////// |
54442116 VZ |
2 | // Name: generic/listctrl.cpp |
3 | // Purpose: generic implementation of wxListCtrl | |
c801d85f | 4 | // Author: Robert Roebling |
cf1dfa6b | 5 | // Vadim Zeitlin (virtual list control support) |
0208334d RR |
6 | // Id: $Id$ |
7 | // Copyright: (c) 1998 Robert Roebling | |
bd8289c1 | 8 | // Licence: wxWindows licence |
c801d85f KB |
9 | ///////////////////////////////////////////////////////////////////////////// |
10 | ||
b54e41c5 | 11 | /* |
70541533 | 12 | TODO |
b54e41c5 | 13 | |
70541533 | 14 | 1. we need to implement searching/sorting for virtual controls somehow |
0a816d95 | 15 | ?2. when changing selection the lines are refreshed twice |
b54e41c5 VZ |
16 | */ |
17 | ||
1370703e VZ |
18 | // ============================================================================ |
19 | // declarations | |
20 | // ============================================================================ | |
21 | ||
22 | // ---------------------------------------------------------------------------- | |
23 | // headers | |
24 | // ---------------------------------------------------------------------------- | |
25 | ||
c801d85f | 26 | #ifdef __GNUG__ |
510fc784 RR |
27 | #pragma implementation "listctrl.h" |
28 | #pragma implementation "listctrlbase.h" | |
1e4d446b | 29 | #endif |
5cd89174 | 30 | |
1e6d9499 JS |
31 | // For compilers that support precompilation, includes "wx.h". |
32 | #include "wx/wxprec.h" | |
33 | ||
34 | #ifdef __BORLANDC__ | |
35 | #pragma hdrstop | |
36 | #endif | |
37 | ||
1e6feb95 VZ |
38 | #if wxUSE_LISTCTRL |
39 | ||
33b7a549 VZ |
40 | #ifndef WX_PRECOMP |
41 | #include "wx/app.h" | |
42 | ||
43 | #include "wx/dynarray.h" | |
44 | ||
45 | #include "wx/dcscreen.h" | |
46 | ||
47 | #include "wx/textctrl.h" | |
48 | #endif | |
49 | ||
b54e41c5 | 50 | #include "wx/imaglist.h" |
33b7a549 | 51 | #include "wx/listctrl.h" |
c801d85f | 52 | |
f16ba4e6 | 53 | #if defined(__WXGTK__) |
33b7a549 VZ |
54 | #include <gtk/gtk.h> |
55 | #include "wx/gtk/win_gtk.h" | |
3fb435df RR |
56 | #endif |
57 | ||
2e4df4bf VZ |
58 | // ---------------------------------------------------------------------------- |
59 | // events | |
60 | // ---------------------------------------------------------------------------- | |
61 | ||
62 | DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_BEGIN_DRAG) | |
63 | DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_BEGIN_RDRAG) | |
64 | DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_BEGIN_LABEL_EDIT) | |
65 | DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_END_LABEL_EDIT) | |
66 | DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_DELETE_ITEM) | |
67 | DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_DELETE_ALL_ITEMS) | |
68 | DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_GET_INFO) | |
69 | DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_SET_INFO) | |
70 | DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_ITEM_SELECTED) | |
71 | DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_ITEM_DESELECTED) | |
72 | DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_KEY_DOWN) | |
73 | DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_INSERT_ITEM) | |
74 | DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_COL_CLICK) | |
11358d39 VZ |
75 | DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_COL_RIGHT_CLICK) |
76 | DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_COL_BEGIN_DRAG) | |
77 | DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_COL_DRAGGING) | |
78 | DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_COL_END_DRAG) | |
2e4df4bf VZ |
79 | DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_ITEM_RIGHT_CLICK) |
80 | DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_ITEM_MIDDLE_CLICK) | |
81 | DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_ITEM_ACTIVATED) | |
0ddefeb0 | 82 | DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_ITEM_FOCUSED) |
614391dc | 83 | DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_CACHE_HINT) |
2e4df4bf | 84 | |
cf1dfa6b VZ |
85 | // ---------------------------------------------------------------------------- |
86 | // constants | |
87 | // ---------------------------------------------------------------------------- | |
88 | ||
89 | // the height of the header window (FIXME: should depend on its font!) | |
90 | static const int HEADER_HEIGHT = 23; | |
91 | ||
92 | // the scrollbar units | |
93 | static const int SCROLL_UNIT_X = 15; | |
94 | static const int SCROLL_UNIT_Y = 15; | |
95 | ||
96 | // the spacing between the lines (in report mode) | |
b54e41c5 | 97 | static const int LINE_SPACING = 0; |
cf1dfa6b VZ |
98 | |
99 | // extra margins around the text label | |
100 | static const int EXTRA_WIDTH = 3; | |
101 | static const int EXTRA_HEIGHT = 4; | |
102 | ||
103 | // offset for the header window | |
104 | static const int HEADER_OFFSET_X = 1; | |
105 | static const int HEADER_OFFSET_Y = 1; | |
106 | ||
107 | // when autosizing the columns, add some slack | |
108 | static const int AUTOSIZE_COL_MARGIN = 10; | |
109 | ||
110 | // default and minimal widths for the header columns | |
111 | static const int WIDTH_COL_DEFAULT = 80; | |
112 | static const int WIDTH_COL_MIN = 10; | |
113 | ||
06b781c7 VZ |
114 | // the space between the image and the text in the report mode |
115 | static const int IMAGE_MARGIN_IN_REPORT_MODE = 5; | |
116 | ||
efbb7287 VZ |
117 | // ============================================================================ |
118 | // private classes | |
119 | // ============================================================================ | |
120 | ||
b54e41c5 VZ |
121 | // ---------------------------------------------------------------------------- |
122 | // wxSelectionStore | |
123 | // ---------------------------------------------------------------------------- | |
124 | ||
125 | int CMPFUNC_CONV wxSizeTCmpFn(size_t n1, size_t n2) { return n1 - n2; } | |
126 | ||
5a1cad6e | 127 | WX_DEFINE_SORTED_EXPORTED_ARRAY_LONG(size_t, wxIndexArray); |
b54e41c5 VZ |
128 | |
129 | // this class is used to store the selected items in the virtual list control | |
130 | // (but it is not tied to list control and so can be used with other controls | |
131 | // such as wxListBox in wxUniv) | |
132 | // | |
133 | // the idea is to make it really smart later (i.e. store the selections as an | |
134 | // array of ranes + individual items) but, as I don't have time to do it now | |
135 | // (this would require writing code to merge/break ranges and much more) keep | |
136 | // it simple but define a clean interface to it which allows it to be made | |
137 | // smarter later | |
138 | class WXDLLEXPORT wxSelectionStore | |
139 | { | |
140 | public: | |
141 | wxSelectionStore() : m_itemsSel(wxSizeTCmpFn) { Init(); } | |
142 | ||
143 | // set the total number of items we handle | |
144 | void SetItemCount(size_t count) { m_count = count; } | |
145 | ||
146 | // special case of SetItemCount(0) | |
147 | void Clear() { m_itemsSel.Clear(); m_count = 0; } | |
148 | ||
149 | // must be called when a new item is inserted/added | |
150 | void OnItemAdd(size_t item) { wxFAIL_MSG( _T("TODO") ); } | |
151 | ||
152 | // must be called when an item is deleted | |
153 | void OnItemDelete(size_t item); | |
154 | ||
155 | // select one item, use SelectRange() insted if possible! | |
156 | // | |
157 | // returns true if the items selection really changed | |
158 | bool SelectItem(size_t item, bool select = TRUE); | |
159 | ||
160 | // select the range of items | |
68a9ef0e VZ |
161 | // |
162 | // return true and fill the itemsChanged array with the indices of items | |
163 | // which have changed state if "few" of them did, otherwise return false | |
164 | // (meaning that too many items changed state to bother counting them | |
165 | // individually) | |
166 | bool SelectRange(size_t itemFrom, size_t itemTo, | |
167 | bool select = TRUE, | |
168 | wxArrayInt *itemsChanged = NULL); | |
b54e41c5 VZ |
169 | |
170 | // return true if the given item is selected | |
171 | bool IsSelected(size_t item) const; | |
172 | ||
173 | // return the total number of selected items | |
174 | size_t GetSelectedCount() const | |
175 | { | |
176 | return m_defaultState ? m_count - m_itemsSel.GetCount() | |
177 | : m_itemsSel.GetCount(); | |
178 | } | |
179 | ||
180 | private: | |
181 | // (re)init | |
182 | void Init() { m_defaultState = FALSE; } | |
183 | ||
184 | // the total number of items we handle | |
185 | size_t m_count; | |
186 | ||
187 | // the default state: normally, FALSE (i.e. off) but maybe set to TRUE if | |
188 | // there are more selected items than non selected ones - this allows to | |
189 | // handle selection of all items efficiently | |
190 | bool m_defaultState; | |
191 | ||
192 | // the array of items whose selection state is different from default | |
193 | wxIndexArray m_itemsSel; | |
194 | ||
195 | DECLARE_NO_COPY_CLASS(wxSelectionStore) | |
196 | }; | |
197 | ||
efbb7287 VZ |
198 | //----------------------------------------------------------------------------- |
199 | // wxListItemData (internal) | |
200 | //----------------------------------------------------------------------------- | |
201 | ||
cf1dfa6b | 202 | class WXDLLEXPORT wxListItemData |
efbb7287 | 203 | { |
efbb7287 | 204 | public: |
cf1dfa6b | 205 | wxListItemData(wxListMainWindow *owner); |
850ed6e7 | 206 | ~wxListItemData(); |
efbb7287 | 207 | |
efbb7287 | 208 | void SetItem( const wxListItem &info ); |
cf1dfa6b VZ |
209 | void SetImage( int image ) { m_image = image; } |
210 | void SetData( long data ) { m_data = data; } | |
efbb7287 VZ |
211 | void SetPosition( int x, int y ); |
212 | void SetSize( int width, int height ); | |
54442116 VZ |
213 | |
214 | bool HasText() const { return !m_text.empty(); } | |
215 | const wxString& GetText() const { return m_text; } | |
216 | void SetText(const wxString& text) { m_text = text; } | |
217 | ||
cf1dfa6b VZ |
218 | // we can't use empty string for measuring the string width/height, so |
219 | // always return something | |
220 | wxString GetTextForMeasuring() const | |
221 | { | |
222 | wxString s = GetText(); | |
223 | if ( s.empty() ) | |
224 | s = _T('H'); | |
225 | ||
226 | return s; | |
227 | } | |
228 | ||
efbb7287 | 229 | bool IsHit( int x, int y ) const; |
54442116 | 230 | |
cf1dfa6b VZ |
231 | int GetX() const; |
232 | int GetY() const; | |
efbb7287 VZ |
233 | int GetWidth() const; |
234 | int GetHeight() const; | |
cf1dfa6b VZ |
235 | |
236 | int GetImage() const { return m_image; } | |
237 | bool HasImage() const { return GetImage() != -1; } | |
238 | ||
efbb7287 VZ |
239 | void GetItem( wxListItem &info ) const; |
240 | ||
6c02c329 VZ |
241 | void SetAttr(wxListItemAttr *attr) { m_attr = attr; } |
242 | wxListItemAttr *GetAttr() const { return m_attr; } | |
efbb7287 | 243 | |
54442116 | 244 | public: |
cf1dfa6b VZ |
245 | // the item image or -1 |
246 | int m_image; | |
247 | ||
248 | // user data associated with the item | |
249 | long m_data; | |
54442116 | 250 | |
cf1dfa6b VZ |
251 | // the item coordinates are not used in report mode, instead this pointer |
252 | // is NULL and the owner window is used to retrieve the item position and | |
253 | // size | |
254 | wxRect *m_rect; | |
255 | ||
256 | // the list ctrl we are in | |
257 | wxListMainWindow *m_owner; | |
258 | ||
259 | // custom attributes or NULL | |
54442116 VZ |
260 | wxListItemAttr *m_attr; |
261 | ||
262 | protected: | |
cf1dfa6b VZ |
263 | // common part of all ctors |
264 | void Init(); | |
54442116 | 265 | |
cf1dfa6b | 266 | wxString m_text; |
efbb7287 VZ |
267 | }; |
268 | ||
269 | //----------------------------------------------------------------------------- | |
270 | // wxListHeaderData (internal) | |
271 | //----------------------------------------------------------------------------- | |
272 | ||
273 | class WXDLLEXPORT wxListHeaderData : public wxObject | |
274 | { | |
efbb7287 VZ |
275 | public: |
276 | wxListHeaderData(); | |
277 | wxListHeaderData( const wxListItem &info ); | |
278 | void SetItem( const wxListItem &item ); | |
279 | void SetPosition( int x, int y ); | |
280 | void SetWidth( int w ); | |
281 | void SetFormat( int format ); | |
282 | void SetHeight( int h ); | |
283 | bool HasImage() const; | |
54442116 VZ |
284 | |
285 | bool HasText() const { return !m_text.empty(); } | |
286 | const wxString& GetText() const { return m_text; } | |
287 | void SetText(const wxString& text) { m_text = text; } | |
288 | ||
efbb7287 | 289 | void GetItem( wxListItem &item ); |
54442116 VZ |
290 | |
291 | bool IsHit( int x, int y ) const; | |
efbb7287 VZ |
292 | int GetImage() const; |
293 | int GetWidth() const; | |
294 | int GetFormat() const; | |
f6bcfd97 | 295 | |
0a816d95 VZ |
296 | protected: |
297 | long m_mask; | |
298 | int m_image; | |
299 | wxString m_text; | |
300 | int m_format; | |
301 | int m_width; | |
302 | int m_xpos, | |
303 | m_ypos; | |
304 | int m_height; | |
305 | ||
efbb7287 | 306 | private: |
0a816d95 | 307 | void Init(); |
efbb7287 VZ |
308 | }; |
309 | ||
310 | //----------------------------------------------------------------------------- | |
311 | // wxListLineData (internal) | |
312 | //----------------------------------------------------------------------------- | |
313 | ||
2c1f73ee VZ |
314 | WX_DECLARE_LIST(wxListItemData, wxListItemDataList); |
315 | #include "wx/listimpl.cpp" | |
316 | WX_DEFINE_LIST(wxListItemDataList); | |
317 | ||
cf1dfa6b | 318 | class WXDLLEXPORT wxListLineData |
efbb7287 VZ |
319 | { |
320 | public: | |
cf1dfa6b VZ |
321 | // the list of subitems: only may have more than one item in report mode |
322 | wxListItemDataList m_items; | |
323 | ||
324 | // this is not used in report view | |
325 | struct GeometryInfo | |
326 | { | |
327 | // total item rect | |
328 | wxRect m_rectAll; | |
329 | ||
330 | // label only | |
331 | wxRect m_rectLabel; | |
332 | ||
333 | // icon only | |
334 | wxRect m_rectIcon; | |
335 | ||
336 | // the part to be highlighted | |
b54e41c5 | 337 | wxRect m_rectHighlight; |
cf1dfa6b | 338 | } *m_gi; |
efbb7287 | 339 | |
cf1dfa6b | 340 | // is this item selected? [NB: not used in virtual mode] |
b54e41c5 | 341 | bool m_highlighted; |
cf1dfa6b VZ |
342 | |
343 | // back pointer to the list ctrl | |
344 | wxListMainWindow *m_owner; | |
efbb7287 VZ |
345 | |
346 | public: | |
5cd89174 | 347 | wxListLineData(wxListMainWindow *owner); |
cf1dfa6b VZ |
348 | |
349 | ~wxListLineData() { delete m_gi; } | |
350 | ||
351 | // are we in report mode? | |
352 | inline bool InReportView() const; | |
353 | ||
354 | // are we in virtual report mode? | |
b54e41c5 | 355 | inline bool IsVirtual() const; |
cf1dfa6b VZ |
356 | |
357 | // these 2 methods shouldn't be called for report view controls, in that | |
358 | // case we determine our position/size ourselves | |
359 | ||
360 | // calculate the size of the line | |
efbb7287 | 361 | void CalculateSize( wxDC *dc, int spacing ); |
cf1dfa6b VZ |
362 | |
363 | // remember the position this line appears at | |
364 | void SetPosition( int x, int y, int window_width, int spacing ); | |
365 | ||
5cd89174 VZ |
366 | // wxListCtrl API |
367 | ||
368 | void SetImage( int image ) { SetImage(0, image); } | |
369 | int GetImage() const { return GetImage(0); } | |
370 | bool HasImage() const { return GetImage() != -1; } | |
371 | bool HasText() const { return !GetText(0).empty(); } | |
cf1dfa6b | 372 | |
efbb7287 VZ |
373 | void SetItem( int index, const wxListItem &info ); |
374 | void GetItem( int index, wxListItem &info ); | |
cf1dfa6b | 375 | |
54442116 | 376 | wxString GetText(int index) const; |
efbb7287 | 377 | void SetText( int index, const wxString s ); |
cf1dfa6b | 378 | |
6c02c329 VZ |
379 | wxListItemAttr *GetAttr() const; |
380 | void SetAttr(wxListItemAttr *attr); | |
381 | ||
cf1dfa6b | 382 | // return true if the highlighting really changed |
b54e41c5 | 383 | bool Highlight( bool on ); |
cf1dfa6b | 384 | |
b54e41c5 | 385 | void ReverseHighlight(); |
cf1dfa6b | 386 | |
b54e41c5 | 387 | bool IsHighlighted() const |
cf1dfa6b | 388 | { |
b54e41c5 | 389 | wxASSERT_MSG( !IsVirtual(), _T("unexpected call to IsHighlighted") ); |
cf1dfa6b | 390 | |
b54e41c5 | 391 | return m_highlighted; |
cf1dfa6b VZ |
392 | } |
393 | ||
5cd89174 VZ |
394 | // draw the line on the given DC in icon/list mode |
395 | void Draw( wxDC *dc ); | |
396 | ||
397 | // the same in report mode | |
398 | void DrawInReportMode( wxDC *dc, | |
399 | const wxRect& rect, | |
400 | const wxRect& rectHL, | |
401 | bool highlighted ); | |
f6bcfd97 | 402 | |
efbb7287 | 403 | private: |
cf1dfa6b VZ |
404 | // set the line to contain num items (only can be > 1 in report mode) |
405 | void InitItems( int num ); | |
406 | ||
407 | // get the mode (i.e. style) of the list control | |
408 | inline int GetMode() const; | |
409 | ||
0e980f91 VZ |
410 | // prepare the DC for drawing with these item's attributes, return true if |
411 | // we need to draw the items background to highlight it, false otherwise | |
412 | bool SetAttributes(wxDC *dc, | |
efbb7287 | 413 | const wxListItemAttr *attr, |
b54e41c5 | 414 | bool highlight); |
efbb7287 | 415 | |
5cd89174 VZ |
416 | // these are only used by GetImage/SetImage above, we don't support images |
417 | // with subitems at the public API level yet | |
418 | void SetImage( int index, int image ); | |
419 | int GetImage( int index ) const; | |
efbb7287 VZ |
420 | }; |
421 | ||
f6bcfd97 BP |
422 | WX_DECLARE_EXPORTED_OBJARRAY(wxListLineData, wxListLineDataArray); |
423 | #include "wx/arrimpl.cpp" | |
424 | WX_DEFINE_OBJARRAY(wxListLineDataArray); | |
425 | ||
efbb7287 VZ |
426 | //----------------------------------------------------------------------------- |
427 | // wxListHeaderWindow (internal) | |
428 | //----------------------------------------------------------------------------- | |
429 | ||
430 | class WXDLLEXPORT wxListHeaderWindow : public wxWindow | |
431 | { | |
432 | protected: | |
433 | wxListMainWindow *m_owner; | |
434 | wxCursor *m_currentCursor; | |
435 | wxCursor *m_resizeCursor; | |
436 | bool m_isDragging; | |
f6bcfd97 | 437 | |
62313c27 | 438 | // column being resized or -1 |
f6bcfd97 BP |
439 | int m_column; |
440 | ||
441 | // divider line position in logical (unscrolled) coords | |
442 | int m_currentX; | |
443 | ||
444 | // minimal position beyond which the divider line can't be dragged in | |
445 | // logical coords | |
446 | int m_minX; | |
efbb7287 VZ |
447 | |
448 | public: | |
449 | wxListHeaderWindow(); | |
f6bcfd97 BP |
450 | |
451 | wxListHeaderWindow( wxWindow *win, | |
452 | wxWindowID id, | |
453 | wxListMainWindow *owner, | |
454 | const wxPoint &pos = wxDefaultPosition, | |
455 | const wxSize &size = wxDefaultSize, | |
456 | long style = 0, | |
457 | const wxString &name = "wxlistctrlcolumntitles" ); | |
458 | ||
0a816d95 VZ |
459 | virtual ~wxListHeaderWindow(); |
460 | ||
efbb7287 | 461 | void DoDrawRect( wxDC *dc, int x, int y, int w, int h ); |
efbb7287 | 462 | void DrawCurrent(); |
f6bcfd97 BP |
463 | void AdjustDC(wxDC& dc); |
464 | ||
465 | void OnPaint( wxPaintEvent &event ); | |
efbb7287 VZ |
466 | void OnMouse( wxMouseEvent &event ); |
467 | void OnSetFocus( wxFocusEvent &event ); | |
468 | ||
f6bcfd97 BP |
469 | // needs refresh |
470 | bool m_dirty; | |
471 | ||
efbb7287 | 472 | private: |
0a816d95 VZ |
473 | // common part of all ctors |
474 | void Init(); | |
475 | ||
a77ec46d RD |
476 | void SendListEvent(wxEventType type, wxPoint pos); |
477 | ||
efbb7287 VZ |
478 | DECLARE_DYNAMIC_CLASS(wxListHeaderWindow) |
479 | DECLARE_EVENT_TABLE() | |
480 | }; | |
481 | ||
482 | //----------------------------------------------------------------------------- | |
483 | // wxListRenameTimer (internal) | |
484 | //----------------------------------------------------------------------------- | |
485 | ||
486 | class WXDLLEXPORT wxListRenameTimer: public wxTimer | |
487 | { | |
488 | private: | |
1370703e | 489 | wxListMainWindow *m_owner; |
efbb7287 VZ |
490 | |
491 | public: | |
492 | wxListRenameTimer( wxListMainWindow *owner ); | |
493 | void Notify(); | |
494 | }; | |
495 | ||
496 | //----------------------------------------------------------------------------- | |
497 | // wxListTextCtrl (internal) | |
498 | //----------------------------------------------------------------------------- | |
499 | ||
500 | class WXDLLEXPORT wxListTextCtrl: public wxTextCtrl | |
501 | { | |
efbb7287 | 502 | public: |
62d89eb4 VZ |
503 | wxListTextCtrl(wxListMainWindow *owner, size_t itemEdit); |
504 | ||
505 | protected: | |
efbb7287 | 506 | void OnChar( wxKeyEvent &event ); |
c13cace1 | 507 | void OnKeyUp( wxKeyEvent &event ); |
efbb7287 VZ |
508 | void OnKillFocus( wxFocusEvent &event ); |
509 | ||
62d89eb4 VZ |
510 | bool AcceptChanges(); |
511 | void Finish(); | |
512 | ||
efbb7287 | 513 | private: |
62d89eb4 VZ |
514 | wxListMainWindow *m_owner; |
515 | wxString m_startValue; | |
516 | size_t m_itemEdited; | |
517 | bool m_finished; | |
518 | ||
efbb7287 VZ |
519 | DECLARE_EVENT_TABLE() |
520 | }; | |
521 | ||
522 | //----------------------------------------------------------------------------- | |
523 | // wxListMainWindow (internal) | |
524 | //----------------------------------------------------------------------------- | |
525 | ||
24b9f055 VZ |
526 | WX_DECLARE_LIST(wxListHeaderData, wxListHeaderDataList); |
527 | #include "wx/listimpl.cpp" | |
528 | WX_DEFINE_LIST(wxListHeaderDataList); | |
529 | ||
cf1dfa6b | 530 | class WXDLLEXPORT wxListMainWindow : public wxScrolledWindow |
efbb7287 | 531 | { |
efbb7287 VZ |
532 | public: |
533 | wxListMainWindow(); | |
1370703e VZ |
534 | wxListMainWindow( wxWindow *parent, |
535 | wxWindowID id, | |
536 | const wxPoint& pos = wxDefaultPosition, | |
537 | const wxSize& size = wxDefaultSize, | |
538 | long style = 0, | |
539 | const wxString &name = _T("listctrlmainwindow") ); | |
540 | ||
541 | virtual ~wxListMainWindow(); | |
542 | ||
cf1dfa6b VZ |
543 | bool HasFlag(int flag) const { return m_parent->HasFlag(flag); } |
544 | ||
1370703e | 545 | // return true if this is a virtual list control |
cf1dfa6b VZ |
546 | bool IsVirtual() const { return HasFlag(wxLC_VIRTUAL); } |
547 | ||
5cd89174 VZ |
548 | // return true if the control is in report mode |
549 | bool InReportView() const { return HasFlag(wxLC_REPORT); } | |
550 | ||
b54e41c5 VZ |
551 | // return true if we are in single selection mode, false if multi sel |
552 | bool IsSingleSel() const { return HasFlag(wxLC_SINGLE_SEL); } | |
553 | ||
cf1dfa6b VZ |
554 | // do we have a header window? |
555 | bool HasHeader() const | |
556 | { return HasFlag(wxLC_REPORT) && !HasFlag(wxLC_NO_HEADER); } | |
1370703e | 557 | |
b54e41c5 | 558 | void HighlightAll( bool on ); |
cf1dfa6b VZ |
559 | |
560 | // all these functions only do something if the line is currently visible | |
561 | ||
562 | // change the line "selected" state, return TRUE if it really changed | |
b54e41c5 VZ |
563 | bool HighlightLine( size_t line, bool highlight = TRUE); |
564 | ||
565 | // as HighlightLine() but do it for the range of lines: this is incredibly | |
566 | // more efficient for virtual list controls! | |
567 | // | |
568 | // NB: unlike HighlightLine() this one does refresh the lines on screen | |
569 | void HighlightLines( size_t lineFrom, size_t lineTo, bool on = TRUE ); | |
cf1dfa6b VZ |
570 | |
571 | // toggle the line state and refresh it | |
b54e41c5 VZ |
572 | void ReverseHighlight( size_t line ) |
573 | { HighlightLine(line, !IsHighlighted(line)); RefreshLine(line); } | |
cf1dfa6b | 574 | |
6b4a8d93 VZ |
575 | // return true if the line is highlighted |
576 | bool IsHighlighted(size_t line) const; | |
577 | ||
cf1dfa6b VZ |
578 | // refresh one or several lines at once |
579 | void RefreshLine( size_t line ); | |
580 | void RefreshLines( size_t lineFrom, size_t lineTo ); | |
581 | ||
49ecb029 VZ |
582 | // refresh all selected items |
583 | void RefreshSelected(); | |
584 | ||
6b4a8d93 VZ |
585 | // refresh all lines below the given one: the difference with |
586 | // RefreshLines() is that the index here might not be a valid one (happens | |
587 | // when the last line is deleted) | |
588 | void RefreshAfter( size_t lineFrom ); | |
efbb7287 | 589 | |
5cd89174 VZ |
590 | // the methods which are forwarded to wxListLineData itself in list/icon |
591 | // modes but are here because the lines don't store their positions in the | |
592 | // report mode | |
593 | ||
594 | // get the bound rect for the entire line | |
595 | wxRect GetLineRect(size_t line) const; | |
596 | ||
597 | // get the bound rect of the label | |
598 | wxRect GetLineLabelRect(size_t line) const; | |
599 | ||
600 | // get the bound rect of the items icon (only may be called if we do have | |
601 | // an icon!) | |
602 | wxRect GetLineIconRect(size_t line) const; | |
603 | ||
604 | // get the rect to be highlighted when the item has focus | |
605 | wxRect GetLineHighlightRect(size_t line) const; | |
606 | ||
607 | // get the size of the total line rect | |
608 | wxSize GetLineSize(size_t line) const | |
609 | { return GetLineRect(line).GetSize(); } | |
610 | ||
611 | // return the hit code for the corresponding position (in this line) | |
612 | long HitTestLine(size_t line, int x, int y) const; | |
613 | ||
34bbbc27 VZ |
614 | // bring the selected item into view, scrolling to it if necessary |
615 | void MoveToItem(size_t item); | |
616 | ||
617 | // bring the current item into view | |
618 | void MoveToFocus() { MoveToItem(m_current); } | |
619 | ||
c5c528fc | 620 | // start editing the label of the given item |
efbb7287 | 621 | void EditLabel( long item ); |
c5c528fc VZ |
622 | |
623 | // suspend/resume redrawing the control | |
624 | void Freeze(); | |
625 | void Thaw(); | |
a77ec46d | 626 | |
a6d57d03 | 627 | void SetFocus(); |
c5c528fc | 628 | |
efbb7287 | 629 | void OnRenameTimer(); |
62d89eb4 | 630 | bool OnRenameAccept(size_t itemEdit, const wxString& value); |
efbb7287 VZ |
631 | |
632 | void OnMouse( wxMouseEvent &event ); | |
cf1dfa6b VZ |
633 | |
634 | // called to switch the selection from the current item to newCurrent, | |
635 | void OnArrowChar( size_t newCurrent, const wxKeyEvent& event ); | |
636 | ||
efbb7287 VZ |
637 | void OnChar( wxKeyEvent &event ); |
638 | void OnKeyDown( wxKeyEvent &event ); | |
639 | void OnSetFocus( wxFocusEvent &event ); | |
640 | void OnKillFocus( wxFocusEvent &event ); | |
efbb7287 | 641 | void OnScroll(wxScrollWinEvent& event) ; |
f6bcfd97 | 642 | |
cf1dfa6b VZ |
643 | void OnPaint( wxPaintEvent &event ); |
644 | ||
efbb7287 | 645 | void DrawImage( int index, wxDC *dc, int x, int y ); |
5cd89174 VZ |
646 | void GetImageSize( int index, int &width, int &height ) const; |
647 | int GetTextLength( const wxString &s ) const; | |
efbb7287 VZ |
648 | |
649 | void SetImageList( wxImageList *imageList, int which ); | |
650 | void SetItemSpacing( int spacing, bool isSmall = FALSE ); | |
651 | int GetItemSpacing( bool isSmall = FALSE ); | |
cf1dfa6b | 652 | |
efbb7287 VZ |
653 | void SetColumn( int col, wxListItem &item ); |
654 | void SetColumnWidth( int col, int width ); | |
cf1dfa6b VZ |
655 | void GetColumn( int col, wxListItem &item ) const; |
656 | int GetColumnWidth( int col ) const; | |
657 | int GetColumnCount() const { return m_columns.GetCount(); } | |
658 | ||
659 | // returns the sum of the heights of all columns | |
660 | int GetHeaderWidth() const; | |
661 | ||
5cd89174 | 662 | int GetCountPerPage() const; |
cf1dfa6b | 663 | |
efbb7287 | 664 | void SetItem( wxListItem &item ); |
62d89eb4 | 665 | void GetItem( wxListItem &item ) const; |
efbb7287 | 666 | void SetItemState( long item, long state, long stateMask ); |
62d89eb4 VZ |
667 | int GetItemState( long item, long stateMask ) const; |
668 | void GetItemRect( long index, wxRect &rect ) const; | |
669 | bool GetItemPosition( long item, wxPoint& pos ) const; | |
670 | int GetSelectedItemCount() const; | |
671 | ||
672 | wxString GetItemText(long item) const | |
673 | { | |
674 | wxListItem info; | |
675 | info.m_itemId = item; | |
676 | GetItem( info ); | |
677 | return info.m_text; | |
678 | } | |
679 | ||
680 | void SetItemText(long item, const wxString& value) | |
681 | { | |
682 | wxListItem info; | |
683 | info.m_mask = wxLIST_MASK_TEXT; | |
684 | info.m_itemId = item; | |
685 | info.m_text = value; | |
686 | SetItem( info ); | |
687 | } | |
cf1dfa6b VZ |
688 | |
689 | // set the scrollbars and update the positions of the items | |
34bbbc27 | 690 | void RecalculatePositions(bool noRefresh = FALSE); |
b54e41c5 VZ |
691 | |
692 | // refresh the window and the header | |
693 | void RefreshAll(); | |
cf1dfa6b | 694 | |
62d89eb4 | 695 | long GetNextItem( long item, int geometry, int state ) const; |
efbb7287 VZ |
696 | void DeleteItem( long index ); |
697 | void DeleteAllItems(); | |
698 | void DeleteColumn( int col ); | |
699 | void DeleteEverything(); | |
700 | void EnsureVisible( long index ); | |
701 | long FindItem( long start, const wxString& str, bool partial = FALSE ); | |
702 | long FindItem( long start, long data); | |
703 | long HitTest( int x, int y, int &flags ); | |
704 | void InsertItem( wxListItem &item ); | |
efbb7287 | 705 | void InsertColumn( long col, wxListItem &item ); |
efbb7287 VZ |
706 | void SortItems( wxListCtrlCompare fn, long data ); |
707 | ||
cf1dfa6b | 708 | size_t GetItemCount() const; |
1370703e | 709 | bool IsEmpty() const { return GetItemCount() == 0; } |
2c1f73ee VZ |
710 | void SetItemCount(long count); |
711 | ||
0ddefeb0 VZ |
712 | // change the current (== focused) item, send a notification event |
713 | void ChangeCurrent(size_t current); | |
714 | void ResetCurrent() { ChangeCurrent((size_t)-1); } | |
cf1dfa6b VZ |
715 | bool HasCurrent() const { return m_current != (size_t)-1; } |
716 | ||
717 | // send out a wxListEvent | |
718 | void SendNotify( size_t line, | |
719 | wxEventType command, | |
720 | wxPoint point = wxDefaultPosition ); | |
721 | ||
b54e41c5 VZ |
722 | // override base class virtual to reset m_lineHeight when the font changes |
723 | virtual bool SetFont(const wxFont& font) | |
724 | { | |
725 | if ( !wxScrolledWindow::SetFont(font) ) | |
726 | return FALSE; | |
727 | ||
728 | m_lineHeight = 0; | |
729 | ||
730 | return TRUE; | |
731 | } | |
cf1dfa6b VZ |
732 | |
733 | // these are for wxListLineData usage only | |
734 | ||
735 | // get the backpointer to the list ctrl | |
736 | wxListCtrl *GetListCtrl() const | |
737 | { | |
738 | return wxStaticCast(GetParent(), wxListCtrl); | |
739 | } | |
740 | ||
741 | // get the height of all lines (assuming they all do have the same height) | |
742 | wxCoord GetLineHeight() const; | |
743 | ||
744 | // get the y position of the given line (only for report view) | |
745 | wxCoord GetLineY(size_t line) const; | |
746 | ||
49ecb029 VZ |
747 | // get the brush to use for the item highlighting |
748 | wxBrush *GetHighlightBrush() const | |
749 | { | |
750 | return m_hasFocus ? m_highlightBrush : m_highlightUnfocusedBrush; | |
751 | } | |
752 | ||
cf1dfa6b VZ |
753 | //protected: |
754 | // the array of all line objects for a non virtual list control | |
755 | wxListLineDataArray m_lines; | |
756 | ||
757 | // the list of column objects | |
758 | wxListHeaderDataList m_columns; | |
759 | ||
760 | // currently focused item or -1 | |
761 | size_t m_current; | |
762 | ||
cf1dfa6b VZ |
763 | // the number of lines per page |
764 | int m_linesPerPage; | |
765 | ||
766 | // this flag is set when something which should result in the window | |
767 | // redrawing happens (i.e. an item was added or deleted, or its appearance | |
768 | // changed) and OnPaint() doesn't redraw the window while it is set which | |
769 | // allows to minimize the number of repaintings when a lot of items are | |
770 | // being added. The real repainting occurs only after the next OnIdle() | |
771 | // call | |
772 | bool m_dirty; | |
773 | ||
b54e41c5 | 774 | wxColour *m_highlightColour; |
cf1dfa6b VZ |
775 | int m_xScroll, |
776 | m_yScroll; | |
777 | wxImageList *m_small_image_list; | |
778 | wxImageList *m_normal_image_list; | |
779 | int m_small_spacing; | |
780 | int m_normal_spacing; | |
781 | bool m_hasFocus; | |
782 | ||
783 | bool m_lastOnSame; | |
784 | wxTimer *m_renameTimer; | |
cf1dfa6b VZ |
785 | bool m_isCreated; |
786 | int m_dragCount; | |
787 | wxPoint m_dragStart; | |
788 | ||
789 | // for double click logic | |
790 | size_t m_lineLastClicked, | |
791 | m_lineBeforeLastClicked; | |
792 | ||
1370703e | 793 | protected: |
cf1dfa6b | 794 | // the total count of items in a virtual list control |
b54e41c5 | 795 | size_t m_countVirt; |
cf1dfa6b | 796 | |
b54e41c5 VZ |
797 | // the object maintaining the items selection state, only used in virtual |
798 | // controls | |
799 | wxSelectionStore m_selStore; | |
cf1dfa6b | 800 | |
1370703e VZ |
801 | // common part of all ctors |
802 | void Init(); | |
803 | ||
cf1dfa6b VZ |
804 | // intiialize m_[xy]Scroll |
805 | void InitScrolling(); | |
806 | ||
1370703e VZ |
807 | // get the line data for the given index |
808 | wxListLineData *GetLine(size_t n) const | |
809 | { | |
810 | wxASSERT_MSG( n != (size_t)-1, _T("invalid line index") ); | |
811 | ||
cf1dfa6b VZ |
812 | if ( IsVirtual() ) |
813 | { | |
814 | wxConstCast(this, wxListMainWindow)->CacheLineData(n); | |
815 | ||
816 | n = 0; | |
817 | } | |
818 | ||
1370703e VZ |
819 | return &m_lines[n]; |
820 | } | |
821 | ||
b54e41c5 VZ |
822 | // get a dummy line which can be used for geometry calculations and such: |
823 | // you must use GetLine() if you want to really draw the line | |
824 | wxListLineData *GetDummyLine() const; | |
cf1dfa6b VZ |
825 | |
826 | // cache the line data of the n-th line in m_lines[0] | |
827 | void CacheLineData(size_t line); | |
828 | ||
b54e41c5 VZ |
829 | // get the range of visible lines |
830 | void GetVisibleLinesRange(size_t *from, size_t *to); | |
831 | ||
832 | // force us to recalculate the range of visible lines | |
833 | void ResetVisibleLinesRange() { m_lineFrom = (size_t)-1; } | |
834 | ||
835 | // get the colour to be used for drawing the rules | |
836 | wxColour GetRuleColour() const | |
837 | { | |
838 | #ifdef __WXMAC__ | |
839 | return *wxWHITE; | |
840 | #else | |
a756f210 | 841 | return wxSystemSettings::GetColour(wxSYS_COLOUR_3DLIGHT); |
b54e41c5 VZ |
842 | #endif |
843 | } | |
cf1dfa6b | 844 | |
efbb7287 | 845 | private: |
cf1dfa6b VZ |
846 | // initialize the current item if needed |
847 | void UpdateCurrent(); | |
848 | ||
5fe143df VZ |
849 | // delete all items but don't refresh: called from dtor |
850 | void DoDeleteAllItems(); | |
851 | ||
cf1dfa6b VZ |
852 | // the height of one line using the current font |
853 | wxCoord m_lineHeight; | |
854 | ||
855 | // the total header width or 0 if not calculated yet | |
856 | wxCoord m_headerWidth; | |
857 | ||
b54e41c5 VZ |
858 | // the first and last lines being shown on screen right now (inclusive), |
859 | // both may be -1 if they must be calculated so never access them directly: | |
860 | // use GetVisibleLinesRange() above instead | |
861 | size_t m_lineFrom, | |
862 | m_lineTo; | |
863 | ||
49ecb029 VZ |
864 | // the brushes to use for item highlighting when we do/don't have focus |
865 | wxBrush *m_highlightBrush, | |
866 | *m_highlightUnfocusedBrush; | |
867 | ||
c5c528fc VZ |
868 | // if this is > 0, the control is frozen and doesn't redraw itself |
869 | size_t m_freezeCount; | |
870 | ||
5a1cad6e | 871 | DECLARE_DYNAMIC_CLASS(wxListMainWindow) |
efbb7287 VZ |
872 | DECLARE_EVENT_TABLE() |
873 | }; | |
874 | ||
875 | // ============================================================================ | |
876 | // implementation | |
877 | // ============================================================================ | |
878 | ||
b54e41c5 VZ |
879 | // ---------------------------------------------------------------------------- |
880 | // wxSelectionStore | |
881 | // ---------------------------------------------------------------------------- | |
882 | ||
883 | bool wxSelectionStore::IsSelected(size_t item) const | |
884 | { | |
885 | bool isSel = m_itemsSel.Index(item) != wxNOT_FOUND; | |
886 | ||
887 | // if the default state is to be selected, being in m_itemsSel means that | |
888 | // the item is not selected, so we have to inverse the logic | |
889 | return m_defaultState ? !isSel : isSel; | |
890 | } | |
891 | ||
892 | bool wxSelectionStore::SelectItem(size_t item, bool select) | |
893 | { | |
894 | // search for the item ourselves as like this we get the index where to | |
895 | // insert it later if needed, so we do only one search in the array instead | |
896 | // of two (adding item to a sorted array requires a search) | |
897 | size_t index = m_itemsSel.IndexForInsert(item); | |
898 | bool isSel = index < m_itemsSel.GetCount() && m_itemsSel[index] == item; | |
899 | ||
900 | if ( select != m_defaultState ) | |
901 | { | |
902 | if ( !isSel ) | |
903 | { | |
904 | m_itemsSel.AddAt(item, index); | |
905 | ||
906 | return TRUE; | |
907 | } | |
908 | } | |
909 | else // reset to default state | |
910 | { | |
911 | if ( isSel ) | |
912 | { | |
913 | m_itemsSel.RemoveAt(index); | |
914 | return TRUE; | |
915 | } | |
916 | } | |
917 | ||
918 | return FALSE; | |
919 | } | |
920 | ||
68a9ef0e VZ |
921 | bool wxSelectionStore::SelectRange(size_t itemFrom, size_t itemTo, |
922 | bool select, | |
923 | wxArrayInt *itemsChanged) | |
b54e41c5 | 924 | { |
68a9ef0e VZ |
925 | // 100 is hardcoded but it shouldn't matter much: the important thing is |
926 | // that we don't refresh everything when really few (e.g. 1 or 2) items | |
927 | // change state | |
928 | static const size_t MANY_ITEMS = 100; | |
929 | ||
b54e41c5 VZ |
930 | wxASSERT_MSG( itemFrom <= itemTo, _T("should be in order") ); |
931 | ||
932 | // are we going to have more [un]selected items than the other ones? | |
68a9ef0e | 933 | if ( itemTo - itemFrom > m_count/2 ) |
b54e41c5 VZ |
934 | { |
935 | if ( select != m_defaultState ) | |
936 | { | |
937 | // the default state now becomes the same as 'select' | |
938 | m_defaultState = select; | |
939 | ||
940 | // so all the old selections (which had state select) shouldn't be | |
941 | // selected any more, but all the other ones should | |
942 | wxIndexArray selOld = m_itemsSel; | |
943 | m_itemsSel.Empty(); | |
944 | ||
945 | // TODO: it should be possible to optimize the searches a bit | |
946 | // knowing the possible range | |
947 | ||
948 | size_t item; | |
949 | for ( item = 0; item < itemFrom; item++ ) | |
950 | { | |
951 | if ( selOld.Index(item) == wxNOT_FOUND ) | |
952 | m_itemsSel.Add(item); | |
953 | } | |
954 | ||
955 | for ( item = itemTo + 1; item < m_count; item++ ) | |
956 | { | |
957 | if ( selOld.Index(item) == wxNOT_FOUND ) | |
958 | m_itemsSel.Add(item); | |
959 | } | |
68a9ef0e VZ |
960 | |
961 | // many items (> half) changed state | |
962 | itemsChanged = NULL; | |
b54e41c5 VZ |
963 | } |
964 | else // select == m_defaultState | |
965 | { | |
966 | // get the inclusive range of items between itemFrom and itemTo | |
967 | size_t count = m_itemsSel.GetCount(), | |
968 | start = m_itemsSel.IndexForInsert(itemFrom), | |
969 | end = m_itemsSel.IndexForInsert(itemTo); | |
970 | ||
971 | if ( start == count || m_itemsSel[start] < itemFrom ) | |
972 | { | |
973 | start++; | |
974 | } | |
975 | ||
976 | if ( end == count || m_itemsSel[end] > itemTo ) | |
977 | { | |
978 | end--; | |
979 | } | |
980 | ||
981 | if ( start <= end ) | |
982 | { | |
983 | // delete all of them (from end to avoid changing indices) | |
984 | for ( int i = end; i >= (int)start; i-- ) | |
985 | { | |
68a9ef0e VZ |
986 | if ( itemsChanged ) |
987 | { | |
988 | if ( itemsChanged->GetCount() > MANY_ITEMS ) | |
989 | { | |
990 | // stop counting (see comment below) | |
991 | itemsChanged = NULL; | |
992 | } | |
ae0d8c14 VZ |
993 | else |
994 | { | |
995 | itemsChanged->Add(m_itemsSel[i]); | |
996 | } | |
68a9ef0e VZ |
997 | } |
998 | ||
b54e41c5 VZ |
999 | m_itemsSel.RemoveAt(i); |
1000 | } | |
1001 | } | |
1002 | } | |
1003 | } | |
1004 | else // "few" items change state | |
1005 | { | |
68a9ef0e VZ |
1006 | if ( itemsChanged ) |
1007 | { | |
1008 | itemsChanged->Empty(); | |
1009 | } | |
1010 | ||
b54e41c5 VZ |
1011 | // just add the items to the selection |
1012 | for ( size_t item = itemFrom; item <= itemTo; item++ ) | |
1013 | { | |
68a9ef0e VZ |
1014 | if ( SelectItem(item, select) && itemsChanged ) |
1015 | { | |
1016 | itemsChanged->Add(item); | |
1017 | ||
1018 | if ( itemsChanged->GetCount() > MANY_ITEMS ) | |
1019 | { | |
1020 | // stop counting them, we'll just eat gobs of memory | |
1021 | // for nothing at all - faster to refresh everything in | |
1022 | // this case | |
1023 | itemsChanged = NULL; | |
1024 | } | |
1025 | } | |
b54e41c5 VZ |
1026 | } |
1027 | } | |
68a9ef0e VZ |
1028 | |
1029 | // we set it to NULL if there are many items changing state | |
1030 | return itemsChanged != NULL; | |
b54e41c5 VZ |
1031 | } |
1032 | ||
1033 | void wxSelectionStore::OnItemDelete(size_t item) | |
1034 | { | |
1035 | size_t count = m_itemsSel.GetCount(), | |
1036 | i = m_itemsSel.IndexForInsert(item); | |
1037 | ||
1038 | if ( i < count && m_itemsSel[i] == item ) | |
1039 | { | |
1040 | // this item itself was in m_itemsSel, remove it from there | |
1041 | m_itemsSel.RemoveAt(i); | |
938b652b VZ |
1042 | |
1043 | count--; | |
b54e41c5 VZ |
1044 | } |
1045 | ||
1046 | // and adjust the index of all which follow it | |
1047 | while ( i < count ) | |
1048 | { | |
1049 | // all following elements must be greater than the one we deleted | |
1050 | wxASSERT_MSG( m_itemsSel[i] > item, _T("logic error") ); | |
1051 | ||
1052 | m_itemsSel[i++]--; | |
1053 | } | |
1054 | } | |
1055 | ||
c801d85f KB |
1056 | //----------------------------------------------------------------------------- |
1057 | // wxListItemData | |
1058 | //----------------------------------------------------------------------------- | |
1059 | ||
850ed6e7 VZ |
1060 | wxListItemData::~wxListItemData() |
1061 | { | |
1062 | // in the virtual list control the attributes are managed by the main | |
1063 | // program, so don't delete them | |
1064 | if ( !m_owner->IsVirtual() ) | |
1065 | { | |
1066 | delete m_attr; | |
1067 | } | |
1068 | ||
1069 | delete m_rect; | |
1070 | } | |
1071 | ||
cf1dfa6b | 1072 | void wxListItemData::Init() |
c801d85f | 1073 | { |
92976ab6 RR |
1074 | m_image = -1; |
1075 | m_data = 0; | |
cf1dfa6b | 1076 | |
0530737d | 1077 | m_attr = NULL; |
e1e955e1 | 1078 | } |
c801d85f | 1079 | |
cf1dfa6b | 1080 | wxListItemData::wxListItemData(wxListMainWindow *owner) |
c801d85f | 1081 | { |
cf1dfa6b | 1082 | Init(); |
0530737d | 1083 | |
cf1dfa6b VZ |
1084 | m_owner = owner; |
1085 | ||
850ed6e7 | 1086 | if ( owner->InReportView() ) |
cf1dfa6b VZ |
1087 | { |
1088 | m_rect = NULL; | |
1089 | } | |
1090 | else | |
1091 | { | |
1092 | m_rect = new wxRect; | |
1093 | } | |
e1e955e1 | 1094 | } |
c801d85f KB |
1095 | |
1096 | void wxListItemData::SetItem( const wxListItem &info ) | |
1097 | { | |
cf1dfa6b | 1098 | if ( info.m_mask & wxLIST_MASK_TEXT ) |
54442116 | 1099 | SetText(info.m_text); |
cf1dfa6b | 1100 | if ( info.m_mask & wxLIST_MASK_IMAGE ) |
54442116 | 1101 | m_image = info.m_image; |
cf1dfa6b | 1102 | if ( info.m_mask & wxLIST_MASK_DATA ) |
54442116 | 1103 | m_data = info.m_data; |
0530737d VZ |
1104 | |
1105 | if ( info.HasAttributes() ) | |
1106 | { | |
1107 | if ( m_attr ) | |
1108 | *m_attr = *info.GetAttributes(); | |
1109 | else | |
1110 | m_attr = new wxListItemAttr(*info.GetAttributes()); | |
1111 | } | |
1112 | ||
cf1dfa6b VZ |
1113 | if ( m_rect ) |
1114 | { | |
1115 | m_rect->x = | |
1116 | m_rect->y = | |
1117 | m_rect->height = 0; | |
1118 | m_rect->width = info.m_width; | |
1119 | } | |
e1e955e1 | 1120 | } |
c801d85f | 1121 | |
debe6624 | 1122 | void wxListItemData::SetPosition( int x, int y ) |
c801d85f | 1123 | { |
cf1dfa6b VZ |
1124 | wxCHECK_RET( m_rect, _T("unexpected SetPosition() call") ); |
1125 | ||
1126 | m_rect->x = x; | |
1127 | m_rect->y = y; | |
e1e955e1 | 1128 | } |
c801d85f | 1129 | |
1e6d9499 | 1130 | void wxListItemData::SetSize( int width, int height ) |
c801d85f | 1131 | { |
cf1dfa6b | 1132 | wxCHECK_RET( m_rect, _T("unexpected SetSize() call") ); |
c801d85f | 1133 | |
cf1dfa6b VZ |
1134 | if ( width != -1 ) |
1135 | m_rect->width = width; | |
1136 | if ( height != -1 ) | |
1137 | m_rect->height = height; | |
e1e955e1 | 1138 | } |
c801d85f | 1139 | |
debe6624 | 1140 | bool wxListItemData::IsHit( int x, int y ) const |
c801d85f | 1141 | { |
cf1dfa6b VZ |
1142 | wxCHECK_MSG( m_rect, FALSE, _T("can't be called in this mode") ); |
1143 | ||
1144 | return wxRect(GetX(), GetY(), GetWidth(), GetHeight()).Inside(x, y); | |
e1e955e1 | 1145 | } |
c801d85f | 1146 | |
fd9811b1 | 1147 | int wxListItemData::GetX() const |
c801d85f | 1148 | { |
cf1dfa6b VZ |
1149 | wxCHECK_MSG( m_rect, 0, _T("can't be called in this mode") ); |
1150 | ||
1151 | return m_rect->x; | |
e1e955e1 | 1152 | } |
c801d85f | 1153 | |
fd9811b1 | 1154 | int wxListItemData::GetY() const |
c801d85f | 1155 | { |
cf1dfa6b VZ |
1156 | wxCHECK_MSG( m_rect, 0, _T("can't be called in this mode") ); |
1157 | ||
1158 | return m_rect->y; | |
e1e955e1 | 1159 | } |
c801d85f | 1160 | |
fd9811b1 | 1161 | int wxListItemData::GetWidth() const |
c801d85f | 1162 | { |
cf1dfa6b VZ |
1163 | wxCHECK_MSG( m_rect, 0, _T("can't be called in this mode") ); |
1164 | ||
1165 | return m_rect->width; | |
e1e955e1 | 1166 | } |
c801d85f | 1167 | |
fd9811b1 | 1168 | int wxListItemData::GetHeight() const |
c801d85f | 1169 | { |
cf1dfa6b | 1170 | wxCHECK_MSG( m_rect, 0, _T("can't be called in this mode") ); |
c801d85f | 1171 | |
cf1dfa6b | 1172 | return m_rect->height; |
e1e955e1 | 1173 | } |
c801d85f | 1174 | |
0530737d | 1175 | void wxListItemData::GetItem( wxListItem &info ) const |
c801d85f | 1176 | { |
92976ab6 RR |
1177 | info.m_text = m_text; |
1178 | info.m_image = m_image; | |
1179 | info.m_data = m_data; | |
c801d85f | 1180 | |
0530737d VZ |
1181 | if ( m_attr ) |
1182 | { | |
1183 | if ( m_attr->HasTextColour() ) | |
1184 | info.SetTextColour(m_attr->GetTextColour()); | |
1185 | if ( m_attr->HasBackgroundColour() ) | |
1186 | info.SetBackgroundColour(m_attr->GetBackgroundColour()); | |
1187 | if ( m_attr->HasFont() ) | |
1188 | info.SetFont(m_attr->GetFont()); | |
1189 | } | |
e1e955e1 | 1190 | } |
c801d85f KB |
1191 | |
1192 | //----------------------------------------------------------------------------- | |
1193 | // wxListHeaderData | |
1194 | //----------------------------------------------------------------------------- | |
1195 | ||
0a816d95 | 1196 | void wxListHeaderData::Init() |
c801d85f | 1197 | { |
92976ab6 | 1198 | m_mask = 0; |
0a816d95 | 1199 | m_image = -1; |
92976ab6 RR |
1200 | m_format = 0; |
1201 | m_width = 0; | |
1202 | m_xpos = 0; | |
1203 | m_ypos = 0; | |
1204 | m_height = 0; | |
e1e955e1 | 1205 | } |
c801d85f | 1206 | |
0a816d95 VZ |
1207 | wxListHeaderData::wxListHeaderData() |
1208 | { | |
1209 | Init(); | |
1210 | } | |
1211 | ||
c801d85f KB |
1212 | wxListHeaderData::wxListHeaderData( const wxListItem &item ) |
1213 | { | |
0a816d95 VZ |
1214 | Init(); |
1215 | ||
92976ab6 | 1216 | SetItem( item ); |
e1e955e1 | 1217 | } |
c801d85f KB |
1218 | |
1219 | void wxListHeaderData::SetItem( const wxListItem &item ) | |
1220 | { | |
92976ab6 | 1221 | m_mask = item.m_mask; |
cf1dfa6b | 1222 | |
0a816d95 VZ |
1223 | if ( m_mask & wxLIST_MASK_TEXT ) |
1224 | m_text = item.m_text; | |
1225 | ||
1226 | if ( m_mask & wxLIST_MASK_IMAGE ) | |
1227 | m_image = item.m_image; | |
1228 | ||
1229 | if ( m_mask & wxLIST_MASK_FORMAT ) | |
1230 | m_format = item.m_format; | |
1231 | ||
1232 | if ( m_mask & wxLIST_MASK_WIDTH ) | |
1233 | SetWidth(item.m_width); | |
e1e955e1 | 1234 | } |
c801d85f | 1235 | |
debe6624 | 1236 | void wxListHeaderData::SetPosition( int x, int y ) |
c801d85f | 1237 | { |
92976ab6 RR |
1238 | m_xpos = x; |
1239 | m_ypos = y; | |
e1e955e1 | 1240 | } |
c801d85f | 1241 | |
debe6624 | 1242 | void wxListHeaderData::SetHeight( int h ) |
c801d85f | 1243 | { |
92976ab6 | 1244 | m_height = h; |
e1e955e1 | 1245 | } |
c801d85f | 1246 | |
debe6624 | 1247 | void wxListHeaderData::SetWidth( int w ) |
c801d85f | 1248 | { |
92976ab6 | 1249 | m_width = w; |
cf1dfa6b VZ |
1250 | if (m_width < 0) |
1251 | m_width = WIDTH_COL_DEFAULT; | |
0a816d95 | 1252 | else if (m_width < WIDTH_COL_MIN) |
cf1dfa6b | 1253 | m_width = WIDTH_COL_MIN; |
e1e955e1 | 1254 | } |
c801d85f | 1255 | |
debe6624 | 1256 | void wxListHeaderData::SetFormat( int format ) |
c801d85f | 1257 | { |
92976ab6 | 1258 | m_format = format; |
e1e955e1 | 1259 | } |
c801d85f | 1260 | |
fd9811b1 | 1261 | bool wxListHeaderData::HasImage() const |
c801d85f | 1262 | { |
0a816d95 | 1263 | return m_image != -1; |
e1e955e1 | 1264 | } |
c801d85f | 1265 | |
c801d85f KB |
1266 | bool wxListHeaderData::IsHit( int x, int y ) const |
1267 | { | |
92976ab6 | 1268 | return ((x >= m_xpos) && (x <= m_xpos+m_width) && (y >= m_ypos) && (y <= m_ypos+m_height)); |
e1e955e1 | 1269 | } |
c801d85f | 1270 | |
0a816d95 | 1271 | void wxListHeaderData::GetItem( wxListItem& item ) |
c801d85f | 1272 | { |
92976ab6 RR |
1273 | item.m_mask = m_mask; |
1274 | item.m_text = m_text; | |
1275 | item.m_image = m_image; | |
1276 | item.m_format = m_format; | |
1277 | item.m_width = m_width; | |
e1e955e1 | 1278 | } |
c801d85f | 1279 | |
fd9811b1 | 1280 | int wxListHeaderData::GetImage() const |
c801d85f | 1281 | { |
92976ab6 | 1282 | return m_image; |
e1e955e1 | 1283 | } |
c801d85f | 1284 | |
fd9811b1 | 1285 | int wxListHeaderData::GetWidth() const |
c801d85f | 1286 | { |
92976ab6 | 1287 | return m_width; |
e1e955e1 | 1288 | } |
c801d85f | 1289 | |
fd9811b1 | 1290 | int wxListHeaderData::GetFormat() const |
c801d85f | 1291 | { |
92976ab6 | 1292 | return m_format; |
e1e955e1 | 1293 | } |
c801d85f KB |
1294 | |
1295 | //----------------------------------------------------------------------------- | |
1296 | // wxListLineData | |
1297 | //----------------------------------------------------------------------------- | |
1298 | ||
cf1dfa6b VZ |
1299 | inline int wxListLineData::GetMode() const |
1300 | { | |
b54e41c5 | 1301 | return m_owner->GetListCtrl()->GetWindowStyleFlag() & wxLC_MASK_TYPE; |
cf1dfa6b | 1302 | } |
c801d85f | 1303 | |
cf1dfa6b | 1304 | inline bool wxListLineData::InReportView() const |
c801d85f | 1305 | { |
cf1dfa6b | 1306 | return m_owner->HasFlag(wxLC_REPORT); |
e1e955e1 | 1307 | } |
c801d85f | 1308 | |
b54e41c5 | 1309 | inline bool wxListLineData::IsVirtual() const |
c801d85f | 1310 | { |
cf1dfa6b VZ |
1311 | return m_owner->IsVirtual(); |
1312 | } | |
2c1f73ee | 1313 | |
5cd89174 | 1314 | wxListLineData::wxListLineData( wxListMainWindow *owner ) |
cf1dfa6b VZ |
1315 | { |
1316 | m_owner = owner; | |
1317 | m_items.DeleteContents( TRUE ); | |
2c1f73ee | 1318 | |
cf1dfa6b VZ |
1319 | if ( InReportView() ) |
1320 | { | |
1321 | m_gi = NULL; | |
1322 | } | |
1323 | else // !report | |
1324 | { | |
1325 | m_gi = new GeometryInfo; | |
1326 | } | |
f6bcfd97 | 1327 | |
b54e41c5 | 1328 | m_highlighted = FALSE; |
f6bcfd97 | 1329 | |
cf1dfa6b VZ |
1330 | InitItems( GetMode() == wxLC_REPORT ? m_owner->GetColumnCount() : 1 ); |
1331 | } | |
f6bcfd97 | 1332 | |
cf1dfa6b VZ |
1333 | void wxListLineData::CalculateSize( wxDC *dc, int spacing ) |
1334 | { | |
1335 | wxListItemDataList::Node *node = m_items.GetFirst(); | |
1336 | wxCHECK_RET( node, _T("no subitems at all??") ); | |
1337 | ||
1338 | wxListItemData *item = node->GetData(); | |
1339 | ||
1340 | switch ( GetMode() ) | |
1341 | { | |
1342 | case wxLC_ICON: | |
1343 | case wxLC_SMALL_ICON: | |
1344 | { | |
1345 | m_gi->m_rectAll.width = spacing; | |
1346 | ||
1347 | wxString s = item->GetText(); | |
1348 | ||
1349 | wxCoord lw, lh; | |
1350 | if ( s.empty() ) | |
5d25c050 | 1351 | { |
cf1dfa6b VZ |
1352 | lh = |
1353 | m_gi->m_rectLabel.width = | |
1354 | m_gi->m_rectLabel.height = 0; | |
5d25c050 | 1355 | } |
cf1dfa6b VZ |
1356 | else // has label |
1357 | { | |
1358 | dc->GetTextExtent( s, &lw, &lh ); | |
1359 | if (lh < SCROLL_UNIT_Y) | |
1360 | lh = SCROLL_UNIT_Y; | |
1361 | lw += EXTRA_WIDTH; | |
1362 | lh += EXTRA_HEIGHT; | |
1363 | ||
1364 | m_gi->m_rectAll.height = spacing + lh; | |
1365 | if (lw > spacing) | |
1366 | m_gi->m_rectAll.width = lw; | |
1367 | ||
1368 | m_gi->m_rectLabel.width = lw; | |
1369 | m_gi->m_rectLabel.height = lh; | |
1370 | } | |
1371 | ||
1372 | if (item->HasImage()) | |
1373 | { | |
1374 | int w, h; | |
1375 | m_owner->GetImageSize( item->GetImage(), w, h ); | |
1376 | m_gi->m_rectIcon.width = w + 8; | |
1377 | m_gi->m_rectIcon.height = h + 8; | |
1378 | ||
1379 | if ( m_gi->m_rectIcon.width > m_gi->m_rectAll.width ) | |
1380 | m_gi->m_rectAll.width = m_gi->m_rectIcon.width; | |
1381 | if ( m_gi->m_rectIcon.height + lh > m_gi->m_rectAll.height - 4 ) | |
1382 | m_gi->m_rectAll.height = m_gi->m_rectIcon.height + lh + 4; | |
1383 | } | |
1384 | ||
1385 | if ( item->HasText() ) | |
5d25c050 | 1386 | { |
b54e41c5 VZ |
1387 | m_gi->m_rectHighlight.width = m_gi->m_rectLabel.width; |
1388 | m_gi->m_rectHighlight.height = m_gi->m_rectLabel.height; | |
cf1dfa6b VZ |
1389 | } |
1390 | else // no text, highlight the icon | |
1391 | { | |
b54e41c5 VZ |
1392 | m_gi->m_rectHighlight.width = m_gi->m_rectIcon.width; |
1393 | m_gi->m_rectHighlight.height = m_gi->m_rectIcon.height; | |
5d25c050 | 1394 | } |
92976ab6 RR |
1395 | } |
1396 | break; | |
cf1dfa6b | 1397 | |
92976ab6 | 1398 | case wxLC_LIST: |
92976ab6 | 1399 | { |
cf1dfa6b | 1400 | wxString s = item->GetTextForMeasuring(); |
2c1f73ee | 1401 | |
13111b2a | 1402 | wxCoord lw,lh; |
92976ab6 | 1403 | dc->GetTextExtent( s, &lw, &lh ); |
cf1dfa6b VZ |
1404 | if (lh < SCROLL_UNIT_Y) |
1405 | lh = SCROLL_UNIT_Y; | |
1406 | lw += EXTRA_WIDTH; | |
1407 | lh += EXTRA_HEIGHT; | |
2c1f73ee | 1408 | |
cf1dfa6b VZ |
1409 | m_gi->m_rectLabel.width = lw; |
1410 | m_gi->m_rectLabel.height = lh; | |
f6bcfd97 | 1411 | |
cf1dfa6b VZ |
1412 | m_gi->m_rectAll.width = lw; |
1413 | m_gi->m_rectAll.height = lh; | |
f6bcfd97 | 1414 | |
0b855868 RR |
1415 | if (item->HasImage()) |
1416 | { | |
cf1dfa6b | 1417 | int w, h; |
0b855868 | 1418 | m_owner->GetImageSize( item->GetImage(), w, h ); |
cf1dfa6b VZ |
1419 | m_gi->m_rectIcon.width = w; |
1420 | m_gi->m_rectIcon.height = h; | |
f6bcfd97 | 1421 | |
cf1dfa6b VZ |
1422 | m_gi->m_rectAll.width += 4 + w; |
1423 | if (h > m_gi->m_rectAll.height) | |
1424 | m_gi->m_rectAll.height = h; | |
bffa1c77 | 1425 | } |
f6bcfd97 | 1426 | |
b54e41c5 VZ |
1427 | m_gi->m_rectHighlight.width = m_gi->m_rectAll.width; |
1428 | m_gi->m_rectHighlight.height = m_gi->m_rectAll.height; | |
92976ab6 RR |
1429 | } |
1430 | break; | |
2c1f73ee | 1431 | |
cf1dfa6b VZ |
1432 | case wxLC_REPORT: |
1433 | wxFAIL_MSG( _T("unexpected call to SetSize") ); | |
92976ab6 | 1434 | break; |
cf1dfa6b VZ |
1435 | |
1436 | default: | |
1437 | wxFAIL_MSG( _T("unknown mode") ); | |
e1e955e1 | 1438 | } |
e1e955e1 | 1439 | } |
c801d85f | 1440 | |
cf1dfa6b VZ |
1441 | void wxListLineData::SetPosition( int x, int y, |
1442 | int window_width, | |
1443 | int spacing ) | |
c801d85f | 1444 | { |
2c1f73ee | 1445 | wxListItemDataList::Node *node = m_items.GetFirst(); |
cf1dfa6b | 1446 | wxCHECK_RET( node, _T("no subitems at all??") ); |
2c1f73ee | 1447 | |
cf1dfa6b | 1448 | wxListItemData *item = node->GetData(); |
2c1f73ee | 1449 | |
cf1dfa6b | 1450 | switch ( GetMode() ) |
0b855868 RR |
1451 | { |
1452 | case wxLC_ICON: | |
cf1dfa6b VZ |
1453 | case wxLC_SMALL_ICON: |
1454 | m_gi->m_rectAll.x = x; | |
1455 | m_gi->m_rectAll.y = y; | |
1456 | ||
1457 | if ( item->HasImage() ) | |
0b855868 | 1458 | { |
c2569f41 VZ |
1459 | m_gi->m_rectIcon.x = m_gi->m_rectAll.x + 4 + |
1460 | (m_gi->m_rectAll.width - m_gi->m_rectIcon.width) / 2; | |
cf1dfa6b | 1461 | m_gi->m_rectIcon.y = m_gi->m_rectAll.y + 4; |
0b855868 | 1462 | } |
cf1dfa6b VZ |
1463 | |
1464 | if ( item->HasText() ) | |
0b855868 | 1465 | { |
cf1dfa6b VZ |
1466 | if (m_gi->m_rectAll.width > spacing) |
1467 | m_gi->m_rectLabel.x = m_gi->m_rectAll.x + 2; | |
5d25c050 | 1468 | else |
cf1dfa6b VZ |
1469 | m_gi->m_rectLabel.x = m_gi->m_rectAll.x + 2 + (spacing/2) - (m_gi->m_rectLabel.width/2); |
1470 | m_gi->m_rectLabel.y = m_gi->m_rectAll.y + m_gi->m_rectAll.height + 2 - m_gi->m_rectLabel.height; | |
b54e41c5 VZ |
1471 | m_gi->m_rectHighlight.x = m_gi->m_rectLabel.x - 2; |
1472 | m_gi->m_rectHighlight.y = m_gi->m_rectLabel.y - 2; | |
bffa1c77 | 1473 | } |
cf1dfa6b | 1474 | else // no text, highlight the icon |
0b855868 | 1475 | { |
b54e41c5 VZ |
1476 | m_gi->m_rectHighlight.x = m_gi->m_rectIcon.x - 4; |
1477 | m_gi->m_rectHighlight.y = m_gi->m_rectIcon.y - 4; | |
bffa1c77 | 1478 | } |
0b855868 | 1479 | break; |
c801d85f | 1480 | |
cf1dfa6b VZ |
1481 | case wxLC_LIST: |
1482 | m_gi->m_rectAll.x = x; | |
1483 | m_gi->m_rectAll.y = y; | |
c801d85f | 1484 | |
b54e41c5 VZ |
1485 | m_gi->m_rectHighlight.x = m_gi->m_rectAll.x; |
1486 | m_gi->m_rectHighlight.y = m_gi->m_rectAll.y; | |
cf1dfa6b | 1487 | m_gi->m_rectLabel.y = m_gi->m_rectAll.y + 2; |
c801d85f | 1488 | |
cf1dfa6b VZ |
1489 | if (item->HasImage()) |
1490 | { | |
1491 | m_gi->m_rectIcon.x = m_gi->m_rectAll.x + 2; | |
1492 | m_gi->m_rectIcon.y = m_gi->m_rectAll.y + 2; | |
1493 | m_gi->m_rectLabel.x = m_gi->m_rectAll.x + 6 + m_gi->m_rectIcon.width; | |
1494 | } | |
1495 | else | |
1496 | { | |
1497 | m_gi->m_rectLabel.x = m_gi->m_rectAll.x + 2; | |
1498 | } | |
1499 | break; | |
c801d85f | 1500 | |
cf1dfa6b VZ |
1501 | case wxLC_REPORT: |
1502 | wxFAIL_MSG( _T("unexpected call to SetPosition") ); | |
1503 | break; | |
c801d85f | 1504 | |
cf1dfa6b VZ |
1505 | default: |
1506 | wxFAIL_MSG( _T("unknown mode") ); | |
1507 | } | |
e1e955e1 | 1508 | } |
c801d85f | 1509 | |
debe6624 | 1510 | void wxListLineData::InitItems( int num ) |
c801d85f | 1511 | { |
2c1f73ee | 1512 | for (int i = 0; i < num; i++) |
cf1dfa6b | 1513 | m_items.Append( new wxListItemData(m_owner) ); |
e1e955e1 | 1514 | } |
c801d85f | 1515 | |
debe6624 | 1516 | void wxListLineData::SetItem( int index, const wxListItem &info ) |
c801d85f | 1517 | { |
2c1f73ee | 1518 | wxListItemDataList::Node *node = m_items.Item( index ); |
1370703e VZ |
1519 | wxCHECK_RET( node, _T("invalid column index in SetItem") ); |
1520 | ||
1521 | wxListItemData *item = node->GetData(); | |
1522 | item->SetItem( info ); | |
e1e955e1 | 1523 | } |
c801d85f | 1524 | |
1e6d9499 | 1525 | void wxListLineData::GetItem( int index, wxListItem &info ) |
c801d85f | 1526 | { |
2c1f73ee | 1527 | wxListItemDataList::Node *node = m_items.Item( index ); |
139adb6a RR |
1528 | if (node) |
1529 | { | |
2c1f73ee | 1530 | wxListItemData *item = node->GetData(); |
139adb6a RR |
1531 | item->GetItem( info ); |
1532 | } | |
e1e955e1 | 1533 | } |
c801d85f | 1534 | |
54442116 | 1535 | wxString wxListLineData::GetText(int index) const |
c801d85f | 1536 | { |
54442116 VZ |
1537 | wxString s; |
1538 | ||
2c1f73ee | 1539 | wxListItemDataList::Node *node = m_items.Item( index ); |
139adb6a RR |
1540 | if (node) |
1541 | { | |
2c1f73ee | 1542 | wxListItemData *item = node->GetData(); |
54442116 | 1543 | s = item->GetText(); |
139adb6a | 1544 | } |
54442116 VZ |
1545 | |
1546 | return s; | |
e1e955e1 | 1547 | } |
c801d85f | 1548 | |
debe6624 | 1549 | void wxListLineData::SetText( int index, const wxString s ) |
c801d85f | 1550 | { |
2c1f73ee | 1551 | wxListItemDataList::Node *node = m_items.Item( index ); |
139adb6a RR |
1552 | if (node) |
1553 | { | |
2c1f73ee | 1554 | wxListItemData *item = node->GetData(); |
139adb6a RR |
1555 | item->SetText( s ); |
1556 | } | |
e1e955e1 | 1557 | } |
c801d85f | 1558 | |
cf1dfa6b | 1559 | void wxListLineData::SetImage( int index, int image ) |
c801d85f | 1560 | { |
2c1f73ee | 1561 | wxListItemDataList::Node *node = m_items.Item( index ); |
cf1dfa6b VZ |
1562 | wxCHECK_RET( node, _T("invalid column index in SetImage()") ); |
1563 | ||
1564 | wxListItemData *item = node->GetData(); | |
1565 | item->SetImage(image); | |
1566 | } | |
1567 | ||
1568 | int wxListLineData::GetImage( int index ) const | |
1569 | { | |
1570 | wxListItemDataList::Node *node = m_items.Item( index ); | |
1571 | wxCHECK_MSG( node, -1, _T("invalid column index in GetImage()") ); | |
1572 | ||
1573 | wxListItemData *item = node->GetData(); | |
1574 | return item->GetImage(); | |
e1e955e1 | 1575 | } |
c801d85f | 1576 | |
6c02c329 VZ |
1577 | wxListItemAttr *wxListLineData::GetAttr() const |
1578 | { | |
1579 | wxListItemDataList::Node *node = m_items.GetFirst(); | |
1580 | wxCHECK_MSG( node, NULL, _T("invalid column index in GetAttr()") ); | |
1581 | ||
1582 | wxListItemData *item = node->GetData(); | |
1583 | return item->GetAttr(); | |
1584 | } | |
1585 | ||
1586 | void wxListLineData::SetAttr(wxListItemAttr *attr) | |
1587 | { | |
1588 | wxListItemDataList::Node *node = m_items.GetFirst(); | |
1589 | wxCHECK_RET( node, _T("invalid column index in SetAttr()") ); | |
1590 | ||
1591 | wxListItemData *item = node->GetData(); | |
1592 | item->SetAttr(attr); | |
1593 | } | |
1594 | ||
0e980f91 | 1595 | bool wxListLineData::SetAttributes(wxDC *dc, |
0530737d | 1596 | const wxListItemAttr *attr, |
0e980f91 | 1597 | bool highlighted) |
0530737d | 1598 | { |
0e980f91 VZ |
1599 | wxWindow *listctrl = m_owner->GetParent(); |
1600 | ||
1601 | // fg colour | |
1602 | ||
1603 | // don't use foreground colour for drawing highlighted items - this might | |
470caaf9 VZ |
1604 | // make them completely invisible (and there is no way to do bit |
1605 | // arithmetics on wxColour, unfortunately) | |
0e980f91 VZ |
1606 | wxColour colText; |
1607 | if ( highlighted ) | |
0530737d | 1608 | { |
a756f210 | 1609 | colText = wxSystemSettings::GetColour(wxSYS_COLOUR_HIGHLIGHTTEXT); |
0530737d VZ |
1610 | } |
1611 | else | |
1612 | { | |
0e980f91 VZ |
1613 | if ( attr && attr->HasTextColour() ) |
1614 | { | |
1615 | colText = attr->GetTextColour(); | |
1616 | } | |
1617 | else | |
1618 | { | |
1619 | colText = listctrl->GetForegroundColour(); | |
1620 | } | |
0530737d VZ |
1621 | } |
1622 | ||
0e980f91 VZ |
1623 | dc->SetTextForeground(colText); |
1624 | ||
1625 | // font | |
1626 | wxFont font; | |
0530737d VZ |
1627 | if ( attr && attr->HasFont() ) |
1628 | { | |
0e980f91 | 1629 | font = attr->GetFont(); |
0530737d VZ |
1630 | } |
1631 | else | |
1632 | { | |
0e980f91 | 1633 | font = listctrl->GetFont(); |
0530737d | 1634 | } |
0e980f91 VZ |
1635 | |
1636 | dc->SetFont(font); | |
1637 | ||
1638 | // bg colour | |
1639 | bool hasBgCol = attr && attr->HasBackgroundColour(); | |
1640 | if ( highlighted || hasBgCol ) | |
1641 | { | |
1642 | if ( highlighted ) | |
1643 | { | |
49ecb029 | 1644 | dc->SetBrush( *m_owner->GetHighlightBrush() ); |
0e980f91 VZ |
1645 | } |
1646 | else | |
1647 | { | |
1648 | dc->SetBrush(wxBrush(attr->GetBackgroundColour(), wxSOLID)); | |
1649 | } | |
1650 | ||
1651 | dc->SetPen( *wxTRANSPARENT_PEN ); | |
1652 | ||
1653 | return TRUE; | |
1654 | } | |
1655 | ||
1656 | return FALSE; | |
0530737d VZ |
1657 | } |
1658 | ||
5cd89174 VZ |
1659 | void wxListLineData::Draw( wxDC *dc ) |
1660 | { | |
1661 | wxListItemDataList::Node *node = m_items.GetFirst(); | |
1662 | wxCHECK_RET( node, _T("no subitems at all??") ); | |
1663 | ||
0e980f91 VZ |
1664 | bool highlighted = IsHighlighted(); |
1665 | ||
1666 | wxListItemAttr *attr = GetAttr(); | |
1667 | ||
1668 | if ( SetAttributes(dc, attr, highlighted) ) | |
1669 | { | |
1670 | dc->DrawRectangle( m_gi->m_rectHighlight ); | |
1671 | } | |
1672 | ||
5cd89174 VZ |
1673 | wxListItemData *item = node->GetData(); |
1674 | if (item->HasImage()) | |
1675 | { | |
1676 | wxRect rectIcon = m_gi->m_rectIcon; | |
1677 | m_owner->DrawImage( item->GetImage(), dc, | |
1678 | rectIcon.x, rectIcon.y ); | |
1679 | } | |
1680 | ||
1681 | if (item->HasText()) | |
1682 | { | |
1683 | wxRect rectLabel = m_gi->m_rectLabel; | |
06b781c7 VZ |
1684 | |
1685 | wxDCClipper clipper(*dc, rectLabel); | |
5cd89174 VZ |
1686 | dc->DrawText( item->GetText(), rectLabel.x, rectLabel.y ); |
1687 | } | |
1688 | } | |
1689 | ||
1690 | void wxListLineData::DrawInReportMode( wxDC *dc, | |
938b652b | 1691 | const wxRect& rect, |
5cd89174 VZ |
1692 | const wxRect& rectHL, |
1693 | bool highlighted ) | |
c801d85f | 1694 | { |
6c02c329 VZ |
1695 | // TODO: later we should support setting different attributes for |
1696 | // different columns - to do it, just add "col" argument to | |
0e980f91 | 1697 | // GetAttr() and move these lines into the loop below |
6c02c329 | 1698 | wxListItemAttr *attr = GetAttr(); |
0e980f91 | 1699 | if ( SetAttributes(dc, attr, highlighted) ) |
c801d85f | 1700 | { |
5cd89174 | 1701 | dc->DrawRectangle( rectHL ); |
e1e955e1 | 1702 | } |
004fd0c8 | 1703 | |
2c1f73ee | 1704 | wxListItemDataList::Node *node = m_items.GetFirst(); |
5cd89174 | 1705 | wxCHECK_RET( node, _T("no subitems at all??") ); |
2c1f73ee | 1706 | |
5cd89174 | 1707 | size_t col = 0; |
938b652b VZ |
1708 | wxCoord x = rect.x + HEADER_OFFSET_X, |
1709 | y = rect.y + (LINE_SPACING + EXTRA_HEIGHT) / 2; | |
cf1dfa6b | 1710 | |
5cd89174 VZ |
1711 | while ( node ) |
1712 | { | |
1713 | wxListItemData *item = node->GetData(); | |
cf1dfa6b | 1714 | |
06b781c7 | 1715 | int width = m_owner->GetColumnWidth(col++); |
5cd89174 | 1716 | int xOld = x; |
06b781c7 | 1717 | x += width; |
cf1dfa6b | 1718 | |
5cd89174 VZ |
1719 | if ( item->HasImage() ) |
1720 | { | |
1721 | int ix, iy; | |
06b781c7 | 1722 | m_owner->DrawImage( item->GetImage(), dc, xOld, y ); |
5cd89174 | 1723 | m_owner->GetImageSize( item->GetImage(), ix, iy ); |
cf1dfa6b | 1724 | |
06b781c7 | 1725 | ix += IMAGE_MARGIN_IN_REPORT_MODE; |
cf1dfa6b | 1726 | |
06b781c7 VZ |
1727 | xOld += ix; |
1728 | width -= ix; | |
1729 | } | |
1730 | ||
1731 | wxDCClipper clipper(*dc, xOld, y, width, rect.height); | |
cf1dfa6b | 1732 | |
5cd89174 VZ |
1733 | if ( item->HasText() ) |
1734 | { | |
06b781c7 | 1735 | dc->DrawText( item->GetText(), xOld, y ); |
5cd89174 | 1736 | } |
cf1dfa6b | 1737 | |
5cd89174 | 1738 | node = node->GetNext(); |
e1e955e1 | 1739 | } |
e1e955e1 | 1740 | } |
c801d85f | 1741 | |
b54e41c5 | 1742 | bool wxListLineData::Highlight( bool on ) |
c801d85f | 1743 | { |
b54e41c5 | 1744 | wxCHECK_MSG( !m_owner->IsVirtual(), FALSE, _T("unexpected call to Highlight") ); |
c801d85f | 1745 | |
b54e41c5 | 1746 | if ( on == m_highlighted ) |
cf1dfa6b | 1747 | return FALSE; |
c801d85f | 1748 | |
b54e41c5 | 1749 | m_highlighted = on; |
c801d85f | 1750 | |
cf1dfa6b | 1751 | return TRUE; |
e1e955e1 | 1752 | } |
c801d85f | 1753 | |
b54e41c5 | 1754 | void wxListLineData::ReverseHighlight( void ) |
c801d85f | 1755 | { |
b54e41c5 | 1756 | Highlight(!IsHighlighted()); |
e1e955e1 | 1757 | } |
c801d85f KB |
1758 | |
1759 | //----------------------------------------------------------------------------- | |
1760 | // wxListHeaderWindow | |
1761 | //----------------------------------------------------------------------------- | |
1762 | ||
5a1cad6e | 1763 | IMPLEMENT_DYNAMIC_CLASS(wxListHeaderWindow,wxWindow) |
c801d85f KB |
1764 | |
1765 | BEGIN_EVENT_TABLE(wxListHeaderWindow,wxWindow) | |
63852e78 RR |
1766 | EVT_PAINT (wxListHeaderWindow::OnPaint) |
1767 | EVT_MOUSE_EVENTS (wxListHeaderWindow::OnMouse) | |
1768 | EVT_SET_FOCUS (wxListHeaderWindow::OnSetFocus) | |
c801d85f KB |
1769 | END_EVENT_TABLE() |
1770 | ||
0a816d95 | 1771 | void wxListHeaderWindow::Init() |
c801d85f | 1772 | { |
63852e78 | 1773 | m_currentCursor = (wxCursor *) NULL; |
cfb50f14 | 1774 | m_isDragging = FALSE; |
0a816d95 VZ |
1775 | m_dirty = FALSE; |
1776 | } | |
1777 | ||
1778 | wxListHeaderWindow::wxListHeaderWindow() | |
1779 | { | |
1780 | Init(); | |
1781 | ||
1782 | m_owner = (wxListMainWindow *) NULL; | |
1783 | m_resizeCursor = (wxCursor *) NULL; | |
e1e955e1 | 1784 | } |
c801d85f | 1785 | |
0a816d95 VZ |
1786 | wxListHeaderWindow::wxListHeaderWindow( wxWindow *win, |
1787 | wxWindowID id, | |
1788 | wxListMainWindow *owner, | |
1789 | const wxPoint& pos, | |
1790 | const wxSize& size, | |
1791 | long style, | |
1792 | const wxString &name ) | |
1793 | : wxWindow( win, id, pos, size, style, name ) | |
c801d85f | 1794 | { |
0a816d95 VZ |
1795 | Init(); |
1796 | ||
63852e78 | 1797 | m_owner = owner; |
63852e78 | 1798 | m_resizeCursor = new wxCursor( wxCURSOR_SIZEWE ); |
f6bcfd97 | 1799 | |
a756f210 | 1800 | SetBackgroundColour( wxSystemSettings::GetColour( wxSYS_COLOUR_BTNFACE ) ); |
e1e955e1 | 1801 | } |
c801d85f | 1802 | |
0a816d95 | 1803 | wxListHeaderWindow::~wxListHeaderWindow() |
a367b9b3 | 1804 | { |
63852e78 | 1805 | delete m_resizeCursor; |
a367b9b3 JS |
1806 | } |
1807 | ||
1e6d9499 | 1808 | void wxListHeaderWindow::DoDrawRect( wxDC *dc, int x, int y, int w, int h ) |
c801d85f | 1809 | { |
f16ba4e6 | 1810 | #if defined(__WXGTK__) && !defined(__WXUNIVERSAL__) |
b54e41c5 VZ |
1811 | GtkStateType state = m_parent->IsEnabled() ? GTK_STATE_NORMAL |
1812 | : GTK_STATE_INSENSITIVE; | |
2c1f73ee | 1813 | |
3fb435df | 1814 | x = dc->XLOG2DEV( x ); |
2c1f73ee | 1815 | |
b54e41c5 VZ |
1816 | gtk_paint_box (m_wxwindow->style, GTK_PIZZA(m_wxwindow)->bin_window, |
1817 | state, GTK_SHADOW_OUT, | |
90350682 VZ |
1818 | (GdkRectangle*) NULL, m_wxwindow, |
1819 | (char *)"button", // const_cast | |
b54e41c5 | 1820 | x-1, y-1, w+2, h+2); |
4176fb7d SC |
1821 | #elif defined( __WXMAC__ ) |
1822 | const int m_corner = 1; | |
1823 | ||
1824 | dc->SetBrush( *wxTRANSPARENT_BRUSH ); | |
1825 | ||
a756f210 | 1826 | dc->SetPen( wxPen( wxSystemSettings::GetColour( wxSYS_COLOUR_BTNSHADOW ) , 1 , wxSOLID ) ); |
4176fb7d SC |
1827 | dc->DrawLine( x+w-m_corner+1, y, x+w, y+h ); // right (outer) |
1828 | dc->DrawRectangle( x, y+h, w+1, 1 ); // bottom (outer) | |
1829 | ||
1830 | wxPen pen( wxColour( 0x88 , 0x88 , 0x88 ), 1, wxSOLID ); | |
1831 | ||
1832 | dc->SetPen( pen ); | |
1833 | dc->DrawLine( x+w-m_corner, y, x+w-1, y+h ); // right (inner) | |
1834 | dc->DrawRectangle( x+1, y+h-1, w-2, 1 ); // bottom (inner) | |
1835 | ||
1836 | dc->SetPen( *wxWHITE_PEN ); | |
1837 | dc->DrawRectangle( x, y, w-m_corner+1, 1 ); // top (outer) | |
1838 | dc->DrawRectangle( x, y, 1, h ); // left (outer) | |
1839 | dc->DrawLine( x, y+h-1, x+1, y+h-1 ); | |
1840 | dc->DrawLine( x+w-1, y, x+w-1, y+1 ); | |
b54e41c5 | 1841 | #else // !GTK, !Mac |
63852e78 | 1842 | const int m_corner = 1; |
c801d85f | 1843 | |
63852e78 | 1844 | dc->SetBrush( *wxTRANSPARENT_BRUSH ); |
c801d85f | 1845 | |
63852e78 RR |
1846 | dc->SetPen( *wxBLACK_PEN ); |
1847 | dc->DrawLine( x+w-m_corner+1, y, x+w, y+h ); // right (outer) | |
17867d61 | 1848 | dc->DrawRectangle( x, y+h, w+1, 1 ); // bottom (outer) |
bd8289c1 | 1849 | |
a756f210 | 1850 | wxPen pen( wxSystemSettings::GetColour( wxSYS_COLOUR_BTNSHADOW ), 1, wxSOLID ); |
004fd0c8 | 1851 | |
63852e78 RR |
1852 | dc->SetPen( pen ); |
1853 | dc->DrawLine( x+w-m_corner, y, x+w-1, y+h ); // right (inner) | |
1854 | dc->DrawRectangle( x+1, y+h-1, w-2, 1 ); // bottom (inner) | |
bd8289c1 | 1855 | |
63852e78 RR |
1856 | dc->SetPen( *wxWHITE_PEN ); |
1857 | dc->DrawRectangle( x, y, w-m_corner+1, 1 ); // top (outer) | |
1858 | dc->DrawRectangle( x, y, 1, h ); // left (outer) | |
1859 | dc->DrawLine( x, y+h-1, x+1, y+h-1 ); | |
1860 | dc->DrawLine( x+w-1, y, x+w-1, y+1 ); | |
3fb435df | 1861 | #endif |
e1e955e1 | 1862 | } |
c801d85f | 1863 | |
f6bcfd97 BP |
1864 | // shift the DC origin to match the position of the main window horz |
1865 | // scrollbar: this allows us to always use logical coords | |
1866 | void wxListHeaderWindow::AdjustDC(wxDC& dc) | |
1867 | { | |
f6bcfd97 BP |
1868 | int xpix; |
1869 | m_owner->GetScrollPixelsPerUnit( &xpix, NULL ); | |
1870 | ||
1871 | int x; | |
1872 | m_owner->GetViewStart( &x, NULL ); | |
1873 | ||
1874 | // account for the horz scrollbar offset | |
1875 | dc.SetDeviceOrigin( -x * xpix, 0 ); | |
f6bcfd97 BP |
1876 | } |
1877 | ||
c801d85f KB |
1878 | void wxListHeaderWindow::OnPaint( wxPaintEvent &WXUNUSED(event) ) |
1879 | { | |
f16ba4e6 | 1880 | #if defined(__WXGTK__) |
10bd0724 JS |
1881 | wxClientDC dc( this ); |
1882 | #else | |
63852e78 | 1883 | wxPaintDC dc( this ); |
10bd0724 JS |
1884 | #endif |
1885 | ||
63852e78 | 1886 | PrepareDC( dc ); |
f6bcfd97 | 1887 | AdjustDC( dc ); |
bffa1c77 | 1888 | |
63852e78 | 1889 | dc.BeginDrawing(); |
bd8289c1 | 1890 | |
63852e78 | 1891 | dc.SetFont( GetFont() ); |
bd8289c1 | 1892 | |
f6bcfd97 BP |
1893 | // width and height of the entire header window |
1894 | int w, h; | |
63852e78 | 1895 | GetClientSize( &w, &h ); |
f6bcfd97 | 1896 | m_owner->CalcUnscrolledPosition(w, 0, &w, NULL); |
c801d85f | 1897 | |
f60d0f94 | 1898 | dc.SetBackgroundMode(wxTRANSPARENT); |
70846f0a VZ |
1899 | |
1900 | // do *not* use the listctrl colour for headers - one day we will have a | |
1901 | // function to set it separately | |
37d403aa | 1902 | //dc.SetTextForeground( *wxBLACK ); |
cf1dfa6b VZ |
1903 | dc.SetTextForeground(wxSystemSettings:: |
1904 | GetSystemColour( wxSYS_COLOUR_WINDOWTEXT )); | |
1905 | ||
1906 | int x = HEADER_OFFSET_X; | |
c801d85f | 1907 | |
63852e78 RR |
1908 | int numColumns = m_owner->GetColumnCount(); |
1909 | wxListItem item; | |
c5b7bb59 | 1910 | for ( int i = 0; i < numColumns && x < w; i++ ) |
63852e78 RR |
1911 | { |
1912 | m_owner->GetColumn( i, item ); | |
f6bcfd97 | 1913 | int wCol = item.m_width; |
f6bcfd97 | 1914 | |
0a816d95 VZ |
1915 | // the width of the rect to draw: make it smaller to fit entirely |
1916 | // inside the column rect | |
1917 | int cw = wCol - 2; | |
f6bcfd97 | 1918 | |
63852e78 | 1919 | dc.SetPen( *wxWHITE_PEN ); |
c801d85f | 1920 | |
cf1dfa6b | 1921 | DoDrawRect( &dc, x, HEADER_OFFSET_Y, cw, h-2 ); |
0a816d95 VZ |
1922 | |
1923 | // if we have an image, draw it on the right of the label | |
1924 | int image = item.m_image; | |
1925 | if ( image != -1 ) | |
1926 | { | |
1927 | wxImageList *imageList = m_owner->m_small_image_list; | |
1928 | if ( imageList ) | |
1929 | { | |
1930 | int ix, iy; | |
1931 | imageList->GetSize(image, ix, iy); | |
1932 | ||
1933 | imageList->Draw | |
1934 | ( | |
1935 | image, | |
1936 | dc, | |
1937 | x + cw - ix - 1, | |
1938 | HEADER_OFFSET_Y + (h - 4 - iy)/2, | |
1939 | wxIMAGELIST_DRAW_TRANSPARENT | |
1940 | ); | |
1941 | ||
1942 | cw -= ix + 2; | |
1943 | } | |
1944 | //else: ignore the column image | |
1945 | } | |
1946 | ||
1947 | // draw the text clipping it so that it doesn't overwrite the column | |
1948 | // boundary | |
1949 | wxDCClipper clipper(dc, x, HEADER_OFFSET_Y, cw, h - 4 ); | |
06b781c7 VZ |
1950 | |
1951 | dc.DrawText( item.GetText(), | |
1952 | x + EXTRA_WIDTH, HEADER_OFFSET_Y + EXTRA_HEIGHT ); | |
1953 | ||
0a816d95 | 1954 | x += wCol; |
63852e78 | 1955 | } |
c5b7bb59 | 1956 | |
63852e78 | 1957 | dc.EndDrawing(); |
e1e955e1 | 1958 | } |
c801d85f | 1959 | |
0208334d RR |
1960 | void wxListHeaderWindow::DrawCurrent() |
1961 | { | |
63852e78 RR |
1962 | int x1 = m_currentX; |
1963 | int y1 = 0; | |
f16ba4e6 | 1964 | m_owner->ClientToScreen( &x1, &y1 ); |
f6bcfd97 | 1965 | |
f16ba4e6 | 1966 | int x2 = m_currentX; |
63852e78 | 1967 | int y2 = 0; |
f6bcfd97 | 1968 | m_owner->GetClientSize( NULL, &y2 ); |
63852e78 | 1969 | m_owner->ClientToScreen( &x2, &y2 ); |
0208334d | 1970 | |
63852e78 | 1971 | wxScreenDC dc; |
3c679789 | 1972 | dc.SetLogicalFunction( wxINVERT ); |
63852e78 RR |
1973 | dc.SetPen( wxPen( *wxBLACK, 2, wxSOLID ) ); |
1974 | dc.SetBrush( *wxTRANSPARENT_BRUSH ); | |
0208334d | 1975 | |
f6bcfd97 BP |
1976 | AdjustDC(dc); |
1977 | ||
63852e78 | 1978 | dc.DrawLine( x1, y1, x2, y2 ); |
0208334d | 1979 | |
63852e78 | 1980 | dc.SetLogicalFunction( wxCOPY ); |
0208334d | 1981 | |
63852e78 RR |
1982 | dc.SetPen( wxNullPen ); |
1983 | dc.SetBrush( wxNullBrush ); | |
0208334d RR |
1984 | } |
1985 | ||
c801d85f KB |
1986 | void wxListHeaderWindow::OnMouse( wxMouseEvent &event ) |
1987 | { | |
f6bcfd97 | 1988 | // we want to work with logical coords |
3ca6a5f0 BP |
1989 | int x; |
1990 | m_owner->CalcUnscrolledPosition(event.GetX(), 0, &x, NULL); | |
3ca6a5f0 | 1991 | int y = event.GetY(); |
f6bcfd97 | 1992 | |
cfb50f14 | 1993 | if (m_isDragging) |
0208334d | 1994 | { |
a77ec46d RD |
1995 | SendListEvent(wxEVT_COMMAND_LIST_COL_DRAGGING, |
1996 | event.GetPosition()); | |
1997 | ||
f6bcfd97 BP |
1998 | // we don't draw the line beyond our window, but we allow dragging it |
1999 | // there | |
2000 | int w = 0; | |
2001 | GetClientSize( &w, NULL ); | |
f6bcfd97 | 2002 | m_owner->CalcUnscrolledPosition(w, 0, &w, NULL); |
f6bcfd97 BP |
2003 | w -= 6; |
2004 | ||
2005 | // erase the line if it was drawn | |
2006 | if ( m_currentX < w ) | |
2007 | DrawCurrent(); | |
2008 | ||
63852e78 RR |
2009 | if (event.ButtonUp()) |
2010 | { | |
2011 | ReleaseMouse(); | |
cfb50f14 | 2012 | m_isDragging = FALSE; |
f6bcfd97 BP |
2013 | m_dirty = TRUE; |
2014 | m_owner->SetColumnWidth( m_column, m_currentX - m_minX ); | |
a77ec46d RD |
2015 | SendListEvent(wxEVT_COMMAND_LIST_COL_END_DRAG, |
2016 | event.GetPosition()); | |
63852e78 RR |
2017 | } |
2018 | else | |
2019 | { | |
f6bcfd97 | 2020 | if (x > m_minX + 7) |
63852e78 RR |
2021 | m_currentX = x; |
2022 | else | |
f6bcfd97 | 2023 | m_currentX = m_minX + 7; |
bd8289c1 | 2024 | |
f6bcfd97 BP |
2025 | // draw in the new location |
2026 | if ( m_currentX < w ) | |
2027 | DrawCurrent(); | |
bffa1c77 | 2028 | } |
0208334d | 2029 | } |
f6bcfd97 | 2030 | else // not dragging |
c801d85f | 2031 | { |
f6bcfd97 BP |
2032 | m_minX = 0; |
2033 | bool hit_border = FALSE; | |
2034 | ||
2035 | // end of the current column | |
2036 | int xpos = 0; | |
2037 | ||
2038 | // find the column where this event occured | |
62313c27 VZ |
2039 | int col, |
2040 | countCol = m_owner->GetColumnCount(); | |
2041 | for (col = 0; col < countCol; col++) | |
bffa1c77 | 2042 | { |
cf1dfa6b VZ |
2043 | xpos += m_owner->GetColumnWidth( col ); |
2044 | m_column = col; | |
f6bcfd97 BP |
2045 | |
2046 | if ( (abs(x-xpos) < 3) && (y < 22) ) | |
2047 | { | |
2048 | // near the column border | |
2049 | hit_border = TRUE; | |
2050 | break; | |
2051 | } | |
2052 | ||
2053 | if ( x < xpos ) | |
2054 | { | |
2055 | // inside the column | |
2056 | break; | |
2057 | } | |
2058 | ||
2059 | m_minX = xpos; | |
bffa1c77 | 2060 | } |
63852e78 | 2061 | |
62313c27 VZ |
2062 | if ( col == countCol ) |
2063 | m_column = -1; | |
2064 | ||
11358d39 | 2065 | if (event.LeftDown() || event.RightUp()) |
63852e78 | 2066 | { |
11358d39 | 2067 | if (hit_border && event.LeftDown()) |
f6bcfd97 BP |
2068 | { |
2069 | m_isDragging = TRUE; | |
2070 | m_currentX = x; | |
2071 | DrawCurrent(); | |
2072 | CaptureMouse(); | |
a77ec46d RD |
2073 | SendListEvent(wxEVT_COMMAND_LIST_COL_BEGIN_DRAG, |
2074 | event.GetPosition()); | |
f6bcfd97 | 2075 | } |
11358d39 | 2076 | else // click on a column |
f6bcfd97 | 2077 | { |
a77ec46d | 2078 | SendListEvent( event.LeftDown() |
11358d39 VZ |
2079 | ? wxEVT_COMMAND_LIST_COL_CLICK |
2080 | : wxEVT_COMMAND_LIST_COL_RIGHT_CLICK, | |
a77ec46d | 2081 | event.GetPosition()); |
f6bcfd97 | 2082 | } |
63852e78 | 2083 | } |
f6bcfd97 | 2084 | else if (event.Moving()) |
63852e78 | 2085 | { |
f6bcfd97 BP |
2086 | bool setCursor; |
2087 | if (hit_border) | |
2088 | { | |
2089 | setCursor = m_currentCursor == wxSTANDARD_CURSOR; | |
2090 | m_currentCursor = m_resizeCursor; | |
2091 | } | |
2092 | else | |
2093 | { | |
2094 | setCursor = m_currentCursor != wxSTANDARD_CURSOR; | |
2095 | m_currentCursor = wxSTANDARD_CURSOR; | |
2096 | } | |
2097 | ||
2098 | if ( setCursor ) | |
2099 | SetCursor(*m_currentCursor); | |
63852e78 | 2100 | } |
e1e955e1 | 2101 | } |
e1e955e1 | 2102 | } |
c801d85f KB |
2103 | |
2104 | void wxListHeaderWindow::OnSetFocus( wxFocusEvent &WXUNUSED(event) ) | |
2105 | { | |
63852e78 | 2106 | m_owner->SetFocus(); |
e1e955e1 | 2107 | } |
c801d85f | 2108 | |
a77ec46d RD |
2109 | void wxListHeaderWindow::SendListEvent(wxEventType type, wxPoint pos) |
2110 | { | |
2111 | wxWindow *parent = GetParent(); | |
2112 | wxListEvent le( type, parent->GetId() ); | |
2113 | le.SetEventObject( parent ); | |
2114 | le.m_pointDrag = pos; | |
2115 | ||
2116 | // the position should be relative to the parent window, not | |
2117 | // this one for compatibility with MSW and common sense: the | |
2118 | // user code doesn't know anything at all about this header | |
2119 | // window, so why should it get positions relative to it? | |
2120 | le.m_pointDrag.y -= GetSize().y; | |
2121 | ||
2122 | le.m_col = m_column; | |
2123 | parent->GetEventHandler()->ProcessEvent( le ); | |
2124 | } | |
2125 | ||
c801d85f KB |
2126 | //----------------------------------------------------------------------------- |
2127 | // wxListRenameTimer (internal) | |
2128 | //----------------------------------------------------------------------------- | |
2129 | ||
bd8289c1 VZ |
2130 | wxListRenameTimer::wxListRenameTimer( wxListMainWindow *owner ) |
2131 | { | |
63852e78 | 2132 | m_owner = owner; |
e1e955e1 | 2133 | } |
c801d85f | 2134 | |
bd8289c1 VZ |
2135 | void wxListRenameTimer::Notify() |
2136 | { | |
63852e78 | 2137 | m_owner->OnRenameTimer(); |
e1e955e1 | 2138 | } |
c801d85f | 2139 | |
ee7ee469 RR |
2140 | //----------------------------------------------------------------------------- |
2141 | // wxListTextCtrl (internal) | |
2142 | //----------------------------------------------------------------------------- | |
2143 | ||
ee7ee469 | 2144 | BEGIN_EVENT_TABLE(wxListTextCtrl,wxTextCtrl) |
63852e78 | 2145 | EVT_CHAR (wxListTextCtrl::OnChar) |
2c1f73ee | 2146 | EVT_KEY_UP (wxListTextCtrl::OnKeyUp) |
63852e78 | 2147 | EVT_KILL_FOCUS (wxListTextCtrl::OnKillFocus) |
ee7ee469 RR |
2148 | END_EVENT_TABLE() |
2149 | ||
62d89eb4 VZ |
2150 | wxListTextCtrl::wxListTextCtrl(wxListMainWindow *owner, size_t itemEdit) |
2151 | : m_startValue(owner->GetItemText(itemEdit)), | |
2152 | m_itemEdited(itemEdit) | |
2153 | { | |
63852e78 | 2154 | m_owner = owner; |
dd5a32cc | 2155 | m_finished = FALSE; |
62d89eb4 VZ |
2156 | |
2157 | wxRect rectLabel = owner->GetLineLabelRect(itemEdit); | |
2158 | ||
2159 | m_owner->CalcScrolledPosition(rectLabel.x, rectLabel.y, | |
2160 | &rectLabel.x, &rectLabel.y); | |
2161 | ||
2162 | (void)Create(owner, wxID_ANY, m_startValue, | |
2163 | wxPoint(rectLabel.x-4,rectLabel.y-4), | |
2164 | wxSize(rectLabel.width+11,rectLabel.height+8)); | |
ee7ee469 RR |
2165 | } |
2166 | ||
62d89eb4 | 2167 | void wxListTextCtrl::Finish() |
ee7ee469 | 2168 | { |
62d89eb4 | 2169 | if ( !m_finished ) |
63852e78 | 2170 | { |
62d89eb4 | 2171 | wxPendingDelete.Append(this); |
f6bcfd97 | 2172 | |
dd5a32cc | 2173 | m_finished = TRUE; |
62d89eb4 | 2174 | |
a6d57d03 | 2175 | m_owner->SetFocus(); |
62d89eb4 VZ |
2176 | } |
2177 | } | |
dd5a32cc | 2178 | |
62d89eb4 VZ |
2179 | bool wxListTextCtrl::AcceptChanges() |
2180 | { | |
2181 | const wxString value = GetValue(); | |
2182 | ||
2183 | if ( value == m_startValue ) | |
2184 | { | |
2185 | // nothing changed, always accept | |
2186 | return TRUE; | |
63852e78 | 2187 | } |
62d89eb4 VZ |
2188 | |
2189 | if ( !m_owner->OnRenameAccept(m_itemEdited, value) ) | |
63852e78 | 2190 | { |
62d89eb4 VZ |
2191 | // vetoed by the user |
2192 | return FALSE; | |
2193 | } | |
f6bcfd97 | 2194 | |
62d89eb4 VZ |
2195 | // accepted, do rename the item |
2196 | m_owner->SetItemText(m_itemEdited, value); | |
f6bcfd97 | 2197 | |
62d89eb4 VZ |
2198 | return TRUE; |
2199 | } | |
dd5a32cc | 2200 | |
62d89eb4 VZ |
2201 | void wxListTextCtrl::OnChar( wxKeyEvent &event ) |
2202 | { | |
2203 | switch ( event.m_keyCode ) | |
2204 | { | |
2205 | case WXK_RETURN: | |
2206 | if ( !AcceptChanges() ) | |
2207 | { | |
2208 | // vetoed by the user code | |
2209 | break; | |
2210 | } | |
2211 | //else: fall through | |
f6bcfd97 | 2212 | |
62d89eb4 VZ |
2213 | case WXK_ESCAPE: |
2214 | Finish(); | |
2215 | break; | |
2216 | ||
2217 | default: | |
2218 | event.Skip(); | |
2219 | } | |
63852e78 RR |
2220 | } |
2221 | ||
c13cace1 VS |
2222 | void wxListTextCtrl::OnKeyUp( wxKeyEvent &event ) |
2223 | { | |
dd5a32cc RR |
2224 | if (m_finished) |
2225 | { | |
2226 | event.Skip(); | |
2227 | return; | |
2228 | } | |
2229 | ||
c13cace1 VS |
2230 | // auto-grow the textctrl: |
2231 | wxSize parentSize = m_owner->GetSize(); | |
2232 | wxPoint myPos = GetPosition(); | |
2233 | wxSize mySize = GetSize(); | |
2234 | int sx, sy; | |
a6d57d03 | 2235 | GetTextExtent(GetValue() + _T("MM"), &sx, &sy); |
cf1dfa6b VZ |
2236 | if (myPos.x + sx > parentSize.x) |
2237 | sx = parentSize.x - myPos.x; | |
2238 | if (mySize.x > sx) | |
2239 | sx = mySize.x; | |
c13cace1 | 2240 | SetSize(sx, -1); |
2c1f73ee | 2241 | |
c13cace1 VS |
2242 | event.Skip(); |
2243 | } | |
2244 | ||
dd5a32cc | 2245 | void wxListTextCtrl::OnKillFocus( wxFocusEvent &event ) |
63852e78 | 2246 | { |
62d89eb4 | 2247 | if ( !m_finished ) |
dd5a32cc | 2248 | { |
62d89eb4 | 2249 | (void)AcceptChanges(); |
004fd0c8 | 2250 | |
62d89eb4 VZ |
2251 | Finish(); |
2252 | } | |
a77ec46d | 2253 | |
62d89eb4 | 2254 | event.Skip(); |
ee7ee469 RR |
2255 | } |
2256 | ||
c801d85f KB |
2257 | //----------------------------------------------------------------------------- |
2258 | // wxListMainWindow | |
2259 | //----------------------------------------------------------------------------- | |
2260 | ||
5a1cad6e | 2261 | IMPLEMENT_DYNAMIC_CLASS(wxListMainWindow,wxScrolledWindow) |
bd8289c1 | 2262 | |
c801d85f KB |
2263 | BEGIN_EVENT_TABLE(wxListMainWindow,wxScrolledWindow) |
2264 | EVT_PAINT (wxListMainWindow::OnPaint) | |
c801d85f KB |
2265 | EVT_MOUSE_EVENTS (wxListMainWindow::OnMouse) |
2266 | EVT_CHAR (wxListMainWindow::OnChar) | |
3dfb93fd | 2267 | EVT_KEY_DOWN (wxListMainWindow::OnKeyDown) |
c801d85f KB |
2268 | EVT_SET_FOCUS (wxListMainWindow::OnSetFocus) |
2269 | EVT_KILL_FOCUS (wxListMainWindow::OnKillFocus) | |
2fa7c206 | 2270 | EVT_SCROLLWIN (wxListMainWindow::OnScroll) |
c801d85f KB |
2271 | END_EVENT_TABLE() |
2272 | ||
1370703e | 2273 | void wxListMainWindow::Init() |
c801d85f | 2274 | { |
139adb6a | 2275 | m_columns.DeleteContents( TRUE ); |
139adb6a | 2276 | m_dirty = TRUE; |
cf1dfa6b VZ |
2277 | m_countVirt = 0; |
2278 | m_lineFrom = | |
b54e41c5 | 2279 | m_lineTo = (size_t)-1; |
cf1dfa6b VZ |
2280 | m_linesPerPage = 0; |
2281 | ||
2282 | m_headerWidth = | |
2283 | m_lineHeight = 0; | |
1370703e | 2284 | |
139adb6a RR |
2285 | m_small_image_list = (wxImageList *) NULL; |
2286 | m_normal_image_list = (wxImageList *) NULL; | |
1370703e | 2287 | |
139adb6a RR |
2288 | m_small_spacing = 30; |
2289 | m_normal_spacing = 40; | |
1370703e | 2290 | |
139adb6a | 2291 | m_hasFocus = FALSE; |
1370703e VZ |
2292 | m_dragCount = 0; |
2293 | m_isCreated = FALSE; | |
2294 | ||
139adb6a RR |
2295 | m_lastOnSame = FALSE; |
2296 | m_renameTimer = new wxListRenameTimer( this ); | |
1370703e | 2297 | |
cf1dfa6b | 2298 | m_current = |
efbb7287 | 2299 | m_lineLastClicked = |
1370703e | 2300 | m_lineBeforeLastClicked = (size_t)-1; |
c5c528fc VZ |
2301 | |
2302 | m_freezeCount = 0; | |
e1e955e1 | 2303 | } |
c801d85f | 2304 | |
cf1dfa6b VZ |
2305 | void wxListMainWindow::InitScrolling() |
2306 | { | |
2307 | if ( HasFlag(wxLC_REPORT) ) | |
2308 | { | |
2309 | m_xScroll = SCROLL_UNIT_X; | |
2310 | m_yScroll = SCROLL_UNIT_Y; | |
2311 | } | |
2312 | else | |
2313 | { | |
2314 | m_xScroll = SCROLL_UNIT_Y; | |
2315 | m_yScroll = 0; | |
2316 | } | |
2317 | } | |
2318 | ||
1370703e | 2319 | wxListMainWindow::wxListMainWindow() |
c801d85f | 2320 | { |
1370703e VZ |
2321 | Init(); |
2322 | ||
49ecb029 VZ |
2323 | m_highlightBrush = |
2324 | m_highlightUnfocusedBrush = (wxBrush *) NULL; | |
1370703e VZ |
2325 | |
2326 | m_xScroll = | |
2327 | m_yScroll = 0; | |
2328 | } | |
2329 | ||
2330 | wxListMainWindow::wxListMainWindow( wxWindow *parent, | |
2331 | wxWindowID id, | |
2332 | const wxPoint& pos, | |
2333 | const wxSize& size, | |
2334 | long style, | |
2335 | const wxString &name ) | |
2336 | : wxScrolledWindow( parent, id, pos, size, | |
2337 | style | wxHSCROLL | wxVSCROLL, name ) | |
2338 | { | |
2339 | Init(); | |
2340 | ||
49ecb029 VZ |
2341 | m_highlightBrush = new wxBrush |
2342 | ( | |
a756f210 | 2343 | wxSystemSettings::GetColour |
49ecb029 VZ |
2344 | ( |
2345 | wxSYS_COLOUR_HIGHLIGHT | |
2346 | ), | |
2347 | wxSOLID | |
2348 | ); | |
2349 | ||
2350 | m_highlightUnfocusedBrush = new wxBrush | |
2351 | ( | |
a756f210 | 2352 | wxSystemSettings::GetColour |
49ecb029 VZ |
2353 | ( |
2354 | wxSYS_COLOUR_BTNSHADOW | |
2355 | ), | |
2356 | wxSOLID | |
2357 | ); | |
2358 | ||
139adb6a RR |
2359 | wxSize sz = size; |
2360 | sz.y = 25; | |
bd8289c1 | 2361 | |
cf1dfa6b | 2362 | InitScrolling(); |
139adb6a | 2363 | SetScrollbars( m_xScroll, m_yScroll, 0, 0, 0, 0 ); |
bd8289c1 | 2364 | |
a756f210 | 2365 | SetBackgroundColour( wxSystemSettings::GetColour( wxSYS_COLOUR_LISTBOX ) ); |
e1e955e1 | 2366 | } |
c801d85f | 2367 | |
fd9811b1 | 2368 | wxListMainWindow::~wxListMainWindow() |
c801d85f | 2369 | { |
5fe143df | 2370 | DoDeleteAllItems(); |
12c1b46a | 2371 | |
b54e41c5 | 2372 | delete m_highlightBrush; |
49ecb029 | 2373 | delete m_highlightUnfocusedBrush; |
004fd0c8 | 2374 | |
139adb6a | 2375 | delete m_renameTimer; |
e1e955e1 | 2376 | } |
c801d85f | 2377 | |
cf1dfa6b | 2378 | void wxListMainWindow::CacheLineData(size_t line) |
c801d85f | 2379 | { |
cf1dfa6b | 2380 | wxListCtrl *listctrl = GetListCtrl(); |
25e3a937 | 2381 | |
b54e41c5 | 2382 | wxListLineData *ld = GetDummyLine(); |
f6bcfd97 | 2383 | |
cf1dfa6b VZ |
2384 | size_t countCol = GetColumnCount(); |
2385 | for ( size_t col = 0; col < countCol; col++ ) | |
2386 | { | |
2387 | ld->SetText(col, listctrl->OnGetItemText(line, col)); | |
2388 | } | |
2389 | ||
5cd89174 | 2390 | ld->SetImage(listctrl->OnGetItemImage(line)); |
6c02c329 | 2391 | ld->SetAttr(listctrl->OnGetItemAttr(line)); |
e1e955e1 | 2392 | } |
c801d85f | 2393 | |
b54e41c5 | 2394 | wxListLineData *wxListMainWindow::GetDummyLine() const |
c801d85f | 2395 | { |
cf1dfa6b | 2396 | wxASSERT_MSG( !IsEmpty(), _T("invalid line index") ); |
2c1f73ee | 2397 | |
cf1dfa6b | 2398 | if ( m_lines.IsEmpty() ) |
2c1f73ee | 2399 | { |
cf1dfa6b VZ |
2400 | // normal controls are supposed to have something in m_lines |
2401 | // already if it's not empty | |
2402 | wxASSERT_MSG( IsVirtual(), _T("logic error") ); | |
2403 | ||
2404 | wxListMainWindow *self = wxConstCast(this, wxListMainWindow); | |
5cd89174 | 2405 | wxListLineData *line = new wxListLineData(self); |
cf1dfa6b | 2406 | self->m_lines.Add(line); |
2c1f73ee VZ |
2407 | } |
2408 | ||
cf1dfa6b VZ |
2409 | return &m_lines[0]; |
2410 | } | |
2411 | ||
5cd89174 VZ |
2412 | // ---------------------------------------------------------------------------- |
2413 | // line geometry (report mode only) | |
2414 | // ---------------------------------------------------------------------------- | |
2415 | ||
cf1dfa6b VZ |
2416 | wxCoord wxListMainWindow::GetLineHeight() const |
2417 | { | |
2418 | wxASSERT_MSG( HasFlag(wxLC_REPORT), _T("only works in report mode") ); | |
673dfcfa | 2419 | |
cf1dfa6b VZ |
2420 | // we cache the line height as calling GetTextExtent() is slow |
2421 | if ( !m_lineHeight ) | |
2c1f73ee | 2422 | { |
cf1dfa6b | 2423 | wxListMainWindow *self = wxConstCast(this, wxListMainWindow); |
bd8289c1 | 2424 | |
cf1dfa6b VZ |
2425 | wxClientDC dc( self ); |
2426 | dc.SetFont( GetFont() ); | |
c801d85f | 2427 | |
cf1dfa6b VZ |
2428 | wxCoord y; |
2429 | dc.GetTextExtent(_T("H"), NULL, &y); | |
004fd0c8 | 2430 | |
cf1dfa6b VZ |
2431 | if ( y < SCROLL_UNIT_Y ) |
2432 | y = SCROLL_UNIT_Y; | |
2433 | y += EXTRA_HEIGHT; | |
206b0a67 | 2434 | |
cf1dfa6b VZ |
2435 | self->m_lineHeight = y + LINE_SPACING; |
2436 | } | |
bffa1c77 | 2437 | |
cf1dfa6b VZ |
2438 | return m_lineHeight; |
2439 | } | |
bffa1c77 | 2440 | |
cf1dfa6b VZ |
2441 | wxCoord wxListMainWindow::GetLineY(size_t line) const |
2442 | { | |
2443 | wxASSERT_MSG( HasFlag(wxLC_REPORT), _T("only works in report mode") ); | |
1370703e | 2444 | |
cf1dfa6b VZ |
2445 | return LINE_SPACING + line*GetLineHeight(); |
2446 | } | |
206b0a67 | 2447 | |
5cd89174 VZ |
2448 | wxRect wxListMainWindow::GetLineRect(size_t line) const |
2449 | { | |
2450 | if ( !InReportView() ) | |
2451 | return GetLine(line)->m_gi->m_rectAll; | |
2452 | ||
2453 | wxRect rect; | |
2454 | rect.x = HEADER_OFFSET_X; | |
2455 | rect.y = GetLineY(line); | |
2456 | rect.width = GetHeaderWidth(); | |
2457 | rect.height = GetLineHeight(); | |
2458 | ||
2459 | return rect; | |
2460 | } | |
2461 | ||
2462 | wxRect wxListMainWindow::GetLineLabelRect(size_t line) const | |
2463 | { | |
2464 | if ( !InReportView() ) | |
2465 | return GetLine(line)->m_gi->m_rectLabel; | |
2466 | ||
2467 | wxRect rect; | |
2468 | rect.x = HEADER_OFFSET_X; | |
2469 | rect.y = GetLineY(line); | |
2470 | rect.width = GetColumnWidth(0); | |
2471 | rect.height = GetLineHeight(); | |
2472 | ||
2473 | return rect; | |
2474 | } | |
2475 | ||
2476 | wxRect wxListMainWindow::GetLineIconRect(size_t line) const | |
2477 | { | |
2478 | if ( !InReportView() ) | |
2479 | return GetLine(line)->m_gi->m_rectIcon; | |
2480 | ||
2481 | wxListLineData *ld = GetLine(line); | |
2482 | wxASSERT_MSG( ld->HasImage(), _T("should have an image") ); | |
2483 | ||
2484 | wxRect rect; | |
2485 | rect.x = HEADER_OFFSET_X; | |
2486 | rect.y = GetLineY(line); | |
2487 | GetImageSize(ld->GetImage(), rect.width, rect.height); | |
2488 | ||
2489 | return rect; | |
2490 | } | |
2491 | ||
2492 | wxRect wxListMainWindow::GetLineHighlightRect(size_t line) const | |
2493 | { | |
2494 | return InReportView() ? GetLineRect(line) | |
2495 | : GetLine(line)->m_gi->m_rectHighlight; | |
2496 | } | |
2497 | ||
2498 | long wxListMainWindow::HitTestLine(size_t line, int x, int y) const | |
2499 | { | |
fc4f1d5f VZ |
2500 | wxASSERT_MSG( line < GetItemCount(), _T("invalid line in HitTestLine") ); |
2501 | ||
5cd89174 VZ |
2502 | wxListLineData *ld = GetLine(line); |
2503 | ||
2504 | if ( ld->HasImage() && GetLineIconRect(line).Inside(x, y) ) | |
2505 | return wxLIST_HITTEST_ONITEMICON; | |
2506 | ||
acf4d858 VS |
2507 | // VS: Testing for "ld->HasText() || InReportView()" instead of |
2508 | // "ld->HasText()" is needed to make empty lines in report view | |
2509 | // possible | |
2510 | if ( ld->HasText() || InReportView() ) | |
5cd89174 VZ |
2511 | { |
2512 | wxRect rect = InReportView() ? GetLineRect(line) | |
2513 | : GetLineLabelRect(line); | |
2514 | ||
2515 | if ( rect.Inside(x, y) ) | |
2516 | return wxLIST_HITTEST_ONITEMLABEL; | |
2517 | } | |
2518 | ||
2519 | return 0; | |
2520 | } | |
2521 | ||
2522 | // ---------------------------------------------------------------------------- | |
2523 | // highlight (selection) handling | |
2524 | // ---------------------------------------------------------------------------- | |
2525 | ||
b54e41c5 | 2526 | bool wxListMainWindow::IsHighlighted(size_t line) const |
cf1dfa6b VZ |
2527 | { |
2528 | if ( IsVirtual() ) | |
2529 | { | |
b54e41c5 | 2530 | return m_selStore.IsSelected(line); |
cf1dfa6b VZ |
2531 | } |
2532 | else // !virtual | |
2533 | { | |
2534 | wxListLineData *ld = GetLine(line); | |
b54e41c5 | 2535 | wxCHECK_MSG( ld, FALSE, _T("invalid index in IsHighlighted") ); |
cf1dfa6b | 2536 | |
b54e41c5 | 2537 | return ld->IsHighlighted(); |
cf1dfa6b VZ |
2538 | } |
2539 | } | |
2540 | ||
68a9ef0e VZ |
2541 | void wxListMainWindow::HighlightLines( size_t lineFrom, |
2542 | size_t lineTo, | |
2543 | bool highlight ) | |
cf1dfa6b | 2544 | { |
cf1dfa6b VZ |
2545 | if ( IsVirtual() ) |
2546 | { | |
68a9ef0e VZ |
2547 | wxArrayInt linesChanged; |
2548 | if ( !m_selStore.SelectRange(lineFrom, lineTo, highlight, | |
2549 | &linesChanged) ) | |
2550 | { | |
2551 | // meny items changed state, refresh everything | |
2552 | RefreshLines(lineFrom, lineTo); | |
2553 | } | |
2554 | else // only a few items changed state, refresh only them | |
2555 | { | |
2556 | size_t count = linesChanged.GetCount(); | |
2557 | for ( size_t n = 0; n < count; n++ ) | |
2558 | { | |
2559 | RefreshLine(linesChanged[n]); | |
2560 | } | |
2561 | } | |
b54e41c5 | 2562 | } |
68a9ef0e | 2563 | else // iterate over all items in non report view |
b54e41c5 | 2564 | { |
b54e41c5 | 2565 | for ( size_t line = lineFrom; line <= lineTo; line++ ) |
cf1dfa6b | 2566 | { |
b54e41c5 | 2567 | if ( HighlightLine(line, highlight) ) |
68a9ef0e VZ |
2568 | { |
2569 | RefreshLine(line); | |
2570 | } | |
cf1dfa6b | 2571 | } |
b54e41c5 VZ |
2572 | } |
2573 | } | |
2574 | ||
2575 | bool wxListMainWindow::HighlightLine( size_t line, bool highlight ) | |
2576 | { | |
2577 | bool changed; | |
2578 | ||
2579 | if ( IsVirtual() ) | |
2580 | { | |
2581 | changed = m_selStore.SelectItem(line, highlight); | |
cf1dfa6b VZ |
2582 | } |
2583 | else // !virtual | |
2584 | { | |
2585 | wxListLineData *ld = GetLine(line); | |
49ecb029 | 2586 | wxCHECK_MSG( ld, FALSE, _T("invalid index in HighlightLine") ); |
cf1dfa6b | 2587 | |
b54e41c5 | 2588 | changed = ld->Highlight(highlight); |
cf1dfa6b VZ |
2589 | } |
2590 | ||
2591 | if ( changed ) | |
2592 | { | |
b54e41c5 | 2593 | SendNotify( line, highlight ? wxEVT_COMMAND_LIST_ITEM_SELECTED |
5cd89174 | 2594 | : wxEVT_COMMAND_LIST_ITEM_DESELECTED ); |
cf1dfa6b VZ |
2595 | } |
2596 | ||
2597 | return changed; | |
2598 | } | |
2599 | ||
2600 | void wxListMainWindow::RefreshLine( size_t line ) | |
2601 | { | |
6ea1323a VZ |
2602 | if ( HasFlag(wxLC_REPORT) ) |
2603 | { | |
2604 | size_t visibleFrom, visibleTo; | |
2605 | GetVisibleLinesRange(&visibleFrom, &visibleTo); | |
c1c4c551 | 2606 | |
6ea1323a VZ |
2607 | if ( line < visibleFrom || line > visibleTo ) |
2608 | return; | |
2609 | } | |
c1c4c551 | 2610 | |
5cd89174 | 2611 | wxRect rect = GetLineRect(line); |
cf1dfa6b VZ |
2612 | |
2613 | CalcScrolledPosition( rect.x, rect.y, &rect.x, &rect.y ); | |
2614 | RefreshRect( rect ); | |
2615 | } | |
2616 | ||
2617 | void wxListMainWindow::RefreshLines( size_t lineFrom, size_t lineTo ) | |
2618 | { | |
2619 | // we suppose that they are ordered by caller | |
2620 | wxASSERT_MSG( lineFrom <= lineTo, _T("indices in disorder") ); | |
2621 | ||
6b4a8d93 VZ |
2622 | wxASSERT_MSG( lineTo < GetItemCount(), _T("invalid line range") ); |
2623 | ||
cf1dfa6b VZ |
2624 | if ( HasFlag(wxLC_REPORT) ) |
2625 | { | |
b54e41c5 VZ |
2626 | size_t visibleFrom, visibleTo; |
2627 | GetVisibleLinesRange(&visibleFrom, &visibleTo); | |
2628 | ||
2629 | if ( lineFrom < visibleFrom ) | |
2630 | lineFrom = visibleFrom; | |
2631 | if ( lineTo > visibleTo ) | |
2632 | lineTo = visibleTo; | |
cf1dfa6b VZ |
2633 | |
2634 | wxRect rect; | |
2635 | rect.x = 0; | |
2636 | rect.y = GetLineY(lineFrom); | |
2637 | rect.width = GetClientSize().x; | |
91c6cc0e | 2638 | rect.height = GetLineY(lineTo) - rect.y + GetLineHeight(); |
cf1dfa6b VZ |
2639 | |
2640 | CalcScrolledPosition( rect.x, rect.y, &rect.x, &rect.y ); | |
2641 | RefreshRect( rect ); | |
2642 | } | |
2643 | else // !report | |
2644 | { | |
2645 | // TODO: this should be optimized... | |
2646 | for ( size_t line = lineFrom; line <= lineTo; line++ ) | |
2647 | { | |
2648 | RefreshLine(line); | |
2649 | } | |
2650 | } | |
2651 | } | |
2652 | ||
6b4a8d93 VZ |
2653 | void wxListMainWindow::RefreshAfter( size_t lineFrom ) |
2654 | { | |
2655 | if ( HasFlag(wxLC_REPORT) ) | |
2656 | { | |
2657 | size_t visibleFrom; | |
2658 | GetVisibleLinesRange(&visibleFrom, NULL); | |
2659 | ||
2660 | if ( lineFrom < visibleFrom ) | |
2661 | lineFrom = visibleFrom; | |
2662 | ||
2663 | wxRect rect; | |
2664 | rect.x = 0; | |
2665 | rect.y = GetLineY(lineFrom); | |
2666 | ||
2667 | wxSize size = GetClientSize(); | |
2668 | rect.width = size.x; | |
2669 | // refresh till the bottom of the window | |
2670 | rect.height = size.y - rect.y; | |
2671 | ||
2672 | CalcScrolledPosition( rect.x, rect.y, &rect.x, &rect.y ); | |
2673 | RefreshRect( rect ); | |
6b4a8d93 VZ |
2674 | } |
2675 | else // !report | |
2676 | { | |
2677 | // TODO: how to do it more efficiently? | |
2678 | m_dirty = TRUE; | |
2679 | } | |
2680 | } | |
2681 | ||
49ecb029 VZ |
2682 | void wxListMainWindow::RefreshSelected() |
2683 | { | |
2684 | if ( IsEmpty() ) | |
2685 | return; | |
2686 | ||
2687 | size_t from, to; | |
2688 | if ( InReportView() ) | |
2689 | { | |
2690 | GetVisibleLinesRange(&from, &to); | |
2691 | } | |
2692 | else // !virtual | |
2693 | { | |
2694 | from = 0; | |
2695 | to = GetItemCount() - 1; | |
2696 | } | |
2697 | ||
cf30ae13 | 2698 | if ( HasCurrent() && m_current >= from && m_current <= to ) |
49ecb029 VZ |
2699 | { |
2700 | RefreshLine(m_current); | |
2701 | } | |
2702 | ||
2703 | for ( size_t line = from; line <= to; line++ ) | |
2704 | { | |
2705 | // NB: the test works as expected even if m_current == -1 | |
2706 | if ( line != m_current && IsHighlighted(line) ) | |
2707 | { | |
2708 | RefreshLine(line); | |
2709 | } | |
2710 | } | |
2711 | } | |
2712 | ||
c5c528fc VZ |
2713 | void wxListMainWindow::Freeze() |
2714 | { | |
2715 | m_freezeCount++; | |
2716 | } | |
2717 | ||
2718 | void wxListMainWindow::Thaw() | |
2719 | { | |
2720 | wxCHECK_RET( m_freezeCount > 0, _T("thawing unfrozen list control?") ); | |
2721 | ||
2722 | if ( !--m_freezeCount ) | |
2723 | { | |
2724 | Refresh(); | |
2725 | } | |
2726 | } | |
2727 | ||
cf1dfa6b VZ |
2728 | void wxListMainWindow::OnPaint( wxPaintEvent &WXUNUSED(event) ) |
2729 | { | |
2730 | // Note: a wxPaintDC must be constructed even if no drawing is | |
2731 | // done (a Windows requirement). | |
2732 | wxPaintDC dc( this ); | |
2733 | ||
c5c528fc | 2734 | if ( IsEmpty() || m_freezeCount ) |
cf1dfa6b | 2735 | { |
c5c528fc | 2736 | // nothing to draw or not the moment to draw it |
cf1dfa6b VZ |
2737 | return; |
2738 | } | |
2739 | ||
1e4d446b VZ |
2740 | if ( m_dirty ) |
2741 | { | |
2742 | // delay the repainting until we calculate all the items positions | |
2743 | return; | |
2744 | } | |
2745 | ||
cf1dfa6b VZ |
2746 | PrepareDC( dc ); |
2747 | ||
2748 | int dev_x, dev_y; | |
2749 | CalcScrolledPosition( 0, 0, &dev_x, &dev_y ); | |
2750 | ||
2751 | dc.BeginDrawing(); | |
2752 | ||
2753 | dc.SetFont( GetFont() ); | |
2754 | ||
2755 | if ( HasFlag(wxLC_REPORT) ) | |
2756 | { | |
b54e41c5 | 2757 | int lineHeight = GetLineHeight(); |
cf1dfa6b | 2758 | |
b54e41c5 VZ |
2759 | size_t visibleFrom, visibleTo; |
2760 | GetVisibleLinesRange(&visibleFrom, &visibleTo); | |
b84839ae VZ |
2761 | |
2762 | wxRect rectLine; | |
2763 | wxCoord xOrig, yOrig; | |
2764 | CalcUnscrolledPosition(0, 0, &xOrig, &yOrig); | |
2765 | ||
ff3d11a0 | 2766 | // tell the caller cache to cache the data |
91c6cc0e VZ |
2767 | if ( IsVirtual() ) |
2768 | { | |
2769 | wxListEvent evCache(wxEVT_COMMAND_LIST_CACHE_HINT, | |
2770 | GetParent()->GetId()); | |
2771 | evCache.SetEventObject( GetParent() ); | |
2772 | evCache.m_oldItemIndex = visibleFrom; | |
2773 | evCache.m_itemIndex = visibleTo; | |
2774 | GetParent()->GetEventHandler()->ProcessEvent( evCache ); | |
2775 | } | |
ff3d11a0 | 2776 | |
b54e41c5 | 2777 | for ( size_t line = visibleFrom; line <= visibleTo; line++ ) |
cf1dfa6b | 2778 | { |
b84839ae VZ |
2779 | rectLine = GetLineRect(line); |
2780 | ||
2781 | if ( !IsExposed(rectLine.x - xOrig, rectLine.y - yOrig, | |
2782 | rectLine.width, rectLine.height) ) | |
2783 | { | |
2784 | // don't redraw unaffected lines to avoid flicker | |
2785 | continue; | |
2786 | } | |
2787 | ||
5cd89174 | 2788 | GetLine(line)->DrawInReportMode( &dc, |
b84839ae | 2789 | rectLine, |
5cd89174 | 2790 | GetLineHighlightRect(line), |
49ecb029 | 2791 | IsHighlighted(line) ); |
cf1dfa6b VZ |
2792 | } |
2793 | ||
2794 | if ( HasFlag(wxLC_HRULES) ) | |
2795 | { | |
b54e41c5 | 2796 | wxPen pen(GetRuleColour(), 1, wxSOLID); |
cf1dfa6b VZ |
2797 | wxSize clientSize = GetClientSize(); |
2798 | ||
b54e41c5 | 2799 | for ( size_t i = visibleFrom; i <= visibleTo; i++ ) |
cf1dfa6b VZ |
2800 | { |
2801 | dc.SetPen(pen); | |
2802 | dc.SetBrush( *wxTRANSPARENT_BRUSH ); | |
b54e41c5 VZ |
2803 | dc.DrawLine(0 - dev_x, i*lineHeight, |
2804 | clientSize.x - dev_x, i*lineHeight); | |
cf1dfa6b VZ |
2805 | } |
2806 | ||
2807 | // Draw last horizontal rule | |
b54e41c5 | 2808 | if ( visibleTo > visibleFrom ) |
cf1dfa6b VZ |
2809 | { |
2810 | dc.SetPen(pen); | |
2811 | dc.SetBrush( *wxTRANSPARENT_BRUSH ); | |
b54e41c5 VZ |
2812 | dc.DrawLine(0 - dev_x, m_lineTo*lineHeight, |
2813 | clientSize.x - dev_x , m_lineTo*lineHeight ); | |
cf1dfa6b | 2814 | } |
2c1f73ee | 2815 | } |
206b0a67 JS |
2816 | |
2817 | // Draw vertical rules if required | |
cf1dfa6b | 2818 | if ( HasFlag(wxLC_VRULES) && !IsEmpty() ) |
206b0a67 | 2819 | { |
b54e41c5 | 2820 | wxPen pen(GetRuleColour(), 1, wxSOLID); |
cf1dfa6b | 2821 | |
206b0a67 JS |
2822 | int col = 0; |
2823 | wxRect firstItemRect; | |
2824 | wxRect lastItemRect; | |
2825 | GetItemRect(0, firstItemRect); | |
2826 | GetItemRect(GetItemCount() - 1, lastItemRect); | |
2827 | int x = firstItemRect.GetX(); | |
673dfcfa JS |
2828 | dc.SetPen(pen); |
2829 | dc.SetBrush(* wxTRANSPARENT_BRUSH); | |
206b0a67 JS |
2830 | for (col = 0; col < GetColumnCount(); col++) |
2831 | { | |
2832 | int colWidth = GetColumnWidth(col); | |
cf1dfa6b VZ |
2833 | x += colWidth; |
2834 | dc.DrawLine(x - dev_x, firstItemRect.GetY() - 1 - dev_y, | |
2835 | x - dev_x, lastItemRect.GetBottom() + 1 - dev_y); | |
206b0a67 | 2836 | } |
d786bf87 | 2837 | } |
139adb6a | 2838 | } |
cf1dfa6b | 2839 | else // !report |
139adb6a | 2840 | { |
1370703e | 2841 | size_t count = GetItemCount(); |
cf1dfa6b VZ |
2842 | for ( size_t i = 0; i < count; i++ ) |
2843 | { | |
2844 | GetLine(i)->Draw( &dc ); | |
2845 | } | |
139adb6a | 2846 | } |
004fd0c8 | 2847 | |
c25f61f1 | 2848 | if ( HasCurrent() ) |
cf1dfa6b | 2849 | { |
c25f61f1 | 2850 | // don't draw rect outline under Max if we already have the background |
49ecb029 VZ |
2851 | // color but under other platforms only draw it if we do: it is a bit |
2852 | // silly to draw "focus rect" if we don't have focus! | |
4176fb7d | 2853 | #ifdef __WXMAC__ |
c25f61f1 | 2854 | if ( !m_hasFocus ) |
49ecb029 VZ |
2855 | #else // !__WXMAC__ |
2856 | if ( m_hasFocus ) | |
2857 | #endif // __WXMAC__/!__WXMAC__ | |
c25f61f1 VZ |
2858 | { |
2859 | dc.SetPen( *wxBLACK_PEN ); | |
2860 | dc.SetBrush( *wxTRANSPARENT_BRUSH ); | |
2861 | dc.DrawRectangle( GetLineHighlightRect(m_current) ); | |
2862 | } | |
cf1dfa6b | 2863 | } |
c801d85f | 2864 | |
139adb6a | 2865 | dc.EndDrawing(); |
e1e955e1 | 2866 | } |
c801d85f | 2867 | |
b54e41c5 | 2868 | void wxListMainWindow::HighlightAll( bool on ) |
c801d85f | 2869 | { |
b54e41c5 | 2870 | if ( IsSingleSel() ) |
c801d85f | 2871 | { |
b54e41c5 VZ |
2872 | wxASSERT_MSG( !on, _T("can't do this in a single sel control") ); |
2873 | ||
2874 | // we just have one item to turn off | |
2875 | if ( HasCurrent() && IsHighlighted(m_current) ) | |
139adb6a | 2876 | { |
b54e41c5 VZ |
2877 | HighlightLine(m_current, FALSE); |
2878 | RefreshLine(m_current); | |
139adb6a | 2879 | } |
e1e955e1 | 2880 | } |
b54e41c5 | 2881 | else // multi sel |
cf1dfa6b | 2882 | { |
b54e41c5 | 2883 | HighlightLines(0, GetItemCount() - 1, on); |
cf1dfa6b | 2884 | } |
e1e955e1 | 2885 | } |
c801d85f | 2886 | |
cf1dfa6b | 2887 | void wxListMainWindow::SendNotify( size_t line, |
05a7f61d VZ |
2888 | wxEventType command, |
2889 | wxPoint point ) | |
c801d85f | 2890 | { |
139adb6a RR |
2891 | wxListEvent le( command, GetParent()->GetId() ); |
2892 | le.SetEventObject( GetParent() ); | |
cf1dfa6b | 2893 | le.m_itemIndex = line; |
05a7f61d VZ |
2894 | |
2895 | // set only for events which have position | |
2896 | if ( point != wxDefaultPosition ) | |
2897 | le.m_pointDrag = point; | |
2898 | ||
c1c4c551 VZ |
2899 | // don't try to get the line info for virtual list controls: the main |
2900 | // program has it anyhow and if we did it would result in accessing all | |
2901 | // the lines, even those which are not visible now and this is precisely | |
2902 | // what we're trying to avoid | |
2903 | if ( !IsVirtual() && (command != wxEVT_COMMAND_LIST_DELETE_ITEM) ) | |
91c6cc0e | 2904 | { |
0ddefeb0 VZ |
2905 | if ( line != (size_t)-1 ) |
2906 | { | |
2907 | GetLine(line)->GetItem( 0, le.m_item ); | |
2908 | } | |
2909 | //else: this happens for wxEVT_COMMAND_LIST_ITEM_FOCUSED event | |
91c6cc0e VZ |
2910 | } |
2911 | //else: there may be no more such item | |
2912 | ||
6e228e42 | 2913 | GetParent()->GetEventHandler()->ProcessEvent( le ); |
e1e955e1 | 2914 | } |
c801d85f | 2915 | |
0ddefeb0 | 2916 | void wxListMainWindow::ChangeCurrent(size_t current) |
c801d85f | 2917 | { |
0ddefeb0 | 2918 | m_current = current; |
c801d85f | 2919 | |
0ddefeb0 | 2920 | SendNotify(current, wxEVT_COMMAND_LIST_ITEM_FOCUSED); |
e1e955e1 | 2921 | } |
c801d85f | 2922 | |
5f1ea0ee | 2923 | void wxListMainWindow::EditLabel( long item ) |
c801d85f | 2924 | { |
cf1dfa6b VZ |
2925 | wxCHECK_RET( (item >= 0) && ((size_t)item < GetItemCount()), |
2926 | wxT("wrong index in wxListCtrl::EditLabel()") ); | |
004fd0c8 | 2927 | |
62d89eb4 | 2928 | size_t itemEdit = (size_t)item; |
e179bd65 | 2929 | |
fd9811b1 | 2930 | wxListEvent le( wxEVT_COMMAND_LIST_BEGIN_LABEL_EDIT, GetParent()->GetId() ); |
139adb6a | 2931 | le.SetEventObject( GetParent() ); |
1370703e | 2932 | le.m_itemIndex = item; |
62d89eb4 | 2933 | wxListLineData *data = GetLine(itemEdit); |
1370703e VZ |
2934 | wxCHECK_RET( data, _T("invalid index in EditLabel()") ); |
2935 | data->GetItem( 0, le.m_item ); | |
62d89eb4 VZ |
2936 | if ( GetParent()->GetEventHandler()->ProcessEvent( le ) && !le.IsAllowed() ) |
2937 | { | |
2938 | // vetoed by user code | |
5f1ea0ee | 2939 | return; |
62d89eb4 | 2940 | } |
004fd0c8 | 2941 | |
cf1dfa6b VZ |
2942 | // We have to call this here because the label in question might just have |
2943 | // been added and no screen update taken place. | |
62d89eb4 | 2944 | if ( m_dirty ) |
cf1dfa6b | 2945 | wxSafeYield(); |
004fd0c8 | 2946 | |
62d89eb4 VZ |
2947 | wxListTextCtrl *text = new wxListTextCtrl(this, itemEdit); |
2948 | ||
92976ab6 | 2949 | text->SetFocus(); |
e1e955e1 | 2950 | } |
c801d85f | 2951 | |
e179bd65 RR |
2952 | void wxListMainWindow::OnRenameTimer() |
2953 | { | |
cf1dfa6b | 2954 | wxCHECK_RET( HasCurrent(), wxT("unexpected rename timer") ); |
004fd0c8 | 2955 | |
cf1dfa6b | 2956 | EditLabel( m_current ); |
e179bd65 RR |
2957 | } |
2958 | ||
62d89eb4 | 2959 | bool wxListMainWindow::OnRenameAccept(size_t itemEdit, const wxString& value) |
c801d85f | 2960 | { |
e179bd65 RR |
2961 | wxListEvent le( wxEVT_COMMAND_LIST_END_LABEL_EDIT, GetParent()->GetId() ); |
2962 | le.SetEventObject( GetParent() ); | |
62d89eb4 | 2963 | le.m_itemIndex = itemEdit; |
1370703e | 2964 | |
62d89eb4 VZ |
2965 | wxListLineData *data = GetLine(itemEdit); |
2966 | wxCHECK_MSG( data, FALSE, _T("invalid index in OnRenameAccept()") ); | |
1370703e VZ |
2967 | |
2968 | data->GetItem( 0, le.m_item ); | |
62d89eb4 VZ |
2969 | le.m_item.m_text = value; |
2970 | return !GetParent()->GetEventHandler()->ProcessEvent( le ) || | |
2971 | le.IsAllowed(); | |
e1e955e1 | 2972 | } |
c801d85f KB |
2973 | |
2974 | void wxListMainWindow::OnMouse( wxMouseEvent &event ) | |
2975 | { | |
3e1c4e00 | 2976 | event.SetEventObject( GetParent() ); |
cf1dfa6b VZ |
2977 | if ( GetParent()->GetEventHandler()->ProcessEvent( event) ) |
2978 | return; | |
2979 | ||
2980 | if ( !HasCurrent() || IsEmpty() ) | |
2981 | return; | |
2982 | ||
2983 | if (m_dirty) | |
2984 | return; | |
e3e65dac | 2985 | |
cf1dfa6b VZ |
2986 | if ( !(event.Dragging() || event.ButtonDown() || event.LeftUp() || |
2987 | event.ButtonDClick()) ) | |
2988 | return; | |
c801d85f | 2989 | |
aaef15bf RR |
2990 | int x = event.GetX(); |
2991 | int y = event.GetY(); | |
2992 | CalcUnscrolledPosition( x, y, &x, &y ); | |
004fd0c8 | 2993 | |
cc734310 | 2994 | // where did we hit it (if we did)? |
92976ab6 | 2995 | long hitResult = 0; |
1370703e | 2996 | |
cf1dfa6b VZ |
2997 | size_t count = GetItemCount(), |
2998 | current; | |
2999 | ||
3000 | if ( HasFlag(wxLC_REPORT) ) | |
92976ab6 | 3001 | { |
5cd89174 | 3002 | current = y / GetLineHeight(); |
cc734310 VZ |
3003 | if ( current < count ) |
3004 | hitResult = HitTestLine(current, x, y); | |
cf1dfa6b VZ |
3005 | } |
3006 | else // !report | |
3007 | { | |
3008 | // TODO: optimize it too! this is less simple than for report view but | |
3009 | // enumerating all items is still not a way to do it!! | |
4e3ace65 | 3010 | for ( current = 0; current < count; current++ ) |
cf1dfa6b | 3011 | { |
5cd89174 | 3012 | hitResult = HitTestLine(current, x, y); |
4e3ace65 VZ |
3013 | if ( hitResult ) |
3014 | break; | |
cf1dfa6b | 3015 | } |
92976ab6 | 3016 | } |
bd8289c1 | 3017 | |
fd9811b1 | 3018 | if (event.Dragging()) |
92976ab6 | 3019 | { |
fd9811b1 | 3020 | if (m_dragCount == 0) |
8d1d2284 VZ |
3021 | { |
3022 | // we have to report the raw, physical coords as we want to be | |
3023 | // able to call HitTest(event.m_pointDrag) from the user code to | |
3024 | // get the item being dragged | |
3025 | m_dragStart = event.GetPosition(); | |
3026 | } | |
bffa1c77 | 3027 | |
fd9811b1 | 3028 | m_dragCount++; |
bffa1c77 | 3029 | |
cf1dfa6b VZ |
3030 | if (m_dragCount != 3) |
3031 | return; | |
bffa1c77 | 3032 | |
05a7f61d VZ |
3033 | int command = event.RightIsDown() ? wxEVT_COMMAND_LIST_BEGIN_RDRAG |
3034 | : wxEVT_COMMAND_LIST_BEGIN_DRAG; | |
bffa1c77 | 3035 | |
fd9811b1 | 3036 | wxListEvent le( command, GetParent()->GetId() ); |
92976ab6 | 3037 | le.SetEventObject( GetParent() ); |
bffa1c77 VZ |
3038 | le.m_pointDrag = m_dragStart; |
3039 | GetParent()->GetEventHandler()->ProcessEvent( le ); | |
3040 | ||
3041 | return; | |
92976ab6 | 3042 | } |
fd9811b1 RR |
3043 | else |
3044 | { | |
3045 | m_dragCount = 0; | |
3046 | } | |
bd8289c1 | 3047 | |
cf1dfa6b VZ |
3048 | if ( !hitResult ) |
3049 | { | |
3050 | // outside of any item | |
3051 | return; | |
3052 | } | |
bd8289c1 | 3053 | |
efbb7287 | 3054 | bool forceClick = FALSE; |
92976ab6 RR |
3055 | if (event.ButtonDClick()) |
3056 | { | |
92976ab6 | 3057 | m_renameTimer->Stop(); |
efbb7287 VZ |
3058 | m_lastOnSame = FALSE; |
3059 | ||
ddba340d VS |
3060 | #ifdef __WXGTK__ |
3061 | // FIXME: wxGTK generates bad sequence of events prior to doubleclick | |
a77ec46d | 3062 | // ("down, up, down, double, up" while other ports |
ddba340d VS |
3063 | // do "down, up, double, up"). We have to have this hack |
3064 | // in place till somebody fixes wxGTK... | |
cf1dfa6b | 3065 | if ( current == m_lineBeforeLastClicked ) |
ddba340d VS |
3066 | #else |
3067 | if ( current == m_lineLastClicked ) | |
3068 | #endif | |
efbb7287 | 3069 | { |
cf1dfa6b | 3070 | SendNotify( current, wxEVT_COMMAND_LIST_ITEM_ACTIVATED ); |
004fd0c8 | 3071 | |
efbb7287 VZ |
3072 | return; |
3073 | } | |
3074 | else | |
3075 | { | |
3076 | // the first click was on another item, so don't interpret this as | |
3077 | // a double click, but as a simple click instead | |
3078 | forceClick = TRUE; | |
3079 | } | |
92976ab6 | 3080 | } |
bd8289c1 | 3081 | |
92976ab6 | 3082 | if (event.LeftUp() && m_lastOnSame) |
c801d85f | 3083 | { |
cf1dfa6b | 3084 | if ((current == m_current) && |
92976ab6 | 3085 | (hitResult == wxLIST_HITTEST_ONITEMLABEL) && |
cf1dfa6b | 3086 | HasFlag(wxLC_EDIT_LABELS) ) |
92976ab6 RR |
3087 | { |
3088 | m_renameTimer->Start( 100, TRUE ); | |
3089 | } | |
3090 | m_lastOnSame = FALSE; | |
e1e955e1 | 3091 | } |
cf1dfa6b | 3092 | else if (event.RightDown()) |
b204641e | 3093 | { |
cf1dfa6b | 3094 | SendNotify( current, wxEVT_COMMAND_LIST_ITEM_RIGHT_CLICK, |
05a7f61d | 3095 | event.GetPosition() ); |
b204641e | 3096 | } |
cf1dfa6b | 3097 | else if (event.MiddleDown()) |
b204641e | 3098 | { |
cf1dfa6b | 3099 | SendNotify( current, wxEVT_COMMAND_LIST_ITEM_MIDDLE_CLICK ); |
92976ab6 | 3100 | } |
cf1dfa6b | 3101 | else if ( event.LeftDown() || forceClick ) |
92976ab6 | 3102 | { |
efbb7287 | 3103 | m_lineBeforeLastClicked = m_lineLastClicked; |
cf1dfa6b VZ |
3104 | m_lineLastClicked = current; |
3105 | ||
3106 | size_t oldCurrent = m_current; | |
efbb7287 | 3107 | |
b54e41c5 | 3108 | if ( IsSingleSel() || !(event.ControlDown() || event.ShiftDown()) ) |
b204641e | 3109 | { |
b54e41c5 | 3110 | HighlightAll( FALSE ); |
0ddefeb0 VZ |
3111 | |
3112 | ChangeCurrent(current); | |
cf1dfa6b | 3113 | |
b54e41c5 | 3114 | ReverseHighlight(m_current); |
e1e955e1 | 3115 | } |
b54e41c5 | 3116 | else // multi sel & either ctrl or shift is down |
b204641e | 3117 | { |
473d087e | 3118 | if (event.ControlDown()) |
92976ab6 | 3119 | { |
0ddefeb0 | 3120 | ChangeCurrent(current); |
cf1dfa6b | 3121 | |
b54e41c5 | 3122 | ReverseHighlight(m_current); |
92976ab6 | 3123 | } |
473d087e | 3124 | else if (event.ShiftDown()) |
92976ab6 | 3125 | { |
0ddefeb0 | 3126 | ChangeCurrent(current); |
bffa1c77 | 3127 | |
cf1dfa6b VZ |
3128 | size_t lineFrom = oldCurrent, |
3129 | lineTo = current; | |
f6bcfd97 | 3130 | |
cf1dfa6b | 3131 | if ( lineTo < lineFrom ) |
92976ab6 | 3132 | { |
cf1dfa6b VZ |
3133 | lineTo = lineFrom; |
3134 | lineFrom = m_current; | |
92976ab6 RR |
3135 | } |
3136 | ||
b54e41c5 | 3137 | HighlightLines(lineFrom, lineTo); |
92976ab6 | 3138 | } |
cf1dfa6b | 3139 | else // !ctrl, !shift |
92976ab6 | 3140 | { |
cf1dfa6b VZ |
3141 | // test in the enclosing if should make it impossible |
3142 | wxFAIL_MSG( _T("how did we get here?") ); | |
92976ab6 | 3143 | } |
e1e955e1 | 3144 | } |
cf1dfa6b | 3145 | |
92976ab6 RR |
3146 | if (m_current != oldCurrent) |
3147 | { | |
3148 | RefreshLine( oldCurrent ); | |
92976ab6 | 3149 | } |
efbb7287 VZ |
3150 | |
3151 | // forceClick is only set if the previous click was on another item | |
3152 | m_lastOnSame = !forceClick && (m_current == oldCurrent); | |
e1e955e1 | 3153 | } |
e1e955e1 | 3154 | } |
c801d85f | 3155 | |
34bbbc27 | 3156 | void wxListMainWindow::MoveToItem(size_t item) |
c801d85f | 3157 | { |
34bbbc27 | 3158 | if ( item == (size_t)-1 ) |
cf1dfa6b | 3159 | return; |
004fd0c8 | 3160 | |
34bbbc27 | 3161 | wxRect rect = GetLineRect(item); |
cf3da716 | 3162 | |
cf1dfa6b | 3163 | int client_w, client_h; |
cf3da716 | 3164 | GetClientSize( &client_w, &client_h ); |
f6bcfd97 | 3165 | |
cf3da716 RR |
3166 | int view_x = m_xScroll*GetScrollPos( wxHORIZONTAL ); |
3167 | int view_y = m_yScroll*GetScrollPos( wxVERTICAL ); | |
004fd0c8 | 3168 | |
cf1dfa6b | 3169 | if ( HasFlag(wxLC_REPORT) ) |
92976ab6 | 3170 | { |
b54e41c5 VZ |
3171 | // the next we need the range of lines shown it might be different, so |
3172 | // recalculate it | |
3173 | ResetVisibleLinesRange(); | |
3174 | ||
cf1dfa6b VZ |
3175 | if (rect.y < view_y ) |
3176 | Scroll( -1, rect.y/m_yScroll ); | |
3177 | if (rect.y+rect.height+5 > view_y+client_h) | |
3178 | Scroll( -1, (rect.y+rect.height-client_h+SCROLL_UNIT_Y)/m_yScroll ); | |
92976ab6 | 3179 | } |
b54e41c5 | 3180 | else // !report |
92976ab6 | 3181 | { |
cf1dfa6b VZ |
3182 | if (rect.x-view_x < 5) |
3183 | Scroll( (rect.x-5)/m_xScroll, -1 ); | |
3184 | if (rect.x+rect.width-5 > view_x+client_w) | |
3185 | Scroll( (rect.x+rect.width-client_w+SCROLL_UNIT_X)/m_xScroll, -1 ); | |
92976ab6 | 3186 | } |
e1e955e1 | 3187 | } |
c801d85f | 3188 | |
cf1dfa6b VZ |
3189 | // ---------------------------------------------------------------------------- |
3190 | // keyboard handling | |
3191 | // ---------------------------------------------------------------------------- | |
3192 | ||
3193 | void wxListMainWindow::OnArrowChar(size_t newCurrent, const wxKeyEvent& event) | |
c801d85f | 3194 | { |
cf1dfa6b VZ |
3195 | wxCHECK_RET( newCurrent < (size_t)GetItemCount(), |
3196 | _T("invalid item index in OnArrowChar()") ); | |
3197 | ||
3198 | size_t oldCurrent = m_current; | |
3199 | ||
3200 | // in single selection we just ignore Shift as we can't select several | |
3201 | // items anyhow | |
b54e41c5 | 3202 | if ( event.ShiftDown() && !IsSingleSel() ) |
cf1dfa6b | 3203 | { |
0ddefeb0 | 3204 | ChangeCurrent(newCurrent); |
cf1dfa6b VZ |
3205 | |
3206 | // select all the items between the old and the new one | |
3207 | if ( oldCurrent > newCurrent ) | |
3208 | { | |
3209 | newCurrent = oldCurrent; | |
3210 | oldCurrent = m_current; | |
3211 | } | |
3212 | ||
b54e41c5 | 3213 | HighlightLines(oldCurrent, newCurrent); |
cf1dfa6b VZ |
3214 | } |
3215 | else // !shift | |
3216 | { | |
b54e41c5 VZ |
3217 | // all previously selected items are unselected unless ctrl is held |
3218 | if ( !event.ControlDown() ) | |
3219 | HighlightAll(FALSE); | |
3220 | ||
0ddefeb0 | 3221 | ChangeCurrent(newCurrent); |
cf1dfa6b | 3222 | |
58c1c096 | 3223 | // refresh the old focus to remove it |
cf1dfa6b VZ |
3224 | RefreshLine( oldCurrent ); |
3225 | ||
3226 | if ( !event.ControlDown() ) | |
3227 | { | |
b54e41c5 | 3228 | HighlightLine( m_current, TRUE ); |
cf1dfa6b VZ |
3229 | } |
3230 | } | |
3231 | ||
92976ab6 | 3232 | RefreshLine( m_current ); |
cf1dfa6b | 3233 | |
cf3da716 | 3234 | MoveToFocus(); |
e1e955e1 | 3235 | } |
c801d85f | 3236 | |
3dfb93fd RR |
3237 | void wxListMainWindow::OnKeyDown( wxKeyEvent &event ) |
3238 | { | |
3239 | wxWindow *parent = GetParent(); | |
004fd0c8 | 3240 | |
3dfb93fd RR |
3241 | /* we propagate the key event up */ |
3242 | wxKeyEvent ke( wxEVT_KEY_DOWN ); | |
3243 | ke.m_shiftDown = event.m_shiftDown; | |
3244 | ke.m_controlDown = event.m_controlDown; | |
3245 | ke.m_altDown = event.m_altDown; | |
3246 | ke.m_metaDown = event.m_metaDown; | |
3247 | ke.m_keyCode = event.m_keyCode; | |
3248 | ke.m_x = event.m_x; | |
3249 | ke.m_y = event.m_y; | |
3250 | ke.SetEventObject( parent ); | |
3251 | if (parent->GetEventHandler()->ProcessEvent( ke )) return; | |
004fd0c8 | 3252 | |
3dfb93fd RR |
3253 | event.Skip(); |
3254 | } | |
004fd0c8 | 3255 | |
c801d85f KB |
3256 | void wxListMainWindow::OnChar( wxKeyEvent &event ) |
3257 | { | |
51cc4dad | 3258 | wxWindow *parent = GetParent(); |
004fd0c8 | 3259 | |
51cc4dad | 3260 | /* we send a list_key event up */ |
cf1dfa6b | 3261 | if ( HasCurrent() ) |
f6bcfd97 BP |
3262 | { |
3263 | wxListEvent le( wxEVT_COMMAND_LIST_KEY_DOWN, GetParent()->GetId() ); | |
cf1dfa6b VZ |
3264 | le.m_itemIndex = m_current; |
3265 | GetLine(m_current)->GetItem( 0, le.m_item ); | |
f6bcfd97 BP |
3266 | le.m_code = (int)event.KeyCode(); |
3267 | le.SetEventObject( parent ); | |
3268 | parent->GetEventHandler()->ProcessEvent( le ); | |
3269 | } | |
51cc4dad | 3270 | |
3dfb93fd RR |
3271 | /* we propagate the char event up */ |
3272 | wxKeyEvent ke( wxEVT_CHAR ); | |
51cc4dad RR |
3273 | ke.m_shiftDown = event.m_shiftDown; |
3274 | ke.m_controlDown = event.m_controlDown; | |
3275 | ke.m_altDown = event.m_altDown; | |
3276 | ke.m_metaDown = event.m_metaDown; | |
3277 | ke.m_keyCode = event.m_keyCode; | |
3278 | ke.m_x = event.m_x; | |
3279 | ke.m_y = event.m_y; | |
3280 | ke.SetEventObject( parent ); | |
3281 | if (parent->GetEventHandler()->ProcessEvent( ke )) return; | |
004fd0c8 | 3282 | |
012a03e0 RR |
3283 | if (event.KeyCode() == WXK_TAB) |
3284 | { | |
3285 | wxNavigationKeyEvent nevent; | |
c5145d41 | 3286 | nevent.SetWindowChange( event.ControlDown() ); |
012a03e0 | 3287 | nevent.SetDirection( !event.ShiftDown() ); |
8253c7fd | 3288 | nevent.SetEventObject( GetParent()->GetParent() ); |
012a03e0 | 3289 | nevent.SetCurrentFocus( m_parent ); |
87948f22 VZ |
3290 | if (GetParent()->GetParent()->GetEventHandler()->ProcessEvent( nevent )) |
3291 | return; | |
012a03e0 | 3292 | } |
004fd0c8 | 3293 | |
51cc4dad | 3294 | /* no item -> nothing to do */ |
cf1dfa6b | 3295 | if (!HasCurrent()) |
c801d85f | 3296 | { |
51cc4dad RR |
3297 | event.Skip(); |
3298 | return; | |
e1e955e1 | 3299 | } |
51cc4dad RR |
3300 | |
3301 | switch (event.KeyCode()) | |
c801d85f | 3302 | { |
51cc4dad | 3303 | case WXK_UP: |
cf1dfa6b VZ |
3304 | if ( m_current > 0 ) |
3305 | OnArrowChar( m_current - 1, event ); | |
51cc4dad | 3306 | break; |
cf1dfa6b | 3307 | |
51cc4dad | 3308 | case WXK_DOWN: |
cf1dfa6b VZ |
3309 | if ( m_current < (size_t)GetItemCount() - 1 ) |
3310 | OnArrowChar( m_current + 1, event ); | |
51cc4dad | 3311 | break; |
cf1dfa6b | 3312 | |
51cc4dad | 3313 | case WXK_END: |
1370703e | 3314 | if (!IsEmpty()) |
cf1dfa6b | 3315 | OnArrowChar( GetItemCount() - 1, event ); |
51cc4dad | 3316 | break; |
cf1dfa6b | 3317 | |
51cc4dad | 3318 | case WXK_HOME: |
1370703e | 3319 | if (!IsEmpty()) |
cf1dfa6b | 3320 | OnArrowChar( 0, event ); |
51cc4dad | 3321 | break; |
cf1dfa6b | 3322 | |
51cc4dad | 3323 | case WXK_PRIOR: |
f6bcfd97 | 3324 | { |
cf1dfa6b VZ |
3325 | int steps = 0; |
3326 | if ( HasFlag(wxLC_REPORT) ) | |
3327 | { | |
3328 | steps = m_linesPerPage - 1; | |
3329 | } | |
3330 | else | |
3331 | { | |
3332 | steps = m_current % m_linesPerPage; | |
3333 | } | |
3334 | ||
3335 | int index = m_current - steps; | |
3336 | if (index < 0) | |
3337 | index = 0; | |
3338 | ||
3339 | OnArrowChar( index, event ); | |
51cc4dad | 3340 | } |
51cc4dad | 3341 | break; |
cf1dfa6b | 3342 | |
51cc4dad | 3343 | case WXK_NEXT: |
bffa1c77 | 3344 | { |
cf1dfa6b VZ |
3345 | int steps = 0; |
3346 | if ( HasFlag(wxLC_REPORT) ) | |
3347 | { | |
3348 | steps = m_linesPerPage - 1; | |
3349 | } | |
3350 | else | |
3351 | { | |
3352 | steps = m_linesPerPage - (m_current % m_linesPerPage) - 1; | |
3353 | } | |
f6bcfd97 | 3354 | |
cf1dfa6b VZ |
3355 | size_t index = m_current + steps; |
3356 | size_t count = GetItemCount(); | |
3357 | if ( index >= count ) | |
3358 | index = count - 1; | |
3359 | ||
3360 | OnArrowChar( index, event ); | |
51cc4dad | 3361 | } |
51cc4dad | 3362 | break; |
cf1dfa6b | 3363 | |
51cc4dad | 3364 | case WXK_LEFT: |
cf1dfa6b | 3365 | if ( !HasFlag(wxLC_REPORT) ) |
51cc4dad | 3366 | { |
cf1dfa6b VZ |
3367 | int index = m_current - m_linesPerPage; |
3368 | if (index < 0) | |
3369 | index = 0; | |
3370 | ||
3371 | OnArrowChar( index, event ); | |
51cc4dad RR |
3372 | } |
3373 | break; | |
cf1dfa6b | 3374 | |
51cc4dad | 3375 | case WXK_RIGHT: |
cf1dfa6b | 3376 | if ( !HasFlag(wxLC_REPORT) ) |
51cc4dad | 3377 | { |
cf1dfa6b VZ |
3378 | size_t index = m_current + m_linesPerPage; |
3379 | ||
3380 | size_t count = GetItemCount(); | |
3381 | if ( index >= count ) | |
3382 | index = count - 1; | |
3383 | ||
3384 | OnArrowChar( index, event ); | |
51cc4dad RR |
3385 | } |
3386 | break; | |
cf1dfa6b | 3387 | |
51cc4dad | 3388 | case WXK_SPACE: |
b54e41c5 | 3389 | if ( IsSingleSel() ) |
33d0e17c | 3390 | { |
87948f22 | 3391 | SendNotify( m_current, wxEVT_COMMAND_LIST_ITEM_ACTIVATED ); |
70541533 VZ |
3392 | |
3393 | if ( IsHighlighted(m_current) ) | |
3394 | { | |
3395 | // don't unselect the item in single selection mode | |
3396 | break; | |
3397 | } | |
3398 | //else: select it in ReverseHighlight() below if unselected | |
33d0e17c | 3399 | } |
70541533 VZ |
3400 | |
3401 | ReverseHighlight(m_current); | |
51cc4dad | 3402 | break; |
cf1dfa6b | 3403 | |
51cc4dad RR |
3404 | case WXK_RETURN: |
3405 | case WXK_EXECUTE: | |
87948f22 | 3406 | SendNotify( m_current, wxEVT_COMMAND_LIST_ITEM_ACTIVATED ); |
51cc4dad | 3407 | break; |
cf1dfa6b | 3408 | |
51cc4dad | 3409 | default: |
51cc4dad | 3410 | event.Skip(); |
e1e955e1 | 3411 | } |
e1e955e1 | 3412 | } |
c801d85f | 3413 | |
cf1dfa6b VZ |
3414 | // ---------------------------------------------------------------------------- |
3415 | // focus handling | |
3416 | // ---------------------------------------------------------------------------- | |
3417 | ||
a6d57d03 VS |
3418 | void wxListMainWindow::SetFocus() |
3419 | { | |
3420 | // VS: wxListMainWindow derives from wxPanel (via wxScrolledWindow) and wxPanel | |
a77ec46d | 3421 | // overrides SetFocus in such way that it does never change focus from |
a6d57d03 | 3422 | // panel's child to the panel itself. Unfortunately, we must be able to change |
a77ec46d | 3423 | // focus to the panel from wxListTextCtrl because the text control should |
a6d57d03 VS |
3424 | // disappear when the user clicks outside it. |
3425 | ||
3426 | wxWindow *oldFocus = FindFocus(); | |
a77ec46d | 3427 | |
072da98f | 3428 | if ( oldFocus && oldFocus->GetParent() == this ) |
a6d57d03 VS |
3429 | { |
3430 | wxWindow::SetFocus(); | |
3431 | } | |
3432 | else | |
3433 | { | |
3434 | wxScrolledWindow::SetFocus(); | |
3435 | } | |
3436 | } | |
3437 | ||
c801d85f KB |
3438 | void wxListMainWindow::OnSetFocus( wxFocusEvent &WXUNUSED(event) ) |
3439 | { | |
bde9072f VZ |
3440 | // wxGTK sends us EVT_SET_FOCUS events even if we had never got |
3441 | // EVT_KILL_FOCUS before which means that we finish by redrawing the items | |
3442 | // which are already drawn correctly resulting in horrible flicker - avoid | |
3443 | // it | |
47724389 VZ |
3444 | if ( !m_hasFocus ) |
3445 | { | |
3446 | m_hasFocus = TRUE; | |
bde9072f | 3447 | |
47724389 VZ |
3448 | RefreshSelected(); |
3449 | } | |
bd8289c1 | 3450 | |
47724389 | 3451 | if ( !GetParent() ) |
cf1dfa6b | 3452 | return; |
004fd0c8 | 3453 | |
63852e78 RR |
3454 | wxFocusEvent event( wxEVT_SET_FOCUS, GetParent()->GetId() ); |
3455 | event.SetEventObject( GetParent() ); | |
3456 | GetParent()->GetEventHandler()->ProcessEvent( event ); | |
e1e955e1 | 3457 | } |
c801d85f KB |
3458 | |
3459 | void wxListMainWindow::OnKillFocus( wxFocusEvent &WXUNUSED(event) ) | |
3460 | { | |
63852e78 | 3461 | m_hasFocus = FALSE; |
004fd0c8 | 3462 | |
49ecb029 | 3463 | RefreshSelected(); |
e1e955e1 | 3464 | } |
c801d85f | 3465 | |
1e6d9499 | 3466 | void wxListMainWindow::DrawImage( int index, wxDC *dc, int x, int y ) |
c801d85f | 3467 | { |
cf1dfa6b | 3468 | if ( HasFlag(wxLC_ICON) && (m_normal_image_list)) |
63852e78 RR |
3469 | { |
3470 | m_normal_image_list->Draw( index, *dc, x, y, wxIMAGELIST_DRAW_TRANSPARENT ); | |
63852e78 | 3471 | } |
cf1dfa6b | 3472 | else if ( HasFlag(wxLC_SMALL_ICON) && (m_small_image_list)) |
63852e78 RR |
3473 | { |
3474 | m_small_image_list->Draw( index, *dc, x, y, wxIMAGELIST_DRAW_TRANSPARENT ); | |
3475 | } | |
cf1dfa6b | 3476 | else if ( HasFlag(wxLC_LIST) && (m_small_image_list)) |
0b855868 RR |
3477 | { |
3478 | m_small_image_list->Draw( index, *dc, x, y, wxIMAGELIST_DRAW_TRANSPARENT ); | |
3479 | } | |
cf1dfa6b | 3480 | else if ( HasFlag(wxLC_REPORT) && (m_small_image_list)) |
63852e78 RR |
3481 | { |
3482 | m_small_image_list->Draw( index, *dc, x, y, wxIMAGELIST_DRAW_TRANSPARENT ); | |
63852e78 | 3483 | } |
e1e955e1 | 3484 | } |
c801d85f | 3485 | |
5cd89174 | 3486 | void wxListMainWindow::GetImageSize( int index, int &width, int &height ) const |
c801d85f | 3487 | { |
cf1dfa6b | 3488 | if ( HasFlag(wxLC_ICON) && m_normal_image_list ) |
63852e78 RR |
3489 | { |
3490 | m_normal_image_list->GetSize( index, width, height ); | |
63852e78 | 3491 | } |
cf1dfa6b | 3492 | else if ( HasFlag(wxLC_SMALL_ICON) && m_small_image_list ) |
63852e78 RR |
3493 | { |
3494 | m_small_image_list->GetSize( index, width, height ); | |
63852e78 | 3495 | } |
cf1dfa6b | 3496 | else if ( HasFlag(wxLC_LIST) && m_small_image_list ) |
0b855868 RR |
3497 | { |
3498 | m_small_image_list->GetSize( index, width, height ); | |
0b855868 | 3499 | } |
cf1dfa6b | 3500 | else if ( HasFlag(wxLC_REPORT) && m_small_image_list ) |
63852e78 RR |
3501 | { |
3502 | m_small_image_list->GetSize( index, width, height ); | |
63852e78 | 3503 | } |
cf1dfa6b VZ |
3504 | else |
3505 | { | |
3506 | width = | |
3507 | height = 0; | |
3508 | } | |
e1e955e1 | 3509 | } |
c801d85f | 3510 | |
5cd89174 | 3511 | int wxListMainWindow::GetTextLength( const wxString &s ) const |
c801d85f | 3512 | { |
5cd89174 | 3513 | wxClientDC dc( wxConstCast(this, wxListMainWindow) ); |
cf1dfa6b | 3514 | dc.SetFont( GetFont() ); |
c801d85f | 3515 | |
cf1dfa6b VZ |
3516 | wxCoord lw; |
3517 | dc.GetTextExtent( s, &lw, NULL ); | |
3518 | ||
3519 | return lw + AUTOSIZE_COL_MARGIN; | |
e1e955e1 | 3520 | } |
c801d85f | 3521 | |
debe6624 | 3522 | void wxListMainWindow::SetImageList( wxImageList *imageList, int which ) |
c801d85f | 3523 | { |
139adb6a | 3524 | m_dirty = TRUE; |
f6bcfd97 BP |
3525 | |
3526 | // calc the spacing from the icon size | |
3527 | int width = 0, | |
3528 | height = 0; | |
3529 | if ((imageList) && (imageList->GetImageCount()) ) | |
3530 | { | |
3531 | imageList->GetSize(0, width, height); | |
3532 | } | |
3533 | ||
3534 | if (which == wxIMAGE_LIST_NORMAL) | |
3535 | { | |
3536 | m_normal_image_list = imageList; | |
3537 | m_normal_spacing = width + 8; | |
3538 | } | |
3539 | ||
3540 | if (which == wxIMAGE_LIST_SMALL) | |
3541 | { | |
3542 | m_small_image_list = imageList; | |
3543 | m_small_spacing = width + 14; | |
3544 | } | |
e1e955e1 | 3545 | } |
c801d85f | 3546 | |
debe6624 | 3547 | void wxListMainWindow::SetItemSpacing( int spacing, bool isSmall ) |
c801d85f | 3548 | { |
139adb6a RR |
3549 | m_dirty = TRUE; |
3550 | if (isSmall) | |
3551 | { | |
3552 | m_small_spacing = spacing; | |
3553 | } | |
3554 | else | |
3555 | { | |
3556 | m_normal_spacing = spacing; | |
3557 | } | |
e1e955e1 | 3558 | } |
c801d85f | 3559 | |
debe6624 | 3560 | int wxListMainWindow::GetItemSpacing( bool isSmall ) |
c801d85f | 3561 | { |
f6bcfd97 | 3562 | return isSmall ? m_small_spacing : m_normal_spacing; |
e1e955e1 | 3563 | } |
c801d85f | 3564 | |
cf1dfa6b VZ |
3565 | // ---------------------------------------------------------------------------- |
3566 | // columns | |
3567 | // ---------------------------------------------------------------------------- | |
3568 | ||
debe6624 | 3569 | void wxListMainWindow::SetColumn( int col, wxListItem &item ) |
c801d85f | 3570 | { |
24b9f055 | 3571 | wxListHeaderDataList::Node *node = m_columns.Item( col ); |
f6bcfd97 | 3572 | |
cf1dfa6b VZ |
3573 | wxCHECK_RET( node, _T("invalid column index in SetColumn") ); |
3574 | ||
3575 | if ( item.m_width == wxLIST_AUTOSIZE_USEHEADER ) | |
3576 | item.m_width = GetTextLength( item.m_text ); | |
3577 | ||
3578 | wxListHeaderData *column = node->GetData(); | |
3579 | column->SetItem( item ); | |
3580 | ||
3581 | wxListHeaderWindow *headerWin = GetListCtrl()->m_headerWin; | |
f6bcfd97 BP |
3582 | if ( headerWin ) |
3583 | headerWin->m_dirty = TRUE; | |
cf1dfa6b VZ |
3584 | |
3585 | m_dirty = TRUE; | |
3586 | ||
3587 | // invalidate it as it has to be recalculated | |
3588 | m_headerWidth = 0; | |
e1e955e1 | 3589 | } |
c801d85f | 3590 | |
debe6624 | 3591 | void wxListMainWindow::SetColumnWidth( int col, int width ) |
c801d85f | 3592 | { |
cf1dfa6b VZ |
3593 | wxCHECK_RET( col >= 0 && col < GetColumnCount(), |
3594 | _T("invalid column index") ); | |
3595 | ||
3596 | wxCHECK_RET( HasFlag(wxLC_REPORT), | |
f6bcfd97 | 3597 | _T("SetColumnWidth() can only be called in report mode.") ); |
0208334d | 3598 | |
63852e78 | 3599 | m_dirty = TRUE; |
abe4a4f1 VS |
3600 | wxListHeaderWindow *headerWin = GetListCtrl()->m_headerWin; |
3601 | if ( headerWin ) | |
3602 | headerWin->m_dirty = TRUE; | |
bd8289c1 | 3603 | |
cf1dfa6b VZ |
3604 | wxListHeaderDataList::Node *node = m_columns.Item( col ); |
3605 | wxCHECK_RET( node, _T("no column?") ); | |
3606 | ||
3607 | wxListHeaderData *column = node->GetData(); | |
3608 | ||
3609 | size_t count = GetItemCount(); | |
3610 | ||
f6bcfd97 BP |
3611 | if (width == wxLIST_AUTOSIZE_USEHEADER) |
3612 | { | |
cf1dfa6b | 3613 | width = GetTextLength(column->GetText()); |
f6bcfd97 | 3614 | } |
cf1dfa6b | 3615 | else if ( width == wxLIST_AUTOSIZE ) |
0180dad6 | 3616 | { |
cf1dfa6b VZ |
3617 | if ( IsVirtual() ) |
3618 | { | |
3619 | // TODO: determine the max width somehow... | |
3620 | width = WIDTH_COL_DEFAULT; | |
3621 | } | |
3622 | else // !virtual | |
0180dad6 | 3623 | { |
cf1dfa6b VZ |
3624 | wxClientDC dc(this); |
3625 | dc.SetFont( GetFont() ); | |
3626 | ||
3627 | int max = AUTOSIZE_COL_MARGIN; | |
3628 | ||
3629 | for ( size_t i = 0; i < count; i++ ) | |
0180dad6 | 3630 | { |
cf1dfa6b VZ |
3631 | wxListLineData *line = GetLine(i); |
3632 | wxListItemDataList::Node *n = line->m_items.Item( col ); | |
3633 | ||
3634 | wxCHECK_RET( n, _T("no subitem?") ); | |
3635 | ||
2c1f73ee | 3636 | wxListItemData *item = n->GetData(); |
cf1dfa6b VZ |
3637 | int current = 0; |
3638 | ||
bffa1c77 VZ |
3639 | if (item->HasImage()) |
3640 | { | |
cf1dfa6b | 3641 | int ix, iy; |
0180dad6 | 3642 | GetImageSize( item->GetImage(), ix, iy ); |
cf1dfa6b | 3643 | current += ix + 5; |
bffa1c77 | 3644 | } |
cf1dfa6b | 3645 | |
bffa1c77 VZ |
3646 | if (item->HasText()) |
3647 | { | |
cf1dfa6b VZ |
3648 | wxCoord w; |
3649 | dc.GetTextExtent( item->GetText(), &w, NULL ); | |
3650 | current += w; | |
bffa1c77 | 3651 | } |
cf1dfa6b | 3652 | |
2c1f73ee VZ |
3653 | if (current > max) |
3654 | max = current; | |
0180dad6 | 3655 | } |
cf1dfa6b VZ |
3656 | |
3657 | width = max + AUTOSIZE_COL_MARGIN; | |
0180dad6 | 3658 | } |
0180dad6 RR |
3659 | } |
3660 | ||
cf1dfa6b | 3661 | column->SetWidth( width ); |
bd8289c1 | 3662 | |
cf1dfa6b VZ |
3663 | // invalidate it as it has to be recalculated |
3664 | m_headerWidth = 0; | |
3665 | } | |
3666 | ||
3667 | int wxListMainWindow::GetHeaderWidth() const | |
3668 | { | |
3669 | if ( !m_headerWidth ) | |
0208334d | 3670 | { |
cf1dfa6b VZ |
3671 | wxListMainWindow *self = wxConstCast(this, wxListMainWindow); |
3672 | ||
3673 | size_t count = GetColumnCount(); | |
3674 | for ( size_t col = 0; col < count; col++ ) | |
63852e78 | 3675 | { |
cf1dfa6b | 3676 | self->m_headerWidth += GetColumnWidth(col); |
63852e78 | 3677 | } |
0208334d | 3678 | } |
bd8289c1 | 3679 | |
cf1dfa6b | 3680 | return m_headerWidth; |
e1e955e1 | 3681 | } |
c801d85f | 3682 | |
cf1dfa6b | 3683 | void wxListMainWindow::GetColumn( int col, wxListItem &item ) const |
c801d85f | 3684 | { |
24b9f055 | 3685 | wxListHeaderDataList::Node *node = m_columns.Item( col ); |
cf1dfa6b VZ |
3686 | wxCHECK_RET( node, _T("invalid column index in GetColumn") ); |
3687 | ||
3688 | wxListHeaderData *column = node->GetData(); | |
3689 | column->GetItem( item ); | |
e1e955e1 | 3690 | } |
c801d85f | 3691 | |
cf1dfa6b | 3692 | int wxListMainWindow::GetColumnWidth( int col ) const |
c801d85f | 3693 | { |
24b9f055 VZ |
3694 | wxListHeaderDataList::Node *node = m_columns.Item( col ); |
3695 | wxCHECK_MSG( node, 0, _T("invalid column index") ); | |
3696 | ||
3697 | wxListHeaderData *column = node->GetData(); | |
3698 | return column->GetWidth(); | |
e1e955e1 | 3699 | } |
c801d85f | 3700 | |
cf1dfa6b VZ |
3701 | // ---------------------------------------------------------------------------- |
3702 | // item state | |
3703 | // ---------------------------------------------------------------------------- | |
c801d85f KB |
3704 | |
3705 | void wxListMainWindow::SetItem( wxListItem &item ) | |
3706 | { | |
cf1dfa6b VZ |
3707 | long id = item.m_itemId; |
3708 | wxCHECK_RET( id >= 0 && (size_t)id < GetItemCount(), | |
3709 | _T("invalid item index in SetItem") ); | |
3710 | ||
6c02c329 VZ |
3711 | if ( !IsVirtual() ) |
3712 | { | |
3713 | wxListLineData *line = GetLine((size_t)id); | |
3714 | line->SetItem( item.m_col, item ); | |
3715 | } | |
3716 | ||
3717 | if ( InReportView() ) | |
cf1dfa6b VZ |
3718 | { |
3719 | // just refresh the line to show the new value of the text/image | |
3720 | RefreshLine((size_t)id); | |
3721 | } | |
6c02c329 | 3722 | else // !report |
92976ab6 | 3723 | { |
6c02c329 | 3724 | // refresh everything (resulting in horrible flicker - FIXME!) |
cf1dfa6b | 3725 | m_dirty = TRUE; |
92976ab6 | 3726 | } |
e1e955e1 | 3727 | } |
c801d85f | 3728 | |
cf1dfa6b | 3729 | void wxListMainWindow::SetItemState( long litem, long state, long stateMask ) |
c801d85f | 3730 | { |
cf1dfa6b | 3731 | wxCHECK_RET( litem >= 0 && (size_t)litem < GetItemCount(), |
54442116 VZ |
3732 | _T("invalid list ctrl item index in SetItem") ); |
3733 | ||
cf1dfa6b | 3734 | size_t oldCurrent = m_current; |
88b792af | 3735 | size_t item = (size_t)litem; // safe because of the check above |
bd8289c1 | 3736 | |
88b792af | 3737 | // do we need to change the focus? |
54442116 | 3738 | if ( stateMask & wxLIST_STATE_FOCUSED ) |
c801d85f | 3739 | { |
54442116 | 3740 | if ( state & wxLIST_STATE_FOCUSED ) |
92976ab6 | 3741 | { |
54442116 | 3742 | // don't do anything if this item is already focused |
cf1dfa6b | 3743 | if ( item != m_current ) |
92976ab6 | 3744 | { |
0ddefeb0 | 3745 | ChangeCurrent(item); |
cf1dfa6b | 3746 | |
88b792af | 3747 | if ( oldCurrent != (size_t)-1 ) |
cf1dfa6b | 3748 | { |
88b792af VZ |
3749 | if ( IsSingleSel() ) |
3750 | { | |
3751 | HighlightLine(oldCurrent, FALSE); | |
3752 | } | |
3753 | ||
cf1dfa6b VZ |
3754 | RefreshLine(oldCurrent); |
3755 | } | |
54442116 | 3756 | |
92976ab6 | 3757 | RefreshLine( m_current ); |
92976ab6 | 3758 | } |
54442116 VZ |
3759 | } |
3760 | else // unfocus | |
3761 | { | |
3762 | // don't do anything if this item is not focused | |
cf1dfa6b | 3763 | if ( item == m_current ) |
bffa1c77 | 3764 | { |
0ddefeb0 | 3765 | ResetCurrent(); |
88b792af | 3766 | |
943f6ad3 VZ |
3767 | if ( IsSingleSel() ) |
3768 | { | |
3769 | // we must unselect the old current item as well or we | |
3770 | // might end up with more than one selected item in a | |
3771 | // single selection control | |
3772 | HighlightLine(oldCurrent, FALSE); | |
3773 | } | |
3774 | ||
88b792af | 3775 | RefreshLine( oldCurrent ); |
bffa1c77 | 3776 | } |
92976ab6 | 3777 | } |
e1e955e1 | 3778 | } |
54442116 | 3779 | |
88b792af | 3780 | // do we need to change the selection state? |
54442116 VZ |
3781 | if ( stateMask & wxLIST_STATE_SELECTED ) |
3782 | { | |
3783 | bool on = (state & wxLIST_STATE_SELECTED) != 0; | |
54442116 | 3784 | |
b54e41c5 | 3785 | if ( IsSingleSel() ) |
54442116 | 3786 | { |
cf1dfa6b VZ |
3787 | if ( on ) |
3788 | { | |
3789 | // selecting the item also makes it the focused one in the | |
3790 | // single sel mode | |
3791 | if ( m_current != item ) | |
3792 | { | |
0ddefeb0 | 3793 | ChangeCurrent(item); |
cf1dfa6b VZ |
3794 | |
3795 | if ( oldCurrent != (size_t)-1 ) | |
3796 | { | |
b54e41c5 | 3797 | HighlightLine( oldCurrent, FALSE ); |
cf1dfa6b VZ |
3798 | RefreshLine( oldCurrent ); |
3799 | } | |
3800 | } | |
3801 | } | |
3802 | else // off | |
3803 | { | |
3804 | // only the current item may be selected anyhow | |
3805 | if ( item != m_current ) | |
3806 | return; | |
3807 | } | |
54442116 VZ |
3808 | } |
3809 | ||
b54e41c5 | 3810 | if ( HighlightLine(item, on) ) |
54442116 | 3811 | { |
cf1dfa6b | 3812 | RefreshLine(item); |
54442116 VZ |
3813 | } |
3814 | } | |
e1e955e1 | 3815 | } |
c801d85f | 3816 | |
62d89eb4 | 3817 | int wxListMainWindow::GetItemState( long item, long stateMask ) const |
c801d85f | 3818 | { |
cf1dfa6b VZ |
3819 | wxCHECK_MSG( item >= 0 && (size_t)item < GetItemCount(), 0, |
3820 | _T("invalid list ctrl item index in GetItemState()") ); | |
3821 | ||
92976ab6 | 3822 | int ret = wxLIST_STATE_DONTCARE; |
cf1dfa6b VZ |
3823 | |
3824 | if ( stateMask & wxLIST_STATE_FOCUSED ) | |
c801d85f | 3825 | { |
cf1dfa6b VZ |
3826 | if ( (size_t)item == m_current ) |
3827 | ret |= wxLIST_STATE_FOCUSED; | |
e1e955e1 | 3828 | } |
cf1dfa6b VZ |
3829 | |
3830 | if ( stateMask & wxLIST_STATE_SELECTED ) | |
c801d85f | 3831 | { |
b54e41c5 | 3832 | if ( IsHighlighted(item) ) |
cf1dfa6b | 3833 | ret |= wxLIST_STATE_SELECTED; |
e1e955e1 | 3834 | } |
cf1dfa6b | 3835 | |
92976ab6 | 3836 | return ret; |
e1e955e1 | 3837 | } |
c801d85f | 3838 | |
62d89eb4 | 3839 | void wxListMainWindow::GetItem( wxListItem &item ) const |
c801d85f | 3840 | { |
cf1dfa6b VZ |
3841 | wxCHECK_RET( item.m_itemId >= 0 && (size_t)item.m_itemId < GetItemCount(), |
3842 | _T("invalid item index in GetItem") ); | |
3843 | ||
3844 | wxListLineData *line = GetLine((size_t)item.m_itemId); | |
3845 | line->GetItem( item.m_col, item ); | |
e1e955e1 | 3846 | } |
c801d85f | 3847 | |
cf1dfa6b VZ |
3848 | // ---------------------------------------------------------------------------- |
3849 | // item count | |
3850 | // ---------------------------------------------------------------------------- | |
3851 | ||
3852 | size_t wxListMainWindow::GetItemCount() const | |
1370703e VZ |
3853 | { |
3854 | return IsVirtual() ? m_countVirt : m_lines.GetCount(); | |
3855 | } | |
3856 | ||
3857 | void wxListMainWindow::SetItemCount(long count) | |
c801d85f | 3858 | { |
b54e41c5 | 3859 | m_selStore.SetItemCount(count); |
1370703e VZ |
3860 | m_countVirt = count; |
3861 | ||
850ed6e7 VZ |
3862 | ResetVisibleLinesRange(); |
3863 | ||
5fe143df VZ |
3864 | // scrollbars must be reset |
3865 | m_dirty = TRUE; | |
e1e955e1 | 3866 | } |
c801d85f | 3867 | |
62d89eb4 | 3868 | int wxListMainWindow::GetSelectedItemCount() const |
c801d85f | 3869 | { |
cf1dfa6b | 3870 | // deal with the quick case first |
b54e41c5 | 3871 | if ( IsSingleSel() ) |
92976ab6 | 3872 | { |
b54e41c5 | 3873 | return HasCurrent() ? IsHighlighted(m_current) : FALSE; |
92976ab6 | 3874 | } |
cf1dfa6b VZ |
3875 | |
3876 | // virtual controls remmebers all its selections itself | |
3877 | if ( IsVirtual() ) | |
b54e41c5 | 3878 | return m_selStore.GetSelectedCount(); |
cf1dfa6b VZ |
3879 | |
3880 | // TODO: we probably should maintain the number of items selected even for | |
3881 | // non virtual controls as enumerating all lines is really slow... | |
3882 | size_t countSel = 0; | |
3883 | size_t count = GetItemCount(); | |
3884 | for ( size_t line = 0; line < count; line++ ) | |
92976ab6 | 3885 | { |
b54e41c5 | 3886 | if ( GetLine(line)->IsHighlighted() ) |
cf1dfa6b | 3887 | countSel++; |
92976ab6 | 3888 | } |
c801d85f | 3889 | |
cf1dfa6b | 3890 | return countSel; |
e1e955e1 | 3891 | } |
e3e65dac | 3892 | |
cf1dfa6b VZ |
3893 | // ---------------------------------------------------------------------------- |
3894 | // item position/size | |
3895 | // ---------------------------------------------------------------------------- | |
3896 | ||
62d89eb4 | 3897 | void wxListMainWindow::GetItemRect( long index, wxRect &rect ) const |
c801d85f | 3898 | { |
cf1dfa6b VZ |
3899 | wxCHECK_RET( index >= 0 && (size_t)index < GetItemCount(), |
3900 | _T("invalid index in GetItemRect") ); | |
3901 | ||
5cd89174 | 3902 | rect = GetLineRect((size_t)index); |
b54e41c5 | 3903 | |
cf1dfa6b | 3904 | CalcScrolledPosition(rect.x, rect.y, &rect.x, &rect.y); |
e1e955e1 | 3905 | } |
c801d85f | 3906 | |
62d89eb4 | 3907 | bool wxListMainWindow::GetItemPosition(long item, wxPoint& pos) const |
c801d85f | 3908 | { |
cf1dfa6b VZ |
3909 | wxRect rect; |
3910 | GetItemRect(item, rect); | |
bd8289c1 | 3911 | |
cf1dfa6b VZ |
3912 | pos.x = rect.x; |
3913 | pos.y = rect.y; | |
bd8289c1 | 3914 | |
cf1dfa6b | 3915 | return TRUE; |
e1e955e1 | 3916 | } |
c801d85f | 3917 | |
cf1dfa6b VZ |
3918 | // ---------------------------------------------------------------------------- |
3919 | // geometry calculation | |
3920 | // ---------------------------------------------------------------------------- | |
3921 | ||
34bbbc27 | 3922 | void wxListMainWindow::RecalculatePositions(bool noRefresh) |
c801d85f | 3923 | { |
1e6d9499 | 3924 | wxClientDC dc( this ); |
92976ab6 | 3925 | dc.SetFont( GetFont() ); |
c801d85f | 3926 | |
cf1dfa6b VZ |
3927 | int iconSpacing; |
3928 | if ( HasFlag(wxLC_ICON) ) | |
3929 | iconSpacing = m_normal_spacing; | |
3930 | else if ( HasFlag(wxLC_SMALL_ICON) ) | |
3931 | iconSpacing = m_small_spacing; | |
3932 | else | |
3933 | iconSpacing = 0; | |
004fd0c8 | 3934 | |
bf632edd RR |
3935 | // Note that we do not call GetClientSize() here but |
3936 | // GetSize() and substract the border size for sunken | |
3937 | // borders manually. This is technically incorrect, | |
3938 | // but we need to know the client area's size WITHOUT | |
3939 | // scrollbars here. Since we don't know if there are | |
3940 | // any scrollbars, we use GetSize() instead. Another | |
3941 | // solution would be to call SetScrollbars() here to | |
3942 | // remove the scrollbars and call GetClientSize() then, | |
3943 | // but this might result in flicker and - worse - will | |
3944 | // reset the scrollbars to 0 which is not good at all | |
3945 | // if you resize a dialog/window, but don't want to | |
3946 | // reset the window scrolling. RR. | |
3947 | // Furthermore, we actually do NOT subtract the border | |
3948 | // width as 2 pixels is just the extra space which we | |
3949 | // need around the actual content in the window. Other- | |
3950 | // wise the text would e.g. touch the upper border. RR. | |
cf1dfa6b VZ |
3951 | int clientWidth, |
3952 | clientHeight; | |
bf632edd | 3953 | GetSize( &clientWidth, &clientHeight ); |
a77ec46d | 3954 | |
cf1dfa6b VZ |
3955 | if ( HasFlag(wxLC_REPORT) ) |
3956 | { | |
3957 | // all lines have the same height | |
b54e41c5 | 3958 | int lineHeight = GetLineHeight(); |
c801d85f | 3959 | |
cf1dfa6b | 3960 | // scroll one line per step |
b54e41c5 | 3961 | m_yScroll = lineHeight; |
bd8289c1 | 3962 | |
cf1dfa6b | 3963 | size_t lineCount = GetItemCount(); |
b54e41c5 | 3964 | int entireHeight = lineCount*lineHeight + LINE_SPACING; |
bd8289c1 | 3965 | |
b54e41c5 VZ |
3966 | m_linesPerPage = clientHeight / lineHeight; |
3967 | ||
3968 | ResetVisibleLinesRange(); | |
2c1f73ee | 3969 | |
cf1dfa6b | 3970 | SetScrollbars( m_xScroll, m_yScroll, |
c020c47e | 3971 | GetHeaderWidth() / m_xScroll, |
cf1dfa6b VZ |
3972 | (entireHeight + m_yScroll - 1)/m_yScroll, |
3973 | GetScrollPos(wxHORIZONTAL), | |
3974 | GetScrollPos(wxVERTICAL), | |
3975 | TRUE ); | |
e1e955e1 | 3976 | } |
cf1dfa6b | 3977 | else // !report |
92976ab6 RR |
3978 | { |
3979 | // at first we try without any scrollbar. if the items don't | |
3980 | // fit into the window, we recalculate after subtracting an | |
3981 | // approximated 15 pt for the horizontal scrollbar | |
004fd0c8 | 3982 | |
b54e41c5 | 3983 | int entireWidth = 0; |
bd8289c1 | 3984 | |
92976ab6 | 3985 | for (int tries = 0; tries < 2; tries++) |
e487524e | 3986 | { |
5d684756 RR |
3987 | // We start with 4 for the border around all items |
3988 | entireWidth = 4; | |
a77ec46d | 3989 | |
5d684756 RR |
3990 | if (tries == 1) |
3991 | { | |
3992 | // Now we have decided that the items do not fit into the | |
3993 | // client area. Unfortunately, wxWindows sometimes thinks | |
3994 | // that it does fit and therefore NO horizontal scrollbar | |
3995 | // is inserted. This looks ugly, so we fudge here and make | |
3996 | // the calculated width bigger than was actually has been | |
3997 | // calculated. This ensures that wxScrolledWindows puts | |
3998 | // a scrollbar at the bottom of its client area. | |
3999 | entireWidth += SCROLL_UNIT_X; | |
4000 | } | |
a77ec46d | 4001 | |
bf632edd | 4002 | // Start at 2,2 so the text does not touch the border |
5d25c050 RR |
4003 | int x = 2; |
4004 | int y = 2; | |
92976ab6 | 4005 | int maxWidth = 0; |
cf1dfa6b VZ |
4006 | m_linesPerPage = 0; |
4007 | int currentlyVisibleLines = 0; | |
4008 | ||
4009 | size_t count = GetItemCount(); | |
4010 | for (size_t i = 0; i < count; i++) | |
92976ab6 | 4011 | { |
cf1dfa6b VZ |
4012 | currentlyVisibleLines++; |
4013 | wxListLineData *line = GetLine(i); | |
92976ab6 | 4014 | line->CalculateSize( &dc, iconSpacing ); |
5d684756 | 4015 | line->SetPosition( x, y, clientWidth, iconSpacing ); // Why clientWidth? (FIXME) |
cf1dfa6b | 4016 | |
5cd89174 | 4017 | wxSize sizeLine = GetLineSize(i); |
cf1dfa6b VZ |
4018 | |
4019 | if ( maxWidth < sizeLine.x ) | |
4020 | maxWidth = sizeLine.x; | |
4021 | ||
4022 | y += sizeLine.y; | |
4023 | if (currentlyVisibleLines > m_linesPerPage) | |
4024 | m_linesPerPage = currentlyVisibleLines; | |
4025 | ||
5d684756 | 4026 | // Assume that the size of the next one is the same... (FIXME) |
bf632edd | 4027 | if ( y + sizeLine.y >= clientHeight ) |
92976ab6 | 4028 | { |
cf1dfa6b | 4029 | currentlyVisibleLines = 0; |
e1208c31 | 4030 | y = 2; |
8b53e5a2 RR |
4031 | x += maxWidth+6; |
4032 | entireWidth += maxWidth+6; | |
92976ab6 RR |
4033 | maxWidth = 0; |
4034 | } | |
a77ec46d | 4035 | |
5d684756 | 4036 | // We have reached the last item. |
cf1dfa6b VZ |
4037 | if ( i == count - 1 ) |
4038 | entireWidth += maxWidth; | |
a77ec46d | 4039 | |
5d684756 | 4040 | if ( (tries == 0) && (entireWidth+SCROLL_UNIT_X > clientWidth) ) |
92976ab6 | 4041 | { |
5d684756 | 4042 | clientHeight -= 15; // We guess the scrollbar height. (FIXME) |
cf1dfa6b VZ |
4043 | m_linesPerPage = 0; |
4044 | currentlyVisibleLines = 0; | |
92976ab6 RR |
4045 | break; |
4046 | } | |
a77ec46d | 4047 | |
cf1dfa6b | 4048 | if ( i == count - 1 ) |
5d684756 | 4049 | tries = 1; // Everything fits, no second try required. |
92976ab6 | 4050 | } |
e487524e | 4051 | } |
bffa1c77 | 4052 | |
92976ab6 | 4053 | int scroll_pos = GetScrollPos( wxHORIZONTAL ); |
cf1dfa6b | 4054 | SetScrollbars( m_xScroll, m_yScroll, (entireWidth+SCROLL_UNIT_X) / m_xScroll, 0, scroll_pos, 0, TRUE ); |
e1e955e1 | 4055 | } |
cf1dfa6b | 4056 | |
34bbbc27 VZ |
4057 | if ( !noRefresh ) |
4058 | { | |
4059 | // FIXME: why should we call it from here? | |
4060 | UpdateCurrent(); | |
b54e41c5 | 4061 | |
34bbbc27 VZ |
4062 | RefreshAll(); |
4063 | } | |
b54e41c5 VZ |
4064 | } |
4065 | ||
4066 | void wxListMainWindow::RefreshAll() | |
4067 | { | |
4068 | m_dirty = FALSE; | |
4069 | Refresh(); | |
4070 | ||
4071 | wxListHeaderWindow *headerWin = GetListCtrl()->m_headerWin; | |
70541533 | 4072 | if ( headerWin && headerWin->m_dirty ) |
b54e41c5 VZ |
4073 | { |
4074 | headerWin->m_dirty = FALSE; | |
4075 | headerWin->Refresh(); | |
4076 | } | |
e1e955e1 | 4077 | } |
c801d85f | 4078 | |
cf1dfa6b | 4079 | void wxListMainWindow::UpdateCurrent() |
c801d85f | 4080 | { |
b54e41c5 | 4081 | if ( !HasCurrent() && !IsEmpty() ) |
92976ab6 | 4082 | { |
0ddefeb0 | 4083 | ChangeCurrent(0); |
92976ab6 | 4084 | } |
e1e955e1 | 4085 | } |
c801d85f | 4086 | |
19695fbd VZ |
4087 | long wxListMainWindow::GetNextItem( long item, |
4088 | int WXUNUSED(geometry), | |
62d89eb4 | 4089 | int state ) const |
c801d85f | 4090 | { |
d1022fd6 VZ |
4091 | long ret = item, |
4092 | max = GetItemCount(); | |
4093 | wxCHECK_MSG( (ret == -1) || (ret < max), -1, | |
13771c08 | 4094 | _T("invalid listctrl index in GetNextItem()") ); |
19695fbd VZ |
4095 | |
4096 | // notice that we start with the next item (or the first one if item == -1) | |
4097 | // and this is intentional to allow writing a simple loop to iterate over | |
4098 | // all selected items | |
d1022fd6 VZ |
4099 | ret++; |
4100 | if ( ret == max ) | |
4101 | { | |
4102 | // this is not an error because the index was ok initially, just no | |
4103 | // such item | |
4104 | return -1; | |
4105 | } | |
4106 | ||
cf1dfa6b VZ |
4107 | if ( !state ) |
4108 | { | |
4109 | // any will do | |
4110 | return (size_t)ret; | |
4111 | } | |
4112 | ||
4113 | size_t count = GetItemCount(); | |
4114 | for ( size_t line = (size_t)ret; line < count; line++ ) | |
63852e78 | 4115 | { |
cf1dfa6b VZ |
4116 | if ( (state & wxLIST_STATE_FOCUSED) && (line == m_current) ) |
4117 | return line; | |
4118 | ||
b54e41c5 | 4119 | if ( (state & wxLIST_STATE_SELECTED) && IsHighlighted(line) ) |
cf1dfa6b | 4120 | return line; |
63852e78 | 4121 | } |
19695fbd | 4122 | |
63852e78 | 4123 | return -1; |
e1e955e1 | 4124 | } |
c801d85f | 4125 | |
cf1dfa6b VZ |
4126 | // ---------------------------------------------------------------------------- |
4127 | // deleting stuff | |
4128 | // ---------------------------------------------------------------------------- | |
4129 | ||
b54e41c5 | 4130 | void wxListMainWindow::DeleteItem( long lindex ) |
c801d85f | 4131 | { |
cf1dfa6b VZ |
4132 | size_t count = GetItemCount(); |
4133 | ||
b54e41c5 | 4134 | wxCHECK_RET( (lindex >= 0) && ((size_t)lindex < count), |
cf1dfa6b VZ |
4135 | _T("invalid item index in DeleteItem") ); |
4136 | ||
b54e41c5 VZ |
4137 | size_t index = (size_t)lindex; |
4138 | ||
d6ddcd57 VZ |
4139 | // we don't need to adjust the index for the previous items |
4140 | if ( HasCurrent() && m_current >= index ) | |
cf1dfa6b | 4141 | { |
d6ddcd57 VZ |
4142 | // if the current item is being deleted, we want the next one to |
4143 | // become selected - unless there is no next one - so don't adjust | |
4144 | // m_current in this case | |
4145 | if ( m_current != index || m_current == count - 1 ) | |
4146 | { | |
4147 | m_current--; | |
4148 | } | |
cf1dfa6b VZ |
4149 | } |
4150 | ||
938b652b | 4151 | if ( InReportView() ) |
63852e78 | 4152 | { |
6b4a8d93 | 4153 | ResetVisibleLinesRange(); |
938b652b VZ |
4154 | } |
4155 | ||
938b652b VZ |
4156 | if ( IsVirtual() ) |
4157 | { | |
4158 | m_countVirt--; | |
b54e41c5 VZ |
4159 | |
4160 | m_selStore.OnItemDelete(index); | |
4161 | } | |
4162 | else | |
4163 | { | |
4164 | m_lines.RemoveAt( index ); | |
63852e78 | 4165 | } |
6b4a8d93 | 4166 | |
70541533 | 4167 | // we need to refresh the (vert) scrollbar as the number of items changed |
b84839ae | 4168 | m_dirty = TRUE; |
91c6cc0e VZ |
4169 | |
4170 | SendNotify( index, wxEVT_COMMAND_LIST_DELETE_ITEM ); | |
4171 | ||
6b4a8d93 | 4172 | RefreshAfter(index); |
e1e955e1 | 4173 | } |
c801d85f | 4174 | |
debe6624 | 4175 | void wxListMainWindow::DeleteColumn( int col ) |
c801d85f | 4176 | { |
24b9f055 VZ |
4177 | wxListHeaderDataList::Node *node = m_columns.Item( col ); |
4178 | ||
4179 | wxCHECK_RET( node, wxT("invalid column index in DeleteColumn()") ); | |
bd8289c1 | 4180 | |
5b077d48 | 4181 | m_dirty = TRUE; |
24b9f055 | 4182 | m_columns.DeleteNode( node ); |
ae409cb8 VZ |
4183 | |
4184 | // invalidate it as it has to be recalculated | |
4185 | m_headerWidth = 0; | |
e1e955e1 | 4186 | } |
c801d85f | 4187 | |
5fe143df | 4188 | void wxListMainWindow::DoDeleteAllItems() |
c801d85f | 4189 | { |
cf1dfa6b VZ |
4190 | if ( IsEmpty() ) |
4191 | { | |
4192 | // nothing to do - in particular, don't send the event | |
4193 | return; | |
4194 | } | |
4195 | ||
b54e41c5 | 4196 | ResetCurrent(); |
7c0ea335 VZ |
4197 | |
4198 | // to make the deletion of all items faster, we don't send the | |
cf1dfa6b VZ |
4199 | // notifications for each item deletion in this case but only one event |
4200 | // for all of them: this is compatible with wxMSW and documented in | |
4201 | // DeleteAllItems() description | |
bffa1c77 | 4202 | |
12c1b46a RR |
4203 | wxListEvent event( wxEVT_COMMAND_LIST_DELETE_ALL_ITEMS, GetParent()->GetId() ); |
4204 | event.SetEventObject( GetParent() ); | |
4205 | GetParent()->GetEventHandler()->ProcessEvent( event ); | |
7c0ea335 | 4206 | |
b54e41c5 VZ |
4207 | if ( IsVirtual() ) |
4208 | { | |
4209 | m_countVirt = 0; | |
4210 | ||
850ed6e7 | 4211 | m_selStore.Clear(); |
b54e41c5 VZ |
4212 | } |
4213 | ||
6b4a8d93 VZ |
4214 | if ( InReportView() ) |
4215 | { | |
4216 | ResetVisibleLinesRange(); | |
4217 | } | |
4218 | ||
5b077d48 | 4219 | m_lines.Clear(); |
5fe143df | 4220 | } |
cf1dfa6b | 4221 | |
5fe143df VZ |
4222 | void wxListMainWindow::DeleteAllItems() |
4223 | { | |
4224 | DoDeleteAllItems(); | |
4225 | ||
4226 | RecalculatePositions(); | |
e1e955e1 | 4227 | } |
c801d85f | 4228 | |
12c1b46a | 4229 | void wxListMainWindow::DeleteEverything() |
c801d85f | 4230 | { |
12c1b46a | 4231 | DeleteAllItems(); |
f6bcfd97 | 4232 | |
5b077d48 | 4233 | m_columns.Clear(); |
e1e955e1 | 4234 | } |
c801d85f | 4235 | |
cf1dfa6b VZ |
4236 | // ---------------------------------------------------------------------------- |
4237 | // scanning for an item | |
4238 | // ---------------------------------------------------------------------------- | |
4239 | ||
debe6624 | 4240 | void wxListMainWindow::EnsureVisible( long index ) |
c801d85f | 4241 | { |
cf1dfa6b VZ |
4242 | wxCHECK_RET( index >= 0 && (size_t)index < GetItemCount(), |
4243 | _T("invalid index in EnsureVisible") ); | |
4244 | ||
4245 | // We have to call this here because the label in question might just have | |
34bbbc27 VZ |
4246 | // been added and its position is not known yet |
4247 | if ( m_dirty ) | |
4248 | { | |
34bbbc27 VZ |
4249 | RecalculatePositions(TRUE /* no refresh */); |
4250 | } | |
4251 | ||
4252 | MoveToItem((size_t)index); | |
e1e955e1 | 4253 | } |
c801d85f | 4254 | |
debe6624 | 4255 | long wxListMainWindow::FindItem(long start, const wxString& str, bool WXUNUSED(partial) ) |
c801d85f | 4256 | { |
5b077d48 RR |
4257 | long pos = start; |
4258 | wxString tmp = str; | |
cf1dfa6b VZ |
4259 | if (pos < 0) |
4260 | pos = 0; | |
54442116 | 4261 | |
cf1dfa6b VZ |
4262 | size_t count = GetItemCount(); |
4263 | for ( size_t i = (size_t)pos; i < count; i++ ) | |
4264 | { | |
4265 | wxListLineData *line = GetLine(i); | |
4266 | if ( line->GetText(0) == tmp ) | |
4267 | return i; | |
5b077d48 | 4268 | } |
cf1dfa6b VZ |
4269 | |
4270 | return wxNOT_FOUND; | |
e1e955e1 | 4271 | } |
c801d85f | 4272 | |
debe6624 | 4273 | long wxListMainWindow::FindItem(long start, long data) |
c801d85f | 4274 | { |
5b077d48 | 4275 | long pos = start; |
cf1dfa6b VZ |
4276 | if (pos < 0) |
4277 | pos = 0; | |
4278 | ||
4279 | size_t count = GetItemCount(); | |
4280 | for (size_t i = (size_t)pos; i < count; i++) | |
5b077d48 | 4281 | { |
cf1dfa6b | 4282 | wxListLineData *line = GetLine(i); |
5b077d48 RR |
4283 | wxListItem item; |
4284 | line->GetItem( 0, item ); | |
cf1dfa6b VZ |
4285 | if (item.m_data == data) |
4286 | return i; | |
5b077d48 | 4287 | } |
cf1dfa6b VZ |
4288 | |
4289 | return wxNOT_FOUND; | |
e1e955e1 | 4290 | } |
c801d85f | 4291 | |
debe6624 | 4292 | long wxListMainWindow::HitTest( int x, int y, int &flags ) |
c801d85f | 4293 | { |
aaef15bf | 4294 | CalcUnscrolledPosition( x, y, &x, &y ); |
e8741cca | 4295 | |
fc4f1d5f VZ |
4296 | size_t count = GetItemCount(); |
4297 | ||
5cd89174 | 4298 | if ( HasFlag(wxLC_REPORT) ) |
c801d85f | 4299 | { |
5cd89174 | 4300 | size_t current = y / GetLineHeight(); |
fc4f1d5f VZ |
4301 | if ( current < count ) |
4302 | { | |
4303 | flags = HitTestLine(current, x, y); | |
4304 | if ( flags ) | |
4305 | return current; | |
4306 | } | |
5cd89174 VZ |
4307 | } |
4308 | else // !report | |
4309 | { | |
4310 | // TODO: optimize it too! this is less simple than for report view but | |
4311 | // enumerating all items is still not a way to do it!! | |
5cd89174 | 4312 | for ( size_t current = 0; current < count; current++ ) |
5b077d48 | 4313 | { |
5cd89174 VZ |
4314 | flags = HitTestLine(current, x, y); |
4315 | if ( flags ) | |
4316 | return current; | |
5b077d48 | 4317 | } |
e1e955e1 | 4318 | } |
cf1dfa6b VZ |
4319 | |
4320 | return wxNOT_FOUND; | |
e1e955e1 | 4321 | } |
c801d85f | 4322 | |
cf1dfa6b VZ |
4323 | // ---------------------------------------------------------------------------- |
4324 | // adding stuff | |
4325 | // ---------------------------------------------------------------------------- | |
4326 | ||
c801d85f KB |
4327 | void wxListMainWindow::InsertItem( wxListItem &item ) |
4328 | { | |
cf1dfa6b VZ |
4329 | wxASSERT_MSG( !IsVirtual(), _T("can't be used with virtual control") ); |
4330 | ||
4331 | size_t count = GetItemCount(); | |
4332 | wxCHECK_RET( item.m_itemId >= 0 && (size_t)item.m_itemId <= count, | |
4333 | _T("invalid item index") ); | |
4334 | ||
4335 | size_t id = item.m_itemId; | |
4336 | ||
5b077d48 | 4337 | m_dirty = TRUE; |
cf1dfa6b | 4338 | |
5b077d48 | 4339 | int mode = 0; |
cf1dfa6b | 4340 | if ( HasFlag(wxLC_REPORT) ) |
1370703e | 4341 | mode = wxLC_REPORT; |
cf1dfa6b | 4342 | else if ( HasFlag(wxLC_LIST) ) |
1370703e | 4343 | mode = wxLC_LIST; |
cf1dfa6b | 4344 | else if ( HasFlag(wxLC_ICON) ) |
1370703e | 4345 | mode = wxLC_ICON; |
cf1dfa6b | 4346 | else if ( HasFlag(wxLC_SMALL_ICON) ) |
1370703e VZ |
4347 | mode = wxLC_ICON; // no typo |
4348 | else | |
4349 | { | |
4350 | wxFAIL_MSG( _T("unknown mode") ); | |
4351 | } | |
004fd0c8 | 4352 | |
5cd89174 | 4353 | wxListLineData *line = new wxListLineData(this); |
004fd0c8 | 4354 | |
5b077d48 | 4355 | line->SetItem( 0, item ); |
cf1dfa6b VZ |
4356 | |
4357 | m_lines.Insert( line, id ); | |
5cd89174 | 4358 | |
b84839ae | 4359 | m_dirty = TRUE; |
5cd89174 | 4360 | RefreshLines(id, GetItemCount() - 1); |
e1e955e1 | 4361 | } |
c801d85f | 4362 | |
debe6624 | 4363 | void wxListMainWindow::InsertColumn( long col, wxListItem &item ) |
c801d85f | 4364 | { |
5b077d48 | 4365 | m_dirty = TRUE; |
cf1dfa6b | 4366 | if ( HasFlag(wxLC_REPORT) ) |
3db7be80 | 4367 | { |
54442116 VZ |
4368 | if (item.m_width == wxLIST_AUTOSIZE_USEHEADER) |
4369 | item.m_width = GetTextLength( item.m_text ); | |
5b077d48 RR |
4370 | wxListHeaderData *column = new wxListHeaderData( item ); |
4371 | if ((col >= 0) && (col < (int)m_columns.GetCount())) | |
4372 | { | |
24b9f055 VZ |
4373 | wxListHeaderDataList::Node *node = m_columns.Item( col ); |
4374 | m_columns.Insert( node, column ); | |
5b077d48 RR |
4375 | } |
4376 | else | |
4377 | { | |
4378 | m_columns.Append( column ); | |
4379 | } | |
ae409cb8 VZ |
4380 | |
4381 | // invalidate it as it has to be recalculated | |
4382 | m_headerWidth = 0; | |
3db7be80 | 4383 | } |
e1e955e1 | 4384 | } |
c801d85f | 4385 | |
cf1dfa6b VZ |
4386 | // ---------------------------------------------------------------------------- |
4387 | // sorting | |
4388 | // ---------------------------------------------------------------------------- | |
4389 | ||
c801d85f KB |
4390 | wxListCtrlCompare list_ctrl_compare_func_2; |
4391 | long list_ctrl_compare_data; | |
4392 | ||
f6bcfd97 | 4393 | int LINKAGEMODE list_ctrl_compare_func_1( wxListLineData **arg1, wxListLineData **arg2 ) |
c801d85f | 4394 | { |
f6bcfd97 BP |
4395 | wxListLineData *line1 = *arg1; |
4396 | wxListLineData *line2 = *arg2; | |
5b077d48 RR |
4397 | wxListItem item; |
4398 | line1->GetItem( 0, item ); | |
4399 | long data1 = item.m_data; | |
4400 | line2->GetItem( 0, item ); | |
4401 | long data2 = item.m_data; | |
4402 | return list_ctrl_compare_func_2( data1, data2, list_ctrl_compare_data ); | |
e1e955e1 | 4403 | } |
c801d85f KB |
4404 | |
4405 | void wxListMainWindow::SortItems( wxListCtrlCompare fn, long data ) | |
4406 | { | |
5b077d48 RR |
4407 | list_ctrl_compare_func_2 = fn; |
4408 | list_ctrl_compare_data = data; | |
4409 | m_lines.Sort( list_ctrl_compare_func_1 ); | |
af7c1052 | 4410 | m_dirty = TRUE; |
e1e955e1 | 4411 | } |
c801d85f | 4412 | |
cf1dfa6b VZ |
4413 | // ---------------------------------------------------------------------------- |
4414 | // scrolling | |
4415 | // ---------------------------------------------------------------------------- | |
4416 | ||
7c74e7fe SC |
4417 | void wxListMainWindow::OnScroll(wxScrollWinEvent& event) |
4418 | { | |
b54e41c5 VZ |
4419 | // update our idea of which lines are shown when we redraw the window the |
4420 | // next time | |
4421 | ResetVisibleLinesRange(); | |
cf1dfa6b | 4422 | |
29149a64 | 4423 | // FIXME |
3a8c693a | 4424 | #if defined(__WXGTK__) && !defined(__WXUNIVERSAL__) |
29149a64 VZ |
4425 | wxScrolledWindow::OnScroll(event); |
4426 | #else | |
1e6feb95 | 4427 | HandleOnScroll( event ); |
29149a64 | 4428 | #endif |
30954328 | 4429 | |
cf1dfa6b | 4430 | if ( event.GetOrientation() == wxHORIZONTAL && HasHeader() ) |
7c74e7fe | 4431 | { |
cf1dfa6b VZ |
4432 | wxListCtrl* lc = GetListCtrl(); |
4433 | wxCHECK_RET( lc, _T("no listctrl window?") ); | |
4434 | ||
afbe906a RR |
4435 | lc->m_headerWin->Refresh(); |
4436 | lc->m_headerWin->Update(); | |
7c74e7fe | 4437 | } |
cf1dfa6b VZ |
4438 | } |
4439 | ||
5cd89174 VZ |
4440 | int wxListMainWindow::GetCountPerPage() const |
4441 | { | |
4442 | if ( !m_linesPerPage ) | |
4443 | { | |
4444 | wxConstCast(this, wxListMainWindow)-> | |
4445 | m_linesPerPage = GetClientSize().y / GetLineHeight(); | |
4446 | } | |
4447 | ||
4448 | return m_linesPerPage; | |
4449 | } | |
4450 | ||
b54e41c5 | 4451 | void wxListMainWindow::GetVisibleLinesRange(size_t *from, size_t *to) |
cf1dfa6b | 4452 | { |
b54e41c5 | 4453 | wxASSERT_MSG( HasFlag(wxLC_REPORT), _T("this is for report mode only") ); |
cf1dfa6b | 4454 | |
b54e41c5 VZ |
4455 | if ( m_lineFrom == (size_t)-1 ) |
4456 | { | |
b54e41c5 | 4457 | size_t count = GetItemCount(); |
6522713c VZ |
4458 | if ( count ) |
4459 | { | |
4460 | m_lineFrom = GetScrollPos(wxVERTICAL); | |
cf1dfa6b | 4461 | |
152c57f2 VZ |
4462 | // this may happen if SetScrollbars() hadn't been called yet |
4463 | if ( m_lineFrom >= count ) | |
bcc0da5c | 4464 | m_lineFrom = count - 1; |
cf1dfa6b | 4465 | |
6522713c VZ |
4466 | // we redraw one extra line but this is needed to make the redrawing |
4467 | // logic work when there is a fractional number of lines on screen | |
4468 | m_lineTo = m_lineFrom + m_linesPerPage; | |
4469 | if ( m_lineTo >= count ) | |
4470 | m_lineTo = count - 1; | |
4471 | } | |
4472 | else // empty control | |
4473 | { | |
4474 | m_lineFrom = 0; | |
4475 | m_lineTo = (size_t)-1; | |
4476 | } | |
cf1dfa6b | 4477 | } |
b54e41c5 | 4478 | |
ae167d2f VZ |
4479 | wxASSERT_MSG( IsEmpty() || |
4480 | (m_lineFrom <= m_lineTo && m_lineTo < GetItemCount()), | |
6b4a8d93 VZ |
4481 | _T("GetVisibleLinesRange() returns incorrect result") ); |
4482 | ||
b54e41c5 VZ |
4483 | if ( from ) |
4484 | *from = m_lineFrom; | |
4485 | if ( to ) | |
4486 | *to = m_lineTo; | |
7c74e7fe SC |
4487 | } |
4488 | ||
c801d85f KB |
4489 | // ------------------------------------------------------------------------------------- |
4490 | // wxListItem | |
4491 | // ------------------------------------------------------------------------------------- | |
4492 | ||
4493 | IMPLEMENT_DYNAMIC_CLASS(wxListItem, wxObject) | |
4494 | ||
c801d85f KB |
4495 | // ------------------------------------------------------------------------------------- |
4496 | // wxListCtrl | |
4497 | // ------------------------------------------------------------------------------------- | |
4498 | ||
4499 | IMPLEMENT_DYNAMIC_CLASS(wxListCtrl, wxControl) | |
bf9b6266 | 4500 | IMPLEMENT_DYNAMIC_CLASS(wxListView, wxListCtrl) |
c801d85f | 4501 | |
0ded6bb6 VZ |
4502 | IMPLEMENT_DYNAMIC_CLASS(wxListEvent, wxNotifyEvent) |
4503 | ||
c801d85f | 4504 | BEGIN_EVENT_TABLE(wxListCtrl,wxControl) |
cf1dfa6b VZ |
4505 | EVT_SIZE(wxListCtrl::OnSize) |
4506 | EVT_IDLE(wxListCtrl::OnIdle) | |
c801d85f KB |
4507 | END_EVENT_TABLE() |
4508 | ||
fd9811b1 | 4509 | wxListCtrl::wxListCtrl() |
c801d85f | 4510 | { |
5b077d48 RR |
4511 | m_imageListNormal = (wxImageList *) NULL; |
4512 | m_imageListSmall = (wxImageList *) NULL; | |
4513 | m_imageListState = (wxImageList *) NULL; | |
cf1dfa6b VZ |
4514 | |
4515 | m_ownsImageListNormal = | |
4516 | m_ownsImageListSmall = | |
4517 | m_ownsImageListState = FALSE; | |
4518 | ||
5b077d48 RR |
4519 | m_mainWin = (wxListMainWindow*) NULL; |
4520 | m_headerWin = (wxListHeaderWindow*) NULL; | |
c801d85f KB |
4521 | } |
4522 | ||
fd9811b1 | 4523 | wxListCtrl::~wxListCtrl() |
c801d85f | 4524 | { |
cf1dfa6b VZ |
4525 | if (m_ownsImageListNormal) |
4526 | delete m_imageListNormal; | |
4527 | if (m_ownsImageListSmall) | |
4528 | delete m_imageListSmall; | |
4529 | if (m_ownsImageListState) | |
4530 | delete m_imageListState; | |
4531 | } | |
4532 | ||
4533 | void wxListCtrl::CreateHeaderWindow() | |
4534 | { | |
4535 | m_headerWin = new wxListHeaderWindow | |
4536 | ( | |
4537 | this, -1, m_mainWin, | |
4538 | wxPoint(0, 0), | |
4539 | wxSize(GetClientSize().x, HEADER_HEIGHT), | |
4540 | wxTAB_TRAVERSAL | |
4541 | ); | |
c801d85f KB |
4542 | } |
4543 | ||
25e3a937 VZ |
4544 | bool wxListCtrl::Create(wxWindow *parent, |
4545 | wxWindowID id, | |
4546 | const wxPoint &pos, | |
4547 | const wxSize &size, | |
4548 | long style, | |
25e3a937 | 4549 | const wxValidator &validator, |
25e3a937 | 4550 | const wxString &name) |
c801d85f | 4551 | { |
cf1dfa6b VZ |
4552 | m_imageListNormal = |
4553 | m_imageListSmall = | |
5b077d48 | 4554 | m_imageListState = (wxImageList *) NULL; |
cf1dfa6b VZ |
4555 | m_ownsImageListNormal = |
4556 | m_ownsImageListSmall = | |
4557 | m_ownsImageListState = FALSE; | |
4558 | ||
5b077d48 RR |
4559 | m_mainWin = (wxListMainWindow*) NULL; |
4560 | m_headerWin = (wxListHeaderWindow*) NULL; | |
bd8289c1 | 4561 | |
b54e41c5 | 4562 | if ( !(style & wxLC_MASK_TYPE) ) |
5b077d48 | 4563 | { |
25e3a937 | 4564 | style = style | wxLC_LIST; |
5b077d48 | 4565 | } |
f6bcfd97 | 4566 | |
07215d86 | 4567 | if ( !wxControl::Create( parent, id, pos, size, style, validator, name ) ) |
cf1dfa6b | 4568 | return FALSE; |
f6bcfd97 | 4569 | |
b54e41c5 VZ |
4570 | // don't create the inner window with the border |
4571 | style &= ~wxSUNKEN_BORDER; | |
bd8289c1 | 4572 | |
25e3a937 | 4573 | m_mainWin = new wxListMainWindow( this, -1, wxPoint(0,0), size, style ); |
bd8289c1 | 4574 | |
b54e41c5 | 4575 | if ( HasFlag(wxLC_REPORT) ) |
ea451729 | 4576 | { |
cf1dfa6b VZ |
4577 | CreateHeaderWindow(); |
4578 | ||
b54e41c5 | 4579 | if ( HasFlag(wxLC_NO_HEADER) ) |
cf1dfa6b VZ |
4580 | { |
4581 | // VZ: why do we create it at all then? | |
ea451729 | 4582 | m_headerWin->Show( FALSE ); |
cf1dfa6b | 4583 | } |
ea451729 | 4584 | } |
bd8289c1 | 4585 | |
cf1dfa6b | 4586 | return TRUE; |
e1e955e1 | 4587 | } |
c801d85f | 4588 | |
debe6624 | 4589 | void wxListCtrl::SetSingleStyle( long style, bool add ) |
c801d85f | 4590 | { |
b54e41c5 VZ |
4591 | wxASSERT_MSG( !(style & wxLC_VIRTUAL), |
4592 | _T("wxLC_VIRTUAL can't be [un]set") ); | |
4593 | ||
f03fc89f | 4594 | long flag = GetWindowStyle(); |
bd8289c1 | 4595 | |
5b077d48 RR |
4596 | if (add) |
4597 | { | |
cf1dfa6b | 4598 | if (style & wxLC_MASK_TYPE) |
b54e41c5 | 4599 | flag &= ~(wxLC_MASK_TYPE | wxLC_VIRTUAL); |
cf1dfa6b VZ |
4600 | if (style & wxLC_MASK_ALIGN) |
4601 | flag &= ~wxLC_MASK_ALIGN; | |
4602 | if (style & wxLC_MASK_SORT) | |
4603 | flag &= ~wxLC_MASK_SORT; | |
5b077d48 | 4604 | } |
c801d85f | 4605 | |
5b077d48 RR |
4606 | if (add) |
4607 | { | |
4608 | flag |= style; | |
4609 | } | |
4610 | else | |
4611 | { | |
cf1dfa6b | 4612 | flag &= ~style; |
5b077d48 | 4613 | } |
bd8289c1 | 4614 | |
5b077d48 | 4615 | SetWindowStyleFlag( flag ); |
e1e955e1 | 4616 | } |
c801d85f | 4617 | |
debe6624 | 4618 | void wxListCtrl::SetWindowStyleFlag( long flag ) |
c801d85f | 4619 | { |
121a3581 RR |
4620 | if (m_mainWin) |
4621 | { | |
4622 | m_mainWin->DeleteEverything(); | |
c801d85f | 4623 | |
a95cdab8 VZ |
4624 | // has the header visibility changed? |
4625 | bool hasHeader = HasFlag(wxLC_REPORT) && !HasFlag(wxLC_NO_HEADER), | |
4626 | willHaveHeader = (flag & wxLC_REPORT) && !(flag & wxLC_NO_HEADER); | |
c801d85f | 4627 | |
a95cdab8 | 4628 | if ( hasHeader != willHaveHeader ) |
5b077d48 | 4629 | { |
a95cdab8 VZ |
4630 | // toggle it |
4631 | if ( hasHeader ) | |
4632 | { | |
4633 | if ( m_headerWin ) | |
4634 | { | |
4635 | // don't delete, just hide, as we can reuse it later | |
4636 | m_headerWin->Show(FALSE); | |
4637 | } | |
4638 | //else: nothing to do | |
4639 | } | |
4640 | else // must show header | |
5b077d48 | 4641 | { |
121a3581 RR |
4642 | if (!m_headerWin) |
4643 | { | |
cf1dfa6b | 4644 | CreateHeaderWindow(); |
121a3581 | 4645 | } |
a95cdab8 | 4646 | else // already have it, just show |
004fd0c8 | 4647 | { |
a95cdab8 | 4648 | m_headerWin->Show( TRUE ); |
004fd0c8 | 4649 | } |
5b077d48 | 4650 | } |
a95cdab8 VZ |
4651 | |
4652 | ResizeReportView(willHaveHeader); | |
bffa1c77 | 4653 | } |
e1e955e1 | 4654 | } |
004fd0c8 | 4655 | |
5b077d48 | 4656 | wxWindow::SetWindowStyleFlag( flag ); |
e1e955e1 | 4657 | } |
c801d85f | 4658 | |
e487524e | 4659 | bool wxListCtrl::GetColumn(int col, wxListItem &item) const |
c801d85f | 4660 | { |
5b077d48 RR |
4661 | m_mainWin->GetColumn( col, item ); |
4662 | return TRUE; | |
e1e955e1 | 4663 | } |
c801d85f | 4664 | |
debe6624 | 4665 | bool wxListCtrl::SetColumn( int col, wxListItem& item ) |
c801d85f | 4666 | { |
5b077d48 RR |
4667 | m_mainWin->SetColumn( col, item ); |
4668 | return TRUE; | |
e1e955e1 | 4669 | } |
c801d85f | 4670 | |
e487524e | 4671 | int wxListCtrl::GetColumnWidth( int col ) const |
c801d85f | 4672 | { |
5b077d48 | 4673 | return m_mainWin->GetColumnWidth( col ); |
e1e955e1 | 4674 | } |
c801d85f | 4675 | |
debe6624 | 4676 | bool wxListCtrl::SetColumnWidth( int col, int width ) |
c801d85f | 4677 | { |
5b077d48 RR |
4678 | m_mainWin->SetColumnWidth( col, width ); |
4679 | return TRUE; | |
e1e955e1 | 4680 | } |
c801d85f | 4681 | |
fd9811b1 | 4682 | int wxListCtrl::GetCountPerPage() const |
c801d85f KB |
4683 | { |
4684 | return m_mainWin->GetCountPerPage(); // different from Windows ? | |
e1e955e1 | 4685 | } |
c801d85f | 4686 | |
e487524e | 4687 | bool wxListCtrl::GetItem( wxListItem &info ) const |
c801d85f | 4688 | { |
5b077d48 RR |
4689 | m_mainWin->GetItem( info ); |
4690 | return TRUE; | |
e1e955e1 | 4691 | } |
c801d85f KB |
4692 | |
4693 | bool wxListCtrl::SetItem( wxListItem &info ) | |
4694 | { | |
5b077d48 RR |
4695 | m_mainWin->SetItem( info ); |
4696 | return TRUE; | |
e1e955e1 | 4697 | } |
c801d85f | 4698 | |
debe6624 | 4699 | long wxListCtrl::SetItem( long index, int col, const wxString& label, int imageId ) |
c801d85f | 4700 | { |
5b077d48 RR |
4701 | wxListItem info; |
4702 | info.m_text = label; | |
4703 | info.m_mask = wxLIST_MASK_TEXT; | |
4704 | info.m_itemId = index; | |
4705 | info.m_col = col; | |
4706 | if ( imageId > -1 ) | |
4707 | { | |
4708 | info.m_image = imageId; | |
4709 | info.m_mask |= wxLIST_MASK_IMAGE; | |
4710 | }; | |
4711 | m_mainWin->SetItem(info); | |
4712 | return TRUE; | |
e1e955e1 | 4713 | } |
c801d85f | 4714 | |
e487524e | 4715 | int wxListCtrl::GetItemState( long item, long stateMask ) const |
c801d85f | 4716 | { |
5b077d48 | 4717 | return m_mainWin->GetItemState( item, stateMask ); |
e1e955e1 | 4718 | } |
c801d85f | 4719 | |
debe6624 | 4720 | bool wxListCtrl::SetItemState( long item, long state, long stateMask ) |
c801d85f | 4721 | { |
5b077d48 RR |
4722 | m_mainWin->SetItemState( item, state, stateMask ); |
4723 | return TRUE; | |
e1e955e1 | 4724 | } |
c801d85f | 4725 | |
debe6624 | 4726 | bool wxListCtrl::SetItemImage( long item, int image, int WXUNUSED(selImage) ) |
c801d85f | 4727 | { |
5b077d48 RR |
4728 | wxListItem info; |
4729 | info.m_image = image; | |
4730 | info.m_mask = wxLIST_MASK_IMAGE; | |
4731 | info.m_itemId = item; | |
4732 | m_mainWin->SetItem( info ); | |
4733 | return TRUE; | |
e1e955e1 | 4734 | } |
c801d85f | 4735 | |
e487524e | 4736 | wxString wxListCtrl::GetItemText( long item ) const |
c801d85f | 4737 | { |
62d89eb4 | 4738 | return m_mainWin->GetItemText(item); |
e1e955e1 | 4739 | } |
c801d85f | 4740 | |
62d89eb4 | 4741 | void wxListCtrl::SetItemText( long item, const wxString& str ) |
c801d85f | 4742 | { |
62d89eb4 | 4743 | m_mainWin->SetItemText(item, str); |
e1e955e1 | 4744 | } |
c801d85f | 4745 | |
e487524e | 4746 | long wxListCtrl::GetItemData( long item ) const |
c801d85f | 4747 | { |
5b077d48 RR |
4748 | wxListItem info; |
4749 | info.m_itemId = item; | |
4750 | m_mainWin->GetItem( info ); | |
4751 | return info.m_data; | |
e1e955e1 | 4752 | } |
c801d85f | 4753 | |
debe6624 | 4754 | bool wxListCtrl::SetItemData( long item, long data ) |
c801d85f | 4755 | { |
5b077d48 RR |
4756 | wxListItem info; |
4757 | info.m_mask = wxLIST_MASK_DATA; | |
4758 | info.m_itemId = item; | |
4759 | info.m_data = data; | |
4760 | m_mainWin->SetItem( info ); | |
4761 | return TRUE; | |
e1e955e1 | 4762 | } |
c801d85f | 4763 | |
0a240683 | 4764 | bool wxListCtrl::GetItemRect( long item, wxRect &rect, int WXUNUSED(code) ) const |
c801d85f | 4765 | { |
5b077d48 RR |
4766 | m_mainWin->GetItemRect( item, rect ); |
4767 | return TRUE; | |
e1e955e1 | 4768 | } |
c801d85f | 4769 | |
e487524e | 4770 | bool wxListCtrl::GetItemPosition( long item, wxPoint& pos ) const |
c801d85f | 4771 | { |
5b077d48 RR |
4772 | m_mainWin->GetItemPosition( item, pos ); |
4773 | return TRUE; | |
e1e955e1 | 4774 | } |
c801d85f | 4775 | |
debe6624 | 4776 | bool wxListCtrl::SetItemPosition( long WXUNUSED(item), const wxPoint& WXUNUSED(pos) ) |
c801d85f | 4777 | { |
5b077d48 | 4778 | return 0; |
e1e955e1 | 4779 | } |
c801d85f | 4780 | |
fd9811b1 | 4781 | int wxListCtrl::GetItemCount() const |
c801d85f | 4782 | { |
5b077d48 | 4783 | return m_mainWin->GetItemCount(); |
e1e955e1 | 4784 | } |
c801d85f | 4785 | |
fd9811b1 | 4786 | int wxListCtrl::GetColumnCount() const |
92976ab6 | 4787 | { |
5b077d48 | 4788 | return m_mainWin->GetColumnCount(); |
92976ab6 RR |
4789 | } |
4790 | ||
33d0b396 RR |
4791 | void wxListCtrl::SetItemSpacing( int spacing, bool isSmall ) |
4792 | { | |
5b077d48 | 4793 | m_mainWin->SetItemSpacing( spacing, isSmall ); |
e1e955e1 | 4794 | } |
33d0b396 | 4795 | |
e487524e | 4796 | int wxListCtrl::GetItemSpacing( bool isSmall ) const |
c801d85f | 4797 | { |
5b077d48 | 4798 | return m_mainWin->GetItemSpacing( isSmall ); |
e1e955e1 | 4799 | } |
c801d85f | 4800 | |
5b98eb2f RL |
4801 | void wxListCtrl::SetItemTextColour( long item, const wxColour &col ) |
4802 | { | |
4803 | wxListItem info; | |
4804 | info.m_itemId = item; | |
4805 | info.SetTextColour( col ); | |
4806 | m_mainWin->SetItem( info ); | |
4807 | } | |
4808 | ||
4809 | wxColour wxListCtrl::GetItemTextColour( long item ) const | |
4810 | { | |
4811 | wxListItem info; | |
4812 | info.m_itemId = item; | |
4813 | m_mainWin->GetItem( info ); | |
4814 | return info.GetTextColour(); | |
4815 | } | |
4816 | ||
4817 | void wxListCtrl::SetItemBackgroundColour( long item, const wxColour &col ) | |
4818 | { | |
4819 | wxListItem info; | |
4820 | info.m_itemId = item; | |
4821 | info.SetBackgroundColour( col ); | |
4822 | m_mainWin->SetItem( info ); | |
4823 | } | |
4824 | ||
4825 | wxColour wxListCtrl::GetItemBackgroundColour( long item ) const | |
4826 | { | |
4827 | wxListItem info; | |
4828 | info.m_itemId = item; | |
4829 | m_mainWin->GetItem( info ); | |
4830 | return info.GetBackgroundColour(); | |
4831 | } | |
4832 | ||
fd9811b1 | 4833 | int wxListCtrl::GetSelectedItemCount() const |
c801d85f | 4834 | { |
5b077d48 | 4835 | return m_mainWin->GetSelectedItemCount(); |
e1e955e1 | 4836 | } |
c801d85f | 4837 | |
fd9811b1 | 4838 | wxColour wxListCtrl::GetTextColour() const |
c801d85f | 4839 | { |
0530737d | 4840 | return GetForegroundColour(); |
e1e955e1 | 4841 | } |
c801d85f | 4842 | |
0530737d | 4843 | void wxListCtrl::SetTextColour(const wxColour& col) |
c801d85f | 4844 | { |
0530737d | 4845 | SetForegroundColour(col); |
e1e955e1 | 4846 | } |
c801d85f | 4847 | |
fd9811b1 | 4848 | long wxListCtrl::GetTopItem() const |
c801d85f | 4849 | { |
5b077d48 | 4850 | return 0; |
e1e955e1 | 4851 | } |
c801d85f | 4852 | |
6de97a3b | 4853 | long wxListCtrl::GetNextItem( long item, int geom, int state ) const |
c801d85f | 4854 | { |
5b077d48 | 4855 | return m_mainWin->GetNextItem( item, geom, state ); |
e1e955e1 | 4856 | } |
c801d85f | 4857 | |
e487524e | 4858 | wxImageList *wxListCtrl::GetImageList(int which) const |
c801d85f | 4859 | { |
5b077d48 RR |
4860 | if (which == wxIMAGE_LIST_NORMAL) |
4861 | { | |
4862 | return m_imageListNormal; | |
4863 | } | |
4864 | else if (which == wxIMAGE_LIST_SMALL) | |
4865 | { | |
4866 | return m_imageListSmall; | |
4867 | } | |
4868 | else if (which == wxIMAGE_LIST_STATE) | |
4869 | { | |
4870 | return m_imageListState; | |
4871 | } | |
4872 | return (wxImageList *) NULL; | |
e1e955e1 | 4873 | } |
c801d85f | 4874 | |
debe6624 | 4875 | void wxListCtrl::SetImageList( wxImageList *imageList, int which ) |
c801d85f | 4876 | { |
2e12c11a VS |
4877 | if ( which == wxIMAGE_LIST_NORMAL ) |
4878 | { | |
4879 | if (m_ownsImageListNormal) delete m_imageListNormal; | |
4880 | m_imageListNormal = imageList; | |
4881 | m_ownsImageListNormal = FALSE; | |
4882 | } | |
4883 | else if ( which == wxIMAGE_LIST_SMALL ) | |
4884 | { | |
4885 | if (m_ownsImageListSmall) delete m_imageListSmall; | |
4886 | m_imageListSmall = imageList; | |
4887 | m_ownsImageListSmall = FALSE; | |
4888 | } | |
4889 | else if ( which == wxIMAGE_LIST_STATE ) | |
4890 | { | |
4891 | if (m_ownsImageListState) delete m_imageListState; | |
4892 | m_imageListState = imageList; | |
4893 | m_ownsImageListState = FALSE; | |
4894 | } | |
4895 | ||
5b077d48 | 4896 | m_mainWin->SetImageList( imageList, which ); |
e1e955e1 | 4897 | } |
c801d85f | 4898 | |
2e12c11a VS |
4899 | void wxListCtrl::AssignImageList(wxImageList *imageList, int which) |
4900 | { | |
4901 | SetImageList(imageList, which); | |
4902 | if ( which == wxIMAGE_LIST_NORMAL ) | |
4903 | m_ownsImageListNormal = TRUE; | |
4904 | else if ( which == wxIMAGE_LIST_SMALL ) | |
4905 | m_ownsImageListSmall = TRUE; | |
4906 | else if ( which == wxIMAGE_LIST_STATE ) | |
4907 | m_ownsImageListState = TRUE; | |
4908 | } | |
4909 | ||
debe6624 | 4910 | bool wxListCtrl::Arrange( int WXUNUSED(flag) ) |
c801d85f | 4911 | { |
5b077d48 | 4912 | return 0; |
e1e955e1 | 4913 | } |
c801d85f | 4914 | |
debe6624 | 4915 | bool wxListCtrl::DeleteItem( long item ) |
c801d85f | 4916 | { |
5b077d48 RR |
4917 | m_mainWin->DeleteItem( item ); |
4918 | return TRUE; | |
e1e955e1 | 4919 | } |
c801d85f | 4920 | |
fd9811b1 | 4921 | bool wxListCtrl::DeleteAllItems() |
c801d85f | 4922 | { |
5b077d48 RR |
4923 | m_mainWin->DeleteAllItems(); |
4924 | return TRUE; | |
e1e955e1 | 4925 | } |
c801d85f | 4926 | |
4f22cf8d | 4927 | bool wxListCtrl::DeleteAllColumns() |
bd8289c1 | 4928 | { |
24b9f055 VZ |
4929 | size_t count = m_mainWin->m_columns.GetCount(); |
4930 | for ( size_t n = 0; n < count; n++ ) | |
85cdcb7a | 4931 | DeleteColumn(0); |
bffa1c77 | 4932 | |
5b077d48 | 4933 | return TRUE; |
4f22cf8d RR |
4934 | } |
4935 | ||
4936 | void wxListCtrl::ClearAll() | |
4937 | { | |
5b077d48 | 4938 | m_mainWin->DeleteEverything(); |
bd8289c1 VZ |
4939 | } |
4940 | ||
debe6624 | 4941 | bool wxListCtrl::DeleteColumn( int col ) |
c801d85f | 4942 | { |
5b077d48 | 4943 | m_mainWin->DeleteColumn( col ); |
40c08808 VZ |
4944 | |
4945 | // if we don't have the header any longer, we need to relayout the window | |
4946 | if ( !GetColumnCount() ) | |
4947 | { | |
4948 | ResizeReportView(FALSE /* no header */); | |
4949 | } | |
4950 | ||
5b077d48 | 4951 | return TRUE; |
e1e955e1 | 4952 | } |
c801d85f | 4953 | |
e179bd65 | 4954 | void wxListCtrl::Edit( long item ) |
c801d85f | 4955 | { |
cf1dfa6b | 4956 | m_mainWin->EditLabel( item ); |
e1e955e1 | 4957 | } |
c801d85f | 4958 | |
debe6624 | 4959 | bool wxListCtrl::EnsureVisible( long item ) |
c801d85f | 4960 | { |
5b077d48 RR |
4961 | m_mainWin->EnsureVisible( item ); |
4962 | return TRUE; | |
e1e955e1 | 4963 | } |
c801d85f | 4964 | |
debe6624 | 4965 | long wxListCtrl::FindItem( long start, const wxString& str, bool partial ) |
c801d85f | 4966 | { |
5b077d48 | 4967 | return m_mainWin->FindItem( start, str, partial ); |
e1e955e1 | 4968 | } |
c801d85f | 4969 | |
debe6624 | 4970 | long wxListCtrl::FindItem( long start, long data ) |
c801d85f | 4971 | { |
5b077d48 | 4972 | return m_mainWin->FindItem( start, data ); |
e1e955e1 | 4973 | } |
c801d85f | 4974 | |
bd8289c1 | 4975 | long wxListCtrl::FindItem( long WXUNUSED(start), const wxPoint& WXUNUSED(pt), |
debe6624 | 4976 | int WXUNUSED(direction)) |
c801d85f | 4977 | { |
5b077d48 | 4978 | return 0; |
e1e955e1 | 4979 | } |
c801d85f KB |
4980 | |
4981 | long wxListCtrl::HitTest( const wxPoint &point, int &flags ) | |
4982 | { | |
5b077d48 | 4983 | return m_mainWin->HitTest( (int)point.x, (int)point.y, flags ); |
e1e955e1 | 4984 | } |
c801d85f KB |
4985 | |
4986 | long wxListCtrl::InsertItem( wxListItem& info ) | |
4987 | { | |
5b077d48 | 4988 | m_mainWin->InsertItem( info ); |
2ebcd5f5 | 4989 | return info.m_itemId; |
e1e955e1 | 4990 | } |
c801d85f | 4991 | |
debe6624 | 4992 | long wxListCtrl::InsertItem( long index, const wxString &label ) |
c801d85f | 4993 | { |
51cc4dad RR |
4994 | wxListItem info; |
4995 | info.m_text = label; | |
4996 | info.m_mask = wxLIST_MASK_TEXT; | |
4997 | info.m_itemId = index; | |
4998 | return InsertItem( info ); | |
e1e955e1 | 4999 | } |
c801d85f | 5000 | |
debe6624 | 5001 | long wxListCtrl::InsertItem( long index, int imageIndex ) |
c801d85f | 5002 | { |
51cc4dad RR |
5003 | wxListItem info; |
5004 | info.m_mask = wxLIST_MASK_IMAGE; | |
5005 | info.m_image = imageIndex; | |
5006 | info.m_itemId = index; | |
5007 | return InsertItem( info ); | |
e1e955e1 | 5008 | } |
c801d85f | 5009 | |
debe6624 | 5010 | long wxListCtrl::InsertItem( long index, const wxString &label, int imageIndex ) |
c801d85f | 5011 | { |
51cc4dad RR |
5012 | wxListItem info; |
5013 | info.m_text = label; | |
5014 | info.m_image = imageIndex; | |
5015 | info.m_mask = wxLIST_MASK_TEXT | wxLIST_MASK_IMAGE; | |
5016 | info.m_itemId = index; | |
5017 | return InsertItem( info ); | |
e1e955e1 | 5018 | } |
c801d85f | 5019 | |
debe6624 | 5020 | long wxListCtrl::InsertColumn( long col, wxListItem &item ) |
c801d85f | 5021 | { |
40c08808 VZ |
5022 | wxCHECK_MSG( m_headerWin, -1, _T("can't add column in non report mode") ); |
5023 | ||
51cc4dad | 5024 | m_mainWin->InsertColumn( col, item ); |
40c08808 VZ |
5025 | |
5026 | // if we hadn't had header before and have it now we need to relayout the | |
5027 | // window | |
5028 | if ( GetColumnCount() == 1 ) | |
5029 | { | |
5030 | ResizeReportView(TRUE /* have header */); | |
5031 | } | |
5032 | ||
d3e90957 | 5033 | m_headerWin->Refresh(); |
25e3a937 | 5034 | |
51cc4dad | 5035 | return 0; |
e1e955e1 | 5036 | } |
c801d85f | 5037 | |
debe6624 JS |
5038 | long wxListCtrl::InsertColumn( long col, const wxString &heading, |
5039 | int format, int width ) | |
c801d85f | 5040 | { |
51cc4dad RR |
5041 | wxListItem item; |
5042 | item.m_mask = wxLIST_MASK_TEXT | wxLIST_MASK_FORMAT; | |
5043 | item.m_text = heading; | |
5044 | if (width >= -2) | |
5045 | { | |
5046 | item.m_mask |= wxLIST_MASK_WIDTH; | |
5047 | item.m_width = width; | |
5048 | } | |
5049 | item.m_format = format; | |
c801d85f | 5050 | |
51cc4dad | 5051 | return InsertColumn( col, item ); |
e1e955e1 | 5052 | } |
c801d85f | 5053 | |
debe6624 | 5054 | bool wxListCtrl::ScrollList( int WXUNUSED(dx), int WXUNUSED(dy) ) |
c801d85f | 5055 | { |
51cc4dad | 5056 | return 0; |
e1e955e1 | 5057 | } |
c801d85f KB |
5058 | |
5059 | // Sort items. | |
5060 | // fn is a function which takes 3 long arguments: item1, item2, data. | |
5061 | // item1 is the long data associated with a first item (NOT the index). | |
5062 | // item2 is the long data associated with a second item (NOT the index). | |
5063 | // data is the same value as passed to SortItems. | |
5064 | // The return value is a negative number if the first item should precede the second | |
5065 | // item, a positive number of the second item should precede the first, | |
5066 | // or zero if the two items are equivalent. | |
5067 | // data is arbitrary data to be passed to the sort function. | |
5068 | ||
5069 | bool wxListCtrl::SortItems( wxListCtrlCompare fn, long data ) | |
5070 | { | |
51cc4dad RR |
5071 | m_mainWin->SortItems( fn, data ); |
5072 | return TRUE; | |
e1e955e1 | 5073 | } |
c801d85f | 5074 | |
cf1dfa6b | 5075 | // ---------------------------------------------------------------------------- |
b54e41c5 | 5076 | // event handlers |
cf1dfa6b VZ |
5077 | // ---------------------------------------------------------------------------- |
5078 | ||
3475a005 | 5079 | void wxListCtrl::OnSize(wxSizeEvent& WXUNUSED(event)) |
53010e52 | 5080 | { |
b54e41c5 | 5081 | if ( !m_mainWin ) |
cf1dfa6b | 5082 | return; |
53010e52 | 5083 | |
a95cdab8 VZ |
5084 | ResizeReportView(m_mainWin->HasHeader()); |
5085 | ||
5086 | m_mainWin->RecalculatePositions(); | |
5087 | } | |
5088 | ||
5089 | void wxListCtrl::ResizeReportView(bool showHeader) | |
5090 | { | |
b54e41c5 | 5091 | int cw, ch; |
51cc4dad | 5092 | GetClientSize( &cw, &ch ); |
bd8289c1 | 5093 | |
a95cdab8 | 5094 | if ( showHeader ) |
51cc4dad | 5095 | { |
cf1dfa6b VZ |
5096 | m_headerWin->SetSize( 0, 0, cw, HEADER_HEIGHT ); |
5097 | m_mainWin->SetSize( 0, HEADER_HEIGHT + 1, cw, ch - HEADER_HEIGHT - 1 ); | |
51cc4dad | 5098 | } |
cf1dfa6b | 5099 | else // no header window |
51cc4dad | 5100 | { |
cf1dfa6b | 5101 | m_mainWin->SetSize( 0, 0, cw, ch ); |
51cc4dad | 5102 | } |
b54e41c5 | 5103 | } |
cf1dfa6b | 5104 | |
b54e41c5 VZ |
5105 | void wxListCtrl::OnIdle( wxIdleEvent & event ) |
5106 | { | |
5107 | event.Skip(); | |
f6bcfd97 | 5108 | |
b54e41c5 VZ |
5109 | // do it only if needed |
5110 | if ( !m_mainWin->m_dirty ) | |
5111 | return; | |
5112 | ||
5113 | m_mainWin->RecalculatePositions(); | |
e1e955e1 | 5114 | } |
53010e52 | 5115 | |
cf1dfa6b VZ |
5116 | // ---------------------------------------------------------------------------- |
5117 | // font/colours | |
5118 | // ---------------------------------------------------------------------------- | |
5119 | ||
f03fc89f | 5120 | bool wxListCtrl::SetBackgroundColour( const wxColour &colour ) |
bd8289c1 | 5121 | { |
51cc4dad RR |
5122 | if (m_mainWin) |
5123 | { | |
5124 | m_mainWin->SetBackgroundColour( colour ); | |
5125 | m_mainWin->m_dirty = TRUE; | |
5126 | } | |
004fd0c8 | 5127 | |
f03fc89f | 5128 | return TRUE; |
e4d06860 RR |
5129 | } |
5130 | ||
f03fc89f | 5131 | bool wxListCtrl::SetForegroundColour( const wxColour &colour ) |
bd8289c1 | 5132 | { |
f03fc89f VZ |
5133 | if ( !wxWindow::SetForegroundColour( colour ) ) |
5134 | return FALSE; | |
004fd0c8 | 5135 | |
51cc4dad RR |
5136 | if (m_mainWin) |
5137 | { | |
5138 | m_mainWin->SetForegroundColour( colour ); | |
5139 | m_mainWin->m_dirty = TRUE; | |
5140 | } | |
004fd0c8 | 5141 | |
51cc4dad RR |
5142 | if (m_headerWin) |
5143 | { | |
5144 | m_headerWin->SetForegroundColour( colour ); | |
5145 | } | |
f03fc89f VZ |
5146 | |
5147 | return TRUE; | |
e4d06860 | 5148 | } |
bd8289c1 | 5149 | |
f03fc89f | 5150 | bool wxListCtrl::SetFont( const wxFont &font ) |
bd8289c1 | 5151 | { |
f03fc89f VZ |
5152 | if ( !wxWindow::SetFont( font ) ) |
5153 | return FALSE; | |
004fd0c8 | 5154 | |
51cc4dad RR |
5155 | if (m_mainWin) |
5156 | { | |
5157 | m_mainWin->SetFont( font ); | |
5158 | m_mainWin->m_dirty = TRUE; | |
5159 | } | |
004fd0c8 | 5160 | |
51cc4dad RR |
5161 | if (m_headerWin) |
5162 | { | |
5163 | m_headerWin->SetFont( font ); | |
5164 | } | |
f03fc89f VZ |
5165 | |
5166 | return TRUE; | |
e4d06860 | 5167 | } |
c801d85f | 5168 | |
cf1dfa6b VZ |
5169 | // ---------------------------------------------------------------------------- |
5170 | // methods forwarded to m_mainWin | |
5171 | // ---------------------------------------------------------------------------- | |
5172 | ||
efbb7287 VZ |
5173 | #if wxUSE_DRAG_AND_DROP |
5174 | ||
5175 | void wxListCtrl::SetDropTarget( wxDropTarget *dropTarget ) | |
5176 | { | |
5177 | m_mainWin->SetDropTarget( dropTarget ); | |
5178 | } | |
5179 | ||
5180 | wxDropTarget *wxListCtrl::GetDropTarget() const | |
5181 | { | |
5182 | return m_mainWin->GetDropTarget(); | |
5183 | } | |
5184 | ||
5185 | #endif // wxUSE_DRAG_AND_DROP | |
5186 | ||
5187 | bool wxListCtrl::SetCursor( const wxCursor &cursor ) | |
5188 | { | |
5189 | return m_mainWin ? m_mainWin->wxWindow::SetCursor(cursor) : FALSE; | |
5190 | } | |
5191 | ||
5192 | wxColour wxListCtrl::GetBackgroundColour() const | |
5193 | { | |
5194 | return m_mainWin ? m_mainWin->GetBackgroundColour() : wxColour(); | |
5195 | } | |
5196 | ||
5197 | wxColour wxListCtrl::GetForegroundColour() const | |
5198 | { | |
5199 | return m_mainWin ? m_mainWin->GetForegroundColour() : wxColour(); | |
5200 | } | |
5201 | ||
5202 | bool wxListCtrl::DoPopupMenu( wxMenu *menu, int x, int y ) | |
5203 | { | |
3a8c693a | 5204 | #if wxUSE_MENUS |
efbb7287 | 5205 | return m_mainWin->PopupMenu( menu, x, y ); |
3a8c693a VZ |
5206 | #else |
5207 | return FALSE; | |
5208 | #endif // wxUSE_MENUS | |
efbb7287 VZ |
5209 | } |
5210 | ||
5211 | void wxListCtrl::SetFocus() | |
5212 | { | |
5213 | /* The test in window.cpp fails as we are a composite | |
5214 | window, so it checks against "this", but not m_mainWin. */ | |
5215 | if ( FindFocus() != this ) | |
5216 | m_mainWin->SetFocus(); | |
5217 | } | |
1e6feb95 | 5218 | |
2c1f73ee VZ |
5219 | // ---------------------------------------------------------------------------- |
5220 | // virtual list control support | |
5221 | // ---------------------------------------------------------------------------- | |
5222 | ||
3475a005 | 5223 | wxString wxListCtrl::OnGetItemText(long WXUNUSED(item), long WXUNUSED(col)) const |
2c1f73ee VZ |
5224 | { |
5225 | // this is a pure virtual function, in fact - which is not really pure | |
5226 | // because the controls which are not virtual don't need to implement it | |
3475a005 | 5227 | wxFAIL_MSG( _T("wxListCtrl::OnGetItemText not supposed to be called") ); |
2c1f73ee VZ |
5228 | |
5229 | return wxEmptyString; | |
5230 | } | |
5231 | ||
3475a005 | 5232 | int wxListCtrl::OnGetItemImage(long WXUNUSED(item)) const |
2c1f73ee VZ |
5233 | { |
5234 | // same as above | |
3475a005 | 5235 | wxFAIL_MSG( _T("wxListCtrl::OnGetItemImage not supposed to be called") ); |
2c1f73ee VZ |
5236 | |
5237 | return -1; | |
5238 | } | |
5239 | ||
6c02c329 VZ |
5240 | wxListItemAttr *wxListCtrl::OnGetItemAttr(long item) const |
5241 | { | |
5242 | wxASSERT_MSG( item >= 0 && item < GetItemCount(), | |
5243 | _T("invalid item index in OnGetItemAttr()") ); | |
5244 | ||
5245 | // no attributes by default | |
5246 | return NULL; | |
5247 | } | |
5248 | ||
2c1f73ee VZ |
5249 | void wxListCtrl::SetItemCount(long count) |
5250 | { | |
5251 | wxASSERT_MSG( IsVirtual(), _T("this is for virtual controls only") ); | |
5252 | ||
5253 | m_mainWin->SetItemCount(count); | |
5254 | } | |
5255 | ||
1a6cb56f VZ |
5256 | void wxListCtrl::RefreshItem(long item) |
5257 | { | |
5258 | m_mainWin->RefreshLine(item); | |
5259 | } | |
5260 | ||
5261 | void wxListCtrl::RefreshItems(long itemFrom, long itemTo) | |
5262 | { | |
5263 | m_mainWin->RefreshLines(itemFrom, itemTo); | |
5264 | } | |
5265 | ||
c5c528fc VZ |
5266 | void wxListCtrl::Freeze() |
5267 | { | |
5268 | m_mainWin->Freeze(); | |
5269 | } | |
5270 | ||
5271 | void wxListCtrl::Thaw() | |
5272 | { | |
5273 | m_mainWin->Thaw(); | |
5274 | } | |
5275 | ||
1e6feb95 | 5276 | #endif // wxUSE_LISTCTRL |
5b98eb2f RL |
5277 | |
5278 | // vi:sts=4:sw=4:et |