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