X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/7c78e7c70271608b076b1dbed201b1204e6898d4..79f585d90388128f9d245f7c92d3013b98b9ed14:/src/qt/bitmap.cpp?ds=sidebyside diff --git a/src/qt/bitmap.cpp b/src/qt/bitmap.cpp index 4d1738355a..d6f9fa87e3 100644 --- a/src/qt/bitmap.cpp +++ b/src/qt/bitmap.cpp @@ -1,237 +1,428 @@ ///////////////////////////////////////////////////////////////////////////// // 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" +IMPLEMENT_DYNAMIC_CLASS(wxBitmap, wxGDIObject) +IMPLEMENT_DYNAMIC_CLASS(wxMask, wxObject) -//----------------------------------------------------------------------------- -// wxMask -//----------------------------------------------------------------------------- +wxBitmapRefData::wxBitmapRefData() +{ + m_ok = FALSE; + m_width = 0; + m_height = 0; + m_depth = 0; + m_quality = 0; + m_numColors = 0; + m_bitmapMask = NULL; +} + +wxBitmapRefData::~wxBitmapRefData() +{ + /* + * TODO: delete the bitmap data here. + */ -IMPLEMENT_DYNAMIC_CLASS(wxMask,wxObject) + if (m_bitmapMask) + delete m_bitmapMask; + m_bitmapMask = NULL; +} + +wxList wxBitmap::sm_handlers; -wxMask::wxMask(void) +wxBitmap::wxBitmap() { -}; + m_refData = NULL; + + if ( wxTheBitmapList ) + wxTheBitmapList->AddBitmap(this); +} -wxMask::wxMask( const wxBitmap& WXUNUSED(bitmap), const wxColour& WXUNUSED(colour) ) +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; + + /* TODO: create the bitmap from data */ + + if ( wxTheBitmapList ) + wxTheBitmapList->AddBitmap(this); +} -wxMask::wxMask( const wxBitmap& WXUNUSED(bitmap) ) +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(); -#define M_BMPDATA ((wxBitmapRefData *)m_refData) + m_refData = new wxBitmapRefData; -IMPLEMENT_DYNAMIC_CLASS(wxBitmap,wxGDIObject) + M_BITMAPDATA->m_width = w; + M_BITMAPDATA->m_height = h; + M_BITMAPDATA->m_depth = d; + + /* TODO: create new bitmap */ + + 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; +} + +void wxBitmap::SetDepth(int d) +{ + if (!M_BITMAPDATA) + m_refData = new wxBitmapRefData; + + M_BITMAPDATA->m_depth = d; +} -wxBitmap::wxBitmap( const char WXUNUSED(bits)[], int width, int height, int WXUNUSED(depth)) +void wxBitmap::SetQuality(int q) { - m_refData = new wxBitmapRefData(); + if (!M_BITMAPDATA) + m_refData = new wxBitmapRefData; + + M_BITMAPDATA->m_quality = q; +} - M_BMPDATA->m_mask = NULL; - M_BMPDATA->m_width = width; - M_BMPDATA->m_height = height; - M_BMPDATA->m_bpp = 1; +void wxBitmap::SetOk(bool isOk) +{ + if (!M_BITMAPDATA) + m_refData = new wxBitmapRefData; - if (wxTheBitmapList) wxTheBitmapList->AddBitmap(this); + M_BITMAPDATA->m_ok = isOk; } - -wxBitmap::~wxBitmap(void) + +void wxBitmap::SetPalette(const wxPalette& palette) { - if (wxTheBitmapList) wxTheBitmapList->DeleteObject(this); -}; - -wxBitmap& wxBitmap::operator = ( const wxBitmap& bmp ) + if (!M_BITMAPDATA) + m_refData = new wxBitmapRefData; + + M_BITMAPDATA->m_bitmapPalette = palette ; +} + +void wxBitmap::SetMask(wxMask *mask) { - 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_bitmapMask = mask ; +} + +void wxBitmap::AddHandler(wxBitmapHandler *handler) { - return m_refData == bmp.m_refData; -}; - -bool wxBitmap::operator != ( const wxBitmap& bmp ) + sm_handlers.Append(handler); +} + +void wxBitmap::InsertHandler(wxBitmapHandler *handler) { - return m_refData != bmp.m_refData; -}; - -bool wxBitmap::Ok(void) const + sm_handlers.Insert(handler); +} + +bool wxBitmap::RemoveHandler(const wxString& name) { - return m_refData != NULL; -}; - -int wxBitmap::GetHeight(void) const + 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; +} + +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_height; -}; +/* TODO + m_maskBitmap = 0; +*/ +} -int wxBitmap::GetWidth(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_width; -}; +/* TODO + m_maskBitmap = 0; +*/ + Create(bitmap, colour); +} -int wxBitmap::GetDepth(void) const +// Construct a mask from a bitmap and a palette index indicating +// the transparent area +wxMask::wxMask(const wxBitmap& bitmap, int paletteIndex) { - if (!Ok()) return 0; - return M_BMPDATA->m_bpp; -}; +/* TODO + m_maskBitmap = 0; +*/ + + Create(bitmap, paletteIndex); +} -void wxBitmap::SetHeight( int height ) +// Construct a mask from a mono bitmap (copies the bitmap). +wxMask::wxMask(const wxBitmap& bitmap) { - if (!Ok()) return; - M_BMPDATA->m_height = height; -}; +/* TODO + m_maskBitmap = 0; +*/ + + Create(bitmap); +} -void wxBitmap::SetWidth( int width ) +wxMask::~wxMask() { - if (!Ok()) return; - M_BMPDATA->m_width = width; -}; +// TODO: delete mask bitmap +} -void wxBitmap::SetDepth( int depth ) +// Create a mask from a mono bitmap (copies the bitmap). +bool wxMask::Create(const wxBitmap& bitmap) { - if (!Ok()) return; - M_BMPDATA->m_bpp = depth; -}; +// TODO + return FALSE; +} -wxMask *wxBitmap::GetMask(void) const +// 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 NULL; - - return M_BMPDATA->m_mask; -}; +// TODO + return FALSE; +} -void wxBitmap::SetMask( wxMask *mask ) +// 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; - - if (M_BMPDATA->m_mask) delete M_BMPDATA->m_mask; - M_BMPDATA->m_mask = mask; -}; +// TODO + return FALSE; +} + +/* + * wxBitmapHandler + */ -void wxBitmap::Resize( int WXUNUSED(height), int WXUNUSED(width) ) +IMPLEMENT_DYNAMIC_CLASS(wxBitmapHandler, wxObject) + +bool wxBitmapHandler::Create(wxBitmap *bitmap, void *data, long type, int width, int height, int depth) { - if (!Ok()) return; - -}; + return FALSE; +} -bool wxBitmap::SaveFile( const wxString &WXUNUSED(name), int WXUNUSED(type), - wxPalette *WXUNUSED(palette) ) +bool wxBitmapHandler::LoadFile(wxBitmap *bitmap, const wxString& name, long type, + int desiredWidth, int desiredHeight) { - return FALSE; -}; + return FALSE; +} -bool wxBitmap::LoadFile( const wxString &WXUNUSED(name), int WXUNUSED(type) ) +bool wxBitmapHandler::SaveFile(wxBitmap *bitmap, const wxString& name, int type, const wxPalette *palette) { - return FALSE; -}; - -wxPalette *wxBitmap::GetPalette(void) const + return FALSE; +} + +/* + * Standard handlers + */ + +/* TODO: bitmap handlers, a bit like this: +class WXDLLEXPORT wxBMPResourceHandler: public wxBitmapHandler { - if (!Ok()) return NULL; - return M_BMPDATA->m_palette; + 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); +*/ +}