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