OWLNext    7.0
Borland's Object Windows Library for the modern age
Loading...
Searching...
No Matches
preview.h
Go to the documentation of this file.
1//----------------------------------------------------------------------------
2// ObjectWindows
3// Copyright (c) 1992, 1996 by Borland International, All Rights Reserved
4//
5/// \file
6/// Definition of print preview classes
7//----------------------------------------------------------------------------
8
9#if !defined(OWL_PREVIEW_H)
10#define OWL_PREVIEW_H
11
12#include <owl/private/defs.h>
13#if defined(BI_HAS_PRAGMA_ONCE)
14# pragma once
15#endif
16
17#include <owl/window.h>
18#include <owl/dc.h>
19
20
21namespace owl {
22
23#include <owl/preclass.h>
24
25class _OWLCLASS TPrintout;
26class _OWLCLASS TPrinter;
27
28/// \addtogroup print
29/// @{
30/// \class TPreviewPage
31// ~~~~~ ~~~~~~~~~~~~
32/// TPreviewPage encapsulates a window which displays print-preview data.
33/// It provides access to the basic information necessary to paint
34/// print-preview data: i.e. the printer's DC.
35//
36/// TPreviewPage displays a page of a document in a print preview window. To obtain
37/// the information needed to display the page, TPreviewPage interacts with
38/// TPrintPreviewDC and TPrintout. Specifically, it creates a TPrintPreviewDC from
39/// the window DC provided in Paint and passes that TPrintPreviewDC object to
40/// TPrintout's SetPrintParams member function. The sample program PRINT.CPP
41/// displays the following print preview window:
42/// \image html bm243.BMP
43//
45 public:
46 TPreviewPage(TWindow* parent,
47 TPrintout& printout,
50 int pagenum = 1);
51
52 void SetPageNumber(int newNum);
53 int GetPageNumber() const;
54
55 // Overriden TWindow virtual
56 //
57 void Paint(TDC&, bool, TRect&) override;
58
59 protected:
60 void EvSize(uint sizeType, const TSize& size);
61
63 int PageNum; ///< Page currently being previewed
64 TSize PrintExtent; ///< Size of printer device (in pixels)
65 TPrintout& Printout; ///< Printout which sends the output
66 TPrintDC& PrintDC; ///< Device context of the printer
67
70};
71
72//
73/// \class TPreviewDCBase
74// ~~~~~ ~~~~~~~~~~~~~~
75/// TPreviewDCBase is the base class encapsulating a 'dual' device
76/// context - i.e. a DC which is tied to the screen but responds as if it
77/// were tied to a printer or some other device. A dual DC is schizophrenic
78/// and maintains two personalities: Dr. Screen and Mr. Printer.
79///
80/// When querried about it's attributes, a 'dual' DC acts as a printer DC.
81/// When requested to modify some attributes, a 'dual' DC acts as both a
82/// printer DC and a screen DC.
83/// When sent output, a 'dual' DC acts as a screen DC.
84///
85/// \note The TPreviewDCBase provides the basics of a 'dual' device context
86/// object. However, this base object does not attempt to map the
87/// screen DC to correspond to the attributes of the printer's device
88/// context.
89//
91 public:
94
95 // Overriden to return printer's HDC
96 //
97 HDC GetAttributeHDC() const;
98
99 protected:
100
101 /// DC of 'real' device (aka TargetDevice) whose output we're previewing
102 //
104};
105
106
107//
108/// \class TPrintPreviewDC
109// ~~~~~ ~~~~~~~~~~~~~~~~
110/// Derived from TPrintDC, TPrintPreviewDC maps printer device coordinates to
111/// logical screen coordinates. It sets the extent of the view window and determines
112/// the screen and printer font attributes. Many of TPrintPreviewDC's functions
113/// override TDC's virtual functions.
114///
115/// TPrintPreviewDC is an enhanced 'TPreviewDCBase' where the attributes
116/// of the screen DC are modified to corresponds [fairly] to those of the
117/// printer.
118///
119/// For example, the screen DC's extent are modified to match those of the
120/// printers. Similarly, the default font of the screen DC is computed to
121/// correspond closely to the default font of the printer.
122//
124 public:
127 const TRect& client,
128 const TRect& clip);
130
131 // Override virtual TDC select & restore functions
132 //
133 void SelectObject(const TFont& newFont);
134 void SelectStockObject(int index);
135 void RestoreFont();
136 int GetDeviceCaps(int index) const;
137
138 // Dual DC synchronizing functions
139 //
140 virtual void SyncFont();
141 virtual void ReScale();
142 virtual void ReOrg();
143
144 // Override virtual TDC color matching functions
145 //
146 TColor SetBkColor(const TColor& color);
147 TColor SetTextColor(const TColor& color);
148
149 // Override virtual TDC viewport & window mapping functions
150 //
151 int SetMapMode(int mode);
152 bool SetViewportOrg(const TPoint& origin, TPoint * oldOrg=0);
153 bool OffsetViewportOrg(const TPoint& delta, TPoint * oldOrg=0);
154
155 bool SetViewportExt(const TSize& extent, TSize * oldExtent=0);
156 bool ScaleViewportExt(int xNum, int xDenom, int yNum, int yDenom,
157 TSize * oldExtent=0);
158
159 bool SetWindowExt(const TSize& extent, TSize * oldExtent=0);
160 bool ScaleWindowExt(int xNum, int xDenom, int yNum, int yDenom,
161 TSize * oldExtent=0);
162
163 // Screen device point to Logical point conversions
164 //
165 bool SDPtoLP(TPoint* points, int count = 1) const;
166 bool SDPtoLP(TRect& rect) const;
167 bool LPtoSDP(TPoint* points, int count = 1) const;
168 bool LPtoSDP(TRect& rect) const;
169
171 HFONT PrnFont; ///< Handle of current font in the printer dc
172 TFont* CurrentPreviewFont; ///< Font object in PrnDC used during preview
173};
174/// @}
175
176#include <owl/posclass.h>
177
178
179// --------------------------------------------------------------------------
180// Inline implementation
181//
182
183//
184/// Converts each of the count points in the points array from screen device
185/// points to logical points of the printer DC. Returns a nonzero value if the call
186/// is successful; otherwise, returns 0.
187//
188inline bool
190 PRECONDITION(::GetObjectType(static_cast<HDC>(Handle)) != 0);
191 return ::DPtoLP(static_cast<HDC>(Handle), points, count);
192}
193
194//
195/// Converts each of the points in the rect from screen device points to
196/// logical points of the printer DC. Returns a nonzero value if the call is
197/// successful; otherwise, returns 0.
198//
199inline bool
201 return SDPtoLP(rect, 2);
202}
203
204//
205/// Converts each of the count points in the points array from logical
206/// points of the printer DC to screen points. Returns a nonzero value if the call
207/// is successful; otherwise, returns 0.
208//
209inline bool
211 PRECONDITION(::GetObjectType(HDC(Handle)) != 0);
212 return ::LPtoDP(HDC(Handle), points, count);
213}
214
215//
216/// Converts each of the points in the rect from logical points of the
217/// printer DC to screen device points. Returns a nonzero value if the call is
218/// successful; otherwise, returns 0.
219inline bool
221 return LPtoSDP(rect, 2);
222}
223
224//
225/// Retrieves the index of the page currently being previewed (painted) on the
226/// preview page window.
227//
228inline int
230 return PageNum;
231}
232
233} // OWL namespace
234
235
236#endif // OWL_PREVIEW_H
#define PRECONDITION(condition)
Definition checks.h:227
Class wrapper for management of color values.
Definition color.h:245
TDC is the root class for GDI DC wrappers.
Definition dc.h:64
HANDLE Handle
< make this function available to derivatives
Definition gdibase.h:81
TFont derived from TGdiObject provides constructors for creating font objects from explicit informati...
Definition gdiobjec.h:296
TPoint is a support class, derived from tagPOINT.
Definition geometry.h:87
TPreviewDCBase is the base class encapsulating a 'dual' device context - i.e.
Definition preview.h:90
TPrintDC & PrnDC
DC of 'real' device (aka TargetDevice) whose output we're previewing.
Definition preview.h:103
TPreviewPage encapsulates a window which displays print-preview data.
Definition preview.h:44
int GetPageNumber() const
Retrieves the index of the page currently being previewed (painted) on the preview page window.
Definition preview.h:229
A DC class that provides access to a printer.
Definition dc.h:874
Derived from TPrintDC, TPrintPreviewDC maps printer device coordinates to logical screen coordinates.
Definition preview.h:123
bool SDPtoLP(TPoint *points, int count=1) const
Converts each of the count points in the points array from screen device points to logical points of ...
Definition preview.h:189
bool LPtoSDP(TPoint *points, int count=1) const
Converts each of the count points in the points array from logical points of the printer DC to screen...
Definition preview.h:210
TPrintout represents the physical printed document that is to sent to a printer to be printed.
Definition printer.h:76
TRect is a mathematical class derived from tagRect.
Definition geometry.h:308
The tagSIZE struct is defined as.
Definition geometry.h:234
TWindow, derived from TEventHandler and TStreamableBase, provides window-specific behavior and encaps...
Definition window.h:414
Definition of GDI DC encapsulation classes: TDC, TWindowDC, TScreenDC, TDesktopDC,...
#define DECLARE_RESPONSE_TABLE(cls)
Definition eventhan.h:436
#define DECLARE_CASTABLE
Definition objstrm.h:1440
Object Windows Library (OWLNext Core)
Definition animctrl.h:22
unsigned int uint
Definition number.h:25
#define protected_data
Definition defs.h:208
#define _OWLCLASS
Definition defs.h:338
bool SetViewportExt(HDC hdc, int w, int h)
Definition preview.cpp:22
bool SetWindowExt(HDC hdc, int w, int h)
Definition preview.cpp:20
bool SetViewportOrg(HDC hdc, int x, int y)
Definition preview.cpp:23
Base window class TWindow definition, including HWND encapsulation.