Add wxApp::GetMainTopWindow() wrapper
This trivial function just allows to avoid checking if wxTheApp is not null before calling GetTopWindow() on it. Replace the existing "wxTheApp && wxTheApp->GetTopWindow()" calls with wxApp::GetMainTopWindow(). No real changes.
This commit is contained in:
		@@ -622,6 +622,10 @@ public:
 | 
			
		||||
        // there are none, will return NULL)
 | 
			
		||||
    virtual wxWindow *GetTopWindow() const;
 | 
			
		||||
 | 
			
		||||
        // convenient helper which is safe to use even if there is no wxApp at
 | 
			
		||||
        // all, it will just return NULL in this case
 | 
			
		||||
    static wxWindow *GetMainTopWindow();
 | 
			
		||||
 | 
			
		||||
        // control the exit behaviour: by default, the program will exit the
 | 
			
		||||
        // main loop (and so, usually, terminate) when the last top-level
 | 
			
		||||
        // program window is deleted. Beware that if you disable this behaviour
 | 
			
		||||
 
 | 
			
		||||
@@ -859,6 +859,18 @@ public:
 | 
			
		||||
    */
 | 
			
		||||
    bool GetUseBestVisual() const;
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
        Returns a pointer to the top application window if any.
 | 
			
		||||
 | 
			
		||||
        This function is safe to call even before creating, or after
 | 
			
		||||
        destroying, the application object, as it simply returns @NULL if it
 | 
			
		||||
        doesn't exist. Otherwise it's equivalent to calling
 | 
			
		||||
        @c wxTheApp->GetTopWindow().
 | 
			
		||||
 | 
			
		||||
        @since 3.1.5
 | 
			
		||||
     */
 | 
			
		||||
    static wxWindow* GetMainTopWindow();
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
        Returns a pointer to the top window.
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -189,6 +189,14 @@ wxWindow* wxAppBase::GetTopWindow() const
 | 
			
		||||
    return window;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/* static */
 | 
			
		||||
wxWindow* wxAppBase::GetMainTopWindow()
 | 
			
		||||
{
 | 
			
		||||
    const wxAppBase* const app = static_cast<wxAppBase*>(GetInstance());
 | 
			
		||||
 | 
			
		||||
    return app ? app->GetTopWindow() : NULL;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
wxVideoMode wxAppBase::GetDisplayMode() const
 | 
			
		||||
{
 | 
			
		||||
    return wxVideoMode();
 | 
			
		||||
 
 | 
			
		||||
@@ -183,8 +183,8 @@ wxDialogBase::GetParentForModalDialog(wxWindow *parent, long style) const
 | 
			
		||||
                    wxGetTopLevelParent(wxGetActiveWindow()));
 | 
			
		||||
 | 
			
		||||
    // and finally the application main window
 | 
			
		||||
    if ( !parent && wxTheApp )
 | 
			
		||||
        parent = CheckIfCanBeUsedAsParent(wxTheApp->GetTopWindow());
 | 
			
		||||
    if ( !parent )
 | 
			
		||||
        parent = CheckIfCanBeUsedAsParent(wxApp::GetMainTopWindow());
 | 
			
		||||
 | 
			
		||||
    return parent;
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -264,7 +264,7 @@ wxIcon wxIconBundle::GetIcon(const wxSize& size, int flags) const
 | 
			
		||||
            sysY = 0;
 | 
			
		||||
    if ( flags & FALLBACK_SYSTEM )
 | 
			
		||||
    {
 | 
			
		||||
        wxWindow* win = wxTheApp ? wxTheApp->GetTopWindow() : NULL;
 | 
			
		||||
        wxWindow* win = wxApp::GetMainTopWindow();
 | 
			
		||||
        sysX = wxSystemSettings::GetMetric(wxSYS_ICON_X, win);
 | 
			
		||||
        sysY = wxSystemSettings::GetMetric(wxSYS_ICON_Y, win);
 | 
			
		||||
    }
 | 
			
		||||
 
 | 
			
		||||
@@ -104,7 +104,7 @@ float wxSizerFlags::DoGetDefaultBorderInPx()
 | 
			
		||||
    // We also have to use the DPI for the monitor showing the top window here
 | 
			
		||||
    // as we don't have any associated window -- but, again, without changes
 | 
			
		||||
    // in the API, there is nothing we can do about this.
 | 
			
		||||
    const wxWindow* const win = wxTheApp ? wxTheApp->GetTopWindow() : NULL;
 | 
			
		||||
    const wxWindow* const win = wxApp::GetMainTopWindow();
 | 
			
		||||
    static wxPrivate::DpiDependentValue<float> s_defaultBorderInPx;
 | 
			
		||||
    if ( s_defaultBorderInPx.HasChanged(win) )
 | 
			
		||||
    {
 | 
			
		||||
 
 | 
			
		||||
@@ -81,10 +81,10 @@ wxString wxAboutDialogInfo::GetDescriptionAndCredits() const
 | 
			
		||||
wxIcon wxAboutDialogInfo::GetIcon() const
 | 
			
		||||
{
 | 
			
		||||
    wxIcon icon = m_icon;
 | 
			
		||||
    if ( !icon.IsOk() && wxTheApp )
 | 
			
		||||
    if ( !icon.IsOk() )
 | 
			
		||||
    {
 | 
			
		||||
        const wxTopLevelWindow * const
 | 
			
		||||
            tlw = wxDynamicCast(wxTheApp->GetTopWindow(), wxTopLevelWindow);
 | 
			
		||||
            tlw = wxDynamicCast(wxApp::GetMainTopWindow(), wxTopLevelWindow);
 | 
			
		||||
        if ( tlw )
 | 
			
		||||
            icon = tlw->GetIcon();
 | 
			
		||||
    }
 | 
			
		||||
 
 | 
			
		||||
@@ -691,8 +691,8 @@ TAG_HANDLER_BEGIN(IMG, "IMG,MAP,AREA")
 | 
			
		||||
#if defined(__WXOSX_COCOA__)
 | 
			
		||||
                // Try to find a 2x resolution image with @2x appended before the file extension.
 | 
			
		||||
                wxWindow* win = m_WParser->GetWindowInterface() ? m_WParser->GetWindowInterface()->GetHTMLWindow() : NULL;
 | 
			
		||||
                if (!win && wxTheApp)
 | 
			
		||||
                    win = wxTheApp->GetTopWindow();
 | 
			
		||||
                if (!win)
 | 
			
		||||
                    win = wxApp::GetMainTopWindow();
 | 
			
		||||
                if (win && win->GetContentScaleFactor() > 1.0)
 | 
			
		||||
                {
 | 
			
		||||
                    if (tmp.Find('.') != wxNOT_FOUND)
 | 
			
		||||
 
 | 
			
		||||
@@ -326,7 +326,7 @@ wxBitmap wxWindowsArtProvider::CreateBitmap(const wxArtID& id,
 | 
			
		||||
/*static*/
 | 
			
		||||
wxSize wxArtProvider::GetNativeSizeHint(const wxArtClient& client)
 | 
			
		||||
{
 | 
			
		||||
    const wxWindow* win = wxTheApp ? wxTheApp->GetTopWindow() : NULL;
 | 
			
		||||
    const wxWindow* win = wxApp::GetMainTopWindow();
 | 
			
		||||
    if ( client == wxART_TOOLBAR )
 | 
			
		||||
    {
 | 
			
		||||
        return wxWindow::FromDIP(wxSize(24, 24), win);
 | 
			
		||||
 
 | 
			
		||||
@@ -109,13 +109,13 @@ public:
 | 
			
		||||
 | 
			
		||||
wxCoord wxCursorRefData::GetStandardWidth()
 | 
			
		||||
{
 | 
			
		||||
    const wxWindow* win = wxTheApp ? wxTheApp->GetTopWindow() : NULL;
 | 
			
		||||
    const wxWindow* win = wxApp::GetMainTopWindow();
 | 
			
		||||
    return wxSystemSettings::GetMetric(wxSYS_CURSOR_X, win);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
wxCoord wxCursorRefData::GetStandardHeight()
 | 
			
		||||
{
 | 
			
		||||
    const wxWindow* win = wxTheApp ? wxTheApp->GetTopWindow() : NULL;
 | 
			
		||||
    const wxWindow* win = wxApp::GetMainTopWindow();
 | 
			
		||||
    return wxSystemSettings::GetMetric(wxSYS_CURSOR_Y, win);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -471,7 +471,7 @@ bool wxICOFileHandler::LoadIcon(wxIcon *icon,
 | 
			
		||||
    else
 | 
			
		||||
#endif
 | 
			
		||||
    // were we asked for a large icon?
 | 
			
		||||
    const wxWindow* win = wxTheApp ? wxTheApp->GetTopWindow() : NULL;
 | 
			
		||||
    const wxWindow* win = wxApp::GetMainTopWindow();
 | 
			
		||||
    if ( desiredWidth == wxGetSystemMetrics(SM_CXICON, win) &&
 | 
			
		||||
         desiredHeight == wxGetSystemMetrics(SM_CYICON, win) )
 | 
			
		||||
    {
 | 
			
		||||
@@ -666,7 +666,7 @@ wxSize wxGetHiconSize(HICON hicon)
 | 
			
		||||
    if ( !size.x )
 | 
			
		||||
    {
 | 
			
		||||
        // use default icon size on this hardware
 | 
			
		||||
        const wxWindow* win = wxTheApp ? wxTheApp->GetTopWindow() : NULL;
 | 
			
		||||
        const wxWindow* win = wxApp::GetMainTopWindow();
 | 
			
		||||
        size.x = wxGetSystemMetrics(SM_CXICON, win);
 | 
			
		||||
        size.y = wxGetSystemMetrics(SM_CYICON, win);
 | 
			
		||||
    }
 | 
			
		||||
 
 | 
			
		||||
@@ -69,8 +69,8 @@ HTMLHELP GetHtmlHelpFunction()
 | 
			
		||||
// fall back to the top level app window and then the desktop if it's NULL
 | 
			
		||||
static HWND GetSuitableHWND(wxWindow *win)
 | 
			
		||||
{
 | 
			
		||||
    if ( !win && wxTheApp )
 | 
			
		||||
        win = wxTheApp->GetTopWindow();
 | 
			
		||||
    if ( !win )
 | 
			
		||||
        win = wxApp::GetMainTopWindow();
 | 
			
		||||
 | 
			
		||||
    return win ? GetHwndOf(win) : ::GetDesktopWindow();
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -393,7 +393,7 @@ void wxMessageDialog::AdjustButtonLabels()
 | 
			
		||||
/* static */
 | 
			
		||||
wxFont wxMessageDialog::GetMessageFont()
 | 
			
		||||
{
 | 
			
		||||
    const wxWindow* win = wxTheApp ? wxTheApp->GetTopWindow() : NULL;
 | 
			
		||||
    const wxWindow* win = wxApp::GetMainTopWindow();
 | 
			
		||||
    const wxNativeFontInfo
 | 
			
		||||
        info(wxMSWImpl::GetNonClientMetrics(win).lfMessageFont, win);
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -179,7 +179,7 @@ wxFont wxSystemSettingsNative::GetFont(wxSystemFont index)
 | 
			
		||||
            // for most (simple) controls, e.g. buttons and such but other
 | 
			
		||||
            // controls may prefer to use lfStatusFont or lfCaptionFont if it
 | 
			
		||||
            // is more appropriate for them
 | 
			
		||||
            const wxWindow* win = wxTheApp ? wxTheApp->GetTopWindow() : NULL;
 | 
			
		||||
            const wxWindow* win = wxApp::GetMainTopWindow();
 | 
			
		||||
            const wxNativeFontInfo
 | 
			
		||||
                info(wxMSWImpl::GetNonClientMetrics(win).lfMessageFont, win);
 | 
			
		||||
 | 
			
		||||
@@ -337,7 +337,7 @@ extern wxFont wxGetCCDefaultFont()
 | 
			
		||||
    // font which is also used for the icon titles and not the stock default
 | 
			
		||||
    // GUI font
 | 
			
		||||
    LOGFONT lf;
 | 
			
		||||
    const wxWindow* win = wxTheApp ? wxTheApp->GetTopWindow() : NULL;
 | 
			
		||||
    const wxWindow* win = wxApp::GetMainTopWindow();
 | 
			
		||||
    if ( wxSystemParametersInfo
 | 
			
		||||
           (
 | 
			
		||||
                SPI_GETICONTITLELOGFONT,
 | 
			
		||||
 
 | 
			
		||||
@@ -4236,7 +4236,7 @@ bool wxWindowMSW::HandleEndSession(bool endSession, long logOff)
 | 
			
		||||
        return false;
 | 
			
		||||
 | 
			
		||||
    // only send once
 | 
			
		||||
    if ( (this != wxTheApp->GetTopWindow()) )
 | 
			
		||||
    if ( this != wxApp::GetMainTopWindow() )
 | 
			
		||||
        return false;
 | 
			
		||||
 | 
			
		||||
    wxCloseEvent event(wxEVT_END_SESSION, wxID_ANY);
 | 
			
		||||
@@ -4773,10 +4773,11 @@ static wxSize GetWindowDPI(HWND hwnd)
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/*extern*/
 | 
			
		||||
int wxGetSystemMetrics(int nIndex, const wxWindow* win)
 | 
			
		||||
int wxGetSystemMetrics(int nIndex, const wxWindow* window)
 | 
			
		||||
{
 | 
			
		||||
#if wxUSE_DYNLIB_CLASS
 | 
			
		||||
    const wxWindow* window = (!win && wxTheApp) ? wxTheApp->GetTopWindow() : win;
 | 
			
		||||
    if ( !window )
 | 
			
		||||
        window = wxApp::GetMainTopWindow();
 | 
			
		||||
 | 
			
		||||
    if ( window )
 | 
			
		||||
    {
 | 
			
		||||
@@ -4798,14 +4799,14 @@ int wxGetSystemMetrics(int nIndex, const wxWindow* win)
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
#else
 | 
			
		||||
    wxUnusedVar(win);
 | 
			
		||||
    wxUnusedVar(window);
 | 
			
		||||
#endif // wxUSE_DYNLIB_CLASS
 | 
			
		||||
 | 
			
		||||
    return ::GetSystemMetrics(nIndex);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/*extern*/
 | 
			
		||||
bool wxSystemParametersInfo(UINT uiAction, UINT uiParam, PVOID pvParam, UINT fWinIni, const wxWindow* win)
 | 
			
		||||
bool wxSystemParametersInfo(UINT uiAction, UINT uiParam, PVOID pvParam, UINT fWinIni, const wxWindow* window)
 | 
			
		||||
{
 | 
			
		||||
    // Note that we can't use SystemParametersInfoForDpi() in non-Unicode build
 | 
			
		||||
    // because it always works with wide strings and we'd have to check for all
 | 
			
		||||
@@ -4813,7 +4814,8 @@ bool wxSystemParametersInfo(UINT uiAction, UINT uiParam, PVOID pvParam, UINT fWi
 | 
			
		||||
    // for them, and convert the returned value to ANSI after the call. Instead
 | 
			
		||||
    // of doing all this, just don't use it at all in the deprecated ANSI build.
 | 
			
		||||
#if wxUSE_DYNLIB_CLASS && wxUSE_UNICODE
 | 
			
		||||
    const wxWindow* window = (!win && wxTheApp) ? wxTheApp->GetTopWindow() : win;
 | 
			
		||||
    if ( !window )
 | 
			
		||||
        window = wxApp::GetMainTopWindow();
 | 
			
		||||
 | 
			
		||||
    if ( window )
 | 
			
		||||
    {
 | 
			
		||||
@@ -4838,7 +4840,7 @@ bool wxSystemParametersInfo(UINT uiAction, UINT uiParam, PVOID pvParam, UINT fWi
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
#else
 | 
			
		||||
    wxUnusedVar(win);
 | 
			
		||||
    wxUnusedVar(window);
 | 
			
		||||
#endif // wxUSE_DYNLIB_CLASS
 | 
			
		||||
 | 
			
		||||
    return ::SystemParametersInfo(uiAction, uiParam, pvParam, fWinIni) == TRUE;
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user