GTK+ Forums

Discussion forum for GTK+ and Programming. Ask questions, troubleshoot problems, view and post example code, or express your opinions.
It is currently Tue Sep 30, 2014 1:53 pm

All times are UTC




Post new topic Reply to topic  [ 2 posts ] 
Author Message
 Post subject: Resize drawning area to scroll
PostPosted: Wed Sep 05, 2012 8:56 pm 
Offline
Familiar Face

Joined: Tue Feb 28, 2012 1:16 pm
Posts: 11
Location: Russia
Hi!

What is the common approach of resizing drawning area to get scroll working?
I have the following:

Code:
   drawing_area_pic4 = gtk_drawing_area_new();

   scroll_pic4 = gtk_scrolled_window_new(NULL, NULL);
   gtk_scrolled_window_add_with_viewport(GTK_SCROLLED_WINDOW(scroll_pic4), drawing_area_pic4);
   gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scroll_pic4), GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);

   g_signal_connect(GTK_OBJECT (drawing_area_pic4), "expose_event",
            (GtkSignalFunc)pic4_expose_event, NULL);

   gtk_widget_set_events(drawing_area_pic4, GDK_EXPOSURE_MASK
                  | GDK_LEAVE_NOTIFY_MASK
                  | GDK_BUTTON_PRESS_MASK
                  | GDK_POINTER_MOTION_MASK
                  | GDK_POINTER_MOTION_HINT_MASK);

   g_signal_connect(G_OBJECT(drawing_area_pic4), "button-press-event", G_CALLBACK(button_press_event), "pic4");
   chkbox_Pic4.is_checked = 0;

   gtk_notebook_append_page(GTK_NOTEBOOK(notebook), scroll_pic4, NULL);
   gtk_notebook_set_tab_label_text(GTK_NOTEBOOK(notebook), scroll_pic4, "Динамика моделирования");

   bzero(&net_data_pic4, sizeof(struct pic4_t));

   gtk_widget_show(scroll_pic4);
   gtk_widget_show(drawing_area_pic4);


In pic4_expose_event handler i calculate height of the picture to draw and the do the following:

Code:
static gboolean
pic4_expose_event(GtkWidget *widget, GdkEventExpose *event, gpointer user_data)
{
   gint xw = widget->allocation.width, yw = widget->allocation.height;

......

      lyt = pango_cairo_create_layout(cr);
      pango_layout_set_font_description(lyt, font);
      pango_layout_set_text(lyt, str1, -1);
      pango_layout_get_pixel_size(lyt, &wd, &hg);
      pango_cairo_show_layout(cr, lyt);
      g_free(str1);

      if ( yw < hg ) {
         gtk_widget_set_size_request(widget, -1, hg);
      }
....
}

so gtk_widget_set_size_request force run pic4_expose_event again.
Something tells me this isn't right.

When i have to call gtk_widget_set_size_request? And is this the only way to get scroll working, i mean through gtk_widget_set_size_request?

Thanx.


Top
 Profile  
 
 Post subject: Re: Resize drawning area to scroll
PostPosted: Wed Sep 05, 2012 9:58 pm 
Offline
GTK+ Guru

Joined: Fri Mar 25, 2011 5:16 pm
Posts: 177
Location: USA
I believe what you need is to call gtk_widget_set_hexpand() and gtk_widget_set_vexpand() on your scroll window.

You don't say what version of Gtk+ your using or your O.S. and version but have a look here:
http://www.gtkforums.com/viewtopic.php?f=3&t=988&p=195381#p195381


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 2 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 5 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group