From e3e883bbd226c9fe6308b47e5842940129cc9f5f Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Sat, 6 Oct 2018 16:14:45 +0200 Subject: [PATCH] Implement wxColourDisplay() in terms of wxDisplay::GetDepth() Get rid of another global display-related function, even though this one only had non-trivial implementation under MSW. --- interface/wx/gdicmn.h | 4 ++++ src/common/gdicmn.cpp | 7 +++++++ src/dfb/utils.cpp | 6 ------ src/gtk/utilsgtk.cpp | 5 ----- src/gtk1/utilsgtk.cpp | 5 ----- src/motif/utils.cpp | 6 ------ src/msw/utilsgui.cpp | 21 --------------------- src/osx/utils_osx.cpp | 8 -------- src/qt/utils.cpp | 5 ----- src/x11/utils.cpp | 6 ------ 10 files changed, 11 insertions(+), 62 deletions(-) diff --git a/interface/wx/gdicmn.h b/interface/wx/gdicmn.h index fc27e066d9..2033b5461d 100644 --- a/interface/wx/gdicmn.h +++ b/interface/wx/gdicmn.h @@ -1183,6 +1183,10 @@ const wxSize wxDefaultSize; /** Returns @true if the display is colour, @false otherwise. + @note Use of this function is not recommended in the new code as it only + works for the primary display. Use wxDisplay::GetDepth() to retrieve + the depth of the appropriate display and compare it with 1 instead. + @header{wx/gdicmn.h} */ bool wxColourDisplay(); diff --git a/src/common/gdicmn.cpp b/src/common/gdicmn.cpp index 22ba30ef37..a584eccc5f 100644 --- a/src/common/gdicmn.cpp +++ b/src/common/gdicmn.cpp @@ -850,6 +850,13 @@ int wxDisplayDepth() return wxDisplay().GetDepth(); } +bool wxColourDisplay() +{ + // If GetDepth() returns 0, meaning unknown, we assume it's a colour + // display, hence the use of "!=" rather than ">" here. + return wxDisplay().GetDepth() != 1; +} + void wxDisplaySize(int *width, int *height) { const wxSize size = wxGetDisplaySize(); diff --git a/src/dfb/utils.cpp b/src/dfb/utils.cpp index 7226d63002..b4e97dc727 100644 --- a/src/dfb/utils.cpp +++ b/src/dfb/utils.cpp @@ -89,12 +89,6 @@ wxDisplayFactory* wxDisplay::CreateFactory() return new wxDisplayFactorySingleDFB; } -bool wxColourDisplay() -{ - #warning "FIXME: wxColourDisplay" - return true; -} - void wxDisplaySizeMM(int *width, int *height) { // FIXME: there's no way to get physical resolution using the DirectDB diff --git a/src/gtk/utilsgtk.cpp b/src/gtk/utilsgtk.cpp index 2ce561ff13..f0a36126f1 100644 --- a/src/gtk/utilsgtk.cpp +++ b/src/gtk/utilsgtk.cpp @@ -90,11 +90,6 @@ void wxDisplaySizeMM( int *width, int *height ) #endif } -bool wxColourDisplay() -{ - return true; -} - wxWindow* wxFindWindowAtPoint(const wxPoint& pt) { return wxGenericFindWindowAtPoint(pt); diff --git a/src/gtk1/utilsgtk.cpp b/src/gtk1/utilsgtk.cpp index c027686ad5..bdcadfa5e7 100644 --- a/src/gtk1/utilsgtk.cpp +++ b/src/gtk1/utilsgtk.cpp @@ -97,11 +97,6 @@ void wxGetMousePosition( int* x, int* y ) gdk_window_get_pointer( NULL, x, y, NULL ); } -bool wxColourDisplay() -{ - return true; -} - wxWindow* wxFindWindowAtPoint(const wxPoint& pt) { return wxGenericFindWindowAtPoint(pt); diff --git a/src/motif/utils.cpp b/src/motif/utils.cpp index 621b89cc27..87a1af7da0 100644 --- a/src/motif/utils.cpp +++ b/src/motif/utils.cpp @@ -225,12 +225,6 @@ void wxGetMousePosition( int* x, int* y ) #endif } -// Return true if we have a colour display -bool wxColourDisplay() -{ - return wxDisplayDepth() > 1; -} - void wxDisplaySizeMM(int *width, int *height) { Display *dpy = wxGlobalDisplay(); diff --git a/src/msw/utilsgui.cpp b/src/msw/utilsgui.cpp index a475bc6290..9ac17ef4b1 100644 --- a/src/msw/utilsgui.cpp +++ b/src/msw/utilsgui.cpp @@ -117,27 +117,6 @@ void wxGetMousePosition( int* x, int* y ) if ( y ) *y = pt.y; } -// Return true if we have a colour display -bool wxColourDisplay() -{ - // this function is called from wxDC ctor so it is called a *lot* of times - // hence we optimize it a bit but doing the check only once - // - // this should be MT safe as only the GUI thread (holding the GUI mutex) - // can call us - static int s_isColour = -1; - - if ( s_isColour == -1 ) - { - ScreenHDC dc; - int noCols = ::GetDeviceCaps(dc, NUMCOLORS); - - s_isColour = (noCols == -1) || (noCols > 2); - } - - return s_isColour != 0; -} - void wxDisplaySizeMM(int *width, int *height) { ScreenHDC dc; diff --git a/src/osx/utils_osx.cpp b/src/osx/utils_osx.cpp index d53c47f753..b1c1975997 100644 --- a/src/osx/utils_osx.cpp +++ b/src/osx/utils_osx.cpp @@ -53,14 +53,6 @@ bool wxCheckForInterrupt(wxWindow *WXUNUSED(wnd)) return false; } -// Return true if we have a colour display -bool wxColourDisplay() -{ - // always the case on OS X - return true; -} - - #if wxOSX_USE_COCOA_OR_CARBON #if wxUSE_GUI diff --git a/src/qt/utils.cpp b/src/qt/utils.cpp index bcaedc95e2..fb6dce807e 100644 --- a/src/qt/utils.cpp +++ b/src/qt/utils.cpp @@ -140,11 +140,6 @@ wxWindow *wxGetActiveWindow() return NULL; } -bool wxColourDisplay() -{ - return QApplication::desktop()->depth() > 1; -} - bool wxLaunchDefaultApplication(const wxString& path, int WXUNUSED( flags ) ) { return QDesktopServices::openUrl( QUrl::fromLocalFile( wxQtConvertString( path ) ) ); diff --git a/src/x11/utils.cpp b/src/x11/utils.cpp index 7a917354ab..a5d71d4046 100644 --- a/src/x11/utils.cpp +++ b/src/x11/utils.cpp @@ -148,12 +148,6 @@ void wxGetMousePosition( int* x, int* y ) #endif }; -// Return true if we have a colour display -bool wxColourDisplay() -{ - return wxDisplayDepth() > 1; -} - void wxDisplaySizeMM(int *width, int *height) { Display *dpy = (Display*) wxGetDisplay();