X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/a5e0e655cb829a0112e1eecdf9ce4bede79cae80..520e470fdd0daef09c77938db642e4583933c90d:/src/msw/app.cpp diff --git a/src/msw/app.cpp b/src/msw/app.cpp index e7a3e6210b..7d5b43fe2c 100644 --- a/src/msw/app.cpp +++ b/src/msw/app.cpp @@ -10,14 +10,14 @@ ///////////////////////////////////////////////////////////////////////////// #ifdef __GNUG__ - #pragma implementation "app.h" +#pragma implementation "app.h" #endif // For compilers that support precompilation, includes "wx.h". #include "wx/wxprec.h" #if defined(__BORLANDC__) - #pragma hdrstop +#pragma hdrstop #endif #ifndef WX_PRECOMP @@ -36,11 +36,10 @@ #endif #include "wx/msw/private.h" -#include "wx/postscrp.h" #include "wx/log.h" #include "wx/module.h" -#if USE_WX_RESOURCES +#if wxUSE_WX_RESOURCES #include "wx/resource.h" #endif @@ -52,6 +51,8 @@ #endif // use debug CRT functions for memory leak detections in VC++ +/* Here we go again commenting it out. PLEASE don't + * uncomment this again. #if defined(__WXDEBUG__) && defined(_MSC_VER) // VC++ uses this macro as debug/release mode indicator #ifndef _DEBUG @@ -60,6 +61,7 @@ #include #endif +*/ extern char *wxBuffer; extern char *wxOsVersion; @@ -96,6 +98,8 @@ LRESULT APIENTRY wxWndProc(HWND, UINT, WPARAM, LPARAM); BEGIN_EVENT_TABLE(wxApp, wxEvtHandler) EVT_IDLE(wxApp::OnIdle) + EVT_END_SESSION(wxApp::OnEndSession) + EVT_QUERY_END_SESSION(wxApp::OnQueryEndSession) END_EVENT_TABLE() #endif @@ -111,14 +115,17 @@ bool wxApp::Initialize() { wxBuffer = new char[1500]; +/* PLEASE don't uncomment this again. IT DOESN'T WORK when building + * using the makefile. #if defined(__WXDEBUG__) && defined(_MSC_VER) // do check for memory leaks on program exit // (another useful flag is _CRTDBG_DELAY_FREE_MEM_DF which doesn't free // deallocated memory which may be used to simulate low-memory condition) _CrtSetDbgFlag(_CrtSetDbgFlag(_CRTDBG_REPORT_FLAG) | _CRTDBG_LEAK_CHECK_DF); #endif // debug build under MS VC++ +*/ - #if (WXDEBUG && USE_MEMORY_TRACING) || USE_DEBUG_CONTEXT + #if (WXDEBUG && wxUSE_MEMORY_TRACING) || wxUSE_DEBUG_CONTEXT #if defined(_WINDLL) streambuf* sBuf = NULL; #else // EXE @@ -127,11 +134,11 @@ bool wxApp::Initialize() ostream* oStr = new ostream(sBuf) ; wxDebugContext::SetStream(oStr, sBuf); - #endif // USE_MEMORY_TRACING + #endif // wxUSE_MEMORY_TRACING wxClassInfo::InitializeClasses(); - #if USE_RESOURCES + #if wxUSE_RESOURCES wxGetResource("wxWindows", "OsVersion", &wxOsVersion); #endif @@ -141,17 +148,10 @@ bool wxApp::Initialize() wxInitializeStockLists(); wxInitializeStockObjects(); - #if USE_WX_RESOURCES + #if wxUSE_WX_RESOURCES wxInitializeResourceSystem(); #endif - // For PostScript printing - #if USE_POSTSCRIPT - wxInitializePrintSetupData(); - wxThePrintPaperDatabase = new wxPrintPaperDatabase; - wxThePrintPaperDatabase->CreateDatabase(); - #endif - wxBitmap::InitStandardHandlers(); #if defined(__WIN95__) @@ -197,7 +197,7 @@ bool wxApp::Initialize() wxDisableButtonBrush = ::CreateBrushIndirect( & lb ) ; ::DeleteObject( (HGDIOBJ)lb.lbHatch ) ; - #if USE_PENWINDOWS + #if wxUSE_PENWINDOWS wxRegisterPenWin(); #endif @@ -346,82 +346,76 @@ bool wxApp::RegisterWindowClasses() //// Convert Windows to argc, argv style -// FIXME this code should be rewritten (use wxArrayString instead...) void wxApp::ConvertToStandardCommandArgs(char* lpCmdLine) { - // Split command line into tokens, as in usual main(argc, argv) - char **command = new char*[50]; // VZ: sure? why not 25 or 73 and a half?? + wxStringList args; - int count = 0; - char *buf = new char[strlen(lpCmdLine) + 1]; - - /* Model independent strcpy */ - int i; - for (i = 0; (buf[i] = lpCmdLine[i]) != 0; i++) - { - /* loop */; - } + wxString cmdLine(lpCmdLine); + int count = 0; - // Get application name - char name[260]; // 260 is MAX_PATH value from windef.h - ::GetModuleFileName(wxhInstance, name, WXSIZEOF(name)); + // Get application name + char name[260]; // 260 is MAX_PATH value from windef.h + ::GetModuleFileName(wxhInstance, name, WXSIZEOF(name)); - // Is it only 16-bit Borland that already copies the program name - // to the first argv index? + // GNUWIN32 already fills in the first arg with the application name. #if !defined(__GNUWIN32__) -// #if ! (defined(__BORLANDC__) && !defined(__WIN32__)) - command[count++] = copystring(name); -// #endif + args.Add(name); + count ++; #endif - strcpy(name, wxFileNameFromPath(name)); - wxStripExtension(name); - wxTheApp->SetAppName(name); + strcpy(name, wxFileNameFromPath(name)); + wxStripExtension(name); + wxTheApp->SetAppName(name); - /* Break up string */ - // Treat strings enclosed in double-quotes as single arguments - char* str = buf; - while (*str) - { - if ( count == WXSIZEOF(command) ) + // Break up string + // Treat strings enclosed in double-quotes as single arguments + int i = 0; + int len = cmdLine.Length(); + while (i < len) { - wxFAIL_MSG("too many command line args."); - break; - } - - while ( *str && isspace(*str) ) // skip whitespace - str++; + // Skip whitespace + while ((i < len) && isspace(cmdLine.GetChar(i))) + i ++; - if (*str == '"') - { - str++; - command[count++] = str; - while (*str && *str != '"') - str++; + if (i < len) + { + if (cmdLine.GetChar(i) == '"') // We found the start of a string + { + i ++; + int first = i; + while ((i < len) && (cmdLine.GetChar(i) != '"')) + i ++; + + wxString arg(cmdLine.Mid(first, (i - first))); + + args.Add(arg); + count ++; + + if (i < len) + i ++; // Skip past 2nd quote + } + else // Unquoted argument + { + int first = i; + while ((i < len) && !isspace(cmdLine.GetChar(i))) + i ++; + + wxString arg(cmdLine.Mid(first, (i - first))); + + args.Add(arg); + count ++; + } + } } - else if (*str) + + wxTheApp->argv = new char*[count + 1]; + for (i = 0; i < count; i++) { - command[count++] = str; - while (*str && !isspace(*str)) - str++; + wxString arg(args[i]); + wxTheApp->argv[i] = copystring((const char*)arg); } - if (*str) - *str++ = '\0'; - } - - wxTheApp->argv = new char*[count + 1]; - wxTheApp->argv[count] = NULL; /* argv[] is NULL terminated list! */ - wxTheApp->argc = count; - - for (i = 0; i < count; i++) - { - wxTheApp->argv[i] = copystring(command[i]); - - delete [] command[i]; - } - - delete [] command; - delete [] buf; + wxTheApp->argv[count] = NULL; // argv[] is a NULL-terminated list + wxTheApp->argc = count; } //// Cleans up any wxWindows internal structures left lying around @@ -431,7 +425,7 @@ void wxApp::CleanUp() //// COMMON CLEANUP wxModule::CleanUpModules(); -#if USE_WX_RESOURCES +#if wxUSE_WX_RESOURCES wxCleanUpResourceSystem(); // wxDefaultResourceTable->ClearTable(); @@ -452,12 +446,6 @@ void wxApp::CleanUp() delete wxTheColourDatabase; wxTheColourDatabase = NULL; -#if USE_POSTSCRIPT - wxInitializePrintSetupData(FALSE); - delete wxThePrintPaperDatabase; - wxThePrintPaperDatabase = NULL; -#endif - wxBitmap::CleanUpHandlers(); delete[] wxBuffer; @@ -472,7 +460,7 @@ void wxApp::CleanUp() FreeLibrary(gs_hRichEdit); #endif -#if USE_PENWINDOWS +#if wxUSE_PENWINDOWS wxCleanUpPenWin(); #endif @@ -521,7 +509,7 @@ int wxEntry(WXHINSTANCE hInstance, bool enterLoop) { #ifndef __WXDEBUG__ // take everything into a try-except block in release build - __try { + try { #endif wxhInstance = (HINSTANCE) hInstance; @@ -585,7 +573,7 @@ int wxEntry(WXHINSTANCE hInstance, delete wxTheApp; wxTheApp = NULL; -#if (WXDEBUG && USE_MEMORY_TRACING) || USE_DEBUG_CONTEXT +#if (WXDEBUG && wxUSE_MEMORY_TRACING) || wxUSE_DEBUG_CONTEXT // At this point we want to check if there are any memory // blocks that aren't part of the wxDebugContext itself, // as a special case. Then when dumping we need to ignore @@ -602,7 +590,7 @@ int wxEntry(WXHINSTANCE hInstance, return retValue; #ifndef __WXDEBUG__ // catch exceptions only in release build } - __except ( EXCEPTION_EXECUTE_HANDLER ) { + except ( EXCEPTION_EXECUTE_HANDLER ) { /* if ( wxTheApp ) wxTheApp->OnFatalException(); @@ -687,7 +675,7 @@ wxApp::~wxApp() { delete[] argv[i]; } - delete argv; + delete[] argv; } bool wxApp::Initialized() @@ -901,6 +889,23 @@ void wxApp::DeletePendingObjects() } } +void wxApp::OnEndSession(wxCloseEvent& event) +{ + if (GetTopWindow()) + GetTopWindow()->Close(TRUE); +} + +// Default behaviour: close the application with prompts. The +// user can veto the close, and therefore the end session. +void wxApp::OnQueryEndSession(wxCloseEvent& event) +{ + if (GetTopWindow()) + { + if (!GetTopWindow()->Close(!event.CanVeto())) + event.Veto(TRUE); + } +} + wxLog* wxApp::CreateLogTarget() { return new wxLogGui;