/[pcsx2_0.9.7]/branch/r3113_0.9.7_beta/3rdparty/wxWidgets/src/generic/numdlgg.cpp
ViewVC logotype

Annotation of /branch/r3113_0.9.7_beta/3rdparty/wxWidgets/src/generic/numdlgg.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 31 - (hide annotations) (download)
Tue Sep 7 03:24:11 2010 UTC (10 years ago) by william
Original Path: trunk/3rdparty/wxWidgets/src/generic/numdlgg.cpp
File size: 5372 byte(s)
committing r3113 initial commit again...
1 william 31 /////////////////////////////////////////////////////////////////////////////
2     // Name: src/generic/numdlgg.cpp
3     // Purpose: wxGetNumberFromUser implementation
4     // Author: Vadim Zeitlin
5     // Modified by:
6     // Created: 23.07.99
7     // RCS-ID: $Id: numdlgg.cpp 54861 2008-07-30 21:53:26Z VZ $
8     // Copyright: (c) Vadim Zeitlin
9     // Licence: wxWindows licence
10     /////////////////////////////////////////////////////////////////////////////
11    
12     // ============================================================================
13     // declarations
14     // ============================================================================
15    
16     // ----------------------------------------------------------------------------
17     // headers
18     // ----------------------------------------------------------------------------
19    
20     // For compilers that support precompilation, includes "wx.h".
21     #include "wx/wxprec.h"
22    
23     #ifdef __BORLANDC__
24     #pragma hdrstop
25     #endif
26    
27     #if wxUSE_NUMBERDLG
28    
29     #ifndef WX_PRECOMP
30     #include <stdio.h>
31    
32     #include "wx/utils.h"
33     #include "wx/dialog.h"
34     #include "wx/button.h"
35     #include "wx/stattext.h"
36     #include "wx/textctrl.h"
37     #include "wx/intl.h"
38     #include "wx/sizer.h"
39     #endif
40    
41     #if wxUSE_STATLINE
42     #include "wx/statline.h"
43     #endif
44    
45     #if wxUSE_SPINCTRL
46     #include "wx/spinctrl.h"
47     #endif
48    
49     // this is where wxGetNumberFromUser() is declared
50     #include "wx/numdlg.h"
51    
52     #if !wxUSE_SPINCTRL
53     // wxTextCtrl will do instead of wxSpinCtrl if we don't have it
54     #define wxSpinCtrl wxTextCtrl
55     #endif
56    
57     // ============================================================================
58     // implementation
59     // ============================================================================
60    
61     // ----------------------------------------------------------------------------
62     // wxNumberEntryDialog
63     // ----------------------------------------------------------------------------
64    
65     BEGIN_EVENT_TABLE(wxNumberEntryDialog, wxDialog)
66     EVT_BUTTON(wxID_OK, wxNumberEntryDialog::OnOK)
67     EVT_BUTTON(wxID_CANCEL, wxNumberEntryDialog::OnCancel)
68     END_EVENT_TABLE()
69    
70     IMPLEMENT_CLASS(wxNumberEntryDialog, wxDialog)
71    
72     wxNumberEntryDialog::wxNumberEntryDialog(wxWindow *parent,
73     const wxString& message,
74     const wxString& prompt,
75     const wxString& caption,
76     long value,
77     long min,
78     long max,
79     const wxPoint& pos)
80     : wxDialog(parent, wxID_ANY, caption,
81     pos, wxDefaultSize)
82     {
83     m_value = value;
84     m_max = max;
85     m_min = min;
86    
87     wxBeginBusyCursor();
88    
89     wxBoxSizer *topsizer = new wxBoxSizer( wxVERTICAL );
90     #if wxUSE_STATTEXT
91     // 1) text message
92     topsizer->Add( CreateTextSizer( message ), 0, wxALL, 10 );
93     #endif
94    
95     // 2) prompt and text ctrl
96     wxBoxSizer *inputsizer = new wxBoxSizer( wxHORIZONTAL );
97    
98     #if wxUSE_STATTEXT
99     // prompt if any
100     if (!prompt.empty())
101     inputsizer->Add( new wxStaticText( this, wxID_ANY, prompt ), 0, wxCENTER | wxLEFT, 10 );
102     #endif
103    
104     // spin ctrl
105     wxString valStr;
106     valStr.Printf(wxT("%ld"), m_value);
107     m_spinctrl = new wxSpinCtrl(this, wxID_ANY, valStr, wxDefaultPosition, wxSize( 140, wxDefaultCoord ), wxSP_ARROW_KEYS, (int)m_min, (int)m_max, (int)m_value);
108     inputsizer->Add( m_spinctrl, 1, wxCENTER | wxLEFT | wxRIGHT, 10 );
109     // add both
110     topsizer->Add( inputsizer, 0, wxEXPAND | wxLEFT|wxRIGHT, 5 );
111    
112     // 3) buttons if any
113     wxSizer *buttonSizer = CreateSeparatedButtonSizer(wxOK | wxCANCEL);
114     if ( buttonSizer )
115     {
116     topsizer->Add(buttonSizer, wxSizerFlags().Expand().DoubleBorder());
117     }
118    
119     SetSizer( topsizer );
120     SetAutoLayout( true );
121    
122     topsizer->SetSizeHints( this );
123     topsizer->Fit( this );
124    
125     Centre( wxBOTH );
126    
127     m_spinctrl->SetSelection(-1, -1);
128     m_spinctrl->SetFocus();
129    
130     wxEndBusyCursor();
131     }
132    
133     void wxNumberEntryDialog::OnOK(wxCommandEvent& WXUNUSED(event))
134     {
135     #if !wxUSE_SPINCTRL
136     wxString tmp = m_spinctrl->GetValue();
137     if ( wxSscanf(tmp, _T("%ld"), &m_value) != 1 )
138     EndModal(wxID_CANCEL);
139     else
140     #else
141     m_value = m_spinctrl->GetValue();
142     #endif
143     if ( m_value < m_min || m_value > m_max )
144     {
145     // not a number or out of range
146     m_value = -1;
147     EndModal(wxID_CANCEL);
148     }
149    
150     EndModal(wxID_OK);
151     }
152    
153     void wxNumberEntryDialog::OnCancel(wxCommandEvent& WXUNUSED(event))
154     {
155     EndModal(wxID_CANCEL);
156     }
157    
158     // ----------------------------------------------------------------------------
159     // global functions
160     // ----------------------------------------------------------------------------
161    
162     // wxGetTextFromUser is in utilscmn.cpp
163    
164     long wxGetNumberFromUser(const wxString& msg,
165     const wxString& prompt,
166     const wxString& title,
167     long value,
168     long min,
169     long max,
170     wxWindow *parent,
171     const wxPoint& pos)
172     {
173     wxNumberEntryDialog dialog(parent, msg, prompt, title,
174     value, min, max, pos);
175     if (dialog.ShowModal() == wxID_OK)
176     return dialog.GetValue();
177    
178     return -1;
179     }
180    
181     #endif // wxUSE_NUMBERDLG

  ViewVC Help
Powered by ViewVC 1.1.22