A small patch

This forum can be used to talk about general design strategies, new ideas and questions in general related to wxWidgets. If you feel your questions doesn't fit anywhere, put it here.
Post Reply
megabyte
I live to help wx-kind
I live to help wx-kind
Posts: 196
Joined: Tue Dec 07, 2004 8:54 pm
Location: Essen, Germany

A small patch

Post by megabyte »

Hello wxWidgets developers,

I found a small issue which can crash an application. Unfortunatelly I don't know how to submit patches to wxWidgets. Please apply this patch.

It's necessary to find the following code in the ..\src\msw\menuitem.cpp file

Code: Select all

#if wxUSE_OWNER_DRAWN
        if ( IsOwnerDrawn() )
        {
            flagsOld |= MF_OWNERDRAW;
            data = (LPCTSTR)this;
        }
        else
#endif  //owner drawn
        {
            flagsOld |= MF_STRING;
            data = (wxChar*) text.c_str();
        }
and replace it by the following one

Code: Select all

#if wxUSE_OWNER_DRAWN
        if ( IsOwnerDrawn() )
        {
            flagsOld |= MF_OWNERDRAW;
            flagsOld &= ~MF_STRING;
            data = (LPCTSTR)this;
        }
        else
#endif  //owner drawn
        {
            flagsOld |= MF_STRING;
            flagsOld &= ~MF_OWNERDRAW;
            data = (wxChar*) text.c_str();
        }
User avatar
ABX
Can't get richer than this
Can't get richer than this
Posts: 810
Joined: Mon Sep 06, 2004 1:43 pm
Location: Poznan, Poland
Contact:

Re: A small patch

Post by ABX »

megabyte wrote:Hello wxWidgets developers,

I found a small issue which can crash an application. Unfortunatelly I don't know how to submit patches to wxWidgets. Please apply this patch.
Read: http://www.wxwidgets.org/technote/patches.htm

Basically following things should be added to your proposition:
1. Which wxWidgest it is related to.
2. How core developer could duplicate the crash.
3. Perhaps explanation why you think this is best place for fixing crash (ie. link to msdn or something if possible)

Thanks in advance and best regards!

ABX
CVS Head, 2.8.X
wxMSW, wxWinCE, wxPalmOS, wxOS2, wxMGL, bakefile
gcc 3.2.3, bcc 5.51, dmc 8.48, ow 1.6, vc 7.1, evc 3/4, pods 1.2
megabyte
I live to help wx-kind
I live to help wx-kind
Posts: 196
Joined: Tue Dec 07, 2004 8:54 pm
Location: Essen, Germany

Re: A small patch

Post by megabyte »

ABX wrote:1. Which wxWidgest it is related to.
Basically, it relies to the versions 2.53, 2.55 and the CVS version, but I catched an access violation using ver.2.55 and in ver.2.53 my code worked without the AV.
ABX wrote:2. How core developer could duplicate the crash.
3. Perhaps explanation why you think this is best place for fixing crash (ie. link to msdn or something if possible)
I will explain. MSDN says
The following groups of flags cannot be used together:

* MF_BYCOMMAND and MF_BYPOSITION
* MF_DISABLED, MF_ENABLED, and MF_GRAYED
* MF_BITMAP, MF_STRING, MF_OWNERDRAW, and MF_SEPARATOR
...
And in wxWidges there is ability to set both MF_STRING and MF_OWNERDRAW in the same time.

It's possible to reproduce this in following way.
1. Create a menu having bitmaps. In this case by default the ms_nDefaultMarginWidth static member is 15 but MarginWidth for bitmap items is 16 and correspondently ms_nLastMarginWidth is 16 too.
2. Create a new menu item and it will have m_bOwnerDrawn = true because, the ResetOwnerDrawn() method is called before SetMarginWidth(GetMarginWidth()) in the wxMenuItem::Init method.
3. Now I wish to reset the m_bOwnerDrawn flag of the created menu item and reset the MF_OWNERDRAW flag using the following code

Code: Select all

wxMenuItem *pItem = Menu->AppendRadioItem(...);
pItem->ResetOwnerDrawn();
const wxString str = pItem->GetText();
pItem->SetText(wxEmptyString);
pItem->SetText(str);
Ok... Now we have both the flags are set and a string pointer as info.dwTypeData in wxMenuItem::SetText method. The result is Windows calls WM_MEASUREITEM and pMeasureStruct->itemData points to the string and not to a wxMenuItem instance but statically casts to wxMenuItem in the wxWindowMSW::MSWOnMeasureItem method.
User avatar
ABX
Can't get richer than this
Can't get richer than this
Posts: 810
Joined: Mon Sep 06, 2004 1:43 pm
Location: Poznan, Poland
Contact:

Re: A small patch

Post by ABX »

megabyte wrote:MSDN says
The following groups of flags cannot be used together:

* MF_BYCOMMAND and MF_BYPOSITION
* MF_DISABLED, MF_ENABLED, and MF_GRAYED
* MF_BITMAP, MF_STRING, MF_OWNERDRAW, and MF_SEPARATOR
...
And in wxWidges there is ability to set both MF_STRING and MF_OWNERDRAW in the same time.
Thanks!
megabyte wrote:It's possible to reproduce this in following way.
Sorry for not being precise but what I meant was if you could provide a diff or complete file which I could put in place of some sample and duplicate this without writing whole example from scratch. You are best placed to modify one of samples for this. samples/minimal or samples/menu sample is natural candidate for presenting this. Thanks in advance for providing modifications this way. We really have a lot to do/test before 2.6 release and every simplification will be helpful.

Thanks and regards, ABX
CVS Head, 2.8.X
wxMSW, wxWinCE, wxPalmOS, wxOS2, wxMGL, bakefile
gcc 3.2.3, bcc 5.51, dmc 8.48, ow 1.6, vc 7.1, evc 3/4, pods 1.2
Post Reply