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