From 6f65e33794fca0c936227235515a40e7df5c56e3 Mon Sep 17 00:00:00 2001 From: Julian Smart Date: Thu, 28 May 1998 19:54:07 +0000 Subject: [PATCH] Updates from Chris Breeze git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@57 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- include/wx/app.h | 6 +- include/wx/gtk/bitmap.h | 24 ++++- include/wx/gtk/dcmemory.h | 3 +- include/wx/gtk1/bitmap.h | 24 ++++- include/wx/gtk1/dcmemory.h | 3 +- include/wx/msw/dc.h | 4 + src/gtk/bitmap.cpp | 28 +++++- src/gtk/dc.cpp | 17 +++- src/gtk/dcclient.cpp | 176 +++++++++++++++++++++++++++++++------ src/gtk/dcmemory.cpp | 12 ++- src/gtk1/bitmap.cpp | 28 +++++- src/gtk1/dc.cpp | 17 +++- src/gtk1/dcclient.cpp | 176 +++++++++++++++++++++++++++++++------ src/gtk1/dcmemory.cpp | 12 ++- src/msw/dc.cpp | 91 ++++++++++++++++--- src/msw/pen.cpp | 7 +- src/msw/utils.cpp | 84 ++++++++---------- 17 files changed, 571 insertions(+), 141 deletions(-) diff --git a/include/wx/app.h b/include/wx/app.h index 8d11a5aeb4..349bac1acf 100644 --- a/include/wx/app.h +++ b/include/wx/app.h @@ -51,8 +51,10 @@ public: // (e.g. hello.cpp). // Now IMPLEMENT_APP should add this code if required. -#if defined(AIX) || defined(AIX4) /* || defined(____HPUX__) */ -#define IMPLEMENT_WXWIN_MAIN int main(int argc, char *argv[]) { return wxEntry(argc, argv); } +#if defined(__AIX__) || defined(__SUN__) || defined(__HPUX__) +#define IMPLEMENT_WXWIN_MAIN \ +extern int wxEntry( int argc, char *argv[] ); \ +int main(int argc, char *argv[]) { return wxEntry(argc, argv); } #else #define IMPLEMENT_WXWIN_MAIN #endif diff --git a/include/wx/gtk/bitmap.h b/include/wx/gtk/bitmap.h index 3d7e90c69b..42f2dabc5a 100644 --- a/include/wx/gtk/bitmap.h +++ b/include/wx/gtk/bitmap.h @@ -3,7 +3,7 @@ // Purpose: // Author: Robert Roebling // Created: 01/02/97 -// Id: +// RCS-ID: $Id$ // Copyright: (c) 1998 Robert Roebling, Julian Smart and Markus Holzem // Licence: wxWindows licence ///////////////////////////////////////////////////////////////////////////// @@ -25,6 +25,11 @@ // classes //----------------------------------------------------------------------------- +class wxDC; +class wxPaintDC; +class wxMemoryDC; +class wxToolBarGTK; + class wxMask; class wxBitmap; @@ -44,8 +49,13 @@ class wxMask: public wxObject wxMask( const wxBitmap& bitmap ); ~wxMask(void); - public: + private: + friend wxBitmap; + friend wxDC; + friend wxPaintDC; + friend wxToolBarGTK; + GdkBitmap *GetBitmap(void) const; protected: @@ -58,6 +68,7 @@ class wxMask: public wxObject // wxBitmap //----------------------------------------------------------------------------- +// CMB 20/5/98: added xbm constructor and GetBitmap() method class wxBitmap: public wxObject { DECLARE_DYNAMIC_CLASS(wxBitmap) @@ -66,6 +77,7 @@ class wxBitmap: public wxObject wxBitmap(void); wxBitmap( const int width, const int height, const int depth = -1 ); + wxBitmap( const char bits[], const int width, const int height, const int depth = 1 ); wxBitmap( char **bits ); wxBitmap( const wxBitmap& bmp ); wxBitmap( const wxBitmap* bmp ); @@ -93,9 +105,15 @@ class wxBitmap: public wxObject wxPalette *GetColourMap(void) const { return GetPalette(); }; - public: + private: + + friend wxDC; + friend wxPaintDC; + friend wxMemoryDC; + friend wxToolBarGTK; GdkPixmap *GetPixmap(void) const; + GdkBitmap *GetBitmap(void) const; // no data :-) }; diff --git a/include/wx/gtk/dcmemory.h b/include/wx/gtk/dcmemory.h index 66cf85bfc0..7afbb3295d 100644 --- a/include/wx/gtk/dcmemory.h +++ b/include/wx/gtk/dcmemory.h @@ -3,7 +3,7 @@ // Purpose: // Author: Robert Roebling // Created: 01/02/97 -// Id: +// RCS-ID: $Id$ // Copyright: (c) 1998 Robert Roebling, Julian Smart and Markus Holzem // Licence: wxWindows licence ///////////////////////////////////////////////////////////////////////////// @@ -41,6 +41,7 @@ class WXDLLEXPORT wxMemoryDC: public wxPaintDC void GetSize( int *width, int *height ); private: + friend wxPaintDC; wxBitmap m_selected; }; diff --git a/include/wx/gtk1/bitmap.h b/include/wx/gtk1/bitmap.h index 3d7e90c69b..42f2dabc5a 100644 --- a/include/wx/gtk1/bitmap.h +++ b/include/wx/gtk1/bitmap.h @@ -3,7 +3,7 @@ // Purpose: // Author: Robert Roebling // Created: 01/02/97 -// Id: +// RCS-ID: $Id$ // Copyright: (c) 1998 Robert Roebling, Julian Smart and Markus Holzem // Licence: wxWindows licence ///////////////////////////////////////////////////////////////////////////// @@ -25,6 +25,11 @@ // classes //----------------------------------------------------------------------------- +class wxDC; +class wxPaintDC; +class wxMemoryDC; +class wxToolBarGTK; + class wxMask; class wxBitmap; @@ -44,8 +49,13 @@ class wxMask: public wxObject wxMask( const wxBitmap& bitmap ); ~wxMask(void); - public: + private: + friend wxBitmap; + friend wxDC; + friend wxPaintDC; + friend wxToolBarGTK; + GdkBitmap *GetBitmap(void) const; protected: @@ -58,6 +68,7 @@ class wxMask: public wxObject // wxBitmap //----------------------------------------------------------------------------- +// CMB 20/5/98: added xbm constructor and GetBitmap() method class wxBitmap: public wxObject { DECLARE_DYNAMIC_CLASS(wxBitmap) @@ -66,6 +77,7 @@ class wxBitmap: public wxObject wxBitmap(void); wxBitmap( const int width, const int height, const int depth = -1 ); + wxBitmap( const char bits[], const int width, const int height, const int depth = 1 ); wxBitmap( char **bits ); wxBitmap( const wxBitmap& bmp ); wxBitmap( const wxBitmap* bmp ); @@ -93,9 +105,15 @@ class wxBitmap: public wxObject wxPalette *GetColourMap(void) const { return GetPalette(); }; - public: + private: + + friend wxDC; + friend wxPaintDC; + friend wxMemoryDC; + friend wxToolBarGTK; GdkPixmap *GetPixmap(void) const; + GdkBitmap *GetBitmap(void) const; // no data :-) }; diff --git a/include/wx/gtk1/dcmemory.h b/include/wx/gtk1/dcmemory.h index 66cf85bfc0..7afbb3295d 100644 --- a/include/wx/gtk1/dcmemory.h +++ b/include/wx/gtk1/dcmemory.h @@ -3,7 +3,7 @@ // Purpose: // Author: Robert Roebling // Created: 01/02/97 -// Id: +// RCS-ID: $Id$ // Copyright: (c) 1998 Robert Roebling, Julian Smart and Markus Holzem // Licence: wxWindows licence ///////////////////////////////////////////////////////////////////////////// @@ -41,6 +41,7 @@ class WXDLLEXPORT wxMemoryDC: public wxPaintDC void GetSize( int *width, int *height ); private: + friend wxPaintDC; wxBitmap m_selected; }; diff --git a/include/wx/msw/dc.h b/include/wx/msw/dc.h index b0c49d268f..5392a19a3b 100644 --- a/include/wx/msw/dc.h +++ b/include/wx/msw/dc.h @@ -100,6 +100,7 @@ public: virtual void SetSystemScale(double x, double y); virtual void SetLogicalOrigin(long x, long y); virtual void SetDeviceOrigin(long x, long y); + virtual void SetAxisOrientation(bool xLeftRight, bool yBottomUp); // This group of functions does actual conversion // of the input, as you'd expect. @@ -217,6 +218,9 @@ protected: double m_userScaleX; double m_userScaleY; + int m_signX; // Used by SetAxisOrientation() to + int m_signY; // invert the axes + int m_mappingMode; long m_minX; // bounding box diff --git a/src/gtk/bitmap.cpp b/src/gtk/bitmap.cpp index ebb2fe5d6a..6c2ecbe6d4 100644 --- a/src/gtk/bitmap.cpp +++ b/src/gtk/bitmap.cpp @@ -3,7 +3,7 @@ // Purpose: // Author: Robert Roebling // Created: 01/02/97 -// Id: +// RCS-ID: $Id$ // Copyright: (c) 1998 Robert Roebling, Julian Smart and Markus Holzem // Licence: wxWindows licence ///////////////////////////////////////////////////////////////////////////// @@ -60,6 +60,7 @@ GdkBitmap *wxMask::GetBitmap(void) const // wxBitmap //----------------------------------------------------------------------------- +// CMB 20/5/98: added m_bitmap for GdkBitmaps class wxBitmapRefData: public wxObjectRefData { public: @@ -68,6 +69,7 @@ class wxBitmapRefData: public wxObjectRefData ~wxBitmapRefData(void); GdkPixmap *m_pixmap; + GdkBitmap *m_bitmap; wxMask *m_mask; int m_width; int m_height; @@ -78,6 +80,7 @@ class wxBitmapRefData: public wxObjectRefData wxBitmapRefData::wxBitmapRefData(void) { m_pixmap = NULL; + m_bitmap = NULL; m_mask = NULL; m_width = 0; m_height = 0; @@ -91,6 +94,7 @@ wxBitmapRefData::~wxBitmapRefData(void) if (m_pixmap) gdk_imlib_free_pixmap( m_pixmap ); #else if (m_pixmap) gdk_pixmap_unref( m_pixmap ); + if (m_bitmap) gdk_bitmap_unref( m_bitmap ); #endif if (m_mask) delete m_mask; if (m_palette) delete m_palette; @@ -158,12 +162,26 @@ wxBitmap::wxBitmap( const wxBitmap* bmp ) if (wxTheBitmapList) wxTheBitmapList->AddBitmap(this); }; - + wxBitmap::wxBitmap( const wxString &filename, const int type ) { LoadFile( filename, type ); }; +// CMB 15/5/98: add constructor for xbm bitmaps +wxBitmap::wxBitmap( const char bits[], const int width, const int height, const int WXUNUSED(depth)) +{ + m_refData = new wxBitmapRefData(); + + M_BMPDATA->m_mask = NULL; + M_BMPDATA->m_bitmap = + gdk_bitmap_create_from_data( (GdkWindow*) &gdk_root_parent, (gchar *) bits, width, height ); + gdk_window_get_size( M_BMPDATA->m_bitmap, &(M_BMPDATA->m_width), &(M_BMPDATA->m_height) ); + M_BMPDATA->m_bpp = 1; + + if (wxTheBitmapList) wxTheBitmapList->AddBitmap(this); +} + wxBitmap::~wxBitmap(void) { if (wxTheBitmapList) wxTheBitmapList->DeleteObject(this); @@ -291,3 +309,9 @@ GdkPixmap *wxBitmap::GetPixmap(void) const return M_BMPDATA->m_pixmap; }; +GdkBitmap *wxBitmap::GetBitmap(void) const +{ + if (!Ok()) return NULL; + return M_BMPDATA->m_bitmap; +}; + diff --git a/src/gtk/dc.cpp b/src/gtk/dc.cpp index c53c2d26fd..9637082010 100644 --- a/src/gtk/dc.cpp +++ b/src/gtk/dc.cpp @@ -3,7 +3,7 @@ // Purpose: // Author: Robert Roebling // Created: 01/02/97 -// Id: +// RCS-ID: $Id$ // Copyright: (c) 1998 Robert Roebling, Julian Smart and Markus Holzem // Licence: wxWindows licence ///////////////////////////////////////////////////////////////////////////// @@ -361,10 +361,25 @@ void wxDC::CalcBoundingBox( long x, long y ) void wxDC::ComputeScaleAndOrigin(void) { + // CMB: copy scale to see if it changes + double origScaleX = m_scaleX; + double origScaleY = m_scaleY; + m_scaleX = m_logicalScaleX * m_userScaleX; m_scaleY = m_logicalScaleY * m_userScaleY; m_deviceOriginX = m_internalDeviceOriginX + m_externalDeviceOriginX; m_deviceOriginY = m_internalDeviceOriginY + m_externalDeviceOriginY; + + // CMB: if scale has changed call SetPen to recalulate the line width + if (m_scaleX != origScaleX || m_scaleY != origScaleY) + { + // this is a bit artificial, but we need to force wxDC to think + // the pen has changed + wxPen* pen = GetPen(); + wxPen tempPen; + m_pen = tempPen; + SetPen(pen); + } }; diff --git a/src/gtk/dcclient.cpp b/src/gtk/dcclient.cpp index dbf2d639a1..dd64b45428 100644 --- a/src/gtk/dcclient.cpp +++ b/src/gtk/dcclient.cpp @@ -3,7 +3,7 @@ // Purpose: // Author: Robert Roebling // Created: 01/02/97 -// Id: +// RCS-ID: $Id$ // Copyright: (c) 1998 Robert Roebling, Julian Smart and Markus Holzem // Licence: wxWindows licence ///////////////////////////////////////////////////////////////////////////// @@ -13,6 +13,7 @@ #endif #include "wx/dcclient.h" +#include "wx/dcmemory.h" //----------------------------------------------------------------------------- // local data @@ -35,6 +36,49 @@ static GdkPixmap **hatch_bitmap = NULL; #define RAD2DEG 57.2957795131 +//----------------------------------------------------------------------------- +// temporary implementation of the missing GDK function +//----------------------------------------------------------------------------- +#include "gdk/gdkprivate.h" +void gdk_draw_bitmap (GdkDrawable *drawable, + GdkGC *gc, + GdkDrawable *src, + gint xsrc, + gint ysrc, + gint xdest, + gint ydest, + gint width, + gint height) +{ + GdkWindowPrivate *drawable_private; + GdkWindowPrivate *src_private; + GdkGCPrivate *gc_private; + + g_return_if_fail (drawable != NULL); + g_return_if_fail (src != NULL); + g_return_if_fail (gc != NULL); + + drawable_private = (GdkWindowPrivate*) drawable; + src_private = (GdkWindowPrivate*) src; + if (drawable_private->destroyed || src_private->destroyed) + return; + gc_private = (GdkGCPrivate*) gc; + + if (width == -1) + width = src_private->width; + if (height == -1) + height = src_private->height; + + XCopyPlane (drawable_private->xdisplay, + src_private->xwindow, + drawable_private->xwindow, + gc_private->xgc, + xsrc, ysrc, + width, height, + xdest, ydest, + 1); +} + //----------------------------------------------------------------------------- // wxPaintDC //----------------------------------------------------------------------------- @@ -159,19 +203,22 @@ void wxPaintDC::DrawEllipticArc( long x, long y, long width, long height, double { if (!Ok()) return; - if (width<0) { width=-width; x=x-width; } - if (height<0) { height=-height; y=y-height; } - long xx = XLOG2DEV(x); long yy = YLOG2DEV(y); - long ww = XLOG2DEVREL(width); - long hh = YLOG2DEVREL(height); + long ww = m_signX * XLOG2DEVREL(width); + long hh = m_signY * YLOG2DEVREL(height); + // CMB: handle -ve width and/or height + if (ww < 0) { ww = -ww; xx = xx - ww; } + if (hh < 0) { hh = -hh; yy = yy - hh; } + + long start = long(sa * 64.0); + long end = long(ea * 64.0); if (m_brush.GetStyle() != wxTRANSPARENT) - gdk_draw_arc( m_window, m_brushGC, TRUE, xx, yy, ww-1, hh-1, 0, long(sa*64) ); + gdk_draw_arc( m_window, m_brushGC, TRUE, xx, yy, ww, hh, start, end ); if (m_pen.GetStyle() != wxTRANSPARENT) - gdk_draw_arc( m_window, m_penGC, FALSE, xx, yy, ww, hh, 0, long(ea*64) ); + gdk_draw_arc( m_window, m_penGC, FALSE, xx, yy, ww, hh, start, end ); }; void wxPaintDC::DrawPoint( long x, long y ) @@ -236,9 +283,16 @@ void wxPaintDC::DrawRectangle( long x, long y, long width, long height ) long xx = XLOG2DEV(x); long yy = YLOG2DEV(y); - long ww = XLOG2DEVREL(width); - long hh = YLOG2DEVREL(height); + long ww = m_signX * XLOG2DEVREL(width); + long hh = m_signY * YLOG2DEVREL(height); + // CMB: draw nothing if transformed w or h is 0 + if (ww == 0 || hh == 0) return; + + // CMB: handle -ve width and/or height + if (ww < 0) { ww = -ww; xx = xx - ww; } + if (hh < 0) { hh = -hh; yy = yy - hh; } + if (m_brush.GetStyle() != wxTRANSPARENT) gdk_draw_rectangle( m_window, m_brushGC, TRUE, xx, yy, ww, hh ); @@ -250,22 +304,48 @@ void wxPaintDC::DrawRoundedRectangle( long x, long y, long width, long height, d { if (!Ok()) return; - if (width<0) { width=-width; x=x-width; } - if (height<0) { height=-height; y=y-height; } - if (radius < 0.0) radius = - radius * ((width < height) ? width : height); long xx = XLOG2DEV(x); long yy = YLOG2DEV(y); - long ww = XLOG2DEVREL(width); - long hh = YLOG2DEVREL(height); + long ww = m_signX * XLOG2DEVREL(width); + long hh = m_signY * YLOG2DEVREL(height); long rr = XLOG2DEVREL((long)radius); + + // CMB: handle -ve width and/or height + if (ww < 0) { ww = -ww; xx = xx - ww; } + if (hh < 0) { hh = -hh; yy = yy - hh; } + + // CMB: if radius is zero use DrawRectangle() instead to avoid + // X drawing errors with small radii + if (rr == 0) + { + DrawRectangle( x, y, width, height ); + return; + } + + // CMB: draw nothing if transformed w or h is 0 + if (ww == 0 || hh == 0) return; + + // CMB: adjust size if outline is drawn otherwise the result is + // 1 pixel too wide and high + if (m_pen.GetStyle() != wxTRANSPARENT) + { + ww--; + hh--; + } + + // CMB: ensure dd is not larger than rectangle otherwise we + // get an hour glass shape long dd = 2 * rr; + if (dd > ww) dd = ww; + if (dd > hh) dd = hh; + rr = dd / 2; if (m_brush.GetStyle() != wxTRANSPARENT) { - gdk_draw_rectangle( m_window, m_brushGC, TRUE, xx+rr, yy, ww-dd, hh ); - gdk_draw_rectangle( m_window, m_brushGC, TRUE, xx, yy+rr, ww, hh-dd ); + gdk_draw_rectangle( m_window, m_brushGC, TRUE, xx+rr, yy, ww-dd+1, hh ); + gdk_draw_rectangle( m_window, m_brushGC, TRUE, xx, yy+rr, ww, hh-dd+1 ); gdk_draw_arc( m_window, m_brushGC, TRUE, xx, yy, dd, dd, 90*64, 90*64 ); gdk_draw_arc( m_window, m_brushGC, TRUE, xx+ww-dd, yy, dd, dd, 0, 90*64 ); gdk_draw_arc( m_window, m_brushGC, TRUE, xx+ww-dd, yy+hh-dd, dd, dd, 270*64, 90*64 ); @@ -289,13 +369,14 @@ void wxPaintDC::DrawEllipse( long x, long y, long width, long height ) { if (!Ok()) return; - if (width<0) { width=-width; x=x-width; } - if (height<0) { height=-height; y=y-height; } - long xx = XLOG2DEV(x); long yy = YLOG2DEV(y); - long ww = XLOG2DEVREL(width); - long hh = YLOG2DEVREL(height); + long ww = m_signX * XLOG2DEVREL(width); + long hh = m_signY * YLOG2DEVREL(height); + + // CMB: handle -ve width and/or height + if (ww < 0) { ww = -ww; xx = xx - ww; } + if (hh < 0) { hh = -hh; yy = yy - hh; } if (m_brush.GetStyle() != wxTRANSPARENT) gdk_draw_arc( m_window, m_brushGC, TRUE, xx, yy, ww, hh, 0, 360*64 ); @@ -342,8 +423,26 @@ bool wxPaintDC::Blit( long xdest, long ydest, long width, long height, { if (!Ok()) return FALSE; - wxClientDC *csrc = (wxClientDC*)source; + // CMB 20/5/98: add blitting of bitmaps + if (source->IsKindOf(CLASSINFO(wxMemoryDC))) + { + wxMemoryDC* srcDC = (wxMemoryDC*)source; + GdkBitmap* bmap = srcDC->m_selected.GetBitmap(); + if (bmap) + { + gdk_draw_bitmap ( + m_window, + m_textGC, + bmap, + source->DeviceToLogicalX(xsrc), source->DeviceToLogicalY(ysrc), + XLOG2DEV(xdest), YLOG2DEV(ydest), + source->DeviceToLogicalXRel(width), source->DeviceToLogicalYRel(height) + ); + return TRUE; + } + } + wxClientDC *csrc = (wxClientDC*)source; gdk_window_copy_area ( m_window, m_penGC, XLOG2DEV(xdest), YLOG2DEV(ydest), csrc->GetWindow(), @@ -366,6 +465,16 @@ void wxPaintDC::DrawText( const wxString &text, long x, long y, bool WXUNUSED(us if (!Ok()) return; GdkFont *font = m_font.GetInternalFont( m_scaleY ); + + // CMB 21/5/98: draw text background if mode is wxSOLID + if (m_backgroundMode == wxSOLID) + { + long width = gdk_string_width( font, text ); + long height = font->ascent + font->descent; + gdk_gc_set_foreground( m_textGC, m_textBackgroundColour.GetColor() ); + gdk_draw_rectangle( m_window, m_textGC, TRUE, x, y, width, height ); + gdk_gc_set_foreground( m_textGC, m_textForegroundColour.GetColor() ); + } gdk_draw_string( m_window, font, m_textGC, XLOG2DEV(x), YLOG2DEV(y) + font->ascent, text ); @@ -383,8 +492,8 @@ void wxPaintDC::GetTextExtent( const wxString &string, long *width, long *height if (!Ok()) return; GdkFont *font = m_font.GetInternalFont( m_scaleY ); - if (width) (*width) = gdk_string_width( font, string ); - if (height) (*height) = font->ascent + font->descent; + if (width) (*width) = long(gdk_string_width( font, string ) / m_scaleX); + if (height) (*height) = long((font->ascent + font->descent) / m_scaleY); }; long wxPaintDC::GetCharWidth(void) @@ -429,6 +538,18 @@ void wxPaintDC::SetPen( const wxPen &pen ) if (!m_pen.Ok()) return; gint width = m_pen.GetWidth(); + // CMB: if width is non-zero scale it with the dc + if (width <= 0) + { + width = 1; + } + else + { + // X doesn't allow different width in x and y and so we take + // the average + double w = 0.5 + (abs(XLOG2DEVREL(width)) + abs(YLOG2DEVREL(width))) / 2.0; + width = (int)w; + } GdkLineStyle lineStyle = GDK_LINE_SOLID; switch (m_pen.GetStyle()) @@ -443,7 +564,7 @@ void wxPaintDC::SetPen( const wxPen &pen ) GdkCapStyle capStyle = GDK_CAP_ROUND; switch (m_pen.GetCap()) { - case wxCAP_ROUND: { capStyle = GDK_CAP_ROUND; break; }; + case wxCAP_ROUND: { capStyle = (width <= 1) ? GDK_CAP_NOT_LAST : GDK_CAP_ROUND; break; }; case wxCAP_PROJECTING: { capStyle = GDK_CAP_PROJECTING; break; }; case wxCAP_BUTT: { capStyle = GDK_CAP_BUTT; break; }; }; @@ -540,8 +661,9 @@ void wxPaintDC::SetTextBackground( const wxColour &col ) gdk_gc_set_background( m_textGC, m_textBackgroundColour.GetColor() ); }; -void wxPaintDC::SetBackgroundMode( int WXUNUSED(mode) ) +void wxPaintDC::SetBackgroundMode( int mode ) { + m_backgroundMode = mode; }; void wxPaintDC::SetPalette( const wxPalette& WXUNUSED(palette) ) diff --git a/src/gtk/dcmemory.cpp b/src/gtk/dcmemory.cpp index 804ba3e3a3..e947cd2ca7 100644 --- a/src/gtk/dcmemory.cpp +++ b/src/gtk/dcmemory.cpp @@ -3,7 +3,7 @@ // Purpose: // Author: Robert Roebling // Created: 01/02/97 -// Id: +// RCS-ID: $Id$ // Copyright: (c) 1998 Robert Roebling, Julian Smart and Markus Holzem // Licence: wxWindows licence ///////////////////////////////////////////////////////////////////////////// @@ -41,7 +41,15 @@ void wxMemoryDC::SelectObject( const wxBitmap& bitmap ) m_selected = bitmap; if (m_selected.Ok()) { - m_window = m_selected.GetPixmap(); + if (m_selected.GetPixmap()) + { + m_window = m_selected.GetPixmap(); + } + else + { + m_window = m_selected.GetBitmap(); + } + SetUpDC(); } else diff --git a/src/gtk1/bitmap.cpp b/src/gtk1/bitmap.cpp index ebb2fe5d6a..6c2ecbe6d4 100644 --- a/src/gtk1/bitmap.cpp +++ b/src/gtk1/bitmap.cpp @@ -3,7 +3,7 @@ // Purpose: // Author: Robert Roebling // Created: 01/02/97 -// Id: +// RCS-ID: $Id$ // Copyright: (c) 1998 Robert Roebling, Julian Smart and Markus Holzem // Licence: wxWindows licence ///////////////////////////////////////////////////////////////////////////// @@ -60,6 +60,7 @@ GdkBitmap *wxMask::GetBitmap(void) const // wxBitmap //----------------------------------------------------------------------------- +// CMB 20/5/98: added m_bitmap for GdkBitmaps class wxBitmapRefData: public wxObjectRefData { public: @@ -68,6 +69,7 @@ class wxBitmapRefData: public wxObjectRefData ~wxBitmapRefData(void); GdkPixmap *m_pixmap; + GdkBitmap *m_bitmap; wxMask *m_mask; int m_width; int m_height; @@ -78,6 +80,7 @@ class wxBitmapRefData: public wxObjectRefData wxBitmapRefData::wxBitmapRefData(void) { m_pixmap = NULL; + m_bitmap = NULL; m_mask = NULL; m_width = 0; m_height = 0; @@ -91,6 +94,7 @@ wxBitmapRefData::~wxBitmapRefData(void) if (m_pixmap) gdk_imlib_free_pixmap( m_pixmap ); #else if (m_pixmap) gdk_pixmap_unref( m_pixmap ); + if (m_bitmap) gdk_bitmap_unref( m_bitmap ); #endif if (m_mask) delete m_mask; if (m_palette) delete m_palette; @@ -158,12 +162,26 @@ wxBitmap::wxBitmap( const wxBitmap* bmp ) if (wxTheBitmapList) wxTheBitmapList->AddBitmap(this); }; - + wxBitmap::wxBitmap( const wxString &filename, const int type ) { LoadFile( filename, type ); }; +// CMB 15/5/98: add constructor for xbm bitmaps +wxBitmap::wxBitmap( const char bits[], const int width, const int height, const int WXUNUSED(depth)) +{ + m_refData = new wxBitmapRefData(); + + M_BMPDATA->m_mask = NULL; + M_BMPDATA->m_bitmap = + gdk_bitmap_create_from_data( (GdkWindow*) &gdk_root_parent, (gchar *) bits, width, height ); + gdk_window_get_size( M_BMPDATA->m_bitmap, &(M_BMPDATA->m_width), &(M_BMPDATA->m_height) ); + M_BMPDATA->m_bpp = 1; + + if (wxTheBitmapList) wxTheBitmapList->AddBitmap(this); +} + wxBitmap::~wxBitmap(void) { if (wxTheBitmapList) wxTheBitmapList->DeleteObject(this); @@ -291,3 +309,9 @@ GdkPixmap *wxBitmap::GetPixmap(void) const return M_BMPDATA->m_pixmap; }; +GdkBitmap *wxBitmap::GetBitmap(void) const +{ + if (!Ok()) return NULL; + return M_BMPDATA->m_bitmap; +}; + diff --git a/src/gtk1/dc.cpp b/src/gtk1/dc.cpp index c53c2d26fd..9637082010 100644 --- a/src/gtk1/dc.cpp +++ b/src/gtk1/dc.cpp @@ -3,7 +3,7 @@ // Purpose: // Author: Robert Roebling // Created: 01/02/97 -// Id: +// RCS-ID: $Id$ // Copyright: (c) 1998 Robert Roebling, Julian Smart and Markus Holzem // Licence: wxWindows licence ///////////////////////////////////////////////////////////////////////////// @@ -361,10 +361,25 @@ void wxDC::CalcBoundingBox( long x, long y ) void wxDC::ComputeScaleAndOrigin(void) { + // CMB: copy scale to see if it changes + double origScaleX = m_scaleX; + double origScaleY = m_scaleY; + m_scaleX = m_logicalScaleX * m_userScaleX; m_scaleY = m_logicalScaleY * m_userScaleY; m_deviceOriginX = m_internalDeviceOriginX + m_externalDeviceOriginX; m_deviceOriginY = m_internalDeviceOriginY + m_externalDeviceOriginY; + + // CMB: if scale has changed call SetPen to recalulate the line width + if (m_scaleX != origScaleX || m_scaleY != origScaleY) + { + // this is a bit artificial, but we need to force wxDC to think + // the pen has changed + wxPen* pen = GetPen(); + wxPen tempPen; + m_pen = tempPen; + SetPen(pen); + } }; diff --git a/src/gtk1/dcclient.cpp b/src/gtk1/dcclient.cpp index dbf2d639a1..dd64b45428 100644 --- a/src/gtk1/dcclient.cpp +++ b/src/gtk1/dcclient.cpp @@ -3,7 +3,7 @@ // Purpose: // Author: Robert Roebling // Created: 01/02/97 -// Id: +// RCS-ID: $Id$ // Copyright: (c) 1998 Robert Roebling, Julian Smart and Markus Holzem // Licence: wxWindows licence ///////////////////////////////////////////////////////////////////////////// @@ -13,6 +13,7 @@ #endif #include "wx/dcclient.h" +#include "wx/dcmemory.h" //----------------------------------------------------------------------------- // local data @@ -35,6 +36,49 @@ static GdkPixmap **hatch_bitmap = NULL; #define RAD2DEG 57.2957795131 +//----------------------------------------------------------------------------- +// temporary implementation of the missing GDK function +//----------------------------------------------------------------------------- +#include "gdk/gdkprivate.h" +void gdk_draw_bitmap (GdkDrawable *drawable, + GdkGC *gc, + GdkDrawable *src, + gint xsrc, + gint ysrc, + gint xdest, + gint ydest, + gint width, + gint height) +{ + GdkWindowPrivate *drawable_private; + GdkWindowPrivate *src_private; + GdkGCPrivate *gc_private; + + g_return_if_fail (drawable != NULL); + g_return_if_fail (src != NULL); + g_return_if_fail (gc != NULL); + + drawable_private = (GdkWindowPrivate*) drawable; + src_private = (GdkWindowPrivate*) src; + if (drawable_private->destroyed || src_private->destroyed) + return; + gc_private = (GdkGCPrivate*) gc; + + if (width == -1) + width = src_private->width; + if (height == -1) + height = src_private->height; + + XCopyPlane (drawable_private->xdisplay, + src_private->xwindow, + drawable_private->xwindow, + gc_private->xgc, + xsrc, ysrc, + width, height, + xdest, ydest, + 1); +} + //----------------------------------------------------------------------------- // wxPaintDC //----------------------------------------------------------------------------- @@ -159,19 +203,22 @@ void wxPaintDC::DrawEllipticArc( long x, long y, long width, long height, double { if (!Ok()) return; - if (width<0) { width=-width; x=x-width; } - if (height<0) { height=-height; y=y-height; } - long xx = XLOG2DEV(x); long yy = YLOG2DEV(y); - long ww = XLOG2DEVREL(width); - long hh = YLOG2DEVREL(height); + long ww = m_signX * XLOG2DEVREL(width); + long hh = m_signY * YLOG2DEVREL(height); + // CMB: handle -ve width and/or height + if (ww < 0) { ww = -ww; xx = xx - ww; } + if (hh < 0) { hh = -hh; yy = yy - hh; } + + long start = long(sa * 64.0); + long end = long(ea * 64.0); if (m_brush.GetStyle() != wxTRANSPARENT) - gdk_draw_arc( m_window, m_brushGC, TRUE, xx, yy, ww-1, hh-1, 0, long(sa*64) ); + gdk_draw_arc( m_window, m_brushGC, TRUE, xx, yy, ww, hh, start, end ); if (m_pen.GetStyle() != wxTRANSPARENT) - gdk_draw_arc( m_window, m_penGC, FALSE, xx, yy, ww, hh, 0, long(ea*64) ); + gdk_draw_arc( m_window, m_penGC, FALSE, xx, yy, ww, hh, start, end ); }; void wxPaintDC::DrawPoint( long x, long y ) @@ -236,9 +283,16 @@ void wxPaintDC::DrawRectangle( long x, long y, long width, long height ) long xx = XLOG2DEV(x); long yy = YLOG2DEV(y); - long ww = XLOG2DEVREL(width); - long hh = YLOG2DEVREL(height); + long ww = m_signX * XLOG2DEVREL(width); + long hh = m_signY * YLOG2DEVREL(height); + // CMB: draw nothing if transformed w or h is 0 + if (ww == 0 || hh == 0) return; + + // CMB: handle -ve width and/or height + if (ww < 0) { ww = -ww; xx = xx - ww; } + if (hh < 0) { hh = -hh; yy = yy - hh; } + if (m_brush.GetStyle() != wxTRANSPARENT) gdk_draw_rectangle( m_window, m_brushGC, TRUE, xx, yy, ww, hh ); @@ -250,22 +304,48 @@ void wxPaintDC::DrawRoundedRectangle( long x, long y, long width, long height, d { if (!Ok()) return; - if (width<0) { width=-width; x=x-width; } - if (height<0) { height=-height; y=y-height; } - if (radius < 0.0) radius = - radius * ((width < height) ? width : height); long xx = XLOG2DEV(x); long yy = YLOG2DEV(y); - long ww = XLOG2DEVREL(width); - long hh = YLOG2DEVREL(height); + long ww = m_signX * XLOG2DEVREL(width); + long hh = m_signY * YLOG2DEVREL(height); long rr = XLOG2DEVREL((long)radius); + + // CMB: handle -ve width and/or height + if (ww < 0) { ww = -ww; xx = xx - ww; } + if (hh < 0) { hh = -hh; yy = yy - hh; } + + // CMB: if radius is zero use DrawRectangle() instead to avoid + // X drawing errors with small radii + if (rr == 0) + { + DrawRectangle( x, y, width, height ); + return; + } + + // CMB: draw nothing if transformed w or h is 0 + if (ww == 0 || hh == 0) return; + + // CMB: adjust size if outline is drawn otherwise the result is + // 1 pixel too wide and high + if (m_pen.GetStyle() != wxTRANSPARENT) + { + ww--; + hh--; + } + + // CMB: ensure dd is not larger than rectangle otherwise we + // get an hour glass shape long dd = 2 * rr; + if (dd > ww) dd = ww; + if (dd > hh) dd = hh; + rr = dd / 2; if (m_brush.GetStyle() != wxTRANSPARENT) { - gdk_draw_rectangle( m_window, m_brushGC, TRUE, xx+rr, yy, ww-dd, hh ); - gdk_draw_rectangle( m_window, m_brushGC, TRUE, xx, yy+rr, ww, hh-dd ); + gdk_draw_rectangle( m_window, m_brushGC, TRUE, xx+rr, yy, ww-dd+1, hh ); + gdk_draw_rectangle( m_window, m_brushGC, TRUE, xx, yy+rr, ww, hh-dd+1 ); gdk_draw_arc( m_window, m_brushGC, TRUE, xx, yy, dd, dd, 90*64, 90*64 ); gdk_draw_arc( m_window, m_brushGC, TRUE, xx+ww-dd, yy, dd, dd, 0, 90*64 ); gdk_draw_arc( m_window, m_brushGC, TRUE, xx+ww-dd, yy+hh-dd, dd, dd, 270*64, 90*64 ); @@ -289,13 +369,14 @@ void wxPaintDC::DrawEllipse( long x, long y, long width, long height ) { if (!Ok()) return; - if (width<0) { width=-width; x=x-width; } - if (height<0) { height=-height; y=y-height; } - long xx = XLOG2DEV(x); long yy = YLOG2DEV(y); - long ww = XLOG2DEVREL(width); - long hh = YLOG2DEVREL(height); + long ww = m_signX * XLOG2DEVREL(width); + long hh = m_signY * YLOG2DEVREL(height); + + // CMB: handle -ve width and/or height + if (ww < 0) { ww = -ww; xx = xx - ww; } + if (hh < 0) { hh = -hh; yy = yy - hh; } if (m_brush.GetStyle() != wxTRANSPARENT) gdk_draw_arc( m_window, m_brushGC, TRUE, xx, yy, ww, hh, 0, 360*64 ); @@ -342,8 +423,26 @@ bool wxPaintDC::Blit( long xdest, long ydest, long width, long height, { if (!Ok()) return FALSE; - wxClientDC *csrc = (wxClientDC*)source; + // CMB 20/5/98: add blitting of bitmaps + if (source->IsKindOf(CLASSINFO(wxMemoryDC))) + { + wxMemoryDC* srcDC = (wxMemoryDC*)source; + GdkBitmap* bmap = srcDC->m_selected.GetBitmap(); + if (bmap) + { + gdk_draw_bitmap ( + m_window, + m_textGC, + bmap, + source->DeviceToLogicalX(xsrc), source->DeviceToLogicalY(ysrc), + XLOG2DEV(xdest), YLOG2DEV(ydest), + source->DeviceToLogicalXRel(width), source->DeviceToLogicalYRel(height) + ); + return TRUE; + } + } + wxClientDC *csrc = (wxClientDC*)source; gdk_window_copy_area ( m_window, m_penGC, XLOG2DEV(xdest), YLOG2DEV(ydest), csrc->GetWindow(), @@ -366,6 +465,16 @@ void wxPaintDC::DrawText( const wxString &text, long x, long y, bool WXUNUSED(us if (!Ok()) return; GdkFont *font = m_font.GetInternalFont( m_scaleY ); + + // CMB 21/5/98: draw text background if mode is wxSOLID + if (m_backgroundMode == wxSOLID) + { + long width = gdk_string_width( font, text ); + long height = font->ascent + font->descent; + gdk_gc_set_foreground( m_textGC, m_textBackgroundColour.GetColor() ); + gdk_draw_rectangle( m_window, m_textGC, TRUE, x, y, width, height ); + gdk_gc_set_foreground( m_textGC, m_textForegroundColour.GetColor() ); + } gdk_draw_string( m_window, font, m_textGC, XLOG2DEV(x), YLOG2DEV(y) + font->ascent, text ); @@ -383,8 +492,8 @@ void wxPaintDC::GetTextExtent( const wxString &string, long *width, long *height if (!Ok()) return; GdkFont *font = m_font.GetInternalFont( m_scaleY ); - if (width) (*width) = gdk_string_width( font, string ); - if (height) (*height) = font->ascent + font->descent; + if (width) (*width) = long(gdk_string_width( font, string ) / m_scaleX); + if (height) (*height) = long((font->ascent + font->descent) / m_scaleY); }; long wxPaintDC::GetCharWidth(void) @@ -429,6 +538,18 @@ void wxPaintDC::SetPen( const wxPen &pen ) if (!m_pen.Ok()) return; gint width = m_pen.GetWidth(); + // CMB: if width is non-zero scale it with the dc + if (width <= 0) + { + width = 1; + } + else + { + // X doesn't allow different width in x and y and so we take + // the average + double w = 0.5 + (abs(XLOG2DEVREL(width)) + abs(YLOG2DEVREL(width))) / 2.0; + width = (int)w; + } GdkLineStyle lineStyle = GDK_LINE_SOLID; switch (m_pen.GetStyle()) @@ -443,7 +564,7 @@ void wxPaintDC::SetPen( const wxPen &pen ) GdkCapStyle capStyle = GDK_CAP_ROUND; switch (m_pen.GetCap()) { - case wxCAP_ROUND: { capStyle = GDK_CAP_ROUND; break; }; + case wxCAP_ROUND: { capStyle = (width <= 1) ? GDK_CAP_NOT_LAST : GDK_CAP_ROUND; break; }; case wxCAP_PROJECTING: { capStyle = GDK_CAP_PROJECTING; break; }; case wxCAP_BUTT: { capStyle = GDK_CAP_BUTT; break; }; }; @@ -540,8 +661,9 @@ void wxPaintDC::SetTextBackground( const wxColour &col ) gdk_gc_set_background( m_textGC, m_textBackgroundColour.GetColor() ); }; -void wxPaintDC::SetBackgroundMode( int WXUNUSED(mode) ) +void wxPaintDC::SetBackgroundMode( int mode ) { + m_backgroundMode = mode; }; void wxPaintDC::SetPalette( const wxPalette& WXUNUSED(palette) ) diff --git a/src/gtk1/dcmemory.cpp b/src/gtk1/dcmemory.cpp index 804ba3e3a3..e947cd2ca7 100644 --- a/src/gtk1/dcmemory.cpp +++ b/src/gtk1/dcmemory.cpp @@ -3,7 +3,7 @@ // Purpose: // Author: Robert Roebling // Created: 01/02/97 -// Id: +// RCS-ID: $Id$ // Copyright: (c) 1998 Robert Roebling, Julian Smart and Markus Holzem // Licence: wxWindows licence ///////////////////////////////////////////////////////////////////////////// @@ -41,7 +41,15 @@ void wxMemoryDC::SelectObject( const wxBitmap& bitmap ) m_selected = bitmap; if (m_selected.Ok()) { - m_window = m_selected.GetPixmap(); + if (m_selected.GetPixmap()) + { + m_window = m_selected.GetPixmap(); + } + else + { + m_window = m_selected.GetBitmap(); + } + SetUpDC(); } else diff --git a/src/msw/dc.cpp b/src/msw/dc.cpp index 7ec41b1008..075c62ee0f 100644 --- a/src/msw/dc.cpp +++ b/src/msw/dc.cpp @@ -108,6 +108,8 @@ wxDC::wxDC(void) m_logicalScaleY = 1.0; m_userScaleX = 1.0; m_userScaleY = 1.0; + m_signX = 1; + m_signY = 1; m_systemScaleX = 1.0; m_systemScaleY = 1.0; m_mappingMode = MM_TEXT; @@ -574,11 +576,6 @@ void wxDC::DrawArc(long x1,long y1,long x2,long y2,double xc,double yc) CalcBoundingBox((xc+radius), (yc+radius)); } -void wxDC::DrawEllipticArc(long WXUNUSED(x),long WXUNUSED(y),long WXUNUSED(w),long WXUNUSED(h),double WXUNUSED(sa),double WXUNUSED(ea)) -{ - // Not implemented -} - void wxDC::DrawPoint(long x, long y) { // BUGBUG - is this necessary? @@ -824,6 +821,51 @@ void wxDC::DrawEllipse(long x, long y, long width, long height) CalcBoundingBox(x2, y2); } +// Chris Breeze 20/5/98: first implementation of DrawEllipticArc on Windows +void wxDC::DrawEllipticArc(long x,long y,long w,long h,double sa,double ea) +{ +// BUGBUG - is this necessary? + if (m_pen.Ok() && m_autoSetting) + SetPen(m_pen) ; + + long x2 = (x+w); + long y2 = (y+h); + + BeginDrawing(); + + const double deg2rad = 3.14159265359 / 180.0; + int rx1 = XLOG2DEV(x+w/2); + int ry1 = YLOG2DEV(y+h/2); + int rx2 = rx1; + int ry2 = ry1; + rx1 += (int)(100.0 * abs(w) * cos(sa * deg2rad)); + ry1 -= (int)(100.0 * abs(h) * m_signY * sin(sa * deg2rad)); + rx2 += (int)(100.0 * abs(w) * cos(ea * deg2rad)); + ry2 -= (int)(100.0 * abs(h) * m_signY * sin(ea * deg2rad)); + + // draw pie with NULL_PEN first and then outline otherwise a line is + // drawn from the start and end points to the centre + HPEN orig_pen = ::SelectObject((HDC) m_hDC, ::GetStockObject(NULL_PEN)); + if (m_signY > 0) + { + (void)Pie((HDC) m_hDC, XLOG2DEV(x), YLOG2DEV(y), XLOG2DEV(x2)+1, YLOG2DEV(y2)+1, + rx1, ry1, rx2, ry2); + } + else + { + (void)Pie((HDC) m_hDC, XLOG2DEV(x), YLOG2DEV(y)-1, XLOG2DEV(x2)+1, YLOG2DEV(y2), + rx1, ry1-1, rx2, ry2-1); + } + ::SelectObject((HDC) m_hDC, orig_pen); + (void)Arc((HDC) m_hDC, XLOG2DEV(x), YLOG2DEV(y), XLOG2DEV(x2), YLOG2DEV(y2), + rx1, ry1, rx2, ry2); + + EndDrawing(); + + CalcBoundingBox(x, y); + CalcBoundingBox(x2, y2); +} + void wxDC::DrawIcon(const wxIcon& icon, long x, long y) { /* @@ -1260,6 +1302,14 @@ void wxDC::SetUserScale(double x, double y) SetMapMode(m_mappingMode); } +void wxDC::SetAxisOrientation(bool xLeftRight, bool yBottomUp) +{ + m_signX = xLeftRight ? 1 : -1; + m_signY = yBottomUp ? -1 : 1; + + SetMapMode(m_mappingMode); +} + void wxDC::SetSystemScale(double x, double y) { m_systemScaleX = x; @@ -1294,42 +1344,42 @@ void wxDC::SetDeviceOrigin(long x, long y) long wxDC::DeviceToLogicalX(long x) const { - return (long) (((x) - m_deviceOriginX)/(m_logicalScaleX*m_userScaleX*m_systemScaleX) - m_logicalOriginX) ; + return (long) (((x) - m_deviceOriginX)/(m_logicalScaleX*m_userScaleX*m_signX*m_systemScaleX) - m_logicalOriginX) ; } long wxDC::DeviceToLogicalXRel(long x) const { - return (long) ((x)/(m_logicalScaleX*m_userScaleX*m_systemScaleX)) ; + return (long) ((x)/(m_logicalScaleX*m_userScaleX*m_signX*m_systemScaleX)) ; } long wxDC::DeviceToLogicalY(long y) const { - return (long) (((y) - m_deviceOriginY)/(m_logicalScaleY*m_userScaleY*m_systemScaleY) - m_logicalOriginY) ; + return (long) (((y) - m_deviceOriginY)/(m_logicalScaleY*m_userScaleY*m_signY*m_systemScaleY) - m_logicalOriginY) ; } long wxDC::DeviceToLogicalYRel(long y) const { - return (long) ((y)/(m_logicalScaleY*m_userScaleY*m_systemScaleY)) ; + return (long) ((y)/(m_logicalScaleY*m_userScaleY*m_signY*m_systemScaleY)) ; } long wxDC::LogicalToDeviceX(long x) const { - return (long) (floor((x) - m_logicalOriginX)*m_logicalScaleX*m_userScaleX*m_systemScaleX + m_deviceOriginX) ; + return (long) (floor((x) - m_logicalOriginX)*m_logicalScaleX*m_userScaleX*m_signX*m_systemScaleX + m_deviceOriginX) ; } long wxDC::LogicalToDeviceXRel(long x) const { - return (long) (floor(x)*m_logicalScaleX*m_userScaleX*m_systemScaleX) ; + return (long) (floor(x)*m_logicalScaleX*m_userScaleX*m_signX*m_systemScaleX) ; } long wxDC::LogicalToDeviceY(long y) const { - return (long) (floor((y) - m_logicalOriginY)*m_logicalScaleY*m_userScaleY*m_systemScaleY + m_deviceOriginY); + return (long) (floor((y) - m_logicalOriginY)*m_logicalScaleY*m_userScaleY*m_signY*m_systemScaleY + m_deviceOriginY); } long wxDC::LogicalToDeviceYRel(long y) const { - return (long) (floor(y)*m_logicalScaleY*m_userScaleY*m_systemScaleY) ; + return (long) (floor(y)*m_logicalScaleY*m_userScaleY*m_signY*m_systemScaleY) ; } // This group of functions may not do any conversion @@ -1395,6 +1445,19 @@ bool wxDC::Blit(long xdest, long ydest, long width, long height, long xsrc1 = xsrc; long ysrc1 = ysrc; + // Chris Breeze 18/5/98: use text foreground/background colours + // when blitting from 1-bit bitmaps + COLORREF old_textground = ::GetTextColor((HDC)m_hDC); + COLORREF old_background = ::GetBkColor((HDC)m_hDC); + if (m_textForegroundColour.Ok()) + { + ::SetTextColor((HDC) m_hDC, m_textForegroundColour.GetPixel() ) ; + } + if (m_textBackgroundColour.Ok()) + { + ::SetBkColor((HDC) m_hDC, m_textBackgroundColour.GetPixel() ) ; + } + DWORD dwRop = rop == wxCOPY ? SRCCOPY : rop == wxCLEAR ? WHITENESS : rop == wxSET ? BLACKNESS : @@ -1483,6 +1546,8 @@ bool wxDC::Blit(long xdest, long ydest, long width, long height, success = (BitBlt((HDC) m_hDC, xdest1, ydest1, (int)width, (int)height, (HDC) source->m_hDC, xsrc1, ysrc1, dwRop) != 0); } + ::SetTextColor((HDC)m_hDC, old_textground); + ::SetBkColor((HDC)m_hDC, old_background); source->EndDrawing(); EndDrawing(); diff --git a/src/msw/pen.cpp b/src/msw/pen.cpp index 12dd825ec7..831cf96b01 100644 --- a/src/msw/pen.cpp +++ b/src/msw/pen.cpp @@ -146,10 +146,6 @@ wxPen::wxPen(const wxString& col, const int Width, const int Style) M_PENDATA->m_dash = 0 ; M_PENDATA->m_hPen = 0 ; - // In Windows, only a pen of width = 1 can be dotted or dashed! - if ((Style == wxDOT) || (Style == wxLONG_DASH) || (Style == wxSHORT_DASH) || (Style == wxDOT_DASH)) - M_PENDATA->m_width = 1; - RealizeResource(); if ( wxThePenList ) @@ -176,7 +172,8 @@ bool wxPen::RealizeResource(void) if (M_PENDATA->m_join==wxJOIN_ROUND && M_PENDATA->m_cap==wxCAP_ROUND && M_PENDATA->m_style!=wxUSER_DASH && - M_PENDATA->m_style!=wxSTIPPLE + M_PENDATA->m_style!=wxSTIPPLE && + M_PENDATA->m_width <= 1 ) M_PENDATA->m_hPen = (WXHPEN) CreatePen(wx2msPenStyle(M_PENDATA->m_style), M_PENDATA->m_width, ms_colour); else diff --git a/src/msw/utils.cpp b/src/msw/utils.cpp index 53fe3c23f0..2b159bb6f1 100644 --- a/src/msw/utils.cpp +++ b/src/msw/utils.cpp @@ -419,66 +419,52 @@ void wxBell(void) #endif } +// Chris Breeze 27/5/98: revised WIN32 code to +// detect WindowsNT correctly int wxGetOsVersion(int *majorVsn, int *minorVsn) { extern char *wxOsVersion; - if (majorVsn) - *majorVsn = 0; - if (minorVsn) - *minorVsn = 0; - + if (majorVsn) *majorVsn = 0; + if (minorVsn) *minorVsn = 0; + +#ifdef WIN32 + OSVERSIONINFO info; + memset(&info, 0, sizeof(OSVERSIONINFO)); + info.dwOSVersionInfoSize = sizeof(OSVERSIONINFO); + if (GetVersionEx(&info)) + { + if (majorVsn) *majorVsn = info.dwMajorVersion; + if (minorVsn) *minorVsn = info.dwMinorVersion; + switch (info.dwPlatformId) + { + case VER_PLATFORM_WIN32s: + return wxWIN32S; + break; + case VER_PLATFORM_WIN32_WINDOWS: + return wxWIN95; + break; + case VER_PLATFORM_WIN32_NT: + return wxWINDOWS_NT; + break; + } + } + return wxWINDOWS; // error if we get here, return generic value +#else + // Win16 code... int retValue ; -#ifndef __WIN32__ -#ifdef __WINDOWS_386__ +# ifdef __WINDOWS_386__ retValue = wxWIN386; -#else - -#if !defined(__WATCOMC__) && !defined(__GNUWIN32__) && USE_PENWINDOWS +# else +# if !defined(__WATCOMC__) && !defined(GNUWIN32) extern HANDLE hPenWin; retValue = hPenWin ? wxPENWINDOWS : wxWINDOWS ; -#endif - -#endif -#else - DWORD Version = GetVersion() ; - WORD lowWord = LOWORD(Version) ; - - if (wxOsVersion) - { - if (strcmp(wxOsVersion, "Win95") == 0) - return wxWIN95; - else if (strcmp(wxOsVersion, "Win32s") == 0) - return wxWIN32S; - else if (strcmp(wxOsVersion, "Windows") == 0) - return wxWINDOWS; - else if (strcmp(wxOsVersion, "WinNT") == 0) - return wxWINDOWS_NT; - } - bool Win32s = (( Version & 0x80000000 ) != 0); - bool Win95 = (( Version & 0xFF ) >= 4); - bool WinNT = Version < 0x80000000; - - // Get the version number - if (majorVsn) - *majorVsn = LOBYTE( lowWord ); - if (minorVsn) - *minorVsn = HIBYTE( lowWord ); - - if (Win95) - return wxWIN95; - else if (Win32s) - return wxWIN32S; - else if (WinNT) - return wxWINDOWS_NT; - else - return wxWINDOWS; - -// retValue = ((high & 0x8000)==0) ? wxWINDOWS_NT : wxWIN32S ; -#endif +# endif +# endif // @@@@ To be completed. I don't have the manual here... if (majorVsn) *majorVsn = 3 ; if (minorVsn) *minorVsn = 1 ; return retValue ; +#endif } // Reading and writing resources (eg WIN.INI, .Xdefaults) -- 2.45.2