1 /////////////////////////////////////////////////////////////////////////////// 
   2 // Name:        univ/window.cpp 
   3 // Purpose:     implementation of extra wxWindow methods for wxUniv port 
   4 // Author:      Vadim Zeitlin 
   8 // Copyright:   (c) 2000 SciTech Software, Inc. (www.scitechsoft.com) 
   9 // Licence:     wxWindows licence 
  10 /////////////////////////////////////////////////////////////////////////////// 
  12 // =========================================================================== 
  14 // =========================================================================== 
  16 // --------------------------------------------------------------------------- 
  18 // --------------------------------------------------------------------------- 
  20 #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA) 
  21     #pragma implementation "univwindow.h" 
  24 // For compilers that support precompilation, includes "wx.h". 
  25 #include "wx/wxprec.h" 
  33     #include "wx/window.h" 
  34     #include "wx/dcclient.h" 
  35     #include "wx/dcmemory.h" 
  37     #include "wx/scrolbar.h" 
  43 #include "wx/univ/colschem.h" 
  44 #include "wx/univ/renderer.h" 
  45 #include "wx/univ/theme.h" 
  51 // turn Refresh() debugging on/off 
  52 #define WXDEBUG_REFRESH 
  55     #undef WXDEBUG_REFRESH 
  58 #if defined(WXDEBUG_REFRESH) && defined(__WXMSW__) && !defined(__WXMICROWIN__) 
  59 #include "wx/msw/private.h" 
  62 // ============================================================================ 
  64 // ============================================================================ 
  66 // ---------------------------------------------------------------------------- 
  68 // ---------------------------------------------------------------------------- 
  70 // we can't use wxWindowNative here as it won't be expanded inside the macro 
  71 #if defined(__WXMSW__) 
  72     IMPLEMENT_DYNAMIC_CLASS(wxWindow
, wxWindowMSW
) 
  73 #elif defined(__WXGTK__) 
  74     IMPLEMENT_DYNAMIC_CLASS(wxWindow
, wxWindowGTK
) 
  75 #elif defined(__WXMGL__) 
  76     IMPLEMENT_DYNAMIC_CLASS(wxWindow
, wxWindowMGL
) 
  77 #elif defined(__WXX11__) 
  78     IMPLEMENT_DYNAMIC_CLASS(wxWindow
, wxWindowX11
) 
  79 #elif defined(__WXPM__) 
  80     IMPLEMENT_DYNAMIC_CLASS(wxWindow
, wxWindowOS2
) 
  83 BEGIN_EVENT_TABLE(wxWindow
, wxWindowNative
) 
  84     EVT_SIZE(wxWindow::OnSize
) 
  86 #if wxUSE_ACCEL || wxUSE_MENUS 
  87     EVT_KEY_DOWN(wxWindow::OnKeyDown
) 
  91     EVT_CHAR(wxWindow::OnChar
) 
  92     EVT_KEY_UP(wxWindow::OnKeyUp
) 
  95     EVT_PAINT(wxWindow::OnPaint
) 
  96     EVT_NC_PAINT(wxWindow::OnNcPaint
) 
  97     EVT_ERASE_BACKGROUND(wxWindow::OnErase
) 
 100 // ---------------------------------------------------------------------------- 
 102 // ---------------------------------------------------------------------------- 
 104 void wxWindow::Init() 
 107     m_scrollbarHorz 
= (wxScrollBar 
*)NULL
; 
 111     m_renderer 
= wxTheme::Get()->GetRenderer(); 
 113     m_oldSize
.x 
= wxDefaultCoord
; 
 114     m_oldSize
.y 
= wxDefaultCoord
; 
 117 bool wxWindow::Create(wxWindow 
*parent
, 
 122                       const wxString
& name
) 
 124     long actualStyle 
= style
; 
 126     // FIXME: may need this on other platforms 
 128     actualStyle 
&= ~wxVSCROLL
; 
 129     actualStyle 
&= ~wxHSCROLL
; 
 132     // we add wxCLIP_CHILDREN to get the same ("natural") behaviour under MSW 
 133     // as under the other platforms 
 134     if ( !wxWindowNative::Create(parent
, id
, pos
, size
, 
 135                                  actualStyle 
| wxCLIP_CHILDREN
, 
 141     // Set full style again, including those we didn't want present 
 142     // when calling the base window Create(). 
 143     wxWindowBase::SetWindowStyleFlag(style
); 
 145     // if we should always have a vertical scrollbar, do show it 
 146     if ( style 
& wxALWAYS_SHOW_SB 
) 
 148 #if wxUSE_TWO_WINDOWS 
 149         SetInsertIntoMain( true ); 
 151         m_scrollbarVert 
= new wxScrollBar(this, wxID_ANY
, 
 152                                           wxDefaultPosition
, wxDefaultSize
, 
 154 #if wxUSE_TWO_WINDOWS 
 155         SetInsertIntoMain( false ); 
 159     // if we should always have a horizontal scrollbar, do show it 
 160     if ( style 
& wxHSCROLL 
) 
 162 #if wxUSE_TWO_WINDOWS 
 163         SetInsertIntoMain( true ); 
 165         m_scrollbarHorz 
= new wxScrollBar(this, wxID_ANY
, 
 166                                           wxDefaultPosition
, wxDefaultSize
, 
 168 #if wxUSE_TWO_WINDOWS 
 169         SetInsertIntoMain( false ); 
 173     if (m_scrollbarHorz 
|| m_scrollbarVert
) 
 176         PositionScrollbars(); 
 182 wxWindow::~wxWindow() 
 184     m_isBeingDeleted 
= true; 
 186     // we have to destroy our children before we're destroyed because our 
 187     // children suppose that we're of type wxWindow, not just wxWindowNative, 
 188     // and so bad things may happen if they're deleted from the base class dtor 
 189     // as by then we're not a wxWindow any longer and wxUniv-specific virtual 
 190     // functions can't be called 
 194 // ---------------------------------------------------------------------------- 
 196 // ---------------------------------------------------------------------------- 
 198 void wxWindow::SetBackground(const wxBitmap
& bitmap
, 
 203     m_alignBgBitmap 
= alignment
; 
 204     m_stretchBgBitmap 
= stretch
; 
 207 const wxBitmap
& wxWindow::GetBackgroundBitmap(int *alignment
, 
 208                                                wxStretch 
*stretch
) const 
 210     if ( m_bitmapBg
.Ok() ) 
 213             *alignment 
= m_alignBgBitmap
; 
 215             *stretch 
= m_stretchBgBitmap
; 
 221 // ---------------------------------------------------------------------------- 
 223 // ---------------------------------------------------------------------------- 
 225 // the event handlers executed when the window must be repainted 
 226 void wxWindow::OnNcPaint(wxNcPaintEvent
& WXUNUSED(event
)) 
 230         // get the window rect 
 232         wxSize size 
= GetSize(); 
 236         rect
.height 
= size
.y
; 
 238         // if the scrollbars are outside the border, we must adjust the rect to 
 240         if ( !m_renderer
->AreScrollbarsInsideBorder() ) 
 242             wxScrollBar 
*scrollbar 
= GetScrollbar(wxVERTICAL
); 
 244                 rect
.width 
-= scrollbar
->GetSize().x
; 
 246             scrollbar 
= GetScrollbar(wxHORIZONTAL
); 
 248                 rect
.height 
-= scrollbar
->GetSize().y
; 
 251         // get the DC and draw the border on it 
 253         DoDrawBorder(dc
, rect
); 
 257 void wxWindow::OnPaint(wxPaintEvent
& event
) 
 261         // it is a native control which paints itself 
 266         // get the DC to use and create renderer on it 
 268         wxControlRenderer 
renderer(this, dc
, m_renderer
); 
 275 // the event handler executed when the window background must be painted 
 276 void wxWindow::OnErase(wxEraseEvent
& event
) 
 285     DoDrawBackground(*event
.GetDC()); 
 287     // if we have both scrollbars, we also have a square in the corner between 
 288     // them which we must paint 
 289     if ( m_scrollbarVert 
&& m_scrollbarHorz 
) 
 291         wxSize size 
= GetSize(); 
 292         wxRect rectClient 
= GetClientRect(), 
 293                rectBorder 
= m_renderer
->GetBorderDimensions(GetBorder()); 
 296         rectCorner
.x 
= rectClient
.GetRight() + 1; 
 297         rectCorner
.y 
= rectClient
.GetBottom() + 1; 
 298         rectCorner
.SetRight(size
.x 
- rectBorder
.width
); 
 299         rectCorner
.SetBottom(size
.y 
- rectBorder
.height
); 
 301         if ( GetUpdateRegion().Contains(rectCorner
) ) 
 303             m_renderer
->DrawScrollCorner(*event
.GetDC(), rectCorner
); 
 308 bool wxWindow::DoDrawBackground(wxDC
& dc
) 
 312     wxSize size 
= GetSize();  // Why not GetClientSize() ? 
 316     rect
.height 
= size
.y
; 
 318     wxWindow 
* const parent 
= GetParent(); 
 319     if ( HasTransparentBackground() && parent 
&& parent
->ProvidesBackground() ) 
 321         wxASSERT( !IsTopLevel() ); 
 323         wxPoint pos 
= GetPosition(); 
 325         AdjustForParentClientOrigin( pos
.x
, pos
.y
, 0 ); 
 327         // Adjust DC logical origin 
 328         wxCoord org_x
, org_y
, x
, y
; 
 329         dc
.GetLogicalOrigin( &org_x
, &org_y 
); 
 332         dc
.SetLogicalOrigin( x
, y 
); 
 338         // Let parent draw the background 
 339         parent
->EraseBackground( dc
, rect 
); 
 341         // Restore DC logical origin 
 342         dc
.SetLogicalOrigin( org_x
, org_y 
); 
 346         // Draw background ouselves 
 347         EraseBackground( dc
, rect 
); 
 353 void wxWindow::EraseBackground(wxDC
& dc
, const wxRect
& rect
) 
 355     if ( GetBackgroundBitmap().Ok() ) 
 357         // Get the bitmap and the flags 
 360         wxBitmap bmp 
= GetBackgroundBitmap(&alignment
, &stretch
); 
 361         wxControlRenderer::DrawBitmap(dc
, bmp
, rect
, alignment
, stretch
); 
 365         // Just fill it with bg colour if no bitmap 
 367         m_renderer
->DrawBackground(dc
, wxTHEME_BG_COLOUR(this), 
 368                                    rect
, GetStateFlags()); 
 372 void wxWindow::DoDrawBorder(wxDC
& dc
, const wxRect
& rect
) 
 374     // draw outline unless the update region is enitrely inside it in which 
 375     // case we don't need to do it 
 376 #if 0 // doesn't seem to work, why? 
 377     if ( wxRegion(rect
).Contains(GetUpdateRegion().GetBox()) != wxInRegion 
) 
 380         m_renderer
->DrawBorder(dc
, GetBorder(), rect
, GetStateFlags()); 
 384 void wxWindow::DoDraw(wxControlRenderer 
* WXUNUSED(renderer
)) 
 388 void wxWindow::Refresh(bool eraseBackground
, const wxRect 
*rectClient
) 
 391     wxPoint pt 
= GetClientAreaOrigin(); 
 393     wxSize size 
= GetClientSize(); 
 397         rectWin 
= *rectClient
; 
 399         // don't refresh anything beyond the client area (scrollbars for 
 401         if ( rectWin
.GetRight() > size
.x 
) 
 402             rectWin
.SetRight(size
.x
); 
 403         if ( rectWin
.GetBottom() > size
.y 
) 
 404             rectWin
.SetBottom(size
.y
); 
 408     else // refresh the entire client area 
 412         rectWin
.width 
= size
.x
; 
 413         rectWin
.height 
= size
.y
; 
 417 #ifdef WXDEBUG_REFRESH 
 418     static bool s_refreshDebug 
= false; 
 419     if ( s_refreshDebug 
) 
 422         dc
.SetBrush(*wxCYAN_BRUSH
); 
 423         dc
.SetPen(*wxTRANSPARENT_PEN
); 
 424         dc
.DrawRectangle(rectWin
); 
 426         // under Unix we use "--sync" X option for this 
 427         #if defined(__WXMSW__) && !defined(__WXMICROWIN__) 
 432 #endif // WXDEBUG_REFRESH 
 434     wxWindowNative::Refresh(eraseBackground
, &rectWin
); 
 436     // Refresh all sub controls if any. 
 437     wxWindowList::compatibility_iterator node 
= GetChildren().GetFirst(); 
 440         wxWindow 
*win 
= node
->GetData(); 
 441         // Only refresh sub controls when it is visible 
 442         // and when it is in the update region. 
 443         if(!win
->IsKindOf(CLASSINFO(wxTopLevelWindow
)) && win
->IsShown() && wxRegion(rectWin
).Contains(win
->GetRect()) != wxOutRegion
) 
 444             win
->Refresh(eraseBackground
, &rectWin
); 
 446         node 
= node
->GetNext(); 
 450 // ---------------------------------------------------------------------------- 
 452 // ---------------------------------------------------------------------------- 
 454 bool wxWindow::Enable(bool enable
) 
 456     if ( !wxWindowNative::Enable(enable
) ) 
 459     // disabled window can't keep focus 
 460     if ( FindFocus() == this && GetParent() != NULL 
) 
 462         GetParent()->SetFocus(); 
 467         // a window with renderer is drawn by ourselves and it has to be 
 468         // refreshed to reflect its new status 
 475 bool wxWindow::IsFocused() const 
 477     wxWindow 
*self 
= wxConstCast(this, wxWindow
); 
 478     return self
->FindFocus() == self
; 
 481 bool wxWindow::IsPressed() const 
 486 bool wxWindow::IsDefault() const 
 491 bool wxWindow::IsCurrent() const 
 496 bool wxWindow::SetCurrent(bool doit
) 
 498     if ( doit 
== m_isCurrent 
) 
 503     if ( CanBeHighlighted() ) 
 509 int wxWindow::GetStateFlags() const 
 513         flags 
|= wxCONTROL_DISABLED
; 
 515     // the following states are only possible if our application is active - if 
 516     // it is not, even our default/focused controls shouldn't appear as such 
 517     if ( wxTheApp
->IsActive() ) 
 520             flags 
|= wxCONTROL_CURRENT
; 
 522             flags 
|= wxCONTROL_FOCUSED
; 
 524             flags 
|= wxCONTROL_PRESSED
; 
 526             flags 
|= wxCONTROL_ISDEFAULT
; 
 532 // ---------------------------------------------------------------------------- 
 534 // ---------------------------------------------------------------------------- 
 536 void wxWindow::OnSize(wxSizeEvent
& event
) 
 540     if ( m_scrollbarVert 
|| m_scrollbarHorz 
) 
 542         PositionScrollbars(); 
 545 #if 0   // ndef __WXMSW__ 
 546     // Refresh the area (strip) previously occupied by the border 
 548     if ( !HasFlag(wxFULL_REPAINT_ON_RESIZE
) && IsShown() ) 
 550         // This code assumes that wxSizeEvent.GetSize() returns 
 551         // the area of the entire window, not just the client 
 553         wxSize newSize 
= event
.GetSize(); 
 555         if (m_oldSize
.x 
== wxDefaultCoord 
&& m_oldSize
.y 
== wxDefaultCoord
) 
 561         if (HasFlag( wxSIMPLE_BORDER 
)) 
 563             if (newSize
.y 
> m_oldSize
.y
) 
 567                 rect
.width 
= m_oldSize
.x
; 
 568                 rect
.y 
= m_oldSize
.y
-2; 
 570                 Refresh( true, &rect 
); 
 572             else if (newSize
.y 
< m_oldSize
.y
) 
 578                 rect
.width 
= newSize
.x
; 
 579                 wxWindowNative::Refresh( true, &rect 
); 
 582             if (newSize
.x 
> m_oldSize
.x
) 
 586                 rect
.height 
= m_oldSize
.y
; 
 587                 rect
.x 
= m_oldSize
.x
-2; 
 589                 Refresh( true, &rect 
); 
 591             else if (newSize
.x 
< m_oldSize
.x
) 
 597                 rect
.height 
= newSize
.y
; 
 598                 wxWindowNative::Refresh( true, &rect 
); 
 602         if (HasFlag( wxSUNKEN_BORDER 
) || HasFlag( wxRAISED_BORDER 
)) 
 604             if (newSize
.y 
> m_oldSize
.y
) 
 608                 rect
.width 
= m_oldSize
.x
; 
 609                 rect
.y 
= m_oldSize
.y
-4; 
 611                 Refresh( true, &rect 
); 
 613             else if (newSize
.y 
< m_oldSize
.y
) 
 619                 rect
.width 
= newSize
.x
; 
 620                 wxWindowNative::Refresh( true, &rect 
); 
 623             if (newSize
.x 
> m_oldSize
.x
) 
 627                 rect
.height 
= m_oldSize
.y
; 
 628                 rect
.x 
= m_oldSize
.x
-4; 
 630                 Refresh( true, &rect 
); 
 632             else if (newSize
.x 
< m_oldSize
.x
) 
 638                 rect
.height 
= newSize
.y
; 
 639                 wxWindowNative::Refresh( true, &rect 
); 
 648 wxSize 
wxWindow::DoGetBestSize() const 
 650     return AdjustSize(DoGetBestClientSize()); 
 653 wxSize 
wxWindow::DoGetBestClientSize() const 
 655     return wxWindowNative::DoGetBestSize(); 
 658 wxSize 
wxWindow::AdjustSize(const wxSize
& size
) const 
 662         m_renderer
->AdjustSize(&sz
, this); 
 666 wxPoint 
wxWindow::GetClientAreaOrigin() const 
 668     wxPoint pt 
= wxWindowBase::GetClientAreaOrigin(); 
 670 #if wxUSE_TWO_WINDOWS 
 673         pt 
+= m_renderer
->GetBorderDimensions(GetBorder()).GetPosition(); 
 679 void wxWindow::DoGetClientSize(int *width
, int *height
) const 
 681     // if it is a native window, we assume it handles the scrollbars itself 
 682     // too - and if it doesn't, there is not much we can do 
 685         wxWindowNative::DoGetClientSize(width
, height
); 
 691     wxWindowNative::DoGetClientSize(&w
, &h
); 
 693     // we assume that the scrollbars are positioned correctly (by a previous 
 694     // call to PositionScrollbars()) here 
 698         rectBorder 
= m_renderer
->GetBorderDimensions(GetBorder()); 
 700     bool inside 
= m_renderer
->AreScrollbarsInsideBorder(); 
 704         // in any case, take account of the scrollbar 
 705         if ( m_scrollbarVert 
) 
 706             w 
-= m_scrollbarVert
->GetSize().x
; 
 708         // if we don't have scrollbar or if it is outside the border (and not 
 709         // blended into it), take account of the right border as well 
 710         if ( !m_scrollbarVert 
|| inside 
) 
 711             w 
-= rectBorder
.width
; 
 713         // and always account for the left border 
 714         *width 
= w 
- rectBorder
.x
; 
 716         // we shouldn't return invalid width 
 723         if ( m_scrollbarHorz 
) 
 724             h 
-= m_scrollbarHorz
->GetSize().y
; 
 726         if ( !m_scrollbarHorz 
|| inside 
) 
 727             h 
-= rectBorder
.height
; 
 729         *height 
= h 
- rectBorder
.y
; 
 731         // we shouldn't return invalid height 
 737 void wxWindow::DoSetClientSize(int width
, int height
) 
 739     // take into account the borders 
 740     wxRect rectBorder 
= m_renderer
->GetBorderDimensions(GetBorder()); 
 741     width 
+= rectBorder
.x
; 
 742     height 
+= rectBorder
.y
; 
 744     // and the scrollbars (as they may be offset into the border, use the 
 745     // scrollbar position, not size - this supposes that PositionScrollbars() 
 746     // had been called before) 
 747     bool inside 
= m_renderer
->AreScrollbarsInsideBorder(); 
 748     wxSize size 
= GetSize(); 
 749     if ( m_scrollbarVert 
) 
 750         width 
+= size
.x 
- m_scrollbarVert
->GetPosition().x
; 
 751     if ( !m_scrollbarVert 
|| inside 
) 
 752         width 
+= rectBorder
.width
; 
 754     if ( m_scrollbarHorz 
) 
 755         height 
+= size
.y 
- m_scrollbarHorz
->GetPosition().y
; 
 756     if ( !m_scrollbarHorz 
|| inside 
) 
 757         height 
+= rectBorder
.height
; 
 759     wxWindowNative::DoSetClientSize(width
, height
); 
 762 wxHitTest 
wxWindow::DoHitTest(wxCoord x
, wxCoord y
) const 
 764     wxHitTest ht 
= wxWindowNative::DoHitTest(x
, y
); 
 765     if ( ht 
== wxHT_WINDOW_INSIDE 
) 
 767         if ( m_scrollbarVert 
&& x 
>= m_scrollbarVert
->GetPosition().x 
) 
 769             // it can still be changed below because it may also be the corner 
 770             ht 
= wxHT_WINDOW_VERT_SCROLLBAR
; 
 773         if ( m_scrollbarHorz 
&& y 
>= m_scrollbarHorz
->GetPosition().y 
) 
 775             ht 
= ht 
== wxHT_WINDOW_VERT_SCROLLBAR 
? wxHT_WINDOW_CORNER
 
 776                                                   : wxHT_WINDOW_HORZ_SCROLLBAR
; 
 783 // ---------------------------------------------------------------------------- 
 784 // scrolling: we implement it entirely ourselves except for ScrollWindow() 
 785 // function which is supposed to be (efficiently) implemented by the native 
 787 // ---------------------------------------------------------------------------- 
 789 void wxWindow::RefreshScrollbars() 
 791     if ( m_scrollbarHorz 
) 
 792         m_scrollbarHorz
->Refresh(); 
 794     if ( m_scrollbarVert 
) 
 795         m_scrollbarVert
->Refresh(); 
 798 void wxWindow::PositionScrollbars() 
 800     // do not use GetClientSize/Rect as it relies on the scrollbars being 
 801     // correctly positioned 
 803     wxSize size 
= GetSize(); 
 804     wxBorder border 
= GetBorder(); 
 805     wxRect rectBorder 
= m_renderer
->GetBorderDimensions(border
); 
 806     bool inside 
= m_renderer
->AreScrollbarsInsideBorder(); 
 808     int height 
= m_scrollbarHorz 
? m_scrollbarHorz
->GetSize().y 
: 0; 
 809     int width 
= m_scrollbarVert 
? m_scrollbarVert
->GetSize().x 
: 0; 
 812     if ( m_scrollbarVert 
) 
 814         rectBar
.x 
= size
.x 
- width
; 
 816            rectBar
.x 
-= rectBorder
.width
; 
 817         rectBar
.width 
= width
; 
 820             rectBar
.y 
+= rectBorder
.y
; 
 821         rectBar
.height 
= size
.y 
- height
; 
 823             rectBar
.height 
-= rectBorder
.y 
+ rectBorder
.height
; 
 825         m_scrollbarVert
->SetSize(rectBar
, wxSIZE_NO_ADJUSTMENTS
); 
 828     if ( m_scrollbarHorz 
) 
 830         rectBar
.y 
= size
.y 
- height
; 
 832             rectBar
.y 
-= rectBorder
.height
; 
 833         rectBar
.height 
= height
; 
 836             rectBar
.x 
+= rectBorder
.x
; 
 837         rectBar
.width 
= size
.x 
- width
; 
 839             rectBar
.width 
-= rectBorder
.x 
+ rectBorder
.width
; 
 841         m_scrollbarHorz
->SetSize(rectBar
, wxSIZE_NO_ADJUSTMENTS
); 
 847 void wxWindow::SetScrollbar(int orient
, 
 853     wxASSERT_MSG( pageSize 
<= range
, 
 854                     _T("page size can't be greater than range") ); 
 856     bool hasClientSizeChanged 
= false; 
 857     wxScrollBar 
*scrollbar 
= GetScrollbar(orient
); 
 858     if ( range 
&& (pageSize 
< range
) ) 
 863 #if wxUSE_TWO_WINDOWS 
 864             SetInsertIntoMain( true ); 
 866             scrollbar 
= new wxScrollBar(this, wxID_ANY
, 
 867                                         wxDefaultPosition
, wxDefaultSize
, 
 868                                         orient 
& wxVERTICAL 
? wxSB_VERTICAL
 
 870 #if wxUSE_TWO_WINDOWS 
 871             SetInsertIntoMain( false ); 
 873             if ( orient 
& wxVERTICAL 
) 
 874                 m_scrollbarVert 
= scrollbar
; 
 876                 m_scrollbarHorz 
= scrollbar
; 
 878             // the client area diminished as we created a scrollbar 
 879             hasClientSizeChanged 
= true; 
 881             PositionScrollbars(); 
 883         else if ( GetWindowStyle() & wxALWAYS_SHOW_SB 
) 
 885             // we might have disabled it before 
 889         scrollbar
->SetScrollbar(pos
, pageSize
, range
, pageSize
, refresh
); 
 891     else // no range means no scrollbar 
 895             // wxALWAYS_SHOW_SB only applies to the vertical scrollbar 
 896             if ( (orient 
& wxVERTICAL
) && (GetWindowStyle() & wxALWAYS_SHOW_SB
) ) 
 898                 // just disable the scrollbar 
 899                 scrollbar
->SetScrollbar(pos
, pageSize
, range
, pageSize
, refresh
); 
 900                 scrollbar
->Disable(); 
 902             else // really remove the scrollbar 
 906                 if ( orient 
& wxVERTICAL 
) 
 907                     m_scrollbarVert 
= NULL
; 
 909                     m_scrollbarHorz 
= NULL
; 
 911                 // the client area increased as we removed a scrollbar 
 912                 hasClientSizeChanged 
= true; 
 914                 // the size of the remaining scrollbar must be adjusted 
 915                 if ( m_scrollbarHorz 
|| m_scrollbarVert 
) 
 917                     PositionScrollbars(); 
 923     // give the window a chance to relayout 
 924     if ( hasClientSizeChanged 
) 
 926 #if wxUSE_TWO_WINDOWS 
 927         wxWindowNative::SetSize( GetSize() ); 
 929         wxSizeEvent 
event(GetSize()); 
 930         (void)GetEventHandler()->ProcessEvent(event
); 
 935 void wxWindow::SetScrollPos(int orient
, int pos
, bool WXUNUSED(refresh
)) 
 937     wxScrollBar 
*scrollbar 
= GetScrollbar(orient
); 
 938     wxCHECK_RET( scrollbar
, _T("no scrollbar to set position for") ); 
 940     scrollbar
->SetThumbPosition(pos
); 
 942     // VZ: I think we can safely ignore this as we always refresh it 
 943     //     automatically whenever the value chanegs 
 950 int wxWindow::GetScrollPos(int orient
) const 
 952     wxScrollBar 
*scrollbar 
= GetScrollbar(orient
); 
 953     return scrollbar 
? scrollbar
->GetThumbPosition() : 0; 
 956 int wxWindow::GetScrollThumb(int orient
) const 
 958     wxScrollBar 
*scrollbar 
= GetScrollbar(orient
); 
 959     return scrollbar 
? scrollbar
->GetThumbSize() : 0; 
 962 int wxWindow::GetScrollRange(int orient
) const 
 964     wxScrollBar 
*scrollbar 
= GetScrollbar(orient
); 
 965     return scrollbar 
? scrollbar
->GetRange() : 0; 
 968 void wxWindow::ScrollWindow(int dx
, int dy
, const wxRect 
*rect
) 
 970     // use native scrolling when available and do it in generic way 
 974     wxWindowNative::ScrollWindow(dx
, dy
, rect
); 
 978     // before scrolling it, ensure that we don't have any unpainted areas 
 985         r 
= ScrollNoRefresh(dx
, 0, rect
); 
 986         Refresh(true /* erase bkgnd */, &r
); 
 991         r 
= ScrollNoRefresh(0, dy
, rect
); 
 992         Refresh(true /* erase bkgnd */, &r
); 
 995     // scroll children accordingly: 
 996     wxPoint 
offset(dx
, dy
); 
 998     for (wxWindowList::compatibility_iterator node 
= GetChildren().GetFirst(); 
 999          node
; node 
= node
->GetNext()) 
1001         wxWindow 
*child 
= node
->GetData(); 
1002         if ( child 
== m_scrollbarVert 
|| child 
== m_scrollbarHorz 
) 
1005         // VS: Scrolling children has non-trivial semantics. If rect=NULL then 
1006         //     it is easy: we scroll all children. Otherwise it gets 
1008         //       1. if scrolling in one direction only, scroll only 
1009         //          those children that intersect shaft defined by the rectangle 
1010         //          and scrolling direction 
1011         //       2. if scrolling in both axes, scroll all children 
1013         if ( rect 
&& (dx 
* dy 
== 0 /* moving in only one of x, y axis */) ) 
1015             wxRect childRect 
= child
->GetRect(); 
1016             if ( dx 
== 0 && (childRect
.GetLeft() <= rect
->GetRight() || 
1017                              childRect
.GetRight() >= rect
->GetLeft()) ) 
1019                 child
->Move(child
->GetPosition() + offset
); 
1021             else if ( dy 
== 0 && (childRect
.GetTop() <= rect
->GetBottom() || 
1022                                   childRect
.GetBottom() >= rect
->GetTop()) ) 
1024                 child
->Move(child
->GetPosition() + offset
); 
1029             child
->Move(child
->GetPosition() + offset
); 
1032 #endif // wxX11/!wxX11 
1035 wxRect 
wxWindow::ScrollNoRefresh(int dx
, int dy
, const wxRect 
*rectTotal
) 
1037     wxASSERT_MSG( !dx 
|| !dy
, _T("can't be used for diag scrolling") ); 
1039     // the rect to refresh (which we will calculate) 
1048     // calculate the part of the window which we can just redraw in the new 
1050     wxSize sizeTotal 
= rectTotal 
? rectTotal
->GetSize() : GetClientSize(); 
1052     wxLogTrace(_T("scroll"), _T("rect is %dx%d, scroll by %d, %d"), 
1053                sizeTotal
.x
, sizeTotal
.y
, dx
, dy
); 
1055     // the initial and end point of the region we move in client coords 
1056     wxPoint ptSource
, ptDest
; 
1059         ptSource 
= rectTotal
->GetPosition(); 
1060         ptDest 
= rectTotal
->GetPosition(); 
1063     // the size of this region 
1065     size
.x 
= sizeTotal
.x 
- abs(dx
); 
1066     size
.y 
= sizeTotal
.y 
- abs(dy
); 
1067     if ( size
.x 
<= 0 || size
.y 
<= 0 ) 
1069         // just redraw everything as nothing of the displayed image will stay 
1070         wxLogTrace(_T("scroll"), _T("refreshing everything")); 
1072         rect 
= rectTotal 
? *rectTotal 
: wxRect(0, 0, sizeTotal
.x
, sizeTotal
.y
); 
1074     else // move the part which doesn't change to the new location 
1076         // note that when we scroll the canvas in some direction we move the 
1077         // block which doesn't need to be refreshed in the opposite direction 
1081             // scroll to the right, move to the left 
1086             // scroll to the left, move to the right 
1092             // scroll down, move up 
1097             // scroll up, move down 
1102         // we need to hide the caret before moving or it will erase itself at 
1103         // the wrong (old) location 
1104         wxCaret 
*caret 
= GetCaret(); 
1107 #endif // wxUSE_CARET 
1110         wxClientDC 
dc(this); 
1111         wxBitmap 
bmp(size
.x
, size
.y
); 
1113         dcMem
.SelectObject(bmp
); 
1115         dcMem
.Blit(wxPoint(), size
, &dc
, ptSource
 
1116 #if defined(__WXGTK__) && !defined(wxHAS_WORKING_GTK_DC_BLIT) 
1117                 + GetClientAreaOrigin() 
1118 #endif // broken wxGTK wxDC::Blit 
1120         dc
.Blit(ptDest
, size
, &dcMem
, wxPoint()); 
1122         wxLogTrace(_T("scroll"), 
1123                    _T("Blit: (%d, %d) of size %dx%d -> (%d, %d)"), 
1124                    ptSource
.x
, ptSource
.y
, 
1126                    ptDest
.x
, ptDest
.y
); 
1128         // and now repaint the uncovered area 
1130         // FIXME: We repaint the intersection of these rectangles twice - is 
1131         //        it bad? I don't think so as it is rare to scroll the window 
1132         //        diagonally anyhow and so adding extra logic to compute 
1133         //        rectangle intersection is probably not worth the effort 
1135         rect
.x 
= ptSource
.x
; 
1136         rect
.y 
= ptSource
.y
; 
1142                 // refresh the area along the right border 
1143                 rect
.x 
+= size
.x 
+ dx
; 
1148                 // refresh the area along the left border 
1152             rect
.height 
= sizeTotal
.y
; 
1154             wxLogTrace(_T("scroll"), _T("refreshing (%d, %d)-(%d, %d)"), 
1156                        rect
.GetRight() + 1, rect
.GetBottom() + 1); 
1163                 // refresh the area along the bottom border 
1164                 rect
.y 
+= size
.y 
+ dy
; 
1169                 // refresh the area along the top border 
1173             rect
.width 
= sizeTotal
.x
; 
1175             wxLogTrace(_T("scroll"), _T("refreshing (%d, %d)-(%d, %d)"), 
1177                        rect
.GetRight() + 1, rect
.GetBottom() + 1); 
1183 #endif // wxUSE_CARET 
1189 // ---------------------------------------------------------------------------- 
1190 // accelerators and menu hot keys 
1191 // ---------------------------------------------------------------------------- 
1194     // the last window over which Alt was pressed (used by OnKeyUp) 
1195     wxWindow 
*wxWindow::ms_winLastAltPress 
= NULL
; 
1196 #endif // wxUSE_MENUS 
1198 #if wxUSE_ACCEL || wxUSE_MENUS 
1200 void wxWindow::OnKeyDown(wxKeyEvent
& event
) 
1203     int key 
= event
.GetKeyCode(); 
1204     if ( !event
.ControlDown() && (key 
== WXK_MENU 
|| key 
== WXK_F10
) ) 
1206         ms_winLastAltPress 
= this; 
1208         // it can't be an accel anyhow 
1212     ms_winLastAltPress 
= NULL
; 
1213 #endif // wxUSE_MENUS 
1216     for ( wxWindow 
*win 
= this; win
; win 
= win
->GetParent() ) 
1218         int command 
= win
->GetAcceleratorTable()->GetCommand(event
); 
1219         if ( command 
!= -1 ) 
1221             wxCommandEvent 
eventCmd(wxEVT_COMMAND_MENU_SELECTED
, command
); 
1222             if ( win
->GetEventHandler()->ProcessEvent(eventCmd
) ) 
1224                 // skip "event.Skip()" below 
1229         if ( win
->IsTopLevel() ) 
1231             // try the frame menu bar 
1233             wxFrame 
*frame 
= wxDynamicCast(win
, wxFrame
); 
1236                 wxMenuBar 
*menubar 
= frame
->GetMenuBar(); 
1237                 if ( menubar 
&& menubar
->ProcessAccelEvent(event
) ) 
1239                     // skip "event.Skip()" below 
1243 #endif // wxUSE_MENUS 
1245             // if it wasn't in a menu, try to find a button 
1246             if ( command 
!= -1 ) 
1248                 wxWindow
* child 
= win
->FindWindow(command
); 
1249                 if ( child 
&& wxDynamicCast(child
, wxButton
) ) 
1251                     wxCommandEvent 
eventCmd(wxEVT_COMMAND_BUTTON_CLICKED
, command
); 
1252                     eventCmd
.SetEventObject(child
); 
1253                     if ( child
->GetEventHandler()->ProcessEvent(eventCmd
) ) 
1255                         // skip "event.Skip()" below 
1261             // don't propagate accels from the child frame to the parent one 
1265 #endif // wxUSE_ACCEL 
1270 #endif // wxUSE_ACCEL 
1274 wxMenuBar 
*wxWindow::GetParentFrameMenuBar() const 
1276     for ( const wxWindow 
*win 
= this; win
; win 
= win
->GetParent() ) 
1278         if ( win
->IsTopLevel() ) 
1280             wxFrame 
*frame 
= wxDynamicCast(win
, wxFrame
); 
1283                 return frame
->GetMenuBar(); 
1286             // don't look further - we don't want to return the menubar of the 
1295 void wxWindow::OnChar(wxKeyEvent
& event
) 
1297     if ( event
.AltDown() && !event
.ControlDown() ) 
1299         int key 
= event
.GetKeyCode(); 
1301         wxMenuBar 
*menubar 
= GetParentFrameMenuBar(); 
1304             int item 
= menubar
->FindNextItemForAccel(-1, key
); 
1307                 menubar
->PopupMenu((size_t)item
); 
1309                 // skip "event.Skip()" below 
1318 void wxWindow::OnKeyUp(wxKeyEvent
& event
) 
1320     int key 
= event
.GetKeyCode(); 
1321     if ( !event
.HasModifiers() && (key 
== WXK_MENU 
|| key 
== WXK_F10
) ) 
1323         // only process Alt release specially if there were no other key 
1324         // presses since Alt had been pressed and if both events happened in 
1326         if ( ms_winLastAltPress 
== this ) 
1328             wxMenuBar 
*menubar 
= GetParentFrameMenuBar(); 
1329             if ( menubar 
&& this != menubar 
) 
1331                 menubar
->SelectMenu(0); 
1340     // in any case reset it 
1341     ms_winLastAltPress 
= NULL
; 
1344 #endif // wxUSE_MENUS 
1346 // ---------------------------------------------------------------------------- 
1347 // MSW-specific section 
1348 // ---------------------------------------------------------------------------- 
1352 #include "wx/msw/private.h" 
1354 WXLRESULT 
wxWindow::MSWWindowProc(WXUINT message
, WXWPARAM wParam
, WXLPARAM lParam
) 
1356     if ( message 
== WM_NCHITTEST 
) 
1358         // the windows which contain the other windows should let the mouse 
1359         // events through, otherwise a window inside a static box would 
1360         // never get any events at all 
1361         if ( IsStaticBox() ) 
1363             return HTTRANSPARENT
; 
1367     return wxWindowNative::MSWWindowProc(message
, wParam
, lParam
);