]> git.saurik.com Git - wxWidgets.git/blame - src/os2/spinbutt.cpp
removed GTKConvertMnemonics() which is not used in GTK1 (which doesn't support mnemonics)
[wxWidgets.git] / src / os2 / spinbutt.cpp
CommitLineData
0e320a79
DW
1/////////////////////////////////////////////////////////////////////////////
2// Name: spinbutt.cpp
3// Purpose: wxSpinButton
409c9842 4// Author: David Webster
0e320a79 5// Modified by:
409c9842 6// Created: 10/15/99
0e320a79 7// RCS-ID: $Id$
409c9842 8// Copyright: (c) David Webster
65571936 9// Licence: wxWindows licence
0e320a79
DW
10/////////////////////////////////////////////////////////////////////////////
11
409c9842
DW
12// For compilers that support precompilation, includes "wx.h".
13#include "wx/wxprec.h"
14
15
16#ifndef WX_PRECOMP
17 #include "wx/wx.h"
0e320a79 18#endif
7e99520b 19#if wxUSE_SPINBTN
0e320a79 20
409c9842
DW
21// Can't resolve reference to CreateUpDownControl in
22// TWIN32, but could probably use normal CreateWindow instead.
23
24
0e320a79 25#include "wx/spinbutt.h"
3bfbab1e 26
3c299c3a
DW
27extern void wxAssociateWinWithHandle( HWND hWnd
28 ,wxWindowOS2* pWin
29 );
3c299c3a 30
3bfbab1e
SN
31IMPLEMENT_DYNAMIC_CLASS(wxSpinEvent, wxNotifyEvent)
32
409c9842
DW
33#include "wx/os2/private.h"
34
35// ============================================================================
36// implementation
37// ============================================================================
38
39// ----------------------------------------------------------------------------
40// wxWin macros
41// ----------------------------------------------------------------------------
0e320a79 42
0e320a79 43IMPLEMENT_DYNAMIC_CLASS(wxSpinButton, wxControl)
0e320a79 44
409c9842 45bool wxSpinButton::Create(
3c299c3a
DW
46 wxWindow* pParent
47, wxWindowID vId
48, const wxPoint& rPos
49, const wxSize& rSize
50, long lStyle
51, const wxString& rsName
409c9842 52)
0e320a79 53{
3c299c3a
DW
54 int nX = rPos.x;
55 int nY = rPos.y;
56 int nWidth = rSize.x;
57 int nHeight = rSize.y;
d8a3f66c 58 SWP vSwp;
3c299c3a
DW
59
60 m_min = 0;
61 m_max = 100;
62 if (vId == -1)
63 m_windowId = NewControlId();
64 else
65 m_windowId = vId;
66 m_backgroundColour = pParent->GetBackgroundColour();
67 m_foregroundColour = pParent->GetForegroundColour();
68 SetName(rsName);
69 SetParent(pParent);
70 m_windowStyle = lStyle;
71
72 //
73 // Get the right size for the control
74 //
75 if (nWidth <= 0 || nHeight <= 0 )
76 {
77 wxSize vSize = DoGetBestSize();
0e320a79 78
3c299c3a
DW
79 if (nWidth <= 0 )
80 nWidth = vSize.x;
81 if (nHeight <= 0 )
82 nHeight = vSize.y;
83 }
84 if (nX < 0 )
85 nX = 0;
86 if (nY < 0 )
87 nY = 0;
88
89 long lSstyle = 0L;
90
91 lSstyle = WS_VISIBLE |
92 WS_TABSTOP |
93 SPBS_MASTER | // We use only single field spin buttons
94 SPBS_NUMERICONLY; // We default to numeric data
95
96 if (m_windowStyle & wxCLIP_SIBLINGS )
97 lSstyle |= WS_CLIPSIBLINGS;
98
3c299c3a
DW
99 m_hWnd = (WXHWND)::WinCreateWindow( GetWinHwnd(pParent)
100 ,WC_SPINBUTTON
101 ,(PSZ)NULL
102 ,lSstyle
103 ,0L, 0L, 0L, 0L
104 ,GetWinHwnd(pParent)
105 ,HWND_TOP
106 ,(HMENU)vId
8787320b 107 ,NULL
3c299c3a
DW
108 ,NULL
109 );
110 if (m_hWnd == 0)
111 {
112 return FALSE;
113 }
8787320b 114 SetRange(m_min, m_max);
3c299c3a
DW
115 if(pParent)
116 pParent->AddChild((wxSpinButton *)this);
117
d8a3f66c
DW
118 ::WinQueryWindowPos(m_hWnd, &vSwp);
119 SetXComp(vSwp.x);
22c68581 120 SetYComp(vSwp.y-5); // compensate for the associated TextControl border
b3260bce
DW
121 wxFont* pTextFont = new wxFont( 10
122 ,wxMODERN
123 ,wxNORMAL
124 ,wxNORMAL
125 );
126 SetFont(*pTextFont);
3c299c3a
DW
127 //
128 // For OS/2 we want to hide the text portion so we can substitute an
22c68581
SN
129 // independent text ctrl in its place.
130 // Therefore we must override any user given width with our best guess.
3c299c3a 131 //
22c68581
SN
132 SetSize( nX - GetXComp()
133 ,nY - GetYComp()
134 ,nWidth
3c299c3a
DW
135 ,nHeight
136 );
137 wxAssociateWinWithHandle( m_hWnd
138 ,(wxWindowOS2*)this
139 );
8787320b
SN
140#if 0
141 // FIXME:
142 // Apparently, this does not work, as it crashes in setvalue/setrange calls
143 // What's it supposed to do anyway?
3c299c3a
DW
144 ::WinSetWindowULong(GetHwnd(), QWL_USER, (LONG)this);
145 fnWndProcSpinCtrl = (WXFARPROC)::WinSubclassWindow(m_hWnd, (PFNWP)wxSpinCtrlWndProc);
8787320b 146#endif
b3260bce 147 delete pTextFont;
3c299c3a
DW
148 return TRUE;
149} // end of wxSpinButton::Create
0e320a79
DW
150
151wxSpinButton::~wxSpinButton()
152{
3c299c3a 153} // end of wxSpinButton::~wxSpinButton
0e320a79 154
409c9842
DW
155// ----------------------------------------------------------------------------
156// size calculation
157// ----------------------------------------------------------------------------
158
e78c4d50 159wxSize wxSpinButton::DoGetBestSize() const
409c9842 160{
3c299c3a 161 //
8787320b 162 // OS/2 PM does not really have system metrics so we'll just set it to
22c68581 163 // 26x20 which is the size of the buttons and the borders.
3c299c3a
DW
164 // Also we have no horizontal spin buttons.
165 //
22c68581 166 wxSize best(26,20);
6670f564 167 return best;
3c299c3a 168} // end of wxSpinButton::DoGetBestSize
409c9842
DW
169
170// ----------------------------------------------------------------------------
0e320a79 171// Attributes
409c9842 172// ----------------------------------------------------------------------------
0e320a79
DW
173
174int wxSpinButton::GetValue() const
175{
3c299c3a
DW
176 long lVal = 0L;
177 char zVal[10];
178
179 ::WinSendMsg( GetHwnd()
180 ,SPBM_QUERYVALUE
181 ,MPFROMP(zVal)
182 ,MPFROM2SHORT( (USHORT)10
183 ,SPBQ_UPDATEIFVALID
184 )
185 );
186 lVal = atol(zVal);
187 return ((int)lVal);
188} // end of wxSpinButton::GetValue
189
6670f564
WS
190bool wxSpinButton::OS2OnScroll( int WXUNUSED(nOrientation),
191 WXWORD WXUNUSED(wParam),
192 WXWORD wPos,
193 WXHWND hControl )
0e320a79 194{
6670f564 195 wxCHECK_MSG(hControl, false, wxT("scrolling what?") )
0e320a79 196
6670f564
WS
197 wxSpinEvent vEvent( wxEVT_SCROLL_THUMBTRACK, m_windowId );
198 int nVal = (int)wPos; // cast is important for negative values!
409c9842 199
3c299c3a
DW
200 vEvent.SetPosition(nVal);
201 vEvent.SetEventObject(this);
202 return(GetEventHandler()->ProcessEvent(vEvent));
203} // end of wxSpinButton::OS2OnScroll
409c9842 204
6670f564
WS
205bool wxSpinButton::OS2Command( WXUINT WXUNUSED(uCmd),
206 WXWORD WXUNUSED(wId) )
409c9842 207{
6670f564 208 return false;
3c299c3a 209} // end of wxSpinButton::OS2Command
409c9842 210
3c299c3a
DW
211void wxSpinButton::SetRange(
212 int nMinVal
213, int nMaxVal
214)
0e320a79 215{
3c299c3a
DW
216 m_min = nMinVal;
217 m_max = nMaxVal;
218
219 ::WinSendMsg( GetHwnd()
220 ,SPBM_SETLIMITS
221 ,MPFROMLONG(nMaxVal)
222 ,MPFROMLONG(nMinVal)
223 );
224} // end of wxSpinButton::SetRange
225
226void wxSpinButton::SetValue(
227 int nValue
228)
229{
230 ::WinSendMsg(GetHwnd(), SPBM_SETCURRENTVALUE, MPFROMLONG(nValue), MPARAM(0));
231} // end of wxSpinButton::SetValue
0e320a79 232
7e99520b 233#endif //wxUSE_SPINBTN