]> git.saurik.com Git - wxWidgets.git/blame - src/generic/numdlgg.cpp
1. wxFileDataObject fixes from Ricky Gonzales - seems to work, so demo added
[wxWidgets.git] / src / generic / numdlgg.cpp
CommitLineData
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
9// Licence: wxWindows license
10/////////////////////////////////////////////////////////////////////////////
11
12// ============================================================================
13// declarations
14// ============================================================================
15
16// ----------------------------------------------------------------------------
17// headers
18// ----------------------------------------------------------------------------
19
20#ifdef __GNUG__
21 #pragma interface "numdlgg.h"
22 #pragma implementation "numdlgg.h"
23#endif
24
25// For compilers that support precompilation, includes "wx.h".
26#include "wx/wxprec.h"
27
28#ifdef __BORLANDC__
29 #pragma hdrstop
30#endif
31
32#ifndef WX_PRECOMP
33 #include <stdio.h>
34
35 #include "wx/utils.h"
36 #include "wx/dialog.h"
37 #include "wx/button.h"
38 #include "wx/stattext.h"
39 #include "wx/textctrl.h"
40 #include "wx/intl.h"
073478b3
RR
41 #include "wx/sizer.h"
42#endif
43
44#if wxUSE_STATLINE
45 #include "wx/statline.h"
31528cd3
VZ
46#endif
47
678cd6de
VZ
48#include "wx/spinctrl.h"
49
31528cd3
VZ
50// this is where wxGetNumberFromUser() is declared
51#include "wx/generic/textdlgg.h"
52
53// ----------------------------------------------------------------------------
54// private classes
55// ----------------------------------------------------------------------------
56
57class WXDLLEXPORT wxNumberEntryDialog : public wxDialog
58{
59public:
60 wxNumberEntryDialog(wxWindow *parent,
61 const wxString& message,
62 const wxString& prompt,
63 const wxString& caption,
64 long value, long min, long max,
65 const wxPoint& pos);
66
67 long GetValue() const { return m_value; }
68
69 // implementation only
70 void OnOK(wxCommandEvent& event);
71 void OnCancel(wxCommandEvent& event);
72
73protected:
678cd6de 74 wxSpinCtrl *m_spinctrl;
31528cd3
VZ
75
76 long m_value, m_min, m_max;
77
78private:
79 DECLARE_EVENT_TABLE()
80};
81
82// ============================================================================
83// implementation
84// ============================================================================
85
86// ----------------------------------------------------------------------------
87// wxNumberEntryDialog
88// ----------------------------------------------------------------------------
89
90BEGIN_EVENT_TABLE(wxNumberEntryDialog, wxDialog)
91 EVT_BUTTON(wxID_OK, wxNumberEntryDialog::OnOK)
92 EVT_BUTTON(wxID_CANCEL, wxNumberEntryDialog::OnCancel)
93END_EVENT_TABLE()
94
95wxNumberEntryDialog::wxNumberEntryDialog(wxWindow *parent,
96 const wxString& message,
97 const wxString& prompt,
98 const wxString& caption,
99 long value,
100 long min,
101 long max,
102 const wxPoint& pos)
103 : wxDialog(parent, -1, caption,
104 pos, wxDefaultSize,
8e877c19 105 wxDEFAULT_DIALOG_STYLE | wxDIALOG_MODAL )
31528cd3 106{
31528cd3
VZ
107 m_value = value;
108 m_max = max;
109 m_min = min;
110
073478b3 111 wxBeginBusyCursor();
678cd6de 112
92afa2b1 113 wxBoxSizer *topsizer = new wxBoxSizer( wxVERTICAL );
31528cd3 114
073478b3 115 // 1) text message
92afa2b1 116 topsizer->Add( CreateTextSizer( message ), 0, wxALL, 10 );
678cd6de 117
073478b3 118 // 2) prompt and text ctrl
92afa2b1 119 wxBoxSizer *inputsizer = new wxBoxSizer( wxHORIZONTAL );
073478b3
RR
120 // prompt if any
121 if (!prompt.IsEmpty())
122 inputsizer->Add( new wxStaticText( this, -1, prompt ), 0, wxCENTER | wxLEFT, 10 );
31528cd3
VZ
123 // spin ctrl
124 wxString valStr;
223d09f6 125 valStr.Printf(wxT("%lu"), m_value);
678cd6de 126 m_spinctrl = new wxSpinCtrl(this, -1, valStr, wxDefaultPosition, wxSize( 140, -1 ) );
073478b3 127 inputsizer->Add( m_spinctrl, 1, wxCENTER | wxLEFT | wxRIGHT, 10 );
678cd6de 128 // add both
073478b3
RR
129 topsizer->Add( inputsizer, 1, wxEXPAND | wxLEFT|wxRIGHT, 5 );
130
131#if wxUSE_STATLINE
132 // 3) static line
133 topsizer->Add( new wxStaticLine( this, -1 ), 0, wxEXPAND | wxLEFT|wxRIGHT|wxTOP, 10 );
134#endif
135
073478b3 136 // 4) buttons
92afa2b1 137 topsizer->Add( CreateButtonSizer( wxOK|wxCANCEL ), 0, wxCENTRE | wxALL, 10 );
678cd6de 138
073478b3
RR
139 SetSizer( topsizer );
140 SetAutoLayout( TRUE );
141
0ae2df30
RR
142 topsizer->SetSizeHints( this );
143 topsizer->Fit( this );
144
073478b3
RR
145 Centre( wxBOTH );
146
31528cd3 147 m_spinctrl->SetFocus();
073478b3
RR
148
149 wxEndBusyCursor();
31528cd3
VZ
150}
151
a4c97004 152void wxNumberEntryDialog::OnOK(wxCommandEvent& WXUNUSED(event))
31528cd3 153{
678cd6de
VZ
154 m_value = m_spinctrl->GetValue();
155 if ( m_value < m_min || m_value > m_max )
31528cd3
VZ
156 {
157 // not a number or out of range
158 m_value = -1;
159 }
160
161 EndModal(wxID_OK);
162}
163
a4c97004 164void wxNumberEntryDialog::OnCancel(wxCommandEvent& WXUNUSED(event))
31528cd3
VZ
165{
166 m_value = -1;
167
168 EndModal(wxID_CANCEL);
169}
170
171// ----------------------------------------------------------------------------
172// global functions
173// ----------------------------------------------------------------------------
174
175// wxGetTextFromUser is in utilscmn.cpp
176
177long wxGetNumberFromUser(const wxString& msg,
178 const wxString& prompt,
179 const wxString& title,
180 long value,
181 long min,
182 long max,
183 wxWindow *parent,
184 const wxPoint& pos)
185{
186 wxNumberEntryDialog dialog(parent, msg, prompt, title,
187 value, min, max, pos);
188 (void)dialog.ShowModal();
189
190 return dialog.GetValue();
191}