Remember position and size of caption list view.
authorCarl Hetherington <cth@carlh.net>
Sat, 18 May 2024 09:41:44 +0000 (11:41 +0200)
committerCarl Hetherington <cth@carlh.net>
Sat, 18 May 2024 09:59:54 +0000 (11:59 +0200)
src/wx/text_panel.cc
src/wx/text_view.cc
src/wx/text_view.h
src/wx/window_metrics.cc [new file with mode: 0644]
src/wx/window_metrics.h [new file with mode: 0644]
src/wx/wscript

index c3a5706b0d23ced98d2bd98b47ea57b81ea3b4cf..4b6e900db984e7f793de3728646b04d6dd7079cd 100644 (file)
@@ -712,7 +712,7 @@ TextPanel::text_view_clicked ()
 
        if (decoder) {
                _text_view.reset(this, _parent->film(), c.front(), c.front()->text_of_original_type(_original_type), decoder, _parent->film_viewer());
-               _text_view->Show ();
+               _text_view->show();
        }
 }
 
index 7e526788651794a717e38c75deba15741f249418..7f60e79f06195516d7cfe723ad88a2f774003d85 100644 (file)
@@ -42,14 +42,17 @@ using namespace boost::placeholders;
 #endif
 
 
+WindowMetrics TextView::_metrics;
+
+
 TextView::TextView (
        wxWindow* parent, shared_ptr<Film> film, shared_ptr<Content> content, shared_ptr<TextContent> text, shared_ptr<Decoder> decoder, FilmViewer& viewer
        )
-       : wxDialog (parent, wxID_ANY, _("Captions"), wxDefaultPosition, wxDefaultSize, wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER)
+       : wxDialog(parent, wxID_ANY, _("Captions"), _metrics.position, wxDefaultSize, wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER)
        , _content (content)
        , _film_viewer (viewer)
 {
-       _list = new wxListCtrl (this, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxLC_REPORT | wxLC_SINGLE_SEL);
+       _list = new wxListCtrl(this, wxID_ANY, wxDefaultPosition, _metrics.size, wxLC_REPORT | wxLC_SINGLE_SEL);
 
        {
                wxListItem ip;
@@ -104,9 +107,34 @@ TextView::TextView (
        }
        while (!decoder->pass ()) {}
        SetSizerAndFit (sizer);
+
+       _list->Bind(wxEVT_SIZE, boost::bind(&TextView::list_sized, this, _1));
+       Bind(wxEVT_MOVE, boost::bind(&TextView::moved, this, _1));
 }
 
 
+void
+TextView::list_sized(wxSizeEvent& ev)
+{
+       _metrics.size = ev.GetSize();
+       ev.Skip();
+}
+
+
+void
+TextView::moved(wxMoveEvent& ev)
+{
+       _metrics.position = ClientToScreen({0, 0});
+       ev.Skip();
+}
+
+
+void
+TextView::show()
+{
+       _metrics.show(this);
+}
+
 void
 TextView::data_start (ContentStringText cts)
 {
index 8cf3c78bbf580480270810723f06878204f50a47..d1271ef268c25ed3e7ae6632d0c36bd19613a850 100644 (file)
@@ -18,6 +18,8 @@
 
 */
 
+
+#include "window_metrics.h"
 #include "lib/content_text.h"
 #include <dcp/warnings.h>
 LIBDCP_DISABLE_WARNINGS
@@ -25,10 +27,12 @@ LIBDCP_DISABLE_WARNINGS
 #include <wx/wx.h>
 LIBDCP_ENABLE_WARNINGS
 
+
 class Decoder;
 class FilmViewer;
 class Film;
 
+
 class TextView : public wxDialog
 {
 public:
@@ -41,10 +45,14 @@ public:
                FilmViewer& viewer
                );
 
+       void show();
+
 private:
        void data_start (ContentStringText cts);
        void data_stop (dcpomatic::ContentTime time);
        void subtitle_selected (wxListEvent &);
+       void moved(wxMoveEvent& ev);
+       void list_sized(wxSizeEvent& ev);
 
        wxListCtrl* _list;
        int _subs;
@@ -53,4 +61,6 @@ private:
        std::vector<dcpomatic::ContentTime> _start_times;
        std::weak_ptr<Content> _content;
        FilmViewer& _film_viewer;
+
+       static WindowMetrics _metrics;
 };
diff --git a/src/wx/window_metrics.cc b/src/wx/window_metrics.cc
new file mode 100644 (file)
index 0000000..4b0c6ce
--- /dev/null
@@ -0,0 +1,45 @@
+/*
+    Copyright (C) 2024 Carl Hetherington <cth@carlh.net>
+
+    This file is part of DCP-o-matic.
+
+    DCP-o-matic is free software; you can redistribute it and/or modify
+    it under the terms of the GNU General Public License as published by
+    the Free Software Foundation; either version 2 of the License, or
+    (at your option) any later version.
+
+    DCP-o-matic is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+    GNU General Public License for more details.
+
+    You should have received a copy of the GNU General Public License
+    along with DCP-o-matic.  If not, see <http://www.gnu.org/licenses/>.
+
+*/
+
+
+#include "window_metrics.h"
+#include <dcp/warnings.h>
+LIBDCP_DISABLE_WARNINGS
+#include <wx/app.h>
+#include <wx/wx.h>
+LIBDCP_ENABLE_WARNINGS
+
+
+void
+WindowMetrics::show(wxWindow* window) const
+{
+#ifdef DCPOMATIC_LINUX
+       auto const position_before = position;
+#endif
+
+       window->Show();
+
+#ifdef DCPOMATIC_LINUX
+       wxTheApp->CallAfter([window, position_before] {
+               window->SetPosition(position_before);
+       });
+#endif
+}
+
diff --git a/src/wx/window_metrics.h b/src/wx/window_metrics.h
new file mode 100644 (file)
index 0000000..30a9211
--- /dev/null
@@ -0,0 +1,39 @@
+/*
+    Copyright (C) 2024 Carl Hetherington <cth@carlh.net>
+
+    This file is part of DCP-o-matic.
+
+    DCP-o-matic is free software; you can redistribute it and/or modify
+    it under the terms of the GNU General Public License as published by
+    the Free Software Foundation; either version 2 of the License, or
+    (at your option) any later version.
+
+    DCP-o-matic is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+    GNU General Public License for more details.
+
+    You should have received a copy of the GNU General Public License
+    along with DCP-o-matic.  If not, see <http://www.gnu.org/licenses/>.
+
+*/
+
+
+#include <dcp/warnings.h>
+LIBDCP_DISABLE_WARNINGS
+#include <wx/gdicmn.h>
+LIBDCP_ENABLE_WARNINGS
+
+
+class wxWindow;
+
+
+class WindowMetrics
+{
+public:
+       void show(wxWindow* window) const;
+
+       wxPoint position = wxDefaultPosition;
+       wxSize size = wxDefaultSize;
+};
+
index bdae9708ee4c35a19bca0363f8756968179dde92..0255149eddec98decfb702d0706d14281c449691 100644 (file)
@@ -186,6 +186,7 @@ sources = """
           video_view.cc
           video_waveform_dialog.cc
           video_waveform_plot.cc
+          window_metrics.cc
           wx_signal_manager.cc
           wx_util.cc
           wx_variant.cc