home *** CD-ROM | disk | FTP | other *** search
/ C/C++ User's Journal & Wi…eveloper's Journal Tools / C-C__Users_Journal_and_Windows_Developers_Journal_Tools_1997.iso / stingray / gridsvw8.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1996-10-27  |  23.2 KB  |  803 lines

  1. // gridsvw8.cpp : implementation of the CGridSample8View class
  2. //
  3.  
  4. // This is a part of the Objective Grid C++ Library.
  5. // Copyright (C) 1995,1996 ClassWorks, Stefan Hoenig.
  6. // All rights reserved.
  7. //
  8. // This source code is only intended as a supplement to
  9. // the Objective Grid Classes Reference and related
  10. // electronic documentation provided with the library.
  11. // See these sources for detailed information regarding
  12. // the Objective Grid product.
  13. //
  14.  
  15. #include "stdafx.h"
  16. #include "gridapp.h"
  17.  
  18. #include "gridsdoc.h"
  19. #include "gridsvw8.h"
  20. #include "dlguser.h"
  21. #include "mainfrm.h"
  22. #include "gridfrms.h"
  23.  
  24. // ScrollTips
  25. #include "gxscrltp.h"
  26.  
  27. #ifdef _DEBUG
  28. #undef THIS_FILE
  29. static char BASED_CODE THIS_FILE[] = __FILE__;
  30. #endif
  31.  
  32. //
  33. // CGridSample8View can be used as standalone, splitter or worksheet gridview
  34. // as you have already seen with CGridSampleView
  35. //
  36. // CGridSample8View illustrates how to apply pushbuttons for headers
  37. // and registering this header control (the skeletton for the control
  38. // is simply copied from the CSimpleButton class in CGridSample5View).
  39. //
  40. // CGridSample8View also illustrates how to select cells with the
  41. //
  42.  
  43. IMPLEMENT_DYNCREATE(CGridSample8View, CMyGridView)
  44.  
  45. static TCHAR BASED_CODE szInstruct[] =
  46.         _T("This view shows you some of the new control types in Version 1.2. ");
  47.  
  48. #define new DEBUG_NEW
  49.  
  50. const UINT NIDTIMER = 101;
  51.  
  52. /////////////////////////////////////////////////////////////////////////////
  53. // CGridSample8CheckBox 
  54.  
  55. // see the bitmap IDS_CHECK_SAMPLE8 how to draw your own
  56. // checkboxes. You should supply 5 bitmaps. All bitmaps
  57. // should have the same size (e.g. m_nCheckBoxSize = 16)
  58.  
  59. // the checkboxes are arranged as follows in the bitmap:
  60. // 0) unchecked
  61. // 1) checked
  62. // 2) unchecked with scope (grey backgorund)
  63. // 3) checked with scope (grey backgorund)
  64. // 4) indetermined
  65.  
  66. CGridSample8CheckBox::CGridSample8CheckBox(CGXGridCore* pGrid)
  67.     : CGXCheckBox(pGrid, TRUE, IDB_CHECK_SAMPLE8, IDB_CHECK_SAMPLE8)
  68. {
  69.     // size of a checkbox
  70.     m_nCheckBoxSize = 16;
  71. }
  72.  
  73. // override GetColorValue to ajust colors in the bitmap
  74. // with system colors
  75.  
  76. COLORREF CGridSample8CheckBox::GetColorValue(COLORREF rgb, BOOL bPrint)
  77. {
  78.     switch (rgb)
  79.     {
  80.     // Replace the white color in the bitmap with 
  81.     // the background color of the window
  82.     case RGB(255, 255, 255):
  83.         return bPrint ? RGB(255, 255, 255) : GetSysColor(COLOR_WINDOW);
  84.  
  85.     default:
  86.         return rgb;
  87.     }
  88. }
  89.  
  90.  
  91. /////////////////////////////////////////////////////////////////////////////
  92. // CGridSample8View
  93.  
  94. BEGIN_MESSAGE_MAP(CGridSample8View, CMyGridView)
  95.     //{{AFX_MSG_MAP(CGridSample8View)
  96.     ON_COMMAND(ID_VIEW_USERACTIONS, OnViewUseractions)
  97.     ON_COMMAND(ID_VIEW_SPLITTERVIEW, OnViewSplitterview)
  98.     ON_WM_TIMER()
  99.     ON_WM_VSCROLL()
  100.     ON_WM_HSCROLL()
  101.     //}}AFX_MSG_MAP
  102. END_MESSAGE_MAP()
  103.  
  104. /////////////////////////////////////////////////////////////////////////////
  105. // CGridSample8View construction/destruction
  106.  
  107. CGridSample8View::CGridSample8View()
  108. {
  109.     nValue1 = 50;
  110.     nValue2 = 50;
  111.     nValue2 = 50;
  112.     m_bTimerRunning = FALSE;
  113.  
  114.     m_nProgBarRow = 22;
  115.     m_nProgBarCol = 3;
  116.  
  117.     // ScrollTips
  118. #if _MFC_VER >= 0x0400
  119.     if (GXGetAppData()->bWin31)
  120.         m_pScrollTip = NULL; // not supported under Win32s
  121.     else
  122.         m_pScrollTip = new CGXScrollTip;
  123. #endif
  124. }
  125.  
  126. CGridSample8View::~CGridSample8View()
  127. {
  128. #if _MFC_VER >= 0x0400
  129.     delete m_pScrollTip;
  130. #endif
  131. }
  132.  
  133. BOOL CGridSample8View::ConnectParam()
  134. {
  135.     // Note: this method is copied from CGridSampleView
  136.     //
  137.  
  138.     BOOL bNew = FALSE;
  139.  
  140.     // Retrive the zero-based worksheet-id if used as worksheet
  141.     if (GetParentTabWnd(this, TRUE))
  142.         m_nViewID = GetParentTabViewID(this);
  143.  
  144.     // check if it is a new pane in a splitter window
  145.     CSplitterWnd* pSplitterWnd = GetParentDynamicSplitter(this, TRUE);
  146.     if (pSplitterWnd != NULL)
  147.     {
  148.         CGXGridView *pView = (CGXGridView *) pSplitterWnd->GetPane(0, 0);
  149.         if (pView != this)
  150.             m_nViewID = pView->GetViewID();
  151.     }
  152.  
  153.     // check if parameter-object exist (in document)
  154.     if (GetDocument()->GetParam(m_nViewID) == NULL)
  155.     {
  156.         // create a parameter-object on the heap
  157.         GetDocument()->SetParam(m_nViewID, new CGXGridParam);
  158.  
  159.         bNew = TRUE;    // this view needs initializing
  160.     }
  161.  
  162.     // connect parameter-object with grid
  163.     SetParam((CGXGridParam*) GetDocument()->GetParam(m_nViewID), FALSE);
  164.  
  165.     return bNew;
  166. }
  167.  
  168. void CGridSample8View::SetupControls()
  169. {
  170.     // Register all controls for the view
  171.  
  172.     // owner drawn checkbox
  173.     RegisterControl(GX_IDS_CTRL_CHECKBOX, new CGridSample8CheckBox(this));
  174.  
  175.     // progress bar
  176.     CGXProgressCtrl* pProgressCtrl = new CGXProgressCtrl(this);
  177.     RegisterControl(GX_IDS_CTRL_PROGRESS, pProgressCtrl);
  178.  
  179.     // password control
  180.     CGXPasswordControl* pPwdControl = new CGXPasswordControl(this, GX_IDS_CTRL_PASSWORD);
  181.     pPwdControl->m_chPasswordChar = _T('*'); // use * as password char
  182.     RegisterControl(GX_IDS_CTRL_PASSWORD, pPwdControl);
  183.  
  184.     // user attributes
  185.     CGXProgressCtrl::AddUserAttributes(GetParam()->GetStylesMap());
  186. }
  187.  
  188. /////////////////////////////////////////////////////////////////////////////
  189. // CGridSample8View drawing
  190.  
  191. void CGridSample8View::OnInitialUpdate()
  192. {
  193.     BOOL bNew = ConnectParam();
  194.  
  195.     CMyGridView::OnInitialUpdate(); // Creates all objects and links them to the grid
  196.  
  197.     // Register all controls for the view
  198.     SetupControls();
  199.  
  200.     if (bNew)
  201.     {
  202.         // Don't create undo-information for the following commands
  203.         GetParam()->EnableUndo(FALSE);
  204.         // (at the end of this procedure, I will reenable it)
  205.  
  206.         SetRowCount(50);
  207.         SetColCount(20);
  208.  
  209.         // Instructions
  210.         SetCoveredCellsRowCol(1, 1, 3, 4);
  211.         SetStyleRange(CGXRange(1,1),
  212.             CGXStyle()
  213.                 .SetWrapText(TRUE)
  214.                 .SetEnabled(FALSE)
  215.                 .SetFont(CGXFont().SetFaceName(_T("Times New Roman")))
  216.                 .SetInterior(RGB(255,251,240))   // Off-white
  217.                 .SetHorizontalAlignment(DT_CENTER)
  218.                 .SetVerticalAlignment(DT_VCENTER)
  219.                 .SetControl(GX_IDS_CTRL_STATIC)
  220.                 .SetBorders(gxBorderAll, CGXPen().SetWidth(2))
  221.                 .SetUserAttribute(GX_IDS_UA_TOOLTIPTEXT, _T("Title"))  
  222.                 .SetValue(szInstruct));
  223.  
  224.         ROWCOL nRow = 5, nCol = 2;
  225.  
  226.         StandardStyle()
  227.             .SetUserAttribute(GX_IDS_UA_INPUTPROMPT, _T("_"))
  228.             .SetVerticalAlignment(DT_VCENTER)
  229.             ;
  230.  
  231.         // if you want that the mask is shown only for filled
  232.         // controls, you should comment out the following three lines:
  233.         CGXMaskControl* pMaskControl =
  234.             (CGXMaskControl*) GetRegisteredControl(GX_IDS_CTRL_MASKEDIT);
  235.         pMaskControl->m_bDisplayEmpty = TRUE;
  236.  
  237. //       Thick border
  238.         SetStyleRange(CGXRange().SetRows(nRow), 
  239.             CGXStyle()
  240.                 .SetBorders(gxBorderTop, CGXPen().SetWidth(2))
  241.             );
  242.  
  243. //       New Masked Edit Title
  244.         SetCoveredCellsRowCol(nRow, nCol, nRow, nCol+1);
  245.         SetStyleRange(CGXRange(nRow, nCol), 
  246.             CGXStyle()
  247.                 .SetValue("New Masked Edit Control")
  248.                 .SetFont(CGXFont().SetBold(TRUE).SetSize(14))
  249.             );
  250.  
  251.         nRow++;
  252.         nRow++;
  253.  
  254. //       Time: ##:## UU , Example: 12:20 AM
  255.         SetValueRange(CGXRange(nRow, nCol), "Time");
  256.         SetStyleRange(CGXRange(nRow, nCol+1, nRow, nCol+2),
  257.             CGXStyle()
  258.             .SetControl(GX_IDS_CTRL_MASKEDIT)
  259.             .SetUserAttribute(GX_IDS_UA_INPUTMASK, _T("##:## UU"))
  260.             .SetUserAttribute(GX_IDS_UA_TOOLTIPTEXT, _T("Press Insert to toggle Insert Mode")) 
  261.             );
  262.         SetValueRange(CGXRange(nRow, nCol+1), _T("1220AM"));
  263.         nRow++;
  264.  
  265. //       Date: ##/##/## , Example: 12/23/95
  266.         SetValueRange(CGXRange(nRow, nCol), "Date");
  267.         SetStyleRange(CGXRange(nRow, nCol+1, nRow, nCol+2),
  268.             CGXStyle()
  269.             .SetControl(GX_IDS_CTRL_MASKEDIT)
  270.             .SetUserAttribute(GX_IDS_UA_INPUTMASK, _T("##/##/##"))
  271.             .SetUserAttribute(GX_IDS_UA_TOOLTIPTEXT, _T("Press Insert to toggle Insert Mode")) 
  272.             );
  273.         SetValueRange(CGXRange(nRow, nCol+1), _T("122395"));
  274.         nRow++;
  275.  
  276. //       SSN: ###-##-####, Example: 148-92-1531
  277.         SetValueRange(CGXRange(nRow, nCol), "SSN");
  278.         SetStyleRange(CGXRange(nRow, nCol+1, nRow, nCol+2),
  279.             CGXStyle()
  280.             .SetControl(GX_IDS_CTRL_MASKEDIT)
  281.             .SetUserAttribute(GX_IDS_UA_INPUTMASK, _T("###-##-####"))
  282.             .SetUserAttribute(GX_IDS_UA_TOOLTIPTEXT, _T("Press Insert to toggle Insert Mode")) 
  283.             );
  284.         SetValueRange(CGXRange(nRow, nCol+1), _T("148921531"));
  285.         nRow++;
  286.  
  287. //       Phone: (###) ###-#### Ext: ####  Example: (800) 924-4223 Ext: 0007
  288.         SetValueRange(CGXRange(nRow, nCol), "Phone");
  289.         SetStyleRange(CGXRange(nRow, nCol+1, nRow, nCol+2),
  290.             CGXStyle()
  291.             .SetControl(GX_IDS_CTRL_MASKEDIT)
  292.             .SetUserAttribute(GX_IDS_UA_INPUTMASK, _T("(###) ###-#### Ext: ####"))
  293.             .SetUserAttribute(GX_IDS_UA_TOOLTIPTEXT, _T("Press Insert to toggle Insert Mode")) 
  294.             );
  295.         SetValueRange(CGXRange(nRow, nCol+1), _T("80092442230007"));
  296.         nRow++;
  297.  
  298. //       Zip: #####, Example: 27858
  299.         SetValueRange(CGXRange(nRow, nCol), "Zip");
  300.         SetStyleRange(CGXRange(nRow, nCol+1, nRow, nCol+2),
  301.             CGXStyle()
  302.             .SetControl(GX_IDS_CTRL_MASKEDIT)
  303.             .SetUserAttribute(GX_IDS_UA_INPUTMASK, _T("#####"))
  304.             .SetUserAttribute(GX_IDS_UA_TOOLTIPTEXT, _T("Press Insert to toggle Insert Mode")) 
  305.             );
  306.         SetValueRange(CGXRange(nRow, nCol+1), _T("27858"));
  307.         nRow++;
  308.  
  309. //       Zip+4: #####-####, Example: 27858-1234
  310.         SetValueRange(CGXRange(nRow, nCol), "Zip+4");
  311.         SetStyleRange(CGXRange(nRow, nCol+1, nRow, nCol+2),
  312.             CGXStyle()
  313.             .SetControl(GX_IDS_CTRL_MASKEDIT)
  314.             .SetUserAttribute(GX_IDS_UA_INPUTMASK, _T("#####-####"))
  315.             .SetUserAttribute(GX_IDS_UA_TOOLTIPTEXT, _T("Press Insert to toggle Insert Mode")) 
  316.             );
  317.         SetValueRange(CGXRange(nRow, nCol+1), _T("278581234"));
  318.         nRow++;
  319.  
  320. //       Name:  &&&&&&&&&&&&&&&&&&&&&&&, Example: Stingray Software
  321.         SetValueRange(CGXRange(nRow, nCol), "Name");
  322.         SetStyleRange(CGXRange(nRow, nCol+1, nRow, nCol+2),
  323.             CGXStyle()
  324.             .SetControl(GX_IDS_CTRL_MASKEDIT)
  325.             .SetUserAttribute(GX_IDS_UA_INPUTMASK, _T("&&&&&&&&&&&&&&&&&&&&&&&"))
  326.             .SetUserAttribute(GX_IDS_UA_TOOLTIPTEXT, _T("Press Insert to toggle Insert Mode")) 
  327.             );
  328.         SetValueRange(CGXRange(nRow, nCol+1), _T("Stingray Software"));
  329.         nRow++;
  330.  
  331. //       Thick border
  332.         SetStyleRange(CGXRange().SetRows(nRow), 
  333.             CGXStyle()
  334.                 .SetBorders(gxBorderTop, CGXPen().SetWidth(2))
  335.             );
  336.  
  337. //       Password Control Title
  338.         SetCoveredCellsRowCol(nRow, nCol, nRow, nCol+1);
  339.         SetStyleRange(CGXRange(nRow, nCol), 
  340.             CGXStyle()
  341.                 .SetValue("Password Control")
  342.                 .SetFont(CGXFont().SetBold(TRUE).SetSize(14))
  343.             );
  344.  
  345.         nRow++;
  346.         nRow++;
  347.  
  348. //       Password
  349.         SetValueRange(CGXRange(nRow, nCol), "Password");
  350.         SetStyleRange(CGXRange(nRow, nCol+1),
  351.             CGXStyle()
  352.             .SetControl(GX_IDS_CTRL_PASSWORD)
  353.             .SetInterior(RGB(192,192,192))    // grey
  354.             .SetDraw3dFrame(gxFrameInset)
  355.             .SetUserAttribute(GX_IDS_UA_TOOLTIPTEXT, _T("CGXPasswordControl")) 
  356.             );
  357.  
  358. //       Thick border
  359.         nRow++;
  360.         SetStyleRange(CGXRange().SetRows(nRow), 
  361.             CGXStyle()
  362.                 .SetBorders(gxBorderTop, CGXPen().SetWidth(2))
  363.             );
  364.  
  365. //       Ownerdrawn checkbox Title
  366.         SetCoveredCellsRowCol(nRow, nCol, nRow, nCol+1);
  367.         SetStyleRange(CGXRange(nRow, nCol), 
  368.             CGXStyle()
  369.                 .SetValue("Ownerdrawn Checkboxes")
  370.                 .SetFont(CGXFont().SetBold(TRUE).SetSize(14))
  371.             );
  372.  
  373.         nRow++;
  374.         nRow++;
  375.  
  376. //       Ownerdrawn checkbox
  377.         SetValueRange(CGXRange(nRow, nCol), "Ownerdrawn Checkbox");
  378.         SetStyleRange(CGXRange(nRow, nCol+1), 
  379.             CGXStyle()
  380.                 .SetControl(GX_IDS_CTRL_CHECKBOX)
  381.                 .SetValue(0L)
  382.                 .SetChoiceList(_T("Show Progress"))
  383.                 .SetUserAttribute(GX_IDS_UA_TOOLTIPTEXT, _T("Click checkbox to stop or start running the progressbars"))  
  384.                 .SetVerticalAlignment(DT_VCENTER));
  385.         nRow++;
  386. //       Thick border
  387.  
  388.         SetStyleRange(CGXRange().SetRows(nRow), 
  389.             CGXStyle()
  390.                 .SetBorders(gxBorderTop, CGXPen().SetWidth(2))
  391.             );
  392.  
  393. //       Progress Bars Title
  394.         SetCoveredCellsRowCol(nRow, nCol, nRow, nCol+1);
  395.         SetStyleRange(CGXRange(nRow, nCol), 
  396.             CGXStyle()
  397.                 .SetValue("Progress Bars")
  398.                 .SetFont(CGXFont().SetBold(TRUE).SetSize(14))
  399.             );
  400.  
  401.         nRow++;
  402.         nRow++;
  403.  
  404. //       Progress Bars
  405.         SetValueRange(CGXRange(nRow, nCol), "Progress Bars");
  406.         SetStyleRange(CGXRange(nRow, nCol+1, nRow, nCol+3), 
  407.             CGXStyle()
  408.                 .SetControl(GX_IDS_CTRL_PROGRESS)
  409.                 .SetValue(50L)
  410.                 .SetUserAttribute(GX_IDS_UA_PROGRESS_MIN, _T("0"))
  411.                 .SetUserAttribute(GX_IDS_UA_PROGRESS_MAX, _T("100"))
  412.                 .SetUserAttribute(GX_IDS_UA_PROGRESS_CAPTIONMASK, _T("%ld %%"))  // sprintf formatting for value
  413.                 .SetUserAttribute(GX_IDS_UA_TOOLTIPTEXT, _T("Click checkbox to stop or start running the progressbars"))  
  414.                 .SetTextColor(RGB(0, 0, 255))        // blue progress bar
  415.                 .SetInterior(RGB(255, 255, 255))    // on white background
  416.                 .SetDraw3dFrame(gxFrameRaised)
  417.             );
  418.         nRow++;
  419.         nRow++;
  420.  
  421. //       Thick border
  422.  
  423.         SetStyleRange(CGXRange().SetRows(nRow), 
  424.             CGXStyle()
  425.                 .SetBorders(gxBorderTop, CGXPen().SetWidth(2))
  426.             );
  427.  
  428. #if _MFC_VER >= 0x0400 
  429.         // Rich Text will not work with UNICODE with MFC 4.2.
  430.         // If you need RichText functionality for your UNICODE
  431.         // builds, you should use MFC 4.1 or contact MS for
  432.         // the MFC 4.2b patch.
  433. //       Rich Edit Title
  434.         SetCoveredCellsRowCol(nRow, nCol, nRow, nCol+1);
  435.         SetStyleRange(CGXRange(nRow, nCol), 
  436.             CGXStyle()
  437.                 .SetValue("Rich Text Formatting")
  438.                 .SetFont(CGXFont().SetBold(TRUE).SetSize(14))
  439.             );
  440.  
  441.         nRow++;
  442.         nRow++;
  443.  
  444. //       Rich Edit
  445.         SetCoveredCellsRowCol(nRow, nCol, nRow, nCol+3);
  446.         SetStyleRange(CGXRange(nRow, nCol), 
  447.             CGXStyle()
  448.                 .SetControl(GX_IDS_CTRL_RICHEDIT)
  449.                 .SetUserAttribute(GX_IDS_UA_TOOLTIPTEXT, _T("CGXRichEditCtrl"))  
  450.                 .SetValue(
  451.                     // * Change the font and color for individual characters
  452.                     // * Copy/Paste from / to Wordpard
  453.                     // * Enlarge cell while entering text
  454.                     _T("{")
  455.                     _T("\\rtf1\\ansi\\deff0\\deftab720")
  456.                     _T("{")
  457.                         _T("\\fonttbl")
  458.                         _T("{\\f0\\fswiss MS Sans Serif;}")
  459.                         _T("{\\f1\\froman\\fcharset2 Symbol;}")
  460.                         _T("{\\f2\\fswiss\\fprq2 System;}")
  461.                         _T("{\\f3\\fswiss\\fprq2 Arial;}")
  462.                         _T("{\\f4\\froman Bookman Old Style;}")
  463.                     _T("}")
  464.                     _T("{\\colortbl\\red0\\green0\\blue0;\\red255\\green0\\blue0;}")
  465.                     _T("\\deflang1033\\pard\\plain\\f3\\fs16\\cf0 * Change the ")
  466.                     _T("\\plain\\f4\\fs24\\cf0\\b\\i\\ul font \\plain\\f3\\fs16\\cf0 or ")
  467.                     _T("\\plain\\f4\\fs24\\cf1\\b\\ul color\\plain\\f3\\fs16\\cf0  ")
  468.                     _T("for individual characters.\\par ")
  469.                     _T("* \\plain\\f3\\fs16\\cf0\\b Copy/Paste ")
  470.                     _T("\\plain\\f3\\fs16\\cf0 from / to Wordpad ")
  471.                     _T("with RTF formattting\\par ")
  472.                     _T("* \\plain\\f3\\fs16\\cf0\\b Enlarge cell ")
  473.                     _T("\\plain\\f3\\fs16\\cf0 while entering text. \\par")
  474.                     _T("* Select some characters in this cell and open Format|Cells to change them!\\par }")
  475.                     )
  476.                 .SetAutoSize(TRUE)
  477.                 .SetWrapText(TRUE)
  478.                 .SetAllowEnter(TRUE)
  479.             );
  480.         nRow++;
  481.  
  482.         // This is the sample from the CGXRichEditCtrl class
  483.         // reference.
  484.  
  485.         SetCoveredCellsRowCol(nRow, nCol, nRow, nCol+3);
  486.         SetStyleRange(CGXRange(nRow, nCol), 
  487.             CGXStyle()
  488.                 .SetControl(GX_IDS_CTRL_RICHEDIT)
  489.                 .SetAutoSize(TRUE)
  490.                 .SetWrapText(TRUE)
  491.                 .SetAllowEnter(TRUE)
  492.             );
  493.  
  494.         SetValueRange(CGXRange(nRow, nCol),
  495.             _T("{\\rtf1\\ansi")
  496.             // font table
  497.             _T("{\\fonttbl")
  498.             _T("\\f0\\froman Times New Roman; ")
  499.             _T("\\f1\\fdecor Courier New; ")
  500.             _T("\\f2\\fswiss Arial;} ")
  501.             _T("\\deff0 ")
  502.             // color table
  503.             _T("{\\colortbl")
  504.             _T("\\red0\\green0\\blue0; ")
  505.             _T("\\red255\\green0\\blue0; ")
  506.             _T("\\red0\\green128\\blue0; ")
  507.             _T("\\red0\\green0\\blue255;} ")
  508.             // first line
  509.             _T("\\qc\\cf1\\f0\\fs20 10 point, Times New Roman, ")
  510.             _T("red, centered\\plain\\par")
  511.             // second line
  512.             _T("\\ql\\cf3\\f1\\fs28 14 point, Courier New, blue, ")
  513.             _T("left aligned\\plain\\par")
  514.             // third line
  515.             _T("\\qr\\cf0\\f2\\fs36 18 point, Arial, black, ")
  516.             _T("right aligned\\plain\\par")
  517.             // fourth line
  518.             _T("\\qc Default font and color, \\b Bold\\plain , \\ul Underline\\plain , \\i Italic \\plain\\par")
  519.             // closing bracket
  520.             _T("}")
  521.         );
  522.         nRow++;
  523.  
  524. //       Thick border
  525.  
  526.         SetStyleRange(CGXRange().SetRows(nRow), 
  527.             CGXStyle()
  528.                 .SetBorders(gxBorderTop, CGXPen().SetWidth(2))
  529.             );
  530.  
  531. #endif
  532.  
  533. //       Other New Features
  534.         SetCoveredCellsRowCol(nRow, nCol, nRow, nCol+1);
  535.         SetStyleRange(CGXRange(nRow, nCol), 
  536.             CGXStyle()
  537.                 .SetValue("Other New Features")
  538.                 .SetFont(CGXFont().SetBold(TRUE).SetSize(14))
  539.             );
  540.  
  541.         nRow++;
  542.         nRow++;
  543.  
  544. //       List of other features
  545. #if _MFC_VER >= 0x0400 
  546.         // Rich Text will not work with UNICODE with MFC 4.2
  547.         // Please contact MS for the MFC 4.2b patch if you
  548.         // need RichText functionality under UNICODE (or use
  549.         // MFC 4.1)
  550.         SetCoveredCellsRowCol(nRow, nCol, nRow, nCol+2);
  551.         SetValueRange(CGXRange(nRow, nCol), _T("* OLE Drag and Drop\r\n")
  552.             _T("  Switch to another sheet, select a range of cells\r\n")
  553.             _T("  and click on the edge of the inverted area and drag\r\n")
  554.             _T("  the cells to different views or applications. You might\r\n")
  555.             _T("  also select text in an edit control and drag this text\r\n")
  556.             _T("  to another cell or another application.")
  557.             );
  558.         nRow++;
  559.  
  560.         SetCoveredCellsRowCol(nRow, nCol, nRow, nCol+2);
  561.         SetValueRange(CGXRange(nRow, nCol), _T("* Tooltips for cells"));
  562.         nRow++;
  563.  
  564.         SetCoveredCellsRowCol(nRow, nCol, nRow, nCol+2);
  565.         SetValueRange(CGXRange(nRow, nCol), _T("* Scrolltips while dragging the scrollthumb"));
  566.         nRow++;
  567. #endif
  568.  
  569.         SetCoveredCellsRowCol(nRow, nCol, nRow, nCol+2);
  570.         SetValueRange(CGXRange(nRow, nCol), _T("* Colors and Scrollbars support changing\r\n  desktop appearance on the fly"));
  571.         nRow++;
  572.  
  573.         SetCoveredCellsRowCol(nRow, nCol, nRow, nCol+2);
  574.         SetValueRange(CGXRange(nRow, nCol), _T("* Smooth tracking of row/column size.\r\n  Try to resize a row or column in this sample view!"));
  575.         nRow++;
  576.  
  577.         SetCoveredCellsRowCol(nRow, nCol, nRow, nCol+2);
  578.         SetValueRange(CGXRange(nRow, nCol), _T("* Check out the release notes for even more new features."));
  579.         nRow++;
  580.  
  581.  
  582. //       Thick border
  583.         SetStyleRange(CGXRange().SetRows(nRow), 
  584.             CGXStyle()
  585.                 .SetBorders(gxBorderTop, CGXPen().SetWidth(2))
  586.             );
  587.  
  588.         ResizeColWidthsToFit(CGXRange().SetRows(5, nRow));
  589.         ResizeRowHeightsToFit(CGXRange().SetRows(5, nRow));
  590.  
  591.  
  592.         // Enable creation of undo-information for user interactions
  593.         GetParam()->EnableUndo(TRUE);
  594.  
  595.         // enable selecting cells only (not complete rows or columns)
  596.         GetParam()->EnableSelection(GX_SELCELL|GX_SELSHIFT|GX_SELKEYBOARD);
  597.         GetParam()->EnableThumbTrack(FALSE);
  598.         GetParam()->EnableMoveCols(FALSE);
  599.         GetParam()->EnableMoveRows(FALSE);
  600.  
  601.         // smooth tracking
  602.         GetParam()->EnableTrackRowHeight(
  603.             GX_TRACK_INDIVIDUAL
  604.             | GX_TRACK_SMOOTHCELLS 
  605.             | GX_TRACK_NOPRESSEDHEADER 
  606.             | GX_TRACK_NOMARKTRACKLINE);
  607.     }
  608.  
  609.     // Position the current cell
  610.  
  611.     SetCurrentCell(4, 1, FALSE /* avoid immediate updating */);
  612.  
  613.     // Limit Copy/Paste and Drag&Drop to Text Only. This makes
  614.     // sure that when the user cuts or drags cells, the cell
  615.     // style will not be cleared out (with all its formattings
  616.     // and control information).
  617.  
  618. #if _MFC_VER >= 0x0400 && !defined(_AFX_NO_OLE_SUPPORT)
  619.     EnableOleDataSource(GX_DNDTEXT|GX_DNDMULTI);
  620. #endif
  621.     m_nClipboardFlags = GX_DNDTEXT|GX_DNDMULTI;
  622.  
  623.     // Enable Update-Hint-Mechanism
  624.  
  625.     EnableHints();
  626. }
  627.  
  628. /////////////////////////////////////////////////////////////////////////////
  629. // CGridSample8View diagnostics
  630.  
  631. #ifdef _DEBUG
  632. void CGridSample8View::AssertValid() const
  633. {
  634.     CMyGridView::AssertValid();
  635. }
  636.  
  637. void CGridSample8View::Dump(CDumpContext& dc) const
  638. {
  639.     CMyGridView::Dump(dc);
  640. }
  641.  
  642. CGridSampleDoc* CGridSample8View::GetDocument() // non-debug version is inline
  643. {
  644.     ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CGridSampleDoc)));
  645.     return (CGridSampleDoc*) m_pDocument;
  646. }
  647.  
  648. #endif //_DEBUG
  649.  
  650.  
  651. /////////////////////////////////////////////////////////////////////////////
  652. // CGridSample8View message handlers
  653.  
  654. // Menu handler for View->Splitter View
  655.  
  656. void CGridSample8View::OnViewSplitterview()
  657. {
  658.     CDocument* pDoc = GetDocument();
  659.  
  660.     CMyMultiDocTemplate* pTemplate
  661.         = (CMyMultiDocTemplate*) ((CGridSampleApp*) AfxGetApp())->m_pSplitterTemplate;
  662.  
  663.     pTemplate->SetViewClass(GetRuntimeClass());
  664.  
  665.     CMDIChildWnd* pNewFrame
  666.         = (CMDIChildWnd*) pTemplate->CreateNewFrame(GetDocument(), NULL);
  667.  
  668.     if (pNewFrame == NULL)
  669.         return;     // not created
  670.  
  671.     ASSERT(pNewFrame->IsKindOf(RUNTIME_CLASS(CSplitterMDIChildWnd)));
  672.  
  673.     CSplitterWnd& splitter = (CSplitterWnd&)
  674.         ((CSplitterMDIChildWnd *) pNewFrame)->m_wndSplitter;
  675.  
  676.     CGridSample8View* pView = (CGridSample8View*)
  677.         splitter.GetPane(0, 0);
  678.  
  679.     // Set view id to active tab view id
  680.     pView->m_nViewID = m_nViewID;
  681.  
  682.     pTemplate->InitialUpdateFrame(pNewFrame, pDoc);
  683.  
  684.     pNewFrame->GetActiveView();
  685.     ASSERT(pView);
  686. }
  687.  
  688. // Menu handler for View->User Actions...
  689.  
  690. void CGridSample8View::OnViewUseractions()
  691. {
  692.     // Note: this method is copied from CGridSampleView
  693.     //
  694.     // Shows a dialog with some attributes of the parameter-object
  695.     // where you can experiment with some attributes
  696.     // such as allowing the user to track columns, select cells
  697.     // or use the grid as a listbox.
  698.  
  699.     // Transfer Current Cell's Data to grid
  700.     if (!TransferCurrentCell())
  701.         return;
  702.  
  703.     CUserActionsDialog dlg(GetParam());
  704.  
  705.     if (dlg.DoModal() == IDOK)
  706.     {
  707.         // Redraw the grid
  708.         Redraw();
  709.     }
  710. }
  711.  
  712. void CGridSample8View::UpdateProgressDisplay()
  713. {
  714.     BOOL bUndo = GetParam()->IsEnableUndo();
  715.     GetParam()->EnableUndo(FALSE);
  716.  
  717.     CGXProgressCtrl::SetProgressValue(this, m_nProgBarRow, m_nProgBarCol, nValue1);
  718.     CGXProgressCtrl::SetProgressValue(this, m_nProgBarRow, m_nProgBarCol+1, nValue2);
  719.     CGXProgressCtrl::SetProgressValue(this, m_nProgBarRow, m_nProgBarCol+2, nValue3);
  720.  
  721.     GetParam()->EnableUndo(bUndo);
  722. }
  723.  
  724. void CGridSample8View::OnTimer(UINT nIDEvent) 
  725. {
  726.     if (nIDEvent == NIDTIMER)
  727.     {
  728.         nValue1 = (nValue1+1)%100;
  729.         nValue2 = (nValue2+2)%100;
  730.         nValue3 = (nValue3+4)%100;
  731.         UpdateProgressDisplay();
  732.     }
  733.     
  734.     CMyGridView::OnTimer(nIDEvent);
  735. }
  736.  
  737. void CGridSample8View::OnActivateView( BOOL bActivate, CView* pActivateView, CView* pDeactiveView )
  738. {       
  739.     if (!bActivate)
  740.     {
  741.         KillTimer(NIDTIMER);
  742.          m_bTimerRunning = FALSE;
  743.     }
  744.  
  745.     CMyGridView::OnActivateView(bActivate, pActivateView, pDeactiveView);
  746. }                
  747.  
  748. BOOL CGridSample8View::CanActivateGrid(BOOL bActivate)
  749. {
  750.     if (!bActivate)
  751.     {
  752.         KillTimer(NIDTIMER);
  753.          m_bTimerRunning = FALSE;
  754.     }
  755.  
  756.     return CMyGridView::CanActivateGrid(bActivate);
  757. }                
  758.  
  759. void CGridSample8View::OnClickedButtonRowCol(ROWCOL nRow, ROWCOL nCol)
  760. {
  761.     nRow, nCol; // Unused
  762.  
  763.     m_bTimerRunning = !m_bTimerRunning;
  764.  
  765.     if (!m_bTimerRunning)
  766.         KillTimer(NIDTIMER);
  767.     else
  768.         SetTimer(NIDTIMER, 100, NULL);
  769. }
  770.  
  771. void CGridSample8View::OnVScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar) 
  772. {
  773. #if _MFC_VER >= 0x0400
  774.     if (!GXGetAppData()->bWin31)
  775.     {
  776.         // ScrollTips
  777.         ROWCOL nRow = nPos, nCol = 0;
  778.         TCHAR szText[256];
  779.         wsprintf(szText, _T("Row: %s"), GetValueRowCol(nRow, nCol));
  780.         m_pScrollTip->HandleScrollMessage(this, nSBCode, SB_VERT, szText, pScrollBar);     
  781.     }
  782. #endif
  783.  
  784.     CMyGridView::OnVScroll(nSBCode, nPos, pScrollBar);
  785. }
  786.  
  787. void CGridSample8View::OnHScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar) 
  788. {
  789. #if _MFC_VER >= 0x0400
  790.     if (!GXGetAppData()->bWin31)
  791.     {
  792.         // ScrollTips
  793.         ROWCOL nRow = 0, nCol = nPos;
  794.         TCHAR szText[256];
  795.         wsprintf(szText, _T("Column: %s"), GetValueRowCol(nRow, nCol));
  796.         m_pScrollTip->HandleScrollMessage(this, nSBCode, SB_HORZ, szText, pScrollBar);     
  797.     }
  798. #endif
  799.     
  800.     CMyGridView::OnHScroll(nSBCode, nPos, pScrollBar);
  801. }
  802.  
  803.