]> git.saurik.com Git - wxWidgets.git/blob - src/generic/textdlgg.cpp
ea9700ee66d243bd8aa75796df45642138c50a0a
[wxWidgets.git] / src / generic / textdlgg.cpp
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 // ============================================================================
13 // declarations
14 // ============================================================================
15
16 // ----------------------------------------------------------------------------
17 // headers
18 // ----------------------------------------------------------------------------
19
20 #ifdef __GNUG__
21 #pragma implementation "textdlgg.h"
22 #endif
23
24 // For compilers that support precompilation, includes "wx.h".
25 #include "wx/wxprec.h"
26
27 #ifdef __BORLANDC__
28 #pragma hdrstop
29 #endif
30
31 #ifndef WX_PRECOMP
32 #include <stdio.h>
33
34 #include "wx/utils.h"
35 #include "wx/dialog.h"
36 #include "wx/button.h"
37 #include "wx/stattext.h"
38 #include "wx/textctrl.h"
39 #include "wx/intl.h"
40 #endif
41
42 #if wxUSE_STATLINE
43 #include "wx/statline.h"
44 #endif
45
46 #include "wx/generic/textdlgg.h"
47
48 // ----------------------------------------------------------------------------
49 // constants
50 // ----------------------------------------------------------------------------
51
52 #define wxID_TEXT 3000
53
54 // ============================================================================
55 // implementation
56 // ============================================================================
57
58 // ----------------------------------------------------------------------------
59 // wxTextEntryDialog
60 // ----------------------------------------------------------------------------
61
62 #if !USE_SHARED_LIBRARY
63 BEGIN_EVENT_TABLE(wxTextEntryDialog, wxDialog)
64 EVT_BUTTON(wxID_OK, wxTextEntryDialog::OnOK)
65 END_EVENT_TABLE()
66
67 IMPLEMENT_CLASS(wxTextEntryDialog, wxDialog)
68 #endif
69
70 wxTextEntryDialog::wxTextEntryDialog(wxWindow *parent,
71 const wxString& message,
72 const wxString& caption,
73 const wxString& value,
74 long style,
75 const wxPoint& pos)
76 : wxDialog(parent, -1, caption, pos, wxDefaultSize,
77 wxDEFAULT_DIALOG_STYLE | wxDIALOG_MODAL),
78 m_value(value)
79 {
80 // calculate the sizes
81 // -------------------
82
83 wxArrayString lines;
84 wxSize sizeText = SplitTextMessage(message, &lines);
85
86 wxSize sizeBtn = GetStandardButtonSize();
87
88 long wText = wxMax(4*sizeBtn.GetWidth(), sizeText.GetWidth());
89 long hText = GetStandardTextHeight();
90
91 long wDialog = 4*LAYOUT_X_MARGIN + wText;
92 long hDialog = 2*LAYOUT_Y_MARGIN +
93 sizeText.GetHeight() * lines.GetCount() +
94 2*LAYOUT_Y_MARGIN +
95 hText +
96 2*LAYOUT_Y_MARGIN +
97 sizeBtn.GetHeight() +
98 2*LAYOUT_Y_MARGIN;
99
100 // create the controls
101 // -------------------
102
103 // message
104 long x = 2*LAYOUT_X_MARGIN;
105 long y = CreateTextMessage(lines,
106 wxPoint(x, 2*LAYOUT_Y_MARGIN),
107 sizeText);
108
109 y += 2*LAYOUT_X_MARGIN;
110
111 // text ctrl
112 m_textctrl = new wxTextCtrl(this, wxID_TEXT, m_value,
113 wxPoint(x, y),
114 wxSize(wText, hText));
115 y += hText + 2*LAYOUT_X_MARGIN;
116
117 // and buttons
118 CreateStandardButtons(wDialog, y, sizeBtn.GetWidth(), sizeBtn.GetHeight());
119
120 // set the dialog size and position
121 SetClientSize(wDialog, hDialog);
122 if ( pos == wxDefaultPosition )
123 {
124 // centre the dialog if no explicit position given
125 Centre(wxBOTH | wxCENTER_FRAME);
126 }
127
128 m_textctrl->SetFocus();
129 }
130
131 void wxTextEntryDialog::OnOK(wxCommandEvent& WXUNUSED(event) )
132 {
133 m_value = m_textctrl->GetValue();
134
135 EndModal(wxID_OK);
136 }
137