added new focus behaviour (like MSW) and toolbar fixes

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@9450 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Stefan Csomor
2001-02-28 20:48:20 +00:00
parent 10e4dbef5d
commit 7810c95b5d
10 changed files with 293 additions and 44 deletions

View File

@@ -125,6 +125,8 @@ protected:
#if wxUSE_STATUSBAR #if wxUSE_STATUSBAR
static bool m_useNativeStatusBar; static bool m_useNativeStatusBar;
#endif // wxUSE_STATUSBAR #endif // wxUSE_STATUSBAR
// the last focused child: we restore focus to it on activation
wxWindow *m_winLastFocused;
private: private:
DECLARE_EVENT_TABLE() DECLARE_EVENT_TABLE()

View File

@@ -177,6 +177,7 @@ public:
// event handlers // event handlers
// -------------- // --------------
void OnSetFocus(wxFocusEvent& event) ;
void OnEraseBackground(wxEraseEvent& event); void OnEraseBackground(wxEraseEvent& event);
void OnIdle(wxIdleEvent& event); void OnIdle(wxIdleEvent& event);
void MacOnScroll(wxScrollEvent&event ) ; void MacOnScroll(wxScrollEvent&event ) ;

View File

@@ -761,10 +761,12 @@ void wxControl::OnMouseEvent( wxMouseEvent &event )
controlpart = FindControl( localwhere , window , &control ) ; controlpart = FindControl( localwhere , window , &control ) ;
{ {
/*
if ( AcceptsFocus() && FindFocus() != this ) if ( AcceptsFocus() && FindFocus() != this )
{ {
SetFocus() ; SetFocus() ;
} }
*/
if ( control && UMAIsControlActive( control ) ) if ( control && UMAIsControlActive( control ) )
{ {
{ {

View File

@@ -100,6 +100,7 @@ bool wxFrame::Create(wxWindow *parent,
m_frameToolBar = NULL ; m_frameToolBar = NULL ;
#endif #endif
m_frameStatusBar = NULL; m_frameStatusBar = NULL;
m_winLastFocused = NULL ;
SetBackgroundColour(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_APPWORKSPACE)); SetBackgroundColour(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_APPWORKSPACE));
@@ -259,10 +260,21 @@ void wxFrame::OnActivate(wxActivateEvent& event)
{ {
if ( !event.GetActive() ) if ( !event.GetActive() )
{ {
event.Skip(); // remember the last focused child
return; m_winLastFocused = FindFocus();
while ( m_winLastFocused )
{
if ( GetChildren().Find(m_winLastFocused) )
break;
m_winLastFocused = m_winLastFocused->GetParent();
} }
event.Skip();
}
else
{
/*
for ( wxWindowList::Node *node = GetChildren().GetFirst(); for ( wxWindowList::Node *node = GetChildren().GetFirst();
node; node;
node = node->GetNext() ) node = node->GetNext() )
@@ -273,7 +285,7 @@ void wxFrame::OnActivate(wxActivateEvent& event)
// restore focus // restore focus
wxWindow *child = node->GetData(); wxWindow *child = node->GetData();
if ( !child->IsTopLevel() if ( !child->IsTopLevel() && child->AcceptsFocus()
#if wxUSE_TOOLBAR #if wxUSE_TOOLBAR
&& !wxDynamicCast(child, wxToolBar) && !wxDynamicCast(child, wxToolBar)
#endif // wxUSE_TOOLBAR #endif // wxUSE_TOOLBAR
@@ -286,12 +298,15 @@ void wxFrame::OnActivate(wxActivateEvent& event)
break; break;
} }
} }
*/
wxSetFocusToChild(this, &m_winLastFocused);
if ( m_frameMenuBar != NULL ) if ( m_frameMenuBar != NULL )
{ {
m_frameMenuBar->MacInstallMenuBar() ; m_frameMenuBar->MacInstallMenuBar() ;
} }
} }
}
void wxFrame::DoGetClientSize(int *x, int *y) const void wxFrame::DoGetClientSize(int *x, int *y) const
{ {

View File

@@ -111,7 +111,6 @@ void wxToolBar::Init()
bool wxToolBar::Create(wxWindow *parent, wxWindowID id, const wxPoint& pos, const wxSize& size, bool wxToolBar::Create(wxWindow *parent, wxWindowID id, const wxPoint& pos, const wxSize& size,
long style, const wxString& name) long style, const wxString& name)
{ {
m_maxWidth = m_maxHeight = 0;
m_defaultWidth = defwidth; m_defaultWidth = defwidth;
m_defaultHeight = defheight; m_defaultHeight = defheight;
@@ -167,7 +166,8 @@ bool wxToolBar::Create(wxWindow *parent, wxWindowID id, const wxPoint& pos, cons
wxToolBar::~wxToolBar() wxToolBar::~wxToolBar()
{ {
// TODO // we must refresh the frame size when the toolbar is deleted but the frame
// is not - otherwise toolbar leaves a hole in the place it used to occupy
} }
PicHandle MakePict(GWorldPtr wp, GWorldPtr mask ) ; PicHandle MakePict(GWorldPtr wp, GWorldPtr mask ) ;
@@ -267,7 +267,7 @@ bool wxToolBar::Realize()
WindowRef window ; WindowRef window ;
wxWindow *win ; wxWindow *win ;
MacGetPortParams( &localOrigin , &clipRect , &window , &win ) ; GetParent()->MacGetPortParams( &localOrigin , &clipRect , &window , &win ) ;
Rect toolbarrect = { m_y + localOrigin.v , m_x + localOrigin.h , Rect toolbarrect = { m_y + localOrigin.v , m_x + localOrigin.h ,
m_y + m_height + localOrigin.v , m_x + m_width + localOrigin.h} ; m_y + m_height + localOrigin.v , m_x + m_width + localOrigin.h} ;
@@ -282,6 +282,7 @@ bool wxToolBar::Realize()
wxSize toolSize = GetToolSize() ; wxSize toolSize = GetToolSize() ;
int tw, th; int tw, th;
GetSize(& tw, & th); GetSize(& tw, & th);
m_maxWidth = m_maxHeight = 0 ;
while (node) while (node)
{ {
wxToolBarTool *tool = (wxToolBarTool *)node->Data(); wxToolBarTool *tool = (wxToolBarTool *)node->Data();
@@ -356,23 +357,36 @@ bool wxToolBar::Realize()
m_macToolHandles.Add( NULL ) ; m_macToolHandles.Add( NULL ) ;
x += (int)toolSize.x / 4; x += (int)toolSize.x / 4;
} }
if ( toolbarrect.left + x + kwxMacToolBarLeftMargin > m_maxWidth) if ( toolbarrect.left + x + kwxMacToolBarLeftMargin - m_x - localOrigin.h > m_maxWidth)
m_maxWidth = toolbarrect.left + x + kwxMacToolBarLeftMargin; m_maxWidth = toolbarrect.left + x + kwxMacToolBarLeftMargin - m_x - localOrigin.h;
if (toolbarrect.top + kwxMacToolBarTopMargin + toolSize.y > m_maxHeight) if (toolbarrect.top + kwxMacToolBarTopMargin - m_y - localOrigin.v > m_maxHeight)
m_maxHeight = toolbarrect.top + kwxMacToolBarTopMargin ; m_maxHeight = toolbarrect.top + kwxMacToolBarTopMargin - m_y - localOrigin.v ;
node = node->Next(); node = node->Next();
} }
if ( GetWindowStyleFlag() & wxTB_HORIZONTAL ) if ( GetWindowStyleFlag() & wxTB_HORIZONTAL )
{ {
m_maxWidth = tw ; // +=toolSize.x; if ( m_maxRows == 0 )
{
// if not set yet, only one row
SetRows(1);
}
m_maxWidth = clipRect.right - m_x ;
//m_maxWidth = tw ; // +=toolSize.x;
//m_maxWidth += m_xMargin ;
m_maxHeight += toolSize.y; m_maxHeight += toolSize.y;
m_maxHeight += m_yMargin; m_maxHeight += m_yMargin;
} }
else else
{ {
m_maxHeight = th ;// += toolSize.y; if ( noButtons > 0 && m_maxRows == 0 )
{
// if not set yet, have one column
SetRows(noButtons);
}
m_maxHeight = clipRect.bottom - m_y ;
//m_maxHeight += m_yMargin ;
m_maxWidth += toolSize.x; m_maxWidth += toolSize.x;
m_maxWidth += m_xMargin; m_maxWidth += m_xMargin;
} }
@@ -506,7 +520,7 @@ void wxToolBar::OnPaint(wxPaintEvent& event)
WindowRef window ; WindowRef window ;
wxWindow *win ; wxWindow *win ;
MacGetPortParams( &localOrigin , &clipRect , &window , &win ) ; GetParent()->MacGetPortParams( &localOrigin , &clipRect , &window , &win ) ;
if ( window && win ) if ( window && win )
{ {
wxMacDrawingHelper help( win ) ; wxMacDrawingHelper help( win ) ;
@@ -532,8 +546,20 @@ void wxToolBar::OnPaint(wxPaintEvent& event)
parent = parent->GetParent() ; parent = parent->GetParent() ;
} }
int w = m_width ;
int h = m_height ;
if ( GetWindowStyleFlag() & wxTB_HORIZONTAL )
{
w = clipRect.right - m_x ;
}
else
{
h = clipRect.bottom - m_y ;
}
Rect toolbarrect = { m_y + localOrigin.v , m_x + localOrigin.h , Rect toolbarrect = { m_y + localOrigin.v , m_x + localOrigin.h ,
m_y + localOrigin.v + m_height , m_x + localOrigin.h + m_width } ; m_y + localOrigin.v + h , m_x + localOrigin.h + w } ;
UMADrawThemePlacard( &toolbarrect , IsEnabled() ? kThemeStateActive : kThemeStateInactive) ; UMADrawThemePlacard( &toolbarrect , IsEnabled() ? kThemeStateActive : kThemeStateInactive) ;
{ {

View File

@@ -65,7 +65,7 @@ BEGIN_EVENT_TABLE(wxWindow, wxEvtHandler)
EVT_SYS_COLOUR_CHANGED(wxWindow::OnSysColourChanged) EVT_SYS_COLOUR_CHANGED(wxWindow::OnSysColourChanged)
EVT_INIT_DIALOG(wxWindow::OnInitDialog) EVT_INIT_DIALOG(wxWindow::OnInitDialog)
EVT_IDLE(wxWindow::OnIdle) EVT_IDLE(wxWindow::OnIdle)
// EVT_SCROLL(wxWindow::OnScroll) EVT_SET_FOCUS(wxWindow::OnSetFocus)
END_EVENT_TABLE() END_EVENT_TABLE()
#endif #endif
@@ -205,6 +205,9 @@ bool wxWindow::Create(wxWindow *parent, wxWindowID id,
void wxWindow::SetFocus() void wxWindow::SetFocus()
{ {
if ( gFocusWindow == this )
return ;
if ( AcceptsFocus() ) if ( AcceptsFocus() )
{ {
if (gFocusWindow ) if (gFocusWindow )
@@ -510,6 +513,14 @@ void wxWindow::DoMoveWindow(int x, int y, int width, int height)
DoSetSize( x,y, width, height ) ; DoSetSize( x,y, width, height ) ;
} }
// set the size of the window: if the dimensions are positive, just use them,
// but if any of them is equal to -1, it means that we must find the value for
// it ourselves (unless sizeFlags contains wxSIZE_ALLOW_MINUS_ONE flag, in
// which case -1 is a valid value for x and y)
//
// If sizeFlags contains wxSIZE_AUTO_WIDTH/HEIGHT flags (default), we calculate
// the width/height to best suit our contents, otherwise we reuse the current
// width/height
void wxWindow::DoSetSize(int x, int y, int width, int height, int sizeFlags) void wxWindow::DoSetSize(int x, int y, int width, int height, int sizeFlags)
{ {
@@ -531,11 +542,49 @@ void wxWindow::DoSetSize(int x, int y, int width, int height, int sizeFlags)
actualX = currentX; actualX = currentX;
if (y == -1 && !(sizeFlags & wxSIZE_ALLOW_MINUS_ONE)) if (y == -1 && !(sizeFlags & wxSIZE_ALLOW_MINUS_ONE))
actualY = currentY; actualY = currentY;
if (width == -1)
actualWidth = currentW ;
if (height == -1)
actualHeight = currentH ;
wxSize size( -1 , -1 ) ;
if (width == -1 || height == -1 )
{
size = DoGetBestSize() ;
}
if ( width == -1 )
{
if ( sizeFlags & wxSIZE_AUTO_WIDTH )
{
actualWidth = size.x ;
if ( actualWidth == -1 )
actualWidth = 80 ;
}
else
{
actualWidth = currentW ;
}
}
if (height == -1)
{
if ( sizeFlags & wxSIZE_AUTO_HEIGHT )
{
actualHeight = size.y ;
if ( actualHeight == -1 )
actualHeight = 26 ;
}
else
{
actualHeight = currentH ;
}
}
if ((m_minWidth != -1) && (actualWidth < m_minWidth))
actualWidth = m_minWidth;
if ((m_minHeight != -1) && (actualHeight < m_minHeight))
actualHeight = m_minHeight;
if ((m_maxWidth != -1) && (actualWidth > m_maxWidth))
actualWidth = m_maxWidth;
if ((m_maxHeight != -1) && (actualHeight > m_maxHeight))
actualHeight = m_maxHeight;
if ( actualX == currentX && actualY == currentY && actualWidth == currentW && actualHeight == currentH) if ( actualX == currentX && actualY == currentY && actualWidth == currentW && actualHeight == currentH)
{ {
MacRepositionScrollBars() ; // we might have a real position shift MacRepositionScrollBars() ; // we might have a real position shift
@@ -1363,6 +1412,30 @@ wxObject* wxWindow::GetChild(int number) const
} }
#endif // WXWIN_COMPATIBILITY #endif // WXWIN_COMPATIBILITY
void wxWindow::OnSetFocus(wxFocusEvent& event)
{
// panel wants to track the window which was the last to have focus in it,
// so we want to set ourselves as the window which last had focus
//
// notice that it's also important to do it upwards the tree becaus
// otherwise when the top level panel gets focus, it won't set it back to
// us, but to some other sibling
wxWindow *win = this;
while ( win )
{
wxWindow *parent = win->GetParent();
wxPanel *panel = wxDynamicCast(parent, wxPanel);
if ( panel )
{
panel->SetLastFocus(win);
}
win = parent;
}
event.Skip();
}
void wxWindow::Clear() void wxWindow::Clear()
{ {
if ( m_macWindowData ) if ( m_macWindowData )
@@ -1528,6 +1601,13 @@ bool wxWindow::MacDispatchMouseEvent(wxMouseEvent& event)
m_cursor.MacInstall() ; m_cursor.MacInstall() ;
} }
if ( event.GetEventType() == wxEVT_LEFT_DOWN )
{
// set focus to this window
if (AcceptsFocus() && FindFocus()!=this)
SetFocus();
}
#if wxUSE_TOOLTIPS #if wxUSE_TOOLTIPS
if ( event.GetEventType() == wxEVT_MOTION if ( event.GetEventType() == wxEVT_MOTION
|| event.GetEventType() == wxEVT_ENTER_WINDOW || event.GetEventType() == wxEVT_ENTER_WINDOW

View File

@@ -761,10 +761,12 @@ void wxControl::OnMouseEvent( wxMouseEvent &event )
controlpart = FindControl( localwhere , window , &control ) ; controlpart = FindControl( localwhere , window , &control ) ;
{ {
/*
if ( AcceptsFocus() && FindFocus() != this ) if ( AcceptsFocus() && FindFocus() != this )
{ {
SetFocus() ; SetFocus() ;
} }
*/
if ( control && UMAIsControlActive( control ) ) if ( control && UMAIsControlActive( control ) )
{ {
{ {

View File

@@ -100,6 +100,7 @@ bool wxFrame::Create(wxWindow *parent,
m_frameToolBar = NULL ; m_frameToolBar = NULL ;
#endif #endif
m_frameStatusBar = NULL; m_frameStatusBar = NULL;
m_winLastFocused = NULL ;
SetBackgroundColour(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_APPWORKSPACE)); SetBackgroundColour(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_APPWORKSPACE));
@@ -259,10 +260,21 @@ void wxFrame::OnActivate(wxActivateEvent& event)
{ {
if ( !event.GetActive() ) if ( !event.GetActive() )
{ {
event.Skip(); // remember the last focused child
return; m_winLastFocused = FindFocus();
while ( m_winLastFocused )
{
if ( GetChildren().Find(m_winLastFocused) )
break;
m_winLastFocused = m_winLastFocused->GetParent();
} }
event.Skip();
}
else
{
/*
for ( wxWindowList::Node *node = GetChildren().GetFirst(); for ( wxWindowList::Node *node = GetChildren().GetFirst();
node; node;
node = node->GetNext() ) node = node->GetNext() )
@@ -273,7 +285,7 @@ void wxFrame::OnActivate(wxActivateEvent& event)
// restore focus // restore focus
wxWindow *child = node->GetData(); wxWindow *child = node->GetData();
if ( !child->IsTopLevel() if ( !child->IsTopLevel() && child->AcceptsFocus()
#if wxUSE_TOOLBAR #if wxUSE_TOOLBAR
&& !wxDynamicCast(child, wxToolBar) && !wxDynamicCast(child, wxToolBar)
#endif // wxUSE_TOOLBAR #endif // wxUSE_TOOLBAR
@@ -286,12 +298,15 @@ void wxFrame::OnActivate(wxActivateEvent& event)
break; break;
} }
} }
*/
wxSetFocusToChild(this, &m_winLastFocused);
if ( m_frameMenuBar != NULL ) if ( m_frameMenuBar != NULL )
{ {
m_frameMenuBar->MacInstallMenuBar() ; m_frameMenuBar->MacInstallMenuBar() ;
} }
} }
}
void wxFrame::DoGetClientSize(int *x, int *y) const void wxFrame::DoGetClientSize(int *x, int *y) const
{ {

View File

@@ -111,7 +111,6 @@ void wxToolBar::Init()
bool wxToolBar::Create(wxWindow *parent, wxWindowID id, const wxPoint& pos, const wxSize& size, bool wxToolBar::Create(wxWindow *parent, wxWindowID id, const wxPoint& pos, const wxSize& size,
long style, const wxString& name) long style, const wxString& name)
{ {
m_maxWidth = m_maxHeight = 0;
m_defaultWidth = defwidth; m_defaultWidth = defwidth;
m_defaultHeight = defheight; m_defaultHeight = defheight;
@@ -167,7 +166,8 @@ bool wxToolBar::Create(wxWindow *parent, wxWindowID id, const wxPoint& pos, cons
wxToolBar::~wxToolBar() wxToolBar::~wxToolBar()
{ {
// TODO // we must refresh the frame size when the toolbar is deleted but the frame
// is not - otherwise toolbar leaves a hole in the place it used to occupy
} }
PicHandle MakePict(GWorldPtr wp, GWorldPtr mask ) ; PicHandle MakePict(GWorldPtr wp, GWorldPtr mask ) ;
@@ -267,7 +267,7 @@ bool wxToolBar::Realize()
WindowRef window ; WindowRef window ;
wxWindow *win ; wxWindow *win ;
MacGetPortParams( &localOrigin , &clipRect , &window , &win ) ; GetParent()->MacGetPortParams( &localOrigin , &clipRect , &window , &win ) ;
Rect toolbarrect = { m_y + localOrigin.v , m_x + localOrigin.h , Rect toolbarrect = { m_y + localOrigin.v , m_x + localOrigin.h ,
m_y + m_height + localOrigin.v , m_x + m_width + localOrigin.h} ; m_y + m_height + localOrigin.v , m_x + m_width + localOrigin.h} ;
@@ -282,6 +282,7 @@ bool wxToolBar::Realize()
wxSize toolSize = GetToolSize() ; wxSize toolSize = GetToolSize() ;
int tw, th; int tw, th;
GetSize(& tw, & th); GetSize(& tw, & th);
m_maxWidth = m_maxHeight = 0 ;
while (node) while (node)
{ {
wxToolBarTool *tool = (wxToolBarTool *)node->Data(); wxToolBarTool *tool = (wxToolBarTool *)node->Data();
@@ -356,23 +357,36 @@ bool wxToolBar::Realize()
m_macToolHandles.Add( NULL ) ; m_macToolHandles.Add( NULL ) ;
x += (int)toolSize.x / 4; x += (int)toolSize.x / 4;
} }
if ( toolbarrect.left + x + kwxMacToolBarLeftMargin > m_maxWidth) if ( toolbarrect.left + x + kwxMacToolBarLeftMargin - m_x - localOrigin.h > m_maxWidth)
m_maxWidth = toolbarrect.left + x + kwxMacToolBarLeftMargin; m_maxWidth = toolbarrect.left + x + kwxMacToolBarLeftMargin - m_x - localOrigin.h;
if (toolbarrect.top + kwxMacToolBarTopMargin + toolSize.y > m_maxHeight) if (toolbarrect.top + kwxMacToolBarTopMargin - m_y - localOrigin.v > m_maxHeight)
m_maxHeight = toolbarrect.top + kwxMacToolBarTopMargin ; m_maxHeight = toolbarrect.top + kwxMacToolBarTopMargin - m_y - localOrigin.v ;
node = node->Next(); node = node->Next();
} }
if ( GetWindowStyleFlag() & wxTB_HORIZONTAL ) if ( GetWindowStyleFlag() & wxTB_HORIZONTAL )
{ {
m_maxWidth = tw ; // +=toolSize.x; if ( m_maxRows == 0 )
{
// if not set yet, only one row
SetRows(1);
}
m_maxWidth = clipRect.right - m_x ;
//m_maxWidth = tw ; // +=toolSize.x;
//m_maxWidth += m_xMargin ;
m_maxHeight += toolSize.y; m_maxHeight += toolSize.y;
m_maxHeight += m_yMargin; m_maxHeight += m_yMargin;
} }
else else
{ {
m_maxHeight = th ;// += toolSize.y; if ( noButtons > 0 && m_maxRows == 0 )
{
// if not set yet, have one column
SetRows(noButtons);
}
m_maxHeight = clipRect.bottom - m_y ;
//m_maxHeight += m_yMargin ;
m_maxWidth += toolSize.x; m_maxWidth += toolSize.x;
m_maxWidth += m_xMargin; m_maxWidth += m_xMargin;
} }
@@ -506,7 +520,7 @@ void wxToolBar::OnPaint(wxPaintEvent& event)
WindowRef window ; WindowRef window ;
wxWindow *win ; wxWindow *win ;
MacGetPortParams( &localOrigin , &clipRect , &window , &win ) ; GetParent()->MacGetPortParams( &localOrigin , &clipRect , &window , &win ) ;
if ( window && win ) if ( window && win )
{ {
wxMacDrawingHelper help( win ) ; wxMacDrawingHelper help( win ) ;
@@ -532,8 +546,20 @@ void wxToolBar::OnPaint(wxPaintEvent& event)
parent = parent->GetParent() ; parent = parent->GetParent() ;
} }
int w = m_width ;
int h = m_height ;
if ( GetWindowStyleFlag() & wxTB_HORIZONTAL )
{
w = clipRect.right - m_x ;
}
else
{
h = clipRect.bottom - m_y ;
}
Rect toolbarrect = { m_y + localOrigin.v , m_x + localOrigin.h , Rect toolbarrect = { m_y + localOrigin.v , m_x + localOrigin.h ,
m_y + localOrigin.v + m_height , m_x + localOrigin.h + m_width } ; m_y + localOrigin.v + h , m_x + localOrigin.h + w } ;
UMADrawThemePlacard( &toolbarrect , IsEnabled() ? kThemeStateActive : kThemeStateInactive) ; UMADrawThemePlacard( &toolbarrect , IsEnabled() ? kThemeStateActive : kThemeStateInactive) ;
{ {

View File

@@ -65,7 +65,7 @@ BEGIN_EVENT_TABLE(wxWindow, wxEvtHandler)
EVT_SYS_COLOUR_CHANGED(wxWindow::OnSysColourChanged) EVT_SYS_COLOUR_CHANGED(wxWindow::OnSysColourChanged)
EVT_INIT_DIALOG(wxWindow::OnInitDialog) EVT_INIT_DIALOG(wxWindow::OnInitDialog)
EVT_IDLE(wxWindow::OnIdle) EVT_IDLE(wxWindow::OnIdle)
// EVT_SCROLL(wxWindow::OnScroll) EVT_SET_FOCUS(wxWindow::OnSetFocus)
END_EVENT_TABLE() END_EVENT_TABLE()
#endif #endif
@@ -205,6 +205,9 @@ bool wxWindow::Create(wxWindow *parent, wxWindowID id,
void wxWindow::SetFocus() void wxWindow::SetFocus()
{ {
if ( gFocusWindow == this )
return ;
if ( AcceptsFocus() ) if ( AcceptsFocus() )
{ {
if (gFocusWindow ) if (gFocusWindow )
@@ -510,6 +513,14 @@ void wxWindow::DoMoveWindow(int x, int y, int width, int height)
DoSetSize( x,y, width, height ) ; DoSetSize( x,y, width, height ) ;
} }
// set the size of the window: if the dimensions are positive, just use them,
// but if any of them is equal to -1, it means that we must find the value for
// it ourselves (unless sizeFlags contains wxSIZE_ALLOW_MINUS_ONE flag, in
// which case -1 is a valid value for x and y)
//
// If sizeFlags contains wxSIZE_AUTO_WIDTH/HEIGHT flags (default), we calculate
// the width/height to best suit our contents, otherwise we reuse the current
// width/height
void wxWindow::DoSetSize(int x, int y, int width, int height, int sizeFlags) void wxWindow::DoSetSize(int x, int y, int width, int height, int sizeFlags)
{ {
@@ -531,11 +542,49 @@ void wxWindow::DoSetSize(int x, int y, int width, int height, int sizeFlags)
actualX = currentX; actualX = currentX;
if (y == -1 && !(sizeFlags & wxSIZE_ALLOW_MINUS_ONE)) if (y == -1 && !(sizeFlags & wxSIZE_ALLOW_MINUS_ONE))
actualY = currentY; actualY = currentY;
if (width == -1)
actualWidth = currentW ;
if (height == -1)
actualHeight = currentH ;
wxSize size( -1 , -1 ) ;
if (width == -1 || height == -1 )
{
size = DoGetBestSize() ;
}
if ( width == -1 )
{
if ( sizeFlags & wxSIZE_AUTO_WIDTH )
{
actualWidth = size.x ;
if ( actualWidth == -1 )
actualWidth = 80 ;
}
else
{
actualWidth = currentW ;
}
}
if (height == -1)
{
if ( sizeFlags & wxSIZE_AUTO_HEIGHT )
{
actualHeight = size.y ;
if ( actualHeight == -1 )
actualHeight = 26 ;
}
else
{
actualHeight = currentH ;
}
}
if ((m_minWidth != -1) && (actualWidth < m_minWidth))
actualWidth = m_minWidth;
if ((m_minHeight != -1) && (actualHeight < m_minHeight))
actualHeight = m_minHeight;
if ((m_maxWidth != -1) && (actualWidth > m_maxWidth))
actualWidth = m_maxWidth;
if ((m_maxHeight != -1) && (actualHeight > m_maxHeight))
actualHeight = m_maxHeight;
if ( actualX == currentX && actualY == currentY && actualWidth == currentW && actualHeight == currentH) if ( actualX == currentX && actualY == currentY && actualWidth == currentW && actualHeight == currentH)
{ {
MacRepositionScrollBars() ; // we might have a real position shift MacRepositionScrollBars() ; // we might have a real position shift
@@ -1363,6 +1412,30 @@ wxObject* wxWindow::GetChild(int number) const
} }
#endif // WXWIN_COMPATIBILITY #endif // WXWIN_COMPATIBILITY
void wxWindow::OnSetFocus(wxFocusEvent& event)
{
// panel wants to track the window which was the last to have focus in it,
// so we want to set ourselves as the window which last had focus
//
// notice that it's also important to do it upwards the tree becaus
// otherwise when the top level panel gets focus, it won't set it back to
// us, but to some other sibling
wxWindow *win = this;
while ( win )
{
wxWindow *parent = win->GetParent();
wxPanel *panel = wxDynamicCast(parent, wxPanel);
if ( panel )
{
panel->SetLastFocus(win);
}
win = parent;
}
event.Skip();
}
void wxWindow::Clear() void wxWindow::Clear()
{ {
if ( m_macWindowData ) if ( m_macWindowData )
@@ -1528,6 +1601,13 @@ bool wxWindow::MacDispatchMouseEvent(wxMouseEvent& event)
m_cursor.MacInstall() ; m_cursor.MacInstall() ;
} }
if ( event.GetEventType() == wxEVT_LEFT_DOWN )
{
// set focus to this window
if (AcceptsFocus() && FindFocus()!=this)
SetFocus();
}
#if wxUSE_TOOLTIPS #if wxUSE_TOOLTIPS
if ( event.GetEventType() == wxEVT_MOTION if ( event.GetEventType() == wxEVT_MOTION
|| event.GetEventType() == wxEVT_ENTER_WINDOW || event.GetEventType() == wxEVT_ENTER_WINDOW