]> git.saurik.com Git - wxWidgets.git/blob - src/dfb/toplevel.cpp
8a5ef12fa92229a3a218421206f911fcd432c47d
[wxWidgets.git] / src / dfb / toplevel.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/dfb/toplevel.cpp
3 // Purpose: Top level window, abstraction of wxFrame and wxDialog
4 // Author: Vaclav Slavik
5 // Created: 2006-08-10
6 // RCS-ID: $Id$
7 // Copyright: (c) 2006 REA Elektronik GmbH
8 // Licence: wxWindows licence
9 /////////////////////////////////////////////////////////////////////////////
10
11 // For compilers that support precompilation, includes "wx.h".
12 #include "wx/wxprec.h"
13
14 #include "wx/toplevel.h"
15
16 #ifndef WX_PRECOMP
17 #include "wx/app.h"
18 #endif // WX_PRECOMP
19
20 #include "wx/dfb/private.h"
21
22 #define TRACE_EVENTS "events"
23
24 // ============================================================================
25 // wxTopLevelWindowDFB
26 // ============================================================================
27
28 // ----------------------------------------------------------------------------
29 // creation & destruction
30 // ----------------------------------------------------------------------------
31
32 void wxTopLevelWindowDFB::Init()
33 {
34 m_isMaximized = false;
35 m_fsIsShowing = false;
36 }
37
38 bool wxTopLevelWindowDFB::Create(wxWindow *parent,
39 wxWindowID id,
40 const wxString& title,
41 const wxPoint& posOrig,
42 const wxSize& sizeOrig,
43 long style,
44 const wxString &name)
45 {
46 // always create a frame of some reasonable, even if arbitrary, size (at
47 // least for MSW compatibility)
48 wxSize size(sizeOrig);
49 if ( size.x == wxDefaultCoord || size.y == wxDefaultCoord )
50 {
51 wxSize sizeDefault = GetDefaultSize();
52 if ( size.x == wxDefaultCoord )
53 size.x = sizeDefault.x;
54 if ( size.y == wxDefaultCoord )
55 size.y = sizeDefault.y;
56 }
57
58 wxPoint pos(posOrig);
59 if ( pos.x == wxDefaultCoord )
60 pos.x = 0;
61 if ( pos.y == wxDefaultCoord )
62 pos.y = 0;
63
64 if ( !wxNonOwnedWindow::Create(parent, id, pos, size, style, name) )
65 return false;
66
67 wxTopLevelWindows.Append(this);
68 m_title = title;
69
70 return true;
71 }
72
73 // ----------------------------------------------------------------------------
74 // showing and hiding
75 // ----------------------------------------------------------------------------
76
77 bool wxTopLevelWindowDFB::ShowFullScreen(bool show, long style)
78 {
79 if ( show == m_fsIsShowing )
80 return true;
81
82 m_fsIsShowing = show;
83
84 if (show)
85 {
86 m_fsSaveStyle = m_windowStyle;
87 m_fsSaveFlag = style;
88 GetPosition(&m_fsSaveFrame.x, &m_fsSaveFrame.y);
89 GetSize(&m_fsSaveFrame.width, &m_fsSaveFrame.height);
90
91 if ( style & wxFULLSCREEN_NOCAPTION )
92 m_windowStyle &= ~wxCAPTION;
93 if ( style & wxFULLSCREEN_NOBORDER )
94 m_windowStyle = wxSIMPLE_BORDER;
95
96 int x, y;
97 wxDisplaySize(&x, &y);
98 SetSize(0, 0, x, y);
99 }
100 else
101 {
102 m_windowStyle = m_fsSaveStyle;
103 SetSize(m_fsSaveFrame.x, m_fsSaveFrame.y,
104 m_fsSaveFrame.width, m_fsSaveFrame.height);
105 }
106
107 return true;
108 }
109
110 bool wxTopLevelWindowDFB::SetTransparent(wxByte alpha)
111 {
112 if ( IsShown() )
113 {
114 if ( !m_dfbwin->SetOpacity(alpha) )
115 return false;
116 }
117
118 m_opacity = alpha;
119 return true;
120 }
121
122 // ----------------------------------------------------------------------------
123 // maximize, minimize etc.
124 // ----------------------------------------------------------------------------
125
126 void wxTopLevelWindowDFB::Maximize(bool maximize)
127 {
128 int x, y, w, h;
129 wxClientDisplayRect(&x, &y, &w, &h);
130
131 if ( maximize && !m_isMaximized )
132 {
133 m_isMaximized = true;
134
135 GetPosition(&m_savedFrame.x, &m_savedFrame.y);
136 GetSize(&m_savedFrame.width, &m_savedFrame.height);
137
138 SetSize(x, y, w, h);
139 }
140 else if ( !maximize && m_isMaximized )
141 {
142 m_isMaximized = false;
143 SetSize(m_savedFrame.x, m_savedFrame.y,
144 m_savedFrame.width, m_savedFrame.height);
145 }
146 }
147
148 bool wxTopLevelWindowDFB::IsMaximized() const
149 {
150 return m_isMaximized;
151 }
152
153 void wxTopLevelWindowDFB::Restore()
154 {
155 if ( IsMaximized() )
156 {
157 Maximize(false);
158 }
159 }
160
161 void wxTopLevelWindowDFB::Iconize(bool WXUNUSED(iconize))
162 {
163 wxFAIL_MSG(wxT("Iconize not supported under wxDFB"));
164 }
165
166 bool wxTopLevelWindowDFB::IsIconized() const
167 {
168 return false;
169 }
170
171 // ----------------------------------------------------------------------------
172 // focus handling
173 // ----------------------------------------------------------------------------
174
175 void wxTopLevelWindowDFB::HandleFocusEvent(const wxDFBWindowEvent& event_)
176 {
177 const DFBWindowEvent& dfbevent = event_;
178 const bool activate = (dfbevent.type == DWET_GOTFOCUS);
179
180 wxLogTrace(TRACE_EVENTS,
181 "toplevel window %p ('%s') %s focus",
182 this, GetName(),
183 activate ? "got" : "lost");
184
185 wxActivateEvent event(wxEVT_ACTIVATE, activate, GetId());
186 event.SetEventObject(this);
187 HandleWindowEvent(event);
188
189 // if a frame that doesn't have wx focus inside it just got focus, we
190 // need to set focus to it (or its child):
191 if ( activate )
192 {
193 wxWindow *focused = wxWindow::FindFocus();
194 if ( !focused || focused->GetTLW() != this )
195 {
196 wxLogTrace(TRACE_EVENTS,
197 "setting wx focus to toplevel window %p ('%s')",
198 this, GetName());
199
200 if ( CanAcceptFocus() )
201 SetFocus();
202 else
203 wxLogTrace(TRACE_EVENTS, "...which doesn't accept it");
204 }
205 }
206 }