]> git.saurik.com Git - wxWidgets.git/blame - src/univ/winuniv.cpp
Missing headers.
[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
394void wxWindow::Refresh(bool eraseBackground, const wxRect *rectClient)
395{
396 wxRect rectWin;
397 wxPoint pt = GetClientAreaOrigin();
398
399 wxSize size = GetClientSize();
400
401 if ( rectClient )
402 {
403 rectWin = *rectClient;
404
405 // don't refresh anything beyond the client area (scrollbars for
406 // example)
407 if ( rectWin.GetRight() > size.x )
408 rectWin.SetRight(size.x);
409 if ( rectWin.GetBottom() > size.y )
410 rectWin.SetBottom(size.y);
411
412 rectWin.Offset(pt);
413 }
414 else // refresh the entire client area
415 {
416 rectWin.x = pt.x;
417 rectWin.y = pt.y;
418 rectWin.width = size.x;
419 rectWin.height = size.y;
420 }
421
422 // debugging helper
423#ifdef WXDEBUG_REFRESH
a290fa5a 424 static bool s_refreshDebug = false;
1e6feb95
VZ
425 if ( s_refreshDebug )
426 {
427 wxWindowDC dc(this);
428 dc.SetBrush(*wxCYAN_BRUSH);
429 dc.SetPen(*wxTRANSPARENT_PEN);
430 dc.DrawRectangle(rectWin);
431
432 // under Unix we use "--sync" X option for this
8cb172b4 433 #if defined(__WXMSW__) && !defined(__WXMICROWIN__)
1e6feb95
VZ
434 ::GdiFlush();
435 ::Sleep(200);
436 #endif // __WXMSW__
437 }
438#endif // WXDEBUG_REFRESH
439
440 wxWindowNative::Refresh(eraseBackground, &rectWin);
82e5f91b
JS
441
442 // Refresh all sub controls if any.
ac32ba44 443 wxWindowList::compatibility_iterator node = GetChildren().GetFirst();
82e5f91b
JS
444 while ( node )
445 {
446 wxWindow *win = node->GetData();
8da1f9a9 447 // Only refresh sub controls when it is visible
82e5f91b 448 // and when it is in the update region.
333a6456 449 if(!win->IsKindOf(CLASSINFO(wxTopLevelWindow)) && win->IsShown() && wxRegion(rectWin).Contains(win->GetRect()) != wxOutRegion)
82e5f91b 450 win->Refresh(eraseBackground, &rectWin);
8da1f9a9 451
82e5f91b
JS
452 node = node->GetNext();
453 }
1e6feb95
VZ
454}
455
456// ----------------------------------------------------------------------------
457// state flags
458// ----------------------------------------------------------------------------
459
460bool wxWindow::Enable(bool enable)
461{
462 if ( !wxWindowNative::Enable(enable) )
a290fa5a 463 return false;
1e6feb95
VZ
464
465 // disabled window can't keep focus
c4bcd8fc 466 if ( FindFocus() == this && GetParent() != NULL )
1e6feb95
VZ
467 {
468 GetParent()->SetFocus();
469 }
470
471 if ( m_renderer )
472 {
473 // a window with renderer is drawn by ourselves and it has to be
474 // refreshed to reflect its new status
475 Refresh();
476 }
477
a290fa5a 478 return true;
1e6feb95
VZ
479}
480
481bool wxWindow::IsFocused() const
482{
5625d0d4 483 return FindFocus() == this;
1e6feb95
VZ
484}
485
486bool wxWindow::IsPressed() const
487{
a290fa5a 488 return false;
1e6feb95
VZ
489}
490
491bool wxWindow::IsDefault() const
492{
a290fa5a 493 return false;
1e6feb95
VZ
494}
495
496bool wxWindow::IsCurrent() const
497{
498 return m_isCurrent;
499}
500
501bool wxWindow::SetCurrent(bool doit)
502{
503 if ( doit == m_isCurrent )
a290fa5a 504 return false;
1e6feb95
VZ
505
506 m_isCurrent = doit;
507
508 if ( CanBeHighlighted() )
509 Refresh();
510
a290fa5a 511 return true;
1e6feb95
VZ
512}
513
514int wxWindow::GetStateFlags() const
515{
516 int flags = 0;
517 if ( !IsEnabled() )
518 flags |= wxCONTROL_DISABLED;
519
520 // the following states are only possible if our application is active - if
521 // it is not, even our default/focused controls shouldn't appear as such
522 if ( wxTheApp->IsActive() )
523 {
524 if ( IsCurrent() )
525 flags |= wxCONTROL_CURRENT;
526 if ( IsFocused() )
527 flags |= wxCONTROL_FOCUSED;
528 if ( IsPressed() )
529 flags |= wxCONTROL_PRESSED;
530 if ( IsDefault() )
531 flags |= wxCONTROL_ISDEFAULT;
532 }
533
534 return flags;
535}
536
537// ----------------------------------------------------------------------------
538// size
539// ----------------------------------------------------------------------------
540
541void wxWindow::OnSize(wxSizeEvent& event)
542{
aae73669 543 event.Skip();
2b5f62a0 544
9a6384ca 545#if wxUSE_SCROLLBAR
1e6feb95
VZ
546 if ( m_scrollbarVert || m_scrollbarHorz )
547 {
548 PositionScrollbars();
549 }
9a6384ca 550#endif // wxUSE_SCROLLBAR
2b5f62a0 551
ab6b6b15 552#if 0 // ndef __WXMSW__
ec47a147 553 // Refresh the area (strip) previously occupied by the border
2b5f62a0 554
e441e1f4 555 if ( !HasFlag(wxFULL_REPAINT_ON_RESIZE) && IsShown() )
ec47a147 556 {
aae73669
RR
557 // This code assumes that wxSizeEvent.GetSize() returns
558 // the area of the entire window, not just the client
559 // area.
ec47a147 560 wxSize newSize = event.GetSize();
2b5f62a0 561
a290fa5a 562 if (m_oldSize.x == wxDefaultCoord && m_oldSize.y == wxDefaultCoord)
aae73669
RR
563 {
564 m_oldSize = newSize;
565 return;
566 }
2b5f62a0 567
ec47a147
RR
568 if (HasFlag( wxSIMPLE_BORDER ))
569 {
570 if (newSize.y > m_oldSize.y)
571 {
572 wxRect rect;
573 rect.x = 0;
574 rect.width = m_oldSize.x;
aae73669 575 rect.y = m_oldSize.y-2;
ec47a147 576 rect.height = 1;
a290fa5a 577 Refresh( true, &rect );
ec47a147 578 }
aae73669
RR
579 else if (newSize.y < m_oldSize.y)
580 {
581 wxRect rect;
582 rect.y = newSize.y;
583 rect.x = 0;
584 rect.height = 1;
585 rect.width = newSize.x;
a290fa5a 586 wxWindowNative::Refresh( true, &rect );
aae73669 587 }
2b5f62a0 588
ec47a147
RR
589 if (newSize.x > m_oldSize.x)
590 {
591 wxRect rect;
592 rect.y = 0;
593 rect.height = m_oldSize.y;
aae73669 594 rect.x = m_oldSize.x-2;
ec47a147 595 rect.width = 1;
a290fa5a 596 Refresh( true, &rect );
ec47a147 597 }
aae73669
RR
598 else if (newSize.x < m_oldSize.x)
599 {
600 wxRect rect;
601 rect.x = newSize.x;
602 rect.y = 0;
603 rect.width = 1;
604 rect.height = newSize.y;
a290fa5a 605 wxWindowNative::Refresh( true, &rect );
aae73669 606 }
ec47a147
RR
607 }
608 else
609 if (HasFlag( wxSUNKEN_BORDER ) || HasFlag( wxRAISED_BORDER ))
610 {
611 if (newSize.y > m_oldSize.y)
612 {
613 wxRect rect;
614 rect.x = 0;
615 rect.width = m_oldSize.x;
aae73669 616 rect.y = m_oldSize.y-4;
ec47a147 617 rect.height = 2;
a290fa5a 618 Refresh( true, &rect );
ec47a147 619 }
aae73669
RR
620 else if (newSize.y < m_oldSize.y)
621 {
622 wxRect rect;
623 rect.y = newSize.y;
624 rect.x = 0;
625 rect.height = 2;
626 rect.width = newSize.x;
a290fa5a 627 wxWindowNative::Refresh( true, &rect );
aae73669 628 }
2b5f62a0 629
ec47a147
RR
630 if (newSize.x > m_oldSize.x)
631 {
632 wxRect rect;
633 rect.y = 0;
634 rect.height = m_oldSize.y;
aae73669 635 rect.x = m_oldSize.x-4;
ec47a147 636 rect.width = 2;
a290fa5a 637 Refresh( true, &rect );
ec47a147 638 }
aae73669
RR
639 else if (newSize.x < m_oldSize.x)
640 {
641 wxRect rect;
642 rect.x = newSize.x;
643 rect.y = 0;
644 rect.width = 2;
645 rect.height = newSize.y;
a290fa5a 646 wxWindowNative::Refresh( true, &rect );
aae73669 647 }
ec47a147 648 }
2b5f62a0 649
ec47a147
RR
650 m_oldSize = newSize;
651 }
652#endif
1e6feb95
VZ
653}
654
655wxSize wxWindow::DoGetBestSize() const
656{
657 return AdjustSize(DoGetBestClientSize());
658}
659
660wxSize wxWindow::DoGetBestClientSize() const
661{
662 return wxWindowNative::DoGetBestSize();
663}
664
665wxSize wxWindow::AdjustSize(const wxSize& size) const
666{
667 wxSize sz = size;
668 if ( m_renderer )
669 m_renderer->AdjustSize(&sz, this);
670 return sz;
671}
672
673wxPoint wxWindow::GetClientAreaOrigin() const
674{
675 wxPoint pt = wxWindowBase::GetClientAreaOrigin();
676
ab6b6b15
RR
677#if wxUSE_TWO_WINDOWS
678#else
1e6feb95
VZ
679 if ( m_renderer )
680 pt += m_renderer->GetBorderDimensions(GetBorder()).GetPosition();
ab6b6b15 681#endif
1e6feb95
VZ
682
683 return pt;
684}
685
686void wxWindow::DoGetClientSize(int *width, int *height) const
687{
3379ed37
VZ
688 // if it is a native window, we assume it handles the scrollbars itself
689 // too - and if it doesn't, there is not much we can do
690 if ( !m_renderer )
691 {
692 wxWindowNative::DoGetClientSize(width, height);
693
694 return;
695 }
696
1e6feb95
VZ
697 int w, h;
698 wxWindowNative::DoGetClientSize(&w, &h);
699
700 // we assume that the scrollbars are positioned correctly (by a previous
701 // call to PositionScrollbars()) here
702
703 wxRect rectBorder;
704 if ( m_renderer )
705 rectBorder = m_renderer->GetBorderDimensions(GetBorder());
706
707 bool inside = m_renderer->AreScrollbarsInsideBorder();
708
709 if ( width )
710 {
9a6384ca 711#if wxUSE_SCROLLBAR
1e6feb95
VZ
712 // in any case, take account of the scrollbar
713 if ( m_scrollbarVert )
714 w -= m_scrollbarVert->GetSize().x;
9a6384ca 715#endif // wxUSE_SCROLLBAR
1e6feb95
VZ
716
717 // if we don't have scrollbar or if it is outside the border (and not
718 // blended into it), take account of the right border as well
9a6384ca
WS
719 if (
720#if wxUSE_SCROLLBAR
721 !m_scrollbarVert ||
722#endif // wxUSE_SCROLLBAR
723 inside )
1e6feb95
VZ
724 w -= rectBorder.width;
725
726 // and always account for the left border
727 *width = w - rectBorder.x;
728
729 // we shouldn't return invalid width
730 if ( *width < 0 )
731 *width = 0;
732 }
733
734 if ( height )
735 {
9a6384ca 736#if wxUSE_SCROLLBAR
1e6feb95
VZ
737 if ( m_scrollbarHorz )
738 h -= m_scrollbarHorz->GetSize().y;
9a6384ca 739#endif // wxUSE_SCROLLBAR
1e6feb95 740
9a6384ca
WS
741 if (
742#if wxUSE_SCROLLBAR
743 !m_scrollbarHorz ||
744#endif // wxUSE_SCROLLBAR
745 inside )
1e6feb95
VZ
746 h -= rectBorder.height;
747
748 *height = h - rectBorder.y;
749
750 // we shouldn't return invalid height
751 if ( *height < 0 )
752 *height = 0;
753 }
754}
755
756void wxWindow::DoSetClientSize(int width, int height)
757{
758 // take into account the borders
759 wxRect rectBorder = m_renderer->GetBorderDimensions(GetBorder());
760 width += rectBorder.x;
761 height += rectBorder.y;
762
763 // and the scrollbars (as they may be offset into the border, use the
764 // scrollbar position, not size - this supposes that PositionScrollbars()
765 // had been called before)
766 bool inside = m_renderer->AreScrollbarsInsideBorder();
767 wxSize size = GetSize();
9a6384ca 768#if wxUSE_SCROLLBAR
1e6feb95
VZ
769 if ( m_scrollbarVert )
770 width += size.x - m_scrollbarVert->GetPosition().x;
9a6384ca
WS
771#endif // wxUSE_SCROLLBAR
772 if (
773#if wxUSE_SCROLLBAR
774 !m_scrollbarVert ||
775#endif // wxUSE_SCROLLBAR
776 inside )
1e6feb95
VZ
777 width += rectBorder.width;
778
9a6384ca 779#if wxUSE_SCROLLBAR
1e6feb95
VZ
780 if ( m_scrollbarHorz )
781 height += size.y - m_scrollbarHorz->GetPosition().y;
9a6384ca
WS
782#endif // wxUSE_SCROLLBAR
783 if (
784#if wxUSE_SCROLLBAR
785 !m_scrollbarHorz ||
786#endif // wxUSE_SCROLLBAR
787 inside )
1e6feb95
VZ
788 height += rectBorder.height;
789
790 wxWindowNative::DoSetClientSize(width, height);
791}
792
793wxHitTest wxWindow::DoHitTest(wxCoord x, wxCoord y) const
794{
795 wxHitTest ht = wxWindowNative::DoHitTest(x, y);
9a6384ca
WS
796
797#if wxUSE_SCROLLBAR
1e6feb95
VZ
798 if ( ht == wxHT_WINDOW_INSIDE )
799 {
800 if ( m_scrollbarVert && x >= m_scrollbarVert->GetPosition().x )
801 {
802 // it can still be changed below because it may also be the corner
803 ht = wxHT_WINDOW_VERT_SCROLLBAR;
804 }
805
806 if ( m_scrollbarHorz && y >= m_scrollbarHorz->GetPosition().y )
807 {
808 ht = ht == wxHT_WINDOW_VERT_SCROLLBAR ? wxHT_WINDOW_CORNER
809 : wxHT_WINDOW_HORZ_SCROLLBAR;
810 }
811 }
9a6384ca 812#endif // wxUSE_SCROLLBAR
1e6feb95
VZ
813
814 return ht;
815}
816
817// ----------------------------------------------------------------------------
818// scrolling: we implement it entirely ourselves except for ScrollWindow()
819// function which is supposed to be (efficiently) implemented by the native
820// window class
821// ----------------------------------------------------------------------------
822
823void wxWindow::RefreshScrollbars()
824{
9a6384ca 825#if wxUSE_SCROLLBAR
1e6feb95
VZ
826 if ( m_scrollbarHorz )
827 m_scrollbarHorz->Refresh();
828
829 if ( m_scrollbarVert )
830 m_scrollbarVert->Refresh();
9a6384ca 831#endif // wxUSE_SCROLLBAR
1e6feb95
VZ
832}
833
834void wxWindow::PositionScrollbars()
835{
9a6384ca 836#if wxUSE_SCROLLBAR
1e6feb95
VZ
837 // do not use GetClientSize/Rect as it relies on the scrollbars being
838 // correctly positioned
839
840 wxSize size = GetSize();
841 wxBorder border = GetBorder();
842 wxRect rectBorder = m_renderer->GetBorderDimensions(border);
843 bool inside = m_renderer->AreScrollbarsInsideBorder();
844
845 int height = m_scrollbarHorz ? m_scrollbarHorz->GetSize().y : 0;
846 int width = m_scrollbarVert ? m_scrollbarVert->GetSize().x : 0;
847
848 wxRect rectBar;
849 if ( m_scrollbarVert )
850 {
851 rectBar.x = size.x - width;
852 if ( inside )
853 rectBar.x -= rectBorder.width;
854 rectBar.width = width;
855 rectBar.y = 0;
856 if ( inside )
857 rectBar.y += rectBorder.y;
858 rectBar.height = size.y - height;
859 if ( inside )
860 rectBar.height -= rectBorder.y + rectBorder.height;
861
862 m_scrollbarVert->SetSize(rectBar, wxSIZE_NO_ADJUSTMENTS);
863 }
864
865 if ( m_scrollbarHorz )
866 {
867 rectBar.y = size.y - height;
868 if ( inside )
869 rectBar.y -= rectBorder.height;
870 rectBar.height = height;
871 rectBar.x = 0;
872 if ( inside )
873 rectBar.x += rectBorder.x;
874 rectBar.width = size.x - width;
875 if ( inside )
876 rectBar.width -= rectBorder.x + rectBorder.width;
877
878 m_scrollbarHorz->SetSize(rectBar, wxSIZE_NO_ADJUSTMENTS);
879 }
880
881 RefreshScrollbars();
9a6384ca 882#endif // wxUSE_SCROLLBAR
1e6feb95
VZ
883}
884
885void wxWindow::SetScrollbar(int orient,
886 int pos,
887 int pageSize,
888 int range,
889 bool refresh)
890{
9a6384ca 891#if wxUSE_SCROLLBAR
3f393e3d
VZ
892 wxASSERT_MSG( pageSize <= range,
893 _T("page size can't be greater than range") );
894
a290fa5a 895 bool hasClientSizeChanged = false;
1e6feb95 896 wxScrollBar *scrollbar = GetScrollbar(orient);
3f393e3d 897 if ( range && (pageSize < range) )
1e6feb95
VZ
898 {
899 if ( !scrollbar )
900 {
901 // create it
ab6b6b15 902#if wxUSE_TWO_WINDOWS
a290fa5a 903 SetInsertIntoMain( true );
ab6b6b15 904#endif
a290fa5a 905 scrollbar = new wxScrollBar(this, wxID_ANY,
1e6feb95
VZ
906 wxDefaultPosition, wxDefaultSize,
907 orient & wxVERTICAL ? wxSB_VERTICAL
908 : wxSB_HORIZONTAL);
ab6b6b15 909#if wxUSE_TWO_WINDOWS
a290fa5a 910 SetInsertIntoMain( false );
ab6b6b15 911#endif
1e6feb95
VZ
912 if ( orient & wxVERTICAL )
913 m_scrollbarVert = scrollbar;
914 else
915 m_scrollbarHorz = scrollbar;
916
917 // the client area diminished as we created a scrollbar
a290fa5a 918 hasClientSizeChanged = true;
1e6feb95
VZ
919
920 PositionScrollbars();
921 }
922 else if ( GetWindowStyle() & wxALWAYS_SHOW_SB )
923 {
924 // we might have disabled it before
925 scrollbar->Enable();
926 }
927
928 scrollbar->SetScrollbar(pos, pageSize, range, pageSize, refresh);
929 }
930 else // no range means no scrollbar
931 {
932 if ( scrollbar )
933 {
934 // wxALWAYS_SHOW_SB only applies to the vertical scrollbar
935 if ( (orient & wxVERTICAL) && (GetWindowStyle() & wxALWAYS_SHOW_SB) )
936 {
937 // just disable the scrollbar
938 scrollbar->SetScrollbar(pos, pageSize, range, pageSize, refresh);
939 scrollbar->Disable();
940 }
941 else // really remove the scrollbar
942 {
943 delete scrollbar;
944
945 if ( orient & wxVERTICAL )
946 m_scrollbarVert = NULL;
947 else
948 m_scrollbarHorz = NULL;
949
950 // the client area increased as we removed a scrollbar
a290fa5a 951 hasClientSizeChanged = true;
1e6feb95
VZ
952
953 // the size of the remaining scrollbar must be adjusted
954 if ( m_scrollbarHorz || m_scrollbarVert )
955 {
956 PositionScrollbars();
957 }
958 }
959 }
960 }
961
962 // give the window a chance to relayout
963 if ( hasClientSizeChanged )
964 {
a17a79ba
RR
965#if wxUSE_TWO_WINDOWS
966 wxWindowNative::SetSize( GetSize() );
967#else
1e6feb95
VZ
968 wxSizeEvent event(GetSize());
969 (void)GetEventHandler()->ProcessEvent(event);
a17a79ba 970#endif
1e6feb95 971 }
9a6384ca
WS
972#else
973 wxUnusedVar(orient);
974 wxUnusedVar(pos);
975 wxUnusedVar(pageSize);
976 wxUnusedVar(range);
977 wxUnusedVar(refresh);
978#endif // wxUSE_SCROLLBAR
1e6feb95
VZ
979}
980
61fef19b 981void wxWindow::SetScrollPos(int orient, int pos, bool WXUNUSED(refresh))
1e6feb95 982{
9a6384ca 983#if wxUSE_SCROLLBAR
1e6feb95 984 wxScrollBar *scrollbar = GetScrollbar(orient);
1e6feb95 985
45e13c7f
JS
986 if (scrollbar)
987 scrollbar->SetThumbPosition(pos);
7d297414
VZ
988
989 // VZ: I think we can safely ignore this as we always refresh it
990 // automatically whenever the value chanegs
991#if 0
1e6feb95
VZ
992 if ( refresh )
993 Refresh();
7d297414 994#endif
9a6384ca
WS
995#else
996 wxUnusedVar(orient);
997 wxUnusedVar(pos);
998#endif // wxUSE_SCROLLBAR
1e6feb95
VZ
999}
1000
1001int wxWindow::GetScrollPos(int orient) const
1002{
9a6384ca 1003#if wxUSE_SCROLLBAR
1e6feb95
VZ
1004 wxScrollBar *scrollbar = GetScrollbar(orient);
1005 return scrollbar ? scrollbar->GetThumbPosition() : 0;
9a6384ca
WS
1006#else
1007 wxUnusedVar(orient);
1008 return 0;
1009#endif // wxUSE_SCROLLBAR
1e6feb95
VZ
1010}
1011
1012int wxWindow::GetScrollThumb(int orient) const
1013{
9a6384ca 1014#if wxUSE_SCROLLBAR
1e6feb95
VZ
1015 wxScrollBar *scrollbar = GetScrollbar(orient);
1016 return scrollbar ? scrollbar->GetThumbSize() : 0;
9a6384ca
WS
1017#else
1018 wxUnusedVar(orient);
1019 return 0;
1020#endif // wxUSE_SCROLLBAR
1e6feb95
VZ
1021}
1022
1023int wxWindow::GetScrollRange(int orient) const
1024{
9a6384ca 1025#if wxUSE_SCROLLBAR
1e6feb95
VZ
1026 wxScrollBar *scrollbar = GetScrollbar(orient);
1027 return scrollbar ? scrollbar->GetRange() : 0;
9a6384ca
WS
1028#else
1029 wxUnusedVar(orient);
1030 return 0;
1031#endif // wxUSE_SCROLLBAR
1e6feb95
VZ
1032}
1033
1034void wxWindow::ScrollWindow(int dx, int dy, const wxRect *rect)
1035{
66a58655
VS
1036 // use native scrolling when available and do it in generic way
1037 // otherwise:
4125131b
RR
1038#ifdef __WXX11__
1039
66a58655 1040 wxWindowNative::ScrollWindow(dx, dy, rect);
4125131b 1041
2b5f62a0 1042#else // !wxX11
4125131b 1043
1e6feb95
VZ
1044 // before scrolling it, ensure that we don't have any unpainted areas
1045 Update();
1046
1047 wxRect r;
1048
1049 if ( dx )
1050 {
1051 r = ScrollNoRefresh(dx, 0, rect);
a290fa5a 1052 Refresh(true /* erase bkgnd */, &r);
1e6feb95
VZ
1053 }
1054
1055 if ( dy )
1056 {
1057 r = ScrollNoRefresh(0, dy, rect);
a290fa5a 1058 Refresh(true /* erase bkgnd */, &r);
1e6feb95 1059 }
2b5f62a0
VZ
1060
1061 // scroll children accordingly:
66a58655 1062 wxPoint offset(dx, dy);
2b5f62a0 1063
ac32ba44 1064 for (wxWindowList::compatibility_iterator node = GetChildren().GetFirst();
66a58655
VS
1065 node; node = node->GetNext())
1066 {
1067 wxWindow *child = node->GetData();
9a6384ca 1068#if wxUSE_SCROLLBAR
1c9f1f4d
VS
1069 if ( child == m_scrollbarVert || child == m_scrollbarHorz )
1070 continue;
9a6384ca 1071#endif // wxUSE_SCROLLBAR
1c9f1f4d
VS
1072
1073 // VS: Scrolling children has non-trivial semantics. If rect=NULL then
2b5f62a0 1074 // it is easy: we scroll all children. Otherwise it gets
1c9f1f4d
VS
1075 // complicated:
1076 // 1. if scrolling in one direction only, scroll only
1077 // those children that intersect shaft defined by the rectangle
1078 // and scrolling direction
1079 // 2. if scrolling in both axes, scroll all children
2b5f62a0 1080
1c9f1f4d
VS
1081 if ( rect && (dx * dy == 0 /* moving in only one of x, y axis */) )
1082 {
1083 wxRect childRect = child->GetRect();
1084 if ( dx == 0 && (childRect.GetLeft() <= rect->GetRight() ||
1085 childRect.GetRight() >= rect->GetLeft()) )
1086 {
1087 child->Move(child->GetPosition() + offset);
1088 }
1089 else if ( dy == 0 && (childRect.GetTop() <= rect->GetBottom() ||
1090 childRect.GetBottom() >= rect->GetTop()) )
1091 {
1092 child->Move(child->GetPosition() + offset);
1093 }
1094 }
1095 else
66a58655
VS
1096 {
1097 child->Move(child->GetPosition() + offset);
1098 }
2b5f62a0
VZ
1099 }
1100#endif // wxX11/!wxX11
1e6feb95
VZ
1101}
1102
1103wxRect wxWindow::ScrollNoRefresh(int dx, int dy, const wxRect *rectTotal)
1104{
1105 wxASSERT_MSG( !dx || !dy, _T("can't be used for diag scrolling") );
1106
1107 // the rect to refresh (which we will calculate)
1108 wxRect rect;
1109
1110 if ( !dx && !dy )
1111 {
1112 // nothing to do
1113 return rect;
1114 }
1115
1116 // calculate the part of the window which we can just redraw in the new
1117 // location
1118 wxSize sizeTotal = rectTotal ? rectTotal->GetSize() : GetClientSize();
1119
1120 wxLogTrace(_T("scroll"), _T("rect is %dx%d, scroll by %d, %d"),
1121 sizeTotal.x, sizeTotal.y, dx, dy);
1122
1123 // the initial and end point of the region we move in client coords
1124 wxPoint ptSource, ptDest;
1125 if ( rectTotal )
1126 {
1127 ptSource = rectTotal->GetPosition();
1128 ptDest = rectTotal->GetPosition();
1129 }
1130
1131 // the size of this region
1132 wxSize size;
1133 size.x = sizeTotal.x - abs(dx);
1134 size.y = sizeTotal.y - abs(dy);
1135 if ( size.x <= 0 || size.y <= 0 )
1136 {
1137 // just redraw everything as nothing of the displayed image will stay
1138 wxLogTrace(_T("scroll"), _T("refreshing everything"));
1139
1140 rect = rectTotal ? *rectTotal : wxRect(0, 0, sizeTotal.x, sizeTotal.y);
1141 }
1142 else // move the part which doesn't change to the new location
1143 {
1144 // note that when we scroll the canvas in some direction we move the
1145 // block which doesn't need to be refreshed in the opposite direction
1146
1147 if ( dx < 0 )
1148 {
1149 // scroll to the right, move to the left
1150 ptSource.x -= dx;
1151 }
1152 else
1153 {
1154 // scroll to the left, move to the right
1155 ptDest.x += dx;
1156 }
1157
1158 if ( dy < 0 )
1159 {
1160 // scroll down, move up
1161 ptSource.y -= dy;
1162 }
1163 else
1164 {
1165 // scroll up, move down
1166 ptDest.y += dy;
1167 }
1168
1169#if wxUSE_CARET
1170 // we need to hide the caret before moving or it will erase itself at
1171 // the wrong (old) location
1172 wxCaret *caret = GetCaret();
1173 if ( caret )
1174 caret->Hide();
1175#endif // wxUSE_CARET
1176
1177 // do move
1178 wxClientDC dc(this);
1179 wxBitmap bmp(size.x, size.y);
1180 wxMemoryDC dcMem;
1181 dcMem.SelectObject(bmp);
1182
c47addef 1183 dcMem.Blit(wxPoint(0,0), size, &dc, ptSource
03147cd0 1184#if defined(__WXGTK__) && !defined(wxHAS_WORKING_GTK_DC_BLIT)
1e6feb95
VZ
1185 + GetClientAreaOrigin()
1186#endif // broken wxGTK wxDC::Blit
1187 );
c47addef 1188 dc.Blit(ptDest, size, &dcMem, wxPoint(0,0));
1e6feb95
VZ
1189
1190 wxLogTrace(_T("scroll"),
1191 _T("Blit: (%d, %d) of size %dx%d -> (%d, %d)"),
1192 ptSource.x, ptSource.y,
1193 size.x, size.y,
1194 ptDest.x, ptDest.y);
1195
1196 // and now repaint the uncovered area
1197
1198 // FIXME: We repaint the intersection of these rectangles twice - is
1199 // it bad? I don't think so as it is rare to scroll the window
1200 // diagonally anyhow and so adding extra logic to compute
1201 // rectangle intersection is probably not worth the effort
1202
1203 rect.x = ptSource.x;
1204 rect.y = ptSource.y;
1205
1206 if ( dx )
1207 {
1208 if ( dx < 0 )
1209 {
1210 // refresh the area along the right border
1211 rect.x += size.x + dx;
1212 rect.width = -dx;
1213 }
1214 else
1215 {
1216 // refresh the area along the left border
1217 rect.width = dx;
1218 }
1219
1220 rect.height = sizeTotal.y;
1221
1222 wxLogTrace(_T("scroll"), _T("refreshing (%d, %d)-(%d, %d)"),
1223 rect.x, rect.y,
1224 rect.GetRight() + 1, rect.GetBottom() + 1);
1225 }
1226
1227 if ( dy )
1228 {
1229 if ( dy < 0 )
1230 {
1231 // refresh the area along the bottom border
1232 rect.y += size.y + dy;
1233 rect.height = -dy;
1234 }
1235 else
1236 {
1237 // refresh the area along the top border
1238 rect.height = dy;
1239 }
1240
1241 rect.width = sizeTotal.x;
1242
1243 wxLogTrace(_T("scroll"), _T("refreshing (%d, %d)-(%d, %d)"),
1244 rect.x, rect.y,
1245 rect.GetRight() + 1, rect.GetBottom() + 1);
1246 }
1247
1248#if wxUSE_CARET
1249 if ( caret )
1250 caret->Show();
1251#endif // wxUSE_CARET
1252 }
1253
1254 return rect;
1255}
1256
1e6feb95
VZ
1257// ----------------------------------------------------------------------------
1258// accelerators and menu hot keys
1259// ----------------------------------------------------------------------------
1260
1261#if wxUSE_MENUS
1262 // the last window over which Alt was pressed (used by OnKeyUp)
1263 wxWindow *wxWindow::ms_winLastAltPress = NULL;
1264#endif // wxUSE_MENUS
1265
1266#if wxUSE_ACCEL || wxUSE_MENUS
1267
1268void wxWindow::OnKeyDown(wxKeyEvent& event)
1269{
1270#if wxUSE_MENUS
1271 int key = event.GetKeyCode();
f52c3131 1272 if ( !event.ControlDown() && (key == WXK_ALT || key == WXK_F10) )
1e6feb95
VZ
1273 {
1274 ms_winLastAltPress = this;
1275
1276 // it can't be an accel anyhow
1277 return;
1278 }
1279
1280 ms_winLastAltPress = NULL;
1281#endif // wxUSE_MENUS
1282
1283#if wxUSE_ACCEL
1284 for ( wxWindow *win = this; win; win = win->GetParent() )
1285 {
1286 int command = win->GetAcceleratorTable()->GetCommand(event);
1287 if ( command != -1 )
1288 {
1289 wxCommandEvent eventCmd(wxEVT_COMMAND_MENU_SELECTED, command);
1290 if ( win->GetEventHandler()->ProcessEvent(eventCmd) )
1291 {
1292 // skip "event.Skip()" below
1293 return;
1294 }
1295 }
1296
1297 if ( win->IsTopLevel() )
1298 {
1299 // try the frame menu bar
1300#if wxUSE_MENUS
1301 wxFrame *frame = wxDynamicCast(win, wxFrame);
1302 if ( frame )
1303 {
1304 wxMenuBar *menubar = frame->GetMenuBar();
1305 if ( menubar && menubar->ProcessAccelEvent(event) )
1306 {
1307 // skip "event.Skip()" below
1308 return;
1309 }
1310 }
1311#endif // wxUSE_MENUS
1312
81762e79
VS
1313 // if it wasn't in a menu, try to find a button
1314 if ( command != -1 )
1315 {
1316 wxWindow* child = win->FindWindow(command);
1317 if ( child && wxDynamicCast(child, wxButton) )
1318 {
1319 wxCommandEvent eventCmd(wxEVT_COMMAND_BUTTON_CLICKED, command);
1320 eventCmd.SetEventObject(child);
1321 if ( child->GetEventHandler()->ProcessEvent(eventCmd) )
1322 {
1323 // skip "event.Skip()" below
1324 return;
1325 }
1326 }
1327 }
1328
1e6feb95
VZ
1329 // don't propagate accels from the child frame to the parent one
1330 break;
1331 }
1332 }
1333#endif // wxUSE_ACCEL
1334
1335 event.Skip();
1336}
1337
1338#endif // wxUSE_ACCEL
1339
1340#if wxUSE_MENUS
1341
1342wxMenuBar *wxWindow::GetParentFrameMenuBar() const
1343{
1344 for ( const wxWindow *win = this; win; win = win->GetParent() )
1345 {
1346 if ( win->IsTopLevel() )
1347 {
1348 wxFrame *frame = wxDynamicCast(win, wxFrame);
1349 if ( frame )
1350 {
1351 return frame->GetMenuBar();
1352 }
1353
1354 // don't look further - we don't want to return the menubar of the
1355 // parent frame
1356 break;
1357 }
1358 }
1359
1360 return NULL;
1361}
1362
1363void wxWindow::OnChar(wxKeyEvent& event)
1364{
1365 if ( event.AltDown() && !event.ControlDown() )
1366 {
1367 int key = event.GetKeyCode();
1368
1369 wxMenuBar *menubar = GetParentFrameMenuBar();
1370 if ( menubar )
1371 {
1372 int item = menubar->FindNextItemForAccel(-1, key);
1373 if ( item != -1 )
1374 {
1375 menubar->PopupMenu((size_t)item);
1376
1377 // skip "event.Skip()" below
1378 return;
1379 }
1380 }
1381 }
1382
1383 event.Skip();
1384}
1385
1386void wxWindow::OnKeyUp(wxKeyEvent& event)
1387{
1388 int key = event.GetKeyCode();
f52c3131 1389 if ( !event.HasModifiers() && (key == WXK_ALT || key == WXK_F10) )
1e6feb95
VZ
1390 {
1391 // only process Alt release specially if there were no other key
1392 // presses since Alt had been pressed and if both events happened in
1393 // the same window
1394 if ( ms_winLastAltPress == this )
1395 {
1396 wxMenuBar *menubar = GetParentFrameMenuBar();
1397 if ( menubar && this != menubar )
1398 {
1399 menubar->SelectMenu(0);
1400 }
1401 }
1402 }
1403 else
1404 {
1405 event.Skip();
1406 }
1407
1408 // in any case reset it
1409 ms_winLastAltPress = NULL;
1410}
1411
1412#endif // wxUSE_MENUS
1413
30827629
VZ
1414// ----------------------------------------------------------------------------
1415// MSW-specific section
1416// ----------------------------------------------------------------------------
1417
1418#ifdef __WXMSW__
1419
1420#include "wx/msw/private.h"
1421
c140b7e7 1422WXLRESULT wxWindow::MSWWindowProc(WXUINT message, WXWPARAM wParam, WXLPARAM lParam)
30827629
VZ
1423{
1424 if ( message == WM_NCHITTEST )
1425 {
1426 // the windows which contain the other windows should let the mouse
1427 // events through, otherwise a window inside a static box would
1428 // never get any events at all
1429 if ( IsStaticBox() )
1430 {
1431 return HTTRANSPARENT;
1432 }
1433 }
1434
1435 return wxWindowNative::MSWWindowProc(message, wParam, lParam);
1436}
1437
1438#endif // __WXMSW__