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