]>
git.saurik.com Git - wxWidgets.git/blob - src/os2/spinctrl.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: msw/spinctrl.cpp
3 // Purpose: wxSpinCtrl class implementation for Win32
4 // Author: David Webster
8 // Copyright: (c) David Webster
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 // ============================================================================
14 // ============================================================================
17 // ----------------------------------------------------------------------------
19 // ----------------------------------------------------------------------------
21 // for compilers that support precompilation, includes "wx.h".
22 #include "wx/wxprec.h"
29 #include "wx/spinctrl.h"
30 #include "wx/os2/private.h"
32 // ----------------------------------------------------------------------------
34 // ----------------------------------------------------------------------------
36 #if !USE_SHARED_LIBRARY
37 IMPLEMENT_DYNAMIC_CLASS(wxSpinCtrl
, wxControl
)
40 // ----------------------------------------------------------------------------
42 // ----------------------------------------------------------------------------
44 // the margin between the up-down control and its buddy
45 static const int MARGIN_BETWEEN
= 5;
47 // ============================================================================
49 // ============================================================================
51 // ----------------------------------------------------------------------------
53 // ----------------------------------------------------------------------------
55 bool wxSpinCtrl::Create(wxWindow
*parent
,
57 const wxString
& value
,
61 int min
, int max
, int initial
,
66 // before using DoGetBestSize(), have to set style to let the base class
67 // know whether this is a horizontal or vertical control (we're always
69 SetWindowStyle(style | wxSP_VERTICAL);
71 // calculate the sizes: the size given is the toal size for both controls
72 // and we need to fit them both in the given width (height is the same)
73 wxSize sizeText(size), sizeBtn(size);
74 sizeBtn.x = wxSpinButton::DoGetBestSize().x;
75 sizeText.x -= sizeBtn.x + MARGIN_BETWEEN;
76 if ( sizeText.x <= 0 )
78 wxLogDebug(_T("not enough space for wxSpinCtrl!"));
82 posBtn.x += sizeText.x + MARGIN_BETWEEN;
84 // create the spin button
85 if ( !wxSpinButton::Create(parent, id, posBtn, sizeBtn, style, name) )
93 // create the text window
94 if ( sizeText.y <= 0 )
96 // make it the same height as the button then
98 wxSpinButton::DoGetSize(&x, &y);
103 m_hwndBuddy = (WXHWND)::CreateWindowEx
105 WS_EX_CLIENTEDGE, // sunken border
106 _T("EDIT"), // window class
107 NULL, // no window title
108 WS_CHILD | WS_VISIBLE | WS_BORDER, // style
109 pos.x, pos.y, // position
110 sizeText.x, sizeText.y, // size
111 GetHwndOf(parent), // parent
112 (HMENU)-1, // control id
113 wxGetInstance(), // app instance
114 NULL // unused client data
119 wxLogLastError("CreateWindow(buddy text window)");
124 // should have the same font as the other controls
125 WXHANDLE hFont = GetParent()->GetFont().GetResourceHandle();
126 ::SendMessage((HWND)m_hwndBuddy, WM_SETFONT, (WPARAM)hFont, TRUE);
128 // associate the text window with the spin button
129 (void)SendMessage(GetHwnd(), UDM_SETBUDDY, (WPARAM)m_hwndBuddy, 0);
134 // ----------------------------------------------------------------------------
136 // ----------------------------------------------------------------------------
138 void wxSpinCtrl::DoMoveWindow(int x
, int y
, int width
, int height
)
140 int widthBtn
= DoGetBestSize().x
;
141 int widthText
= width
- widthBtn
- MARGIN_BETWEEN
;
142 if ( widthText
<= 0 )
144 wxLogDebug(_T("not enough space for wxSpinCtrl!"));
148 if ( !::MoveWindow((HWND)m_hwndBuddy, x, y, widthText, height, TRUE) )
150 wxLogLastError("MoveWindow(buddy)");
153 x += widthText + MARGIN_BETWEEN;
154 if ( !::MoveWindow(GetHwnd(), x, y, widthBtn, height, TRUE) )
156 wxLogLastError("MoveWindow");