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"
38 #include "wx/arrimpl.cpp"
39 WX_DEFINE_OBJARRAY(wxArrayVideoModes
)
41 const wxVideoMode wxDefaultVideoMode
;
43 #endif // wxUSE_DISPLAY
45 // ----------------------------------------------------------------------------
47 // ----------------------------------------------------------------------------
49 // the factory object used by wxDisplay
51 // created on demand and destroyed by wxDisplayModule
52 static wxDisplayFactory
*gs_factory
= NULL
;
54 // ----------------------------------------------------------------------------
55 // wxDisplayImplSingle: trivial implementation working for main display only
56 // ----------------------------------------------------------------------------
58 class WXDLLEXPORT wxDisplayImplSingle
: public wxDisplayImpl
61 wxDisplayImplSingle() : wxDisplayImpl(0) { }
63 virtual wxRect
GetGeometry() const
66 wxDisplaySize(&r
.width
, &r
.height
);
70 virtual wxRect
GetClientArea() const { return wxGetClientDisplayRect(); }
72 virtual wxString
GetName() const { return wxString(); }
75 // no video modes support for us, provide just the stubs
77 virtual wxArrayVideoModes
GetModes(const wxVideoMode
& WXUNUSED(mode
)) const
79 return wxArrayVideoModes();
82 virtual wxVideoMode
GetCurrentMode() const { return wxVideoMode(); }
84 virtual bool ChangeMode(const wxVideoMode
& WXUNUSED(mode
)) { return false; }
85 #endif // wxUSE_DISPLAY
88 DECLARE_NO_COPY_CLASS(wxDisplayImplSingle
)
91 // ----------------------------------------------------------------------------
92 // wxDisplayModule is used to cleanup gs_factory
93 // ----------------------------------------------------------------------------
95 class wxDisplayModule
: public wxModule
98 virtual bool OnInit() { return true; }
108 DECLARE_DYNAMIC_CLASS(wxDisplayModule
)
111 IMPLEMENT_DYNAMIC_CLASS(wxDisplayModule
, wxModule
)
113 // ============================================================================
114 // wxDisplay implementation
115 // ============================================================================
117 // ----------------------------------------------------------------------------
119 // ----------------------------------------------------------------------------
121 wxDisplay::wxDisplay(size_t n
)
123 wxASSERT_MSG( n
< GetCount(),
124 wxT("An invalid index was passed to wxDisplay") );
126 m_impl
= Factory().CreateDisplay(n
);
129 wxDisplay::~wxDisplay()
134 // ----------------------------------------------------------------------------
135 // static functions forwarded to wxDisplayFactory
136 // ----------------------------------------------------------------------------
138 /* static */ size_t wxDisplay::GetCount()
140 return Factory().GetCount();
143 /* static */ int wxDisplay::GetFromPoint(const wxPoint
& pt
)
145 return Factory().GetFromPoint(pt
);
148 /* static */ int wxDisplay::GetFromWindow(wxWindow
*window
)
150 wxCHECK_MSG( window
, wxNOT_FOUND
, _T("invalid window") );
152 return Factory().GetFromWindow(window
);
155 // ----------------------------------------------------------------------------
156 // functions forwarded to wxDisplayImpl
157 // ----------------------------------------------------------------------------
159 wxRect
wxDisplay::GetGeometry() const
161 wxCHECK_MSG( IsOk(), wxRect(), _T("invalid wxDisplay object") );
163 return m_impl
->GetGeometry();
166 wxRect
wxDisplay::GetClientArea() const
168 wxCHECK_MSG( IsOk(), wxRect(), _T("invalid wxDisplay object") );
170 return m_impl
->GetClientArea();
173 wxString
wxDisplay::GetName() const
175 wxCHECK_MSG( IsOk(), wxString(), _T("invalid wxDisplay object") );
177 return m_impl
->GetName();
180 bool wxDisplay::IsPrimary() const
182 return m_impl
&& m_impl
->GetIndex() == 0;
187 wxArrayVideoModes
wxDisplay::GetModes(const wxVideoMode
& mode
) const
189 wxCHECK_MSG( IsOk(), wxArrayVideoModes(), _T("invalid wxDisplay object") );
191 return m_impl
->GetModes(mode
);
194 wxVideoMode
wxDisplay::GetCurrentMode() const
196 wxCHECK_MSG( IsOk(), wxVideoMode(), _T("invalid wxDisplay object") );
198 return m_impl
->GetCurrentMode();
201 bool wxDisplay::ChangeMode(const wxVideoMode
& mode
)
203 wxCHECK_MSG( IsOk(), false, _T("invalid wxDisplay object") );
205 return m_impl
->ChangeMode(mode
);
208 #endif // wxUSE_DIRECTDRAW
210 // ----------------------------------------------------------------------------
211 // static functions implementation
212 // ----------------------------------------------------------------------------
214 // if wxUSE_DISPLAY == 1 this is implemented in port-specific code
217 /* static */ wxDisplayFactory
*wxDisplay::CreateFactory()
219 return new wxDisplayFactorySingle
;
222 #endif // !wxUSE_DISPLAY
224 /* static */ wxDisplayFactory
& wxDisplay::Factory()
228 gs_factory
= CreateFactory();
234 // ============================================================================
235 // wxDisplayFactory implementation
236 // ============================================================================
238 int wxDisplayFactory::GetFromWindow(wxWindow
*window
)
240 // consider that the window belongs to the display containing its centre
241 const wxRect
r(window
->GetRect());
242 return GetFromPoint(wxPoint(r
.x
+ r
.width
/2, r
.y
+ r
.height
/2));
245 // ============================================================================
246 // wxDisplayFactorySingle implementation
247 // ============================================================================
250 wxDisplayImpl
*wxDisplayFactorySingle::CreateDisplay(size_t n
)
252 // we recognize the main display only
253 return n
!= 0 ? NULL
: new wxDisplayImplSingle
;
256 int wxDisplayFactorySingle::GetFromPoint(const wxPoint
& pt
)
258 if ( pt
.x
>= 0 && pt
.y
>= 0 )
261 wxDisplaySize(&w
, &h
);
263 if ( pt
.x
< w
&& pt
.y
< h
)
267 // the point is outside of the screen