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: 2008/10/17 08:18:14 $
00006   Version:   $Revision: 1.8 $
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 
00084 #endif // EO _USE_WXWIDGETS_
00085 //===========================================================================
00086 
00087 //===========================================================================
00088 #include "bbtkSystem.h"
00089 //===========================================================================
00090 
00091 //===========================================================================
00092 // SIGNAL/SLOT MECHANISM 
00093 // FOR bbtk WINDOWS CREATION/DESTRUCTION OBSERVATION 
00094 // BBTKWXSIG
00095 #include <boost/signal.hpp>
00096 #include <boost/bind.hpp>
00097 // \BBTKWXSIG
00098 //===========================================================================
00099 
00100 namespace bbtk
00101 {
00102 
00103   //==================================================================
00105   
00106 // BBTKWXSIG
00107 #define bbtkAddWxSignalObserver(METHOD)         \
00108   Wx::AddSignalObserver(boost::bind(&METHOD, this))
00109 // \BBTKWXSIG
00110 
00111 #define BBTK_BUSY_CURSOR bbtk::Wx::BusyCursor __bbtk_dummy_busy_cursor;
00112 
00113   struct BBTK_EXPORT Wx
00114   {     
00115   public:
00116     // BBTKWXSIG
00117     typedef boost::signals::trackable SignalObserver;
00118     typedef boost::signal<void ()>  Signal_type;
00119     typedef Signal_type::slot_function_type Slot_function_type;
00120     // \BBTKWXSIG
00121 
00122     /*
00123     static void ResetCursor();
00124     static void BeginBusyCursor(); 
00125     static void EndBusyCursor();
00126     */
00127 
00128     static void LoopUntilAllWindowsClose();
00129 
00130     class BusyCursor
00131     {
00132     public:
00133       BusyCursor();
00134       ~BusyCursor();
00135       wxBusyCursor* mCursor;
00136     };
00137 
00138     static void SetTopWindowParent(wxWindow*);
00139     static void SetAutoDestroyTopWindow(bool);
00140 
00143     static wxWindow* GetTopWindow();
00144     static bool TopWindowExists();
00145     
00146     static void IncNbWindowsAlive();
00147     static void DecNbWindowsAlive();
00148     static int  GetNbWindowsAlive();
00149     static bool IsSomeWindowAlive();
00150     
00151     static void IncNbWindowsShown();
00152     static void DecNbWindowsShown();
00153     static int  GetNbWindowsShown();
00154     static bool IsSomeWindowShown();
00155 
00156     // BBTKWXSIG
00157     static void AddSignalObserver(Slot_function_type);
00158     // \BBTKWXSIG
00159 
00160   private:
00161 
00162     static void CreateWxAppIfNeeded();
00163     static void DestroyWxAppIfNeeded();
00164 
00165     static void CreateTopWindowIfNeeded();
00166     static void DestroyTopWindowIfNeeded();
00167 
00169     static void SetTopWindow(wxWindow*);
00170   }; // struct Wx
00171   //==================================================================
00172   
00173 
00174 
00175 
00176 #ifdef _USE_WXWIDGETS_
00177   //==================================================================
00179   inline wxString std2wx(const std::string& s){
00180     wxString wx;
00181     const char* my_string=s.c_str();
00182     wxMBConvUTF8 *wxconv= new wxMBConvUTF8();
00183     wx=wxString(wxconv->cMB2WC(my_string),wxConvUTF8);
00184     delete wxconv;
00185     // test if conversion works of not. In case it fails convert from Ascii
00186     if(wx.length()==0)
00187       wx=wxString(wxString::FromAscii(s.c_str()));
00188     return wx;
00189   }
00190   //==================================================================
00191 
00192   //==================================================================
00194   inline std::string wx2std(const wxString& s){
00195     std::string s2;
00196     if(s.wxString::IsAscii()) {
00197       s2=s.wxString::ToAscii();
00198     } else {
00199       const wxWX2MBbuf tmp_buf = wxConvCurrent->cWX2MB(s);
00200       const char *tmp_str = (const char*) tmp_buf;
00201       s2=std::string(tmp_str, strlen(tmp_str));
00202     }
00203     return s2;
00204   }
00205   //==================================================================
00206 #endif // EO _USE_WXWIDGETS
00207 
00208   
00209 } // namespace bbtk
00210   
00211 
00212 #endif // EO __bbtkWx_h_INCLUDED__

Generated on Wed Nov 12 11:37:08 2008 for BBTK by  doxygen 1.5.6