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 / mygridvw.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1996-10-27  |  30.6 KB  |  1,226 lines

  1. // mygridvw.cpp : implementation of the CMyGridView 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 "resource.h"
  17. #include "mygridvw.h"
  18.  
  19. #ifndef _GXSTYDLG_H_
  20. #include "gxstydlg.h"
  21. #endif
  22.  
  23. #ifndef _GXPRPD_H_
  24. #include "gxprpdlg.h"
  25. #endif
  26.  
  27. #ifdef _DEBUG
  28. #undef THIS_FILE
  29. static char BASED_CODE THIS_FILE[] = __FILE__;
  30. #endif
  31.  
  32. IMPLEMENT_DYNCREATE(CMyGridView, CGXGridView)
  33.  
  34. #define new DEBUG_NEW
  35.  
  36. /////////////////////////////////////////////////////////////////////////////
  37. // CMyGridView
  38. //
  39. // CMyGridView contains code for menu handlers
  40. //
  41. // Use this class as a collection of code which you can copy to your
  42. // specific gridview class or simply copy the whole file to your
  43. // project and use it as a base class for your gridview classes.
  44. //
  45. // Following menu handlers are implemented in CMyGridView:
  46. // File->
  47. //     Page Setup
  48. //     Header/Footer Setup
  49. // Edit->
  50. //     Clear
  51. //     Insert Column
  52. //     Insert Row
  53. //     Remove Column
  54. //     Remove Row
  55. // View->
  56. //     Zoom In
  57. //     Zoom Out
  58. //     100%
  59. //     Read Only
  60. //     Properties...
  61. // Format->
  62. //     Cells...
  63. //     Lookup...
  64. //     Freeze Columns
  65. //     Unfreeze Columns
  66. //     Freeze Rows
  67. //     Unfreeze Rows
  68. //     Cover Cells
  69. //     Remove Covering
  70. //     Styles...
  71. //     Resize Rows
  72. //     Resize Columns
  73. //     Align->
  74. //         Left
  75. //         Center
  76. //         Right
  77. //     Style->
  78. //         Bold
  79. //         Italic
  80. //         Underline
  81. //
  82. // Following menu handlers are implemented in CGXGridView:
  83. // Edit->
  84. //     Undo (ID_EDIT_UNDO)
  85. //     Redo (ID_EDIT_REDO)
  86. //     Find... (ID_EDIT_FIND)
  87. //     Replace... (ID_EDIT_REPLACE)
  88. //     Find again (ID_EDIT_REPEAT)
  89. //     Cut (ID_EDIT_CUT)
  90. //     Copy (ID_EDIT_COPY)
  91. //     Paste (ID_EDIT_PASTE)
  92. //
  93. // Additional Operations ease the applying of styles to selected cell ranges
  94. //
  95. // BOOL NeedStyle(const CGXStyle& styleNeeded, BOOL& bRet);
  96. //    Is used by OnUpdateFormatStyle... and OnUpdateFormatAlign... to determine
  97. //    the state of a specific style as bold, italic, underline
  98. //    for the current cell or selected range of cells.
  99. //
  100. // void SetStyle(const CGXStyle& style, GXModifyType mt = gxOverride);
  101. // void SetStyle(const CGXStyle* pStyle, GXModifyType mt);
  102. //    Is used by OnFormatStyle... and OnFormatAlign... to set
  103. //    the style for the current cell or selected range of cells.
  104. //
  105. // written by Stefan Hoenig, 12.02.94
  106. //
  107.  
  108. BEGIN_MESSAGE_MAP(CMyGridView, CGXGridView)
  109.     //{{AFX_MSG_MAP(CMyGridView)
  110.     ON_COMMAND(ID_FILE_HEADERFOOTER, OnFileHeaderfooter)
  111.     ON_COMMAND(ID_FILE_PAGE_SETUP, OnFilePageSetup)
  112.     ON_COMMAND(ID_EDIT_INSERTCOL, OnEditInsertcol)
  113.     ON_COMMAND(ID_EDIT_INSERTROW, OnEditInsertrow)
  114.     ON_COMMAND(ID_EDIT_REMOVECOLS, OnEditRemovecols)
  115.     ON_COMMAND(ID_EDIT_REMOVEROWS, OnEditRemoverows)
  116.     ON_COMMAND(ID_VIEW_100, OnView100)
  117.     ON_COMMAND(ID_VIEW_PROPERTIES, OnViewProperties)
  118.     ON_COMMAND(ID_VIEW_READONLY, OnViewReadonly)
  119.     ON_COMMAND(ID_VIEW_ZOOMIN, OnViewZoomin)
  120.     ON_COMMAND(ID_VIEW_ZOOMOUT, OnViewZoomout)
  121.     ON_COMMAND(ID_FORMAT_ALIGN_CENTER, OnFormatAlignCenter)
  122.     ON_COMMAND(ID_FORMAT_ALIGN_LEFT, OnFormatAlignLeft)
  123.     ON_COMMAND(ID_FORMAT_ALIGN_RIGHT, OnFormatAlignRight)
  124.     ON_COMMAND(ID_FORMAT_CELLS, OnFormatCells)
  125.     ON_COMMAND(ID_FORMAT_COVERCELLS, OnFormatCovercells)
  126.     ON_COMMAND(ID_FORMAT_FREEZECOLS, OnFormatFreezecols)
  127.     ON_COMMAND(ID_FORMAT_FREEZEROWS, OnFormatFreezerows)
  128.     ON_COMMAND(ID_FORMAT_LOOKUP, OnFormatLookup)
  129.     ON_COMMAND(ID_FORMAT_REMOVECOVER, OnFormatRemovecover)
  130.     ON_COMMAND(ID_FORMAT_STYLE_BOLD, OnFormatStyleBold)
  131.     ON_COMMAND(ID_FORMAT_STYLE_ITALIC, OnFormatStyleItalic)
  132.     ON_COMMAND(ID_FORMAT_STYLE_UNDERLINE, OnFormatStyleUnderline)
  133.     ON_COMMAND(ID_FORMAT_STYLES, OnFormatStyles)
  134.     ON_COMMAND(ID_FORMAT_UNFREEZECOLS, OnFormatUnfreezecols)
  135.     ON_COMMAND(ID_FORMAT_UNFREEZEROWS, OnFormatUnfreezerows)
  136.     ON_UPDATE_COMMAND_UI(ID_EDIT_REMOVECOLS, OnUpdateEditRemovecols)
  137.     ON_UPDATE_COMMAND_UI(ID_EDIT_REMOVEROWS, OnUpdateEditRemoverows)
  138.     ON_UPDATE_COMMAND_UI(ID_FORMAT_ALIGN_CENTER, OnUpdateFormatAlignCenter)
  139.     ON_UPDATE_COMMAND_UI(ID_FORMAT_ALIGN_LEFT, OnUpdateFormatAlignLeft)
  140.     ON_UPDATE_COMMAND_UI(ID_FORMAT_ALIGN_RIGHT, OnUpdateFormatAlignRight)
  141.     ON_UPDATE_COMMAND_UI(ID_FORMAT_CELLS, OnUpdateFormatCells)
  142.     ON_UPDATE_COMMAND_UI(ID_FORMAT_COVERCELLS, OnUpdateFormatCovercells)
  143.     ON_UPDATE_COMMAND_UI(ID_FORMAT_FREEZECOLS, OnUpdateFormatFreezecols)
  144.     ON_UPDATE_COMMAND_UI(ID_FORMAT_FREEZEROWS, OnUpdateFormatFreezerows)
  145.     ON_UPDATE_COMMAND_UI(ID_FORMAT_LOOKUP, OnUpdateFormatLookup)
  146.     ON_UPDATE_COMMAND_UI(ID_FORMAT_REMOVECOVER, OnUpdateFormatRemovecover)
  147.     ON_UPDATE_COMMAND_UI(ID_FORMAT_STYLE_BOLD, OnUpdateFormatStyleBold)
  148.     ON_UPDATE_COMMAND_UI(ID_FORMAT_STYLE_ITALIC, OnUpdateFormatStyleItalic)
  149.     ON_UPDATE_COMMAND_UI(ID_FORMAT_STYLE_UNDERLINE, OnUpdateFormatStyleUnderline)
  150.     ON_UPDATE_COMMAND_UI(ID_FORMAT_UNFREEZECOLS, OnUpdateFormatUnfreezecols)
  151.     ON_UPDATE_COMMAND_UI(ID_FORMAT_UNFREEZEROWS, OnUpdateFormatUnfreezerows)
  152.     ON_UPDATE_COMMAND_UI(ID_VIEW_READONLY, OnUpdateViewReadonly)
  153.     ON_UPDATE_COMMAND_UI(ID_VIEW_ZOOMIN, OnUpdateViewZoomin)
  154.     ON_UPDATE_COMMAND_UI(ID_VIEW_ZOOMOUT, OnUpdateViewZoomout)
  155.     ON_COMMAND(ID_EDIT_CLEAR, OnEditClear)
  156.     ON_UPDATE_COMMAND_UI(ID_EDIT_CLEAR, OnUpdateEditClear)
  157.     ON_UPDATE_COMMAND_UI(ID_FILE_SAVE, OnUpdateFileSave)
  158.     ON_COMMAND(ID_FORMAT_RESIZECOLS, OnFormatResizecols)
  159.     ON_UPDATE_COMMAND_UI(ID_FORMAT_RESIZECOLS, OnUpdateFormatResizecols)
  160.     ON_COMMAND(ID_FORMAT_RESIZEROWS, OnFormatResizerows)
  161.     ON_UPDATE_COMMAND_UI(ID_FORMAT_RESIZEROWS, OnUpdateFormatResizerows)
  162.     ON_COMMAND(ID_VIEW_WYSIWIG, OnViewWysiwig)
  163.     ON_UPDATE_COMMAND_UI(ID_VIEW_WYSIWIG, OnUpdateViewWysiwig)
  164.     ON_WM_CREATE()
  165.     //}}AFX_MSG_MAP
  166.     // Standard printing commands
  167.     ON_COMMAND(ID_FILE_PRINT, CGXGridView::OnFilePrint)
  168.     ON_COMMAND(ID_FILE_PRINT_PREVIEW, CGXGridView::OnFilePrintPreview)
  169. END_MESSAGE_MAP()
  170.  
  171. /////////////////////////////////////////////////////////////////////////////
  172. // CMyGridView construction/destruction
  173.  
  174. CMyGridView::CMyGridView()
  175. {
  176.     // TODO: add construction code here
  177.  
  178. }
  179.  
  180. CMyGridView::~CMyGridView()
  181. {
  182. }
  183.  
  184. const UINT gxnFirstCtrl = 18001;
  185.  
  186. int CMyGridView::OnCreate(LPCREATESTRUCT lpCreateStruct)
  187. {
  188.     if (CGXGridView::OnCreate(lpCreateStruct) == -1)
  189.         return -1;
  190.  
  191. #if _MFC_VER >= 0x0400 && !defined(_AFX_NO_OLE_SUPPORT)
  192.     // Enable grid to be used as data source
  193.     EnableOleDataSource();
  194.  
  195.     // Register the grid as drop target
  196.     VERIFY(m_objDndDropTarget.Register(this));
  197. #endif
  198.  
  199. #if _MFC_VER >= 0x0400
  200.     EnableGridToolTips();
  201. #endif
  202.  
  203.     return 0;
  204. }
  205.  
  206. void CMyGridView::OnInitialUpdate()
  207. {
  208.     // check parameter object
  209.     if (GetParam() == NULL)
  210.         SetParam(new CGXGridParam);
  211.  
  212.     // check styles
  213.     if (GetParam()->GetStylesMap() == NULL)
  214.     {
  215.         CGXStylesMap* stylesmap = new CGXStylesMap;
  216.  
  217.         // standard styles
  218.         stylesmap->CreateStandardStyles();
  219.  
  220.         // use spin-control in "User"-page
  221.         CGXStyle styleSpin;
  222.         styleSpin.SetControl(GX_IDS_CTRL_SPINEDIT).SetWrapText(FALSE);
  223.  
  224.         // user attributes
  225.             // Validation: warning message
  226.         stylesmap->AddUserAttribute(GX_IDS_UA_VALID_MSG,
  227.             CGXStyle().SetWrapText(TRUE).SetAutoSize(TRUE));
  228.  
  229.             // Validation: maximum value
  230.         stylesmap->AddUserAttribute(GX_IDS_UA_VALID_MAX,
  231.             &styleSpin);
  232.  
  233.             // Validation: Minimum value
  234.         stylesmap->AddUserAttribute(GX_IDS_UA_VALID_MIN,
  235.             &styleSpin);
  236.  
  237.             // Spinbounds: Minimum value
  238.         stylesmap->AddUserAttribute(GX_IDS_UA_SPINBOUND_MIN,
  239.             &styleSpin);
  240.  
  241.             // Spinbounds: maximum value
  242.         stylesmap->AddUserAttribute(GX_IDS_UA_SPINBOUND_MAX,
  243.             &styleSpin);
  244.  
  245.             // Spinbounds: start value when changing from null
  246.         stylesmap->AddUserAttribute(GX_IDS_UA_SPINSTART, &styleSpin);
  247.  
  248.             // Spinbounds: wrap value
  249.         stylesmap->AddUserAttribute(GX_IDS_UA_SPINBOUND_WRAP,
  250.             CGXStyle().SetControl(GX_IDS_CTRL_CHECKBOX3D)
  251.                   .SetVerticalAlignment(DT_VCENTER)
  252.                   .SetHorizontalAlignment(DT_CENTER));
  253.  
  254.             // Checkbox, checked/uncheck represantation
  255.         CGXStyle  styleCheck;
  256.         stylesmap->AddUserAttribute(GX_IDS_UA_CHECKBOX_CHECKED,
  257.             &styleCheck);
  258.  
  259.         stylesmap->AddUserAttribute(GX_IDS_UA_CHECKBOX_UNCHECKED,
  260.             &styleCheck);
  261.  
  262.             // Tooltips
  263. #if _MFC_VER >= 0x0400
  264.         stylesmap->AddUserAttribute(GX_IDS_UA_TOOLTIPTEXT,
  265.             CGXStyle().SetWrapText(TRUE).SetAutoSize(TRUE));
  266. #endif
  267.  
  268.             // Masked input
  269.         stylesmap->AddUserAttribute(GX_IDS_UA_INPUTMASK,
  270.             CGXStyle().SetWrapText(TRUE).SetAutoSize(TRUE));
  271.  
  272.         stylesmap->AddUserAttribute(GX_IDS_UA_INPUTPROMPT,
  273.             CGXStyle().SetMaxLength(1));
  274.  
  275.         // load profile/registry settings
  276.         stylesmap->ReadProfile();
  277.  
  278.         // attach object to parameter-object
  279.         GetParam()->SetStylesMap(stylesmap);
  280.     }
  281.  
  282.     CGXGridView::OnInitialUpdate();
  283.  
  284.     // Register default controls (they need to be register for each view)
  285.  
  286.     // All registered controls will appear in the control-listbox in the control-page
  287.     // of the style-sheet. The user can apply these controls to cells.
  288.  
  289.     // GX_IDS_CTRL_EDIT is registered by default in CGXGridCore::OnGridInitialUpdate
  290.  
  291.     // GridMFC Comboboxes (not derived from CComboBox)
  292.  
  293.         // allow text input which fits the choice list
  294.     RegisterControl(GX_IDS_CTRL_TEXTFIT,
  295.         new CGXComboBox(this, gxnFirstCtrl+1, gxnFirstCtrl+2, GXCOMBO_TEXTFIT));
  296.  
  297.         // allow user to input any text
  298.     RegisterControl(GX_IDS_CTRL_COMBOBOX,
  299.         new CGXComboBox(this, gxnFirstCtrl+3, gxnFirstCtrl+4, GXCOMBO_NOTEXTFIT));
  300.  
  301.         // use an integer as cell value
  302.     RegisterControl(GX_IDS_CTRL_ONEBASED,
  303.         new CGXComboBox(this, gxnFirstCtrl+5, gxnFirstCtrl+6, GXCOMBO_ONEBASED));
  304.  
  305.         // use an zero-based integer as cell value
  306.     RegisterControl(GX_IDS_CTRL_ZEROBASED,
  307.         new CGXComboBox(this, gxnFirstCtrl+7, gxnFirstCtrl+8,
  308.         GXCOMBO_ZEROBASED));
  309.  
  310.         // use an integer as cell value
  311.     RegisterControl(GX_IDS_CTRL_ONEBASED_EX,
  312.         new CGXComboBox(this, gxnFirstCtrl+20, gxnFirstCtrl+21,
  313.         GXCOMBO_ONEBASED|GXCOMBO_DISPLAYCHOICE));
  314.  
  315.         // use an zero-based integer as cell value
  316.     RegisterControl(GX_IDS_CTRL_ZEROBASED_EX,
  317.         new CGXComboBox(this, gxnFirstCtrl+22, gxnFirstCtrl+23,
  318.         GXCOMBO_ZEROBASED|GXCOMBO_DISPLAYCHOICE));
  319.  
  320.     // Register all controls and user attributes for the view
  321.     {
  322.         CGXMaskControl* pEditCtrl = new CGXMaskControl(this, GX_IDS_CTRL_MASKEDIT);
  323.         pEditCtrl->CreateControl();
  324.         RegisterControl(GX_IDS_CTRL_MASKEDIT, pEditCtrl);
  325.     }
  326.  
  327.     // CComboBox adapter (derived from CComboBox)
  328.  
  329.     // CComboBox adapter with CBS_DROPDOWN style
  330.     {
  331.         CGXComboBoxWnd* pWnd = new CGXComboBoxWnd(this);
  332.         // Comment: Added CBS_AUTOHSCROLL flag
  333.         pWnd->Create(WS_VSCROLL | CBS_DROPDOWN | CBS_AUTOHSCROLL, gxnFirstCtrl+9);
  334.         pWnd->m_bFillWithChoiceList = TRUE;
  335.         pWnd->m_bWantArrowKeys = FALSE;
  336.         RegisterControl(GX_IDS_CTRL_CBS_DROPDOWN, pWnd);
  337.     }
  338.  
  339.     // CComboBox adapter with CBS_DROPDOWNLIST style
  340.     {
  341.         CGXComboBoxWnd* pWnd = new CGXComboBoxWnd(this);
  342.         pWnd->Create(WS_VSCROLL | CBS_DROPDOWNLIST, gxnFirstCtrl+10);
  343.         pWnd->m_bFillWithChoiceList = TRUE;
  344.         pWnd->m_bWantArrowKeys = FALSE;
  345.         RegisterControl(GX_IDS_CTRL_CBS_DROPDOWNLIST, pWnd);
  346.     }
  347.  
  348.     // If you need a combobox with CBS_SORT style or if you
  349.     // need an ownerdrawn combobox, you can register them
  350.     // as seen for the GX_IDS_CTRL_CBS_DROPDOWNLIST and
  351.     // GX_IDS_CTRL_CBS_DROPDOWN controls.
  352.  
  353.         // Textcontrol with Spinbuttons
  354.     RegisterControl(GX_IDS_CTRL_SPINEDIT, new CGXSpinEdit(this, gxnFirstCtrl+10));
  355.  
  356.         // Textcontrol with hotspot button
  357.     RegisterControl(GX_IDS_CTRL_HOTSPOT, new CGXHotSpotEdit(this, gxnFirstCtrl+11));
  358.  
  359.         // Textcontrol with Vertical scrollbars
  360.     RegisterControl(GX_IDS_CTRL_SCROLLEDIT, new CGXVScrollEdit(this, gxnFirstCtrl+12));
  361.  
  362.         // Listbox
  363.     RegisterControl(GX_IDS_CTRL_LISTBOX, new CGXListBox(this, gxnFirstCtrl+13));
  364.  
  365.         // Static Text
  366.     RegisterControl(GX_IDS_CTRL_STATIC, new CGXStatic(this));
  367.  
  368.         // Push Button
  369.     RegisterControl(GX_IDS_CTRL_PUSHBTN, new CGXPushbutton(this));
  370.  
  371.         // Radio Buttons
  372.     RegisterControl(GX_IDS_CTRL_RADIOBTN, new CGXRadioButton(this, FALSE /* normal Look */));
  373.     RegisterControl(GX_IDS_CTRL_RADIOBTN3D, new CGXRadioButton(this, TRUE /* 3d-Look */));
  374.  
  375.         // Check Boxes
  376.     RegisterControl(GX_IDS_CTRL_CHECKBOX, new CGXCheckBox(this, FALSE /* normal Look */));
  377.     RegisterControl(GX_IDS_CTRL_CHECKBOX3D, new CGXCheckBox(this, TRUE /* 3d-Look */));
  378.  
  379. #if _MFC_VER >= 0x0400
  380.     {
  381.         CGXRichEditCtrl* pWnd = new CGXRichEditCtrl(this);
  382.         pWnd->CreateControl();
  383.         RegisterControl(GX_IDS_CTRL_RICHEDIT, pWnd);
  384.     }
  385. #endif
  386. }
  387.  
  388. /////////////////////////////////////////////////////////////////////////////
  389. // CMyGridView diagnostics
  390.  
  391. #ifdef _DEBUG
  392. void CMyGridView::AssertValid() const
  393. {
  394.     CGXGridView::AssertValid();
  395. }
  396.  
  397. void CMyGridView::Dump(CDumpContext& dc) const
  398. {
  399.     CGXGridView::Dump(dc);
  400. }
  401.  
  402. #endif //_DEBUG
  403.  
  404. /////////////////////////////////////////////////////////////////////////////
  405. // CMyGridView Operations
  406.  
  407. BOOL CMyGridView::NeedStyle(const CGXStyle& styleNeeded, BOOL& bRet)
  408. {
  409.     CGXRangeList* pSelList = GetParam()->GetRangeList();
  410.  
  411.     POSITION pos = pSelList->GetHeadPosition();
  412.     ROWCOL nRow, nCol;
  413.  
  414.     bRet = FALSE;
  415.     if (pos)
  416.     {
  417.         nRow = pSelList->GetAt(pos)->top;
  418.         nCol = pSelList->GetAt(pos)->left;
  419.     }
  420.     else if (!GetCurrentCell(&nRow, &nCol))
  421.     {
  422.         return FALSE;
  423.     }
  424.  
  425.     if (nRow > GetRowCount() || nCol > GetColCount())
  426.         return FALSE;
  427.  
  428.     if (nRow > 0 && nCol > 0)
  429.     {
  430.         // Cell style (as stored in CGXData)
  431.         CGXStyle style;
  432.         ComposeStyleRowCol(nRow, nCol, &style);
  433.  
  434.         // Cell-specific style, e.g. RTF will set font and textcolor
  435.         // attributes of the current selection
  436.         CGXControl* pControl = GetRegisteredControl(style.GetControl());
  437.         pControl->LoadStyle(nRow, nCol, &style);
  438.  
  439.         bRet = style.IsSubSet(styleNeeded);
  440.     }
  441.     else
  442.     {
  443.         // Row or column ranges
  444.         // Compose style
  445.         CGXStyle* pStyle = new CGXStyle;
  446.  
  447.         GetStyleRowCol(nRow, nCol, *pStyle, gxCopy, -1);
  448.         GetStyleRowCol(0, 0, *pStyle, gxApplyNew, -1);
  449.         pStyle->LoadBaseStyle(*m_pParam->GetStylesMap());
  450.  
  451.         bRet = pStyle->IsSubSet(styleNeeded);
  452.  
  453.         delete pStyle;
  454.     }
  455.  
  456.     return TRUE;
  457. }
  458.  
  459. void CMyGridView::SetStyle(const CGXStyle& style, GXModifyType mt)
  460. {
  461.     SetStyle(&style, mt);
  462. }
  463.  
  464. void CMyGridView::SetStyle(const CGXStyle* pStyle, GXModifyType mt, BOOL bExpand)
  465. {
  466.     // if there are no cells selected,
  467.     // copy the current cell's coordinates
  468.     BOOL bAbort = FALSE;
  469.     CGXRangeList selList;
  470.     if (!CopyRangeList(selList, TRUE))
  471.         return;
  472.  
  473.     CGXLongOperation theOp;
  474.  
  475.     BOOL bTrans = selList.GetCount() > 1;
  476.  
  477.     if (bTrans)
  478.         BeginTrans(GXGetAppData()->strmCellFormatting);
  479.  
  480.     ROWCOL nRowCount = GetRowCount();
  481.     ROWCOL nColCount = GetColCount();
  482.  
  483.     // loop through selected cells
  484.     POSITION pos = selList.GetHeadPosition();
  485.     while (pos)
  486.     {
  487.         CGXRange rect = selList.GetNext(pos);
  488.  
  489.         if (bExpand)
  490.             rect.ExpandRange(1, 1, nRowCount, nColCount);
  491.  
  492.         // SetStyleRange returns FALSE if operation failed.
  493.         if (!SetStyleRange(rect, pStyle, mt, rect.IsCells() ? 0: -1)
  494.             || theOp.DoMessages(bAbort) && bAbort)
  495.         {
  496.             if (bTrans)
  497.                 Rollback();
  498.             return;
  499.         }
  500.     }
  501.  
  502.     if (bTrans)
  503.         CommitTrans();
  504.  
  505.     ROWCOL nRow, nCol;
  506.     if (GetCurrentCell(nRow, nCol))
  507.         GetControl(nRow, nCol)->Refresh();
  508. }
  509.  
  510. /////////////////////////////////////////////////////////////////////////////
  511. // File menu handlers
  512.  
  513. void CMyGridView::OnUpdateFileSave(CCmdUI* pCmdUI)
  514. {
  515.     pCmdUI->Enable(GetDocument()->IsModified());
  516. }
  517.  
  518. void CMyGridView::OnFilePageSetup()
  519. {
  520.     BOOL bSaveDefault = FALSE;
  521.  
  522.     CGXProperties* pPropertyObj = GetParam()->GetProperties();
  523.     ASSERT(pPropertyObj->IsKindOf(RUNTIME_CLASS(CGXProperties)));
  524.  
  525.     CGXProperties* pNewSettings = new CGXProperties;
  526.     *pNewSettings = *pPropertyObj;
  527.  
  528.     CGXPrintPropertiesDialog  dlg(pNewSettings, GetParam()->GetStylesMap(), &bSaveDefault, FALSE);
  529.  
  530.     int result = dlg.DoModal();
  531.     if (result == IDOK)
  532.     {
  533.         *pPropertyObj = *pNewSettings;
  534.         if (bSaveDefault)
  535.             pPropertyObj->WriteProfile();
  536.  
  537.         SetModifiedFlag();
  538.     }
  539.  
  540.     delete pNewSettings;
  541. }
  542.  
  543. void CMyGridView::OnFileHeaderfooter()
  544. {
  545.     BOOL bSaveDefault = FALSE;
  546.  
  547.     CGXProperties* pPropertyObj = GetParam()->GetProperties();
  548.     ASSERT(pPropertyObj->IsKindOf(RUNTIME_CLASS(CGXProperties)));
  549.  
  550.     CGXProperties* pNewSettings = new CGXProperties;
  551.     *pNewSettings = *pPropertyObj;
  552.  
  553.     CGXHeaderFooterDialog dlg(pNewSettings, &bSaveDefault);
  554.  
  555.     int result = dlg.DoModal();
  556.     if (result == IDOK)
  557.     {
  558.         *pPropertyObj = *pNewSettings;
  559.         if (bSaveDefault)
  560.             pPropertyObj->WriteProfile();
  561.  
  562.         SetModifiedFlag();
  563.     }
  564.  
  565.     delete pNewSettings;
  566. }
  567.  
  568. /////////////////////////////////////////////////////////////////////////////
  569. // Edit menu handlers
  570.  
  571. void CMyGridView::OnEditClear()
  572. {
  573.     SetStyle(NULL, gxRemove, TRUE);
  574. }
  575.  
  576. void CMyGridView::OnUpdateEditClear(CCmdUI* pCmdUI)
  577. {
  578.     pCmdUI->Enable(GetParam() && GetParam()->GetRangeList()->GetCount() > 0 || IsCurrentCell());
  579. }
  580.  
  581. void CMyGridView::OnEditInsertcol()
  582. {
  583.     ROWCOL nRow = 0, nCol = 0;
  584.  
  585.     // if there are no cells selected,
  586.     // copy the current cell's coordinates
  587.     CGXRangeList selList;
  588.     if (CopyRangeList(selList, TRUE))
  589.         nCol = selList.GetHead()->left;
  590.     else
  591.         nCol = GetColCount()+1;
  592.  
  593.     nCol = max(1, nCol);
  594.  
  595.     InsertCols(nCol, 1);
  596.     ScrollCellInView(GetTopRow(), nCol+1);
  597. }
  598.  
  599. void CMyGridView::OnEditInsertrow()
  600. {
  601.     ROWCOL nRow = 0, nCol = 0;
  602.  
  603.     // if there are no cells selected,
  604.     // copy the current cell's coordinates
  605.     CGXRangeList selList;
  606.     if (CopyRangeList(selList, TRUE))
  607.         nRow = selList.GetHead()->top;
  608.     else
  609.         nRow = GetRowCount()+1;
  610.  
  611.     nRow = max(1, nRow);
  612.  
  613.     InsertRows(nRow, 1);
  614.     ScrollCellInView(nRow+1, GetLeftCol());
  615. }
  616.  
  617. void CMyGridView::OnEditRemovecols()
  618. {
  619.     CGXRangeList* pSelList = GetParam()->GetRangeList();
  620.  
  621.     if (pSelList->IsAnyCellFromRow(0) && pSelList->GetCount() == 1)
  622.     {
  623.         CGXRange range = pSelList->GetHead();
  624.         range.ExpandRange(0, 1, 0, GetColCount());
  625.         RemoveCols(range.left, range.right);
  626.     }
  627. }
  628.  
  629. void CMyGridView::OnEditRemoverows()
  630. {
  631.     CGXRangeList* pSelList = GetParam()->GetRangeList();
  632.     if (pSelList->IsAnyCellFromCol(0) && pSelList->GetCount() == 1)
  633.     {
  634.         CGXRange range = pSelList->GetHead();
  635.         range.ExpandRange(1, 0, GetRowCount(), 0);
  636.         RemoveRows(range.top, range.bottom);
  637.     }
  638. }
  639.  
  640. void CMyGridView::OnUpdateEditRemovecols(CCmdUI* pCmdUI)
  641. {
  642.     if (GetParam() == NULL)
  643.     {
  644.         pCmdUI->Enable(FALSE);
  645.         return;
  646.     }
  647.  
  648.     CGXRangeList* pSelList = GetParam()->GetRangeList();
  649.     pCmdUI->Enable(pSelList->IsAnyCellFromRow(0) && pSelList->GetCount() == 1);
  650. }
  651.  
  652. void CMyGridView::OnUpdateEditRemoverows(CCmdUI* pCmdUI)
  653. {
  654.     if (GetParam() == NULL)
  655.     {
  656.         pCmdUI->Enable(FALSE);
  657.         return;
  658.     }
  659.  
  660.     CGXRangeList* pSelList = GetParam()->GetRangeList();
  661.     pCmdUI->Enable(pSelList->IsAnyCellFromCol(0) && pSelList->GetCount() == 1);
  662. }
  663.  
  664. /////////////////////////////////////////////////////////////////////////////
  665. // View menu handlers
  666.  
  667. void CMyGridView::OnViewProperties()
  668. {
  669.     BOOL bSaveDefault = FALSE;
  670.  
  671.     CGXProperties* pPropertyObj = GetParam()->GetProperties();
  672.     ASSERT(pPropertyObj->IsKindOf(RUNTIME_CLASS(CGXProperties)));
  673.  
  674.     CGXProperties* pNewSettings = new CGXProperties;
  675.     *pNewSettings = *pPropertyObj;
  676.  
  677.     CGXDisplayPropertiesDialog dlg(pNewSettings, GetParam()->GetStylesMap(), &bSaveDefault, FALSE);
  678.  
  679.     int result = dlg.DoModal();
  680.     if (result == IDOK)
  681.     {
  682.         *pPropertyObj = *pNewSettings;
  683.         if (bSaveDefault)
  684.             pPropertyObj->WriteProfile();
  685.  
  686.         SetModifiedFlag();
  687.         Redraw();
  688.     }
  689.  
  690.     delete pNewSettings;
  691. }
  692.  
  693. void CMyGridView::OnView100()
  694. {
  695.     SetZoom(100);
  696. }
  697.  
  698. void CMyGridView::OnViewZoomin()
  699. {
  700.     if (GetZoom() < 300)
  701.         SetZoom(GetZoom()*11/10);
  702. }
  703.  
  704. void CMyGridView::OnViewZoomout()
  705. {
  706.     if (GetZoom() > 40)
  707.         SetZoom(GetZoom()*10/11);
  708. }
  709.  
  710. void CMyGridView::OnUpdateViewZoomin(CCmdUI* pCmdUI)
  711. {
  712.     pCmdUI->Enable(GetParam() && GetZoom() < 300);
  713. }
  714.  
  715. void CMyGridView::OnUpdateViewZoomout(CCmdUI* pCmdUI)
  716. {
  717.     pCmdUI->Enable(GetParam() && GetZoom() > 40);
  718. }
  719.  
  720. void CMyGridView::OnViewReadonly()
  721. {
  722.     SetReadOnly(!IsReadOnly());
  723. }
  724.  
  725. void CMyGridView::OnUpdateViewReadonly(CCmdUI* pCmdUI)
  726. {
  727.     pCmdUI->SetCheck(GetParam() && IsReadOnly());
  728. }
  729.  
  730. void CMyGridView::OnViewWysiwig()
  731. {
  732.     if (GetParam())
  733.     {
  734.         BOOL bWysiWyg = !GetParam()->IsDrawWYSIWYG();
  735.  
  736.         if (bWysiWyg)
  737.         {
  738.             // make sure grid this is suported
  739.             CGXPrintDevice* pPD = GetParam()->GetPrintDevice();
  740.  
  741.             // GetPrintDC() will create printer device context
  742.             // when it is called the first time. Further calls
  743.             // will return the previously created device context.
  744.  
  745.             HDC hPrintDC = 0;
  746.             if (pPD)
  747.                 hPrintDC = pPD->GetPrintDC();
  748.  
  749.             if (hPrintDC == 0)
  750.                 return;
  751.         }
  752.  
  753.         GetParam()->SetDrawWYSIWYG(bWysiWyg);
  754.         Redraw();
  755.     }
  756. }
  757.  
  758. void CMyGridView::OnUpdateViewWysiwig(CCmdUI* pCmdUI)
  759. {
  760.     pCmdUI->SetCheck(GetParam() && GetParam()->IsDrawWYSIWYG());
  761. }
  762.  
  763. /////////////////////////////////////////////////////////////////////////////
  764. // Format menu handlers
  765.  
  766. void CMyGridView::OnFormatCells()
  767. {
  768.     // if there are no cells selected,
  769.     // copy the current cell's coordinates
  770.     CGXRangeList selList;
  771.     if (!CopyRangeList(selList, TRUE))
  772.         return;
  773.  
  774.     ROWCOL nRow = selList.GetHead()->top;
  775.     ROWCOL nCol = selList.GetHead()->left;
  776.  
  777.     CGXStyle* pStyle = CreateStyle();
  778.     ComposeStyleRowCol(max(nRow, 1), max(nCol, 1), pStyle);
  779.  
  780.     CGXStyleSheet sheet(_T("Cells"), *GetParam()->GetStylesMap());
  781.  
  782.     sheet.CreatePages();
  783.     sheet.SetDefaultStyle(*pStyle);
  784.     sheet.SetStyle(CGXStyle());
  785.  
  786.     if (sheet.DoModal() != IDOK)
  787.     {
  788.         delete pStyle;
  789.         return;
  790.     }
  791.  
  792.     CGXLongOperation theOp;
  793.  
  794.     BeginTrans(GXGetAppData()->strmCellFormatting);
  795.  
  796. //  TransferCurrentCell();
  797.  
  798.     TRY
  799.     {
  800.         // markierte Zellen
  801.         POSITION pos = selList.GetHeadPosition();
  802.         while (pos)
  803.         {
  804.             CGXRange rect = selList.GetNext(pos);
  805.  
  806.             if (!SetStyleRange(rect, sheet.GetStyle(), gxOverride, rect.IsCells() ? 0 : -1))
  807.                 AfxThrowUserException();
  808.         }
  809.  
  810.         CommitTrans();
  811.     }
  812.     CATCH(CUserException, e)
  813.     {
  814.         Rollback();
  815.     }
  816.     END_CATCH
  817.  
  818.     delete pStyle;
  819. }
  820.  
  821. void CMyGridView::OnFormatLookup()
  822. {
  823.     ROWCOL nRow, nCol;
  824.  
  825.     CGXStyle* pStyle = CreateStyle();
  826.     if (GetCurrentCell(nRow, nCol) && (nRow > 0 && nCol > 0))
  827.     {
  828.         // Cell style (as stored in CGXData)
  829.         ComposeStyleRowCol(nRow, nCol, pStyle);
  830.  
  831.         // Cell-specific style, e.g. RTF will set font and textcolor
  832.         // attributes of the current selection
  833.         CGXControl* pControl = GetRegisteredControl(pStyle->GetControl());
  834.         pControl->LoadStyle(nRow, nCol, pStyle);
  835.  
  836.     }
  837.     else
  838.     {
  839.         // Row or column ranges
  840.         // Compose style
  841.         CGXStyle* pStyle = new CGXStyle;
  842.  
  843.         GetStyleRowCol(nRow, nCol, *pStyle, gxCopy, -1);
  844.         GetStyleRowCol(0, 0, *pStyle, gxApplyNew, -1);
  845.         pStyle->LoadBaseStyle(*m_pParam->GetStylesMap());
  846.     }
  847.  
  848.     CGXStyleSheet sheet(_T("Lookup Cell"), *GetParam()->GetStylesMap());
  849.     sheet.CreatePages();
  850.     sheet.SetStyle(*pStyle);
  851.  
  852.     sheet.DoModal();
  853.  
  854.     delete pStyle;
  855. }
  856.  
  857. void CMyGridView::OnFormatStyles()
  858. {
  859.     CGXStylesDialog dlg;
  860.     CGXStylesMap& stylesmap = *GetParam()->GetStylesMap();
  861.  
  862.     dlg.SetStylesMap(stylesmap);
  863.  
  864.     if (dlg.DoModal() == IDOK)
  865.     {
  866.         stylesmap = dlg.GetStylesMap();
  867.         Redraw();
  868.     }
  869. }
  870.  
  871. void CMyGridView::OnUpdateFormatCells(CCmdUI* pCmdUI)
  872. {
  873.     pCmdUI->Enable(IsCurrentCell() || GetParam() && GetParam()->GetRangeList()->GetCount() > 0);
  874. }
  875.  
  876. void CMyGridView::OnUpdateFormatLookup(CCmdUI* pCmdUI)
  877. {
  878.     pCmdUI->Enable(GetParam() && IsCurrentCell());
  879. }
  880.  
  881. /////////////////////////////////////////////////////////////////////////////
  882. // Freeze Rows and Columns menu handlers
  883.  
  884. void CMyGridView::OnFormatFreezecols()
  885. {
  886.     FreezeCols();
  887. }
  888.  
  889. void CMyGridView::OnFormatFreezerows()
  890. {
  891.     FreezeRows();
  892. }
  893.  
  894. void CMyGridView::OnFormatUnfreezecols()
  895. {
  896.     UnfreezeCols();
  897. }
  898.  
  899. void CMyGridView::OnFormatUnfreezerows()
  900. {
  901.     UnfreezeRows();
  902. }
  903.  
  904. void CMyGridView::OnUpdateFormatFreezecols(CCmdUI* pCmdUI)
  905. {
  906.     pCmdUI->Enable(CanFreezeCols());
  907. }
  908.  
  909. void CMyGridView::OnUpdateFormatFreezerows(CCmdUI* pCmdUI)
  910. {
  911.     pCmdUI->Enable(CanFreezeRows());
  912. }
  913.  
  914. void CMyGridView::OnUpdateFormatUnfreezecols(CCmdUI* pCmdUI)
  915. {
  916.     pCmdUI->Enable(CanUnfreezeCols());
  917. }
  918.  
  919. void CMyGridView::OnUpdateFormatUnfreezerows(CCmdUI* pCmdUI)
  920. {
  921.     pCmdUI->Enable(CanUnfreezeRows());
  922. }
  923.  
  924. /////////////////////////////////////////////////////////////////////////////
  925. // Optimize rows and column widths
  926.  
  927. void CMyGridView::OnFormatResizecols()
  928. {
  929.     // if there are no cells selected,
  930.     // copy the current cell's coordinates
  931.     CGXRangeList selList;
  932.     if (!CopyRangeList(selList, TRUE))
  933.         return;
  934.  
  935.     CGXLongOperation theOp;
  936.  
  937.     // Transfer Current Cell's Data to grid
  938.     if (!TransferCurrentCell())
  939.         return;
  940.  
  941.     BeginTrans(GXGetAppData()->strmResizeCols);
  942.  
  943.     // stop updating the display for subsequent commands
  944.     BOOL bLock = LockUpdate(TRUE);
  945.  
  946.     TRY
  947.     {
  948.         // series of commands
  949.         // (ResizeColWidthsToFit will do a lot of SetColWidth commands)
  950.         POSITION pos = selList.GetHeadPosition();
  951.         CGXRange range;
  952.         while (pos)
  953.         {
  954.             range = *selList.GetNext(pos);
  955.             MergeCoveredCells(range);
  956.             if (!ResizeColWidthsToFit(range))
  957.                 AfxThrowUserException();
  958.         }
  959.  
  960.         CommitTrans();
  961.     }
  962.     CATCH(CUserException, e)
  963.     {
  964.         Rollback();
  965.     }
  966.     END_CATCH
  967.  
  968.     // Now, refresh the whole grid
  969.     LockUpdate(bLock);
  970.     Redraw();
  971. }
  972.  
  973. void CMyGridView::OnUpdateFormatResizecols(CCmdUI* pCmdUI)
  974. {
  975.     pCmdUI->Enable(IsCurrentCell() || GetParam() && GetParam()->GetRangeList()->GetCount() > 0);
  976. }
  977.  
  978. void CMyGridView::OnFormatResizerows()
  979. {
  980.     // if there are no cells selected,
  981.     // copy the current cell's coordinates
  982.     CGXRangeList selList;
  983.     if (!CopyRangeList(selList, TRUE))
  984.         return;
  985.  
  986.     CGXLongOperation theOp;
  987.  
  988.     // Transfer Current Cell's Data to grid
  989.     if (!TransferCurrentCell())
  990.         return;
  991.  
  992.     BeginTrans(GXGetAppData()->strmResizeRows);
  993.  
  994.     // stop updating the display for subsequent commands
  995.     BOOL bLock = LockUpdate(TRUE);
  996.  
  997.     TRY
  998.     {
  999.         // series of commands
  1000.         // (ResizeRowHeihtsToFit will do a lot of SetRowHeight commands)
  1001.         POSITION pos = selList.GetHeadPosition();
  1002.         CGXRange range;
  1003.         while (pos)
  1004.         {
  1005.             range = *selList.GetNext(pos);
  1006.             MergeCoveredCells(range);
  1007.             if (!ResizeRowHeightsToFit(range))
  1008.                 AfxThrowUserException();
  1009.         }
  1010.  
  1011.         CommitTrans();
  1012.     }
  1013.     CATCH(CUserException, e)
  1014.     {
  1015.         Rollback();
  1016.     }
  1017.     END_CATCH
  1018.  
  1019.     // Now, refresh the whole grid
  1020.     LockUpdate(bLock);
  1021.     Redraw();
  1022. }
  1023.  
  1024. void CMyGridView::OnUpdateFormatResizerows(CCmdUI* pCmdUI)
  1025. {
  1026.     pCmdUI->Enable(IsCurrentCell() || GetParam() && GetParam()->GetRangeList()->GetCount() > 0);
  1027. }
  1028.  
  1029. /////////////////////////////////////////////////////////////////////////////
  1030. // Cover Cells menu handlers
  1031.  
  1032. void CMyGridView::OnFormatCovercells()
  1033. {
  1034.     CGXRangeList* pSelList = GetParam()->GetRangeList();
  1035.  
  1036.     // check if there is a valid selection
  1037.     if (pSelList->IsEmpty()
  1038.         || !pSelList->GetHead()->IsCells() /* check if range of cells and not rows or coluns */)
  1039.         return;
  1040.  
  1041.     CGXRange* range = pSelList->GetHead();
  1042.  
  1043.     if (SetCoveredCellsRowCol(range->top, range->left, range->bottom, range->right))
  1044.     {
  1045.         // remove all selections, if command was succesfull
  1046.         SetSelection(0);
  1047.     }
  1048. }
  1049.  
  1050. void CMyGridView::OnFormatRemovecover()
  1051. {
  1052.     ROWCOL nRow, nCol;
  1053.  
  1054.     if (GetCurrentCell(&nRow, &nCol))
  1055.     {
  1056.         CGXRange covered;
  1057.  
  1058.         if (GetCoveredCellsRowCol(nRow, nCol, covered))
  1059.         {
  1060.             SetCoveredCellsRowCol(nRow, nCol, nRow, nCol);
  1061.         }
  1062.     }
  1063. }
  1064.  
  1065. void CMyGridView::OnUpdateFormatCovercells(CCmdUI* pCmdUI)
  1066. {
  1067.     if (GetParam() == NULL)
  1068.     {
  1069.         pCmdUI->Enable(FALSE);
  1070.         return;
  1071.     }
  1072.  
  1073.     CGXRangeList* pSelList = GetParam()->GetRangeList();
  1074.  
  1075.     // check if there is a valid selection
  1076.     BOOL b = pSelList->IsEmpty()
  1077.         || !pSelList->GetHead()->IsCells(); /* check if range of cells and not rows or coluns */
  1078.  
  1079.     pCmdUI->Enable(!b);
  1080. }
  1081.  
  1082. void CMyGridView::OnUpdateFormatRemovecover(CCmdUI* pCmdUI)
  1083. {
  1084.     if (GetParam() == NULL)
  1085.     {
  1086.         pCmdUI->Enable(FALSE);
  1087.         return;
  1088.     }
  1089.  
  1090.     ROWCOL nRow, nCol;
  1091.  
  1092.     if (GetCurrentCell(&nRow, &nCol))
  1093.     {
  1094.         CGXRange covered;
  1095.  
  1096.         if (GetCoveredCellsRowCol(nRow, nCol, covered))
  1097.         {
  1098.             pCmdUI->Enable(TRUE);
  1099.             return;
  1100.         }
  1101.     }
  1102.     pCmdUI->Enable(FALSE);
  1103. }
  1104.  
  1105. /////////////////////////////////////////////////////////////////////////////
  1106. // Alignment menu handlers
  1107.  
  1108. void CMyGridView::OnFormatAlignCenter()
  1109. {
  1110.     SetStyle(CGXStyle().SetHorizontalAlignment(DT_CENTER));
  1111. }
  1112.  
  1113. void CMyGridView::OnFormatAlignLeft()
  1114. {
  1115.     SetStyle(CGXStyle().SetHorizontalAlignment(DT_LEFT));
  1116. }
  1117.  
  1118. void CMyGridView::OnFormatAlignRight()
  1119. {
  1120.     SetStyle(CGXStyle().SetHorizontalAlignment(DT_RIGHT));
  1121. }
  1122.  
  1123. void CMyGridView::OnUpdateFormatAlignCenter(CCmdUI* pCmdUI)
  1124. {
  1125.     if (GetParam() == NULL)
  1126.     {
  1127.         pCmdUI->Enable(FALSE);
  1128.         return;
  1129.     }
  1130.  
  1131.     BOOL bCheck = FALSE;
  1132.     pCmdUI->Enable(NeedStyle(CGXStyle().SetHorizontalAlignment(DT_CENTER), bCheck));
  1133.     pCmdUI->SetCheck(bCheck);
  1134. }
  1135.  
  1136. void CMyGridView::OnUpdateFormatAlignLeft(CCmdUI* pCmdUI)
  1137. {
  1138.     if (GetParam() == NULL)
  1139.     {
  1140.         pCmdUI->Enable(FALSE);
  1141.         return;
  1142.     }
  1143.  
  1144.     BOOL bCheck = FALSE;
  1145.     pCmdUI->Enable(NeedStyle(CGXStyle().SetHorizontalAlignment(DT_LEFT), bCheck));
  1146.     pCmdUI->SetCheck(bCheck);
  1147. }
  1148.  
  1149. void CMyGridView::OnUpdateFormatAlignRight(CCmdUI* pCmdUI)
  1150. {
  1151.     if (GetParam() == NULL)
  1152.     {
  1153.         pCmdUI->Enable(FALSE);
  1154.         return;
  1155.     }
  1156.  
  1157.     BOOL bCheck = FALSE;
  1158.     pCmdUI->Enable(NeedStyle(CGXStyle().SetHorizontalAlignment(DT_RIGHT), bCheck));
  1159.     pCmdUI->SetCheck(bCheck);
  1160. }
  1161.  
  1162. /////////////////////////////////////////////////////////////////////////////
  1163. // Style menu handlers
  1164.  
  1165. void CMyGridView::OnFormatStyleBold()
  1166. {
  1167.     BOOL bSet = TRUE;
  1168.     if (NeedStyle(CGXStyle().SetFont(CGXFont().SetBold(TRUE)), bSet))
  1169.         SetStyle(CGXStyle().SetFont(CGXFont().SetBold(!bSet)));
  1170. }
  1171.  
  1172. void CMyGridView::OnFormatStyleItalic()
  1173. {
  1174.     BOOL bSet = TRUE;
  1175.     if (NeedStyle(CGXStyle().SetFont(CGXFont().SetItalic(TRUE)), bSet))
  1176.         SetStyle(CGXStyle().SetFont(CGXFont().SetItalic(!bSet)));
  1177. }
  1178.  
  1179. void CMyGridView::OnFormatStyleUnderline()
  1180. {
  1181.     BOOL bSet = TRUE;
  1182.     if (NeedStyle(CGXStyle().SetFont(CGXFont().SetUnderline(TRUE)), bSet))
  1183.         SetStyle(CGXStyle().SetFont(CGXFont().SetUnderline(!bSet)));
  1184. }
  1185.  
  1186. void CMyGridView::OnUpdateFormatStyleBold(CCmdUI* pCmdUI)
  1187. {
  1188.     if (GetParam() == NULL)
  1189.     {
  1190.         pCmdUI->Enable(FALSE);
  1191.         return;
  1192.     }
  1193.  
  1194.     BOOL bCheck = FALSE;
  1195.     pCmdUI->Enable(NeedStyle(CGXStyle().SetFont(CGXFont().SetBold(TRUE)), bCheck));
  1196.     pCmdUI->SetCheck(bCheck);
  1197. }
  1198.  
  1199. void CMyGridView::OnUpdateFormatStyleItalic(CCmdUI* pCmdUI)
  1200. {
  1201.     if (GetParam() == NULL)
  1202.     {
  1203.         pCmdUI->Enable(FALSE);
  1204.         return;
  1205.     }
  1206.  
  1207.     BOOL bCheck = FALSE;
  1208.     pCmdUI->Enable(NeedStyle(CGXStyle().SetFont(CGXFont().SetItalic(TRUE)), bCheck));
  1209.     pCmdUI->SetCheck(bCheck);
  1210. }
  1211.  
  1212. void CMyGridView::OnUpdateFormatStyleUnderline(CCmdUI* pCmdUI)
  1213. {
  1214.     if (GetParam() == NULL)
  1215.     {
  1216.         pCmdUI->Enable(FALSE);
  1217.         return;
  1218.     }
  1219.  
  1220.     BOOL bCheck = FALSE;
  1221.     pCmdUI->Enable(NeedStyle(CGXStyle().SetFont(CGXFont().SetUnderline(TRUE)), bCheck));
  1222.     pCmdUI->SetCheck(bCheck);
  1223. }
  1224.  
  1225.  
  1226.