#include "bbtkWx.h"
#include "bbtkMessageManager.h"
+#include <boost/signal.hpp>
+//#include <boost/bind.hpp>
namespace bbtk
{
- void wx::ResetCursor()
+
+ static wxWindow* mgTopWindow = 0;
+ static int mgNbWindowsAlive = 0;
+ static int mgNbWindowsShown = 0;
+ static bool mgAutoDestroyTopWindow = true;
+
+ // BBTKWXSIG
+ static Wx::Signal_type mgWxSignal;
+ // \BBTKWXSIG
+
+
+ //=========================================================================
+ void Wx::CreateTopWindow(wxWindow* parent, bool autodestroy)
+ {
+ wxWindow* top =
+ new wxFrame(parent,
+ -1,
+ _T("TOP BBTK FRAME (YOU SHOULD NOT SEE ME !!)"));
+ top->Hide();
+ Wx::SetTopWindow(top);
+ mgAutoDestroyTopWindow = autodestroy;
+ }
+ //=========================================================================
+
+ //=========================================================================
+ wxWindow* Wx::GetTopWindow()
+ {
+ if (mgTopWindow==0) Wx::CreateTopWindow(0);
+ return mgTopWindow;
+ }
+ //=========================================================================
+
+ //=========================================================================
+ bool Wx::TopWindowExists()
+ {
+ return (mgTopWindow!=0);
+ }
+ //=========================================================================
+
+ // BBTKWXSIG
+ //=========================================================================
+ void Wx::AddSignalObserver(Slot_function_type f)
+ {
+ mgWxSignal.connect(f);
+ }
+ //=========================================================================
+ // \BBTKWXSIG
+
+ //=========================================================================
+ void Wx::AutoDestroyTopWindow(bool b)
+ {
+ mgAutoDestroyTopWindow = b;
+ }
+ //=========================================================================
+
+ //=========================================================================
+ void Wx::SetTopWindow(wxWindow* w)
+ {
+ if ( mgTopWindow )
+ {
+ bbtkGlobalError("wx::SetTopWindow : top window already set !");
+ }
+ mgTopWindow = w;
+ }
+ //=========================================================================
+
+
+ //=========================================================================
+ void Wx::IncNbWindowsAlive()
+ {
+ mgNbWindowsAlive++;
+ bbtkDebugMessage("wx",2,"* Number of windows alive = "<<mgNbWindowsAlive
+ <<std::endl);
+ // BBTKWXSIG
+ mgWxSignal();
+ // \BBTKWXSIG
+ }
+ //=========================================================================
+
+ //=========================================================================
+ void Wx::DecNbWindowsAlive()
+ {
+ mgNbWindowsAlive--;
+ bbtkDebugMessage("wx",2,"* Number of windows alive = "<<mgNbWindowsAlive
+ <<std::endl);
+ if ( (mgNbWindowsAlive==0) &&
+ (mgAutoDestroyTopWindow) )
+ {
+ bbtkDebugMessage("wx",2," --> Destructing top window"<<std::endl);
+ mgTopWindow->Close();
+ mgTopWindow = 0;
+ }
+ // BBTKWXSIG
+ mgWxSignal();
+ // \BBTKWXSIG
+ }
+ //=========================================================================
+
+ //=========================================================================
+ void Wx::IncNbWindowsShown()
+ {
+ mgNbWindowsShown++;
+ bbtkDebugMessage("wx",2,"* Number of windows shown = "<<mgNbWindowsShown
+ <<std::endl);
+ // BBTKWXSIG
+ mgWxSignal();
+ // \BBTKWXSIG
+ }
+ //=========================================================================
+
+ //=========================================================================
+ void Wx::DecNbWindowsShown()
+ {
+ mgNbWindowsShown--;
+ bbtkDebugMessage("wx",2,"* Number of windows shown = "<<mgNbWindowsShown
+ <<std::endl);
+ if ( (mgNbWindowsAlive==0) &&
+ (mgAutoDestroyTopWindow) )
+ {
+ bbtkDebugMessage("wx",2," --> Destructing top window"<<std::endl);
+ mgTopWindow->Close();
+ mgTopWindow = 0;
+ }
+ // BBTKWXSIG
+ mgWxSignal();
+ // \BBTKWXSIG
+ }
+ //=========================================================================
+
+
+ //=========================================================================
+ int Wx::GetNbWindowsAlive()
+ {
+ return mgNbWindowsAlive;
+ }
+ //=========================================================================
+
+ //=========================================================================
+ bool Wx::IsSomeWindowAlive()
+ {
+ return (mgNbWindowsAlive>0);
+ }
+ //=========================================================================
+
+
+ //=========================================================================
+ int Wx::GetNbWindowsShown()
+ {
+ return mgNbWindowsShown;
+ }
+ //=========================================================================
+
+ //=========================================================================
+ bool Wx::IsSomeWindowShown()
+ {
+ return (mgNbWindowsShown>0);
+ }
+ //=========================================================================
+
+ //=========================================================================
+ void Wx::ResetCursor()
{
- bbtkDebugMessage("Wx",9,"wx::ResetCursor()"<<std::endl);
+ if (!TopWindowExists()) return;
+ bbtkDebugMessage("wx",9,"Wx::ResetCursor()"<<std::endl);
while (wxIsBusy()) ::wxEndBusyCursor();
}
- void wx::BeginBusyCursor()
+ //=========================================================================
+ //=========================================================================
+ void Wx::BeginBusyCursor()
{
- bbtkDebugMessage("Wx",9,"wx::BeginBusyCursor()"<<std::endl);
+ if (!TopWindowExists()) return;
+ bbtkDebugMessage("wx",9,"Wx::BeginBusyCursor()"<<std::endl);
::wxBeginBusyCursor();
}
- void wx::EndBusyCursor()
+ //=========================================================================
+ //=========================================================================
+ void Wx::EndBusyCursor()
{
- bbtkDebugMessage("Wx",9,"wx::EndBusyCursor()"<<std::endl);
+ if (!TopWindowExists()) return;
+ bbtkDebugMessage("wx",9,"Wx::EndBusyCursor()"<<std::endl);
::wxEndBusyCursor();
}
-
+ //=========================================================================
+
}