Spurious characters in the GtkText widget?
- From: Sachin Garg <sachin cdacb ernet in>
- To: GTK Mailing List <gtk-list redhat com>
- Subject: Spurious characters in the GtkText widget?
- Date: Sun, 24 Oct 1999 00:49:28 +0530 (IST)
Hi all,
Recently, I started using GTK+, so my question might be very basic.
Please bear with me for this long mail.
What I am trying to do is this:
Catch KeyPresses, put them in a buffer, do some processing and then
insert the processed text in a GTKText widget. The processing involves
knowing where a word ends (using the space, tab or newline
characters). If a word ending is found, advance the insertion point
using gtk_text_set_point(), else let the insertion point be at the
beginning of the word, i.e. call gtk_text_set_point() with teh old
position, which is stored in a static variable.
I am enclosing a snippet of what happens.I request u people to make
head-or-tail out of this :)
KEY_PRESS_EVENT event->keyval: 181: 0xb5 event->length 1
event->string µ
INPUT string length 1
INPUT string :
0xb5
OUTPUT string length 2
OUTPUT string :
0x4d 0xc9
Widget Text length: 2
Widget Text: MÉ
0x4d 0xc9
Widget Text Pos: 2
KLUDGE: Del Status: 0
KLUDGE: After Delete: Widget Text length: 2
KLUDGE: After Delete: Widget Text: MÉ
0x4d 0xc9
let me explain this:
The key corresponding to 0xb5 (keys have been remapped using xmodmap)
is pressed. The input buffer contains 0xb5, and after
processing the output buffer contains 0x4d 0xc9. These characters are
inserted into the text widget using gtk_text_insert(). After this, the
widget contents length, text and position are queried for using
gtk_text_get_length(), gtk_editable_get_chars() and
gtk_text_get_point() functions.
I will explain the lines starting with "KLUDGE:" later.
So far, so good.
The problem starts here:
KEY_PRESS_EVENT event->keyval: 65505: 0xffe1 event->length 0
event->string
Now this wasn't a key press! Something spurious is happening here!
event->length is zero, so NO damage done and we carry on:
KEY_PRESS_EVENT event->keyval: 197: 0xc5 event->length 1 event->string Å
INPUT string length 2
INPUT string :
0xb5 0xc5
Now the INPUT buffer contains 2 characters,
OUTPUT string length 4
OUTPUT string :
0x4d 0xc9 0x76 0xc9
and the OUTPUT buffer 4 characters
Widget Text length: 7
Widget Text: MÉvÉMɵ
0x4d 0xc9 0x76 0xc9 0x4d 0xc9 0xb5
BUT, the Widget contains 7 characters. The 3 extra characters, as can
be noticed are the previous 2 in the buffer and the previous key
press.
Widget Text Pos: 4
and the point is positioned at 4, where it should be!
KLUDGE: Del Status: 1
KLUDGE: After Delete: Widget Text length: 4
KLUDGE: After Delete: Widget Text: MÉvÉ
0x4d 0xc9 0x76 0xc9
This is something I did to prevent cluttering up the display. I simply
delete gtk_text_get_length() - gtk_text_get_point() number of
characters using gtk_text_forward_delete()
Now, carrying on:
KEY_PRESS_EVENT event->keyval: 218: 0xda event->length 1 event->string Ú
INPUT string length 3
INPUT string :
0xb5 0xc5 0xda
INPUT buffer: 3 characters,
OUTPUT string length 5
OUTPUT string :
0x4d 0xc9 0x76 0xc9 0xc9
OUTPUT buffer: 5 characters,
Widget Text length: 10
Widget Text: MÉvÉÉMÉvÉÅ
0x4d 0xc9 0x76 0xc9 0xc9 0x4d 0xc9 0x76 0xc9 0xc5
Widget Text Pos: 5
BUT, widget contains 10 characters, insertion point is at location 5.
The 5 extra characters, as can be noticed are the previous 4 in the
buffer and the previous key press.
May, I add, that since a word ending has *not* been encountered, the
insertion point remains at the old one, i.e. 0.
KLUDGE: Del Status: 1
KLUDGE: After Delete: Widget Text length: 5
KLUDGE: After Delete: Widget Text: MÉvÉÉ
0x4d 0xc9 0x76 0xc9 0xc9
Carrying on:
KEY_PRESS_EVENT event->keyval: 32: 0x20 event->length 1 event->string
INPUT string length 4
INPUT string :
0xb5 0xc5 0xda 0x20
OUTPUT string length 6
OUTPUT string :
0x4d 0xc9 0x76 0xc9 0xc9 0x20
Widget Text length: 12
Widget Text: MÉvÉÉ MÉvÉÉÚ
0x4d 0xc9 0x76 0xc9 0xc9 0x20 0x4d 0xc9 0x76 0xc9 0xc9 0xda
Widget Text Pos: 6
BUT, widget contains 12 characters, insertion point is at location 6.
The 6 extra characters, as can be noticed are the previous 5 in the
buffer and the previous key press.
KLUDGE: Del Status: 1
KLUDGE: After Delete: Widget Text length: 6
KLUDGE: After Delete: Widget Text: MÉvÉÉ
0x4d 0xc9 0x76 0xc9 0xc9 0x20
A space has been received (0x20), and the insertion point moves on to
position 6.
KEY_PRESS_EVENT event->keyval: 186: 0xba event->length 1 event->string º
INPUT string length 1
INPUT string :
0xba
OUTPUT string length 2
OUTPUT string :
0x56 0xc9
Widget Text length: 9
Widget Text: MÉvÉÉ VÉ
0x4d 0xc9 0x76 0xc9 0xc9 0x20 0x56 0xc9 0x20
Widget Text Pos: 8
KLUDGE: Del Status: 1
KLUDGE: After Delete: Widget Text length: 8
KLUDGE: After Delete: Widget Text: MÉvÉÉ VÉ
0x4d 0xc9 0x76 0xc9 0xc9 0x20 0x56 0xc9
BUT, widget contains 9 characters, insertion point is at location 8.
The 1 extra character, as can be noticed is the previous key press.
KEY_PRESS_EVENT event->keyval: 216: 0xd8 event->length 1 event->string Ø
INPUT string length 2
INPUT string :
0xba 0xd8
OUTPUT string length 4
OUTPUT string :
0x56 0xc9 0xbd 0xfe
Widget Text length: 13
Widget Text: MÉvÉÉ VɽþVɺ
0x4d 0xc9 0x76 0xc9 0xc9 0x20 0x56 0xc9 0xbd 0xfe 0x56 0xc9 0xba
Widget Text Pos: 10
KLUDGE: Del Status: 1
KLUDGE: After Delete: Widget Text length: 10
KLUDGE: After Delete: Widget Text: MÉvÉÉ Vɽþ
0x4d 0xc9 0x76 0xc9 0xc9 0x20 0x56 0xc9 0xbd 0xfe
so on, and so forth ...
Could it be, that even though I am trapping the KEY_PRESS events, they
make their way to the GtkWidget?
If so, how to disable this? Or a better method to get input into teh
GtkTextWidget?
Thanks a lot and soryy for the outrageously long mail.
Warm regards,
Sachin
Hubbard's Law:
Don't take life too seriously; you won't get out of it alive.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Sachin Garg, Member Technical Staff
Centre for Development of Advanced Computing,BANGALORE,INDIA
Phone: +91-80-5584271/143/982 Fax: +91-80-5584893
http://sangam.cjb.net <sachin@cdacb.ernet.in>
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]