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