]>
Commit | Line | Data |
---|---|---|
e9576ca5 SC |
1 | ///////////////////////////////////////////////////////////////////////////// |
2 | // Name: control.cpp | |
3 | // Purpose: wxControl class | |
4 | // Author: AUTHOR | |
5 | // Modified by: | |
6 | // Created: ??/??/98 | |
7 | // RCS-ID: $Id$ | |
8 | // Copyright: (c) AUTHOR | |
89ebf1c9 | 9 | // Licence: wxWindows licence |
e9576ca5 SC |
10 | ///////////////////////////////////////////////////////////////////////////// |
11 | ||
12 | #ifdef __GNUG__ | |
13 | #pragma implementation "control.h" | |
14 | #endif | |
15 | ||
d8c736e5 GD |
16 | #include "wx/defs.h" |
17 | ||
e9576ca5 | 18 | #include "wx/control.h" |
03e11df5 GD |
19 | #include "wx/panel.h" |
20 | #include "wx/app.h" | |
5fde6fcc | 21 | #include "wx/dc.h" |
456c94e1 | 22 | #include "wx/dcclient.h" |
519cb848 SC |
23 | #include "wx/notebook.h" |
24 | #include "wx/tabctrl.h" | |
2f1ae414 | 25 | #include "wx/radiobox.h" |
519cb848 | 26 | #include "wx/spinbutt.h" |
03e11df5 GD |
27 | #include "wx/scrolbar.h" |
28 | #include "wx/button.h" | |
29 | #include "wx/dialog.h" | |
30 | #include "wx/statbox.h" | |
31 | #include "wx/sizer.h" | |
32 | #include "wx/stattext.h" | |
e9576ca5 | 33 | |
2f1ae414 | 34 | #if !USE_SHARED_LIBRARY |
8208e181 | 35 | IMPLEMENT_ABSTRACT_CLASS(wxControl, wxWindow) |
e9576ca5 | 36 | |
2f1ae414 | 37 | BEGIN_EVENT_TABLE(wxControl, wxWindow) |
89ebf1c9 RR |
38 | EVT_MOUSE_EVENTS( wxControl::OnMouseEvent ) |
39 | EVT_CHAR( wxControl::OnKeyDown ) | |
40 | EVT_PAINT( wxControl::OnPaint ) | |
e9576ca5 | 41 | END_EVENT_TABLE() |
2f1ae414 | 42 | #endif |
e9576ca5 | 43 | |
d497dca4 | 44 | #include "wx/mac/uma.h" |
519cb848 | 45 | |
e9576ca5 | 46 | // Item members |
519cb848 SC |
47 | |
48 | ControlActionUPP wxMacLiveScrollbarActionUPP = NULL ; | |
49 | ||
2f1ae414 | 50 | pascal void wxMacLiveScrollbarActionProc( ControlHandle control , ControlPartCode partCode ) ; |
519cb848 SC |
51 | pascal void wxMacLiveScrollbarActionProc( ControlHandle control , ControlPartCode partCode ) |
52 | { | |
89ebf1c9 RR |
53 | if ( partCode != 0) |
54 | { | |
55 | wxControl* wx = (wxControl*) GetControlReference( control ) ; | |
56 | if ( wx ) | |
57 | { | |
58 | wx->MacHandleControlClick( control , partCode ) ; | |
59 | } | |
60 | } | |
519cb848 SC |
61 | } |
62 | ||
e9576ca5 SC |
63 | wxControl::wxControl() |
64 | { | |
89ebf1c9 RR |
65 | m_macControl = NULL ; |
66 | m_macHorizontalBorder = 0 ; // additional pixels around the real control | |
67 | m_macVerticalBorder = 0 ; | |
e9576ca5 SC |
68 | m_backgroundColour = *wxWHITE; |
69 | m_foregroundColour = *wxBLACK; | |
e7549107 SC |
70 | #if WXWIN_COMPATIBILITY |
71 | m_callback = 0; | |
72 | #endif // WXWIN_COMPATIBILITY | |
519cb848 | 73 | |
89ebf1c9 RR |
74 | if ( wxMacLiveScrollbarActionUPP == NULL ) |
75 | { | |
4114d0af | 76 | #if defined(UNIVERSAL_INTERFACES_VERSION) && (UNIVERSAL_INTERFACES_VERSION >= 0x0340) |
03e11df5 GD |
77 | wxMacLiveScrollbarActionUPP = NewControlActionUPP( wxMacLiveScrollbarActionProc ); |
78 | #else | |
89ebf1c9 | 79 | wxMacLiveScrollbarActionUPP = NewControlActionProc( wxMacLiveScrollbarActionProc ) ; |
03e11df5 | 80 | #endif |
89ebf1c9 | 81 | } |
e9576ca5 SC |
82 | } |
83 | ||
2f1ae414 SC |
84 | bool wxControl::Create(wxWindow *parent, wxWindowID id, |
85 | const wxPoint& pos, | |
86 | const wxSize& size, long style, | |
87 | const wxValidator& validator, | |
88 | const wxString& name) | |
89 | { | |
89ebf1c9 RR |
90 | m_macControl = NULL ; |
91 | m_macHorizontalBorder = 0 ; // additional pixels around the real control | |
92 | m_macVerticalBorder = 0 ; | |
2f1ae414 SC |
93 | bool rval = wxWindow::Create(parent, id, pos, size, style, name); |
94 | if (rval) { | |
95 | #if wxUSE_VALIDATORS | |
96 | SetValidator(validator); | |
97 | #endif | |
98 | } | |
99 | return rval; | |
100 | } | |
101 | ||
e9576ca5 SC |
102 | wxControl::~wxControl() |
103 | { | |
e7549107 | 104 | m_isBeingDeleted = TRUE; |
e9576ca5 SC |
105 | // If we delete an item, we should initialize the parent panel, |
106 | // because it could now be invalid. | |
9c641c05 SC |
107 | wxWindow *parent = GetParent() ; |
108 | if ( parent ) | |
e9576ca5 | 109 | { |
9c641c05 SC |
110 | if (parent->GetDefaultItem() == (wxButton*) this) |
111 | parent->SetDefaultItem(NULL); | |
e9576ca5 | 112 | } |
519cb848 SC |
113 | if ( m_macControl ) |
114 | { | |
89ebf1c9 RR |
115 | ::DisposeControl( m_macControl ) ; |
116 | m_macControl = NULL ; | |
519cb848 | 117 | } |
e9576ca5 SC |
118 | } |
119 | ||
e7549107 | 120 | void wxControl::SetLabel(const wxString& title) |
e9576ca5 | 121 | { |
89ebf1c9 RR |
122 | m_label = title ; |
123 | ||
124 | if ( m_macControl ) | |
125 | { | |
126 | Str255 maclabel ; | |
127 | wxString label ; | |
128 | ||
129 | if( wxApp::s_macDefaultEncodingIsPC ) | |
130 | label = wxMacMakeMacStringFromPC( title ) ; | |
131 | else | |
132 | label = title ; | |
133 | ||
03e11df5 | 134 | #if TARGET_CARBON |
89ebf1c9 | 135 | c2pstrcpy( (StringPtr) maclabel , label ) ; |
03e11df5 | 136 | #else |
89ebf1c9 RR |
137 | strcpy( (char *) maclabel , label ) ; |
138 | c2pstr( (char *) maclabel ) ; | |
03e11df5 | 139 | #endif |
89ebf1c9 RR |
140 | ::SetControlTitle( m_macControl , maclabel ) ; |
141 | } | |
142 | Refresh() ; | |
e9576ca5 SC |
143 | } |
144 | ||
37e2cb08 | 145 | wxSize wxControl::DoGetBestSize() const |
e9576ca5 | 146 | { |
89ebf1c9 RR |
147 | Rect bestsize = { 0 , 0 , 0 , 0 } ; |
148 | short baselineoffset ; | |
149 | int bestWidth, bestHeight ; | |
150 | ::GetBestControlRect( m_macControl , &bestsize , &baselineoffset ) ; | |
151 | ||
152 | if ( EmptyRect( &bestsize ) ) | |
153 | { | |
154 | baselineoffset = 0; | |
155 | bestsize.left = bestsize.top = 0 ; | |
156 | bestsize.right = 16 ; | |
157 | bestsize.bottom = 16 ; | |
158 | if ( IsKindOf( CLASSINFO( wxScrollBar ) ) ) | |
159 | { | |
160 | bestsize.bottom = 16 ; | |
161 | } | |
162 | else if ( IsKindOf( CLASSINFO( wxSpinButton ) ) ) | |
163 | { | |
164 | bestsize.bottom = 24 ; | |
165 | } | |
166 | } | |
167 | ||
168 | if ( IsKindOf( CLASSINFO( wxButton ) ) ) | |
169 | { | |
170 | bestWidth = m_label.Length() * 8 + 12 ; | |
171 | if ( bestWidth < 70 ) | |
172 | bestWidth = 70 ; | |
173 | } | |
174 | else if ( IsKindOf( CLASSINFO( wxStaticText ) ) ) | |
175 | { | |
176 | bestWidth = m_label.Length() * 8 ; | |
177 | } | |
178 | else | |
179 | bestWidth = bestsize.right - bestsize.left ; | |
180 | ||
181 | bestWidth += 2 * m_macHorizontalBorder ; | |
182 | ||
183 | bestHeight = bestsize.bottom - bestsize.top ; | |
184 | if ( bestHeight < 10 ) | |
185 | bestHeight = 13 ; | |
186 | ||
187 | bestHeight += 2 * m_macVerticalBorder; | |
188 | ||
189 | ||
9453cf2b | 190 | return wxSize(bestWidth, bestHeight); |
e9576ca5 SC |
191 | } |
192 | ||
e7549107 | 193 | bool wxControl::ProcessCommand (wxCommandEvent & event) |
e9576ca5 SC |
194 | { |
195 | // Tries: | |
196 | // 1) A callback function (to become obsolete) | |
197 | // 2) OnCommand, starting at this window and working up parent hierarchy | |
198 | // 3) OnCommand then calls ProcessEvent to search the event tables. | |
e7549107 SC |
199 | #if WXWIN_COMPATIBILITY |
200 | if ( m_callback ) | |
e9576ca5 | 201 | { |
e7549107 SC |
202 | (void)(*m_callback)(this, event); |
203 | ||
204 | return TRUE; | |
e9576ca5 SC |
205 | } |
206 | else | |
e7549107 | 207 | #endif // WXWIN_COMPATIBILITY |
e9576ca5 | 208 | { |
e7549107 | 209 | return GetEventHandler()->ProcessEvent(event); |
e9576ca5 SC |
210 | } |
211 | } | |
212 | ||
519cb848 SC |
213 | // ------------------------ |
214 | wxList *wxWinMacControlList = NULL; | |
215 | wxControl *wxFindControlFromMacControl(ControlHandle inControl ) | |
216 | { | |
217 | wxNode *node = wxWinMacControlList->Find((long)inControl); | |
218 | if (!node) | |
219 | return NULL; | |
220 | return (wxControl *)node->Data(); | |
221 | } | |
222 | ||
223 | void wxAssociateControlWithMacControl(ControlHandle inControl, wxControl *control) | |
224 | { | |
225 | // adding NULL WindowRef is (first) surely a result of an error and | |
226 | // (secondly) breaks menu command processing | |
227 | wxCHECK_RET( inControl != (ControlHandle) NULL, "attempt to add a NULL WindowRef to window list" ); | |
228 | ||
229 | if ( !wxWinMacControlList->Find((long)inControl) ) | |
230 | wxWinMacControlList->Append((long)inControl, control); | |
231 | } | |
232 | ||
233 | void wxRemoveMacControlAssociation(wxControl *control) | |
234 | { | |
235 | wxWinMacControlList->DeleteObject(control); | |
236 | } | |
237 | ||
238 | void wxControl::MacPreControlCreate( wxWindow *parent, wxWindowID id, wxString label , | |
89ebf1c9 RR |
239 | const wxPoint& pos, |
240 | const wxSize& size, long style, | |
241 | const wxValidator& validator, | |
242 | const wxString& name , Rect *outBounds , StringPtr maclabel ) | |
519cb848 | 243 | { |
89ebf1c9 | 244 | m_label = label ; |
519cb848 SC |
245 | SetName(name); |
246 | if ( &validator ) | |
89ebf1c9 | 247 | SetValidator(validator); |
519cb848 SC |
248 | |
249 | m_windowStyle = style; | |
9453cf2b | 250 | parent->AddChild(this); |
519cb848 SC |
251 | |
252 | m_backgroundColour = parent->GetBackgroundColour() ; | |
253 | m_foregroundColour = parent->GetForegroundColour() ; | |
254 | ||
255 | if (id == -1) | |
256 | m_windowId = NewControlId(); | |
257 | else | |
258 | m_windowId = id; | |
259 | ||
9453cf2b SC |
260 | // These sizes will be adjusted in MacPostControlCreate |
261 | ||
89ebf1c9 RR |
262 | m_width = size.x ; |
263 | m_height = size.y ; | |
264 | m_x = pos.x ; | |
265 | m_y = pos.y ; | |
266 | ||
267 | outBounds->top = -10; | |
268 | outBounds->left = -10; | |
269 | outBounds->bottom = 0; | |
270 | outBounds->right = 0; | |
271 | ||
272 | char c_text[255]; | |
273 | strcpy( c_text , label ) ; | |
274 | if( wxApp::s_macDefaultEncodingIsPC ) | |
275 | { | |
276 | wxMacConvertFromPCForControls( c_text ) ; | |
277 | } | |
519cb848 | 278 | |
03e11df5 | 279 | #if TARGET_CARBON |
89ebf1c9 | 280 | c2pstrcpy( (StringPtr) maclabel , c_text ) ; |
03e11df5 | 281 | #else |
89ebf1c9 RR |
282 | strcpy( (char *) maclabel , c_text ) ; |
283 | c2pstr( (char *) maclabel ) ; | |
03e11df5 | 284 | #endif |
519cb848 SC |
285 | } |
286 | ||
287 | void wxControl::MacPostControlCreate() | |
288 | { | |
89ebf1c9 RR |
289 | wxASSERT_MSG( m_macControl != NULL , "No valid mac control" ) ; |
290 | ||
291 | if ( IsKindOf( CLASSINFO( wxScrollBar ) ) ) | |
292 | { | |
293 | // no font | |
294 | } | |
295 | else if ( IsKindOf( CLASSINFO( wxStaticBox ) ) || IsKindOf( CLASSINFO( wxRadioBox ) ) || IsKindOf( CLASSINFO( wxButton ) ) ) | |
296 | { | |
297 | ControlFontStyleRec controlstyle ; | |
298 | controlstyle.flags = kControlUseFontMask ; | |
299 | controlstyle.font = kControlFontSmallBoldSystemFont ; | |
300 | ||
301 | ::SetControlFontStyle( m_macControl , &controlstyle ) ; | |
302 | } | |
303 | else | |
304 | { | |
305 | ControlFontStyleRec controlstyle ; | |
306 | controlstyle.flags = kControlUseFontMask ; | |
307 | controlstyle.font = kControlFontSmallSystemFont ; | |
308 | ||
309 | ::SetControlFontStyle( m_macControl , &controlstyle ) ; | |
310 | } | |
311 | ControlHandle container = GetParent()->MacGetContainerForEmbedding() ; | |
312 | wxASSERT_MSG( container != NULL , wxT("No valid mac container control") ) ; | |
313 | ::EmbedControl( m_macControl , container ) ; | |
314 | m_macControlIsShown = true ; | |
315 | ||
316 | wxAssociateControlWithMacControl( m_macControl , this ) ; | |
9453cf2b SC |
317 | |
318 | ||
319 | // Adjust the controls size and position | |
320 | wxPoint pos(m_x, m_y); | |
321 | wxSize best_size( DoGetBestSize() ); | |
322 | wxSize new_size( m_width, m_height ); | |
323 | ||
324 | m_x = m_y = m_width = m_height = -1; // Forces SetSize to move/size the control | |
325 | ||
326 | if (new_size.x == -1) { | |
327 | new_size.x = best_size.x; | |
328 | } | |
329 | if (new_size.y == -1) { | |
330 | new_size.y = best_size.y; | |
331 | } | |
332 | ||
333 | SetSize(pos.x, pos.y, new_size.x, new_size.y); | |
334 | ||
335 | UMAShowControl( m_macControl ) ; | |
a5a8ff8a | 336 | Refresh() ; |
519cb848 SC |
337 | } |
338 | ||
339 | void wxControl::MacAdjustControlRect() | |
340 | { | |
89ebf1c9 RR |
341 | wxASSERT_MSG( m_macControl != NULL , wxT("No valid mac control") ) ; |
342 | if ( m_width == -1 || m_height == -1 ) | |
343 | { | |
344 | Rect bestsize = { 0 , 0 , 0 , 0 } ; | |
345 | short baselineoffset ; | |
346 | ||
347 | ::GetBestControlRect( m_macControl , &bestsize , &baselineoffset ) ; | |
348 | ||
349 | if ( EmptyRect( &bestsize ) ) | |
350 | { | |
351 | baselineoffset = 0; | |
352 | bestsize.left = bestsize.top = 0 ; | |
353 | bestsize.right = 16 ; | |
354 | bestsize.bottom = 16 ; | |
355 | if ( IsKindOf( CLASSINFO( wxScrollBar ) ) ) | |
356 | { | |
357 | bestsize.bottom = 16 ; | |
358 | } | |
359 | else if ( IsKindOf( CLASSINFO( wxSpinButton ) ) ) | |
360 | { | |
361 | bestsize.bottom = 24 ; | |
362 | } | |
363 | } | |
364 | ||
365 | if ( m_width == -1 ) | |
366 | { | |
367 | if ( IsKindOf( CLASSINFO( wxButton ) ) ) | |
368 | { | |
369 | m_width = m_label.Length() * 8 + 12 ; | |
370 | if ( m_width < 70 ) | |
371 | m_width = 70 ; | |
372 | } | |
373 | else if ( IsKindOf( CLASSINFO( wxStaticText ) ) ) | |
374 | { | |
375 | m_width = m_label.Length() * 8 ; | |
376 | } | |
377 | else | |
378 | m_width = bestsize.right - bestsize.left ; | |
379 | ||
380 | m_width += 2 * m_macHorizontalBorder ; | |
381 | } | |
382 | if ( m_height == -1 ) | |
383 | { | |
384 | m_height = bestsize.bottom - bestsize.top ; | |
385 | if ( m_height < 10 ) | |
386 | m_height = 13 ; | |
387 | ||
388 | m_height += 2 * m_macVerticalBorder; | |
389 | } | |
390 | ||
de043984 | 391 | UMASizeControl( m_macControl , m_width - 2 * m_macHorizontalBorder, m_height - 2 * m_macVerticalBorder ) ; |
89ebf1c9 | 392 | } |
519cb848 SC |
393 | } |
394 | ControlHandle wxControl::MacGetContainerForEmbedding() | |
395 | { | |
89ebf1c9 RR |
396 | if ( m_macControl ) |
397 | return m_macControl ; | |
519cb848 | 398 | |
89ebf1c9 | 399 | return wxWindow::MacGetContainerForEmbedding() ; |
519cb848 SC |
400 | } |
401 | ||
402 | void wxControl::MacSuperChangedPosition() | |
403 | { | |
89ebf1c9 RR |
404 | if ( m_macControl ) |
405 | { | |
406 | Rect contrlRect ; | |
407 | GetControlBounds( m_macControl , &contrlRect ) ; | |
408 | int former_mac_x = contrlRect.left ; | |
409 | int former_mac_y = contrlRect.top ; | |
410 | int mac_x = m_x ; | |
411 | int mac_y = m_y ; | |
1c310985 | 412 | GetParent()->MacWindowToRootWindow( & mac_x , & mac_y ) ; |
89ebf1c9 | 413 | |
1c310985 | 414 | WindowRef rootwindow = MacGetRootWindow() ; |
1c310985 | 415 | |
1c310985 SC |
416 | if ( mac_x + m_macHorizontalBorder != former_mac_x || |
417 | mac_y + m_macVerticalBorder != former_mac_y ) | |
89ebf1c9 RR |
418 | { |
419 | { | |
420 | Rect inval = { former_mac_y , former_mac_x , former_mac_y + m_height , former_mac_x + m_width } ; | |
421 | InvalWindowRect( rootwindow , &inval ) ; | |
422 | } | |
423 | UMAMoveControl( m_macControl , mac_x + m_macHorizontalBorder , mac_y + m_macVerticalBorder ) ; | |
424 | { | |
425 | Rect inval = { mac_y , mac_x , mac_y + m_height , mac_x + m_width } ; | |
426 | InvalWindowRect( rootwindow , &inval ) ; | |
427 | } | |
428 | } | |
89ebf1c9 RR |
429 | } |
430 | ||
431 | wxWindow::MacSuperChangedPosition() ; | |
519cb848 SC |
432 | } |
433 | ||
434 | void wxControl::MacSuperEnabled( bool enabled ) | |
435 | { | |
1c469f7f | 436 | Refresh(FALSE) ; |
1c310985 | 437 | wxWindow::MacSuperEnabled( enabled ) ; |
519cb848 SC |
438 | } |
439 | ||
440 | void wxControl::MacSuperShown( bool show ) | |
441 | { | |
89ebf1c9 RR |
442 | if ( m_macControl ) |
443 | { | |
444 | if ( !show ) | |
445 | { | |
446 | if ( m_macControlIsShown ) | |
447 | { | |
1c310985 | 448 | ::UMAHideControl( m_macControl ) ; |
89ebf1c9 RR |
449 | m_macControlIsShown = false ; |
450 | } | |
451 | } | |
452 | else | |
453 | { | |
454 | if ( MacIsReallyShown() && !m_macControlIsShown ) | |
455 | { | |
456 | ::UMAShowControl( m_macControl ) ; | |
457 | m_macControlIsShown = true ; | |
458 | } | |
459 | } | |
460 | } | |
461 | ||
462 | wxWindow::MacSuperShown( show ) ; | |
519cb848 SC |
463 | } |
464 | ||
465 | void wxControl::DoSetSize(int x, int y, | |
466 | int width, int height, | |
467 | int sizeFlags ) | |
468 | { | |
89ebf1c9 RR |
469 | if ( m_macControl == NULL ) |
470 | { | |
471 | wxWindow::DoSetSize( x , y ,width , height ,sizeFlags ) ; | |
472 | return ; | |
473 | } | |
519cb848 | 474 | |
9453cf2b SC |
475 | Rect oldbounds, newbounds; |
476 | int new_x, new_y, new_width, new_height; | |
477 | int mac_x, mac_y; | |
478 | ||
479 | new_x = m_x; | |
480 | new_y = m_y; | |
481 | new_width = m_width; | |
482 | new_height = m_height; | |
483 | ||
484 | if (sizeFlags & wxSIZE_ALLOW_MINUS_ONE) | |
485 | { | |
486 | new_x = x; | |
487 | new_y = y; | |
488 | new_width = width; | |
489 | new_height = height; | |
490 | } | |
491 | else | |
492 | { | |
493 | if (x != -1) new_x = x; | |
494 | if (y != -1) new_y = y; | |
495 | if (width != -1) new_width = width; | |
496 | if (height != -1) new_height = height; | |
497 | } | |
498 | ||
499 | if(sizeFlags & wxSIZE_AUTO) | |
500 | { | |
501 | wxSize size = GetBestSize(); | |
502 | if (sizeFlags & wxSIZE_AUTO_WIDTH) | |
503 | { | |
504 | if (width == -1) new_width = size.x; | |
505 | } | |
506 | if (sizeFlags & wxSIZE_AUTO_HEIGHT) | |
507 | { | |
508 | if (height == -1) new_height = size.y; | |
509 | } | |
510 | } | |
1c310985 | 511 | AdjustForParentClientOrigin(new_x, new_y, sizeFlags); |
9453cf2b SC |
512 | |
513 | mac_x = new_x; | |
514 | mac_y = new_y; | |
515 | if(GetParent()) { | |
1c310985 | 516 | GetParent()->MacWindowToRootWindow(&mac_x, &mac_y); |
9453cf2b SC |
517 | } |
518 | GetControlBounds(m_macControl, &oldbounds); | |
519 | oldbounds.right = oldbounds.left + m_width; | |
520 | oldbounds.bottom = oldbounds.top + m_height; | |
521 | ||
522 | bool doMove = false; | |
523 | bool doResize = false; | |
524 | ||
525 | if ( mac_x != (oldbounds.left - m_macHorizontalBorder) || | |
526 | mac_y != (oldbounds.top - m_macVerticalBorder) ) | |
527 | { | |
528 | doMove = true ; | |
529 | } | |
530 | if ( new_width != oldbounds.right - oldbounds.left - 2 * m_macHorizontalBorder || | |
531 | new_height != oldbounds.bottom - oldbounds.top - 2 * m_macVerticalBorder) | |
532 | { | |
533 | doResize = true ; | |
534 | } | |
535 | ||
536 | if ( doMove || doResize ) | |
537 | { | |
1c310985 SC |
538 | Refresh() ; |
539 | ||
9453cf2b SC |
540 | // Ensure resize is within constraints |
541 | if ((m_minWidth != -1) && (new_width < m_minWidth)) { | |
542 | new_width = m_minWidth; | |
543 | } | |
544 | if ((m_minHeight != -1) && (new_height < m_minHeight)) { | |
545 | new_height = m_minHeight; | |
546 | } | |
547 | if ((m_maxWidth != -1) && (new_width > m_maxWidth)) { | |
548 | new_width = m_maxWidth; | |
549 | } | |
550 | if ((m_maxHeight != -1) && (new_height > m_maxHeight)) { | |
551 | new_height = m_maxHeight; | |
552 | } | |
553 | ||
554 | if ( doMove ) | |
555 | { | |
556 | m_x = new_x; | |
557 | m_y = new_y; | |
558 | ||
559 | UMAMoveControl(m_macControl, | |
560 | mac_x + m_macHorizontalBorder, mac_y + m_macVerticalBorder); | |
1c310985 | 561 | |
9453cf2b SC |
562 | wxMoveEvent event(wxPoint(m_x, m_y), m_windowId); |
563 | event.SetEventObject(this); | |
564 | GetEventHandler()->ProcessEvent(event) ; | |
565 | } | |
566 | if ( doResize ) | |
567 | { | |
568 | m_width = new_width; | |
569 | m_height = new_height; | |
570 | ||
571 | UMASizeControl( m_macControl, | |
572 | m_width - 2 * m_macHorizontalBorder, | |
573 | m_height - 2 * m_macVerticalBorder ) ; | |
574 | ||
abfe4a84 | 575 | |
9453cf2b SC |
576 | wxSizeEvent event(wxSize(m_width, m_height), m_windowId); |
577 | event.SetEventObject(this); | |
578 | GetEventHandler()->ProcessEvent(event); | |
579 | } | |
580 | ||
1c310985 | 581 | Refresh() ; |
9453cf2b | 582 | } |
519cb848 SC |
583 | } |
584 | ||
519cb848 SC |
585 | bool wxControl::Show(bool show) |
586 | { | |
89ebf1c9 RR |
587 | if ( !wxWindow::Show( show ) ) |
588 | return FALSE ; | |
589 | ||
590 | if ( m_macControl ) | |
591 | { | |
592 | if ( !show ) | |
593 | { | |
594 | if ( m_macControlIsShown ) | |
595 | { | |
1c310985 | 596 | ::UMAHideControl( m_macControl ) ; |
89ebf1c9 RR |
597 | m_macControlIsShown = false ; |
598 | } | |
599 | } | |
600 | else | |
601 | { | |
602 | if ( MacIsReallyShown() && !m_macControlIsShown ) | |
603 | { | |
604 | ::UMAShowControl( m_macControl ) ; | |
605 | m_macControlIsShown = true ; | |
606 | } | |
607 | } | |
608 | } | |
609 | return TRUE ; | |
519cb848 SC |
610 | } |
611 | ||
e7549107 | 612 | bool wxControl::Enable(bool enable) |
519cb848 | 613 | { |
e7549107 SC |
614 | if ( !wxWindow::Enable(enable) ) |
615 | return FALSE; | |
519cb848 | 616 | |
89ebf1c9 RR |
617 | if ( m_macControl ) |
618 | { | |
619 | if ( enable ) | |
620 | UMAActivateControl( m_macControl ) ; | |
621 | else | |
622 | UMADeactivateControl( m_macControl ) ; | |
623 | } | |
624 | return TRUE ; | |
519cb848 SC |
625 | } |
626 | ||
627 | void wxControl::Refresh(bool eraseBack, const wxRect *rect) | |
628 | { | |
89ebf1c9 | 629 | wxWindow::Refresh( eraseBack , rect ) ; |
519cb848 SC |
630 | } |
631 | ||
2f1ae414 SC |
632 | void wxControl::MacRedrawControl() |
633 | { | |
de043984 | 634 | if ( m_macControl && MacGetRootWindow() ) |
89ebf1c9 | 635 | { |
de043984 SC |
636 | wxClientDC dc(this) ; |
637 | wxMacPortSetter helper(&dc) ; | |
638 | ||
639 | // the controls sometimes draw outside their boundaries, this | |
640 | // should be resolved differently but is not trivial (e.g. drop shadows) | |
641 | // since adding them to the border would yield in enormous gaps between | |
642 | // the controls | |
643 | Rect r = { 0 , 0 , 32000 , 32000 } ; | |
644 | ClipRect( &r ) ; | |
645 | wxDC::MacSetupBackgroundForCurrentPort( MacGetBackgroundBrush() ) ; | |
646 | UMADrawControl( m_macControl ) ; | |
89ebf1c9 | 647 | } |
2f1ae414 SC |
648 | } |
649 | ||
519cb848 SC |
650 | void wxControl::OnPaint(wxPaintEvent& event) |
651 | { | |
89ebf1c9 RR |
652 | if ( m_macControl ) |
653 | { | |
de043984 SC |
654 | wxPaintDC dc(this) ; |
655 | wxMacPortSetter helper(&dc) ; | |
656 | // the controls sometimes draw outside their boundaries, this | |
657 | // should be resolved differently but is not trivial (e.g. drop shadows) | |
658 | // since adding them to the border would yield in enormous gaps between | |
659 | // the controls | |
660 | Rect r = { 0 , 0 , 32000 , 32000 } ; | |
661 | ClipRect( &r ) ; | |
662 | ||
663 | wxDC::MacSetupBackgroundForCurrentPort( MacGetBackgroundBrush() ) ; | |
664 | UMADrawControl( m_macControl ) ; | |
89ebf1c9 RR |
665 | } |
666 | else | |
667 | { | |
a5a8ff8a | 668 | event.Skip() ; |
89ebf1c9 | 669 | } |
519cb848 | 670 | } |
51abe921 SC |
671 | void wxControl::OnEraseBackground(wxEraseEvent& event) |
672 | { | |
1c310985 | 673 | wxWindow::OnEraseBackground( event ) ; |
51abe921 SC |
674 | } |
675 | ||
519cb848 SC |
676 | |
677 | void wxControl::OnKeyDown( wxKeyEvent &event ) | |
678 | { | |
89ebf1c9 RR |
679 | if ( m_macControl == NULL ) |
680 | return ; | |
681 | ||
682 | EventRecord *ev = wxTheApp->MacGetCurrentEvent() ; | |
683 | short keycode ; | |
684 | short keychar ; | |
685 | keychar = short(ev->message & charCodeMask); | |
686 | keycode = short(ev->message & keyCodeMask) >> 8 ; | |
687 | ||
688 | ::HandleControlKey( m_macControl , keycode , keychar , ev->modifiers ) ; | |
519cb848 SC |
689 | } |
690 | ||
691 | void wxControl::OnMouseEvent( wxMouseEvent &event ) | |
692 | { | |
89ebf1c9 RR |
693 | if ( m_macControl == NULL ) |
694 | { | |
695 | event.Skip() ; | |
696 | return ; | |
697 | } | |
698 | ||
699 | if (event.GetEventType() == wxEVT_LEFT_DOWN || event.GetEventType() == wxEVT_LEFT_DCLICK ) | |
700 | { | |
701 | ||
702 | int x = event.m_x ; | |
703 | int y = event.m_y ; | |
704 | ||
705 | MacClientToRootWindow( &x , &y ) ; | |
706 | ||
707 | ControlHandle control ; | |
708 | Point localwhere ; | |
709 | SInt16 controlpart ; | |
1c310985 | 710 | WindowRef window = MacGetRootWindow() ; |
89ebf1c9 RR |
711 | |
712 | localwhere.h = x ; | |
713 | localwhere.v = y ; | |
714 | ||
715 | short modifiers = 0; | |
716 | ||
717 | if ( !event.m_leftDown && !event.m_rightDown ) | |
718 | modifiers |= btnState ; | |
719 | ||
720 | if ( event.m_shiftDown ) | |
721 | modifiers |= shiftKey ; | |
722 | ||
723 | if ( event.m_controlDown ) | |
724 | modifiers |= controlKey ; | |
725 | ||
726 | if ( event.m_altDown ) | |
727 | modifiers |= optionKey ; | |
728 | ||
729 | if ( event.m_metaDown ) | |
730 | modifiers |= cmdKey ; | |
f78024a1 | 731 | /* |
892e461e | 732 | #if TARGET_CARBON |
280df085 | 733 | control = FindControlUnderMouse( localwhere , window , &controlpart ) ; |
892e461e | 734 | #else |
89ebf1c9 | 735 | controlpart = FindControl( localwhere , window , &control ) ; |
892e461e | 736 | #endif |
f78024a1 | 737 | */ |
89ebf1c9 RR |
738 | { |
739 | /* | |
740 | if ( AcceptsFocus() && FindFocus() != this ) | |
741 | { | |
742 | SetFocus() ; | |
743 | } | |
744 | */ | |
745 | control = m_macControl ; | |
746 | if ( control && ::IsControlActive( control ) ) | |
747 | { | |
748 | { | |
749 | controlpart = ::HandleControlClick( control , localwhere , modifiers , (ControlActionUPP) -1 ) ; | |
750 | wxTheApp->s_lastMouseDown = 0 ; | |
751 | if ( control && controlpart != kControlNoPart && | |
752 | ! IsKindOf( CLASSINFO( wxScrollBar ) ) | |
753 | ) // otherwise we will get the event twice for scrollbar | |
754 | { | |
755 | MacHandleControlClick( control , controlpart ) ; | |
756 | } | |
757 | } | |
758 | } | |
759 | } | |
760 | } | |
519cb848 SC |
761 | } |
762 | ||
763 | bool wxControl::MacCanFocus() const | |
764 | { | |
89ebf1c9 RR |
765 | { if ( m_macControl == NULL ) |
766 | return true ; | |
767 | else | |
768 | return false ; | |
769 | } | |
519cb848 SC |
770 | } |
771 | ||
772 | void wxControl::MacHandleControlClick( ControlHandle control , SInt16 controlpart ) | |
773 | { | |
89ebf1c9 | 774 | wxASSERT_MSG( m_macControl != NULL , "No valid mac control" ) ; |
519cb848 SC |
775 | } |
776 |