Commit MetaInfo

Revision82865aa55768951b12c578769c599f5fd19a7d79 (tree)
Time2017-02-20 00:42:41
Author <exeal@user...>

Log Message

Reimplemented input.*.

Change Summary

Incremental Difference

diff -r f196d53b749d -r 82865aa55768 alpha/src/input.cpp
--- a/alpha/src/input.cpp Mon Feb 20 00:38:58 2017 +0900
+++ b/alpha/src/input.cpp Mon Feb 20 00:42:41 2017 +0900
@@ -5,15 +5,19 @@
55 * @date 2009, 2014
66 */
77
8+#include "application.hpp"
9+#include "function-pointer.hpp"
810 #include "input.hpp"
9-#include "application.hpp" // StatusBar
10-#include "function-pointer.hpp"
11+#include "localized-string.hpp"
12+#include "ui/main-window.hpp"
1113 //#include "resource/messages.h"
1214 #include <ascension/viewer/widgetapi/event/user-input.hpp>
13-#include <bitset>
15+#include <boost/format.hpp>
1416 #include <boost/python/stl_iterator.hpp>
15-#include <glibmm/i18n.h>
16-#include <gtkmm/accelgroup.h>
17+#include <bitset>
18+#if ASCENSION_SELECTS_WINDOW_SYSTEM(GTK)
19+# include <gtkmm/accelgroup.h>
20+#endif
1721
1822
1923 namespace {
@@ -36,58 +40,40 @@
3640 * @param naturalKey
3741 * @param modifierKeys
3842 */
39- KeyStroke::KeyStroke(NaturalKey naturalKey, ModifierKey modifierKeys /* = 0 */) : naturalKey_(naturalKey), modifierKeys_(modifierKeys) {
43+ KeyStroke::KeyStroke(NaturalKey naturalKey, ModifierKey modifierKeys /* = 0 */) : naturalKey_(naturalKey), modifierKeys_(static_cast<ascension::viewer::widgetapi::event::KeyboardModifier>(modifierKeys)) {
4044 }
4145
42- /**
43- * Equality operator returns @c true if equals to the given @c KeyStroke.
44- * @param other The @c KeyStroke object to test
45- * @return The result
46- */
47- bool KeyStroke::operator==(const KeyStroke& other) const BOOST_NOEXCEPT {
48- return naturalKey() == other.naturalKey() && modifierKeys() == other.modifierKeys();
49- }
50-/*
51-namespace {
52- inline wstring modifierString(UINT vkey, const wchar_t* defaultString) {
53- if(const int sc = ::MapVirtualKeyW(vkey, MAPVK_VK_TO_VSC) << 16) {
54- WCHAR s[256];
55- if(::GetKeyNameTextW(sc | (1 << 25), s, MANAH_COUNTOF(s)) != 0)
56- return s;
57- }
58- return defaultString;
59- }
60-}
61-
62-wstring KeyStroke::format(py::object keys) {
63- if(py::extract<const KeyStroke&>(keys).check())
64- return static_cast<const KeyStroke&>(py::extract<const KeyStroke&>(keys)).format();
65- return format(makeStlInputIterator<const KeyStroke>(keys), py::stl_input_iterator<const KeyStroke>());
66-}
67-*/
68- /// Returns the modifier keys.
69- KeyStroke::ModifierKey KeyStroke::modifierKeys() const BOOST_NOEXCEPT {
70- return modifierKeys_;
71- }
72-
73- /// Returns the natural key code.
74- KeyStroke::NaturalKey KeyStroke::naturalKey() const BOOST_NOEXCEPT {
75- return naturalKey_;
46+ namespace {
47+#if ASCENSION_SELECTS_WINDOW_SYSTEM(WIN32)
48+ inline PlatformString modifierString(UINT vkey, const PlatformString& defaultString) {
49+ if(const int sc = ::MapVirtualKeyW(vkey, MAPVK_VK_TO_VSC) << 16) {
50+ WCHAR s[256];
51+ if(::GetKeyNameTextW(sc | (1 << 25), s, std::extent<decltype(s)>::value) != 0)
52+ return s;
53+ }
54+ return defaultString;
55+ }
56+#endif
57+// wstring KeyStroke::format(py::object keys) {
58+// if(py::extract<const KeyStroke&>(keys).check())
59+// return static_cast<const KeyStroke&>(py::extract<const KeyStroke&>(keys)).format();
60+// return format(makeStlInputIterator<const KeyStroke>(keys), py::stl_input_iterator<const KeyStroke>());
61+// }
7662 }
7763
7864 /// Returns a human-readable text represents this key stroke.
7965 PlatformString KeyStroke::text() const BOOST_NOEXCEPT {
80-#if 1
66+#if ASCENSION_SELECTS_WINDOW_SYSTEM(GTK)
8167 return Gtk::AccelGroup::get_label(naturalKey(), static_cast<Gdk::ModifierType>(modifierKeys()));
82-#else
83- wstring result;
68+#elif ASCENSION_SELECTS_WINDOW_SYSTEM(WIN32)
69+ PlatformString result;
8470 result.reserve(256);
8571
86- if((modifierKeys() & CONTROL_KEY) != 0)
72+ if(modifierKeys_.test(ascension::viewer::widgetapi::event::CONTROL_DOWN))
8773 result.append(modifierString(VK_CONTROL, L"Ctrl")).append(L"+");
88- if((modifierKeys() & SHIFT_KEY) != 0)
74+ if(modifierKeys_.test(ascension::viewer::widgetapi::event::SHIFT_DOWN))
8975 result.append(modifierString(VK_SHIFT, L"Shift")).append(L"+");
90- if((modifierKeys() & ALTERNATIVE_KEY) != 0)
76+ if(modifierKeys_.test(ascension::viewer::widgetapi::event::ALT_DOWN))
9177 result.append(modifierString(VK_MENU, L"Alt")).append(L"+");
9278
9379 if(UINT sc = ::MapVirtualKeyW(naturalKey(), MAPVK_VK_TO_VSC) << 16) {
@@ -98,7 +84,7 @@
9884 sc |= (1 << 24);
9985 }
10086 wchar_t buffer[256];
101- if(::GetKeyNameTextW(sc | (1 << 25), buffer, MANAH_COUNTOF(buffer)) != 0) {
87+ if(::GetKeyNameTextW(sc | (1 << 25), buffer, std::extent<decltype(buffer)>::value) != 0) {
10288 result += buffer;
10389 return result;
10490 }
@@ -157,14 +143,6 @@
157143 }
158144
159145 /**
160- * Returns @c true if this @c KeyMap is locked.
161- * @see #lock, #unlock
162- */
163- bool KeyMap::isLocked() const BOOST_NOEXCEPT {
164- return lockedCount_ != 0;
165- }
166-
167- /**
168146 * Increments the lock count.
169147 * @throw std#overflow_error
170148 * @see #isLocked, #unlock
@@ -275,6 +253,7 @@
275253 }
276254 }
277255
256+#if ASCENSION_SELECTS_WINDOW_SYSTEM(GTK)
278257 /**
279258 * Handles button press event.
280259 * @param event The event object
@@ -291,13 +270,63 @@
291270 bool InputManager::input(const GdkEventKey& event) {
292271 if(event.type != Gdk::KEY_PRESS || event.is_modifier != 0)
293272 return false;
273+ return input(KeyStroke(static_cast<KeyStroke::NaturalKey>(event.keyval), static_cast<KeyStroke::ModifierKey>(event.state)));
274+ }
294275
295- const KeyStroke key(static_cast<KeyStroke::NaturalKey>(event.keyval), static_cast<KeyStroke::ModifierKey>(event.state));
276+ /**
277+ * Handles touch event.
278+ * @param event The event object
279+ */
280+ bool InputManager::input(const GdkEventTouch& event) {
281+ // TODO: Not implemented.
282+ return false;
283+ }
284+
285+#elif ASCENSION_SELECTS_WINDOW_SYSTEM(WIN32)
286+
287+/***/
288+bool InputManager::input(const MSG& message) {
289+ if((message.message == WM_KEYDOWN || message.message == WM_SYSKEYDOWN) && message.wParam != VK_PROCESSKEY) {
290+ // this interrupts WM_CHARs
291+ const KeyStroke k(
292+ static_cast<KeyStroke::NaturalKey>(message.wParam),
293+ static_cast<KeyStroke::ModifierKey>(ascension::win32::makeKeyboardModifiers().to_ulong()));
294+ switch(k.naturalKey()) {
295+ case VK_SHIFT:
296+ case VK_CONTROL:
297+ case VK_MENU:
298+ return false;
299+ }
300+ return input(k);
301+ } else if(message.message == WM_SYSCHAR) {
302+/* // interrupt menu activation if key sequence is defined
303+ if(!pendingKeySequence_.empty())
304+ return true;
305+ const KeyStroke k(
306+ static_cast<KeyStroke::ModifierKey>(
307+ ((::GetKeyState(VK_CONTROL) < 0) ? KeyStroke::CONTROL_KEY : 0)
308+ | ((::GetKeyState(VK_SHIFT) < 0) ? KeyStroke::SHIFT_KEY : 0)
309+ | KeyStroke::ALTERNATIVE_KEY),
310+ LOBYTE(::VkKeyScanW(static_cast<WCHAR>(message.wParam & 0xffffu))));
311+ bool partialMatch;
312+ py::object command(mappingScheme_.second->command(pendingKeySequence_, &partialMatch));
313+ if(command != py::object() || partialMatch)
314+ return true;
315+*/ }
316+ return false;
317+}
318+#endif
319+ /**
320+ * @internal
321+ * @param keyStroke
322+ * @return
323+ */
324+ bool InputManager::input(const KeyStroke& keyStroke) {
296325 boost::python::object definition;
297326 if(pendingKeyStrokes_.empty()) // first stroke
298- definition = lookupKey(key);
327+ definition = lookupKey(keyStroke);
299328 else {
300- pendingKeyStrokes_.push_back(key);
329+ pendingKeyStrokes_.push_back(keyStroke);
301330 boost::python::tuple keyStrokes(pendingKeyStrokes_);
302331 definition = lookupKey(keyStrokes);
303332 }
@@ -319,7 +348,7 @@
319348 PlatformString incompleteKeyStrokes;
320349 assert(pendingKeyStrokes_.size() != 1);
321350 if(pendingKeyStrokes_.empty())
322- incompleteKeyStrokes = key.text();
351+ incompleteKeyStrokes = keyStroke.text();
323352 else {
324353 for(std::size_t i = 0, c = pendingKeyStrokes_.size(); ; ++i) {
325354 incompleteKeyStrokes += pendingKeyStrokes_[i].text();
@@ -351,76 +380,6 @@
351380 }
352381 }
353382
354- /**
355- * Handles touch event.
356- * @param event The event object
357- */
358- bool InputManager::input(const GdkEventTouch& event) {
359- // TODO: Not implemented.
360- return false;
361- }
362-
363-#if ASCENSION_SELECTS_WINDOW_SYSTEM(WIN32) && 0
364-/***/
365-bool InputManager::input(const MSG& message) {
366- if((message.message == WM_KEYDOWN || message.message == WM_SYSKEYDOWN) && message.wParam != VK_PROCESSKEY) {
367- // this interrupts WM_CHARs
368- const KeyStroke k(
369- static_cast<KeyStroke::ModifierKey>(
370- ((::GetKeyState(VK_CONTROL) < 0) ? KeyStroke::CONTROL_KEY : 0)
371- | ((::GetKeyState(VK_SHIFT) < 0) ? KeyStroke::SHIFT_KEY : 0)
372- | ((message.message == WM_SYSKEYDOWN || ::GetKeyState(VK_MENU) < 0) ? KeyStroke::ALTERNATIVE_KEY : 0)),
373- static_cast<KeyStroke::VirtualKey>(message.wParam));
374- switch(k.naturalKey()) {
375- case VK_SHIFT:
376- case VK_CONTROL:
377- case VK_MENU:
378- return false;
379- }
380- bool partialMatch;
381- pendingKeySequence_.push_back(k);
382- py::object command(mappingScheme_.second->command(pendingKeySequence_, &partialMatch));
383- if(command != py::object()) {
384- pendingKeySequence_.clear();
385- bool typed = false;
386- if(inputTypedCharacterCommand_ == py::object())
387- inputTypedCharacterCommand_ = Interpreter::instance().module("intrinsics").attr("input_typed_character");
388- if(command == inputTypedCharacterCommand_)
389- typed = true;
390- if(!typed)
391- ambient::Interpreter::instance().executeCommand(command);
392- alpha::Alpha::instance().statusBar().setText(L"");
393- return !typed;
394- } else if(partialMatch) {
395- const wstring s(KeyStroke::format(pendingKeySequence_.begin(), pendingKeySequence_.end()));
396- alpha::Alpha::instance().statusBar().setText(s.c_str());
397- return true;
398- }
399- const bool activateMenu =
400- pendingKeySequence_.size() == 1 && (k.modifierKeys() & KeyStroke::ALTERNATIVE_KEY) != 0;
401- pendingKeySequence_.clear();
402- ::MessageBeep(MB_OK);
403- alpha::Alpha::instance().statusBar().setText(L"");
404- return !activateMenu;
405- } else if(message.message == WM_SYSCHAR) {
406-/* // interrupt menu activation if key sequence is defined
407- if(!pendingKeySequence_.empty())
408- return true;
409- const KeyStroke k(
410- static_cast<KeyStroke::ModifierKey>(
411- ((::GetKeyState(VK_CONTROL) < 0) ? KeyStroke::CONTROL_KEY : 0)
412- | ((::GetKeyState(VK_SHIFT) < 0) ? KeyStroke::SHIFT_KEY : 0)
413- | KeyStroke::ALTERNATIVE_KEY),
414- LOBYTE(::VkKeyScanW(static_cast<WCHAR>(message.wParam & 0xffffu))));
415- bool partialMatch;
416- py::object command(mappingScheme_.second->command(pendingKeySequence_, &partialMatch));
417- if(command != py::object() || partialMatch)
418- return true;
419-*/ }
420- return false;
421-}
422-#endif
423-
424383 /// Returns the singleton instance.
425384 InputManager& InputManager::instance() {
426385 static InputManager singleton;
diff -r f196d53b749d -r 82865aa55768 alpha/src/input.hpp
--- a/alpha/src/input.hpp Mon Feb 20 00:38:58 2017 +0900
+++ b/alpha/src/input.hpp Mon Feb 20 00:42:41 2017 +0900
@@ -9,6 +9,7 @@
99 #define ALPHA_INPUT_HPP
1010 #include "platform-string.hpp"
1111 #include <ascension/corelib/detail/scope-guard.hpp>
12+#include <ascension/viewer/widgetapi/event/keyboard-modifier.hpp>
1213 #include <boost/functional/hash.hpp> // boost.hash_combine, boost.hash_value
1314 #include <boost/operators.hpp> // boost.equality_comparable
1415 #include <boost/python.hpp>
@@ -37,14 +38,14 @@
3738 public:
3839 explicit KeyStroke(NaturalKey naturalKey, ModifierKey modifierKeys = static_cast<ModifierKey>(0));
3940 explicit KeyStroke(const PlatformString& format);
40- bool operator==(const KeyStroke& other) const BOOST_NOEXCEPT;
41+ BOOST_CONSTEXPR bool operator==(const KeyStroke& other) const BOOST_NOEXCEPT;
4142 ModifierKey modifierKeys() const BOOST_NOEXCEPT;
42- NaturalKey naturalKey() const BOOST_NOEXCEPT;
43+ BOOST_CONSTEXPR NaturalKey naturalKey() const BOOST_NOEXCEPT;
4344 PlatformString text() const BOOST_NOEXCEPT;
4445
4546 private:
4647 /*const*/ NaturalKey naturalKey_;
47- /*const*/ ModifierKey modifierKeys_;
48+ /*const*/ ascension::viewer::widgetapi::event::KeyboardModifiers modifierKeys_;
4849 };
4950 }
5051 }
@@ -80,7 +81,7 @@
8081
8182 class KeyMap : public AbstractKeyMap, public std::enable_shared_from_this<KeyMap> {
8283 public:
83- explicit KeyMap(const PlatformString& name = Glib::ustring());
84+ explicit KeyMap(const PlatformString& name = PlatformString());
8485
8586 /// @name Attributes
8687 /// @{
@@ -99,7 +100,7 @@
99100
100101 /// @name Access Control
101102 /// @{
102- bool isLocked() const BOOST_NOEXCEPT;
103+ BOOST_CONSTEXPR bool isLocked() const BOOST_NOEXCEPT;
103104 void lock();
104105 void unlock();
105106 /// @}
@@ -160,12 +161,17 @@
160161 /// @name Input Handling
161162 /// @{
162163 void cancelIncompleteKeyStrokes();
164+#if ASCENSION_SELECTS_WINDOW_SYSTEM(GTK)
163165 bool input(const GdkEventButton& event); // for button_press_event
164166 bool input(const GdkEventKey& event); // for key_press_event
165167 bool input(const GdkEventTouch& event); // for touch_event
168+#elif ASCENSION_SELECTS_WINDOW_SYSTEM(WIN32)
169+ bool input(const MSG& message);
170+#endif
166171 /// @}
167172
168173 private:
174+ bool input(const KeyStroke& keyStroke);
169175 template<typename Key>
170176 boost::python::object internalLookupKey(const Key& key) const;
171177 private:
@@ -175,6 +181,34 @@
175181 typedef ascension::detail::MutexWithClass<KeyMap, &KeyMap::lock, &KeyMap::unlock> KeyMapMutex;
176182 std::unique_ptr<boost::lock_guard<KeyMapMutex>> mappingSchemeLocker_, modalMappingSchemeLocker_;
177183 };
184+
185+
186+ /**
187+ * Equality operator returns @c true if equals to the given @c KeyStroke.
188+ * @param other The @c KeyStroke object to test
189+ * @return The result
190+ */
191+ inline BOOST_CONSTEXPR bool KeyStroke::operator==(const KeyStroke& other) const BOOST_NOEXCEPT {
192+ return naturalKey() == other.naturalKey() && modifierKeys() == other.modifierKeys();
193+ }
194+
195+ /// Returns the modifier keys.
196+ inline KeyStroke::ModifierKey KeyStroke::modifierKeys() const BOOST_NOEXCEPT {
197+ return static_cast<ModifierKey>(modifierKeys_.to_ulong());
198+ }
199+
200+ /// Returns the natural key code.
201+ inline BOOST_CONSTEXPR KeyStroke::NaturalKey KeyStroke::naturalKey() const BOOST_NOEXCEPT {
202+ return naturalKey_;
203+ }
204+
205+ /**
206+ * Returns @c true if this @c KeyMap is locked.
207+ * @see #lock, #unlock
208+ */
209+ inline BOOST_CONSTEXPR bool KeyMap::isLocked() const BOOST_NOEXCEPT {
210+ return lockedCount_ != 0;
211+ }
178212 }
179213 } // namespace alpha.ui
180214
Show on old repository browser