home *** CD-ROM | disk | FTP | other *** search
/ Programming Tool Box / SIMS_2.iso / vb_refer / vb_grid / grid.h < prev    next >
Encoding:
C/C++ Source or Header  |  1991-02-23  |  12.1 KB  |  446 lines

  1. //---------------------------------------------------------------------------
  2. // Grid.h
  3. //---------------------------------------------------------------------------
  4. // Copyright (C) 1990-91,  Microsoft Corp.
  5. //                 All Rights Reserved
  6. // Information Contained Herein Is Proprietary and Confidential.
  7. //---------------------------------------------------------------------------
  8.  
  9. //---------------------------------------------------------------------------
  10. // Helpful Macros
  11. //---------------------------------------------------------------------------
  12. #define OFFSETIN( struc, field )  ( (USHORT)&( ((struc *)0)->field ) )
  13.  
  14.  
  15. //---------------------------------------------------------------------------
  16. // Resource ID's
  17. //---------------------------------------------------------------------------
  18. // Toolbox bitmap resource IDs numbers must be consecutive from N to N+5
  19. //---------------------------------------------------------------------------
  20. #define IDBMP_GRID        8000
  21. #define IDBMP_GRIDDOWN        8001
  22. #define IDBMP_GRIDMONO        8003
  23. #define IDBMP_GRIDMONODOWN    8004
  24. #define IDBMP_GRIDEGA        8006
  25. #define IDBMP_GRIDEGADOWN    8007
  26.  
  27. #define IDCUR_HSEP        9000
  28. #define IDCUR_VSEP        9001
  29.  
  30.  
  31. #ifndef RC_INVOKED
  32. //---------------------------------------------------------------------------
  33. // Grid control data and structs
  34. //---------------------------------------------------------------------------
  35. HCURSOR hcurHSep;
  36. HCURSOR hcurVSep;
  37. HCURSOR hcurArrow;
  38.  
  39. _segment segGrid;   // segment where the Grid HCTL is stored
  40. _segment segData;   // segment where the Grid data is stored
  41.  
  42. #define GBP _based(segGrid) *    // Grid based pointer
  43. #define DBP _based(segData) *    // Data based pointer
  44.  
  45. #define GBH GBP GBP        // Grid based handle
  46. #define DBH DBP DBP        // Data based handle
  47.  
  48. typedef VOID DBH BHVOID;    // void handle
  49.  
  50. typedef CHAR DBH BHSTR;     // handle to a string
  51.  
  52. typedef struct tagROWDATA {
  53.     SHORT    Height;     // row height in pixels
  54.     SHORT    Cols;        // allocated columns for THIS row
  55.     SHORT    fDefHeight:1;    // height was set by default
  56.     BHSTR    bhStr[1];    // array of handles to column text data
  57.     } ROWDATA;
  58.  
  59. typedef struct tagROWARRAY {
  60.     ROWDATA    DBH bhRowData[1];// array of handles to each row's data
  61.     } ROWARRAY;
  62.  
  63. typedef struct tagCOLDATA {
  64.     SHORT    Width;        // width in pixels
  65.     SHORT    Alignment;    // left/center/right
  66.     SHORT    fDefWidth:1;    // width was set by default
  67.     } COLDATA;
  68.  
  69. typedef struct tagCOLARRAY {
  70.     COLDATA    ColData[1];    // array of handles to each col's data
  71.     } COLARRAY;
  72.  
  73. typedef struct tagGRID
  74. {
  75.     FSHORT    fl;        // flags (unused)
  76.     FSHORT    SelType:2;
  77.     FSHORT    fFocus:1;
  78.     FSHORT    fSelection:1;
  79.     FSHORT    fMouseCapture:1;
  80.     FSHORT    fScrollVert:1;
  81.     FSHORT    fScrollHorz:1;
  82.     SHORT    Row;
  83.     SHORT    Col;
  84.     SHORT    Rows;
  85.     SHORT    Cols;
  86.     SHORT    FixedRows;
  87.     SHORT    FixedCols;
  88.     SHORT    TopRow;
  89.     SHORT    BottomRow;
  90.     SHORT    TopRowMax;
  91.     SHORT    WholeBottomRow;
  92.     SHORT    LeftCol;
  93.     SHORT    RightCol;
  94.     SHORT    LeftColMax;
  95.     SHORT    WholeRightCol;
  96.     SHORT    OrgY;
  97.     SHORT    OrgX;
  98.     SHORT    SelTopRow;
  99.     SHORT    SelBottomRow;
  100.     SHORT    SelLeftCol;
  101.     SHORT    SelRightCol;
  102.     SHORT    KeySelRow;
  103.     SHORT    KeySelCol;
  104.     HFONT    hFont;
  105.     SHORT    Width;
  106.     SHORT    Height;
  107.     SHORT    DefWidth;
  108.     SHORT    DefHeight;
  109.     ROWARRAY    DBH bhRowArray; // handle to array of row data
  110.     COLARRAY    DBH bhColArray; // handle to array of col data
  111.     _segment    segData;    // segment where the Grid data is stored
  112.     _segment    segClip;    // segment where the Clip data is constructed
  113. }
  114. GRID;
  115.  
  116. typedef GRID GBP PGRID;
  117.  
  118. #define GRIDDEREF( hctl )   ((PGRID)(VOID *)(SHORT)(LONG)VBControlDeRef(hctl))
  119.  
  120.  
  121. //---------------------------------------------------------------------------
  122. // Control Procudure
  123. //---------------------------------------------------------------------------
  124. LONG _export GridCtlProc( HCTL, HWND, USHORT, USHORT, LONG );
  125.  
  126.  
  127. //---------------------------------------------------------------------------
  128. // Property info
  129. //---------------------------------------------------------------------------
  130. #ifdef CTL_DATA
  131. PROPINFO CTL_DATA propinfoGridText =
  132. {
  133.     "Text",
  134.     DT_HSZ | PF_fGetMsg | PF_fSetMsg | PF_fNoShow,
  135.     0, 0
  136. };
  137.  
  138. PROPINFO CTL_DATA propinfoGridRows =
  139. {
  140.     "Rows",
  141.     DT_SHORT | PF_fGetData | PF_fSetMsg | PF_fSaveData,
  142.     OFFSETIN(GRID,Rows), 0
  143. };
  144.  
  145. PROPINFO CTL_DATA propinfoGridCols =
  146. {
  147.     "Cols",
  148.     DT_SHORT | PF_fGetData | PF_fSetMsg | PF_fSaveData,
  149.     OFFSETIN(GRID,Cols), 0
  150. };
  151.  
  152. PROPINFO CTL_DATA propinfoGridFixedRows =
  153. {
  154.     "FixedRows",
  155.     DT_SHORT | PF_fGetData | PF_fSetMsg | PF_fSaveData,
  156.     OFFSETIN(GRID,FixedRows), 0
  157. };
  158.  
  159. PROPINFO CTL_DATA propinfoGridFixedCols =
  160. {
  161.     "FixedCols",
  162.     DT_SHORT | PF_fGetData | PF_fSetMsg | PF_fSaveData,
  163.     OFFSETIN(GRID,FixedCols), 0
  164. };
  165.  
  166. PROPINFO CTL_DATA propinfoGridRow =
  167. {
  168.     "Row",
  169.     DT_SHORT | PF_fGetData | PF_fSetMsg | PF_fNoShow,
  170.     OFFSETIN(GRID,Row), 0
  171. };
  172.  
  173. PROPINFO CTL_DATA propinfoGridCol =
  174. {
  175.     "Col",
  176.     DT_SHORT | PF_fGetData | PF_fSetMsg | PF_fNoShow,
  177.     OFFSETIN(GRID,Col), 0
  178. };
  179.  
  180. CHAR CTL_DATA szScrollbarTypes[] = "0 - None\0"\
  181.                    "1 - Horizontal\0"\
  182.                    "2 - Vertical\0"\
  183.                    "3 - Both\0"\
  184.                    "";
  185. PROPINFO CTL_DATA propinfoGridScrollBars =
  186. {
  187.     "ScrollBars",
  188.     DT_ENUM | PF_fGetMsg | PF_fSetMsg | PF_fSaveData,
  189.     0, 0,
  190.     0,                // 0 - None
  191.     szScrollbarTypes, 3
  192. };
  193.  
  194. PROPINFO CTL_DATA propinfoGridRowHeight =
  195. {
  196.     "RowHeight",
  197.     DT_LONG | PF_fGetMsg | PF_fSetMsg | PF_fNoShow,
  198.     0, 0
  199. };
  200.  
  201. PROPINFO CTL_DATA propinfoGridColWidth =
  202. {
  203.     "ColWidth",
  204.     DT_LONG | PF_fGetMsg | PF_fSetMsg | PF_fNoShow,
  205.     0, 0
  206. };
  207.  
  208. PROPINFO CTL_DATA propinfoGridColAlignment =
  209. {
  210.     "ColAlignment",
  211.     DT_SHORT | PF_fGetMsg | PF_fSetMsg | PF_fNoShow,
  212.     0, 0
  213. };
  214.  
  215. PROPINFO CTL_DATA propinfoGridCellSelected =
  216. {
  217.     "CellSelected",
  218.     DT_BOOL | PF_fGetMsg | PF_fSetMsg | PF_fNoShow | PF_fNoRuntimeW,
  219.     0, 0
  220. };
  221.  
  222. PROPINFO CTL_DATA propinfoGridClip =
  223. {
  224.     "Clip",
  225.     DT_HSZ | PF_fGetMsg | PF_fSetMsg,
  226.     0, 0
  227. };
  228.  
  229. PROPINFO CTL_DATA propinfoGridSelStartRow =
  230. {
  231.     "SelStartRow",
  232.     DT_SHORT | PF_fGetData | PF_fSetMsg | PF_fNoShow,
  233.     OFFSETIN(GRID,SelTopRow), 0
  234. };
  235.  
  236. PROPINFO CTL_DATA propinfoGridSelEndRow =
  237. {
  238.     "SelEndRow",
  239.     DT_SHORT | PF_fGetData | PF_fSetMsg | PF_fNoShow,
  240.     OFFSETIN(GRID,SelBottomRow), 0
  241. };
  242.  
  243. PROPINFO CTL_DATA propinfoGridSelStartCol =
  244. {
  245.     "SelStartCol",
  246.     DT_SHORT | PF_fGetData | PF_fSetMsg | PF_fNoShow,
  247.     OFFSETIN(GRID,SelLeftCol), 0
  248. };
  249.  
  250. PROPINFO CTL_DATA propinfoGridSelEndCol =
  251. {
  252.     "SelEndCol",
  253.     DT_SHORT | PF_fGetData | PF_fSetMsg | PF_fNoShow,
  254.     OFFSETIN(GRID,SelRightCol), 0
  255. };
  256. #endif    // CTL_DATA
  257.  
  258.  
  259. //---------------------------------------------------------------------------
  260. // Property list
  261. //---------------------------------------------------------------------------
  262. // Define the consecutive indicies for the properties
  263. //---------------------------------------------------------------------------
  264. #define IPROP_GRID_CTLNAME    0x0000
  265. #define IPROP_GRID_INDEX    0x0001
  266. #define IPROP_GRID_BACKCOLOR    0x0002
  267. #define IPROP_GRID_FORECOLOR    0x0003
  268. #define IPROP_GRID_LEFT     0x0004
  269. #define IPROP_GRID_TOP        0x0005
  270. #define IPROP_GRID_WIDTH    0x0006
  271. #define IPROP_GRID_HEIGHT    0x0007
  272. #define IPROP_GRID_ENABLED    0x0008
  273. #define IPROP_GRID_VISIBLE    0x0009
  274. #define IPROP_GRID_FONTNAME    0x000A
  275. #define IPROP_GRID_FONTSIZE    0x000B
  276. #define IPROP_GRID_FONTBOLD    0x000C
  277. #define IPROP_GRID_FONTITALIC    0x000D
  278. #define IPROP_GRID_FONTSTRIKE    0x000E
  279. #define IPROP_GRID_FONTUNDER    0x000F
  280. #define IPROP_GRID_TABINDEX    0x0010
  281. #define IPROP_GRID_TABSTOP    0x0011
  282. #define IPROP_GRID_PARENT    0x0012
  283. #define IPROP_GRID_DRAGMODE    0x0013
  284. #define IPROP_GRID_DRAGICON    0x0014
  285. #define IPROP_GRID_TAG        0x0015
  286. #define IPROP_GRID_TEXT     0x0016
  287. #define IPROP_GRID_ROWS     0x0017
  288. #define IPROP_GRID_COLS     0x0018
  289. #define IPROP_GRID_FIXEDROWS    0x0019
  290. #define IPROP_GRID_FIXEDCOLS    0x001A
  291. #define IPROP_GRID_ROW        0x001B
  292. #define IPROP_GRID_COL        0x001C
  293. #define IPROP_GRID_SCROLLBARS    0x001D
  294. #define IPROP_GRID_ROWHEIGHT    0x001E
  295. #define IPROP_GRID_COLWIDTH    0x001F
  296. #define IPROP_GRID_COLALIGN    0x0020
  297. #define IPROP_GRID_CELLSEL    0x0021
  298. #define IPROP_GRID_CLIP     0x0022
  299. #define IPROP_GRID_SELSTARTROW    0x0023
  300. #define IPROP_GRID_SELENDROW    0x0024
  301. #define IPROP_GRID_SELSTARTCOL    0x0025
  302. #define IPROP_GRID_SELENDCOL    0x0026
  303.  
  304. #ifdef CTL_DATA
  305. PPROPINFO CTL_DATA proplistGrid[] =
  306. {
  307.     PPROPINFO_STD_CTLNAME,
  308.     PPROPINFO_STD_INDEX,
  309.     PPROPINFO_STD_BACKCOLOR,
  310.     PPROPINFO_STD_FORECOLOR,
  311.     PPROPINFO_STD_LEFT,
  312.     PPROPINFO_STD_TOP,
  313.     PPROPINFO_STD_WIDTH,
  314.     PPROPINFO_STD_HEIGHT,
  315.     PPROPINFO_STD_ENABLED,
  316.     PPROPINFO_STD_VISIBLE,
  317.     PPROPINFO_STD_FONTNAME,
  318.     PPROPINFO_STD_FONTSIZE,
  319.     PPROPINFO_STD_FONTBOLD,
  320.     PPROPINFO_STD_FONTITALIC,
  321.     PPROPINFO_STD_FONTSTRIKE,
  322.     PPROPINFO_STD_FONTUNDER,
  323.     PPROPINFO_STD_TABINDEX,
  324.     PPROPINFO_STD_TABSTOP,
  325.     PPROPINFO_STD_PARENT,
  326.     PPROPINFO_STD_DRAGMODE,
  327.     PPROPINFO_STD_DRAGICON,
  328.     PPROPINFO_STD_TAG,
  329.     &propinfoGridText,
  330.     &propinfoGridRows,
  331.     &propinfoGridCols,
  332.     &propinfoGridFixedRows,
  333.     &propinfoGridFixedCols,
  334.     &propinfoGridRow,
  335.     &propinfoGridCol,
  336.     &propinfoGridScrollBars,
  337.     &propinfoGridRowHeight,
  338.     &propinfoGridColWidth,
  339.     &propinfoGridColAlignment,
  340.     &propinfoGridCellSelected,
  341.     &propinfoGridClip,
  342.     &propinfoGridSelStartRow,
  343.     &propinfoGridSelEndRow,
  344.     &propinfoGridSelStartCol,
  345.     &propinfoGridSelEndCol,
  346.     NULL
  347. };
  348. #endif    // CTL_DATA
  349.  
  350.  
  351. //---------------------------------------------------------------------------
  352. // Event procedure parameter prototypes
  353. //---------------------------------------------------------------------------
  354. #ifdef CTL_DATA
  355. EVENTINFO CTL_DATA eventinfoClick =
  356. {
  357.     "Click",
  358.     0,
  359.     0,
  360.     NULL,
  361.     NULL
  362. };
  363.  
  364. EVENTINFO CTL_DATA eventinfoDblClick =
  365. {
  366.     "DblClick",
  367.     0,
  368.     0,
  369.     NULL,
  370.     NULL
  371. };
  372.  
  373. EVENTINFO CTL_DATA eventinfoSelChange =
  374. {
  375.     "SelChange",
  376.     0,
  377.     0,
  378.     NULL,
  379.     NULL
  380. };
  381. #endif    // CTL_DATA
  382.  
  383.  
  384. //---------------------------------------------------------------------------
  385. // Event list
  386. //---------------------------------------------------------------------------
  387. // Define the consecutive indicies for the events
  388. //---------------------------------------------------------------------------
  389. #define EVENT_GRID_CLICK    0
  390. #define EVENT_GRID_DBLCLICK    1
  391. #define EVENT_GRID_DRAGDROP    2
  392. #define EVENT_GRID_DRAGOVER    3
  393. #define EVENT_GRID_GOTFOCUS    4
  394. #define EVENT_GRID_KEYDOWN    5
  395. #define EVENT_GRID_KEYPRESS    6
  396. #define EVENT_GRID_KEYUP    7
  397. #define EVENT_GRID_LOSTFOCUS    8
  398. #define EVENT_GRID_SELCHANGE    9
  399.  
  400. #ifdef CTL_DATA
  401. PEVENTINFO CTL_DATA eventlistGrid[] =
  402. {
  403.     &eventinfoClick,
  404.     &eventinfoDblClick,
  405.     PEVENTINFO_STD_DRAGDROP,
  406.     PEVENTINFO_STD_DRAGOVER,
  407.     PEVENTINFO_STD_GOTFOCUS,
  408.     PEVENTINFO_STD_KEYDOWN,
  409.     PEVENTINFO_STD_KEYPRESS,
  410.     PEVENTINFO_STD_KEYUP,
  411.     PEVENTINFO_STD_LOSTFOCUS,
  412.     &eventinfoSelChange,
  413.     NULL
  414. };
  415. #endif    // CTL_DATA
  416.  
  417.  
  418. //---------------------------------------------------------------------------
  419. // Model struct
  420. //---------------------------------------------------------------------------
  421. // Define the control model (using the event and property structures).
  422. //---------------------------------------------------------------------------
  423. #ifdef CTL_DATA
  424. MODEL CTL_DATA modelGrid =
  425. {
  426.     VB_VERSION,             // VB version being used
  427.     MODEL_fFocusOk | MODEL_fWantArrows, // MODEL flags
  428.     (PCTLPROC)GridCtlProc,        // Control procedure
  429.     CS_VREDRAW | CS_HREDRAW        // Class style
  430.            | CS_DBLCLKS,
  431.     WS_CHILD | WS_VSCROLL | WS_HSCROLL    // Default Window style
  432.          | WS_BORDER,
  433.     sizeof(GRID),            // cbCtlExtra for GRID structure
  434.     IDBMP_GRID,             // Palette bitmap ID
  435.     "Grid",                // Default control name
  436.     "Grid",                // Visual Basic class name
  437.     NULL,                // Parent class name
  438.     proplistGrid,            // Properties list
  439.     eventlistGrid            // Events list
  440. };
  441. #endif    // CTL_DATA
  442.  
  443. #endif    // RC_INVOKED
  444.  
  445. //---------------------------------------------------------------------------
  446.