]> git.saurik.com Git - wxWidgets.git/blame - src/generic/textdlgg.cpp
fixed SetWindowStyleFlag() to not remove WS_VISIBLE; also refresh the control automat...
[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$
6aa89a22 8// Copyright: (c) Julian Smart
65571936 9// Licence: wxWindows licence
c801d85f
KB
10/////////////////////////////////////////////////////////////////////////////
11
c50f1fb9
VZ
12// ============================================================================
13// declarations
14// ============================================================================
15
16// ----------------------------------------------------------------------------
17// headers
18// ----------------------------------------------------------------------------
19
14f355c2 20#if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
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
1e6feb95
VZ
31#if wxUSE_TEXTDLG
32
c801d85f 33#ifndef WX_PRECOMP
c50f1fb9
VZ
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"
92afa2b1 40 #include "wx/sizer.h"
dcf924a3
RR
41#endif
42
43#if wxUSE_STATLINE
c50f1fb9 44 #include "wx/statline.h"
c801d85f
KB
45#endif
46
47#include "wx/generic/textdlgg.h"
48
c50f1fb9
VZ
49// ----------------------------------------------------------------------------
50// constants
51// ----------------------------------------------------------------------------
52
c49245f8 53static const int wxID_TEXT = 3000;
dcf924a3 54
c50f1fb9
VZ
55// ============================================================================
56// implementation
57// ============================================================================
58
59// ----------------------------------------------------------------------------
c801d85f 60// wxTextEntryDialog
c50f1fb9 61// ----------------------------------------------------------------------------
c801d85f 62
c801d85f 63BEGIN_EVENT_TABLE(wxTextEntryDialog, wxDialog)
c50f1fb9 64 EVT_BUTTON(wxID_OK, wxTextEntryDialog::OnOK)
c801d85f
KB
65END_EVENT_TABLE()
66
67IMPLEMENT_CLASS(wxTextEntryDialog, wxDialog)
c801d85f 68
c50f1fb9
VZ
69wxTextEntryDialog::wxTextEntryDialog(wxWindow *parent,
70 const wxString& message,
71 const wxString& caption,
72 const wxString& value,
73 long style,
74 const wxPoint& pos)
ca65c044 75 : wxDialog(parent, wxID_ANY, caption, pos, wxDefaultSize,
c50f1fb9
VZ
76 wxDEFAULT_DIALOG_STYLE | wxDIALOG_MODAL),
77 m_value(value)
c801d85f 78{
92afa2b1
RR
79 m_dialogStyle = style;
80 m_value = value;
81
82 wxBeginBusyCursor();
479cd5de 83
92afa2b1
RR
84 wxBoxSizer *topsizer = new wxBoxSizer( wxVERTICAL );
85
86 // 1) text message
87 topsizer->Add( CreateTextSizer( message ), 0, wxALL, 10 );
479cd5de 88
92afa2b1 89 // 2) text ctrl
a294c6d5 90 m_textctrl = new wxTextCtrl(this, wxID_TEXT, value,
422d0ff0 91 wxDefaultPosition, wxSize(300, wxDefaultCoord),
a294c6d5 92 style & ~wxTextEntryDialogStyle);
92afa2b1
RR
93 topsizer->Add( m_textctrl, 1, wxEXPAND | wxLEFT|wxRIGHT, 15 );
94
fc0d5b6b
JS
95#if wxUSE_VALIDATORS
96 wxTextValidator validator( wxFILTER_NONE, &m_value );
97 m_textctrl->SetValidator( validator );
98#endif
99 // wxUSE_VALIDATORS
100
92afa2b1
RR
101#if wxUSE_STATLINE
102 // 3) static line
ca65c044 103 topsizer->Add( new wxStaticLine( this, wxID_ANY ), 0, wxEXPAND | wxLEFT|wxRIGHT|wxTOP, 10 );
92afa2b1
RR
104#endif
105
106 // 4) buttons
107 topsizer->Add( CreateButtonSizer( style ), 0, wxCENTRE | wxALL, 10 );
479cd5de 108
ca65c044 109 SetAutoLayout( true );
8b17ba72 110 SetSizer( topsizer );
479cd5de 111
92afa2b1
RR
112 topsizer->SetSizeHints( this );
113 topsizer->Fit( this );
92afa2b1 114
13d13a9e
WS
115 if ( ( style & wxCENTRE ) == wxCENTRE )
116 Centre( wxBOTH );
c801d85f 117
19de4eec 118 m_textctrl->SetSelection(-1, -1);
c50f1fb9 119 m_textctrl->SetFocus();
92afa2b1
RR
120
121 wxEndBusyCursor();
c801d85f
KB
122}
123
124void wxTextEntryDialog::OnOK(wxCommandEvent& WXUNUSED(event) )
125{
fc0d5b6b 126#if wxUSE_VALIDATORS
ca65c044 127 if( Validate() && TransferDataFromWindow() )
fc0d5b6b
JS
128 {
129 EndModal( wxID_OK );
130 }
131#else
c50f1fb9 132 m_value = m_textctrl->GetValue();
c801d85f 133
c50f1fb9 134 EndModal(wxID_OK);
fc0d5b6b
JS
135#endif
136 // wxUSE_VALIDATORS
c801d85f 137}
1e6feb95 138
a8f6ef51
VZ
139void wxTextEntryDialog::SetValue(const wxString& val)
140{
141 m_value = val;
142
143 m_textctrl->SetValue(val);
144}
145
fc0d5b6b
JS
146#if wxUSE_VALIDATORS
147void wxTextEntryDialog::SetTextValidator( long style )
148{
149 wxTextValidator validator( style, &m_value );
150 m_textctrl->SetValidator( validator );
151}
152
153void wxTextEntryDialog::SetTextValidator( wxTextValidator& validator )
154{
155 m_textctrl->SetValidator( validator );
156}
157
158#endif
159 // wxUSE_VALIDATORS
160
1e6feb95 161#endif // wxUSE_TEXTDLG