OrcaSlicer latest
OrcaSlicer
Loading...
Searching...
No Matches
Slic3r::GUI::DockPanel Class Reference

#include </home/runner/work/OrcaSlicer/OrcaSlicer/src/slic3r/GUI/DockPanel.hpp>

Inheritance diagram for Slic3r::GUI::DockPanel:
Collaboration diagram for Slic3r::GUI::DockPanel:

Public Types

using MessageHandler = std::function<void(const nlohmann::json& data)>
using CloseHandler = std::function<void()>

Public Member Functions

 DockPanel (wxWindow *parent, const std::string &html, MessageHandler on_message, CloseHandler on_close, CloseHandler on_destroyed)
 ~DockPanel () override
void push_message (const nlohmann::json &data)
void request_close ()
void destroy_silently ()
void fire_close ()

Protected Member Functions

std::optional< std::string > page_html () override
bool on_page_message (const std::string &kind, const nlohmann::json &data) override
wxWebView * browser () const
void post_to_page (const std::string &json)

Private Member Functions

void remove_pane ()
void on_load_event (wxWebViewEvent &event)
void on_navigated (wxWebViewEvent &event)
void on_script_message (wxWebViewEvent &event)
void on_webview_recreated (wxCommandEvent &event)
void apply_theme ()
void load_page_html ()

Private Attributes

std::string m_html
bool m_closing {false}
MessageHandler m_on_message
CloseHandler m_on_close
CloseHandler m_on_destroyed
wxWebView * m_browser {nullptr}
bool m_content_loaded {false}
bool m_own_page_load {false}
bool m_content_navigated {false}

Detailed Description

Member Typedef Documentation

◆ CloseHandler

using Slic3r::GUI::DockPanel::CloseHandler = std::function<void()>

◆ MessageHandler

using Slic3r::GUI::DockPanel::MessageHandler = std::function<void(const nlohmann::json& data)>

Constructor & Destructor Documentation

◆ DockPanel()

Slic3r::GUI::DockPanel::DockPanel ( wxWindow * parent,
const std::string & html,
MessageHandler on_message,
CloseHandler on_close,
CloseHandler on_destroyed )
31 , m_html(html)
32 , m_on_message(std::move(on_message))
33 , m_on_close(std::move(on_close))
34 , m_on_destroyed(std::move(on_destroyed))
35{
36 // A link asking for a new window has nowhere to open from a docked panel.
37 browser()->Bind(wxEVT_WEBVIEW_NEWWINDOW, [](wxWebViewEvent& event) { event.Veto(); });
38}
CloseHandler m_on_close
Definition DockPanel.hpp:53
std::string m_html
Definition DockPanel.hpp:50
MessageHandler m_on_message
Definition DockPanel.hpp:52
CloseHandler m_on_destroyed
Definition DockPanel.hpp:54
WebPanel(wxWindow *parent, const char *bridge_script)
Definition WebPanel.cpp:21
wxWebView * browser() const
Definition WebPanel.hpp:28
const char * orca_bridge_script()
Definition WebHosting.cpp:67

References Slic3r::GUI::WebPanel::WebPanel(), Slic3r::GUI::WebPanel::browser(), m_html, m_on_close, m_on_destroyed, and m_on_message.

Here is the call graph for this function:

◆ ~DockPanel()

Slic3r::GUI::DockPanel::~DockPanel ( )
override
41{
44}

References m_on_destroyed.

Member Function Documentation

◆ apply_theme()

void Slic3r::GUI::WebPanel::apply_theme ( )
privateinherited
104{
106}
wxWebView * m_browser
Definition WebPanel.hpp:48
static std::string theme_apply_script()
Definition WebViewHostDialog.cpp:88
static bool RunScript(wxWebView *webView, wxString const &msg)
Definition WebView.cpp:491

References m_browser, WebView::RunScript(), and Slic3r::GUI::WebViewHostDialog::theme_apply_script().

Referenced by on_load_event(), and on_webview_recreated().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ browser()

wxWebView * Slic3r::GUI::WebPanel::browser ( ) const
inlineprotectedinherited
28{ return m_browser; }

References m_browser.

Referenced by Slic3r::GUI::DockPanel::DockPanel(), Slic3r::PluginPage::PluginPage(), and Slic3r::PluginPage::on_new_window().

Here is the caller graph for this function:

◆ destroy_silently()

void Slic3r::GUI::DockPanel::destroy_silently ( )
93{
94 m_closing = true;
95 m_on_close = nullptr;
97}
bool m_closing
Definition DockPanel.hpp:51
void remove_pane()
Definition DockPanel.cpp:99

References m_closing, m_on_close, and remove_pane().

Here is the call graph for this function:

◆ fire_close()

void Slic3r::GUI::DockPanel::fire_close ( )
67{
68 if (m_closing)
69 return;
70 m_closing = true;
71 if (m_on_close) {
72 CloseHandler on_close = std::move(m_on_close);
73 m_on_close = nullptr;
74 on_close();
75 }
76}
std::function< void()> CloseHandler
Definition DockPanel.hpp:22

References m_closing, and m_on_close.

Referenced by request_close().

Here is the caller graph for this function:

◆ load_page_html()

void Slic3r::GUI::WebPanel::load_page_html ( )
privateinherited
76{
77 if (const std::optional<std::string> html = page_html()) {
78 m_own_page_load = true;
79 m_browser->SetPage(wxString::FromUTF8(*html), web_hosting::content_base_url());
80 }
81}
bool m_own_page_load
Definition WebPanel.hpp:50
virtual std::optional< std::string > page_html()=0
wxString content_base_url()
Definition WebHosting.cpp:55

References Slic3r::GUI::web_hosting::content_base_url(), m_browser, m_own_page_load, and page_html().

Referenced by on_load_event().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ on_load_event()

void Slic3r::GUI::WebPanel::on_load_event ( wxWebViewEvent & event)
privateinherited
43{
44 const bool loaded = event.GetEventType() == wxEVT_WEBVIEW_LOADED;
45 if (!m_content_loaded) {
46 // The first bootstrap load (or its error) triggers the swap to the plugin HTML.
47 m_content_loaded = true;
49 } else if (!web_hosting::is_content_url(event.GetURL())) {
50 // Not our document (a linked page, a substituted error page), or any document on Edge, which ignores
51 // the base URL and restores SetPage content on a reload itself; either way it takes the app theme.
52 if (loaded)
54 } else if (m_own_page_load) {
55 m_own_page_load = false;
56 // The document-start theme script is fixed at creation, so re-apply the app theme.
57 if (loaded)
59 } else if (loaded && m_content_navigated) {
60 // WebKit reloads the SetPage base URL, so a committed load of it that we did not start is a
61 // reload. A failed navigation is reported against the page that stayed but never commits.
63 }
64 if (loaded)
65 m_content_navigated = false;
66 event.Skip();
67}
bool m_content_loaded
Definition WebPanel.hpp:49
void load_page_html()
Definition WebPanel.cpp:75
bool m_content_navigated
Definition WebPanel.hpp:51
void apply_theme()
Definition WebPanel.cpp:103
bool is_content_url(const wxString &url)
Definition WebHosting.cpp:60

References apply_theme(), Slic3r::GUI::web_hosting::is_content_url(), load_page_html(), m_content_loaded, m_content_navigated, and m_own_page_load.

Referenced by WebPanel().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ on_navigated()

void Slic3r::GUI::WebPanel::on_navigated ( wxWebViewEvent & event)
privateinherited
70{
72 event.Skip();
73}

References Slic3r::GUI::web_hosting::is_content_url(), and m_content_navigated.

Referenced by WebPanel().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ on_page_message()

bool Slic3r::GUI::DockPanel::on_page_message ( const std::string & kind,
const nlohmann::json & data )
overrideprotectedvirtual

Implements Slic3r::GUI::WebPanel.

47{
48 if (kind == "message") {
49 if (m_on_message)
50 m_on_message(data);
51 return true;
52 }
53 if (kind == "close") {
55 return true;
56 }
57 return false;
58}
void request_close()
Definition DockPanel.cpp:78

References m_on_message, and request_close().

Here is the call graph for this function:

◆ on_script_message()

void Slic3r::GUI::WebPanel::on_script_message ( wxWebViewEvent & event)
privateinherited
84{
85 const nlohmann::json payload = nlohmann::json::parse(event.GetString().utf8_string(), nullptr, false);
86 if (!payload.is_object() || payload.value("channel", std::string()) != "orca")
87 return;
88
89 const std::string kind = payload.value("kind", std::string());
90 if (!on_page_message(kind, payload.contains("data") ? payload["data"] : nlohmann::json()))
91 BOOST_LOG_TRIVIAL(warning) << "WebPanel ignored a window.orca '" << kind << "' call; this host does not support it";
92}
virtual bool on_page_message(const std::string &kind, const nlohmann::json &data)=0

References on_page_message().

Referenced by WebPanel().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ on_webview_recreated()

void Slic3r::GUI::WebPanel::on_webview_recreated ( wxCommandEvent & event)
privateinherited
95{
96 SetBackgroundColour(wxGetApp().get_window_default_clr());
97 m_browser->SetBackgroundColour(GetBackgroundColour());
98 Refresh();
99 // Handled without Skip(), so WebView::RecreateAll() does not reload the plugin page.
100 apply_theme();
101}

References apply_theme(), and m_browser.

Referenced by WebPanel().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ page_html()

std::optional< std::string > Slic3r::GUI::DockPanel::page_html ( )
inlineoverrideprotectedvirtual

Implements Slic3r::GUI::WebPanel.

44{ return m_html; }

References m_html.

◆ post_to_page()

void Slic3r::GUI::WebPanel::post_to_page ( const std::string & json)
protectedinherited
109{
110 WebView::RunScript(m_browser, wxString::Format(
111 "(function dispatch(payload, attempts) {\n"
112 " if (typeof window.__orcaDispatch === 'function') { window.__orcaDispatch(payload); return; }\n"
113 " if (attempts < 100) window.setTimeout(function() { dispatch(payload, attempts + 1); }, 25);\n"
114 "})({data: %s}, 0);",
115 wxString::FromUTF8(json)));
116}
nlohmann::json json
Definition AssembleList.cpp:42

References m_browser, and WebView::RunScript().

Referenced by Slic3r::GUI::DockPanel::push_message(), and Slic3r::PluginPage::push_message().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ push_message()

void Slic3r::GUI::DockPanel::push_message ( const nlohmann::json & data)
61{
62 if (!m_closing)
63 post_to_page(data.dump(-1, ' ', false, nlohmann::json::error_handler_t::replace));
64}
void post_to_page(const std::string &json)
Definition WebPanel.cpp:108

References m_closing, and Slic3r::GUI::WebPanel::post_to_page().

Here is the call graph for this function:

◆ remove_pane()

void Slic3r::GUI::DockPanel::remove_pane ( )
private
100{
101 if (Plater* plater = wxGetApp().plater())
103 else
104 Destroy();
105}
void remove_dock_pane(wxWindow *window)
Definition Plater.cpp:19169
static Plater * plater()
Definition GUI_Factories.cpp:400
@ Plater
Definition Shortcuts.hpp:21

References Slic3r::GUI::plater().

Referenced by destroy_silently().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ request_close()

void Slic3r::GUI::DockPanel::request_close ( )
79{
80 if (m_closing)
81 return;
82 fire_close();
83 // A page-requested close arrives inside the web view's script callback, so destroy later; another
84 // close path may have destroyed the panel by then.
85 wxWeakRef<DockPanel> self(this);
86 CallAfter([self]() {
87 if (self)
88 self->remove_pane();
89 });
90}
void fire_close()
Definition DockPanel.cpp:66

References fire_close(), and m_closing.

Referenced by on_page_message().

Here is the call graph for this function:
Here is the caller graph for this function:

Member Data Documentation

◆ m_browser

wxWebView* Slic3r::GUI::WebPanel::m_browser {nullptr}
privateinherited

◆ m_closing

bool Slic3r::GUI::DockPanel::m_closing {false}
private

◆ m_content_loaded

bool Slic3r::GUI::WebPanel::m_content_loaded {false}
privateinherited
49{false};

Referenced by on_load_event().

◆ m_content_navigated

bool Slic3r::GUI::WebPanel::m_content_navigated {false}
privateinherited
51{false}; // a navigation to the base URL has committed

Referenced by on_load_event(), and on_navigated().

◆ m_html

std::string Slic3r::GUI::DockPanel::m_html
private

Referenced by DockPanel(), and page_html().

◆ m_on_close

CloseHandler Slic3r::GUI::DockPanel::m_on_close
private

◆ m_on_destroyed

CloseHandler Slic3r::GUI::DockPanel::m_on_destroyed
private

Referenced by DockPanel(), and ~DockPanel().

◆ m_on_message

MessageHandler Slic3r::GUI::DockPanel::m_on_message
private

Referenced by DockPanel(), and on_page_message().

◆ m_own_page_load

bool Slic3r::GUI::WebPanel::m_own_page_load {false}
privateinherited
50{false}; // a SetPage of the plugin HTML is in flight

Referenced by load_page_html(), and on_load_event().


The documentation for this class was generated from the following files:
  • /home/runner/work/OrcaSlicer/OrcaSlicer/src/slic3r/GUI/DockPanel.hpp
  • /home/runner/work/OrcaSlicer/OrcaSlicer/src/slic3r/GUI/DockPanel.cpp