aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorlecoanet2007-04-23 13:06:18 +0000
committerlecoanet2007-04-23 13:06:18 +0000
commit7c5d00a56e62284cd53a21b45e7cff0e570903d3 (patch)
tree5cd2092ae7a2ebd2341e0cf93f5e8f6da1880f59
parentb027f06702b6716133c7b2ff89d345dda3189d2c (diff)
downloadtkzinc-7c5d00a56e62284cd53a21b45e7cff0e570903d3.zip
tkzinc-7c5d00a56e62284cd53a21b45e7cff0e570903d3.tar.gz
tkzinc-7c5d00a56e62284cd53a21b45e7cff0e570903d3.tar.bz2
tkzinc-7c5d00a56e62284cd53a21b45e7cff0e570903d3.tar.xz
Fix the text cursor not displayed when the text is empty
-rw-r--r--demos/textInput.tcl2
-rw-r--r--generic/Item.c1
-rw-r--r--generic/Text.c50
-rw-r--r--generic/tkZinc.c14
4 files changed, 31 insertions, 36 deletions
diff --git a/demos/textInput.tcl b/demos/textInput.tcl
index 31da1c5..79b6e40 100644
--- a/demos/textInput.tcl
+++ b/demos/textInput.tcl
@@ -41,7 +41,7 @@ namespace eval textInputDemo {
###########################################
# Zinc
##########################################
- grid [zinc $w.zinc -width 500 -height 300 -font $defaultfont -borderwidth 0] \
+ grid [zinc $w.zinc -width 500 -height 300 -render 1 -font $defaultfont -borderwidth 0] \
-row 1 -column 0 -columnspan 2 -sticky news
grid columnconfigure $w 0 -weight 1
grid columnconfigure $w 1 -weight 1
diff --git a/generic/Item.c b/generic/Item.c
index 31d747e..6739e0e 100644
--- a/generic/Item.c
+++ b/generic/Item.c
@@ -2404,6 +2404,7 @@ Invalidate(ZnItem item,
if (ISSET(item->flags, ZN_VISIBLE_BIT)) {
/*printf("invalidate graphics for item %d\n", item->id);*/
ZnDamage(item->wi, &item->item_bounding_box);
+ ZnNeedRedisplay(item->wi);
#ifdef GL
#ifdef GL_LIST
/*
diff --git a/generic/Text.c b/generic/Text.c
index 5b378bc..67ef520 100644
--- a/generic/Text.c
+++ b/generic/Text.c
@@ -57,8 +57,8 @@ static const char compile_id[] = "$Compile: " __FILE__ " " __DATE__ " " __TIME__
*/
typedef struct _TextLineInfo
{
- char *start; /* Index of first char in line */
- unsigned short num_bytes; /* Number of displayed bytes in line (NOT chars)*/
+ char *start; /* Index of first char in line */
+ unsigned short num_bytes; /* Number of displayed bytes in line (NOT chars)*/
unsigned short width; /* Line width in pixels */
unsigned short origin_x; /* X pos for drawing the line */
unsigned short origin_y;
@@ -444,37 +444,37 @@ ComputeCursor(ZnItem item,
TextLineInfo lines, lines_ptr;
unsigned int i, line_index, insert_index, num_lines;
+ if ((wi->focus_item != item) || ISCLEAR(wi->flags, ZN_GOT_FOCUS) || !ti->cursor_on) {
+ return;
+ }
num_lines = ZnListSize(text->text_info);
if (num_lines == 0) {
*cursor_line = 0;
+ *cursor_offset = 0;
+ return;
}
lines = ZnListArray(text->text_info);
- if ((wi->focus_item == item) && ISSET(wi->flags, ZN_GOT_FOCUS) && ti->cursor_on) {
- insert_index = Tcl_UtfAtIndex(text->text, (int) text->insert_index)-text->text;
- for (i = 0, lines_ptr = lines; i < num_lines; i++, lines_ptr++) {
- /*
- * Mark the line with the cursor and compute its
- * position along the X axis.
- */
- line_index = lines_ptr->start - text->text;
- if ((insert_index >= line_index) &&
- (insert_index <= line_index + lines_ptr->num_bytes)) {
- *cursor_line = i;
- *cursor_offset = Tk_TextWidth(text->font, (char *) lines_ptr->start,
- insert_index - line_index);
- }
+ insert_index = Tcl_UtfAtIndex(text->text, (int) text->insert_index) - text->text;
+ for (i = 0, lines_ptr = lines; i < num_lines; i++, lines_ptr++) {
+ /*
+ * Mark the line with the cursor and compute its
+ * position along the X axis.
+ */
+ line_index = lines_ptr->start - text->text;
+ if ((insert_index >= line_index) && (insert_index <= line_index + lines_ptr->num_bytes)) {
+ *cursor_line = i;
+ *cursor_offset = Tk_TextWidth(text->font, (char *) lines_ptr->start, insert_index - line_index);
}
}
-
}
static void
-ComputeSelection(ZnItem item,
- int *sel_first_line,
- int *sel_last_line,
- unsigned int *sel_start_offset,
- unsigned int *sel_stop_offset)
+ComputeSelection(ZnItem item,
+ int *sel_first_line,
+ int *sel_last_line,
+ unsigned int *sel_start_offset,
+ unsigned int *sel_stop_offset)
{
TextItem text = (TextItem) item;
ZnWInfo *wi = item->wi;
@@ -929,8 +929,7 @@ Draw(ZnItem item)
/*
* Setup the gc for the cursor and draw it.
*/
- if (cursor_line >= 0 &&
- (wi->focus_item == item) && ti->cursor_on) {
+ if (cursor_line >= 0) {
values.fill_style = FillSolid;
values.line_width = ti->insert_width;
values.foreground = ZnGetGradientPixel(ti->insert_color, 0.0);
@@ -1206,8 +1205,7 @@ Render(ZnItem item)
/*
* Render the cursor.
*/
- if ((cursor_line >= 0) &&
- (wi->focus_item == item) && ti->cursor_on) {
+ if (cursor_line >= 0) {
color = ZnGetGradientColor(ti->insert_color, 0.0, &alpha);
alpha = ZnComposeAlpha(alpha, wi->alpha);
glColor4us(color->red, color->green, color->blue, alpha);
diff --git a/generic/tkZinc.c b/generic/tkZinc.c
index e7d6851..df3aeb6 100644
--- a/generic/tkZinc.c
+++ b/generic/tkZinc.c
@@ -336,7 +336,7 @@ static Tk_ConfigSpec config_specs[] = {
{TK_CONFIG_BOOLEAN, "-confine", "confine", "Confine",
"1", Tk_Offset(ZnWInfo, confine), 0, NULL},
{TK_CONFIG_ACTIVE_CURSOR, "-cursor", "cursor", "Cursor",
- "", Tk_Offset(ZnWInfo, cursor), TK_CONFIG_NULL_OK, NULL},
+ "arrow", Tk_Offset(ZnWInfo, cursor), TK_CONFIG_NULL_OK, NULL},
{TK_CONFIG_FONT, "-font", "font", "Font",
"-adobe-helvetica-bold-r-normal--*-120-*-*-*-*-*-*",
Tk_Offset(ZnWInfo, font), 0, NULL},
@@ -7277,16 +7277,13 @@ Blink(ClientData client_data)
}
if (wi->text_info.cursor_on) {
wi->text_info.cursor_on = 0;
- wi->blink_handler = Tcl_CreateTimerHandler(wi->insert_off_time,
- Blink, client_data);
+ wi->blink_handler = Tcl_CreateTimerHandler(wi->insert_off_time, Blink, client_data);
}
else {
wi->text_info.cursor_on = 1;
- wi->blink_handler = Tcl_CreateTimerHandler(wi->insert_on_time,
- Blink, client_data);
+ wi->blink_handler = Tcl_CreateTimerHandler(wi->insert_on_time, Blink, client_data);
}
- if ((wi->focus_item != ZN_NO_ITEM) &&
- (wi->focus_item->class->Cursor != NULL)) {
+ if ((wi->focus_item != ZN_NO_ITEM) && (wi->focus_item->class->Cursor != NULL)) {
ZnITEM.Invalidate(wi->focus_item, ZN_DRAW_FLAG);
}
}
@@ -7300,8 +7297,7 @@ Focus(ZnWInfo *wi,
SET(wi->flags, ZN_GOT_FOCUS);
wi->text_info.cursor_on = 1;
if (wi->insert_off_time != 0) {
- wi->blink_handler = Tcl_CreateTimerHandler(wi->insert_off_time,
- Blink, (ClientData) wi);
+ wi->blink_handler = Tcl_CreateTimerHandler(wi->insert_off_time, Blink, (ClientData) wi);
}
}
else {