Files
OrcaSlicer-KX/src/slic3r/GUI/Widgets/TabCtrl.cpp
Ocraftyone 25a055491e Update wxWidgets to v3.2.1 (#2905)
* Upgrade wxWidgets to 3.2.1
Based on prusa3d/PrusaSlicer@9a7e024

Co-authored-by: tamasmeszaros <meszaros.q@gmail.com>

* Implement BitmapCache

* update wxExtensions while keeping legacy items

* update dc.DrawBitmap calls to use get_bitmap

* Fix GetSize/Width/Height calls

* update BitmapComboBox

* fix ifndef in wxExtensions.hpp

* update my todos to OcraftyoneTODO

* Get to a compilable state
Everything seems to be working (including the plater). I am not seeing any graphical issues

* fix extruder color icons

* fix crash on opening support tab

* remove GetBmpSize method from DropDown.cpp

* Update TextInput to use bitmap bundles

* update a TODO after testing

* fix the rendering of the icons on combobox

* fix a few todos

* fix WipeTowerDialog.cpp

* Overhaul WipeTowerDialog

Removed simple version of the dialog since BBS removed the functionality but left the code.
Center the table (only seen when the table is smaller than the minimum size of the dialog)
Fix issue where editing a value causes the m_min_flush_label to change colors slightly
Fix an issue where changing a value or running an auto calc changes the disabled value from "-" to "0"

* update a few todos

* Update some todos

* Show dropdown when editing is started

* Update NanoSVG.cmake

Update NanoSVG to work with PR #2780

* Dim the icon on ComboBox when disabled

* solve ObjectDataViewModel todos

leaving colPrint and colEditing cases alone as it does not seem to impact anything

* Update names in wxExtensions

-Rename msw_rescale to sys_color_changed
-Replace GetBmpSize, GetBmpWidth, GetBmpHeight with renamed version (same name without "Bmp")

Both of these changes were also made by PrusaSlicer.

Original Commit: Prusa3D/PrusaSlicer@066b567
Co-authored-by: YuSanka <yusanka@gmail.com>

* update BitmapCache::from_svg

disable finding bundle in the cache to match load_svg
update to match values used in load_svg

* Update ScalableButton

change the signature and remove functions/vars pertaining to a default bmp
fix TODOs in ScalableButton

Original Commit: Prusa3D/PrusaSlicer@066b567
Co-authored-by: YuSanka <yusanka@gmail.com>

* fix up some more todos in wxExtensions

* update ScalableBitmap to use bmp bundles

use wxBitmapBundle by default
add flag to use old scaled bitmap function (specifically to solve issue with advanced toggle)

* attempt to fix macos deps build

* fix ubuntu build

* Revert "attempt to fix macos deps build"

Mistakenly made change to wrong file

This reverts commit d9c20b51216db1d409aeb0420d9d901000ad1b00.

* update wxWidgets patch

an attempt to fix macOS build

* Remove duplicate variable from OrcaSlicer.cpp

* Fix macOS build issue

* Fix blank DataViewItem being added to objects list

* Filament ComboBox editor updates

-Add show drop down feature to ObjectTable
-Call finish editing when ComboBox is closed in ObjectList

* remove Apple specific declarations missed during refactor

* delete old wxWidgets patch

* fix ubuntu seg fault

* include patch from #2926

* update patch to include wxWidgets/wxWidgets@991a74c

* fix deps not compiling on Windows

* update WipeTowerDialog

relocates the recalculate button back to its previous position
changes the wording of the tip message label
add spacing below the matrix

* finish patching wxWidgets

from prusa3d/PrusaSlicer@f8477d1 and prusa3d/PrusaSlicer@066b567

Co-authored-by: YuSanka <yusanka@gmail.com>

* fix combobox crash

* revert outside plate changes

---------

Co-authored-by: tamasmeszaros <meszaros.q@gmail.com>
Co-authored-by: YuSanka <yusanka@gmail.com>
2023-12-04 15:21:49 +00:00

311 lines
8.5 KiB
C++

#include "TabCtrl.hpp"
wxDEFINE_EVENT( wxEVT_TAB_SEL_CHANGING, wxCommandEvent );
wxDEFINE_EVENT( wxEVT_TAB_SEL_CHANGED, wxCommandEvent );
BEGIN_EVENT_TABLE(TabCtrl, StaticBox)
EVT_KEY_DOWN(TabCtrl::keyDown)
END_EVENT_TABLE()
/*
* Called by the system of by wxWidgets when the panel needs
* to be redrawn. You can also trigger this call by
* calling Refresh()/Update().
*/
#define TAB_BUTTON_SPACE 2
#define TAB_BUTTON_PADDING_X 2
#define TAB_BUTTON_PADDING_Y 2
#define TAB_BUTTON_PADDING TAB_BUTTON_PADDING_X, TAB_BUTTON_PADDING_Y
TabCtrl::TabCtrl(wxWindow * parent,
wxWindowID id,
const wxPoint & pos,
const wxSize & size,
long style)
: StaticBox(parent, id, pos, size, style)
{
#if 0
radius = 5;
#else
radius = 1;
#endif
border_width = 1;
SetBorderColor(0xcecece);
sizer = new wxBoxSizer(wxHORIZONTAL);
sizer->AddSpacer(10);
SetSizer(sizer);
Bind(wxEVT_COMMAND_BUTTON_CLICKED, &TabCtrl::buttonClicked, this);
//wxString reason;
//IsTransparentBackgroundSupported(&reason);
}
TabCtrl::~TabCtrl()
{}
int TabCtrl::GetSelection() const { return sel; }
void TabCtrl::SelectItem(int item)
{
if (item == sel || !sendTabCtrlEvent(true))
return;
if (sel >= 0) {
wxCommandEvent e(wxEVT_CHECKBOX);
auto b = btns[sel];
e.SetEventObject(b);
b->GetEventHandler()->ProcessEvent(e);
}
sel = item;
if (sel >= 0) {
wxCommandEvent e(wxEVT_CHECKBOX);
auto b = btns[sel];
e.SetEventObject(b);
b->GetEventHandler()->ProcessEvent(e);
}
sendTabCtrlEvent();
relayout();
Refresh();
}
void TabCtrl::Unselect()
{
SelectItem(-1);
}
void TabCtrl::Rescale()
{
for (auto & b : btns)
b->Rescale();
}
bool TabCtrl::SetFont(wxFont const& font)
{
StaticBox::SetFont(font);
bold = font.Bold();
for (size_t i = 0; i < btns.size(); ++i)
btns[i]->SetFont(i == sel ? bold : font);
return true;
}
int TabCtrl::AppendItem(const wxString &item,
int image, int selImage,
void * clientData)
{
Button * btn = new Button();
btn->Create(this, item, "", wxBORDER_NONE);
btn->SetFont(GetFont());
btn->SetTextColor(StateColor(
std::make_pair(0x6B6B6C, (int) StateColor::NotChecked),
std::make_pair(*wxLIGHT_GREY, (int) StateColor::Normal)));
btn->SetBackgroundColor(StateColor());
btn->SetCornerRadius(0);
btn->SetPaddingSize({TAB_BUTTON_PADDING});
btns.push_back(btn);
if (btns.size() > 1)
sizer->GetItem(sizer->GetItemCount() - 1)->SetMinSize({0, 0});
sizer->Add(btn, 0, wxALIGN_CENTER_VERTICAL | wxALL, TAB_BUTTON_SPACE * 2);
sizer->AddStretchSpacer(1);
relayout();
return btns.size() - 1;
}
bool TabCtrl::DeleteItem(int item)
{
return false;
}
void TabCtrl::DeleteAllItems()
{
sizer->Clear(true);
sizer->AddSpacer(10);
btns.clear();
if (sel >= 0) {
sel = -1;
sendTabCtrlEvent();
}
}
unsigned int TabCtrl::GetCount() const { return btns.size(); }
wxString TabCtrl::GetItemText(unsigned int item) const
{
return item < btns.size() ? btns[item]->GetLabel() : wxString{};
}
void TabCtrl::SetItemText(unsigned int item, wxString const &value)
{
if (item >= btns.size()) return;
btns[item]->SetLabel(value);
}
bool TabCtrl::GetItemBold(unsigned int item) const
{
if (item >= btns.size()) return false;
return btns[item]->GetFont() == bold;
}
void TabCtrl::SetItemBold(unsigned int item, bool bold)
{
if (item >= btns.size()) return;
btns[item]->SetFont(bold ? this->bold : GetFont());
btns[item]->Rescale();
}
void* TabCtrl::GetItemData(unsigned int item) const
{
if (item >= btns.size()) return nullptr;
return btns[item]->GetClientData();
}
void TabCtrl::SetItemData(unsigned int item, void* clientData)
{
if (item >= btns.size()) return;
btns[item]->SetClientData(clientData);
}
void TabCtrl::SetItemTextColour(unsigned int item, const StateColor &col)
{
if (item >= btns.size()) return;
btns[item]->SetTextColor(col);
}
int TabCtrl::GetFirstVisibleItem() const
{
return btns.size() == 0 ? -1 : 0;
}
int TabCtrl::GetNextVisible(int item) const
{
return ++item < btns.size() ? item : -1;
}
bool TabCtrl::IsVisible(unsigned int item) const
{
return true;
}
void TabCtrl::DoSetSize(int x, int y, int width, int height, int sizeFlags)
{
wxWindow::DoSetSize(x, y, width, height, sizeFlags);
if (sizeFlags & wxSIZE_USE_EXISTING) return;
relayout();
}
#ifdef __WIN32__
WXLRESULT TabCtrl::MSWWindowProc(WXUINT nMsg, WXWPARAM wParam, WXLPARAM lParam)
{
if (nMsg == WM_GETDLGCODE) { return DLGC_WANTARROWS; }
return wxWindow::MSWWindowProc(nMsg, wParam, lParam);
}
#endif
void TabCtrl::relayout()
{
int offset = 10;
int item = sel + 1;
int first = 0;
for (int i = 0; i < item; ++i)
offset += btns[i]->GetMinSize().x + TAB_BUTTON_SPACE * 2;
if (item < btns.size())
offset += btns[item]->GetMinSize().x + TAB_BUTTON_SPACE * 2;
int width = GetSize().x;
auto sizer = GetSizer();
for (int i = 0; i < btns.size(); ++i) {
auto size = btns[i]->GetMinSize().x + TAB_BUTTON_SPACE * 2;
if (i < sel && offset > width) {
sizer->Show(i * 2 + 1, false);
sizer->Show(i * 2 + 2, false);
offset -= size;
first = i + 1;
} else if (i <= item) {
sizer->Show(i * 2 + 1, true);
sizer->Show(i * 2 + 2, true);
} else if (offset <= width) {
sizer->Show(i * 2 + 1, true);
sizer->Show(i * 2 + 2, true);
offset += size;
item = i;
} else {
sizer->Show(i * 2 + 1, false);
sizer->Show(i * 2 + 2, false);
}
sizer->GetItem(i * 2 + 2)->SetMinSize({0, 0});
}
if (item >= btns.size())
-- item;
// Keep spacing 2 ~ 10 TAB_BUTTON_SPACE
int b = GetSize().x - offset - 10 - (item + 1 - first) * TAB_BUTTON_SPACE * 8;
sizer->GetItem(item * 2 + 2)->SetMinSize({b > 0 ? b : 0, 0});
sizer->Layout();
}
void TabCtrl::buttonClicked(wxCommandEvent &event)
{
SetFocus();
auto btn = event.GetEventObject();
auto iter = std::find(btns.begin(), btns.end(), btn);
SelectItem(iter == btns.end() ? -1 : iter - btns.begin());
}
void TabCtrl::keyDown(wxKeyEvent &event)
{
switch (event.GetKeyCode()) {
case WXK_UP:
case WXK_DOWN:
case WXK_LEFT:
case WXK_RIGHT:
if ((event.GetKeyCode() == WXK_UP || event.GetKeyCode() == WXK_LEFT) && GetSelection() > 0) {
SelectItem(GetSelection() - 1);
} else if ((event.GetKeyCode() == WXK_DOWN || event.GetKeyCode() == WXK_RIGHT) && GetSelection() + 1 < btns.size()) {
SelectItem(GetSelection() + 1);
}
break;
}
}
void TabCtrl::doRender(wxDC& dc)
{
wxSize size = GetSize();
int states = state_handler.states();
if (sel < 0) { return; }
auto x1 = btns[sel]->GetPosition().x;
auto x2 = x1 + btns[sel]->GetSize().x;
const int BS2 = (1 + border_width) / 2;
#if 0
const int BS = border_width / 2;
x1 -= TAB_BUTTON_SPACE; x2 += TAB_BUTTON_SPACE;
dc.SetPen(wxPen(border_color.colorForStates(states), border_width));
dc.SetBrush(*wxTRANSPARENT_BRUSH);
dc.DrawLine(0, size.y - BS2, x1 - radius + BS2, size.y - BS2);
dc.DrawArc(x1 - radius, size.y, x1, size.y - radius, x1 - radius, size.y - radius);
dc.DrawLine(x1, size.y - radius, x1, radius);
dc.DrawArc(x1 + radius, 0, x1, radius, x1 + radius, radius);
dc.DrawLine(x1 + radius, BS, x2 - radius, BS);
dc.DrawArc(x2, radius, x2 - radius, 0, x2 - radius, radius);
dc.DrawLine(x2, radius, x2, size.y - radius);
dc.DrawArc(x2, size.y - radius, x2 + radius, size.y, x2 + radius, size.y - radius);
dc.DrawLine(x2 + radius - BS2, size.y - BS2, size.x, size.y - BS2);
#else
dc.SetPen(wxPen(border_color.colorForStates(states), border_width));
dc.DrawLine(0, size.y - BS2, size.x, size.y - BS2);
wxColour c(0xf2, 0x75, 0x4e, 0xff);
dc.SetPen(wxPen(c, 1));
dc.SetBrush(c);
dc.DrawRoundedRectangle(x1 - radius, size.y - BS2 - border_width * 3, x2 + radius * 2 - x1, border_width * 3, radius);
#endif
}
bool TabCtrl::sendTabCtrlEvent(bool changing)
{
wxCommandEvent event(changing ? wxEVT_TAB_SEL_CHANGING : wxEVT_TAB_SEL_CHANGED, GetId());
event.SetEventObject(this);
event.SetInt(sel);
GetEventHandler()->ProcessEvent(event);
return true;
}