]>
Commit | Line | Data |
---|---|---|
e9576ca5 SC |
1 | ///////////////////////////////////////////////////////////////////////////// |
2 | // Name: windows.cpp | |
3 | // Purpose: wxWindow | |
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 "window.h" | |
14 | #endif | |
15 | ||
16 | #include "wx/setup.h" | |
17 | #include "wx/menu.h" | |
18 | #include "wx/dc.h" | |
19 | #include "wx/dcclient.h" | |
519cb848 | 20 | #include "wx/utils.h" |
e9576ca5 SC |
21 | #include "wx/app.h" |
22 | #include "wx/panel.h" | |
23 | #include "wx/layout.h" | |
24 | #include "wx/dialog.h" | |
25 | #include "wx/listbox.h" | |
26 | #include "wx/button.h" | |
27 | #include "wx/settings.h" | |
28 | #include "wx/msgdlg.h" | |
29 | #include "wx/frame.h" | |
519cb848 SC |
30 | #include "wx/notebook.h" |
31 | #include "wx/tabctrl.h" | |
32 | // TODO remove the line below, just for lookup-up convenience CS | |
33 | #include "wx/mac/window.h" | |
e9576ca5 SC |
34 | |
35 | #include "wx/menuitem.h" | |
36 | #include "wx/log.h" | |
37 | ||
519cb848 SC |
38 | #define wxWINDOW_HSCROLL 5998 |
39 | #define wxWINDOW_VSCROLL 5997 | |
40 | #define MAC_SCROLLBAR_SIZE 16 | |
41 | ||
42 | #include <wx/mac/uma.h> | |
43 | ||
e9576ca5 SC |
44 | #if wxUSE_DRAG_AND_DROP |
45 | #include "wx/dnd.h" | |
46 | #endif | |
47 | ||
48 | #include <string.h> | |
49 | ||
50 | extern wxList wxPendingDelete; | |
519cb848 | 51 | wxWindow* gFocusWindow = NULL ; |
e9576ca5 SC |
52 | |
53 | #if !USE_SHARED_LIBRARY | |
54 | IMPLEMENT_DYNAMIC_CLASS(wxWindow, wxEvtHandler) | |
55 | ||
56 | BEGIN_EVENT_TABLE(wxWindow, wxEvtHandler) | |
57 | EVT_CHAR(wxWindow::OnChar) | |
58 | EVT_ERASE_BACKGROUND(wxWindow::OnEraseBackground) | |
59 | EVT_SYS_COLOUR_CHANGED(wxWindow::OnSysColourChanged) | |
60 | EVT_INIT_DIALOG(wxWindow::OnInitDialog) | |
61 | EVT_IDLE(wxWindow::OnIdle) | |
519cb848 | 62 | EVT_PAINT(wxWindow::OnPaint) |
e9576ca5 SC |
63 | END_EVENT_TABLE() |
64 | ||
65 | #endif | |
66 | ||
67 | ||
68 | // Constructor | |
69 | wxWindow::wxWindow() | |
70 | { | |
519cb848 SC |
71 | Init() ; |
72 | } | |
73 | ||
74 | void wxWindow::Init() | |
75 | { | |
76 | m_macWindowData = NULL ; | |
77 | m_isWindow = TRUE; | |
78 | m_x = 0; | |
79 | m_y = 0 ; | |
80 | m_width = 0 ; | |
81 | m_height = 0 ; | |
82 | // these are the defaults for MSW | |
83 | m_macShown = true ; | |
84 | m_macEnabled = true ; | |
85 | // Generic | |
86 | m_windowId = 0; | |
87 | m_windowStyle = 0; | |
88 | m_windowParent = NULL; | |
89 | m_windowEventHandler = this; | |
90 | m_windowName = ""; | |
91 | m_windowCursor = *wxSTANDARD_CURSOR; | |
92 | m_children = new wxWindowList; | |
93 | m_constraints = NULL; | |
94 | m_constraintsInvolvedIn = NULL; | |
95 | m_windowSizer = NULL; | |
96 | m_sizerParent = NULL; | |
97 | m_autoLayout = FALSE; | |
98 | m_windowValidator = NULL; | |
99 | m_defaultItem = NULL; | |
100 | m_returnCode = 0; | |
101 | m_caretWidth = 0; m_caretHeight = 0; | |
102 | m_caretEnabled = FALSE; | |
103 | m_caretShown = FALSE; | |
104 | m_backgroundColour = wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DFACE) ; | |
105 | // m_backgroundColour = wxSystemSettings::GetSystemColour(wxSYS_COLOUR_WINDOW) ; ; | |
106 | m_foregroundColour = *wxBLACK; | |
107 | m_hScrollBar = NULL ; | |
108 | m_vScrollBar = NULL ; | |
109 | m_mouseInWindow = FALSE; | |
e9576ca5 SC |
110 | |
111 | #if wxUSE_DRAG_AND_DROP | |
519cb848 | 112 | m_pDropTarget = NULL; |
e9576ca5 SC |
113 | #endif |
114 | } | |
115 | ||
116 | // Destructor | |
117 | wxWindow::~wxWindow() | |
118 | { | |
519cb848 SC |
119 | if ( s_lastMouseWindow == this ) |
120 | { | |
121 | s_lastMouseWindow = NULL ; | |
122 | } | |
e9576ca5 SC |
123 | // Have to delete constraints/sizer FIRST otherwise |
124 | // sizers may try to look at deleted windows as they | |
125 | // delete themselves. | |
126 | #if wxUSE_CONSTRAINTS | |
127 | DeleteRelatedConstraints(); | |
128 | if (m_constraints) | |
129 | { | |
130 | // This removes any dangling pointers to this window | |
131 | // in other windows' constraintsInvolvedIn lists. | |
132 | UnsetConstraints(m_constraints); | |
133 | delete m_constraints; | |
134 | m_constraints = NULL; | |
135 | } | |
136 | if (m_windowSizer) | |
137 | { | |
138 | delete m_windowSizer; | |
139 | m_windowSizer = NULL; | |
140 | } | |
141 | // If this is a child of a sizer, remove self from parent | |
142 | if (m_sizerParent) | |
143 | m_sizerParent->RemoveChild((wxWindow *)this); | |
144 | #endif | |
145 | ||
519cb848 SC |
146 | if ( FindFocus() == this ) |
147 | { | |
148 | // really a bad thing - maybe an error ? | |
149 | // we cannot even send it a kill focus message at this stage | |
150 | gFocusWindow = NULL ; | |
151 | } | |
152 | ||
e9576ca5 SC |
153 | if (m_windowParent) |
154 | m_windowParent->RemoveChild(this); | |
155 | ||
156 | DestroyChildren(); | |
157 | ||
519cb848 SC |
158 | if ( m_macWindowData ) |
159 | { | |
160 | UMADisposeWindow( m_macWindowData->m_macWindow ) ; | |
161 | delete m_macWindowData ; | |
162 | wxRemoveMacWindowAssociation( this ) ; | |
163 | } | |
e9576ca5 SC |
164 | |
165 | delete m_children; | |
166 | m_children = NULL; | |
167 | ||
168 | // Just in case the window has been Closed, but | |
169 | // we're then deleting immediately: don't leave | |
170 | // dangling pointers. | |
171 | wxPendingDelete.DeleteObject(this); | |
172 | ||
173 | if ( m_windowValidator ) | |
174 | delete m_windowValidator; | |
175 | } | |
176 | ||
177 | // Destroy the window (delayed, if a managed window) | |
178 | bool wxWindow::Destroy() | |
179 | { | |
180 | delete this; | |
181 | return TRUE; | |
182 | } | |
183 | ||
184 | // Constructor | |
185 | bool wxWindow::Create(wxWindow *parent, wxWindowID id, | |
186 | const wxPoint& pos, | |
187 | const wxSize& size, | |
188 | long style, | |
189 | const wxString& name) | |
190 | { | |
519cb848 SC |
191 | m_isWindow = TRUE; |
192 | // Generic | |
e9576ca5 SC |
193 | m_windowId = 0; |
194 | m_windowStyle = 0; | |
195 | m_windowParent = NULL; | |
196 | m_windowEventHandler = this; | |
197 | m_windowName = ""; | |
198 | m_windowCursor = *wxSTANDARD_CURSOR; | |
199 | m_constraints = NULL; | |
200 | m_constraintsInvolvedIn = NULL; | |
201 | m_windowSizer = NULL; | |
202 | m_sizerParent = NULL; | |
203 | m_autoLayout = FALSE; | |
204 | m_windowValidator = NULL; | |
205 | ||
206 | #if wxUSE_DRAG_AND_DROP | |
207 | m_pDropTarget = NULL; | |
208 | #endif | |
209 | ||
210 | m_caretWidth = 0; m_caretHeight = 0; | |
211 | m_caretEnabled = FALSE; | |
212 | m_caretShown = FALSE; | |
213 | m_minSizeX = -1; | |
214 | m_minSizeY = -1; | |
215 | m_maxSizeX = -1; | |
216 | m_maxSizeY = -1; | |
217 | m_defaultItem = NULL; | |
218 | m_windowParent = NULL; | |
219 | if (!parent) | |
220 | return FALSE; | |
221 | ||
222 | if (parent) parent->AddChild(this); | |
223 | ||
224 | m_returnCode = 0; | |
225 | ||
226 | SetName(name); | |
227 | ||
228 | if ( id == -1 ) | |
229 | m_windowId = (int)NewControlId(); | |
230 | else | |
519cb848 | 231 | m_windowId = id; |
e9576ca5 SC |
232 | |
233 | // m_backgroundColour = wxSystemSettings::GetSystemColour(wxSYS_COLOUR_WINDOW) ; ; | |
234 | m_backgroundColour = wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DFACE) ; | |
235 | m_foregroundColour = *wxBLACK; | |
236 | ||
237 | m_windowStyle = style; | |
238 | ||
239 | if ( id == -1 ) | |
240 | m_windowId = (int)NewControlId(); | |
241 | else | |
519cb848 | 242 | m_windowId = id; |
e9576ca5 | 243 | |
519cb848 SC |
244 | m_x = (int)pos.x; |
245 | m_y = (int)pos.y; | |
246 | AdjustForParentClientOrigin(m_x, m_y, wxSIZE_USE_EXISTING); | |
247 | m_width = size.x; | |
248 | m_height = size.y; | |
249 | ||
250 | MacCreateScrollBars( style ) ; | |
e9576ca5 SC |
251 | |
252 | return TRUE; | |
253 | } | |
254 | ||
255 | void wxWindow::SetFocus() | |
256 | { | |
519cb848 SC |
257 | if ( AcceptsFocus() ) |
258 | { | |
259 | if (gFocusWindow ) | |
260 | { | |
261 | wxControl* control = wxDynamicCast( gFocusWindow , wxControl ) ; | |
262 | if ( control && control->GetMacControl() ) | |
263 | { | |
264 | UMASetKeyboardFocus( gFocusWindow->GetMacRootWindow() , control->GetMacControl() , kControlFocusNoPart ) ; | |
265 | } | |
266 | wxFocusEvent event(wxEVT_KILL_FOCUS, gFocusWindow->m_windowId); | |
267 | event.SetEventObject(gFocusWindow); | |
268 | gFocusWindow->GetEventHandler()->ProcessEvent(event) ; | |
269 | } | |
270 | gFocusWindow = this ; | |
271 | { | |
272 | wxControl* control = wxDynamicCast( gFocusWindow , wxControl ) ; | |
273 | if ( control && control->GetMacControl() ) | |
274 | { | |
275 | UMASetKeyboardFocus( gFocusWindow->GetMacRootWindow() , control->GetMacControl() , kControlEditTextPart ) ; | |
276 | } | |
277 | ||
278 | wxFocusEvent event(wxEVT_SET_FOCUS, m_windowId); | |
279 | event.SetEventObject(this); | |
280 | GetEventHandler()->ProcessEvent(event) ; | |
281 | } | |
282 | } | |
e9576ca5 SC |
283 | } |
284 | ||
285 | void wxWindow::Enable(bool enable) | |
286 | { | |
519cb848 SC |
287 | if ( m_macEnabled == enable ) |
288 | return ; | |
289 | ||
290 | m_macEnabled = enable ; | |
291 | ||
292 | MacSuperEnabled( enable ) ; | |
293 | return; | |
e9576ca5 SC |
294 | } |
295 | ||
296 | void wxWindow::CaptureMouse() | |
297 | { | |
519cb848 | 298 | wxTheApp->s_captureWindow = this ; |
e9576ca5 SC |
299 | } |
300 | ||
301 | void wxWindow::ReleaseMouse() | |
302 | { | |
519cb848 | 303 | wxTheApp->s_captureWindow = NULL ; |
e9576ca5 SC |
304 | } |
305 | ||
306 | // Push/pop event handler (i.e. allow a chain of event handlers | |
307 | // be searched) | |
308 | void wxWindow::PushEventHandler(wxEvtHandler *handler) | |
309 | { | |
310 | handler->SetNextHandler(GetEventHandler()); | |
311 | SetEventHandler(handler); | |
312 | } | |
313 | ||
314 | wxEvtHandler *wxWindow::PopEventHandler(bool deleteHandler) | |
315 | { | |
316 | if ( GetEventHandler() ) | |
317 | { | |
318 | wxEvtHandler *handlerA = GetEventHandler(); | |
319 | wxEvtHandler *handlerB = handlerA->GetNextHandler(); | |
320 | handlerA->SetNextHandler(NULL); | |
321 | SetEventHandler(handlerB); | |
322 | if ( deleteHandler ) | |
323 | { | |
324 | delete handlerA; | |
325 | return NULL; | |
326 | } | |
327 | else | |
328 | return handlerA; | |
329 | } | |
330 | else | |
331 | return NULL; | |
332 | } | |
333 | ||
334 | #if wxUSE_DRAG_AND_DROP | |
335 | ||
336 | void wxWindow::SetDropTarget(wxDropTarget *pDropTarget) | |
337 | { | |
338 | if ( m_pDropTarget != 0 ) { | |
339 | delete m_pDropTarget; | |
340 | } | |
341 | ||
342 | m_pDropTarget = pDropTarget; | |
343 | if ( m_pDropTarget != 0 ) | |
344 | { | |
345 | // TODO | |
346 | } | |
347 | } | |
348 | ||
349 | #endif | |
350 | ||
351 | // Old style file-manager drag&drop | |
352 | void wxWindow::DragAcceptFiles(bool accept) | |
353 | { | |
354 | // TODO | |
355 | } | |
356 | ||
357 | // Get total size | |
358 | void wxWindow::GetSize(int *x, int *y) const | |
359 | { | |
519cb848 SC |
360 | *x = m_width ; |
361 | *y = m_height ; | |
e9576ca5 SC |
362 | } |
363 | ||
364 | void wxWindow::GetPosition(int *x, int *y) const | |
365 | { | |
519cb848 SC |
366 | *x = m_x ; |
367 | *y = m_y ; | |
368 | if (GetParent()) | |
369 | { | |
370 | wxPoint pt(GetParent()->GetClientAreaOrigin()); | |
371 | *x -= pt.x; | |
372 | *y -= pt.y; | |
373 | } | |
e9576ca5 SC |
374 | } |
375 | ||
376 | void wxWindow::ScreenToClient(int *x, int *y) const | |
377 | { | |
519cb848 SC |
378 | WindowRef window = GetMacRootWindow() ; |
379 | ||
380 | Point localwhere ; | |
381 | localwhere.h = * x ; | |
382 | localwhere.v = * y ; | |
383 | ||
384 | GrafPtr port ; | |
385 | ::GetPort( &port ) ; | |
386 | ::SetPort( UMAGetWindowPort( window ) ) ; | |
387 | ::GlobalToLocal( &localwhere ) ; | |
388 | ::SetPort( port ) ; | |
389 | ||
390 | *x = localwhere.h ; | |
391 | *y = localwhere.v ; | |
392 | ||
393 | MacRootWindowToClient( x , y ) ; | |
e9576ca5 SC |
394 | } |
395 | ||
396 | void wxWindow::ClientToScreen(int *x, int *y) const | |
397 | { | |
519cb848 SC |
398 | WindowRef window = GetMacRootWindow() ; |
399 | ||
400 | MacClientToRootWindow( x , y ) ; | |
401 | ||
402 | Point localwhere ; | |
403 | localwhere.h = * x ; | |
404 | localwhere.v = * y ; | |
405 | ||
406 | GrafPtr port ; | |
407 | ::GetPort( &port ) ; | |
408 | ::SetPort( UMAGetWindowPort( window ) ) ; | |
409 | ::LocalToGlobal( &localwhere ) ; | |
410 | ::SetPort( port ) ; | |
411 | *x = localwhere.h ; | |
412 | *y = localwhere.v ; | |
413 | } | |
414 | ||
415 | void wxWindow::MacClientToRootWindow( int *x , int *y ) const | |
416 | { | |
417 | if ( m_macWindowData ) | |
418 | { | |
419 | } | |
420 | else | |
421 | { | |
422 | *x += m_x ; | |
423 | *y += m_y ; | |
424 | GetParent()->MacClientToRootWindow( x , y ) ; | |
425 | } | |
426 | } | |
427 | ||
428 | void wxWindow::MacRootWindowToClient( int *x , int *y ) const | |
429 | { | |
430 | if ( m_macWindowData ) | |
431 | { | |
432 | } | |
433 | else | |
434 | { | |
435 | *x -= m_x ; | |
436 | *y -= m_y ; | |
437 | GetParent()->MacRootWindowToClient( x , y ) ; | |
438 | } | |
e9576ca5 SC |
439 | } |
440 | ||
441 | void wxWindow::SetCursor(const wxCursor& cursor) | |
442 | { | |
443 | m_windowCursor = cursor; | |
444 | if (m_windowCursor.Ok()) | |
445 | { | |
519cb848 SC |
446 | // since this only affects the window-cursor, we adopt the same |
447 | // behaviour as windows -> it will only change on mouse moved events | |
448 | // otherwise the ::WxSetCursor routine will have to be used | |
e9576ca5 SC |
449 | } |
450 | } | |
451 | ||
452 | ||
453 | // Get size *available for subwindows* i.e. excluding menu bar etc. | |
454 | void wxWindow::GetClientSize(int *x, int *y) const | |
455 | { | |
519cb848 SC |
456 | *x = m_width ; |
457 | *y = m_height ; | |
458 | ||
459 | if (m_vScrollBar && m_vScrollBar->IsShown() ) | |
460 | (*x) -= MAC_SCROLLBAR_SIZE; | |
461 | if (m_hScrollBar && m_hScrollBar->IsShown() ) | |
462 | (*y) -= MAC_SCROLLBAR_SIZE; | |
463 | } | |
464 | ||
465 | void wxWindow::DoSetSize(int x, int y, int width, int height, int sizeFlags) | |
466 | { | |
467 | int former_x = m_x ; | |
468 | int former_y = m_y ; | |
469 | int former_w = m_width ; | |
470 | int former_h = m_height ; | |
471 | ||
472 | int currentX, currentY; | |
473 | GetPosition(¤tX, ¤tY); | |
474 | int currentW,currentH; | |
475 | GetSize(¤tW, ¤tH); | |
476 | ||
477 | int actualWidth = width; | |
478 | int actualHeight = height; | |
479 | int actualX = x; | |
480 | int actualY = y; | |
481 | if (x == -1 || (sizeFlags & wxSIZE_ALLOW_MINUS_ONE)) | |
482 | actualX = currentX; | |
483 | if (y == -1 || (sizeFlags & wxSIZE_ALLOW_MINUS_ONE)) | |
484 | actualY = currentY; | |
485 | if (width == -1) | |
486 | actualWidth = currentW ; | |
487 | if (height == -1) | |
488 | actualHeight = currentH ; | |
489 | ||
490 | if ( actualX == currentX && actualY == currentY && actualWidth == currentW && actualHeight == currentH) | |
491 | { | |
492 | MacRepositionScrollBars() ; // we might have a real position shift | |
493 | return ; | |
494 | } | |
e9576ca5 | 495 | |
519cb848 SC |
496 | AdjustForParentClientOrigin(actualX, actualY, sizeFlags); |
497 | ||
498 | ||
499 | bool doMove = false ; | |
500 | bool doResize = false ; | |
501 | ||
502 | if ( actualX != former_x || actualY != former_y ) | |
503 | { | |
504 | doMove = true ; | |
505 | } | |
506 | if ( actualWidth != former_w || actualHeight != former_h ) | |
507 | { | |
508 | doResize = true ; | |
509 | } | |
e9576ca5 | 510 | |
519cb848 SC |
511 | if ( doMove || doResize ) |
512 | { | |
513 | if ( m_macWindowData ) | |
514 | { | |
515 | } | |
516 | else | |
517 | { | |
518 | // erase former position | |
519 | { | |
520 | wxMacDrawingClientHelper focus( this ) ; | |
521 | if ( focus.Ok() ) | |
522 | { | |
523 | Rect clientrect = { 0 , 0 , m_height , m_width } ; | |
524 | InvalRect( &clientrect ) ; | |
525 | } | |
526 | } | |
527 | } | |
528 | m_x = actualX ; | |
529 | m_y = actualY ; | |
530 | m_width = actualWidth ; | |
531 | m_height = actualHeight ; | |
532 | if ( m_macWindowData ) | |
533 | { | |
534 | if ( doMove ) | |
535 | ::MoveWindow(m_macWindowData->m_macWindow, m_x, m_y, false); // don't make frontmost | |
536 | ||
537 | if ( doResize ) | |
538 | ::SizeWindow(m_macWindowData->m_macWindow, m_width, m_height, true); | |
539 | ||
540 | // the OS takes care of invalidating and erasing | |
541 | ||
542 | if ( IsKindOf( CLASSINFO( wxFrame ) ) ) | |
543 | { | |
544 | wxFrame* frame = (wxFrame*) this ; | |
545 | frame->PositionStatusBar(); | |
546 | frame->PositionToolBar(); | |
547 | } | |
548 | } | |
549 | else | |
550 | { | |
551 | // erase new position | |
552 | { | |
553 | wxMacDrawingClientHelper focus( this ) ; | |
554 | if ( focus.Ok() ) | |
555 | { | |
556 | Rect clientrect = { 0 , 0 , m_height , m_width } ; | |
557 | InvalRect( &clientrect ) ; | |
558 | } | |
559 | } | |
560 | if ( doMove ) | |
561 | wxWindow::MacSuperChangedPosition() ; // like this only children will be notified | |
562 | } | |
563 | MacRepositionScrollBars() ; | |
564 | if ( doMove ) | |
565 | { | |
566 | wxMoveEvent event(wxPoint(m_x, m_y), m_windowId); | |
567 | event.SetEventObject(this); | |
568 | GetEventHandler()->ProcessEvent(event) ; | |
569 | } | |
570 | if ( doResize ) | |
571 | { | |
572 | MacRepositionScrollBars() ; | |
573 | wxSizeEvent event(wxSize(m_width, m_height), m_windowId); | |
574 | event.SetEventObject(this); | |
575 | GetEventHandler()->ProcessEvent(event); | |
576 | } | |
577 | } | |
e9576ca5 | 578 | } |
e9576ca5 SC |
579 | // For implementation purposes - sometimes decorations make the client area |
580 | // smaller | |
519cb848 | 581 | |
e9576ca5 SC |
582 | wxPoint wxWindow::GetClientAreaOrigin() const |
583 | { | |
584 | return wxPoint(0, 0); | |
585 | } | |
586 | ||
587 | // Makes an adjustment to the window position (for example, a frame that has | |
588 | // a toolbar that it manages itself). | |
589 | void wxWindow::AdjustForParentClientOrigin(int& x, int& y, int sizeFlags) | |
590 | { | |
519cb848 SC |
591 | if( !m_macWindowData ) |
592 | { | |
e9576ca5 SC |
593 | if (((sizeFlags & wxSIZE_NO_ADJUSTMENTS) == 0) && GetParent()) |
594 | { | |
595 | wxPoint pt(GetParent()->GetClientAreaOrigin()); | |
596 | x += pt.x; y += pt.y; | |
597 | } | |
519cb848 SC |
598 | } |
599 | } | |
600 | ||
601 | void wxWindow::SetTitle(const wxString& title) | |
602 | { | |
603 | wxString label ; | |
604 | ||
605 | if( wxApp::s_macDefaultEncodingIsPC ) | |
606 | label = wxMacMakeMacStringFromPC( title ) ; | |
607 | else | |
608 | label = title ; | |
609 | ||
610 | if ( m_macWindowData ) | |
611 | UMASetWTitleC( m_macWindowData->m_macWindow , label ) ; | |
612 | } | |
613 | ||
614 | wxString wxWindow::GetTitle() const | |
615 | { | |
616 | if ( m_macWindowData ) | |
617 | { | |
618 | char title[256] ; | |
619 | wxString label ; | |
620 | UMAGetWTitleC( m_macWindowData->m_macWindow , title ) ; | |
621 | if( wxApp::s_macDefaultEncodingIsPC ) | |
622 | label = wxMacMakePCStringFromMac( title ) ; | |
623 | else | |
624 | label = title ; | |
625 | return label; | |
626 | } | |
627 | ||
628 | return wxEmptyString ; | |
629 | } | |
630 | ||
631 | void wxWindow::Centre(int direction) | |
632 | { | |
633 | int x_offset,y_offset ; | |
634 | int display_width, display_height; | |
635 | int width, height, x, y; | |
636 | wxWindow *parent = GetParent(); | |
637 | if ((direction & wxCENTER_FRAME) && parent) | |
638 | { | |
639 | parent->GetPosition(&x_offset,&y_offset) ; | |
640 | parent->GetSize(&display_width,&display_height) ; | |
641 | } | |
642 | else | |
643 | { | |
644 | wxDisplaySize(&display_width, &display_height); | |
645 | x_offset = 0 ; | |
646 | y_offset = LMGetMBarHeight() + LMGetMBarHeight() / 2 ; // approx. the window title height | |
647 | } | |
648 | ||
649 | GetSize(&width, &height); | |
650 | GetPosition(&x, &y); | |
651 | ||
652 | if (direction & wxHORIZONTAL) | |
653 | x = (int)((display_width - width)/2); | |
654 | if (direction & wxVERTICAL) | |
655 | y = (int)((display_height - height)/2); | |
656 | ||
657 | SetSize(x+x_offset, y+y_offset, width, height); | |
e9576ca5 SC |
658 | } |
659 | ||
519cb848 | 660 | |
e9576ca5 SC |
661 | bool wxWindow::Show(bool show) |
662 | { | |
519cb848 SC |
663 | if ( m_macShown == show ) |
664 | return TRUE ; | |
665 | ||
666 | m_macShown = show ; | |
667 | if ( m_macWindowData ) | |
668 | { | |
669 | if (show) | |
670 | { | |
671 | UMAShowWindow( m_macWindowData->m_macWindow ) ; | |
672 | UMASelectWindow( m_macWindowData->m_macWindow ) ; | |
673 | // no need to generate events here, they will get them triggered by macos | |
674 | wxSizeEvent event(wxSize(m_width, m_height), m_windowId); | |
675 | event.SetEventObject(this); | |
676 | GetEventHandler()->ProcessEvent(event); | |
677 | } | |
678 | else | |
679 | { | |
680 | UMAHideWindow( m_macWindowData->m_macWindow ) ; | |
681 | } | |
682 | } | |
683 | Refresh() ; | |
684 | MacSuperShown( show ) ; | |
685 | return TRUE; | |
e9576ca5 SC |
686 | } |
687 | ||
688 | bool wxWindow::IsShown() const | |
689 | { | |
519cb848 | 690 | return m_macShown; |
e9576ca5 SC |
691 | } |
692 | ||
693 | int wxWindow::GetCharHeight() const | |
694 | { | |
519cb848 SC |
695 | wxClientDC dc ( (wxWindow*)this ) ; |
696 | return dc.GetCharHeight() ; | |
e9576ca5 SC |
697 | } |
698 | ||
699 | int wxWindow::GetCharWidth() const | |
700 | { | |
519cb848 SC |
701 | wxClientDC dc ( (wxWindow*)this ) ; |
702 | return dc.GetCharWidth() ; | |
e9576ca5 SC |
703 | } |
704 | ||
705 | void wxWindow::GetTextExtent(const wxString& string, int *x, int *y, | |
706 | int *descent, int *externalLeading, const wxFont *theFont, bool) const | |
707 | { | |
708 | wxFont *fontToUse = (wxFont *)theFont; | |
709 | if (!fontToUse) | |
710 | fontToUse = (wxFont *) & m_windowFont; | |
711 | ||
712 | // TODO | |
713 | } | |
714 | ||
519cb848 SC |
715 | void wxWindow::MacEraseBackground( Rect *rect ) |
716 | { | |
717 | WindowRef window = GetMacRootWindow() ; | |
718 | if ( m_backgroundColour == wxSystemSettings::GetSystemColour(wxSYS_COLOUR_APPWORKSPACE) ) | |
719 | { | |
720 | UMASetThemeWindowBackground( window , kThemeBrushDocumentWindowBackground , false ) ; | |
721 | } | |
722 | else if ( m_backgroundColour == wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DFACE ) ) | |
723 | { | |
724 | // on mac we have the difficult situation, that 3dface gray can be different colours, depending whether | |
725 | // it is on a notebook panel or not, in order to take care of that we walk up the hierarchy until we have | |
726 | // either a non gray background color or a non control window | |
727 | ||
728 | wxWindow* parent = GetParent() ; | |
729 | while( parent ) | |
730 | { | |
731 | if ( parent->m_backgroundColour != wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DFACE ) ) | |
732 | { | |
733 | // if we have any other colours in the hierarchy | |
734 | RGBBackColor( &parent->m_backgroundColour.GetPixel()) ; | |
735 | break ; | |
736 | } | |
737 | if( parent->IsKindOf( CLASSINFO( wxControl ) ) && ((wxControl*)parent)->GetMacControl() ) | |
738 | { | |
739 | // if we have the normal colours in the hierarchy but another control etc. -> use it's background | |
740 | if ( parent->IsKindOf( CLASSINFO( wxNotebook ) ) || parent->IsKindOf( CLASSINFO( wxTabCtrl ) )) | |
741 | { | |
742 | ApplyThemeBackground (kThemeBackgroundTabPane, rect, kThemeStateActive,8,true); | |
743 | break ; | |
744 | } | |
745 | } | |
746 | else | |
747 | { | |
748 | // we have arrived at a non control item | |
749 | parent = NULL ; | |
750 | break ; | |
751 | } | |
752 | parent = parent->GetParent() ; | |
753 | } | |
754 | if ( !parent ) | |
755 | { | |
756 | // if there is nothing special -> use default | |
757 | UMASetThemeWindowBackground( window , kThemeBrushDialogBackgroundActive , false ) ; | |
758 | } | |
759 | } | |
760 | else | |
761 | { | |
762 | RGBBackColor( &m_backgroundColour.GetPixel()) ; | |
763 | } | |
764 | ||
765 | EraseRect( rect ) ; | |
766 | ||
767 | for (wxNode *node = m_children->First(); node; node = node->Next()) | |
768 | { | |
769 | wxWindow *child = (wxWindow*)node->Data(); | |
770 | // int width ; | |
771 | // int height ; | |
772 | ||
773 | // child->GetClientSize( &width , &height ) ; | |
774 | ||
775 | Rect clientrect = { child->m_x , child->m_y , child->m_x +child->m_width , child->m_y + child->m_height } ; | |
776 | SectRect( &clientrect , rect , &clientrect ) ; | |
777 | ||
778 | OffsetRect( &clientrect , -child->m_x , -child->m_y ) ; | |
779 | if ( child->GetMacRootWindow() == window && child->IsReallyShown() ) | |
780 | { | |
781 | wxMacDrawingClientHelper focus( this ) ; | |
782 | if ( focus.Ok() ) | |
783 | { | |
784 | child->MacEraseBackground( &clientrect ) ; | |
785 | } | |
786 | } | |
787 | } | |
788 | } | |
789 | ||
e9576ca5 SC |
790 | void wxWindow::Refresh(bool eraseBack, const wxRect *rect) |
791 | { | |
519cb848 SC |
792 | wxMacDrawingClientHelper focus( this ) ; |
793 | if ( focus.Ok() ) | |
794 | { | |
795 | int width , height ; | |
796 | GetClientSize( &width , &height ) ; | |
797 | Rect clientrect = { 0 , 0 , height , width } ; | |
798 | ClipRect( &clientrect ) ; | |
799 | ||
800 | if ( rect ) | |
801 | { | |
802 | Rect r = { rect->y , rect->x , rect->y + rect->height , rect->x + rect->width } ; | |
803 | SectRect( &clientrect , &r , &clientrect ) ; | |
804 | } | |
805 | InvalRect( &clientrect ) ; | |
806 | /* | |
807 | if ( eraseBack ) | |
808 | { | |
809 | MacEraseBackground( &clientrect ) ; | |
810 | } | |
811 | */ | |
812 | } | |
e9576ca5 SC |
813 | } |
814 | ||
815 | // Responds to colour changes: passes event on to children. | |
816 | void wxWindow::OnSysColourChanged(wxSysColourChangedEvent& event) | |
817 | { | |
818 | wxNode *node = GetChildren().First(); | |
819 | while ( node ) | |
820 | { | |
821 | // Only propagate to non-top-level windows | |
822 | wxWindow *win = (wxWindow *)node->Data(); | |
823 | if ( win->GetParent() ) | |
824 | { | |
825 | wxSysColourChangedEvent event2; | |
826 | event.m_eventObject = win; | |
827 | win->GetEventHandler()->ProcessEvent(event2); | |
828 | } | |
829 | ||
830 | node = node->Next(); | |
831 | } | |
832 | } | |
833 | ||
834 | // This can be called by the app (or wxWindows) to do default processing for the current | |
835 | // event. Save message/event info in wxWindow so they can be used in this function. | |
836 | long wxWindow::Default() | |
837 | { | |
838 | // TODO | |
839 | return 0; | |
840 | } | |
841 | ||
842 | void wxWindow::InitDialog() | |
843 | { | |
844 | wxInitDialogEvent event(GetId()); | |
845 | event.SetEventObject( this ); | |
846 | GetEventHandler()->ProcessEvent(event); | |
847 | } | |
848 | ||
849 | // Default init dialog behaviour is to transfer data to window | |
850 | void wxWindow::OnInitDialog(wxInitDialogEvent& event) | |
851 | { | |
852 | TransferDataToWindow(); | |
853 | } | |
854 | ||
855 | // Caret manipulation | |
856 | void wxWindow::CreateCaret(int w, int h) | |
857 | { | |
858 | m_caretWidth = w; | |
859 | m_caretHeight = h; | |
860 | m_caretEnabled = TRUE; | |
861 | } | |
862 | ||
863 | void wxWindow::CreateCaret(const wxBitmap *WXUNUSED(bitmap)) | |
864 | { | |
865 | // TODO | |
866 | } | |
867 | ||
868 | void wxWindow::ShowCaret(bool show) | |
869 | { | |
870 | // TODO | |
871 | } | |
872 | ||
873 | void wxWindow::DestroyCaret() | |
874 | { | |
875 | // TODO | |
876 | m_caretEnabled = FALSE; | |
877 | } | |
878 | ||
879 | void wxWindow::SetCaretPos(int x, int y) | |
880 | { | |
881 | // TODO | |
882 | } | |
883 | ||
884 | void wxWindow::GetCaretPos(int *x, int *y) const | |
885 | { | |
886 | // TODO | |
887 | } | |
888 | ||
889 | wxWindow *wxGetActiveWindow() | |
890 | { | |
519cb848 | 891 | // actually this is a windows-only concept |
e9576ca5 SC |
892 | return NULL; |
893 | } | |
894 | ||
895 | void wxWindow::SetSizeHints(int minW, int minH, int maxW, int maxH, int WXUNUSED(incW), int WXUNUSED(incH)) | |
896 | { | |
897 | m_minSizeX = minW; | |
898 | m_minSizeY = minH; | |
899 | m_maxSizeX = maxW; | |
900 | m_maxSizeY = maxH; | |
901 | } | |
902 | ||
e9576ca5 SC |
903 | |
904 | // Coordinates relative to the window | |
905 | void wxWindow::WarpPointer (int x_pos, int y_pos) | |
906 | { | |
519cb848 | 907 | // We really dont move the mouse programmatically under mac |
e9576ca5 SC |
908 | } |
909 | ||
910 | void wxWindow::OnEraseBackground(wxEraseEvent& event) | |
911 | { | |
519cb848 | 912 | // TODO : probably we would adopt the EraseEvent structure |
e9576ca5 SC |
913 | Default(); |
914 | } | |
915 | ||
916 | int wxWindow::GetScrollPos(int orient) const | |
917 | { | |
519cb848 SC |
918 | if ( orient == wxHORIZONTAL ) |
919 | { | |
920 | if ( m_hScrollBar ) | |
921 | return m_hScrollBar->GetThumbPosition() ; | |
922 | } | |
923 | else | |
924 | { | |
925 | if ( m_vScrollBar ) | |
926 | return m_vScrollBar->GetThumbPosition() ; | |
927 | } | |
e9576ca5 SC |
928 | return 0; |
929 | } | |
930 | ||
931 | // This now returns the whole range, not just the number | |
932 | // of positions that we can scroll. | |
933 | int wxWindow::GetScrollRange(int orient) const | |
934 | { | |
519cb848 SC |
935 | if ( orient == wxHORIZONTAL ) |
936 | { | |
937 | if ( m_hScrollBar ) | |
938 | return m_hScrollBar->GetRange() ; | |
939 | } | |
940 | else | |
941 | { | |
942 | if ( m_vScrollBar ) | |
943 | return m_vScrollBar->GetRange() ; | |
944 | } | |
e9576ca5 SC |
945 | return 0; |
946 | } | |
947 | ||
948 | int wxWindow::GetScrollThumb(int orient) const | |
949 | { | |
519cb848 SC |
950 | if ( orient == wxHORIZONTAL ) |
951 | { | |
952 | if ( m_hScrollBar ) | |
953 | return m_hScrollBar->GetThumbSize() ; | |
954 | } | |
955 | else | |
956 | { | |
957 | if ( m_vScrollBar ) | |
958 | return m_vScrollBar->GetThumbSize() ; | |
959 | } | |
e9576ca5 SC |
960 | return 0; |
961 | } | |
962 | ||
963 | void wxWindow::SetScrollPos(int orient, int pos, bool refresh) | |
964 | { | |
519cb848 SC |
965 | if ( orient == wxHORIZONTAL ) |
966 | { | |
967 | if ( m_hScrollBar ) | |
968 | m_hScrollBar->SetThumbPosition( pos ) ; | |
969 | } | |
970 | else | |
971 | { | |
972 | if ( m_vScrollBar ) | |
973 | m_vScrollBar->SetThumbPosition( pos ) ; | |
974 | } | |
e9576ca5 SC |
975 | } |
976 | ||
977 | // New function that will replace some of the above. | |
978 | void wxWindow::SetScrollbar(int orient, int pos, int thumbVisible, | |
979 | int range, bool refresh) | |
980 | { | |
519cb848 SC |
981 | if ( orient == wxHORIZONTAL ) |
982 | { | |
983 | if ( m_hScrollBar ) | |
984 | { | |
985 | if ( range == 0 || thumbVisible >= range ) | |
986 | { | |
987 | if ( m_hScrollBar->IsShown() ) | |
988 | m_hScrollBar->Show(false) ; | |
989 | } | |
990 | else | |
991 | { | |
992 | if ( !m_hScrollBar->IsShown() ) | |
993 | m_hScrollBar->Show(true) ; | |
994 | m_hScrollBar->SetScrollbar( pos , thumbVisible , range , refresh ) ; | |
995 | } | |
996 | } | |
997 | } | |
998 | else | |
999 | { | |
1000 | if ( m_vScrollBar ) | |
1001 | { | |
1002 | if ( range == 0 || thumbVisible >= range ) | |
1003 | { | |
1004 | if ( m_vScrollBar->IsShown() ) | |
1005 | m_vScrollBar->Show(false) ; | |
1006 | } | |
1007 | else | |
1008 | { | |
1009 | if ( !m_vScrollBar->IsShown() ) | |
1010 | m_vScrollBar->Show(true) ; | |
1011 | m_vScrollBar->SetScrollbar( pos , thumbVisible , range , refresh ) ; | |
1012 | } | |
1013 | } | |
1014 | } | |
1015 | MacRepositionScrollBars() ; | |
e9576ca5 SC |
1016 | } |
1017 | ||
1018 | // Does a physical scroll | |
1019 | void wxWindow::ScrollWindow(int dx, int dy, const wxRect *rect) | |
1020 | { | |
519cb848 SC |
1021 | wxMacDrawingClientHelper focus( this ) ; |
1022 | if ( focus.Ok() ) | |
1023 | { | |
1024 | int width , height ; | |
1025 | GetClientSize( &width , &height ) ; | |
1026 | Rect scrollrect = { 0 , 0 , height , width } ; | |
1027 | ||
1028 | RgnHandle updateRgn = NewRgn() ; | |
1029 | ClipRect( &scrollrect ) ; | |
1030 | if ( rect ) | |
1031 | { | |
1032 | Rect r = { rect->y , rect->x , rect->y + rect->height , rect->x + rect->width } ; | |
1033 | SectRect( &scrollrect , &r , &scrollrect ) ; | |
1034 | } | |
1035 | ScrollRect( &scrollrect , dx , dy , updateRgn ) ; | |
1036 | InvalRgn( updateRgn ) ; | |
1037 | DisposeRgn( updateRgn ) ; | |
1038 | } | |
e9576ca5 SC |
1039 | } |
1040 | ||
1041 | void wxWindow::SetFont(const wxFont& font) | |
1042 | { | |
1043 | m_windowFont = font; | |
1044 | ||
1045 | if (!m_windowFont.Ok()) | |
1046 | return; | |
1047 | // TODO | |
1048 | } | |
1049 | ||
1050 | void wxWindow::OnChar(wxKeyEvent& event) | |
1051 | { | |
1052 | if ( event.KeyCode() == WXK_TAB ) { | |
1053 | // propagate the TABs to the parent - it's up to it to decide what | |
1054 | // to do with it | |
1055 | if ( GetParent() ) { | |
1056 | if ( GetParent()->ProcessEvent(event) ) | |
1057 | return; | |
1058 | } | |
1059 | } | |
1060 | } | |
1061 | ||
1062 | void wxWindow::OnPaint(wxPaintEvent& event) | |
1063 | { | |
519cb848 SC |
1064 | /* |
1065 | if ( m_macWindowData ) | |
1066 | { | |
1067 | wxMacDrawingClientHelper helper ( this ) ; | |
1068 | long x ,y ,w ,h ; | |
1069 | GetUpdateRegion().GetBox( x , y , w , h ) ; | |
1070 | UMASetThemeWindowBackground( m_macWindowData->m_macWindow , m_macWindowData->m_macWindowBackgroundTheme , false ) ; | |
1071 | Rect r = { y , x, y+h , x+w } ; | |
1072 | EraseRect( &r ) ; | |
1073 | } | |
1074 | else | |
1075 | { | |
1076 | wxMacDrawingClientHelper helper ( this ) ; | |
1077 | long x ,y ,w ,h ; | |
1078 | GetUpdateRegion().GetBox( x , y , w , h ) ; | |
1079 | RGBBackColor( &m_backgroundColour.GetPixel() ) ; | |
1080 | Rect r = { y , x, y+h , x+w } ; | |
1081 | EraseRect( &r ) ; | |
1082 | } | |
1083 | */ | |
e9576ca5 SC |
1084 | } |
1085 | ||
1086 | bool wxWindow::IsEnabled() const | |
1087 | { | |
519cb848 | 1088 | return m_macEnabled ; |
e9576ca5 SC |
1089 | } |
1090 | ||
1091 | // Dialog support: override these and call | |
1092 | // base class members to add functionality | |
1093 | // that can't be done using validators. | |
1094 | // NOTE: these functions assume that controls | |
1095 | // are direct children of this window, not grandchildren | |
1096 | // or other levels of descendant. | |
1097 | ||
1098 | // Transfer values to controls. If returns FALSE, | |
1099 | // it's an application error (pops up a dialog) | |
1100 | bool wxWindow::TransferDataToWindow() | |
1101 | { | |
1102 | wxNode *node = GetChildren().First(); | |
1103 | while ( node ) | |
1104 | { | |
1105 | wxWindow *child = (wxWindow *)node->Data(); | |
1106 | if ( child->GetValidator() && | |
1107 | !child->GetValidator()->TransferToWindow() ) | |
1108 | { | |
1109 | wxMessageBox("Application Error", "Could not transfer data to window", wxOK|wxICON_EXCLAMATION); | |
1110 | return FALSE; | |
1111 | } | |
1112 | ||
1113 | node = node->Next(); | |
1114 | } | |
1115 | return TRUE; | |
1116 | } | |
1117 | ||
1118 | // Transfer values from controls. If returns FALSE, | |
1119 | // validation failed: don't quit | |
1120 | bool wxWindow::TransferDataFromWindow() | |
1121 | { | |
1122 | wxNode *node = GetChildren().First(); | |
1123 | while ( node ) | |
1124 | { | |
1125 | wxWindow *child = (wxWindow *)node->Data(); | |
1126 | if ( child->GetValidator() && !child->GetValidator()->TransferFromWindow() ) | |
1127 | { | |
1128 | return FALSE; | |
1129 | } | |
1130 | ||
1131 | node = node->Next(); | |
1132 | } | |
1133 | return TRUE; | |
1134 | } | |
1135 | ||
1136 | bool wxWindow::Validate() | |
1137 | { | |
1138 | wxNode *node = GetChildren().First(); | |
1139 | while ( node ) | |
1140 | { | |
1141 | wxWindow *child = (wxWindow *)node->Data(); | |
1142 | if ( child->GetValidator() && /* child->GetValidator()->Ok() && */ !child->GetValidator()->Validate(this) ) | |
1143 | { | |
1144 | return FALSE; | |
1145 | } | |
1146 | ||
1147 | node = node->Next(); | |
1148 | } | |
1149 | return TRUE; | |
1150 | } | |
1151 | ||
1152 | // Get the window with the focus | |
1153 | wxWindow *wxWindow::FindFocus() | |
1154 | { | |
519cb848 SC |
1155 | return gFocusWindow ; |
1156 | } | |
1157 | ||
1158 | // ---------------------------------------------------------------------------- | |
1159 | // RTTI | |
1160 | // ---------------------------------------------------------------------------- | |
1161 | ||
1162 | bool wxWindow::IsTopLevel() const | |
1163 | { | |
1164 | return wxDynamicCast(this, wxFrame) || wxDynamicCast(this, wxDialog); | |
e9576ca5 SC |
1165 | } |
1166 | ||
1167 | void wxWindow::AddChild(wxWindow *child) | |
1168 | { | |
1169 | GetChildren().Append(child); | |
1170 | child->m_windowParent = this; | |
1171 | } | |
1172 | ||
1173 | void wxWindow::RemoveChild(wxWindow *child) | |
1174 | { | |
1175 | GetChildren().DeleteObject(child); | |
1176 | child->m_windowParent = NULL; | |
1177 | } | |
1178 | ||
1179 | void wxWindow::DestroyChildren() | |
1180 | { | |
1181 | wxNode *node; | |
1182 | while ((node = GetChildren().First()) != (wxNode *)NULL) { | |
1183 | wxWindow *child; | |
1184 | if ((child = (wxWindow *)node->Data()) != (wxWindow *)NULL) { | |
1185 | delete child; | |
519cb848 | 1186 | if ( GetChildren().Find(child) ) |
e9576ca5 SC |
1187 | delete node; |
1188 | } | |
1189 | } /* while */ | |
1190 | } | |
1191 | ||
1192 | void wxWindow::MakeModal(bool modal) | |
1193 | { | |
1194 | // Disable all other windows | |
1195 | if (this->IsKindOf(CLASSINFO(wxDialog)) || this->IsKindOf(CLASSINFO(wxFrame))) | |
1196 | { | |
1197 | wxNode *node = wxTopLevelWindows.First(); | |
1198 | while (node) | |
1199 | { | |
1200 | wxWindow *win = (wxWindow *)node->Data(); | |
1201 | if (win != this) | |
1202 | win->Enable(!modal); | |
1203 | ||
1204 | node = node->Next(); | |
1205 | } | |
1206 | } | |
1207 | } | |
1208 | ||
1209 | // If nothing defined for this, try the parent. | |
1210 | // E.g. we may be a button loaded from a resource, with no callback function | |
1211 | // defined. | |
1212 | void wxWindow::OnCommand(wxWindow& win, wxCommandEvent& event) | |
1213 | { | |
1214 | if (GetEventHandler()->ProcessEvent(event) ) | |
1215 | return; | |
1216 | if (m_windowParent) | |
1217 | m_windowParent->GetEventHandler()->OnCommand(win, event); | |
1218 | } | |
1219 | ||
519cb848 SC |
1220 | // ---------------------------------------------------------------------------- |
1221 | // constraints and sizers | |
1222 | // ---------------------------------------------------------------------------- | |
1223 | ||
1224 | #if wxUSE_CONSTRAINTS | |
1225 | ||
1226 | void wxWindow::SetConstraints( wxLayoutConstraints *constraints ) | |
e9576ca5 | 1227 | { |
519cb848 SC |
1228 | if ( m_constraints ) |
1229 | { | |
1230 | UnsetConstraints(m_constraints); | |
1231 | delete m_constraints; | |
1232 | } | |
1233 | m_constraints = constraints; | |
1234 | if ( m_constraints ) | |
1235 | { | |
1236 | // Make sure other windows know they're part of a 'meaningful relationship' | |
1237 | if ( m_constraints->left.GetOtherWindow() && (m_constraints->left.GetOtherWindow() != this) ) | |
1238 | m_constraints->left.GetOtherWindow()->AddConstraintReference(this); | |
1239 | if ( m_constraints->top.GetOtherWindow() && (m_constraints->top.GetOtherWindow() != this) ) | |
1240 | m_constraints->top.GetOtherWindow()->AddConstraintReference(this); | |
1241 | if ( m_constraints->right.GetOtherWindow() && (m_constraints->right.GetOtherWindow() != this) ) | |
1242 | m_constraints->right.GetOtherWindow()->AddConstraintReference(this); | |
1243 | if ( m_constraints->bottom.GetOtherWindow() && (m_constraints->bottom.GetOtherWindow() != this) ) | |
1244 | m_constraints->bottom.GetOtherWindow()->AddConstraintReference(this); | |
1245 | if ( m_constraints->width.GetOtherWindow() && (m_constraints->width.GetOtherWindow() != this) ) | |
1246 | m_constraints->width.GetOtherWindow()->AddConstraintReference(this); | |
1247 | if ( m_constraints->height.GetOtherWindow() && (m_constraints->height.GetOtherWindow() != this) ) | |
1248 | m_constraints->height.GetOtherWindow()->AddConstraintReference(this); | |
1249 | if ( m_constraints->centreX.GetOtherWindow() && (m_constraints->centreX.GetOtherWindow() != this) ) | |
1250 | m_constraints->centreX.GetOtherWindow()->AddConstraintReference(this); | |
1251 | if ( m_constraints->centreY.GetOtherWindow() && (m_constraints->centreY.GetOtherWindow() != this) ) | |
1252 | m_constraints->centreY.GetOtherWindow()->AddConstraintReference(this); | |
1253 | } | |
e9576ca5 SC |
1254 | } |
1255 | ||
519cb848 SC |
1256 | // This removes any dangling pointers to this window in other windows' |
1257 | // constraintsInvolvedIn lists. | |
e9576ca5 SC |
1258 | void wxWindow::UnsetConstraints(wxLayoutConstraints *c) |
1259 | { | |
519cb848 SC |
1260 | if ( c ) |
1261 | { | |
1262 | if ( c->left.GetOtherWindow() && (c->top.GetOtherWindow() != this) ) | |
1263 | c->left.GetOtherWindow()->RemoveConstraintReference(this); | |
1264 | if ( c->top.GetOtherWindow() && (c->top.GetOtherWindow() != this) ) | |
1265 | c->top.GetOtherWindow()->RemoveConstraintReference(this); | |
1266 | if ( c->right.GetOtherWindow() && (c->right.GetOtherWindow() != this) ) | |
1267 | c->right.GetOtherWindow()->RemoveConstraintReference(this); | |
1268 | if ( c->bottom.GetOtherWindow() && (c->bottom.GetOtherWindow() != this) ) | |
1269 | c->bottom.GetOtherWindow()->RemoveConstraintReference(this); | |
1270 | if ( c->width.GetOtherWindow() && (c->width.GetOtherWindow() != this) ) | |
1271 | c->width.GetOtherWindow()->RemoveConstraintReference(this); | |
1272 | if ( c->height.GetOtherWindow() && (c->height.GetOtherWindow() != this) ) | |
1273 | c->height.GetOtherWindow()->RemoveConstraintReference(this); | |
1274 | if ( c->centreX.GetOtherWindow() && (c->centreX.GetOtherWindow() != this) ) | |
1275 | c->centreX.GetOtherWindow()->RemoveConstraintReference(this); | |
1276 | if ( c->centreY.GetOtherWindow() && (c->centreY.GetOtherWindow() != this) ) | |
1277 | c->centreY.GetOtherWindow()->RemoveConstraintReference(this); | |
1278 | } | |
e9576ca5 SC |
1279 | } |
1280 | ||
519cb848 SC |
1281 | // Back-pointer to other windows we're involved with, so if we delete this |
1282 | // window, we must delete any constraints we're involved with. | |
e9576ca5 SC |
1283 | void wxWindow::AddConstraintReference(wxWindow *otherWin) |
1284 | { | |
519cb848 SC |
1285 | if ( !m_constraintsInvolvedIn ) |
1286 | m_constraintsInvolvedIn = new wxWindowList; | |
1287 | if ( !m_constraintsInvolvedIn->Find(otherWin) ) | |
1288 | m_constraintsInvolvedIn->Append(otherWin); | |
e9576ca5 SC |
1289 | } |
1290 | ||
1291 | // REMOVE back-pointer to other windows we're involved with. | |
1292 | void wxWindow::RemoveConstraintReference(wxWindow *otherWin) | |
1293 | { | |
519cb848 SC |
1294 | if ( m_constraintsInvolvedIn ) |
1295 | m_constraintsInvolvedIn->DeleteObject(otherWin); | |
e9576ca5 SC |
1296 | } |
1297 | ||
1298 | // Reset any constraints that mention this window | |
1299 | void wxWindow::DeleteRelatedConstraints() | |
1300 | { | |
519cb848 | 1301 | if ( m_constraintsInvolvedIn ) |
e9576ca5 | 1302 | { |
519cb848 SC |
1303 | wxWindowList::Node *node = m_constraintsInvolvedIn->GetFirst(); |
1304 | while (node) | |
1305 | { | |
1306 | wxWindow *win = node->GetData(); | |
1307 | wxLayoutConstraints *constr = win->GetConstraints(); | |
1308 | ||
1309 | // Reset any constraints involving this window | |
1310 | if ( constr ) | |
1311 | { | |
1312 | constr->left.ResetIfWin(this); | |
1313 | constr->top.ResetIfWin(this); | |
1314 | constr->right.ResetIfWin(this); | |
1315 | constr->bottom.ResetIfWin(this); | |
1316 | constr->width.ResetIfWin(this); | |
1317 | constr->height.ResetIfWin(this); | |
1318 | constr->centreX.ResetIfWin(this); | |
1319 | constr->centreY.ResetIfWin(this); | |
1320 | } | |
1321 | ||
1322 | wxWindowList::Node *next = node->GetNext(); | |
1323 | delete node; | |
1324 | node = next; | |
1325 | } | |
1326 | ||
1327 | delete m_constraintsInvolvedIn; | |
1328 | m_constraintsInvolvedIn = (wxWindowList *) NULL; | |
e9576ca5 | 1329 | } |
e9576ca5 SC |
1330 | } |
1331 | ||
1332 | void wxWindow::SetSizer(wxSizer *sizer) | |
1333 | { | |
519cb848 SC |
1334 | if (m_windowSizer) delete m_windowSizer; |
1335 | ||
1336 | m_windowSizer = sizer; | |
e9576ca5 SC |
1337 | } |
1338 | ||
e9576ca5 SC |
1339 | bool wxWindow::Layout() |
1340 | { | |
e9576ca5 SC |
1341 | int w, h; |
1342 | GetClientSize(&w, &h); | |
519cb848 SC |
1343 | |
1344 | // If there is a sizer, use it instead of the constraints | |
1345 | if ( GetSizer() ) | |
1346 | { | |
1347 | GetSizer()->SetDimension( 0, 0, w, h ); | |
1348 | return TRUE; | |
1349 | } | |
1350 | ||
1351 | if ( GetConstraints() ) | |
1352 | { | |
1353 | GetConstraints()->width.SetValue(w); | |
1354 | GetConstraints()->height.SetValue(h); | |
1355 | } | |
1356 | ||
1357 | // Evaluate child constraints | |
e9576ca5 SC |
1358 | ResetConstraints(); // Mark all constraints as unevaluated |
1359 | DoPhase(1); // Just one phase need if no sizers involved | |
1360 | DoPhase(2); | |
1361 | SetConstraintSizes(); // Recursively set the real window sizes | |
519cb848 SC |
1362 | |
1363 | return TRUE; | |
e9576ca5 SC |
1364 | } |
1365 | ||
1366 | ||
519cb848 SC |
1367 | // Do a phase of evaluating constraints: the default behaviour. wxSizers may |
1368 | // do a similar thing, but also impose their own 'constraints' and order the | |
1369 | // evaluation differently. | |
e9576ca5 SC |
1370 | bool wxWindow::LayoutPhase1(int *noChanges) |
1371 | { | |
519cb848 SC |
1372 | wxLayoutConstraints *constr = GetConstraints(); |
1373 | if ( constr ) | |
1374 | { | |
1375 | return constr->SatisfyConstraints(this, noChanges); | |
1376 | } | |
1377 | else | |
1378 | return TRUE; | |
e9576ca5 SC |
1379 | } |
1380 | ||
1381 | bool wxWindow::LayoutPhase2(int *noChanges) | |
1382 | { | |
519cb848 SC |
1383 | *noChanges = 0; |
1384 | ||
1385 | // Layout children | |
1386 | DoPhase(1); | |
1387 | DoPhase(2); | |
1388 | return TRUE; | |
e9576ca5 SC |
1389 | } |
1390 | ||
1391 | // Do a phase of evaluating child constraints | |
1392 | bool wxWindow::DoPhase(int phase) | |
1393 | { | |
519cb848 SC |
1394 | int noIterations = 0; |
1395 | int maxIterations = 500; | |
1396 | int noChanges = 1; | |
1397 | int noFailures = 0; | |
1398 | wxWindowList succeeded; | |
1399 | while ((noChanges > 0) && (noIterations < maxIterations)) | |
e9576ca5 | 1400 | { |
519cb848 SC |
1401 | noChanges = 0; |
1402 | noFailures = 0; | |
1403 | wxWindowList::Node *node = GetChildren().GetFirst(); | |
1404 | while (node) | |
e9576ca5 | 1405 | { |
519cb848 SC |
1406 | wxWindow *child = node->GetData(); |
1407 | if ( !child->IsTopLevel() ) | |
e9576ca5 | 1408 | { |
519cb848 SC |
1409 | wxLayoutConstraints *constr = child->GetConstraints(); |
1410 | if ( constr ) | |
1411 | { | |
1412 | if ( !succeeded.Find(child) ) | |
1413 | { | |
1414 | int tempNoChanges = 0; | |
1415 | bool success = ( (phase == 1) ? child->LayoutPhase1(&tempNoChanges) : child->LayoutPhase2(&tempNoChanges) ) ; | |
1416 | noChanges += tempNoChanges; | |
1417 | if ( success ) | |
1418 | { | |
1419 | succeeded.Append(child); | |
1420 | } | |
1421 | } | |
1422 | } | |
e9576ca5 | 1423 | } |
519cb848 | 1424 | node = node->GetNext(); |
e9576ca5 | 1425 | } |
519cb848 SC |
1426 | |
1427 | noIterations++; | |
e9576ca5 | 1428 | } |
519cb848 SC |
1429 | |
1430 | return TRUE; | |
e9576ca5 SC |
1431 | } |
1432 | ||
1433 | void wxWindow::ResetConstraints() | |
1434 | { | |
519cb848 SC |
1435 | wxLayoutConstraints *constr = GetConstraints(); |
1436 | if ( constr ) | |
1437 | { | |
1438 | constr->left.SetDone(FALSE); | |
1439 | constr->top.SetDone(FALSE); | |
1440 | constr->right.SetDone(FALSE); | |
1441 | constr->bottom.SetDone(FALSE); | |
1442 | constr->width.SetDone(FALSE); | |
1443 | constr->height.SetDone(FALSE); | |
1444 | constr->centreX.SetDone(FALSE); | |
1445 | constr->centreY.SetDone(FALSE); | |
1446 | } | |
1447 | wxWindowList::Node *node = GetChildren().GetFirst(); | |
1448 | while (node) | |
1449 | { | |
1450 | wxWindow *win = node->GetData(); | |
1451 | if ( !win->IsTopLevel() ) | |
1452 | win->ResetConstraints(); | |
1453 | node = node->GetNext(); | |
1454 | } | |
e9576ca5 SC |
1455 | } |
1456 | ||
519cb848 SC |
1457 | // Need to distinguish between setting the 'fake' size for windows and sizers, |
1458 | // and setting the real values. | |
e9576ca5 SC |
1459 | void wxWindow::SetConstraintSizes(bool recurse) |
1460 | { | |
519cb848 SC |
1461 | wxLayoutConstraints *constr = GetConstraints(); |
1462 | if ( constr && constr->left.GetDone() && constr->right.GetDone( ) && | |
1463 | constr->width.GetDone() && constr->height.GetDone()) | |
e9576ca5 | 1464 | { |
519cb848 SC |
1465 | int x = constr->left.GetValue(); |
1466 | int y = constr->top.GetValue(); | |
1467 | int w = constr->width.GetValue(); | |
1468 | int h = constr->height.GetValue(); | |
1469 | ||
1470 | if ( (constr->width.GetRelationship() != wxAsIs ) || | |
1471 | (constr->height.GetRelationship() != wxAsIs) ) | |
1472 | { | |
1473 | SetSize(x, y, w, h); | |
1474 | } | |
1475 | else | |
1476 | { | |
1477 | // If we don't want to resize this window, just move it... | |
1478 | Move(x, y); | |
1479 | } | |
e9576ca5 | 1480 | } |
519cb848 | 1481 | else if ( constr ) |
e9576ca5 | 1482 | { |
519cb848 SC |
1483 | char *windowClass = GetClassInfo()->GetClassName(); |
1484 | ||
1485 | wxString winName; | |
1486 | if ( GetName() == _T("") ) | |
1487 | winName = _T("unnamed"); | |
1488 | else | |
1489 | winName = GetName(); | |
1490 | wxLogDebug( _T("Constraint(s) not satisfied for window of type %s, name %s:\n"), | |
1491 | (const char *)windowClass, | |
1492 | (const char *)winName); | |
1493 | if ( !constr->left.GetDone()) wxLogDebug( _T(" unsatisfied 'left' constraint.\n") ); | |
1494 | if ( !constr->right.GetDone()) wxLogDebug( _T(" unsatisfied 'right' constraint.\n") ); | |
1495 | if ( !constr->width.GetDone()) wxLogDebug( _T(" unsatisfied 'width' constraint.\n") ); | |
1496 | if ( !constr->height.GetDone()) wxLogDebug( _T(" unsatisfied 'height' constraint.\n") ); | |
1497 | wxLogDebug( _T("Please check constraints: try adding AsIs() constraints.\n") ); | |
e9576ca5 | 1498 | } |
e9576ca5 | 1499 | |
519cb848 | 1500 | if ( recurse ) |
e9576ca5 | 1501 | { |
519cb848 SC |
1502 | wxWindowList::Node *node = GetChildren().GetFirst(); |
1503 | while (node) | |
1504 | { | |
1505 | wxWindow *win = node->GetData(); | |
1506 | if ( !win->IsTopLevel() ) | |
1507 | win->SetConstraintSizes(); | |
1508 | node = node->GetNext(); | |
1509 | } | |
e9576ca5 | 1510 | } |
e9576ca5 SC |
1511 | } |
1512 | ||
1513 | // Only set the size/position of the constraint (if any) | |
1514 | void wxWindow::SetSizeConstraint(int x, int y, int w, int h) | |
1515 | { | |
519cb848 SC |
1516 | wxLayoutConstraints *constr = GetConstraints(); |
1517 | if ( constr ) | |
e9576ca5 | 1518 | { |
519cb848 SC |
1519 | if ( x != -1 ) |
1520 | { | |
1521 | constr->left.SetValue(x); | |
1522 | constr->left.SetDone(TRUE); | |
1523 | } | |
1524 | if ( y != -1 ) | |
1525 | { | |
1526 | constr->top.SetValue(y); | |
1527 | constr->top.SetDone(TRUE); | |
1528 | } | |
1529 | if ( w != -1 ) | |
1530 | { | |
1531 | constr->width.SetValue(w); | |
1532 | constr->width.SetDone(TRUE); | |
1533 | } | |
1534 | if ( h != -1 ) | |
1535 | { | |
1536 | constr->height.SetValue(h); | |
1537 | constr->height.SetDone(TRUE); | |
1538 | } | |
e9576ca5 | 1539 | } |
e9576ca5 SC |
1540 | } |
1541 | ||
1542 | void wxWindow::MoveConstraint(int x, int y) | |
1543 | { | |
519cb848 SC |
1544 | wxLayoutConstraints *constr = GetConstraints(); |
1545 | if ( constr ) | |
e9576ca5 | 1546 | { |
519cb848 SC |
1547 | if ( x != -1 ) |
1548 | { | |
1549 | constr->left.SetValue(x); | |
1550 | constr->left.SetDone(TRUE); | |
1551 | } | |
1552 | if ( y != -1 ) | |
1553 | { | |
1554 | constr->top.SetValue(y); | |
1555 | constr->top.SetDone(TRUE); | |
1556 | } | |
e9576ca5 | 1557 | } |
e9576ca5 SC |
1558 | } |
1559 | ||
1560 | void wxWindow::GetSizeConstraint(int *w, int *h) const | |
1561 | { | |
519cb848 SC |
1562 | wxLayoutConstraints *constr = GetConstraints(); |
1563 | if ( constr ) | |
1564 | { | |
1565 | *w = constr->width.GetValue(); | |
1566 | *h = constr->height.GetValue(); | |
1567 | } | |
1568 | else | |
1569 | GetSize(w, h); | |
e9576ca5 SC |
1570 | } |
1571 | ||
1572 | void wxWindow::GetClientSizeConstraint(int *w, int *h) const | |
1573 | { | |
519cb848 SC |
1574 | wxLayoutConstraints *constr = GetConstraints(); |
1575 | if ( constr ) | |
1576 | { | |
1577 | *w = constr->width.GetValue(); | |
1578 | *h = constr->height.GetValue(); | |
1579 | } | |
1580 | else | |
1581 | GetClientSize(w, h); | |
e9576ca5 SC |
1582 | } |
1583 | ||
1584 | void wxWindow::GetPositionConstraint(int *x, int *y) const | |
1585 | { | |
519cb848 SC |
1586 | wxLayoutConstraints *constr = GetConstraints(); |
1587 | if ( constr ) | |
1588 | { | |
1589 | *x = constr->left.GetValue(); | |
1590 | *y = constr->top.GetValue(); | |
1591 | } | |
1592 | else | |
1593 | GetPosition(x, y); | |
e9576ca5 SC |
1594 | } |
1595 | ||
519cb848 SC |
1596 | #endif // wxUSE_CONSTRAINTS |
1597 | ||
e9576ca5 SC |
1598 | bool wxWindow::Close(bool force) |
1599 | { | |
1600 | wxCloseEvent event(wxEVT_CLOSE_WINDOW, m_windowId); | |
1601 | event.SetEventObject(this); | |
e3065973 | 1602 | #if WXWIN_COMPATIBILITY |
e9576ca5 | 1603 | event.SetForce(force); |
e3065973 JS |
1604 | #endif |
1605 | event.SetCanVeto(!force); | |
e9576ca5 SC |
1606 | |
1607 | return GetEventHandler()->ProcessEvent(event); | |
1608 | } | |
1609 | ||
1610 | wxObject* wxWindow::GetChild(int number) const | |
1611 | { | |
1612 | // Return a pointer to the Nth object in the window | |
1613 | wxNode *node = GetChildren().First(); | |
1614 | int n = number; | |
1615 | while (node && n--) | |
1616 | node = node->Next() ; | |
1617 | if (node) | |
1618 | { | |
1619 | wxObject *obj = (wxObject *)node->Data(); | |
1620 | return(obj) ; | |
1621 | } | |
1622 | else | |
1623 | return NULL ; | |
1624 | } | |
1625 | ||
1626 | void wxWindow::OnDefaultAction(wxControl *initiatingItem) | |
1627 | { | |
1628 | // Obsolete function | |
1629 | } | |
1630 | ||
1631 | void wxWindow::Clear() | |
1632 | { | |
519cb848 SC |
1633 | if ( m_macWindowData ) |
1634 | { | |
1635 | wxMacDrawingClientHelper helper ( this ) ; | |
1636 | int w ,h ; | |
1637 | wxPoint origin = GetClientAreaOrigin() ; | |
1638 | GetClientSize( &w , &h ) ; | |
1639 | UMASetThemeWindowBackground( m_macWindowData->m_macWindow , m_macWindowData->m_macWindowBackgroundTheme , false ) ; | |
1640 | Rect r = { origin.y , origin.x, origin.y+h , origin.x+w } ; | |
1641 | EraseRect( &r ) ; | |
1642 | } | |
1643 | else | |
1644 | { | |
1645 | wxClientDC dc(this); | |
e9576ca5 SC |
1646 | wxBrush brush(GetBackgroundColour(), wxSOLID); |
1647 | dc.SetBackground(brush); | |
1648 | dc.Clear(); | |
519cb848 | 1649 | } |
e9576ca5 SC |
1650 | } |
1651 | ||
1652 | // Fits the panel around the items | |
1653 | void wxWindow::Fit() | |
1654 | { | |
1655 | int maxX = 0; | |
1656 | int maxY = 0; | |
1657 | wxNode *node = GetChildren().First(); | |
1658 | while ( node ) | |
1659 | { | |
1660 | wxWindow *win = (wxWindow *)node->Data(); | |
1661 | int wx, wy, ww, wh; | |
1662 | win->GetPosition(&wx, &wy); | |
1663 | win->GetSize(&ww, &wh); | |
1664 | if ( wx + ww > maxX ) | |
1665 | maxX = wx + ww; | |
1666 | if ( wy + wh > maxY ) | |
1667 | maxY = wy + wh; | |
1668 | ||
1669 | node = node->Next(); | |
1670 | } | |
1671 | SetClientSize(maxX + 5, maxY + 5); | |
1672 | } | |
1673 | ||
1674 | void wxWindow::SetValidator(const wxValidator& validator) | |
1675 | { | |
1676 | if ( m_windowValidator ) | |
1677 | delete m_windowValidator; | |
1678 | m_windowValidator = validator.Clone(); | |
1679 | ||
1680 | if ( m_windowValidator ) | |
1681 | m_windowValidator->SetWindow(this) ; | |
1682 | } | |
1683 | ||
1684 | void wxWindow::SetAcceleratorTable(const wxAcceleratorTable& accel) | |
1685 | { | |
1686 | m_acceleratorTable = accel; | |
1687 | } | |
1688 | ||
1689 | // Find a window by id or name | |
1690 | wxWindow *wxWindow::FindWindow(long id) | |
1691 | { | |
1692 | if ( GetId() == id) | |
1693 | return this; | |
1694 | ||
1695 | wxNode *node = GetChildren().First(); | |
1696 | while ( node ) | |
1697 | { | |
1698 | wxWindow *child = (wxWindow *)node->Data(); | |
1699 | wxWindow *found = child->FindWindow(id); | |
1700 | if ( found ) | |
1701 | return found; | |
1702 | node = node->Next(); | |
1703 | } | |
1704 | return NULL; | |
1705 | } | |
1706 | ||
1707 | wxWindow *wxWindow::FindWindow(const wxString& name) | |
1708 | { | |
1709 | if ( GetName() == name) | |
1710 | return this; | |
1711 | ||
1712 | wxNode *node = GetChildren().First(); | |
1713 | while ( node ) | |
1714 | { | |
1715 | wxWindow *child = (wxWindow *)node->Data(); | |
1716 | wxWindow *found = child->FindWindow(name); | |
1717 | if ( found ) | |
1718 | return found; | |
1719 | node = node->Next(); | |
1720 | } | |
1721 | return NULL; | |
1722 | } | |
1723 | ||
1724 | void wxWindow::OnIdle(wxIdleEvent& event) | |
1725 | { | |
519cb848 SC |
1726 | /* |
1727 | // Check if we need to send a LEAVE event | |
1728 | if (m_mouseInWindow) | |
1729 | { | |
1730 | POINT pt; | |
1731 | ::GetCursorPos(&pt); | |
1732 | if (::WindowFromPoint(pt) != (HWND) GetHWND()) | |
1733 | { | |
1734 | // Generate a LEAVE event | |
1735 | m_mouseInWindow = FALSE; | |
1736 | MSWOnMouseLeave(pt.x, pt.y, 0); | |
1737 | } | |
e9576ca5 SC |
1738 | } |
1739 | */ | |
1740 | ||
1741 | // This calls the UI-update mechanism (querying windows for | |
1742 | // menu/toolbar/control state information) | |
1743 | UpdateWindowUI(); | |
1744 | } | |
1745 | ||
1746 | // Raise the window to the top of the Z order | |
1747 | void wxWindow::Raise() | |
1748 | { | |
1749 | // TODO | |
1750 | } | |
1751 | ||
1752 | // Lower the window to the bottom of the Z order | |
1753 | void wxWindow::Lower() | |
1754 | { | |
1755 | // TODO | |
1756 | } | |
1757 | ||
1758 | bool wxWindow::AcceptsFocus() const | |
1759 | { | |
519cb848 | 1760 | return IsShown() && IsEnabled() && MacCanFocus() ; |
e9576ca5 SC |
1761 | } |
1762 | ||
1763 | // Update region access | |
1764 | wxRegion wxWindow::GetUpdateRegion() const | |
1765 | { | |
1766 | return m_updateRegion; | |
1767 | } | |
1768 | ||
1769 | bool wxWindow::IsExposed(int x, int y, int w, int h) const | |
1770 | { | |
1771 | return (m_updateRegion.Contains(x, y, w, h) != wxOutRegion); | |
1772 | } | |
1773 | ||
1774 | bool wxWindow::IsExposed(const wxPoint& pt) const | |
1775 | { | |
1776 | return (m_updateRegion.Contains(pt) != wxOutRegion); | |
1777 | } | |
1778 | ||
1779 | bool wxWindow::IsExposed(const wxRect& rect) const | |
1780 | { | |
1781 | return (m_updateRegion.Contains(rect) != wxOutRegion); | |
1782 | } | |
1783 | ||
1784 | /* | |
1785 | * Allocates control IDs | |
1786 | */ | |
1787 | ||
1788 | int wxWindow::NewControlId() | |
1789 | { | |
1790 | static int s_controlId = 0; | |
1791 | s_controlId ++; | |
1792 | return s_controlId; | |
1793 | } | |
1794 | ||
519cb848 SC |
1795 | void wxWindow::DoSetClientSize(int width, int height) |
1796 | { | |
1797 | if ( width != -1 || height != -1 ) | |
1798 | { | |
1799 | ||
1800 | if ( width != -1 && m_vScrollBar ) | |
1801 | width += MAC_SCROLLBAR_SIZE ; | |
1802 | if ( height != -1 && m_vScrollBar ) | |
1803 | height += MAC_SCROLLBAR_SIZE ; | |
1804 | ||
1805 | DoSetSize( -1 , -1 , width , height ) ; | |
1806 | } | |
1807 | } | |
1808 | ||
1809 | // ------------------------ | |
1810 | wxList *wxWinMacWindowList = NULL; | |
1811 | wxWindow *wxFindWinFromMacWindow(WindowRef inWindowRef) | |
1812 | { | |
1813 | wxNode *node = wxWinMacWindowList->Find((long)inWindowRef); | |
1814 | if (!node) | |
1815 | return NULL; | |
1816 | return (wxWindow *)node->Data(); | |
1817 | } | |
1818 | ||
1819 | void wxAssociateWinWithMacWindow(WindowRef inWindowRef, wxWindow *win) | |
1820 | { | |
1821 | // adding NULL WindowRef is (first) surely a result of an error and | |
1822 | // (secondly) breaks menu command processing | |
1823 | wxCHECK_RET( inWindowRef != (WindowRef) NULL, "attempt to add a NULL WindowRef to window list" ); | |
1824 | ||
1825 | if ( !wxWinMacWindowList->Find((long)inWindowRef) ) | |
1826 | wxWinMacWindowList->Append((long)inWindowRef, win); | |
1827 | } | |
1828 | ||
1829 | void wxRemoveMacWindowAssociation(wxWindow *win) | |
1830 | { | |
1831 | wxWinMacWindowList->DeleteObject(win); | |
1832 | } | |
1833 | ||
1834 | wxWindow* wxWindow::s_lastMouseWindow = NULL ; | |
1835 | ||
1836 | bool wxWindow::MacGetWindowFromPointSub( const wxPoint &point , wxWindow** outWin ) | |
1837 | { | |
1838 | if ((point.x < m_x) || (point.y < m_y) || | |
1839 | (point.x > (m_x + m_width)) || (point.y > (m_y + m_height))) | |
1840 | return FALSE; | |
1841 | ||
1842 | WindowRef window = GetMacRootWindow() ; | |
1843 | ||
1844 | wxPoint newPoint( point ) ; | |
1845 | ||
1846 | newPoint.x -= m_x; | |
1847 | newPoint.y -= m_y; | |
1848 | ||
1849 | if ( m_children ) | |
1850 | { | |
1851 | for (wxNode *node = m_children->First(); node; node = node->Next()) | |
1852 | { | |
1853 | wxWindow *child = (wxWindow*)node->Data(); | |
1854 | if ( child->GetMacRootWindow() == window ) | |
1855 | { | |
1856 | if (child->MacGetWindowFromPointSub(newPoint , outWin )) | |
1857 | return TRUE; | |
1858 | } | |
1859 | } | |
1860 | } | |
1861 | ||
1862 | *outWin = this ; | |
1863 | return TRUE; | |
1864 | } | |
1865 | ||
1866 | bool wxWindow::MacGetWindowFromPoint( const wxPoint &screenpoint , wxWindow** outWin ) | |
1867 | { | |
1868 | WindowRef window ; | |
1869 | Point pt = { screenpoint.y , screenpoint.x } ; | |
1870 | if ( ::FindWindow( pt , &window ) == 3 ) | |
1871 | { | |
1872 | wxPoint point( screenpoint ) ; | |
1873 | wxWindow* win = wxFindWinFromMacWindow( window ) ; | |
1874 | win->ScreenToClient( point ) ; | |
1875 | return win->MacGetWindowFromPointSub( point , outWin ) ; | |
1876 | } | |
1877 | return FALSE ; | |
1878 | } | |
1879 | ||
1880 | extern int wxBusyCursorCount ; | |
1881 | ||
1882 | bool wxWindow::MacDispatchMouseEvent(wxMouseEvent& event) | |
1883 | { | |
1884 | if ((event.m_x < m_x) || (event.m_y < m_y) || | |
1885 | (event.m_x > (m_x + m_width)) || (event.m_y > (m_y + m_height))) | |
1886 | return FALSE; | |
1887 | ||
1888 | if ( IsKindOf( CLASSINFO ( wxStaticBox ) ) ) | |
1889 | return FALSE ; | |
1890 | ||
1891 | WindowRef window = GetMacRootWindow() ; | |
1892 | ||
1893 | event.m_x -= m_x; | |
1894 | event.m_y -= m_y; | |
1895 | ||
1896 | int x = event.m_x ; | |
1897 | int y = event.m_y ; | |
1898 | ||
1899 | if ( m_children ) | |
1900 | { | |
1901 | for (wxNode *node = m_children->First(); node; node = node->Next()) | |
1902 | { | |
1903 | wxWindow *child = (wxWindow*)node->Data(); | |
1904 | if ( child->GetMacRootWindow() == window && child->IsReallyShown() && child->IsReallyEnabled() ) | |
1905 | { | |
1906 | if (child->MacDispatchMouseEvent(event)) | |
1907 | return TRUE; | |
1908 | } | |
1909 | } | |
1910 | } | |
1911 | ||
1912 | event.m_x = x ; | |
1913 | event.m_y = y ; | |
1914 | ||
1915 | if ( wxBusyCursorCount == 0 ) | |
1916 | { | |
1917 | m_windowCursor.MacInstall() ; | |
1918 | } | |
1919 | GetEventHandler()->ProcessEvent( event ) ; | |
1920 | return TRUE; | |
1921 | } | |
1922 | ||
1923 | void wxWindow::MacFireMouseEvent( EventRecord *ev ) | |
1924 | { | |
1925 | wxMouseEvent event(wxEVT_LEFT_DOWN); | |
1926 | bool isDown = !(ev->modifiers & btnState) ; // 1 is for up | |
1927 | bool controlDown = ev->modifiers & controlKey ; // for simulating right mouse | |
1928 | ||
1929 | event.m_leftDown = isDown && !controlDown; | |
1930 | event.m_middleDown = FALSE; | |
1931 | event.m_rightDown = isDown && controlDown; | |
1932 | ||
1933 | if ( ev->what == mouseDown ) | |
1934 | { | |
1935 | if ( controlDown ) | |
1936 | event.SetEventType(wxEVT_RIGHT_DOWN ) ; | |
1937 | else | |
1938 | event.SetEventType(wxEVT_LEFT_DOWN ) ; | |
1939 | } | |
1940 | else if ( ev->what == mouseUp ) | |
1941 | { | |
1942 | if ( controlDown ) | |
1943 | event.SetEventType(wxEVT_RIGHT_UP ) ; | |
1944 | else | |
1945 | event.SetEventType(wxEVT_LEFT_UP ) ; | |
1946 | } | |
1947 | else | |
1948 | { | |
1949 | event.SetEventType(wxEVT_MOTION ) ; | |
1950 | } | |
1951 | ||
1952 | event.m_shiftDown = ev->modifiers & shiftKey; | |
1953 | event.m_controlDown = ev->modifiers & controlKey; | |
1954 | event.m_altDown = ev->modifiers & optionKey; | |
1955 | event.m_metaDown = ev->modifiers & cmdKey; | |
1956 | ||
1957 | Point localwhere = ev->where ; | |
1958 | ||
1959 | GrafPtr port ; | |
1960 | ::GetPort( &port ) ; | |
1961 | ::SetPort( UMAGetWindowPort( m_macWindowData->m_macWindow ) ) ; | |
1962 | ::GlobalToLocal( &localwhere ) ; | |
1963 | ::SetPort( port ) ; | |
1964 | ||
1965 | event.m_x = localwhere.h; | |
1966 | event.m_y = localwhere.v; | |
1967 | event.m_x += m_x; | |
1968 | event.m_y += m_y; | |
1969 | ||
1970 | /* | |
1971 | wxPoint origin = GetClientAreaOrigin() ; | |
1972 | ||
1973 | event.m_x += origin.x ; | |
1974 | event.m_y += origin.y ; | |
1975 | */ | |
1976 | ||
1977 | event.m_timeStamp = ev->when; | |
1978 | event.SetEventObject(this); | |
1979 | if ( wxTheApp->s_captureWindow ) | |
1980 | { | |
1981 | int x = event.m_x ; | |
1982 | int y = event.m_y ; | |
1983 | wxTheApp->s_captureWindow->ScreenToClient( &x , &y ) ; | |
1984 | event.m_x = x ; | |
1985 | event.m_y = y ; | |
1986 | wxTheApp->s_captureWindow->GetEventHandler()->ProcessEvent( event ) ; | |
1987 | if ( ev->what == mouseUp ) | |
1988 | { | |
1989 | wxTheApp->s_captureWindow = NULL ; | |
1990 | if ( wxBusyCursorCount == 0 ) | |
1991 | { | |
1992 | m_windowCursor.MacInstall() ; | |
1993 | } | |
1994 | } | |
1995 | } | |
1996 | else | |
1997 | { | |
1998 | MacDispatchMouseEvent( event ) ; | |
1999 | } | |
2000 | } | |
2001 | ||
2002 | void wxWindow::MacMouseDown( EventRecord *ev , short part) | |
2003 | { | |
2004 | MacFireMouseEvent( ev ) ; | |
2005 | } | |
2006 | ||
2007 | void wxWindow::MacMouseUp( EventRecord *ev , short part) | |
2008 | { | |
2009 | WindowPtr frontWindow ; | |
2010 | switch (part) | |
2011 | { | |
2012 | case inContent: | |
2013 | { | |
2014 | MacFireMouseEvent( ev ) ; | |
2015 | } | |
2016 | break ; | |
2017 | } | |
2018 | } | |
2019 | ||
2020 | void wxWindow::MacMouseMoved( EventRecord *ev , short part) | |
2021 | { | |
2022 | WindowPtr frontWindow ; | |
2023 | switch (part) | |
2024 | { | |
2025 | case inContent: | |
2026 | { | |
2027 | MacFireMouseEvent( ev ) ; | |
2028 | } | |
2029 | break ; | |
2030 | } | |
2031 | } | |
2032 | void wxWindow::MacActivate( EventRecord *ev , bool inIsActivating ) | |
2033 | { | |
2034 | wxActivateEvent event(wxEVT_ACTIVATE, inIsActivating); | |
2035 | event.m_timeStamp = ev->when ; | |
2036 | event.SetEventObject(this); | |
2037 | ||
2038 | GetEventHandler()->ProcessEvent(event); | |
2039 | ||
2040 | UMAHighlightAndActivateWindow( m_macWindowData->m_macWindow , inIsActivating ) ; | |
2041 | } | |
2042 | ||
2043 | void wxWindow::MacRedraw( RgnHandle updatergn , long time) | |
2044 | { | |
2045 | // updatergn is always already clipped to our boundaries | |
2046 | WindowRef window = GetMacRootWindow() ; | |
2047 | wxWindow* win = wxFindWinFromMacWindow( window ) ; | |
2048 | { | |
2049 | wxMacDrawingClientHelper focus( this ) ; | |
2050 | if ( focus.Ok() ) | |
2051 | { | |
2052 | WindowRef window = GetMacRootWindow() ; | |
2053 | if ( m_backgroundColour == wxSystemSettings::GetSystemColour(wxSYS_COLOUR_APPWORKSPACE) ) | |
2054 | { | |
2055 | UMASetThemeWindowBackground( window , kThemeBrushDocumentWindowBackground , false ) ; | |
2056 | } | |
2057 | else if ( m_backgroundColour == wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DFACE ) ) | |
2058 | { | |
2059 | // on mac we have the difficult situation, that 3dface gray can be different colours, depending whether | |
2060 | // it is on a notebook panel or not, in order to take care of that we walk up the hierarchy until we have | |
2061 | // either a non gray background color or a non control window | |
2062 | ||
2063 | ||
2064 | wxWindow* parent = GetParent() ; | |
2065 | while( parent ) | |
2066 | { | |
2067 | if ( parent->GetMacRootWindow() != window ) | |
2068 | { | |
2069 | // we are in a different window on the mac system | |
2070 | parent = NULL ; | |
2071 | break ; | |
2072 | } | |
2073 | ||
2074 | if( parent->IsKindOf( CLASSINFO( wxControl ) ) && ((wxControl*)parent)->GetMacControl() ) | |
2075 | { | |
2076 | if ( parent->m_backgroundColour != wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DFACE ) ) | |
2077 | { | |
2078 | // if we have any other colours in the hierarchy | |
2079 | RGBBackColor( &parent->m_backgroundColour.GetPixel()) ; | |
2080 | break ; | |
2081 | } | |
2082 | // if we have the normal colours in the hierarchy but another control etc. -> use it's background | |
2083 | if ( parent->IsKindOf( CLASSINFO( wxNotebook ) ) || parent->IsKindOf( CLASSINFO( wxTabCtrl ) )) | |
2084 | { | |
2085 | ApplyThemeBackground (kThemeBackgroundTabPane, &(**updatergn).rgnBBox , kThemeStateActive,8,true); | |
2086 | break ; | |
2087 | } | |
2088 | } | |
2089 | else | |
2090 | { | |
2091 | parent = NULL ; | |
2092 | break ; | |
2093 | } | |
2094 | parent = parent->GetParent() ; | |
2095 | } | |
2096 | if ( !parent ) | |
2097 | { | |
2098 | // if there is nothing special -> use default | |
2099 | UMASetThemeWindowBackground( window , kThemeBrushDialogBackgroundActive , false ) ; | |
2100 | } | |
2101 | } | |
2102 | else | |
2103 | { | |
2104 | RGBBackColor( &m_backgroundColour.GetPixel()) ; | |
2105 | } | |
2106 | SetClip( updatergn ) ; | |
2107 | EraseRgn( updatergn ) ; | |
2108 | } | |
2109 | } | |
2110 | ||
2111 | ||
2112 | m_updateRegion = updatergn ; | |
2113 | wxPaintEvent event; | |
2114 | event.m_timeStamp = time ; | |
2115 | event.SetEventObject(this); | |
2116 | ||
2117 | GetEventHandler()->ProcessEvent(event); | |
2118 | ||
2119 | RgnHandle childupdate = NewRgn() ; | |
2120 | ||
2121 | for (wxNode *node = m_children->First(); node; node = node->Next()) | |
2122 | { | |
2123 | wxWindow *child = (wxWindow*)node->Data(); | |
2124 | int width ; | |
2125 | int height ; | |
2126 | ||
2127 | child->GetClientSize( &width , &height ) ; | |
2128 | ||
2129 | SetRectRgn( childupdate , child->m_x , child->m_y , child->m_x +width , child->m_y + height ) ; | |
2130 | SectRgn( childupdate , m_updateRegion.GetWXHRGN() , childupdate ) ; | |
2131 | OffsetRgn( childupdate , -child->m_x , -child->m_y ) ; | |
2132 | if ( child->GetMacRootWindow() == window && child->IsReallyShown() ) | |
2133 | { | |
2134 | // because dialogs may also be children | |
2135 | child->MacRedraw( childupdate , time ) ; | |
2136 | } | |
2137 | } | |
2138 | DisposeRgn( childupdate ) ; | |
2139 | // eventually a draw grow box here | |
2140 | } | |
2141 | ||
2142 | void wxWindow::MacUpdateImmediately() | |
2143 | { | |
2144 | WindowRef window = GetMacRootWindow() ; | |
2145 | if ( window ) | |
2146 | { | |
2147 | wxWindow* win = wxFindWinFromMacWindow( window ) ; | |
2148 | BeginUpdate( window ) ; | |
2149 | if ( win ) | |
2150 | { | |
2151 | #if ! TARGET_CARBON | |
2152 | if ( !EmptyRgn( window->visRgn ) ) | |
2153 | #endif | |
2154 | { | |
2155 | win->MacRedraw( window->visRgn , wxTheApp->sm_lastMessageTime ) ; | |
2156 | /* | |
2157 | { | |
2158 | wxMacDrawingHelper help( win ) ; | |
2159 | SetOrigin( 0 , 0 ) ; | |
2160 | UMASetThemeWindowBackground( win->m_macWindowData->m_macWindow , kThemeBrushDialogBackgroundActive , false ) ; | |
2161 | UMAUpdateControls( window , window->visRgn ) ; | |
2162 | UMASetThemeWindowBackground( win->m_macWindowData->m_macWindow , win->m_macWindowData->m_macWindowBackgroundTheme , false ) ; | |
2163 | } | |
2164 | */ | |
2165 | } | |
2166 | } | |
2167 | EndUpdate( window ) ; | |
2168 | } | |
2169 | } | |
2170 | ||
2171 | void wxWindow::MacUpdate( EventRecord *ev ) | |
2172 | { | |
2173 | WindowRef window = (WindowRef) ev->message ; | |
2174 | wxWindow * win = wxFindWinFromMacWindow( window ) ; | |
2175 | ||
2176 | BeginUpdate( window ) ; | |
2177 | if ( win ) | |
2178 | { | |
2179 | // if windowshade gives incompatibility , take the follwing out | |
2180 | #if ! TARGET_CARBON | |
2181 | if ( !EmptyRgn( window->visRgn ) ) | |
2182 | #endif | |
2183 | { | |
2184 | MacRedraw( window->visRgn , ev->when ) ; | |
2185 | /* | |
2186 | { | |
2187 | wxMacDrawingHelper help( this ) ; | |
2188 | SetOrigin( 0 , 0 ) ; | |
2189 | UMASetThemeWindowBackground( m_macWindowData->m_macWindow , kThemeBrushDialogBackgroundActive , false ) ; | |
2190 | UMAUpdateControls( window , window->visRgn ) ; | |
2191 | UMASetThemeWindowBackground( m_macWindowData->m_macWindow , m_macWindowData->m_macWindowBackgroundTheme , false ) ; | |
2192 | } | |
2193 | */ | |
2194 | } | |
2195 | } | |
2196 | EndUpdate( window ) ; | |
2197 | } | |
2198 | ||
2199 | WindowRef wxWindow::GetMacRootWindow() const | |
2200 | { | |
2201 | WindowRef window = NULL ; | |
2202 | wxWindow *iter = (wxWindow*)this ; | |
2203 | ||
2204 | while( iter ) | |
2205 | { | |
2206 | if ( iter->m_macWindowData ) | |
2207 | return iter->m_macWindowData->m_macWindow ; | |
2208 | ||
2209 | iter = iter->GetParent() ; | |
2210 | } | |
2211 | wxASSERT_MSG( 1 , "No valid mac root window" ) ; | |
2212 | return NULL ; | |
2213 | } | |
2214 | ||
2215 | void wxWindow::MacCreateScrollBars( long style ) | |
2216 | { | |
2217 | wxASSERT_MSG( m_vScrollBar == NULL && m_hScrollBar == NULL , "attempt to create window twice" ) ; | |
2218 | bool hasBoth = ( style & wxVSCROLL ) && ( style & wxHSCROLL ) ; | |
2219 | int adjust = hasBoth ? MAC_SCROLLBAR_SIZE - 1: 0 ; | |
2220 | ||
2221 | if ( style & wxVSCROLL ) | |
2222 | { | |
2223 | m_vScrollBar = new wxScrollBar(this, wxWINDOW_VSCROLL, wxPoint(m_width-MAC_SCROLLBAR_SIZE, 0), | |
2224 | wxSize(MAC_SCROLLBAR_SIZE, m_height - adjust), wxVERTICAL); | |
2225 | } | |
2226 | if ( style & wxHSCROLL ) | |
2227 | { | |
2228 | m_hScrollBar = new wxScrollBar(this, wxWINDOW_HSCROLL, wxPoint(0 , m_height-MAC_SCROLLBAR_SIZE ), | |
2229 | wxSize( m_width - adjust, MAC_SCROLLBAR_SIZE), wxHORIZONTAL); | |
2230 | } | |
2231 | // because the create does not take into account the client area origin | |
2232 | MacRepositionScrollBars() ; // we might have a real position shift | |
2233 | } | |
2234 | ||
2235 | void wxWindow::MacRepositionScrollBars() | |
2236 | { | |
2237 | bool hasBoth = ( m_hScrollBar && m_hScrollBar->IsShown()) && ( m_vScrollBar && m_vScrollBar->IsShown()) ; | |
2238 | int adjust = hasBoth ? MAC_SCROLLBAR_SIZE - 1 : 0 ; | |
2239 | ||
2240 | if ( m_vScrollBar ) | |
2241 | { | |
2242 | m_vScrollBar->SetSize( m_width-MAC_SCROLLBAR_SIZE, 0, MAC_SCROLLBAR_SIZE, m_height - adjust , wxSIZE_USE_EXISTING); | |
2243 | } | |
2244 | if ( m_hScrollBar ) | |
2245 | { | |
2246 | m_hScrollBar->SetSize( 0 , m_height-MAC_SCROLLBAR_SIZE ,m_width - adjust, MAC_SCROLLBAR_SIZE, wxSIZE_USE_EXISTING); | |
2247 | } | |
2248 | } | |
2249 | ||
2250 | void wxWindow::MacKeyDown( EventRecord *ev ) | |
2251 | { | |
2252 | } | |
2253 | ||
2254 | ||
2255 | ||
2256 | ||
2257 | ControlHandle wxWindow::MacGetContainerForEmbedding() | |
2258 | { | |
2259 | if ( m_macWindowData ) | |
2260 | return m_macWindowData->m_macRootControl ; | |
2261 | else | |
2262 | return GetParent()->MacGetContainerForEmbedding() ; | |
2263 | } | |
2264 | ||
2265 | void wxWindow::MacSuperChangedPosition() | |
2266 | { | |
2267 | // only window-absolute structures have to be moved i.e. controls | |
2268 | ||
2269 | wxNode *node = GetChildren().First(); | |
2270 | while ( node ) | |
2271 | { | |
2272 | wxWindow *child = (wxWindow *)node->Data(); | |
2273 | child->MacSuperChangedPosition() ; | |
2274 | node = node->Next(); | |
2275 | } | |
2276 | } | |
2277 | ||
2278 | bool wxWindow::IsReallyShown() const | |
2279 | { | |
2280 | if ( m_macWindowData ) | |
2281 | return m_macShown ; | |
2282 | else | |
2283 | return m_macShown && GetParent()->IsReallyShown() ; | |
2284 | } | |
2285 | ||
2286 | bool wxWindow::IsReallyEnabled() const | |
2287 | { | |
2288 | if ( m_macWindowData ) | |
2289 | return m_macEnabled ; | |
2290 | else | |
2291 | return m_macEnabled && GetParent()->IsReallyEnabled() ; | |
2292 | } | |
2293 | ||
2294 | void wxWindow::MacSuperEnabled( bool enabled ) | |
2295 | { | |
2296 | wxNode *node = GetChildren().First(); | |
2297 | while ( node ) | |
2298 | { | |
2299 | wxWindow *child = (wxWindow *)node->Data(); | |
2300 | if ( child->m_macEnabled ) | |
2301 | child->MacSuperEnabled( enabled ) ; | |
2302 | node = node->Next(); | |
2303 | } | |
2304 | } | |
2305 | void wxWindow::MacSuperShown( bool show ) | |
2306 | { | |
2307 | wxNode *node = GetChildren().First(); | |
2308 | while ( node ) | |
2309 | { | |
2310 | wxWindow *child = (wxWindow *)node->Data(); | |
2311 | if ( child->m_macShown ) | |
2312 | child->MacSuperShown( show ) ; | |
2313 | node = node->Next(); | |
2314 | } | |
2315 | } | |
2316 | ||
2317 | bool wxWindow::MacSetupFocusPort( ) | |
2318 | { | |
2319 | Point localOrigin ; | |
2320 | Rect clipRect ; | |
2321 | WindowRef window ; | |
2322 | wxWindow *rootwin ; | |
2323 | GrafPtr port ; | |
2324 | ||
2325 | MacGetPortParams( &localOrigin , &clipRect , &window , &rootwin) ; | |
2326 | return MacSetPortFocusParams( localOrigin, clipRect, window , rootwin ) ; | |
2327 | } | |
2328 | ||
2329 | bool wxWindow::MacSetupFocusClientPort( ) | |
2330 | { | |
2331 | Point localOrigin ; | |
2332 | Rect clipRect ; | |
2333 | WindowRef window ; | |
2334 | wxWindow *rootwin ; | |
2335 | GrafPtr port ; | |
2336 | ||
2337 | MacGetPortClientParams( &localOrigin , &clipRect , &window , &rootwin) ; | |
2338 | return MacSetPortFocusParams( localOrigin, clipRect, window , rootwin ) ; | |
2339 | } | |
2340 | ||
2341 | bool wxWindow::MacSetupDrawingPort( ) | |
2342 | { | |
2343 | Point localOrigin ; | |
2344 | Rect clipRect ; | |
2345 | WindowRef window ; | |
2346 | wxWindow *rootwin ; | |
2347 | GrafPtr port ; | |
2348 | ||
2349 | MacGetPortParams( &localOrigin , &clipRect , &window , &rootwin) ; | |
2350 | return MacSetPortDrawingParams( localOrigin, clipRect, window , rootwin ) ; | |
2351 | } | |
2352 | ||
2353 | bool wxWindow::MacSetupDrawingClientPort( ) | |
2354 | { | |
2355 | Point localOrigin ; | |
2356 | Rect clipRect ; | |
2357 | WindowRef window ; | |
2358 | wxWindow *rootwin ; | |
2359 | GrafPtr port ; | |
2360 | ||
2361 | MacGetPortClientParams( &localOrigin , &clipRect , &window , &rootwin) ; | |
2362 | return MacSetPortDrawingParams( localOrigin, clipRect, window , rootwin ) ; | |
2363 | } | |
2364 | ||
2365 | ||
2366 | bool wxWindow::MacSetPortFocusParams( const Point & localOrigin, const Rect & clipRect, WindowRef window , wxWindow* win ) | |
2367 | { | |
2368 | if ( window == NULL ) | |
2369 | return false ; | |
2370 | ||
2371 | GrafPtr currPort; | |
2372 | GrafPtr port ; | |
2373 | ||
2374 | ::GetPort(&currPort); | |
2375 | port = UMAGetWindowPort( window) ; | |
2376 | if (currPort != port ) | |
2377 | ::SetPort(port); | |
2378 | ||
2379 | ::SetOrigin(-localOrigin.h, -localOrigin.v); | |
2380 | return true; | |
2381 | } | |
2382 | ||
2383 | bool wxWindow::MacSetPortDrawingParams( const Point & localOrigin, const Rect & clipRect, WindowRef window , wxWindow* win ) | |
2384 | { | |
2385 | if ( window == NULL ) | |
2386 | return false ; | |
2387 | ||
2388 | GrafPtr currPort; | |
2389 | GrafPtr port ; | |
2390 | ::GetPort(&currPort); | |
2391 | port = UMAGetWindowPort( window) ; | |
2392 | if (currPort != port ) | |
2393 | ::SetPort(port); | |
2394 | ||
2395 | ::SetOrigin(-localOrigin.h, -localOrigin.v); | |
2396 | ::ClipRect(&clipRect); | |
2397 | ||
2398 | ::PenNormal() ; | |
2399 | ::RGBBackColor(& win->GetBackgroundColour().GetPixel() ) ; | |
2400 | ::RGBForeColor(& win->GetForegroundColour().GetPixel() ) ; | |
2401 | ::BackPat( &qd.white ) ; | |
2402 | ::UMASetThemeWindowBackground( win->m_macWindowData->m_macWindow , win->m_macWindowData->m_macWindowBackgroundTheme , false ) ; | |
2403 | return true; | |
2404 | } | |
2405 | ||
2406 | void wxWindow::MacGetPortParams(Point* localOrigin, Rect* clipRect, WindowRef *window , wxWindow** rootwin) | |
2407 | { | |
2408 | if ( m_macWindowData ) | |
2409 | { | |
2410 | localOrigin->h = 0; | |
2411 | localOrigin->v = 0; | |
2412 | clipRect->left = 0; | |
2413 | clipRect->top = 0; | |
2414 | clipRect->right = m_width; | |
2415 | clipRect->bottom = m_height; | |
2416 | *window = m_macWindowData->m_macWindow ; | |
2417 | *rootwin = this ; | |
2418 | } | |
2419 | else | |
2420 | { | |
2421 | wxASSERT( GetParent() != NULL ) ; | |
2422 | GetParent()->MacGetPortParams( localOrigin , clipRect , window, rootwin) ; | |
2423 | localOrigin->h += m_x; | |
2424 | localOrigin->v += m_y; | |
2425 | OffsetRect(clipRect, -m_x, -m_y); | |
2426 | ||
2427 | Rect myClip; | |
2428 | myClip.left = 0; | |
2429 | myClip.top = 0; | |
2430 | myClip.right = m_width; | |
2431 | myClip.bottom = m_height; | |
2432 | SectRect(clipRect, &myClip, clipRect); | |
2433 | } | |
2434 | } | |
2435 | ||
2436 | void wxWindow::MacGetPortClientParams(Point* localOrigin, Rect* clipRect, WindowRef *window , wxWindow** rootwin ) | |
2437 | { | |
2438 | int width , height ; | |
2439 | GetClientSize( &width , &height ) ; | |
2440 | ||
2441 | if ( m_macWindowData ) | |
2442 | { | |
2443 | localOrigin->h = 0; | |
2444 | localOrigin->v = 0; | |
2445 | clipRect->left = 0; | |
2446 | clipRect->top = 0; | |
2447 | clipRect->right = m_width ;//width; | |
2448 | clipRect->bottom = m_height ;// height; | |
2449 | *window = m_macWindowData->m_macWindow ; | |
2450 | *rootwin = this ; | |
2451 | } | |
2452 | else | |
2453 | { | |
2454 | wxASSERT( GetParent() != NULL ) ; | |
2455 | ||
2456 | GetParent()->MacGetPortClientParams( localOrigin , clipRect , window, rootwin) ; | |
2457 | ||
2458 | localOrigin->h += m_x; | |
2459 | localOrigin->v += m_y; | |
2460 | OffsetRect(clipRect, -m_x, -m_y); | |
2461 | ||
2462 | Rect myClip; | |
2463 | myClip.left = 0; | |
2464 | myClip.top = 0; | |
2465 | myClip.right = width; | |
2466 | myClip.bottom = height; | |
2467 | SectRect(clipRect, &myClip, clipRect); | |
2468 | } | |
2469 | } | |
2470 | ||
2471 | wxMacFocusHelper::wxMacFocusHelper( wxWindow * theWindow ) | |
2472 | { | |
2473 | m_ok = false ; | |
2474 | Point localOrigin ; | |
2475 | Rect clipRect ; | |
2476 | WindowRef window ; | |
2477 | wxWindow *rootwin ; | |
2478 | m_currentPort = NULL ; | |
2479 | GetPort( &m_formerPort ) ; | |
2480 | if ( theWindow ) | |
2481 | { | |
2482 | ||
2483 | theWindow->MacGetPortParams( &localOrigin , &clipRect , &window , &rootwin) ; | |
2484 | m_currentPort = UMAGetWindowPort( window ) ; | |
2485 | theWindow->MacSetPortFocusParams( localOrigin, clipRect, window , rootwin ) ; | |
2486 | m_ok = true ; | |
2487 | } | |
2488 | } | |
2489 | ||
2490 | wxMacFocusHelper::~wxMacFocusHelper() | |
2491 | { | |
2492 | if ( m_ok ) | |
2493 | { | |
2494 | SetOrigin( 0 , 0 ) ; | |
2495 | } | |
2496 | if ( m_formerPort != m_currentPort ) | |
2497 | SetPort( m_formerPort ) ; | |
2498 | } | |
2499 | ||
2500 | wxMacDrawingHelper::wxMacDrawingHelper( wxWindow * theWindow ) | |
2501 | { | |
2502 | m_ok = false ; | |
2503 | Point localOrigin ; | |
2504 | Rect clipRect ; | |
2505 | WindowRef window ; | |
2506 | wxWindow *rootwin ; | |
2507 | m_currentPort = NULL ; | |
2508 | ||
2509 | GetPort( &m_formerPort ) ; | |
2510 | if ( theWindow ) | |
2511 | { | |
2512 | theWindow->MacGetPortParams( &localOrigin , &clipRect , &window , &rootwin) ; | |
2513 | m_currentPort = UMAGetWindowPort( window ) ; | |
2514 | if ( m_formerPort != m_currentPort ) | |
2515 | SetPort( m_currentPort ) ; | |
2516 | GetPenState( &m_savedPenState ) ; | |
2517 | theWindow->MacSetPortDrawingParams( localOrigin, clipRect, window , rootwin ) ; | |
2518 | m_ok = true ; | |
2519 | } | |
2520 | } | |
2521 | ||
2522 | wxMacDrawingHelper::~wxMacDrawingHelper() | |
2523 | { | |
2524 | if ( m_ok ) | |
2525 | { | |
2526 | SetPenState( &m_savedPenState ) ; | |
2527 | SetOrigin( 0 , 0 ) ; | |
2528 | ClipRect( &m_currentPort->portRect ) ; | |
2529 | } | |
2530 | ||
2531 | if ( m_formerPort != m_currentPort ) | |
2532 | SetPort( m_formerPort ) ; | |
2533 | } | |
2534 | ||
2535 | wxMacFocusClientHelper::wxMacFocusClientHelper( wxWindow * theWindow ) | |
2536 | { | |
2537 | m_ok = false ; | |
2538 | Point localOrigin ; | |
2539 | Rect clipRect ; | |
2540 | WindowRef window ; | |
2541 | wxWindow *rootwin ; | |
2542 | m_currentPort = NULL ; | |
2543 | ||
2544 | GetPort( &m_formerPort ) ; | |
2545 | ||
2546 | if ( theWindow ) | |
2547 | { | |
2548 | theWindow->MacGetPortClientParams( &localOrigin , &clipRect , &window , &rootwin) ; | |
2549 | m_currentPort = UMAGetWindowPort( window ) ; | |
2550 | theWindow->MacSetPortFocusParams( localOrigin, clipRect, window , rootwin ) ; | |
2551 | m_ok = true ; | |
2552 | } | |
2553 | } | |
2554 | ||
2555 | wxMacFocusClientHelper::~wxMacFocusClientHelper() | |
2556 | { | |
2557 | if ( m_ok ) | |
2558 | { | |
2559 | SetOrigin( 0 , 0 ) ; | |
2560 | } | |
2561 | if ( m_formerPort != m_currentPort ) | |
2562 | SetPort( m_formerPort ) ; | |
2563 | } | |
2564 | ||
2565 | wxMacDrawingClientHelper::wxMacDrawingClientHelper( wxWindow * theWindow ) | |
2566 | { | |
2567 | m_ok = false ; | |
2568 | Point localOrigin ; | |
2569 | Rect clipRect ; | |
2570 | WindowRef window ; | |
2571 | wxWindow *rootwin ; | |
2572 | m_currentPort = NULL ; | |
2573 | ||
2574 | GetPort( &m_formerPort ) ; | |
2575 | ||
2576 | if ( theWindow ) | |
2577 | { | |
2578 | theWindow->MacGetPortClientParams( &localOrigin , &clipRect , &window , &rootwin) ; | |
2579 | m_currentPort = UMAGetWindowPort( window ) ; | |
2580 | if ( m_formerPort != m_currentPort ) | |
2581 | SetPort( m_currentPort ) ; | |
2582 | GetPenState( &m_savedPenState ) ; | |
2583 | theWindow->MacSetPortDrawingParams( localOrigin, clipRect, window , rootwin ) ; | |
2584 | m_ok = true ; | |
2585 | } | |
2586 | } | |
2587 | ||
2588 | wxMacDrawingClientHelper::~wxMacDrawingClientHelper() | |
2589 | { | |
2590 | if ( m_ok ) | |
2591 | { | |
2592 | SetPenState( &m_savedPenState ) ; | |
2593 | SetOrigin( 0 , 0 ) ; | |
2594 | ClipRect( &m_currentPort->portRect ) ; | |
2595 | } | |
2596 | ||
2597 | if ( m_formerPort != m_currentPort ) | |
2598 | SetPort( m_formerPort ) ; | |
2599 | } | |
2600 | ||
2601 | // ---------------------------------------------------------------------------- | |
2602 | // list classes implementation | |
2603 | // ---------------------------------------------------------------------------- | |
2604 | ||
2605 | void wxWindowListNode::DeleteData() | |
2606 | { | |
2607 | delete (wxWindow *)GetData(); | |
2608 | } | |
e9576ca5 | 2609 |