Menu

#671 [wxSmith] assert after inserting wxListCtrl on windows

Undefined
applied
nobody
Patch
2018-04-29
2018-04-23
bluehazzard
No

After inserting a wxListCtrl in a wxSmith dialog this assert gets triggered:

wxListCtrl style should have exactly one mode bit set

the cause is the missing style bit in the preview, because the default style is 0

Does someone know how to set a default style for wxSmith items?

Discussion

  • Miguel Gimenez

    Miguel Gimenez - 2018-04-24

    In wxslistctrl.cpp, line 31 change

    WXS_ST_BEGIN(wxsListCtrlStyles,_T(""))
    

    to (for example)

    WXS_ST_BEGIN(wxsListCtrlStyles,_T("wxLC_LIST"))
    

    but you will get the same exception when you try to change the style, as this always violates the "exactly one mode bit set" rule. To fix this, in OnBuildPreview() if Style() & wxLC_MASK_TYPE is 0 youu can use a default value, and if it has more than one bit set then select one of them with some priority crtieria (top to bottom?)

     
  • Miguel Gimenez

    Miguel Gimenez - 2018-04-24

    Something like this (sorry for the code style)

    wxObject* wxsListCtrl::OnBuildPreview(wxWindow* Parent, long Flags)
    {
        long Mode = Style() & wxLC_MASK_TYPE;
        if (!Mode || (Mode & wxLC_LIST))
          Mode = wxLC_LIST;
         else if (Mode & wxLC_REPORT)
          Mode = wxLC_REPORT;
         else if (Mode & wxLC_ICON)
          Mode = wxLC_ICON;
         else
          Mode = wxLC_SMALL_ICON;
    
        wxListCtrl* Preview = new wxListCtrl(Parent, GetId(), Pos(Parent), Size(Parent), (Style() & ~wxLC_MASK_TYPE) | Mode);
        return SetupWindow(Preview,Flags);
    }
    

    This will fix the asserts, but the generated code will produce asserts if the selected style is invalid; anyway, the ball is now in the user side.

     
  • bluehazzard

    bluehazzard - 2018-04-24

    WXS_ST_BEGIN(wxsListCtrlStyles,_T("wxLC_LIST"))

    i totally missed that..

    To fix this, in OnBuildPreview() if Style() & wxLC_MASK_TYPE is 0 youu can use a default value, and if it has more than one bit set then select one of them with some priority crtieria (top to bottom?)

    or some message box with a warning?

    This will fix the asserts, but the generated code will produce asserts if the selected style is invalid; anyway, the ball is now in the user side.

    I am totally on your side here xD

     
  • Miguel Gimenez

    Miguel Gimenez - 2018-04-27

    This is the patch with the proposed changes.

     
  • Teodor Petrov

    Teodor Petrov - 2018-04-29
    • status: open --> applied
    • Type: Undefined --> Patch
     
  • Teodor Petrov

    Teodor Petrov - 2018-04-29

    Thanks for contribution.

     

Log in to post a comment.