prntdlgg.cpp
来自「A*算法 A*算法 A*算法 A*算法A*算法A*算法」· C++ 代码 · 共 1,108 行 · 第 1/3 页
CPP
1,108 行
/////////////////////////////////////////////////////////////////////////////
// Name: prntdlgg.cpp
// Purpose: Generic print dialogs
// Author: Julian Smart
// Modified by:
// Created: 04/01/98
// RCS-ID: $Id: prntdlgg.cpp,v 1.82.2.1 2005/11/08 18:11:12 JS Exp $
// Copyright: (c) Julian Smart
// Licence: wxWindows licence
/////////////////////////////////////////////////////////////////////////////
// ============================================================================
// declarations
// ============================================================================
// ----------------------------------------------------------------------------
// headers
// ----------------------------------------------------------------------------
#if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
#pragma implementation "prntdlgg.h"
#endif
// For compilers that support precompilation, includes "wx.h".
#include "wx/wxprec.h"
#ifdef __BORLANDC__
#pragma hdrstop
#endif
#if wxUSE_PRINTING_ARCHITECTURE && (!defined(__WXMSW__) || wxUSE_POSTSCRIPT_ARCHITECTURE_IN_MSW)
#ifndef WX_PRECOMP
#include "wx/utils.h"
#include "wx/dc.h"
#include "wx/stattext.h"
#include "wx/statbox.h"
#include "wx/button.h"
#include "wx/checkbox.h"
#include "wx/textctrl.h"
#include "wx/radiobox.h"
#include "wx/filedlg.h"
#include "wx/combobox.h"
#include "wx/intl.h"
#include "wx/sizer.h"
#include "wx/cmndata.h"
#endif
#if wxUSE_STATLINE
#include "wx/statline.h"
#endif
#include "wx/generic/prntdlgg.h"
#if wxUSE_POSTSCRIPT
#include "wx/generic/dcpsg.h"
#endif
#include "wx/prntbase.h"
#include "wx/printdlg.h"
#include "wx/paper.h"
#include "wx/filename.h"
#include "wx/tokenzr.h"
#include "wx/imaglist.h"
#include <stdlib.h>
#include <string.h>
#if wxUSE_LIBGNOMEPRINT
#include "wx/html/forcelnk.h"
FORCE_LINK(gnome_print)
#endif
// ----------------------------------------------------------------------------
// global vars
// ----------------------------------------------------------------------------
extern wxPrintPaperDatabase *wxThePrintPaperDatabase;
#if wxUSE_POSTSCRIPT
//----------------------------------------------------------------------------
// wxPostScriptNativeData
//----------------------------------------------------------------------------
IMPLEMENT_CLASS(wxPostScriptPrintNativeData, wxPrintNativeDataBase)
wxPostScriptPrintNativeData::wxPostScriptPrintNativeData()
{
m_previewCommand = wxEmptyString;
#ifdef __VMS__
m_printerCommand = wxT("print");
m_printerOptions = wxT("/nonotify/queue=psqueue");
m_afmPath = wxT("sys$ps_font_metrics:");
#endif
#ifdef __WXMSW__
m_printerCommand = wxT("print");
m_printerOptions = wxEmptyString;
m_afmPath = wxT("c:\\windows\\system\\");
#endif
#if !defined(__VMS__) && !defined(__WXMSW__)
m_printerCommand = wxT("lpr");
m_printerOptions = wxEmptyString;
m_afmPath = wxEmptyString;
#endif
m_printerScaleX = 1.0;
m_printerScaleY = 1.0;
m_printerTranslateX = 0;
m_printerTranslateY = 0;
}
wxPostScriptPrintNativeData::~wxPostScriptPrintNativeData()
{
}
bool wxPostScriptPrintNativeData::TransferTo( wxPrintData &WXUNUSED(data) )
{
return true;
}
bool wxPostScriptPrintNativeData::TransferFrom( const wxPrintData &WXUNUSED(data) )
{
return true;
}
// ----------------------------------------------------------------------------
// Generic print dialog for non-Windows printing use.
// ----------------------------------------------------------------------------
IMPLEMENT_CLASS(wxGenericPrintDialog, wxPrintDialogBase)
BEGIN_EVENT_TABLE(wxGenericPrintDialog, wxPrintDialogBase)
EVT_BUTTON(wxID_OK, wxGenericPrintDialog::OnOK)
EVT_BUTTON(wxPRINTID_SETUP, wxGenericPrintDialog::OnSetup)
EVT_RADIOBOX(wxPRINTID_RANGE, wxGenericPrintDialog::OnRange)
END_EVENT_TABLE()
wxGenericPrintDialog::wxGenericPrintDialog(wxWindow *parent,
wxPrintDialogData* data)
: wxPrintDialogBase(parent, wxID_ANY, _("Print"),
wxPoint(0,0), wxSize(600, 600),
wxDEFAULT_DIALOG_STYLE |
wxTAB_TRAVERSAL)
{
if ( data )
m_printDialogData = *data;
Init(parent);
}
wxGenericPrintDialog::wxGenericPrintDialog(wxWindow *parent,
wxPrintData* data)
: wxPrintDialogBase(parent, wxID_ANY, _("Print"),
wxPoint(0,0), wxSize(600, 600),
wxDEFAULT_DIALOG_STYLE |
wxTAB_TRAVERSAL)
{
if ( data )
m_printDialogData = *data;
Init(parent);
}
void wxGenericPrintDialog::Init(wxWindow * WXUNUSED(parent))
{
// wxDialog::Create(parent, wxID_ANY, _("Print"), wxPoint(0,0), wxSize(600, 600),
// wxDEFAULT_DIALOG_STYLE | wxTAB_TRAVERSAL);
wxBoxSizer *mainsizer = new wxBoxSizer( wxVERTICAL );
// 1) top row
wxPrintFactory* factory = wxPrintFactory::GetFactory();
wxStaticBoxSizer *topsizer = new wxStaticBoxSizer(
new wxStaticBox( this, wxID_ANY, _( "Printer options" ) ), wxHORIZONTAL );
wxFlexGridSizer *flex = new wxFlexGridSizer( 2 );
flex->AddGrowableCol( 1 );
topsizer->Add( flex, 1, wxGROW );
m_printToFileCheckBox = new wxCheckBox( this, wxPRINTID_PRINTTOFILE, _("Print to File") );
flex->Add( m_printToFileCheckBox, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5 );
m_setupButton = new wxButton(this, wxPRINTID_SETUP, _("Setup...") );
flex->Add( m_setupButton, 0, wxALIGN_CENTER_VERTICAL|wxALIGN_RIGHT|wxALL, 5 );
if (!factory->HasPrintSetupDialog())
m_setupButton->Enable( false );
if (factory->HasPrinterLine())
{
flex->Add( new wxStaticText( this, wxID_ANY, _("Printer:") ),
0, wxALIGN_CENTER_VERTICAL|wxALL, 5 );
flex->Add( new wxStaticText( this, wxID_ANY, factory->CreatePrinterLine() ),
0, wxALIGN_CENTER_VERTICAL|wxALL, 5 );
}
if (factory->HasStatusLine())
{
flex->Add( new wxStaticText( this, wxID_ANY, _("Status:") ),
0, wxALIGN_CENTER_VERTICAL|wxALL-wxTOP, 5 );
flex->Add( new wxStaticText( this, wxID_ANY, factory->CreateStatusLine() ),
0, wxALIGN_CENTER_VERTICAL|wxALL-wxTOP, 5 );
}
mainsizer->Add( topsizer, 0, wxLEFT|wxTOP|wxRIGHT|wxGROW, 10 );
// 2) middle row with radio box
wxString *choices = new wxString[2];
choices[0] = _("All");
choices[1] = _("Pages");
m_fromText = (wxTextCtrl*)NULL;
m_toText = (wxTextCtrl*)NULL;
m_rangeRadioBox = (wxRadioBox *)NULL;
if (m_printDialogData.GetFromPage() != 0)
{
m_rangeRadioBox = new wxRadioBox(this, wxPRINTID_RANGE, _("Print Range"),
wxDefaultPosition, wxDefaultSize,
2, choices,
1, wxRA_VERTICAL);
m_rangeRadioBox->SetSelection(1);
mainsizer->Add( m_rangeRadioBox, 0, wxLEFT|wxTOP|wxRIGHT, 10 );
}
// 3) bottom row
wxBoxSizer *bottomsizer = new wxBoxSizer( wxHORIZONTAL );
if (m_printDialogData.GetFromPage() != 0)
{
bottomsizer->Add( new wxStaticText(this, wxPRINTID_STATIC, _("From:") ), 0, wxCENTER|wxALL, 5 );
m_fromText = new wxTextCtrl(this, wxPRINTID_FROM, wxEmptyString, wxDefaultPosition, wxSize(40, wxDefaultCoord));
bottomsizer->Add( m_fromText, 1, wxCENTER|wxRIGHT, 10 );
bottomsizer->Add( new wxStaticText(this, wxPRINTID_STATIC, _("To:") ), 0, wxCENTER|wxALL, 5);
m_toText = new wxTextCtrl(this, wxPRINTID_TO, wxEmptyString, wxDefaultPosition, wxSize(40, wxDefaultCoord));
bottomsizer->Add( m_toText, 1, wxCENTER|wxRIGHT, 10 );
}
bottomsizer->Add( new wxStaticText(this, wxPRINTID_STATIC, _("Copies:") ), 0, wxCENTER|wxALL, 5 );
m_noCopiesText = new wxTextCtrl(this, wxPRINTID_COPIES, wxEmptyString, wxPoint(252, 130), wxSize(40, wxDefaultCoord));
bottomsizer->Add( m_noCopiesText, 1, wxCENTER|wxRIGHT, 10 );
mainsizer->Add( bottomsizer, 0, wxTOP|wxLEFT|wxRIGHT, 12 );
#if wxUSE_STATLINE
// 4) static line
mainsizer->Add( new wxStaticLine( this, wxID_ANY ), 0, wxEXPAND | wxLEFT|wxRIGHT|wxTOP, 10 );
#endif
// 5) buttons
mainsizer->Add( CreateButtonSizer( wxOK|wxCANCEL), 0, wxEXPAND|wxALL, 10 );
SetAutoLayout( true );
SetSizer( mainsizer );
mainsizer->Fit( this );
Centre(wxBOTH);
// Calls wxWindow::OnInitDialog and then wxGenericPrintDialog::TransferDataToWindow
InitDialog();
delete[] choices;
}
int wxGenericPrintDialog::ShowModal()
{
return wxDialog::ShowModal();
}
wxGenericPrintDialog::~wxGenericPrintDialog()
{
}
void wxGenericPrintDialog::OnOK(wxCommandEvent& WXUNUSED(event))
{
TransferDataFromWindow();
// An empty 'to' field signals printing just the
// 'from' page.
if (m_printDialogData.GetToPage() < 1)
m_printDialogData.SetToPage(m_printDialogData.GetFromPage());
// There are some interactions between the global setup data
// and the standard print dialog. The global printing 'mode'
// is determined by whether the user checks Print to file
// or not.
if (m_printDialogData.GetPrintToFile())
{
m_printDialogData.GetPrintData().SetPrintMode(wxPRINT_MODE_FILE);
wxFileName fname( m_printDialogData.GetPrintData().GetFilename() );
wxFileDialog dialog( this, _("PostScript file"),
fname.GetPath(), fname.GetFullName(), wxT("*.ps"), wxSAVE | wxOVERWRITE_PROMPT );
if (dialog.ShowModal() != wxID_OK) return;
m_printDialogData.GetPrintData().SetFilename( dialog.GetPath() );
}
else
{
m_printDialogData.GetPrintData().SetPrintMode(wxPRINT_MODE_PRINTER);
}
EndModal(wxID_OK);
}
void wxGenericPrintDialog::OnRange(wxCommandEvent& event)
{
if (!m_fromText) return;
if (event.GetInt() == 0)
{
m_fromText->Enable(false);
m_toText->Enable(false);
}
else if (event.GetInt() == 1)
{
m_fromText->Enable(true);
m_toText->Enable(true);
}
}
void wxGenericPrintDialog::OnSetup(wxCommandEvent& WXUNUSED(event))
{
wxPrintFactory* factory = wxPrintFactory::GetFactory();
if (factory->HasPrintSetupDialog())
{
// The print setup dialog should change the
// print data in-place if not cancelled.
wxDialog *dialog = factory->CreatePrintSetupDialog( this, &m_printDialogData.GetPrintData() );
dialog->ShowModal();
dialog->Destroy();
}
}
bool wxGenericPrintDialog::TransferDataToWindow()
{
if(m_printDialogData.GetFromPage() != 0)
{
if(m_fromText)
{
if (m_printDialogData.GetEnablePageNumbers())
{
m_fromText->Enable(true);
m_toText->Enable(true);
if (m_printDialogData.GetFromPage() > 0)
m_fromText->SetValue(wxString::Format(_T("%d"), m_printDialogData.GetFromPage()));
if (m_printDialogData.GetToPage() > 0)
m_toText->SetValue(wxString::Format(_T("%d"), m_printDialogData.GetToPage()));
if(m_rangeRadioBox)
if (m_printDialogData.GetAllPages() || m_printDialogData.GetFromPage() == 0)
m_rangeRadioBox->SetSelection(0);
else
m_rangeRadioBox->SetSelection(1);
}
else
{
m_fromText->Enable(false);
m_toText->Enable(false);
if(m_rangeRadioBox)
{
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?