support cursor_pos for candidate() functions, and trigger background pgEntry on candidate action
This commit is contained in:
parent
7e1203e4a7
commit
169eee50c0
|
|
@ -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));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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();
|
||||
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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();
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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() {
|
||||
|
|
|
|||
|
|
@ -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:
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue