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