From: Vadim Zeitlin Date: Wed, 24 Nov 1999 12:30:56 +0000 (+0000) Subject: 1. wxIcon/wxCursor change, wxGDIImage class added X-Git-Url: https://git.saurik.com/wxWidgets.git/commitdiff_plain/6d167489bdf17d55d9bd11be834bc17277661063?ds=inline 1. wxIcon/wxCursor change, wxGDIImage class added 2. wxCriticalSection doesn't alloc memory any more 3. many minor fixes in bitmap/icon code git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@4673 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- diff --git a/include/wx/gdicmn.h b/include/wx/gdicmn.h index dd913a0c95..b89c81760a 100644 --- a/include/wx/gdicmn.h +++ b/include/wx/gdicmn.h @@ -50,7 +50,8 @@ class WXDLLEXPORT wxString; // Bitmap flags enum { - wxBITMAP_TYPE_BMP = 1, + wxBITMAP_TYPE_INVALID, // should be == 0 for compatibility! + wxBITMAP_TYPE_BMP, wxBITMAP_TYPE_BMP_RESOURCE, wxBITMAP_TYPE_RESOURCE = wxBITMAP_TYPE_BMP_RESOURCE, wxBITMAP_TYPE_ICO, @@ -73,12 +74,12 @@ enum wxBITMAP_TYPE_PNM_RESOURCE, wxBITMAP_TYPE_PCX, wxBITMAP_TYPE_PCX_RESOURCE, - wxBITMAP_TYPE_PICT, - wxBITMAP_TYPE_PICT_RESOURCE, - wxBITMAP_TYPE_ICON, - wxBITMAP_TYPE_ICON_RESOURCE, - wxBITMAP_TYPE_MACCURSOR , - wxBITMAP_TYPE_MACCURSOR_RESOURCE, + wxBITMAP_TYPE_PICT, + wxBITMAP_TYPE_PICT_RESOURCE, + wxBITMAP_TYPE_ICON, + wxBITMAP_TYPE_ICON_RESOURCE, + wxBITMAP_TYPE_MACCURSOR, + wxBITMAP_TYPE_MACCURSOR_RESOURCE, wxBITMAP_TYPE_ANY = 50 }; diff --git a/include/wx/menuitem.h b/include/wx/menuitem.h index 74bbc43f3d..63b3137ec0 100644 --- a/include/wx/menuitem.h +++ b/include/wx/menuitem.h @@ -45,12 +45,7 @@ class WXDLLEXPORT wxMenu; class WXDLLEXPORT wxMenuItemBase : public wxObject { public: - // some compilers need a default constructor here, do not use - wxMenuItemBase() {} - -/* This makes no sense (lots of asserts on MSW) so commenting out -- JACS - { wxFAIL_MSG( wxT("illegal call") ); } -*/ + wxMenuItemBase() { } // creation static wxMenuItem *New(wxMenu *parentMenu = (wxMenu *)NULL, diff --git a/include/wx/msw/app.h b/include/wx/msw/app.h index 54d4d65222..770123e24d 100644 --- a/include/wx/msw/app.h +++ b/include/wx/msw/app.h @@ -83,7 +83,16 @@ public: virtual bool ProcessMessage(WXMSG* pMsg); void DeletePendingObjects(); bool ProcessIdle(); - int GetComCtl32Version() const; + +#if wxUSE_RICHEDIT + // initialize the richedit DLL of (at least) given version, return TRUE if + // ok (Win95 has version 1, Win98/NT4 has 1 and 2, W2K has 3) + static bool InitRichEdit(int version = 2); +#endif // wxUSE_RICHEDIT + + // returns 400, 470, 471 for comctl32.dll 4.00, 4.70, 4.71 or 0 if it + // wasn't found at all + static int GetComCtl32Version(); public: int m_nCmdShow; diff --git a/include/wx/msw/bitmap.h b/include/wx/msw/bitmap.h index fdde21bb3e..a7d5676755 100644 --- a/include/wx/msw/bitmap.h +++ b/include/wx/msw/bitmap.h @@ -1,5 +1,5 @@ ///////////////////////////////////////////////////////////////////////////// -// Name: bitmap.h +// Name: wx/msw/bitmap.h // Purpose: wxBitmap class // Author: Julian Smart // Modified by: @@ -16,109 +16,57 @@ #pragma interface "bitmap.h" #endif -#include "wx/gdiobj.h" +#include "wx/msw/gdiimage.h" #include "wx/gdicmn.h" #include "wx/palette.h" -// Bitmap class WXDLLEXPORT wxDC; class WXDLLEXPORT wxControl; class WXDLLEXPORT wxBitmap; class WXDLLEXPORT wxBitmapHandler; class WXDLLEXPORT wxIcon; +class WXDLLEXPORT wxMask; class WXDLLEXPORT wxCursor; class WXDLLEXPORT wxControl; -// A mask is a mono bitmap used for drawing bitmaps -// transparently. -class WXDLLEXPORT wxMask: public wxObject -{ - DECLARE_DYNAMIC_CLASS(wxMask) - -public: - wxMask(); - - // Construct a mask from a bitmap and a colour indicating - // the transparent area - wxMask(const wxBitmap& bitmap, const wxColour& colour); - - // Construct a mask from a bitmap and a palette index indicating - // the transparent area - wxMask(const wxBitmap& bitmap, int paletteIndex); - - // Construct a mask from a mono bitmap (copies the bitmap). - wxMask(const wxBitmap& bitmap); - - ~wxMask(); - - bool Create(const wxBitmap& bitmap, const wxColour& colour); - bool Create(const wxBitmap& bitmap, int paletteIndex); - bool Create(const wxBitmap& bitmap); - - // Implementation - WXHBITMAP GetMaskBitmap() const { return m_maskBitmap; } - void SetMaskBitmap(WXHBITMAP bmp) { m_maskBitmap = bmp; } +// ---------------------------------------------------------------------------- +// Bitmap data +// +// NB: this class is private, but declared here to make it possible inline +// wxBitmap functions accessing it +// ---------------------------------------------------------------------------- -protected: - WXHBITMAP m_maskBitmap; -}; - -class WXDLLEXPORT wxBitmapRefData: public wxGDIRefData +class WXDLLEXPORT wxBitmapRefData : public wxGDIImageRefData { - friend class WXDLLEXPORT wxBitmap; - friend class WXDLLEXPORT wxIcon; - friend class WXDLLEXPORT wxCursor; public: wxBitmapRefData(); - ~wxBitmapRefData(); + virtual ~wxBitmapRefData() { Free(); } + + virtual void Free(); public: - int m_width; - int m_height; - int m_depth; - bool m_ok; - int m_numColors; - wxPalette m_bitmapPalette; - int m_quality; - -#ifdef __WXMSW__ - WXHBITMAP m_hBitmap; - wxDC * m_selectedInto; // So bitmap knows whether it's been selected into - // a device context (for error checking) - wxMask * m_bitmapMask; // Option mask -#endif -}; + int m_numColors; + wxPalette m_bitmapPalette; + int m_quality; -#define M_BITMAPDATA ((wxBitmapRefData *)m_refData) + // MSW-specific + // ------------ -class WXDLLEXPORT wxBitmapHandler: public wxObject -{ - DECLARE_DYNAMIC_CLASS(wxBitmapHandler) -public: - wxBitmapHandler() { m_name = ""; m_extension = ""; m_type = 0; }; - - virtual bool Create(wxBitmap *bitmap, void *data, long flags, int width, int height, int depth = 1); - virtual bool LoadFile(wxBitmap *bitmap, const wxString& name, long flags, - int desiredWidth, int desiredHeight); - virtual bool SaveFile(wxBitmap *bitmap, const wxString& name, int type, const wxPalette *palette = NULL); - - void SetName(const wxString& name) { m_name = name; } - void SetExtension(const wxString& ext) { m_extension = ext; } - void SetType(long type) { m_type = type; } - wxString GetName() const { return m_name; } - wxString GetExtension() const { return m_extension; } - long GetType() const { return m_type; } -protected: - wxString m_name; - wxString m_extension; - long m_type; + // this field is solely for error checking: we detect selecting a bitmap + // into more than one DC at once or deleting a bitmap still selected into a + // DC (both are serious programming errors under Windows) + wxDC *m_selectedInto; + + // optional mask for transparent drawing + wxMask *m_bitmapMask; }; -#define M_BITMAPHANDLERDATA ((wxBitmapRefData *)bitmap->GetRefData()) -class WXDLLEXPORT wxBitmap: public wxGDIObject -{ -friend class WXDLLEXPORT wxBitmapHandler; +// ---------------------------------------------------------------------------- +// wxBitmap: a mono or colour bitmap +// ---------------------------------------------------------------------------- +class WXDLLEXPORT wxBitmap : public wxGDIImage +{ public: // default ctor creates an invalid bitmap, you must Create() it later wxBitmap() { Init(); } @@ -159,82 +107,169 @@ public: return *this; } + wxBitmap& operator=(const wxCursor& cursor) + { + (void)CopyFromCursor(cursor); + + return *this; + } + virtual ~wxBitmap(); // copies the contents and mask of the given (colour) icon to the bitmap bool CopyFromIcon(const wxIcon& icon); + // copies the contents and mask of the given cursor to the bitmap + bool CopyFromCursor(const wxCursor& cursor); + virtual bool Create(int width, int height, int depth = -1); virtual bool Create(void *data, long type, int width, int height, int depth = 1); virtual bool LoadFile(const wxString& name, long type = wxBITMAP_TYPE_BMP_RESOURCE); virtual bool SaveFile(const wxString& name, int type, const wxPalette *cmap = NULL); - bool Ok() const { return (M_BITMAPDATA && M_BITMAPDATA->m_ok); } - int GetWidth() const { return (M_BITMAPDATA ? M_BITMAPDATA->m_width : 0); } - int GetHeight() const { return (M_BITMAPDATA ? M_BITMAPDATA->m_height : 0); } - int GetDepth() const { return (M_BITMAPDATA ? M_BITMAPDATA->m_depth : 0); } - int GetQuality() const { return (M_BITMAPDATA ? M_BITMAPDATA->m_quality : 0); } - void SetWidth(int w); - void SetHeight(int h); - void SetDepth(int d); + wxBitmapRefData *GetBitmapData() const { return (wxBitmapRefData *)m_refData; } + + int GetQuality() const { return (GetBitmapData() ? GetBitmapData()->m_quality : 0); } void SetQuality(int q); - void SetOk(bool isOk); -#if WXWIN_COMPATIBILITY - wxPalette *GetColourMap() const { return GetPalette(); } - void SetColourMap(wxPalette *cmap) { SetPalette(*cmap); }; -#endif - wxPalette* GetPalette() const { return (M_BITMAPDATA ? (& M_BITMAPDATA->m_bitmapPalette) : (wxPalette*) NULL); } + + wxPalette* GetPalette() const { return (GetBitmapData() ? (& GetBitmapData()->m_bitmapPalette) : (wxPalette*) NULL); } void SetPalette(const wxPalette& palette); - wxMask *GetMask() const { return (M_BITMAPDATA ? M_BITMAPDATA->m_bitmapMask : (wxMask*) NULL); } + wxMask *GetMask() const { return (GetBitmapData() ? GetBitmapData()->m_bitmapMask : (wxMask*) NULL); } void SetMask(wxMask *mask) ; bool operator==(const wxBitmap& bitmap) { return m_refData == bitmap.m_refData; } bool operator!=(const wxBitmap& bitmap) { return m_refData != bitmap.m_refData; } - // Format handling - static wxList& GetHandlers() { return sm_handlers; } - static void AddHandler(wxBitmapHandler *handler); - static void InsertHandler(wxBitmapHandler *handler); - static bool RemoveHandler(const wxString& name); - static wxBitmapHandler *FindHandler(const wxString& name); - static wxBitmapHandler *FindHandler(const wxString& extension, long bitmapType); - static wxBitmapHandler *FindHandler(long bitmapType); - - static void InitStandardHandlers(); - static void CleanUpHandlers(); +#if WXWIN_COMPATIBILITY_2 + void SetOk(bool isOk); +#endif // WXWIN_COMPATIBILITY_2 -protected: - static wxList sm_handlers; +#if WXWIN_COMPATIBILITY + wxPalette *GetColourMap() const { return GetPalette(); } + void SetColourMap(wxPalette *cmap) { SetPalette(*cmap); }; +#endif // WXWIN_COMPATIBILITY // Implementation public: - void SetHBITMAP(WXHBITMAP bmp); - WXHBITMAP GetHBITMAP() const { return (M_BITMAPDATA ? M_BITMAPDATA->m_hBitmap : 0); } - void SetSelectedInto(wxDC *dc) { if (M_BITMAPDATA) M_BITMAPDATA->m_selectedInto = dc; } - wxDC *GetSelectedInto() const { return (M_BITMAPDATA ? M_BITMAPDATA->m_selectedInto : (wxDC*) NULL); } - bool FreeResource(bool force = FALSE); - - // Creates a bitmap that matches the device context's depth, from - // an arbitray bitmap. At present, the original bitmap must have an - // associated palette. (TODO: use a default palette if no palette exists.) - // This function is necessary for you to Blit an arbitrary bitmap (which may have - // the wrong depth). wxDC::SelectObject will compare the depth of the bitmap - // with the DC's depth, and create a new bitmap if the depths differ. - // Eventually we should perhaps make this a public API function so that - // an app can efficiently produce bitmaps of the correct depth. - // The Windows solution is to use SetDibBits to blit an arbotrary DIB directly to a DC, but - // this is too Windows-specific, hence this solution of quietly converting the wxBitmap. - // Contributed by Frederic Villeneuve + void SetHBITMAP(WXHBITMAP bmp) { SetHandle((WXHANDLE)bmp); } + WXHBITMAP GetHBITMAP() const { return (WXHBITMAP)GetHandle(); } + + void SetSelectedInto(wxDC *dc) { if (GetBitmapData()) GetBitmapData()->m_selectedInto = dc; } + wxDC *GetSelectedInto() const { return (GetBitmapData() ? GetBitmapData()->m_selectedInto : (wxDC*) NULL); } + + // Creates a bitmap that matches the device context's depth, from an + // arbitray bitmap. At present, the original bitmap must have an associated + // palette. (TODO: use a default palette if no palette exists.) This + // function is necessary for you to Blit an arbitrary bitmap (which may + // have the wrong depth). wxDC::SelectObject will compare the depth of the + // bitmap with the DC's depth, and create a new bitmap if the depths + // differ. Eventually we should perhaps make this a public API function so + // that an app can efficiently produce bitmaps of the correct depth. The + // Windows solution is to use SetDibBits to blit an arbotrary DIB directly + // to a DC, but this is too Windows-specific, hence this solution of + // quietly converting the wxBitmap. Contributed by Frederic Villeneuve + // wxBitmap GetBitmapForDC(wxDC& dc) const; protected: // common part of all ctors void Init(); + virtual wxGDIImageRefData *CreateData() const + { return new wxBitmapRefData; } + private: +#ifdef __WIN32__ + // common part of CopyFromIcon/CopyFromCursor for Win32 + bool CopyFromIconOrCursor(const wxGDIImage& icon); +#endif // __WIN32__ + DECLARE_DYNAMIC_CLASS(wxBitmap) }; +// ---------------------------------------------------------------------------- +// wxMask: a mono bitmap used for drawing bitmaps transparently. +// ---------------------------------------------------------------------------- + +class WXDLLEXPORT wxMask : public wxObject +{ +public: + wxMask(); + + // Construct a mask from a bitmap and a colour indicating the transparent + // area + wxMask(const wxBitmap& bitmap, const wxColour& colour); + + // Construct a mask from a bitmap and a palette index indicating the + // transparent area + wxMask(const wxBitmap& bitmap, int paletteIndex); + + // Construct a mask from a mono bitmap (copies the bitmap). + wxMask(const wxBitmap& bitmap); + + // construct a mask from the givne bitmap handle + wxMask(WXHBITMAP hbmp) { m_maskBitmap = hbmp; } + + virtual ~wxMask(); + + bool Create(const wxBitmap& bitmap, const wxColour& colour); + bool Create(const wxBitmap& bitmap, int paletteIndex); + bool Create(const wxBitmap& bitmap); + + // Implementation + WXHBITMAP GetMaskBitmap() const { return m_maskBitmap; } + void SetMaskBitmap(WXHBITMAP bmp) { m_maskBitmap = bmp; } + +protected: + WXHBITMAP m_maskBitmap; + + DECLARE_DYNAMIC_CLASS(wxMask) +}; + +// ---------------------------------------------------------------------------- +// wxBitmapHandler is a class which knows how to load/save bitmaps to/from file +// ---------------------------------------------------------------------------- + +class WXDLLEXPORT wxBitmapHandler : public wxGDIImageHandler +{ +public: + wxBitmapHandler() { m_type = wxBITMAP_TYPE_INVALID; } + wxBitmapHandler(const wxString& name, const wxString& ext, long type) + : wxGDIImageHandler(name, ext, type) + { + } + + // keep wxBitmapHandler derived from wxGDIImageHandler compatible with the + // old class which worked only with bitmaps + virtual bool Create(wxBitmap *bitmap, + void *data, + long flags, + int width, int height, int depth = 1); + virtual bool LoadFile(wxBitmap *bitmap, + const wxString& name, + long flags, + int desiredWidth, int desiredHeight); + virtual bool SaveFile(wxBitmap *bitmap, + const wxString& name, + int type, + const wxPalette *palette = NULL); + + virtual bool Create(wxGDIImage *image, + void *data, + long flags, + int width, int height, int depth = 1); + virtual bool Load(wxGDIImage *image, + const wxString& name, + long flags, + int desiredWidth, int desiredHeight); + virtual bool Save(wxGDIImage *image, + const wxString& name, + int type); + +private: + DECLARE_DYNAMIC_CLASS(wxBitmapHandler) +}; + #endif // _WX_BITMAP_H_ diff --git a/include/wx/msw/cursor.h b/include/wx/msw/cursor.h index d5fab5b83b..4e28fcc178 100644 --- a/include/wx/msw/cursor.h +++ b/include/wx/msw/cursor.h @@ -1,67 +1,82 @@ ///////////////////////////////////////////////////////////////////////////// -// Name: cursor.h +// Name: wx/msw/cursor.h // Purpose: wxCursor class // Author: Julian Smart // Modified by: // Created: 01/02/97 // RCS-ID: $Id$ // Copyright: (c) Julian Smart -// Licence: wxWindows licence +// Licence: wxWindows licence ///////////////////////////////////////////////////////////////////////////// #ifndef _WX_CURSOR_H_ #define _WX_CURSOR_H_ #ifdef __GNUG__ -#pragma interface "cursor.h" + #pragma interface "cursor.h" #endif -#include "wx/bitmap.h" +// compatible (even if incorrect) behaviour by default: derive wxCursor from +// wxBitmap +#ifndef wxICON_IS_BITMAP + #define wxICON_IS_BITMAP 1 +#endif + +#if wxICON_IS_BITMAP + #include "wx/bitmap.h" + + #define wxCursorRefDataBase wxBitmapRefData + #define wxCursorBase wxBitmap +#else + #include "wx/msw/gdiimage.h" -class WXDLLEXPORT wxCursorRefData: public wxBitmapRefData + #define wxCursorRefDataBase wxGDIImageRefData + #define wxCursorBase wxGDIImage +#endif + +class WXDLLEXPORT wxCursorRefData : public wxCursorRefDataBase { - friend class WXDLLEXPORT wxBitmap; - friend class WXDLLEXPORT wxCursor; public: - wxCursorRefData(void); - ~wxCursorRefData(void); + wxCursorRefData(); + virtual ~wxCursorRefData() { Free(); } -protected: - WXHCURSOR m_hCursor; - bool m_destroyCursor; -}; + virtual void Free(); -#define M_CURSORDATA ((wxCursorRefData *)m_refData) -#define M_CURSORHANDLERDATA ((wxCursorRefData *)bitmap->m_refData) + // for compatibility +public: + bool m_destroyCursor; +}; // Cursor -class WXDLLEXPORT wxCursor: public wxBitmap +class WXDLLEXPORT wxCursor : public wxCursorBase { - DECLARE_DYNAMIC_CLASS(wxCursor) - public: - wxCursor(void); + wxCursor(); - // Copy constructors - inline wxCursor(const wxCursor& cursor) { Ref(cursor); } + // Copy constructors + wxCursor(const wxCursor& cursor) { Ref(cursor); } - wxCursor(const char bits[], int width, int height, int hotSpotX = -1, int hotSpotY = -1, - const char maskBits[] = NULL); - wxCursor(const wxString& name, long flags = wxBITMAP_TYPE_CUR_RESOURCE, - int hotSpotX = 0, int hotSpotY = 0); - wxCursor(int cursor_type); - ~wxCursor(void); + wxCursor(const char bits[], int width, int height, + int hotSpotX = -1, int hotSpotY = -1, + const char maskBits[] = NULL); + wxCursor(const wxString& name, + long flags = wxBITMAP_TYPE_CUR_RESOURCE, + int hotSpotX = 0, int hotSpotY = 0); + wxCursor(int cursor_type); + virtual ~wxCursor(); - virtual bool Ok(void) const { return (m_refData != NULL && M_CURSORDATA->m_hCursor) ; } + wxCursor& operator = (const wxCursor& cursor) { if (*this == cursor) return (*this); Ref(cursor); return *this; } + bool operator == (const wxCursor& cursor) const { return m_refData == cursor.m_refData; } + bool operator != (const wxCursor& cursor) const { return m_refData != cursor.m_refData; } - wxCursor& operator = (const wxCursor& cursor) { if (*this == cursor) return (*this); Ref(cursor); return *this; } - bool operator == (const wxCursor& cursor) const { return m_refData == cursor.m_refData; } - bool operator != (const wxCursor& cursor) const { return m_refData != cursor.m_refData; } + void SetHCURSOR(WXHCURSOR cursor) { SetHandle((WXHANDLE)cursor); } + WXHCURSOR GetHCURSOR() const { return (WXHCURSOR)GetHandle(); } - void SetHCURSOR(WXHCURSOR cursor); - inline WXHCURSOR GetHCURSOR(void) const { return (M_CURSORDATA ? M_CURSORDATA->m_hCursor : 0); } +protected: + virtual wxGDIImageRefData *CreateData() const { return new wxCursorRefData; } - bool FreeResource(bool force = FALSE); +private: + DECLARE_DYNAMIC_CLASS(wxCursor) }; #endif diff --git a/include/wx/msw/dib.h b/include/wx/msw/dib.h index 2944272aaf..b84eb86046 100644 --- a/include/wx/msw/dib.h +++ b/include/wx/msw/dib.h @@ -1,22 +1,41 @@ ///////////////////////////////////////////////////////////////////////////// -// Name: dib.h +// Name: wx/msw/dib.h // Purpose: Routines for loading and saving DIBs // Author: Various // Modified by: // Created: 01/02/97 // RCS-ID: $Id$ // Copyright: (c) Julian Smart -// Licence: wxWindows licence +// Licence: wxWindows licence ///////////////////////////////////////////////////////////////////////////// #ifndef _WX_DIB_H_ #define _WX_DIB_H_ class WXDLLEXPORT wxBitmap; -class WXDLLEXPORT wxColourMap; +class WXDLLEXPORT wxPalette; + +// ---------------------------------------------------------------------------- +// Functions for working with DIBs +// ---------------------------------------------------------------------------- + +// VZ: we have 3 different sets of functions: from bitmap.cpp (wxCreateDIB and +// wxFreeDIB), from dib.cpp and from dataobj.cpp - surely there is some +// redundancy between them? (FIXME) + +// defined in bitmap.cpp +extern bool wxCreateDIB(long xSize, long ySize, long bitsPerPixel, + HPALETTE hPal, LPBITMAPINFO* lpDIBHeader); +extern void wxFreeDIB(LPBITMAPINFO lpDIBHeader); + +// defined in ole/dataobj.cpp +extern size_t wxConvertBitmapToDIB(LPBITMAPINFO pbi, const wxBitmap& bitmap); +extern wxBitmap wxConvertDIBToBitmap(const LPBITMAPINFO pbi); + +// the rest is defined in dib.cpp // Save (device dependent) wxBitmap as a DIB -bool wxSaveBitmap(wxChar *filename, wxBitmap *bitmap, wxColourMap *colourmap = NULL); +bool wxSaveBitmap(wxChar *filename, wxBitmap *bitmap, wxPalette *colourmap = NULL); // Load device independent bitmap into device dependent bitmap wxBitmap *wxLoadBitmap(wxChar *filename, wxColourMap **colourmap = NULL); @@ -30,5 +49,5 @@ HANDLE wxReadDIB2(LPTSTR lpFileName); LPSTR wxFindDIBBits (LPSTR lpbi); HPALETTE wxMakeDIBPalette(LPBITMAPINFOHEADER lpInfo); -#endif +#endif // _WX_DIB_H_ diff --git a/include/wx/msw/gdiobj.h b/include/wx/msw/gdiobj.h index 8f79cd0133..e7285541d1 100644 --- a/include/wx/msw/gdiobj.h +++ b/include/wx/msw/gdiobj.h @@ -1,66 +1,64 @@ ///////////////////////////////////////////////////////////////////////////// -// Name: gdiobj.h +// Name: wx/msw/gdiobj.h // Purpose: wxGDIObject class: base class for other GDI classes // Author: Julian Smart // Modified by: // Created: 01/02/97 // RCS-ID: $Id$ // Copyright: (c) Julian Smart -// Licence: wxWindows licence +// Licence: wxWindows licence ///////////////////////////////////////////////////////////////////////////// #ifndef _WX_GDIOBJ_H_ #define _WX_GDIOBJ_H_ -#include "wx/object.h" - #ifdef __GNUG__ -#pragma interface "gdiobj.h" + #pragma interface "gdiobj.h" #endif -// wxGDIRefData is the reference-counted data part of a GDI object. -// It contains another counter, m_usageCount, which counts the number -// of times this object has been used; e.g. in SetFont, the count -// is incremented. This is different from reference counting, -// where only the constructors, destructors and (un)clone operations -// affect the reference count. -// THIS IS NOW BEING REMOVED AS REDUNDANT AND ERROR-PRONE +#include "wx/object.h" // base class -class WXDLLEXPORT wxGDIRefData: public wxObjectRefData { -public: - inline wxGDIRefData(void) - { - } +// ---------------------------------------------------------------------------- +// wxGDIRefData is the base class for wxXXXData structures which contain the +// real data for the GDI object and are shared among all wxWin objects sharing +// the same native GDI object +// ---------------------------------------------------------------------------- + +class WXDLLEXPORT wxGDIRefData : public wxObjectRefData +{ + // this class is intentionally left blank }; -#define M_GDIDATA ((wxGDIRefData *)m_refData) +// ---------------------------------------------------------------------------- +// wxGDIObject +// ---------------------------------------------------------------------------- -class WXDLLEXPORT wxGDIObject: public wxObject +class WXDLLEXPORT wxGDIObject : public wxObject { -DECLARE_DYNAMIC_CLASS(wxGDIObject) - public: - inline wxGDIObject(void) { m_visible = FALSE; }; - inline ~wxGDIObject(void) {}; +public: + wxGDIObject() { m_visible = FALSE; }; - // Creates the resource - virtual bool RealizeResource(void) { return FALSE; }; + // Creates the resource + virtual bool RealizeResource() { return FALSE; }; - // Frees the resource - virtual bool FreeResource(bool WXUNUSED(force) = FALSE) { return FALSE; }; + // Frees the resource + virtual bool FreeResource(bool WXUNUSED(force) = FALSE) { return FALSE; } - virtual bool IsFree(void) const { return FALSE; }; + virtual bool IsFree() const { return FALSE; } - inline bool IsNull(void) const { return (m_refData == 0); } + bool IsNull() const { return (m_refData == 0); } - // Returns handle. - virtual WXHANDLE GetResourceHandle(void) { return 0; } + // Returns handle. + virtual WXHANDLE GetResourceHandle() { return 0; } - virtual bool GetVisible(void) { return m_visible; } - virtual void SetVisible(bool v) { m_visible = v; } + virtual bool GetVisible() { return m_visible; } + virtual void SetVisible(bool v) { m_visible = v; } protected: - bool m_visible; // Can a pointer to this object be safely taken? - // - only if created within FindOrCreate... + bool m_visible; // TRUE only if we should delete this object ourselves + +private: + DECLARE_DYNAMIC_CLASS(wxGDIObject) }; #endif diff --git a/include/wx/msw/icon.h b/include/wx/msw/icon.h index e331678228..6104c696ec 100644 --- a/include/wx/msw/icon.h +++ b/include/wx/msw/icon.h @@ -1,5 +1,5 @@ ///////////////////////////////////////////////////////////////////////////// -// Name: icon.h +// Name: wx/msw/icon.h // Purpose: wxIcon class // Author: Julian Smart // Modified by: @@ -16,34 +16,49 @@ #pragma interface "icon.h" #endif -#include "wx/bitmap.h" +// ---------------------------------------------------------------------------- +// headers +// ---------------------------------------------------------------------------- + +// compatible (even if incorrect) behaviour by default: derive wxIcon from +// wxBitmap +#ifndef wxICON_IS_BITMAP + #define wxICON_IS_BITMAP 1 +#endif + +#if wxICON_IS_BITMAP + #include "wx/bitmap.h" + + #define wxIconRefDataBase wxBitmapRefData + #define wxIconBase wxBitmap +#else + #include "wx/msw/gdiimage.h" + + #define wxIconRefDataBase wxGDIImageRefData + #define wxIconBase wxGDIImage +#endif // --------------------------------------------------------------------------- // icon data // --------------------------------------------------------------------------- -class WXDLLEXPORT wxIconRefData: public wxBitmapRefData -{ - friend class WXDLLEXPORT wxBitmap; - friend class WXDLLEXPORT wxIcon; +// notice that although wxIconRefData inherits from wxBitmapRefData, it is not +// a valid wxBitmapRefData +class WXDLLEXPORT wxIconRefData : public wxIconRefDataBase +{ public: - wxIconRefData(); - ~wxIconRefData(); + wxIconRefData() { } + virtual ~wxIconRefData() { Free(); } -public: - WXHICON m_hIcon; + virtual void Free(); }; -#define M_ICONDATA ((wxIconRefData *)m_refData) -#define M_ICONHANDLERDATA ((wxIconRefData *)bitmap->GetRefData()) - // --------------------------------------------------------------------------- // Icon // --------------------------------------------------------------------------- -class WXDLLEXPORT wxIcon : public wxBitmap -{ - DECLARE_DYNAMIC_CLASS(wxIcon) +class WXDLLEXPORT wxIcon : public wxIconBase +{ public: wxIcon(); @@ -51,61 +66,35 @@ public: wxIcon(const wxIcon& icon) { Ref(icon); } wxIcon(const char bits[], int width, int height); - wxIcon(const wxString& name, long flags = wxBITMAP_TYPE_ICO_RESOURCE, + wxIcon(const wxString& name, + long type = wxBITMAP_TYPE_ICO_RESOURCE, int desiredWidth = -1, int desiredHeight = -1); - ~wxIcon(); + virtual ~wxIcon(); - bool LoadFile(const wxString& name, long flags = wxBITMAP_TYPE_ICO_RESOURCE, - int desiredWidth = -1, int desiredHeight = -1); + virtual bool LoadFile(const wxString& name, + long type = wxBITMAP_TYPE_ICO_RESOURCE, + int desiredWidth = -1, int desiredHeight = -1); wxIcon& operator = (const wxIcon& icon) - { if (*this == icon) return (*this); Ref(icon); return *this; } + { if ( *this != icon ) Ref(icon); return *this; } bool operator == (const wxIcon& icon) const { return m_refData == icon.m_refData; } bool operator != (const wxIcon& icon) const { return m_refData != icon.m_refData; } - void SetHICON(WXHICON ico); - WXHICON GetHICON() const { return (M_ICONDATA ? M_ICONDATA->m_hIcon : 0); } + wxIconRefData *GetIconData() const { return (wxIconRefData *)m_refData; } - bool Ok() const { return (m_refData != NULL && M_ICONDATA->m_hIcon != 0) ; } - - bool FreeResource(bool force = FALSE); -}; + void SetHICON(WXHICON icon) { SetHandle((WXHANDLE)icon); } + WXHICON GetHICON() const { return (WXHICON)GetHandle(); } -// TODO: Put these in separate, private header - -class WXDLLEXPORT wxICOFileHandler: public wxBitmapHandler -{ -DECLARE_DYNAMIC_CLASS(wxICOFileHandler) - -public: - wxICOFileHandler() +protected: + virtual wxGDIImageRefData *CreateData() const { - m_name = "ICO icon file"; - m_extension = "ico"; - m_type = wxBITMAP_TYPE_ICO; - }; - - virtual bool LoadFile(wxBitmap *bitmap, const wxString& name, long flags, - int desiredWidth = -1, int desiredHeight = -1); -}; - -class WXDLLEXPORT wxICOResourceHandler: public wxBitmapHandler -{ -DECLARE_DYNAMIC_CLASS(wxICOResourceHandler) - -public: - wxICOResourceHandler() - { - m_name = "ICO resource"; - m_extension = "ico"; - m_type = wxBITMAP_TYPE_ICO_RESOURCE; - }; - - virtual bool LoadFile(wxBitmap *bitmap, const wxString& name, long flags, - int desiredWidth = -1, int desiredHeight = -1); + return new wxIconRefData; + } +private: + DECLARE_DYNAMIC_CLASS(wxIcon) }; #endif diff --git a/include/wx/msw/private.h b/include/wx/msw/private.h index 1017104e5a..981189b3ff 100644 --- a/include/wx/msw/private.h +++ b/include/wx/msw/private.h @@ -220,6 +220,23 @@ inline void wxRGBToColour(wxColour& c, COLORREF rgb) c.Set(GetRValue(rgb), GetGValue(rgb), GetBValue(rgb)); } +// --------------------------------------------------------------------------- +// small helper classes +// --------------------------------------------------------------------------- + +// create an instance of this class and use it as the HDC for screen, will +// automatically release the DC going out of scope +class ScreenHDC +{ +public: + ScreenHDC() { m_hdc = GetDC(NULL); } + ~ScreenHDC() { ReleaseDC(NULL, m_hdc); } + operator HDC() const { return m_hdc; } + +private: + HDC m_hdc; +}; + // --------------------------------------------------------------------------- // macros to make casting between WXFOO and FOO a bit easier: the GetFoo() // returns Foo cast to the Windows type for oruselves, while GetFooOf() takes diff --git a/include/wx/msw/setup0.h b/include/wx/msw/setup0.h index 734adc7459..1a73808f9e 100644 --- a/include/wx/msw/setup0.h +++ b/include/wx/msw/setup0.h @@ -19,6 +19,10 @@ // define this to 0 when building wxBase library #define wxUSE_GUI 1 +// ---------------------------------------------------------------------------- +// compatibility settings +// ---------------------------------------------------------------------------- + #define WXWIN_COMPATIBILITY 0 // Compatibility with 1.68 API. // Level 0: no backward compatibility, all new features @@ -26,6 +30,19 @@ // the compatibility code is now very minimal so there // is little advantage to setting it to 1. +// in wxMSW version 2.1.11 and earlier, wxIcon always derives from wxBitmap, +// but this is very dangerous because you can mistakenly pass an icon instead +// of a bitmap to a function taking "const wxBitmap&" - which will *not* work +// because an icon is not a valid bitmap +// +// Starting from 2.1.12, you have the choice under this backwards compatible +// behaviour (your code will still compile, but probably won't behave as +// expected!) and not deriving wxIcon class from wxBitmap, but providing a +// conversion ctor wxBitmap(const wxIcon&) instead. +// +// Recommended setting: 0 +#define wxICON_IS_BITMAP 0 + // ---------------------------------------------------------------------------- // General features // ---------------------------------------------------------------------------- @@ -300,6 +317,13 @@ // See note above about using FAFA and CTL3D. #endif +// can we use RICHEDIT control? +#if defined(__WIN95__) && !defined(__TWIN32__) && !defined(__GNUWIN32_OLD__) +#define wxUSE_RICHEDIT 1 +#else +#define wxUSE_RICHEDIT 0 +#endif + #define wxUSE_COMMON_DIALOGS 1 // On rare occasions (e.g. using DJGPP) may want // to omit common dialogs diff --git a/include/wx/msw/statbmp.h b/include/wx/msw/statbmp.h index 115abfb206..fe255032bb 100644 --- a/include/wx/msw/statbmp.h +++ b/include/wx/msw/statbmp.h @@ -31,7 +31,7 @@ public: wxStaticBitmap(wxWindow *parent, wxWindowID id, - const wxBitmap& label, + const wxGDIImage& label, const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxDefaultSize, long style = 0, @@ -42,7 +42,7 @@ public: bool Create(wxWindow *parent, wxWindowID id, - const wxBitmap& label, + const wxGDIImage& label, const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxDefaultSize, long style = 0, @@ -50,15 +50,15 @@ public: virtual ~wxStaticBitmap() { Free(); } - virtual void SetIcon(const wxIcon& icon) { SetBitmap(icon); } - virtual void SetBitmap(const wxBitmap& bitmap); + void SetIcon(const wxIcon& icon) { SetImage(icon); } + void SetBitmap(const wxBitmap& bitmap) { SetImage(bitmap); } // assert failure is provoked by an attempt to get an icon from bitmap or // vice versa const wxIcon& GetIcon() const - { wxASSERT( m_isIcon ); return *m_image.icon; } + { wxASSERT( m_isIcon ); return *(wxIcon *)m_image; } const wxBitmap& GetBitmap() const - { wxASSERT( !m_isIcon ); return *m_image.bitmap; } + { wxASSERT( !m_isIcon ); return *(wxBitmap *)m_image; } // overriden base class virtuals virtual bool AcceptsFocus() const { return FALSE; } @@ -70,21 +70,19 @@ public: #endif // __WIN16__ protected: - void Init() { m_isIcon = TRUE; m_image.icon = NULL; } + virtual wxSize DoGetBestSize() const; + + void Init() { m_isIcon = TRUE; m_image = NULL; } void Free(); // TRUE if icon/bitmap is valid bool ImageIsOk() const; + void SetImage(const wxGDIImage& image); + // we can have either an icon or a bitmap bool m_isIcon; - union - { - wxIcon *icon; - wxBitmap *bitmap; - } m_image; - - virtual wxSize DoGetBestSize() const; + wxGDIImage *m_image; }; #endif diff --git a/include/wx/tbarbase.h b/include/wx/tbarbase.h index 79e2349772..08ce5dbe1e 100644 --- a/include/wx/tbarbase.h +++ b/include/wx/tbarbase.h @@ -1,5 +1,5 @@ ///////////////////////////////////////////////////////////////////////////// -// Name: tbarbase.h +// Name: wx/tbarbase.h // Purpose: Base class for toolbar classes // Author: Julian Smart // Modified by: diff --git a/include/wx/thread.h b/include/wx/thread.h index af59d0db30..641ce6330b 100644 --- a/include/wx/thread.h +++ b/include/wx/thread.h @@ -21,7 +21,8 @@ #include "wx/setup.h" #if wxUSE_THREADS -/* otherwise we get undefined references for non-thread case (KB)*/ + +// only for wxUSE_THREADS - otherwise we'd get undefined symbols #ifdef __GNUG__ #pragma interface "thread.h" #endif @@ -37,28 +38,31 @@ // constants // ---------------------------------------------------------------------------- -typedef enum +enum wxMutexError { wxMUTEX_NO_ERROR = 0, wxMUTEX_DEAD_LOCK, // Mutex has been already locked by THE CALLING thread wxMUTEX_BUSY, // Mutex has been already locked by ONE thread wxMUTEX_UNLOCKED, wxMUTEX_MISC_ERROR -} wxMutexError; +}; -typedef enum +enum wxThreadError { wxTHREAD_NO_ERROR = 0, // No error wxTHREAD_NO_RESOURCE, // No resource left to create a new thread wxTHREAD_RUNNING, // The thread is already running wxTHREAD_NOT_RUNNING, // The thread isn't running wxTHREAD_MISC_ERROR // Some other error -} wxThreadError; +}; // defines the interval of priority -#define WXTHREAD_MIN_PRIORITY 0u -#define WXTHREAD_DEFAULT_PRIORITY 50u -#define WXTHREAD_MAX_PRIORITY 100u +enum +{ + WXTHREAD_MIN_PRIORITY = 0u, + WXTHREAD_DEFAULT_PRIORITY = 50u, + WXTHREAD_MAX_PRIORITY = 100u +}; // ---------------------------------------------------------------------------- // A mutex object is a synchronization object whose state is set to signaled @@ -129,21 +133,24 @@ private: // Critical section: this is the same as mutex but is only visible to the // threads of the same process. For the platforms which don't have native // support for critical sections, they're implemented entirely in terms of -// mutexes +// mutexes. +// +// NB: wxCriticalSection object does not allocate any memory in its ctor +// which makes it possible to have static globals of this class // ---------------------------------------------------------------------------- -// in order to avoid any overhead under !MSW make all wxCriticalSection class -// functions inline - but this can't be done under MSW -#if defined(__WXMSW__) - class WXDLLEXPORT wxCriticalSectionInternal; - #define WXCRITICAL_INLINE -#elif defined(__WXMAC__) - class WXDLLEXPORT wxCriticalSectionInternal; - #define WXCRITICAL_INLINE -#elif defined(__WXPM__) - #define WXCRITICAL_INLINE -#else // !MSW && !PM +class WXDLLEXPORT wxCriticalSectionInternal; + +// in order to avoid any overhead under platforms where critical sections are +// just mutexes make all wxCriticalSection class functions inline +#if !defined(__WXMSW__) && !defined(__WXPM__) && !defined(__WXMAC__) #define WXCRITICAL_INLINE inline + + #define wxCRITSECT_IS_MUTEX 1 +#else // MSW || Mac || OS2 + #define WXCRITICAL_INLINE + + #define wxCRITSECT_IS_MUTEX 0 #endif // MSW/!MSW // you should consider wxCriticalSectionLocker whenever possible instead of @@ -165,11 +172,18 @@ private: wxCriticalSection(const wxCriticalSection&); wxCriticalSection& operator=(const wxCriticalSection&); -#if defined(__WXMSW__) || defined(__WXMAC__) - wxCriticalSectionInternal *m_critsect; -#else // !MSW +#if wxCRITSECT_IS_MUTEX wxMutex m_mutex; -#endif // MSW/!MSW +#elif defined(__WXMSW__) + // we can't allocate any memory in the ctor, so use placement new - + // unfortunately, we have to hardcode the sizeof() here because we can't + // include windows.h from this public header + char m_buffer[24]; +#elif !defined(__WXPM__) + wxCriticalSectionInternal *m_critsect; +#else + // nothing for OS/2 +#endif // !Unix/Unix }; // keep your preprocessor name space clean diff --git a/include/wx/toolbar.h b/include/wx/toolbar.h index 47911912d2..600a4743af 100644 --- a/include/wx/toolbar.h +++ b/include/wx/toolbar.h @@ -1,5 +1,24 @@ -#ifndef _TOOLBAR_H_BASE_ -#define _TOOLBAR_H_BASE_ +///////////////////////////////////////////////////////////////////////////// +// Name: wx/toolbar.h +// Purpose: wxToolBar interface declaration +// Author: Vadim Zeitlin +// Modified by: +// Created: 20.11.99 +// RCS-ID: $Id$ +// Copyright: (c) wxWindows team +// Licence: wxWindows licence +///////////////////////////////////////////////////////////////////////////// + +#ifndef _WX_TOOLBAR_H_BASE_ +#define _WX_TOOLBAR_H_BASE_ + +#include "wx/tbarbase.h" // the base class for all toolbars + +#if 0 +class WXDLLEXPORT wxToolBar : public wxControl +{ +}; +#endif // 0 #if defined(__WXMSW__) && defined(__WIN95__) # include "wx/msw/tbar95.h" @@ -20,4 +39,4 @@ #endif #endif - // _TOOLBAR_H_BASE_ + // _WX_TOOLBAR_H_BASE_ diff --git a/src/common/gdicmn.cpp b/src/common/gdicmn.cpp index 93f757164f..4f33ad414b 100644 --- a/src/common/gdicmn.cpp +++ b/src/common/gdicmn.cpp @@ -499,7 +499,8 @@ wxPen *wxPenList::FindOrCreatePen (const wxColour& colour, int width, int style) for (wxNode * node = First (); node; node = node->Next ()) { wxPen *each_pen = (wxPen *) node->Data (); - if (each_pen && each_pen->GetVisible() && + if (each_pen && + each_pen->GetVisible() && each_pen->GetWidth () == width && each_pen->GetStyle () == style && each_pen->GetColour ().Red () == colour.Red () && @@ -514,6 +515,7 @@ wxPen *wxPenList::FindOrCreatePen (const wxColour& colour, int width, int style) // returning a pointer to an automatic variable and hanging on to it // (dangling pointer). pen->SetVisible(TRUE); + return pen; } @@ -542,19 +544,23 @@ wxBrush *wxBrushList::FindOrCreateBrush (const wxColour& colour, int style) for (wxNode * node = First (); node; node = node->Next ()) { wxBrush *each_brush = (wxBrush *) node->Data (); - if (each_brush && each_brush->GetVisible() && + if (each_brush && + each_brush->GetVisible() && each_brush->GetStyle () == style && each_brush->GetColour ().Red () == colour.Red () && each_brush->GetColour ().Green () == colour.Green () && each_brush->GetColour ().Blue () == colour.Blue ()) return each_brush; } + // Yes, we can return a pointer to this in a later FindOrCreateBrush call, // because we created it within FindOrCreateBrush. Safeguards against // returning a pointer to an automatic variable and hanging on to it // (dangling pointer). wxBrush *brush = new wxBrush (colour, style); + brush->SetVisible(TRUE); + return brush; } @@ -565,19 +571,19 @@ void wxBrushList::RemoveBrush (wxBrush * brush) wxFontList::~wxFontList () { - wxNode *node = First (); - while (node) + wxNode *node = First (); + while (node) { - // Only delete objects that are 'visible', i.e. - // that have been created using FindOrCreate..., - // where the pointers are expected to be shared - // (and therefore not deleted by any one part of an app). - wxFont *font = (wxFont *) node->Data (); - wxNode *next = node->Next (); - if (font->GetVisible()) - delete font; - node = next; -} + // Only delete objects that are 'visible', i.e. + // that have been created using FindOrCreate..., + // where the pointers are expected to be shared + // (and therefore not deleted by any one part of an app). + wxFont *font = (wxFont *) node->Data (); + wxNode *next = node->Next (); + if (font->GetVisible()) + delete font; + node = next; + } } void wxFontList::AddFont (wxFont * font) @@ -596,27 +602,27 @@ wxFont *wxFontList:: for (wxNode * node = First (); node; node = node->Next ()) { wxFont *each_font = (wxFont *) node->Data (); - if (each_font && each_font->GetVisible() && each_font->Ok() && + if (each_font && + each_font->GetVisible() && + each_font->Ok() && each_font->GetPointSize () == PointSize && each_font->GetStyle () == Style && each_font->GetWeight () == Weight && each_font->GetUnderlined () == underline && - //#if defined(__X__) - // each_font->GetFontId () == FamilyOrFontId) /* New font system */ - //#else #if defined(__WXGTK__) (each_font->GetFamily() == FamilyOrFontId || - (each_font->GetFamily() == wxSWISS && FamilyOrFontId == wxDEFAULT)) && + (each_font->GetFamily() == wxSWISS && FamilyOrFontId == wxDEFAULT)) && #else each_font->GetFamily() == FamilyOrFontId && #endif ((each_font->GetFaceName() == wxT("")) || each_font->GetFaceName() == Face) && (encoding == wxFONTENCODING_DEFAULT || each_font->GetEncoding() == encoding)) - //#endif return each_font; } wxFont *font = new wxFont (PointSize, FamilyOrFontId, Style, Weight, underline, Face, encoding); + font->SetVisible(TRUE); + return font; } diff --git a/src/common/image.cpp b/src/common/image.cpp index be1fcda4f5..163154260e 100644 --- a/src/common/image.cpp +++ b/src/common/image.cpp @@ -894,11 +894,10 @@ wxBitmap wxImage::ConvertToBitmap() const free(lpDIBh); free(lpBits); +#if WXWIN_COMPATIBILITY_2 // check the wxBitmap object - if( bitmap.GetHBITMAP() ) - bitmap.SetOk( TRUE ); - else - bitmap.SetOk( FALSE ); + bitmap.GetBitmapData()->SetOk(); +#endif // WXWIN_COMPATIBILITY_2 return bitmap; } diff --git a/src/msw/app.cpp b/src/msw/app.cpp index a184037d67..3528af8915 100644 --- a/src/msw/app.cpp +++ b/src/msw/app.cpp @@ -129,14 +129,10 @@ HBRUSH wxDisableButtonBrush = (HBRUSH) 0; LRESULT WXDLLEXPORT APIENTRY wxWndProc(HWND, UINT, WPARAM, LPARAM); -#if defined(__WIN95__) && !defined(__TWIN32__) - #define wxUSE_RICHEDIT 1 -#else - #define wxUSE_RICHEDIT 0 -#endif - #if wxUSE_RICHEDIT - static HINSTANCE gs_hRichEdit = (HINSTANCE) NULL; + // the handle to richedit DLL and the version of the DLL loaded + static HINSTANCE gs_hRichEdit = (HINSTANCE)NULL; + static int gs_verRichEdit = -1; #endif // =========================================================================== @@ -193,15 +189,6 @@ bool wxApp::Initialize() #if defined(__WIN95__) InitCommonControls(); -#if wxUSE_RICHEDIT - gs_hRichEdit = LoadLibrary(wxT("RICHED32.DLL")); - - if (gs_hRichEdit == (HINSTANCE) NULL) - { - wxLogError(_("Could not initialise Rich Edit DLL")); - } -#endif // wxUSE_RICHEDIT - #endif // __WIN95__ #if wxUSE_OLE @@ -517,15 +504,11 @@ void wxApp::CleanUp() wxSetKeyboardHook(FALSE); -#ifdef __WIN95__ - #if wxUSE_RICHEDIT if (gs_hRichEdit != (HINSTANCE) NULL) FreeLibrary(gs_hRichEdit); #endif -#endif - #if wxUSE_PENWINDOWS wxCleanUpPenWin(); #endif @@ -1098,47 +1081,105 @@ void wxApp::OnQueryEndSession(wxCloseEvent& event) } } -int wxApp::GetComCtl32Version() const +#if wxUSE_RICHEDIT + +/* static */ +bool wxApp::InitRichEdit(int version) { - // have we loaded COMCTL32 yet? - HMODULE theModule = ::GetModuleHandle(wxT("COMCTL32")); - int version = 0; + wxCHECK_MSG( version >= 1 && version <= 3, FALSE, + _T("incorrect richedit control version requested") ); - // if so, then we can check for the version - if (theModule) + if ( version <= gs_verRichEdit ) { - // InitCommonControlsEx is unique to 4.7 and later - FARPROC theProc = ::GetProcAddress(theModule, "InitCommonControlsEx"); + // we've already got this or better + return TRUE; + } - if (! theProc) - { // not found, must be 4.00 - version = 400; - } - else + if ( gs_hRichEdit ) + { + ::FreeLibrary(gs_hRichEdit); + } + + // always try load riched20.dll first - like this we won't have to reload + // it later if we're first asked for RE 1 and then for RE 2 or 3 + wxString dllname = _T("riched20.dll"); + gs_hRichEdit = ::LoadLibrary(dllname); + if ( !gs_hRichEdit && (version == 1) ) + { + // fall back to RE 1 + dllname = _T("riched32.dll"); + gs_hRichEdit = ::LoadLibrary(dllname); + } + + if ( !gs_hRichEdit ) + { + wxLogSysError(_("Could not load Rich Edit DLL '%s'"), dllname.c_str()); + + gs_verRichEdit = -1; + + return FALSE; + } + + gs_verRichEdit = version; + + return TRUE; +} + +#endif // wxUSE_RICHEDIT + +/* static */ +int wxApp::GetComCtl32Version() +{ + // TODO should use DllGetVersion() instead of this hack + + // cache the result + static int s_verComCtl32 = -1; // MT-FIXME + + if ( s_verComCtl32 == -1 ) + { + s_verComCtl32 = 0; + + // have we loaded COMCTL32 yet? + HMODULE theModule = ::GetModuleHandle(wxT("COMCTL32")); + + // if so, then we can check for the version + if (theModule) { - // The following symbol are unique to 4.71 - // DllInstall - // FlatSB_EnableScrollBar FlatSB_GetScrollInfo FlatSB_GetScrollPos - // FlatSB_GetScrollProp FlatSB_GetScrollRange FlatSB_SetScrollInfo - // FlatSB_SetScrollPos FlatSB_SetScrollProp FlatSB_SetScrollRange - // FlatSB_ShowScrollBar - // _DrawIndirectImageList _DuplicateImageList - // InitializeFlatSB - // UninitializeFlatSB - // we could check for any of these - I chose DllInstall - FARPROC theProc = ::GetProcAddress(theModule, "DllInstall"); - if (! theProc) - { - // not found, must be 4.70 - version = 470; + // InitCommonControlsEx is unique to 4.7 and later + FARPROC theProc = ::GetProcAddress(theModule, + _T("InitCommonControlsEx")); + + if ( !theProc ) + { // not found, must be 4.00 + s_verComCtl32 = 400; } else - { // found, must be 4.71 - version = 471; + { + // The following symbol are unique to 4.71 + // DllInstall + // FlatSB_EnableScrollBar FlatSB_GetScrollInfo FlatSB_GetScrollPos + // FlatSB_GetScrollProp FlatSB_GetScrollRange FlatSB_SetScrollInfo + // FlatSB_SetScrollPos FlatSB_SetScrollProp FlatSB_SetScrollRange + // FlatSB_ShowScrollBar + // _DrawIndirectImageList _DuplicateImageList + // InitializeFlatSB + // UninitializeFlatSB + // we could check for any of these - I chose DllInstall + FARPROC theProc = ::GetProcAddress(theModule, _T("DllInstall")); + if ( !theProc ) + { + // not found, must be 4.70 + s_verComCtl32 = 470; + } + else + { // found, must be 4.71 + s_verComCtl32 = 471; + } } } } - return version; + + return s_verComCtl32; } void wxExit() diff --git a/src/msw/bitmap.cpp b/src/msw/bitmap.cpp index 7579bcee53..fe11b93585 100644 --- a/src/msw/bitmap.cpp +++ b/src/msw/bitmap.cpp @@ -53,6 +53,8 @@ #if !USE_SHARED_LIBRARIES IMPLEMENT_DYNAMIC_CLASS(wxBitmap, wxGDIObject) IMPLEMENT_DYNAMIC_CLASS(wxMask, wxObject) + + IMPLEMENT_DYNAMIC_CLASS(wxBitmapHandler, wxObject) #endif // ============================================================================ @@ -65,35 +67,33 @@ wxBitmapRefData::wxBitmapRefData() { - m_ok = FALSE; - m_width = 0; - m_height = 0; - m_depth = 0; - m_quality = 0; - m_hBitmap = 0 ; - m_selectedInto = NULL; - m_numColors = 0; - m_bitmapMask = NULL; + m_quality = 0; + m_selectedInto = NULL; + m_numColors = 0; + m_bitmapMask = NULL; } -wxBitmapRefData::~wxBitmapRefData() +void wxBitmapRefData::Free() { wxASSERT_MSG( !m_selectedInto, wxT("deleting bitmap still selected into wxMemoryDC") ); if ( m_hBitmap) - DeleteObject((HBITMAP) m_hBitmap); + { + if ( !::DeleteObject((HBITMAP)m_hBitmap) ) + { + wxLogLastError("DeleteObject(hbitmap)"); + } + } - if ( m_bitmapMask ) - delete m_bitmapMask; + delete m_bitmapMask; + m_bitmapMask = NULL; } // ---------------------------------------------------------------------------- -// wxBitmap +// wxBitmap creation // ---------------------------------------------------------------------------- -wxList wxBitmap::sm_handlers; - // this function should be called from all wxBitmap ctors void wxBitmap::Init() { @@ -103,62 +103,98 @@ void wxBitmap::Init() wxTheBitmapList->AddBitmap(this); } -bool wxBitmap::CopyFromIcon(const wxIcon& icon) +#ifdef __WIN32__ + +bool wxBitmap::CopyFromIconOrCursor(const wxGDIImage& icon) +{ + // it may be either HICON or HCURSOR + HICON hicon = (HICON)icon.GetHandle(); + + ICONINFO iconInfo; + if ( !::GetIconInfo(hicon, &iconInfo) ) + { + wxLogLastError("GetIconInfo"); + + return FALSE; + } + + wxBitmapRefData *refData = new wxBitmapRefData; + m_refData = refData; + + refData->m_width = icon.GetWidth(); + refData->m_height = icon.GetHeight(); + refData->m_depth = wxDisplayDepth(); + + refData->m_hBitmap = (WXHBITMAP)iconInfo.hbmColor; + refData->m_bitmapMask = new wxMask((WXHBITMAP)iconInfo.hbmMask); + +#if WXWIN_COMPATIBILITY_2 + refData->m_ok = TRUE; +#endif // WXWIN_COMPATIBILITY_2 + + return TRUE; +} + +#endif // Win32 + +bool wxBitmap::CopyFromCursor(const wxCursor& cursor) { UnRef(); - if ( !icon.Ok() ) + if ( !cursor.Ok() ) return FALSE; - int width = icon.GetWidth(), - height = icon.GetHeight(); +#ifdef __WIN16__ + wxFAIL_MSG( _T("don't know how to convert cursor to bitmap") ); + + return FALSE; +#endif // Win16 + + return CopyFromIconOrCursor(cursor); +} + +bool wxBitmap::CopyFromIcon(const wxIcon& icon) +{ + UnRef(); - HICON hicon = (HICON) icon.GetHICON(); + if ( !icon.Ok() ) + return FALSE; // GetIconInfo() doesn't exist under Win16 and I don't know any other way // to create a bitmap from icon there - but using this way we won't have // the mask (FIXME) #ifdef __WIN16__ + int width = icon.GetWidth(), + height = icon.GetHeight(); + // copy the icon to the bitmap - HDC hdcScreen = ::GetDC((HWND)NULL); + ScreenHDC hdcScreen; HDC hdc = ::CreateCompatibleDC(hdcScreen); HBITMAP hbitmap = ::CreateCompatibleBitmap(hdcScreen, width, height); HBITMAP hbmpOld = (HBITMAP)::SelectObject(hdc, hbitmap); - ::DrawIcon(hdc, 0, 0, hicon); + ::DrawIcon(hdc, 0, 0, GetHiconOf(icon)); ::SelectObject(hdc, hbmpOld); ::DeleteDC(hdc); - ::ReleaseDC((HWND)NULL, hdcScreen); -#else // Win32 - ICONINFO iconInfo; - if ( !GetIconInfo(hicon, &iconInfo) ) - { - wxLogLastError("GetIconInfo"); - - return FALSE; - } - HBITMAP hbitmap = iconInfo.hbmColor; + wxBitmapRefData *refData = new wxBitmapRefData; + m_refData = refData; - wxMask *mask = new wxMask; - mask->SetMaskBitmap((WXHBITMAP)iconInfo.hbmMask); -#endif // Win16/32 + refData->m_width = width; + refData->m_height = height; + refData->m_depth = wxDisplayDepth(); - m_refData = new wxBitmapRefData; - - M_BITMAPDATA->m_width = width; - M_BITMAPDATA->m_height = height; - M_BITMAPDATA->m_depth = wxDisplayDepth(); + refData->m_hBitmap = (WXHBITMAP)hbitmap; - M_BITMAPDATA->m_hBitmap = (WXHBITMAP)hbitmap; - M_BITMAPDATA->m_ok = TRUE; - -#ifndef __WIN16__ - SetMask(mask); -#endif // !Win16 +#if WXWIN_COMPATIBILITY_2 + refData->m_ok = TRUE; +#endif // WXWIN_COMPATIBILITY_2 return TRUE; +#else // Win32 + return CopyFromIconOrCursor(icon); +#endif // Win16/Win32 } wxBitmap::~wxBitmap() @@ -167,50 +203,26 @@ wxBitmap::~wxBitmap() wxTheBitmapList->DeleteObject(this); } -bool wxBitmap::FreeResource(bool WXUNUSED(force)) -{ - if ( !M_BITMAPDATA ) - return FALSE; - - wxASSERT_MSG( !M_BITMAPDATA->m_selectedInto, - wxT("freeing bitmap still selected into wxMemoryDC") ); - - if (M_BITMAPDATA->m_hBitmap) - { - DeleteObject((HBITMAP) M_BITMAPDATA->m_hBitmap); - } - M_BITMAPDATA->m_hBitmap = 0 ; - -/* - if (M_BITMAPDATA->m_bitmapPalette) - delete M_BITMAPDATA->m_bitmapPalette; - - M_BITMAPDATA->m_bitmapPalette = NULL ; -*/ - - return TRUE; -} - - wxBitmap::wxBitmap(const char bits[], int the_width, int the_height, int no_bits) { Init(); - m_refData = new wxBitmapRefData; - - M_BITMAPDATA->m_width = the_width ; - M_BITMAPDATA->m_height = the_height ; - M_BITMAPDATA->m_depth = no_bits ; - M_BITMAPDATA->m_numColors = 0; + wxBitmapRefData *refData = new wxBitmapRefData; + m_refData = refData; - M_BITMAPDATA->m_hBitmap = (WXHBITMAP) CreateBitmap(the_width, the_height, 1, no_bits, bits); + refData->m_width = the_width; + refData->m_height = the_height; + refData->m_depth = no_bits; + refData->m_numColors = 0; + refData->m_selectedInto = NULL; - if (M_BITMAPDATA->m_hBitmap) - M_BITMAPDATA->m_ok = TRUE; - else - M_BITMAPDATA->m_ok = FALSE; + HBITMAP hbmp = ::CreateBitmap(the_width, the_height, 1, no_bits, bits); + if ( !hbmp ) + { + wxLogLastError("CreateBitmap"); + } - M_BITMAPDATA->m_selectedInto = NULL; + SetHBITMAP((WXHBITMAP)hbmp); } // Create from XPM data @@ -232,7 +244,7 @@ wxBitmap::wxBitmap(void *data, long type, int width, int height, int depth) { Init(); - (void) Create(data, type, width, height, depth); + (void)Create(data, type, width, height, depth); } wxBitmap::wxBitmap(const wxString& filename, long type) @@ -244,225 +256,141 @@ wxBitmap::wxBitmap(const wxString& filename, long type) bool wxBitmap::Create(int w, int h, int d) { - UnRef(); + UnRef(); + + m_refData = new wxBitmapRefData; + + GetBitmapData()->m_width = w; + GetBitmapData()->m_height = h; + GetBitmapData()->m_depth = d; + + HBITMAP hbmp; + + if ( d > 0 ) + { + hbmp = ::CreateBitmap(w, h, 1, d, NULL); + if ( !hbmp ) + { + wxLogLastError("CreateBitmap"); + } + } + else + { + ScreenHDC dc; + hbmp = ::CreateCompatibleBitmap(dc, w, h); + if ( !hbmp ) + { + wxLogLastError("CreateCompatibleBitmap"); + } + + GetBitmapData()->m_depth = wxDisplayDepth(); + } - m_refData = new wxBitmapRefData; + SetHBITMAP((WXHBITMAP)hbmp); - M_BITMAPDATA->m_width = w; - M_BITMAPDATA->m_height = h; - M_BITMAPDATA->m_depth = d; +#if WXWIN_COMPATIBILITY_2 + GetBitmapData()->m_ok = hbmp != 0; +#endif // WXWIN_COMPATIBILITY_2 - if (d > 0) - { - M_BITMAPDATA->m_hBitmap = (WXHBITMAP) CreateBitmap(w, h, 1, d, NULL); - } - else - { - HDC dc = GetDC((HWND) NULL); - M_BITMAPDATA->m_hBitmap = (WXHBITMAP) CreateCompatibleBitmap(dc, w, h); - ReleaseDC((HWND) NULL, dc); - M_BITMAPDATA->m_depth = wxDisplayDepth(); - } - if (M_BITMAPDATA->m_hBitmap) - M_BITMAPDATA->m_ok = TRUE; - else - M_BITMAPDATA->m_ok = FALSE; - return M_BITMAPDATA->m_ok; + return Ok(); } bool wxBitmap::LoadFile(const wxString& filename, long type) { - UnRef(); + UnRef(); - m_refData = new wxBitmapRefData; + wxBitmapHandler *handler = wxDynamicCast(FindHandler(type), wxBitmapHandler); - wxBitmapHandler *handler = FindHandler(type); + if ( handler ) + { + m_refData = new wxBitmapRefData; -#if 0 - if ( handler == NULL ) - return FALSE; -#else - if ( handler == NULL ) { - wxImage image; - if (!image.LoadFile( filename, type )) return FALSE; - if (image.Ok()) + return handler->LoadFile(this, filename, type, -1, -1); + } + else { + wxImage image; + if ( !image.LoadFile( filename, type ) || !image.Ok() ) + return FALSE; + *this = image.ConvertToBitmap(); + return TRUE; } - else return FALSE; - } -#endif - return handler->LoadFile(this, filename, type, -1, -1); } bool wxBitmap::Create(void *data, long type, int width, int height, int depth) { - UnRef(); + UnRef(); - m_refData = new wxBitmapRefData; + wxBitmapHandler *handler = wxDynamicCast(FindHandler(type), wxBitmapHandler); - wxBitmapHandler *handler = FindHandler(type); + if ( !handler ) + { + wxLogDebug(wxT("Failed to create bitmap: no bitmap handler for " + "type %d defined."), type); - if ( handler == NULL ) { - wxLogWarning(wxT("no bitmap handler for type %d defined."), type); + return FALSE; + } - return FALSE; - } + m_refData = new wxBitmapRefData; - return handler->Create(this, data, type, width, height, depth); + return handler->Create(this, data, type, width, height, depth); } bool wxBitmap::SaveFile(const wxString& filename, int type, const wxPalette *palette) { - wxBitmapHandler *handler = FindHandler(type); + wxBitmapHandler *handler = wxDynamicCast(FindHandler(type), wxBitmapHandler); -#if 0 - if ( handler == NULL ) - return FALSE; -#else - if ( handler == NULL ) { // try wxImage - wxImage image( *this ); - if (image.Ok()) return image.SaveFile( filename, type ); - else return FALSE; - } -#endif - - return handler->SaveFile(this, filename, type, palette); -} - -void wxBitmap::SetWidth(int w) -{ - if (!M_BITMAPDATA) - m_refData = new wxBitmapRefData; - - M_BITMAPDATA->m_width = w; -} - -void wxBitmap::SetHeight(int h) -{ - if (!M_BITMAPDATA) - m_refData = new wxBitmapRefData; + if ( handler ) + { + return handler->SaveFile(this, filename, type, palette); + } + else + { + // FIXME what about palette? shouldn't we use it? + wxImage image( *this ); + if (!image.Ok()) + return FALSE; - M_BITMAPDATA->m_height = h; + return image.SaveFile( filename, type ); + } } -void wxBitmap::SetDepth(int d) -{ - if (!M_BITMAPDATA) - m_refData = new wxBitmapRefData; - - M_BITMAPDATA->m_depth = d; -} +// ---------------------------------------------------------------------------- +// wxBitmap accessors +// ---------------------------------------------------------------------------- void wxBitmap::SetQuality(int q) { - if (!M_BITMAPDATA) - m_refData = new wxBitmapRefData; + EnsureHasData(); - M_BITMAPDATA->m_quality = q; + GetBitmapData()->m_quality = q; } +#if WXWIN_COMPATIBILITY_2 void wxBitmap::SetOk(bool isOk) { - if (!M_BITMAPDATA) - m_refData = new wxBitmapRefData; + EnsureHasData(); - M_BITMAPDATA->m_ok = isOk; + GetBitmapData()->m_ok = isOk; } +#endif // WXWIN_COMPATIBILITY_2 void wxBitmap::SetPalette(const wxPalette& palette) { - if (!M_BITMAPDATA) - m_refData = new wxBitmapRefData; + EnsureHasData(); - M_BITMAPDATA->m_bitmapPalette = palette ; + GetBitmapData()->m_bitmapPalette = palette; } void wxBitmap::SetMask(wxMask *mask) { - if (!M_BITMAPDATA) - m_refData = new wxBitmapRefData; - - M_BITMAPDATA->m_bitmapMask = mask ; -} - -void wxBitmap::SetHBITMAP(WXHBITMAP bmp) -{ - if (!M_BITMAPDATA) - m_refData = new wxBitmapRefData; - - M_BITMAPDATA->m_hBitmap = bmp; - M_BITMAPDATA->m_ok = bmp != 0; -} - -void wxBitmap::AddHandler(wxBitmapHandler *handler) -{ - sm_handlers.Append(handler); -} - -void wxBitmap::InsertHandler(wxBitmapHandler *handler) -{ - sm_handlers.Insert(handler); -} - -bool wxBitmap::RemoveHandler(const wxString& name) -{ - wxBitmapHandler *handler = FindHandler(name); - if ( handler ) - { - sm_handlers.DeleteObject(handler); - return TRUE; - } - else - return FALSE; -} - -wxBitmapHandler *wxBitmap::FindHandler(const wxString& name) -{ - wxNode *node = sm_handlers.First(); - while ( node ) - { - wxBitmapHandler *handler = (wxBitmapHandler *)node->Data(); - if ( (handler->GetName().Cmp(name) == 0) ) - return handler; - node = node->Next(); - } - return NULL; -} - -wxBitmapHandler *wxBitmap::FindHandler(const wxString& extension, long bitmapType) -{ - wxNode *node = sm_handlers.First(); - while ( node ) - { - wxBitmapHandler *handler = (wxBitmapHandler *)node->Data(); - if ( (handler->GetExtension().Cmp(extension) == 0) && - (bitmapType == -1 || (handler->GetType() == bitmapType)) ) - return handler; - node = node->Next(); - } - return NULL; -} + EnsureHasData(); -wxBitmapHandler *wxBitmap::FindHandler(long bitmapType) -{ - wxNode *node = sm_handlers.First(); - while ( node ) - { - wxBitmapHandler *handler = (wxBitmapHandler *)node->Data(); - if (handler->GetType() == bitmapType) - return handler; - node = node->Next(); - } - return NULL; + GetBitmapData()->m_bitmapMask = mask; } -// New Create/FreeDIB functions since ones in dibutils.cpp are confusing -static long createDIB(long xSize, long ySize, long bitsPerPixel, - HPALETTE hPal, LPBITMAPINFO* lpDIBHeader); -static long freeDIB(LPBITMAPINFO lpDIBHeader); - // Creates a bitmap that matches the device context, from // an arbitray bitmap. At present, the original bitmap must have an // associated palette. TODO: use a default palette if no palette exists. @@ -475,21 +403,12 @@ wxBitmap wxBitmap::GetBitmapForDC(wxDC& dc) const LPBITMAPINFO lpDib; void *lpBits = (void*) NULL; -/* - wxASSERT( this->GetPalette() && this->GetPalette()->Ok() && (this->GetPalette()->GetHPALETTE() != 0) ); - - tmpBitmap.SetPalette(this->GetPalette()); - memDC.SelectObject(tmpBitmap); - memDC.SetPalette(this->GetPalette()); - - hPal = (HPALETTE) this->GetPalette()->GetHPALETTE(); -*/ - if( this->GetPalette() && this->GetPalette()->Ok() && (this->GetPalette()->GetHPALETTE() != 0) ) + if( GetPalette() && GetPalette()->Ok() ) { - tmpBitmap.SetPalette(* this->GetPalette()); + tmpBitmap.SetPalette(*GetPalette()); memDC.SelectObject(tmpBitmap); - memDC.SetPalette(* this->GetPalette()); - hPal = (HPALETTE) this->GetPalette()->GetHPALETTE(); + memDC.SetPalette(*GetPalette()); + hPal = (HPALETTE)GetPalette()->GetHPALETTE(); } else { @@ -501,25 +420,32 @@ wxBitmap wxBitmap::GetBitmapForDC(wxDC& dc) const memDC.SetPalette( palette ); } - // set the height negative because in a DIB the order of the lines is reversed - createDIB(this->GetWidth(), -this->GetHeight(), this->GetDepth(), hPal, &lpDib); + // set the height negative because in a DIB the order of the lines is + // reversed + if ( !wxCreateDIB(GetWidth(), -GetHeight(), GetDepth(), hPal, &lpDib) ) + { + return wxNullBitmap; + } lpBits = malloc(lpDib->bmiHeader.biSizeImage); - ::GetBitmapBits((HBITMAP)GetHBITMAP(), lpDib->bmiHeader.biSizeImage, lpBits); + ::GetBitmapBits(GetHbitmap(), lpDib->bmiHeader.biSizeImage, lpBits); - ::SetDIBitsToDevice((HDC) memDC.GetHDC(), 0, 0, this->GetWidth(), this->GetHeight(), - 0, 0, 0, this->GetHeight(), lpBits, lpDib, DIB_RGB_COLORS); + ::SetDIBitsToDevice(GetHdcOf(memDC), 0, 0, + GetWidth(), GetHeight(), + 0, 0, 0, GetHeight(), + lpBits, lpDib, DIB_RGB_COLORS); free(lpBits); - freeDIB(lpDib); - return (tmpBitmap); + wxFreeDIB(lpDib); + + return tmpBitmap; } -/* - * wxMask - */ +// ---------------------------------------------------------------------------- +// wxMask +// ---------------------------------------------------------------------------- wxMask::wxMask() { @@ -531,7 +457,7 @@ wxMask::wxMask() wxMask::wxMask(const wxBitmap& bitmap, const wxColour& colour) { m_maskBitmap = 0; - Create(bitmap, colour); + Create(bitmap, colour); } // Construct a mask from a bitmap and a palette index indicating @@ -539,14 +465,14 @@ wxMask::wxMask(const wxBitmap& bitmap, const wxColour& colour) wxMask::wxMask(const wxBitmap& bitmap, int paletteIndex) { m_maskBitmap = 0; - Create(bitmap, paletteIndex); + Create(bitmap, paletteIndex); } // Construct a mask from a mono bitmap (copies the bitmap). wxMask::wxMask(const wxBitmap& bitmap) { m_maskBitmap = 0; - Create(bitmap); + Create(bitmap); } wxMask::~wxMask() @@ -559,29 +485,29 @@ wxMask::~wxMask() bool wxMask::Create(const wxBitmap& bitmap) { if ( m_maskBitmap ) - { - ::DeleteObject((HBITMAP) m_maskBitmap); - m_maskBitmap = 0; - } - if (!bitmap.Ok() || bitmap.GetDepth() != 1) - { - return FALSE; - } - m_maskBitmap = (WXHBITMAP) CreateBitmap( - bitmap.GetWidth(), - bitmap.GetHeight(), - 1, 1, 0 - ); - HDC srcDC = CreateCompatibleDC(0); - SelectObject(srcDC, (HBITMAP) bitmap.GetHBITMAP()); - HDC destDC = CreateCompatibleDC(0); - SelectObject(destDC, (HBITMAP) m_maskBitmap); - BitBlt(destDC, 0, 0, bitmap.GetWidth(), bitmap.GetHeight(), srcDC, 0, 0, SRCCOPY); - SelectObject(srcDC, 0); - DeleteDC(srcDC); - SelectObject(destDC, 0); - DeleteDC(destDC); - return TRUE; + { + ::DeleteObject((HBITMAP) m_maskBitmap); + m_maskBitmap = 0; + } + if (!bitmap.Ok() || bitmap.GetDepth() != 1) + { + return FALSE; + } + m_maskBitmap = (WXHBITMAP) CreateBitmap( + bitmap.GetWidth(), + bitmap.GetHeight(), + 1, 1, 0 + ); + HDC srcDC = CreateCompatibleDC(0); + SelectObject(srcDC, (HBITMAP) bitmap.GetHBITMAP()); + HDC destDC = CreateCompatibleDC(0); + SelectObject(destDC, (HBITMAP) m_maskBitmap); + BitBlt(destDC, 0, 0, bitmap.GetWidth(), bitmap.GetHeight(), srcDC, 0, 0, SRCCOPY); + SelectObject(srcDC, 0); + DeleteDC(srcDC); + SelectObject(destDC, 0); + DeleteDC(destDC); + return TRUE; } // Create a mask from a bitmap and a palette index indicating @@ -589,20 +515,20 @@ bool wxMask::Create(const wxBitmap& bitmap) bool wxMask::Create(const wxBitmap& bitmap, int paletteIndex) { if ( m_maskBitmap ) - { - ::DeleteObject((HBITMAP) m_maskBitmap); - m_maskBitmap = 0; - } - if (bitmap.Ok() && bitmap.GetPalette()->Ok()) - { - unsigned char red, green, blue; - if (bitmap.GetPalette()->GetRGB(paletteIndex, &red, &green, &blue)) { - wxColour transparentColour(red, green, blue); - return Create(bitmap, transparentColour); + ::DeleteObject((HBITMAP) m_maskBitmap); + m_maskBitmap = 0; } - } - return FALSE; + if (bitmap.Ok() && bitmap.GetPalette()->Ok()) + { + unsigned char red, green, blue; + if (bitmap.GetPalette()->GetRGB(paletteIndex, &red, &green, &blue)) + { + wxColour transparentColour(red, green, blue); + return Create(bitmap, transparentColour); + } + } + return FALSE; } // Create a mask from a bitmap and a colour indicating @@ -610,208 +536,119 @@ bool wxMask::Create(const wxBitmap& bitmap, int paletteIndex) bool wxMask::Create(const wxBitmap& bitmap, const wxColour& colour) { if ( m_maskBitmap ) - { - ::DeleteObject((HBITMAP) m_maskBitmap); - m_maskBitmap = 0; - } - if (!bitmap.Ok()) - { - return FALSE; - } - - // scan the bitmap for the transparent colour and set - // the corresponding pixels in the mask to BLACK and - // the rest to WHITE - COLORREF maskColour = RGB(colour.Red(), colour.Green(), colour.Blue()); - m_maskBitmap = (WXHBITMAP) ::CreateBitmap( - bitmap.GetWidth(), - bitmap.GetHeight(), - 1, 1, 0 - ); - HDC srcDC = ::CreateCompatibleDC(0); - ::SelectObject(srcDC, (HBITMAP) bitmap.GetHBITMAP()); - HDC destDC = ::CreateCompatibleDC(0); - ::SelectObject(destDC, (HBITMAP) m_maskBitmap); - - // this is not very efficient, but I can't think - // of a better way of doing it - for (int w = 0; w < bitmap.GetWidth(); w++) - { - for (int h = 0; h < bitmap.GetHeight(); h++) { - COLORREF col = GetPixel(srcDC, w, h); - if (col == maskColour) - { - ::SetPixel(destDC, w, h, RGB(0, 0, 0)); - } - else - { - ::SetPixel(destDC, w, h, RGB(255, 255, 255)); - } + ::DeleteObject((HBITMAP) m_maskBitmap); + m_maskBitmap = 0; + } + if (!bitmap.Ok()) + { + return FALSE; } - } - ::SelectObject(srcDC, 0); - ::DeleteDC(srcDC); - ::SelectObject(destDC, 0); - ::DeleteDC(destDC); - return TRUE; -} - -/* - * wxBitmapHandler - */ - -IMPLEMENT_DYNAMIC_CLASS(wxBitmapHandler, wxObject) - -bool wxBitmapHandler::Create(wxBitmap *WXUNUSED(bitmap), void *WXUNUSED(data), long WXUNUSED(type), int WXUNUSED(width), int WXUNUSED(height), int WXUNUSED(depth)) -{ - return FALSE; -} - -bool wxBitmapHandler::LoadFile(wxBitmap *WXUNUSED(bitmap), const wxString& WXUNUSED(name), long WXUNUSED(type), - int WXUNUSED(desiredWidth), int WXUNUSED(desiredHeight)) -{ - return FALSE; -} - -bool wxBitmapHandler::SaveFile(wxBitmap *WXUNUSED(bitmap), const wxString& WXUNUSED(name), int WXUNUSED(type), const wxPalette *WXUNUSED(palette)) -{ - return FALSE; -} - -/* - * Standard handlers - */ - -class WXDLLEXPORT wxBMPResourceHandler: public wxBitmapHandler -{ - DECLARE_DYNAMIC_CLASS(wxBMPResourceHandler) -public: - inline wxBMPResourceHandler() - { - m_name = "Windows bitmap resource"; - m_extension = ""; - m_type = wxBITMAP_TYPE_BMP_RESOURCE; - }; - - virtual bool LoadFile(wxBitmap *bitmap, const wxString& name, long flags, - int desiredWidth, int desiredHeight); -}; -IMPLEMENT_DYNAMIC_CLASS(wxBMPResourceHandler, wxBitmapHandler) -bool wxBMPResourceHandler::LoadFile(wxBitmap *bitmap, const wxString& name, long WXUNUSED(flags), - int WXUNUSED(desiredWidth), int WXUNUSED(desiredHeight)) -{ - // TODO: load colourmap. - M_BITMAPHANDLERDATA->m_hBitmap = (WXHBITMAP) ::LoadBitmap(wxGetInstance(), name); - if (M_BITMAPHANDLERDATA->m_hBitmap) + // scan the bitmap for the transparent colour and set + // the corresponding pixels in the mask to BLACK and + // the rest to WHITE + COLORREF maskColour = RGB(colour.Red(), colour.Green(), colour.Blue()); + m_maskBitmap = (WXHBITMAP) ::CreateBitmap( + bitmap.GetWidth(), + bitmap.GetHeight(), + 1, 1, 0 + ); + HDC srcDC = ::CreateCompatibleDC(0); + ::SelectObject(srcDC, (HBITMAP) bitmap.GetHBITMAP()); + HDC destDC = ::CreateCompatibleDC(0); + ::SelectObject(destDC, (HBITMAP) m_maskBitmap); + + // this is not very efficient, but I can't think + // of a better way of doing it + for (int w = 0; w < bitmap.GetWidth(); w++) { - M_BITMAPHANDLERDATA->m_ok = TRUE; - BITMAP bm; - GetObject((HBITMAP) M_BITMAPHANDLERDATA->m_hBitmap, sizeof(BITMAP), (LPSTR) &bm); - M_BITMAPHANDLERDATA->m_width = bm.bmWidth; - M_BITMAPHANDLERDATA->m_height = bm.bmHeight; - M_BITMAPHANDLERDATA->m_depth = bm.bmBitsPixel; - - if ( bitmap->IsKindOf(CLASSINFO(wxIcon)) ) + for (int h = 0; h < bitmap.GetHeight(); h++) { + COLORREF col = GetPixel(srcDC, w, h); + if (col == maskColour) + { + ::SetPixel(destDC, w, h, RGB(0, 0, 0)); + } + else + { + ::SetPixel(destDC, w, h, RGB(255, 255, 255)); + } } - - return TRUE; } + ::SelectObject(srcDC, 0); + ::DeleteDC(srcDC); + ::SelectObject(destDC, 0); + ::DeleteDC(destDC); + return TRUE; +} + +// ---------------------------------------------------------------------------- +// wxBitmapHandler +// ---------------------------------------------------------------------------- - // it's probably not found - wxLogError(wxT("Can't load bitmap '%s' from resources! Check .rc file."), name.c_str()); +bool wxBitmapHandler::Create(wxGDIImage *image, + void *data, + long flags, + int width, int height, int depth) +{ + wxBitmap *bitmap = wxDynamicCast(image, wxBitmap); - return FALSE; + return bitmap ? Create(bitmap, data, width, height, depth) : FALSE; } -class WXDLLEXPORT wxBMPFileHandler: public wxBitmapHandler +bool wxBitmapHandler::Load(wxGDIImage *image, + const wxString& name, + long flags, + int width, int height) { - DECLARE_DYNAMIC_CLASS(wxBMPFileHandler) -public: - inline wxBMPFileHandler() - { - m_name = "Windows bitmap file"; - m_extension = "bmp"; - m_type = wxBITMAP_TYPE_BMP; - }; + wxBitmap *bitmap = wxDynamicCast(image, wxBitmap); - virtual bool LoadFile(wxBitmap *bitmap, const wxString& name, long flags, - int desiredWidth, int desiredHeight); - virtual bool SaveFile(wxBitmap *bitmap, const wxString& name, int type, const wxPalette *palette = NULL); -}; -IMPLEMENT_DYNAMIC_CLASS(wxBMPFileHandler, wxBitmapHandler) + return bitmap ? LoadFile(bitmap, name, flags, width, height) : FALSE; +} -bool wxBMPFileHandler::LoadFile(wxBitmap *bitmap, const wxString& name, long WXUNUSED(flags), - int WXUNUSED(desiredWidth), int WXUNUSED(desiredHeight)) +bool wxBitmapHandler::Save(wxGDIImage *image, + const wxString& name, + int type) { -#if wxUSE_IMAGE_LOADING_IN_MSW - wxPalette *palette = NULL; - bool success = FALSE; -/* - if (type & wxBITMAP_DISCARD_COLOURMAP) - success = wxLoadIntoBitmap(WXSTRINGCAST name, bitmap); - else -*/ - success = (wxLoadIntoBitmap(WXSTRINGCAST name, bitmap, &palette) != 0); - if (!success && palette) - { - delete palette; - palette = NULL; - } - if (palette) - { - M_BITMAPHANDLERDATA->m_bitmapPalette = *palette; - delete palette; - } - return success; -#else - return FALSE; -#endif + wxBitmap *bitmap = wxDynamicCast(image, wxBitmap); + + return bitmap ? SaveFile(bitmap, name, type) : FALSE; } -bool wxBMPFileHandler::SaveFile(wxBitmap *bitmap, const wxString& name, int WXUNUSED(type), const wxPalette *pal) +bool wxBitmapHandler::Create(wxBitmap *WXUNUSED(bitmap), + void *WXUNUSED(data), + long WXUNUSED(type), + int WXUNUSED(width), + int WXUNUSED(height), + int WXUNUSED(depth)) { -#if wxUSE_IMAGE_LOADING_IN_MSW - wxPalette *actualPalette = (wxPalette *)pal; - if (!actualPalette && (!M_BITMAPHANDLERDATA->m_bitmapPalette.IsNull())) - actualPalette = & (M_BITMAPHANDLERDATA->m_bitmapPalette); - return (wxSaveBitmap(WXSTRINGCAST name, bitmap, actualPalette) != 0); -#else - return FALSE; -#endif + return FALSE; } -void wxBitmap::CleanUpHandlers() +bool wxBitmapHandler::LoadFile(wxBitmap *WXUNUSED(bitmap), + const wxString& WXUNUSED(name), + long WXUNUSED(type), + int WXUNUSED(desiredWidth), + int WXUNUSED(desiredHeight)) { - wxNode *node = sm_handlers.First(); - while ( node ) - { - wxBitmapHandler *handler = (wxBitmapHandler *)node->Data(); - wxNode *next = node->Next(); - delete handler; - delete node; - node = next; - } + return FALSE; } -void wxBitmap::InitStandardHandlers() +bool wxBitmapHandler::SaveFile(wxBitmap *WXUNUSED(bitmap), + const wxString& WXUNUSED(name), + int WXUNUSED(type), + const wxPalette *WXUNUSED(palette)) { - AddHandler(new wxBMPResourceHandler); - AddHandler(new wxBMPFileHandler); - - // Not added by default: include xpmhand.h in your app - // and call these in your wxApp::OnInit. -// AddHandler(new wxXPMFileHandler); -// AddHandler(new wxXPMDataHandler); - - AddHandler(new wxICOResourceHandler); - AddHandler(new wxICOFileHandler); + return FALSE; } -static long createDIB(long xSize, long ySize, long bitsPerPixel, - HPALETTE hPal, LPBITMAPINFO* lpDIBHeader) +// ---------------------------------------------------------------------------- +// DIB functions +// ---------------------------------------------------------------------------- + +bool wxCreateDIB(long xSize, long ySize, long bitsPerPixel, + HPALETTE hPal, LPBITMAPINFO* lpDIBHeader) { unsigned long i, headerSize; LPBITMAPINFO lpDIBheader = NULL; @@ -825,10 +662,8 @@ static long createDIB(long xSize, long ySize, long bitsPerPixel, GetPaletteEntries(hPal, 0, 256, lpPe); - memset(lpDIBheader, 0x00, sizeof(BITMAPINFOHEADER)); - // Fill in the static parts of the DIB header lpDIBheader->bmiHeader.biSize = sizeof(BITMAPINFOHEADER); lpDIBheader->bmiHeader.biWidth = xSize; @@ -838,8 +673,7 @@ static long createDIB(long xSize, long ySize, long bitsPerPixel, // this value must be 1, 4, 8 or 24 so PixelDepth can only be lpDIBheader->bmiHeader.biBitCount = (WORD)(bitsPerPixel); lpDIBheader->bmiHeader.biCompression = BI_RGB; - lpDIBheader->bmiHeader.biSizeImage = xSize * abs(ySize) * bitsPerPixel >> -3; + lpDIBheader->bmiHeader.biSizeImage = xSize * abs(ySize) * bitsPerPixel >> 3; lpDIBheader->bmiHeader.biClrUsed = 256; @@ -853,21 +687,12 @@ static long createDIB(long xSize, long ySize, long bitsPerPixel, *lpDIBHeader = lpDIBheader; - - return (0); - + return TRUE; } - - -static long freeDIB(LPBITMAPINFO lpDIBHeader) +void wxFreeDIB(LPBITMAPINFO lpDIBHeader) { - - if (lpDIBHeader != NULL) { - free(lpDIBHeader); - } - - return (0); + free(lpDIBHeader); } diff --git a/src/msw/clipbrd.cpp b/src/msw/clipbrd.cpp index 6b93ebf988..bb12806233 100644 --- a/src/msw/clipbrd.cpp +++ b/src/msw/clipbrd.cpp @@ -319,7 +319,9 @@ void *wxGetClipboardData(wxDataFormat dataFormat, long *len) wxBM->SetWidth(bm.bmWidth); wxBM->SetHeight(bm.bmHeight); wxBM->SetDepth(bm.bmPlanes); +#if WXWIN_COMPATIBILITY_2 wxBM->SetOk(TRUE); +#endif // WXWIN_COMPATIBILITY_2 retval = wxBM; break; }