1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214
|
/////////////////////////////////////////////////////////////////////////////
// Name: wx/private/display.h
// Purpose: wxDisplayImpl class declaration
// Author: Vadim Zeitlin
// Created: 2006-03-15
// Copyright: (c) 2002-2006 Vadim Zeitlin <vadim@wxwidgets.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 wxDisplayFactory
{
public:
wxDisplayFactory() { }
virtual ~wxDisplayFactory() { ClearImpls(); }
// Create the display if necessary using CreateDisplay(), otherwise just
// get it from cache.
wxDisplayImpl* GetDisplay(unsigned n)
{
// Normally, m_impls should be cleared if the number of displays in the
// system changes because InvalidateCache() must be called. However in
// some ports (e.g. Mac right now, see #18318), cache invalidation never
// happens, so we can end up with m_impls size being out of sync with
// the actual number of monitors. Compensate for this here by checking
// if the index is invalid and invalidating the cache at least in this
// case.
//
// Note that this is still incorrect because we continue using outdated
// information if the first monitor is disconnected, for example. The
// only real solution is to ensure that InvalidateCache() is called,
// but for now this at least avoids crashes when a new display is
// connected.
if ( n >= m_impls.size() )
{
// This strange two-step resize is done to clear all the existing
// elements: they may not be valid any longer if the number of
// displays has changed.
m_impls.resize(0);
m_impls.resize(GetCount());
}
else if ( m_impls[n] )
{
// Just return the existing display if we have it.
return m_impls[n];
}
m_impls[n] = CreateDisplay(n);
return m_impls[n];
}
// Return the primary display object, creating it if necessary.
wxDisplayImpl* GetPrimaryDisplay();
// 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);
// Trigger recreation of wxDisplayImpl when they're needed the next time.
virtual void InvalidateCache() { ClearImpls(); }
protected:
// create a new display object
//
// it can return a NULL pointer if the display creation failed
virtual wxDisplayImpl *CreateDisplay(unsigned n) = 0;
private:
// Delete all the elements of m_impls vector and clear it.
void ClearImpls();
// On-demand populated vector of wxDisplayImpl objects.
wxVector<wxDisplayImpl*> m_impls;
wxDECLARE_NO_COPY_CLASS(wxDisplayFactory);
};
// ----------------------------------------------------------------------------
// wxDisplayImpl: base class for all wxDisplay implementations
// ----------------------------------------------------------------------------
class 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 depth or 0 if unknown
virtual int GetDepth() const = 0;
// return the scale factor used to convert logical pixels to physical ones
virtual double GetScaleFactor() const { return 1.0; }
// return the resolution of the display, by default uses GetScaleFactor(),
// but can be also overridden directly, as is done in wxMSW
virtual wxSize GetPPI() const { return wxDisplay::GetStdPPI()*GetScaleFactor(); }
// return the name (may be empty)
virtual wxString GetName() const { return wxString(); }
// 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) { }
#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 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_
|