Shared scrollbar between 2 Text widgets EXAMPLE
- From: Marc Aubry <marc upr41 univ-rennes1 fr>
- To: "gtk-list redhat com" <gtk-list redhat com>
- Subject: Shared scrollbar between 2 Text widgets EXAMPLE
- Date: Wed, 13 May 1998 10:48:27 +0200
As requested, here is an example of my shared scrollbar...
Version #1 (Owen's one): the program does'nt segfault but the two Text
Widgets are not scrolling together.
Version #2 (my version): the two Text Widgets are scrolling together
but the program segfaults when scrolling while there is two much lines
in one text widget !
/* Shared Scrollbar */
#include <gtk/gtk.h>
void delete_event (GtkWidget *widget, gpointer *data);
void realize_text (GtkWidget *widget, GtkWidget *text);
void text_scrolling (GtkAdjustment *adj1, GtkAdjustment *adj2);
void delete_event (GtkWidget *widget, gpointer *data)
{
gtk_main_quit ();
}
void realize_text (GtkWidget *widget, GtkWidget *text)
{
guint i;
gchar buffer[32];
gtk_text_freeze (GTK_TEXT (text));
for (i=0; i<10; i++)
{
sprintf (buffer, "One line #%d\n", i);
gtk_text_insert (GTK_TEXT (text), NULL, &text->style->black,
NULL,
buffer, -1);
}
gtk_text_thaw (GTK_TEXT (text));
}
void text_scrolling (GtkAdjustment *adj1, GtkAdjustment *adj2)
{
adj2->value = CLAMP (adj1->value, 0, adj2->upper - adj2->page_size);
gtk_signal_emit_by_name (GTK_OBJECT (adj2), "value_changed");
}
int main (int argc, char *argv[])
{
GtkWidget *window, *text, *text2;
GtkWidget *vscrollbar;
GtkWidget *main_vbox, *hbox, *textbox;
GtkWidget *button;
gtk_init (&argc, &argv);
window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
gtk_window_set_title (GTK_WINDOW (window), "Shared Scrollbar");
gtk_signal_connect (GTK_OBJECT (window), "destroy",
GTK_SIGNAL_FUNC (gtk_main_quit), NULL);
gtk_container_border_width (GTK_CONTAINER (window), 5);
gtk_widget_set_usize (GTK_WIDGET (window), 600, 400);
main_vbox = gtk_vbox_new (FALSE, 1);
gtk_container_add (GTK_CONTAINER (window), main_vbox);
textbox = gtk_hbox_new (FALSE, 0);
text = gtk_text_new (NULL, NULL);
gtk_text_set_editable (GTK_TEXT(text), TRUE);
gtk_box_pack_start (GTK_BOX(textbox), text, TRUE, TRUE, 0);
text2 = gtk_text_new (NULL, NULL);
gtk_text_set_editable (GTK_TEXT(text2), TRUE);
gtk_widget_set_usize (GTK_WIDGET (text2), 80, 0);
gtk_box_pack_start (GTK_BOX(textbox), text2, FALSE, FALSE, 0);
gtk_widget_show (text);
gtk_widget_show (text2);
vscrollbar = gtk_vscrollbar_new (GTK_TEXT (text)->vadj);
/* VERSION #1 */
// gtk_signal_connect ( GTK_OBJECT(GTK_TEXT (text)->vadj), "changed",
// GTK_SIGNAL_FUNC (text_scrolling),
GTK_TEXT(text2)->vadj )
;
/* VERSION #2 */
gtk_text_set_adjustments (GTK_TEXT (text2), NULL, GTK_TEXT
(text)->vadj);
gtk_box_pack_start (GTK_BOX(textbox), vscrollbar, FALSE, FALSE, 0);
gtk_widget_show (vscrollbar);
gtk_box_pack_start (GTK_BOX(main_vbox), textbox, TRUE, TRUE, 0);
hbox = gtk_hbox_new (TRUE, 0);
button = gtk_button_new_with_label ("Quit");
gtk_signal_connect ( GTK_OBJECT(button), "clicked",
GTK_SIGNAL_FUNC (delete_event), NULL);
gtk_box_pack_start (GTK_BOX (hbox), button, TRUE, TRUE, 0);
gtk_widget_show (button);
button = gtk_button_new_with_label ("Add Text (Left)");
gtk_signal_connect ( GTK_OBJECT(button), "clicked",
GTK_SIGNAL_FUNC (realize_text), text);
gtk_box_pack_start (GTK_BOX (hbox), button, TRUE, TRUE, 0);
gtk_widget_show (button);
button = gtk_button_new_with_label ("Add Text (Right)");
gtk_signal_connect ( GTK_OBJECT(button), "clicked",
GTK_SIGNAL_FUNC (realize_text), text2);
gtk_box_pack_start (GTK_BOX (hbox), button, TRUE, TRUE, 0);
gtk_widget_show (button);
gtk_box_pack_start (GTK_BOX(main_vbox), hbox, FALSE, FALSE, 0);
gtk_widget_show (textbox);
gtk_widget_show (hbox);
gtk_widget_show (main_vbox);
gtk_widget_show (window);
gtk_main ();
return 0;
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]