]>
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 ) ; | |
c809f3be | 269 | m_macControlIsShown = true ; |
519cb848 SC |
270 | MacAdjustControlRect() ; |
271 | wxAssociateControlWithMacControl( m_macControl , this ) ; | |
272 | } | |
273 | ||
274 | void wxControl::MacAdjustControlRect() | |
275 | { | |
276 | wxASSERT_MSG( m_macControl != NULL , "No valid mac control" ) ; | |
277 | if ( m_width == -1 || m_height == -1 ) | |
278 | { | |
279 | Rect bestsize = { 0 , 0 , 0 , 0 } ; | |
280 | short baselineoffset ; | |
281 | ||
282 | UMAGetBestControlRect( m_macControl , &bestsize , &baselineoffset ) ; | |
283 | ||
284 | if ( EmptyRect( &bestsize ) ) | |
285 | { | |
286 | baselineoffset = 0; | |
287 | bestsize.left = bestsize.top = 0 ; | |
288 | bestsize.right = 16 ; | |
289 | bestsize.bottom = 16 ; | |
290 | if ( IsKindOf( CLASSINFO( wxScrollBar ) ) ) | |
291 | { | |
292 | bestsize.bottom = 16 ; | |
293 | } | |
294 | else if ( IsKindOf( CLASSINFO( wxSpinButton ) ) ) | |
295 | { | |
296 | bestsize.bottom = 24 ; | |
297 | } | |
298 | } | |
299 | ||
300 | if ( m_width == -1 ) | |
301 | { | |
302 | if ( IsKindOf( CLASSINFO( wxButton ) ) ) | |
303 | { | |
2f1ae414 | 304 | m_width = m_label.Length() * 8 + 12 ; |
519cb848 SC |
305 | } |
306 | else if ( IsKindOf( CLASSINFO( wxStaticText ) ) ) | |
307 | { | |
308 | m_width = m_label.Length() * 8 ; | |
309 | } | |
310 | else | |
2f1ae414 SC |
311 | m_width = bestsize.right - bestsize.left ; |
312 | ||
313 | m_width += 2 * m_macHorizontalBorder ; | |
519cb848 SC |
314 | } |
315 | if ( m_height == -1 ) | |
316 | { | |
317 | m_height = bestsize.bottom - bestsize.top ; | |
318 | if ( m_height < 10 ) | |
319 | m_height = 13 ; | |
320 | ||
321 | m_height += 2 * m_macVerticalBorder; | |
322 | } | |
323 | ||
324 | wxMacDrawingHelper helper ( wxFindWinFromMacWindow( GetMacRootWindow() ) ) ; | |
325 | if ( helper.Ok() ) | |
326 | { | |
2f1ae414 | 327 | UMASizeControl( m_macControl , m_width - 2 * m_macHorizontalBorder, m_height - 2 * m_macVerticalBorder ) ; |
519cb848 SC |
328 | } |
329 | } | |
330 | } | |
331 | ControlHandle wxControl::MacGetContainerForEmbedding() | |
332 | { | |
333 | if ( m_macControl ) | |
334 | return m_macControl ; | |
335 | ||
336 | return wxWindow::MacGetContainerForEmbedding() ; | |
337 | } | |
338 | ||
339 | void wxControl::MacSuperChangedPosition() | |
340 | { | |
341 | if ( m_macControl ) | |
342 | { | |
2f1ae414 SC |
343 | Rect contrlRect ; |
344 | GetControlBounds( m_macControl , &contrlRect ) ; | |
345 | int former_mac_x = contrlRect.left ; | |
346 | int former_mac_y = contrlRect.top ; | |
519cb848 SC |
347 | int mac_x = m_x ; |
348 | int mac_y = m_y ; | |
349 | GetParent()->MacClientToRootWindow( & mac_x , & mac_y ) ; | |
350 | ||
351 | WindowRef rootwindow = GetMacRootWindow() ; | |
352 | wxWindow* wxrootwindow = wxFindWinFromMacWindow( rootwindow ) ; | |
353 | UMASetThemeWindowBackground( rootwindow , kThemeBrushDialogBackgroundActive , false ) ; | |
354 | wxMacDrawingHelper focus( wxrootwindow ) ; | |
355 | ||
356 | if ( mac_x != former_mac_x || mac_y != former_mac_y ) | |
357 | { | |
358 | { | |
359 | Rect inval = { former_mac_y , former_mac_x , former_mac_y + m_height , former_mac_x + m_width } ; | |
2f1ae414 | 360 | InvalWindowRect( rootwindow , &inval ) ; |
519cb848 | 361 | } |
2f1ae414 | 362 | UMAMoveControl( m_macControl , mac_x + m_macHorizontalBorder , mac_y + m_macVerticalBorder ) ; |
519cb848 SC |
363 | { |
364 | Rect inval = { mac_y , mac_x , mac_y + m_height , mac_x + m_width } ; | |
2f1ae414 | 365 | InvalWindowRect( rootwindow , &inval ) ; |
519cb848 SC |
366 | } |
367 | } | |
368 | if ( wxrootwindow->IsKindOf( CLASSINFO( wxDialog ) ) ) | |
369 | { | |
370 | } | |
371 | else | |
372 | { | |
373 | UMASetThemeWindowBackground( rootwindow , kThemeBrushDocumentWindowBackground , false ) ; | |
374 | } | |
375 | } | |
376 | ||
377 | wxWindow::MacSuperChangedPosition() ; | |
378 | } | |
379 | ||
380 | void wxControl::MacSuperEnabled( bool enabled ) | |
381 | { | |
e7549107 | 382 | /* |
519cb848 SC |
383 | if ( m_macControl ) |
384 | { | |
385 | if ( UMAHasAppearance() ) | |
386 | { | |
387 | if ( !enabled ) | |
388 | { | |
389 | ::DeactivateControl( m_macControl ) ; | |
390 | } | |
391 | else | |
392 | { | |
393 | if ( m_macEnabled ) | |
394 | ::ActivateControl( m_macControl ) ; | |
395 | } | |
396 | } | |
397 | else | |
398 | { | |
399 | if ( !enabled ) | |
400 | { | |
401 | ::HiliteControl( m_macControl , 255 ) ; | |
402 | } | |
403 | else | |
404 | { | |
405 | if ( m_macEnabled ) | |
406 | ::HiliteControl( m_macControl , 0 ) ; | |
407 | } | |
408 | } | |
409 | } | |
410 | wxWindow::MacSuperEnabled( enabled ) ; | |
2f1ae414 | 411 | */ |
519cb848 SC |
412 | } |
413 | ||
414 | void wxControl::MacSuperShown( bool show ) | |
415 | { | |
416 | if ( m_macControl ) | |
417 | { | |
418 | if ( !show ) | |
419 | { | |
c809f3be SC |
420 | if ( m_macControlIsShown ) |
421 | { | |
422 | ::UMAHideControl( m_macControl ) ; | |
423 | m_macControlIsShown = false ; | |
424 | } | |
519cb848 SC |
425 | } |
426 | else | |
427 | { | |
c809f3be SC |
428 | if ( MacIsReallyShown() && !m_macControlIsShown ) |
429 | { | |
519cb848 | 430 | ::UMAShowControl( m_macControl ) ; |
c809f3be SC |
431 | m_macControlIsShown = true ; |
432 | } | |
519cb848 SC |
433 | } |
434 | } | |
435 | ||
436 | wxWindow::MacSuperShown( show ) ; | |
437 | } | |
438 | ||
439 | void wxControl::DoSetSize(int x, int y, | |
440 | int width, int height, | |
441 | int sizeFlags ) | |
442 | { | |
443 | if ( m_macControl == NULL ) | |
444 | { | |
445 | wxWindow::DoSetSize( x , y ,width , height ,sizeFlags ) ; | |
446 | return ; | |
447 | } | |
448 | ||
449 | WindowRef rootwindow = GetMacRootWindow() ; | |
450 | wxWindow* wxrootwindow = wxFindWinFromMacWindow( rootwindow ) ; | |
451 | UMASetThemeWindowBackground( rootwindow , kThemeBrushDialogBackgroundActive , false ) ; | |
452 | ||
453 | int former_x = m_x ; | |
454 | int former_y = m_y ; | |
455 | int former_w = m_width ; | |
456 | int former_h = m_height ; | |
457 | ||
2f1ae414 SC |
458 | Rect contrlRect ; |
459 | GetControlBounds( m_macControl , &contrlRect ) ; | |
460 | int former_mac_x = contrlRect.left ; | |
461 | int former_mac_y = contrlRect.top ; | |
519cb848 SC |
462 | |
463 | int currentX, currentY; | |
464 | GetPosition(¤tX, ¤tY); | |
465 | int currentW,currentH; | |
466 | GetSize(¤tW, ¤tH); | |
467 | ||
468 | int actualWidth = width; | |
469 | int actualHeight = height; | |
470 | int actualX = x; | |
471 | int actualY = y; | |
2f1ae414 | 472 | if (x == -1 && !(sizeFlags & wxSIZE_ALLOW_MINUS_ONE)) |
519cb848 | 473 | actualX = currentX; |
2f1ae414 | 474 | if (y == -1 && !(sizeFlags & wxSIZE_ALLOW_MINUS_ONE)) |
519cb848 SC |
475 | actualY = currentY; |
476 | if (width == -1) | |
477 | actualWidth = currentW ; | |
478 | if (height == -1) | |
479 | actualHeight = currentH ; | |
480 | ||
481 | if ( actualX == currentX && actualY == currentY && actualWidth == currentW && actualHeight == currentH) | |
482 | return ; | |
483 | ||
484 | AdjustForParentClientOrigin(actualX, actualY, sizeFlags); | |
2f1ae414 SC |
485 | WindowRef macrootwindow = GetMacRootWindow() ; |
486 | wxMacDrawingHelper focus( wxFindWinFromMacWindow( macrootwindow ) ) ; | |
519cb848 SC |
487 | |
488 | int mac_x = actualX ; | |
489 | int mac_y = actualY ; | |
490 | GetParent()->MacClientToRootWindow( & mac_x , & mac_y ) ; | |
491 | ||
492 | if ( mac_x != former_mac_x || mac_y != former_mac_y ) | |
493 | { | |
494 | { | |
495 | Rect inval = { former_mac_y , former_mac_x , former_mac_y + m_height , former_mac_x + m_width } ; | |
2f1ae414 | 496 | InvalWindowRect( macrootwindow, &inval ) ; |
519cb848 | 497 | } |
2f1ae414 | 498 | UMAMoveControl( m_macControl , mac_x + m_macHorizontalBorder , mac_y + m_macVerticalBorder ) ; |
519cb848 SC |
499 | { |
500 | Rect inval = { mac_y , mac_x , mac_y + m_height , mac_x + m_width } ; | |
2f1ae414 | 501 | InvalWindowRect(macrootwindow, &inval ) ; |
519cb848 SC |
502 | } |
503 | } | |
504 | ||
505 | if ( actualX != former_x || actualY != former_y ) | |
506 | { | |
507 | m_x = actualX ; | |
508 | m_y = actualY ; | |
509 | ||
510 | MacRepositionScrollBars() ; | |
511 | // To consider -> should the parameters be the effective or the virtual coordinates (AdjustForParent..) | |
512 | wxMoveEvent event(wxPoint(m_x, m_y), m_windowId); | |
513 | event.SetEventObject(this); | |
514 | GetEventHandler()->ProcessEvent(event); | |
515 | } | |
516 | if ( actualWidth != former_w || actualHeight != former_h ) | |
517 | { | |
518 | { | |
519 | Rect inval = { mac_y , mac_x , mac_y + former_h , mac_x + former_w } ; | |
2f1ae414 | 520 | InvalWindowRect( macrootwindow, &inval ) ; |
519cb848 SC |
521 | } |
522 | m_width = actualWidth ; | |
523 | m_height = actualHeight ; | |
524 | ||
2f1ae414 | 525 | UMASizeControl( m_macControl , m_width - 2 * m_macHorizontalBorder, m_height - 2 * m_macVerticalBorder ) ; |
519cb848 SC |
526 | { |
527 | Rect inval = { mac_y , mac_x , mac_y + m_height , mac_x + m_width } ; | |
2f1ae414 | 528 | InvalWindowRect( macrootwindow , &inval ) ; |
519cb848 SC |
529 | } |
530 | ||
531 | MacRepositionScrollBars() ; | |
532 | wxSizeEvent event(wxSize(m_width, m_height), m_windowId); | |
533 | event.SetEventObject(this); | |
534 | GetEventHandler()->ProcessEvent(event); | |
535 | } | |
536 | if ( wxrootwindow->IsKindOf( CLASSINFO( wxDialog ) ) ) | |
537 | { | |
538 | } | |
539 | else | |
540 | { | |
541 | UMASetThemeWindowBackground( rootwindow , kThemeBrushDocumentWindowBackground , false ) ; | |
542 | } | |
543 | } | |
544 | ||
519cb848 SC |
545 | bool wxControl::Show(bool show) |
546 | { | |
e7549107 SC |
547 | if ( !wxWindow::Show( show ) ) |
548 | return FALSE ; | |
549 | ||
550 | if ( m_macControl ) | |
551 | { | |
c809f3be SC |
552 | if ( !show ) |
553 | { | |
554 | if ( m_macControlIsShown ) | |
555 | { | |
556 | ::UMAHideControl( m_macControl ) ; | |
557 | m_macControlIsShown = false ; | |
558 | } | |
559 | } | |
e7549107 | 560 | else |
c809f3be SC |
561 | { |
562 | if ( MacIsReallyShown() && !m_macControlIsShown ) | |
563 | { | |
564 | ::UMAShowControl( m_macControl ) ; | |
565 | m_macControlIsShown = true ; | |
566 | } | |
567 | } | |
e7549107 SC |
568 | } |
569 | return TRUE ; | |
519cb848 SC |
570 | } |
571 | ||
e7549107 | 572 | bool wxControl::Enable(bool enable) |
519cb848 | 573 | { |
e7549107 SC |
574 | if ( !wxWindow::Enable(enable) ) |
575 | return FALSE; | |
519cb848 | 576 | |
e7549107 | 577 | if ( m_macControl ) |
519cb848 | 578 | { |
e7549107 SC |
579 | |
580 | if ( UMAHasAppearance() ) | |
581 | { | |
582 | if ( enable ) | |
583 | ::ActivateControl( m_macControl ) ; | |
584 | else | |
585 | ::DeactivateControl( m_macControl ) ; | |
586 | } | |
519cb848 | 587 | else |
e7549107 SC |
588 | { |
589 | if ( enable ) | |
590 | ::HiliteControl( m_macControl , 0 ) ; | |
591 | else | |
592 | ::HiliteControl( m_macControl , 255 ) ; | |
593 | } | |
519cb848 | 594 | } |
e7549107 | 595 | return TRUE ; |
519cb848 SC |
596 | } |
597 | ||
598 | void wxControl::Refresh(bool eraseBack, const wxRect *rect) | |
599 | { | |
600 | if ( m_macControl ) | |
601 | { | |
602 | wxWindow::Refresh( eraseBack , rect ) ; | |
603 | } | |
604 | else | |
605 | { | |
606 | wxWindow::Refresh( eraseBack , rect ) ; | |
607 | } | |
608 | } | |
609 | ||
2f1ae414 SC |
610 | void wxControl::MacRedrawControl() |
611 | { | |
612 | if ( m_macControl ) | |
613 | { | |
614 | WindowRef window = GetMacRootWindow() ; | |
615 | if ( window ) | |
616 | { | |
617 | wxWindow* win = wxFindWinFromMacWindow( window ) ; | |
618 | if ( win ) | |
619 | { | |
620 | wxMacDrawingHelper help( win ) ; | |
621 | // the mac control manager always assumes to have the origin at 0,0 | |
622 | SetOrigin( 0 , 0 ) ; | |
623 | ||
624 | bool hasTabBehind = false ; | |
625 | wxWindow* parent = GetParent() ; | |
626 | while ( parent ) | |
627 | { | |
628 | if( parent->MacGetWindowData() ) | |
629 | { | |
630 | UMASetThemeWindowBackground( win->MacGetWindowData()->m_macWindow , kThemeBrushDialogBackgroundActive , false ) ; | |
631 | break ; | |
632 | } | |
633 | ||
634 | if( parent->IsKindOf( CLASSINFO( wxNotebook ) ) || parent->IsKindOf( CLASSINFO( wxTabCtrl ) )) | |
635 | { | |
636 | if ( ((wxControl*)parent)->m_macControl ) | |
637 | SetUpControlBackground( ((wxControl*)parent)->m_macControl , -1 , true ) ; | |
638 | break ; | |
639 | } | |
640 | ||
641 | parent = parent->GetParent() ; | |
642 | } | |
643 | ||
644 | UMADrawControl( m_macControl ) ; | |
645 | UMASetThemeWindowBackground( win->MacGetWindowData()->m_macWindow , win->MacGetWindowData()->m_macWindowBackgroundTheme , false ) ; | |
b89dac78 | 646 | wxDC::MacInvalidateSetup() ; |
2f1ae414 SC |
647 | } |
648 | } | |
649 | } | |
650 | } | |
651 | ||
519cb848 SC |
652 | void wxControl::OnPaint(wxPaintEvent& event) |
653 | { | |
654 | if ( m_macControl ) | |
655 | { | |
656 | WindowRef window = GetMacRootWindow() ; | |
657 | if ( window ) | |
658 | { | |
659 | wxWindow* win = wxFindWinFromMacWindow( window ) ; | |
660 | if ( win ) | |
661 | { | |
662 | wxMacDrawingHelper help( win ) ; | |
2f1ae414 | 663 | // the mac control manager always assumes to have the origin at 0,0 |
519cb848 SC |
664 | SetOrigin( 0 , 0 ) ; |
665 | ||
666 | bool hasTabBehind = false ; | |
667 | wxWindow* parent = GetParent() ; | |
668 | while ( parent ) | |
669 | { | |
e7549107 | 670 | if( parent->MacGetWindowData() ) |
519cb848 | 671 | { |
e7549107 | 672 | UMASetThemeWindowBackground( win->MacGetWindowData()->m_macWindow , kThemeBrushDialogBackgroundActive , false ) ; |
519cb848 SC |
673 | break ; |
674 | } | |
675 | ||
676 | if( parent->IsKindOf( CLASSINFO( wxNotebook ) ) || parent->IsKindOf( CLASSINFO( wxTabCtrl ) )) | |
677 | { | |
678 | if ( ((wxControl*)parent)->m_macControl ) | |
679 | SetUpControlBackground( ((wxControl*)parent)->m_macControl , -1 , true ) ; | |
680 | break ; | |
681 | } | |
682 | ||
683 | parent = parent->GetParent() ; | |
684 | } | |
685 | ||
686 | UMADrawControl( m_macControl ) ; | |
e7549107 | 687 | UMASetThemeWindowBackground( win->MacGetWindowData()->m_macWindow , win->MacGetWindowData()->m_macWindowBackgroundTheme , false ) ; |
b89dac78 | 688 | wxDC::MacInvalidateSetup() ; |
519cb848 SC |
689 | } |
690 | } | |
691 | } | |
692 | else | |
693 | { | |
e7549107 | 694 | // wxWindow::OnPaint( event ) ; |
519cb848 SC |
695 | } |
696 | } | |
51abe921 SC |
697 | void wxControl::OnEraseBackground(wxEraseEvent& event) |
698 | { | |
699 | // In general, you don't want to erase the background of a control, | |
700 | // or you'll get a flicker. | |
701 | // TODO: move this 'null' function into each control that | |
702 | // might flicker. | |
703 | } | |
704 | ||
519cb848 SC |
705 | |
706 | void wxControl::OnKeyDown( wxKeyEvent &event ) | |
707 | { | |
708 | if ( m_macControl == NULL ) | |
709 | return ; | |
710 | ||
711 | EventRecord *ev = wxTheApp->MacGetCurrentEvent() ; | |
712 | short keycode ; | |
713 | short keychar ; | |
714 | keychar = short(ev->message & charCodeMask); | |
715 | keycode = short(ev->message & keyCodeMask) >> 8 ; | |
716 | ||
717 | UMAHandleControlKey( m_macControl , keycode , keychar , ev->modifiers ) ; | |
718 | } | |
719 | ||
720 | void wxControl::OnMouseEvent( wxMouseEvent &event ) | |
721 | { | |
722 | if ( m_macControl == NULL ) | |
723 | { | |
724 | event.Skip() ; | |
725 | return ; | |
726 | } | |
727 | ||
2f1ae414 | 728 | if (event.GetEventType() == wxEVT_LEFT_DOWN || event.GetEventType() == wxEVT_LEFT_DCLICK ) |
519cb848 SC |
729 | { |
730 | ||
731 | int x = event.m_x ; | |
732 | int y = event.m_y ; | |
733 | ||
734 | MacClientToRootWindow( &x , &y ) ; | |
735 | ||
736 | ControlHandle control ; | |
737 | Point localwhere ; | |
738 | GrafPtr port ; | |
739 | SInt16 controlpart ; | |
740 | WindowRef window = GetMacRootWindow() ; | |
741 | ||
742 | localwhere.h = x ; | |
743 | localwhere.v = y ; | |
744 | ||
745 | short modifiers = 0; | |
746 | ||
747 | if ( !event.m_leftDown && !event.m_rightDown ) | |
748 | modifiers |= btnState ; | |
749 | ||
750 | if ( event.m_shiftDown ) | |
751 | modifiers |= shiftKey ; | |
752 | ||
753 | if ( event.m_controlDown ) | |
754 | modifiers |= controlKey ; | |
755 | ||
756 | if ( event.m_altDown ) | |
757 | modifiers |= optionKey ; | |
758 | ||
759 | if ( event.m_metaDown ) | |
760 | modifiers |= cmdKey ; | |
761 | ||
762 | controlpart = FindControl( localwhere , window , &control ) ; | |
763 | { | |
7810c95b | 764 | /* |
519cb848 SC |
765 | if ( AcceptsFocus() && FindFocus() != this ) |
766 | { | |
767 | SetFocus() ; | |
768 | } | |
7810c95b | 769 | */ |
519cb848 SC |
770 | if ( control && UMAIsControlActive( control ) ) |
771 | { | |
772 | { | |
773 | if ( controlpart == kControlIndicatorPart && !UMAHasAppearance() ) | |
774 | controlpart = UMAHandleControlClick( control , localwhere , modifiers , (ControlActionUPP) NULL ) ; | |
775 | else | |
776 | controlpart = UMAHandleControlClick( control , localwhere , modifiers , (ControlActionUPP) -1 ) ; | |
777 | wxTheApp->s_lastMouseDown = 0 ; | |
778 | if ( controlpart && ! ( ( UMAHasAppearance() || (controlpart != kControlIndicatorPart) ) | |
779 | && (IsKindOf( CLASSINFO( wxScrollBar ) ) ) ) ) // otherwise we will get the event twice | |
780 | { | |
781 | MacHandleControlClick( control , controlpart ) ; | |
782 | } | |
783 | } | |
784 | } | |
785 | } | |
786 | } | |
787 | } | |
788 | ||
789 | bool wxControl::MacCanFocus() const | |
790 | { | |
791 | { if ( m_macControl == NULL ) | |
792 | return true ; | |
793 | else | |
794 | return false ; | |
795 | } | |
796 | } | |
797 | ||
798 | void wxControl::MacHandleControlClick( ControlHandle control , SInt16 controlpart ) | |
799 | { | |
800 | wxASSERT_MSG( m_macControl != NULL , "No valid mac control" ) ; | |
801 | } | |
802 |