Added wxNotebookSizer
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@4902 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -27,6 +27,7 @@
|
|||||||
//---------------------------------------------------------------------------
|
//---------------------------------------------------------------------------
|
||||||
|
|
||||||
class wxStaticBox;
|
class wxStaticBox;
|
||||||
|
class wxNotebook;
|
||||||
|
|
||||||
class wxSizerItem;
|
class wxSizerItem;
|
||||||
class wxSizer;
|
class wxSizer;
|
||||||
@@ -193,5 +194,25 @@ protected:
|
|||||||
wxStaticBox *m_staticBox;
|
wxStaticBox *m_staticBox;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
//---------------------------------------------------------------------------
|
||||||
|
// wxNotebookSizer
|
||||||
|
//---------------------------------------------------------------------------
|
||||||
|
|
||||||
|
class WXDLLEXPORT wxNotebookSizer: public wxSizer
|
||||||
|
{
|
||||||
|
DECLARE_CLASS(wxNotebookSizer);
|
||||||
|
public:
|
||||||
|
wxNotebookSizer( wxNotebook *nb );
|
||||||
|
|
||||||
|
void RecalcSizes();
|
||||||
|
wxSize CalcMin();
|
||||||
|
|
||||||
|
wxNotebook *GetNotebook()
|
||||||
|
{ return m_notebook; }
|
||||||
|
|
||||||
|
protected:
|
||||||
|
wxNotebook *m_notebook;
|
||||||
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
// __WXSIZER_H__
|
// __WXSIZER_H__
|
||||||
|
@@ -25,8 +25,10 @@
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include <ctype.h>
|
#include <ctype.h>
|
||||||
|
|
||||||
#include "wx/sizer.h"
|
#include "wx/sizer.h"
|
||||||
#include "wx/statline.h"
|
#include "wx/statline.h"
|
||||||
|
#include "wx/notebook.h"
|
||||||
|
|
||||||
#include "layout.h"
|
#include "layout.h"
|
||||||
|
|
||||||
@@ -40,7 +42,7 @@ MyApp::MyApp()
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
bool MyApp::OnInit(void)
|
bool MyApp::OnInit()
|
||||||
{
|
{
|
||||||
// Create the main frame window
|
// Create the main frame window
|
||||||
frame = new MyFrame((MyFrame *) NULL, (char *) "wxWindows Layout Demo", 0, 0, 550, 500);
|
frame = new MyFrame((MyFrame *) NULL, (char *) "wxWindows Layout Demo", 0, 0, 550, 500);
|
||||||
@@ -54,7 +56,8 @@ bool MyApp::OnInit(void)
|
|||||||
wxMenu *file_menu = new wxMenu;
|
wxMenu *file_menu = new wxMenu;
|
||||||
|
|
||||||
file_menu->Append(LAYOUT_LOAD_FILE, "&Load file", "Load a text file");
|
file_menu->Append(LAYOUT_LOAD_FILE, "&Load file", "Load a text file");
|
||||||
file_menu->Append(LAYOUT_TEST_NEW, "&Test new sizers", "Test new sizer code");
|
file_menu->Append(LAYOUT_TEST_SIZER, "&Test sizers", "Test sizer");
|
||||||
|
file_menu->Append(LAYOUT_TEST_NB, "&Test notebook sizers", "Test notebook sizer");
|
||||||
|
|
||||||
file_menu->AppendSeparator();
|
file_menu->AppendSeparator();
|
||||||
file_menu->Append(LAYOUT_QUIT, "E&xit", "Quit program");
|
file_menu->Append(LAYOUT_QUIT, "E&xit", "Quit program");
|
||||||
@@ -171,7 +174,8 @@ MyFrame::MyFrame(wxFrame *frame, char *title, int x, int y, int w, int h):
|
|||||||
BEGIN_EVENT_TABLE(MyFrame, wxFrame)
|
BEGIN_EVENT_TABLE(MyFrame, wxFrame)
|
||||||
EVT_MENU(LAYOUT_LOAD_FILE, MyFrame::LoadFile)
|
EVT_MENU(LAYOUT_LOAD_FILE, MyFrame::LoadFile)
|
||||||
EVT_MENU(LAYOUT_QUIT, MyFrame::Quit)
|
EVT_MENU(LAYOUT_QUIT, MyFrame::Quit)
|
||||||
EVT_MENU(LAYOUT_TEST_NEW, MyFrame::TestNewSizers)
|
EVT_MENU(LAYOUT_TEST_SIZER, MyFrame::TestSizers)
|
||||||
|
EVT_MENU(LAYOUT_TEST_NB, MyFrame::TestNotebookSizers)
|
||||||
EVT_MENU(LAYOUT_ABOUT, MyFrame::About)
|
EVT_MENU(LAYOUT_ABOUT, MyFrame::About)
|
||||||
EVT_SIZE(MyFrame::OnSize)
|
EVT_SIZE(MyFrame::OnSize)
|
||||||
END_EVENT_TABLE()
|
END_EVENT_TABLE()
|
||||||
@@ -190,18 +194,65 @@ void MyFrame::LoadFile(wxCommandEvent& WXUNUSED(event) )
|
|||||||
|
|
||||||
void MyFrame::Quit(wxCommandEvent& WXUNUSED(event) )
|
void MyFrame::Quit(wxCommandEvent& WXUNUSED(event) )
|
||||||
{
|
{
|
||||||
this->Close(TRUE);
|
this->Close(TRUE);
|
||||||
}
|
}
|
||||||
|
|
||||||
void MyFrame::TestNewSizers(wxCommandEvent& WXUNUSED(event) )
|
void MyFrame::TestSizers(wxCommandEvent& WXUNUSED(event) )
|
||||||
{
|
{
|
||||||
NewSizerFrame *newFrame = new NewSizerFrame((MyFrame *) NULL, "Sizer Test Frame", 50, 50 );
|
MySizerFrame *newFrame = new MySizerFrame((MyFrame *) NULL, "Sizer Test Frame", 50, 50 );
|
||||||
newFrame->Show(TRUE);
|
newFrame->Show(TRUE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void MyFrame::TestNotebookSizers(wxCommandEvent& WXUNUSED(event) )
|
||||||
|
{
|
||||||
|
wxDialog dialog( this, -1, "Notebook Sizer Test Dialog" );
|
||||||
|
|
||||||
|
// Begin with first hierarchy: a notebook at the top and
|
||||||
|
// and OK button at the bottom.
|
||||||
|
|
||||||
|
wxBoxSizer *topsizer = new wxBoxSizer( wxVERTICAL );
|
||||||
|
|
||||||
|
wxNotebook *notebook = new wxNotebook( &dialog, -1 );
|
||||||
|
wxNotebookSizer *nbs = new wxNotebookSizer( notebook );
|
||||||
|
topsizer->Add( nbs, 1, wxGROW );
|
||||||
|
|
||||||
|
wxButton *button = new wxButton( &dialog, wxID_OK, "OK" );
|
||||||
|
topsizer->Add( button, 0, wxALIGN_RIGHT | wxALL, 10 );
|
||||||
|
|
||||||
|
// First page: one big text ctrl
|
||||||
|
wxTextCtrl *multi = new wxTextCtrl( notebook, -1, "TextCtrl.", wxDefaultPosition, wxDefaultSize, wxTE_MULTILINE );
|
||||||
|
notebook->AddPage( multi, "Page One" );
|
||||||
|
|
||||||
|
// Second page: a text ctrl and a button
|
||||||
|
wxPanel *panel = new wxPanel( notebook, -1 );
|
||||||
|
notebook->AddPage( panel, "Page Two" );
|
||||||
|
|
||||||
|
wxBoxSizer *panelsizer = new wxBoxSizer( wxVERTICAL );
|
||||||
|
|
||||||
|
wxTextCtrl *text = new wxTextCtrl( panel, -1, "TextLine 1.", wxDefaultPosition, wxSize(250,-1) );
|
||||||
|
panelsizer->Add( text, 0, wxGROW|wxALL, 30 );
|
||||||
|
text = new wxTextCtrl( panel, -1, "TextLine 2.", wxDefaultPosition, wxSize(250,-1) );
|
||||||
|
panelsizer->Add( text, 0, wxGROW|wxALL, 30 );
|
||||||
|
wxButton *button2 = new wxButton( panel, -1, "Hallo" );
|
||||||
|
panelsizer->Add( button2, 0, wxALIGN_RIGHT | wxLEFT|wxRIGHT|wxBOTTOM, 30 );
|
||||||
|
|
||||||
|
panel->SetAutoLayout( TRUE );
|
||||||
|
panel->SetSizer( panelsizer );
|
||||||
|
|
||||||
|
// Tell dialog to use sizer
|
||||||
|
|
||||||
|
dialog.SetAutoLayout( TRUE );
|
||||||
|
topsizer->Fit( &dialog );
|
||||||
|
topsizer->SetSizeHints( &dialog );
|
||||||
|
dialog.SetSizer( topsizer );
|
||||||
|
|
||||||
|
dialog.ShowModal();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void MyFrame::About(wxCommandEvent& WXUNUSED(event) )
|
void MyFrame::About(wxCommandEvent& WXUNUSED(event) )
|
||||||
{
|
{
|
||||||
(void)wxMessageBox("wxWindows GUI library layout demo\n",
|
(void)wxMessageBox("wxWindows GUI library layout demo\n",
|
||||||
"About Layout Demo", wxOK|wxCENTRE);
|
"About Layout Demo", wxOK|wxCENTRE);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -245,7 +296,7 @@ MyWindow::MyWindow(wxFrame *frame, int x, int y, int w, int h, long style):
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
MyWindow::~MyWindow(void)
|
MyWindow::~MyWindow()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -257,10 +308,10 @@ void MyWindow::OnPaint(wxPaintEvent& WXUNUSED(event) )
|
|||||||
}
|
}
|
||||||
|
|
||||||
//-----------------------------------------------------------------
|
//-----------------------------------------------------------------
|
||||||
// NewSizerFrame
|
// MySizerFrame
|
||||||
//-----------------------------------------------------------------
|
//-----------------------------------------------------------------
|
||||||
|
|
||||||
NewSizerFrame::NewSizerFrame(wxFrame *frame, char *title, int x, int y ):
|
MySizerFrame::MySizerFrame(wxFrame *frame, char *title, int x, int y ):
|
||||||
wxFrame(frame, -1, title, wxPoint(x, y) )
|
wxFrame(frame, -1, title, wxPoint(x, y) )
|
||||||
{
|
{
|
||||||
// we want to get a dialog that is stretchable because it
|
// we want to get a dialog that is stretchable because it
|
||||||
|
@@ -12,9 +12,9 @@
|
|||||||
// Define a new application
|
// Define a new application
|
||||||
class MyApp: public wxApp
|
class MyApp: public wxApp
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
MyApp(void) ;
|
MyApp();
|
||||||
bool OnInit(void);
|
bool OnInit();
|
||||||
};
|
};
|
||||||
|
|
||||||
// Define a new frame
|
// Define a new frame
|
||||||
@@ -23,7 +23,7 @@ class MyWindow;
|
|||||||
|
|
||||||
class MyFrame: public wxFrame
|
class MyFrame: public wxFrame
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
wxPanel *panel;
|
wxPanel *panel;
|
||||||
MyTextWindow *text_window;
|
MyTextWindow *text_window;
|
||||||
MyWindow *canvas;
|
MyWindow *canvas;
|
||||||
@@ -33,44 +33,48 @@ class MyFrame: public wxFrame
|
|||||||
|
|
||||||
void LoadFile(wxCommandEvent& event);
|
void LoadFile(wxCommandEvent& event);
|
||||||
void Quit(wxCommandEvent& event);
|
void Quit(wxCommandEvent& event);
|
||||||
void TestNewSizers(wxCommandEvent& event);
|
void TestSizers(wxCommandEvent& event);
|
||||||
|
void TestNotebookSizers(wxCommandEvent& event);
|
||||||
void About(wxCommandEvent& event);
|
void About(wxCommandEvent& event);
|
||||||
|
|
||||||
DECLARE_EVENT_TABLE()
|
private:
|
||||||
|
DECLARE_EVENT_TABLE()
|
||||||
};
|
};
|
||||||
|
|
||||||
// Define a new text subwindow that can respond to drag-and-drop
|
// Define a new text subwindow that can respond to drag-and-drop
|
||||||
class MyTextWindow: public wxTextCtrl
|
class MyTextWindow: public wxTextCtrl
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
MyTextWindow(wxFrame *frame, int x=-1, int y=-1, int width=-1, int height=-1,
|
MyTextWindow(wxFrame *frame, int x=-1, int y=-1, int width=-1, int height=-1,
|
||||||
long style=wxTE_MULTILINE):
|
long style=wxTE_MULTILINE):
|
||||||
wxTextCtrl(frame, -1, "", wxPoint(x, y), wxSize(width, height), style)
|
wxTextCtrl(frame, -1, "", wxPoint(x, y), wxSize(width, height), style)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
// Define a new canvas which can receive some events
|
// Define a new canvas which can receive some events
|
||||||
class MyWindow: public wxWindow
|
class MyWindow: public wxWindow
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
MyWindow(wxFrame *frame, int x, int y, int w, int h, long style = wxRETAINED);
|
MyWindow(wxFrame *frame, int x, int y, int w, int h, long style = wxRETAINED);
|
||||||
~MyWindow(void) ;
|
~MyWindow();
|
||||||
void OnPaint(wxPaintEvent& event);
|
void OnPaint(wxPaintEvent& event);
|
||||||
|
|
||||||
|
private:
|
||||||
DECLARE_EVENT_TABLE()
|
DECLARE_EVENT_TABLE()
|
||||||
};
|
};
|
||||||
|
|
||||||
class NewSizerFrame: public wxFrame
|
class MySizerFrame: public wxFrame
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
wxPanel *panel;
|
wxPanel *panel;
|
||||||
NewSizerFrame(wxFrame *frame, char *title, int x, int y );
|
MySizerFrame(wxFrame *frame, char *title, int x, int y );
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#define LAYOUT_QUIT 100
|
#define LAYOUT_QUIT 100
|
||||||
#define LAYOUT_TEST 101
|
#define LAYOUT_TEST 101
|
||||||
#define LAYOUT_ABOUT 102
|
#define LAYOUT_ABOUT 102
|
||||||
#define LAYOUT_LOAD_FILE 103
|
#define LAYOUT_LOAD_FILE 103
|
||||||
#define LAYOUT_TEST_NEW 104
|
#define LAYOUT_TEST_SIZER 104
|
||||||
|
#define LAYOUT_TEST_NB 105
|
||||||
|
@@ -23,6 +23,7 @@
|
|||||||
#include "wx/sizer.h"
|
#include "wx/sizer.h"
|
||||||
#include "wx/utils.h"
|
#include "wx/utils.h"
|
||||||
#include "wx/statbox.h"
|
#include "wx/statbox.h"
|
||||||
|
#include "wx/notebook.h"
|
||||||
|
|
||||||
//---------------------------------------------------------------------------
|
//---------------------------------------------------------------------------
|
||||||
|
|
||||||
@@ -30,6 +31,7 @@ IMPLEMENT_ABSTRACT_CLASS(wxSizerItem, wxObject);
|
|||||||
IMPLEMENT_ABSTRACT_CLASS(wxSizer, wxObject);
|
IMPLEMENT_ABSTRACT_CLASS(wxSizer, wxObject);
|
||||||
IMPLEMENT_ABSTRACT_CLASS(wxBoxSizer, wxSizer);
|
IMPLEMENT_ABSTRACT_CLASS(wxBoxSizer, wxSizer);
|
||||||
IMPLEMENT_ABSTRACT_CLASS(wxStaticBoxSizer, wxBoxSizer);
|
IMPLEMENT_ABSTRACT_CLASS(wxStaticBoxSizer, wxBoxSizer);
|
||||||
|
IMPLEMENT_ABSTRACT_CLASS(wxNotebookSizer, wxSizer);
|
||||||
|
|
||||||
//---------------------------------------------------------------------------
|
//---------------------------------------------------------------------------
|
||||||
// wxSizerItem
|
// wxSizerItem
|
||||||
@@ -542,9 +544,10 @@ void wxStaticBoxSizer::RecalcSizes()
|
|||||||
|
|
||||||
wxSize wxStaticBoxSizer::CalcMin()
|
wxSize wxStaticBoxSizer::CalcMin()
|
||||||
{
|
{
|
||||||
// this will have to be done platform by platform
|
// This will have to be done platform by platform
|
||||||
// as there is no way to guess the thickness of
|
// as there is no way to guess the thickness of
|
||||||
// a wxStaticBox border
|
// a wxStaticBox border.
|
||||||
|
|
||||||
int top_border = 15;
|
int top_border = 15;
|
||||||
if (m_staticBox->GetLabel().IsEmpty()) top_border = 5;
|
if (m_staticBox->GetLabel().IsEmpty()) top_border = 5;
|
||||||
int other_border = 5;
|
int other_border = 5;
|
||||||
@@ -555,3 +558,65 @@ wxSize wxStaticBoxSizer::CalcMin()
|
|||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//---------------------------------------------------------------------------
|
||||||
|
// wxNotebookSizer
|
||||||
|
//---------------------------------------------------------------------------
|
||||||
|
|
||||||
|
wxNotebookSizer::wxNotebookSizer( wxNotebook *nb )
|
||||||
|
{
|
||||||
|
wxASSERT_MSG( nb, wxT("wxNotebookSizer needs a notebook") );
|
||||||
|
|
||||||
|
m_notebook = nb;
|
||||||
|
}
|
||||||
|
|
||||||
|
void wxNotebookSizer::RecalcSizes()
|
||||||
|
{
|
||||||
|
m_notebook->SetSize( m_position.x, m_position.y, m_size.x, m_size.y );
|
||||||
|
}
|
||||||
|
|
||||||
|
wxSize wxNotebookSizer::CalcMin()
|
||||||
|
{
|
||||||
|
// This will have to be done platform by platform
|
||||||
|
// as there is no way to guess the thickness of
|
||||||
|
// the wxNotebook tabs and border.
|
||||||
|
|
||||||
|
int borderX = 5;
|
||||||
|
int borderY = 5;
|
||||||
|
if ((m_notebook->HasFlag(wxNB_RIGHT)) ||
|
||||||
|
(m_notebook->HasFlag(wxNB_LEFT)))
|
||||||
|
{
|
||||||
|
borderX += 70; // improvements later..
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
borderY += 35; // improvements later..
|
||||||
|
}
|
||||||
|
|
||||||
|
if (m_notebook->GetChildren().GetCount() == 0)
|
||||||
|
return wxSize(borderX + 10, borderY + 10);
|
||||||
|
|
||||||
|
int maxX = 0;
|
||||||
|
int maxY = 0;
|
||||||
|
|
||||||
|
wxWindowList::Node *node = m_notebook->GetChildren().GetFirst();
|
||||||
|
while (node)
|
||||||
|
{
|
||||||
|
wxWindow *item = node->GetData();
|
||||||
|
wxSizer *itemsizer = item->GetSizer();
|
||||||
|
|
||||||
|
if (itemsizer)
|
||||||
|
{
|
||||||
|
wxSize subsize( itemsizer->CalcMin() );
|
||||||
|
|
||||||
|
if (subsize.x > maxX) maxX = subsize.x;
|
||||||
|
if (subsize.y > maxY) maxY = subsize.y;
|
||||||
|
}
|
||||||
|
|
||||||
|
node = node->GetNext();
|
||||||
|
}
|
||||||
|
|
||||||
|
return wxSize( borderX + maxX, borderY + maxY );
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user