Skip to content

Commit 6052c99

Browse files
authored
Merge pull request #1483 from GillesDuvert/issue_1470
Solves Issue #1470 and more : Changes OK, apparently --widget-compat has no effect on Windows and OSX (???) ths is unimportant now.
2 parents 4374f57 + 58e9884 commit 6052c99

File tree

7 files changed

+103
-78
lines changed

7 files changed

+103
-78
lines changed

src/gdl.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -317,7 +317,7 @@ int main(int argc, char *argv[])
317317

318318
bool force_no_wxgraphics = false;
319319
usePlatformDeviceName=false;
320-
forceWxWidgetsUglyFonts = false;
320+
tryToMimicOriginalWidgets = false;
321321
useDSFMTAcceleration = true;
322322
iAmANotebook=false; //option --notebook
323323
#ifdef HAVE_LIBWXWIDGETS
@@ -459,7 +459,7 @@ int main(int argc, char *argv[])
459459
}
460460
else if (string(argv[a]) == "--widget-compat")
461461
{
462-
forceWxWidgetsUglyFonts = true;
462+
tryToMimicOriginalWidgets = true;
463463
}
464464
#ifdef _WIN32
465465
else if (string(argv[a]) == "--posix") lib::posixpaths=true;
@@ -519,7 +519,7 @@ int main(int argc, char *argv[])
519519
if (force_no_wxgraphics) useWxWidgetsForGraphics=false; //this has the last answer, whatever the setup.
520520
#endif
521521
std::string doUseUglyFonts=GetEnvString("GDL_WIDGETS_COMPAT");
522-
if ( doUseUglyFonts.length() > 0) forceWxWidgetsUglyFonts=true;
522+
if ( doUseUglyFonts.length() > 0) tryToMimicOriginalWidgets=true;
523523

524524
InitGDL();
525525

src/gdlwidget.cpp

+57-38
Original file line numberDiff line numberDiff line change
@@ -300,6 +300,9 @@ inline int GDLWidget::widgetAlignment()
300300
long expand=wxEXPAND;
301301
if (this->IsLabel()) expand=0; //labels are not expanded
302302
if (this->IsDraw()) expand=0; //draw are not expanded
303+
if (this->IsDropList()) expand=0; //droplists are not expanded
304+
if (this->IsNormalBase()) expand=0;
305+
if (this->IsTabbedBase()) expand=0; //apparently IsTabbedBase() is not set even if base is a Tabbed base???
303306
if (myAlign == gdlwALIGN_NOT) return expand|wxALIGN_LEFT|wxALIGN_TOP;
304307
//left is top by default and right is bottom. So define left as top and remove top if bottom, etc.
305308
//ignore sets that do not concern the current layout (vetrtical or horizontal)
@@ -951,7 +954,7 @@ bool GDLWidget::InitWx() {
951954
void GDLWidget::Init()
952955
{
953956
//set system font to something sensible now that wx is ON:
954-
if (forceWxWidgetsUglyFonts)
957+
if (tryToMimicOriginalWidgets)
955958
systemFont = wxFont(8, wxFONTFAMILY_MODERN, wxFONTSTYLE_NORMAL,wxFONTWEIGHT_NORMAL) ;// identical for me to GDLWidget::setDefaultFont(wxFont("Monospace 8"));
956959
#ifdef __WXMSW__ //update for windows:
957960
bool ok=systemFont.SetNativeFontInfoUserDesc(wxString("consolas 8")); //consolas 8 is apparently the one most identical to linux courier 8 and IDL X11 default font.
@@ -977,7 +980,8 @@ void GDLWidget::Init()
977980
gdlDefaultTreeStateImages->Add(wxIcon(pixmap_checked)); //gdlWxTree_UNCHECKED
978981
//create wxIcon HERE and not before wxWidgets is started!
979982
wxgdlicon = wxIcon(gdlicon_xpm);
980-
//use a phantom window to retrieve the exact size of scrollBars wxWidget give wrong values.
983+
//use a phantom window to retrieve the exact size of scrollBars (wxWidget give wrong values).
984+
//Also get normal panel color
981985
gdlwxPhantomFrame* test = new gdlwxPhantomFrame();
982986
test->Hide();
983987
test->Realize();
@@ -1329,7 +1333,7 @@ void GDLWidgetTopBase::Realize(bool map, bool use_default) {
13291333

13301334
OnRealize();
13311335

1332-
if (map) topFrame->Show() ; //endShowRequestEvent();
1336+
if (map) topFrame->Show() ; //endShowRequestEvent();
13331337
else topFrame->Hide(); //SendHideRequestEvent();
13341338
realized = true;
13351339
}
@@ -1753,32 +1757,30 @@ void GDLWidgetBase::CreateBase(wxWindow* parent){
17531757
if (doFrame && frameWidth > 0) {
17541758
wxScrolled<wxPanel>* frame = new wxScrolled<wxPanel>(parent, wxID_ANY, wOffset, wxDefaultSize, gdlBORDER_EXT);
17551759
theWxContainer=frame;
1756-
#ifdef GDL_DEBUG_WIDGETS_COLORIZE
1757-
frame->SetBackgroundColour(wxColour(0x60, 0xe0, 0x94)); //vert clair
1758-
#endif
17591760
wxBoxSizer* panelsz = new wxBoxSizer(wxVERTICAL);
17601761
frame->SetSizer(panelsz);
1762+
1763+
wxBoxSizer* sz_inside=panelsz;
1764+
wxPanel* frame_inside=frame;
1765+
DLong newframewidth=frameWidth;
1766+
if (frameWidth > 10 && tryToMimicOriginalWidgets ) {
1767+
newframewidth=frameWidth/2;
1768+
frame->SetBackgroundColour(*wxBLACK); //will show a strong frame as does IDL
17611769
// Fancy variant:
1762-
// int mode = wxBORDER_NONE;
1763-
// int width = 2; //the size of wxBORDER_SUNKEN
1764-
// if (frameWidth > 2) {
1765-
// mode = wxBORDER_SIMPLE;
1766-
// width = 3;
1767-
// }
1768-
// if (frameWidth > 3) {
1769-
// mode = wxBORDER_RAISED;
1770-
// width = 4;
1771-
// }
1772-
// wxPanel* frame_inside = new wxPanel(frame, wxID_ANY, wxDefaultPosition, wxDefaultSize, mode);
1773-
// sz->Add(frame_inside, FRAME_ALLOWSTRETCH, wxALL, frameWidth - width);
1774-
//
1775-
// wxBoxSizer* sz_inside = new wxBoxSizer(wxVERTICAL);
1776-
// frame_inside->SetSizer(sz_inside);
1777-
// widgetPanel = new wxScrolledWindow(frame_inside, wxID_ANY, wOffset, wxDefaultSize);
1770+
int mode = wxBORDER_NONE;
1771+
frame_inside = new wxPanel(frame, wxID_ANY, wxDefaultPosition, wxDefaultSize, mode);
1772+
frame_inside->SetBackgroundColour(*wxLIGHT_GREY);
1773+
panelsz->Add(frame_inside, FRAME_ALLOWSTRETCH, wxALL, newframewidth);
1774+
1775+
sz_inside = new wxBoxSizer(wxVERTICAL);
1776+
frame_inside->SetSizer(sz_inside);
1777+
}
17781778
if (xpad > 0 || ypad > 0) {
1779-
wxScrolled<wxPanel>* padxpady = new wxScrolled<wxPanel>(frame);
1779+
wxScrolled<wxPanel>* padxpady = new wxScrolled<wxPanel>(frame_inside);
17801780
#ifdef GDL_DEBUG_WIDGETS_COLORIZE
17811781
padxpady->SetBackgroundColour(wxColour(0xa7, 0x3d, 0x0f)); //orange fonce
1782+
#else
1783+
if (tryToMimicOriginalWidgets ) padxpady->SetBackgroundColour(wxColour(sysPanelDefaultColour));
17821784
#endif
17831785
wxGridBagSizer* sz = new wxGridBagSizer(ypad, xpad);
17841786
padxpady->SetSizer(sz);
@@ -1799,12 +1801,14 @@ void GDLWidgetBase::CreateBase(wxWindow* parent){
17991801
padxpady->SetScrollbars(gdlSCROLL_RATE, gdlSCROLL_RATE, wSize.x / gdlSCROLL_RATE, wSize.y / gdlSCROLL_RATE);
18001802
padxpady->ShowScrollbars(wxSHOW_SB_ALWAYS, wxSHOW_SB_ALWAYS);
18011803
}
1802-
panelsz->Add(padxpady, FRAME_ALLOWSTRETCH, wxALL | wxEXPAND, frameWidth);//gdlFRAME_MARGIN);
1803-
panelsz->Fit(padxpady);
1804+
sz_inside->Add(padxpady, FRAME_ALLOWSTRETCH, wxALL | wxEXPAND, newframewidth);//gdlFRAME_MARGIN);
1805+
sz_inside->Fit(padxpady);
18041806
} else {
1805-
widgetPanel = new wxScrolledWindow(frame, widgetID, wOffset, wxDefaultSize);
1807+
widgetPanel = new wxScrolledWindow(frame_inside, widgetID, wOffset, wxDefaultSize);
18061808
#ifdef GDL_DEBUG_WIDGETS_COLORIZE
18071809
widgetPanel->SetBackgroundColour(RandomWxColour());
1810+
#else
1811+
if (tryToMimicOriginalWidgets ) widgetPanel->SetBackgroundColour(wxColour(sysPanelDefaultColour));
18081812
#endif
18091813
// widgetPanel->SetVirtualSize(wSize);
18101814
widgetPanel->SetSize(wScrollSize);
@@ -1814,8 +1818,8 @@ void GDLWidgetBase::CreateBase(wxWindow* parent){
18141818
widgetPanel->SetScrollbars(gdlSCROLL_RATE, gdlSCROLL_RATE, wSize.x / gdlSCROLL_RATE, wSize.y / gdlSCROLL_RATE);
18151819
widgetPanel->ShowScrollbars(wxSHOW_SB_ALWAYS, wxSHOW_SB_ALWAYS);
18161820
}
1817-
panelsz->Add(widgetPanel, FRAME_ALLOWSTRETCH, wxALL | wxEXPAND, frameWidth);//gdlFRAME_MARGIN);
1818-
panelsz->Fit(widgetPanel);
1821+
sz_inside->Add(widgetPanel, FRAME_ALLOWSTRETCH, wxALL | wxEXPAND, newframewidth);//gdlFRAME_MARGIN);
1822+
sz_inside->Fit(widgetPanel);
18191823
}
18201824
theWxWidget = widgetPanel;
18211825
} else {
@@ -2136,7 +2140,6 @@ GDLWidgetTabbedBase::GDLWidgetTabbedBase(WidgetIDT parentID, EnvT* e, ULong even
21362140

21372141
wxNotebook* parentTab = dynamic_cast<wxNotebook*> (parent->GetWxWidget());
21382142
assert(parentTab != NULL);
2139-
21402143
wxString titleWxString = wxString(title_.c_str(), wxConvUTF8);
21412144
if (nrows < 1 && ncols < 1 && frameWidth < 1) frameWidth=1; //set framewidth (temporary) in this case to get good result
21422145
CreateBase(parentTab);
@@ -2473,6 +2476,7 @@ GDLWidgetTab::GDLWidgetTab( WidgetIDT p, EnvT* e, ULong eventFlags_, DLong locat
24732476
theWxContainer = theWxWidget = notebook;
24742477
if (parentSizer) parentSizer->Add(notebook,DONOTALLOWSTRETCH,widgetAlignment()|wxALL, gdlSPACE);
24752478
}
2479+
notebook->SetPadding(wxSize(0,0));
24762480
//wxNotebook DOES NOT USE a sizer.
24772481
this->AddToDesiredEvents(wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGED,wxNotebookEventHandler(gdlwxFrame::OnPageChanged),notebook);
24782482
}
@@ -2511,19 +2515,30 @@ BaseGDL* GDLWidgetTab::GetTabMultiline(){
25112515
//special as wxNotebook DOES NOT RECOMPILE ITS SIZE BEFORE REALIZATION.
25122516
void GDLWidgetTab::OnRealize(){
25132517
GDLWidgetContainer::OnRealize();
2514-
std::cerr<<".";
25152518
wxNotebook * nb=dynamic_cast<wxNotebook*>(theWxWidget);
25162519
assert( nb != NULL);
2517-
nb->InvalidateBestSize();
25182520
size_t n=nb->GetPageCount();
2519-
wxSize s(-1,1);
2520-
for (auto i=0; i<n; ++i) {
2521-
wxWindow* w=nb->GetPage(i);
2522-
wxSize s_tmp=w->GetBestSize();
2523-
s.x = MAX(s.x, s_tmp.x);
2524-
s.y = MAX(s.y, s_tmp.y);
2521+
if (n > 1) {
2522+
wxSize s=nb->GetSize();
2523+
//insure larger enough to see tab changer
2524+
if (s.x < 100) {
2525+
s.x=100;
2526+
nb->SetMinSize(s);
2527+
}
25252528
}
2526-
nb->SetMinSize(s);
2529+
2530+
// nb->InvalidateBestSize();
2531+
// size_t n=nb->GetPageCount();
2532+
// for (auto i=0; i<n; ++i) {
2533+
// wxWindow* w=nb->GetPage(i);
2534+
// wxSize s_tmp=w->GetBestSize();
2535+
// s.x = MAX(s.x, s_tmp.x);
2536+
// s.y = MAX(s.y, s_tmp.y);
2537+
// std::cerr<<"s.x="<<s.x<<" from "<<s_tmp.x<<std::endl;
2538+
// std::cerr<<"s.y="<<s.y<<" from "<<s_tmp.y<<std::endl;
2539+
// }
2540+
// nb->SetMinSize(s);
2541+
// nb->SetMinClientSize(s);
25272542
}
25282543

25292544

@@ -6050,6 +6065,9 @@ void gdlwxPhantomFrame::Realize() {
60506065
if (w.y <= 0) w.y=gdlABSENT_SIZE_VALUE;
60516066
sysScrollHeight=w.y;
60526067
sysScrollWidth=w.x;
6068+
wxColour color=c->GetBackgroundColour();
6069+
sysPanelDefaultColour=color.GetRGB();
6070+
// std::cerr<<sysPanelDefaultColour<<std::endl;
60536071
}
60546072

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

60756093
void gdlwxPlotFrame::Realize() {
6094+
this->SetClientSize(this->GetClientSize());
60766095
#ifdef GDL_DEBUG_WIDGETS
60776096
wxMessageOutputStderr().Printf(_T("gdlwxPlotFrame:Realize\n"));
60786097
#endif

src/gdlwidget.hpp

+11-8
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,8 @@
8181
#define gdlBUTTON_SPACE 4
8282
#define gdlSMALL_SPACE 1
8383
#define gdlBORDER_SPACE 2
84-
#define gdlBORDER_EXT wxBORDER_THEME // wxBORDER_SUNKEN //wxBORDER_RAISED//wxBORDER_SIMPLE //wxBORDER_RAISED
85-
#define gdlBORDER_INT wxBORDER_NONE //wxBORDER_SUNKEN
84+
#define gdlBORDER_EXT wxBORDER_SUNKEN // wxBORDER_THEME // wxBORDER_SUNKEN //wxBORDER_RAISED//wxBORDER_SIMPLE //wxBORDER_RAISED
85+
#define gdlBORDER_INT wxBORDER_RAISED //wxBORDER_SUNKEN
8686
#define gdlTEXT_XMARGIN 4
8787
#define gdlTEXT_YMARGIN 4
8888
#define DONOTALLOWSTRETCH 0
@@ -357,7 +357,7 @@ void OnDrag(wxMouseEvent& event);
357357
static int sysScrollHeight=25;
358358
static int sysScrollWidth=25;
359359
static int sysComboboxArrow=25;
360-
360+
static wxUint32 sysPanelDefaultColour;
361361
class GDLWidget
362362
{
363363
// static part is used for the abstraction
@@ -631,6 +631,8 @@ class GDLWidget
631631
virtual bool IsContainer() const { return false;}
632632
virtual bool IsBase() const { return false;}
633633
virtual bool IsTopBase() const { return false;}
634+
virtual bool IsNormalBase() const { return false;}
635+
virtual bool IsTabbedBase() const { return false;}
634636
virtual bool IsContextBase() const { return false; }
635637
virtual bool IsButton() const { return false;}
636638
virtual bool IsMenu() const { return false;}
@@ -832,8 +834,6 @@ class GDLWidgetBase: public GDLWidgetContainer
832834
void CreateBase(wxWindow* parent);
833835
bool IsVertical() {return (ncols>0);}
834836
bool IsHorizontal() {return (nrows>0);}
835-
virtual bool IsNormalBase() const { return false;}
836-
virtual bool IsTabbedBase() const { return false;}
837837
void SetWidgetSize(DLong sizex, DLong sizey) final;
838838

839839
void NullWxWidget() { theWxWidget = NULL;}
@@ -921,9 +921,12 @@ class GDLWidgetTopBase : public GDLWidgetBase {
921921
if (w != NULL)
922922
w->OnRealize();
923923
}
924-
topFrame->Fit();
925-
topFrame->refreshFrameSize();
926924
DoMapAsRequested();
925+
926+
topFrame->Fit();
927+
topFrame->SetClientSize(topFrame->GetClientSize());
928+
topFrame->refreshFrameSize();
929+
927930
ConnectToDesiredEvents();
928931

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

992995
~GDLWidgetTabbedBase();
993996
void SetBaseTitle(std::string &s);
994-
bool IsTabbedBase() const { return true; }
997+
bool IsTabbedBase() const final { return true;}
995998
void mapBase(bool val) final;
996999

9971000
//Same as Container except that we have to reorder widgets in some cases

src/gdlwidgeteventhandler.cpp

+10-6
Original file line numberDiff line numberDiff line change
@@ -93,16 +93,20 @@ wxPoint gdlwxGraphicsPanel::WhereIsMouse(wxMouseEvent &e) {
9393
}
9494
int RemapModifiers(wxMouseEvent &e) {
9595
int out = 0;
96+
#ifndef __WXGTK__
9697
if (wxGetKeyState(WXK_CAPITAL)) out |= 0x04;
97-
if (e.ControlDown()) out |= 0x02;
98+
#endif
99+
if (e.RawControlDown()) out |= 0x02; //RAW for OSX specificity
98100
if (e.AltDown()) out |= 0x08;
99101
if (e.ShiftDown()) out |= 0x01;
100102
return out;
101103
}
102104
int GetModifiers() {
103105
int out = 0;
106+
#ifndef __WXGTK__
104107
if (wxGetKeyState(WXK_CAPITAL)) out |= 0x04;
105-
if (wxGetKeyState(WXK_CONTROL)) out |= 0x02;
108+
#endif
109+
if (wxGetKeyState(WXK_RAW_CONTROL)) out |= 0x02; //RAW for OSX specificity
106110
if (wxGetKeyState(WXK_ALT)) out |= 0x08;
107111
if (wxGetKeyState(WXK_SHIFT)) out |= 0x01;
108112
return out;
@@ -1382,7 +1386,7 @@ void gdlwxGraphicsPanel::OnPaint(wxPaintEvent& event)
13821386
void gdlwxPlotPanel::OnPlotWindowSize(wxSizeEvent &event) {
13831387
wxSize newSize = event.GetSize(); //size returned by the external frame
13841388
gdlwxPlotFrame* p = this->GetMyFrame();
1385-
p->Disconnect(wxEVT_SIZE, wxSizeEventHandler(gdlwxPlotFrame::OnPlotWindowSize));
1389+
// p->Disconnect(wxEVT_SIZE, wxSizeEventHandler(gdlwxPlotFrame::OnPlotWindowSize));
13861390
#if (GDL_DEBUG_ALL_EVENTS || GDL_DEBUG_SIZE_EVENTS)
13871391
wxMessageOutputStderr().Printf(_T("in gdlwxPlotPanel::OnPlotWindowSize: %d (%d,%d), (%d,%d)\n"), event.GetId(), event.GetSize().x, event.GetSize().y,
13881392
newSize.x, newSize.y);
@@ -1414,9 +1418,9 @@ void gdlwxPlotPanel::OnPlotWindowSize(wxSizeEvent &event) {
14141418
(*static_cast<DLongGDL*> (SysVar::D()->GetTag(SysVar::D()->Desc()->TagIndex("X_VSIZE"), 0)))[0] = newSize.x;
14151419
(*static_cast<DLongGDL*> (SysVar::D()->GetTag(SysVar::D()->Desc()->TagIndex("Y_VSIZE"), 0)))[0] = newSize.y;
14161420

1417-
p->Fit();
1418-
p->Refresh();
1419-
p->Connect(wxEVT_SIZE, wxSizeEventHandler(gdlwxPlotFrame::OnPlotWindowSize));
1421+
// p->Fit();
1422+
// p->Refresh();
1423+
// p->Connect(wxEVT_SIZE, wxSizeEventHandler(gdlwxPlotFrame::OnPlotWindowSize));
14201424
// event.Skip();
14211425
}
14221426
void gdlwxGraphicsPanel::OnPlotWindowSize(wxSizeEvent &event)

src/objects.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ volatile bool iAmANotebook;
107107
//do we use name Devices differently among platforms?
108108
volatile bool usePlatformDeviceName;
109109
// do we force fonts to be the ugly IDL fonts?
110-
volatile bool forceWxWidgetsUglyFonts;
110+
volatile bool tryToMimicOriginalWidgets;
111111
//do we use our own copy of (better?) drivers?
112112
volatile bool useLocalDrivers;
113113
//do we favor SIMD-accelerated random number generation?

src/objects.hpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ extern volatile bool useWxWidgets;
7878
// tells if wxwidgets backend for graphics is to be used...
7979
extern volatile bool useWxWidgetsForGraphics;
8080
// do we force fonts to be the ugly IDL fonts?
81-
extern volatile bool forceWxWidgetsUglyFonts;
81+
extern volatile bool tryToMimicOriginalWidgets;
8282
//do we favor SIMD-accelerated random number generation?
8383
extern volatile bool useDSFMTAcceleration;
8484
//do we use our own copy of (better?) drivers?

0 commit comments

Comments
 (0)