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