X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/f97c985452b20a8c2f0bbfb1d0275298bf09fb45..a5e13868ca700aa39bae26b8fb13c640f466d9f0:/src/motif/bitmap.cpp diff --git a/src/motif/bitmap.cpp b/src/motif/bitmap.cpp index 58b53da7f7..93eb32f732 100644 --- a/src/motif/bitmap.cpp +++ b/src/motif/bitmap.cpp @@ -19,13 +19,15 @@ #include "wx/bitmap.h" #include "wx/icon.h" #include "wx/log.h" +#include "wx/control.h" +#include "wx/dcmemory.h" #include #include "wx/motif/private.h" // TODO: correct symbol, path? -#if USE_XPM +#if wxUSE_XPM #include #endif @@ -152,7 +154,7 @@ wxBitmap::wxBitmap(const wxString& filename, long type) // Create from XPM data static wxControl* sg_Control = NULL; -wxBitmap::wxBitmap(const char **data, wxControl* control) +wxBitmap::wxBitmap(char **data, wxControl* control) { // Pass the control to the Create function using a global sg_Control = control; @@ -573,7 +575,7 @@ bool wxXBMDataHandler::Create(wxBitmap *bitmap, void *data, long flags, int widt return TRUE; } -#if USE_XPM +#if wxUSE_XPM class WXDLLEXPORT wxXPMFileHandler: public wxBitmapHandler { DECLARE_DYNAMIC_CLASS(wxXPMFileHandler) @@ -595,7 +597,7 @@ IMPLEMENT_DYNAMIC_CLASS(wxXPMFileHandler, wxBitmapHandler) bool wxXPMFileHandler::LoadFile(wxBitmap *bitmap, const wxString& name, long flags, int desiredWidth, int desiredHeight) { - Display *dpy = wxGetDisplay(); + Display *dpy = (Display*) wxGetDisplay(); M_BITMAPHANDLERDATA->m_display = (WXDisplay*) dpy; XpmAttributes xpmAttr; @@ -618,8 +620,17 @@ bool wxXPMFileHandler::LoadFile(wxBitmap *bitmap, const wxString& name, long fla M_BITMAPHANDLERDATA->m_bitmapMask->SetPixmap((WXPixmap) mask); } + unsigned int depthRet; + int xRet, yRet; + unsigned int widthRet, heightRet, borderWidthRet; + Window rootWindowRet; + XGetGeometry(dpy, pixmap, &rootWindowRet, &xRet, &yRet, + &widthRet, &heightRet, &borderWidthRet, &depthRet); + M_BITMAPHANDLERDATA->m_width = xpmAttr.width; M_BITMAPHANDLERDATA->m_height = xpmAttr.height; + + /* if ( xpmAttr.npixels > 2 ) { M_BITMAPHANDLERDATA->m_depth = 8; // TODO: next time not just a guess :-) ... @@ -627,12 +638,16 @@ bool wxXPMFileHandler::LoadFile(wxBitmap *bitmap, const wxString& name, long fla { M_BITMAPHANDLERDATA->m_depth = 1; // mono } + */ + + M_BITMAPHANDLERDATA->m_depth = depthRet; M_BITMAPHANDLERDATA->m_numColors = xpmAttr.npixels; XpmFreeAttributes(&xpmAttr); M_BITMAPHANDLERDATA->m_ok = TRUE; + return TRUE; } else { // XpmDebugError(errorStatus, name); @@ -663,7 +678,7 @@ class WXDLLEXPORT wxXPMDataHandler: public wxBitmapHandler { DECLARE_DYNAMIC_CLASS(wxXPMDataHandler) public: - inline wxXBMDataHandler() + inline wxXPMDataHandler() { m_name = "XPM data"; m_extension = "xpm"; @@ -681,7 +696,7 @@ bool wxXPMDataHandler::Create(wxBitmap *bitmap, void *data, long flags, int widt M_BITMAPHANDLERDATA->m_depth = 1; M_BITMAPHANDLERDATA->m_freePixmap = TRUE; - Display *dpy = wxGetDisplay(); + Display *dpy = (Display*) wxGetDisplay(); M_BITMAPHANDLERDATA->m_display = (WXDisplay*) dpy; XpmAttributes xpmAttr; @@ -712,6 +727,15 @@ bool wxXPMDataHandler::Create(wxBitmap *bitmap, void *data, long flags, int widt // Set attributes M_BITMAPHANDLERDATA->m_width = xpmAttr.width; M_BITMAPHANDLERDATA->m_height = xpmAttr.height; + + unsigned int depthRet; + int xRet, yRet; + unsigned int widthRet, heightRet, borderWidthRet; + Window rootWindowRet; + XGetGeometry(dpy, pixmap, &rootWindowRet, &xRet, &yRet, + &widthRet, &heightRet, &borderWidthRet, &depthRet); + + /* if ( xpmAttr.npixels > 2 ) { M_BITMAPHANDLERDATA->m_depth = 8; // next time not just a guess :-) ... @@ -719,6 +743,10 @@ bool wxXPMDataHandler::Create(wxBitmap *bitmap, void *data, long flags, int widt { M_BITMAPHANDLERDATA->m_depth = 1; // mono } + */ + + M_BITMAPHANDLERDATA->m_depth = depthRet; + M_BITMAPHANDLERDATA->m_numColors = xpmAttr.npixels; XpmFreeAttributes(&xpmAttr); M_BITMAPHANDLERDATA->m_ok = TRUE; @@ -760,7 +788,7 @@ void wxBitmap::InitStandardHandlers() // XPM is considered standard for Moif, although it can be omitted if absolutely // necessary. -#if USE_XPM +#if wxUSE_XPM AddHandler(new wxXPMFileHandler); AddHandler(new wxXPMDataHandler); #endif @@ -844,6 +872,18 @@ WXPixmap wxBitmap::GetInsensPixmap (WXWidget w) { Display *dpy = (Display*) M_BITMAPDATA->m_display; + if (M_BITMAPDATA->m_insensPixmap) + return M_BITMAPDATA->m_insensPixmap; + + if (!w) + { + M_BITMAPDATA->m_insensPixmap = (WXPixmap) XCreateInsensitivePixmap(dpy, (Pixmap) M_BITMAPDATA->m_pixmap); + if (M_BITMAPDATA->m_insensPixmap) + return M_BITMAPDATA->m_insensPixmap; + else + return M_BITMAPDATA->m_pixmap; + } + if (M_BITMAPDATA->m_insensImage == (WXPixmap) 0) return M_BITMAPDATA->m_pixmap; @@ -964,3 +1004,23 @@ static return ipixmap; } +// Creates a bitmap with transparent areas drawn in +// the given colour. +wxBitmap wxCreateMaskedBitmap(wxBitmap& bitmap, wxColour& colour) +{ + wxBitmap newBitmap(bitmap.GetWidth(), + bitmap.GetHeight(), + bitmap.GetDepth()); + wxMemoryDC destDC; + wxMemoryDC srcDC; + srcDC.SelectObject(bitmap); + destDC.SelectObject(newBitmap); + + wxBrush brush(colour, wxSOLID); + destDC.SetOptimization(FALSE); + destDC.SetBackground(brush); + destDC.Clear(); + destDC.Blit(0, 0, bitmap.GetWidth(), bitmap.GetHeight(), & srcDC, 0, 0, wxCOPY, TRUE); + + return newBitmap; +}