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
00137
00138
00139
00140
00141
00142
00143
00144
00145
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
00167
00168
00169
00170
00171
00172
00173
00174 class CTRL_GRID : public MGUI::CTRL {
00175 public:
00176
00177
00178 enum FORMAT {
00179 FORMAT_Left = 0,
00180 FORMAT_Right = 1,
00181 FORMAT_Center = 2
00182 };
00183
00184 enum STYLE {
00185 STYLE_AlignLeft = 0x0800,
00186 STYLE_AlignTop = 0x0000,
00187 STYLE_AutoArrange = 0x0100,
00188 STYLE_EditLabels = 0x0200,
00189 STYLE_NoColumnHeader = 0x4000,
00190 STYLE_NoLabelWrap = 0x0080,
00191 STYLE_NoScroll = 0x2000,
00192 STYLE_NoSortHeader = 0x8000,
00193 STYLE_OwnerData = 0x1000,
00194 STYLE_ShowSelAlways = 0x0008,
00195 STYLE_NoGridLines = 0x0001,
00196 STYLE_SingleSel = 0x0004,
00197 STYLE_SortAscending = 0x0010,
00198 STYLE_SortDescending = 0x0020
00199 };
00200
00201 enum VIEWMODE {
00202 VIEWMODE_Icon = 0,
00203 VIEWMODE_Report = 1,
00204 VIEWMODE_SmallIcon = 2,
00205 VIEWMODE_List = 3
00206 };
00207
00208 enum IMAGELISTTYPE {
00209 IMAGELISTTYPE_Normal = 0,
00210 IMAGELISTTYPE_Small = 1,
00211 IMAGELISTTYPE_State = 2
00212 };
00213
00214
00215
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;
00228 int m_indent;
00229 int m_IconIndex;
00230 int m_StateImageIndex;
00231 int m_OverlayImageIndex;
00232 bool m_bSelected;
00233 };
00234
00235
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
00252 CTRL_GRID (
00253 );
00254
00255
00256 virtual ~CTRL_GRID (
00257 );
00258
00259
00260 void Create (
00261 MGUI::LAYOUT_PANE_BASE& ParentPane,
00262 int height = 10,
00263 int width = 40,
00264 VIEWMODE viewmode = VIEWMODE_Report,
00265 STYLE style = STYLE_AlignTop,
00266 MGUI::LAYOUT_SIZEALIGN sizealign = MGUI::LAYOUT_SIZEALIGN_Expand
00267 );
00268
00269
00270 void DeleteAllColumns (
00271 );
00272
00273
00274 void DeleteAllItems (
00275 );
00276
00277
00278 void DeleteColumn (
00279 int col
00280 );
00281
00282
00283 void DeleteItem (
00284 int itemnum
00285 );
00286
00287
00288 void DeleteItemByData (
00289 ID id
00290 );
00291
00292
00293 void DeselectAllItems (
00294 );
00295
00296
00297
00298 bool EditItem (
00299 int itemnum,
00300 int column = 0,
00301 bool selectall = true
00302 );
00303
00304
00305
00306 bool EditItem (
00307 int itemnum,
00308 int column,
00309 const UNICODE *initstr,
00310 bool selectall = true
00311 );
00312
00313
00314 void EnsureVisible (
00315 int itemnum,
00316 bool PartialOK = false
00317 );
00318
00319
00320
00321 int FindItemByData (
00322 const void* value
00323 ) const;
00324
00325
00326
00327 int FindItemByData (
00328 ID data
00329 ) const { return (FindItemByData((void*)data)); }
00330
00331
00332
00333
00334 int GetBottomRow (
00335 ) const { return (GetTopRow() + GetCountPerPage()); }
00336
00337
00338 bool GetCellRect (
00339 int itemnum,
00340 int col,
00341 LRECT2D& rect
00342 ) const;
00343
00344
00345 int GetColumnCount (
00346 ) const;
00347
00348
00349
00350 bool GetColumnLabel (
00351 int column,
00352 MISTRING& label
00353 ) const;
00354
00355
00356
00357
00358 ERRVALUE GetColumnOrderArray (
00359 SIMPLE_ARRAY<INT32>& array
00360 );
00361
00362
00363 int GetColumnWidth (
00364 int column
00365 ) const;
00366
00367
00368 int GetCountPerPage (
00369 ) const;
00370
00371
00372 int GetHeadingHeight (
00373 ) const;
00374
00375
00376 int GetItemCount (
00377 ) const;
00378
00379
00380 MGUI::ID GetItemData (
00381 int itemnum
00382 ) const;
00383
00384
00385
00386 int GetNextSelectedItem (
00387 int startitem = -1
00388 ) const;
00389
00390
00391 int GetSelectedCount (
00392 ) const;
00393
00394 #ifdef WIN32_MFC
00395
00396
00397 BOOL GetSubItemRect (
00398 int item,
00399 int colnum,
00400 CRect& rect
00401 );
00402 #endif
00403
00404
00405 int GetTopRow (
00406 ) const;
00407
00408
00409 int InsertColumn (
00410 int colnum,
00411 const char *string,
00412 FORMAT format = FORMAT_Left,
00413 int width = -1,
00414 bool lookup = true
00415 );
00416
00417
00418 int InsertColumn (
00419 int colnum,
00420 const UNICODE *string,
00421 FORMAT format = FORMAT_Left,
00422 int width = -1
00423 );
00424
00425
00426 int InsertColumn (
00427 int colnum,
00428 const MISTRING& string,
00429 FORMAT format = FORMAT_Left,
00430 int width = -1
00431 ) { return (InsertColumn(colnum,static_cast<const UNICODE*>(string),format,width)); }
00432
00433
00434
00435 int InsertItem (
00436 const char *string,
00437 bool lookup = true
00438 );
00439
00440
00441
00442 int InsertItem (
00443 const UNICODE *string
00444 );
00445
00446
00447
00448 int InsertItem (
00449 const MISTRING& string
00450 ) { return (InsertItem(static_cast<const UNICODE*>(string))); }
00451
00452
00453
00454 int InsertItem (
00455 int pos,
00456 const char *string,
00457 bool lookup = true
00458 );
00459
00460
00461
00462 int InsertItem (
00463 int pos,
00464 const UNICODE *string
00465 );
00466
00467
00468
00469 bool IsItemSelected (
00470 int itemnum
00471 ) const;
00472
00473
00474 void Redraw (
00475 bool updatenow = true
00476 );
00477
00478
00479 void RedrawItems (
00480 int firstitemnum,
00481 int lastitemnum,
00482 bool updatenow = true
00483 );
00484
00485
00486
00487 bool SetColumnLabel (
00488 int column,
00489 const UNICODE* label
00490 );
00491
00492
00493 void SetColumnOrderArray (
00494 SIMPLE_ARRAY<INT32>& array
00495 );
00496
00497
00498
00499
00500 void SetColumnWidth (
00501 int column,
00502 int width
00503 );
00504
00505 #ifdef WIN32_MFC
00506
00507 void SetExtendedStyle (
00508 UINT32 exstyles,
00509 UINT32 mask = 0
00510 );
00511 #endif
00512
00513
00514 void SetImageList (
00515 IMAGELIST& imagelist,
00516 IMAGELISTTYPE listtype = IMAGELISTTYPE_Small,
00517 bool shared = false
00518 );
00519
00520
00521 int SetItemCount (
00522 int NumItems
00523 );
00524
00525
00526 void SetItemData (
00527 int itemnum,
00528 ID value
00529 );
00530
00531
00532
00533
00534
00535
00536 void SetItemImage (
00537 int itemnum,
00538 int imageindex
00539 );
00540
00541
00542 void SetItemSelected (
00543 int itemnum,
00544 bool selected = true
00545 );
00546
00547
00548 void SetItemText (
00549 int itemnum,
00550 int subitem,
00551 const char *string,
00552 bool lookup = true
00553 );
00554
00555
00556 void SetItemText (
00557 int itemnum,
00558 int subitem,
00559 const UNICODE *string
00560 );
00561
00562
00563 void SortItems (
00564 int column = 0,
00565 bool bAscending = true
00566 );
00567
00568
00569 void Update (
00570 int itemnum
00571 );
00572
00573 protected:
00574
00575 STYLE GetStyle (
00576 ) const { return m_style; }
00577
00578
00579
00580
00581
00582 virtual bool OnBeginLabelEdit (
00583 int itemnum,
00584 int subitemnum
00585 );
00586
00587
00588 virtual void OnClickColumn (
00589 int itemnum,
00590 int column,
00591 KEYSTATE state
00592 );
00593
00594
00595 virtual void OnClickItem (
00596 int itemnum,
00597 int column,
00598 KEYSTATE state
00599 );
00600
00601
00602 virtual void OnDoubleClickItem (
00603 int itemnum,
00604 int column,
00605 KEYSTATE state
00606 );
00607
00608
00609
00610
00611 virtual bool OnDrawItem (
00612 CUSTOMDRAW& drawinfo
00613 );
00614
00615
00616
00617
00618
00619 virtual bool OnEndLabelEdit (
00620 int row,
00621 int col,
00622 MISTRING& string
00623 );
00624
00625
00626
00627
00628
00629 virtual bool OnGetDispInfo (
00630 int row,
00631 int col,
00632 CTRL_GRID::DISPINFO& dispinfo
00633 );
00634
00635
00636 virtual void OnItemActivate (
00637 );
00638
00639
00640
00641
00642
00643
00644 virtual int OnItemCompare (
00645 UINT32 rowitem1,
00646 UINT32 rowitem2
00647 );
00648
00649
00650
00651
00652
00653 virtual int OnItemCompare (
00654 UINT32 rowitem1,
00655 UINT32 rowitem2,
00656 int colnum,
00657 bool bAscending
00658 );
00659
00660
00661 virtual void OnItemSelect (
00662 int itemnum,
00663 int subitemnum
00664 );
00665
00666
00667 virtual void OnItemUnselect (
00668 int itemnum,
00669 int subitemnum
00670 );
00671
00672
00673 virtual void OnOwnerDataCacheHint (
00674 int from,
00675 int to
00676 );
00677
00678
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
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
00714 template <class _CT> class CTRL_GRID_T : public MGUI::CTRL_GRID {
00715 public:
00716
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
00736 virtual ~CTRL_GRID_T (
00737 ) { }
00738
00739
00740 void Create (
00741 MGUI::LAYOUT_PANE_BASE& ParentPane,
00742 _CT *pContainer,
00743 int height = 10,
00744 int width = 40,
00745 VIEWMODE viewmode = VIEWMODE_Report,
00746 STYLE style = STYLE_AlignTop,
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
00755 void SetBeginLabelEditFunc (
00756 bool (_CT::*BeginLabelEditFunc)(int row, int col)
00757 ) { m_OnBeginLabelEditFunc = BeginLabelEditFunc; };
00758
00759
00760 void SetClickColumnFunc (
00761 void (_CT::*ClickColumnFunc)(int itemnum, int column, KEYSTATE state)
00762 ) { m_OnClickColumnFunc = ClickColumnFunc; };
00763
00764
00765 void SetClickItemFunc (
00766 void (_CT::*ClickItemFunc)(int itemnum, int column, KEYSTATE state)
00767 ) { m_OnClickItemFunc = ClickItemFunc; };
00768
00769
00770 void SetDoubleClickItemFunc (
00771 void (_CT::*DoubleClickItemFunc)(int itemnum, int column, KEYSTATE state)
00772 ) { m_OnDoubleClickItemFunc = DoubleClickItemFunc; };
00773
00774
00775 void SetEndLabelEditFunc (
00776 bool (_CT::*EndLabelEditFunc)(int row, int col, MISTRING& string)
00777 ) { m_OnEndLabelEditFunc = EndLabelEditFunc; };
00778
00779
00780
00781 void SetGetDispInfoFunc (
00782 bool (_CT::*GetDispInfoFunc)(int row, int col, DISPINFO& info)
00783 ) { m_OnGetDispInfoFunc = GetDispInfoFunc; };
00784
00785
00786 void SetItemActivateFunc (
00787 void (_CT::*ItemActivateFunc)()
00788 ) { m_OnItemActivateFunc = ItemActivateFunc; };
00789
00790
00791
00792
00793 void SetItemCompareFunc (
00794 int (_CT::*ItemCompareFunc)(UINT32 rowitem1, UINT32 rowitem2, int ColNum, bool bAscending)
00795 ) { m_OnItemCompareFunc = ItemCompareFunc; };
00796
00797
00798
00799 void SetItemDrawFunc (
00800 bool (_CT::*ItemDrawFunc)(CUSTOMDRAW&)
00801 ) { m_OnItemDrawFunc = ItemDrawFunc; };
00802
00803
00804 void SetItemSelectFunc (
00805 void (_CT::*ItemSelectFunc)(int itemnum, int subitemnum)
00806 ) { m_OnItemSelectFunc = ItemSelectFunc; };
00807
00808
00809 void SetItemUnselectFunc (
00810 void (_CT::*ItemUnselectFunc)(int itemnum, int subitemnum)
00811 ) { m_OnItemUnselectFunc = ItemUnselectFunc; };
00812
00813
00814 void SetOwnerDataCacheHintFunc (
00815 void (_CT::*OwnerDataCacheHintFunc)(int from, int to)
00816 ) { m_OnOwnerDataCacheHintFunc = OwnerDataCacheHintFunc; };
00817
00818
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 }
00932
00933 #endif // INC_MGUI_GRID_H
00934