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