CGXDrawingAndFormatting encapsulates some general methods used for drawing and formatting text in Objective Grid. In earlier versions, these methods were global methods. The disadvantage was that there was no possibility for you to customize these methods without modifying the source code.
The CGXDrawingAndFormatting class gives you the ability to override the default behavior of these methods.
If you have derived a class from CGXDrawingAndFormatting you can force Objective Grid to use your customized methods by calling SetDaFTools().
class CMyDrawingTools: public CGXDrawingAndFormatting { public: CMyDrawingTools(); virtual CString GXFormatText(const CGXStyle& style, LPCTSTR pszValue = NULL, unsigned nValueType = GX_VT_STRING, CGXGridCore* pGrid = NULL, CGXControl* pControl = NULL); }; // in your InitInstance method GXInit(); GXSetDaFTools(new CMyDrawingTools); |
where CMyDrawingTools must be derived from CGXDrawingAndFormatting.
// Text routines virtual int GXDrawTextLikeMultiLineEdit(CDC* pDC, LPCTSTR lpszString, int nCount, CRect rect, UINT nFormat, LPRECT lpRectClip = NULL); virtual int GXDrawRotatedText(CDC* pDC, LPCTSTR lpszString, int nCount, CRect rect, UINT nFormat, LONG lfOrientation, LPRECT lpRectClip = NULL); virtual int GXGetMultiLineTextPosUnderPt(CDC* pDC, LPCTSTR lpszString, int nCount, CRect rect, UINT nFormat, CPoint pt); virtual int GXGetMultiLineTextBreakCount(CDC* pDC, LPCTSTR lpszString, int nCount, CRect rc, UINT nFormat); virtual int GXComputeLineBreaks(CDC* pDC, LPCTSTR sz, int nCount, LPRECT rc, UINT nFormat, int* LineBreaks, int* LineLengths, int nMaxBreaks); // Text formatting and parsing virtual CString GXFormatText(const CGXStyle& style, LPCTSTR pszValue = NULL, unsigned nValueType = GX_VT_STRING, CGXGridCore* pGrid = NULL, CGXControl* pControl = NULL); virtual BOOL GXDeval(LPCTSTR s, double *d, unsigned* pImportFormat = NULL, unsigned* pImportPlaces = NULL); |
See "Macros And Globals" in the Objective Grid Class Reference for a description of these methods.
To enable IntelliMouse Support for Objective Grid, you should add a call to EnableIntelliMouse() before calling OnGridInitialUpdate() or Initialize().
The IntelliMouse support in Objective Grid is very similar to the IntelliMouse support in Microsoft Excel and Microsoft Internet Explorer. Objective Grid supports the following features:
Scrolling by rolling the mouse wheel
Scroll horizontally by clicking SHIFT and rolling the mouse wheel
Zoom in and out by clicking CTRL and rolling the mouse wheel
Auto scrolling by clicking the mouse wheel button and dragging the mouse up, down, to the left or right.
ClickLock for the mouse wheel button: Just click and hold down the mouse wheel button for a moment and your click is locked. With ClickLock you can scroll the grid very easy by simply dragging the mouse (just as with Autoscroll but you don't have to hold the mouse wheel button down). Click again to release ClickLock.
void CMyGridView::OnInitialUpdate() { CGXGridView::OnInitialUpdate(); EnableIntelliMouse(); } BOOL CSample4Dialog::OnInitDialog() { CDialog::OnInitDialog(); GetGridWnd()->EnableFormulaEngine(); GetGridWnd()->Initialize(); GetGridWnd()->SetRowCount(25); GetGridWnd()->SetColCount(52); GetGridWnd()->SetCurrentCell(1,1); GetGridWnd()->EnableIntelliMouse(); GetGridWnd()->SetFocus(); return FALSE; // return TRUE unless you set the // focus to a control } |
To display rotated text in a cell, use CGXFont::SetOrientation() and specify the angle.
SetCoveredCellsRowCol(400, 1, 402, 1); SetStyleRange(CGXRange(400, 1), CGXStyle() .SetFont(CGXFont() .SetSize(12) .SetBold(TRUE) .SetOrientation(-900) ) .SetValue(_T("TEST")) ); |
Please note that only single lines are support for rotated text. Objective Grid does not support word-break with rotated text.
It is possible to add support for rotated text in the font page by adding a combo box with style set to "Simple" to the IDD_DIALOG_FONTPAGE template. When you specify IDC_GXCBORIENTATION as the resource ID for this combo box, the font page will allow the user to specify the font orientation via the combo box.
Objective Grid has support for different character sets. You can assign a specific character set to a cell via SetFaceName().
SetFaceName("Arial"); // Default charset will be used SetFaceName("Arial (Western)"); // Western charset will be used SetFaceName("Arial (Cyrillic)"); // Cyrillic charset will be used |
You can also specify if the character set should be displayed in the font page of the stylesheet by setting
GXGetAppData()->m_bDisplayFontCharset = TRUE; |
The default is FALSE (character sets will not be displayed in the font page).
Enabling Japanese in ANSI-DBCS Grid build types using the Japanese locale may require following workaround:
LOGFONT logFont; SystemParametersInfo(SPI_GETICONTITLELOGFONT,sizeof(logFont),&logFont,0); CGXFont gxFont(logFont); CGXFontInfo* pFontInfo = GXGetFontState()->GetFontInfo(gxFont.GetFaceNameId()); pFontInfo->nCharSet = logFont.lfCharSet; pFontInfo->lfPitchAndFamily = logFont.lfPitchAndFamily; gxFont.SetSize(12); gxFont.SetBold(TRUE); SetStyleRange( CGXRange(1,1), CGXStyle().SetFont(CGXFont(gxFont))); |
The CGXGridCore::CopyCells() and CGXGridCore::MoveCells() APIs lets you easily copy or move a given range of cells to a new destination.
You can also force CGXGridCore to use these new commands for doing Copy/Paste and OLE drag & drop commands within a worksheet by setting the m_bDirectCopyPaste and m_bDirectCutPaste attributes in the CGXGridParam object.
m_bDirectCopyPaste — Set this to TRUE if data should be copied within the grid with the CopyCells() method, and not using the clipboard. Set it to FALSE if conventional clipboard copy/paste should be used.
m_bDirectCutPaste — Set this to TRUE if data should be moved within the grid with the MoveCells() method, and not using the clipboard. When cutting cells, cells will only be marked as cut, and are cleared only when the user executes a Paste command. If m_bDirectCutPaste is FALSE, the conventional clipboard cut/paste will be used.
m_bDirectDragDrop — Set this to TRUE if data should be copied or moved with CopyCells() or MoveCells(), or to FALSE if conventional clipboard cut/copy/paste should be used.
When using direct cut and paste, cell values will not be cleared until you paste data into the same worksheet. When you select cells and then select the menu item Edit|Cut, the selected cells will be marked with a gray background. This indicates that the cells will be cleared once the paste operation is completed.
When you click on a scrollbar or if you press an arrow key, scrolling will accelerate incrementally. Also, when dragging the mouse out of the grid, autoscrolling will accelerate incrementally. The user can slow down the scrolling speed by moving the mouse nearer to the grid or speed up the scrolling by moving the mouse farther away from the grid.
Scrolling when the user drags the mouse out of the grid (with the left button pressed) is controlled with SetAutoScroll().
Acceleration of the scrolling when the user holds down an arrow key is controlled with SetAccelArrowKey().
Acceleration of the scrolling when the user presses a scrollbar button is controlled with SetAccelScrollbars().
To add OLE Drag and Drop support to your grid, simply:
Add a call to EnableOleDropTarget() and a call to EnableOleDataSource() during initialization for your grid object (usually in your override of CDialog::OnInitDialog() or CView::OnInitialUpdate()).
If you want to customize the OLE Drag and Drop behavior, you can pass a combination of flags as the parameter.
EnableOleDropTarget(GX_DNDEGDESCROLL | GX_DNDAUTOSCROLL | GX_DNDTEXT | GX_DNDSTYLES); |
Add a call to AfxOleInit() in your project's override of CWinApp::InitInstance().
A popular Excel feature allows users to copy (but not move) values by dragging with the mouse while holding down the Ctrl key. To enable this functionality in your grid:
Enable OLE Drag and Drop.
Add the OnGridDragOver() override shown below.
// in .h file virtual DROPEFFECT OnGridDragOver(CGXNoOleDataObjectProxy* pDataObject, DWORD dwKeyState, CPoint point); //in .cpp file DROPEFFECT C1stGridView::OnGridDragOver(CGXNoOleDataObjectProxy* pDataObject,DWORD dwKeyState, CPoint point) { return CGXGridView::OnGridDragOver(pDataObject,MK_CONTROL, point); } |
This technique is shown in the sample located at <stingray-installdir>\Samples\Grid\Tutorial\1stGrid\Step3.
Before Objective Grid 6.1, the programmer had to override the WM_VSCROLL and WM_HSCROLL messages. With Objective Grid 6.1 and later, you only need to call:
EnableScrollTips(); |
during the initialization for your grid object. This will enable the display of the row and column number when the user is dragging the scrollbar thumb.
However, if you want to customize the text displayed in the scroll tips, you need to use the old approach instead. Embed a CGXScrollTip object into your derived class and forward WM_VSCROLL and WM_HSCROLL messages to the CGXScrollTip object.
You can enable cell tips by calling EnableCellTips()during initialization for the grid object. Cell tips are implemented using Objective Grid's plug-in classes. They are essentially fly-by windows that appear when the following conditions are met:
The cell's text is truncated (either horizontally or vertically)
The mouse pointer has hovered over the cell for a specified amount of time
The cell's WrapText (Word break) setting is FALSE (disabled)
A similar feature can be seen in Visual Studio Solution Explorer window or in the Windows Explorer tree view.
Copyright © Rogue Wave Software, Inc. All Rights Reserved.
The Rogue Wave name and logo, and Stingray, are registered trademarks of Rogue Wave Software. All other trademarks are the property of their respective owners.
Provide feedback to Rogue Wave about its documentation.