Change the implementation of ListBoxImpl::RegisterImage

The ListBoxImpl::RegisterImage in PlatWX.cpp is supposed to accept an
XPM and convert it into a useable form. For wxWidgets, the useable form
is obviously a wxBitmap. According to the Scintilla specification, the
function should accept both a copy of an XPM file and a set of XPM data.

Currently RegisterImage uses the the wxWidgets XPM image handler. This
has 2 drawbacks. First it requires that the XPM handler is loaded before
the function can be called. Second, the function only accepts a copy of
an XPM file and does not work with XPM data.

Instead use wxXPMDecoder. This class can be decode both types of input
and can be used to build a wxBitmap.
This commit is contained in:
New Pagodi
2019-03-17 01:47:36 -05:00
parent 91d3981a7b
commit 8c180ee7b5

View File

@@ -27,6 +27,7 @@
#include "wx/encconv.h"
#include "wx/listctrl.h"
#include "wx/mstream.h"
#include "wx/xpmdecod.h"
#include "wx/image.h"
#include "wx/imaglist.h"
#include "wx/tokenzr.h"
@@ -2561,10 +2562,23 @@ void ListBoxImpl::RegisterImageHelper(int type, wxBitmap& bmp)
}
void ListBoxImpl::RegisterImage(int type, const char *xpm_data) {
wxXPMDecoder dec;
wxImage img;
// This check is borrowed from src/stc/scintilla/src/XPM.cpp.
// Test done is two parts to avoid possibility of overstepping the memory
// if memcmp implemented strangely. Must be 4 bytes at least at destination.
if ( (0 == memcmp(xpm_data, "/* X", 4)) &&
(0 == memcmp(xpm_data, "/* XPM */", 9)) )
{
wxMemoryInputStream stream(xpm_data, strlen(xpm_data)+1);
wxImage img(stream, wxBITMAP_TYPE_XPM);
img = dec.ReadFile(stream);
}
else
img = dec.ReadData(reinterpret_cast<const char* const*>(xpm_data));
wxBitmap bmp(img);
RegisterImageHelper(type, bmp);
RegisterImageHelper(type,bmp);
}