wxCocoa: Added preliminary wxBitmap support
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@22188 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -1,37 +1,35 @@
|
|||||||
/////////////////////////////////////////////////////////////////////////////
|
/////////////////////////////////////////////////////////////////////////////
|
||||||
// Name: bitmap.h
|
// Name: include/wx/cocoa/bitmap.h
|
||||||
// Purpose: wxBitmap class
|
// Purpose: wxBitmap class
|
||||||
// Author: AUTHOR
|
// Author: David Elliott
|
||||||
// Modified by:
|
// Modified by:
|
||||||
// Created: ??/??/98
|
// Created: 2003/07/19
|
||||||
// RCS-ID: $Id$
|
// RCS-ID: $Id$
|
||||||
// Copyright: (c) AUTHOR
|
// Copyright: (c) 2003 David Elliott
|
||||||
// Licence: wxWindows licence
|
// Licence: wxWindows licence
|
||||||
/////////////////////////////////////////////////////////////////////////////
|
/////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
#ifndef _WX_BITMAP_H_
|
#ifndef __WX_COCOA_BITMAP_H__
|
||||||
#define _WX_BITMAP_H_
|
#define __WX_COCOA_BITMAP_H__
|
||||||
|
|
||||||
#if defined(__GNUG__) && !defined(__APPLE__)
|
|
||||||
#pragma interface "bitmap.h"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#include "wx/palette.h"
|
#include "wx/palette.h"
|
||||||
|
|
||||||
// Bitmap
|
// Bitmap
|
||||||
class WXDLLEXPORT wxBitmap;
|
class WXDLLEXPORT wxBitmap;
|
||||||
class WXDLLEXPORT wxBitmapHandler;
|
|
||||||
class WXDLLEXPORT wxIcon;
|
class WXDLLEXPORT wxIcon;
|
||||||
class WXDLLEXPORT wxCursor;
|
class WXDLLEXPORT wxCursor;
|
||||||
class WXDLLEXPORT wxImage;
|
class WXDLLEXPORT wxImage;
|
||||||
|
|
||||||
|
// ========================================================================
|
||||||
|
// wxMask
|
||||||
|
// ========================================================================
|
||||||
|
/* DFE: wxMask is not implemented yet */
|
||||||
|
|
||||||
// A mask is a mono bitmap used for drawing bitmaps
|
// A mask is a mono bitmap used for drawing bitmaps
|
||||||
// transparently.
|
// transparently.
|
||||||
class WXDLLEXPORT wxMask: public wxObject
|
class WXDLLEXPORT wxMask: public wxObject
|
||||||
{
|
{
|
||||||
DECLARE_DYNAMIC_CLASS(wxMask)
|
DECLARE_DYNAMIC_CLASS(wxMask)
|
||||||
DECLARE_NO_COPY_CLASS(wxMask)
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
wxMask();
|
wxMask();
|
||||||
|
|
||||||
@@ -59,143 +57,96 @@ protected:
|
|||||||
// WXHBITMAP m_maskBitmap;
|
// WXHBITMAP m_maskBitmap;
|
||||||
};
|
};
|
||||||
|
|
||||||
class WXDLLEXPORT wxBitmapRefData: public wxGDIRefData
|
// ========================================================================
|
||||||
|
// wxBitmap
|
||||||
|
// ========================================================================
|
||||||
|
class WXDLLEXPORT wxBitmap: public wxGDIObject
|
||||||
{
|
{
|
||||||
DECLARE_NO_COPY_CLASS(wxBitmapRefData)
|
DECLARE_DYNAMIC_CLASS(wxBitmap)
|
||||||
|
// ------------------------------------------------------------------------
|
||||||
friend class WXDLLEXPORT wxBitmap;
|
// initialization
|
||||||
friend class WXDLLEXPORT wxIcon;
|
// ------------------------------------------------------------------------
|
||||||
friend class WXDLLEXPORT wxCursor;
|
|
||||||
public:
|
public:
|
||||||
wxBitmapRefData();
|
// Platform-specific default constructor
|
||||||
~wxBitmapRefData();
|
wxBitmap();
|
||||||
|
// Copy constructors
|
||||||
|
wxBitmap(const wxBitmap& bitmap)
|
||||||
|
: wxGDIObject()
|
||||||
|
{ Ref(bitmap); }
|
||||||
|
// Initialize with raw data.
|
||||||
|
wxBitmap(const char bits[], int width, int height, int depth = 1);
|
||||||
|
// Initialize with XPM data
|
||||||
|
wxBitmap(const char **bits) { CreateFromXpm(bits); }
|
||||||
|
wxBitmap(char **bits) { CreateFromXpm((const char**)bits); }
|
||||||
|
// Load a file or resource
|
||||||
|
wxBitmap(const wxString& name, wxBitmapType type = wxBITMAP_TYPE_BMP_RESOURCE);
|
||||||
|
// Constructor for generalised creation from data
|
||||||
|
wxBitmap(void *data, wxBitmapType type, int width, int height, int depth = 1);
|
||||||
|
// If depth is omitted, will create a bitmap compatible with the display
|
||||||
|
wxBitmap(int width, int height, int depth = -1);
|
||||||
|
// Convert from wxImage:
|
||||||
|
wxBitmap(const wxImage& image, int depth = -1)
|
||||||
|
{ CreateFromImage(image, depth); }
|
||||||
|
// destructor
|
||||||
|
~wxBitmap();
|
||||||
|
|
||||||
|
// ------------------------------------------------------------------------
|
||||||
|
// Implementation
|
||||||
|
// ------------------------------------------------------------------------
|
||||||
public:
|
public:
|
||||||
int m_width;
|
// Initialize with XPM data
|
||||||
int m_height;
|
bool CreateFromXpm(const char **bits);
|
||||||
int m_depth;
|
// Initialize from wxImage
|
||||||
bool m_ok;
|
bool CreateFromImage(const wxImage& image, int depth=-1);
|
||||||
int m_numColors;
|
|
||||||
wxPalette m_bitmapPalette;
|
|
||||||
int m_quality;
|
|
||||||
|
|
||||||
// TOTO: platofmr specific hBitmap
|
virtual bool Create(int width, int height, int depth = -1);
|
||||||
// WXHBITMAP m_hBitmap;
|
virtual bool Create(void *data, wxBitmapType type, int width, int height, int depth = 1);
|
||||||
wxMask * m_bitmapMask; // Optional mask
|
virtual bool LoadFile(const wxString& name, wxBitmapType type = wxBITMAP_TYPE_BMP_RESOURCE);
|
||||||
|
virtual bool SaveFile(const wxString& name, wxBitmapType type, const wxPalette *cmap = NULL) const;
|
||||||
|
|
||||||
|
// copies the contents and mask of the given (colour) icon to the bitmap
|
||||||
|
virtual bool CopyFromIcon(const wxIcon& icon);
|
||||||
|
|
||||||
|
wxImage ConvertToImage() const;
|
||||||
|
|
||||||
|
// get the given part of bitmap
|
||||||
|
wxBitmap GetSubBitmap( const wxRect& rect ) const;
|
||||||
|
|
||||||
|
bool Ok() const;
|
||||||
|
int GetWidth() const;
|
||||||
|
int GetHeight() const;
|
||||||
|
int GetDepth() const;
|
||||||
|
int GetQuality() const;
|
||||||
|
void SetWidth(int w);
|
||||||
|
void SetHeight(int h);
|
||||||
|
void SetDepth(int d);
|
||||||
|
void SetQuality(int q);
|
||||||
|
void SetOk(bool isOk);
|
||||||
|
|
||||||
|
wxPalette* GetPalette() const;
|
||||||
|
void SetPalette(const wxPalette& palette);
|
||||||
|
|
||||||
|
wxMask *GetMask() const;
|
||||||
|
void SetMask(wxMask *mask) ;
|
||||||
|
|
||||||
|
int GetBitmapType() const;
|
||||||
|
|
||||||
|
inline wxBitmap& operator = (const wxBitmap& bitmap)
|
||||||
|
{ if (*this == bitmap) return (*this); Ref(bitmap); return *this; }
|
||||||
|
inline bool operator == (const wxBitmap& bitmap) const
|
||||||
|
{ return m_refData == bitmap.m_refData; }
|
||||||
|
inline bool operator != (const wxBitmap& bitmap) const
|
||||||
|
{ return m_refData != bitmap.m_refData; }
|
||||||
|
|
||||||
|
// wxObjectRefData
|
||||||
|
wxObjectRefData *CreateRefData() const;
|
||||||
|
wxObjectRefData *CloneRefData(const wxObjectRefData *data) const;
|
||||||
|
|
||||||
|
// wxCocoa
|
||||||
|
WX_NSBitmapImageRep GetNSBitmapImageRep();
|
||||||
|
|
||||||
|
static void InitStandardHandlers() { }
|
||||||
|
static void CleanUpHandlers() { }
|
||||||
};
|
};
|
||||||
|
|
||||||
#define M_BITMAPDATA ((wxBitmapRefData *)m_refData)
|
#endif // __WX_COCOA_BITMAP_H__
|
||||||
|
|
||||||
class WXDLLEXPORT wxBitmapHandler: public wxBitmapHandlerBase
|
|
||||||
{
|
|
||||||
DECLARE_DYNAMIC_CLASS(wxBitmapHandler)
|
|
||||||
public:
|
|
||||||
wxBitmapHandler() : m_name(), m_extension(), m_type(0) { }
|
|
||||||
virtual ~wxBitmapHandler();
|
|
||||||
|
|
||||||
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(const 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 wxBitmapBase
|
|
||||||
{
|
|
||||||
DECLARE_DYNAMIC_CLASS(wxBitmap)
|
|
||||||
|
|
||||||
friend class WXDLLEXPORT wxBitmapHandler;
|
|
||||||
|
|
||||||
public:
|
|
||||||
wxBitmap(); // Platform-specific
|
|
||||||
|
|
||||||
// Copy constructors
|
|
||||||
wxBitmap(const wxBitmap& bitmap)
|
|
||||||
: wxBitmapBase()
|
|
||||||
{ Ref(bitmap); }
|
|
||||||
|
|
||||||
// Initialize with raw data.
|
|
||||||
wxBitmap(const char bits[], int width, int height, int depth = 1);
|
|
||||||
|
|
||||||
// Initialize with XPM data
|
|
||||||
bool CreateFromXpm(const char **bits);
|
|
||||||
wxBitmap(const char **bits) { CreateFromXpm(bits); }
|
|
||||||
wxBitmap(char **bits);
|
|
||||||
|
|
||||||
// Load a file or resource
|
|
||||||
wxBitmap(const wxString& name, wxBitmapType type = wxBITMAP_TYPE_BMP_RESOURCE);
|
|
||||||
|
|
||||||
// Constructor for generalised creation from data
|
|
||||||
wxBitmap(void *data, wxBitmapType type, int width, int height, int depth = 1);
|
|
||||||
|
|
||||||
// If depth is omitted, will create a bitmap compatible with the display
|
|
||||||
wxBitmap(int width, int height, int depth = -1);
|
|
||||||
|
|
||||||
// Convert from wxImage:
|
|
||||||
wxBitmap(const wxImage& image, int depth = -1);
|
|
||||||
|
|
||||||
~wxBitmap();
|
|
||||||
|
|
||||||
wxImage ConvertToImage() const;
|
|
||||||
|
|
||||||
// get the given part of bitmap
|
|
||||||
wxBitmap GetSubBitmap( const wxRect& rect ) const;
|
|
||||||
|
|
||||||
virtual bool Create(int width, int height, int depth = -1);
|
|
||||||
virtual bool Create(void *data, wxBitmapType type, int width, int height, int depth = 1);
|
|
||||||
virtual bool LoadFile(const wxString& name, wxBitmapType type = wxBITMAP_TYPE_BMP_RESOURCE);
|
|
||||||
virtual bool SaveFile(const wxString& name, wxBitmapType type, const wxPalette *cmap = NULL) const;
|
|
||||||
|
|
||||||
// copies the contents and mask of the given (colour) icon to the bitmap
|
|
||||||
virtual bool CopyFromIcon(const wxIcon& icon);
|
|
||||||
|
|
||||||
bool Ok() const;
|
|
||||||
int GetWidth() const;
|
|
||||||
int GetHeight() const;
|
|
||||||
int GetDepth() const;
|
|
||||||
int GetQuality() const;
|
|
||||||
void SetWidth(int w);
|
|
||||||
void SetHeight(int h);
|
|
||||||
void SetDepth(int d);
|
|
||||||
void SetQuality(int q);
|
|
||||||
void SetOk(bool isOk);
|
|
||||||
|
|
||||||
wxPalette* GetPalette() const;
|
|
||||||
void SetPalette(const wxPalette& palette);
|
|
||||||
|
|
||||||
wxMask *GetMask() const;
|
|
||||||
void SetMask(wxMask *mask) ;
|
|
||||||
|
|
||||||
int GetBitmapType() const;
|
|
||||||
|
|
||||||
inline wxBitmap& operator = (const wxBitmap& bitmap) { if (*this == bitmap) return (*this); Ref(bitmap); return *this; }
|
|
||||||
inline bool operator == (const wxBitmap& bitmap) const { return m_refData == bitmap.m_refData; }
|
|
||||||
inline bool operator != (const wxBitmap& bitmap) const { return m_refData != bitmap.m_refData; }
|
|
||||||
|
|
||||||
static void InitStandardHandlers();
|
|
||||||
protected:
|
|
||||||
|
|
||||||
// TODO: Implementation
|
|
||||||
public:
|
|
||||||
// void SetHBITMAP(WXHBITMAP bmp);
|
|
||||||
// WXHBITMAP GetHBITMAP() const;
|
|
||||||
|
|
||||||
// WXHMETAFILE GetPict() const;
|
|
||||||
|
|
||||||
bool FreeResource(bool force = FALSE);
|
|
||||||
};
|
|
||||||
#endif
|
|
||||||
// _WX_BITMAP_H_
|
|
||||||
|
@@ -1,18 +1,14 @@
|
|||||||
/////////////////////////////////////////////////////////////////////////////
|
/////////////////////////////////////////////////////////////////////////////
|
||||||
// Name: bitmap.cpp
|
// Name: src/cocoa/bitmap.cpp
|
||||||
// Purpose: wxBitmap
|
// Purpose: wxBitmap
|
||||||
// Author: AUTHOR
|
// Author: David Elliott
|
||||||
// Modified by:
|
// Modified by:
|
||||||
// Created: ??/??/98
|
// Created: 2003/07/19
|
||||||
// RCS-ID: $Id$
|
// RCS-ID: $Id$
|
||||||
// Copyright: (c) AUTHOR
|
// Copyright: (c) 2003 David Elliott
|
||||||
// Licence: wxWindows licence
|
// Licence: wxWindows licence
|
||||||
/////////////////////////////////////////////////////////////////////////////
|
/////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
#ifdef __GNUG__
|
|
||||||
#pragma implementation "bitmap.h"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#include "wx/setup.h"
|
#include "wx/setup.h"
|
||||||
#include "wx/utils.h"
|
#include "wx/utils.h"
|
||||||
#include "wx/palette.h"
|
#include "wx/palette.h"
|
||||||
@@ -20,11 +16,38 @@
|
|||||||
#include "wx/icon.h"
|
#include "wx/icon.h"
|
||||||
#include "wx/log.h"
|
#include "wx/log.h"
|
||||||
#include "wx/image.h"
|
#include "wx/image.h"
|
||||||
|
#include "wx/xpmdecod.h"
|
||||||
|
|
||||||
#if !USE_SHARED_LIBRARIES
|
#include "wx/cocoa/autorelease.h"
|
||||||
IMPLEMENT_DYNAMIC_CLASS(wxBitmap, wxGDIObject)
|
#include "wx/cocoa/string.h"
|
||||||
IMPLEMENT_DYNAMIC_CLASS(wxMask, wxObject)
|
|
||||||
#endif
|
#import <AppKit/NSBitmapImageRep.h>
|
||||||
|
#import <AppKit/NSGraphics.h>
|
||||||
|
|
||||||
|
// ========================================================================
|
||||||
|
// wxBitmapRefData
|
||||||
|
// ========================================================================
|
||||||
|
class wxBitmapRefData: public wxGDIRefData
|
||||||
|
{
|
||||||
|
friend class wxBitmap;
|
||||||
|
public:
|
||||||
|
wxBitmapRefData();
|
||||||
|
wxBitmapRefData( const wxBitmapRefData& data );
|
||||||
|
virtual ~wxBitmapRefData();
|
||||||
|
|
||||||
|
protected:
|
||||||
|
int m_width;
|
||||||
|
int m_height;
|
||||||
|
int m_depth;
|
||||||
|
bool m_ok;
|
||||||
|
int m_numColors;
|
||||||
|
wxPalette m_bitmapPalette;
|
||||||
|
int m_quality;
|
||||||
|
WX_NSBitmapImageRep m_cocoaNSBitmapImageRep;
|
||||||
|
wxMask *m_bitmapMask; // Optional mask
|
||||||
|
};
|
||||||
|
|
||||||
|
#define M_BITMAPDATA ((wxBitmapRefData *)m_refData)
|
||||||
|
|
||||||
wxBitmapRefData::wxBitmapRefData()
|
wxBitmapRefData::wxBitmapRefData()
|
||||||
{
|
{
|
||||||
@@ -34,20 +57,38 @@ wxBitmapRefData::wxBitmapRefData()
|
|||||||
m_depth = 0;
|
m_depth = 0;
|
||||||
m_quality = 0;
|
m_quality = 0;
|
||||||
m_numColors = 0;
|
m_numColors = 0;
|
||||||
|
m_cocoaNSBitmapImageRep = nil;
|
||||||
m_bitmapMask = NULL;
|
m_bitmapMask = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
wxBitmapRefData::wxBitmapRefData( const wxBitmapRefData& data)
|
||||||
|
{
|
||||||
|
m_width = data.m_width;
|
||||||
|
m_height = data.m_height;
|
||||||
|
m_depth = data.m_depth;
|
||||||
|
m_ok = data.m_ok;
|
||||||
|
m_numColors = data.m_numColors;
|
||||||
|
m_bitmapPalette = data.m_bitmapPalette;
|
||||||
|
m_quality = data.m_quality;
|
||||||
|
m_cocoaNSBitmapImageRep = data.m_cocoaNSBitmapImageRep;
|
||||||
|
[m_cocoaNSBitmapImageRep retain];
|
||||||
|
m_bitmapMask = data.m_bitmapMask?new wxMask(*data.m_bitmapMask):NULL;
|
||||||
|
}
|
||||||
|
|
||||||
wxBitmapRefData::~wxBitmapRefData()
|
wxBitmapRefData::~wxBitmapRefData()
|
||||||
{
|
{
|
||||||
/*
|
[m_cocoaNSBitmapImageRep release];
|
||||||
* TODO: delete the bitmap data here.
|
m_cocoaNSBitmapImageRep = NULL;
|
||||||
*/
|
|
||||||
|
|
||||||
if (m_bitmapMask)
|
delete m_bitmapMask;
|
||||||
delete m_bitmapMask;
|
|
||||||
m_bitmapMask = NULL;
|
m_bitmapMask = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ========================================================================
|
||||||
|
// wxBitmap
|
||||||
|
// ========================================================================
|
||||||
|
IMPLEMENT_DYNAMIC_CLASS(wxBitmap, wxGDIObject)
|
||||||
|
|
||||||
wxBitmap::wxBitmap()
|
wxBitmap::wxBitmap()
|
||||||
{
|
{
|
||||||
m_refData = NULL;
|
m_refData = NULL;
|
||||||
@@ -101,82 +142,21 @@ wxBitmap::wxBitmap(const wxString& filename, wxBitmapType type)
|
|||||||
wxTheBitmapList->AddBitmap(this);
|
wxTheBitmapList->AddBitmap(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
wxBitmap::wxBitmap(const wxImage& image, int depth)
|
wxObjectRefData *wxBitmap::CreateRefData() const
|
||||||
{
|
{
|
||||||
|
return new wxBitmapRefData;
|
||||||
}
|
}
|
||||||
|
|
||||||
wxBitmap::wxBitmap(char **bits)
|
wxObjectRefData *wxBitmap::CloneRefData(const wxObjectRefData *data) const
|
||||||
{
|
{
|
||||||
|
return new wxBitmapRefData(*(wxBitmapRefData*)data);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* TODO: maybe allow creation from XPM
|
WX_NSBitmapImageRep wxBitmap::GetNSBitmapImageRep()
|
||||||
// Create from data
|
|
||||||
wxBitmap::wxBitmap(const char **data)
|
|
||||||
{
|
{
|
||||||
(void) Create((void *)data, wxBITMAP_TYPE_XPM_DATA, 0, 0, 0);
|
if(!M_BITMAPDATA)
|
||||||
}
|
return NULL;
|
||||||
*/
|
return M_BITMAPDATA->m_cocoaNSBitmapImageRep;
|
||||||
|
|
||||||
bool wxBitmap::Create(int w, int h, int d)
|
|
||||||
{
|
|
||||||
UnRef();
|
|
||||||
|
|
||||||
m_refData = new wxBitmapRefData;
|
|
||||||
|
|
||||||
M_BITMAPDATA->m_width = w;
|
|
||||||
M_BITMAPDATA->m_height = h;
|
|
||||||
M_BITMAPDATA->m_depth = d;
|
|
||||||
|
|
||||||
/* TODO: create new bitmap */
|
|
||||||
|
|
||||||
return M_BITMAPDATA->m_ok;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool wxBitmap::LoadFile(const wxString& filename, wxBitmapType type)
|
|
||||||
{
|
|
||||||
UnRef();
|
|
||||||
|
|
||||||
m_refData = new wxBitmapRefData;
|
|
||||||
|
|
||||||
wxBitmapHandler *handler = FindHandler(type);
|
|
||||||
|
|
||||||
if ( handler == NULL ) {
|
|
||||||
wxLogWarning("no bitmap handler for type %d defined.", type);
|
|
||||||
|
|
||||||
return FALSE;
|
|
||||||
}
|
|
||||||
|
|
||||||
return handler->LoadFile(this, filename, type, -1, -1);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool wxBitmap::Create(void *data, wxBitmapType type, int width, int height, int depth)
|
|
||||||
{
|
|
||||||
UnRef();
|
|
||||||
|
|
||||||
m_refData = new wxBitmapRefData;
|
|
||||||
|
|
||||||
wxBitmapHandler *handler = FindHandler(type);
|
|
||||||
|
|
||||||
if ( handler == NULL ) {
|
|
||||||
wxLogWarning("no bitmap handler for type %d defined.", type);
|
|
||||||
|
|
||||||
return FALSE;
|
|
||||||
}
|
|
||||||
|
|
||||||
return handler->Create(this, data, type, width, height, depth);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool wxBitmap::SaveFile(const wxString& filename, wxBitmapType type, const wxPalette *palette) const
|
|
||||||
{
|
|
||||||
wxBitmapHandler *handler = FindHandler(type);
|
|
||||||
|
|
||||||
if ( handler == NULL ) {
|
|
||||||
wxLogWarning("no bitmap handler for type %d defined.", type);
|
|
||||||
|
|
||||||
return FALSE;
|
|
||||||
}
|
|
||||||
|
|
||||||
return handler->SaveFile(this, filename, type, palette);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void wxBitmap::SetWidth(int w)
|
void wxBitmap::SetWidth(int w)
|
||||||
@@ -235,9 +215,181 @@ void wxBitmap::SetMask(wxMask *mask)
|
|||||||
M_BITMAPDATA->m_bitmapMask = mask ;
|
M_BITMAPDATA->m_bitmapMask = mask ;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
bool wxBitmap::Ok() const
|
||||||
* wxMask
|
{
|
||||||
*/
|
return m_refData && M_BITMAPDATA->m_ok;
|
||||||
|
}
|
||||||
|
|
||||||
|
wxPalette* wxBitmap::GetPalette() const
|
||||||
|
{
|
||||||
|
if(!m_refData)
|
||||||
|
return NULL;
|
||||||
|
return &M_BITMAPDATA->m_bitmapPalette;
|
||||||
|
}
|
||||||
|
|
||||||
|
wxMask* wxBitmap::GetMask() const
|
||||||
|
{
|
||||||
|
if(!m_refData)
|
||||||
|
return NULL;
|
||||||
|
return M_BITMAPDATA->m_bitmapMask;
|
||||||
|
}
|
||||||
|
|
||||||
|
int wxBitmap::GetDepth() const
|
||||||
|
{
|
||||||
|
if(!m_refData)
|
||||||
|
return 0;
|
||||||
|
return M_BITMAPDATA->m_depth;
|
||||||
|
}
|
||||||
|
|
||||||
|
int wxBitmap::GetWidth() const
|
||||||
|
{
|
||||||
|
if(!m_refData)
|
||||||
|
return 0;
|
||||||
|
return M_BITMAPDATA->m_width;
|
||||||
|
}
|
||||||
|
|
||||||
|
int wxBitmap::GetHeight() const
|
||||||
|
{
|
||||||
|
if(!m_refData)
|
||||||
|
return 0;
|
||||||
|
return M_BITMAPDATA->m_height;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool wxBitmap::Create(int w, int h, int d)
|
||||||
|
{
|
||||||
|
UnRef();
|
||||||
|
|
||||||
|
m_refData = new wxBitmapRefData;
|
||||||
|
|
||||||
|
M_BITMAPDATA->m_width = w;
|
||||||
|
M_BITMAPDATA->m_height = h;
|
||||||
|
M_BITMAPDATA->m_depth = d;
|
||||||
|
|
||||||
|
/* TODO: create new bitmap */
|
||||||
|
|
||||||
|
return M_BITMAPDATA->m_ok;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool wxBitmap::LoadFile(const wxString& filename, wxBitmapType type)
|
||||||
|
{
|
||||||
|
wxAutoNSAutoreleasePool pool;
|
||||||
|
UnRef();
|
||||||
|
|
||||||
|
m_refData = new wxBitmapRefData;
|
||||||
|
|
||||||
|
NSBitmapImageRep *imageRep = [NSBitmapImageRep
|
||||||
|
imageRepWithContentsOfFile:wxNSStringWithWxString(filename)];
|
||||||
|
|
||||||
|
if(imageRep)
|
||||||
|
{
|
||||||
|
M_BITMAPDATA->m_width = [imageRep pixelsWide];
|
||||||
|
M_BITMAPDATA->m_height = [imageRep pixelsHigh];
|
||||||
|
M_BITMAPDATA->m_depth = 24; // FIXME
|
||||||
|
M_BITMAPDATA->m_ok = true;
|
||||||
|
M_BITMAPDATA->m_numColors = 0;
|
||||||
|
M_BITMAPDATA->m_quality = 0;
|
||||||
|
M_BITMAPDATA->m_cocoaNSBitmapImageRep = [imageRep retain];
|
||||||
|
M_BITMAPDATA->m_bitmapMask = NULL;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
wxImage image;
|
||||||
|
if(!image.LoadFile(filename,type))
|
||||||
|
return false;
|
||||||
|
if(!image.Ok())
|
||||||
|
return false;
|
||||||
|
*this = wxBitmap(image);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool wxBitmap::Create(void *data, wxBitmapType type, int width, int height, int depth)
|
||||||
|
{
|
||||||
|
UnRef();
|
||||||
|
|
||||||
|
m_refData = new wxBitmapRefData;
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool wxBitmap::SaveFile(const wxString& filename, wxBitmapType type, const wxPalette *palette) const
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool wxBitmap::CopyFromIcon(const wxIcon& icno)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
wxBitmap wxBitmap::GetSubBitmap(wxRect const&) const
|
||||||
|
{
|
||||||
|
return wxNullBitmap;
|
||||||
|
}
|
||||||
|
|
||||||
|
wxImage wxBitmap::ConvertToImage() const
|
||||||
|
{
|
||||||
|
if(!M_BITMAPDATA->m_ok)
|
||||||
|
return wxImage(5,5)/*wxNullImage*/;
|
||||||
|
return wxImage(M_BITMAPDATA->m_width,M_BITMAPDATA->m_height);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool wxBitmap::CreateFromXpm(const char **xpm)
|
||||||
|
{
|
||||||
|
#if wxUSE_IMAGE && wxUSE_XPM
|
||||||
|
UnRef();
|
||||||
|
|
||||||
|
wxCHECK_MSG( xpm, false, wxT("invalid XPM data") )
|
||||||
|
|
||||||
|
wxXPMDecoder decoder;
|
||||||
|
wxImage img = decoder.ReadData(xpm);
|
||||||
|
wxCHECK_MSG( img.Ok(), false, wxT("invalid XPM data") )
|
||||||
|
|
||||||
|
*this = wxBitmap(img);
|
||||||
|
return true;
|
||||||
|
#else
|
||||||
|
return false;
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
bool wxBitmap::CreateFromImage(const wxImage& image, int depth)
|
||||||
|
{
|
||||||
|
UnRef();
|
||||||
|
|
||||||
|
wxCHECK_MSG(image.Ok(), false, wxT("invalid image"));
|
||||||
|
wxCHECK_MSG(depth == -1 || depth == 1, false, wxT("invalid bitmap depth"));
|
||||||
|
|
||||||
|
m_refData = new wxBitmapRefData();
|
||||||
|
|
||||||
|
M_BITMAPDATA->m_width = image.GetWidth();
|
||||||
|
M_BITMAPDATA->m_height = image.GetHeight();
|
||||||
|
NSBitmapImageRep *bitmapImage = [[NSBitmapImageRep alloc]
|
||||||
|
initWithBitmapDataPlanes: NULL
|
||||||
|
pixelsWide: image.GetWidth()
|
||||||
|
pixelsHigh: image.GetHeight()
|
||||||
|
bitsPerSample: 8
|
||||||
|
samplesPerPixel: 3
|
||||||
|
hasAlpha: NO
|
||||||
|
isPlanar: NO
|
||||||
|
colorSpaceName: NSCalibratedRGBColorSpace
|
||||||
|
bytesPerRow: 0
|
||||||
|
bitsPerPixel: 0];
|
||||||
|
|
||||||
|
const int numBytes = image.GetWidth()*image.GetHeight()*3;
|
||||||
|
memcpy([bitmapImage bitmapData], image.GetData(), numBytes);
|
||||||
|
// TODO: Alpha and convert to desired depth
|
||||||
|
M_BITMAPDATA->m_depth = 24;
|
||||||
|
M_BITMAPDATA->m_ok = true;
|
||||||
|
M_BITMAPDATA->m_numColors = 0;
|
||||||
|
M_BITMAPDATA->m_quality = 0;
|
||||||
|
M_BITMAPDATA->m_cocoaNSBitmapImageRep = bitmapImage;
|
||||||
|
M_BITMAPDATA->m_bitmapMask = NULL;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// ========================================================================
|
||||||
|
// wxMask
|
||||||
|
// ========================================================================
|
||||||
|
|
||||||
|
IMPLEMENT_DYNAMIC_CLASS(wxMask, wxObject)
|
||||||
|
|
||||||
wxMask::wxMask()
|
wxMask::wxMask()
|
||||||
{
|
{
|
||||||
@@ -305,115 +457,3 @@ bool wxMask::Create(const wxBitmap& bitmap, const wxColour& colour)
|
|||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
* wxBitmapHandler
|
|
||||||
*/
|
|
||||||
|
|
||||||
IMPLEMENT_DYNAMIC_CLASS(wxBitmapHandler, wxObject)
|
|
||||||
|
|
||||||
wxBitmapHandler::~wxBitmapHandler()
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
bool wxBitmapHandler::Create(wxBitmap *bitmap, void *data, long type, int width, int height, int depth)
|
|
||||||
{
|
|
||||||
return FALSE;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool wxBitmapHandler::LoadFile(wxBitmap *bitmap, const wxString& name, long type,
|
|
||||||
int desiredWidth, int desiredHeight)
|
|
||||||
{
|
|
||||||
return FALSE;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool wxBitmapHandler::SaveFile(const wxBitmap *bitmap, const wxString& name, int type, const wxPalette *palette)
|
|
||||||
{
|
|
||||||
return FALSE;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Standard handlers
|
|
||||||
*/
|
|
||||||
|
|
||||||
/* TODO: bitmap handlers, a bit like this:
|
|
||||||
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)
|
|
||||||
*/
|
|
||||||
|
|
||||||
void wxBitmap::InitStandardHandlers()
|
|
||||||
{
|
|
||||||
/* TODO: initialize all standard bitmap or derive class handlers here.
|
|
||||||
AddHandler(new wxBMPResourceHandler);
|
|
||||||
AddHandler(new wxBMPFileHandler);
|
|
||||||
AddHandler(new wxXPMFileHandler);
|
|
||||||
AddHandler(new wxXPMDataHandler);
|
|
||||||
AddHandler(new wxICOResourceHandler);
|
|
||||||
AddHandler(new wxICOFileHandler);
|
|
||||||
*/
|
|
||||||
}
|
|
||||||
|
|
||||||
bool wxBitmap::CopyFromIcon(const wxIcon& icno)
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
wxPalette* wxBitmap::GetPalette() const
|
|
||||||
{
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
wxBitmap wxBitmap::GetSubBitmap(wxRect const&) const
|
|
||||||
{
|
|
||||||
return wxNullBitmap;
|
|
||||||
}
|
|
||||||
|
|
||||||
wxImage wxBitmap::ConvertToImage() const
|
|
||||||
{
|
|
||||||
return wxNullImage;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool wxBitmap::Ok() const
|
|
||||||
{
|
|
||||||
return FALSE;
|
|
||||||
}
|
|
||||||
|
|
||||||
wxMask* wxBitmap::GetMask() const
|
|
||||||
{
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
int wxBitmap::GetDepth() const
|
|
||||||
{
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
int wxBitmap::GetWidth() const
|
|
||||||
{
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
int wxBitmap::GetHeight() const
|
|
||||||
{
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
bool wxBitmap::CreateFromXpm(const char **)
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
// vim:sts=4:sw=4:syn=cpp:et
|
|
||||||
|
@@ -19,7 +19,7 @@
|
|||||||
#pragma hdrstop
|
#pragma hdrstop
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(__WXMGL__) || defined(__WXMAC__) || defined(__WXCOCOA__) \
|
#if defined(__WXMGL__) || defined(__WXMAC__) \
|
||||||
|| defined(__WXMOTIF__) || defined(__WXX11__)
|
|| defined(__WXMOTIF__) || defined(__WXX11__)
|
||||||
|
|
||||||
#include "wx/setup.h"
|
#include "wx/setup.h"
|
||||||
|
Reference in New Issue
Block a user