2 ScrolledWindows on a ScrolledWindow no resize Topic is solved

Are you writing your own components and need help with how to set them up or have questions about the components you are deriving from ? Ask them here.
Post Reply
kea_
Experienced Solver
Experienced Solver
Posts: 59
Joined: Wed Oct 17, 2007 7:32 am

2 ScrolledWindows on a ScrolledWindow no resize

Post by kea_ »

Hello together,

I have a wxScrolledWindow (Base) as a base and in this I have a wxBoxSizer in the BoxSizer I have two wxScrolledWindow (Win1 and Win2).
That works fine. But if I like to change the size of the Win1 the wxSizer does not Recalc the size.
See the examples below.

This is the source for the Base:

Code: Select all

coMyTable::coMyTable(wxWindow *wParent, wxWindowID id, long lStyle)
         : wxScrolledWindow(wParent, id, wxDefaultPosition, wxDefaultSize, lStyle)
         , csMyTableData(){

    m_szrTop = new wxBoxSizer(wxVERTICAL);
    SetSizer(m_szrTop);
    m_szrTop->Add(m_mtlLabel = new coMyTableLabel(this, ID_LABEL, this), 0, wxALL | wxEXPAND, 0);
    m_szrTop->Add(m_mtbBody = new coMyTableBody(this, ID_BODY, this), 1, wxALL | wxEXPAND, 0);
}


coMyTable::~coMyTable(){}


void coMyTable::SetLabelHeight(int iHeight){
    m_mtlLabel->SetSize(m_mtlLabel->GetSize().GetWidth(), iHeight);
//    m_mtlLabel->Refresh();
    //m_szrTop->RecalcSizes();
    //FitInside();
}
Win1:

Code: Select all

#include "coMyTableLabel.h"


BEGIN_EVENT_TABLE(coMyTableLabel, wxScrolledWindow)
    EVT_PAINT(coMyTableLabel::OnPaint)
    EVT_ERASE_BACKGROUND(coMyTableLabel::OnEraseBackground)
    EVT_MOUSE_EVENTS(coMyTableLabel::OnMouseEvent)
    //EVT_SIZE(coMyTableLabel::OnSize)
END_EVENT_TABLE()


coMyTableLabel::coMyTableLabel(wxWindow *wnd, wxWindowID id, csMyTableData *dt)
              : wxScrolledWindow(wnd, id, wxDefaultPosition, wxDefaultSize, wxFULL_REPAINT_ON_RESIZE){

    m_dt = dt;
    SetAutoLayout(true);
}


coMyTableLabel::~coMyTableLabel(){}


// **  E V E N T S  ***
void coMyTableLabel::OnEraseBackground(wxEraseEvent& event){}


void coMyTableLabel::OnPaint(wxPaintEvent &event){
    wxBufferedPaintDC dc(this);
    PrepareDC(dc);

    dc.SetFont(GetFont());
    dc.SetBackground(wxBrush(wxColour("#ffffff"), wxSOLID));
    dc.Clear();

    m_dt->DrawLabel(dc, GetSize());
}


void coMyTableLabel::OnMouseEvent(wxMouseEvent &event){
    /*wxString sCursor = "default";
    m_data->OnMouseEventLabel(event, sCursor);
    if(sCursor == "default"){
        wxScrolledWindow::SetCursor(*wxSTANDARD_CURSOR);
    }else if(sCursor == "sizewe"){
        wxScrolledWindow::SetCursor(wxCursor(wxCURSOR_SIZEWE));
    }

    Refresh();*/
}


void coMyTableLabel::OnSize(wxSizeEvent &event){
    Layout();
}
Win2:

Code: Select all

#include "coMyTableBody.h"


BEGIN_EVENT_TABLE(coMyTableBody, wxScrolledWindow)
    EVT_PAINT(coMyTableBody::OnPaint)
    EVT_ERASE_BACKGROUND(coMyTableBody::OnEraseBackground)
    //EVT_MOUSE_EVENTS(coMyTableBody::OnMouseEvent)
END_EVENT_TABLE()


coMyTableBody::coMyTableBody(wxWindow *wnd, wxWindowID id, csMyTableData *dt)
             : wxScrolledWindow(wnd, id, wxDefaultPosition, wxDefaultSize, wxFULL_REPAINT_ON_RESIZE){

    m_dt = dt;
    wxScrolledWindow::SetScrollRate(1, 1);
}


coMyTableBody::~coMyTableBody(){}


// **  E V E N T S  ***
void coMyTableBody::OnEraseBackground(wxEraseEvent& event){}


void coMyTableBody::OnPaint(wxPaintEvent &event){
    wxBufferedPaintDC dc(this);
    PrepareDC(dc);

    dc.SetFont(GetFont());
    dc.SetBackground(wxBrush(wxColour("#ffffff"), wxSOLID));
    dc.Clear();

    m_dt->DrawBody(dc);
}


void coMyTableBody::OnMouseEvent(wxMouseEvent &event){
    /*wxString sCursor = "default";

    m_mgdData->OnMouseEventTable(event, sCursor);
    if(sCursor == "default"){
        wxScrolledWindow::SetCursor(*wxSTANDARD_CURSOR);
    }else if(sCursor == "sizewe"){
        wxScrolledWindow::SetCursor(wxCursor(wxCURSOR_SIZEWE));
    }

    Refresh();*/
}
Does any body know a solution?
Please help me.

Greetings kea_
Attachments
Gross.jpg
Gross.jpg (16.9 KiB) Viewed 2451 times
klein.jpg
klein.jpg (16.92 KiB) Viewed 2451 times
Auria
Site Admin
Site Admin
Posts: 6695
Joined: Thu Sep 28, 2006 12:23 am
Contact:

Post by Auria »

Before even looking at your code, there's a question i really want to ask : why put scrolled windows inside a scrollwindow? This doubly-scrolling layout seems very uncommon and I can't think of any use.

Second, by looking at your code, I see you are using SetSize(). This method is useless if you are using sizers, because in this case the sizers will call it again and overwrite your values eventually. Try calling SetMinSize, SetPreferredSize, etc... (or whatever they're called) and calling Layout() after
"Keyboard not detected. Press F1 to continue"
-- Windows
kea_
Experienced Solver
Experienced Solver
Posts: 59
Joined: Wed Oct 17, 2007 7:32 am

Post by kea_ »

Yes you have right it has no sense for a scrolledwindow in a scrolledwindow.

I will take a wxPanel for that.

For the second.
If you put a wxSizer to a top Window (wxFrame) the set size works. You can change the height of a sizer. This must have to do something width the top level window.

Thank you for your answer.

kea_
Post Reply