]> git.saurik.com Git - wxWidgets.git/commitdiff
Initial ShowWithoutActivating implementations for Mac and Windows, and attempt to...
authorKevin Ollivier <kevino@theolliviers.com>
Fri, 30 Oct 2009 05:04:47 +0000 (05:04 +0000)
committerKevin Ollivier <kevino@theolliviers.com>
Fri, 30 Oct 2009 05:04:47 +0000 (05:04 +0000)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@62508 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

13 files changed:
include/wx/gtk/toplevel.h
include/wx/msw/toplevel.h
include/wx/osx/carbon/private.h
include/wx/osx/cocoa/private.h
include/wx/osx/core/private.h
include/wx/osx/iphone/private.h
include/wx/osx/toplevel.h
include/wx/toplevel.h
src/msw/toplevel.cpp
src/osx/carbon/nonownedwnd.cpp
src/osx/cocoa/nonownedwnd.mm
src/osx/toplevel_osx.cpp
tests/toplevel/toplevel.cpp [new file with mode: 0644]

index a5e356e2db633dc0b096f2dc9a1a9f371ee84d0f..013e081df60b00a51e7b30e2a23324d340779440 100644 (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; };
 
index 43721fa25fe4921d097508df75562b8c8ba6c494..b464c227b7f0749f28b3e2c3b1bca752ba980c5a 100644 (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; }
 
index bc4794ac57b05bcfd8687d5f13064781335775fb..a96cde255a4f217971af7173e0e67dc32e809c06 100644 (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 ;
index d9bf8338d126c65e9be18a5a65940a17d5ad8040..3473aadca9a18e6152c53096052fd0a1a2943d90 100644 (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;
index 2ea1bd40a7f9961d25ea880ded30b758f632dd4b..917f6a684a346439f3001fe3febfa91010f72319 100644 (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
index b4c25709a512b952bf29c6d83683cb8f744975cc..fa5cbd5f145ea8f97475a204d5df137eeb422e1f 100644 (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;
index 3cc75c482031ddfe2ee854f38f17327cccdb0a65..80ccb39ed50ac8b9a5a43ac14952058bcb8d9110 100644 (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 ;
 
index a5fb510039fcb830484508d9ff69666ba75e4479..93490abc3c3c43195aac473ed0d4309c0c8bd492 100644 (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;
index 37739849902b79ece53fe6be7c667838cfb917ce..e74256523cb68902edc2edda5ac4579937b47ca3 100644 (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
index cab04631f5a7522d74224c8eb6f75c0f0b0d3302..75077bc46e8a4c11e00cdb9ed5980efb8b434d5a 100644 (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 )
 {
index c44f4eba89f42ff69bf02e5f52b92f7f65d513f7..c19341742eea0e826179eb545a486e6e171f9baf 100644 (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 )
 {
index 91ac80da69e8b3df0adbe7d08cfcc168211a9c68..0e646c5f697bd1ade572fa674dd47664f3b96cee 100644 (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();
+}
diff --git a/tests/toplevel/toplevel.cpp b/tests/toplevel/toplevel.cpp
new file mode 100644 (file)
index 0000000..9306a93
--- /dev/null
@@ -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());
+}