Skip to content

Commit

Permalink
Merge pull request #1464 from GillesDuvert/solved_question_mark
Browse files Browse the repository at this point in the history
Seems very much OK
  • Loading branch information
GillesDuvert authored Jan 6, 2023
2 parents 7382391 + 7a42075 commit 0629d02
Show file tree
Hide file tree
Showing 8 changed files with 154 additions and 145 deletions.
21 changes: 11 additions & 10 deletions src/devicewx.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -172,15 +172,14 @@ 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();
//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().MyLoop(); //central loop for wxEvents!
//#endif
}

// these widget specific events are always set:
Expand All @@ -189,9 +188,11 @@ 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));

#ifdef __WXMSW__
plotFrame->Connect(wxEVT_SIZE, wxSizeEventHandler(gdlwxPlotFrame::OnPlotWindowSize)); //Timer resize do not work on MSW
#else
plotFrame->Connect(wxEVT_SIZE, wxSizeEventHandler(gdlwxPlotFrame::OnPlotSizeWithTimer));
#endif
return true;
}

Expand Down
18 changes: 13 additions & 5 deletions src/gdl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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__
Expand Down Expand Up @@ -398,10 +398,18 @@ 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
#ifdef _WIN32
lib::posixpaths = false;
#endif
Expand Down Expand Up @@ -575,7 +583,7 @@ int main(int argc, char *argv[])

#ifdef HAVE_LIBWXWIDGETS
//tells if wxWidgets is working (may not be the case if DISPLAY is not set) by setting useWxWidgets to false
useWxWidgets=GDLWidget::InitWx();
if (useWxWidgets) useWxWidgets=GDLWidget::InitWx();
// default is wx Graphics...
useWxWidgetsForGraphics=useWxWidgets;
#else
Expand Down Expand Up @@ -606,7 +614,7 @@ int main(int argc, char *argv[])
if (driversNotFound) cerr << "- Local drivers not found --- using default ones. " << endl;
else if (getenv(DrvEnvName)) cerr << "- Using local drivers in " << getenv(DrvEnvName) << endl; //protect against NULL.
}
}
}
if (useDSFMTAcceleration && (GetEnvString("GDL_NO_DSFMT").length() > 0)) useDSFMTAcceleration=false;

//report in !GDL status struct
Expand Down
107 changes: 49 additions & 58 deletions src/gdlwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#include <wx/wrapsizer.h>
#include <wx/textctrl.h>
#include <wx/menuitem.h>
#include <wx/display.h>

#include "basegdl.hpp"
#include "dstructgdl.hpp"
Expand Down Expand Up @@ -563,14 +564,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().MyLoop(); //central loop for wxEvents!
//#endif
}

//Alternate version if there were sizing problems with the one above.
Expand Down Expand Up @@ -773,7 +774,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;
Expand Down Expand Up @@ -918,19 +919,28 @@ DLongGDL* GDLWidget::GetAllHeirs(){
for (SizeT i = 0; i < currentVectorSize ; ++i) (*result)[i] = widgetIDList[i];
return result;
}
#ifdef __WXMAC__
#include <Carbon/Carbon.h>
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
try{
wxInitialize();
} catch (...) {return false;}
//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;
}
Expand All @@ -940,7 +950,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
Expand All @@ -949,9 +959,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);
Expand All @@ -967,7 +974,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
Expand All @@ -984,7 +996,7 @@ void GDLWidget::ResetWidgets() {
#ifdef __WXMAC__
wxTheApp->Yield();
#else
wxGetApp().MainLoop(); //central loop for wxEvents!
wxGetApp().MyLoop(); //central loop for wxEvents!
#endif
}
// UnInit
Expand Down Expand Up @@ -6108,12 +6120,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...
Expand Down Expand Up @@ -6267,8 +6277,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);

Expand Down Expand Up @@ -6460,34 +6468,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<<loop<<std::endl;
if (loop) {
if (loop->IsRunning()) {
while (loop->Pending()) // Unprocessed events in queue
{
loop->Dispatch(); // Dispatch next event in queue
int wxAppGDL::MyLoop() {
if (loop.IsOk()) {
// std::cerr<<&loop<<std::endl;
loop.SetActive(&loop);
if (loop.IsRunning()) {
while (loop.Pending()) // Unprocessed events in queue
{
loop.Dispatch(); // Dispatch next event in queue
}
}
}
}
return 0;
}
#endif
Expand Down
17 changes: 10 additions & 7 deletions src/gdlwidget.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,11 @@
#else
#define NEWLINECHARSIZE 1 //length of <nl>
#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"};
Expand Down Expand Up @@ -229,13 +232,15 @@ class WidgetEventInfo {
};
#ifndef __WXMAC__
// main App class
#include "wx/evtloop.h"

class wxAppGDL: public wxApp
{
wxEventLoopBase* loop;
wxGUIEventLoop loop;
public:
virtual int MainLoop();
virtual bool OnInit();
int MyLoop();
};

wxDECLARE_APP(wxAppGDL); //wxAppGDL is equivalent to wxGetApp()
#endif

Expand Down Expand Up @@ -2067,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);
void OnPlotWindowSize(wxSizeEvent& event); //unused
DECLARE_EVENT_TABLE()
};
class GDLWXStream;
Expand Down
Loading

0 comments on commit 0629d02

Please sign in to comment.