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