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