]> git.saurik.com Git - wxWidgets.git/blame - src/generic/textdlgg.cpp
some updates...
[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
c50f1fb9 9// Licence: wxWindows license
c801d85f
KB
10/////////////////////////////////////////////////////////////////////////////
11
c50f1fb9
VZ
12// ============================================================================
13// declarations
14// ============================================================================
15
16// ----------------------------------------------------------------------------
17// headers
18// ----------------------------------------------------------------------------
19
c801d85f 20#ifdef __GNUG__
c50f1fb9 21 #pragma implementation "textdlgg.h"
c801d85f
KB
22#endif
23
24// For compilers that support precompilation, includes "wx.h".
25#include "wx/wxprec.h"
26
27#ifdef __BORLANDC__
c50f1fb9 28 #pragma hdrstop
c801d85f
KB
29#endif
30
31#ifndef WX_PRECOMP
c50f1fb9
VZ
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"
dcf924a3
RR
40#endif
41
42#if wxUSE_STATLINE
c50f1fb9 43 #include "wx/statline.h"
c801d85f
KB
44#endif
45
46#include "wx/generic/textdlgg.h"
47
c50f1fb9
VZ
48// ----------------------------------------------------------------------------
49// constants
50// ----------------------------------------------------------------------------
51
52#define wxID_TEXT 3000
dcf924a3 53
c50f1fb9
VZ
54// ============================================================================
55// implementation
56// ============================================================================
57
58// ----------------------------------------------------------------------------
c801d85f 59// wxTextEntryDialog
c50f1fb9 60// ----------------------------------------------------------------------------
c801d85f
KB
61
62#if !USE_SHARED_LIBRARY
63BEGIN_EVENT_TABLE(wxTextEntryDialog, wxDialog)
c50f1fb9 64 EVT_BUTTON(wxID_OK, wxTextEntryDialog::OnOK)
c801d85f
KB
65END_EVENT_TABLE()
66
67IMPLEMENT_CLASS(wxTextEntryDialog, wxDialog)
68#endif
69
c50f1fb9
VZ
70wxTextEntryDialog::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)
c801d85f 79{
c50f1fb9
VZ
80 // calculate the sizes
81 // -------------------
dcf924a3 82
c50f1fb9
VZ
83 wxArrayString lines;
84 wxSize sizeText = SplitTextMessage(message, &lines);
dcf924a3 85
c50f1fb9 86 wxSize sizeBtn = GetStandardButtonSize();
dcf924a3 87
c50f1fb9
VZ
88 long wText = wxMax(4*sizeBtn.GetWidth(), sizeText.GetWidth());
89 long hText = GetStandardTextHeight();
dcf924a3 90
c50f1fb9
VZ
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;
dcf924a3 99
c50f1fb9
VZ
100 // create the controls
101 // -------------------
dcf924a3 102
c50f1fb9
VZ
103 // message
104 long x = 2*LAYOUT_X_MARGIN;
105 long y = CreateTextMessage(lines,
106 wxPoint(x, 2*LAYOUT_Y_MARGIN),
107 sizeText);
dcf924a3 108
c50f1fb9
VZ
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;
c801d85f 116
c50f1fb9
VZ
117 // and buttons
118 CreateStandardButtons(wDialog, y, sizeBtn.GetWidth(), sizeBtn.GetHeight());
c801d85f 119
c50f1fb9
VZ
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 }
c801d85f 127
c50f1fb9 128 m_textctrl->SetFocus();
c801d85f
KB
129}
130
131void wxTextEntryDialog::OnOK(wxCommandEvent& WXUNUSED(event) )
132{
c50f1fb9 133 m_value = m_textctrl->GetValue();
c801d85f 134
c50f1fb9 135 EndModal(wxID_OK);
c801d85f
KB
136}
137