0022972: Eliminate macro definitions that has compiler-provided analogs (WNT and...
[occt.git] / src / V3d / V3d_View_Print.cxx
1 // Created by: THA
2 // Copyright (c) 1999-2014 OPEN CASCADE SAS
3 //
4 // This file is part of Open CASCADE Technology software library.
5 //
6 // This library is free software; you can redistribute it and/or modify it under
7 // the terms of the GNU Lesser General Public License version 2.1 as published
8 // by the Free Software Foundation, with special exception defined in the file
9 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
10 // distribution for complete text of the license and disclaimer of any warranty.
11 //
12 // Alternatively, this file may be used under the terms of Open CASCADE
13 // commercial license or contractual agreement.
14
15 // e-mail           t-hartl@muenchen.matra-dtv.fr
16
17 /************************************************************************/
18 /* Includes                                                             */
19 /************************************************************************/
20
21 #ifdef _WIN32
22 #include <windows.h>
23 #pragma comment( lib, "comdlg32.lib"  )
24 #endif
25
26
27 #include <Aspect_GradientBackground.hxx>
28 #include <Aspect_Grid.hxx>
29 #include <Aspect_Window.hxx>
30 #include <Bnd_Box.hxx>
31 #include <gp_Ax3.hxx>
32 #include <gp_Dir.hxx>
33 #include <Graphic3d_Group.hxx>
34 #include <Graphic3d_Structure.hxx>
35 #include <Graphic3d_TextureEnv.hxx>
36 #include <Graphic3d_Vector.hxx>
37 #include <Quantity_Color.hxx>
38 #include <Standard_MultiplyDefined.hxx>
39 #include <Standard_NotImplemented.hxx>
40 #include <Standard_TypeMismatch.hxx>
41 #include <V3d_BadValue.hxx>
42 #include <V3d_Light.hxx>
43 #include <V3d_UnMapped.hxx>
44 #include <V3d_View.hxx>
45 #include <V3d_Viewer.hxx>
46
47 #ifdef _WIN32
48 struct Device
49 {
50         Device();
51         ~Device();
52         
53         PRINTDLG _pd;
54 };
55
56 //**********************************************************************
57
58 static Device device;
59
60 //**********************************************************************
61
62 Device::Device()
63 {
64         memset(&_pd, 0, sizeof(PRINTDLG));
65         _pd.hDevNames = NULL;
66         _pd.hDevMode = NULL;
67         _pd.lStructSize = sizeof(PRINTDLG);
68 }
69
70 //**********************************************************************
71
72 Device::~Device()
73 {       
74         // :TODO:
75         if (_pd.hDevNames) GlobalFree(_pd.hDevNames);
76         if (_pd.hDevMode) GlobalFree(_pd.hDevMode);
77         if (_pd.hDC) DeleteDC(_pd.hDC);
78 }
79 #endif
80
81 //=============================================================================
82 //function : SetGrid
83 //purpose  :
84 //=============================================================================
85 Standard_Boolean V3d_View::Print (const Aspect_Handle    thePrintDC,
86                                   const Standard_Boolean theShowDialog,
87                                   const Standard_Boolean theShowBackground,
88                                   const Standard_CString theFilename,
89                                   const Aspect_PrintAlgo thePrintAlgorithm) const
90 {
91 #ifdef _WIN32
92   if (myView->IsDefined())
93   {
94     if (thePrintDC != NULL)
95     {
96       return myView->Print (thePrintDC, theShowBackground, theFilename, thePrintAlgorithm);
97     }
98
99     if (device._pd.hDC == NULL || theShowDialog)
100     {
101       if (device._pd.hDC)
102         DeleteDC (device._pd.hDC);
103       if (!theShowDialog)
104       {
105         device._pd.Flags = PD_RETURNDC | PD_NOSELECTION | PD_RETURNDEFAULT;
106       }
107       else
108       {
109         device._pd.Flags = PD_RETURNDC | PD_NOSELECTION;
110       }
111
112       BOOL ispd;
113       ispd = PrintDlg((LPPRINTDLG)(&(device._pd)));
114
115       if (!ispd)
116       {
117         return Standard_False;
118       }
119
120       if (!(device._pd.hDC)) 
121       {
122         if (device._pd.hDevNames) 
123         {
124           GlobalFree (device._pd.hDevNames);
125           device._pd.hDevNames = NULL;
126         }
127         if (device._pd.hDevMode)
128         {
129           GlobalFree (device._pd.hDevMode);
130           device._pd.hDevMode = NULL;
131         }
132         MessageBox (0, "Couldn't create Printer Device Context", "Error", MB_OK | MB_ICONSTOP);
133         return Standard_False;
134       }
135     }
136
137     // process scale factor accordingly to the new printing approach
138     DEVMODE* aMode = (LPDEVMODE)GlobalLock(device._pd.hDevMode);
139
140     // convert percents to multiplication factor, 100% = 1.0
141     Standard_Real aScaleFactor = (Standard_Real) aMode->dmScale / 100.0;
142     GlobalUnlock (device._pd.hDevMode);
143     return myView->Print (device._pd.hDC, theShowBackground, theFilename, thePrintAlgorithm, aScaleFactor);
144   }
145 #else
146   Standard_NotImplemented::Raise ("V3d_View::Print is implemented only on Windows");
147 #endif
148   return Standard_False;
149 }