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