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