📄 mdi.cpp
字号:
}
break;
case WM_SIZE:
// though we don't (usually) resize the MDI client to exactly fit the
// client area we need to pass this one to DefFrameProc to allow the children to show
break;
}
if ( !processed )
rc = wxFrame::MSWWindowProc(message, wParam, lParam);
return rc;
}
bool wxMDIParentFrame::HandleActivate(int state, bool minimized, WXHWND activate)
{
bool processed = false;
if ( wxWindow::HandleActivate(state, minimized, activate) )
{
// already processed
processed = true;
}
// If this window is an MDI parent, we must also send an OnActivate message
// to the current child.
if ( (m_currentChild != NULL) &&
((state == WA_ACTIVE) || (state == WA_CLICKACTIVE)) )
{
wxActivateEvent event(wxEVT_ACTIVATE, true, m_currentChild->GetId());
event.SetEventObject( m_currentChild );
if ( m_currentChild->GetEventHandler()->ProcessEvent(event) )
processed = true;
}
return processed;
}
bool wxMDIParentFrame::HandleCommand(WXWORD id, WXWORD cmd, WXHWND hwnd)
{
// In case it's e.g. a toolbar.
if ( hwnd )
{
wxWindow *win = wxFindWinFromHandle(hwnd);
if ( win )
return win->MSWCommand(cmd, id);
}
if (wxCurrentPopupMenu)
{
wxMenu *popupMenu = wxCurrentPopupMenu;
wxCurrentPopupMenu = NULL;
if (popupMenu->MSWCommand(cmd, id))
return true;
}
// is it one of standard MDI commands?
WXWPARAM wParam = 0;
WXLPARAM lParam = 0;
int msg;
switch ( id )
{
case IDM_WINDOWCASCADE:
msg = WM_MDICASCADE;
wParam = MDITILE_SKIPDISABLED;
break;
case IDM_WINDOWTILEHOR:
wParam |= MDITILE_HORIZONTAL;
// fall through
case IDM_WINDOWTILEVERT:
if ( !wParam )
wParam = MDITILE_VERTICAL;
msg = WM_MDITILE;
wParam |= MDITILE_SKIPDISABLED;
break;
case IDM_WINDOWICONS:
msg = WM_MDIICONARRANGE;
break;
case IDM_WINDOWNEXT:
msg = WM_MDINEXT;
lParam = 0; // next child
break;
case IDM_WINDOWPREV:
msg = WM_MDINEXT;
lParam = 1; // previous child
break;
default:
msg = 0;
}
if ( msg )
{
::SendMessage(GetWinHwnd(GetClientWindow()), msg, wParam, lParam);
return true;
}
// FIXME VZ: what does this test do??
if (id >= 0xF000)
{
return false; // Get WndProc to call default proc
}
if ( IsMdiCommandId(id) )
{
wxWindowList::compatibility_iterator node = GetChildren().GetFirst();
while ( node )
{
wxWindow *child = node->GetData();
if ( child->GetHWND() )
{
long childId = wxGetWindowId(child->GetHWND());
if (childId == (long)id)
{
::SendMessage( GetWinHwnd(GetClientWindow()),
WM_MDIACTIVATE,
(WPARAM)child->GetHWND(), 0);
return true;
}
}
node = node->GetNext();
}
}
else if ( m_parentFrameActive )
{
return ProcessCommand(id);
}
else if ( m_currentChild )
{
return m_currentChild->HandleCommand(id, cmd, hwnd);
}
else
{
// this shouldn't happen because it means that our messages are being
// lost (they're not sent to the parent frame nor to the children)
wxFAIL_MSG(wxT("MDI parent frame is not active, yet there is no active MDI child?"));
}
return false;
}
WXLRESULT wxMDIParentFrame::MSWDefWindowProc(WXUINT message,
WXWPARAM wParam,
WXLPARAM lParam)
{
WXHWND clientWnd;
if ( GetClientWindow() )
clientWnd = GetClientWindow()->GetHWND();
else
clientWnd = 0;
return DefFrameProc(GetHwnd(), (HWND)clientWnd, message, wParam, lParam);
}
bool wxMDIParentFrame::MSWTranslateMessage(WXMSG* msg)
{
MSG *pMsg = (MSG *)msg;
// first let the current child get it
if ( m_currentChild && m_currentChild->GetHWND() &&
m_currentChild->MSWTranslateMessage(msg) )
{
return true;
}
// then try out accel table (will also check the menu accels)
if ( wxFrame::MSWTranslateMessage(msg) )
{
return true;
}
// finally, check for MDI specific built in accel keys
if ( pMsg->message == WM_KEYDOWN || pMsg->message == WM_SYSKEYDOWN )
{
if ( ::TranslateMDISysAccel(GetWinHwnd(GetClientWindow()), pMsg))
return true;
}
return false;
}
// ===========================================================================
// wxMDIChildFrame
// ===========================================================================
void wxMDIChildFrame::Init()
{
m_needsResize = true;
m_needsInitialShow = true;
}
bool wxMDIChildFrame::Create(wxMDIParentFrame *parent,
wxWindowID id,
const wxString& title,
const wxPoint& pos,
const wxSize& size,
long style,
const wxString& name)
{
SetName(name);
if ( id != wxID_ANY )
m_windowId = id;
else
m_windowId = (int)NewControlId();
if ( parent )
{
parent->AddChild(this);
}
int x = pos.x;
int y = pos.y;
int width = size.x;
int height = size.y;
MDICREATESTRUCT mcs;
mcs.szClass = style & wxFULL_REPAINT_ON_RESIZE
? wxMDIChildFrameClassName
: wxMDIChildFrameClassNameNoRedraw;
mcs.szTitle = title;
mcs.hOwner = wxGetInstance();
if (x != wxDefaultCoord)
mcs.x = x;
else
mcs.x = CW_USEDEFAULT;
if (y != wxDefaultCoord)
mcs.y = y;
else
mcs.y = CW_USEDEFAULT;
if (width != wxDefaultCoord)
mcs.cx = width;
else
mcs.cx = CW_USEDEFAULT;
if (height != wxDefaultCoord)
mcs.cy = height;
else
mcs.cy = CW_USEDEFAULT;
DWORD msflags = WS_OVERLAPPED | WS_CLIPCHILDREN;
if (style & wxMINIMIZE_BOX)
msflags |= WS_MINIMIZEBOX;
if (style & wxMAXIMIZE_BOX)
msflags |= WS_MAXIMIZEBOX;
if (style & wxTHICK_FRAME)
msflags |= WS_THICKFRAME;
if (style & wxSYSTEM_MENU)
msflags |= WS_SYSMENU;
if ((style & wxMINIMIZE) || (style & wxICONIZE))
msflags |= WS_MINIMIZE;
if (style & wxMAXIMIZE)
msflags |= WS_MAXIMIZE;
if (style & wxCAPTION)
msflags |= WS_CAPTION;
mcs.style = msflags;
mcs.lParam = 0;
wxWindowCreationHook hook(this);
m_hWnd = (WXHWND)::SendMessage(GetWinHwnd(parent->GetClientWindow()),
WM_MDICREATE, 0, (LONG)(LPSTR)&mcs);
wxAssociateWinWithHandle((HWND) GetHWND(), this);
return true;
}
wxMDIChildFrame::~wxMDIChildFrame()
{
// will be destroyed by DestroyChildren() but reset them before calling it
// to avoid using dangling pointers if a callback comes in the meanwhile
#if wxUSE_TOOLBAR
m_frameToolBar = NULL;
#endif
#if wxUSE_STATUSBAR
m_frameStatusBar = NULL;
#endif // wxUSE_STATUSBAR
DestroyChildren();
RemoveWindowMenu(NULL, m_hMenu);
MSWDestroyWindow();
}
bool wxMDIChildFrame::Show(bool show)
{
m_needsInitialShow = false;
return wxFrame::Show(show);
}
// Set the client size (i.e. leave the calculation of borders etc.
// to wxWidgets)
void wxMDIChildFrame::DoSetClientSize(int width, int height)
{
HWND hWnd = GetHwnd();
RECT rect;
::GetClientRect(hWnd, &rect);
RECT rect2;
GetWindowRect(hWnd, &rect2);
// Find the difference between the entire window (title bar and all)
// and the client area; add this to the new client size to move the
// window
int actual_width = rect2.right - rect2.left - rect.right + width;
int actual_height = rect2.bottom - rect2.top - rect.bottom + height;
#if wxUSE_STATUSBAR
if (GetStatusBar() && GetStatusBar()->IsShown())
{
int sx, sy;
GetStatusBar()->GetSize(&sx, &sy);
actual_height += sy;
}
#endif // wxUSE_STATUSBAR
POINT point;
point.x = rect2.left;
point.y = rect2.top;
// If there's an MDI parent, must subtract the parent's top left corner
// since MoveWindow moves relative to the parent
wxMDIParentFrame *mdiParent = (wxMDIParentFrame *)GetParent();
::ScreenToClient((HWND) mdiParent->GetClientWindow()->GetHWND(), &point);
MoveWindow(hWnd, point.x, point.y, actual_width, actual_height, (BOOL)true);
wxSize size(width, height);
wxSizeEvent event(size, m_windowId);
event.SetEventObject( this );
GetEventHandler()->ProcessEvent(event);
}
void wxMDIChildFrame::DoGetPosition(int *x, int *y) const
{
RECT rect;
GetWindowRect(GetHwnd(), &rect);
POINT point;
point.x = rect.left;
point.y = rect.top;
// Since we now have the absolute screen coords,
// if there's a parent we must subtract its top left corner
wxMDIParentFrame *mdiParent = (wxMDIParentFrame *)GetParent();
::ScreenToClient((HWND) mdiParent->GetClientWindow()->GetHWND(), &point);
if (x)
*x = point.x;
if (y)
*y = point.y;
}
void wxMDIChildFrame::InternalSetMenuBar()
{
wxMDIParentFrame *parent = (wxMDIParentFrame *)GetParent();
InsertWindowMenu(parent->GetClientWindow(),
m_hMenu, GetMDIWindowMenu(parent));
parent->m_parentFrameActive = false;
}
void wxMDIChildFrame::DetachMenuBar()
{
RemoveWindowMenu(NULL, m_hMenu);
wxFrame::DetachMenuBar();
}
WXHICON wxMDIChildFrame::GetDefaultIcon() const
{
// we don't have any standard icons (any more)
return (WXHICON)0;
}
// ---------------------------------------------------------------------------
// MDI operations
// ---------------------------------------------------------------------------
void wxMDIChildFrame::Maximize(bool maximize)
{
wxMDIParentFrame *parent = (wxMDIParentFrame *)GetParent();
if ( parent && parent->GetClientWindow() )
{
::SendMessage(GetWinHwnd(parent->GetClientWindow()),
maximize ? WM_MDIMAXIMIZE : WM_MDIRESTORE,
(WPARAM)GetHwnd(), 0);
}
}
void wxMDIChildFrame::Restore()
{
wxMDIParentFrame *parent = (wxMDIParentFrame *)GetParent();
if ( parent && parent->GetClientWindow() )
{
::SendMessage(GetWinHwnd(parent->GetClientWindow()), WM_MDIRESTORE,
(WPARAM) GetHwnd(), 0);
}
}
void wxMDIChildFrame::Activate()
{
wxMDIParentFrame *parent = (wxMDIParentFrame *)GetParent();
if ( parent && parent->GetClientWindow() )
{
::SendMessage(GetWinHwnd(parent->GetClientWindow()), WM_MDIACTIVATE,
(WPARAM) GetHwnd(), 0);
}
}
// ---------------------------------------------------------------------------
// MDI window proc and message handlers
// ---------------------------------------------------------------------------
WXLRESULT wxMDIChildFrame::MSWWindowProc(WXUINT message,
WXWPARAM wParam,
WXLPARAM lParam)
{
WXLRESULT rc = 0;
bool processed = false;
switch ( message )
{
case WM_COMMAND:
{
WORD id, cmd;
WXHWND hwnd;
UnpackCommand((WXWPARAM)wParam, (WXLPARAM)lParam,
&id, &hwnd, &cmd);
processed = HandleCommand(id, cmd, (WXHWND)hwnd);
}
break;
case WM_GETMINMAXINFO:
processed = HandleGetMinMaxInfo((MINMAXINFO *)lParam);
break;
case WM_MDIACTIVATE:
{
WXWORD act;
WXHWND hwndAct, hwndDeact;
UnpackMDIActivate(wParam, lParam, &act, &hwndAct, &hwndDeact);
processed = HandleMDIActivate(act, hwndAct, hwndDeact);
}
// fall through
case WM_MOVE:
// must pass WM_MOVE to DefMDIChildProc() to recalculate MDI client
// scrollbars if necessary
// fall through
case WM_SIZE:
// must pass WM_SIZE to DefMDIChildProc(), otherwise many weird
// things happen
MSWDefWindowProc(message, wParam, lParam);
break;
case WM_SYSCOMMAND:
// DefMDIChildProc handles SC_{NEXT/PREV}WINDOW here, so pass it
// the message (the base class version does not)
return MSWDefWindowProc(message, wParam, lParam);
case WM_WINDOWPOSCHANGING:
processed = HandleWindowPosChanging((LPWINDOWPOS)lParam);
break;
}
if ( !processed )
rc = wxFrame::MSWWindowProc(message, wParam, lParam);
return rc;
}
bool wxMDIChildFrame::HandleCommand(WXWORD id, WXWORD cmd, WXHWND hwnd)
{
// In case it's e.g. a toolbar.
if ( hwnd )
{
wxWindow *win = wxFindWinFromHandle(hwnd);
if (win)
return win->MSWCommand(cmd, id);
}
if (wxCurrentPopupMenu)
{
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -