]>
Commit | Line | Data |
---|---|---|
e9576ca5 SC |
1 | ///////////////////////////////////////////////////////////////////////////// |
2 | // Name: control.cpp | |
3 | // Purpose: wxControl class | |
a31a5f85 | 4 | // Author: Stefan Csomor |
e9576ca5 | 5 | // Modified by: |
a31a5f85 | 6 | // Created: 1998-01-01 |
e9576ca5 | 7 | // RCS-ID: $Id$ |
a31a5f85 | 8 | // Copyright: (c) Stefan Csomor |
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 ) |
89ebf1c9 | 39 | EVT_PAINT( wxControl::OnPaint ) |
e9576ca5 | 40 | END_EVENT_TABLE() |
2f1ae414 | 41 | #endif |
e9576ca5 | 42 | |
d497dca4 | 43 | #include "wx/mac/uma.h" |
7372fd0a | 44 | #include "wx/mac/private.h" |
519cb848 | 45 | |
e9576ca5 | 46 | // Item members |
519cb848 | 47 | |
17a2c5a1 SC |
48 | |
49 | #if PRAGMA_STRUCT_ALIGN | |
50 | #pragma options align=mac68k | |
51 | #elif PRAGMA_STRUCT_PACKPUSH | |
52 | #pragma pack(push, 2) | |
53 | #elif PRAGMA_STRUCT_PACK | |
54 | #pragma pack(2) | |
55 | #endif | |
56 | ||
57 | typedef struct { | |
58 | unsigned short instruction; | |
59 | void (*function)(); | |
60 | } cdefRec, *cdefPtr, **cdefHandle; | |
61 | ||
62 | #if PRAGMA_STRUCT_ALIGN | |
63 | #pragma options align=reset | |
64 | #elif PRAGMA_STRUCT_PACKPUSH | |
65 | #pragma pack(pop) | |
66 | #elif PRAGMA_STRUCT_PACK | |
67 | #pragma pack() | |
68 | #endif | |
69 | ||
519cb848 | 70 | ControlActionUPP wxMacLiveScrollbarActionUPP = NULL ; |
17a2c5a1 | 71 | wxControl *wxFindControlFromMacControl(ControlHandle inControl ) ; |
519cb848 | 72 | |
2f1ae414 | 73 | pascal void wxMacLiveScrollbarActionProc( ControlHandle control , ControlPartCode partCode ) ; |
519cb848 SC |
74 | pascal void wxMacLiveScrollbarActionProc( ControlHandle control , ControlPartCode partCode ) |
75 | { | |
89ebf1c9 RR |
76 | if ( partCode != 0) |
77 | { | |
78 | wxControl* wx = (wxControl*) GetControlReference( control ) ; | |
79 | if ( wx ) | |
80 | { | |
4b26b60f | 81 | wx->MacHandleControlClick( control , partCode , true /* stillDown */ ) ; |
89ebf1c9 RR |
82 | } |
83 | } | |
519cb848 SC |
84 | } |
85 | ||
692f921a | 86 | ControlColorUPP wxMacSetupControlBackgroundUPP = NULL ; |
17a2c5a1 SC |
87 | ControlDefUPP wxMacControlActionUPP = NULL ; |
88 | ||
eb22f2a6 | 89 | pascal SInt32 wxMacControlDefinition(SInt16 varCode, ControlRef theControl, ControlDefProcMessage message, SInt32 param) |
17a2c5a1 SC |
90 | { |
91 | ||
e40298d5 JS |
92 | wxControl* wx = (wxControl*) wxFindControlFromMacControl( theControl ) ; |
93 | if ( wx != NULL && wx->IsKindOf( CLASSINFO( wxControl ) ) ) | |
94 | { | |
95 | if( message == drawCntl ) | |
96 | { | |
97 | wxMacWindowClipper clip( wx ) ; | |
98 | return InvokeControlDefUPP( varCode , theControl , message , param , (ControlDefUPP) wx->MacGetControlAction() ) ; | |
99 | } | |
100 | else | |
101 | return InvokeControlDefUPP( varCode , theControl , message , param , (ControlDefUPP) wx->MacGetControlAction() ) ; | |
102 | } | |
103 | return NULL ; | |
17a2c5a1 | 104 | } |
692f921a SC |
105 | |
106 | pascal OSStatus wxMacSetupControlBackground( ControlRef iControl , SInt16 iMessage , SInt16 iDepth , Boolean iIsColor ) | |
107 | { | |
e40298d5 JS |
108 | OSStatus status = noErr ; |
109 | switch( iMessage ) | |
110 | { | |
111 | case kControlMsgSetUpBackground : | |
112 | { | |
113 | wxControl* wx = (wxControl*) GetControlReference( iControl ) ; | |
114 | if ( wx != NULL && wx->IsKindOf( CLASSINFO( wxControl ) ) ) | |
115 | { | |
116 | wxDC::MacSetupBackgroundForCurrentPort( wx->MacGetBackgroundBrush() ) ; | |
64820d33 | 117 | #if TARGET_CARBON |
e40298d5 JS |
118 | // under classic this would lead to partial redraws |
119 | RgnHandle clip = NewRgn() ; | |
120 | int x = 0 , y = 0; | |
121 | ||
122 | wx->MacWindowToRootWindow( &x,&y ) ; | |
123 | CopyRgn( (RgnHandle) wx->MacGetVisibleRegion(false).GetWXHRGN() , clip ) ; | |
124 | OffsetRgn( clip , x , y ) ; | |
125 | SetClip( clip ) ; | |
126 | DisposeRgn( clip ) ; | |
64820d33 | 127 | #endif |
e40298d5 JS |
128 | } |
129 | else | |
130 | { | |
131 | status = paramErr ; | |
132 | } | |
133 | } | |
134 | break ; | |
135 | default : | |
136 | status = paramErr ; | |
137 | break ; | |
138 | } | |
139 | return status ; | |
692f921a SC |
140 | } |
141 | ||
e9576ca5 SC |
142 | wxControl::wxControl() |
143 | { | |
89ebf1c9 | 144 | m_macControl = NULL ; |
17a2c5a1 | 145 | m_macControlAction = NULL ; |
89ebf1c9 RR |
146 | m_macHorizontalBorder = 0 ; // additional pixels around the real control |
147 | m_macVerticalBorder = 0 ; | |
e9576ca5 SC |
148 | m_backgroundColour = *wxWHITE; |
149 | m_foregroundColour = *wxBLACK; | |
519cb848 | 150 | |
89ebf1c9 RR |
151 | if ( wxMacLiveScrollbarActionUPP == NULL ) |
152 | { | |
4114d0af | 153 | #if defined(UNIVERSAL_INTERFACES_VERSION) && (UNIVERSAL_INTERFACES_VERSION >= 0x0340) |
03e11df5 GD |
154 | wxMacLiveScrollbarActionUPP = NewControlActionUPP( wxMacLiveScrollbarActionProc ); |
155 | #else | |
89ebf1c9 | 156 | wxMacLiveScrollbarActionUPP = NewControlActionProc( wxMacLiveScrollbarActionProc ) ; |
03e11df5 | 157 | #endif |
89ebf1c9 | 158 | } |
e9576ca5 SC |
159 | } |
160 | ||
2f1ae414 SC |
161 | bool wxControl::Create(wxWindow *parent, wxWindowID id, |
162 | const wxPoint& pos, | |
163 | const wxSize& size, long style, | |
164 | const wxValidator& validator, | |
165 | const wxString& name) | |
166 | { | |
89ebf1c9 RR |
167 | m_macControl = NULL ; |
168 | m_macHorizontalBorder = 0 ; // additional pixels around the real control | |
169 | m_macVerticalBorder = 0 ; | |
327788ac | 170 | |
2f1ae414 | 171 | bool rval = wxWindow::Create(parent, id, pos, size, style, name); |
327788ac SC |
172 | if ( parent ) |
173 | { | |
174 | m_backgroundColour = parent->GetBackgroundColour() ; | |
175 | m_foregroundColour = parent->GetForegroundColour() ; | |
176 | } | |
2f1ae414 SC |
177 | if (rval) { |
178 | #if wxUSE_VALIDATORS | |
179 | SetValidator(validator); | |
180 | #endif | |
181 | } | |
182 | return rval; | |
183 | } | |
184 | ||
e9576ca5 SC |
185 | wxControl::~wxControl() |
186 | { | |
e7549107 | 187 | m_isBeingDeleted = TRUE; |
17a2c5a1 | 188 | wxRemoveMacControlAssociation( this ) ; |
e9576ca5 SC |
189 | // If we delete an item, we should initialize the parent panel, |
190 | // because it could now be invalid. | |
9c641c05 SC |
191 | wxWindow *parent = GetParent() ; |
192 | if ( parent ) | |
e9576ca5 | 193 | { |
9c641c05 SC |
194 | if (parent->GetDefaultItem() == (wxButton*) this) |
195 | parent->SetDefaultItem(NULL); | |
e9576ca5 | 196 | } |
76a5e5d2 | 197 | if ( (ControlHandle) m_macControl ) |
519cb848 | 198 | { |
76a5e5d2 | 199 | ::DisposeControl( (ControlHandle) m_macControl ) ; |
89ebf1c9 | 200 | m_macControl = NULL ; |
519cb848 | 201 | } |
e9576ca5 SC |
202 | } |
203 | ||
e7549107 | 204 | void wxControl::SetLabel(const wxString& title) |
e9576ca5 | 205 | { |
28c98a77 | 206 | m_label = wxStripMenuCodes(title) ; |
89ebf1c9 | 207 | |
427ff662 | 208 | if ( m_macControl ) |
89ebf1c9 | 209 | { |
427ff662 | 210 | UMASetControlTitle( (ControlHandle) m_macControl , m_label ) ; |
89ebf1c9 RR |
211 | } |
212 | Refresh() ; | |
e9576ca5 SC |
213 | } |
214 | ||
37e2cb08 | 215 | wxSize wxControl::DoGetBestSize() const |
e9576ca5 | 216 | { |
89ebf1c9 RR |
217 | Rect bestsize = { 0 , 0 , 0 , 0 } ; |
218 | short baselineoffset ; | |
219 | int bestWidth, bestHeight ; | |
76a5e5d2 | 220 | ::GetBestControlRect( (ControlHandle) m_macControl , &bestsize , &baselineoffset ) ; |
89ebf1c9 RR |
221 | |
222 | if ( EmptyRect( &bestsize ) ) | |
223 | { | |
224 | baselineoffset = 0; | |
225 | bestsize.left = bestsize.top = 0 ; | |
226 | bestsize.right = 16 ; | |
227 | bestsize.bottom = 16 ; | |
228 | if ( IsKindOf( CLASSINFO( wxScrollBar ) ) ) | |
229 | { | |
230 | bestsize.bottom = 16 ; | |
231 | } | |
232 | else if ( IsKindOf( CLASSINFO( wxSpinButton ) ) ) | |
233 | { | |
234 | bestsize.bottom = 24 ; | |
235 | } | |
236 | } | |
237 | ||
238 | if ( IsKindOf( CLASSINFO( wxButton ) ) ) | |
239 | { | |
240 | bestWidth = m_label.Length() * 8 + 12 ; | |
241 | if ( bestWidth < 70 ) | |
242 | bestWidth = 70 ; | |
243 | } | |
244 | else if ( IsKindOf( CLASSINFO( wxStaticText ) ) ) | |
245 | { | |
246 | bestWidth = m_label.Length() * 8 ; | |
247 | } | |
248 | else | |
249 | bestWidth = bestsize.right - bestsize.left ; | |
250 | ||
251 | bestWidth += 2 * m_macHorizontalBorder ; | |
252 | ||
253 | bestHeight = bestsize.bottom - bestsize.top ; | |
254 | if ( bestHeight < 10 ) | |
255 | bestHeight = 13 ; | |
256 | ||
257 | bestHeight += 2 * m_macVerticalBorder; | |
258 | ||
259 | ||
9453cf2b | 260 | return wxSize(bestWidth, bestHeight); |
e9576ca5 SC |
261 | } |
262 | ||
e7549107 | 263 | bool wxControl::ProcessCommand (wxCommandEvent & event) |
e9576ca5 | 264 | { |
a3bf7524 VS |
265 | // Tries: |
266 | // 1) OnCommand, starting at this window and working up parent hierarchy | |
267 | // 2) OnCommand then calls ProcessEvent to search the event tables. | |
268 | return GetEventHandler()->ProcessEvent(event); | |
e9576ca5 SC |
269 | } |
270 | ||
519cb848 SC |
271 | // ------------------------ |
272 | wxList *wxWinMacControlList = NULL; | |
273 | wxControl *wxFindControlFromMacControl(ControlHandle inControl ) | |
274 | { | |
275 | wxNode *node = wxWinMacControlList->Find((long)inControl); | |
276 | if (!node) | |
277 | return NULL; | |
eb22f2a6 | 278 | return (wxControl *)node->GetData(); |
519cb848 SC |
279 | } |
280 | ||
281 | void wxAssociateControlWithMacControl(ControlHandle inControl, wxControl *control) | |
282 | { | |
283 | // adding NULL WindowRef is (first) surely a result of an error and | |
284 | // (secondly) breaks menu command processing | |
427ff662 | 285 | wxCHECK_RET( inControl != (ControlHandle) NULL, wxT("attempt to add a NULL WindowRef to window list") ); |
519cb848 SC |
286 | |
287 | if ( !wxWinMacControlList->Find((long)inControl) ) | |
288 | wxWinMacControlList->Append((long)inControl, control); | |
289 | } | |
290 | ||
291 | void wxRemoveMacControlAssociation(wxControl *control) | |
292 | { | |
293 | wxWinMacControlList->DeleteObject(control); | |
294 | } | |
295 | ||
296 | void wxControl::MacPreControlCreate( wxWindow *parent, wxWindowID id, wxString label , | |
89ebf1c9 RR |
297 | const wxPoint& pos, |
298 | const wxSize& size, long style, | |
299 | const wxValidator& validator, | |
76a5e5d2 | 300 | const wxString& name , WXRECTPTR outBounds , unsigned char* maclabel ) |
519cb848 | 301 | { |
89ebf1c9 | 302 | m_label = label ; |
9453cf2b | 303 | |
b45ed7a2 | 304 | // These sizes will be adjusted in MacPostControlCreate |
89ebf1c9 RR |
305 | m_width = size.x ; |
306 | m_height = size.y ; | |
307 | m_x = pos.x ; | |
308 | m_y = pos.y ; | |
309 | ||
76a5e5d2 SC |
310 | ((Rect*)outBounds)->top = -10; |
311 | ((Rect*)outBounds)->left = -10; | |
312 | ((Rect*)outBounds)->bottom = 0; | |
313 | ((Rect*)outBounds)->right = 0; | |
89ebf1c9 | 314 | |
c5c9378c | 315 | wxMacStringToPascal( wxStripMenuCodes(label) , maclabel ) ; |
519cb848 SC |
316 | } |
317 | ||
318 | void wxControl::MacPostControlCreate() | |
319 | { | |
427ff662 | 320 | wxASSERT_MSG( (ControlHandle) m_macControl != NULL , wxT("No valid mac control") ) ; |
89ebf1c9 RR |
321 | |
322 | if ( IsKindOf( CLASSINFO( wxScrollBar ) ) ) | |
323 | { | |
324 | // no font | |
325 | } | |
2d9d0118 | 326 | else if ( !UMAHasAquaLayout() && (IsKindOf( CLASSINFO( wxStaticBox ) ) || IsKindOf( CLASSINFO( wxRadioBox ) ) || IsKindOf( CLASSINFO( wxButton ) ) ) ) |
89ebf1c9 RR |
327 | { |
328 | ControlFontStyleRec controlstyle ; | |
329 | controlstyle.flags = kControlUseFontMask ; | |
330 | controlstyle.font = kControlFontSmallBoldSystemFont ; | |
331 | ||
76a5e5d2 | 332 | ::SetControlFontStyle( (ControlHandle) m_macControl , &controlstyle ) ; |
89ebf1c9 RR |
333 | } |
334 | else | |
335 | { | |
336 | ControlFontStyleRec controlstyle ; | |
337 | controlstyle.flags = kControlUseFontMask ; | |
4b26b60f SC |
338 | |
339 | if (IsKindOf( CLASSINFO( wxButton ) ) ) | |
340 | controlstyle.font = kControlFontSmallSystemFont ; // eventually kControlFontBigSystemFont ; | |
341 | else | |
342 | controlstyle.font = kControlFontSmallSystemFont ; | |
89ebf1c9 | 343 | |
76a5e5d2 | 344 | ::SetControlFontStyle( (ControlHandle) m_macControl , &controlstyle ) ; |
89ebf1c9 | 345 | } |
76a5e5d2 | 346 | ControlHandle container = (ControlHandle) GetParent()->MacGetContainerForEmbedding() ; |
89ebf1c9 | 347 | wxASSERT_MSG( container != NULL , wxT("No valid mac container control") ) ; |
76a5e5d2 | 348 | ::EmbedControl( (ControlHandle) m_macControl , container ) ; |
89ebf1c9 RR |
349 | m_macControlIsShown = true ; |
350 | ||
76a5e5d2 | 351 | wxAssociateControlWithMacControl( (ControlHandle) m_macControl , this ) ; |
e40298d5 JS |
352 | if ( wxMacSetupControlBackgroundUPP == NULL ) |
353 | { | |
354 | wxMacSetupControlBackgroundUPP = NewControlColorUPP( wxMacSetupControlBackground ) ; | |
355 | } | |
356 | if ( wxMacControlActionUPP == NULL ) | |
357 | { | |
358 | wxMacControlActionUPP = NewControlDefUPP( wxMacControlDefinition ) ; | |
359 | } | |
111c1e2c JS |
360 | // The following block of code is responsible for crashes when switching |
361 | // back to windows, which can be seen in the dialogs sample. | |
362 | // It is disabled until a proper solution can be found. | |
363 | #if 0 | |
17a2c5a1 | 364 | #if TARGET_CARBON |
b6f5f27a SC |
365 | /* |
366 | only working under classic carbon | |
17a2c5a1 SC |
367 | m_macControlAction = *(**(ControlHandle)m_macControl).contrlDefProc ; |
368 | (**(ControlHandle)m_macControl).contrlDefProc = (Handle) &wxMacControlActionUPP ; | |
b6f5f27a | 369 | */ |
17a2c5a1 SC |
370 | #else |
371 | m_macControlAction = *(**(ControlHandle)m_macControl).contrlDefProc ; | |
372 | ||
373 | cdefHandle cdef ; | |
374 | cdef = (cdefHandle) NewHandle( sizeof(cdefRec) ) ; | |
375 | if ( (**(ControlHandle)m_macControl).contrlDefProc != NULL ) | |
376 | { | |
e40298d5 JS |
377 | (**cdef).instruction = 0x4EF9; /* JMP instruction */ |
378 | (**cdef).function = (void(*)()) wxMacControlActionUPP; | |
379 | (**(ControlHandle)m_macControl).contrlDefProc = (Handle) cdef ; | |
17a2c5a1 | 380 | } |
111c1e2c | 381 | #endif |
17a2c5a1 | 382 | #endif |
e40298d5 JS |
383 | SetControlColorProc( (ControlHandle) m_macControl , wxMacSetupControlBackgroundUPP ) ; |
384 | ||
385 | // Adjust the controls size and position | |
386 | wxPoint pos(m_x, m_y); | |
387 | wxSize best_size( DoGetBestSize() ); | |
388 | wxSize new_size( m_width, m_height ); | |
389 | ||
390 | m_x = m_y = m_width = m_height = -1; // Forces SetSize to move/size the control | |
391 | ||
392 | if (new_size.x == -1) { | |
9453cf2b | 393 | new_size.x = best_size.x; |
e40298d5 JS |
394 | } |
395 | if (new_size.y == -1) { | |
396 | new_size.y = best_size.y; | |
397 | } | |
398 | ||
399 | SetSize(pos.x, pos.y, new_size.x, new_size.y); | |
400 | ||
427ff662 SC |
401 | #if wxUSE_UNICODE |
402 | UMASetControlTitle( (ControlHandle) m_macControl , wxStripMenuCodes(m_label) ) ; | |
403 | #endif | |
404 | ||
e40298d5 JS |
405 | UMAShowControl( (ControlHandle) m_macControl ) ; |
406 | ||
407 | SetCursor( *wxSTANDARD_CURSOR ) ; | |
408 | ||
409 | Refresh() ; | |
519cb848 SC |
410 | } |
411 | ||
412 | void wxControl::MacAdjustControlRect() | |
413 | { | |
76a5e5d2 | 414 | wxASSERT_MSG( (ControlHandle) m_macControl != NULL , wxT("No valid mac control") ) ; |
89ebf1c9 RR |
415 | if ( m_width == -1 || m_height == -1 ) |
416 | { | |
417 | Rect bestsize = { 0 , 0 , 0 , 0 } ; | |
418 | short baselineoffset ; | |
419 | ||
76a5e5d2 | 420 | ::GetBestControlRect( (ControlHandle) m_macControl , &bestsize , &baselineoffset ) ; |
89ebf1c9 RR |
421 | |
422 | if ( EmptyRect( &bestsize ) ) | |
423 | { | |
424 | baselineoffset = 0; | |
425 | bestsize.left = bestsize.top = 0 ; | |
426 | bestsize.right = 16 ; | |
427 | bestsize.bottom = 16 ; | |
428 | if ( IsKindOf( CLASSINFO( wxScrollBar ) ) ) | |
429 | { | |
430 | bestsize.bottom = 16 ; | |
431 | } | |
432 | else if ( IsKindOf( CLASSINFO( wxSpinButton ) ) ) | |
433 | { | |
434 | bestsize.bottom = 24 ; | |
435 | } | |
436 | } | |
437 | ||
438 | if ( m_width == -1 ) | |
439 | { | |
440 | if ( IsKindOf( CLASSINFO( wxButton ) ) ) | |
441 | { | |
442 | m_width = m_label.Length() * 8 + 12 ; | |
443 | if ( m_width < 70 ) | |
444 | m_width = 70 ; | |
445 | } | |
446 | else if ( IsKindOf( CLASSINFO( wxStaticText ) ) ) | |
447 | { | |
448 | m_width = m_label.Length() * 8 ; | |
449 | } | |
450 | else | |
451 | m_width = bestsize.right - bestsize.left ; | |
452 | ||
327788ac | 453 | m_width += 2 * m_macHorizontalBorder + MacGetLeftBorderSize() + MacGetRightBorderSize() ; |
89ebf1c9 RR |
454 | } |
455 | if ( m_height == -1 ) | |
456 | { | |
457 | m_height = bestsize.bottom - bestsize.top ; | |
458 | if ( m_height < 10 ) | |
459 | m_height = 13 ; | |
460 | ||
327788ac | 461 | m_height += 2 * m_macVerticalBorder + MacGetTopBorderSize() + MacGetBottomBorderSize() ; |
89ebf1c9 | 462 | } |
e40298d5 | 463 | MacUpdateDimensions() ; |
327788ac | 464 | // UMASizeControl( (ControlHandle) m_macControl , m_width - 2 * m_macHorizontalBorder, m_height - 2 * m_macVerticalBorder ) ; |
89ebf1c9 | 465 | } |
519cb848 | 466 | } |
76a5e5d2 SC |
467 | |
468 | WXWidget wxControl::MacGetContainerForEmbedding() | |
519cb848 | 469 | { |
89ebf1c9 RR |
470 | if ( m_macControl ) |
471 | return m_macControl ; | |
519cb848 | 472 | |
89ebf1c9 | 473 | return wxWindow::MacGetContainerForEmbedding() ; |
519cb848 SC |
474 | } |
475 | ||
327788ac | 476 | void wxControl::MacUpdateDimensions() |
519cb848 | 477 | { |
e40298d5 JS |
478 | // actually in the current systems this should never be possible, but later reparenting |
479 | // may become a reality | |
480 | ||
481 | if ( (ControlHandle) m_macControl == NULL ) | |
482 | return ; | |
483 | ||
484 | if ( GetParent() == NULL ) | |
485 | return ; | |
486 | ||
327788ac SC |
487 | WindowRef rootwindow = (WindowRef) MacGetRootWindow() ; |
488 | if ( rootwindow == NULL ) | |
e40298d5 JS |
489 | return ; |
490 | ||
327788ac SC |
491 | Rect oldBounds ; |
492 | GetControlBounds( (ControlHandle) m_macControl , &oldBounds ) ; | |
493 | ||
494 | int new_x = m_x + MacGetLeftBorderSize() + m_macHorizontalBorder ; | |
495 | int new_y = m_y + MacGetTopBorderSize() + m_macVerticalBorder ; | |
496 | int new_width = m_width - MacGetLeftBorderSize() - MacGetRightBorderSize() - 2 * m_macHorizontalBorder ; | |
497 | int new_height = m_height - MacGetTopBorderSize() - MacGetBottomBorderSize() - 2 * m_macVerticalBorder ; | |
498 | ||
499 | GetParent()->MacWindowToRootWindow( & new_x , & new_y ) ; | |
500 | bool doMove = new_x != oldBounds.left || new_y != oldBounds.top ; | |
501 | bool doResize = ( oldBounds.right - oldBounds.left ) != new_width || (oldBounds.bottom - oldBounds.top ) != new_height ; | |
e40298d5 JS |
502 | if ( doMove || doResize ) |
503 | { | |
504 | InvalWindowRect( rootwindow, &oldBounds ) ; | |
505 | if ( doMove ) | |
506 | { | |
507 | UMAMoveControl( (ControlHandle) m_macControl , new_x , new_y ) ; | |
508 | } | |
509 | if ( doResize ) | |
510 | { | |
511 | UMASizeControl( (ControlHandle) m_macControl , new_width , new_height ) ; | |
512 | } | |
513 | } | |
327788ac | 514 | } |
89ebf1c9 | 515 | |
327788ac SC |
516 | void wxControl::MacSuperChangedPosition() |
517 | { | |
e40298d5 | 518 | MacUpdateDimensions() ; |
89ebf1c9 | 519 | wxWindow::MacSuperChangedPosition() ; |
519cb848 SC |
520 | } |
521 | ||
522 | void wxControl::MacSuperEnabled( bool enabled ) | |
523 | { | |
1c469f7f | 524 | Refresh(FALSE) ; |
1c310985 | 525 | wxWindow::MacSuperEnabled( enabled ) ; |
519cb848 SC |
526 | } |
527 | ||
e40298d5 | 528 | void wxControl::MacSuperShown( bool show ) |
519cb848 | 529 | { |
76a5e5d2 | 530 | if ( (ControlHandle) m_macControl ) |
89ebf1c9 RR |
531 | { |
532 | if ( !show ) | |
533 | { | |
534 | if ( m_macControlIsShown ) | |
535 | { | |
76a5e5d2 | 536 | ::UMAHideControl( (ControlHandle) m_macControl ) ; |
89ebf1c9 RR |
537 | m_macControlIsShown = false ; |
538 | } | |
539 | } | |
540 | else | |
541 | { | |
542 | if ( MacIsReallyShown() && !m_macControlIsShown ) | |
543 | { | |
76a5e5d2 | 544 | ::UMAShowControl( (ControlHandle) m_macControl ) ; |
89ebf1c9 RR |
545 | m_macControlIsShown = true ; |
546 | } | |
547 | } | |
548 | } | |
549 | ||
550 | wxWindow::MacSuperShown( show ) ; | |
519cb848 SC |
551 | } |
552 | ||
553 | void wxControl::DoSetSize(int x, int y, | |
554 | int width, int height, | |
555 | int sizeFlags ) | |
556 | { | |
327788ac | 557 | wxWindow::DoSetSize( x , y ,width , height ,sizeFlags ) ; |
64820d33 SC |
558 | #if 0 |
559 | { | |
e40298d5 JS |
560 | Rect meta , control ; |
561 | GetControlBounds( (ControlHandle) m_macControl , &control ) ; | |
562 | RgnHandle rgn = NewRgn() ; | |
563 | GetControlRegion( (ControlHandle) m_macControl , kControlStructureMetaPart , rgn ) ; | |
564 | GetRegionBounds( rgn , &meta ) ; | |
565 | if ( !EmptyRect( &meta ) ) | |
566 | { | |
567 | wxASSERT( meta.left >= control.left - m_macHorizontalBorder ) ; | |
568 | wxASSERT( meta.right <= control.right + m_macHorizontalBorder ) ; | |
569 | wxASSERT( meta.top >= control.top - m_macVerticalBorder ) ; | |
570 | wxASSERT( meta.bottom <= control.bottom + m_macVerticalBorder ) ; | |
571 | } | |
572 | DisposeRgn( rgn ) ; | |
64820d33 SC |
573 | } |
574 | #endif | |
327788ac | 575 | return ; |
519cb848 SC |
576 | } |
577 | ||
519cb848 SC |
578 | bool wxControl::Show(bool show) |
579 | { | |
89ebf1c9 RR |
580 | if ( !wxWindow::Show( show ) ) |
581 | return FALSE ; | |
582 | ||
76a5e5d2 | 583 | if ( (ControlHandle) m_macControl ) |
89ebf1c9 RR |
584 | { |
585 | if ( !show ) | |
586 | { | |
587 | if ( m_macControlIsShown ) | |
588 | { | |
76a5e5d2 | 589 | ::UMAHideControl( (ControlHandle) m_macControl ) ; |
89ebf1c9 RR |
590 | m_macControlIsShown = false ; |
591 | } | |
592 | } | |
593 | else | |
594 | { | |
595 | if ( MacIsReallyShown() && !m_macControlIsShown ) | |
596 | { | |
76a5e5d2 | 597 | ::UMAShowControl( (ControlHandle) m_macControl ) ; |
89ebf1c9 RR |
598 | m_macControlIsShown = true ; |
599 | } | |
600 | } | |
601 | } | |
602 | return TRUE ; | |
519cb848 SC |
603 | } |
604 | ||
e7549107 | 605 | bool wxControl::Enable(bool enable) |
519cb848 | 606 | { |
e7549107 SC |
607 | if ( !wxWindow::Enable(enable) ) |
608 | return FALSE; | |
519cb848 | 609 | |
76a5e5d2 | 610 | if ( (ControlHandle) m_macControl ) |
89ebf1c9 RR |
611 | { |
612 | if ( enable ) | |
76a5e5d2 | 613 | UMAActivateControl( (ControlHandle) m_macControl ) ; |
89ebf1c9 | 614 | else |
76a5e5d2 | 615 | UMADeactivateControl( (ControlHandle) m_macControl ) ; |
89ebf1c9 RR |
616 | } |
617 | return TRUE ; | |
519cb848 SC |
618 | } |
619 | ||
620 | void wxControl::Refresh(bool eraseBack, const wxRect *rect) | |
621 | { | |
89ebf1c9 | 622 | wxWindow::Refresh( eraseBack , rect ) ; |
519cb848 SC |
623 | } |
624 | ||
2f1ae414 SC |
625 | void wxControl::MacRedrawControl() |
626 | { | |
404dfcae | 627 | if ( (ControlHandle) m_macControl && MacGetRootWindow() && m_macControlIsShown ) |
89ebf1c9 | 628 | { |
de043984 SC |
629 | wxClientDC dc(this) ; |
630 | wxMacPortSetter helper(&dc) ; | |
17a2c5a1 | 631 | wxMacWindowClipper clipper(this) ; |
de043984 | 632 | wxDC::MacSetupBackgroundForCurrentPort( MacGetBackgroundBrush() ) ; |
76a5e5d2 | 633 | UMADrawControl( (ControlHandle) m_macControl ) ; |
89ebf1c9 | 634 | } |
2f1ae414 SC |
635 | } |
636 | ||
519cb848 SC |
637 | void wxControl::OnPaint(wxPaintEvent& event) |
638 | { | |
76a5e5d2 | 639 | if ( (ControlHandle) m_macControl ) |
89ebf1c9 | 640 | { |
de043984 SC |
641 | wxPaintDC dc(this) ; |
642 | wxMacPortSetter helper(&dc) ; | |
17a2c5a1 | 643 | wxMacWindowClipper clipper(this) ; |
de043984 | 644 | wxDC::MacSetupBackgroundForCurrentPort( MacGetBackgroundBrush() ) ; |
76a5e5d2 | 645 | UMADrawControl( (ControlHandle) m_macControl ) ; |
89ebf1c9 RR |
646 | } |
647 | else | |
648 | { | |
a5a8ff8a | 649 | event.Skip() ; |
89ebf1c9 | 650 | } |
519cb848 | 651 | } |
51abe921 SC |
652 | void wxControl::OnEraseBackground(wxEraseEvent& event) |
653 | { | |
1c310985 | 654 | wxWindow::OnEraseBackground( event ) ; |
51abe921 SC |
655 | } |
656 | ||
519cb848 SC |
657 | void wxControl::OnKeyDown( wxKeyEvent &event ) |
658 | { | |
76a5e5d2 | 659 | if ( (ControlHandle) m_macControl == NULL ) |
89ebf1c9 RR |
660 | return ; |
661 | ||
c5c9378c SC |
662 | #if TARGET_CARBON |
663 | ||
e40298d5 JS |
664 | char charCode ; |
665 | UInt32 keyCode ; | |
c5c9378c SC |
666 | UInt32 modifiers ; |
667 | ||
e40298d5 JS |
668 | GetEventParameter( (EventRef) wxTheApp->MacGetCurrentEvent(), kEventParamKeyMacCharCodes, typeChar, NULL,sizeof(char), NULL,&charCode ); |
669 | GetEventParameter( (EventRef) wxTheApp->MacGetCurrentEvent(), kEventParamKeyCode, typeUInt32, NULL, sizeof(UInt32), NULL, &keyCode ); | |
670 | GetEventParameter((EventRef) wxTheApp->MacGetCurrentEvent(), kEventParamKeyModifiers, typeUInt32, NULL, sizeof(UInt32), NULL, &modifiers); | |
c5c9378c SC |
671 | |
672 | ::HandleControlKey( (ControlHandle) m_macControl , keyCode , charCode , modifiers ) ; | |
e40298d5 | 673 | |
c5c9378c | 674 | #else |
76a5e5d2 | 675 | EventRecord *ev = (EventRecord*) wxTheApp->MacGetCurrentEvent() ; |
89ebf1c9 RR |
676 | short keycode ; |
677 | short keychar ; | |
678 | keychar = short(ev->message & charCodeMask); | |
679 | keycode = short(ev->message & keyCodeMask) >> 8 ; | |
680 | ||
76a5e5d2 | 681 | ::HandleControlKey( (ControlHandle) m_macControl , keycode , keychar , ev->modifiers ) ; |
c5c9378c | 682 | #endif |
519cb848 SC |
683 | } |
684 | ||
685 | void wxControl::OnMouseEvent( wxMouseEvent &event ) | |
686 | { | |
76a5e5d2 | 687 | if ( (ControlHandle) m_macControl == NULL ) |
89ebf1c9 RR |
688 | { |
689 | event.Skip() ; | |
690 | return ; | |
691 | } | |
692 | ||
693 | if (event.GetEventType() == wxEVT_LEFT_DOWN || event.GetEventType() == wxEVT_LEFT_DCLICK ) | |
694 | { | |
695 | ||
696 | int x = event.m_x ; | |
697 | int y = event.m_y ; | |
698 | ||
699 | MacClientToRootWindow( &x , &y ) ; | |
700 | ||
701 | ControlHandle control ; | |
702 | Point localwhere ; | |
703 | SInt16 controlpart ; | |
89ebf1c9 RR |
704 | |
705 | localwhere.h = x ; | |
706 | localwhere.v = y ; | |
707 | ||
708 | short modifiers = 0; | |
709 | ||
710 | if ( !event.m_leftDown && !event.m_rightDown ) | |
711 | modifiers |= btnState ; | |
712 | ||
713 | if ( event.m_shiftDown ) | |
714 | modifiers |= shiftKey ; | |
715 | ||
716 | if ( event.m_controlDown ) | |
717 | modifiers |= controlKey ; | |
718 | ||
719 | if ( event.m_altDown ) | |
720 | modifiers |= optionKey ; | |
721 | ||
722 | if ( event.m_metaDown ) | |
723 | modifiers |= cmdKey ; | |
89ebf1c9 | 724 | { |
76a5e5d2 | 725 | control = (ControlHandle) m_macControl ; |
89ebf1c9 RR |
726 | if ( control && ::IsControlActive( control ) ) |
727 | { | |
728 | { | |
729 | controlpart = ::HandleControlClick( control , localwhere , modifiers , (ControlActionUPP) -1 ) ; | |
730 | wxTheApp->s_lastMouseDown = 0 ; | |
4b26b60f | 731 | if ( control && controlpart != kControlNoPart ) |
89ebf1c9 | 732 | { |
4b26b60f | 733 | MacHandleControlClick( control , controlpart , false /* mouse not down anymore */ ) ; |
89ebf1c9 RR |
734 | } |
735 | } | |
736 | } | |
737 | } | |
738 | } | |
63d1f74f SC |
739 | else |
740 | { | |
741 | event.Skip() ; | |
742 | } | |
519cb848 SC |
743 | } |
744 | ||
745 | bool wxControl::MacCanFocus() const | |
746 | { | |
e40298d5 JS |
747 | if ( (ControlHandle) m_macControl == NULL ) |
748 | return true ; | |
749 | else | |
750 | return false ; | |
519cb848 SC |
751 | } |
752 | ||
4b26b60f | 753 | void wxControl::MacHandleControlClick( WXWidget control , wxInt16 controlpart , bool WXUNUSED( mouseStillDown ) ) |
519cb848 | 754 | { |
427ff662 | 755 | wxASSERT_MSG( (ControlHandle) m_macControl != NULL , wxT("No valid mac control") ) ; |
519cb848 SC |
756 | } |
757 |