]>
Commit | Line | Data |
---|---|---|
31528cd3 VZ |
1 | ///////////////////////////////////////////////////////////////////////////// |
2 | // Name: numdlgg.cpp | |
3 | // Purpose: wxGetNumberFromUser implementation | |
4 | // Author: Vadim Zeitlin | |
5 | // Modified by: | |
6 | // Created: 23.07.99 | |
7 | // RCS-ID: $Id$ | |
8 | // Copyright: (c) Vadim Zeitlin | |
65571936 | 9 | // Licence: wxWindows licence |
31528cd3 VZ |
10 | ///////////////////////////////////////////////////////////////////////////// |
11 | ||
12 | // ============================================================================ | |
13 | // declarations | |
14 | // ============================================================================ | |
15 | ||
16 | // ---------------------------------------------------------------------------- | |
17 | // headers | |
18 | // ---------------------------------------------------------------------------- | |
19 | ||
14f355c2 | 20 | #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA) |
ff83a770 | 21 | #pragma implementation "numdlgg.cpp" |
31528cd3 VZ |
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 | ||
1e6feb95 VZ |
31 | #if wxUSE_NUMBERDLG |
32 | ||
31528cd3 VZ |
33 | #ifndef WX_PRECOMP |
34 | #include <stdio.h> | |
35 | ||
36 | #include "wx/utils.h" | |
37 | #include "wx/dialog.h" | |
38 | #include "wx/button.h" | |
39 | #include "wx/stattext.h" | |
40 | #include "wx/textctrl.h" | |
41 | #include "wx/intl.h" | |
073478b3 RR |
42 | #include "wx/sizer.h" |
43 | #endif | |
44 | ||
45 | #if wxUSE_STATLINE | |
46 | #include "wx/statline.h" | |
31528cd3 VZ |
47 | #endif |
48 | ||
3a5bcc4d | 49 | #if wxUSE_SPINCTRL |
678cd6de | 50 | #include "wx/spinctrl.h" |
f6bcfd97 | 51 | #endif |
678cd6de | 52 | |
31528cd3 | 53 | // this is where wxGetNumberFromUser() is declared |
fc5414a1 | 54 | #include "wx/numdlg.h" |
31528cd3 | 55 | |
a7540f46 VZ |
56 | #if !wxUSE_SPINCTRL |
57 | // wxTextCtrl will do instead of wxSpinCtrl if we don't have it | |
58 | #define wxSpinCtrl wxTextCtrl | |
59 | #endif | |
60 | ||
d2cdad17 WS |
61 | // --------------------------------------------------------------------------- |
62 | // macros | |
63 | // --------------------------------------------------------------------------- | |
64 | ||
65 | /* Macro for avoiding #ifdefs when value have to be different depending on size of | |
66 | device we display on | |
67 | */ | |
68 | ||
69 | #if defined(__SMARTPHONE__) | |
70 | #define wxLARGESMALL(large,small) small | |
71 | #else | |
72 | #define wxLARGESMALL(large,small) large | |
73 | #endif | |
74 | ||
31528cd3 VZ |
75 | // ============================================================================ |
76 | // implementation | |
77 | // ============================================================================ | |
78 | ||
79 | // ---------------------------------------------------------------------------- | |
80 | // wxNumberEntryDialog | |
81 | // ---------------------------------------------------------------------------- | |
82 | ||
83 | BEGIN_EVENT_TABLE(wxNumberEntryDialog, wxDialog) | |
84 | EVT_BUTTON(wxID_OK, wxNumberEntryDialog::OnOK) | |
85 | EVT_BUTTON(wxID_CANCEL, wxNumberEntryDialog::OnCancel) | |
86 | END_EVENT_TABLE() | |
87 | ||
4b5e5cfb MB |
88 | IMPLEMENT_CLASS(wxNumberEntryDialog, wxDialog) |
89 | ||
31528cd3 VZ |
90 | wxNumberEntryDialog::wxNumberEntryDialog(wxWindow *parent, |
91 | const wxString& message, | |
92 | const wxString& prompt, | |
93 | const wxString& caption, | |
94 | long value, | |
95 | long min, | |
96 | long max, | |
97 | const wxPoint& pos) | |
ca65c044 | 98 | : wxDialog(parent, wxID_ANY, caption, |
2a21ac15 | 99 | pos, wxDefaultSize) |
31528cd3 | 100 | { |
31528cd3 VZ |
101 | m_value = value; |
102 | m_max = max; | |
103 | m_min = min; | |
104 | ||
073478b3 | 105 | wxBeginBusyCursor(); |
678cd6de | 106 | |
92afa2b1 | 107 | wxBoxSizer *topsizer = new wxBoxSizer( wxVERTICAL ); |
31528cd3 | 108 | |
073478b3 | 109 | // 1) text message |
92afa2b1 | 110 | topsizer->Add( CreateTextSizer( message ), 0, wxALL, 10 ); |
678cd6de | 111 | |
073478b3 | 112 | // 2) prompt and text ctrl |
92afa2b1 | 113 | wxBoxSizer *inputsizer = new wxBoxSizer( wxHORIZONTAL ); |
073478b3 RR |
114 | // prompt if any |
115 | if (!prompt.IsEmpty()) | |
ca65c044 | 116 | inputsizer->Add( new wxStaticText( this, wxID_ANY, prompt ), 0, wxCENTER | wxLEFT, 10 ); |
31528cd3 VZ |
117 | // spin ctrl |
118 | wxString valStr; | |
fc5414a1 | 119 | valStr.Printf(wxT("%ld"), m_value); |
422d0ff0 | 120 | m_spinctrl = new wxSpinCtrl(this, wxID_ANY, valStr, wxDefaultPosition, wxSize( 140, wxDefaultCoord ) ); |
3a5bcc4d | 121 | #if wxUSE_SPINCTRL |
479cd5de | 122 | m_spinctrl->SetRange((int)m_min, (int)m_max); |
5dd26b08 | 123 | #endif |
073478b3 | 124 | inputsizer->Add( m_spinctrl, 1, wxCENTER | wxLEFT | wxRIGHT, 10 ); |
678cd6de | 125 | // add both |
073478b3 RR |
126 | topsizer->Add( inputsizer, 1, wxEXPAND | wxLEFT|wxRIGHT, 5 ); |
127 | ||
d2cdad17 WS |
128 | #ifdef __SMARTPHONE__ |
129 | ||
130 | SetRightMenu(wxID_CANCEL, _("Cancel")); | |
131 | ||
132 | #else // __SMARTPHONE__/!__SMARTPHONE__ | |
133 | ||
073478b3 RR |
134 | #if wxUSE_STATLINE |
135 | // 3) static line | |
ca65c044 | 136 | topsizer->Add( new wxStaticLine( this, wxID_ANY ), 0, wxEXPAND | wxLEFT|wxRIGHT|wxTOP, 10 ); |
073478b3 RR |
137 | #endif |
138 | ||
073478b3 | 139 | // 4) buttons |
92afa2b1 | 140 | topsizer->Add( CreateButtonSizer( wxOK|wxCANCEL ), 0, wxCENTRE | wxALL, 10 ); |
678cd6de | 141 | |
d2cdad17 WS |
142 | #endif // !__SMARTPHONE__ |
143 | ||
073478b3 | 144 | SetSizer( topsizer ); |
ca65c044 | 145 | SetAutoLayout( true ); |
073478b3 | 146 | |
0ae2df30 RR |
147 | topsizer->SetSizeHints( this ); |
148 | topsizer->Fit( this ); | |
149 | ||
073478b3 RR |
150 | Centre( wxBOTH ); |
151 | ||
8282369a | 152 | m_spinctrl->SetSelection(-1, -1); |
31528cd3 | 153 | m_spinctrl->SetFocus(); |
073478b3 RR |
154 | |
155 | wxEndBusyCursor(); | |
31528cd3 VZ |
156 | } |
157 | ||
a4c97004 | 158 | void wxNumberEntryDialog::OnOK(wxCommandEvent& WXUNUSED(event)) |
31528cd3 | 159 | { |
a7540f46 VZ |
160 | #if !wxUSE_SPINCTRL |
161 | wxString tmp = m_spinctrl->GetValue(); | |
162 | if ( wxSscanf(tmp, _T("%ld"), &m_value) != 1 ) | |
fc5414a1 | 163 | EndModal(wxID_CANCEL); |
a7540f46 VZ |
164 | else |
165 | #else | |
678cd6de | 166 | m_value = m_spinctrl->GetValue(); |
a7540f46 | 167 | #endif |
678cd6de | 168 | if ( m_value < m_min || m_value > m_max ) |
31528cd3 VZ |
169 | { |
170 | // not a number or out of range | |
fc5414a1 | 171 | EndModal(wxID_CANCEL); |
31528cd3 VZ |
172 | } |
173 | ||
174 | EndModal(wxID_OK); | |
175 | } | |
176 | ||
a4c97004 | 177 | void wxNumberEntryDialog::OnCancel(wxCommandEvent& WXUNUSED(event)) |
31528cd3 | 178 | { |
31528cd3 VZ |
179 | EndModal(wxID_CANCEL); |
180 | } | |
181 | ||
182 | // ---------------------------------------------------------------------------- | |
183 | // global functions | |
184 | // ---------------------------------------------------------------------------- | |
185 | ||
186 | // wxGetTextFromUser is in utilscmn.cpp | |
187 | ||
188 | long wxGetNumberFromUser(const wxString& msg, | |
189 | const wxString& prompt, | |
190 | const wxString& title, | |
191 | long value, | |
192 | long min, | |
193 | long max, | |
194 | wxWindow *parent, | |
195 | const wxPoint& pos) | |
196 | { | |
197 | wxNumberEntryDialog dialog(parent, msg, prompt, title, | |
198 | value, min, max, pos); | |
fc5414a1 | 199 | if (dialog.ShowModal() == wxID_OK) |
31528cd3 | 200 | return dialog.GetValue(); |
ca65c044 | 201 | |
fc5414a1 | 202 | return -1; |
31528cd3 | 203 | } |
1e6feb95 VZ |
204 | |
205 | #endif // wxUSE_NUMBERDLG |