]> git.saurik.com Git - wxWidgets.git/blame - src/gtk1/spinbutt.cpp
wxFrame size bug
[wxWidgets.git] / src / gtk1 / spinbutt.cpp
CommitLineData
8e189077
RR
1/////////////////////////////////////////////////////////////////////////////
2// Name: spinbutt.cpp
3// Purpose: wxSpinButton
4// Author: Robert
5// Modified by:
6// RCS-ID: $Id$
7// Copyright: (c) Robert Roebling
8// Licence: wxWindows licence
9/////////////////////////////////////////////////////////////////////////////
10
11#ifdef __GNUG__
12#pragma implementation "spinbutt.h"
13#endif
14
15#include "wx/spinbutt.h"
16#include "wx/utils.h"
f5368809 17#include <math.h>
8e189077
RR
18
19//-----------------------------------------------------------------------------
20// data
21//-----------------------------------------------------------------------------
22
23extern bool g_blockEventsOnDrag;
24
25//-----------------------------------------------------------------------------
26// "value_changed"
27//-----------------------------------------------------------------------------
28
29static void gtk_spinbutt_callback( GtkWidget *WXUNUSED(widget), wxSpinButton *win )
30{
31 if (!win->HasVMT()) return;
32 if (g_blockEventsOnDrag) return;
33
34 float diff = win->m_adjust->value - win->m_oldPos;
35 if (fabs(diff) < 0.2) return;
36
37 wxEventType command = wxEVT_NULL;
38
39 float line_step = win->m_adjust->step_increment;
40 float page_step = win->m_adjust->page_increment;
41
42 if (fabs(diff-line_step) < 0.2) command = wxEVT_SCROLL_LINEDOWN;
43 else if (fabs(diff+line_step) < 0.2) command = wxEVT_SCROLL_LINEUP;
44 else if (fabs(diff-page_step) < 0.2) command = wxEVT_SCROLL_PAGEDOWN;
45 else if (fabs(diff+page_step) < 0.2) command = wxEVT_SCROLL_PAGEUP;
46 else command = wxEVT_SCROLL_THUMBTRACK;
47
48 int value = (int)(win->m_adjust->value+0.5);
49
50 wxSpinEvent event( command, win->GetId());
51 event.SetPosition( value );
52 event.SetOrientation( wxVERTICAL );
53 event.SetEventObject( win );
54
55 win->ProcessEvent( event );
56}
57
58//-----------------------------------------------------------------------------
59// wxSpinButton
60//-----------------------------------------------------------------------------
61
62IMPLEMENT_DYNAMIC_CLASS(wxSpinButton,wxControl)
63
64BEGIN_EVENT_TABLE(wxSpinButton, wxControl)
65 EVT_SIZE(wxSpinButton::OnSize)
66END_EVENT_TABLE()
67
68wxSpinButton::wxSpinButton()
69{
70}
71
72bool wxSpinButton::Create(wxWindow *parent, wxWindowID id, const wxPoint& pos, const wxSize& size,
73 long style, const wxString& name)
74{
75 m_needParent = TRUE;
76
77 wxSize new_size = size;
78 new_size.x = 16;
79 if (new_size.y == -1) new_size.y = 30;
80
81 PreCreation( parent, id, pos, new_size, style, name );
82
83// SetValidator( validator );
84
85 m_oldPos = 0.0;
86
87 m_adjust = (GtkAdjustment*) gtk_adjustment_new( 0.0, 0.0, 100.0, 1.0, 5.0, 0.0);
88
89 m_widget = gtk_spin_button_new( m_adjust, 0, 0 );
90
91 gtk_spin_button_set_wrap( GTK_SPIN_BUTTON(m_widget), (m_windowStyle & wxSP_WRAP) );
92
93 gtk_signal_connect (GTK_OBJECT (m_adjust), "value_changed",
94 (GtkSignalFunc) gtk_spinbutt_callback, (gpointer) this );
95
96 m_parent->AddChild( this );
97
98 (m_parent->m_insertCallback)( m_parent, this );
99
100 PostCreation();
101
102 SetBackgroundColour( parent->GetBackgroundColour() );
103
104 Show( TRUE );
105
106 return TRUE;
107}
108
109wxSpinButton::~wxSpinButton()
110{
111}
112
113int wxSpinButton::GetMin() const
114{
115 wxCHECK_MSG( (m_widget != NULL), 0, "invalid spin button" );
116
117 return (int)(m_adjust->lower+0.5);
118}
119
120int wxSpinButton::GetMax() const
121{
122 wxCHECK_MSG( (m_widget != NULL), 0, "invalid spin button" );
123
124 return (int)(m_adjust->upper+0.5);
125}
126
127int wxSpinButton::GetValue() const
128{
129 wxCHECK_MSG( (m_widget != NULL), 0, "invalid spin button" );
130
131 return (int)(m_adjust->value+0.5);
132}
133
134void wxSpinButton::SetValue( int value )
135{
136 wxCHECK_RET( (m_widget != NULL), "invalid spin button" );
137
138 float fpos = (float)value;
139 m_oldPos = fpos;
140 if (fabs(fpos-m_adjust->value) < 0.2) return;
141 m_adjust->value = fpos;
142
143 gtk_signal_emit_by_name( GTK_OBJECT(m_adjust), "value_changed" );
144}
145
146void wxSpinButton::SetRange(int minVal, int maxVal)
147{
148 wxCHECK_RET( (m_widget != NULL), "invalid spin button" );
149
150 float fmin = (float)minVal;
151 float fmax = (float)maxVal;
152
153 if ((fabs(fmin-m_adjust->lower) < 0.2) &&
154 (fabs(fmax-m_adjust->upper) < 0.2))
155 return;
156
157 m_adjust->lower = fmin;
158 m_adjust->upper = fmax;
159
160 gtk_signal_emit_by_name( GTK_OBJECT(m_adjust), "changed" );
161}
162
163void wxSpinButton::OnSize( wxSizeEvent &WXUNUSED(event) )
164{
165 wxCHECK_RET( (m_widget != NULL), "invalid spin button" );
166
167 m_width = 16;
168 gtk_widget_set_usize( m_widget, m_width, m_height );
169}
170
171bool wxSpinButton::IsOwnGtkWindow( GdkWindow *window )
172{
173 return GTK_SPIN_BUTTON(m_widget)->panel == window;
174}
175
176void wxSpinButton::ApplyWidgetStyle()
177{
178 SetWidgetStyle();
179 gtk_widget_set_style( m_widget, m_widgetStyle );
180}
181
182//-----------------------------------------------------------------------------
183// wxSpinEvent
184//-----------------------------------------------------------------------------
185
186IMPLEMENT_DYNAMIC_CLASS(wxSpinEvent, wxScrollEvent)
187
188wxSpinEvent::wxSpinEvent(wxEventType commandType, int id):
189 wxScrollEvent(commandType, id)
190{
191}
192
193