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