X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/7c78e7c70271608b076b1dbed201b1204e6898d4..b1683d38998df9b7a03486ec11bfc46833de91c5:/src/qt/bitmap.cpp?ds=inline diff --git a/src/qt/bitmap.cpp b/src/qt/bitmap.cpp index 4d1738355a..1e6255f551 100644 --- a/src/qt/bitmap.cpp +++ b/src/qt/bitmap.cpp @@ -1,237 +1,430 @@ ///////////////////////////////////////////////////////////////////////////// // Name: bitmap.cpp -// Purpose: -// Author: Robert Roebling -// Created: 01/02/97 +// Purpose: wxBitmap +// Author: AUTHOR +// Modified by: +// Created: ??/??/98 // RCS-ID: $Id$ -// Copyright: (c) 1998 Robert Roebling, Julian Smart and Markus Holzem -// Licence: wxWindows licence +// Copyright: (c) AUTHOR +// Licence: wxWindows licence ///////////////////////////////////////////////////////////////////////////// #ifdef __GNUG__ #pragma implementation "bitmap.h" #endif +#include "wx/setup.h" +#include "wx/utils.h" +#include "wx/palette.h" #include "wx/bitmap.h" +#include "wx/icon.h" +#include "wx/log.h" +#if !USE_SHARED_LIBRARIES +IMPLEMENT_DYNAMIC_CLASS(wxBitmap, wxGDIObject) +IMPLEMENT_DYNAMIC_CLASS(wxMask, wxObject) +#endif + +wxBitmapRefData::wxBitmapRefData() +{ + m_ok = FALSE; + m_width = 0; + m_height = 0; + m_depth = 0; + m_quality = 0; + m_numColors = 0; + m_bitmapMask = NULL; +} -//----------------------------------------------------------------------------- -// wxMask -//----------------------------------------------------------------------------- +wxBitmapRefData::~wxBitmapRefData() +{ + /* + * TODO: delete the bitmap data here. + */ + + if (m_bitmapMask) + delete m_bitmapMask; + m_bitmapMask = NULL; +} -IMPLEMENT_DYNAMIC_CLASS(wxMask,wxObject) +wxList wxBitmap::sm_handlers; -wxMask::wxMask(void) +wxBitmap::wxBitmap() { -}; + m_refData = NULL; -wxMask::wxMask( const wxBitmap& WXUNUSED(bitmap), const wxColour& WXUNUSED(colour) ) + if ( wxTheBitmapList ) + wxTheBitmapList->AddBitmap(this); +} + +wxBitmap::~wxBitmap() { -}; + if (wxTheBitmapList) + wxTheBitmapList->DeleteObject(this); +} -wxMask::wxMask( const wxBitmap& WXUNUSED(bitmap), int WXUNUSED(paletteIndex) ) +wxBitmap::wxBitmap(const char bits[], int the_width, int the_height, int no_bits) { -}; + m_refData = new wxBitmapRefData; + + M_BITMAPDATA->m_width = the_width ; + M_BITMAPDATA->m_height = the_height ; + M_BITMAPDATA->m_depth = no_bits ; + M_BITMAPDATA->m_numColors = 0; -wxMask::wxMask( const wxBitmap& WXUNUSED(bitmap) ) + /* TODO: create the bitmap from data */ + + if ( wxTheBitmapList ) + wxTheBitmapList->AddBitmap(this); +} + +wxBitmap::wxBitmap(int w, int h, int d) { -}; + (void)Create(w, h, d); + + if ( wxTheBitmapList ) + wxTheBitmapList->AddBitmap(this); +} -wxMask::~wxMask(void) +wxBitmap::wxBitmap(void *data, long type, int width, int height, int depth) { -}; + (void) Create(data, type, width, height, depth); -//----------------------------------------------------------------------------- -// wxBitmap -//----------------------------------------------------------------------------- - -class wxBitmapRefData: public wxObjectRefData -{ - public: - - wxBitmapRefData(void); - ~wxBitmapRefData(void); - - wxMask *m_mask; - int m_width; - int m_height; - int m_bpp; - wxPalette *m_palette; -}; + if ( wxTheBitmapList ) + wxTheBitmapList->AddBitmap(this); +} -wxBitmapRefData::wxBitmapRefData(void) +wxBitmap::wxBitmap(const wxString& filename, long type) { - m_mask = NULL; - m_width = 0; - m_height = 0; - m_bpp = 0; - m_palette = NULL; -}; + LoadFile(filename, (int)type); -wxBitmapRefData::~wxBitmapRefData(void) + if ( wxTheBitmapList ) + wxTheBitmapList->AddBitmap(this); +} + +/* TODO: maybe allow creation from XPM +// Create from data +wxBitmap::wxBitmap(const char **data) { - if (m_mask) delete m_mask; - if (m_palette) delete m_palette; -}; + (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; -#define M_BMPDATA ((wxBitmapRefData *)m_refData) + /* TODO: create new bitmap */ -IMPLEMENT_DYNAMIC_CLASS(wxBitmap,wxGDIObject) + return M_BITMAPDATA->m_ok; +} -wxBitmap::wxBitmap(void) +bool wxBitmap::LoadFile(const wxString& filename, long type) { - if (wxTheBitmapList) wxTheBitmapList->AddBitmap(this); -}; - -wxBitmap::wxBitmap( int width, int height, int depth ) -{ - m_refData = new wxBitmapRefData(); - M_BMPDATA->m_mask = NULL; - M_BMPDATA->m_width = width; - M_BMPDATA->m_height = height; - M_BMPDATA->m_bpp = depth; - - if (wxTheBitmapList) wxTheBitmapList->AddBitmap(this); -}; + 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); +} -wxBitmap::wxBitmap( char **WXUNUSED(bits) ) +bool wxBitmap::Create(void *data, long type, int width, int height, int depth) { - m_refData = new wxBitmapRefData(); + UnRef(); - if (wxTheBitmapList) wxTheBitmapList->AddBitmap(this); -}; - -wxBitmap::wxBitmap( const wxBitmap& bmp ) + 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, int type, const wxPalette *palette) { - Ref( bmp ); - - if (wxTheBitmapList) wxTheBitmapList->AddBitmap(this); -}; - -wxBitmap::wxBitmap( const wxBitmap* bmp ) + 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) { - if (bmp) Ref( *bmp ); - - if (wxTheBitmapList) wxTheBitmapList->AddBitmap(this); -}; + if (!M_BITMAPDATA) + m_refData = new wxBitmapRefData; -wxBitmap::wxBitmap( const wxString &filename, int type ) + M_BITMAPDATA->m_width = w; +} + +void wxBitmap::SetHeight(int h) { - LoadFile( filename, type ); -}; + if (!M_BITMAPDATA) + m_refData = new wxBitmapRefData; + + M_BITMAPDATA->m_height = h; +} -wxBitmap::wxBitmap( const char WXUNUSED(bits)[], int width, int height, int WXUNUSED(depth)) +void wxBitmap::SetDepth(int d) { - m_refData = new wxBitmapRefData(); + if (!M_BITMAPDATA) + m_refData = new wxBitmapRefData; - M_BMPDATA->m_mask = NULL; - M_BMPDATA->m_width = width; - M_BMPDATA->m_height = height; - M_BMPDATA->m_bpp = 1; + M_BITMAPDATA->m_depth = d; +} + +void wxBitmap::SetQuality(int q) +{ + if (!M_BITMAPDATA) + m_refData = new wxBitmapRefData; - if (wxTheBitmapList) wxTheBitmapList->AddBitmap(this); + M_BITMAPDATA->m_quality = q; } - -wxBitmap::~wxBitmap(void) + +void wxBitmap::SetOk(bool isOk) { - if (wxTheBitmapList) wxTheBitmapList->DeleteObject(this); -}; - -wxBitmap& wxBitmap::operator = ( const wxBitmap& bmp ) + if (!M_BITMAPDATA) + m_refData = new wxBitmapRefData; + + M_BITMAPDATA->m_ok = isOk; +} + +void wxBitmap::SetPalette(const wxPalette& palette) { - if (*this == bmp) return (*this); - Ref( bmp ); - return *this; -}; - -bool wxBitmap::operator == ( const wxBitmap& bmp ) + if (!M_BITMAPDATA) + m_refData = new wxBitmapRefData; + + M_BITMAPDATA->m_bitmapPalette = palette ; +} + +void wxBitmap::SetMask(wxMask *mask) { - return m_refData == bmp.m_refData; -}; - -bool wxBitmap::operator != ( const wxBitmap& bmp ) + if (!M_BITMAPDATA) + m_refData = new wxBitmapRefData; + + M_BITMAPDATA->m_bitmapMask = mask ; +} + +void wxBitmap::AddHandler(wxBitmapHandler *handler) { - return m_refData != bmp.m_refData; -}; - -bool wxBitmap::Ok(void) const + sm_handlers.Append(handler); +} + +void wxBitmap::InsertHandler(wxBitmapHandler *handler) { - return m_refData != NULL; -}; - -int wxBitmap::GetHeight(void) const + sm_handlers.Insert(handler); +} + +bool wxBitmap::RemoveHandler(const wxString& name) { - if (!Ok()) return 0; - return M_BMPDATA->m_height; -}; + 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() == name ) + return handler; + node = node->Next(); + } + return NULL; +} -int wxBitmap::GetWidth(void) const +wxBitmapHandler *wxBitmap::FindHandler(const wxString& extension, long bitmapType) +{ + wxNode *node = sm_handlers.First(); + while ( node ) + { + wxBitmapHandler *handler = (wxBitmapHandler *)node->Data(); + if ( handler->GetExtension() == extension && + (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; +} + +/* + * wxMask + */ + +wxMask::wxMask() { - if (!Ok()) return 0; - return M_BMPDATA->m_width; -}; +/* TODO + m_maskBitmap = 0; +*/ +} -int wxBitmap::GetDepth(void) const +// Construct a mask from a bitmap and a colour indicating +// the transparent area +wxMask::wxMask(const wxBitmap& bitmap, const wxColour& colour) { - if (!Ok()) return 0; - return M_BMPDATA->m_bpp; -}; +/* TODO + m_maskBitmap = 0; +*/ + Create(bitmap, colour); +} -void wxBitmap::SetHeight( int height ) +// Construct a mask from a bitmap and a palette index indicating +// the transparent area +wxMask::wxMask(const wxBitmap& bitmap, int paletteIndex) { - if (!Ok()) return; - M_BMPDATA->m_height = height; -}; +/* TODO + m_maskBitmap = 0; +*/ + + Create(bitmap, paletteIndex); +} -void wxBitmap::SetWidth( int width ) +// Construct a mask from a mono bitmap (copies the bitmap). +wxMask::wxMask(const wxBitmap& bitmap) { - if (!Ok()) return; - M_BMPDATA->m_width = width; -}; +/* TODO + m_maskBitmap = 0; +*/ + + Create(bitmap); +} -void wxBitmap::SetDepth( int depth ) +wxMask::~wxMask() { - if (!Ok()) return; - M_BMPDATA->m_bpp = depth; -}; +// TODO: delete mask bitmap +} -wxMask *wxBitmap::GetMask(void) const +// Create a mask from a mono bitmap (copies the bitmap). +bool wxMask::Create(const wxBitmap& bitmap) { - if (!Ok()) return NULL; - - return M_BMPDATA->m_mask; -}; +// TODO + return FALSE; +} -void wxBitmap::SetMask( wxMask *mask ) +// Create a mask from a bitmap and a palette index indicating +// the transparent area +bool wxMask::Create(const wxBitmap& bitmap, int paletteIndex) { - if (!Ok()) return; - - if (M_BMPDATA->m_mask) delete M_BMPDATA->m_mask; - M_BMPDATA->m_mask = mask; -}; +// TODO + return FALSE; +} -void wxBitmap::Resize( int WXUNUSED(height), int WXUNUSED(width) ) +// Create a mask from a bitmap and a colour indicating +// the transparent area +bool wxMask::Create(const wxBitmap& bitmap, const wxColour& colour) { - if (!Ok()) return; - -}; +// TODO + return FALSE; +} -bool wxBitmap::SaveFile( const wxString &WXUNUSED(name), int WXUNUSED(type), - wxPalette *WXUNUSED(palette) ) +/* + * wxBitmapHandler + */ + +IMPLEMENT_DYNAMIC_CLASS(wxBitmapHandler, wxObject) + +bool wxBitmapHandler::Create(wxBitmap *bitmap, void *data, long type, int width, int height, int depth) { - return FALSE; -}; + return FALSE; +} -bool wxBitmap::LoadFile( const wxString &WXUNUSED(name), int WXUNUSED(type) ) +bool wxBitmapHandler::LoadFile(wxBitmap *bitmap, const wxString& name, long type, + int desiredWidth, int desiredHeight) { - return FALSE; -}; - -wxPalette *wxBitmap::GetPalette(void) const + return FALSE; +} + +bool wxBitmapHandler::SaveFile(wxBitmap *bitmap, const wxString& name, int type, const wxPalette *palette) { - if (!Ok()) return NULL; - return M_BMPDATA->m_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::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() +{ +/* 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); +*/ +}