Mercurial > mercurial > hgweb_searcher03.cgi
comparison src/preview.cpp @ 9:b455f2d8aac9
Implement Preview.
author | pyon@macmini |
---|---|
date | Thu, 24 Apr 2014 18:31:39 +0900 |
parents | |
children | 29021e6e1ebe |
comparison
equal
deleted
inserted
replaced
8:4967d1e2b30c | 9:b455f2d8aac9 |
---|---|
1 // Filename : preview.cpp | |
2 // Last Change: 24-Apr-2014. | |
3 // | |
4 | |
5 #include "preview.h" | |
6 #define THUMB_W 60 | |
7 #define THUMB_H 75 | |
8 | |
9 PreviewDialog::PreviewDialog( wxWindow* parent, wxWindowID id, const wxString& title, const wxPoint& pos, const wxSize& size, long style ) | |
10 : wxDialog( parent, id, title, pos, size, style ) | |
11 { | |
12 //this->SetSizeHints( wxDefaultSize, wxDefaultSize ); | |
13 | |
14 wxBoxSizer* bSizerTop = new wxBoxSizer( wxHORIZONTAL ); | |
15 | |
16 m_scrolledWindow = new wxScrolledWindow( this, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxALWAYS_SHOW_SB ); | |
17 m_bitmap = new wxStaticBitmap( m_scrolledWindow, wxID_ANY, wxNullBitmap, wxDefaultPosition, wxDefaultSize, 0 ); | |
18 bSizerTop->Add( m_scrolledWindow, 1, wxALL|wxEXPAND, 5 ); | |
19 | |
20 wxBoxSizer* bSizerMenu = new wxBoxSizer( wxVERTICAL ); | |
21 | |
22 /* | |
23 m_listCtrl = new wxListCtrl( this, ID_PLIST, wxDefaultPosition, wxSize( 140, -1 ), wxLC_ICON ); | |
24 m_imageList = new wxImageList( THUMB_W, THUMB_H ); | |
25 m_listCtrl->AssignImageList( m_imageList, wxIMAGE_LIST_NORMAL ); | |
26 bSizerMenu->Add( m_listCtrl, 1, wxRIGHT|wxLEFT|wxBOTTOM|wxEXPAND, 5 ); | |
27 */ | |
28 | |
29 m_buttonPrint = new wxButton( this, ID_PRINT, wxT("印刷"), wxDefaultPosition, wxDefaultSize, 0 ); | |
30 bSizerMenu->Add( m_buttonPrint, 0, wxALL, 5 ); | |
31 bSizerMenu->Add( 0, 0, 1, 0, 5 ); | |
32 | |
33 m_buttonClose = new wxButton( this, wxID_CANCEL, wxT("閉じる"), wxDefaultPosition, wxDefaultSize, 0 ); | |
34 m_buttonClose->SetDefault(); | |
35 bSizerMenu->Add( m_buttonClose, 0, wxALL, 5 ); | |
36 | |
37 bSizerTop->Add( bSizerMenu, 0, wxALL|wxEXPAND, 5 ); | |
38 | |
39 this->SetSizer( bSizerTop ); | |
40 this->Layout(); | |
41 } | |
42 | |
43 PreviewDialog::~PreviewDialog() | |
44 { | |
45 } | |
46 | |
47 // Event Table | |
48 BEGIN_EVENT_TABLE( PreviewDialog, wxDialog ) | |
49 EVT_BUTTON( ID_PRINT, PreviewDialog::OnPrint ) | |
50 END_EVENT_TABLE() | |
51 | |
52 #define WIDTH 2480 | |
53 #define HEIGHT 3509 | |
54 void PreviewDialog::SetImage( wxString file ) | |
55 { | |
56 int w, h; | |
57 m_scrolledWindow->GetSize( &w, &h ); | |
58 h = h * WIDTH / ( w - 200 ); | |
59 | |
60 wxImage img; | |
61 img.LoadFile( file, wxBITMAP_TYPE_JPEG ); | |
62 wxBitmap bmp( img.Scale( w, h, wxIMAGE_QUALITY_HIGH ) ); | |
63 m_bitmap->SetBitmap( bmp ); | |
64 | |
65 m_scrolledWindow->SetScrollbars( 10, 10, 0, h/10 ); | |
66 m_preview = file; | |
67 } | |
68 | |
69 void PreviewDialog::OnPrint( wxCommandEvent& WXUNUSED(envet) ) | |
70 { | |
71 wxString html; | |
72 html = html + wxT("<html><body>\n"); | |
73 | |
74 wxString tmpjpg = wxGetCwd() + wxFILE_SEP_PATH + wxT("tmp") + wxFILE_SEP_PATH + wxT("preview.jpg"); | |
75 | |
76 wxCopyFile( m_preview, tmpjpg, true ); | |
77 | |
78 html = html + wxT("<img src=\"") + tmpjpg + wxT("\" width=\"750\" height=\"1060\"/>"); | |
79 html = html + wxT("</body></html>"); | |
80 | |
81 // start printing | |
82 wxHtmlPrintout hpout( wxT("Searcher03") ); | |
83 hpout.SetMargins( 0, 0, 0, 0, 0 ); | |
84 wxPrintDialogData pd; | |
85 wxPrinter p( &pd ); | |
86 | |
87 hpout.SetHtmlText( html, wxEmptyString, false ); | |
88 p.Print( NULL, &hpout, true ); | |
89 } | |
90 |