1/////////////////////////////////////////////////////////////////////////////// 2// Name: wx/os2/listctrl.h 3// Purpose: wxListCtrl class 4// Author: 5// Modified by: 6// Created: 7// RCS-ID: $Id: listctrl.h 37982 2006-03-10 21:26:59Z RD $ 8// Copyright: (c) wxWidgets team 9// Licence: wxWindows licence 10/////////////////////////////////////////////////////////////////////////////// 11 12#ifndef _WX_LISTCTRL_H_ 13#define _WX_LISTCTRL_H_ 14 15#if wxUSE_LISTCTRL 16 17#include "wx/control.h" 18#include "wx/event.h" 19#include "wx/hash.h" 20#include "wx/textctrl.h" 21 22 23class WXDLLEXPORT wxImageList; 24 25typedef int (wxCALLBACK *wxListCtrlCompare)(long lItem1, long lItem2, long lSortData); 26 27class WXDLLEXPORT wxListCtrl: public wxControl 28{ 29public: 30 wxListCtrl() { Init(); } 31 wxListCtrl( wxWindow* pParent 32 ,wxWindowID vId = -1 33 ,const wxPoint& rPos = wxDefaultPosition 34 ,const wxSize& rSize = wxDefaultSize 35 ,long lStyle = wxLC_ICON 36 ,const wxValidator& rValidator = wxDefaultValidator 37 ,const wxString& rsName = wxListCtrlNameStr) 38 { 39 Init(); 40 Create( pParent 41 ,vId 42 ,rPos 43 ,rSize 44 ,lStyle 45 ,rValidator 46 ,rsName 47 ); 48 } 49 virtual ~wxListCtrl(); 50 51 bool Create( wxWindow* pParent 52 ,wxWindowID vId = -1 53 ,const wxPoint& rPos = wxDefaultPosition 54 ,const wxSize& rSize = wxDefaultSize 55 ,long lStyle = wxLC_ICON 56 ,const wxValidator& rValidator = wxDefaultValidator 57 ,const wxString& rsName = wxListCtrlNameStr 58 ); 59 60 61 // Attributes 62 //////////////////////////////////////////////////////////////////////////// 63 // 64 65 // 66 // Set the control colours 67 // 68 bool SetForegroundColour(const wxColour& rCol); 69 bool SetBackgroundColour(const wxColour& rCol); 70 71 // 72 // Information about this column 73 // 74 bool GetColumn( int nCol 75 ,wxListItem& rItem 76 ) const; 77 bool SetColumn( int nCol 78 ,wxListItem& rItem 79 ); 80 81 // 82 // Column width 83 // 84 int GetColumnWidth(int nCol) const; 85 bool SetColumnWidth( int nCol 86 ,int nWidth 87 ); 88 89 // 90 // Gets the number of items that can fit vertically in the 91 // visible area of the list control (list or report view) 92 // or the total number of items in the list control (icon 93 // or small icon view) 94 // 95 int GetCountPerPage(void) const; 96 97 wxRect GetViewRect() const; 98 // 99 // Gets the edit control for editing labels. 100 // 101 wxTextCtrl* GetEditControl(void) const; 102 103 // 104 // Information about the item 105 // 106 bool GetItem(wxListItem& rInfo) const; 107 bool SetItem(wxListItem& rInfo); 108 109 // 110 // Sets a string field at a particular column 111 // 112 long SetItem( long lIndex 113 ,int nCol 114 ,const wxString& rsLabel 115 ,int nImageId = -1 116 ); 117 118 // 119 // Item state 120 // 121 int GetItemState( long lItem 122 ,long lStateMask 123 ) const; 124 bool SetItemState( long lItem 125 ,long lState 126 ,long lStateMask 127 ); 128 129 // 130 // Sets the item image 131 // 132 bool SetItemImage( long lItem 133 ,int nImage 134 ,int lSelImage 135 ); 136 bool SetItemColumnImage( long lItem 137 ,long lColumn 138 ,int nImage 139 ); 140 141 // 142 // Item text 143 // 144 wxString GetItemText(long lItem) const; 145 void SetItemText( long lItem 146 ,const wxString& rsStr 147 ); 148 149 // 150 // Item data 151 // 152 long GetItemData(long lItem) const; 153 bool SetItemData( long lItem 154 ,long lData 155 ); 156 157 // 158 // Gets the item rectangle 159 // 160 bool GetItemRect( long lItem 161 ,wxRect& rRect 162 ,int nCode = wxLIST_RECT_BOUNDS 163 ) const; 164 165 // 166 // Item position 167 // 168 bool GetItemPosition( long lItem 169 ,wxPoint& rPos 170 ) const; 171 bool SetItemPosition( long lItem 172 ,const wxPoint& rPos 173 ); 174 175 // 176 // Gets the number of items in the list control 177 // 178 int GetItemCount(void) const; 179 180 // 181 // Gets the number of columns in the list control 182 // 183 inline int GetColumnCount(void) const { return m_nColCount; } 184 185 // 186 // Retrieves the spacing between icons in pixels. 187 // If bIsSmall is true, gets the spacing for the small icon 188 // view, otherwise the large icon view. 189 // 190 int GetItemSpacing(bool bIsSmall) const; 191 192 // 193 // Foreground colour of an item. 194 // 195 wxColour GetItemTextColour(long lItem) const; 196 void SetItemTextColour( long lItem 197 ,const wxColour& rCol 198 ); 199 200 // 201 // Background colour of an item. 202 // 203 wxColour GetItemBackgroundColour(long lItem ) const; 204 void SetItemBackgroundColour( long lItem 205 ,const wxColour& rCol 206 ); 207 208 // 209 // Gets the number of selected items in the list control 210 // 211 int GetSelectedItemCount(void) const; 212 213 // 214 // Text colour of the listview 215 // 216 wxColour GetTextColour(void) const; 217 void SetTextColour(const wxColour& rCol); 218 219 // 220 // Gets the index of the topmost visible item when in 221 // list or report view 222 // 223 long GetTopItem(void) const; 224 225 // 226 // Add or remove a single window style 227 void SetSingleStyle( long lStyle 228 ,bool bAdd = true 229 ); 230 231 // 232 // Set the whole window style 233 // 234 void SetWindowStyleFlag(long lStyle); 235 236 // 237 // Searches for an item, starting from 'item'. 238 // item can be -1 to find the first item that matches the 239 // specified flags. 240 // Returns the item or -1 if unsuccessful. 241 long GetNextItem( long lItem 242 ,int nGeometry = wxLIST_NEXT_ALL 243 ,int lState = wxLIST_STATE_DONTCARE 244 ) const; 245 246 // 247 // Gets one of the three image lists 248 // 249 wxImageList* GetImageList(int nWhich) const; 250 251 // 252 // Sets the image list 253 // 254 void SetImageList( wxImageList* pImageList 255 ,int nWhich 256 ); 257 void AssignImageList( wxImageList* pImageList 258 ,int nWhich 259 ); 260 261 // 262 // Returns true if it is a virtual list control 263 // 264 inline bool IsVirtual() const { return (GetWindowStyle() & wxLC_VIRTUAL) != 0; } 265 266 // 267 // Refresh items selectively (only useful for virtual list controls) 268 // 269 void RefreshItem(long lItem); 270 void RefreshItems( long lItemFrom 271 ,long lItemTo 272 ); 273 274 // 275 // Operations 276 //////////////////////////////////////////////////////////////////////////// 277 // 278 279 // 280 // Arranges the items 281 // 282 bool Arrange(int nFlag = wxLIST_ALIGN_DEFAULT); 283 284 // 285 // Deletes an item 286 // 287 bool DeleteItem(long lItem); 288 289 // 290 // Deletes all items 291 bool DeleteAllItems(void); 292 293 // 294 // Deletes a column 295 // 296 bool DeleteColumn(int nCol); 297 298 // 299 // Deletes all columns 300 // 301 bool DeleteAllColumns(void); 302 303 // 304 // Clears items, and columns if there are any. 305 // 306 void ClearAll(void); 307 308 // 309 // Edit the label 310 // 311 wxTextCtrl* EditLabel( long lItem 312 ,wxClassInfo* pTextControlClass = CLASSINFO(wxTextCtrl) 313 ); 314 315 // 316 // End label editing, optionally cancelling the edit 317 // 318 bool EndEditLabel(bool bCancel); 319 320 // 321 // Ensures this item is visible 322 // 323 bool EnsureVisible(long lItem); 324 325 // 326 // Find an item whose label matches this string, starting from the item after 'start' 327 // or the beginning if 'start' is -1. 328 // 329 long FindItem( long lStart 330 ,const wxString& rsStr 331 ,bool bPartial = false 332 ); 333 334 // 335 // Find an item whose data matches this data, starting from the item after 'start' 336 // or the beginning if 'start' is -1. 337 // 338 long FindItem( long lStart 339 ,long lData 340 ); 341 342 // 343 // Find an item nearest this position in the specified direction, starting from 344 // the item after 'start' or the beginning if 'start' is -1. 345 // 346 long FindItem( long lStart 347 ,const wxPoint& rPoint 348 ,int lDirection 349 ); 350 351 // 352 // Determines which item (if any) is at the specified point, 353 // giving details in 'flags' (see wxLIST_HITTEST_... flags above) 354 // 355 long HitTest( const wxPoint& rPoint 356 ,int& rFlags 357 ); 358 359 // 360 // Inserts an item, returning the index of the new item if successful, 361 // -1 otherwise. 362 // 363 long InsertItem(wxListItem& rInfo); 364 365 // 366 // Insert a string item 367 // 368 long InsertItem( long lIndex 369 ,const wxString& rsLabel 370 ); 371 372 // 373 // Insert an image item 374 // 375 long InsertItem( long lIndex 376 ,int nImageIndex 377 ); 378 379 // 380 // Insert an image/string item 381 // 382 long InsertItem( long lIndex 383 ,const wxString& rsLabel 384 ,int nImageIndex 385 ); 386 387 // 388 // For list view mode (only), inserts a column. 389 // 390 long InsertColumn( long lCol 391 ,wxListItem& rInfo 392 ); 393 394 long InsertColumn( long lCol 395 ,const wxString& rsHeading 396 ,int nFormat = wxLIST_FORMAT_LEFT 397 ,int lWidth = -1 398 ); 399 400 // 401 // set the number of items in a virtual list control 402 // 403 void SetItemCount(long lCount); 404 405 // 406 // Scrolls the list control. If in icon, small icon or report view mode, 407 // x specifies the number of pixels to scroll. If in list view mode, x 408 // specifies the number of columns to scroll. 409 // If in icon, small icon or list view mode, y specifies the number of pixels 410 // to scroll. If in report view mode, y specifies the number of lines to scroll. 411 // 412 bool ScrollList( int nDx 413 ,int nDy 414 ); 415 416 // Sort items. 417 418 // 419 // fn is a function which takes 3 long arguments: item1, item2, data. 420 // item1 is the long data associated with a first item (NOT the index). 421 // item2 is the long data associated with a second item (NOT the index). 422 // data is the same value as passed to SortItems. 423 // The return value is a negative number if the first item should precede the second 424 // item, a positive number of the second item should precede the first, 425 // or zero if the two items are equivalent. 426 // 427 // data is arbitrary data to be passed to the sort function. 428 // 429 bool SortItems( wxListCtrlCompare fn 430 ,long lData 431 ); 432 433 // 434 // IMPLEMENTATION 435 // -------------- 436 // 437 virtual bool OS2Command( WXUINT uParam 438 ,WXWORD wId 439 ); 440 // 441 // Bring the control in sync with current m_windowStyle value 442 // 443 void UpdateStyle(void); 444 445 // 446 // Implementation: converts wxWidgets style to MSW style. 447 // Can be a single style flag or a bit list. 448 // oldStyle is 'normalised' so that it doesn't contain 449 // conflicting styles. 450 // 451 long ConvertToOS2Style( long& lOldStyle 452 ,long lStyle 453 ) const; 454 long ConvertArrangeToOS2Style(long lStyle); 455 long ConvertViewToOS2Style(long lStyle); 456 457 virtual MRESULT OS2WindowProc( WXUINT uMsg 458 ,WXWPARAM wParam 459 ,WXLPARAM lParam 460 ); 461 462 // Event handlers 463 //////////////////////////////////////////////////////////////////////////// 464 // Necessary for drawing hrules and vrules, if specified 465 void OnPaint(wxPaintEvent& rEvent); 466 467protected: 468 // 469 // common part of all ctors 470 // 471 void Init(void); 472 473 // 474 // Free memory taken by all internal data 475 // 476 void FreeAllInternalData(void); 477 478 wxTextCtrl* m_pTextCtrl; // The control used for editing a label 479 wxImageList* m_pImageListNormal; // The image list for normal icons 480 wxImageList* m_pImageListSmall; // The image list for small icons 481 wxImageList* m_pImageListState; // The image list state icons (not implemented yet) 482 bool m_bOwnsImageListNormal; 483 bool m_bOwnsImageListSmall; 484 bool m_bOwnsImageListState; 485 long m_lBaseStyle; // Basic PM style flags, for recreation purposes 486 int m_nColCount; // PM doesn't have GetColumnCount so must 487 // keep track of inserted/deleted columns 488 489 // 490 // true if we have any internal data (user data & attributes) 491 // 492 bool m_bAnyInternalData; 493 494 // 495 // true if we have any items with custom attributes 496 // 497 bool m_bHasAnyAttr; 498 499 // 500 // These functions are only used for virtual list view controls, i.e. the 501 // ones with wxLC_VIRTUAL style 502 // 503 // return the text for the given column of the given item 504 // 505 virtual wxString OnGetItemText( long lItem 506 ,long lColumn 507 ) const; 508 509 // 510 // Return the icon for the given item. In report view, OnGetItemImage will 511 // only be called for the first column. See OnGetItemColumnImage for 512 // details. 513 // 514 virtual int OnGetItemImage(long lItem) const; 515 516 // 517 // Return the icon for the given item and column 518 // 519 virtual int OnGetItemColumnImage(long lItem, long lColumn) const; 520 521 // 522 // Return the attribute for the item (may return NULL if none) 523 // 524 virtual wxListItemAttr* OnGetItemAttr(long lItem) const; 525 526private: 527 bool DoCreateControl( int nX 528 ,int nY 529 ,int nWidth 530 ,int nHeight 531 ); 532 533 DECLARE_DYNAMIC_CLASS(wxListCtrl) 534 DECLARE_EVENT_TABLE() 535 DECLARE_NO_COPY_CLASS(wxListCtrl) 536}; // end of CLASS wxListCtrl 537 538#endif // wxUSE_LISTCTRL 539 540#endif // _WX_LISTCTRL_H_ 541 542