]> git.saurik.com Git - wxWidgets.git/blobdiff - src/gtk/print.cpp
several g++ 4 warning fixes
[wxWidgets.git] / src / gtk / print.cpp
index a26ba656e1c9c8c3b53e22abf2ac15b689ad3b1d..4ac6043261851e6eba2db23bdd300fe3b0c7095d 100644 (file)
@@ -22,6 +22,7 @@
 #ifndef WX_PRECOMP
 #include "wx/log.h"
 #include "wx/dcmemory.h"
+#include "wx/dcprint.h"
 #include "wx/icon.h"
 #include "wx/math.h"
 #include "wx/image.h"
@@ -260,15 +261,24 @@ bool wxGtkPrintNativeData::TransferTo( wxPrintData &data )
     if(!m_config)
         return false;
 
-    GtkPrintQuality quality = gtk_print_settings_get_quality(m_config);
-    if (quality == GTK_PRINT_QUALITY_HIGH)
-        data.SetQuality(wxPRINT_QUALITY_HIGH);
-    else if (quality == GTK_PRINT_QUALITY_LOW)
-        data.SetQuality(wxPRINT_QUALITY_LOW);
-    else if (quality == GTK_PRINT_QUALITY_DRAFT)
-        data.SetQuality(wxPRINT_QUALITY_DRAFT);
-    else
-        data.SetQuality(wxPRINT_QUALITY_MEDIUM);
+    int resolution = gtk_print_settings_get_resolution(m_config);
+    if ( resolution > 0 )
+    {
+        // if resolution is explicitly set, use it
+        data.SetQuality(resolution);
+    }
+    else // use more vague "quality"
+    {
+        GtkPrintQuality quality = gtk_print_settings_get_quality(m_config);
+        if (quality == GTK_PRINT_QUALITY_HIGH)
+            data.SetQuality(wxPRINT_QUALITY_HIGH);
+        else if (quality == GTK_PRINT_QUALITY_LOW)
+            data.SetQuality(wxPRINT_QUALITY_LOW);
+        else if (quality == GTK_PRINT_QUALITY_DRAFT)
+            data.SetQuality(wxPRINT_QUALITY_DRAFT);
+        else
+            data.SetQuality(wxPRINT_QUALITY_MEDIUM);
+    }
 
     data.SetNoCopies(gtk_print_settings_get_n_copies(m_config));
 
@@ -891,6 +901,12 @@ void wxGtkPrinter::BeginPrint(wxPrintout *printout, GtkPrintOperation *operation
     wxPrintData printdata = GetPrintDialogData().GetPrintData();
     wxGtkPrintNativeData *native = (wxGtkPrintNativeData*) printdata.GetNativeData();
 
+    // We need to update printdata with the new data from the dialog and we
+    // have to do this here because this method needs this new data and we
+    // cannot update it earlier
+    native->SetPrintConfig(gtk_print_operation_get_print_settings(operation));
+    printdata.ConvertFromNative();
+
     SetPrintContext(context);
     native->SetPrintContext( context );
 
@@ -1087,8 +1103,8 @@ bool wxGtkPrinter::Setup( wxWindow * WXUNUSED(parent) )
 
 IMPLEMENT_ABSTRACT_CLASS(wxGtkPrinterDCImpl, wxDCImpl)
 
-wxGtkPrinterDCImpl::wxGtkPrinterDCImpl( wxPrinterDC *owner, const wxPrintData& data ) :
-   wxDCImpl( owner )
+wxGtkPrinterDCImpl::wxGtkPrinterDCImpl(wxPrinterDC *owner, const wxPrintData& data)
+                  : wxDCImpl( owner )
 {
     m_printData = data;
 
@@ -1256,7 +1272,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) );
@@ -1364,7 +1380,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 );
 
@@ -1377,7 +1393,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;
 
@@ -1794,7 +1810,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();
@@ -1900,11 +1916,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);
@@ -1916,8 +1932,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;
     }
 
@@ -1964,7 +1980,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;
@@ -2007,31 +2023,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;
@@ -2082,10 +2098,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)
@@ -2250,25 +2266,59 @@ int wxGtkPrinterDCImpl::GetResolution()
 IMPLEMENT_CLASS(wxGtkPrintPreview, wxPrintPreviewBase)
 
 void wxGtkPrintPreview::Init(wxPrintout * WXUNUSED(printout),
-                                    wxPrintout * WXUNUSED(printoutForPrinting))
+                             wxPrintout * WXUNUSED(printoutForPrinting),
+                             wxPrintData *data)
 {
+    // convert wxPrintQuality to resolution (input pointer can be NULL)
+    wxPrintQuality quality = data ? data->GetQuality() : wxPRINT_QUALITY_MEDIUM;
+    switch ( quality )
+    {
+        case wxPRINT_QUALITY_HIGH:
+            m_resolution = 1200;
+            break;
+
+        case wxPRINT_QUALITY_LOW:
+            m_resolution = 300;
+            break;
+
+        case wxPRINT_QUALITY_DRAFT:
+            m_resolution = 150;
+            break;
+
+        default:
+            if ( quality > 0 )
+            {
+                // positive values directly indicate print resolution
+                m_resolution = quality;
+                break;
+            }
+
+            wxFAIL_MSG( "unknown print quality" );
+            // fall through
+
+        case wxPRINT_QUALITY_MEDIUM:
+            m_resolution = 600;
+            break;
+
+    }
+
     DetermineScaling();
 }
 
 wxGtkPrintPreview::wxGtkPrintPreview(wxPrintout *printout,
-                                                   wxPrintout *printoutForPrinting,
-                                                   wxPrintDialogData *data)
-                        : wxPrintPreviewBase(printout, printoutForPrinting, data)
+                                     wxPrintout *printoutForPrinting,
+                                     wxPrintDialogData *data)
+                 : wxPrintPreviewBase(printout, printoutForPrinting, data)
 {
-    Init(printout, printoutForPrinting);
+    Init(printout, printoutForPrinting, data ? &data->GetPrintData() : NULL);
 }
 
 wxGtkPrintPreview::wxGtkPrintPreview(wxPrintout *printout,
-                                                   wxPrintout *printoutForPrinting,
-                                                   wxPrintData *data)
-                        : wxPrintPreviewBase(printout, printoutForPrinting, data)
+                                     wxPrintout *printoutForPrinting,
+                                     wxPrintData *data)
+                 : wxPrintPreviewBase(printout, printoutForPrinting, data)
 {
-    Init(printout, printoutForPrinting);
+    Init(printout, printoutForPrinting, data);
 }
 
 wxGtkPrintPreview::~wxGtkPrintPreview()
@@ -2300,15 +2350,13 @@ void wxGtkPrintPreview::DetermineScaling()
         m_previewPrintout->SetPPIScreen( (int) ((ScreenPixels.GetWidth() * 25.4) / ScreenMM.GetWidth()),
                                          (int) ((ScreenPixels.GetHeight() * 25.4) / ScreenMM.GetHeight()) );
 
-        // TODO !!!!!!!!!!!!!!!      
-        int resolution = 600;
-        m_previewPrintout->SetPPIPrinter( resolution, resolution );
+        m_previewPrintout->SetPPIPrinter( m_resolution, m_resolution );
 
         // Get width and height in points (1/72th of an inch)
         wxSize sizeDevUnits(paper->GetSizeDeviceUnits());
 
-        sizeDevUnits.x = wxRound((double)sizeDevUnits.x * (double)resolution / 72.0);
-        sizeDevUnits.y = wxRound((double)sizeDevUnits.y * (double)resolution / 72.0);
+        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);
 
@@ -2329,7 +2377,7 @@ 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)resolution;
+        m_previewScaleX = 0.8 * 72.0 / (double)m_resolution;
         m_previewScaleY = m_previewScaleX;
     }
 }