From dbc7ceb9250bcc2f856f87555f8f4273da31c148 Mon Sep 17 00:00:00 2001 From: Kevin Ollivier Date: Fri, 30 Oct 2009 05:04:47 +0000 Subject: [PATCH] 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 --- include/wx/gtk/toplevel.h | 1 + include/wx/msw/toplevel.h | 1 + include/wx/osx/carbon/private.h | 3 + include/wx/osx/cocoa/private.h | 4 ++ include/wx/osx/core/private.h | 4 ++ include/wx/osx/iphone/private.h | 3 + include/wx/osx/toplevel.h | 3 + include/wx/toplevel.h | 6 ++ src/msw/toplevel.cpp | 8 +++ src/osx/carbon/nonownedwnd.cpp | 28 ++++++-- src/osx/cocoa/nonownedwnd.mm | 15 ++++- src/osx/toplevel_osx.cpp | 10 +++ tests/toplevel/toplevel.cpp | 113 ++++++++++++++++++++++++++++++++ 13 files changed, 189 insertions(+), 10 deletions(-) create mode 100644 tests/toplevel/toplevel.cpp diff --git a/include/wx/gtk/toplevel.h b/include/wx/gtk/toplevel.h index a5e356e2db..013e081df6 100644 --- a/include/wx/gtk/toplevel.h +++ b/include/wx/gtk/toplevel.h @@ -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; }; diff --git a/include/wx/msw/toplevel.h b/include/wx/msw/toplevel.h index 43721fa25f..b464c227b7 100644 --- a/include/wx/msw/toplevel.h +++ b/include/wx/msw/toplevel.h @@ -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; } diff --git a/include/wx/osx/carbon/private.h b/include/wx/osx/carbon/private.h index bc4794ac57..a96cde255a 100644 --- a/include/wx/osx/carbon/private.h +++ b/include/wx/osx/carbon/private.h @@ -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 ; diff --git a/include/wx/osx/cocoa/private.h b/include/wx/osx/cocoa/private.h index d9bf8338d1..3473aadca9 100644 --- a/include/wx/osx/cocoa/private.h +++ b/include/wx/osx/cocoa/private.h @@ -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; diff --git a/include/wx/osx/core/private.h b/include/wx/osx/core/private.h index 2ea1bd40a7..917f6a684a 100644 --- a/include/wx/osx/core/private.h +++ b/include/wx/osx/core/private.h @@ -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 diff --git a/include/wx/osx/iphone/private.h b/include/wx/osx/iphone/private.h index b4c25709a5..fa5cbd5f14 100644 --- a/include/wx/osx/iphone/private.h +++ b/include/wx/osx/iphone/private.h @@ -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; diff --git a/include/wx/osx/toplevel.h b/include/wx/osx/toplevel.h index 3cc75c4820..80ccb39ed5 100644 --- a/include/wx/osx/toplevel.h +++ b/include/wx/osx/toplevel.h @@ -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 ; diff --git a/include/wx/toplevel.h b/include/wx/toplevel.h index a5fb510039..93490abc3c 100644 --- a/include/wx/toplevel.h +++ b/include/wx/toplevel.h @@ -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; diff --git a/src/msw/toplevel.cpp b/src/msw/toplevel.cpp index 3773984990..e74256523c 100644 --- a/src/msw/toplevel.cpp +++ b/src/msw/toplevel.cpp @@ -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 diff --git a/src/osx/carbon/nonownedwnd.cpp b/src/osx/carbon/nonownedwnd.cpp index cab04631f5..75077bc46e 100644 --- a/src/osx/carbon/nonownedwnd.cpp +++ b/src/osx/carbon/nonownedwnd.cpp @@ -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 ) { diff --git a/src/osx/cocoa/nonownedwnd.mm b/src/osx/cocoa/nonownedwnd.mm index c44f4eba89..c19341742e 100644 --- a/src/osx/cocoa/nonownedwnd.mm +++ b/src/osx/cocoa/nonownedwnd.mm @@ -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 ) { diff --git a/src/osx/toplevel_osx.cpp b/src/osx/toplevel_osx.cpp index 91ac80da69..0e646c5f69 100644 --- a/src/osx/toplevel_osx.cpp +++ b/src/osx/toplevel_osx.cpp @@ -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(); +} diff --git a/tests/toplevel/toplevel.cpp b/tests/toplevel/toplevel.cpp new file mode 100644 index 0000000000..9306a93f5e --- /dev/null +++ b/tests/toplevel/toplevel.cpp @@ -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 +/////////////////////////////////////////////////////////////////////////////// + +// ---------------------------------------------------------------------------- +// 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()); +} -- 2.47.2