Main Page | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Class Members | File Members | Related Pages

GUIUtils.cpp

Go to the documentation of this file.
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 #include <wx/mimetype.h>      // not included by wxprec.h
00042 
00043 #ifndef mgPRECOMP
00044    #include "mg/GUIUtils.h"
00045 #endif
00046 
00047 
00048 
00051 //wxTimer *g_pFrameTmr;
00052 
00053 
00054 
00055 // ----------------------------------------------------------------------------
00056 // GLOBAL FUNCTIONS
00057 // ----------------------------------------------------------------------------
00058 
00059 bool wxViewHTMLFile(const wxString& url)
00060 {
00061    wxFileType *ft = wxTheMimeTypesManager->GetFileTypeFromExtension(wxT("html"));
00062    
00063    if (!ft) {
00064       wxLogError(wxT("Impossible to determine the file type for extension html.")
00065          wxT("Please edit your MIME types."));
00066       return FALSE;
00067    }
00068    
00069    
00070    wxString cmd;
00071    bool ok = ft->GetOpenCommand(&cmd,
00072       wxFileType::MessageParameters(url, _T("")));
00073    delete ft;
00074    
00075    if (!ok) {
00076       
00077       // TODO: some kind of configuration dialog here.
00078       wxMessageBox(_("Could not determine the command for running the browser."),
00079          wxT("Browsing problem"), wxOK|wxICON_EXCLAMATION);
00080       return FALSE;
00081    }
00082    
00083    // GetOpenCommand can prepend file:// even if it already has http://
00084    if (cmd.Find(wxT("http://")) != -1 || cmd.Find(wxT("https://")) != -1)
00085       cmd.Replace(wxT("file://"), wxT(""));
00086    
00087    // try to exec the command
00088    return (wxExecute(cmd, FALSE) != 0);
00089 }
00090 
00091 
00092 
00093 
00094 // ----------------------------------------------------------------------------
00095 // LOG FUNCTIONS
00096 // ----------------------------------------------------------------------------
00097 
00098 #ifdef mgENABLE_LOG
00099 
00100    // log functions can't allocate memory (LogError("out of memory...") should
00101    // work!), so we use a static buffer for all log messages
00102    #define LOG_BUFFER_SIZE   (4096)
00103 
00104    // static buffer for error messages
00105    static wxChar   smg_szBufStatic[LOG_BUFFER_SIZE];
00106 
00107    static wxChar  *smg_szBuf     = smg_szBufStatic;
00108    static size_t   smg_szBufSize = WXSIZEOF( smg_szBufStatic );
00109 
00110    #if wxUSE_THREADS
00111 
00112    // the critical section protecting the static buffer
00113    static wxCriticalSection gsmg_csLogBuf;
00114 
00115    #endif // wxUSE_THREADS
00116 
00117    // return true if we have a non NULL non disabled log target
00118    static inline bool IsMGLoggingEnabled()
00119    { return wxLog::IsEnabled() && (wxLog::GetActiveTarget() != NULL); }
00120 
00121 
00122    #define IMPLEMENT_MATHGUI_LOG_FUNCTION(level)                       \
00123      void mgVLog##level(const wxChar *szFormat, va_list argptr)        \
00124      {                                                                 \
00125       if ( IsMGLoggingEnabled() ) {                                   \
00126         wxCRIT_SECT_LOCKER(locker, gsmg_csLogBuf);                    \
00127                                                       \
00128         wxVsnprintf(smg_szBuf, smg_szBufSize, szFormat, argptr);      \
00129                                                       \
00130         wxLog::OnLog(mgLOG_##level, smg_szBuf, time(NULL));           \
00131       }                                                               \
00132      }                                                                 \
00133      void mgLog##level(const wxChar *szFormat, ...)                    \
00134      {                                                                 \
00135       va_list argptr;                                                 \
00136       va_start(argptr, szFormat);                                     \
00137       mgVLog##level(szFormat, argptr);                                \
00138       va_end(argptr);                                                 \
00139      }
00140 
00141 
00142 
00143    IMPLEMENT_MATHGUI_LOG_FUNCTION(Debug)
00144    IMPLEMENT_MATHGUI_LOG_FUNCTION(Event)
00145    IMPLEMENT_MATHGUI_LOG_FUNCTION(BoxEvent)
00146 
00147 #endif      // mgENABLE_LOG
00148 
00149 
00150 


Documentation generated with Doxygen on Sun Feb 6 17:19:26 2005
Visit MathStudio home page for more info

[ Top ]