From 3417c2cd3d5cb05451270b5a09fe2355406158a3 Mon Sep 17 00:00:00 2001 From: Robert Roebling Date: Mon, 9 Aug 1999 17:00:51 +0000 Subject: [PATCH] Replaced old wxSizer, Converted two of wxGTK's standard dialogs to use them, Applied two fixes to wxDC code, Made wxRadiobox a little smaller, Added sizer.h to wx.h git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@3325 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- include/wx/layout.h | 165 ---------- include/wx/sizer.h | 37 ++- include/wx/window.h | 7 - include/wx/wx.h | 1 + samples/layout/layout.cpp | 127 +------- samples/layout/layout.h | 16 +- src/common/layout.cpp | 647 +------------------------------------- src/common/sizer.cpp | 64 ++-- src/common/wincmn.cpp | 85 ++--- src/gtk/button.cpp | 8 +- src/gtk/choicdlg.cpp | 107 +++---- src/gtk/dcclient.cpp | 24 +- src/gtk/radiobox.cpp | 2 +- src/gtk/textdlg.cpp | 103 +++--- src/gtk1/button.cpp | 8 +- src/gtk1/choicdlg.cpp | 107 +++---- src/gtk1/dcclient.cpp | 24 +- src/gtk1/radiobox.cpp | 2 +- src/gtk1/textdlg.cpp | 103 +++--- 19 files changed, 297 insertions(+), 1340 deletions(-) diff --git a/include/wx/layout.h b/include/wx/layout.h index f0affc67ed..e3e5353ce7 100644 --- a/include/wx/layout.h +++ b/include/wx/layout.h @@ -62,19 +62,6 @@ enum wxRelationship wxAbsolute }; -enum wxSizerBehaviour -{ - wxSizerShrink, - wxSizerExpand, - wxSizerNone -}; - -#define wxTYPE_SIZER 90 - -// ============================================================================= -// classes -// ============================================================================= - // ---------------------------------------------------------------------------- // wxIndividualLayoutConstraint: a constraint on window position // ---------------------------------------------------------------------------- @@ -195,157 +182,5 @@ public: } }; -// ---------------------------------------------------------------------------- -// sizers -// ---------------------------------------------------------------------------- - -/* - -Algorithm: - - Each sizer has a Layout function. - - wxExpandSizer::Layout ; E.g. for resizeable windows - - - parent size must be known (i.e. called - from OnSize or explicitly) - - call Layout on each child to give it a chance to resize - (e.g. child shrinks around its own children): - stop when all children return TRUE, or no change - - evaluate constraints on self to set size - - wxShrinkSizer::Layout ; E.g. fit-to-contents windows - ; Perhaps 2 rowcols, one above other. - - - call Layout on each child to give it a chance to resize - (e.g. child shrinks around its own children): - stop when each returns TRUE, or no change - - fit around children - (what if some want to be centred? E.g. OK/Cancel rowcol. - - done by centring e.g. bottom sizer w.r.t. top sizer. - (sibling relationship only)) - - evaluate own constraints (e.g. may be below another window) - - IF parent is a real window (remember: a real window can - have only one child sizer, although a sizer can have several child - (real) windows), then resize this parent WITHOUT invoking Layout - again. - Frame and dialog box OnSizes can check if the sizer is a shrink - sizer; if not, can call layout. Maybe have virtual bool AutoSizeLayout() - to determine this. - -How to relayout if a child sizer/window changes? Need to go all the way -to the top of the hierarchy and call Layout() again. - - wxRowColSizer::Layout - - - Similar to wxShrinkSizer only instead of shrinking to fit - contents, more sophisticated layout of contents, and THEN - shrinking (possibly). - - Do the same parent window check/setsize as for wxShrinkSizer. - -*/ - -class WXDLLEXPORT wxSizer : public wxWindow -{ - DECLARE_DYNAMIC_CLASS(wxSizer) - -protected: - wxSizerBehaviour sizerBehaviour; - int borderX; - int borderY; - int sizerWidth; - int sizerHeight; - int sizerX; - int sizerY; - -public: - wxSizer(); - wxSizer(wxWindowBase *parent, wxSizerBehaviour behav = wxSizerNone); - ~wxSizer(); - - bool Create(wxWindowBase *parent, wxSizerBehaviour behav = wxSizerNone); - - virtual void DoGetSize(int *w, int *h) const; - virtual void DoGetClientSize(int *w, int *h) const { GetSize(w, h); } - virtual void DoGetPosition(int *x, int *y) const; - - void SizerSetSize(int x, int y, int w, int h) { SetSize(x, y, w, h); } - void SizerMove(int x, int y) { Move(x, y); } - - virtual void SetBorder(int w, int h); - int GetBorderX() { return borderX ; } - int GetBorderY() { return borderY ; } - - virtual void AddSizerChild(wxWindowBase *child); - virtual void RemoveSizerChild(wxWindowBase *child); - - virtual void SetBehaviour(wxSizerBehaviour b) { sizerBehaviour = b; } - virtual wxSizerBehaviour GetBehaviour() { return sizerBehaviour; } - - virtual bool LayoutPhase1(int *); - virtual bool LayoutPhase2(int *); - -protected: - virtual void DoSetSize(int x, int y, - int width, int height, - int sizeFlags = wxSIZE_AUTO); -}; - -#define wxSIZER_ROWS TRUE -#define wxSIZER_COLS FALSE - -class WXDLLEXPORT wxRowColSizer : public wxSizer -{ - DECLARE_DYNAMIC_CLASS(wxRowColSizer) - -protected: - bool rowOrCol; - int rowOrColSize; - int xSpacing; - int ySpacing; - -public: - // rowOrCol = TRUE to be laid out in rows, otherwise in columns. - wxRowColSizer(); - wxRowColSizer(wxWindowBase *parent, bool rowOrCol = wxSIZER_ROWS, - int rowsOrColSize = 20, wxSizerBehaviour = wxSizerShrink); - ~wxRowColSizer(); - - bool Create(wxWindowBase *parent, bool rowOrCol = wxSIZER_ROWS, - int rowsOrColSize = 20, wxSizerBehaviour = wxSizerShrink); - - virtual void SetRowOrCol(bool rc) { rowOrCol = rc; } - virtual bool GetRowOrCol() { return rowOrCol; } - virtual void SetRowOrColSize(int n) { rowOrColSize = n; } - virtual int GetRowOrColSize() { return rowOrColSize; } - virtual void SetSpacing(int x, int y) { xSpacing = x; ySpacing = y; } - virtual void GetSpacing(int *x, int *y) { *x = xSpacing; *y = ySpacing; } - - bool LayoutPhase1(int *); - bool LayoutPhase2(int *); -}; - -class WXDLLEXPORT wxSpacingSizer : public wxSizer -{ - DECLARE_DYNAMIC_CLASS(wxSpacingSizer) - -public: - wxSpacingSizer(); - wxSpacingSizer(wxWindowBase *parent, wxRelationship rel, wxWindowBase *other, int spacing); - wxSpacingSizer(wxWindowBase *parent); - ~wxSpacingSizer(); - - bool Create(wxWindowBase *parent, wxRelationship rel, wxWindowBase *other, int sp); - bool Create(wxWindowBase *parent); -}; - -// ---------------------------------------------------------------------------- -// global functions -// ---------------------------------------------------------------------------- - -#if WXWIN_COMPATIBILITY - extern bool WXDLLEXPORT wxOldDoLayout(wxWindowBase *win); -#endif // WXWIN_COMPATIBILITY - #endif // _WX_LAYOUTH__ diff --git a/include/wx/sizer.h b/include/wx/sizer.h index 140b6cb5b4..a7f2cb0564 100644 --- a/include/wx/sizer.h +++ b/include/wx/sizer.h @@ -1,6 +1,6 @@ ///////////////////////////////////////////////////////////////////////////// // Name: sizer.h -// Purpose: provide wxNewSizer class for layounting +// Purpose: provide wxSizer class for layounting // Author: Robert Roebling and Robin Dunn // Modified by: // Created: @@ -26,38 +26,37 @@ // classes //--------------------------------------------------------------------------- -class wxNewSizerItem; -class wxNewSizer; -class wxBorderNewSizer; -class wxBoxNewSizer; +class wxSizerItem; +class wxSizer; +class wxBox; //--------------------------------------------------------------------------- -// wxNewSizerItem +// wxSizerItem //--------------------------------------------------------------------------- -class WXDLLEXPORT wxNewSizerItem: public wxObject +class WXDLLEXPORT wxSizerItem: public wxObject { public: // spacer - wxNewSizerItem( int width, int height, int option, int flag, int border ); + wxSizerItem( int width, int height, int option, int flag, int border ); // window - wxNewSizerItem( wxWindow *window, int option, int flag, int border ); + wxSizerItem( wxWindow *window, int option, int flag, int border ); // subsizer - wxNewSizerItem( wxNewSizer *sizer, int option, int flag, int border ); + wxSizerItem( wxSizer *sizer, int option, int flag, int border ); virtual wxSize GetSize(); virtual wxSize CalcMin(); virtual void SetDimension( wxPoint pos, wxSize size ); bool IsWindow(); - bool IsNewSizer(); + bool IsSizer(); bool IsSpacer(); wxWindow *GetWindow() const { return m_window; } - wxNewSizer *GetNewSizer() const + wxSizer *GetSizer() const { return m_sizer; } int GetOption() const { return m_option; } @@ -68,7 +67,7 @@ public: protected: wxWindow *m_window; - wxNewSizer *m_sizer; + wxSizer *m_sizer; wxSize m_size; wxSize m_minSize; int m_option; @@ -77,17 +76,17 @@ protected: }; //--------------------------------------------------------------------------- -// wxNewSizer +// wxSizer //--------------------------------------------------------------------------- -class WXDLLEXPORT wxNewSizer: public wxObject +class WXDLLEXPORT wxSizer: public wxObject { public: - wxNewSizer(); - ~wxNewSizer(); + wxSizer(); + ~wxSizer(); virtual void Add( wxWindow *window, int option = 0, int flag = 0, int border = 0 ); - virtual void Add( wxNewSizer *sizer, int option = 0, int flag = 0, int border = 0 ); + virtual void Add( wxSizer *sizer, int option = 0, int flag = 0, int border = 0 ); virtual void Add( int width, int height, int option = 0, int flag = 0, int border = 0 ); void SetDimension( int x, int y, int width, int height ); @@ -119,7 +118,7 @@ protected: // wxBox //--------------------------------------------------------------------------- -class WXDLLEXPORT wxBox: public wxNewSizer +class WXDLLEXPORT wxBox: public wxSizer { public: wxBox( int orient ); diff --git a/include/wx/window.h b/include/wx/window.h index 5ae7d448c9..cc2212738b 100644 --- a/include/wx/window.h +++ b/include/wx/window.h @@ -606,7 +606,6 @@ public: virtual bool DoPhase(int); // these methods are virtual but normally won't be overridden - virtual void TransformSizerToActual(int *x, int *y) const ; virtual void SetSizeConstraint(int x, int y, int w, int h); virtual void MoveConstraint(int x, int y); virtual void GetSizeConstraint(int *w, int *h) const ; @@ -617,12 +616,6 @@ public: // TODO: what are they and how do they work?? void SetSizer( wxSizer *sizer ); wxSizer *GetSizer() const { return m_windowSizer; } - - void SetSizerParent( wxWindowBase *win ) { m_sizerParent = win; } - wxWindowBase *GetSizerParent() const { return m_sizerParent; } - - virtual void SizerSetSize(int x, int y, int w, int h); - virtual void SizerMove(int x, int y); #endif // wxUSE_CONSTRAINTS // backward compatibility diff --git a/include/wx/wx.h b/include/wx/wx.h index f9f587bcc2..fd1bddc0a1 100644 --- a/include/wx/wx.h +++ b/include/wx/wx.h @@ -56,6 +56,7 @@ #include "wx/gauge.h" #include "wx/combobox.h" #include "wx/layout.h" +#include "wx/sizer.h" #include "wx/memory.h" #include "wx/mdi.h" #include "wx/scrolwin.h" diff --git a/samples/layout/layout.cpp b/samples/layout/layout.cpp index 373d658534..1392d68921 100644 --- a/samples/layout/layout.cpp +++ b/samples/layout/layout.cpp @@ -54,7 +54,6 @@ bool MyApp::OnInit(void) wxMenu *file_menu = new wxMenu; file_menu->Append(LAYOUT_LOAD_FILE, "&Load file", "Load a text file"); - file_menu->Append(LAYOUT_TEST, "&Test sizers", "Test sizer code"); file_menu->Append(LAYOUT_TEST_NEW, "&Test new sizers", "Test new sizer code"); file_menu->AppendSeparator(); @@ -172,7 +171,6 @@ MyFrame::MyFrame(wxFrame *frame, char *title, int x, int y, int w, int h): BEGIN_EVENT_TABLE(MyFrame, wxFrame) EVT_MENU(LAYOUT_LOAD_FILE, MyFrame::LoadFile) EVT_MENU(LAYOUT_QUIT, MyFrame::Quit) - EVT_MENU(LAYOUT_TEST, MyFrame::TestSizers) EVT_MENU(LAYOUT_TEST_NEW, MyFrame::TestNewSizers) EVT_MENU(LAYOUT_ABOUT, MyFrame::About) EVT_SIZE(MyFrame::OnSize) @@ -195,12 +193,6 @@ void MyFrame::Quit(wxCommandEvent& WXUNUSED(event) ) this->Close(TRUE); } -void MyFrame::TestSizers(wxCommandEvent& WXUNUSED(event) ) -{ - SizerFrame *newFrame = new SizerFrame((MyFrame *) NULL, "Sizer Test Frame", 50, 50, 500, 500); - newFrame->Show(TRUE); -} - void MyFrame::TestNewSizers(wxCommandEvent& WXUNUSED(event) ) { NewSizerFrame *newFrame = new NewSizerFrame((MyFrame *) NULL, "Sizer Test Frame", 50, 50 ); @@ -264,103 +256,6 @@ void MyWindow::OnPaint(wxPaintEvent& WXUNUSED(event) ) frame->Draw(dc,TRUE); } -//----------------------------------------------------------------- -// SizerFrame -//----------------------------------------------------------------- - -SizerFrame::SizerFrame(wxFrame *frame, char *title, int x, int y, int w, int h): - wxFrame(frame, -1, title, wxPoint(x, y), wxSize(w, h)) -{ - panel = new wxPanel(this, -1, wxPoint(0, 0), wxSize(-1, -1), wxTAB_TRAVERSAL); - panel->SetBackgroundColour(wxColour(192, 192, 192)); - - // A sizer to fit the whole panel, plus two sizers, one - // above the other. A button is centred on the lower - // sizer; a rowcol containing 3 buttons is centred on the upper - // sizer. - wxSizer *expandSizer = new wxSizer(panel, wxSizerExpand); - expandSizer->SetName("expandSizer"); - - wxLayoutConstraints *c; - - /////// TOP OF PANEL - /////// - wxSizer *topSizer = new wxSizer(expandSizer); - topSizer->SetName("topSizer"); - - // Specify constraints for the top sizer - c = new wxLayoutConstraints; - c->left.SameAs (expandSizer, wxLeft); - c->top.SameAs (expandSizer, wxTop); - c->right.SameAs (expandSizer, wxRight); - c->height.PercentOf (expandSizer, wxHeight, 50); - - topSizer->SetConstraints(c); - - /* - * Add a row-col sizer and some buttons - */ - - // Default is layout by rows, 20 columns per row, shrink to fit. - wxRowColSizer *rowCol = new wxRowColSizer(topSizer); - rowCol->SetName("rowCol"); - - wxButton *button = new wxButton(panel, -1, "Button 1"); - rowCol->AddSizerChild(button); - - button = new wxButton(panel, -1, "Button 2"); - rowCol->AddSizerChild(button); - - button = new wxButton(panel, -1, "Button 3"); - rowCol->AddSizerChild(button); - - // Centre the rowcol in the middle of the upper sizer - c = new wxLayoutConstraints; - c->centreX.SameAs (topSizer, wxCentreX); - c->centreY.SameAs (topSizer, wxCentreY); - c->width.AsIs(); - c->height.AsIs(); - rowCol->SetConstraints(c); - - /////// BOTTOM OF PANEL - /////// - wxSizer *bottomSizer = new wxSizer(expandSizer); - - // Specify constraints for the bottom sizer - c = new wxLayoutConstraints; - c->left.SameAs (expandSizer, wxLeft); - c->top.PercentOf (expandSizer, wxHeight, 50); - c->right.SameAs (expandSizer, wxRight); - c->height.PercentOf (expandSizer, wxHeight, 50); - - bottomSizer->SetConstraints(c); - - wxButton *button2 = new wxButton(panel, -1, "Test button"); - - // The button should be a child of the bottom sizer - bottomSizer->AddSizerChild(button2); - - // Centre the button on the sizer - c = new wxLayoutConstraints; - c->centreX.SameAs (bottomSizer, wxCentreX); - c->centreY.SameAs (bottomSizer, wxCentreY); - c->width.PercentOf (bottomSizer, wxWidth, 20); - c->height.PercentOf (bottomSizer, wxHeight, 20); - button2->SetConstraints(c); -} - -BEGIN_EVENT_TABLE(SizerFrame, wxFrame) - EVT_SIZE(SizerFrame::OnSize) -END_EVENT_TABLE() - - -// Size the subwindows when the frame is resized -void SizerFrame::OnSize(wxSizeEvent& event) -{ - wxFrame::OnSize(event); - panel->Layout(); -} - //----------------------------------------------------------------- // NewSizerFrame //----------------------------------------------------------------- @@ -372,7 +267,7 @@ NewSizerFrame::NewSizerFrame(wxFrame *frame, char *title, int x, int y ): // has a text ctrl in the middle. at the bottom, we have // two buttons which. - topsizer = new wxBox( wxVERTICAL ); + wxBox *topsizer = new wxBox( wxVERTICAL ); // 1) top: create wxStaticText with minimum size equal to its default size topsizer->Add( @@ -425,24 +320,10 @@ NewSizerFrame::NewSizerFrame(wxFrame *frame, char *title, int x, int y ): // don't allow frame to get smaller than what the sizers tell ye topsizer->SetSizeHints( this ); - // layout widgets - topsizer->Layout(); + SetSizer( topsizer ); + + SetAutoLayout( TRUE ); } -// This can later be removed if we integrate wxNewSizers -// into wxWindows - -BEGIN_EVENT_TABLE(NewSizerFrame, wxFrame) - EVT_SIZE(NewSizerFrame::OnSize) -END_EVENT_TABLE() - -void NewSizerFrame::OnSize(wxSizeEvent& event) -{ - wxFrame::OnSize(event); - - wxSize client_size( GetClientSize() ); - - topsizer->SetDimension( 0, 0, client_size.x, client_size.y ); -} diff --git a/samples/layout/layout.h b/samples/layout/layout.h index 14bbd7a502..7aad45fd82 100644 --- a/samples/layout/layout.h +++ b/samples/layout/layout.h @@ -33,7 +33,6 @@ class MyFrame: public wxFrame void LoadFile(wxCommandEvent& event); void Quit(wxCommandEvent& event); - void TestSizers(wxCommandEvent& event); void TestNewSizers(wxCommandEvent& event); void About(wxCommandEvent& event); @@ -62,25 +61,12 @@ class MyWindow: public wxWindow DECLARE_EVENT_TABLE() }; -class SizerFrame: public wxFrame -{ - public: - wxPanel *panel; - SizerFrame(wxFrame *frame, char *title, int x, int y, int w, int h); - void OnSize(wxSizeEvent& event); - - DECLARE_EVENT_TABLE() -}; - class NewSizerFrame: public wxFrame { public: wxPanel *panel; - wxNewSizer *topsizer; NewSizerFrame(wxFrame *frame, char *title, int x, int y ); - void OnSize(wxSizeEvent& event); - - DECLARE_EVENT_TABLE() + }; #define LAYOUT_QUIT 100 diff --git a/src/common/layout.cpp b/src/common/layout.cpp index e11c18f3f2..188d4c6d8f 100644 --- a/src/common/layout.cpp +++ b/src/common/layout.cpp @@ -47,57 +47,8 @@ #if !USE_SHARED_LIBRARY IMPLEMENT_DYNAMIC_CLASS(wxIndividualLayoutConstraint, wxObject) IMPLEMENT_DYNAMIC_CLASS(wxLayoutConstraints, wxObject) - IMPLEMENT_DYNAMIC_CLASS(wxSizer, wxObject) - IMPLEMENT_DYNAMIC_CLASS(wxRowColSizer, wxSizer) - IMPLEMENT_DYNAMIC_CLASS(wxSpacingSizer, wxSizer) #endif -/* -TODO: - - Non shrink-to-fit row-col behaviour. - - Give justification styles, so can e.g. centre - the rows & cols, distribute the available space... - - Shrink-to-fit: should resize outer window (e.g. dialog box) - if directly associated with this kind of window. - - How to deal with a rowcol that stretches in one direction - but shrinks-to-fit in other. E.g. a horizontal toolbar: the width - stretches to fit the frame, but the height is constant - or wraps around contents. The algorithm currently assumes - both dimensions have the same behaviour. Could assume a constant - height (absolute value). - - rowcol where each row or column is aligned (length of - largest element determines spacing) - - Groupbox sizer - - Analyze aesthetic dialog boxes and implement using sizers. - - What reuseable components can we provide? E.g. Ok/Cancel/Help - group of buttons. - - use wxStaticItems for aesthetic dialogs. - -*/ - -// Find margin sizes if a sizer, or zero otherwise -int wxSizerMarginX(wxWindowBase *win) -{ - if ( win->IsKindOf(CLASSINFO(wxSizer)) ) - { - wxSizer *sizer = (wxSizer *)win; - return sizer->GetBorderX(); - } - else - return 0; -} - -int wxSizerMarginY(wxWindowBase *win) -{ - if ( win->IsKindOf(CLASSINFO(wxSizer)) ) - { - wxSizer *sizer = (wxSizer *)win; - return sizer->GetBorderY(); - } - else - return 0; -} - wxIndividualLayoutConstraint::wxIndividualLayoutConstraint() { @@ -778,35 +729,35 @@ int wxIndividualLayoutConstraint::GetEdge(wxEdge which, { case wxLeft: { - return wxSizerMarginX(other); + return 0; } case wxTop: { - return wxSizerMarginY(other); + return 0; } case wxRight: { int w, h; other->GetClientSizeConstraint(&w, &h); - return w - wxSizerMarginX(other); + return w; } case wxBottom: { int w, h; other->GetClientSizeConstraint(&w, &h); - return h - wxSizerMarginY(other); + return h; } case wxWidth: { int w, h; other->GetClientSizeConstraint(&w, &h); - return w - 2*wxSizerMarginX(other); + return w; } case wxHeight: { int w, h; other->GetClientSizeConstraint(&w, &h); - return h - 2*wxSizerMarginY(other); + return h; } case wxCentreX: case wxCentreY: @@ -1181,590 +1132,4 @@ bool wxOldDoLayout(wxWindowBase *win) } #endif // WXWIN_COMPATIBILITY -wxSizer::wxSizer() -{ - sizerBehaviour = wxSizerNone; - borderX = 2; - borderY = 2; - sizerX = 0; - sizerY = 0; - sizerWidth = 0; - sizerHeight = 0; -} - -wxSizer::wxSizer(wxWindowBase *parent, wxSizerBehaviour behav) -{ - Create(parent, behav); -} - -bool wxSizer::Create(wxWindowBase *parent, wxSizerBehaviour behav) -{ - sizerBehaviour = behav; - borderX = 2; - borderY = 2; - m_sizerParent = parent; - sizerX = 0; - sizerY = 0; - sizerWidth = 0; - sizerHeight = 0; - - // A normal window can have just one top-level sizer - // associated with it. - if (!parent->IsKindOf(CLASSINFO(wxSizer))) - { - parent->SetSizer(this); - } - else - ((wxSizer *)parent)->AddSizerChild(this); - - switch (sizerBehaviour) - { - case wxSizerExpand: - { - // Defines a set of constraints - // to expand the sizer to fit the parent window - wxLayoutConstraints *c = new wxLayoutConstraints; - - c->left.SameAs(parent, wxLeft, 0); - c->top.SameAs(parent, wxTop, 0); - c->right.SameAs(parent, wxRight, 0); - c->bottom.SameAs(parent, wxBottom, 0); - - SetConstraints(c); - break; - } - case wxSizerShrink: - case wxSizerNone: - default: - { - } - } - return TRUE; -} - -wxSizer::~wxSizer() -{ - // Remove all children without deleting them, - // or ~wxbWindow will delete proper windows _twice_ - wxNode *node = GetChildren().First(); - while (node) - { - wxNode *next = node->Next(); - wxWindowBase *win = (wxWindowBase *)node->Data(); - if (!win->IsKindOf(CLASSINFO(wxSizer))) - { - delete node; - win->SetSizerParent((wxWindowBase *) NULL); - } - else - { - RemoveSizerChild(win); - delete win; - } - node = next; - } - - if (m_sizerParent) // && !m_sizerParent->IsKindOf(CLASSINFO(wxSizer))) - { - m_sizerParent->SetSizer((wxSizer *) NULL); - m_sizerParent = (wxWindowBase *) NULL; - } - -} - -void wxSizer::SetBorder(int x, int y) -{ - borderX = x; - borderY = y; - /* No: the margin is for inside, not outside (expansion) - - if ( GetConstraints() ) - { - GetConstraints()->left.SetMargin(x); - GetConstraints()->right.SetMargin(x); - GetConstraints()->top.SetMargin(y); - GetConstraints()->bottom.SetMargin(y); - } - */ - -} - -void wxSizer::AddSizerChild(wxWindowBase *child) -{ - child->SetSizerParent(this); - GetChildren().Append(child); - - // Add some constraints for the purpose of storing - // the relative position of the window/sizer - // during layout calculations. - if (!child->GetConstraints()) - { - wxLayoutConstraints *c = new wxLayoutConstraints; - c->left.AsIs(); - c->top.AsIs(); - c->width.AsIs(); - c->height.AsIs(); - int w, h; - child->GetSize(&w, &h); - c->width.SetValue(w); - c->height.SetValue(h); - - child->SetConstraints(c); - } -} - -void wxSizer::RemoveSizerChild(wxWindowBase *child) -{ - GetChildren().DeleteObject(child); -} - -void wxSizer::DoSetSize(int x, int y, int w, int h, int WXUNUSED(flags)) -{ - wxLayoutConstraints *constr = GetConstraints(); - if (x != -1) - { - sizerX = x; - if (constr) - constr->left.SetValue(x); - } - if (y != -1) - { - sizerY = y; - if (constr) - constr->top.SetValue(y); - } - if (w != -1) - { - sizerWidth = w; - if (constr) - constr->width.SetValue(w); - } - if (h != -1) - { - sizerHeight = h; - if (constr) - constr->height.SetValue(h); - } -} - -void wxSizer::DoGetSize(int *w, int *h) const -{ - *w = sizerWidth; - *h = sizerHeight; -} - -void wxSizer::DoGetPosition(int *x, int *y) const -{ - *x = sizerX; - *y = sizerY; -} - -bool wxSizer::LayoutPhase1(int *noChanges) -{ - *noChanges = 0; - switch (sizerBehaviour) - { - case wxSizerExpand: - { - if (!m_sizerParent) - { - wxMessageBox(_("wxExpandSizer has no parent!"), _("Sizer error"), wxOK); - return TRUE; - } - - // Set the size to fill the parent client area - int pw, ph; - m_sizerParent->GetClientSize(&pw, &ph); - SetSize(GetBorderX(), GetBorderY(), pw - 2*GetBorderX(), ph - 2*GetBorderY()); - wxLayoutConstraints *constr = GetConstraints(); - - // Fill in the constraints - if (constr) - { - constr->left.SetValue(0); constr->left.SetDone(TRUE); - constr->top.SetValue(0); constr->right.SetDone(TRUE); - constr->width.SetValue(pw); constr->width.SetDone(TRUE); - constr->height.SetValue(ph); constr->height.SetDone(TRUE); - } - - return TRUE; - break; - } - case wxSizerShrink: - { - wxLayoutConstraints *constr = GetConstraints(); - - if (constr) - { - // Force the constraint to have as-is width and height - // if we're in shrink-to-fit mode, because if left unconstrained, - // SatisfyConstraints will fail. The shrink-to-fit option - // essentially specifies the width and height as 'whatever I calculate'. - constr->width.AsIs(); - constr->height.AsIs(); - } - DoPhase(1); - DoPhase(2); - // Find the bounding box and set own size - int maxX = 0; - int maxY = 0; - - wxNode *node = GetChildren().First(); - while (node) - { - int x, y, width, height; - wxWindowBase *win = (wxWindowBase *)node->Data(); - win->GetSizeConstraint(&width, &height); - win->GetPositionConstraint(&x, &y); - if ((x+width) > maxX) - maxX = (x + width); - if ((y+height) > maxY) - maxY = (y + height); - - node = node->Next(); - } - SetSize(GetBorderX(), GetBorderY(), maxX, maxY); - - // If this is the only sizer for the parent, size the parent to this sizer. - if ( m_sizerParent && (m_sizerParent->GetSizer() == this) ) - m_sizerParent->SetClientSize(maxX + 2*GetBorderX(), maxY + 2*GetBorderY()); - - return TRUE; - break; - } - case wxSizerNone: - { - wxLayoutConstraints *constr = GetConstraints(); - if (constr) - { - bool success = constr->SatisfyConstraints(this, noChanges); - if (success) - { - int x = constr->left.GetValue(); - int y = constr->top.GetValue(); - int w = constr->width.GetValue(); - int h = constr->height.GetValue(); - SetSize(x, y, w, h); - } - return success; - } - else - return TRUE; - break; - } - } - return TRUE; - -} - -bool wxSizer::LayoutPhase2(int *noChanges) -{ - *noChanges = 0; - - switch (sizerBehaviour) - { - case wxSizerExpand: - { - // Layout children - DoPhase(1); - DoPhase(2); - return TRUE; - } - case wxSizerShrink: - { - wxLayoutConstraints *constr = GetConstraints(); - if (constr) - { - bool success = constr->SatisfyConstraints(this, noChanges); - if (success) - { - int x = constr->left.GetValue(); - int y = constr->top.GetValue(); - Move(x, y); - } - return success; - } - break; - } - case wxSizerNone: - { - // Layout children - DoPhase(1); - DoPhase(2); - - // Is this a dumb fix for lack of constraint evaluation? - wxLayoutConstraints *constr = GetConstraints(); - if (constr) - { - bool success = constr->SatisfyConstraints(this, noChanges); - if (success) - { - int x = constr->left.GetValue(); - int y = constr->top.GetValue(); - int w = constr->width.GetValue(); - int h = constr->height.GetValue(); - SetSize(x, y, w, h); - } - return success; - } - else - return TRUE; - } - } - return TRUE; -} - -/* - * wxRowColSizer - */ - -wxRowColSizer::wxRowColSizer() -{ - rowOrCol = TRUE; - rowOrColSize = 20; - xSpacing = 2; - ySpacing = 2; -} - -wxRowColSizer::wxRowColSizer(wxWindowBase *parent, bool rc, int n, wxSizerBehaviour behav) -{ - Create(parent, rc, n, behav); -} - -bool wxRowColSizer::Create(wxWindowBase *parent, bool rc, int n, wxSizerBehaviour behav) -{ - wxSizer::Create(parent, behav); - - rowOrCol = rc; - rowOrColSize = n; - xSpacing = 2; - ySpacing = 2; - - return TRUE; -} - -wxRowColSizer::~wxRowColSizer() -{ -} - -bool wxRowColSizer::LayoutPhase1(int *noChanges) -{ - *noChanges = 0; - wxLayoutConstraints *constr = GetConstraints(); - - if (constr) - { - // Force the constraint to have as-is width and height - // if we're in shrink-to-fit mode, because if left unconstrained, - // SatisfyConstraints will fail. The shrink-to-fit option - // essentially specifies the width and height as 'whatever I calculate'. - if (sizerBehaviour == wxSizerShrink) - { - constr->width.AsIs(); - constr->height.AsIs(); - } - - // Only evaluate the constraints FIRST if we're NOT - // in shrink-to-fit mode, i.e. we want to size the rowcol - // first, then lay the children out in the space we've calculated. - if (sizerBehaviour != wxSizerShrink) - { - bool success = constr->SatisfyConstraints(this, noChanges); - if (success) - { - int x = constr->left.GetValue(); - int y = constr->top.GetValue(); - int w = constr->width.GetValue(); - int h = constr->height.GetValue(); - SetSize(x, y, w, h); - } - else - return FALSE; - - // Continue to do the rest of the phase when the constraints have been - // satisfied, i.e. we're on the last iteration of phase 1 and - // can now do the actual rowcol laying out. - } - } - - // If we ARE in shrink-to-fit mode, we must now - // calculate the child sizes BEFORE laying out in rows or columns. - if (sizerBehaviour == wxSizerShrink) - { - DoPhase(1); - DoPhase(2); - - // WILL THE WINDOW BE SIZED CORRECTLY AT THIS POINT? - // CHECK CONSTRAINTS IF ANY... - int noRows = 0; - int noCols = 0; - int currentX = borderX; - int currentY = borderY; - int maxX = currentX; - int maxY = currentY; - - wxNode *node = GetChildren().First(); - while (node) - { - wxWindowBase *win = (wxWindowBase *)node->Data(); - int childWidth, childHeight; - if (win->GetConstraints() && - win->GetConstraints()->width.GetDone() && - win->GetConstraints()->height.GetDone()) - { - childWidth = win->GetConstraints()->width.GetValue(); - childHeight = win->GetConstraints()->height.GetValue(); - } - else - win->GetSize(&childWidth, &childHeight); - - win->MoveConstraint(currentX, currentY); - - if ((currentX + childWidth) > maxX) - maxX = (currentX + childWidth); - if ((currentY + childHeight) > maxY) - maxY = (currentY + childHeight); - - if (rowOrCol) - { - currentX += childWidth + xSpacing; - noCols ++; - - // Reset to start of row - if (noCols == rowOrColSize) - { - currentX = borderX; - currentY += childHeight + ySpacing; - noCols = 0; - } - } - else - { - currentY += childHeight + ySpacing; - noRows ++; - - // Reset to start of col - if (noRows == rowOrColSize) - { - currentY = borderY; - currentX += childWidth + xSpacing; - noRows = 0; - } - } - - node = node->Next(); - } - maxX += borderX; - maxY += borderY; - - SetSize(-1, -1, maxX, maxY); - } - return TRUE; -} - -bool wxRowColSizer::LayoutPhase2(int *noChanges) -{ - *noChanges = 0; - - // If shrink-to-fit, it's only at Phase 2 that we know the size of - // the wxRowColSizer, and now we can evaluate the - // constraints and pass result back up to parent. - // This implements a depth-first strategy - if (sizerBehaviour == wxSizerShrink) - { - wxLayoutConstraints *constr = GetConstraints(); - if (constr) - { - bool success = constr->SatisfyConstraints(this, noChanges); - if (success) - { - int x = constr->left.GetValue(); - int y = constr->top.GetValue(); - Move(x, y); - } - return success; - } - else return TRUE; - } - else - { - // Lay out the children: breadth-first strategy. - DoPhase(1); - DoPhase(2); - - // Space them - } - return TRUE; -} - - -/* - * wxSpacingSizer - */ - -wxSpacingSizer::wxSpacingSizer() -{ -} - -wxSpacingSizer::wxSpacingSizer(wxWindowBase *parent) -{ - Create(parent); -} - -wxSpacingSizer::wxSpacingSizer(wxWindowBase *parent, wxRelationship rel, wxWindowBase *other, int spacing) -{ - Create(parent, rel, other, spacing); -} - -bool wxSpacingSizer::Create(wxWindowBase *parent) -{ - wxSizer::Create(parent); - return TRUE; -} - -bool wxSpacingSizer::Create(wxWindowBase *parent, wxRelationship rel, wxWindowBase *other, int spacing) -{ - wxLayoutConstraints *c = new wxLayoutConstraints; - - wxSizer::Create(parent); - - switch ( rel ) - { - case wxLeftOf : - c->width.Absolute (spacing); - c->top.SameAs (other, wxTop); - c->bottom.SameAs (other, wxBottom); - c->right.LeftOf (other); - break; - case wxRightOf : - c->width.Absolute (spacing); - c->top.SameAs (other, wxTop); - c->bottom.SameAs (other, wxBottom); - c->left.RightOf (other); - break; - case wxBelow : - c->height.Absolute (spacing); - c->left.SameAs (other, wxLeft); - c->right.SameAs (other, wxRight); - c->top.Below (other); - break; - case wxAbove : - c->height.Absolute (spacing); - c->left.SameAs (other, wxLeft); - c->right.SameAs (other, wxRight); - c->bottom.Above (other); - break; - - default : - break; - } - SetConstraints(c); - - return TRUE; -} - -wxSpacingSizer::~wxSpacingSizer() -{ -} - #endif // wxUSE_CONSTRAINTS diff --git a/src/common/sizer.cpp b/src/common/sizer.cpp index 5a004dd535..9a140fd684 100644 --- a/src/common/sizer.cpp +++ b/src/common/sizer.cpp @@ -1,6 +1,6 @@ ///////////////////////////////////////////////////////////////////////////// // Name: sizer.cpp -// Purpose: provide wxNewSizer class for layounting +// Purpose: provide new wxSizer class for layounting // Author: Robert Roebling and Robin Dunn // Modified by: // Created: @@ -24,13 +24,13 @@ #include "wx/utils.h" //--------------------------------------------------------------------------- -// wxNewSizerItem +// wxSizerItem //--------------------------------------------------------------------------- -wxNewSizerItem::wxNewSizerItem( int width, int height, int option, int flag, int border ) +wxSizerItem::wxSizerItem( int width, int height, int option, int flag, int border ) { m_window = (wxWindow *) NULL; - m_sizer = (wxNewSizer *) NULL; + m_sizer = (wxSizer *) NULL; m_option = option; m_border = border; m_flag = flag; @@ -43,10 +43,10 @@ wxNewSizerItem::wxNewSizerItem( int width, int height, int option, int flag, int m_size = m_minSize; } -wxNewSizerItem::wxNewSizerItem( wxWindow *window, int option, int flag, int border ) +wxSizerItem::wxSizerItem( wxWindow *window, int option, int flag, int border ) { m_window = window; - m_sizer = (wxNewSizer *) NULL; + m_sizer = (wxSizer *) NULL; m_option = option; m_border = border; m_flag = flag; @@ -58,7 +58,7 @@ wxNewSizerItem::wxNewSizerItem( wxWindow *window, int option, int flag, int bord // m_size = ... } -wxNewSizerItem::wxNewSizerItem( wxNewSizer *sizer, int option, int flag, int border ) +wxSizerItem::wxSizerItem( wxSizer *sizer, int option, int flag, int border ) { m_window = (wxWindow *) NULL; m_sizer = sizer; @@ -73,10 +73,10 @@ wxNewSizerItem::wxNewSizerItem( wxNewSizer *sizer, int option, int flag, int bor // m_size = ... } -wxSize wxNewSizerItem::GetSize() +wxSize wxSizerItem::GetSize() { wxSize ret; - if (IsNewSizer()) + if (IsSizer()) ret = m_sizer->GetSize(); else if (IsWindow()) @@ -95,10 +95,10 @@ wxSize wxNewSizerItem::GetSize() return ret; } -wxSize wxNewSizerItem::CalcMin() +wxSize wxSizerItem::CalcMin() { wxSize ret; - if (IsNewSizer()) + if (IsSizer()) ret = m_sizer->CalcMin(); /* The minimum size of a window should be the @@ -123,7 +123,7 @@ wxSize wxNewSizerItem::CalcMin() return ret; } -void wxNewSizerItem::SetDimension( wxPoint pos, wxSize size ) +void wxSizerItem::SetDimension( wxPoint pos, wxSize size ) { if (m_flag & wxWEST) { @@ -144,7 +144,7 @@ void wxNewSizerItem::SetDimension( wxPoint pos, wxSize size ) size.y -= m_border; } - if (IsNewSizer()) + if (IsSizer()) m_sizer->SetDimension( pos.x, pos.y, size.x, size.y ); if (IsWindow()) @@ -153,67 +153,67 @@ void wxNewSizerItem::SetDimension( wxPoint pos, wxSize size ) m_size = size; } -bool wxNewSizerItem::IsWindow() +bool wxSizerItem::IsWindow() { return (m_window != NULL); } -bool wxNewSizerItem::IsNewSizer() +bool wxSizerItem::IsSizer() { return (m_sizer != NULL); } -bool wxNewSizerItem::IsSpacer() +bool wxSizerItem::IsSpacer() { return (m_window == NULL) && (m_sizer == NULL); } //--------------------------------------------------------------------------- -// wxNewSizer +// wxSizer //--------------------------------------------------------------------------- -wxNewSizer::wxNewSizer() +wxSizer::wxSizer() { m_children.DeleteContents( TRUE ); } -wxNewSizer::~wxNewSizer() +wxSizer::~wxSizer() { } -void wxNewSizer::Add( wxWindow *window, int option, int flag, int border ) +void wxSizer::Add( wxWindow *window, int option, int flag, int border ) { - m_children.Append( new wxNewSizerItem( window, option, flag, border ) ); + m_children.Append( new wxSizerItem( window, option, flag, border ) ); } -void wxNewSizer::Add( wxNewSizer *sizer, int option, int flag, int border ) +void wxSizer::Add( wxSizer *sizer, int option, int flag, int border ) { - m_children.Append( new wxNewSizerItem( sizer, option, flag, border ) ); + m_children.Append( new wxSizerItem( sizer, option, flag, border ) ); } -void wxNewSizer::Add( int width, int height, int option, int flag, int border ) +void wxSizer::Add( int width, int height, int option, int flag, int border ) { - m_children.Append( new wxNewSizerItem( width, height, option, flag, border ) ); + m_children.Append( new wxSizerItem( width, height, option, flag, border ) ); } -void wxNewSizer::Fit( wxWindow *window ) +void wxSizer::Fit( wxWindow *window ) { window->SetSize( GetMinWindowSize( window ) ); } -void wxNewSizer::Layout() +void wxSizer::Layout() { m_size = CalcMin(); RecalcSizes(); } -void wxNewSizer::SetSizeHints( wxWindow *window ) +void wxSizer::SetSizeHints( wxWindow *window ) { wxSize size( GetMinWindowSize( window ) ); window->SetSizeHints( size.x, size.y ); } -wxSize wxNewSizer::GetMinWindowSize( wxWindow *window ) +wxSize wxSizer::GetMinWindowSize( wxWindow *window ) { wxSize minSize( GetMinSize() ); wxSize size( window->GetSize() ); @@ -222,7 +222,7 @@ wxSize wxNewSizer::GetMinWindowSize( wxWindow *window ) minSize.y+size.y-client_size.y ); } -void wxNewSizer::SetDimension( int x, int y, int width, int height ) +void wxSizer::SetDimension( int x, int y, int width, int height ) { m_position.x = x; m_position.y = y; @@ -269,7 +269,7 @@ void wxBox::RecalcSizes() wxNode *node = m_children.GetFirst(); while (node) { - wxNewSizerItem *item = (wxNewSizerItem*) node->Data(); + wxSizerItem *item = (wxSizerItem*) node->Data(); int weight = 1; if (item->GetOption()) @@ -342,7 +342,7 @@ wxSize wxBox::CalcMin() wxNode *node = m_children.GetFirst(); while (node) { - wxNewSizerItem *item = (wxNewSizerItem*) node->Data(); + wxSizerItem *item = (wxSizerItem*) node->Data(); int weight = 1; if (item->GetOption()) diff --git a/src/common/wincmn.cpp b/src/common/wincmn.cpp index ae2c62a671..d754cab345 100644 --- a/src/common/wincmn.cpp +++ b/src/common/wincmn.cpp @@ -43,6 +43,7 @@ #if wxUSE_CONSTRAINTS #include "wx/layout.h" + #include "wx/sizer.h" #endif // wxUSE_CONSTRAINTS #if wxUSE_DRAG_AND_DROP @@ -131,7 +132,6 @@ void wxWindowBase::InitBase() m_constraints = (wxLayoutConstraints *) NULL; m_constraintsInvolvedIn = (wxWindowList *) NULL; m_windowSizer = (wxSizer *) NULL; - m_sizerParent = (wxWindowBase *) NULL; m_autoLayout = FALSE; #endif // wxUSE_CONSTRAINTS @@ -234,9 +234,6 @@ wxWindowBase::~wxWindowBase() if ( m_windowSizer ) delete m_windowSizer; - // If this is a child of a sizer, remove self from parent - if ( m_sizerParent ) - m_sizerParent->RemoveChild(this); #endif // wxUSE_CONSTRAINTS #if wxUSE_DRAG_AND_DROP @@ -889,39 +886,35 @@ void wxWindowBase::DeleteRelatedConstraints() void wxWindowBase::SetSizer(wxSizer *sizer) { + if (m_windowSizer) delete m_windowSizer; + m_windowSizer = sizer; - if ( sizer ) - sizer->SetSizerParent(this); } bool wxWindowBase::Layout() { - if ( GetConstraints() ) - { - int w, h; - GetClientSize(&w, &h); - GetConstraints()->width.SetValue(w); - GetConstraints()->height.SetValue(h); - } - - // If top level (one sizer), evaluate the sizer's constraints. + int w, h; + GetClientSize(&w, &h); + + // If there is a sizer, use it instead of the constraints if ( GetSizer() ) { - int noChanges; - GetSizer()->ResetConstraints(); // Mark all constraints as unevaluated - GetSizer()->LayoutPhase1(&noChanges); - GetSizer()->LayoutPhase2(&noChanges); - GetSizer()->SetConstraintSizes(); // Recursively set the real window sizes + GetSizer()->SetDimension( 0, 0, w, h ); return TRUE; } - else + + if ( GetConstraints() ) { - // Otherwise, evaluate child constraints - ResetConstraints(); // Mark all constraints as unevaluated - DoPhase(1); // Just one phase need if no sizers involved - DoPhase(2); - SetConstraintSizes(); // Recursively set the real window sizes + GetConstraints()->width.SetValue(w); + GetConstraints()->height.SetValue(h); } + + // Evaluate child constraints + ResetConstraints(); // Mark all constraints as unevaluated + DoPhase(1); // Just one phase need if no sizers involved + DoPhase(2); + SetConstraintSizes(); // Recursively set the real window sizes + return TRUE; } @@ -1029,17 +1022,15 @@ void wxWindowBase::SetConstraintSizes(bool recurse) int w = constr->width.GetValue(); int h = constr->height.GetValue(); - // If we don't want to resize this window, just move it... if ( (constr->width.GetRelationship() != wxAsIs ) || - (constr->height.GetRelationship() != wxAsIs)) + (constr->height.GetRelationship() != wxAsIs) ) { - // Calls Layout() recursively. AAAGH. How can we stop that. - // Simply take Layout() out of non-top level OnSizes. - SizerSetSize(x, y, w, h); + SetSize(x, y, w, h); } else { - SizerMove(x, y); + // If we don't want to resize this window, just move it... + Move(x, y); } } else if ( constr ) @@ -1074,36 +1065,6 @@ void wxWindowBase::SetConstraintSizes(bool recurse) } } -// This assumes that all sizers are 'on' the same window, i.e. the parent of -// this window. -void wxWindowBase::TransformSizerToActual(int *x, int *y) const -{ - if ( !m_sizerParent || m_sizerParent->IsTopLevel() ) - return; - - int xp, yp; - m_sizerParent->GetPosition(&xp, &yp); - m_sizerParent->TransformSizerToActual(&xp, &yp); - *x += xp; - *y += yp; -} - -void wxWindowBase::SizerSetSize(int x, int y, int w, int h) -{ - int xx = x; - int yy = y; - TransformSizerToActual(&xx, &yy); - SetSize(xx, yy, w, h); -} - -void wxWindowBase::SizerMove(int x, int y) -{ - int xx = x; - int yy = y; - TransformSizerToActual(&xx, &yy); - Move(xx, yy); -} - // Only set the size/position of the constraint (if any) void wxWindowBase::SetSizeConstraint(int x, int y, int w, int h) { diff --git a/src/gtk/button.cpp b/src/gtk/button.cpp index dc7dd01c59..e109966054 100644 --- a/src/gtk/button.cpp +++ b/src/gtk/button.cpp @@ -92,9 +92,13 @@ bool wxButton::Create( wxWindow *parent, wxWindowID id, const wxString &label, SetLabel(label); + int x = 0; int y = 0; + wxFont new_font( parent->GetFont() ); + GetTextExtent( m_label, &x, &y, (int*)NULL, (int*)NULL, &new_font ); + wxSize newSize = size; - if (newSize.x == -1) newSize.x = 15+gdk_string_measure( m_widget->style->font, label.mbc_str() ); - if (newSize.y == -1) newSize.y = 26; + if (newSize.x == -1) newSize.x = 12+x; + if (newSize.y == -1) newSize.y = 11+y; SetSize( newSize.x, newSize.y ); gtk_signal_connect( GTK_OBJECT(m_widget), "clicked", diff --git a/src/gtk/choicdlg.cpp b/src/gtk/choicdlg.cpp index 903e1009d8..5aeb8dec86 100644 --- a/src/gtk/choicdlg.cpp +++ b/src/gtk/choicdlg.cpp @@ -28,6 +28,7 @@ #include "wx/listbox.h" #include "wx/stattext.h" #include "wx/intl.h" + #include "wx/sizer.h" #endif #if wxUSE_STATLINE @@ -36,24 +37,19 @@ #include "wx/gtk/choicdlg.h" -/* Split message, using constraints to position controls */ -static wxSize wxSplitMessage2( const wxString &message, wxWindow *parent ) +static void wxSplitMessage2( const wxString &message, wxWindow *parent, wxSizer* sizer ) { - int y = 10; - int w = 50; - wxString line( _T("") ); + wxString line; for (size_t pos = 0; pos < message.Len(); pos++) { if (message[pos] == _T('\n')) { if (!line.IsEmpty()) { - wxStaticText *s1 = new wxStaticText( parent, -1, line, wxPoint(15,y) ); - wxSize size1( s1->GetSize() ); - if (size1.x > w) w = size1.x; + wxStaticText *s1 = new wxStaticText( parent, -1, line ); + sizer->Add( s1 ); line = _T(""); } - y += 18; } else { @@ -61,16 +57,12 @@ static wxSize wxSplitMessage2( const wxString &message, wxWindow *parent ) } } + // remaining text behind last '\n' if (!line.IsEmpty()) { - wxStaticText *s2 = new wxStaticText( parent, -1, line, wxPoint(15,y) ); - wxSize size2( s2->GetSize() ); - if (size2.x > w) w = size2.x; + wxStaticText *s2 = new wxStaticText( parent, -1, line ); + sizer->Add( s2 ); } - - y += 18; - - return wxSize(w+30,y); } @@ -202,7 +194,7 @@ IMPLEMENT_CLASS(wxSingleChoiceDialog, wxDialog) wxSingleChoiceDialog::wxSingleChoiceDialog(wxWindow *parent, const wxString& message, const wxString& caption, int n, const wxString *choices, char **clientData, long style, const wxPoint& pos): - wxDialog(parent, -1, caption, pos, wxDefaultSize, wxDEFAULT_DIALOG_STYLE|wxDIALOG_MODAL|wxTAB_TRAVERSAL) + wxDialog(parent, -1, caption, pos, wxDefaultSize, wxDEFAULT_DIALOG_STYLE|wxRESIZE_BORDER|wxDIALOG_MODAL|wxTAB_TRAVERSAL) { Create(parent, message, caption, n, choices, clientData, style); } @@ -240,17 +232,15 @@ bool wxSingleChoiceDialog::Create( wxWindow *WXUNUSED(parent), const wxString& m wxBeginBusyCursor(); - wxSize message_size( wxSplitMessage2( message, this ) ); + wxBox *topsizer = new wxBox( wxVERTICAL ); - wxButton *ok = (wxButton *) NULL; - wxButton *cancel = (wxButton *) NULL; - wxList m_buttons; - - int y = message_size.y + 15; - - int listbox_height = 150; - - wxListBox *listBox = new wxListBox( this, wxID_LISTBOX, wxPoint(10, y), wxSize(360, listbox_height), + // 1) text message + wxBox *textsizer = new wxBox( wxVERTICAL ); + wxSplitMessage2( message, this, textsizer ); + topsizer->Add( textsizer, 0, wxALL, 10 ); + + // 2) list box + wxListBox *listBox = new wxListBox( this, wxID_LISTBOX, wxDefaultPosition, wxSize(160,100) , n, choices, wxLB_ALWAYS_SB ); listBox->SetSelection( m_selection ); if (clientData) @@ -258,53 +248,46 @@ bool wxSingleChoiceDialog::Create( wxWindow *WXUNUSED(parent), const wxString& m for (int i = 0; i < n; i++) listBox->SetClientData(i, clientData[i]); } - - y += listbox_height + 35; + topsizer->Add( listBox, 1, wxEXPAND | wxLEFT|wxRIGHT, 15 ); - if (style & wxOK) - { - ok = new wxButton( this, wxID_OK, _("OK"), wxPoint(-1,y), wxSize(80,-1) ); - m_buttons.Append( ok ); - } - if (style & wxCANCEL) - { - cancel = new wxButton( this, wxID_CANCEL, _("Cancel"), wxPoint(-1,y), wxSize(80,-1) ); - m_buttons.Append( cancel ); - } +#if wxUSE_STATLINE + // 3) static line + topsizer->Add( new wxStaticLine( this, -1 ), 0, wxEXPAND | wxLEFT|wxRIGHT|wxTOP, 3 ); +#endif - if (ok) + + // 4) buttons + wxBox *buttonsizer = new wxBox( wxHORIZONTAL ); + + wxButton *ok = (wxButton *) NULL; + if (style & wxOK) { - ok->SetDefault(); - ok->SetFocus(); + ok = new wxButton( this, wxID_OK, _("OK") ); + buttonsizer->Add( ok, 0, wxLEFT|wxRIGHT, 10 ); } - int w = m_buttons.GetCount() * 100; - if (message_size.x > w) w = message_size.x; - int space = w / (m_buttons.GetCount()*2); - - listBox->SetSize( 20, -1, w-10, listbox_height ); - - int m = 0; - wxNode *node = m_buttons.First(); - while (node) + wxButton *cancel = (wxButton *) NULL; + if (style & wxCANCEL) { - wxWindow *win = (wxWindow*)node->Data(); - int x = (m*2+1)*space - 40 + 15; - win->Move( x, -1 ); - node = node->Next(); - m++; + cancel = new wxButton( this, wxID_CANCEL, _("Cancel") ); + buttonsizer->Add( cancel, 0, wxLEFT|wxRIGHT, 10 ); } -#if wxUSE_STATLINE - int edge_margin = 7; - (void) new wxStaticLine( this, -1, wxPoint(edge_margin,y-20), wxSize(w+30-2*edge_margin, 5) ); -#endif - - SetSize( w+30, y+40 ); + topsizer->Add( buttonsizer, 0, wxCENTRE | wxALL, 10 ); + + topsizer->SetSizeHints( this ); + topsizer->Fit( this ); + SetSizer( topsizer ); + SetAutoLayout( TRUE ); Centre( wxBOTH ); + if (ok) + ok->SetDefault(); + + listBox->SetFocus(); + wxEndBusyCursor(); return TRUE; diff --git a/src/gtk/dcclient.cpp b/src/gtk/dcclient.cpp index 6ec3b44223..81bd578de4 100644 --- a/src/gtk/dcclient.cpp +++ b/src/gtk/dcclient.cpp @@ -304,6 +304,7 @@ void wxWindowDC::DoDrawLines( int n, wxPoint points[], long xoffset, long yoffse long x2 = XLOG2DEV(points[i+1].x + xoffset); long y1 = YLOG2DEV(points[i].y + yoffset); // oh, what a waste long y2 = YLOG2DEV(points[i+1].y + yoffset); + if (m_window) gdk_draw_line( m_window, m_penGC, x1, y1, x2, y2 ); @@ -327,7 +328,7 @@ void wxWindowDC::DoDrawPolygon( int n, wxPoint points[], long xoffset, long yoff CalcBoundingBox( points[i].x + xoffset, points[i].y + yoffset ); } - if (m_brush.GetStyle() != wxTRANSPARENT) + if ((m_brush.GetStyle() != wxTRANSPARENT) && m_window) gdk_draw_polygon (m_window, m_brushGC, TRUE, gdkpoints, n); // To do: Fillstyle @@ -1039,29 +1040,26 @@ void wxWindowDC::SetBackground( const wxBrush &brush ) gdk_gc_set_background( m_penGC, m_backgroundBrush.GetColour().GetColor() ); gdk_gc_set_background( m_bgGC, m_backgroundBrush.GetColour().GetColor() ); gdk_gc_set_foreground( m_bgGC, m_backgroundBrush.GetColour().GetColor() ); - - GdkFill fillStyle = GDK_SOLID; - switch (m_backgroundBrush.GetStyle()) - { - case wxSOLID: - case wxTRANSPARENT: - break; - default: - fillStyle = GDK_STIPPLED; - } - - gdk_gc_set_fill( m_bgGC, fillStyle ); + + gdk_gc_set_fill( m_bgGC, GDK_SOLID ); if ((m_backgroundBrush.GetStyle() == wxSTIPPLE) && (m_backgroundBrush.GetStipple()->Ok())) { if (m_backgroundBrush.GetStipple()->GetPixmap()) + { + gdk_gc_set_fill( m_bgGC, GDK_TILED ); gdk_gc_set_tile( m_bgGC, m_backgroundBrush.GetStipple()->GetPixmap() ); + } else + { + gdk_gc_set_fill( m_bgGC, GDK_STIPPLED ); gdk_gc_set_stipple( m_bgGC, m_backgroundBrush.GetStipple()->GetBitmap() ); + } } if (IS_HATCH(m_backgroundBrush.GetStyle())) { + gdk_gc_set_fill( m_bgGC, GDK_STIPPLED ); int num = m_backgroundBrush.GetStyle() - wxBDIAGONAL_HATCH; gdk_gc_set_stipple( m_bgGC, hatches[num] ); } diff --git a/src/gtk/radiobox.cpp b/src/gtk/radiobox.cpp index 5328d1565d..dcd089fa7e 100644 --- a/src/gtk/radiobox.cpp +++ b/src/gtk/radiobox.cpp @@ -271,7 +271,7 @@ wxSize wxRadioBox::LayoutItems() node = node->Next(); } res.x = x+4; - res.y = 42; + res.y = 40; } return res; diff --git a/src/gtk/textdlg.cpp b/src/gtk/textdlg.cpp index a0267ad3f9..db9257d998 100644 --- a/src/gtk/textdlg.cpp +++ b/src/gtk/textdlg.cpp @@ -28,6 +28,7 @@ #include "wx/stattext.h" #include "wx/textctrl.h" #include "wx/intl.h" + #include "wx/sizer.h" #endif #if wxUSE_STATLINE @@ -36,24 +37,19 @@ #include "wx/gtk/textdlg.h" -/* Split message, using constraints to position controls */ -static wxSize wxSplitMessage2( const wxString &message, wxWindow *parent ) +static void wxSplitMessage2( const wxString &message, wxWindow *parent, wxSizer* sizer ) { - int y = 10; - int w = 50; - wxString line( _T("") ); + wxString line; for (size_t pos = 0; pos < message.Len(); pos++) { if (message[pos] == _T('\n')) { if (!line.IsEmpty()) { - wxStaticText *s1 = new wxStaticText( parent, -1, line, wxPoint(15,y) ); - wxSize size1( s1->GetSize() ); - if (size1.x > w) w = size1.x; + wxStaticText *s1 = new wxStaticText( parent, -1, line ); + sizer->Add( s1 ); line = _T(""); } - y += 18; } else { @@ -61,16 +57,12 @@ static wxSize wxSplitMessage2( const wxString &message, wxWindow *parent ) } } + // remaining text behind last '\n' if (!line.IsEmpty()) { - wxStaticText *s2 = new wxStaticText( parent, -1, line, wxPoint(15,y) ); - wxSize size2( s2->GetSize() ); - if (size2.x > w) w = size2.x; + wxStaticText *s2 = new wxStaticText( parent, -1, line ); + sizer->Add( s2 ); } - - y += 18; - - return wxSize(w+30,y); } // wxTextEntryDialog @@ -92,64 +84,55 @@ wxTextEntryDialog::wxTextEntryDialog(wxWindow *parent, const wxString& message, wxBeginBusyCursor(); - wxSize message_size( wxSplitMessage2( message, this ) ); + wxBox *topsizer = new wxBox( wxVERTICAL ); - wxButton *ok = (wxButton *) NULL; - wxButton *cancel = (wxButton *) NULL; - wxList m_buttons; - - int y = message_size.y + 15; - - wxTextCtrl *textCtrl = new wxTextCtrl(this, wxID_TEXT, value, wxPoint(-1, y), wxSize(350, -1)); - - y += 65; + // 1) text message + wxBox *textsizer = new wxBox( wxVERTICAL ); + wxSplitMessage2( message, this, textsizer ); + topsizer->Add( textsizer, 0, wxALL, 10 ); - if (style & wxOK) - { - ok = new wxButton( this, wxID_OK, _("OK"), wxPoint(-1,y), wxSize(80,-1) ); - m_buttons.Append( ok ); - } + // 2) text ctrl + wxTextCtrl *textCtrl = new wxTextCtrl(this, wxID_TEXT, value, wxDefaultPosition, wxSize(300, -1)); + topsizer->Add( textCtrl, 1, wxEXPAND | wxLEFT|wxRIGHT, 15 ); - if (style & wxCANCEL) - { - cancel = new wxButton( this, wxID_CANCEL, _("Cancel"), wxPoint(-1,y), wxSize(80,-1) ); - m_buttons.Append( cancel ); - } +#if wxUSE_STATLINE + // 3) static line + topsizer->Add( new wxStaticLine( this, -1 ), 0, wxEXPAND | wxLEFT|wxRIGHT|wxTOP, 3 ); +#endif - if (ok) + + // 4) buttons + wxBox *buttonsizer = new wxBox( wxHORIZONTAL ); + + wxButton *ok = (wxButton *) NULL; + if (style & wxOK) { - ok->SetDefault(); - ok->SetFocus(); + ok = new wxButton( this, wxID_OK, _("OK") ); + buttonsizer->Add( ok, 0, wxLEFT|wxRIGHT, 10 ); } - int w = wxMax( 350, m_buttons.GetCount() * 100 ); - w = wxMax( w, message_size.x ); - int space = w / (m_buttons.GetCount()*2); - - textCtrl->SetSize( 20, -1, w-10, -1 ); - - int m = 0; - wxNode *node = m_buttons.First(); - while (node) + wxButton *cancel = (wxButton *) NULL; + if (style & wxCANCEL) { - wxWindow *win = (wxWindow*)node->Data(); - int x = (m*2+1)*space - 40 + 15; - win->Move( x, -1 ); - node = node->Next(); - m++; + cancel = new wxButton( this, wxID_CANCEL, _("Cancel") ); + buttonsizer->Add( cancel, 0, wxLEFT|wxRIGHT, 10 ); } -#if wxUSE_STATLINE - int edge_margin = 7; - (void) new wxStaticLine( this, -1, wxPoint(edge_margin,y-20), wxSize(w+30-2*edge_margin, 5) ); -#endif - - SetSize( w+30, y+40 ); + topsizer->Add( buttonsizer, 0, wxCENTRE | wxALL, 10 ); + + topsizer->SetSizeHints( this ); + topsizer->Fit( this ); + SetSizer( topsizer ); + SetAutoLayout( TRUE ); Centre( wxBOTH ); + if (ok) + ok->SetDefault(); + + textCtrl->SetFocus(); - wxEndBusyCursor(); + wxEndBusyCursor(); } void wxTextEntryDialog::OnOK(wxCommandEvent& WXUNUSED(event) ) diff --git a/src/gtk1/button.cpp b/src/gtk1/button.cpp index dc7dd01c59..e109966054 100644 --- a/src/gtk1/button.cpp +++ b/src/gtk1/button.cpp @@ -92,9 +92,13 @@ bool wxButton::Create( wxWindow *parent, wxWindowID id, const wxString &label, SetLabel(label); + int x = 0; int y = 0; + wxFont new_font( parent->GetFont() ); + GetTextExtent( m_label, &x, &y, (int*)NULL, (int*)NULL, &new_font ); + wxSize newSize = size; - if (newSize.x == -1) newSize.x = 15+gdk_string_measure( m_widget->style->font, label.mbc_str() ); - if (newSize.y == -1) newSize.y = 26; + if (newSize.x == -1) newSize.x = 12+x; + if (newSize.y == -1) newSize.y = 11+y; SetSize( newSize.x, newSize.y ); gtk_signal_connect( GTK_OBJECT(m_widget), "clicked", diff --git a/src/gtk1/choicdlg.cpp b/src/gtk1/choicdlg.cpp index 903e1009d8..5aeb8dec86 100644 --- a/src/gtk1/choicdlg.cpp +++ b/src/gtk1/choicdlg.cpp @@ -28,6 +28,7 @@ #include "wx/listbox.h" #include "wx/stattext.h" #include "wx/intl.h" + #include "wx/sizer.h" #endif #if wxUSE_STATLINE @@ -36,24 +37,19 @@ #include "wx/gtk/choicdlg.h" -/* Split message, using constraints to position controls */ -static wxSize wxSplitMessage2( const wxString &message, wxWindow *parent ) +static void wxSplitMessage2( const wxString &message, wxWindow *parent, wxSizer* sizer ) { - int y = 10; - int w = 50; - wxString line( _T("") ); + wxString line; for (size_t pos = 0; pos < message.Len(); pos++) { if (message[pos] == _T('\n')) { if (!line.IsEmpty()) { - wxStaticText *s1 = new wxStaticText( parent, -1, line, wxPoint(15,y) ); - wxSize size1( s1->GetSize() ); - if (size1.x > w) w = size1.x; + wxStaticText *s1 = new wxStaticText( parent, -1, line ); + sizer->Add( s1 ); line = _T(""); } - y += 18; } else { @@ -61,16 +57,12 @@ static wxSize wxSplitMessage2( const wxString &message, wxWindow *parent ) } } + // remaining text behind last '\n' if (!line.IsEmpty()) { - wxStaticText *s2 = new wxStaticText( parent, -1, line, wxPoint(15,y) ); - wxSize size2( s2->GetSize() ); - if (size2.x > w) w = size2.x; + wxStaticText *s2 = new wxStaticText( parent, -1, line ); + sizer->Add( s2 ); } - - y += 18; - - return wxSize(w+30,y); } @@ -202,7 +194,7 @@ IMPLEMENT_CLASS(wxSingleChoiceDialog, wxDialog) wxSingleChoiceDialog::wxSingleChoiceDialog(wxWindow *parent, const wxString& message, const wxString& caption, int n, const wxString *choices, char **clientData, long style, const wxPoint& pos): - wxDialog(parent, -1, caption, pos, wxDefaultSize, wxDEFAULT_DIALOG_STYLE|wxDIALOG_MODAL|wxTAB_TRAVERSAL) + wxDialog(parent, -1, caption, pos, wxDefaultSize, wxDEFAULT_DIALOG_STYLE|wxRESIZE_BORDER|wxDIALOG_MODAL|wxTAB_TRAVERSAL) { Create(parent, message, caption, n, choices, clientData, style); } @@ -240,17 +232,15 @@ bool wxSingleChoiceDialog::Create( wxWindow *WXUNUSED(parent), const wxString& m wxBeginBusyCursor(); - wxSize message_size( wxSplitMessage2( message, this ) ); + wxBox *topsizer = new wxBox( wxVERTICAL ); - wxButton *ok = (wxButton *) NULL; - wxButton *cancel = (wxButton *) NULL; - wxList m_buttons; - - int y = message_size.y + 15; - - int listbox_height = 150; - - wxListBox *listBox = new wxListBox( this, wxID_LISTBOX, wxPoint(10, y), wxSize(360, listbox_height), + // 1) text message + wxBox *textsizer = new wxBox( wxVERTICAL ); + wxSplitMessage2( message, this, textsizer ); + topsizer->Add( textsizer, 0, wxALL, 10 ); + + // 2) list box + wxListBox *listBox = new wxListBox( this, wxID_LISTBOX, wxDefaultPosition, wxSize(160,100) , n, choices, wxLB_ALWAYS_SB ); listBox->SetSelection( m_selection ); if (clientData) @@ -258,53 +248,46 @@ bool wxSingleChoiceDialog::Create( wxWindow *WXUNUSED(parent), const wxString& m for (int i = 0; i < n; i++) listBox->SetClientData(i, clientData[i]); } - - y += listbox_height + 35; + topsizer->Add( listBox, 1, wxEXPAND | wxLEFT|wxRIGHT, 15 ); - if (style & wxOK) - { - ok = new wxButton( this, wxID_OK, _("OK"), wxPoint(-1,y), wxSize(80,-1) ); - m_buttons.Append( ok ); - } - if (style & wxCANCEL) - { - cancel = new wxButton( this, wxID_CANCEL, _("Cancel"), wxPoint(-1,y), wxSize(80,-1) ); - m_buttons.Append( cancel ); - } +#if wxUSE_STATLINE + // 3) static line + topsizer->Add( new wxStaticLine( this, -1 ), 0, wxEXPAND | wxLEFT|wxRIGHT|wxTOP, 3 ); +#endif - if (ok) + + // 4) buttons + wxBox *buttonsizer = new wxBox( wxHORIZONTAL ); + + wxButton *ok = (wxButton *) NULL; + if (style & wxOK) { - ok->SetDefault(); - ok->SetFocus(); + ok = new wxButton( this, wxID_OK, _("OK") ); + buttonsizer->Add( ok, 0, wxLEFT|wxRIGHT, 10 ); } - int w = m_buttons.GetCount() * 100; - if (message_size.x > w) w = message_size.x; - int space = w / (m_buttons.GetCount()*2); - - listBox->SetSize( 20, -1, w-10, listbox_height ); - - int m = 0; - wxNode *node = m_buttons.First(); - while (node) + wxButton *cancel = (wxButton *) NULL; + if (style & wxCANCEL) { - wxWindow *win = (wxWindow*)node->Data(); - int x = (m*2+1)*space - 40 + 15; - win->Move( x, -1 ); - node = node->Next(); - m++; + cancel = new wxButton( this, wxID_CANCEL, _("Cancel") ); + buttonsizer->Add( cancel, 0, wxLEFT|wxRIGHT, 10 ); } -#if wxUSE_STATLINE - int edge_margin = 7; - (void) new wxStaticLine( this, -1, wxPoint(edge_margin,y-20), wxSize(w+30-2*edge_margin, 5) ); -#endif - - SetSize( w+30, y+40 ); + topsizer->Add( buttonsizer, 0, wxCENTRE | wxALL, 10 ); + + topsizer->SetSizeHints( this ); + topsizer->Fit( this ); + SetSizer( topsizer ); + SetAutoLayout( TRUE ); Centre( wxBOTH ); + if (ok) + ok->SetDefault(); + + listBox->SetFocus(); + wxEndBusyCursor(); return TRUE; diff --git a/src/gtk1/dcclient.cpp b/src/gtk1/dcclient.cpp index 6ec3b44223..81bd578de4 100644 --- a/src/gtk1/dcclient.cpp +++ b/src/gtk1/dcclient.cpp @@ -304,6 +304,7 @@ void wxWindowDC::DoDrawLines( int n, wxPoint points[], long xoffset, long yoffse long x2 = XLOG2DEV(points[i+1].x + xoffset); long y1 = YLOG2DEV(points[i].y + yoffset); // oh, what a waste long y2 = YLOG2DEV(points[i+1].y + yoffset); + if (m_window) gdk_draw_line( m_window, m_penGC, x1, y1, x2, y2 ); @@ -327,7 +328,7 @@ void wxWindowDC::DoDrawPolygon( int n, wxPoint points[], long xoffset, long yoff CalcBoundingBox( points[i].x + xoffset, points[i].y + yoffset ); } - if (m_brush.GetStyle() != wxTRANSPARENT) + if ((m_brush.GetStyle() != wxTRANSPARENT) && m_window) gdk_draw_polygon (m_window, m_brushGC, TRUE, gdkpoints, n); // To do: Fillstyle @@ -1039,29 +1040,26 @@ void wxWindowDC::SetBackground( const wxBrush &brush ) gdk_gc_set_background( m_penGC, m_backgroundBrush.GetColour().GetColor() ); gdk_gc_set_background( m_bgGC, m_backgroundBrush.GetColour().GetColor() ); gdk_gc_set_foreground( m_bgGC, m_backgroundBrush.GetColour().GetColor() ); - - GdkFill fillStyle = GDK_SOLID; - switch (m_backgroundBrush.GetStyle()) - { - case wxSOLID: - case wxTRANSPARENT: - break; - default: - fillStyle = GDK_STIPPLED; - } - - gdk_gc_set_fill( m_bgGC, fillStyle ); + + gdk_gc_set_fill( m_bgGC, GDK_SOLID ); if ((m_backgroundBrush.GetStyle() == wxSTIPPLE) && (m_backgroundBrush.GetStipple()->Ok())) { if (m_backgroundBrush.GetStipple()->GetPixmap()) + { + gdk_gc_set_fill( m_bgGC, GDK_TILED ); gdk_gc_set_tile( m_bgGC, m_backgroundBrush.GetStipple()->GetPixmap() ); + } else + { + gdk_gc_set_fill( m_bgGC, GDK_STIPPLED ); gdk_gc_set_stipple( m_bgGC, m_backgroundBrush.GetStipple()->GetBitmap() ); + } } if (IS_HATCH(m_backgroundBrush.GetStyle())) { + gdk_gc_set_fill( m_bgGC, GDK_STIPPLED ); int num = m_backgroundBrush.GetStyle() - wxBDIAGONAL_HATCH; gdk_gc_set_stipple( m_bgGC, hatches[num] ); } diff --git a/src/gtk1/radiobox.cpp b/src/gtk1/radiobox.cpp index 5328d1565d..dcd089fa7e 100644 --- a/src/gtk1/radiobox.cpp +++ b/src/gtk1/radiobox.cpp @@ -271,7 +271,7 @@ wxSize wxRadioBox::LayoutItems() node = node->Next(); } res.x = x+4; - res.y = 42; + res.y = 40; } return res; diff --git a/src/gtk1/textdlg.cpp b/src/gtk1/textdlg.cpp index a0267ad3f9..db9257d998 100644 --- a/src/gtk1/textdlg.cpp +++ b/src/gtk1/textdlg.cpp @@ -28,6 +28,7 @@ #include "wx/stattext.h" #include "wx/textctrl.h" #include "wx/intl.h" + #include "wx/sizer.h" #endif #if wxUSE_STATLINE @@ -36,24 +37,19 @@ #include "wx/gtk/textdlg.h" -/* Split message, using constraints to position controls */ -static wxSize wxSplitMessage2( const wxString &message, wxWindow *parent ) +static void wxSplitMessage2( const wxString &message, wxWindow *parent, wxSizer* sizer ) { - int y = 10; - int w = 50; - wxString line( _T("") ); + wxString line; for (size_t pos = 0; pos < message.Len(); pos++) { if (message[pos] == _T('\n')) { if (!line.IsEmpty()) { - wxStaticText *s1 = new wxStaticText( parent, -1, line, wxPoint(15,y) ); - wxSize size1( s1->GetSize() ); - if (size1.x > w) w = size1.x; + wxStaticText *s1 = new wxStaticText( parent, -1, line ); + sizer->Add( s1 ); line = _T(""); } - y += 18; } else { @@ -61,16 +57,12 @@ static wxSize wxSplitMessage2( const wxString &message, wxWindow *parent ) } } + // remaining text behind last '\n' if (!line.IsEmpty()) { - wxStaticText *s2 = new wxStaticText( parent, -1, line, wxPoint(15,y) ); - wxSize size2( s2->GetSize() ); - if (size2.x > w) w = size2.x; + wxStaticText *s2 = new wxStaticText( parent, -1, line ); + sizer->Add( s2 ); } - - y += 18; - - return wxSize(w+30,y); } // wxTextEntryDialog @@ -92,64 +84,55 @@ wxTextEntryDialog::wxTextEntryDialog(wxWindow *parent, const wxString& message, wxBeginBusyCursor(); - wxSize message_size( wxSplitMessage2( message, this ) ); + wxBox *topsizer = new wxBox( wxVERTICAL ); - wxButton *ok = (wxButton *) NULL; - wxButton *cancel = (wxButton *) NULL; - wxList m_buttons; - - int y = message_size.y + 15; - - wxTextCtrl *textCtrl = new wxTextCtrl(this, wxID_TEXT, value, wxPoint(-1, y), wxSize(350, -1)); - - y += 65; + // 1) text message + wxBox *textsizer = new wxBox( wxVERTICAL ); + wxSplitMessage2( message, this, textsizer ); + topsizer->Add( textsizer, 0, wxALL, 10 ); - if (style & wxOK) - { - ok = new wxButton( this, wxID_OK, _("OK"), wxPoint(-1,y), wxSize(80,-1) ); - m_buttons.Append( ok ); - } + // 2) text ctrl + wxTextCtrl *textCtrl = new wxTextCtrl(this, wxID_TEXT, value, wxDefaultPosition, wxSize(300, -1)); + topsizer->Add( textCtrl, 1, wxEXPAND | wxLEFT|wxRIGHT, 15 ); - if (style & wxCANCEL) - { - cancel = new wxButton( this, wxID_CANCEL, _("Cancel"), wxPoint(-1,y), wxSize(80,-1) ); - m_buttons.Append( cancel ); - } +#if wxUSE_STATLINE + // 3) static line + topsizer->Add( new wxStaticLine( this, -1 ), 0, wxEXPAND | wxLEFT|wxRIGHT|wxTOP, 3 ); +#endif - if (ok) + + // 4) buttons + wxBox *buttonsizer = new wxBox( wxHORIZONTAL ); + + wxButton *ok = (wxButton *) NULL; + if (style & wxOK) { - ok->SetDefault(); - ok->SetFocus(); + ok = new wxButton( this, wxID_OK, _("OK") ); + buttonsizer->Add( ok, 0, wxLEFT|wxRIGHT, 10 ); } - int w = wxMax( 350, m_buttons.GetCount() * 100 ); - w = wxMax( w, message_size.x ); - int space = w / (m_buttons.GetCount()*2); - - textCtrl->SetSize( 20, -1, w-10, -1 ); - - int m = 0; - wxNode *node = m_buttons.First(); - while (node) + wxButton *cancel = (wxButton *) NULL; + if (style & wxCANCEL) { - wxWindow *win = (wxWindow*)node->Data(); - int x = (m*2+1)*space - 40 + 15; - win->Move( x, -1 ); - node = node->Next(); - m++; + cancel = new wxButton( this, wxID_CANCEL, _("Cancel") ); + buttonsizer->Add( cancel, 0, wxLEFT|wxRIGHT, 10 ); } -#if wxUSE_STATLINE - int edge_margin = 7; - (void) new wxStaticLine( this, -1, wxPoint(edge_margin,y-20), wxSize(w+30-2*edge_margin, 5) ); -#endif - - SetSize( w+30, y+40 ); + topsizer->Add( buttonsizer, 0, wxCENTRE | wxALL, 10 ); + + topsizer->SetSizeHints( this ); + topsizer->Fit( this ); + SetSizer( topsizer ); + SetAutoLayout( TRUE ); Centre( wxBOTH ); + if (ok) + ok->SetDefault(); + + textCtrl->SetFocus(); - wxEndBusyCursor(); + wxEndBusyCursor(); } void wxTextEntryDialog::OnOK(wxCommandEvent& WXUNUSED(event) ) -- 2.45.2