/************************************************************************
*
* Resource ID Organiser Add-In
*
* (c) Copyright 2000-2002 by Anna-Jayne Metcalfe (resorg@annasplace.me.uk)
* All rights reserved.
*
************************************************************************
*
* Filename : MainFrame.cpp
*
* Description : CMainFrame - MDI main frame window class
*
* Compiler : Microsoft Visual C++ 6.0, Service Pack 3 or later
*
* Target
* Environment : Windows 98/NT/2000/XP
*
* NOTE:
*
* This software is provided "as is" free for personal use. All
* title and copyrights in and to the software, including but not
* limited to any images, text, etc. incorporated into it, are
* owned by Anna-Jayne Metcalfe, except where acknowledged otherwise.
*
* Your may freely to use this code in your own products, PROVIDED
* this notice is not removed or modified.
*
*
* Visit http://www.annasplace.me.uk/resorg for latest updates
*
************************************************************************
*
* MODIFICATION HISTORY:
*
* This is a controlled document. See project configuration
* control tool for latest version and full version history.
*
* $Archive: /Projects/AddIns/ResOrg/ResOrgAddIn/MainFrame.cpp $
* $Revision: 16 $
* $Date: 25/11/02 16:52 $
* $Author: Anna $
*
* $History: MainFrame.cpp $
*
* ***************** Version 16 *****************
* User: Anna Date: 25/11/02 Time: 16:52
* Updated in $/Projects/AddIns/ResOrg/ResOrgAddIn
* Changed website address in banner
*
* ***************** Version 15 *****************
* User: Anna Date: 22/10/02 Time: 13:34
* Updated in $/Projects/AddIns/ResOrg/ResOrgAddIn
* Changed name/mail address (at last!)
*
* ***************** Version 14 *****************
* User: Andy Date: 2/08/02 Time: 17:03
* Updated in $/Projects/AddIns/ResOrg/ResOrgAddIn
* Renamed CWorkspaceHelper to CVc6AutomationHelper, and moved it to the
* ResOrgCore module
*
* ***************** Version 13 *****************
* User: Andy Date: 1/24/02 Time: 11:35p
* Updated in $/Projects/AddIns/ResOrg/ResOrgAddIn
* CMainFrame::DoModal() in the add-in now shows the workspace if
* necessary
*
* ***************** Version 12 *****************
* User: Andy Date: 1/18/02 Time: 10:41p
* Updated in $/Projects/AddIns/ResOrg/ResOrgAddIn
* Enabled "flat look" for the workspace
*
* ***************** Version 11 *****************
* User: Andy Date: 2/06/01 Time: 16:51
* Updated in $/Projects/AddIns/ResOrg/ResOrgAddIn
* Moved common functionality to a new class (CResOrgMDIFrameWnd) in
* ResOrgUtils
*
* ***************** Version 10 *****************
* User: Andy Date: 26/05/01 Time: 21:01
* Updated in $/Projects/AddIns/ResOrg/ResOrgAddIn
* Cleaned up DoModal() a bit
*
* ***************** Version 9 *****************
* User: Andy Date: 26/05/01 Time: 17:22
* Updated in $/Projects/AddIns/ResOrg/ResOrgAddIn
* 1. Removed help message handlers (these have been moved to the app)
* 2. Set the ID of the Projects View so we can link in the topic for
* context help
*
* ***************** Version 8 *****************
* User: Andy Date: 22/05/01 Time: 7:00
* Updated in $/Projects/AddIns/ResOrg/ResOrgAddIn
* OnCmdMsg() now routes messages to the "Options" global helper
*
* ***************** Version 7 *****************
* User: Andy Date: 26/04/01 Time: 19:40
* Updated in $/Projects/AddIns/ResOrg/ResOrgAddIn
* Renamed Resource.h to ResOrgAddIn_Res.h
*
* ***************** Version 6 *****************
* User: Andy Date: 2/04/01 Time: 17:51
* Updated in $/Projects/AddIns/ResOrg/ResOrgAddIn
* Use CResOrgSymbolsDoc::GetSymbolBuffer() instead of accessing directly
*
* ***************** Version 5 *****************
* User: Andy Date: 5/03/01 Time: 19:03
* Updated in $/Projects/AddIns/ResOrg/ResOrgAddIn
* Added "Close All" command to the Window menu
*
* ***************** Version 4 *****************
* User: Andy Date: 2/03/01 Time: 17:33
* Updated in $/Projects/AddIns/ResOrg/ResOrgAddIn
* Removed unnecessary code
*
* ***************** Version 3 *****************
* User: Andy Date: 17/02/01 Time: 7:07
* Updated in $/Projects/AddIns/ResOrg/ResOrgAddIn
* CResOrgSymbolsView => CResOrgSymbolsListView
*
* ***************** Version 2 *****************
* User: Andy Date: 29/11/00 Time: 18:36
* Updated in $/Projects/AddIns/ResOrg/ResOrgAddIn
* 1. CMainFrame::OnClose() now saves modified files if necessary
* 2. Added file banner
*
* $Nokeywords: $
*
************************************************************************/
// MainFrame.cpp : implementation of the CMainFrame class
//
#include "StdAfx.h"
#include <afxpriv.h> // For WM_KICKIDLE
#include "ResOrgAddIn_Res.h"
#include "ResOrgAddInApp.h" // For CWorkspaceHelper extern declaration
#include "ResOrgProjectsDoc.h"
#include "ResOrgProjectsView.h"
#include "MainFrame.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CMainFrame
IMPLEMENT_DYNCREATE(CMainFrame, CMainFrame_BASE)
BEGIN_MESSAGE_MAP(CMainFrame, CMainFrame_BASE)
//{{AFX_MSG_MAP(CMainFrame)
ON_MESSAGE( WM_KICKIDLE, OnKickIdle)
ON_WM_CREATE()
ON_WM_CLOSE()
//}}AFX_MSG_MAP
ON_COMMAND_EX( ID_VIEW_WORKSPACE, OnBarCheck)
ON_UPDATE_COMMAND_UI( ID_VIEW_WORKSPACE, OnUpdateControlBarMenu)
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CMainFrame construction/destruction
CMainFrame::CMainFrame(void)
{
m_pProjectsDoc = NULL;
}
CMainFrame::~CMainFrame(void)
{
}
/////////////////////////////////////////////////////////////////////////////
// CMainFrame virtual overrides
int CMainFrame::DoModal(HWND hWndDevStudio)
{
// Disable parent (before creating window)
PreModal();
BOOL bEnableParent = FALSE;
BOOL bMaximised = FALSE;
BOOL bActive = FALSE;
if ( (hWndDevStudio != NULL) && ::IsWindowEnabled(hWndDevStudio) )
{
bMaximised = ::IsZoomed(hWndDevStudio) ;
bActive = (::GetActiveWindow() == hWndDevStudio);
::ShowWindow(hWndDevStudio, SW_HIDE);
::EnableWindow(hWndDevStudio, FALSE);
bEnableParent = TRUE;
}
try
{
// Refresh the workspace
m_pProjectsDoc->UpdateAllViews(NULL, SHOW_WORKSPACE);
if (Options.AutoHideWorkspace())
{
ShowWorkspace(Workspace.GetProjectCount() > 0);
}
else
{
ShowWorkspace(TRUE);
}
// Show window
ShowWindow(bMaximised ? SW_SHOWMAXIMIZED : SW_SHOWNORMAL);
// Get the size/position of the DevStudio main window and use them
WINDOWPLACEMENT wndPlacement;
if (::GetWindowPlacement(hWndDevStudio, &wndPlacement) )
{
::SetWindowPlacement(m_hWnd, &wndPlacement);
}
RunModalLoop(MLF_SHOWONIDLE);
// Hide the window before enabling the parent, etc.
if (m_hWnd != NULL)
{
ShowWindow(SW_HIDE);
}
}
catch (CException* e)
{
e->Delete();
m_nModalResult = -1;
}
// Get the workspace to clear and release it's IProject pointers
m_pProjectsDoc->UpdateAllViews(NULL, CLEAR_WORKSPACE);
if (hWndDevStudio != NULL)
{
if (bEnableParent)
{
::ShowWindow(hWndDevStudio, bMaximised ? SW_SHOWMAXIMIZED : SW_SHOWNORMAL);
::EnableWindow(hWndDevStudio, TRUE);
}
if (bActive)
{
::SetActiveWindow(hWndDevStudio);
}
}
PostModal();
// Close all symbol documents
// Note that the "Projects" document is unaffected
AfxGetApp()->CloseAllDocuments(FALSE);
// unlock/free resources as necessary
return m_nModalResult;
}
void CMainFrame::PreModal(void)
{
// Allow OLE servers to disable themselves
CWinApp* pApp = AfxGetApp();
if (pApp != NULL)
{
pApp->EnableModeless(FALSE);
}
}
void CMainFrame::PostModal(void)
{
// R-enable windows
if (::IsWindow(m_hWndTop))
{
::EnableWindow(m_hWndTop, TRUE);
}
m_hWndTop = NULL;
CWinApp* pApp = AfxGetApp();
if (pApp != NULL)
{
pApp->EnableModeless(TRUE);
}
}
BOOL CMainFrame::OnCmdMsg(UINT nID, int nCode, void* pExtra, AFX_CMDHANDLERINFO* pHandlerInfo)
{
if (CMainFrame_BASE::OnCmdMsg(nID, nCode, pExtra, pHandlerInfo) )
{
return TRUE;
}
return m_wndWorkspace.OnCmdMsg(nID, nCode, pExtra, pHandlerInfo);
}
/////////////////////////////////////////////////////////////////////////////
// CMainFrame operations
void CMainFrame::ShowWorkspace(BOOL bShow)
{
ShowControlBar(&m_wndWorkspace, bShow, FALSE);
}
/////////////////////////////////////////////////////////////////////////////
// CMainFrame diagnostics
#ifdef _DEBUG
void CMainFrame::AssertValid(void) const
{
CMainFrame_BASE::AssertValid();
}
void CMainFrame::Dump(CDumpContext& dc) const
{
CMainFrame_BASE::Dump(dc);
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// CMainFrame implementation
// (none)
/////////////////////////////////////////////////////////////////////////////
// CMainFrame message handlers
int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
int nResult = CMainFrame_BASE::OnCreate(lpCreateStruct);
if (-1 != nResult)
{
// Create the "Workspace" docking window.
//
// Initialise m_wndWorkspace control bar
if( !m_wndWorkspace.Create(this, ID_VIEW_WORKSPACE,
_T("Workspace"), CSize(225,100), CBRS_LEFT ))
{
TRACE0("Failed to create dialog bar m_wndWorkspace\n");
return -1; // fail to create
}
m_wndWorkspace.EnableFlatLook();
// Create the document for each of the tab views, then add the
// document / view to the tab control. This is a very simple implementation.
// you could go further and actually create a document template for each tab,
// and add it to the app. If so, you would pass in m_pMyDocTemplate->CreateNewDocument(),
// instead of dynamically allocating a pointer for each document as shown here.
// This was done for simplicity.
//
// "Projects" tab (the only one at present)
m_pProjectsDoc = new CResOrgProjectsDoc;
ASSERT_KINDOF( CDocument, m_pProjectsDoc );
m_wndWorkspace.AddView( _T( "Projects" ), RUNTIME_CLASS( CResOrgProjectsView ), m_pProjectsDoc );
// Define the image list to use with the tab control
m_TabImages.Create( IDB_WORKSPACE_TABS, 16, 1, RGB( 0, 255, 0 ));
m_wndWorkspace.SetTabImageList( &m_TabImages );
m_wndWorkspace.EnableDockingOnSizeBar( CBRS_ALIGN_ANY );
EnableDockingSizeBar( CBRS_ALIGN_ANY );
DockSizeBar( &m_wndWorkspace );
// Set the popoup menu id.
m_wndWorkspace.SetMenuID( IDR_MAINFRAME, NULL, 1 );
// Set the ID of the view so we can link in the topic
// for context help
//
// Note that this has to be a command (ID_) or the
// wrong help context ID will be generated by the
// framework (this only happens because the view
// is inside a control bar)
CView* pView = m_wndWorkspace.GetView(0);
if (NULL != pView)
{
pView->SetDlgCtrlID(ID_DISPLAY_WORKSPACE);
}
// Restore the previous bar and window states.
LoadBarState(_T("Bar State"));
}
return nResult;
}
void CMainFrame::OnClose(void)
{
CWinApp* pApp = AfxGetApp();
if ( (NULL != pApp) && (this == pApp->m_pMainWnd) )
{
// Attempt to save all modified documents
if (!pApp->SaveAllModified())
{
return; // Don't close just yet
}
}
// Save the bar and window states.
m_state.SaveWindowPos(this);
SaveBarState(_T("Bar State"));
m_nModalResult = IDOK;
EndModalLoop(m_nModalResult);
}
// Handle MFC private message WM_KICKIDLE. LPARAM is the idle count.
// Return TRUE/FALSE continue/discontinue idle processing.
LRESULT CMainFrame::OnKickIdle(WPARAM, LPARAM lCount)
{
return AfxGetApp()->OnIdle(lCount);
}