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