wxCheckBox - multiline style

If you are using the main C++ distribution of wxWidgets, Feel free to ask any question related to wxWidgets development here. This means questions regarding to C++ and wxWidgets, not compile problems.
Post Reply
schmallaria
Earned a small fee
Earned a small fee
Posts: 24
Joined: Fri Aug 19, 2005 9:54 am

wxCheckBox - multiline style

Post by schmallaria » Mon Sep 26, 2005 12:07 pm

hello,

is there a way to make the text that goes with a wxCheckBox wrap to the next line?

phlox81
wxWorld Domination!
wxWorld Domination!
Posts: 1387
Joined: Thu Aug 18, 2005 7:49 pm
Location: Germany
Contact:

Post by phlox81 » Mon Sep 26, 2005 12:19 pm

maybe "\r\n" will help.
wxCheckbox::SetLabel("1st line \r\n 2nd line");

benedicte
wxWorld Domination!
wxWorld Domination!
Posts: 1409
Joined: Wed Jan 19, 2005 3:44 pm
Location: Paris, France

Post by benedicte » Mon Sep 26, 2005 4:16 pm

how does it behave on Unix ?
how to make it dynamic ?

schmallaria
Earned a small fee
Earned a small fee
Posts: 24
Joined: Fri Aug 19, 2005 9:54 am

Post by schmallaria » Tue Sep 27, 2005 8:40 am

\r\n dont't work :( .

i think the problem is:

wxWidgets don't supports the BS_MULTILINE style on MSW. here is the code of the create function from wxCheckBox

Code: Select all

bool wxCheckBox::Create(wxWindow *parent,
                        wxWindowID id,
                        const wxString& label,
                        const wxPoint& pos,
                        const wxSize& size, long style,
                        const wxValidator& validator,
                        const wxString& name)
{
    Init();

    if ( !CreateControl(parent, id, pos, size, style, validator, name) )
        return false;

    long msStyle = WS_TABSTOP;

    if ( style & wxCHK_3STATE )
    {
        msStyle |= BS_3STATE;
    }
    else
    {
        wxASSERT_MSG( !Is3rdStateAllowedForUser(),
            wxT("Using wxCH_ALLOW_3RD_STATE_FOR_USER")
            wxT(" style flag for a 2-state checkbox is useless") );
        msStyle |= BS_CHECKBOX;
    }

    if ( style & wxALIGN_RIGHT )
    {
        msStyle |= BS_LEFTTEXT | BS_RIGHT;
    }

    //here i think we need the follwoing line of code
    msStyle |= BS_MULTINLINE;

    return MSWCreateControl(wxT("BUTTON"), msStyle, pos, size, label, 0);
}
but when i made my change to it and build the library.
the text isn't displayed correct because the sizer around my checkbox clips the text (top and bottom).

can anyone help me?

Jamie
Filthy Rich wx Solver
Filthy Rich wx Solver
Posts: 205
Joined: Wed Mar 30, 2005 10:56 pm

Post by Jamie » Tue Sep 27, 2005 9:23 am

Add this change, from this:

Code: Select all

GetTextExtent(str, &wCheckbox, &hCheckbox);
in DoGetBestSize() to this:

Code: Select all

wxClientDC dc(wx_const_cast(wxCheckBox *, this));
dc.SetFont(GetFont());
dc.GetMultiLineTextExtent(str, &wCheckbox, &hCheckbox);

Post Reply