Merge lp:~unity-team/nux/nux.composition-char into lp:nux/2.0
- nux.composition-char
- Merge into 2.0
Proposed by
Jay Taoko
Status: | Merged |
---|---|
Approved by: | Neil J. Patel |
Approved revision: | 589 |
Merged at revision: | 588 |
Proposed branch: | lp:~unity-team/nux/nux.composition-char |
Merge into: | lp:nux/2.0 |
Diff against target: |
716 lines (+559/-11) 10 files modified
Nux/Makefile.am (+4/-2) Nux/ProgramFramework/TestTextEntry.cpp (+175/-0) Nux/ProgramFramework/TestTextEntry.h (+79/-0) Nux/TextEntry.cpp (+9/-0) Nux/TextEntry.h (+22/-6) configure.ac (+1/-1) tests/Makefile.am (+12/-2) tests/Readme.txt (+3/-0) tests/gtest-nux-textentry.cpp (+95/-0) tests/xtest-text-entry-logic.cpp (+159/-0) |
To merge this branch: | bzr merge lp:~unity-team/nux/nux.composition-char |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Neil J. Patel (community) | Approve | ||
Tim Penhey (community) | Needs Fixing | ||
Review via email: mp+95652@code.launchpad.net |
Commit message
Description of the change
UNBLOCK
* Switch the TextEntry to text input mode (TextEntry:
Fix bug #944674
To post a comment you must log in.
Revision history for this message
Neil J. Patel (njpatel) wrote : | # |
Looks good, passes all tests, thanks Jay!
review:
Approve
Preview Diff
[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1 | === modified file 'Nux/Makefile.am' |
2 | --- Nux/Makefile.am 2012-02-26 03:55:44 +0000 |
3 | +++ Nux/Makefile.am 2012-03-05 19:35:25 +0000 |
4 | @@ -201,11 +201,13 @@ |
5 | |
6 | nuxprogramframework_cpp = \ |
7 | $(srcdir)/ProgramFramework/ProgramTemplate.cpp \ |
8 | - $(srcdir)/ProgramFramework/TestView.cpp |
9 | + $(srcdir)/ProgramFramework/TestView.cpp \ |
10 | + $(srcdir)/ProgramFramework/TestTextEntry.cpp |
11 | |
12 | nuxprogramframework_h = \ |
13 | $(srcdir)/ProgramFramework/ProgramTemplate.h \ |
14 | - $(srcdir)/ProgramFramework/TestView.h |
15 | + $(srcdir)/ProgramFramework/TestView.h \ |
16 | + $(srcdir)/ProgramFramework/TestTextEntry.h |
17 | |
18 | |
19 | libnux_@NUX_API_VERSION@_la_SOURCES = \ |
20 | |
21 | === added file 'Nux/ProgramFramework/TestTextEntry.cpp' |
22 | --- Nux/ProgramFramework/TestTextEntry.cpp 1970-01-01 00:00:00 +0000 |
23 | +++ Nux/ProgramFramework/TestTextEntry.cpp 2012-03-05 19:35:25 +0000 |
24 | @@ -0,0 +1,175 @@ |
25 | +/* |
26 | + * Copyright 2012 Inalogic Inc. |
27 | + * |
28 | + * This program is free software: you can redistribute it and/or modify it |
29 | + * under the terms of the GNU General Public License version 3, as published |
30 | + * by the Free Software Foundation. |
31 | + * |
32 | + * This program is distributed in the hope that it will be useful, but |
33 | + * WITHOUT ANY WARRANTY; without even the implied warranties of |
34 | + * MERCHANTABILITY, SATISFACTORY QUALITY or FITNESS FOR A PARTICULAR |
35 | + * PURPOSE. See the GNU General Public License for more details. |
36 | + * |
37 | + * You should have received a copy of the GNU General Public License |
38 | + * version 3 along with this program. If not, see |
39 | + * <http://www.gnu.org/licenses/> |
40 | + * |
41 | + * Authored by: Jay Taoko <jaytaoko@inalogic.com> |
42 | + * |
43 | + */ |
44 | + |
45 | +#include "Nux/Nux.h" |
46 | +#include "TestTextEntry.h" |
47 | + |
48 | +/* |
49 | + TestTextEntry: |
50 | + This class is a Nux view that processes all mouse events that it receives. It is meant for testing simulated |
51 | + mouse events. |
52 | +*/ |
53 | +namespace nux { |
54 | +NUX_IMPLEMENT_OBJECT_TYPE(TestTextEntry); |
55 | + |
56 | +TestTextEntry::TestTextEntry(NUX_FILE_LINE_DECL) |
57 | +: nux::TextEntry("", NUX_FILE_LINE_PARAM) |
58 | +{ |
59 | + ResetEvents(); |
60 | + ResetKeyFocusEvents(); |
61 | + |
62 | + key_nav_direction_ = nux::KEY_NAV_NONE; |
63 | + |
64 | + has_focus_ = false; |
65 | + mouse_in_ = false; |
66 | + mouse_mouse_drag_ = false; |
67 | + mouse_mouse_down_ = false; |
68 | + |
69 | + mouse_down.connect(sigc::mem_fun(this, &TestTextEntry::OnMouseDown)); |
70 | + mouse_up.connect(sigc::mem_fun(this, &TestTextEntry::OnMouseUp)); |
71 | + mouse_drag.connect(sigc::mem_fun(this, &TestTextEntry::OnMouseDrag)); |
72 | + mouse_click.connect(sigc::mem_fun(this, &TestTextEntry::OnMouseClick)); |
73 | + mouse_double_click.connect(sigc::mem_fun(this, &TestTextEntry::OnMouseDoubleClick)); |
74 | + mouse_move.connect(sigc::mem_fun(this, &TestTextEntry::OnMouseMove)); |
75 | + mouse_enter.connect(sigc::mem_fun(this, &TestTextEntry::OnMouseEnter)); |
76 | + mouse_leave.connect(sigc::mem_fun(this, &TestTextEntry::OnMouseLeave)); |
77 | + key_nav_focus_change.connect(sigc::mem_fun(this, &TestTextEntry::OnKeyNavFocusChange)); |
78 | + begin_key_focus.connect(sigc::mem_fun(this, &TestTextEntry::OnBeginKeyFocus)); |
79 | + end_key_focus.connect(sigc::mem_fun(this, &TestTextEntry::OnEndKeyFocus)); |
80 | + object_destroyed.connect(sigc::mem_fun(this, &TestTextEntry::OnObjectDestroyed)); |
81 | + |
82 | + text_changed.connect(sigc::mem_fun(this, &TestTextEntry::OnTextChanged)); |
83 | + |
84 | + |
85 | +} |
86 | + |
87 | +TestTextEntry::~TestTextEntry() |
88 | +{ |
89 | + |
90 | +} |
91 | + |
92 | +void TestTextEntry::ResetEvents() |
93 | +{ |
94 | + registered_mouse_down_ = false; |
95 | + registered_mouse_up_ = false; |
96 | + registered_mouse_drag_ = false; |
97 | + registered_mouse_enter_ = false; |
98 | + registered_mouse_leave_ = false; |
99 | + registered_mouse_click_ = false; |
100 | + registered_mouse_double_click_ = false; |
101 | + registered_mouse_move_ = false; |
102 | + registered_mouse_enter_ = false; |
103 | + registered_mouse_leave_ = false; |
104 | + registered_object_destroyed_ = false; |
105 | + registered_text_changed_ = false; |
106 | +} |
107 | + |
108 | +void TestTextEntry::ResetKeyFocusEvents() |
109 | +{ |
110 | + registered_begin_keynav_focus_ = false; |
111 | + registered_end_keynav_focus_ = false; |
112 | +} |
113 | + |
114 | +void TestTextEntry::OnMouseDown(int x, int y, unsigned long button_flags, unsigned long key_flags) |
115 | +{ |
116 | + registered_mouse_down_ = true; |
117 | + mouse_mouse_down_ = true; |
118 | + QueueDraw(); |
119 | +} |
120 | + |
121 | +void TestTextEntry::OnMouseUp(int x, int y, unsigned long button_flags, unsigned long key_flags) |
122 | +{ |
123 | + registered_mouse_up_ = true; |
124 | + |
125 | + mouse_mouse_down_ = false; |
126 | + mouse_mouse_drag_ = false; |
127 | + QueueDraw(); |
128 | +} |
129 | + |
130 | +void TestTextEntry::OnMouseDrag(int x, int y, int dx, int dy, unsigned long button_flags, unsigned long key_flags) |
131 | +{ |
132 | + registered_mouse_drag_ = true; |
133 | + mouse_mouse_drag_ = true; |
134 | + QueueDraw(); |
135 | +} |
136 | + |
137 | +void TestTextEntry::OnMouseClick(int x, int y, unsigned long button_flags, unsigned long key_flags) |
138 | +{ |
139 | + registered_mouse_click_ = true; |
140 | + QueueDraw(); |
141 | +} |
142 | + |
143 | +void TestTextEntry::OnMouseDoubleClick(int x, int y, unsigned long button_flags, unsigned long key_flags) |
144 | +{ |
145 | + registered_mouse_double_click_ = true; |
146 | + mouse_mouse_down_ = true; |
147 | + QueueDraw(); |
148 | +} |
149 | + |
150 | +void TestTextEntry::OnMouseMove(int x, int y, int dx, int dy, unsigned long button_flags, unsigned long key_flags) |
151 | +{ |
152 | + registered_mouse_move_ = true; |
153 | + QueueDraw(); |
154 | +} |
155 | + |
156 | +void TestTextEntry::OnMouseEnter(int x, int y, unsigned long button_flags, unsigned long key_flags) |
157 | +{ |
158 | + registered_mouse_enter_ = true; |
159 | + mouse_in_ = true; |
160 | + QueueDraw(); |
161 | +} |
162 | + |
163 | +void TestTextEntry::OnMouseLeave(int x, int y, unsigned long button_flags, unsigned long key_flags) |
164 | +{ |
165 | + registered_mouse_leave_ = true; |
166 | + mouse_in_ = false; |
167 | + QueueDraw(); |
168 | +} |
169 | + |
170 | +void TestTextEntry::OnKeyNavFocusChange(nux::Area* area, bool has_focus, nux::KeyNavDirection direction) |
171 | +{ |
172 | + has_focus_ = HasKeyFocus(); |
173 | + |
174 | + has_focus_ = has_focus; |
175 | + key_nav_direction_ = direction; |
176 | + QueueDraw(); |
177 | +} |
178 | + |
179 | +void TestTextEntry::OnBeginKeyFocus() |
180 | +{ |
181 | + registered_begin_keynav_focus_ = true; |
182 | +} |
183 | + |
184 | +void TestTextEntry::OnEndKeyFocus() |
185 | +{ |
186 | + registered_end_keynav_focus_ = true; |
187 | +} |
188 | + |
189 | +void TestTextEntry::OnObjectDestroyed(nux::Object* object) |
190 | +{ |
191 | + registered_object_destroyed_ = true; |
192 | +} |
193 | + |
194 | +void TestTextEntry::OnTextChanged(TextEntry* text_entry) |
195 | +{ |
196 | + registered_text_changed_ = true; |
197 | +} |
198 | + |
199 | +} |
200 | |
201 | === added file 'Nux/ProgramFramework/TestTextEntry.h' |
202 | --- Nux/ProgramFramework/TestTextEntry.h 1970-01-01 00:00:00 +0000 |
203 | +++ Nux/ProgramFramework/TestTextEntry.h 2012-03-05 19:35:25 +0000 |
204 | @@ -0,0 +1,79 @@ |
205 | +/* |
206 | + * Copyright 2012 Inalogic Inc. |
207 | + * |
208 | + * This program is free software: you can redistribute it and/or modify it |
209 | + * under the terms of the GNU General Public License version 3, as published |
210 | + * by the Free Software Foundation. |
211 | + * |
212 | + * This program is distributed in the hope that it will be useful, but |
213 | + * WITHOUT ANY WARRANTY; without even the implied warranties of |
214 | + * MERCHANTABILITY, SATISFACTORY QUALITY or FITNESS FOR A PARTICULAR |
215 | + * PURPOSE. See the GNU General Public License for more details. |
216 | + * |
217 | + * You should have received a copy of the GNU General Public License |
218 | + * version 3 along with this program. If not, see |
219 | + * <http://www.gnu.org/licenses/> |
220 | + * |
221 | + * Authored by: Jay Taoko <jaytaoko@inalogic.com> |
222 | + * |
223 | + */ |
224 | + |
225 | +#ifndef TEST_TEXT_ENTRY_H |
226 | +#define TEST_TEXT_ENTRY_H |
227 | + |
228 | +#include "Nux/TextEntry.h" |
229 | + |
230 | +namespace nux { |
231 | +class TestTextEntry: public nux::TextEntry |
232 | +{ |
233 | + NUX_DECLARE_OBJECT_TYPE(TestTextEntry, TextEntry); |
234 | +public: |
235 | + TestTextEntry(NUX_FILE_LINE_PROTO); |
236 | + ~TestTextEntry(); |
237 | + |
238 | + void ResetEvents(); |
239 | + void ResetKeyFocusEvents(); |
240 | + |
241 | + bool has_focus_; |
242 | + bool registered_mouse_down_; |
243 | + bool registered_mouse_up_; |
244 | + bool registered_mouse_drag_; |
245 | + bool registered_mouse_click_; |
246 | + bool registered_mouse_double_click_; |
247 | + bool registered_mouse_move_; |
248 | + bool registered_mouse_enter_; |
249 | + bool registered_mouse_leave_; |
250 | + bool registered_object_destroyed_; |
251 | + |
252 | + bool registered_begin_keynav_focus_; |
253 | + bool registered_end_keynav_focus_; |
254 | + |
255 | + bool registered_text_changed_; |
256 | + |
257 | + nux::KeyNavDirection key_nav_direction_; //!< The key nav direction received when the view obtained the focus. |
258 | + |
259 | +protected: |
260 | + bool mouse_in_; |
261 | + bool mouse_mouse_drag_; |
262 | + bool mouse_mouse_down_; |
263 | + |
264 | + |
265 | + void OnMouseDown(int x, int y, unsigned long button_flags, unsigned long key_flags); |
266 | + void OnMouseUp(int x, int y, unsigned long button_flags, unsigned long key_flags); |
267 | + void OnMouseDrag(int x, int y, int dx, int dy, unsigned long button_flags, unsigned long key_flags); |
268 | + void OnMouseClick(int x, int y, unsigned long button_flags, unsigned long key_flags); |
269 | + void OnMouseDoubleClick(int x, int y, unsigned long button_flags, unsigned long key_flags); |
270 | + void OnMouseMove(int x, int y, int dx, int dy, unsigned long button_flags, unsigned long key_flags); |
271 | + void OnMouseEnter(int x, int y, unsigned long button_flags, unsigned long key_flags); |
272 | + void OnMouseLeave(int x, int y, unsigned long button_flags, unsigned long key_flags); |
273 | + void OnKeyNavFocusChange(nux::Area* area, bool has_focus, nux::KeyNavDirection direction); |
274 | + void OnBeginKeyFocus(); |
275 | + void OnEndKeyFocus(); |
276 | + void OnObjectDestroyed(Object* object); |
277 | + |
278 | + void OnTextChanged(TextEntry* text_entry); |
279 | +}; |
280 | + |
281 | +} |
282 | +#endif // TEST_TEXT_ENTRY_H |
283 | + |
284 | |
285 | === modified file 'Nux/TextEntry.cpp' |
286 | --- Nux/TextEntry.cpp 2012-03-01 22:52:45 +0000 |
287 | +++ Nux/TextEntry.cpp 2012-03-05 19:35:25 +0000 |
288 | @@ -590,6 +590,8 @@ |
289 | selection_bound_ = 0; |
290 | need_im_reset_ = true; |
291 | //ResetImContext(); |
292 | + |
293 | + text_input_mode_ = true; |
294 | QueueRefresh(true, true); |
295 | text_changed.emit(this); |
296 | } |
297 | @@ -1497,6 +1499,7 @@ |
298 | } |
299 | |
300 | ResetLayout(); |
301 | + text_input_mode_ = true; |
302 | text_changed.emit(this); |
303 | } |
304 | |
305 | @@ -1528,6 +1531,7 @@ |
306 | selection_bound_ -= (end - start); |
307 | |
308 | ResetLayout(); |
309 | + text_input_mode_ = true; |
310 | text_changed.emit(this); |
311 | } |
312 | |
313 | @@ -2269,4 +2273,9 @@ |
314 | return lose_key_focus_on_key_nav_direction_down_; |
315 | } |
316 | |
317 | + bool TextEntry::IsInTextInputMode() const |
318 | + { |
319 | + return text_input_mode_; |
320 | + } |
321 | + |
322 | } |
323 | |
324 | === modified file 'Nux/TextEntry.h' |
325 | --- Nux/TextEntry.h 2012-03-01 06:11:05 +0000 |
326 | +++ Nux/TextEntry.h 2012-03-05 19:35:25 +0000 |
327 | @@ -186,6 +186,27 @@ |
328 | |
329 | bool GetLoseKeyFocusOnKeyNavDirectionDown() const; |
330 | |
331 | + /*! |
332 | + Return True if the text has been modified after the text entry has received the keyboard focus.\n |
333 | + If the text entry already has characters typed in and it gets the keyboard focus, this function return false |
334 | + while the text has not been modified. The text can be modified either by typing new characters or addind text |
335 | + through TextEntry::SetText, TextEntry::EnterText, TextEntry::DeleteText. |
336 | + If this text entry does not have the keyboard focus, this function returns false. |
337 | + |
338 | + @return True after the text entry has received the keyboard focus and text has been typed in. |
339 | + */ |
340 | + bool IsInTextInputMode() const; |
341 | + |
342 | + /*! |
343 | + Insert text at current caret position. |
344 | + */ |
345 | + void EnterText(const char* str); |
346 | + |
347 | + /*! |
348 | + Delete text in a specified range, in number of characters. |
349 | + */ |
350 | + void DeleteText(int start, int end); |
351 | + |
352 | protected: |
353 | bool _block_focus; // used to selectively ignore focus keyevents |
354 | |
355 | @@ -280,11 +301,6 @@ |
356 | /** Get previous char length before index, in number of bytes. */ |
357 | int GetPrevCharLength(int index); |
358 | |
359 | - /** Insert text at current caret position */ |
360 | - void EnterText(const char* str); |
361 | - /** Delete text in a specified range, in number of characters. */ |
362 | - void DeleteText(int start, int end); |
363 | - |
364 | /** Select the current word under cursor */ |
365 | void SelectWord(); |
366 | /** Select the current display line under cursor */ |
367 | @@ -444,7 +460,7 @@ |
368 | #endif |
369 | bool ime_active_; |
370 | |
371 | - bool text_input_mode_; |
372 | + bool text_input_mode_; //!< Transient state of the TextEntry. \sa IsInTextInputMode. |
373 | bool key_nav_mode_; |
374 | |
375 | bool lose_key_focus_on_key_nav_direction_up_; |
376 | |
377 | === modified file 'configure.ac' |
378 | --- configure.ac 2012-03-01 16:13:25 +0000 |
379 | +++ configure.ac 2012-03-05 19:35:25 +0000 |
380 | @@ -22,7 +22,7 @@ |
381 | # The number format is : year/month/day |
382 | # e.g.: december 5th, 2011 is: 20111205 |
383 | # To make more than one API change in a day, add a number to the date. Like 20111205.xx |
384 | -m4_define([nux_abi_version], [20120301.01]) |
385 | +m4_define([nux_abi_version], [20120305.01]) |
386 | |
387 | m4_define([nux_version], |
388 | [nux_major_version.nux_minor_version.nux_micro_version]) |
389 | |
390 | === modified file 'tests/Makefile.am' |
391 | --- tests/Makefile.am 2012-02-26 01:57:06 +0000 |
392 | +++ tests/Makefile.am 2012-03-05 19:35:25 +0000 |
393 | @@ -14,7 +14,8 @@ |
394 | xtest-focus-on-mouse-down \ |
395 | xtest-keynav-directions \ |
396 | xtest-text-entry \ |
397 | - xtest-focus-on-mouse-enter |
398 | + xtest-text-entry-logic \ |
399 | + xtest-focus-on-mouse-enter |
400 | |
401 | # Please keep alphabetical |
402 | # test_nux_SOURCES = \ |
403 | @@ -85,6 +86,7 @@ |
404 | gtest-nux-emmetrics.cpp \ |
405 | gtest-nux-main.cpp \ |
406 | gtest-nux-statictext.cpp \ |
407 | + gtest-nux-textentry.cpp \ |
408 | gtest-nux-view.cpp \ |
409 | gtest-nux-windowcompositor.cpp \ |
410 | gtest-nux-windowthread.cpp |
411 | @@ -238,6 +240,13 @@ |
412 | xtest_text_entry_LDADD = $(TestLibs) |
413 | xtest_text_entry_LDFLAGS = -lpthread -lXtst |
414 | |
415 | +xtest_text_entry_logic_SOURCES = xtest-text-entry-logic.cpp \ |
416 | + nux_automated_test_framework.cpp \ |
417 | + nux_automated_test_framework.h |
418 | + |
419 | +xtest_text_entry_logic_CPPFLAGS = $(TestFlags) |
420 | +xtest_text_entry_logic_LDADD = $(TestLibs) |
421 | +xtest_text_entry_logic_LDFLAGS = -lpthread -lXtst |
422 | |
423 | #run make test as part of make check |
424 | check-local: test gtest test-apps |
425 | @@ -252,7 +261,7 @@ |
426 | check-headless: gtest-nuxcore |
427 | @gtester --verbose -k -o=test-nux-results.xml ./gtest-nuxcore |
428 | |
429 | -test-apps: test-graphics-display test-empty-window xtest-text-entry xtest-button xtest-mouse-events xtest-mouse-buttons xtest-hgrid-key-navigation xtest-hlayout-key-navigation xtest-vlayout-key-navigation xtest-scrollbar xtest-focus-on-mouse-down xtest-focus-on-mouse-enter xtest-keynav-directions |
430 | +test-apps: test-graphics-display test-empty-window xtest-text-entry xtest-button xtest-mouse-events xtest-mouse-buttons xtest-hgrid-key-navigation xtest-hlayout-key-navigation xtest-vlayout-key-navigation xtest-scrollbar xtest-focus-on-mouse-down xtest-focus-on-mouse-enter xtest-keynav-directions xtest-text-entry-logic |
431 | ./test-graphics-display |
432 | ./test-empty-window |
433 | ./xtest-text-entry |
434 | @@ -266,6 +275,7 @@ |
435 | ./xtest-focus-on-mouse-down |
436 | ./xtest-focus-on-mouse-enter |
437 | ./xtest-keynav-directions |
438 | + ./xtest-text-entry-logic |
439 | |
440 | check-report: |
441 | @gtester -k -o=test-nux-results.xml -k ./test-nux \ |
442 | |
443 | === modified file 'tests/Readme.txt' |
444 | --- tests/Readme.txt 2012-02-23 00:32:36 +0000 |
445 | +++ tests/Readme.txt 2012-03-05 19:35:25 +0000 |
446 | @@ -56,3 +56,6 @@ |
447 | |
448 | xtest-text-entry |
449 | Simulate various operations on the text entry |
450 | + |
451 | +xtest-text-entry-logic |
452 | + Test the state of TextEntry::text_input_mode_ before and after some text is typed in. |
453 | |
454 | === added file 'tests/gtest-nux-textentry.cpp' |
455 | --- tests/gtest-nux-textentry.cpp 1970-01-01 00:00:00 +0000 |
456 | +++ tests/gtest-nux-textentry.cpp 2012-03-05 19:35:25 +0000 |
457 | @@ -0,0 +1,95 @@ |
458 | +#include <string> |
459 | +#include <fstream> |
460 | + |
461 | +#include <iostream> |
462 | +#include <gmock/gmock.h> |
463 | +#include <boost/filesystem.hpp> |
464 | +#include <glib.h> |
465 | + |
466 | +#include "Nux/Nux.h" |
467 | +#include "Nux/TextEntry.h" |
468 | + |
469 | + |
470 | +using namespace testing; |
471 | + |
472 | +namespace { |
473 | + |
474 | +TEST(TestTextEntry, TestSetText) |
475 | +{ |
476 | + nux::NuxInitialize(0); |
477 | + nux::WindowThread* wnd_thread = nux::CreateNuxWindow("Nux Window", 300, 200, |
478 | + nux::WINDOWSTYLE_NORMAL, NULL, false, NULL, NULL); |
479 | + |
480 | + nux::TextEntry* text_entry = new nux::TextEntry(""); |
481 | + |
482 | + nux::GetWindowThread()->GetWindowCompositor().SetKeyFocusArea(text_entry); |
483 | + |
484 | + EXPECT_EQ(text_entry->IsInTextInputMode(), false); |
485 | + |
486 | + text_entry->SetText("Nux"); |
487 | + EXPECT_EQ(text_entry->GetText() == std::string("Nux"), true); |
488 | + |
489 | + EXPECT_EQ(text_entry->IsInTextInputMode(), true); |
490 | + |
491 | + text_entry->UnReference(); |
492 | + delete wnd_thread; |
493 | +} |
494 | + |
495 | +TEST(TestTextEntry, TestEnterText) |
496 | +{ |
497 | + nux::NuxInitialize(0); |
498 | + nux::WindowThread* wnd_thread = nux::CreateNuxWindow("Nux Window", 300, 200, |
499 | + nux::WINDOWSTYLE_NORMAL, NULL, false, NULL, NULL); |
500 | + |
501 | + nux::TextEntry* text_entry = new nux::TextEntry(""); |
502 | + |
503 | + nux::GetWindowThread()->GetWindowCompositor().SetKeyFocusArea(text_entry); |
504 | + |
505 | + EXPECT_EQ(text_entry->IsInTextInputMode(), false); |
506 | + |
507 | + text_entry->EnterText("Nux"); |
508 | + |
509 | + EXPECT_EQ(text_entry->GetText() == std::string("Nux"), true); |
510 | + |
511 | + EXPECT_EQ(text_entry->IsInTextInputMode(), true); |
512 | + |
513 | + text_entry->UnReference(); |
514 | + delete wnd_thread; |
515 | +} |
516 | + |
517 | +TEST(TestTextEntry, TestDeleteText) |
518 | +{ |
519 | + nux::NuxInitialize(0); |
520 | + nux::WindowThread* wnd_thread = nux::CreateNuxWindow("Nux Window", 300, 200, |
521 | + nux::WINDOWSTYLE_NORMAL, NULL, false, NULL, NULL); |
522 | + |
523 | + nux::TextEntry* text_entry = new nux::TextEntry(""); |
524 | + |
525 | + nux::GetWindowThread()->GetWindowCompositor().SetKeyFocusArea(text_entry); |
526 | + |
527 | + EXPECT_EQ(text_entry->IsInTextInputMode(), false); |
528 | + |
529 | + text_entry->EnterText("Nux"); |
530 | + |
531 | + EXPECT_EQ(text_entry->GetText() == std::string("Nux"), true); |
532 | + |
533 | + EXPECT_EQ(text_entry->IsInTextInputMode(), true); |
534 | + |
535 | + nux::GetWindowThread()->GetWindowCompositor().SetKeyFocusArea(NULL); |
536 | + |
537 | + nux::GetWindowThread()->GetWindowCompositor().SetKeyFocusArea(text_entry); |
538 | + |
539 | + EXPECT_EQ(text_entry->IsInTextInputMode(), false); |
540 | + |
541 | + text_entry->DeleteText(0, 3); |
542 | + |
543 | + EXPECT_EQ(text_entry->GetText() == std::string(""), true); |
544 | + |
545 | + EXPECT_EQ(text_entry->IsInTextInputMode(), true); |
546 | + |
547 | + |
548 | + text_entry->UnReference(); |
549 | + delete wnd_thread; |
550 | +} |
551 | + |
552 | +} |
553 | |
554 | === added file 'tests/xtest-text-entry-logic.cpp' |
555 | --- tests/xtest-text-entry-logic.cpp 1970-01-01 00:00:00 +0000 |
556 | +++ tests/xtest-text-entry-logic.cpp 2012-03-05 19:35:25 +0000 |
557 | @@ -0,0 +1,159 @@ |
558 | +/* |
559 | + * Copyright 2010 Inalogic Inc. |
560 | + * |
561 | + * This program is free software: you can redistribute it and/or modify it |
562 | + * under the terms of the GNU General Public License version 3, as published |
563 | + * by the Free Software Foundation. |
564 | + * |
565 | + * This program is distributed in the hope that it will be useful, but |
566 | + * WITHOUT ANY WARRANTY; without even the implied warranties of |
567 | + * MERCHANTABILITY, SATISFACTORY QUALITY or FITNESS FOR A PARTICULAR |
568 | + * PURPOSE. See the GNU General Public License for more details. |
569 | + * |
570 | + * You should have received a copy of the GNU General Public License |
571 | + * version 3 along with this program. If not, see |
572 | + * <http://www.gnu.org/licenses/> |
573 | + * |
574 | + * Authored by: Jay Taoko <jaytaoko@inalogic.com> |
575 | + * |
576 | + */ |
577 | + |
578 | +#include "Nux/Nux.h" |
579 | +#include "Nux/WindowThread.h" |
580 | +#include "Nux/VLayout.h" |
581 | +#include "Nux/TextEntry.h" |
582 | +#include "Nux/InputMethodIBus.h" |
583 | +#include "Nux/ProgramFramework/ProgramTemplate.h" |
584 | +#include "Nux/ProgramFramework/TestView.h" |
585 | +#include "Nux/ProgramFramework/TestTextEntry.h" |
586 | +#include <X11/extensions/XTest.h> |
587 | +#include <X11/keysym.h> |
588 | +#include "nux_automated_test_framework.h" |
589 | + |
590 | +class TestTextEntry: public ProgramTemplate |
591 | +{ |
592 | +public: |
593 | + TestTextEntry(const char* program_name, int window_width, int window_height, int program_life_span); |
594 | + ~TestTextEntry(); |
595 | + |
596 | + virtual void UserInterfaceSetup(); |
597 | + |
598 | + void ResetEvents(); |
599 | + |
600 | + nux::TestTextEntry* text_entry_; |
601 | + |
602 | +}; |
603 | + |
604 | +TestTextEntry::TestTextEntry(const char* program_name, |
605 | + int window_width, |
606 | + int window_height, |
607 | + int program_life_span) |
608 | + : ProgramTemplate(program_name, window_width, window_height, program_life_span) |
609 | + , text_entry_(NULL) |
610 | +{ |
611 | + ResetEvents(); |
612 | +} |
613 | + |
614 | +TestTextEntry::~TestTextEntry() |
615 | +{ |
616 | + |
617 | +} |
618 | + |
619 | +void TestTextEntry::ResetEvents() |
620 | +{ |
621 | + if (text_entry_) |
622 | + text_entry_->ResetEvents(); |
623 | +} |
624 | + |
625 | +void TestTextEntry::UserInterfaceSetup() |
626 | +{ |
627 | + nux::VLayout* main_layout = new nux::VLayout(NUX_TRACKER_LOCATION); |
628 | + text_entry_ = new nux::TestTextEntry(NUX_TRACKER_LOCATION); |
629 | + text_entry_->SetFontSize(76); |
630 | + |
631 | + main_layout->AddView(text_entry_, 0, nux::MINOR_POSITION_CENTER, nux::MINOR_SIZE_FULL); |
632 | + main_layout->SetSpaceBetweenChildren(10); |
633 | + main_layout->SetContentDistribution(nux::MAJOR_POSITION_CENTER); |
634 | + |
635 | + static_cast<nux::WindowThread*>(window_thread_)->SetLayout(main_layout); |
636 | + |
637 | + nux::ColorLayer background(nux::Color(0xFF4D4D4D)); |
638 | + static_cast<nux::WindowThread*>(window_thread_)->SetWindowBackgroundPaintLayer(&background); |
639 | +} |
640 | + |
641 | +TestTextEntry* test_textentry = NULL; |
642 | + |
643 | +void TestingThread(nux::NThread* thread, void* user_data) |
644 | +{ |
645 | + while (test_textentry->ReadyToGo() == false) |
646 | + { |
647 | + nuxDebugMsg("Waiting to start"); |
648 | + nux::SleepForMilliseconds(300); |
649 | + } |
650 | + |
651 | + nux::SleepForMilliseconds(1300); |
652 | + |
653 | + nux::WindowThread* wnd_thread = static_cast<nux::WindowThread*>(user_data); |
654 | + |
655 | + NuxAutomatedTestFramework test(wnd_thread); |
656 | + |
657 | + test.Startup(); |
658 | + |
659 | + test.TestReportMsg(test_textentry->text_entry_, "TextEntry created"); |
660 | + |
661 | + test_textentry->ResetEvents(); |
662 | + test.ViewSendMouseMotionToCenter(test_textentry->text_entry_); |
663 | + |
664 | + test.TestReportMsg(test_textentry->text_entry_->HasKeyFocus() == false, "Focus test"); |
665 | + test.TestReportMsg(test_textentry->text_entry_->IsInTextInputMode() == false, "Text input mode test"); |
666 | + test.ViewSendMouseClick(0, 1); |
667 | + test.TestReportMsg(test_textentry->text_entry_->HasKeyFocus() == true, "Focus test"); |
668 | + test.TestReportMsg(test_textentry->text_entry_->IsInTextInputMode() == false, "Text input mode test"); |
669 | + |
670 | + // Type "Nux" |
671 | + // The cursor is at the end of the line |
672 | + // Simulate CTRL+A to select the entire text |
673 | + // Simulate DELETE key to delete the text |
674 | + { |
675 | + test.ViewSendString("Nux"); |
676 | + test.TestReportMsg(test_textentry->text_entry_->GetText() == "Nux", "Typed \"Nux\""); |
677 | + |
678 | + test.TestReportMsg(test_textentry->text_entry_->IsInTextInputMode() == true, "Text input mode test"); |
679 | + |
680 | + test.ViewSendCtrlA(); |
681 | + nux::SleepForMilliseconds(500); |
682 | + test.TestReportMsg(test_textentry->text_entry_->GetTextSelection() == "Nux", "Selection is \"Nux\""); |
683 | + |
684 | + test.ViewSendDelete(); |
685 | + nux::SleepForMilliseconds(500); |
686 | + test.TestReportMsg(test_textentry->text_entry_->GetText() == "", "TextEntry is empty"); |
687 | + } |
688 | + |
689 | + if (test.WhenDoneTerminateProgram()) |
690 | + { |
691 | + wnd_thread->ExitMainLoop(); |
692 | + } |
693 | + nuxDebugMsg("Exit testing thread"); |
694 | +} |
695 | + |
696 | +int main(int argc, char** argv) |
697 | +{ |
698 | + int xstatus = XInitThreads(); |
699 | + nuxAssertMsg(xstatus > 0, "XInitThreads has failed"); |
700 | + |
701 | + test_textentry = new TestTextEntry("Text Entry", 600, 200, 10000); |
702 | + test_textentry->Startup(); |
703 | + test_textentry->UserInterfaceSetup(); |
704 | + |
705 | + nux::SystemThread* test_thread = nux::CreateSystemThread(NULL, &TestingThread, test_textentry->GetWindowThread()); |
706 | + |
707 | + test_thread->Start(test_textentry); |
708 | + |
709 | + test_textentry->Run(); |
710 | + |
711 | + delete test_thread; |
712 | + delete test_textentry; |
713 | + |
714 | + return 0; |
715 | +} |
716 | + |
Jay, can you change the description to explain what the problem was and how this branch fixes it?
Also, tests :-)