From 27ea1d8aae3055025b2ebac9d9f7e93feee7569d Mon Sep 17 00:00:00 2001 From: Robert Roebling Date: Fri, 13 Aug 1999 17:32:30 +0000 Subject: [PATCH] Added wxStaticBoxSizer, Makefile updates, Improved look of wxGenericPageSetupDialog git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@3369 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- Makefile.in | 8 +- configure.in | 1 + distrib/msw/tmake/unx.t | 6 + include/wx/sizer.h | 22 ++++ samples/printing/.cvsignore | 1 - src/common/sizer.cpp | 53 +++++++++ src/generic/prntdlgg.cpp | 212 +++++++++++++++++++++--------------- 7 files changed, 215 insertions(+), 88 deletions(-) diff --git a/Makefile.in b/Makefile.in index ea7706a8d2..df0f028274 100644 --- a/Makefile.in +++ b/Makefile.in @@ -1,6 +1,6 @@ # -# This file was automatically generated by tmake at 14:38, 1999/08/13 +# This file was automatically generated by tmake at 15:55, 1999/08/13 # DO NOT CHANGE THIS FILE, YOUR CHANGES WILL BE LOST! CHANGE UNX.T! # @@ -1448,6 +1448,12 @@ SAMPLES_DIST: cp $(SAMPDIR)/checklst/Makefile.in $(DISTDIR)/samples/checklst cp $(SAMPDIR)/checklst/*.cpp $(DISTDIR)/samples/checklst cp $(SAMPDIR)/checklst/*.xpm $(DISTDIR)/samples/checklst + mkdir $(DISTDIR)/samples/checkls + cp $(SAMPDIR)/printing/Makefile.in $(DISTDIR)/samples/printing + cp $(SAMPDIR)/printing/*.cpp $(DISTDIR)/samples/printing + cp $(SAMPDIR)/printing/*.h $(DISTDIR)/samples/printing + cp $(SAMPDIR)/printing/*.xpm $(DISTDIR)/samples/printing + cp $(SAMPDIR)/printing/*.xbm $(DISTDIR)/samples/printing dist: ALL_DIST @GUIDIST@ SAMPLES_DIST cd _dist_dir; tar ch wx$(TOOLKIT) | gzip -f9 > $(WXARCHIVE); mv $(WXARCHIVE) .. diff --git a/configure.in b/configure.in index 6fc5851295..7002888c7d 100644 --- a/configure.in +++ b/configure.in @@ -2703,6 +2703,7 @@ AC_OUTPUT([ samples/checklst/Makefile samples/config/Makefile samples/controls/Makefile + samples/printing/Makefile ], [ chmod +x wx-config diff --git a/distrib/msw/tmake/unx.t b/distrib/msw/tmake/unx.t index 0a1ba7ae7e..2a1a2b4cea 100644 --- a/distrib/msw/tmake/unx.t +++ b/distrib/msw/tmake/unx.t @@ -658,6 +658,12 @@ SAMPLES_DIST: cp $(SAMPDIR)/checklst/Makefile.in $(DISTDIR)/samples/checklst cp $(SAMPDIR)/checklst/*.cpp $(DISTDIR)/samples/checklst cp $(SAMPDIR)/checklst/*.xpm $(DISTDIR)/samples/checklst + mkdir $(DISTDIR)/samples/checkls + cp $(SAMPDIR)/printing/Makefile.in $(DISTDIR)/samples/printing + cp $(SAMPDIR)/printing/*.cpp $(DISTDIR)/samples/printing + cp $(SAMPDIR)/printing/*.h $(DISTDIR)/samples/printing + cp $(SAMPDIR)/printing/*.xpm $(DISTDIR)/samples/printing + cp $(SAMPDIR)/printing/*.xbm $(DISTDIR)/samples/printing dist: ALL_DIST @GUIDIST@ SAMPLES_DIST cd _dist_dir; tar ch wx$(TOOLKIT) | gzip -f9 > $(WXARCHIVE); mv $(WXARCHIVE) .. diff --git a/include/wx/sizer.h b/include/wx/sizer.h index 5f82f4ce94..61eda2e4ec 100644 --- a/include/wx/sizer.h +++ b/include/wx/sizer.h @@ -26,9 +26,12 @@ // classes //--------------------------------------------------------------------------- +class wxStaticBox; + class wxSizerItem; class wxSizer; class wxBoxSizer; +class wxStaticBoxSizer; //--------------------------------------------------------------------------- // wxSizerItem @@ -138,5 +141,24 @@ protected: int m_fixedHeight; }; +//--------------------------------------------------------------------------- +// wxStaticBoxSizer +//--------------------------------------------------------------------------- + +class WXDLLEXPORT wxStaticBoxSizer: public wxBoxSizer +{ +public: + wxStaticBoxSizer( wxStaticBox *box, int orient ); + + void RecalcSizes(); + wxSize CalcMin(); + + wxStaticBox *GetStaticBox() + { return m_staticBox; } + +protected: + wxStaticBox *m_staticBox; +}; + #endif // __WXSIZER_H__ diff --git a/samples/printing/.cvsignore b/samples/printing/.cvsignore index f5eaa1a859..8b13789179 100644 --- a/samples/printing/.cvsignore +++ b/samples/printing/.cvsignore @@ -1,2 +1 @@ -Makefile.in diff --git a/src/common/sizer.cpp b/src/common/sizer.cpp index f5f6ede49e..5dbc84608b 100644 --- a/src/common/sizer.cpp +++ b/src/common/sizer.cpp @@ -22,6 +22,7 @@ #include "wx/sizer.h" #include "wx/utils.h" +#include "wx/statbox.h" //--------------------------------------------------------------------------- // wxSizerItem @@ -384,3 +385,55 @@ wxSize wxBoxSizer::CalcMin() return wxSize( m_minWidth, m_minHeight ); } + +//--------------------------------------------------------------------------- +// wxStaticBoxSizer +//--------------------------------------------------------------------------- + +wxStaticBoxSizer::wxStaticBoxSizer( wxStaticBox *box, int orient ) + : wxBoxSizer( orient ) +{ + wxASSERT_MSG( box, _T("wxStaticBoxSizer needs a static box") ); + + m_staticBox = box; +} + +void wxStaticBoxSizer::RecalcSizes() +{ + // this will have to be done platform by platform + // as there is no way to guess the thickness of + // a wxStaticBox border + int top_border = 15; + if (m_staticBox->GetLabel().IsEmpty()) top_border = 5; + int other_border = 5; + + m_staticBox->SetSize( m_position.x, m_position.y, m_size.x, m_size.y ); + + wxPoint old_pos( m_position ); + m_position.x += other_border; + m_position.y += top_border; + wxSize old_size( m_size ); + m_size.x -= 2*other_border; + m_size.y -= top_border + other_border; + + wxBoxSizer::RecalcSizes(); + + m_position = old_pos; + m_size = old_size; +} + +wxSize wxStaticBoxSizer::CalcMin() +{ + // this will have to be done platform by platform + // as there is no way to guess the thickness of + // a wxStaticBox border + int top_border = 15; + if (m_staticBox->GetLabel().IsEmpty()) top_border = 5; + int other_border = 5; + + wxSize ret( wxBoxSizer::CalcMin() ); + ret.x += 2*top_border; + ret.y += other_border + top_border; + + return ret; +} diff --git a/src/generic/prntdlgg.cpp b/src/generic/prntdlgg.cpp index b716064026..53fa919d26 100644 --- a/src/generic/prntdlgg.cpp +++ b/src/generic/prntdlgg.cpp @@ -47,6 +47,11 @@ #include "wx/choice.h" #include "wx/combobox.h" #include + #include "wx/sizer.h" +#endif + +#if wxUSE_STATLINE + #include "wx/statline.h" #endif #include "wx/generic/prntdlgg.h" @@ -138,12 +143,24 @@ void wxGenericPrintDialog::Init(wxWindow * WXUNUSED(parent)) // wxDialog::Create(parent, -1, _("Print"), wxPoint(0, 0), wxSize(600, 600), // wxDEFAULT_DIALOG_STYLE | wxDIALOG_MODAL | wxTAB_TRAVERSAL); - (void)new wxStaticBox( this, -1, _( "Printer options" ), wxPoint( 5, 5), wxSize( 300, 60 ) ); + wxBoxSizer *mainsizer = new wxBoxSizer( wxVERTICAL ); - m_printToFileCheckBox = new wxCheckBox(this, wxPRINTID_PRINTTOFILE, _("Print to File"), wxPoint(20, 25) ); + // 1) top row + + wxStaticBoxSizer *topsizer = new wxStaticBoxSizer( + new wxStaticBox( this, -1, _( "Printer options" ) ), wxHORIZONTAL ); + m_printToFileCheckBox = new wxCheckBox( this, wxPRINTID_PRINTTOFILE, _("Print to File") ); + topsizer->Add( m_printToFileCheckBox, 0, wxCENTER|wxALL, 5 ); - m_setupButton = new wxButton(this, wxPRINTID_SETUP, _("Setup..."), wxPoint(160, 25), wxSize(100, -1)); + topsizer->Add( 60,2,1 ); + m_setupButton = new wxButton(this, wxPRINTID_SETUP, _("Setup...") ); + topsizer->Add( m_setupButton, 0, wxCENTER|wxALL, 5 ); + + mainsizer->Add( topsizer, 0, wxLEFT|wxTOP|wxRIGHT, 10 ); + + // 2) middle row with radio box + wxString *choices = new wxString[2]; choices[0] = _("All"); choices[1] = _("Pages"); @@ -155,33 +172,48 @@ void wxGenericPrintDialog::Init(wxWindow * WXUNUSED(parent)) if (m_printDialogData.GetFromPage() != 0) { m_rangeRadioBox = new wxRadioBox(this, wxPRINTID_RANGE, _("Print Range"), - wxPoint(5, 80), wxSize(-1, -1), + wxDefaultPosition, wxDefaultSize, 2, choices, 1, wxRA_VERTICAL); m_rangeRadioBox->SetSelection(1); + + mainsizer->Add( m_rangeRadioBox, 0, wxLEFT|wxTOP|wxRIGHT, 10 ); } - if(m_printDialogData.GetFromPage() != 0) + // 3) bottom row + + wxBoxSizer *bottomsizer = new wxBoxSizer( wxHORIZONTAL ); + + if (m_printDialogData.GetFromPage() != 0) { - (void) new wxStaticText(this, wxPRINTID_STATIC, _("From:"), wxPoint(5, 135)); + bottomsizer->Add( new wxStaticText(this, wxPRINTID_STATIC, _("From:") ), 0, wxCENTER|wxALL, 5 ); + m_fromText = new wxTextCtrl(this, wxPRINTID_FROM, "", wxDefaultPosition, wxSize(40, -1)); + bottomsizer->Add( m_fromText, 1, wxCENTER|wxRIGHT, 10 ); - m_fromText = new wxTextCtrl(this, wxPRINTID_FROM, "", wxPoint(45, 130), wxSize(40, -1)); + bottomsizer->Add( new wxStaticText(this, wxPRINTID_STATIC, _("To:") ), 0, wxCENTER|wxALL, 5); + m_toText = new wxTextCtrl(this, wxPRINTID_TO, "", wxDefaultPosition, wxSize(40, -1)); + bottomsizer->Add( m_toText, 1, wxCENTER|wxRIGHT, 10 ); + } - (void) new wxStaticText(this, wxPRINTID_STATIC, _("To:"), wxPoint(100, 135)); + bottomsizer->Add( new wxStaticText(this, wxPRINTID_STATIC, _("Copies:") ), 0, wxCENTER|wxALL, 5 ); + m_noCopiesText = new wxTextCtrl(this, wxPRINTID_COPIES, "", wxPoint(252, 130), wxSize(40, -1)); + bottomsizer->Add( m_noCopiesText, 1, wxCENTER|wxRIGHT, 10 ); - m_toText = new wxTextCtrl(this, wxPRINTID_TO, "", wxPoint(133, 130), wxSize(40, -1)); - } + mainsizer->Add( bottomsizer, 0, wxTOP|wxLEFT|wxRIGHT, 12 ); - (void) new wxStaticText(this, wxPRINTID_STATIC, _("Copies:"), wxPoint(200, 135)); +#if wxUSE_STATLINE + // 4) static line + mainsizer->Add( new wxStaticLine( this, -1 ), 0, wxEXPAND | wxLEFT|wxRIGHT|wxTOP, 10 ); +#endif - m_noCopiesText = new wxTextCtrl(this, wxPRINTID_COPIES, "", wxPoint(252, 130), wxSize(40, -1)); + // 5) buttons - wxButton *okButton = new wxButton(this, wxID_OK, _("OK"), wxPoint(40, 180), wxSize(80, -1)); - (void) new wxButton(this, wxID_CANCEL, _("Cancel"), wxPoint(180, 180), wxSize(80, -1)); + mainsizer->Add( CreateButtonSizer( wxOK|wxCANCEL), 0, wxCENTER|wxALL, 10 ); - okButton->SetDefault(); - okButton->SetFocus(); - Fit(); + SetAutoLayout( TRUE ); + SetSizer( mainsizer ); + + mainsizer->Fit( this ); Centre(wxBOTH); // Calls wxWindow::OnInitDialog and then wxGenericPrintDialog::TransferDataToWindow @@ -573,93 +605,101 @@ void wxGenericPageSetupDialog::OnPrinter(wxCommandEvent& WXUNUSED(event)) wxGenericPageSetupDialog::wxGenericPageSetupDialog(wxWindow *parent, wxPageSetupData* data): wxDialog(parent, -1, _("Page Setup"), wxPoint(0, 0), wxSize(600, 600), wxDIALOG_MODAL|wxDEFAULT_DIALOG_STYLE|wxTAB_TRAVERSAL) { - if ( data ) + if (data) m_pageData = *data; + + int textWidth = 80; + + wxBoxSizer *mainsizer = new wxBoxSizer( wxVERTICAL ); + + // 1) top + wxStaticBoxSizer *topsizer = new wxStaticBoxSizer( + new wxStaticBox(this,wxPRINTID_STATIC, _("Paper size")), wxHORIZONTAL ); + + int n = wxThePrintPaperDatabase->Number(); + wxString *choices = new wxString [n]; + int i; + for (i = 0; i < n; i++) + { + wxPrintPaperType *paper = (wxPrintPaperType *)wxThePrintPaperDatabase->Nth(i)->Data(); + choices[i] = paper->GetName(); + } - int buttonWidth = 75; - int buttonHeight = 25; - int spacing = 5; -#ifdef __WXMOTIF__ - spacing = 15; -#endif - - int yPos = 5; - int xPos = 5; - - wxButton *okButton = new wxButton(this, wxID_OK, _("OK"), wxPoint(5, yPos), wxSize(buttonWidth, buttonHeight)); - (void) new wxButton(this, wxID_CANCEL, _("Cancel"), wxPoint(buttonWidth + 5 + spacing, yPos), wxSize(buttonWidth, buttonHeight)); - - m_printerButton = new wxButton(this, wxPRINTID_SETUP, _("Printer..."), wxPoint(buttonWidth*2 + 5 + 2*spacing, yPos), wxSize(buttonWidth, buttonHeight)); - - if ( !m_pageData.GetEnablePrinter() ) - m_printerButton->Enable(FALSE); - - // if (m_printData.GetEnableHelp()) - // wxButton *helpButton = new wxButton(this, (wxFunction)wxGenericPageSetupHelpProc, _("Help"), -1, -1, buttonWidth, buttonHeight); - - okButton->SetDefault(); - okButton->SetFocus(); - - xPos = 5; - yPos += 35; - -#ifdef __WXMOTIF__ - yPos += 10; -#endif + m_paperTypeChoice = new wxComboBox(this, wxPRINTID_PAPERSIZE, _("Paper Size"), + wxDefaultPosition, wxSize(300, -1), n, choices); + topsizer->Add( m_paperTypeChoice, 1, wxEXPAND|wxALL, 5 ); +// m_paperTypeChoice->SetSelection(sel); - m_paperTypeChoice = CreatePaperTypeChoice(&xPos, &yPos); + mainsizer->Add( topsizer, 0, wxTOP|wxLEFT|wxRIGHT | wxEXPAND, 10 ); - xPos = 5; + // 2) middle sizer with radio box - wxString *choices = new wxString[2]; - choices[0] = _("Portrait"); - choices[1] = _("Landscape"); + wxString *choices2 = new wxString[2]; + choices2[0] = _("Portrait"); + choices2[1] = _("Landscape"); m_orientationRadioBox = new wxRadioBox(this, wxPRINTID_ORIENTATION, _("Orientation"), - wxPoint(xPos, yPos), wxSize(-1, -1), 2, choices, 2); + wxDefaultPosition, wxDefaultSize, 2, choices2, 2); m_orientationRadioBox->SetSelection(0); - xPos = 5; - yPos += 60; + mainsizer->Add( m_orientationRadioBox, 0, wxTOP|wxLEFT|wxRIGHT, 10 ); - int staticWidth = 110; -#ifdef __WXMOTIF__ - staticWidth += 20; -#endif + // 3) margins - int textWidth = 60; - spacing = 10; + wxBoxSizer *table = new wxBoxSizer( wxHORIZONTAL ); - (void) new wxStaticText(this, wxPRINTID_STATIC, _("Left margin (mm):"), wxPoint(xPos, yPos)); - xPos += staticWidth; - - m_marginLeftText = new wxTextCtrl(this, wxPRINTID_LEFTMARGIN, "", wxPoint(xPos, yPos), wxSize(textWidth, -1)); - xPos += textWidth + spacing; - - (void) new wxStaticText(this, wxPRINTID_STATIC, _("Right margin (mm):"), wxPoint(xPos, yPos)); - xPos += staticWidth; - - m_marginRightText = new wxTextCtrl(this, wxPRINTID_RIGHTMARGIN, "", wxPoint(xPos, yPos), wxSize(textWidth, -1)); - xPos += textWidth + spacing; - - yPos += 35; - xPos = 5; - - (void) new wxStaticText(this, wxPRINTID_STATIC, _("Top margin (mm):"), wxPoint(xPos, yPos)); - xPos += staticWidth; + wxBoxSizer *column1 = new wxBoxSizer( wxVERTICAL ); + column1->Add( new wxStaticText(this, wxPRINTID_STATIC, _("Left margin (mm):")),1,wxALL|wxALIGN_RIGHT,5 ); + column1->Add( new wxStaticText(this, wxPRINTID_STATIC, _("Top margin (mm):")),1,wxALL|wxALIGN_RIGHT,5 ); + table->Add( column1, 0, wxALL | wxEXPAND, 5 ); + + wxBoxSizer *column2 = new wxBoxSizer( wxVERTICAL ); + m_marginLeftText = new wxTextCtrl(this, wxPRINTID_LEFTMARGIN, "", wxDefaultPosition, wxSize(textWidth, -1)); + m_marginTopText = new wxTextCtrl(this, wxPRINTID_TOPMARGIN, "", wxDefaultPosition, wxSize(textWidth, -1)); + column2->Add( m_marginLeftText, 1, wxALL, 5 ); + column2->Add( m_marginTopText, 1, wxALL, 5 ); + table->Add( column2, 0, wxRIGHT|wxTOP|wxBOTTOM | wxEXPAND, 5 ); + + wxBoxSizer *column3 = new wxBoxSizer( wxVERTICAL ); + column3->Add( new wxStaticText(this, wxPRINTID_STATIC, _("Right margin (mm):")),1,wxALL|wxALIGN_RIGHT,5 ); + column3->Add( new wxStaticText(this, wxPRINTID_STATIC, _("Bottom margin (mm):")),1,wxALL|wxALIGN_RIGHT,5 ); + table->Add( column3, 0, wxALL | wxEXPAND, 5 ); + + wxBoxSizer *column4 = new wxBoxSizer( wxVERTICAL ); + m_marginRightText = new wxTextCtrl(this, wxPRINTID_RIGHTMARGIN, "", wxDefaultPosition, wxSize(textWidth, -1)); + m_marginBottomText = new wxTextCtrl(this, wxPRINTID_BOTTOMMARGIN, "", wxDefaultPosition, wxSize(textWidth, -1)); + column4->Add( m_marginRightText, 1, wxALL, 5 ); + column4->Add( m_marginBottomText, 1, wxALL, 5 ); + table->Add( column4, 0, wxRIGHT|wxTOP|wxBOTTOM | wxEXPAND, 5 ); + + mainsizer->Add( table, 0 ); + +#if wxUSE_STATLINE + // 5) static line + mainsizer->Add( new wxStaticLine( this, -1 ), 0, wxEXPAND | wxLEFT|wxRIGHT|wxTOP, 10 ); +#endif - m_marginTopText = new wxTextCtrl(this, wxPRINTID_TOPMARGIN, "", wxPoint(xPos, yPos), wxSize(textWidth, -1)); - xPos += textWidth + spacing; + // 6) buttons + + wxSizer* buttonsizer = CreateButtonSizer( wxOK|wxCANCEL); + m_printerButton = new wxButton(this, wxPRINTID_SETUP, _("Printer...") ); + buttonsizer->Add( m_printerButton, 0, wxLEFT|wxRIGHT, 10 ); + if ( !m_pageData.GetEnablePrinter() ) + m_printerButton->Enable(FALSE); + // if (m_printData.GetEnableHelp()) + // wxButton *helpButton = new wxButton(this, (wxFunction)wxGenericPageSetupHelpProc, _("Help"), -1, -1, buttonWidth, buttonHeight); + mainsizer->Add( buttonsizer, 0, wxCENTER|wxALL, 10 ); - (void) new wxStaticText(this, wxPRINTID_STATIC, _("Bottom margin (mm):"), wxPoint(xPos, yPos)); - xPos += staticWidth; - m_marginBottomText = new wxTextCtrl(this, wxPRINTID_BOTTOMMARGIN, "", wxPoint(xPos, yPos), wxSize(textWidth, -1)); + SetAutoLayout( TRUE ); + SetSizer( mainsizer ); - Fit(); + mainsizer->Fit( this ); Centre(wxBOTH); InitDialog(); - delete [] choices; + + delete[] choices; + delete [] choices2; } wxGenericPageSetupDialog::~wxGenericPageSetupDialog() -- 2.45.2