Opened 5 years ago

Closed 4 years ago

#11595 closed defect (fixed)

Bitmap in menu items disappear on Windows

Reported by: congelli501 Owned by:
Priority: normal Milestone:
Component: wxMSW Version: stable-latest
Keywords: menu item bitmap icon label Cc: malcompl
Blocked By: Blocking:
Patch: no

Description

Hello !
On Windows (this problem doesn't exist on wxGTK), when I change the wxMenuItem label, the bitmap associated to the menu item disappear... and it's impossible to add a new one.

Here is an example.
App.hpp :

//------------------------------------------------------------------------------
#include "wx/wxprec.h"
 
#ifdef __BORLANDC__
    #pragma hdrstop
#endif
 
#ifndef WX_PRECOMP
    #include "wx/wx.h"
#endif
//------------------------------------------------------------------------------
#include "MainFrame.hpp"
//------------------------------------------------------------------------------
 
#if not defined APP_HPP_AUTO_SAVE
#define APP_HPP_AUTO_SAVE
 
class App : public wxApp
{
public:
    virtual bool OnInit();
 
private:
    MainFrame *m_frame;
};
//------------------------------------------------------------------------------
 
#endif //APP_HPP_AUTO_SAVE

App.cpp :

//------------------------------------------------------------------------------
#include "App.hpp"
//------------------------------------------------------------------------------
IMPLEMENT_APP(App)
//------------------------------------------------------------------------------
bool App::OnInit()
{
    m_frame = new MainFrame(_T("test"),  wxDefaultPosition, wxSize(300, 300));
    m_frame->Show(true);
 
    return true;
}
//------------------------------------------------------------------------------

MainFrame.hpp :

//------------------------------------------------------------------------------
#if not defined MAIN_FRAME_HPP_AUTO_SAVE
#define MAIN_FRAME_HPP_AUTO_SAVE
 
//------------------------------------------------------------------------------
#include "wx/wxprec.h"
 
#ifdef __BORLANDC__
    #pragma hdrstop
#endif
 
#ifndef WX_PRECOMP
    #include "wx/wx.h"
#endif
//------------------------------------------------------------------------------
 
class MainFrame : public wxFrame
{
public:
    MainFrame(const wxString& title, const wxPoint& pos, const wxSize& size, long style = wxDEFAULT_FRAME_STYLE);
    void OnQuit(wxCommandEvent& event);
    void OnBtUpdate(wxCommandEvent& event);
 
protected:
    wxMenuItem *m_MenuItem;
 
    wxMenuBar *m_MenuBar;
};
 
#endif //MAIN_FRAME_HPP_AUTO_SAVE

MainFrame.cpp :

//------------------------------------------------------------------------------
#include "MainFrame.hpp"
//------------------------------------------------------------------------------
/* XPM */
static char * ok_xpm[] = {
"16 16 3 1",
"     c #000000",
".    c #FFFF00",
"+    c #FF0000",
"         .......",
"        ........",
"  ++   .........",
"    ++...+++....",
"     +...+..+.. ",
"    ..+..+..+.  ",
"   ...+...+.+   ",
"  ....++++..+   ",
" .......... +   ",
"..........  +   ",
".....++++++++   ",
"........        ",
".......         ",
"......          ",
".....          .",
"....          .."};
//------------------------------------------------------------------------------
MainFrame::MainFrame(const wxString& title, const wxPoint& pos, const wxSize& size, long style) : wxFrame(NULL, -1, title, pos, size, style)
{
        // File menu
    wxMenu *FileMenu = new wxMenu;
    m_MenuItem = new wxMenuItem(FileMenu, wxID_ANY, _T("Test"));
    m_MenuItem->SetBitmap(wxBitmap(ok_xpm));
    FileMenu->Append(m_MenuItem);
 
        // Menubar
    m_MenuBar = new wxMenuBar();
    m_MenuBar->Append(FileMenu,_("&File"));
 
    SetMenuBar(m_MenuBar);
 
    // Events
    Connect( m_MenuItem->GetId(), wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler(MainFrame::OnBtUpdate));
}
//------------------------------------------------------------------------------
void MainFrame::OnBtUpdate(wxCommandEvent& event)
{
    m_MenuItem->SetItemLabel(_T("Coucou"));
}
//------------------------------------------------------------------------------

Attachments (2)

menu.png download (5.2 KB) - added by congelli501 5 years ago.
Menu
error.png download (9.5 KB) - added by congelli501 5 years ago.
Error message, wxWidgets was build as RELEASE.

Download all attachments as: .zip

Change History (19)

comment:1 Changed 5 years ago by vadz

  • Status changed from new to infoneeded_new

I think this was fixed in the trunk. It's not easy for me to test it (please read HowToSubmitPatches to learn about how to make it simpler) though so I didn't do it yet. Please retest your code with 2.9.0 to see if the problem is still there, if it isn't we might be able to backport the fixes to 2.8.

comment:2 Changed 5 years ago by congelli501

  • Status changed from infoneeded_new to new

The problem is not really resolved : indeed, the icon doesn't disappear anymore when we change the item label, but there are some other problem. When the label is changed, the previous one is not really replaced : the two labels are displayed in the same menu item (cf image).

Changed 5 years ago by congelli501

Menu

comment:3 Changed 5 years ago by vadz

  • Cc malcompl added

I wonder if this bug could be fixed in the ownerdraw-refactor branch by Marcin (when will we merge it in the trunk BTW?). I could test it myself if I had a simple patch reproducing the problem...

comment:4 Changed 5 years ago by malcompl

I've tested the code and this bug does not exist in the trunk and ownerdraw-refactor branch.
The ownerdraw-refactor branch is finished, so you can merge it with trunk when you're ready ;)

I found some other bug, when I was testing for this problem. It has to do with calculation of rcImg for not ownerdrawn item - if asociated bmp is less than standard size of checkmark. But curently I have no free time to fix it.

comment:5 Changed 5 years ago by vadz

  • Resolution set to fixed
  • Status changed from new to closed

This bug should be fixed now in the trunk as ownerdraw branch was merged into it so closing it, please reopen with a test case if you still see it.

Marcin, if you have a test case for the other bug you found, please open another ticket for it so that we don't forget about it. TIA!

comment:6 Changed 5 years ago by congelli501

  • Resolution fixed deleted
  • Status changed from closed to reopened

There is another problem now : wxWidgets build is broken on Windows :
Build options :

mingw32-make.exe -f makefile.gcc -j 2 BUILD=release SHARED=0 UNICODE=1

Output :

g++ -c -o gcc_mswu\corelib_mdi.o  -O2 -mthreads  -DHAVE_W32API_H -D__WXMSW__   -DNDEBUG    -D_UNICODE   -I..\..\lib\gcc_lib\mswu -I..\..\include  -W -Wall -DWXBUILDING -I..\..\src\tiff\libtiff -I..\..\src\jpeg -I..\..\src\png -I..\..\src\zlib -I..\..\src\regex -I..\..\src\expat\lib -DwxUSE_BASE=0   -Wno-ctor-dtor-privacy   -MTgcc_mswu\corelib_mdi.o -MFgcc_mswu\corelib_mdi.o.d -MD -MP ../../src/msw/mdi.cpp
In file included from ../../include/wx/menuitem.h:195,
                 from ../../include/wx/menu.h:28,
                 from ../../include/wx/mdi.h:20,
                 from ../../src/msw/mdi.cpp:30:
../../include/wx/msw/menuitem.h:123: error: `HDC' has not been declared
../../include/wx/msw/menuitem.h:123: error: expected `,' or `...' before '*' token
../../include/wx/msw/menuitem.h:123: error: ISO C++ forbids declaration of `hdc' with no type
../../include/wx/msw/menuitem.h:123: error: ISO C++ forbids declaration of `RECT' with no type
mingw32-make.exe: *** [gcc_mswu\corelib_mdi.o] Error 1

comment:7 Changed 5 years ago by VZ

(In [63252]) Compilation fix after ownerdraw-refactor branch merge.

Don't use HDC in public headers, it may not be declared there. Use WXHDC
instead even if this means having ugly casts.

This fixed mingw32 compilation (see #11595).

comment:8 Changed 5 years ago by congelli501

Another bug :

g++ -c -o gcc_mswu\corelib_mdi.o  -O2 -mthreads  -DHAVE_W32API_H -D__WXMSW__   -DNDEBUG    -D_UNICODE   -I..\..\lib\gcc_lib\mswu -I..\..\include  -W -Wall -DWXBUILDING -I..\..\src\tiff\libtiff -I..\..\src\jpeg -I..\..\src\png -I..\..\src\zlib -I..\..\src\regex -I..\..\src\expat\lib -DwxUSE_BASE=0   -Wno-ctor-dtor-privacy   -MTgcc_mswu\corelib_mdi.o -MFgcc_mswu\corelib_mdi.o.d -MD -MP ../../src/msw/mdi.cpp
In file included from ../../include/wx/menuitem.h:195,
                 from ../../include/wx/menu.h:28,
                 from ../../include/wx/mdi.h:20,
                 from ../../src/msw/mdi.cpp:30:
../../include/wx/msw/menuitem.h:123: error: expected `,' or `...' before '*' token
../../include/wx/msw/menuitem.h:123: error: ISO C++ forbids declaration of `RECT' with no type
mingw32-make.exe: *** [gcc_mswu\corelib_mdi.o] Error 1

comment:9 Changed 5 years ago by alarsen

  • Priority changed from normal to blocker
  • Status changed from reopened to confirmed
  • Version changed from 2.8.10 to 2.9-svn

comment:10 Changed 5 years ago by VZ

(In [63272]) Compilation fixes for PCH-less build after ownerdraw-refactor branch merge.

Forward declare more classes, in particular use tagRECT which can be forward
declared, instead of RECT typedef in public headers.

Also include more header in #ifndef WX_PRECOMP case.

See #11595.

comment:11 Changed 5 years ago by vadz

  • Priority changed from blocker to normal
  • Status changed from confirmed to infoneeded_new

Changing the status back after fixing the compilation problem.

comment:12 Changed 5 years ago by alarsen

  • Priority changed from normal to blocker

Using MinGW 3.4.5 (cross-compiling on Linux) I still get errors when building wx:

src/msw/ownerdrw.cpp:126: error: `HIMAGELIST' was not declared in this scope
src/msw/ownerdrw.cpp:128: error: `::ImageList_Add' has not been declared
src/msw/ownerdrw.cpp:129: error: `ILD_SELECTED' was not declared in this scope
src/msw/ownerdrw.cpp:129: error: `ILD_NORMAL' was not declared in this scope
src/msw/ownerdrw.cpp:130: error: `::ImageList_Draw' has not been declared
src/msw/ownerdrw.cpp:131: error: `::ImageList_Destroy' has not been declared

so the spook isn't over yet...

comment:13 follow-up: Changed 5 years ago by vadz

  • Priority changed from blocker to normal

Thanks, I've really fixed it now by checking that the build works instead of doing it blindly but I wonder why you (both Anders and the OP) don't use PCH. At least on my system (I'm also cross-compiling from Linux) the difference in speed is noticeable and using PCH is more than twice faster. Of course, it also takes 4 times more space on the disk but speed is usually more important...

comment:14 Changed 5 years ago by VZ

(In [63274]) Another compilation fix for wxMSW without PCH.

Need to include <commctrl.h> as we use HIMAGELIST and related functions now.

See #11595.

comment:15 in reply to: ↑ 13 Changed 5 years ago by alarsen

Replying to vadz:

Thanks, I've really fixed it now by checking that the build works instead of doing it blindly

It works now, thanks for fixing it!

I wonder why you (both Anders and the OP) don't use PCH.

well, cross-configuring with MinGW-gcc 3.4.5 on Linux yields
"checking for gcc precompiled header bug... yes"

I can't upgrade to a (working) MinGW-gcc 4.2.1, since libraries build with that version are incompatible with the current native MinGW-gcc 3.4.4 :(

comment:16 Changed 5 years ago by congelli501

  • Status changed from infoneeded_new to new

Build now works, but I still get a problem with menu.
Now I get an error when I open a menu (cf file). The source is the same as in comment #1. Icon size is 16*16px.

Changed 5 years ago by congelli501

Error message, wxWidgets was build as RELEASE.

comment:17 Changed 4 years ago by congelli501

  • Resolution set to fixed
  • Status changed from new to closed

Now, everything works fine.

Note: See TracTickets for help on using tickets.