]> git.saurik.com Git - wxWidgets.git/blobdiff - src/gtk/print.cpp
another 64 bit fix: make SendMsg() return wxIntPtr instead of long too
[wxWidgets.git] / src / gtk / print.cpp
index d19b567da547e531ece7ad04a6709c5a640204e7..a1cd4c3043d578abf9a0f9f28bcfe2def6b8fdbb 100644 (file)
 #include <gtk/gtk.h>
 #include <gtk/gtkpagesetupunixdialog.h>
 
+#if wxUSE_GRAPHICS_CONTEXT
+#include "wx/graphics.h"
+#endif
+
 #include "wx/link.h"
 wxFORCE_LINK_THIS_MODULE(gtk_print)
 
@@ -1095,11 +1099,23 @@ bool wxGtkPrinter::Setup( wxWindow * WXUNUSED(parent) )
 // wxGtkPrinterDC
 //-----------------------------------------------------------------------------
 
+#define wxCAIRO_SCALE 1
+
+#if wxCAIRO_SCALE
+
+#define XLOG2DEV(x)     LogicalToDeviceX(x)
+#define XLOG2DEVREL(x)  LogicalToDeviceXRel(x)
+#define YLOG2DEV(x)     LogicalToDeviceY(x)
+#define YLOG2DEVREL(x)  LogicalToDeviceYRel(x)
+
+#else
+
 #define XLOG2DEV(x)     ((double)(LogicalToDeviceX(x)) * m_DEV2PS)
 #define XLOG2DEVREL(x)  ((double)(LogicalToDeviceXRel(x)) * m_DEV2PS)
 #define YLOG2DEV(x)     ((double)(LogicalToDeviceY(x)) * m_DEV2PS)
 #define YLOG2DEVREL(x)  ((double)(LogicalToDeviceYRel(x)) * m_DEV2PS)
 
+#endif
 
 IMPLEMENT_ABSTRACT_CLASS(wxGtkPrinterDCImpl, wxDCImpl)
 
@@ -1118,15 +1134,22 @@ wxGtkPrinterDCImpl::wxGtkPrinterDCImpl(wxPrinterDC *owner, const wxPrintData& da
     if (m_resolution < 0)
         m_resolution = (1 << (m_resolution+4)) *150;
 
-    m_PS2DEV = (double)m_resolution / 72.0;
-    m_DEV2PS = 72.0 / (double)m_resolution;
-
     m_context = gtk_print_context_create_pango_context( m_gpc );
     m_layout = gtk_print_context_create_pango_layout ( m_gpc );
     m_fontdesc = pango_font_description_from_string( "Sans 12" );
 
     m_cairo = gtk_print_context_get_cairo_context ( m_gpc );
 
+#if wxCAIRO_SCALE
+    m_PS2DEV = 1.0;
+    m_DEV2PS = 1.0;
+    
+    gs_cairo->cairo_scale( m_cairo, 72.0 / (double)m_resolution, 72.0 / (double)m_resolution );
+#else
+    m_PS2DEV = (double)m_resolution / 72.0;
+    m_DEV2PS = 72.0 / (double)m_resolution;
+#endif
+
     m_currentRed = 0;
     m_currentBlue = 0;
     m_currentGreen = 0;
@@ -1155,6 +1178,11 @@ bool wxGtkPrinterDCImpl::IsOk() const
     return m_gpc != NULL;
 }
 
+void* wxGtkPrinterDCImpl::GetCairoContext() const
+{
+    return (void*) cairo_reference( m_cairo );
+}
+
 bool wxGtkPrinterDCImpl::DoFloodFill(wxCoord WXUNUSED(x1),
                                wxCoord WXUNUSED(y1),
                                const wxColour& WXUNUSED(col),
@@ -1272,7 +1300,7 @@ bool wxGtkPrinterDCImpl::DoGetPixel(wxCoord WXUNUSED(x1),
 
 void wxGtkPrinterDCImpl::DoDrawLine(wxCoord x1, wxCoord y1, wxCoord x2, wxCoord y2)
 {
-    if  (m_pen.GetStyle() == wxTRANSPARENT) return;
+    if  (m_pen.GetStyle() == wxPENSTYLE_TRANSPARENT) return;
 
     SetPen( m_pen );
     gs_cairo->cairo_move_to ( m_cairo, XLOG2DEV(x1), YLOG2DEV(y1) );
@@ -1380,7 +1408,7 @@ void wxGtkPrinterDCImpl::DoDrawEllipticArc(wxCoord x,wxCoord y,wxCoord w,wxCoord
 
 void wxGtkPrinterDCImpl::DoDrawPoint(wxCoord x, wxCoord y)
 {
-    if  (m_pen.GetStyle() == wxTRANSPARENT) return;
+    if  (m_pen.GetStyle() == wxPENSTYLE_TRANSPARENT) return;
 
     SetPen( m_pen );
 
@@ -1393,7 +1421,7 @@ void wxGtkPrinterDCImpl::DoDrawPoint(wxCoord x, wxCoord y)
 
 void wxGtkPrinterDCImpl::DoDrawLines(int n, wxPoint points[], wxCoord xoffset, wxCoord yoffset)
 {
-    if (m_pen.GetStyle() == wxTRANSPARENT) return;
+    if (m_pen.GetStyle() == wxPENSTYLE_TRANSPARENT) return;
 
     if (n <= 0) return;
 
@@ -1810,7 +1838,7 @@ void wxGtkPrinterDCImpl::DoDrawRotatedText(const wxString& text, wxCoord x, wxCo
 
     pango_layout_get_pixel_size( m_layout, &w, &h );
 
-        if ( m_backgroundMode == wxSOLID )
+        if ( m_backgroundMode == wxBRUSHSTYLE_SOLID )
         {
             unsigned char red = m_textBackgroundColour.Red();
             unsigned char blue = m_textBackgroundColour.Blue();
@@ -1916,11 +1944,11 @@ void wxGtkPrinterDCImpl::SetPen( const wxPen& pen )
 
     switch (m_pen.GetStyle())
     {
-        case wxDOT:           gs_cairo->cairo_set_dash( m_cairo, dotted, 2, 0 ); break;
-        case wxSHORT_DASH:    gs_cairo->cairo_set_dash( m_cairo, short_dashed, 2, 0 ); break;
-        case wxLONG_DASH:     gs_cairo->cairo_set_dash( m_cairo, long_dashed, 2, 0 ); break;
-        case wxDOT_DASH:      gs_cairo->cairo_set_dash( m_cairo, dotted_dashed, 4, 0 );  break;
-        case wxUSER_DASH:
+        case wxPENSTYLE_DOT:        gs_cairo->cairo_set_dash( m_cairo, dotted, 2, 0 ); break;
+        case wxPENSTYLE_SHORT_DASH: gs_cairo->cairo_set_dash( m_cairo, short_dashed, 2, 0 ); break;
+        case wxPENSTYLE_LONG_DASH:  gs_cairo->cairo_set_dash( m_cairo, long_dashed, 2, 0 ); break;
+        case wxPENSTYLE_DOT_DASH:   gs_cairo->cairo_set_dash( m_cairo, dotted_dashed, 4, 0 );  break;
+        case wxPENSTYLE_USER_DASH:
         {
             wxDash *wx_dashes;
             int num = m_pen.GetDashes (&wx_dashes);
@@ -1932,8 +1960,8 @@ void wxGtkPrinterDCImpl::SetPen( const wxPen& pen )
             g_free( g_dashes );
         }
         break;
-        case wxSOLID:
-        case wxTRANSPARENT:
+        case wxPENSTYLE_SOLID:
+        case wxPENSTYLE_TRANSPARENT:
         default:              gs_cairo->cairo_set_dash( m_cairo, NULL, 0, 0 );   break;
     }
 
@@ -1980,7 +2008,7 @@ void wxGtkPrinterDCImpl::SetBrush( const wxBrush& brush )
 
     m_brush = brush;
 
-    if (m_brush.GetStyle() == wxTRANSPARENT)
+    if (m_brush.GetStyle() == wxBRUSHSTYLE_TRANSPARENT)
     {
         gs_cairo->cairo_set_source_rgba( m_cairo, 0, 0, 0, 0 );
         m_currentRed = 0;
@@ -2023,31 +2051,31 @@ void wxGtkPrinterDCImpl::SetBrush( const wxBrush& brush )
 
         switch (m_brush.GetStyle())
         {
-            case wxCROSS_HATCH:
+            case wxBRUSHSTYLE_CROSS_HATCH:
                 gs_cairo->cairo_move_to(cr, 5, 0);
                 gs_cairo->cairo_line_to(cr, 5, 10);
                 gs_cairo->cairo_move_to(cr, 0, 5);
                 gs_cairo->cairo_line_to(cr, 10, 5);
                 break;
-            case wxBDIAGONAL_HATCH:
+            case wxBRUSHSTYLE_BDIAGONAL_HATCH:
                 gs_cairo->cairo_move_to(cr, 0, 10);
                 gs_cairo->cairo_line_to(cr, 10, 0);
                 break;
-            case wxFDIAGONAL_HATCH:
+            case wxBRUSHSTYLE_FDIAGONAL_HATCH:
                 gs_cairo->cairo_move_to(cr, 0, 0);
                 gs_cairo->cairo_line_to(cr, 10, 10);
                 break;
-            case wxCROSSDIAG_HATCH:
+            case wxBRUSHSTYLE_CROSSDIAG_HATCH:
                 gs_cairo->cairo_move_to(cr, 0, 0);
                 gs_cairo->cairo_line_to(cr, 10, 10);
                 gs_cairo->cairo_move_to(cr, 10, 0);
                 gs_cairo->cairo_line_to(cr, 0, 10);
                 break;
-            case wxHORIZONTAL_HATCH:
+            case wxBRUSHSTYLE_HORIZONTAL_HATCH:
                 gs_cairo->cairo_move_to(cr, 0, 5);
                 gs_cairo->cairo_line_to(cr, 10, 5);
                 break;
-            case wxVERTICAL_HATCH:
+            case wxBRUSHSTYLE_VERTICAL_HATCH:
                 gs_cairo->cairo_move_to(cr, 5, 0);
                 gs_cairo->cairo_line_to(cr, 5, 10);
                 break;
@@ -2098,10 +2126,10 @@ void wxGtkPrinterDCImpl::SetBackground( const wxBrush& brush )
 
 void wxGtkPrinterDCImpl::SetBackgroundMode(int mode)
 {
-    if (mode == wxSOLID)
-        m_backgroundMode = wxSOLID;
+    if (mode == wxBRUSHSTYLE_SOLID)
+        m_backgroundMode = wxBRUSHSTYLE_SOLID;
     else
-        m_backgroundMode = wxTRANSPARENT;
+        m_backgroundMode = wxBRUSHSTYLE_TRANSPARENT;
 }
 
 void wxGtkPrinterDCImpl::DoSetClippingRegion(wxCoord x, wxCoord y, wxCoord width, wxCoord height)
@@ -2218,9 +2246,9 @@ void wxGtkPrinterDCImpl::DoGetSize(int* width, int* height) const
     GtkPageSetup *setup = gtk_print_context_get_page_setup( m_gpc );
 
     if (width)
-        *width = wxRound( gtk_page_setup_get_paper_width( setup, GTK_UNIT_POINTS ) * m_PS2DEV );
+        *width = wxRound( (double)gtk_page_setup_get_paper_width( setup, GTK_UNIT_POINTS ) * (double)m_resolution / 72.0 );
     if (height)
-        *height = wxRound( gtk_page_setup_get_paper_height( setup, GTK_UNIT_POINTS ) * m_PS2DEV );
+        *height = wxRound( (double)gtk_page_setup_get_paper_height( setup, GTK_UNIT_POINTS ) * (double)m_resolution / 72.0 );
 }
 
 void wxGtkPrinterDCImpl::DoGetSizeMM(int *width, int *height) const
@@ -2277,10 +2305,6 @@ void wxGtkPrintPreview::Init(wxPrintout * WXUNUSED(printout),
             m_resolution = 1200;
             break;
 
-        default:
-            wxFAIL_MSG( "unknown print quality" );
-            // fall through
-
         case wxPRINT_QUALITY_LOW:
             m_resolution = 300;
             break;
@@ -2358,9 +2382,9 @@ void wxGtkPrintPreview::DetermineScaling()
 
         // Get width and height in points (1/72th of an inch)
         wxSize sizeDevUnits(paper->GetSizeDeviceUnits());
-
         sizeDevUnits.x = wxRound((double)sizeDevUnits.x * (double)m_resolution / 72.0);
         sizeDevUnits.y = wxRound((double)sizeDevUnits.y * (double)m_resolution / 72.0);
+        
         wxSize sizeTenthsMM(paper->GetSize());
         wxSize sizeMM(sizeTenthsMM.x / 10, sizeTenthsMM.y / 10);