[Classes] [Prev] [Next] [Methods]

CUnits, CCentimeterUnits, CCharacterUnits, and CInchUnits

Methods Index

Heritage
Description
Usage
Enums
Output Device
Private Data Members
Mapping values, where: logical * mapping = physical
Development Metrics
Object ownership
Macros
Public Methods
Output Device Methods
Methods for Selecting Development-to-Execution Mappings
Methods for Setting User-Defined Mappings,
Where: Logical * Mapping = Physical
Logical-To-Physical Conversion Methods
Physical-To-Logical Conversion Methods
Static Methods for Global Unit Object Settings
Protected Methods

Classes Derived From CUnits: CCentimeterUnits
Description
Public Methods

Classes Derived From CUnits: CCharacterUnits
Description
Private Data Members
Public Methods
Private Methods

Classes Derived From CUnits: CInchUnits
Description
Public Methods

CUnits,
CCentimeterUnits,
CCharacterUnits, and
CInchUnits


Heritage

Superclass: CNotifier

Subclasses: None


Description

CUnits is a class that allows you to use logical units to define the coordinates on the screen. The use of logical units makes applications more portable because different machines have different screen widths, heights, and resolutions. The logical units are mapped out to the physical device on which you are displaying your information. We use the term "physical device" because the units can be mapped not only to a screen display but also to a printer display. If they are mapped to the screen, the logical units are translated into pixels; if they are mapped to a printer, then the logical units are translated into printer units.


Usage

By default, all XVT-Power++ applications use a one-to-one pixel mapping for drawing or printing. You can set a different mapping-in centimeters, inches, characters, or a user-defined unit-by instantiating a CUnits object and then calling a certain object in the application framework hierarchy and setting its units through its SetUnits method. XVT recommends that you set units only at the window or application level.

CUnits objects are treated just like CEnvironment objects in that objects inherit the units of their enclosures, unless they have their own private units. A view enclosure uses its own units, if it has any, or it inherits the units of its enclosure, which could be a window. A window can either have its own units or use the units of its document. Finally, there is a global CUnits object from which all objects in the application framework hierarchy can inherit.


Enums

Output Device

SCREEN Translate units to screen pixels during execution
PRINTER Translate units to printer pixels during execution


Private Data Members

static const CUnits* itsGlobalUnits; Global units object
OutputDevice itsOutputDevice;

Mapping values, where: logical * mapping = physical

float itsHMapping; Current horizontal mappings
float itsVMapping; Current vertical mappings
float itsHScreenMapping Horizontal screen mappings
float itsVScreenMapping; Vertical screen mappings
float itsHPrinterMapping Horizontal printer mappings
float itsVPrinterMapping; Vertical printer mappings

Development Metrics

int itsScreenWidth,
itsScreenHeight;
int itsHResolution,
itsVResolution;
BOOLEAN itIsMapping; Dynamic device-to-runtime map

Object ownership

CBoss* itsOwner; The object owning the units


Macros

The following macros allow easy specification that a unit is physical. They should be used only within classes derived from CBoss. Each of these macros tests whether an object has any units. If it does, a macro takes the pixels and translates them to logical units.

#define HLogical(thePixels) (itsUnits? \
itsUnits->HPhysicalToLogical(thePixels) : \
thePixels)
#define VLogical(thePixels) (itsUnits? \
itsUnits->VPhysicalToLogical(thePixels) : \
thePixels)
#define HPhysical(theUnits) (itsUnits? \
itsUnits->HLogicalToPhysical(theUnits) : \
int(theUnits))
#define VPhysical(theUnits) (itsUnits? \
itsUnits->VLogicalToPhysical(theUnits) : \
int(theUnits))

Public Methods

CUnits(float theHScreenMapping	= 1.0, 
float theVScreenMapping = 1.0,
float theHPrinterMapping = 1.0,
float theVPrinterMapping = 1.0,
OutputDevice theDevice = SCREEN);
virtual ~CUnits(void);
void SetOwner(CBoss* theOwner);
CBoss* GetOwner(void) const;

Output Device Methods

For the following methods, the screen is the default output device.

void SetOutputDevice(OutputDevice theDevice);
OutputDevice GetOutputDevice(void) const;

Methods for Selecting Development-to-Execution Mappings

void SetDynamicMapping(BOOLEAN isMapping);
BOOLEAN GetDynamicMapping(void) const;
void SetDevelopmentMetrics(int theDeviceWidth, 
int theDeviceHeight, int theHResolution,
int theVResolution);

Methods for Setting User-Defined Mappings,
Where: Logical * Mapping = Physical

void SetScreenMapping(float theHScreenMapping, 
float theVScreenMapping);
void SetPrinterMapping(float theHPrinterMapping, 
float theVPrinterMapping);
float GetHScreenMapping(void) const;
float GetVScreenMapping(void) const;
float GetHPrinterMapping(void) const;
float GetVPrinterMapping(void) const;

Logical-To-Physical Conversion Methods

You can call the following methods when you want to translate a certain logical coordinate to a certain physical coordinate using the specified units.

int HLogicalToPhysical(UNITS theLogicalUnit) const;
int VLogicalToPhysical(UNITS theLogicalUnit) const;
RCT LogicalToPhysical(
UNITS theLeft,
UNITS theTop,
UNITS theRight,
UNITS theBottom) const;
PNT LogicalToPhysical(
UNITS theHPos,
UNITS theVPos) const;

Physical-To-Logical Conversion Methods

UNITS HPhysicalToLogical(int thePhysicalUnit) const;
UNITS VPhysicalToLogical(int thePhysicalUnit) const;
CPoint PhysicalToLogical(const PNT thePnt) const;
CRect PhysicalToLogical(const RCT& theRct) const;

Static Methods for Global Unit Object Settings

static void SetGlobalUnits(const CUnits* theUnits);
static const CUnits* GetGlobalUnits(void) const;

Protected Methods

void UpdateOwner(void);

Classes Derived From CUnits: CCentimeterUnits


Description

CCentimeterUnits calculates all the horizontal and vertical screen/printer mappings so that each unit is a centimeter.


Public Methods

CCentimeterUnits(void);

Classes Derived From CUnits: CCharacterUnits


Description

Given a font, CCharacterUnits calculates the mappings for the average height and width of a character in that font. Mappings are calculated for both the screen and the printer. To calculate the mappings, the environment must be set up for printing. On UNIX Motif/OPEN LOOK, the XVTPATH environment variable must also be set.

When CCharacterUnits calculates the mappings for the average height and width of a character in a font, this becomes the standard unit. For example, if you specify that you want an object to measure three units horizontally, its width is approximately the width of three characters.


Private Data Members

CFont itsFont; The font
static BOOLEAN itNeedsPrinterMapping Flag to determine if units are being used in a print job;
by default, this flag is set to TRUE


Public Methods

CCharacterUnits(const CFont& theBaseFont = STDFont);
void SetBaseFont(const CFont& theBaseFont = STDFont);
const CFont & GetBaseFont(void) const;
static void NeedsPrinterMapping(
BOOLEAN needsMapping);

Private Methods

void GetCharSize(WINDOW theXVTWindow, 
int* theWidth, int* theHeight);

Classes Derived From CUnits: CInchUnits


Description

CInchUnits calculates all the horizontal and vertical screen/printer mappings so that each unit is an inch.


Public Methods

CInchUnits(void);


[Classes] [Prev] [Next] [Methods]

support@xvt.com


Visit our online help desk for tech support

Copyright © 2009, Providence Software Solutions Inc. All rights reserved.