merge the formfield patch from ooo-build
[ooovba.git] / sal / osl / w32 / diagnose.c
blobdc0de3704a8ca8d7f4632f7fe6054b2bd4411324
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: diagnose.c,v $
10 * $Revision: 1.14 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 #include "system.h"
33 #define NO_DEBUG_CRT
35 #include <osl/diagnose.h>
36 #include <osl/thread.h>
38 #define NO_DEBUG_CRT
40 static pfunc_osl_printDebugMessage _pPrintDebugMessage = NULL;
41 static pfunc_osl_printDetailedDebugMessage _pPrintDetailedDebugMessage = NULL;
43 pfunc_osl_printDebugMessage SAL_CALL osl_setDebugMessageFunc( pfunc_osl_printDebugMessage pNewFunc )
45 pfunc_osl_printDebugMessage pOldFunc = _pPrintDebugMessage;
46 _pPrintDebugMessage = pNewFunc;
48 return pOldFunc;
51 pfunc_osl_printDetailedDebugMessage SAL_CALL osl_setDetailedDebugMessageFunc( pfunc_osl_printDetailedDebugMessage pNewFunc )
53 pfunc_osl_printDetailedDebugMessage pOldFunc = _pPrintDetailedDebugMessage;
54 _pPrintDetailedDebugMessage = pNewFunc;
55 return pOldFunc;
59 Trace output
62 void SAL_CALL osl_breakDebug(void)
64 DebugBreak();
69 /* Uncomment this define to get profiling time output */
70 /* #define OSL_PROFILING */
71 /* comment this define to stop output thread identifier*/
72 #define OSL_TRACE_THREAD 1
73 void SAL_CALL osl_trace(const sal_Char* lpszFormat, ...)
75 va_list args;
76 int written = 0;
78 va_start(args, lpszFormat);
80 #if defined(OSL_PROFILING)
81 fprintf(stderr, "time : %06lu : ", osl_getGlobalTimer() );
82 #else
83 #if defined(OSL_TRACE_THREAD)
84 fprintf(stderr,"Thread: %6d :",osl_getThreadIdentifier(NULL));
85 #else
86 fprintf(stderr,"Trace Message : ");
87 #endif
88 #endif
90 if ( IsDebuggerPresent() )
92 sal_Char szMessage[512];
93 szMessage[sizeof(szMessage)-1] = 0;
94 written = _vsnprintf( szMessage, sizeof(szMessage) - 2, lpszFormat, args );
95 if ( written == -1 )
96 written = sizeof(szMessage) - 2;
97 szMessage[ written++ ] = '\n';
98 szMessage[ written ] = 0;
99 OutputDebugString( szMessage );
102 vfprintf(stderr,lpszFormat, args);
104 fprintf(stderr,"\n");
106 fflush(stderr);
108 va_end(args);
111 sal_Bool SAL_CALL osl_assertFailedLine(const sal_Char* pszFileName, sal_Int32 nLine, const sal_Char* pszMessage)
113 #ifndef NO_DEBUG_CRT
114 return (_CrtDbgReport(_CRT_ASSERT, pszFileName, nLine, NULL, pszMessage));
115 #else
116 HWND hWndParent;
117 UINT nFlags;
118 int nCode;
120 /* get app name or NULL if unknown (don't call assert) */
121 LPCSTR lpszAppName = "Error";
122 sal_Char szMessage[512];
124 /* format message into buffer */
125 szMessage[sizeof(szMessage)-1] = '\0'; /* zero terminate always */
126 _snprintf(szMessage, sizeof(szMessage)-1, "%s: File %hs, Line %d\n:%s\n",
127 lpszAppName, pszFileName, nLine, pszMessage);
129 OutputDebugString(szMessage);
131 if ( _pPrintDetailedDebugMessage )
132 _pPrintDetailedDebugMessage( pszFileName, nLine, pszMessage );
133 else if ( _pPrintDebugMessage )
134 _pPrintDebugMessage( szMessage );
135 else if ( !getenv( "DISABLE_SAL_DBGBOX" ) )
137 TCHAR szBoxMessage[1024];
139 /* active popup window for the current thread */
140 hWndParent = GetActiveWindow();
141 if (hWndParent != NULL)
142 hWndParent = GetLastActivePopup(hWndParent);
144 /* set message box flags */
145 nFlags = MB_TASKMODAL | MB_ICONWARNING | MB_YESNOCANCEL | MB_DEFBUTTON2 | MB_SETFOREGROUND;
146 if (hWndParent == NULL)
147 nFlags |= MB_SERVICE_NOTIFICATION;
149 /* display the assert */
151 szBoxMessage[sizeof(szBoxMessage)-1] = 0;
152 _snprintf(szBoxMessage, sizeof(szBoxMessage)-1, "%s\n( Yes=Abort / No=Ignore / Cancel=Debugger )",
153 szMessage);
155 nCode = MessageBox(hWndParent, szBoxMessage, "Assertion Failed!", nFlags);
157 if (nCode == IDYES)
158 FatalExit(-1);
160 if (nCode == IDNO)
161 return sal_False; /* ignore */
163 if (nCode == IDCANCEL)
164 return sal_True; /* will cause oslDebugBreak */
166 #endif /* NO_DEBUG_CRT */
167 return sal_False; /* not shure, not care */
170 sal_Int32 SAL_CALL osl_reportError(sal_uInt32 nType, const sal_Char* pszMessage)
172 UINT nFlags;
173 int nDisposition;
175 // active popup window for the current thread
176 HWND hWndParent = GetActiveWindow();
177 if (hWndParent != NULL)
178 hWndParent = GetLastActivePopup(hWndParent);
180 nType = nType; /* avoid warnings */
182 /* set message box flags */
183 nFlags = MB_TASKMODAL | MB_ICONERROR | MB_YESNOCANCEL | MB_DEFBUTTON2 | MB_SETFOREGROUND;
184 if (hWndParent == NULL)
185 nFlags |= MB_SERVICE_NOTIFICATION;
187 // display the assert
188 nDisposition = MessageBox(hWndParent, pszMessage, "Exception!", nFlags);
190 return nDisposition;