Page 1 of 1

Toolbar image problem

Posted: Sun Jun 29, 2014 10:55 pm
by coder99
Running wxCrafter 1.5 stand-alone - MSVC 2010 Express, wxWidgets 3.0.0
After importing a wxFB project and fixing the path to the XPM tool bar graphics and compiling without errors, I get an assert failure at toolbar.cpp(795) in wxToolbar::Realize(): invalid bitmap.
The bitmap shows as expected in the preview.
The code which fails:

Code: Select all

  m_toolBar->AddTool(wxID_HELP, _("tool"), wxXmlResource::Get()->LoadBitmap(wxT("help")), wxNullBitmap, wxITEM_NORMAL, _("Help"), wxT(""), NULL);
    m_toolBar->Realize();
wxBuBaseFrame_wxcr_bitmaps.xrc:

Code: Select all

<?xml version="1.0" encoding="UTF-8"?>
<resource xmlns="http://www.wxwindows.org/wxxrc" version="2.3.0.1">
  <object class="wxBitmap" name="help">rc\help.xpm</object>
</resource>
and wxBuBaseFrame_wxcr_bitmaps.cpp:

Code: Select all

void wxCB73DInitBitmapResources()
{
    // Check for memory FS. If not present, load the handler:
    {
        wxMemoryFSHandler::AddFile(wxT("XRC_resource/dummy_file"), wxT("dummy one"));
        wxFileSystem fsys;
        wxFSFile *f = fsys.OpenFile(wxT("memory:XRC_resource/dummy_file"));
        wxMemoryFSHandler::RemoveFile(wxT("XRC_resource/dummy_file"));
        if (f) delete f;
        else wxFileSystem::AddHandler(new wxMemoryFSHandlerBase);
    }
    XRC_ADD_FILE(wxT("XRC_resource/wxBuBaseFrame_wxcr_bitmaps.cpp$rc_help.xpm"), xml_res_file_0, xml_res_size_0, wxT(""));
    XRC_ADD_FILE(wxT("XRC_resource/wxBuBaseFrame_wxcr_bitmaps.cpp$F__pkg_wx_MSVC2010_wxBU-wxCR_wxBuBaseFrame_wxcr_bitmaps.xrc"), xml_res_file_1, xml_res_size_1, wxT("text/xml"));
    wxXmlResource::Get()->Load(wxT("memory:XRC_resource/wxBuBaseFrame_wxcr_bitmaps.cpp$F__pkg_wx_MSVC2010_wxBU-wxCR_wxBuBaseFrame_wxcr_bitmaps.xrc"));
}
I know I have had similar problems before and it seems that eventually it all works, but I have never figured out what it took to make it work and it always is frustrating until I get there :-)
Any hints or pointers will be greatly appreciated.

TIA

Re: Toolbar image problem

Posted: Mon Jun 30, 2014 12:39 am
by eranif
Usually when these kind of errors occurs, it means that you are missing some bitmap handler in your code.
Try adding a call to wxImage::AddHandler(...) (fill the correct handler)

Eran

Re: Toolbar image problem

Posted: Mon Jun 30, 2014 4:06 am
by coder99
eranif wrote:Usually when these kind of errors occurs, it means that you are missing some bitmap handler in your code.
Try adding a call to wxImage::AddHandler(...) (fill the correct handler)
Thank you, Eran.
After adding:
wxInitAllImageHandlers();
the icon showed.
But, the handler(s) however MUST be added in the MyApp:OnInit() _before_ the main frame is constructed to be effective.

With the handler installed, if I use a 22x22 png file, I get this warning:
16:59:06: iCCP: known incorrect sRGB profile
16:59:06: iCCP: cHRM chunk does not match sRGB
but the icon is displayed.

If I use a 16x16 png, I get no warning and the icon shows.
Also ArtProvider Icons show

Will this handler eventually be added to wxCrafter?

Re: Toolbar image problem

Posted: Mon Jun 30, 2014 9:10 am
by eranif
coder99 wrote:But, the handler(s) however MUST be added in the MyApp:OnInit() _before_ the main frame is constructed to be effective.
This is how wxWidgets works. You need to add the handlers you intend to use in your App derived class
coder99 wrote:Will this handler eventually be added to wxCrafter?
Like you mentioned, it should be added before the constructor is called, in the App class - which wxCrafter has no control over

Eran

Re: Toolbar image problem

Posted: Mon Jun 30, 2014 7:50 pm
by coder99
eranif wrote:
coder99 wrote:But, the handler(s) however MUST be added in the MyApp:OnInit() _before_ the main frame is constructed to be effective.
This is how wxWidgets works. You need to add the handlers you intend to use in your App derived class
Eran
This would explain why I had no problems with some 'imports', but it still leaves me wondering, how wxFB did it, because, according to this argument, all that was needed should have been in the code prior to the import or does wxCrafter things so differently and if so, why does it do things such that this issue becomes a problem?

Just curious, as I will likely have to 'import' a few more projects. :)

Re: Toolbar image problem

Posted: Mon Jun 30, 2014 8:14 pm
by eranif
I don't know what wxFB is doing, since I am not familiar with their code base

However, adding ::wxInitAllImageHandlers() should not be too dificult to remember to add... ;)
After all, it should be added once to the app code and not per dialog/frame that you import from wxFB
Eran

Re: Toolbar image problem

Posted: Tue Jul 01, 2014 2:54 am
by coder99
eranif wrote:I don't know what wxFB is doing, since I am not familiar with their code base
Here is a typical line from wxCrafter for a tool bar button:

Code: Select all

m_toolBar->AddTool(wxID_TOOL_OPEN_JOB, _("Tool Label"), wxXmlResource::Get()->LoadBitmap(wxT("fileopen")), wxNullBitmap, wxITEM_NORMAL, _("Open a job file"), _("Open a job file"), NULL);
and the equivalent code from wxFB:

Code: Select all

m_toolBar->AddTool( wxID_TOOL_OPEN_JOB, _("Open"), wxBitmap( fileopen_xpm ), wxNullBitmap, wxITEM_NORMAL, _("Open a job file"), _("Open a job file"), NULL ); 
Both instances use the same XPM graphic file rc/fileopen.xpm.

With wxCrafter I had to add the handler, with wxFB things worked without it.

Re: Toolbar image problem

Posted: Tue Jul 01, 2014 8:06 am
by eranif
Wxfb is limited when it comes for bitmap handling.
Iirc, when not using xpm ( e.g. When using png files) you have no way to embed them into your executable.
You can only specify the path to the files, while wxcrafter embed the bitmaps to the binary automatically.

I could optimize it so in case of using XPM, it will be added in a different way

Eran