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
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
163
164//
165/// Overriden virtual of TWindow to allow preview frame to create the preview
166/// page(s).
167//
168void
170{
172
173 // !BB NOTE: The follow order of calls (i.e. calling
174 // SetPrintParams() before calling GetDialogInfo()
175 // is the opposite of the order used by TPrinter::Print
176 // (when we're really printing). However, the following
177 // seems more logical since the 'Printout' can accurately
178 // compute it page info. only after it has received the
179 // PrinterDC...
180 // Investigate and make update so that a 'Printout' can
181 // expect a consistent order of calls whether we're printing
182 // or simply previewing...
183 //
184
185 // Hand printout the target DC and page size
186 //
188
189 // Allow printout to update page range information
190 //
192 Printout.GetDialogInfo(data.MinPage, data.MaxPage,
193 data.FromPage, data.ToPage);
194
195 // Create/Initialize Preview Pages
196 //
198 data.FromPage > 0 ? data.FromPage : 1);
199 Page1->Create();
200 Page2 = nullptr;
201
202 LayoutPages();
203
204/*
205 data.FromPage = 1;
206 data.ToPage = 1;
207 data.MinPage = 1;
208 data.MaxPage = 1;
209*/
210}
211
212//
213/// Returns a pointer to a TPreviewPage object.
214/// \note This default version simply returns a 'true' TPreviewPage. However,
215/// derived TPreviewWin classes can return a more sophisticated preview page (e.g.,
216/// one that can handle zooming).
217//
221 int pagenum)
222{
223 return new TPreviewPage(parent, printout, prndc, printExtent, pagenum);
224}
225
226//
227/// Repositions the preview page(s) using the aspect ratio of the printer when
228/// determining the dimensions of the pages.
229//
230void
232{
234
236 metrics1.Y.Set(lmTop, lmBelow, lmParent, lmTop, 15);
237
238 //
239 // Determine major axis of preview page, have that follow parent size.
240 // Make minor axis a percentage (aspect ratio) of the page's major axis
241 //
242 TRect r = Client->GetClientRect();
243 long ratio;
244
246 ratio = (static_cast<long>(PrinterPageSize.cy) * 100) / PrinterPageSize.cx;
247 else
248 ratio = (static_cast<long>(PrinterPageSize.cx) * 100) / PrinterPageSize.cy;
249
250 bool xMajor = (((r.Width() * ratio) / 100) > r.Height());
251 if (xMajor) {
252 metrics1.Height.Set(lmBottom, lmAbove, lmParent, lmBottom, 15);
253 metrics1.Width.PercentOf(Page1, static_cast<int>(static_cast<long>(PrinterPageSize.cx) * 95 / PrinterPageSize.cy), lmHeight);
254 }
255 else {
256 metrics1.Height.PercentOf(Page1, static_cast<int>(static_cast<long>(PrinterPageSize.cy) * 95 / PrinterPageSize.cx), lmWidth);
257 metrics1.Width.Set(lmRight, lmLeftOf, lmParent, lmRight, 15);
258 }
259
261
262 if (Page2) {
264
265 metrics2.X.Set(lmLeft, lmRightOf, Page1, lmRight, 30);
266 metrics2.Y.SameAs(Page1, lmTop);
267
268 // Assume portrait
269 //
270 metrics2.Width.SameAs(Page1, lmWidth);
271 metrics2.Height.SameAs(Page1, lmBottom);
272
274 }
275
276 Client->Layout();
277}
278
279//
280// Update the information displayed on the control bar of the
281// preview frame window.
282// NOTE: This method simply updates the page info. Derived classes
283// can display additional information.
284//
285void
287{
288 // Update the page count.
289 //
293 if (pgGadget) {
294 tchar buffer[32];
295#if BI_MSG_LANGUAGE == 0x0411
296 sprintf(buffer, "�߰�� %d - %d", Page1->GetPageNumber(),
298 else
299 sprintf(buffer, "�߰�� %d", Page1->GetPageNumber());
300#else
301 if (Page2 && Page2->GetPageNumber())
302 _stprintf(buffer, _T("Page %d - %d"), Page1->GetPageNumber(),
304 else
305 _stprintf(buffer, _T("Page %d"), Page1->GetPageNumber());
306#endif
307 pgGadget->SetText(buffer);
308 }
309}
310
311//
312// Command enabler of 'PREVIOUS' command
313//
314void
315TPreviewWin::CePrevious(TCommandEnabler& ce)
316{
317 // Only have previous on if we're not at the first page.
318 //
319 ce.Enable(Page1->GetPageNumber() > 1);
320}
321
322//
323// Command enabler of 'NEXT' command.
324//
325void
326TPreviewWin::CeNext (TCommandEnabler& ce)
327{
328 // Only have next on if we're not at the last page.
329 //
330 TPrintDialog::TData &printerData = Printer.GetSetup();
331 ce.Enable(printerData.ToPage < printerData.MaxPage);
332}
333
334//
335// Handler of 'PREVIOUS' command
336//
337void
338TPreviewWin::CmPrevious()
339{
340 TPrintDialog::TData &printerData = Printer.GetSetup();
341
342 if (printerData.FromPage > printerData.MinPage) {
343 printerData.FromPage--;
344 printerData.ToPage--;
345
347 if (Page2)
349 }
350
352}
353
354//
355// Handler of 'NEXT' command
356//
357void
358TPreviewWin::CmNext()
359{
360 TPrintDialog::TData &printerData = Printer.GetSetup();
361
362 if (printerData.ToPage < printerData.MaxPage) {
363 printerData.FromPage++;
364 printerData.ToPage++;
365
367 if (Page2)
369 }
371}
372
373//
374// Handler of request for only one preview page.
375//
376void
377TPreviewWin::CmOneUp ()
378{
379 if (Page2) {
381
382 delete Page2;
383 Page2 = nullptr;
384
385 Client->Layout();
386
387 TPrintDialog::TData &printerData = Printer.GetSetup();
388 printerData.ToPage = printerData.FromPage;
389
391 }
392}
393
394//
395// Command enabler of request for two preview pages.
396//
397void
398TPreviewWin::CeTwoUp(TCommandEnabler& ce)
399{
400 // Two up is only available for portrait mode.
401 //
402 ce.Enable(PrinterPageSize.cx <= PrinterPageSize.cy);
403}
404
405//
406// Handler of request for two preview pages
407//
408void
409TPreviewWin::CmTwoUp()
410{
411 if (Page2 == nullptr) {
414 Page1->GetPageNumber() + 1);
415 Page2->Create();
416
417 TPrintDialog::TData &printerData = Printer.GetSetup();
418
419 // Page 2 is the next page. If the next page is outside of our range then
420 // set the first page back one and the 2nd page is the current page. If
421 // the document is only 1 page long then the 2nd page is empty.
422 //
423 if (printerData.FromPage == printerData.MaxPage) {
424 if (printerData.FromPage > 1) {
425 printerData.FromPage--;
426 printerData.ToPage = printerData.FromPage + 1;
429 }
430 else {
432 }
433 }
434 else {
435 printerData.ToPage = printerData.FromPage + 1;
437 }
438
439 LayoutPages();
441 }
442}
443
444//
445// Handler of request to terminate preview session
446//
447void
448TPreviewWin::CmDone()
449{
450 CloseWindow();
451}
452
453
454} // OWL namespace
455/* ========================================================================== */
456
#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:169
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:231
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:219
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:286
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