/*
 *  CWStation
 *  Copyright (c) 2004 by Thierry Leconte (F4DWV)
 *
 *      $Id: image.c,v 1.10 2004/04/24 07:19:48 f4dwv Exp $
 *
 *   This library is free software; you can redistribute it and/or modify
 *   it under the terms of the GNU Library General Public License as
 *   published by the Free Software Foundation; either version 2 of
 *   the License, or (at your option) any later version.
 *
 *   This program is distributed in the hope that it will be useful,
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *   GNU Library General Public License for more details.
 *
 *   You should have received a copy of the GNU Library General Public
 *   License along with this library; if not, write to the Free Software
 *   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 *
 */
                                                                                                                              
#include <stdlib.h>

#include <gtk/gtk.h>

#include "sound.h"

gboolean Txflag=FALSE;

void txthread(GtkWidget *app)
{
GtkTextBuffer *Text;
GtkTextMark *Mark;
GtkTextIter start,end;
GtkTextTag *tag;
gunichar c;

gdk_threads_enter();
Text=gtk_text_view_get_buffer(GTK_TEXT_VIEW(lookup_widget(app,"TxText")));
gtk_text_buffer_get_start_iter(Text,&start);
Mark=gtk_text_buffer_create_mark(Text,NULL,&start,TRUE);
gtk_text_mark_set_visible(Mark,TRUE);
tag = gtk_text_buffer_create_tag(Text, NULL, "foreground", "red", "editable" , FALSE , NULL);  
gdk_threads_leave();

do {

gdk_threads_enter();
gtk_text_buffer_get_iter_at_offset (Text, &start, 0);
gtk_text_buffer_get_iter_at_mark(Text,&end,Mark);
if(Txflag && !gtk_text_iter_is_end(&end)) {
	c=gtk_text_iter_get_char(&end);
	gtk_text_iter_forward_char(&end);
	gtk_text_buffer_move_mark(Text,Mark,&end);
	gtk_text_buffer_apply_tag (Text, tag, &start, &end);
	gdk_flush();
	gdk_threads_leave();
	writecwchar(c);
} else {
	gdk_threads_leave();
	sleep(1);
}

} while(1);
g_thread_exit(0);
}
