]>
Commit | Line | Data |
---|---|---|
409c9842 DW |
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 | ||
409c9842 | 36 | IMPLEMENT_DYNAMIC_CLASS(wxSpinCtrl, wxControl) |
409c9842 DW |
37 | |
38 | // ---------------------------------------------------------------------------- | |
39 | // constants | |
40 | // ---------------------------------------------------------------------------- | |
41 | ||
42 | // the margin between the up-down control and its buddy | |
43 | static const int MARGIN_BETWEEN = 5; | |
44 | ||
45 | // ============================================================================ | |
46 | // implementation | |
47 | // ============================================================================ | |
48 | ||
49 | // ---------------------------------------------------------------------------- | |
50 | // construction | |
51 | // ---------------------------------------------------------------------------- | |
52 | ||
53 | bool wxSpinCtrl::Create(wxWindow *parent, | |
54 | wxWindowID id, | |
3e7fb41b | 55 | const wxString& value, |
409c9842 DW |
56 | const wxPoint& pos, |
57 | const wxSize& size, | |
58 | long style, | |
59 | int min, int max, int initial, | |
60 | const wxString& name) | |
61 | { | |
62 | // TODO: | |
63 | /* | |
64 | // before using DoGetBestSize(), have to set style to let the base class | |
65 | // know whether this is a horizontal or vertical control (we're always | |
66 | // vertical) | |
67 | SetWindowStyle(style | wxSP_VERTICAL); | |
68 | ||
69 | // calculate the sizes: the size given is the toal size for both controls | |
70 | // and we need to fit them both in the given width (height is the same) | |
71 | wxSize sizeText(size), sizeBtn(size); | |
72 | sizeBtn.x = wxSpinButton::DoGetBestSize().x; | |
73 | sizeText.x -= sizeBtn.x + MARGIN_BETWEEN; | |
74 | if ( sizeText.x <= 0 ) | |
75 | { | |
76 | wxLogDebug(_T("not enough space for wxSpinCtrl!")); | |
77 | } | |
78 | ||
79 | wxPoint posBtn(pos); | |
80 | posBtn.x += sizeText.x + MARGIN_BETWEEN; | |
81 | ||
82 | // create the spin button | |
83 | if ( !wxSpinButton::Create(parent, id, posBtn, sizeBtn, style, name) ) | |
84 | { | |
85 | return FALSE; | |
86 | } | |
87 | ||
88 | SetRange(min, max); | |
89 | SetValue(initial); | |
90 | ||
91 | // create the text window | |
92 | if ( sizeText.y <= 0 ) | |
93 | { | |
94 | // make it the same height as the button then | |
95 | int x, y; | |
96 | wxSpinButton::DoGetSize(&x, &y); | |
97 | ||
98 | sizeText.y = y; | |
99 | } | |
100 | ||
101 | m_hwndBuddy = (WXHWND)::CreateWindowEx | |
102 | ( | |
103 | WS_EX_CLIENTEDGE, // sunken border | |
104 | _T("EDIT"), // window class | |
105 | NULL, // no window title | |
106 | WS_CHILD | WS_VISIBLE | WS_BORDER, // style | |
107 | pos.x, pos.y, // position | |
108 | sizeText.x, sizeText.y, // size | |
109 | GetHwndOf(parent), // parent | |
110 | (HMENU)-1, // control id | |
111 | wxGetInstance(), // app instance | |
112 | NULL // unused client data | |
113 | ); | |
114 | ||
115 | if ( !m_hwndBuddy ) | |
116 | { | |
117 | wxLogLastError("CreateWindow(buddy text window)"); | |
118 | ||
119 | return FALSE; | |
120 | } | |
121 | ||
122 | // should have the same font as the other controls | |
123 | WXHANDLE hFont = GetParent()->GetFont().GetResourceHandle(); | |
124 | ::SendMessage((HWND)m_hwndBuddy, WM_SETFONT, (WPARAM)hFont, TRUE); | |
125 | ||
126 | // associate the text window with the spin button | |
127 | (void)SendMessage(GetHwnd(), UDM_SETBUDDY, (WPARAM)m_hwndBuddy, 0); | |
128 | */ | |
129 | return FALSE; | |
130 | } | |
131 | ||
132 | // ---------------------------------------------------------------------------- | |
133 | // size calculations | |
134 | // ---------------------------------------------------------------------------- | |
135 | ||
136 | void wxSpinCtrl::DoMoveWindow(int x, int y, int width, int height) | |
137 | { | |
138 | int widthBtn = DoGetBestSize().x; | |
139 | int widthText = width - widthBtn - MARGIN_BETWEEN; | |
140 | if ( widthText <= 0 ) | |
141 | { | |
142 | wxLogDebug(_T("not enough space for wxSpinCtrl!")); | |
143 | } | |
144 | // TODO: | |
145 | /* | |
146 | if ( !::MoveWindow((HWND)m_hwndBuddy, x, y, widthText, height, TRUE) ) | |
147 | { | |
148 | wxLogLastError("MoveWindow(buddy)"); | |
149 | } | |
150 | ||
151 | x += widthText + MARGIN_BETWEEN; | |
152 | if ( !::MoveWindow(GetHwnd(), x, y, widthBtn, height, TRUE) ) | |
153 | { | |
154 | wxLogLastError("MoveWindow"); | |
155 | } | |
156 | */ | |
157 | } |