]> git.saurik.com Git - wxWidgets.git/blob - src/os2/spinctrl.cpp
OnEnter/OnDragOver API update (compiles, links, somewhat runs under wxGTK)
[wxWidgets.git] / src / os2 / spinctrl.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: msw/spinctrl.cpp
3 // Purpose: wxSpinCtrl class implementation for Win32
4 // Author: David Webster
5 // Modified by:
6 // Created: 10/15/99
7 // RCS-ID: $Id$
8 // Copyright: (c) David Webster
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
11
12 // ============================================================================
13 // declarations
14 // ============================================================================
15
16
17 // ----------------------------------------------------------------------------
18 // headers
19 // ----------------------------------------------------------------------------
20
21 // for compilers that support precompilation, includes "wx.h".
22 #include "wx/wxprec.h"
23
24
25 #ifndef WX_PRECOMP
26 #include "wx/wx.h"
27 #endif
28
29 #include "wx/spinctrl.h"
30 #include "wx/os2/private.h"
31
32 // ----------------------------------------------------------------------------
33 // macros
34 // ----------------------------------------------------------------------------
35
36 #if !USE_SHARED_LIBRARY
37 IMPLEMENT_DYNAMIC_CLASS(wxSpinCtrl, wxControl)
38 #endif
39
40 // ----------------------------------------------------------------------------
41 // constants
42 // ----------------------------------------------------------------------------
43
44 // the margin between the up-down control and its buddy
45 static const int MARGIN_BETWEEN = 5;
46
47 // ============================================================================
48 // implementation
49 // ============================================================================
50
51 // ----------------------------------------------------------------------------
52 // construction
53 // ----------------------------------------------------------------------------
54
55 bool wxSpinCtrl::Create(wxWindow *parent,
56 wxWindowID id,
57 const wxPoint& pos,
58 const wxSize& size,
59 long style,
60 int min, int max, int initial,
61 const wxString& name)
62 {
63 // TODO:
64 /*
65 // before using DoGetBestSize(), have to set style to let the base class
66 // know whether this is a horizontal or vertical control (we're always
67 // vertical)
68 SetWindowStyle(style | wxSP_VERTICAL);
69
70 // calculate the sizes: the size given is the toal size for both controls
71 // and we need to fit them both in the given width (height is the same)
72 wxSize sizeText(size), sizeBtn(size);
73 sizeBtn.x = wxSpinButton::DoGetBestSize().x;
74 sizeText.x -= sizeBtn.x + MARGIN_BETWEEN;
75 if ( sizeText.x <= 0 )
76 {
77 wxLogDebug(_T("not enough space for wxSpinCtrl!"));
78 }
79
80 wxPoint posBtn(pos);
81 posBtn.x += sizeText.x + MARGIN_BETWEEN;
82
83 // create the spin button
84 if ( !wxSpinButton::Create(parent, id, posBtn, sizeBtn, style, name) )
85 {
86 return FALSE;
87 }
88
89 SetRange(min, max);
90 SetValue(initial);
91
92 // create the text window
93 if ( sizeText.y <= 0 )
94 {
95 // make it the same height as the button then
96 int x, y;
97 wxSpinButton::DoGetSize(&x, &y);
98
99 sizeText.y = y;
100 }
101
102 m_hwndBuddy = (WXHWND)::CreateWindowEx
103 (
104 WS_EX_CLIENTEDGE, // sunken border
105 _T("EDIT"), // window class
106 NULL, // no window title
107 WS_CHILD | WS_VISIBLE | WS_BORDER, // style
108 pos.x, pos.y, // position
109 sizeText.x, sizeText.y, // size
110 GetHwndOf(parent), // parent
111 (HMENU)-1, // control id
112 wxGetInstance(), // app instance
113 NULL // unused client data
114 );
115
116 if ( !m_hwndBuddy )
117 {
118 wxLogLastError("CreateWindow(buddy text window)");
119
120 return FALSE;
121 }
122
123 // should have the same font as the other controls
124 WXHANDLE hFont = GetParent()->GetFont().GetResourceHandle();
125 ::SendMessage((HWND)m_hwndBuddy, WM_SETFONT, (WPARAM)hFont, TRUE);
126
127 // associate the text window with the spin button
128 (void)SendMessage(GetHwnd(), UDM_SETBUDDY, (WPARAM)m_hwndBuddy, 0);
129 */
130 return FALSE;
131 }
132
133 // ----------------------------------------------------------------------------
134 // size calculations
135 // ----------------------------------------------------------------------------
136
137 void wxSpinCtrl::DoMoveWindow(int x, int y, int width, int height)
138 {
139 int widthBtn = DoGetBestSize().x;
140 int widthText = width - widthBtn - MARGIN_BETWEEN;
141 if ( widthText <= 0 )
142 {
143 wxLogDebug(_T("not enough space for wxSpinCtrl!"));
144 }
145 // TODO:
146 /*
147 if ( !::MoveWindow((HWND)m_hwndBuddy, x, y, widthText, height, TRUE) )
148 {
149 wxLogLastError("MoveWindow(buddy)");
150 }
151
152 x += widthText + MARGIN_BETWEEN;
153 if ( !::MoveWindow(GetHwnd(), x, y, widthBtn, height, TRUE) )
154 {
155 wxLogLastError("MoveWindow");
156 }
157 */
158 }