OWLNext    7.0
Borland's Object Windows Library for the modern age
Loading...
Searching...
No Matches
prevwin.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 TPreviewWin
7//----------------------------------------------------------------------------
8#include <owl/pch.h>
9#include <owl/prevwin.h>
10#include <owl/prevwin.rh>
11#include <owl/editfile.rh>
12#include <stdio.h>
13
14namespace owl {
15
17
18DEFINE_RESPONSE_TABLE1(TPreviewWin, TDecoratedFrame)
28
29
30//
31/// Destructor of Preview frame window. Performs general cleanup.
32//
33TPreviewWin::TPreviewWin(TWindow *parentWindow, /* Parent window object */
34 TPrinter& printer, /* Printer object */
35 TPrintout& printout, /* Printout object */
36 TWindow& dataWindow, /* Owner of preview data*/
37 LPCTSTR title, /* Title of preview win */
38 TLayoutWindow* client) /* Client of preview win*/
39:
41 DataWindow(dataWindow),
42 Printer(printer),
43 Printout(printout),
44 PrnDC(nullptr),
45 PreviewSpeedBar(nullptr),
46 Page1(nullptr),
47 Page2(nullptr),
48 Client(client)
49{
51 Init();
52}
53
54//
55/// String-aware overload
56//
60 TPrintout& printout,
62 const tstring& title,
64:
66 DataWindow(dataWindow),
67 Printer(printer),
68 Printout(printout),
69 PrnDC(nullptr),
70 PreviewSpeedBar(nullptr),
71 Page1(nullptr),
72 Page2(nullptr),
73 Client(client)
74{
76 Init();
77}
78
80{
82
83 // Retrieve device context of default printer
84 //
85 PrnDC = new TPrintDC{data.GetDeviceName(), data.GetDevMode()};
86
87 // Let printer object update it page sizes
88 //
90
91 // Make a local copy of the printer's page size
92 //
94
95 // Set background of preview window
96 //
98
99 // Setup toolbar of preview window
100 //
102
103 // !BB Revisit the following restrictions...
104 //
105
106#if 0
107 // We want a window that cannot be sized, maximized, or minimized.
108 //
110
111#else
112 Attr.X = 0;
113 Attr.Y = -1;
114 Attr.W = GetParentO()->GetClientRect().Width();
115 Attr.H = GetParentO()->GetClientRect().Height() + 1;
116 Parent->MapWindowPoints(GetHandle(), (TPoint*)&Attr.X, 1);
117#endif
118}
119
120//
121// Destructor of Preview frame window - Performs general cleanup
122//
124{
125 delete Page1;
126 Page1 = nullptr;
127 delete Page2;
128 Page2 = nullptr;
129
130 delete PrnDC;
131 PrnDC = nullptr;
132}
133
134//
135// Creates a control bar which is inserted along the top edge of the
136// preview frame window.
137// NOTE: The control bar is populated with buttongadgets to iterate
138// through the pages and print the document.
139//
140void
159
160//
161/// Overriden virtual of TWindow to allow preview frame to create the preview
162/// page(s).
163//
164void
166{
168
169 // !BB NOTE: The follow order of calls (i.e. calling
170 // SetPrintParams() before calling GetDialogInfo()
171 // is the opposite of the order used by TPrinter::Print
172 // (when we're really printing). However, the following
173 // seems more logical since the 'Printout' can accurately
174 // compute it page info. only after it has received the
175 // PrinterDC...
176 // Investigate and make update so that a 'Printout' can
177 // expect a consistent order of calls whether we're printing
178 // or simply previewing...
179 //
180
181 // Hand printout the target DC and page size
182 //
184
185 // Allow printout to update page range information
186 //
188 Printout.GetDialogInfo(data.MinPage, data.MaxPage,
189 data.FromPage, data.ToPage);
190
191 // Create/Initialize Preview Pages
192 //
194 data.FromPage > 0 ? data.FromPage : 1);
195 Page1->Create();
196 Page2 = nullptr;
197
198 LayoutPages();
199
200/*
201 data.FromPage = 1;
202 data.ToPage = 1;
203 data.MinPage = 1;
204 data.MaxPage = 1;
205*/
206}
207
208//
209/// Returns a pointer to a TPreviewPage object.
210/// \note This default version simply returns a 'true' TPreviewPage. However,
211/// derived TPreviewWin classes can return a more sophisticated preview page (e.g.,
212/// one that can handle zooming).
213//
217 int pagenum)
218{
219 return new TPreviewPage(parent, printout, prndc, printExtent, pagenum);
220}
221
222//
223/// Repositions the preview page(s) using the aspect ratio of the printer when
224/// determining the dimensions of the pages.
225//
226void
228{
230
232 metrics1.Y.Set(lmTop, lmBelow, lmParent, lmTop, 15);
233
234 //
235 // Determine major axis of preview page, have that follow parent size.
236 // Make minor axis a percentage (aspect ratio) of the page's major axis
237 //
238 TRect r = Client->GetClientRect();
239 long ratio;
240
242 ratio = (static_cast<long>(PrinterPageSize.cy) * 100) / PrinterPageSize.cx;
243 else
244 ratio = (static_cast<long>(PrinterPageSize.cx) * 100) / PrinterPageSize.cy;
245
246 bool xMajor = (((r.Width() * ratio) / 100) > r.Height());
247 if (xMajor) {
248 metrics1.Height.Set(lmBottom, lmAbove, lmParent, lmBottom, 15);
249 metrics1.Width.PercentOf(Page1, static_cast<int>(static_cast<long>(PrinterPageSize.cx) * 95 / PrinterPageSize.cy), lmHeight);
250 }
251 else {
252 metrics1.Height.PercentOf(Page1, static_cast<int>(static_cast<long>(PrinterPageSize.cy) * 95 / PrinterPageSize.cx), lmWidth);
253 metrics1.Width.Set(lmRight, lmLeftOf, lmParent, lmRight, 15);
254 }
255
257
258 if (Page2) {
260
261 metrics2.X.Set(lmLeft, lmRightOf, Page1, lmRight, 30);
262 metrics2.Y.SameAs(Page1, lmTop);
263
264 // Assume portrait
265 //
266 metrics2.Width.SameAs(Page1, lmWidth);
267 metrics2.Height.SameAs(Page1, lmBottom);
268
270 }
271
272 Client->Layout();
273}
274
275//
276// Update the information displayed on the control bar of the
277// preview frame window.
278// NOTE: This method simply updates the page info. Derived classes
279// can display additional information.
280//
281void
283{
284 // Update the page count.
285 //
289 if (pgGadget) {
290 tchar buffer[32];
291 if (Page2 && Page2->GetPageNumber())
292 _stprintf(buffer, _T("Page %d - %d"), Page1->GetPageNumber(), Page2->GetPageNumber());
293 else
294 _stprintf(buffer, _T("Page %d"), Page1->GetPageNumber());
295 pgGadget->SetText(buffer);
296 }
297}
298
299//
300// Command enabler of 'PREVIOUS' command
301//
302void
303TPreviewWin::CePrevious(TCommandEnabler& ce)
304{
305 // Only have previous on if we're not at the first page.
306 //
307 ce.Enable(Page1->GetPageNumber() > 1);
308}
309
310//
311// Command enabler of 'NEXT' command.
312//
313void
314TPreviewWin::CeNext (TCommandEnabler& ce)
315{
316 // Only have next on if we're not at the last page.
317 //
318 TPrintDialog::TData &printerData = Printer.GetSetup();
319 ce.Enable(printerData.ToPage < printerData.MaxPage);
320}
321
322//
323// Handler of 'PREVIOUS' command
324//
325void
326TPreviewWin::CmPrevious()
327{
328 TPrintDialog::TData &printerData = Printer.GetSetup();
329
330 if (printerData.FromPage > printerData.MinPage) {
331 printerData.FromPage--;
332 printerData.ToPage--;
333
335 if (Page2)
337 }
338
340}
341
342//
343// Handler of 'NEXT' command
344//
345void
346TPreviewWin::CmNext()
347{
348 TPrintDialog::TData &printerData = Printer.GetSetup();
349
350 if (printerData.ToPage < printerData.MaxPage) {
351 printerData.FromPage++;
352 printerData.ToPage++;
353
355 if (Page2)
357 }
359}
360
361//
362// Handler of request for only one preview page.
363//
364void
365TPreviewWin::CmOneUp ()
366{
367 if (Page2) {
369
370 delete Page2;
371 Page2 = nullptr;
372
373 Client->Layout();
374
375 TPrintDialog::TData &printerData = Printer.GetSetup();
376 printerData.ToPage = printerData.FromPage;
377
379 }
380}
381
382//
383// Command enabler of request for two preview pages.
384//
385void
386TPreviewWin::CeTwoUp(TCommandEnabler& ce)
387{
388 // Two up is only available for portrait mode.
389 //
390 ce.Enable(PrinterPageSize.cx <= PrinterPageSize.cy);
391}
392
393//
394// Handler of request for two preview pages
395//
396void
397TPreviewWin::CmTwoUp()
398{
399 if (Page2 == nullptr) {
402 Page1->GetPageNumber() + 1);
403 Page2->Create();
404
405 TPrintDialog::TData &printerData = Printer.GetSetup();
406
407 // Page 2 is the next page. If the next page is outside of our range then
408 // set the first page back one and the 2nd page is the current page. If
409 // the document is only 1 page long then the 2nd page is empty.
410 //
411 if (printerData.FromPage == printerData.MaxPage) {
412 if (printerData.FromPage > 1) {
413 printerData.FromPage--;
414 printerData.ToPage = printerData.FromPage + 1;
417 }
418 else {
420 }
421 }
422 else {
423 printerData.ToPage = printerData.FromPage + 1;
425 }
426
427 LayoutPages();
429 }
430}
431
432//
433// Handler of request to terminate preview session
434//
435void
436TPreviewWin::CmDone()
437{
438 CloseWindow();
439}
440
441
442} // OWL namespace
443/* ========================================================================== */
444
#define PRECONDITION(condition)
Definition checks.h:227
Derived from TGadget, TButtonGadget represent buttons that you can click on or off.
Definition buttonga.h:65
@ Down
Button is down, i.e. checked.
Definition buttonga.h:82
@ Exclusive
Stays down when pressed and causes other buttons in the group to pop back up.
Definition buttonga.h:71
@ Command
Basic type of this button.
Definition buttonga.h:70
static const TColor SysAppWorkspace
The symbolic system color value for the background of multiple document interface (MDI) applications.
Definition color.h:336
Base class for an extensible interface for auto enabling/disabling of commands (menu items,...
Definition window.h:209
Derived from TGadgetWindow, TControlBar implements a control bar that provides mnemonic access for it...
Definition controlb.h:61
TDecoratedFrame automatically positions its client window (you must supply a client window) so that i...
Definition decframe.h:74
@ Top
Refers to top edge of frame.
Definition decframe.h:90
void SetupWindow() override
Override SetupWindow in order to layout & position decorations Calls TLayoutWindow::Layout to size an...
Definition decframe.cpp:148
virtual void Insert(TWindow &decoration, TLocation location=Top)
Insert a decoration window into position at one of the four edges.
Definition decframe.cpp:899
@ Recessed
Recessed into the window.
Definition gadget.h:131
TGadget * GadgetWithId(int id) const
Returns the gadget with a given ID, or 0 if none is found.
Definition gadgetli.cpp:56
void Insert(TGadget &, TPlacement=After, TGadget *sibling=nullptr) override
Inserts a gadget before or after a sibling gadget (TPlacement).
When specifying the layout metrics for a window, four layout constraints are needed.
Definition layoutwi.h:54
Derived from TWindow, TLayoutWindow provides functionality for defining the layout metrics for a wind...
Definition layoutwi.h:122
virtual void Layout()
Causes the window to resize and position its children according to the specified metrics.
Definition layoutwi.cpp:351
void SetChildLayoutMetrics(TWindow &child, const TLayoutMetrics &metrics)
Sets the metrics for the window and removes any existing ones.
Definition layoutwi.cpp:465
bool RemoveChildLayoutMetrics(const TWindow &child)
Removes child (layout) metrics for a given child (if found) and updates other children as necessary.
Definition layoutwi.cpp:529
TPoint is a support class, derived from tagPOINT.
Definition geometry.h:87
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
void SetPageNumber(int newNum)
Sets newNum to the number of the page currently displayed in the preview window.
Definition preview.cpp:491
TPreviewWin encapsulates a simple preview window frame.
Definition prevwin.h:36
TPrinter & Printer
Printer device object.
Definition prevwin.h:72
void SetupWindow() override
Overriden virtual of TWindow to allow preview frame to create the preview page(s).
Definition prevwin.cpp:165
TPreviewWin(TWindow *parentWindow, TPrinter &printer, TPrintout &printout, TWindow &dataWindow, LPCTSTR title, TLayoutWindow *client)
Destructor of Preview frame window. Performs general cleanup.
Definition prevwin.cpp:33
TPrintDC * PrnDC
Printer DC.
Definition prevwin.h:74
TPreviewPage * Page1
Pointer to first preview page.
Definition prevwin.h:78
virtual void SetupSpeedBar()
Definition prevwin.cpp:141
virtual void LayoutPages()
Repositions the preview page(s) using the aspect ratio of the printer when determining the dimensions...
Definition prevwin.cpp:227
TPrintout & Printout
Printer document object.
Definition prevwin.h:73
~TPreviewWin() override
Definition prevwin.cpp:123
virtual TPreviewPage * GetNewPreviewPage(TWindow *parent, TPrintout &printout, TPrintDC &prndc, TSize &printExtent, int pagenum=1)
Returns a pointer to a TPreviewPage object.
Definition prevwin.cpp:215
TControlBar * PreviewSpeedBar
Pointer to toolbar object.
Definition prevwin.h:77
TSize PrinterPageSize
Printer's page size.
Definition prevwin.h:75
virtual void UpdateSpeedBar()
Definition prevwin.cpp:282
TPreviewPage * Page2
Pointer to second preview page.
Definition prevwin.h:79
A DC class that provides access to a printer.
Definition dc.h:874
TPrintDialog::TData contains information required to initialize the printer dialog box with the user'...
Definition printdia.h:58
TPrinter is an encapsulation around the Windows printer device interface, and represents the physical...
Definition printer.h:164
TSize GetPageSize() const
Returns the size of the page.
Definition printer.cpp:519
virtual void SetPageSizes(const TPrintDC &dc)
Updates the PageSize variables by querying the device capabilities of the specified device context.
Definition printer.cpp:1081
TPrintDialog::TData & GetSetup()
Returns a reference to the TPrintDialog data structure.
Definition printer.cpp:457
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
virtual void GetDialogInfo(int &minPage, int &maxPage, int &selFromPage, int &selToPage)
Retrieves information needed to allow the printing of selected pages of the document and returns true...
Definition printout.cpp:136
TRect is a mathematical class derived from tagRect.
Definition geometry.h:308
TSeparatorGadget is a simple class you can use to create a separator between gadgets.
Definition gadget.h:354
The tagSIZE struct is defined as.
Definition geometry.h:234
Derived from TGadget, TTextGadget is a text gadget object.
Definition textgadg.h:37
@ Left
Aligns the text at the left edge of the bounding rectangle.
Definition textgadg.h:43
TWindow, derived from TEventHandler and TStreamableBase, provides window-specific behavior and encaps...
Definition window.h:414
void SetBkgndColor(TColor color, bool shouldUpdate=true)
Sets the background color for the window.
Definition window.h:1925
virtual bool Create()
Creates the window interface element to be associated with this ObjectWindows interface element.
Definition window.cpp:2399
TWindow * GetParentO() const
Return the OWL's parent for this window.
Definition window.h:2006
void GetClientRect(TRect &rect) const
Gets the coordinates of the window's client area and then copies them into the object referred to by ...
Definition window.cpp:3624
HWND GetHandle() const
Returns the handle of the window.
Definition window.h:2020
virtual void CloseWindow(int retVal=0)
Determines if it is okay to close a window before actually closing the window.
Definition window.cpp:2809
#define _stprintf
Definition cygwin.h:88
#define _T(x)
Definition cygwin.h:51
#define DEFINE_RESPONSE_TABLE1(cls, base)
Macro to define a response table for a class with one base.
Definition eventhan.h:492
#define lmParent
Use to represent the parent in layout metrics.
Definition layoutco.h:31
@ lmTop
The top edge of the window.
Definition layoutco.h:38
@ lmBottom
The bottom edge of the window.
Definition layoutco.h:40
@ lmRight
The right edge of the window.
Definition layoutco.h:39
@ lmLeft
The left edge of the window.
Definition layoutco.h:37
@ lmLeftOf
Definition layoutco.h:71
@ lmAbove
Definition layoutco.h:71
@ lmRightOf
Definition layoutco.h:72
@ lmBelow
Definition layoutco.h:72
@ lmWidth
Definition layoutco.h:48
@ lmHeight
Definition layoutco.h:48
Object Windows Library (OWLNext Core)
Definition animctrl.h:22
OWL_DIAGINFO
Definition animctrl.cpp:14
END_RESPONSE_TABLE
Definition button.cpp:26
std::string tstring
Definition defs.h:79
#define TYPESAFE_DOWNCAST(object, toClass)
Definition defs.h:269
Definition of TPreviewWin, the Preview Window class.
#define EV_COMMAND_ENABLE(id, method)
Response table entry for enabling a command.
Definition windowev.h:193
#define EV_COMMAND(id, method)
Response table entry for a menu/accelerator/push button message.
Definition windowev.h:171