1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: src/common/dpycmn.cpp
3 // Purpose: wxDisplay and wxDisplayImplSingle implementation
4 // Author: Vadim Zeitlin
7 // Copyright: (c) 2003-2006 Vadim Zeitlin <vadim@wxwindows.org>
8 // Licence: wxWindows licence
9 ///////////////////////////////////////////////////////////////////////////////
11 // ============================================================================
13 // ============================================================================
15 // ----------------------------------------------------------------------------
17 // ----------------------------------------------------------------------------
19 // For compilers that support precompilation, includes "wx.h".
20 #include "wx/wxprec.h"
27 #include "wx/gdicmn.h"
28 #include "wx/window.h"
29 #include "wx/module.h"
32 #include "wx/display.h"
33 #include "wx/display_impl.h"
37 #include "wx/arrimpl.cpp"
38 WX_DEFINE_OBJARRAY(wxArrayVideoModes
)
40 const wxVideoMode wxDefaultVideoMode
;
42 #endif // wxUSE_DISPLAY
44 // ----------------------------------------------------------------------------
46 // ----------------------------------------------------------------------------
48 // the factory object used by wxDisplay
50 // created on demand and destroyed by wxDisplayModule
51 static wxDisplayFactory
*gs_factory
= NULL
;
53 // ----------------------------------------------------------------------------
54 // wxDisplayImplSingle: trivial implementation working for main display only
55 // ----------------------------------------------------------------------------
57 class WXDLLEXPORT wxDisplayImplSingle
: public wxDisplayImpl
60 wxDisplayImplSingle() : wxDisplayImpl(0) { }
62 virtual wxRect
GetGeometry() const
65 wxDisplaySize(&r
.width
, &r
.height
);
69 virtual wxRect
GetClientArea() const { return wxGetClientDisplayRect(); }
71 virtual wxString
GetName() const { return wxString(); }
74 // no video modes support for us, provide just the stubs
76 virtual wxArrayVideoModes
GetModes(const wxVideoMode
& WXUNUSED(mode
)) const
78 return wxArrayVideoModes();
81 virtual wxVideoMode
GetCurrentMode() const { return wxVideoMode(); }
83 virtual bool ChangeMode(const wxVideoMode
& WXUNUSED(mode
)) { return false; }
84 #endif // wxUSE_DISPLAY
87 wxDECLARE_NO_COPY_CLASS(wxDisplayImplSingle
);
90 // ----------------------------------------------------------------------------
91 // wxDisplayModule is used to cleanup gs_factory
92 // ----------------------------------------------------------------------------
94 class wxDisplayModule
: public wxModule
97 virtual bool OnInit() { return true; }
100 wxDELETE(gs_factory
);
103 DECLARE_DYNAMIC_CLASS(wxDisplayModule
)
106 IMPLEMENT_DYNAMIC_CLASS(wxDisplayModule
, wxModule
)
108 // ============================================================================
109 // wxDisplay implementation
110 // ============================================================================
112 // ----------------------------------------------------------------------------
114 // ----------------------------------------------------------------------------
116 wxDisplay::wxDisplay(unsigned n
)
118 wxASSERT_MSG( n
< GetCount(),
119 wxT("An invalid index was passed to wxDisplay") );
121 m_impl
= Factory().CreateDisplay(n
);
124 wxDisplay::~wxDisplay()
129 // ----------------------------------------------------------------------------
130 // static functions forwarded to wxDisplayFactory
131 // ----------------------------------------------------------------------------
133 /* static */ unsigned wxDisplay::GetCount()
135 return Factory().GetCount();
138 /* static */ int wxDisplay::GetFromPoint(const wxPoint
& pt
)
140 return Factory().GetFromPoint(pt
);
143 /* static */ int wxDisplay::GetFromWindow(const wxWindow
*window
)
145 wxCHECK_MSG( window
, wxNOT_FOUND
, wxT("invalid window") );
147 return Factory().GetFromWindow(window
);
150 // ----------------------------------------------------------------------------
151 // functions forwarded to wxDisplayImpl
152 // ----------------------------------------------------------------------------
154 wxRect
wxDisplay::GetGeometry() const
156 wxCHECK_MSG( IsOk(), wxRect(), wxT("invalid wxDisplay object") );
158 return m_impl
->GetGeometry();
161 wxRect
wxDisplay::GetClientArea() const
163 wxCHECK_MSG( IsOk(), wxRect(), wxT("invalid wxDisplay object") );
165 return m_impl
->GetClientArea();
168 wxString
wxDisplay::GetName() const
170 wxCHECK_MSG( IsOk(), wxString(), wxT("invalid wxDisplay object") );
172 return m_impl
->GetName();
175 bool wxDisplay::IsPrimary() const
177 return m_impl
&& m_impl
->GetIndex() == 0;
182 wxArrayVideoModes
wxDisplay::GetModes(const wxVideoMode
& mode
) const
184 wxCHECK_MSG( IsOk(), wxArrayVideoModes(), wxT("invalid wxDisplay object") );
186 return m_impl
->GetModes(mode
);
189 wxVideoMode
wxDisplay::GetCurrentMode() const
191 wxCHECK_MSG( IsOk(), wxVideoMode(), wxT("invalid wxDisplay object") );
193 return m_impl
->GetCurrentMode();
196 bool wxDisplay::ChangeMode(const wxVideoMode
& mode
)
198 wxCHECK_MSG( IsOk(), false, wxT("invalid wxDisplay object") );
200 return m_impl
->ChangeMode(mode
);
203 #endif // wxUSE_DISPLAY
205 // ----------------------------------------------------------------------------
206 // static functions implementation
207 // ----------------------------------------------------------------------------
209 // if wxUSE_DISPLAY == 1 this is implemented in port-specific code
212 /* static */ wxDisplayFactory
*wxDisplay::CreateFactory()
214 return new wxDisplayFactorySingle
;
217 #endif // !wxUSE_DISPLAY
219 /* static */ wxDisplayFactory
& wxDisplay::Factory()
223 gs_factory
= CreateFactory();
229 // ============================================================================
230 // wxDisplayFactory implementation
231 // ============================================================================
233 int wxDisplayFactory::GetFromWindow(const wxWindow
*window
)
235 // consider that the window belongs to the display containing its centre
236 const wxRect
r(window
->GetScreenRect());
237 return GetFromPoint(wxPoint(r
.x
+ r
.width
/2, r
.y
+ r
.height
/2));
240 // ============================================================================
241 // wxDisplayFactorySingle implementation
242 // ============================================================================
245 wxDisplayImpl
*wxDisplayFactorySingle::CreateDisplay(unsigned n
)
247 // we recognize the main display only
248 return n
!= 0 ? NULL
: new wxDisplayImplSingle
;
251 int wxDisplayFactorySingle::GetFromPoint(const wxPoint
& pt
)
253 if ( pt
.x
>= 0 && pt
.y
>= 0 )
256 wxDisplaySize(&w
, &h
);
258 if ( pt
.x
< w
&& pt
.y
< h
)
262 // the point is outside of the screen