bbtkWx.h

Go to the documentation of this file.
00001 /*=========================================================================                                                                               
00002   Program:   bbtk
00003   Module:    $RCSfile: bbtkWx.h,v $
00004   Language:  C++
00005   Date:      $Date: 2009/05/28 08:12:06 $
00006   Version:   $Revision: 1.11 $
00007 =========================================================================*/
00008 
00009 /* ---------------------------------------------------------------------
00010 
00011 * Copyright (c) CREATIS-LRMN (Centre de Recherche en Imagerie Medicale)
00012 * Authors : Eduardo Davila, Laurent Guigues, Jean-Pierre Roux
00013 *
00014 *  This software is governed by the CeCILL-B license under French law and 
00015 *  abiding by the rules of distribution of free software. You can  use, 
00016 *  modify and/ or redistribute the software under the terms of the CeCILL-B 
00017 *  license as circulated by CEA, CNRS and INRIA at the following URL 
00018 *  http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html 
00019 *  or in the file LICENSE.txt.
00020 *
00021 *  As a counterpart to the access to the source code and  rights to copy,
00022 *  modify and redistribute granted by the license, users are provided only
00023 *  with a limited warranty  and the software's author,  the holder of the
00024 *  economic rights,  and the successive licensors  have only  limited
00025 *  liability. 
00026 *
00027 *  The fact that you are presently reading this means that you have had
00028 *  knowledge of the CeCILL-B license and that you accept its terms.
00029 * ------------------------------------------------------------------------ */                                                                         
00030 
00031 
00032 /* ---------------------------------------------------------------------
00033 
00034 * Copyright (c) CREATIS-LRMN (Centre de Recherche en Imagerie Medicale)
00035 * Authors : Eduardo Davila, Laurent Guigues, Jean-Pierre Roux
00036 *
00037 *  This software is governed by the CeCILL-B license under French law and 
00038 *  abiding by the rules of distribution of free software. You can  use, 
00039 *  modify and/ or redistribute the software under the terms of the CeCILL-B 
00040 *  license as circulated by CEA, CNRS and INRIA at the following URL 
00041 *  http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html 
00042 *  or in the file LICENSE.txt.
00043 *
00044 *  As a counterpart to the access to the source code and  rights to copy,
00045 *  modify and redistribute granted by the license, users are provided only
00046 *  with a limited warranty  and the software's author,  the holder of the
00047 *  economic rights,  and the successive licensors  have only  limited
00048 *  liability. 
00049 *
00050 *  The fact that you are presently reading this means that you have had
00051 *  knowledge of the CeCILL-B license and that you accept its terms.
00052 * ------------------------------------------------------------------------ */                                                                         
00053 
00054 
00055 #ifndef __bbtkWx_h_INCLUDED__
00056 #define __bbtkWx_h_INCLUDED__
00057 
00058 //===========================================================================
00059 // Wx headers
00060 #ifdef USE_WXWIDGETS
00061 // For compilers that support precompilation, includes "wx/wx.h".
00062 #include "wx/wxprec.h"
00063 #include <wx/datetime.h>
00064 
00065 
00066 #ifdef __BORLANDC__
00067 #pragma hdrstop
00068 #endif
00069 
00070 #ifndef WX_PRECOMP
00071 #include <wx/wx.h>
00072 #endif
00073 
00074 #ifdef __WXGTK__
00075 # include <locale.h>
00076 #endif //__WXGTK__
00077 // EO Wx headers
00078 
00079 #else //USE_WXWIDGETS
00080 
00081 // define wxWindow
00082 typedef void wxWindow;
00083 typedef void wxBusyCursor;
00084 
00085 #endif // EO USE_WXWIDGETS
00086 //===========================================================================
00087 
00088 //===========================================================================
00089 #include "bbtkSystem.h"
00090 //===========================================================================
00091 
00092 //===========================================================================
00093 // SIGNAL/SLOT MECHANISM 
00094 // FOR bbtk WINDOWS CREATION/DESTRUCTION OBSERVATION 
00095 // BBTKWXSIG
00096 #include <boost/signal.hpp>
00097 #include <boost/bind.hpp>
00098 // \BBTKWXSIG
00099 //===========================================================================
00100 
00101 namespace bbtk
00102 {
00103 
00104   //==================================================================
00106   
00107 // BBTKWXSIG
00108 #define bbtkAddWxSignalObserver(METHOD)         \
00109   Wx::AddSignalObserver(boost::bind(&METHOD, this))
00110 // \BBTKWXSIG
00111 
00112 #define BBTK_BUSY_CURSOR bbtk::Wx::BusyCursor __bbtk_dummy_busy_cursor;
00113 
00114   struct BBTK_EXPORT Wx
00115   {     
00116   public:
00117     // BBTKWXSIG
00118     typedef boost::signals::trackable SignalObserver;
00119     typedef boost::signal<void ()>  Signal_type;
00120     typedef Signal_type::slot_function_type Slot_function_type;
00121     // \BBTKWXSIG
00122 
00123     class BusyCursor
00124     {
00125     public:
00126       BusyCursor();
00127       ~BusyCursor();
00128       wxBusyCursor* mCursor;
00129     };
00130 
00131     static void ProcessPendingEvents();
00132     
00134     static void SetTopWindow(wxWindow*);
00136     static wxWindow* GetTopWindow();
00137 
00138 
00139     static void IncNbWindowsAlive();
00140     static void DecNbWindowsAlive();
00141     static int  GetNbWindowsAlive();
00142     static bool IsSomeWindowAlive();
00143     
00144      // BBTKWXSIG
00145     static void AddSignalObserver(Slot_function_type);
00146     // \BBTKWXSIG
00147 
00148   
00149   private:
00150 
00151     static void CreateWxAppIfNeeded();
00152     static void DestroyWxAppIfNeeded();
00153 
00154   }; // struct Wx
00155   //==================================================================
00156   
00157 
00158 
00159 
00160 #ifdef USE_WXWIDGETS
00161   //==================================================================
00163   inline wxString std2wx(const std::string& s){
00164     wxString wx;
00165     const char* my_string=s.c_str();
00166     wxMBConvUTF8 *wxconv= new wxMBConvUTF8();
00167     wx=wxString(wxconv->cMB2WC(my_string),wxConvUTF8);
00168     delete wxconv;
00169     // test if conversion works of not. In case it fails convert from Ascii
00170     if(wx.length()==0)
00171       wx=wxString(wxString::FromAscii(s.c_str()));
00172     return wx;
00173   }
00174   //==================================================================
00175 
00176   //==================================================================
00178   inline std::string wx2std(const wxString& s){
00179     std::string s2;
00180     if(s.wxString::IsAscii()) {
00181       s2=s.wxString::ToAscii();
00182     } else {
00183       const wxWX2MBbuf tmp_buf = wxConvCurrent->cWX2MB(s);
00184       const char *tmp_str = (const char*) tmp_buf;
00185       s2=std::string(tmp_str, strlen(tmp_str));
00186     }
00187     return s2;
00188   }
00189   //==================================================================
00190 #endif // EO _USE_WXWIDGETS
00191 
00192   
00193 } // namespace bbtk
00194   
00195 
00196 #endif // EO __bbtkWx_h_INCLUDED__

Generated on Mon Jul 27 14:59:14 2009 for BBTK by  doxygen 1.5.3