From 5951beaf9effae43cb4535ecca04ccd6341c73ab Mon Sep 17 00:00:00 2001 From: Jack Andersen Date: Sun, 27 Dec 2015 13:25:10 -1000 Subject: [PATCH] Remove old text input methods --- specter/include/Specter/Control.hpp | 4 ++ .../include/Specter/DeferredWindowEvents.hpp | 14 +---- specter/include/Specter/RootView.hpp | 1 - specter/include/Specter/TextField.hpp | 2 - specter/include/Specter/View.hpp | 1 - specter/lib/RootView.cpp | 20 +++--- specter/lib/TextField.cpp | 63 ------------------- 7 files changed, 15 insertions(+), 90 deletions(-) diff --git a/specter/include/Specter/Control.hpp b/specter/include/Specter/Control.hpp index c3b824737..671921029 100644 --- a/specter/include/Specter/Control.hpp +++ b/specter/include/Specter/Control.hpp @@ -70,6 +70,10 @@ protected: ITextInputView(ViewResources& res, View& parentView, IControlBinding* controlBinding) : Control(res, parentView, controlBinding) {} +public: + virtual void clipboardCopy() {} + virtual void clipboardCut() {} + virtual void clipboardPaste() {} }; } diff --git a/specter/include/Specter/DeferredWindowEvents.hpp b/specter/include/Specter/DeferredWindowEvents.hpp index 63418da30..cc91e7586 100644 --- a/specter/include/Specter/DeferredWindowEvents.hpp +++ b/specter/include/Specter/DeferredWindowEvents.hpp @@ -50,8 +50,7 @@ struct DeferredWindowEvents : public boo::IWindowCallback SpecialKeyDown, SpecialKeyUp, ModKeyDown, - ModKeyUp, - UTF8FragmentDown + ModKeyUp } m_type; boo::SWindowCoord m_coord; @@ -63,7 +62,6 @@ struct DeferredWindowEvents : public boo::IWindowCallback unsigned long m_charcode; boo::ESpecialKey m_special; bool m_isRepeat; - std::string m_fragment; void dispatch(Receiver& rec) const { @@ -114,9 +112,6 @@ struct DeferredWindowEvents : public boo::IWindowCallback case Type::ModKeyUp: rec.modKeyUp(m_mods); break; - case Type::UTF8FragmentDown: - rec.utf8FragmentDown(m_fragment); - break; default: break; } } @@ -244,13 +239,6 @@ struct DeferredWindowEvents : public boo::IWindowCallback m_cmds.emplace_back(Command::Type::ModKeyUp); m_cmds.back().m_mods = mod; } - - void utf8FragmentDown(const std::string& str) - { - std::unique_lock lk(m_mt); - m_cmds.emplace_back(Command::Type::UTF8FragmentDown); - m_cmds.back().m_fragment = str; - } boo::ITextInputCallback* getTextInputCallback() {return m_rec.getTextInputCallback();} diff --git a/specter/include/Specter/RootView.hpp b/specter/include/Specter/RootView.hpp index adef20dff..1d09b1986 100644 --- a/specter/include/Specter/RootView.hpp +++ b/specter/include/Specter/RootView.hpp @@ -56,7 +56,6 @@ public: void specialKeyUp(boo::ESpecialKey key, boo::EModifierKey mods); void modKeyDown(boo::EModifierKey mod, bool isRepeat); void modKeyUp(boo::EModifierKey mod); - void utf8FragmentDown(const std::string& str); boo::ITextInputCallback* getTextInputCallback() {return m_activeTextView;} void dispatchEvents() {m_events.dispatchEvents();} diff --git a/specter/include/Specter/TextField.hpp b/specter/include/Specter/TextField.hpp index de029e4f5..f1b280617 100644 --- a/specter/include/Specter/TextField.hpp +++ b/specter/include/Specter/TextField.hpp @@ -72,9 +72,7 @@ public: void mouseMove(const boo::SWindowCoord&); void mouseEnter(const boo::SWindowCoord&); void mouseLeave(const boo::SWindowCoord&); - void charKeyDown(unsigned long, boo::EModifierKey, bool); void specialKeyDown(boo::ESpecialKey, boo::EModifierKey, bool); - void utf8FragmentDown(const std::string&); bool hasMarkedText() const; std::pair markedRange() const; diff --git a/specter/include/Specter/View.hpp b/specter/include/Specter/View.hpp index 76e1610c1..9f0e33e2a 100644 --- a/specter/include/Specter/View.hpp +++ b/specter/include/Specter/View.hpp @@ -203,7 +203,6 @@ public: virtual void specialKeyUp(boo::ESpecialKey, boo::EModifierKey) {} virtual void modKeyDown(boo::EModifierKey, bool) {} virtual void modKeyUp(boo::EModifierKey) {} - virtual void utf8FragmentDown(const std::string&) {} virtual void resized(const boo::SWindowRect& root, const boo::SWindowRect& sub); virtual void think() {} diff --git a/specter/lib/RootView.cpp b/specter/lib/RootView.cpp index 4e68e134e..174e09d6d 100644 --- a/specter/lib/RootView.cpp +++ b/specter/lib/RootView.cpp @@ -108,16 +108,22 @@ void RootView::charKeyDown(unsigned long charCode, boo::EModifierKey mods, bool { if (m_view) m_view->charKeyDown(charCode, mods, isRepeat); - //if (m_activeTextView) - // m_activeTextView->charKeyDown(charCode, mods, isRepeat); + if (m_activeTextView && + (mods & (boo::EModifierKey::Ctrl|boo::EModifierKey::Command)) != boo::EModifierKey::None) + { + if (charCode == 'c' || charCode == 'C') + m_activeTextView->clipboardCopy(); + else if (charCode == 'x' || charCode == 'X') + m_activeTextView->clipboardCut(); + else if (charCode == 'v' || charCode == 'V') + m_activeTextView->clipboardPaste(); + } } void RootView::charKeyUp(unsigned long charCode, boo::EModifierKey mods) { if (m_view) m_view->charKeyUp(charCode, mods); - //if (m_activeTextView) - // m_activeTextView->charKeyUp(charCode, mods); } void RootView::specialKeyDown(boo::ESpecialKey key, boo::EModifierKey mods, bool isRepeat) @@ -157,12 +163,6 @@ void RootView::modKeyUp(boo::EModifierKey mod) m_activeTextView->modKeyUp(mod); } -void RootView::utf8FragmentDown(const std::string& str) -{ - //if (m_activeTextView) - // m_activeTextView->utf8FragmentDown(str); -} - View* RootView::setContentView(View* view) { View* ret = m_view; diff --git a/specter/lib/TextField.cpp b/specter/lib/TextField.cpp index f646043ab..1240e2175 100644 --- a/specter/lib/TextField.cpp +++ b/specter/lib/TextField.cpp @@ -288,46 +288,6 @@ void TextField::clipboardPaste() } } -void TextField::charKeyDown(unsigned long charCode, boo::EModifierKey mods, bool isRepeat) -{ - if (charCode < 0x20) - return; - - if ((mods & (boo::EModifierKey::Ctrl|boo::EModifierKey::Command)) != boo::EModifierKey::None) - { - if (charCode == 'c' || charCode == 'C') - clipboardCopy(); - else if (charCode == 'v' || charCode == 'V') - clipboardPaste(); - return; - } - - if (m_selectionCount) - { - std::string newStr(m_textStr.cbegin(), (UTF8Iterator(m_textStr.cbegin()) + m_selectionStart).iter()); - utf8proc_uint8_t theChar[5] = {}; - utf8proc_ssize_t sz = utf8proc_encode_char(charCode, theChar); - if (sz > 0) - newStr += (char*)theChar; - newStr.append((UTF8Iterator(m_textStr.cbegin()) + m_selectionStart + m_selectionCount).iter(), - m_textStr.cend()); - size_t selStart = m_selectionStart; - setText(newStr); - setCursorPos(selStart + 1); - } - else - { - std::string newStr(m_textStr.cbegin(), (UTF8Iterator(m_textStr.cbegin()) + m_cursorPos).iter()); - utf8proc_uint8_t theChar[5] = {}; - utf8proc_ssize_t sz = utf8proc_encode_char(charCode, theChar); - if (sz > 0) - newStr += (char*)theChar; - newStr.append((UTF8Iterator(m_textStr.cbegin()) + m_cursorPos).iter(), m_textStr.cend()); - setText(newStr); - setCursorPos(m_cursorPos + 1); - } -} - void TextField::specialKeyDown(boo::ESpecialKey key, boo::EModifierKey mods, bool isRepeat) { std::unique_lock lk(m_textInputLk); @@ -425,29 +385,6 @@ void TextField::specialKeyDown(boo::ESpecialKey key, boo::EModifierKey mods, boo } } } - -void TextField::utf8FragmentDown(const std::string& str) -{ - std::string saniStr = SanitizeUTF8TextLine(str.data(), str.size()); - if (m_selectionCount) - { - std::string newStr(m_textStr.cbegin(), (UTF8Iterator(m_textStr.cbegin()) + m_selectionStart).iter()); - newStr += saniStr; - size_t newSel = UTF8Iterator(newStr.cbegin()).countTo(newStr.cend()); - newStr.append((UTF8Iterator(m_textStr.cbegin()) + m_selectionStart + m_selectionCount).iter(), m_textStr.cend()); - setText(newStr); - setCursorPos(newSel); - } - else - { - std::string newStr(m_textStr.cbegin(), (UTF8Iterator(m_textStr.cbegin()) + m_cursorPos).iter()); - newStr += saniStr; - size_t newSel = UTF8Iterator(newStr.cbegin()).countTo(newStr.cend()); - newStr.append((UTF8Iterator(m_textStr.cbegin()) + m_cursorPos).iter(), m_textStr.cend()); - setText(newStr); - setCursorPos(newSel); - } -} bool TextField::hasMarkedText() const {