X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/31528cd3cac75558beef4bce0ba21fd182a808ab..50494a55ae4f0ec07a15b811dbcce5a8ae9fc7bc:/src/motif/bitmap.cpp diff --git a/src/motif/bitmap.cpp b/src/motif/bitmap.cpp index 58bc1cc259..76aa578d77 100644 --- a/src/motif/bitmap.cpp +++ b/src/motif/bitmap.cpp @@ -21,8 +21,15 @@ #include "wx/log.h" #include "wx/control.h" #include "wx/dcmemory.h" +#include "wx/image.h" +#ifdef __VMS__ +#pragma message disable nosimpint +#endif #include +#ifdef __VMS__ +#pragma message enable nosimpint +#endif #include "wx/motif/private.h" @@ -30,10 +37,8 @@ #include #endif -#if !USE_SHARED_LIBRARIES - IMPLEMENT_DYNAMIC_CLASS(wxBitmap, wxGDIObject) - IMPLEMENT_DYNAMIC_CLASS(wxMask, wxObject) -#endif +IMPLEMENT_DYNAMIC_CLASS(wxBitmap, wxGDIObject) +IMPLEMENT_DYNAMIC_CLASS(wxMask, wxObject) wxBitmapRefData::wxBitmapRefData() { @@ -103,6 +108,8 @@ wxBitmapRefData::~wxBitmapRefData() wxList wxBitmap::sm_handlers; +#define M_BMPDATA ((wxBitmapRefData *)m_refData) + wxBitmap::wxBitmap() { m_refData = NULL; @@ -163,6 +170,13 @@ wxBitmap::wxBitmap(char **data, wxControl* control) sg_Control = (wxControl*) NULL; } +bool wxBitmap::CreateFromXpm(const char **bits) +{ + wxCHECK_MSG( bits, FALSE, _T("NULL pointer in wxBitmap::CreateFromXpm") ); + + return Create(bits, wxBITMAP_TYPE_XPM_DATA, 0, 0, 0); +} + bool wxBitmap::Create(int w, int h, int d) { UnRef(); @@ -197,9 +211,14 @@ bool wxBitmap::LoadFile(const wxString& filename, long type) wxBitmapHandler *handler = FindHandler(type); if ( handler == NULL ) { - wxLogWarning("%s: no bitmap handler for type %d defined.", (const char*) filename, type); - - return FALSE; + wxImage image; + if (!image.LoadFile( filename, type )) return FALSE; + if (image.Ok()) + { + *this = image.ConvertToBitmap(); + return TRUE; + } + else return FALSE; } return handler->LoadFile(this, filename, type, -1, -1); @@ -226,10 +245,10 @@ bool wxBitmap::SaveFile(const wxString& filename, int type, const wxPalette *pal { wxBitmapHandler *handler = FindHandler(type); - if ( handler == NULL ) { - wxLogWarning("no bitmap handler for type %d defined.", type); - - return FALSE; + if ( handler == NULL ) { // try wxImage + wxImage image( *this ); + if (image.Ok()) return image.SaveFile( filename, type ); + else return FALSE; } return handler->SaveFile(this, filename, type, palette); @@ -291,6 +310,20 @@ void wxBitmap::SetMask(wxMask *mask) M_BITMAPDATA->m_bitmapMask = mask ; } +wxBitmap wxBitmap::GetSubBitmap( const wxRect& rect) const +{ + wxCHECK_MSG( Ok() && + (rect.x >= 0) && (rect.y >= 0) && + (rect.x+rect.width <= M_BMPDATA->m_width) && (rect.y+rect.height <= M_BMPDATA->m_height), + wxNullBitmap, wxT("invalid bitmap or bitmap region") ); + + wxBitmap ret( rect.width, rect.height, 0 ); + wxASSERT_MSG( ret.Ok(), wxT("GetSubBitmap error") ); + + // The remaining still TODO + return ret; +} + void wxBitmap::AddHandler(wxBitmapHandler *handler) { sm_handlers.Append(handler); @@ -818,10 +851,10 @@ WXPixmap wxBitmap::GetLabelPixmap (WXWidget w) this is a catch22!! - So, before doing thing really clean, I just do nothing; if the pixmap is - referenced by many widgets, Motif performs caching functions. - And if pixmap is referenced with multiples colors, we just have some - memory leaks... I hope we can deal with them... + So, before doing thing really clean, I just do nothing; if the pixmap is + referenced by many widgets, Motif performs caching functions. + And if pixmap is referenced with multiples colors, we just have some + memory leaks... I hope we can deal with them... */ // Must be destroyed, because colours can have been changed! if (M_BITMAPDATA->m_labelPixmap) @@ -850,26 +883,27 @@ WXPixmap wxBitmap::GetArmPixmap (WXWidget w) Display *dpy = (Display*) M_BITMAPDATA->m_display; #ifdef FOO - See GetLabelPixmap () comment - // Must be destroyed, because colours can have been changed! - if (M_BITMAPDATA->m_armPixmap) - XmDestroyPixmap (DefaultScreenOfDisplay (dpy), M_BITMAPDATA->m_armPixmap); + // See GetLabelPixmap () comment + + // Must be destroyed, because colours can have been changed! + if (M_BITMAPDATA->m_armPixmap) + XmDestroyPixmap (DefaultScreenOfDisplay (dpy), M_BITMAPDATA->m_armPixmap); #endif - char tmp[128]; - sprintf (tmp, "Im%x", (unsigned int) M_BITMAPDATA->m_image); + char tmp[128]; + sprintf (tmp, "Im%x", (unsigned int) M_BITMAPDATA->m_image); - Pixel fg, bg; - Widget widget = (Widget) w; + Pixel fg, bg; + Widget widget = (Widget) w; - XtVaGetValues (widget, XmNarmColor, &bg, NULL); - while (XmIsGadget (widget)) - widget = XtParent (widget); - XtVaGetValues (widget, XmNforeground, &fg, NULL); + XtVaGetValues (widget, XmNarmColor, &bg, NULL); + while (XmIsGadget (widget)) + widget = XtParent (widget); + XtVaGetValues (widget, XmNforeground, &fg, NULL); - M_BITMAPDATA->m_armPixmap = (WXPixmap) XmGetPixmap (DefaultScreenOfDisplay (dpy), tmp, fg, bg); + M_BITMAPDATA->m_armPixmap = (WXPixmap) XmGetPixmap (DefaultScreenOfDisplay (dpy), tmp, fg, bg); - return M_BITMAPDATA->m_armPixmap; + return M_BITMAPDATA->m_armPixmap; } WXPixmap wxBitmap::GetInsensPixmap (WXWidget w) @@ -898,19 +932,19 @@ WXPixmap wxBitmap::GetInsensPixmap (WXWidget w) XmDestroyPixmap (DefaultScreenOfDisplay (dpy), (Pixmap) M_BITMAPDATA->m_insensPixmap); #endif - char tmp[128]; - sprintf (tmp, "Not%x", (unsigned int) M_BITMAPDATA->m_insensImage); + char tmp[128]; + sprintf (tmp, "Not%x", (unsigned int) M_BITMAPDATA->m_insensImage); - Pixel fg, bg; - Widget widget = (Widget) w; + Pixel fg, bg; + Widget widget = (Widget) w; - while (XmIsGadget (widget)) - widget = XtParent (widget); - XtVaGetValues (widget, XmNbackground, &bg, XmNforeground, &fg, NULL); + while (XmIsGadget (widget)) + widget = XtParent (widget); + XtVaGetValues (widget, XmNbackground, &bg, XmNforeground, &fg, NULL); - M_BITMAPDATA->m_insensPixmap = (WXPixmap) XmGetPixmap (DefaultScreenOfDisplay (dpy), tmp, fg, bg); + M_BITMAPDATA->m_insensPixmap = (WXPixmap) XmGetPixmap (DefaultScreenOfDisplay (dpy), tmp, fg, bg); - return M_BITMAPDATA->m_insensPixmap; + return M_BITMAPDATA->m_insensPixmap; } // We may need this sometime... @@ -920,30 +954,30 @@ WXPixmap wxBitmap::GetInsensPixmap (WXWidget w) NAME XCreateInsensitivePixmap - create a grayed-out copy of a pixmap - SYNOPSIS - Pixmap XCreateInsensitivePixmap( Display *display, Pixmap pixmap ) + SYNOPSIS + Pixmap XCreateInsensitivePixmap( Display *display, Pixmap pixmap ) - DESCRIPTION - This function creates a grayed-out copy of the argument pixmap, suitable - for use as a XmLabel's XmNlabelInsensitivePixmap resource. + DESCRIPTION + This function creates a grayed-out copy of the argument pixmap, suitable + for use as a XmLabel's XmNlabelInsensitivePixmap resource. - RETURN VALUES - The return value is the new Pixmap id or zero on error. Errors include - a NULL display argument or an invalid Pixmap argument. + RETURN VALUES + The return value is the new Pixmap id or zero on error. Errors include + a NULL display argument or an invalid Pixmap argument. - ERRORS - If one of the XLib functions fail, it will produce a X error. The - default X error handler prints a diagnostic and calls exit(). + ERRORS + If one of the XLib functions fail, it will produce a X error. The + default X error handler prints a diagnostic and calls exit(). - SEE ALSO - XCopyArea(3), XCreateBitmapFromData(3), XCreateGC(3), XCreatePixmap(3), - XFillRectangle(3), exit(2) + SEE ALSO + XCopyArea(3), XCreateBitmapFromData(3), XCreateGC(3), XCreatePixmap(3), + XFillRectangle(3), exit(2) - AUTHOR - John R Veregge - john@puente.jpl.nasa.gov - Advanced Engineering and Prototyping Group (AEG) - Information Systems Technology Section (395) - Jet Propulsion Lab - Calif Institute of Technology + AUTHOR + John R Veregge - john@puente.jpl.nasa.gov + Advanced Engineering and Prototyping Group (AEG) + Information Systems Technology Section (395) + Jet Propulsion Lab - Calif Institute of Technology *****************************************************************************/ @@ -951,14 +985,13 @@ Pixmap XCreateInsensitivePixmap( Display *display, Pixmap pixmap ) { - static - char stipple_data[] = - { - 0x55, 0x55, 0xAA, 0xAA, 0x55, 0x55, 0xAA, 0xAA, + static char stipple_data[] = + { + 0x55, 0x55, 0xAA, 0xAA, 0x55, 0x55, 0xAA, 0xAA, 0x55, 0x55, 0xAA, 0xAA, 0x55, 0x55, 0xAA, 0xAA, 0x55, 0x55, 0xAA, 0xAA, 0x55, 0x55, 0xAA, 0xAA, 0x55, 0x55, 0xAA, 0xAA, 0x55, 0x55, 0xAA, 0xAA - }; + }; GC gc; Pixmap ipixmap, stipple; unsigned width, height, depth; @@ -973,30 +1006,30 @@ XCreateInsensitivePixmap( Display *display, Pixmap pixmap ) return ipixmap; if ( 0 == XGetGeometry( display, pixmap, &window, &x, &y, - &width, &height, &border, &depth ) - ) + &width, &height, &border, &depth ) + ) return ipixmap; /* BadDrawable: probably an invalid pixmap */ - /* Get the stipple pixmap to be used to 'gray-out' the argument pixmap. - */ + /* Get the stipple pixmap to be used to 'gray-out' the argument pixmap. + */ stipple = XCreateBitmapFromData( display, pixmap, stipple_data, 16, 16 ); if ( 0 != stipple ) { gc = XCreateGC( display, pixmap, (XtGCMask)0, (XGCValues*)NULL ); if ( NULL != gc ) { - /* Create an identical copy of the argument pixmap. - */ + /* Create an identical copy of the argument pixmap. + */ ipixmap = XCreatePixmap( display, pixmap, width, height, depth ); if ( 0 != ipixmap ) { - /* Copy the argument pixmap into the new pixmap. - */ + /* Copy the argument pixmap into the new pixmap. + */ XCopyArea( display, pixmap, ipixmap, - gc, 0, 0, width, height, 0, 0 ); + gc, 0, 0, width, height, 0, 0 ); - /* Refill the new pixmap using the stipple algorithm/pixmap. - */ + /* Refill the new pixmap using the stipple algorithm/pixmap. + */ XSetStipple( display, gc, stipple ); XSetFillStyle( display, gc, FillStippled ); XFillRectangle( display, ipixmap, gc, 0, 0, width, height ); @@ -1010,7 +1043,7 @@ XCreateInsensitivePixmap( Display *display, Pixmap pixmap ) // Creates a bitmap with transparent areas drawn in // the given colour. -wxBitmap wxCreateMaskedBitmap(wxBitmap& bitmap, wxColour& colour) +wxBitmap wxCreateMaskedBitmap(const wxBitmap& bitmap, wxColour& colour) { wxBitmap newBitmap(bitmap.GetWidth(), bitmap.GetHeight(),