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