]>
Commit | Line | Data |
---|---|---|
c801d85f KB |
1 | ///////////////////////////////////////////////////////////////////////////// |
2 | // Name: listctrl.cpp | |
3 | // Purpose: | |
4 | // Author: Robert Roebling | |
0208334d RR |
5 | // Id: $Id$ |
6 | // Copyright: (c) 1998 Robert Roebling | |
bd8289c1 | 7 | // Licence: wxWindows licence |
c801d85f KB |
8 | ///////////////////////////////////////////////////////////////////////////// |
9 | ||
10 | #ifdef __GNUG__ | |
510fc784 RR |
11 | #pragma implementation "listctrl.h" |
12 | #pragma implementation "listctrlbase.h" | |
c801d85f KB |
13 | #endif |
14 | ||
1e6d9499 JS |
15 | // For compilers that support precompilation, includes "wx.h". |
16 | #include "wx/wxprec.h" | |
17 | ||
18 | #ifdef __BORLANDC__ | |
19 | #pragma hdrstop | |
20 | #endif | |
21 | ||
0208334d RR |
22 | #include "wx/dcscreen.h" |
23 | #include "wx/app.h" | |
02527779 | 24 | #include "wx/listctrl.h" |
f60d0f94 | 25 | #include "wx/generic/imaglist.h" |
f6bcfd97 | 26 | #include "wx/dynarray.h" |
c801d85f | 27 | |
3fb435df RR |
28 | #ifdef __WXGTK__ |
29 | #include <gtk/gtk.h> | |
30 | #include "wx/gtk/win_gtk.h" | |
31 | #endif | |
32 | ||
7c74e7fe | 33 | #ifndef wxUSE_GENERIC_LIST_EXTENSIONS |
d6d26e04 | 34 | #define wxUSE_GENERIC_LIST_EXTENSIONS 1 |
7c74e7fe SC |
35 | #endif |
36 | ||
efbb7287 VZ |
37 | // ============================================================================ |
38 | // private classes | |
39 | // ============================================================================ | |
40 | ||
41 | //----------------------------------------------------------------------------- | |
42 | // wxListItemData (internal) | |
43 | //----------------------------------------------------------------------------- | |
44 | ||
45 | class WXDLLEXPORT wxListItemData : public wxObject | |
46 | { | |
47 | public: | |
48 | wxString m_text; | |
49 | int m_image; | |
50 | long m_data; | |
51 | int m_xpos,m_ypos; | |
52 | int m_width,m_height; | |
53 | ||
54 | wxListItemAttr *m_attr; | |
55 | ||
56 | public: | |
57 | wxListItemData(); | |
58 | ~wxListItemData() { delete m_attr; } | |
59 | ||
60 | wxListItemData( const wxListItem &info ); | |
61 | void SetItem( const wxListItem &info ); | |
62 | void SetText( const wxString &s ); | |
63 | void SetImage( int image ); | |
64 | void SetData( long data ); | |
65 | void SetPosition( int x, int y ); | |
66 | void SetSize( int width, int height ); | |
67 | bool HasImage() const; | |
68 | bool HasText() const; | |
69 | bool IsHit( int x, int y ) const; | |
70 | void GetText( wxString &s ); | |
71 | const wxString& GetText() { return m_text; } | |
72 | int GetX( void ) const; | |
73 | int GetY( void ) const; | |
74 | int GetWidth() const; | |
75 | int GetHeight() const; | |
76 | int GetImage() const; | |
77 | void GetItem( wxListItem &info ) const; | |
78 | ||
79 | wxListItemAttr *GetAttributes() const { return m_attr; } | |
80 | ||
81 | private: | |
82 | DECLARE_DYNAMIC_CLASS(wxListItemData); | |
83 | }; | |
84 | ||
85 | //----------------------------------------------------------------------------- | |
86 | // wxListHeaderData (internal) | |
87 | //----------------------------------------------------------------------------- | |
88 | ||
89 | class WXDLLEXPORT wxListHeaderData : public wxObject | |
90 | { | |
91 | protected: | |
92 | long m_mask; | |
93 | int m_image; | |
94 | wxString m_text; | |
95 | int m_format; | |
96 | int m_width; | |
97 | int m_xpos,m_ypos; | |
98 | int m_height; | |
99 | ||
100 | public: | |
101 | wxListHeaderData(); | |
102 | wxListHeaderData( const wxListItem &info ); | |
103 | void SetItem( const wxListItem &item ); | |
104 | void SetPosition( int x, int y ); | |
105 | void SetWidth( int w ); | |
106 | void SetFormat( int format ); | |
107 | void SetHeight( int h ); | |
108 | bool HasImage() const; | |
109 | bool HasText() const; | |
110 | bool IsHit( int x, int y ) const; | |
111 | void GetItem( wxListItem &item ); | |
112 | void GetText( wxString &s ); | |
113 | int GetImage() const; | |
114 | int GetWidth() const; | |
115 | int GetFormat() const; | |
f6bcfd97 | 116 | |
efbb7287 VZ |
117 | private: |
118 | DECLARE_DYNAMIC_CLASS(wxListHeaderData); | |
119 | }; | |
120 | ||
121 | //----------------------------------------------------------------------------- | |
122 | // wxListLineData (internal) | |
123 | //----------------------------------------------------------------------------- | |
124 | ||
125 | class WXDLLEXPORT wxListLineData : public wxObject | |
126 | { | |
127 | public: | |
128 | wxList m_items; | |
129 | wxRect m_bound_all; | |
130 | wxRect m_bound_label; | |
131 | wxRect m_bound_icon; | |
132 | wxRect m_bound_hilight; | |
133 | int m_mode; | |
134 | bool m_hilighted; | |
135 | wxBrush *m_hilightBrush; | |
136 | int m_spacing; | |
137 | wxListMainWindow *m_owner; | |
138 | ||
139 | void DoDraw( wxDC *dc, bool hilight, bool paintBG ); | |
140 | ||
141 | public: | |
142 | wxListLineData() {} | |
143 | wxListLineData( wxListMainWindow *owner, int mode, wxBrush *hilightBrush ); | |
144 | void CalculateSize( wxDC *dc, int spacing ); | |
145 | void SetPosition( wxDC *dc, int x, int y, int window_width ); | |
146 | void SetColumnPosition( int index, int x ); | |
147 | void GetSize( int &width, int &height ); | |
148 | void GetExtent( int &x, int &y, int &width, int &height ); | |
149 | void GetLabelExtent( int &x, int &y, int &width, int &height ); | |
150 | long IsHit( int x, int y ); | |
151 | void InitItems( int num ); | |
152 | void SetItem( int index, const wxListItem &info ); | |
153 | void GetItem( int index, wxListItem &info ); | |
154 | void GetText( int index, wxString &s ); | |
155 | void SetText( int index, const wxString s ); | |
156 | int GetImage( int index ); | |
157 | void GetRect( wxRect &rect ); | |
158 | void Hilight( bool on ); | |
159 | void ReverseHilight(); | |
160 | void DrawRubberBand( wxDC *dc, bool on ); | |
161 | void Draw( wxDC *dc ); | |
162 | bool IsInRect( int x, int y, const wxRect &rect ); | |
163 | bool IsHilighted(); | |
164 | void AssignRect( wxRect &dest, int x, int y, int width, int height ); | |
165 | void AssignRect( wxRect &dest, const wxRect &source ); | |
f6bcfd97 | 166 | |
efbb7287 VZ |
167 | private: |
168 | void SetAttributes(wxDC *dc, | |
169 | const wxListItemAttr *attr, | |
170 | const wxColour& colText, const wxFont& font, | |
171 | bool hilight); | |
172 | ||
173 | DECLARE_DYNAMIC_CLASS(wxListLineData); | |
174 | }; | |
175 | ||
f6bcfd97 BP |
176 | |
177 | WX_DECLARE_EXPORTED_OBJARRAY(wxListLineData, wxListLineDataArray); | |
178 | #include "wx/arrimpl.cpp" | |
179 | WX_DEFINE_OBJARRAY(wxListLineDataArray); | |
180 | ||
efbb7287 VZ |
181 | //----------------------------------------------------------------------------- |
182 | // wxListHeaderWindow (internal) | |
183 | //----------------------------------------------------------------------------- | |
184 | ||
185 | class WXDLLEXPORT wxListHeaderWindow : public wxWindow | |
186 | { | |
187 | protected: | |
188 | wxListMainWindow *m_owner; | |
189 | wxCursor *m_currentCursor; | |
190 | wxCursor *m_resizeCursor; | |
191 | bool m_isDragging; | |
f6bcfd97 BP |
192 | |
193 | // column being resized | |
194 | int m_column; | |
195 | ||
196 | // divider line position in logical (unscrolled) coords | |
197 | int m_currentX; | |
198 | ||
199 | // minimal position beyond which the divider line can't be dragged in | |
200 | // logical coords | |
201 | int m_minX; | |
efbb7287 VZ |
202 | |
203 | public: | |
204 | wxListHeaderWindow(); | |
f6bcfd97 BP |
205 | virtual ~wxListHeaderWindow(); |
206 | ||
207 | wxListHeaderWindow( wxWindow *win, | |
208 | wxWindowID id, | |
209 | wxListMainWindow *owner, | |
210 | const wxPoint &pos = wxDefaultPosition, | |
211 | const wxSize &size = wxDefaultSize, | |
212 | long style = 0, | |
213 | const wxString &name = "wxlistctrlcolumntitles" ); | |
214 | ||
efbb7287 | 215 | void DoDrawRect( wxDC *dc, int x, int y, int w, int h ); |
efbb7287 | 216 | void DrawCurrent(); |
f6bcfd97 BP |
217 | void AdjustDC(wxDC& dc); |
218 | ||
219 | void OnPaint( wxPaintEvent &event ); | |
efbb7287 VZ |
220 | void OnMouse( wxMouseEvent &event ); |
221 | void OnSetFocus( wxFocusEvent &event ); | |
222 | ||
f6bcfd97 BP |
223 | // needs refresh |
224 | bool m_dirty; | |
225 | ||
efbb7287 VZ |
226 | private: |
227 | DECLARE_DYNAMIC_CLASS(wxListHeaderWindow) | |
228 | DECLARE_EVENT_TABLE() | |
229 | }; | |
230 | ||
231 | //----------------------------------------------------------------------------- | |
232 | // wxListRenameTimer (internal) | |
233 | //----------------------------------------------------------------------------- | |
234 | ||
235 | class WXDLLEXPORT wxListRenameTimer: public wxTimer | |
236 | { | |
237 | private: | |
238 | wxListMainWindow *m_owner; | |
239 | ||
240 | public: | |
241 | wxListRenameTimer( wxListMainWindow *owner ); | |
242 | void Notify(); | |
243 | }; | |
244 | ||
245 | //----------------------------------------------------------------------------- | |
246 | // wxListTextCtrl (internal) | |
247 | //----------------------------------------------------------------------------- | |
248 | ||
249 | class WXDLLEXPORT wxListTextCtrl: public wxTextCtrl | |
250 | { | |
251 | private: | |
252 | bool *m_accept; | |
253 | wxString *m_res; | |
254 | wxListMainWindow *m_owner; | |
255 | wxString m_startValue; | |
256 | ||
257 | public: | |
258 | wxListTextCtrl() {} | |
259 | wxListTextCtrl( wxWindow *parent, const wxWindowID id, | |
260 | bool *accept, wxString *res, wxListMainWindow *owner, | |
261 | const wxString &value = "", | |
262 | const wxPoint &pos = wxDefaultPosition, const wxSize &size = wxDefaultSize, | |
263 | int style = 0, | |
264 | const wxValidator& validator = wxDefaultValidator, | |
809934d2 | 265 | const wxString &name = "listctrltextctrl" ); |
efbb7287 | 266 | void OnChar( wxKeyEvent &event ); |
c13cace1 | 267 | void OnKeyUp( wxKeyEvent &event ); |
efbb7287 VZ |
268 | void OnKillFocus( wxFocusEvent &event ); |
269 | ||
270 | private: | |
271 | DECLARE_DYNAMIC_CLASS(wxListTextCtrl); | |
272 | DECLARE_EVENT_TABLE() | |
273 | }; | |
274 | ||
275 | //----------------------------------------------------------------------------- | |
276 | // wxListMainWindow (internal) | |
277 | //----------------------------------------------------------------------------- | |
278 | ||
279 | class WXDLLEXPORT wxListMainWindow: public wxScrolledWindow | |
280 | { | |
281 | public: | |
282 | long m_mode; | |
f6bcfd97 | 283 | wxListLineDataArray m_lines; |
efbb7287 VZ |
284 | wxList m_columns; |
285 | wxListLineData *m_current; | |
286 | wxListLineData *m_currentEdit; | |
287 | int m_visibleLines; | |
288 | wxBrush *m_hilightBrush; | |
289 | wxColour *m_hilightColour; | |
290 | int m_xScroll,m_yScroll; | |
291 | bool m_dirty; | |
292 | wxImageList *m_small_image_list; | |
293 | wxImageList *m_normal_image_list; | |
294 | int m_small_spacing; | |
295 | int m_normal_spacing; | |
296 | bool m_hasFocus; | |
297 | bool m_usedKeys; | |
298 | bool m_lastOnSame; | |
299 | wxTimer *m_renameTimer; | |
300 | bool m_renameAccept; | |
301 | wxString m_renameRes; | |
302 | bool m_isCreated; | |
303 | int m_dragCount; | |
304 | wxPoint m_dragStart; | |
305 | ||
306 | // for double click logic | |
307 | wxListLineData *m_lineLastClicked, | |
308 | *m_lineBeforeLastClicked; | |
309 | ||
310 | public: | |
311 | wxListMainWindow(); | |
312 | wxListMainWindow( wxWindow *parent, wxWindowID id, | |
313 | const wxPoint &pos = wxDefaultPosition, const wxSize &size = wxDefaultSize, | |
809934d2 | 314 | long style = 0, const wxString &name = "listctrlmainwindow" ); |
efbb7287 VZ |
315 | ~wxListMainWindow(); |
316 | void RefreshLine( wxListLineData *line ); | |
317 | void OnPaint( wxPaintEvent &event ); | |
318 | void HilightAll( bool on ); | |
05a7f61d VZ |
319 | void SendNotify( wxListLineData *line, |
320 | wxEventType command, | |
321 | wxPoint point = wxDefaultPosition ); | |
efbb7287 VZ |
322 | void FocusLine( wxListLineData *line ); |
323 | void UnfocusLine( wxListLineData *line ); | |
324 | void SelectLine( wxListLineData *line ); | |
325 | void DeselectLine( wxListLineData *line ); | |
326 | void DeleteLine( wxListLineData *line ); | |
327 | ||
328 | void EditLabel( long item ); | |
329 | void Edit( long item ) { EditLabel(item); } // deprecated | |
330 | void OnRenameTimer(); | |
331 | void OnRenameAccept(); | |
332 | ||
333 | void OnMouse( wxMouseEvent &event ); | |
334 | void MoveToFocus(); | |
335 | void OnArrowChar( wxListLineData *newCurrent, bool shiftDown ); | |
336 | void OnChar( wxKeyEvent &event ); | |
337 | void OnKeyDown( wxKeyEvent &event ); | |
338 | void OnSetFocus( wxFocusEvent &event ); | |
339 | void OnKillFocus( wxFocusEvent &event ); | |
340 | void OnSize( wxSizeEvent &event ); | |
341 | void OnScroll(wxScrollWinEvent& event) ; | |
f6bcfd97 | 342 | |
efbb7287 VZ |
343 | void DrawImage( int index, wxDC *dc, int x, int y ); |
344 | void GetImageSize( int index, int &width, int &height ); | |
345 | int GetIndexOfLine( const wxListLineData *line ); | |
346 | int GetTextLength( wxString &s ); // should be const | |
347 | ||
348 | void SetImageList( wxImageList *imageList, int which ); | |
349 | void SetItemSpacing( int spacing, bool isSmall = FALSE ); | |
350 | int GetItemSpacing( bool isSmall = FALSE ); | |
351 | void SetColumn( int col, wxListItem &item ); | |
352 | void SetColumnWidth( int col, int width ); | |
353 | void GetColumn( int col, wxListItem &item ); | |
354 | int GetColumnWidth( int vol ); | |
355 | int GetColumnCount(); | |
356 | int GetCountPerPage(); | |
357 | void SetItem( wxListItem &item ); | |
358 | void GetItem( wxListItem &item ); | |
359 | void SetItemState( long item, long state, long stateMask ); | |
360 | int GetItemState( long item, long stateMask ); | |
361 | int GetItemCount(); | |
362 | void GetItemRect( long index, wxRect &rect ); | |
363 | bool GetItemPosition( long item, wxPoint& pos ); | |
364 | int GetSelectedItemCount(); | |
365 | void SetMode( long mode ); | |
366 | long GetMode() const; | |
367 | void CalculatePositions(); | |
368 | void RealizeChanges(); | |
369 | long GetNextItem( long item, int geometry, int state ); | |
370 | void DeleteItem( long index ); | |
371 | void DeleteAllItems(); | |
372 | void DeleteColumn( int col ); | |
373 | void DeleteEverything(); | |
374 | void EnsureVisible( long index ); | |
375 | long FindItem( long start, const wxString& str, bool partial = FALSE ); | |
376 | long FindItem( long start, long data); | |
377 | long HitTest( int x, int y, int &flags ); | |
378 | void InsertItem( wxListItem &item ); | |
379 | // void AddItem( wxListItem &item ); | |
380 | void InsertColumn( long col, wxListItem &item ); | |
381 | // void AddColumn( wxListItem &item ); | |
382 | void SortItems( wxListCtrlCompare fn, long data ); | |
383 | ||
384 | private: | |
385 | DECLARE_DYNAMIC_CLASS(wxListMainWindow); | |
386 | DECLARE_EVENT_TABLE() | |
387 | }; | |
388 | ||
389 | // ============================================================================ | |
390 | // implementation | |
391 | // ============================================================================ | |
392 | ||
c801d85f KB |
393 | //----------------------------------------------------------------------------- |
394 | // wxListItemData | |
395 | //----------------------------------------------------------------------------- | |
396 | ||
397 | IMPLEMENT_DYNAMIC_CLASS(wxListItemData,wxObject); | |
398 | ||
fd9811b1 | 399 | wxListItemData::wxListItemData() |
c801d85f | 400 | { |
92976ab6 RR |
401 | m_image = -1; |
402 | m_data = 0; | |
403 | m_xpos = 0; | |
404 | m_ypos = 0; | |
405 | m_width = 0; | |
406 | m_height = 0; | |
0530737d | 407 | m_attr = NULL; |
e1e955e1 | 408 | } |
c801d85f KB |
409 | |
410 | wxListItemData::wxListItemData( const wxListItem &info ) | |
411 | { | |
92976ab6 RR |
412 | m_image = -1; |
413 | m_data = 0; | |
0530737d VZ |
414 | m_attr = NULL; |
415 | ||
92976ab6 | 416 | SetItem( info ); |
e1e955e1 | 417 | } |
c801d85f KB |
418 | |
419 | void wxListItemData::SetItem( const wxListItem &info ) | |
420 | { | |
92976ab6 RR |
421 | if (info.m_mask & wxLIST_MASK_TEXT) m_text = info.m_text; |
422 | if (info.m_mask & wxLIST_MASK_IMAGE) m_image = info.m_image; | |
423 | if (info.m_mask & wxLIST_MASK_DATA) m_data = info.m_data; | |
0530737d VZ |
424 | |
425 | if ( info.HasAttributes() ) | |
426 | { | |
427 | if ( m_attr ) | |
428 | *m_attr = *info.GetAttributes(); | |
429 | else | |
430 | m_attr = new wxListItemAttr(*info.GetAttributes()); | |
431 | } | |
432 | ||
92976ab6 RR |
433 | m_xpos = 0; |
434 | m_ypos = 0; | |
435 | m_width = info.m_width; | |
436 | m_height = 0; | |
e1e955e1 | 437 | } |
c801d85f KB |
438 | |
439 | void wxListItemData::SetText( const wxString &s ) | |
440 | { | |
92976ab6 | 441 | m_text = s; |
e1e955e1 | 442 | } |
c801d85f | 443 | |
debe6624 | 444 | void wxListItemData::SetImage( int image ) |
c801d85f | 445 | { |
92976ab6 | 446 | m_image = image; |
e1e955e1 | 447 | } |
c801d85f | 448 | |
debe6624 | 449 | void wxListItemData::SetData( long data ) |
c801d85f | 450 | { |
92976ab6 | 451 | m_data = data; |
e1e955e1 | 452 | } |
c801d85f | 453 | |
debe6624 | 454 | void wxListItemData::SetPosition( int x, int y ) |
c801d85f | 455 | { |
92976ab6 RR |
456 | m_xpos = x; |
457 | m_ypos = y; | |
e1e955e1 | 458 | } |
c801d85f | 459 | |
1e6d9499 | 460 | void wxListItemData::SetSize( int width, int height ) |
c801d85f | 461 | { |
92976ab6 RR |
462 | if (width != -1) m_width = width; |
463 | if (height != -1) m_height = height; | |
e1e955e1 | 464 | } |
c801d85f | 465 | |
fd9811b1 | 466 | bool wxListItemData::HasImage() const |
c801d85f | 467 | { |
92976ab6 | 468 | return (m_image >= 0); |
e1e955e1 | 469 | } |
c801d85f | 470 | |
fd9811b1 | 471 | bool wxListItemData::HasText() const |
c801d85f | 472 | { |
92976ab6 | 473 | return (!m_text.IsNull()); |
e1e955e1 | 474 | } |
c801d85f | 475 | |
debe6624 | 476 | bool wxListItemData::IsHit( int x, int y ) const |
c801d85f | 477 | { |
92976ab6 | 478 | return ((x >= m_xpos) && (x <= m_xpos+m_width) && (y >= m_ypos) && (y <= m_ypos+m_height)); |
e1e955e1 | 479 | } |
c801d85f KB |
480 | |
481 | void wxListItemData::GetText( wxString &s ) | |
482 | { | |
92976ab6 | 483 | s = m_text; |
e1e955e1 | 484 | } |
c801d85f | 485 | |
fd9811b1 | 486 | int wxListItemData::GetX() const |
c801d85f | 487 | { |
92976ab6 | 488 | return m_xpos; |
e1e955e1 | 489 | } |
c801d85f | 490 | |
fd9811b1 | 491 | int wxListItemData::GetY() const |
c801d85f | 492 | { |
92976ab6 | 493 | return m_ypos; |
e1e955e1 | 494 | } |
c801d85f | 495 | |
fd9811b1 | 496 | int wxListItemData::GetWidth() const |
c801d85f | 497 | { |
92976ab6 | 498 | return m_width; |
e1e955e1 | 499 | } |
c801d85f | 500 | |
fd9811b1 | 501 | int wxListItemData::GetHeight() const |
c801d85f | 502 | { |
92976ab6 | 503 | return m_height; |
e1e955e1 | 504 | } |
c801d85f | 505 | |
fd9811b1 | 506 | int wxListItemData::GetImage() const |
c801d85f | 507 | { |
92976ab6 | 508 | return m_image; |
e1e955e1 | 509 | } |
c801d85f | 510 | |
0530737d | 511 | void wxListItemData::GetItem( wxListItem &info ) const |
c801d85f | 512 | { |
92976ab6 RR |
513 | info.m_text = m_text; |
514 | info.m_image = m_image; | |
515 | info.m_data = m_data; | |
c801d85f | 516 | |
0530737d VZ |
517 | if ( m_attr ) |
518 | { | |
519 | if ( m_attr->HasTextColour() ) | |
520 | info.SetTextColour(m_attr->GetTextColour()); | |
521 | if ( m_attr->HasBackgroundColour() ) | |
522 | info.SetBackgroundColour(m_attr->GetBackgroundColour()); | |
523 | if ( m_attr->HasFont() ) | |
524 | info.SetFont(m_attr->GetFont()); | |
525 | } | |
e1e955e1 | 526 | } |
c801d85f KB |
527 | |
528 | //----------------------------------------------------------------------------- | |
529 | // wxListHeaderData | |
530 | //----------------------------------------------------------------------------- | |
531 | ||
532 | IMPLEMENT_DYNAMIC_CLASS(wxListHeaderData,wxObject); | |
533 | ||
fd9811b1 | 534 | wxListHeaderData::wxListHeaderData() |
c801d85f | 535 | { |
92976ab6 RR |
536 | m_mask = 0; |
537 | m_image = 0; | |
538 | m_format = 0; | |
539 | m_width = 0; | |
540 | m_xpos = 0; | |
541 | m_ypos = 0; | |
542 | m_height = 0; | |
e1e955e1 | 543 | } |
c801d85f KB |
544 | |
545 | wxListHeaderData::wxListHeaderData( const wxListItem &item ) | |
546 | { | |
92976ab6 RR |
547 | SetItem( item ); |
548 | m_xpos = 0; | |
549 | m_ypos = 0; | |
550 | m_height = 0; | |
e1e955e1 | 551 | } |
c801d85f KB |
552 | |
553 | void wxListHeaderData::SetItem( const wxListItem &item ) | |
554 | { | |
92976ab6 RR |
555 | m_mask = item.m_mask; |
556 | m_text = item.m_text; | |
557 | m_image = item.m_image; | |
558 | m_format = item.m_format; | |
559 | m_width = item.m_width; | |
560 | if (m_width < 0) m_width = 80; | |
561 | if (m_width < 6) m_width = 6; | |
e1e955e1 | 562 | } |
c801d85f | 563 | |
debe6624 | 564 | void wxListHeaderData::SetPosition( int x, int y ) |
c801d85f | 565 | { |
92976ab6 RR |
566 | m_xpos = x; |
567 | m_ypos = y; | |
e1e955e1 | 568 | } |
c801d85f | 569 | |
debe6624 | 570 | void wxListHeaderData::SetHeight( int h ) |
c801d85f | 571 | { |
92976ab6 | 572 | m_height = h; |
e1e955e1 | 573 | } |
c801d85f | 574 | |
debe6624 | 575 | void wxListHeaderData::SetWidth( int w ) |
c801d85f | 576 | { |
92976ab6 RR |
577 | m_width = w; |
578 | if (m_width < 0) m_width = 80; | |
579 | if (m_width < 6) m_width = 6; | |
e1e955e1 | 580 | } |
c801d85f | 581 | |
debe6624 | 582 | void wxListHeaderData::SetFormat( int format ) |
c801d85f | 583 | { |
92976ab6 | 584 | m_format = format; |
e1e955e1 | 585 | } |
c801d85f | 586 | |
fd9811b1 | 587 | bool wxListHeaderData::HasImage() const |
c801d85f | 588 | { |
92976ab6 | 589 | return (m_image != 0); |
e1e955e1 | 590 | } |
c801d85f | 591 | |
fd9811b1 | 592 | bool wxListHeaderData::HasText() const |
c801d85f | 593 | { |
92976ab6 | 594 | return (m_text.Length() > 0); |
e1e955e1 | 595 | } |
c801d85f KB |
596 | |
597 | bool wxListHeaderData::IsHit( int x, int y ) const | |
598 | { | |
92976ab6 | 599 | return ((x >= m_xpos) && (x <= m_xpos+m_width) && (y >= m_ypos) && (y <= m_ypos+m_height)); |
e1e955e1 | 600 | } |
c801d85f KB |
601 | |
602 | void wxListHeaderData::GetItem( wxListItem &item ) | |
603 | { | |
92976ab6 RR |
604 | item.m_mask = m_mask; |
605 | item.m_text = m_text; | |
606 | item.m_image = m_image; | |
607 | item.m_format = m_format; | |
608 | item.m_width = m_width; | |
e1e955e1 | 609 | } |
c801d85f KB |
610 | |
611 | void wxListHeaderData::GetText( wxString &s ) | |
612 | { | |
92976ab6 | 613 | s = m_text; |
e1e955e1 | 614 | } |
c801d85f | 615 | |
fd9811b1 | 616 | int wxListHeaderData::GetImage() const |
c801d85f | 617 | { |
92976ab6 | 618 | return m_image; |
e1e955e1 | 619 | } |
c801d85f | 620 | |
fd9811b1 | 621 | int wxListHeaderData::GetWidth() const |
c801d85f | 622 | { |
92976ab6 | 623 | return m_width; |
e1e955e1 | 624 | } |
c801d85f | 625 | |
fd9811b1 | 626 | int wxListHeaderData::GetFormat() const |
c801d85f | 627 | { |
92976ab6 | 628 | return m_format; |
e1e955e1 | 629 | } |
c801d85f KB |
630 | |
631 | //----------------------------------------------------------------------------- | |
632 | // wxListLineData | |
633 | //----------------------------------------------------------------------------- | |
634 | ||
635 | IMPLEMENT_DYNAMIC_CLASS(wxListLineData,wxObject); | |
636 | ||
debe6624 | 637 | wxListLineData::wxListLineData( wxListMainWindow *owner, int mode, wxBrush *hilightBrush ) |
c801d85f | 638 | { |
92976ab6 RR |
639 | m_mode = mode; |
640 | m_hilighted = FALSE; | |
641 | m_owner = owner; | |
642 | m_hilightBrush = hilightBrush; | |
643 | m_items.DeleteContents( TRUE ); | |
644 | m_spacing = 0; | |
e1e955e1 | 645 | } |
c801d85f | 646 | |
1e6d9499 | 647 | void wxListLineData::CalculateSize( wxDC *dc, int spacing ) |
c801d85f | 648 | { |
92976ab6 RR |
649 | m_spacing = spacing; |
650 | switch (m_mode) | |
c801d85f | 651 | { |
92976ab6 RR |
652 | case wxLC_ICON: |
653 | { | |
654 | m_bound_all.width = m_spacing; | |
92976ab6 RR |
655 | wxNode *node = m_items.First(); |
656 | if (node) | |
657 | { | |
658 | wxListItemData *item = (wxListItemData*)node->Data(); | |
0530737d | 659 | wxString s = item->GetText(); |
5d25c050 | 660 | if (s.IsEmpty()) s = wxT("H"); |
13111b2a | 661 | wxCoord lw,lh; |
92976ab6 | 662 | dc->GetTextExtent( s, &lw, &lh ); |
5d25c050 RR |
663 | if (lh < 15) lh = 15; |
664 | lw += 4; | |
665 | lh += 3; | |
f6bcfd97 | 666 | |
5d25c050 | 667 | m_bound_all.height = m_spacing+lh; |
92976ab6 | 668 | if (lw > m_spacing) m_bound_all.width = lw; |
5d25c050 RR |
669 | m_bound_label.width = lw; |
670 | m_bound_label.height = lh; | |
f6bcfd97 | 671 | |
5d25c050 RR |
672 | if (item->HasImage()) |
673 | { | |
674 | int w = 0; | |
675 | int h = 0; | |
676 | m_owner->GetImageSize( item->GetImage(), w, h ); | |
677 | m_bound_icon.width = w + 8; | |
678 | m_bound_icon.height = h + 8; | |
f6bcfd97 BP |
679 | |
680 | if ( m_bound_icon.width > m_bound_all.width ) | |
681 | m_bound_all.width = m_bound_icon.width; | |
682 | if ( h + lh > m_bound_all.height - 4 ) | |
683 | m_bound_all.height = h + lh + 4; | |
5d25c050 | 684 | } |
f6bcfd97 | 685 | |
5d25c050 RR |
686 | if (!item->HasText()) |
687 | { | |
688 | m_bound_hilight.width = m_bound_icon.width; | |
689 | m_bound_hilight.height = m_bound_icon.height; | |
690 | } | |
691 | else | |
692 | { | |
693 | m_bound_hilight.width = m_bound_label.width; | |
694 | m_bound_hilight.height = m_bound_label.height; | |
695 | } | |
92976ab6 RR |
696 | } |
697 | break; | |
698 | } | |
699 | case wxLC_LIST: | |
700 | { | |
701 | wxNode *node = m_items.First(); | |
702 | if (node) | |
703 | { | |
704 | wxListItemData *item = (wxListItemData*)node->Data(); | |
f6bcfd97 | 705 | |
0530737d | 706 | wxString s = item->GetText(); |
5d25c050 | 707 | if (s.IsEmpty()) s = wxT("H"); |
13111b2a | 708 | wxCoord lw,lh; |
92976ab6 | 709 | dc->GetTextExtent( s, &lw, &lh ); |
5d25c050 RR |
710 | if (lh < 15) lh = 15; |
711 | lw += 4; | |
712 | lh += 3; | |
713 | m_bound_label.width = lw; | |
714 | m_bound_label.height = lh; | |
f6bcfd97 | 715 | |
92976ab6 RR |
716 | m_bound_all.width = lw; |
717 | m_bound_all.height = lh; | |
f6bcfd97 | 718 | |
0b855868 RR |
719 | if (item->HasImage()) |
720 | { | |
5dd26b08 JS |
721 | int w = 0; |
722 | int h = 0; | |
0b855868 | 723 | m_owner->GetImageSize( item->GetImage(), w, h ); |
5d25c050 RR |
724 | m_bound_icon.width = w; |
725 | m_bound_icon.height = h; | |
f6bcfd97 | 726 | |
bffa1c77 VZ |
727 | m_bound_all.width += 4 + w; |
728 | if (h > m_bound_all.height) m_bound_all.height = h; | |
729 | } | |
f6bcfd97 | 730 | |
5d25c050 RR |
731 | m_bound_hilight.width = m_bound_all.width; |
732 | m_bound_hilight.height = m_bound_all.height; | |
92976ab6 RR |
733 | } |
734 | break; | |
735 | } | |
736 | case wxLC_REPORT: | |
737 | { | |
738 | m_bound_all.width = 0; | |
739 | m_bound_all.height = 0; | |
740 | wxNode *node = m_items.First(); | |
efad36b8 RR |
741 | if (node) |
742 | { | |
743 | wxListItemData *item = (wxListItemData*)node->Data(); | |
744 | if (item->HasImage()) | |
745 | { | |
746 | int w = 0; | |
747 | int h = 0; | |
748 | m_owner->GetImageSize( item->GetImage(), w, h ); | |
749 | m_bound_icon.width = w; | |
750 | m_bound_icon.height = h; | |
751 | } | |
752 | else | |
753 | { | |
754 | m_bound_icon.width = 0; | |
755 | m_bound_icon.height = 0; | |
756 | } | |
757 | } | |
92976ab6 RR |
758 | while (node) |
759 | { | |
760 | wxListItemData *item = (wxListItemData*)node->Data(); | |
5d25c050 RR |
761 | wxString s = item->GetText(); |
762 | if (s.IsEmpty()) s = wxT("H"); | |
13111b2a | 763 | wxCoord lw,lh; |
7c74e7fe | 764 | dc->GetTextExtent( s, &lw, &lh ); |
40c70187 | 765 | if (lh < 15) lh = 15; |
5d25c050 RR |
766 | lw += 4; |
767 | lh += 3; | |
f6bcfd97 | 768 | |
92976ab6 | 769 | item->SetSize( item->GetWidth(), lh ); |
7c74e7fe | 770 | m_bound_all.width += lw; |
92976ab6 RR |
771 | m_bound_all.height = lh; |
772 | node = node->Next(); | |
773 | } | |
d7ace8a9 VS |
774 | m_bound_label.width = m_bound_all.width; |
775 | m_bound_label.height = m_bound_all.height; | |
92976ab6 RR |
776 | break; |
777 | } | |
e1e955e1 | 778 | } |
e1e955e1 | 779 | } |
c801d85f | 780 | |
bc1dcfc1 VZ |
781 | void wxListLineData::SetPosition( wxDC * WXUNUSED(dc), |
782 | int x, int y, int window_width ) | |
c801d85f | 783 | { |
0b855868 RR |
784 | m_bound_all.x = x; |
785 | m_bound_all.y = y; | |
786 | switch (m_mode) | |
787 | { | |
788 | case wxLC_ICON: | |
c801d85f | 789 | { |
0b855868 RR |
790 | wxNode *node = m_items.First(); |
791 | if (node) | |
792 | { | |
793 | wxListItemData *item = (wxListItemData*)node->Data(); | |
794 | if (item->HasImage()) | |
795 | { | |
f6bcfd97 BP |
796 | m_bound_icon.x = m_bound_all.x + 4 |
797 | + (m_spacing - m_bound_icon.width)/2; | |
5d25c050 | 798 | m_bound_icon.y = m_bound_all.y + 4; |
0b855868 RR |
799 | } |
800 | if (item->HasText()) | |
801 | { | |
0b855868 | 802 | if (m_bound_all.width > m_spacing) |
5d25c050 | 803 | m_bound_label.x = m_bound_all.x + 2; |
0b855868 | 804 | else |
5d25c050 RR |
805 | m_bound_label.x = m_bound_all.x + 2 + (m_spacing/2) - (m_bound_label.width/2); |
806 | m_bound_label.y = m_bound_all.y + m_bound_all.height + 2 - m_bound_label.height; | |
807 | m_bound_hilight.x = m_bound_label.x - 2; | |
808 | m_bound_hilight.y = m_bound_label.y - 2; | |
809 | } | |
810 | else | |
811 | { | |
812 | m_bound_hilight.x = m_bound_icon.x - 4; | |
813 | m_bound_hilight.y = m_bound_icon.y - 4; | |
0b855868 RR |
814 | } |
815 | } | |
816 | break; | |
e1e955e1 | 817 | } |
0b855868 | 818 | case wxLC_LIST: |
c801d85f | 819 | { |
5d25c050 RR |
820 | m_bound_hilight.x = m_bound_all.x; |
821 | m_bound_hilight.y = m_bound_all.y; | |
822 | m_bound_label.y = m_bound_all.y + 2; | |
0b855868 RR |
823 | wxNode *node = m_items.First(); |
824 | if (node) | |
825 | { | |
826 | wxListItemData *item = (wxListItemData*)node->Data(); | |
827 | if (item->HasImage()) | |
bffa1c77 | 828 | { |
0b855868 RR |
829 | m_bound_icon.x = m_bound_all.x + 2; |
830 | m_bound_icon.y = m_bound_all.y + 2; | |
5d25c050 RR |
831 | m_bound_label.x = m_bound_all.x + 6 + m_bound_icon.width; |
832 | } | |
833 | else | |
834 | { | |
835 | m_bound_label.x = m_bound_all.x + 2; | |
bffa1c77 VZ |
836 | } |
837 | } | |
0b855868 RR |
838 | break; |
839 | } | |
840 | case wxLC_REPORT: | |
841 | { | |
0b855868 | 842 | m_bound_all.x = 0; |
0b855868 RR |
843 | m_bound_all.width = window_width; |
844 | AssignRect( m_bound_hilight, m_bound_all ); | |
5d25c050 RR |
845 | m_bound_label.x = m_bound_all.x + 2; |
846 | m_bound_label.y = m_bound_all.y + 2; | |
0b855868 RR |
847 | wxNode *node = m_items.First(); |
848 | if (node) | |
849 | { | |
850 | wxListItemData *item = (wxListItemData*)node->Data(); | |
bffa1c77 VZ |
851 | if (item->HasImage()) |
852 | { | |
0b855868 RR |
853 | m_bound_icon.x = m_bound_all.x + 2; |
854 | m_bound_icon.y = m_bound_all.y + 2; | |
5d25c050 | 855 | m_bound_label.x += 4 + m_bound_icon.width; |
bffa1c77 VZ |
856 | } |
857 | } | |
0b855868 | 858 | break; |
e1e955e1 | 859 | } |
e1e955e1 | 860 | } |
e1e955e1 | 861 | } |
c801d85f | 862 | |
debe6624 | 863 | void wxListLineData::SetColumnPosition( int index, int x ) |
c801d85f | 864 | { |
6f2a55e3 | 865 | wxNode *node = m_items.Nth( (size_t)index ); |
92976ab6 RR |
866 | if (node) |
867 | { | |
868 | wxListItemData *item = (wxListItemData*)node->Data(); | |
869 | item->SetPosition( x, m_bound_all.y+1 ); | |
870 | } | |
e1e955e1 | 871 | } |
c801d85f KB |
872 | |
873 | void wxListLineData::GetSize( int &width, int &height ) | |
874 | { | |
139adb6a RR |
875 | width = m_bound_all.width; |
876 | height = m_bound_all.height; | |
e1e955e1 | 877 | } |
c801d85f KB |
878 | |
879 | void wxListLineData::GetExtent( int &x, int &y, int &width, int &height ) | |
880 | { | |
139adb6a RR |
881 | x = m_bound_all.x; |
882 | y = m_bound_all.y; | |
883 | width = m_bound_all.width; | |
884 | height = m_bound_all.height; | |
e1e955e1 | 885 | } |
c801d85f KB |
886 | |
887 | void wxListLineData::GetLabelExtent( int &x, int &y, int &width, int &height ) | |
888 | { | |
139adb6a RR |
889 | x = m_bound_label.x; |
890 | y = m_bound_label.y; | |
891 | width = m_bound_label.width; | |
892 | height = m_bound_label.height; | |
e1e955e1 | 893 | } |
c801d85f | 894 | |
0a240683 | 895 | void wxListLineData::GetRect( wxRect &rect ) |
c801d85f | 896 | { |
139adb6a | 897 | AssignRect( rect, m_bound_all ); |
e1e955e1 | 898 | } |
c801d85f | 899 | |
debe6624 | 900 | long wxListLineData::IsHit( int x, int y ) |
c801d85f | 901 | { |
139adb6a RR |
902 | wxNode *node = m_items.First(); |
903 | if (node) | |
904 | { | |
905 | wxListItemData *item = (wxListItemData*)node->Data(); | |
906 | if (item->HasImage() && IsInRect( x, y, m_bound_icon )) return wxLIST_HITTEST_ONITEMICON; | |
907 | if (item->HasText() && IsInRect( x, y, m_bound_label )) return wxLIST_HITTEST_ONITEMLABEL; | |
908 | // if (!(item->HasImage() || item->HasText())) return 0; | |
909 | } | |
910 | // if there is no icon or text = empty | |
911 | if (IsInRect( x, y, m_bound_all )) return wxLIST_HITTEST_ONITEMICON; | |
912 | return 0; | |
e1e955e1 | 913 | } |
c801d85f | 914 | |
debe6624 | 915 | void wxListLineData::InitItems( int num ) |
c801d85f | 916 | { |
139adb6a | 917 | for (int i = 0; i < num; i++) m_items.Append( new wxListItemData() ); |
e1e955e1 | 918 | } |
c801d85f | 919 | |
debe6624 | 920 | void wxListLineData::SetItem( int index, const wxListItem &info ) |
c801d85f | 921 | { |
139adb6a RR |
922 | wxNode *node = m_items.Nth( index ); |
923 | if (node) | |
924 | { | |
925 | wxListItemData *item = (wxListItemData*)node->Data(); | |
926 | item->SetItem( info ); | |
927 | } | |
e1e955e1 | 928 | } |
c801d85f | 929 | |
1e6d9499 | 930 | void wxListLineData::GetItem( int index, wxListItem &info ) |
c801d85f | 931 | { |
139adb6a RR |
932 | int i = index; |
933 | wxNode *node = m_items.Nth( i ); | |
934 | if (node) | |
935 | { | |
936 | wxListItemData *item = (wxListItemData*)node->Data(); | |
937 | item->GetItem( info ); | |
938 | } | |
e1e955e1 | 939 | } |
c801d85f | 940 | |
debe6624 | 941 | void wxListLineData::GetText( int index, wxString &s ) |
c801d85f | 942 | { |
139adb6a RR |
943 | int i = index; |
944 | wxNode *node = m_items.Nth( i ); | |
945 | s = ""; | |
946 | if (node) | |
947 | { | |
948 | wxListItemData *item = (wxListItemData*)node->Data(); | |
949 | item->GetText( s ); | |
950 | } | |
e1e955e1 | 951 | } |
c801d85f | 952 | |
debe6624 | 953 | void wxListLineData::SetText( int index, const wxString s ) |
c801d85f | 954 | { |
139adb6a RR |
955 | int i = index; |
956 | wxNode *node = m_items.Nth( i ); | |
957 | if (node) | |
958 | { | |
959 | wxListItemData *item = (wxListItemData*)node->Data(); | |
960 | item->SetText( s ); | |
961 | } | |
e1e955e1 | 962 | } |
c801d85f | 963 | |
debe6624 | 964 | int wxListLineData::GetImage( int index ) |
c801d85f | 965 | { |
139adb6a RR |
966 | int i = index; |
967 | wxNode *node = m_items.Nth( i ); | |
968 | if (node) | |
969 | { | |
970 | wxListItemData *item = (wxListItemData*)node->Data(); | |
971 | return item->GetImage(); | |
972 | } | |
973 | return -1; | |
e1e955e1 | 974 | } |
c801d85f | 975 | |
0530737d VZ |
976 | void wxListLineData::SetAttributes(wxDC *dc, |
977 | const wxListItemAttr *attr, | |
978 | const wxColour& colText, | |
470caaf9 VZ |
979 | const wxFont& font, |
980 | bool hilight) | |
0530737d | 981 | { |
470caaf9 VZ |
982 | // don't use foregroud colour for drawing highlighted items - this might |
983 | // make them completely invisible (and there is no way to do bit | |
984 | // arithmetics on wxColour, unfortunately) | |
985 | if ( !hilight && attr && attr->HasTextColour() ) | |
0530737d VZ |
986 | { |
987 | dc->SetTextForeground(attr->GetTextColour()); | |
988 | } | |
989 | else | |
990 | { | |
991 | dc->SetTextForeground(colText); | |
992 | } | |
993 | ||
994 | if ( attr && attr->HasFont() ) | |
995 | { | |
996 | dc->SetFont(attr->GetFont()); | |
997 | } | |
998 | else | |
999 | { | |
1000 | dc->SetFont(font); | |
1001 | } | |
1002 | } | |
1003 | ||
1e6d9499 | 1004 | void wxListLineData::DoDraw( wxDC *dc, bool hilight, bool paintBG ) |
c801d85f | 1005 | { |
e06b9569 JS |
1006 | int dev_x = 0; |
1007 | int dev_y = 0; | |
3d2d8da1 RR |
1008 | m_owner->CalcScrolledPosition( m_bound_all.x, m_bound_all.y, &dev_x, &dev_y ); |
1009 | wxCoord dev_w = m_bound_all.width; | |
1010 | wxCoord dev_h = m_bound_all.height; | |
004fd0c8 | 1011 | |
139adb6a | 1012 | if (!m_owner->IsExposed( dev_x, dev_y, dev_w, dev_h )) |
139adb6a | 1013 | return; |
bd8289c1 | 1014 | |
0530737d VZ |
1015 | wxWindow *listctrl = m_owner->GetParent(); |
1016 | ||
1017 | // default foreground colour | |
1018 | wxColour colText; | |
1019 | if ( hilight ) | |
1020 | { | |
1021 | colText = wxSystemSettings::GetSystemColour( wxSYS_COLOUR_HIGHLIGHTTEXT ); | |
1022 | } | |
1023 | else | |
1024 | { | |
1025 | colText = listctrl->GetForegroundColour(); | |
1026 | } | |
1027 | ||
1028 | // default font | |
1029 | wxFont font = listctrl->GetFont(); | |
1030 | ||
1031 | // VZ: currently we set the colours/fonts only once, but like this (i.e. | |
1032 | // using SetAttributes() inside the loop), it will be trivial to | |
1033 | // customize the subitems (in report mode) too. | |
1034 | wxListItemData *item = (wxListItemData*)m_items.First()->Data(); | |
1035 | wxListItemAttr *attr = item->GetAttributes(); | |
470caaf9 | 1036 | SetAttributes(dc, attr, colText, font, hilight); |
0530737d VZ |
1037 | |
1038 | bool hasBgCol = attr && attr->HasBackgroundColour(); | |
1039 | if ( paintBG || hasBgCol ) | |
c801d85f | 1040 | { |
63852e78 RR |
1041 | if (hilight) |
1042 | { | |
1043 | dc->SetBrush( * m_hilightBrush ); | |
63852e78 RR |
1044 | } |
1045 | else | |
1046 | { | |
0530737d VZ |
1047 | if ( hasBgCol ) |
1048 | dc->SetBrush(wxBrush(attr->GetBackgroundColour(), wxSOLID)); | |
1049 | else | |
1050 | dc->SetBrush( * wxWHITE_BRUSH ); | |
63852e78 | 1051 | } |
0530737d VZ |
1052 | |
1053 | dc->SetPen( * wxTRANSPARENT_PEN ); | |
63852e78 RR |
1054 | dc->DrawRectangle( m_bound_hilight.x, m_bound_hilight.y, |
1055 | m_bound_hilight.width, m_bound_hilight.height ); | |
e1e955e1 | 1056 | } |
004fd0c8 | 1057 | |
63852e78 | 1058 | if (m_mode == wxLC_REPORT) |
c801d85f | 1059 | { |
63852e78 RR |
1060 | wxNode *node = m_items.First(); |
1061 | while (node) | |
1062 | { | |
1063 | wxListItemData *item = (wxListItemData*)node->Data(); | |
63852e78 RR |
1064 | int x = item->GetX(); |
1065 | if (item->HasImage()) | |
1066 | { | |
1067 | int y = 0; | |
1068 | m_owner->DrawImage( item->GetImage(), dc, x, item->GetY() ); | |
1069 | m_owner->GetImageSize( item->GetImage(), x, y ); | |
1070 | x += item->GetX() + 5; | |
1071 | } | |
40c70187 | 1072 | dc->SetClippingRegion( item->GetX(), item->GetY(), item->GetWidth()-3, item->GetHeight() ); |
63852e78 RR |
1073 | if (item->HasText()) |
1074 | { | |
40c70187 | 1075 | dc->DrawText( item->GetText(), x, item->GetY()+1 ); |
63852e78 RR |
1076 | } |
1077 | dc->DestroyClippingRegion(); | |
1078 | node = node->Next(); | |
1079 | } | |
e1e955e1 | 1080 | } |
63852e78 | 1081 | else |
c801d85f | 1082 | { |
63852e78 RR |
1083 | wxNode *node = m_items.First(); |
1084 | if (node) | |
1085 | { | |
1086 | wxListItemData *item = (wxListItemData*)node->Data(); | |
1087 | if (item->HasImage()) | |
1088 | { | |
1089 | m_owner->DrawImage( item->GetImage(), dc, m_bound_icon.x, m_bound_icon.y ); | |
1090 | } | |
1091 | if (item->HasText()) | |
1092 | { | |
0530737d | 1093 | dc->DrawText( item->GetText(), m_bound_label.x, m_bound_label.y ); |
63852e78 RR |
1094 | } |
1095 | } | |
e1e955e1 | 1096 | } |
e1e955e1 | 1097 | } |
c801d85f | 1098 | |
debe6624 | 1099 | void wxListLineData::Hilight( bool on ) |
c801d85f | 1100 | { |
63852e78 | 1101 | if (on == m_hilighted) return; |
6e228e42 | 1102 | m_hilighted = on; |
63852e78 RR |
1103 | if (on) |
1104 | m_owner->SelectLine( this ); | |
1105 | else | |
1106 | m_owner->DeselectLine( this ); | |
e1e955e1 | 1107 | } |
c801d85f KB |
1108 | |
1109 | void wxListLineData::ReverseHilight( void ) | |
1110 | { | |
63852e78 RR |
1111 | m_hilighted = !m_hilighted; |
1112 | if (m_hilighted) | |
1113 | m_owner->SelectLine( this ); | |
1114 | else | |
1115 | m_owner->DeselectLine( this ); | |
e1e955e1 | 1116 | } |
c801d85f | 1117 | |
1e6d9499 | 1118 | void wxListLineData::DrawRubberBand( wxDC *dc, bool on ) |
c801d85f | 1119 | { |
63852e78 RR |
1120 | if (on) |
1121 | { | |
1122 | dc->SetPen( * wxBLACK_PEN ); | |
1123 | dc->SetBrush( * wxTRANSPARENT_BRUSH ); | |
1124 | dc->DrawRectangle( m_bound_hilight.x, m_bound_hilight.y, | |
1125 | m_bound_hilight.width, m_bound_hilight.height ); | |
1126 | } | |
e1e955e1 | 1127 | } |
c801d85f | 1128 | |
1e6d9499 | 1129 | void wxListLineData::Draw( wxDC *dc ) |
c801d85f | 1130 | { |
63852e78 | 1131 | DoDraw( dc, m_hilighted, m_hilighted ); |
e1e955e1 | 1132 | } |
c801d85f | 1133 | |
0a240683 | 1134 | bool wxListLineData::IsInRect( int x, int y, const wxRect &rect ) |
c801d85f | 1135 | { |
004fd0c8 | 1136 | return ((x >= rect.x) && (x <= rect.x+rect.width) && |
63852e78 | 1137 | (y >= rect.y) && (y <= rect.y+rect.height)); |
e1e955e1 | 1138 | } |
c801d85f KB |
1139 | |
1140 | bool wxListLineData::IsHilighted( void ) | |
1141 | { | |
63852e78 | 1142 | return m_hilighted; |
e1e955e1 | 1143 | } |
c801d85f | 1144 | |
0a240683 | 1145 | void wxListLineData::AssignRect( wxRect &dest, int x, int y, int width, int height ) |
c801d85f | 1146 | { |
63852e78 RR |
1147 | dest.x = x; |
1148 | dest.y = y; | |
1149 | dest.width = width; | |
1150 | dest.height = height; | |
e1e955e1 | 1151 | } |
c801d85f | 1152 | |
0a240683 | 1153 | void wxListLineData::AssignRect( wxRect &dest, const wxRect &source ) |
c801d85f | 1154 | { |
63852e78 RR |
1155 | dest.x = source.x; |
1156 | dest.y = source.y; | |
1157 | dest.width = source.width; | |
1158 | dest.height = source.height; | |
e1e955e1 | 1159 | } |
c801d85f KB |
1160 | |
1161 | //----------------------------------------------------------------------------- | |
1162 | // wxListHeaderWindow | |
1163 | //----------------------------------------------------------------------------- | |
1164 | ||
1165 | IMPLEMENT_DYNAMIC_CLASS(wxListHeaderWindow,wxWindow); | |
1166 | ||
1167 | BEGIN_EVENT_TABLE(wxListHeaderWindow,wxWindow) | |
63852e78 RR |
1168 | EVT_PAINT (wxListHeaderWindow::OnPaint) |
1169 | EVT_MOUSE_EVENTS (wxListHeaderWindow::OnMouse) | |
1170 | EVT_SET_FOCUS (wxListHeaderWindow::OnSetFocus) | |
c801d85f KB |
1171 | END_EVENT_TABLE() |
1172 | ||
1173 | wxListHeaderWindow::wxListHeaderWindow( void ) | |
1174 | { | |
63852e78 RR |
1175 | m_owner = (wxListMainWindow *) NULL; |
1176 | m_currentCursor = (wxCursor *) NULL; | |
1177 | m_resizeCursor = (wxCursor *) NULL; | |
cfb50f14 | 1178 | m_isDragging = FALSE; |
e1e955e1 | 1179 | } |
c801d85f | 1180 | |
bd8289c1 | 1181 | wxListHeaderWindow::wxListHeaderWindow( wxWindow *win, wxWindowID id, wxListMainWindow *owner, |
debe6624 JS |
1182 | const wxPoint &pos, const wxSize &size, |
1183 | long style, const wxString &name ) : | |
c801d85f KB |
1184 | wxWindow( win, id, pos, size, style, name ) |
1185 | { | |
63852e78 | 1186 | m_owner = owner; |
c801d85f | 1187 | // m_currentCursor = wxSTANDARD_CURSOR; |
63852e78 RR |
1188 | m_currentCursor = (wxCursor *) NULL; |
1189 | m_resizeCursor = new wxCursor( wxCURSOR_SIZEWE ); | |
cfb50f14 | 1190 | m_isDragging = FALSE; |
f6bcfd97 BP |
1191 | m_dirty = FALSE; |
1192 | ||
cfb50f14 | 1193 | SetBackgroundColour( wxSystemSettings::GetSystemColour( wxSYS_COLOUR_BTNFACE ) ); |
e1e955e1 | 1194 | } |
c801d85f | 1195 | |
a367b9b3 JS |
1196 | wxListHeaderWindow::~wxListHeaderWindow( void ) |
1197 | { | |
63852e78 | 1198 | delete m_resizeCursor; |
a367b9b3 JS |
1199 | } |
1200 | ||
1e6d9499 | 1201 | void wxListHeaderWindow::DoDrawRect( wxDC *dc, int x, int y, int w, int h ) |
c801d85f | 1202 | { |
3fb435df RR |
1203 | #ifdef __WXGTK__ |
1204 | GtkStateType state = GTK_STATE_NORMAL; | |
1205 | if (!m_parent->IsEnabled()) state = GTK_STATE_INSENSITIVE; | |
1206 | ||
1207 | x = dc->XLOG2DEV( x ); | |
1208 | ||
05a7f61d VZ |
1209 | gtk_paint_box (m_wxwindow->style, GTK_PIZZA(m_wxwindow)->bin_window, state, GTK_SHADOW_OUT, |
1210 | (GdkRectangle*) NULL, m_wxwindow, "button", x-1, y-1, w+2, h+2); | |
3fb435df | 1211 | #else |
63852e78 | 1212 | const int m_corner = 1; |
c801d85f | 1213 | |
63852e78 | 1214 | dc->SetBrush( *wxTRANSPARENT_BRUSH ); |
c801d85f | 1215 | |
63852e78 RR |
1216 | dc->SetPen( *wxBLACK_PEN ); |
1217 | dc->DrawLine( x+w-m_corner+1, y, x+w, y+h ); // right (outer) | |
17867d61 | 1218 | dc->DrawRectangle( x, y+h, w+1, 1 ); // bottom (outer) |
bd8289c1 | 1219 | |
63852e78 | 1220 | wxPen pen( wxSystemSettings::GetSystemColour( wxSYS_COLOUR_BTNSHADOW ), 1, wxSOLID ); |
004fd0c8 | 1221 | |
63852e78 RR |
1222 | dc->SetPen( pen ); |
1223 | dc->DrawLine( x+w-m_corner, y, x+w-1, y+h ); // right (inner) | |
1224 | dc->DrawRectangle( x+1, y+h-1, w-2, 1 ); // bottom (inner) | |
bd8289c1 | 1225 | |
63852e78 RR |
1226 | dc->SetPen( *wxWHITE_PEN ); |
1227 | dc->DrawRectangle( x, y, w-m_corner+1, 1 ); // top (outer) | |
1228 | dc->DrawRectangle( x, y, 1, h ); // left (outer) | |
1229 | dc->DrawLine( x, y+h-1, x+1, y+h-1 ); | |
1230 | dc->DrawLine( x+w-1, y, x+w-1, y+1 ); | |
3fb435df | 1231 | #endif |
e1e955e1 | 1232 | } |
c801d85f | 1233 | |
f6bcfd97 BP |
1234 | // shift the DC origin to match the position of the main window horz |
1235 | // scrollbar: this allows us to always use logical coords | |
1236 | void wxListHeaderWindow::AdjustDC(wxDC& dc) | |
1237 | { | |
1238 | #if wxUSE_GENERIC_LIST_EXTENSIONS | |
1239 | int xpix; | |
1240 | m_owner->GetScrollPixelsPerUnit( &xpix, NULL ); | |
1241 | ||
1242 | int x; | |
1243 | m_owner->GetViewStart( &x, NULL ); | |
1244 | ||
1245 | // account for the horz scrollbar offset | |
1246 | dc.SetDeviceOrigin( -x * xpix, 0 ); | |
1247 | #endif // wxUSE_GENERIC_LIST_EXTENSIONS | |
1248 | } | |
1249 | ||
c801d85f KB |
1250 | void wxListHeaderWindow::OnPaint( wxPaintEvent &WXUNUSED(event) ) |
1251 | { | |
63852e78 RR |
1252 | wxPaintDC dc( this ); |
1253 | PrepareDC( dc ); | |
f6bcfd97 | 1254 | AdjustDC( dc ); |
bffa1c77 | 1255 | |
63852e78 | 1256 | dc.BeginDrawing(); |
bd8289c1 | 1257 | |
63852e78 | 1258 | dc.SetFont( GetFont() ); |
bd8289c1 | 1259 | |
f6bcfd97 BP |
1260 | // width and height of the entire header window |
1261 | int w, h; | |
63852e78 | 1262 | GetClientSize( &w, &h ); |
f6bcfd97 BP |
1263 | #if wxUSE_GENERIC_LIST_EXTENSIONS |
1264 | m_owner->CalcUnscrolledPosition(w, 0, &w, NULL); | |
1265 | #endif // wxUSE_GENERIC_LIST_EXTENSIONS | |
c801d85f | 1266 | |
f60d0f94 | 1267 | dc.SetBackgroundMode(wxTRANSPARENT); |
70846f0a VZ |
1268 | |
1269 | // do *not* use the listctrl colour for headers - one day we will have a | |
1270 | // function to set it separately | |
37d403aa JS |
1271 | //dc.SetTextForeground( *wxBLACK ); |
1272 | dc.SetTextForeground(wxSystemSettings::GetSystemColour( wxSYS_COLOUR_WINDOWTEXT )); | |
c801d85f | 1273 | |
f6bcfd97 BP |
1274 | int x = 1; // left of the header rect |
1275 | const int y = 1; // top | |
63852e78 RR |
1276 | int numColumns = m_owner->GetColumnCount(); |
1277 | wxListItem item; | |
1278 | for (int i = 0; i < numColumns; i++) | |
1279 | { | |
1280 | m_owner->GetColumn( i, item ); | |
f6bcfd97 BP |
1281 | int wCol = item.m_width; |
1282 | int cw = wCol - 2; // the width of the rect to draw | |
1283 | ||
1284 | int xEnd = x + wCol; | |
1285 | ||
1286 | // VZ: no, draw it normally - this is better now as we allow resizing | |
1287 | // of the last column as well | |
1288 | #if 0 | |
1289 | // let the last column occupy all available space | |
1290 | if ( i == numColumns - 1 ) | |
470caaf9 | 1291 | cw = w-x-1; |
f6bcfd97 BP |
1292 | #endif // 0 |
1293 | ||
63852e78 | 1294 | dc.SetPen( *wxWHITE_PEN ); |
c801d85f | 1295 | |
63852e78 | 1296 | DoDrawRect( &dc, x, y, cw, h-2 ); |
40c70187 | 1297 | dc.SetClippingRegion( x, y, cw-5, h-4 ); |
63852e78 | 1298 | dc.DrawText( item.m_text, x+4, y+3 ); |
40c70187 | 1299 | dc.DestroyClippingRegion(); |
f6bcfd97 BP |
1300 | x += wCol; |
1301 | ||
1302 | if (xEnd > w+5) | |
1303 | break; | |
63852e78 RR |
1304 | } |
1305 | dc.EndDrawing(); | |
e1e955e1 | 1306 | } |
c801d85f | 1307 | |
0208334d RR |
1308 | void wxListHeaderWindow::DrawCurrent() |
1309 | { | |
63852e78 RR |
1310 | int x1 = m_currentX; |
1311 | int y1 = 0; | |
f6bcfd97 BP |
1312 | ClientToScreen( &x1, &y1 ); |
1313 | ||
63852e78 RR |
1314 | int x2 = m_currentX-1; |
1315 | int y2 = 0; | |
f6bcfd97 | 1316 | m_owner->GetClientSize( NULL, &y2 ); |
63852e78 | 1317 | m_owner->ClientToScreen( &x2, &y2 ); |
0208334d | 1318 | |
63852e78 | 1319 | wxScreenDC dc; |
3c679789 | 1320 | dc.SetLogicalFunction( wxINVERT ); |
63852e78 RR |
1321 | dc.SetPen( wxPen( *wxBLACK, 2, wxSOLID ) ); |
1322 | dc.SetBrush( *wxTRANSPARENT_BRUSH ); | |
0208334d | 1323 | |
f6bcfd97 BP |
1324 | AdjustDC(dc); |
1325 | ||
63852e78 | 1326 | dc.DrawLine( x1, y1, x2, y2 ); |
0208334d | 1327 | |
63852e78 | 1328 | dc.SetLogicalFunction( wxCOPY ); |
0208334d | 1329 | |
63852e78 RR |
1330 | dc.SetPen( wxNullPen ); |
1331 | dc.SetBrush( wxNullBrush ); | |
0208334d RR |
1332 | } |
1333 | ||
c801d85f KB |
1334 | void wxListHeaderWindow::OnMouse( wxMouseEvent &event ) |
1335 | { | |
f6bcfd97 BP |
1336 | // we want to work with logical coords |
1337 | #if wxUSE_GENERIC_LIST_EXTENSIONS | |
3ca6a5f0 BP |
1338 | int x; |
1339 | m_owner->CalcUnscrolledPosition(event.GetX(), 0, &x, NULL); | |
f6bcfd97 BP |
1340 | #else // !wxUSE_GENERIC_LIST_EXTENSIONS |
1341 | int x = event.GetX(); | |
f6bcfd97 | 1342 | #endif // wxUSE_GENERIC_LIST_EXTENSIONS |
3ca6a5f0 | 1343 | int y = event.GetY(); |
f6bcfd97 | 1344 | |
cfb50f14 | 1345 | if (m_isDragging) |
0208334d | 1346 | { |
f6bcfd97 BP |
1347 | // we don't draw the line beyond our window, but we allow dragging it |
1348 | // there | |
1349 | int w = 0; | |
1350 | GetClientSize( &w, NULL ); | |
1351 | #if wxUSE_GENERIC_LIST_EXTENSIONS | |
1352 | m_owner->CalcUnscrolledPosition(w, 0, &w, NULL); | |
1353 | #endif // wxUSE_GENERIC_LIST_EXTENSIONS | |
1354 | w -= 6; | |
1355 | ||
1356 | // erase the line if it was drawn | |
1357 | if ( m_currentX < w ) | |
1358 | DrawCurrent(); | |
1359 | ||
63852e78 RR |
1360 | if (event.ButtonUp()) |
1361 | { | |
1362 | ReleaseMouse(); | |
cfb50f14 | 1363 | m_isDragging = FALSE; |
f6bcfd97 BP |
1364 | m_dirty = TRUE; |
1365 | m_owner->SetColumnWidth( m_column, m_currentX - m_minX ); | |
63852e78 RR |
1366 | } |
1367 | else | |
1368 | { | |
f6bcfd97 | 1369 | if (x > m_minX + 7) |
63852e78 RR |
1370 | m_currentX = x; |
1371 | else | |
f6bcfd97 | 1372 | m_currentX = m_minX + 7; |
bd8289c1 | 1373 | |
f6bcfd97 BP |
1374 | // draw in the new location |
1375 | if ( m_currentX < w ) | |
1376 | DrawCurrent(); | |
bffa1c77 | 1377 | } |
0208334d | 1378 | } |
f6bcfd97 | 1379 | else // not dragging |
c801d85f | 1380 | { |
f6bcfd97 BP |
1381 | m_minX = 0; |
1382 | bool hit_border = FALSE; | |
1383 | ||
1384 | // end of the current column | |
1385 | int xpos = 0; | |
1386 | ||
1387 | // find the column where this event occured | |
1388 | int countCol = m_owner->GetColumnCount(); | |
1389 | for (int j = 0; j < countCol; j++) | |
bffa1c77 | 1390 | { |
f6bcfd97 BP |
1391 | xpos += m_owner->GetColumnWidth( j ); |
1392 | m_column = j; | |
1393 | ||
1394 | if ( (abs(x-xpos) < 3) && (y < 22) ) | |
1395 | { | |
1396 | // near the column border | |
1397 | hit_border = TRUE; | |
1398 | break; | |
1399 | } | |
1400 | ||
1401 | if ( x < xpos ) | |
1402 | { | |
1403 | // inside the column | |
1404 | break; | |
1405 | } | |
1406 | ||
1407 | m_minX = xpos; | |
bffa1c77 | 1408 | } |
63852e78 | 1409 | |
f6bcfd97 | 1410 | if (event.LeftDown()) |
63852e78 | 1411 | { |
f6bcfd97 BP |
1412 | if (hit_border) |
1413 | { | |
1414 | m_isDragging = TRUE; | |
1415 | m_currentX = x; | |
1416 | DrawCurrent(); | |
1417 | CaptureMouse(); | |
1418 | } | |
1419 | else | |
1420 | { | |
1421 | wxWindow *parent = GetParent(); | |
1422 | wxListEvent le( wxEVT_COMMAND_LIST_COL_CLICK, parent->GetId() ); | |
1423 | le.SetEventObject( parent ); | |
1424 | le.m_col = m_column; | |
1425 | parent->GetEventHandler()->ProcessEvent( le ); | |
1426 | } | |
63852e78 | 1427 | } |
f6bcfd97 | 1428 | else if (event.Moving()) |
63852e78 | 1429 | { |
f6bcfd97 BP |
1430 | bool setCursor; |
1431 | if (hit_border) | |
1432 | { | |
1433 | setCursor = m_currentCursor == wxSTANDARD_CURSOR; | |
1434 | m_currentCursor = m_resizeCursor; | |
1435 | } | |
1436 | else | |
1437 | { | |
1438 | setCursor = m_currentCursor != wxSTANDARD_CURSOR; | |
1439 | m_currentCursor = wxSTANDARD_CURSOR; | |
1440 | } | |
1441 | ||
1442 | if ( setCursor ) | |
1443 | SetCursor(*m_currentCursor); | |
63852e78 | 1444 | } |
e1e955e1 | 1445 | } |
e1e955e1 | 1446 | } |
c801d85f KB |
1447 | |
1448 | void wxListHeaderWindow::OnSetFocus( wxFocusEvent &WXUNUSED(event) ) | |
1449 | { | |
63852e78 | 1450 | m_owner->SetFocus(); |
e1e955e1 | 1451 | } |
c801d85f KB |
1452 | |
1453 | //----------------------------------------------------------------------------- | |
1454 | // wxListRenameTimer (internal) | |
1455 | //----------------------------------------------------------------------------- | |
1456 | ||
bd8289c1 VZ |
1457 | wxListRenameTimer::wxListRenameTimer( wxListMainWindow *owner ) |
1458 | { | |
63852e78 | 1459 | m_owner = owner; |
e1e955e1 | 1460 | } |
c801d85f | 1461 | |
bd8289c1 VZ |
1462 | void wxListRenameTimer::Notify() |
1463 | { | |
63852e78 | 1464 | m_owner->OnRenameTimer(); |
e1e955e1 | 1465 | } |
c801d85f | 1466 | |
ee7ee469 RR |
1467 | //----------------------------------------------------------------------------- |
1468 | // wxListTextCtrl (internal) | |
1469 | //----------------------------------------------------------------------------- | |
1470 | ||
1471 | IMPLEMENT_DYNAMIC_CLASS(wxListTextCtrl,wxTextCtrl); | |
bd8289c1 | 1472 | |
ee7ee469 | 1473 | BEGIN_EVENT_TABLE(wxListTextCtrl,wxTextCtrl) |
63852e78 | 1474 | EVT_CHAR (wxListTextCtrl::OnChar) |
c13cace1 | 1475 | EVT_KEY_UP (wxListTextCtrl::OnKeyUp) |
63852e78 | 1476 | EVT_KILL_FOCUS (wxListTextCtrl::OnKillFocus) |
ee7ee469 RR |
1477 | END_EVENT_TABLE() |
1478 | ||
674ac8b9 VZ |
1479 | wxListTextCtrl::wxListTextCtrl( wxWindow *parent, |
1480 | const wxWindowID id, | |
1481 | bool *accept, | |
1482 | wxString *res, | |
1483 | wxListMainWindow *owner, | |
1484 | const wxString &value, | |
1485 | const wxPoint &pos, | |
1486 | const wxSize &size, | |
1487 | int style, | |
1488 | const wxValidator& validator, | |
1489 | const wxString &name ) | |
1490 | : wxTextCtrl( parent, id, value, pos, size, style, validator, name ) | |
ee7ee469 | 1491 | { |
63852e78 RR |
1492 | m_res = res; |
1493 | m_accept = accept; | |
1494 | m_owner = owner; | |
5f1ea0ee RR |
1495 | (*m_accept) = FALSE; |
1496 | (*m_res) = ""; | |
1497 | m_startValue = value; | |
ee7ee469 RR |
1498 | } |
1499 | ||
1500 | void wxListTextCtrl::OnChar( wxKeyEvent &event ) | |
1501 | { | |
63852e78 RR |
1502 | if (event.m_keyCode == WXK_RETURN) |
1503 | { | |
1504 | (*m_accept) = TRUE; | |
1505 | (*m_res) = GetValue(); | |
f6bcfd97 | 1506 | |
bce1406b RR |
1507 | if (!wxPendingDelete.Member(this)) |
1508 | wxPendingDelete.Append(this); | |
1509 | ||
1510 | if ((*m_accept) && ((*m_res) != m_startValue)) | |
1511 | m_owner->OnRenameAccept(); | |
f6bcfd97 | 1512 | |
63852e78 RR |
1513 | return; |
1514 | } | |
1515 | if (event.m_keyCode == WXK_ESCAPE) | |
1516 | { | |
1517 | (*m_accept) = FALSE; | |
1518 | (*m_res) = ""; | |
f6bcfd97 | 1519 | |
bce1406b RR |
1520 | if (!wxPendingDelete.Member(this)) |
1521 | wxPendingDelete.Append(this); | |
f6bcfd97 | 1522 | |
63852e78 RR |
1523 | return; |
1524 | } | |
f6bcfd97 | 1525 | |
63852e78 RR |
1526 | event.Skip(); |
1527 | } | |
1528 | ||
c13cace1 VS |
1529 | void wxListTextCtrl::OnKeyUp( wxKeyEvent &event ) |
1530 | { | |
1531 | // auto-grow the textctrl: | |
1532 | wxSize parentSize = m_owner->GetSize(); | |
1533 | wxPoint myPos = GetPosition(); | |
1534 | wxSize mySize = GetSize(); | |
1535 | int sx, sy; | |
1536 | GetTextExtent(GetValue() + _T("MM"), &sx, &sy); | |
1537 | if (myPos.x + sx > parentSize.x) sx = parentSize.x - myPos.x; | |
1538 | if (mySize.x > sx) sx = mySize.x; | |
1539 | SetSize(sx, -1); | |
1540 | ||
1541 | event.Skip(); | |
1542 | } | |
1543 | ||
63852e78 RR |
1544 | void wxListTextCtrl::OnKillFocus( wxFocusEvent &WXUNUSED(event) ) |
1545 | { | |
bce1406b RR |
1546 | if (!wxPendingDelete.Member(this)) |
1547 | wxPendingDelete.Append(this); | |
004fd0c8 | 1548 | |
5f1ea0ee RR |
1549 | if ((*m_accept) && ((*m_res) != m_startValue)) |
1550 | m_owner->OnRenameAccept(); | |
ee7ee469 RR |
1551 | } |
1552 | ||
c801d85f KB |
1553 | //----------------------------------------------------------------------------- |
1554 | // wxListMainWindow | |
1555 | //----------------------------------------------------------------------------- | |
1556 | ||
1557 | IMPLEMENT_DYNAMIC_CLASS(wxListMainWindow,wxScrolledWindow); | |
bd8289c1 | 1558 | |
c801d85f KB |
1559 | BEGIN_EVENT_TABLE(wxListMainWindow,wxScrolledWindow) |
1560 | EVT_PAINT (wxListMainWindow::OnPaint) | |
1561 | EVT_SIZE (wxListMainWindow::OnSize) | |
1562 | EVT_MOUSE_EVENTS (wxListMainWindow::OnMouse) | |
1563 | EVT_CHAR (wxListMainWindow::OnChar) | |
3dfb93fd | 1564 | EVT_KEY_DOWN (wxListMainWindow::OnKeyDown) |
c801d85f KB |
1565 | EVT_SET_FOCUS (wxListMainWindow::OnSetFocus) |
1566 | EVT_KILL_FOCUS (wxListMainWindow::OnKillFocus) | |
2fa7c206 | 1567 | EVT_SCROLLWIN (wxListMainWindow::OnScroll) |
c801d85f KB |
1568 | END_EVENT_TABLE() |
1569 | ||
fd9811b1 | 1570 | wxListMainWindow::wxListMainWindow() |
c801d85f | 1571 | { |
139adb6a | 1572 | m_mode = 0; |
139adb6a RR |
1573 | m_columns.DeleteContents( TRUE ); |
1574 | m_current = (wxListLineData *) NULL; | |
1575 | m_visibleLines = 0; | |
1576 | m_hilightBrush = (wxBrush *) NULL; | |
1577 | m_xScroll = 0; | |
1578 | m_yScroll = 0; | |
1579 | m_dirty = TRUE; | |
1580 | m_small_image_list = (wxImageList *) NULL; | |
1581 | m_normal_image_list = (wxImageList *) NULL; | |
1582 | m_small_spacing = 30; | |
1583 | m_normal_spacing = 40; | |
1584 | m_hasFocus = FALSE; | |
1585 | m_usedKeys = TRUE; | |
1586 | m_lastOnSame = FALSE; | |
1587 | m_renameTimer = new wxListRenameTimer( this ); | |
1588 | m_isCreated = FALSE; | |
1589 | m_dragCount = 0; | |
efbb7287 VZ |
1590 | |
1591 | m_lineLastClicked = | |
1592 | m_lineBeforeLastClicked = (wxListLineData *)NULL; | |
e1e955e1 | 1593 | } |
c801d85f | 1594 | |
bd8289c1 | 1595 | wxListMainWindow::wxListMainWindow( wxWindow *parent, wxWindowID id, |
c801d85f | 1596 | const wxPoint &pos, const wxSize &size, |
debe6624 | 1597 | long style, const wxString &name ) : |
a367b9b3 | 1598 | wxScrolledWindow( parent, id, pos, size, style|wxHSCROLL|wxVSCROLL, name ) |
c801d85f | 1599 | { |
139adb6a | 1600 | m_mode = style; |
139adb6a RR |
1601 | m_columns.DeleteContents( TRUE ); |
1602 | m_current = (wxListLineData *) NULL; | |
1603 | m_dirty = TRUE; | |
1604 | m_visibleLines = 0; | |
1605 | m_hilightBrush = new wxBrush( wxSystemSettings::GetSystemColour(wxSYS_COLOUR_HIGHLIGHT), wxSOLID ); | |
1606 | m_small_image_list = (wxImageList *) NULL; | |
1607 | m_normal_image_list = (wxImageList *) NULL; | |
1608 | m_small_spacing = 30; | |
1609 | m_normal_spacing = 40; | |
1610 | m_hasFocus = FALSE; | |
1611 | m_dragCount = 0; | |
1612 | m_isCreated = FALSE; | |
1613 | wxSize sz = size; | |
1614 | sz.y = 25; | |
bd8289c1 | 1615 | |
139adb6a RR |
1616 | if (m_mode & wxLC_REPORT) |
1617 | { | |
7c74e7fe SC |
1618 | #if wxUSE_GENERIC_LIST_EXTENSIONS |
1619 | m_xScroll = 15; | |
1620 | #else | |
139adb6a | 1621 | m_xScroll = 0; |
7c74e7fe | 1622 | #endif |
139adb6a RR |
1623 | m_yScroll = 15; |
1624 | } | |
1625 | else | |
1626 | { | |
1627 | m_xScroll = 15; | |
1628 | m_yScroll = 0; | |
1629 | } | |
1630 | SetScrollbars( m_xScroll, m_yScroll, 0, 0, 0, 0 ); | |
bd8289c1 | 1631 | |
139adb6a RR |
1632 | m_usedKeys = TRUE; |
1633 | m_lastOnSame = FALSE; | |
1634 | m_renameTimer = new wxListRenameTimer( this ); | |
1635 | m_renameAccept = FALSE; | |
c801d85f | 1636 | |
91fc2bdc | 1637 | SetBackgroundColour( wxSystemSettings::GetSystemColour( wxSYS_COLOUR_LISTBOX ) ); |
e1e955e1 | 1638 | } |
c801d85f | 1639 | |
fd9811b1 | 1640 | wxListMainWindow::~wxListMainWindow() |
c801d85f | 1641 | { |
12c1b46a RR |
1642 | DeleteEverything(); |
1643 | ||
139adb6a | 1644 | if (m_hilightBrush) delete m_hilightBrush; |
004fd0c8 | 1645 | |
139adb6a | 1646 | delete m_renameTimer; |
e1e955e1 | 1647 | } |
c801d85f KB |
1648 | |
1649 | void wxListMainWindow::RefreshLine( wxListLineData *line ) | |
1650 | { | |
e6527f9d | 1651 | if (m_dirty) return; |
25e3a937 | 1652 | |
3d2d8da1 | 1653 | if (!line) return; |
f6bcfd97 | 1654 | |
139adb6a RR |
1655 | int x = 0; |
1656 | int y = 0; | |
1657 | int w = 0; | |
1658 | int h = 0; | |
3d2d8da1 RR |
1659 | line->GetExtent( x, y, w, h ); |
1660 | CalcScrolledPosition( x, y, &x, &y ); | |
1661 | wxRect rect( x, y, w, h ); | |
1662 | Refresh( TRUE, &rect ); | |
e1e955e1 | 1663 | } |
c801d85f KB |
1664 | |
1665 | void wxListMainWindow::OnPaint( wxPaintEvent &WXUNUSED(event) ) | |
1666 | { | |
f60d0f94 JS |
1667 | // Note: a wxPaintDC must be constructed even if no drawing is |
1668 | // done (a Windows requirement). | |
1669 | wxPaintDC dc( this ); | |
1670 | PrepareDC( dc ); | |
1671 | ||
139adb6a | 1672 | if (m_dirty) return; |
004fd0c8 | 1673 | |
139adb6a | 1674 | if (m_lines.GetCount() == 0) return; |
bd8289c1 | 1675 | |
139adb6a | 1676 | dc.BeginDrawing(); |
c801d85f | 1677 | |
139adb6a | 1678 | dc.SetFont( GetFont() ); |
004fd0c8 | 1679 | |
139adb6a RR |
1680 | if (m_mode & wxLC_REPORT) |
1681 | { | |
206b0a67 JS |
1682 | wxPen pen(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DLIGHT), 1, wxSOLID); |
1683 | dc.SetPen(pen); | |
1684 | dc.SetBrush(* wxTRANSPARENT_BRUSH); | |
1685 | ||
1686 | wxSize clientSize = GetClientSize(); | |
206b0a67 | 1687 | |
139adb6a | 1688 | int lineSpacing = 0; |
f6bcfd97 | 1689 | wxListLineData *line = &m_lines[0]; |
139adb6a RR |
1690 | int dummy = 0; |
1691 | line->GetSize( dummy, lineSpacing ); | |
1692 | lineSpacing += 1; | |
bffa1c77 | 1693 | |
139adb6a | 1694 | int y_s = m_yScroll*GetScrollPos( wxVERTICAL ); |
bffa1c77 | 1695 | |
f6bcfd97 BP |
1696 | size_t i_to = y_s / lineSpacing + m_visibleLines+2; |
1697 | if (i_to >= m_lines.GetCount()) i_to = m_lines.GetCount(); | |
206b0a67 JS |
1698 | size_t i; |
1699 | for (i = y_s / lineSpacing; i < i_to; i++) | |
bffa1c77 | 1700 | { |
f6bcfd97 | 1701 | m_lines[i].Draw( &dc ); |
206b0a67 JS |
1702 | // Draw horizontal rule if required |
1703 | if (GetWindowStyle() & wxLC_HRULES) | |
1704 | dc.DrawLine(0, i*lineSpacing, clientSize.x, i*lineSpacing); | |
bffa1c77 | 1705 | } |
206b0a67 JS |
1706 | |
1707 | // Draw last horizontal rule | |
1708 | if ((i > (size_t) (y_s / lineSpacing)) && (GetWindowStyle() & wxLC_HRULES)) | |
1709 | dc.DrawLine(0, i*lineSpacing, clientSize.x, i*lineSpacing); | |
1710 | ||
1711 | // Draw vertical rules if required | |
1712 | if ((GetWindowStyle() & wxLC_VRULES) && (GetItemCount() > 0)) | |
1713 | { | |
1714 | int col = 0; | |
1715 | wxRect firstItemRect; | |
1716 | wxRect lastItemRect; | |
1717 | GetItemRect(0, firstItemRect); | |
1718 | GetItemRect(GetItemCount() - 1, lastItemRect); | |
1719 | int x = firstItemRect.GetX(); | |
1720 | for (col = 0; col < GetColumnCount(); col++) | |
1721 | { | |
1722 | int colWidth = GetColumnWidth(col); | |
1723 | x += colWidth ; | |
1724 | dc.DrawLine(x, firstItemRect.GetY() - 1, x, lastItemRect.GetBottom() + 1); | |
1725 | } | |
d786bf87 | 1726 | } |
139adb6a RR |
1727 | } |
1728 | else | |
1729 | { | |
f6bcfd97 BP |
1730 | for (size_t i = 0; i < m_lines.GetCount(); i++) |
1731 | m_lines[i].Draw( &dc ); | |
139adb6a | 1732 | } |
004fd0c8 | 1733 | |
139adb6a | 1734 | if (m_current) m_current->DrawRubberBand( &dc, m_hasFocus ); |
c801d85f | 1735 | |
139adb6a | 1736 | dc.EndDrawing(); |
e1e955e1 | 1737 | } |
c801d85f | 1738 | |
debe6624 | 1739 | void wxListMainWindow::HilightAll( bool on ) |
c801d85f | 1740 | { |
f6bcfd97 | 1741 | for (size_t i = 0; i < m_lines.GetCount(); i++) |
c801d85f | 1742 | { |
f6bcfd97 | 1743 | wxListLineData *line = &m_lines[i]; |
139adb6a RR |
1744 | if (line->IsHilighted() != on) |
1745 | { | |
1746 | line->Hilight( on ); | |
1747 | RefreshLine( line ); | |
1748 | } | |
e1e955e1 | 1749 | } |
e1e955e1 | 1750 | } |
c801d85f | 1751 | |
05a7f61d VZ |
1752 | void wxListMainWindow::SendNotify( wxListLineData *line, |
1753 | wxEventType command, | |
1754 | wxPoint point ) | |
c801d85f | 1755 | { |
139adb6a RR |
1756 | wxListEvent le( command, GetParent()->GetId() ); |
1757 | le.SetEventObject( GetParent() ); | |
1758 | le.m_itemIndex = GetIndexOfLine( line ); | |
05a7f61d VZ |
1759 | |
1760 | // set only for events which have position | |
1761 | if ( point != wxDefaultPosition ) | |
1762 | le.m_pointDrag = point; | |
1763 | ||
139adb6a | 1764 | line->GetItem( 0, le.m_item ); |
6e228e42 RR |
1765 | GetParent()->GetEventHandler()->ProcessEvent( le ); |
1766 | // GetParent()->GetEventHandler()->AddPendingEvent( le ); | |
e1e955e1 | 1767 | } |
c801d85f KB |
1768 | |
1769 | void wxListMainWindow::FocusLine( wxListLineData *WXUNUSED(line) ) | |
1770 | { | |
1771 | // SendNotify( line, wxEVT_COMMAND_LIST_ITEM_FOCUSSED ); | |
e1e955e1 | 1772 | } |
c801d85f KB |
1773 | |
1774 | void wxListMainWindow::UnfocusLine( wxListLineData *WXUNUSED(line) ) | |
1775 | { | |
1776 | // SendNotify( line, wxEVT_COMMAND_LIST_ITEM_UNFOCUSSED ); | |
e1e955e1 | 1777 | } |
c801d85f KB |
1778 | |
1779 | void wxListMainWindow::SelectLine( wxListLineData *line ) | |
1780 | { | |
139adb6a | 1781 | SendNotify( line, wxEVT_COMMAND_LIST_ITEM_SELECTED ); |
e1e955e1 | 1782 | } |
c801d85f KB |
1783 | |
1784 | void wxListMainWindow::DeselectLine( wxListLineData *line ) | |
1785 | { | |
139adb6a | 1786 | SendNotify( line, wxEVT_COMMAND_LIST_ITEM_DESELECTED ); |
e1e955e1 | 1787 | } |
c801d85f KB |
1788 | |
1789 | void wxListMainWindow::DeleteLine( wxListLineData *line ) | |
1790 | { | |
139adb6a | 1791 | SendNotify( line, wxEVT_COMMAND_LIST_DELETE_ITEM ); |
e1e955e1 | 1792 | } |
c801d85f | 1793 | |
e179bd65 | 1794 | /* *** */ |
ee7ee469 | 1795 | |
5f1ea0ee | 1796 | void wxListMainWindow::EditLabel( long item ) |
c801d85f | 1797 | { |
3e1c4e00 | 1798 | wxCHECK_RET( ((size_t)item < m_lines.GetCount()), |
f6bcfd97 | 1799 | wxT("wrong index in wxListCtrl::Edit()") ); |
004fd0c8 | 1800 | |
f6bcfd97 | 1801 | m_currentEdit = &m_lines[(size_t)item]; |
e179bd65 | 1802 | |
fd9811b1 | 1803 | wxListEvent le( wxEVT_COMMAND_LIST_BEGIN_LABEL_EDIT, GetParent()->GetId() ); |
139adb6a | 1804 | le.SetEventObject( GetParent() ); |
e179bd65 RR |
1805 | le.m_itemIndex = GetIndexOfLine( m_currentEdit ); |
1806 | m_currentEdit->GetItem( 0, le.m_item ); | |
139adb6a | 1807 | GetParent()->GetEventHandler()->ProcessEvent( le ); |
004fd0c8 | 1808 | |
86f975a8 | 1809 | if (!le.IsAllowed()) |
5f1ea0ee | 1810 | return; |
004fd0c8 | 1811 | |
dc6c62a9 RR |
1812 | // We have to call this here because the label in |
1813 | // question might just have been added and no screen | |
1814 | // update taken place. | |
1815 | if (m_dirty) wxYield(); | |
1816 | ||
92976ab6 | 1817 | wxString s; |
e179bd65 | 1818 | m_currentEdit->GetText( 0, s ); |
92976ab6 RR |
1819 | int x = 0; |
1820 | int y = 0; | |
1821 | int w = 0; | |
1822 | int h = 0; | |
e179bd65 | 1823 | m_currentEdit->GetLabelExtent( x, y, w, h ); |
004fd0c8 | 1824 | |
92976ab6 RR |
1825 | wxClientDC dc(this); |
1826 | PrepareDC( dc ); | |
1827 | x = dc.LogicalToDeviceX( x ); | |
1828 | y = dc.LogicalToDeviceY( y ); | |
bd8289c1 | 1829 | |
92976ab6 RR |
1830 | wxListTextCtrl *text = new wxListTextCtrl( |
1831 | this, -1, &m_renameAccept, &m_renameRes, this, s, wxPoint(x-4,y-4), wxSize(w+11,h+8) ); | |
1832 | text->SetFocus(); | |
e1e955e1 | 1833 | } |
c801d85f | 1834 | |
e179bd65 RR |
1835 | void wxListMainWindow::OnRenameTimer() |
1836 | { | |
223d09f6 | 1837 | wxCHECK_RET( m_current, wxT("invalid m_current") ); |
004fd0c8 | 1838 | |
f6bcfd97 | 1839 | Edit( m_lines.Index( *m_current ) ); |
e179bd65 RR |
1840 | } |
1841 | ||
c801d85f KB |
1842 | void wxListMainWindow::OnRenameAccept() |
1843 | { | |
e179bd65 RR |
1844 | wxListEvent le( wxEVT_COMMAND_LIST_END_LABEL_EDIT, GetParent()->GetId() ); |
1845 | le.SetEventObject( GetParent() ); | |
1846 | le.m_itemIndex = GetIndexOfLine( m_currentEdit ); | |
1847 | m_currentEdit->GetItem( 0, le.m_item ); | |
1848 | le.m_item.m_text = m_renameRes; | |
1849 | GetParent()->GetEventHandler()->ProcessEvent( le ); | |
004fd0c8 | 1850 | |
e179bd65 | 1851 | if (!le.IsAllowed()) return; |
004fd0c8 | 1852 | |
5f1ea0ee RR |
1853 | wxListItem info; |
1854 | info.m_mask = wxLIST_MASK_TEXT; | |
1855 | info.m_itemId = le.m_itemIndex; | |
1856 | info.m_text = m_renameRes; | |
aaa37c0d | 1857 | info.SetTextColour(le.m_item.GetTextColour()); |
5f1ea0ee | 1858 | SetItem( info ); |
e1e955e1 | 1859 | } |
c801d85f KB |
1860 | |
1861 | void wxListMainWindow::OnMouse( wxMouseEvent &event ) | |
1862 | { | |
3e1c4e00 | 1863 | event.SetEventObject( GetParent() ); |
92976ab6 | 1864 | if (GetParent()->GetEventHandler()->ProcessEvent( event)) return; |
e3e65dac | 1865 | |
92976ab6 RR |
1866 | if (!m_current) return; |
1867 | if (m_dirty) return; | |
0b855868 | 1868 | if ( !(event.Dragging() || event.ButtonDown() || event.LeftUp() || event.ButtonDClick()) ) return; |
c801d85f | 1869 | |
aaef15bf RR |
1870 | int x = event.GetX(); |
1871 | int y = event.GetY(); | |
1872 | CalcUnscrolledPosition( x, y, &x, &y ); | |
004fd0c8 | 1873 | |
51cc4dad | 1874 | /* Did we actually hit an item ? */ |
92976ab6 | 1875 | long hitResult = 0; |
92976ab6 | 1876 | wxListLineData *line = (wxListLineData *) NULL; |
f6bcfd97 | 1877 | for (size_t i = 0; i < m_lines.GetCount(); i++) |
92976ab6 | 1878 | { |
f6bcfd97 | 1879 | line = &m_lines[i]; |
92976ab6 RR |
1880 | hitResult = line->IsHit( x, y ); |
1881 | if (hitResult) break; | |
1882 | line = (wxListLineData *) NULL; | |
92976ab6 | 1883 | } |
bd8289c1 | 1884 | |
fd9811b1 | 1885 | if (event.Dragging()) |
92976ab6 | 1886 | { |
fd9811b1 | 1887 | if (m_dragCount == 0) |
bffa1c77 VZ |
1888 | m_dragStart = wxPoint(x,y); |
1889 | ||
fd9811b1 | 1890 | m_dragCount++; |
bffa1c77 VZ |
1891 | |
1892 | if (m_dragCount != 3) return; | |
1893 | ||
05a7f61d VZ |
1894 | int command = event.RightIsDown() ? wxEVT_COMMAND_LIST_BEGIN_RDRAG |
1895 | : wxEVT_COMMAND_LIST_BEGIN_DRAG; | |
bffa1c77 | 1896 | |
fd9811b1 | 1897 | wxListEvent le( command, GetParent()->GetId() ); |
92976ab6 | 1898 | le.SetEventObject( GetParent() ); |
bffa1c77 VZ |
1899 | le.m_pointDrag = m_dragStart; |
1900 | GetParent()->GetEventHandler()->ProcessEvent( le ); | |
1901 | ||
1902 | return; | |
92976ab6 | 1903 | } |
fd9811b1 RR |
1904 | else |
1905 | { | |
1906 | m_dragCount = 0; | |
1907 | } | |
bd8289c1 | 1908 | |
92976ab6 | 1909 | if (!line) return; |
bd8289c1 | 1910 | |
efbb7287 | 1911 | bool forceClick = FALSE; |
92976ab6 RR |
1912 | if (event.ButtonDClick()) |
1913 | { | |
92976ab6 | 1914 | m_renameTimer->Stop(); |
efbb7287 VZ |
1915 | m_lastOnSame = FALSE; |
1916 | ||
1917 | if ( line == m_lineBeforeLastClicked ) | |
1918 | { | |
1919 | m_usedKeys = FALSE; | |
004fd0c8 | 1920 | |
efbb7287 | 1921 | SendNotify( line, wxEVT_COMMAND_LIST_ITEM_ACTIVATED ); |
004fd0c8 | 1922 | |
efbb7287 VZ |
1923 | return; |
1924 | } | |
1925 | else | |
1926 | { | |
1927 | // the first click was on another item, so don't interpret this as | |
1928 | // a double click, but as a simple click instead | |
1929 | forceClick = TRUE; | |
1930 | } | |
92976ab6 | 1931 | } |
bd8289c1 | 1932 | |
92976ab6 | 1933 | if (event.LeftUp() && m_lastOnSame) |
c801d85f | 1934 | { |
92976ab6 RR |
1935 | m_usedKeys = FALSE; |
1936 | if ((line == m_current) && | |
1937 | (hitResult == wxLIST_HITTEST_ONITEMLABEL) && | |
1938 | (m_mode & wxLC_EDIT_LABELS) ) | |
1939 | { | |
1940 | m_renameTimer->Start( 100, TRUE ); | |
1941 | } | |
1942 | m_lastOnSame = FALSE; | |
1943 | return; | |
e1e955e1 | 1944 | } |
bd8289c1 | 1945 | |
92976ab6 | 1946 | if (event.RightDown()) |
b204641e | 1947 | { |
05a7f61d VZ |
1948 | SendNotify( line, wxEVT_COMMAND_LIST_ITEM_RIGHT_CLICK, |
1949 | event.GetPosition() ); | |
92976ab6 | 1950 | return; |
b204641e | 1951 | } |
004fd0c8 | 1952 | |
92976ab6 | 1953 | if (event.MiddleDown()) |
b204641e | 1954 | { |
92976ab6 RR |
1955 | SendNotify( line, wxEVT_COMMAND_LIST_ITEM_MIDDLE_CLICK ); |
1956 | return; | |
1957 | } | |
004fd0c8 | 1958 | |
efbb7287 | 1959 | if ( event.LeftDown() || forceClick ) |
92976ab6 | 1960 | { |
efbb7287 VZ |
1961 | m_lineBeforeLastClicked = m_lineLastClicked; |
1962 | m_lineLastClicked = line; | |
1963 | ||
92976ab6 RR |
1964 | m_usedKeys = FALSE; |
1965 | wxListLineData *oldCurrent = m_current; | |
1966 | if (m_mode & wxLC_SINGLE_SEL) | |
b204641e | 1967 | { |
92976ab6 RR |
1968 | m_current = line; |
1969 | HilightAll( FALSE ); | |
1970 | m_current->ReverseHilight(); | |
1971 | RefreshLine( m_current ); | |
e1e955e1 | 1972 | } |
92976ab6 | 1973 | else |
b204641e | 1974 | { |
473d087e | 1975 | if (event.ControlDown()) |
92976ab6 RR |
1976 | { |
1977 | m_current = line; | |
1978 | m_current->ReverseHilight(); | |
1979 | RefreshLine( m_current ); | |
1980 | } | |
473d087e | 1981 | else if (event.ShiftDown()) |
92976ab6 | 1982 | { |
f6bcfd97 | 1983 | size_t j; |
3e1c4e00 | 1984 | |
92976ab6 | 1985 | m_current = line; |
bffa1c77 | 1986 | |
92976ab6 | 1987 | int numOfCurrent = -1; |
f6bcfd97 | 1988 | for (j = 0; j < m_lines.GetCount(); j++) |
92976ab6 | 1989 | { |
f6bcfd97 | 1990 | wxListLineData *test_line = &m_lines[j]; |
92976ab6 RR |
1991 | numOfCurrent++; |
1992 | if (test_line == oldCurrent) break; | |
92976ab6 | 1993 | } |
bffa1c77 | 1994 | |
92976ab6 | 1995 | int numOfLine = -1; |
f6bcfd97 BP |
1996 | |
1997 | for (j = 0; j < m_lines.GetCount(); j++) | |
92976ab6 | 1998 | { |
f6bcfd97 | 1999 | wxListLineData *test_line = &m_lines[j]; |
92976ab6 RR |
2000 | numOfLine++; |
2001 | if (test_line == line) break; | |
92976ab6 RR |
2002 | } |
2003 | ||
2004 | if (numOfLine < numOfCurrent) | |
004fd0c8 | 2005 | { |
bffa1c77 VZ |
2006 | int i = numOfLine; |
2007 | numOfLine = numOfCurrent; | |
2008 | numOfCurrent = i; | |
2009 | } | |
2010 | ||
92976ab6 RR |
2011 | for (int i = 0; i <= numOfLine-numOfCurrent; i++) |
2012 | { | |
f6bcfd97 | 2013 | wxListLineData *test_line= &m_lines[numOfCurrent + i]; |
92976ab6 RR |
2014 | test_line->Hilight(TRUE); |
2015 | RefreshLine( test_line ); | |
92976ab6 RR |
2016 | } |
2017 | } | |
2018 | else | |
2019 | { | |
2020 | m_current = line; | |
2021 | HilightAll( FALSE ); | |
2022 | m_current->ReverseHilight(); | |
2023 | RefreshLine( m_current ); | |
2024 | } | |
e1e955e1 | 2025 | } |
92976ab6 RR |
2026 | if (m_current != oldCurrent) |
2027 | { | |
2028 | RefreshLine( oldCurrent ); | |
2029 | UnfocusLine( oldCurrent ); | |
2030 | FocusLine( m_current ); | |
2031 | } | |
efbb7287 VZ |
2032 | |
2033 | // forceClick is only set if the previous click was on another item | |
2034 | m_lastOnSame = !forceClick && (m_current == oldCurrent); | |
2035 | ||
92976ab6 | 2036 | return; |
e1e955e1 | 2037 | } |
e1e955e1 | 2038 | } |
c801d85f | 2039 | |
e179bd65 | 2040 | void wxListMainWindow::MoveToFocus() |
c801d85f | 2041 | { |
92976ab6 | 2042 | if (!m_current) return; |
004fd0c8 | 2043 | |
cf3da716 RR |
2044 | int item_x = 0; |
2045 | int item_y = 0; | |
2046 | int item_w = 0; | |
2047 | int item_h = 0; | |
2048 | m_current->GetExtent( item_x, item_y, item_w, item_h ); | |
2049 | ||
2050 | int client_w = 0; | |
2051 | int client_h = 0; | |
2052 | GetClientSize( &client_w, &client_h ); | |
f6bcfd97 | 2053 | |
cf3da716 RR |
2054 | int view_x = m_xScroll*GetScrollPos( wxHORIZONTAL ); |
2055 | int view_y = m_yScroll*GetScrollPos( wxVERTICAL ); | |
004fd0c8 | 2056 | |
92976ab6 RR |
2057 | if (m_mode & wxLC_REPORT) |
2058 | { | |
08bf1d5d RR |
2059 | if (item_y < view_y ) |
2060 | Scroll( -1, (item_y)/m_yScroll ); | |
f6bcfd97 | 2061 | if (item_y+item_h+5 > view_y+client_h) |
cf3da716 | 2062 | Scroll( -1, (item_y+item_h-client_h+15)/m_yScroll ); |
92976ab6 RR |
2063 | } |
2064 | else | |
2065 | { | |
f6bcfd97 | 2066 | if (item_x-view_x < 5) |
cf3da716 | 2067 | Scroll( (item_x-5)/m_xScroll, -1 ); |
f6bcfd97 | 2068 | if (item_x+item_w-5 > view_x+client_w) |
cf3da716 | 2069 | Scroll( (item_x+item_w-client_w+15)/m_xScroll, -1 ); |
92976ab6 | 2070 | } |
e1e955e1 | 2071 | } |
c801d85f KB |
2072 | |
2073 | void wxListMainWindow::OnArrowChar( wxListLineData *newCurrent, bool shiftDown ) | |
2074 | { | |
92976ab6 RR |
2075 | if ((m_mode & wxLC_SINGLE_SEL) || (m_usedKeys == FALSE)) m_current->Hilight( FALSE ); |
2076 | wxListLineData *oldCurrent = m_current; | |
2077 | m_current = newCurrent; | |
92976ab6 RR |
2078 | if (shiftDown || (m_mode & wxLC_SINGLE_SEL)) m_current->Hilight( TRUE ); |
2079 | RefreshLine( m_current ); | |
2080 | RefreshLine( oldCurrent ); | |
2081 | FocusLine( m_current ); | |
2082 | UnfocusLine( oldCurrent ); | |
cf3da716 | 2083 | MoveToFocus(); |
e1e955e1 | 2084 | } |
c801d85f | 2085 | |
3dfb93fd RR |
2086 | void wxListMainWindow::OnKeyDown( wxKeyEvent &event ) |
2087 | { | |
2088 | wxWindow *parent = GetParent(); | |
004fd0c8 | 2089 | |
3dfb93fd RR |
2090 | /* we propagate the key event up */ |
2091 | wxKeyEvent ke( wxEVT_KEY_DOWN ); | |
2092 | ke.m_shiftDown = event.m_shiftDown; | |
2093 | ke.m_controlDown = event.m_controlDown; | |
2094 | ke.m_altDown = event.m_altDown; | |
2095 | ke.m_metaDown = event.m_metaDown; | |
2096 | ke.m_keyCode = event.m_keyCode; | |
2097 | ke.m_x = event.m_x; | |
2098 | ke.m_y = event.m_y; | |
2099 | ke.SetEventObject( parent ); | |
2100 | if (parent->GetEventHandler()->ProcessEvent( ke )) return; | |
004fd0c8 | 2101 | |
3dfb93fd RR |
2102 | event.Skip(); |
2103 | } | |
004fd0c8 | 2104 | |
c801d85f KB |
2105 | void wxListMainWindow::OnChar( wxKeyEvent &event ) |
2106 | { | |
51cc4dad | 2107 | wxWindow *parent = GetParent(); |
004fd0c8 | 2108 | |
51cc4dad | 2109 | /* we send a list_key event up */ |
f6bcfd97 BP |
2110 | if ( m_current ) |
2111 | { | |
2112 | wxListEvent le( wxEVT_COMMAND_LIST_KEY_DOWN, GetParent()->GetId() ); | |
2113 | le.m_itemIndex = GetIndexOfLine( m_current ); | |
2114 | m_current->GetItem( 0, le.m_item ); | |
2115 | le.m_code = (int)event.KeyCode(); | |
2116 | le.SetEventObject( parent ); | |
2117 | parent->GetEventHandler()->ProcessEvent( le ); | |
2118 | } | |
51cc4dad | 2119 | |
3dfb93fd RR |
2120 | /* we propagate the char event up */ |
2121 | wxKeyEvent ke( wxEVT_CHAR ); | |
51cc4dad RR |
2122 | ke.m_shiftDown = event.m_shiftDown; |
2123 | ke.m_controlDown = event.m_controlDown; | |
2124 | ke.m_altDown = event.m_altDown; | |
2125 | ke.m_metaDown = event.m_metaDown; | |
2126 | ke.m_keyCode = event.m_keyCode; | |
2127 | ke.m_x = event.m_x; | |
2128 | ke.m_y = event.m_y; | |
2129 | ke.SetEventObject( parent ); | |
2130 | if (parent->GetEventHandler()->ProcessEvent( ke )) return; | |
004fd0c8 | 2131 | |
012a03e0 RR |
2132 | if (event.KeyCode() == WXK_TAB) |
2133 | { | |
2134 | wxNavigationKeyEvent nevent; | |
c5145d41 | 2135 | nevent.SetWindowChange( event.ControlDown() ); |
012a03e0 | 2136 | nevent.SetDirection( !event.ShiftDown() ); |
8253c7fd | 2137 | nevent.SetEventObject( GetParent()->GetParent() ); |
012a03e0 | 2138 | nevent.SetCurrentFocus( m_parent ); |
8253c7fd | 2139 | if (GetParent()->GetParent()->GetEventHandler()->ProcessEvent( nevent )) return; |
012a03e0 | 2140 | } |
004fd0c8 | 2141 | |
51cc4dad RR |
2142 | /* no item -> nothing to do */ |
2143 | if (!m_current) | |
c801d85f | 2144 | { |
51cc4dad RR |
2145 | event.Skip(); |
2146 | return; | |
e1e955e1 | 2147 | } |
51cc4dad RR |
2148 | |
2149 | switch (event.KeyCode()) | |
c801d85f | 2150 | { |
51cc4dad RR |
2151 | case WXK_UP: |
2152 | { | |
f6bcfd97 BP |
2153 | int index = m_lines.Index(*m_current); |
2154 | if (index != wxNOT_FOUND && index > 0) | |
2155 | OnArrowChar( &m_lines[index-1], event.ShiftDown() ); | |
51cc4dad RR |
2156 | break; |
2157 | } | |
2158 | case WXK_DOWN: | |
2159 | { | |
f6bcfd97 BP |
2160 | int index = m_lines.Index(*m_current); |
2161 | if (index != wxNOT_FOUND && (size_t)index < m_lines.GetCount()-1) | |
2162 | OnArrowChar( &m_lines[index+1], event.ShiftDown() ); | |
51cc4dad RR |
2163 | break; |
2164 | } | |
2165 | case WXK_END: | |
2166 | { | |
f6bcfd97 BP |
2167 | if (!m_lines.IsEmpty()) |
2168 | OnArrowChar( &m_lines.Last(), event.ShiftDown() ); | |
51cc4dad RR |
2169 | break; |
2170 | } | |
2171 | case WXK_HOME: | |
2172 | { | |
f6bcfd97 BP |
2173 | if (!m_lines.IsEmpty()) |
2174 | OnArrowChar( &m_lines[0], event.ShiftDown() ); | |
51cc4dad RR |
2175 | break; |
2176 | } | |
2177 | case WXK_PRIOR: | |
2178 | { | |
2179 | int steps = 0; | |
f6bcfd97 | 2180 | int index = m_lines.Index(*m_current); |
004fd0c8 | 2181 | if (m_mode & wxLC_REPORT) |
bffa1c77 VZ |
2182 | { |
2183 | steps = m_visibleLines-1; | |
2184 | } | |
51cc4dad RR |
2185 | else |
2186 | { | |
f6bcfd97 BP |
2187 | steps = index % m_visibleLines; |
2188 | } | |
2189 | if (index != wxNOT_FOUND) | |
2190 | { | |
2191 | index -= steps; | |
3e1c4e00 | 2192 | if (index < 0) index = 0; |
f6bcfd97 | 2193 | OnArrowChar( &m_lines[index], event.ShiftDown() ); |
51cc4dad | 2194 | } |
51cc4dad RR |
2195 | break; |
2196 | } | |
2197 | case WXK_NEXT: | |
2198 | { | |
2199 | int steps = 0; | |
f6bcfd97 | 2200 | int index = m_lines.Index(*m_current); |
004fd0c8 | 2201 | if (m_mode & wxLC_REPORT) |
bffa1c77 VZ |
2202 | { |
2203 | steps = m_visibleLines-1; | |
2204 | } | |
51cc4dad RR |
2205 | else |
2206 | { | |
f6bcfd97 BP |
2207 | steps = m_visibleLines-(index % m_visibleLines)-1; |
2208 | } | |
2209 | ||
2210 | if (index != wxNOT_FOUND) | |
2211 | { | |
2212 | index += steps; | |
3e1c4e00 | 2213 | if ((size_t)index >= m_lines.GetCount()) |
f6bcfd97 BP |
2214 | index = m_lines.GetCount()-1; |
2215 | OnArrowChar( &m_lines[index], event.ShiftDown() ); | |
51cc4dad | 2216 | } |
51cc4dad RR |
2217 | break; |
2218 | } | |
2219 | case WXK_LEFT: | |
2220 | { | |
2221 | if (!(m_mode & wxLC_REPORT)) | |
2222 | { | |
f6bcfd97 BP |
2223 | int index = m_lines.Index(*m_current); |
2224 | if (index != wxNOT_FOUND) | |
2225 | { | |
2226 | index -= m_visibleLines; | |
2227 | if (index < 0) index = 0; | |
2228 | OnArrowChar( &m_lines[index], event.ShiftDown() ); | |
2229 | } | |
51cc4dad RR |
2230 | } |
2231 | break; | |
2232 | } | |
2233 | case WXK_RIGHT: | |
2234 | { | |
2235 | if (!(m_mode & wxLC_REPORT)) | |
2236 | { | |
f6bcfd97 BP |
2237 | int index = m_lines.Index(*m_current); |
2238 | if (index != wxNOT_FOUND) | |
2239 | { | |
2240 | index += m_visibleLines; | |
3e1c4e00 | 2241 | if ((size_t)index >= m_lines.GetCount()) |
f6bcfd97 BP |
2242 | index = m_lines.GetCount()-1; |
2243 | OnArrowChar( &m_lines[index], event.ShiftDown() ); | |
2244 | } | |
51cc4dad RR |
2245 | } |
2246 | break; | |
2247 | } | |
2248 | case WXK_SPACE: | |
2249 | { | |
33d0e17c RR |
2250 | if (m_mode & wxLC_SINGLE_SEL) |
2251 | { | |
2252 | wxListEvent le( wxEVT_COMMAND_LIST_ITEM_ACTIVATED, GetParent()->GetId() ); | |
2253 | le.SetEventObject( GetParent() ); | |
2254 | le.m_itemIndex = GetIndexOfLine( m_current ); | |
2255 | m_current->GetItem( 0, le.m_item ); | |
2256 | GetParent()->GetEventHandler()->ProcessEvent( le ); | |
2257 | } | |
2258 | else | |
2259 | { | |
2260 | m_current->ReverseHilight(); | |
2261 | RefreshLine( m_current ); | |
2262 | } | |
51cc4dad RR |
2263 | break; |
2264 | } | |
2265 | case WXK_INSERT: | |
2266 | { | |
2267 | if (!(m_mode & wxLC_SINGLE_SEL)) | |
2268 | { | |
2269 | wxListLineData *oldCurrent = m_current; | |
2270 | m_current->ReverseHilight(); | |
f6bcfd97 BP |
2271 | int index = m_lines.Index( *m_current ) + 1; |
2272 | if ( (size_t)index < m_lines.GetCount() ) | |
2273 | m_current = &m_lines[index]; | |
51cc4dad RR |
2274 | RefreshLine( oldCurrent ); |
2275 | RefreshLine( m_current ); | |
2276 | UnfocusLine( oldCurrent ); | |
2277 | FocusLine( m_current ); | |
cf3da716 | 2278 | MoveToFocus(); |
51cc4dad RR |
2279 | } |
2280 | break; | |
2281 | } | |
2282 | case WXK_RETURN: | |
2283 | case WXK_EXECUTE: | |
2284 | { | |
2285 | wxListEvent le( wxEVT_COMMAND_LIST_ITEM_ACTIVATED, GetParent()->GetId() ); | |
2286 | le.SetEventObject( GetParent() ); | |
2287 | le.m_itemIndex = GetIndexOfLine( m_current ); | |
2288 | m_current->GetItem( 0, le.m_item ); | |
2289 | GetParent()->GetEventHandler()->ProcessEvent( le ); | |
2290 | break; | |
2291 | } | |
2292 | default: | |
2293 | { | |
2294 | event.Skip(); | |
2295 | return; | |
2296 | } | |
e1e955e1 | 2297 | } |
51cc4dad | 2298 | m_usedKeys = TRUE; |
e1e955e1 | 2299 | } |
c801d85f | 2300 | |
cae5359f RR |
2301 | #ifdef __WXGTK__ |
2302 | extern wxWindow *g_focusWindow; | |
2303 | #endif | |
2304 | ||
c801d85f KB |
2305 | void wxListMainWindow::OnSetFocus( wxFocusEvent &WXUNUSED(event) ) |
2306 | { | |
63852e78 RR |
2307 | m_hasFocus = TRUE; |
2308 | RefreshLine( m_current ); | |
bd8289c1 | 2309 | |
63852e78 | 2310 | if (!GetParent()) return; |
004fd0c8 | 2311 | |
cae5359f RR |
2312 | #ifdef __WXGTK__ |
2313 | g_focusWindow = GetParent(); | |
2314 | #endif | |
bd8289c1 | 2315 | |
63852e78 RR |
2316 | wxFocusEvent event( wxEVT_SET_FOCUS, GetParent()->GetId() ); |
2317 | event.SetEventObject( GetParent() ); | |
2318 | GetParent()->GetEventHandler()->ProcessEvent( event ); | |
e1e955e1 | 2319 | } |
c801d85f KB |
2320 | |
2321 | void wxListMainWindow::OnKillFocus( wxFocusEvent &WXUNUSED(event) ) | |
2322 | { | |
63852e78 RR |
2323 | m_hasFocus = FALSE; |
2324 | RefreshLine( m_current ); | |
e1e955e1 | 2325 | } |
c801d85f KB |
2326 | |
2327 | void wxListMainWindow::OnSize( wxSizeEvent &WXUNUSED(event) ) | |
2328 | { | |
2329 | /* | |
2330 | We don't even allow the wxScrolledWindow::AdjustScrollbars() call | |
004fd0c8 | 2331 | |
c801d85f | 2332 | */ |
2035e10e | 2333 | m_dirty = TRUE; |
e1e955e1 | 2334 | } |
c801d85f | 2335 | |
1e6d9499 | 2336 | void wxListMainWindow::DrawImage( int index, wxDC *dc, int x, int y ) |
c801d85f | 2337 | { |
63852e78 RR |
2338 | if ((m_mode & wxLC_ICON) && (m_normal_image_list)) |
2339 | { | |
2340 | m_normal_image_list->Draw( index, *dc, x, y, wxIMAGELIST_DRAW_TRANSPARENT ); | |
2341 | return; | |
2342 | } | |
2343 | if ((m_mode & wxLC_SMALL_ICON) && (m_small_image_list)) | |
2344 | { | |
2345 | m_small_image_list->Draw( index, *dc, x, y, wxIMAGELIST_DRAW_TRANSPARENT ); | |
2346 | } | |
0b855868 RR |
2347 | if ((m_mode & wxLC_LIST) && (m_small_image_list)) |
2348 | { | |
2349 | m_small_image_list->Draw( index, *dc, x, y, wxIMAGELIST_DRAW_TRANSPARENT ); | |
2350 | } | |
63852e78 RR |
2351 | if ((m_mode & wxLC_REPORT) && (m_small_image_list)) |
2352 | { | |
2353 | m_small_image_list->Draw( index, *dc, x, y, wxIMAGELIST_DRAW_TRANSPARENT ); | |
2354 | return; | |
2355 | } | |
e1e955e1 | 2356 | } |
c801d85f KB |
2357 | |
2358 | void wxListMainWindow::GetImageSize( int index, int &width, int &height ) | |
2359 | { | |
63852e78 RR |
2360 | if ((m_mode & wxLC_ICON) && (m_normal_image_list)) |
2361 | { | |
2362 | m_normal_image_list->GetSize( index, width, height ); | |
2363 | return; | |
2364 | } | |
2365 | if ((m_mode & wxLC_SMALL_ICON) && (m_small_image_list)) | |
2366 | { | |
2367 | m_small_image_list->GetSize( index, width, height ); | |
2368 | return; | |
2369 | } | |
0b855868 RR |
2370 | if ((m_mode & wxLC_LIST) && (m_small_image_list)) |
2371 | { | |
2372 | m_small_image_list->GetSize( index, width, height ); | |
2373 | return; | |
2374 | } | |
63852e78 RR |
2375 | if ((m_mode & wxLC_REPORT) && (m_small_image_list)) |
2376 | { | |
2377 | m_small_image_list->GetSize( index, width, height ); | |
2378 | return; | |
2379 | } | |
2380 | width = 0; | |
2381 | height = 0; | |
e1e955e1 | 2382 | } |
c801d85f KB |
2383 | |
2384 | int wxListMainWindow::GetTextLength( wxString &s ) | |
2385 | { | |
1e6d9499 | 2386 | wxClientDC dc( this ); |
13111b2a VZ |
2387 | wxCoord lw = 0; |
2388 | wxCoord lh = 0; | |
139adb6a RR |
2389 | dc.GetTextExtent( s, &lw, &lh ); |
2390 | return lw + 6; | |
e1e955e1 | 2391 | } |
c801d85f KB |
2392 | |
2393 | int wxListMainWindow::GetIndexOfLine( const wxListLineData *line ) | |
2394 | { | |
f6bcfd97 BP |
2395 | int i = m_lines.Index(*line); |
2396 | if (i == wxNOT_FOUND) return -1; | |
2397 | else return i; | |
e1e955e1 | 2398 | } |
c801d85f | 2399 | |
debe6624 | 2400 | void wxListMainWindow::SetImageList( wxImageList *imageList, int which ) |
c801d85f | 2401 | { |
139adb6a | 2402 | m_dirty = TRUE; |
f6bcfd97 BP |
2403 | |
2404 | // calc the spacing from the icon size | |
2405 | int width = 0, | |
2406 | height = 0; | |
2407 | if ((imageList) && (imageList->GetImageCount()) ) | |
2408 | { | |
2409 | imageList->GetSize(0, width, height); | |
2410 | } | |
2411 | ||
2412 | if (which == wxIMAGE_LIST_NORMAL) | |
2413 | { | |
2414 | m_normal_image_list = imageList; | |
2415 | m_normal_spacing = width + 8; | |
2416 | } | |
2417 | ||
2418 | if (which == wxIMAGE_LIST_SMALL) | |
2419 | { | |
2420 | m_small_image_list = imageList; | |
2421 | m_small_spacing = width + 14; | |
2422 | } | |
e1e955e1 | 2423 | } |
c801d85f | 2424 | |
debe6624 | 2425 | void wxListMainWindow::SetItemSpacing( int spacing, bool isSmall ) |
c801d85f | 2426 | { |
139adb6a RR |
2427 | m_dirty = TRUE; |
2428 | if (isSmall) | |
2429 | { | |
2430 | m_small_spacing = spacing; | |
2431 | } | |
2432 | else | |
2433 | { | |
2434 | m_normal_spacing = spacing; | |
2435 | } | |
e1e955e1 | 2436 | } |
c801d85f | 2437 | |
debe6624 | 2438 | int wxListMainWindow::GetItemSpacing( bool isSmall ) |
c801d85f | 2439 | { |
f6bcfd97 | 2440 | return isSmall ? m_small_spacing : m_normal_spacing; |
e1e955e1 | 2441 | } |
c801d85f | 2442 | |
debe6624 | 2443 | void wxListMainWindow::SetColumn( int col, wxListItem &item ) |
c801d85f | 2444 | { |
63852e78 RR |
2445 | m_dirty = TRUE; |
2446 | wxNode *node = m_columns.Nth( col ); | |
2447 | if (node) | |
2448 | { | |
2449 | if (item.m_width == wxLIST_AUTOSIZE_USEHEADER) item.m_width = GetTextLength( item.m_text )+7; | |
2450 | wxListHeaderData *column = (wxListHeaderData*)node->Data(); | |
2451 | column->SetItem( item ); | |
2452 | } | |
f6bcfd97 BP |
2453 | |
2454 | wxListHeaderWindow *headerWin = ((wxListCtrl*) GetParent())->m_headerWin; | |
2455 | if ( headerWin ) | |
2456 | headerWin->m_dirty = TRUE; | |
e1e955e1 | 2457 | } |
c801d85f | 2458 | |
debe6624 | 2459 | void wxListMainWindow::SetColumnWidth( int col, int width ) |
c801d85f | 2460 | { |
f6bcfd97 BP |
2461 | wxCHECK_RET( m_mode & wxLC_REPORT, |
2462 | _T("SetColumnWidth() can only be called in report mode.") ); | |
0208334d | 2463 | |
63852e78 | 2464 | m_dirty = TRUE; |
bd8289c1 | 2465 | |
0180dad6 RR |
2466 | wxNode *node = (wxNode*) NULL; |
2467 | ||
f6bcfd97 BP |
2468 | if (width == wxLIST_AUTOSIZE_USEHEADER) |
2469 | { | |
2470 | // TODO do use the header | |
2471 | width = 80; | |
2472 | } | |
2473 | else if (width == wxLIST_AUTOSIZE) | |
0180dad6 RR |
2474 | { |
2475 | wxClientDC dc(this); | |
2476 | dc.SetFont( GetFont() ); | |
2477 | int max = 10; | |
3e1c4e00 | 2478 | |
f6bcfd97 | 2479 | for (size_t i = 0; i < m_lines.GetCount(); i++) |
0180dad6 | 2480 | { |
f6bcfd97 | 2481 | wxListLineData *line = &m_lines[i]; |
0180dad6 RR |
2482 | wxNode *n = line->m_items.Nth( col ); |
2483 | if (n) | |
2484 | { | |
2485 | wxListItemData *item = (wxListItemData*)n->Data(); | |
bffa1c77 | 2486 | int current = 0, ix = 0, iy = 0; |
13111b2a | 2487 | wxCoord lx = 0, ly = 0; |
bffa1c77 VZ |
2488 | if (item->HasImage()) |
2489 | { | |
0180dad6 | 2490 | GetImageSize( item->GetImage(), ix, iy ); |
bffa1c77 VZ |
2491 | current = ix + 5; |
2492 | } | |
2493 | if (item->HasText()) | |
2494 | { | |
2495 | wxString str; | |
2496 | item->GetText( str ); | |
2497 | dc.GetTextExtent( str, &lx, &ly ); | |
2498 | current += lx; | |
2499 | } | |
2500 | if (current > max) max = current; | |
0180dad6 | 2501 | } |
0180dad6 | 2502 | } |
bffa1c77 | 2503 | width = max+10; |
0180dad6 RR |
2504 | } |
2505 | ||
2506 | node = m_columns.Nth( col ); | |
63852e78 RR |
2507 | if (node) |
2508 | { | |
2509 | wxListHeaderData *column = (wxListHeaderData*)node->Data(); | |
2510 | column->SetWidth( width ); | |
2511 | } | |
bd8289c1 | 2512 | |
f6bcfd97 | 2513 | for (size_t i = 0; i < m_lines.GetCount(); i++) |
0208334d | 2514 | { |
f6bcfd97 | 2515 | wxListLineData *line = &m_lines[i]; |
63852e78 RR |
2516 | wxNode *n = line->m_items.Nth( col ); |
2517 | if (n) | |
2518 | { | |
2519 | wxListItemData *item = (wxListItemData*)n->Data(); | |
2520 | item->SetSize( width, -1 ); | |
2521 | } | |
0208334d | 2522 | } |
bd8289c1 | 2523 | |
f6bcfd97 BP |
2524 | wxListHeaderWindow *headerWin = ((wxListCtrl*) GetParent())->m_headerWin; |
2525 | if ( headerWin ) | |
2526 | headerWin->m_dirty = TRUE; | |
e1e955e1 | 2527 | } |
c801d85f | 2528 | |
debe6624 | 2529 | void wxListMainWindow::GetColumn( int col, wxListItem &item ) |
c801d85f | 2530 | { |
63852e78 RR |
2531 | wxNode *node = m_columns.Nth( col ); |
2532 | if (node) | |
2533 | { | |
2534 | wxListHeaderData *column = (wxListHeaderData*)node->Data(); | |
2535 | column->GetItem( item ); | |
2536 | } | |
2537 | else | |
2538 | { | |
2539 | item.m_format = 0; | |
2540 | item.m_width = 0; | |
2541 | item.m_text = ""; | |
2542 | item.m_image = 0; | |
2543 | item.m_data = 0; | |
2544 | } | |
e1e955e1 | 2545 | } |
c801d85f | 2546 | |
bd8289c1 | 2547 | int wxListMainWindow::GetColumnWidth( int col ) |
c801d85f | 2548 | { |
92976ab6 RR |
2549 | wxNode *node = m_columns.Nth( col ); |
2550 | if (node) | |
2551 | { | |
2552 | wxListHeaderData *column = (wxListHeaderData*)node->Data(); | |
2553 | return column->GetWidth(); | |
2554 | } | |
2555 | else | |
2556 | { | |
004fd0c8 | 2557 | return 0; |
92976ab6 | 2558 | } |
e1e955e1 | 2559 | } |
c801d85f | 2560 | |
e179bd65 | 2561 | int wxListMainWindow::GetColumnCount() |
c801d85f | 2562 | { |
92976ab6 | 2563 | return m_columns.Number(); |
e1e955e1 | 2564 | } |
c801d85f | 2565 | |
e179bd65 | 2566 | int wxListMainWindow::GetCountPerPage() |
c801d85f | 2567 | { |
92976ab6 | 2568 | return m_visibleLines; |
e1e955e1 | 2569 | } |
c801d85f KB |
2570 | |
2571 | void wxListMainWindow::SetItem( wxListItem &item ) | |
2572 | { | |
92976ab6 | 2573 | m_dirty = TRUE; |
f6bcfd97 | 2574 | if (item.m_itemId >= 0 && (size_t)item.m_itemId < m_lines.GetCount()) |
92976ab6 | 2575 | { |
f6bcfd97 | 2576 | wxListLineData *line = &m_lines[(size_t)item.m_itemId]; |
92976ab6 RR |
2577 | if (m_mode & wxLC_REPORT) item.m_width = GetColumnWidth( item.m_col )-3; |
2578 | line->SetItem( item.m_col, item ); | |
2579 | } | |
e1e955e1 | 2580 | } |
c801d85f | 2581 | |
debe6624 | 2582 | void wxListMainWindow::SetItemState( long item, long state, long stateMask ) |
c801d85f | 2583 | { |
92976ab6 | 2584 | // m_dirty = TRUE; no recalcs needed |
bd8289c1 | 2585 | |
92976ab6 | 2586 | wxListLineData *oldCurrent = m_current; |
bd8289c1 | 2587 | |
92976ab6 | 2588 | if (stateMask & wxLIST_STATE_FOCUSED) |
c801d85f | 2589 | { |
f6bcfd97 | 2590 | if (item >= 0 && (size_t)item < m_lines.GetCount()) |
92976ab6 | 2591 | { |
f6bcfd97 | 2592 | wxListLineData *line = &m_lines[(size_t)item]; |
92976ab6 RR |
2593 | UnfocusLine( m_current ); |
2594 | m_current = line; | |
2595 | FocusLine( m_current ); | |
4aefa363 | 2596 | if ((m_mode & wxLC_SINGLE_SEL) && oldCurrent) oldCurrent->Hilight( FALSE ); |
92976ab6 | 2597 | RefreshLine( m_current ); |
00a39542 | 2598 | if (oldCurrent) RefreshLine( oldCurrent ); |
92976ab6 | 2599 | } |
e1e955e1 | 2600 | } |
bd8289c1 | 2601 | |
92976ab6 | 2602 | if (stateMask & wxLIST_STATE_SELECTED) |
c801d85f | 2603 | { |
6f2a55e3 | 2604 | bool on = (state & wxLIST_STATE_SELECTED) != 0; |
92976ab6 RR |
2605 | if (!on && (m_mode & wxLC_SINGLE_SEL)) return; |
2606 | ||
f6bcfd97 | 2607 | if (item >= 0 && (size_t)item < m_lines.GetCount()) |
92976ab6 | 2608 | { |
f6bcfd97 | 2609 | wxListLineData *line = &m_lines[(size_t)item]; |
92976ab6 RR |
2610 | if (m_mode & wxLC_SINGLE_SEL) |
2611 | { | |
2612 | UnfocusLine( m_current ); | |
2613 | m_current = line; | |
2614 | FocusLine( m_current ); | |
00a39542 | 2615 | if (oldCurrent) oldCurrent->Hilight( FALSE ); |
92976ab6 | 2616 | RefreshLine( m_current ); |
00a39542 | 2617 | if (oldCurrent) RefreshLine( oldCurrent ); |
92976ab6 | 2618 | } |
6f2a55e3 | 2619 | bool on = (state & wxLIST_STATE_SELECTED) != 0; |
bffa1c77 VZ |
2620 | if (on != line->IsHilighted()) |
2621 | { | |
139adb6a RR |
2622 | line->Hilight( on ); |
2623 | RefreshLine( line ); | |
bffa1c77 | 2624 | } |
92976ab6 | 2625 | } |
e1e955e1 | 2626 | } |
e1e955e1 | 2627 | } |
c801d85f | 2628 | |
debe6624 | 2629 | int wxListMainWindow::GetItemState( long item, long stateMask ) |
c801d85f | 2630 | { |
92976ab6 RR |
2631 | int ret = wxLIST_STATE_DONTCARE; |
2632 | if (stateMask & wxLIST_STATE_FOCUSED) | |
c801d85f | 2633 | { |
f6bcfd97 | 2634 | if (item >= 0 && (size_t)item < m_lines.GetCount()) |
92976ab6 | 2635 | { |
f6bcfd97 | 2636 | wxListLineData *line = &m_lines[(size_t)item]; |
92976ab6 RR |
2637 | if (line == m_current) ret |= wxLIST_STATE_FOCUSED; |
2638 | } | |
e1e955e1 | 2639 | } |
92976ab6 | 2640 | if (stateMask & wxLIST_STATE_SELECTED) |
c801d85f | 2641 | { |
f6bcfd97 | 2642 | if (item >= 0 && (size_t)item < m_lines.GetCount()) |
92976ab6 | 2643 | { |
f6bcfd97 | 2644 | wxListLineData *line = &m_lines[(size_t)item]; |
92976ab6 RR |
2645 | if (line->IsHilighted()) ret |= wxLIST_STATE_FOCUSED; |
2646 | } | |
e1e955e1 | 2647 | } |
92976ab6 | 2648 | return ret; |
e1e955e1 | 2649 | } |
c801d85f KB |
2650 | |
2651 | void wxListMainWindow::GetItem( wxListItem &item ) | |
2652 | { | |
f6bcfd97 | 2653 | if (item.m_itemId >= 0 && (size_t)item.m_itemId < m_lines.GetCount()) |
92976ab6 | 2654 | { |
f6bcfd97 | 2655 | wxListLineData *line = &m_lines[(size_t)item.m_itemId]; |
92976ab6 RR |
2656 | line->GetItem( item.m_col, item ); |
2657 | } | |
2658 | else | |
2659 | { | |
2660 | item.m_mask = 0; | |
2661 | item.m_text = ""; | |
2662 | item.m_image = 0; | |
2663 | item.m_data = 0; | |
2664 | } | |
e1e955e1 | 2665 | } |
c801d85f | 2666 | |
e179bd65 | 2667 | int wxListMainWindow::GetItemCount() |
c801d85f | 2668 | { |
f6bcfd97 | 2669 | return m_lines.GetCount(); |
e1e955e1 | 2670 | } |
c801d85f | 2671 | |
0a240683 | 2672 | void wxListMainWindow::GetItemRect( long index, wxRect &rect ) |
c801d85f | 2673 | { |
f6bcfd97 | 2674 | if (index >= 0 && (size_t)index < m_lines.GetCount()) |
92976ab6 | 2675 | { |
f6bcfd97 | 2676 | m_lines[(size_t)index].GetRect( rect ); |
ea5ac909 | 2677 | this->CalcScrolledPosition(rect.x,rect.y,&rect.x,&rect.y); |
92976ab6 RR |
2678 | } |
2679 | else | |
2680 | { | |
2681 | rect.x = 0; | |
2682 | rect.y = 0; | |
2683 | rect.width = 0; | |
2684 | rect.height = 0; | |
2685 | } | |
e1e955e1 | 2686 | } |
c801d85f | 2687 | |
e3e65dac RR |
2688 | bool wxListMainWindow::GetItemPosition(long item, wxPoint& pos) |
2689 | { | |
ea5ac909 VZ |
2690 | wxRect rect; |
2691 | this->GetItemRect(item,rect); | |
2692 | pos.x=rect.x; pos.y=rect.y; | |
92976ab6 | 2693 | return TRUE; |
e1e955e1 | 2694 | } |
e3e65dac | 2695 | |
e179bd65 | 2696 | int wxListMainWindow::GetSelectedItemCount() |
c801d85f | 2697 | { |
92976ab6 | 2698 | int ret = 0; |
f6bcfd97 | 2699 | for (size_t i = 0; i < m_lines.GetCount(); i++) |
92976ab6 | 2700 | { |
f6bcfd97 | 2701 | if (m_lines[i].IsHilighted()) ret++; |
92976ab6 RR |
2702 | } |
2703 | return ret; | |
e1e955e1 | 2704 | } |
c801d85f | 2705 | |
debe6624 | 2706 | void wxListMainWindow::SetMode( long mode ) |
c801d85f | 2707 | { |
92976ab6 RR |
2708 | m_dirty = TRUE; |
2709 | m_mode = mode; | |
bd8289c1 | 2710 | |
92976ab6 | 2711 | DeleteEverything(); |
bd8289c1 | 2712 | |
92976ab6 RR |
2713 | if (m_mode & wxLC_REPORT) |
2714 | { | |
7c74e7fe SC |
2715 | #if wxUSE_GENERIC_LIST_EXTENSIONS |
2716 | m_xScroll = 15; | |
2717 | #else | |
92976ab6 | 2718 | m_xScroll = 0; |
7c74e7fe | 2719 | #endif |
92976ab6 RR |
2720 | m_yScroll = 15; |
2721 | } | |
2722 | else | |
2723 | { | |
2724 | m_xScroll = 15; | |
2725 | m_yScroll = 0; | |
2726 | } | |
e1e955e1 | 2727 | } |
c801d85f | 2728 | |
e179bd65 | 2729 | long wxListMainWindow::GetMode() const |
c801d85f | 2730 | { |
63852e78 | 2731 | return m_mode; |
e1e955e1 | 2732 | } |
c801d85f | 2733 | |
e179bd65 | 2734 | void wxListMainWindow::CalculatePositions() |
c801d85f | 2735 | { |
f6bcfd97 | 2736 | if (m_lines.IsEmpty()) return; |
e487524e | 2737 | |
1e6d9499 | 2738 | wxClientDC dc( this ); |
92976ab6 | 2739 | dc.SetFont( GetFont() ); |
c801d85f | 2740 | |
92976ab6 RR |
2741 | int iconSpacing = 0; |
2742 | if (m_mode & wxLC_ICON) iconSpacing = m_normal_spacing; | |
2743 | if (m_mode & wxLC_SMALL_ICON) iconSpacing = m_small_spacing; | |
004fd0c8 | 2744 | |
92976ab6 RR |
2745 | // we take the first line (which also can be an icon or |
2746 | // an a text item in wxLC_ICON and wxLC_LIST modes) to | |
2747 | // measure the size of the line | |
004fd0c8 | 2748 | |
92976ab6 RR |
2749 | int lineWidth = 0; |
2750 | int lineHeight = 0; | |
2751 | int lineSpacing = 0; | |
c801d85f | 2752 | |
f6bcfd97 | 2753 | wxListLineData *line = &m_lines[0]; |
92976ab6 RR |
2754 | line->CalculateSize( &dc, iconSpacing ); |
2755 | int dummy = 0; | |
2756 | line->GetSize( dummy, lineSpacing ); | |
5d25c050 | 2757 | lineSpacing += 1; |
bd8289c1 | 2758 | |
92976ab6 RR |
2759 | int clientWidth = 0; |
2760 | int clientHeight = 0; | |
bd8289c1 | 2761 | |
92976ab6 | 2762 | if (m_mode & wxLC_REPORT) |
c801d85f | 2763 | { |
08bf1d5d RR |
2764 | // scroll one line per step |
2765 | m_yScroll = lineSpacing; | |
2766 | ||
92976ab6 RR |
2767 | int x = 4; |
2768 | int y = 1; | |
f6bcfd97 | 2769 | int entireHeight = m_lines.GetCount() * lineSpacing + 2; |
92976ab6 | 2770 | int scroll_pos = GetScrollPos( wxVERTICAL ); |
7c74e7fe | 2771 | #if wxUSE_GENERIC_LIST_EXTENSIONS |
7c0ea335 | 2772 | int x_scroll_pos = GetScrollPos( wxHORIZONTAL ); |
7c74e7fe | 2773 | #else |
08bf1d5d | 2774 | SetScrollbars( m_xScroll, m_yScroll, 0, entireHeight/m_yScroll +1, 0, scroll_pos, TRUE ); |
7c74e7fe | 2775 | #endif |
92976ab6 RR |
2776 | GetClientSize( &clientWidth, &clientHeight ); |
2777 | ||
7c74e7fe | 2778 | int entireWidth = 0 ; |
f6bcfd97 | 2779 | for (size_t j = 0; j < m_lines.GetCount(); j++) |
92976ab6 | 2780 | { |
f6bcfd97 | 2781 | wxListLineData *line = &m_lines[j]; |
92976ab6 RR |
2782 | line->CalculateSize( &dc, iconSpacing ); |
2783 | line->SetPosition( &dc, x, y, clientWidth ); | |
2784 | int col_x = 2; | |
2785 | for (int i = 0; i < GetColumnCount(); i++) | |
2786 | { | |
2787 | line->SetColumnPosition( i, col_x ); | |
2788 | col_x += GetColumnWidth( i ); | |
2789 | } | |
7c74e7fe SC |
2790 | entireWidth = wxMax( entireWidth , col_x ) ; |
2791 | #if wxUSE_GENERIC_LIST_EXTENSIONS | |
2792 | line->SetPosition( &dc, x, y, col_x ); | |
2793 | #endif | |
92976ab6 | 2794 | y += lineSpacing; // one pixel blank line between items |
92976ab6 | 2795 | } |
08bf1d5d | 2796 | m_visibleLines = clientHeight / lineSpacing; |
7c74e7fe | 2797 | #if wxUSE_GENERIC_LIST_EXTENSIONS |
08bf1d5d | 2798 | SetScrollbars( m_xScroll, m_yScroll, entireWidth/m_xScroll +1, entireHeight/m_yScroll +1, x_scroll_pos , scroll_pos, TRUE ); |
7c74e7fe | 2799 | #endif |
e1e955e1 | 2800 | } |
92976ab6 RR |
2801 | else |
2802 | { | |
2803 | // at first we try without any scrollbar. if the items don't | |
2804 | // fit into the window, we recalculate after subtracting an | |
2805 | // approximated 15 pt for the horizontal scrollbar | |
004fd0c8 | 2806 | |
92976ab6 | 2807 | GetSize( &clientWidth, &clientHeight ); |
bffa1c77 | 2808 | clientHeight -= 4; // sunken frame |
bd8289c1 | 2809 | |
92976ab6 | 2810 | int entireWidth = 0; |
bd8289c1 | 2811 | |
92976ab6 | 2812 | for (int tries = 0; tries < 2; tries++) |
e487524e | 2813 | { |
92976ab6 | 2814 | entireWidth = 0; |
5d25c050 RR |
2815 | int x = 2; |
2816 | int y = 2; | |
92976ab6 | 2817 | int maxWidth = 0; |
0b855868 | 2818 | m_visibleLines = 0; |
bffa1c77 | 2819 | int m_currentVisibleLines = 0; |
f6bcfd97 | 2820 | for (size_t i = 0; i < m_lines.GetCount(); i++) |
92976ab6 | 2821 | { |
bffa1c77 | 2822 | m_currentVisibleLines++; |
f6bcfd97 | 2823 | wxListLineData *line = &m_lines[i]; |
92976ab6 RR |
2824 | line->CalculateSize( &dc, iconSpacing ); |
2825 | line->SetPosition( &dc, x, y, clientWidth ); | |
2826 | line->GetSize( lineWidth, lineHeight ); | |
2827 | if (lineWidth > maxWidth) maxWidth = lineWidth; | |
2828 | y += lineSpacing; | |
bffa1c77 VZ |
2829 | if (m_currentVisibleLines > m_visibleLines) |
2830 | m_visibleLines = m_currentVisibleLines; | |
8b53e5a2 | 2831 | if (y+lineSpacing-6 >= clientHeight) // -6 for earlier "line breaking" |
92976ab6 | 2832 | { |
bffa1c77 | 2833 | m_currentVisibleLines = 0; |
e1208c31 | 2834 | y = 2; |
8b53e5a2 RR |
2835 | x += maxWidth+6; |
2836 | entireWidth += maxWidth+6; | |
92976ab6 RR |
2837 | maxWidth = 0; |
2838 | } | |
f6bcfd97 | 2839 | if (i == m_lines.GetCount()-1) entireWidth += maxWidth; |
92976ab6 RR |
2840 | if ((tries == 0) && (entireWidth > clientWidth)) |
2841 | { | |
2842 | clientHeight -= 15; // scrollbar height | |
0b855868 | 2843 | m_visibleLines = 0; |
bffa1c77 | 2844 | m_currentVisibleLines = 0; |
92976ab6 RR |
2845 | break; |
2846 | } | |
f6bcfd97 | 2847 | if (i == m_lines.GetCount()-1) tries = 1; // everything fits, no second try required |
92976ab6 | 2848 | } |
e487524e | 2849 | } |
bffa1c77 | 2850 | |
92976ab6 RR |
2851 | int scroll_pos = GetScrollPos( wxHORIZONTAL ); |
2852 | SetScrollbars( m_xScroll, m_yScroll, (entireWidth+15) / m_xScroll, 0, scroll_pos, 0, TRUE ); | |
e1e955e1 | 2853 | } |
e1e955e1 | 2854 | } |
c801d85f | 2855 | |
f6bcfd97 | 2856 | void wxListMainWindow::RealizeChanges() |
c801d85f | 2857 | { |
92976ab6 RR |
2858 | if (!m_current) |
2859 | { | |
f6bcfd97 BP |
2860 | if (!m_lines.IsEmpty()) |
2861 | m_current = &m_lines[0]; | |
92976ab6 RR |
2862 | } |
2863 | if (m_current) | |
2864 | { | |
2865 | FocusLine( m_current ); | |
f6bcfd97 BP |
2866 | // TODO: MSW doesn't automatically hilight the |
2867 | // first item. | |
2868 | // if (m_mode & wxLC_SINGLE_SEL) m_current->Hilight( TRUE ); | |
92976ab6 | 2869 | } |
e1e955e1 | 2870 | } |
c801d85f | 2871 | |
19695fbd VZ |
2872 | long wxListMainWindow::GetNextItem( long item, |
2873 | int WXUNUSED(geometry), | |
2874 | int state ) | |
c801d85f | 2875 | { |
d1022fd6 VZ |
2876 | long ret = item, |
2877 | max = GetItemCount(); | |
2878 | wxCHECK_MSG( (ret == -1) || (ret < max), -1, | |
13771c08 | 2879 | _T("invalid listctrl index in GetNextItem()") ); |
19695fbd VZ |
2880 | |
2881 | // notice that we start with the next item (or the first one if item == -1) | |
2882 | // and this is intentional to allow writing a simple loop to iterate over | |
2883 | // all selected items | |
d1022fd6 VZ |
2884 | ret++; |
2885 | if ( ret == max ) | |
2886 | { | |
2887 | // this is not an error because the index was ok initially, just no | |
2888 | // such item | |
2889 | return -1; | |
2890 | } | |
2891 | ||
f6bcfd97 | 2892 | for (size_t i = (size_t)ret; i < m_lines.GetCount(); i++) |
63852e78 | 2893 | { |
f6bcfd97 | 2894 | wxListLineData *line = &m_lines[i]; |
19695fbd VZ |
2895 | if ((state & wxLIST_STATE_FOCUSED) && (line == m_current)) |
2896 | return ret; | |
2897 | if ((state & wxLIST_STATE_SELECTED) && (line->IsHilighted())) | |
2898 | return ret; | |
2899 | if (!state) | |
2900 | return ret; | |
63852e78 | 2901 | ret++; |
63852e78 | 2902 | } |
19695fbd | 2903 | |
63852e78 | 2904 | return -1; |
e1e955e1 | 2905 | } |
c801d85f | 2906 | |
debe6624 | 2907 | void wxListMainWindow::DeleteItem( long index ) |
c801d85f | 2908 | { |
63852e78 | 2909 | m_dirty = TRUE; |
f6bcfd97 | 2910 | if (index >= 0 && (size_t)index < m_lines.GetCount()) |
63852e78 | 2911 | { |
f6bcfd97 | 2912 | wxListLineData *line = &m_lines[(size_t)index]; |
63852e78 RR |
2913 | if (m_current == line) m_current = (wxListLineData *) NULL; |
2914 | DeleteLine( line ); | |
f6bcfd97 | 2915 | m_lines.RemoveAt( (size_t)index ); |
63852e78 | 2916 | } |
e1e955e1 | 2917 | } |
c801d85f | 2918 | |
debe6624 | 2919 | void wxListMainWindow::DeleteColumn( int col ) |
c801d85f | 2920 | { |
5b077d48 | 2921 | wxCHECK_RET( col < (int)m_columns.GetCount(), |
223d09f6 | 2922 | wxT("attempting to delete inexistent column in wxListView") ); |
bd8289c1 | 2923 | |
5b077d48 RR |
2924 | m_dirty = TRUE; |
2925 | wxNode *node = m_columns.Nth( col ); | |
2926 | if (node) m_columns.DeleteNode( node ); | |
e1e955e1 | 2927 | } |
c801d85f | 2928 | |
12c1b46a | 2929 | void wxListMainWindow::DeleteAllItems() |
c801d85f | 2930 | { |
5b077d48 RR |
2931 | m_dirty = TRUE; |
2932 | m_current = (wxListLineData *) NULL; | |
7c0ea335 VZ |
2933 | |
2934 | // to make the deletion of all items faster, we don't send the | |
2935 | // notifications in this case: this is compatible with wxMSW and | |
2936 | // documented in DeleteAllItems() description | |
bffa1c77 | 2937 | |
12c1b46a RR |
2938 | wxListEvent event( wxEVT_COMMAND_LIST_DELETE_ALL_ITEMS, GetParent()->GetId() ); |
2939 | event.SetEventObject( GetParent() ); | |
2940 | GetParent()->GetEventHandler()->ProcessEvent( event ); | |
7c0ea335 | 2941 | |
5b077d48 | 2942 | m_lines.Clear(); |
e1e955e1 | 2943 | } |
c801d85f | 2944 | |
12c1b46a | 2945 | void wxListMainWindow::DeleteEverything() |
c801d85f | 2946 | { |
12c1b46a | 2947 | DeleteAllItems(); |
f6bcfd97 | 2948 | |
5b077d48 | 2949 | m_columns.Clear(); |
e1e955e1 | 2950 | } |
c801d85f | 2951 | |
debe6624 | 2952 | void wxListMainWindow::EnsureVisible( long index ) |
c801d85f | 2953 | { |
dc6c62a9 RR |
2954 | // We have to call this here because the label in |
2955 | // question might just have been added and no screen | |
2956 | // update taken place. | |
2957 | if (m_dirty) wxYield(); | |
2958 | ||
5b077d48 RR |
2959 | wxListLineData *oldCurrent = m_current; |
2960 | m_current = (wxListLineData *) NULL; | |
f6bcfd97 BP |
2961 | if (index >= 0 && (size_t)index < m_lines.GetCount()) |
2962 | m_current = &m_lines[(size_t)index]; | |
5b077d48 RR |
2963 | if (m_current) MoveToFocus(); |
2964 | m_current = oldCurrent; | |
e1e955e1 | 2965 | } |
c801d85f | 2966 | |
debe6624 | 2967 | long wxListMainWindow::FindItem(long start, const wxString& str, bool WXUNUSED(partial) ) |
c801d85f | 2968 | { |
5b077d48 RR |
2969 | long pos = start; |
2970 | wxString tmp = str; | |
2971 | if (pos < 0) pos = 0; | |
3ca6a5f0 | 2972 | for (size_t i = (size_t)pos; i < m_lines.GetCount(); i++) |
5b077d48 | 2973 | { |
f6bcfd97 | 2974 | wxListLineData *line = &m_lines[i]; |
5b077d48 RR |
2975 | wxString s = ""; |
2976 | line->GetText( 0, s ); | |
2977 | if (s == tmp) return pos; | |
5b077d48 RR |
2978 | pos++; |
2979 | } | |
2980 | return -1; | |
e1e955e1 | 2981 | } |
c801d85f | 2982 | |
debe6624 | 2983 | long wxListMainWindow::FindItem(long start, long data) |
c801d85f | 2984 | { |
5b077d48 RR |
2985 | long pos = start; |
2986 | if (pos < 0) pos = 0; | |
3ca6a5f0 | 2987 | for (size_t i = (size_t)pos; i < m_lines.GetCount(); i++) |
5b077d48 | 2988 | { |
f6bcfd97 | 2989 | wxListLineData *line = &m_lines[i]; |
5b077d48 RR |
2990 | wxListItem item; |
2991 | line->GetItem( 0, item ); | |
2992 | if (item.m_data == data) return pos; | |
5b077d48 RR |
2993 | pos++; |
2994 | } | |
2995 | return -1; | |
e1e955e1 | 2996 | } |
c801d85f | 2997 | |
debe6624 | 2998 | long wxListMainWindow::HitTest( int x, int y, int &flags ) |
c801d85f | 2999 | { |
aaef15bf | 3000 | CalcUnscrolledPosition( x, y, &x, &y ); |
e8741cca | 3001 | |
5b077d48 | 3002 | int count = 0; |
f6bcfd97 | 3003 | for (size_t i = 0; i < m_lines.GetCount(); i++) |
c801d85f | 3004 | { |
f6bcfd97 | 3005 | wxListLineData *line = &m_lines[i]; |
aaef15bf | 3006 | long ret = line->IsHit( x, y ); |
191ebf4d | 3007 | if (ret) // & flags) // No: flags is output-only so may be garbage at this point |
5b077d48 | 3008 | { |
6f2a55e3 | 3009 | flags = (int)ret; |
5b077d48 RR |
3010 | return count; |
3011 | } | |
5b077d48 | 3012 | count++; |
e1e955e1 | 3013 | } |
5b077d48 | 3014 | return -1; |
e1e955e1 | 3015 | } |
c801d85f KB |
3016 | |
3017 | void wxListMainWindow::InsertItem( wxListItem &item ) | |
3018 | { | |
5b077d48 RR |
3019 | m_dirty = TRUE; |
3020 | int mode = 0; | |
3021 | if (m_mode & wxLC_REPORT) mode = wxLC_REPORT; | |
3022 | else if (m_mode & wxLC_LIST) mode = wxLC_LIST; | |
3023 | else if (m_mode & wxLC_ICON) mode = wxLC_ICON; | |
3024 | else if (m_mode & wxLC_SMALL_ICON) mode = wxLC_ICON; // no typo | |
004fd0c8 | 3025 | |
5b077d48 | 3026 | wxListLineData *line = new wxListLineData( this, mode, m_hilightBrush ); |
004fd0c8 | 3027 | |
5b077d48 RR |
3028 | if (m_mode & wxLC_REPORT) |
3029 | { | |
3030 | line->InitItems( GetColumnCount() ); | |
3031 | item.m_width = GetColumnWidth( 0 )-3; | |
3032 | } | |
3033 | else | |
3034 | { | |
3035 | line->InitItems( 1 ); | |
3036 | } | |
004fd0c8 | 3037 | |
5b077d48 | 3038 | line->SetItem( 0, item ); |
f6bcfd97 | 3039 | if ((item.m_itemId >= 0) && ((size_t)item.m_itemId < m_lines.GetCount())) |
5b077d48 | 3040 | { |
f6bcfd97 | 3041 | m_lines.Insert( line, (size_t)item.m_itemId ); |
5b077d48 RR |
3042 | } |
3043 | else | |
3044 | { | |
f6bcfd97 | 3045 | m_lines.Add( line ); |
300aaa8f | 3046 | item.m_itemId = m_lines.GetCount()-1; |
5b077d48 | 3047 | } |
e1e955e1 | 3048 | } |
c801d85f | 3049 | |
debe6624 | 3050 | void wxListMainWindow::InsertColumn( long col, wxListItem &item ) |
c801d85f | 3051 | { |
5b077d48 RR |
3052 | m_dirty = TRUE; |
3053 | if (m_mode & wxLC_REPORT) | |
3db7be80 | 3054 | { |
5b077d48 RR |
3055 | if (item.m_width == wxLIST_AUTOSIZE_USEHEADER) item.m_width = GetTextLength( item.m_text ); |
3056 | wxListHeaderData *column = new wxListHeaderData( item ); | |
3057 | if ((col >= 0) && (col < (int)m_columns.GetCount())) | |
3058 | { | |
6f2a55e3 | 3059 | wxNode *node = m_columns.Nth( (size_t)col ); |
5b077d48 RR |
3060 | if (node) |
3061 | m_columns.Insert( node, column ); | |
3062 | } | |
3063 | else | |
3064 | { | |
3065 | m_columns.Append( column ); | |
3066 | } | |
3db7be80 | 3067 | } |
e1e955e1 | 3068 | } |
c801d85f KB |
3069 | |
3070 | wxListCtrlCompare list_ctrl_compare_func_2; | |
3071 | long list_ctrl_compare_data; | |
3072 | ||
f6bcfd97 | 3073 | int LINKAGEMODE list_ctrl_compare_func_1( wxListLineData **arg1, wxListLineData **arg2 ) |
c801d85f | 3074 | { |
f6bcfd97 BP |
3075 | wxListLineData *line1 = *arg1; |
3076 | wxListLineData *line2 = *arg2; | |
5b077d48 RR |
3077 | wxListItem item; |
3078 | line1->GetItem( 0, item ); | |
3079 | long data1 = item.m_data; | |
3080 | line2->GetItem( 0, item ); | |
3081 | long data2 = item.m_data; | |
3082 | return list_ctrl_compare_func_2( data1, data2, list_ctrl_compare_data ); | |
e1e955e1 | 3083 | } |
c801d85f KB |
3084 | |
3085 | void wxListMainWindow::SortItems( wxListCtrlCompare fn, long data ) | |
3086 | { | |
5b077d48 RR |
3087 | list_ctrl_compare_func_2 = fn; |
3088 | list_ctrl_compare_data = data; | |
3089 | m_lines.Sort( list_ctrl_compare_func_1 ); | |
af7c1052 | 3090 | m_dirty = TRUE; |
e1e955e1 | 3091 | } |
c801d85f | 3092 | |
7c74e7fe SC |
3093 | void wxListMainWindow::OnScroll(wxScrollWinEvent& event) |
3094 | { | |
bffa1c77 | 3095 | wxScrolledWindow::OnScroll( event ) ; |
7c74e7fe SC |
3096 | #if wxUSE_GENERIC_LIST_EXTENSIONS |
3097 | ||
3098 | if (event.GetOrientation() == wxHORIZONTAL && ( m_mode & wxLC_REPORT )) | |
3099 | { | |
bffa1c77 VZ |
3100 | wxListCtrl* lc = wxDynamicCast( GetParent() , wxListCtrl ) ; |
3101 | if ( lc ) | |
3102 | { | |
3103 | lc->m_headerWin->Refresh() ; | |
7c74e7fe | 3104 | #ifdef __WXMAC__ |
bffa1c77 | 3105 | lc->m_headerWin->MacUpdateImmediately() ; |
7c74e7fe | 3106 | #endif |
bffa1c77 | 3107 | } |
7c74e7fe SC |
3108 | } |
3109 | #endif | |
3110 | } | |
3111 | ||
c801d85f KB |
3112 | // ------------------------------------------------------------------------------------- |
3113 | // wxListItem | |
3114 | // ------------------------------------------------------------------------------------- | |
3115 | ||
3116 | IMPLEMENT_DYNAMIC_CLASS(wxListItem, wxObject) | |
3117 | ||
fd9811b1 | 3118 | wxListItem::wxListItem() |
c801d85f | 3119 | { |
63852e78 RR |
3120 | m_mask = 0; |
3121 | m_itemId = 0; | |
3122 | m_col = 0; | |
3123 | m_state = 0; | |
3124 | m_stateMask = 0; | |
3125 | m_image = 0; | |
3126 | m_data = 0; | |
3127 | m_format = wxLIST_FORMAT_CENTRE; | |
3128 | m_width = 0; | |
aaa37c0d VZ |
3129 | |
3130 | m_attr = NULL; | |
c801d85f KB |
3131 | } |
3132 | ||
9b00bb16 RR |
3133 | void wxListItem::Clear() |
3134 | { | |
3135 | m_mask = 0; | |
3136 | m_itemId = 0; | |
3137 | m_col = 0; | |
3138 | m_state = 0; | |
3139 | m_stateMask = 0; | |
3140 | m_image = 0; | |
3141 | m_data = 0; | |
3142 | m_format = wxLIST_FORMAT_CENTRE; | |
3143 | m_width = 0; | |
3144 | m_text = wxEmptyString; | |
3145 | ||
3146 | if (m_attr) delete m_attr; | |
3147 | m_attr = NULL; | |
3148 | } | |
3149 | ||
3150 | void wxListItem::ClearAttributes() | |
3151 | { | |
3152 | if (m_attr) delete m_attr; | |
3153 | m_attr = NULL; | |
3154 | } | |
3155 | ||
c801d85f KB |
3156 | // ------------------------------------------------------------------------------------- |
3157 | // wxListEvent | |
3158 | // ------------------------------------------------------------------------------------- | |
3159 | ||
92976ab6 | 3160 | IMPLEMENT_DYNAMIC_CLASS(wxListEvent, wxNotifyEvent) |
c801d85f | 3161 | |
8f79098a | 3162 | wxListEvent::wxListEvent( wxEventType commandType, int id ): |
92976ab6 | 3163 | wxNotifyEvent( commandType, id ) |
c801d85f | 3164 | { |
5b077d48 RR |
3165 | m_code = 0; |
3166 | m_itemIndex = 0; | |
3167 | m_oldItemIndex = 0; | |
3168 | m_col = 0; | |
3169 | m_cancelled = FALSE; | |
3170 | m_pointDrag.x = 0; | |
3171 | m_pointDrag.y = 0; | |
e1e955e1 | 3172 | } |
c801d85f | 3173 | |
72a7edf0 RR |
3174 | void wxListEvent::CopyObject(wxObject& object_dest) const |
3175 | { | |
3176 | wxListEvent *obj = (wxListEvent *)&object_dest; | |
3177 | ||
3178 | wxNotifyEvent::CopyObject(object_dest); | |
3179 | ||
3180 | obj->m_code = m_code; | |
3181 | obj->m_itemIndex = m_itemIndex; | |
3182 | obj->m_oldItemIndex = m_oldItemIndex; | |
3183 | obj->m_col = m_col; | |
3184 | obj->m_cancelled = m_cancelled; | |
3185 | obj->m_pointDrag = m_pointDrag; | |
3186 | obj->m_item.m_mask = m_item.m_mask; | |
3187 | obj->m_item.m_itemId = m_item.m_itemId; | |
3188 | obj->m_item.m_col = m_item.m_col; | |
3189 | obj->m_item.m_state = m_item.m_state; | |
3190 | obj->m_item.m_stateMask = m_item.m_stateMask; | |
3191 | obj->m_item.m_text = m_item.m_text; | |
3192 | obj->m_item.m_image = m_item.m_image; | |
3193 | obj->m_item.m_data = m_item.m_data; | |
3194 | obj->m_item.m_format = m_item.m_format; | |
3195 | obj->m_item.m_width = m_item.m_width; | |
aaa37c0d VZ |
3196 | |
3197 | if ( m_item.HasAttributes() ) | |
3198 | { | |
3199 | obj->m_item.SetTextColour(m_item.GetTextColour()); | |
3200 | } | |
72a7edf0 RR |
3201 | } |
3202 | ||
c801d85f KB |
3203 | // ------------------------------------------------------------------------------------- |
3204 | // wxListCtrl | |
3205 | // ------------------------------------------------------------------------------------- | |
3206 | ||
3207 | IMPLEMENT_DYNAMIC_CLASS(wxListCtrl, wxControl) | |
3208 | ||
3209 | BEGIN_EVENT_TABLE(wxListCtrl,wxControl) | |
3210 | EVT_SIZE (wxListCtrl::OnSize) | |
53010e52 | 3211 | EVT_IDLE (wxListCtrl::OnIdle) |
c801d85f KB |
3212 | END_EVENT_TABLE() |
3213 | ||
fd9811b1 | 3214 | wxListCtrl::wxListCtrl() |
c801d85f | 3215 | { |
5b077d48 RR |
3216 | m_imageListNormal = (wxImageList *) NULL; |
3217 | m_imageListSmall = (wxImageList *) NULL; | |
3218 | m_imageListState = (wxImageList *) NULL; | |
2e12c11a | 3219 | m_ownsImageListNormal = m_ownsImageListSmall = m_ownsImageListState = FALSE; |
5b077d48 RR |
3220 | m_mainWin = (wxListMainWindow*) NULL; |
3221 | m_headerWin = (wxListHeaderWindow*) NULL; | |
c801d85f KB |
3222 | } |
3223 | ||
fd9811b1 | 3224 | wxListCtrl::~wxListCtrl() |
c801d85f | 3225 | { |
2e12c11a VS |
3226 | if (m_ownsImageListNormal) delete m_imageListNormal; |
3227 | if (m_ownsImageListSmall) delete m_imageListSmall; | |
3228 | if (m_ownsImageListState) delete m_imageListState; | |
c801d85f KB |
3229 | } |
3230 | ||
25e3a937 VZ |
3231 | bool wxListCtrl::Create(wxWindow *parent, |
3232 | wxWindowID id, | |
3233 | const wxPoint &pos, | |
3234 | const wxSize &size, | |
3235 | long style, | |
25e3a937 | 3236 | const wxValidator &validator, |
25e3a937 | 3237 | const wxString &name) |
c801d85f | 3238 | { |
5b077d48 RR |
3239 | m_imageListNormal = (wxImageList *) NULL; |
3240 | m_imageListSmall = (wxImageList *) NULL; | |
3241 | m_imageListState = (wxImageList *) NULL; | |
2e12c11a | 3242 | m_ownsImageListNormal = m_ownsImageListSmall = m_ownsImageListState = FALSE; |
5b077d48 RR |
3243 | m_mainWin = (wxListMainWindow*) NULL; |
3244 | m_headerWin = (wxListHeaderWindow*) NULL; | |
bd8289c1 | 3245 | |
25e3a937 | 3246 | if ( !(style & (wxLC_REPORT | wxLC_LIST | wxLC_ICON)) ) |
5b077d48 | 3247 | { |
25e3a937 | 3248 | style = style | wxLC_LIST; |
5b077d48 | 3249 | } |
f6bcfd97 | 3250 | |
098963c3 | 3251 | bool ret = wxControl::Create( parent, id, pos, size, style, validator, name ); |
f6bcfd97 BP |
3252 | |
3253 | ||
25e3a937 VZ |
3254 | if (style & wxSUNKEN_BORDER) |
3255 | style -= wxSUNKEN_BORDER; | |
bd8289c1 | 3256 | |
25e3a937 | 3257 | m_mainWin = new wxListMainWindow( this, -1, wxPoint(0,0), size, style ); |
bd8289c1 | 3258 | |
f03fc89f | 3259 | if (HasFlag(wxLC_REPORT)) |
ea451729 | 3260 | { |
5b077d48 | 3261 | m_headerWin = new wxListHeaderWindow( this, -1, m_mainWin, wxPoint(0,0), wxSize(size.x,23), wxTAB_TRAVERSAL ); |
ea451729 RR |
3262 | if (HasFlag(wxLC_NO_HEADER)) |
3263 | m_headerWin->Show( FALSE ); | |
3264 | } | |
5b077d48 | 3265 | else |
ea451729 | 3266 | { |
5b077d48 | 3267 | m_headerWin = (wxListHeaderWindow *) NULL; |
ea451729 | 3268 | } |
bd8289c1 | 3269 | |
5b077d48 | 3270 | return ret; |
e1e955e1 | 3271 | } |
c801d85f KB |
3272 | |
3273 | void wxListCtrl::OnSize( wxSizeEvent &WXUNUSED(event) ) | |
3274 | { | |
5b077d48 | 3275 | /* handled in OnIdle */ |
bd8289c1 | 3276 | |
5b077d48 | 3277 | if (m_mainWin) m_mainWin->m_dirty = TRUE; |
e1e955e1 | 3278 | } |
c801d85f | 3279 | |
debe6624 | 3280 | void wxListCtrl::SetSingleStyle( long style, bool add ) |
c801d85f | 3281 | { |
f03fc89f | 3282 | long flag = GetWindowStyle(); |
bd8289c1 | 3283 | |
5b077d48 RR |
3284 | if (add) |
3285 | { | |
3286 | if (style & wxLC_MASK_TYPE) flag = flag & ~wxLC_MASK_TYPE; | |
3287 | if (style & wxLC_MASK_ALIGN) flag = flag & ~wxLC_MASK_ALIGN; | |
3288 | if (style & wxLC_MASK_SORT) flag = flag & ~wxLC_MASK_SORT; | |
3289 | } | |
c801d85f | 3290 | |
5b077d48 RR |
3291 | if (add) |
3292 | { | |
3293 | flag |= style; | |
3294 | } | |
3295 | else | |
3296 | { | |
3297 | if (flag & style) flag -= style; | |
3298 | } | |
bd8289c1 | 3299 | |
5b077d48 | 3300 | SetWindowStyleFlag( flag ); |
e1e955e1 | 3301 | } |
c801d85f | 3302 | |
debe6624 | 3303 | void wxListCtrl::SetWindowStyleFlag( long flag ) |
c801d85f | 3304 | { |
121a3581 RR |
3305 | if (m_mainWin) |
3306 | { | |
3307 | m_mainWin->DeleteEverything(); | |
c801d85f | 3308 | |
121a3581 RR |
3309 | int width = 0; |
3310 | int height = 0; | |
3311 | GetClientSize( &width, &height ); | |
c801d85f | 3312 | |
121a3581 | 3313 | m_mainWin->SetMode( flag ); |
bd8289c1 | 3314 | |
121a3581 | 3315 | if (flag & wxLC_REPORT) |
5b077d48 | 3316 | { |
121a3581 | 3317 | if (!HasFlag(wxLC_REPORT)) |
5b077d48 | 3318 | { |
121a3581 RR |
3319 | if (!m_headerWin) |
3320 | { | |
004fd0c8 | 3321 | m_headerWin = new wxListHeaderWindow( this, -1, m_mainWin, |
bffa1c77 VZ |
3322 | wxPoint(0,0), wxSize(width,23), wxTAB_TRAVERSAL ); |
3323 | if (HasFlag(wxLC_NO_HEADER)) | |
3324 | m_headerWin->Show( FALSE ); | |
121a3581 RR |
3325 | } |
3326 | else | |
004fd0c8 | 3327 | { |
bffa1c77 VZ |
3328 | if (flag & wxLC_NO_HEADER) |
3329 | m_headerWin->Show( FALSE ); | |
3330 | else | |
8636aed8 | 3331 | m_headerWin->Show( TRUE ); |
004fd0c8 | 3332 | } |
5b077d48 RR |
3333 | } |
3334 | } | |
121a3581 | 3335 | else |
5b077d48 | 3336 | { |
8636aed8 | 3337 | if (HasFlag(wxLC_REPORT) && !(HasFlag(wxLC_NO_HEADER))) |
121a3581 RR |
3338 | { |
3339 | m_headerWin->Show( FALSE ); | |
3340 | } | |
bffa1c77 | 3341 | } |
e1e955e1 | 3342 | } |
004fd0c8 | 3343 | |
5b077d48 | 3344 | wxWindow::SetWindowStyleFlag( flag ); |
e1e955e1 | 3345 | } |
c801d85f | 3346 | |
e487524e | 3347 | bool wxListCtrl::GetColumn(int col, wxListItem &item) const |
c801d85f | 3348 | { |
5b077d48 RR |
3349 | m_mainWin->GetColumn( col, item ); |
3350 | return TRUE; | |
e1e955e1 | 3351 | } |
c801d85f | 3352 | |
debe6624 | 3353 | bool wxListCtrl::SetColumn( int col, wxListItem& item ) |
c801d85f | 3354 | { |
5b077d48 RR |
3355 | m_mainWin->SetColumn( col, item ); |
3356 | return TRUE; | |
e1e955e1 | 3357 | } |
c801d85f | 3358 | |
e487524e | 3359 | int wxListCtrl::GetColumnWidth( int col ) const |
c801d85f | 3360 | { |
5b077d48 | 3361 | return m_mainWin->GetColumnWidth( col ); |
e1e955e1 | 3362 | } |
c801d85f | 3363 | |
debe6624 | 3364 | bool wxListCtrl::SetColumnWidth( int col, int width ) |
c801d85f | 3365 | { |
5b077d48 RR |
3366 | m_mainWin->SetColumnWidth( col, width ); |
3367 | return TRUE; | |
e1e955e1 | 3368 | } |
c801d85f | 3369 | |
fd9811b1 | 3370 | int wxListCtrl::GetCountPerPage() const |
c801d85f KB |
3371 | { |
3372 | return m_mainWin->GetCountPerPage(); // different from Windows ? | |
e1e955e1 | 3373 | } |
c801d85f | 3374 | |
e487524e | 3375 | bool wxListCtrl::GetItem( wxListItem &info ) const |
c801d85f | 3376 | { |
5b077d48 RR |
3377 | m_mainWin->GetItem( info ); |
3378 | return TRUE; | |
e1e955e1 | 3379 | } |
c801d85f KB |
3380 | |
3381 | bool wxListCtrl::SetItem( wxListItem &info ) | |
3382 | { | |
5b077d48 RR |
3383 | m_mainWin->SetItem( info ); |
3384 | return TRUE; | |
e1e955e1 | 3385 | } |
c801d85f | 3386 | |
debe6624 | 3387 | long wxListCtrl::SetItem( long index, int col, const wxString& label, int imageId ) |
c801d85f | 3388 | { |
5b077d48 RR |
3389 | wxListItem info; |
3390 | info.m_text = label; | |
3391 | info.m_mask = wxLIST_MASK_TEXT; | |
3392 | info.m_itemId = index; | |
3393 | info.m_col = col; | |
3394 | if ( imageId > -1 ) | |
3395 | { | |
3396 | info.m_image = imageId; | |
3397 | info.m_mask |= wxLIST_MASK_IMAGE; | |
3398 | }; | |
3399 | m_mainWin->SetItem(info); | |
3400 | return TRUE; | |
e1e955e1 | 3401 | } |
c801d85f | 3402 | |
e487524e | 3403 | int wxListCtrl::GetItemState( long item, long stateMask ) const |
c801d85f | 3404 | { |
5b077d48 | 3405 | return m_mainWin->GetItemState( item, stateMask ); |
e1e955e1 | 3406 | } |
c801d85f | 3407 | |
debe6624 | 3408 | bool wxListCtrl::SetItemState( long item, long state, long stateMask ) |
c801d85f | 3409 | { |
5b077d48 RR |
3410 | m_mainWin->SetItemState( item, state, stateMask ); |
3411 | return TRUE; | |
e1e955e1 | 3412 | } |
c801d85f | 3413 | |
debe6624 | 3414 | bool wxListCtrl::SetItemImage( long item, int image, int WXUNUSED(selImage) ) |
c801d85f | 3415 | { |
5b077d48 RR |
3416 | wxListItem info; |
3417 | info.m_image = image; | |
3418 | info.m_mask = wxLIST_MASK_IMAGE; | |
3419 | info.m_itemId = item; | |
3420 | m_mainWin->SetItem( info ); | |
3421 | return TRUE; | |
e1e955e1 | 3422 | } |
c801d85f | 3423 | |
e487524e | 3424 | wxString wxListCtrl::GetItemText( long item ) const |
c801d85f | 3425 | { |
5b077d48 RR |
3426 | wxListItem info; |
3427 | info.m_itemId = item; | |
3428 | m_mainWin->GetItem( info ); | |
3429 | return info.m_text; | |
e1e955e1 | 3430 | } |
c801d85f | 3431 | |
debe6624 | 3432 | void wxListCtrl::SetItemText( long item, const wxString &str ) |
c801d85f | 3433 | { |
5b077d48 RR |
3434 | wxListItem info; |
3435 | info.m_mask = wxLIST_MASK_TEXT; | |
3436 | info.m_itemId = item; | |
3437 | info.m_text = str; | |
3438 | m_mainWin->SetItem( info ); | |
e1e955e1 | 3439 | } |
c801d85f | 3440 | |
e487524e | 3441 | long wxListCtrl::GetItemData( long item ) const |
c801d85f | 3442 | { |
5b077d48 RR |
3443 | wxListItem info; |
3444 | info.m_itemId = item; | |
3445 | m_mainWin->GetItem( info ); | |
3446 | return info.m_data; | |
e1e955e1 | 3447 | } |
c801d85f | 3448 | |
debe6624 | 3449 | bool wxListCtrl::SetItemData( long item, long data ) |
c801d85f | 3450 | { |
5b077d48 RR |
3451 | wxListItem info; |
3452 | info.m_mask = wxLIST_MASK_DATA; | |
3453 | info.m_itemId = item; | |
3454 | info.m_data = data; | |
3455 | m_mainWin->SetItem( info ); | |
3456 | return TRUE; | |
e1e955e1 | 3457 | } |
c801d85f | 3458 | |
0a240683 | 3459 | bool wxListCtrl::GetItemRect( long item, wxRect &rect, int WXUNUSED(code) ) const |
c801d85f | 3460 | { |
5b077d48 RR |
3461 | m_mainWin->GetItemRect( item, rect ); |
3462 | return TRUE; | |
e1e955e1 | 3463 | } |
c801d85f | 3464 | |
e487524e | 3465 | bool wxListCtrl::GetItemPosition( long item, wxPoint& pos ) const |
c801d85f | 3466 | { |
5b077d48 RR |
3467 | m_mainWin->GetItemPosition( item, pos ); |
3468 | return TRUE; | |
e1e955e1 | 3469 | } |
c801d85f | 3470 | |
debe6624 | 3471 | bool wxListCtrl::SetItemPosition( long WXUNUSED(item), const wxPoint& WXUNUSED(pos) ) |
c801d85f | 3472 | { |
5b077d48 | 3473 | return 0; |
e1e955e1 | 3474 | } |
c801d85f | 3475 | |
fd9811b1 | 3476 | int wxListCtrl::GetItemCount() const |
c801d85f | 3477 | { |
5b077d48 | 3478 | return m_mainWin->GetItemCount(); |
e1e955e1 | 3479 | } |
c801d85f | 3480 | |
fd9811b1 | 3481 | int wxListCtrl::GetColumnCount() const |
92976ab6 | 3482 | { |
5b077d48 | 3483 | return m_mainWin->GetColumnCount(); |
92976ab6 RR |
3484 | } |
3485 | ||
33d0b396 RR |
3486 | void wxListCtrl::SetItemSpacing( int spacing, bool isSmall ) |
3487 | { | |
5b077d48 | 3488 | m_mainWin->SetItemSpacing( spacing, isSmall ); |
e1e955e1 | 3489 | } |
33d0b396 | 3490 | |
e487524e | 3491 | int wxListCtrl::GetItemSpacing( bool isSmall ) const |
c801d85f | 3492 | { |
5b077d48 | 3493 | return m_mainWin->GetItemSpacing( isSmall ); |
e1e955e1 | 3494 | } |
c801d85f | 3495 | |
fd9811b1 | 3496 | int wxListCtrl::GetSelectedItemCount() const |
c801d85f | 3497 | { |
5b077d48 | 3498 | return m_mainWin->GetSelectedItemCount(); |
e1e955e1 | 3499 | } |
c801d85f | 3500 | |
fd9811b1 | 3501 | wxColour wxListCtrl::GetTextColour() const |
c801d85f | 3502 | { |
0530737d | 3503 | return GetForegroundColour(); |
e1e955e1 | 3504 | } |
c801d85f | 3505 | |
0530737d | 3506 | void wxListCtrl::SetTextColour(const wxColour& col) |
c801d85f | 3507 | { |
0530737d | 3508 | SetForegroundColour(col); |
e1e955e1 | 3509 | } |
c801d85f | 3510 | |
fd9811b1 | 3511 | long wxListCtrl::GetTopItem() const |
c801d85f | 3512 | { |
5b077d48 | 3513 | return 0; |
e1e955e1 | 3514 | } |
c801d85f | 3515 | |
6de97a3b | 3516 | long wxListCtrl::GetNextItem( long item, int geom, int state ) const |
c801d85f | 3517 | { |
5b077d48 | 3518 | return m_mainWin->GetNextItem( item, geom, state ); |
e1e955e1 | 3519 | } |
c801d85f | 3520 | |
e487524e | 3521 | wxImageList *wxListCtrl::GetImageList(int which) const |
c801d85f | 3522 | { |
5b077d48 RR |
3523 | if (which == wxIMAGE_LIST_NORMAL) |
3524 | { | |
3525 | return m_imageListNormal; | |
3526 | } | |
3527 | else if (which == wxIMAGE_LIST_SMALL) | |
3528 | { | |
3529 | return m_imageListSmall; | |
3530 | } | |
3531 | else if (which == wxIMAGE_LIST_STATE) | |
3532 | { | |
3533 | return m_imageListState; | |
3534 | } | |
3535 | return (wxImageList *) NULL; | |
e1e955e1 | 3536 | } |
c801d85f | 3537 | |
debe6624 | 3538 | void wxListCtrl::SetImageList( wxImageList *imageList, int which ) |
c801d85f | 3539 | { |
2e12c11a VS |
3540 | if ( which == wxIMAGE_LIST_NORMAL ) |
3541 | { | |
3542 | if (m_ownsImageListNormal) delete m_imageListNormal; | |
3543 | m_imageListNormal = imageList; | |
3544 | m_ownsImageListNormal = FALSE; | |
3545 | } | |
3546 | else if ( which == wxIMAGE_LIST_SMALL ) | |
3547 | { | |
3548 | if (m_ownsImageListSmall) delete m_imageListSmall; | |
3549 | m_imageListSmall = imageList; | |
3550 | m_ownsImageListSmall = FALSE; | |
3551 | } | |
3552 | else if ( which == wxIMAGE_LIST_STATE ) | |
3553 | { | |
3554 | if (m_ownsImageListState) delete m_imageListState; | |
3555 | m_imageListState = imageList; | |
3556 | m_ownsImageListState = FALSE; | |
3557 | } | |
3558 | ||
5b077d48 | 3559 | m_mainWin->SetImageList( imageList, which ); |
e1e955e1 | 3560 | } |
c801d85f | 3561 | |
2e12c11a VS |
3562 | void wxListCtrl::AssignImageList(wxImageList *imageList, int which) |
3563 | { | |
3564 | SetImageList(imageList, which); | |
3565 | if ( which == wxIMAGE_LIST_NORMAL ) | |
3566 | m_ownsImageListNormal = TRUE; | |
3567 | else if ( which == wxIMAGE_LIST_SMALL ) | |
3568 | m_ownsImageListSmall = TRUE; | |
3569 | else if ( which == wxIMAGE_LIST_STATE ) | |
3570 | m_ownsImageListState = TRUE; | |
3571 | } | |
3572 | ||
debe6624 | 3573 | bool wxListCtrl::Arrange( int WXUNUSED(flag) ) |
c801d85f | 3574 | { |
5b077d48 | 3575 | return 0; |
e1e955e1 | 3576 | } |
c801d85f | 3577 | |
debe6624 | 3578 | bool wxListCtrl::DeleteItem( long item ) |
c801d85f | 3579 | { |
5b077d48 RR |
3580 | m_mainWin->DeleteItem( item ); |
3581 | return TRUE; | |
e1e955e1 | 3582 | } |
c801d85f | 3583 | |
fd9811b1 | 3584 | bool wxListCtrl::DeleteAllItems() |
c801d85f | 3585 | { |
5b077d48 RR |
3586 | m_mainWin->DeleteAllItems(); |
3587 | return TRUE; | |
e1e955e1 | 3588 | } |
c801d85f | 3589 | |
4f22cf8d | 3590 | bool wxListCtrl::DeleteAllColumns() |
bd8289c1 VZ |
3591 | { |
3592 | for ( size_t n = 0; n < m_mainWin->m_columns.GetCount(); n++ ) | |
3593 | DeleteColumn(n); | |
bffa1c77 | 3594 | |
5b077d48 | 3595 | return TRUE; |
4f22cf8d RR |
3596 | } |
3597 | ||
3598 | void wxListCtrl::ClearAll() | |
3599 | { | |
5b077d48 | 3600 | m_mainWin->DeleteEverything(); |
bd8289c1 VZ |
3601 | } |
3602 | ||
debe6624 | 3603 | bool wxListCtrl::DeleteColumn( int col ) |
c801d85f | 3604 | { |
5b077d48 RR |
3605 | m_mainWin->DeleteColumn( col ); |
3606 | return TRUE; | |
e1e955e1 | 3607 | } |
c801d85f | 3608 | |
e179bd65 | 3609 | void wxListCtrl::Edit( long item ) |
c801d85f | 3610 | { |
e179bd65 | 3611 | m_mainWin->Edit( item ); |
e1e955e1 | 3612 | } |
c801d85f | 3613 | |
debe6624 | 3614 | bool wxListCtrl::EnsureVisible( long item ) |
c801d85f | 3615 | { |
5b077d48 RR |
3616 | m_mainWin->EnsureVisible( item ); |
3617 | return TRUE; | |
e1e955e1 | 3618 | } |
c801d85f | 3619 | |
debe6624 | 3620 | long wxListCtrl::FindItem( long start, const wxString& str, bool partial ) |
c801d85f | 3621 | { |
5b077d48 | 3622 | return m_mainWin->FindItem( start, str, partial ); |
e1e955e1 | 3623 | } |
c801d85f | 3624 | |
debe6624 | 3625 | long wxListCtrl::FindItem( long start, long data ) |
c801d85f | 3626 | { |
5b077d48 | 3627 | return m_mainWin->FindItem( start, data ); |
e1e955e1 | 3628 | } |
c801d85f | 3629 | |
bd8289c1 | 3630 | long wxListCtrl::FindItem( long WXUNUSED(start), const wxPoint& WXUNUSED(pt), |
debe6624 | 3631 | int WXUNUSED(direction)) |
c801d85f | 3632 | { |
5b077d48 | 3633 | return 0; |
e1e955e1 | 3634 | } |
c801d85f KB |
3635 | |
3636 | long wxListCtrl::HitTest( const wxPoint &point, int &flags ) | |
3637 | { | |
5b077d48 | 3638 | return m_mainWin->HitTest( (int)point.x, (int)point.y, flags ); |
e1e955e1 | 3639 | } |
c801d85f KB |
3640 | |
3641 | long wxListCtrl::InsertItem( wxListItem& info ) | |
3642 | { | |
5b077d48 | 3643 | m_mainWin->InsertItem( info ); |
2ebcd5f5 | 3644 | return info.m_itemId; |
e1e955e1 | 3645 | } |
c801d85f | 3646 | |
debe6624 | 3647 | long wxListCtrl::InsertItem( long index, const wxString &label ) |
c801d85f | 3648 | { |
51cc4dad RR |
3649 | wxListItem info; |
3650 | info.m_text = label; | |
3651 | info.m_mask = wxLIST_MASK_TEXT; | |
3652 | info.m_itemId = index; | |
3653 | return InsertItem( info ); | |
e1e955e1 | 3654 | } |
c801d85f | 3655 | |
debe6624 | 3656 | long wxListCtrl::InsertItem( long index, int imageIndex ) |
c801d85f | 3657 | { |
51cc4dad RR |
3658 | wxListItem info; |
3659 | info.m_mask = wxLIST_MASK_IMAGE; | |
3660 | info.m_image = imageIndex; | |
3661 | info.m_itemId = index; | |
3662 | return InsertItem( info ); | |
e1e955e1 | 3663 | } |
c801d85f | 3664 | |
debe6624 | 3665 | long wxListCtrl::InsertItem( long index, const wxString &label, int imageIndex ) |
c801d85f | 3666 | { |
51cc4dad RR |
3667 | wxListItem info; |
3668 | info.m_text = label; | |
3669 | info.m_image = imageIndex; | |
3670 | info.m_mask = wxLIST_MASK_TEXT | wxLIST_MASK_IMAGE; | |
3671 | info.m_itemId = index; | |
3672 | return InsertItem( info ); | |
e1e955e1 | 3673 | } |
c801d85f | 3674 | |
debe6624 | 3675 | long wxListCtrl::InsertColumn( long col, wxListItem &item ) |
c801d85f | 3676 | { |
d3e90957 | 3677 | wxASSERT( m_headerWin ); |
51cc4dad | 3678 | m_mainWin->InsertColumn( col, item ); |
d3e90957 | 3679 | m_headerWin->Refresh(); |
25e3a937 | 3680 | |
51cc4dad | 3681 | return 0; |
e1e955e1 | 3682 | } |
c801d85f | 3683 | |
debe6624 JS |
3684 | long wxListCtrl::InsertColumn( long col, const wxString &heading, |
3685 | int format, int width ) | |
c801d85f | 3686 | { |
51cc4dad RR |
3687 | wxListItem item; |
3688 | item.m_mask = wxLIST_MASK_TEXT | wxLIST_MASK_FORMAT; | |
3689 | item.m_text = heading; | |
3690 | if (width >= -2) | |
3691 | { | |
3692 | item.m_mask |= wxLIST_MASK_WIDTH; | |
3693 | item.m_width = width; | |
3694 | } | |
3695 | item.m_format = format; | |
c801d85f | 3696 | |
51cc4dad | 3697 | return InsertColumn( col, item ); |
e1e955e1 | 3698 | } |
c801d85f | 3699 | |
debe6624 | 3700 | bool wxListCtrl::ScrollList( int WXUNUSED(dx), int WXUNUSED(dy) ) |
c801d85f | 3701 | { |
51cc4dad | 3702 | return 0; |
e1e955e1 | 3703 | } |
c801d85f KB |
3704 | |
3705 | // Sort items. | |
3706 | // fn is a function which takes 3 long arguments: item1, item2, data. | |
3707 | // item1 is the long data associated with a first item (NOT the index). | |
3708 | // item2 is the long data associated with a second item (NOT the index). | |
3709 | // data is the same value as passed to SortItems. | |
3710 | // The return value is a negative number if the first item should precede the second | |
3711 | // item, a positive number of the second item should precede the first, | |
3712 | // or zero if the two items are equivalent. | |
3713 | // data is arbitrary data to be passed to the sort function. | |
3714 | ||
3715 | bool wxListCtrl::SortItems( wxListCtrlCompare fn, long data ) | |
3716 | { | |
51cc4dad RR |
3717 | m_mainWin->SortItems( fn, data ); |
3718 | return TRUE; | |
e1e955e1 | 3719 | } |
c801d85f | 3720 | |
e3e65dac | 3721 | void wxListCtrl::OnIdle( wxIdleEvent &WXUNUSED(event) ) |
53010e52 | 3722 | { |
51cc4dad | 3723 | if (!m_mainWin->m_dirty) return; |
53010e52 | 3724 | |
51cc4dad RR |
3725 | int cw = 0; |
3726 | int ch = 0; | |
3727 | GetClientSize( &cw, &ch ); | |
bd8289c1 | 3728 | |
51cc4dad RR |
3729 | int x = 0; |
3730 | int y = 0; | |
3731 | int w = 0; | |
3732 | int h = 0; | |
bd8289c1 | 3733 | |
8636aed8 | 3734 | if (HasFlag(wxLC_REPORT) && !HasFlag(wxLC_NO_HEADER)) |
51cc4dad RR |
3735 | { |
3736 | m_headerWin->GetPosition( &x, &y ); | |
3737 | m_headerWin->GetSize( &w, &h ); | |
3738 | if ((x != 0) || (y != 0) || (w != cw) || (h != 23)) | |
3739 | m_headerWin->SetSize( 0, 0, cw, 23 ); | |
3740 | ||
3741 | m_mainWin->GetPosition( &x, &y ); | |
3742 | m_mainWin->GetSize( &w, &h ); | |
3743 | if ((x != 0) || (y != 24) || (w != cw) || (h != ch-24)) | |
3744 | m_mainWin->SetSize( 0, 24, cw, ch-24 ); | |
3745 | } | |
3746 | else | |
3747 | { | |
3748 | m_mainWin->GetPosition( &x, &y ); | |
3749 | m_mainWin->GetSize( &w, &h ); | |
3750 | if ((x != 0) || (y != 24) || (w != cw) || (h != ch)) | |
3751 | m_mainWin->SetSize( 0, 0, cw, ch ); | |
3752 | } | |
bd8289c1 | 3753 | |
51cc4dad RR |
3754 | m_mainWin->CalculatePositions(); |
3755 | m_mainWin->RealizeChanges(); | |
3756 | m_mainWin->m_dirty = FALSE; | |
3757 | m_mainWin->Refresh(); | |
f6bcfd97 BP |
3758 | |
3759 | if ( m_headerWin && m_headerWin->m_dirty ) | |
3760 | { | |
3761 | m_headerWin->m_dirty = FALSE; | |
3762 | m_headerWin->Refresh(); | |
3763 | } | |
e1e955e1 | 3764 | } |
53010e52 | 3765 | |
f03fc89f | 3766 | bool wxListCtrl::SetBackgroundColour( const wxColour &colour ) |
bd8289c1 | 3767 | { |
51cc4dad RR |
3768 | if (m_mainWin) |
3769 | { | |
3770 | m_mainWin->SetBackgroundColour( colour ); | |
3771 | m_mainWin->m_dirty = TRUE; | |
3772 | } | |
004fd0c8 | 3773 | |
f03fc89f | 3774 | return TRUE; |
e4d06860 RR |
3775 | } |
3776 | ||
f03fc89f | 3777 | bool wxListCtrl::SetForegroundColour( const wxColour &colour ) |
bd8289c1 | 3778 | { |
f03fc89f VZ |
3779 | if ( !wxWindow::SetForegroundColour( colour ) ) |
3780 | return FALSE; | |
004fd0c8 | 3781 | |
51cc4dad RR |
3782 | if (m_mainWin) |
3783 | { | |
3784 | m_mainWin->SetForegroundColour( colour ); | |
3785 | m_mainWin->m_dirty = TRUE; | |
3786 | } | |
004fd0c8 | 3787 | |
51cc4dad RR |
3788 | if (m_headerWin) |
3789 | { | |
3790 | m_headerWin->SetForegroundColour( colour ); | |
3791 | } | |
f03fc89f VZ |
3792 | |
3793 | return TRUE; | |
e4d06860 | 3794 | } |
bd8289c1 | 3795 | |
f03fc89f | 3796 | bool wxListCtrl::SetFont( const wxFont &font ) |
bd8289c1 | 3797 | { |
f03fc89f VZ |
3798 | if ( !wxWindow::SetFont( font ) ) |
3799 | return FALSE; | |
004fd0c8 | 3800 | |
51cc4dad RR |
3801 | if (m_mainWin) |
3802 | { | |
3803 | m_mainWin->SetFont( font ); | |
3804 | m_mainWin->m_dirty = TRUE; | |
3805 | } | |
004fd0c8 | 3806 | |
51cc4dad RR |
3807 | if (m_headerWin) |
3808 | { | |
3809 | m_headerWin->SetFont( font ); | |
3810 | } | |
f03fc89f VZ |
3811 | |
3812 | return TRUE; | |
e4d06860 | 3813 | } |
c801d85f | 3814 | |
efbb7287 VZ |
3815 | #if wxUSE_DRAG_AND_DROP |
3816 | ||
3817 | void wxListCtrl::SetDropTarget( wxDropTarget *dropTarget ) | |
3818 | { | |
3819 | m_mainWin->SetDropTarget( dropTarget ); | |
3820 | } | |
3821 | ||
3822 | wxDropTarget *wxListCtrl::GetDropTarget() const | |
3823 | { | |
3824 | return m_mainWin->GetDropTarget(); | |
3825 | } | |
3826 | ||
3827 | #endif // wxUSE_DRAG_AND_DROP | |
3828 | ||
3829 | bool wxListCtrl::SetCursor( const wxCursor &cursor ) | |
3830 | { | |
3831 | return m_mainWin ? m_mainWin->wxWindow::SetCursor(cursor) : FALSE; | |
3832 | } | |
3833 | ||
3834 | wxColour wxListCtrl::GetBackgroundColour() const | |
3835 | { | |
3836 | return m_mainWin ? m_mainWin->GetBackgroundColour() : wxColour(); | |
3837 | } | |
3838 | ||
3839 | wxColour wxListCtrl::GetForegroundColour() const | |
3840 | { | |
3841 | return m_mainWin ? m_mainWin->GetForegroundColour() : wxColour(); | |
3842 | } | |
3843 | ||
3844 | bool wxListCtrl::DoPopupMenu( wxMenu *menu, int x, int y ) | |
3845 | { | |
3846 | return m_mainWin->PopupMenu( menu, x, y ); | |
3847 | } | |
3848 | ||
3849 | void wxListCtrl::SetFocus() | |
3850 | { | |
3851 | /* The test in window.cpp fails as we are a composite | |
3852 | window, so it checks against "this", but not m_mainWin. */ | |
3853 | if ( FindFocus() != this ) | |
3854 | m_mainWin->SetFocus(); | |
3855 | } |