std::shared_ptr
[dcpomatic.git] / src / wx / content_panel.cc
index 2c5fea79bee8596190813e00c707525fe313f09a..7114e8337fb6b6298ef9aada0ffe0b65d9c218e3 100644 (file)
@@ -57,9 +57,9 @@ using std::cout;
 using std::vector;
 using std::max;
 using std::exception;
-using boost::shared_ptr;
-using boost::weak_ptr;
-using boost::dynamic_pointer_cast;
+using std::shared_ptr;
+using std::weak_ptr;
+using std::dynamic_pointer_cast;
 using boost::optional;
 using namespace dcpomatic;
 #if BOOST_VERSION >= 106100
@@ -154,17 +154,7 @@ ContentPanel::ContentPanel (wxNotebook* n, shared_ptr<Film> film, weak_ptr<FilmV
 void
 ContentPanel::first_shown ()
 {
-       int const sn = wxDisplay::GetFromWindow(_splitter);
-       if (sn >= 0) {
-               wxRect const screen = wxDisplay(sn).GetClientArea();
-               /* This is a hack to try and make the content notebook a sensible size; large on big displays but small
-                  enough on small displays to leave space for the content area.
-                  */
-               _splitter->SplitHorizontally (_top_panel, _notebook, screen.height > 800 ? -600 : -150);
-       } else {
-               /* Fallback for when GetFromWindow fails for reasons that aren't clear */
-               _splitter->SplitHorizontally (_top_panel, _notebook, -600);
-       }
+       _splitter->first_shown (_top_panel, _notebook);
 }
 
 
@@ -809,3 +799,49 @@ ContentPanel::panels () const
        p.push_back (_timing_panel);
        return p;
 }
+
+
+LimitedSplitter::LimitedSplitter (wxWindow* parent)
+       : wxSplitterWindow (parent, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxSP_NOBORDER | wxSP_3DSASH | wxSP_LIVE_UPDATE)
+       , _first_shown (false)
+       , _top_panel_minimum_size (350)
+{
+       /* This value doesn't really mean much but we just want to stop double-click on the
+          divider from shrinking the bottom panel (#1601).
+       */
+       SetMinimumPaneSize (64);
+
+       Bind (wxEVT_SIZE, boost::bind(&LimitedSplitter::sized, this, _1));
+}
+
+
+void
+LimitedSplitter::first_shown (wxWindow* top, wxWindow* bottom)
+{
+       int const sn = wxDisplay::GetFromWindow(this);
+       if (sn >= 0) {
+               wxRect const screen = wxDisplay(sn).GetClientArea();
+               /* This is a hack to try and make the content notebook a sensible size; large on big displays but small
+                  enough on small displays to leave space for the content area.
+                  */
+               SplitHorizontally (top, bottom, screen.height > 800 ? -600 : -_top_panel_minimum_size);
+       } else {
+               /* Fallback for when GetFromWindow fails for reasons that aren't clear */
+               SplitHorizontally (top, bottom, -600);
+       }
+       _first_shown = true;
+}
+
+
+void
+LimitedSplitter::sized (wxSizeEvent& ev)
+{
+       if (_first_shown && GetSize().GetHeight() > _top_panel_minimum_size && GetSashPosition() < _top_panel_minimum_size) {
+               /* The window is now fairly big but the top panel is small; this happens when the DCP-o-matic window
+                * is shrunk and then made larger again.  Try to set a sensible top panel size in this case (#1839).
+                */
+               SetSashPosition (_top_panel_minimum_size);
+       }
+
+       ev.Skip ();
+}