From ee4387cc1d36070c2a0a23bf335bb1e6714d83fd Mon Sep 17 00:00:00 2001 From: GillesDuvert Date: Mon, 2 Jan 2023 19:11:24 +0100 Subject: [PATCH 1/8] may well be the culprit of #1461 --- src/devicewx.hpp | 4 ++-- src/gdlwidgeteventhandler.cpp | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/devicewx.hpp b/src/devicewx.hpp index d4e6929c5..9cc0bb568 100644 --- a/src/devicewx.hpp +++ b/src/devicewx.hpp @@ -189,8 +189,8 @@ if(hide) { plot->Connect(wxEVT_ERASE_BACKGROUND, wxEraseEventHandler(gdlwxDrawPanel::OnErase)); plotFrame->Connect(wxEVT_CLOSE_WINDOW, wxCloseEventHandler(gdlwxPlotFrame::OnUnhandledClosePlotFrame)); - // plotFrame->Connect(wxEVT_SIZE, wxSizeEventHandler(gdlwxPlotFrame::OnPlotSizeWithTimer)); - plotFrame->Connect(wxEVT_SIZE, wxSizeEventHandler(gdlwxPlotFrame::OnPlotWindowSize)); + plotFrame->Connect(wxEVT_SIZE, wxSizeEventHandler(gdlwxPlotFrame::OnPlotSizeWithTimer)); +// plotFrame->Connect(wxEVT_SIZE, wxSizeEventHandler(gdlwxPlotFrame::OnPlotWindowSize)); return true; } diff --git a/src/gdlwidgeteventhandler.cpp b/src/gdlwidgeteventhandler.cpp index 1632a3440..ff17d7c2b 100644 --- a/src/gdlwidgeteventhandler.cpp +++ b/src/gdlwidgeteventhandler.cpp @@ -959,7 +959,7 @@ void gdlwxPlotFrame::OnPlotSizeWithTimer(wxSizeEvent& event) { m_resizeTimer->Start(50, wxTIMER_ONE_SHOT); return; } else { //take it immediately. - m_resizeTimer->StartOnce(1); + m_resizeTimer->Stop(); //StartOnce(1); } } void gdlwxPlotFrame::OnPlotWindowSize(wxSizeEvent &event) { From ca2b0ea952ae074a6f86aa7312f7bd1632ac6a15 Mon Sep 17 00:00:00 2001 From: GillesDuvert Date: Tue, 3 Jan 2023 20:05:50 +0100 Subject: [PATCH 2/8] OK by using a wxPaintDC in a PaintEvent, and nowhere esle, the paint problem looks to have disappeared. --- src/devicewx.hpp | 14 +++++++------- src/gdlwidget.cpp | 24 ++++++++++-------------- src/gdlwidget.hpp | 2 +- src/gdlwidgeteventhandler.cpp | 34 ++++++++++++++++++---------------- src/gdlwxstream.cpp | 14 ++------------ src/gdlwxstream.hpp | 1 - 6 files changed, 38 insertions(+), 51 deletions(-) diff --git a/src/devicewx.hpp b/src/devicewx.hpp index 9cc0bb568..4dae9fd22 100644 --- a/src/devicewx.hpp +++ b/src/devicewx.hpp @@ -172,15 +172,15 @@ if(hide) { } else { plotFrame->Show(); //WithoutActivating(); --> this does nothing good. Better tailor your window manager to 'focus under mouse" // plotFrame->UpdateWindowUI(); not useful - plotFrame->Refresh(); - plotFrame->Update(); plotFrame->Raise(); + plotFrame->Refresh(); +// plotFrame->Update(); //really show by letting the loop do its magic. Necessary. -#ifdef __WXMAC__ - wxTheApp->Yield(); -#else - wxGetApp().MainLoop(); //central loop for wxEvents! -#endif +//#ifdef __WXMAC__ +// wxTheApp->Yield(); +//#else +// wxGetApp().MainLoop(); //central loop for wxEvents! +//#endif } // these widget specific events are always set: diff --git a/src/gdlwidget.cpp b/src/gdlwidget.cpp index 8c7a5f8b2..e08167181 100644 --- a/src/gdlwidget.cpp +++ b/src/gdlwidget.cpp @@ -563,14 +563,14 @@ void GDLWidget::UpdateGui() actID = widget->parentID; } this->GetMyTopLevelFrame()->Fit(); -// this->GetMyTopLevelFrame()->Refresh(); - this->GetMyTopLevelFrame()->Update(); + this->GetMyTopLevelFrame()->Refresh(); +// this->GetMyTopLevelFrame()->Update(); END_CHANGESIZE_NOEVENT -#ifdef __WXMAC__ - wxTheApp->Yield(); -#else - wxGetApp().MainLoop(); //central loop for wxEvents! -#endif +//#ifdef __WXMAC__ +// wxTheApp->Yield(); +//#else +// wxGetApp().MainLoop(); //central loop for wxEvents! +//#endif } //Alternate version if there were sizing problems with the one above. @@ -6108,12 +6108,10 @@ gdlwxPlotPanel::gdlwxPlotPanel( gdlwxPlotFrame* parent) //, wxWindowID id, const void gdlwxGraphicsPanel::RepaintGraphics(bool doClear) { wxClientDC dc(this); //is a scrolled window: needed - DoPrepareDC(dc); //you probably do not want to call wxScrolled::PrepareDC() on wxAutoBufferedPaintDC as it already does this internally for the real underlying wxPaintDC. -// dc.SetDeviceClippingRegion(GetUpdateRegion()); +// DoPrepareDC(dc); //you probably do not want to call wxScrolled::PrepareDC() on wxAutoBufferedPaintDC as it already does this internally for the real underlying wxPaintDC. +//// dc.SetDeviceClippingRegion(GetUpdateRegion()); if (doClear) dc.Clear(); - dc.Blit(0, 0, drawSize.x, drawSize.y, wx_dc, 0, 0); -// this->Refresh(); -// this->Update(); + this->Refresh(); //--> will call PAINT EVENT, this one will blit and work. } ////Stem for generalization of Drag'n'Drop, a WIDGET_DRAW can receive drop events from something else than a tree widget... @@ -6267,8 +6265,6 @@ GDLWidgetDraw::GDLWidgetDraw( WidgetIDT p, EnvT* e, int windowIndex, //these widget specific events are always set: this->AddToDesiredEvents( wxEVT_PAINT, wxPaintEventHandler(gdlwxDrawPanel::OnPaint),draw); - this->AddToDesiredEvents( wxEVT_PAINT, wxPaintEventHandler(gdlwxDrawPanel::OnPaint),draw); -// this->AddToDesiredEvents( wxEVT_SIZE, wxSizeEventHandler(gdlwxDrawPanel::OnSize),draw); //disable flicker see https://wiki.wxwidgets.org/Flicker-Free_Drawing this->AddToDesiredEvents( wxEVT_ERASE_BACKGROUND, wxEraseEventHandler(gdlwxDrawPanel::OnErase),draw); diff --git a/src/gdlwidget.hpp b/src/gdlwidget.hpp index 373279a33..62e447610 100644 --- a/src/gdlwidget.hpp +++ b/src/gdlwidget.hpp @@ -2072,7 +2072,7 @@ class gdlwxPlotFrame : public wxFrame { void OnTimerPlotResize(wxTimerEvent& event); void OnUnhandledClosePlotFrame(wxCloseEvent & event); void OnPlotSizeWithTimer(wxSizeEvent& event); - void OnPlotWindowSize(wxSizeEvent& event); +// void OnPlotWindowSize(wxSizeEvent& event); //unused DECLARE_EVENT_TABLE() }; class GDLWXStream; diff --git a/src/gdlwidgeteventhandler.cpp b/src/gdlwidgeteventhandler.cpp index ff17d7c2b..ff91f3463 100644 --- a/src/gdlwidgeteventhandler.cpp +++ b/src/gdlwidgeteventhandler.cpp @@ -962,18 +962,18 @@ void gdlwxPlotFrame::OnPlotSizeWithTimer(wxSizeEvent& event) { m_resizeTimer->Stop(); //StartOnce(1); } } -void gdlwxPlotFrame::OnPlotWindowSize(wxSizeEvent &event) { - - wxSize newSize = event.GetSize(); //size returned by the external frame - gdlwxGraphicsPanel* w = dynamic_cast (this->GetChildren().GetFirst()->GetData()); - if (w==NULL) { - event.Skip(); - std::cerr<<"No wxWidget!"<GetId()); - w->OnPlotWindowSize(sizeEvent); - event.Skip(); -} +//void gdlwxPlotFrame::OnPlotWindowSize(wxSizeEvent &event) { +// +// wxSize newSize = event.GetSize(); //size returned by the external frame +// gdlwxGraphicsPanel* w = dynamic_cast (this->GetChildren().GetFirst()->GetData()); +// if (w==NULL) { +// event.Skip(); +// std::cerr<<"No wxWidget!"<GetId()); +// w->OnPlotWindowSize(sizeEvent); +// event.Skip(); +//} //same for widget_draw // mouse.LeftIsDown() is not present before wxWidgets 2.8.12 , find an alternative. @@ -1033,7 +1033,7 @@ void gdlwxFrame::OnSizeWithTimer(wxSizeEvent& event) m_resizeTimer->Start(50, wxTIMER_ONE_SHOT); return; } else { //take it immediately. - m_resizeTimer->StartOnce(1); + m_resizeTimer->Stop(); //StartOnce(1); } } @@ -1353,12 +1353,14 @@ void gdlwxDrawPanel::OnErase(wxEraseEvent& event) void gdlwxGraphicsPanel::OnPaint(wxPaintEvent& event) { - if (drawSize.x<1||drawSize.y<1) return; + if (drawSize.x<1||drawSize.y<1) return; #if (GDL_DEBUG_ALL_EVENTS || GDL_DEBUG_PAINT_EVENTS) wxMessageOutputStderr().Printf(_T("in gdlwxGraphicsPanel::OnPaint: %d (%d,%d)\n"),event.GetId(),drawSize.x, drawSize.y); #endif - this->RepaintGraphics(); - event.Skip(); + wxPaintDC dc(this); + DoPrepareDC(dc); //you probably do not want to call wxScrolled::PrepareDC() on wxAutoBufferedPaintDC as it already does this internally for the real underlying wxPaintDC. + dc.SetDeviceClippingRegion(GetUpdateRegion()); + dc.Blit(0, 0, drawSize.x, drawSize.y, wx_dc, 0, 0); } void gdlwxPlotPanel::OnPlotWindowSize(wxSizeEvent &event) { diff --git a/src/gdlwxstream.cpp b/src/gdlwxstream.cpp index 7b58e0432..1a63b4d04 100644 --- a/src/gdlwxstream.cpp +++ b/src/gdlwxstream.cpp @@ -123,20 +123,10 @@ void GDLWXStream::SetGdlxwGraphicsPanel(gdlwxGraphicsPanel* w, bool isPlot) isplot=isPlot; } -void GDLWXStream::DoUpdate() +void GDLWXStream::Update() { - if( this->valid && container != NULL) { - container->RepaintGraphics(); - //will be updated by eventloop. -//#ifdef __WXMAC__ -// wxTheApp->Yield(); -//#else -// wxGetApp().MainLoop(); //central loop for wxEvents! -//#endif - } + if( this->valid && container != NULL) container->Refresh(); } -//We should not need "Update" -void GDLWXStream::Update(){DoUpdate();} ////should be used when one does not recreate a wxstream each time size changes... void GDLWXStream::SetSize( wxSize s ) { diff --git a/src/gdlwxstream.hpp b/src/gdlwxstream.hpp index d0c1e9516..b1ff878af 100644 --- a/src/gdlwxstream.hpp +++ b/src/gdlwxstream.hpp @@ -54,7 +54,6 @@ class GDLWXStream: public GDLGStream // void set_stream(); //!< Calls some code before every PLplot command. void SetSize( const wxSize s ); //!< Set new size of plot area. void RenewPlot(); //!< Redo plot. - void DoUpdate(); virtual void Update() final; void SetGdlxwGraphicsPanel(gdlwxGraphicsPanel* w, bool isPlot=true); gdlwxGraphicsPanel* GetMyContainer(){return container;} From 0d3bc846e1b02b924ee30a46d893aabdf789dc31 Mon Sep 17 00:00:00 2001 From: GillesDuvert Date: Wed, 4 Jan 2023 20:14:44 +0100 Subject: [PATCH 3/8] new implementation of wxAPP loop --- simpler, cleaner and does not crash apparently OSX windows now are in front when clicked (even if it uses an obsolete code) and so widgets work, yahoo. OSX strangely does not run the wxApp loop as on UNIX and Windows. So we still need to use Yield() and I very much want to know why. --- src/devicewx.hpp | 3 +- src/gdl.cpp | 2 +- src/gdlwidget.cpp | 77 +++++++++++++++++++-------------------------- src/gdlwidget.hpp | 8 +++-- src/gdlwxstream.cpp | 9 +++++- src/widget.cpp | 5 +-- 6 files changed, 49 insertions(+), 55 deletions(-) diff --git a/src/devicewx.hpp b/src/devicewx.hpp index 4dae9fd22..4f8d4f0f3 100644 --- a/src/devicewx.hpp +++ b/src/devicewx.hpp @@ -174,12 +174,11 @@ if(hide) { // plotFrame->UpdateWindowUI(); not useful plotFrame->Raise(); plotFrame->Refresh(); -// plotFrame->Update(); //really show by letting the loop do its magic. Necessary. //#ifdef __WXMAC__ // wxTheApp->Yield(); //#else -// wxGetApp().MainLoop(); //central loop for wxEvents! +// wxGetApp().MyLoop(); //central loop for wxEvents! //#endif } diff --git a/src/gdl.cpp b/src/gdl.cpp index 65b4d436c..d1887c944 100644 --- a/src/gdl.cpp +++ b/src/gdl.cpp @@ -63,7 +63,7 @@ //we use gdlgstream in gdl.cpp #include "gdlgstream.hpp" -//initialize wxWidgets system +//initialize wxWidgets system: create an instance of wxAppGDL #ifdef HAVE_LIBWXWIDGETS #include "gdlwidget.hpp" #ifndef __WXMAC__ diff --git a/src/gdlwidget.cpp b/src/gdlwidget.cpp index e08167181..f6dc059e1 100644 --- a/src/gdlwidget.cpp +++ b/src/gdlwidget.cpp @@ -569,7 +569,7 @@ void GDLWidget::UpdateGui() //#ifdef __WXMAC__ // wxTheApp->Yield(); //#else -// wxGetApp().MainLoop(); //central loop for wxEvents! +// wxGetApp().MyLoop(); //central loop for wxEvents! //#endif } @@ -773,7 +773,7 @@ void GDLWidget::HandleWidgetEvents() #ifdef __WXMAC__ wxTheApp->Yield(); #else - wxGetApp().MainLoop(); //central loop for wxEvents! + wxGetApp().MyLoop(); //central loop for wxEvents! #endif //treat our GDL events... DStructGDL* ev = NULL; @@ -918,19 +918,23 @@ DLongGDL* GDLWidget::GetAllHeirs(){ for (SizeT i = 0; i < currentVectorSize ; ++i) (*result)[i] = widgetIDList[i]; return result; } +#ifdef __WXMAC__ + #include +extern "C" { void CPSEnableForegroundOperation( ProcessSerialNumber* psn ); } +#endif // -bool GDLWidget::InitWx() -{ if (wxTheApp == NULL) { //not already initialized -if (!wxInitialize()) { - std::cerr << "WARNING: wxWidgets not initializing, widget-related commands will not be available." << std::endl; - return false; - } -#ifndef __WXMAC__ - wxAppGDL* app = new wxAppGDL(); - app->SetInstance(app); -#endif -} else {std::cerr << "INFO: wxWidgets already initialized (in 3rd party library?), pursue with fingers crossed" << std::endl; } +bool GDLWidget::InitWx() { + // this hack enables to have a GUI on Mac OSX even if the + // program was called from the command line (and isn't a bundle) + #ifdef __WXMAC__ + ProcessSerialNumber psn; + + GetCurrentProcess( &psn ); + CPSEnableForegroundOperation( &psn ); + SetFrontProcess( &psn ); + #endif + wxInitialize(); wxInitAllImageHandlers(); //do it here once for all return true; } @@ -949,9 +953,6 @@ void GDLWidget::Init() //initially defaultFont and systemFont are THE SAME. defaultFont=systemFont; SetWxStarted(); -#ifndef __WXMAC__ - wxGetApp().OnInit(); -#endif //initialize default image lists for trees: // Make an image list containing small icons wxSize ImagesSize(DEFAULT_TREE_IMAGE_SIZE,DEFAULT_TREE_IMAGE_SIZE); @@ -967,7 +968,12 @@ void GDLWidget::Init() gdlDefaultTreeStateImages->Add(wxIcon(pixmap_checked)); //gdlWxTree_UNCHECKED //create wxIcon HERE and not before wxWidgets is started! wxgdlicon = wxIcon(gdlicon_xpm); -} + //use a phantom window to retrieve the exact size of scrollBars wxWidget give wrong values. + gdlwxPhantomFrame* test = new gdlwxPhantomFrame(); + test->Hide(); + test->Realize(); + test->Destroy(); + } //ResetWidgets void GDLWidget::ResetWidgets() { //Delete current widgets --- complicated, use utility procedure @@ -984,7 +990,7 @@ void GDLWidget::ResetWidgets() { #ifdef __WXMAC__ wxTheApp->Yield(); #else - wxGetApp().MainLoop(); //central loop for wxEvents! + wxGetApp().MyLoop(); //central loop for wxEvents! #endif } // UnInit @@ -6456,34 +6462,17 @@ void GDLWidgetDraw::SetWidgetScreenSize(DLong sizex, DLong sizey) { // So we rely only on doing nothing and call Yield() , that works, fingers crossed. // Really strange but wxWidgets is not well documented (who is?) #ifndef __WXMAC__ - -#include "wx/evtloop.h" -#include "wx/ptr_scpd.h" -wxDEFINE_TIED_SCOPED_PTR_TYPE(wxEventLoop); - -bool wxAppGDL::OnInit() -{ - //use a phantom window to retrieve the exact size of scrollBars wxWidget give wrong values. - gdlwxPhantomFrame* test = new gdlwxPhantomFrame(); - test->Hide(); - test->Realize(); - test->Destroy(); - return true; -} - -int wxAppGDL::MainLoop() { - wxEventLoopTiedPtr mainLoop((wxEventLoop **) & m_mainLoop, new wxEventLoop); - m_mainLoop->SetActive(m_mainLoop); - loop = this->GetMainLoop(); -// std::cerr<IsRunning()) { - while (loop->Pending()) // Unprocessed events in queue - { - loop->Dispatch(); // Dispatch next event in queue +int wxAppGDL::MyLoop() { + if (loop.IsOk()) { +// std::cerr<<&loop<valid && container != NULL) container->Refresh(); + if( this->valid && container != NULL) { + container->Refresh(); +#ifdef __WXMAC__ + wxTheApp->Yield(); +#else + wxGetApp().MyLoop(); //central loop for wxEvents! +#endif + } } ////should be used when one does not recreate a wxstream each time size changes... void GDLWXStream::SetSize( wxSize s ) diff --git a/src/widget.cpp b/src/widget.cpp index 9f0678e1b..c86f12488 100644 --- a/src/widget.cpp +++ b/src/widget.cpp @@ -2495,7 +2495,7 @@ BaseGDL* widget_info( EnvT* e ) { #ifdef __WXMAC__ wxTheApp->Yield(); #else - wxGetApp().MainLoop(); //central loop for wxEvents! + wxGetApp().MyLoop(); //central loop for wxEvents! #endif if (!all) { //specific widget(s) @@ -2527,9 +2527,6 @@ BaseGDL* widget_info( EnvT* e ) { if (nowait) return defaultRes; if (sigControlC) return defaultRes; -#if __WXMSW__ - wxMilliSleep(20); // Sleep a bit to prevent CPU overuse //not useful if Yield() -#endif } //end inner loop //here we got a real event, process it, walking back the hierachy (in CallEventHandler()) for modified ev in case of function handlers. endwait: From 8c191dbecf7073c5cd56d7bbb0a482f3616718d7 Mon Sep 17 00:00:00 2001 From: GillesDuvert Date: Thu, 5 Jan 2023 14:20:18 +0100 Subject: [PATCH 4/8] evrything OK on ALL PLATFORMS! --- src/devicewx.hpp | 6 +- src/gdlwidget.cpp | 2 +- src/gdlwidget.hpp | 9 +-- src/gdlwidgeteventhandler.cpp | 113 +++++++++++++++++++--------------- 4 files changed, 72 insertions(+), 58 deletions(-) diff --git a/src/devicewx.hpp b/src/devicewx.hpp index 4f8d4f0f3..177299a76 100644 --- a/src/devicewx.hpp +++ b/src/devicewx.hpp @@ -188,9 +188,11 @@ if(hide) { plot->Connect(wxEVT_ERASE_BACKGROUND, wxEraseEventHandler(gdlwxDrawPanel::OnErase)); plotFrame->Connect(wxEVT_CLOSE_WINDOW, wxCloseEventHandler(gdlwxPlotFrame::OnUnhandledClosePlotFrame)); +#ifdef __WXMSW__ + plotFrame->Connect(wxEVT_SIZE, wxSizeEventHandler(gdlwxPlotFrame::OnPlotWindowSize)); //Timer resize do not work on MSW +#else plotFrame->Connect(wxEVT_SIZE, wxSizeEventHandler(gdlwxPlotFrame::OnPlotSizeWithTimer)); -// plotFrame->Connect(wxEVT_SIZE, wxSizeEventHandler(gdlwxPlotFrame::OnPlotWindowSize)); - +#endif return true; } diff --git a/src/gdlwidget.cpp b/src/gdlwidget.cpp index f6dc059e1..2ee719b00 100644 --- a/src/gdlwidget.cpp +++ b/src/gdlwidget.cpp @@ -944,7 +944,7 @@ void GDLWidget::Init() //set system font to something sensible now that wx is ON: if (forceWxWidgetsUglyFonts) systemFont = wxFont(8, wxFONTFAMILY_MODERN, wxFONTSTYLE_NORMAL,wxFONTWEIGHT_NORMAL) ;// identical for me to GDLWidget::setDefaultFont(wxFont("Monospace 8")); -#if __WXMSW__ //update for windows: +#ifdef __WXMSW__ //update for windows: bool ok=systemFont.SetNativeFontInfoUserDesc(wxString("consolas 8")); //consolas 8 is apparently the one most identical to linux courier 8 and IDL X11 default font. if (!ok) systemFont = wxFont(8, wxFONTFAMILY_MODERN, wxFONTSTYLE_NORMAL,wxFONTWEIGHT_NORMAL) ; #endif diff --git a/src/gdlwidget.hpp b/src/gdlwidget.hpp index d8240b88b..eb8095d30 100644 --- a/src/gdlwidget.hpp +++ b/src/gdlwidget.hpp @@ -95,8 +95,11 @@ #else #define NEWLINECHARSIZE 1 //length of #endif - +#ifdef __WXMSW__ +#define gdlSIZE_EVENT_HANDLER wxSizeEventHandler(gdlwxFrame::OnSize) //Timer resize do not work on MSW +#else #define gdlSIZE_EVENT_HANDLER wxSizeEventHandler(gdlwxFrame::OnSizeWithTimer) //filter mouse events (manual resize) to avoid too many updtes for nothing +#endif #define gdlSIZE_IMMEDIATE_EVENT_HANDLER wxSizeEventHandler(gdlwxFrame::OnSize) typedef DLong WidgetIDT; static std::string widgetNameList[]={"BASE","BUTTON","SLIDER","TEXT","DRAW","LABEL","LIST","MBAR","DROPLIST","TABLE","TAB","TREE","COMBOBOX","PROPERTYSHEET","WINDOW"}; @@ -2069,12 +2072,10 @@ class gdlwxPlotFrame : public wxFrame { bool IsScrolled(){return scrolled;} void Realize(); // event handlers (these functions should _not_ be virtual) -// void OnClosePlotFrame(wxCloseEvent & event); -// void OnPlotSizeWithTimer(wxSizeEvent& event); void OnTimerPlotResize(wxTimerEvent& event); void OnUnhandledClosePlotFrame(wxCloseEvent & event); void OnPlotSizeWithTimer(wxSizeEvent& event); -// void OnPlotWindowSize(wxSizeEvent& event); //unused + void OnPlotWindowSize(wxSizeEvent& event); //unused DECLARE_EVENT_TABLE() }; class GDLWXStream; diff --git a/src/gdlwidgeteventhandler.cpp b/src/gdlwidgeteventhandler.cpp index ff91f3463..0e182317c 100644 --- a/src/gdlwidgeteventhandler.cpp +++ b/src/gdlwidgeteventhandler.cpp @@ -909,13 +909,13 @@ void gdlwxFrame::OnPageChanged( wxNotebookEvent& event) } //Timer-filtered resizing for graphics. - -// mouse.LeftIsDown() is not present before wxWidgets 2.8.12 , find an alternative. -void gdlwxPlotFrame::OnTimerPlotResize(wxTimerEvent& event) -{ -#if (GDL_DEBUG_ALL_EVENTS || GDL_DEBUG_TIMER_EVENTS) - wxMessageOutputStderr().Printf(_T("in gdlwxFrame::OnTimerPlotResize: %d (%d,%d).."), event.GetId(), frameSize.x, frameSize.y); +// 1) the timer : restart if still resizing by hand +void gdlwxPlotFrame::OnPlotSizeWithTimer(wxSizeEvent& event) { + frameSize = event.GetSize(); +#if (GDL_DEBUG_ALL_EVENTS || GDL_DEBUG_SIZE_EVENTS) + wxMessageOutputStderr().Printf(_T("gdlwxPlotFrame::OnPlotSizeWithTimer: %d %d \n"), frameSize.x, frameSize.y); #endif + //is it a resize of frame due to a manual intervention? wxMouseState mouse = wxGetMouseState(); #if wxCHECK_VERSION(3,0,0) if (mouse.LeftIsDown()) { @@ -924,32 +924,26 @@ void gdlwxPlotFrame::OnTimerPlotResize(wxTimerEvent& event) #endif m_resizeTimer->Start(50, wxTIMER_ONE_SHOT); return; - } - //there may have been size events since the start of the timer. Process them. -// frameSize=this->GetSize(); - gdlwxGraphicsPanel* w = dynamic_cast (this->GetChildren().GetFirst()->GetData()); - if (w==NULL) { - event.Skip(); - std::cerr<<"No wxWidget!"<GetId()); - w->OnPlotWindowSize(sizeEvent); -#if (GDL_DEBUG_ALL_EVENTS || GDL_DEBUG_TIMER_EVENTS) - wxMessageOutputStderr().Printf(_T("gdlwxFrame::OnTimerPlotResize() has been Processed.\n")); + } else { //take it immediately. +#if (GDL_DEBUG_ALL_EVENTS || GDL_DEBUG_SIZE_EVENTS) + wxMessageOutputStderr().Printf(_T("gdlwxPlotFrame::OnPlotSizeWithTimer: handle new size \n")); #endif + m_resizeTimer->Stop(); //StartOnce(1); + } } +// 2) actual resize when mouse released +void gdlwxPlotFrame::OnTimerPlotResize(wxTimerEvent& event) { -void gdlwxPlotFrame::OnPlotSizeWithTimer(wxSizeEvent& event) { - wxSize newSize = event.GetSize(); - if (frameSize == newSize) { + gdlwxPlotPanel* w = dynamic_cast (this->GetChildren().GetFirst()->GetData()); + if (w == NULL) { event.Skip(); +#if (GDL_DEBUG_ALL_EVENTS || GDL_DEBUG_TIMER_EVENTS) + std::cerr << "No wxWidget!" << std::endl; return; - } - frameSize = newSize; //no cost -#if (GDL_DEBUG_ALL_EVENTS || GDL_DEBUG_SIZE_EVENTS) - wxMessageOutputStderr().Printf(_T("in gdlwxPlotWindow::OnPlotSizeWithTimer: new framesize is %d %d ; mouseState %d & Processed.\n"), frameSize.x, frameSize.y, wxGetMouseState().LeftIsDown()); #endif - //is it a resize of frame due to a manual intervention? + } + + frameSize=this->GetSize(); //event.GetSize(); wxMouseState mouse = wxGetMouseState(); #if wxCHECK_VERSION(3,0,0) if (mouse.LeftIsDown()) { @@ -958,30 +952,43 @@ void gdlwxPlotFrame::OnPlotSizeWithTimer(wxSizeEvent& event) { #endif m_resizeTimer->Start(50, wxTIMER_ONE_SHOT); return; - } else { //take it immediately. - m_resizeTimer->Stop(); //StartOnce(1); } + +#if (GDL_DEBUG_ALL_EVENTS || GDL_DEBUG_TIMER_EVENTS) + wxMessageOutputStderr().Printf(_T("in gdlwxPlotFrame::OnTimerPlotResize: event %d size: (%d,%d).."), event.GetId(), frameSize.x, frameSize.y); +#endif + + //there may have been size events since the start of the timer. Process them. +#if (GDL_DEBUG_ALL_EVENTS || GDL_DEBUG_TIMER_EVENTS) + wxMessageOutputStderr().Printf(_T(".. Processed.\n")); +#endif + wxSizeEvent sizeEvent(frameSize, w->GetId()); + w->OnPlotWindowSize(sizeEvent); +} + + //in case timers do not work (Windows, apparently). +void gdlwxPlotFrame::OnPlotWindowSize(wxSizeEvent &event) { + gdlwxPlotPanel* w = dynamic_cast (this->GetChildren().GetFirst()->GetData()); + if (w == NULL) { + event.Skip(); +#if (GDL_DEBUG_ALL_EVENTS || GDL_DEBUG_SIZE_EVENTS) + std::cerr << "No wxWidget!" << std::endl; + return; +#endif + } + + frameSize=event.GetSize(); +#if (GDL_DEBUG_ALL_EVENTS || GDL_DEBUG_SIZE_EVENTS) + wxMessageOutputStderr().Printf(_T("in gdlwxPlotFrame::OnPlotWindowSize: event %d size: (%d,%d) processed."), event.GetId(), frameSize.x, frameSize.y); +#endif + wxSizeEvent sizeEvent(frameSize, w->GetId()); + w->OnPlotWindowSize(sizeEvent); } -//void gdlwxPlotFrame::OnPlotWindowSize(wxSizeEvent &event) { -// -// wxSize newSize = event.GetSize(); //size returned by the external frame -// gdlwxGraphicsPanel* w = dynamic_cast (this->GetChildren().GetFirst()->GetData()); -// if (w==NULL) { -// event.Skip(); -// std::cerr<<"No wxWidget!"<GetId()); -// w->OnPlotWindowSize(sizeEvent); -// event.Skip(); -//} //same for widget_draw // mouse.LeftIsDown() is not present before wxWidgets 2.8.12 , find an alternative. void gdlwxFrame::OnTimerResize(wxTimerEvent& event) { -#if (GDL_DEBUG_ALL_EVENTS || GDL_DEBUG_TIMER_EVENTS) - wxMessageOutputStderr().Printf(_T("in gdlwxFrame::OnTimerResize: %d (%d,%d).."), event.GetId(), frameSize.x, frameSize.y); -#endif wxMouseState mouse = wxGetMouseState(); #if wxCHECK_VERSION(3,0,0) if (mouse.LeftIsDown()) { @@ -991,10 +998,13 @@ void gdlwxFrame::OnTimerResize(wxTimerEvent& event) m_resizeTimer->Start(50, wxTIMER_ONE_SHOT); return; } + + if (!gdlOwner) {event.Skip(); return; } + #if (GDL_DEBUG_ALL_EVENTS || GDL_DEBUG_TIMER_EVENTS) - wxMessageOutputStderr().Printf(_T("Processed.\n")); + wxMessageOutputStderr().Printf(_T("in gdlwxFrame::OnTimerResize: %d (%d,%d) processed.\n"), event.GetId(), frameSize.x, frameSize.y); #endif - if (!gdlOwner) {event.Skip(); return;} + GDLWidget* owner = dynamic_cast (gdlOwner); if (!owner) return; DULong flags = 0; @@ -1017,12 +1027,7 @@ void gdlwxFrame::OnTimerResize(wxTimerEvent& event) // The timer will be canceled and the actual size processed if the event shows that the mouse is not pressed anymore. void gdlwxFrame::OnSizeWithTimer(wxSizeEvent& event) { - wxSize newSize = event.GetSize(); - if (frameSize == newSize) {event.Skip();return;} - frameSize = newSize; //no cost -#if (GDL_DEBUG_ALL_EVENTS || GDL_DEBUG_SIZE_EVENTS) - wxMessageOutputStderr().Printf(_T("in gdlwxFrame::OnSizeWithTimer: new framesize is %d %d ; mouseState %d & Processed.\n"), frameSize.x, frameSize.y, wxGetMouseState().LeftIsDown()); -#endif + frameSize = event.GetSize(); //is it a resize of frame due to a manual intervention? wxMouseState mouse = wxGetMouseState(); #if wxCHECK_VERSION(3,0,0) @@ -1031,8 +1036,14 @@ void gdlwxFrame::OnSizeWithTimer(wxSizeEvent& event) if (mouse.LeftDown()) { #endif m_resizeTimer->Start(50, wxTIMER_ONE_SHOT); +#if (GDL_DEBUG_ALL_EVENTS || GDL_DEBUG_SIZE_EVENTS) + wxMessageOutputStderr().Printf(_T("in gdlwxFrame::OnSizeWithTimer: new framesize is %d %d ;\n"), frameSize.x, frameSize.y); +#endif return; } else { //take it immediately. +#if (GDL_DEBUG_ALL_EVENTS || GDL_DEBUG_SIZE_EVENTS) + wxMessageOutputStderr().Printf(_T("in gdlwxFrame::OnSizeWithTimer: new framesize is %d %d ; mouseState %d & Processed.\n"), frameSize.x, frameSize.y, wxGetMouseState().LeftIsDown()); +#endif m_resizeTimer->Stop(); //StartOnce(1); } } From 73a5a5848c4071ca78f702f865040a2a9f6aa216 Mon Sep 17 00:00:00 2001 From: GillesDuvert Date: Thu, 5 Jan 2023 18:00:24 +0100 Subject: [PATCH 5/8] a test --- src/gdlwidget.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/gdlwidget.cpp b/src/gdlwidget.cpp index 2ee719b00..b2c04b985 100644 --- a/src/gdlwidget.cpp +++ b/src/gdlwidget.cpp @@ -934,7 +934,9 @@ bool GDLWidget::InitWx() { CPSEnableForegroundOperation( &psn ); SetFrontProcess( &psn ); #endif - wxInitialize(); + try{ + wxInitialize(); + } catch (...) {return false;} wxInitAllImageHandlers(); //do it here once for all return true; } From 8368e45fd872f8a4756485548caa1966586284ba Mon Sep 17 00:00:00 2001 From: GillesDuvert Date: Thu, 5 Jan 2023 18:21:32 +0100 Subject: [PATCH 6/8] test2 --- src/gdlwidget.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/gdlwidget.cpp b/src/gdlwidget.cpp index b2c04b985..329caf134 100644 --- a/src/gdlwidget.cpp +++ b/src/gdlwidget.cpp @@ -25,6 +25,7 @@ #include #include #include +#include #include "basegdl.hpp" #include "dstructgdl.hpp" @@ -937,6 +938,8 @@ bool GDLWidget::InitWx() { try{ wxInitialize(); } catch (...) {return false;} + wxDisplay *d= new wxDisplay(); + if(d->GetCount()<1) return false; wxInitAllImageHandlers(); //do it here once for all return true; } From 79702a35b3cea207395372bba50f72fae4ae1872 Mon Sep 17 00:00:00 2001 From: GillesDuvert Date: Thu, 5 Jan 2023 21:15:49 +0100 Subject: [PATCH 7/8] test 3 --- src/gdl.cpp | 17 +++++++++++++---- src/gdlwidget.cpp | 3 ++- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/src/gdl.cpp b/src/gdl.cpp index d1887c944..0d0bfcf8d 100644 --- a/src/gdl.cpp +++ b/src/gdl.cpp @@ -285,10 +285,19 @@ int main(int argc, char *argv[]) useDSFMTAcceleration = true; iAmANotebook=false; //option --notebook #ifdef HAVE_LIBWXWIDGETS - useWxWidgets=true; + + #if defined (__WXMAC__) + useWxWidgets=true; + #elif defined (__WXMSW__) + useWxWidgets=true; + #else + if (GetEnvString("DISPLAY").length() > 0) useWxWidgets=true; else useWxWidgets=false; + #endif + #else useWxWidgets=false; -#endif +#endif + std::cerr<<"useWxWidgets: "< 0)) useDSFMTAcceleration=false; //report in !GDL status struct diff --git a/src/gdlwidget.cpp b/src/gdlwidget.cpp index 329caf134..b15fb5e60 100644 --- a/src/gdlwidget.cpp +++ b/src/gdlwidget.cpp @@ -938,7 +938,8 @@ bool GDLWidget::InitWx() { try{ wxInitialize(); } catch (...) {return false;} - wxDisplay *d= new wxDisplay(); + //avoid using if no Display is present! + wxDisplay *d= new wxDisplay(); if(d->GetCount()<1) return false; wxInitAllImageHandlers(); //do it here once for all return true; From 7a42075db87432da3e371a969d2ea508e118ec34 Mon Sep 17 00:00:00 2001 From: GillesDuvert Date: Fri, 6 Jan 2023 00:59:08 +0100 Subject: [PATCH 8/8] remove debug message --- src/gdl.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/src/gdl.cpp b/src/gdl.cpp index 0d0bfcf8d..7db69766a 100644 --- a/src/gdl.cpp +++ b/src/gdl.cpp @@ -297,7 +297,6 @@ int main(int argc, char *argv[]) #else useWxWidgets=false; #endif - std::cerr<<"useWxWidgets: "<