OrcaSlicer latest
OrcaSlicer
Loading...
Searching...
No Matches
StateHandler Class Reference

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

Inheritance diagram for StateHandler:
Collaboration diagram for StateHandler:

Public Types

enum  State {
  Enabled = 1 , Checked = 2 , Focused = 4 , Hovered = 8 ,
  Pressed = 16 , Disabled = 1 << 16 , NotChecked = 2 << 16 , NotFocused = 4 << 16 ,
  NotHovered = 8 << 16 , NotPressed = 16 << 16
}

Public Member Functions

 StateHandler (wxWindow *owner)
 ~StateHandler ()
void attach (StateColor const &color)
void attach (std::vector< StateColor const * > const &colors)
void attach_child (wxWindow *child)
void remove_child (wxWindow *child)
void update_binds ()
int states () const
void set_state (int state, int mask)

Private Member Functions

 StateHandler (StateHandler *parent, wxWindow *owner)
void changed (wxEvent &event)
void changed (int state2)

Private Attributes

wxWindow * owner_
std::vector< StateColor const * > colors_
int bind_states_ = 0
int states_ = 0
int states2_ = 0
std::vector< std::unique_ptr< StateHandler > > children_
StateHandler * parent_ = nullptr

Detailed Description

Member Enumeration Documentation

◆ State

Enumerator
Enabled 
Checked 
Focused 
Hovered 
Pressed 
Disabled 
NotChecked 
NotFocused 
NotHovered 
NotPressed 
17 {
18 Enabled = 1,
19 Checked = 2,
20 Focused = 4,
21 Hovered = 8,
22 Pressed = 16,
23 Disabled = 1 << 16,
24 NotChecked = 2 << 16,
25 NotFocused = 4 << 16,
26 NotHovered = 8 << 16,
27 NotPressed = 16 << 16,
28 };
@ NotPressed
Definition StateHandler.hpp:27
@ Disabled
Definition StateHandler.hpp:23
@ NotFocused
Definition StateHandler.hpp:25
@ NotChecked
Definition StateHandler.hpp:24
@ Pressed
Definition StateHandler.hpp:22
@ NotHovered
Definition StateHandler.hpp:26
@ Hovered
Definition StateHandler.hpp:21
@ Checked
Definition StateHandler.hpp:19
@ Focused
Definition StateHandler.hpp:20
@ Enabled
Definition StateHandler.hpp:18

Constructor & Destructor Documentation

◆ StateHandler() [1/2]

StateHandler::StateHandler ( wxWindow * owner)
11 : owner_(owner)
12{
13 owner_->PushEventHandler(this);
14 if (owner->IsEnabled())
16 if (owner->HasFocus())
18}
wxWindow * owner_
Definition StateHandler.hpp:58
int states_
Definition StateHandler.hpp:61

References Enabled, Focused, owner_, and states_.

Referenced by StateHandler(), and attach_child().

Here is the caller graph for this function:

◆ ~StateHandler()

StateHandler::~StateHandler ( )
20{ owner_->RemoveEventHandler(this); }

References owner_.

◆ StateHandler() [2/2]

StateHandler::StateHandler ( StateHandler * parent,
wxWindow * owner )
private
91 : StateHandler(owner)
92{
94 parent_ = parent;
95}
StateHandler * parent_
Definition StateHandler.hpp:64
StateHandler(wxWindow *owner)
Definition StateHandler.cpp:10

References StateHandler(), Enabled, parent_, and states_.

Here is the call graph for this function:

Member Function Documentation

◆ attach() [1/2]

void StateHandler::attach ( StateColor const & color)
23{
24 colors_.push_back(&color);
25}
std::vector< StateColor const * > colors_
Definition StateHandler.hpp:59

References colors_.

◆ attach() [2/2]

void StateHandler::attach ( std::vector< StateColor const * > const & colors)
28{
29 colors_.insert(colors_.end(), colors.begin(), colors.end());
30}

References colors_.

◆ attach_child()

void StateHandler::attach_child ( wxWindow * child)
33{
34 auto ch = new StateHandler(this, child);
35 children_.emplace_back(ch);
36 ch->update_binds();
37 states2_ |= ch->states();
38}
int states2_
Definition StateHandler.hpp:62
std::vector< std::unique_ptr< StateHandler > > children_
Definition StateHandler.hpp:63

References StateHandler(), children_, and states2_.

Here is the call graph for this function:

◆ changed() [1/2]

void StateHandler::changed ( int state2)
private
130{
131 int old = states2_;
132 states2_ = 0;
133 for (auto &c : children_) states2_ |= c->states();
134 if (old != states2_ && (old | states_) != (states_ | states2_)) {
135 if (parent_)
136 parent_->changed(states_ | states2_);
137 else
138 owner_->Refresh();
139 }
140}

References children_, owner_, parent_, states2_, and states_.

◆ changed() [2/2]

void StateHandler::changed ( wxEvent & event)
private
98{
99 event.Skip();
100 wxEventType events[] = {EVT_ENABLE_CHANGED, wxEVT_CHECKBOX, wxEVT_SET_FOCUS, wxEVT_ENTER_WINDOW, wxEVT_LEFT_DOWN};
101 wxEventType events2[] = {0, 0, wxEVT_KILL_FOCUS, wxEVT_LEAVE_WINDOW, wxEVT_LEFT_UP};
102 int old = states_;
103 // some events are from another window (ex: text_ctrl of TextInput), save state in states2_ to avoid conflicts
104 for (int i = 0; i < 5; ++i) {
105 if (events2[i]) {
106 if (event.GetEventType() == events[i]) {
107 states_ |= 1 << i;
108 break;
109 } else if (event.GetEventType() == events2[i]) {
110 states_ &= ~(1 << i);
111 break;
112 }
113 }
114 else {
115 if (event.GetEventType() == events[i]) {
116 states_ ^= (1 << i);
117 break;
118 }
119 }
120 }
121 if (old != states_ && (old | states2_) != (states_ | states2_)) {
122 if (parent_)
123 parent_->changed(states_ | states2_);
124 else
125 owner_->Refresh();
126 }
127}

References owner_, parent_, states2_, and states_.

Referenced by update_binds().

Here is the caller graph for this function:

◆ remove_child()

void StateHandler::remove_child ( wxWindow * child)
41{
42 children_.erase(std::remove_if(children_.begin(), children_.end(),
43 [child](auto &c) { return c->owner_ == child; }), children_.end());
44 states2_ = 0;
45 for (auto & c : children_) states2_ |= c->states();
46}

References children_, and states2_.

◆ set_state()

void StateHandler::set_state ( int state,
int mask )
78{
79 if ((states_ & mask) == (state & mask)) return;
80 int old = states_;
81 states_ = (states_ & ~mask) | (state & mask);
82 if (old != states_ && (old | states2_) != (states_ | states2_)) {
83 if (parent_)
84 parent_->changed(states_ | states2_);
85 else
86 owner_->Refresh();
87 }
88}

References owner_, parent_, states2_, and states_.

◆ states()

int StateHandler::states ( ) const
inline
46{ return states_ | states2_; }

References states2_, and states_.

Referenced by update_binds().

Here is the caller graph for this function:

◆ update_binds()

void StateHandler::update_binds ( )
49{
50 int bind_states = parent_ ? (parent_->bind_states_ & ~Enabled) : 0;
51 for (auto c : colors_) {
52 bind_states |= c->states();
53 }
54 bind_states = bind_states | (bind_states >> 16);
55 int diff = bind_states ^ bind_states_;
57 wxEventType events[] = {EVT_ENABLE_CHANGED, wxEVT_CHECKBOX, wxEVT_SET_FOCUS, wxEVT_ENTER_WINDOW, wxEVT_LEFT_DOWN};
58 wxEventType events2[] = {0, 0, wxEVT_KILL_FOCUS, wxEVT_LEAVE_WINDOW, wxEVT_LEFT_UP};
59 for (int i = 0; i < 5; ++i) {
60 int s = states[i];
61 if (diff & s) {
62 if (bind_states & s) {
63 Bind(events[i], &StateHandler::changed, this);
64 if (events2[i])
65 Bind(events2[i], &StateHandler::changed, this);
66 } else {
67 Unbind(events[i], &StateHandler::changed, this);
68 if (events2[i])
69 owner_->Unbind(events2[i], &StateHandler::changed, this);
70 }
71 }
72 }
73 bind_states_ = bind_states;
74 for (auto &c : children_) c->update_binds();
75}
int states() const
Definition StateHandler.hpp:46
int bind_states_
Definition StateHandler.hpp:60
State
Definition StateHandler.hpp:17
void changed(wxEvent &event)
Definition StateHandler.cpp:97
Slic3r::Polygons diff(const Slic3r::Polygon &subject, const Slic3r::Polygon &clip, ApplySafetyOffset do_safety_offset)
Definition ClipperUtils.cpp:731

References bind_states_, changed(), Checked, children_, colors_, Enabled, Focused, Hovered, owner_, parent_, Pressed, and states().

Here is the call graph for this function:

Member Data Documentation

◆ bind_states_

int StateHandler::bind_states_ = 0
private

Referenced by update_binds().

◆ children_

std::vector<std::unique_ptr<StateHandler> > StateHandler::children_
private

◆ colors_

std::vector<StateColor const *> StateHandler::colors_
private

Referenced by attach(), attach(), and update_binds().

◆ owner_

wxWindow* StateHandler::owner_
private

◆ parent_

StateHandler* StateHandler::parent_ = nullptr
private

◆ states2_

int StateHandler::states2_ = 0
private

◆ states_

int StateHandler::states_ = 0
private

The documentation for this class was generated from the following files:
  • /home/runner/work/OrcaSlicer/OrcaSlicer/src/slic3r/GUI/Widgets/StateHandler.hpp
  • /home/runner/work/OrcaSlicer/OrcaSlicer/src/slic3r/GUI/Widgets/StateHandler.cpp