]>
git.saurik.com Git - wxWidgets.git/blob - src/generic/textdlgg.cpp
1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: wxTextEntryDialog
4 // Author: Julian Smart
8 // Copyright: (c) Julian Smart and Markus Holzem
9 // Licence: wxWindows license
10 /////////////////////////////////////////////////////////////////////////////
13 #pragma implementation "textdlgg.h"
16 // For compilers that support precompilation, includes "wx.h".
17 #include "wx/wxprec.h"
26 #include "wx/dialog.h"
27 #include "wx/listbox.h"
28 #include "wx/button.h"
29 #include "wx/stattext.h"
30 #include "wx/textctrl.h"
31 #include "wx/layout.h"
35 #include "wx/generic/textdlgg.h"
39 #if !USE_SHARED_LIBRARY
40 BEGIN_EVENT_TABLE(wxTextEntryDialog
, wxDialog
)
41 EVT_BUTTON(wxID_OK
, wxTextEntryDialog::OnOK
)
44 IMPLEMENT_CLASS(wxTextEntryDialog
, wxDialog
)
47 extern void wxSplitMessage2(const char *message
, wxList
*messageList
, wxWindow
*parent
, wxRowColSizer
*sizer
);
49 wxTextEntryDialog::wxTextEntryDialog(wxWindow
*parent
, const wxString
& message
, const wxString
& caption
,
50 const wxString
& value
, long style
, const wxPoint
& pos
):
51 wxDialog(parent
, -1, caption
, pos
, wxDefaultSize
, wxDEFAULT_DIALOG_STYLE
|wxDIALOG_MODAL
)
53 m_dialogStyle
= style
;
58 wxSizer
*topSizer
= new wxSizer(this, wxSizerShrink
);
59 topSizer
->SetBorder(10, 10);
61 wxRowColSizer
*messageSizer
= new wxRowColSizer(topSizer
, wxSIZER_COLS
, 100);
62 messageSizer
->SetName("messageSizer");
64 // bool centre = ((style & wxCENTRE) == wxCENTRE);
67 wxSplitMessage2(message
, &messageList
, this, messageSizer
);
70 wxSpacingSizer
*spacingSizer
= new wxSpacingSizer(topSizer
, wxBelow
, messageSizer
, 10);
72 wxTextCtrl
*textCtrl
= new wxTextCtrl(this, wxID_TEXT
, value
, wxPoint(-1, -1), wxSize(350, -1));
74 wxRowColSizer
*textSizer
= new wxRowColSizer(topSizer
, wxSIZER_ROWS
);
75 textSizer
->AddSizerChild(textCtrl
);
76 textSizer
->SetName("textSizer");
78 // Create constraints for the text sizer
79 wxLayoutConstraints
*textC
= new wxLayoutConstraints
;
80 textC
->left
.SameAs (messageSizer
, wxLeft
);
81 textC
->top
.Below (spacingSizer
);
82 textSizer
->SetConstraints(textC
);
84 // Insert another spacer
85 wxSpacingSizer
*spacingSizer2
= new wxSpacingSizer(topSizer
, wxBelow
, textSizer
, 10);
86 spacingSizer
->SetName("spacingSizer2");
88 // Insert a sizer for the buttons
89 wxRowColSizer
*buttonSizer
= new wxRowColSizer(topSizer
, wxSIZER_ROWS
);
90 buttonSizer
->SetName("buttonSizer");
92 // Specify constraints for the button sizer
93 wxLayoutConstraints
*c
= new wxLayoutConstraints
;
96 c
->top
.Below (spacingSizer2
);
97 c
->centreX
.SameAs (textSizer
, wxCentreX
);
98 buttonSizer
->SetConstraints(c
);
101 wxButton
*cancel
= NULL
;
104 ok
= new wxButton(this, wxID_OK
, _("OK"));
105 buttonSizer
->AddSizerChild(ok
);
108 if (style
& wxCANCEL
) {
109 cancel
= new wxButton(this, wxID_CANCEL
, _("Cancel"));
110 buttonSizer
->AddSizerChild(cancel
);
122 void wxTextEntryDialog::OnOK(wxCommandEvent
& WXUNUSED(event
) )
124 wxTextCtrl
*textCtrl
= (wxTextCtrl
*)FindWindow(wxID_TEXT
);
126 m_value
= textCtrl
->GetValue();
131 wxString
wxGetTextFromUser(const wxString
& message
, const wxString
& caption
,
132 const wxString
& defaultValue
, wxWindow
*parent
,
133 int x
, int y
, bool WXUNUSED(centre
) )
135 wxTextEntryDialog
dialog(parent
, message
, caption
, defaultValue
, wxOK
|wxCANCEL
, wxPoint(x
, y
));
136 if (dialog
.ShowModal() == wxID_OK
)
137 return dialog
.GetValue();