📄 mainwnd.cpp
字号:
// FALSE if fail.
if (!m_cEventView.CreateStatic (this, 2, 1))
{
TRACE (_T("OTC: CKMainWnd::OnCreateClient () -> CreateStatic () failed\n"));
return (FALSE);
}
// Split top (data view) pane again into two panes, side by side. Left
// pane will be "group view", right pane will be the "item view". Return
// FALSE if fail.
if (!m_cDataView.CreateStatic (&m_cEventView, 1, 2))
{
TRACE (_T("OTC: CKMainWnd::OnCreateClient () -> CreateStatic () failed\n"));
return (FALSE);
}
// Get client area of main window. We will use it to set initial size
// of the 3 component panes. Top panes will each be half the width of
// the client area, and 3/4 its heigth. Bottom pane will be its full
// width and 1/4 its height.
RECT rc;
GetClientRect (&rc);
// Create "group view" in top left pane:
if (!m_cDataView.CreateView (
0, 0,
RUNTIME_CLASS (CKGroupView),
CSize (rc.right / 2, 3 * rc.bottom / 4),
pContext))
{
ASSERT (FALSE);
return (FALSE);
}
// Create "item view" in top right pane:
if (!m_cDataView.CreateView (
0, 1,
RUNTIME_CLASS (CKItemView),
CSize (rc.right / 2, 3 * rc.bottom / 4),
pContext))
{
ASSERT (FALSE);
return (FALSE);
}
// Create "event view" in bottom pane:
if (!m_cEventView.CreateView (
1, 0,
RUNTIME_CLASS (CKEventView),
CSize (rc.right, rc.bottom / 4),
pContext))
{
ASSERT (FALSE);
return (FALSE);
}
// Save event view pointer:
m_pEventLog = (CKEventView *) m_cEventView.GetPane (1, 0);
// Start update status bar timer:
SetTimer (STATUSUPDATETIMER, STATUSUPDATEINTERVAL, NULL);
// If we make it here, everything went OK. Return TRUE to indicate
// success:
return (TRUE);
}
// **************************************************************************
// ActivateFrame ()
//
// Description:
// Handles notification that the window frame should be activated and
// updated. Override this function to load current window settings.
//
// Parameters:
// int nCmdShow Specifies how the CWnd is to be shown.
// SW_HIDE, SW_MINIMIZE, etc.
//
// Returns:
// void
// **************************************************************************
void CKMainWnd::ActivateFrame (int nCmdShow)
{
// Make sure window settings are loaded from registry just once per
// application load by using the m_bLoaded flag:
if (!m_bLoaded)
{
LoadSettings ();
m_bLoaded = true;
}
// Perform default processing:
CFrameWnd::ActivateFrame (nCmdShow);
}
// **************************************************************************
// OnClose ()
//
// Description:
// Handles notification that the window is being destroyed. Override this
// function to save current window settings.
//
// Parameters:
// none
//
// Returns:
// void
// **************************************************************************
void CKMainWnd::OnClose ()
{
// Get pointer to our document object:
CKDocument *pDoc = (CKDocument *) GetActiveDocument ();
ASSERT (pDoc);
// Only allow a close if the document is not locked (i.e. some other
// thread is using document and needs it to stay alive until they are
// done:
if (!pDoc->IsLocked ())
{
// Save main window settings in registry so it will appear the
// same next time application is started:
SaveSettings ();
// Perform default processing:
CFrameWnd::OnClose ();
}
else
{
// Don't allow close. Sound a beep to warn user:
MessageBeep ((DWORD)-1);
return;
}
}
// **************************************************************************
// OnEndSession ()
//
// Description:
// Handles notification that the session is ending.
//
// Parameters:
// BOOL bEnding If TRUE, Windows can terminate any time after
// all applications have returned from processing
// this call. Override this function to save
// current window settings.
//
// Returns:
// void
// **************************************************************************
void CKMainWnd::OnEndSession (BOOL bEnding)
{
// Save main window settings to registry so it will appear the same the
// next time application is started:
SaveSettings ();
// Perfrom default processing:
CFrameWnd::OnEndSession (bEnding);
}
// **************************************************************************
// OnCmdMsg ()
//
// Description:
// Called by the framework to route and dispatch command messages and to
// handle the update of command user-interface objects. Override to pass
// message onto appropriate view to process.
//
// Parameters:
// UINT nID Contains the command ID.
// int nCode Identifies the command notification code.
// void *pExtra Used according to the value of nCode.
// AFX_CMDHANDLERINFO *pHandlerInfo If not NULL, OnCmdMsg fills in the
// pTarget and pmf members of the
// pHandlerInfo structure instead of
// dispatching the command. Typically,
// this parameter should be NULL.
//
// Returns:
// BOOL - TRUE if message processed.
// **************************************************************************
BOOL CKMainWnd::OnCmdMsg (UINT nID, int nCode, void *pExtra, AFX_CMDHANDLERINFO *pHandlerInfo)
{
// See if the default framework can process the message. Return TRUE
// if it can:
if (CFrameWnd::OnCmdMsg (nID, nCode, pExtra, pHandlerInfo))
return (TRUE);
// Otherwise pass it onto the document for routing to all inactive views.
// If one of these views processes the message, return TRUE:
CKDocument *pDoc = (CKDocument *) GetActiveDocument ();
if (pDoc != NULL)
{
if (pDoc->RouteCmdMsg (GetActiveView (), nID, nCode, pExtra, pHandlerInfo))
return (TRUE);
}
// If we make it here, message not processed. Return FALSE to indicate
// this:
return (FALSE);
}
// **************************************************************************
// OnUpdateCmdUI ()
//
// Description:
// Handles notification to update the enabled state of application
// functionality (i.e, menu items).
//
// Parameters:
// CCmdUI *pCmdUI Encapsulates user interface data
//
// Returns:
// void
// **************************************************************************
void CKMainWnd::OnUpdateCmdUI (CCmdUI *pCmdUI)
{
// Get pointer to our document:
CKDocument *pDoc = (CKDocument *) GetActiveDocument ();
ASSERT (pDoc != NULL);
// Set flag to indicate we sould disable all items related to project
// edit functions if the docuemtn is presently locked (i.e. don't allow
// other threads to access document data while another thread has
// possession of it.)
bool bDisableProjectEditOperations = pDoc->IsLocked ();
// Processes according to the menu item we are being asked about:
switch (pCmdUI->m_nID)
{
// Disable "File|New", "File|Open", and "File|Exit" if document
// is locked:
case ID_FILE_NEW:
case ID_FILE_OPEN:
case ID_APP_EXIT:
pCmdUI->Enable (!pDoc->IsLocked ());
break;
// Always enable "Help|About":
case ID_APP_ABOUT:
pCmdUI->Enable (true);
break;
// Enable "File|Save" only if document is not locked, and is modified:
case ID_FILE_SAVE:
pCmdUI->Enable (!bDisableProjectEditOperations && ((CKDocument *) GetActiveDocument ())->IsModified ());
break;
// Enable "File|Save As" only if document is not locked and has
// server objects defined:
case ID_FILE_SAVE_AS:
pCmdUI->Enable (!bDisableProjectEditOperations && ((CKDocument *) GetActiveDocument ())->GetServerCount () > 0);
break;
// Disable "File|Most Recently Used Files" selections if document
// is locked:
case ID_FILE_MRU_FILE1:
case ID_FILE_MRU_FILE2:
case ID_FILE_MRU_FILE3:
case ID_FILE_MRU_FILE4:
case ID_FILE_MRU_FILE5:
case ID_FILE_MRU_FILE6:
case ID_FILE_MRU_FILE7:
case ID_FILE_MRU_FILE8:
case ID_FILE_MRU_FILE9:
case ID_FILE_MRU_FILE10:
case ID_FILE_MRU_FILE11:
case ID_FILE_MRU_FILE12:
case ID_FILE_MRU_FILE13:
case ID_FILE_MRU_FILE14:
case ID_FILE_MRU_FILE15:
case ID_FILE_MRU_FILE16:
if (pCmdUI->m_pMenu)
{
int iMRU;
CMenu *pMenu = pCmdUI->m_pMenu;
TRACE (_T("Deleting MRU list\n"));
// Pre-delete everything so that things don't get screwed up when
// the user makes a change
for (iMRU = ID_FILE_MRU_FILE1; iMRU <= ID_FILE_MRU_FILE16; iMRU++)
pMenu->DeleteMenu (iMRU, MF_BYCOMMAND);
cApp.OnUpdateMRUFile (pCmdUI);
// If locked, set enabled state to "GRAYED and DISABLED":
if (pDoc->IsLocked ())
{
for (iMRU = ID_FILE_MRU_FILE1; iMRU <= ID_FILE_MRU_FILE16; iMRU++)
pMenu->EnableMenuItem (iMRU, MF_BYCOMMAND | MF_GRAYED | MF_DISABLED);
}
}
break;
// Enable "Edit|Copy" only if document is not locked, and appropriate
// item is slected:
case ID_EDIT_COPY:
{
// If document is not locked, look at what view is active and what
// sort of view items are selected:
if (!bDisableProjectEditOperations)
{
// Get pointer to the active view:
CView *pView = GetActiveView ();
// If the group view is active, enable if a server or group
// is selected:
if (pView == GetGroupView ())
{
pCmdUI->Enable ((pDoc->GetSelectedServer () != NULL) ||
(pDoc->GetSelectedGroup () != NULL));
}
// Else if the item view is active, enable if one or more
// items are selected:
else if (pView == GetItemView ())
{
pCmdUI->Enable (((CKItemView *)pView)->GetSelectedCount ());
}
// Otherwise disable:
else
pCmdUI->Enable (false);
}
// Disable if document is locked:
else
pCmdUI->Enable (false);
}
break;
// Enable "Edit|Cut" and "Edit|Delete" only if document is not locked
// and a group or server is selected:
case ID_EDIT_CUT:
case ID_EDIT_DELETE:
if (bDisableProjectEditOperations)
pCmdUI->Enable (false);
else
pCmdUI->Enable ((pDoc->GetSelectedServer () != NULL) ||
(pDoc->GetSelectedGroup () != NULL));
break;
// Disable "Edit|Paste" if document is locked. If not, enable only if
// it makes sence to paste the contents of the clipboard into the
// selected item:
case ID_EDIT_PASTE:
{
if (bDisableProjectEditOperations)
pCmdUI->Enable (false);
else
{
// Get pointer to the active view:
CView *pView = GetActiveView ();
// Get pointer to the selected server and group:
CKServer *pServer = pDoc->GetSelectedServer ();
CKGroup *pGroup = pDoc->GetSelectedGroup ();
// If group view is active:
if (pView == GetGroupView ())
{
// Can paste server if no selected object:
if (pServer == NULL && pGroup == NULL)
pCmdUI->Enable (IsClipboardFormatAvailable (CF_SERVER));
// Can paste group or server if a server is selected:
else if (pServer != NULL)
pCmdUI->Enable (IsClipboardFormatAvailable (CF_SERVER) ||
IsClipboardFormatAvailable (CF_GROUP));
// Can paste item if a group is selected:
else if (pGroup != NULL)
pCmdUI->Enable (IsClipboardFormatAvailable (CF_ITEM));
}
// Else if item view is active:
else if (pView == GetItemView ())
{
// Can paste item if a group is selected:
if (pGroup != NULL)
pCmdUI->Enable (IsClipboardFormatAvailable (CF_ITEM));
// Otherwise can't paste anything:
else
pCmdUI->Enable (false);
}
// Can't paste into any other view, so disable:
else
pCmdUI->Enable (false);
}
}
break;
// Enable "Edit|New Server Connection" if document is not locked:
case ID_EDIT_NEWSERVER:
pCmdUI->Enable (!bDisableProjectEditOperations);
break;
// Enable "Edit|New Group" if document is not locked and a server
// is selected:
case ID_EDIT_NEWGROUP:
pCmdUI->Enable (!bDisableProjectEditOperations && pDoc->GetSelectedServer () != NULL);
break;
// Enable "Edit|Properties" if document is not locked and a server or
// or group is selected:
case ID_EDIT_PROPERTIES:
if (bDisableProjectEditOperations)
pCmdUI->Enable (false);
else
pCmdUI->Enable ((pDoc->GetSelectedServer () != NULL) ||
(pDoc->GetSelectedGroup () != NULL));
break;
// Enable "Edit|New Item" if document is not locked and a group
// is selected:
case ID_EDIT_NEWITEM:
pCmdUI->Enable (!bDisableProjectEditOperations && pDoc->GetSelectedGroup () != NULL);
break;
// Enable "View|Clear Messages" if the event view has messages in it:
case ID_VIEW_CLEAR:
pCmdUI->Enable (GetEventView ()->GetEventCount ());
break;
// Always enable "View|Log Errors Only". Check if event view's
// "log errors only" flag has been set:
case ID_VIEW_ERRORONLY:
pCmdUI->Enable (true);
pCmdUI->SetCheck (GetEventView ()->LogErrorsOnly ());
break;
// Enable "Tools|Server|Connect" if document is not locked, a
// server is selected, and that server in not presently connected:
case ID_TOOLS_CONNECT:
{
CKServer *pServer = pDoc->GetSelectedServer ();
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -