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