diff options
author | Pavel Labath <pavelo@centrum.sk> | 2011-06-11 11:00:45 (GMT) |
---|---|---|
committer | Pavel Labath <pavelo@centrum.sk> | 2011-06-15 23:12:25 (GMT) |
commit | cd9df3b8144c4c41f7b57f0075fbb98ef7561296 (patch) | |
tree | 10ffc1692e4afbcb2c74b9db8c8a44b434ef62ca /src/FocusControl.cc | |
parent | 787c7a994d4328a9c90a037dd464f8007351b0c0 (diff) | |
download | fluxbox_pavel-cd9df3b8144c4c41f7b57f0075fbb98ef7561296.zip fluxbox_pavel-cd9df3b8144c4c41f7b57f0075fbb98ef7561296.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 abedcf2..4f3b390 100644 --- a/src/FocusControl.cc +++ b/src/FocusControl.cc | |||
@@ -599,86 +599,19 @@ void FocusControl::setFocusedWindow(WinClient *client) { | |||
599 | namespace FbTk { | 599 | namespace FbTk { |
600 | 600 | ||
601 | template<> | 601 | template<> |
602 | std::string FbTk::Resource<FocusControl::FocusModel>::getString() const { | 602 | const EnumTraits<FocusControl::FocusModel>::Pair EnumTraits<FocusControl::FocusModel>::s_map[] = { |
603 | switch (m_value) { | 603 | { "MouseFocus", FocusControl::MOUSEFOCUS }, |
604 | case FocusControl::MOUSEFOCUS: | 604 | { "StrictMouseFocus", FocusControl::STRICTMOUSEFOCUS }, |
605 | return string("MouseFocus"); | 605 | { "ClickFocus", FocusControl::CLICKFOCUS }, |
606 | case FocusControl::STRICTMOUSEFOCUS: | 606 | { NULL, FocusControl::CLICKFOCUS } |
607 | return string("StrictMouseFocus"); | 607 | }; |
608 | case FocusControl::CLICKFOCUS: | ||
609 | return string("ClickFocus"); | ||
610 | } | ||
611 | // default string | ||
612 | return string("ClickFocus"); | ||
613 | } | ||
614 | |||
615 | template<> | ||
616 | void FbTk::Resource<FocusControl::FocusModel>:: | ||
617 | setFromString(char const *strval) { | ||
618 | if (strcasecmp(strval, "MouseFocus") == 0) | ||
619 | m_value = FocusControl::MOUSEFOCUS; | ||
620 | else if (strcasecmp(strval, "StrictMouseFocus") == 0) | ||
621 | m_value = FocusControl::STRICTMOUSEFOCUS; | ||
622 | else if (strcasecmp(strval, "ClickToFocus") == 0) | ||
623 | m_value = FocusControl::CLICKFOCUS; | ||
624 | else | ||
625 | setDefaultValue(); | ||
626 | } | ||
627 | |||
628 | template<> | ||
629 | void FbTk::Resource<FocusControl::FocusModel>::setFromLua(lua::state &l) { | ||
630 | lua::stack_sentry s(l, -1); | ||
631 | if(l.isstring(-1)) | ||
632 | setFromString(l.tostring(-1).c_str()); | ||
633 | else | ||
634 | setDefaultValue(); | ||
635 | l.pop(); | ||
636 | } | ||
637 | |||
638 | template<> | ||
639 | void FbTk::Resource<FocusControl::FocusModel>::pushToLua(lua::state &l) const { | ||
640 | l.pushstring(getString()); | ||
641 | } | ||
642 | |||
643 | 608 | ||
644 | template<> | 609 | template<> |
645 | std::string FbTk::Resource<FocusControl::TabFocusModel>::getString() const { | 610 | const EnumTraits<FocusControl::TabFocusModel>::Pair EnumTraits<FocusControl::TabFocusModel>::s_map[] = { |
646 | switch (m_value) { | 611 | { "SloppyTabFocus", FocusControl::MOUSETABFOCUS }, |
647 | case FocusControl::MOUSETABFOCUS: | 612 | { "ClickToTabFocus", FocusControl::CLICKTABFOCUS }, |
648 | return string("SloppyTabFocus"); | 613 | { NULL, FocusControl::CLICKTABFOCUS } |
649 | case FocusControl::CLICKTABFOCUS: | 614 | }; |
650 | return string("ClickToTabFocus"); | ||
651 | } | ||
652 | // default string | ||
653 | return string("ClickToTabFocus"); | ||
654 | } | ||
655 | |||
656 | template<> | ||
657 | void FbTk::Resource<FocusControl::TabFocusModel>:: | ||
658 | setFromString(char const *strval) { | ||
659 | |||
660 | if (strcasecmp(strval, "SloppyTabFocus") == 0 ) | ||
661 | m_value = FocusControl::MOUSETABFOCUS; | ||
662 | else if (strcasecmp(strval, "ClickToTabFocus") == 0) | ||
663 | m_value = FocusControl::CLICKTABFOCUS; | ||
664 | else | ||
665 | setDefaultValue(); | ||
666 | } | ||
667 | |||
668 | template<> | ||
669 | void FbTk::Resource<FocusControl::TabFocusModel>::setFromLua(lua::state &l) { | ||
670 | lua::stack_sentry s(l, -1); | ||
671 | if(l.isstring(-1)) | ||
672 | setFromString(l.tostring(-1).c_str()); | ||
673 | else | ||
674 | setDefaultValue(); | ||
675 | l.pop(); | ||
676 | } | ||
677 | |||
678 | template<> | ||
679 | void FbTk::Resource<FocusControl::TabFocusModel>::pushToLua(lua::state &l) const { | ||
680 | l.pushstring(getString()); | ||
681 | } | ||
682 | 615 | ||
683 | } // end namespace FbTk | 616 | } // end namespace FbTk |
684 | 617 | ||