0025137: The methods "Convert" point defined in the reference frame of the view into...
[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 WNT
22 #include <windows.h>
23 #pragma comment( lib, "comdlg32.lib"  )
24 #endif
25
26 #include <V3d_View.jxx>
27 #include <Standard_NotImplemented.hxx>
28
29 #ifdef WNT
30 struct Device
31 {
32         Device();
33         ~Device();
34         
35         PRINTDLG _pd;
36 };
37
38 //**********************************************************************
39
40 static Device device;
41
42 //**********************************************************************
43
44 Device::Device()
45 {
46         memset(&_pd, 0, sizeof(PRINTDLG));
47         _pd.hDevNames = NULL;
48         _pd.hDevMode = NULL;
49         _pd.lStructSize = sizeof(PRINTDLG);
50 }
51
52 //**********************************************************************
53
54 Device::~Device()
55 {       
56         // :TODO:
57         if (_pd.hDevNames) GlobalFree(_pd.hDevNames);
58         if (_pd.hDevMode) GlobalFree(_pd.hDevMode);
59         if (_pd.hDC) DeleteDC(_pd.hDC);
60 }
61 #endif
62
63 /************************************************************************/
64 /* Print Method                                                        */
65 /************************************************************************/
66
67 Standard_Boolean V3d_View::Print (const Aspect_Handle    hPrnDC,
68                                   const Standard_Boolean showDialog,
69                                   const Standard_Boolean showBackground,
70                                   const Standard_CString filename,
71                                   const Aspect_PrintAlgo printAlgorithm) const
72 {
73 #ifdef WNT
74         if( MyView->IsDefined() ) 
75         {
76                 if (hPrnDC != NULL)
77                 {
78                         return MyView->Print(hPrnDC, showBackground,
79                                              filename, printAlgorithm) ;
80                         
81                 }
82
83                 if (device._pd.hDC == NULL || showDialog )
84                 {
85                         if (device._pd.hDC)
86                                 DeleteDC(device._pd.hDC);
87                         if ( !showDialog )
88                         {
89                                 device._pd.Flags = PD_RETURNDC | PD_NOSELECTION | PD_RETURNDEFAULT;
90                         }
91                         else
92                         {
93                                 device._pd.Flags = PD_RETURNDC | PD_NOSELECTION;
94                         }
95
96                         BOOL    ispd;
97                         ispd = PrintDlg((LPPRINTDLG)(&(device._pd)));
98                 
99                         if (!ispd)
100                         {
101                                 return Standard_False;
102                         }
103                         
104                         if (!(device._pd.hDC)) 
105                         {
106                                 if (device._pd.hDevNames) 
107                                 {
108                                         GlobalFree(device._pd.hDevNames);
109                                         device._pd.hDevNames = NULL;
110                                 }
111                                 if (device._pd.hDevMode)
112                                 {
113                                         GlobalFree(device._pd.hDevMode);
114                                         device._pd.hDevMode = NULL;
115                                 }
116                                 MessageBox(0, "Couldn't create Printer Device Context", "Error", MB_OK | MB_ICONSTOP);
117                                 return Standard_False;
118                         }
119                 }
120
121     // process scale factor accordingly to the new printing approach
122     DEVMODE* aMode = (LPDEVMODE)GlobalLock(device._pd.hDevMode);
123
124     // convert percents to multiplication factor, 100% = 1.0
125     Standard_Real aScaleFactor = (Standard_Real) aMode->dmScale / 100.0;
126     GlobalUnlock (device._pd.hDevMode);
127    return MyView->Print(device._pd.hDC, showBackground,
128                         filename, printAlgorithm, aScaleFactor) ;
129         }
130 #else
131         Standard_NotImplemented::Raise ("V3d_View::Print is implemented only on Windows");
132 #endif
133   return Standard_False;
134 }