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