]> git.saurik.com Git - wxWidgets.git/blame - src/generic/textdlgg.cpp
* wxMemory*Stream link problem fix.
[wxWidgets.git] / src / generic / textdlgg.cpp
CommitLineData
c801d85f
KB
1/////////////////////////////////////////////////////////////////////////////
2// Name: textdlgg.cpp
3// Purpose: wxTextEntryDialog
4// Author: Julian Smart
5// Modified by:
6// Created: 04/01/98
7// RCS-ID: $Id$
8// Copyright: (c) Julian Smart and Markus Holzem
9// Licence: wxWindows license
10/////////////////////////////////////////////////////////////////////////////
11
12#ifdef __GNUG__
13#pragma implementation "textdlgg.h"
14#endif
15
16// For compilers that support precompilation, includes "wx.h".
17#include "wx/wxprec.h"
18
19#ifdef __BORLANDC__
20#pragma hdrstop
21#endif
22
23#ifndef WX_PRECOMP
24#include <stdio.h>
25#include "wx/utils.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"
32#include "wx/intl.h"
33#endif
34
35#include "wx/generic/textdlgg.h"
36
37// wxTextEntryDialog
38
39#if !USE_SHARED_LIBRARY
40BEGIN_EVENT_TABLE(wxTextEntryDialog, wxDialog)
41 EVT_BUTTON(wxID_OK, wxTextEntryDialog::OnOK)
42END_EVENT_TABLE()
43
44IMPLEMENT_CLASS(wxTextEntryDialog, wxDialog)
45#endif
46
47extern void wxSplitMessage2(const char *message, wxList *messageList, wxWindow *parent, wxRowColSizer *sizer);
48
49wxTextEntryDialog::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)
52{
53 m_dialogStyle = style;
54 m_value = value;
55
56 wxBeginBusyCursor();
57
58 wxSizer *topSizer = new wxSizer(this, wxSizerShrink);
59 topSizer->SetBorder(10, 10);
60
61 wxRowColSizer *messageSizer = new wxRowColSizer(topSizer, wxSIZER_COLS, 100);
62 messageSizer->SetName("messageSizer");
63
64// bool centre = ((style & wxCENTRE) == wxCENTRE);
65
66 wxList messageList;
67 wxSplitMessage2(message, &messageList, this, messageSizer);
68
69 // Insert a spacer
70 wxSpacingSizer *spacingSizer = new wxSpacingSizer(topSizer, wxBelow, messageSizer, 10);
71
72 wxTextCtrl *textCtrl = new wxTextCtrl(this, wxID_TEXT, value, wxPoint(-1, -1), wxSize(350, -1));
73
74 wxRowColSizer *textSizer = new wxRowColSizer(topSizer, wxSIZER_ROWS);
75 textSizer->AddSizerChild(textCtrl);
76 textSizer->SetName("textSizer");
77
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);
83
84 // Insert another spacer
85 wxSpacingSizer *spacingSizer2 = new wxSpacingSizer(topSizer, wxBelow, textSizer, 10);
86 spacingSizer->SetName("spacingSizer2");
87
88 // Insert a sizer for the buttons
89 wxRowColSizer *buttonSizer = new wxRowColSizer(topSizer, wxSIZER_ROWS);
90 buttonSizer->SetName("buttonSizer");
91
92 // Specify constraints for the button sizer
93 wxLayoutConstraints *c = new wxLayoutConstraints;
94 c->width.AsIs ();
95 c->height.AsIs ();
96 c->top.Below (spacingSizer2);
97 c->centreX.SameAs (textSizer, wxCentreX);
98 buttonSizer->SetConstraints(c);
99
100 wxButton *ok = NULL;
101 wxButton *cancel = NULL;
102
103 if (style & wxOK) {
104 ok = new wxButton(this, wxID_OK, _("OK"));
105 buttonSizer->AddSizerChild(ok);
106 }
107
108 if (style & wxCANCEL) {
109 cancel = new wxButton(this, wxID_CANCEL, _("Cancel"));
110 buttonSizer->AddSizerChild(cancel);
111 }
112
113 if (ok)
114 {
115 ok->SetDefault();
116 ok->SetFocus();
117 }
118
119 Layout();
120 Centre(wxBOTH);
121
122 wxEndBusyCursor();
123}
124
125void wxTextEntryDialog::OnOK(wxCommandEvent& WXUNUSED(event) )
126{
127 wxTextCtrl *textCtrl = (wxTextCtrl *)FindWindow(wxID_TEXT);
128 if ( textCtrl )
129 m_value = textCtrl->GetValue();
130
131 EndModal(wxID_OK);
132}
133
134wxString wxGetTextFromUser(const wxString& message, const wxString& caption,
135 const wxString& defaultValue, wxWindow *parent,
136 int x, int y, bool WXUNUSED(centre) )
137{
138 wxTextEntryDialog dialog(parent, message, caption, defaultValue, wxOK|wxCANCEL, wxPoint(x, y));
4efd7443 139 if (dialog.ShowModal() == wxID_OK)
c801d85f
KB
140 return dialog.GetValue();
141 else
142 return wxString("");
143}