]> git.saurik.com Git - wxWidgets.git/blame - src/generic/numdlgg.cpp
only change the bitmap size for the borderless controls
[wxWidgets.git] / src / generic / numdlgg.cpp
CommitLineData
31528cd3 1/////////////////////////////////////////////////////////////////////////////
897b24cf 2// Name: src/generic/numdlgg.cpp
31528cd3
VZ
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
31528cd3
VZ
20// For compilers that support precompilation, includes "wx.h".
21#include "wx/wxprec.h"
22
23#ifdef __BORLANDC__
24 #pragma hdrstop
25#endif
26
1e6feb95
VZ
27#if wxUSE_NUMBERDLG
28
31528cd3
VZ
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"
073478b3
RR
38 #include "wx/sizer.h"
39#endif
40
41#if wxUSE_STATLINE
42 #include "wx/statline.h"
31528cd3
VZ
43#endif
44
3a5bcc4d 45#if wxUSE_SPINCTRL
678cd6de 46#include "wx/spinctrl.h"
f6bcfd97 47#endif
678cd6de 48
31528cd3 49// this is where wxGetNumberFromUser() is declared
fc5414a1 50#include "wx/numdlg.h"
31528cd3 51
a7540f46
VZ
52#if !wxUSE_SPINCTRL
53 // wxTextCtrl will do instead of wxSpinCtrl if we don't have it
54 #define wxSpinCtrl wxTextCtrl
55#endif
56
31528cd3
VZ
57// ============================================================================
58// implementation
59// ============================================================================
60
61// ----------------------------------------------------------------------------
62// wxNumberEntryDialog
63// ----------------------------------------------------------------------------
64
65BEGIN_EVENT_TABLE(wxNumberEntryDialog, wxDialog)
66 EVT_BUTTON(wxID_OK, wxNumberEntryDialog::OnOK)
67 EVT_BUTTON(wxID_CANCEL, wxNumberEntryDialog::OnCancel)
68END_EVENT_TABLE()
69
4b5e5cfb
MB
70IMPLEMENT_CLASS(wxNumberEntryDialog, wxDialog)
71
31528cd3
VZ
72wxNumberEntryDialog::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)
ca65c044 80 : wxDialog(parent, wxID_ANY, caption,
2a21ac15 81 pos, wxDefaultSize)
31528cd3 82{
31528cd3
VZ
83 m_value = value;
84 m_max = max;
85 m_min = min;
86
073478b3 87 wxBeginBusyCursor();
678cd6de 88
92afa2b1 89 wxBoxSizer *topsizer = new wxBoxSizer( wxVERTICAL );
001e76a9 90#if wxUSE_STATTEXT
073478b3 91 // 1) text message
92afa2b1 92 topsizer->Add( CreateTextSizer( message ), 0, wxALL, 10 );
897b24cf 93#endif
678cd6de 94
073478b3 95 // 2) prompt and text ctrl
92afa2b1 96 wxBoxSizer *inputsizer = new wxBoxSizer( wxHORIZONTAL );
132422c4
RN
97
98#if wxUSE_STATTEXT
073478b3 99 // prompt if any
897b24cf 100 if (!prompt.empty())
ca65c044 101 inputsizer->Add( new wxStaticText( this, wxID_ANY, prompt ), 0, wxCENTER | wxLEFT, 10 );
132422c4 102#endif
897b24cf 103
31528cd3
VZ
104 // spin ctrl
105 wxString valStr;
fc5414a1 106 valStr.Printf(wxT("%ld"), m_value);
422d0ff0 107 m_spinctrl = new wxSpinCtrl(this, wxID_ANY, valStr, wxDefaultPosition, wxSize( 140, wxDefaultCoord ) );
3a5bcc4d 108#if wxUSE_SPINCTRL
479cd5de 109 m_spinctrl->SetRange((int)m_min, (int)m_max);
5dd26b08 110#endif
073478b3 111 inputsizer->Add( m_spinctrl, 1, wxCENTER | wxLEFT | wxRIGHT, 10 );
678cd6de 112 // add both
897b24cf 113 topsizer->Add( inputsizer, 0, wxEXPAND | wxLEFT|wxRIGHT, 5 );
678cd6de 114
897b24cf 115 // 3) buttons if any
bd9f3519
VZ
116 wxSizer *buttonSizer = CreateSeparatedButtonSizer(wxOK | wxCANCEL);
117 if ( buttonSizer )
897b24cf 118 {
bd9f3519 119 topsizer->Add(buttonSizer, wxSizerFlags().Expand().DoubleBorder());
897b24cf 120 }
d2cdad17 121
073478b3 122 SetSizer( topsizer );
ca65c044 123 SetAutoLayout( true );
073478b3 124
0ae2df30
RR
125 topsizer->SetSizeHints( this );
126 topsizer->Fit( this );
127
073478b3
RR
128 Centre( wxBOTH );
129
8282369a 130 m_spinctrl->SetSelection(-1, -1);
31528cd3 131 m_spinctrl->SetFocus();
073478b3
RR
132
133 wxEndBusyCursor();
31528cd3
VZ
134}
135
a4c97004 136void wxNumberEntryDialog::OnOK(wxCommandEvent& WXUNUSED(event))
31528cd3 137{
a7540f46
VZ
138#if !wxUSE_SPINCTRL
139 wxString tmp = m_spinctrl->GetValue();
140 if ( wxSscanf(tmp, _T("%ld"), &m_value) != 1 )
fc5414a1 141 EndModal(wxID_CANCEL);
a7540f46
VZ
142 else
143#else
678cd6de 144 m_value = m_spinctrl->GetValue();
a7540f46 145#endif
678cd6de 146 if ( m_value < m_min || m_value > m_max )
31528cd3
VZ
147 {
148 // not a number or out of range
cdec37ac 149 m_value = -1;
fc5414a1 150 EndModal(wxID_CANCEL);
31528cd3
VZ
151 }
152
153 EndModal(wxID_OK);
154}
155
a4c97004 156void wxNumberEntryDialog::OnCancel(wxCommandEvent& WXUNUSED(event))
31528cd3 157{
31528cd3
VZ
158 EndModal(wxID_CANCEL);
159}
160
161// ----------------------------------------------------------------------------
162// global functions
163// ----------------------------------------------------------------------------
164
165// wxGetTextFromUser is in utilscmn.cpp
166
167long wxGetNumberFromUser(const wxString& msg,
168 const wxString& prompt,
169 const wxString& title,
170 long value,
171 long min,
172 long max,
173 wxWindow *parent,
174 const wxPoint& pos)
175{
176 wxNumberEntryDialog dialog(parent, msg, prompt, title,
177 value, min, max, pos);
fc5414a1 178 if (dialog.ShowModal() == wxID_OK)
cdec37ac 179 return dialog.GetValue();
ca65c044 180
fc5414a1 181 return -1;
31528cd3 182}
1e6feb95
VZ
183
184#endif // wxUSE_NUMBERDLG