Nux

Merge lp:~sao/nux/cursor-blink into lp:nux

Proposed by Oliver Sauder
Status: Merged
Merged at revision: 362
Proposed branch: lp:~sao/nux/cursor-blink
Merge into: lp:nux
Diff against target: 155 lines (+46/-16)
2 files modified
Nux/TextEntry.cpp (+40/-10)
Nux/TextEntry.h (+6/-6)
To merge this branch: bzr merge lp:~sao/nux/cursor-blink
Reviewer Review Type Date Requested Status
Jay Taoko (community) Approve
Review via email: mp+63400@code.launchpad.net

Description of the change

This branch is based on the work done in lp:~greggory-hz/nux/cursor-blink.

* The cursor is now always hidden when the TextEntry does not have the focus.
* Blinking of the cursor is implemented as it was outlined in the source code comment.
* Reset of the layout is needed to correctly show the blinking of the cursor.
* When the TextEntry gains focus again the cursor will now be at the same position
as when it was when losing focus.

To post a comment you must log in.
Revision history for this message
Jay Taoko (jaytaoko) wrote :

Oliver,

Thank you for your patch! Before we can accept it, we require you to agree to inalogic's contributor agreement (http://inalogic.com/license). If you accept it, send and email to <email address hidden> and state that you agree.

Revision history for this message
Oliver Sauder (sao) wrote :

Done.

Revision history for this message
Jay Taoko (jaytaoko) wrote :

I am ready to accept your branch. Due to the changes in the .h file, I cannot back-port it to Nux for and SRU. I will merge it to Nux trunk.

Thank you!

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'Nux/TextEntry.cpp'
2--- Nux/TextEntry.cpp 2011-05-27 04:08:01 +0000
3+++ Nux/TextEntry.cpp 2011-06-03 16:02:27 +0000
4@@ -137,7 +137,7 @@
5 italic_ = false;
6 multiline_ = false;
7 wrap_ = false;
8- cursor_visible_ = true;
9+ cursor_visible_ = false;
10 readonly_ = false;
11 content_modified_ = false;
12 //selection_changed_ = false;
13@@ -184,6 +184,9 @@
14
15 TextEntry::~TextEntry ()
16 {
17+ if(cursor_blink_timer_)
18+ g_source_remove(cursor_blink_timer_);
19+
20 cairo_font_options_destroy (font_options_);
21 if (_texture2D)
22 _texture2D->UnReference ();
23@@ -203,13 +206,14 @@
24
25 void TextEntry::DoSetFocused (bool focused)
26 {
27-
28+ focused_ = focused;
29+ cursor_visible_ = focused; // visibilty of cursor depends on focus
30 View::DoSetFocused (focused);
31 if (focused == true)
32 {
33 _block_focus = true;
34- SetCursor(0);
35- QueueRefresh(false, true);
36+ SetCursor(cursor_);
37+ QueueRefresh(true, true);
38
39 Area *_parent = GetParentObject();
40 if (_parent == NULL)
41@@ -226,7 +230,10 @@
42 parent->SetFocusControl (false);
43 }
44 }
45-
46+ else
47+ {
48+ QueueRefresh(true, false); // needed to hide cursor
49+ }
50 }
51
52 void TextEntry::GeometryChanged ()
53@@ -684,10 +691,11 @@
54 //gtk_im_context_focus_in(im_context_);
55 //UpdateIMCursorLocation();
56 }
57+ cursor_visible_ = true; // show cursor when getting focus
58 selection_changed_ = true;
59 cursor_moved_ = true;
60 // Don't adjust scroll.
61- QueueRefresh(false, false);
62+ QueueRefresh(true, false);
63 }
64 }
65
66@@ -701,10 +709,11 @@
67 need_im_reset_ = true;
68 //gtk_im_context_focus_out(im_context_);
69 }
70+ cursor_visible_ = false; // hide cursor when losing focus
71 selection_changed_ = true;
72 cursor_moved_ = true;
73 // Don't adjust scroll.
74- QueueRefresh(false, false);
75+ QueueRefresh(true, false);
76 }
77 }
78
79@@ -795,7 +804,7 @@
80 AdjustScroll();
81
82 QueueTextDraw();
83- //todo: QueueCursorBlink();
84+ QueueCursorBlink();
85 }
86
87 void TextEntry::ResetImContext()
88@@ -888,6 +897,27 @@
89 canvas->PopState();
90 }
91 }
92+
93+ bool TextEntry::CursorBlinkCallback(TextEntry *self)
94+ {
95+ if (self->cursor_blink_status_)
96+ self->ShowCursor();
97+ else
98+ self->HideCursor();
99+
100+ if (--self->cursor_blink_status_ < 0)
101+ self->cursor_blink_status_ = 2;
102+
103+ return true;
104+ }
105+
106+ void TextEntry::QueueCursorBlink()
107+ {
108+ if (!cursor_blink_timer_)
109+ cursor_blink_timer_ = g_timeout_add(kCursorBlinkTimeout,
110+ (GSourceFunc)&CursorBlinkCallback,
111+ this);
112+ }
113
114 void TextEntry::ShowCursor()
115 {
116@@ -897,7 +927,7 @@
117 if (focused_ && !readonly_)
118 {
119 cursor_moved_ = true;
120- QueueTextDraw();
121+ QueueRefresh(true, false);
122 }
123 }
124 }
125@@ -910,7 +940,7 @@
126 if (focused_ && !readonly_)
127 {
128 cursor_moved_ = true;
129- QueueTextDraw();
130+ QueueRefresh(true, false);
131 }
132 }
133 }
134
135=== modified file 'Nux/TextEntry.h'
136--- Nux/TextEntry.h 2011-04-28 22:28:39 +0000
137+++ Nux/TextEntry.h 2011-06-03 16:02:27 +0000
138@@ -222,12 +222,12 @@
139 // /** Set the visibility of the edit control */
140 // void SetVisibility(bool visible);
141 //
142-// /** Check if the cursor should be blinking */
143-// bool IsCursorBlinking();
144-// /** Send out a request to blink the cursor if necessary */
145-// void QueueCursorBlink();
146-// /** Timer callback to blink the cursor */
147-// bool CursorBlinkCallback(int timer_id);
148+// /** Check if the cursor should be blinking */
149+// bool IsCursorBlinking();
150+ /** Send out a request to blink the cursor if necessary */
151+ void QueueCursorBlink();
152+ static bool CursorBlinkCallback(TextEntry *data);
153+
154 void ShowCursor();
155 void HideCursor();
156

Subscribers

People subscribed via source and target branches