Skip to content

Commit 0629d02

Browse files
authored
Merge pull request #1464 from GillesDuvert/solved_question_mark
Seems very much OK
2 parents 7382391 + 7a42075 commit 0629d02

8 files changed

+154
-145
lines changed

src/devicewx.hpp

+11-10
Original file line numberDiff line numberDiff line change
@@ -172,15 +172,14 @@ if(hide) {
172172
} else {
173173
plotFrame->Show(); //WithoutActivating(); --> this does nothing good. Better tailor your window manager to 'focus under mouse"
174174
// plotFrame->UpdateWindowUI(); not useful
175-
plotFrame->Refresh();
176-
plotFrame->Update();
177175
plotFrame->Raise();
176+
plotFrame->Refresh();
178177
//really show by letting the loop do its magic. Necessary.
179-
#ifdef __WXMAC__
180-
wxTheApp->Yield();
181-
#else
182-
wxGetApp().MainLoop(); //central loop for wxEvents!
183-
#endif
178+
//#ifdef __WXMAC__
179+
// wxTheApp->Yield();
180+
//#else
181+
// wxGetApp().MyLoop(); //central loop for wxEvents!
182+
//#endif
184183
}
185184

186185
// these widget specific events are always set:
@@ -189,9 +188,11 @@ if(hide) {
189188
plot->Connect(wxEVT_ERASE_BACKGROUND, wxEraseEventHandler(gdlwxDrawPanel::OnErase));
190189

191190
plotFrame->Connect(wxEVT_CLOSE_WINDOW, wxCloseEventHandler(gdlwxPlotFrame::OnUnhandledClosePlotFrame));
192-
// plotFrame->Connect(wxEVT_SIZE, wxSizeEventHandler(gdlwxPlotFrame::OnPlotSizeWithTimer));
193-
plotFrame->Connect(wxEVT_SIZE, wxSizeEventHandler(gdlwxPlotFrame::OnPlotWindowSize));
194-
191+
#ifdef __WXMSW__
192+
plotFrame->Connect(wxEVT_SIZE, wxSizeEventHandler(gdlwxPlotFrame::OnPlotWindowSize)); //Timer resize do not work on MSW
193+
#else
194+
plotFrame->Connect(wxEVT_SIZE, wxSizeEventHandler(gdlwxPlotFrame::OnPlotSizeWithTimer));
195+
#endif
195196
return true;
196197
}
197198

src/gdl.cpp

+13-5
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@
6363
//we use gdlgstream in gdl.cpp
6464
#include "gdlgstream.hpp"
6565

66-
//initialize wxWidgets system
66+
//initialize wxWidgets system: create an instance of wxAppGDL
6767
#ifdef HAVE_LIBWXWIDGETS
6868
#include "gdlwidget.hpp"
6969
#ifndef __WXMAC__
@@ -398,10 +398,18 @@ int main(int argc, char *argv[])
398398
useDSFMTAcceleration = true;
399399
iAmANotebook=false; //option --notebook
400400
#ifdef HAVE_LIBWXWIDGETS
401-
useWxWidgets=true;
401+
402+
#if defined (__WXMAC__)
403+
useWxWidgets=true;
404+
#elif defined (__WXMSW__)
405+
useWxWidgets=true;
406+
#else
407+
if (GetEnvString("DISPLAY").length() > 0) useWxWidgets=true; else useWxWidgets=false;
408+
#endif
409+
402410
#else
403411
useWxWidgets=false;
404-
#endif
412+
#endif
405413
#ifdef _WIN32
406414
lib::posixpaths = false;
407415
#endif
@@ -575,7 +583,7 @@ int main(int argc, char *argv[])
575583

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

612620
//report in !GDL status struct

src/gdlwidget.cpp

+49-58
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
#include <wx/wrapsizer.h>
2626
#include <wx/textctrl.h>
2727
#include <wx/menuitem.h>
28+
#include <wx/display.h>
2829

2930
#include "basegdl.hpp"
3031
#include "dstructgdl.hpp"
@@ -563,14 +564,14 @@ void GDLWidget::UpdateGui()
563564
actID = widget->parentID;
564565
}
565566
this->GetMyTopLevelFrame()->Fit();
566-
// this->GetMyTopLevelFrame()->Refresh();
567-
this->GetMyTopLevelFrame()->Update();
567+
this->GetMyTopLevelFrame()->Refresh();
568+
// this->GetMyTopLevelFrame()->Update();
568569
END_CHANGESIZE_NOEVENT
569-
#ifdef __WXMAC__
570-
wxTheApp->Yield();
571-
#else
572-
wxGetApp().MainLoop(); //central loop for wxEvents!
573-
#endif
570+
//#ifdef __WXMAC__
571+
// wxTheApp->Yield();
572+
//#else
573+
// wxGetApp().MyLoop(); //central loop for wxEvents!
574+
//#endif
574575
}
575576

576577
//Alternate version if there were sizing problems with the one above.
@@ -773,7 +774,7 @@ void GDLWidget::HandleWidgetEvents()
773774
#ifdef __WXMAC__
774775
wxTheApp->Yield();
775776
#else
776-
wxGetApp().MainLoop(); //central loop for wxEvents!
777+
wxGetApp().MyLoop(); //central loop for wxEvents!
777778
#endif
778779
//treat our GDL events...
779780
DStructGDL* ev = NULL;
@@ -918,19 +919,28 @@ DLongGDL* GDLWidget::GetAllHeirs(){
918919
for (SizeT i = 0; i < currentVectorSize ; ++i) (*result)[i] = widgetIDList[i];
919920
return result;
920921
}
922+
#ifdef __WXMAC__
923+
#include <Carbon/Carbon.h>
924+
extern "C" { void CPSEnableForegroundOperation( ProcessSerialNumber* psn ); }
925+
#endif
921926

922927
//
923-
bool GDLWidget::InitWx()
924-
{ if (wxTheApp == NULL) { //not already initialized
925-
if (!wxInitialize()) {
926-
std::cerr << "WARNING: wxWidgets not initializing, widget-related commands will not be available." << std::endl;
927-
return false;
928-
}
929-
#ifndef __WXMAC__
930-
wxAppGDL* app = new wxAppGDL();
931-
app->SetInstance(app);
932-
#endif
933-
} else {std::cerr << "INFO: wxWidgets already initialized (in 3rd party library?), pursue with fingers crossed" << std::endl; }
928+
bool GDLWidget::InitWx() {
929+
// this hack enables to have a GUI on Mac OSX even if the
930+
// program was called from the command line (and isn't a bundle)
931+
#ifdef __WXMAC__
932+
ProcessSerialNumber psn;
933+
934+
GetCurrentProcess( &psn );
935+
CPSEnableForegroundOperation( &psn );
936+
SetFrontProcess( &psn );
937+
#endif
938+
try{
939+
wxInitialize();
940+
} catch (...) {return false;}
941+
//avoid using if no Display is present!
942+
wxDisplay *d= new wxDisplay();
943+
if(d->GetCount()<1) return false;
934944
wxInitAllImageHandlers(); //do it here once for all
935945
return true;
936946
}
@@ -940,7 +950,7 @@ void GDLWidget::Init()
940950
//set system font to something sensible now that wx is ON:
941951
if (forceWxWidgetsUglyFonts)
942952
systemFont = wxFont(8, wxFONTFAMILY_MODERN, wxFONTSTYLE_NORMAL,wxFONTWEIGHT_NORMAL) ;// identical for me to GDLWidget::setDefaultFont(wxFont("Monospace 8"));
943-
#if __WXMSW__ //update for windows:
953+
#ifdef __WXMSW__ //update for windows:
944954
bool ok=systemFont.SetNativeFontInfoUserDesc(wxString("consolas 8")); //consolas 8 is apparently the one most identical to linux courier 8 and IDL X11 default font.
945955
if (!ok) systemFont = wxFont(8, wxFONTFAMILY_MODERN, wxFONTSTYLE_NORMAL,wxFONTWEIGHT_NORMAL) ;
946956
#endif
@@ -949,9 +959,6 @@ void GDLWidget::Init()
949959
//initially defaultFont and systemFont are THE SAME.
950960
defaultFont=systemFont;
951961
SetWxStarted();
952-
#ifndef __WXMAC__
953-
wxGetApp().OnInit();
954-
#endif
955962
//initialize default image lists for trees:
956963
// Make an image list containing small icons
957964
wxSize ImagesSize(DEFAULT_TREE_IMAGE_SIZE,DEFAULT_TREE_IMAGE_SIZE);
@@ -967,7 +974,12 @@ void GDLWidget::Init()
967974
gdlDefaultTreeStateImages->Add(wxIcon(pixmap_checked)); //gdlWxTree_UNCHECKED
968975
//create wxIcon HERE and not before wxWidgets is started!
969976
wxgdlicon = wxIcon(gdlicon_xpm);
970-
}
977+
//use a phantom window to retrieve the exact size of scrollBars wxWidget give wrong values.
978+
gdlwxPhantomFrame* test = new gdlwxPhantomFrame();
979+
test->Hide();
980+
test->Realize();
981+
test->Destroy();
982+
}
971983
//ResetWidgets
972984
void GDLWidget::ResetWidgets() {
973985
//Delete current widgets --- complicated, use utility procedure
@@ -984,7 +996,7 @@ void GDLWidget::ResetWidgets() {
984996
#ifdef __WXMAC__
985997
wxTheApp->Yield();
986998
#else
987-
wxGetApp().MainLoop(); //central loop for wxEvents!
999+
wxGetApp().MyLoop(); //central loop for wxEvents!
9881000
#endif
9891001
}
9901002
// UnInit
@@ -6108,12 +6120,10 @@ gdlwxPlotPanel::gdlwxPlotPanel( gdlwxPlotFrame* parent) //, wxWindowID id, const
61086120

61096121
void gdlwxGraphicsPanel::RepaintGraphics(bool doClear) {
61106122
wxClientDC dc(this); //is a scrolled window: needed
6111-
DoPrepareDC(dc); //you probably do not want to call wxScrolled::PrepareDC() on wxAutoBufferedPaintDC as it already does this internally for the real underlying wxPaintDC.
6112-
// dc.SetDeviceClippingRegion(GetUpdateRegion());
6123+
// DoPrepareDC(dc); //you probably do not want to call wxScrolled::PrepareDC() on wxAutoBufferedPaintDC as it already does this internally for the real underlying wxPaintDC.
6124+
//// dc.SetDeviceClippingRegion(GetUpdateRegion());
61136125
if (doClear) dc.Clear();
6114-
dc.Blit(0, 0, drawSize.x, drawSize.y, wx_dc, 0, 0);
6115-
// this->Refresh();
6116-
// this->Update();
6126+
this->Refresh(); //--> will call PAINT EVENT, this one will blit and work.
61176127
}
61186128

61196129
////Stem for generalization of Drag'n'Drop, a WIDGET_DRAW can receive drop events from something else than a tree widget...
@@ -6267,8 +6277,6 @@ GDLWidgetDraw::GDLWidgetDraw( WidgetIDT p, EnvT* e, int windowIndex,
62676277

62686278
//these widget specific events are always set:
62696279
this->AddToDesiredEvents( wxEVT_PAINT, wxPaintEventHandler(gdlwxDrawPanel::OnPaint),draw);
6270-
this->AddToDesiredEvents( wxEVT_PAINT, wxPaintEventHandler(gdlwxDrawPanel::OnPaint),draw);
6271-
// this->AddToDesiredEvents( wxEVT_SIZE, wxSizeEventHandler(gdlwxDrawPanel::OnSize),draw);
62726280
//disable flicker see https://wiki.wxwidgets.org/Flicker-Free_Drawing
62736281
this->AddToDesiredEvents( wxEVT_ERASE_BACKGROUND, wxEraseEventHandler(gdlwxDrawPanel::OnErase),draw);
62746282

@@ -6460,34 +6468,17 @@ void GDLWidgetDraw::SetWidgetScreenSize(DLong sizex, DLong sizey) {
64606468
// So we rely only on doing nothing and call Yield() , that works, fingers crossed.
64616469
// Really strange but wxWidgets is not well documented (who is?)
64626470
#ifndef __WXMAC__
6463-
6464-
#include "wx/evtloop.h"
6465-
#include "wx/ptr_scpd.h"
6466-
wxDEFINE_TIED_SCOPED_PTR_TYPE(wxEventLoop);
6467-
6468-
bool wxAppGDL::OnInit()
6469-
{
6470-
//use a phantom window to retrieve the exact size of scrollBars wxWidget give wrong values.
6471-
gdlwxPhantomFrame* test = new gdlwxPhantomFrame();
6472-
test->Hide();
6473-
test->Realize();
6474-
test->Destroy();
6475-
return true;
6476-
}
6477-
6478-
int wxAppGDL::MainLoop() {
6479-
wxEventLoopTiedPtr mainLoop((wxEventLoop **) & m_mainLoop, new wxEventLoop);
6480-
m_mainLoop->SetActive(m_mainLoop);
6481-
loop = this->GetMainLoop();
6482-
// std::cerr<<loop<<std::endl;
6483-
if (loop) {
6484-
if (loop->IsRunning()) {
6485-
while (loop->Pending()) // Unprocessed events in queue
6486-
{
6487-
loop->Dispatch(); // Dispatch next event in queue
6471+
int wxAppGDL::MyLoop() {
6472+
if (loop.IsOk()) {
6473+
// std::cerr<<&loop<<std::endl;
6474+
loop.SetActive(&loop);
6475+
if (loop.IsRunning()) {
6476+
while (loop.Pending()) // Unprocessed events in queue
6477+
{
6478+
loop.Dispatch(); // Dispatch next event in queue
6479+
}
64886480
}
64896481
}
6490-
}
64916482
return 0;
64926483
}
64936484
#endif

src/gdlwidget.hpp

+10-7
Original file line numberDiff line numberDiff line change
@@ -95,8 +95,11 @@
9595
#else
9696
#define NEWLINECHARSIZE 1 //length of <nl>
9797
#endif
98-
98+
#ifdef __WXMSW__
99+
#define gdlSIZE_EVENT_HANDLER wxSizeEventHandler(gdlwxFrame::OnSize) //Timer resize do not work on MSW
100+
#else
99101
#define gdlSIZE_EVENT_HANDLER wxSizeEventHandler(gdlwxFrame::OnSizeWithTimer) //filter mouse events (manual resize) to avoid too many updtes for nothing
102+
#endif
100103
#define gdlSIZE_IMMEDIATE_EVENT_HANDLER wxSizeEventHandler(gdlwxFrame::OnSize)
101104
typedef DLong WidgetIDT;
102105
static std::string widgetNameList[]={"BASE","BUTTON","SLIDER","TEXT","DRAW","LABEL","LIST","MBAR","DROPLIST","TABLE","TAB","TREE","COMBOBOX","PROPERTYSHEET","WINDOW"};
@@ -229,13 +232,15 @@ class WidgetEventInfo {
229232
};
230233
#ifndef __WXMAC__
231234
// main App class
235+
#include "wx/evtloop.h"
236+
232237
class wxAppGDL: public wxApp
233238
{
234-
wxEventLoopBase* loop;
239+
wxGUIEventLoop loop;
235240
public:
236-
virtual int MainLoop();
237-
virtual bool OnInit();
241+
int MyLoop();
238242
};
243+
239244
wxDECLARE_APP(wxAppGDL); //wxAppGDL is equivalent to wxGetApp()
240245
#endif
241246

@@ -2067,12 +2072,10 @@ class gdlwxPlotFrame : public wxFrame {
20672072
bool IsScrolled(){return scrolled;}
20682073
void Realize();
20692074
// event handlers (these functions should _not_ be virtual)
2070-
// void OnClosePlotFrame(wxCloseEvent & event);
2071-
// void OnPlotSizeWithTimer(wxSizeEvent& event);
20722075
void OnTimerPlotResize(wxTimerEvent& event);
20732076
void OnUnhandledClosePlotFrame(wxCloseEvent & event);
20742077
void OnPlotSizeWithTimer(wxSizeEvent& event);
2075-
void OnPlotWindowSize(wxSizeEvent& event);
2078+
void OnPlotWindowSize(wxSizeEvent& event); //unused
20762079
DECLARE_EVENT_TABLE()
20772080
};
20782081
class GDLWXStream;

0 commit comments

Comments
 (0)