X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/c96acfeff6d057aace5b0870acc999218d6ac1cd..14722c43c30918cd8fbba956b50ac3426d2fe339:/src/gtk/print.cpp?ds=sidebyside diff --git a/src/gtk/print.cpp b/src/gtk/print.cpp index 39c517b0fd..7ef941c862 100644 --- a/src/gtk/print.cpp +++ b/src/gtk/print.cpp @@ -31,7 +31,6 @@ #endif #include "wx/fontutil.h" -#include "wx/gtk/private.h" #include "wx/dynlib.h" #include "wx/paper.h" @@ -57,7 +56,7 @@ wxFORCE_LINK_THIS_MODULE(gtk_print) #include "wx/gtk/private/object.h" -// Usefull to convert angles from/to Rad to/from Deg. +// 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; @@ -75,7 +74,7 @@ public: { #if wxUSE_LIBGNOMEPRINT // This module must be initialized AFTER gnomeprint's one - AddDependency(CLASSINFO(wxGnomePrintModule)); + AddDependency(wxCLASSINFO(wxGnomePrintModule)); #endif } bool OnInit(); @@ -87,8 +86,12 @@ private: bool wxGtkPrintModule::OnInit() { +#ifndef __WXGTK3__ if (gtk_check_version(2,10,0) == NULL) +#endif + { wxPrintFactory::SetPrintFactory( new wxGtkPrintFactory ); + } return true; } @@ -620,8 +623,6 @@ wxGtkPrintDialog::~wxGtkPrintDialog() // This is called even if we actually don't want the dialog to appear. int wxGtkPrintDialog::ShowModal() { - GtkPrintOperationResult response; - // We need to restore the settings given in the constructor. wxPrintData data = m_printDialogData.GetPrintData(); wxGtkPrintNativeData *native = @@ -655,10 +656,17 @@ int wxGtkPrintDialog::ShowModal() // Show the dialog if needed. GError* gError = NULL; - if (GetShowDialog()) - response = gtk_print_operation_run (printOp, GTK_PRINT_OPERATION_ACTION_PRINT_DIALOG, GTK_WINDOW(gtk_widget_get_toplevel(m_parent->m_widget) ), &gError); - else - response = gtk_print_operation_run (printOp, GTK_PRINT_OPERATION_ACTION_PRINT, GTK_WINDOW(gtk_widget_get_toplevel(m_parent->m_widget)), &gError); + GtkPrintOperationResult response = gtk_print_operation_run + ( + printOp, + GetShowDialog() + ? GTK_PRINT_OPERATION_ACTION_PRINT_DIALOG + : GTK_PRINT_OPERATION_ACTION_PRINT, + m_parent + ? GTK_WINDOW(gtk_widget_get_toplevel(m_parent->m_widget)) + : NULL, + &gError + ); // Does everything went well? if (response == GTK_PRINT_OPERATION_RESULT_CANCEL) @@ -771,7 +779,9 @@ int wxGtkPageSetupDialog::ShowModal() title = _("Page Setup"); GtkWidget * dlg = gtk_page_setup_unix_dialog_new(title.utf8_str(), - GTK_WINDOW(m_parent->m_widget)); + m_parent + ? GTK_WINDOW(m_parent->m_widget) + : NULL); gtk_page_setup_unix_dialog_set_print_settings( GTK_PAGE_SETUP_UNIX_DIALOG(dlg), nativeData); @@ -1206,6 +1216,11 @@ void* wxGtkPrinterDCImpl::GetCairoContext() const return (void*) cairo_reference( m_cairo ); } +void* wxGtkPrinterDCImpl::GetHandle() const +{ + return GetCairoContext(); +} + bool wxGtkPrinterDCImpl::DoFloodFill(wxCoord WXUNUSED(x1), wxCoord WXUNUSED(y1), const wxColour& WXUNUSED(col), @@ -1699,9 +1714,11 @@ void wxGtkPrinterDCImpl::DoDrawBitmap( const wxBitmap& bitmap, wxCoord x, wxCoor y = wxCoord(YLOG2DEV(y)); int bw = bitmap.GetWidth(); int bh = bitmap.GetHeight(); +#ifndef __WXGTK3__ wxBitmap bmpSource = bitmap; // we need a non-const instance. if (!useMask && !bitmap.HasPixbuf() && bitmap.GetMask()) bmpSource.SetMask(NULL); +#endif cairo_save(m_cairo); @@ -1713,12 +1730,16 @@ void wxGtkPrinterDCImpl::DoDrawBitmap( const wxBitmap& bitmap, wxCoord x, wxCoor wxDouble scaleY = (wxDouble) YLOG2DEVREL(bh) / (wxDouble) bh; cairo_scale(m_cairo, scaleX, scaleY); +#ifdef __WXGTK3__ + bitmap.Draw(m_cairo, 0, 0, useMask, &m_textForegroundColour, &m_textBackgroundColour); +#else gdk_cairo_set_source_pixbuf(m_cairo, bmpSource.GetPixbuf(), 0, 0); cairo_pattern_set_filter(cairo_get_source(m_cairo), CAIRO_FILTER_NEAREST); // Use the original size here since the context is scaled already. cairo_rectangle(m_cairo, 0, 0, bw, bh); // Fill the rectangle using the pattern. cairo_fill(m_cairo); +#endif CalcBoundingBox(0,0); CalcBoundingBox(bw,bh); @@ -1738,25 +1759,12 @@ void wxGtkPrinterDCImpl::DoDrawRotatedText(const wxString& text, wxCoord x, wxCo angle = -angle; - bool underlined = m_font.Ok() && m_font.GetUnderlined(); - const wxScopedCharBuffer data = text.utf8_str(); - size_t datalen = strlen(data); - pango_layout_set_text( m_layout, data, datalen); + pango_layout_set_text(m_layout, data, data.length()); - if (underlined) - { - PangoAttrList *attrs = pango_attr_list_new(); - PangoAttribute *a = pango_attr_underline_new(PANGO_UNDERLINE_SINGLE); - a->start_index = 0; - a->end_index = datalen; - pango_attr_list_insert(attrs, a); - pango_layout_set_attributes(m_layout, attrs); - pango_attr_list_unref(attrs); - } - - if (m_textForegroundColour.Ok()) + const bool setAttrs = m_font.GTKSetPangoAttrs(m_layout); + if (m_textForegroundColour.IsOk()) { unsigned char red = m_textForegroundColour.Red(); unsigned char blue = m_textForegroundColour.Blue(); @@ -1816,7 +1824,7 @@ void wxGtkPrinterDCImpl::DoDrawRotatedText(const wxString& text, wxCoord x, wxCo cairo_restore( m_cairo ); - if (underlined) + if (setAttrs) { // Undo underline attributes setting pango_layout_set_attributes(m_layout, NULL); @@ -1844,7 +1852,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 ); @@ -1861,7 +1869,7 @@ void wxGtkPrinterDCImpl::SetFont( const wxFont& font ) void wxGtkPrinterDCImpl::SetPen( const wxPen& pen ) { - if (!pen.Ok()) return; + if (!pen.IsOk()) return; m_pen = pen; @@ -1940,7 +1948,7 @@ void wxGtkPrinterDCImpl::SetPen( const wxPen& pen ) void wxGtkPrinterDCImpl::SetBrush( const wxBrush& brush ) { - if (!brush.Ok()) return; + if (!brush.IsOk()) return; m_brush = brush; @@ -2149,8 +2157,8 @@ void wxGtkPrinterDCImpl::DoGetTextExtent(const wxString& string, wxCoord *width, { // scale the font and apply it PangoFontDescription *desc = theFont->GetNativeFontInfo()->description; - float size = pango_font_description_get_size(desc); - size = size * GetFontPointSizeAdjustment(72.0); + oldSize = pango_font_description_get_size(desc); + const float size = oldSize * GetFontPointSizeAdjustment(72.0); pango_font_description_set_size(desc, (gint)size); pango_layout_set_font_description(m_layout, desc);