This commit is contained in:
Glenn Maynard
2005-06-03 23:42:07 +00:00
parent a4e5d038d2
commit 2d644e67af
4 changed files with 70 additions and 69 deletions
+51 -51
View File
@@ -10,44 +10,44 @@
#include "Selector_Dialog.h" #include "Selector_Dialog.h"
DialogDriver *MakeDialogDriver() DialogDriver *MakeDialogDriver()
{ {
CString drivers = "win32,cocoa,null"; CString sDrivers = "win32,cocoa,null";
CStringArray DriversToTry; CStringArray asDriversToTry;
split(drivers, ",", DriversToTry, true); split( sDrivers, ",", asDriversToTry, true );
ASSERT( DriversToTry.size() != 0 ); ASSERT( asDriversToTry.size() != 0 );
CString Driver; CString sDriver;
DialogDriver *ret = NULL; DialogDriver *pRet = NULL;
for( unsigned i = 0; ret == NULL && i < DriversToTry.size(); ++i ) for( unsigned i = 0; pRet == NULL && i < asDriversToTry.size(); ++i )
{ {
Driver = DriversToTry[i]; sDriver = asDriversToTry[i];
#ifdef USE_DIALOG_DRIVER_COCOA #ifdef USE_DIALOG_DRIVER_COCOA
if( !DriversToTry[i].CompareNoCase("Cocoa") ) ret = new DialogDriver_Cocoa; if( !asDriversToTry[i].CompareNoCase("Cocoa") ) pRet = new DialogDriver_Cocoa;
#endif #endif
#ifdef USE_DIALOG_DRIVER_NULL #ifdef USE_DIALOG_DRIVER_NULL
if( !DriversToTry[i].CompareNoCase("Null") ) ret = new DialogDriver_Null; if( !asDriversToTry[i].CompareNoCase("Null") ) pRet = new DialogDriver_Null;
#endif #endif
#ifdef USE_DIALOG_DRIVER_WIN32 #ifdef USE_DIALOG_DRIVER_WIN32
if( !DriversToTry[i].CompareNoCase("Win32") ) ret = new DialogDriver_Win32; if( !asDriversToTry[i].CompareNoCase("Win32") ) pRet = new DialogDriver_Win32;
#endif #endif
if( ret == NULL ) if( pRet == NULL )
{ {
continue; continue;
} }
CString sError = ret->Init(); CString sError = pRet->Init();
if( sError != "" ) if( sError != "" )
{ {
if( LOG ) if( LOG )
LOG->Info( "Couldn't load driver %s: %s", DriversToTry[i].c_str(), sError.c_str() ); LOG->Info( "Couldn't load driver %s: %s", asDriversToTry[i].c_str(), sError.c_str() );
SAFE_DELETE( ret ); SAFE_DELETE( pRet );
} }
} }
return ret; return pRet;
} }
static DialogDriver *g_pImpl = NULL; static DialogDriver *g_pImpl = NULL;
@@ -77,53 +77,53 @@ bool Dialog::IsShowingDialog()
return g_bIsShowingDialog; return g_bIsShowingDialog;
} }
static bool MessageIsIgnored( CString ID ) static bool MessageIsIgnored( CString sID )
{ {
vector<CString> list; vector<CString> asList;
split( PREFSMAN->m_sIgnoredMessageWindows, ",", list ); split( PREFSMAN->m_sIgnoredMessageWindows, ",", asList );
for( unsigned i = 0; i < list.size(); ++i ) for( unsigned i = 0; i < asList.size(); ++i )
if( !ID.CompareNoCase(list[i]) ) if( !sID.CompareNoCase(asList[i]) )
return true; return true;
return false; return false;
} }
void Dialog::IgnoreMessage( CString ID ) void Dialog::IgnoreMessage( CString sID )
{ {
/* We can't ignore messages before PREFSMAN is around. */ /* We can't ignore messages before PREFSMAN is around. */
if( PREFSMAN == NULL ) if( PREFSMAN == NULL )
{ {
if( ID != "" && LOG ) if( sID != "" && LOG )
LOG->Warn( "Dialog: message \"%s\" set ID too early for ignorable messages", ID.c_str() ); LOG->Warn( "Dialog: message \"%s\" set ID too early for ignorable messages", sID.c_str() );
return; return;
} }
if( ID == "" ) if( sID == "" )
return; return;
if( MessageIsIgnored(ID) ) if( MessageIsIgnored(sID) )
return; return;
vector<CString> list; vector<CString> asList;
split( PREFSMAN->m_sIgnoredMessageWindows, ",", list ); split( PREFSMAN->m_sIgnoredMessageWindows, ",", asList );
list.push_back( ID ); asList.push_back( sID );
PREFSMAN->m_sIgnoredMessageWindows.Set( join(",",list) ); PREFSMAN->m_sIgnoredMessageWindows.Set( join(",",asList) );
PREFSMAN->SaveGlobalPrefsToDisk(); PREFSMAN->SaveGlobalPrefsToDisk();
} }
void Dialog::Error( CString sMessage, CString ID ) void Dialog::Error( CString sMessage, CString sID )
{ {
Dialog::Init(); Dialog::Init();
if( LOG ) if( LOG )
LOG->Trace( "Dialog: \"%s\" [%s]", sMessage.c_str(), ID.c_str() ); LOG->Trace( "Dialog: \"%s\" [%s]", sMessage.c_str(), sID.c_str() );
if( ID != "" && MessageIsIgnored( ID ) ) if( sID != "" && MessageIsIgnored(sID) )
return; return;
g_bIsShowingDialog = true; g_bIsShowingDialog = true;
g_pImpl->Error( sMessage, ID ); g_pImpl->Error( sMessage, sID );
g_bIsShowingDialog = false; g_bIsShowingDialog = false;
} }
@@ -133,69 +133,69 @@ void Dialog::SetWindowed( bool bWindowed )
g_bWindowed = bWindowed; g_bWindowed = bWindowed;
} }
void Dialog::OK( CString sMessage, CString ID ) void Dialog::OK( CString sMessage, CString sID )
{ {
Dialog::Init(); Dialog::Init();
if( LOG ) if( LOG )
LOG->Trace( "Dialog: \"%s\" [%s]", sMessage.c_str(), ID.c_str() ); LOG->Trace( "Dialog: \"%s\" [%s]", sMessage.c_str(), sID.c_str() );
if( ID != "" && MessageIsIgnored( ID ) ) if( sID != "" && MessageIsIgnored(sID) )
return; return;
g_bIsShowingDialog = true; g_bIsShowingDialog = true;
// only show Dialog if windowed // only show Dialog if windowed
if( !g_bWindowed ) if( !g_bWindowed )
g_NullDriver.OK( sMessage, ID ); g_NullDriver.OK( sMessage, sID );
else else
g_pImpl->OK( sMessage, ID ); // call derived version g_pImpl->OK( sMessage, sID ); // call derived version
g_bIsShowingDialog = false; g_bIsShowingDialog = false;
} }
Dialog::Result Dialog::AbortRetryIgnore( CString sMessage, CString ID ) Dialog::Result Dialog::AbortRetryIgnore( CString sMessage, CString sID )
{ {
Dialog::Init(); Dialog::Init();
if( LOG ) if( LOG )
LOG->Trace( "Dialog: \"%s\" [%s]", sMessage.c_str(), ID.c_str() ); LOG->Trace( "Dialog: \"%s\" [%s]", sMessage.c_str(), sID.c_str() );
if( ID != "" && MessageIsIgnored( ID ) ) if( sID != "" && MessageIsIgnored(sID) )
return g_NullDriver.AbortRetryIgnore( sMessage, ID ); return g_NullDriver.AbortRetryIgnore( sMessage, sID );
g_bIsShowingDialog = true; g_bIsShowingDialog = true;
// only show Dialog if windowed // only show Dialog if windowed
Dialog::Result ret; Dialog::Result ret;
if( !g_bWindowed ) if( !g_bWindowed )
ret = g_NullDriver.AbortRetryIgnore( sMessage, ID ); ret = g_NullDriver.AbortRetryIgnore( sMessage, sID );
else else
ret = g_pImpl->AbortRetryIgnore( sMessage, ID ); // call derived version ret = g_pImpl->AbortRetryIgnore( sMessage, sID ); // call derived version
g_bIsShowingDialog = false; g_bIsShowingDialog = false;
return ret; return ret;
} }
Dialog::Result Dialog::AbortRetry( CString sMessage, CString ID ) Dialog::Result Dialog::AbortRetry( CString sMessage, CString sID )
{ {
Dialog::Init(); Dialog::Init();
if( LOG ) if( LOG )
LOG->Trace( "Dialog: \"%s\" [%s]", sMessage.c_str(), ID.c_str() ); LOG->Trace( "Dialog: \"%s\" [%s]", sMessage.c_str(), sID.c_str() );
if( ID != "" && MessageIsIgnored( ID ) ) if( sID != "" && MessageIsIgnored(sID) )
return g_NullDriver.AbortRetry( sMessage, ID ); return g_NullDriver.AbortRetry( sMessage, sID );
g_bIsShowingDialog = true; g_bIsShowingDialog = true;
// only show Dialog if windowed // only show Dialog if windowed
Dialog::Result ret; Dialog::Result ret;
if( !g_bWindowed ) if( !g_bWindowed )
ret = g_NullDriver.AbortRetry( sMessage, ID ); ret = g_NullDriver.AbortRetry( sMessage, sID );
else else
ret = g_pImpl->AbortRetry( sMessage, ID ); // call derived version ret = g_pImpl->AbortRetry( sMessage, sID ); // call derived version
g_bIsShowingDialog = false; g_bIsShowingDialog = false;
+5 -5
View File
@@ -12,13 +12,13 @@ namespace Dialog
bool IsShowingDialog(); bool IsShowingDialog();
enum Result { abort, retry, ignore }; enum Result { abort, retry, ignore };
void Error( CString error, CString ID = "" ); void Error( CString sError, CString sID = "" );
void OK( CString sMessage, CString ID = "" ); void OK( CString sMessage, CString sID = "" );
Result AbortRetryIgnore( CString sMessage, CString ID = "" ); Result AbortRetryIgnore( CString sMessage, CString sID = "" );
Result AbortRetry( CString sMessage, CString ID = "" ); Result AbortRetry( CString sMessage, CString sID = "" );
/* for DialogDrivers */ /* for DialogDrivers */
void IgnoreMessage( CString ID ); void IgnoreMessage( CString sID );
}; };
#endif #endif
@@ -20,7 +20,7 @@ static BOOL CALLBACK OKWndProc( HWND hWnd, UINT msg, WPARAM wParam, LPARAM lPara
{ {
case WM_INITDIALOG: case WM_INITDIALOG:
{ {
// Disable parent, like a modal MessageBox does. // Disable the parent window, like a modal MessageBox does.
EnableWindow( GetParent(hWnd), FALSE ); EnableWindow( GetParent(hWnd), FALSE );
// Hide or display "Don't show this message." // Hide or display "Don't show this message."
@@ -65,14 +65,14 @@ static BOOL CALLBACK OKWndProc( HWND hWnd, UINT msg, WPARAM wParam, LPARAM lPara
} }
void DialogDriver_Win32::OK( CString sMessage, CString ID ) void DialogDriver_Win32::OK( CString sMessage, CString sID )
{ {
g_bAllowHush = ID != ""; g_bAllowHush = sID != "";
g_sMessage = sMessage; g_sMessage = sMessage;
AppInstance handle; AppInstance handle;
DialogBox( handle.Get(), MAKEINTRESOURCE(IDD_OK), GraphicsWindow::GetHwnd(), OKWndProc ); DialogBox( handle.Get(), MAKEINTRESOURCE(IDD_OK), GraphicsWindow::GetHwnd(), OKWndProc );
if( g_bAllowHush && g_bHush ) if( g_bAllowHush && g_bHush )
Dialog::IgnoreMessage( ID ); Dialog::IgnoreMessage( sID );
} }
static CString g_sErrorString; static CString g_sErrorString;
@@ -131,9 +131,10 @@ static BOOL CALLBACK ErrorWndProc( HWND hWnd, UINT msg, WPARAM wParam, LPARAM lP
return FALSE; return FALSE;
} }
void DialogDriver_Win32::Error( CString error, CString ID ) void DialogDriver_Win32::Error( CString sError, CString sID )
{ {
g_sErrorString = error; g_sErrorString = sError;
// throw up a pretty error dialog // throw up a pretty error dialog
AppInstance handle; AppInstance handle;
DialogBox( handle.Get(), MAKEINTRESOURCE(IDD_ERROR_DIALOG), NULL, ErrorWndProc ); DialogBox( handle.Get(), MAKEINTRESOURCE(IDD_ERROR_DIALOG), NULL, ErrorWndProc );
@@ -152,7 +153,7 @@ Dialog::Result DialogDriver_Win32::AbortRetryIgnore( CString sMessage, CString I
} }
} }
Dialog::Result DialogDriver_Win32::AbortRetry( CString sMessage, CString ID ) Dialog::Result DialogDriver_Win32::AbortRetry( CString sMessage, CString sID )
{ {
CString sWindowTitle = WINDOW_TITLE.IsLoaded() ? WINDOW_TITLE.GetValue() : ""; CString sWindowTitle = WINDOW_TITLE.IsLoaded() ? WINDOW_TITLE.GetValue() : "";
@@ -6,10 +6,10 @@
class DialogDriver_Win32: public DialogDriver class DialogDriver_Win32: public DialogDriver
{ {
public: public:
void Error( CString sMessage, CString ID ); void Error( CString sMessage, CString sID );
void OK( CString sMessage, CString ID ); void OK( CString sMessage, CString sID );
Dialog::Result AbortRetryIgnore( CString sMessage, CString ID ); Dialog::Result AbortRetryIgnore( CString sMessage, CString sID );
Dialog::Result AbortRetry( CString sMessage, CString ID ); Dialog::Result AbortRetry( CString sMessage, CString sID );
}; };
#define USE_DIALOG_DRIVER_WIN32 #define USE_DIALOG_DRIVER_WIN32