grid.h

Go to the documentation of this file.
00001 /**
00002  * \file mgui/grid.h
00003  * \brief MGUI::CTRL_GRID class definitions
00004  *
00005  * \if NODOC
00006  * $Id: grid.h_v 1.48 2004/11/08 15:41:39 mju Exp $
00007  *
00008  * $Log: grid.h_v $
00009  * Revision 1.48  2004/11/08 15:41:39  mju
00010  * Change lpoint2d to struct so matches previous defns.
00011  *
00012  * Revision 1.47  2004/11/04 20:31:49  dwilliss
00013  * added lpoint2D to OnRightClickItem
00014  *
00015  * Revision 1.46  2004/05/28 21:44:28  mju
00016  * Add methods using mistring.
00017  *
00018  * Revision 1.45  2004/05/25 15:09:50  mju
00019  * OnEndLabelEdit now uses non-const string.
00020  *
00021  * Revision 1.44  2003/10/27 21:22:32  mju
00022  * Remove SetItemFocus as done automatically by SetItemSelected.
00023  *
00024  * Revision 1.43  2003/10/03 19:58:19  linux32build!build
00025  * Doxygen
00026  *
00027  * Revision 1.42  2003/09/15 13:49:32  fileserver!dwilliss
00028  * Doxygen
00029  *
00030  * Revision 1.41  2003/09/11 16:59:18  mju
00031  * Specify namespace for ID in case ambiguous
00032  *
00033  * Revision 1.40  2003/09/10 21:30:48  mju
00034  * Use MGUI::ID for "item data".
00035  *
00036  * Revision 1.39  2003/07/24 20:13:09  dwilliss
00037  * Added a STYLE type
00038  *
00039  * Revision 1.38  2003/04/09 20:50:59  dwilliss
00040  * Don't use _T in tmplates. Mac's ctype.h defines a global _T
00041  *
00042  * Revision 1.37  2003/01/27 18:54:28  mju
00043  * Add GetHeadingHeight.
00044  *
00045  * Revision 1.36  2003/01/24 21:05:28  mju
00046  * Add InsertItem methods taking position.
00047  *
00048  * Revision 1.35  2003/01/24 20:41:10  mju
00049  * Add EditItem methods.
00050  *
00051  * Revision 1.34  2003/01/23 20:18:07  mju
00052  * Make all methods referencing wrapped control non-inline.
00053  *
00054  * Revision 1.33  2003/01/15 18:29:51  mju
00055  * Remove #ifdefed-out methods.
00056  *
00057  * Revision 1.32  2003/01/06 18:15:30  dwilliss
00058  * Typo in template
00059  *
00060  * Revision 1.31  2003/01/06 17:47:59  dwilliss
00061  * Added members to keep track of previously selected item so that we can
00062  * implement multiselect
00063  *
00064  * Revision 1.30  2003/01/06 15:45:14  dwilliss
00065  * Revert back to Mike's fix.  I didn't realize he had "fixed" it for me in
00066  * a way counter to the way I would have done it.
00067  *
00068  * Revision 1.28  2003/01/06 14:08:24  mju
00069  * Fix template to use correct signature for onitemselect/unselect.
00070  *
00071  * Revision 1.27  2003/01/03 23:09:11  dwilliss
00072  * almost right...
00073  *
00074  * Revision 1.26  2003/01/03 23:04:11  dwilliss
00075  * OnItemSelect/Unselect need to return bool on the actual control used in X
00076  *
00077  * Revision 1.25  2002/12/11 15:20:35  mju
00078  * Move contrib stuff here.
00079  *
00080  * Revision 1.24  2002/10/24 21:51:46  dwilliss
00081  * Had broken something in MFC-only code
00082  *
00083  * Revision 1.23  2002/10/24 20:52:19  dwilliss
00084  * Fixed sorting issues
00085  *
00086  * Revision 1.22  2002/10/11 14:50:15  dwilliss
00087  * Moved KEYSTATE enum out of this control and into ctrl.h
00088  *
00089  * Revision 1.21  2002/10/10 19:49:40  dwilliss
00090  * Took out a method that shouldn't be there
00091  *
00092  * Revision 1.20  2002/10/10 17:57:14  dwilliss
00093  * Made the KEYSTATE enum ORable.  The MIGRID that the X version is implemented
00094  * on now passes keyboard state through the OnLClicked methods
00095  *
00096  * Revision 1.19  2002/10/10 17:15:10  dwilliss
00097  * Added a KEYSTATE enum and parameter to all the OnClickXxx methods
00098  *
00099  * Revision 1.18  2002/10/09 16:35:29  mju
00100  * Rename as 'grid.h'.
00101  *
00102  * Revision 1.17  2002/10/09 16:07:48  mju
00103  * Moved to 'mgui' folder.
00104  *
00105  * Revision 1.16  2002/10/09 14:18:43  dwilliss
00106  * Change CUSTOMDRAW to call the HDC "gc" so it's the same name in X and MFC
00107  *
00108  * Revision 1.14  2002/06/07 15:58:26  dwilliss
00109  * OnGetDispInfo now returns bool
00110  *
00111  * Revision 1.13  2002/05/17 15:28:07  dwilliss
00112  * OnClickColumn defined inconsistantly between base and derived class - FIXED
00113  * Constructor had stupid compile error that only the Mac caught.
00114  *
00115  * Revision 1.12  2002/04/05 21:40:28  dwilliss
00116  * SetExtendedStyle() shouldn't be private
00117  *
00118  * Revision 1.11  2002/03/15 22:32:20  dwilliss
00119  * If not BeginLabelEditFunc() set in template, default should depend on
00120  * STYLE_EditLabels flag, not just always true
00121  *
00122  * Revision 1.10  2002/02/19 20:21:31  dwilliss
00123  * OnEditStart actually cancels the edit for X now
00124  *
00125  * Revision 1.6  2002/02/14 17:15:25  dwilliss
00126  * Added methods to delete columns
00127  *
00128  * Revision 1.5  2002/02/12 17:03:46  dwilliss
00129  * X implementation almost done
00130  *
00131  * Revision 1.3  2002/02/08 23:16:16  dwilliss
00132  * OnDrawItem now takes a struct with parameters instead of a bunch of parms
00133  *
00134  * Revision 1.2  2002/02/08 22:16:51  dwilliss
00135  * Compiles for both X and MFC now.  Renamed to CTRL_GRID (was CTRL_LIST)
00136  *
00137  * Revision 1.1  2002/02/04 18:48:22  dwilliss
00138  * Initial revision
00139  *
00140  * 
00141  * 2     12/13/01 10:55a Mju
00142  * MGUI unificiation with X.
00143  * 
00144  * 1     12/03/01 9:41a Mju
00145  * \endif
00146 **/
00147 
00148 #ifndef  INC_MGUI_GRID_H
00149 #define  INC_MGUI_GRID_H
00150 
00151 #ifndef  INC_MGUI_CTRL_H
00152 #include <mgui/ctrl.h>
00153 #endif
00154 
00155 namespace MGD {
00156    class CONTEXT;
00157    }
00158 
00159 struct LPOINT2D;
00160 
00161 namespace MGUI {
00162 
00163 class IMAGELIST;
00164 
00165 //------------------------------------------------------------------------------------------------
00166 //! Grid user interface class.
00167 //! There is also a MGUI::CTRL_GRID_T template which helps eliminate the need for subclassing.  See
00168 //! the description for MGUI::CTRL for more information on using templates.
00169 //! There are two general ways to work with lists, "standard" and "owner-data" (virtual).  In the
00170 //! standard configuration the list control itself contains all of the data (strings, icons, states)
00171 //! for each list entry.  In the "owner-data" configuration, the data is stored outside the list
00172 //! and the OnGetDispInfo and OnOwnerDataCacheHint methods are overridden (or set when using the
00173 //! template) and will be called by the list control when data is needed to be displayed in the list.
00174 class CTRL_GRID : public MGUI::CTRL {
00175    public:
00176 
00177       // Note: enum constants are the same values as the MFC #defines but hard-coded since they're not defined in the X case (alternative was ugly repetition)
00178       enum FORMAT {
00179          FORMAT_Left =           0, //!< LVCFMT_LEFT,
00180          FORMAT_Right =          1, //!< LVCFMT_RIGHT
00181          FORMAT_Center =         2  //!< LVCFMT_CENTER,
00182          };
00183 
00184       enum STYLE {
00185          STYLE_AlignLeft =       0x0800,  //!<LVS_ALIGNLEFT,
00186          STYLE_AlignTop =        0x0000,  //!<LVS_ALIGNTOP,
00187          STYLE_AutoArrange =     0x0100,  //!<LVS_AUTOARRANGE,
00188          STYLE_EditLabels =      0x0200,  //!<LVS_EDITLABELS,
00189          STYLE_NoColumnHeader =  0x4000,  //!<LVS_NOCOLUMNHEADER,
00190          STYLE_NoLabelWrap =     0x0080,  //!<LVS_NOLABELWRAP,
00191          STYLE_NoScroll =        0x2000,  //!<LVS_NOSCROLL,
00192          STYLE_NoSortHeader =    0x8000,  //!<LVS_NOSORTHEADER,
00193          STYLE_OwnerData =       0x1000,  //!<LVS_OWNERDATA,
00194          STYLE_ShowSelAlways =   0x0008,  //!<LVS_SHOWSELALWAYS,
00195          STYLE_NoGridLines =     0x0001,  //!<
00196          STYLE_SingleSel =       0x0004,  //!<LVS_SINGLESEL,
00197          STYLE_SortAscending =   0x0010,  //!<LVS_SORTASCENDING,
00198          STYLE_SortDescending =  0x0020   //!<LVS_SORTDESCENDING
00199          };
00200 
00201       enum VIEWMODE {
00202          VIEWMODE_Icon =         0,    //!<LVS_ICON,           NOTE: Not implemented in X case
00203          VIEWMODE_Report =       1,    //!<LVS_REPORT,         
00204          VIEWMODE_SmallIcon =    2,    //!<LVS_SMALLICON    NOTE: Not implemented in X case
00205          VIEWMODE_List =         3     //!<LVS_LIST,           
00206          };
00207 
00208       enum IMAGELISTTYPE {
00209          IMAGELISTTYPE_Normal =  0,    //!< LVSIL_NORMAL
00210          IMAGELISTTYPE_Small  =  1,    //!< LVSIL_SMALL
00211          IMAGELISTTYPE_State  =  2     //!< LVSIL_STATE
00212          };
00213 
00214       //! Structure passed to OnGetDispInfo
00215       //! Note: for the present, only the m_text member is supported by X
00216       struct DISPINFO {
00217          DISPINFO () :
00218             m_indent(0),
00219             m_IconIndex(-1),
00220             m_StateImageIndex(-1),
00221             m_OverlayImageIndex(-1),
00222             m_bSelected(false) 
00223             {}
00224             
00225          ~DISPINFO() {}
00226 
00227          MISTRING m_text;  //!< String to display
00228          int m_indent;     //!< Number of icon widths to indent (default == 0)
00229          int m_IconIndex;  //!< 0-based Index into IMAGELIST set by SetImageList(), -1 == none
00230          int m_StateImageIndex;  //!< Displayed next to the item's icon -1 = none.  
00231          int m_OverlayImageIndex;   //!< Drawn on top of item's icon. -1 = none.
00232          bool m_bSelected; 
00233          };
00234       
00235       //! Structure passed to OnDrawItem()
00236       struct CUSTOMDRAW {
00237          int row;
00238          int col;
00239          LRECT2D rect;
00240          COLOR BackgroundColor;
00241          COLOR TextColor;
00242          bool ChangedBackgroundColor;
00243          bool ChangedTextColor;
00244       #ifdef WIN32_MFC
00245          HDC gc;
00246       #else
00247          MGD::CONTEXT* gc;
00248       #endif
00249          };
00250             
00251       //! Constructor.
00252       CTRL_GRID (
00253          );
00254 
00255       //! Destructor.
00256       virtual ~CTRL_GRID (
00257          );
00258 
00259       //! Create the control.
00260       void Create (
00261          MGUI::LAYOUT_PANE_BASE& ParentPane,    //!< Parent pane
00262          int height = 10,                       //!< Height in rows,
00263          int width = 40,                        //!< Width in 'em' characters
00264          VIEWMODE viewmode = VIEWMODE_Report,   //!< Initial viewing mode
00265          STYLE style = STYLE_AlignTop,          //!< List style
00266          MGUI::LAYOUT_SIZEALIGN sizealign = MGUI::LAYOUT_SIZEALIGN_Expand
00267          );
00268 
00269       //! Delete all columns.
00270       void DeleteAllColumns (
00271          );
00272 
00273       //! Delete all items.
00274       void DeleteAllItems (
00275          );
00276 
00277       //! Delete specified column.
00278       void DeleteColumn (
00279          int col
00280          );
00281 
00282       //! Delete specified item.
00283       void DeleteItem (
00284          int itemnum
00285          );
00286 
00287       //! Delete specified item given assigned data value.
00288       void DeleteItemByData (
00289          ID id
00290          );
00291 
00292       //! Deselect all items.
00293       void DeselectAllItems (
00294          );
00295 
00296       //! Begin editing specified item, starting with currently displayed value.
00297       //! @return true if successful, false if not.
00298       bool EditItem (
00299          int itemnum,
00300          int column = 0,
00301          bool selectall = true                  //!< Select all existing text so typing will replace
00302          );
00303 
00304       //! Begin editing specified item, starting with specified string.
00305       //! @return true if successful, false if not.
00306       bool EditItem (
00307          int itemnum,
00308          int column,
00309          const UNICODE *initstr,                //!< String to replace with prior to editing
00310          bool selectall = true                  //!< Select all existing text so typing will replace
00311          );
00312 
00313       //! Ensures that an item is visible.
00314       void EnsureVisible (
00315          int itemnum,
00316          bool PartialOK = false
00317          );
00318 
00319       //! Find item by matching specified data value as pointer.
00320       //! @return Item number or -1 if none found.
00321       int FindItemByData (
00322          const void* value
00323          ) const;
00324 
00325       //! Find item by matching specified data value as ID.
00326       //! @return Item number or -1 if none found.
00327       int FindItemByData (
00328          ID data
00329          ) const { return (FindItemByData((void*)data)); }
00330 
00331       //! Get the index (row number) of the bottom-most visible item.
00332       //! Note: Return value may be greater than number of rows of data
00333       //! if more rows are visible than there are data for.
00334       int GetBottomRow (
00335          ) const { return (GetTopRow() + GetCountPerPage()); }
00336 
00337       //! Get the bounding rectangle of a single cell.
00338       bool GetCellRect (
00339          int itemnum,
00340          int col,
00341          LRECT2D& rect
00342          ) const;
00343 
00344       //! Get number of columns in the list.
00345       int GetColumnCount (
00346          ) const;
00347 
00348       //! Get the label for a column.
00349       //! @return true if successful, false otherwise
00350       bool GetColumnLabel (
00351          int column,
00352          MISTRING& label
00353          ) const;
00354 
00355       //! Get the order of columns in the list.  
00356       //! Columns can be reordered by dragging them around if you call
00357       //! SetExtendedStyle() with LVS_EX_HEADERDRAGDROP
00358       ERRVALUE GetColumnOrderArray (
00359          SIMPLE_ARRAY<INT32>& array
00360          );
00361 
00362       //! Get the width of a column in pixels.
00363       int GetColumnWidth (
00364          int column
00365          ) const;
00366 
00367       //! Get number of items that can fit vertically in the visible area of control (in report mode only).
00368       int GetCountPerPage (
00369          ) const;
00370 
00371       //! Get height of heading in pixels.
00372       int GetHeadingHeight (
00373          ) const;
00374 
00375       //! Get number of items in list.
00376       int GetItemCount (
00377          ) const;
00378 
00379       //! Get data value associated with item.
00380       MGUI::ID GetItemData (
00381          int itemnum
00382          ) const;
00383 
00384       //! Get next selected item in list.
00385       //! @return Index of next item or -1 if no more items.
00386       int GetNextSelectedItem (
00387          int startitem = -1                     //!< Starting item for search, starting item is excluded
00388          ) const;
00389 
00390       //! Get number of selected items.
00391       int GetSelectedCount (
00392          ) const;
00393 
00394    #ifdef WIN32_MFC
00395       //! Return the rectangle (in client coordinates) of a given row/column in the list
00396       //! Only exists in MFC version because it returns an MFC CRect
00397       BOOL GetSubItemRect (
00398          int item,
00399          int colnum,
00400          CRect& rect
00401          );
00402    #endif
00403 
00404       //! Get the index (row number) of the top-most visible item
00405       int GetTopRow (
00406          ) const;
00407 
00408       //! Insert new column with label from resource or ASCII string.
00409       int InsertColumn (
00410          int colnum,                            //!< Column number and subitem
00411          const char *string,                    //!< String for resource lookup or to set
00412          FORMAT format = FORMAT_Left,           //!< Column format
00413          int width = -1,                        //!< Width of column in PIXELS
00414          bool lookup = true                     //!< 'true' to perform resource lookup, false to use string as-is
00415          );
00416 
00417       //! Insert new column with label from UNICODE* string.
00418       int InsertColumn (
00419          int colnum,                            //!< Column number and subitem
00420          const UNICODE *string,                 //!< String for column heading
00421          FORMAT format = FORMAT_Left,           //!< Column format
00422          int width = -1                         //!< Width of column in PIXELS
00423          );
00424 
00425       //! Insert new column with label from MISTRING;
00426       int InsertColumn (
00427          int colnum,                            //!< Column number and subitem
00428          const MISTRING& string,                //!< String for column heading
00429          FORMAT format = FORMAT_Left,           //!< Column format
00430          int width = -1                         //!< Width of column in PIXELS
00431          ) { return (InsertColumn(colnum,static_cast<const UNICODE*>(string),format,width)); }
00432 
00433       //! Insert new item from resource or ASCII string.
00434       //! @return Item number of inserted item if successful, < 0 if error.
00435       int InsertItem (
00436          const char *string,                    //!< String for resource lookup or to set
00437          bool lookup = true                     //!< 'true' to perform resource lookup, false to use string as-is
00438          );
00439 
00440       //! Insert new item with Unicode string.
00441       //! @return Item number of inserted item if successful, < 0 if error.
00442       int InsertItem (
00443          const UNICODE *string                  //!< Item string
00444          );
00445 
00446       //! Insert new item with Unicode string.
00447       //! @return Item number of inserted item if successful, < 0 if error.
00448       int InsertItem (
00449          const MISTRING& string                 //!< Item string
00450          ) { return (InsertItem(static_cast<const UNICODE*>(string))); }
00451 
00452       //! Insert new item at specified position from resource or ASCII string.
00453       //! @return Item number of inserted item if successful, < 0 if error.
00454       int InsertItem (
00455          int pos,                               //!< Item position in list
00456          const char *string,                    //!< String for resource lookup or to set
00457          bool lookup = true                     //!< 'true' to perform resource lookup, false to use string as-is
00458          );
00459 
00460       //! Insert new item at specified position with Unicode string.
00461       //! @return Item number of inserted item if successful, < 0 if error.
00462       int InsertItem (
00463          int pos,                               //!< Item position in list
00464          const UNICODE *string                  //!< Item string
00465          );
00466 
00467       //! Determine if specified item is currently "selected".
00468       //! @return 'true' if selected, 'false' if not.
00469       bool IsItemSelected (
00470          int itemnum
00471          ) const;
00472 
00473       //! Force the control to repaint all items.
00474       void Redraw (
00475          bool updatenow = true
00476          );
00477 
00478       //! Force the control to repaint a range of items.
00479       void RedrawItems (
00480          int firstitemnum,
00481          int lastitemnum,
00482          bool updatenow = true
00483          );
00484 
00485       //! Set column label.
00486       //! @return true if successful, false otherwise
00487       bool SetColumnLabel (
00488          int column,
00489          const UNICODE* label
00490          );
00491 
00492       //! Set the order of columns within the list.
00493       void SetColumnOrderArray (
00494          SIMPLE_ARRAY<INT32>& array
00495          );
00496 
00497       //! Set the width of a column.  The width can be in pixels or one of the
00498       //! constants LVSCW_AUTOSIZE or LVSCW_AUTOSIZE_USE_HEADER as described in
00499       //! LVM_SETCOLUMNWIDTH in the Platform SDK documentation.
00500       void SetColumnWidth (
00501          int column,
00502          int width
00503          );
00504 
00505    #ifdef WIN32_MFC
00506       //! Set extended styles.    (MFC version only)
00507       void SetExtendedStyle (
00508          UINT32 exstyles,                       //!< LVS_EX_...
00509          UINT32 mask = 0                        //!< Mask for styles to change, 0 to set all specified
00510          );
00511    #endif
00512 
00513       //! Set image list.
00514       void SetImageList (
00515          IMAGELIST& imagelist,                  //!< Image list
00516          IMAGELISTTYPE listtype = IMAGELISTTYPE_Small,            //!< Type of image list, IMAGELISTTYPE_Normal, IMAGELISTTYPE_Small or IMAGELISTTYPE_State
00517          bool shared = false                    //!< 'true' if image list is shared, 'false' if control should take ownership
00518          );
00519 
00520       //! Set number of items in list.
00521       int SetItemCount (
00522          int NumItems
00523          );
00524 
00525       //! Set application-specific data to associate with list item.
00526       void SetItemData (
00527          int itemnum,                           //!< Item number
00528          ID value                         //!< Value to associate with item
00529          );
00530 
00531       //! Set the image index to use for a givem item.
00532       //! This only handles column 0, and currently only for MFC
00533       //! Pass -1 for imageindex to have no icon
00534       //! imageindex is a 0-based index into the IMAGELIST set via
00535       //! SetImageList()
00536       void SetItemImage (
00537          int itemnum,
00538          int imageindex
00539          );
00540 
00541       //! Set whether item is 'selected or not.
00542       void SetItemSelected (
00543          int itemnum,                           //!< Item number
00544          bool selected = true
00545          );
00546 
00547       //! Set item or subitem text from resource or ASCII string.
00548       void SetItemText (
00549          int itemnum,                           //!< Item number
00550          int subitem,                           //!< Sub item, 0 for item
00551          const char *string,                    //!< String for resource lookup or to set
00552          bool lookup = true                     //!< 'true' to perform resource lookup, false to use string as-is
00553          );
00554 
00555       //! Set item or subitem text from Unicode string.
00556       void SetItemText (
00557          int itemnum,                           //!< Item number
00558          int subitem,                           //!< Sub item, 0 for item
00559          const UNICODE *string                  //!< Item or subitem string
00560          );
00561 
00562       //! Sort the data in the list on a given column.
00563       void SortItems (
00564          int column = 0,         //!< Column to sort on
00565          bool bAscending = true
00566          );
00567 
00568       //! Force the control to repaint a specified item
00569       void Update (
00570          int itemnum
00571          );
00572 
00573    protected:
00574 
00575       STYLE GetStyle (
00576          ) const { return m_style; }
00577 
00578       //! Called when user clicks on label to begin editing.
00579       //! @return 'false' if editing is NOT allowed or 'true' if editing is allowed.
00580       //! Default implementation always returns 'true' if the grid was
00581       //! created with STYLE_EditLabels or 'false' if not.
00582       virtual bool OnBeginLabelEdit (
00583          int itemnum,
00584          int subitemnum
00585          );
00586 
00587       //! Called when user clicks on column heading.
00588       virtual void OnClickColumn (
00589          int itemnum,
00590          int column,
00591          KEYSTATE state
00592          );
00593 
00594       //! Called when user left-clicks on a list item.
00595       virtual void OnClickItem (
00596          int itemnum,                                             
00597          int column,
00598          KEYSTATE state
00599          );
00600 
00601       //! Called when user double-left-clicks on a list item.
00602       virtual void OnDoubleClickItem (
00603          int itemnum,
00604          int column,
00605          KEYSTATE state
00606          );
00607       
00608       //! Called before an item is drawn.
00609       //! Override if you want to do the drawing yourself. 
00610       //! Should return true if you did all the drawing.  Return false to let the base class draw the item.
00611       virtual bool OnDrawItem (
00612          CUSTOMDRAW& drawinfo
00613          );
00614 
00615       //! Called when user clicks on label to begin editing.
00616       //! @return 'true' if to accept changes or 'false' to reject changes.
00617       //! Default implementation always returns 'true' if the grid was
00618       //! created with STYLE_EditLabels or 'false' if not.
00619       virtual bool OnEndLabelEdit (
00620          int row,
00621          int col,
00622          MISTRING& string
00623          );
00624 
00625       //! Called by list to request information stored by owner rather than list.
00626       //!
00627       //! Derived implementation should return true if it actually filled in
00628       //! anything.  Return false to behave as if OnGetDispInfo wasn't overridden.
00629       virtual bool OnGetDispInfo (
00630          int row,
00631          int col,
00632          CTRL_GRID::DISPINFO& dispinfo 
00633          );
00634 
00635       //! Called when an item is "activated" (normally via a double click).
00636       virtual void OnItemActivate (
00637          );
00638 
00639       //! Called by SortItems() to compare items.
00640       //! Should return < 0 if rowitem1 should precede rowitem2 and > 0 if rowitem1 should follow rowitem2
00641       //! and 0 if the two items are equivalent.
00642       //! XXX DEPRECATED. Don't override this, override the one that takes
00643       //! a column number and direction
00644       virtual int OnItemCompare (
00645          UINT32 rowitem1,
00646          UINT32 rowitem2
00647          );
00648 
00649       //! Called by SortItems() to compare items.
00650       //! Should return < 0 if rowitem1 should precede rowitem2 and > 0 if rowitem1 should follow rowitem2
00651       //! and 0 if the two items are equivalent.
00652       //! if bAscending is false, you should reverse the order.
00653       virtual int OnItemCompare (
00654          UINT32 rowitem1,
00655          UINT32 rowitem2,
00656          int colnum,
00657          bool bAscending
00658          );
00659 
00660       //! Called when an item is "selected".
00661       virtual void OnItemSelect (
00662          int itemnum,
00663          int subitemnum
00664          );
00665 
00666       //! Called when an item is "unselected".
00667       virtual void OnItemUnselect (
00668          int itemnum,
00669          int subitemnum
00670          );
00671 
00672       //! Called for owner-data list to provide hints about what to cache.
00673       virtual void OnOwnerDataCacheHint (
00674          int from,
00675          int to
00676          );
00677 
00678       //! Called when user right-clicks on a list item.
00679       virtual void OnRightClickItem (
00680          int itemnum,
00681          int column,
00682          const LPOINT2D&,
00683          KEYSTATE state
00684          );
00685 
00686    private:
00687       #ifndef GENERATING_DOXYGEN_OUTPUT
00688 
00689       class MyListCtrl;
00690       friend class MyListCtrl;
00691 
00692       MyListCtrl *m_pCtrl;
00693       STYLE m_style;
00694       int m_PrevSelRow;
00695       int m_PrevSelCol;
00696 
00697       // UNIMPLEMENTED / UNSUPPORTED
00698       CTRL_GRID (const CTRL_GRID&);
00699       CTRL_GRID& operator= (const CTRL_GRID&);
00700 
00701    #ifdef WIN32_MFC
00702       static int CALLBACK CompareCallback (LPARAM rowitem1, LPARAM rowitem2, LPARAM cbdata);
00703    #endif
00704       #endif // GENERATING_DOXYGEN_OUTPUT
00705 
00706 
00707    };
00708 
00709 DEFINE_ENUM_OPERATORS(MGUI::CTRL_GRID::STYLE);
00710 
00711 
00712 //------------------------------------------------------------------------------------------------
00713 //! List control template.
00714 template <class _CT> class CTRL_GRID_T : public MGUI::CTRL_GRID {
00715    public:
00716       //! Constructor.
00717       CTRL_GRID_T (
00718          ):
00719          m_pContainer(0),
00720          m_OnBeginLabelEditFunc(0),
00721          m_OnClickColumnFunc(0),
00722          m_OnClickItemFunc(0),
00723          m_OnDoubleClickItemFunc(0),
00724          m_OnEndLabelEditFunc(0),
00725          m_OnGetDispInfoFunc(0),
00726          m_OnItemActivateFunc(0),
00727          m_OnItemDrawFunc(0),
00728          m_OnItemCompareFunc(0),
00729          m_OnItemSelectFunc(0),
00730          m_OnItemUnselectFunc(0),
00731          m_OnOwnerDataCacheHintFunc(0),
00732          m_OnRightClickItemFunc(0)
00733          { }
00734 
00735       //! Destructor.
00736       virtual ~CTRL_GRID_T (
00737          ) { }
00738 
00739       //! Create list box control with no label.
00740       void Create (
00741          MGUI::LAYOUT_PANE_BASE& ParentPane,    //!< Parent pane
00742          _CT *pContainer,                       //!< Pointer to callback container class
00743          int height = 10,                       //!< Height in rows,
00744          int width = 40,                        //!< Width in 'em' characters
00745          VIEWMODE viewmode = VIEWMODE_Report,   //!< Initial viewing mode
00746          STYLE style = STYLE_AlignTop,          //!< List style
00747          MGUI::LAYOUT_SIZEALIGN sizealign = MGUI::LAYOUT_SIZEALIGN_Expand
00748          ) {
00749          m_pContainer = pContainer;
00750          CTRL_GRID::Create(ParentPane,height,width,viewmode,style,sizealign);
00751          return;
00752          }
00753 
00754       //! Set method to call when user clicks on label to begin editing.
00755       void SetBeginLabelEditFunc (
00756          bool (_CT::*BeginLabelEditFunc)(int row, int col)
00757          ) { m_OnBeginLabelEditFunc = BeginLabelEditFunc; };
00758 
00759       //! Set method to call when user clicks on a column heading.
00760       void SetClickColumnFunc (
00761          void (_CT::*ClickColumnFunc)(int itemnum, int column, KEYSTATE state)
00762          ) { m_OnClickColumnFunc = ClickColumnFunc; };
00763 
00764       //! Set method to call when user left-clicks on an item.
00765       void SetClickItemFunc (
00766          void (_CT::*ClickItemFunc)(int itemnum, int column, KEYSTATE state)
00767          ) { m_OnClickItemFunc = ClickItemFunc; };
00768 
00769       //! Set method to call when user double-left-clicks on an item.
00770       void SetDoubleClickItemFunc (
00771          void (_CT::*DoubleClickItemFunc)(int itemnum, int column, KEYSTATE state)
00772          ) { m_OnDoubleClickItemFunc = DoubleClickItemFunc; };
00773 
00774       //! Set method to call when user clicks on label to end editing.
00775       void SetEndLabelEditFunc (
00776          bool (_CT::*EndLabelEditFunc)(int row, int col, MISTRING& string)
00777          ) { m_OnEndLabelEditFunc = EndLabelEditFunc; };
00778 
00779       //! Set method to call when user activates or deactivates item.
00780             //! XXX NMLVDISPINFO& is meaningless in X case
00781       void SetGetDispInfoFunc (
00782          bool (_CT::*GetDispInfoFunc)(int row, int col, DISPINFO& info)
00783          ) { m_OnGetDispInfoFunc = GetDispInfoFunc; };
00784 
00785       //! Set method to call when user activates or deactivates item.
00786       void SetItemActivateFunc (
00787          void (_CT::*ItemActivateFunc)()
00788          ) { m_OnItemActivateFunc = ItemActivateFunc; };
00789 
00790       //! Set method to call for compare two items for sorting
00791       //! Should return < 0 if rowitem1 should precede rowitem2 and > 0 if rowitem1 should follow rowitem2
00792       //! and 0 if the two items are equivalent.
00793       void SetItemCompareFunc (
00794          int (_CT::*ItemCompareFunc)(UINT32 rowitem1, UINT32 rowitem2, int ColNum, bool bAscending)
00795          ) { m_OnItemCompareFunc = ItemCompareFunc; };
00796 
00797       //! Set method to call for custom item drawing.
00798             //! XXX NMLVCUSTOMDRAW& is meaningless in X case
00799       void SetItemDrawFunc (
00800          bool (_CT::*ItemDrawFunc)(CUSTOMDRAW&)
00801          ) { m_OnItemDrawFunc = ItemDrawFunc; };
00802 
00803       //! Set method to call when item is selected
00804       void SetItemSelectFunc (
00805          void (_CT::*ItemSelectFunc)(int itemnum, int subitemnum)
00806          ) { m_OnItemSelectFunc = ItemSelectFunc; };
00807 
00808       //! Set method to call when item is unselected
00809       void SetItemUnselectFunc (
00810          void (_CT::*ItemUnselectFunc)(int itemnum, int subitemnum)
00811          ) { m_OnItemUnselectFunc = ItemUnselectFunc; };
00812 
00813       //! Set method to call when user activates or deactivates item.
00814       void SetOwnerDataCacheHintFunc (
00815          void (_CT::*OwnerDataCacheHintFunc)(int from, int to)
00816          ) { m_OnOwnerDataCacheHintFunc = OwnerDataCacheHintFunc; };
00817 
00818       //! Set method to call when user right-clicks on an item.
00819       void SetRightClickItemFunc (
00820          void (_CT::*RightClickItemFunc)(int itemnum, int column, const LPOINT2D&, KEYSTATE state)
00821          ) { m_OnRightClickItemFunc = RightClickItemFunc; };
00822 
00823    private:
00824       #ifndef GENERATING_DOXYGEN_OUTPUT
00825 
00826       virtual bool OnBeginLabelEdit (
00827          int row,
00828          int col
00829          ) { 
00830          if (m_OnBeginLabelEditFunc != 0) {
00831             return (m_pContainer->*m_OnBeginLabelEditFunc)(row, col);
00832             }
00833          else {
00834             return ((GetStyle() & STYLE_EditLabels) != 0);
00835             }
00836          }
00837 
00838       virtual void OnClickColumn (
00839          int itemnum,
00840          int column,
00841          KEYSTATE state
00842          ) { if (m_OnClickColumnFunc != 0) (m_pContainer->*m_OnClickColumnFunc)(itemnum,column,state); }
00843 
00844       virtual void OnClickItem (
00845          int itemnum,
00846          int column,
00847          KEYSTATE state
00848          ) { if (itemnum >= 0 && m_OnClickItemFunc != 0) (m_pContainer->*m_OnClickItemFunc)(itemnum,column,state); 
00849             else CTRL_GRID::OnClickItem(itemnum, column, state); 
00850          }
00851 
00852       virtual void OnDoubleClickItem (
00853          int itemnum,
00854          int column,
00855          KEYSTATE state
00856          ) { if (m_OnDoubleClickItemFunc != 0) (m_pContainer->*m_OnDoubleClickItemFunc)(itemnum,column, state); }
00857 
00858       virtual int OnItemCompare (
00859          UINT32 rowitem1,
00860          UINT32 rowitem2,
00861          int colnum,
00862          bool bAscending
00863          ) { if (m_OnItemCompareFunc != 0) return ((m_pContainer->*m_OnItemCompareFunc)(rowitem1, rowitem2, colnum, bAscending)); else return (0); }
00864 
00865       virtual bool OnDrawItem (
00866          CUSTOMDRAW& drawinfo
00867          ) { if (m_OnItemDrawFunc != 0) return ((m_pContainer->*m_OnItemDrawFunc)(drawinfo)); else return (false); }
00868 
00869       virtual bool OnEndLabelEdit (
00870          int row,
00871          int col,
00872          MISTRING& string
00873          ) { return ((m_OnEndLabelEditFunc != 0) ? (m_pContainer->*m_OnEndLabelEditFunc)(row, col, string) : true); }
00874 
00875       virtual bool OnGetDispInfo (
00876          int row,
00877          int col,
00878          DISPINFO& info
00879          ) { if (m_OnGetDispInfoFunc != 0) return((m_pContainer->*m_OnGetDispInfoFunc)(row, col, info)); 
00880          return (false);
00881          }
00882 
00883       virtual void OnItemActivate (
00884          ) { if (m_OnItemActivateFunc != 0) (m_pContainer->*m_OnItemActivateFunc)(); }
00885 
00886       virtual void OnItemSelect (
00887          int itemnum,
00888          int subitemnum
00889          ) { if (m_OnItemSelectFunc != 0) (m_pContainer->*m_OnItemSelectFunc)(itemnum, subitemnum);
00890             else CTRL_GRID::OnItemSelect(itemnum, subitemnum);
00891          }
00892 
00893       virtual void OnItemUnselect (
00894          int itemnum,
00895          int subitemnum
00896          ) { if (m_OnItemUnselectFunc != 0) (m_pContainer->*m_OnItemUnselectFunc)(itemnum, subitemnum);
00897             else CTRL_GRID::OnItemUnselect(itemnum, subitemnum);
00898          }
00899 
00900       virtual void OnOwnerDataCacheHint (
00901          int from,
00902          int to
00903          ) { if (m_OnOwnerDataCacheHintFunc != 0) (m_pContainer->*m_OnOwnerDataCacheHintFunc)(from,to); };
00904 
00905       virtual void OnRightClickItem (
00906          int itemnum,
00907          int column,
00908          const LPOINT2D& pt,
00909          KEYSTATE state
00910          ) { if (m_OnRightClickItemFunc != 0) (m_pContainer->*m_OnRightClickItemFunc)(itemnum,column,pt,state); }
00911 
00912       _CT *m_pContainer;
00913       bool (_CT::*m_OnBeginLabelEditFunc)(int row, int col);
00914       void (_CT::*m_OnClickColumnFunc)(int row, int column, KEYSTATE state);
00915       void (_CT::*m_OnClickItemFunc)(int row, int column, KEYSTATE state);
00916       void (_CT::*m_OnDoubleClickItemFunc)(int row, int column, KEYSTATE state);
00917       bool (_CT::*m_OnEndLabelEditFunc)(int row, int col, MISTRING& string);
00918       bool (_CT::*m_OnGetDispInfoFunc)(int row, int col, CTRL_GRID::DISPINFO&info);
00919       void (_CT::*m_OnItemActivateFunc)();
00920       void (_CT::*m_OnItemSelectFunc)(int item, int subitem);
00921       void (_CT::*m_OnItemUnselectFunc)(int item, int subitem);
00922       int (_CT::*m_OnItemCompareFunc)(UINT32 rowitem1, UINT32 rowitem2, int col, bool bAscending);
00923       bool (_CT::*m_OnItemDrawFunc)(CUSTOMDRAW& drawinfo);
00924       void (_CT::*m_OnOwnerDataCacheHintFunc)(int from, int to);
00925       void (_CT::*m_OnRightClickItemFunc)(int itemnum, int column, const LPOINT2D&, KEYSTATE state);
00926       #endif // GENERATING_DOXYGEN_OUTPUT
00927    };
00928 
00929 //------------------------------------------------------------------------------------------------
00930 
00931 }  // End of MGUI namespace
00932 
00933 #endif   // INC_MGUI_GRID_H
00934 

Generated on Tue Dec 14 13:18:17 2004 for TNTsdk by  doxygen 1.3.8-20040913