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