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