Initial ShowWithoutActivating implementations for Mac and Windows, and attempt to improve IsActive behavior on Mac. Also adding ShowWithoutActivating() and Show/Hide tests, but until the mainloop issues are resolved, not adding them to tests.bkl.

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@62508 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Kevin Ollivier 2009-10-30 05:04:47 +00:00
parent bc7879ec4c
commit dbc7ceb925
13 changed files with 189 additions and 10 deletions

View File

@ -52,6 +52,7 @@ public:
virtual bool EnableCloseButton(bool enable = true);
virtual void ShowWithoutActivating();
virtual bool ShowFullScreen(bool show, long style = wxFULLSCREEN_ALL);
virtual bool IsFullScreen() const { return m_fsIsShowing; };

View File

@ -64,6 +64,7 @@ public:
virtual bool Show(bool show = true);
virtual void ShowWithoutActivating();
virtual bool ShowFullScreen(bool show, long style = wxFULLSCREEN_ALL);
virtual bool IsFullScreen() const { return m_fsIsShowing; }

View File

@ -1040,12 +1040,15 @@ public :
virtual bool IsFullScreen() const;
virtual bool ShowFullScreen(bool show, long style);
virtual void ShowWithoutActivating();
virtual void RequestUserAttention(int flags);
virtual void ScreenToWindow( int *x, int *y );
virtual void WindowToScreen( int *x, int *y );
virtual bool IsActive();
bool MacGetUnifiedAppearance() const ;

View File

@ -233,6 +233,8 @@ public :
virtual bool IsFullScreen() const;
virtual bool ShowFullScreen(bool show, long style);
virtual void ShowWithoutActivating();
virtual void RequestUserAttention(int flags);
@ -240,6 +242,8 @@ public :
virtual void WindowToScreen( int *x, int *y );
virtual bool IsActive();
wxNonOwnedWindow* GetWXPeer() { return m_wxPeer; }
protected :
WX_wxNSWindow m_macWindow;

View File

@ -717,6 +717,8 @@ public :
virtual bool IsFullScreen() const= 0;
virtual void ShowWithoutActivating() { Show(true); }
virtual bool ShowFullScreen(bool show, long style)= 0;
virtual void RequestUserAttention(int flags) = 0;
@ -725,6 +727,8 @@ public :
virtual void WindowToScreen( int *x, int *y ) = 0;
virtual bool IsActive() = 0;
wxNonOwnedWindow* GetWXPeer() { return m_wxPeer; }
// static creation methods, must be implemented by all toolkits

View File

@ -169,6 +169,9 @@ public :
virtual void WindowToScreen( int *x, int *y );
// FIXME: Does iPhone have a concept of inactive windows?
virtual bool IsActive() { return true; }
wxNonOwnedWindow* GetWXPeer() { return m_wxPeer; }
protected :
WX_UIWindow m_macWindow;

View File

@ -62,7 +62,10 @@ public:
virtual void Iconize(bool iconize = true);
virtual bool IsIconized() const;
virtual void Restore();
virtual bool IsActive();
virtual void ShowWithoutActivating();
virtual bool ShowFullScreen(bool show, long style = wxFULLSCREEN_ALL) ;
virtual bool IsFullScreen() const ;

View File

@ -160,6 +160,12 @@ public:
// maximize the window to cover entire screen
virtual bool ShowFullScreen(bool show, long style = wxFULLSCREEN_ALL) = 0;
// shows the window, but doesn't activate it. If the base code is being run,
// it means the port doesn't implement this method yet and so alert the user.
virtual void ShowWithoutActivating() {
wxFAIL_MSG("ShowWithoutActivating not implemented on this platform.");
}
// return true if the frame is in fullscreen mode
virtual bool IsFullScreen() const = 0;

View File

@ -609,6 +609,14 @@ void wxTopLevelWindowMSW::DoShowWindow(int nShowCmd)
m_iconized = nShowCmd == SW_MINIMIZE;
}
void wxTopLevelWindowMSW::ShowWithoutActivating()
{
if ( !wxWindowBase::Show(true) )
return false;
DoShowWindow(SW_SHOWNA);
}
bool wxTopLevelWindowMSW::Show(bool show)
{
// don't use wxWindow version as we want to call DoShowWindow() ourselves

View File

@ -51,6 +51,21 @@ void wxNonOwnedWindowCarbonImpl::Lower()
::SendBehind( m_macWindow , NULL ) ;
}
void wxNonOwnedWindowCarbonImpl::ShowWithoutActivating()
{
bool plainTransition = true;
#if wxUSE_SYSTEM_OPTIONS
if ( wxSystemOptions::HasOption(wxMAC_WINDOW_PLAIN_TRANSITION) )
plainTransition = ( wxSystemOptions::GetOptionInt( wxMAC_WINDOW_PLAIN_TRANSITION ) == 1 ) ;
#endif
if ( plainTransition )
::ShowWindow( (WindowRef)m_macWindow );
else
::TransitionWindow( (WindowRef)m_macWindow, kWindowZoomTransitionEffect, kWindowShowTransitionAction, NULL );
}
bool wxNonOwnedWindowCarbonImpl::Show(bool show)
{
bool plainTransition = true;
@ -62,14 +77,8 @@ bool wxNonOwnedWindowCarbonImpl::Show(bool show)
if (show)
{
#if wxOSX_USE_CARBON
if ( plainTransition )
::ShowWindow( (WindowRef)m_macWindow );
else
::TransitionWindow( (WindowRef)m_macWindow, kWindowZoomTransitionEffect, kWindowShowTransitionAction, NULL );
ShowWithoutActivating();
::SelectWindow( (WindowRef)m_macWindow ) ;
#endif
}
else
{
@ -1669,6 +1678,11 @@ void wxNonOwnedWindowCarbonImpl::WindowToScreen( int *x, int *y )
*y = (int)p.y;
}
bool wxNonOwnedWindowCarbonImpl::IsActive()
{
return ActiveNonFloatingWindow() == m_macWindow;
}
wxNonOwnedWindowImpl* wxNonOwnedWindowImpl::CreateNonOwnedWindow( wxNonOwnedWindow* wxpeer, wxWindow* parent, const wxPoint& pos, const wxSize& size,
long style, long extraStyle, const wxString& name )
{

View File

@ -471,17 +471,21 @@ void wxNonOwnedWindowCocoaImpl::Lower()
[m_macWindow orderWindow:NSWindowBelow relativeTo:0];
}
void wxNonOwnedWindowCocoaImpl::ShowWithoutActivating()
{
[[m_macWindow contentView] setNeedsDisplay:YES];
}
bool wxNonOwnedWindowCocoaImpl::Show(bool show)
{
if ( show )
{
wxNonOwnedWindow* wxpeer = GetWXPeer();
if (wxpeer && !(wxpeer->GetWindowStyle() & wxFRAME_TOOL_WINDOW))
[m_macWindow makeKeyAndOrderFront:nil];
[m_macWindow makeKeyAndOrderFront:nil];
else
[m_macWindow orderFront:nil];
[[m_macWindow contentView] setNeedsDisplay:YES];
ShowWithoutActivating();
}
else
[m_macWindow orderOut:nil];
@ -676,6 +680,11 @@ void wxNonOwnedWindowCocoaImpl::WindowToScreen( int *x, int *y )
*y = p.y;
}
bool wxNonOwnedWindowCocoaImpl::IsActive()
{
return [m_macWindow isKeyWindow];
}
wxNonOwnedWindowImpl* wxNonOwnedWindowImpl::CreateNonOwnedWindow( wxNonOwnedWindow* wxpeer, wxWindow* parent, const wxPoint& pos, const wxSize& size,
long style, long extraStyle, const wxString& name )
{

View File

@ -157,6 +157,11 @@ wxString wxTopLevelWindowMac::GetTitle() const
return wxWindow::GetLabel();
}
void wxTopLevelWindowMac::ShowWithoutActivating()
{
return m_nowpeer->ShowWithoutActivating();
}
bool wxTopLevelWindowMac::ShowFullScreen(bool show, long style)
{
return m_nowpeer->ShowFullScreen(show, style);
@ -171,3 +176,8 @@ void wxTopLevelWindowMac::RequestUserAttention(int flags)
{
return m_nowpeer->RequestUserAttention(flags);
}
bool wxTopLevelWindowMac::IsActive()
{
return m_nowpeer->IsActive();
}

113
tests/toplevel/toplevel.cpp Normal file
View File

@ -0,0 +1,113 @@
///////////////////////////////////////////////////////////////////////////////
// Name: tests/toplevel/toplevel.cpp
// Purpose: Tests for wxTopLevelWindow
// Author: Kevin Ollivier
// Created: 2008-05-25
// RCS-ID: $Id: toplevel.cpp 53741 2008-05-25 03:08:31Z VZ $
// Copyright: (c) 2009 Kevin Ollivier <kevino@theolliviers.com>
///////////////////////////////////////////////////////////////////////////////
// ----------------------------------------------------------------------------
// headers
// ----------------------------------------------------------------------------
#include "testprec.h"
#ifdef __BORLANDC__
#pragma hdrstop
#endif
#ifndef WX_PRECOMP
#include "wx/app.h"
#include "wx/window.h"
#endif // WX_PRECOMP
#include "wx/evtloop.h"
// ----------------------------------------------------------------------------
// test class
// ----------------------------------------------------------------------------
class TopLevelWindowTestCase : public CppUnit::TestCase
{
public:
TopLevelWindowTestCase() { }
virtual void setUp();
virtual void tearDown();
private:
CPPUNIT_TEST_SUITE( TopLevelWindowTestCase );
CPPUNIT_TEST( DialogShowTest );
CPPUNIT_TEST( FrameShowTest );
CPPUNIT_TEST_SUITE_END();
void DialogShowTest();
void FrameShowTest();
void TopLevelWindowShowTest(wxTopLevelWindow* tlw);
DECLARE_NO_COPY_CLASS(TopLevelWindowTestCase)
};
// register in the unnamed registry so that these tests are run by default
CPPUNIT_TEST_SUITE_REGISTRATION( TopLevelWindowTestCase );
// also include in it's own registry so that these tests can be run alone
CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( TopLevelWindowTestCase, "TopLevelWindowTestCase" );
// ----------------------------------------------------------------------------
// test initialization
// ----------------------------------------------------------------------------
void TopLevelWindowTestCase::setUp()
{
}
void TopLevelWindowTestCase::tearDown()
{
}
// ----------------------------------------------------------------------------
// tests themselves
// ----------------------------------------------------------------------------
void TopLevelWindowTestCase::DialogShowTest()
{
wxDialog* dialog = new wxDialog(NULL, -1, "Dialog Test");
TopLevelWindowShowTest(dialog);
dialog->Destroy();
}
void TopLevelWindowTestCase::FrameShowTest()
{
wxFrame* frame = new wxFrame(NULL, -1, "Frame test");
TopLevelWindowShowTest(frame);
frame->Destroy();
}
void TopLevelWindowTestCase::TopLevelWindowShowTest(wxTopLevelWindow* tlw)
{
CPPUNIT_ASSERT(!tlw->IsShown());
wxTextCtrl* textCtrl = new wxTextCtrl(tlw, -1, "test");
textCtrl->SetFocus();
// only run this test on platforms where ShowWithoutActivating is implemented.
#ifdef __WXMSW__ || defined(__WXMAC__)
tlw->ShowWithoutActivating();
CPPUNIT_ASSERT(tlw->IsShown());
CPPUNIT_ASSERT(!tlw->IsActive());
tlw->Hide();
CPPUNIT_ASSERT(!tlw->IsShown());
CPPUNIT_ASSERT(!tlw->IsActive());
#endif
tlw->Show(true);
CPPUNIT_ASSERT(tlw->IsActive());
CPPUNIT_ASSERT(tlw->IsShown());
tlw->Hide();
CPPUNIT_ASSERT(!tlw->IsShown());
CPPUNIT_ASSERT(tlw->IsActive());
}