mirror of
https://github.com/OrcaSlicer/OrcaSlicer.git
synced 2026-10-10 09:11:08 +00:00
* Remove Unused Project Includes and Forward-Declare Where a Type Is Only Referenced Generated with include-what-you-use and applied conservatively. Only OrcaSlicer's own headers, the ones under src/ and tests/, are removed or forward-declared; standard-library and third-party includes are left alone. An include is removed only when both the Release and the Debug configuration leave it unused, never from inside a conditional block, and never from a file with platform-specific blocks, which only gain includes. Files whose only use of a header sits behind a feature or debug macro (libvgcode's OpenGL ES and marker code, the ARACHNE/TESTS_EXPORT_SVGS debug output) keep their includes. clonable_ptr.hpp gains #pragma once; it had no include guard and was only safe while Config.hpp was its sole includer. * Remove Unused Project Includes From Files With Platform-Specific Code A Linux include-what-you-use run cannot see the code inside _WIN32, __APPLE__ or __linux__ blocks, so its verdict is only taken where nothing the removed header declares, directly or through what it includes, is named inside those blocks. Removals also have to hold in both the Release and Debug configuration and never touch a line inside a conditional block. * Restore the libslic3r Precompiled Header and Direct Includes Lost in the Platform Pass The platform-file pass treated pchheader.hpp as an ordinary header and emptied it, and left GUI_Preview.hpp and 14 other files relying on headers they no longer reached directly. * Restore MainFrame.hpp in ParamsDialog.cpp for the Windows-Only Reparent Call * Include Headers That Files Reached Through Ones the Cleanup Removed * Drop Includes Duplicated by the Cleanup or by Main's Own Additions * Leave PreciseSeam.cpp as Main Has It After the Precise Seam Rework
99 lines
3.8 KiB
C++
99 lines
3.8 KiB
C++
#ifndef slic3r_GUI_WebDialog_hpp_
|
|
#define slic3r_GUI_WebDialog_hpp_
|
|
|
|
#include "Widgets/WebViewHostDialog.hpp"
|
|
|
|
#include <functional>
|
|
#include <optional>
|
|
#include <string>
|
|
|
|
#include <nlohmann/json.hpp>
|
|
#include <wx/string.h>
|
|
#include <wx/gdicmn.h>
|
|
#include <wx/toplevel.h>
|
|
#include <wx/event.h>
|
|
#include <wx/webview.h>
|
|
|
|
class wxCloseEvent;
|
|
class wxSize;
|
|
class wxWebViewEvent;
|
|
class wxWindow;
|
|
|
|
namespace Slic3r { namespace GUI {
|
|
|
|
// A host-owned webview window that renders plugin-supplied raw HTML and bridges
|
|
// messages to/from the page through a small injected `window.orca` API.
|
|
//
|
|
// This class is deliberately Python-agnostic: it talks to the plugin layer only
|
|
// through std::function hooks. Those hooks must NOT capture bare pybind11
|
|
// objects, because the dialog can be destroyed on the main thread without the
|
|
// GIL held; the plugin layer wraps any Python callables in a GIL-safe holder.
|
|
//
|
|
// Usable both modally (ShowModal -> read result()) and modelessly (Show()).
|
|
class WebDialog : public Slic3r::GUI::WebViewHostDialog
|
|
{
|
|
public:
|
|
using MessageHandler = std::function<void(const nlohmann::json& data)>;
|
|
using SubmitHandler = std::function<void(const nlohmann::json& data)>;
|
|
using CloseHandler = std::function<void()>;
|
|
|
|
// on_submit fires once for window.orca.submit(). on_close fires only on a
|
|
// user/JS-initiated close (while the window is alive). on_destroyed runs from
|
|
// the destructor on every path and must touch host-side state only (no Python
|
|
// / no derived members).
|
|
WebDialog(wxWindow* parent,
|
|
const wxString& title,
|
|
const std::string& html,
|
|
const wxSize& size,
|
|
MessageHandler on_message,
|
|
SubmitHandler on_submit,
|
|
CloseHandler on_close,
|
|
CloseHandler on_destroyed,
|
|
long wx_style = wxSYSTEM_MENU | wxCAPTION | wxCLOSE_BOX | wxMAXIMIZE_BOX | wxRESIZE_BORDER);
|
|
~WebDialog() override;
|
|
|
|
static void post_message(WebDialog* dialog, const nlohmann::json& data);
|
|
static void request_close(WebDialog* dialog);
|
|
static void destroy_silently(WebDialog* dialog);
|
|
|
|
// Push a payload to the page; delivered to handlers registered via
|
|
// window.orca.onMessage(). MAIN-THREAD ONLY (the plugin layer marshals).
|
|
void push_message(const nlohmann::json& data);
|
|
|
|
bool is_open() const { return m_open; }
|
|
|
|
// The payload submitted via window.orca.submit() (modal use), if any.
|
|
const std::optional<nlohmann::json>& result() const { return m_result; }
|
|
|
|
protected:
|
|
void on_script_message(const nlohmann::json& payload) override;
|
|
// Plugin HTML is loaded as a raw string, not a localized resource URL.
|
|
bool append_language_to_url() const override { return false; }
|
|
void add_user_scripts() override;
|
|
|
|
private:
|
|
void on_bootstrap_event(wxWebViewEvent& event);
|
|
void on_navigated(wxWebViewEvent& event);
|
|
void load_page_html();
|
|
void on_close_window(wxCloseEvent& event);
|
|
void fire_submit(const nlohmann::json& data);
|
|
void fire_close();
|
|
void finish(bool submitted, const nlohmann::json& data);
|
|
|
|
std::string m_html;
|
|
bool m_content_loaded{false};
|
|
bool m_own_page_load{false}; // a SetPage of the plugin HTML is in flight
|
|
bool m_content_navigated{false}; // a navigation to the base URL has committed
|
|
bool m_open{true};
|
|
bool m_close_fired{false};
|
|
std::optional<nlohmann::json> m_result;
|
|
MessageHandler m_on_message;
|
|
SubmitHandler m_on_submit;
|
|
CloseHandler m_on_close;
|
|
CloseHandler m_on_destroyed;
|
|
};
|
|
|
|
}} // namespace Slic3r::GUI
|
|
|
|
#endif // slic3r_GUI_WebDialog_hpp_
|