1 ///////////////////////////////////////////////////////////////////////////// 
   2 // Name:        src/motif/scrolbar.cpp 
   3 // Purpose:     wxScrollBar 
   4 // Author:      Julian Smart 
   8 // Copyright:   (c) Julian Smart 
   9 // Licence:     wxWindows licence 
  10 ///////////////////////////////////////////////////////////////////////////// 
  12 // For compilers that support precompilation, includes "wx.h". 
  13 #include "wx/wxprec.h" 
  15 #include "wx/scrolbar.h" 
  18 #pragma message disable nosimpint 
  21 #include <Xm/ScrollBar.h> 
  23 #pragma message enable nosimpint 
  26 #include "wx/motif/private.h" 
  28 static void wxScrollBarCallback(Widget widget
, XtPointer clientData
, 
  29                         XmScaleCallbackStruct 
*cbs
); 
  31 IMPLEMENT_DYNAMIC_CLASS(wxScrollBar
, wxControl
) 
  34 bool wxScrollBar::Create(wxWindow 
*parent
, wxWindowID id
, 
  36            const wxSize
& size
, long style
, 
  37            const wxValidator
& validator
, 
  40     if( !CreateControl( parent
, id
, pos
, size
, style
, validator
, name 
) ) 
  45         ( style 
& wxHORIZONTAL 
) ? wxSize( 140, 16 ) : wxSize( 16, 140 ); 
  46     if( size
.x 
!= -1 ) newSize
.x 
= size
.x
; 
  47     if( size
.y 
!= -1 ) newSize
.y 
= size
.y
; 
  49     Widget parentWidget 
= (Widget
) parent
->GetClientWidget(); 
  52         DoCreateScrollBar( (WXWidget
)parentWidget
, 
  53                            (wxOrientation
)(style 
& (wxHORIZONTAL
|wxVERTICAL
)), 
  54                            (void (*)())wxScrollBarCallback 
); 
  57     AttachWidget (parent
, m_mainWidget
, (WXWidget
) NULL
, 
  58                   pos
.x
, pos
.y
, newSize
.x
, newSize
.y
); 
  63 wxScrollBar::~wxScrollBar() 
  67 void wxScrollBar::SetThumbPosition(int pos
) 
  69     XtVaSetValues ((Widget
) m_mainWidget
, 
  74 int wxScrollBar::GetThumbPosition() const 
  77     XtVaGetValues((Widget
) m_mainWidget
, 
  78                   XmNvalue
, &pos
, NULL
); 
  82 void wxScrollBar::SetScrollbar(int position
, int thumbSize
, int range
, int pageSize
, 
  83     bool WXUNUSED(refresh
)) 
  85     m_viewSize 
= pageSize
; 
  86     m_pageSize 
= thumbSize
; 
  94     XtVaSetValues((Widget
) m_mainWidget
, 
  98          XmNsliderSize
, thumbSize
, 
  99          XmNpageIncrement
, pageSize
, 
 103 void wxScrollBar::Command(wxCommandEvent
& event
) 
 105     SetThumbPosition(event
.GetInt()); 
 106     ProcessCommand(event
); 
 109 void wxScrollBar::ChangeFont(bool WXUNUSED(keepOriginalSize
)) 
 112     // Do anything for a scrollbar? A font will never be seen. 
 115 void wxScrollBar::ChangeBackgroundColour() 
 117     wxWindow::ChangeBackgroundColour(); 
 119     XtVaSetValues ((Widget
) GetMainWidget(), 
 120         XmNtroughColor
, m_backgroundColour
.AllocColour(XtDisplay((Widget
) GetMainWidget())), 
 124 static void wxScrollBarCallback(Widget widget
, XtPointer clientData
, 
 125                                 XmScaleCallbackStruct 
*cbs
) 
 127     wxScrollBar 
*scrollBar 
= (wxScrollBar
*)wxGetWindowFromTable(widget
); 
 128     wxCHECK_RET( scrollBar
, _T("invalid widget in scrollbar callback") ); 
 130     wxOrientation orientation 
= (wxOrientation
)wxPtrToUInt(clientData
); 
 131     wxEventType eventType 
= wxEVT_NULL
; 
 137             eventType 
= wxEVT_SCROLL_LINEDOWN
; 
 142             eventType 
= wxEVT_SCROLL_LINEUP
; 
 147             eventType 
= wxEVT_SCROLL_THUMBTRACK
; 
 150         case XmCR_VALUE_CHANGED
: 
 152             eventType 
= wxEVT_SCROLL_THUMBRELEASE
; 
 155         case XmCR_PAGE_INCREMENT
: 
 157             eventType 
= wxEVT_SCROLL_PAGEDOWN
; 
 160         case XmCR_PAGE_DECREMENT
: 
 162             eventType 
= wxEVT_SCROLL_PAGEUP
; 
 167             eventType 
= wxEVT_SCROLL_TOP
; 
 172             eventType 
= wxEVT_SCROLL_BOTTOM
; 
 177             // Should never get here 
 178             wxFAIL_MSG("Unknown scroll event."); 
 183     wxScrollEvent 
event(eventType
, scrollBar
->GetId(), 
 184                         cbs
->value
, orientation
); 
 185     event
.SetEventObject(scrollBar
); 
 186     scrollBar
->HandleWindowEvent(event
);