Gtk 1.2.8 gtk_progress_bar_update() bug update
- From: learfox furry ao net
- To: GTK Application Development List <gtk-app-devel-list gnome org>
- Subject: Gtk 1.2.8 gtk_progress_bar_update() bug update
- Date: Mon, 18 Dec 2000 18:03:27 -0800 (PST)
I've done some more testing and it appears the bug dosen't occure because
of event processing prior to freezing the GtkText widget.
Each time I run my program I get different results even when I perform
the *EXACT* same procedures.
What really appears to be the problem is gtk_progress_bar_update()
and a combination of the GtkText widget.
I've decided to just include the two functions in question.
/*
* Sets the status of the progress bar on the viewer.
*
* Value must be from 0.0 to 1.0 inclusive.
*
* Note that gtk_main_iteration() will be called when this function
* is called to update the progress bar properly.
*/
void ViewerSetStatusProgress(viewer_struct *v, gfloat percent)
{
GtkWidget *w;
gfloat p;
if(v == NULL)
return;
if(percent < 0.0)
percent = 0.0;
else if(percent > 1.0)
percent = 1.0;
w = v->status_bar_progress;
if(w == NULL)
return;
gtk_progress_set_format_string(
GTK_PROGRESS(w), "%p%%"
);
gtk_progress_set_show_text(
GTK_PROGRESS(w), (percent > 0) ? TRUE : FALSE
);
p = v->status_bar_progress_pos_last;
if(p > percent)
p = percent;
while(1)
{
if(p > percent)
p = percent;
gtk_progress_bar_update(
GTK_PROGRESS_BAR(w), p
);
/* Itterate through GTK main function until all events are
* handled so that we ensure this progress bar setting is
* updated.
*/
while(gtk_events_pending() > 0)
gtk_main_iteration();
if(p < percent)
p += (gfloat)0.05;
else
break;
}
v->status_bar_progress_pos_last = percent;
return;
}
/*
* Inserts the given buffer to the viewer's view text parsed.
*
* If buf_len is -1 then the entire given buf will be inserted,
* and in which case the given buf needs to be null terminated.
*
* Calling function is responsible for setting the starting
* text insert position.
*
* If the callback function is not NULL and returns non-zero then
* the insert will be aborted.
*/
void ViewerTextInsert(
viewer_struct *v, const char *buf, int buf_len,
void *client_data, int (*func_cb)(long, long, void *)
)
{
int status;
GtkWidget *w;
GtkText *text;
char last_char;
const char *buf_ptr, *buf_next, *buf_end;
medit_core_struct *core_ptr;
medit_styles_list_struct *styles_list;
GdkFont *cur_font = NULL;
GtkStyle *style_ptr;
if((v == NULL) || (buf == NULL))
return;
/* Get pointer to core structure. */
core_ptr = (medit_core_struct *)v->core_ptr;
if(core_ptr == NULL)
return;
/* Get pointer to styles list structure on core. */
styles_list = &core_ptr->styles_list;
/* Sanitize buffer length. */
if(buf_len < 0)
buf_len = strlen(buf);
if(buf_len == 0)
return;
/* Get view text widget pointer. */
w = v->view_text;
if(w == NULL)
return;
else
text = GTK_TEXT(w);
gtk_text_freeze(text);
/* Set current standard font. */
style_ptr = styles_list->edit_text_standard;
cur_font = (style_ptr != NULL) ? style_ptr->font : NULL;
#define IS_CTL_CHAR(c) (((c) == 0x08))
/* Itterate through buffer. */
last_char = '\0'; /* Reset last character to be printed. */
buf_ptr = buf;
buf_end = (const char *)(buf + buf_len);
while(buf_ptr < buf_end)
{
if(func_cb != NULL)
{
status = func_cb(
(long)MIN(buf_ptr - buf, buf_len), (long)buf_len,
client_data
);
if(status)
break;
}
/* Seek to next control charater if any, setting buf_next
* to point to the next control character or end of buffer.
*/
buf_next = buf_ptr;
while(buf_next < buf_end)
{
if(IS_CTL_CHAR(*buf_next))
break;
else
buf_next++;
}
/* Current character a control character? */
if(IS_CTL_CHAR(*buf_ptr))
{
/* Change style. */
style_ptr = styles_list->edit_text_standard;
/* Need to work on this. */
/* Delete one character backwards. */
gtk_text_backward_delete(text, 1);
/* Increment and insert next character. */
buf_ptr++;
if(buf_ptr < buf_end)
{
gtk_text_insert(
text,
cur_font,
NULL, /* Foreground color. */
NULL, /* Background color. */
buf_ptr,
1
);
}
/* Increment to next character. */
buf_ptr++;
}
else
{
/* Store to next control character or end of buffer. */
int seg_len = (int)(buf_next - buf_ptr);
if(seg_len > 0)
{
gtk_text_insert(
text,
cur_font,
NULL, /* Foreground color. */
NULL, /* Background color. */
buf_ptr,
seg_len
);
}
/* Seek past this segment. */
buf_ptr = (const char *)(buf_ptr + MAX(seg_len, 1));
/* Record last character to be printed. */
if((buf_ptr < buf_end) && (buf_ptr > buf))
last_char = (*(buf_ptr - 1));
}
}
#undef IS_CTL_CHAR
gtk_text_thaw(text);
return;
}
--
Sincerely, ,"-_ \|/
-Capt. Taura M. , O=__ --X--
..__ ,_JNMNNEO=_ /|\
OMNOUMmnne. {OMMNNNEEEEOO=_
UOOOBIOOOEOMMn. 'LONMMMMNNEEEOOO=.__..,,..
UUOOEUUOOOOOOOObe '"=OMMMMWNEEEOOOOO,"=OEEEOO=,._
OOUUUIEEIOONNOIUbe. "7OMMMMNNNNNWWEEEEOOOOOO" "'.
EEBNNMMMNWNWWEEIMMNe. __ 7EMMMNNNNNWWWEEEEEEEOO. " .
NNMMMMWWWMMMWEINMMMNn "=BBEEEEMMMMMMMMNNNWWWEEOOOOO=._ .
http://furry.ao.net/~learfox/
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]