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