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

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

Inheritance diagram for Slic3r::GUI::ColorPickerDialog:
Collaboration diagram for Slic3r::GUI::ColorPickerDialog:

Public Member Functions

 ColorPickerDialog (wxWindow *parent, const ColorSelection &initial, ColorPickerOptions options={}, bool preserve_multi_color=false, wxWindow *anchor=nullptr)
 ~ColorPickerDialog () override
const std::optional< ColorSelection > & selection () const
bool create_webview (const std::string &resource_path, const wxString &title, const wxSize &dialog_size=wxSize(820, 660), const wxSize &min_size=wxSize(640, 640))
void load_url (const wxString &url)
bool run_script (const wxString &script)
void call_web_handler (const nlohmann::json &payload, const wxString &handler=wxT("HandleStudio"))
void EndModal (int retCode) override
float scale_factor () const
float prev_scale_factor () const
void set_scale_factor (float v)
void set_prev_scale_factor (float v)
void set_em_unit (int v)
bool force_rescale () const
int em_unit () const
const wxFont & normal_font () const
void enable_force_rescale ()
int ShowModal ()

Static Public Member Functions

static std::string document_start_injector (const std::string &markup, const char *dom_id, const char *position, const std::string &prelude={}, const std::string &on_inject={})
static std::string theme_user_script ()
static std::string element_defaults_user_script ()
static std::string theme_apply_script ()
static std::string localized_strings_script (const nlohmann::json &strings)

Protected Member Functions

wxWebView * browser () const
wxString build_resource_url (const std::string &resource_path) const
bool handle_common_script_command (const nlohmann::json &payload, int close_return_code=wxID_CANCEL)
virtual void on_script_message_parse_error (const wxString &payload, const std::exception &error)
virtual bool append_language_to_url () const
void register_theme_user_scripts ()
virtual nlohmann::json localized_strings () const
void apply_theme_live ()

Private Member Functions

void add_user_scripts () override
void on_script_message (const nlohmann::json &payload) override
void handle_web_command (const nlohmann::json &payload)
void send_initial_state ()
void finish (int return_code)
void position_panel ()
void move_to_anchor ()
void resize_to_content (int height)
void focus_webview ()
void repaint_webview ()
void on_dpi_changed (const wxRect &suggested_rect) override
void on_sys_color_changed () override
void on_script_message_event (wxWebViewEvent &event)
void on_webview_recreated (wxCommandEvent &event)
void update_em_unit ()
bool is_new_scale_factor () const
void rescale (const wxRect &suggested_rect)

Private Attributes

ColorSelection m_initial
ColorPickerOptions m_options
std::optional< ColorSelection > m_selection
std::vector< ColorSelection > m_favorites
std::string m_page_id
bool m_preserve_multi_color = false
bool m_init_sent = false
bool m_page_ready = false
bool m_closing = false
bool m_favorites_writable = false
bool m_sidebar_open = false
std::string m_palette
bool m_initial_positioned = false
wxRect m_anchor_rect
wxRect m_work_area
int m_content_height = 360
int m_content_width = 330
bool m_positioning = false
std::shared_ptr< std::atomic< bool > > m_alive = std::make_shared<std::atomic<bool>>(true)
wxWebView * m_browser {nullptr}
float m_scale_factor
int m_em_unit
wxFont m_normal_font
float m_prev_scale_factor
bool m_can_rescale
bool m_force_rescale
int m_new_font_point_size

Detailed Description

Constructor & Destructor Documentation

◆ ColorPickerDialog()

Slic3r::GUI::ColorPickerDialog::ColorPickerDialog ( wxWindow * parent,
const ColorSelection & initial,
ColorPickerOptions options = {},
bool preserve_multi_color = false,
wxWindow * anchor = nullptr )
747 : WebViewHostDialog(parent, wxID_ANY, _L("Color Picker"), wxDefaultPosition, wxDefaultSize,
748 wxCAPTION | wxSYSTEM_MENU | wxCLOSE_BOX | wxFRAME_NO_TASKBAR),
749 m_initial(initial), m_options(options), m_preserve_multi_color(preserve_multi_color)
750{
751 Bind(wxEVT_CLOSE_WINDOW, [this](wxCloseEvent&) { finish(wxID_CANCEL); });
752 Bind(wxEVT_CHAR_HOOK, [this](wxKeyEvent& event) {
753 if (event.GetKeyCode() == WXK_ESCAPE)
754 finish(wxID_CANCEL);
755 else
756 event.Skip();
757 });
758 SetBackgroundColour(wxGetApp().get_window_default_clr());
759 wxGetApp().UpdateDlgDarkUI(this);
760#ifdef __WXGTK__
761 // wxGTK dialogs default to CENTER_ON_PARENT, which conflicts with the anchor.
762 gtk_window_set_position(GTK_WINDOW(GetHandle()), GTK_WIN_POS_NONE);
763#endif
764 // Snapshot the trigger instead of following the mouse or retaining a raw pointer.
765 wxWindow* trigger = anchor ? anchor : parent;
766 if (trigger)
767 m_anchor_rect = trigger->GetScreenRect();
768 int display_index = wxDisplay::GetFromPoint(m_anchor_rect.GetPosition() + wxPoint(m_anchor_rect.width / 2, m_anchor_rect.height / 2));
769 if (display_index == wxNOT_FOUND)
770 display_index = 0;
771 m_work_area = wxDisplay(static_cast<unsigned int>(display_index)).GetClientArea();
772 const auto normalized = normalize_color_selection(initial, options);
773 if (normalized)
774 m_initial = *normalized;
775 // Read the sidebar state before the WebView exists: add_user_scripts() passes it to the page,
776 // and the window opens at the matching size instead of resizing after the page loads.
777 if (wxGetApp().app_config) {
778 const AppConfig& config = *wxGetApp().app_config;
779 m_sidebar_open = config.get(COLOR_PICKER_UI_SECTION, "sidebar_open") == "1";
780 if (const std::string palette = config.get(COLOR_PICKER_UI_SECTION, "palette"); valid_palette_id(palette))
781 m_palette = palette;
782 }
785 if (!normalized || !create_webview("web/dialog/ColorPickerDialog/index.html", _L("Color Picker"),
787 wxSize(COLOR_PICKER_PAGE_WIDTH, COLOR_PICKER_PAGE_HEIGHT))) {
788 auto* sizer = new wxBoxSizer(wxVERTICAL);
789 sizer->Add(new wxStaticText(this, wxID_ANY, wxS("wxWebView unavailable")), wxSizerFlags().Border(wxALL, FromDIP(20)));
790 sizer->Add(new wxButton(this, wxID_CANCEL, _L("Cancel")), wxSizerFlags().Right().Border(wxALL, FromDIP(8)));
791 SetSizerAndFit(sizer);
792 Bind(wxEVT_BUTTON, [this](wxCommandEvent&) { finish(wxID_CANCEL); }, wxID_CANCEL);
793 Bind(wxEVT_SHOW, [this](wxShowEvent& event) {
794 if (event.IsShown() && !m_initial_positioned) {
796 wxGetApp().CallAfter([this, alive = m_alive] {
797 if (alive->load(std::memory_order_acquire) && !m_closing) {
800 }
801 });
802 }
803 event.Skip();
804 });
805 wxGetApp().UpdateDlgDarkUI(this);
807 return;
808 }
809 browser()->EnableBrowserAcceleratorKeys(false);
810 browser()->Bind(EVT_WEBVIEW_RECREATED, [this](wxCommandEvent& event) {
811 wxGetApp().UpdateDlgDarkUI(this);
812 event.Skip(); // The shared host updates the page theme.
813 });
814 Bind(wxEVT_ACTIVATE, [this](wxActivateEvent& event) {
815 if (event.GetActive() && IsShown() && !m_closing)
817 event.Skip();
818 });
819 if (wxGetApp().app_config) {
820 const auto stored = load_color_picker_favorites(*wxGetApp().app_config);
821 m_favorites = stored.favorites;
822 m_favorites_writable = stored.writable;
823 }
824 // The shared host attaches its sizer before constructing the full layout.
825 GetSizer()->SetSizeHints(this);
826 Move(m_work_area.GetPosition());
827 // SetSizeHints may fit the window to the WebView's small initial best size.
828 // Restore the intended dialog size only after applying the layout hints.
831 Bind(wxEVT_SHOW, [this](wxShowEvent& event) {
832 if (event.IsShown() && !m_initial_positioned) {
835 // GTK may ignore the requested position until the window is shown.
836 wxGetApp().CallAfter([this, alive = m_alive] {
837 if (alive->load(std::memory_order_acquire) && !m_closing) {
842 }
843 });
844 }
845 event.Skip();
846 });
847}
#define _L(s)
Definition OBJ.cpp:34
class WXDLLIMPEXP_FWD_CORE wxButton
Definition ProgressDialog.hpp:27
class WXDLLIMPEXP_FWD_CORE wxStaticText
Definition ProgressDialog.hpp:30
wxRect m_work_area
Definition ColorPickerDialog.hpp:85
bool m_preserve_multi_color
Definition ColorPickerDialog.hpp:76
ColorSelection m_initial
Definition ColorPickerDialog.hpp:71
int m_content_width
Definition ColorPickerDialog.hpp:87
std::vector< ColorSelection > m_favorites
Definition ColorPickerDialog.hpp:74
void focus_webview()
Definition ColorPickerDialog.cpp:893
void resize_to_content(int height)
Definition ColorPickerDialog.cpp:880
int m_content_height
Definition ColorPickerDialog.hpp:86
void move_to_anchor()
Definition ColorPickerDialog.cpp:868
bool m_closing
Definition ColorPickerDialog.hpp:79
ColorPickerOptions m_options
Definition ColorPickerDialog.hpp:72
void finish(int return_code)
Definition ColorPickerDialog.cpp:1078
bool m_favorites_writable
Definition ColorPickerDialog.hpp:80
bool m_sidebar_open
Definition ColorPickerDialog.hpp:81
std::shared_ptr< std::atomic< bool > > m_alive
Definition ColorPickerDialog.hpp:89
bool m_initial_positioned
Definition ColorPickerDialog.hpp:83
std::string m_palette
Definition ColorPickerDialog.hpp:82
wxRect m_anchor_rect
Definition ColorPickerDialog.hpp:84
wxWebView * browser() const
Definition WebViewHostDialog.hpp:75
WebViewHostDialog(wxWindow *parent, wxWindowID id=wxID_ANY, const wxString &title=wxT(""), const wxPoint &pos=wxDefaultPosition, const wxSize &size=wxDefaultSize, long style=wxSYSTEM_MENU|wxCAPTION|wxCLOSE_BOX|wxMAXIMIZE_BOX|wxRESIZE_BORDER)
Definition WebViewHostDialog.cpp:161
bool create_webview(const std::string &resource_path, const wxString &title, const wxSize &dialog_size=wxSize(820, 660), const wxSize &min_size=wxSize(640, 640))
Definition WebViewHostDialog.cpp:172
constexpr int COLOR_PICKER_PAGE_HEIGHT
Definition ColorPickerDialog.cpp:290
constexpr int COLOR_PICKER_PAGE_WIDTH
Definition ColorPickerDialog.cpp:289
bool valid_palette_id(const std::string &id)
Definition ColorPickerDialog.cpp:294
std::optional< ColorSelection > normalize_color_selection(const ColorSelection &selection, ColorPickerOptions options)
Definition ColorPickerDialog.cpp:99
constexpr int COLOR_PICKER_SIDEBAR_WIDTH
Definition ColorPickerDialog.cpp:291
ColorPickerFavoritesState load_color_picker_favorites(AppConfig &config)
Definition ColorPickerDialog.cpp:207
@ Right
Definition GLToolbar.hpp:462

References Slic3r::GUI::WebViewHostDialog::WebViewHostDialog(), _L, Slic3r::GUI::WebViewHostDialog::browser(), Slic3r::GUI::WebViewHostDialog::create_webview(), finish(), focus_webview(), Slic3r::AppConfig::get(), m_alive, m_anchor_rect, m_closing, m_content_height, m_content_width, m_favorites, m_favorites_writable, m_initial, m_initial_positioned, m_options, m_palette, m_preserve_multi_color, m_sidebar_open, m_work_area, move_to_anchor(), resize_to_content(), Slic3r::GUI::Right, wxButton, and wxStaticText.

Here is the call graph for this function:

◆ ~ColorPickerDialog()

Slic3r::GUI::ColorPickerDialog::~ColorPickerDialog ( )
override
849{ m_alive->store(false, std::memory_order_release); }

References m_alive.

Member Function Documentation

◆ add_user_scripts()

void Slic3r::GUI::ColorPickerDialog::add_user_scripts ( )
overrideprivatevirtual

Reimplemented from Slic3r::GUI::WebViewHostDialog.

938{
939 if (wxWebView* view = browser()) {
940 auto language = wxGetApp().current_language_code().ToStdString();
941 std::replace(language.begin(), language.end(), '_', '-');
942 const std::string script = "window.ORCA_UI_STRINGS = " +
943 color_picker_ui_strings().dump(-1, ' ', false, nlohmann::json::error_handler_t::ignore) +
944 ";window.ORCA_COLOR_PICKER_LANGUAGE = " + nlohmann::json(language).dump() +
945 // Lets the page lay out the sidebar before its first paint, matching the window size.
946 ";window.ORCA_COLOR_PICKER_UI = " + nlohmann::json({{"sidebar_open", m_sidebar_open}, {"palette", m_palette}}).dump() + ";";
947 view->AddUserScript(wxString::FromUTF8(script));
948 }
949}
nlohmann::json color_picker_ui_strings()
Definition ColorPickerDialog.cpp:301
size_t dump(const PresetBundle &bundle, const Sections &sections, std::ostream &out)
Definition profile_include_dump.cpp:96

References Slic3r::GUI::WebViewHostDialog::browser(), m_palette, and m_sidebar_open.

Here is the call graph for this function:

◆ append_language_to_url()

virtual bool Slic3r::GUI::WebViewHostDialog::append_language_to_url ( ) const
inlineprotectedvirtualinherited

Reimplemented in Slic3r::GUI::WebDialog.

84{ return true; }

Referenced by build_resource_url().

Here is the caller graph for this function:

◆ apply_theme_live()

void Slic3r::GUI::WebViewHostDialog::apply_theme_live ( )
protectedinherited
300{
301 if (!m_browser)
302 return;
303 // Update the already-loaded document in place (no reload, no flash) by rewriting the
304 // injected :root variables + data-orca-theme; the whole cascade re-flows from these.
305 // The document-start script keeps the creation-time theme for any later reload, and
306 // these dialogs are not reloaded on a theme toggle (see WebView::RecreateAll).
307 run_script(wxString::FromUTF8(host_theme_apply_js()));
308}
bool run_script(const wxString &script)
Definition WebViewHostDialog.cpp:234
wxWebView * m_browser
Definition WebViewHostDialog.hpp:109
std::string host_theme_apply_js()
Definition WebViewHostDialog.cpp:73

References m_browser, and run_script().

Referenced by on_webview_recreated().

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

◆ browser()

◆ build_resource_url()

wxString Slic3r::GUI::WebViewHostDialog::build_resource_url ( const std::string & resource_path) const
protectedinherited
210{
211 wxString target_url = file_url_from_path(boost::filesystem::path(resources_dir()) / resource_path);
212
214 const wxString lang = wxGetApp().current_language_code_safe();
215 if (!lang.empty()) {
216 target_url += wxT("?lang=");
217 target_url += lang;
218 }
219 }
220
221 return target_url;
222}
virtual bool append_language_to_url() const
Definition WebViewHostDialog.hpp:84
wxString file_url_from_path(const boost::filesystem::path &path)
Definition GUI.cpp:569
const std::string & resources_dir()
Definition utils.cpp:296

References append_language_to_url(), Slic3r::GUI::file_url_from_path(), and Slic3r::resources_dir().

Referenced by create_webview().

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

◆ call_web_handler()

void Slic3r::GUI::WebViewHostDialog::call_web_handler ( const nlohmann::json & payload,
const wxString & handler = wxT("HandleStudio") )
inherited
243{
244 const wxString payload_text = wxString::FromUTF8(payload.dump(-1, ' ', false, nlohmann::json::error_handler_t::ignore));
245 const wxString script = handler + wxT("(") + payload_text + wxT(")");
246
247 wxGetApp().CallAfter([this, script] { run_script(script); });
248}

References run_script().

Referenced by Slic3r::GUI::SpeedDialWebDialog::handle_web_command(), Slic3r::GUI::PresetBundleDialog::ListBundles(), Slic3r::GUI::ExportPresetBundleDialog::OnRequestPresets(), Slic3r::GUI::WebDialog::push_message(), Slic3r::GUI::TerminalDialog::resolve_and_run(), Slic3r::GUI::PluginsDialog::restore_capability_config(), Slic3r::GUI::PluginsDialog::save_capability_config(), Slic3r::GUI::SpeedDialWebDialog::search_tabs(), Slic3r::GUI::SpeedDialWebDialog::send_actions(), Slic3r::GUI::PluginsConfigDialog::send_capabilities(), Slic3r::GUI::PluginsConfigDialog::send_capability_config(), Slic3r::GUI::PluginsDialog::send_capability_config(), Slic3r::GUI::PluginsDialog::send_plugins(), Slic3r::GUI::PluginsConfigDialog::send_save_error(), Slic3r::GUI::PluginsConfigDialog::show_status(), and Slic3r::GUI::PluginsDialog::show_status().

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

◆ create_webview()

bool Slic3r::GUI::WebViewHostDialog::create_webview ( const std::string & resource_path,
const wxString & title,
const wxSize & dialog_size = wxSize(820, 660),
const wxSize & min_size = wxSize(640, 640) )
inherited
176{
177 SetTitle(title);
178 SetMinSize(FromDIP(min_size));
179
180 const wxString target_url = build_resource_url(resource_path);
181 wxBoxSizer* topsizer = new wxBoxSizer(wxVERTICAL);
182
183 // Created empty and loaded below, after the user scripts are added, so the first load already has them.
184 m_browser = WebView::CreateWebView(this, wxEmptyString);
185 if (m_browser == nullptr) {
186 wxLogError("Could not init m_browser");
187 delete topsizer;
188 return false;
189 }
190
191 SetSizer(topsizer);
192 topsizer->Add(m_browser, wxSizerFlags().Expand().Proportion(1));
193
194 SetSize(FromDIP(dialog_size));
195 CenterOnParent();
196
197 Bind(wxEVT_WEBVIEW_SCRIPT_MESSAGE_RECEIVED, &WebViewHostDialog::on_script_message_event, this, m_browser->GetId());
198
199 // Inject the shared host theme contract BEFORE the first load so the page paints in
200 // the app theme with no flash, and re-theme live when the app theme toggles.
202 m_browser->Bind(EVT_WEBVIEW_RECREATED, &WebViewHostDialog::on_webview_recreated, this);
203
204 load_url(target_url);
205 wxGetApp().UpdateDlgDarkUI(this);
206 return true;
207}
void on_webview_recreated(wxCommandEvent &event)
Definition WebViewHostDialog.cpp:310
wxString build_resource_url(const std::string &resource_path) const
Definition WebViewHostDialog.cpp:209
void register_theme_user_scripts()
Definition WebViewHostDialog.cpp:285
void on_script_message_event(wxWebViewEvent &event)
Definition WebViewHostDialog.cpp:274
void load_url(const wxString &url)
Definition WebViewHostDialog.cpp:224
static wxWebView * CreateWebView(wxWindow *parent, wxString const &url)
Definition WebView.cpp:313

References build_resource_url(), WebView::CreateWebView(), load_url(), m_browser, on_script_message_event(), on_webview_recreated(), and register_theme_user_scripts().

Referenced by Slic3r::GUI::ColorPickerDialog::ColorPickerDialog(), Slic3r::GUI::PluginsConfigDialog::PluginsConfigDialog(), Slic3r::GUI::PluginsDialog::PluginsDialog(), Slic3r::GUI::SpeedDialWebDialog::SpeedDialWebDialog(), Slic3r::GUI::TerminalDialog::TerminalDialog(), Slic3r::GUI::WebDialog::WebDialog(), Slic3r::GUI::PresetBundleDialog::create(), and Slic3r::GUI::ExportPresetBundleDialog::Init().

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

◆ document_start_injector()

std::string Slic3r::GUI::WebViewHostDialog::document_start_injector ( const std::string & markup,
const char * dom_id,
const char * position,
const std::string & prelude = {},
const std::string & on_inject = {} )
staticinherited
135{
136 const std::string literal = nlohmann::json(markup).dump();
137 std::string s;
138 s += "(function(){";
139 // wxWebView's AddUserScript runs in child frames too (including cross-origin
140 // frames on WebView2). Host theme state belongs only to the top-level page.
141 s += "if(window.top!==window.self)return;";
142 s += prelude;
143 s += "var css=" + literal + ";";
144 s += "function inject(){";
145 s += "var root=document.head||document.documentElement;if(!root)return false;";
146 s += "if(!document.getElementById('" + std::string(dom_id) + "'))root.insertAdjacentHTML('" +
147 std::string(position) + "',css);";
148 s += on_inject;
149 s += "return true;}";
150 s += "if(inject())return;";
151 s += "var obs=new MutationObserver(function(){if(inject())obs.disconnect();});";
152 s += "obs.observe(document,{childList:true});})();";
153 return s;
154}

Referenced by element_defaults_user_script(), and theme_user_script().

Here is the caller graph for this function:

◆ element_defaults_user_script()

std::string Slic3r::GUI::WebViewHostDialog::element_defaults_user_script ( )
staticinherited
103{
104 std::string css;
105 css += "<style id=\"orca-plugin-defaults\">";
106 css += "html,body{background:var(--orca-bg);color:var(--orca-fg);"
107 "font-family:var(--orca-font);font-size:13px;}";
108 css += "body{margin:0;}";
109 css += "h1,h2,h3,h4,h5,h6{color:var(--orca-fg);font-weight:600;}";
110 css += "a{color:var(--orca-accent);}";
111 css += "hr{border:0;border-top:1px solid var(--orca-border);}";
112 css += "button{font:inherit;color:var(--orca-accent-fg);background:var(--orca-accent);"
113 "border:1px solid var(--orca-accent);border-radius:4px;padding:5px 14px;cursor:pointer;}";
114 css += "button:hover{filter:brightness(1.1);}";
115 css += "button:disabled{opacity:.5;cursor:default;}";
116 css += "input,select,textarea{font:inherit;color:var(--orca-fg);"
117 "background:var(--orca-bg);border:1px solid var(--orca-border);"
118 "border-radius:4px;padding:4px 8px;}";
119 css += "input:focus,select:focus,textarea:focus{outline:none;border-color:var(--orca-accent);}";
120 css += "table{border-collapse:collapse;}";
121 css += "th,td{text-align:left;padding:6px 10px;border-bottom:1px solid var(--orca-border);}";
122 css += "th{color:var(--orca-muted);font-weight:600;}";
123 css += "::-webkit-scrollbar{width:12px;height:12px;}";
124 css += "::-webkit-scrollbar-thumb{background:var(--orca-border);border-radius:6px;}";
125 css += "::-webkit-scrollbar-track{background:transparent;}";
126 css += "</style>";
127 return document_start_injector(css, "orca-plugin-defaults", "beforeend");
128}
static std::string document_start_injector(const std::string &markup, const char *dom_id, const char *position, const std::string &prelude={}, const std::string &on_inject={})
Definition WebViewHostDialog.cpp:130

References document_start_injector().

Referenced by Slic3r::GUI::WebPanel::WebPanel(), and Slic3r::GUI::WebDialog::add_user_scripts().

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

◆ em_unit()

int Slic3r::GUI::DPIAware< wxDialog >::em_unit ( ) const
inlineinherited
203{ return m_em_unit; }
Definition GUI_Utils.hpp:107

Referenced by Slic3r::GUI::AuxiliaryDialog::AuxiliaryDialog(), Slic3r::GUI::CopyrightsDialog::CopyrightsDialog(), Slic3r::GUI::DesignTextDialog::DesignTextDialog(), Slic3r::GUI::EditGCodeDialog::EditGCodeDialog(), Slic3r::GUI::FileArchiveDialog::FileArchiveDialog(), Slic3r::GUI::MsgNoUpdates::MsgNoUpdates(), Slic3r::GUI::MsgUpdateForced::MsgUpdateForced(), Slic3r::GUI::OAuthDialog::OAuthDialog(), Slic3r::GUI::ParamsDialog::ParamsDialog(), Slic3r::GUI::PhysicalPrinterDialog::PhysicalPrinterDialog(), Slic3r::GUI::SettingsDialog::SettingsDialog(), anonymous_namespace{3DPrinterOS.cpp}::TokenAuthDialog::TokenAuthDialog(), anonymous_namespace{3DPrinterOS.cpp}::UploadOptionsDialog::UploadOptionsDialog(), Slic3r::GUI::PublishSettingsDialog::add_row_ui(), Slic3r::GUI::DiffPresetDialog::complete_dialog_creation(), Slic3r::GUI::DiffPresetDialog::create_edit_sizer(), Slic3r::GUI::DiffPresetDialog::create_presets_sizer(), Slic3r::GUI::DiffPresetDialog::create_tree(), Slic3r::GUI::ElegooPrintHostSendDialog::init(), Slic3r::GUI::FlashforgePrintHostSendDialog::init(), Slic3r::GUI::PrintHostSendDialog::init(), Slic3r::GUI::AboutDialog::on_dpi_changed(), Slic3r::GUI::AuxiliaryDialog::on_dpi_changed(), Slic3r::GUI::BedShapeDialog::on_dpi_changed(), Slic3r::GUI::ConfigWizard::on_dpi_changed(), Slic3r::GUI::CopyrightsDialog::on_dpi_changed(), Slic3r::GUI::DiffPresetDialog::on_dpi_changed(), Slic3r::GUI::EditGCodeDialog::on_dpi_changed(), Slic3r::GUI::FileArchiveDialog::on_dpi_changed(), Slic3r::GUI::OAuthDialog::on_dpi_changed(), Slic3r::GUI::ObjectTableDialog::on_dpi_changed(), Slic3r::GUI::ParamsDialog::on_dpi_changed(), Slic3r::GUI::PhysicalPrinterDialog::on_dpi_changed(), Slic3r::GUI::PrintHostQueueDialog::on_dpi_changed(), Slic3r::GUI::PurgeModeDialog::on_dpi_changed(), Slic3r::GUI::SavePresetDialog::on_dpi_changed(), Slic3r::GUI::SendSystemInfoDialog::on_dpi_changed(), Slic3r::GUI::SettingsDialog::on_dpi_changed(), and Slic3r::GUI::UnsavedChangesDialog::on_dpi_changed().

Here is the caller graph for this function:

◆ enable_force_rescale()

void Slic3r::GUI::DPIAware< wxDialog >::enable_force_rescale ( )
inlineinherited
206{ m_force_rescale = true; }

◆ EndModal()

void Slic3r::GUI::DPIDialog::EndModal ( int retCode)
inlineoverrideinherited
306 {
307 if (!dialogStack.empty() && dialogStack.front() != this) {
308 // This is a bug in wxWidgets
309 // when the dialog is not top modal dialog, EndModal() just hide dialog without quit
310 // the modal event loop. And the modal event loop blocks us from bottom widgets.
311 // Solution: let user click it manually or close outside. FIXME
312 BOOST_LOG_TRIVIAL(warning) << "DPIAware::EndModal Error: dialogStack is not empty, but top dialog is not this one. retCode=" << retCode;
313 return;
314 }
315
316 return wxDialog::EndModal(retCode);
317 }
std::deque< wxDialog * > dialogStack
Definition GUI_Utils.cpp:549

References Slic3r::GUI::dialogStack.

Referenced by Slic3r::GUI::CloneDialog::CloneDialog(), Slic3r::GUI::ConfigWizard::ConfigWizard(), Slic3r::GUI::CreatePresetSuccessfulDialog::CreatePresetSuccessfulDialog(), Slic3r::GUI::DeleteConfirmDialog::DeleteConfirmDialog(), Slic3r::GUI::DesignVariableDialog::DesignVariableDialog(), Slic3r::GUI::anonymous_namespace{PrintHostDialogs.cpp}::FlashforgeSlotDialog::FlashforgeSlotDialog(), Slic3r::GUI::GuideFrame::GuideFrame(), Slic3r::GUI::InputIpAddressDialog::InputIpAddressDialog(), Slic3r::GUI::ManualNozzleCountDialog::ManualNozzleCountDialog(), Slic3r::GUI::MsgUpdateConfig::MsgUpdateConfig(), Slic3r::GUI::MsgUpdateForced::MsgUpdateForced(), Slic3r::GUI::MultiChoiceDialog::MultiChoiceDialog(), Slic3r::GUI::NetworkErrorDialog::NetworkErrorDialog(), Slic3r::GUI::NetworkPluginRestartDialog::NetworkPluginRestartDialog(), Slic3r::GUI::PartSkipConfirmDialog::PartSkipConfirmDialog(), Slic3r::GUI::PhysicalPrinterDialog::PhysicalPrinterDialog(), Slic3r::GUI::PlateNameEditDialog::PlateNameEditDialog(), Slic3r::GUI::PlateSettingsDialog::PlateSettingsDialog(), Slic3r::GUI::PublishSettingsDialog::PublishSettingsDialog(), Slic3r::GUI::SelectMachineDialog::SelectMachineDialog(), Slic3r::GUI::SendFailedConfirm::SendFailedConfirm(), Slic3r::GUI::SendSystemInfoDialog::SendSystemInfoDialog(), Slic3r::GUI::ShortcutCaptureDialog::ShortcutCaptureDialog(), Slic3r::GUI::SingleChoiceDialog::SingleChoiceDialog(), StepMeshDialog::StepMeshDialog(), Slic3r::GUI::SyncAmsInfoDialog::SyncAmsInfoDialog(), anonymous_namespace{3DPrinterOS.cpp}::TokenAuthDialog::TokenAuthDialog(), Slic3r::GUI::UpdatePluginDialog::UpdatePluginDialog(), Slic3r::GUI::UpdateVersionDialog::UpdateVersionDialog(), Slic3r::GUI::wgtDeviceNozzleRackUpgradeDlg::wgtDeviceNozzleRackUpgradeDlg(), Slic3r::GUI::SavePresetDialog::accept(), Slic3r::GUI::MsgDialog::add_button(), Slic3r::GUI::TipsDialog::add_button(), Slic3r::GUI::FilamentPickerDialog::BindEvents(), Slic3r::GUI::PluginPickerDialog::build_capability_ui(), Slic3r::GUI::BedShapeDialog::build_dialog(), Slic3r::GUI::PluginPickerDialog::build_ui(), Slic3r::GUI::UnsavedChangesDialog::close(), Slic3r::GUI::FileArchiveDialog::create_btn_sizer(), Slic3r::GUI::ColorDecomposeDialog::create_button_panel(), Slic3r::GUI::MixedFilamentDialog::create_button_panel(), Slic3r::GUI::CreateFilamentPresetDialog::create_dialog_buttons(), Slic3r::GUI::CreatePresetForPrinterDialog::create_dialog_buttons(), Slic3r::GUI::EditFilamentPresetDialog::create_dialog_buttons(), Slic3r::GUI::ExportConfigsDialog::create_dialog_buttons(), Slic3r::GUI::PreferencesDialog::create_item_language_combobox(), Slic3r::GUI::PreferencesDialog::create_item_region_combobox(), Slic3r::GUI::PreferencesDialog::create_items(), Slic3r::GUI::CreatePrinterPresetDialog::create_page1_dialog_buttons(), Slic3r::GUI::CreatePrinterPresetDialog::create_page2_dialog_buttons(), Slic3r::GUI::ExportConfigsDialog::data_init(), Slic3r::GUI::WebDialog::destroy_silently(), Slic3r::GUI::EditFilamentPresetDialog::edit_preset(), Slic3r::GUI::ConnectPrinterDialog::end_modal(), Slic3r::GUI::PrintHostSendDialog::EndModal(), Slic3r::GUI::ColorPickerDialog::finish(), Slic3r::GUI::WebDialog::finish(), Slic3r::GUI::Newer3mfVersionDialog::get_btn_sizer(), Slic3r::GUI::ScoreDialog::get_button_sizer(), Slic3r::GUI::WebViewHostDialog::handle_common_script_command(), Slic3r::GUI::ExportPresetBundleDialog::InitExportData(), Slic3r::GUI::SelectMachineDialog::navigate_to_timelapse_page(), Slic3r::GUI::BindMachineDialog::on_bind_success(), Slic3r::GUI::ConnectPrinterDialog::on_button_confirm(), Slic3r::GUI::RecenterDialog::on_button_confirm(), Slic3r::GUI::BindMachineDialog::on_cancel(), Slic3r::GUI::EditCalibrationHistoryDialog::on_cancel(), Slic3r::GUI::InputIpAddressDialog::on_cancel(), Slic3r::GUI::NewCalibrationHistoryDialog::on_cancel(), Slic3r::GUI::OAuthDialog::on_cancel(), Slic3r::GUI::PingCodeBindDialog::on_cancel(), Slic3r::GUI::SelectMachineDialog::on_cancel(), Slic3r::GUI::SendToPrinterDialog::on_cancel(), Slic3r::GUI::SyncAmsInfoDialog::on_cancel(), Slic3r::GUI::UnBindMachineDialog::on_cancel(), Slic3r::GUI::WebDialog::on_close_window(), Slic3r::GUI::NetworkPluginDownloadDialog::on_dont_ask(), Slic3r::GUI::NetworkPluginDownloadDialog::on_download(), Slic3r::GUI::EditDevNameDialog::on_edit_name(), Slic3r::GUI::ConfirmBeforeSendDialog::on_hide(), Slic3r::GUI::PrivacyUpdateDialog::on_hide(), Slic3r::GUI::ShortcutCaptureDialog::on_key(), Slic3r::GUI::TextureImportDialog::on_ok_clicked(), Slic3r::GUI::FileArchiveDialog::on_open_button(), Slic3r::GUI::NetworkPluginDownloadDialog::on_remind_later(), Slic3r::GUI::ProjectDropDialog::on_select_cancel(), Slic3r::GUI::SavePresetDialog::on_select_cancel(), Slic3r::GUI::ProjectDropDialog::on_select_ok(), Slic3r::GUI::SendMultiMachinePage::on_send(), Slic3r::GUI::NetworkPluginDownloadDialog::on_skip(), Slic3r::GUI::TextureImportDialog::on_skip_clicked(), Slic3r::GUI::NetworkPluginDownloadDialog::on_skip_version(), Slic3r::GUI::Cornering_Test_Dlg::on_start(), Slic3r::GUI::FlowRateCalibrationDialog::on_start(), Slic3r::GUI::Input_Shaping_Damp_Test_Dlg::on_start(), Slic3r::GUI::Input_Shaping_Freq_Test_Dlg::on_start(), Slic3r::GUI::MaxVolumetricSpeed_Test_Dlg::on_start(), Slic3r::GUI::PA_Calibration_Dlg::on_start(), Slic3r::GUI::Retraction_Test_Dlg::on_start(), Slic3r::GUI::Temp_Calibration_Dlg::on_start(), Slic3r::GUI::VFA_Test_Dlg::on_start(), Slic3r::GUI::CalibrationDialog::on_start_calibration(), Slic3r::GUI::UnBindMachineDialog::on_unbind_printer(), Slic3r::GUI::PartSkipDialog::OnApplyDialog(), anonymous_namespace{3DPrinterOS.cpp}::TokenAuthDialog::OnCancel(), Slic3r::GUI::AboutDialog::onCloseDialog(), Slic3r::GUI::CopyrightsDialog::onCloseDialog(), Slic3r::GUI::MultiNozzleSyncDialog::OnRackStatusReadingFinished(), Slic3r::GUI::GuideFrame::OnScriptMessage(), Slic3r::GUI::InputIpAddressDialog::OnTimer(), Slic3r::GUI::KBShortcutsDialog::open_mouse_preferences(), Slic3r::GUI::TroubleshootDialog::PackAll(), Slic3r::GUI::TroubleshootDialog::RebuildSystemProfiles(), Slic3r::GUI::SpeedDialWebDialog::run_action(), Slic3r::GUI::OAuthDialog::Show(), Slic3r::GUI::MultiNozzleSyncDialog::UpdateButton(), and Slic3r::GUI::CreatePrinterPresetDialog::validate_input_valid().

◆ finish()

void Slic3r::GUI::ColorPickerDialog::finish ( int return_code)
private
1079{
1080 if (m_closing)
1081 return;
1082 m_closing = true;
1083 if (return_code != wxID_OK)
1084 m_selection.reset();
1085 if (IsModal())
1086 EndModal(return_code);
1087 else
1088 Hide();
1089}
std::optional< ColorSelection > m_selection
Definition ColorPickerDialog.hpp:73
void EndModal(int retCode) override
Definition GUI_Utils.hpp:305

References Slic3r::GUI::DPIDialog::EndModal(), m_closing, and m_selection.

Referenced by ColorPickerDialog(), and handle_web_command().

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

◆ focus_webview()

void Slic3r::GUI::ColorPickerDialog::focus_webview ( )
private
894{
895 wxWebView* view = browser();
896 if (!view)
897 return;
898#ifdef __linux__
899 if (void* backend = view->GetNativeBackend())
900 gtk_widget_grab_focus(static_cast<GtkWidget*>(backend));
901#else
902 view->SetFocus();
903#endif
904 if (m_page_ready)
905 run_script("window.ColorPickerDialog.focusInput();");
906}
bool m_page_ready
Definition ColorPickerDialog.hpp:78

References Slic3r::GUI::WebViewHostDialog::browser(), m_page_ready, and Slic3r::GUI::WebViewHostDialog::run_script().

Referenced by ColorPickerDialog(), and handle_web_command().

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

◆ force_rescale()

bool Slic3r::GUI::DPIAware< wxDialog >::force_rescale ( ) const
inlineinherited
201{ return m_force_rescale; }

◆ handle_common_script_command()

bool Slic3r::GUI::WebViewHostDialog::handle_common_script_command ( const nlohmann::json & payload,
int close_return_code = wxID_CANCEL )
protectedinherited
251{
252 const std::string command = payload.value("command", "");
253 if (command == "close_page") {
254 if (IsModal())
255 EndModal(close_return_code);
256 else
257 Close();
258 return true;
259 }
260
261 return false;
262}

References Slic3r::GUI::DPIDialog::EndModal().

Referenced by Slic3r::GUI::ExportPresetBundleDialog::on_script_message(), Slic3r::GUI::PluginsConfigDialog::on_script_message(), Slic3r::GUI::PluginsDialog::on_script_message(), Slic3r::GUI::PresetBundleDialog::on_script_message(), Slic3r::GUI::SpeedDialWebDialog::on_script_message(), Slic3r::GUI::TerminalDialog::on_script_message(), and Slic3r::GUI::WebDialog::on_script_message().

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

◆ handle_web_command()

void Slic3r::GUI::ColorPickerDialog::handle_web_command ( const nlohmann::json & payload)
private
962{
963 if (!browser() || !payload.is_object())
964 return;
965 const auto command = payload.find("command");
966 const auto page_id = payload.find("page_id");
967 if (command == payload.end() || !command->is_string() || page_id == payload.end() || !page_id->is_string())
968 return;
969 const auto& id = page_id->get_ref<const std::string&>();
970 if (id.empty() || id.size() > 64)
971 return;
972 if (*command == "ready") {
973 // A repeated ready from the same document must not reset its edits. A new
974 // document (e.g. WebView recreation) gets a fresh initialization handshake.
975 if (id != m_page_id) {
976 m_page_id = id;
977 m_page_ready = false;
978 m_init_sent = false;
979 }
980 if (!m_init_sent)
982 return;
983 }
984 if (id != m_page_id)
985 return;
986 if (*command == "cancel") {
987 finish(wxID_CANCEL);
988 return;
989 }
990 if (*command == "initialized") {
991 if (m_init_sent && !m_page_ready) {
992 m_page_ready = true;
995 }
996 return;
997 }
998 if (!m_page_ready)
999 return;
1000 if (*command == "resize") {
1001 const auto height = payload.find("height");
1002 if (height == payload.end() || !height->is_number())
1003 return;
1004 const double value = height->get<double>();
1005 if (!std::isfinite(value) || value < 300 || value > 900)
1006 return;
1007 // Width is optional so an older page that reports only height keeps the current width.
1008 const auto width = payload.find("width");
1009 if (width != payload.end()) {
1010 if (!width->is_number())
1011 return;
1012 const double width_value = width->get<double>();
1013 if (!std::isfinite(width_value) || width_value < 300 || width_value > 1200)
1014 return;
1015 m_content_width = static_cast<int>(std::ceil(width_value));
1016 }
1017 resize_to_content(static_cast<int>(std::ceil(value)));
1018 return;
1019 }
1020 if (*command == "confirm") {
1021 const auto value = payload.find("selection");
1022 if (value == payload.end())
1023 return;
1024 const auto selection = color_selection_from_json(*value, m_options);
1025 if (!selection)
1026 return;
1028 finish(wxID_OK);
1029 } else if (*command == "update_favorites") {
1030 const auto values = payload.find("favorites");
1031 if (values == payload.end() || !m_favorites_writable || !wxGetApp().app_config)
1032 return;
1033 const auto favorites = color_favorites_from_json(*values);
1034 if (favorites && save_color_picker_favorites(*wxGetApp().app_config, *values)) {
1035 m_favorites = *favorites;
1036 nlohmann::json canonical = nlohmann::json::array();
1037 for (const ColorSelection& selection : m_favorites)
1038 canonical.push_back(color_selection_to_json(selection));
1039 const nlohmann::json response = {{"command", "favorites"}, {"page_id", m_page_id}, {"favorites", std::move(canonical)}};
1040 run_script(wxString::FromUTF8("window.ColorPickerDialog.handleMessage(" + response.dump() + ")"));
1041 }
1042 } else if (*command == "update_ui") {
1043 // Sidebar open/closed and the chosen palette, restored the next time the picker opens.
1044 const auto open = payload.find("sidebar_open");
1045 const auto palette = payload.find("palette");
1046 if (open == payload.end() || !open->is_boolean() || palette == payload.end() || !palette->is_string() || !wxGetApp().app_config)
1047 return;
1048 const auto& id = palette->get_ref<const std::string&>();
1049 if (!valid_palette_id(id))
1050 return;
1051 m_sidebar_open = open->get<bool>();
1052 m_palette = id;
1053 // set() marks the config dirty; it is written with the rest of the app config.
1054 AppConfig& config = *wxGetApp().app_config;
1055 config.set(COLOR_PICKER_UI_SECTION, "sidebar_open", m_sidebar_open ? "1" : "0");
1056 config.set(COLOR_PICKER_UI_SECTION, "palette", m_palette);
1057 }
1058}
std::string m_page_id
Definition ColorPickerDialog.hpp:75
void repaint_webview()
Definition ColorPickerDialog.cpp:908
bool m_init_sent
Definition ColorPickerDialog.hpp:77
const std::optional< ColorSelection > & selection() const
Definition ColorPickerDialog.hpp:55
void send_initial_state()
Definition ColorPickerDialog.cpp:1060
nlohmann::json color_selection_to_json(const ColorSelection &selection)
Definition ColorPickerDialog.cpp:138
std::optional< std::vector< ColorSelection > > color_favorites_from_json(const nlohmann::json &values)
Definition ColorPickerDialog.cpp:151
std::optional< ColorSelection > color_selection_from_json(const nlohmann::json &value, ColorPickerOptions options)
Definition ColorPickerDialog.cpp:116
bool save_color_picker_favorites(AppConfig &config, const nlohmann::json &values)
Definition ColorPickerDialog.cpp:190
std::variant< ColorRGBA, ColorGradient > ColorSelection
Definition ColorPickerDialog.hpp:28
coord_t width(const BoundingBox &box)
Definition Arrange.cpp:1184
coord_t height(const BoundingBox &box)
Definition Arrange.cpp:1185
bool empty(const BoundingBoxBase< PointType, PointsType > &bb)
Definition BoundingBox.hpp:273

References Slic3r::GUI::WebViewHostDialog::browser(), Slic3r::empty(), finish(), focus_webview(), m_content_width, m_favorites, m_favorites_writable, m_init_sent, m_options, m_page_id, m_page_ready, m_palette, m_selection, m_sidebar_open, repaint_webview(), resize_to_content(), Slic3r::GUI::WebViewHostDialog::run_script(), selection(), send_initial_state(), and Slic3r::AppConfig::set().

Referenced by on_script_message().

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

◆ is_new_scale_factor()

bool Slic3r::GUI::DPIAware< wxDialog >::is_new_scale_factor ( ) const
inlineprivateinherited
262{ return fabs(m_scale_factor - m_prev_scale_factor) > 0.001; }

◆ load_url()

void Slic3r::GUI::WebViewHostDialog::load_url ( const wxString & url)
inherited
225{
226 if (!m_browser)
227 return;
228
229 BOOST_LOG_TRIVIAL(trace) << __FUNCTION__ << " enter, url=" << into_u8(url);
231 m_browser->SetFocus();
232}
static void LoadUrl(wxWebView *webView, wxString const &url)
Definition WebView.cpp:480
std::string into_u8(const wxString &str)
Definition GUI.cpp:549
void trace(unsigned int level, const char *message)
Definition utils.cpp:247

References Slic3r::GUI::into_u8(), WebView::LoadUrl(), m_browser, and Slic3r::trace().

Referenced by create_webview().

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

◆ localized_strings()

virtual nlohmann::json Slic3r::GUI::WebViewHostDialog::localized_strings ( ) const
inlineprotectedvirtualinherited

Reimplemented in Slic3r::GUI::ExportPresetBundleDialog, Slic3r::GUI::PluginsConfigDialog, Slic3r::GUI::PluginsDialog, Slic3r::GUI::PresetBundleDialog, Slic3r::GUI::SpeedDialWebDialog, and Slic3r::GUI::TerminalDialog.

99{ return nullptr; }

Referenced by register_theme_user_scripts().

Here is the caller graph for this function:

◆ localized_strings_script()

std::string Slic3r::GUI::WebViewHostDialog::localized_strings_script ( const nlohmann::json & strings)
staticinherited
157{
158 return "window.ORCA_UI_STRINGS = " + strings.dump(-1, ' ', false, nlohmann::json::error_handler_t::ignore) + ";";
159}

Referenced by Slic3r::GUI::GuideFrame::GuideFrame(), WipingDialog::WipingDialog(), Slic3r::GUI::add_page_strings(), Slic3r::GUI::ProjectPanel::create_browser(), Slic3r::GUI::WebViewPanel::create_browser(), and register_theme_user_scripts().

Here is the caller graph for this function:

◆ move_to_anchor()

void Slic3r::GUI::ColorPickerDialog::move_to_anchor ( )
private
869{
870 const wxPoint position = color_picker_panel_position(m_anchor_rect, m_work_area, GetSize(), FromDIP(4));
871 if (position != GetPosition())
872 Move(position);
873#ifdef __WXGTK__
874 // wxGTK caches requested coordinates: Move can skip a post-show request even
875 // when the window manager ignored the initial one. Reapply at native level.
876 gtk_window_move(GTK_WINDOW(GetHandle()), position.x, position.y);
877#endif
878}
wxPoint color_picker_panel_position(const wxRect &anchor, const wxRect &work_area, const wxSize &size, int gap)
Definition ColorPickerDialog.cpp:734

References m_anchor_rect, and m_work_area.

Referenced by ColorPickerDialog().

Here is the caller graph for this function:

◆ normal_font()

◆ on_dpi_changed()

void Slic3r::GUI::ColorPickerDialog::on_dpi_changed ( const wxRect & suggested_rect)
overrideprivatevirtual

Implements Slic3r::GUI::DPIAware< wxDialog >.

927{
929 Refresh();
930}

References m_content_height, and resize_to_content().

Here is the call graph for this function:

◆ on_script_message()

void Slic3r::GUI::ColorPickerDialog::on_script_message ( const nlohmann::json & payload)
overrideprivatevirtual

Implements Slic3r::GUI::WebViewHostDialog.

952{
953 // GTK/WebKit may call on the native script-message stack. All dialog work,
954 // including EndModal, runs after that callback and checks the lifetime token.
955 wxGetApp().CallAfter([this, alive = m_alive, payload] {
956 if (alive->load(std::memory_order_acquire) && !m_closing)
957 handle_web_command(payload);
958 });
959}
void handle_web_command(const nlohmann::json &payload)
Definition ColorPickerDialog.cpp:961

References handle_web_command(), m_alive, and m_closing.

Here is the call graph for this function:

◆ on_script_message_event()

void Slic3r::GUI::WebViewHostDialog::on_script_message_event ( wxWebViewEvent & event)
privateinherited
275{
276 const wxString payload = event.GetString();
277
278 try {
279 on_script_message(nlohmann::json::parse(payload.utf8_string()));
280 } catch (const std::exception& e) {
282 }
283}
virtual void on_script_message_parse_error(const wxString &payload, const std::exception &error)
Definition WebViewHostDialog.cpp:269
virtual void on_script_message(const nlohmann::json &payload)=0

References on_script_message(), and on_script_message_parse_error().

Referenced by create_webview().

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

◆ on_script_message_parse_error()

void Slic3r::GUI::WebViewHostDialog::on_script_message_parse_error ( const wxString & payload,
const std::exception & error )
protectedvirtualinherited
270{
271 BOOST_LOG_TRIVIAL(trace) << __FUNCTION__ << "; payload=" << into_u8(payload) << "; error=" << error.what();
272}

References Slic3r::GUI::into_u8(), and Slic3r::trace().

Referenced by on_script_message_event().

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

◆ on_sys_color_changed()

void Slic3r::GUI::ColorPickerDialog::on_sys_color_changed ( )
overrideprivatevirtual

Reimplemented from Slic3r::GUI::DPIAware< wxDialog >.

933{
934 wxGetApp().UpdateDlgDarkUI(this);
935}

◆ on_webview_recreated()

void Slic3r::GUI::WebViewHostDialog::on_webview_recreated ( wxCommandEvent & event)
privateinherited
311{
312 // Handled: do NOT Skip(), so WebView::RecreateAll skips the redundant reload.
314}
void apply_theme_live()
Definition WebViewHostDialog.cpp:299

References apply_theme_live().

Referenced by create_webview().

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

◆ position_panel()

void Slic3r::GUI::ColorPickerDialog::position_panel ( )
private
852{
853 if (m_positioning)
854 return;
855 m_positioning = true;
856 // Both dimensions come from the page: width changes when the palette sidebar opens or closes.
857 wxSize size = FromDIP(wxSize(m_content_width, m_content_height));
858 // The work-area limit includes the native title bar and fixed frame.
859 const wxSize frame = GetSize() - GetClientSize();
860 size.x = std::min(size.x, std::max(1, m_work_area.width - frame.x));
861 size.y = std::min(size.y, std::max(1, m_work_area.height - frame.y - FromDIP(16)));
862 SetMinSize(wxSize(std::min(FromDIP(320), size.x), std::min(FromDIP(360), size.y)));
863 if (size != GetClientSize())
864 SetClientSize(size);
865 m_positioning = false;
866}
bool m_positioning
Definition ColorPickerDialog.hpp:88

References m_content_height, m_content_width, m_positioning, and m_work_area.

Referenced by resize_to_content().

Here is the caller graph for this function:

◆ prev_scale_factor()

float Slic3r::GUI::DPIAware< wxDialog >::prev_scale_factor ( ) const
inlineinherited
196{ return m_prev_scale_factor; }

◆ register_theme_user_scripts()

void Slic3r::GUI::WebViewHostDialog::register_theme_user_scripts ( )
protectedinherited
286{
287 if (!m_browser)
288 return;
289 // Added once, at creation. Deliberately no RemoveAllUserScripts() here: the "wx"
290 // script message handler is registered separately (AddScriptMessageHandler), but on
291 // some backends RemoveAllUserScripts() drops it too, which would break
292 // window.wx.postMessage / HandleStudio. Live re-theme goes through apply_theme_live().
293 m_browser->AddUserScript(wxString::FromUTF8(theme_user_script()));
294 if (const nlohmann::json strings = localized_strings(); !strings.is_null())
295 m_browser->AddUserScript(wxString::FromUTF8(localized_strings_script(strings)));
297}
static std::string theme_user_script()
Definition WebViewHostDialog.cpp:93
static std::string localized_strings_script(const nlohmann::json &strings)
Definition WebViewHostDialog.cpp:156
virtual void add_user_scripts()
Definition WebViewHostDialog.hpp:95
virtual nlohmann::json localized_strings() const
Definition WebViewHostDialog.hpp:99

References add_user_scripts(), localized_strings(), localized_strings_script(), m_browser, and theme_user_script().

Referenced by create_webview().

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

◆ repaint_webview()

void Slic3r::GUI::ColorPickerDialog::repaint_webview ( )
private
909{
910 wxWebView* view = browser();
911 if (!view)
912 return;
913 view->Refresh();
914#ifdef __WXOSX__
915 if (void* backend = view->GetNativeBackend())
917 view->Update();
918#elif defined(__linux__)
919 if (void* backend = view->GetNativeBackend())
920 gtk_widget_queue_draw(static_cast<GtkWidget*>(backend));
921#else
922 view->Update();
923#endif
924}
void WKWebView_force_display(void *web)
Definition MacDarkMode.mm:109

References Slic3r::GUI::WebViewHostDialog::browser(), and Slic3r::GUI::WKWebView_force_display().

Referenced by handle_web_command(), and resize_to_content().

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

◆ rescale()

void Slic3r::GUI::DPIAware< wxDialog >::rescale ( const wxRect & suggested_rect)
inlineprivateinherited
265 {
266 this->Freeze();
267
268 m_force_rescale = false;
269
270 // set normal application font as a current window font
271 m_normal_font = this->GetFont();
272
274
275 // rescale missed controls sizes and images
277
278 this->Layout();
279 this->Thaw();
280
281 // reset previous scale factor from current scale factor value
283 }
virtual void on_dpi_changed(const wxRect &suggested_rect)=0
void update_em_unit()
Definition GUI_Utils.hpp:249

◆ resize_to_content()

void Slic3r::GUI::ColorPickerDialog::resize_to_content ( int height)
private
881{
884 Layout();
885#ifdef __WXOSX__
886 // Like SpeedDial, explicitly match WKWebView's viewport even at unchanged size.
887 if (wxWebView* view = browser())
888 view->SetSize(GetClientSize());
889#endif
891}
void position_panel()
Definition ColorPickerDialog.cpp:851

References Slic3r::GUI::WebViewHostDialog::browser(), m_content_height, position_panel(), and repaint_webview().

Referenced by ColorPickerDialog(), handle_web_command(), and on_dpi_changed().

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

◆ run_script()

bool Slic3r::GUI::WebViewHostDialog::run_script ( const wxString & script)
inherited
235{
236 if (!m_browser)
237 return false;
238
239 return WebView::RunScript(m_browser, script);
240}
static bool RunScript(wxWebView *webView, wxString const &msg)
Definition WebView.cpp:491

References m_browser, and WebView::RunScript().

Referenced by apply_theme_live(), call_web_handler(), Slic3r::GUI::ColorPickerDialog::focus_webview(), Slic3r::GUI::ColorPickerDialog::handle_web_command(), and Slic3r::GUI::ColorPickerDialog::send_initial_state().

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

◆ scale_factor()

float Slic3r::GUI::DPIAware< wxDialog >::scale_factor ( ) const
inlineinherited
195{ return m_scale_factor; }

◆ selection()

const std::optional< ColorSelection > & Slic3r::GUI::ColorPickerDialog::selection ( ) const
inline
55{ return m_selection; }

References m_selection.

Referenced by Slic3r::GUI::FilamentPickerDialog::BindEvents(), handle_web_command(), and send_initial_state().

Here is the caller graph for this function:

◆ send_initial_state()

void Slic3r::GUI::ColorPickerDialog::send_initial_state ( )
private
1061{
1062 nlohmann::json favorites = nlohmann::json::array();
1063 for (const ColorSelection& selection : m_favorites)
1064 favorites.push_back(color_selection_to_json(selection));
1065 const nlohmann::json payload = {{"command", "init"}, {"page_id", m_page_id},
1066 {"options", {{"allow_gradient", m_options.allow_gradient}, {"allow_alpha", m_options.allow_alpha},
1067 {"max_gradient_colors", COLOR_PICKER_MAX_GRADIENT_COLORS}}},
1068 {"selection", color_selection_to_json(m_initial)}, {"favorites", std::move(favorites)},
1069 {"favorites_writable", m_favorites_writable}, {"preserve_multi_color", m_preserve_multi_color},
1070 {"ui", {{"sidebar_open", m_sidebar_open}, {"palette", m_palette}}}};
1071 m_init_sent = true;
1072 // Already deferred and guarded: avoid the shared call_web_handler's unguarded
1073 // second CallAfter, which could run after this modal dialog is destroyed.
1074 if (!run_script(wxString::FromUTF8("window.ColorPickerDialog.handleMessage(" + payload.dump() + ")")))
1075 m_init_sent = false;
1076}
constexpr std::size_t COLOR_PICKER_MAX_GRADIENT_COLORS
Definition ColorPickerDialog.hpp:24

References Slic3r::GUI::COLOR_PICKER_MAX_GRADIENT_COLORS, m_favorites, m_favorites_writable, m_init_sent, m_initial, m_options, m_page_id, m_palette, m_preserve_multi_color, m_sidebar_open, Slic3r::GUI::WebViewHostDialog::run_script(), and selection().

Referenced by handle_web_command().

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

◆ set_em_unit()

void Slic3r::GUI::DPIAware< wxDialog >::set_em_unit ( int v)
inlineinherited
200{ m_em_unit = v; }

◆ set_prev_scale_factor()

void Slic3r::GUI::DPIAware< wxDialog >::set_prev_scale_factor ( float v)
inlineinherited

◆ set_scale_factor()

void Slic3r::GUI::DPIAware< wxDialog >::set_scale_factor ( float v)
inlineinherited
198{ m_scale_factor = v; }

◆ ShowModal()

◆ theme_apply_script()

std::string Slic3r::GUI::WebViewHostDialog::theme_apply_script ( )
staticinherited
88{ return host_theme_apply_js(); }

Referenced by Slic3r::GUI::WebPanel::apply_theme().

Here is the caller graph for this function:

◆ theme_user_script()

std::string Slic3r::GUI::WebViewHostDialog::theme_user_script ( )
staticinherited
94{
95 const std::string style = "<style id=\"orca-host-theme-vars\">" + host_theme_vars_css() + "</style>";
97 style, "orca-host-theme-vars", "afterbegin",
98 "window.__orcaHostThemed=true;var theme=\"" + host_theme_name() + "\";",
99 "if(document.documentElement)document.documentElement.setAttribute('data-orca-theme',theme);");
100}
#define style
Definition WipeTowerDialog.cpp:101
std::string host_theme_vars_css()
Definition WebViewHostDialog.cpp:40
std::string host_theme_name()
Definition WebViewHostDialog.cpp:35

References document_start_injector(), and style.

Referenced by Slic3r::GUI::WebPanel::WebPanel(), and register_theme_user_scripts().

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

◆ update_em_unit()

void Slic3r::GUI::DPIAware< wxDialog >::update_em_unit ( )
inlineprivateinherited
250 {
251 // Linux specific issue : get_dpi_for_window(this) still doesn't responce to the Display's scale in new wxWidgets(3.1.3).
252 // So, calculate the m_em_unit value from the font size, as before
253#if !defined(__WXGTK__)
255#else
256 // initialize default width_unit according to the width of the one symbol ("m") of the currently active font of this window.
257 m_em_unit = std::max<size_t>(10, this->GetTextExtent("m").x - 1);
258#endif // __WXGTK__
259 }

Member Data Documentation

◆ m_alive

std::shared_ptr<std::atomic<bool> > Slic3r::GUI::ColorPickerDialog::m_alive = std::make_shared<std::atomic<bool>>(true)
private

◆ m_anchor_rect

wxRect Slic3r::GUI::ColorPickerDialog::m_anchor_rect
private

◆ m_browser

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

◆ m_can_rescale

bool Slic3r::GUI::DPIAware< wxDialog >::m_can_rescale
privateinherited
235{ true };

◆ m_closing

bool Slic3r::GUI::ColorPickerDialog::m_closing = false
private

◆ m_content_height

int Slic3r::GUI::ColorPickerDialog::m_content_height = 360
private

◆ m_content_width

int Slic3r::GUI::ColorPickerDialog::m_content_width = 330
private

◆ m_em_unit

int Slic3r::GUI::DPIAware< wxDialog >::m_em_unit
privateinherited

◆ m_favorites

std::vector<ColorSelection> Slic3r::GUI::ColorPickerDialog::m_favorites
private

◆ m_favorites_writable

bool Slic3r::GUI::ColorPickerDialog::m_favorites_writable = false
private

◆ m_force_rescale

bool Slic3r::GUI::DPIAware< wxDialog >::m_force_rescale
privateinherited
236{ false };

◆ m_init_sent

bool Slic3r::GUI::ColorPickerDialog::m_init_sent = false
private

◆ m_initial

ColorSelection Slic3r::GUI::ColorPickerDialog::m_initial
private

◆ m_initial_positioned

bool Slic3r::GUI::ColorPickerDialog::m_initial_positioned = false
private

Referenced by ColorPickerDialog().

◆ m_new_font_point_size

int Slic3r::GUI::DPIAware< wxDialog >::m_new_font_point_size
privateinherited

◆ m_normal_font

wxFont Slic3r::GUI::DPIAware< wxDialog >::m_normal_font
privateinherited

◆ m_options

ColorPickerOptions Slic3r::GUI::ColorPickerDialog::m_options
private

◆ m_page_id

std::string Slic3r::GUI::ColorPickerDialog::m_page_id
private

◆ m_page_ready

bool Slic3r::GUI::ColorPickerDialog::m_page_ready = false
private

◆ m_palette

std::string Slic3r::GUI::ColorPickerDialog::m_palette
private

◆ m_positioning

bool Slic3r::GUI::ColorPickerDialog::m_positioning = false
private

Referenced by position_panel().

◆ m_preserve_multi_color

bool Slic3r::GUI::ColorPickerDialog::m_preserve_multi_color = false
private

◆ m_prev_scale_factor

float Slic3r::GUI::DPIAware< wxDialog >::m_prev_scale_factor
privateinherited

◆ m_scale_factor

float Slic3r::GUI::DPIAware< wxDialog >::m_scale_factor
privateinherited

◆ m_selection

std::optional<ColorSelection> Slic3r::GUI::ColorPickerDialog::m_selection
private

◆ m_sidebar_open

bool Slic3r::GUI::ColorPickerDialog::m_sidebar_open = false
private

◆ m_work_area

wxRect Slic3r::GUI::ColorPickerDialog::m_work_area
private

The documentation for this class was generated from the following files: