]> git.saurik.com Git - wxWidgets.git/blame - src/os2/frame.cpp
HP-UX recommendations added
[wxWidgets.git] / src / os2 / frame.cpp
CommitLineData
0e320a79
DW
1/////////////////////////////////////////////////////////////////////////////
2// Name: frame.cpp
3// Purpose: wxFrame
f0a56ab0 4// Author: David Webster
0e320a79 5// Modified by:
29435d81 6// Created: 10/27/99
0e320a79 7// RCS-ID: $Id$
f0a56ab0 8// Copyright: (c) David Webster
0e320a79
DW
9// Licence: wxWindows licence
10/////////////////////////////////////////////////////////////////////////////
11
21802234
DW
12// For compilers that support precompilation, includes "wx.h".
13#include "wx/wxprec.h"
14
15#ifndef WX_PRECOMP
16 #include "wx/setup.h"
17 #include "wx/frame.h"
18 #include "wx/menu.h"
19 #include "wx/app.h"
20 #include "wx/utils.h"
21 #include "wx/dialog.h"
22 #include "wx/settings.h"
23 #include "wx/dcclient.h"
24#endif // WX_PRECOMP
25
26#include "wx/os2/private.h"
f38374d0
DW
27
28#if wxUSE_STATUSBAR
29 #include "wx/statusbr.h"
ea51d98d 30 #include "wx/generic/statusbr.h"
f38374d0
DW
31#endif // wxUSE_STATUSBAR
32
33#if wxUSE_TOOLBAR
34 #include "wx/toolbar.h"
35#endif // wxUSE_TOOLBAR
36
0e320a79 37#include "wx/menuitem.h"
21802234 38#include "wx/log.h"
0e320a79 39
f38374d0
DW
40// ----------------------------------------------------------------------------
41// globals
42// ----------------------------------------------------------------------------
43
21802234
DW
44extern wxWindowList wxModelessWindows;
45extern wxList WXDLLEXPORT wxPendingDelete;
46extern wxChar wxFrameClassName[];
47extern wxMenu *wxCurrentPopupMenu;
0e320a79 48
f38374d0
DW
49// ----------------------------------------------------------------------------
50// event tables
51// ----------------------------------------------------------------------------
52
f38374d0
DW
53BEGIN_EVENT_TABLE(wxFrame, wxFrameBase)
54 EVT_ACTIVATE(wxFrame::OnActivate)
55 EVT_SYS_COLOUR_CHANGED(wxFrame::OnSysColourChanged)
0e320a79
DW
56END_EVENT_TABLE()
57
58IMPLEMENT_DYNAMIC_CLASS(wxFrame, wxWindow)
0e320a79 59
f38374d0
DW
60// ============================================================================
61// implementation
62// ============================================================================
0e320a79 63
f38374d0
DW
64// ----------------------------------------------------------------------------
65// static class members
66// ----------------------------------------------------------------------------
0e320a79 67
f38374d0
DW
68#if wxUSE_NATIVE_STATUSBAR
69 bool wxFrame::m_useNativeStatusBar = TRUE;
70#else
71 bool wxFrame::m_useNativeStatusBar = FALSE;
72#endif
0e320a79 73
f38374d0
DW
74// ----------------------------------------------------------------------------
75// creation/destruction
76// ----------------------------------------------------------------------------
77
78void wxFrame::Init()
0e320a79 79{
80d83cbc 80 m_bIconized = FALSE;
f38374d0 81
21802234 82#if wxUSE_TOOLTIPS
80d83cbc 83 m_hHwndToolTip = 0;
21802234 84#endif
ea51d98d
DW
85 // Data to save/restore when calling ShowFullScreen
86 m_lFsStyle = 0L;
87 m_lFsOldWindowStyle = 0L;
88 m_nFsStatusBarFields = 0;
89 m_nFsStatusBarHeight = 0;
90 m_nFsToolBarHeight = 0;
91 m_bFsIsMaximized = FALSE;
92 m_bFsIsShowing = FALSE;
93} // end of wxFrame::Init
94
95bool wxFrame::Create(
96 wxWindow* pParent
97, wxWindowID vId
98, const wxString& rsTitle
99, const wxPoint& rPos
100, const wxSize& rSize
101, long lStyle
102, const wxString& rsName
103)
f38374d0 104{
ea51d98d
DW
105 int nX = rPos.x;
106 int nY = rPos.y;
107 int nWidth = rSize.x;
108 int nHeight = rSize.y;
ea51d98d
DW
109
110 SetName(rsName);
111 m_windowStyle = lStyle;
112 m_frameMenuBar = NULL;
113 m_frameToolBar = NULL;
114 m_frameStatusBar = NULL;
115
116 SetBackgroundColour(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_APPWORKSPACE));
117
118 if (vId > -1 )
119 m_windowId = vId;
120 else
121 m_windowId = (int)NewControlId();
122
80d83cbc 123 if (pParent)
ea51d98d
DW
124 pParent->AddChild(this);
125
126 m_bIconized = FALSE;
127
128 //
129 // We pass NULL as parent to MSWCreate because frames with parents behave
80d83cbc 130 // very strangely under Win95 shell.
ea51d98d
DW
131 // Alteration by JACS: keep normal Windows behaviour (float on top of parent)
132 // with this style.
133 //
134 if ((m_windowStyle & wxFRAME_FLOAT_ON_PARENT) == 0)
135 pParent = NULL;
136
137 if (!pParent)
138 wxTopLevelWindows.Append(this);
139
140 OS2Create( m_windowId
141 ,pParent
142 ,wxFrameClassName
143 ,this
144 ,rsTitle
145 ,nX
146 ,nY
147 ,nWidth
148 ,nHeight
149 ,lStyle
150 );
151
152 wxModelessWindows.Append(this);
153 return TRUE;
154} // end of wxFrame::Create
0e320a79
DW
155
156wxFrame::~wxFrame()
157{
ea51d98d
DW
158 m_isBeingDeleted = TRUE;
159 wxTopLevelWindows.DeleteObject(this);
0e320a79 160
ea51d98d 161 DeleteAllBars();
29435d81 162
ea51d98d
DW
163 if (wxTheApp && (wxTopLevelWindows.Number() == 0))
164 {
165 wxTheApp->SetTopWindow(NULL);
0e320a79 166
ea51d98d
DW
167 if (wxTheApp->GetExitOnFrameDelete())
168 {
80d83cbc 169 ::WinPostMsg(GetHwnd(), WM_QUIT, 0, 0);
ea51d98d
DW
170 }
171 }
172 wxModelessWindows.DeleteObject(this);
173
174 //
175 // For some reason, wxWindows can activate another task altogether
176 // when a frame is destroyed after a modal dialog has been invoked.
177 // Try to bring the parent to the top.
178 //
179 // MT:Only do this if this frame is currently the active window, else weird
180 // things start to happen.
181 //
182 if (wxGetActiveWindow() == this)
0e320a79 183 {
ea51d98d
DW
184 if (GetParent() && GetParent()->GetHWND())
185 {
ea51d98d
DW
186 ::WinSetWindowPos( (HWND) GetParent()->GetHWND()
187 ,HWND_TOP
80d83cbc
DW
188 ,0
189 ,0
190 ,0
191 ,0
192 ,SWP_ZORDER
ea51d98d
DW
193 );
194 }
0e320a79 195 }
ea51d98d 196} // end of wxFrame::~wxFrame
0e320a79 197
ea51d98d 198//
0e320a79 199// Get size *available for subwindows* i.e. excluding menu bar, toolbar etc.
ea51d98d 200//
80d83cbc
DW
201void wxFrame::DoGetClientSize(
202 int* pX
203, int* pY
204) const
0e320a79 205{
80d83cbc
DW
206 //
207 // OS/2 PM's coordinates go from bottom-left not
208 // top-left thus the += instead of the -=
209 //
210 RECTL vRect;
211 HWND hWndClient;
212
213 //
214 // PM has no GetClientRect that inherantly knows about the client window
215 // We have to explicitly go fetch it!
216 //
217 hWndClient = ::WinWindowFromId(GetHwnd(), FID_CLIENT);
218 ::WinQueryWindowRect(hWndClient, &vRect);
21802234 219
f38374d0 220#if wxUSE_STATUSBAR
80d83cbc
DW
221 if ( GetStatusBar() )
222 {
223 int nStatusX
224 int nStatusY;
225
226 GetStatusBar()->GetClientSize( &nStatusX
227 ,&nStatusY
228 );
229 vRect.yBottom += nStatusY;
230 }
f38374d0 231#endif // wxUSE_STATUSBAR
21802234 232
80d83cbc
DW
233 wxPoint vPoint(GetClientAreaOrigin());
234
235 vRect.bottom += pt.y;
236 vRect.right -= pt.x;
21802234 237
80d83cbc
DW
238 if (pX)
239 *pX = vRect.xRight;
240 if (pY)
241 *pY = vRect.yBottom;
242} // end of wxFrame::DoGetClientSize
0e320a79 243
80d83cbc 244//
0e320a79
DW
245// Set the client size (i.e. leave the calculation of borders etc.
246// to wxWindows)
80d83cbc
DW
247//
248void wxFrame::DoSetClientSize(
249 int nWidth
250, int nHeight
251)
0e320a79 252{
80d83cbc
DW
253 HWND hWnd = GetHwnd();
254 HWND hWndClient;
255 RECTL vRect;
256 RECT vRect2;
0e320a79 257
80d83cbc
DW
258 hWndClient = ::WinWindowFromId(GetHwnd(), FID_CLIENT);
259 ::WinQueryWindowRect(hWndClient, &vRect);
21802234 260
80d83cbc 261 ::WinQueryWindowRect(hWnd, &vRect2);
21802234 262
80d83cbc
DW
263 //
264 // Find the difference between the entire window (title bar and all)
265 // and the client area; add this to the new client size to move the
266 // window. Remember OS/2's backwards y coord system!
267 //
268 int nActualWidth = vRect2.xRight - vRect2.xLeft - vRect.xRight + nWidth;
269 int nActualHeight = vRect2.yTop + vRect2.yTop - vRect.yTop + nHeight;
29435d81 270
f38374d0 271#if wxUSE_STATUSBAR
80d83cbc
DW
272 if ( GetStatusBar() )
273 {
274 int nStatusX;
275 int nStatusY;
276
277 GetStatusBar()->GetClientSize( &nStatusX
278 ,&nStatusY
279 );
280 nActualHeight += nStatusY;
281 }
f38374d0 282#endif // wxUSE_STATUSBAR
29435d81 283
80d83cbc
DW
284 wxPoint vPoint(GetClientAreaOrigin());
285 nActualWidth += vPoint.y;
286 nActualHeight += vPoint.x;
287
288 POINTL vPointl;
289
290 vPointl.x = vRect2.xLeft;
291 vPoint.y = vRect2.yTop;
292
293 ::WinSetWindowPos( hWnd
294 ,HWND_TOP
295 ,vPointl.x
296 ,vPointl.y
297 ,nActualWidth
298 ,nActualHeight
299 ,SWP_MOVE | SWP_SIZE | SWP_SHOW
300 );
301
302 wxSizeEvent vEvent( wxSize( nWidth
303 ,nHeight
304 )
305 ,m_windowId
306 );
307 vEvent.SetEventObject(this);
308 GetEventHandler()->ProcessEvent(vEvent);
309} // end of wxFrame::DoSetClientSize
310
311void wxFrame::DoGetSize(
312 int* pWidth
313, int* pHeight
314) const
315{
316 RECTL vRect;
21802234 317
80d83cbc
DW
318 ::WinQueryWindowRect(GetHwnd(), &vRect);
319 *pWidth = vRect.xRight - vRect.xLeft;
320 *pHeight = vRect.yTop - vRect.yBottom;
321} // end of wxFrame::DoGetSize
21802234 322
80d83cbc
DW
323void wxFrame::DoGetPosition(
324 int* pX
325, int* pY
326) const
327{
328 RECTL vRect;
329 POINT vPoint;
29435d81 330
80d83cbc
DW
331 ::WinQueryWindowRect(GetHwnd(), &vRect);
332 vPoint.x = vRect.xLeft;
0e320a79 333
80d83cbc
DW
334 //
335 // OS/2 is backwards [WIN32 it is vRect.yTop]
336 //
337 vPoint.y = vRect.yBottom;
0e320a79 338
80d83cbc
DW
339 *pX = vPoint.x;
340 *pY = vPoint.y;
341} // end of wxFrame::DoGetPosition
0e320a79 342
f38374d0
DW
343// ----------------------------------------------------------------------------
344// variations around ::ShowWindow()
345// ----------------------------------------------------------------------------
346
80d83cbc
DW
347void wxFrame::DoShowWindow(
348 int nShowCmd
349)
0e320a79 350{
80d83cbc
DW
351 ::WinShowWindow(GetHwnd(), nShowCmd);
352 m_bIconized = nShowCmd == SWP_MINIMIZE;
353} // end of wxFrame::DoShowWindow
21802234 354
80d83cbc
DW
355bool wxFrame::Show(
356 bool bShow
357)
0e320a79 358{
80d83cbc 359 DoShowWindow(show ? SWP_SHOW : SW_HIDE);
21802234 360
80d83cbc 361 if (bShow)
f38374d0 362 {
80d83cbc
DW
363 wxActivateEvent vEvent(wxEVT_ACTIVATE, TRUE, m_windowId);
364
365 ::WinSetWindowPos( (HWND) GetHWND()
366 ,HWND_TOP
367 ,0
368 ,0
369 ,0
370 ,0
371 ,SWP_ZORDER
372 );
373 vEvent.SetEventObject(this);
374 GetEventHandler()->ProcessEvent(vEvent);
f38374d0
DW
375 }
376 else
377 {
80d83cbc 378 //
f38374d0 379 // Try to highlight the correct window (the parent)
80d83cbc
DW
380 //
381 if (GetParent())
f38374d0 382 {
80d83cbc
DW
383 HWND hWndParent = GetHwndOf(GetParent());
384
f38374d0 385 if (hWndParent)
80d83cbc
DW
386 ::WinSetWindowPos( hWndParent
387 ,HWND_TOP
388 ,0
389 ,0
390 ,0
391 ,0
392 ,SWP_ZORDER
393 );
f38374d0
DW
394 }
395 }
f38374d0 396 return TRUE;
80d83cbc 397} // end of wxFrame::Show
f38374d0 398
80d83cbc
DW
399void wxFrame::Iconize(
400 bool bIconize
401)
f38374d0 402{
80d83cbc
DW
403 DoShowWindow(bIconize ? SWP_MINIMIZE : SWP_RESTORE);
404} // end of wxFrame::Iconize
0e320a79 405
80d83cbc
DW
406void wxFrame::Maximize(
407 bool bMaximize)
0e320a79 408{
80d83cbc
DW
409 DoShowWindow(bMaximize ? SWP_MAXIMIZE : SWP_RESTORE);
410} // end of wxFrame::Maximize
f38374d0
DW
411
412void wxFrame::Restore()
413{
80d83cbc
DW
414 DoShowWindow(SWP_RESTORE);
415} // end of wxFrame::Restore
0e320a79
DW
416
417bool wxFrame::IsIconized() const
418{
80d83cbc
DW
419 SWP vSwp;
420 bool bIconic;
421
422 ::WinQueryWindowPos(GetHwnd(), &vSwp)
423
424 if (vSwp.fl & SWP_MINIMIZE)
425 ((wxFrame*)this)->m_bIconized = TRUE;
426 else
427 ((wxFrame*)this)->m_bIconized = FALSE;
428 return m_bIconized;
429} // end of wxFrame::IsIconized
0e320a79 430
21802234
DW
431// Is it maximized?
432bool wxFrame::IsMaximized() const
0e320a79 433{
80d83cbc
DW
434 SWP vSwp;
435 bool bIconic;
436
437 ::WinQueryWindowPos(GetHwnd(), &vSwp)
438 return (vSwp.fl & SWP_MAXIMIZE);
439} // end of wxFrame::IsMaximized
0e320a79
DW
440
441void wxFrame::SetIcon(const wxIcon& icon)
442{
f38374d0
DW
443 wxFrameBase::SetIcon(icon);
444
29435d81
DW
445// TODO:
446/*
f38374d0
DW
447 if ( m_icon.Ok() )
448 {
449 SendMessage(GetHwnd(), WM_SETICON,
450 (WPARAM)TRUE, (LPARAM)(HICON) m_icon.GetHICON());
451 }
29435d81 452*/
0e320a79
DW
453}
454
21802234 455#if wxUSE_STATUSBAR
f38374d0
DW
456wxStatusBar *wxFrame::OnCreateStatusBar(int number,
457 long style,
458 wxWindowID id,
459 const wxString& name)
0e320a79
DW
460{
461 wxStatusBar *statusBar = NULL;
0e320a79 462
f38374d0 463 statusBar = wxFrameBase::OnCreateStatusBar(number, style, id, name);
0e320a79 464
f38374d0 465 return statusBar;
0e320a79
DW
466}
467
468void wxFrame::PositionStatusBar()
469{
f38374d0
DW
470// TODO:
471/*
472 // native status bar positions itself
473 if ( m_frameStatusBar )
474 {
475 int w, h;
476 GetClientSize(&w, &h);
477 int sw, sh;
478 m_frameStatusBar->GetSize(&sw, &sh);
479
480 // Since we wish the status bar to be directly under the client area,
481 // we use the adjusted sizes without using wxSIZE_NO_ADJUSTMENTS.
482 m_frameStatusBar->SetSize(0, h, w, sh);
483 }
484*/
0e320a79 485}
21802234 486#endif // wxUSE_STATUSBAR
0e320a79 487
21802234 488void wxFrame::DetachMenuBar()
0e320a79 489{
21802234 490 if (m_frameMenuBar)
0e320a79 491 {
29435d81 492 m_frameMenuBar->Detach();
0e320a79 493 m_frameMenuBar = NULL;
21802234
DW
494 }
495}
496
497void wxFrame::SetMenuBar(wxMenuBar *menu_bar)
498{
499 if (!menu_bar)
500 {
501 DetachMenuBar();
0e320a79
DW
502 return;
503 }
c3d43472 504
29435d81 505 wxCHECK_RET( !menu_bar->GetFrame(), wxT("this menubar is already attached") );
0e320a79 506
21802234
DW
507 if (m_frameMenuBar)
508 delete m_frameMenuBar;
509
29435d81 510 m_hMenu = menu_bar->Create();
21802234
DW
511
512 if ( !m_hMenu )
513 return;
514
515 InternalSetMenuBar();
516
517 m_frameMenuBar = menu_bar;
29435d81 518 menu_bar->Attach(this);
0e320a79
DW
519}
520
21802234 521void wxFrame::InternalSetMenuBar()
0e320a79 522{
21802234 523// TODO:
29435d81
DW
524/*
525 if ( !::SetMenu(GetHwnd(), (HMENU)m_hMenu) )
0e320a79 526 {
21802234 527 wxLogLastError("SetMenu");
0e320a79 528 }
21802234 529*/
0e320a79
DW
530}
531
532// Responds to colour changes, and passes event on to children.
533void wxFrame::OnSysColourChanged(wxSysColourChangedEvent& event)
534{
f38374d0
DW
535// TODO:
536/*
0e320a79
DW
537 SetBackgroundColour(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_APPWORKSPACE));
538 Refresh();
539
540 if ( m_frameStatusBar )
541 {
542 wxSysColourChangedEvent event2;
543 event2.SetEventObject( m_frameStatusBar );
21802234 544 m_frameStatusBar->GetEventHandler()->ProcessEvent(event2);
0e320a79
DW
545 }
546
547 // Propagate the event to the non-top-level children
548 wxWindow::OnSysColourChanged(event);
f38374d0 549*/
0e320a79
DW
550}
551
21802234
DW
552/*
553 * Frame window
554 *
555 */
556
557bool wxFrame::OS2Create(int id, wxWindow *parent, const wxChar *wclass, wxWindow *wx_win, const wxChar *title,
558 int x, int y, int width, int height, long style)
559
560{
80d83cbc 561 m_hDefaultIcon = (WXHICON) (wxSTD_FRAME_ICON ? wxSTD_FRAME_ICON : wxDEFAULT_FRAME_ICON);
21802234
DW
562
563 // If child windows aren't properly drawn initially, WS_CLIPCHILDREN
564 // could be the culprit. But without it, you can get a lot of flicker.
29435d81 565
21802234
DW
566// TODO:
567/*
568 DWORD msflags = 0;
569 if ((style & wxCAPTION) == wxCAPTION)
570 msflags = WS_OVERLAPPED;
571 else
572 msflags = WS_POPUP;
573
574 if (style & wxMINIMIZE_BOX)
575 msflags |= WS_MINIMIZEBOX;
576 if (style & wxMAXIMIZE_BOX)
577 msflags |= WS_MAXIMIZEBOX;
578 if (style & wxTHICK_FRAME)
579 msflags |= WS_THICKFRAME;
580 if (style & wxSYSTEM_MENU)
581 msflags |= WS_SYSMENU;
582 if ((style & wxMINIMIZE) || (style & wxICONIZE))
583 msflags |= WS_MINIMIZE;
584 if (style & wxMAXIMIZE)
585 msflags |= WS_MAXIMIZE;
586 if (style & wxCAPTION)
587 msflags |= WS_CAPTION;
588 if (style & wxCLIP_CHILDREN)
589 msflags |= WS_CLIPCHILDREN;
590
591 // Keep this in wxFrame because it saves recoding this function
592 // in wxTinyFrame
593#if wxUSE_ITSY_BITSY
594 if (style & wxTINY_CAPTION_VERT)
595 msflags |= IBS_VERTCAPTION;
596 if (style & wxTINY_CAPTION_HORIZ)
597 msflags |= IBS_HORZCAPTION;
598#else
599 if (style & wxTINY_CAPTION_VERT)
600 msflags |= WS_CAPTION;
601 if (style & wxTINY_CAPTION_HORIZ)
602 msflags |= WS_CAPTION;
603#endif
604 if ((style & wxTHICK_FRAME) == 0)
605 msflags |= WS_BORDER;
606
607 WXDWORD extendedStyle = MakeExtendedStyle(style);
608
609#if !defined(__WIN16__) && !defined(__SC__)
610 if (style & wxFRAME_TOOL_WINDOW)
611 extendedStyle |= WS_EX_TOOLWINDOW;
612#endif
613
614 if (style & wxSTAY_ON_TOP)
615 extendedStyle |= WS_EX_TOPMOST;
616
617 m_iconized = FALSE;
29435d81 618 if ( !wxWindow::MSWCreate(id, parent, wclass, wx_win, title, x, y, width, height,
21802234
DW
619 msflags, NULL, extendedStyle) )
620 return FALSE;
621
622 // Seems to be necessary if we use WS_POPUP
623 // style instead of WS_OVERLAPPED
624 if (width > -1 && height > -1)
625 ::PostMessage(GetHwnd(), WM_SIZE, SIZE_RESTORED, MAKELPARAM(width, height));
29435d81 626*/
f38374d0 627 return TRUE;
0e320a79
DW
628}
629
630// Default activation behaviour - set the focus for the first child
631// subwindow found.
632void wxFrame::OnActivate(wxActivateEvent& event)
633{
21802234
DW
634 for ( wxWindowList::Node *node = GetChildren().GetFirst();
635 node;
636 node = node->GetNext() )
0e320a79 637 {
21802234
DW
638 // FIXME all this is totally bogus - we need to do the same as wxPanel,
639 // but how to do it without duplicating the code?
640
641 // restore focus
642 wxWindow *child = node->GetData();
643
644 if ( !child->IsTopLevel()
645#if wxUSE_TOOLBAR
646 && !wxDynamicCast(child, wxToolBar)
647#endif // wxUSE_TOOLBAR
648#if wxUSE_STATUSBAR
649 && !wxDynamicCast(child, wxStatusBar)
650#endif // wxUSE_STATUSBAR
651 )
652 {
653 child->SetFocus();
654 return;
655 }
0e320a79 656 }
0e320a79
DW
657}
658
f38374d0
DW
659// ----------------------------------------------------------------------------
660// wxFrame size management: we exclude the areas taken by menu/status/toolbars
661// from the client area, so the client area is what's really available for the
662// frame contents
663// ----------------------------------------------------------------------------
0e320a79
DW
664
665// Checks if there is a toolbar, and returns the first free client position
666wxPoint wxFrame::GetClientAreaOrigin() const
667{
668 wxPoint pt(0, 0);
669 if (GetToolBar())
670 {
671 int w, h;
672 GetToolBar()->GetSize(& w, & h);
673
674 if (GetToolBar()->GetWindowStyleFlag() & wxTB_VERTICAL)
675 {
676 pt.x += w;
677 }
678 else
679 {
680 pt.y += h;
681 }
682 }
683 return pt;
684}
685
e6ebb514 686void wxFrame::DoScreenToClient(int *x, int *y) const
0e320a79 687{
29435d81 688 wxWindow::DoScreenToClient(x, y);
0e320a79
DW
689
690 // We may be faking the client origin.
691 // So a window that's really at (0, 30) may appear
692 // (to wxWin apps) to be at (0, 0).
693 wxPoint pt(GetClientAreaOrigin());
694 *x -= pt.x;
695 *y -= pt.y;
696}
697
e6ebb514 698void wxFrame::DoClientToScreen(int *x, int *y) const
0e320a79
DW
699{
700 // We may be faking the client origin.
701 // So a window that's really at (0, 30) may appear
702 // (to wxWin apps) to be at (0, 0).
703 wxPoint pt1(GetClientAreaOrigin());
704 *x += pt1.x;
705 *y += pt1.y;
706
e6ebb514 707 wxWindow::DoClientToScreen(x, y);
0e320a79
DW
708}
709
f38374d0
DW
710// ----------------------------------------------------------------------------
711// tool/status bar stuff
712// ----------------------------------------------------------------------------
713
21802234 714#if wxUSE_TOOLBAR
f38374d0 715
0e320a79
DW
716wxToolBar* wxFrame::CreateToolBar(long style, wxWindowID id, const wxString& name)
717{
f38374d0 718 if ( wxFrameBase::CreateToolBar(style, id, name) )
0e320a79 719 {
0e320a79 720 PositionToolBar();
0e320a79 721 }
0e320a79 722
f38374d0 723 return m_frameToolBar;
0e320a79
DW
724}
725
726void wxFrame::PositionToolBar()
727{
29435d81
DW
728// TODO:
729/*
21802234 730 RECT rect;
29435d81 731 ::GetClientRect(GetHwnd(), &rect);
0e320a79 732
f38374d0 733#if wxUSE_STATUSBAR
0e320a79
DW
734 if ( GetStatusBar() )
735 {
f38374d0
DW
736 int statusX, statusY;
737 GetStatusBar()->GetClientSize(&statusX, &statusY);
738 rect.bottom -= statusY;
0e320a79 739 }
f38374d0 740#endif // wxUSE_STATUSBAR
0e320a79 741
f38374d0 742 if ( GetToolBar() )
0e320a79
DW
743 {
744 int tw, th;
f38374d0 745 GetToolBar()->GetSize(&tw, &th);
0e320a79 746
f38374d0 747 if ( GetToolBar()->GetWindowStyleFlag() & wxTB_VERTICAL )
0e320a79 748 {
f38374d0 749 th = rect.bottom;
0e320a79
DW
750 }
751 else
752 {
f38374d0 753 tw = rect.right;
21802234 754 }
f38374d0
DW
755
756 // Use the 'real' MSW position here
757 GetToolBar()->SetSize(0, 0, tw, th, wxSIZE_NO_ADJUSTMENTS);
21802234 758 }
29435d81 759*/
21802234
DW
760}
761#endif // wxUSE_TOOLBAR
762
f38374d0
DW
763// ----------------------------------------------------------------------------
764// frame state (iconized/maximized/...)
765// ----------------------------------------------------------------------------
766
21802234
DW
767// propagate our state change to all child frames: this allows us to emulate X
768// Windows behaviour where child frames float independently of the parent one
769// on the desktop, but are iconized/restored with it
770void wxFrame::IconizeChildFrames(bool bIconize)
771{
772 for ( wxWindowList::Node *node = GetChildren().GetFirst();
773 node;
774 node = node->GetNext() )
775 {
776 wxWindow *win = node->GetData();
777
778 if ( win->IsKindOf(CLASSINFO(wxFrame)) )
779 {
780 ((wxFrame *)win)->Iconize(bIconize);
0e320a79
DW
781 }
782 }
783}
784
21802234
DW
785// ===========================================================================
786// message processing
787// ===========================================================================
788
789// ---------------------------------------------------------------------------
790// preprocessing
791// ---------------------------------------------------------------------------
792
793bool wxFrame::OS2TranslateMessage(WXMSG* pMsg)
794{
f38374d0
DW
795// TODO:
796/*
29435d81
DW
797 if ( wxWindow::OS2TranslateMessage(pMsg) )
798 return TRUE;
f38374d0 799*/
21802234
DW
800 // try the menu bar accels
801 wxMenuBar *menuBar = GetMenuBar();
802 if ( !menuBar )
803 return FALSE;
804
29435d81
DW
805 const wxAcceleratorTable& acceleratorTable = menuBar->GetAccelTable();
806 return acceleratorTable.Translate(this, pMsg);
21802234
DW
807}
808
809// ---------------------------------------------------------------------------
810// our private (non virtual) message handlers
811// ---------------------------------------------------------------------------
812
813bool wxFrame::HandlePaint()
814{
21802234 815// TODO:
29435d81
DW
816/*
817 RECT rect;
818 if ( GetUpdateRect(GetHwnd(), &rect, FALSE) )
819 {
820 if ( m_iconized )
821 {
822 HICON hIcon = m_icon.Ok() ? GetHiconOf(m_icon)
823 : (HICON)m_defaultIcon;
824
21802234
DW
825 // Hold a pointer to the dc so long as the OnPaint() message
826 // is being processed
29435d81
DW
827 PAINTSTRUCT ps;
828 HDC hdc = ::BeginPaint(GetHwnd(), &ps);
829
830 // Erase background before painting or we get white background
831 MSWDefWindowProc(WM_ICONERASEBKGND, (WORD)(LONG)ps.hdc, 0L);
832
833 if ( hIcon )
834 {
835 RECT rect;
836 ::GetClientRect(GetHwnd(), &rect);
21802234
DW
837
838 // FIXME: why hardcoded?
29435d81
DW
839 static const int icon_width = 32;
840 static const int icon_height = 32;
841
842 int icon_x = (int)((rect.right - icon_width)/2);
843 int icon_y = (int)((rect.bottom - icon_height)/2);
844
845 ::DrawIcon(hdc, icon_x, icon_y, hIcon);
846 }
847
848 ::EndPaint(GetHwnd(), &ps);
849
850 return TRUE;
851 }
852 else
853 {
854 return wxWindow::HandlePaint();
855 }
856 }
857 else
858 {
859 // nothing to paint - processed
860 return TRUE;
861 }
862*/
863 return FALSE;
21802234
DW
864}
865
866bool wxFrame::HandleSize(int x, int y, WXUINT id)
867{
868 bool processed = FALSE;
869
29435d81
DW
870// TODO:
871/*
872 switch ( id )
21802234
DW
873 {
874 case SIZENORMAL:
875 // only do it it if we were iconized before, otherwise resizing the
876 // parent frame has a curious side effect of bringing it under it's
877 // children
878 if ( !m_iconized )
879 break;
880
881 // restore all child frames too
882 IconizeChildFrames(FALSE);
883
884 // fall through
885
886 case SIZEFULLSCREEN:
887 m_iconized = FALSE;
888 break;
889
890 case SIZEICONIC:
891 // iconize all child frames too
892 IconizeChildFrames(TRUE);
893
894 m_iconized = TRUE;
895 break;
896 }
f38374d0 897
21802234
DW
898 if ( !m_iconized )
899 {
29435d81 900 // forward WM_SIZE to status bar control
f38374d0
DW
901#if wxUSE_NATIVE_STATUSBAR
902 if (m_frameStatusBar && m_frameStatusBar->IsKindOf(CLASSINFO(wxStatusBar95)))
903 {
904 wxSizeEvent event(wxSize(x, y), m_frameStatusBar->GetId());
905 event.SetEventObject( m_frameStatusBar );
906
907 ((wxStatusBar95 *)m_frameStatusBar)->OnSize(event);
908 }
909#endif // wxUSE_NATIVE_STATUSBAR
910
21802234
DW
911 PositionStatusBar();
912 PositionToolBar();
913
914 wxSizeEvent event(wxSize(x, y), m_windowId);
915 event.SetEventObject( this );
916 processed = GetEventHandler()->ProcessEvent(event);
917 }
f38374d0 918*/
21802234
DW
919 return processed;
920}
921
922bool wxFrame::HandleCommand(WXWORD id, WXWORD cmd, WXHWND control)
923{
f38374d0
DW
924// TODO:
925/*
21802234
DW
926 if ( control )
927 {
928 // In case it's e.g. a toolbar.
929 wxWindow *win = wxFindWinFromHandle(control);
930 if ( win )
f38374d0 931 return win->MSWCommand(cmd, id);
21802234
DW
932 }
933
934 // handle here commands from menus and accelerators
935 if ( cmd == 0 || cmd == 1 )
936 {
937 if ( wxCurrentPopupMenu )
938 {
939 wxMenu *popupMenu = wxCurrentPopupMenu;
940 wxCurrentPopupMenu = NULL;
941
f38374d0 942 return popupMenu->MSWCommand(cmd, id);
21802234
DW
943 }
944
945 if ( ProcessCommand(id) )
946 {
947 return TRUE;
948 }
949 }
f38374d0 950*/
21802234
DW
951 return FALSE;
952}
953
954bool wxFrame::HandleMenuSelect(WXWORD nItem, WXWORD flags, WXHMENU hMenu)
955{
956 int item;
957 if ( flags == 0xFFFF && hMenu == 0 )
958 {
959 // menu was removed from screen
960 item = -1;
961 }
29435d81 962// TODO:
21802234
DW
963/*
964 else if ( !(flags & MF_POPUP) && !(flags & MF_SEPARATOR) )
965 {
966 item = nItem;
967 }
21802234
DW
968 else
969 {
970 // don't give hints for separators (doesn't make sense) nor for the
971 // items opening popup menus (they don't have them anyhow)
972 return FALSE;
973 }
f38374d0 974*/
21802234
DW
975 wxMenuEvent event(wxEVT_MENU_HIGHLIGHT, item);
976 event.SetEventObject( this );
977
978 return GetEventHandler()->ProcessEvent(event);
979}
980
981// ---------------------------------------------------------------------------
982// the window proc for wxFrame
983// ---------------------------------------------------------------------------
984
985MRESULT wxFrame::OS2WindowProc(HWND hwnd, WXUINT message, WXWPARAM wParam, WXLPARAM lParam)
986{
f38374d0 987 long rc = 0;
21802234
DW
988 bool processed = FALSE;
989
990// TODO:
991/*
992 switch ( message )
993 {
994 case WM_CLOSE:
995 // if we can't close, tell the system that we processed the
996 // message - otherwise it would close us
997 processed = !Close();
998 break;
999
1000 case WM_COMMAND:
1001 {
1002 WORD id, cmd;
1003 WXHWND hwnd;
1004 UnpackCommand((WXWPARAM)wParam, (WXLPARAM)lParam,
1005 &id, &hwnd, &cmd);
1006
1007 processed = HandleCommand(id, cmd, (WXHWND)hwnd);
1008 }
1009 break;
1010
1011 case WM_MENUSELECT:
1012 {
1013 WXWORD item, flags;
1014 WXHMENU hmenu;
1015 UnpackMenuSelect(wParam, lParam, &item, &flags, &hmenu);
1016
1017 processed = HandleMenuSelect(item, flags, hmenu);
1018 }
1019 break;
1020
1021 case WM_PAINT:
1022 processed = HandlePaint();
1023 break;
1024
1025 case WM_QUERYDRAGICON:
1026 {
1027 HICON hIcon = m_icon.Ok() ? GetHiconOf(m_icon)
1028 : (HICON)(m_defaultIcon);
1029 rc = (long)hIcon;
1030 processed = rc != 0;
1031 }
1032 break;
1033
1034 case WM_SIZE:
1035 processed = HandleSize(LOWORD(lParam), HIWORD(lParam), wParam);
1036 break;
1037 }
f38374d0 1038
21802234 1039 if ( !processed )
f38374d0 1040 rc = wxWindow::MSWWindowProc(message, wParam, lParam);
21802234
DW
1041
1042 return rc;
f38374d0
DW
1043*/
1044 return (MRESULT)0;
21802234
DW
1045}
1046