Skip to content

Solves Issue #1470 and more #1483

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Jan 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/gdl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -394,7 +394,7 @@ int main(int argc, char *argv[])

bool force_no_wxgraphics = false;
usePlatformDeviceName=false;
forceWxWidgetsUglyFonts = false;
tryToMimicOriginalWidgets = false;
useDSFMTAcceleration = true;
iAmANotebook=false; //option --notebook
#ifdef HAVE_LIBWXWIDGETS
Expand Down Expand Up @@ -536,7 +536,7 @@ int main(int argc, char *argv[])
}
else if (string(argv[a]) == "--widget-compat")
{
forceWxWidgetsUglyFonts = true;
tryToMimicOriginalWidgets = true;
}
#ifdef _WIN32
else if (string(argv[a]) == "--posix") lib::posixpaths=true;
Expand Down Expand Up @@ -596,7 +596,7 @@ int main(int argc, char *argv[])
if (force_no_wxgraphics) useWxWidgetsForGraphics=false; //this has the last answer, whatever the setup.
#endif
std::string doUseUglyFonts=GetEnvString("GDL_WIDGETS_COMPAT");
if ( doUseUglyFonts.length() > 0) forceWxWidgetsUglyFonts=true;
if ( doUseUglyFonts.length() > 0) tryToMimicOriginalWidgets=true;

InitGDL();

Expand Down
95 changes: 57 additions & 38 deletions src/gdlwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,9 @@ inline int GDLWidget::widgetAlignment()
long expand=wxEXPAND;
if (this->IsLabel()) expand=0; //labels are not expanded
if (this->IsDraw()) expand=0; //draw are not expanded
if (this->IsDropList()) expand=0; //droplists are not expanded
if (this->IsNormalBase()) expand=0;
if (this->IsTabbedBase()) expand=0; //apparently IsTabbedBase() is not set even if base is a Tabbed base???
if (myAlign == gdlwALIGN_NOT) return expand|wxALIGN_LEFT|wxALIGN_TOP;
//left is top by default and right is bottom. So define left as top and remove top if bottom, etc.
//ignore sets that do not concern the current layout (vetrtical or horizontal)
Expand Down Expand Up @@ -951,7 +954,7 @@ bool GDLWidget::InitWx() {
void GDLWidget::Init()
{
//set system font to something sensible now that wx is ON:
if (forceWxWidgetsUglyFonts)
if (tryToMimicOriginalWidgets)
systemFont = wxFont(8, wxFONTFAMILY_MODERN, wxFONTSTYLE_NORMAL,wxFONTWEIGHT_NORMAL) ;// identical for me to GDLWidget::setDefaultFont(wxFont("Monospace 8"));
#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.
Expand All @@ -977,7 +980,8 @@ 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.
//use a phantom window to retrieve the exact size of scrollBars (wxWidget give wrong values).
//Also get normal panel color
gdlwxPhantomFrame* test = new gdlwxPhantomFrame();
test->Hide();
test->Realize();
Expand Down Expand Up @@ -1329,7 +1333,7 @@ void GDLWidgetTopBase::Realize(bool map, bool use_default) {

OnRealize();

if (map) topFrame->Show() ; //endShowRequestEvent();
if (map) topFrame->Show() ; //endShowRequestEvent();
else topFrame->Hide(); //SendHideRequestEvent();
realized = true;
}
Expand Down Expand Up @@ -1753,32 +1757,30 @@ void GDLWidgetBase::CreateBase(wxWindow* parent){
if (doFrame && frameWidth > 0) {
wxScrolled<wxPanel>* frame = new wxScrolled<wxPanel>(parent, wxID_ANY, wOffset, wxDefaultSize, gdlBORDER_EXT);
theWxContainer=frame;
#ifdef GDL_DEBUG_WIDGETS_COLORIZE
frame->SetBackgroundColour(wxColour(0x60, 0xe0, 0x94)); //vert clair
#endif
wxBoxSizer* panelsz = new wxBoxSizer(wxVERTICAL);
frame->SetSizer(panelsz);

wxBoxSizer* sz_inside=panelsz;
wxPanel* frame_inside=frame;
DLong newframewidth=frameWidth;
if (frameWidth > 10 && tryToMimicOriginalWidgets ) {
newframewidth=frameWidth/2;
frame->SetBackgroundColour(*wxBLACK); //will show a strong frame as does IDL
// Fancy variant:
// int mode = wxBORDER_NONE;
// int width = 2; //the size of wxBORDER_SUNKEN
// if (frameWidth > 2) {
// mode = wxBORDER_SIMPLE;
// width = 3;
// }
// if (frameWidth > 3) {
// mode = wxBORDER_RAISED;
// width = 4;
// }
// wxPanel* frame_inside = new wxPanel(frame, wxID_ANY, wxDefaultPosition, wxDefaultSize, mode);
// sz->Add(frame_inside, FRAME_ALLOWSTRETCH, wxALL, frameWidth - width);
//
// wxBoxSizer* sz_inside = new wxBoxSizer(wxVERTICAL);
// frame_inside->SetSizer(sz_inside);
// widgetPanel = new wxScrolledWindow(frame_inside, wxID_ANY, wOffset, wxDefaultSize);
int mode = wxBORDER_NONE;
frame_inside = new wxPanel(frame, wxID_ANY, wxDefaultPosition, wxDefaultSize, mode);
frame_inside->SetBackgroundColour(*wxLIGHT_GREY);
panelsz->Add(frame_inside, FRAME_ALLOWSTRETCH, wxALL, newframewidth);

sz_inside = new wxBoxSizer(wxVERTICAL);
frame_inside->SetSizer(sz_inside);
}
if (xpad > 0 || ypad > 0) {
wxScrolled<wxPanel>* padxpady = new wxScrolled<wxPanel>(frame);
wxScrolled<wxPanel>* padxpady = new wxScrolled<wxPanel>(frame_inside);
#ifdef GDL_DEBUG_WIDGETS_COLORIZE
padxpady->SetBackgroundColour(wxColour(0xa7, 0x3d, 0x0f)); //orange fonce
#else
if (tryToMimicOriginalWidgets ) padxpady->SetBackgroundColour(wxColour(sysPanelDefaultColour));
#endif
wxGridBagSizer* sz = new wxGridBagSizer(ypad, xpad);
padxpady->SetSizer(sz);
Expand All @@ -1799,12 +1801,14 @@ void GDLWidgetBase::CreateBase(wxWindow* parent){
padxpady->SetScrollbars(gdlSCROLL_RATE, gdlSCROLL_RATE, wSize.x / gdlSCROLL_RATE, wSize.y / gdlSCROLL_RATE);
padxpady->ShowScrollbars(wxSHOW_SB_ALWAYS, wxSHOW_SB_ALWAYS);
}
panelsz->Add(padxpady, FRAME_ALLOWSTRETCH, wxALL | wxEXPAND, frameWidth);//gdlFRAME_MARGIN);
panelsz->Fit(padxpady);
sz_inside->Add(padxpady, FRAME_ALLOWSTRETCH, wxALL | wxEXPAND, newframewidth);//gdlFRAME_MARGIN);
sz_inside->Fit(padxpady);
} else {
widgetPanel = new wxScrolledWindow(frame, widgetID, wOffset, wxDefaultSize);
widgetPanel = new wxScrolledWindow(frame_inside, widgetID, wOffset, wxDefaultSize);
#ifdef GDL_DEBUG_WIDGETS_COLORIZE
widgetPanel->SetBackgroundColour(RandomWxColour());
#else
if (tryToMimicOriginalWidgets ) widgetPanel->SetBackgroundColour(wxColour(sysPanelDefaultColour));
#endif
// widgetPanel->SetVirtualSize(wSize);
widgetPanel->SetSize(wScrollSize);
Expand All @@ -1814,8 +1818,8 @@ void GDLWidgetBase::CreateBase(wxWindow* parent){
widgetPanel->SetScrollbars(gdlSCROLL_RATE, gdlSCROLL_RATE, wSize.x / gdlSCROLL_RATE, wSize.y / gdlSCROLL_RATE);
widgetPanel->ShowScrollbars(wxSHOW_SB_ALWAYS, wxSHOW_SB_ALWAYS);
}
panelsz->Add(widgetPanel, FRAME_ALLOWSTRETCH, wxALL | wxEXPAND, frameWidth);//gdlFRAME_MARGIN);
panelsz->Fit(widgetPanel);
sz_inside->Add(widgetPanel, FRAME_ALLOWSTRETCH, wxALL | wxEXPAND, newframewidth);//gdlFRAME_MARGIN);
sz_inside->Fit(widgetPanel);
}
theWxWidget = widgetPanel;
} else {
Expand Down Expand Up @@ -2136,7 +2140,6 @@ GDLWidgetTabbedBase::GDLWidgetTabbedBase(WidgetIDT parentID, EnvT* e, ULong even

wxNotebook* parentTab = dynamic_cast<wxNotebook*> (parent->GetWxWidget());
assert(parentTab != NULL);

wxString titleWxString = wxString(title_.c_str(), wxConvUTF8);
if (nrows < 1 && ncols < 1 && frameWidth < 1) frameWidth=1; //set framewidth (temporary) in this case to get good result
CreateBase(parentTab);
Expand Down Expand Up @@ -2473,6 +2476,7 @@ GDLWidgetTab::GDLWidgetTab( WidgetIDT p, EnvT* e, ULong eventFlags_, DLong locat
theWxContainer = theWxWidget = notebook;
if (parentSizer) parentSizer->Add(notebook,DONOTALLOWSTRETCH,widgetAlignment()|wxALL, gdlSPACE);
}
notebook->SetPadding(wxSize(0,0));
//wxNotebook DOES NOT USE a sizer.
this->AddToDesiredEvents(wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGED,wxNotebookEventHandler(gdlwxFrame::OnPageChanged),notebook);
}
Expand Down Expand Up @@ -2511,19 +2515,30 @@ BaseGDL* GDLWidgetTab::GetTabMultiline(){
//special as wxNotebook DOES NOT RECOMPILE ITS SIZE BEFORE REALIZATION.
void GDLWidgetTab::OnRealize(){
GDLWidgetContainer::OnRealize();
std::cerr<<".";
wxNotebook * nb=dynamic_cast<wxNotebook*>(theWxWidget);
assert( nb != NULL);
nb->InvalidateBestSize();
size_t n=nb->GetPageCount();
wxSize s(-1,1);
for (auto i=0; i<n; ++i) {
wxWindow* w=nb->GetPage(i);
wxSize s_tmp=w->GetBestSize();
s.x = MAX(s.x, s_tmp.x);
s.y = MAX(s.y, s_tmp.y);
if (n > 1) {
wxSize s=nb->GetSize();
//insure larger enough to see tab changer
if (s.x < 100) {
s.x=100;
nb->SetMinSize(s);
}
}
nb->SetMinSize(s);

// nb->InvalidateBestSize();
// size_t n=nb->GetPageCount();
// for (auto i=0; i<n; ++i) {
// wxWindow* w=nb->GetPage(i);
// wxSize s_tmp=w->GetBestSize();
// s.x = MAX(s.x, s_tmp.x);
// s.y = MAX(s.y, s_tmp.y);
// std::cerr<<"s.x="<<s.x<<" from "<<s_tmp.x<<std::endl;
// std::cerr<<"s.y="<<s.y<<" from "<<s_tmp.y<<std::endl;
// }
// nb->SetMinSize(s);
// nb->SetMinClientSize(s);
}


Expand Down Expand Up @@ -6050,6 +6065,9 @@ void gdlwxPhantomFrame::Realize() {
if (w.y <= 0) w.y=gdlABSENT_SIZE_VALUE;
sysScrollHeight=w.y;
sysScrollWidth=w.x;
wxColour color=c->GetBackgroundColour();
sysPanelDefaultColour=color.GetRGB();
// std::cerr<<sysPanelDefaultColour<<std::endl;
}

// Frame for Plots ========================================================
Expand All @@ -6073,6 +6091,7 @@ gdlwxPlotFrame::~gdlwxPlotFrame() {
}

void gdlwxPlotFrame::Realize() {
this->SetClientSize(this->GetClientSize());
#ifdef GDL_DEBUG_WIDGETS
wxMessageOutputStderr().Printf(_T("gdlwxPlotFrame:Realize\n"));
#endif
Expand Down
19 changes: 11 additions & 8 deletions src/gdlwidget.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,8 @@
#define gdlBUTTON_SPACE 4
#define gdlSMALL_SPACE 1
#define gdlBORDER_SPACE 2
#define gdlBORDER_EXT wxBORDER_THEME // wxBORDER_SUNKEN //wxBORDER_RAISED//wxBORDER_SIMPLE //wxBORDER_RAISED
#define gdlBORDER_INT wxBORDER_NONE //wxBORDER_SUNKEN
#define gdlBORDER_EXT wxBORDER_SUNKEN // wxBORDER_THEME // wxBORDER_SUNKEN //wxBORDER_RAISED//wxBORDER_SIMPLE //wxBORDER_RAISED
#define gdlBORDER_INT wxBORDER_RAISED //wxBORDER_SUNKEN
#define gdlTEXT_XMARGIN 4
#define gdlTEXT_YMARGIN 4
#define DONOTALLOWSTRETCH 0
Expand Down Expand Up @@ -357,7 +357,7 @@ void OnDrag(wxMouseEvent& event);
static int sysScrollHeight=25;
static int sysScrollWidth=25;
static int sysComboboxArrow=25;

static wxUint32 sysPanelDefaultColour;
class GDLWidget
{
// static part is used for the abstraction
Expand Down Expand Up @@ -631,6 +631,8 @@ class GDLWidget
virtual bool IsContainer() const { return false;}
virtual bool IsBase() const { return false;}
virtual bool IsTopBase() const { return false;}
virtual bool IsNormalBase() const { return false;}
virtual bool IsTabbedBase() const { return false;}
virtual bool IsContextBase() const { return false; }
virtual bool IsButton() const { return false;}
virtual bool IsMenu() const { return false;}
Expand Down Expand Up @@ -832,8 +834,6 @@ class GDLWidgetBase: public GDLWidgetContainer
void CreateBase(wxWindow* parent);
bool IsVertical() {return (ncols>0);}
bool IsHorizontal() {return (nrows>0);}
virtual bool IsNormalBase() const { return false;}
virtual bool IsTabbedBase() const { return false;}
void SetWidgetSize(DLong sizex, DLong sizey) final;

void NullWxWidget() { theWxWidget = NULL;}
Expand Down Expand Up @@ -921,9 +921,12 @@ class GDLWidgetTopBase : public GDLWidgetBase {
if (w != NULL)
w->OnRealize();
}
topFrame->Fit();
topFrame->refreshFrameSize();
DoMapAsRequested();

topFrame->Fit();
topFrame->SetClientSize(topFrame->GetClientSize());
topFrame->refreshFrameSize();

ConnectToDesiredEvents();

if (notifyRealize != "") { //insure it is called once only for this.
Expand Down Expand Up @@ -991,7 +994,7 @@ class GDLWidgetTabbedBase : public GDLWidgetBase {

~GDLWidgetTabbedBase();
void SetBaseTitle(std::string &s);
bool IsTabbedBase() const { return true; }
bool IsTabbedBase() const final { return true;}
void mapBase(bool val) final;

//Same as Container except that we have to reorder widgets in some cases
Expand Down
16 changes: 10 additions & 6 deletions src/gdlwidgeteventhandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,16 +93,20 @@ wxPoint gdlwxGraphicsPanel::WhereIsMouse(wxMouseEvent &e) {
}
int RemapModifiers(wxMouseEvent &e) {
int out = 0;
#ifndef __WXGTK__
if (wxGetKeyState(WXK_CAPITAL)) out |= 0x04;
if (e.ControlDown()) out |= 0x02;
#endif
if (e.RawControlDown()) out |= 0x02; //RAW for OSX specificity
if (e.AltDown()) out |= 0x08;
if (e.ShiftDown()) out |= 0x01;
return out;
}
int GetModifiers() {
int out = 0;
#ifndef __WXGTK__
if (wxGetKeyState(WXK_CAPITAL)) out |= 0x04;
if (wxGetKeyState(WXK_CONTROL)) out |= 0x02;
#endif
if (wxGetKeyState(WXK_RAW_CONTROL)) out |= 0x02; //RAW for OSX specificity
if (wxGetKeyState(WXK_ALT)) out |= 0x08;
if (wxGetKeyState(WXK_SHIFT)) out |= 0x01;
return out;
Expand Down Expand Up @@ -1382,7 +1386,7 @@ void gdlwxGraphicsPanel::OnPaint(wxPaintEvent& event)
void gdlwxPlotPanel::OnPlotWindowSize(wxSizeEvent &event) {
wxSize newSize = event.GetSize(); //size returned by the external frame
gdlwxPlotFrame* p = this->GetMyFrame();
p->Disconnect(wxEVT_SIZE, wxSizeEventHandler(gdlwxPlotFrame::OnPlotWindowSize));
// p->Disconnect(wxEVT_SIZE, wxSizeEventHandler(gdlwxPlotFrame::OnPlotWindowSize));
#if (GDL_DEBUG_ALL_EVENTS || GDL_DEBUG_SIZE_EVENTS)
wxMessageOutputStderr().Printf(_T("in gdlwxPlotPanel::OnPlotWindowSize: %d (%d,%d), (%d,%d)\n"), event.GetId(), event.GetSize().x, event.GetSize().y,
newSize.x, newSize.y);
Expand Down Expand Up @@ -1414,9 +1418,9 @@ void gdlwxPlotPanel::OnPlotWindowSize(wxSizeEvent &event) {
(*static_cast<DLongGDL*> (SysVar::D()->GetTag(SysVar::D()->Desc()->TagIndex("X_VSIZE"), 0)))[0] = newSize.x;
(*static_cast<DLongGDL*> (SysVar::D()->GetTag(SysVar::D()->Desc()->TagIndex("Y_VSIZE"), 0)))[0] = newSize.y;

p->Fit();
p->Refresh();
p->Connect(wxEVT_SIZE, wxSizeEventHandler(gdlwxPlotFrame::OnPlotWindowSize));
// p->Fit();
// p->Refresh();
// p->Connect(wxEVT_SIZE, wxSizeEventHandler(gdlwxPlotFrame::OnPlotWindowSize));
// event.Skip();
}
void gdlwxGraphicsPanel::OnPlotWindowSize(wxSizeEvent &event)
Expand Down
2 changes: 1 addition & 1 deletion src/objects.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ volatile bool iAmANotebook;
//do we use name Devices differently among platforms?
volatile bool usePlatformDeviceName;
// do we force fonts to be the ugly IDL fonts?
volatile bool forceWxWidgetsUglyFonts;
volatile bool tryToMimicOriginalWidgets;
//do we use our own copy of (better?) drivers?
volatile bool useLocalDrivers;
//do we favor SIMD-accelerated random number generation?
Expand Down
2 changes: 1 addition & 1 deletion src/objects.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ extern volatile bool useWxWidgets;
// tells if wxwidgets backend for graphics is to be used...
extern volatile bool useWxWidgetsForGraphics;
// do we force fonts to be the ugly IDL fonts?
extern volatile bool forceWxWidgetsUglyFonts;
extern volatile bool tryToMimicOriginalWidgets;
//do we favor SIMD-accelerated random number generation?
extern volatile bool useDSFMTAcceleration;
//do we use our own copy of (better?) drivers?
Expand Down
Loading