From 63b5dcf6da740344fa36eb52bad2aaef59d5dc5a Mon Sep 17 00:00:00 2001 From: Glenn Maynard Date: Mon, 7 Jul 2003 03:53:16 +0000 Subject: [PATCH] implement IgnoredMessageWindows for ArchHooks::MessageBoxOK --- stepmania/src/arch/ArchHooks/ArchHooks.h | 8 +- .../src/arch/ArchHooks/ArchHooks_Win32.cpp | 87 ++++++++++++++++++- .../src/arch/ArchHooks/ArchHooks_Win32.h | 7 +- 3 files changed, 94 insertions(+), 8 deletions(-) diff --git a/stepmania/src/arch/ArchHooks/ArchHooks.h b/stepmania/src/arch/ArchHooks/ArchHooks.h index a0a829d81a..17e76c0e36 100644 --- a/stepmania/src/arch/ArchHooks/ArchHooks.h +++ b/stepmania/src/arch/ArchHooks/ArchHooks.h @@ -28,10 +28,12 @@ public: * and we can safely log and throw. */ virtual void DumpDebugInfo() { } - /* Message box stuff. Not supported on all archs. */ + /* Message box stuff. Not supported on all archs. The ID can be used + * to identify a class of messages, for "don't display this dialog"-type + * prompts. */ enum MessageBoxResult { abort, retry, ignore }; - virtual void MessageBoxOK( CString sMessage ) {} - virtual MessageBoxResult MessageBoxAbortRetryIgnore( CString sMessage ) { return ignore; } + virtual void MessageBoxOK( CString sMessage, CString ID = "" ) {} + virtual MessageBoxResult MessageBoxAbortRetryIgnore( CString sMessage, CString ID = "" ) { return ignore; } virtual ~ArchHooks() { } }; diff --git a/stepmania/src/arch/ArchHooks/ArchHooks_Win32.cpp b/stepmania/src/arch/ArchHooks/ArchHooks_Win32.cpp index 3c0a5facbf..af93a0741c 100644 --- a/stepmania/src/arch/ArchHooks/ArchHooks_Win32.cpp +++ b/stepmania/src/arch/ArchHooks/ArchHooks_Win32.cpp @@ -1,6 +1,11 @@ #include "global.h" #include "ArchHooks_Win32.h" +#include "RageUtil.h" +#include "PrefsManager.h" +#include "resource.h" + +#include "archutils/win32/AppInstance.h" #include "archutils/win32/tls.h" #include "archutils/win32/crash.h" #include "archutils/win32/DebugInfoHunt.h" @@ -34,12 +39,88 @@ void ArchHooks_Win32::DumpDebugInfo() SearchForDebugInfo(); } -void ArchHooks_Win32::MessageBoxOK( CString sMessage ) +bool ArchHooks_Win32::MessageIsIgnored( CString ID ) { - MessageBox(NULL, sMessage, "StepMania", MB_OK ); + vector list; + split( PREFSMAN->m_sIgnoredMessageWindows, ",", list ); + for( unsigned i = 0; i < list.size(); ++i ) + if( !ID.CompareNoCase(list[i]) ) + return true; + return false; } -ArchHooks::MessageBoxResult ArchHooks_Win32::MessageBoxAbortRetryIgnore( CString sMessage ) +void ArchHooks_Win32::IgnoreMessage( CString ID ) +{ + if( MessageIsIgnored(ID) ) + return; + vector list; + split( PREFSMAN->m_sIgnoredMessageWindows, ",", list ); + list.push_back( ID ); + PREFSMAN->m_sIgnoredMessageWindows = join( ",", list ); + PREFSMAN->SaveGlobalPrefsToDisk(); +} + +static CString g_sMessage; +static bool g_AllowHush; +static bool g_Hush; +static BOOL CALLBACK OKWndProc( HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam ) +{ + switch( msg ) + { + case WM_INITDIALOG: + { + g_Hush = false; + CString sMessage = g_sMessage; + + sMessage.Replace( "\n", "\r\n" ); + HWND hush = GetDlgItem( hWnd, IDC_HUSH ); + int style = GetWindowLong(hush, GWL_STYLE); + + if( g_AllowHush ) + style |= WS_VISIBLE; + else + style &= ~WS_VISIBLE; + SetWindowLong( hush, GWL_STYLE, style ); + + SendDlgItemMessage( + hWnd, + IDC_MESSAGE, + WM_SETTEXT, + 0, + (LPARAM)(LPCTSTR)sMessage + ); + } + break; + case WM_COMMAND: + switch (LOWORD(wParam)) + { + case IDOK: + g_Hush = !!IsDlgButtonChecked(hWnd, IDC_HUSH); + /* fall through */ + case IDCANCEL: + EndDialog( hWnd, 0 ); + break; + } + } + return FALSE; +} + + + + +void ArchHooks_Win32::MessageBoxOK( CString sMessage, CString ID ) +{ + g_AllowHush = ID != ""; + if( g_AllowHush && MessageIsIgnored( ID ) ) + return; + g_sMessage = sMessage; + AppInstance handle; + DialogBox(handle.Get(), MAKEINTRESOURCE(IDD_OK), NULL, OKWndProc); + if( g_AllowHush && g_Hush ) + IgnoreMessage( ID ); +} + +ArchHooks::MessageBoxResult ArchHooks_Win32::MessageBoxAbortRetryIgnore( CString sMessage, CString ID ) { switch( MessageBox(NULL, sMessage, "StepMania", MB_ABORTRETRYIGNORE ) ) { diff --git a/stepmania/src/arch/ArchHooks/ArchHooks_Win32.h b/stepmania/src/arch/ArchHooks/ArchHooks_Win32.h index a9d9d1f546..6284fec7e2 100644 --- a/stepmania/src/arch/ArchHooks/ArchHooks_Win32.h +++ b/stepmania/src/arch/ArchHooks/ArchHooks_Win32.h @@ -4,13 +4,16 @@ #include "ArchHooks.h" class ArchHooks_Win32: public ArchHooks { + bool MessageIsIgnored( CString ID ); + void IgnoreMessage( CString ID ); + public: ArchHooks_Win32(); void Log(CString str, bool important); void DumpDebugInfo(); void AdditionalLog(CString str); - void MessageBoxOK( CString sMessage ); - MessageBoxResult MessageBoxAbortRetryIgnore( CString sMessage ); + void MessageBoxOK( CString sMessage, CString ID ); + MessageBoxResult MessageBoxAbortRetryIgnore( CString sMessage, CString ID ); }; #undef ARCH_HOOKS