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