Instead of forwarding to these functions from wxDisplay implementation in wxUSE_DISPLAY==0 case, make the functions themselves wrappers around wxDisplay, which may, or not, depending on the platform, have a simpler implementation in wxUSE_DISPLAY==0 case, but is always available in any case. As part of this change, only use src/osx/core/display.cpp in macOS builds, not iOS ones and update the Xcode project accordingly too. This cuts down on code duplication, especially in wxGTK, and facilitates further additions to wxDisplay API.
176 lines
5.3 KiB
C++
176 lines
5.3 KiB
C++
/////////////////////////////////////////////////////////////////////////////
|
|
// Name: wx/private/display.h
|
|
// Purpose: wxDisplayImpl class declaration
|
|
// Author: Vadim Zeitlin
|
|
// Created: 2006-03-15
|
|
// Copyright: (c) 2002-2006 Vadim Zeitlin <vadim@wxwindows.org>
|
|
// Licence: wxWindows licence
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
|
#ifndef _WX_PRIVATE_DISPLAY_H_
|
|
#define _WX_PRIVATE_DISPLAY_H_
|
|
|
|
#include "wx/display.h"
|
|
#include "wx/gdicmn.h" // for wxRect
|
|
#include "wx/vector.h"
|
|
|
|
// ----------------------------------------------------------------------------
|
|
// wxDisplayFactory: allows to create wxDisplay objects
|
|
// ----------------------------------------------------------------------------
|
|
|
|
class WXDLLIMPEXP_CORE wxDisplayFactory
|
|
{
|
|
public:
|
|
wxDisplayFactory() { }
|
|
virtual ~wxDisplayFactory();
|
|
|
|
// Create the display if necessary using CreateDisplay(), otherwise just
|
|
// get it from cache.
|
|
wxDisplayImpl* GetDisplay(unsigned n)
|
|
{
|
|
if ( m_impls.empty() )
|
|
m_impls.resize(GetCount());
|
|
else if ( m_impls[n] )
|
|
return m_impls[n];
|
|
|
|
m_impls[n] = CreateDisplay(n);
|
|
return m_impls[n];
|
|
}
|
|
|
|
// get the total number of displays
|
|
virtual unsigned GetCount() = 0;
|
|
|
|
// return the display for the given point or wxNOT_FOUND
|
|
virtual int GetFromPoint(const wxPoint& pt) = 0;
|
|
|
|
// return the display for the given window or wxNOT_FOUND
|
|
//
|
|
// the window pointer must not be NULL (i.e. caller should check it)
|
|
virtual int GetFromWindow(const wxWindow *window);
|
|
|
|
protected:
|
|
// create a new display object
|
|
//
|
|
// it can return a NULL pointer if the display creation failed
|
|
virtual wxDisplayImpl *CreateDisplay(unsigned n) = 0;
|
|
|
|
private:
|
|
// On-demand populated vector of wxDisplayImpl objects.
|
|
wxVector<wxDisplayImpl*> m_impls;
|
|
|
|
wxDECLARE_NO_COPY_CLASS(wxDisplayFactory);
|
|
};
|
|
|
|
// ----------------------------------------------------------------------------
|
|
// wxDisplayImpl: base class for all wxDisplay implementations
|
|
// ----------------------------------------------------------------------------
|
|
|
|
class WXDLLIMPEXP_CORE wxDisplayImpl
|
|
{
|
|
public:
|
|
// virtual dtor for this base class
|
|
virtual ~wxDisplayImpl() { }
|
|
|
|
|
|
// return the full area of this display
|
|
virtual wxRect GetGeometry() const = 0;
|
|
|
|
// return the area of the display available for normal windows
|
|
virtual wxRect GetClientArea() const { return GetGeometry(); }
|
|
|
|
// return the name (may be empty)
|
|
virtual wxString GetName() const = 0;
|
|
|
|
// return the index of this display
|
|
unsigned GetIndex() const { return m_index; }
|
|
|
|
// return true if this is the primary monitor (usually one with index 0)
|
|
virtual bool IsPrimary() const { return GetIndex() == 0; }
|
|
|
|
|
|
#if wxUSE_DISPLAY
|
|
// implements wxDisplay::GetModes()
|
|
virtual wxArrayVideoModes GetModes(const wxVideoMode& mode) const = 0;
|
|
|
|
// get current video mode
|
|
virtual wxVideoMode GetCurrentMode() const = 0;
|
|
|
|
// change current mode, return true if succeeded, false otherwise
|
|
virtual bool ChangeMode(const wxVideoMode& mode) = 0;
|
|
#endif // wxUSE_DISPLAY
|
|
|
|
protected:
|
|
// create the object providing access to the display with the given index
|
|
wxDisplayImpl(unsigned n) : m_index(n) { }
|
|
|
|
|
|
// the index of this display (0 is always the primary one)
|
|
const unsigned m_index;
|
|
|
|
|
|
friend class wxDisplayFactory;
|
|
|
|
wxDECLARE_NO_COPY_CLASS(wxDisplayImpl);
|
|
};
|
|
|
|
// ----------------------------------------------------------------------------
|
|
// wxDisplayImplSingle: the simplest possible impl for the main display only
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// Note that this is still an ABC and GetGeometry() and GetClientArea() methods
|
|
// must be implemented in the derived classes.
|
|
|
|
class WXDLLEXPORT wxDisplayImplSingle : public wxDisplayImpl
|
|
{
|
|
public:
|
|
wxDisplayImplSingle() : wxDisplayImpl(0) { }
|
|
|
|
virtual wxString GetName() const wxOVERRIDE { return wxString(); }
|
|
|
|
#if wxUSE_DISPLAY
|
|
// no video modes support for us, provide just the stubs
|
|
virtual wxArrayVideoModes
|
|
GetModes(const wxVideoMode& WXUNUSED(mode)) const wxOVERRIDE
|
|
{
|
|
return wxArrayVideoModes();
|
|
}
|
|
|
|
virtual wxVideoMode GetCurrentMode() const wxOVERRIDE
|
|
{
|
|
return wxVideoMode();
|
|
}
|
|
|
|
virtual bool ChangeMode(const wxVideoMode& WXUNUSED(mode)) wxOVERRIDE
|
|
{
|
|
return false;
|
|
}
|
|
#endif // wxUSE_DISPLAY
|
|
|
|
wxDECLARE_NO_COPY_CLASS(wxDisplayImplSingle);
|
|
};
|
|
|
|
// ----------------------------------------------------------------------------
|
|
// wxDisplayFactorySingle
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// This is the simplest implementation of wxDisplayFactory using single/main
|
|
// display only. It is used when wxUSE_DISPLAY == 0 because getting the size of
|
|
// the main display is always needed.
|
|
//
|
|
// Note that this is still an ABC and derived classes must implement
|
|
// CreateSingleDisplay().
|
|
|
|
class WXDLLIMPEXP_CORE wxDisplayFactorySingle : public wxDisplayFactory
|
|
{
|
|
public:
|
|
virtual unsigned GetCount() wxOVERRIDE { return 1; }
|
|
virtual int GetFromPoint(const wxPoint& pt) wxOVERRIDE;
|
|
|
|
protected:
|
|
virtual wxDisplayImpl *CreateDisplay(unsigned n) wxOVERRIDE;
|
|
|
|
virtual wxDisplayImpl *CreateSingleDisplay() = 0;
|
|
};
|
|
|
|
#endif // _WX_PRIVATE_DISPLAY_H_
|