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