00001 /*========================================================================= 00002 Program: bbtk 00003 Module: $RCSfile: bbtkWx.cxx,v $ 00004 Language: C++ 00005 Date: $Date: 2010/01/14 13:17:27 $ 00006 Version: $Revision: 1.16 $ 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 #include "bbtkWx.h" 00032 #include "bbtkMessageManager.h" 00033 00034 #ifdef _USE_WXWIDGETS_ 00035 00036 namespace bbtk 00037 { 00038 //========================================================================= 00039 class WxApp; 00040 //========================================================================= 00041 00042 //========================================================================= 00043 static WxApp* mgWxApp = 0; 00044 static wxWindow* mgTopWindow = 0; 00045 static int mgNbWindowsAlive = 0; 00046 //========================================================================= 00047 00048 //========================================================================= 00049 // BBTKWXSIG 00050 static Wx::Signal_type mgWxSignal; 00051 // \BBTKWXSIG 00052 //========================================================================= 00053 00054 00055 //========================================================================= 00056 // The wxApp class which is used when no user wxApp was created 00057 class WxApp : public wxApp 00058 { 00059 public: 00060 bool OnInit( ); 00061 int OnExit() { return true; } 00062 }; 00063 //========================================================================= 00064 IMPLEMENT_APP_NO_MAIN(WxApp); 00065 //========================================================================= 00066 bool WxApp::OnInit( ) 00067 { 00068 wxApp::OnInit(); 00069 #ifdef __WXGTK__ 00070 //See http://www.wxwindows.org/faqgtk.htm#locale 00071 setlocale(LC_NUMERIC, "C"); 00072 #endif 00073 return true; 00074 } 00075 //========================================================================= 00076 00077 //========================================================================= 00078 void Wx::CreateWxAppIfNeeded() 00079 { 00080 if (wxApp::GetInstance()==0) 00081 { 00082 if (mgWxApp != 0) 00083 { 00084 bbtkGlobalError("Wx::CreateWxAppIfNeeded() : INTERNAL ERROR ! (wxApp::GetInstance()==0) && (mgWxApp != 0)"); 00085 } 00086 bbtkDebugMessage("wx",1," --> Creating bbtk wxApp"<<std::endl); 00087 mgWxApp = new WxApp; 00088 wxApp::SetInstance(mgWxApp); 00089 wxInitialize(); 00090 } 00091 } 00092 //========================================================================= 00093 00094 //========================================================================= 00095 void Wx::DestroyWxAppIfNeeded() 00096 { 00097 if (mgWxApp!= 0) 00098 { 00099 // bbtkDebugMessage("wx",1," --> Destructing bbtk WxApp"<<std::endl); 00100 //delete mgWxApp; 00101 // mgWxApp = 0; 00102 // Uninit wx 00103 // wxUninitialize(); 00104 } 00105 } 00106 //========================================================================= 00107 00108 00109 //========================================================================= 00110 void Wx::ProcessPendingEvents() 00111 { 00112 /* 00113 if (Wx::GetTopWindow() != 0) 00114 { 00115 Wx::GetTopWindow()->DestroyChildren(); 00116 } 00117 */ 00118 00119 /* 00120 wxApp* a = (wxApp*)wxApp::GetInstance(); 00121 if (a==0) return; 00122 00123 std::cout << "$$$$$$$$$$$$$$ PROCESS PENDING "<<std::endl; 00124 while (a->Pending()) 00125 a->Dispatch(); 00126 std::cout << "$$$$$$$$$$$$$$ PROCESS PENDING DONE"<<std::endl; 00127 */ 00128 } 00129 00130 00131 //========================================================================= 00132 wxWindow* Wx::GetTopWindow() 00133 { 00134 return mgTopWindow; 00135 } 00136 //========================================================================= 00137 00138 00139 // BBTKWXSIG 00140 //========================================================================= 00141 void Wx::AddSignalObserver(Slot_function_type f) 00142 { 00143 mgWxSignal.connect(f); 00144 } 00145 //========================================================================= 00146 // \BBTKWXSIG 00147 00148 00149 //========================================================================= 00150 void Wx::SetTopWindow(wxWindow* w) 00151 { 00152 if ( mgTopWindow ) 00153 { 00154 bbtkGlobalError("Wx::SetTopWindow : top window already set !"); 00155 } 00156 //mgTopWindow = w; 00157 } 00158 //========================================================================= 00159 00160 00161 //========================================================================= 00162 void Wx::IncNbWindowsAlive() 00163 { 00164 mgNbWindowsAlive++; 00165 bbtkDebugMessage("wx",2,"* Number of windows alive = "<<mgNbWindowsAlive 00166 <<std::endl); 00167 // BBTKWXSIG 00168 mgWxSignal(); 00169 // \BBTKWXSIG 00170 } 00171 //========================================================================= 00172 00173 //========================================================================= 00174 void Wx::DecNbWindowsAlive() 00175 { 00176 mgNbWindowsAlive--; 00177 bbtkDebugMessage("wx",2,"* Number of windows alive = "<<mgNbWindowsAlive 00178 <<std::endl); 00179 00180 // BBTKWXSIG 00181 mgWxSignal(); 00182 // \BBTKWXSIG 00183 } 00184 //========================================================================= 00185 00186 //========================================================================= 00187 int Wx::GetNbWindowsAlive() 00188 { 00189 return mgNbWindowsAlive; 00190 } 00191 //========================================================================= 00192 00193 //========================================================================= 00194 bool Wx::IsSomeWindowAlive() 00195 { 00196 return (mgNbWindowsAlive!=0); 00197 } 00198 //========================================================================= 00199 00200 00201 //========================================================================= 00202 Wx::BusyCursor::BusyCursor() 00203 { 00204 mCursor = 0; 00205 if (wxApp::GetInstance()!=0) 00206 { 00207 bbtkDebugMessage("wx",2, 00208 "Wx::BusyCursor::BusyCursor() : creating new cursor" 00209 <<std::endl); 00210 //mCursor = new wxBusyCursor; 00211 } 00212 } 00213 //========================================================================= 00214 //========================================================================= 00215 Wx::BusyCursor::~BusyCursor() 00216 { 00217 if (mCursor) 00218 { 00219 //delete mCursor; 00220 bbtkDebugMessage("wx",2, 00221 "Wx::BusyCursor::~BusyCursor() : deleting cursor"<<std::endl); 00222 } 00223 } 00224 //========================================================================= 00225 00226 00227 00228 } // namespace bbtk 00229 00230 #else 00231 //======================================================================= 00232 // WITHOUT WX 00233 //========================================================================= 00234 namespace bbtk 00235 { 00236 //========================================================================= 00237 Wx::BusyCursor::BusyCursor() 00238 { 00239 } 00240 Wx::BusyCursor::~BusyCursor() 00241 { 00242 } 00243 //========================================================================= 00244 00245 } // namespace bbtk 00246 #endif 00247