From 169eee50c008e6b060db31fc7e9fa1a9958771ba Mon Sep 17 00:00:00 2001 From: David Rose Date: Thu, 8 Apr 2004 19:34:42 +0000 Subject: [PATCH] support cursor_pos for candidate() functions, and trigger background pgEntry on candidate action --- panda/src/display/graphicsWindowInputDevice.cxx | 5 +++-- panda/src/display/graphicsWindowInputDevice.h | 3 ++- panda/src/event/buttonEvent.I | 7 +++++-- panda/src/event/buttonEvent.cxx | 2 ++ panda/src/event/buttonEvent.h | 3 ++- panda/src/pgui/pgEntry.cxx | 6 +++++- panda/src/pgui/pgEntry.h | 1 + panda/src/pgui/pgItem.cxx | 17 +++++++++++++++++ panda/src/pgui/pgItem.h | 1 + panda/src/pgui/pgMouseWatcherBackground.cxx | 11 +++++++++++ panda/src/pgui/pgMouseWatcherBackground.h | 1 + panda/src/tform/mouseWatcher.cxx | 6 +++--- panda/src/tform/mouseWatcher.h | 2 +- panda/src/tform/mouseWatcherParameter.I | 15 ++++++++++++++- panda/src/tform/mouseWatcherParameter.h | 5 ++++- 15 files changed, 72 insertions(+), 13 deletions(-) diff --git a/panda/src/display/graphicsWindowInputDevice.cxx b/panda/src/display/graphicsWindowInputDevice.cxx index f6c1872278..1581957e89 100644 --- a/panda/src/display/graphicsWindowInputDevice.cxx +++ b/panda/src/display/graphicsWindowInputDevice.cxx @@ -200,7 +200,8 @@ keystroke(int keycode, double time) { //////////////////////////////////////////////////////////////////// void GraphicsWindowInputDevice:: candidate(const wstring &candidate_string, size_t highlight_start, - size_t highlight_end, double time) { + size_t highlight_end, size_t cursor_pos) { _button_events.push_back(ButtonEvent(candidate_string, - highlight_start, highlight_end)); + highlight_start, highlight_end, + cursor_pos)); } diff --git a/panda/src/display/graphicsWindowInputDevice.h b/panda/src/display/graphicsWindowInputDevice.h index 8a84236d7d..78839698a0 100644 --- a/panda/src/display/graphicsWindowInputDevice.h +++ b/panda/src/display/graphicsWindowInputDevice.h @@ -67,7 +67,8 @@ public: void button_up(ButtonHandle button, double time = ClockObject::get_global_clock()->get_frame_time()); void keystroke(int keycode, double time = ClockObject::get_global_clock()->get_frame_time()); void candidate(const wstring &candidate_string, size_t highlight_start, - size_t higlight_end, double time = ClockObject::get_global_clock()->get_frame_time()); + size_t higlight_end, size_t cursor_pos); + INLINE void set_pointer_in_window(int x, int y); INLINE void set_pointer_out_of_window(); diff --git a/panda/src/event/buttonEvent.I b/panda/src/event/buttonEvent.I index 459b481146..c016db63ac 100644 --- a/panda/src/event/buttonEvent.I +++ b/panda/src/event/buttonEvent.I @@ -70,14 +70,15 @@ ButtonEvent(short keycode, double time) : //////////////////////////////////////////////////////////////////// INLINE ButtonEvent:: ButtonEvent(const wstring &candidate_string, size_t highlight_start, - size_t highlight_end, double time) : + size_t highlight_end, size_t cursor_pos) : _button(ButtonHandle::none()), _keycode(0), _candidate_string(candidate_string), _highlight_start(highlight_start), _highlight_end(highlight_end), + _cursor_pos(cursor_pos), _type(T_candidate), - _time(time) + _time(ClockObject::get_global_clock()->get_frame_time()) { } @@ -93,6 +94,7 @@ ButtonEvent(const ButtonEvent ©) : _candidate_string(copy._candidate_string), _highlight_start(copy._highlight_start), _highlight_end(copy._highlight_end), + _cursor_pos(copy._cursor_pos), _type(copy._type), _time(copy._time) { @@ -110,6 +112,7 @@ operator = (const ButtonEvent ©) { _candidate_string = copy._candidate_string; _highlight_start = copy._highlight_start; _highlight_end = copy._highlight_end; + _cursor_pos = copy._cursor_pos; _type = copy._type; _time = copy._time; } diff --git a/panda/src/event/buttonEvent.cxx b/panda/src/event/buttonEvent.cxx index 412344b8f1..ad361abaff 100644 --- a/panda/src/event/buttonEvent.cxx +++ b/panda/src/event/buttonEvent.cxx @@ -85,6 +85,7 @@ write_datagram(Datagram &dg) const { TextEncoder::get_default_encoding())); dg.add_uint16(_highlight_start); dg.add_uint16(_highlight_end); + dg.add_uint16(_cursor_pos); } } @@ -112,5 +113,6 @@ read_datagram(DatagramIterator &scan) { TextEncoder::get_default_encoding()); _highlight_start = scan.get_uint16(); _highlight_end = scan.get_uint16(); + _cursor_pos = scan.get_uint16(); } } diff --git a/panda/src/event/buttonEvent.h b/panda/src/event/buttonEvent.h index 89447a0718..76c2a7e4f0 100644 --- a/panda/src/event/buttonEvent.h +++ b/panda/src/event/buttonEvent.h @@ -84,7 +84,7 @@ public: INLINE ButtonEvent(ButtonHandle button, Type type, double time = ClockObject::get_global_clock()->get_frame_time()); INLINE ButtonEvent(short keycode, double time = ClockObject::get_global_clock()->get_frame_time()); INLINE ButtonEvent(const wstring &candidate_string, size_t highlight_start, - size_t higlight_end, double time = ClockObject::get_global_clock()->get_frame_time()); + size_t highlight_end, size_t cursor_pos); INLINE ButtonEvent(const ButtonEvent ©); INLINE void operator = (const ButtonEvent ©); @@ -112,6 +112,7 @@ public: wstring _candidate_string; size_t _highlight_start; size_t _highlight_end; + size_t _cursor_pos; // This is the type of the button event (see above). Type _type; diff --git a/panda/src/pgui/pgEntry.cxx b/panda/src/pgui/pgEntry.cxx index a457b7ba3e..04c8c86f88 100644 --- a/panda/src/pgui/pgEntry.cxx +++ b/panda/src/pgui/pgEntry.cxx @@ -47,6 +47,7 @@ PGEntry(const string &name) : _cursor_stale = true; _candidate_highlight_start = 0; _candidate_highlight_end = 0; + _candidate_cursor_pos = 0; _max_chars = 0; _max_width = 0.0f; _num_lines = 1; @@ -468,7 +469,9 @@ candidate(const MouseWatcherParameter ¶m, bool background) { _candidate_wtext = param.get_candidate_string(); _candidate_highlight_start = param.get_highlight_start(); _candidate_highlight_end = param.get_highlight_end(); + _candidate_cursor_pos = param.get_cursor_pos(); _text_geom_stale = true; + type(param); } } PGItem::candidate(param, background); @@ -835,10 +838,11 @@ update_cursor() { update_text(); _cursor_position = min(_cursor_position, (int)_wtext.length()); + _candidate_cursor_pos = min(_candidate_cursor_pos, _candidate_wtext.length()); // Determine the row and column of the cursor. int row = 0; - int column = _cursor_position; + int column = _cursor_position + _candidate_cursor_pos; while (row + 1 < (int)_ww_lines.size() && column > (int)_ww_lines[row]._str.length()) { column -= _ww_lines[row]._str.length(); diff --git a/panda/src/pgui/pgEntry.h b/panda/src/pgui/pgEntry.h index 4a633ef1a5..2296cee2b3 100644 --- a/panda/src/pgui/pgEntry.h +++ b/panda/src/pgui/pgEntry.h @@ -142,6 +142,7 @@ private: wstring _candidate_wtext; size_t _candidate_highlight_start; size_t _candidate_highlight_end; + size_t _candidate_cursor_pos; int _max_chars; float _max_width; diff --git a/panda/src/pgui/pgItem.cxx b/panda/src/pgui/pgItem.cxx index e286e18490..6b5d8345f2 100644 --- a/panda/src/pgui/pgItem.cxx +++ b/panda/src/pgui/pgItem.cxx @@ -504,6 +504,23 @@ background_keystroke(const MouseWatcherParameter ¶m) { } } +//////////////////////////////////////////////////////////////////// +// Function: PGItem::background_candidate +// Access: Public, Static +// Description: Calls candidate() on all the PGItems with background +// focus. +//////////////////////////////////////////////////////////////////// +void PGItem:: +background_candidate(const MouseWatcherParameter ¶m) { + BackgroundFocus::const_iterator fi; + for (fi = _background_focus.begin(); fi != _background_focus.end(); ++fi) { + PGItem *item = *fi; + if (!item->get_focus()) { + item->candidate(param, true); + } + } +} + //////////////////////////////////////////////////////////////////// // Function: PGItem::set_active // Access: Published, Virtual diff --git a/panda/src/pgui/pgItem.h b/panda/src/pgui/pgItem.h index c6f39813a9..ce157dc690 100644 --- a/panda/src/pgui/pgItem.h +++ b/panda/src/pgui/pgItem.h @@ -83,6 +83,7 @@ public: static void background_press(const MouseWatcherParameter ¶m); static void background_release(const MouseWatcherParameter ¶m); static void background_keystroke(const MouseWatcherParameter ¶m); + static void background_candidate(const MouseWatcherParameter ¶m); PUBLISHED: INLINE void set_frame(float left, float right, float bottom, float top); diff --git a/panda/src/pgui/pgMouseWatcherBackground.cxx b/panda/src/pgui/pgMouseWatcherBackground.cxx index 133f58691a..3b5b72551b 100644 --- a/panda/src/pgui/pgMouseWatcherBackground.cxx +++ b/panda/src/pgui/pgMouseWatcherBackground.cxx @@ -77,3 +77,14 @@ void PGMouseWatcherBackground:: keystroke(const MouseWatcherParameter ¶m) { PGItem::background_keystroke(param); } + +//////////////////////////////////////////////////////////////////// +// Function: PGMouseWatcherBackground::candidate +// Access: Public, Virtual +// Description: This is a callback hook function, called whenever +// the user uses the IME. +//////////////////////////////////////////////////////////////////// +void PGMouseWatcherBackground:: +candidate(const MouseWatcherParameter ¶m) { + PGItem::background_candidate(param); +} diff --git a/panda/src/pgui/pgMouseWatcherBackground.h b/panda/src/pgui/pgMouseWatcherBackground.h index 27273b0fc4..7bf9184598 100644 --- a/panda/src/pgui/pgMouseWatcherBackground.h +++ b/panda/src/pgui/pgMouseWatcherBackground.h @@ -38,6 +38,7 @@ PUBLISHED: virtual void press(const MouseWatcherParameter ¶m); virtual void release(const MouseWatcherParameter ¶m); virtual void keystroke(const MouseWatcherParameter ¶m); + virtual void candidate(const MouseWatcherParameter ¶m); public: static TypeHandle get_class_type() { diff --git a/panda/src/tform/mouseWatcher.cxx b/panda/src/tform/mouseWatcher.cxx index edd0f61aca..37fbe596fb 100644 --- a/panda/src/tform/mouseWatcher.cxx +++ b/panda/src/tform/mouseWatcher.cxx @@ -745,9 +745,9 @@ keystroke(int keycode) { //////////////////////////////////////////////////////////////////// void MouseWatcher:: candidate(const wstring &candidate_string, size_t highlight_start, - size_t highlight_end) { + size_t highlight_end, size_t cursor_pos) { MouseWatcherParameter param; - param.set_candidate(candidate_string, highlight_start, highlight_end); + param.set_candidate(candidate_string, highlight_start, highlight_end, cursor_pos); param.set_modifier_buttons(_mods); param.set_mouse(_mouse); @@ -1016,7 +1016,7 @@ do_transmit_data(const DataNodeTransmit &input, DataNodeTransmit &output) { break; case ButtonEvent::T_candidate: - candidate(be._candidate_string, be._highlight_start, be._highlight_end); + candidate(be._candidate_string, be._highlight_start, be._highlight_end, be._cursor_pos); break; case ButtonEvent::T_resume_down: diff --git a/panda/src/tform/mouseWatcher.h b/panda/src/tform/mouseWatcher.h index 04c4bd9cef..8b9905a036 100644 --- a/panda/src/tform/mouseWatcher.h +++ b/panda/src/tform/mouseWatcher.h @@ -140,7 +140,7 @@ protected: void release(ButtonHandle button); void keystroke(int keycode); void candidate(const wstring &candidate, size_t highlight_start, - size_t highlight_end); + size_t highlight_end, size_t cursor_pos); void global_keyboard_press(const MouseWatcherParameter ¶m); void global_keyboard_release(const MouseWatcherParameter ¶m); diff --git a/panda/src/tform/mouseWatcherParameter.I b/panda/src/tform/mouseWatcherParameter.I index 84790ceeb4..467d2a6d92 100644 --- a/panda/src/tform/mouseWatcherParameter.I +++ b/panda/src/tform/mouseWatcherParameter.I @@ -96,10 +96,12 @@ set_keycode(int keycode) { //////////////////////////////////////////////////////////////////// INLINE void MouseWatcherParameter:: set_candidate(const wstring &candidate_string, - size_t highlight_start, size_t highlight_end) { + size_t highlight_start, size_t highlight_end, + size_t cursor_pos) { _candidate_string = candidate_string; _highlight_start = highlight_start; _highlight_end = highlight_end; + _cursor_pos = cursor_pos; _flags |= F_has_candidate; } @@ -257,6 +259,17 @@ get_highlight_end() const { return _highlight_end; } +//////////////////////////////////////////////////////////////////// +// Function: MouseWatcherParameter::get_cursor_pos +// Access: Published +// Description: Returns the position of the user's edit cursor within +// the candidate string. +//////////////////////////////////////////////////////////////////// +INLINE size_t MouseWatcherParameter:: +get_cursor_pos() const { + return _cursor_pos; +} + //////////////////////////////////////////////////////////////////// // Function: MouseWatcherParameter::get_modifier_buttons // Access: Published diff --git a/panda/src/tform/mouseWatcherParameter.h b/panda/src/tform/mouseWatcherParameter.h index 7be2b41758..26925e0a12 100644 --- a/panda/src/tform/mouseWatcherParameter.h +++ b/panda/src/tform/mouseWatcherParameter.h @@ -43,7 +43,8 @@ public: INLINE void set_keycode(int keycode); INLINE void set_candidate(const wstring &candidate_string, size_t highlight_start, - size_t higlight_end); + size_t higlight_end, + size_t cursor_pos); INLINE void set_modifier_buttons(const ModifierButtons &mods); INLINE void set_mouse(const LPoint2f &mouse); INLINE void set_outside(bool flag); @@ -65,6 +66,7 @@ PUBLISHED: INLINE string get_candidate_string_encoded(TextEncoder::Encoding encoding) const; INLINE size_t get_highlight_start() const; INLINE size_t get_highlight_end() const; + INLINE size_t get_cursor_pos() const; INLINE const ModifierButtons &get_modifier_buttons() const; @@ -81,6 +83,7 @@ public: wstring _candidate_string; size_t _highlight_start; size_t _highlight_end; + size_t _cursor_pos; ModifierButtons _mods; LPoint2f _mouse;