Rogue Wave banner
Previous fileTop of DocumentContentsIndex pageNext file
Objective Grid User's Guide
Rogue Wave web site:  Home Page  |  Main Documentation Page

5.5 Cell and Window Coordinates

Cell and window coordinates are related to each other. It is possible to compute the cell coordinate from a given window point or to compute the window rectangle for a given cell. Hit-Testing is used for determining what is located under a given window coordinate.

5.5.1 Cell Coordinates

The user can scroll the data rows in the view. Column and row headers are fixed at the top and left margins of the window. Optionally, several rows or columns can be frozen so that they never scroll out of the view.

The grid maintains the number of frozen rows and columns and the cell coordinate of the top-left cell. The top-left cell is always located in the first scrollable row and column. All other cell coordinates can be derived from these parameters.

The grid component distinguishes between two coordinate systems:

A characteristic of headers and frozen rows and columns is that both relative and absolute coordinates are the same value:

Figure 45: Relationship between absolute and relative coordinates

The following CGXGridCore methods can be used to determine or convert coordinates:

GetClientRow(), GetClientCol(), GetRow(), GetCol(), GetTopRow(), GetLeftCol(), GetFrozenRows(), and GetFrozenCols().

5.5.2 Window Coordinates

All column widths, row heights, and font heights are specified in pixels. A typical VGA screen has a resolution of 800x600 or 1024x768 pixels. A printer normally has a considerably higher resolution. To avoid generating much smaller output when printing versus drawing to the screen, Windows uses a technique called coordinate mapping. Objective Grid uses coordinate mapping extensively with its device context.

5.5.2.1 Device Context

All drawing operations in Microsoft Windows are done through a device context that contains information about the coordinate mapping and drawing attributes, such as font and color. The grid component initializes the mapping mode with 72 pixels per inch for printer output. This is the same value used for screen output. Thus, the developer does not have to consider whether the grid is being displayed to a printer or to the screen when drawing. The coordinate mapping mode for the device context is initialized in CGXGridCore::OnPrepareDC().

5.5.2.2 Row Heights and Column Widths

Row heights are determined with the overridable method CGXGridCore::GetRowHeight(). Column widths are determined with CGXGridCore::GetColWidth().

Row and column widths are stored internally as logical values. This makes it possible to adapt these values to a change of the zooming factor or standard font size. The following methods in the grid component perform these conversions: CGXGridCore::Height_LPtoDP() and CGXGridCore::Width_LPtoDP() convert logical values to pixel values. CGXGridCore::Height_DPtoLP() and CGXGridCore::Width_DPtoLP() convert pixel values to logical values.

Furthermore, GetRowHeight() and GetColWidth() call the overridable method CGXGridcore::IsRowVisible() or CGXGridCore::IsColVisible() to determine if the specified row or column is visible. In a splitter window, for example, the row headers of the right pane are not visible.

5.5.2.3 Converting Between Cell and Window Coordinates

It is possible to compute the window rectangle for a given cell because the height and width for each row and column is known. Conversely, it is also possible to determine the cell displayed at a given point.

The following CGXGridCore methods perform the necessary calculations:

CalcClientColFromPt()
CalcClientRowFromPt()
CalcRectFromRowCol()
CalcRectFromRowColEx()
CalcSumOfColWidths()
CalcSumOfClientColWidths()
CalcSumOfRowHeights()
CalcSumOfClientRowHeights()
GetGridRect()
SetGridRect()

5.5.3 Hit-Testing

Hit-testing is used to determine what is located under a given window coordinate. The method CGXGridCore::HitTest() computes a hit value for a given point.

The following hit values are defined:

One use of HitTest() is for a context-sensitive mouse cursor. Whenever the mouse is moved, the grid calls HitTest() and changes the mouse cursor as necessary.


GetRowCount() and GetColCount() are used extensively to validate values within routines. In addition, because HitTest() is called repeatedly on every mouse move and because this method touches a lot of grid code, including GetRowCount(), it is not unusual for GetRowCount() to be called thousands of times in a short period of time. Because GetRowCount() and GetColCount() are called quite often, your overrides of these methods are not an appropriate place to do extensive calculation.



Previous fileTop of DocumentContentsNo linkNext file

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.