mirror of
https://github.com/OrcaSlicer/OrcaSlicer.git
synced 2026-09-26 18:31:11 +00:00
Merge branch 'main' into dev/ffmpeg-player
This commit is contained in:
@@ -2083,9 +2083,6 @@ void AMSRoad::OnPassRoad(std::vector<AMSPassRoadMode> prord_list)
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
|
||||
/*************************************************
|
||||
Description:AMSRoadUpPart
|
||||
**************************************************/
|
||||
|
||||
@@ -95,14 +95,11 @@ void Button::SetIcon(const wxString& icon)
|
||||
}
|
||||
}
|
||||
|
||||
void Button::SetInactiveIcon(const wxString &icon)
|
||||
void Button::SetIcon(const wxBitmap& icon)
|
||||
{
|
||||
if (!icon.IsEmpty()) {
|
||||
// BBS set button icon default size to 20
|
||||
this->inactive_icon = ScalableBitmap(this, icon.ToStdString(), this->active_icon.px_cnt());
|
||||
} else {
|
||||
this->inactive_icon = ScalableBitmap();
|
||||
}
|
||||
this->active_icon = ScalableBitmap();
|
||||
this->active_icon.bmp() = icon;
|
||||
messureSize();
|
||||
Refresh();
|
||||
}
|
||||
|
||||
@@ -257,12 +254,10 @@ void Button::SetStyle(const ButtonStyle style, const ButtonType type)
|
||||
|
||||
void Button::Rescale()
|
||||
{
|
||||
if (this->active_icon.bmp().IsOk())
|
||||
// Only a named icon can be re-rasterized; one set from a wxBitmap has no source file,
|
||||
if (!this->active_icon.name().empty())
|
||||
this->active_icon.msw_rescale();
|
||||
|
||||
if (this->inactive_icon.bmp().IsOk())
|
||||
this->inactive_icon.msw_rescale();
|
||||
|
||||
messureSize();
|
||||
|
||||
if(m_has_style)
|
||||
@@ -293,11 +288,7 @@ void Button::render(wxDC& dc)
|
||||
wxSize szIcon;
|
||||
wxSize textSize = this->textSize.GetSize();
|
||||
|
||||
ScalableBitmap icon;
|
||||
if (m_selected || ((states & (int)StateColor::State::Hovered) != 0))
|
||||
icon = active_icon;
|
||||
else
|
||||
icon = inactive_icon;
|
||||
const ScalableBitmap& icon = active_icon;
|
||||
wxSize padding = this->paddingSize;
|
||||
int spacing = 5;
|
||||
// Wrap text
|
||||
@@ -512,8 +503,8 @@ void Button::OnParentMotion(wxMouseEvent& event)
|
||||
{
|
||||
if (!tipWindow)
|
||||
{
|
||||
tipWindow = new wxTipWindow(this, tip);
|
||||
tipWindow->Bind(wxEVT_DESTROY, [this](wxEvent& event) { this->tipWindow = nullptr;});
|
||||
tipWindow = wxTipWindow::New(this, tip);
|
||||
if (!tipWindow) return event.Skip();
|
||||
tipWindow->Enable(false);
|
||||
}
|
||||
|
||||
@@ -531,7 +522,8 @@ void Button::OnParentMotion(wxMouseEvent& event)
|
||||
{
|
||||
if (tipWindow)
|
||||
{
|
||||
delete tipWindow;
|
||||
tipWindow->Dismiss();
|
||||
tipWindow->Destroy();
|
||||
tipWindow = nullptr;
|
||||
}
|
||||
}
|
||||
@@ -552,7 +544,7 @@ void Button::OnParentLeave(wxMouseEvent& event)
|
||||
if (!screen_rect.Contains(pos))
|
||||
{
|
||||
tipWindow->Dismiss();
|
||||
delete tipWindow;
|
||||
tipWindow->Destroy();
|
||||
tipWindow = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
|
||||
#include "../wxExtensions.hpp"
|
||||
#include "StaticBox.hpp"
|
||||
#include <wx/tipwin.h>
|
||||
|
||||
class ButtonProps
|
||||
{
|
||||
@@ -27,14 +28,13 @@ enum class ButtonType{
|
||||
Expanded , // Font14 Semi-Rounded For full length buttons. ex. buttons in static box
|
||||
};
|
||||
|
||||
class wxTipWindow;
|
||||
class Button : public StaticBox
|
||||
{
|
||||
wxTipWindow::Ref tipWindow;
|
||||
wxRect textSize;
|
||||
wxSize minSize; // set by outer
|
||||
wxSize paddingSize;
|
||||
ScalableBitmap active_icon;
|
||||
ScalableBitmap inactive_icon;
|
||||
|
||||
StateColor text_color;
|
||||
|
||||
@@ -44,8 +44,6 @@ class Button : public StaticBox
|
||||
bool isCenter = true;
|
||||
bool vertical = false;
|
||||
|
||||
wxTipWindow* tipWindow = nullptr;
|
||||
|
||||
static const int buttonWidth = 200;
|
||||
static const int buttonHeight = 50;
|
||||
|
||||
@@ -61,8 +59,7 @@ public:
|
||||
bool SetFont(const wxFont& font) override;
|
||||
|
||||
void SetIcon(const wxString& icon);
|
||||
|
||||
void SetInactiveIcon(const wxString& icon);
|
||||
void SetIcon(const wxBitmap& icon);
|
||||
|
||||
void SetMinSize(const wxSize& size) override;
|
||||
void SetMaxSize(const wxSize& size) override;
|
||||
|
||||
@@ -87,10 +87,18 @@ void ComboBox::SetSelection(int n)
|
||||
return;
|
||||
drop.SetSelection(n);
|
||||
SetLabel(drop.GetValue());
|
||||
if (drop.selection >= 0 && drop.iconSize.y > 0 && items[drop.selection].icon_textctrl.IsOk())
|
||||
SetIcon(items[drop.selection].icon_textctrl);
|
||||
else
|
||||
if (drop.selection >= 0 && drop.iconSize.y > 0 && items[drop.selection].icon_textctrl.IsOk()) {
|
||||
if (m_keep_drop_arrow) {
|
||||
SetIcon("drop_down");
|
||||
SetIcon_1(items[drop.selection].icon_textctrl);
|
||||
} else {
|
||||
SetIcon(items[drop.selection].icon_textctrl);
|
||||
}
|
||||
} else {
|
||||
SetIcon("drop_down");
|
||||
if (m_keep_drop_arrow)
|
||||
SetIcon_1(wxNullBitmap);
|
||||
}
|
||||
|
||||
if (drop.selection >= 0) {
|
||||
SetStaticTips(items[drop.selection].text_static_tips, wxNullBitmap);
|
||||
@@ -120,10 +128,18 @@ void ComboBox::SetValue(const wxString &value)
|
||||
{
|
||||
drop.SetValue(value);
|
||||
SetLabel(value);
|
||||
if (drop.selection >= 0 && drop.iconSize.y > 0 && items[drop.selection].icon_textctrl.IsOk())
|
||||
SetIcon(items[drop.selection].icon_textctrl);
|
||||
else
|
||||
if (drop.selection >= 0 && drop.iconSize.y > 0 && items[drop.selection].icon_textctrl.IsOk()) {
|
||||
if (m_keep_drop_arrow) {
|
||||
SetIcon("drop_down");
|
||||
SetIcon_1(items[drop.selection].icon_textctrl);
|
||||
} else {
|
||||
SetIcon(items[drop.selection].icon_textctrl);
|
||||
}
|
||||
} else {
|
||||
SetIcon("drop_down");
|
||||
if (m_keep_drop_arrow)
|
||||
SetIcon_1(wxNullBitmap);
|
||||
}
|
||||
|
||||
if (drop.selection >= 0) {
|
||||
SetStaticTips(items[drop.selection].text_static_tips, wxNullBitmap);
|
||||
|
||||
@@ -16,6 +16,7 @@ class ComboBox : public wxWindowWithItems<TextInput, wxItemContainer>
|
||||
bool drop_down = false;
|
||||
bool text_off = false;
|
||||
bool is_replace_text_to_image = false;
|
||||
bool m_keep_drop_arrow = false; // When true, item icon goes to icon_1, keeping drop_down arrow
|
||||
wxString replace_text;
|
||||
wxString image_for_text;
|
||||
|
||||
@@ -31,6 +32,11 @@ public:
|
||||
|
||||
DropDown & GetDropDown() { return drop; }
|
||||
|
||||
// When true, item icon is shown as icon_1 (secondary), preserving drop_down arrow.
|
||||
// Note: item bitmaps are set via raw wxBitmap (not ScalableBitmap), so they won't
|
||||
// auto-rescale on DPI change. Caller should recreate items after DPI change.
|
||||
void SetKeepDropArrow(bool keep) { m_keep_drop_arrow = keep; }
|
||||
|
||||
virtual bool SetFont(wxFont const & font) override;
|
||||
|
||||
public:
|
||||
|
||||
@@ -427,7 +427,10 @@ void DropDown::render(wxDC &dc)
|
||||
}
|
||||
pt.y += (rcContent.height - textSize.y) / 2;
|
||||
dc.SetFont(GetFont());
|
||||
dc.SetTextForeground(text_color.colorForStates(states2));
|
||||
// Dimmed items stay selectable, so they only borrow the disabled text tone rather
|
||||
// than taking the disabled state itself.
|
||||
const int text_states = (item.style & DD_ITEM_STYLE_DIMMED) ? (states2 & ~StateColor::Enabled) : states2;
|
||||
dc.SetTextForeground(text_color.colorForStates(text_states));
|
||||
dc.DrawText(text, pt);
|
||||
if (group.IsEmpty() && !item.group_key.IsEmpty()) {
|
||||
auto szBmp = arrow_bitmap.GetBmpSize();
|
||||
|
||||
@@ -13,6 +13,7 @@
|
||||
|
||||
#define DD_ITEM_STYLE_SPLIT_ITEM 0x0001 // ----text----, text with horizontal line arounds
|
||||
#define DD_ITEM_STYLE_DISABLED 0x0002 // ----text----, text with horizontal line arounds
|
||||
#define DD_ITEM_STYLE_DIMMED 0x0004 // gray text, but still selectable
|
||||
|
||||
wxDECLARE_EVENT(EVT_DISMISS, wxCommandEvent);
|
||||
|
||||
|
||||
@@ -630,7 +630,7 @@ NozzleListTable::NozzleListTable(wxWindow* parent) : wxPanel(parent,wxID_ANY,wxD
|
||||
SetSizer(sizer);
|
||||
Layout();
|
||||
|
||||
m_web_view->Bind(wxEVT_WEBVIEW_SCRIPT_MESSAGE_RECEIVED, [this,sizer](wxWebViewEvent& evt) {
|
||||
m_web_view->Bind(wxEVT_WEBVIEW_SCRIPT_MESSAGE_RECEIVED, [this](wxWebViewEvent& evt) {
|
||||
std::string message = evt.GetString().ToStdString();
|
||||
BOOST_LOG_TRIVIAL(debug) << __FUNCTION__ << "Received message: " << message;
|
||||
try {
|
||||
@@ -1168,8 +1168,8 @@ void MultiNozzleSyncDialog::UpdateButton(std::weak_ptr<DevNozzleRack> rack, bool
|
||||
m_cancel_btn->SetLabel(_L("Ignore"));
|
||||
m_confirm_btn->SetLabel(_L("Refresh"));
|
||||
|
||||
m_cancel_btn->Bind(wxEVT_LEFT_DOWN, [this, rack, ignore_opt](auto& e) {ignore_opt(); });
|
||||
m_confirm_btn->Bind(wxEVT_LEFT_DOWN, [this, rack, refresh_cmd](auto& e) {refresh_cmd(); });
|
||||
m_cancel_btn->Bind(wxEVT_LEFT_DOWN, [rack, ignore_opt](auto& e) {ignore_opt(); });
|
||||
m_confirm_btn->Bind(wxEVT_LEFT_DOWN, [rack, refresh_cmd](auto& e) {refresh_cmd(); });
|
||||
}
|
||||
else if (has_unknown) {
|
||||
m_cancel_btn->Show();
|
||||
@@ -1178,8 +1178,8 @@ void MultiNozzleSyncDialog::UpdateButton(std::weak_ptr<DevNozzleRack> rack, bool
|
||||
m_cancel_btn->SetLabel(_L("Ignore"));
|
||||
m_confirm_btn->SetLabel(_L("Refresh"));
|
||||
|
||||
m_cancel_btn->Bind(wxEVT_LEFT_DOWN, [this, rack, ignore_opt](auto& e) {ignore_opt(); });
|
||||
m_confirm_btn->Bind(wxEVT_LEFT_DOWN, [this, rack, refresh_cmd](auto& e) {refresh_cmd(); });
|
||||
m_cancel_btn->Bind(wxEVT_LEFT_DOWN, [rack, ignore_opt](auto& e) {ignore_opt(); });
|
||||
m_confirm_btn->Bind(wxEVT_LEFT_DOWN, [rack, refresh_cmd](auto& e) {refresh_cmd(); });
|
||||
}
|
||||
else if (has_unreliable) {
|
||||
m_cancel_btn->Show();
|
||||
@@ -1188,8 +1188,8 @@ void MultiNozzleSyncDialog::UpdateButton(std::weak_ptr<DevNozzleRack> rack, bool
|
||||
m_cancel_btn->SetLabel(_L("Refresh"));
|
||||
m_confirm_btn->SetLabel(_L("Confirm"));
|
||||
|
||||
m_cancel_btn->Bind(wxEVT_LEFT_DOWN, [this, rack, refresh_cmd](auto& e) {refresh_cmd(); });
|
||||
m_confirm_btn->Bind(wxEVT_LEFT_DOWN, [this, rack, trust_cmd](auto& e) {trust_cmd(); });
|
||||
m_cancel_btn->Bind(wxEVT_LEFT_DOWN, [rack, refresh_cmd](auto& e) {refresh_cmd(); });
|
||||
m_confirm_btn->Bind(wxEVT_LEFT_DOWN, [rack, trust_cmd](auto& e) {trust_cmd(); });
|
||||
|
||||
}
|
||||
else {
|
||||
|
||||
@@ -167,7 +167,7 @@ class MultiNozzleSyncDialog : public DPIDialog
|
||||
{
|
||||
public:
|
||||
MultiNozzleSyncDialog(wxWindow* parent, std::weak_ptr<DevNozzleRack> rack);
|
||||
virtual void on_dpi_changed(const wxRect& suggested_rect) {};
|
||||
virtual void on_dpi_changed(const wxRect& suggested_rect) override {};
|
||||
std::vector<NozzleOption> GetNozzleOptions(const std::vector<MultiNozzleUtils::NozzleGroupInfo>& group_infos);
|
||||
|
||||
std::optional<NozzleOption> GetSelectedOption() {
|
||||
|
||||
@@ -56,7 +56,7 @@ protected:
|
||||
void paintEvent(wxPaintEvent &evt);
|
||||
void render(wxDC &dc);
|
||||
void doRender(wxDC &dc);
|
||||
virtual void DoSetSize(int x, int y, int width, int height, int sizeFlags = wxSIZE_AUTO);
|
||||
virtual void DoSetSize(int x, int y, int width, int height, int sizeFlags = wxSIZE_AUTO) override;
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -33,7 +33,7 @@ public:
|
||||
void OnPaint(wxPaintEvent &evt);
|
||||
virtual ~ProgressDialog();
|
||||
|
||||
virtual void DoSetSize(int x, int y, int width, int height, int sizeFlags = wxSIZE_AUTO);
|
||||
virtual void DoSetSize(int x, int y, int width, int height, int sizeFlags = wxSIZE_AUTO) override;
|
||||
bool Create(const wxString &title, const wxString &message, int maximum = 100, wxWindow *parent = NULL, int style = wxPD_APP_MODAL | wxPD_AUTO_HIDE);
|
||||
|
||||
virtual bool Update(int value, const wxString &newmsg = wxEmptyString, bool *skip = NULL);
|
||||
|
||||
@@ -31,7 +31,7 @@ public:
|
||||
|
||||
void SetLayoutStyle(int style);
|
||||
|
||||
void SetLabel(const wxString& label);
|
||||
void SetLabel(const wxString& label) override;
|
||||
|
||||
bool SetForegroundColour(wxColour const & colour) override;
|
||||
|
||||
@@ -47,7 +47,7 @@ public:
|
||||
|
||||
void SetBackgroundColor(StateColor const &color);
|
||||
|
||||
bool Enable(bool enable = true);
|
||||
bool Enable(bool enable = true) override;
|
||||
|
||||
void Rescale();
|
||||
|
||||
|
||||
@@ -9,6 +9,8 @@
|
||||
#include "../GUI_Utils.hpp"
|
||||
#endif
|
||||
|
||||
wxDEFINE_EVENT(EVT_SPINCTRL_TEXT, wxCommandEvent);
|
||||
|
||||
BEGIN_EVENT_TABLE(SpinInput, StaticBox)
|
||||
|
||||
EVT_KEY_DOWN(SpinInput::keyPressed)
|
||||
@@ -74,8 +76,9 @@ void SpinInput::Create(wxWindow *parent,
|
||||
state_handler.attach_child(text_ctrl);
|
||||
text_ctrl->Bind(wxEVT_KILL_FOCUS, &SpinInput::onTextLostFocus, this);
|
||||
text_ctrl->Bind(wxEVT_TEXT_ENTER, &SpinInput::onTextEnter, this);
|
||||
text_ctrl->Bind(wxEVT_TEXT, &SpinInput::onTextChanged, this);
|
||||
text_ctrl->Bind(wxEVT_KEY_DOWN, &SpinInput::keyPressed, this);
|
||||
text_ctrl->Bind(wxEVT_RIGHT_DOWN, [this](auto &e) {}); // disable context menu
|
||||
text_ctrl->Bind(wxEVT_RIGHT_DOWN, [](auto &e) {}); // disable context menu
|
||||
button_inc = createButton(true);
|
||||
button_dec = createButton(false);
|
||||
delta = 0;
|
||||
@@ -300,6 +303,19 @@ void SpinInput::onTextEnter(wxCommandEvent &event)
|
||||
ProcessEventLocally(event);
|
||||
}
|
||||
|
||||
void SpinInput::onTextChanged(wxCommandEvent &event)
|
||||
{
|
||||
long value;
|
||||
if (text_ctrl->GetValue().ToLong(&value)) {
|
||||
wxCommandEvent e(EVT_SPINCTRL_TEXT, GetId());
|
||||
e.SetEventObject(this);
|
||||
e.SetInt((int) value);
|
||||
e.SetString(text_ctrl->GetValue());
|
||||
GetEventHandler()->ProcessEvent(e);
|
||||
}
|
||||
event.Skip();
|
||||
}
|
||||
|
||||
void SpinInput::mouseWheelMoved(wxMouseEvent &event)
|
||||
{
|
||||
auto delta = event.GetWheelRotation() < 0 ? 1 : -1;
|
||||
|
||||
@@ -9,6 +9,10 @@
|
||||
|
||||
class Button;
|
||||
|
||||
// Fired on every keystroke that leaves a parseable integer in the field, so callers can
|
||||
// react live rather than only on commit (wxEVT_SPINCTRL) or Enter. Ported from BambuStudio.
|
||||
wxDECLARE_EVENT(EVT_SPINCTRL_TEXT, wxCommandEvent);
|
||||
|
||||
class SpinInput : public wxNavigationEnabled<StaticBox>
|
||||
{
|
||||
wxSize labelSize;
|
||||
@@ -98,6 +102,7 @@ private:
|
||||
void keyPressed(wxKeyEvent& event);
|
||||
void onTimer(wxTimerEvent &evnet);
|
||||
void onTextLostFocus(wxEvent &event);
|
||||
void onTextChanged(wxCommandEvent &event);
|
||||
void onTextEnter(wxCommandEvent &event);
|
||||
|
||||
void sendSpinEvent();
|
||||
|
||||
@@ -63,7 +63,7 @@ public:
|
||||
bool IsVisible(unsigned int item) const;
|
||||
|
||||
private:
|
||||
virtual void DoSetSize(int x, int y, int width, int height, int sizeFlags = wxSIZE_AUTO);
|
||||
virtual void DoSetSize(int x, int y, int width, int height, int sizeFlags = wxSIZE_AUTO) override;
|
||||
|
||||
#ifdef __WIN32__
|
||||
WXLRESULT MSWWindowProc(WXUINT nMsg, WXWPARAM wParam, WXLPARAM lParam) override;
|
||||
|
||||
@@ -134,7 +134,7 @@ void TempInput::Create(wxWindow *parent, wxString text, wxString label, wxString
|
||||
}
|
||||
}
|
||||
});
|
||||
text_ctrl->Bind(wxEVT_RIGHT_DOWN, [this](auto &e) {}); // disable context menu
|
||||
text_ctrl->Bind(wxEVT_RIGHT_DOWN, [](auto &e) {}); // disable context menu
|
||||
text_ctrl->Bind(wxEVT_LEFT_DOWN, [this](auto &e) {
|
||||
if (m_read_only) {
|
||||
return;
|
||||
|
||||
@@ -107,7 +107,7 @@ public:
|
||||
wxString GetTagTemp() { return text_ctrl->GetValue(); }
|
||||
wxString GetCurrTemp() { return GetLabel(); }
|
||||
int get_max_temp() { return max_temp; }
|
||||
void SetLabel(const wxString &label);
|
||||
void SetLabel(const wxString &label) override;
|
||||
|
||||
void SetTextColor(StateColor const &color);
|
||||
|
||||
@@ -128,7 +128,7 @@ public:
|
||||
void ReSetOnChanging() { m_on_changing = false; }
|
||||
|
||||
protected:
|
||||
virtual void DoSetSize(int x, int y, int width, int height, int sizeFlags = wxSIZE_AUTO);
|
||||
virtual void DoSetSize(int x, int y, int width, int height, int sizeFlags = wxSIZE_AUTO) override;
|
||||
|
||||
void DoSetToolTipText(wxString const &tip) override;
|
||||
|
||||
|
||||
@@ -85,7 +85,7 @@ void TextInput::Create(wxWindow * parent,
|
||||
e.SetId(GetId());
|
||||
ProcessEventLocally(e);
|
||||
});
|
||||
text_ctrl->Bind(wxEVT_RIGHT_DOWN, [this](auto &e) {}); // disable context menu
|
||||
text_ctrl->Bind(wxEVT_RIGHT_DOWN, [](auto &e) {}); // disable context menu
|
||||
if (!icon.IsEmpty()) {
|
||||
this->icon = ScalableBitmap(this, icon.ToStdString(), 16);
|
||||
}
|
||||
@@ -139,6 +139,15 @@ void TextInput::SetIcon_1(const wxString &icon) {
|
||||
Rescale();
|
||||
}
|
||||
|
||||
// Set icon_1 from a raw bitmap. Note: won't auto-rescale on DPI change
|
||||
// since ScalableBitmap::name() will be empty. Caller should re-set after DPI change.
|
||||
void TextInput::SetIcon_1(const wxBitmap &icon) {
|
||||
this->icon_1 = ScalableBitmap();
|
||||
if (icon.IsOk())
|
||||
this->icon_1.bmp() = icon;
|
||||
Rescale();
|
||||
}
|
||||
|
||||
void TextInput::SetLabelColor(StateColor const &color)
|
||||
{
|
||||
label_color = color;
|
||||
|
||||
@@ -46,7 +46,7 @@ public:
|
||||
// Only meant to be used by inspector, not public API
|
||||
int GetCornerRadius() const { return static_cast<int>(radius); }
|
||||
|
||||
void SetLabel(const wxString& label);
|
||||
void SetLabel(const wxString& label) override;
|
||||
|
||||
void SetStaticTips(const wxString& tips, const wxBitmap& bitmap);
|
||||
|
||||
@@ -54,6 +54,7 @@ public:
|
||||
void SetIcon(const wxString & icon);
|
||||
|
||||
void SetIcon_1(const wxString &icon);
|
||||
void SetIcon_1(const wxBitmap &icon);
|
||||
|
||||
void SetLabelColor(StateColor const &color);
|
||||
|
||||
@@ -73,7 +74,7 @@ protected:
|
||||
virtual void OnEdit() {}
|
||||
|
||||
virtual void DoSetSize(
|
||||
int x, int y, int width, int height, int sizeFlags = wxSIZE_AUTO);
|
||||
int x, int y, int width, int height, int sizeFlags = wxSIZE_AUTO) override;
|
||||
|
||||
void DoSetToolTipText(wxString const &tip) override;
|
||||
|
||||
|
||||
@@ -104,7 +104,7 @@ DWORD DownloadAndInstallWV2RT() {
|
||||
class WebViewEdge : public wxWebViewEdge
|
||||
{
|
||||
public:
|
||||
bool SetUserAgent(const wxString &userAgent)
|
||||
bool SetUserAgent(const wxString &userAgent) override
|
||||
{
|
||||
bool dark = userAgent.Contains("dark");
|
||||
SetColorScheme(dark ? COREWEBVIEW2_PREFERRED_COLOR_SCHEME_DARK : COREWEBVIEW2_PREFERRED_COLOR_SCHEME_LIGHT);
|
||||
|
||||
@@ -57,18 +57,6 @@ std::string host_theme_vars_css()
|
||||
return s;
|
||||
}
|
||||
|
||||
// Document-start user script: injects the contract <style>, stamps data-orca-theme before
|
||||
// first paint, and raises a JS flag so the legacy globalapi.js dark.css poll stands down for
|
||||
// host-themed pages. The WebView2 timing guard lives in document_start_injector().
|
||||
std::string host_theme_user_script()
|
||||
{
|
||||
const std::string style = "<style id=\"orca-host-theme-vars\">" + host_theme_vars_css() + "</style>";
|
||||
return WebViewHostDialog::document_start_injector(
|
||||
style, "orca-host-theme-vars", "afterbegin",
|
||||
"window.__orcaHostThemed=true;var theme=\"" + host_theme_name() + "\";",
|
||||
"if(document.documentElement)document.documentElement.setAttribute('data-orca-theme',theme);");
|
||||
}
|
||||
|
||||
// JS to re-theme an already-loaded document live (no reload): replace the injected
|
||||
// style's contents and update data-orca-theme. Everything downstream (theme.css
|
||||
// tokens, plugin element defaults, page layout) re-cascades from these values.
|
||||
@@ -87,6 +75,46 @@ if(document.documentElement)
|
||||
|
||||
} // namespace
|
||||
|
||||
// Document-start user script: injects the contract <style>, stamps data-orca-theme before
|
||||
// first paint, and raises a JS flag so the legacy globalapi.js dark.css poll stands down for
|
||||
// host-themed pages. The WebView2 timing guard lives in document_start_injector().
|
||||
std::string WebViewHostDialog::theme_user_script()
|
||||
{
|
||||
const std::string style = "<style id=\"orca-host-theme-vars\">" + host_theme_vars_css() + "</style>";
|
||||
return document_start_injector(
|
||||
style, "orca-host-theme-vars", "afterbegin",
|
||||
"window.__orcaHostThemed=true;var theme=\"" + host_theme_name() + "\";",
|
||||
"if(document.documentElement)document.documentElement.setAttribute('data-orca-theme',theme);");
|
||||
}
|
||||
|
||||
std::string WebViewHostDialog::plugin_defaults_user_script()
|
||||
{
|
||||
std::string css;
|
||||
css += "<style id=\"orca-plugin-defaults\">";
|
||||
css += "html,body{background:var(--orca-bg);color:var(--orca-fg);"
|
||||
"font-family:var(--orca-font);font-size:13px;}";
|
||||
css += "body{margin:0;}";
|
||||
css += "h1,h2,h3,h4,h5,h6{color:var(--orca-fg);font-weight:600;}";
|
||||
css += "a{color:var(--orca-accent);}";
|
||||
css += "hr{border:0;border-top:1px solid var(--orca-border);}";
|
||||
css += "button{font:inherit;color:var(--orca-accent-fg);background:var(--orca-accent);"
|
||||
"border:1px solid var(--orca-accent);border-radius:4px;padding:5px 14px;cursor:pointer;}";
|
||||
css += "button:hover{filter:brightness(1.1);}";
|
||||
css += "button:disabled{opacity:.5;cursor:default;}";
|
||||
css += "input,select,textarea{font:inherit;color:var(--orca-fg);"
|
||||
"background:var(--orca-bg);border:1px solid var(--orca-border);"
|
||||
"border-radius:4px;padding:4px 8px;}";
|
||||
css += "input:focus,select:focus,textarea:focus{outline:none;border-color:var(--orca-accent);}";
|
||||
css += "table{border-collapse:collapse;}";
|
||||
css += "th,td{text-align:left;padding:6px 10px;border-bottom:1px solid var(--orca-border);}";
|
||||
css += "th{color:var(--orca-muted);font-weight:600;}";
|
||||
css += "::-webkit-scrollbar{width:12px;height:12px;}";
|
||||
css += "::-webkit-scrollbar-thumb{background:var(--orca-border);border-radius:6px;}";
|
||||
css += "::-webkit-scrollbar-track{background:transparent;}";
|
||||
css += "</style>";
|
||||
return document_start_injector(css, "orca-plugin-defaults", "beforeend");
|
||||
}
|
||||
|
||||
std::string WebViewHostDialog::document_start_injector(const std::string& markup,
|
||||
const char* dom_id,
|
||||
const char* position,
|
||||
@@ -244,7 +272,7 @@ void WebViewHostDialog::register_theme_user_scripts()
|
||||
// script message handler is registered separately (AddScriptMessageHandler), but on
|
||||
// some backends RemoveAllUserScripts() drops it too, which would break
|
||||
// window.wx.postMessage / HandleStudio. Live re-theme goes through apply_theme_live().
|
||||
m_browser->AddUserScript(wxString::FromUTF8(host_theme_user_script()));
|
||||
m_browser->AddUserScript(wxString::FromUTF8(theme_user_script()));
|
||||
add_user_scripts();
|
||||
}
|
||||
|
||||
|
||||
@@ -49,6 +49,10 @@ public:
|
||||
const std::string& prelude = {},
|
||||
const std::string& on_inject = {});
|
||||
|
||||
// Shared by modeless Pages tabs and PluginWebDialog.
|
||||
static std::string theme_user_script();
|
||||
static std::string plugin_defaults_user_script();
|
||||
|
||||
protected:
|
||||
wxWebView* browser() const { return m_browser; }
|
||||
|
||||
|
||||
Reference in New Issue
Block a user