]> git.saurik.com Git - wxWidgets.git/blame_incremental - include/wx/generic/listctrl.h
1. kbd interface for wxScrolledWindow
[wxWidgets.git] / include / wx / generic / listctrl.h
... / ...
CommitLineData
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
29class WXDLLEXPORT wxDropTarget;
30#endif
31
32//-----------------------------------------------------------------------------
33// classes
34//-----------------------------------------------------------------------------
35
36class WXDLLEXPORT wxListItem;
37class WXDLLEXPORT wxListEvent;
38class WXDLLEXPORT wxListCtrl;
39
40//-----------------------------------------------------------------------------
41// internal classes
42//-----------------------------------------------------------------------------
43
44class WXDLLEXPORT wxListHeaderData;
45class WXDLLEXPORT wxListItemData;
46class WXDLLEXPORT wxListLineData;
47
48class WXDLLEXPORT wxListHeaderWindow;
49class WXDLLEXPORT wxListMainWindow;
50
51class WXDLLEXPORT wxListRenameTimer;
52class WXDLLEXPORT wxListTextCtrl;
53
54//-----------------------------------------------------------------------------
55// wxListItemData (internal)
56//-----------------------------------------------------------------------------
57
58class WXDLLEXPORT wxListItemData : public wxObject
59{
60public:
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
67 wxListItemAttr *m_attr;
68
69public:
70 wxListItemData();
71 ~wxListItemData() { delete m_attr; }
72
73 wxListItemData( const wxListItem &info );
74 void SetItem( const wxListItem &info );
75 void SetText( const wxString &s );
76 void SetImage( int image );
77 void SetData( long data );
78 void SetPosition( int x, int y );
79 void SetSize( int width, int height );
80 bool HasImage() const;
81 bool HasText() const;
82 bool IsHit( int x, int y ) const;
83 void GetText( wxString &s );
84 const wxString& GetText() { return m_text; }
85 int GetX( void ) const;
86 int GetY( void ) const;
87 int GetWidth() const;
88 int GetHeight() const;
89 int GetImage() const;
90 void GetItem( wxListItem &info ) const;
91
92 wxListItemAttr *GetAttributes() const { return m_attr; }
93
94private:
95 DECLARE_DYNAMIC_CLASS(wxListItemData);
96};
97
98//-----------------------------------------------------------------------------
99// wxListHeaderData (internal)
100//-----------------------------------------------------------------------------
101
102class WXDLLEXPORT wxListHeaderData : public wxObject
103{
104protected:
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;
112
113public:
114 wxListHeaderData();
115 wxListHeaderData( const wxListItem &info );
116 void SetItem( const wxListItem &item );
117 void SetPosition( int x, int y );
118 void SetWidth( int w );
119 void SetFormat( int format );
120 void SetHeight( int h );
121 bool HasImage() const;
122 bool HasText() const;
123 bool IsHit( int x, int y ) const;
124 void GetItem( wxListItem &item );
125 void GetText( wxString &s );
126 int GetImage() const;
127 int GetWidth() const;
128 int GetFormat() const;
129
130private:
131 DECLARE_DYNAMIC_CLASS(wxListHeaderData);
132};
133
134//-----------------------------------------------------------------------------
135// wxListLineData (internal)
136//-----------------------------------------------------------------------------
137
138class WXDLLEXPORT wxListLineData : public wxObject
139{
140public:
141 wxList m_items;
142 wxRect m_bound_all;
143 wxRect m_bound_label;
144 wxRect m_bound_icon;
145 wxRect m_bound_hilight;
146 int m_mode;
147 bool m_hilighted;
148 wxBrush *m_hilightBrush;
149 int m_spacing;
150 wxListMainWindow *m_owner;
151
152 void DoDraw( wxDC *dc, bool hilight, bool paintBG );
153
154public:
155 wxListLineData() {}
156 wxListLineData( wxListMainWindow *owner, int mode, wxBrush *hilightBrush );
157 void CalculateSize( wxDC *dc, int spacing );
158 void SetPosition( wxDC *dc, int x, int y, int window_width );
159 void SetColumnPosition( int index, int x );
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 );
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 );
170 void GetRect( wxRect &rect );
171 void Hilight( bool on );
172 void ReverseHilight();
173 void DrawRubberBand( wxDC *dc, bool on );
174 void Draw( wxDC *dc );
175 bool IsInRect( int x, int y, const wxRect &rect );
176 bool IsHilighted();
177 void AssignRect( wxRect &dest, int x, int y, int width, int height );
178 void AssignRect( wxRect &dest, const wxRect &source );
179
180private:
181 void SetAttributes(wxDC *dc,
182 const wxListItemAttr *attr,
183 const wxColour& colText, const wxFont& font,
184 bool hilight);
185
186 DECLARE_DYNAMIC_CLASS(wxListLineData);
187};
188
189//-----------------------------------------------------------------------------
190// wxListHeaderWindow (internal)
191//-----------------------------------------------------------------------------
192
193class WXDLLEXPORT wxListHeaderWindow : public wxWindow
194{
195protected:
196 wxListMainWindow *m_owner;
197 wxCursor *m_currentCursor;
198 wxCursor *m_resizeCursor;
199 bool m_isDragging;
200 int m_column;
201 int m_minX;
202 int m_currentX;
203
204public:
205 wxListHeaderWindow();
206 ~wxListHeaderWindow();
207 wxListHeaderWindow( wxWindow *win, wxWindowID id, wxListMainWindow *owner,
208 const wxPoint &pos = wxDefaultPosition, const wxSize &size = wxDefaultSize,
209 long style = 0, const wxString &name = "columntitles" );
210 void DoDrawRect( wxDC *dc, int x, int y, int w, int h );
211 void OnPaint( wxPaintEvent &event );
212 void DrawCurrent();
213 void OnMouse( wxMouseEvent &event );
214 void OnSetFocus( wxFocusEvent &event );
215
216private:
217 DECLARE_DYNAMIC_CLASS(wxListHeaderWindow)
218 DECLARE_EVENT_TABLE()
219};
220
221//-----------------------------------------------------------------------------
222// wxListRenameTimer (internal)
223//-----------------------------------------------------------------------------
224
225class WXDLLEXPORT wxListRenameTimer: public wxTimer
226{
227private:
228 wxListMainWindow *m_owner;
229
230public:
231 wxListRenameTimer( wxListMainWindow *owner );
232 void Notify();
233};
234
235//-----------------------------------------------------------------------------
236// wxListTextCtrl (internal)
237//-----------------------------------------------------------------------------
238
239class WXDLLEXPORT wxListTextCtrl: public wxTextCtrl
240{
241private:
242 bool *m_accept;
243 wxString *m_res;
244 wxListMainWindow *m_owner;
245 wxString m_startValue;
246
247public:
248 wxListTextCtrl() {}
249 wxListTextCtrl( wxWindow *parent, const wxWindowID id,
250 bool *accept, wxString *res, wxListMainWindow *owner,
251 const wxString &value = "",
252 const wxPoint &pos = wxDefaultPosition, const wxSize &size = wxDefaultSize,
253 int style = 0,
254 const wxValidator& validator = wxDefaultValidator,
255 const wxString &name = "wxListTextCtrlText" );
256 void OnChar( wxKeyEvent &event );
257 void OnKillFocus( wxFocusEvent &event );
258
259private:
260 DECLARE_DYNAMIC_CLASS(wxListTextCtrl);
261 DECLARE_EVENT_TABLE()
262};
263
264//-----------------------------------------------------------------------------
265// wxListMainWindow (internal)
266//-----------------------------------------------------------------------------
267
268class WXDLLEXPORT wxListMainWindow: public wxScrolledWindow
269{
270public:
271 long m_mode;
272 wxList m_lines;
273 wxList m_columns;
274 wxListLineData *m_current;
275 wxListLineData *m_currentEdit;
276 int m_visibleLines;
277 wxBrush *m_hilightBrush;
278 wxColour *m_hilightColour;
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;
289 bool m_renameAccept;
290 wxString m_renameRes;
291 bool m_isCreated;
292 int m_dragCount;
293 wxPoint m_dragStart;
294
295public:
296 wxListMainWindow();
297 wxListMainWindow( wxWindow *parent, wxWindowID id,
298 const wxPoint &pos = wxDefaultPosition, const wxSize &size = wxDefaultSize,
299 long style = 0, const wxString &name = "listctrl" );
300 ~wxListMainWindow();
301 void RefreshLine( wxListLineData *line );
302 void OnPaint( wxPaintEvent &event );
303 void HilightAll( bool on );
304 void SendNotify( wxListLineData *line, wxEventType command );
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 );
310
311 void EditLabel( long item );
312 void Edit( long item ) { EditLabel(item); } // deprecated
313 void OnRenameTimer();
314 void OnRenameAccept();
315
316 void OnMouse( wxMouseEvent &event );
317 void MoveToFocus();
318 void OnArrowChar( wxListLineData *newCurrent, bool shiftDown );
319 void OnChar( wxKeyEvent &event );
320 void OnKeyDown( wxKeyEvent &event );
321 void OnSetFocus( wxFocusEvent &event );
322 void OnKillFocus( wxFocusEvent &event );
323 void OnSize( wxSizeEvent &event );
324 void OnScroll(wxScrollWinEvent& event) ;
325
326 void DrawImage( int index, wxDC *dc, int x, int y );
327 void GetImageSize( int index, int &width, int &height );
328 int GetIndexOfLine( const wxListLineData *line );
329 int GetTextLength( wxString &s ); // should be const
330
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 );
338 int GetColumnCount();
339 int GetCountPerPage();
340 void SetItem( wxListItem &item );
341 void GetItem( wxListItem &item );
342 void SetItemState( long item, long state, long stateMask );
343 int GetItemState( long item, long stateMask );
344 int GetItemCount();
345 void GetItemRect( long index, wxRect &rect );
346 bool GetItemPosition( long item, wxPoint& pos );
347 int GetSelectedItemCount();
348 void SetMode( long mode );
349 long GetMode() const;
350 void CalculatePositions();
351 void RealizeChanges();
352 long GetNextItem( long item, int geometry, int state );
353 void DeleteItem( long index );
354 void DeleteAllItems();
355 void DeleteColumn( int col );
356 void DeleteEverything();
357 void EnsureVisible( long index );
358 long FindItem( long start, const wxString& str, bool partial = FALSE );
359 long FindItem( long start, long data);
360 long HitTest( int x, int y, int &flags );
361 void InsertItem( wxListItem &item );
362// void AddItem( wxListItem &item );
363 void InsertColumn( long col, wxListItem &item );
364// void AddColumn( wxListItem &item );
365 void SortItems( wxListCtrlCompare fn, long data );
366
367private:
368 DECLARE_DYNAMIC_CLASS(wxListMainWindow);
369 DECLARE_EVENT_TABLE()
370};
371
372//-----------------------------------------------------------------------------
373// wxListCtrl
374//-----------------------------------------------------------------------------
375
376class WXDLLEXPORT wxListCtrl: public wxControl
377{
378public:
379 wxListCtrl();
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" )
387 {
388 Create(parent, id, pos, size, style, validator, name);
389 }
390 ~wxListCtrl();
391
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" );
399
400 bool GetColumn( int col, wxListItem& item ) const;
401 bool SetColumn( int col, wxListItem& item );
402 int GetColumnWidth( int col ) const;
403 bool SetColumnWidth( int col, int width);
404 int GetCountPerPage() const; // not the same in wxGLC as in Windows, I think
405
406 bool GetItem( wxListItem& info ) const;
407 bool SetItem( wxListItem& info ) ;
408 long SetItem( long index, int col, const wxString& label, int imageId = -1 );
409 int GetItemState( long item, long stateMask ) const;
410 bool SetItemState( long item, long state, long stateMask);
411 bool SetItemImage( long item, int image, int selImage);
412 wxString GetItemText( long item ) const;
413 void SetItemText( long item, const wxString& str );
414 long GetItemData( long item ) const;
415 bool SetItemData( long item, long data );
416 bool GetItemRect( long item, wxRect& rect, int code = wxLIST_RECT_BOUNDS ) const;
417 bool GetItemPosition( long item, wxPoint& pos ) const;
418 bool SetItemPosition( long item, const wxPoint& pos ); // not supported in wxGLC
419 int GetItemCount() const;
420 int GetColumnCount() const;
421 void SetItemSpacing( int spacing, bool isSmall = FALSE );
422 int GetItemSpacing( bool isSmall ) const;
423 int GetSelectedItemCount() const;
424 wxColour GetTextColour() const;
425 void SetTextColour(const wxColour& col);
426 long GetTopItem() const;
427
428 void SetSingleStyle( long style, bool add = TRUE ) ;
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 );
434 bool Arrange( int flag = wxLIST_ALIGN_DEFAULT ); // always wxLIST_ALIGN_LEFT in wxGLC
435
436 void ClearAll();
437 bool DeleteItem( long item );
438 bool DeleteAllItems();
439 bool DeleteAllColumns();
440 bool DeleteColumn( int col );
441
442 void EditLabel( long item ) { Edit(item); }
443 void Edit( long item );
444
445 bool EnsureVisible( long item );
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);
450 long InsertItem(wxListItem& info);
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 );
460
461 void OnIdle( wxIdleEvent &event );
462 void OnSize( wxSizeEvent &event );
463
464 // We have to hand down a few functions
465
466 bool SetBackgroundColour( const wxColour &colour );
467 bool SetForegroundColour( const wxColour &colour );
468 bool SetFont( const wxFont &font );
469
470#if wxUSE_DRAG_AND_DROP
471 void SetDropTarget( wxDropTarget *dropTarget )
472 { m_mainWin->SetDropTarget( dropTarget ); }
473 wxDropTarget *GetDropTarget() const
474 { return m_mainWin->GetDropTarget(); }
475#endif
476
477 bool SetCursor( const wxCursor &cursor )
478 { return m_mainWin ? m_mainWin->wxWindow::SetCursor(cursor) : FALSE; }
479 wxColour GetBackgroundColour() const
480 { return m_mainWin ? m_mainWin->GetBackgroundColour() : wxColour(); }
481 wxColour GetForegroundColour() const
482 { return m_mainWin ? m_mainWin->GetForegroundColour() : wxColour(); }
483 bool DoPopupMenu( wxMenu *menu, int x, int y )
484 { return m_mainWin->PopupMenu( menu, x, y ); }
485 void SetFocus()
486 {
487 /* The test in window.cpp fails as we are a composite
488 window, so it checks against "this", but not m_mainWin. */
489 if (FindFocus() != this)
490 m_mainWin->SetFocus();
491 }
492
493 // implementation
494 // --------------
495
496 wxImageList *m_imageListNormal;
497 wxImageList *m_imageListSmall;
498 wxImageList *m_imageListState; // what's that ?
499 wxListHeaderWindow *m_headerWin;
500 wxListMainWindow *m_mainWin;
501
502private:
503 DECLARE_EVENT_TABLE()
504 DECLARE_DYNAMIC_CLASS(wxListCtrl);
505};
506
507
508#endif // __LISTCTRLH_G__