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 // Licence: 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"
30 #include "wx/module.h"
33 #include "wx/display.h"
34 #include "wx/display_impl.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 wxDECLARE_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; }
101 wxDELETE(gs_factory
);
104 DECLARE_DYNAMIC_CLASS(wxDisplayModule
)
107 IMPLEMENT_DYNAMIC_CLASS(wxDisplayModule
, wxModule
)
109 // ============================================================================
110 // wxDisplay implementation
111 // ============================================================================
113 // ----------------------------------------------------------------------------
115 // ----------------------------------------------------------------------------
117 wxDisplay::wxDisplay(unsigned n
)
119 wxASSERT_MSG( n
< GetCount(),
120 wxT("An invalid index was passed to wxDisplay") );
122 m_impl
= Factory().CreateDisplay(n
);
125 wxDisplay::~wxDisplay()
130 // ----------------------------------------------------------------------------
131 // static functions forwarded to wxDisplayFactory
132 // ----------------------------------------------------------------------------
134 /* static */ unsigned wxDisplay::GetCount()
136 return Factory().GetCount();
139 /* static */ int wxDisplay::GetFromPoint(const wxPoint
& pt
)
141 return Factory().GetFromPoint(pt
);
144 /* static */ int wxDisplay::GetFromWindow(const wxWindow
*window
)
146 wxCHECK_MSG( window
, wxNOT_FOUND
, wxT("invalid window") );
148 return Factory().GetFromWindow(window
);
151 // ----------------------------------------------------------------------------
152 // functions forwarded to wxDisplayImpl
153 // ----------------------------------------------------------------------------
155 wxRect
wxDisplay::GetGeometry() const
157 wxCHECK_MSG( IsOk(), wxRect(), wxT("invalid wxDisplay object") );
159 return m_impl
->GetGeometry();
162 wxRect
wxDisplay::GetClientArea() const
164 wxCHECK_MSG( IsOk(), wxRect(), wxT("invalid wxDisplay object") );
166 return m_impl
->GetClientArea();
169 wxString
wxDisplay::GetName() const
171 wxCHECK_MSG( IsOk(), wxString(), wxT("invalid wxDisplay object") );
173 return m_impl
->GetName();
176 bool wxDisplay::IsPrimary() const
178 return m_impl
&& m_impl
->GetIndex() == 0;
183 wxArrayVideoModes
wxDisplay::GetModes(const wxVideoMode
& mode
) const
185 wxCHECK_MSG( IsOk(), wxArrayVideoModes(), wxT("invalid wxDisplay object") );
187 return m_impl
->GetModes(mode
);
190 wxVideoMode
wxDisplay::GetCurrentMode() const
192 wxCHECK_MSG( IsOk(), wxVideoMode(), wxT("invalid wxDisplay object") );
194 return m_impl
->GetCurrentMode();
197 bool wxDisplay::ChangeMode(const wxVideoMode
& mode
)
199 wxCHECK_MSG( IsOk(), false, wxT("invalid wxDisplay object") );
201 return m_impl
->ChangeMode(mode
);
204 #endif // wxUSE_DISPLAY
206 // ----------------------------------------------------------------------------
207 // static functions implementation
208 // ----------------------------------------------------------------------------
210 // if wxUSE_DISPLAY == 1 this is implemented in port-specific code
213 /* static */ wxDisplayFactory
*wxDisplay::CreateFactory()
215 return new wxDisplayFactorySingle
;
218 #endif // !wxUSE_DISPLAY
220 /* static */ wxDisplayFactory
& wxDisplay::Factory()
224 gs_factory
= CreateFactory();
230 // ============================================================================
231 // wxDisplayFactory implementation
232 // ============================================================================
234 int wxDisplayFactory::GetFromWindow(const wxWindow
*window
)
236 // consider that the window belongs to the display containing its centre
237 const wxRect
r(window
->GetRect());
238 return GetFromPoint(wxPoint(r
.x
+ r
.width
/2, r
.y
+ r
.height
/2));
241 // ============================================================================
242 // wxDisplayFactorySingle implementation
243 // ============================================================================
246 wxDisplayImpl
*wxDisplayFactorySingle::CreateDisplay(unsigned n
)
248 // we recognize the main display only
249 return n
!= 0 ? NULL
: new wxDisplayImplSingle
;
252 int wxDisplayFactorySingle::GetFromPoint(const wxPoint
& pt
)
254 if ( pt
.x
>= 0 && pt
.y
>= 0 )
257 wxDisplaySize(&w
, &h
);
259 if ( pt
.x
< w
&& pt
.y
< h
)
263 // the point is outside of the screen