1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: src/common/dpycmn.cpp
3 // Purpose: wxDisplay and wxDisplayImplSingle implementation
4 // Author: Vadim Zeitlin
8 // Copyright: (c) 2003-2006 Vadim Zeitlin <vadim@wxwindows.org>
9 // License: wxWindows licence
10 ///////////////////////////////////////////////////////////////////////////////
12 // ============================================================================
14 // ============================================================================
16 // ----------------------------------------------------------------------------
18 // ----------------------------------------------------------------------------
20 // For compilers that support precompilation, includes "wx.h".
21 #include "wx/wxprec.h"
28 #include "wx/gdicmn.h"
29 #include "wx/window.h"
32 #include "wx/display.h"
33 #include "wx/display_impl.h"
34 #include "wx/module.h"
35 #include "wx/gdicmn.h" // for wxDisplaySize()
39 #include "wx/arrimpl.cpp"
40 WX_DEFINE_OBJARRAY(wxArrayVideoModes
)
42 const wxVideoMode wxDefaultVideoMode
;
44 #endif // wxUSE_DISPLAY
46 // ----------------------------------------------------------------------------
48 // ----------------------------------------------------------------------------
50 // the factory object used by wxDisplay
52 // created on demand and destroyed by wxDisplayModule
53 static wxDisplayFactory
*gs_factory
= NULL
;
55 // ----------------------------------------------------------------------------
56 // wxDisplayImplSingle: trivial implementation working for main display only
57 // ----------------------------------------------------------------------------
59 class WXDLLEXPORT wxDisplayImplSingle
: public wxDisplayImpl
62 wxDisplayImplSingle() : wxDisplayImpl(0) { }
64 virtual wxRect
GetGeometry() const
67 wxDisplaySize(&r
.width
, &r
.height
);
71 virtual wxRect
GetClientArea() const { return wxGetClientDisplayRect(); }
73 virtual wxString
GetName() const { return wxString(); }
76 // no video modes support for us, provide just the stubs
78 virtual wxArrayVideoModes
GetModes(const wxVideoMode
& WXUNUSED(mode
)) const
80 return wxArrayVideoModes();
83 virtual wxVideoMode
GetCurrentMode() const { return wxVideoMode(); }
85 virtual bool ChangeMode(const wxVideoMode
& WXUNUSED(mode
)) { return false; }
86 #endif // wxUSE_DISPLAY
89 DECLARE_NO_COPY_CLASS(wxDisplayImplSingle
)
92 // ----------------------------------------------------------------------------
93 // wxDisplayModule is used to cleanup gs_factory
94 // ----------------------------------------------------------------------------
96 class wxDisplayModule
: public wxModule
99 virtual bool OnInit() { return true; }
100 virtual void OnExit()
109 DECLARE_DYNAMIC_CLASS(wxDisplayModule
)
112 IMPLEMENT_DYNAMIC_CLASS(wxDisplayModule
, wxModule
)
114 // ============================================================================
115 // wxDisplay implementation
116 // ============================================================================
118 // ----------------------------------------------------------------------------
120 // ----------------------------------------------------------------------------
122 wxDisplay::wxDisplay(size_t n
)
124 wxASSERT_MSG( n
< GetCount(),
125 wxT("An invalid index was passed to wxDisplay") );
127 m_impl
= Factory().CreateDisplay(n
);
130 wxDisplay::~wxDisplay()
135 // ----------------------------------------------------------------------------
136 // static functions forwarded to wxDisplayFactory
137 // ----------------------------------------------------------------------------
139 /* static */ size_t wxDisplay::GetCount()
141 return Factory().GetCount();
144 /* static */ int wxDisplay::GetFromPoint(const wxPoint
& pt
)
146 return Factory().GetFromPoint(pt
);
149 /* static */ int wxDisplay::GetFromWindow(wxWindow
*window
)
151 wxCHECK_MSG( window
, wxNOT_FOUND
, _T("invalid window") );
153 return Factory().GetFromWindow(window
);
156 // ----------------------------------------------------------------------------
157 // functions forwarded to wxDisplayImpl
158 // ----------------------------------------------------------------------------
160 wxRect
wxDisplay::GetGeometry() const
162 wxCHECK_MSG( IsOk(), wxRect(), _T("invalid wxDisplay object") );
164 return m_impl
->GetGeometry();
167 wxRect
wxDisplay::GetClientArea() const
169 wxCHECK_MSG( IsOk(), wxRect(), _T("invalid wxDisplay object") );
171 return m_impl
->GetClientArea();
174 wxString
wxDisplay::GetName() const
176 wxCHECK_MSG( IsOk(), wxString(), _T("invalid wxDisplay object") );
178 return m_impl
->GetName();
181 bool wxDisplay::IsPrimary() const
183 return m_impl
&& m_impl
->GetIndex() == 0;
188 wxArrayVideoModes
wxDisplay::GetModes(const wxVideoMode
& mode
) const
190 wxCHECK_MSG( IsOk(), wxArrayVideoModes(), _T("invalid wxDisplay object") );
192 return m_impl
->GetModes(mode
);
195 wxVideoMode
wxDisplay::GetCurrentMode() const
197 wxCHECK_MSG( IsOk(), wxVideoMode(), _T("invalid wxDisplay object") );
199 return m_impl
->GetCurrentMode();
202 bool wxDisplay::ChangeMode(const wxVideoMode
& mode
)
204 wxCHECK_MSG( IsOk(), false, _T("invalid wxDisplay object") );
206 return m_impl
->ChangeMode(mode
);
209 #endif // wxUSE_DIRECTDRAW
211 // ----------------------------------------------------------------------------
212 // static functions implementation
213 // ----------------------------------------------------------------------------
215 // if wxUSE_DISPLAY == 1 this is implemented in port-specific code
218 /* static */ wxDisplayFactory
*wxDisplay::CreateFactory()
220 return new wxDisplayFactorySingle
;
223 #endif // !wxUSE_DISPLAY
225 /* static */ wxDisplayFactory
& wxDisplay::Factory()
229 gs_factory
= CreateFactory();
235 // ============================================================================
236 // wxDisplayFactory implementation
237 // ============================================================================
239 int wxDisplayFactory::GetFromWindow(wxWindow
*window
)
241 // consider that the window belongs to the display containing its centre
242 const wxRect
r(window
->GetRect());
243 return GetFromPoint(wxPoint(r
.x
+ r
.width
/2, r
.y
+ r
.height
/2));
246 // ============================================================================
247 // wxDisplayFactorySingle implementation
248 // ============================================================================
251 wxDisplayImpl
*wxDisplayFactorySingle::CreateDisplay(size_t n
)
253 // we recognize the main display only
254 return n
!= 0 ? NULL
: new wxDisplayImplSingle
;
257 int wxDisplayFactorySingle::GetFromPoint(const wxPoint
& pt
)
259 if ( pt
.x
>= 0 && pt
.y
>= 0 )
262 wxDisplaySize(&w
, &h
);
264 if ( pt
.x
< w
&& pt
.y
< h
)
268 // the point is outside of the screen