]>
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"
41 #if (defined(__WIN95__) && !defined(__GNUWIN32__)) || defined(__TWIN32__) || defined(wxUSE_NORLANDER_HEADERS)
45 // ----------------------------------------------------------------------------
47 // ----------------------------------------------------------------------------
49 #if !USE_SHARED_LIBRARY
50 IMPLEMENT_DYNAMIC_CLASS(wxSpinCtrl
, wxControl
)
53 // ----------------------------------------------------------------------------
55 // ----------------------------------------------------------------------------
57 // the margin between the up-down control and its buddy
58 static const int MARGIN_BETWEEN
= 5;
60 // ============================================================================
62 // ============================================================================
64 // ----------------------------------------------------------------------------
66 // ----------------------------------------------------------------------------
68 bool wxSpinCtrl::Create(wxWindow
*parent
,
73 int min
, int max
, int initial
,
76 // before using DoGetBestSize(), have to set style to let the base class
77 // know whether this is a horizontal or vertical control (we're always
79 SetWindowStyle(style
| wxSP_VERTICAL
);
81 // calculate the sizes: the size given is the toal size for both controls
82 // and we need to fit them both in the given width (height is the same)
83 wxSize
sizeText(size
), sizeBtn(size
);
84 sizeBtn
.x
= wxSpinButton::DoGetBestSize().x
;
85 sizeText
.x
-= sizeBtn
.x
+ MARGIN_BETWEEN
;
86 if ( sizeText
.x
<= 0 )
88 wxLogDebug(_T("not enough space for wxSpinCtrl!"));
92 posBtn
.x
+= sizeText
.x
+ MARGIN_BETWEEN
;
94 // create the spin button
95 if ( !wxSpinButton::Create(parent
, id
, posBtn
, sizeBtn
, style
, name
) )
103 // create the text window
104 if ( sizeText
.y
<= 0 )
106 // make it the same height as the button then
108 wxSpinButton::DoGetSize(&x
, &y
);
113 m_hwndBuddy
= (WXHWND
)::CreateWindowEx
115 WS_EX_CLIENTEDGE
, // sunken border
116 _T("EDIT"), // window class
117 NULL
, // no window title
118 WS_CHILD
| WS_VISIBLE
| WS_BORDER
, // style
119 pos
.x
, pos
.y
, // position
120 sizeText
.x
, sizeText
.y
, // size
121 GetHwndOf(parent
), // parent
122 (HMENU
)-1, // control id
123 wxGetInstance(), // app instance
124 NULL
// unused client data
129 wxLogLastError("CreateWindow(buddy text window)");
134 // should have the same font as the other controls
135 WXHANDLE hFont
= GetParent()->GetFont().GetResourceHandle();
136 ::SendMessage((HWND
)m_hwndBuddy
, WM_SETFONT
, (WPARAM
)hFont
, TRUE
);
138 // associate the text window with the spin button
139 (void)SendMessage(GetHwnd(), UDM_SETBUDDY
, (WPARAM
)m_hwndBuddy
, 0);
144 // ----------------------------------------------------------------------------
146 // ----------------------------------------------------------------------------
148 void wxSpinCtrl::DoMoveWindow(int x
, int y
, int width
, int height
)
150 int widthBtn
= DoGetBestSize().x
;
151 int widthText
= width
- widthBtn
- MARGIN_BETWEEN
;
152 if ( widthText
<= 0 )
154 wxLogDebug(_T("not enough space for wxSpinCtrl!"));
157 if ( !::MoveWindow((HWND
)m_hwndBuddy
, x
, y
, widthText
, height
, TRUE
) )
159 wxLogLastError("MoveWindow(buddy)");
162 x
+= widthText
+ MARGIN_BETWEEN
;
163 if ( !::MoveWindow(GetHwnd(), x
, y
, widthBtn
, height
, TRUE
) )
165 wxLogLastError("MoveWindow");