#include "wx/stattext.h"
#include "wx/textctrl.h"
#include "wx/intl.h"
+ #include "wx/sizer.h"
#endif
#if wxUSE_STATLINE
#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
{
}
}
+ // 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
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, 10 );
+#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) )