wxDataFormat GetMatchingPair();
// implementation
-
- GdkAtom GtkGetMatchingPair();
+
+ GdkAtom GtkGetMatchingPair(bool quiet = false);
void GtkRegisterWidget( GtkWidget *widget );
void GtkUnregisterWidget( GtkWidget *widget );
// implementation
- GdkAtom GetMatchingPair();
+ GdkAtom GetMatchingPair(bool quiet = false);
void RegisterWidget( GtkWidget *widget );
void UnregisterWidget( GtkWidget *widget );
#include "wx/dynarray.h"
+// wxUSE_LOG_DEBUG enables the debug log messages
#ifndef wxUSE_LOG_DEBUG
#if wxDEBUG_LEVEL
#define wxUSE_LOG_DEBUG 1
#endif
#endif
+// wxUSE_LOG_TRACE enables the trace messages, they are disabled by default
+#ifndef wxUSE_LOG_TRACE
+ #if wxDEBUG_LEVEL >= 2
+ #define wxUSE_LOG_TRACE 1
+ #else // wxDEBUG_LEVEL < 2
+ #define wxUSE_LOG_TRACE 0
+ #endif
+#endif // wxUSE_LOG_TRACE
+
// ----------------------------------------------------------------------------
// forward declarations
// ----------------------------------------------------------------------------
// "trivial" derivations of wxLog
// ----------------------------------------------------------------------------
-// log everything to a buffer
+// log everything except for the debug/trace messages (which are passed to
+// wxMessageOutputDebug) to a buffer
class WXDLLIMPEXP_BASE wxLogBuffer : public wxLog
{
public:
virtual void Flush();
protected:
+#if wxUSE_LOG_DEBUG || wxUSE_LOG_TRACE
virtual void DoLog(wxLogLevel level, const wxString& szString, time_t t);
- virtual void DoLogString(const wxString& szString, time_t t);
wxSUPPRESS_DOLOG_HIDE_WARNING()
+#endif // wxUSE_LOG_DEBUG || wxUSE_LOG_TRACE
+
+ virtual void DoLogString(const wxString& szString, time_t t);
+
wxSUPPRESS_DOLOGSTRING_HIDE_WARNING()
private:
#else // !wxUSE_LOG
+#undef wxUSE_LOG_DEBUG
+#define wxUSE_LOG_DEBUG 0
+
+#undef wxUSE_LOG_TRACE
+#define wxUSE_LOG_TRACE 0
+
#ifdef __WATCOMC__
// workaround for http://bugzilla.openwatcom.org/show_bug.cgi?id=351
#define WX_WATCOM_ONLY_CODE( x ) x
DECLARE_LOG_FUNCTION2(SysError, unsigned long, lErrCode);
#endif
-// debug functions do nothing in release mode
-#if wxUSE_LOG && wxUSE_LOG_DEBUG
+
+// debug functions can be completely disabled in optimized builds
+
+// if these log functions are disabled, we prefer to define them as (empty)
+// variadic macros as this completely removes them and their argument
+// evaluation from the object code but if this is not supported by compiler we
+// use empty inline functions instead (defining them as nothing would result in
+// compiler warnings)
+//
+// note that making wxVLogDebug/Trace() themselves (empty inline) functions is
+// a bad idea as some compilers are stupid enough to not inline even empty
+// functions if their parameters are complicated enough, but by defining them
+// as an empty inline function we ensure that even dumbest compilers optimise
+// them away
+#ifdef __BORLANDC__
+ // but Borland gives "W8019: Code has no effect" for wxLogNop() so we need
+ // to define it differently for it to avoid these warnings (same problem as
+ // with wxUnusedVar())
+ #define wxLogNop() { }
+#else
+ inline void wxLogNop() { }
+#endif
+
+#if wxUSE_LOG_DEBUG
DECLARE_LOG_FUNCTION(Debug);
+#else // !wxUSE_LOG_DEBUG
+ #define wxVLogDebug(fmt, valist) wxLogNop()
- // there is no more unconditional LogTrace: it is not different from
- // LogDebug and it creates overload ambiguities
- //DECLARE_LOG_FUNCTION(Trace);
+ #ifdef HAVE_VARIADIC_MACROS
+ #define wxLogDebug(fmt, ...) wxLogNop()
+ #else // !HAVE_VARIADIC_MACROS
+ WX_DEFINE_VARARG_FUNC_NOP(wxLogDebug, 1, (const wxString&))
+ #endif
+#endif // wxUSE_LOG_DEBUG/!wxUSE_LOG_DEBUG
+#if wxUSE_LOG_TRACE
// this version only logs the message if the mask had been added to the
// list of masks with AddTraceMask()
DECLARE_LOG_FUNCTION2(Trace, const wxString&, mask);
// string identifiers
#if WXWIN_COMPATIBILITY_2_8
DECLARE_LOG_FUNCTION2(Trace, wxTraceMask, mask);
-#endif // wxDEBUG_LEVEL
#ifdef __WATCOMC__
// workaround for http://bugzilla.openwatcom.org/show_bug.cgi?id=351
DECLARE_LOG_FUNCTION2(Trace, int, mask);
#endif
-#else //!debug || !wxUSE_LOG
- // these functions do nothing in release builds, but don't define them as
- // nothing as it could result in different code structure in debug and
- // release and this could result in trouble when these macros are used
- // inside if/else
- //
- // note that making wxVLogDebug/Trace() themselves (empty inline) functions
- // is a bad idea as some compilers are stupid enough to not inline even
- // empty functions if their parameters are complicated enough, but by
- // defining them as an empty inline function we ensure that even dumbest
- // compilers optimise them away
-#ifdef __BORLANDC__
- // but Borland gives "W8019: Code has no effect" for wxLogNop() so we need
- // to define it differently for it to avoid these warnings (same problem as
- // with wxUnusedVar())
- #define wxLogNop() { }
-#else
- inline void wxLogNop() { }
-#endif
+#endif // WXWIN_COMPATIBILITY_2_8
- #define wxVLogDebug(fmt, valist) wxLogNop()
+#else // !wxUSE_LOG_TRACE
#define wxVLogTrace(mask, fmt, valist) wxLogNop()
#ifdef HAVE_VARIADIC_MACROS
- // unlike the inline functions below, this completely removes the
- // wxLogXXX calls from the object file:
- #define wxLogDebug(fmt, ...) wxLogNop()
#define wxLogTrace(mask, fmt, ...) wxLogNop()
#else // !HAVE_VARIADIC_MACROS
- //inline void wxLogDebug(const wxString& fmt, ...) {}
- WX_DEFINE_VARARG_FUNC_NOP(wxLogDebug, 1, (const wxString&))
- //inline void wxLogTrace(wxTraceMask, const wxString& fmt, ...) {}
- //inline void wxLogTrace(const wxString&, const wxString& fmt, ...) {}
WX_DEFINE_VARARG_FUNC_NOP(wxLogTrace, 2, (wxTraceMask, const wxString&))
WX_DEFINE_VARARG_FUNC_NOP(wxLogTrace, 2, (const wxString&, const wxString&))
#ifdef __WATCOMC__
WX_DEFINE_VARARG_FUNC_NOP(wxLogTrace, 2, (const wchar_t*, const wchar_t*))
#endif
#endif // HAVE_VARIADIC_MACROS/!HAVE_VARIADIC_MACROS
-#endif // debug/!debug
+#endif // wxUSE_LOG_TRACE/!wxUSE_LOG_TRACE
#if defined(__VISUALC__) && __VISUALC__ < 1300
#pragma warning(default:4003)
}
#endif // wxUSE_UNICODE_UTF8
-// debug functions
-#ifdef __WXDEBUG__
+// ----------------------------------------------------------------------------
+// debug and trace functions
+// ----------------------------------------------------------------------------
+
+#if wxUSE_LOG_DEBUG
+ void wxVLogDebug(const wxString& format, va_list argptr)
+ {
+ if ( wxLog::IsEnabled() )
+ {
+ wxLog::OnLog(wxLOG_Debug,
+ wxString::FormatV(format, argptr), time(NULL));
+ }
+ }
#if !wxUSE_UTF8_LOCALE_ONLY
- #define IMPLEMENT_LOG_DEBUG_FUNCTION_WCHAR(level) \
- void wxDoLog##level##Wchar(const wxChar *format, ...) \
- { \
- va_list argptr; \
- va_start(argptr, format); \
- wxVLog##level(format, argptr); \
- va_end(argptr); \
- }
-#else
- #define IMPLEMENT_LOG_DEBUG_FUNCTION_WCHAR(level)
-#endif
+ void wxDoLogDebugWchar(const wxChar *format, ...)
+ {
+ va_list argptr;
+ va_start(argptr, format);
+ wxVLogDebug(format, argptr);
+ va_end(argptr);
+ }
+#endif // !wxUSE_UTF8_LOCALE_ONLY
#if wxUSE_UNICODE_UTF8
- #define IMPLEMENT_LOG_DEBUG_FUNCTION_UTF8(level) \
- void wxDoLog##level##Utf8(const char *format, ...) \
- { \
- va_list argptr; \
- va_start(argptr, format); \
- wxVLog##level(format, argptr); \
- va_end(argptr); \
- }
-#else
- #define IMPLEMENT_LOG_DEBUG_FUNCTION_UTF8(level)
-#endif
-
-#define IMPLEMENT_LOG_DEBUG_FUNCTION(level) \
- void wxVLog##level(const wxString& format, va_list argptr) \
- { \
- if ( wxLog::IsEnabled() ) { \
- wxLog::OnLog(wxLOG_##level, \
- wxString::FormatV(format, argptr), time(NULL)); \
- } \
- } \
- IMPLEMENT_LOG_DEBUG_FUNCTION_WCHAR(level) \
- IMPLEMENT_LOG_DEBUG_FUNCTION_UTF8(level)
-
+ void wxDoLogDebugUtf8(const char *format, ...)
+ {
+ va_list argptr;
+ va_start(argptr, format);
+ wxVLogDebug(format, argptr);
+ va_end(argptr);
+ }
+#endif // wxUSE_UNICODE_UTF8
+#endif // wxUSE_LOG_DEBUG
+#if wxUSE_LOG_TRACE
void wxVLogTrace(const wxString& mask, const wxString& format, va_list argptr)
{
if ( wxLog::IsEnabled() && wxLog::IsAllowedTraceMask(mask) ) {
void wxVLogTrace(const wchar_t *mask, const wxString& format, va_list argptr)
{ wxVLogTrace(wxString(mask), format, argptr); }
#endif // __WATCOMC__
+#endif // wxUSE_LOG_TRACE
-#else // release
- #define IMPLEMENT_LOG_DEBUG_FUNCTION(level)
-#endif
-
-IMPLEMENT_LOG_DEBUG_FUNCTION(Debug)
-IMPLEMENT_LOG_DEBUG_FUNCTION(Trace)
// wxLogSysError: one uses the last error code, for other you must give it
// explicitly
LogString(szString, t);
break;
+#if wxUSE_LOG_DEBUG || wxUSE_LOG_TRACE
+#if wxUSE_LOG_TRACE
case wxLOG_Trace:
+#endif
+#if wxUSE_LOG_DEBUG
case wxLOG_Debug:
-#ifdef __WXDEBUG__
+#endif
{
- wxString msg = level == wxLOG_Trace ? wxS("Trace: ")
- : wxS("Debug: ");
- msg << szString;
- LogString(msg, t);
+ wxString str;
+
+ // don't prepend "debug/trace" prefix under MSW as it goes to
+ // the debug window anyhow and don't add time stamp neither as
+ // debug output viewers under Windows typically add it
+ // themselves anyhow
+ #ifndef __WXMSW__
+ TimeStamp(&str);
+
+ str += level == wxLOG_Trace ? wxT("Trace: ")
+ : wxT("Debug: ");
+ #endif // !__WXMSW__
+
+ str += szString;
+ wxMessageOutputDebug().Output(str);
}
-#endif // Debug
break;
+#endif // wxUSE_LOG_DEBUG || wxUSE_LOG_TRACE
}
}
}
}
+#if wxUSE_LOG_DEBUG || wxUSE_LOG_TRACE
+
void wxLogBuffer::DoLog(wxLogLevel level, const wxString& szString, time_t t)
{
- switch ( level )
- {
- case wxLOG_Trace:
- case wxLOG_Debug:
-#ifdef __WXDEBUG__
- // don't put debug messages in the buffer, we don't want to show
- // them to the user in a msg box, log them immediately
- {
- wxString str;
- TimeStamp(&str);
- str += szString;
+ // don't put debug messages in the buffer, we don't want to show
+ // them to the user in a msg box, log them immediately
+ bool showImmediately = false;
+#if wxUSE_LOG_TRACE
+ if ( level == wxLOG_Trace )
+ showImmediately = true;
+#endif
+#if wxUSE_LOG_DEBUG
+ if ( level == wxLOG_Debug )
+ showImmediately = true;
+#endif
- wxMessageOutputDebug dbgout;
- dbgout.Printf(wxS("%s\n"), str.c_str());
- }
-#endif // __WXDEBUG__
- break;
+ if ( showImmediately )
+ {
+ wxString str;
+ TimeStamp(&str);
+ str += szString;
- default:
- wxLog::DoLog(level, szString, t);
+ wxMessageOutputDebug dbgout;
+ dbgout.Printf(wxS("%s\n"), str.c_str());
+ }
+ else
+ {
+ wxLog::DoLog(level, szString, t);
}
}
+#endif // wxUSE_LOG_DEBUG || wxUSE_LOG_TRACE
+
void wxLogBuffer::DoLogString(const wxString& szString, time_t WXUNUSED(t))
{
m_str << szString << wxS("\n");
wxWindow *win,
bool captureMouse)
{
-#ifdef __WXDEBUG__
+#if wxUSE_LOG_TRACE
static const wxChar *cursorModes[] =
{
_T("SELECT_CELL"),
: win ? _T("rowLabelWin")
: _T("gridWin"),
cursorModes[m_cursorMode], cursorModes[mode]);
-#endif
+#endif // wxUSE_LOG_TRACE
if ( mode == m_cursorMode &&
win == m_winCapture &&
#include "wx/artprov.h"
#include "wx/collpane.h"
#include "wx/arrstr.h"
+#include "wx/msgout.h"
#if wxUSE_THREADS
#include "wx/thread.h"
#endif // wxUSE_STATUSBAR
break;
- case wxLOG_Trace:
- case wxLOG_Debug:
- #ifdef __WXDEBUG__
- {
- wxString str;
- TimeStamp(&str);
- str += szString;
-
- #if defined(__WXMSW__) && !defined(__WXMICROWIN__)
- // don't prepend debug/trace here: it goes to the
- // debug window anyhow
- str += wxT("\r\n");
- OutputDebugString(str.wx_str());
- #else
- // send them to stderr
- wxFprintf(stderr, wxT("[%s] %s\n"),
- level == wxLOG_Trace ? wxT("Trace")
- : wxT("Debug"),
- str.c_str());
- fflush(stderr);
- #endif
- }
- #endif // __WXDEBUG__
-
- break;
-
case wxLOG_FatalError:
// show this one immediately
wxMessageBox(szString, _("Fatal error"), wxICON_HAND);
m_aTimes.Add((long)t);
m_bHasMessages = true;
break;
+
+ default:
+ // let the base class deal with debug/trace messages as well as any
+ // custom levels
+ wxLog::DoLog(level, szString, t);
}
}
// the flags used for the last DoDragDrop()
static long gs_flagsForDrag = 0;
-#ifdef __WXDEBUG__
// the trace mask we use with wxLogTrace() - call
// wxLog::AddTraceMask(TRACE_DND) to enable the trace messages from here
// (there are quite a few of them, so don't enable this by default)
-static const wxChar *TRACE_DND = _T("dnd");
-#endif
+#define TRACE_DND "dnd"
// global variables because GTK+ DnD want to have the
// mouse event that caused it
if (!ret)
{
-#ifdef __WXDEBUG__
wxLogTrace(TRACE_DND, wxT( "Drop target: OnDrop returned FALSE") );
-#endif
/* cancel the whole thing */
gtk_drag_finish( context,
}
else
{
-#ifdef __WXDEBUG__
wxLogTrace(TRACE_DND, wxT( "Drop target: OnDrop returned true") );
-#endif
#if wxUSE_THREADS
/* disable GUI threads */
return;
}
-#ifdef __WXDEBUG__
wxLogTrace(TRACE_DND, wxT( "Drop target: data received event") );
-#endif
/* inform the wxDropTarget about the current GtkSelectionData.
this is only valid for the duration of this call */
if ( wxIsDragResultOk( drop_target->OnData( x, y, result ) ) )
{
-#ifdef __WXDEBUG__
wxLogTrace(TRACE_DND, wxT( "Drop target: OnData returned true") );
-#endif
/* tell GTK that data transfer was successful */
gtk_drag_finish( context, TRUE, FALSE, time );
}
else
{
-#ifdef __WXDEBUG__
wxLogTrace(TRACE_DND, wxT( "Drop target: OnData returned FALSE") );
-#endif
/* tell GTK that data transfer was not successful */
gtk_drag_finish( context, FALSE, FALSE, time );
{
// GetMatchingPair() checks for m_dataObject too, no need to do it here
- // disable the debug message from GetMatchingPair() - there are too many
- // of them otherwise
-#ifdef __WXDEBUG__
- wxLogNull noLog;
-#endif // Debug
-
- return (GtkGetMatchingPair() != (GdkAtom) 0) ? def : wxDragNone;
+ // disable the trace message from GetMatchingPair() by passing true to it
+ // (there are just too many of them otherwise)
+ return (GtkGetMatchingPair(true) != (GdkAtom) 0) ? def : wxDragNone;
}
bool wxDropTarget::OnDrop( wxCoord WXUNUSED(x), wxCoord WXUNUSED(y) )
return wxDataFormat( GtkGetMatchingPair() );
}
-GdkAtom wxDropTarget::GtkGetMatchingPair()
+GdkAtom wxDropTarget::GtkGetMatchingPair(bool quiet)
{
if (!m_dataObject)
return (GdkAtom) 0;
GdkAtom formatAtom = (GdkAtom)(child->data);
wxDataFormat format( formatAtom );
-#ifdef __WXDEBUG__
- wxLogTrace(TRACE_DND, wxT("Drop target: drag has format: %s"),
- format.GetId().c_str());
-#endif // Debug
+ if ( !quiet )
+ {
+ wxLogTrace(TRACE_DND, wxT("Drop target: drag has format: %s"),
+ format.GetId().c_str());
+ }
if (m_dataObject->IsSupportedFormat( format ))
return formatAtom;
{
wxDataFormat format( selection_data->target );
-#ifdef __WXDEBUG__
wxLogTrace(TRACE_DND, wxT("Drop source: format requested: %s"),
format.GetId().c_str());
-#endif
drop_source->m_retValue = wxDragCancel;
if (!data)
{
-#ifdef __WXDEBUG__
wxLogTrace(TRACE_DND, wxT("Drop source: no data object") );
-#endif
- return;
+ return;
}
if (!data->IsSupportedFormat(format))
{
-#ifdef __WXDEBUG__
wxLogTrace(TRACE_DND, wxT("Drop source: unsupported format") );
-#endif
- return;
+ return;
}
if (data->GetDataSize(format) == 0)
{
-#ifdef __WXDEBUG__
wxLogTrace(TRACE_DND, wxT("Drop source: empty data") );
-#endif
- return;
+ return;
}
size_t size = data->GetDataSize(format);
for (size_t i = 0; i < count; i++)
{
GdkAtom atom = array[i];
-#ifdef __WXDEBUG__
- wxLogTrace(TRACE_DND, wxT("Drop source: Supported atom %s"), gdk_atom_name( atom ));
-#endif
- gtk_target_list_add( target_list, atom, 0, 0 );
+ wxLogTrace(TRACE_DND, wxT("Drop source: Supported atom %s"),
+ gdk_atom_name( atom ));
+ gtk_target_list_add( target_list, atom, 0, 0 );
}
delete[] array;
extern void wxapp_install_idle_handler();
extern bool g_isIdle;
-//-----------------------------------------------------------------------------
-// thread system
-//-----------------------------------------------------------------------------
-
-#if wxUSE_THREADS
-#endif
-
//----------------------------------------------------------------------------
// global data
//----------------------------------------------------------------------------
{
// GetMatchingPair() checks for m_dataObject too, no need to do it here
- // disable the debug message from GetMatchingPair() - there are too many
- // of them otherwise
-#ifdef __WXDEBUG__
- wxLogNull noLog;
-#endif // Debug
-
- return (GetMatchingPair() != (GdkAtom) 0) ? def : wxDragNone;
+ // disable the debug message from GetMatchingPair() by passing true to it
+ return (GetMatchingPair(true) != (GdkAtom) 0) ? def : wxDragNone;
}
bool wxDropTarget::OnDrop( wxCoord WXUNUSED(x), wxCoord WXUNUSED(y) )
GdkAtom formatAtom = GPOINTER_TO_INT(child->data);
wxDataFormat format( formatAtom );
-#ifdef __WXDEBUG__
- wxLogTrace(TRACE_DND, wxT("Drop target: drag has format: %s"),
- format.GetId().c_str());
-#endif // Debug
+ if ( !quiet )
+ {
+ wxLogTrace(TRACE_DND, wxT("Drop target: drag has format: %s"),
+ format.GetId().c_str());
+ }
if (m_dataObject->IsSupportedFormat( format ))
return formatAtom;
wxThreadState GetState() const { return m_state; }
void SetState(wxThreadState state)
{
-#ifdef __WXDEBUG__
+#if wxUSE_LOG_TRACE
static const wxChar *stateNames[] =
{
_T("NEW"),
wxLogTrace(TRACE_THREADS, _T("Thread %p: %s => %s."),
GetId(), stateNames[m_state], stateNames[state]);
-#endif // __WXDEBUG__
+#endif // wxUSE_LOG_TRACE
m_state = state;
}