X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/2d120f8391920145647ec10e84629bc21fa9f1bb..51ec29ea5d1d1093bafbae27a8483211a90d9659:/src/motif/slider.cpp diff --git a/src/motif/slider.cpp b/src/motif/slider.cpp index 3e47c9a424..70c5c66a24 100644 --- a/src/motif/slider.cpp +++ b/src/motif/slider.cpp @@ -1,37 +1,43 @@ ///////////////////////////////////////////////////////////////////////////// -// Name: slider.cpp +// Name: src/motif/slider.cpp // Purpose: wxSlider // Author: Julian Smart // Modified by: // Created: 17/09/98 // RCS-ID: $Id$ // Copyright: (c) Julian Smart -// Licence: wxWindows licence +// Licence: wxWindows licence ///////////////////////////////////////////////////////////////////////////// -#ifdef __GNUG__ -#pragma implementation "slider.h" -#endif +// For compilers that support precompilation, includes "wx.h". +#include "wx/wxprec.h" + +#if wxUSE_SLIDER #include "wx/slider.h" -#include "wx/utils.h" +#ifndef WX_PRECOMP + #include "wx/utils.h" +#endif + +#ifdef __VMS__ +#pragma message disable nosimpint +#endif #include #include #include #include #include +#ifdef __VMS__ +#pragma message enable nosimpint +#endif -#include - -void wxSliderCallback (Widget widget, XtPointer clientData, XmScaleCallbackStruct * cbs); +#include "wx/motif/private.h" -#if !USE_SHARED_LIBRARY -IMPLEMENT_DYNAMIC_CLASS(wxSlider, wxControl) +static void wxSliderCallback (Widget widget, XtPointer clientData, XmScaleCallbackStruct * cbs); BEGIN_EVENT_TABLE(wxSlider, wxControl) END_EVENT_TABLE() -#endif @@ -42,7 +48,6 @@ wxSlider::wxSlider() m_lineSize = 1; m_rangeMax = 0; m_rangeMin = 0; - m_tickFreq = 0; } bool wxSlider::Create(wxWindow *parent, wxWindowID id, @@ -52,30 +57,24 @@ bool wxSlider::Create(wxWindow *parent, wxWindowID id, const wxValidator& validator, const wxString& name) { - SetName(name); - SetValidator(validator); - m_backgroundColour = parent->GetBackgroundColour(); - m_foregroundColour = parent->GetForegroundColour(); - - if (parent) parent->AddChild(this); - + if ( !((style & wxSL_HORIZONTAL) || (style & wxSL_VERTICAL)) ) + style |= wxSL_HORIZONTAL; + + if( !CreateControl( parent, id, pos, size, style, validator, name ) ) + return false; + PreCreation(); + m_lineSize = 1; m_windowStyle = style; - m_tickFreq = 0; - - if ( id == -1 ) - m_windowId = (int)NewControlId(); - else - m_windowId = id; - + m_rangeMax = maxValue; m_rangeMin = minValue; - + // Not used in Motif, I think m_pageSize = (int)((maxValue-minValue)/10); - + Widget parentWidget = (Widget) parent->GetClientWidget(); - + Widget sliderWidget = XtVaCreateManagedWidget ("sliderWidget", xmScaleWidgetClass, parentWidget, XmNorientation, @@ -87,27 +86,16 @@ bool wxSlider::Create(wxWindow *parent, wxWindowID id, XmNvalue, value, XmNshowValue, True, NULL); - + m_mainWidget = (WXWidget) sliderWidget; - - if(style & wxSL_NOTIFY_DRAG) - XtAddCallback (sliderWidget, XmNdragCallback, - (XtCallbackProc) wxSliderCallback, (XtPointer) this); - else - XtAddCallback (sliderWidget, XmNvalueChangedCallback, - (XtCallbackProc) wxSliderCallback, (XtPointer) this); - + + XtAddCallback (sliderWidget, XmNvalueChangedCallback, (XtCallbackProc) wxSliderCallback, (XtPointer) this); XtAddCallback (sliderWidget, XmNdragCallback, (XtCallbackProc) wxSliderCallback, (XtPointer) this); - - m_windowFont = parent->GetFont(); - - ChangeFont(FALSE); - SetCanAddEventHandler(TRUE); + + PostCreation(); AttachWidget (parent, m_mainWidget, (WXWidget) NULL, pos.x, pos.y, size.x, size.y); - - ChangeBackgroundColour(); - - return TRUE; + + return true; } wxSlider::~wxSlider() @@ -126,38 +114,33 @@ void wxSlider::SetValue(int value) XtVaSetValues ((Widget) m_mainWidget, XmNvalue, value, NULL); } -void wxSlider::GetSize(int *width, int *height) const -{ - wxControl::GetSize(width, height); -} - -void wxSlider::SetSize(int x, int y, int width, int height, int sizeFlags) +void wxSlider::DoSetSize(int x, int y, int width, int height, int sizeFlags) { Widget widget = (Widget) m_mainWidget; - + bool managed = XtIsManaged(widget); - + if (managed) XtUnmanageChild (widget); - + if (((m_windowStyle & wxHORIZONTAL) == wxHORIZONTAL) && (width > -1)) { XtVaSetValues (widget, XmNscaleWidth, wxMax (width, 10), NULL); } - + if (((m_windowStyle & wxVERTICAL) == wxVERTICAL) && (height > -1)) { XtVaSetValues (widget, XmNscaleHeight, wxMax (height, 10), NULL); } - + int xx = x; int yy = y; AdjustForParentClientOrigin(xx, yy, sizeFlags); - + if (x > -1 || (sizeFlags & wxSIZE_ALLOW_MINUS_ONE)) XtVaSetValues (widget, XmNx, xx, NULL); if (y > -1 || (sizeFlags & wxSIZE_ALLOW_MINUS_ONE)) XtVaSetValues (widget, XmNy, yy, NULL); - + if (managed) XtManageChild (widget); } @@ -166,17 +149,11 @@ void wxSlider::SetRange(int minValue, int maxValue) { m_rangeMin = minValue; m_rangeMax = maxValue; - + XtVaSetValues ((Widget) m_mainWidget, XmNminimum, minValue, XmNmaximum, maxValue, NULL); } // For trackbars only -void wxSlider::SetTickFreq(int n, int pos) -{ - // Not implemented in Motif - m_tickFreq = n; -} - void wxSlider::SetPageSize(int pageSize) { // Not implemented in Motif @@ -188,16 +165,6 @@ int wxSlider::GetPageSize() const return m_pageSize; } -void wxSlider::ClearSel() -{ - // Not implemented in Motif -} - -void wxSlider::ClearTicks() -{ - // Not implemented in Motif -} - void wxSlider::SetLineSize(int lineSize) { // Not implemented in Motif @@ -210,23 +177,6 @@ int wxSlider::GetLineSize() const return m_lineSize; } -int wxSlider::GetSelEnd() const -{ - // Not implemented in Motif - return 0; -} - -int wxSlider::GetSelStart() const -{ - // Not implemented in Motif - return 0; -} - -void wxSlider::SetSelection(int WXUNUSED(minPos), int WXUNUSED(maxPos)) -{ - // Not implemented in Motif -} - void wxSlider::SetThumbLength(int WXUNUSED(len)) { // Not implemented in Motif (?) @@ -238,56 +188,44 @@ int wxSlider::GetThumbLength() const return 0; } -void wxSlider::SetTick(int WXUNUSED(tickPos)) -{ - // Not implemented in Motif -} - void wxSlider::Command (wxCommandEvent & event) { SetValue (event.GetInt()); ProcessCommand (event); } -void wxSlider::ChangeFont(bool keepOriginalSize) -{ - wxWindow::ChangeFont(keepOriginalSize); -} - -void wxSlider::ChangeBackgroundColour() -{ - wxWindow::ChangeBackgroundColour(); -} - -void wxSlider::ChangeForegroundColour() -{ - wxWindow::ChangeForegroundColour(); -} - -void wxSliderCallback (Widget widget, XtPointer clientData, XmScaleCallbackStruct * cbs) +void wxSliderCallback (Widget widget, XtPointer clientData, + XmScaleCallbackStruct * cbs) { wxSlider *slider = (wxSlider *) clientData; + wxEventType scrollEvent; + switch (cbs->reason) { case XmCR_VALUE_CHANGED: + scrollEvent = wxEVT_SCROLL_THUMBRELEASE; + break; + case XmCR_DRAG: + scrollEvent = wxEVT_SCROLL_THUMBTRACK; + break; + default: - { - // TODO: the XmCR_VALUE_CHANGED case should be handled - // differently (it's not sent continually as the slider moves). - // In which case we need a similar behaviour for other platforms. - - wxScrollEvent event(wxEVT_SCROLL_THUMBTRACK, slider->GetId()); - XtVaGetValues (widget, XmNvalue, &event.m_commandInt, NULL); - event.SetEventObject(slider); - slider->ProcessCommand(event); - - // Also send a wxCommandEvent for compatibility. - wxCommandEvent event2(wxEVT_COMMAND_SLIDER_UPDATED, slider->GetId()); - event2.SetEventObject(slider); - slider->ProcessCommand(event2); - break; - } + return; } + + wxScrollEvent event(scrollEvent, slider->GetId()); + int commandInt = event.GetInt(); + XtVaGetValues (widget, XmNvalue, &commandInt, NULL); + event.SetInt(commandInt); + event.SetEventObject(slider); + slider->HandleWindowEvent(event); + + // Also send a wxCommandEvent for compatibility. + wxCommandEvent event2(wxEVT_COMMAND_SLIDER_UPDATED, slider->GetId()); + event2.SetEventObject(slider); + event2.SetInt( event.GetInt() ); + slider->HandleWindowEvent(event2); } +#endif // wxUSE_SLIDER