]>
Commit | Line | Data |
---|---|---|
2bda0e17 KB |
1 | ///////////////////////////////////////////////////////////////////////////// |
2 | // Name: frame.cpp | |
3 | // Purpose: wxFrame | |
4 | // Author: Julian Smart | |
5 | // Modified by: | |
6 | // Created: 01/02/97 | |
7 | // RCS-ID: $Id$ | |
8 | // Copyright: (c) Julian Smart and Markus Holzem | |
9 | // Licence: wxWindows licence | |
10 | ///////////////////////////////////////////////////////////////////////////// | |
11 | ||
12 | #ifdef __GNUG__ | |
13 | #pragma implementation "frame.h" | |
14 | #endif | |
15 | ||
16 | // For compilers that support precompilation, includes "wx.h". | |
17 | #include "wx/wxprec.h" | |
18 | ||
19 | #ifdef __BORLANDC__ | |
20 | #pragma hdrstop | |
21 | #endif | |
22 | ||
23 | #ifndef WX_PRECOMP | |
24 | #include "wx/setup.h" | |
25 | #include "wx/frame.h" | |
26 | #include "wx/menu.h" | |
27 | #include "wx/app.h" | |
28 | #include "wx/utils.h" | |
29 | #include "wx/dialog.h" | |
30 | #include "wx/settings.h" | |
31 | #include "wx/dcclient.h" | |
32 | #endif | |
33 | ||
34 | #include "wx/msw/private.h" | |
35 | #include "wx/statusbr.h" | |
36 | #include "wx/menuitem.h" | |
37 | ||
38 | #ifdef LoadAccelerators | |
39 | #undef LoadAccelerators | |
40 | #endif | |
41 | ||
42 | #if USE_NATIVE_STATUSBAR | |
43 | #include <wx/msw/statbr95.h> | |
44 | #endif | |
45 | ||
46 | extern wxList wxModelessWindows; | |
47 | extern wxList wxPendingDelete; | |
48 | extern char wxFrameClassName[]; | |
49 | ||
50 | #if !USE_SHARED_LIBRARY | |
51 | BEGIN_EVENT_TABLE(wxFrame, wxWindow) | |
52 | EVT_SIZE(wxFrame::OnSize) | |
53 | EVT_ACTIVATE(wxFrame::OnActivate) | |
54 | EVT_MENU_HIGHLIGHT_ALL(wxFrame::OnMenuHighlight) | |
55 | EVT_SYS_COLOUR_CHANGED(wxFrame::OnSysColourChanged) | |
56 | EVT_IDLE(wxFrame::OnIdle) | |
57 | EVT_CLOSE(wxFrame::OnCloseWindow) | |
58 | END_EVENT_TABLE() | |
59 | ||
60 | IMPLEMENT_DYNAMIC_CLASS(wxFrame, wxWindow) | |
61 | #endif | |
62 | ||
63 | #if USE_NATIVE_STATUSBAR | |
64 | bool wxFrame::m_useNativeStatusBar = TRUE; | |
65 | #else | |
66 | bool wxFrame::m_useNativeStatusBar = FALSE; | |
67 | #endif | |
68 | ||
69 | wxFrame::wxFrame(void) | |
70 | { | |
73e7daa0 | 71 | m_frameToolBar = NULL ; |
2bda0e17 KB |
72 | m_frameMenuBar = NULL; |
73 | m_frameStatusBar = NULL; | |
74 | ||
75 | m_windowParent = NULL; | |
76 | m_iconized = FALSE; | |
77 | } | |
78 | ||
79 | bool wxFrame::Create(wxWindow *parent, | |
debe6624 | 80 | wxWindowID id, |
2bda0e17 KB |
81 | const wxString& title, |
82 | const wxPoint& pos, | |
83 | const wxSize& size, | |
debe6624 | 84 | long style, |
2bda0e17 KB |
85 | const wxString& name) |
86 | { | |
87 | if (!parent) | |
88 | wxTopLevelWindows.Append(this); | |
89 | ||
90 | SetName(name); | |
91 | // m_modalShowing = FALSE; | |
92 | m_windowStyle = style; | |
93 | m_frameMenuBar = NULL; | |
73e7daa0 | 94 | m_frameToolBar = NULL ; |
2bda0e17 KB |
95 | m_frameStatusBar = NULL; |
96 | ||
97 | SetBackgroundColour(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_APPWORKSPACE)); | |
98 | ||
99 | // m_icon = NULL; | |
100 | if ( id > -1 ) | |
101 | m_windowId = id; | |
102 | else | |
103 | m_windowId = (int)NewControlId(); | |
104 | ||
105 | if (parent) parent->AddChild(this); | |
106 | ||
107 | int x = pos.x; | |
108 | int y = pos.y; | |
109 | int width = size.x; | |
110 | int height = size.y; | |
111 | ||
112 | m_iconized = FALSE; | |
113 | MSWCreate(m_windowId, (wxWindow *)parent, wxFrameClassName, this, (char *)(const char *)title, | |
114 | x, y, width, height, style); | |
115 | ||
116 | wxModelessWindows.Append(this); | |
117 | return TRUE; | |
118 | } | |
119 | ||
120 | wxFrame::~wxFrame(void) | |
121 | { | |
122 | m_isBeingDeleted = TRUE; | |
123 | wxTopLevelWindows.DeleteObject(this); | |
124 | ||
125 | if (m_frameStatusBar) | |
126 | delete m_frameStatusBar; | |
127 | if (m_frameMenuBar) | |
128 | delete m_frameMenuBar; | |
129 | ||
130 | /* New behaviour March 1998: check if it's the last top-level window */ | |
131 | // if (wxTheApp && (this == wxTheApp->GetTopWindow())) | |
132 | ||
133 | if (wxTheApp && (wxTopLevelWindows.Number() == 0)) | |
134 | { | |
135 | wxTheApp->SetTopWindow(NULL); | |
136 | ||
137 | if (wxTheApp->GetExitOnFrameDelete()) | |
138 | { | |
139 | PostQuitMessage(0); | |
140 | } | |
141 | } | |
142 | ||
143 | wxModelessWindows.DeleteObject(this); | |
144 | ||
145 | // For some reason, wxWindows can activate another task altogether | |
146 | // when a frame is destroyed after a modal dialog has been invoked. | |
147 | // Try to bring the parent to the top. | |
148 | if (GetParent() && GetParent()->GetHWND()) | |
149 | ::BringWindowToTop((HWND) GetParent()->GetHWND()); | |
150 | } | |
151 | ||
152 | WXHMENU wxFrame::GetWinMenu(void) const | |
153 | { | |
154 | return m_hMenu; | |
155 | } | |
156 | ||
157 | // Get size *available for subwindows* i.e. excluding menu bar etc. | |
158 | // For XView, this is the same as GetSize | |
159 | void wxFrame::GetClientSize(int *x, int *y) const | |
160 | { | |
161 | RECT rect; | |
162 | GetClientRect((HWND) GetHWND(), &rect); | |
163 | ||
164 | if ( m_frameStatusBar ) | |
165 | { | |
166 | int statusX, statusY; | |
167 | m_frameStatusBar->GetClientSize(&statusX, &statusY); | |
168 | rect.bottom -= statusY; | |
169 | } | |
170 | *x = rect.right; | |
171 | *y = rect.bottom; | |
172 | } | |
173 | ||
174 | // Set the client size (i.e. leave the calculation of borders etc. | |
175 | // to wxWindows) | |
debe6624 | 176 | void wxFrame::SetClientSize(int width, int height) |
2bda0e17 KB |
177 | { |
178 | HWND hWnd = (HWND) GetHWND(); | |
179 | ||
180 | RECT rect; | |
181 | GetClientRect(hWnd, &rect); | |
182 | ||
183 | RECT rect2; | |
184 | GetWindowRect(hWnd, &rect2); | |
185 | ||
186 | // Find the difference between the entire window (title bar and all) | |
187 | // and the client area; add this to the new client size to move the | |
188 | // window | |
189 | int actual_width = rect2.right - rect2.left - rect.right + width; | |
190 | int actual_height = rect2.bottom - rect2.top - rect.bottom + height; | |
191 | ||
192 | if ( m_frameStatusBar ) | |
193 | { | |
194 | int statusX, statusY; | |
195 | m_frameStatusBar->GetClientSize(&statusX, &statusY); | |
196 | actual_height += statusY; | |
197 | } | |
198 | ||
199 | POINT point; | |
200 | point.x = rect2.left; | |
201 | point.y = rect2.top; | |
202 | ||
203 | MoveWindow(hWnd, point.x, point.y, actual_width, actual_height, (BOOL)TRUE); | |
debe6624 | 204 | |
2bda0e17 KB |
205 | wxSizeEvent event(wxSize(width, height), m_windowId); |
206 | event.SetEventObject( this ); | |
207 | GetEventHandler()->ProcessEvent(event); | |
2bda0e17 KB |
208 | } |
209 | ||
210 | void wxFrame::GetSize(int *width, int *height) const | |
211 | { | |
212 | RECT rect; | |
213 | GetWindowRect((HWND) GetHWND(), &rect); | |
214 | *width = rect.right - rect.left; | |
215 | *height = rect.bottom - rect.top; | |
216 | } | |
217 | ||
218 | void wxFrame::GetPosition(int *x, int *y) const | |
219 | { | |
220 | RECT rect; | |
221 | GetWindowRect((HWND) GetHWND(), &rect); | |
222 | POINT point; | |
223 | point.x = rect.left; | |
224 | point.y = rect.top; | |
225 | ||
226 | *x = point.x; | |
227 | *y = point.y; | |
228 | } | |
229 | ||
debe6624 | 230 | void wxFrame::SetSize(int x, int y, int width, int height, int sizeFlags) |
2bda0e17 KB |
231 | { |
232 | int currentX, currentY; | |
233 | int x1 = x; | |
234 | int y1 = y; | |
235 | int w1 = width; | |
236 | int h1 = height; | |
237 | ||
238 | GetPosition(¤tX, ¤tY); | |
239 | if (x == -1 || (sizeFlags & wxSIZE_ALLOW_MINUS_ONE)) | |
240 | x1 = currentX; | |
241 | if (y == -1 || (sizeFlags & wxSIZE_ALLOW_MINUS_ONE)) | |
242 | y1 = currentY; | |
243 | ||
244 | int ww,hh ; | |
245 | GetSize(&ww,&hh) ; | |
246 | if (width == -1) w1 = ww ; | |
247 | if (height==-1) h1 = hh ; | |
248 | ||
249 | MoveWindow((HWND) GetHWND(), x1, y1, w1, h1, (BOOL)TRUE); | |
250 | ||
2bda0e17 KB |
251 | wxSizeEvent event(wxSize(width, height), m_windowId); |
252 | event.SetEventObject( this ); | |
253 | GetEventHandler()->ProcessEvent(event); | |
2bda0e17 KB |
254 | } |
255 | ||
debe6624 | 256 | bool wxFrame::Show(bool show) |
2bda0e17 KB |
257 | { |
258 | int cshow; | |
259 | if (show) | |
260 | cshow = SW_SHOW; | |
261 | else | |
262 | cshow = SW_HIDE; | |
263 | ||
264 | if (!show) | |
265 | { | |
266 | // Try to highlight the correct window (the parent) | |
267 | HWND hWndParent = 0; | |
268 | if (GetParent()) | |
269 | { | |
270 | hWndParent = (HWND) GetParent()->GetHWND(); | |
271 | if (hWndParent) | |
272 | ::BringWindowToTop(hWndParent); | |
273 | } | |
274 | } | |
275 | ||
276 | ShowWindow((HWND) GetHWND(), (BOOL)cshow); | |
277 | if (show) | |
278 | { | |
279 | BringWindowToTop((HWND) GetHWND()); | |
280 | ||
2bda0e17 KB |
281 | wxActivateEvent event(wxEVT_ACTIVATE, TRUE, m_windowId); |
282 | event.SetEventObject( this ); | |
283 | GetEventHandler()->ProcessEvent(event); | |
2bda0e17 KB |
284 | } |
285 | return TRUE; | |
286 | } | |
287 | ||
debe6624 | 288 | void wxFrame::Iconize(bool iconize) |
2bda0e17 KB |
289 | { |
290 | if (!iconize) | |
291 | Show(TRUE); | |
292 | ||
293 | int cshow; | |
294 | if (iconize) | |
295 | cshow = SW_MINIMIZE; | |
296 | else | |
297 | cshow = SW_RESTORE; | |
298 | ShowWindow((HWND) GetHWND(), (BOOL)cshow); | |
299 | m_iconized = iconize; | |
300 | } | |
301 | ||
302 | // Equivalent to maximize/restore in Windows | |
debe6624 | 303 | void wxFrame::Maximize(bool maximize) |
2bda0e17 KB |
304 | { |
305 | Show(TRUE); | |
306 | int cshow; | |
307 | if (maximize) | |
308 | cshow = SW_MAXIMIZE; | |
309 | else | |
310 | cshow = SW_RESTORE; | |
311 | ShowWindow((HWND) GetHWND(), cshow); | |
312 | m_iconized = FALSE; | |
313 | } | |
314 | ||
315 | bool wxFrame::IsIconized(void) const | |
316 | { | |
317 | ((wxFrame *)this)->m_iconized = (::IsIconic((HWND) GetHWND()) != 0); | |
318 | return m_iconized; | |
319 | } | |
320 | ||
321 | void wxFrame::SetTitle(const wxString& title) | |
322 | { | |
323 | SetWindowText((HWND) GetHWND(), (const char *)title); | |
324 | } | |
325 | ||
326 | wxString wxFrame::GetTitle(void) const | |
327 | { | |
328 | GetWindowText((HWND) GetHWND(), wxBuffer, 1000); | |
329 | return wxString(wxBuffer); | |
330 | } | |
331 | ||
332 | void wxFrame::SetIcon(const wxIcon& icon) | |
333 | { | |
334 | m_icon = icon; | |
335 | #if defined(__WIN95__) | |
336 | if ( m_icon.Ok() ) | |
337 | SendMessage((HWND) GetHWND(), WM_SETICON, | |
338 | (WPARAM)TRUE, (LPARAM)(HICON) m_icon.GetHICON()); | |
339 | #endif | |
340 | } | |
341 | ||
debe6624 | 342 | wxStatusBar *wxFrame::OnCreateStatusBar(int number) |
2bda0e17 KB |
343 | { |
344 | wxStatusBar *statusBar = NULL; | |
345 | ||
346 | #if USE_NATIVE_STATUSBAR | |
347 | if (UsesNativeStatusBar()) | |
348 | { | |
349 | statusBar = new wxStatusBar95(this); | |
350 | } | |
351 | else | |
352 | #endif | |
353 | { | |
354 | statusBar = new wxStatusBar(this, -1, wxPoint(0, 0), wxSize(100, 20)); | |
355 | ||
356 | // Set the height according to the font and the border size | |
357 | wxClientDC dc(statusBar); | |
358 | dc.SetFont(* statusBar->GetFont()); | |
359 | ||
360 | long x, y; | |
361 | dc.GetTextExtent("X", &x, &y); | |
362 | ||
363 | int height = (int)( (y * 1.1) + 2* statusBar->GetBorderY()); | |
364 | ||
365 | statusBar->SetSize(-1, -1, 100, height); | |
366 | } | |
367 | ||
368 | statusBar->SetFieldsCount(number); | |
369 | return statusBar; | |
370 | } | |
371 | ||
debe6624 | 372 | bool wxFrame::CreateStatusBar(int number) |
2bda0e17 KB |
373 | { |
374 | // VZ: calling CreateStatusBar twice is an error - why anyone would do it? | |
1311c7a9 VZ |
375 | wxCHECK_MSG( m_frameStatusBar == NULL, FALSE, |
376 | "recreating status bar in wxFrame" ); | |
2bda0e17 KB |
377 | |
378 | m_frameStatusBar = OnCreateStatusBar(number); | |
379 | if ( m_frameStatusBar ) | |
380 | { | |
381 | PositionStatusBar(); | |
382 | return TRUE; | |
383 | } | |
384 | else | |
385 | return FALSE; | |
386 | } | |
387 | ||
debe6624 | 388 | void wxFrame::SetStatusText(const wxString& text, int number) |
2bda0e17 | 389 | { |
1311c7a9 | 390 | wxCHECK_RET( m_frameStatusBar != NULL, "no statusbar to set text for" ); |
2bda0e17 KB |
391 | |
392 | m_frameStatusBar->SetStatusText(text, number); | |
393 | } | |
394 | ||
8b9518ee | 395 | void wxFrame::SetStatusWidths(int n, const int widths_field[]) |
2bda0e17 | 396 | { |
1311c7a9 | 397 | wxCHECK_RET( m_frameStatusBar != NULL, "no statusbar to set widths for" ); |
2bda0e17 KB |
398 | |
399 | m_frameStatusBar->SetStatusWidths(n, widths_field); | |
400 | PositionStatusBar(); | |
401 | } | |
402 | ||
403 | void wxFrame::PositionStatusBar(void) | |
404 | { | |
405 | // native status bar positions itself | |
406 | if (m_frameStatusBar | |
407 | #if USE_NATIVE_STATUSBAR | |
408 | && !m_frameStatusBar->IsKindOf(CLASSINFO(wxStatusBar95)) | |
409 | #endif | |
410 | ) | |
411 | { | |
412 | int w, h; | |
413 | GetClientSize(&w, &h); | |
414 | int sw, sh; | |
415 | m_frameStatusBar->GetSize(&sw, &sh); | |
416 | m_frameStatusBar->SetSize(0, h, w, sh); | |
417 | } | |
418 | } | |
419 | ||
420 | void wxFrame::SetMenuBar(wxMenuBar *menu_bar) | |
421 | { | |
422 | if (!menu_bar) | |
423 | { | |
424 | m_frameMenuBar = NULL; | |
425 | return; | |
426 | } | |
427 | ||
428 | if (menu_bar->m_menuBarFrame) | |
429 | return; | |
430 | ||
431 | int i; | |
432 | HMENU menu = CreateMenu(); | |
433 | ||
434 | for (i = 0; i < menu_bar->m_menuCount; i ++) | |
435 | { | |
436 | HMENU popup = (HMENU)menu_bar->m_menus[i]->m_hMenu; | |
437 | // | |
438 | // After looking Bounds Checker result, it seems that all | |
439 | // menus must be individually destroyed. So, don't reset m_hMenu, | |
440 | // to allow ~wxMenu to do the job. | |
441 | // | |
442 | menu_bar->m_menus[i]->m_savehMenu = (WXHMENU) popup; | |
443 | // Uncommenting for the moment... JACS | |
444 | menu_bar->m_menus[i]->m_hMenu = 0; | |
445 | AppendMenu(menu, MF_POPUP | MF_STRING, (UINT)popup, menu_bar->m_titles[i]); | |
446 | } | |
447 | ||
448 | menu_bar->m_hMenu = (WXHMENU)menu; | |
449 | if (m_frameMenuBar) | |
450 | delete m_frameMenuBar; | |
451 | ||
452 | this->m_hMenu = (WXHMENU) menu; | |
453 | ||
454 | DWORD err = 0; | |
455 | if (!SetMenu((HWND) GetHWND(), menu)) | |
456 | { | |
457 | #ifdef __WIN32__ | |
458 | err = GetLastError(); | |
459 | #endif | |
460 | } | |
461 | ||
462 | m_frameMenuBar = menu_bar; | |
463 | menu_bar->m_menuBarFrame = this; | |
464 | } | |
465 | ||
466 | bool wxFrame::LoadAccelerators(const wxString& table) | |
467 | { | |
468 | m_acceleratorTable = (WXHANDLE) | |
469 | #ifdef __WIN32__ | |
470 | #ifdef UNICODE | |
471 | ::LoadAcceleratorsW(wxGetInstance(), (const char *)table); | |
472 | #else | |
473 | ::LoadAcceleratorsA(wxGetInstance(), (const char *)table); | |
474 | #endif | |
475 | #else | |
476 | ::LoadAccelerators(wxGetInstance(), (const char *)table); | |
477 | #endif | |
478 | ||
479 | // The above is necessary because LoadAccelerators is a macro | |
480 | // which we have undefed earlier in the file to avoid confusion | |
481 | // with wxFrame::LoadAccelerators. Ugh! | |
482 | ||
483 | return (m_acceleratorTable != (WXHANDLE) NULL); | |
484 | } | |
485 | ||
486 | void wxFrame::Fit(void) | |
487 | { | |
488 | // Work out max. size | |
489 | wxNode *node = GetChildren()->First(); | |
490 | int max_width = 0; | |
491 | int max_height = 0; | |
492 | while (node) | |
493 | { | |
494 | // Find a child that's a subwindow, but not a dialog box. | |
495 | wxWindow *win = (wxWindow *)node->Data(); | |
496 | ||
497 | if (!win->IsKindOf(CLASSINFO(wxFrame)) && | |
498 | !win->IsKindOf(CLASSINFO(wxDialog))) | |
499 | { | |
500 | int width, height; | |
501 | int x, y; | |
502 | win->GetSize(&width, &height); | |
503 | win->GetPosition(&x, &y); | |
504 | ||
505 | if ((x + width) > max_width) | |
506 | max_width = x + width; | |
507 | if ((y + height) > max_height) | |
508 | max_height = y + height; | |
509 | } | |
510 | node = node->Next(); | |
511 | } | |
512 | SetClientSize(max_width, max_height); | |
513 | } | |
514 | ||
515 | // Responds to colour changes, and passes event on to children. | |
516 | void wxFrame::OnSysColourChanged(wxSysColourChangedEvent& event) | |
517 | { | |
518 | SetBackgroundColour(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_APPWORKSPACE)); | |
519 | Refresh(); | |
520 | ||
521 | if ( m_frameStatusBar ) | |
522 | { | |
523 | wxSysColourChangedEvent event2; | |
524 | event2.SetEventObject( m_frameStatusBar ); | |
525 | m_frameStatusBar->ProcessEvent(event2); | |
526 | } | |
527 | ||
528 | // Propagate the event to the non-top-level children | |
529 | wxWindow::OnSysColourChanged(event); | |
530 | } | |
531 | ||
532 | /* | |
533 | * Frame window | |
534 | * | |
535 | */ | |
536 | ||
debe6624 JS |
537 | void wxFrame::MSWCreate(int id, wxWindow *parent, const char *wclass, wxWindow *wx_win, const char *title, |
538 | int x, int y, int width, int height, long style) | |
2bda0e17 KB |
539 | |
540 | { | |
541 | m_defaultIcon = (WXHICON) (wxSTD_FRAME_ICON ? wxSTD_FRAME_ICON : wxDEFAULT_FRAME_ICON); | |
542 | ||
543 | // If child windows aren't properly drawn initially, WS_CLIPCHILDREN | |
544 | // could be the culprit. But without it, you can get a lot of flicker. | |
545 | ||
2bda0e17 KB |
546 | DWORD msflags = 0; |
547 | if ((style & wxCAPTION) == wxCAPTION) | |
1c089c47 | 548 | msflags = WS_OVERLAPPED; |
2bda0e17 | 549 | else |
1c089c47 | 550 | msflags = WS_POPUP; |
2bda0e17 KB |
551 | |
552 | if (style & wxMINIMIZE_BOX) | |
553 | msflags |= WS_MINIMIZEBOX; | |
554 | if (style & wxMAXIMIZE_BOX) | |
555 | msflags |= WS_MAXIMIZEBOX; | |
556 | if (style & wxTHICK_FRAME) | |
557 | msflags |= WS_THICKFRAME; | |
558 | if (style & wxSYSTEM_MENU) | |
559 | msflags |= WS_SYSMENU; | |
560 | if ((style & wxMINIMIZE) || (style & wxICONIZE)) | |
561 | msflags |= WS_MINIMIZE; | |
562 | if (style & wxMAXIMIZE) | |
563 | msflags |= WS_MAXIMIZE; | |
564 | if (style & wxCAPTION) | |
565 | msflags |= WS_CAPTION; | |
1c089c47 JS |
566 | if (style & wxCLIP_CHILDREN) |
567 | msflags |= WS_CLIPCHILDREN; | |
2bda0e17 KB |
568 | |
569 | // Keep this in wxFrame because it saves recoding this function | |
570 | // in wxTinyFrame | |
571 | #if USE_ITSY_BITSY | |
572 | if (style & wxTINY_CAPTION_VERT) | |
573 | msflags |= IBS_VERTCAPTION; | |
574 | if (style & wxTINY_CAPTION_HORIZ) | |
575 | msflags |= IBS_HORZCAPTION; | |
576 | #else | |
577 | if (style & wxTINY_CAPTION_VERT) | |
578 | msflags |= WS_CAPTION; | |
579 | if (style & wxTINY_CAPTION_HORIZ) | |
580 | msflags |= WS_CAPTION; | |
581 | #endif | |
582 | if ((style & wxTHICK_FRAME) == 0) | |
583 | msflags |= WS_BORDER; | |
584 | ||
585 | WXDWORD extendedStyle = MakeExtendedStyle(style); | |
586 | ||
587 | if (style & wxSTAY_ON_TOP) | |
588 | extendedStyle |= WS_EX_TOPMOST; | |
589 | ||
590 | m_iconized = FALSE; | |
591 | wxWindow::MSWCreate(id, parent, wclass, wx_win, title, x, y, width, height, | |
592 | msflags, NULL, extendedStyle); | |
593 | // Seems to be necessary if we use WS_POPUP | |
594 | // style instead of WS_OVERLAPPED | |
595 | if (width > -1 && height > -1) | |
596 | ::PostMessage((HWND) GetHWND(), WM_SIZE, SIZE_RESTORED, MAKELPARAM(width, height)); | |
597 | } | |
598 | ||
599 | bool wxFrame::MSWOnPaint(void) | |
600 | { | |
b2aef89b | 601 | #if WXDEBUG > 1 |
2bda0e17 KB |
602 | wxDebugMsg("wxFrameWnd::OnPaint %d\n", handle); |
603 | #endif | |
604 | RECT rect; | |
605 | if (GetUpdateRect((HWND) GetHWND(), &rect, FALSE)) | |
606 | { | |
607 | if (m_iconized) | |
608 | { | |
609 | HICON the_icon; | |
610 | if (m_icon.Ok()) | |
611 | the_icon = (HICON) m_icon.GetHICON(); | |
612 | if (the_icon == 0) | |
613 | the_icon = (HICON) m_defaultIcon; | |
614 | ||
615 | PAINTSTRUCT ps; | |
616 | // Hold a pointer to the dc so long as the OnPaint() message | |
617 | // is being processed | |
618 | HDC cdc = BeginPaint((HWND) GetHWND(), &ps); | |
619 | ||
620 | // Erase background before painting or we get white background | |
621 | this->MSWDefWindowProc(WM_ICONERASEBKGND,(WORD)ps.hdc,0L); | |
622 | ||
623 | if (the_icon) | |
624 | { | |
625 | RECT rect; | |
626 | GetClientRect((HWND) GetHWND(), &rect); | |
627 | int icon_width = 32; | |
628 | int icon_height = 32; | |
629 | int icon_x = (int)((rect.right - icon_width)/2); | |
630 | int icon_y = (int)((rect.bottom - icon_height)/2); | |
631 | DrawIcon(cdc, icon_x, icon_y, the_icon); | |
632 | } | |
633 | ||
634 | EndPaint((HWND) GetHWND(), &ps); | |
635 | } | |
1c089c47 | 636 | else |
2bda0e17 | 637 | { |
debe6624 JS |
638 | wxPaintEvent event(m_windowId); |
639 | event.m_eventObject = this; | |
640 | if (!GetEventHandler()->ProcessEvent(event)) | |
641 | Default(); | |
2bda0e17 KB |
642 | } |
643 | return 0; | |
644 | } | |
645 | return 1; | |
646 | } | |
647 | ||
648 | WXHICON wxFrame::MSWOnQueryDragIcon(void) | |
649 | { | |
650 | if (m_icon.Ok() && (m_icon.GetHICON() != 0)) | |
651 | return m_icon.GetHICON(); | |
652 | else | |
653 | return m_defaultIcon; | |
654 | } | |
655 | ||
debe6624 | 656 | void wxFrame::MSWOnSize(int x, int y, WXUINT id) |
2bda0e17 | 657 | { |
b2aef89b | 658 | #if WXDEBUG > 1 |
2bda0e17 KB |
659 | wxDebugMsg("wxFrameWnd::OnSize %d\n", m_hWnd); |
660 | #endif | |
661 | switch (id) | |
662 | { | |
663 | case SIZEFULLSCREEN: | |
664 | case SIZENORMAL: | |
665 | m_iconized = FALSE; | |
666 | break; | |
667 | case SIZEICONIC: | |
668 | m_iconized = TRUE; | |
669 | break; | |
670 | } | |
671 | ||
672 | if (!m_iconized) | |
673 | { | |
674 | // forward WM_SIZE to status bar control | |
675 | #if USE_NATIVE_STATUSBAR | |
676 | if (m_frameStatusBar && m_frameStatusBar->IsKindOf(CLASSINFO(wxStatusBar95))) | |
677 | { | |
678 | wxSizeEvent event(wxSize(x, y), m_frameStatusBar->GetId()); | |
679 | event.SetEventObject( m_frameStatusBar ); | |
680 | ||
681 | ((wxStatusBar95 *)m_frameStatusBar)->OnSize(event); | |
682 | } | |
683 | #endif | |
684 | ||
685 | PositionStatusBar(); | |
2bda0e17 KB |
686 | wxSizeEvent event(wxSize(x, y), m_windowId); |
687 | event.SetEventObject( this ); | |
debe6624 JS |
688 | if (!GetEventHandler()->ProcessEvent(event)) |
689 | Default(); | |
2bda0e17 KB |
690 | } |
691 | } | |
692 | ||
693 | bool wxFrame::MSWOnClose(void) | |
694 | { | |
b2aef89b | 695 | #if WXDEBUG > 1 |
2bda0e17 KB |
696 | wxDebugMsg("wxFrameWnd::OnClose %d\n", handle); |
697 | #endif | |
698 | return Close(); | |
699 | } | |
700 | ||
debe6624 | 701 | bool wxFrame::MSWOnCommand(WXWORD id, WXWORD cmd, WXHWND control) |
2bda0e17 | 702 | { |
b2aef89b | 703 | #if WXDEBUG > 1 |
2bda0e17 KB |
704 | wxDebugMsg("wxFrameWnd::OnCommand %d\n", handle); |
705 | #endif | |
706 | if (cmd == 0 || cmd == 1 ) // Can be either a menu command or an accelerator. | |
707 | { | |
708 | // In case it's e.g. a toolbar. | |
709 | wxWindow *win = wxFindWinFromHandle(control); | |
710 | if (win) | |
711 | return win->MSWCommand(cmd, id); | |
712 | ||
713 | if (GetMenuBar() && GetMenuBar()->FindItemForId(id)) | |
714 | { | |
715 | ProcessCommand(id); | |
716 | return TRUE; | |
717 | } | |
718 | else | |
719 | return FALSE; | |
720 | } | |
721 | else | |
722 | return FALSE; | |
723 | } | |
724 | ||
debe6624 | 725 | void wxFrame::MSWOnMenuHighlight(WXWORD nItem, WXWORD nFlags, WXHMENU hSysMenu) |
2bda0e17 | 726 | { |
2bda0e17 KB |
727 | if (nFlags == 0xFFFF && hSysMenu == 0) |
728 | { | |
729 | wxMenuEvent event(wxEVT_MENU_HIGHLIGHT, -1); | |
730 | event.SetEventObject( this ); | |
731 | GetEventHandler()->ProcessEvent(event); | |
732 | } | |
733 | else if (nFlags != MF_SEPARATOR) | |
734 | { | |
735 | wxMenuEvent event(wxEVT_MENU_HIGHLIGHT, nItem); | |
736 | event.SetEventObject( this ); | |
737 | GetEventHandler()->ProcessEvent(event); | |
738 | } | |
2bda0e17 KB |
739 | } |
740 | ||
741 | bool wxFrame::MSWProcessMessage(WXMSG* pMsg) | |
742 | { | |
743 | if (m_acceleratorTable != 0 && | |
c4e7c2aa | 744 | ::TranslateAccelerator((HWND) GetHWND(), (HACCEL) m_acceleratorTable, (MSG *)pMsg)) |
2bda0e17 KB |
745 | return TRUE; |
746 | ||
747 | return FALSE; | |
748 | } | |
749 | ||
750 | // Default resizing behaviour - if only ONE subwindow, | |
751 | // resize to client rectangle size | |
752 | void wxFrame::OnSize(wxSizeEvent& event) | |
753 | { | |
cd70477b VZ |
754 | // if we're using constraints - do use them |
755 | #if USE_CONSTRAINTS | |
756 | if ( GetAutoLayout() ) { | |
757 | Layout(); | |
758 | return; | |
759 | } | |
760 | #endif | |
761 | ||
762 | // do we have _exactly_ one child? | |
2bda0e17 | 763 | wxWindow *child = NULL; |
cd70477b | 764 | for ( wxNode *node = GetChildren()->First(); node; node = node->Next() ) |
2bda0e17 KB |
765 | { |
766 | wxWindow *win = (wxWindow *)node->Data(); | |
cd70477b VZ |
767 | if ( !win->IsKindOf(CLASSINFO(wxFrame)) && |
768 | !win->IsKindOf(CLASSINFO(wxDialog)) && | |
73e7daa0 JS |
769 | (win != GetStatusBar()) && |
770 | (win != GetToolBar()) ) | |
2bda0e17 | 771 | { |
cd70477b VZ |
772 | if ( child ) |
773 | return; // it's our second subwindow - nothing to do | |
2bda0e17 | 774 | child = win; |
2bda0e17 KB |
775 | } |
776 | } | |
777 | ||
cd70477b VZ |
778 | if ( child ) { |
779 | // we have exactly one child - set it's size to fill the whole frame | |
73e7daa0 JS |
780 | int clientW, clientH; |
781 | GetClientSize(&clientW, &clientH); | |
2bda0e17 | 782 | |
73e7daa0 JS |
783 | int x = 0; |
784 | int y = 0; | |
785 | ||
786 | // Manage the toolbar if there is one | |
787 | if ( GetToolBar() ) | |
788 | { | |
789 | int wt, ht; | |
790 | GetToolBar()->GetSize(&wt, &ht); | |
791 | clientH -= ht; | |
792 | y += ht; | |
793 | GetToolBar()->SetSize(0, 0, clientW, ht); | |
794 | } | |
795 | ||
796 | child->SetSize(x, y, clientW, clientH); | |
2bda0e17 | 797 | } |
2bda0e17 KB |
798 | } |
799 | ||
800 | // Default activation behaviour - set the focus for the first child | |
801 | // subwindow found. | |
802 | void wxFrame::OnActivate(wxActivateEvent& event) | |
803 | { | |
804 | for(wxNode *node = GetChildren()->First(); node; node = node->Next()) | |
805 | { | |
806 | // Find a child that's a subwindow, but not a dialog box. | |
807 | wxWindow *child = (wxWindow *)node->Data(); | |
808 | if (!child->IsKindOf(CLASSINFO(wxFrame)) && | |
809 | !child->IsKindOf(CLASSINFO(wxDialog))) | |
810 | { | |
b2aef89b | 811 | #if WXDEBUG > 1 |
2bda0e17 KB |
812 | wxDebugMsg("wxFrame::OnActivate: about to set the child's focus.\n"); |
813 | #endif | |
814 | child->SetFocus(); | |
815 | return; | |
816 | } | |
817 | } | |
818 | } | |
819 | ||
820 | // The default implementation for the close window event - calls | |
821 | // OnClose for backward compatibility. | |
822 | ||
823 | void wxFrame::OnCloseWindow(wxCloseEvent& event) | |
824 | { | |
825 | // Compatibility | |
826 | if ( GetEventHandler()->OnClose() || event.GetForce()) | |
827 | { | |
828 | this->Destroy(); | |
829 | } | |
830 | } | |
831 | ||
47fa7969 JS |
832 | bool wxFrame::OnClose(void) |
833 | { | |
834 | return TRUE; | |
835 | } | |
836 | ||
2bda0e17 KB |
837 | // Destroy the window (delayed, if a managed window) |
838 | bool wxFrame::Destroy(void) | |
839 | { | |
840 | if (!wxPendingDelete.Member(this)) | |
841 | wxPendingDelete.Append(this); | |
842 | return TRUE; | |
843 | } | |
844 | ||
845 | // Default menu selection behaviour - display a help string | |
846 | void wxFrame::OnMenuHighlight(wxMenuEvent& event) | |
847 | { | |
848 | if (GetStatusBar()) | |
849 | { | |
850 | if (event.GetMenuId() == -1) | |
851 | SetStatusText(""); | |
852 | else | |
853 | { | |
854 | wxMenuBar *menuBar = GetMenuBar(); | |
855 | if (menuBar) | |
856 | { | |
857 | wxString helpString(menuBar->GetHelpString(event.GetMenuId())); | |
858 | if (helpString != "") | |
859 | SetStatusText(helpString); | |
860 | } | |
861 | } | |
862 | } | |
863 | } | |
864 | ||
2bda0e17 KB |
865 | wxMenuBar *wxFrame::GetMenuBar(void) const |
866 | { | |
867 | return m_frameMenuBar; | |
868 | } | |
869 | ||
debe6624 | 870 | void wxFrame::Centre(int direction) |
2bda0e17 KB |
871 | { |
872 | int display_width, display_height, width, height, x, y; | |
873 | wxDisplaySize(&display_width, &display_height); | |
874 | ||
875 | GetSize(&width, &height); | |
876 | GetPosition(&x, &y); | |
877 | ||
878 | if (direction & wxHORIZONTAL) | |
879 | x = (int)((display_width - width)/2); | |
880 | if (direction & wxVERTICAL) | |
881 | y = (int)((display_height - height)/2); | |
882 | ||
883 | SetSize(x, y, width, height); | |
884 | } | |
885 | ||
886 | // Call this to simulate a menu command | |
887 | void wxFrame::Command(int id) | |
888 | { | |
889 | ProcessCommand(id); | |
890 | } | |
891 | ||
892 | void wxFrame::ProcessCommand(int id) | |
893 | { | |
894 | wxCommandEvent commandEvent(wxEVENT_TYPE_MENU_COMMAND, id); | |
895 | commandEvent.SetInt( id ); | |
896 | commandEvent.SetEventObject( this ); | |
897 | ||
898 | wxMenuBar *bar = GetMenuBar() ; | |
899 | if (!bar) | |
900 | return; | |
901 | ||
2bda0e17 KB |
902 | wxMenuItem *item = bar->FindItemForId(id) ; |
903 | if (item && item->IsCheckable()) | |
904 | { | |
2bda0e17 KB |
905 | bar->Check(id,!bar->Checked(id)) ; |
906 | } | |
debe6624 | 907 | GetEventHandler()->ProcessEvent(commandEvent); |
2bda0e17 KB |
908 | } |
909 | ||
910 | void wxFrame::OnIdle(wxIdleEvent& event) | |
911 | { | |
912 | DoMenuUpdates(); | |
913 | } | |
914 | ||
915 | // Query app for menu item updates (called from OnIdle) | |
916 | void wxFrame::DoMenuUpdates(void) | |
917 | { | |
918 | wxMenuBar* bar = GetMenuBar(); | |
919 | if (!bar) | |
920 | return; | |
921 | ||
922 | int i; | |
923 | for (i = 0; i < bar->m_menuCount; i++) | |
924 | { | |
925 | wxMenu* menu = bar->m_menus[i]; | |
926 | ||
927 | DoMenuUpdates(menu); | |
928 | } | |
929 | } | |
930 | ||
931 | void wxFrame::DoMenuUpdates(wxMenu* menu) | |
932 | { | |
933 | wxNode* node = menu->m_menuItems.First(); | |
934 | while (node) | |
935 | { | |
936 | wxMenuItem* item = (wxMenuItem*) node->Data(); | |
937 | if ( !item->IsSeparator() ) | |
938 | { | |
939 | wxWindowID id = item->GetId(); | |
940 | wxUpdateUIEvent event(id); | |
941 | event.SetEventObject( this ); | |
942 | ||
943 | if (GetEventHandler()->ProcessEvent(event)) | |
944 | { | |
945 | if (event.GetSetText()) | |
946 | menu->SetLabel(id, event.GetText()); | |
947 | if (event.GetSetChecked()) | |
948 | menu->Check(id, event.GetChecked()); | |
949 | if (event.GetSetEnabled()) | |
950 | menu->Enable(id, event.GetEnabled()); | |
951 | } | |
952 | ||
953 | if (item->GetSubMenu()) | |
954 | DoMenuUpdates(item->GetSubMenu()); | |
955 | } | |
956 | node = node->Next(); | |
957 | } | |
958 | } |