frame.cpp
来自「A*算法 A*算法 A*算法 A*算法A*算法A*算法」· C++ 代码 · 共 1,133 行 · 第 1/3 页
CPP
1,133 行
{
wxToolMenuBar* toolBar = new wxToolMenuBar(this, wxID_ANY,
wxDefaultPosition, wxDefaultSize,
wxBORDER_NONE | wxTB_HORIZONTAL,
wxToolBarNameStr, menubar);
SetToolBar(toolBar);
menubar->SetToolBar(toolBar);
}
// Now adjust size for menu bar
int menuHeight = 26;
//When the main window is created using CW_USEDEFAULT the height of the
// is created is not taken into account). So we resize the window after
// if a menubar is present
{
RECT rc;
::GetWindowRect((HWND) GetHWND(), &rc);
// adjust for menu / titlebar height
rc.bottom -= (2*menuHeight-1);
::MoveWindow((HWND) GetHWND(), rc.left, rc.top, rc.right, rc.bottom, FALSE);
}
#endif
wxFrameBase::AttachMenuBar(menubar);
if ( !menubar )
{
// actually remove the menu from the frame
m_hMenu = (WXHMENU)0;
InternalSetMenuBar();
}
else // set new non NULL menu bar
{
#if !defined(__WXWINCE__) || defined(WINCE_WITH_COMMANDBAR)
// Can set a menubar several times.
if ( menubar->GetHMenu() )
{
m_hMenu = menubar->GetHMenu();
}
else // no HMENU yet
{
m_hMenu = menubar->Create();
if ( !m_hMenu )
{
wxFAIL_MSG( _T("failed to create menu bar") );
return;
}
}
#endif
InternalSetMenuBar();
}
}
void wxFrame::InternalSetMenuBar()
{
#if defined(__WXMICROWIN__) || defined(__WXWINCE__)
// Nothing
#else
if ( !::SetMenu(GetHwnd(), (HMENU)m_hMenu) )
{
wxLogLastError(wxT("SetMenu"));
}
#endif
}
#endif // wxUSE_MENUS_NATIVE
// Responds to colour changes, and passes event on to children.
void wxFrame::OnSysColourChanged(wxSysColourChangedEvent& event)
{
SetOwnBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_APPWORKSPACE));
Refresh();
#if wxUSE_STATUSBAR
if ( m_frameStatusBar )
{
wxSysColourChangedEvent event2;
event2.SetEventObject( m_frameStatusBar );
m_frameStatusBar->GetEventHandler()->ProcessEvent(event2);
}
#endif // wxUSE_STATUSBAR
// Propagate the event to the non-top-level children
wxWindow::OnSysColourChanged(event);
}
// Pass true to show full screen, false to restore.
bool wxFrame::ShowFullScreen(bool show, long style)
{
// TODO-CE: add support for CE
#if !defined(__WXMICROWIN__) && !defined(__WXWINCE__)
if ( IsFullScreen() == show )
return false;
if (show)
{
// zap the toolbar, menubar, and statusbar if needed
//
// TODO: hide commandbar for WINCE_WITH_COMMANDBAR
#if wxUSE_TOOLBAR
wxToolBar *theToolBar = GetToolBar();
if ((style & wxFULLSCREEN_NOTOOLBAR) && theToolBar)
{
if ( theToolBar->IsShown() )
{
theToolBar->SetSize(wxDefaultCoord,0);
theToolBar->Show(false);
}
else // prevent it from being restored later
{
style &= ~wxFULLSCREEN_NOTOOLBAR;
}
}
#endif // wxUSE_TOOLBAR
if (style & wxFULLSCREEN_NOMENUBAR)
SetMenu((HWND)GetHWND(), (HMENU) NULL);
#if wxUSE_STATUSBAR
wxStatusBar *theStatusBar = GetStatusBar();
// Save the number of fields in the statusbar
if ((style & wxFULLSCREEN_NOSTATUSBAR) && theStatusBar)
{
if ( theStatusBar->IsShown() )
theStatusBar->Show(false);
else
style &= ~wxFULLSCREEN_NOSTATUSBAR;
}
#endif // wxUSE_STATUSBAR
}
else // restore to normal
{
// restore the toolbar, menubar, and statusbar if we had hid them
#if wxUSE_TOOLBAR
wxToolBar *theToolBar = GetToolBar();
if ((m_fsStyle & wxFULLSCREEN_NOTOOLBAR) && theToolBar)
{
theToolBar->Show(true);
}
#endif // wxUSE_TOOLBAR
if (m_fsStyle & wxFULLSCREEN_NOMENUBAR)
{
WXHMENU menu = m_hMenu;
#if wxUSE_MDI_ARCHITECTURE
wxMDIParentFrame *frame = wxDynamicCast(this, wxMDIParentFrame);
if (frame)
{
wxMDIChildFrame *child = frame->GetActiveChild();
if (child)
{
menu = child->GetWinMenu();
}
}
#endif // wxUSE_MDI_ARCHITECTURE
if (menu)
{
::SetMenu(GetHwnd(), (HMENU)menu);
}
}
#if wxUSE_STATUSBAR
wxStatusBar *theStatusBar = GetStatusBar();
if ((m_fsStyle & wxFULLSCREEN_NOSTATUSBAR) && theStatusBar)
{
theStatusBar->Show(true);
PositionStatusBar();
}
#endif // wxUSE_STATUSBAR
}
#endif // !defined(__WXMICROWIN__) && !defined(__WXWINCE__)
return wxFrameBase::ShowFullScreen(show, style);
}
// ----------------------------------------------------------------------------
// tool/status bar stuff
// ----------------------------------------------------------------------------
#if wxUSE_TOOLBAR
wxToolBar* wxFrame::CreateToolBar(long style, wxWindowID id, const wxString& name)
{
#if defined(WINCE_WITHOUT_COMMANDBAR)
// We may already have a toolbar from calling SetMenuBar.
if (GetToolBar())
return GetToolBar();
#endif
if ( wxFrameBase::CreateToolBar(style, id, name) )
{
PositionToolBar();
}
return m_frameToolBar;
}
void wxFrame::PositionToolBar()
{
wxToolBar *toolbar = GetToolBar();
if ( toolbar && toolbar->IsShown() )
{
#if defined(WINCE_WITHOUT_COMMANDBAR)
// We want to do something different in WinCE, because
// the toolbar should be associated with the commandbar,
// and not an independent window.
// TODO
#else
// don't call our (or even wxTopLevelWindow) version because we want
// the real (full) client area size, not excluding the tool/status bar
int width, height;
wxWindow::DoGetClientSize(&width, &height);
#if wxUSE_STATUSBAR
wxStatusBar *statbar = GetStatusBar();
if ( statbar && statbar->IsShown() )
{
height -= statbar->GetClientSize().y;
}
#endif // wxUSE_STATUSBAR
int x = 0;
int y = 0;
#if defined(WINCE_WITH_COMMANDBAR)
// We're using a commandbar - so we have to allow for it.
if (GetMenuBar() && GetMenuBar()->GetCommandBar())
{
RECT rect;
::GetWindowRect((HWND) GetMenuBar()->GetCommandBar(), &rect);
y = rect.bottom - rect.top;
}
#endif
int tx, ty;
int tw, th;
toolbar->GetPosition(&tx, &ty);
toolbar->GetSize(&tw, &th);
// Adjust
if (ty < 0 && (-ty == th))
ty = 0;
if (tx < 0 && (-tx == tw))
tx = 0;
int desiredW = tw;
int desiredH = th;
if ( toolbar->GetWindowStyleFlag() & wxTB_VERTICAL )
{
desiredH = height;
}
else
{
desiredW = width;
// if ( toolbar->GetWindowStyleFlag() & wxTB_FLAT )
// desiredW -= 3;
}
// use the 'real' MSW position here, don't offset relativly to the
// client area origin
// Optimise such that we don't have to always resize the toolbar
// when the frame changes, otherwise we'll get a lot of flicker.
bool heightChanging wxDUMMY_INITIALIZE(true);
bool widthChanging wxDUMMY_INITIALIZE(true);
if ( toolbar->GetWindowStyleFlag() & wxTB_VERTICAL )
{
// It's OK if the current height is greater than what can be shown.
heightChanging = (desiredH > th) ;
widthChanging = (desiredW != tw) ;
// The next time around, we may not have to set the size
if (heightChanging)
desiredH = desiredH + 200;
}
else
{
// It's OK if the current width is greater than what can be shown.
widthChanging = (desiredW > tw) ;
heightChanging = (desiredH != th) ;
// The next time around, we may not have to set the size
if (widthChanging)
desiredW = desiredW + 200;
}
if (tx != 0 || ty != 0 || widthChanging || heightChanging)
toolbar->SetSize(x, y, desiredW, desiredH, wxSIZE_NO_ADJUSTMENTS);
#endif // __WXWINCE__
}
}
#endif // wxUSE_TOOLBAR
// ----------------------------------------------------------------------------
// frame state (iconized/maximized/...)
// ----------------------------------------------------------------------------
// propagate our state change to all child frames: this allows us to emulate X
// Windows behaviour where child frames float independently of the parent one
// on the desktop, but are iconized/restored with it
void wxFrame::IconizeChildFrames(bool bIconize)
{
m_iconized = bIconize;
for ( wxWindowList::compatibility_iterator node = GetChildren().GetFirst();
node;
node = node->GetNext() )
{
wxWindow *win = node->GetData();
// iconizing the frames with this style under Win95 shell puts them at
// the bottom of the screen (as the MDI children) instead of making
// them appear in the taskbar because they are, by virtue of this
// style, not managed by the taskbar - instead leave Windows take care
// of them
#ifdef __WIN95__
if ( win->GetWindowStyle() & wxFRAME_TOOL_WINDOW )
continue;
#endif // Win95
// the child MDI frames are a special case and should not be touched by
// the parent frame - instead, they are managed by the user
wxFrame *frame = wxDynamicCast(win, wxFrame);
if ( frame
#if wxUSE_MDI_ARCHITECTURE
&& !frame->IsMDIChild()
#endif // wxUSE_MDI_ARCHITECTURE
)
{
// we don't want to restore the child frames which had been
// iconized even before we were iconized, so save the child frame
// status when iconizing the parent frame and check it when
// restoring it
if ( bIconize )
{
frame->m_wasMinimized = frame->IsIconized();
}
// note that we shouldn't touch the hidden frames neither because
// iconizing/restoring them would show them as a side effect
if ( !frame->m_wasMinimized && frame->IsShown() )
frame->Iconize(bIconize);
}
}
}
WXHICON wxFrame::GetDefaultIcon() const
{
// we don't have any standard icons (any more)
return (WXHICON)0;
}
// ===========================================================================
// message processing
// ===========================================================================
// ---------------------------------------------------------------------------
// preprocessing
// ---------------------------------------------------------------------------
bool wxFrame::MSWTranslateMessage(WXMSG* pMsg)
{
if ( wxWindow::MSWTranslateMessage(pMsg) )
return true;
#if wxUSE_MENUS && wxUSE_ACCEL && !defined(__WXUNIVERSAL__)
// try the menu bar accels
wxMenuBar *menuBar = GetMenuBar();
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?