From d275c7eb8420c81e97a8b308c60c27d9856b58f9 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Sun, 30 Sep 2001 22:06:39 +0000 Subject: [PATCH] added wxUSE_PALETTE and fixed compilation with it set to 0 git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@11749 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- configure.in | 7 +++ include/wx/chkconf.h | 8 +++ include/wx/dc.h | 10 ++++ include/wx/image.h | 2 + include/wx/msw/bitmap.h | 7 +++ include/wx/msw/dc.h | 5 ++ include/wx/msw/setup0.h | 3 ++ include/wx/palette.h | 18 ++++--- include/wx/univ/setup.h | 2 + setup.h.in | 5 ++ src/common/effects.cpp | 5 ++ src/common/image.cpp | 6 +++ src/common/quantize.cpp | 35 ++++++++----- src/generic/paletteg.cpp | 34 ++++++++----- src/msw/bitmap.cpp | 20 +++++++- src/msw/data.cpp | 2 + src/msw/dc.cpp | 103 ++++++++++++++++++++++----------------- src/msw/dib.cpp | 4 ++ src/msw/gdiimage.cpp | 9 ++++ src/msw/palette.cpp | 38 +++++++-------- src/msw/pen.cpp | 3 +- 21 files changed, 226 insertions(+), 100 deletions(-) diff --git a/configure.in b/configure.in index b605d73e9a..e35d9ccb49 100644 --- a/configure.in +++ b/configure.in @@ -774,6 +774,7 @@ if test $DEBUG_CONFIGURE = 1; then DEFAULT_wxUSE_UNICODE=no DEFAULT_wxUSE_WCSRTOMBS=no + DEFAULT_wxUSE_PALETTE=no DEFAULT_wxUSE_IMAGE=no DEFAULT_wxUSE_GIF=no DEFAULT_wxUSE_PCX=no @@ -933,6 +934,7 @@ else DEFAULT_wxUSE_UNICODE=no DEFAULT_wxUSE_WCSRTOMBS=no + DEFAULT_wxUSE_PALETTE=yes DEFAULT_wxUSE_IMAGE=yes DEFAULT_wxUSE_GIF=yes DEFAULT_wxUSE_PCX=yes @@ -1290,6 +1292,7 @@ dnl --------------------------------------------------------------------------- dnl support for image formats that do not rely on external library dnl --------------------------------------------------------------------------- +WX_ARG_ENABLE(palette, [ --enable-palette use wxPalette class], wxUSE_PALETTE) WX_ARG_ENABLE(image, [ --enable-image use wxImage class], wxUSE_IMAGE) WX_ARG_ENABLE(gif, [ --enable-gif use gif images (GIF file format)], wxUSE_GIF) WX_ARG_ENABLE(pcx, [ --enable-pcx use pcx images (PCX file format)], wxUSE_PCX) @@ -4258,6 +4261,10 @@ if test "$wxUSE_VALIDATORS" = "yes"; then SAMPLES_SUBDIRS="$SAMPLES_SUBDIRS validate" fi +if test "$wxUSE_PALETTE" = "yes" ; then + AC_DEFINE(wxUSE_PALETTE) +fi + if test "$wxUSE_IMAGE" = "yes" ; then AC_DEFINE(wxUSE_IMAGE) fi diff --git a/include/wx/chkconf.h b/include/wx/chkconf.h index c55cfd8b57..4d9097ac3b 100644 --- a/include/wx/chkconf.h +++ b/include/wx/chkconf.h @@ -309,6 +309,14 @@ # endif #endif /* !defined(wxUSE_NOTEBOOK) */ +#ifndef wxUSE_PALETTE +# ifdef wxABORT_ON_CONFIG_ERROR +# error "wxUSE_PALETTE must be defined." +# else +# define wxUSE_PALETTE 0 +# endif +#endif /* !defined(wxUSE_PALETTE) */ + #ifndef wxUSE_POPUPWIN # ifdef wxABORT_ON_CONFIG_ERROR # error "wxUSE_POPUPWIN must be defined." diff --git a/include/wx/dc.h b/include/wx/dc.h index 1a7283aab7..ccf87a1784 100644 --- a/include/wx/dc.h +++ b/include/wx/dc.h @@ -316,7 +316,9 @@ public: virtual void SetBrush(const wxBrush& brush) = 0; virtual void SetBackground(const wxBrush& brush) = 0; virtual void SetBackgroundMode(int mode) = 0; +#if wxUSE_PALETTE virtual void SetPalette(const wxPalette& palette) = 0; +#endif // wxUSE_PALETTE // clipping region // --------------- @@ -588,12 +590,17 @@ public: #endif // !Win16 #if WXWIN_COMPATIBILITY + +#if wxUSE_PALETTE virtual void SetColourMap(const wxPalette& palette) { SetPalette(palette); } +#endif // wxUSE_PALETTE + void GetTextExtent(const wxString& string, float *x, float *y, float *descent = NULL, float *externalLeading = NULL, wxFont *theFont = NULL, bool use16bit = FALSE) const ; void GetSize(float* width, float* height) const { int w, h; GetSize(& w, & h); *width = w; *height = h; } void GetSizeMM(float *width, float *height) const { long w, h; GetSizeMM(& w, & h); *width = (float) w; *height = (float) h; } + #endif // WXWIN_COMPATIBILITY protected: @@ -731,7 +738,10 @@ protected: wxColour m_textForegroundColour; wxColour m_textBackgroundColour; wxFont m_font; + +#if wxUSE_PALETTE wxPalette m_palette; +#endif // wxUSE_PALETTE private: DECLARE_NO_COPY_CLASS(wxDCBase) diff --git a/include/wx/image.h b/include/wx/image.h index adfce58b9c..4c145b247d 100644 --- a/include/wx/image.h +++ b/include/wx/image.h @@ -185,10 +185,12 @@ public: void SetMask( bool mask = TRUE ); bool HasMask() const; +#if wxUSE_PALETTE // Palette functions bool HasPalette() const; const wxPalette& GetPalette() const; void SetPalette(const wxPalette& palette); +#endif // wxUSE_PALETTE // Option functions (arbitrary name/value mapping) void SetOption(const wxString& name, const wxString& value); diff --git a/include/wx/msw/bitmap.h b/include/wx/msw/bitmap.h index 85f7b683c5..dff632bbb3 100644 --- a/include/wx/msw/bitmap.h +++ b/include/wx/msw/bitmap.h @@ -29,6 +29,7 @@ class WXDLLEXPORT wxMask; class WXDLLEXPORT wxCursor; class WXDLLEXPORT wxControl; class WXDLLEXPORT wxImage; +class WXDLLEXPORT wxPalette; // ---------------------------------------------------------------------------- // Bitmap data @@ -47,7 +48,9 @@ public: public: int m_numColors; +#if wxUSE_PALETTE wxPalette m_bitmapPalette; +#endif // wxUSE_PALETTE int m_quality; // MSW-specific @@ -147,8 +150,10 @@ public: int GetQuality() const { return (GetBitmapData() ? GetBitmapData()->m_quality : 0); } void SetQuality(int q); +#if wxUSE_PALETTE wxPalette* GetPalette() const { return (GetBitmapData() ? (& GetBitmapData()->m_bitmapPalette) : (wxPalette*) NULL); } void SetPalette(const wxPalette& palette); +#endif // wxUSE_PALETTE wxMask *GetMask() const { return (GetBitmapData() ? GetBitmapData()->m_bitmapMask : (wxMask*) NULL); } void SetMask(wxMask *mask) ; @@ -160,10 +165,12 @@ public: void SetOk(bool isOk); #endif // WXWIN_COMPATIBILITY_2 +#if wxUSE_PALETTE #if WXWIN_COMPATIBILITY wxPalette *GetColourMap() const { return GetPalette(); } void SetColourMap(wxPalette *cmap) { SetPalette(*cmap); }; #endif // WXWIN_COMPATIBILITY +#endif // wxUSE_PALETTE // Implementation public: diff --git a/include/wx/msw/dc.h b/include/wx/msw/dc.h index 50e310c902..30f79932f5 100644 --- a/include/wx/msw/dc.h +++ b/include/wx/msw/dc.h @@ -115,7 +115,9 @@ public: virtual void SetBrush(const wxBrush& brush); virtual void SetBackground(const wxBrush& brush); virtual void SetBackgroundMode(int mode); +#if wxUSE_PALETTE virtual void SetPalette(const wxPalette& palette); +#endif // wxUSE_PALETTE virtual void DestroyClippingRegion(); @@ -255,7 +257,10 @@ protected: WXHPEN m_oldPen; WXHBRUSH m_oldBrush; WXHFONT m_oldFont; + +#if wxUSE_PALETTE WXHPALETTE m_oldPalette; +#endif // wxUSE_PALETTE #if wxUSE_DC_CACHEING static wxList sm_bitmapCache; diff --git a/include/wx/msw/setup0.h b/include/wx/msw/setup0.h index 4591583e2a..0021a80906 100644 --- a/include/wx/msw/setup0.h +++ b/include/wx/msw/setup0.h @@ -890,6 +890,9 @@ // Set to 1 for XPM format support #define wxUSE_XPM 1 +// Set to 1 to compile in wxPalette class +#define wxUSE_PALETTE 1 + // ---------------------------------------------------------------------------- // Windows-only settings // ---------------------------------------------------------------------------- diff --git a/include/wx/palette.h b/include/wx/palette.h index a09f55dc32..8e8c6b5bba 100644 --- a/include/wx/palette.h +++ b/include/wx/palette.h @@ -1,21 +1,25 @@ #ifndef _WX_PALETTE_H_BASE_ #define _WX_PALETTE_H_BASE_ +#if wxUSE_PALETTE + #if defined(__WXMSW__) -#include "wx/msw/palette.h" + #include "wx/msw/palette.h" #elif defined(__WXMOTIF__) -#include "wx/motif/palette.h" + #include "wx/motif/palette.h" #elif defined(__WXGTK__) -#include "wx/generic/paletteg.h" + #include "wx/generic/paletteg.h" #elif defined(__WXMGL__) -#include "wx/mgl/palette.h" + #include "wx/mgl/palette.h" #elif defined(__WXMAC__) -#include "wx/mac/palette.h" + #include "wx/mac/palette.h" #elif defined(__WXPM__) -#include "wx/os2/palette.h" + #include "wx/os2/palette.h" #elif defined(__WXSTUBS__) -#include "wx/stubs/palette.h" + #include "wx/stubs/palette.h" #endif +#endif // wxUSE_PALETTE + #endif // _WX_PALETTE_H_BASE_ diff --git a/include/wx/univ/setup.h b/include/wx/univ/setup.h index b61f2df207..b115ff9e58 100644 --- a/include/wx/univ/setup.h +++ b/include/wx/univ/setup.h @@ -329,4 +329,6 @@ #endif +#define wxUSE_PALETTE 0 + #endif // _WX_UNIV_SETUP_H_ diff --git a/setup.h.in b/setup.h.in index 925b4c5c20..94bdba822a 100644 --- a/setup.h.in +++ b/setup.h.in @@ -762,6 +762,11 @@ */ #define wxUSE_ZIPSTREAM 0 +/* + * wxPalette class + */ +#define wxUSE_PALETTE 0 + /* * wxImage support */ diff --git a/src/common/effects.cpp b/src/common/effects.cpp index ae4c66e40f..965c5724ea 100644 --- a/src/common/effects.cpp +++ b/src/common/effects.cpp @@ -96,11 +96,14 @@ bool wxEffects::TileBitmap(const wxRect& rect, wxDC& dc, wxBitmap& bitmap) wxMemoryDC dcMem; +#if wxUSE_PALETTE if (bitmap.GetPalette() && !hiColour) { dc.SetPalette(* bitmap.GetPalette()); dcMem.SetPalette(* bitmap.GetPalette()); } +#endif // wxUSE_PALETTE + dcMem.SelectObject(bitmap); int i, j; @@ -111,11 +114,13 @@ bool wxEffects::TileBitmap(const wxRect& rect, wxDC& dc, wxBitmap& bitmap) } dcMem.SelectObject(wxNullBitmap); +#if wxUSE_PALETTE if (bitmap.GetPalette() && !hiColour) { dc.SetPalette(wxNullPalette); dcMem.SetPalette(wxNullPalette); } +#endif // wxUSE_PALETTE return TRUE; } diff --git a/src/common/image.cpp b/src/common/image.cpp index 51318de205..fe48bf366a 100644 --- a/src/common/image.cpp +++ b/src/common/image.cpp @@ -58,7 +58,9 @@ public: unsigned char m_maskRed,m_maskGreen,m_maskBlue; bool m_ok; bool m_static; +#if wxUSE_PALETTE wxPalette m_palette; +#endif // wxUSE_PALETTE wxArrayString m_optionNames; wxArrayString m_optionValues; }; @@ -718,6 +720,8 @@ int wxImage::GetHeight() const return M_IMGDATA->m_height; } +#if wxUSE_PALETTE + // Palette functions bool wxImage::HasPalette() const @@ -742,6 +746,8 @@ void wxImage::SetPalette(const wxPalette& palette) M_IMGDATA->m_palette = palette; } +#endif // wxUSE_PALETTE + // Option functions (arbitrary name/value mapping) void wxImage::SetOption(const wxString& name, const wxString& value) { diff --git a/src/common/quantize.cpp b/src/common/quantize.cpp index f6e1fb45ba..07c63c52e2 100644 --- a/src/common/quantize.cpp +++ b/src/common/quantize.cpp @@ -1483,8 +1483,11 @@ void wxQuantize::DoQuantize(unsigned w, unsigned h, unsigned char **in_rows, uns // TODO: somehow make use of the Windows system colours, rather than ignoring them for the // purposes of quantization. -bool wxQuantize::Quantize(const wxImage& src, wxImage& dest, wxPalette** pPalette, int desiredNoColours, - unsigned char** eightBitData, int flags) +bool wxQuantize::Quantize(const wxImage& src, wxImage& dest, + wxPalette** pPalette, + int desiredNoColours, + unsigned char** eightBitData, + int flags) { int i; @@ -1559,6 +1562,7 @@ bool wxQuantize::Quantize(const wxImage& src, wxImage& dest, wxPalette** pPalett else delete[] data8bit; +#if wxUSE_PALETTE // Make a wxWindows palette if (pPalette) { @@ -1604,6 +1608,7 @@ bool wxQuantize::Quantize(const wxImage& src, wxImage& dest, wxPalette** pPalett delete[] g; delete[] b; } +#endif // wxUSE_PALETTE return TRUE; } @@ -1611,20 +1616,24 @@ bool wxQuantize::Quantize(const wxImage& src, wxImage& dest, wxPalette** pPalett // This version sets a palette in the destination image so you don't // have to manage it yourself. -bool wxQuantize::Quantize(const wxImage& src, wxImage& dest, int desiredNoColours, - unsigned char** eightBitData, int flags) +bool wxQuantize::Quantize(const wxImage& src, + wxImage& dest, + int desiredNoColours, + unsigned char** eightBitData, + int flags) { wxPalette* palette = NULL; - if (Quantize(src, dest, & palette, desiredNoColours, eightBitData, flags)) + if ( !Quantize(src, dest, & palette, desiredNoColours, eightBitData, flags) ) + return FALSE; + +#if wxUSE_PALETTE + if (palette) { - if (palette) - { - dest.SetPalette(* palette); - delete palette; - } - return TRUE; + dest.SetPalette(* palette); + delete palette; } - else - return FALSE; +#endif // wxUSE_PALETTE + + return TRUE; } diff --git a/src/generic/paletteg.cpp b/src/generic/paletteg.cpp index edb0336210..ce66f89140 100644 --- a/src/generic/paletteg.cpp +++ b/src/generic/paletteg.cpp @@ -1,11 +1,11 @@ ///////////////////////////////////////////////////////////////////////////// -// Name: palette.cpp +// Name: src/generic/paletteg.cpp // Purpose: // Author: Robert Roebling // Created: 01/02/97 // Id: // Copyright: (c) 1998 Robert Roebling, Julian Smart and Markus Holzem -// Licence: wxWindows licence +// Licence: wxWindows licence ///////////////////////////////////////////////////////////////////////////// @@ -13,8 +13,16 @@ #pragma implementation "paletteg.h" #endif -#include "wx/palette.h" +// For compilers that support precompilation, includes "wx.h". +#include "wx/wxprec.h" + +#if defined(__BORLANDC__) + #pragma hdrstop +#endif + +#if wxUSE_PALETTE +#include "wx/palette.h" //----------------------------------------------------------------------------- // wxPalette @@ -96,13 +104,13 @@ bool wxPalette::Ok(void) const bool wxPalette::Create(int n, const unsigned char *red, - const unsigned char *green, + const unsigned char *green, const unsigned char *blue) { UnRef(); m_refData = new wxPaletteRefData(); - - M_PALETTEDATA->m_count = n; + + M_PALETTEDATA->m_count = n; M_PALETTEDATA->m_entries = new wxPaletteEntry[n]; wxPaletteEntry *e = M_PALETTEDATA->m_entries; @@ -122,8 +130,8 @@ int wxPalette::GetPixel( const unsigned char red, { if (!m_refData) return FALSE; - int closest = 0; - double d,distance = 1000.0; // max. dist is 256 + int closest = 0; + double d,distance = 1000.0; // max. dist is 256 wxPaletteEntry *e = M_PALETTEDATA->m_entries; for (int i = 0; i < M_PALETTEDATA->m_count; i++, e++) @@ -135,17 +143,17 @@ int wxPalette::GetPixel( const unsigned char red, closest = i; } } - return closest; + return closest; } -bool wxPalette::GetRGB(int pixel, +bool wxPalette::GetRGB(int pixel, unsigned char *red, - unsigned char *green, + unsigned char *green, unsigned char *blue) const { if (!m_refData) return FALSE; if (pixel >= M_PALETTEDATA->m_count) return FALSE; - + wxPaletteEntry& p = M_PALETTEDATA->m_entries[pixel]; if (red) *red = p.red; if (green) *green = p.green; @@ -153,4 +161,6 @@ bool wxPalette::GetRGB(int pixel, return TRUE; } +#endif // wxUSE_PALETTE + diff --git a/src/msw/bitmap.cpp b/src/msw/bitmap.cpp index 8e8b4e0832..a68e54fa7d 100644 --- a/src/msw/bitmap.cpp +++ b/src/msw/bitmap.cpp @@ -467,12 +467,14 @@ bool wxBitmap::CreateFromImage( const wxImage& image, int depth ) hbitmap = ::CreateCompatibleBitmap( hdc, width, bmpHeight ); ::SelectObject( memdc, hbitmap); +#if wxUSE_PALETTE HPALETTE hOldPalette = 0; if (image.GetPalette().Ok()) { hOldPalette = ::SelectPalette(memdc, (HPALETTE) image.GetPalette().GetHPALETTE(), FALSE); ::RealizePalette(memdc); } +#endif // wxUSE_PALETTE // copy image data into DIB data and then into DDB (in a loop) unsigned char *data = image.GetData(); @@ -523,8 +525,10 @@ bool wxBitmap::CreateFromImage( const wxImage& image, int depth ) } SetHBITMAP( (WXHBITMAP) hbitmap ); +#if wxUSE_PALETTE if (hOldPalette) SelectPalette(memdc, hOldPalette, FALSE); +#endif // wxUSE_PALETTE // similarly, created an mono-bitmap for the possible mask if( image.HasMask() ) @@ -792,7 +796,9 @@ bool wxBitmap::Create(void *data, long type, int width, int height, int depth) return handler->Create(this, data, type, width, height, depth); } -bool wxBitmap::SaveFile(const wxString& filename, int type, const wxPalette *palette) +bool wxBitmap::SaveFile(const wxString& filename, + int type, + const wxPalette *palette) { wxBitmapHandler *handler = wxDynamicCast(FindHandler(type), wxBitmapHandler); @@ -882,6 +888,8 @@ void wxBitmap::SetOk(bool isOk) } #endif // WXWIN_COMPATIBILITY_2 +#if wxUSE_PALETTE + void wxBitmap::SetPalette(const wxPalette& palette) { EnsureHasData(); @@ -889,6 +897,8 @@ void wxBitmap::SetPalette(const wxPalette& palette) GetBitmapData()->m_bitmapPalette = palette; } +#endif // wxUSE_PALETTE + void wxBitmap::SetMask(wxMask *mask) { EnsureHasData(); @@ -911,6 +921,7 @@ wxBitmap wxBitmap::GetBitmapForDC(wxDC& dc) const LPBITMAPINFO lpDib; void *lpBits = (void*) NULL; +#if wxUSE_PALETTE if( GetPalette() && GetPalette()->Ok() ) { tmpBitmap.SetPalette(*GetPalette()); @@ -927,6 +938,9 @@ wxBitmap wxBitmap::GetBitmapForDC(wxDC& dc) const memDC.SelectObject(tmpBitmap); memDC.SetPalette( palette ); } +#else // !wxUSE_PALETTE + hPal = (HPALETTE) ::GetStockObject(DEFAULT_PALETTE); +#endif // wxUSE_PALETTE/!wxUSE_PALETTE // set the height negative because in a DIB the order of the lines is // reversed @@ -1032,6 +1046,8 @@ bool wxMask::Create(const wxBitmap& bitmap, int paletteIndex) ::DeleteObject((HBITMAP) m_maskBitmap); m_maskBitmap = 0; } + +#if wxUSE_PALETTE if (bitmap.Ok() && bitmap.GetPalette()->Ok()) { unsigned char red, green, blue; @@ -1041,6 +1057,8 @@ bool wxMask::Create(const wxBitmap& bitmap, int paletteIndex) return Create(bitmap, transparentColour); } } +#endif // wxUSE_PALETTE + return FALSE; } diff --git a/src/msw/data.cpp b/src/msw/data.cpp index 7e863a33d3..9657bb89ed 100644 --- a/src/msw/data.cpp +++ b/src/msw/data.cpp @@ -96,7 +96,9 @@ wxIcon wxNullIcon; wxCursor wxNullCursor; wxPen wxNullPen; wxBrush wxNullBrush; +#if wxUSE_PALETTE wxPalette wxNullPalette; +#endif // wxUSE_PALETTE wxFont wxNullFont; wxColour wxNullColour; diff --git a/src/msw/dc.cpp b/src/msw/dc.cpp index 9691e86fe2..596a748cf3 100644 --- a/src/msw/dc.cpp +++ b/src/msw/dc.cpp @@ -178,7 +178,9 @@ wxDC::wxDC() m_oldPen = 0; m_oldBrush = 0; m_oldFont = 0; +#if wxUSE_PALETTE m_oldPalette = 0; +#endif // wxUSE_PALETTE m_bOwnsDC = FALSE; m_hDC = 0; @@ -246,16 +248,21 @@ void wxDC::SelectOldObjects(WXHDC dc) ::SelectObject((HDC) dc, (HFONT) m_oldFont); } m_oldFont = 0; + +#if wxUSE_PALETTE if (m_oldPalette) { ::SelectPalette((HDC) dc, (HPALETTE) m_oldPalette, TRUE); } m_oldPalette = 0; +#endif // wxUSE_PALETTE } m_brush = wxNullBrush; m_pen = wxNullPen; +#if wxUSE_PALETTE m_palette = wxNullPalette; +#endif // wxUSE_PALETTE m_font = wxNullFont; m_backgroundBrush = wxNullBrush; m_selectedBitmap = wxNullBitmap; @@ -270,7 +277,7 @@ void wxDC::UpdateClipBox() #ifdef __WXMICROWIN__ if (!GetHDC()) return; #endif - + RECT rect; GetClipBox(GetHdc(), &rect); @@ -285,7 +292,7 @@ void wxDC::DoSetClippingRegion(wxCoord x, wxCoord y, wxCoord w, wxCoord h) #ifdef __WXMICROWIN__ if (!GetHDC()) return; #endif - + m_clipping = TRUE; // the region coords are always the device ones, so do the translation @@ -317,7 +324,7 @@ void wxDC::DoSetClippingRegionAsRegion(const wxRegion& region) #ifdef __WXMICROWIN__ if (!GetHDC()) return; #endif - + wxCHECK_RET( GetHrgnOf(region), wxT("invalid clipping region") ); m_clipping = TRUE; @@ -336,7 +343,7 @@ void wxDC::DestroyClippingRegion() #ifdef __WXMICROWIN__ if (!GetHDC()) return; #endif - + if (m_clipping && m_hDC) { // TODO: this should restore the previous clipping region, @@ -377,7 +384,7 @@ int wxDC::GetDepth() const #ifdef __WXMICROWIN__ if (!GetHDC()) return 16; #endif - + return (int)::GetDeviceCaps(GetHdc(), BITSPIXEL); } @@ -390,7 +397,7 @@ void wxDC::Clear() #ifdef __WXMICROWIN__ if (!GetHDC()) return; #endif - + RECT rect; if ( m_canvas ) { @@ -428,7 +435,7 @@ void wxDC::DoFloodFill(wxCoord x, wxCoord y, const wxColour& col, int style) #ifdef __WXMICROWIN__ if (!GetHDC()) return; #endif - + if ( !::ExtFloodFill(GetHdc(), XLOG2DEV(x), YLOG2DEV(y), col.GetPixel(), style == wxFLOOD_SURFACE ? FLOODFILLSURFACE @@ -457,7 +464,7 @@ bool wxDC::DoGetPixel(wxCoord x, wxCoord y, wxColour *col) const #ifdef __WXMICROWIN__ if (!GetHDC()) return FALSE; #endif - + wxCHECK_MSG( col, FALSE, _T("NULL colour parameter in wxDC::GetPixel") ); // get the color of the pixel @@ -473,7 +480,7 @@ void wxDC::DoCrossHair(wxCoord x, wxCoord y) #ifdef __WXMICROWIN__ if (!GetHDC()) return; #endif - + wxCoord x1 = x-VIEWPORT_EXTENT; wxCoord y1 = y-VIEWPORT_EXTENT; wxCoord x2 = x+VIEWPORT_EXTENT; @@ -494,7 +501,7 @@ void wxDC::DoDrawLine(wxCoord x1, wxCoord y1, wxCoord x2, wxCoord y2) #ifdef __WXMICROWIN__ if (!GetHDC()) return; #endif - + (void)MoveToEx(GetHdc(), XLOG2DEV(x1), YLOG2DEV(y1), NULL); (void)LineTo(GetHdc(), XLOG2DEV(x2), YLOG2DEV(y2)); @@ -515,7 +522,7 @@ void wxDC::DoDrawArc(wxCoord x1, wxCoord y1, #ifdef __WXMICROWIN__ if (!GetHDC()) return; #endif - + wxColourChanger cc(*this); // needed for wxSTIPPLE_MASK_OPAQUE handling double dx = xc - x1; @@ -567,7 +574,7 @@ void wxDC::DoDrawCheckMark(wxCoord x1, wxCoord y1, #ifdef __WXMICROWIN__ if (!GetHDC()) return; #endif - + wxCoord x2 = x1 + width, y2 = y1 + height; @@ -605,7 +612,7 @@ void wxDC::DoDrawPoint(wxCoord x, wxCoord y) #ifdef __WXMICROWIN__ if (!GetHDC()) return; #endif - + COLORREF color = 0x00ffffff; if (m_pen.Ok()) { @@ -622,7 +629,7 @@ void wxDC::DoDrawPolygon(int n, wxPoint points[], wxCoord xoffset, wxCoord yoffs #ifdef __WXMICROWIN__ if (!GetHDC()) return; #endif - + wxColourChanger cc(*this); // needed for wxSTIPPLE_MASK_OPAQUE handling // Do things less efficiently if we have offsets @@ -659,7 +666,7 @@ void wxDC::DoDrawLines(int n, wxPoint points[], wxCoord xoffset, wxCoord yoffset #ifdef __WXMICROWIN__ if (!GetHDC()) return; #endif - + // Do things less efficiently if we have offsets if (xoffset != 0 || yoffset != 0) { @@ -690,7 +697,7 @@ void wxDC::DoDrawRectangle(wxCoord x, wxCoord y, wxCoord width, wxCoord height) #ifdef __WXMICROWIN__ if (!GetHDC()) return; #endif - + wxColourChanger cc(*this); // needed for wxSTIPPLE_MASK_OPAQUE handling wxCoord x2 = x + width; @@ -731,7 +738,7 @@ void wxDC::DoDrawRoundedRectangle(wxCoord x, wxCoord y, wxCoord width, wxCoord h #ifdef __WXMICROWIN__ if (!GetHDC()) return; #endif - + wxColourChanger cc(*this); // needed for wxSTIPPLE_MASK_OPAQUE handling // Now, a negative radius value is interpreted to mean @@ -771,7 +778,7 @@ void wxDC::DoDrawEllipse(wxCoord x, wxCoord y, wxCoord width, wxCoord height) #ifdef __WXMICROWIN__ if (!GetHDC()) return; #endif - + wxColourChanger cc(*this); // needed for wxSTIPPLE_MASK_OPAQUE handling wxCoord x2 = (x+width); @@ -789,7 +796,7 @@ void wxDC::DoDrawEllipticArc(wxCoord x,wxCoord y,wxCoord w,wxCoord h,double sa,d #ifdef __WXMICROWIN__ if (!GetHDC()) return; #endif - + wxColourChanger cc(*this); // needed for wxSTIPPLE_MASK_OPAQUE handling wxCoord x2 = x + w; @@ -836,7 +843,7 @@ void wxDC::DoDrawIcon(const wxIcon& icon, wxCoord x, wxCoord y) #ifdef __WXMICROWIN__ if (!GetHDC()) return; #endif - + wxCHECK_RET( icon.Ok(), wxT("invalid icon in DrawIcon") ); #ifdef __WIN32__ @@ -854,7 +861,7 @@ void wxDC::DoDrawBitmap( const wxBitmap &bmp, wxCoord x, wxCoord y, bool useMask #ifdef __WXMICROWIN__ if (!GetHDC()) return; #endif - + wxCHECK_RET( bmp.Ok(), _T("invalid bitmap in wxDC::DrawBitmap") ); int width = bmp.GetWidth(), @@ -945,7 +952,7 @@ void wxDC::DoDrawText(const wxString& text, wxCoord x, wxCoord y) #ifdef __WXMICROWIN__ if (!GetHDC()) return; #endif - + DrawAnyText(text, x, y); // update the bounding box @@ -961,7 +968,7 @@ void wxDC::DrawAnyText(const wxString& text, wxCoord x, wxCoord y) #ifdef __WXMICROWIN__ if (!GetHDC()) return; #endif - + // prepare for drawing the text if ( m_textForegroundColour.Ok() ) SetTextColor(GetHdc(), m_textForegroundColour.GetPixel()); @@ -997,7 +1004,7 @@ void wxDC::DoDrawRotatedText(const wxString& text, #ifdef __WXMICROWIN__ if (!GetHDC()) return; #endif - + // we test that we have some font because otherwise we should still use the // "else" part below to avoid that DrawRotatedText(angle = 180) and // DrawRotatedText(angle = 0) use different fonts (we can't use the default @@ -1065,12 +1072,14 @@ void wxDC::DoDrawRotatedText(const wxString& text, // set GDI objects // --------------------------------------------------------------------------- +#if wxUSE_PALETTE + void wxDC::SetPalette(const wxPalette& palette) { #ifdef __WXMICROWIN__ if (!GetHDC()) return; #endif - + // Set the old object temporarily, in case the assignment deletes an object // that's not yet selected out. if (m_oldPalette) @@ -1104,12 +1113,14 @@ void wxDC::SetPalette(const wxPalette& palette) } } +#endif // wxUSE_PALETTE + void wxDC::SetFont(const wxFont& the_font) { #ifdef __WXMICROWIN__ if (!GetHDC()) return; #endif - + // Set the old object temporarily, in case the assignment deletes an object // that's not yet selected out. if (m_oldFont) @@ -1144,7 +1155,7 @@ void wxDC::SetPen(const wxPen& pen) #ifdef __WXMICROWIN__ if (!GetHDC()) return; #endif - + // Set the old object temporarily, in case the assignment deletes an object // that's not yet selected out. if (m_oldPen) @@ -1178,7 +1189,7 @@ void wxDC::SetBrush(const wxBrush& brush) #ifdef __WXMICROWIN__ if (!GetHDC()) return; #endif - + // Set the old object temporarily, in case the assignment deletes an object // that's not yet selected out. if (m_oldBrush) @@ -1229,7 +1240,7 @@ void wxDC::SetBackground(const wxBrush& brush) #ifdef __WXMICROWIN__ if (!GetHDC()) return; #endif - + m_backgroundBrush = brush; if (!m_backgroundBrush.Ok()) @@ -1274,7 +1285,7 @@ void wxDC::SetBackgroundMode(int mode) #ifdef __WXMICROWIN__ if (!GetHDC()) return; #endif - + m_backgroundMode = mode; // SetBackgroundColour now only refers to text background @@ -1294,7 +1305,7 @@ void wxDC::SetLogicalFunction(int function) #ifdef __WXMICROWIN__ if (!GetHDC()) return; #endif - + m_logicalFunction = function; SetRop(m_hDC); @@ -1361,7 +1372,7 @@ wxCoord wxDC::GetCharHeight() const #ifdef __WXMICROWIN__ if (!GetHDC()) return 0; #endif - + TEXTMETRIC lpTextMetric; GetTextMetrics(GetHdc(), &lpTextMetric); @@ -1374,7 +1385,7 @@ wxCoord wxDC::GetCharWidth() const #ifdef __WXMICROWIN__ if (!GetHDC()) return 0; #endif - + TEXTMETRIC lpTextMetric; GetTextMetrics(GetHdc(), &lpTextMetric); @@ -1396,7 +1407,7 @@ void wxDC::DoGetTextExtent(const wxString& string, wxCoord *x, wxCoord *y, return; } #endif - + HFONT hfontOld; if ( font ) { @@ -1431,7 +1442,7 @@ void wxDC::SetMapMode(int mode) #ifdef __WXMICROWIN__ if (!GetHDC()) return; #endif - + m_mappingMode = mode; int pixel_width = 0; @@ -1503,7 +1514,7 @@ void wxDC::SetUserScale(double x, double y) #ifdef __WXMICROWIN__ if (!GetHDC()) return; #endif - + m_userScaleX = x; m_userScaleY = y; @@ -1515,7 +1526,7 @@ void wxDC::SetAxisOrientation(bool xLeftRight, bool yBottomUp) #ifdef __WXMICROWIN__ if (!GetHDC()) return; #endif - + m_signX = xLeftRight ? 1 : -1; m_signY = yBottomUp ? -1 : 1; @@ -1527,7 +1538,7 @@ void wxDC::SetSystemScale(double x, double y) #ifdef __WXMICROWIN__ if (!GetHDC()) return; #endif - + m_scaleX = x; m_scaleY = y; @@ -1539,7 +1550,7 @@ void wxDC::SetLogicalOrigin(wxCoord x, wxCoord y) #ifdef __WXMICROWIN__ if (!GetHDC()) return; #endif - + m_logicalOriginX = x; m_logicalOriginY = y; @@ -1551,7 +1562,7 @@ void wxDC::SetDeviceOrigin(wxCoord x, wxCoord y) #ifdef __WXMICROWIN__ if (!GetHDC()) return; #endif - + m_deviceOriginX = x; m_deviceOriginY = y; @@ -1619,7 +1630,7 @@ bool wxDC::DoBlit(wxCoord xdest, wxCoord ydest, #ifdef __WXMICROWIN__ if (!GetHDC()) return FALSE; #endif - + wxMask *mask = NULL; if ( useMask ) { @@ -1803,7 +1814,7 @@ void wxDC::DoGetSize(int *w, int *h) const #ifdef __WXMICROWIN__ if (!GetHDC()) return; #endif - + if ( w ) *w = ::GetDeviceCaps(GetHdc(), HORZRES); if ( h ) *h = ::GetDeviceCaps(GetHdc(), VERTRES); } @@ -1813,7 +1824,7 @@ void wxDC::DoGetSizeMM(int *w, int *h) const #ifdef __WXMICROWIN__ if (!GetHDC()) return; #endif - + if ( w ) *w = ::GetDeviceCaps(GetHdc(), HORZSIZE); if ( h ) *h = ::GetDeviceCaps(GetHdc(), VERTSIZE); } @@ -1823,7 +1834,7 @@ wxSize wxDC::GetPPI() const #ifdef __WXMICROWIN__ if (!GetHDC()) return wxSize(); #endif - + int x = ::GetDeviceCaps(GetHdc(), LOGPIXELSX); int y = ::GetDeviceCaps(GetHdc(), LOGPIXELSY); @@ -1836,7 +1847,7 @@ void wxDC::SetLogicalScale(double x, double y) #ifdef __WXMICROWIN__ if (!GetHDC()) return; #endif - + m_logicalScaleX = x; m_logicalScaleY = y; } @@ -1849,7 +1860,7 @@ void wxDC::DoGetTextExtent(const wxString& string, float *x, float *y, #ifdef __WXMICROWIN__ if (!GetHDC()) return; #endif - + wxCoord x1, y1, descent1, externalLeading1; GetTextExtent(string, & x1, & y1, & descent1, & externalLeading1, theFont, use16bit); *x = x1; *y = y1; diff --git a/src/msw/dib.cpp b/src/msw/dib.cpp index a4db58f8df..f5b86d7c2b 100644 --- a/src/msw/dib.cpp +++ b/src/msw/dib.cpp @@ -708,12 +708,14 @@ bool wxLoadIntoBitmap(wxChar *filename, wxBitmap *bitmap, wxPalette **pal) if (hPalette) { +#if wxUSE_PALETTE if (pal) { *pal = new wxPalette; (*pal)->SetHPALETTE((WXHPALETTE) hPalette); } else +#endif // wxUSE_PALETTE DeleteObject(hPalette); } else if (pal) @@ -928,8 +930,10 @@ HANDLE wxBitmapToDIB (HBITMAP hBitmap, HPALETTE hPal) bool wxSaveBitmap(wxChar *filename, wxBitmap *bitmap, wxPalette *colourmap) { HPALETTE hPalette = 0; +#if wxUSE_PALETTE if (colourmap) hPalette = (HPALETTE) colourmap->GetHPALETTE(); +#endif // wxUSE_PALETTE HANDLE dibHandle = wxBitmapToDIB((HBITMAP) bitmap->GetHBITMAP(), hPalette); if (dibHandle) diff --git a/src/msw/gdiimage.cpp b/src/msw/gdiimage.cpp index 64ad5b730c..3ead2479d1 100644 --- a/src/msw/gdiimage.cpp +++ b/src/msw/gdiimage.cpp @@ -355,6 +355,8 @@ bool wxBMPFileHandler::LoadFile(wxBitmap *bitmap, #if wxUSE_IMAGE_LOADING_IN_MSW wxPalette *palette = NULL; bool success = wxLoadIntoBitmap(WXSTRINGCAST name, bitmap, &palette) != 0; + +#if wxUSE_PALETTE if ( success && palette ) { bitmap->SetPalette(*palette); @@ -362,6 +364,7 @@ bool wxBMPFileHandler::LoadFile(wxBitmap *bitmap, // it was copied by the bitmap if it was loaded successfully delete palette; +#endif // wxUSE_PALETTE return success; #else @@ -375,9 +378,15 @@ bool wxBMPFileHandler::SaveFile(wxBitmap *bitmap, const wxPalette *pal) { #if wxUSE_IMAGE_LOADING_IN_MSW + +#if wxUSE_PALETTE wxPalette *actualPalette = (wxPalette *)pal; if ( !actualPalette ) actualPalette = bitmap->GetPalette(); +#else + wxPalette *actualPalette = NULL; +#endif // wxUSE_PALETTE + return wxSaveBitmap(WXSTRINGCAST name, bitmap, actualPalette) != 0; #else return FALSE; diff --git a/src/msw/palette.cpp b/src/msw/palette.cpp index 7d88c7fe72..48d8a76150 100644 --- a/src/msw/palette.cpp +++ b/src/msw/palette.cpp @@ -6,7 +6,7 @@ // Created: 04/01/98 // RCS-ID: $Id$ // Copyright: (c) Julian Smart and Markus Holzem -// Licence: wxWindows license +// Licence: wxWindows license ///////////////////////////////////////////////////////////////////////////// #ifdef __GNUG__ @@ -17,18 +17,16 @@ #include "wx/wxprec.h" #ifdef __BORLANDC__ -#pragma hdrstop + #pragma hdrstop #endif +#if wxUSE_PALETTE + #ifndef WX_PRECOMP -#include -#include "wx/setup.h" -#include "wx/palette.h" + #include "wx/palette.h" #endif -#include - -#include "assert.h" +#include "wx/msw/private.h" IMPLEMENT_DYNAMIC_CLASS(wxPalette, wxGDIObject) @@ -44,8 +42,8 @@ wxPaletteRefData::wxPaletteRefData(void) wxPaletteRefData::~wxPaletteRefData(void) { - if ( m_hPalette ) - ::DeleteObject((HPALETTE) m_hPalette); + if ( m_hPalette ) + ::DeleteObject((HPALETTE) m_hPalette); } wxPalette::wxPalette(void) @@ -59,16 +57,16 @@ wxPalette::wxPalette(int n, const unsigned char *red, const unsigned char *green wxPalette::~wxPalette(void) { -// FreeResource(TRUE); +// FreeResource(TRUE); } bool wxPalette::FreeResource(bool WXUNUSED(force)) { - if ( M_PALETTEDATA && M_PALETTEDATA->m_hPalette) - { + if ( M_PALETTEDATA && M_PALETTEDATA->m_hPalette) + { DeleteObject((HPALETTE)M_PALETTEDATA->m_hPalette); - } - return TRUE; + } + return TRUE; } bool wxPalette::Create(int n, const unsigned char *red, const unsigned char *green, const unsigned char *blue) @@ -112,7 +110,7 @@ int wxPalette::GetPixel(const unsigned char red, const unsigned char green, cons return FALSE; #else if ( !m_refData ) - return FALSE; + return FALSE; return ::GetNearestPaletteIndex((HPALETTE) M_PALETTEDATA->m_hPalette, PALETTERGB(red, green, blue)); #endif @@ -124,7 +122,7 @@ bool wxPalette::GetRGB(int index, unsigned char *red, unsigned char *green, unsi return FALSE; #else if ( !m_refData ) - return FALSE; + return FALSE; if (index < 0 || index > 255) return FALSE; @@ -143,9 +141,11 @@ bool wxPalette::GetRGB(int index, unsigned char *red, unsigned char *green, unsi void wxPalette::SetHPALETTE(WXHPALETTE pal) { - if ( !m_refData ) - m_refData = new wxPaletteRefData; + if ( !m_refData ) + m_refData = new wxPaletteRefData; M_PALETTEDATA->m_hPalette = pal; } +#endif // wxUSE_PALETTE + diff --git a/src/msw/pen.cpp b/src/msw/pen.cpp index 3149b72ecf..e15f066eda 100644 --- a/src/msw/pen.cpp +++ b/src/msw/pen.cpp @@ -240,8 +240,7 @@ bool wxPen::RealizeResource() if (M_PENDATA->m_style==wxUSER_DASH && M_PENDATA->m_nbDash && M_PENDATA->m_dash) { real_dash = new wxMSWDash[M_PENDATA->m_nbDash]; - int i, dsh; - for (i=0; im_nbDash; i++) + for ( int i = 0; i < M_PENDATA->m_nbDash; i++ ) real_dash[i] = M_PENDATA->m_dash[i] * M_PENDATA->m_width; } else -- 2.45.2