]> git.saurik.com Git - wxWidgets.git/blame - src/univ/winuniv.cpp
revert memory leak fix, it causes crash
[wxWidgets.git] / src / univ / winuniv.cpp
CommitLineData
1e6feb95 1///////////////////////////////////////////////////////////////////////////////
e4db172a 2// Name: src/univ/window.cpp
1e6feb95
VZ
3// Purpose: implementation of extra wxWindow methods for wxUniv port
4// Author: Vadim Zeitlin
5// Modified by:
6// Created: 06.08.00
7// RCS-ID: $Id$
442b35b5 8// Copyright: (c) 2000 SciTech Software, Inc. (www.scitechsoft.com)
65571936 9// Licence: wxWindows licence
1e6feb95
VZ
10///////////////////////////////////////////////////////////////////////////////
11
12// ===========================================================================
13// declarations
14// ===========================================================================
15
16// ---------------------------------------------------------------------------
17// headers
18// ---------------------------------------------------------------------------
19
1e6feb95
VZ
20// For compilers that support precompilation, includes "wx.h".
21#include "wx/wxprec.h"
22
23#ifdef __BORLANDC__
24 #pragma hdrstop
25#endif
26
e4db172a
WS
27#include "wx/window.h"
28
1e6feb95
VZ
29#ifndef WX_PRECOMP
30 #include "wx/app.h"
1e6feb95
VZ
31 #include "wx/dcclient.h"
32 #include "wx/dcmemory.h"
33 #include "wx/event.h"
34 #include "wx/scrolbar.h"
35 #include "wx/menu.h"
8cb172b4 36 #include "wx/frame.h"
e4db172a 37 #include "wx/log.h"
1e6feb95
VZ
38#endif // WX_PRECOMP
39
40#include "wx/univ/colschem.h"
41#include "wx/univ/renderer.h"
42#include "wx/univ/theme.h"
43
44#if wxUSE_CARET
45 #include "wx/caret.h"
46#endif // wxUSE_CARET
47
48// turn Refresh() debugging on/off
49#define WXDEBUG_REFRESH
50
51#ifndef __WXDEBUG__
52 #undef WXDEBUG_REFRESH
53#endif
54
cff7ef89
VS
55#if defined(WXDEBUG_REFRESH) && defined(__WXMSW__) && !defined(__WXMICROWIN__)
56#include "wx/msw/private.h"
57#endif
58
1e6feb95
VZ
59// ============================================================================
60// implementation
61// ============================================================================
62
63// ----------------------------------------------------------------------------
64// event tables
65// ----------------------------------------------------------------------------
66
67// we can't use wxWindowNative here as it won't be expanded inside the macro
68#if defined(__WXMSW__)
69 IMPLEMENT_DYNAMIC_CLASS(wxWindow, wxWindowMSW)
70#elif defined(__WXGTK__)
71 IMPLEMENT_DYNAMIC_CLASS(wxWindow, wxWindowGTK)
72#elif defined(__WXMGL__)
73 IMPLEMENT_DYNAMIC_CLASS(wxWindow, wxWindowMGL)
b3c86150
VS
74#elif defined(__WXDFB__)
75 IMPLEMENT_DYNAMIC_CLASS(wxWindow, wxWindowDFB)
8354aa92
RR
76#elif defined(__WXX11__)
77 IMPLEMENT_DYNAMIC_CLASS(wxWindow, wxWindowX11)
19193a2c
KB
78#elif defined(__WXPM__)
79 IMPLEMENT_DYNAMIC_CLASS(wxWindow, wxWindowOS2)
1e6feb95
VZ
80#endif
81
82BEGIN_EVENT_TABLE(wxWindow, wxWindowNative)
83 EVT_SIZE(wxWindow::OnSize)
84
85#if wxUSE_ACCEL || wxUSE_MENUS
86 EVT_KEY_DOWN(wxWindow::OnKeyDown)
87#endif // wxUSE_ACCEL
88
89#if wxUSE_MENUS
90 EVT_CHAR(wxWindow::OnChar)
91 EVT_KEY_UP(wxWindow::OnKeyUp)
92#endif // wxUSE_MENUS
93
94 EVT_PAINT(wxWindow::OnPaint)
95 EVT_NC_PAINT(wxWindow::OnNcPaint)
96 EVT_ERASE_BACKGROUND(wxWindow::OnErase)
97END_EVENT_TABLE()
98
99// ----------------------------------------------------------------------------
100// creation
101// ----------------------------------------------------------------------------
102
103void wxWindow::Init()
104{
9a6384ca 105#if wxUSE_SCROLLBAR
1e6feb95
VZ
106 m_scrollbarVert =
107 m_scrollbarHorz = (wxScrollBar *)NULL;
9a6384ca 108#endif // wxUSE_SCROLLBAR
1e6feb95 109
a290fa5a 110 m_isCurrent = false;
1e6feb95
VZ
111
112 m_renderer = wxTheme::Get()->GetRenderer();
2b5f62a0 113
a290fa5a
WS
114 m_oldSize.x = wxDefaultCoord;
115 m_oldSize.y = wxDefaultCoord;
1e6feb95
VZ
116}
117
118bool wxWindow::Create(wxWindow *parent,
119 wxWindowID id,
120 const wxPoint& pos,
121 const wxSize& size,
122 long style,
123 const wxString& name)
124{
588cf92f 125 long actualStyle = style;
8da1f9a9 126
54e90b2a
VS
127 // we add wxCLIP_CHILDREN to get the same ("natural") behaviour under MSW
128 // as under the other platforms
129 actualStyle |= wxCLIP_CHILDREN;
130
588cf92f
JS
131 actualStyle &= ~wxVSCROLL;
132 actualStyle &= ~wxHSCROLL;
54e90b2a 133
d743254a 134#ifdef __WXMSW__
54e90b2a
VS
135 // without this, borders (non-client areas in general) are not repainted
136 // correctly when resizing; apparently, native NC areas are fully repainted
137 // even without this style by MSW, but wxUniv implements client area
138 // itself, so it doesn't work correctly for us
139 //
140 // FIXME: this is very expensive, we need to fix the (commented-out) code
141 // in OnSize() instead
142 actualStyle |= wxFULL_REPAINT_ON_RESIZE;
8da1f9a9
VZ
143#endif
144
54e90b2a 145 if ( !wxWindowNative::Create(parent, id, pos, size, actualStyle, name) )
a290fa5a 146 return false;
1e6feb95 147
588cf92f
JS
148 // Set full style again, including those we didn't want present
149 // when calling the base window Create().
150 wxWindowBase::SetWindowStyleFlag(style);
151
1cb853a8
JS
152 // if we allow or should always have a vertical scrollbar, make it
153 if ( style & wxVSCROLL || style & wxALWAYS_SHOW_SB )
1e6feb95 154 {
ab6b6b15 155#if wxUSE_TWO_WINDOWS
a290fa5a 156 SetInsertIntoMain( true );
ab6b6b15 157#endif
9a6384ca 158#if wxUSE_SCROLLBAR
a290fa5a 159 m_scrollbarVert = new wxScrollBar(this, wxID_ANY,
1e6feb95
VZ
160 wxDefaultPosition, wxDefaultSize,
161 wxSB_VERTICAL);
9a6384ca 162#endif // wxUSE_SCROLLBAR
ab6b6b15 163#if wxUSE_TWO_WINDOWS
a290fa5a 164 SetInsertIntoMain( false );
ab6b6b15 165#endif
588cf92f 166 }
1e6feb95 167
1cb853a8 168 // if we should allow a horizontal scrollbar, make it
588cf92f
JS
169 if ( style & wxHSCROLL )
170 {
171#if wxUSE_TWO_WINDOWS
a290fa5a 172 SetInsertIntoMain( true );
588cf92f 173#endif
9a6384ca 174#if wxUSE_SCROLLBAR
a290fa5a 175 m_scrollbarHorz = new wxScrollBar(this, wxID_ANY,
588cf92f
JS
176 wxDefaultPosition, wxDefaultSize,
177 wxSB_HORIZONTAL);
9a6384ca 178#endif // wxUSE_SCROLLBAR
588cf92f 179#if wxUSE_TWO_WINDOWS
a290fa5a 180 SetInsertIntoMain( false );
588cf92f
JS
181#endif
182 }
8da1f9a9 183
9a6384ca 184#if wxUSE_SCROLLBAR
588cf92f
JS
185 if (m_scrollbarHorz || m_scrollbarVert)
186 {
187 // position it/them
1e6feb95
VZ
188 PositionScrollbars();
189 }
9a6384ca 190#endif // wxUSE_SCROLLBAR
1e6feb95 191
a290fa5a 192 return true;
1e6feb95
VZ
193}
194
8da1f9a9
VZ
195wxWindow::~wxWindow()
196{
197 m_isBeingDeleted = true;
198
199 // we have to destroy our children before we're destroyed because our
200 // children suppose that we're of type wxWindow, not just wxWindowNative,
201 // and so bad things may happen if they're deleted from the base class dtor
202 // as by then we're not a wxWindow any longer and wxUniv-specific virtual
203 // functions can't be called
204 DestroyChildren();
205}
206
1e6feb95
VZ
207// ----------------------------------------------------------------------------
208// background pixmap
209// ----------------------------------------------------------------------------
210
211void wxWindow::SetBackground(const wxBitmap& bitmap,
212 int alignment,
213 wxStretch stretch)
214{
215 m_bitmapBg = bitmap;
216 m_alignBgBitmap = alignment;
217 m_stretchBgBitmap = stretch;
218}
219
220const wxBitmap& wxWindow::GetBackgroundBitmap(int *alignment,
221 wxStretch *stretch) const
222{
223 if ( m_bitmapBg.Ok() )
224 {
225 if ( alignment )
226 *alignment = m_alignBgBitmap;
227 if ( stretch )
228 *stretch = m_stretchBgBitmap;
229 }
230
231 return m_bitmapBg;
232}
233
234// ----------------------------------------------------------------------------
235// painting
236// ----------------------------------------------------------------------------
237
1e6feb95 238// the event handlers executed when the window must be repainted
3795cdba 239void wxWindow::OnNcPaint(wxNcPaintEvent& WXUNUSED(event))
1e6feb95
VZ
240{
241 if ( m_renderer )
242 {
243 // get the window rect
9a6384ca 244 wxRect rect(GetSize());
1e6feb95 245
9a6384ca 246#if wxUSE_SCROLLBAR
1e6feb95
VZ
247 // if the scrollbars are outside the border, we must adjust the rect to
248 // exclude them
249 if ( !m_renderer->AreScrollbarsInsideBorder() )
250 {
251 wxScrollBar *scrollbar = GetScrollbar(wxVERTICAL);
252 if ( scrollbar )
253 rect.width -= scrollbar->GetSize().x;
254
255 scrollbar = GetScrollbar(wxHORIZONTAL);
256 if ( scrollbar )
257 rect.height -= scrollbar->GetSize().y;
258 }
9a6384ca 259#endif // wxUSE_SCROLLBAR
1e6feb95
VZ
260
261 // get the DC and draw the border on it
262 wxWindowDC dc(this);
263 DoDrawBorder(dc, rect);
264 }
265}
266
267void wxWindow::OnPaint(wxPaintEvent& event)
268{
269 if ( !m_renderer )
270 {
271 // it is a native control which paints itself
272 event.Skip();
273 }
274 else
275 {
276 // get the DC to use and create renderer on it
277 wxPaintDC dc(this);
278 wxControlRenderer renderer(this, dc, m_renderer);
279
280 // draw the control
281 DoDraw(&renderer);
282 }
283}
284
5ebcf581
RR
285// the event handler executed when the window background must be painted
286void wxWindow::OnErase(wxEraseEvent& event)
287{
288 if ( !m_renderer )
289 {
290 event.Skip();
291
292 return;
293 }
2b5f62a0 294
5ebcf581
RR
295 DoDrawBackground(*event.GetDC());
296
9a6384ca 297#if wxUSE_SCROLLBAR
5ebcf581
RR
298 // if we have both scrollbars, we also have a square in the corner between
299 // them which we must paint
300 if ( m_scrollbarVert && m_scrollbarHorz )
301 {
302 wxSize size = GetSize();
303 wxRect rectClient = GetClientRect(),
304 rectBorder = m_renderer->GetBorderDimensions(GetBorder());
305
306 wxRect rectCorner;
307 rectCorner.x = rectClient.GetRight() + 1;
308 rectCorner.y = rectClient.GetBottom() + 1;
309 rectCorner.SetRight(size.x - rectBorder.width);
310 rectCorner.SetBottom(size.y - rectBorder.height);
311
312 if ( GetUpdateRegion().Contains(rectCorner) )
313 {
314 m_renderer->DrawScrollCorner(*event.GetDC(), rectCorner);
315 }
316 }
9a6384ca 317#endif // wxUSE_SCROLLBAR
5ebcf581
RR
318}
319
1e6feb95
VZ
320bool wxWindow::DoDrawBackground(wxDC& dc)
321{
1e6feb95 322 wxRect rect;
2b5f62a0 323
5ebcf581
RR
324 wxSize size = GetSize(); // Why not GetClientSize() ?
325 rect.x = 0;
326 rect.y = 0;
327 rect.width = size.x;
328 rect.height = size.y;
2b5f62a0
VZ
329
330 wxWindow * const parent = GetParent();
3d74a760 331 if ( HasTransparentBackground() && parent )
1e6feb95 332 {
5ebcf581 333 wxASSERT( !IsTopLevel() );
2b5f62a0 334
5ebcf581 335 wxPoint pos = GetPosition();
2b5f62a0 336
5ebcf581 337 AdjustForParentClientOrigin( pos.x, pos.y, 0 );
2b5f62a0 338
5ebcf581 339 // Adjust DC logical origin
635eb8bc
JS
340 wxCoord org_x, org_y, x, y;
341 dc.GetLogicalOrigin( &org_x, &org_y );
342 x = org_x + pos.x;
343 y = org_y + pos.y;
5ebcf581 344 dc.SetLogicalOrigin( x, y );
2b5f62a0 345
5ebcf581
RR
346 // Adjust draw rect
347 rect.x = pos.x;
348 rect.y = pos.y;
2b5f62a0 349
5ebcf581 350 // Let parent draw the background
2b5f62a0 351 parent->EraseBackground( dc, rect );
635eb8bc
JS
352
353 // Restore DC logical origin
354 dc.SetLogicalOrigin( org_x, org_y );
1e6feb95 355 }
5ebcf581
RR
356 else
357 {
90e572f1 358 // Draw background ourselves
2b5f62a0 359 EraseBackground( dc, rect );
5ebcf581 360 }
2b5f62a0 361
a290fa5a 362 return true;
5ebcf581 363}
1e6feb95 364
5ebcf581
RR
365void wxWindow::EraseBackground(wxDC& dc, const wxRect& rect)
366{
1e6feb95
VZ
367 if ( GetBackgroundBitmap().Ok() )
368 {
5ebcf581 369 // Get the bitmap and the flags
1e6feb95
VZ
370 int alignment;
371 wxStretch stretch;
372 wxBitmap bmp = GetBackgroundBitmap(&alignment, &stretch);
373 wxControlRenderer::DrawBitmap(dc, bmp, rect, alignment, stretch);
374 }
2b5f62a0 375 else
1e6feb95 376 {
5ebcf581 377 // Just fill it with bg colour if no bitmap
2b5f62a0 378
1e6feb95
VZ
379 m_renderer->DrawBackground(dc, wxTHEME_BG_COLOUR(this),
380 rect, GetStateFlags());
381 }
1e6feb95
VZ
382}
383
384void wxWindow::DoDrawBorder(wxDC& dc, const wxRect& rect)
385{
386 // draw outline unless the update region is enitrely inside it in which
387 // case we don't need to do it
388#if 0 // doesn't seem to work, why?
389 if ( wxRegion(rect).Contains(GetUpdateRegion().GetBox()) != wxInRegion )
390#endif
391 {
392 m_renderer->DrawBorder(dc, GetBorder(), rect, GetStateFlags());
393 }
394}
395
61fef19b 396void wxWindow::DoDraw(wxControlRenderer * WXUNUSED(renderer))
1e6feb95
VZ
397{
398}
399
6ef4b814 400void wxWindow::Refresh(bool eraseBackground, const wxRect *rect)
1e6feb95 401{
6ef4b814
VS
402 wxRect rectClient; // the same rectangle in client coordinates
403 wxPoint origin = GetClientAreaOrigin();
1e6feb95
VZ
404
405 wxSize size = GetClientSize();
406
6ef4b814 407 if ( rect )
1e6feb95 408 {
6ef4b814
VS
409 // the rectangle passed as argument is in client coordinates
410 rectClient = *rect;
1e6feb95
VZ
411
412 // don't refresh anything beyond the client area (scrollbars for
413 // example)
6ef4b814
VS
414 if ( rectClient.GetRight() > size.x )
415 rectClient.SetRight(size.x);
416 if ( rectClient.GetBottom() > size.y )
417 rectClient.SetBottom(size.y);
1e6feb95 418
1e6feb95
VZ
419 }
420 else // refresh the entire client area
421 {
6ef4b814
VS
422 // x,y is already set to 0 by default
423 rectClient.SetSize(size);
1e6feb95
VZ
424 }
425
6ef4b814
VS
426 // convert refresh rectangle to window coordinates:
427 wxRect rectWin(rectClient);
428 rectWin.Offset(origin);
429
1e6feb95
VZ
430 // debugging helper
431#ifdef WXDEBUG_REFRESH
a290fa5a 432 static bool s_refreshDebug = false;
1e6feb95
VZ
433 if ( s_refreshDebug )
434 {
435 wxWindowDC dc(this);
436 dc.SetBrush(*wxCYAN_BRUSH);
437 dc.SetPen(*wxTRANSPARENT_PEN);
438 dc.DrawRectangle(rectWin);
439
440 // under Unix we use "--sync" X option for this
8cb172b4 441 #if defined(__WXMSW__) && !defined(__WXMICROWIN__)
1e6feb95
VZ
442 ::GdiFlush();
443 ::Sleep(200);
444 #endif // __WXMSW__
445 }
446#endif // WXDEBUG_REFRESH
447
448 wxWindowNative::Refresh(eraseBackground, &rectWin);
82e5f91b
JS
449
450 // Refresh all sub controls if any.
6ef4b814
VS
451 wxWindowList& children = GetChildren();
452 for ( wxWindowList::iterator i = children.begin(); i != children.end(); ++i )
82e5f91b 453 {
6ef4b814
VS
454 wxWindow *child = *i;
455 // only refresh subcontrols if they are visible:
456 if ( child->IsTopLevel() || !child->IsShown() || child->IsFrozen() )
457 continue;
458
459 // ...and when the subcontrols are in the update region:
460 wxRect childrect(child->GetRect());
461 childrect.Intersect(rectClient);
462 if ( childrect.IsEmpty() )
463 continue;
464
465 // refresh the subcontrol now:
466 childrect.Offset(-child->GetPosition());
467 // NB: We must call wxWindowNative version because we need to refresh
468 // the entire control, not just its client area, and this is why we
469 // don't account for child client area origin here neither. Also
470 // note that we don't pass eraseBackground to the child, but use
471 // true instead: this is because we can't be sure that
472 // eraseBackground=false is safe for children as well and not only
473 // for the parent.
474 child->wxWindowNative::Refresh(eraseBackground, &childrect);
82e5f91b 475 }
1e6feb95
VZ
476}
477
478// ----------------------------------------------------------------------------
479// state flags
480// ----------------------------------------------------------------------------
481
482bool wxWindow::Enable(bool enable)
483{
484 if ( !wxWindowNative::Enable(enable) )
a290fa5a 485 return false;
1e6feb95
VZ
486
487 // disabled window can't keep focus
c4bcd8fc 488 if ( FindFocus() == this && GetParent() != NULL )
1e6feb95
VZ
489 {
490 GetParent()->SetFocus();
491 }
492
493 if ( m_renderer )
494 {
495 // a window with renderer is drawn by ourselves and it has to be
496 // refreshed to reflect its new status
497 Refresh();
498 }
499
a290fa5a 500 return true;
1e6feb95
VZ
501}
502
503bool wxWindow::IsFocused() const
504{
5625d0d4 505 return FindFocus() == this;
1e6feb95
VZ
506}
507
508bool wxWindow::IsPressed() const
509{
a290fa5a 510 return false;
1e6feb95
VZ
511}
512
513bool wxWindow::IsDefault() const
514{
a290fa5a 515 return false;
1e6feb95
VZ
516}
517
518bool wxWindow::IsCurrent() const
519{
520 return m_isCurrent;
521}
522
523bool wxWindow::SetCurrent(bool doit)
524{
525 if ( doit == m_isCurrent )
a290fa5a 526 return false;
1e6feb95
VZ
527
528 m_isCurrent = doit;
529
530 if ( CanBeHighlighted() )
531 Refresh();
532
a290fa5a 533 return true;
1e6feb95
VZ
534}
535
536int wxWindow::GetStateFlags() const
537{
538 int flags = 0;
539 if ( !IsEnabled() )
540 flags |= wxCONTROL_DISABLED;
541
542 // the following states are only possible if our application is active - if
543 // it is not, even our default/focused controls shouldn't appear as such
544 if ( wxTheApp->IsActive() )
545 {
546 if ( IsCurrent() )
547 flags |= wxCONTROL_CURRENT;
548 if ( IsFocused() )
549 flags |= wxCONTROL_FOCUSED;
550 if ( IsPressed() )
551 flags |= wxCONTROL_PRESSED;
552 if ( IsDefault() )
553 flags |= wxCONTROL_ISDEFAULT;
554 }
555
556 return flags;
557}
558
559// ----------------------------------------------------------------------------
560// size
561// ----------------------------------------------------------------------------
562
563void wxWindow::OnSize(wxSizeEvent& event)
564{
aae73669 565 event.Skip();
2b5f62a0 566
9a6384ca 567#if wxUSE_SCROLLBAR
1e6feb95
VZ
568 if ( m_scrollbarVert || m_scrollbarHorz )
569 {
570 PositionScrollbars();
571 }
9a6384ca 572#endif // wxUSE_SCROLLBAR
2b5f62a0 573
ab6b6b15 574#if 0 // ndef __WXMSW__
ec47a147 575 // Refresh the area (strip) previously occupied by the border
2b5f62a0 576
e441e1f4 577 if ( !HasFlag(wxFULL_REPAINT_ON_RESIZE) && IsShown() )
ec47a147 578 {
aae73669
RR
579 // This code assumes that wxSizeEvent.GetSize() returns
580 // the area of the entire window, not just the client
581 // area.
ec47a147 582 wxSize newSize = event.GetSize();
2b5f62a0 583
a290fa5a 584 if (m_oldSize.x == wxDefaultCoord && m_oldSize.y == wxDefaultCoord)
aae73669
RR
585 {
586 m_oldSize = newSize;
587 return;
588 }
2b5f62a0 589
ec47a147
RR
590 if (HasFlag( wxSIMPLE_BORDER ))
591 {
592 if (newSize.y > m_oldSize.y)
593 {
594 wxRect rect;
595 rect.x = 0;
596 rect.width = m_oldSize.x;
aae73669 597 rect.y = m_oldSize.y-2;
ec47a147 598 rect.height = 1;
a290fa5a 599 Refresh( true, &rect );
ec47a147 600 }
aae73669
RR
601 else if (newSize.y < m_oldSize.y)
602 {
603 wxRect rect;
604 rect.y = newSize.y;
605 rect.x = 0;
606 rect.height = 1;
607 rect.width = newSize.x;
a290fa5a 608 wxWindowNative::Refresh( true, &rect );
aae73669 609 }
2b5f62a0 610
ec47a147
RR
611 if (newSize.x > m_oldSize.x)
612 {
613 wxRect rect;
614 rect.y = 0;
615 rect.height = m_oldSize.y;
aae73669 616 rect.x = m_oldSize.x-2;
ec47a147 617 rect.width = 1;
a290fa5a 618 Refresh( true, &rect );
ec47a147 619 }
aae73669
RR
620 else if (newSize.x < m_oldSize.x)
621 {
622 wxRect rect;
623 rect.x = newSize.x;
624 rect.y = 0;
625 rect.width = 1;
626 rect.height = newSize.y;
a290fa5a 627 wxWindowNative::Refresh( true, &rect );
aae73669 628 }
ec47a147
RR
629 }
630 else
631 if (HasFlag( wxSUNKEN_BORDER ) || HasFlag( wxRAISED_BORDER ))
632 {
633 if (newSize.y > m_oldSize.y)
634 {
635 wxRect rect;
636 rect.x = 0;
637 rect.width = m_oldSize.x;
aae73669 638 rect.y = m_oldSize.y-4;
ec47a147 639 rect.height = 2;
a290fa5a 640 Refresh( true, &rect );
ec47a147 641 }
aae73669
RR
642 else if (newSize.y < m_oldSize.y)
643 {
644 wxRect rect;
645 rect.y = newSize.y;
646 rect.x = 0;
647 rect.height = 2;
648 rect.width = newSize.x;
a290fa5a 649 wxWindowNative::Refresh( true, &rect );
aae73669 650 }
2b5f62a0 651
ec47a147
RR
652 if (newSize.x > m_oldSize.x)
653 {
654 wxRect rect;
655 rect.y = 0;
656 rect.height = m_oldSize.y;
aae73669 657 rect.x = m_oldSize.x-4;
ec47a147 658 rect.width = 2;
a290fa5a 659 Refresh( true, &rect );
ec47a147 660 }
aae73669
RR
661 else if (newSize.x < m_oldSize.x)
662 {
663 wxRect rect;
664 rect.x = newSize.x;
665 rect.y = 0;
666 rect.width = 2;
667 rect.height = newSize.y;
a290fa5a 668 wxWindowNative::Refresh( true, &rect );
aae73669 669 }
ec47a147 670 }
2b5f62a0 671
ec47a147
RR
672 m_oldSize = newSize;
673 }
674#endif
1e6feb95
VZ
675}
676
677wxSize wxWindow::DoGetBestSize() const
678{
679 return AdjustSize(DoGetBestClientSize());
680}
681
682wxSize wxWindow::DoGetBestClientSize() const
683{
684 return wxWindowNative::DoGetBestSize();
685}
686
687wxSize wxWindow::AdjustSize(const wxSize& size) const
688{
689 wxSize sz = size;
690 if ( m_renderer )
691 m_renderer->AdjustSize(&sz, this);
692 return sz;
693}
694
695wxPoint wxWindow::GetClientAreaOrigin() const
696{
697 wxPoint pt = wxWindowBase::GetClientAreaOrigin();
698
ab6b6b15
RR
699#if wxUSE_TWO_WINDOWS
700#else
1e6feb95
VZ
701 if ( m_renderer )
702 pt += m_renderer->GetBorderDimensions(GetBorder()).GetPosition();
ab6b6b15 703#endif
1e6feb95
VZ
704
705 return pt;
706}
707
708void wxWindow::DoGetClientSize(int *width, int *height) const
709{
3379ed37
VZ
710 // if it is a native window, we assume it handles the scrollbars itself
711 // too - and if it doesn't, there is not much we can do
712 if ( !m_renderer )
713 {
714 wxWindowNative::DoGetClientSize(width, height);
715
716 return;
717 }
718
1e6feb95
VZ
719 int w, h;
720 wxWindowNative::DoGetClientSize(&w, &h);
721
722 // we assume that the scrollbars are positioned correctly (by a previous
723 // call to PositionScrollbars()) here
724
725 wxRect rectBorder;
726 if ( m_renderer )
727 rectBorder = m_renderer->GetBorderDimensions(GetBorder());
728
1e6feb95
VZ
729 if ( width )
730 {
9a6384ca 731#if wxUSE_SCROLLBAR
1e6feb95
VZ
732 // in any case, take account of the scrollbar
733 if ( m_scrollbarVert )
734 w -= m_scrollbarVert->GetSize().x;
9a6384ca 735#endif // wxUSE_SCROLLBAR
1e6feb95 736
4eb124f5
VS
737 // account for the left and right borders
738 *width = w - rectBorder.x - rectBorder.width;
1e6feb95
VZ
739
740 // we shouldn't return invalid width
741 if ( *width < 0 )
742 *width = 0;
743 }
744
745 if ( height )
746 {
9a6384ca 747#if wxUSE_SCROLLBAR
1e6feb95
VZ
748 if ( m_scrollbarHorz )
749 h -= m_scrollbarHorz->GetSize().y;
9a6384ca 750#endif // wxUSE_SCROLLBAR
1e6feb95 751
4eb124f5 752 *height = h - rectBorder.y - rectBorder.height;
1e6feb95
VZ
753
754 // we shouldn't return invalid height
755 if ( *height < 0 )
756 *height = 0;
757 }
758}
759
760void wxWindow::DoSetClientSize(int width, int height)
761{
762 // take into account the borders
763 wxRect rectBorder = m_renderer->GetBorderDimensions(GetBorder());
764 width += rectBorder.x;
765 height += rectBorder.y;
766
767 // and the scrollbars (as they may be offset into the border, use the
768 // scrollbar position, not size - this supposes that PositionScrollbars()
769 // had been called before)
1e6feb95 770 wxSize size = GetSize();
9a6384ca 771#if wxUSE_SCROLLBAR
1e6feb95
VZ
772 if ( m_scrollbarVert )
773 width += size.x - m_scrollbarVert->GetPosition().x;
9a6384ca 774#endif // wxUSE_SCROLLBAR
4eb124f5 775 width += rectBorder.width;
1e6feb95 776
9a6384ca 777#if wxUSE_SCROLLBAR
1e6feb95
VZ
778 if ( m_scrollbarHorz )
779 height += size.y - m_scrollbarHorz->GetPosition().y;
9a6384ca 780#endif // wxUSE_SCROLLBAR
4eb124f5 781 height += rectBorder.height;
1e6feb95
VZ
782
783 wxWindowNative::DoSetClientSize(width, height);
784}
785
786wxHitTest wxWindow::DoHitTest(wxCoord x, wxCoord y) const
787{
788 wxHitTest ht = wxWindowNative::DoHitTest(x, y);
9a6384ca
WS
789
790#if wxUSE_SCROLLBAR
1e6feb95
VZ
791 if ( ht == wxHT_WINDOW_INSIDE )
792 {
793 if ( m_scrollbarVert && x >= m_scrollbarVert->GetPosition().x )
794 {
795 // it can still be changed below because it may also be the corner
796 ht = wxHT_WINDOW_VERT_SCROLLBAR;
797 }
798
799 if ( m_scrollbarHorz && y >= m_scrollbarHorz->GetPosition().y )
800 {
801 ht = ht == wxHT_WINDOW_VERT_SCROLLBAR ? wxHT_WINDOW_CORNER
802 : wxHT_WINDOW_HORZ_SCROLLBAR;
803 }
804 }
9a6384ca 805#endif // wxUSE_SCROLLBAR
1e6feb95
VZ
806
807 return ht;
808}
809
810// ----------------------------------------------------------------------------
811// scrolling: we implement it entirely ourselves except for ScrollWindow()
812// function which is supposed to be (efficiently) implemented by the native
813// window class
814// ----------------------------------------------------------------------------
815
816void wxWindow::RefreshScrollbars()
817{
9a6384ca 818#if wxUSE_SCROLLBAR
1e6feb95
VZ
819 if ( m_scrollbarHorz )
820 m_scrollbarHorz->Refresh();
821
822 if ( m_scrollbarVert )
823 m_scrollbarVert->Refresh();
9a6384ca 824#endif // wxUSE_SCROLLBAR
1e6feb95
VZ
825}
826
827void wxWindow::PositionScrollbars()
828{
9a6384ca 829#if wxUSE_SCROLLBAR
1e6feb95
VZ
830 // do not use GetClientSize/Rect as it relies on the scrollbars being
831 // correctly positioned
832
833 wxSize size = GetSize();
834 wxBorder border = GetBorder();
835 wxRect rectBorder = m_renderer->GetBorderDimensions(border);
836 bool inside = m_renderer->AreScrollbarsInsideBorder();
837
838 int height = m_scrollbarHorz ? m_scrollbarHorz->GetSize().y : 0;
839 int width = m_scrollbarVert ? m_scrollbarVert->GetSize().x : 0;
840
841 wxRect rectBar;
842 if ( m_scrollbarVert )
843 {
844 rectBar.x = size.x - width;
845 if ( inside )
846 rectBar.x -= rectBorder.width;
847 rectBar.width = width;
848 rectBar.y = 0;
849 if ( inside )
850 rectBar.y += rectBorder.y;
851 rectBar.height = size.y - height;
852 if ( inside )
853 rectBar.height -= rectBorder.y + rectBorder.height;
854
855 m_scrollbarVert->SetSize(rectBar, wxSIZE_NO_ADJUSTMENTS);
856 }
857
858 if ( m_scrollbarHorz )
859 {
860 rectBar.y = size.y - height;
861 if ( inside )
862 rectBar.y -= rectBorder.height;
863 rectBar.height = height;
864 rectBar.x = 0;
865 if ( inside )
866 rectBar.x += rectBorder.x;
867 rectBar.width = size.x - width;
868 if ( inside )
869 rectBar.width -= rectBorder.x + rectBorder.width;
870
871 m_scrollbarHorz->SetSize(rectBar, wxSIZE_NO_ADJUSTMENTS);
872 }
873
874 RefreshScrollbars();
9a6384ca 875#endif // wxUSE_SCROLLBAR
1e6feb95
VZ
876}
877
878void wxWindow::SetScrollbar(int orient,
879 int pos,
880 int pageSize,
881 int range,
882 bool refresh)
883{
9a6384ca 884#if wxUSE_SCROLLBAR
3f393e3d
VZ
885 wxASSERT_MSG( pageSize <= range,
886 _T("page size can't be greater than range") );
887
a290fa5a 888 bool hasClientSizeChanged = false;
1e6feb95 889 wxScrollBar *scrollbar = GetScrollbar(orient);
3f393e3d 890 if ( range && (pageSize < range) )
1e6feb95
VZ
891 {
892 if ( !scrollbar )
893 {
894 // create it
ab6b6b15 895#if wxUSE_TWO_WINDOWS
a290fa5a 896 SetInsertIntoMain( true );
ab6b6b15 897#endif
a290fa5a 898 scrollbar = new wxScrollBar(this, wxID_ANY,
1e6feb95
VZ
899 wxDefaultPosition, wxDefaultSize,
900 orient & wxVERTICAL ? wxSB_VERTICAL
901 : wxSB_HORIZONTAL);
ab6b6b15 902#if wxUSE_TWO_WINDOWS
a290fa5a 903 SetInsertIntoMain( false );
ab6b6b15 904#endif
1e6feb95
VZ
905 if ( orient & wxVERTICAL )
906 m_scrollbarVert = scrollbar;
907 else
908 m_scrollbarHorz = scrollbar;
909
910 // the client area diminished as we created a scrollbar
a290fa5a 911 hasClientSizeChanged = true;
1e6feb95
VZ
912
913 PositionScrollbars();
914 }
915 else if ( GetWindowStyle() & wxALWAYS_SHOW_SB )
916 {
917 // we might have disabled it before
918 scrollbar->Enable();
919 }
920
921 scrollbar->SetScrollbar(pos, pageSize, range, pageSize, refresh);
922 }
923 else // no range means no scrollbar
924 {
925 if ( scrollbar )
926 {
927 // wxALWAYS_SHOW_SB only applies to the vertical scrollbar
928 if ( (orient & wxVERTICAL) && (GetWindowStyle() & wxALWAYS_SHOW_SB) )
929 {
930 // just disable the scrollbar
931 scrollbar->SetScrollbar(pos, pageSize, range, pageSize, refresh);
932 scrollbar->Disable();
933 }
934 else // really remove the scrollbar
935 {
936 delete scrollbar;
937
938 if ( orient & wxVERTICAL )
939 m_scrollbarVert = NULL;
940 else
941 m_scrollbarHorz = NULL;
942
943 // the client area increased as we removed a scrollbar
a290fa5a 944 hasClientSizeChanged = true;
1e6feb95
VZ
945
946 // the size of the remaining scrollbar must be adjusted
947 if ( m_scrollbarHorz || m_scrollbarVert )
948 {
949 PositionScrollbars();
950 }
951 }
952 }
953 }
954
955 // give the window a chance to relayout
956 if ( hasClientSizeChanged )
957 {
a17a79ba
RR
958#if wxUSE_TWO_WINDOWS
959 wxWindowNative::SetSize( GetSize() );
960#else
1e6feb95
VZ
961 wxSizeEvent event(GetSize());
962 (void)GetEventHandler()->ProcessEvent(event);
a17a79ba 963#endif
1e6feb95 964 }
9a6384ca
WS
965#else
966 wxUnusedVar(orient);
967 wxUnusedVar(pos);
968 wxUnusedVar(pageSize);
969 wxUnusedVar(range);
970 wxUnusedVar(refresh);
971#endif // wxUSE_SCROLLBAR
1e6feb95
VZ
972}
973
61fef19b 974void wxWindow::SetScrollPos(int orient, int pos, bool WXUNUSED(refresh))
1e6feb95 975{
9a6384ca 976#if wxUSE_SCROLLBAR
1e6feb95 977 wxScrollBar *scrollbar = GetScrollbar(orient);
1e6feb95 978
45e13c7f
JS
979 if (scrollbar)
980 scrollbar->SetThumbPosition(pos);
7d297414
VZ
981
982 // VZ: I think we can safely ignore this as we always refresh it
983 // automatically whenever the value chanegs
984#if 0
1e6feb95
VZ
985 if ( refresh )
986 Refresh();
7d297414 987#endif
9a6384ca
WS
988#else
989 wxUnusedVar(orient);
990 wxUnusedVar(pos);
991#endif // wxUSE_SCROLLBAR
1e6feb95
VZ
992}
993
994int wxWindow::GetScrollPos(int orient) const
995{
9a6384ca 996#if wxUSE_SCROLLBAR
1e6feb95
VZ
997 wxScrollBar *scrollbar = GetScrollbar(orient);
998 return scrollbar ? scrollbar->GetThumbPosition() : 0;
9a6384ca
WS
999#else
1000 wxUnusedVar(orient);
1001 return 0;
1002#endif // wxUSE_SCROLLBAR
1e6feb95
VZ
1003}
1004
1005int wxWindow::GetScrollThumb(int orient) const
1006{
9a6384ca 1007#if wxUSE_SCROLLBAR
1e6feb95
VZ
1008 wxScrollBar *scrollbar = GetScrollbar(orient);
1009 return scrollbar ? scrollbar->GetThumbSize() : 0;
9a6384ca
WS
1010#else
1011 wxUnusedVar(orient);
1012 return 0;
1013#endif // wxUSE_SCROLLBAR
1e6feb95
VZ
1014}
1015
1016int wxWindow::GetScrollRange(int orient) const
1017{
9a6384ca 1018#if wxUSE_SCROLLBAR
1e6feb95
VZ
1019 wxScrollBar *scrollbar = GetScrollbar(orient);
1020 return scrollbar ? scrollbar->GetRange() : 0;
9a6384ca
WS
1021#else
1022 wxUnusedVar(orient);
1023 return 0;
1024#endif // wxUSE_SCROLLBAR
1e6feb95
VZ
1025}
1026
1027void wxWindow::ScrollWindow(int dx, int dy, const wxRect *rect)
1028{
66a58655
VS
1029 // use native scrolling when available and do it in generic way
1030 // otherwise:
4125131b
RR
1031#ifdef __WXX11__
1032
66a58655 1033 wxWindowNative::ScrollWindow(dx, dy, rect);
4125131b 1034
2b5f62a0 1035#else // !wxX11
4125131b 1036
1e6feb95
VZ
1037 // before scrolling it, ensure that we don't have any unpainted areas
1038 Update();
1039
1040 wxRect r;
1041
1042 if ( dx )
1043 {
1044 r = ScrollNoRefresh(dx, 0, rect);
a290fa5a 1045 Refresh(true /* erase bkgnd */, &r);
1e6feb95
VZ
1046 }
1047
1048 if ( dy )
1049 {
1050 r = ScrollNoRefresh(0, dy, rect);
a290fa5a 1051 Refresh(true /* erase bkgnd */, &r);
1e6feb95 1052 }
2b5f62a0
VZ
1053
1054 // scroll children accordingly:
66a58655 1055 wxPoint offset(dx, dy);
2b5f62a0 1056
ac32ba44 1057 for (wxWindowList::compatibility_iterator node = GetChildren().GetFirst();
66a58655
VS
1058 node; node = node->GetNext())
1059 {
1060 wxWindow *child = node->GetData();
9a6384ca 1061#if wxUSE_SCROLLBAR
1c9f1f4d
VS
1062 if ( child == m_scrollbarVert || child == m_scrollbarHorz )
1063 continue;
9a6384ca 1064#endif // wxUSE_SCROLLBAR
1c9f1f4d
VS
1065
1066 // VS: Scrolling children has non-trivial semantics. If rect=NULL then
2b5f62a0 1067 // it is easy: we scroll all children. Otherwise it gets
1c9f1f4d
VS
1068 // complicated:
1069 // 1. if scrolling in one direction only, scroll only
1070 // those children that intersect shaft defined by the rectangle
1071 // and scrolling direction
1072 // 2. if scrolling in both axes, scroll all children
2b5f62a0 1073
1c9f1f4d
VS
1074 if ( rect && (dx * dy == 0 /* moving in only one of x, y axis */) )
1075 {
1076 wxRect childRect = child->GetRect();
1077 if ( dx == 0 && (childRect.GetLeft() <= rect->GetRight() ||
1078 childRect.GetRight() >= rect->GetLeft()) )
1079 {
1080 child->Move(child->GetPosition() + offset);
1081 }
1082 else if ( dy == 0 && (childRect.GetTop() <= rect->GetBottom() ||
1083 childRect.GetBottom() >= rect->GetTop()) )
1084 {
1085 child->Move(child->GetPosition() + offset);
1086 }
1087 }
1088 else
66a58655
VS
1089 {
1090 child->Move(child->GetPosition() + offset);
1091 }
2b5f62a0
VZ
1092 }
1093#endif // wxX11/!wxX11
1e6feb95
VZ
1094}
1095
1096wxRect wxWindow::ScrollNoRefresh(int dx, int dy, const wxRect *rectTotal)
1097{
1098 wxASSERT_MSG( !dx || !dy, _T("can't be used for diag scrolling") );
1099
1100 // the rect to refresh (which we will calculate)
1101 wxRect rect;
1102
1103 if ( !dx && !dy )
1104 {
1105 // nothing to do
1106 return rect;
1107 }
1108
1109 // calculate the part of the window which we can just redraw in the new
1110 // location
1111 wxSize sizeTotal = rectTotal ? rectTotal->GetSize() : GetClientSize();
1112
1113 wxLogTrace(_T("scroll"), _T("rect is %dx%d, scroll by %d, %d"),
1114 sizeTotal.x, sizeTotal.y, dx, dy);
1115
1116 // the initial and end point of the region we move in client coords
1117 wxPoint ptSource, ptDest;
1118 if ( rectTotal )
1119 {
1120 ptSource = rectTotal->GetPosition();
1121 ptDest = rectTotal->GetPosition();
1122 }
1123
1124 // the size of this region
1125 wxSize size;
1126 size.x = sizeTotal.x - abs(dx);
1127 size.y = sizeTotal.y - abs(dy);
1128 if ( size.x <= 0 || size.y <= 0 )
1129 {
1130 // just redraw everything as nothing of the displayed image will stay
1131 wxLogTrace(_T("scroll"), _T("refreshing everything"));
1132
1133 rect = rectTotal ? *rectTotal : wxRect(0, 0, sizeTotal.x, sizeTotal.y);
1134 }
1135 else // move the part which doesn't change to the new location
1136 {
1137 // note that when we scroll the canvas in some direction we move the
1138 // block which doesn't need to be refreshed in the opposite direction
1139
1140 if ( dx < 0 )
1141 {
1142 // scroll to the right, move to the left
1143 ptSource.x -= dx;
1144 }
1145 else
1146 {
1147 // scroll to the left, move to the right
1148 ptDest.x += dx;
1149 }
1150
1151 if ( dy < 0 )
1152 {
1153 // scroll down, move up
1154 ptSource.y -= dy;
1155 }
1156 else
1157 {
1158 // scroll up, move down
1159 ptDest.y += dy;
1160 }
1161
1162#if wxUSE_CARET
1163 // we need to hide the caret before moving or it will erase itself at
1164 // the wrong (old) location
1165 wxCaret *caret = GetCaret();
1166 if ( caret )
1167 caret->Hide();
1168#endif // wxUSE_CARET
1169
1170 // do move
1171 wxClientDC dc(this);
1172 wxBitmap bmp(size.x, size.y);
1173 wxMemoryDC dcMem;
1174 dcMem.SelectObject(bmp);
1175
c47addef 1176 dcMem.Blit(wxPoint(0,0), size, &dc, ptSource
03147cd0 1177#if defined(__WXGTK__) && !defined(wxHAS_WORKING_GTK_DC_BLIT)
1e6feb95
VZ
1178 + GetClientAreaOrigin()
1179#endif // broken wxGTK wxDC::Blit
1180 );
c47addef 1181 dc.Blit(ptDest, size, &dcMem, wxPoint(0,0));
1e6feb95
VZ
1182
1183 wxLogTrace(_T("scroll"),
1184 _T("Blit: (%d, %d) of size %dx%d -> (%d, %d)"),
1185 ptSource.x, ptSource.y,
1186 size.x, size.y,
1187 ptDest.x, ptDest.y);
1188
1189 // and now repaint the uncovered area
1190
1191 // FIXME: We repaint the intersection of these rectangles twice - is
1192 // it bad? I don't think so as it is rare to scroll the window
1193 // diagonally anyhow and so adding extra logic to compute
1194 // rectangle intersection is probably not worth the effort
1195
1196 rect.x = ptSource.x;
1197 rect.y = ptSource.y;
1198
1199 if ( dx )
1200 {
1201 if ( dx < 0 )
1202 {
1203 // refresh the area along the right border
1204 rect.x += size.x + dx;
1205 rect.width = -dx;
1206 }
1207 else
1208 {
1209 // refresh the area along the left border
1210 rect.width = dx;
1211 }
1212
1213 rect.height = sizeTotal.y;
1214
1215 wxLogTrace(_T("scroll"), _T("refreshing (%d, %d)-(%d, %d)"),
1216 rect.x, rect.y,
1217 rect.GetRight() + 1, rect.GetBottom() + 1);
1218 }
1219
1220 if ( dy )
1221 {
1222 if ( dy < 0 )
1223 {
1224 // refresh the area along the bottom border
1225 rect.y += size.y + dy;
1226 rect.height = -dy;
1227 }
1228 else
1229 {
1230 // refresh the area along the top border
1231 rect.height = dy;
1232 }
1233
1234 rect.width = sizeTotal.x;
1235
1236 wxLogTrace(_T("scroll"), _T("refreshing (%d, %d)-(%d, %d)"),
1237 rect.x, rect.y,
1238 rect.GetRight() + 1, rect.GetBottom() + 1);
1239 }
1240
1241#if wxUSE_CARET
1242 if ( caret )
1243 caret->Show();
1244#endif // wxUSE_CARET
1245 }
1246
1247 return rect;
1248}
1249
1e6feb95
VZ
1250// ----------------------------------------------------------------------------
1251// accelerators and menu hot keys
1252// ----------------------------------------------------------------------------
1253
1254#if wxUSE_MENUS
1255 // the last window over which Alt was pressed (used by OnKeyUp)
1256 wxWindow *wxWindow::ms_winLastAltPress = NULL;
1257#endif // wxUSE_MENUS
1258
1259#if wxUSE_ACCEL || wxUSE_MENUS
1260
1261void wxWindow::OnKeyDown(wxKeyEvent& event)
1262{
1263#if wxUSE_MENUS
1264 int key = event.GetKeyCode();
f52c3131 1265 if ( !event.ControlDown() && (key == WXK_ALT || key == WXK_F10) )
1e6feb95
VZ
1266 {
1267 ms_winLastAltPress = this;
1268
1269 // it can't be an accel anyhow
1270 return;
1271 }
1272
1273 ms_winLastAltPress = NULL;
1274#endif // wxUSE_MENUS
1275
1276#if wxUSE_ACCEL
1277 for ( wxWindow *win = this; win; win = win->GetParent() )
1278 {
1279 int command = win->GetAcceleratorTable()->GetCommand(event);
1280 if ( command != -1 )
1281 {
1282 wxCommandEvent eventCmd(wxEVT_COMMAND_MENU_SELECTED, command);
1283 if ( win->GetEventHandler()->ProcessEvent(eventCmd) )
1284 {
1285 // skip "event.Skip()" below
1286 return;
1287 }
1288 }
1289
1290 if ( win->IsTopLevel() )
1291 {
1292 // try the frame menu bar
1293#if wxUSE_MENUS
1294 wxFrame *frame = wxDynamicCast(win, wxFrame);
1295 if ( frame )
1296 {
1297 wxMenuBar *menubar = frame->GetMenuBar();
1298 if ( menubar && menubar->ProcessAccelEvent(event) )
1299 {
1300 // skip "event.Skip()" below
1301 return;
1302 }
1303 }
1304#endif // wxUSE_MENUS
1305
81762e79
VS
1306 // if it wasn't in a menu, try to find a button
1307 if ( command != -1 )
1308 {
1309 wxWindow* child = win->FindWindow(command);
1310 if ( child && wxDynamicCast(child, wxButton) )
1311 {
1312 wxCommandEvent eventCmd(wxEVT_COMMAND_BUTTON_CLICKED, command);
1313 eventCmd.SetEventObject(child);
1314 if ( child->GetEventHandler()->ProcessEvent(eventCmd) )
1315 {
1316 // skip "event.Skip()" below
1317 return;
1318 }
1319 }
1320 }
1321
1e6feb95
VZ
1322 // don't propagate accels from the child frame to the parent one
1323 break;
1324 }
1325 }
1326#endif // wxUSE_ACCEL
1327
1328 event.Skip();
1329}
1330
1331#endif // wxUSE_ACCEL
1332
1333#if wxUSE_MENUS
1334
1335wxMenuBar *wxWindow::GetParentFrameMenuBar() const
1336{
1337 for ( const wxWindow *win = this; win; win = win->GetParent() )
1338 {
1339 if ( win->IsTopLevel() )
1340 {
1341 wxFrame *frame = wxDynamicCast(win, wxFrame);
1342 if ( frame )
1343 {
1344 return frame->GetMenuBar();
1345 }
1346
1347 // don't look further - we don't want to return the menubar of the
1348 // parent frame
1349 break;
1350 }
1351 }
1352
1353 return NULL;
1354}
1355
1356void wxWindow::OnChar(wxKeyEvent& event)
1357{
1358 if ( event.AltDown() && !event.ControlDown() )
1359 {
1360 int key = event.GetKeyCode();
1361
1362 wxMenuBar *menubar = GetParentFrameMenuBar();
1363 if ( menubar )
1364 {
1365 int item = menubar->FindNextItemForAccel(-1, key);
1366 if ( item != -1 )
1367 {
1368 menubar->PopupMenu((size_t)item);
1369
1370 // skip "event.Skip()" below
1371 return;
1372 }
1373 }
1374 }
1375
1376 event.Skip();
1377}
1378
1379void wxWindow::OnKeyUp(wxKeyEvent& event)
1380{
1381 int key = event.GetKeyCode();
f52c3131 1382 if ( !event.HasModifiers() && (key == WXK_ALT || key == WXK_F10) )
1e6feb95
VZ
1383 {
1384 // only process Alt release specially if there were no other key
1385 // presses since Alt had been pressed and if both events happened in
1386 // the same window
1387 if ( ms_winLastAltPress == this )
1388 {
1389 wxMenuBar *menubar = GetParentFrameMenuBar();
1390 if ( menubar && this != menubar )
1391 {
1392 menubar->SelectMenu(0);
1393 }
1394 }
1395 }
1396 else
1397 {
1398 event.Skip();
1399 }
1400
1401 // in any case reset it
1402 ms_winLastAltPress = NULL;
1403}
1404
1405#endif // wxUSE_MENUS
1406
30827629
VZ
1407// ----------------------------------------------------------------------------
1408// MSW-specific section
1409// ----------------------------------------------------------------------------
1410
1411#ifdef __WXMSW__
1412
1413#include "wx/msw/private.h"
1414
c140b7e7 1415WXLRESULT wxWindow::MSWWindowProc(WXUINT message, WXWPARAM wParam, WXLPARAM lParam)
30827629
VZ
1416{
1417 if ( message == WM_NCHITTEST )
1418 {
1419 // the windows which contain the other windows should let the mouse
1420 // events through, otherwise a window inside a static box would
1421 // never get any events at all
1422 if ( IsStaticBox() )
1423 {
1424 return HTTRANSPARENT;
1425 }
1426 }
1427
1428 return wxWindowNative::MSWWindowProc(message, wParam, lParam);
1429}
1430
1431#endif // __WXMSW__