]> git.saurik.com Git - wxWidgets.git/blame - include/wx/generic/listctrl.h
wxCalendarCtrl works under MSW too
[wxWidgets.git] / include / wx / generic / listctrl.h
CommitLineData
c801d85f 1/////////////////////////////////////////////////////////////////////////////
bdc72a22 2// Name: wx/generic/listctrl.h
c801d85f
KB
3// Purpose: Generic list control
4// Author: Robert Roebling
5// Created: 01/02/97
6// Id:
7// Copyright: (c) 1998 Robert Roebling, Julian Smart and Markus Holzem
bdc72a22 8// Licence: wxWindows licence
c801d85f
KB
9/////////////////////////////////////////////////////////////////////////////
10
11#ifndef __LISTCTRLH_G__
12#define __LISTCTRLH_G__
13
14#ifdef __GNUG__
0d3820b3 15#pragma interface "listctrl.h"
c801d85f
KB
16#endif
17
18#include "wx/defs.h"
19#include "wx/object.h"
f60d0f94 20#include "wx/generic/imaglist.h"
c801d85f
KB
21#include "wx/control.h"
22#include "wx/timer.h"
ee7ee469 23#include "wx/textctrl.h"
c801d85f
KB
24#include "wx/dcclient.h"
25#include "wx/scrolwin.h"
26#include "wx/settings.h"
27
1e6d9499
JS
28#if wxUSE_DRAG_AND_DROP
29class WXDLLEXPORT wxDropTarget;
30#endif
31
c801d85f
KB
32//-----------------------------------------------------------------------------
33// classes
34//-----------------------------------------------------------------------------
35
1e6d9499
JS
36class WXDLLEXPORT wxListItem;
37class WXDLLEXPORT wxListEvent;
38class WXDLLEXPORT wxListCtrl;
c801d85f
KB
39
40//-----------------------------------------------------------------------------
41// internal classes
42//-----------------------------------------------------------------------------
43
1e6d9499
JS
44class WXDLLEXPORT wxListHeaderData;
45class WXDLLEXPORT wxListItemData;
46class WXDLLEXPORT wxListLineData;
c801d85f 47
1e6d9499
JS
48class WXDLLEXPORT wxListHeaderWindow;
49class WXDLLEXPORT wxListMainWindow;
c801d85f 50
1e6d9499 51class WXDLLEXPORT wxListRenameTimer;
e179bd65 52class WXDLLEXPORT wxListTextCtrl;
c801d85f 53
c801d85f
KB
54//-----------------------------------------------------------------------------
55// wxListItemData (internal)
56//-----------------------------------------------------------------------------
57
1e6d9499 58class WXDLLEXPORT wxListItemData : public wxObject
c801d85f 59{
fd9811b1 60public:
c801d85f
KB
61 wxString m_text;
62 int m_image;
63 long m_data;
64 int m_xpos,m_ypos;
65 int m_width,m_height;
0530737d
VZ
66
67 wxListItemAttr *m_attr;
a3622daa 68
fd9811b1
RR
69public:
70 wxListItemData();
0530737d
VZ
71 ~wxListItemData() { delete m_attr; }
72
c801d85f
KB
73 wxListItemData( const wxListItem &info );
74 void SetItem( const wxListItem &info );
75 void SetText( const wxString &s );
debe6624
JS
76 void SetImage( int image );
77 void SetData( long data );
78 void SetPosition( int x, int y );
79 void SetSize( int width, int height );
fd9811b1
RR
80 bool HasImage() const;
81 bool HasText() const;
debe6624 82 bool IsHit( int x, int y ) const;
c801d85f 83 void GetText( wxString &s );
0530737d 84 const wxString& GetText() { return m_text; }
c801d85f
KB
85 int GetX( void ) const;
86 int GetY( void ) const;
fd9811b1
RR
87 int GetWidth() const;
88 int GetHeight() const;
89 int GetImage() const;
0530737d
VZ
90 void GetItem( wxListItem &info ) const;
91
92 wxListItemAttr *GetAttributes() const { return m_attr; }
57c4d796 93
fd9811b1
RR
94private:
95 DECLARE_DYNAMIC_CLASS(wxListItemData);
c801d85f
KB
96};
97
98//-----------------------------------------------------------------------------
99// wxListHeaderData (internal)
100//-----------------------------------------------------------------------------
101
1e6d9499 102class WXDLLEXPORT wxListHeaderData : public wxObject
c801d85f 103{
b16088bf 104protected:
c801d85f
KB
105 long m_mask;
106 int m_image;
107 wxString m_text;
108 int m_format;
109 int m_width;
110 int m_xpos,m_ypos;
111 int m_height;
a3622daa 112
b16088bf 113public:
fd9811b1 114 wxListHeaderData();
c801d85f
KB
115 wxListHeaderData( const wxListItem &info );
116 void SetItem( const wxListItem &item );
debe6624
JS
117 void SetPosition( int x, int y );
118 void SetWidth( int w );
119 void SetFormat( int format );
120 void SetHeight( int h );
fd9811b1
RR
121 bool HasImage() const;
122 bool HasText() const;
debe6624 123 bool IsHit( int x, int y ) const;
c801d85f
KB
124 void GetItem( wxListItem &item );
125 void GetText( wxString &s );
fd9811b1
RR
126 int GetImage() const;
127 int GetWidth() const;
128 int GetFormat() const;
b16088bf
RR
129
130private:
131 DECLARE_DYNAMIC_CLASS(wxListHeaderData);
c801d85f
KB
132};
133
134//-----------------------------------------------------------------------------
135// wxListLineData (internal)
136//-----------------------------------------------------------------------------
137
1e6d9499 138class WXDLLEXPORT wxListLineData : public wxObject
c801d85f 139{
b16088bf 140public:
c801d85f 141 wxList m_items;
fd9811b1
RR
142 wxRect m_bound_all;
143 wxRect m_bound_label;
144 wxRect m_bound_icon;
145 wxRect m_bound_hilight;
c801d85f
KB
146 int m_mode;
147 bool m_hilighted;
148 wxBrush *m_hilightBrush;
149 int m_spacing;
150 wxListMainWindow *m_owner;
151
1e6d9499 152 void DoDraw( wxDC *dc, bool hilight, bool paintBG );
c801d85f 153
b16088bf
RR
154public:
155 wxListLineData() {}
debe6624 156 wxListLineData( wxListMainWindow *owner, int mode, wxBrush *hilightBrush );
1e6d9499
JS
157 void CalculateSize( wxDC *dc, int spacing );
158 void SetPosition( wxDC *dc, int x, int y, int window_width );
debe6624 159 void SetColumnPosition( int index, int x );
c801d85f
KB
160 void GetSize( int &width, int &height );
161 void GetExtent( int &x, int &y, int &width, int &height );
162 void GetLabelExtent( int &x, int &y, int &width, int &height );
debe6624
JS
163 long IsHit( int x, int y );
164 void InitItems( int num );
165 void SetItem( int index, const wxListItem &info );
166 void GetItem( int index, wxListItem &info );
167 void GetText( int index, wxString &s );
168 void SetText( int index, const wxString s );
169 int GetImage( int index );
0a240683 170 void GetRect( wxRect &rect );
debe6624 171 void Hilight( bool on );
fd9811b1 172 void ReverseHilight();
1e6d9499
JS
173 void DrawRubberBand( wxDC *dc, bool on );
174 void Draw( wxDC *dc );
0a240683 175 bool IsInRect( int x, int y, const wxRect &rect );
fd9811b1 176 bool IsHilighted();
0a240683
JS
177 void AssignRect( wxRect &dest, int x, int y, int width, int height );
178 void AssignRect( wxRect &dest, const wxRect &source );
b16088bf
RR
179
180private:
0530737d
VZ
181 void SetAttributes(wxDC *dc,
182 const wxListItemAttr *attr,
470caaf9
VZ
183 const wxColour& colText, const wxFont& font,
184 bool hilight);
0530737d 185
b16088bf 186 DECLARE_DYNAMIC_CLASS(wxListLineData);
c801d85f
KB
187};
188
189//-----------------------------------------------------------------------------
190// wxListHeaderWindow (internal)
191//-----------------------------------------------------------------------------
192
1e6d9499 193class WXDLLEXPORT wxListHeaderWindow : public wxWindow
c801d85f 194{
b16088bf 195protected:
c801d85f
KB
196 wxListMainWindow *m_owner;
197 wxCursor *m_currentCursor;
198 wxCursor *m_resizeCursor;
cfb50f14 199 bool m_isDragging;
0208334d
RR
200 int m_column;
201 int m_minX;
202 int m_currentX;
c801d85f 203
b16088bf 204public:
fd9811b1
RR
205 wxListHeaderWindow();
206 ~wxListHeaderWindow();
a3622daa 207 wxListHeaderWindow( wxWindow *win, wxWindowID id, wxListMainWindow *owner,
debe6624
JS
208 const wxPoint &pos = wxDefaultPosition, const wxSize &size = wxDefaultSize,
209 long style = 0, const wxString &name = "columntitles" );
1e6d9499 210 void DoDrawRect( wxDC *dc, int x, int y, int w, int h );
c801d85f 211 void OnPaint( wxPaintEvent &event );
0208334d 212 void DrawCurrent();
c801d85f
KB
213 void OnMouse( wxMouseEvent &event );
214 void OnSetFocus( wxFocusEvent &event );
a3622daa 215
b16088bf
RR
216private:
217 DECLARE_DYNAMIC_CLASS(wxListHeaderWindow)
218 DECLARE_EVENT_TABLE()
c801d85f
KB
219};
220
221//-----------------------------------------------------------------------------
222// wxListRenameTimer (internal)
223//-----------------------------------------------------------------------------
224
1e6d9499 225class WXDLLEXPORT wxListRenameTimer: public wxTimer
c801d85f 226{
b16088bf
RR
227private:
228 wxListMainWindow *m_owner;
a3622daa 229
b16088bf
RR
230public:
231 wxListRenameTimer( wxListMainWindow *owner );
232 void Notify();
c801d85f
KB
233};
234
c801d85f
KB
235//-----------------------------------------------------------------------------
236// wxListTextCtrl (internal)
237//-----------------------------------------------------------------------------
238
1e6d9499 239class WXDLLEXPORT wxListTextCtrl: public wxTextCtrl
c801d85f 240{
b16088bf 241private:
c801d85f
KB
242 bool *m_accept;
243 wxString *m_res;
244 wxListMainWindow *m_owner;
5f1ea0ee 245 wxString m_startValue;
c801d85f 246
b16088bf
RR
247public:
248 wxListTextCtrl() {}
57c4d796 249 wxListTextCtrl( wxWindow *parent, const wxWindowID id,
ee7ee469
RR
250 bool *accept, wxString *res, wxListMainWindow *owner,
251 const wxString &value = "",
252 const wxPoint &pos = wxDefaultPosition, const wxSize &size = wxDefaultSize,
0530737d 253 int style = 0,
57c4d796 254#if wxUSE_VALIDATORS
0530737d 255 const wxValidator& validator = wxDefaultValidator,
57c4d796 256#endif
ee7ee469
RR
257 const wxString &name = "wxListTextCtrlText" );
258 void OnChar( wxKeyEvent &event );
259 void OnKillFocus( wxFocusEvent &event );
57c4d796 260
b16088bf
RR
261private:
262 DECLARE_DYNAMIC_CLASS(wxListTextCtrl);
263 DECLARE_EVENT_TABLE()
c801d85f
KB
264};
265
c801d85f
KB
266//-----------------------------------------------------------------------------
267// wxListMainWindow (internal)
268//-----------------------------------------------------------------------------
269
1e6d9499 270class WXDLLEXPORT wxListMainWindow: public wxScrolledWindow
c801d85f 271{
b16088bf 272public:
c801d85f
KB
273 long m_mode;
274 wxList m_lines;
a3622daa 275 wxList m_columns;
c801d85f 276 wxListLineData *m_current;
e179bd65 277 wxListLineData *m_currentEdit;
c801d85f
KB
278 int m_visibleLines;
279 wxBrush *m_hilightBrush;
280 wxColour *m_hilightColour;
c801d85f
KB
281 int m_xScroll,m_yScroll;
282 bool m_dirty;
283 wxImageList *m_small_image_list;
284 wxImageList *m_normal_image_list;
285 int m_small_spacing;
286 int m_normal_spacing;
287 bool m_hasFocus;
288 bool m_usedKeys;
289 bool m_lastOnSame;
290 wxTimer *m_renameTimer;
c801d85f
KB
291 bool m_renameAccept;
292 wxString m_renameRes;
293 bool m_isCreated;
e3e65dac 294 int m_dragCount;
fd9811b1 295 wxPoint m_dragStart;
c801d85f 296
b16088bf 297public:
e179bd65 298 wxListMainWindow();
a3622daa 299 wxListMainWindow( wxWindow *parent, wxWindowID id,
debe6624
JS
300 const wxPoint &pos = wxDefaultPosition, const wxSize &size = wxDefaultSize,
301 long style = 0, const wxString &name = "listctrl" );
e179bd65 302 ~wxListMainWindow();
c801d85f
KB
303 void RefreshLine( wxListLineData *line );
304 void OnPaint( wxPaintEvent &event );
debe6624 305 void HilightAll( bool on );
64693098 306 void SendNotify( wxListLineData *line, wxEventType command );
c801d85f
KB
307 void FocusLine( wxListLineData *line );
308 void UnfocusLine( wxListLineData *line );
309 void SelectLine( wxListLineData *line );
310 void DeselectLine( wxListLineData *line );
311 void DeleteLine( wxListLineData *line );
57c4d796 312
5f1ea0ee
RR
313 void EditLabel( long item );
314 void Edit( long item ) { EditLabel(item); } // deprecated
e179bd65
RR
315 void OnRenameTimer();
316 void OnRenameAccept();
57c4d796 317
c801d85f 318 void OnMouse( wxMouseEvent &event );
e179bd65 319 void MoveToFocus();
c801d85f
KB
320 void OnArrowChar( wxListLineData *newCurrent, bool shiftDown );
321 void OnChar( wxKeyEvent &event );
3dfb93fd 322 void OnKeyDown( wxKeyEvent &event );
c801d85f
KB
323 void OnSetFocus( wxFocusEvent &event );
324 void OnKillFocus( wxFocusEvent &event );
325 void OnSize( wxSizeEvent &event );
0530737d
VZ
326 void OnScroll(wxScrollWinEvent& event) ;
327
1e6d9499 328 void DrawImage( int index, wxDC *dc, int x, int y );
c801d85f
KB
329 void GetImageSize( int index, int &width, int &height );
330 int GetIndexOfLine( const wxListLineData *line );
331 int GetTextLength( wxString &s ); // should be const
332
debe6624
JS
333 void SetImageList( wxImageList *imageList, int which );
334 void SetItemSpacing( int spacing, bool isSmall = FALSE );
335 int GetItemSpacing( bool isSmall = FALSE );
336 void SetColumn( int col, wxListItem &item );
337 void SetColumnWidth( int col, int width );
338 void GetColumn( int col, wxListItem &item );
339 int GetColumnWidth( int vol );
e179bd65
RR
340 int GetColumnCount();
341 int GetCountPerPage();
c801d85f
KB
342 void SetItem( wxListItem &item );
343 void GetItem( wxListItem &item );
a3622daa 344 void SetItemState( long item, long state, long stateMask );
debe6624 345 int GetItemState( long item, long stateMask );
e179bd65 346 int GetItemCount();
0a240683 347 void GetItemRect( long index, wxRect &rect );
e179bd65
RR
348 bool GetItemPosition( long item, wxPoint& pos );
349 int GetSelectedItemCount();
debe6624 350 void SetMode( long mode );
e179bd65
RR
351 long GetMode() const;
352 void CalculatePositions();
353 void RealizeChanges();
debe6624
JS
354 long GetNextItem( long item, int geometry, int state );
355 void DeleteItem( long index );
e179bd65 356 void DeleteAllItems();
debe6624 357 void DeleteColumn( int col );
e179bd65 358 void DeleteEverything();
debe6624 359 void EnsureVisible( long index );
e179bd65
RR
360 long FindItem( long start, const wxString& str, bool partial = FALSE );
361 long FindItem( long start, long data);
debe6624 362 long HitTest( int x, int y, int &flags );
c801d85f 363 void InsertItem( wxListItem &item );
30dea054 364// void AddItem( wxListItem &item );
debe6624 365 void InsertColumn( long col, wxListItem &item );
30dea054 366// void AddColumn( wxListItem &item );
c801d85f 367 void SortItems( wxListCtrlCompare fn, long data );
a3622daa 368
b16088bf
RR
369private:
370 DECLARE_DYNAMIC_CLASS(wxListMainWindow);
371 DECLARE_EVENT_TABLE()
c801d85f
KB
372};
373
374//-----------------------------------------------------------------------------
375// wxListCtrl
376//-----------------------------------------------------------------------------
377
1e6d9499 378class WXDLLEXPORT wxListCtrl: public wxControl
c801d85f 379{
b16088bf 380public:
e179bd65 381 wxListCtrl();
32e9da8b 382 wxListCtrl( wxWindow *parent, wxWindowID id = -1,
debe6624 383 const wxPoint &pos = wxDefaultPosition, const wxSize &size = wxDefaultSize,
57c4d796 384#if wxUSE_VALIDATORS
32e9da8b 385 long style = wxLC_ICON, const wxValidator& validator = wxDefaultValidator,
57c4d796 386#endif
32e9da8b
RR
387 const wxString &name = "listctrl" )
388 {
b16088bf 389 Create(parent, id, pos, size, style, validator, name);
32e9da8b 390 }
e179bd65 391 ~wxListCtrl();
b16088bf 392
32e9da8b 393 bool Create( wxWindow *parent, wxWindowID id = -1,
debe6624 394 const wxPoint &pos = wxDefaultPosition, const wxSize &size = wxDefaultSize,
57c4d796 395#if wxUSE_VALIDATORS
32e9da8b 396 long style = wxLC_ICON, const wxValidator& validator = wxDefaultValidator,
57c4d796 397#endif
b16088bf
RR
398 const wxString &name = "listctrl" );
399
e487524e 400 bool GetColumn( int col, wxListItem& item ) const;
debe6624 401 bool SetColumn( int col, wxListItem& item );
e487524e 402 int GetColumnWidth( int col ) const;
debe6624 403 bool SetColumnWidth( int col, int width);
e179bd65 404 int GetCountPerPage() const; // not the same in wxGLC as in Windows, I think
b16088bf 405
e487524e 406 bool GetItem( wxListItem& info ) const;
c801d85f 407 bool SetItem( wxListItem& info ) ;
debe6624 408 long SetItem( long index, int col, const wxString& label, int imageId = -1 );
e487524e 409 int GetItemState( long item, long stateMask ) const;
debe6624
JS
410 bool SetItemState( long item, long state, long stateMask);
411 bool SetItemImage( long item, int image, int selImage);
e487524e 412 wxString GetItemText( long item ) const;
debe6624 413 void SetItemText( long item, const wxString& str );
e487524e 414 long GetItemData( long item ) const;
debe6624 415 bool SetItemData( long item, long data );
0a240683 416 bool GetItemRect( long item, wxRect& rect, int code = wxLIST_RECT_BOUNDS ) const;
e487524e 417 bool GetItemPosition( long item, wxPoint& pos ) const;
debe6624 418 bool SetItemPosition( long item, const wxPoint& pos ); // not supported in wxGLC
e179bd65
RR
419 int GetItemCount() const;
420 int GetColumnCount() const;
33d0b396 421 void SetItemSpacing( int spacing, bool isSmall = FALSE );
e487524e 422 int GetItemSpacing( bool isSmall ) const;
e179bd65 423 int GetSelectedItemCount() const;
0530737d
VZ
424 wxColour GetTextColour() const;
425 void SetTextColour(const wxColour& col);
e179bd65 426 long GetTopItem() const;
b16088bf 427
debe6624 428 void SetSingleStyle( long style, bool add = TRUE ) ;
e179bd65
RR
429 void SetWindowStyleFlag( long style );
430 void RecreateWindow() {}
431 long GetNextItem( long item, int geometry = wxLIST_NEXT_ALL, int state = wxLIST_STATE_DONTCARE ) const;
432 wxImageList *GetImageList( int which ) const;
433 void SetImageList( wxImageList *imageList, int which );
debe6624 434 bool Arrange( int flag = wxLIST_ALIGN_DEFAULT ); // always wxLIST_ALIGN_LEFT in wxGLC
57c4d796 435
4f22cf8d 436 void ClearAll();
debe6624 437 bool DeleteItem( long item );
e179bd65
RR
438 bool DeleteAllItems();
439 bool DeleteAllColumns();
debe6624 440 bool DeleteColumn( int col );
57c4d796 441
e179bd65
RR
442 void EditLabel( long item ) { Edit(item); }
443 void Edit( long item );
57c4d796 444
debe6624 445 bool EnsureVisible( long item );
e179bd65
RR
446 long FindItem( long start, const wxString& str, bool partial = FALSE );
447 long FindItem( long start, long data );
448 long FindItem( long start, const wxPoint& pt, int direction ); // not supported in wxGLC
449 long HitTest( const wxPoint& point, int& flags);
c801d85f 450 long InsertItem(wxListItem& info);
e179bd65
RR
451 long InsertItem( long index, const wxString& label );
452 long InsertItem( long index, int imageIndex );
453 long InsertItem( long index, const wxString& label, int imageIndex );
454 long InsertColumn( long col, wxListItem& info );
455 long InsertColumn( long col, const wxString& heading, int format = wxLIST_FORMAT_LEFT,
456 int width = -1 );
457 bool ScrollList( int dx, int dy );
458 bool SortItems( wxListCtrlCompare fn, long data );
459 bool Update( long item );
b16088bf 460
77e7a1dc 461 void OnIdle( wxIdleEvent &event );
b16088bf 462 void OnSize( wxSizeEvent &event );
57c4d796 463
77e7a1dc 464 // We have to hand down a few functions
57c4d796 465
f03fc89f
VZ
466 bool SetBackgroundColour( const wxColour &colour );
467 bool SetForegroundColour( const wxColour &colour );
468 bool SetFont( const wxFont &font );
57c4d796 469
1e6d9499 470#if wxUSE_DRAG_AND_DROP
c801d85f 471 void SetDropTarget( wxDropTarget *dropTarget )
77e7a1dc 472 { m_mainWin->SetDropTarget( dropTarget ); }
c801d85f 473 wxDropTarget *GetDropTarget() const
77e7a1dc 474 { return m_mainWin->GetDropTarget(); }
1e6d9499
JS
475#endif
476
f03fc89f
VZ
477 bool SetCursor( const wxCursor &cursor )
478 { return m_mainWin ? m_mainWin->wxWindow::SetCursor(cursor) : FALSE; }
77e7a1dc 479 wxColour GetBackgroundColour() const
f03fc89f 480 { return m_mainWin ? m_mainWin->GetBackgroundColour() : wxColour(); }
77e7a1dc 481 wxColour GetForegroundColour() const
f03fc89f 482 { return m_mainWin ? m_mainWin->GetForegroundColour() : wxColour(); }
a1665b22 483 bool DoPopupMenu( wxMenu *menu, int x, int y )
39570cd4 484 { return m_mainWin->PopupMenu( menu, x, y ); }
b292e2f5 485 void SetFocus()
b16088bf 486 {
c0d6c58b
KB
487 /* The test in window.cpp fails as we are a composite
488 window, so it checks against "this", but not m_mainWin. */
b16088bf
RR
489 if (FindFocus() != this)
490 m_mainWin->SetFocus();
491 }
c801d85f 492
b16088bf
RR
493 // implementation
494 // --------------
57c4d796 495
a3622daa
VZ
496 wxImageList *m_imageListNormal;
497 wxImageList *m_imageListSmall;
c801d85f
KB
498 wxImageList *m_imageListState; // what's that ?
499 wxListHeaderWindow *m_headerWin;
500 wxListMainWindow *m_mainWin;
a3622daa 501
b16088bf
RR
502private:
503 DECLARE_EVENT_TABLE()
504 DECLARE_DYNAMIC_CLASS(wxListCtrl);
c801d85f
KB
505};
506
507
508#endif // __LISTCTRLH_G__