]>
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 | |
9 | // Licence: wxWindows licence | |
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) |
519cb848 SC |
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 | { | |
52 | if ( partCode != 0) | |
53 | { | |
54 | wxControl* wx = (wxControl*) GetControlReference( control ) ; | |
55 | if ( wx ) | |
56 | { | |
57 | wx->MacHandleControlClick( control , partCode ) ; | |
58 | } | |
59 | } | |
60 | } | |
61 | ||
e9576ca5 SC |
62 | wxControl::wxControl() |
63 | { | |
2f1ae414 SC |
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 SC |
72 | |
73 | if ( wxMacLiveScrollbarActionUPP == NULL ) | |
74 | { | |
4114d0af | 75 | #if defined(UNIVERSAL_INTERFACES_VERSION) && (UNIVERSAL_INTERFACES_VERSION >= 0x0340) |
03e11df5 GD |
76 | wxMacLiveScrollbarActionUPP = NewControlActionUPP( wxMacLiveScrollbarActionProc ); |
77 | #else | |
519cb848 | 78 | wxMacLiveScrollbarActionUPP = NewControlActionProc( wxMacLiveScrollbarActionProc ) ; |
03e11df5 | 79 | #endif |
519cb848 | 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 | { | |
89 | m_macControl = NULL ; | |
90 | m_macHorizontalBorder = 0 ; // additional pixels around the real control | |
91 | m_macVerticalBorder = 0 ; | |
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. | |
e7549107 SC |
106 | wxPanel *panel = wxDynamicCast(GetParent(), wxPanel); |
107 | if ( panel ) | |
e9576ca5 | 108 | { |
e7549107 SC |
109 | if (panel->GetDefaultItem() == (wxButton*) this) |
110 | panel->SetDefaultItem(NULL); | |
e9576ca5 | 111 | } |
519cb848 SC |
112 | if ( m_macControl ) |
113 | { | |
72055702 | 114 | ::DisposeControl( m_macControl ) ; |
519cb848 SC |
115 | m_macControl = NULL ; |
116 | } | |
e9576ca5 SC |
117 | } |
118 | ||
e7549107 | 119 | void wxControl::SetLabel(const wxString& title) |
e9576ca5 | 120 | { |
e7549107 | 121 | m_label = title ; |
519cb848 SC |
122 | |
123 | if ( m_macControl ) | |
124 | { | |
125 | Str255 maclabel ; | |
e7549107 SC |
126 | wxString label ; |
127 | ||
128 | if( wxApp::s_macDefaultEncodingIsPC ) | |
129 | label = wxMacMakeMacStringFromPC( title ) ; | |
130 | else | |
131 | label = title ; | |
519cb848 | 132 | |
03e11df5 GD |
133 | #if TARGET_CARBON |
134 | c2pstrcpy( (StringPtr) maclabel , label ) ; | |
135 | #else | |
136 | strcpy( (char *) maclabel , label ) ; | |
137 | c2pstr( (char *) maclabel ) ; | |
138 | #endif | |
519cb848 SC |
139 | ::SetControlTitle( m_macControl , maclabel ) ; |
140 | } | |
fdaf613a | 141 | Refresh() ; |
e9576ca5 SC |
142 | } |
143 | ||
37e2cb08 | 144 | wxSize wxControl::DoGetBestSize() const |
e9576ca5 | 145 | { |
9453cf2b SC |
146 | Rect bestsize = { 0 , 0 , 0 , 0 } ; |
147 | short baselineoffset ; | |
148 | int bestWidth, bestHeight ; | |
72055702 | 149 | ::GetBestControlRect( m_macControl , &bestsize , &baselineoffset ) ; |
9453cf2b SC |
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 | ||
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 , | |
238 | const wxPoint& pos, | |
239 | const wxSize& size, long style, | |
240 | const wxValidator& validator, | |
241 | const wxString& name , Rect *outBounds , StringPtr maclabel ) | |
242 | { | |
243 | m_label = label ; | |
244 | SetName(name); | |
245 | if ( &validator ) | |
246 | SetValidator(validator); | |
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 | ||
519cb848 SC |
261 | m_width = size.x ; |
262 | m_height = size.y ; | |
9453cf2b SC |
263 | m_x = pos.x ; |
264 | m_y = pos.y ; | |
519cb848 | 265 | |
9453cf2b SC |
266 | outBounds->top = -10; |
267 | outBounds->left = -10; | |
268 | outBounds->bottom = 0; | |
269 | outBounds->right = 0; | |
519cb848 | 270 | |
03e11df5 GD |
271 | char c_text[255]; |
272 | strcpy( c_text , label ) ; | |
519cb848 SC |
273 | if( wxApp::s_macDefaultEncodingIsPC ) |
274 | { | |
03e11df5 | 275 | wxMacConvertFromPCForControls( c_text ) ; |
519cb848 SC |
276 | } |
277 | ||
03e11df5 GD |
278 | #if TARGET_CARBON |
279 | c2pstrcpy( (StringPtr) maclabel , c_text ) ; | |
280 | #else | |
281 | strcpy( (char *) maclabel , c_text ) ; | |
282 | c2pstr( (char *) maclabel ) ; | |
283 | #endif | |
519cb848 SC |
284 | } |
285 | ||
286 | void wxControl::MacPostControlCreate() | |
287 | { | |
288 | wxASSERT_MSG( m_macControl != NULL , "No valid mac control" ) ; | |
289 | ||
290 | if ( IsKindOf( CLASSINFO( wxScrollBar ) ) ) | |
291 | { | |
292 | // no font | |
293 | } | |
2f1ae414 | 294 | else if ( IsKindOf( CLASSINFO( wxStaticBox ) ) || IsKindOf( CLASSINFO( wxRadioBox ) ) || IsKindOf( CLASSINFO( wxButton ) ) ) |
519cb848 SC |
295 | { |
296 | ControlFontStyleRec controlstyle ; | |
297 | controlstyle.flags = kControlUseFontMask ; | |
298 | controlstyle.font = kControlFontSmallBoldSystemFont ; | |
299 | ||
72055702 | 300 | ::SetControlFontStyle( m_macControl , &controlstyle ) ; |
519cb848 SC |
301 | } |
302 | else | |
303 | { | |
304 | ControlFontStyleRec controlstyle ; | |
305 | controlstyle.flags = kControlUseFontMask ; | |
306 | controlstyle.font = kControlFontSmallSystemFont ; | |
307 | ||
72055702 | 308 | ::SetControlFontStyle( m_macControl , &controlstyle ) ; |
519cb848 SC |
309 | } |
310 | ControlHandle container = GetParent()->MacGetContainerForEmbedding() ; | |
9453cf2b | 311 | wxASSERT_MSG( container != NULL , wxT("No valid mac container control") ) ; |
72055702 | 312 | ::EmbedControl( m_macControl , container ) ; |
c809f3be | 313 | m_macControlIsShown = true ; |
9453cf2b | 314 | |
519cb848 | 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 ) ; | |
519cb848 SC |
335 | } |
336 | ||
337 | void wxControl::MacAdjustControlRect() | |
338 | { | |
9453cf2b | 339 | wxASSERT_MSG( m_macControl != NULL , wxT("No valid mac control") ) ; |
519cb848 SC |
340 | if ( m_width == -1 || m_height == -1 ) |
341 | { | |
342 | Rect bestsize = { 0 , 0 , 0 , 0 } ; | |
343 | short baselineoffset ; | |
344 | ||
72055702 | 345 | ::GetBestControlRect( m_macControl , &bestsize , &baselineoffset ) ; |
519cb848 SC |
346 | |
347 | if ( EmptyRect( &bestsize ) ) | |
348 | { | |
349 | baselineoffset = 0; | |
350 | bestsize.left = bestsize.top = 0 ; | |
351 | bestsize.right = 16 ; | |
352 | bestsize.bottom = 16 ; | |
353 | if ( IsKindOf( CLASSINFO( wxScrollBar ) ) ) | |
354 | { | |
355 | bestsize.bottom = 16 ; | |
356 | } | |
357 | else if ( IsKindOf( CLASSINFO( wxSpinButton ) ) ) | |
358 | { | |
359 | bestsize.bottom = 24 ; | |
360 | } | |
361 | } | |
362 | ||
363 | if ( m_width == -1 ) | |
364 | { | |
365 | if ( IsKindOf( CLASSINFO( wxButton ) ) ) | |
366 | { | |
2f1ae414 | 367 | m_width = m_label.Length() * 8 + 12 ; |
0a67a93b SC |
368 | if ( m_width < 70 ) |
369 | m_width = 70 ; | |
519cb848 SC |
370 | } |
371 | else if ( IsKindOf( CLASSINFO( wxStaticText ) ) ) | |
372 | { | |
373 | m_width = m_label.Length() * 8 ; | |
374 | } | |
375 | else | |
2f1ae414 SC |
376 | m_width = bestsize.right - bestsize.left ; |
377 | ||
378 | m_width += 2 * m_macHorizontalBorder ; | |
519cb848 SC |
379 | } |
380 | if ( m_height == -1 ) | |
381 | { | |
382 | m_height = bestsize.bottom - bestsize.top ; | |
383 | if ( m_height < 10 ) | |
384 | m_height = 13 ; | |
385 | ||
386 | m_height += 2 * m_macVerticalBorder; | |
387 | } | |
388 | ||
389 | wxMacDrawingHelper helper ( wxFindWinFromMacWindow( GetMacRootWindow() ) ) ; | |
390 | if ( helper.Ok() ) | |
391 | { | |
2f1ae414 | 392 | UMASizeControl( m_macControl , m_width - 2 * m_macHorizontalBorder, m_height - 2 * m_macVerticalBorder ) ; |
519cb848 SC |
393 | } |
394 | } | |
395 | } | |
396 | ControlHandle wxControl::MacGetContainerForEmbedding() | |
397 | { | |
398 | if ( m_macControl ) | |
399 | return m_macControl ; | |
400 | ||
401 | return wxWindow::MacGetContainerForEmbedding() ; | |
402 | } | |
403 | ||
404 | void wxControl::MacSuperChangedPosition() | |
405 | { | |
406 | if ( m_macControl ) | |
407 | { | |
2f1ae414 SC |
408 | Rect contrlRect ; |
409 | GetControlBounds( m_macControl , &contrlRect ) ; | |
410 | int former_mac_x = contrlRect.left ; | |
411 | int former_mac_y = contrlRect.top ; | |
519cb848 SC |
412 | int mac_x = m_x ; |
413 | int mac_y = m_y ; | |
414 | GetParent()->MacClientToRootWindow( & mac_x , & mac_y ) ; | |
415 | ||
416 | WindowRef rootwindow = GetMacRootWindow() ; | |
417 | wxWindow* wxrootwindow = wxFindWinFromMacWindow( rootwindow ) ; | |
72055702 | 418 | ::SetThemeWindowBackground( rootwindow , kThemeBrushDialogBackgroundActive , false ) ; |
519cb848 SC |
419 | wxMacDrawingHelper focus( wxrootwindow ) ; |
420 | ||
421 | if ( mac_x != former_mac_x || mac_y != former_mac_y ) | |
422 | { | |
fd2e20ff SC |
423 | { |
424 | Rect inval = { former_mac_y , former_mac_x , former_mac_y + m_height , former_mac_x + m_width } ; | |
425 | InvalWindowRect( rootwindow , &inval ) ; | |
426 | } | |
2f1ae414 | 427 | UMAMoveControl( m_macControl , mac_x + m_macHorizontalBorder , mac_y + m_macVerticalBorder ) ; |
fd2e20ff SC |
428 | { |
429 | Rect inval = { mac_y , mac_x , mac_y + m_height , mac_x + m_width } ; | |
430 | InvalWindowRect( rootwindow , &inval ) ; | |
431 | } | |
519cb848 SC |
432 | } |
433 | if ( wxrootwindow->IsKindOf( CLASSINFO( wxDialog ) ) ) | |
434 | { | |
435 | } | |
436 | else | |
437 | { | |
72055702 | 438 | ::SetThemeWindowBackground( rootwindow , kThemeBrushDocumentWindowBackground , false ) ; |
519cb848 SC |
439 | } |
440 | } | |
441 | ||
442 | wxWindow::MacSuperChangedPosition() ; | |
443 | } | |
444 | ||
445 | void wxControl::MacSuperEnabled( bool enabled ) | |
446 | { | |
e7549107 | 447 | /* |
519cb848 SC |
448 | if ( m_macControl ) |
449 | { | |
450 | if ( UMAHasAppearance() ) | |
451 | { | |
452 | if ( !enabled ) | |
453 | { | |
454 | ::DeactivateControl( m_macControl ) ; | |
455 | } | |
456 | else | |
457 | { | |
458 | if ( m_macEnabled ) | |
459 | ::ActivateControl( m_macControl ) ; | |
460 | } | |
461 | } | |
462 | else | |
463 | { | |
464 | if ( !enabled ) | |
465 | { | |
466 | ::HiliteControl( m_macControl , 255 ) ; | |
467 | } | |
468 | else | |
469 | { | |
470 | if ( m_macEnabled ) | |
471 | ::HiliteControl( m_macControl , 0 ) ; | |
472 | } | |
473 | } | |
474 | } | |
475 | wxWindow::MacSuperEnabled( enabled ) ; | |
2f1ae414 | 476 | */ |
519cb848 SC |
477 | } |
478 | ||
479 | void wxControl::MacSuperShown( bool show ) | |
480 | { | |
481 | if ( m_macControl ) | |
482 | { | |
483 | if ( !show ) | |
484 | { | |
c809f3be SC |
485 | if ( m_macControlIsShown ) |
486 | { | |
72055702 | 487 | ::HideControl( m_macControl ) ; |
c809f3be SC |
488 | m_macControlIsShown = false ; |
489 | } | |
519cb848 SC |
490 | } |
491 | else | |
492 | { | |
c809f3be SC |
493 | if ( MacIsReallyShown() && !m_macControlIsShown ) |
494 | { | |
519cb848 | 495 | ::UMAShowControl( m_macControl ) ; |
c809f3be SC |
496 | m_macControlIsShown = true ; |
497 | } | |
519cb848 SC |
498 | } |
499 | } | |
500 | ||
501 | wxWindow::MacSuperShown( show ) ; | |
502 | } | |
503 | ||
504 | void wxControl::DoSetSize(int x, int y, | |
505 | int width, int height, | |
506 | int sizeFlags ) | |
507 | { | |
508 | if ( m_macControl == NULL ) | |
509 | { | |
510 | wxWindow::DoSetSize( x , y ,width , height ,sizeFlags ) ; | |
511 | return ; | |
512 | } | |
513 | ||
9453cf2b SC |
514 | Rect oldbounds, newbounds; |
515 | int new_x, new_y, new_width, new_height; | |
516 | int mac_x, mac_y; | |
517 | ||
518 | new_x = m_x; | |
519 | new_y = m_y; | |
520 | new_width = m_width; | |
521 | new_height = m_height; | |
522 | ||
523 | if (sizeFlags & wxSIZE_ALLOW_MINUS_ONE) | |
524 | { | |
525 | new_x = x; | |
526 | new_y = y; | |
527 | new_width = width; | |
528 | new_height = height; | |
529 | } | |
530 | else | |
531 | { | |
532 | if (x != -1) new_x = x; | |
533 | if (y != -1) new_y = y; | |
534 | if (width != -1) new_width = width; | |
535 | if (height != -1) new_height = height; | |
536 | } | |
537 | ||
538 | if(sizeFlags & wxSIZE_AUTO) | |
539 | { | |
540 | wxSize size = GetBestSize(); | |
541 | if (sizeFlags & wxSIZE_AUTO_WIDTH) | |
542 | { | |
543 | if (width == -1) new_width = size.x; | |
544 | } | |
545 | if (sizeFlags & wxSIZE_AUTO_HEIGHT) | |
546 | { | |
547 | if (height == -1) new_height = size.y; | |
548 | } | |
549 | } | |
550 | AdjustForParentClientOrigin(new_x, new_y, sizeFlags); | |
551 | ||
552 | mac_x = new_x; | |
553 | mac_y = new_y; | |
554 | if(GetParent()) { | |
555 | GetParent()->MacClientToRootWindow(&mac_x, &mac_y); | |
556 | } | |
557 | GetControlBounds(m_macControl, &oldbounds); | |
558 | oldbounds.right = oldbounds.left + m_width; | |
559 | oldbounds.bottom = oldbounds.top + m_height; | |
560 | ||
561 | bool doMove = false; | |
562 | bool doResize = false; | |
563 | ||
564 | if ( mac_x != (oldbounds.left - m_macHorizontalBorder) || | |
565 | mac_y != (oldbounds.top - m_macVerticalBorder) ) | |
566 | { | |
567 | doMove = true ; | |
568 | } | |
569 | if ( new_width != oldbounds.right - oldbounds.left - 2 * m_macHorizontalBorder || | |
570 | new_height != oldbounds.bottom - oldbounds.top - 2 * m_macVerticalBorder) | |
571 | { | |
572 | doResize = true ; | |
573 | } | |
574 | ||
575 | if ( doMove || doResize ) | |
576 | { | |
577 | // Ensure resize is within constraints | |
578 | if ((m_minWidth != -1) && (new_width < m_minWidth)) { | |
579 | new_width = m_minWidth; | |
580 | } | |
581 | if ((m_minHeight != -1) && (new_height < m_minHeight)) { | |
582 | new_height = m_minHeight; | |
583 | } | |
584 | if ((m_maxWidth != -1) && (new_width > m_maxWidth)) { | |
585 | new_width = m_maxWidth; | |
586 | } | |
587 | if ((m_maxHeight != -1) && (new_height > m_maxHeight)) { | |
588 | new_height = m_maxHeight; | |
589 | } | |
590 | ||
591 | if ( doMove ) | |
592 | { | |
593 | m_x = new_x; | |
594 | m_y = new_y; | |
595 | ||
596 | UMAMoveControl(m_macControl, | |
597 | mac_x + m_macHorizontalBorder, mac_y + m_macVerticalBorder); | |
598 | ||
599 | wxMoveEvent event(wxPoint(m_x, m_y), m_windowId); | |
600 | event.SetEventObject(this); | |
601 | GetEventHandler()->ProcessEvent(event) ; | |
602 | } | |
603 | if ( doResize ) | |
604 | { | |
605 | m_width = new_width; | |
606 | m_height = new_height; | |
607 | ||
608 | UMASizeControl( m_macControl, | |
609 | m_width - 2 * m_macHorizontalBorder, | |
610 | m_height - 2 * m_macVerticalBorder ) ; | |
611 | ||
abfe4a84 | 612 | |
9453cf2b SC |
613 | wxSizeEvent event(wxSize(m_width, m_height), m_windowId); |
614 | event.SetEventObject(this); | |
615 | GetEventHandler()->ProcessEvent(event); | |
616 | } | |
617 | ||
618 | // Set up port | |
619 | WindowRef rootwindow = GetMacRootWindow() ; | |
620 | wxWindow* wxrootwindow = wxFindWinFromMacWindow( rootwindow ) ; | |
621 | wxMacDrawingHelper focus( wxrootwindow ); | |
622 | ||
72055702 | 623 | ::SetThemeWindowBackground( rootwindow , kThemeBrushDialogBackgroundActive , false ) ; |
9453cf2b SC |
624 | // Update window at old and new positions |
625 | SetRect(&newbounds, m_x, m_y, m_x + m_width, m_y + m_height); | |
626 | InvalWindowRect( rootwindow , &oldbounds ); | |
627 | InvalWindowRect( rootwindow , &newbounds ); | |
628 | ||
629 | MacRepositionScrollBars() ; | |
630 | ||
631 | if ( !wxrootwindow->IsKindOf( CLASSINFO( wxDialog ) ) ) | |
632 | { | |
72055702 | 633 | ::SetThemeWindowBackground( rootwindow, kThemeBrushDocumentWindowBackground, false ); |
9453cf2b SC |
634 | } |
635 | } | |
519cb848 SC |
636 | } |
637 | ||
519cb848 SC |
638 | bool wxControl::Show(bool show) |
639 | { | |
e7549107 SC |
640 | if ( !wxWindow::Show( show ) ) |
641 | return FALSE ; | |
642 | ||
643 | if ( m_macControl ) | |
644 | { | |
c809f3be SC |
645 | if ( !show ) |
646 | { | |
647 | if ( m_macControlIsShown ) | |
648 | { | |
72055702 | 649 | ::HideControl( m_macControl ) ; |
c809f3be SC |
650 | m_macControlIsShown = false ; |
651 | } | |
652 | } | |
e7549107 | 653 | else |
c809f3be SC |
654 | { |
655 | if ( MacIsReallyShown() && !m_macControlIsShown ) | |
656 | { | |
657 | ::UMAShowControl( m_macControl ) ; | |
658 | m_macControlIsShown = true ; | |
659 | } | |
660 | } | |
e7549107 SC |
661 | } |
662 | return TRUE ; | |
519cb848 SC |
663 | } |
664 | ||
e7549107 | 665 | bool wxControl::Enable(bool enable) |
519cb848 | 666 | { |
e7549107 SC |
667 | if ( !wxWindow::Enable(enable) ) |
668 | return FALSE; | |
519cb848 | 669 | |
e7549107 | 670 | if ( m_macControl ) |
519cb848 | 671 | { |
fdaf613a SC |
672 | if ( enable ) |
673 | UMAActivateControl( m_macControl ) ; | |
519cb848 | 674 | else |
fdaf613a | 675 | UMADeactivateControl( m_macControl ) ; |
519cb848 | 676 | } |
e7549107 | 677 | return TRUE ; |
519cb848 SC |
678 | } |
679 | ||
680 | void wxControl::Refresh(bool eraseBack, const wxRect *rect) | |
681 | { | |
682 | if ( m_macControl ) | |
683 | { | |
684 | wxWindow::Refresh( eraseBack , rect ) ; | |
685 | } | |
686 | else | |
687 | { | |
688 | wxWindow::Refresh( eraseBack , rect ) ; | |
689 | } | |
690 | } | |
691 | ||
2f1ae414 SC |
692 | void wxControl::MacRedrawControl() |
693 | { | |
694 | if ( m_macControl ) | |
695 | { | |
696 | WindowRef window = GetMacRootWindow() ; | |
697 | if ( window ) | |
698 | { | |
699 | wxWindow* win = wxFindWinFromMacWindow( window ) ; | |
700 | if ( win ) | |
701 | { | |
702 | wxMacDrawingHelper help( win ) ; | |
703 | // the mac control manager always assumes to have the origin at 0,0 | |
704 | SetOrigin( 0 , 0 ) ; | |
705 | ||
2f1ae414 SC |
706 | wxWindow* parent = GetParent() ; |
707 | while ( parent ) | |
708 | { | |
709 | if( parent->MacGetWindowData() ) | |
710 | { | |
72055702 | 711 | ::SetThemeWindowBackground( win->MacGetWindowData()->m_macWindow , kThemeBrushDialogBackgroundActive , false ) ; |
2f1ae414 SC |
712 | break ; |
713 | } | |
714 | ||
715 | if( parent->IsKindOf( CLASSINFO( wxNotebook ) ) || parent->IsKindOf( CLASSINFO( wxTabCtrl ) )) | |
716 | { | |
717 | if ( ((wxControl*)parent)->m_macControl ) | |
718 | SetUpControlBackground( ((wxControl*)parent)->m_macControl , -1 , true ) ; | |
719 | break ; | |
720 | } | |
721 | ||
722 | parent = parent->GetParent() ; | |
723 | } | |
724 | ||
725 | UMADrawControl( m_macControl ) ; | |
72055702 | 726 | ::SetThemeWindowBackground( win->MacGetWindowData()->m_macWindow , win->MacGetWindowData()->m_macWindowBackgroundTheme , false ) ; |
2f1ae414 SC |
727 | } |
728 | } | |
729 | } | |
730 | } | |
731 | ||
519cb848 SC |
732 | void wxControl::OnPaint(wxPaintEvent& event) |
733 | { | |
734 | if ( m_macControl ) | |
735 | { | |
736 | WindowRef window = GetMacRootWindow() ; | |
737 | if ( window ) | |
738 | { | |
739 | wxWindow* win = wxFindWinFromMacWindow( window ) ; | |
740 | if ( win ) | |
741 | { | |
742 | wxMacDrawingHelper help( win ) ; | |
2f1ae414 | 743 | // the mac control manager always assumes to have the origin at 0,0 |
519cb848 | 744 | SetOrigin( 0 , 0 ) ; |
27419164 | 745 | |
519cb848 SC |
746 | wxWindow* parent = GetParent() ; |
747 | while ( parent ) | |
748 | { | |
e7549107 | 749 | if( parent->MacGetWindowData() ) |
519cb848 | 750 | { |
72055702 | 751 | ::SetThemeWindowBackground( win->MacGetWindowData()->m_macWindow , kThemeBrushDialogBackgroundActive , false ) ; |
519cb848 SC |
752 | break ; |
753 | } | |
754 | ||
755 | if( parent->IsKindOf( CLASSINFO( wxNotebook ) ) || parent->IsKindOf( CLASSINFO( wxTabCtrl ) )) | |
756 | { | |
757 | if ( ((wxControl*)parent)->m_macControl ) | |
758 | SetUpControlBackground( ((wxControl*)parent)->m_macControl , -1 , true ) ; | |
759 | break ; | |
760 | } | |
761 | ||
762 | parent = parent->GetParent() ; | |
763 | } | |
27419164 | 764 | |
519cb848 | 765 | UMADrawControl( m_macControl ) ; |
72055702 | 766 | ::SetThemeWindowBackground( win->MacGetWindowData()->m_macWindow , win->MacGetWindowData()->m_macWindowBackgroundTheme , false ) ; |
519cb848 SC |
767 | } |
768 | } | |
769 | } | |
770 | else | |
771 | { | |
e7549107 | 772 | // wxWindow::OnPaint( event ) ; |
519cb848 SC |
773 | } |
774 | } | |
51abe921 SC |
775 | void wxControl::OnEraseBackground(wxEraseEvent& event) |
776 | { | |
777 | // In general, you don't want to erase the background of a control, | |
778 | // or you'll get a flicker. | |
779 | // TODO: move this 'null' function into each control that | |
780 | // might flicker. | |
781 | } | |
782 | ||
519cb848 SC |
783 | |
784 | void wxControl::OnKeyDown( wxKeyEvent &event ) | |
785 | { | |
786 | if ( m_macControl == NULL ) | |
787 | return ; | |
788 | ||
789 | EventRecord *ev = wxTheApp->MacGetCurrentEvent() ; | |
790 | short keycode ; | |
791 | short keychar ; | |
792 | keychar = short(ev->message & charCodeMask); | |
793 | keycode = short(ev->message & keyCodeMask) >> 8 ; | |
794 | ||
72055702 | 795 | ::HandleControlKey( m_macControl , keycode , keychar , ev->modifiers ) ; |
519cb848 SC |
796 | } |
797 | ||
798 | void wxControl::OnMouseEvent( wxMouseEvent &event ) | |
799 | { | |
800 | if ( m_macControl == NULL ) | |
801 | { | |
802 | event.Skip() ; | |
803 | return ; | |
804 | } | |
805 | ||
2f1ae414 | 806 | if (event.GetEventType() == wxEVT_LEFT_DOWN || event.GetEventType() == wxEVT_LEFT_DCLICK ) |
519cb848 SC |
807 | { |
808 | ||
809 | int x = event.m_x ; | |
810 | int y = event.m_y ; | |
811 | ||
812 | MacClientToRootWindow( &x , &y ) ; | |
813 | ||
814 | ControlHandle control ; | |
815 | Point localwhere ; | |
519cb848 SC |
816 | SInt16 controlpart ; |
817 | WindowRef window = GetMacRootWindow() ; | |
818 | ||
819 | localwhere.h = x ; | |
820 | localwhere.v = y ; | |
821 | ||
822 | short modifiers = 0; | |
823 | ||
824 | if ( !event.m_leftDown && !event.m_rightDown ) | |
825 | modifiers |= btnState ; | |
826 | ||
827 | if ( event.m_shiftDown ) | |
828 | modifiers |= shiftKey ; | |
829 | ||
830 | if ( event.m_controlDown ) | |
831 | modifiers |= controlKey ; | |
832 | ||
833 | if ( event.m_altDown ) | |
834 | modifiers |= optionKey ; | |
835 | ||
836 | if ( event.m_metaDown ) | |
837 | modifiers |= cmdKey ; | |
f78024a1 | 838 | /* |
892e461e | 839 | #if TARGET_CARBON |
280df085 | 840 | control = FindControlUnderMouse( localwhere , window , &controlpart ) ; |
892e461e | 841 | #else |
892e461e SC |
842 | controlpart = FindControl( localwhere , window , &control ) ; |
843 | #endif | |
f78024a1 | 844 | */ |
519cb848 | 845 | { |
7810c95b | 846 | /* |
519cb848 SC |
847 | if ( AcceptsFocus() && FindFocus() != this ) |
848 | { | |
849 | SetFocus() ; | |
850 | } | |
7810c95b | 851 | */ |
f78024a1 | 852 | control = m_macControl ; |
72055702 | 853 | if ( control && ::IsControlActive( control ) ) |
519cb848 SC |
854 | { |
855 | { | |
f78024a1 | 856 | controlpart = ::HandleControlClick( control , localwhere , modifiers , (ControlActionUPP) -1 ) ; |
519cb848 | 857 | wxTheApp->s_lastMouseDown = 0 ; |
abfe4a84 | 858 | if ( control && controlpart != kControlNoPart && |
f78024a1 SC |
859 | ! IsKindOf( CLASSINFO( wxScrollBar ) ) |
860 | ) // otherwise we will get the event twice for scrollbar | |
519cb848 | 861 | { |
f78024a1 | 862 | MacHandleControlClick( control , controlpart ) ; |
519cb848 SC |
863 | } |
864 | } | |
865 | } | |
866 | } | |
867 | } | |
868 | } | |
869 | ||
870 | bool wxControl::MacCanFocus() const | |
871 | { | |
872 | { if ( m_macControl == NULL ) | |
873 | return true ; | |
874 | else | |
875 | return false ; | |
876 | } | |
877 | } | |
878 | ||
879 | void wxControl::MacHandleControlClick( ControlHandle control , SInt16 controlpart ) | |
880 | { | |
881 | wxASSERT_MSG( m_macControl != NULL , "No valid mac control" ) ; | |
882 | } | |
883 |