mirror of
https://github.com/OrcaSlicer/OrcaSlicer.git
synced 2026-10-08 00:01:09 +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
420 lines
13 KiB
C++
420 lines
13 KiB
C++
#ifndef slic3r_Tabbook_hpp_
|
|
#define slic3r_Tabbook_hpp_
|
|
|
|
//#ifdef _WIN32
|
|
|
|
#include <cstddef>
|
|
#include <string>
|
|
#include <vector>
|
|
#include <wx/bookctrl.h>
|
|
#include <wx/event.h>
|
|
#include <wx/gdicmn.h>
|
|
#include <wx/debug.h>
|
|
#include <wx/chartype.h>
|
|
#include <wx/object.h>
|
|
#include <wx/sizer.h>
|
|
#include <wx/string.h>
|
|
#include <wx/window.h>
|
|
#include <wx/withimages.h>
|
|
#include "wxExtensions.hpp"
|
|
#include <wx/defs.h>
|
|
#include <wx/notebook.h>
|
|
|
|
class wxObject;
|
|
class wxStaticText;
|
|
|
|
|
|
class TabButton;
|
|
|
|
// custom message the ButtonsListCtrl sends to its parent (Notebook) to notify a selection change:
|
|
wxDECLARE_EVENT(wxCUSTOMEVT_TABBOOK_SEL_CHANGED, wxCommandEvent);
|
|
|
|
class TabButtonsListCtrl : public wxControl
|
|
{
|
|
public:
|
|
// BBS
|
|
TabButtonsListCtrl(wxWindow *parent, wxBoxSizer *side_tools = NULL);
|
|
~TabButtonsListCtrl() {}
|
|
|
|
void OnPaint(wxPaintEvent&);
|
|
void SetSelection(int sel);
|
|
void showNewTag(int sel, bool show = false);
|
|
void Rescale();
|
|
bool InsertPage(size_t n, const wxString& text, bool bSelect = false, const std::string& bmp_name = "");
|
|
void RemovePage(size_t n);
|
|
bool SetPageImage(size_t n, const std::string& bmp_name);
|
|
void SetPageText(size_t n, const wxString& strText);
|
|
wxString GetPageText(size_t n) const;
|
|
const wxSize& GetPaddingSize(size_t n);
|
|
void SetPaddingSize(const wxSize& size);
|
|
void SetFooterText(const wxString& text);
|
|
TabButton* pageButton;
|
|
|
|
private:
|
|
wxFlexGridSizer* m_buttons_sizer;
|
|
wxBoxSizer* m_sizer;
|
|
ScalableBitmap m_arrow_img;
|
|
std::vector<TabButton*> m_pageButtons;
|
|
int m_selection {-1};
|
|
int m_btn_margin;
|
|
int m_line_margin;
|
|
wxStaticText* m_footer_text {nullptr};
|
|
};
|
|
|
|
class Tabbook: public wxBookCtrlBase
|
|
{
|
|
public:
|
|
Tabbook(wxWindow * parent,
|
|
wxWindowID winid = wxID_ANY,
|
|
const wxPoint & pos = wxDefaultPosition,
|
|
const wxSize & size = wxDefaultSize,
|
|
// BBS
|
|
wxBoxSizer* side_tools = NULL,
|
|
long style = 0)
|
|
{
|
|
Init();
|
|
Create(parent, winid, pos, size, side_tools, style);
|
|
}
|
|
|
|
bool Create(wxWindow * parent,
|
|
wxWindowID winid = wxID_ANY,
|
|
const wxPoint & pos = wxDefaultPosition,
|
|
const wxSize & size = wxDefaultSize,
|
|
// BBS
|
|
wxBoxSizer* side_tools = NULL,
|
|
long style = 0)
|
|
{
|
|
if (!wxBookCtrlBase::Create(parent, winid, pos, size, style))
|
|
return false;
|
|
|
|
m_bookctrl = new TabButtonsListCtrl(this, side_tools);
|
|
|
|
wxSizer* mainSizer = new wxBoxSizer(IsVertical() ? wxVERTICAL : wxHORIZONTAL);
|
|
|
|
if (style & wxBK_RIGHT || style & wxBK_BOTTOM)
|
|
mainSizer->Add(0, 0, 1, wxEXPAND, 0);
|
|
|
|
m_controlSizer = new wxBoxSizer(IsVertical() ? wxHORIZONTAL : wxVERTICAL);
|
|
m_controlSizer->Add(m_bookctrl, wxSizerFlags(0).Expand());
|
|
wxSizerFlags flags;
|
|
if (IsVertical())
|
|
flags.Expand();
|
|
else
|
|
flags.Expand();
|
|
mainSizer->Add(m_controlSizer, flags.Border(wxALL, m_controlMargin));
|
|
SetSizer(mainSizer);
|
|
|
|
this->Bind(wxCUSTOMEVT_TABBOOK_SEL_CHANGED, [this](wxCommandEvent& evt)
|
|
{
|
|
if (int page_idx = evt.GetId(); page_idx >= 0)
|
|
SetSelection(page_idx);
|
|
});
|
|
|
|
this->Bind(wxEVT_NAVIGATION_KEY, &Tabbook::OnNavigationKey, this);
|
|
|
|
return true;
|
|
}
|
|
|
|
|
|
// Methods specific to this class.
|
|
|
|
// A method allowing to add a new page without any label (which is unused
|
|
// by this control) and show it immediately.
|
|
bool ShowNewPage(wxWindow * page)
|
|
{
|
|
return AddPage(page, wxString());
|
|
}
|
|
|
|
// Set effect to use for showing/hiding pages.
|
|
void SetEffects(wxShowEffect showEffect, wxShowEffect hideEffect)
|
|
{
|
|
m_showEffect = showEffect;
|
|
m_hideEffect = hideEffect;
|
|
}
|
|
|
|
// Or the same effect for both of them.
|
|
void SetEffect(wxShowEffect effect)
|
|
{
|
|
SetEffects(effect, effect);
|
|
}
|
|
|
|
// And the same for time outs.
|
|
void SetEffectsTimeouts(unsigned showTimeout, unsigned hideTimeout)
|
|
{
|
|
m_showTimeout = showTimeout;
|
|
m_hideTimeout = hideTimeout;
|
|
}
|
|
|
|
void SetEffectTimeout(unsigned timeout)
|
|
{
|
|
SetEffectsTimeouts(timeout, timeout);
|
|
}
|
|
|
|
|
|
// Implement base class pure virtual methods.
|
|
|
|
bool AddPage(wxWindow* page,
|
|
const wxString& text,
|
|
bool bSelect = false,
|
|
int imageId = NO_IMAGE) override
|
|
{
|
|
DoInvalidateBestSize();
|
|
return InsertPage(GetPageCount(), page, text, bSelect, imageId);
|
|
}
|
|
|
|
//// Page management
|
|
virtual bool InsertPage(size_t n,
|
|
wxWindow * page,
|
|
const wxString & text,
|
|
bool bSelect = false,
|
|
int imageId = NO_IMAGE) override
|
|
{
|
|
if (!wxBookCtrlBase::InsertPage(n, page, text, bSelect, imageId))
|
|
return false;
|
|
|
|
GetBtnsListCtrl()->InsertPage(n, text, bSelect);
|
|
|
|
if (!DoSetSelectionAfterInsertion(n, bSelect))
|
|
page->Hide();
|
|
|
|
return true;
|
|
}
|
|
|
|
bool RemovePage(size_t n) override
|
|
{
|
|
if (!wxBookCtrlBase::RemovePage(n))
|
|
return false;
|
|
|
|
SetSelection(0);
|
|
return true;
|
|
}
|
|
|
|
virtual int SetSelection(size_t n) override
|
|
{
|
|
GetBtnsListCtrl()->SetSelection(n);
|
|
int ret = DoSetSelection(n, SetSelection_SendEvent);
|
|
|
|
// check that only the selected page is visible and others are hidden:
|
|
for (size_t page = 0; page < m_pages.size(); page++) {
|
|
wxWindow* win_a = GetPage(page);
|
|
wxWindow* win_b = GetPage(n);
|
|
if (page != n && GetPage(page) != GetPage(n)) {
|
|
m_pages[page]->Hide();
|
|
}
|
|
}
|
|
|
|
return ret;
|
|
}
|
|
|
|
virtual int ChangeSelection(size_t n) override
|
|
{
|
|
GetBtnsListCtrl()->SetSelection(n);
|
|
return DoSetSelection(n);
|
|
}
|
|
|
|
// Neither labels nor images are supported but we still store the labels
|
|
// just in case the user code attaches some importance to them.
|
|
virtual bool SetPageText(size_t n, const wxString & strText) override
|
|
{
|
|
wxCHECK_MSG(n < GetPageCount(), false, wxS("Invalid page"));
|
|
|
|
GetBtnsListCtrl()->SetPageText(n, strText);
|
|
|
|
return true;
|
|
}
|
|
|
|
virtual wxString GetPageText(size_t n) const override
|
|
{
|
|
wxCHECK_MSG(n < GetPageCount(), wxString(), wxS("Invalid page"));
|
|
return GetBtnsListCtrl()->GetPageText(n);
|
|
}
|
|
|
|
virtual bool SetPageImage(size_t WXUNUSED(n), int WXUNUSED(imageId)) override
|
|
{
|
|
return false;
|
|
}
|
|
|
|
virtual int GetPageImage(size_t WXUNUSED(n)) const override
|
|
{
|
|
return NO_IMAGE;
|
|
}
|
|
|
|
bool SetPageImage(size_t n, const std::string& bmp_name)
|
|
{
|
|
return GetBtnsListCtrl()->SetPageImage(n, bmp_name);
|
|
}
|
|
|
|
// Override some wxWindow methods too.
|
|
virtual void SetFocus() override
|
|
{
|
|
wxWindow* const page = GetCurrentPage();
|
|
if (page)
|
|
page->SetFocus();
|
|
}
|
|
|
|
TabButtonsListCtrl *GetBtnsListCtrl() const { return static_cast<TabButtonsListCtrl *>(m_bookctrl); }
|
|
|
|
void Rescale()
|
|
{
|
|
GetBtnsListCtrl()->Rescale();
|
|
}
|
|
|
|
void SetFooterText(const wxString& text)
|
|
{
|
|
GetBtnsListCtrl()->SetFooterText(text);
|
|
}
|
|
|
|
void OnNavigationKey(wxNavigationKeyEvent& event)
|
|
{
|
|
if (event.IsWindowChange()) {
|
|
// change pages
|
|
//AdvanceSelection(event.GetDirection());
|
|
this->GetGrandParent()->HandleWindowEvent(event);
|
|
}
|
|
else {
|
|
// we get this event in 3 cases
|
|
//
|
|
// a) one of our pages might have generated it because the user TABbed
|
|
// out from it in which case we should propagate the event upwards and
|
|
// our parent will take care of setting the focus to prev/next sibling
|
|
//
|
|
// or
|
|
//
|
|
// b) the parent panel wants to give the focus to us so that we
|
|
// forward it to our selected page. We can't deal with this in
|
|
// OnSetFocus() because we don't know which direction the focus came
|
|
// from in this case and so can't choose between setting the focus to
|
|
// first or last panel child
|
|
//
|
|
// or
|
|
//
|
|
// c) we ourselves (see MSWTranslateMessage) generated the event
|
|
//
|
|
wxWindow* const parent = GetParent();
|
|
|
|
// the wxObject* casts are required to avoid MinGW GCC 2.95.3 ICE
|
|
const bool isFromParent = event.GetEventObject() == (wxObject*)parent;
|
|
const bool isFromSelf = event.GetEventObject() == (wxObject*)this;
|
|
const bool isForward = event.GetDirection();
|
|
|
|
if (isFromSelf && !isForward)
|
|
{
|
|
// focus is currently on notebook tab and should leave
|
|
// it backwards (Shift-TAB)
|
|
event.SetCurrentFocus(this);
|
|
parent->HandleWindowEvent(event);
|
|
}
|
|
else if (isFromParent || isFromSelf)
|
|
{
|
|
// no, it doesn't come from child, case (b) or (c): forward to a
|
|
// page but only if entering notebook page (i.e. direction is
|
|
// backwards (Shift-TAB) comething from out-of-notebook, or
|
|
// direction is forward (TAB) from ourselves),
|
|
if (m_selection != wxNOT_FOUND &&
|
|
(!event.GetDirection() || isFromSelf))
|
|
{
|
|
// so that the page knows that the event comes from it's parent
|
|
// and is being propagated downwards
|
|
event.SetEventObject(this);
|
|
|
|
wxWindow* page = m_pages[m_selection];
|
|
if (!page->HandleWindowEvent(event))
|
|
{
|
|
page->SetFocus();
|
|
}
|
|
//else: page manages focus inside it itself
|
|
}
|
|
else // otherwise set the focus to the notebook itself
|
|
{
|
|
SetFocus();
|
|
}
|
|
}
|
|
else
|
|
{
|
|
// it comes from our child, case (a), pass to the parent, but only
|
|
// if the direction is forwards. Otherwise set the focus to the
|
|
// notebook itself. The notebook is always the 'first' control of a
|
|
// page.
|
|
if (!isForward)
|
|
{
|
|
SetFocus();
|
|
}
|
|
else if (parent)
|
|
{
|
|
event.SetCurrentFocus(this);
|
|
parent->HandleWindowEvent(event);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
protected:
|
|
virtual void UpdateSelectedPage(size_t WXUNUSED(newsel)) override
|
|
{
|
|
// Nothing to do here, but must be overridden to avoid the assert in
|
|
// the base class version.
|
|
}
|
|
|
|
virtual wxBookCtrlEvent * CreatePageChangingEvent() const override
|
|
{
|
|
return new wxBookCtrlEvent(wxEVT_BOOKCTRL_PAGE_CHANGING,
|
|
GetId());
|
|
}
|
|
|
|
virtual void MakeChangedEvent(wxBookCtrlEvent & event) override
|
|
{
|
|
event.SetEventType(wxEVT_BOOKCTRL_PAGE_CHANGED);
|
|
}
|
|
|
|
virtual wxWindow * DoRemovePage(size_t page) override
|
|
{
|
|
wxWindow* const win = wxBookCtrlBase::DoRemovePage(page);
|
|
if (win)
|
|
{
|
|
GetBtnsListCtrl()->RemovePage(page);
|
|
DoSetSelectionAfterRemoval(page);
|
|
}
|
|
|
|
return win;
|
|
}
|
|
|
|
virtual void DoSize() override
|
|
{
|
|
wxWindow* const page = GetCurrentPage();
|
|
if (page)
|
|
page->SetSize(GetPageRect());
|
|
}
|
|
|
|
virtual void DoShowPage(wxWindow * page, bool show) override
|
|
{
|
|
if (show)
|
|
page->ShowWithEffect(m_showEffect, m_showTimeout);
|
|
else
|
|
page->HideWithEffect(m_hideEffect, m_hideTimeout);
|
|
}
|
|
|
|
private:
|
|
void Init()
|
|
{
|
|
// We don't need any border as we don't have anything to separate the
|
|
// page contents from.
|
|
SetInternalBorder(0);
|
|
|
|
// No effects by default.
|
|
m_showEffect =
|
|
m_hideEffect = wxSHOW_EFFECT_NONE;
|
|
|
|
m_showTimeout =
|
|
m_hideTimeout = 0;
|
|
}
|
|
|
|
wxShowEffect m_showEffect,
|
|
m_hideEffect;
|
|
|
|
unsigned m_showTimeout,
|
|
m_hideTimeout;
|
|
|
|
};
|
|
//#endif // _WIN32
|
|
#endif // slic3r_Tabbook_hpp_
|