📄 gprint.cpp
字号:
}//----------------------------------------------------------------------------// wxGnomePrintSetupDialog//----------------------------------------------------------------------------IMPLEMENT_CLASS(wxGnomePrintDialog, wxPrintDialogBase)wxGnomePrintDialog::wxGnomePrintDialog( 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();}wxGnomePrintDialog::wxGnomePrintDialog( 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();}void wxGnomePrintDialog::Init(){ wxPrintData data = m_printDialogData.GetPrintData(); wxGnomePrintNativeData *native = (wxGnomePrintNativeData*) data.GetNativeData(); m_widget = gs_lgp->gnome_print_dialog_new( native->GetPrintJob(), (guchar*)"Print", GNOME_PRINT_DIALOG_RANGE|GNOME_PRINT_DIALOG_COPIES ); int flag = 0; if (m_printDialogData.GetEnableSelection()) flag |= GNOME_PRINT_RANGE_SELECTION; if (m_printDialogData.GetEnablePageNumbers()) flag |= GNOME_PRINT_RANGE_ALL|GNOME_PRINT_RANGE_RANGE; gs_lgp->gnome_print_dialog_construct_range_page( (GnomePrintDialog*) m_widget, flag, m_printDialogData.GetMinPage(), m_printDialogData.GetMaxPage(), NULL, NULL );}wxGnomePrintDialog::~wxGnomePrintDialog(){ m_widget = NULL;}int wxGnomePrintDialog::ShowModal(){ // Transfer data from m_printDalogData to dialog here int response = gtk_dialog_run (GTK_DIALOG (m_widget)); if (response == GNOME_PRINT_DIALOG_RESPONSE_CANCEL) { gtk_widget_destroy(m_widget); m_widget = NULL; return wxID_CANCEL; } gint copies = 1; gboolean collate = false; gs_lgp->gnome_print_dialog_get_copies( (GnomePrintDialog*) m_widget, &copies, &collate ); m_printDialogData.SetNoCopies( copies ); m_printDialogData.SetCollate( collate ); switch (gs_lgp->gnome_print_dialog_get_range( (GnomePrintDialog*) m_widget )) { case GNOME_PRINT_RANGE_SELECTION: m_printDialogData.SetSelection( true ); break; case GNOME_PRINT_RANGE_ALL: m_printDialogData.SetAllPages( true ); m_printDialogData.SetFromPage( 0 ); m_printDialogData.SetToPage( 9999 ); break; case GNOME_PRINT_RANGE_RANGE: default: gint start,end; gs_lgp->gnome_print_dialog_get_range_page( (GnomePrintDialog*) m_widget, &start, &end ); m_printDialogData.SetFromPage( start ); m_printDialogData.SetToPage( end ); break; } gtk_widget_destroy(m_widget); m_widget = NULL; if (response == GNOME_PRINT_DIALOG_RESPONSE_PREVIEW) return wxID_PREVIEW; return wxID_OK;}wxDC *wxGnomePrintDialog::GetPrintDC(){ // Later return NULL;}bool wxGnomePrintDialog::Validate(){ return true;}bool wxGnomePrintDialog::TransferDataToWindow(){ return true;}bool wxGnomePrintDialog::TransferDataFromWindow(){ return true;}//----------------------------------------------------------------------------// wxGnomePageSetupDialog//----------------------------------------------------------------------------IMPLEMENT_CLASS(wxGnomePageSetupDialog, wxPageSetupDialogBase)wxGnomePageSetupDialog::wxGnomePageSetupDialog( wxWindow *parent, wxPageSetupDialogData* data ){ if (data) m_pageDialogData = *data; wxGnomePrintNativeData *native = (wxGnomePrintNativeData*) m_pageDialogData.GetPrintData().GetNativeData(); // This is required as the page setup dialog // calculates wrong values otherwise. gs_lgp->gnome_print_config_set( native->GetPrintConfig(), (const guchar*) GNOME_PRINT_KEY_PREFERED_UNIT, (const guchar*) "Pts" ); m_widget = gtk_dialog_new(); gtk_window_set_title( GTK_WINDOW(m_widget), wxGTK_CONV( _("Page setup") ) ); GtkWidget *main = gs_lgp->gnome_paper_selector_new_with_flags( native->GetPrintConfig(), GNOME_PAPER_SELECTOR_MARGINS|GNOME_PAPER_SELECTOR_FEED_ORIENTATION ); gtk_container_set_border_width (GTK_CONTAINER (main), 8); gtk_widget_show (main); gtk_container_add( GTK_CONTAINER (GTK_DIALOG (m_widget)->vbox), main ); gtk_dialog_set_has_separator (GTK_DIALOG (m_widget), TRUE); gtk_dialog_add_buttons (GTK_DIALOG (m_widget), GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, GTK_STOCK_OK, GTK_RESPONSE_OK, NULL); gtk_dialog_set_default_response (GTK_DIALOG (m_widget), GTK_RESPONSE_OK);}wxGnomePageSetupDialog::~wxGnomePageSetupDialog(){}wxPageSetupDialogData& wxGnomePageSetupDialog::GetPageSetupDialogData(){ return m_pageDialogData;}int wxGnomePageSetupDialog::ShowModal(){ wxGnomePrintNativeData *native = (wxGnomePrintNativeData*) m_pageDialogData.GetPrintData().GetNativeData(); GnomePrintConfig *config = native->GetPrintConfig(); // Transfer data from m_pageDialogData to native dialog int ret = gtk_dialog_run( GTK_DIALOG(m_widget) ); if (ret == GTK_RESPONSE_OK) { // Transfer data back to m_pageDialogData // I don't know how querying the last parameter works // I cannot test it as the dialog is currently broken // anyways (it only works for points). double ml,mr,mt,mb,pw,ph; gs_lgp->gnome_print_config_get_length (config, (const guchar*) GNOME_PRINT_KEY_PAGE_MARGIN_LEFT, &ml, NULL); gs_lgp->gnome_print_config_get_length (config, (const guchar*) GNOME_PRINT_KEY_PAGE_MARGIN_RIGHT, &mr, NULL); gs_lgp->gnome_print_config_get_length (config, (const guchar*) GNOME_PRINT_KEY_PAGE_MARGIN_TOP, &mt, NULL); gs_lgp->gnome_print_config_get_length (config, (const guchar*) GNOME_PRINT_KEY_PAGE_MARGIN_BOTTOM, &mb, NULL); gs_lgp->gnome_print_config_get_length (config, (const guchar*) GNOME_PRINT_KEY_PAPER_WIDTH, &pw, NULL); gs_lgp->gnome_print_config_get_length (config, (const guchar*) GNOME_PRINT_KEY_PAPER_HEIGHT, &ph, NULL); // This probably assumes that the user entered the // values in Pts. Since that is the only the dialog // works right now, we need to fix this later. const GnomePrintUnit *mm_unit = gs_lgp->gnome_print_unit_get_by_abbreviation( (const guchar*) "mm" ); const GnomePrintUnit *pts_unit = gs_lgp->gnome_print_unit_get_by_abbreviation( (const guchar*) "Pts" ); gs_lgp->gnome_print_convert_distance( &ml, pts_unit, mm_unit ); gs_lgp->gnome_print_convert_distance( &mr, pts_unit, mm_unit ); gs_lgp->gnome_print_convert_distance( &mt, pts_unit, mm_unit ); gs_lgp->gnome_print_convert_distance( &mb, pts_unit, mm_unit ); gs_lgp->gnome_print_convert_distance( &pw, pts_unit, mm_unit ); gs_lgp->gnome_print_convert_distance( &ph, pts_unit, mm_unit ); m_pageDialogData.SetMarginTopLeft( wxPoint( (int)(ml+0.5), (int)(mt+0.5)) ); m_pageDialogData.SetMarginBottomRight( wxPoint( (int)(mr+0.5), (int)(mb+0.5)) ); m_pageDialogData.SetPaperSize( wxSize( (int)(pw+0.5), (int)(ph+0.5) ) );#if 0 wxPrintf( wxT("paper %d %d, top margin %d\n"), m_pageDialogData.GetPaperSize().x, m_pageDialogData.GetPaperSize().y, m_pageDialogData.GetMarginTopLeft().x );#endif ret = wxID_OK; } else { ret = wxID_CANCEL; } gtk_widget_destroy( m_widget ); m_widget = NULL; return ret;}bool wxGnomePageSetupDialog::Validate(){ return true;}bool wxGnomePageSetupDialog::TransferDataToWindow(){ return true;}bool wxGnomePageSetupDialog::TransferDataFromWindow(){ return true;}//----------------------------------------------------------------------------// wxGnomePrinter//----------------------------------------------------------------------------IMPLEMENT_CLASS(wxGnomePrinter, wxPrinterBase)wxGnomePrinter::wxGnomePrinter( wxPrintDialogData *data ) : wxPrinterBase( data ){ m_gpc = NULL; m_native_preview = false;}wxGnomePrinter::~wxGnomePrinter(){}bool wxGnomePrinter::Print(wxWindow *parent, wxPrintout *printout, bool prompt ){ if (!printout) { sm_lastError = wxPRINTER_ERROR; return false; } wxPrintData printdata = GetPrintDialogData().GetPrintData(); wxGnomePrintNativeData *native = (wxGnomePrintNativeData*) printdata.GetNativeData(); GnomePrintJob *job = gs_lgp->gnome_print_job_new( native->GetPrintConfig() ); m_gpc = gs_lgp->gnome_print_job_get_context (job); // The GnomePrintJob is temporarily stored in the // native print data as the native print dialog // needs to access it. native->SetPrintJob( job ); printout->SetIsPreview(false); if (m_printDialogData.GetMinPage() < 1) m_printDialogData.SetMinPage(1); if (m_printDialogData.GetMaxPage() < 1) m_printDialogData.SetMaxPage(9999); wxDC *dc; if (prompt) dc = PrintDialog( parent ); else dc = new wxGnomePrintDC( this ); if (m_native_preview) printout->SetIsPreview(true); if (!dc) { gs_lgp->gnome_print_job_close( job ); g_object_unref (job); sm_lastError = wxPRINTER_ERROR; return false; } wxSize ScreenPixels = wxGetDisplaySize(); wxSize ScreenMM = wxGetDisplaySizeMM(); printout->SetPPIScreen( (int) ((ScreenPixels.GetWidth() * 25.4) / ScreenMM.GetWidth()), (int) ((ScreenPixels.GetHeight() * 25.4) / ScreenMM.GetHeight()) ); printout->SetPPIPrinter( wxGnomePrintDC::GetResolution(), wxGnomePrintDC::GetResolution() ); printout->SetDC(dc); int w, h; dc->GetSize(&w, &h); printout->SetPageSizePixels((int)w, (int)h); printout->SetPaperRectPixels(wxRect(0, 0, w, h)); int mw, mh; dc->GetSizeMM(&mw, &mh); printout->SetPageSizeMM((int)mw, (int)mh); printout->OnPreparePrinting(); // Get some parameters from the printout, if defined int fromPage, toPage; int minPage, maxPage; printout->GetPageInfo(&minPage, &maxPage, &fromPage, &toPage); if (maxPage == 0) { gs_lgp->gnome_print_job_close( job ); g_object_unref (job); sm_lastError = wxPRINTER_ERROR; return false; } printout->OnBeginPrinting(); int minPageNum = minPage, maxPageNum = maxPage; if ( !m_printDialogData.GetAllPages() ) { minPageNum = m_printDialogData.GetFromPage(); maxPageNum = m_printDialogData.GetToPage(); } int copyCount; for ( copyCount = 1; copyCount <= m_printDialogData.GetNoCopies(); copyCount++ ) { if (!printout->OnBeginDocument(minPageNum, maxPageNum)) { wxLogError(_("Could not start printing.")); sm_lastError = wxPRINTER_ERROR; break; } int pn; for ( pn = minPageNum; pn <= maxPageNum && printout->HasPage(pn); pn++ ) { dc->StartPage(); printout->OnPrintPage(pn); dc->EndPage(); } printout->OnEndDocument(); printout->OnEndPrinting();
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -