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
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,
48 TPrintDC& prndc,
49 TSize& printExtent,
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
68 DECLARE_RESPONSE_TABLE(TPreviewPage);
69 DECLARE_CASTABLE;
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:
92 TPreviewDCBase(TDC& screen,
93 TPrintDC& printdc);
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:
125 TPrintPreviewDC(TDC& screen,
126 TPrintDC& printdc,
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
189TPrintPreviewDC::SDPtoLP(TPoint* points, int count) const {
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
210TPrintPreviewDC::LPtoSDP(TPoint* points, int count) const {
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
HDC GetAttributeHDC() const
Overriden to return printer's HDC.
Definition preview.cpp:43
TPrintDC & PrnDC
DC of 'real' device (aka TargetDevice) whose output we're previewing.
Definition preview.h:103
TPreviewDCBase(TDC &screen, TPrintDC &printdc)
Constructs a basic Preview DC.
Definition preview.cpp:32
int GetPageNumber() const
Retrieves the index of the page currently being previewed (painted) on the preview page window.
Definition preview.h:229
void Paint(TDC &, bool, TRect &) override
Using a TPrintPreviewDC, 'print' the current page (PageNum) of Printout onto the window DC provided.
Definition preview.cpp:510
TPreviewPage(TWindow *parent, TPrintout &printout, TPrintDC &prndc, TSize &printExtent, int pagenum=1)
Constructs a TPreviewPage object where parent is the parent window, printout is a reference to the co...
Definition preview.cpp:474
void EvSize(uint sizeType, const TSize &size)
Invalidates the entire window when the size of the page displayed in the preview window changes.
Definition preview.cpp:536
void SetPageNumber(int newNum)
Sets newNum to the number of the page currently displayed in the preview window.
Definition preview.cpp:491
A DC class that provides access to a printer.
Definition dc.h:874
TPrintDC(HDC handle, TAutoDelete autoDelete=NoAutoDelete)
Creates a TPrintDC object for the DC given by handle.
Definition printdc.cpp:66
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
TColor SetBkColor(const TColor &color)
Sets the current background color of this DC to the given color value or the nearest available.
Definition preview.cpp:334
void RestoreFont()
Restores the original GDI font object to this DC.
Definition preview.cpp:148
bool ScaleWindowExt(int xNum, int xDenom, int yNum, int yDenom, TSize *oldExtent=0)
Modifies this DC's window extents relative to the current values.
Definition preview.cpp:453
virtual void ReOrg()
Gets the x- and y- extents of the viewport, equalizes the logical and screen points,...
Definition preview.cpp:308
TColor SetTextColor(const TColor &color)
Sets the current text color of this DC to the given color value.
Definition preview.cpp:346
virtual void ReScale()
Maps the points of the printer DC to the screen DC.
Definition preview.cpp:278
bool SetWindowExt(const TSize &extent, TSize *oldExtent=0)
Sets the DC's window x- and y-extents to the given extent values.
Definition preview.cpp:435
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
void SelectStockObject(int index)
Retrieves a handle to a predefined stock font.
Definition preview.cpp:122
TPrintPreviewDC(TDC &screen, TPrintDC &printdc, const TRect &client, const TRect &clip)
TPrintPreviewDC's constructor takes a screen DC as well as a printer DC.
Definition preview.cpp:53
virtual void SyncFont()
Sets the screen font equal to the current printer font.
Definition preview.cpp:216
bool ScaleViewportExt(int xNum, int xDenom, int yNum, int yDenom, TSize *oldExtent=0)
Modifies this DC's viewport extents relative to the current values.
Definition preview.cpp:419
bool SetViewportOrg(const TPoint &origin, TPoint *oldOrg=0)
Sets the printer DC's viewport origin to the given origin value, and saves the previous origin in old...
Definition preview.cpp:373
bool OffsetViewportOrg(const TPoint &delta, TPoint *oldOrg=0)
Modifies this DC's viewport origin relative to the current values.
Definition preview.cpp:387
int SetMapMode(int mode)
Sets the current window mapping mode of this DC to mode.
Definition preview.cpp:360
int GetDeviceCaps(int index) const
GetDeviceCaps returns capability information, such as font and pitch attributes, about the printer DC...
Definition preview.cpp:162
void SelectObject(const TFont &newFont)
Selects the given font object into this DC.
Definition preview.cpp:100
bool SetViewportExt(const TSize &extent, TSize *oldExtent=0)
Sets the screen's viewport x- and y-extents to the given extent values.
Definition preview.cpp:403
TPrinter is an encapsulation around the Windows printer device interface, and represents the physical...
Definition printer.h:167
TPrintout represents the physical printed document that is to sent to a printer to be printed.
Definition printer.h:79
TRect is a mathematical class derived from tagRect.
Definition geometry.h:308
The tagSIZE struct is defined as.
Definition geometry.h:234
TWindow(TWindow *parent, LPCTSTR title=nullptr, TModule *module=nullptr)
Adds this to the child list of parent if nonzero, and calls EnableAutoCreate so that this will be cre...
Definition window.cpp:341
Definition of GDI DC encapsulation classes: TDC, TWindowDC, TScreenDC, TDesktopDC,...
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
Base window class TWindow definition, including HWND encapsulation.