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