Commit | Line | Data |
---|---|---|
7fd59977 | 1 | // File V3d_View_Print.cxx |
2 | // Created March 2000 | |
3 | // Author THA | |
4 | // e-mail t-hartl@muenchen.matra-dtv.fr | |
5 | ||
6 | /************************************************************************/ | |
7 | /* Includes */ | |
8 | /************************************************************************/ | |
9 | ||
10 | #ifdef WNT | |
11 | #include <windows.h> | |
12 | #pragma comment( lib, "comdlg32.lib" ) | |
13 | #endif | |
14 | ||
15 | #include <V3d_View.jxx> | |
16 | #include <Standard_NotImplemented.hxx> | |
17 | ||
18 | #ifdef WNT | |
19 | struct Device | |
20 | { | |
21 | Device(); | |
22 | ~Device(); | |
23 | ||
24 | PRINTDLG _pd; | |
25 | }; | |
26 | ||
27 | //********************************************************************** | |
28 | ||
29 | static Device device; | |
30 | ||
31 | //********************************************************************** | |
32 | ||
33 | Device::Device() | |
34 | { | |
35 | memset(&_pd, 0, sizeof(PRINTDLG)); | |
36 | _pd.hDevNames = NULL; | |
37 | _pd.hDevMode = NULL; | |
38 | _pd.lStructSize = sizeof(PRINTDLG); | |
39 | } | |
40 | ||
41 | //********************************************************************** | |
42 | ||
43 | Device::~Device() | |
44 | { | |
45 | // :TODO: | |
46 | if (_pd.hDevNames) GlobalFree(_pd.hDevNames); | |
47 | if (_pd.hDevMode) GlobalFree(_pd.hDevMode); | |
48 | if (_pd.hDC) DeleteDC(_pd.hDC); | |
49 | } | |
50 | #endif | |
51 | ||
52 | /************************************************************************/ | |
53 | /* Print Method */ | |
54 | /************************************************************************/ | |
55 | ||
7edf74fd A |
56 | Standard_Boolean V3d_View::Print (const Aspect_Handle hPrnDC, |
57 | const Standard_Boolean showDialog, | |
58 | const Standard_Boolean showBackground, | |
59 | const Standard_CString filename, | |
60 | const Aspect_PrintAlgo printAlgorithm) const | |
7fd59977 | 61 | { |
62 | #ifdef WNT | |
63 | if( MyView->IsDefined() ) | |
64 | { | |
65 | if (hPrnDC != NULL) | |
66 | { | |
7edf74fd A |
67 | return MyView->Print(hPrnDC, showBackground, |
68 | filename, printAlgorithm) ; | |
69 | ||
7fd59977 | 70 | } |
71 | ||
72 | if (device._pd.hDC == NULL || showDialog ) | |
73 | { | |
74 | if (device._pd.hDC) | |
75 | DeleteDC(device._pd.hDC); | |
76 | if ( !showDialog ) | |
77 | { | |
78 | device._pd.Flags = PD_RETURNDC | PD_NOSELECTION | PD_RETURNDEFAULT; | |
79 | } | |
80 | else | |
81 | { | |
82 | device._pd.Flags = PD_RETURNDC | PD_NOSELECTION; | |
83 | } | |
84 | ||
85 | BOOL ispd; | |
86 | ispd = PrintDlg((LPPRINTDLG)(&(device._pd))); | |
87 | ||
88 | if (!ispd) | |
89 | { | |
7edf74fd | 90 | return Standard_False; |
7fd59977 | 91 | } |
92 | ||
93 | if (!(device._pd.hDC)) | |
94 | { | |
95 | if (device._pd.hDevNames) | |
96 | { | |
97 | GlobalFree(device._pd.hDevNames); | |
98 | device._pd.hDevNames = NULL; | |
99 | } | |
100 | if (device._pd.hDevMode) | |
101 | { | |
102 | GlobalFree(device._pd.hDevMode); | |
103 | device._pd.hDevMode = NULL; | |
104 | } | |
105 | MessageBox(0, "Couldn't create Printer Device Context", "Error", MB_OK | MB_ICONSTOP); | |
7edf74fd | 106 | return Standard_False; |
7fd59977 | 107 | } |
108 | } | |
7edf74fd A |
109 | |
110 | // process scale factor accordingly to the new printing approach | |
111 | DEVMODE* aMode = (LPDEVMODE)GlobalLock(device._pd.hDevMode); | |
112 | ||
113 | // convert percents to multiplication factor, 100% = 1.0 | |
114 | Standard_Real aScaleFactor = (Standard_Real) aMode->dmScale / 100.0; | |
115 | GlobalUnlock (device._pd.hDevMode); | |
116 | return MyView->Print(device._pd.hDC, showBackground, | |
117 | filename, printAlgorithm, aScaleFactor) ; | |
7fd59977 | 118 | } |
119 | #else | |
120 | Standard_NotImplemented::Raise ("V3d_View::Print is implemented only on Windows"); | |
121 | #endif | |
7edf74fd | 122 | return Standard_False; |
7fd59977 | 123 | } |