1//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
2/// Name:         wxCasPrint Class
3///
4/// Purpose:      Manage statistics image printing
5///
6/// Author:       ThePolish <thepolish@vipmail.ru>
7///
8/// Copyright (c) 2004-2011 ThePolish ( thepolish@vipmail.ru )
9///
10/// Derived from CAS by Pedro de Oliveira <falso@rdk.homeip.net>
11///
12/// Pixmaps from aMule http://www.amule.org
13///
14/// This program is free software; you can redistribute it and/or modify
15///  it under the terms of the GNU General Public License as published by
16/// the Free Software Foundation; either version 2 of the License, or
17/// (at your option) any later version.
18///
19/// This program is distributed in the hope that it will be useful,
20/// but WITHOUT ANY WARRANTY; without even the implied warranty of
21/// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
22/// GNU General Public License for more details.
23///
24/// You should have received a copy of the GNU General Public License
25/// along with this program; if not, write to the
26/// Free Software Foundation, Inc.,
27/// 51 Franklin St, Fifth Floor, Boston, MA  02110-1301, USA
28//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
29
30
31#ifdef __BORLANDC__
32 #pragma hdrstop
33#endif
34
35// For all others, include the necessary headers
36#ifndef WX_PRECOMP
37 #include "wx/wx.h"
38#endif
39
40#include <wx/image.h>
41
42#include "wxcas.h"
43#include "wxcasframe.h"
44#include "wxcasprint.h"
45
46// Constructor
47WxCasPrint::WxCasPrint ( const wxString& title ) : wxPrintout ( title )
48{}
49
50// Destructor
51WxCasPrint::~WxCasPrint ()
52{}
53
54bool
55WxCasPrint::OnPrintPage ( int page )
56{
57	wxDC * dc = GetDC ();
58	if ( dc ) {
59		if ( page == 1 ) {
60			DrawPageOne ( dc );
61		}
62
63
64		dc->SetDeviceOrigin ( 0, 0 );
65		dc->SetUserScale ( 1.0, 1.0 );
66
67		return TRUE;
68	} else {
69		return FALSE;
70	}
71}
72
73bool
74WxCasPrint::OnBeginDocument ( int startPage, int endPage )
75{
76	if ( !wxPrintout::OnBeginDocument ( startPage, endPage ) ) {
77		return FALSE;
78	} else {
79		return TRUE;
80	}
81}
82
83void
84WxCasPrint::GetPageInfo ( int *minPage, int *maxPage, int *selPageFrom,
85                          int *selPageTo )
86{
87	*minPage = 1;
88	*maxPage = 1;
89	*selPageFrom = 1;
90	*selPageTo = 1;
91}
92
93bool
94WxCasPrint::HasPage ( int pageNum )
95{
96	return ( pageNum == 1 );
97}
98
99void
100WxCasPrint::DrawPageOne ( wxDC * dc )
101{
102	wxInt32 dc_w, dc_h;
103
104	// Get the size of the DC in pixels
105	dc->GetSize ( &dc_w, &dc_h );
106
107	// Get the size of the image in pixels
108	wxImage *statImage = wxGetApp ().GetMainFrame () ->GetStatImage ();
109
110	wxUint32 marginX = 50;
111	wxUint32 marginY = 50;
112
113	wxUint32 sizeX = statImage->GetWidth () + 2 * marginX;
114	wxUint32 sizeY = statImage->GetHeight () + 2 * marginY;
115
116	// Calculate a suitable scaling factor
117	float scale = wxMin ( ( float ) ( dc_w ) / sizeX, ( float ) ( dc_h ) / sizeY );
118
119	// Calculate the position on the DC for centring the graphic
120	float posX = marginX + ( dc_w - sizeX * scale ) / 2.0;
121	float posY = marginY + ( dc_h - sizeY * scale ) / 2.0;
122
123	// Set the scale and origin
124	dc->SetUserScale ( scale, scale );
125	dc->SetDeviceOrigin ( ( wxCoord ) posX, ( wxCoord ) posY );
126
127	// Draw image
128	dc->DrawBitmap ( wxBitmap( *statImage ), 0, 0, FALSE );
129}
130// File_checked_for_headers
131