GTK+ Forums

Discussion forum for GTK+ and Programming. Ask questions, troubleshoot problems, view and post example code, or express your opinions.
It is currently Wed Oct 01, 2014 6:18 pm

All times are UTC




Post new topic Reply to topic  [ 3 posts ] 
Author Message
 Post subject: Gtk3's Height-for-width new method: How do I implement it?
PostPosted: Thu Aug 23, 2012 2:28 pm 
Offline

Joined: Thu Aug 23, 2012 2:19 pm
Posts: 2
I've developed a gtk2 app (Conky Companion) in C to help users of my conky scripts

Click.

create their own conkyrcs with relative ease. A screenshot of the main screen is the following:

http://i.imgur.com/jWl88.jpg

The user can drag and drop icons or labels from the right side to the left, move them, resize them, change their size or colour, etc. When happy, he can press the generate button and generate a conkyrc file.

The screen is a top,non resizable window with a table. The 2 sides of the table are frames in which fixed containers have been put.
Whenever someones tries to place an icon or a label at the right or bottom border of the left frame/fixed container, the widget goes off bounds, as you can see from the screen shot above.

I'm now trying to port the app to Gtk3 and I'm facing a bizarre problem.
Whenever a user tries to place or move an object to the right or bottom border of the left frame/fixed container, it resizes itself to accommodate the newly placed widget.

http://i.imgur.com/d1lc4.jpg

If I move the object to the left (or up), the frame goes back to its size defined by gtk_widget_set_size_request.

Is there a way to make a fixed container... fixed? I don't want it to resize.

The code that places the frame and the fixed container in the window is this:
Code:
/* LEFT FRAME */

frame1= gtk_frame_new(NULL);
gtk_table_attach(GTK_TABLE(table), frame1, 0,14,0,49,GTK_SHRINK,GTK_SHRINK,0,0);
gtk_widget_set_size_request(frame1, 360,570);

gtk_widget_show(frame1);


/* LEFT FRAME - FIXED CONTAINER */

fixed1 = gtk_fixed_new();
gtk_widget_set_has_window(fixed1,TRUE);
gtk_container_add(GTK_CONTAINER(frame1),fixed1);
gtk_widget_modify_bg (fixed1, GTK_STATE_NORMAL, &color);

gtk_drag_dest_set (
    fixed1, GTK_DEST_DEFAULT_ALL,
    target_list, 1, GDK_ACTION_COPY|GDK_ACTION_MOVE);

g_signal_connect (fixed1, "drag-drop",G_CALLBACK (dr_data_rec_1d1), (gpointer)fixed1);

gtk_widget_show(fixed1);   


I've tried the following things:
1)Fiddling with GTK_EXPAND and GTK_FILL for the placement of the frame. No change.
2)gtk_window_set_geometry_hints for the window, table, frame and fixed container. No change.
3)Replacing gtk_table with gtk_grid. No change.

After posting on StackOverflow, I was advised to consult the following page

http://developer.gnome.org/gtk3/3.2/ch25s02.html#id1482126

which I did. If I understood correctly, the new way of declaring

Code:
/* LEFT FRAME */

frame1= gtk_frame_new(NULL);
gtk_table_attach(GTK_TABLE(table), frame1, 0,14,0,49,GTK_SHRINK,GTK_SHRINK,0,0);
gtk_widget_set_size_request(frame1, 360,570);   


is (ignore the height for the time being)

Code:
static void
my_widget_get_preferred_width (GtkWidget *widget,
                               gint      *minimal_width,
                               gint      *natural_width)
{
  GtkRequisition requisition;

  gtk_widget_get_requisition (widget, &requisition);

  *minimal_width = *natural_width = requisition.width;
}

....

/* LEFT FRAME */

frame1= gtk_frame_new(NULL);
gtk_table_attach(GTK_TABLE(table), frame1, 0,14,0,49,GTK_SHRINK,GTK_SHRINK,0,0);

gint min_width=360;
gint nat_width=360;

GTK_WIDGET_GET_CLASS(frame1)->get_preferred_width=my_widget_get_preferred_width;
my_widget_get_preferred_width(frame1,&min_width,&nat_width);   


It compiles OK, but, when run, it gives me this error:

Code:
(conky_companion:19700): Gtk-WARNING **: GtkFrame 0xa00e660: widget tried to     gtk_widget_get_width inside  GtkWidget     ::get_width implementation.


without ever drawing the window and it segfaults after a while.

What am I missing here?
Or, TL;DR, what is the equivalent of

Code:
gtk_widget_set_size_request(frame1, 360,570);     


in gtk3? (StackOverflow gave up, no answer in Crunchbang and Arch Linux forums, you're my last hope)


Top
 Profile  
 
 Post subject: Re: Gtk3's Height-for-width new method: How do I implement i
PostPosted: Thu Aug 23, 2012 5:41 pm 
Offline
Never Seen the Sunlight

Joined: Wed Jul 23, 2008 10:31 am
Posts: 2406
Location: Slovenia
Hello and welcome to the GTK+ forums!

It seems to me that your problem stems from the fact that GtkFixed allowed children to "overflow" in 2.x series and in 3.x this is not allowed anymore.

Your problem can be fixed in numerous ways, but none of the is completely trivial. I would recommend using GtkDrawingArea as a canvas. This will take some learning if you never used cairo drawing library before, but will enable you to add some nice effects to your application (exact positioning, preview while dragging, mark currently selected item, resizing using mouse - like in inkscape for example, ...). I'm wiling to provide you some assistance with this endeavor if you decide to implement it.

Another way of dealing with this would be to pack GtkFixed inside GtkViewport and manually fix the position, but this has a potential to become really messy really quick.

Cheers,
Tadej


Top
 Profile  
 
 Post subject: Re: Gtk3's Height-for-width new method: How do I implement i
PostPosted: Thu Aug 23, 2012 7:25 pm 
Offline

Joined: Thu Aug 23, 2012 2:19 pm
Posts: 2
A 1000 thanks for your reply tadeboro.
I was getting really desperate about this.
Will google and read about gtkdrawingarea.
Does the latter allow to list all the widgets I've placed on it?
I need this, as well as knowing their places and sizes, in order to generate the conkyrc file.

I guess using a gtkfixed widget for this job was just a hack from my part; I'll have to adjust.

Thanks again.

EDIT: Also, while you're on it, do you have any idea about how one should apply the new height for width geometry method?


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

All times are UTC


Who is online

Users browsing this forum: No registered users and 3 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