]> git.saurik.com Git - wxWidgets.git/blame - src/os2/mdi.cpp
changed wxImage::ComputeHistogram to use wxHashMap
[wxWidgets.git] / src / os2 / mdi.cpp
CommitLineData
0e320a79
DW
1/////////////////////////////////////////////////////////////////////////////
2// Name: mdi.cpp
3// Purpose: MDI classes
75f11ad7 4// Author: David Webster
0e320a79 5// Modified by:
75f11ad7 6// Created: 10/10/99
0e320a79 7// RCS-ID: $Id$
75f11ad7
DW
8// Copyright: (c) David Webster
9// Licence: wxWindows licence
0e320a79
DW
10/////////////////////////////////////////////////////////////////////////////
11
75f11ad7
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/statusbr.h"
23 #include "wx/settings.h"
24 #include "wx/intl.h"
25 #include "wx/log.h"
0e320a79
DW
26#endif
27
28#include "wx/mdi.h"
75f11ad7
DW
29#include "wx/os2/private.h"
30
31#include <string.h>
32
33// ---------------------------------------------------------------------------
34// global variables
35// ---------------------------------------------------------------------------
36
37extern wxWindowList wxModelessWindows; // from dialog.cpp
38extern wxMenu *wxCurrentPopupMenu;
39
75f11ad7
DW
40extern wxWindow *wxWndHook; // from window.cpp
41
42extern void wxAssociateWinWithHandle(HWND hWnd, wxWindow *win);
43
44static HWND invalidHandle = 0;
45
46// ---------------------------------------------------------------------------
47// constants
48// ---------------------------------------------------------------------------
49
50static const int IDM_WINDOWTILE = 4001;
51static const int IDM_WINDOWTILEHOR = 4001;
52static const int IDM_WINDOWCASCADE = 4002;
53static const int IDM_WINDOWICONS = 4003;
54static const int IDM_WINDOWNEXT = 4004;
55static const int IDM_WINDOWTILEVERT = 4005;
56
57// This range gives a maximum of 500 MDI children. Should be enough :-)
58static const int wxFIRST_MDI_CHILD = 4100;
59static const int wxLAST_MDI_CHILD = 4600;
0e320a79 60
75f11ad7
DW
61// Status border dimensions
62static const int wxTHICK_LINE_BORDER = 3;
63static const int wxTHICK_LINE_WIDTH = 1;
64
65// ---------------------------------------------------------------------------
66// private functions
67// ---------------------------------------------------------------------------
68
69// set the MDI menus (by sending the WM_MDISETMENU message) and update the menu
70// of the parent of win (which is supposed to be the MDI client window)
71static void MDISetMenu(wxWindow *win, HMENU hmenuFrame, HMENU hmenuWindow);
72
73// insert the window menu (subMenu) into menu just before "Help" submenu or at
74// the very end if not found
75static void InsertWindowMenu(wxWindow *win, WXHMENU menu, HMENU subMenu);
76
77// is this an id of an MDI child?
78inline bool IsMdiCommandId(int id)
79{
80 return (id >= wxFIRST_MDI_CHILD) && (id <= wxLAST_MDI_CHILD);
81}
82
1b086de1 83// unpack the parameters of WM_MDIACTIVATE message
75f11ad7
DW
84static void UnpackMDIActivate(WXWPARAM wParam, WXLPARAM lParam,
85 WXWORD *activate, WXHWND *hwndAct, WXHWND *hwndDeact);
86
1b086de1
DW
87// return the HMENU of the MDI menu
88static inline HMENU GetMDIWindowMenu(wxMDIParentFrame *frame)
89{
90 wxMenu *menu = frame->GetWindowMenu();
91 return menu ? GetHmenuOf(menu) : 0;
92}
93
75f11ad7
DW
94// ===========================================================================
95// implementation
96// ===========================================================================
97
98// ---------------------------------------------------------------------------
99// wxWin macros
100// ---------------------------------------------------------------------------
0e320a79 101
75f11ad7
DW
102 IMPLEMENT_DYNAMIC_CLASS(wxMDIParentFrame, wxFrame)
103 IMPLEMENT_DYNAMIC_CLASS(wxMDIChildFrame, wxFrame)
104 IMPLEMENT_DYNAMIC_CLASS(wxMDIClientWindow, wxWindow)
0e320a79
DW
105
106BEGIN_EVENT_TABLE(wxMDIParentFrame, wxFrame)
75f11ad7
DW
107 EVT_SIZE(wxMDIParentFrame::OnSize)
108 EVT_SYS_COLOUR_CHANGED(wxMDIParentFrame::OnSysColourChanged)
0e320a79
DW
109END_EVENT_TABLE()
110
111BEGIN_EVENT_TABLE(wxMDIClientWindow, wxWindow)
75f11ad7 112 EVT_SCROLL(wxMDIClientWindow::OnScroll)
0e320a79
DW
113END_EVENT_TABLE()
114
75f11ad7
DW
115// ===========================================================================
116// wxMDIParentFrame: the frame which contains the client window which manages
117// the children
118// ===========================================================================
0e320a79
DW
119
120wxMDIParentFrame::wxMDIParentFrame()
121{
75f11ad7
DW
122 m_clientWindow = NULL;
123 m_currentChild = NULL;
124 m_windowMenu = 0;
125 m_parentFrameActive = TRUE;
0e320a79
DW
126}
127
128bool wxMDIParentFrame::Create(wxWindow *parent,
75f11ad7
DW
129 wxWindowID id,
130 const wxString& title,
131 const wxPoint& pos,
132 const wxSize& size,
133 long style,
134 const wxString& name)
0e320a79 135{
80d83cbc 136 m_hDefaultIcon = (WXHICON) (wxSTD_MDIPARENTFRAME_ICON ? wxSTD_MDIPARENTFRAME_ICON : wxDEFAULT_MDIPARENTFRAME_ICON);
0e320a79 137
75f11ad7
DW
138 m_clientWindow = NULL;
139 m_currentChild = NULL;
140 m_windowMenu = 0;
141 m_parentFrameActive = TRUE;
0e320a79 142
75f11ad7
DW
143 if (!parent)
144 wxTopLevelWindows.Append(this);
0e320a79 145
75f11ad7 146 SetName(name);
2004cad1 147 wxWindowBase::Show(TRUE); // MDI child frame starts off shown
75f11ad7 148 m_windowStyle = style;
0e320a79 149
75f11ad7 150 if (parent) parent->AddChild(this);
0e320a79 151
75f11ad7
DW
152 if ( id > -1 )
153 m_windowId = id;
154 else
155 m_windowId = (int)NewControlId();
0e320a79 156
75f11ad7
DW
157 int x = pos.x;
158 int y = pos.y;
159 int width = size.x;
160 int height = size.y;
161
162// TODO: m_windowMenu = (WXHMENU) ::LoadMenu(wxGetInstance(), wxT("wxWindowMenu"));
163/*
164 DWORD msflags = WS_OVERLAPPED;
165 if (style & wxMINIMIZE_BOX)
166 msflags |= WS_MINIMIZEBOX;
167 if (style & wxMAXIMIZE_BOX)
168 msflags |= WS_MAXIMIZEBOX;
169 if (style & wxTHICK_FRAME)
170 msflags |= WS_THICKFRAME;
171 if (style & wxSYSTEM_MENU)
172 msflags |= WS_SYSMENU;
173 if ((style & wxMINIMIZE) || (style & wxICONIZE))
174 msflags |= WS_MINIMIZE;
175 if (style & wxMAXIMIZE)
176 msflags |= WS_MAXIMIZE;
177 if (style & wxCAPTION)
178 msflags |= WS_CAPTION;
179
180 if (style & wxCLIP_CHILDREN)
181 msflags |= WS_CLIPCHILDREN;
182
183 wxWindow::MSWCreate(m_windowId, parent, wxMDIFrameClassName, this, title, x, y, width, height,
184 msflags);
185*/
186 wxModelessWindows.Append(this);
187
188 return TRUE;
0e320a79
DW
189}
190
191wxMDIParentFrame::~wxMDIParentFrame()
192{
75f11ad7 193 DestroyChildren();
0e320a79 194
75f11ad7
DW
195// TODO: ::DestroyMenu((HMENU)m_windowMenu);
196 m_windowMenu = 0;
0e320a79 197
75f11ad7 198 if ( m_clientWindow )
0e320a79 199 {
75f11ad7
DW
200 if ( m_clientWindow->OS2GetOldWndProc() )
201 m_clientWindow->UnsubclassWin();
0e320a79 202
75f11ad7
DW
203 m_clientWindow->SetHWND(0);
204 delete m_clientWindow;
205 }
0e320a79
DW
206}
207
75f11ad7 208void wxMDIParentFrame::InternalSetMenuBar()
0e320a79 209{
75f11ad7
DW
210 // TODO:
211/*
212 HMENU subMenu = GetSubMenu((HMENU) m_windowMenu, 0);
0e320a79 213
75f11ad7
DW
214 m_parentFrameActive = TRUE;
215
216 InsertWindowMenu(GetClientWindow(), m_hMenu, subMenu);
217*/
0e320a79
DW
218}
219
75f11ad7 220void wxMDIParentFrame::OnSize(wxSizeEvent& event)
0e320a79 221{
75f11ad7
DW
222 // TODO:
223/*
224 if ( GetClientWindow() )
225 {
226 int width, height;
227 GetClientSize(&width, &height);
228
229 GetClientWindow()->SetSize(0, 0, width, height);
230 }
231*/
0e320a79
DW
232}
233
234// Returns the active MDI child window
235wxMDIChildFrame *wxMDIParentFrame::GetActiveChild() const
236{
75f11ad7
DW
237 HWND hWnd = 0; // TODO: (HWND)::SendMessage(GetWinHwnd(GetClientWindow()),
238// WM_MDIGETACTIVE, 0, 0L);
239 if ( hWnd == 0 )
240 return NULL;
241 else
242 return (wxMDIChildFrame *)wxFindWinFromHandle((WXHWND) hWnd);
0e320a79
DW
243}
244
75f11ad7
DW
245// Create the client window class (don't Create the window, just return a new
246// class)
0e320a79
DW
247wxMDIClientWindow *wxMDIParentFrame::OnCreateClient()
248{
75f11ad7 249 return new wxMDIClientWindow;
0e320a79
DW
250}
251
252// Responds to colour changes, and passes event on to children.
253void wxMDIParentFrame::OnSysColourChanged(wxSysColourChangedEvent& event)
254{
75f11ad7
DW
255 if ( m_clientWindow )
256 {
a756f210 257 m_clientWindow->SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_APPWORKSPACE));
75f11ad7
DW
258 m_clientWindow->Refresh();
259 }
0e320a79 260
75f11ad7 261 event.Skip();
0e320a79
DW
262}
263
75f11ad7 264// ---------------------------------------------------------------------------
0e320a79 265// MDI operations
75f11ad7
DW
266// ---------------------------------------------------------------------------
267
0e320a79
DW
268void wxMDIParentFrame::Cascade()
269{
75f11ad7 270// TODO: ::SendMessage(GetWinHwnd(GetClientWindow()), WM_MDICASCADE, 0, 0);
0e320a79
DW
271}
272
75f11ad7 273// TODO: add a direction argument (hor/vert)
0e320a79
DW
274void wxMDIParentFrame::Tile()
275{
75f11ad7 276// TODO: ::SendMessage(GetWinHwnd(GetClientWindow()), WM_MDITILE, MDITILE_HORIZONTAL, 0);
0e320a79
DW
277}
278
279void wxMDIParentFrame::ArrangeIcons()
280{
75f11ad7 281// TODO: ::SendMessage(GetWinHwnd(GetClientWindow()), WM_MDIICONARRANGE, 0, 0);
0e320a79
DW
282}
283
284void wxMDIParentFrame::ActivateNext()
285{
75f11ad7 286// TODO: ::SendMessage(GetWinHwnd(GetClientWindow()), WM_MDINEXT, 0, 0);
0e320a79
DW
287}
288
289void wxMDIParentFrame::ActivatePrevious()
290{
75f11ad7 291// TODO: ::SendMessage(GetWinHwnd(GetClientWindow()), WM_MDINEXT, 0, 1);
0e320a79
DW
292}
293
75f11ad7
DW
294// ---------------------------------------------------------------------------
295// the MDI parent frame window proc
296// ---------------------------------------------------------------------------
0e320a79 297
a885d89a 298MRESULT wxMDIParentFrame::OS2WindowProc(WXUINT message,
75f11ad7
DW
299 WXWPARAM wParam,
300 WXLPARAM lParam)
0e320a79 301{
75f11ad7
DW
302 MRESULT rc = 0;
303 bool processed = FALSE;
304
305 // TODO:
306/*
307 switch ( message )
308 {
309 case WM_ACTIVATE:
310 {
311 WXWORD state, minimized;
312 WXHWND hwnd;
313 UnpackActivate(wParam, lParam, &state, &minimized, &hwnd);
314
315 processed = HandleActivate(state, minimized != 0, hwnd);
316 }
317 break;
318
319 case WM_COMMAND:
320 {
321 WXWORD id, cmd;
322 WXHWND hwnd;
323 UnpackCommand(wParam, lParam, &id, &hwnd, &cmd);
324
325 (void)HandleCommand(id, cmd, hwnd);
326
327 // even if the frame didn't process it, there is no need to try it
328 // once again (i.e. call wxFrame::HandleCommand()) - we just dud it,
329 // so pretend we processed the message anyhow
330 processed = TRUE;
331 }
332
333 // always pass this message DefFrameProc(), otherwise MDI menu
334 // commands (and sys commands - more surprizingly!) won't work
335 MSWDefWindowProc(message, wParam, lParam);
336 break;
337
338 case WM_CREATE:
339 m_clientWindow = OnCreateClient();
340 // Uses own style for client style
341 if ( !m_clientWindow->CreateClient(this, GetWindowStyleFlag()) )
342 {
343 wxLogMessage(_("Failed to create MDI parent frame."));
344
345 rc = -1;
346 }
347
348 processed = TRUE;
349 break;
350
351 case WM_ERASEBKGND:
352 processed = TRUE;
353
354 // we erase background ourselves
355 rc = TRUE;
356 break;
357
358 case WM_MENUSELECT:
359 {
360 WXWORD item, flags;
361 WXHMENU hmenu;
362 UnpackMenuSelect(wParam, lParam, &item, &flags, &hmenu);
363
364 if ( m_parentFrameActive )
365 {
366 processed = HandleMenuSelect(item, flags, hmenu);
367 }
368 else if (m_currentChild)
369 {
370 processed = m_currentChild->
371 HandleMenuSelect(item, flags, hmenu);
372 }
373 }
374 break;
375
376 case WM_SIZE:
377 // as we don't (usually) resize the MDI client to exactly fit the
378 // client area (we put it below the toolbar, above statusbar &c),
379 // we should not pass this one to DefFrameProc
380 break;
381 }
382*/
383 if ( !processed )
80d83cbc 384 rc = wxFrame::OS2WindowProc(message, wParam, lParam);
75f11ad7
DW
385
386 return rc;
0e320a79
DW
387}
388
75f11ad7 389bool wxMDIParentFrame::HandleActivate(int state, bool minimized, WXHWND activate)
0e320a79 390{
75f11ad7 391 bool processed = FALSE;
0e320a79 392
75f11ad7
DW
393 // TODO:
394/*
395 if ( wxWindow::HandleActivate(state, minimized, activate) )
396 {
397 // already processed
398 processed = TRUE;
399 }
400
401 // If this window is an MDI parent, we must also send an OnActivate message
402 // to the current child.
403 if ( (m_currentChild != NULL) &&
404 ((state == WA_ACTIVE) || (state == WA_CLICKACTIVE)) )
405 {
406 wxActivateEvent event(wxEVT_ACTIVATE, TRUE, m_currentChild->GetId());
407 event.SetEventObject( m_currentChild );
408 if ( m_currentChild->GetEventHandler()->ProcessEvent(event) )
409 processed = TRUE;
410 }
411*/
412 return processed;
413}
414
415bool wxMDIParentFrame::HandleCommand(WXWORD id, WXWORD cmd, WXHWND hwnd)
416{
417 // In case it's e.g. a toolbar.
418 if ( hwnd )
419 {
420 wxWindow *win = wxFindWinFromHandle(hwnd);
421 if ( win )
422 return FALSE; // Need to get wxWindow for OS/2 up to date: win->OS2Command(cmd, id);
423 }
424
425 // is it one of standard MDI commands?
426 WXWPARAM wParam = 0;
9dea36ef 427 int msg = 0;
75f11ad7
DW
428
429 // TODO:
430/*
431 switch ( id )
432 {
433 case IDM_WINDOWCASCADE:
434 msg = WM_MDICASCADE;
435 wParam = MDITILE_SKIPDISABLED;
436 break;
437
438 case IDM_WINDOWTILEHOR:
439 wParam |= MDITILE_HORIZONTAL;
440 // fall through
441
442 case IDM_WINDOWTILEVERT:
443 if ( !wParam )
444 wParam = MDITILE_VERTICAL;
445 msg = WM_MDITILE;
446 wParam |= MDITILE_SKIPDISABLED;
447 break;
448
449 case IDM_WINDOWICONS:
450 msg = WM_MDIICONARRANGE;
451 break;
452
453 case IDM_WINDOWNEXT:
454 msg = WM_MDINEXT;
455 break;
456
457 default:
458 msg = 0;
459 }
460*/
461 if ( msg )
462 {
463// TODO: ::SendMessage(GetWinHwnd(GetClientWindow()), msg, wParam, 0);
464
465 return TRUE;
466 }
467
468 // FIXME VZ: what does this test do??
469 if (id >= 0xF000)
470 {
471 return FALSE; // Get WndProc to call default proc
472 }
473
474 if ( IsMdiCommandId(id) )
475 {
476 wxWindowList::Node* node = GetChildren().GetFirst();
477 while ( node )
478 {
479 wxWindow* child = node->GetData();
480 if ( child->GetHWND() )
481 {
482 long childId = wxGetWindowId(child->GetHWND());
483 if (childId == (long)id)
484 {
485// TODO: ::SendMessage( GetWinHwnd(GetClientWindow()),
486// WM_MDIACTIVATE,
487// (WPARAM)child->GetHWND(), 0);
488 return TRUE;
489 }
490 }
491 node = node->GetNext();
492 }
493 }
494 else if ( m_parentFrameActive )
495 {
496 return ProcessCommand(id);
497 }
498 else if ( m_currentChild )
499 {
500 return m_currentChild->HandleCommand(id, cmd, hwnd);
501 }
502 else
503 {
504 // this shouldn't happen because it means that our messages are being
505 // lost (they're not sent to the parent frame nor to the children)
506 wxFAIL_MSG(wxT("MDI parent frame is not active, "
507 "yet there is no active MDI child?"));
508 }
509
510 return FALSE;
511}
512
a885d89a 513MRESULT wxMDIParentFrame::OS2DefWindowProc(WXUINT message,
75f11ad7
DW
514 WXWPARAM wParam,
515 WXLPARAM lParam)
516{
517 WXHWND clientWnd;
518 if ( GetClientWindow() )
519 clientWnd = GetClientWindow()->GetHWND();
0e320a79 520 else
75f11ad7
DW
521 clientWnd = 0;
522
523// TODO: return DefFrameProc(GetHwnd(), (HWND)clientWnd, message, wParam, lParam);
524 return((MRESULT)0);
525}
0e320a79 526
75f11ad7
DW
527bool wxMDIParentFrame::OS2TranslateMessage(WXMSG* msg)
528{
529 // TODO:
530/*
531 if ( m_currentChild && m_currentChild->GetHWND() &&
532 m_currentChild->OS2TranslateMessage(msg) )
533 {
534 return TRUE;
535 }
0e320a79 536
75f11ad7
DW
537 if ( m_acceleratorTable.Translate(this, msg) )
538 {
539 return TRUE;
540 }
0e320a79 541
75f11ad7
DW
542 if ( pMsg->message == WM_KEYDOWN || pMsg->message == WM_SYSKEYDOWN )
543 {
544 if ( ::TranslateMDISysAccel(GetWinHwnd(GetClientWindow()), pMsg))
545 return TRUE;
546 }
547*/
0e320a79
DW
548 return FALSE;
549}
550
75f11ad7
DW
551// ===========================================================================
552// wxMDIChildFrame
553// ===========================================================================
554
555wxMDIChildFrame::wxMDIChildFrame()
556{
557}
558
559bool wxMDIChildFrame::Create(wxMDIParentFrame *parent,
560 wxWindowID id,
561 const wxString& title,
562 const wxPoint& pos,
563 const wxSize& size,
564 long style,
565 const wxString& name)
566{
80d83cbc
DW
567 m_hDefaultIcon = (WXHICON)(wxSTD_MDICHILDFRAME_ICON ? wxSTD_MDICHILDFRAME_ICON
568 : wxDEFAULT_MDICHILDFRAME_ICON);
75f11ad7
DW
569
570 SetName(name);
571
572 if ( id > -1 )
573 m_windowId = id;
574 else
575 m_windowId = (int)NewControlId();
576
577 if ( parent )
578 {
579 parent->AddChild(this);
580 }
581
582 wxWndHook = this;
583
584 int x = pos.x;
585 int y = pos.y;
586 int width = size.x;
587 int height = size.y;
588
589 // TODO:
590/*
591 MDICREATESTRUCT mcs;
592
593 mcs.szClass = wxMDIChildFrameClassName;
594 mcs.szTitle = title;
595 mcs.hOwner = wxGetInstance();
596 if (x > -1)
597 mcs.x = x;
598 else
599 mcs.x = CW_USEDEFAULT;
600
601 if (y > -1)
602 mcs.y = y;
603 else
604 mcs.y = CW_USEDEFAULT;
605
606 if (width > -1)
607 mcs.cx = width;
608 else
609 mcs.cx = CW_USEDEFAULT;
610
611 if (height > -1)
612 mcs.cy = height;
613 else
614 mcs.cy = CW_USEDEFAULT;
615
616 DWORD msflags = WS_OVERLAPPED | WS_CLIPCHILDREN;
617 if (style & wxMINIMIZE_BOX)
618 msflags |= WS_MINIMIZEBOX;
619 if (style & wxMAXIMIZE_BOX)
620 msflags |= WS_MAXIMIZEBOX;
621 if (style & wxTHICK_FRAME)
622 msflags |= WS_THICKFRAME;
623 if (style & wxSYSTEM_MENU)
624 msflags |= WS_SYSMENU;
625 if ((style & wxMINIMIZE) || (style & wxICONIZE))
626 msflags |= WS_MINIMIZE;
627 if (style & wxMAXIMIZE)
628 msflags |= WS_MAXIMIZE;
629 if (style & wxCAPTION)
630 msflags |= WS_CAPTION;
631
632 mcs.style = msflags;
633
634 mcs.lParam = 0;
635*/
636 DWORD Return = 0; // SendMessage(GetWinHwnd(parent->GetClientWindow()),
637// WM_MDICREATE, 0, (LONG)(LPSTR)&mcs);
638 m_hWnd = (WXHWND)Return;
639
640 wxWndHook = NULL;
641 wxAssociateWinWithHandle((HWND) GetHWND(), this);
642
643 // VZ: what's this? an act of piracy?
644 //SetWindowLong(GetHwnd(), 0, (long)this);
645
646 wxModelessWindows.Append(this);
647 return TRUE;
648}
649
0e320a79
DW
650wxMDIChildFrame::~wxMDIChildFrame()
651{
75f11ad7 652 OS2DestroyWindow();
0e320a79
DW
653}
654
655// Set the client size (i.e. leave the calculation of borders etc.
656// to wxWindows)
75f11ad7 657void wxMDIChildFrame::DoSetClientSize(int width, int height)
0e320a79 658{
75f11ad7
DW
659 HWND hWnd = GetHwnd();
660
661 // TODO:
662/*
663 RECT rect;
664 ::GetClientRect(hWnd, &rect);
665
666 RECT rect2;
667 GetWindowRect(hWnd, &rect2);
668
669 // Find the difference between the entire window (title bar and all)
670 // and the client area; add this to the new client size to move the
671 // window
672 int actual_width = rect2.right - rect2.left - rect.right + width;
673 int actual_height = rect2.bottom - rect2.top - rect.bottom + height;
674
675 if (GetStatusBar())
676 {
677 int sx, sy;
678 GetStatusBar()->GetSize(&sx, &sy);
679 actual_height += sy;
680 }
681
682 POINT point;
683 point.x = rect2.left;
684 point.y = rect2.top;
685
686 // If there's an MDI parent, must subtract the parent's top left corner
687 // since MoveWindow moves relative to the parent
688 wxMDIParentFrame *mdiParent = (wxMDIParentFrame *)GetParent();
689 ::ScreenToClient((HWND) mdiParent->GetClientWindow()->GetHWND(), &point);
690
691 MoveWindow(hWnd, point.x, point.y, actual_width, actual_height, (BOOL)TRUE);
692
693 wxSizeEvent event(wxSize(width, height), m_windowId);
694 event.SetEventObject( this );
695 GetEventHandler()->ProcessEvent(event);
696*/
0e320a79
DW
697}
698
75f11ad7 699void wxMDIChildFrame::DoGetPosition(int *x, int *y) const
0e320a79 700{
75f11ad7
DW
701 // TODO:
702/*
703 RECT rect;
704 GetWindowRect(GetHwnd(), &rect);
705 POINT point;
706 point.x = rect.left;
707 point.y = rect.top;
708
709 // Since we now have the absolute screen coords,
710 // if there's a parent we must subtract its top left corner
711 wxMDIParentFrame *mdiParent = (wxMDIParentFrame *)GetParent();
712 ::ScreenToClient((HWND) mdiParent->GetClientWindow()->GetHWND(), &point);
713
714 *x = point.x;
715 *y = point.y;
716*/
0e320a79
DW
717}
718
75f11ad7 719void wxMDIChildFrame::InternalSetMenuBar()
0e320a79 720{
75f11ad7
DW
721 // TODO:
722/*
723
724 wxMDIParentFrame *parent = (wxMDIParentFrame *)GetParent();
725
726 HMENU subMenu = GetSubMenu((HMENU)parent->GetWindowMenu(), 0);
727
728 InsertWindowMenu(parent->GetClientWindow(), m_hMenu, subMenu);
729
730 parent->m_parentFrameActive = FALSE;
731*/
0e320a79
DW
732}
733
75f11ad7 734// ---------------------------------------------------------------------------
0e320a79 735// MDI operations
75f11ad7
DW
736// ---------------------------------------------------------------------------
737
738void wxMDIChildFrame::Maximize(bool maximize)
0e320a79 739{
75f11ad7
DW
740 wxMDIParentFrame *parent = (wxMDIParentFrame *)GetParent();
741 // TODO:
742/*
743 if ( parent && parent->GetClientWindow() )
744 {
745 ::SendMessage(GetWinHwnd(parent->GetClientWindow()),
746 maximize ? WM_MDIMAXIMIZE : WM_MDIRESTORE,
747 (WPARAM)GetHwnd(), 0);
748 }
749*/
0e320a79
DW
750}
751
752void wxMDIChildFrame::Restore()
753{
75f11ad7
DW
754 // TODO:
755/*
756 wxMDIParentFrame *parent = (wxMDIParentFrame *)GetParent();
757 if ( parent && parent->GetClientWindow() )
758 {
759 ::SendMessage(GetWinHwnd(parent->GetClientWindow()), WM_MDIRESTORE,
760 (WPARAM) GetHwnd(), 0);
761 }
762*/
0e320a79
DW
763}
764
765void wxMDIChildFrame::Activate()
75f11ad7
DW
766{
767 // TODO:
768/*
769 wxMDIParentFrame *parent = (wxMDIParentFrame *)GetParent();
770 if ( parent && parent->GetClientWindow() )
771 {
772 ::SendMessage(GetWinHwnd(parent->GetClientWindow()), WM_MDIACTIVATE,
773 (WPARAM) GetHwnd(), 0);
774 }
775*/
776}
777
778// ---------------------------------------------------------------------------
779// MDI window proc and message handlers
780// ---------------------------------------------------------------------------
781
a885d89a 782MRESULT wxMDIChildFrame::OS2WindowProc(WXUINT message,
75f11ad7
DW
783 WXWPARAM wParam,
784 WXLPARAM lParam)
785{
786 MRESULT rc = 0;
787 bool processed = FALSE;
788
789 // TODO:
790/*
791 switch ( message )
792 {
793 case WM_COMMAND:
794 {
795 WORD id, cmd;
796 WXHWND hwnd;
797 UnpackCommand((WXWPARAM)wParam, (WXLPARAM)lParam,
798 &id, &hwnd, &cmd);
799
800 processed = HandleCommand(id, cmd, (WXHWND)hwnd);
801 }
802 break;
803
804 case WM_GETMINMAXINFO:
805 // let the default window proc calculate the size of MDI children
806 // frames because it is based on the size of the MDI client window,
807 // not on the values specified in wxWindow m_min/max variables
808 return MSWDefWindowProc(message, wParam, lParam);
809
810 case WM_MDIACTIVATE:
811 {
812 WXWORD act;
813 WXHWND hwndAct, hwndDeact;
814 UnpackMDIActivate(wParam, lParam, &act, &hwndAct, &hwndDeact);
815
816 processed = HandleMDIActivate(act, hwndAct, hwndDeact);
817 }
818 // fall through
819
820 case WM_MOVE:
821 // must pass WM_MOVE to DefMDIChildProc() to recalculate MDI client
822 // scrollbars if necessary
823
824 // fall through
825
826 case WM_SIZE:
827 // must pass WM_SIZE to DefMDIChildProc(), otherwise many weird
828 // things happen
829 MSWDefWindowProc(message, wParam, lParam);
830 break;
831
832 case WM_SYSCOMMAND:
833 // DefMDIChildProc handles SC_{NEXT/PREV}WINDOW here, so pass it
834 // the message (the base class version does not)
835 return MSWDefWindowProc(message, wParam, lParam);
836
837 case WM_WINDOWPOSCHANGING:
838 processed = HandleWindowPosChanging((LPWINDOWPOS)lParam);
839 break;
840 }
841*/
842 if ( !processed )
80d83cbc 843 rc = wxFrame::OS2WindowProc(message, wParam, lParam);
75f11ad7
DW
844
845 return rc;
846}
847
848bool wxMDIChildFrame::HandleSize(int x, int y, WXUINT id)
849{
850 HWND hwnd = GetHwnd();
851
852 if ( !hwnd || hwnd == invalidHandle )
853 {
854 return FALSE;
855 }
856
857 // TODO:
858/*
859 switch (id)
860 {
861 case SIZEFULLSCREEN:
862 case SIZENORMAL:
863 m_iconized = FALSE;
864 break;
865
866 case SIZEICONIC:
867 m_iconized = TRUE;
868 break;
869 }
870
871 if ( !m_iconized )
872 {
873 // forward WM_SIZE to status bar control
874#if wxUSE_NATIVE_STATUSBAR
875 if (m_frameStatusBar && m_frameStatusBar->IsKindOf(CLASSINFO(wxStatusBar95)))
876 {
877 wxSizeEvent event(wxSize(x, y), m_frameStatusBar->GetId());
878 event.SetEventObject( m_frameStatusBar );
879
880 ((wxStatusBar95 *)m_frameStatusBar)->OnSize(event);
881 }
882#endif // wxUSE_NATIVE_STATUSBAR
883
884 PositionStatusBar();
885 PositionToolBar();
886
887 return wxWindow::HandleSize(x, y, id);
888 }
889 else
890 {
891 return FALSE;
892 }
893*/
894 return TRUE;
895}
896
897bool wxMDIChildFrame::HandleCommand(WXWORD id, WXWORD cmd, WXHWND hwnd)
898{
899 // In case it's e.g. a toolbar.
900 if ( hwnd )
901 {
902 wxWindow *win = wxFindWinFromHandle(hwnd);
903// if (win)
904// Fix dependent stuff return win->OS2Command(cmd, id);
905 }
906
907 if (wxCurrentPopupMenu)
908 {
909 wxMenu *popupMenu = wxCurrentPopupMenu;
910 wxCurrentPopupMenu = NULL;
911// Fix dependent stuff if (popupMenu->OS2Command(cmd, id))
912// return TRUE;
913 }
914
476607a7 915 if (GetMenuBar() && GetMenuBar()->FindItem(id))
75f11ad7
DW
916 {
917 ProcessCommand(id);
918 return TRUE;
919 }
920 else
921 return FALSE;
922
923 return TRUE;
924}
925
926bool wxMDIChildFrame::HandleMDIActivate(long WXUNUSED(activate),
927 WXHWND hwndAct,
928 WXHWND hwndDeact)
929{
930 wxMDIParentFrame *parent = (wxMDIParentFrame *)GetParent();
931
932 HMENU menuToSet = 0;
933
934 bool activated;
935
936 if ( m_hWnd == hwndAct )
937 {
938 activated = TRUE;
939 parent->m_currentChild = this;
940
941 HMENU child_menu = (HMENU)GetWinMenu();
942 if ( child_menu )
943 {
944 parent->m_parentFrameActive = FALSE;
945
946 menuToSet = child_menu;
947 }
948 }
949 else if ( m_hWnd == hwndDeact )
950 {
951 wxASSERT_MSG( parent->m_currentChild == this,
952 wxT("can't deactivate MDI child which wasn't active!") );
953
954 activated = FALSE;
955 parent->m_currentChild = NULL;
956
957 HMENU parent_menu = (HMENU)parent->GetWinMenu();
958 if ( parent_menu )
959 {
960 parent->m_parentFrameActive = TRUE;
961
962 menuToSet = parent_menu;
963 }
964 }
965 else
966 {
967 // we have nothing to with it
968 return FALSE;
969 }
970
971 if ( menuToSet )
972 {
973 HMENU subMenu = 0; // TODO: GetSubMenu((HMENU) parent->GetWindowMenu(), 0);
974
975 MDISetMenu(parent->GetClientWindow(), menuToSet, subMenu);
976 }
977
978 wxActivateEvent event(wxEVT_ACTIVATE, activated, m_windowId);
979 event.SetEventObject( this );
980
981 return GetEventHandler()->ProcessEvent(event);
982}
983
984bool wxMDIChildFrame::HandleWindowPosChanging(void *pos)
985{
986// WINDOWPOS *lpPos = (WINDOWPOS *)pos;
987 return FALSE;
988}
989
990// ---------------------------------------------------------------------------
991// MDI specific message translation/preprocessing
992// ---------------------------------------------------------------------------
993
a885d89a 994MRESULT wxMDIChildFrame::OS2DefWindowProc(WXUINT message, WXWPARAM wParam, WXLPARAM lParam)
0e320a79
DW
995{
996 // TODO
75f11ad7
DW
997/*
998 return DefMDIChildProc(GetHwnd(),
999 (UINT)message, (WPARAM)wParam, (LPARAM)lParam);
1000*/
1001 return (MRESULT)0;
0e320a79
DW
1002}
1003
75f11ad7
DW
1004bool wxMDIChildFrame::OS2TranslateMessage(WXMSG* msg)
1005{
7e99520b 1006#if wxUSE_ACCEL
f6bcfd97 1007 return m_acceleratorTable.Translate(GetParent()->GetHWND(), msg);
7e99520b
DW
1008#else
1009 return FALSE;
1010#endif //wxUSE_ACCEL
1011
75f11ad7 1012}
0e320a79 1013
75f11ad7
DW
1014// ---------------------------------------------------------------------------
1015// misc
1016// ---------------------------------------------------------------------------
1017
1018void wxMDIChildFrame::OS2DestroyWindow()
0e320a79 1019{
75f11ad7
DW
1020// get wxWindow up to date OS2DetachWindowMenu();
1021 invalidHandle = GetHwnd();
1022
1023 wxMDIParentFrame *parent = (wxMDIParentFrame *)GetParent();
1024
1025 // Must make sure this handle is invalidated (set to NULL) since all sorts
1026 // of things could happen after the child client is destroyed, but before
1027 // the wxFrame is destroyed.
1028
1029 HWND oldHandle = (HWND)GetHWND();
1030// TODO: SendMessage(GetWinHwnd(parent->GetClientWindow()), WM_MDIDESTROY,
1031// (WPARAM)oldHandle, 0);
1032 invalidHandle = 0;
1033
1034 if (m_hMenu)
1035 {
1036// TODO: ::DestroyMenu((HMENU) m_hMenu);
1037 m_hMenu = 0;
1038 }
1039 m_hWnd = 0;
0e320a79
DW
1040}
1041
75f11ad7
DW
1042// Change the client window's extended style so we don't get a client edge
1043// style when a child is maximised (a double border looks silly.)
1044bool wxMDIChildFrame::ResetWindowStyle(void *vrect)
0e320a79 1045{
75f11ad7 1046 return FALSE;
0e320a79
DW
1047}
1048
75f11ad7
DW
1049// ===========================================================================
1050// wxMDIClientWindow: the window of predefined (by Windows) class which
1051// contains the child frames
1052// ===========================================================================
1053
0e320a79
DW
1054bool wxMDIClientWindow::CreateClient(wxMDIParentFrame *parent, long style)
1055{
a756f210 1056 m_backgroundColour = wxSystemSettings::GetColour(wxSYS_COLOUR_APPWORKSPACE);
0e320a79 1057
75f11ad7
DW
1058 // TODO:
1059/*
1060 CLIENTCREATESTRUCT ccs;
1061 m_windowStyle = style;
1062 m_parent = parent;
1063
1064 ccs.hWindowMenu = (HMENU)parent->GetWindowMenu();
1065 ccs.idFirstChild = wxFIRST_MDI_CHILD;
1066
1067 DWORD msStyle = WS_VISIBLE | WS_CHILD | WS_CLIPCHILDREN;
1068 if ( style & wxHSCROLL )
1069 msStyle |= WS_HSCROLL;
1070 if ( style & wxVSCROLL )
1071 msStyle |= WS_VSCROLL;
1072
1073#if defined(__WIN95__)
1074 DWORD exStyle = WS_EX_CLIENTEDGE;
1075#else
1076 DWORD exStyle = 0;
1077#endif
1078
1079 wxWndHook = this;
1080 m_hWnd = (WXHWND)::CreateWindowEx
1081 (
1082 exStyle,
1083 wxT("MDICLIENT"),
1084 NULL,
1085 msStyle,
1086 0, 0, 0, 0,
1087 GetWinHwnd(parent),
1088 NULL,
1089 wxGetInstance(),
1090 (LPSTR)(LPCLIENTCREATESTRUCT)&ccs);
1091 if ( !m_hWnd )
1092 {
1093 wxLogLastError("CreateWindowEx(MDI client)");
1094
1095 return FALSE;
1096 }
1097
1098 SubclassWin(m_hWnd);
1099 wxWndHook = NULL;
1100*/
1101 return TRUE;
0e320a79
DW
1102}
1103
1104// Explicitly call default scroll behaviour
1105void wxMDIClientWindow::OnScroll(wxScrollEvent& event)
1106{
75f11ad7
DW
1107 // Note: for client windows, the scroll position is not set in
1108 // WM_HSCROLL, WM_VSCROLL, so we can't easily determine what
1109 // scroll position we're at.
1110 // This makes it hard to paint patterns or bitmaps in the background,
1111 // and have the client area scrollable as well.
1112
1113 if ( event.GetOrientation() == wxHORIZONTAL )
1114 m_scrollX = event.GetPosition(); // Always returns zero!
1115 else
1116 m_scrollY = event.GetPosition(); // Always returns zero!
1117
1118 event.Skip();
1119}
1120
1121// ---------------------------------------------------------------------------
1122// non member functions
1123// ---------------------------------------------------------------------------
1124
1125static void MDISetMenu(wxWindow *win, HMENU hmenuFrame, HMENU hmenuWindow)
1126{
1127 // TODO:
1128/*
1129 ::SendMessage(GetWinHwnd(win), WM_MDISETMENU,
1130 (WPARAM)hmenuFrame, (LPARAM)hmenuWindow);
1131 // update menu bar of the parent window
1132 wxWindow *parent = win->GetParent();
1133 wxCHECK_RET( parent, wxT("MDI client without parent frame? weird...") );
1134
1135 ::DrawMenuBar(GetWinHwnd(parent));
1136*/
1137}
1138
1139static void InsertWindowMenu(wxWindow *win, WXHMENU menu, HMENU subMenu)
1140{
1141/*
1142 // Try to insert Window menu in front of Help, otherwise append it.
1143 HMENU hmenu = (HMENU)menu;
1144 int N = GetMenuItemCount(hmenu);
1145 bool success = FALSE;
1146 for ( int i = 0; i < N; i++ )
1147 {
1148 wxChar buf[256];
1149 int chars = GetMenuString(hmenu, i, buf, WXSIZEOF(buf), MF_BYPOSITION);
1150 if ( chars == 0 )
1151 {
1152 wxLogLastError(wxT("GetMenuString"));
1153
1154 continue;
1155 }
1156
1157 if ( wxStripMenuCodes(wxString(buf)).IsSameAs(wxT("Help")) )
1158 {
1159 success = TRUE;
1160 ::InsertMenu(hmenu, i, MF_BYPOSITION | MF_POPUP | MF_STRING,
1161 (UINT)subMenu, wxT("&Window"));
1162 break;
1163 }
1164 }
1165
1166 if ( !success )
1167 {
1168 ::AppendMenu(hmenu, MF_POPUP, (UINT)subMenu, wxT("&Window"));
1169 }
1170 MDISetMenu(win, hmenu, subMenu);
1171*/
1172}
1173
1174static void UnpackMDIActivate(WXWPARAM wParam, WXLPARAM lParam,
1175 WXWORD *activate, WXHWND *hwndAct, WXHWND *hwndDeact)
1176{
1177 *activate = TRUE;
1178 *hwndAct = (WXHWND)lParam;
1179 *hwndDeact = (WXHWND)wParam;
0e320a79
DW
1180}
1181