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