00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089
00090
00091
00092
00093
00094
00095
00096
00097
00098
00099
00100
00101
00102
00103
00104
00105
00106
00107
00108
00109
00110
00111
00112
00113
00114
00115
00116
00117
00118
00119
00120
00121
00122
00123
00124
00125
00126
00127
00128
00129
00130
00131
00132
00133
00134
00135
00136 #ifndef INC_MGUI_GRID_H
00137 #define INC_MGUI_GRID_H
00138
00139 #ifndef INC_MGUI_CTRL_H
00140 #include <mgui/ctrl.h>
00141 #endif
00142
00143 namespace MGD {
00144 class CONTEXT;
00145 }
00146
00147
00148 namespace MGUI {
00149
00150 class IMAGELIST;
00151
00152
00153
00154
00155
00156
00157
00158
00159
00160
00161 class CTRL_GRID : public MGUI::CTRL {
00162 public:
00163
00164
00165 enum FORMAT {
00166 FORMAT_Left = 0,
00167 FORMAT_Right = 1,
00168 FORMAT_Center = 2
00169 };
00170
00171 enum STYLE {
00172 STYLE_AlignLeft = 0x0800,
00173 STYLE_AlignTop = 0x0000,
00174 STYLE_AutoArrange = 0x0100,
00175 STYLE_EditLabels = 0x0200,
00176 STYLE_NoColumnHeader = 0x4000,
00177 STYLE_NoLabelWrap = 0x0080,
00178 STYLE_NoScroll = 0x2000,
00179 STYLE_NoSortHeader = 0x8000,
00180 STYLE_OwnerData = 0x1000,
00181 STYLE_ShowSelAlways = 0x0008,
00182 STYLE_NoGridLines = 0x0001,
00183 STYLE_SingleSel = 0x0004,
00184 STYLE_SortAscending = 0x0010,
00185 STYLE_SortDescending = 0x0020
00186 };
00187
00188 enum VIEWMODE {
00189 VIEWMODE_Icon = 0,
00190 VIEWMODE_Report = 1,
00191 VIEWMODE_SmallIcon = 2,
00192 VIEWMODE_List = 3
00193 };
00194
00195 enum IMAGELISTTYPE {
00196 IMAGELISTTYPE_Normal = 0,
00197 IMAGELISTTYPE_Small = 1,
00198 IMAGELISTTYPE_State = 2
00199 };
00200
00201
00202
00203 struct DISPINFO {
00204 DISPINFO () :
00205 m_indent(0),
00206 m_IconIndex(-1),
00207 m_StateImageIndex(-1),
00208 m_OverlayImageIndex(-1),
00209 m_bSelected(false)
00210 {}
00211
00212 ~DISPINFO() {}
00213
00214 MISTRING m_text;
00215 int m_indent;
00216 int m_IconIndex;
00217 int m_StateImageIndex;
00218 int m_OverlayImageIndex;
00219 bool m_bSelected;
00220 };
00221
00222
00223 struct CUSTOMDRAW {
00224 int row;
00225 int col;
00226 LRECT2D rect;
00227 COLOR BackgroundColor;
00228 COLOR TextColor;
00229 bool ChangedBackgroundColor;
00230 bool ChangedTextColor;
00231 #ifdef WIN32_MFC
00232 HDC gc;
00233 #else
00234 MGD::CONTEXT* gc;
00235 #endif
00236 };
00237
00238
00239 CTRL_GRID (
00240 );
00241
00242
00243 virtual ~CTRL_GRID (
00244 );
00245
00246
00247 void Create (
00248 MGUI::LAYOUT_PANE_BASE& ParentPane,
00249 int height = 10,
00250 int width = 40,
00251 VIEWMODE viewmode = VIEWMODE_Report,
00252 STYLE style = STYLE_AlignTop,
00253 MGUI::LAYOUT_SIZEALIGN sizealign = MGUI::LAYOUT_SIZEALIGN_Expand
00254 );
00255
00256
00257 void DeleteAllColumns (
00258 );
00259
00260
00261 void DeleteAllItems (
00262 );
00263
00264
00265 void DeleteColumn (
00266 int col
00267 );
00268
00269
00270 void DeleteItem (
00271 int itemnum
00272 );
00273
00274
00275 void DeleteItemByData (
00276 ID id
00277 );
00278
00279
00280 void DeselectAllItems (
00281 );
00282
00283
00284
00285 bool EditItem (
00286 int itemnum,
00287 int column = 0,
00288 bool selectall = true
00289 );
00290
00291
00292
00293 bool EditItem (
00294 int itemnum,
00295 int column,
00296 const UNICODE *initstr,
00297 bool selectall = true
00298 );
00299
00300
00301 void EnsureVisible (
00302 int itemnum,
00303 bool PartialOK = false
00304 );
00305
00306
00307
00308 int FindItemByData (
00309 const void* value
00310 ) const;
00311
00312
00313
00314 int FindItemByData (
00315 ID data
00316 ) const { return (FindItemByData((void*)data)); }
00317
00318
00319
00320
00321 int GetBottomRow (
00322 ) const { return (GetTopRow() + GetCountPerPage()); }
00323
00324
00325 bool GetCellRect (
00326 int itemnum,
00327 int col,
00328 LRECT2D& rect
00329 ) const;
00330
00331
00332 int GetColumnCount (
00333 ) const;
00334
00335
00336
00337 bool GetColumnLabel (
00338 int column,
00339 MISTRING& label
00340 ) const;
00341
00342
00343
00344
00345 ERRVALUE GetColumnOrderArray (
00346 SIMPLE_ARRAY<INT32>& array
00347 );
00348
00349
00350 int GetColumnWidth (
00351 int column
00352 ) const;
00353
00354
00355 int GetCountPerPage (
00356 ) const;
00357
00358
00359 int GetHeadingHeight (
00360 ) const;
00361
00362
00363 int GetItemCount (
00364 ) const;
00365
00366
00367 MGUI::ID GetItemData (
00368 int itemnum
00369 ) const;
00370
00371
00372
00373 int GetNextSelectedItem (
00374 int startitem = -1
00375 ) const;
00376
00377
00378 int GetSelectedCount (
00379 ) const;
00380
00381 #ifdef WIN32_MFC
00382
00383
00384 BOOL GetSubItemRect (
00385 int item,
00386 int colnum,
00387 CRect& rect
00388 );
00389 #endif
00390
00391
00392 int GetTopRow (
00393 ) const;
00394
00395
00396 int InsertColumn (
00397 int colnum,
00398 const char *string,
00399 FORMAT format = FORMAT_Left,
00400 int width = -1,
00401 bool lookup = true
00402 );
00403
00404
00405 int InsertColumn (
00406 int colnum,
00407 const UNICODE *string,
00408 FORMAT format = FORMAT_Left,
00409 int width = -1
00410 );
00411
00412
00413
00414 int InsertItem (
00415 const char *string,
00416 bool lookup = true
00417 );
00418
00419
00420
00421 int InsertItem (
00422 const UNICODE *string
00423 );
00424
00425
00426
00427 int InsertItem (
00428 int pos,
00429 const char *string,
00430 bool lookup = true
00431 );
00432
00433
00434
00435 int InsertItem (
00436 int pos,
00437 const UNICODE *string
00438 );
00439
00440
00441
00442 bool IsItemSelected (
00443 int itemnum
00444 ) const;
00445
00446
00447 void Redraw (
00448 bool updatenow = true
00449 );
00450
00451
00452 void RedrawItems (
00453 int firstitemnum,
00454 int lastitemnum,
00455 bool updatenow = true
00456 );
00457
00458
00459
00460 bool SetColumnLabel (
00461 int column,
00462 const UNICODE* label
00463 );
00464
00465
00466 void SetColumnOrderArray (
00467 SIMPLE_ARRAY<INT32>& array
00468 );
00469
00470
00471
00472
00473 void SetColumnWidth (
00474 int column,
00475 int width
00476 );
00477
00478 #ifdef WIN32_MFC
00479
00480 void SetExtendedStyle (
00481 UINT32 exstyles,
00482 UINT32 mask = 0
00483 );
00484 #endif
00485
00486
00487 void SetImageList (
00488 IMAGELIST& imagelist,
00489 IMAGELISTTYPE listtype = IMAGELISTTYPE_Small,
00490 bool shared = false
00491 );
00492
00493
00494 int SetItemCount (
00495 int NumItems
00496 );
00497
00498
00499 void SetItemData (
00500 int itemnum,
00501 ID value
00502 );
00503
00504
00505
00506
00507
00508
00509 void SetItemImage (
00510 int itemnum,
00511 int imageindex
00512 );
00513
00514
00515 void SetItemSelected (
00516 int itemnum,
00517 bool selected = true
00518 );
00519
00520
00521 void SetItemText (
00522 int itemnum,
00523 int subitem,
00524 const char *string,
00525 bool lookup = true
00526 );
00527
00528
00529 void SetItemText (
00530 int itemnum,
00531 int subitem,
00532 const UNICODE *string
00533 );
00534
00535
00536 void SortItems (
00537 int column = 0,
00538 bool bAscending = true
00539 );
00540
00541
00542 void Update (
00543 int itemnum
00544 );
00545
00546 protected:
00547
00548 STYLE GetStyle (
00549 ) const { return m_style; }
00550
00551
00552
00553
00554
00555 virtual bool OnBeginLabelEdit (
00556 int itemnum,
00557 int subitemnum
00558 );
00559
00560
00561 virtual void OnClickColumn (
00562 int itemnum,
00563 int column,
00564 KEYSTATE state
00565 );
00566
00567
00568 virtual void OnClickItem (
00569 int itemnum,
00570 int column,
00571 KEYSTATE state
00572 );
00573
00574
00575 virtual void OnDoubleClickItem (
00576 int itemnum,
00577 int column,
00578 KEYSTATE state
00579 );
00580
00581
00582
00583
00584 virtual bool OnDrawItem (
00585 CUSTOMDRAW& drawinfo
00586 );
00587
00588
00589
00590
00591
00592 virtual bool OnEndLabelEdit (
00593 int row,
00594 int col,
00595 const MISTRING& string
00596 );
00597
00598
00599
00600
00601
00602 virtual bool OnGetDispInfo (
00603 int row,
00604 int col,
00605 CTRL_GRID::DISPINFO& dispinfo
00606 );
00607
00608
00609 virtual void OnItemActivate (
00610 );
00611
00612
00613
00614
00615
00616
00617 virtual int OnItemCompare (
00618 UINT32 rowitem1,
00619 UINT32 rowitem2
00620 );
00621
00622
00623
00624
00625
00626 virtual int OnItemCompare (
00627 UINT32 rowitem1,
00628 UINT32 rowitem2,
00629 int colnum,
00630 bool bAscending
00631 );
00632
00633
00634 virtual void OnItemSelect (
00635 int itemnum,
00636 int subitemnum
00637 );
00638
00639
00640 virtual void OnItemUnselect (
00641 int itemnum,
00642 int subitemnum
00643 );
00644
00645
00646 virtual void OnOwnerDataCacheHint (
00647 int from,
00648 int to
00649 );
00650
00651
00652 virtual void OnRightClickItem (
00653 int itemnum,
00654 int column,
00655 KEYSTATE state
00656 );
00657
00658 private:
00659 #ifndef GENERATING_DOXYGEN_OUTPUT
00660
00661 class MyListCtrl;
00662 friend class MyListCtrl;
00663
00664 MyListCtrl *m_pCtrl;
00665 STYLE m_style;
00666 int m_PrevSelRow;
00667 int m_PrevSelCol;
00668
00669
00670 CTRL_GRID (const CTRL_GRID&);
00671 CTRL_GRID& operator= (const CTRL_GRID&);
00672
00673 #ifdef WIN32_MFC
00674 static int CALLBACK CompareCallback (LPARAM rowitem1, LPARAM rowitem2, LPARAM cbdata);
00675 #endif
00676 #endif // GENERATING_DOXYGEN_OUTPUT
00677
00678
00679 };
00680
00681 DEFINE_ENUM_OPERATORS(MGUI::CTRL_GRID::STYLE);
00682
00683
00684
00685
00686 template <class _CT> class CTRL_GRID_T : public MGUI::CTRL_GRID {
00687 public:
00688
00689 CTRL_GRID_T (
00690 ):
00691 m_pContainer(0),
00692 m_OnBeginLabelEditFunc(0),
00693 m_OnClickColumnFunc(0),
00694 m_OnClickItemFunc(0),
00695 m_OnDoubleClickItemFunc(0),
00696 m_OnEndLabelEditFunc(0),
00697 m_OnGetDispInfoFunc(0),
00698 m_OnItemActivateFunc(0),
00699 m_OnItemDrawFunc(0),
00700 m_OnItemCompareFunc(0),
00701 m_OnItemSelectFunc(0),
00702 m_OnItemUnselectFunc(0),
00703 m_OnOwnerDataCacheHintFunc(0),
00704 m_OnRightClickItemFunc(0)
00705 { }
00706
00707
00708 virtual ~CTRL_GRID_T (
00709 ) { }
00710
00711
00712 void Create (
00713 MGUI::LAYOUT_PANE_BASE& ParentPane,
00714 _CT *pContainer,
00715 int height = 10,
00716 int width = 40,
00717 VIEWMODE viewmode = VIEWMODE_Report,
00718 STYLE style = STYLE_AlignTop,
00719 MGUI::LAYOUT_SIZEALIGN sizealign = MGUI::LAYOUT_SIZEALIGN_Expand
00720 ) {
00721 m_pContainer = pContainer;
00722 CTRL_GRID::Create(ParentPane,height,width,viewmode,style,sizealign);
00723 return;
00724 }
00725
00726
00727 void SetBeginLabelEditFunc (
00728 bool (_CT::*BeginLabelEditFunc)(int row, int col)
00729 ) { m_OnBeginLabelEditFunc = BeginLabelEditFunc; };
00730
00731
00732 void SetClickColumnFunc (
00733 void (_CT::*ClickColumnFunc)(int itemnum, int column, KEYSTATE state)
00734 ) { m_OnClickColumnFunc = ClickColumnFunc; };
00735
00736
00737 void SetClickItemFunc (
00738 void (_CT::*ClickItemFunc)(int itemnum, int column, KEYSTATE state)
00739 ) { m_OnClickItemFunc = ClickItemFunc; };
00740
00741
00742 void SetDoubleClickItemFunc (
00743 void (_CT::*DoubleClickItemFunc)(int itemnum, int column, KEYSTATE state)
00744 ) { m_OnDoubleClickItemFunc = DoubleClickItemFunc; };
00745
00746
00747 void SetEndLabelEditFunc (
00748 bool (_CT::*EndLabelEditFunc)(int row, int col, const MISTRING& string)
00749 ) { m_OnEndLabelEditFunc = EndLabelEditFunc; };
00750
00751
00752
00753 void SetGetDispInfoFunc (
00754 bool (_CT::*GetDispInfoFunc)(int row, int col, DISPINFO& info)
00755 ) { m_OnGetDispInfoFunc = GetDispInfoFunc; };
00756
00757
00758 void SetItemActivateFunc (
00759 void (_CT::*ItemActivateFunc)()
00760 ) { m_OnItemActivateFunc = ItemActivateFunc; };
00761
00762
00763
00764
00765 void SetItemCompareFunc (
00766 int (_CT::*ItemCompareFunc)(UINT32 rowitem1, UINT32 rowitem2, int ColNum, bool bAscending)
00767 ) { m_OnItemCompareFunc = ItemCompareFunc; };
00768
00769
00770
00771 void SetItemDrawFunc (
00772 bool (_CT::*ItemDrawFunc)(CUSTOMDRAW&)
00773 ) { m_OnItemDrawFunc = ItemDrawFunc; };
00774
00775
00776 void SetItemSelectFunc (
00777 void (_CT::*ItemSelectFunc)(int itemnum, int subitemnum)
00778 ) { m_OnItemSelectFunc = ItemSelectFunc; };
00779
00780
00781 void SetItemUnselectFunc (
00782 void (_CT::*ItemUnselectFunc)(int itemnum, int subitemnum)
00783 ) { m_OnItemUnselectFunc = ItemUnselectFunc; };
00784
00785
00786 void SetOwnerDataCacheHintFunc (
00787 void (_CT::*OwnerDataCacheHintFunc)(int from, int to)
00788 ) { m_OnOwnerDataCacheHintFunc = OwnerDataCacheHintFunc; };
00789
00790
00791 void SetRightClickItemFunc (
00792 void (_CT::*RightClickItemFunc)(int itemnum, int column, KEYSTATE state)
00793 ) { m_OnRightClickItemFunc = RightClickItemFunc; };
00794
00795 private:
00796 #ifndef GENERATING_DOXYGEN_OUTPUT
00797
00798 virtual bool OnBeginLabelEdit (
00799 int row,
00800 int col
00801 ) {
00802 if (m_OnBeginLabelEditFunc != 0) {
00803 return (m_pContainer->*m_OnBeginLabelEditFunc)(row, col);
00804 }
00805 else {
00806 return ((GetStyle() & STYLE_EditLabels) != 0);
00807 }
00808 }
00809
00810 virtual void OnClickColumn (
00811 int itemnum,
00812 int column,
00813 KEYSTATE state
00814 ) { if (m_OnClickColumnFunc != 0) (m_pContainer->*m_OnClickColumnFunc)(itemnum,column,state); }
00815
00816 virtual void OnClickItem (
00817 int itemnum,
00818 int column,
00819 KEYSTATE state
00820 ) { if (itemnum >= 0 && m_OnClickItemFunc != 0) (m_pContainer->*m_OnClickItemFunc)(itemnum,column,state);
00821 else CTRL_GRID::OnClickItem(itemnum, column, state);
00822 }
00823
00824 virtual void OnDoubleClickItem (
00825 int itemnum,
00826 int column,
00827 KEYSTATE state
00828 ) { if (m_OnDoubleClickItemFunc != 0) (m_pContainer->*m_OnDoubleClickItemFunc)(itemnum,column, state); }
00829
00830 virtual int OnItemCompare (
00831 UINT32 rowitem1,
00832 UINT32 rowitem2,
00833 int colnum,
00834 bool bAscending
00835 ) { if (m_OnItemCompareFunc != 0) return ((m_pContainer->*m_OnItemCompareFunc)(rowitem1, rowitem2, colnum, bAscending)); else return (0); }
00836
00837 virtual bool OnDrawItem (
00838 CUSTOMDRAW& drawinfo
00839 ) { if (m_OnItemDrawFunc != 0) return ((m_pContainer->*m_OnItemDrawFunc)(drawinfo)); else return (false); }
00840
00841 virtual bool OnEndLabelEdit (
00842 int row,
00843 int col,
00844 const MISTRING& string
00845 ) { return ((m_OnEndLabelEditFunc != 0) ? (m_pContainer->*m_OnEndLabelEditFunc)(row, col, string) : true); }
00846
00847 virtual bool OnGetDispInfo (
00848 int row,
00849 int col,
00850 DISPINFO& info
00851 ) { if (m_OnGetDispInfoFunc != 0) return((m_pContainer->*m_OnGetDispInfoFunc)(row, col, info));
00852 return (false);
00853 }
00854
00855 virtual void OnItemActivate (
00856 ) { if (m_OnItemActivateFunc != 0) (m_pContainer->*m_OnItemActivateFunc)(); }
00857
00858 virtual void OnItemSelect (
00859 int itemnum,
00860 int subitemnum
00861 ) { if (m_OnItemSelectFunc != 0) (m_pContainer->*m_OnItemSelectFunc)(itemnum, subitemnum);
00862 else CTRL_GRID::OnItemSelect(itemnum, subitemnum);
00863 }
00864
00865 virtual void OnItemUnselect (
00866 int itemnum,
00867 int subitemnum
00868 ) { if (m_OnItemUnselectFunc != 0) (m_pContainer->*m_OnItemUnselectFunc)(itemnum, subitemnum);
00869 else CTRL_GRID::OnItemUnselect(itemnum, subitemnum);
00870 }
00871
00872 virtual void OnOwnerDataCacheHint (
00873 int from,
00874 int to
00875 ) { if (m_OnOwnerDataCacheHintFunc != 0) (m_pContainer->*m_OnOwnerDataCacheHintFunc)(from,to); };
00876
00877 virtual void OnRightClickItem (
00878 int itemnum,
00879 int column,
00880 KEYSTATE state
00881 ) { if (m_OnRightClickItemFunc != 0) (m_pContainer->*m_OnRightClickItemFunc)(itemnum,column,state); }
00882
00883 _CT *m_pContainer;
00884 bool (_CT::*m_OnBeginLabelEditFunc)(int row, int col);
00885 void (_CT::*m_OnClickColumnFunc)(int row, int column, KEYSTATE state);
00886 void (_CT::*m_OnClickItemFunc)(int row, int column, KEYSTATE state);
00887 void (_CT::*m_OnDoubleClickItemFunc)(int row, int column, KEYSTATE state);
00888 bool (_CT::*m_OnEndLabelEditFunc)(int row, int col, const MISTRING& string);
00889 bool (_CT::*m_OnGetDispInfoFunc)(int row, int col, CTRL_GRID::DISPINFO&info);
00890 void (_CT::*m_OnItemActivateFunc)();
00891 void (_CT::*m_OnItemSelectFunc)(int item, int subitem);
00892 void (_CT::*m_OnItemUnselectFunc)(int item, int subitem);
00893 int (_CT::*m_OnItemCompareFunc)(UINT32 rowitem1, UINT32 rowitem2, int col, bool bAscending);
00894 bool (_CT::*m_OnItemDrawFunc)(CUSTOMDRAW& drawinfo);
00895 void (_CT::*m_OnOwnerDataCacheHintFunc)(int from, int to);
00896 void (_CT::*m_OnRightClickItemFunc)(int itemnum, int column, KEYSTATE state);
00897 #endif // GENERATING_DOXYGEN_OUTPUT
00898 };
00899
00900
00901
00902 }
00903
00904 #endif // INC_MGUI_GRID_H
00905