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