X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/820ec9bbc2ca025f9038b172a910617d8beb89a0..d3f81b85331b14943862a0c0df5ef8adb4426ad4:/src/gtk/print.cpp diff --git a/src/gtk/print.cpp b/src/gtk/print.cpp index a081a16877..071c5e6733 100644 --- a/src/gtk/print.cpp +++ b/src/gtk/print.cpp @@ -1,5 +1,5 @@ ///////////////////////////////////////////////////////////////////////////// -// Name: wx/gtk/print.cpp +// Name: src/gtk/print.cpp // Author: Anthony Bretaudeau // Purpose: GTK printing support // Created: 2007-08-25 @@ -37,6 +37,13 @@ #include +#if GTK_CHECK_VERSION(2,14,0) +#include +#else +#include +#endif + + #if wxUSE_GRAPHICS_CONTEXT #include "wx/graphics.h" #endif @@ -48,7 +55,9 @@ wxFORCE_LINK_THIS_MODULE(gtk_print) #include "wx/gtk/gnome/gprint.h" #endif -// Usefull to convert angles from/to Rad to/from Deg. +#include "wx/gtk/private/object.h" + +// Useful to convert angles from/to Rad to/from Deg. static const double RAD2DEG = 180.0 / M_PI; static const double DEG2RAD = M_PI / 180.0; @@ -389,6 +398,9 @@ bool wxGtkPrintNativeData::TransferTo( wxPrintData &data ) data.SetPaperId( wxPAPER_FANFOLD_LGL_GERMAN); else data.SetPaperId(wxPAPER_NONE); + + data.SetPrinterName(gtk_print_settings_get_printer(m_config)); + return true; } @@ -537,6 +549,8 @@ bool wxGtkPrintNativeData::TransferFrom( const wxPrintData &data ) default: break; } + gtk_print_settings_set_printer(m_config, data.GetPrinterName().utf8_str()); + return true; } @@ -653,8 +667,8 @@ int wxGtkPrintDialog::ShowModal() } else if (response == GTK_PRINT_OPERATION_RESULT_ERROR) { + wxLogError(_("Error while printing: ") + wxString(gError ? gError->message : "???")); g_error_free (gError); - wxLogError(_("Error while printing: ") + wxString::Format(_("%s"), gError->message)); return wxID_NO; // We use wxID_NO because there is no wxID_ERROR available } @@ -663,6 +677,12 @@ int wxGtkPrintDialog::ShowModal() native->SetPrintConfig(newSettings); data.ConvertFromNative(); + // Set PrintDialogData variables + m_printDialogData.SetPrintData(data); + m_printDialogData.SetCollate(data.GetCollate()); + m_printDialogData.SetNoCopies(data.GetNoCopies()); + m_printDialogData.SetPrintToFile(data.GetPrinterName() == "Print to File"); + // Same problem as a few lines before. switch (gtk_print_settings_get_print_pages(newSettings)) { @@ -740,43 +760,80 @@ int wxGtkPageSetupDialog::ShowModal() } } - // Now show the dialog. - GtkPageSetup* newPageSetup = gtk_print_run_page_setup_dialog (GTK_WINDOW(m_parent->m_widget), - oldPageSetup, - nativeData); - - int ret; - if (newPageSetup != oldPageSetup) - { - native->SetPageSetupToSettings(nativeData, newPageSetup); - m_pageDialogData.GetPrintData().ConvertFromNative(); - // Store custom paper format if any. - if (m_pageDialogData.GetPrintData().GetPaperId() == wxPAPER_NONE) - { - gdouble ml,mr,mt,mb,pw,ph; - ml = gtk_page_setup_get_left_margin (newPageSetup, GTK_UNIT_MM); - mr = gtk_page_setup_get_right_margin (newPageSetup, GTK_UNIT_MM); - mt = gtk_page_setup_get_top_margin (newPageSetup, GTK_UNIT_MM); - mb = gtk_page_setup_get_bottom_margin (newPageSetup, GTK_UNIT_MM); + // Set selected printer + gtk_print_settings_set(nativeData, "format-for-printer", + gtk_print_settings_get_printer(nativeData)); - pw = gtk_page_setup_get_paper_width (newPageSetup, GTK_UNIT_MM); - ph = gtk_page_setup_get_paper_height (newPageSetup, GTK_UNIT_MM); + // Create custom dialog + wxString title(GetTitle()); + if ( title.empty() ) + title = _("Page Setup"); + GtkWidget * + dlg = gtk_page_setup_unix_dialog_new(title.utf8_str(), + GTK_WINDOW(m_parent->m_widget)); - m_pageDialogData.SetMarginTopLeft( wxPoint( (int)(ml+0.5), (int)(mt+0.5)) ); - m_pageDialogData.SetMarginBottomRight( wxPoint( (int)(mr+0.5), (int)(mb+0.5)) ); + gtk_page_setup_unix_dialog_set_print_settings( + GTK_PAGE_SETUP_UNIX_DIALOG(dlg), nativeData); + gtk_page_setup_unix_dialog_set_page_setup( + GTK_PAGE_SETUP_UNIX_DIALOG(dlg), oldPageSetup); - m_pageDialogData.SetPaperSize( wxSize( (int)(pw+0.5), (int)(ph+0.5) ) ); - } + int result = gtk_dialog_run(GTK_DIALOG(dlg)); + gtk_widget_hide(dlg); - ret = wxID_OK; - } - else + switch ( result ) { - ret = wxID_CANCEL; + case GTK_RESPONSE_OK: + case GTK_RESPONSE_APPLY: + { + // Store Selected Printer Name + gtk_print_settings_set_printer + ( + nativeData, + gtk_print_settings_get(nativeData, "format-for-printer") + ); + + wxGtkObject + newPageSetup(gtk_page_setup_unix_dialog_get_page_setup( + GTK_PAGE_SETUP_UNIX_DIALOG(dlg))); + native->SetPageSetupToSettings(nativeData, newPageSetup); + + m_pageDialogData.GetPrintData().ConvertFromNative(); + + // Store custom paper format if any. + if ( m_pageDialogData.GetPrintData().GetPaperId() == wxPAPER_NONE ) + { + gdouble ml,mr,mt,mb,pw,ph; + ml = gtk_page_setup_get_left_margin (newPageSetup, GTK_UNIT_MM); + mr = gtk_page_setup_get_right_margin (newPageSetup, GTK_UNIT_MM); + mt = gtk_page_setup_get_top_margin (newPageSetup, GTK_UNIT_MM); + mb = gtk_page_setup_get_bottom_margin (newPageSetup, GTK_UNIT_MM); + + pw = gtk_page_setup_get_paper_width (newPageSetup, GTK_UNIT_MM); + ph = gtk_page_setup_get_paper_height (newPageSetup, GTK_UNIT_MM); + + 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))); + } + + result = wxID_OK; + } + break; + + default: + case GTK_RESPONSE_CANCEL: + result = wxID_CANCEL; + break; } - return ret; + gtk_widget_destroy(dlg); + + return result; } //---------------------------------------------------------------------------- @@ -1681,7 +1738,7 @@ void wxGtkPrinterDCImpl::DoDrawRotatedText(const wxString& text, wxCoord x, wxCo angle = -angle; - bool underlined = m_font.Ok() && m_font.GetUnderlined(); + bool underlined = m_font.IsOk() && m_font.GetUnderlined(); const wxScopedCharBuffer data = text.utf8_str(); @@ -1699,7 +1756,7 @@ void wxGtkPrinterDCImpl::DoDrawRotatedText(const wxString& text, wxCoord x, wxCo pango_attr_list_unref(attrs); } - if (m_textForegroundColour.Ok()) + if (m_textForegroundColour.IsOk()) { unsigned char red = m_textForegroundColour.Red(); unsigned char blue = m_textForegroundColour.Blue(); @@ -1787,7 +1844,7 @@ void wxGtkPrinterDCImpl::SetFont( const wxFont& font ) { m_font = font; - if (m_font.Ok()) + if (m_font.IsOk()) { if (m_fontdesc) pango_font_description_free( m_fontdesc ); @@ -1804,7 +1861,7 @@ void wxGtkPrinterDCImpl::SetFont( const wxFont& font ) void wxGtkPrinterDCImpl::SetPen( const wxPen& pen ) { - if (!pen.Ok()) return; + if (!pen.IsOk()) return; m_pen = pen; @@ -1883,7 +1940,7 @@ void wxGtkPrinterDCImpl::SetPen( const wxPen& pen ) void wxGtkPrinterDCImpl::SetBrush( const wxBrush& brush ) { - if (!brush.Ok()) return; + if (!brush.IsOk()) return; m_brush = brush; @@ -2156,7 +2213,7 @@ void wxGtkPrinterDCImpl::SetPrintData(const wxPrintData& data) m_printData = data; } -// overriden for wxPrinterDC Impl +// overridden for wxPrinterDC Impl wxRect wxGtkPrinterDCImpl::GetPaperRect() const { @@ -2257,8 +2314,14 @@ void wxGtkPrintPreview::DetermineScaling() if (paper) { - m_previewPrintout->SetPPIScreen(wxGetDisplayPPI()); - m_previewPrintout->SetPPIPrinter( m_resolution, m_resolution ); + const wxSize screenPPI = wxGetDisplayPPI(); + int logPPIScreenX = screenPPI.GetWidth(); + int logPPIScreenY = screenPPI.GetHeight(); + int logPPIPrinterX = m_resolution; + int logPPIPrinterY = m_resolution; + + m_previewPrintout->SetPPIScreen( logPPIScreenX, logPPIScreenY ); + m_previewPrintout->SetPPIPrinter( logPPIPrinterX, logPPIPrinterY ); // Get width and height in points (1/72th of an inch) wxSize sizeDevUnits(paper->GetSizeDeviceUnits()); @@ -2285,8 +2348,8 @@ void wxGtkPrintPreview::DetermineScaling() m_previewPrintout->SetPaperRectPixels(wxRect(0, 0, m_pageWidth, m_pageHeight)); // At 100%, the page should look about page-size on the screen. - m_previewScaleX = 0.8 * 72.0 / (double)m_resolution; - m_previewScaleY = m_previewScaleX; + m_previewScaleX = float(logPPIScreenX) / logPPIPrinterX; + m_previewScaleY = float(logPPIScreenY) / logPPIPrinterY; } }