wxSplitterWindow broken on Windows?

Do you have a typical platform dependent issue you're battling with ? Ask it here. Make sure you mention your platform, compiler, and wxWidgets version.
Post Reply
dwangerin
In need of some credit
In need of some credit
Posts: 2
Joined: Thu May 21, 2020 2:18 pm

wxSplitterWindow broken on Windows?

Post by dwangerin »

It appears that the wxSplitterWindow has two issues on Windows. I am using wxWidgets 3.1.3 on Windows 10 and have checked this with both Visual Studio 2017 and 2019. The wxSplitterWindow used to work on older (2.x) versions of wxWidgets. I have not been able to track down when the wxWidgets code changed or if this is a Windows 10 issue.

The first issue is that the sash does not appear regardless of the style used- it is always an invisible line that can be dragged but has no other visual clue. Another thread (here) mentions this same behavior so I believe the issue is with wxWidgets, not my code. I can probably live with this by using boxes around the split panels, but this is less than ideal.

The second issue is that there does not appear to be a way to set the initial sash position. No matter what value is passed to the SplitVertically() call it will always set the sash at the minimum pane size. This is a serious issue for me since it essentially breaks my app.

Here is the test code:

Code: Select all

#include <wx/wx.h>
#include <wx/splitter.h>
#include <wx/sizer.h>


class EmptyPanel : public wxPanel
{
public:
	EmptyPanel ( wxWindow *parent, std::string label_text ) : wxPanel ( parent )
	{
		wxStaticBoxSizer *sizer = new wxStaticBoxSizer ( wxVERTICAL, this, "" );
		sizer->Add ( new wxStaticText ( sizer->GetStaticBox (), wxID_ANY, label_text ) );
		SetSizerAndFit ( sizer );
	}
	virtual ~EmptyPanel () {};
};


class TestSplitterPanel : public wxPanel
{
public:
	TestSplitterPanel ( wxWindow *parent )
		: wxPanel ( parent )
	{
		// wxSP_3D wxSP_THIN_SASH wxSP_3DSASH wxSP_3DBORDER wxSP_BORDER wxSP_NOBORDER wxSP_NO_XP_THEME
		long style = wxSP_3D;
		wxSplitterWindow *splitter = new wxSplitterWindow ( this, wxID_ANY, wxDefaultPosition, wxDefaultSize, style );
		splitter->SetMinimumPaneSize ( 50 );

		wxPanel *left = new wxPanel ( splitter );
		wxBoxSizer *left_sizer = new wxBoxSizer ( wxVERTICAL );
		left_sizer->Add ( new EmptyPanel ( left, "Left Panel" ), 1, wxEXPAND | wxALL, 5 );
		left->SetSizer ( left_sizer );

		wxPanel *right = new wxPanel ( splitter );
		wxBoxSizer *right_sizer = new wxBoxSizer ( wxVERTICAL );
		right_sizer->Add ( new EmptyPanel ( right, "Right Panel" ), 1, wxEXPAND | wxALL, 5 );
		right->SetSizer ( right_sizer );

		splitter->SplitVertically ( left, right, 200 );
		//splitter->SetSashInvisible ( false );

		wxBoxSizer *sizer = new wxBoxSizer ( wxHORIZONTAL );
		sizer->Add ( splitter, 1, wxEXPAND );
		SetSizerAndFit ( sizer );
		//splitter->SplitVertically (left, right);
	}

	virtual ~TestSplitterPanel () {};
};


class TestFrame : public wxFrame
{
public:
	TestFrame () : wxFrame ( nullptr, -1, "Test" )
	{
		wxBoxSizer* sizer = new wxBoxSizer ( wxVERTICAL );
		sizer->Add ( new TestSplitterPanel ( this ), wxSizerFlags ().Expand ().Proportion ( 1 ) );
		SetSizerAndFit ( sizer );
		SetSize ( 600, 400 );
		Center ();
	};
	virtual ~TestFrame () {};
private:
};


class TestApp : public wxApp
{
public:
	TestApp () {};
	virtual ~TestApp () {};
	virtual bool OnInit () override
	{
		wxFrame* mainFrame = new TestFrame ();
		mainFrame->Show ( true );
		return true;
	};
};


wxIMPLEMENT_APP ( TestApp );
Does anyone know if there is a way to fix these issues, especially issue 2?
New Pagodi
Super wx Problem Solver
Super wx Problem Solver
Posts: 469
Joined: Tue Jun 20, 2006 6:47 pm
Contact:

Re: wxSplitterWindow broken on Windows?

Post by New Pagodi »

Code: Select all

SetSizerAndFit ( sizer );
This tells all windows to resize to the minimum size. Just use SetSizer instead.
dwangerin
In need of some credit
In need of some credit
Posts: 2
Joined: Thu May 21, 2020 2:18 pm

Re: wxSplitterWindow broken on Windows?

Post by dwangerin »

That fixed it! For anyone else reading this thread, the sample code used three instances of SetSizerAndFit(): in the wxFrame, in the main wxPanel that contained the wxSplitterWindow, and in each of the wxPanels inside of the splitter. It is fine to retain the SetSizerAndFit() call in the internal panels of the splitter but must be removed from both the wxFrame and the main wxPanel.
Post Reply