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 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 DECLARE_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; }
107 DECLARE_DYNAMIC_CLASS(wxDisplayModule
)
110 IMPLEMENT_DYNAMIC_CLASS(wxDisplayModule
, wxModule
)
112 // ============================================================================
113 // wxDisplay implementation
114 // ============================================================================
116 // ----------------------------------------------------------------------------
118 // ----------------------------------------------------------------------------
120 wxDisplay::wxDisplay(size_t n
)
122 wxASSERT_MSG( n
< GetCount(),
123 wxT("An invalid index was passed to wxDisplay") );
125 m_impl
= Factory().CreateDisplay(n
);
128 wxDisplay::~wxDisplay()
133 // ----------------------------------------------------------------------------
134 // static functions forwarded to wxDisplayFactory
135 // ----------------------------------------------------------------------------
137 /* static */ size_t wxDisplay::GetCount()
139 return Factory().GetCount();
142 /* static */ int wxDisplay::GetFromPoint(const wxPoint
& pt
)
144 return Factory().GetFromPoint(pt
);
147 /* static */ int wxDisplay::GetFromWindow(wxWindow
*window
)
149 wxCHECK_MSG( window
, wxNOT_FOUND
, _T("invalid window") );
151 return Factory().GetFromWindow(window
);
154 // ----------------------------------------------------------------------------
155 // functions forwarded to wxDisplayImpl
156 // ----------------------------------------------------------------------------
158 wxRect
wxDisplay::GetGeometry() const
160 wxCHECK_MSG( IsOk(), wxRect(), _T("invalid wxDisplay object") );
162 return m_impl
->GetGeometry();
165 wxString
wxDisplay::GetName() const
167 wxCHECK_MSG( IsOk(), wxString(), _T("invalid wxDisplay object") );
169 return m_impl
->GetName();
172 bool wxDisplay::IsPrimary() const
174 return m_impl
&& m_impl
->GetIndex() == 0;
179 wxArrayVideoModes
wxDisplay::GetModes(const wxVideoMode
& mode
) const
181 wxCHECK_MSG( IsOk(), wxArrayVideoModes(), _T("invalid wxDisplay object") );
183 return m_impl
->GetModes(mode
);
186 wxVideoMode
wxDisplay::GetCurrentMode() const
188 wxCHECK_MSG( IsOk(), wxVideoMode(), _T("invalid wxDisplay object") );
190 return m_impl
->GetCurrentMode();
193 bool wxDisplay::ChangeMode(const wxVideoMode
& mode
)
195 wxCHECK_MSG( IsOk(), false, _T("invalid wxDisplay object") );
197 return m_impl
->ChangeMode(mode
);
200 #endif // wxUSE_DIRECTDRAW
202 // ----------------------------------------------------------------------------
203 // static functions implementation
204 // ----------------------------------------------------------------------------
206 // if wxUSE_DISPLAY == 1 this is implemented in port-specific code
209 /* static */ wxDisplayFactory
*wxDisplay::CreateFactory()
211 return new wxDisplayFactorySingle
;
214 #endif // !wxUSE_DISPLAY
216 /* static */ wxDisplayFactory
& wxDisplay::Factory()
220 gs_factory
= CreateFactory();
226 // ============================================================================
227 // wxDisplayFactory implementation
228 // ============================================================================
230 int wxDisplayFactory::GetFromWindow(wxWindow
*window
)
232 // consider that the window belongs to the display containing its centre
233 const wxRect
r(window
->GetRect());
234 return GetFromPoint(wxPoint(r
.x
+ r
.width
/2, r
.y
+ r
.height
/2));
237 // ============================================================================
238 // wxDisplayFactorySingle implementation
239 // ============================================================================
242 wxDisplayImpl
*wxDisplayFactorySingle::CreateDisplay(size_t n
)
244 // we recognize the main display only
245 return n
!= 0 ? NULL
: new wxDisplayImplSingle
;
248 int wxDisplayFactorySingle::GetFromPoint(const wxPoint
& pt
)
250 if ( pt
.x
>= 0 && pt
.y
>= 0 )
253 wxDisplaySize(&w
, &h
);
255 if ( pt
.x
< w
&& pt
.y
< h
)
259 // the point is outside of the screen