]>
Commit | Line | Data |
---|---|---|
1 | ///////////////////////////////////////////////////////////////////////////// | |
2 | // Name: control.cpp | |
3 | // Purpose: wxControl class | |
4 | // Author: David Webster | |
5 | // Modified by: | |
6 | // Created: 09/17/99 | |
7 | // RCS-ID: $Id$ | |
8 | // Copyright: (c) Julian Smart and Markus Holzem | |
9 | // Licence: wxWindows licence | |
10 | ///////////////////////////////////////////////////////////////////////////// | |
11 | ||
12 | #ifdef __GNUG__ | |
13 | #pragma implementation "control.h" | |
14 | #endif | |
15 | ||
16 | // For compilers that support precompilation, includes "wx.h". | |
17 | #include "wx/wxprec.h" | |
18 | ||
19 | #ifndef WX_PRECOMP | |
20 | #include "wx/event.h" | |
21 | #include "wx/app.h" | |
22 | #include "wx/dcclient.h" | |
23 | #endif | |
24 | #include "wx/os2/private.h" | |
25 | #include "wx/control.h" | |
26 | ||
27 | IMPLEMENT_ABSTRACT_CLASS(wxControl, wxWindow) | |
28 | ||
29 | BEGIN_EVENT_TABLE(wxControl, wxWindow) | |
30 | EVT_ERASE_BACKGROUND(wxControl::OnEraseBackground) | |
31 | END_EVENT_TABLE() | |
32 | ||
33 | // Item members | |
34 | wxControl::wxControl() | |
35 | { | |
36 | m_backgroundColour = *wxWHITE; | |
37 | m_foregroundColour = *wxBLACK; | |
38 | ||
39 | #if WXWIN_COMPATIBILITY | |
40 | m_callback = 0; | |
41 | #endif // WXWIN_COMPATIBILITY | |
42 | } | |
43 | ||
44 | wxControl::~wxControl() | |
45 | { | |
46 | m_isBeingDeleted = TRUE; | |
47 | } | |
48 | ||
49 | bool wxControl::OS2CreateControl(const wxChar *classname, WXDWORD style) | |
50 | { | |
51 | m_hWnd = (WXHWND)::WinCreateWindow( GetHwndOf(GetParent()) | |
52 | ,classname | |
53 | ,NULL | |
54 | ,style | |
55 | ,0,0,0,0 | |
56 | ,NULLHANDLE | |
57 | ,HWND_TOP | |
58 | ,(HMENU)GetId() | |
59 | ,NULL | |
60 | ,NULL | |
61 | ); | |
62 | ||
63 | ||
64 | if ( !m_hWnd ) | |
65 | { | |
66 | #ifdef __WXDEBUG__ | |
67 | wxLogError(wxT("Failed to create a control of class '%s'"), classname); | |
68 | #endif // DEBUG | |
69 | ||
70 | return FALSE; | |
71 | } | |
72 | ||
73 | // subclass again for purposes of dialog editing mode | |
74 | SubclassWin(m_hWnd); | |
75 | ||
76 | // controls use the same font and colours as their parent dialog by default | |
77 | InheritAttributes(); | |
78 | ||
79 | return TRUE; | |
80 | } | |
81 | ||
82 | wxSize wxControl::DoGetBestSize() const | |
83 | { | |
84 | return wxSize(DEFAULT_ITEM_WIDTH, DEFAULT_ITEM_HEIGHT); | |
85 | } | |
86 | ||
87 | bool wxControl::ProcessCommand(wxCommandEvent& event) | |
88 | { | |
89 | #if WXWIN_COMPATIBILITY | |
90 | if ( m_callback ) | |
91 | { | |
92 | (void)(*m_callback)(this, event); | |
93 | ||
94 | return TRUE; | |
95 | } | |
96 | else | |
97 | #endif // WXWIN_COMPATIBILITY | |
98 | ||
99 | return GetEventHandler()->ProcessEvent(event); | |
100 | } | |
101 | ||
102 | bool wxControl::OS2OnNotify(int idCtrl, | |
103 | WXLPARAM lParam, | |
104 | WXLPARAM* result) | |
105 | { | |
106 | wxCommandEvent event(wxEVT_NULL, m_windowId); | |
107 | wxEventType eventType = wxEVT_NULL; | |
108 | /* TODO: | |
109 | NMHDR *hdr1 = (NMHDR*) lParam; | |
110 | switch ( hdr1->code ) | |
111 | { | |
112 | case NM_CLICK: | |
113 | eventType = wxEVT_COMMAND_LEFT_CLICK; | |
114 | break; | |
115 | ||
116 | case NM_DBLCLK: | |
117 | eventType = wxEVT_COMMAND_LEFT_DCLICK; | |
118 | break; | |
119 | ||
120 | case NM_RCLICK: | |
121 | eventType = wxEVT_COMMAND_RIGHT_CLICK; | |
122 | break; | |
123 | ||
124 | case NM_RDBLCLK: | |
125 | eventType = wxEVT_COMMAND_RIGHT_DCLICK; | |
126 | break; | |
127 | ||
128 | case NM_SETFOCUS: | |
129 | eventType = wxEVT_COMMAND_SET_FOCUS; | |
130 | break; | |
131 | ||
132 | case NM_KILLFOCUS: | |
133 | eventType = wxEVT_COMMAND_KILL_FOCUS; | |
134 | break; | |
135 | ||
136 | case NM_RETURN: | |
137 | eventType = wxEVT_COMMAND_ENTER; | |
138 | break; | |
139 | ||
140 | default: | |
141 | return wxWindow::OS2OnNotify(idCtrl, lParam, result); | |
142 | } | |
143 | */ | |
144 | event.SetEventType(eventType); | |
145 | event.SetEventObject(this); | |
146 | ||
147 | return GetEventHandler()->ProcessEvent(event); | |
148 | } | |
149 | ||
150 | void wxControl::OnEraseBackground(wxEraseEvent& event) | |
151 | { | |
152 | // In general, you don't want to erase the background of a control, | |
153 | // or you'll get a flicker. | |
154 | // TODO: move this 'null' function into each control that | |
155 | // might flicker. | |
156 | ||
157 | RECT rect; | |
158 | /* | |
159 | * below is msw code. | |
160 | * TODO: convert to PM Code | |
161 | * ::GetClientRect((HWND) GetHWND(), &rect); | |
162 | * | |
163 | * HBRUSH hBrush = ::CreateSolidBrush(PALETTERGB(GetBackgroundColour().Red(), | |
164 | * GetBackgroundColour().Green(), | |
165 | * GetBackgroundColour().Blue())); | |
166 | * int mode = ::SetMapMode((HDC) event.GetDC()->GetHDC(), MM_TEXT); | |
167 | * | |
168 | * ::FillRect ((HDC) event.GetDC()->GetHDC(), &rect, hBrush); | |
169 | * ::DeleteObject(hBrush); | |
170 | * ::SetMapMode((HDC) event.GetDC()->GetHDC(), mode); | |
171 | */ | |
172 | } | |
173 | ||
174 | WXDWORD wxControl::GetExStyle(WXDWORD& style) const | |
175 | { | |
176 | bool want3D; | |
177 | WXDWORD exStyle = Determine3DEffects(WS_EX_CLIENTEDGE, &want3D) ; | |
178 | ||
179 | // Even with extended styles, need to combine with FS_BORDER | |
180 | // for them to look right. Check it out later, base window style does | |
181 | // not designate BORDERS. Down in Frame and And controls. | |
182 | ||
183 | if ( want3D || wxStyleHasBorder(m_windowStyle) ) | |
184 | style |= FS_BORDER; | |
185 | ||
186 | return exStyle; | |
187 | } | |
188 | ||
189 | // --------------------------------------------------------------------------- | |
190 | // global functions | |
191 | // --------------------------------------------------------------------------- | |
192 | ||
193 | // Call this repeatedly for several wnds to find the overall size | |
194 | // of the widget. | |
195 | // Call it initially with -1 for all values in rect. | |
196 | // Keep calling for other widgets, and rect will be modified | |
197 | // to calculate largest bounding rectangle. | |
198 | void wxFindMaxSize(WXHWND wnd, RECT *rect) | |
199 | { | |
200 | int left = rect->xLeft; | |
201 | int right = rect->xRight; | |
202 | int top = rect->yTop; | |
203 | int bottom = rect->yBottom; | |
204 | ||
205 | ::WinQueryWindowRect((HWND) wnd, rect); | |
206 | ||
207 | if (left < 0) | |
208 | return; | |
209 | ||
210 | if (left < rect->xLeft) | |
211 | rect->xLeft = left; | |
212 | ||
213 | if (right > rect->xRight) | |
214 | rect->xRight = right; | |
215 | ||
216 | if (top < rect->yTop) | |
217 | rect->yTop = top; | |
218 | ||
219 | if (bottom > rect->yBottom) | |
220 | rect->yBottom = bottom; | |
221 | } | |
222 |