Added a examples of virtual size use for setting scrollbars

both 'manually' and via sizer layout to scroll sample.
Tweaked it for various 2.4 idioms that have arisen since
it was written.

Replaced GenericScrolledWin's DoSetVirtualSize, it really is
needed for everything to work for both the user and lib.
Don't call it from default scrolledwindow OnSize handlers
unless AutoLayout is enabled though, and use the larger of
best and client size.  Hopefully this will fix any earlier
troubles this caused with M.

Purged (many) stray tabs &co from sizer.cpp

Changed DoGetBestSize to return wxDefaultSize when no useful
best size can be determined.  If GetBestSize is intended to
return the minimum undistorted size a window can take, we
must be able to discriminate between valid and 'best guess'
sizes, else the best guess windows can only grow.


git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/branches/WX_2_4_BRANCH@17776 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Ron Lee
2002-11-09 13:29:26 +00:00
parent 8b1632ebe7
commit 9064852f8e
8 changed files with 376 additions and 186 deletions

View File

@@ -69,6 +69,8 @@ public:
// lay out the window and its children
virtual bool Layout();
virtual void DoSetVirtualSize(int x, int y);
protected:
// this is needed for wxEVT_PAINT processing hack described in
// wxScrollHelperEvtHandler::ProcessEvent()

View File

@@ -299,6 +299,9 @@ public:
// set window size to wrap around its children
virtual void Fit();
// set virtual size to satisfy children
virtual void FitInside();
// set min/max size of the window
virtual void SetSizeHints( int minW, int minH,
int maxW = -1, int maxH = -1,
@@ -342,6 +345,17 @@ public:
virtual void DoSetVirtualSize( int x, int y );
virtual wxSize DoGetVirtualSize() const; // { return m_virtualSize; }
// Return the largest of ClientSize and BestSize (as determined
// by a sizer, interior children, or other means)
virtual wxSize GetBestVirtualSize() const
{
wxSize client( GetClientSize() );
wxSize best( GetBestSize() );
return wxSize( wxMax( client.x, best.x ), wxMax( client.y, best.y ) );
}
// window state
// ------------

View File

@@ -4,6 +4,7 @@
* Author: Robert Roebling
*
* Copyright: (C) 1998, Robert Roebling
* 2002, Ron Lee
*
*/
@@ -51,6 +52,30 @@ public:
DECLARE_EVENT_TABLE()
};
// ----------------------------------------------------------------------------
// Autoscrolling example.
// ----------------------------------------------------------------------------
// this class uses the 'virtual' size attribute along with an internal
// sizer to automatically set up scrollbars as needed
class MyAutoScrollWindow : public wxScrolledWindow
{
private:
wxButton *m_button;
public:
MyAutoScrollWindow( wxWindow *parent );
void OnResizeClick( wxCommandEvent &WXUNUSED( event ) );
DECLARE_EVENT_TABLE()
};
// ----------------------------------------------------------------------------
// MyScrolledWindow classes: examples of wxScrolledWindow usage
// ----------------------------------------------------------------------------
@@ -59,17 +84,15 @@ public:
class MyScrolledWindowBase : public wxScrolledWindow
{
public:
MyScrolledWindowBase(wxWindow *parent) : wxScrolledWindow(parent)
MyScrolledWindowBase(wxWindow *parent)
: wxScrolledWindow(parent)
, m_nLines( 100 )
{
m_nLines = 100;
InitScrollbars();
wxClientDC dc(this);
dc.GetTextExtent(_T("Line 17"), NULL, &m_hLine);
}
protected:
// set the scrollbar params
void InitScrollbars();
// the height of one line on screen
wxCoord m_hLine;
@@ -78,24 +101,40 @@ protected:
};
// this class does "stupid" redrawing - it redraws everything each time
// and sets the scrollbar extent directly.
class MyScrolledWindowDumb : public MyScrolledWindowBase
{
public:
MyScrolledWindowDumb(wxWindow *parent) : MyScrolledWindowBase(parent) { }
MyScrolledWindowDumb(wxWindow *parent) : MyScrolledWindowBase(parent)
{
// no horz scrolling
SetScrollbars(0, m_hLine, 0, m_nLines + 1, 0, 0, TRUE /* no refresh */);
}
virtual void OnDraw(wxDC& dc);
};
// this class does "smart" redrawing - only redraws the lines which must be
// redrawn
// redrawn and sets the scroll rate and virtual size to affect the
// scrollbars.
//
// Note that this class should produce identical results to the one above.
class MyScrolledWindowSmart : public MyScrolledWindowBase
{
public:
MyScrolledWindowSmart(wxWindow *parent) : MyScrolledWindowBase(parent) { }
MyScrolledWindowSmart(wxWindow *parent) : MyScrolledWindowBase(parent)
{
// no horz scrolling
SetScrollRate( 0, m_hLine );
SetVirtualSize( -1, ( m_nLines + 1 ) * m_hLine );
}
virtual void OnDraw(wxDC& dc);
};
// ----------------------------------------------------------------------------
// MyFrame
// ----------------------------------------------------------------------------
@@ -131,13 +170,13 @@ IMPLEMENT_APP(MyApp)
// ids
#define ID_ADDBUTTON 1
#define ID_DELBUTTON 2
#define ID_MOVEBUTTON 3
#define ID_SCROLLWIN 4
#define ID_QUERYPOS 5
const long ID_ADDBUTTON = wxNewId();
const long ID_DELBUTTON = wxNewId();
const long ID_MOVEBUTTON = wxNewId();
const long ID_SCROLLWIN = wxNewId();
const long ID_QUERYPOS = wxNewId();
#define ID_NEWBUTTON 10
const long ID_NEWBUTTON = wxNewId();
// MyCanvas
@@ -145,7 +184,7 @@ IMPLEMENT_DYNAMIC_CLASS(MyCanvas, wxScrolledWindow)
BEGIN_EVENT_TABLE(MyCanvas, wxScrolledWindow)
EVT_PAINT( MyCanvas::OnPaint)
EVT_MOUSE_EVENTS( MyCanvas::OnMouseDown)
EVT_MOUSE_EVENTS( MyCanvas::OnMouseDown)
EVT_BUTTON( ID_QUERYPOS, MyCanvas::OnQueryPosition)
EVT_BUTTON( ID_ADDBUTTON, MyCanvas::OnAddButton)
EVT_BUTTON( ID_DELBUTTON, MyCanvas::OnDeleteButton)
@@ -155,12 +194,15 @@ END_EVENT_TABLE()
MyCanvas::MyCanvas( wxWindow *parent, wxWindowID id,
const wxPoint &pos, const wxSize &size )
: wxScrolledWindow( parent, id, pos, size, wxSUNKEN_BORDER | wxTAB_TRAVERSAL, "test canvas" )
: wxScrolledWindow( parent, id, pos, size, wxSUNKEN_BORDER | wxTAB_TRAVERSAL, _T("test canvas") )
{
(void) new wxButton( this, ID_ADDBUTTON, "add button", wxPoint(10,10) );
(void) new wxButton( this, ID_DELBUTTON, "del button", wxPoint(10,40) );
(void) new wxButton( this, ID_MOVEBUTTON, "move button", wxPoint(150,10) );
(void) new wxButton( this, ID_SCROLLWIN, "scroll win", wxPoint(250,10) );
SetScrollRate( 10, 10 );
SetVirtualSize( 500, 1000 );
(void) new wxButton( this, ID_ADDBUTTON, _T("add button"), wxPoint(10,10) );
(void) new wxButton( this, ID_DELBUTTON, _T("del button"), wxPoint(10,40) );
(void) new wxButton( this, ID_MOVEBUTTON, _T("move button"), wxPoint(150,10) );
(void) new wxButton( this, ID_SCROLLWIN, _T("scroll win"), wxPoint(250,10) );
#if 0
@@ -253,9 +295,9 @@ void MyCanvas::OnPaint( wxPaintEvent &WXUNUSED(event) )
wxPaintDC dc( this );
PrepareDC( dc );
dc.DrawText( "Press mouse button to test calculations!", 160, 50 );
dc.DrawText( _T("Press mouse button to test calculations!"), 160, 50 );
dc.DrawText( "Some text", 140, 140 );
dc.DrawText( _T("Some text"), 140, 140 );
dc.DrawRectangle( 100, 160, 200, 200 );
}
@@ -305,12 +347,87 @@ void MyCanvas::OnScrollWin( wxCommandEvent &WXUNUSED(event) )
Scroll( -1, y+2 );
}
// MyAutoScrollWindow
const long ID_RESIZEBUTTON = wxNewId();
const wxSize SMALL_BUTTON( 100, 50 );
const wxSize LARGE_BUTTON( 300, 100 );
BEGIN_EVENT_TABLE( MyAutoScrollWindow, wxScrolledWindow)
EVT_BUTTON( ID_RESIZEBUTTON, MyAutoScrollWindow::OnResizeClick)
END_EVENT_TABLE()
MyAutoScrollWindow::MyAutoScrollWindow( wxWindow *parent )
: wxScrolledWindow( parent )
{
SetBackgroundColour( wxT("GREEN") );
// Set the rate we'd like for scrolling.
SetScrollRate( 5, 5 );
// Populate a sizer with a 'resizing' button and some
// other static decoration
wxFlexGridSizer *innersizer = new wxFlexGridSizer( 2, 2 );
m_button = new wxButton( this,
ID_RESIZEBUTTON,
_T("Press me"),
wxDefaultPosition,
SMALL_BUTTON );
// We need to do this here, because wxADJUST_MINSIZE below
// will cause the initial size to be ignored for Best/Min size.
// It would be nice to fix the sizers to handle this a little
// more cleanly.
m_button->SetSizeHints( SMALL_BUTTON.GetWidth(), SMALL_BUTTON.GetHeight() );
innersizer->Add( m_button,
0,
wxALIGN_CENTER | wxALL | wxADJUST_MINSIZE,
20 );
innersizer->Add( new wxStaticText( this, -1, _T("This is just") ),
0,
wxALIGN_CENTER );
innersizer->Add( new wxStaticText( this, -1, _T("some decoration") ),
0,
wxALIGN_CENTER );
innersizer->Add( new wxStaticText( this, -1, _T("for you to scroll...") ),
0,
wxALIGN_CENTER );
// Then use the sizer to set the scrolled region size.
SetSizer( innersizer );
}
void MyAutoScrollWindow::OnResizeClick( wxCommandEvent &WXUNUSED( event ) )
{
// Arbitrarily resize the button to change the minimum size of
// the (scrolled) sizer.
if( m_button->GetSize() == SMALL_BUTTON )
m_button->SetSizeHints( LARGE_BUTTON.GetWidth(), LARGE_BUTTON.GetHeight() );
else
m_button->SetSizeHints( SMALL_BUTTON.GetWidth(), SMALL_BUTTON.GetHeight() );
// Force update layout and scrollbars, since nothing we do here
// necessarily generates a size event which would do it for us.
FitInside();
}
// MyFrame
const int ID_QUIT = 108;
const int ID_ABOUT = 109;
const int ID_DELETE_ALL = 110;
const int ID_INSERT_NEW = 111;
const long ID_QUIT = wxNewId();
const long ID_ABOUT = wxNewId();
const long ID_DELETE_ALL = wxNewId();
const long ID_INSERT_NEW = wxNewId();
IMPLEMENT_DYNAMIC_CLASS( MyFrame, wxFrame )
@@ -322,17 +439,17 @@ BEGIN_EVENT_TABLE(MyFrame,wxFrame)
END_EVENT_TABLE()
MyFrame::MyFrame()
: wxFrame( (wxFrame *)NULL, -1, "wxScrolledWindow sample",
: wxFrame( (wxFrame *)NULL, -1, _T("wxScrolledWindow sample"),
wxPoint(20,20), wxSize(470,500) )
{
wxMenu *file_menu = new wxMenu();
file_menu->Append( ID_DELETE_ALL, "Delete all");
file_menu->Append( ID_INSERT_NEW, "Insert new");
file_menu->Append( ID_ABOUT, "&About..");
file_menu->Append( ID_QUIT, "E&xit\tAlt-X");
file_menu->Append( ID_DELETE_ALL, _T("Delete all"));
file_menu->Append( ID_INSERT_NEW, _T("Insert new"));
file_menu->Append( ID_ABOUT, _T("&About.."));
file_menu->Append( ID_QUIT, _T("E&xit\tAlt-X"));
wxMenuBar *menu_bar = new wxMenuBar();
menu_bar->Append(file_menu, "&File");
menu_bar->Append(file_menu, _T("&File"));
SetMenuBar( menu_bar );
@@ -340,19 +457,24 @@ MyFrame::MyFrame()
int widths[] = { -1, 100 };
SetStatusWidths( 2, widths );
m_canvas = new MyCanvas( this, -1, wxPoint(0,0), wxSize(100,100) );
m_canvas->SetScrollbars( 10, 10, 50, 100 );
wxBoxSizer *topsizer = new wxBoxSizer( wxVERTICAL );
// Setting an explicit size here is superfluous, it will be overridden
// by the sizer in any case.
m_canvas = new MyCanvas( this, -1, wxPoint(0,0), wxSize(100,100) );
// This is done with ScrollRate/VirtualSize in MyCanvas ctor now,
// both should produce identical results.
//m_canvas->SetScrollbars( 10, 10, 50, 100 );
topsizer->Add( m_canvas, 1, wxEXPAND );
topsizer->Add( new MyAutoScrollWindow( this ), 1, wxEXPAND );
wxSizer *sizerBtm = new wxBoxSizer(wxHORIZONTAL);
sizerBtm->Add( new MyScrolledWindowDumb(this), 1, wxEXPAND );
sizerBtm->Add( new MyScrolledWindowSmart(this), 1, wxEXPAND );
topsizer->Add( sizerBtm, 1, wxEXPAND );
SetAutoLayout( TRUE );
SetSizer( topsizer );
}
@@ -363,7 +485,7 @@ void MyFrame::OnDeleteAll( wxCommandEvent &WXUNUSED(event) )
void MyFrame::OnInsertNew( wxCommandEvent &WXUNUSED(event) )
{
(void)new wxButton( m_canvas, -1, "Hello", wxPoint(100,100) );
(void)new wxButton( m_canvas, -1, _T("Hello"), wxPoint(100,100) );
}
void MyFrame::OnQuit( wxCommandEvent &WXUNUSED(event) )
@@ -373,9 +495,12 @@ void MyFrame::OnQuit( wxCommandEvent &WXUNUSED(event) )
void MyFrame::OnAbout( wxCommandEvent &WXUNUSED(event) )
{
(void)wxMessageBox( "wxScroll demo\n"
"Robert Roebling (c) 1998",
"About wxScroll Demo", wxICON_INFORMATION | wxOK );
(void)wxMessageBox( _T("wxScroll demo\n"
"Robert Roebling (c) 1998\n"
"Autoscrolling examples\n"
"Ron Lee (c) 2002"),
_T("About wxScroll Demo"),
wxICON_INFORMATION | wxOK );
}
//-----------------------------------------------------------------------------
@@ -394,15 +519,6 @@ bool MyApp::OnInit()
// MyScrolledWindowXXX
// ----------------------------------------------------------------------------
void MyScrolledWindowBase::InitScrollbars()
{
wxClientDC dc(this);
dc.GetTextExtent(_T("Line 17"), NULL, &m_hLine);
// no horz scrolling
SetScrollbars(0, m_hLine, 0, m_nLines + 1, 0, 0, TRUE /* no refresh */);
}
void MyScrolledWindowDumb::OnDraw(wxDC& dc)
{
// this is useful to see which lines are redrawn

View File

@@ -50,7 +50,7 @@ wxSizerItem::wxSizerItem( int width, int height, int option, int flag, int borde
m_option = option;
m_border = border;
m_flag = flag;
m_show = TRUE; // Cannot be changed
m_show = TRUE; // Cannot be changed
m_userData = userData;
// minimal size is the initial size
@@ -530,8 +530,7 @@ void wxSizer::SetDimension( int x, int y, int width, int height )
m_position.y = y;
m_size.x = width;
m_size.y = height;
CalcMin();
RecalcSizes();
Layout();
}
wxSize wxSizer::GetMinSize()
@@ -638,61 +637,68 @@ bool wxSizer::DoSetItemMinSize( int pos, int width, int height )
return TRUE;
}
void wxSizer::Show (wxWindow *window, bool show)
void wxSizer::Show(wxWindow *window, bool show)
{
wxNode *node = m_children.GetFirst();
while (node) {
while (node)
{
wxSizerItem *item = (wxSizerItem*) node->Data();
if (item->IsWindow () && item->GetWindow () == window) {
item->Show (show);
window->Show (show);
return;
}
node = node->Next();
if (item->IsWindow() && item->GetWindow() == window)
{
item->Show(show);
window->Show(show);
return;
}
node = node->Next();
}
}
void wxSizer::Show (wxSizer *sizer, bool show)
void wxSizer::Show(wxSizer *sizer, bool show)
{
wxNode *node = m_children.GetFirst();
while (node) {
while (node)
{
wxSizerItem *item = (wxSizerItem*) node->Data();
if (item->IsSizer () && item->GetSizer () == sizer) {
item->Show (show);
sizer->ShowItems (show);
return;
}
node = node->Next();
if (item->IsSizer() && item->GetSizer() == sizer)
{
item->Show(show);
sizer->ShowItems(show);
return;
}
node = node->Next();
}
}
void wxSizer::ShowItems (bool show)
{
wxNode *node = m_children.GetFirst();
while (node) {
while (node)
{
wxSizerItem *item = (wxSizerItem*) node->Data();
if (item->IsWindow ())
item->GetWindow()->Show (show);
else if (item->IsSizer ())
item->GetSizer ()->ShowItems (show);
if (item->IsWindow())
item->GetWindow()->Show (show);
else if (item->IsSizer())
item->GetSizer()->ShowItems (show);
node = node->Next();
node = node->Next();
}
}
bool wxSizer::IsShown (wxWindow *window)
{
wxNode *node = m_children.GetFirst();
while (node) {
while (node)
{
wxSizerItem *item = (wxSizerItem*) node->Data();
if (item->IsWindow () && item->GetWindow () == window) {
return item->IsShown ();
}
node = node->Next();
if (item->IsWindow() && item->GetWindow() == window)
{
return item->IsShown();
}
node = node->Next();
}
return FALSE;
@@ -701,13 +707,15 @@ bool wxSizer::IsShown (wxWindow *window)
bool wxSizer::IsShown (wxSizer *sizer)
{
wxNode *node = m_children.GetFirst();
while (node) {
while (node)
{
wxSizerItem *item = (wxSizerItem*) node->Data();
if (item->IsSizer () && item->GetSizer () == sizer) {
return item->IsShown ();
}
node = node->Next();
if (item->IsSizer() && item->GetSizer() == sizer)
{
return item->IsShown();
}
node = node->Next();
}
return FALSE;
@@ -1055,65 +1063,65 @@ void wxBoxSizer::RecalcSizes()
while (node)
{
wxSizerItem *item = (wxSizerItem*) node->Data();
if (item->IsShown ()) {
int weight = 1;
if (item->GetOption())
weight = item->GetOption();
wxSize size( item->CalcMin() );
if (m_orient == wxVERTICAL)
if (item->IsShown())
{
wxCoord height = size.y;
int weight = 1;
if (item->GetOption())
weight = item->GetOption();
wxSize size( item->CalcMin() );
if (m_orient == wxVERTICAL)
{
height = (delta * weight) + extra;
extra = 0; // only the first item will get the remainder as extra size
wxCoord height = size.y;
if (item->GetOption())
{
height = (delta * weight) + extra;
extra = 0; // only the first item will get the remainder as extra size
}
wxPoint child_pos( pt );
wxSize child_size( wxSize( size.x, height) );
if (item->GetFlag() & (wxEXPAND | wxSHAPED))
child_size.x = m_size.x;
else if (item->GetFlag() & wxALIGN_RIGHT)
child_pos.x += m_size.x - size.x;
else if (item->GetFlag() & (wxCENTER | wxALIGN_CENTER_HORIZONTAL))
// XXX wxCENTER is added for backward compatibility;
// wxALIGN_CENTER should be used in new code
child_pos.x += (m_size.x - size.x) / 2;
item->SetDimension( child_pos, child_size );
pt.y += height;
}
wxPoint child_pos( pt );
wxSize child_size( wxSize( size.x, height) );
if (item->GetFlag() & (wxEXPAND | wxSHAPED))
child_size.x = m_size.x;
else if (item->GetFlag() & wxALIGN_RIGHT)
child_pos.x += m_size.x - size.x;
else if (item->GetFlag() & (wxCENTER | wxALIGN_CENTER_HORIZONTAL))
// XXX wxCENTER is added for backward compatibility;
// wxALIGN_CENTER should be used in new code
child_pos.x += (m_size.x - size.x) / 2;
item->SetDimension( child_pos, child_size );
pt.y += height;
}
else
{
wxCoord width = size.x;
if (item->GetOption())
else
{
width = (delta * weight) + extra;
extra = 0; // only the first item will get the remainder as extra size
wxCoord width = size.x;
if (item->GetOption())
{
width = (delta * weight) + extra;
extra = 0; // only the first item will get the remainder as extra size
}
wxPoint child_pos( pt );
wxSize child_size( wxSize(width, size.y) );
if (item->GetFlag() & (wxEXPAND | wxSHAPED))
child_size.y = m_size.y;
else if (item->GetFlag() & wxALIGN_BOTTOM)
child_pos.y += m_size.y - size.y;
else if (item->GetFlag() & (wxCENTER | wxALIGN_CENTER_VERTICAL))
// XXX wxCENTER is added for backward compatibility;
// wxALIGN_CENTER should be used in new code
child_pos.y += (m_size.y - size.y) / 2;
item->SetDimension( child_pos, child_size );
pt.x += width;
}
wxPoint child_pos( pt );
wxSize child_size( wxSize(width, size.y) );
if (item->GetFlag() & (wxEXPAND | wxSHAPED))
child_size.y = m_size.y;
else if (item->GetFlag() & wxALIGN_BOTTOM)
child_pos.y += m_size.y - size.y;
else if (item->GetFlag() & (wxCENTER | wxALIGN_CENTER_VERTICAL))
// XXX wxCENTER is added for backward compatibility;
// wxALIGN_CENTER should be used in new code
child_pos.y += (m_size.y - size.y) / 2;
item->SetDimension( child_pos, child_size );
pt.x += width;
}
}
node = node->Next();
}
@@ -1136,7 +1144,7 @@ wxSize wxBoxSizer::CalcMin()
while (node)
{
wxSizerItem *item = (wxSizerItem*) node->Data();
if (item->IsShown () && item->GetOption() != 0)
if (item->IsShown() && item->GetOption() != 0)
{
int stretch = item->GetOption();
wxSize size( item->CalcMin() );
@@ -1156,43 +1164,44 @@ wxSize wxBoxSizer::CalcMin()
while (node)
{
wxSizerItem *item = (wxSizerItem*) node->Data();
if (item->IsShown ()) {
m_stretchable += item->GetOption();
wxSize size( item->CalcMin() );
if (item->GetOption() != 0)
if (item->IsShown())
{
m_stretchable += item->GetOption();
wxSize size( item->CalcMin() );
if (item->GetOption() != 0)
{
if (m_orient == wxHORIZONTAL)
size.x = stretchSize * item->GetOption();
else
size.y = stretchSize * item->GetOption();
}
if (m_orient == wxHORIZONTAL)
size.x = stretchSize * item->GetOption();
else
size.y = stretchSize * item->GetOption();
}
if (m_orient == wxHORIZONTAL)
{
m_minWidth += size.x;
m_minHeight = wxMax( m_minHeight, size.y );
}
else
{
m_minHeight += size.y;
m_minWidth = wxMax( m_minWidth, size.x );
}
if (item->GetOption() == 0)
{
if (m_orient == wxVERTICAL)
{
m_fixedHeight += size.y;
m_fixedWidth = wxMax( m_fixedWidth, size.x );
m_minWidth += size.x;
m_minHeight = wxMax( m_minHeight, size.y );
}
else
{
m_fixedWidth += size.x;
m_fixedHeight = wxMax( m_fixedHeight, size.y );
m_minHeight += size.y;
m_minWidth = wxMax( m_minWidth, size.x );
}
if (item->GetOption() == 0)
{
if (m_orient == wxVERTICAL)
{
m_fixedHeight += size.y;
m_fixedWidth = wxMax( m_fixedWidth, size.x );
}
else
{
m_fixedWidth += size.x;
m_fixedHeight = wxMax( m_fixedHeight, size.y );
}
}
}
}
node = node->Next();
}

View File

@@ -470,6 +470,15 @@ void wxWindowBase::Fit()
//else: do nothing if we have no children
}
// fits virtual size (ie. scrolled area etc.) around children
void wxWindowBase::FitInside()
{
if ( GetChildren().GetCount() > 0 )
{
SetVirtualSize( GetBestVirtualSize() );
}
}
// return the size best suited for the current window
wxSize wxWindowBase::DoGetBestSize() const
{
@@ -565,7 +574,16 @@ wxSize wxWindowBase::DoGetBestSize() const
{
// for a generic window there is no natural best size - just use the
// current one
return GetSize();
//return GetSize();
// Unfortunately, the above causes problems for code that expects
// BestSize to be the minimal unmangled size of the window. (eg.
// the window may grow, but BestSize will never suggest it could
// be smaller). Return instead something more indicative of the
// fact there is no reasonable answer to be given. Anything expecting
// the current size in that case should check for this and request
// it specifically.
return wxDefaultSize;
}
}
@@ -593,8 +611,6 @@ void wxWindowBase::SetVirtualSizeHints( int minW, int minH,
m_maxVirtualWidth = maxW;
m_minVirtualHeight = minH;
m_maxVirtualHeight = maxH;
SetVirtualSize( GetClientSize() );
}
void wxWindowBase::DoSetVirtualSize( int x, int y )

View File

@@ -340,9 +340,11 @@ void wxScrollHelper::SetScrollbars(int pixelsPerUnitX,
m_xScrollPosition = xPos;
m_yScrollPosition = yPos;
m_targetWindow->SetVirtualSizeHints( noUnitsX * pixelsPerUnitX, noUnitsY * pixelsPerUnitY );
// For better backward compatibility we set persisting limits
// here not just the size. It makes SetScrollbars 'sticky'
// emulating the old non-autoscroll behaviour.
AdjustScrollbars();
m_targetWindow->SetVirtualSizeHints( noUnitsX * pixelsPerUnitX, noUnitsY * pixelsPerUnitY );
if (do_refresh && !noRefresh)
m_targetWindow->Refresh(TRUE, GetRect());
@@ -867,17 +869,19 @@ void wxScrollHelper::DoCalcUnscrolledPosition(int x, int y, int *xx, int *yy) co
// Default OnSize resets scrollbars, if any
void wxScrollHelper::HandleOnSize(wxSizeEvent& WXUNUSED(event))
{
if ( m_targetWindow != m_win )
m_targetWindow->SetVirtualSize( m_targetWindow->GetClientSize() );
if( m_win->GetAutoLayout() )
{
if ( m_targetWindow != m_win )
m_targetWindow->FitInside();
m_win->SetVirtualSize( m_win->GetClientSize() );
AdjustScrollbars();
m_win->FitInside();
#if wxUSE_CONSTRAINTS
if (m_win->GetAutoLayout())
m_win->Layout();
#endif
}
else
AdjustScrollbars();
}
// This calls OnDraw, having adjusted the origin according to the current
@@ -1171,6 +1175,17 @@ bool wxGenericScrolledWindow::Layout()
return wxPanel::Layout();
}
void wxGenericScrolledWindow::DoSetVirtualSize(int x, int y)
{
wxPanel::DoSetVirtualSize( x, y );
AdjustScrollbars();
#if wxUSE_CONSTRAINTS
if (GetAutoLayout())
Layout();
#endif
}
void wxGenericScrolledWindow::OnPaint(wxPaintEvent& event)
{
// the user code didn't really draw the window if we got here, so set this

View File

@@ -349,6 +349,10 @@ void wxScrolledWindow::SetScrollbars( int pixelsPerUnitX, int pixelsPerUnitY,
m_hAdjust->value = m_xScrollPosition = xPos;
m_vAdjust->value = m_yScrollPosition = yPos;
// For better backward compatibility we set persisting limits
// here not just the size. It makes SetScrollbars 'sticky'
// emulating the old non-autoscroll behaviour.
m_targetWindow->SetVirtualSizeHints( noUnitsX * pixelsPerUnitX, noUnitsY * pixelsPerUnitY );
if (!noRefresh)
@@ -823,10 +827,15 @@ bool wxScrolledWindow::Layout()
// Default OnSize resets scrollbars, if any
void wxScrolledWindow::OnSize(wxSizeEvent& WXUNUSED(event))
{
if( m_targetWindow != this )
m_targetWindow->SetVirtualSize( m_targetWindow->GetClientSize() );
if( GetAutoLayout() )
{
if( m_targetWindow != this )
m_targetWindow->FitInside();
SetVirtualSize( GetClientSize() );
FitInside();
}
else
AdjustScrollbars();
}
// This calls OnDraw, having adjusted the origin according to the current

View File

@@ -349,6 +349,10 @@ void wxScrolledWindow::SetScrollbars( int pixelsPerUnitX, int pixelsPerUnitY,
m_hAdjust->value = m_xScrollPosition = xPos;
m_vAdjust->value = m_yScrollPosition = yPos;
// For better backward compatibility we set persisting limits
// here not just the size. It makes SetScrollbars 'sticky'
// emulating the old non-autoscroll behaviour.
m_targetWindow->SetVirtualSizeHints( noUnitsX * pixelsPerUnitX, noUnitsY * pixelsPerUnitY );
if (!noRefresh)
@@ -823,10 +827,15 @@ bool wxScrolledWindow::Layout()
// Default OnSize resets scrollbars, if any
void wxScrolledWindow::OnSize(wxSizeEvent& WXUNUSED(event))
{
if( m_targetWindow != this )
m_targetWindow->SetVirtualSize( m_targetWindow->GetClientSize() );
if( GetAutoLayout() )
{
if( m_targetWindow != this )
m_targetWindow->FitInside();
SetVirtualSize( GetClientSize() );
FitInside();
}
else
AdjustScrollbars();
}
// This calls OnDraw, having adjusted the origin according to the current