]> git.saurik.com Git - wxWidgets.git/blame - include/wx/generic/listctrl.h
Add draft wxPlotWindow
[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,
0530737d 254 const wxValidator& validator = wxDefaultValidator,
ee7ee469
RR
255 const wxString &name = "wxListTextCtrlText" );
256 void OnChar( wxKeyEvent &event );
257 void OnKillFocus( wxFocusEvent &event );
57c4d796 258
b16088bf
RR
259private:
260 DECLARE_DYNAMIC_CLASS(wxListTextCtrl);
261 DECLARE_EVENT_TABLE()
c801d85f
KB
262};
263
c801d85f
KB
264//-----------------------------------------------------------------------------
265// wxListMainWindow (internal)
266//-----------------------------------------------------------------------------
267
1e6d9499 268class WXDLLEXPORT wxListMainWindow: public wxScrolledWindow
c801d85f 269{
b16088bf 270public:
c801d85f
KB
271 long m_mode;
272 wxList m_lines;
a3622daa 273 wxList m_columns;
c801d85f 274 wxListLineData *m_current;
e179bd65 275 wxListLineData *m_currentEdit;
c801d85f
KB
276 int m_visibleLines;
277 wxBrush *m_hilightBrush;
278 wxColour *m_hilightColour;
c801d85f
KB
279 int m_xScroll,m_yScroll;
280 bool m_dirty;
281 wxImageList *m_small_image_list;
282 wxImageList *m_normal_image_list;
283 int m_small_spacing;
284 int m_normal_spacing;
285 bool m_hasFocus;
286 bool m_usedKeys;
287 bool m_lastOnSame;
288 wxTimer *m_renameTimer;
c801d85f
KB
289 bool m_renameAccept;
290 wxString m_renameRes;
291 bool m_isCreated;
e3e65dac 292 int m_dragCount;
fd9811b1 293 wxPoint m_dragStart;
c801d85f 294
b16088bf 295public:
e179bd65 296 wxListMainWindow();
a3622daa 297 wxListMainWindow( wxWindow *parent, wxWindowID id,
debe6624
JS
298 const wxPoint &pos = wxDefaultPosition, const wxSize &size = wxDefaultSize,
299 long style = 0, const wxString &name = "listctrl" );
e179bd65 300 ~wxListMainWindow();
c801d85f
KB
301 void RefreshLine( wxListLineData *line );
302 void OnPaint( wxPaintEvent &event );
debe6624 303 void HilightAll( bool on );
64693098 304 void SendNotify( wxListLineData *line, wxEventType command );
c801d85f
KB
305 void FocusLine( wxListLineData *line );
306 void UnfocusLine( wxListLineData *line );
307 void SelectLine( wxListLineData *line );
308 void DeselectLine( wxListLineData *line );
309 void DeleteLine( wxListLineData *line );
57c4d796 310
5f1ea0ee
RR
311 void EditLabel( long item );
312 void Edit( long item ) { EditLabel(item); } // deprecated
e179bd65
RR
313 void OnRenameTimer();
314 void OnRenameAccept();
57c4d796 315
c801d85f 316 void OnMouse( wxMouseEvent &event );
e179bd65 317 void MoveToFocus();
c801d85f
KB
318 void OnArrowChar( wxListLineData *newCurrent, bool shiftDown );
319 void OnChar( wxKeyEvent &event );
3dfb93fd 320 void OnKeyDown( wxKeyEvent &event );
c801d85f
KB
321 void OnSetFocus( wxFocusEvent &event );
322 void OnKillFocus( wxFocusEvent &event );
323 void OnSize( wxSizeEvent &event );
0530737d
VZ
324 void OnScroll(wxScrollWinEvent& event) ;
325
1e6d9499 326 void DrawImage( int index, wxDC *dc, int x, int y );
c801d85f
KB
327 void GetImageSize( int index, int &width, int &height );
328 int GetIndexOfLine( const wxListLineData *line );
329 int GetTextLength( wxString &s ); // should be const
330
debe6624
JS
331 void SetImageList( wxImageList *imageList, int which );
332 void SetItemSpacing( int spacing, bool isSmall = FALSE );
333 int GetItemSpacing( bool isSmall = FALSE );
334 void SetColumn( int col, wxListItem &item );
335 void SetColumnWidth( int col, int width );
336 void GetColumn( int col, wxListItem &item );
337 int GetColumnWidth( int vol );
e179bd65
RR
338 int GetColumnCount();
339 int GetCountPerPage();
c801d85f
KB
340 void SetItem( wxListItem &item );
341 void GetItem( wxListItem &item );
a3622daa 342 void SetItemState( long item, long state, long stateMask );
debe6624 343 int GetItemState( long item, long stateMask );
e179bd65 344 int GetItemCount();
0a240683 345 void GetItemRect( long index, wxRect &rect );
e179bd65
RR
346 bool GetItemPosition( long item, wxPoint& pos );
347 int GetSelectedItemCount();
debe6624 348 void SetMode( long mode );
e179bd65
RR
349 long GetMode() const;
350 void CalculatePositions();
351 void RealizeChanges();
debe6624
JS
352 long GetNextItem( long item, int geometry, int state );
353 void DeleteItem( long index );
e179bd65 354 void DeleteAllItems();
debe6624 355 void DeleteColumn( int col );
e179bd65 356 void DeleteEverything();
debe6624 357 void EnsureVisible( long index );
e179bd65
RR
358 long FindItem( long start, const wxString& str, bool partial = FALSE );
359 long FindItem( long start, long data);
debe6624 360 long HitTest( int x, int y, int &flags );
c801d85f 361 void InsertItem( wxListItem &item );
30dea054 362// void AddItem( wxListItem &item );
debe6624 363 void InsertColumn( long col, wxListItem &item );
30dea054 364// void AddColumn( wxListItem &item );
c801d85f 365 void SortItems( wxListCtrlCompare fn, long data );
a3622daa 366
b16088bf
RR
367private:
368 DECLARE_DYNAMIC_CLASS(wxListMainWindow);
369 DECLARE_EVENT_TABLE()
c801d85f
KB
370};
371
372//-----------------------------------------------------------------------------
373// wxListCtrl
374//-----------------------------------------------------------------------------
375
1e6d9499 376class WXDLLEXPORT wxListCtrl: public wxControl
c801d85f 377{
b16088bf 378public:
e179bd65 379 wxListCtrl();
674ac8b9
VZ
380 wxListCtrl( wxWindow *parent,
381 wxWindowID id = -1,
382 const wxPoint &pos = wxDefaultPosition,
383 const wxSize &size = wxDefaultSize,
384 long style = wxLC_ICON,
385 const wxValidator& validator = wxDefaultValidator,
386 const wxString &name = "listctrl" )
32e9da8b 387 {
b16088bf 388 Create(parent, id, pos, size, style, validator, name);
32e9da8b 389 }
e179bd65 390 ~wxListCtrl();
b16088bf 391
674ac8b9
VZ
392 bool Create( wxWindow *parent,
393 wxWindowID id = -1,
394 const wxPoint &pos = wxDefaultPosition,
395 const wxSize &size = wxDefaultSize,
396 long style = wxLC_ICON,
397 const wxValidator& validator = wxDefaultValidator,
398 const wxString &name = "listctrl" );
b16088bf 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__