]> git.saurik.com Git - wxWidgets.git/blob - src/univ/topluniv.cpp
d79c39eba32ba3f0d92d534643230f4170308731
[wxWidgets.git] / src / univ / topluniv.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: topluniv.cpp
3 // Author: Vaclav Slavik
4 // Id: $Id$
5 // Copyright: (c) 2001 SciTech Software, Inc. (www.scitechsoft.com)
6 // Licence: wxWindows licence
7 /////////////////////////////////////////////////////////////////////////////
8
9 // ============================================================================
10 // declarations
11 // ============================================================================
12
13 // ----------------------------------------------------------------------------
14 // headers
15 // ----------------------------------------------------------------------------
16
17 #ifdef __GNUG__
18 #pragma implementation "univtoplevel.h"
19 #endif
20
21 // For compilers that support precompilation, includes "wx.h".
22 #include "wx/wxprec.h"
23
24 #ifdef __BORLANDC__
25 #pragma hdrstop
26 #endif
27
28 #include "wx/defs.h"
29 #include "wx/toplevel.h"
30 #include "wx/univ/renderer.h"
31 #include "wx/dcclient.h"
32 #include "wx/bitmap.h"
33 #include "wx/image.h"
34
35
36 // ----------------------------------------------------------------------------
37 // event tables
38 // ----------------------------------------------------------------------------
39
40 BEGIN_EVENT_TABLE(wxTopLevelWindow, wxTopLevelWindowNative)
41 WX_EVENT_TABLE_INPUT_CONSUMER(wxTopLevelWindow)
42 EVT_NC_PAINT(wxTopLevelWindow::OnNcPaint)
43 END_EVENT_TABLE()
44
45 WX_FORWARD_TO_INPUT_CONSUMER(wxTopLevelWindow)
46
47
48 // ============================================================================
49 // implementation
50 // ============================================================================
51
52 int wxTopLevelWindow::ms_drawDecorations = -1;
53
54 void wxTopLevelWindow::Init()
55 {
56 m_isActive = FALSE;
57 m_windowStyle = 0;
58 }
59
60 bool wxTopLevelWindow::Create(wxWindow *parent,
61 wxWindowID id,
62 const wxString& title,
63 const wxPoint& pos,
64 const wxSize& sizeOrig,
65 long style,
66 const wxString &name)
67 {
68 // init them to avoid compiler warnings
69 long styleOrig = 0,
70 exstyleOrig = 0;
71
72 if ( ms_drawDecorations == -1 )
73 ms_drawDecorations = TRUE;
74 // FIXME_MGL -- this is temporary; we assume for now that native TLW
75 // can't do decorations, which is not true
76
77 if ( ms_drawDecorations )
78 {
79 CreateInputHandler(wxINP_HANDLER_TOPLEVEL);
80
81 styleOrig = style;
82 exstyleOrig = GetExtraStyle();
83 // style &= ~(wxCAPTION | wxMINIMIZE_BOX | wxMAXIMIZE_BOX |
84 // wxSYSTEM_MENU | wxRESIZE_BORDER | wxFRAME_TOOL_WINDOW |
85 // wxTHICK_FRAME);
86 // style = wxSIMPLE_BORDER;
87 // SetExtraStyle(exstyleOrig &
88 // ~(wxFRAME_EX_CONTEXTHELP | wxDIALOG_EX_CONTEXTHELP));
89 }
90
91 if ( !wxTopLevelWindowNative::Create(parent, id, title, pos,
92 sizeOrig, style, name) )
93 return FALSE;
94
95 if ( ms_drawDecorations )
96 {
97 m_windowStyle = styleOrig;
98 m_exStyle = exstyleOrig;
99 }
100
101 return TRUE;
102 }
103
104 bool wxTopLevelWindow::ShowFullScreen(bool show, long style)
105 {
106 if ( show == IsFullScreen() ) return FALSE;
107
108 if ( ms_drawDecorations )
109 {
110 if ( show )
111 {
112 m_fsSavedStyle = m_windowStyle;
113 if ( style & wxFULLSCREEN_NOBORDER )
114 m_windowStyle |= wxSIMPLE_BORDER;
115 if ( style & wxFULLSCREEN_NOCAPTION )
116 m_windowStyle &= ~wxCAPTION;
117 }
118 else
119 {
120 m_windowStyle = m_fsSavedStyle;
121 }
122 }
123
124 return wxTopLevelWindowNative::ShowFullScreen(show, style);
125 }
126
127 long wxTopLevelWindow::GetDecorationsStyle() const
128 {
129 long style = 0;
130
131 if ( m_windowStyle & wxCAPTION )
132 {
133 style |= wxTOPLEVEL_TITLEBAR | wxTOPLEVEL_BUTTON_CLOSE;
134 if ( m_windowStyle & wxMINIMIZE_BOX )
135 style |= wxTOPLEVEL_BUTTON_MINIMIZE;
136 if ( m_windowStyle & wxMAXIMIZE_BOX )
137 style |= wxTOPLEVEL_BUTTON_MAXIMIZE;
138 if ( m_exStyle & (wxFRAME_EX_CONTEXTHELP | wxDIALOG_EX_CONTEXTHELP))
139 style |= wxTOPLEVEL_BUTTON_HELP;
140 }
141 if ( (m_windowStyle & (wxSIMPLE_BORDER | wxNO_BORDER)) == 0 )
142 style |= wxTOPLEVEL_BORDER;
143 if ( m_windowStyle & (wxRESIZE_BORDER | wxTHICK_FRAME) )
144 style |= wxTOPLEVEL_RESIZEABLE;
145
146 if ( IsMaximized() )
147 style |= wxTOPLEVEL_MAXIMIZED;
148 if ( GetIcon().Ok() )
149 style |= wxTOPLEVEL_ICON;
150 if ( m_isActive )
151 style |= wxTOPLEVEL_ACTIVE;
152
153 return style;
154 }
155
156 // ----------------------------------------------------------------------------
157 // client area handling
158 // ----------------------------------------------------------------------------
159
160 wxPoint wxTopLevelWindow::GetClientAreaOrigin() const
161 {
162 if ( ms_drawDecorations )
163 {
164 int w, h;
165 wxTopLevelWindowNative::DoGetClientSize(&w, &h);
166 wxRect rect = wxRect(wxTopLevelWindowNative::GetClientAreaOrigin(),
167 wxSize(w, h));
168 rect = m_renderer->GetFrameClientArea(rect,
169 GetDecorationsStyle());
170 return rect.GetPosition();
171 }
172 else
173 {
174 return wxTopLevelWindowNative::GetClientAreaOrigin();
175 }
176 }
177
178 void wxTopLevelWindow::DoGetClientSize(int *width, int *height) const
179 {
180 if ( ms_drawDecorations )
181 {
182 int w, h;
183 wxTopLevelWindowNative::DoGetClientSize(&w, &h);
184 wxRect rect = wxRect(wxTopLevelWindowNative::GetClientAreaOrigin(),
185 wxSize(w, h));
186 rect = m_renderer->GetFrameClientArea(rect,
187 GetDecorationsStyle());
188 if ( width )
189 *width = rect.width;
190 if ( height )
191 *height = rect.height;
192 }
193 else
194 wxTopLevelWindowNative::DoGetClientSize(width, height);
195 }
196
197 void wxTopLevelWindow::DoSetClientSize(int width, int height)
198 {
199 if ( ms_drawDecorations )
200 {
201 wxSize size = m_renderer->GetFrameTotalSize(wxSize(width, height),
202 GetDecorationsStyle());
203 wxTopLevelWindowNative::DoSetClientSize(size.x, size.y);
204 }
205 else
206 wxTopLevelWindowNative::DoSetClientSize(width, height);
207 }
208
209 void wxTopLevelWindow::OnNcPaint(wxPaintEvent& event)
210 {
211 if ( !ms_drawDecorations || !m_renderer )
212 event.Skip();
213 else
214 {
215 // get the window rect
216 wxRect rect;
217 wxSize size = GetSize();
218 rect.x =
219 rect.y = 0;
220 rect.width = size.x;
221 rect.height = size.y;
222
223 wxWindowDC dc(this);
224 m_renderer->DrawFrameTitleBar(dc, rect,
225 GetTitle(), m_titlebarIcon,
226 GetDecorationsStyle());
227 }
228 }
229
230 // ----------------------------------------------------------------------------
231 // icons
232 // ----------------------------------------------------------------------------
233
234 void wxTopLevelWindow::SetIcon(const wxIcon& icon)
235 {
236 wxTopLevelWindowNative::SetIcon(icon);
237 if ( !m_renderer ) return;
238
239 wxSize size = m_renderer->GetFrameIconSize();
240
241 if ( !icon.Ok() || size.x == -1 )
242 m_titlebarIcon = icon;
243 else
244 {
245 wxBitmap bmp1;
246 bmp1.CopyFromIcon(icon);
247 if ( !bmp1.Ok() )
248 m_titlebarIcon = wxNullIcon;
249 else if ( bmp1.GetWidth() == size.x && bmp1.GetHeight() == size.y )
250 m_titlebarIcon = icon;
251 else
252 {
253 wxImage img = bmp1.ConvertToImage();
254 img.Rescale(size.x, size.y);
255 m_titlebarIcon.CopyFromBitmap(wxBitmap(img));
256 }
257 }
258 }
259
260 // ----------------------------------------------------------------------------
261 // actions
262 // ----------------------------------------------------------------------------
263
264 bool wxTopLevelWindow::PerformAction(const wxControlAction& action,
265 long numArg,
266 const wxString& strArg)
267 {
268 if ( action == wxACTION_TOPLEVEL_ACTIVATE )
269 {
270 if ( m_isActive != (bool)numArg )
271 {
272 Refresh();
273 m_isActive = (bool)numArg;
274 wxNcPaintEvent event(GetId());
275 event.SetEventObject(this);
276 GetEventHandler()->ProcessEvent(event);
277 printf("activation: %i\n", m_isActive);
278 }
279 return TRUE;
280 }
281 else
282 return FALSE;
283 }
284
285
286 // ============================================================================
287 // wxStdFrameInputHandler: handles focus, resizing and titlebar buttons clicks
288 // ============================================================================
289
290 wxStdFrameInputHandler::wxStdFrameInputHandler(wxInputHandler *inphand)
291 : wxStdInputHandler(inphand)
292 {
293 }
294
295 bool wxStdFrameInputHandler::HandleMouse(wxInputConsumer *consumer,
296 const wxMouseEvent& event)
297 {
298 return wxStdInputHandler::HandleMouse(consumer, event);
299 }
300
301 bool wxStdFrameInputHandler::HandleMouseMove(wxInputConsumer *consumer,
302 const wxMouseEvent& event)
303 {
304 return wxStdInputHandler::HandleMouseMove(consumer, event);
305 }
306
307 bool wxStdFrameInputHandler::HandleActivation(wxInputConsumer *consumer,
308 bool activated)
309 {
310 consumer->PerformAction(wxACTION_TOPLEVEL_ACTIVATE, activated);
311 return FALSE;
312 }