]>
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 | |
9 | // Licence: wxWindows licence | |
10 | ///////////////////////////////////////////////////////////////////////////// | |
11 | ||
12 | #ifdef __GNUG__ | |
13 | #pragma implementation "control.h" | |
14 | #endif | |
15 | ||
16 | #include "wx/control.h" | |
03e11df5 GD |
17 | #include "wx/panel.h" |
18 | #include "wx/app.h" | |
5fde6fcc | 19 | #include "wx/dc.h" |
519cb848 SC |
20 | #include "wx/notebook.h" |
21 | #include "wx/tabctrl.h" | |
2f1ae414 | 22 | #include "wx/radiobox.h" |
519cb848 | 23 | #include "wx/spinbutt.h" |
03e11df5 GD |
24 | #include "wx/scrolbar.h" |
25 | #include "wx/button.h" | |
26 | #include "wx/dialog.h" | |
27 | #include "wx/statbox.h" | |
28 | #include "wx/sizer.h" | |
29 | #include "wx/stattext.h" | |
e9576ca5 | 30 | |
2f1ae414 | 31 | #if !USE_SHARED_LIBRARY |
8208e181 | 32 | IMPLEMENT_ABSTRACT_CLASS(wxControl, wxWindow) |
e9576ca5 | 33 | |
2f1ae414 | 34 | BEGIN_EVENT_TABLE(wxControl, wxWindow) |
519cb848 SC |
35 | EVT_MOUSE_EVENTS( wxControl::OnMouseEvent ) |
36 | EVT_CHAR( wxControl::OnKeyDown ) | |
37 | EVT_PAINT( wxControl::OnPaint ) | |
e9576ca5 | 38 | END_EVENT_TABLE() |
2f1ae414 | 39 | #endif |
e9576ca5 | 40 | |
519cb848 SC |
41 | #include <wx/mac/uma.h> |
42 | ||
e9576ca5 | 43 | // Item members |
519cb848 SC |
44 | |
45 | ControlActionUPP wxMacLiveScrollbarActionUPP = NULL ; | |
46 | ||
2f1ae414 | 47 | pascal void wxMacLiveScrollbarActionProc( ControlHandle control , ControlPartCode partCode ) ; |
519cb848 SC |
48 | pascal void wxMacLiveScrollbarActionProc( ControlHandle control , ControlPartCode partCode ) |
49 | { | |
50 | if ( partCode != 0) | |
51 | { | |
52 | wxControl* wx = (wxControl*) GetControlReference( control ) ; | |
53 | if ( wx ) | |
54 | { | |
55 | wx->MacHandleControlClick( control , partCode ) ; | |
56 | } | |
57 | } | |
58 | } | |
59 | ||
e9576ca5 SC |
60 | wxControl::wxControl() |
61 | { | |
2f1ae414 SC |
62 | m_macControl = NULL ; |
63 | m_macHorizontalBorder = 0 ; // additional pixels around the real control | |
64 | m_macVerticalBorder = 0 ; | |
e9576ca5 SC |
65 | m_backgroundColour = *wxWHITE; |
66 | m_foregroundColour = *wxBLACK; | |
e7549107 SC |
67 | #if WXWIN_COMPATIBILITY |
68 | m_callback = 0; | |
69 | #endif // WXWIN_COMPATIBILITY | |
519cb848 SC |
70 | |
71 | if ( wxMacLiveScrollbarActionUPP == NULL ) | |
72 | { | |
4114d0af | 73 | #if defined(UNIVERSAL_INTERFACES_VERSION) && (UNIVERSAL_INTERFACES_VERSION >= 0x0340) |
03e11df5 GD |
74 | wxMacLiveScrollbarActionUPP = NewControlActionUPP( wxMacLiveScrollbarActionProc ); |
75 | #else | |
519cb848 | 76 | wxMacLiveScrollbarActionUPP = NewControlActionProc( wxMacLiveScrollbarActionProc ) ; |
03e11df5 | 77 | #endif |
519cb848 | 78 | } |
e9576ca5 SC |
79 | } |
80 | ||
2f1ae414 SC |
81 | bool wxControl::Create(wxWindow *parent, wxWindowID id, |
82 | const wxPoint& pos, | |
83 | const wxSize& size, long style, | |
84 | const wxValidator& validator, | |
85 | const wxString& name) | |
86 | { | |
87 | m_macControl = NULL ; | |
88 | m_macHorizontalBorder = 0 ; // additional pixels around the real control | |
89 | m_macVerticalBorder = 0 ; | |
90 | bool rval = wxWindow::Create(parent, id, pos, size, style, name); | |
91 | if (rval) { | |
92 | #if wxUSE_VALIDATORS | |
93 | SetValidator(validator); | |
94 | #endif | |
95 | } | |
96 | return rval; | |
97 | } | |
98 | ||
e9576ca5 SC |
99 | wxControl::~wxControl() |
100 | { | |
e7549107 | 101 | m_isBeingDeleted = TRUE; |
e9576ca5 SC |
102 | // If we delete an item, we should initialize the parent panel, |
103 | // because it could now be invalid. | |
e7549107 SC |
104 | wxPanel *panel = wxDynamicCast(GetParent(), wxPanel); |
105 | if ( panel ) | |
e9576ca5 | 106 | { |
e7549107 SC |
107 | if (panel->GetDefaultItem() == (wxButton*) this) |
108 | panel->SetDefaultItem(NULL); | |
e9576ca5 | 109 | } |
519cb848 SC |
110 | if ( m_macControl ) |
111 | { | |
112 | UMADisposeControl( m_macControl ) ; | |
113 | m_macControl = NULL ; | |
114 | } | |
e9576ca5 SC |
115 | } |
116 | ||
e7549107 | 117 | void wxControl::SetLabel(const wxString& title) |
e9576ca5 | 118 | { |
e7549107 | 119 | m_label = title ; |
519cb848 SC |
120 | |
121 | if ( m_macControl ) | |
122 | { | |
123 | Str255 maclabel ; | |
e7549107 SC |
124 | wxString label ; |
125 | ||
126 | if( wxApp::s_macDefaultEncodingIsPC ) | |
127 | label = wxMacMakeMacStringFromPC( title ) ; | |
128 | else | |
129 | label = title ; | |
519cb848 | 130 | |
03e11df5 GD |
131 | #if TARGET_CARBON |
132 | c2pstrcpy( (StringPtr) maclabel , label ) ; | |
133 | #else | |
134 | strcpy( (char *) maclabel , label ) ; | |
135 | c2pstr( (char *) maclabel ) ; | |
136 | #endif | |
519cb848 SC |
137 | ::SetControlTitle( m_macControl , maclabel ) ; |
138 | } | |
e9576ca5 SC |
139 | } |
140 | ||
37e2cb08 | 141 | wxSize wxControl::DoGetBestSize() const |
e9576ca5 | 142 | { |
e7549107 | 143 | return wxSize(20, 20); |
e9576ca5 SC |
144 | } |
145 | ||
e7549107 | 146 | bool wxControl::ProcessCommand (wxCommandEvent & event) |
e9576ca5 SC |
147 | { |
148 | // Tries: | |
149 | // 1) A callback function (to become obsolete) | |
150 | // 2) OnCommand, starting at this window and working up parent hierarchy | |
151 | // 3) OnCommand then calls ProcessEvent to search the event tables. | |
e7549107 SC |
152 | #if WXWIN_COMPATIBILITY |
153 | if ( m_callback ) | |
e9576ca5 | 154 | { |
e7549107 SC |
155 | (void)(*m_callback)(this, event); |
156 | ||
157 | return TRUE; | |
e9576ca5 SC |
158 | } |
159 | else | |
e7549107 | 160 | #endif // WXWIN_COMPATIBILITY |
e9576ca5 | 161 | { |
e7549107 | 162 | return GetEventHandler()->ProcessEvent(event); |
e9576ca5 SC |
163 | } |
164 | } | |
165 | ||
519cb848 SC |
166 | // ------------------------ |
167 | wxList *wxWinMacControlList = NULL; | |
168 | wxControl *wxFindControlFromMacControl(ControlHandle inControl ) | |
169 | { | |
170 | wxNode *node = wxWinMacControlList->Find((long)inControl); | |
171 | if (!node) | |
172 | return NULL; | |
173 | return (wxControl *)node->Data(); | |
174 | } | |
175 | ||
176 | void wxAssociateControlWithMacControl(ControlHandle inControl, wxControl *control) | |
177 | { | |
178 | // adding NULL WindowRef is (first) surely a result of an error and | |
179 | // (secondly) breaks menu command processing | |
180 | wxCHECK_RET( inControl != (ControlHandle) NULL, "attempt to add a NULL WindowRef to window list" ); | |
181 | ||
182 | if ( !wxWinMacControlList->Find((long)inControl) ) | |
183 | wxWinMacControlList->Append((long)inControl, control); | |
184 | } | |
185 | ||
186 | void wxRemoveMacControlAssociation(wxControl *control) | |
187 | { | |
188 | wxWinMacControlList->DeleteObject(control); | |
189 | } | |
190 | ||
191 | void wxControl::MacPreControlCreate( wxWindow *parent, wxWindowID id, wxString label , | |
192 | const wxPoint& pos, | |
193 | const wxSize& size, long style, | |
194 | const wxValidator& validator, | |
195 | const wxString& name , Rect *outBounds , StringPtr maclabel ) | |
196 | { | |
197 | m_label = label ; | |
198 | SetName(name); | |
199 | if ( &validator ) | |
200 | SetValidator(validator); | |
201 | ||
202 | m_windowStyle = style; | |
203 | parent->AddChild((wxButton *)this); | |
204 | ||
205 | m_backgroundColour = parent->GetBackgroundColour() ; | |
206 | m_foregroundColour = parent->GetForegroundColour() ; | |
207 | ||
208 | if (id == -1) | |
209 | m_windowId = NewControlId(); | |
210 | else | |
211 | m_windowId = id; | |
212 | ||
213 | m_width = size.x ; | |
214 | m_height = size.y ; | |
215 | int x = pos.x ; | |
216 | int y = pos.y ; | |
217 | AdjustForParentClientOrigin(x, y, wxSIZE_USE_EXISTING); | |
218 | m_x = x ; | |
219 | m_y = y ; | |
220 | ||
221 | ||
519cb848 SC |
222 | parent->MacClientToRootWindow( &x , &y ) ; |
223 | outBounds->top = y + m_macVerticalBorder ; | |
224 | outBounds->left = x + m_macHorizontalBorder ; | |
225 | outBounds->bottom = outBounds->top + m_height - 2 * m_macVerticalBorder; | |
226 | outBounds->right = outBounds->left + m_width - 2 * m_macHorizontalBorder ; | |
227 | ||
03e11df5 GD |
228 | char c_text[255]; |
229 | strcpy( c_text , label ) ; | |
519cb848 SC |
230 | if( wxApp::s_macDefaultEncodingIsPC ) |
231 | { | |
03e11df5 | 232 | wxMacConvertFromPCForControls( c_text ) ; |
519cb848 SC |
233 | } |
234 | ||
03e11df5 GD |
235 | #if TARGET_CARBON |
236 | c2pstrcpy( (StringPtr) maclabel , c_text ) ; | |
237 | #else | |
238 | strcpy( (char *) maclabel , c_text ) ; | |
239 | c2pstr( (char *) maclabel ) ; | |
240 | #endif | |
519cb848 SC |
241 | } |
242 | ||
243 | void wxControl::MacPostControlCreate() | |
244 | { | |
245 | wxASSERT_MSG( m_macControl != NULL , "No valid mac control" ) ; | |
246 | ||
247 | if ( IsKindOf( CLASSINFO( wxScrollBar ) ) ) | |
248 | { | |
249 | // no font | |
250 | } | |
2f1ae414 | 251 | else if ( IsKindOf( CLASSINFO( wxStaticBox ) ) || IsKindOf( CLASSINFO( wxRadioBox ) ) || IsKindOf( CLASSINFO( wxButton ) ) ) |
519cb848 SC |
252 | { |
253 | ControlFontStyleRec controlstyle ; | |
254 | controlstyle.flags = kControlUseFontMask ; | |
255 | controlstyle.font = kControlFontSmallBoldSystemFont ; | |
256 | ||
257 | ::UMASetControlFontStyle( m_macControl , &controlstyle ) ; | |
258 | } | |
259 | else | |
260 | { | |
261 | ControlFontStyleRec controlstyle ; | |
262 | controlstyle.flags = kControlUseFontMask ; | |
263 | controlstyle.font = kControlFontSmallSystemFont ; | |
264 | ||
265 | ::UMASetControlFontStyle( m_macControl , &controlstyle ) ; | |
266 | } | |
267 | ControlHandle container = GetParent()->MacGetContainerForEmbedding() ; | |
268 | wxASSERT_MSG( container != NULL , "No valid mac container control" ) ; | |
269 | ::UMAEmbedControl( m_macControl , container ) ; | |
c809f3be | 270 | m_macControlIsShown = true ; |
519cb848 SC |
271 | MacAdjustControlRect() ; |
272 | wxAssociateControlWithMacControl( m_macControl , this ) ; | |
273 | } | |
274 | ||
275 | void wxControl::MacAdjustControlRect() | |
276 | { | |
277 | wxASSERT_MSG( m_macControl != NULL , "No valid mac control" ) ; | |
278 | if ( m_width == -1 || m_height == -1 ) | |
279 | { | |
280 | Rect bestsize = { 0 , 0 , 0 , 0 } ; | |
281 | short baselineoffset ; | |
282 | ||
283 | UMAGetBestControlRect( m_macControl , &bestsize , &baselineoffset ) ; | |
284 | ||
285 | if ( EmptyRect( &bestsize ) ) | |
286 | { | |
287 | baselineoffset = 0; | |
288 | bestsize.left = bestsize.top = 0 ; | |
289 | bestsize.right = 16 ; | |
290 | bestsize.bottom = 16 ; | |
291 | if ( IsKindOf( CLASSINFO( wxScrollBar ) ) ) | |
292 | { | |
293 | bestsize.bottom = 16 ; | |
294 | } | |
295 | else if ( IsKindOf( CLASSINFO( wxSpinButton ) ) ) | |
296 | { | |
297 | bestsize.bottom = 24 ; | |
298 | } | |
299 | } | |
300 | ||
301 | if ( m_width == -1 ) | |
302 | { | |
303 | if ( IsKindOf( CLASSINFO( wxButton ) ) ) | |
304 | { | |
2f1ae414 | 305 | m_width = m_label.Length() * 8 + 12 ; |
0a67a93b SC |
306 | if ( m_width < 70 ) |
307 | m_width = 70 ; | |
519cb848 SC |
308 | } |
309 | else if ( IsKindOf( CLASSINFO( wxStaticText ) ) ) | |
310 | { | |
311 | m_width = m_label.Length() * 8 ; | |
312 | } | |
313 | else | |
2f1ae414 SC |
314 | m_width = bestsize.right - bestsize.left ; |
315 | ||
316 | m_width += 2 * m_macHorizontalBorder ; | |
519cb848 SC |
317 | } |
318 | if ( m_height == -1 ) | |
319 | { | |
320 | m_height = bestsize.bottom - bestsize.top ; | |
321 | if ( m_height < 10 ) | |
322 | m_height = 13 ; | |
323 | ||
324 | m_height += 2 * m_macVerticalBorder; | |
325 | } | |
326 | ||
327 | wxMacDrawingHelper helper ( wxFindWinFromMacWindow( GetMacRootWindow() ) ) ; | |
328 | if ( helper.Ok() ) | |
329 | { | |
2f1ae414 | 330 | UMASizeControl( m_macControl , m_width - 2 * m_macHorizontalBorder, m_height - 2 * m_macVerticalBorder ) ; |
519cb848 SC |
331 | } |
332 | } | |
333 | } | |
334 | ControlHandle wxControl::MacGetContainerForEmbedding() | |
335 | { | |
336 | if ( m_macControl ) | |
337 | return m_macControl ; | |
338 | ||
339 | return wxWindow::MacGetContainerForEmbedding() ; | |
340 | } | |
341 | ||
342 | void wxControl::MacSuperChangedPosition() | |
343 | { | |
344 | if ( m_macControl ) | |
345 | { | |
2f1ae414 SC |
346 | Rect contrlRect ; |
347 | GetControlBounds( m_macControl , &contrlRect ) ; | |
348 | int former_mac_x = contrlRect.left ; | |
349 | int former_mac_y = contrlRect.top ; | |
519cb848 SC |
350 | int mac_x = m_x ; |
351 | int mac_y = m_y ; | |
352 | GetParent()->MacClientToRootWindow( & mac_x , & mac_y ) ; | |
353 | ||
354 | WindowRef rootwindow = GetMacRootWindow() ; | |
355 | wxWindow* wxrootwindow = wxFindWinFromMacWindow( rootwindow ) ; | |
356 | UMASetThemeWindowBackground( rootwindow , kThemeBrushDialogBackgroundActive , false ) ; | |
357 | wxMacDrawingHelper focus( wxrootwindow ) ; | |
358 | ||
359 | if ( mac_x != former_mac_x || mac_y != former_mac_y ) | |
360 | { | |
361 | { | |
362 | Rect inval = { former_mac_y , former_mac_x , former_mac_y + m_height , former_mac_x + m_width } ; | |
2f1ae414 | 363 | InvalWindowRect( rootwindow , &inval ) ; |
519cb848 | 364 | } |
2f1ae414 | 365 | UMAMoveControl( m_macControl , mac_x + m_macHorizontalBorder , mac_y + m_macVerticalBorder ) ; |
519cb848 SC |
366 | { |
367 | Rect inval = { mac_y , mac_x , mac_y + m_height , mac_x + m_width } ; | |
2f1ae414 | 368 | InvalWindowRect( rootwindow , &inval ) ; |
519cb848 SC |
369 | } |
370 | } | |
371 | if ( wxrootwindow->IsKindOf( CLASSINFO( wxDialog ) ) ) | |
372 | { | |
373 | } | |
374 | else | |
375 | { | |
376 | UMASetThemeWindowBackground( rootwindow , kThemeBrushDocumentWindowBackground , false ) ; | |
377 | } | |
378 | } | |
379 | ||
380 | wxWindow::MacSuperChangedPosition() ; | |
381 | } | |
382 | ||
383 | void wxControl::MacSuperEnabled( bool enabled ) | |
384 | { | |
e7549107 | 385 | /* |
519cb848 SC |
386 | if ( m_macControl ) |
387 | { | |
388 | if ( UMAHasAppearance() ) | |
389 | { | |
390 | if ( !enabled ) | |
391 | { | |
392 | ::DeactivateControl( m_macControl ) ; | |
393 | } | |
394 | else | |
395 | { | |
396 | if ( m_macEnabled ) | |
397 | ::ActivateControl( m_macControl ) ; | |
398 | } | |
399 | } | |
400 | else | |
401 | { | |
402 | if ( !enabled ) | |
403 | { | |
404 | ::HiliteControl( m_macControl , 255 ) ; | |
405 | } | |
406 | else | |
407 | { | |
408 | if ( m_macEnabled ) | |
409 | ::HiliteControl( m_macControl , 0 ) ; | |
410 | } | |
411 | } | |
412 | } | |
413 | wxWindow::MacSuperEnabled( enabled ) ; | |
2f1ae414 | 414 | */ |
519cb848 SC |
415 | } |
416 | ||
417 | void wxControl::MacSuperShown( bool show ) | |
418 | { | |
419 | if ( m_macControl ) | |
420 | { | |
421 | if ( !show ) | |
422 | { | |
c809f3be SC |
423 | if ( m_macControlIsShown ) |
424 | { | |
425 | ::UMAHideControl( m_macControl ) ; | |
426 | m_macControlIsShown = false ; | |
427 | } | |
519cb848 SC |
428 | } |
429 | else | |
430 | { | |
c809f3be SC |
431 | if ( MacIsReallyShown() && !m_macControlIsShown ) |
432 | { | |
519cb848 | 433 | ::UMAShowControl( m_macControl ) ; |
c809f3be SC |
434 | m_macControlIsShown = true ; |
435 | } | |
519cb848 SC |
436 | } |
437 | } | |
438 | ||
439 | wxWindow::MacSuperShown( show ) ; | |
440 | } | |
441 | ||
442 | void wxControl::DoSetSize(int x, int y, | |
443 | int width, int height, | |
444 | int sizeFlags ) | |
445 | { | |
446 | if ( m_macControl == NULL ) | |
447 | { | |
448 | wxWindow::DoSetSize( x , y ,width , height ,sizeFlags ) ; | |
449 | return ; | |
450 | } | |
451 | ||
452 | WindowRef rootwindow = GetMacRootWindow() ; | |
453 | wxWindow* wxrootwindow = wxFindWinFromMacWindow( rootwindow ) ; | |
454 | UMASetThemeWindowBackground( rootwindow , kThemeBrushDialogBackgroundActive , false ) ; | |
455 | ||
456 | int former_x = m_x ; | |
457 | int former_y = m_y ; | |
458 | int former_w = m_width ; | |
459 | int former_h = m_height ; | |
460 | ||
2f1ae414 SC |
461 | Rect contrlRect ; |
462 | GetControlBounds( m_macControl , &contrlRect ) ; | |
463 | int former_mac_x = contrlRect.left ; | |
464 | int former_mac_y = contrlRect.top ; | |
519cb848 SC |
465 | |
466 | int currentX, currentY; | |
467 | GetPosition(¤tX, ¤tY); | |
468 | int currentW,currentH; | |
469 | GetSize(¤tW, ¤tH); | |
470 | ||
471 | int actualWidth = width; | |
472 | int actualHeight = height; | |
473 | int actualX = x; | |
474 | int actualY = y; | |
2f1ae414 | 475 | if (x == -1 && !(sizeFlags & wxSIZE_ALLOW_MINUS_ONE)) |
519cb848 | 476 | actualX = currentX; |
2f1ae414 | 477 | if (y == -1 && !(sizeFlags & wxSIZE_ALLOW_MINUS_ONE)) |
519cb848 SC |
478 | actualY = currentY; |
479 | if (width == -1) | |
480 | actualWidth = currentW ; | |
481 | if (height == -1) | |
482 | actualHeight = currentH ; | |
483 | ||
484 | if ( actualX == currentX && actualY == currentY && actualWidth == currentW && actualHeight == currentH) | |
485 | return ; | |
486 | ||
487 | AdjustForParentClientOrigin(actualX, actualY, sizeFlags); | |
2f1ae414 SC |
488 | WindowRef macrootwindow = GetMacRootWindow() ; |
489 | wxMacDrawingHelper focus( wxFindWinFromMacWindow( macrootwindow ) ) ; | |
519cb848 SC |
490 | |
491 | int mac_x = actualX ; | |
492 | int mac_y = actualY ; | |
493 | GetParent()->MacClientToRootWindow( & mac_x , & mac_y ) ; | |
494 | ||
495 | if ( mac_x != former_mac_x || mac_y != former_mac_y ) | |
496 | { | |
497 | { | |
498 | Rect inval = { former_mac_y , former_mac_x , former_mac_y + m_height , former_mac_x + m_width } ; | |
2f1ae414 | 499 | InvalWindowRect( macrootwindow, &inval ) ; |
519cb848 | 500 | } |
2f1ae414 | 501 | UMAMoveControl( m_macControl , mac_x + m_macHorizontalBorder , mac_y + m_macVerticalBorder ) ; |
519cb848 SC |
502 | { |
503 | Rect inval = { mac_y , mac_x , mac_y + m_height , mac_x + m_width } ; | |
2f1ae414 | 504 | InvalWindowRect(macrootwindow, &inval ) ; |
519cb848 SC |
505 | } |
506 | } | |
507 | ||
508 | if ( actualX != former_x || actualY != former_y ) | |
509 | { | |
510 | m_x = actualX ; | |
511 | m_y = actualY ; | |
512 | ||
513 | MacRepositionScrollBars() ; | |
514 | // To consider -> should the parameters be the effective or the virtual coordinates (AdjustForParent..) | |
515 | wxMoveEvent event(wxPoint(m_x, m_y), m_windowId); | |
516 | event.SetEventObject(this); | |
517 | GetEventHandler()->ProcessEvent(event); | |
518 | } | |
519 | if ( actualWidth != former_w || actualHeight != former_h ) | |
520 | { | |
521 | { | |
522 | Rect inval = { mac_y , mac_x , mac_y + former_h , mac_x + former_w } ; | |
2f1ae414 | 523 | InvalWindowRect( macrootwindow, &inval ) ; |
519cb848 SC |
524 | } |
525 | m_width = actualWidth ; | |
526 | m_height = actualHeight ; | |
527 | ||
2f1ae414 | 528 | UMASizeControl( m_macControl , m_width - 2 * m_macHorizontalBorder, m_height - 2 * m_macVerticalBorder ) ; |
519cb848 SC |
529 | { |
530 | Rect inval = { mac_y , mac_x , mac_y + m_height , mac_x + m_width } ; | |
2f1ae414 | 531 | InvalWindowRect( macrootwindow , &inval ) ; |
519cb848 SC |
532 | } |
533 | ||
534 | MacRepositionScrollBars() ; | |
535 | wxSizeEvent event(wxSize(m_width, m_height), m_windowId); | |
536 | event.SetEventObject(this); | |
537 | GetEventHandler()->ProcessEvent(event); | |
538 | } | |
539 | if ( wxrootwindow->IsKindOf( CLASSINFO( wxDialog ) ) ) | |
540 | { | |
541 | } | |
542 | else | |
543 | { | |
544 | UMASetThemeWindowBackground( rootwindow , kThemeBrushDocumentWindowBackground , false ) ; | |
545 | } | |
546 | } | |
547 | ||
519cb848 SC |
548 | bool wxControl::Show(bool show) |
549 | { | |
e7549107 SC |
550 | if ( !wxWindow::Show( show ) ) |
551 | return FALSE ; | |
552 | ||
553 | if ( m_macControl ) | |
554 | { | |
c809f3be SC |
555 | if ( !show ) |
556 | { | |
557 | if ( m_macControlIsShown ) | |
558 | { | |
559 | ::UMAHideControl( m_macControl ) ; | |
560 | m_macControlIsShown = false ; | |
561 | } | |
562 | } | |
e7549107 | 563 | else |
c809f3be SC |
564 | { |
565 | if ( MacIsReallyShown() && !m_macControlIsShown ) | |
566 | { | |
567 | ::UMAShowControl( m_macControl ) ; | |
568 | m_macControlIsShown = true ; | |
569 | } | |
570 | } | |
e7549107 SC |
571 | } |
572 | return TRUE ; | |
519cb848 SC |
573 | } |
574 | ||
e7549107 | 575 | bool wxControl::Enable(bool enable) |
519cb848 | 576 | { |
e7549107 SC |
577 | if ( !wxWindow::Enable(enable) ) |
578 | return FALSE; | |
519cb848 | 579 | |
e7549107 | 580 | if ( m_macControl ) |
519cb848 | 581 | { |
e7549107 SC |
582 | |
583 | if ( UMAHasAppearance() ) | |
584 | { | |
585 | if ( enable ) | |
586 | ::ActivateControl( m_macControl ) ; | |
587 | else | |
588 | ::DeactivateControl( m_macControl ) ; | |
589 | } | |
519cb848 | 590 | else |
e7549107 SC |
591 | { |
592 | if ( enable ) | |
593 | ::HiliteControl( m_macControl , 0 ) ; | |
594 | else | |
595 | ::HiliteControl( m_macControl , 255 ) ; | |
596 | } | |
519cb848 | 597 | } |
e7549107 | 598 | return TRUE ; |
519cb848 SC |
599 | } |
600 | ||
601 | void wxControl::Refresh(bool eraseBack, const wxRect *rect) | |
602 | { | |
603 | if ( m_macControl ) | |
604 | { | |
605 | wxWindow::Refresh( eraseBack , rect ) ; | |
606 | } | |
607 | else | |
608 | { | |
609 | wxWindow::Refresh( eraseBack , rect ) ; | |
610 | } | |
611 | } | |
612 | ||
2f1ae414 SC |
613 | void wxControl::MacRedrawControl() |
614 | { | |
615 | if ( m_macControl ) | |
616 | { | |
617 | WindowRef window = GetMacRootWindow() ; | |
618 | if ( window ) | |
619 | { | |
620 | wxWindow* win = wxFindWinFromMacWindow( window ) ; | |
621 | if ( win ) | |
622 | { | |
623 | wxMacDrawingHelper help( win ) ; | |
624 | // the mac control manager always assumes to have the origin at 0,0 | |
625 | SetOrigin( 0 , 0 ) ; | |
626 | ||
627 | bool hasTabBehind = false ; | |
628 | wxWindow* parent = GetParent() ; | |
629 | while ( parent ) | |
630 | { | |
631 | if( parent->MacGetWindowData() ) | |
632 | { | |
633 | UMASetThemeWindowBackground( win->MacGetWindowData()->m_macWindow , kThemeBrushDialogBackgroundActive , false ) ; | |
634 | break ; | |
635 | } | |
636 | ||
637 | if( parent->IsKindOf( CLASSINFO( wxNotebook ) ) || parent->IsKindOf( CLASSINFO( wxTabCtrl ) )) | |
638 | { | |
639 | if ( ((wxControl*)parent)->m_macControl ) | |
640 | SetUpControlBackground( ((wxControl*)parent)->m_macControl , -1 , true ) ; | |
641 | break ; | |
642 | } | |
643 | ||
644 | parent = parent->GetParent() ; | |
645 | } | |
646 | ||
647 | UMADrawControl( m_macControl ) ; | |
648 | UMASetThemeWindowBackground( win->MacGetWindowData()->m_macWindow , win->MacGetWindowData()->m_macWindowBackgroundTheme , false ) ; | |
649 | } | |
650 | } | |
651 | } | |
652 | } | |
653 | ||
519cb848 SC |
654 | void wxControl::OnPaint(wxPaintEvent& event) |
655 | { | |
656 | if ( m_macControl ) | |
657 | { | |
658 | WindowRef window = GetMacRootWindow() ; | |
659 | if ( window ) | |
660 | { | |
661 | wxWindow* win = wxFindWinFromMacWindow( window ) ; | |
662 | if ( win ) | |
663 | { | |
664 | wxMacDrawingHelper help( win ) ; | |
2f1ae414 | 665 | // the mac control manager always assumes to have the origin at 0,0 |
519cb848 | 666 | SetOrigin( 0 , 0 ) ; |
27419164 | 667 | |
519cb848 | 668 | |
27419164 | 669 | bool hasTabBehind = false ; |
519cb848 SC |
670 | wxWindow* parent = GetParent() ; |
671 | while ( parent ) | |
672 | { | |
e7549107 | 673 | if( parent->MacGetWindowData() ) |
519cb848 | 674 | { |
e7549107 | 675 | UMASetThemeWindowBackground( win->MacGetWindowData()->m_macWindow , kThemeBrushDialogBackgroundActive , false ) ; |
519cb848 SC |
676 | break ; |
677 | } | |
678 | ||
679 | if( parent->IsKindOf( CLASSINFO( wxNotebook ) ) || parent->IsKindOf( CLASSINFO( wxTabCtrl ) )) | |
680 | { | |
681 | if ( ((wxControl*)parent)->m_macControl ) | |
682 | SetUpControlBackground( ((wxControl*)parent)->m_macControl , -1 , true ) ; | |
683 | break ; | |
684 | } | |
685 | ||
686 | parent = parent->GetParent() ; | |
687 | } | |
27419164 | 688 | |
519cb848 | 689 | UMADrawControl( m_macControl ) ; |
e7549107 | 690 | UMASetThemeWindowBackground( win->MacGetWindowData()->m_macWindow , win->MacGetWindowData()->m_macWindowBackgroundTheme , false ) ; |
519cb848 SC |
691 | } |
692 | } | |
693 | } | |
694 | else | |
695 | { | |
e7549107 | 696 | // wxWindow::OnPaint( event ) ; |
519cb848 SC |
697 | } |
698 | } | |
51abe921 SC |
699 | void wxControl::OnEraseBackground(wxEraseEvent& event) |
700 | { | |
701 | // In general, you don't want to erase the background of a control, | |
702 | // or you'll get a flicker. | |
703 | // TODO: move this 'null' function into each control that | |
704 | // might flicker. | |
705 | } | |
706 | ||
519cb848 SC |
707 | |
708 | void wxControl::OnKeyDown( wxKeyEvent &event ) | |
709 | { | |
710 | if ( m_macControl == NULL ) | |
711 | return ; | |
712 | ||
713 | EventRecord *ev = wxTheApp->MacGetCurrentEvent() ; | |
714 | short keycode ; | |
715 | short keychar ; | |
716 | keychar = short(ev->message & charCodeMask); | |
717 | keycode = short(ev->message & keyCodeMask) >> 8 ; | |
718 | ||
719 | UMAHandleControlKey( m_macControl , keycode , keychar , ev->modifiers ) ; | |
720 | } | |
721 | ||
722 | void wxControl::OnMouseEvent( wxMouseEvent &event ) | |
723 | { | |
724 | if ( m_macControl == NULL ) | |
725 | { | |
726 | event.Skip() ; | |
727 | return ; | |
728 | } | |
729 | ||
2f1ae414 | 730 | if (event.GetEventType() == wxEVT_LEFT_DOWN || event.GetEventType() == wxEVT_LEFT_DCLICK ) |
519cb848 SC |
731 | { |
732 | ||
733 | int x = event.m_x ; | |
734 | int y = event.m_y ; | |
735 | ||
736 | MacClientToRootWindow( &x , &y ) ; | |
737 | ||
738 | ControlHandle control ; | |
739 | Point localwhere ; | |
740 | GrafPtr port ; | |
741 | SInt16 controlpart ; | |
742 | WindowRef window = GetMacRootWindow() ; | |
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 | controlpart = FindControl( localwhere , window , &control ) ; | |
765 | { | |
7810c95b | 766 | /* |
519cb848 SC |
767 | if ( AcceptsFocus() && FindFocus() != this ) |
768 | { | |
769 | SetFocus() ; | |
770 | } | |
7810c95b | 771 | */ |
519cb848 SC |
772 | if ( control && UMAIsControlActive( control ) ) |
773 | { | |
774 | { | |
775 | if ( controlpart == kControlIndicatorPart && !UMAHasAppearance() ) | |
776 | controlpart = UMAHandleControlClick( control , localwhere , modifiers , (ControlActionUPP) NULL ) ; | |
777 | else | |
778 | controlpart = UMAHandleControlClick( control , localwhere , modifiers , (ControlActionUPP) -1 ) ; | |
779 | wxTheApp->s_lastMouseDown = 0 ; | |
780 | if ( controlpart && ! ( ( UMAHasAppearance() || (controlpart != kControlIndicatorPart) ) | |
781 | && (IsKindOf( CLASSINFO( wxScrollBar ) ) ) ) ) // otherwise we will get the event twice | |
782 | { | |
783 | MacHandleControlClick( control , controlpart ) ; | |
784 | } | |
785 | } | |
786 | } | |
787 | } | |
788 | } | |
789 | } | |
790 | ||
791 | bool wxControl::MacCanFocus() const | |
792 | { | |
793 | { if ( m_macControl == NULL ) | |
794 | return true ; | |
795 | else | |
796 | return false ; | |
797 | } | |
798 | } | |
799 | ||
800 | void wxControl::MacHandleControlClick( ControlHandle control , SInt16 controlpart ) | |
801 | { | |
802 | wxASSERT_MSG( m_macControl != NULL , "No valid mac control" ) ; | |
803 | } | |
804 |