~ubuntu-dev/wxwidgets2.6/upstream-debian

« back to all changes in this revision

Viewing changes to src/generic/textdlgg.cpp

  • Committer: Daniel T Chen
  • Date: 2006-06-26 10:15:11 UTC
  • Revision ID: crimsun@ubuntu.com-20060626101511-a4436cec4c6d9b35
ImportĀ DebianĀ 2.6.3.2.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/////////////////////////////////////////////////////////////////////////////
 
2
// Name:        textdlgg.cpp
 
3
// Purpose:     wxTextEntryDialog
 
4
// Author:      Julian Smart
 
5
// Modified by:
 
6
// Created:     04/01/98
 
7
// RCS-ID:      $Id: textdlgg.cpp,v 1.35 2005/04/02 17:44:12 JS Exp $
 
8
// Copyright:   (c) Julian Smart
 
9
// Licence:     wxWindows licence
 
10
/////////////////////////////////////////////////////////////////////////////
 
11
 
 
12
// ============================================================================
 
13
// declarations
 
14
// ============================================================================
 
15
 
 
16
// ----------------------------------------------------------------------------
 
17
// headers
 
18
// ----------------------------------------------------------------------------
 
19
 
 
20
#if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
 
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
#if wxUSE_TEXTDLG
 
32
 
 
33
#ifndef WX_PRECOMP
 
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
    #include "wx/sizer.h"
 
41
#endif
 
42
 
 
43
#if wxUSE_STATLINE
 
44
    #include "wx/statline.h"
 
45
#endif
 
46
 
 
47
#include "wx/generic/textdlgg.h"
 
48
 
 
49
// ----------------------------------------------------------------------------
 
50
// constants
 
51
// ----------------------------------------------------------------------------
 
52
 
 
53
static const int wxID_TEXT = 3000;
 
54
 
 
55
// ---------------------------------------------------------------------------
 
56
// macros
 
57
// ---------------------------------------------------------------------------
 
58
 
 
59
/* Macro for avoiding #ifdefs when value have to be different depending on size of
 
60
   device we display on - take it from something like wxDesktopPolicy in the future
 
61
 */
 
62
 
 
63
#if defined(__SMARTPHONE__)
 
64
    #define wxLARGESMALL(large,small) small
 
65
#else
 
66
    #define wxLARGESMALL(large,small) large
 
67
#endif
 
68
 
 
69
// ============================================================================
 
70
// implementation
 
71
// ============================================================================
 
72
 
 
73
// ----------------------------------------------------------------------------
 
74
// wxTextEntryDialog
 
75
// ----------------------------------------------------------------------------
 
76
 
 
77
BEGIN_EVENT_TABLE(wxTextEntryDialog, wxDialog)
 
78
    EVT_BUTTON(wxID_OK, wxTextEntryDialog::OnOK)
 
79
END_EVENT_TABLE()
 
80
 
 
81
IMPLEMENT_CLASS(wxTextEntryDialog, wxDialog)
 
82
 
 
83
wxTextEntryDialog::wxTextEntryDialog(wxWindow *parent,
 
84
                                     const wxString& message,
 
85
                                     const wxString& caption,
 
86
                                     const wxString& value,
 
87
                                     long style,
 
88
                                     const wxPoint& pos)
 
89
                 : wxDialog(parent, wxID_ANY, caption, pos, wxDefaultSize,
 
90
                            wxDEFAULT_DIALOG_STYLE | wxDIALOG_MODAL),
 
91
                   m_value(value)
 
92
{
 
93
    m_dialogStyle = style;
 
94
    m_value = value;
 
95
 
 
96
    wxBeginBusyCursor();
 
97
 
 
98
    wxBoxSizer *topsizer = new wxBoxSizer( wxVERTICAL );
 
99
 
 
100
#if wxUSE_STATTEXT
 
101
    // 1) text message
 
102
    topsizer->Add( CreateTextSizer( message ), 0, wxALL, wxLARGESMALL(10,0) );
 
103
#endif        
 
104
 
 
105
    // 2) text ctrl
 
106
    m_textctrl = new wxTextCtrl(this, wxID_TEXT, value,
 
107
                                wxDefaultPosition, wxSize(300, wxDefaultCoord),
 
108
                                style & ~wxTextEntryDialogStyle);
 
109
    topsizer->Add( m_textctrl, style & wxTE_MULTILINE ? 1 : 0, wxEXPAND | wxLEFT|wxRIGHT, wxLARGESMALL(15,0) );
 
110
 
 
111
#if wxUSE_VALIDATORS
 
112
    wxTextValidator validator( wxFILTER_NONE, &m_value );
 
113
    m_textctrl->SetValidator( validator );
 
114
#endif
 
115
  // wxUSE_VALIDATORS
 
116
 
 
117
    // smart phones does not support or do not waste space for wxButtons
 
118
#ifdef __SMARTPHONE__
 
119
 
 
120
    SetRightMenu(wxID_CANCEL, _("Cancel"));
 
121
 
 
122
#else // __SMARTPHONE__/!__SMARTPHONE__
 
123
 
 
124
#if wxUSE_STATLINE
 
125
    // 3) static line
 
126
    topsizer->Add( new wxStaticLine( this, wxID_ANY ), 0, wxEXPAND | wxLEFT|wxRIGHT|wxTOP, 10 );
 
127
#endif
 
128
 
 
129
    // 4) buttons
 
130
    topsizer->Add( CreateButtonSizer( style ), 0, wxEXPAND | wxALL, 10 );
 
131
 
 
132
#endif // !__SMARTPHONE__
 
133
 
 
134
    SetAutoLayout( true );
 
135
    SetSizer( topsizer );
 
136
 
 
137
#if !defined(__SMARTPHONE__) && !defined(__POCKETPC__)
 
138
    topsizer->SetSizeHints( this );
 
139
    topsizer->Fit( this );
 
140
 
 
141
    if ( style & wxCENTRE )
 
142
        Centre( wxBOTH );
 
143
#endif
 
144
 
 
145
    m_textctrl->SetSelection(-1, -1);
 
146
    m_textctrl->SetFocus();
 
147
 
 
148
    wxEndBusyCursor();
 
149
}
 
150
 
 
151
void wxTextEntryDialog::OnOK(wxCommandEvent& WXUNUSED(event) )
 
152
{
 
153
#if wxUSE_VALIDATORS
 
154
    if( Validate() && TransferDataFromWindow() )
 
155
    {
 
156
        EndModal( wxID_OK );
 
157
    }
 
158
#else
 
159
    m_value = m_textctrl->GetValue();
 
160
 
 
161
    EndModal(wxID_OK);
 
162
#endif
 
163
  // wxUSE_VALIDATORS
 
164
}
 
165
 
 
166
void wxTextEntryDialog::SetValue(const wxString& val)
 
167
{
 
168
    m_value = val;
 
169
 
 
170
    m_textctrl->SetValue(val);
 
171
}
 
172
 
 
173
#if wxUSE_VALIDATORS
 
174
void wxTextEntryDialog::SetTextValidator( long style )
 
175
{
 
176
    wxTextValidator validator( style, &m_value );
 
177
    m_textctrl->SetValidator( validator );
 
178
}
 
179
 
 
180
void wxTextEntryDialog::SetTextValidator( wxTextValidator& validator )
 
181
{
 
182
    m_textctrl->SetValidator( validator );
 
183
}
 
184
 
 
185
#endif
 
186
  // wxUSE_VALIDATORS
 
187
 
 
188
// ----------------------------------------------------------------------------
 
189
// wxPasswordEntryDialog
 
190
// ----------------------------------------------------------------------------
 
191
 
 
192
IMPLEMENT_CLASS(wxPasswordEntryDialog, wxTextEntryDialog)
 
193
 
 
194
wxPasswordEntryDialog::wxPasswordEntryDialog(wxWindow *parent,
 
195
                                     const wxString& message,
 
196
                                     const wxString& caption,
 
197
                                     const wxString& value,
 
198
                                     long style,
 
199
                                     const wxPoint& pos)
 
200
                 : wxTextEntryDialog(parent, message, caption, value,
 
201
                                     style | wxTE_PASSWORD, pos)
 
202
{
 
203
    // Only change from wxTextEntryDialog is the password style
 
204
}
 
205
 
 
206
#endif // wxUSE_TEXTDLG