]> git.saurik.com Git - wxWidgets.git/blobdiff - src/common/log.cpp
* Added threads event propagation. Should compile on GTK (tested).
[wxWidgets.git] / src / common / log.cpp
index f92320b0f81535a94f28c687a17d0bc8222c6761..686cd757541e6a7abdd48db96adb2643a6884930 100644 (file)
 
 // wxWindows
 #ifndef WX_PRECOMP
+  #include  <wx/event.h>
   #include  <wx/app.h>
   #include  <wx/string.h>
   #include  <wx/intl.h>
   #include  <wx/menu.h>
   #include  <wx/frame.h>
-
-  #include  <wx/generic/msgdlgg.h>
+  #include  <wx/msgdlg.h>
   #include  <wx/filedlg.h>
   #include  <wx/textctrl.h>
 #endif //WX_PRECOMP
@@ -239,7 +239,14 @@ void WXDLLEXPORT wxLogSysError(long lErrCode, const char *szFormat, ...)
 wxLog::wxLog()
 {
   m_bHasMessages = FALSE;
-  m_bVerbose     = FALSE;
+
+  // enable verbose messages by default in the debug builds
+#ifdef __WXDEBUG__
+  m_bVerbose = TRUE;
+#else // release
+  m_bVerbose = FALSE;
+#endif // debug/release
+
   m_szTimeFormat = "[%d/%b/%y %H:%M:%S] ";
 }
 
@@ -330,8 +337,8 @@ void wxLog::DoLog(wxLogLevel level, const char *szString)
       break;
 
     case wxLOG_Info:
-      if ( GetVerbose() )
     case wxLOG_Message:
+      if ( GetVerbose() )
         DoLogString(str + szString);
       // fall through
 
@@ -358,7 +365,7 @@ void wxLog::DoLog(wxLogLevel level, const char *szString)
 
 void wxLog::DoLogString(const char *WXUNUSED(szString))
 {
-  wxFAIL_MSG(_("DoLogString must be overrided if it's called."));
+  wxFAIL_MSG("DoLogString must be overriden if it's called.");
 }
 
 void wxLog::Flush()
@@ -380,15 +387,24 @@ wxLogStderr::wxLogStderr(FILE *fp)
 
 void wxLogStderr::DoLogString(const char *szString)
 {
-  fputs(szString, m_fp);
-  fputc('\n', m_fp);
+  wxString str(szString);
+  str << '\n';
+
+  fputs(str, m_fp);
   fflush(m_fp);
+
+  // under Windows, programs usually don't have stderr at all, so make show the
+  // messages also under debugger
+#ifdef __WXMSW__
+    OutputDebugString(str + '\r');
+#endif // MSW
 }
 
 // ----------------------------------------------------------------------------
 // wxLogStream implementation
 // ----------------------------------------------------------------------------
 
+#if wxUSE_STD_IOSTREAM
 wxLogStream::wxLogStream(ostream *ostr)
 {
   if ( ostr == NULL )
@@ -401,15 +417,17 @@ void wxLogStream::DoLogString(const char *szString)
 {
   (*m_ostr) << szString << endl << flush;
 }
+#endif
 
 #ifndef   wxUSE_NOGUI
+
 // ----------------------------------------------------------------------------
 // wxLogTextCtrl implementation
 // ----------------------------------------------------------------------------
-wxLogTextCtrl::wxLogTextCtrl(wxTextCtrl *pTextCtrl)
-// @@@ TODO: in wxGTK wxTextCtrl doesn't derive from streambuf
 
-// Also, in DLL mode in wxMSW, can't use it.
+#if wxUSE_STD_IOSTREAM
+wxLogTextCtrl::wxLogTextCtrl(wxTextCtrl *pTextCtrl)
+// DLL mode in wxMSW, can't use it.
 #if defined(NO_TEXT_WINDOW_STREAM)
 #else
              : wxLogStream(new ostream(pTextCtrl))
@@ -421,6 +439,7 @@ wxLogTextCtrl::~wxLogTextCtrl()
 {
   delete m_ostr;
 }
+#endif
 
 // ----------------------------------------------------------------------------
 // wxLogGui implementation
@@ -513,18 +532,14 @@ void wxLogGui::DoLog(wxLogLevel level, const char *szString)
               OutputDebugString(strTime + szString + "\n\r");
           #else  
             // send them to stderr
-    /*
             fprintf(stderr, "%s %s: %s\n",
                     strTime.c_str(),
-                    level == wxLOG_Trace ? _("Trace") : _("Debug"),
-                    szString);
-     */
-            fprintf(stderr, "%s\n",
+                    level == wxLOG_Trace ? "Trace" : "Debug",
                     szString);
             fflush(stderr);
           #endif
         }
-      #endif
+      #endif // __WXDEBUG__
       break;
 
     case wxLOG_FatalError:
@@ -689,7 +704,14 @@ void wxLogFrame::OnSave(wxCommandEvent& WXUNUSED(event))
   // -------------------------
   int nLines = m_pTextCtrl->GetNumberOfLines();
   for ( int nLine = 0; bOk && nLine < nLines; nLine++ ) {
-    bOk = file.Write(m_pTextCtrl->GetLineText(nLine) + wxTextFile::GetEOL());
+    bOk = file.Write(m_pTextCtrl->GetLineText(nLine) + 
+// we're not going to pull in the whole wxTextFile if all we need is this...
+#if wxUSE_TEXTFILE
+                     wxTextFile::GetEOL()
+#else // !wxUSE_TEXTFILE
+                       '\n'
+#endif // wxUSE_TEXTFILE
+                    );
   }
 
   if ( bOk )
@@ -966,13 +988,24 @@ void wxOnAssert(const char *szFile, int nLine, const char *szMsg)
     // He-e-e-e-elp!! we're trapped in endless loop
     Trap();
 
+    s_bInAssert = FALSE;
+
     return;
   }
 
   s_bInAssert = TRUE;
 
   char szBuf[LOG_BUFFER_SIZE];
-  sprintf(szBuf, _("Assert failed in file %s at line %d"), szFile, nLine);
+
+  // make life easier for people using VC++ IDE: clicking on the message will
+  // take us immediately to the place of the failed assert
+#ifdef __VISUALC__
+  sprintf(szBuf, "%s(%d): assert failed", szFile, nLine);
+#else  // !VC++
+  // make the error message more clear for all the others
+  sprintf(szBuf, "Assert failed in file %s at line %d", szFile, nLine);
+#endif // VC/!VC
+
   if ( szMsg != NULL ) {
     strcat(szBuf, ": ");
     strcat(szBuf, szMsg);
@@ -985,12 +1018,12 @@ void wxOnAssert(const char *szFile, int nLine, const char *szMsg)
     // send it to the normal log destination
     wxLogDebug(szBuf);
 
-    #ifdef wxUSE_NOGUI
+    #if wxUSE_NOGUI
       Trap();
     #else
-      strcat(szBuf, _("\nDo you want to stop the program?"
-                      "\nYou can also choose [Cancel] to suppress "
-                      "further warnings."));
+      strcat(szBuf, "\nDo you want to stop the program?"
+                    "\nYou can also choose [Cancel] to suppress "
+                    "further warnings.");
 
       switch ( wxMessageBox(szBuf, _("Debug"),
                             wxYES_NO | wxCANCEL | wxICON_STOP ) ) {