]>
git.saurik.com Git - wxWidgets.git/blob - src/gtk/spinbutt.cpp
   1 ///////////////////////////////////////////////////////////////////////////// 
   2 // Name:        src/gtk/spinbutt.cpp 
   3 // Purpose:     wxSpinButton 
   7 // Copyright:   (c) Robert Roebling 
   8 // Licence:     wxWindows licence 
   9 ///////////////////////////////////////////////////////////////////////////// 
  11 // For compilers that support precompilation, includes "wx.h". 
  12 #include "wx/wxprec.h" 
  16 #include "wx/spinbutt.h" 
  22 #include "wx/gtk/private.h" 
  24 //----------------------------------------------------------------------------- 
  26 //----------------------------------------------------------------------------- 
  28 extern bool   g_blockEventsOnDrag
; 
  30 //----------------------------------------------------------------------------- 
  32 //----------------------------------------------------------------------------- 
  36 gtk_value_changed(GtkSpinButton
* spinbutton
, wxSpinButton
* win
) 
  38     if (g_isIdle
) wxapp_install_idle_handler(); 
  40     const double value 
= gtk_spin_button_get_value(spinbutton
); 
  41     const int pos 
= int(value
); 
  42     const int oldPos 
= win
->m_pos
; 
  43     if (!win
->m_hasVMT 
|| g_blockEventsOnDrag 
|| win
->m_blockScrollEvent 
|| pos 
== oldPos
) 
  49     wxSpinEvent 
event(pos 
> oldPos 
? wxEVT_SCROLL_LINEUP 
: wxEVT_SCROLL_LINEDOWN
, win
->GetId()); 
  50     event
.SetPosition(pos
); 
  51     event
.SetEventObject(win
); 
  53     if ((win
->GetEventHandler()->ProcessEvent( event 
)) && 
  56         /* program has vetoed */ 
  57         win
->BlockScrollEvent(); 
  58         gtk_spin_button_set_value(spinbutton
, oldPos
); 
  59         win
->UnblockScrollEvent(); 
  65     /* always send a thumbtrack event */ 
  66     wxSpinEvent 
event2(wxEVT_SCROLL_THUMBTRACK
, win
->GetId()); 
  67     event2
.SetPosition(pos
); 
  68     event2
.SetEventObject(win
); 
  69     win
->GetEventHandler()->ProcessEvent(event2
); 
  73 //----------------------------------------------------------------------------- 
  75 //----------------------------------------------------------------------------- 
  77 IMPLEMENT_DYNAMIC_CLASS(wxSpinButton
,wxControl
) 
  78 IMPLEMENT_DYNAMIC_CLASS(wxSpinEvent
, wxNotifyEvent
) 
  80 BEGIN_EVENT_TABLE(wxSpinButton
, wxControl
) 
  81     EVT_SIZE(wxSpinButton::OnSize
) 
  84 wxSpinButton::wxSpinButton() 
  89 bool wxSpinButton::Create(wxWindow 
*parent
, 
  98     wxSize new_size 
= size
, 
  99            sizeBest 
= DoGetBestSize(); 
 100     new_size
.x 
= sizeBest
.x
;            // override width always 
 101     if (new_size
.y 
== -1) 
 102         new_size
.y 
= sizeBest
.y
; 
 104     if (!PreCreation( parent
, pos
, new_size 
) || 
 105         !CreateBase( parent
, id
, pos
, new_size
, style
, wxDefaultValidator
, name 
)) 
 107         wxFAIL_MSG( wxT("wxSpinButton creation failed") ); 
 113     m_widget 
= gtk_spin_button_new_with_range(0, 100, 1); 
 115     gtk_spin_button_set_wrap( GTK_SPIN_BUTTON(m_widget
), 
 116                               (int)(m_windowStyle 
& wxSP_WRAP
) ); 
 118     g_signal_connect_after( 
 119         m_widget
, "value_changed", G_CALLBACK(gtk_value_changed
), this); 
 121     m_parent
->DoAddChild( this ); 
 123     PostCreation(new_size
); 
 128 int wxSpinButton::GetMin() const 
 130     wxCHECK_MSG( (m_widget 
!= NULL
), 0, wxT("invalid spin button") ); 
 133     gtk_spin_button_get_range((GtkSpinButton
*)m_widget
, &min
, NULL
); 
 137 int wxSpinButton::GetMax() const 
 139     wxCHECK_MSG( (m_widget 
!= NULL
), 0, wxT("invalid spin button") ); 
 142     gtk_spin_button_get_range((GtkSpinButton
*)m_widget
, NULL
, &max
); 
 146 int wxSpinButton::GetValue() const 
 148     wxCHECK_MSG( (m_widget 
!= NULL
), 0, wxT("invalid spin button") ); 
 153 void wxSpinButton::SetValue( int value 
) 
 155     wxCHECK_RET( (m_widget 
!= NULL
), wxT("invalid spin button") ); 
 158     gtk_spin_button_set_value((GtkSpinButton
*)m_widget
, value
); 
 159     UnblockScrollEvent(); 
 162 void wxSpinButton::SetRange(int minVal
, int maxVal
) 
 164     wxCHECK_RET( (m_widget 
!= NULL
), wxT("invalid spin button") ); 
 167     gtk_spin_button_set_range((GtkSpinButton
*)m_widget
, minVal
, maxVal
); 
 168     UnblockScrollEvent(); 
 171 void wxSpinButton::OnSize( wxSizeEvent 
&WXUNUSED(event
) ) 
 173     wxCHECK_RET( (m_widget 
!= NULL
), wxT("invalid spin button") ); 
 175     m_width 
= DoGetBestSize().x
; 
 176     gtk_widget_set_size_request( m_widget
, m_width
, m_height 
); 
 179 bool wxSpinButton::IsOwnGtkWindow( GdkWindow 
*window 
) 
 181     return GTK_SPIN_BUTTON(m_widget
)->panel 
== window
; 
 184 wxSize 
wxSpinButton::DoGetBestSize() const 
 186     wxSize 
best(15, 26); // FIXME 
 193 wxSpinButton::GetClassDefaultAttributes(wxWindowVariant 
WXUNUSED(variant
)) 
 195     // TODO: overload to accept functions like gtk_spin_button_new? 
 196     // Until then use a similar type 
 197     return GetDefaultAttributesFromGTKWidget(gtk_button_new
);