Mercurial > mercurial > hgweb_searcher03.cgi
diff src/preview.cpp @ 9:b455f2d8aac9
Implement Preview.
author | pyon@macmini |
---|---|
date | Thu, 24 Apr 2014 18:31:39 +0900 |
parents | |
children | 29021e6e1ebe |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/preview.cpp Thu Apr 24 18:31:39 2014 +0900 @@ -0,0 +1,90 @@ +// Filename : preview.cpp +// Last Change: 24-Apr-2014. +// + +#include "preview.h" +#define THUMB_W 60 +#define THUMB_H 75 + +PreviewDialog::PreviewDialog( wxWindow* parent, wxWindowID id, const wxString& title, const wxPoint& pos, const wxSize& size, long style ) + : wxDialog( parent, id, title, pos, size, style ) +{ + //this->SetSizeHints( wxDefaultSize, wxDefaultSize ); + + wxBoxSizer* bSizerTop = new wxBoxSizer( wxHORIZONTAL ); + + m_scrolledWindow = new wxScrolledWindow( this, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxALWAYS_SHOW_SB ); + m_bitmap = new wxStaticBitmap( m_scrolledWindow, wxID_ANY, wxNullBitmap, wxDefaultPosition, wxDefaultSize, 0 ); + bSizerTop->Add( m_scrolledWindow, 1, wxALL|wxEXPAND, 5 ); + + wxBoxSizer* bSizerMenu = new wxBoxSizer( wxVERTICAL ); + + /* + m_listCtrl = new wxListCtrl( this, ID_PLIST, wxDefaultPosition, wxSize( 140, -1 ), wxLC_ICON ); + m_imageList = new wxImageList( THUMB_W, THUMB_H ); + m_listCtrl->AssignImageList( m_imageList, wxIMAGE_LIST_NORMAL ); + bSizerMenu->Add( m_listCtrl, 1, wxRIGHT|wxLEFT|wxBOTTOM|wxEXPAND, 5 ); + */ + + m_buttonPrint = new wxButton( this, ID_PRINT, wxT("印刷"), wxDefaultPosition, wxDefaultSize, 0 ); + bSizerMenu->Add( m_buttonPrint, 0, wxALL, 5 ); + bSizerMenu->Add( 0, 0, 1, 0, 5 ); + + m_buttonClose = new wxButton( this, wxID_CANCEL, wxT("閉じる"), wxDefaultPosition, wxDefaultSize, 0 ); + m_buttonClose->SetDefault(); + bSizerMenu->Add( m_buttonClose, 0, wxALL, 5 ); + + bSizerTop->Add( bSizerMenu, 0, wxALL|wxEXPAND, 5 ); + + this->SetSizer( bSizerTop ); + this->Layout(); +} + +PreviewDialog::~PreviewDialog() +{ +} + +// Event Table +BEGIN_EVENT_TABLE( PreviewDialog, wxDialog ) + EVT_BUTTON( ID_PRINT, PreviewDialog::OnPrint ) +END_EVENT_TABLE() + +#define WIDTH 2480 +#define HEIGHT 3509 +void PreviewDialog::SetImage( wxString file ) +{ + int w, h; + m_scrolledWindow->GetSize( &w, &h ); + h = h * WIDTH / ( w - 200 ); + + wxImage img; + img.LoadFile( file, wxBITMAP_TYPE_JPEG ); + wxBitmap bmp( img.Scale( w, h, wxIMAGE_QUALITY_HIGH ) ); + m_bitmap->SetBitmap( bmp ); + + m_scrolledWindow->SetScrollbars( 10, 10, 0, h/10 ); + m_preview = file; +} + +void PreviewDialog::OnPrint( wxCommandEvent& WXUNUSED(envet) ) +{ + wxString html; + html = html + wxT("<html><body>\n"); + + wxString tmpjpg = wxGetCwd() + wxFILE_SEP_PATH + wxT("tmp") + wxFILE_SEP_PATH + wxT("preview.jpg"); + + wxCopyFile( m_preview, tmpjpg, true ); + + html = html + wxT("<img src=\"") + tmpjpg + wxT("\" width=\"750\" height=\"1060\"/>"); + html = html + wxT("</body></html>"); + + // start printing + wxHtmlPrintout hpout( wxT("Searcher03") ); + hpout.SetMargins( 0, 0, 0, 0, 0 ); + wxPrintDialogData pd; + wxPrinter p( &pd ); + + hpout.SetHtmlText( html, wxEmptyString, false ); + p.Print( NULL, &hpout, true ); +} +