slidercombo.cpp

Go to the documentation of this file.
00001 
00002 // Name:        slidercombo.cpp
00003 // Purpose:     A pop-up slider combo control
00004 // Author:      Mart Raudsepp
00005 // Modified by:
00006 // Created:     2006-07-06
00007 // RCS-ID:      $Id: $
00008 // Copyright:   (c) 2006 Mart Raudsepp
00009 // Licence:     wxWindows licence
00011 
00012 #include "slidercombo.h"
00013 
00014 #include <wx/slider.h>
00015 
00016 #ifdef __WXGTK20__
00017 #include <gtk/gtk.h>
00018 
00019 extern "C" {
00020 static gboolean
00021 xara_slidercombo_expose_callback( GtkWidget *widget,
00022                                   GdkEventExpose *gdk_event,
00023                                   gboolean user_data )
00024 {
00025     gtk_paint_box (widget->style,
00026                    widget->window,
00027                    GTK_STATE_NORMAL,
00028                    GTK_SHADOW_OUT,
00029                    NULL, widget, "menu",
00030                    0, 0,
00031                    widget->allocation.width, widget->allocation.height);
00032 
00033     return FALSE;
00034 }
00035 }
00036 #endif
00037 
00038 class wxSliderComboPopup : public wxSlider, public wxComboPopup
00039 {
00040 public:
00041 
00042     virtual void Init()
00043     {
00044     }
00045 
00046     virtual bool Create( wxWindow* parent )
00047     {
00048         long style = m_combo->GetWindowStyleFlag();
00049         style &= wxSL_HORIZONTAL | wxSL_VERTICAL | wxSL_LABELS | wxSL_INVERSE;
00050 
00051         // Add raised border for other ports (gtk2 draws its native one with the expose callback)
00052 #ifndef __WXGTK20__
00053         style |= wxRAISED_BORDER;
00054 #endif
00055 
00056         if (wxSlider::Create(parent, wxID_ANY,
00057                              50, 0, 100,
00058                              wxDefaultPosition, wxDefaultSize,
00059                              style))
00060         {
00061 #ifdef __WXGTK20__
00062             g_signal_connect (m_widget, "expose_event",
00063                               G_CALLBACK (xara_slidercombo_expose_callback), NULL);
00064 #endif
00065             return true;
00066         }
00067         return false;
00068     }
00069 
00070     virtual void OnShow()
00071     {
00072     }
00073 
00074     virtual wxSize GetAdjustedSize( int minWidth,
00075                                     int WXUNUSED(prefHeight),
00076                                     int maxHeight )
00077     {
00078         wxSize sz = GetBestSize();
00079         return wxSize(wxMax(120, minWidth), wxMin(sz.GetHeight(), maxHeight));
00080     }
00081 
00082     virtual wxWindow *GetControl() { return this; }
00083 
00084     virtual void SetStringValue( const wxString& s )
00085     {
00086     }
00087 
00088     virtual wxString GetStringValue() const
00089     {
00090         // FIXME: Does this get called in wxGTK? On wxMSW this gets called on popup close
00091         return m_combo->GetValue();
00092     }
00093 
00094 protected:
00095     void OnSliderScrollEvent(wxScrollEvent& event)
00096     {
00097         wxScrollEvent ev( event.GetEventType(),
00098                           m_combo->GetId(),
00099                           event.GetPosition(),
00100                           event.GetOrientation() );
00101         ev.SetEventObject( m_combo );
00102         m_combo->GetEventHandler()->ProcessEvent( ev );
00103         if (event.GetEventType() == wxEVT_SCROLL_THUMBRELEASE)
00104             m_combo->HidePopup();
00105     }
00106 
00107 private:
00108     DECLARE_EVENT_TABLE()
00109 };
00110 
00111 BEGIN_EVENT_TABLE(wxSliderComboPopup, wxSlider)
00112     EVT_SCROLL(wxSliderComboPopup::OnSliderScrollEvent)
00113 END_EVENT_TABLE()
00114 
00115 
00116 IMPLEMENT_DYNAMIC_CLASS(wxSliderCombo, wxComboCtrl)
00117 
00118 void wxSliderCombo::Init()
00119 {
00120     m_slider = NULL;
00121     m_suffix = wxEmptyString;
00122     m_automatic_updates = true;
00123 }
00124 
00125 wxSliderCombo::wxSliderCombo(wxWindow *parent, wxWindowID id, int value,
00126                              const wxPoint& pos, const wxSize& size,
00127                              long style, const wxString& name)
00128 // FIXME: initial string and validator should maybe be in our ctor too?
00129 {
00130     Init();
00131     Create(parent, id, value, pos, size, style, name);
00132 }
00133 
00134 bool wxSliderCombo::Create(wxWindow *parent, wxWindowID id,
00135                            int value,
00136                            const wxPoint& pos, const wxSize& size,
00137                            long style, const wxString& name)
00138 {
00139     if (wxComboCtrl::Create(parent, id, wxEmptyString, pos, size, style, wxDefaultValidator, name))
00140     {
00141         wxSliderComboPopup* sliderpopup = new wxSliderComboPopup();
00142         m_slider = sliderpopup;
00143         SetPopupControl(sliderpopup);
00144         m_slider->SetValue(value);
00145         return true;
00146     }
00147     return false;
00148 }
00149 
00150 wxSliderCombo::~wxSliderCombo()
00151 {
00152 }
00153 
00154 wxString wxSliderCombo::GetValueSuffix() const
00155 {
00156     return m_suffix;
00157 }
00158 
00159 void wxSliderCombo::SetValueSuffix(wxString& suffix)
00160 {
00161     m_suffix = suffix;
00162 }
00163 
00164 bool wxSliderCombo::GetAutomaticUpdates() const
00165 {
00166     return m_automatic_updates;
00167 }
00168 
00169 void wxSliderCombo::SetAutomaticUpdates(bool automatic_updates)
00170 {
00171     m_automatic_updates = automatic_updates;
00172 }
00173 
00174 int wxSliderCombo::GetSliderValue() const
00175 {
00176     return m_slider->GetValue();
00177 }
00178 
00179 void wxSliderCombo::SetSliderValue(int value)
00180 {
00181     m_slider->SetValue(value);
00182 }
00183 
00184 void wxSliderCombo::SetRange(int minValue, int maxValue)
00185 {
00186     m_slider->SetRange(minValue, maxValue);
00187     // FIXME: Perhaps need to sync with text control
00188 }
00189 
00190 int wxSliderCombo::GetSliderMin() const
00191 {
00192     return m_slider->GetMin();
00193 }
00194 
00195 int wxSliderCombo::GetSliderMax() const
00196 {
00197     return m_slider->GetMax();
00198 }
00199 
00200 void wxSliderCombo::SetSliderMin( int minValue )
00201 {
00202     m_slider->SetMin(minValue);
00203 }
00204 
00205 void wxSliderCombo::SetSliderMax( int maxValue )
00206 {
00207     m_slider->SetMax(maxValue);
00208 }
00209 
00210 void wxSliderCombo::SetLineSize(int lineSize)
00211 {
00212     m_slider->SetLineSize(lineSize);
00213 }
00214 
00215 void wxSliderCombo::SetPageSize(int pageSize)
00216 {
00217     m_slider->SetPageSize(pageSize);
00218 }
00219 
00220 int wxSliderCombo::GetLineSize() const
00221 {
00222     return m_slider->GetLineSize();
00223 }
00224 
00225 int wxSliderCombo::GetPageSize() const
00226 {
00227     return m_slider->GetPageSize();
00228 }
00229 
00230 void wxSliderCombo::SetThumbLength(int lenPixels)
00231 {
00232     m_slider->SetThumbLength(lenPixels);
00233 }
00234 
00235 int wxSliderCombo::GetThumbLength() const
00236 {
00237     return m_slider->GetThumbLength();
00238 }
00239 
00240 void wxSliderCombo::SetTickFreq(int n, int pos)
00241 {
00242     m_slider->SetTickFreq(n, pos);
00243 }
00244 
00245 int wxSliderCombo::GetTickFreq() const
00246 {
00247     return m_slider->GetTickFreq();
00248 }
00249 
00250 void wxSliderCombo::ClearTicks()
00251 {
00252     m_slider->ClearTicks();
00253 }
00254 
00255 void wxSliderCombo::SetTick(int tickPos)
00256 {
00257     m_slider->SetTick(tickPos);
00258 }
00259 
00260 void wxSliderCombo::ClearSel()
00261 {
00262     m_slider->ClearSel();
00263 }
00264 
00265 int wxSliderCombo::GetSelEnd() const
00266 {
00267     return m_slider->GetSelEnd();
00268 }
00269 
00270 int wxSliderCombo::GetSelStart() const
00271 {
00272     return m_slider->GetSelStart();
00273 }
00274 
00275 void wxSliderCombo::SetSelection(int min, int max)
00276 {
00277     m_slider->SetSelection(min,max);
00278 }

Generated on Sat Nov 10 03:49:02 2007 for Camelot by  doxygen 1.4.4