From 3e21fc053d9017f79ad71675db8d2e1497049159 Mon Sep 17 00:00:00 2001 From: David Elliott Date: Mon, 17 Jan 2005 21:30:53 +0000 Subject: [PATCH] Moved Clear() implementation into wxDC using a new virtual CocoaGetBounds() to determine the rect to clear. Also added CocoaUnapplyTransformations() to bring the coordinate system back into Cocoa coordinates for those cases such as Clear() where it makes more sense. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@31440 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- include/wx/cocoa/dc.h | 5 +++++ include/wx/cocoa/dcclient.h | 3 +-- include/wx/cocoa/dcmemory.h | 3 +-- src/cocoa/dc.mm | 33 +++++++++++++++++++++++++++++++++ src/cocoa/dcclient.mm | 20 +++++++++----------- src/cocoa/dcmemory.mm | 24 ++++++++++-------------- 6 files changed, 59 insertions(+), 29 deletions(-) diff --git a/include/wx/cocoa/dc.h b/include/wx/cocoa/dc.h index ed39d574e9..c9cc225042 100644 --- a/include/wx/cocoa/dc.h +++ b/include/wx/cocoa/dc.h @@ -58,7 +58,12 @@ protected: void CocoaUnwindStackAndLoseFocus(); // DC flipping/transformation void CocoaApplyTransformations(); + void CocoaUnapplyTransformations(); WX_NSAffineTransform m_cocoaWxToBoundsTransform; +// Get bounds rect (for Clear()) + // note: we use void * to mean NSRect * so that we can avoid + // putting NSRect in the headers. + virtual bool CocoaGetBounds(void *rectData); // Blitting virtual bool CocoaDoBlitOnFocusedDC(wxCoord xdest, wxCoord ydest, wxCoord width, wxCoord height, wxCoord xsrc, wxCoord ysrc, diff --git a/include/wx/cocoa/dcclient.h b/include/wx/cocoa/dcclient.h index b7c56ab412..5bfc6a15e9 100644 --- a/include/wx/cocoa/dcclient.h +++ b/include/wx/cocoa/dcclient.h @@ -27,8 +27,6 @@ public: wxWindowDC(wxWindow *win); ~wxWindowDC(void); - // NSView specific functions - virtual void Clear(); protected: wxWindow *m_window; WX_NSView m_lockedNSView; @@ -37,6 +35,7 @@ protected: virtual bool CocoaUnlockFocus(); bool CocoaLockFocusOnNSView(WX_NSView nsview); bool CocoaUnlockFocusOnNSView(); + virtual bool CocoaGetBounds(void *rectData); }; class wxClientDC: public wxWindowDC diff --git a/include/wx/cocoa/dcmemory.h b/include/wx/cocoa/dcmemory.h index 1265fb84dd..889b5ce9bd 100644 --- a/include/wx/cocoa/dcmemory.h +++ b/include/wx/cocoa/dcmemory.h @@ -23,14 +23,13 @@ public: ~wxMemoryDC(void); virtual void SelectObject(const wxBitmap& bitmap); virtual void DoGetSize(int *width, int *height) const; - - virtual void Clear(); protected: wxBitmap m_selectedBitmap; WX_NSImage m_cocoaNSImage; // DC stack virtual bool CocoaLockFocus(); virtual bool CocoaUnlockFocus(); + virtual bool CocoaGetBounds(void *rectData); // Blitting virtual bool CocoaDoBlitOnFocusedDC(wxCoord xdest, wxCoord ydest, wxCoord width, wxCoord height, wxCoord xsrc, wxCoord ysrc, diff --git a/src/cocoa/dc.mm b/src/cocoa/dc.mm index da2d539def..7ef93f80ee 100644 --- a/src/cocoa/dc.mm +++ b/src/cocoa/dc.mm @@ -185,6 +185,23 @@ void wxDC::CocoaApplyTransformations() // TODO: Apply device/logical/user position/scaling transformations } +void wxDC::CocoaUnapplyTransformations() +{ + // NOTE: You *must* call this with focus held. + // Undo all transforms so we're back in true Cocoa coords with + // no scaling or flipping. + NSAffineTransform *invertTransform; + invertTransform = [m_cocoaWxToBoundsTransform copy]; + [invertTransform invert]; + [invertTransform concat]; +} + +bool wxDC::CocoaGetBounds(void *rectData) +{ + // We don't know what we are so we can't return anything. + return false; +} + void wxDC::DoDrawRectangle(wxCoord x, wxCoord y, wxCoord width, wxCoord height) { wxAutoNSAutoreleasePool pool; @@ -553,6 +570,22 @@ void wxDC::SetTextBackground( const wxColour &col ) void wxDC::Clear() { + if(!CocoaTakeFocus()) return; + + NSRect boundsRect; + if(!CocoaGetBounds(&boundsRect)) return; + + NSGraphicsContext *context = [NSGraphicsContext currentContext]; + [context saveGraphicsState]; + + // Undo all transforms so when we draw our bounds rect we + // really overwrite our bounds rect. + CocoaUnapplyTransformations(); + + [m_backgroundBrush.GetNSColor() set]; + [NSBezierPath fillRect:boundsRect]; + + [context restoreGraphicsState]; } void wxDC::SetBackground(const wxBrush& brush) diff --git a/src/cocoa/dcclient.mm b/src/cocoa/dcclient.mm index bcf82d7aab..d6ca05bc5e 100644 --- a/src/cocoa/dcclient.mm +++ b/src/cocoa/dcclient.mm @@ -80,17 +80,15 @@ bool wxWindowDC::CocoaUnlockFocus() return CocoaUnlockFocusOnNSView(); } -void wxWindowDC::Clear() -{ - if(!CocoaTakeFocus()) return; - - NSGraphicsContext *context = [NSGraphicsContext currentContext]; - [context saveGraphicsState]; - - [m_backgroundBrush.GetNSColor() set]; - [NSBezierPath fillRect:[m_lockedNSView bounds]]; - - [context restoreGraphicsState]; +bool wxWindowDC::CocoaGetBounds(void *rectData) +{ + if(!rectData) + return false; + if(!m_lockedNSView) + return false; + NSRect *pRect = (NSRect*)rectData; + *pRect = [m_lockedNSView bounds]; + return true; } /* diff --git a/src/cocoa/dcmemory.mm b/src/cocoa/dcmemory.mm index f3f2d3e2d0..fb11593b35 100644 --- a/src/cocoa/dcmemory.mm +++ b/src/cocoa/dcmemory.mm @@ -151,20 +151,16 @@ bool wxMemoryDC::CocoaDoBlitOnFocusedDC(wxCoord xdest, wxCoord ydest, return false; } -void wxMemoryDC::Clear() +bool wxMemoryDC::CocoaGetBounds(void *rectData) { - if(!CocoaTakeFocus()) return; - - NSGraphicsContext *context = [NSGraphicsContext currentContext]; - [context saveGraphicsState]; - - [m_backgroundBrush.GetNSColor() set]; - NSRect rect; - rect.origin.x = 0; - rect.origin.y = 0; - rect.size = [m_cocoaNSImage size]; - [NSBezierPath fillRect:rect]; - - [context restoreGraphicsState]; + if(!rectData) + return false; + if(!m_cocoaNSImage) + return false; + NSRect *pRect = (NSRect*)rectData; + pRect->origin.x = 0.0; + pRect->origin.y = 0.0; + pRect->size = [m_cocoaNSImage size]; + return true; } -- 2.45.2