/************************************************************************
*
* Resource ID Organiser Core Library
*
* (c) Copyright 2000-2003 by Anna-Jayne Metcalfe (resorg@annasplace.me.uk)
* All rights reserved.
*
************************************************************************
*
* Filename : ResOrgCoreApp.cpp
*
* Description : CResOrgCoreApp - application base class to avoid
* duplication between the application classes in the ResOrgApp,
* ResOrgAddIn and ResOrgNETAddIn modules
*
* Compiler : Microsoft Visual C++ 6.0, Service Pack 3 or later
* Microsoft Visual C++ .NET 2002
*
* 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/ResOrgCore/ResOrgCoreApp.cpp $
* $Revision: 6 $
* $Date: 15/04/03 20:37 $
* $Author: Anna $
*
* $History: ResOrgCoreApp.cpp $
*
* ***************** Version 6 *****************
* User: Anna Date: 15/04/03 Time: 20:37
* Updated in $/Projects/AddIns/ResOrg/ResOrgCore
* 1. Removed unnecessary file guards (#pragma once works well enough)
* 2. Updated file banners
*
* ***************** Version 5 *****************
* User: Anna Date: 26/03/03 Time: 14:09
* Updated in $/Projects/AddIns/ResOrg/ResOrgCore
* Added CResOrgSymbolsDocMultiFile::GetDisplayTitle() to choose the title
* displayed for a multi-file Symbols Display
*
* ***************** Version 4 *****************
* User: Anna Date: 3/03/03 Time: 23:30
* Updated in $/Projects/AddIns/ResOrg/ResOrgCore
* CResOrgCoreApp::OpenHtmlView() no longer twiddles the view directly -
* it asks the document to it instead
*
* ***************** Version 3 *****************
* User: Anna Date: 15/02/03 Time: 20:53
* Updated in $/Projects/AddIns/ResOrg/ResOrgCore
* Commenting changes only
*
* ***************** Version 2 *****************
* User: Anna Date: 30/01/03 Time: 21:05
* Updated in $/Projects/AddIns/ResOrg/ResOrgCore
* Moved common application class functionality to CResOrgCoreApp
*
* ***************** Version 1 *****************
* User: Anna Date: 30/01/03 Time: 19:51
* Created in $/Projects/AddIns/ResOrg/ResOrgCore
*
* $Nokeywords: $
*
************************************************************************/
#include "StdAfx.h"
#include <AfxHtml.h>
#include "ResOrgCore_Res.h"
#include "ResOrgSplashWnd.h"
#include "ResOrgSymbolsDoc.h"
#include "ResOrgHtmlDoc.h"
#include "ResOrgSymbolsDocMultiFile.h"
#include "ResOrgOptions.h"
#include "ResOrgCoreApp.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CResOrgCoreApp
BEGIN_MESSAGE_MAP(CResOrgCoreApp, CResOrgCoreApp_BASE)
//{{AFX_MSG_MAP(CResOrgCoreApp)
ON_COMMAND( ID_RESORG_OPTIONS, OnCmdOptions)
ON_COMMAND( ID_WINDOW_CLOSE_ALL, OnCmdWindowCloseAll)
ON_UPDATE_COMMAND_UI( ID_WINDOW_CLOSE_ALL, OnUpdateWindowCloseAll)
ON_COMMAND( ID_RESORG_WEB, OnCmdResOrgWebsite)
ON_COMMAND( ID_RESORG_WEB_FAQ, OnCmdResOrgFAQ)
ON_UPDATE_COMMAND_UI( ID_RESORG_WEB_FAQ, OnUpdateResOrgFAQ)
ON_COMMAND( ID_RESORG_WEB_DISCUSSIONS, OnCmdResOrgDiscussionBoard)
ON_UPDATE_COMMAND_UI( ID_RESORG_WEB_DISCUSSIONS, OnUpdateResOrgDiscussionBoard)
ON_COMMAND( ID_RESORG_WEB_BUGS, OnCmdResOrgKnownBugs)
ON_UPDATE_COMMAND_UI( ID_RESORG_WEB_BUGS, OnUpdateResOrgKnownBugs)
ON_COMMAND( ID_RESORG_MAILING_LIST, OnCmdResOrgMailingList)
ON_UPDATE_COMMAND_UI( ID_RESORG_MAILING_LIST, OnUpdateResOrgMailingList)
//}}AFX_MSG_MAP
ON_COMMAND( ID_HELP_FINDER, CResOrgCoreApp_BASE::OnHelpFinder)
ON_COMMAND( ID_HELP, CResOrgCoreApp_BASE::OnHelp)
ON_COMMAND( ID_CONTEXT_HELP, CResOrgCoreApp_BASE::OnContextHelp)
ON_COMMAND( ID_DEFAULT_HELP, CResOrgCoreApp_BASE::OnHelpFinder)
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CResOrgCoreApp construction/destruction
CResOrgCoreApp::CResOrgCoreApp(void)
{
m_pwndSplash = NULL;
m_pMultiSymbolFileTemplate = NULL;
m_pHtmlDocTemplate = NULL;
m_dwSplashTime = 0;
m_bCheckNextSymbolValues = TRUE;
}
CResOrgCoreApp::~CResOrgCoreApp(void)
{
if (NULL != m_pwndSplash)
{
delete m_pwndSplash;
}
if (NULL != m_pMultiSymbolFileTemplate)
{
delete m_pMultiSymbolFileTemplate;
}
if (NULL != m_pHtmlDocTemplate)
{
delete m_pHtmlDocTemplate;
}
}
/////////////////////////////////////////////////////////////////////////////
// CResOrgCoreApp virtual overrides
/// Override of CWinApp::OpenDocumentFile() to implement the
/// "Warn if the Next Symbol values of a file are in use" option
///
CDocument* CResOrgCoreApp::OpenDocumentFile(LPCTSTR lpszFileName)
{
CDocument* pDoc = CResOrgCoreApp_BASE::OpenDocumentFile(lpszFileName);
if ( (NULL != pDoc) && Options.WarnIfNextSymbolValuesInUse() && m_bCheckNextSymbolValues)
{
CResOrgSymbolsDoc* pSymDoc = DYNAMIC_DOWNCAST( CResOrgSymbolsDoc,
pDoc);
if (NULL != pSymDoc)
{
pSymDoc->CheckNextSymbolValues();
}
}
return pDoc;
}
/////////////////////////////////////////////////////////////////////////////
// CResOrgCoreApp operations
/// Prompt the user to ask whether all open windows should be closed
//
/// \return IDYES (yes), IDNO (no) or IDCANCEL (cancel)
//
int CResOrgCoreApp::DoCloseAllWindowsQuery(void)
{
BOOL bResult = FALSE;
int nOpenDocs = m_pDocManager->GetOpenDocumentCount();
if (nOpenDocs > 0)
{
int eResult = ::AfxMessageBox( IDP_RESORG_CLOSE_ALL_QUERY,
MB_ICONEXCLAMATION | MB_YESNOCANCEL | MB_DEFBUTTON1);
switch (eResult)
{
case IDYES:
CloseOpenDocuments();
bResult = TRUE;
break;
case IDNO:
bResult = TRUE;
break;
case IDCANCEL:
break;
}
}
else
{
bResult = TRUE;
}
return bResult;
}
/// Show the ResOrg splash screen
//
void CResOrgCoreApp::ShowSplashScreen(void)
{
m_pwndSplash = new CResOrgSplashWnd;
if (!m_pMainWnd->IsIconic() && m_pwndSplash->Create(m_pMainWnd))
{
m_pwndSplash->ShowWindow(SW_SHOW);
m_pwndSplash->UpdateWindow();
}
m_dwSplashTime = ::GetTickCount();
m_pMainWnd->UpdateWindow();
}
/// Close the ResOrg splash screen
//
void CResOrgCoreApp::KillSplashScreen(void)
{
if ( (NULL != m_pwndSplash) && (NULL != m_pwndSplash->GetSafeHwnd()) )
{
m_pwndSplash->DestroyWindow();
delete m_pwndSplash;
m_pwndSplash = NULL;
m_pMainWnd->UpdateWindow();
}
}
/// Open a multi-file Symbols Display containing the contents of the specified files
//
/// \param arraySymbolFilePathNames A string array containing the pathnames of the files to open
/// \param sTitle The title of the view. If blank, a default title will be used
//
void CResOrgCoreApp::OpenMultiFileSymbolsView( const CStringArray& arraySymbolFilePathNames,
const CString& sTitle /*= _T("")*/ )
{
ASSERT(NULL != m_pMultiSymbolFileTemplate);
if ( (NULL != m_pMultiSymbolFileTemplate) && (arraySymbolFilePathNames.GetSize() > 0) )
{
CDocument* pDoc = m_pMultiSymbolFileTemplate->CreateNewDocument();
if (pDoc != NULL)
{
if (!sTitle.IsEmpty() )
{
pDoc->SetTitle(sTitle);
}
else
{
pDoc->SetTitle( CResOrgSymbolsDocMultiFile::GetDisplayTitle(arraySymbolFilePathNames) );
}
CFrameWnd* pFrame = m_pMultiSymbolFileTemplate->CreateNewFrame(pDoc, NULL);
if (pFrame == NULL)
{
TRACE0("Warning: failed to create new frame.\n");
AfxMessageBox(AFX_IDP_COMMAND_FAILURE, MB_OK | MB_ICONSTOP);
return; // command failed
}
pDoc->DeleteContents();
static_cast<CResOrgSymbolsDocMultiFile*>(pDoc)->AddFiles(arraySymbolFilePathNames);
m_pMultiSymbolFileTemplate->InitialUpdateFrame(pFrame, pDoc);
}
}
}
/// Open an HTML view with the specified title and URL
//
/// \param sTitle The title of the view
/// \param sURL The URL to open
//
void CResOrgCoreApp::OpenHtmlView( const CString& sTitle,
const CString& sURL)
{
ASSERT(NULL != m_pHtmlDocTemplate);
if (NULL != m_pHtmlDocTemplate)
{
CDocument* pDoc = m_pHtmlDocTemplate->CreateNewDocument();
if (pDoc != NULL)
{
pDoc->SetTitle(sTitle);
CFrameWnd* pFrame = m_pHtmlDocTemplate->CreateNewFrame(pDoc, NULL);
if (pFrame == NULL)
{
TRACE0("Warning: failed to create new frame.\n");
AfxMessageBox(AFX_IDP_COMMAND_FAILURE, MB_OK | MB_ICONSTOP);
return; // command failed
}
m_pHtmlDocTemplate->InitialUpdateFrame(pFrame, pDoc);
static_cast<CResOrgHtmlDoc*>(pDoc)->SetUrl(sURL);
}
}
}
/// Close all open documents
//
bool CResOrgCoreApp::CloseOpenDocuments(void)
{
bool bResult = true;
CNGDocEnumerator docs;
CDocument* pDoc = NULL;
do
{
pDoc = docs.GetNextDoc();
if (NULL != pDoc)
{
if (pDoc->SaveModified() )
{
pDoc->OnCloseDocument();
}
else
{
bResult = false;
break;
}
}
} while (NULL != pDoc);
CloseOpenDocuments(m_pMultiSymbolFileTemplate);
CloseOpenDocuments(m_pHtmlDocTemplate);
return bResult;
}
/// Close all open documents belonging to the specified document template
//
/// \param pTemplate A pointer to the document template
/// \return true if all documents were closed sucessfully, false otherwise
//
bool CResOrgCoreApp::CloseOpenDocuments(CMultiDocTemplate* pTemplate)
{
bool bResult = true;
if (NULL != pTemplate)
{
POSITION pos = pTemplate->GetFirstDocPosition();
while (NULL != pos)
{
CDocument* pDoc = pTemplate->GetNextDoc(pos);
if (NULL != pDoc)
{
if (pDoc->SaveModified() )
{
pDoc->OnCloseDocument();
}
else
{
bResult = false;
}
}
}
}
return bResult;
}
/////////////////////////////////////////////////////////////////////////////
// CResOrgCoreApp implementation
/////////////////////////////////////////////////////////////////////////////
// CResOrgCoreApp command handlers
/// Handler for the ID_RESORG_OPTIONS command
///
/// Open the "Options" property sheet
//
void CResOrgCoreApp::OnCmdOptions(void)
{
Options.Configure();
}
/// Handler for the ID_WINDOW_CLOSE_ALL command
///
/// Close all open views
//
void CResOrgCoreApp::OnCmdWindowCloseAll(void)
{
CloseOpenDocuments();
}
/// UI Update handler for the ID_WINDOW_CLOSE_ALL command
//
void CResOrgCoreApp::OnUpdateWindowCloseAll(CCmdUI* pCmdUI)
{
int nOpenDocs = m_pDocManager->GetOpenDocumentCount();
if (0 == nOpenDocs)
{
POSITION pos = m_pHtmlDocTemplate->GetFirstDocPosition();
if (NULL != pos)
{
if (NULL != m_pHtmlDocTemplate->GetNextDoc(pos) )
{
nOpenDocs++; // Force command to be available
}
}
}
pCmdUI->Enable(nOpenDocs > 0);
}
/// Handler for the ID_RESORG_WEB command
///
/// Open the homepage of the ResOrg website in an HTML view
//
void CResOrgCoreApp::OnCmdResOrgWebsite(void)
{
CString sTitle;
sTitle.LoadString(IDP_RESORG_WEB_TITLE);
OpenHtmlView(sTitle, Options.GetWebURL() );
}
/// Handler for the ID_RESORG_WEB_FAQ command
///
/// Open the ResOrg FAQ page in an HTML view
//
void CResOrgCoreApp::OnCmdResOrgFAQ(void)
{
CString sTitle;
sTitle.LoadString(IDP_RESORG_FAQ_TITLE);
OpenHtmlView(sTitle, Options.GetFaqURL() );
}
/// UI update handler for the ID_RESORG_WEB_FAQ command
//
void CResOrgCoreApp::OnUpdateResOrgFAQ(CCmdUI* pCmdUI)
{
pCmdUI->Enable( !Options.GetFaqURL().IsEmpty() );
}
/// Handler for the ID_RESORG_WEB_DISCUSSIONS command
///
/// Open the ResOrg MSN Group in an HTML view
//
void CResOrgCoreApp::OnCmdResOrgDiscussionBoard(void)
{
CString sTitle;
sTitle.LoadString(IDP_RESORG_DISCUSSIONS_TITLE);
OpenHtmlView(sTitle, Options.GetDiscussionBoardURL() );
}
/// UI update handler for the ID_RESORG_WEB_DISCUSSIONS command
//
void CResOrgCoreApp::OnUpdateResOrgDiscussionBoard(CCmdUI* pCmdUI)
{
pCmdUI->Enable( !Options.GetDiscussionBoardURL().IsEmpty() );
}
/// Handler for the ID_RESORG_WEB_BUGS command
///
/// Open the Known Bugs page (in the ResOrg MSN Group) in an HTML view
///
void CResOrgCoreApp::OnCmdResOrgKnownBugs(void)
{
CString sTitle;
sTitle.LoadString(IDP_RESORG_KNOWN_BUGS_TITLE);
OpenHtmlView(sTitle, Options.GetKnownBugsURL() );
}
/// UI update handler for the ID_RESORG_WEB_BUGS command
///
void CResOrgCoreApp::OnUpdateResOrgKnownBugs(CCmdUI* pCmdUI)
{
pCmdUI->Enable( !Options.GetKnownBugsURL().IsEmpty() );
}
/// Handler for the ID_RESORG_MAILING_LIST command
///
/// Open the Mailing List subscribe/unsubscribe page in an HTML view
///
void CResOrgCoreApp::OnCmdResOrgMailingList(void)
{
CString sTitle;
sTitle.LoadString(IDP_RESORG_MAILING_LIST);
OpenHtmlView(sTitle, Options.GetMailingListURL() );
}
/// UI update handler for the ID_RESORG_MAILING_LIST command
///
void CResOrgCoreApp::OnUpdateResOrgMailingList(CCmdUI* pCmdUI)
{
pCmdUI->Enable( !Options.GetMailingListURL().IsEmpty() );
}