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