]> git.saurik.com Git - wxWidgets.git/blobdiff - src/common/dcbase.cpp
stricter reply code checking: verify that we get the expected reply, not just that...
[wxWidgets.git] / src / common / dcbase.cpp
index ee83c03fdabe2f1b6c59134b5fe4783ac0834dc4..a60da2e6573e8329c69cb9fb4ded229916af23e1 100644 (file)
@@ -133,17 +133,23 @@ IMPLEMENT_DYNAMIC_CLASS(wxDCFactoryCleanupModule, wxModule)
 
 wxDCImpl* wxNativeDCFactory::CreateWindowDC( wxWindowDC *owner, wxWindow *window )
 {
 
 wxDCImpl* wxNativeDCFactory::CreateWindowDC( wxWindowDC *owner, wxWindow *window )
 {
-    return new wxWindowDCImpl( owner, window );
+    wxDCImpl * const impl = new wxWindowDCImpl( owner, window );
+    impl->InheritAttributes(window);
+    return impl;
 }
 
 wxDCImpl* wxNativeDCFactory::CreateClientDC( wxClientDC *owner, wxWindow *window )
 {
 }
 
 wxDCImpl* wxNativeDCFactory::CreateClientDC( wxClientDC *owner, wxWindow *window )
 {
-    return new wxClientDCImpl( owner, window );
+    wxDCImpl * const impl = new wxClientDCImpl( owner, window );
+    impl->InheritAttributes(window);
+    return impl;
 }
 
 wxDCImpl* wxNativeDCFactory::CreatePaintDC( wxPaintDC *owner, wxWindow *window )
 {
 }
 
 wxDCImpl* wxNativeDCFactory::CreatePaintDC( wxPaintDC *owner, wxWindow *window )
 {
-    return new wxPaintDCImpl( owner, window );
+    wxDCImpl * const impl = new wxPaintDCImpl( owner, window );
+    impl->InheritAttributes(window);
+    return impl;
 }
 
 wxDCImpl* wxNativeDCFactory::CreateMemoryDC( wxMemoryDC *owner )
 }
 
 wxDCImpl* wxNativeDCFactory::CreateMemoryDC( wxMemoryDC *owner )
@@ -151,9 +157,19 @@ wxDCImpl* wxNativeDCFactory::CreateMemoryDC( wxMemoryDC *owner )
     return new wxMemoryDCImpl( owner );
 }
 
     return new wxMemoryDCImpl( owner );
 }
 
-wxDCImpl* wxNativeDCFactory::CreateMemoryDC( wxMemoryDC *owner, wxBitmap &bitmap )
+wxDCImpl* wxNativeDCFactory::CreateMemoryDC(wxMemoryDC *owner, wxBitmap& bitmap)
 {
 {
-    return new wxMemoryDCImpl( owner, bitmap );
+    // the bitmap may be modified when it's selected into a memory DC so make
+    // sure changing this bitmap doesn't affect any other shallow copies of it
+    // (see wxMemoryDC::SelectObject())
+    //
+    // notice that we don't provide any ctor equivalent to SelectObjectAsSource
+    // method because this should be rarely needed and easy to work around by
+    // using the default ctor and calling SelectObjectAsSource itself
+    if ( bitmap.IsOk() )
+        bitmap.UnShare();
+
+    return new wxMemoryDCImpl(owner, bitmap);
 }
 
 wxDCImpl* wxNativeDCFactory::CreateMemoryDC( wxMemoryDC *owner, wxDC *dc )
 }
 
 wxDCImpl* wxNativeDCFactory::CreateMemoryDC( wxMemoryDC *owner, wxDC *dc )
@@ -284,12 +300,12 @@ wxPrinterDC::wxPrinterDC(const wxPrintData& data)
 {
 }
 
 {
 }
 
-wxRect wxPrinterDC::GetPaperRect()
+wxRect wxPrinterDC::GetPaperRect() const
 {
     return GetImpl()->GetPaperRect();
 }
 
 {
     return GetImpl()->GetPaperRect();
 }
 
-int wxPrinterDC::GetResolution()
+int wxPrinterDC::GetResolution() const
 {
     return GetImpl()->GetResolution();
 }
 {
     return GetImpl()->GetResolution();
 }
@@ -1092,6 +1108,16 @@ void wxDCImpl::DoGradientFillConcentric(const wxRect& rect,
     m_pen.SetColour(oldPenColour);
 }
 
     m_pen.SetColour(oldPenColour);
 }
 
+void wxDCImpl::InheritAttributes(wxWindow *win)
+{
+    wxCHECK_RET( win, "window can't be NULL" );
+
+    SetFont(win->GetFont());
+    SetTextForeground(win->GetForegroundColour());
+    SetTextBackground(win->GetBackgroundColour());
+    SetBackground(wxBrush(win->GetBackgroundColour()));
+}
+
 //-----------------------------------------------------------------------------
 // wxDC
 //-----------------------------------------------------------------------------
 //-----------------------------------------------------------------------------
 // wxDC
 //-----------------------------------------------------------------------------
@@ -1622,3 +1648,15 @@ void wxDCImpl::CalculateEllipticPoints( wxPointList* points,
 } // CalculateEllipticPoints
 
 #endif // __WXWINCE__
 } // CalculateEllipticPoints
 
 #endif // __WXWINCE__
+
+float wxDCImpl::GetFontPointSizeAdjustment(float dpi)
+{
+    // wxMSW has long-standing bug where wxFont point size is interpreted as
+    // "pixel size corresponding to given point size *on screen*". In other
+    // words, on a typical 600dpi printer and a typical 96dpi screen, fonts
+    // are ~6 times smaller when printing. Unfortunately, this bug is so severe
+    // that *all* printing code has to account for it and consequently, other
+    // ports need to emulate this bug too:
+    const wxSize screenPPI = wxGetDisplayPPI();
+    return float(screenPPI.y) / dpi;
+}