00001 00002 // MathGUI = 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 "GUIUtils.h" 00036 #endif 00037 00038 00039 // includes 00040 #include "mg/mgprec.h" 00041 00042 #ifndef mgPRECOMP 00043 #include "mc/MathUtils.h" 00044 #include "mc/MathCore.h" 00045 #include "mg/MathGUI.h" 00046 #include "mg/GUIUtils.h" 00047 #endif 00048 00049 00050 00051 00052 // Definition of the STATIC variables of mgMathGUI 00053 mgMathGUI *mgMathGUI::g_pTheInstance = NULL; 00054 //void (*mgMathGUI::OnError)(const wxString &) = NULL; 00055 wxApp *mgMathGUI::m_pApp = NULL; 00056 00057 00058 // the event sent on wrong user input 00059 DEFINE_EVENT_TYPE( mgEVT_SYNTAX_ERROR ) 00060 00061 00062 00063 // ----------------- 00064 // mcMATHGUI 00065 // ----------------- 00066 00067 mgMathGUI::mgMathGUI() 00068 { 00069 m_pCore = NULL; 00070 } 00071 00072 mgMathGUI::~mgMathGUI() 00073 { 00074 // nothing to delete... 00075 wxLog *logtarget = wxLog::SetActiveTarget(NULL); 00076 mgSAFE_DELETE(logtarget); 00077 } 00078 00079 // this one is static 00080 mgMathGUI *mgMathGUI::Get() 00081 { 00082 mcASSERT(g_pTheInstance != NULL, 00083 wxT("Before using mgMathGUI::Get() you must call mgMathGUI::Setup()")); 00084 return g_pTheInstance; 00085 } 00086 00087 // this one is static 00088 void mgMathGUI::Set(mgMathGUI *p) 00089 { 00090 if (g_pTheInstance != NULL) 00091 delete g_pTheInstance; 00092 g_pTheInstance = p; 00093 } 00094 00095 // this one is static 00096 void mgMathGUI::OnError(const wxString &str) 00097 { 00098 wxCommandEvent ev(mgEVT_SYNTAX_ERROR); 00099 ev.m_commandString = str; 00100 00101 // fire an syntax error event... 00102 if (m_pApp) m_pApp->AddPendingEvent(ev); 00103 } 00104 00105 00106 // this one is static 00107 void mgMathGUI::Setup(wxApp *app) 00108 { 00109 // be sure mcMathCore singleton class has already been created 00110 mcASSERT(mcMathCore::Get() != NULL, 00111 wxT("Before calling mgMathGUI::Setup you must call mcMathCore::Setup")); 00112 00113 // create the global instance of the class 00114 mgMathGUI::g_pTheInstance = new mgMathGUI(); 00115 00116 m_pApp = app; 00117 mcMathCore::OnError = mgMathGUI::OnError; 00118 } 00119 00120 // this one is static 00121 void mgMathGUI::Cleanup() 00122 { 00123 // be sure that mcMathCore has not been deleted yet 00124 mcASSERT(mcMathCore::Get() != NULL, 00125 wxT("Before calling mcMathCore::Cleanup you must call mgMathGUI::Cleanup")); 00126 00127 // delete the global istance of this class 00128 mcSAFE_DELETE(mgMathGUI::g_pTheInstance); 00129 00130 #ifdef mgENABLE_LOG 00131 wxLog *p = wxLog::GetActiveTarget(); 00132 wxLog::SetActiveTarget(NULL); 00133 mgSAFE_DELETE(p); 00134 #endif 00135 } 00136 00137 00138 00139
[ Top ] |