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