I created a main window with 2 subwindows, but i can't
draw lines in the subwindow.
The drawing works only in main window. Can anybody help
me ???
Are there other possibilities to create subwindows (what
about GDK_WINDOW_CHILD)?
How can I set that the child windows are only moveable
within the mainwindow ?
My source code :
#include <stdio.h>
#include <string.h>
#include "gdk/gdk.h"
#include "gtk/gtk.h"
/* ======================= Callback functions ========================== */
gint close_sub_win (GtkWidget * widget,gpointer daten)
{
gtk_widget_destroy(widget);
return (TRUE);
}
gint close_prog (GtkWidget * widget,GdkEvent * event,
gpointer daten)
{
gtk_main_quit();
return (TRUE);
}
/*======================= main function ============================== */
int main(int argc, char *argv[])
{
GtkWidget * main_win,
* sub_win1,
* sub_win2;
GdkColormap * palette;
GdkRectangle update_rect;
GdkColor color;
GdkGC * context;
GtkStyle * style; /* window style */
gtk_init(&argc,&argv);
/* ========================================================================== */
main_win= gtk_window_new(GTK_WINDOW_TOPLEVEL);
gtk_widget_set_app_paintable(main_win,TRUE);
gtk_container_set_border_width (GTK_CONTAINER (main_win), 10);
gtk_widget_set_usize(main_win,
gdk_screen_width(),
gdk_screen_height());
gtk_window_set_policy (GTK_WINDOW(main_win), FALSE, FALSE, FALSE);
style = gtk_style_copy (gtk_widget_get_style(main_win));
gdk_color_parse("blue",&color);
style->bg[GTK_STATE_NORMAL]= color;
gtk_widget_set_style (main_win,style);
gtk_window_set_title (GTK_WINDOW(main_win), "Hello");
gtk_signal_connect(GTK_OBJECT(main_win),
"delete_event",
GTK_SIGNAL_FUNC(close_prog),
NULL);
/* ========================= create sub windows=============================== */
sub_win1= gtk_window_new(GTK_WINDOW_TOPLEVEL);
gtk_signal_connect(GTK_OBJECT(sub_win1),
"delete_event",
GTK_SIGNAL_FUNC(close_sub_win),
NULL);
gtk_widget_set_usize(sub_win1,300,200);
gtk_widget_set_uposition(sub_win1,50,50);
gtk_widget_set_sensitive(sub_win1,FALSE);
gtk_window_set_title (GTK_WINDOW(sub_win1), "Subwindow 1");
gtk_window_set_policy (GTK_WINDOW(sub_win1), FALSE, FALSE, FALSE);
gtk_window_set_transient_for (GTK_WINDOW(sub_win1), GTK_WINDOW(main_win));
gtk_widget_set_app_paintable(sub_win1,TRUE);
/*===========================================================================*/
sub_win2= gtk_window_new(GTK_WINDOW_TOPLEVEL);
gtk_signal_connect(GTK_OBJECT(sub_win2),
"delete_event",
GTK_SIGNAL_FUNC(close_sub_win),
NULL);
gtk_widget_set_usize(sub_win2,300,200);
gtk_widget_set_uposition(sub_win2,450,50);
gtk_widget_set_sensitive(sub_win2,FALSE);
gtk_window_set_title (GTK_WINDOW(sub_win2), "Subwindow 2");
gtk_window_set_policy (GTK_WINDOW(sub_win2), FALSE, FALSE, FALSE);
gtk_window_set_transient_for (GTK_WINDOW(sub_win2), GTK_WINDOW(main_win));
gtk_widget_set_app_paintable(sub_win2,TRUE);
/*========================================================================*/
gtk_widget_show(main_win);
gtk_widget_show(sub_win1);
gtk_widget_show(sub_win2);
/*========================== Draw line into a subwindow ==========================*/
context= gdk_gc_new(sub_win1->window);
gdk_gc_set_line_attributes(context, 2, GDK_LINE_SOLID, GDK_CAP_BUTT, GDK_JOIN_MITER);
gdk_draw_line (sub_win1->window,
kontext,
50,50,100,100);
update_rect.x=0;
update_rect.y=0;
update_rect.width= sub_win1->allocation.width;
update_rect.width= sub_win1->allocation.width;
gtk_widget_draw (sub_win1, &update_rect);
/* ========================================================================
*/
gtk_main();
return 0;
}