OWLNext    7.0
Borland's Object Windows Library for the modern age
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
richedpr.cpp
Go to the documentation of this file.
1//----------------------------------------------------------------------------
2// ObjectWindows
3// Copyright (c) 1995, 1996 by Borland International, All Rights Reserved
4//
5/// \file
6/// Implementation of support classes for Print/PrintPreview of TRichEdits
7//----------------------------------------------------------------------------
8#include <owl/pch.h>
9#include <owl/window.h>
10#include <owl/control.h>
11#include <owl/edit.h>
12#include <owl/editsear.h>
13#include <owl/editfile.h>
14#include <owl/richedit.h>
15#include <owl/richedpr.h>
16
17#if defined(__BORLANDC__)
18# pragma option -w-ccc // Disable "Condition is always true/false"
19#endif
20
21namespace owl {
22
24
25//
26/// Constructs a Printout object which represent a RICHEDIT's document.
27//
31:
33 Printer(printer),
34 RichEdit(richEdit),
35 SizePhysPage(0),
36 SizePhysInch(0),
37 Margins(0),
38 FlushCache(false),
39 TextLen(0),
40 PageCount(0),
41 PageIndices(5)
42{
44
45 // Initialize data members
46 //
48}
49
50//
51/// String-aware overload
52//
54:
56 Printer(printer),
57 RichEdit(richEdit),
58 SizePhysPage(0),
59 SizePhysInch(0),
60 Margins(0),
61 FlushCache(false),
62 TextLen(0),
63 PageCount(0),
64 PageIndices(5)
65{
67
68 // Initialize data members
69 //
71}
72
73//
74// Destructor of 'RichEdit PrintOut' - Flushes any cached formatting
75// information
76//
78{
79 // Flush cached format information
80 //
81 if (FlushCache)
82 {
83 const auto ok = RichEdit.GetHandle() != nullptr;
84 WARN(!ok, _T("TRichEditPrintout::~TRichEditPrintout: Terminating due to failed precondition."));
85 if (!ok) std::terminate();
86
88 }
89}
90
91//
92/// This method is invoked by the printer or print-preview classes to allow the
93/// printout to update the page range information.
94//
95void
97 int& selFromPage, int& selToPage)
98{
99 if (PageCount && TextLen) {
100 minPage = 1;
102
104 int startSel, endSel;
106
107 // !BB Update to support multiple preview pages
108 //
111 }
112 else {
113 minPage = maxPage = 0;
115 }
116}
117
118//
119/// This method is invoked by the printer or print-preview objects to hand the
120/// printout object the target device context and the size of its pages.
121//
122void
124{
126
127 // Chain call base class' version
128 //
130
131 // Update size info about printer DC
132 //
137 if (!SizePhysPage.cx)
139 if (!SizePhysPage.cy)
141
142
143 // Set up the target and render DCs
144 // NOTE: In the case of PrintPreview, the two HDCs differ.
145 // When we're really printing, the attribute DC and
146 // GetHDC() return the same HDC.
147 //
148 FmtRange.SetTargetDC(dc->GetAttributeHDC()); // Format Device
149 FmtRange.SetRenderDC(dc->GetHDC()); // Render Device
150
151 // Set the page and render rectangles in twips
152 // Handle margins, if requested.
153 //
154 TRect rect(0, 0, MulDiv(SizePhysPage.cx, 1440, SizePhysInch.cx),
155 MulDiv(SizePhysPage.cy, 1440, SizePhysInch.cy));
156 if (Margins.cx) {
157 ;
158 }
159 if (Margins.cy) {
160 ;
161 }
164
165 // Retrieve length of document and set range
166 //
168
169 // Compute number of pages and cache their offsets
170 //
171 if (TextLen > 0) {
172 PageCount = 1; // Pages are not zero-based
173 FmtRange.SetRange(0, TextLen); // Format entire range.....
174 int endOfRange;
175 do {
177
178 if(PageCount >= static_cast<int>(PageIndices.Size()))
180 else
182
183 FmtRange.chrg.cpMin = endOfRange;
184 FmtRange.SetRenderRect(rect); // Ctl seems to corrupt the 'rc' member!
185 } while (FmtRange.chrg.cpMin < TextLen);
186
187 PageCount--;
188
189 // Free cached formatting information
190 //
192 }
193 else {
194 PageCount = 0;
195 }
196}
197
198//
199/// This routine is invoked to inform the printout that a printing operation has started.
200//
201void
205
206//
207/// This routine is invoked to inform the printout that the printint operation has ended.
208//
209void
213
214//
215/// This routine is invoked to request the printout object to print a page.
216//
217void
219{
220 PRECONDITION(page > 0);
222
223 // Check control's handle is !0
224 //
226
227 // These should have been set via a prior call to 'SetPrintParams'
228 //
229 PRECONDITION(FmtRange.hdcTarget !=0);
230 PRECONDITION(FmtRange.hdc != 0);
231
232 // Check whether we're in 'real' printing mode or just print preview.
233 // In print preview mode the target does not match the render DC.....
234 //
235 if (FmtRange.hdc != FmtRange.hdcTarget) {
236
237 int saveId = SaveDC(FmtRange.hdc);
238 if (FmtRange.hdc) {
239 TDC dc(FmtRange.hdc);
240
241 // Make window DC match target's logical size
242 //
246 SizePhysInch.cx),
249 SizePhysInch.cy)));
250 dc.SetViewportExt(TSize(bandRect.Width(), bandRect.Height()));
251
252 // Update character range for specified page
253 //
255
256 // Have Edit control draw into window
257 //
259
260 // Flag that we need to reset control
261 //
262 FlushCache = true;
263 }
264 // Restore the DC
265 //
266 RestoreDC(FmtRange.hdc, saveId);
267 }
268 else {
269 // We're really printing! Update character range for specified page
270 //
272
273 // Have Edit control format data
274 //
276
277 // Flag that we need to reset control
278 //
279 FlushCache = true;
280
281 // Have Edit control display to render rectangle of device
282 //
284 }
285}
286
287//
288/// This routine is invoked to asked the printout object whether it has necessary
289/// information to print the specified page.
290//
291bool
296
297//
298/// Returns the index of the page at the particular offset within the buffer of an
299/// edit control.
300//
301int
303{
305
306 int page = 0;
307 if (PageCount > 0) {
308 for (int i=1; i<=PageCount; i++) {
309 if (PageIndices[i] >= offset) {
310 if (PageIndices[i-1] <= offset) {
311 page = i;
312 break;
313 }
314 }
315 }
316 }
317 return page;
318}
319
320//
321/// Constructor of RichEdit PagePreview object.
322//
324 TPrintout& printout,
327 int pagenum)
328:
329 TPreviewPage(parent, printout, prndc, printExtent, pagenum)
330{
331}
332
333//
334/// WM_PAINT handler of RichEdit PagePreview window. Displays a preview of the page
335/// if the printout can handle it. Otherwise, simply fills the window with a white
336/// background.
337//
338void
340{
343
344 TPreviewDCBase pdc(dc, PrintDC);
345 Printout.SetPrintParams(&pdc, PrintExtent);
346
347 if (Printout.HasPage(PageNum)) {
348 Printout.BeginPrinting();
349 Printout.BeginDocument(PageNum, PageNum, pfBoth);
350 Printout.PrintPage(PageNum, client, pfBoth);
351 Printout.EndDocument();
352 Printout.EndPrinting();
353 }
354 else
356}
357
358//
359/// Constructor of a RichEdit Preview Frame.
360//
371
372//
373/// String-aware overload
374//
385
386//
387/// Returns pointer to a preview page object.
388//
391 TPrintout& printout,
394 int pagenum)
395{
396 return new TRichEditPagePreview(parent, printout, prndc,
398}
399
400
401} // OWL namespace
402/* ========================================================================== */
403
#define CHECK(condition)
Definition checks.h:239
#define WARN(condition, message)
Definition checks.h:273
#define PRECONDITION(condition)
Definition checks.h:227
uint Size() const
Definition template.h:672
TDC is the root class for GDI DC wrappers.
Definition dc.h:64
virtual int GetDeviceCaps(int index) const
Used under WIN3.1 or later, GetDeviceCaps returns capability information about this DC.
Definition dc.cpp:373
virtual int SetMapMode(int mode)
Sets the current window mapping mode of this DC to mode.
Definition dc.cpp:431
virtual HDC GetAttributeHDC() const
Returns the attributes of the DC object.
Definition dc.cpp:81
virtual bool SetWindowExt(const TSize &extent, TSize *oldExtent=nullptr)
Sets this DC's window x- and y-extents to the given extent values.
Definition dc.cpp:536
bool PatBlt(int x, int y, int w, int h, uint32 rop=PATCOPY)
Definition dc.h:2448
virtual bool SetViewportExt(const TSize &extent, TSize *oldExtent=nullptr)
Sets this DC's viewport x- and y-extents to the given extent values.
Definition dc.cpp:474
HDC GetHDC() const
Return the handle of the device context.
Definition dc.h:981
void SetRange(const TCharRange &)
Sets the range of text to format.
Definition richedit.cpp:446
void SetRenderDC(HDC)
Sets the device context of the device to render to.
Definition richedit.cpp:408
void SetPageRect(const TRect &)
Sets the entire area of the rendering device.
Definition richedit.cpp:437
void SetTargetDC(HDC)
Sets the device context of the target device to format for.
Definition richedit.cpp:417
void SetRenderRect(const TRect &)
Sets the area to render to.
Definition richedit.cpp:427
Derived from TWindow, TLayoutWindow provides functionality for defining the layout metrics for a wind...
Definition layoutwi.h:122
TPreviewDCBase is the base class encapsulating a 'dual' device context - i.e.
Definition preview.h:90
TPreviewPage encapsulates a window which displays print-preview data.
Definition preview.h:44
TPreviewWin encapsulates a simple preview window frame.
Definition prevwin.h:36
A DC class that provides access to a printer.
Definition dc.h:874
TPrinter is an encapsulation around the Windows printer device interface, and represents the physical...
Definition printer.h:164
TPrintout represents the physical printed document that is to sent to a printer to be printed.
Definition printer.h:76
virtual void SetPrintParams(TPrintDC *dc, TSize pageSize)
SetPrintParams sets DC to dc and PageSize to pageSize.
Definition printout.cpp:122
TRect is a mathematical class derived from tagRect.
Definition geometry.h:308
TRichEdit encapsulates a rich edit control, a window in which a user can enter, edit and format text.
Definition richedit.h:261
bool DisplayBand(TRect &)
int FormatRange(const TFormatRange &range, bool render=true)
void GetSelection(int &startPos, int &endPos) const override
Retrieves the starting and ending character position of the selection in the rich edit control.
Definition richedit.cpp:916
int GetTextLength() const
Definition richedit.cpp:989
TRichEditPagePreview is a window which displays rich edit data formatted for a particular printer DC.
Definition richedpr.h:69
void Paint(TDC &dc, bool, TRect &clip)
WM_PAINT handler of RichEdit PagePreview window.
Definition richedpr.cpp:339
TRichEditPagePreview(TWindow *parent, TPrintout &printout, TPrintDC &prndc, TSize &printExtent, int pagenum=1)
Constructor of RichEdit PagePreview object.
Definition richedpr.cpp:323
TRichEditPreviewFrame(TWindow *parentWindow, TPrinter &printer, TPrintout &printout, TRichEdit &richEdit, LPCTSTR title, TLayoutWindow *client)
Constructor of a RichEdit Preview Frame.
Definition richedpr.cpp:361
TPreviewPage * GetNewPreviewPage(TWindow *parent, TPrintout &printout, TPrintDC &prndc, TSize &printExtent, int pagenum=1)
Returns pointer to a preview page object.
Definition richedpr.cpp:390
void GetDialogInfo(int &minPage, int &maxPage, int &selFromPage, int &selToPage)
This method is invoked by the printer or print-preview classes to allow the printout to update the pa...
Definition richedpr.cpp:96
int TextLen
Length of text formatted.
Definition richedpr.h:132
TIntArray PageIndices
Index of page offsets.
Definition richedpr.h:134
TRichEdit & RichEdit
Ref. to associated control.
Definition richedpr.h:126
void PrintPage(int page, TRect &rect, uint flags)
This routine is invoked to request the printout object to print a page.
Definition richedpr.cpp:218
int PageCount
Number of pages formatted.
Definition richedpr.h:133
void BeginPrinting()
This routine is invoked to inform the printout that a printing operation has started.
Definition richedpr.cpp:202
TFormatRange FmtRange
Range of text to format.
Definition richedpr.h:130
void SetPrintParams(TPrintDC *dc, TSize pageSize)
This method is invoked by the printer or print-preview objects to hand the printout object the target...
Definition richedpr.cpp:123
bool FlushCache
Have cached formatted data.
Definition richedpr.h:131
TSize SizePhysInch
Size of printer in inches.
Definition richedpr.h:128
int PageOfOffset(int offset)
Returns the index of the page at the particular offset within the buffer of an edit control.
Definition richedpr.cpp:302
TSize SizePhysPage
Physical size of printer (pels)
Definition richedpr.h:127
bool HasPage(int pageNumber)
This routine is invoked to asked the printout object whether it has necessary information to print th...
Definition richedpr.cpp:292
void EndPrinting()
This routine is invoked to inform the printout that the printint operation has ended.
Definition richedpr.cpp:210
TSize Margins
Size of margins.
Definition richedpr.h:129
TRichEditPrintout(TPrinter &printer, TRichEdit &richEdit, LPCTSTR title)
Constructs a Printout object which represent a RICHEDIT's document.
Definition richedpr.cpp:28
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
TRect GetClientRect() const
Gets the coordinates of the window's client area (the area in a window you can use for drawing).
Definition window.h:2217
HWND GetHandle() const
Returns the handle of the window.
Definition window.h:2020
Definition of class TControl.
#define _T(x)
Definition cygwin.h:51
Definition of class TEdit.
Definition of class TEditFile, a text edit which can find/replace and read/write from/to a file.
Definition of class TEditSearch, an edit control that responds to Find, Replace and FindNext menu com...
@ pfBoth
Current band accepts both text and graphics.
Definition printer.h:64
Object Windows Library (OWLNext Core)
Definition animctrl.h:22
OWL_DIAGINFO
Definition animctrl.cpp:14
std::string tstring
Definition defs.h:79
unsigned int uint
Definition number.h:25
Definition of class TRichEdit.
Definition of classes supporting Printing/PrintPreview for TRichEdit.
Base window class TWindow definition, including HWND encapsulation.