]>
git.saurik.com Git - wxWidgets.git/blob - src/msw/spinctrl.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: msw/spinctrl.cpp
3 // Purpose: wxSpinCtrl class implementation for Win32
4 // Author: Vadim Zeitlin
8 // Copyright: (c) Vadim Zeitlin
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 // ============================================================================
14 // ============================================================================
17 #pragma implementation "spinctrlbase.h"
18 #pragma implementation "spinctrl.h"
21 // ----------------------------------------------------------------------------
23 // ----------------------------------------------------------------------------
25 // for compilers that support precompilation, includes "wx.h".
26 #include "wx/wxprec.h"
36 #if defined(__WIN95__)
38 #include "wx/spinctrl.h"
39 #include "wx/msw/private.h"
43 // ----------------------------------------------------------------------------
45 // ----------------------------------------------------------------------------
47 #if !USE_SHARED_LIBRARY
48 IMPLEMENT_DYNAMIC_CLASS(wxSpinCtrl
, wxControl
)
51 // ----------------------------------------------------------------------------
53 // ----------------------------------------------------------------------------
55 // the margin between the up-down control and its buddy
56 static const int MARGIN_BETWEEN
= 5;
58 // ============================================================================
60 // ============================================================================
62 // ----------------------------------------------------------------------------
64 // ----------------------------------------------------------------------------
66 bool wxSpinCtrl::Create(wxWindow
*parent
,
71 int min
, int max
, int initial
,
74 // before using DoGetBestSize(), have to set style to let the base class
75 // know whether this is a horizontal or vertical control (we're always
77 SetWindowStyle(style
| wxSP_VERTICAL
);
79 // calculate the sizes: the size given is the toal size for both controls
80 // and we need to fit them both in the given width (height is the same)
81 wxSize
sizeText(size
), sizeBtn(size
);
82 sizeBtn
.x
= wxSpinButton::DoGetBestSize().x
;
83 sizeText
.x
-= sizeBtn
.x
+ MARGIN_BETWEEN
;
84 if ( sizeText
.x
<= 0 )
86 wxLogDebug(_T("not enough space for wxSpinCtrl!"));
90 posBtn
.x
+= sizeText
.x
+ MARGIN_BETWEEN
;
92 // create the spin button
93 if ( !wxSpinButton::Create(parent
, id
, posBtn
, sizeBtn
, style
, name
) )
101 // create the text window
102 if ( sizeText
.y
<= 0 )
104 // make it the same height as the button then
106 wxSpinButton::DoGetSize(&x
, &y
);
111 m_hwndBuddy
= (WXHWND
)::CreateWindowEx
113 WS_EX_CLIENTEDGE
, // sunken border
114 _T("EDIT"), // window class
115 NULL
, // no window title
116 WS_CHILD
| WS_VISIBLE
| WS_BORDER
, // style
117 pos
.x
, pos
.y
, // position
118 sizeText
.x
, sizeText
.y
, // size
119 GetHwndOf(parent
), // parent
120 (HMENU
)-1, // control id
121 wxGetInstance(), // app instance
122 NULL
// unused client data
127 wxLogLastError("CreateWindow(buddy text window)");
132 // should have the same font as the other controls
133 WXHANDLE hFont
= GetParent()->GetFont().GetResourceHandle();
134 ::SendMessage((HWND
)m_hwndBuddy
, WM_SETFONT
, (WPARAM
)hFont
, TRUE
);
136 // associate the text window with the spin button
137 (void)SendMessage(GetHwnd(), UDM_SETBUDDY
, (WPARAM
)m_hwndBuddy
, 0);
142 // ----------------------------------------------------------------------------
144 // ----------------------------------------------------------------------------
146 void wxSpinCtrl::DoMoveWindow(int x
, int y
, int width
, int height
)
148 int widthBtn
= DoGetBestSize().x
;
149 int widthText
= width
- widthBtn
- MARGIN_BETWEEN
;
150 if ( widthText
<= 0 )
152 wxLogDebug(_T("not enough space for wxSpinCtrl!"));
155 if ( !::MoveWindow((HWND
)m_hwndBuddy
, x
, y
, widthText
, height
, TRUE
) )
157 wxLogLastError("MoveWindow(buddy)");
160 x
+= widthText
+ MARGIN_BETWEEN
;
161 if ( !::MoveWindow(GetHwnd(), x
, y
, widthBtn
, height
, TRUE
) )
163 wxLogLastError("MoveWindow");