wxDisplay cleanup/rewrite:

- wxDisplay is now a concrete class and uses a pImpl-based design
- got rid of four duplicate but subtly different versions of trivial
  single display-only wxDisplay implementation (but 2 versions of Mac
  Classic and Mac CoreGraphics implementations each still remain...)
- assorted code simplifications and memory leaks fixes


git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@38127 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Vadim Zeitlin
2006-03-16 04:23:07 +00:00
parent 8072477d51
commit ef1717a963
23 changed files with 1739 additions and 2073 deletions

View File

@@ -1,45 +0,0 @@
/////////////////////////////////////////////////////////////////////////////
// Name: include/wx/cocoa/display.h
// Purpose: wxDisplay class for wxCocoa
// Author: Ryan Norton
// Modified by:
// Created: 2004-10-03
// RCS-ID: $Id$
// Copyright: (c) Ryan Norton
// Licence: wxWindows licence
/////////////////////////////////////////////////////////////////////////////
#ifndef _WX_COCOA_DISPLAY_H_
#define _WX_COCOA_DISPLAY_H_
#include "wx/object.h"
#include "wx/display.h"
class wxRect;
class wxString;
class WXDLLEXPORT wxDisplay : public wxDisplayBase
{
public:
wxDisplay ( size_t index = 0 );
~wxDisplay();
virtual wxRect GetGeometry() const;
virtual int GetDepth() const;
virtual wxString GetName() const;
virtual wxArrayVideoModes
GetModes(const wxVideoMode& mode = wxDefaultVideoMode) const;
virtual wxVideoMode GetCurrentMode() const;
virtual bool ChangeMode(const wxVideoMode& mode = wxDefaultVideoMode);
private:
struct _CGDirectDisplayID * m_id;
DECLARE_NO_COPY_CLASS(wxDisplay)
};
#endif // _WX_COCOA_DISPLAY_H_

View File

@@ -1,37 +1,43 @@
///////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////
// Name: wx/display.h // Name: wx/display.h
// Purpose: wxDisplay class // Purpose: wxDisplay class
// Author: Royce Mitchell III // Author: Royce Mitchell III, Vadim Zeitlin
// Modified by: Vadim Zeitlin (resolution changes, display modes, ...)
// Created: 06/21/02 // Created: 06/21/02
// RCS-ID: $Id$ // RCS-ID: $Id$
// Copyright: (c) 2002-2003 wxWidgets team // Copyright: (c) 2002-2006 wxWidgets team
// Licence: wxWindows licence // Licence: wxWindows licence
///////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////
#ifndef _WX_DISPLAY_H_BASE_ #ifndef _WX_DISPLAY_H_BASE_
#define _WX_DISPLAY_H_BASE_ #define _WX_DISPLAY_H_BASE_
#if wxUSE_DISPLAY // NB: no #if wxUSE_DISPLAY here, the display geometry part of this class (but
// not the video mode stuff) is always available but if wxUSE_DISPLAY == 0
// it becomes just a trivial wrapper around the old wxDisplayXXX() functions
#include "wx/dynarray.h" #if wxUSE_DISPLAY
#include "wx/vidmode.h" #include "wx/dynarray.h"
#include "wx/vidmode.h"
WX_DECLARE_EXPORTED_OBJARRAY(wxVideoMode, wxArrayVideoModes);
// default, uninitialized, video mode object
extern WXDLLEXPORT_DATA(const wxVideoMode) wxDefaultVideoMode;
#endif // wxUSE_DISPLAY
class WXDLLEXPORT wxWindow; class WXDLLEXPORT wxWindow;
class WXDLLEXPORT wxPoint; class WXDLLEXPORT wxPoint;
class WXDLLEXPORT wxRect; class WXDLLEXPORT wxRect;
class WXDLLEXPORT wxString; class WXDLLEXPORT wxString;
WX_DECLARE_EXPORTED_OBJARRAY(wxVideoMode, wxArrayVideoModes); class WXDLLEXPORT wxDisplayFactory;
class WXDLLEXPORT wxDisplayImpl;
// default, uninitialized, video mode object
extern WXDLLEXPORT_DATA(const wxVideoMode) wxDefaultVideoMode;
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
// wxDisplayBase: represents a display/monitor attached to the system // wxDisplay: represents a display/monitor attached to the system
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
class WXDLLEXPORT wxDisplayBase class WXDLLEXPORT wxDisplay
{ {
public: public:
// initialize the object containing all information about the given // initialize the object containing all information about the given
@@ -39,7 +45,12 @@ public:
// //
// the displays are numbered from 0 to GetCount() - 1, 0 is always the // the displays are numbered from 0 to GetCount() - 1, 0 is always the
// primary display and the only one which is always supported // primary display and the only one which is always supported
wxDisplayBase(size_t index = 0); wxDisplay(size_t n = 0);
// dtor is not virtual as this is a concrete class not meant to be derived
// from
~wxDisplay();
// return the number of available displays, valid parameters to // return the number of available displays, valid parameters to
// wxDisplay ctor are from 0 up to this number // wxDisplay ctor are from 0 up to this number
@@ -55,18 +66,19 @@ public:
// return true if the object was initialized successfully // return true if the object was initialized successfully
virtual bool IsOk() const { return true; } bool IsOk() const { return m_impl != NULL; }
// get the display size // get the display size
virtual wxRect GetGeometry() const = 0; wxRect GetGeometry() const;
// name may be empty // name may be empty
virtual wxString GetName() const = 0; wxString GetName() const;
// display 0 is usually the primary display // display 0 is usually the primary display
virtual bool IsPrimary() const { return m_index == 0; } bool IsPrimary() const;
#if wxUSE_DISPLAY
// enumerate all video modes supported by this display matching the given // enumerate all video modes supported by this display matching the given
// one (in the sense of wxVideoMode::Match()) // one (in the sense of wxVideoMode::Match())
// //
@@ -74,49 +86,40 @@ public:
// always at least one video mode supported by display, the returned array // always at least one video mode supported by display, the returned array
// is only empty for the default value of the argument if this function is // is only empty for the default value of the argument if this function is
// not supported at all on this platform // not supported at all on this platform
virtual wxArrayVideoModes wxArrayVideoModes
GetModes(const wxVideoMode& mode = wxDefaultVideoMode) const = 0; GetModes(const wxVideoMode& mode = wxDefaultVideoMode) const;
// get current video mode // get current video mode
virtual wxVideoMode GetCurrentMode() const = 0; wxVideoMode GetCurrentMode() const;
// change current mode, return true if succeeded, false otherwise // change current mode, return true if succeeded, false otherwise
// //
// for the default value of the argument restores the video mode to default // for the default value of the argument restores the video mode to default
virtual bool ChangeMode(const wxVideoMode& mode = wxDefaultVideoMode) = 0; bool ChangeMode(const wxVideoMode& mode = wxDefaultVideoMode);
// restore the default video mode (just a more readable synonym) // restore the default video mode (just a more readable synonym)
void ResetMode() { (void)ChangeMode(); } void ResetMode() { (void)ChangeMode(); }
// virtual dtor as for any base class
virtual ~wxDisplayBase() { }
protected:
// the index of this display (0 is always the primary one)
size_t m_index;
DECLARE_NO_COPY_CLASS(wxDisplayBase)
};
#if defined(__WXMSW__)
#include "wx/msw/display.h"
#elif defined(__WXMOTIF__)
#include "wx/unix/displayx11.h"
#elif defined(__WXGTK__)
#include "wx/unix/displayx11.h"
#elif defined(__WXX11__)
#include "wx/unix/displayx11.h"
#elif defined(__WXCOCOA__)
#include "wx/cocoa/display.h"
#elif defined(__WXMAC__)
#include "wx/mac/display.h"
#elif defined(__WXPM__)
#include "wx/os2/display.h"
#elif defined(__WXMGL__)
#include "wx/mgl/display.h"
#endif
#endif // wxUSE_DISPLAY #endif // wxUSE_DISPLAY
private:
// returns the factory used to implement our static methods and create new
// displays
static wxDisplayFactory& Factory();
// creates the factory object, called by Factory() when it is called for
// the first time and should return a pointer allocated with new (the
// caller will delete it)
//
// this method must be implemented in platform-specific code if
// wxUSE_DISPLAY == 1 (if it is 0 we provide the stub in common code)
static wxDisplayFactory *CreateFactory();
// the real implementation
wxDisplayImpl *m_impl;
DECLARE_NO_COPY_CLASS(wxDisplay)
};
#endif // _WX_DISPLAY_H_BASE_ #endif // _WX_DISPLAY_H_BASE_

105
include/wx/display_impl.h Normal file
View File

@@ -0,0 +1,105 @@
/////////////////////////////////////////////////////////////////////////////
// Name: wx/display_impl.h
// Purpose: wxDisplayImpl class declaration
// Author: Vadim Zeitlin
// Created: 2006-03-15
// RCS-ID: $Id$
// Copyright: (c) 2002-2006 Vadim Zeitlin <vadim@wxwindows.org>
// Licence: wxWindows licence
/////////////////////////////////////////////////////////////////////////////
#ifndef _WX_DISPLAY_IMPL_H_BASE_
#define _WX_DISPLAY_IMPL_H_BASE_
// ----------------------------------------------------------------------------
// wxDisplayFactory: allows to create wxDisplay objects
// ----------------------------------------------------------------------------
class WXDLLEXPORT wxDisplayFactory
{
public:
wxDisplayFactory() { }
virtual ~wxDisplayFactory() { }
// create a new display object
//
// it can return a NULL pointer if the display creation failed
virtual wxDisplayImpl *CreateDisplay(size_t n) = 0;
// get the total number of displays
virtual size_t 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(wxWindow *window);
};
// ----------------------------------------------------------------------------
// wxDisplayImpl: base class for all wxDisplay implementations
// ----------------------------------------------------------------------------
class WXDLLEXPORT wxDisplayImpl
{
public:
// virtual dtor for this base class
virtual ~wxDisplayImpl() { }
// return the full area of this display
virtual wxRect GetGeometry() const = 0;
// return the name (may be empty)
virtual wxString GetName() const = 0;
// return the index of this display
size_t 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(size_t n) : m_index(n) { }
// the index of this display (0 is always the primary one)
const size_t m_index;
friend class wxDisplayFactory;
DECLARE_NO_COPY_CLASS(wxDisplayImpl)
};
// ----------------------------------------------------------------------------
// wxDisplayFactorySingle
// ----------------------------------------------------------------------------
// this is a stub implementation using single/main display only, it is
// available even if wxUSE_DISPLAY == 0
class WXDLLEXPORT wxDisplayFactorySingle : public wxDisplayFactory
{
public:
virtual wxDisplayImpl *CreateDisplay(size_t n);
virtual size_t GetCount() { return 1; }
virtual int GetFromPoint(const wxPoint& pt);
};
#endif // _WX_DISPLAY_IMPL_H_BASE_

View File

@@ -1,46 +0,0 @@
/////////////////////////////////////////////////////////////////////////////
// Name: display.h
// Purpose: wxDisplay class customization for Mac
// Author: Brian Victor/Royce Mitchel for non OSX / Ryan Norton for OS X
// Modified by:
// Created: 06/21/02
// RCS-ID: $Id$
// Copyright: (c) wxWidgets team
// Licence: wxWindows licence
/////////////////////////////////////////////////////////////////////////////
#ifndef _WX_MAC_DISPLAY_H_
#define _WX_MAC_DISPLAY_H_
#include "wx/object.h"
#include "wx/display.h"
class wxDisplayMacPriv;
class wxRect;
class wxString;
class WXDLLEXPORT wxDisplay : public wxDisplayBase
{
public:
wxDisplay ( size_t index = 0 );
~wxDisplay();
virtual wxRect GetGeometry() const;
virtual int GetDepth() const;
virtual wxString GetName() const;
virtual wxArrayVideoModes
GetModes(const wxVideoMode& mode = wxDefaultVideoMode) const;
virtual wxVideoMode GetCurrentMode() const;
virtual bool ChangeMode(const wxVideoMode& mode = wxDefaultVideoMode);
private:
wxDisplayMacPriv* m_priv;
DECLARE_NO_COPY_CLASS(wxDisplay)
};
#endif // _WX_MAC_DISPLAY_H_

View File

@@ -1,46 +0,0 @@
/////////////////////////////////////////////////////////////////////////////
// Name: display.h
// Purpose: wxDisplay class customization for Mac
// Author: Brian Victor
// Modified by: Royce Mitchell III
// Created: 06/21/02
// RCS-ID: $Id$
// Copyright: (c) wxWidgets team
// Licence: wxWindows licence
/////////////////////////////////////////////////////////////////////////////
#ifndef _WX_MAC_DISPLAY_H_
#define _WX_MAC_DISPLAY_H_
#include "wx/object.h"
#include "wx/display.h"
class wxDisplayMacPriv;
class wxRect;
class wxString;
class WXDLLEXPORT wxDisplay : public wxDisplayBase
{
public:
wxDisplay ( size_t index = 0 );
~wxDisplay();
virtual wxRect GetGeometry() const;
virtual int GetDepth() const;
virtual wxString GetName() const;
virtual wxArrayVideoModes
GetModes(const wxVideoMode& mode = wxDefaultVideoMode) const;
virtual wxVideoMode GetCurrentMode() const;
virtual bool ChangeMode(const wxVideoMode& mode = wxDefaultVideoMode);
private:
wxDisplayMacPriv* m_priv;
DECLARE_NO_COPY_CLASS(wxDisplay)
};
#endif // _WX_MAC_DISPLAY_H_

View File

@@ -1,5 +0,0 @@
#ifdef __WXMAC_CLASSIC__
#include "wx/mac/classic/display.h"
#else
#include "wx/mac/carbon/display.h"
#endif

View File

@@ -56,6 +56,11 @@
# define wxUSE_CLIPBOARD 0 # define wxUSE_CLIPBOARD 0
#endif /* wxUSE_CLIPBOARD */ #endif /* wxUSE_CLIPBOARD */
#if wxUSE_DISPLAY
# undef wxUSE_DISPLAY
# define wxUSE_DISPLAY 0
#endif /* wxUSE_DISPLAY */
#if wxUSE_SOCKETS #if wxUSE_SOCKETS
# undef wxUSE_SOCKETS # undef wxUSE_SOCKETS
# define wxUSE_SOCKETS 0 # define wxUSE_SOCKETS 0

View File

@@ -1,40 +0,0 @@
/////////////////////////////////////////////////////////////////////////////
// Name: wx/mgl/display.h
// Purpose: wxDisplay class customization for WXMGL
// Author: Wlodzimierz ABX Skiba
// Modified by:
// Created: 05/03/2006
// RCS-ID: $Id$
// Copyright: (c) Wlodzimierz Skiba
// Licence: wxWindows licence
/////////////////////////////////////////////////////////////////////////////
#ifndef _WX_MGL_DISPLAY_H_
#define _WX_MGL_DISPLAY_H_
class WXDLLEXPORT wxDisplay : public wxDisplayBase
{
public:
// create the display object for the given physical display
wxDisplay(size_t index = 0);
virtual ~wxDisplay();
// implement base class pure virtuals
virtual bool IsOk() const;
virtual wxRect GetGeometry() const;
virtual wxString GetName() const;
virtual wxArrayVideoModes GetModes(const wxVideoMode& mode = wxDefaultVideoMode) const;
virtual wxVideoMode GetCurrentMode() const;
virtual bool ChangeMode(const wxVideoMode& mode = wxDefaultVideoMode);
virtual bool IsPrimary() const;
private:
DECLARE_NO_COPY_CLASS(wxDisplay)
};
#endif // _WX_MGL_DISPLAY_H_

View File

@@ -1,51 +0,0 @@
/////////////////////////////////////////////////////////////////////////////
// Name: display.h
// Purpose: wxDisplay class customization for WXMSW
// Author: Royce Mitchell III
// Modified by:
// Created: 06/21/02
// RCS-ID: $Id$
// Copyright: (c) wxWidgets team
// Licence: wxWindows licence
/////////////////////////////////////////////////////////////////////////////
#ifndef _WX_MSW_DISPLAY_H_
#define _WX_MSW_DISPLAY_H_
class WXDLLEXPORT wxDisplay : public wxDisplayBase
{
public:
// this function may be called *before* using any other wxDisplay methods
// to tell it to use DirectX functions instead of the standard Windows ones
static void UseDirectX(bool useDX);
// create the display object for the given physical display
wxDisplay(size_t index = 0);
virtual ~wxDisplay();
// implement base class pure virtuals
virtual bool IsOk() const;
virtual wxRect GetGeometry() const;
virtual wxString GetName() const;
virtual wxArrayVideoModes
GetModes(const wxVideoMode& mode = wxVideoMode()) const;
virtual wxVideoMode GetCurrentMode() const;
virtual bool ChangeMode(const wxVideoMode& mode = wxVideoMode());
virtual bool IsPrimary() const;
private:
// we have different implementations using DirectDraw and without it
wxArrayVideoModes DoGetModesDirectX(const wxVideoMode& modeMatch) const;
bool DoChangeModeDirectX(const wxVideoMode& mode);
wxArrayVideoModes DoGetModesWindows(const wxVideoMode& modeMatch) const;
bool DoChangeModeWindows(const wxVideoMode& mode);
DECLARE_NO_COPY_CLASS(wxDisplay)
};
#endif // _WX_MSW_DISPLAY_H_

View File

@@ -21,6 +21,11 @@
to disable here features not supported currently or enable to disable here features not supported currently or enable
features required */ features required */
#if wxUSE_DISPLAY
# undef wxUSE_DISPLAY
# define wxUSE_DISPLAY 0
#endif /* wxUSE_DISPLAY */
#if wxUSE_STACKWALKER #if wxUSE_STACKWALKER
# undef wxUSE_STACKWALKER # undef wxUSE_STACKWALKER
# define wxUSE_STACKWALKER 0 # define wxUSE_STACKWALKER 0

View File

@@ -1,44 +0,0 @@
/////////////////////////////////////////////////////////////////////////////
// Name: displayx11.h
// Purpose: wxDisplay class for Unix/X11
// Author: Brian Victor
// Modified by:
// Created: 12/05/02
// RCS-ID: $Id$
// Copyright: (c) wxWidgets team
// Licence: wxWindows licence
/////////////////////////////////////////////////////////////////////////////
#ifndef _WX_DISPLAY_H_
#define _WX_DISPLAY_H_
#if wxUSE_DISPLAY
class wxRect;
class wxString;
class wxDisplayUnixPriv;
class WXDLLEXPORT wxDisplay : public wxDisplayBase
{
public:
wxDisplay (size_t index = 0);
~wxDisplay();
virtual wxRect GetGeometry() const;
virtual int GetDepth() const;
virtual wxString GetName() const;
virtual wxArrayVideoModes GetModes(const wxVideoMode& mode = wxDefaultVideoMode) const;
virtual wxVideoMode GetCurrentMode() const;
virtual bool ChangeMode(const wxVideoMode& mode = wxDefaultVideoMode);
private:
DECLARE_NO_COPY_CLASS(wxDisplay)
};
#endif // wxUSE_DISPLAY
#endif // _WX_DISPLAY_H_

View File

@@ -52,6 +52,9 @@
#undef wxUSE_CLIPBOARD #undef wxUSE_CLIPBOARD
#define wxUSE_CLIPBOARD 0 #define wxUSE_CLIPBOARD 0
#undef wxUSE_DISPLAY
#define wxUSE_DISPLAY 0
#undef wxUSE_COMBOBOX #undef wxUSE_COMBOBOX
#define wxUSE_COMBOBOX 0 #define wxUSE_COMBOBOX 0

View File

@@ -1,52 +0,0 @@
/////////////////////////////////////////////////////////////////////////////
// Name: wx/palmos/display.h
// Purpose: wxDisplay class customization for Palm OS
// Author: William Osborne - minimal working wxPalmOS port
// Modified by:
// Created: 10/13/04
// RCS-ID: $Id$
// Copyright: (c) William Osborne
// Licence: wxWindows licence
/////////////////////////////////////////////////////////////////////////////
#ifndef _WX_PALMOS_DISPLAY_H_
#define _WX_PALMOS_DISPLAY_H_
class WXDLLEXPORT wxDisplay : public wxDisplayBase
{
public:
// this function may be called *before* using any other wxDisplay methods
// to tell it to use DirectX functions instead of the standard Windows ones
static void UseDirectX(bool useDX);
// create the display object for the given physical display
wxDisplay(size_t index = 0);
virtual ~wxDisplay();
// implement base class pure virtuals
virtual bool IsOk() const;
virtual wxRect GetGeometry() const;
virtual wxString GetName() const;
virtual wxArrayVideoModes
GetModes(const wxVideoMode& mode = wxVideoMode()) const;
virtual wxVideoMode GetCurrentMode() const;
virtual bool ChangeMode(const wxVideoMode& mode = wxVideoMode());
private:
// get the display name to use with EnumDisplaySettings()
wxString GetNameForEnumSettings() const;
// we have different implementations using DirectDraw and without it
wxArrayVideoModes DoGetModesDirectX(const wxVideoMode& modeMatch) const;
bool DoChangeModeDirectX(const wxVideoMode& mode);
wxArrayVideoModes DoGetModesWindows(const wxVideoMode& modeMatch) const;
bool DoChangeModeWindows(const wxVideoMode& mode);
DECLARE_NO_COPY_CLASS(wxDisplay)
};
#endif // _WX_PALMOS_DISPLAY_H_

View File

@@ -1,48 +0,0 @@
/////////////////////////////////////////////////////////////////////////////
// Name: displayx11.h
// Purpose: wxDisplay class for Unix/X11
// Author: Brian Victor
// Modified by:
// Created: 12/05/02
// RCS-ID: $Id$
// Copyright: (c) wxWidgets team
// Licence: wxWindows licence
/////////////////////////////////////////////////////////////////////////////
#ifndef _WX_DISPLAYX11_H_
#define _WX_DISPLAYX11_H_
#if wxUSE_DISPLAY
class wxRect;
class wxString;
class wxDisplayUnixPriv;
class WXDLLEXPORT wxDisplay : public wxDisplayBase
{
public:
wxDisplay ( size_t index = 0 );
virtual wxRect GetGeometry() const;
virtual int GetDepth() const;
virtual wxString GetName() const;
virtual wxArrayVideoModes
GetModes(const wxVideoMode& mode = wxDefaultVideoMode) const;
virtual wxVideoMode GetCurrentMode() const;
virtual bool ChangeMode(const wxVideoMode& mode = wxDefaultVideoMode);
~wxDisplay();
private:
wxDisplayUnixPriv *m_priv;
DECLARE_NO_COPY_CLASS(wxDisplay)
};
#endif // wxUSE_DISPLAY
#endif // _WX_GTK_DISPLAY_H_

View File

@@ -2,7 +2,7 @@
// Name: src/cocoa/display.mm // Name: src/cocoa/display.mm
// Purpose: Cocoa implementation of wxDisplay class // Purpose: Cocoa implementation of wxDisplay class
// Author: Ryan Norton // Author: Ryan Norton
// Modified by: // Modified by:
// Created: 2004-10-03 // Created: 2004-10-03
// RCS-ID: $Id$ // RCS-ID: $Id$
// Copyright: (c) Ryan Norton // Copyright: (c) Ryan Norton
@@ -23,36 +23,74 @@
#endif #endif
#include "wx/display.h" #include "wx/display.h"
#include "wx/display_impl.h"
#include "wx/gdicmn.h" #include "wx/gdicmn.h"
#include "wx/string.h" #include "wx/string.h"
#import <Foundation/Foundation.h> #import <Foundation/Foundation.h>
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
// private classes // display classes implementation
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
size_t wxDisplayBase::GetCount() class wxDisplayImplMacOSX : public wxDisplayImpl
{
public:
wxDisplayImplMacOSX(CGDirectDisplayID id_) : m_id(id_) { }
virtual wxRect GetGeometry() const;
virtual wxString GetName() const { return wxString(); }
virtual wxArrayVideoModes GetModes(const wxVideoMode& mode) const;
virtual wxVideoMode GetCurrentMode() const;
virtual bool ChangeMode(const wxVideoMode& mode);
private:
CGDirectDisplayID m_id;
DECLARE_NO_COPY_CLASS(wxDisplayImplMacOSX)
};
class wxDisplayFactoryMacOSX : public wxDisplayFactory
{
public:
wxDisplayFactoryMacOSX();
virtual wxDisplayImpl *CreateDisplay(size_t n);
virtual size_t GetCount();
virtual int GetFromPoint(const wxPoint& pt);
protected:
DECLARE_NO_COPY_CLASS(wxDisplayFactoryMacOSX)
};
// ============================================================================
// wxDisplayFactoryMacOSX implementation
// ============================================================================
size_t wxDisplayFactoryMacOSX::GetCount()
{ {
CGDisplayCount count; CGDisplayCount count;
#ifdef __WXDEBUG__ #ifdef __WXDEBUG__
CGDisplayErr err = CGDisplayErr err =
#endif #endif
CGGetActiveDisplayList(0, NULL, &count); CGGetActiveDisplayList(0, NULL, &count);
wxASSERT(err == CGDisplayNoErr); wxASSERT(err == CGDisplayNoErr);
return count; return count;
} }
int wxDisplayBase::GetFromPoint(const wxPoint &p) int wxDisplayFactoryMacOSX::GetFromPoint(const wxPoint& p)
{ {
CGPoint thePoint = {(float)p.x, (float)p.y}; CGPoint thePoint = {(float)p.x, (float)p.y};
CGDirectDisplayID theID; CGDirectDisplayID theID;
CGDisplayCount theCount; CGDisplayCount theCount;
CGDisplayErr err = CGGetDisplaysWithPoint(thePoint, 1, &theID, &theCount); CGDisplayErr err = CGGetDisplaysWithPoint(thePoint, 1, &theID, &theCount);
wxASSERT(err == CGDisplayNoErr); wxASSERT(err == CGDisplayNoErr);
int nWhich = -1;
int nWhich = wxNOT_FOUND;
if (theCount) if (theCount)
{ {
theCount = GetCount(); theCount = GetCount();
@@ -60,61 +98,54 @@ int wxDisplayBase::GetFromPoint(const wxPoint &p)
err = CGGetActiveDisplayList(theCount, theIDs, &theCount); err = CGGetActiveDisplayList(theCount, theIDs, &theCount);
wxASSERT(err == CGDisplayNoErr); wxASSERT(err == CGDisplayNoErr);
for(nWhich = 0; nWhich < (int) theCount; ++nWhich) for (nWhich = 0; nWhich < (int) theCount; ++nWhich)
{ {
if(theIDs[nWhich] == theID) if (theIDs[nWhich] == theID)
break; break;
} }
delete[] theIDs; delete [] theIDs;
if(nWhich == (int) theCount) if (nWhich == (int) theCount)
{ {
wxFAIL_MSG(wxT("Failed to find display in display list")); wxFAIL_MSG(wxT("Failed to find display in display list"));
nWhich = -1; nWhich = wxNOT_FOUND;
} }
} }
return nWhich;
}//CFUserNotification[NSBundle bundleForClass:[self class]]
wxDisplay::wxDisplay(size_t index) : wxDisplayBase ( index ) return nWhich;
}
wxDisplayImpl *wxDisplayFactoryMacOSX::CreateDisplay(size_t n)
{ {
CGDisplayCount theCount = GetCount(); CGDisplayCount theCount = GetCount();
CGDirectDisplayID* theIDs = new CGDirectDisplayID[theCount]; CGDirectDisplayID* theIDs = new CGDirectDisplayID[theCount];
#ifdef __WXDEBUG__ #ifdef __WXDEBUG__
CGDisplayErr err = CGDisplayErr err =
#endif #endif
CGGetActiveDisplayList(theCount, theIDs, &theCount); CGGetActiveDisplayList(theCount, theIDs, &theCount);
wxASSERT(err == CGDisplayNoErr); wxASSERT( err == CGDisplayNoErr );
wxASSERT(index < theCount); wxASSERT( n < theCount );
m_id = theIDs[index]; wxDisplayImplMacOSX *display = new wxDisplayImplMacOSX(theIDs[n]);
delete[] theIDs; delete [] theIDs;
return display;
} }
wxRect wxDisplay::GetGeometry() const
wxRect wxDisplayImplMacOSX::GetGeometry() const
{ {
CGRect theRect = CGDisplayBounds(m_id); CGRect theRect = CGDisplayBounds(m_id);
return wxRect( (int)theRect.origin.x, return wxRect( (int)theRect.origin.x,
(int)theRect.origin.y, (int)theRect.origin.y,
(int)theRect.size.width, (int)theRect.size.width,
(int)theRect.size.height ); //floats (int)theRect.size.height ); //floats
} }
int wxDisplay::GetDepth() const
{
return (int) CGDisplayBitsPerPixel(m_id); //size_t
}
wxString wxDisplay::GetName() const
{
// Macs don't name their displays...
return wxEmptyString;
}
static int wxCFDictKeyToInt( CFDictionaryRef desc, CFStringRef key ) static int wxCFDictKeyToInt( CFDictionaryRef desc, CFStringRef key )
{ {
CFNumberRef value; CFNumberRef value;
@@ -126,40 +157,39 @@ static int wxCFDictKeyToInt( CFDictionaryRef desc, CFStringRef key )
return num; return num;
} }
wxArrayVideoModes wxArrayVideoModes wxDisplayImplMacOSX::GetModes(const wxVideoMode& mode) const
wxDisplay::GetModes(const wxVideoMode& mode) const
{ {
wxArrayVideoModes Modes; wxArrayVideoModes Modes;
CFArrayRef theArray = CGDisplayAvailableModes(m_id); CFArrayRef theArray = CGDisplayAvailableModes(m_id);
for(CFIndex i = 0; i < CFArrayGetCount(theArray); ++i) for(CFIndex i = 0; i < CFArrayGetCount(theArray); ++i)
{ {
CFDictionaryRef theValue = (CFDictionaryRef) CFArrayGetValueAtIndex(theArray, i); CFDictionaryRef theValue = (CFDictionaryRef) CFArrayGetValueAtIndex(theArray, i);
wxVideoMode theMode(wxCFDictKeyToInt(theValue, kCGDisplayWidth), wxVideoMode theMode(wxCFDictKeyToInt(theValue, kCGDisplayWidth),
wxCFDictKeyToInt(theValue, kCGDisplayHeight), wxCFDictKeyToInt(theValue, kCGDisplayHeight),
wxCFDictKeyToInt(theValue, kCGDisplayBitsPerPixel), wxCFDictKeyToInt(theValue, kCGDisplayBitsPerPixel),
wxCFDictKeyToInt(theValue, kCGDisplayRefreshRate)); wxCFDictKeyToInt(theValue, kCGDisplayRefreshRate));
if (theMode.Matches(mode)) if (theMode.Matches(mode))
Modes.Add(theMode); Modes.Add(theMode);
} }
return Modes; return Modes;
} }
wxVideoMode wxDisplay::GetCurrentMode() const wxVideoMode wxDisplayImplMacOSX::GetCurrentMode() const
{ {
CFDictionaryRef theValue = CGDisplayCurrentMode (m_id); CFDictionaryRef theValue = CGDisplayCurrentMode (m_id);
return wxVideoMode(wxCFDictKeyToInt(theValue, kCGDisplayWidth), return wxVideoMode(wxCFDictKeyToInt(theValue, kCGDisplayWidth),
wxCFDictKeyToInt(theValue, kCGDisplayHeight), wxCFDictKeyToInt(theValue, kCGDisplayHeight),
wxCFDictKeyToInt(theValue, kCGDisplayBitsPerPixel), wxCFDictKeyToInt(theValue, kCGDisplayBitsPerPixel),
wxCFDictKeyToInt(theValue, kCGDisplayRefreshRate)); wxCFDictKeyToInt(theValue, kCGDisplayRefreshRate));
} }
bool wxDisplay::ChangeMode(const wxVideoMode& mode) bool wxDisplayImplMacOSX::ChangeMode(const wxVideoMode& mode)
{ {
//Changing to default mode (wxDefualtVideoMode) doesn't //Changing to default mode (wxDefualtVideoMode) doesn't
//work because we don't have access to the system's 'scrn' //work because we don't have access to the system's 'scrn'
@@ -173,17 +203,23 @@ bool wxDisplay::ChangeMode(const wxVideoMode& mode)
(size_t)mode.h, (size_t)mode.h,
(double)mode.refresh, (double)mode.refresh,
&bExactMatch); &bExactMatch);
bool bOK = bExactMatch; bool bOK = bExactMatch;
if(bOK) if(bOK)
bOK = CGDisplaySwitchToMode(m_id, theCGMode) == CGDisplayNoErr; bOK = CGDisplaySwitchToMode(m_id, theCGMode) == CGDisplayNoErr;
return bOK; return bOK;
} }
wxDisplay::~wxDisplay() // ============================================================================
// wxDisplay::CreateFactory()
// ============================================================================
/* static */ wxDisplayFactory *wxDisplay::CreateFactory()
{ {
return new wxDisplayFactoryMac;
} }
#endif // wxUSE_DISPLAY #endif // wxUSE_DISPLAY

View File

@@ -1,11 +1,11 @@
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////
// Name: src/common/dpycmn.cpp // Name: src/common/dpycmn.cpp
// Purpose: wxDisplayBase implementation // Purpose: wxDisplay and wxDisplayImplSingle implementation
// Author: Vadim Zeitlin // Author: Vadim Zeitlin
// Modified by: // Modified by:
// Created: 01.03.03 // Created: 01.03.03
// RCS-ID: $Id$ // RCS-ID: $Id$
// Copyright: (c) 2003 Vadim Zeitlin <vadim@wxwindows.org> // Copyright: (c) 2003-2006 Vadim Zeitlin <vadim@wxwindows.org>
// License: wxWindows licence // License: wxWindows licence
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////
@@ -24,43 +24,239 @@
#pragma hdrstop #pragma hdrstop
#endif #endif
#if wxUSE_DISPLAY
#ifndef WX_PRECOMP #ifndef WX_PRECOMP
#include "wx/gdicmn.h" #include "wx/gdicmn.h"
#include "wx/window.h" #include "wx/window.h"
#endif //WX_PRECOMP #endif //WX_PRECOMP
#include "wx/display.h" #include "wx/display.h"
#include "wx/display_impl.h"
#include "wx/module.h"
#include "wx/gdicmn.h" // for wxDisplaySize()
#if wxUSE_DISPLAY
#include "wx/arrimpl.cpp" #include "wx/arrimpl.cpp"
WX_DEFINE_OBJARRAY(wxArrayVideoModes) WX_DEFINE_OBJARRAY(wxArrayVideoModes)
const wxVideoMode wxDefaultVideoMode; const wxVideoMode wxDefaultVideoMode;
#endif // wxUSE_DISPLAY
// ----------------------------------------------------------------------------
// globals
// ----------------------------------------------------------------------------
// the factory object used by wxDisplay
//
// created on demand and destroyed by wxDisplayModule
static wxDisplayFactory *gs_factory = NULL;
// ----------------------------------------------------------------------------
// wxDisplayImplSingle: trivial implementation working for main display only
// ----------------------------------------------------------------------------
class WXDLLEXPORT wxDisplayImplSingle : public wxDisplayImpl
{
public:
wxDisplayImplSingle() : wxDisplayImpl(0) { }
virtual wxRect GetGeometry() const
{
wxRect r;
wxDisplaySize(&r.width, &r.height);
return r;
}
virtual wxString GetName() const { return wxString(); }
#if wxUSE_DISPLAY
// no video modes support for us, provide just the stubs
virtual wxArrayVideoModes GetModes(const wxVideoMode& WXUNUSED(mode)) const
{
return wxArrayVideoModes();
}
virtual wxVideoMode GetCurrentMode() const { return wxVideoMode(); }
virtual bool ChangeMode(const wxVideoMode& WXUNUSED(mode)) { return false; }
#endif // wxUSE_DISPLAY
DECLARE_NO_COPY_CLASS(wxDisplayImplSingle)
};
// ----------------------------------------------------------------------------
// wxDisplayModule is used to cleanup gs_factory
// ----------------------------------------------------------------------------
class wxDisplayModule : public wxModule
{
public:
virtual bool OnInit() { return true; }
virtual void OnExit()
{
if ( gs_factory )
{
delete gs_factory;
gs_factory = NULL;
}
}
DECLARE_DYNAMIC_CLASS(wxDisplayModule)
};
IMPLEMENT_DYNAMIC_CLASS(wxDisplayModule, wxModule)
// ============================================================================ // ============================================================================
// implementation // wxDisplay implementation
// ============================================================================ // ============================================================================
wxDisplayBase::wxDisplayBase(size_t index) // ----------------------------------------------------------------------------
: m_index (index) // ctor/dtor
// ----------------------------------------------------------------------------
wxDisplay::wxDisplay(size_t n)
{ {
wxASSERT_MSG( m_index < GetCount(), wxASSERT_MSG( n < GetCount(),
wxT("An invalid index was passed to wxDisplay") ); wxT("An invalid index was passed to wxDisplay") );
m_impl = Factory().CreateDisplay(n);
} }
// MSW has its own specific implementation of this wxDisplay::~wxDisplay()
#ifndef __WXMSW__
int wxDisplayBase::GetFromWindow(wxWindow *window)
{ {
wxCHECK_MSG( window, wxNOT_FOUND, _T("NULL window") ); delete m_impl;
}
// consider that the window belong to the display containing its centre // ----------------------------------------------------------------------------
// static functions forwarded to wxDisplayFactory
// ----------------------------------------------------------------------------
/* static */ size_t wxDisplay::GetCount()
{
return Factory().GetCount();
}
/* static */ int wxDisplay::GetFromPoint(const wxPoint& pt)
{
return Factory().GetFromPoint(pt);
}
/* static */ int wxDisplay::GetFromWindow(wxWindow *window)
{
wxCHECK_MSG( window, wxNOT_FOUND, _T("invalid window") );
return Factory().GetFromWindow(window);
}
// ----------------------------------------------------------------------------
// functions forwarded to wxDisplayImpl
// ----------------------------------------------------------------------------
wxRect wxDisplay::GetGeometry() const
{
wxCHECK_MSG( IsOk(), wxRect(), _T("invalid wxDisplay object") );
return m_impl->GetGeometry();
}
wxString wxDisplay::GetName() const
{
wxCHECK_MSG( IsOk(), wxString(), _T("invalid wxDisplay object") );
return m_impl->GetName();
}
bool wxDisplay::IsPrimary() const
{
return m_impl && m_impl->GetIndex() == 0;
}
#if wxUSE_DISPLAY
wxArrayVideoModes wxDisplay::GetModes(const wxVideoMode& mode) const
{
wxCHECK_MSG( IsOk(), wxArrayVideoModes(), _T("invalid wxDisplay object") );
return m_impl->GetModes(mode);
}
wxVideoMode wxDisplay::GetCurrentMode() const
{
wxCHECK_MSG( IsOk(), wxVideoMode(), _T("invalid wxDisplay object") );
return m_impl->GetCurrentMode();
}
bool wxDisplay::ChangeMode(const wxVideoMode& mode)
{
wxCHECK_MSG( IsOk(), false, _T("invalid wxDisplay object") );
return m_impl->ChangeMode(mode);
}
#endif // wxUSE_DIRECTDRAW
// ----------------------------------------------------------------------------
// static functions implementation
// ----------------------------------------------------------------------------
// if wxUSE_DISPLAY == 1 this is implemented in port-specific code
#if !wxUSE_DISPLAY
/* static */ wxDisplayFactory *wxDisplay::CreateFactory()
{
return new wxDisplayFactorySingle;
}
#endif // !wxUSE_DISPLAY
/* static */ wxDisplayFactory& wxDisplay::Factory()
{
if ( !gs_factory )
{
gs_factory = CreateFactory();
}
return *gs_factory;
}
// ============================================================================
// wxDisplayFactory implementation
// ============================================================================
int wxDisplayFactory::GetFromWindow(wxWindow *window)
{
// consider that the window belongs to the display containing its centre
const wxRect r(window->GetRect()); const wxRect r(window->GetRect());
return GetFromPoint(wxPoint(r.x + r.width/2, r.y + r.height/2)); return GetFromPoint(wxPoint(r.x + r.width/2, r.y + r.height/2));
} }
#endif // !__WXMSW__ // ============================================================================
// wxDisplayFactorySingle implementation
// ============================================================================
/* static */
wxDisplayImpl *wxDisplayFactorySingle::CreateDisplay(size_t n)
{
// we recognize the main display only
return n != 0 ? NULL : new wxDisplayImplSingle;
}
int wxDisplayFactorySingle::GetFromPoint(const wxPoint& pt)
{
if ( pt.x >= 0 && pt.y >= 0 )
{
int w, h;
wxDisplaySize(&w, &h);
if ( pt.x < w && pt.y < h )
return 0;
}
// the point is outside of the screen
return wxNOT_FOUND;
}
#endif // wxUSE_DISPLAY

View File

@@ -1,14 +1,22 @@
///////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////
// Name: display.cpp // Name: src/mac/carbon/display.cpp
// Purpose: Mac implementation of wxDisplay class // Purpose: Mac implementation of wxDisplay class
// Author: Ryan Norton & Brian Victor // Author: Ryan Norton & Brian Victor
// Modified by: Royce Mitchell III // Modified by: Royce Mitchell III, Vadim Zeitlin
// Created: 06/21/02 // Created: 06/21/02
// RCS-ID: $Id$ // RCS-ID: $Id$
// Copyright: (c) wxWidgets team // Copyright: (c) wxWidgets team
// Licence: wxWindows licence // Licence: wxWindows licence
///////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////
// ============================================================================
// declarations
// ============================================================================
// ----------------------------------------------------------------------------
// headers
// ----------------------------------------------------------------------------
#include "wx/wxprec.h" #include "wx/wxprec.h"
#ifdef __BORLANDC__ #ifdef __BORLANDC__
@@ -20,7 +28,6 @@
#ifndef WX_PRECOMP #ifndef WX_PRECOMP
#include "wx/dynarray.h" #include "wx/dynarray.h"
#include "wx/log.h" #include "wx/log.h"
#include "wx/msgdlg.h"
#endif #endif
#ifdef __DARWIN__ #ifdef __DARWIN__
@@ -35,32 +42,65 @@
#endif #endif
#include "wx/display.h" #include "wx/display.h"
#include "wx/display_impl.h"
#include "wx/gdicmn.h" #include "wx/gdicmn.h"
#include "wx/string.h" #include "wx/string.h"
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
// private classes // display classes implementation
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
#ifdef __WXMAC_OSX__ #ifdef __WXMAC_OSX__
class wxDisplayMacPriv class wxDisplayImplMacOSX : public wxDisplayImpl
{ {
public: public:
wxDisplayImplMacOSX(CGDirectDisplayID id) : m_id(id) { }
virtual wxRect GetGeometry() const;
virtual wxString GetName() const { return wxString(); }
virtual wxArrayVideoModes GetModes(const wxVideoMode& mode) const;
virtual wxVideoMode GetCurrentMode() const;
virtual bool ChangeMode(const wxVideoMode& mode);
private:
CGDirectDisplayID m_id; CGDirectDisplayID m_id;
DECLARE_NO_COPY_CLASS(wxDisplayImplMacOSX)
}; };
size_t wxDisplayBase::GetCount() class wxDisplayFactoryMacOSX : public wxDisplayFactory
{
public:
wxDisplayFactoryMacOSX();
virtual wxDisplayImpl *CreateDisplay(size_t n);
virtual size_t GetCount();
virtual int GetFromPoint(const wxPoint& pt);
protected:
DECLARE_NO_COPY_CLASS(wxDisplayFactoryMacOSX)
};
// ============================================================================
// wxDisplayFactoryMacOSX implementation
// ============================================================================
size_t wxDisplayFactoryMacOSX::GetCount()
{ {
CGDisplayCount count; CGDisplayCount count;
CGDisplayErr err = CGGetActiveDisplayList(0, NULL, &count); #ifdef __WXDEBUG__
CGDisplayErr err =
#endif
CGGetActiveDisplayList(0, NULL, &count);
wxASSERT(err == CGDisplayNoErr); wxASSERT(err == CGDisplayNoErr);
return count; return count;
} }
int wxDisplayBase::GetFromPoint(const wxPoint &p) int wxDisplayFactoryMacOSX::GetFromPoint(const wxPoint& p)
{ {
CGPoint thePoint = {(float)p.x, (float)p.y}; CGPoint thePoint = {(float)p.x, (float)p.y};
CGDirectDisplayID theID; CGDirectDisplayID theID;
@@ -68,7 +108,7 @@ int wxDisplayBase::GetFromPoint(const wxPoint &p)
CGDisplayErr err = CGGetDisplaysWithPoint(thePoint, 1, &theID, &theCount); CGDisplayErr err = CGGetDisplaysWithPoint(thePoint, 1, &theID, &theCount);
wxASSERT(err == CGDisplayNoErr); wxASSERT(err == CGDisplayNoErr);
int nWhich = -1; int nWhich = wxNOT_FOUND;
if (theCount) if (theCount)
{ {
@@ -88,50 +128,46 @@ int wxDisplayBase::GetFromPoint(const wxPoint &p)
if (nWhich == (int) theCount) if (nWhich == (int) theCount)
{ {
wxFAIL_MSG(wxT("Failed to find display in display list")); wxFAIL_MSG(wxT("Failed to find display in display list"));
nWhich = -1; nWhich = wxNOT_FOUND;
} }
} }
return nWhich; return nWhich;
} }
wxDisplay::wxDisplay(size_t index) wxDisplayImpl *wxDisplayFactoryMacOSX::CreateDisplay(size_t n)
: wxDisplayBase( index ) ,
m_priv( new wxDisplayMacPriv() )
{ {
CGDisplayCount theCount = GetCount(); CGDisplayCount theCount = GetCount();
CGDirectDisplayID* theIDs = new CGDirectDisplayID[theCount]; CGDirectDisplayID* theIDs = new CGDirectDisplayID[theCount];
CGDisplayErr err = CGGetActiveDisplayList(theCount, theIDs, &theCount); #ifdef __WXDEBUG__
CGDisplayErr err =
#endif
CGGetActiveDisplayList(theCount, theIDs, &theCount);
wxASSERT( err == CGDisplayNoErr ); wxASSERT( err == CGDisplayNoErr );
wxASSERT( index < theCount ); wxASSERT( n < theCount );
m_priv->m_id = theIDs[index]; wxDisplayImplMacOSX *display = new wxDisplayImplMacOSX(theIDs[n]);
delete [] theIDs; delete [] theIDs;
return display;
} }
wxRect wxDisplay::GetGeometry() const // ============================================================================
// wxDisplayImplMacOSX implementation
// ============================================================================
wxRect wxDisplayImplMacOSX::GetGeometry() const
{ {
CGRect theRect = CGDisplayBounds(m_priv->m_id); CGRect theRect = CGDisplayBounds(m_id);
return wxRect( (int)theRect.origin.x, return wxRect( (int)theRect.origin.x,
(int)theRect.origin.y, (int)theRect.origin.y,
(int)theRect.size.width, (int)theRect.size.width,
(int)theRect.size.height ); //floats (int)theRect.size.height ); //floats
} }
int wxDisplay::GetDepth() const
{
return (int) CGDisplayBitsPerPixel( m_priv->m_id ); //size_t
}
wxString wxDisplay::GetName() const
{
// Macs don't name their displays...
return wxEmptyString;
}
static int wxCFDictKeyToInt( CFDictionaryRef desc, CFStringRef key ) static int wxCFDictKeyToInt( CFDictionaryRef desc, CFStringRef key )
{ {
CFNumberRef value = (CFNumberRef) CFDictionaryGetValue( desc, key ); CFNumberRef value = (CFNumberRef) CFDictionaryGetValue( desc, key );
@@ -144,12 +180,11 @@ static int wxCFDictKeyToInt( CFDictionaryRef desc, CFStringRef key )
return num; return num;
} }
wxArrayVideoModes wxArrayVideoModes wxDisplayImplMacOSX::GetModes(const wxVideoMode& mode) const
wxDisplay::GetModes(const wxVideoMode& mode) const
{ {
wxArrayVideoModes resultModes; wxArrayVideoModes resultModes;
CFArrayRef theArray = CGDisplayAvailableModes( m_priv->m_id ); CFArrayRef theArray = CGDisplayAvailableModes( m_id );
for (CFIndex i = 0; i < CFArrayGetCount(theArray); ++i) for (CFIndex i = 0; i < CFArrayGetCount(theArray); ++i)
{ {
@@ -168,9 +203,9 @@ wxArrayVideoModes
return resultModes; return resultModes;
} }
wxVideoMode wxDisplay::GetCurrentMode() const wxVideoMode wxDisplayImplMacOSX::GetCurrentMode() const
{ {
CFDictionaryRef theValue = CGDisplayCurrentMode( m_priv->m_id ); CFDictionaryRef theValue = CGDisplayCurrentMode( m_id );
return wxVideoMode( return wxVideoMode(
wxCFDictKeyToInt( theValue, kCGDisplayWidth ), wxCFDictKeyToInt( theValue, kCGDisplayWidth ),
@@ -179,7 +214,7 @@ wxVideoMode wxDisplay::GetCurrentMode() const
wxCFDictKeyToInt( theValue, kCGDisplayRefreshRate )); wxCFDictKeyToInt( theValue, kCGDisplayRefreshRate ));
} }
bool wxDisplay::ChangeMode( const wxVideoMode& mode ) bool wxDisplayImplMacOSX::ChangeMode( const wxVideoMode& mode )
{ {
// Changing to default mode (wxDefaultVideoMode) doesn't // Changing to default mode (wxDefaultVideoMode) doesn't
// work because we don't have access to the system's 'scrn' // work because we don't have access to the system's 'scrn'
@@ -187,7 +222,7 @@ bool wxDisplay::ChangeMode( const wxVideoMode& mode )
// will return to after this app is done // will return to after this app is done
boolean_t bExactMatch; boolean_t bExactMatch;
CFDictionaryRef theCGMode = CGDisplayBestModeForParametersAndRefreshRate( CFDictionaryRef theCGMode = CGDisplayBestModeForParametersAndRefreshRate(
m_priv->m_id, m_id,
(size_t)mode.bpp, (size_t)mode.bpp,
(size_t)mode.w, (size_t)mode.w,
(size_t)mode.h, (size_t)mode.h,
@@ -197,49 +232,74 @@ bool wxDisplay::ChangeMode( const wxVideoMode& mode )
bool bOK = bExactMatch; bool bOK = bExactMatch;
if (bOK) if (bOK)
bOK = CGDisplaySwitchToMode( m_priv->m_id, theCGMode ) == CGDisplayNoErr; bOK = CGDisplaySwitchToMode( m_id, theCGMode ) == CGDisplayNoErr;
return bOK; return bOK;
} }
wxDisplay::~wxDisplay() // ============================================================================
// wxDisplay::CreateFactory()
// ============================================================================
/* static */ wxDisplayFactory *wxDisplay::CreateFactory()
{ {
if ( m_priv ) return new wxDisplayFactoryMacOSX;
{
delete m_priv;
m_priv = 0;
}
} }
#else #else // !__WXMAC_OSX__
class wxDisplayMacPriv class wxDisplayImplMac : public wxDisplayImpl
{ {
public: public:
wxDisplayImplMac(GDHandle hndl) : m_hndl(hndl) { }
virtual wxRect GetGeometry() const;
virtual wxString GetName() const { return wxString(); }
virtual wxArrayVideoModes GetModes(const wxVideoMode& mode) const;
virtual wxVideoMode GetCurrentMode() const;
virtual bool ChangeMode(const wxVideoMode& mode);
private:
GDHandle m_hndl; GDHandle m_hndl;
DECLARE_NO_COPY_CLASS(wxDisplayImplMac)
}; };
size_t wxDisplayBase::GetCount() class wxDisplayFactoryMac : public wxDisplayFactory
{
public:
wxDisplayFactoryMac();
virtual wxDisplayImpl *CreateDisplay(size_t n);
virtual size_t GetCount();
virtual int GetFromPoint(const wxPoint& pt);
protected:
DECLARE_NO_COPY_CLASS(wxDisplayFactoryMac)
};
// ============================================================================
// wxDisplayFactoryMac implementation
// ============================================================================
size_t wxDisplayFactoryMac::GetCount()
{ {
GDHandle hndl;
size_t num = 0; size_t num = 0;
hndl = DMGetFirstScreenDevice(true); GDHandle hndl = DMGetFirstScreenDevice(true);
while (hndl) while(hndl)
{ {
num++; num++;
hndl = DMGetNextScreenDevice(hndl, true); hndl = DMGetNextScreenDevice(hndl, true);
} }
return num; return num;
} }
int wxDisplayBase::GetFromPoint(const wxPoint &p) int wxDisplayFactoryMac::GetFromPoint(const wxPoint &p)
{ {
GDHandle hndl;
size_t num = 0; size_t num = 0;
hndl = DMGetFirstScreenDevice(true); GDHandle hndl = DMGetFirstScreenDevice(true);
while(hndl)
while (hndl)
{ {
Rect screenrect = (*hndl)->gdRect; Rect screenrect = (*hndl)->gdRect;
if (p.x >= screenrect.left && if (p.x >= screenrect.left &&
@@ -249,63 +309,39 @@ int wxDisplayBase::GetFromPoint(const wxPoint &p)
{ {
return num; return num;
} }
num++; num++;
hndl = DMGetNextScreenDevice(hndl, true); hndl = DMGetNextScreenDevice(hndl, true);
} }
return -1; return wxNOT_FOUND;
} }
wxDisplay::wxDisplay( size_t index ) wxDisplayImpl *wxDisplayFactoryMac::CreateDisplay(size_t n)
: wxDisplayBase( index ),
m_priv( new wxDisplayMacPriv() )
{ {
GDHandle hndl; GDHandle hndl = DMGetFirstScreenDevice(true);
hndl = DMGetFirstScreenDevice(true); while(hndl)
m_priv->m_hndl = NULL;
while (hndl)
{ {
if (index == 0) if (n == 0)
m_priv->m_hndl = hndl; {
return new wxDisplayImplMac(hndl);
index--; }
n--;
hndl = DMGetNextScreenDevice(hndl, true); hndl = DMGetNextScreenDevice(hndl, true);
} }
return NULL;
} }
wxRect wxDisplay::GetGeometry() const // ============================================================================
// wxDisplayImplMac implementation
// ============================================================================
wxRect wxDisplayImplMac::GetGeometry() const
{ {
if ((m_priv == NULL) || (m_priv->m_hndl == NULL)) Rect screenrect = (*m_hndl)->gdRect;
return wxRect(0, 0, 0, 0); return wxRect(screenrect.left, screenrect.top,
screenrect.right - screenrect.left,
Rect screenrect = (*(m_priv->m_hndl))->gdRect; screenrect.bottom - screenrect.top);
return wxRect(
screenrect.left, screenrect.top,
screenrect.right - screenrect.left,
screenrect.bottom - screenrect.top );
}
int wxDisplay::GetDepth() const
{
if ((m_priv == NULL) || (m_priv->m_hndl == NULL))
return 0;
// This cryptic looking code is based on Apple's sample code:
// http://developer.apple.com/samplecode/Sample_Code/Graphics_2D/GDevVideo/Gen.cp.htm
// RN - according to the docs
// gdPMap is a bitmap-type representation of the GDevice, and all
// 0x0000FFFF does is get the lower 16 bits of pixelSize. However,
// since pixelSize is only 16 bits (a short)...
return ((*(*(m_priv->m_hndl))->gdPMap)->pixelSize) & 0x0000FFFF;
}
wxString wxDisplay::GetName() const
{
// Macs don't name their displays...
return wxEmptyString;
} }
struct DMModeIteratorRec struct DMModeIteratorRec
@@ -415,8 +451,7 @@ pascal void DMModeTransProc(
#undef pDBI #undef pDBI
} }
wxArrayVideoModes wxArrayVideoModes wxDisplayImplMac::GetModes(const wxVideoMode& mode) const
wxDisplay::GetModes(const wxVideoMode& mode) const
{ {
wxArrayVideoModes Modes; wxArrayVideoModes Modes;
unsigned long dwDMVer; unsigned long dwDMVer;
@@ -432,7 +467,7 @@ wxArrayVideoModes
DisplayIDType nDisplayID; DisplayIDType nDisplayID;
OSErr err; OSErr err;
err = DMGetDisplayIDByGDevice(m_priv->m_hndl, &nDisplayID, false); err = DMGetDisplayIDByGDevice(m_hndl, &nDisplayID, false);
verify_noerr( err ); verify_noerr( err );
// Create a new list... // Create a new list...
@@ -468,7 +503,7 @@ wxArrayVideoModes
return Modes; return Modes;
} }
wxVideoMode wxDisplay::GetCurrentMode() const wxVideoMode wxDisplayImplMac::GetCurrentMode() const
{ {
unsigned long dwDMVer; unsigned long dwDMVer;
wxVideoMode RetMode; wxVideoMode RetMode;
@@ -481,7 +516,7 @@ wxVideoMode wxDisplay::GetCurrentMode() const
VDSwitchInfoRec sMode; // Note: csMode member also contains the bit depth VDSwitchInfoRec sMode; // Note: csMode member also contains the bit depth
OSErr err; OSErr err;
err = DMGetDisplayMode( m_priv->m_hndl, &sMode ); err = DMGetDisplayMode( m_hndl, &sMode );
if (err == noErr) if (err == noErr)
{ {
DMListIndexType nNumModes; DMListIndexType nNumModes;
@@ -489,7 +524,7 @@ wxVideoMode wxDisplay::GetCurrentMode() const
DMDisplayModeListIteratorUPP uppMLI; DMDisplayModeListIteratorUPP uppMLI;
DisplayIDType nDisplayID; DisplayIDType nDisplayID;
err = DMGetDisplayIDByGDevice(m_priv->m_hndl, &nDisplayID, false); err = DMGetDisplayIDByGDevice(m_hndl, &nDisplayID, false);
verify_noerr( err ); verify_noerr( err );
// Create a new list... // Create a new list...
@@ -538,7 +573,7 @@ wxVideoMode wxDisplay::GetCurrentMode() const
return RetMode; return RetMode;
} }
bool wxDisplay::ChangeMode(const wxVideoMode& mode) bool wxDisplayImplMac::ChangeMode(const wxVideoMode& mode)
{ {
unsigned long dwDMVer; unsigned long dwDMVer;
@@ -580,7 +615,7 @@ bool wxDisplay::ChangeMode(const wxVideoMode& mode)
DisplayIDType nDisplayID; DisplayIDType nDisplayID;
OSErr err; OSErr err;
err = DMGetDisplayIDByGDevice(m_priv->m_hndl, &nDisplayID, false); err = DMGetDisplayIDByGDevice(m_hndl, &nDisplayID, false);
verify_noerr( err ); verify_noerr( err );
// Create a new list... // Create a new list...
@@ -618,7 +653,7 @@ bool wxDisplay::ChangeMode(const wxVideoMode& mode)
// For the really paranoid - // For the really paranoid -
// unsigned long flags; // unsigned long flags;
// Boolean bok; // Boolean bok;
// wxASSERT(noErr == DMCheckDisplayMode(m_priv->m_hndl, sMode.csData, // wxASSERT(noErr == DMCheckDisplayMode(m_hndl, sMode.csData,
// sMode.csMode, &flags, NULL, &bok)); // sMode.csMode, &flags, NULL, &bok));
// wxASSERT(bok); // wxASSERT(bok);
@@ -632,7 +667,7 @@ bool wxDisplay::ChangeMode(const wxVideoMode& mode)
unsigned long dwBPP = (unsigned long) mode.bpp; unsigned long dwBPP = (unsigned long) mode.bpp;
err = DMSetDisplayMode( err = DMSetDisplayMode(
m_priv->m_hndl, sMode.csData, m_hndl, sMode.csData,
(unsigned long*) &(dwBPP), (unsigned long*) &(dwBPP),
NULL, //(unsigned long) &sMode NULL, //(unsigned long) &sMode
hDisplayState ); hDisplayState );
@@ -640,7 +675,7 @@ bool wxDisplay::ChangeMode(const wxVideoMode& mode)
if (err != noErr) if (err != noErr)
{ {
DMEndConfigureDisplays(hDisplayState); DMEndConfigureDisplays(hDisplayState);
wxMessageBox( wxString::Format(wxT("Could not set the display mode")) ); wxLogError(wxT("Could not set the display mode"));
return false; return false;
} }
@@ -660,13 +695,13 @@ bool wxDisplay::ChangeMode(const wxVideoMode& mode)
return true; return true;
} }
wxDisplay::~wxDisplay() // ============================================================================
// wxDisplay::CreateFactory()
// ============================================================================
/* static */ wxDisplayFactory *wxDisplay::CreateFactory()
{ {
if ( m_priv ) return new wxDisplayFactoryMac;
{
delete m_priv;
m_priv = 0;
}
} }
#endif // !OSX #endif // !OSX

View File

@@ -1,14 +1,22 @@
///////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////
// Name: display.cpp // Name: src/mac/classic/display.cpp
// Purpose: Mac implementation of wxDisplay class // Purpose: Mac implementation of wxDisplay class
// Author: Brian Victor // Author: Brian Victor
// Modified by: Royce Mitchell III & Ryan Norton // Modified by: Royce Mitchell III & Ryan Norton, Vadim Zeitlin
// Created: 06/21/02 // Created: 06/21/02
// RCS-ID: $Id$ // RCS-ID: $Id$
// Copyright: (c) wxWidgets team // Copyright: (c) wxWidgets team
// Licence: wxWindows licence // Licence: wxWindows licence
///////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////
// ============================================================================
// declarations
// ============================================================================
// ----------------------------------------------------------------------------
// headers
// ----------------------------------------------------------------------------
// For compilers that support precompilation, includes "wx.h". // For compilers that support precompilation, includes "wx.h".
#include "wx/wxprec.h" #include "wx/wxprec.h"
@@ -21,7 +29,6 @@
#ifndef WX_PRECOMP #ifndef WX_PRECOMP
#include "wx/dynarray.h" #include "wx/dynarray.h"
#include "wx/log.h" #include "wx/log.h"
#include "wx/msgdlg.h"
#endif #endif
#ifdef __DARWIN__ #ifdef __DARWIN__
@@ -35,24 +42,53 @@
#endif #endif
#include "wx/display.h" #include "wx/display.h"
#include "wx/display_impl.h"
#include "wx/gdicmn.h" #include "wx/gdicmn.h"
#include "wx/string.h" #include "wx/string.h"
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
// private classes // display implementation classes
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
class wxDisplayMacPriv class wxDisplayImplMac : public wxDisplayImpl
{ {
public: public:
wxDisplayImplMac(GDHandle hndl) : m_hndl(hndl) { }
virtual wxRect GetGeometry() const;
virtual wxString GetName() const { return wxString(); }
virtual wxArrayVideoModes GetModes(const wxVideoMode& mode) const;
virtual wxVideoMode GetCurrentMode() const;
virtual bool ChangeMode(const wxVideoMode& mode);
private:
GDHandle m_hndl; GDHandle m_hndl;
DECLARE_NO_COPY_CLASS(wxDisplayImplMac)
}; };
size_t wxDisplayBase::GetCount() class wxDisplayFactoryMac : public wxDisplayFactory
{
public:
wxDisplayFactoryMac();
virtual wxDisplayImpl *CreateDisplay(size_t n);
virtual size_t GetCount();
virtual int GetFromPoint(const wxPoint& pt);
protected:
DECLARE_NO_COPY_CLASS(wxDisplayFactoryMac)
};
// ============================================================================
// wxDisplayFactoryMac implementation
// ============================================================================
size_t wxDisplayFactoryMac::GetCount()
{ {
GDHandle hndl;
size_t num = 0; size_t num = 0;
hndl = DMGetFirstScreenDevice(true); GDHandle hndl = DMGetFirstScreenDevice(true);
while(hndl) while(hndl)
{ {
num++; num++;
@@ -61,11 +97,10 @@ size_t wxDisplayBase::GetCount()
return num; return num;
} }
int wxDisplayBase::GetFromPoint(const wxPoint &p) int wxDisplayFactoryMac::GetFromPoint(const wxPoint &p)
{ {
GDHandle hndl;
size_t num = 0; size_t num = 0;
hndl = DMGetFirstScreenDevice(true); GDHandle hndl = DMGetFirstScreenDevice(true);
while(hndl) while(hndl)
{ {
Rect screenrect = (*hndl)->gdRect; Rect screenrect = (*hndl)->gdRect;
@@ -79,154 +114,134 @@ int wxDisplayBase::GetFromPoint(const wxPoint &p)
num++; num++;
hndl = DMGetNextScreenDevice(hndl, true); hndl = DMGetNextScreenDevice(hndl, true);
} }
return -1;
return wxNOT_FOUND;
} }
wxDisplay::wxDisplay(size_t index) : wxDisplayBase ( index ), wxDisplayImpl *wxDisplayFactoryMac::CreateDisplay(size_t n)
m_priv ( new wxDisplayMacPriv() )
{ {
GDHandle hndl; GDHandle hndl = DMGetFirstScreenDevice(true);
hndl = DMGetFirstScreenDevice(true);
m_priv->m_hndl = NULL;
while(hndl) while(hndl)
{ {
if (index == 0) if (n == 0)
{ {
m_priv->m_hndl = hndl; return new wxDisplayImplMac(hndl);
} }
index--; n--;
hndl = DMGetNextScreenDevice(hndl, true); hndl = DMGetNextScreenDevice(hndl, true);
} }
return NULL;
} }
wxRect wxDisplay::GetGeometry() const // ============================================================================
// wxDisplayImplMac implementation
// ============================================================================
wxRect wxDisplayImplMac::GetGeometry() const
{ {
if (!(m_priv)) return wxRect(0, 0, 0, 0); Rect screenrect = (*m_hndl)->gdRect;
if (!(m_priv->m_hndl)) return wxRect(0, 0, 0, 0); return wxRect(screenrect.left, screenrect.top,
Rect screenrect = (*(m_priv->m_hndl))->gdRect; screenrect.right - screenrect.left,
return wxRect( screenrect.left, screenrect.top, screenrect.bottom - screenrect.top);
screenrect.right - screenrect.left, screenrect.bottom - screenrect.top);
}
int wxDisplay::GetDepth() const
{
if (!(m_priv)) return 0;
if (!(m_priv->m_hndl)) return 0;
// This cryptic looking code is based on Apple's sample code:
// http://developer.apple.com/samplecode/Sample_Code/Graphics_2D/GDevVideo/Gen.cp.htm
//RN - according to the docs
//gdPMap is a bitmap-type representation of the GDevice, and all
//0x0000FFFF does is get the lower 16 bits of pixelSize. However,
//since pixelSize is only 16 bits (a short)...
return ((*(*(m_priv->m_hndl))->gdPMap)->pixelSize) & 0x0000FFFF;
}
wxString wxDisplay::GetName() const
{
// Macs don't name their displays...
return wxEmptyString;
} }
struct DMModeIteratorRec struct DMModeIteratorRec
{ {
wxArrayVideoModes* pModes; wxArrayVideoModes* pModes;
const wxVideoMode* pMatchMode; const wxVideoMode* pMatchMode;
}; };
pascal void DMModeListIteratorProc ( void* pData, pascal void DMModeListIteratorProc ( void* pData,
DMListIndexType nIndex, DMListIndexType nIndex,
DMDisplayModeListEntryPtr pInfo) DMDisplayModeListEntryPtr pInfo)
{ {
DMModeIteratorRec* pInfoData = (DMModeIteratorRec*) pData; DMModeIteratorRec* pInfoData = (DMModeIteratorRec*) pData;
//Note that in testing the refresh rate is always 0 on my ibook - RN //Note that in testing the refresh rate is always 0 on my ibook - RN
int refresh = (int) Fix2Long(pInfo->displayModeResolutionInfo->csRefreshRate); int refresh = (int) Fix2Long(pInfo->displayModeResolutionInfo->csRefreshRate);
for(unsigned long i = 0; i < pInfo->displayModeDepthBlockInfo->depthBlockCount; ++i) for(unsigned long i = 0; i < pInfo->displayModeDepthBlockInfo->depthBlockCount; ++i)
{ {
#define pDBI pInfo->displayModeDepthBlockInfo->depthVPBlock[i].depthVPBlock #define pDBI pInfo->displayModeDepthBlockInfo->depthVPBlock[i].depthVPBlock
if (wxVideoMode((int) pInfo->displayModeResolutionInfo->csHorizontalPixels, if (wxVideoMode((int) pInfo->displayModeResolutionInfo->csHorizontalPixels,
(int) pInfo->displayModeResolutionInfo->csVerticalLines, (int) pInfo->displayModeResolutionInfo->csVerticalLines,
(int) pDBI->vpPixelSize, (int) pDBI->vpPixelSize,
refresh).Matches(*pInfoData->pMatchMode) ) refresh).Matches(*pInfoData->pMatchMode) )
{ {
pInfoData->pModes->Add(wxVideoMode((int) pInfo->displayModeResolutionInfo->csHorizontalPixels, pInfoData->pModes->Add(wxVideoMode((int) pInfo->displayModeResolutionInfo->csHorizontalPixels,
(int) pInfo->displayModeResolutionInfo->csVerticalLines, (int) pInfo->displayModeResolutionInfo->csVerticalLines,
(int) pDBI->vpPixelSize, (int) pDBI->vpPixelSize,
refresh)); refresh));
} }
#undef pDBI #undef pDBI
} }
} }
struct DMModeInfoRec struct DMModeInfoRec
{ {
const wxVideoMode* pMode; const wxVideoMode* pMode;
VDSwitchInfoRec sMode; VDSwitchInfoRec sMode;
bool bMatched; bool bMatched;
}; };
pascal void DMModeInfoProc ( void* pData, pascal void DMModeInfoProc ( void* pData,
DMListIndexType nIndex, DMListIndexType nIndex,
DMDisplayModeListEntryPtr pInfo) DMDisplayModeListEntryPtr pInfo)
{ {
DMModeInfoRec* pInfoData = (DMModeInfoRec*) pData; DMModeInfoRec* pInfoData = (DMModeInfoRec*) pData;
Fixed refresh = Long2Fix(pInfoData->pMode->refresh); Fixed refresh = Long2Fix(pInfoData->pMode->refresh);
for(unsigned long i = 0; i < pInfo->displayModeDepthBlockInfo->depthBlockCount; ++i) for(unsigned long i = 0; i < pInfo->displayModeDepthBlockInfo->depthBlockCount; ++i)
{ {
#define pDBI pInfo->displayModeDepthBlockInfo->depthVPBlock[i].depthVPBlock #define pDBI pInfo->displayModeDepthBlockInfo->depthVPBlock[i].depthVPBlock
if (pInfoData->pMode->w == (int&) pInfo->displayModeResolutionInfo->csHorizontalPixels && if (pInfoData->pMode->w == (int&) pInfo->displayModeResolutionInfo->csHorizontalPixels &&
pInfoData->pMode->h == (int&) pInfo->displayModeResolutionInfo->csVerticalLines && pInfoData->pMode->h == (int&) pInfo->displayModeResolutionInfo->csVerticalLines &&
pInfoData->pMode->bpp == (int) pDBI->vpPixelSize && pInfoData->pMode->bpp == (int) pDBI->vpPixelSize &&
refresh == pInfo->displayModeResolutionInfo->csRefreshRate) refresh == pInfo->displayModeResolutionInfo->csRefreshRate)
{ {
memcpy(&pInfoData->sMode, pInfo->displayModeDepthBlockInfo->depthVPBlock[i].depthSwitchInfo, memcpy(&pInfoData->sMode, pInfo->displayModeDepthBlockInfo->depthVPBlock[i].depthSwitchInfo,
sizeof(VDSwitchInfoRec)); sizeof(VDSwitchInfoRec));
pInfoData->sMode.csMode = pDBI->vpPixelSize; pInfoData->sMode.csMode = pDBI->vpPixelSize;
pInfoData->bMatched = true; pInfoData->bMatched = true;
break; break;
} }
#undef pDBI #undef pDBI
} }
} }
struct DMModeTransRec struct DMModeTransRec
{ {
wxVideoMode Mode; wxVideoMode Mode;
const VDSwitchInfoRec* psMode; const VDSwitchInfoRec* psMode;
bool bMatched; bool bMatched;
}; };
pascal void DMModeTransProc ( void* pData, pascal void DMModeTransProc ( void* pData,
DMListIndexType nIndex, DMListIndexType nIndex,
DMDisplayModeListEntryPtr pInfo) DMDisplayModeListEntryPtr pInfo)
{ {
DMModeTransRec* pInfoData = (DMModeTransRec*) pData; DMModeTransRec* pInfoData = (DMModeTransRec*) pData;
for(unsigned long i = 0; i < pInfo->displayModeDepthBlockInfo->depthBlockCount; ++i) for(unsigned long i = 0; i < pInfo->displayModeDepthBlockInfo->depthBlockCount; ++i)
{ {
#define pDBI pInfo->displayModeDepthBlockInfo->depthVPBlock[i].depthVPBlock #define pDBI pInfo->displayModeDepthBlockInfo->depthVPBlock[i].depthVPBlock
if (pInfoData->psMode->csData == pInfo->displayModeDepthBlockInfo->depthVPBlock[i].depthSwitchInfo->csData) if (pInfoData->psMode->csData == pInfo->displayModeDepthBlockInfo->depthVPBlock[i].depthSwitchInfo->csData)
{ {
pInfoData->Mode = wxVideoMode((int) pInfo->displayModeResolutionInfo->csHorizontalPixels, pInfoData->Mode = wxVideoMode((int) pInfo->displayModeResolutionInfo->csHorizontalPixels,
(int) pInfo->displayModeResolutionInfo->csVerticalLines, (int) pInfo->displayModeResolutionInfo->csVerticalLines,
(int) pDBI->vpPixelSize, (int) pDBI->vpPixelSize,
(int) Fix2Long(pInfo->displayModeResolutionInfo->csRefreshRate) ); (int) Fix2Long(pInfo->displayModeResolutionInfo->csRefreshRate) );
pInfoData->bMatched = true; pInfoData->bMatched = true;
break; break;
} }
#undef pDBI #undef pDBI
} }
} }
wxArrayVideoModes wxArrayVideoModes wxDisplayImplMac::GetModes(const wxVideoMode& mode) const
wxDisplay::GetModes(const wxVideoMode& mode) const
{ {
wxArrayVideoModes Modes; wxArrayVideoModes Modes;
unsigned long dwDMVer; unsigned long dwDMVer;
@@ -236,207 +251,207 @@ wxArrayVideoModes
if (dwDMVer >= 0x020000) //version 2? if (dwDMVer >= 0x020000) //version 2?
{ {
DMListIndexType nNumModes; DMListIndexType nNumModes;
DMListType pModes; DMListType pModes;
DMDisplayModeListIteratorUPP uppMLI; DMDisplayModeListIteratorUPP uppMLI;
DisplayIDType nDisplayID; DisplayIDType nDisplayID;
wxASSERT(DMGetDisplayIDByGDevice(m_priv->m_hndl, &nDisplayID, false) == noErr); wxASSERT(DMGetDisplayIDByGDevice(m_hndl, &nDisplayID, false) == noErr);
//Create a new list... //Create a new list...
wxASSERT_MSG(DMNewDisplayModeList(nDisplayID, NULL, NULL, &nNumModes, &pModes) == noErr, wxT("Could not create a new display mode list") ); wxASSERT_MSG(DMNewDisplayModeList(nDisplayID, NULL, NULL, &nNumModes, &pModes) == noErr, wxT("Could not create a new display mode list") );
uppMLI = NewDMDisplayModeListIteratorUPP(DMModeListIteratorProc); uppMLI = NewDMDisplayModeListIteratorUPP(DMModeListIteratorProc);
wxASSERT(uppMLI); wxASSERT(uppMLI);
DMModeIteratorRec sModeInfo; DMModeIteratorRec sModeInfo;
sModeInfo.pModes = &Modes; sModeInfo.pModes = &Modes;
sModeInfo.pMatchMode = &mode; sModeInfo.pMatchMode = &mode;
for (DMListIndexType i = 0; i < nNumModes; ++i) for (DMListIndexType i = 0; i < nNumModes; ++i)
{ {
wxASSERT(DMGetIndexedDisplayModeFromList(pModes, i, NULL, wxASSERT(DMGetIndexedDisplayModeFromList(pModes, i, NULL,
uppMLI, &sModeInfo) == noErr); uppMLI, &sModeInfo) == noErr);
} }
DisposeDMDisplayModeListIteratorUPP(uppMLI); DisposeDMDisplayModeListIteratorUPP(uppMLI);
wxASSERT(DMDisposeList(pModes) == noErr); wxASSERT(DMDisposeList(pModes) == noErr);
} }
else //DM 1.0, 1.2, 1.x else //DM 1.0, 1.2, 1.x
{ {
wxLogSysError(wxString::Format(wxT("Display Manager Version %u Not Supported! Present? %s"), wxLogSysError(wxString::Format(wxT("Display Manager Version %u Not Supported! Present? %s"),
(unsigned int) dwDMVer / 0x10000, (unsigned int) dwDMVer / 0x10000,
(dwDMVer & (1 << gestaltDisplayMgrPresent) ? wxT("Yes") : wxT("No")) ) (dwDMVer & (1 << gestaltDisplayMgrPresent) ? wxT("Yes") : wxT("No")) )
); );
} }
return Modes; return Modes;
} }
wxVideoMode wxDisplay::GetCurrentMode() const wxVideoMode wxDisplayImplMac::GetCurrentMode() const
{ {
unsigned long dwDMVer; unsigned long dwDMVer;
wxVideoMode RetMode; wxVideoMode RetMode;
Gestalt(gestaltDisplayMgrVers, (long*) &dwDMVer); Gestalt(gestaltDisplayMgrVers, (long*) &dwDMVer);
//Check DM version (for backward compatibility only - 7.5.3+ use 2.0) //Check DM version (for backward compatibility only - 7.5.3+ use 2.0)
if (dwDMVer >= 0x020000) //version 2? if (dwDMVer >= 0x020000) //version 2?
{ {
VDSwitchInfoRec sMode; //Note - csMode member also contains the bit depth VDSwitchInfoRec sMode; //Note - csMode member also contains the bit depth
if (DMGetDisplayMode(m_priv->m_hndl, &sMode) == noErr) if (DMGetDisplayMode(m_hndl, &sMode) == noErr)
{ {
DMListIndexType nNumModes; DMListIndexType nNumModes;
DMListType pModes; DMListType pModes;
DMDisplayModeListIteratorUPP uppMLI; DMDisplayModeListIteratorUPP uppMLI;
DisplayIDType nDisplayID; DisplayIDType nDisplayID;
wxASSERT(DMGetDisplayIDByGDevice(m_priv->m_hndl, &nDisplayID, false) == noErr); wxASSERT(DMGetDisplayIDByGDevice(m_hndl, &nDisplayID, false) == noErr);
//Create a new list... //Create a new list...
wxASSERT_MSG(DMNewDisplayModeList(nDisplayID, NULL, NULL, &nNumModes, &pModes) == noErr, wxASSERT_MSG(DMNewDisplayModeList(nDisplayID, NULL, NULL, &nNumModes, &pModes) == noErr,
wxT("Could not create a new display mode list") ); wxT("Could not create a new display mode list") );
uppMLI = NewDMDisplayModeListIteratorUPP(DMModeTransProc);
wxASSERT(uppMLI);
DMModeTransRec sModeInfo; uppMLI = NewDMDisplayModeListIteratorUPP(DMModeTransProc);
sModeInfo.bMatched = false; wxASSERT(uppMLI);
sModeInfo.psMode = &sMode;
for (DMListIndexType i = 0; i < nNumModes; ++i)
{
wxASSERT(DMGetIndexedDisplayModeFromList(pModes, i, NULL,
uppMLI, &sModeInfo) == noErr);
if ( sModeInfo.bMatched == true ) DMModeTransRec sModeInfo;
{ sModeInfo.bMatched = false;
RetMode = sModeInfo.Mode; sModeInfo.psMode = &sMode;
break; for (DMListIndexType i = 0; i < nNumModes; ++i)
} {
} wxASSERT(DMGetIndexedDisplayModeFromList(pModes, i, NULL,
uppMLI, &sModeInfo) == noErr);
DisposeDMDisplayModeListIteratorUPP(uppMLI); if ( sModeInfo.bMatched == true )
wxASSERT(DMDisposeList(pModes) == noErr); {
} RetMode = sModeInfo.Mode;
else //Can't get current mode? break;
{ }
wxLogSysError(wxString::Format(wxT("Couldn't obtain current display mode!!!\ndwDMVer:%u"), }
(unsigned int) dwDMVer));
} DisposeDMDisplayModeListIteratorUPP(uppMLI);
wxASSERT(DMDisposeList(pModes) == noErr);
}
else //Can't get current mode?
{
wxLogSysError(wxString::Format(wxT("Couldn't obtain current display mode!!!\ndwDMVer:%u"),
(unsigned int) dwDMVer));
}
} }
else //DM ver 1 else //DM ver 1
{ {
wxLogSysError(wxString::Format(wxT("Display Manager Version %u Not Supported! Present? %s"), wxLogSysError(wxString::Format(wxT("Display Manager Version %u Not Supported! Present? %s"),
(unsigned int) dwDMVer / 0x10000, (unsigned int) dwDMVer / 0x10000,
(dwDMVer & (1 << gestaltDisplayMgrPresent) ? wxT("Yes") : wxT("No")) ) (dwDMVer & (1 << gestaltDisplayMgrPresent) ? wxT("Yes") : wxT("No")) )
); );
} }
return RetMode; return RetMode;
} }
bool wxDisplay::ChangeMode(const wxVideoMode& mode) bool wxDisplayImplMac::ChangeMode(const wxVideoMode& mode)
{ {
unsigned long dwDMVer; unsigned long dwDMVer;
Gestalt(gestaltDisplayMgrVers, (long*)&dwDMVer); Gestalt(gestaltDisplayMgrVers, (long*)&dwDMVer);
if (GetCount() == 1 || dwDMVer >= 0x020000) if (GetCount() == 1 || dwDMVer >= 0x020000)
{ {
if (mode == wxDefaultVideoMode) if (mode == wxDefaultVideoMode)
{ {
//#ifndef __DARWIN__ //#ifndef __DARWIN__
// Handle hDisplayState; // Handle hDisplayState;
// if (DMBeginConfigureDisplays(&hDisplayState) != noErr) // if (DMBeginConfigureDisplays(&hDisplayState) != noErr)
// { // {
// wxLogSysError(wxT("Could not lock display for display mode changing!")); // wxLogSysError(wxT("Could not lock display for display mode changing!"));
// return false; // return false;
// } // }
// wxASSERT( DMUseScreenPrefs(true, hDisplayState) == noErr); // wxASSERT( DMUseScreenPrefs(true, hDisplayState) == noErr);
// DMEndConfigureDisplays(hDisplayState); // DMEndConfigureDisplays(hDisplayState);
// return true; // return true;
//#else //#else
//hmmmmm.... //hmmmmm....
return true; return true;
//#endif //#endif
} }
//0 & NULL for params 2 & 3 of DMSetVideoMode signal it to use defaults (current mode)
//DM 2.0+ doesn't use params 2 & 3 of DMSetDisplayMode
//so we have to use this icky structure
VDSwitchInfoRec sMode;
memset(&sMode, 0, sizeof(VDSwitchInfoRec) );
DMListIndexType nNumModes; //0 & NULL for params 2 & 3 of DMSetVideoMode signal it to use defaults (current mode)
DMListType pModes; //DM 2.0+ doesn't use params 2 & 3 of DMSetDisplayMode
DMDisplayModeListIteratorUPP uppMLI; //so we have to use this icky structure
DisplayIDType nDisplayID; VDSwitchInfoRec sMode;
memset(&sMode, 0, sizeof(VDSwitchInfoRec) );
wxASSERT(DMGetDisplayIDByGDevice(m_priv->m_hndl, &nDisplayID, false) == noErr); DMListIndexType nNumModes;
//Create a new list... DMListType pModes;
wxASSERT_MSG(DMNewDisplayModeList(nDisplayID, NULL, NULL, &nNumModes, &pModes) == noErr, DMDisplayModeListIteratorUPP uppMLI;
wxT("Could not create a new display mode list") ); DisplayIDType nDisplayID;
uppMLI = NewDMDisplayModeListIteratorUPP(DMModeInfoProc); wxASSERT(DMGetDisplayIDByGDevice(m_hndl, &nDisplayID, false) == noErr);
wxASSERT(uppMLI); //Create a new list...
wxASSERT_MSG(DMNewDisplayModeList(nDisplayID, NULL, NULL, &nNumModes, &pModes) == noErr,
wxT("Could not create a new display mode list") );
DMModeInfoRec sModeInfo; uppMLI = NewDMDisplayModeListIteratorUPP(DMModeInfoProc);
sModeInfo.bMatched = false; wxASSERT(uppMLI);
sModeInfo.pMode = &mode;
unsigned int i;
for(i = 0; i < nNumModes; ++i)
{
wxASSERT(DMGetIndexedDisplayModeFromList(pModes, i, NULL,
uppMLI, &sModeInfo) == noErr);
if (sModeInfo.bMatched == true)
{
sMode = sModeInfo.sMode;
break;
}
}
if(i == nNumModes)
return false;
DisposeDMDisplayModeListIteratorUPP(uppMLI); DMModeInfoRec sModeInfo;
wxASSERT(DMDisposeList(pModes) == noErr); sModeInfo.bMatched = false;
sModeInfo.pMode = &mode;
// For the really paranoid - unsigned int i;
// unsigned long flags; for(i = 0; i < nNumModes; ++i)
// Boolean bok; {
// wxASSERT(noErr == DMCheckDisplayMode(m_priv->m_hndl, sMode.csData, wxASSERT(DMGetIndexedDisplayModeFromList(pModes, i, NULL,
// sMode.csMode, &flags, NULL, &bok)); uppMLI, &sModeInfo) == noErr);
// wxASSERT(bok); if (sModeInfo.bMatched == true)
{
Handle hDisplayState; sMode = sModeInfo.sMode;
if (DMBeginConfigureDisplays(&hDisplayState) != noErr) break;
{ }
wxLogSysError(wxT("Could not lock display for display mode changing!")); }
return false; if(i == nNumModes)
}
unsigned long dwBPP = (unsigned long) mode.bpp;
if (DMSetDisplayMode(m_priv->m_hndl, sMode.csData,
(unsigned long*) &(dwBPP), NULL
//(unsigned long) &sMode
, hDisplayState
) != noErr)
{
DMEndConfigureDisplays(hDisplayState);
wxMessageBox(wxString::Format(wxT("Could not set the display mode")));
return false; return false;
}
DMEndConfigureDisplays(hDisplayState); DisposeDMDisplayModeListIteratorUPP(uppMLI);
wxASSERT(DMDisposeList(pModes) == noErr);
// For the really paranoid -
// unsigned long flags;
// Boolean bok;
// wxASSERT(noErr == DMCheckDisplayMode(m_hndl, sMode.csData,
// sMode.csMode, &flags, NULL, &bok));
// wxASSERT(bok);
Handle hDisplayState;
if (DMBeginConfigureDisplays(&hDisplayState) != noErr)
{
wxLogSysError(wxT("Could not lock display for display mode changing!"));
return false;
}
unsigned long dwBPP = (unsigned long) mode.bpp;
if (DMSetDisplayMode(m_hndl, sMode.csData,
(unsigned long*) &(dwBPP), NULL
//(unsigned long) &sMode
, hDisplayState
) != noErr)
{
DMEndConfigureDisplays(hDisplayState);
wxLogError(wxT("Could not set the display mode"));
return false;
}
DMEndConfigureDisplays(hDisplayState);
} }
else //DM 1.0, 1.2, 1.x else //DM 1.0, 1.2, 1.x
{ {
wxLogSysError(wxString::Format(wxT("Monitor gravitation not supported yet. dwDMVer:%u"), wxLogSysError(wxString::Format(wxT("Monitor gravitation not supported yet. dwDMVer:%u"),
(unsigned int) dwDMVer)); (unsigned int) dwDMVer));
return false; return false;
} }
return true; return true;
} }
wxDisplay::~wxDisplay() // ============================================================================
// wxDisplay::CreateFactory()
// ============================================================================
/* static */ wxDisplayFactory *wxDisplay::CreateFactory()
{ {
if ( m_priv ) return new wxDisplayFactoryMac;
{
delete m_priv;
m_priv = 0;
}
} }
#endif // wxUSE_DISPLAY #endif // wxUSE_DISPLAY

View File

@@ -1,99 +0,0 @@
/////////////////////////////////////////////////////////////////////////////
// Name: src/mgl/display.cpp
// Purpose: MGL Implementation of wxDisplay class
// Author: Wlodzimierz ABX Skiba
// Modified by:
// Created: 05/03/2006
// RCS-ID: $Id$
// Copyright: (c) Wlodzimierz Skiba
// Licence: wxWindows licence
/////////////////////////////////////////////////////////////////////////////
// For compilers that support precompilation, includes "wx.h".
#include "wx/wxprec.h"
#ifdef __BORLANDC__
#pragma hdrstop
#endif
#if wxUSE_DISPLAY
#ifndef WX_PRECOMP
#include "wx/gdicmn.h"
#endif
#include "wx/display.h"
/* static */
int wxDisplayBase::GetFromPoint ( const wxPoint& WXUNUSED(pt) )
{
// TODO
return wxNOT_FOUND;
}
/* static */
size_t wxDisplayBase::GetCount()
{
// TODO
return 1;
}
// ----------------------------------------------------------------------------
// wxDisplay ctor/dtor
// ----------------------------------------------------------------------------
wxDisplay::wxDisplay ( size_t n )
: wxDisplayBase ( n )
{
}
wxDisplay::~wxDisplay()
{
}
bool wxDisplay::IsOk() const
{
// TODO
return m_index < GetCount();
}
wxRect wxDisplay::GetGeometry() const
{
wxRect rect;
// TODO
return rect;
}
wxString wxDisplay::GetName() const
{
// TODO
return wxEmptyString;
}
wxArrayVideoModes wxDisplay::GetModes(const wxVideoMode& WXUNUSED(modeMatch)) const
{
wxArrayVideoModes modes;
// TODO
return modes;
}
wxVideoMode wxDisplay::GetCurrentMode() const
{
wxVideoMode mode;
// TODO
return mode;
}
bool wxDisplay::ChangeMode(const wxVideoMode& WXUNUSED(mode))
{
// TODO
return false;
}
bool wxDisplay::IsPrimary() const
{
// TODO
return false;
}
#endif // wxUSE_DISPLAY

File diff suppressed because it is too large Load Diff

View File

@@ -1,87 +0,0 @@
///////////////////////////////////////////////////////////////////////////
// Name: displayx11.cpp
// Purpose: Unix/X11 implementation of wxDisplay class
// Author: Brian Victor
// Modified by:
// Created: 12/05/02
// RCS-ID: $Id$
// Copyright: (c) wxWidgets team
// Licence: wxWindows licence
/////////////////////////////////////////////////////////////////////////////
// For compilers that support precompilation, includes "wx.h".
#include "wx/wxprec.h"
#ifdef __BORLANDC__
#pragma hdrstop
#endif
#include "wx/display.h"
#include "wx/intl.h"
#include "wx/log.h"
#ifndef WX_PRECOMP
#include "wx/dynarray.h"
#include "wx/gdicmn.h"
#include "wx/string.h"
#include "wx/utils.h"
#endif /* WX_PRECOMP */
#if wxUSE_DISPLAY
size_t wxDisplayBase::GetCount()
{
return 1;
}
int wxDisplayBase::GetFromPoint(const wxPoint &p)
{
return -1;
}
wxDisplay::wxDisplay(size_t index)
: wxDisplayBase ( index )
{
}
wxDisplay::~wxDisplay()
{
}
wxRect wxDisplay::GetGeometry() const
{
wxRect vRect(0,0,0,0);
return vRect;
}
int wxDisplay::GetDepth() const
{
return 24;
}
wxString wxDisplay::GetName() const
{
return wxEmptyString;
}
wxArrayVideoModes wxDisplay::GetModes(const wxVideoMode& mode) const
{
wxArrayVideoModes modes;
return modes;
}
wxVideoMode wxDisplay::GetCurrentMode() const
{
// Not implemented
return wxVideoMode();
}
bool wxDisplay::ChangeMode(const wxVideoMode& mode)
{
// Not implemented
return false;
}
#endif /* wxUSE_DISPLAY */

View File

@@ -1,272 +0,0 @@
/////////////////////////////////////////////////////////////////////////////
// Name: src/palmos/display.cpp
// Purpose: Palm OS Implementation of wxDisplay class
// Author: William Osborne - minimal working wxPalmOS port
// Modified by:
// Created: 10.13.04
// RCS-ID: $Id$
// Copyright: (c) William Osborne
// Licence: wxWindows licence
/////////////////////////////////////////////////////////////////////////////
// ===========================================================================
// declarations
// ===========================================================================
// ---------------------------------------------------------------------------
// headers
// ---------------------------------------------------------------------------
// For compilers that support precompilation, includes "wx.h".
#include "wx/wxprec.h"
#ifdef __BORLANDC__
#pragma hdrstop
#endif
#if wxUSE_DISPLAY
#ifndef WX_PRECOMP
#include "wx/app.h"
#include "wx/dynarray.h"
#include "wx/frame.h"
#endif
#include "wx/dynload.h"
#include "wx/display.h"
// ----------------------------------------------------------------------------
// macros
// ----------------------------------------------------------------------------
#ifdef _UNICODE
#define WINFUNC(x) _T(#x) L"W"
#else
#define WINFUNC(x) #x "A"
#endif
// ----------------------------------------------------------------------------
// private classes
// ----------------------------------------------------------------------------
class wxDisplayInfo
{
public:
// handle of this monitor used by MonitorXXX() functions, never NULL
HMONITOR m_hmon;
// IDirectDraw object used to control this display, may be NULL
IDirectDraw2 *m_pDD2;
// DirectDraw GUID for this display, only valid when using DirectDraw
GUID m_guid;
// the entire area of this monitor in virtual screen coordinates
wxRect m_rect;
// the display device name for this monitor, empty initially and retrieved
// on demand by DoGetName()
wxString m_devName;
wxDisplayInfo() { m_hmon = NULL; m_pDD2 = NULL; }
~wxDisplayInfo() { if ( m_pDD2 ) m_pDD2->Release(); }
};
WX_DECLARE_OBJARRAY(wxDisplayInfo, wxDisplayInfoArray);
#include "wx/arrimpl.cpp"
WX_DEFINE_OBJARRAY(wxDisplayInfoArray);
// this module is used to cleanup gs_displays array
class wxDisplayModule : public wxModule
{
public:
virtual bool OnInit() { return true; }
virtual void OnExit();
DECLARE_DYNAMIC_CLASS(wxDisplayModule)
};
IMPLEMENT_DYNAMIC_CLASS(wxDisplayModule, wxModule)
// ----------------------------------------------------------------------------
// globals
// ----------------------------------------------------------------------------
// this is not really MT-unsafe as wxDisplay is only going to be used from the
// main thread, i.e. we consider that it's a GUI class and so don't protect it
static wxDisplayInfoArray *gs_displays = NULL;
// ===========================================================================
// implementation
// ===========================================================================
// ----------------------------------------------------------------------------
// local functions
// ----------------------------------------------------------------------------
// initialize gs_displays using DirectX functions
static bool DoInitDirectX()
{
return false;
}
// initialize gs_displays using the standard Windows functions
static void DoInitStdWindows()
{
}
// this function must be called before accessing gs_displays array as it
// creates and initializes it
static void InitDisplays()
{
}
// convert a DEVMODE to our wxVideoMode
wxVideoMode ConvertToVideoMode(const DEVMODE& dm)
{
return wxVideoMode(160,
160,
16,
0);
}
// ----------------------------------------------------------------------------
// wxDisplayModule
// ----------------------------------------------------------------------------
void wxDisplayModule::OnExit()
{
}
// ---------------------------------------------------------------------------
// wxDisplay
// ---------------------------------------------------------------------------
/* static */
void wxDisplay::UseDirectX(bool useDX)
{
}
// helper of GetFromPoint() and GetFromWindow()
static int DisplayFromHMONITOR(HMONITOR hmon)
{
return wxNOT_FOUND;
}
/* static */
size_t wxDisplayBase::GetCount()
{
return 0;
}
/* static */
int wxDisplayBase::GetFromPoint ( const wxPoint& pt )
{
return 0;
}
/* static */
int wxDisplayBase::GetFromWindow(wxWindow *window)
{
return 0;
}
// ----------------------------------------------------------------------------
// wxDisplay ctor/dtor
// ----------------------------------------------------------------------------
wxDisplay::wxDisplay ( size_t n )
: wxDisplayBase ( n )
{
}
wxDisplay::~wxDisplay()
{
}
// ----------------------------------------------------------------------------
// wxDisplay simple accessors
// ----------------------------------------------------------------------------
bool wxDisplay::IsOk() const
{
return false;
}
wxRect wxDisplay::GetGeometry() const
{
wxRect rect;
return rect;
}
wxString wxDisplay::GetName() const
{
wxString ret;
return ret;
}
wxString wxDisplay::GetNameForEnumSettings() const
{
wxString ret;
return ret;
}
// ----------------------------------------------------------------------------
// video modes enumeration
// ----------------------------------------------------------------------------
wxArrayVideoModes
wxDisplay::DoGetModesDirectX(const wxVideoMode& WXUNUSED(modeMatch)) const
{
wxArrayVideoModes modes;
return modes;
}
wxArrayVideoModes
wxDisplay::DoGetModesWindows(const wxVideoMode& modeMatch) const
{
wxArrayVideoModes modes;
return modes;
}
wxArrayVideoModes wxDisplay::GetModes(const wxVideoMode& modeMatch) const
{
return gs_useDirectX ? DoGetModesDirectX(modeMatch)
: DoGetModesWindows(modeMatch);
}
wxVideoMode wxDisplay::GetCurrentMode() const
{
wxVideoMode mode;
return mode;
}
// ----------------------------------------------------------------------------
// video mode switching
// ----------------------------------------------------------------------------
bool wxDisplay::DoChangeModeDirectX(const wxVideoMode& mode)
{
return false;
}
bool wxDisplay::DoChangeModeWindows(const wxVideoMode& mode)
{
return false;
}
bool wxDisplay::ChangeMode(const wxVideoMode& mode)
{
return gs_useDirectX ? DoChangeModeDirectX(mode)
: DoChangeModeWindows(mode);
}
#endif // wxUSE_DISPLAY

View File

@@ -1,7 +1,7 @@
/////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////
// Name: displayx11.cpp // Name: src/unix/displayx11.cpp
// Purpose: Unix/X11 implementation of wxDisplay class // Purpose: Unix/X11 implementation of wxDisplay class
// Author: Brian Victor // Author: Brian Victor, Vadim Zeitlin
// Modified by: // Modified by:
// Created: 12/05/02 // Created: 12/05/02
// RCS-ID: $Id$ // RCS-ID: $Id$
@@ -9,6 +9,14 @@
// Licence: wxWindows licence // Licence: wxWindows licence
///////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////
// ============================================================================
// declarations
// ============================================================================
// ----------------------------------------------------------------------------
// headers
// ----------------------------------------------------------------------------
// For compilers that support precompilation, includes "wx.h". // For compilers that support precompilation, includes "wx.h".
#include "wx/wxprec.h" #include "wx/wxprec.h"
@@ -17,6 +25,7 @@
#endif #endif
#include "wx/display.h" #include "wx/display.h"
#include "wx/display_impl.h"
#include "wx/intl.h" #include "wx/intl.h"
#include "wx/log.h" #include "wx/log.h"
@@ -31,132 +40,119 @@
/* These must be included after the wx files. Otherwise the Data macro in /* These must be included after the wx files. Otherwise the Data macro in
* Xlibint.h conflicts with a function declaration in wx/list.h. */ * Xlibint.h conflicts with a function declaration in wx/list.h. */
extern "C" { extern "C"
#include <X11/Xlib.h> {
#ifndef __VMS #include <X11/Xlib.h>
#include <X11/Xlibint.h> #include <X11/Xlibint.h>
# include <X11/extensions/Xinerama.h>
#ifdef HAVE_X11_EXTENSIONS_XF86VMODE_H #include <X11/extensions/Xinerama.h>
#include <X11/extensions/xf86vmode.h> #ifdef HAVE_X11_EXTENSIONS_XF86VMODE_H
#endif #include <X11/extensions/xf86vmode.h>
#endif #endif
} }
class wxDisplayUnixPriv // ----------------------------------------------------------------------------
// helper class to automatically free XineramaQueryScreens() return value
// ----------------------------------------------------------------------------
class ScreensInfo
{ {
public: public:
wxRect m_rect; ScreensInfo()
int m_depth; {
m_screens = XineramaQueryScreens((Display *)wxGetDisplay(), &m_num);
}
~ScreensInfo()
{
XFree(m_screens);
}
operator const XineramaScreenInfo *() const { return m_screens; }
size_t GetCount() const { return wx_static_cast(size_t, m_num); }
private:
XineramaScreenInfo *m_screens;
int m_num;
}; };
size_t wxDisplayBase::GetCount() // ----------------------------------------------------------------------------
// display and display factory classes
// ----------------------------------------------------------------------------
class WXDLLEXPORT wxDisplayImplX11 : public wxDisplayImpl
{ {
Display *disp = (Display*)wxGetDisplay(); public:
wxDisplayImplX11(const XineramaScreenInfo& info)
#ifndef __VMS : m_rect(info.x_org, info.y_org, info.width, info.height)
if ( XineramaIsActive(disp) )
{
XineramaScreenInfo *screenarr;
int numscreens;
screenarr = XineramaQueryScreens(disp, &numscreens);
XFree(screenarr);
return numscreens;
}
else
#endif
{
return 1;
}
}
int wxDisplayBase::GetFromPoint(const wxPoint &p)
{
Display *disp = (Display*)wxGetDisplay();
#ifndef __VMS
if ( XineramaIsActive(disp) )
{
int which_screen = -1;
XineramaScreenInfo *screenarr;
int numscreens;
screenarr = XineramaQueryScreens(disp, &numscreens);
int i;
for (i = 0; i < numscreens; ++i)
{ {
if (p.x >= screenarr[i].x_org &&
p.x < screenarr[i].x_org + screenarr[i].width &&
p.y >= screenarr[i].y_org &&
p.y < screenarr[i].y_org + screenarr[i].height)
{
which_screen = i;
}
} }
XFree(screenarr); virtual wxRect GetGeometry() const { return m_rect; }
return which_screen; virtual wxString GetName() const { return wxString(); }
}
else virtual wxArrayVideoModes GetModes(const wxVideoMode& mode) const;
#endif virtual wxVideoMode GetCurrentMode() const;
{ virtual bool ChangeMode(const wxVideoMode& mode);
wxSize size = wxGetDisplaySize();
if (p.x >= 0 && private:
p.x < size.GetWidth() && wxRect m_rect;
p.y >= 0 && int m_depth;
p.y < size.GetHeight())
DECLARE_NO_COPY_CLASS(wxDisplayImplX11)
};
class wxDisplayFactoryX11 : public wxDisplayFactory
{
public:
wxDisplayFactoryX11();
virtual wxDisplayImpl *CreateDisplay(size_t n);
virtual size_t GetCount();
virtual int GetFromPoint(const wxPoint& pt);
protected:
DECLARE_NO_COPY_CLASS(wxDisplayFactoryX11)
};
// ============================================================================
// wxDisplayFactoryX11 implementation
// ============================================================================
size_t wxDisplayFactoryX11::GetCount()
{
return ScreensInfo().GetCount();
}
int wxDisplayFactoryX11::GetFromPoint(const wxPoint& p)
{
ScreensInfo screens;
const size_t numscreens(screens.GetCount());
for ( size_t i = 0; i < numscreens; ++i )
{ {
return 0; const XineramaScreenInfo& s = screens[i];
if ( p.x >= s.x_org && p.x < s.x_org + s.width &&
p.y >= s.y_org && p.y < s.y_org + s.height )
{
return i;
}
} }
return -1; return wxNOT_FOUND;
}
} }
wxDisplay::wxDisplay(size_t index) : wxDisplayBase ( index ), m_priv( new wxDisplayUnixPriv ) wxDisplayImpl *wxDisplayFactoryX11::CreateDisplay(size_t n)
{ {
Display *disp = (Display*)wxGetDisplay(); ScreensInfo screens;
#ifndef __VMS return n < screens.GetCount() ? new wxDisplayImplX11(screens[n]) : NULL;
if ( XineramaIsActive(disp) )
{
XineramaScreenInfo *screenarr;
int numscreens;
screenarr = XineramaQueryScreens(disp, &numscreens);
m_priv->m_rect = wxRect(screenarr[index].x_org, screenarr[index].y_org,
screenarr[index].width, screenarr[index].height);
m_priv->m_depth = DefaultDepth(disp, DefaultScreen(disp));
XFree(screenarr);
}
else
#endif
{
wxSize size = wxGetDisplaySize();
m_priv->m_rect = wxRect(0, 0, size.GetWidth(), size.GetHeight());
m_priv->m_depth = wxDisplayDepth();
}
}
wxDisplay::~wxDisplay()
{
delete m_priv;
}
wxRect wxDisplay::GetGeometry() const
{
return m_priv->m_rect;
}
int wxDisplay::GetDepth() const
{
return m_priv->m_depth;
}
wxString wxDisplay::GetName() const
{
return wxEmptyString;
} }
// ============================================================================
// wxDisplayImplX11 implementation
// ============================================================================
#ifdef HAVE_X11_EXTENSIONS_XF86VMODE_H #ifdef HAVE_X11_EXTENSIONS_XF86VMODE_H
@@ -269,19 +265,19 @@ bool wxDisplay::ChangeMode(const wxVideoMode& mode)
wxArrayVideoModes wxDisplay::GetModes(const wxVideoMode& mode) const wxArrayVideoModes wxDisplay::GetModes(const wxVideoMode& mode) const
{ {
Display *disp = (Display*)wxGetDisplay(); int count_return;
int count_return; int* depths = XListDepths((Display*)wxGetDisplay(), 0, &count_return);
int* depths = XListDepths(disp, 0, &count_return); wxArrayVideoModes modes;
wxArrayVideoModes modes; if ( depths )
if (depths)
{
int x;
for (x = 0; x < count_return; ++x)
{ {
modes.Add(wxVideoMode(m_priv->m_rect.GetWidth(), m_priv->m_rect.GetHeight(), depths[x])); for ( int x = 0; x < count_return; ++x )
{
modes.Add(wxVideoMode(m_rect.GetWidth(), m_rect.GetHeight(), depths[x]));
}
XFree(depths);
} }
} return modes;
return modes;
} }
wxVideoMode wxDisplay::GetCurrentMode() const wxVideoMode wxDisplay::GetCurrentMode() const
@@ -298,4 +294,16 @@ bool wxDisplay::ChangeMode(const wxVideoMode& mode)
#endif // !HAVE_X11_EXTENSIONS_XF86VMODE_H #endif // !HAVE_X11_EXTENSIONS_XF86VMODE_H
// ============================================================================
// wxDisplay::CreateFactory()
// ============================================================================
/* static */ wxDisplayFactory *wxDisplay::CreateFactory()
{
Display *disp = (Display*)wxGetDisplay();
return XineramaIsActive(disp) ? new wxDisplayFactoryX11
: new wxDisplayFactorySingle;
}
#endif /* wxUSE_DISPLAY */ #endif /* wxUSE_DISPLAY */