diff options
author | Pavel Labath <pavelo@centrum.sk> | 2011-06-11 11:00:45 (GMT) |
---|---|---|
committer | Pavel Labath <pavelo@centrum.sk> | 2013-02-16 23:49:23 (GMT) |
commit | eb0eef14134ee667c60f75f53de4e24950f3c117 (patch) | |
tree | 58b35842e1f84666373478bca3386be037a7a019 /src/FocusControl.cc | |
parent | 3b7c1a3c220b7ccec0dee7804d36dabfe81449c4 (diff) | |
download | fluxbox_pavel-eb0eef14134ee667c60f75f53de4e24950f3c117.zip fluxbox_pavel-eb0eef14134ee667c60f75f53de4e24950f3c117.tar.bz2 |
Simplify FbTk::Resource template class
by outsourcing the conversion from string/lua to the specific type (and back) to a separate
class. This change touches a lot of files because the interface of FbTk::Resource changed
slightly. However, the changes are minor.
Diffstat (limited to 'src/FocusControl.cc')
-rw-r--r-- | src/FocusControl.cc | 89 |
1 files changed, 11 insertions, 78 deletions
diff --git a/src/FocusControl.cc b/src/FocusControl.cc index df07806..8f1a94f 100644 --- a/src/FocusControl.cc +++ b/src/FocusControl.cc | |||
@@ -617,86 +617,19 @@ void FocusControl::setFocusedWindow(WinClient *client) { | |||
617 | namespace FbTk { | 617 | namespace FbTk { |
618 | 618 | ||
619 | template<> | 619 | template<> |
620 | std::string FbTk::Resource<FocusControl::FocusModel>::getString() const { | 620 | const EnumTraits<FocusControl::FocusModel>::Pair EnumTraits<FocusControl::FocusModel>::s_map[] = { |
621 | switch (m_value) { | 621 | { "MouseFocus", FocusControl::MOUSEFOCUS }, |
622 | case FocusControl::MOUSEFOCUS: | 622 | { "StrictMouseFocus", FocusControl::STRICTMOUSEFOCUS }, |
623 | return string("MouseFocus"); | 623 | { "ClickFocus", FocusControl::CLICKFOCUS }, |
624 | case FocusControl::STRICTMOUSEFOCUS: | 624 | { NULL, FocusControl::CLICKFOCUS } |
625 | return string("StrictMouseFocus"); | 625 | }; |
626 | case FocusControl::CLICKFOCUS: | ||
627 | return string("ClickFocus"); | ||
628 | } | ||
629 | // default string | ||
630 | return string("ClickFocus"); | ||
631 | } | ||
632 | |||
633 | template<> | ||
634 | void FbTk::Resource<FocusControl::FocusModel>:: | ||
635 | setFromString(char const *strval) { | ||
636 | if (strcasecmp(strval, "MouseFocus") == 0) | ||
637 | m_value = FocusControl::MOUSEFOCUS; | ||
638 | else if (strcasecmp(strval, "StrictMouseFocus") == 0) | ||
639 | m_value = FocusControl::STRICTMOUSEFOCUS; | ||
640 | else if (strcasecmp(strval, "ClickToFocus") == 0) | ||
641 | m_value = FocusControl::CLICKFOCUS; | ||
642 | else | ||
643 | setDefaultValue(); | ||
644 | } | ||
645 | |||
646 | template<> | ||
647 | void FbTk::Resource<FocusControl::FocusModel>::setFromLua(lua::state &l) { | ||
648 | lua::stack_sentry s(l, -1); | ||
649 | if(l.isstring(-1)) | ||
650 | setFromString(l.tostring(-1).c_str()); | ||
651 | else | ||
652 | setDefaultValue(); | ||
653 | l.pop(); | ||
654 | } | ||
655 | |||
656 | template<> | ||
657 | void FbTk::Resource<FocusControl::FocusModel>::pushToLua(lua::state &l) const { | ||
658 | l.pushstring(getString()); | ||
659 | } | ||
660 | |||
661 | 626 | ||
662 | template<> | 627 | template<> |
663 | std::string FbTk::Resource<FocusControl::TabFocusModel>::getString() const { | 628 | const EnumTraits<FocusControl::TabFocusModel>::Pair EnumTraits<FocusControl::TabFocusModel>::s_map[] = { |
664 | switch (m_value) { | 629 | { "SloppyTabFocus", FocusControl::MOUSETABFOCUS }, |
665 | case FocusControl::MOUSETABFOCUS: | 630 | { "ClickToTabFocus", FocusControl::CLICKTABFOCUS }, |
666 | return string("SloppyTabFocus"); | 631 | { NULL, FocusControl::CLICKTABFOCUS } |
667 | case FocusControl::CLICKTABFOCUS: | 632 | }; |
668 | return string("ClickToTabFocus"); | ||
669 | } | ||
670 | // default string | ||
671 | return string("ClickToTabFocus"); | ||
672 | } | ||
673 | |||
674 | template<> | ||
675 | void FbTk::Resource<FocusControl::TabFocusModel>:: | ||
676 | setFromString(char const *strval) { | ||
677 | |||
678 | if (strcasecmp(strval, "SloppyTabFocus") == 0 ) | ||
679 | m_value = FocusControl::MOUSETABFOCUS; | ||
680 | else if (strcasecmp(strval, "ClickToTabFocus") == 0) | ||
681 | m_value = FocusControl::CLICKTABFOCUS; | ||
682 | else | ||
683 | setDefaultValue(); | ||
684 | } | ||
685 | |||
686 | template<> | ||
687 | void FbTk::Resource<FocusControl::TabFocusModel>::setFromLua(lua::state &l) { | ||
688 | lua::stack_sentry s(l, -1); | ||
689 | if(l.isstring(-1)) | ||
690 | setFromString(l.tostring(-1).c_str()); | ||
691 | else | ||
692 | setDefaultValue(); | ||
693 | l.pop(); | ||
694 | } | ||
695 | |||
696 | template<> | ||
697 | void FbTk::Resource<FocusControl::TabFocusModel>::pushToLua(lua::state &l) const { | ||
698 | l.pushstring(getString()); | ||
699 | } | ||
700 | 633 | ||
701 | } // end namespace FbTk | 634 | } // end namespace FbTk |
702 | 635 | ||