]>
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 | ||
57a7b7c1 JS |
351 | void wxFrame::SetAcceleratorTable(const wxAcceleratorTable& accel) |
352 | { | |
353 | m_acceleratorTable = accel; | |
354 | } | |
355 | ||
81d66cf3 JS |
356 | wxStatusBar *wxFrame::OnCreateStatusBar(int number, long style, wxWindowID id, |
357 | const wxString& name) | |
2bda0e17 KB |
358 | { |
359 | wxStatusBar *statusBar = NULL; | |
360 | ||
361 | #if USE_NATIVE_STATUSBAR | |
362 | if (UsesNativeStatusBar()) | |
363 | { | |
81d66cf3 | 364 | statusBar = new wxStatusBar95(this, id, style); |
2bda0e17 KB |
365 | } |
366 | else | |
367 | #endif | |
368 | { | |
81d66cf3 JS |
369 | statusBar = new wxStatusBar(this, id, wxPoint(0, 0), wxSize(100, 20), |
370 | style, name); | |
2bda0e17 KB |
371 | |
372 | // Set the height according to the font and the border size | |
373 | wxClientDC dc(statusBar); | |
374 | dc.SetFont(* statusBar->GetFont()); | |
375 | ||
376 | long x, y; | |
377 | dc.GetTextExtent("X", &x, &y); | |
378 | ||
379 | int height = (int)( (y * 1.1) + 2* statusBar->GetBorderY()); | |
380 | ||
381 | statusBar->SetSize(-1, -1, 100, height); | |
382 | } | |
383 | ||
384 | statusBar->SetFieldsCount(number); | |
385 | return statusBar; | |
386 | } | |
387 | ||
81d66cf3 JS |
388 | wxStatusBar* wxFrame::CreateStatusBar(int number, long style, wxWindowID id, |
389 | const wxString& name) | |
2bda0e17 KB |
390 | { |
391 | // VZ: calling CreateStatusBar twice is an error - why anyone would do it? | |
1311c7a9 VZ |
392 | wxCHECK_MSG( m_frameStatusBar == NULL, FALSE, |
393 | "recreating status bar in wxFrame" ); | |
2bda0e17 | 394 | |
81d66cf3 JS |
395 | m_frameStatusBar = OnCreateStatusBar(number, style, id, |
396 | name); | |
2bda0e17 KB |
397 | if ( m_frameStatusBar ) |
398 | { | |
399 | PositionStatusBar(); | |
81d66cf3 | 400 | return m_frameStatusBar; |
2bda0e17 KB |
401 | } |
402 | else | |
81d66cf3 | 403 | return NULL; |
2bda0e17 KB |
404 | } |
405 | ||
debe6624 | 406 | void wxFrame::SetStatusText(const wxString& text, int number) |
2bda0e17 | 407 | { |
1311c7a9 | 408 | wxCHECK_RET( m_frameStatusBar != NULL, "no statusbar to set text for" ); |
2bda0e17 KB |
409 | |
410 | m_frameStatusBar->SetStatusText(text, number); | |
411 | } | |
412 | ||
8b9518ee | 413 | void wxFrame::SetStatusWidths(int n, const int widths_field[]) |
2bda0e17 | 414 | { |
1311c7a9 | 415 | wxCHECK_RET( m_frameStatusBar != NULL, "no statusbar to set widths for" ); |
2bda0e17 KB |
416 | |
417 | m_frameStatusBar->SetStatusWidths(n, widths_field); | |
418 | PositionStatusBar(); | |
419 | } | |
420 | ||
421 | void wxFrame::PositionStatusBar(void) | |
422 | { | |
423 | // native status bar positions itself | |
424 | if (m_frameStatusBar | |
425 | #if USE_NATIVE_STATUSBAR | |
426 | && !m_frameStatusBar->IsKindOf(CLASSINFO(wxStatusBar95)) | |
427 | #endif | |
428 | ) | |
429 | { | |
430 | int w, h; | |
431 | GetClientSize(&w, &h); | |
432 | int sw, sh; | |
433 | m_frameStatusBar->GetSize(&sw, &sh); | |
81d66cf3 JS |
434 | |
435 | // Since we wish the status bar to be directly under the client area, | |
436 | // we use the adjusted sizes without using wxSIZE_NO_ADJUSTMENTS. | |
2bda0e17 KB |
437 | m_frameStatusBar->SetSize(0, h, w, sh); |
438 | } | |
439 | } | |
440 | ||
441 | void wxFrame::SetMenuBar(wxMenuBar *menu_bar) | |
442 | { | |
443 | if (!menu_bar) | |
444 | { | |
445 | m_frameMenuBar = NULL; | |
446 | return; | |
447 | } | |
448 | ||
449 | if (menu_bar->m_menuBarFrame) | |
450 | return; | |
451 | ||
452 | int i; | |
453 | HMENU menu = CreateMenu(); | |
454 | ||
455 | for (i = 0; i < menu_bar->m_menuCount; i ++) | |
456 | { | |
457 | HMENU popup = (HMENU)menu_bar->m_menus[i]->m_hMenu; | |
458 | // | |
459 | // After looking Bounds Checker result, it seems that all | |
460 | // menus must be individually destroyed. So, don't reset m_hMenu, | |
461 | // to allow ~wxMenu to do the job. | |
462 | // | |
463 | menu_bar->m_menus[i]->m_savehMenu = (WXHMENU) popup; | |
464 | // Uncommenting for the moment... JACS | |
465 | menu_bar->m_menus[i]->m_hMenu = 0; | |
466 | AppendMenu(menu, MF_POPUP | MF_STRING, (UINT)popup, menu_bar->m_titles[i]); | |
467 | } | |
468 | ||
469 | menu_bar->m_hMenu = (WXHMENU)menu; | |
470 | if (m_frameMenuBar) | |
471 | delete m_frameMenuBar; | |
472 | ||
473 | this->m_hMenu = (WXHMENU) menu; | |
474 | ||
475 | DWORD err = 0; | |
476 | if (!SetMenu((HWND) GetHWND(), menu)) | |
477 | { | |
478 | #ifdef __WIN32__ | |
479 | err = GetLastError(); | |
480 | #endif | |
481 | } | |
482 | ||
483 | m_frameMenuBar = menu_bar; | |
484 | menu_bar->m_menuBarFrame = this; | |
485 | } | |
486 | ||
57a7b7c1 | 487 | #if 0 |
2bda0e17 KB |
488 | bool wxFrame::LoadAccelerators(const wxString& table) |
489 | { | |
490 | m_acceleratorTable = (WXHANDLE) | |
491 | #ifdef __WIN32__ | |
492 | #ifdef UNICODE | |
493 | ::LoadAcceleratorsW(wxGetInstance(), (const char *)table); | |
494 | #else | |
495 | ::LoadAcceleratorsA(wxGetInstance(), (const char *)table); | |
496 | #endif | |
497 | #else | |
498 | ::LoadAccelerators(wxGetInstance(), (const char *)table); | |
499 | #endif | |
500 | ||
501 | // The above is necessary because LoadAccelerators is a macro | |
502 | // which we have undefed earlier in the file to avoid confusion | |
503 | // with wxFrame::LoadAccelerators. Ugh! | |
504 | ||
505 | return (m_acceleratorTable != (WXHANDLE) NULL); | |
506 | } | |
57a7b7c1 | 507 | #endif |
2bda0e17 KB |
508 | |
509 | void wxFrame::Fit(void) | |
510 | { | |
511 | // Work out max. size | |
512 | wxNode *node = GetChildren()->First(); | |
513 | int max_width = 0; | |
514 | int max_height = 0; | |
515 | while (node) | |
516 | { | |
517 | // Find a child that's a subwindow, but not a dialog box. | |
518 | wxWindow *win = (wxWindow *)node->Data(); | |
519 | ||
520 | if (!win->IsKindOf(CLASSINFO(wxFrame)) && | |
521 | !win->IsKindOf(CLASSINFO(wxDialog))) | |
522 | { | |
523 | int width, height; | |
524 | int x, y; | |
525 | win->GetSize(&width, &height); | |
526 | win->GetPosition(&x, &y); | |
527 | ||
528 | if ((x + width) > max_width) | |
529 | max_width = x + width; | |
530 | if ((y + height) > max_height) | |
531 | max_height = y + height; | |
532 | } | |
533 | node = node->Next(); | |
534 | } | |
535 | SetClientSize(max_width, max_height); | |
536 | } | |
537 | ||
538 | // Responds to colour changes, and passes event on to children. | |
539 | void wxFrame::OnSysColourChanged(wxSysColourChangedEvent& event) | |
540 | { | |
541 | SetBackgroundColour(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_APPWORKSPACE)); | |
542 | Refresh(); | |
543 | ||
544 | if ( m_frameStatusBar ) | |
545 | { | |
546 | wxSysColourChangedEvent event2; | |
547 | event2.SetEventObject( m_frameStatusBar ); | |
548 | m_frameStatusBar->ProcessEvent(event2); | |
549 | } | |
550 | ||
551 | // Propagate the event to the non-top-level children | |
552 | wxWindow::OnSysColourChanged(event); | |
553 | } | |
554 | ||
555 | /* | |
556 | * Frame window | |
557 | * | |
558 | */ | |
559 | ||
debe6624 JS |
560 | void wxFrame::MSWCreate(int id, wxWindow *parent, const char *wclass, wxWindow *wx_win, const char *title, |
561 | int x, int y, int width, int height, long style) | |
2bda0e17 KB |
562 | |
563 | { | |
564 | m_defaultIcon = (WXHICON) (wxSTD_FRAME_ICON ? wxSTD_FRAME_ICON : wxDEFAULT_FRAME_ICON); | |
565 | ||
566 | // If child windows aren't properly drawn initially, WS_CLIPCHILDREN | |
567 | // could be the culprit. But without it, you can get a lot of flicker. | |
568 | ||
2bda0e17 KB |
569 | DWORD msflags = 0; |
570 | if ((style & wxCAPTION) == wxCAPTION) | |
1c089c47 | 571 | msflags = WS_OVERLAPPED; |
2bda0e17 | 572 | else |
1c089c47 | 573 | msflags = WS_POPUP; |
2bda0e17 KB |
574 | |
575 | if (style & wxMINIMIZE_BOX) | |
576 | msflags |= WS_MINIMIZEBOX; | |
577 | if (style & wxMAXIMIZE_BOX) | |
578 | msflags |= WS_MAXIMIZEBOX; | |
579 | if (style & wxTHICK_FRAME) | |
580 | msflags |= WS_THICKFRAME; | |
581 | if (style & wxSYSTEM_MENU) | |
582 | msflags |= WS_SYSMENU; | |
583 | if ((style & wxMINIMIZE) || (style & wxICONIZE)) | |
584 | msflags |= WS_MINIMIZE; | |
585 | if (style & wxMAXIMIZE) | |
586 | msflags |= WS_MAXIMIZE; | |
587 | if (style & wxCAPTION) | |
588 | msflags |= WS_CAPTION; | |
1c089c47 JS |
589 | if (style & wxCLIP_CHILDREN) |
590 | msflags |= WS_CLIPCHILDREN; | |
2bda0e17 KB |
591 | |
592 | // Keep this in wxFrame because it saves recoding this function | |
593 | // in wxTinyFrame | |
594 | #if USE_ITSY_BITSY | |
595 | if (style & wxTINY_CAPTION_VERT) | |
596 | msflags |= IBS_VERTCAPTION; | |
597 | if (style & wxTINY_CAPTION_HORIZ) | |
598 | msflags |= IBS_HORZCAPTION; | |
599 | #else | |
600 | if (style & wxTINY_CAPTION_VERT) | |
601 | msflags |= WS_CAPTION; | |
602 | if (style & wxTINY_CAPTION_HORIZ) | |
603 | msflags |= WS_CAPTION; | |
604 | #endif | |
605 | if ((style & wxTHICK_FRAME) == 0) | |
606 | msflags |= WS_BORDER; | |
607 | ||
608 | WXDWORD extendedStyle = MakeExtendedStyle(style); | |
609 | ||
610 | if (style & wxSTAY_ON_TOP) | |
611 | extendedStyle |= WS_EX_TOPMOST; | |
612 | ||
613 | m_iconized = FALSE; | |
614 | wxWindow::MSWCreate(id, parent, wclass, wx_win, title, x, y, width, height, | |
615 | msflags, NULL, extendedStyle); | |
616 | // Seems to be necessary if we use WS_POPUP | |
617 | // style instead of WS_OVERLAPPED | |
618 | if (width > -1 && height > -1) | |
619 | ::PostMessage((HWND) GetHWND(), WM_SIZE, SIZE_RESTORED, MAKELPARAM(width, height)); | |
620 | } | |
621 | ||
622 | bool wxFrame::MSWOnPaint(void) | |
623 | { | |
b2aef89b | 624 | #if WXDEBUG > 1 |
2bda0e17 KB |
625 | wxDebugMsg("wxFrameWnd::OnPaint %d\n", handle); |
626 | #endif | |
627 | RECT rect; | |
628 | if (GetUpdateRect((HWND) GetHWND(), &rect, FALSE)) | |
629 | { | |
630 | if (m_iconized) | |
631 | { | |
632 | HICON the_icon; | |
633 | if (m_icon.Ok()) | |
634 | the_icon = (HICON) m_icon.GetHICON(); | |
635 | if (the_icon == 0) | |
636 | the_icon = (HICON) m_defaultIcon; | |
637 | ||
638 | PAINTSTRUCT ps; | |
639 | // Hold a pointer to the dc so long as the OnPaint() message | |
640 | // is being processed | |
641 | HDC cdc = BeginPaint((HWND) GetHWND(), &ps); | |
642 | ||
643 | // Erase background before painting or we get white background | |
644 | this->MSWDefWindowProc(WM_ICONERASEBKGND,(WORD)ps.hdc,0L); | |
645 | ||
646 | if (the_icon) | |
647 | { | |
648 | RECT rect; | |
649 | GetClientRect((HWND) GetHWND(), &rect); | |
650 | int icon_width = 32; | |
651 | int icon_height = 32; | |
652 | int icon_x = (int)((rect.right - icon_width)/2); | |
653 | int icon_y = (int)((rect.bottom - icon_height)/2); | |
654 | DrawIcon(cdc, icon_x, icon_y, the_icon); | |
655 | } | |
656 | ||
657 | EndPaint((HWND) GetHWND(), &ps); | |
658 | } | |
1c089c47 | 659 | else |
2bda0e17 | 660 | { |
debe6624 JS |
661 | wxPaintEvent event(m_windowId); |
662 | event.m_eventObject = this; | |
663 | if (!GetEventHandler()->ProcessEvent(event)) | |
664 | Default(); | |
2bda0e17 KB |
665 | } |
666 | return 0; | |
667 | } | |
668 | return 1; | |
669 | } | |
670 | ||
671 | WXHICON wxFrame::MSWOnQueryDragIcon(void) | |
672 | { | |
673 | if (m_icon.Ok() && (m_icon.GetHICON() != 0)) | |
674 | return m_icon.GetHICON(); | |
675 | else | |
676 | return m_defaultIcon; | |
677 | } | |
678 | ||
debe6624 | 679 | void wxFrame::MSWOnSize(int x, int y, WXUINT id) |
2bda0e17 | 680 | { |
b2aef89b | 681 | #if WXDEBUG > 1 |
2bda0e17 KB |
682 | wxDebugMsg("wxFrameWnd::OnSize %d\n", m_hWnd); |
683 | #endif | |
684 | switch (id) | |
685 | { | |
686 | case SIZEFULLSCREEN: | |
687 | case SIZENORMAL: | |
688 | m_iconized = FALSE; | |
689 | break; | |
690 | case SIZEICONIC: | |
691 | m_iconized = TRUE; | |
692 | break; | |
693 | } | |
694 | ||
695 | if (!m_iconized) | |
696 | { | |
697 | // forward WM_SIZE to status bar control | |
698 | #if USE_NATIVE_STATUSBAR | |
699 | if (m_frameStatusBar && m_frameStatusBar->IsKindOf(CLASSINFO(wxStatusBar95))) | |
700 | { | |
701 | wxSizeEvent event(wxSize(x, y), m_frameStatusBar->GetId()); | |
702 | event.SetEventObject( m_frameStatusBar ); | |
703 | ||
704 | ((wxStatusBar95 *)m_frameStatusBar)->OnSize(event); | |
705 | } | |
706 | #endif | |
707 | ||
708 | PositionStatusBar(); | |
81d66cf3 JS |
709 | PositionToolBar(); |
710 | ||
2bda0e17 KB |
711 | wxSizeEvent event(wxSize(x, y), m_windowId); |
712 | event.SetEventObject( this ); | |
debe6624 JS |
713 | if (!GetEventHandler()->ProcessEvent(event)) |
714 | Default(); | |
2bda0e17 KB |
715 | } |
716 | } | |
717 | ||
718 | bool wxFrame::MSWOnClose(void) | |
719 | { | |
b2aef89b | 720 | #if WXDEBUG > 1 |
2bda0e17 KB |
721 | wxDebugMsg("wxFrameWnd::OnClose %d\n", handle); |
722 | #endif | |
723 | return Close(); | |
724 | } | |
725 | ||
debe6624 | 726 | bool wxFrame::MSWOnCommand(WXWORD id, WXWORD cmd, WXHWND control) |
2bda0e17 | 727 | { |
b2aef89b | 728 | #if WXDEBUG > 1 |
2bda0e17 KB |
729 | wxDebugMsg("wxFrameWnd::OnCommand %d\n", handle); |
730 | #endif | |
731 | if (cmd == 0 || cmd == 1 ) // Can be either a menu command or an accelerator. | |
732 | { | |
733 | // In case it's e.g. a toolbar. | |
734 | wxWindow *win = wxFindWinFromHandle(control); | |
735 | if (win) | |
736 | return win->MSWCommand(cmd, id); | |
737 | ||
738 | if (GetMenuBar() && GetMenuBar()->FindItemForId(id)) | |
739 | { | |
740 | ProcessCommand(id); | |
741 | return TRUE; | |
742 | } | |
743 | else | |
744 | return FALSE; | |
745 | } | |
746 | else | |
747 | return FALSE; | |
748 | } | |
749 | ||
debe6624 | 750 | void wxFrame::MSWOnMenuHighlight(WXWORD nItem, WXWORD nFlags, WXHMENU hSysMenu) |
2bda0e17 | 751 | { |
2bda0e17 KB |
752 | if (nFlags == 0xFFFF && hSysMenu == 0) |
753 | { | |
754 | wxMenuEvent event(wxEVT_MENU_HIGHLIGHT, -1); | |
755 | event.SetEventObject( this ); | |
756 | GetEventHandler()->ProcessEvent(event); | |
757 | } | |
758 | else if (nFlags != MF_SEPARATOR) | |
759 | { | |
760 | wxMenuEvent event(wxEVT_MENU_HIGHLIGHT, nItem); | |
761 | event.SetEventObject( this ); | |
762 | GetEventHandler()->ProcessEvent(event); | |
763 | } | |
2bda0e17 KB |
764 | } |
765 | ||
766 | bool wxFrame::MSWProcessMessage(WXMSG* pMsg) | |
767 | { | |
57a7b7c1 JS |
768 | return FALSE; |
769 | } | |
770 | ||
771 | bool wxFrame::MSWTranslateMessage(WXMSG* pMsg) | |
772 | { | |
773 | if (m_acceleratorTable.Ok() && | |
774 | ::TranslateAccelerator((HWND) GetHWND(), (HACCEL) m_acceleratorTable.GetHACCEL(), (MSG *)pMsg)) | |
2bda0e17 KB |
775 | return TRUE; |
776 | ||
777 | return FALSE; | |
778 | } | |
779 | ||
780 | // Default resizing behaviour - if only ONE subwindow, | |
781 | // resize to client rectangle size | |
782 | void wxFrame::OnSize(wxSizeEvent& event) | |
783 | { | |
cd70477b VZ |
784 | // if we're using constraints - do use them |
785 | #if USE_CONSTRAINTS | |
786 | if ( GetAutoLayout() ) { | |
787 | Layout(); | |
788 | return; | |
789 | } | |
790 | #endif | |
791 | ||
792 | // do we have _exactly_ one child? | |
2bda0e17 | 793 | wxWindow *child = NULL; |
cd70477b | 794 | for ( wxNode *node = GetChildren()->First(); node; node = node->Next() ) |
2bda0e17 KB |
795 | { |
796 | wxWindow *win = (wxWindow *)node->Data(); | |
cd70477b VZ |
797 | if ( !win->IsKindOf(CLASSINFO(wxFrame)) && |
798 | !win->IsKindOf(CLASSINFO(wxDialog)) && | |
73e7daa0 JS |
799 | (win != GetStatusBar()) && |
800 | (win != GetToolBar()) ) | |
2bda0e17 | 801 | { |
cd70477b VZ |
802 | if ( child ) |
803 | return; // it's our second subwindow - nothing to do | |
2bda0e17 | 804 | child = win; |
2bda0e17 KB |
805 | } |
806 | } | |
807 | ||
cd70477b VZ |
808 | if ( child ) { |
809 | // we have exactly one child - set it's size to fill the whole frame | |
73e7daa0 JS |
810 | int clientW, clientH; |
811 | GetClientSize(&clientW, &clientH); | |
2bda0e17 | 812 | |
73e7daa0 JS |
813 | int x = 0; |
814 | int y = 0; | |
815 | ||
73e7daa0 | 816 | child->SetSize(x, y, clientW, clientH); |
2bda0e17 | 817 | } |
2bda0e17 KB |
818 | } |
819 | ||
820 | // Default activation behaviour - set the focus for the first child | |
821 | // subwindow found. | |
822 | void wxFrame::OnActivate(wxActivateEvent& event) | |
823 | { | |
824 | for(wxNode *node = GetChildren()->First(); node; node = node->Next()) | |
825 | { | |
826 | // Find a child that's a subwindow, but not a dialog box. | |
827 | wxWindow *child = (wxWindow *)node->Data(); | |
828 | if (!child->IsKindOf(CLASSINFO(wxFrame)) && | |
829 | !child->IsKindOf(CLASSINFO(wxDialog))) | |
830 | { | |
b2aef89b | 831 | #if WXDEBUG > 1 |
2bda0e17 KB |
832 | wxDebugMsg("wxFrame::OnActivate: about to set the child's focus.\n"); |
833 | #endif | |
834 | child->SetFocus(); | |
835 | return; | |
836 | } | |
837 | } | |
838 | } | |
839 | ||
840 | // The default implementation for the close window event - calls | |
841 | // OnClose for backward compatibility. | |
842 | ||
843 | void wxFrame::OnCloseWindow(wxCloseEvent& event) | |
844 | { | |
845 | // Compatibility | |
846 | if ( GetEventHandler()->OnClose() || event.GetForce()) | |
847 | { | |
848 | this->Destroy(); | |
849 | } | |
850 | } | |
851 | ||
47fa7969 JS |
852 | bool wxFrame::OnClose(void) |
853 | { | |
854 | return TRUE; | |
855 | } | |
856 | ||
2bda0e17 KB |
857 | // Destroy the window (delayed, if a managed window) |
858 | bool wxFrame::Destroy(void) | |
859 | { | |
860 | if (!wxPendingDelete.Member(this)) | |
861 | wxPendingDelete.Append(this); | |
862 | return TRUE; | |
863 | } | |
864 | ||
865 | // Default menu selection behaviour - display a help string | |
866 | void wxFrame::OnMenuHighlight(wxMenuEvent& event) | |
867 | { | |
868 | if (GetStatusBar()) | |
869 | { | |
870 | if (event.GetMenuId() == -1) | |
871 | SetStatusText(""); | |
872 | else | |
873 | { | |
874 | wxMenuBar *menuBar = GetMenuBar(); | |
875 | if (menuBar) | |
876 | { | |
877 | wxString helpString(menuBar->GetHelpString(event.GetMenuId())); | |
878 | if (helpString != "") | |
879 | SetStatusText(helpString); | |
880 | } | |
881 | } | |
882 | } | |
883 | } | |
884 | ||
2bda0e17 KB |
885 | wxMenuBar *wxFrame::GetMenuBar(void) const |
886 | { | |
887 | return m_frameMenuBar; | |
888 | } | |
889 | ||
debe6624 | 890 | void wxFrame::Centre(int direction) |
2bda0e17 KB |
891 | { |
892 | int display_width, display_height, width, height, x, y; | |
893 | wxDisplaySize(&display_width, &display_height); | |
894 | ||
895 | GetSize(&width, &height); | |
896 | GetPosition(&x, &y); | |
897 | ||
898 | if (direction & wxHORIZONTAL) | |
899 | x = (int)((display_width - width)/2); | |
900 | if (direction & wxVERTICAL) | |
901 | y = (int)((display_height - height)/2); | |
902 | ||
903 | SetSize(x, y, width, height); | |
904 | } | |
905 | ||
906 | // Call this to simulate a menu command | |
907 | void wxFrame::Command(int id) | |
908 | { | |
909 | ProcessCommand(id); | |
910 | } | |
911 | ||
912 | void wxFrame::ProcessCommand(int id) | |
913 | { | |
914 | wxCommandEvent commandEvent(wxEVENT_TYPE_MENU_COMMAND, id); | |
915 | commandEvent.SetInt( id ); | |
916 | commandEvent.SetEventObject( this ); | |
917 | ||
918 | wxMenuBar *bar = GetMenuBar() ; | |
919 | if (!bar) | |
920 | return; | |
921 | ||
2bda0e17 KB |
922 | wxMenuItem *item = bar->FindItemForId(id) ; |
923 | if (item && item->IsCheckable()) | |
924 | { | |
2bda0e17 KB |
925 | bar->Check(id,!bar->Checked(id)) ; |
926 | } | |
debe6624 | 927 | GetEventHandler()->ProcessEvent(commandEvent); |
2bda0e17 KB |
928 | } |
929 | ||
81d66cf3 JS |
930 | // Checks if there is a toolbar, and returns the first free client position |
931 | wxPoint wxFrame::GetClientAreaOrigin() const | |
932 | { | |
933 | wxPoint pt(0, 0); | |
934 | if (GetToolBar()) | |
935 | { | |
936 | int w, h; | |
937 | GetToolBar()->GetSize(& w, & h); | |
938 | ||
939 | if (GetToolBar()->GetWindowStyleFlag() & wxTB_VERTICAL) | |
940 | { | |
941 | pt.x += w; | |
942 | } | |
943 | else | |
944 | { | |
945 | pt.y += h; | |
946 | } | |
947 | } | |
948 | return pt; | |
949 | } | |
950 | ||
951 | wxToolBar* wxFrame::CreateToolBar(long style, wxWindowID id, const wxString& name) | |
952 | { | |
953 | wxCHECK_MSG( m_frameToolBar == NULL, FALSE, | |
954 | "recreating toolbar in wxFrame" ); | |
955 | ||
956 | wxToolBar* toolBar = OnCreateToolBar(style, id, name); | |
957 | if (toolBar) | |
958 | { | |
959 | SetToolBar(toolBar); | |
960 | PositionToolBar(); | |
961 | return toolBar; | |
962 | } | |
963 | else | |
964 | { | |
965 | return NULL; | |
966 | } | |
967 | } | |
968 | ||
969 | wxToolBar* wxFrame::OnCreateToolBar(long style, wxWindowID id, const wxString& name) | |
970 | { | |
971 | return new wxToolBar(this, id, wxDefaultPosition, wxDefaultSize, style, name); | |
972 | } | |
973 | ||
974 | void wxFrame::PositionToolBar(void) | |
975 | { | |
976 | int cw, ch; | |
977 | ||
978 | RECT rect; | |
979 | ::GetClientRect((HWND) GetHWND(), &rect); | |
980 | ||
981 | if ( GetStatusBar() ) | |
982 | { | |
983 | int statusX, statusY; | |
984 | GetStatusBar()->GetClientSize(&statusX, &statusY); | |
985 | rect.bottom -= statusY; | |
986 | } | |
987 | ||
988 | if (GetToolBar()) | |
989 | { | |
990 | int tw, th; | |
991 | GetToolBar()->GetSize(& tw, & th); | |
992 | ||
993 | if (GetToolBar()->GetWindowStyleFlag() & wxTB_VERTICAL) | |
994 | { | |
995 | // Use the 'real' MSW position | |
996 | GetToolBar()->SetSize(0, 0, tw, rect.bottom, wxSIZE_NO_ADJUSTMENTS); | |
997 | } | |
998 | else | |
999 | { | |
1000 | // Use the 'real' MSW position | |
1001 | GetToolBar()->SetSize(0, 0, rect.right, th, wxSIZE_NO_ADJUSTMENTS); | |
1002 | } | |
1003 | } | |
1004 | } | |
1005 |