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
This commit is contained in:
Vadim Zeitlin
1999-11-24 12:30:56 +00:00
parent 162999bfb7
commit 6d167489bd
19 changed files with 906 additions and 900 deletions

View File

@@ -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,

View File

@@ -45,13 +45,8 @@ 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") ); }
*/
// creation
static wxMenuItem *New(wxMenu *parentMenu = (wxMenu *)NULL,
int id = wxID_SEPARATOR,

View File

@@ -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;

View File

@@ -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
// ----------------------------------------------------------------------------
// Bitmap data
//
// NB: this class is private, but declared here to make it possible inline
// wxBitmap functions accessing it
// ----------------------------------------------------------------------------
class WXDLLEXPORT wxBitmapRefData : public wxGDIImageRefData
{
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; }
protected:
WXHBITMAP m_maskBitmap;
};
class WXDLLEXPORT wxBitmapRefData: public wxGDIRefData
{
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
// MSW-specific
// ------------
// 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_BITMAPDATA ((wxBitmapRefData *)m_refData)
// ----------------------------------------------------------------------------
// wxBitmap: a mono or colour bitmap
// ----------------------------------------------------------------------------
class WXDLLEXPORT wxBitmapHandler: public wxObject
class WXDLLEXPORT wxBitmap : public wxGDIImage
{
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;
};
#define M_BITMAPHANDLERDATA ((wxBitmapRefData *)bitmap->GetRefData())
class WXDLLEXPORT wxBitmap: public wxGDIObject
{
friend class WXDLLEXPORT wxBitmapHandler;
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);
#if WXWIN_COMPATIBILITY_2
void SetOk(bool isOk);
#endif // WXWIN_COMPATIBILITY_2
static void InitStandardHandlers();
static void CleanUpHandlers();
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);
void SetHBITMAP(WXHBITMAP bmp) { SetHandle((WXHANDLE)bmp); }
WXHBITMAP GetHBITMAP() const { return (WXHBITMAP)GetHandle(); }
// 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 <frederic.villeneuve@natinst.com>
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
// <frederic.villeneuve@natinst.com>
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_

View File

@@ -1,5 +1,5 @@
/////////////////////////////////////////////////////////////////////////////
// Name: cursor.h
// Name: wx/msw/cursor.h
// Purpose: wxCursor class
// Author: Julian Smart
// Modified by:
@@ -16,52 +16,67 @@
#pragma interface "cursor.h"
#endif
// 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"
class WXDLLEXPORT wxCursorRefData: public wxBitmapRefData
{
friend class WXDLLEXPORT wxBitmap;
friend class WXDLLEXPORT wxCursor;
public:
wxCursorRefData(void);
~wxCursorRefData(void);
#define wxCursorRefDataBase wxBitmapRefData
#define wxCursorBase wxBitmap
#else
#include "wx/msw/gdiimage.h"
protected:
WXHCURSOR m_hCursor;
#define wxCursorRefDataBase wxGDIImageRefData
#define wxCursorBase wxGDIImage
#endif
class WXDLLEXPORT wxCursorRefData : public wxCursorRefDataBase
{
public:
wxCursorRefData();
virtual ~wxCursorRefData() { Free(); }
virtual void Free();
// for compatibility
public:
bool m_destroyCursor;
};
#define M_CURSORDATA ((wxCursorRefData *)m_refData)
#define M_CURSORHANDLERDATA ((wxCursorRefData *)bitmap->m_refData)
// 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); }
wxCursor(const wxCursor& cursor) { Ref(cursor); }
wxCursor(const char bits[], int width, int height, int hotSpotX = -1, int hotSpotY = -1,
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,
wxCursor(const wxString& name,
long flags = wxBITMAP_TYPE_CUR_RESOURCE,
int hotSpotX = 0, int hotSpotY = 0);
wxCursor(int cursor_type);
~wxCursor(void);
virtual bool Ok(void) const { return (m_refData != NULL && M_CURSORDATA->m_hCursor) ; }
virtual ~wxCursor();
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);
inline WXHCURSOR GetHCURSOR(void) const { return (M_CURSORDATA ? M_CURSORDATA->m_hCursor : 0); }
void SetHCURSOR(WXHCURSOR cursor) { SetHandle((WXHANDLE)cursor); }
WXHCURSOR GetHCURSOR() const { return (WXHCURSOR)GetHandle(); }
bool FreeResource(bool force = FALSE);
protected:
virtual wxGDIImageRefData *CreateData() const { return new wxCursorRefData; }
private:
DECLARE_DYNAMIC_CLASS(wxCursor)
};
#endif

View File

@@ -1,5 +1,5 @@
/////////////////////////////////////////////////////////////////////////////
// Name: dib.h
// Name: wx/msw/dib.h
// Purpose: Routines for loading and saving DIBs
// Author: Various
// Modified by:
@@ -13,10 +13,29 @@
#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_

View File

@@ -1,5 +1,5 @@
/////////////////////////////////////////////////////////////////////////////
// Name: gdiobj.h
// Name: wx/msw/gdiobj.h
// Purpose: wxGDIObject class: base class for other GDI classes
// Author: Julian Smart
// Modified by:
@@ -12,55 +12,53 @@
#ifndef _WX_GDIOBJ_H_
#define _WX_GDIOBJ_H_
#include "wx/object.h"
#ifdef __GNUG__
#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
{
DECLARE_DYNAMIC_CLASS(wxGDIObject)
public:
inline wxGDIObject(void) { m_visible = FALSE; };
inline ~wxGDIObject(void) {};
wxGDIObject() { m_visible = FALSE; };
// Creates the resource
virtual bool RealizeResource(void) { return FALSE; };
virtual bool RealizeResource() { return FALSE; };
// Frees the resource
virtual bool FreeResource(bool WXUNUSED(force) = FALSE) { return FALSE; };
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; }
virtual WXHANDLE GetResourceHandle() { return 0; }
virtual bool GetVisible(void) { return m_visible; }
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

View File

@@ -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
// ----------------------------------------------------------------------------
// 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
// notice that although wxIconRefData inherits from wxBitmapRefData, it is not
// a valid wxBitmapRefData
class WXDLLEXPORT wxIconRefData : public wxIconRefDataBase
{
friend class WXDLLEXPORT wxBitmap;
friend class WXDLLEXPORT wxIcon;
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,
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) ; }
void SetHICON(WXHICON icon) { SetHandle((WXHANDLE)icon); }
WXHICON GetHICON() const { return (WXHICON)GetHandle(); }
bool FreeResource(bool force = FALSE);
};
// TODO: Put these in separate, private header
class WXDLLEXPORT wxICOFileHandler: public wxBitmapHandler
protected:
virtual wxGDIImageRefData *CreateData() const
{
DECLARE_DYNAMIC_CLASS(wxICOFileHandler)
public:
wxICOFileHandler()
{
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

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -1,5 +1,5 @@
/////////////////////////////////////////////////////////////////////////////
// Name: tbarbase.h
// Name: wx/tbarbase.h
// Purpose: Base class for toolbar classes
// Author: Julian Smart
// Modified by:

View File

@@ -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
// 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

View File

@@ -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_

View File

@@ -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;
}
@@ -596,14 +602,13 @@ 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)) &&
@@ -612,11 +617,12 @@ wxFont *wxFontList::
#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;
}

View File

@@ -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;
}

View File

@@ -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
// 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,21 +1081,77 @@ void wxApp::OnQueryEndSession(wxCloseEvent& event)
}
}
int wxApp::GetComCtl32Version() const
#if wxUSE_RICHEDIT
/* static */
bool wxApp::InitRichEdit(int version)
{
wxCHECK_MSG( version >= 1 && version <= 3, FALSE,
_T("incorrect richedit control version requested") );
if ( version <= gs_verRichEdit )
{
// we've already got this or better
return TRUE;
}
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"));
int version = 0;
// if so, then we can check for the version
if (theModule)
{
// InitCommonControlsEx is unique to 4.7 and later
FARPROC theProc = ::GetProcAddress(theModule, "InitCommonControlsEx");
FARPROC theProc = ::GetProcAddress(theModule,
_T("InitCommonControlsEx"));
if ( !theProc )
{ // not found, must be 4.00
version = 400;
s_verComCtl32 = 400;
}
else
{
@@ -1126,19 +1165,21 @@ int wxApp::GetComCtl32Version() const
// InitializeFlatSB
// UninitializeFlatSB
// we could check for any of these - I chose DllInstall
FARPROC theProc = ::GetProcAddress(theModule, "DllInstall");
FARPROC theProc = ::GetProcAddress(theModule, _T("DllInstall"));
if ( !theProc )
{
// not found, must be 4.70
version = 470;
s_verComCtl32 = 470;
}
else
{ // found, must be 4.71
version = 471;
s_verComCtl32 = 471;
}
}
}
return version;
}
return s_verComCtl32;
}
void wxExit()

View File

@@ -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;
}
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;
m_bitmapMask = NULL;
}
// ----------------------------------------------------------------------------
// wxBitmap
// wxBitmap creation
// ----------------------------------------------------------------------------
wxList wxBitmap::sm_handlers;
// this function should be called from all wxBitmap ctors
void wxBitmap::Init()
{
@@ -103,6 +103,56 @@ void wxBitmap::Init()
wxTheBitmapList->AddBitmap(this);
}
#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 ( !cursor.Ok() )
return FALSE;
#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();
@@ -110,55 +160,41 @@ bool wxBitmap::CopyFromIcon(const wxIcon& icon)
if ( !icon.Ok() )
return FALSE;
int width = icon.GetWidth(),
height = icon.GetHeight();
HICON hicon = (HICON) icon.GetHICON();
// 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;
}
wxBitmapRefData *refData = new wxBitmapRefData;
m_refData = refData;
HBITMAP hbitmap = iconInfo.hbmColor;
refData->m_width = width;
refData->m_height = height;
refData->m_depth = wxDisplayDepth();
wxMask *mask = new wxMask;
mask->SetMaskBitmap((WXHBITMAP)iconInfo.hbmMask);
#endif // Win16/32
refData->m_hBitmap = (WXHBITMAP)hbitmap;
m_refData = new wxBitmapRefData;
M_BITMAPDATA->m_width = width;
M_BITMAPDATA->m_height = height;
M_BITMAPDATA->m_depth = wxDisplayDepth();
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;
wxBitmapRefData *refData = new wxBitmapRefData;
m_refData = refData;
M_BITMAPDATA->m_width = the_width ;
M_BITMAPDATA->m_height = the_height ;
M_BITMAPDATA->m_depth = no_bits ;
M_BITMAPDATA->m_numColors = 0;
refData->m_width = the_width;
refData->m_height = the_height;
refData->m_depth = no_bits;
refData->m_numColors = 0;
refData->m_selectedInto = NULL;
M_BITMAPDATA->m_hBitmap = (WXHBITMAP) CreateBitmap(the_width, the_height, 1, no_bits, bits);
HBITMAP hbmp = ::CreateBitmap(the_width, the_height, 1, no_bits, bits);
if ( !hbmp )
{
wxLogLastError("CreateBitmap");
}
if (M_BITMAPDATA->m_hBitmap)
M_BITMAPDATA->m_ok = TRUE;
else
M_BITMAPDATA->m_ok = FALSE;
M_BITMAPDATA->m_selectedInto = NULL;
SetHBITMAP((WXHBITMAP)hbmp);
}
// Create from XPM data
@@ -248,221 +260,137 @@ bool wxBitmap::Create(int w, int h, int d)
m_refData = new wxBitmapRefData;
M_BITMAPDATA->m_width = w;
M_BITMAPDATA->m_height = h;
M_BITMAPDATA->m_depth = d;
GetBitmapData()->m_width = w;
GetBitmapData()->m_height = h;
GetBitmapData()->m_depth = d;
HBITMAP hbmp;
if ( d > 0 )
{
M_BITMAPDATA->m_hBitmap = (WXHBITMAP) CreateBitmap(w, h, 1, d, NULL);
hbmp = ::CreateBitmap(w, h, 1, d, NULL);
if ( !hbmp )
{
wxLogLastError("CreateBitmap");
}
}
else
{
HDC dc = GetDC((HWND) NULL);
M_BITMAPDATA->m_hBitmap = (WXHBITMAP) CreateCompatibleBitmap(dc, w, h);
ReleaseDC((HWND) NULL, dc);
M_BITMAPDATA->m_depth = wxDisplayDepth();
ScreenHDC dc;
hbmp = ::CreateCompatibleBitmap(dc, w, h);
if ( !hbmp )
{
wxLogLastError("CreateCompatibleBitmap");
}
if (M_BITMAPDATA->m_hBitmap)
M_BITMAPDATA->m_ok = TRUE;
else
M_BITMAPDATA->m_ok = FALSE;
return M_BITMAPDATA->m_ok;
GetBitmapData()->m_depth = wxDisplayDepth();
}
SetHBITMAP((WXHBITMAP)hbmp);
#if WXWIN_COMPATIBILITY_2
GetBitmapData()->m_ok = hbmp != 0;
#endif // WXWIN_COMPATIBILITY_2
return Ok();
}
bool wxBitmap::LoadFile(const wxString& filename, long type)
{
UnRef();
wxBitmapHandler *handler = wxDynamicCast(FindHandler(type), wxBitmapHandler);
if ( handler )
{
m_refData = new wxBitmapRefData;
wxBitmapHandler *handler = FindHandler(type);
#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();
m_refData = new wxBitmapRefData;
wxBitmapHandler *handler = wxDynamicCast(FindHandler(type), wxBitmapHandler);
wxBitmapHandler *handler = FindHandler(type);
if ( handler == NULL ) {
wxLogWarning(wxT("no bitmap handler for type %d defined."), type);
if ( !handler )
{
wxLogDebug(wxT("Failed to create bitmap: no bitmap handler for "
"type %d defined."), type);
return FALSE;
}
m_refData = new wxBitmapRefData;
return handler->Create(this, data, type, width, height, depth);
}
bool wxBitmap::SaveFile(const wxString& filename, int type, const wxPalette *palette)
{
wxBitmapHandler *handler = FindHandler(type);
#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
wxBitmapHandler *handler = wxDynamicCast(FindHandler(type), wxBitmapHandler);
if ( handler )
{
return handler->SaveFile(this, filename, type, palette);
}
void wxBitmap::SetWidth(int w)
else
{
if (!M_BITMAPDATA)
m_refData = new wxBitmapRefData;
// FIXME what about palette? shouldn't we use it?
wxImage image( *this );
if (!image.Ok())
return FALSE;
M_BITMAPDATA->m_width = w;
return image.SaveFile( filename, type );
}
}
void wxBitmap::SetHeight(int h)
{
if (!M_BITMAPDATA)
m_refData = new wxBitmapRefData;
M_BITMAPDATA->m_height = h;
}
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;
EnsureHasData();
M_BITMAPDATA->m_bitmapMask = mask ;
GetBitmapData()->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;
}
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;
}
// 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()
{
@@ -657,160 +583,71 @@ bool wxMask::Create(const wxBitmap& bitmap, const wxColour& colour)
return TRUE;
}
/*
* wxBitmapHandler
*/
// ----------------------------------------------------------------------------
// wxBitmapHandler
// ----------------------------------------------------------------------------
IMPLEMENT_DYNAMIC_CLASS(wxBitmapHandler, wxObject)
bool wxBitmapHandler::Create(wxGDIImage *image,
void *data,
long flags,
int width, int height, int depth)
{
wxBitmap *bitmap = wxDynamicCast(image, wxBitmap);
bool wxBitmapHandler::Create(wxBitmap *WXUNUSED(bitmap), void *WXUNUSED(data), long WXUNUSED(type), int WXUNUSED(width), int WXUNUSED(height), int WXUNUSED(depth))
return bitmap ? Create(bitmap, data, width, height, depth) : FALSE;
}
bool wxBitmapHandler::Load(wxGDIImage *image,
const wxString& name,
long flags,
int width, int height)
{
wxBitmap *bitmap = wxDynamicCast(image, wxBitmap);
return bitmap ? LoadFile(bitmap, name, flags, width, height) : FALSE;
}
bool wxBitmapHandler::Save(wxGDIImage *image,
const wxString& name,
int type)
{
wxBitmap *bitmap = wxDynamicCast(image, wxBitmap);
return bitmap ? SaveFile(bitmap, name, type) : FALSE;
}
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))
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))
bool wxBitmapHandler::SaveFile(wxBitmap *WXUNUSED(bitmap),
const wxString& WXUNUSED(name),
int WXUNUSED(type),
const wxPalette *WXUNUSED(palette))
{
return FALSE;
}
/*
* Standard handlers
*/
// ----------------------------------------------------------------------------
// DIB functions
// ----------------------------------------------------------------------------
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)
{
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)) )
{
}
return TRUE;
}
// it's probably not found
wxLogError(wxT("Can't load bitmap '%s' from resources! Check .rc file."), name.c_str());
return FALSE;
}
class WXDLLEXPORT wxBMPFileHandler: public wxBitmapHandler
{
DECLARE_DYNAMIC_CLASS(wxBMPFileHandler)
public:
inline wxBMPFileHandler()
{
m_name = "Windows bitmap file";
m_extension = "bmp";
m_type = wxBITMAP_TYPE_BMP;
};
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)
bool wxBMPFileHandler::LoadFile(wxBitmap *bitmap, const wxString& name, long WXUNUSED(flags),
int WXUNUSED(desiredWidth), int WXUNUSED(desiredHeight))
{
#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
}
bool wxBMPFileHandler::SaveFile(wxBitmap *bitmap, const wxString& name, int WXUNUSED(type), const wxPalette *pal)
{
#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
}
void wxBitmap::CleanUpHandlers()
{
wxNode *node = sm_handlers.First();
while ( node )
{
wxBitmapHandler *handler = (wxBitmapHandler *)node->Data();
wxNode *next = node->Next();
delete handler;
delete node;
node = next;
}
}
void wxBitmap::InitStandardHandlers()
{
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);
}
static long createDIB(long xSize, long ySize, long bitsPerPixel,
bool wxCreateDIB(long xSize, long ySize, long bitsPerPixel,
HPALETTE hPal, LPBITMAPINFO* lpDIBHeader)
{
unsigned long i, headerSize;
@@ -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);
}

View File

@@ -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;
}