]> git.saurik.com Git - wxWidgets.git/blame - src/dfb/toplevel.cpp
correction to last commit: don't test unsetenv() return value, it's void under Darwin
[wxWidgets.git] / src / dfb / toplevel.cpp
CommitLineData
b3c86150
VS
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"
b3c86150
VS
18#endif // WX_PRECOMP
19
b3c86150
VS
20#include "wx/dfb/private.h"
21
a5001e93 22#define TRACE_EVENTS "events"
6954a1e2 23
b3c86150
VS
24// ============================================================================
25// wxTopLevelWindowDFB
26// ============================================================================
27
28// ----------------------------------------------------------------------------
29// creation & destruction
30// ----------------------------------------------------------------------------
31
32void wxTopLevelWindowDFB::Init()
33{
b3c86150
VS
34 m_isMaximized = false;
35 m_fsIsShowing = false;
b3c86150
VS
36}
37
38bool 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{
b3c86150
VS
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
42b0d8b9 64 if ( !wxNonOwnedWindow::Create(parent, id, pos, size, style, name) )
b3c86150 65 return false;
b3c86150
VS
66
67 wxTopLevelWindows.Append(this);
68 m_title = title;
69
b3c86150
VS
70 return true;
71}
72
b3c86150
VS
73// ----------------------------------------------------------------------------
74// showing and hiding
75// ----------------------------------------------------------------------------
76
77#warning "FIXME: the rest of this file is almost same as for MGL, merge it"
78bool wxTopLevelWindowDFB::ShowFullScreen(bool show, long style)
79{
42b0d8b9
VS
80 if ( show == m_fsIsShowing )
81 return true;
b3c86150
VS
82
83 m_fsIsShowing = show;
84
85 if (show)
86 {
87 m_fsSaveStyle = m_windowStyle;
88 m_fsSaveFlag = style;
89 GetPosition(&m_fsSaveFrame.x, &m_fsSaveFrame.y);
90 GetSize(&m_fsSaveFrame.width, &m_fsSaveFrame.height);
91
92 if ( style & wxFULLSCREEN_NOCAPTION )
93 m_windowStyle &= ~wxCAPTION;
94 if ( style & wxFULLSCREEN_NOBORDER )
95 m_windowStyle = wxSIMPLE_BORDER;
96
97 int x, y;
98 wxDisplaySize(&x, &y);
99 SetSize(0, 0, x, y);
100 }
101 else
102 {
103 m_windowStyle = m_fsSaveStyle;
104 SetSize(m_fsSaveFrame.x, m_fsSaveFrame.y,
105 m_fsSaveFrame.width, m_fsSaveFrame.height);
106 }
107
108 return true;
109}
110
b3c86150
VS
111bool wxTopLevelWindowDFB::SetTransparent(wxByte alpha)
112{
113 if ( IsShown() )
114 {
52c8d32a 115 if ( !m_dfbwin->SetOpacity(alpha) )
b3c86150
VS
116 return false;
117 }
118
119 m_opacity = alpha;
120 return true;
121}
122
123// ----------------------------------------------------------------------------
124// maximize, minimize etc.
125// ----------------------------------------------------------------------------
126
127void wxTopLevelWindowDFB::Maximize(bool maximize)
128{
129 int x, y, w, h;
130 wxClientDisplayRect(&x, &y, &w, &h);
131
132 if ( maximize && !m_isMaximized )
133 {
134 m_isMaximized = true;
135
136 GetPosition(&m_savedFrame.x, &m_savedFrame.y);
137 GetSize(&m_savedFrame.width, &m_savedFrame.height);
138
139 SetSize(x, y, w, h);
140 }
141 else if ( !maximize && m_isMaximized )
142 {
143 m_isMaximized = false;
144 SetSize(m_savedFrame.x, m_savedFrame.y,
145 m_savedFrame.width, m_savedFrame.height);
146 }
147}
148
149bool wxTopLevelWindowDFB::IsMaximized() const
150{
151 return m_isMaximized;
152}
153
154void wxTopLevelWindowDFB::Restore()
155{
156 if ( IsMaximized() )
157 {
158 Maximize(false);
159 }
160}
161
162void wxTopLevelWindowDFB::Iconize(bool WXUNUSED(iconize))
163{
164 wxFAIL_MSG(wxT("Iconize not supported under wxDFB"));
165}
166
167bool wxTopLevelWindowDFB::IsIconized() const
168{
169 return false;
170}
6954a1e2
VS
171
172// ----------------------------------------------------------------------------
173// focus handling
174// ----------------------------------------------------------------------------
175
176void wxTopLevelWindowDFB::HandleFocusEvent(const wxDFBWindowEvent& event_)
177{
178 const DFBWindowEvent& dfbevent = event_;
179 const bool activate = (dfbevent.type == DWET_GOTFOCUS);
180
181 wxLogTrace(TRACE_EVENTS,
a5001e93 182 "toplevel window %p ('%s') %s focus",
6954a1e2 183 this, GetName(),
a5001e93 184 activate ? "got" : "lost");
6954a1e2
VS
185
186 wxActivateEvent event(wxEVT_ACTIVATE, activate, GetId());
187 event.SetEventObject(this);
188 GetEventHandler()->ProcessEvent(event);
189
190 // if a frame that doesn't have wx focus inside it just got focus, we
191 // need to set focus to it (or its child):
192 if ( activate )
193 {
194 wxWindow *focused = wxWindow::FindFocus();
195 if ( !focused || focused->GetTLW() != this )
196 {
197 wxLogTrace(TRACE_EVENTS,
a5001e93 198 "setting wx focus to toplevel window %p ('%s')",
6954a1e2
VS
199 this, GetName());
200
201 if ( CanAcceptFocus() )
202 SetFocus();
fd2be5df
VS
203 else
204 wxLogTrace(TRACE_EVENTS, "...which doesn't accept it");
6954a1e2
VS
205 }
206 }
207}