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: 2010/01/14 13:17:27 $
00006   Version:   $Revision: 1.12 $
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 #ifndef __bbtkWx_h_INCLUDED__
00033 #define __bbtkWx_h_INCLUDED__
00034 
00035 //===========================================================================
00036 // Wx headers
00037 #ifdef USE_WXWIDGETS
00038 // For compilers that support precompilation, includes "wx/wx.h".
00039 #include "wx/wxprec.h"
00040 #include <wx/datetime.h>
00041 
00042 
00043 #ifdef __BORLANDC__
00044 #pragma hdrstop
00045 #endif
00046 
00047 #ifndef WX_PRECOMP
00048 #include <wx/wx.h>
00049 #endif
00050 
00051 #ifdef __WXGTK__
00052 # include <locale.h>
00053 #endif //__WXGTK__
00054 // EO Wx headers
00055 
00056 #else //USE_WXWIDGETS
00057 
00058 // define wxWindow
00059 typedef void wxWindow;
00060 typedef void wxBusyCursor;
00061 
00062 #endif // EO USE_WXWIDGETS
00063 //===========================================================================
00064 
00065 //===========================================================================
00066 #include "bbtkSystem.h"
00067 //===========================================================================
00068 
00069 //===========================================================================
00070 // SIGNAL/SLOT MECHANISM 
00071 // FOR bbtk WINDOWS CREATION/DESTRUCTION OBSERVATION 
00072 // BBTKWXSIG
00073 #include <boost/signal.hpp>
00074 #include <boost/bind.hpp>
00075 // \BBTKWXSIG
00076 //===========================================================================
00077 
00078 namespace bbtk
00079 {
00080 
00081   //==================================================================
00083   
00084 // BBTKWXSIG
00085 #define bbtkAddWxSignalObserver(METHOD)         \
00086   Wx::AddSignalObserver(boost::bind(&METHOD, this))
00087 // \BBTKWXSIG
00088 
00089 #define BBTK_BUSY_CURSOR bbtk::Wx::BusyCursor __bbtk_dummy_busy_cursor;
00090 
00091   struct BBTK_EXPORT Wx
00092   {     
00093   public:
00094     // BBTKWXSIG
00095     typedef boost::signals::trackable SignalObserver;
00096     typedef boost::signal<void ()>  Signal_type;
00097     typedef Signal_type::slot_function_type Slot_function_type;
00098     // \BBTKWXSIG
00099 
00100     class BusyCursor
00101     {
00102     public:
00103       BusyCursor();
00104       ~BusyCursor();
00105       wxBusyCursor* mCursor;
00106     };
00107 
00108     static void ProcessPendingEvents();
00109     
00111     static void SetTopWindow(wxWindow*);
00113     static wxWindow* GetTopWindow();
00114 
00115 
00116     static void IncNbWindowsAlive();
00117     static void DecNbWindowsAlive();
00118     static int  GetNbWindowsAlive();
00119     static bool IsSomeWindowAlive();
00120     
00121      // BBTKWXSIG
00122     static void AddSignalObserver(Slot_function_type);
00123     // \BBTKWXSIG
00124 
00125   
00126   private:
00127 
00128     static void CreateWxAppIfNeeded();
00129     static void DestroyWxAppIfNeeded();
00130 
00131   }; // struct Wx
00132   //==================================================================
00133 
00134 
00135 #ifdef USE_WXWIDGETS
00136   //==================================================================
00138   inline wxString std2wx(const std::string& s){
00139     wxString wx;
00140     const char* my_string=s.c_str();
00141     wxMBConvUTF8 *wxconv= new wxMBConvUTF8();
00142     wx=wxString(wxconv->cMB2WC(my_string),wxConvUTF8);
00143     delete wxconv;
00144     // test if conversion works of not. In case it fails convert from Ascii
00145     if(wx.length()==0)
00146       wx=wxString(wxString::FromAscii(s.c_str()));
00147     return wx;
00148   }
00149   //==================================================================
00150 
00151   //==================================================================
00153   inline std::string wx2std(const wxString& s){
00154     std::string s2;
00155     if(s.wxString::IsAscii()) {
00156       s2=s.wxString::ToAscii();
00157     } else {
00158       const wxWX2MBbuf tmp_buf = wxConvCurrent->cWX2MB(s);
00159       const char *tmp_str = (const char*) tmp_buf;
00160       s2=std::string(tmp_str, strlen(tmp_str));
00161     }
00162     return s2;
00163   }
00164   //==================================================================
00165 #endif // EO _USE_WXWIDGETS
00166 
00167   
00168 } // namespace bbtk
00169   
00170 
00171 #endif // EO __bbtkWx_h_INCLUDED__

Generated on Thu May 31 14:12:03 2012 for BBTK by  doxygen 1.5.7.1