home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Chip 1997 October
/
Chip_1997-10_cd.bin
/
tema
/
sybase
/
powerj
/
hpp.z
/
WCANVAS.HPP
< prev
next >
Wrap
C/C++ Source or Header
|
1997-01-24
|
28KB
|
881 lines
/*************************************************************************
*
* WCanvas
*
*************************************************************************/
#ifndef _WCANVAS_HPP_INCLUDED
#define _WCANVAS_HPP_INCLUDED
#ifndef _WNO_PRAGMA_PUSH
#pragma pack(push,8);
#pragma enum int;
#endif
#ifndef _WPOINT_HPP_INCLUDED
# include "wpoint.hpp"
#endif
#ifndef _WRECT_HPP_INCLUDED
# include "wrect.hpp"
#endif
#ifndef _WREGION_HPP_INCLUDED
# include "wregion.hpp"
#endif
class WFont;
class WBrush;
class WPalette;
class WColor;
class WPen;
class WBitmap;
class WIcon;
class WCursor;
class WWindow;
class WPrinterData;
#ifndef _WIN16
#undef TextOut
#undef DrawText
#undef GetTextMetrics
#if defined( _UNICODE )
#define TextOut TextOutW
#define DrawText DrawTextW
#define GetTextMetrics GetTextMetricsW
#else
#define TextOut TextOutA
#define DrawText DrawTextA
#define GetTextMetrics GetTextMetricsA
#endif
#endif
#define WROPBlackness ((WULong)0x00000042L)
#define WROPWhiteness ((WULong)0x00FF0062L)
#define WROPCopySource ((WULong)0x00CC0020L)
#define WROPPaintSource ((WULong)0x00EE0086L)
#define WROPEraseSource ((WULong)0x00440328L)
#define WROPInvertSource ((WULong)0x00660046L)
#define WROPCombineSource ((WULong)0x008800C6L)
#define WROPCopySourceAndInvert ((WULong)0x00330008L)
#define WROPEraseSourceAndInvert ((WULong)0x001100A6L)
#define WTextAlignBaseline ((WULong)0x00000018L)
#define WTextAlignBottom ((WULong)0x00000008L)
#define WTextAlignTop ((WULong)0x00000000L)
#define WTextAlignCenter ((WULong)0x00000006L)
#define WTextAlignLeft ((WULong)0x00000000L)
#define WTextAlignRight ((WULong)0x00000002L)
#define WTextAlignRTLReading ((WULong)0x00000100L)
#define WTextAlignRightToLeftReading ((WULong)0x00000100L)
#define WTextAlignNoUpdateCP ((WULong)0x00000000L)
#define WTextAlignNoUpdateCurrentPos ((WULong)0x00000000L)
#define WTextAlignUpdateCP ((WULong)0x00000001L)
#define WTextAlignUpdateCurrentPos ((WULong)0x00000001L)
#define WDrawOptionOpaque 0x0002
#define WDrawOptionClipped 0x0004
#define WDrawOptionGlyphIndex 0x0010
#define WDrawOptionRightToLeftReading 0x0080
enum WCBackgroundMode {
WCBMTransparent = 1,
WCBMOpaque = 2,
};
enum WCMappingMode {
WCMMError = 0,
WCMMText = 1, WCMMPixels = WCMMText,
WCMMLoMetric = 2,
WCMMHiMetric = 3,
WCMMLoEnglish = 4,
WCMMHiEnglish = 5,
WCMMTwips = 6,
WCMMIsotropic = 7,
WCMMAnisotropic = 8
};
enum WCanvasCapabilities {
WCCHorizontalMM = 4, // millimeters
WCCVerticalMM = 6, // millimeters
WCCHorizontalPixels = 8,
WCCVerticalPixels = 10,
WCCLogicalPixelsX = 88,
WCCLogicalPixelsY = 90,
};
enum WFloodFillTypes {
WFFBorder = 0,
WFFSurface = 1
};
enum WForeMixMode {
WFMMBlack = 1,
WFMMNotMergePen = 2,
WFMMMAskNotPen = 3,
WFMMNotCopyPen = 4,
WFMMMaskPenNot = 5,
WFMMNot = 6,
WFMMXorPen = 7,
WFMMNotMaskPen = 8,
WFMMMaskPen = 9,
WFMMNororPen = 10,
WFMMNop = 11,
WFMMMergeNorPen = 12,
WFMMCopyPen = 13,
WFMMMergePenNot = 14,
WFMMMergePen = 15,
WFMMWhite = 16,
WFMMLast = 16,
};
enum WArcDirection {
WADCounterClockWise = 1,
WADClockWise = 2,
};
#define WDrawTextTop ((WULong)0x00000000)
#define WDrawTextLeft ((WULong)0x00000000)
#define WDrawTextCenter ((WULong)0x00000001)
#define WDrawTextRight ((WULong)0x00000002)
#define WDrawTextVCenter ((WULong)0x00000004)
#define WDrawTextBottom ((WULong)0x00000008)
#define WDrawTextWordBreak ((WULong)0x00000010)
#define WDrawTextSingleLine ((WULong)0x00000020)
#define WDrawTextExpandTabs ((WULong)0x00000040)
#define WDrawTextTabStop ((WULong)0x00000080)
#define WDrawTextNoClip ((WULong)0x00000100)
#define WDrawTextExternalLeading ((WULong)0x00000200)
#define WDrawTextCalcRect ((WULong)0x00000400)
#define WDrawTextNoPrefix ((WULong)0x00000800)
#define WDrawTextEditControl ((WULong)0x00002000)
#define WDrawTextPathEllipsis ((WULong)0x00004000)
#define WDrawTextEndEllipsis ((WULong)0x00008000)
#define WDrawTextModifyString ((WULong)0x00010000)
#define WDrawTextRTLReading ((WULong)0x00020000)
#define WDrawTextWordEllipsis ((WULong)0x00040000)
#define WDrawTextDefault ((WULong)0x00000800)
#define WDrawIconCompat 0x0004
#define WDrawIconDefaultSize 0x0008
#define WDrawIconImage 0x0002
#define WDrawIconMask 0x0001
#define WDrawIconNormal 0x0003
#define WDrawCursorCompat WDrawIconCompat
#define WDrawCursorDefaultSize WDrawIconDefaultSize
#define WDrawCursorImage WDrawIconImage
#define WDrawCursorMask WDrawIconMask
#define WDrawCursorNormal WDrawIconNormal
class WCanvasReference; // internal use only
//
// TextMetrics -- Use to obtain information on a selected font.
//
struct WTextMetrics {
WLong height;
WLong ascent;
WLong descent;
WLong internalLeading;
WLong externalLeading;
WLong averageWidth;
WLong maximumWidth;
};
//
// WInfoCanvas
//
#pragma warning 849 9
class WCMCLASS WInfoCanvas : public WObject {
WDeclareSubclass( WInfoCanvas, WObject );
public:
/**********************************************************
* Constructors and Destructors
*********************************************************/
WInfoCanvas();
WInfoCanvas( const WInfoCanvas & canvas );
WInfoCanvas( WDeviceHandle dev, WBool deleteHandle=FALSE );
WInfoCanvas( const WChar *driverName, const WChar *deviceName,
const void *deviceData );
~WInfoCanvas();
WInfoCanvas& operator=( const WInfoCanvas & ic );
/**********************************************************
* Properties
*********************************************************/
// Handle
//
// Returns the low-level HDC that corresponds to the canvas.
WDeviceHandle GetHandle() const;
// Size
//
// Returns a rectangle representing the size (in pixels)
// of the canvas, with top & left always set to 0.
WRect GetSize() const;
/**********************************************************
* Methods
*********************************************************/
// Clear
virtual void Clear();
// Create
virtual WBool Create( const WInfoCanvas & canvas );
virtual WBool Create( WDeviceHandle dev, WBool deleteHandle=FALSE );
virtual WBool Create( const WChar * driverName,
const WChar * deviceName,
const void * deviceData );
// QueryCapability
//
// Query the capabilities the device has.
WInt QueryCapability( WCanvasCapabilities capability ) const;
/**********************************************************
* Static Methods
*********************************************************/
// IsValidHandle
//
// Returns TRUE if the given handle is valid.
static WBool IsValidHandle( WDeviceHandle handle,
WBool nullValid=FALSE );
/**********************************************************
* Private
*********************************************************/
protected:
WCanvasReference *_ref;
};
//
// WCanvas
//
class WCMCLASS WCanvas : public WInfoCanvas {
WDeclareSubclass( WCanvas, WInfoCanvas );
public:
/**********************************************************
* Constructors and Destructors
*********************************************************/
WCanvas();
WCanvas( WDeviceHandle dev, WBool deleteHandle=FALSE );
WCanvas( const WChar *driverName, const WChar *deviceName,
const void *deviceData );
WCanvas( const WCanvas & canvas, WBool makeMemoryDC=FALSE );
~WCanvas();
WCanvas& operator=( const WCanvas & c );
/**********************************************************
* Properties
*********************************************************/
// ArcDirection
//
// The drawing direction to be used for arc and rectangle
// functions
WBool SetArcDirection( WArcDirection direction );
WArcDirection GetArcDirection();
// BackColor
//
// Set the background color for drawing.
WBool SetBackColor( const WColor & color );
WColor GetBackColor() const;
// BackMode
//
// Set/get the background drawing mode.
WBool SetBackMode( WCBackgroundMode mode );
WCBackgroundMode GetBackMode() const;
// Bitmap
//
// Set/get the bitmap associated with a canvas.
WBool SetBitmap( const WBitmap & newBitmap );
WBitmap GetBitmap() const;
// Brush
//
// Set/get the brush associated with a canvas.
WBool SetBrush( const WBrush & newBrush );
WBrush GetBrush() const;
// ClippingRectangle
//
// Returns the current clipping rectangle.
WRect GetClippingRectangle() const;
WBool SetClippingRectangle( const WRect & r );
// DrawPosition
//
// The current position of the pen.
WBool SetDrawPosition( const WPoint & point );
WPoint GetDrawPosition() const;
// Font
//
// Set/get the font associated with a canvas.
WBool SetFont( const WFont & newFont );
WFont GetFont() const;
// ForeMixMode
//
// The current foreground mix mode
WBool SetForeMixMode( WForeMixMode mode );
WForeMixMode GetForeMixMode();
// MappingMode
//
// Set/get the mapping mode for the canvas.
WCMappingMode GetMappingMode() const;
WBool SetMappingMode( WCMappingMode mode );
// Palette
//
// Set/get the palette associated with a canvas.
// Choose forceBackground=TRUE when RealizePalette is to
// map the logical palette to the physical palette (in the
// best possible way).
WBool SetPalette( const WPalette & newPalette,
WBool forceBackground=FALSE );
WPalette GetPalette() const;
// Pen
//
// Set/get the pen associated with a canvas.
WBool SetPen( const WPen & newPen );
WPen GetPen() const;
// PolygonFillMode
//
// Set/get the polygon fill mode
WBool SetPolygonFillMode( WPolygonFillMode mode );
WPolygonFillMode GetPolygonFillMode() const;
// TextAlignment
//
// The text alignment.
WBool SetTextAlignment( WULong flags );
WULong GetTextAlignment() const;
// TextColor
//
// The text color for drawing.
WBool SetTextColor( const WColor & color );
WColor GetTextColor() const;
// TextMetrics
//
// Returns metrics of the currently-selected font.
WTextMetrics GetTextMetrics() const;
/**********************************************************
* Methods
*********************************************************/
// CalculateTextRectangle
WBool CalculateTextRectangle( WRect & r, const WChar *text,
WInt numChars=-1 );
// CalculateWrapLength
//
// Given a width and a string, determines how many
// characters in that string will fit in the width.
// Also optinally fills in an array of text extents
// for each character, up to the # of characters that
// will fit.
WInt CalculateWrapLength( WInt width, const WChar *text,
WInt numChars=-1, WInt *extents=NULL );
// Clear
//
// This clears (release or destroys) the HDC that
// for the canvas.
virtual void Clear();
// Create
virtual WBool Create( const WInfoCanvas & canvas );
virtual WBool Create( WDeviceHandle dev, WBool deleteHandle=FALSE );
virtual WBool Create( const WChar * driverName,
const WChar * deviceName,
const void * deviceData );
virtual WBool Create( const WCanvas & canvas,
WBool makeMemoryDC=FALSE );
// DrawArc
//
// Draws an elliptical arc
WBool DrawArc( const WRect & boundingRect, const WPoint & radial1end,
const WPoint & radial2end,
WBool useCurrentPosition=TRUE );
// DrawBezierCurves
//
// Draws a series of Bezier curves
WBool DrawBezierCurves( WPoint * pointArray, WInt numPoints,
WBool useCurrentPosition=TRUE );
// DrawBitmap
//
// Draws a bitmap,
WBool DrawBitmap( const WBitmap & bitmap, const WRect & dest,
WBool stretch=TRUE, WULong rop=WROPCopySource );
WBool DrawBitmap( const WBitmap & bitmap, const WRect & dest,
const WRect & src, WBool stretch=TRUE,
WULong rop=WROPCopySource );
// DrawChord
//
// Draws a chord (a region bounded by the intersection of an
// ellipse and a line segment)
WBool DrawChord( const WRect & boundingRect,
const WPoint & radial1end,
const WPoint & radial2end );
// DrawEllipse
//
// Draws an ellipse centered on the given rectangle.
WBool DrawEllipse( const WRect & r, WBool fill=TRUE );
// DrawFromCanvas
//
// Draws the contents of another canvas into this canvas.
WBool DrawFromCanvas( const WRect & destination,
const WCanvas & sourceCanvas,
WULong rop=WROPCopySource );
WBool DrawFromCanvas( const WRect & destination,
const WPoint & source,
const WCanvas & sourceCanvas,
WULong rop=WROPCopySource );
WBool DrawFromCanvas( const WRect & destination,
const WRect & source,
const WCanvas & sourceCanvas,
WULong rop=WROPCopySource,
WBool stretch=FALSE );
// DrawFocusRectangle
//
// Draws a focus rectangle. Call it a second time to
// erase it.
WBool DrawFocusRectangle( const WRect & r );
// DrawIcon
//
// Draws an icon.
WBool DrawIcon( const WIcon & icon, const WPoint & loc );
WBool DrawIcon( const WIcon & icon, const WPoint & loc,
const WSize & size, WULong flags=WDrawIconNormal,
const WBrush *brush=NULL, WULong index=0 );
// DrawCursor
//
// Draws an cursor.
WBool DrawCursor( const WCursor & cursor, const WPoint & loc );
WBool DrawCursor( const WCursor & cursor, const WPoint & loc,
const WSize & size, WULong flags=WDrawCursorNormal,
const WBrush *brush=NULL, WULong index=0 );
// DrawLine
//
// Draws a line from the current/given position to the given
// point. Moves the current point.
WBool DrawLine( const WPoint & endPoint );
WBool DrawLine( const WPoint & startPoint, const WPoint & endPoint );
// DrawLines
//
// Draws a series of line segments
WBool DrawLines( WPoint * pointArray, WInt numPoints,
WBool useCurrentPosition=TRUE );
// DrawPolygons
//
// Draw a series of closed polygons
WBool DrawPolygons( WPoint * pointArray, WInt * vertexCountArray,
WInt numPolygons );
// DrawPie
//
// Draws a pie piece.
WBool DrawPie( const WRect & rect, const WPoint & firstRadial,
const WPoint & secondRadial );
// DrawPolygon
//
// Draws a polygon.
WBool DrawPolygon( WPoint * pointArray, WInt numPoints );
// DrawRectangle
//
// Draws a rectangle. The outline is drawn with the current
// pen, the inside is filled with the current brush if
// fill is true.
WBool DrawRectangle( const WRect & rect, WBool fill=TRUE );
// DrawRoundRectangle
//
// Like DrawRectangle, but draws round corners.
WBool DrawRoundRectangle( const WRect & rect, WInt cornerWidth,
WInt cornerHeight, WBool fill=TRUE );
// DrawText
//
// Draws text. The first form calls TextOut to draw a line
// of text. The second calls DrawTextEx to draw a line
// or lines. The third calls API DrawText. The forth call
// ExtTextOut. In all cases if you pass an outputRect
// as the last parameter, no drawing is done, but instead
// the size of the drawn text is calculated.
WBool DrawText( const WChar *string, WInt numChars=-1,
WRect *outputRect=NULL, WInt space = 0);
WBool DrawText( const WPoint & pt, const WChar *string,
WInt numChars=-1,
WRect *outputRect=NULL, WInt space = 0);
WBool DrawText( const WRect & rect, const WChar *string,
WInt numChars=-1, WULong flags=WDrawTextDefault,
WRect *outputRect=NULL );
WBool DrawText( const WPoint & pt, const WChar *string,
WInt numChars, WUInt drawOptions,
WRect clippingRect, WIntArray * spacing,
WRect *outputRect=NULL);
// FillRectangle
//
// Fill the given rectangle. If no brush is given, uses
// the current brush setting.
WBool FillRectangle( const WRect & rect,
const WBrush * useBrush=NULL );
// FillRegion
//
// Fill the given region. If no brush is given, uses
// the current brush setting.
WBool FillRegion( const WRegion & region,
const WBrush * useBrush=NULL );
// FloodFill
WBool FloodFill( const WPoint & start, const WColor & borderColor,
WFloodFillTypes type=WFFBorder );
// FrameRectangle
//
// Draws border around specified rectangle using brush, 1 unit wide
WBool FrameRectangle( const WRect & rect, const WBrush * brush=NULL );
// FrameRegion
//
// Frame the given region. If no brush is given, uses
// the current brush setting.
WBool FrameRegion( const WRegion & region,
const WBrush * useBrush=NULL,
WInt width=1, WInt height=1 );
// InvertRectangle
//
// Inverts a rectangle by performing a logical NOT operation
WBool InvertRectangle( const WRect & rect );
// InvertRegion
WBool InvertRegion( const WRegion & region );
// PaintRegion
//
// Uses the current brush setting
WBool PaintRegion( const WRegion & region );
// RealizePalette
WInt RealizePalette();
// Reset
//
// Resets the canvas to its original state, optionally
// popping the stack of saved states.
WBool Reset( WBool popStack=TRUE );
// Restore
//
// Restores the canvas to a previously-saved state.
WBool Restore( WInt stateIndex );
// Save
//
// Saves the canvas state. If return value is 0,
// failed, otherwise it's the state index.
WInt Save();
// UpdateColors
WBool UpdateColors();
/**********************************************************
* Item Properties
*********************************************************/
// SetPixel/GetPixel
//
// Get or set the colour of a given pixel location
//
// Note: GetPixel() will not always work for an arbitrary location,
// even if the point is within the bounds of your DC. It will only
// work if the point being retrieved is inside the clipping
// region. Also note that you can only make the clipping region
// SMALLER than the current clipping region.
// See MS Knowledge base PSS ID #: Q119472 for more info.
WBool SetPixel( WPoint loc, WColor &color,
WBool useClosestColor = FALSE );
WColor GetPixel( WPoint loc );
/**********************************************************
* Private
*********************************************************/
protected:
};
//
// WDisplayCanvas
//
class WCMCLASS WDisplayCanvas : public WCanvas {
WDeclareSubclass( WDisplayCanvas, WCanvas );
public:
/**********************************************************
* Constructors and Destructors
*********************************************************/
WDisplayCanvas();
WDisplayCanvas( const WDisplayCanvas & canvas );
WDisplayCanvas( WDeviceHandle dev, WBool deleteHandle=FALSE,
const WWindow *window=NULL );
WDisplayCanvas( const WChar *driverName, const WChar *deviceName,
const void *deviceData );
WDisplayCanvas( const WWindow *window, WBool inPaint=FALSE,
WBool nonClient=FALSE );
~WDisplayCanvas();
WDisplayCanvas& operator=( const WDisplayCanvas & c );
/**********************************************************
* Methods
*********************************************************/
// Clear
virtual void Clear();
// Create
virtual WBool Create( const WDisplayCanvas & canvas );
virtual WBool Create( WDeviceHandle dev, WBool deleteHandle=FALSE,
const WWindow * window=NULL );
virtual WBool Create( const WChar * driverName,
const WChar * deviceName,
const void * deviceData );
virtual WBool Create( const WWindow * window, WBool inPaint=FALSE,
WBool nonClient=FALSE );
/**********************************************************
* Private
*********************************************************/
protected:
const WWindow *_window;
};
//
// WPrinterCanvas
//
class WCMCLASS WPrinterCanvas : public WCanvas {
WDeclareSubclass( WPrinterCanvas, WCanvas );
public:
/**********************************************************
* Constructors and Destructors
*********************************************************/
WPrinterCanvas();
WPrinterCanvas( const WPrinterCanvas & canvas );
WPrinterCanvas( WDeviceHandle dev, WBool deleteHandle=FALSE );
WPrinterCanvas( const WChar *driverName, const WChar *deviceName,
const void *deviceData );
WPrinterCanvas( const WPrinterData & printerData );
~WPrinterCanvas();
WPrinterCanvas& operator=( const WPrinterCanvas & c );
/**********************************************************
* Properties
*********************************************************/
// JobID
//
// Returns the current job ID if a document is being
// printed.
WInt GetJobID() const;
// PageNumber
//
// Returns the current page number if a document is
// being printed.
WInt GetPageNumber() const;
/**********************************************************
* Methods
*********************************************************/
// AbortDocument
WBool AbortDocument();
// Clear
virtual void Clear();
// Create
virtual WBool Create( const WPrinterCanvas & canvas );
virtual WBool Create( WDeviceHandle dev, WBool deleteHandle=FALSE );
virtual WBool Create( const WChar * driverName,
const WChar * deviceName,
const void * deviceData );
virtual WBool Create( const WPrinterData & printerData );
// EndDocument
//
// Finish spooling the document.
WBool EndDocument();
// EndPage
//
// Finish spooling a page.
WBool EndPage();
// StartDocument
//
// Prepare a new document for printing. If this is called
// while still printing a document, the current document
// is ended first.
WBool StartDocument( const WChar *documentName=NULL,
const WChar *printToFilePath=NULL );
// StartPage
//
// Prepare a page for printing. If this is called while
// still printing a page, the current page is ended first.
// By default the canvas state is saved across pages.
WBool StartPage( WBool saveState=TRUE );
/**********************************************************
* Private
*********************************************************/
private:
WBool _printingPage;
WInt _jobID;
WInt _pageNumber;
};
#pragma warning 849 1
#ifdef _DEBUG
#define W_ISCANVASHANDLE(h) CHECKGDI(WInfoCanvas::IsValidHandle((WDeviceHandle)h))
#else
#define W_ISCANVASHANDLE(h)
#endif
#ifndef _WNO_PRAGMA_PUSH
#pragma enum pop;
#pragma pack(pop);
#endif
#endif // _WCANVAS_HPP_INCLUDED