| 453 | } |
| 454 | |
| 455 | void Widget::SetState( State state ) { |
| 456 | // Do nothing if state wouldn't change. |
| 457 | if( GetState() == state ) { |
| 458 | return; |
| 459 | } |
| 460 | |
| 461 | auto old_state = GetState(); |
| 462 | |
| 463 | // Store the new state. |
| 464 | m_state = state; |
| 465 | |
| 466 | auto emit_state_change = false; |
| 467 | |
| 468 | // If HandleStateChange() changed the state, do not call observer, will be |
| 469 | // done from there too. |
| 470 | if( GetState() != old_state ) { |
| 471 | HandleStateChange( static_cast<State>( old_state ) ); |
| 472 | emit_state_change = true; |
| 473 | } |
| 474 | |
| 475 | if( state == State::ACTIVE ) { |
| 476 | GrabFocus( shared_from_this() ); |
| 477 | SetActiveWidget( shared_from_this() ); |
| 478 | } |
| 479 | else if( old_state == State::ACTIVE ) { |
| 480 | SetActiveWidget( Ptr() ); |
| 481 | } |
| 482 | |
| 483 | if( emit_state_change ) { |
| 484 | GetSignals().Emit( OnStateChange ); |
| 485 | } |
| 486 | } |
| 487 | |
| 488 | Widget::State Widget::GetState() const { |
| 489 | return m_state; |