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