]> git.saurik.com Git - wxWidgets.git/commitdiff
wxCocoa: Added preliminary wxBitmap support
authorDavid Elliott <dfe@tgwbd.org>
Mon, 21 Jul 2003 00:27:32 +0000 (00:27 +0000)
committerDavid Elliott <dfe@tgwbd.org>
Mon, 21 Jul 2003 00:27:32 +0000 (00:27 +0000)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@22188 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

include/wx/cocoa/bitmap.h
src/cocoa/bitmap.mm
src/common/bmpbase.cpp

index 619011b7dafce750541ab1b99caa3635db8b354f..42a6f408c82e033a7a7f72b4b9b123fa621cc269 100644 (file)
@@ -1,37 +1,35 @@
 /////////////////////////////////////////////////////////////////////////////
-// Name:        bitmap.h
+// Name:        include/wx/cocoa/bitmap.h
 // Purpose:     wxBitmap class
-// Author:      AUTHOR
+// Author:      David Elliott
 // Modified by:
-// Created:     ??/??/98
+// Created:     2003/07/19
 // RCS-ID:      $Id$
-// Copyright:   (c) AUTHOR
+// Copyright:   (c) 2003 David Elliott
 // Licence:    wxWindows licence
 /////////////////////////////////////////////////////////////////////////////
 
-#ifndef _WX_BITMAP_H_
-#define _WX_BITMAP_H_
-
-#if defined(__GNUG__) && !defined(__APPLE__)
-  #pragma interface "bitmap.h"
-#endif
+#ifndef __WX_COCOA_BITMAP_H__
+#define __WX_COCOA_BITMAP_H__
 
 #include "wx/palette.h"
 
 // Bitmap
 class WXDLLEXPORT wxBitmap;
-class WXDLLEXPORT wxBitmapHandler;
 class WXDLLEXPORT wxIcon;
 class WXDLLEXPORT wxCursor;
 class WXDLLEXPORT wxImage;
 
+// ========================================================================
+// wxMask
+// ========================================================================
+/* DFE: wxMask is not implemented yet */
+
 // A mask is a mono bitmap used for drawing bitmaps
 // transparently.
 class WXDLLEXPORT wxMask: public wxObject
 {
     DECLARE_DYNAMIC_CLASS(wxMask)
-    DECLARE_NO_COPY_CLASS(wxMask)
-
 public:
   wxMask();
 
@@ -59,143 +57,96 @@ protected:
 //  WXHBITMAP m_maskBitmap;
 };
 
-class WXDLLEXPORT wxBitmapRefData: public wxGDIRefData
+// ========================================================================
+// wxBitmap
+// ========================================================================
+class WXDLLEXPORT wxBitmap: public wxGDIObject
 {
-    DECLARE_NO_COPY_CLASS(wxBitmapRefData)
-        
-    friend class WXDLLEXPORT wxBitmap;
-    friend class WXDLLEXPORT wxIcon;
-    friend class WXDLLEXPORT wxCursor;
-public:
-    wxBitmapRefData();
-    ~wxBitmapRefData();
-
-public:
-  int           m_width;
-  int           m_height;
-  int           m_depth;
-  bool          m_ok;
-  int           m_numColors;
-  wxPalette     m_bitmapPalette;
-  int           m_quality;
-
-  // TOTO: platofmr specific hBitmap
-//  WXHBITMAP     m_hBitmap;
-  wxMask *      m_bitmapMask; // Optional mask
-};
-
-#define M_BITMAPDATA ((wxBitmapRefData *)m_refData)
-
-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;
-
+    DECLARE_DYNAMIC_CLASS(wxBitmap)
+// ------------------------------------------------------------------------
+// initialization
+// ------------------------------------------------------------------------
 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);
+    // Platform-specific default constructor
+    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();
   
-  // 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
+// ------------------------------------------------------------------------
+// Implementation
+// ------------------------------------------------------------------------
 public:
-//  void SetHBITMAP(WXHBITMAP bmp);
-//  WXHBITMAP GetHBITMAP() const;
+    // Initialize with XPM data
+    bool CreateFromXpm(const char **bits);
+    // Initialize from wxImage
+    bool CreateFromImage(const wxImage& image, int depth=-1);
+
+    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);
+
+    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;
   
-//  WXHMETAFILE GetPict() const;
-
-  bool FreeResource(bool force = FALSE);
+    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() { }
 };
-#endif
-  // _WX_BITMAP_H_
+
+#endif // __WX_COCOA_BITMAP_H__
index ed803d80858aa4165c83fbc13a5d1b23e9e6ca6d..4d7bb3f22930e0fad2ad018b2356469f603d20ac 100644 (file)
@@ -1,18 +1,14 @@
 /////////////////////////////////////////////////////////////////////////////
-// Name:        bitmap.cpp
+// Name:        src/cocoa/bitmap.cpp
 // Purpose:     wxBitmap
-// Author:      AUTHOR
+// Author:      David Elliott
 // Modified by:
-// Created:     ??/??/98
+// Created:     2003/07/19
 // RCS-ID:      $Id$
-// Copyright:   (c) AUTHOR
+// Copyright:   (c) 2003 David Elliott
 // Licence:     wxWindows licence
 /////////////////////////////////////////////////////////////////////////////
 
-#ifdef __GNUG__
-#pragma implementation "bitmap.h"
-#endif
-
 #include "wx/setup.h"
 #include "wx/utils.h"
 #include "wx/palette.h"
 #include "wx/icon.h"
 #include "wx/log.h"
 #include "wx/image.h"
+#include "wx/xpmdecod.h"
 
-#if !USE_SHARED_LIBRARIES
-IMPLEMENT_DYNAMIC_CLASS(wxBitmap, wxGDIObject)
-IMPLEMENT_DYNAMIC_CLASS(wxMask, wxObject)
-#endif
+#include "wx/cocoa/autorelease.h"
+#include "wx/cocoa/string.h"
+
+#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()
 {
@@ -34,20 +57,38 @@ wxBitmapRefData::wxBitmapRefData()
     m_depth = 0;
     m_quality = 0;
     m_numColors = 0;
+    m_cocoaNSBitmapImageRep = nil;
     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()
 {
-    /*
-     * TODO: delete the bitmap data here.
-     */
+    [m_cocoaNSBitmapImageRep release];
+    m_cocoaNSBitmapImageRep = NULL;
 
-    if (m_bitmapMask)
-        delete m_bitmapMask;
+    delete m_bitmapMask;
     m_bitmapMask = NULL;
 }
 
+// ========================================================================
+// wxBitmap
+// ========================================================================
+IMPLEMENT_DYNAMIC_CLASS(wxBitmap, wxGDIObject)
+
 wxBitmap::wxBitmap()
 {
     m_refData = NULL;
@@ -101,82 +142,21 @@ wxBitmap::wxBitmap(const wxString& filename, wxBitmapType type)
         wxTheBitmapList->AddBitmap(this);
 }
 
-wxBitmap::wxBitmap(const wxImage& image, int depth)
-{
-}
-
-wxBitmap::wxBitmap(char **bits)
-{
-}
-
-/* TODO: maybe allow creation from XPM
-// Create from data
-wxBitmap::wxBitmap(const char **data)
+wxObjectRefData *wxBitmap::CreateRefData() const
 {
-    (void) Create((void *)data, wxBITMAP_TYPE_XPM_DATA, 0, 0, 0);
-}
-*/
-
-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;
+    return new wxBitmapRefData;
 }
 
-bool wxBitmap::LoadFile(const wxString& filename, wxBitmapType type)
+wxObjectRefData *wxBitmap::CloneRefData(const wxObjectRefData *data) const
 {
-    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);
+    return new wxBitmapRefData(*(wxBitmapRefData*)data);
 }
 
-bool wxBitmap::Create(void *data, wxBitmapType type, int width, int height, int depth)
+WX_NSBitmapImageRep wxBitmap::GetNSBitmapImageRep()
 {
-    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);
+    if(!M_BITMAPDATA)
+        return NULL;
+    return M_BITMAPDATA->m_cocoaNSBitmapImageRep;
 }
 
 void wxBitmap::SetWidth(int w)
@@ -235,185 +215,245 @@ void wxBitmap::SetMask(wxMask *mask)
     M_BITMAPDATA->m_bitmapMask = mask ;
 }
 
-/*
- * wxMask
- */
-
-wxMask::wxMask()
+bool wxBitmap::Ok() const
 {
-/* TODO
-    m_maskBitmap = 0;
-*/
+    return m_refData && M_BITMAPDATA->m_ok;
 }
 
-// Construct a mask from a bitmap and a colour indicating
-// the transparent area
-wxMask::wxMask(const wxBitmap& bitmap, const wxColour& colour)
+wxPalette* wxBitmap::GetPalette() const
 {
-/* TODO
-    m_maskBitmap = 0;
-*/
-    Create(bitmap, colour);
+    if(!m_refData)
+        return NULL;
+    return &M_BITMAPDATA->m_bitmapPalette;
 }
 
-// Construct a mask from a bitmap and a palette index indicating
-// the transparent area
-wxMask::wxMask(const wxBitmap& bitmap, int paletteIndex)
+wxMask* wxBitmap::GetMask() const
 {
-/* TODO
-    m_maskBitmap = 0;
-*/
-
-    Create(bitmap, paletteIndex);
+    if(!m_refData)
+        return NULL;
+    return M_BITMAPDATA->m_bitmapMask;
 }
 
-// Construct a mask from a mono bitmap (copies the bitmap).
-wxMask::wxMask(const wxBitmap& bitmap)
+int wxBitmap::GetDepth() const
 {
-/* TODO
-    m_maskBitmap = 0;
-*/
-
-    Create(bitmap);
+    if(!m_refData)
+        return 0;
+    return M_BITMAPDATA->m_depth;
 }
 
-wxMask::~wxMask()
+int wxBitmap::GetWidth() const
 {
-// TODO: delete mask bitmap
+    if(!m_refData)
+        return 0;
+    return M_BITMAPDATA->m_width;
 }
 
-// Create a mask from a mono bitmap (copies the bitmap).
-bool wxMask::Create(const wxBitmap& bitmap)
+int wxBitmap::GetHeight() const
 {
-// TODO
-    return FALSE;
+    if(!m_refData)
+        return 0;
+    return M_BITMAPDATA->m_height;
 }
 
-// Create a mask from a bitmap and a palette index indicating
-// the transparent area
-bool wxMask::Create(const wxBitmap& bitmap, int paletteIndex)
+bool wxBitmap::Create(int w, int h, int d)
 {
-// TODO
-    return FALSE;
+    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;
 }
 
-// Create a mask from a bitmap and a colour indicating
-// the transparent area
-bool wxMask::Create(const wxBitmap& bitmap, const wxColour& colour)
+bool wxBitmap::LoadFile(const wxString& filename, wxBitmapType type)
 {
-// TODO
-    return FALSE;
-}
+    wxAutoNSAutoreleasePool pool;
+    UnRef();
 
-/*
- * wxBitmapHandler
- */
+    m_refData = new wxBitmapRefData;
 
-IMPLEMENT_DYNAMIC_CLASS(wxBitmapHandler, wxObject)
+    NSBitmapImageRep *imageRep = [NSBitmapImageRep
+        imageRepWithContentsOfFile:wxNSStringWithWxString(filename)];
 
-wxBitmapHandler::~wxBitmapHandler()
-{
+    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 wxBitmapHandler::Create(wxBitmap *bitmap, void *data, long type, int width, int height, int depth)
+bool wxBitmap::Create(void *data, wxBitmapType type, int width, int height, int depth)
 {
-    return FALSE;
+    UnRef();
+
+    m_refData = new wxBitmapRefData;
+
+    return false;
 }
 
-bool wxBitmapHandler::LoadFile(wxBitmap *bitmap, const wxString& name, long type,
-        int desiredWidth, int desiredHeight)
+bool wxBitmap::SaveFile(const wxString& filename, wxBitmapType type, const wxPalette *palette) const
 {
-    return FALSE;
+    return false;
 }
 
-bool wxBitmapHandler::SaveFile(const wxBitmap *bitmap, const wxString& name, int type, const wxPalette *palette)
+bool wxBitmap::CopyFromIcon(const wxIcon& icno)
 {
-    return FALSE;
+    return false;
 }
 
-/*
- * Standard handlers
- */
-
-/* TODO: bitmap handlers, a bit like this:
-class WXDLLEXPORT wxBMPResourceHandler: public wxBitmapHandler
+wxBitmap wxBitmap::GetSubBitmap(wxRect const&) const
 {
-    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)
-*/
+    return wxNullBitmap;
+}
 
-void wxBitmap::InitStandardHandlers()
+wxImage wxBitmap::ConvertToImage() const
 {
-/* 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);
-*/
+    if(!M_BITMAPDATA->m_ok)
+        return wxImage(5,5)/*wxNullImage*/;
+    return wxImage(M_BITMAPDATA->m_width,M_BITMAPDATA->m_height);
 }
 
-bool wxBitmap::CopyFromIcon(const wxIcon& icno)
+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
 }
 
-wxPalette* wxBitmap::GetPalette() const
+bool wxBitmap::CreateFromImage(const wxImage& image, int depth)
 {
-    return NULL;
+    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;
 }
 
-wxBitmap wxBitmap::GetSubBitmap(wxRect const&) const
+// ========================================================================
+// wxMask
+// ========================================================================
+
+IMPLEMENT_DYNAMIC_CLASS(wxMask, wxObject)
+
+wxMask::wxMask()
 {
-    return wxNullBitmap;
+/* TODO
+    m_maskBitmap = 0;
+*/
 }
 
-wxImage wxBitmap::ConvertToImage() const
+// Construct a mask from a bitmap and a colour indicating
+// the transparent area
+wxMask::wxMask(const wxBitmap& bitmap, const wxColour& colour)
 {
-    return wxNullImage;
+/* TODO
+    m_maskBitmap = 0;
+*/
+    Create(bitmap, colour);
 }
 
-bool wxBitmap::Ok() const
+// Construct a mask from a bitmap and a palette index indicating
+// the transparent area
+wxMask::wxMask(const wxBitmap& bitmap, int paletteIndex)
 {
-    return FALSE;
+/* TODO
+    m_maskBitmap = 0;
+*/
+
+    Create(bitmap, paletteIndex);
 }
 
-wxMask* wxBitmap::GetMask() const
+// Construct a mask from a mono bitmap (copies the bitmap).
+wxMask::wxMask(const wxBitmap& bitmap)
 {
-    return NULL;
+/* TODO
+    m_maskBitmap = 0;
+*/
+
+    Create(bitmap);
 }
 
-int wxBitmap::GetDepth() const
+wxMask::~wxMask()
 {
-    return 0;
+// TODO: delete mask bitmap
 }
 
-int wxBitmap::GetWidth() const
+// Create a mask from a mono bitmap (copies the bitmap).
+bool wxMask::Create(const wxBitmap& bitmap)
 {
-    return 0;
+// TODO
+    return FALSE;
 }
 
-int wxBitmap::GetHeight() const
+// Create a mask from a bitmap and a palette index indicating
+// the transparent area
+bool wxMask::Create(const wxBitmap& bitmap, int paletteIndex)
 {
-    return 0;
+// TODO
+    return FALSE;
 }
 
-
-bool wxBitmap::CreateFromXpm(const char **)
+// Create a mask from a bitmap and a colour indicating
+// the transparent area
+bool wxMask::Create(const wxBitmap& bitmap, const wxColour& colour)
 {
-    return false;
+// TODO
+    return FALSE;
 }
 
-// vim:sts=4:sw=4:syn=cpp:et
index 6e007f98f4335d099dc1a59d6dbfe4f369963dc5..09d126126602e66ac14b80ad7b49e9adc4075954 100644 (file)
@@ -19,7 +19,7 @@
     #pragma hdrstop
 #endif
 
-#if defined(__WXMGL__) || defined(__WXMAC__) || defined(__WXCOCOA__) \
+#if defined(__WXMGL__) || defined(__WXMAC__) \
     || defined(__WXMOTIF__) || defined(__WXX11__)
 
 #include "wx/setup.h"