00001 00002 // MathCore = a WYSIWYG equation editor + a powerful math engine // 00003 // Copyright (C) 2003 by Francesco Montorsi // 00004 // // 00005 // This library is free software; you can redistribute it and/or // 00006 // modify it under the terms of the GNU Lesser General Public // 00007 // License as published by the Free Software Foundation; either // 00008 // version 2.1 of the License, or (at your option) any later // 00009 // version. // 00010 // // 00011 // This library is distributed in the hope that it will be useful, // 00012 // but WITHOUT ANY WARRANTY; without even the implied warranty of // 00013 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // 00014 // GNU Lesser General Public License for more details. // 00015 // // 00016 // You should have received a copy of the GNU Lesser General Public // 00017 // License along with this program; if not, write to the Free // 00018 // Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, // 00019 // MA 02111-1307, USA. // 00020 // // 00021 // For any comment, suggestion or feature request, please contact // 00022 // the administrator of the project at frm@users.sourceforge.net // 00023 // // 00030 00031 00032 00033 // optimization for GCC compiler 00034 #ifdef __GNUG__ 00035 #pragma implementation "MathUtils.h" 00036 #endif 00037 00038 // includes 00039 #include "mc/mcprec.h" 00040 #include <wx/image.h> // this is not included by mc.h & mcprec.h 00041 #ifdef __BORLANDC__ 00042 #pragma hdrstop 00043 #endif 00044 00045 #ifndef mcPRECOMP 00046 #include "mc/MathUtils.h" 00047 #include "mc/Element.h" 00048 #endif 00049 00050 00051 00052 // ------------------------ 00053 // LOG functions 00054 // ------------------------ 00055 00056 #if defined(mcENABLE_LOG) 00057 00058 // DO NOT PRINT THAT ANNOYING TIMESTAMP 00059 void mcLog::DoLogString(const wxChar *szString, time_t WXUNUSED(t)) 00060 { wxPrintf(szString); wxPrintf(wxT("\n")); } 00061 00062 00063 // log functions can't allocate memory (LogError("out of memory...") should 00064 // work!), so we use a static buffer for all log messages 00065 #define LOG_BUFFER_SIZE (4096) 00066 00067 // static buffer for error messages 00068 static wxChar smc_szBufStatic[LOG_BUFFER_SIZE]; 00069 00070 static wxChar *smc_szBuf = smc_szBufStatic; 00071 static size_t smc_szBufSize = WXSIZEOF( smc_szBufStatic ); 00072 00073 #if wxUSE_THREADS 00074 00075 // the critical section protecting the static buffer 00076 static wxCriticalSection gsmc_csLogBuf; 00077 00078 #endif // wxUSE_THREADS 00079 00080 // return true if we have a non NULL non disabled log target 00081 static inline bool IsMCLoggingEnabled() 00082 { return wxLog::IsEnabled() && (wxLog::GetActiveTarget() != NULL); } 00083 00084 00085 00086 #define mcIMPLEMENT_MATHCORE_LOG_FUNCTION(level) \ 00087 void mcVLog##level(const wxChar *szFormat, va_list argptr) \ 00088 { \ 00089 if ( IsMCLoggingEnabled() ) { \ 00090 wxCRIT_SECT_LOCKER(locker, gsmc_csLogBuf); \ 00091 wxVsnprintf(smc_szBuf, smc_szBufSize, szFormat, argptr); \ 00092 wxLog::OnLog(mcLOG_##level, smc_szBuf, 0); \ 00093 } \ 00094 } \ 00095 void mcLog##level(const wxChar *szFormat, ...) \ 00096 { \ 00097 va_list argptr; \ 00098 va_start(argptr, szFormat); \ 00099 mcVLog##level(szFormat, argptr); \ 00100 va_end(argptr); \ 00101 } 00102 00103 00104 00105 mcIMPLEMENT_MATHCORE_LOG_FUNCTION(Generic) 00106 mcIMPLEMENT_MATHCORE_LOG_FUNCTION(Math) 00107 mcIMPLEMENT_MATHCORE_LOG_FUNCTION(GUI) 00108 mcIMPLEMENT_MATHCORE_LOG_FUNCTION(IO) 00109 00110 #endif // mcENABLE_LOG 00111 00112 00113 00114 // ---------------------------- 00115 // UTILITIES 00116 // ---------------------------- 00117 00118 wxString wxIndent(const wxString &str, int indent) 00119 { 00120 wxString tmp(str); 00121 00122 if (tmp.Freq(wxT('\n')) > 1) { 00123 00124 // if this element returned a description containing various lines, 00125 // indent those lines using the given indentation value 00126 tmp.Replace(wxT("\n"), wxT("\n") + wxString(wxT(' '), indent)); 00127 00128 // trim the final spaces added by the line above 00129 tmp.Trim(); 00130 00131 // re-add the final '\n' removed by the line above 00132 tmp += wxT("\n"); 00133 } 00134 00135 return tmp; 00136 } 00137 /* 00138 int GetNumber(wxChar c) 00139 { return c-48; } 00140 00141 int GetNumDigitOf(int n) 00142 { 00143 float f=(float)n; 00144 int c; 00145 for (c=1; f >= 10.0; c++) 00146 f *= 0.1f; 00147 return c; 00148 }*/ 00149 00150 wxBitmap *wxLoadMaskForXPM(char **xpm, const wxColour &mask) 00151 { 00152 wxBitmap bmp(xpm); 00153 00154 // onle wxImage supports masks, so we must convert our wxBitmap 00155 // in a wxImage and then from wxImage to wxBitmap... 00156 wxImage img = bmp.ConvertToImage(); 00157 img.SetMaskColour(255, 255, 255); 00158 return new wxBitmap(img); 00159 } 00160 00161 int wxFindOneOf(const wxString &str, const wxString &tofind) 00162 { 00163 int r = wxNOT_FOUND; 00164 for (int i=0; i < (int)tofind.Len(); i++) 00165 if ((r = str.Find(tofind.GetChar(i))) != wxNOT_FOUND) 00166 return r; 00167 return wxNOT_FOUND; 00168 } 00169 00170 00171 00172
[ Top ] |