2012-01-04 3 views
1

저는 wxWidgets와 C++에 새롭지만 다른 툴킷에 익숙합니다. 이 같은 레이아웃 원 :C++ wxWidgets - 폭이없는 ScrolledWindow의 문제

My design

를이는 모습입니다.

enter image description here

그래서이 크게 주석이 내 코드입니다 : 내 방 창문이 전혀 폭이없는 것처럼 보입니다.

여기 내 코드가 있습니다. 그 코드는 제가 얻을 수있는 의도와 비슷합니다. , 내가 여기에 같은 같은 구체적인 질문을 가지고 죄송

//CONTENTS OF GUI_MESSAGE_ITEM.H 

#ifndef GUIMESSAGEITEM_H 
#define GUIMESSAGEITEM_H 

#include "wx/panel.h" // Base class: wxPanel 
#include "wx/stattext.h" 
#include "sms_message.h" 
#include "wx/window.h" 
#include "wx/wx.h" 

class GUIMessageItem : public wxPanel { 

public: 
    GUIMessageItem(wxWindow* parent, wxWindowID winid, const SMSMessage& smsMessage); 
    ~GUIMessageItem(); 

private: 
    wxStaticText* stSender; 
    wxStaticText* stSentTime; 
    wxStaticText* stMessageContents; 
}; 

#endif // GUIMESSAGEITEM_H 

//CONTENTS OF GUI_MESSAGE_ITEM.CPP 

#include "gui_message_item.h" 

GUIMessageItem::GUIMessageItem(wxWindow* parent, wxWindowID winid, const SMSMessage& smsMessage) : 
    wxPanel(parent, winid), 
    stSender(new wxStaticText(this, winid, smsMessage.GetSender())), 
    stSentTime(new wxStaticText(this, winid, smsMessage.GetSentTime())), 
    stMessageContents(new wxStaticText(this, winid, smsMessage.GetMessage())) 
{ 
    wxColour blue(wxT("#2A2AF7")); 
    wxColour green(wxT("#56DB4F")); 
    wxFont originalFont = stSender->GetFont(); 
    wxFont boldFont(originalFont); 
    boldFont.SetWeight(wxFONTWEIGHT_BOLD); 
    wxSize stsMin(100, 60); 
    wxSize bodyMin(300, 100); 

    stSender->SetForegroundColour(blue); 
    stSentTime->SetForegroundColour(green); 
    stSender->SetFont(boldFont); 
    stSentTime->SetFont(boldFont); 
    stSender->SetMinSize(stsMin); 
    stSentTime->SetMinSize(stsMin); 

    stMessageContents->SetMinSize(bodyMin); 
    stMessageContents->Wrap(200); 

    wxBoxSizer* lines = new wxBoxSizer(wxVERTICAL); 
    wxBoxSizer* topLine = new wxBoxSizer(wxHORIZONTAL); 
    lines->AddSpacer(4); 
    topLine->AddSpacer(5); 
    this->SetSizer(lines); 

    topLine->Add(stSender, wxALIGN_LEFT); 
    topLine->Add(stSentTime, wxALIGN_RIGHT); 
    lines->Add(topLine); 
    lines->Add(stMessageContents, wxALIGN_CENTER_HORIZONTAL); 

    lines->SetMinSize(wxSize(400,400)); 
    this->FitInside(); 
    this->Layout(); 
} 

GUIMessageItem::~GUIMessageItem() 
{ 
} 

//MAIN CODE FOR THE WHOLE FORM 

MainFrameBase::MainFrameBase(wxWindow* parent, wxWindowID id, const wxString& title, const wxPoint& pos, const wxSize& size, long style) : wxFrame(parent, id, title, pos, size, style) 
{ 
    this->SetSizeHints(wxDefaultSize, wxDefaultSize); 

    //Menu Bar stuff. 
    m_menuBar = new wxMenuBar(0); 
    m_menuFile = new wxMenu(); 
    wxMenuItem* menuFileExit; 
    menuFileExit = new wxMenuItem(m_menuFile, wxID_EXIT, wxString(_("E&xit")) + wxT('\t') + wxT("Alt+X"), wxEmptyString, wxITEM_NORMAL); 

    wxMenuItem* menuFileOpen; 
    menuFileOpen = new wxMenuItem(m_menuFile, wxID_OPEN, wxString(_("&Open")) + wxT('\t') + wxT("Alt+O"), wxEmptyString, wxITEM_NORMAL); 

    m_menuFile->Append(menuFileOpen); 
    m_menuFile->Append(menuFileExit); 
    m_menuBar->Append(m_menuFile, _("&File")); 

    this->SetMenuBar(m_menuBar); 

    //main sizer for whole interface 
    wxBoxSizer* mainSizer = new wxBoxSizer(wxVERTICAL); 

    this->SetSizer(mainSizer); 

    // Filter box section 
    wxStaticText* filterLabel = new wxStaticText(this, wxID_ANY, wxT("Filter by Sender:")); 

    m_filter = new wxComboBox(
     this, 
     wxID_ANY, 
     wxT(""), 
     wxDefaultPosition, 
     wxDefaultSize, 
     0, 
     NULL, 
     wxCB_DROPDOWN|wxCB_READONLY 
    ); 

    wxBoxSizer* filterSizer = new wxBoxSizer(wxHORIZONTAL); 
    filterSizer->Add(filterLabel); 
    filterSizer->Add(m_filter); 
    mainSizer->Add(filterSizer); 

    // List of Messages section //The issue must be here somewhere... 
    m_scrWin = new wxScrolledWindow(
     this, 
     wxID_ANY 
    ); 

    m_listSizer = new wxBoxSizer(wxVERTICAL); 
    m_scrWin->SetSizer(m_listSizer); 
    mainSizer->Add(m_scrWin, wxEXPAND); //m_scrWin should take the WHOLE of the interface. 

    //example msg 
    SMSMessage* exampleMessage = new SMSMessage(
     wxT("+44 07950 322 789"), 
     wxT("2011-13-07 13:22"), 
     wxT("Yo mate, what's up?") 
    ); 

    for (int i = 0; i < 6; i++) { 
     AddSMSMessagePanel(*exampleMessage); 
    } 

    //wxSize minimum(300,500); 

    m_scrWin->FitInside();    //Use fit inside to make the scrollwindow use the width of the items inside? without doing this I get no scrollbar at all... 
    //m_scrWin->SetMinSize(minimum); 
    //m_listSizer->SetMinSize(minimum); 
    //m_scrWin->EnableScrolling(true, true); 
    //m_scrWin->SetScrollRate(1,1); 
    m_scrWin->SetScrollRate(5, 5); 

    this->Layout(); 
    m_statusBar = this->CreateStatusBar(1, wxST_SIZEGRIP, wxID_ANY); 

    this->Centre(wxBOTH); 

    // Connect Events 
    this->Connect(wxEVT_CLOSE_WINDOW, wxCloseEventHandler(MainFrameBase::OnCloseFrame)); 
    this->Connect(menuFileOpen->GetId(), wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler(MainFrameBase::OnFileOpen)); 
    this->Connect(menuFileExit->GetId(), wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler(MainFrameBase::OnExitClick)); 
} 

void MainFrameBase::AddSMSMessagePanel(const SMSMessage& message) { 
    GUIMessageItem* gmi = new GUIMessageItem(m_scrWin, wxID_ANY, message); //object inherits from wxPanel 
    m_listSizer->Add(gmi); 
} 

: 디자인 "에 전송"과 "메시지"재사용 가능한 패널을 기반으로 독특한 블록에이 각각의 "보낸 사람"입니다 하지만 저는 C++과 wxWidgets에 익숙하지 않고 이미이 문제를 해결하기 위해 약 5 시간을 보냈습니다. 나는 부족한 지식을 알고 있습니다. .

은 완전한 소스 코드에 대한 링크입니다 : https://github.com/PhillipTaylor/SMSReader

+0

이 질문에 대한 답변을 좀 더 격려하기 위해 할 수있는 것이 있습니까? – Philluminati

+0

두 가지 제안 : 1. 시간을 좀 더주십시오.이 질문에 답하는 것이 대부분의 사람들에게 최우선 순위는 아닙니다. 2. 적은 코드로이 문제를 재현 해보십시오. – ravenspoint

답변

1

이 보는 많은 코드이고, 나는 무슨 일이 일어나고 있는지 이해하는 척하지 않습니다.

많은 코드를 작성하고 디버깅하고 있습니다. 가능한 많은 코드가 wxGrid를 사용하여 대체 될 수 있습니다. wxGrid를 사용하면 작업이 훨씬 간단 해지고 모든 까다로운 작업이 이미 테스트되고 디버깅됩니다.

+0

고맙습니다. 내가 포함하지 않은 누락 된 기능이있었습니다 (위의 그림 참조). 또한 m_listSizer-> Layout()에 대한 호출을 추가했습니다. (위에 표시되지 않음). – Philluminati

0

다음은 DialogBlocks에 의해 생성 된 코드입니다. 설명대로 레이아웃을 생성해야합니다.

void test::CreateControls() 
{  
////@begin test content construction 
    test* itemPanel1 = this; 

    wxBoxSizer* itemBoxSizer2 = new wxBoxSizer(wxVERTICAL); 
    itemPanel1->SetSizer(itemBoxSizer2); 

    wxBoxSizer* itemBoxSizer3 = new wxBoxSizer(wxHORIZONTAL); 
    itemBoxSizer2->Add(itemBoxSizer3, 0, wxALIGN_LEFT|wxLEFT|wxRIGHT|wxTOP, 5); 

    wxStaticText* itemStaticText4 = new wxStaticText(itemPanel1, wxID_STATIC, _("Static text"), wxDefaultPosition, wxDefaultSize, 0); 
    itemBoxSizer3->Add(itemStaticText4, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5); 

    wxArrayString itemChoice5Strings; 
    wxChoice* itemChoice5 = new wxChoice(itemPanel1, ID_CHOICE, wxDefaultPosition, wxDefaultSize, itemChoice5Strings, 0); 
    itemBoxSizer3->Add(itemChoice5, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5); 

    wxArrayString itemSimpleHtmlListBox6Strings; 
    wxSimpleHtmlListBox* itemSimpleHtmlListBox6 = new wxSimpleHtmlListBox(itemPanel1, ID_SIMPLEHTMLLISTBOX, wxDefaultPosition, wxSize(400, 300), itemSimpleHtmlListBox6Strings, wxHLB_DEFAULT_STYLE); 
    itemBoxSizer2->Add(itemSimpleHtmlListBox6, 1, wxGROW|wxLEFT|wxRIGHT|wxBOTTOM, 5); 

////@end test content construction 
}