GTK+ Forums

Discussion forum for GTK+ and Programming. Ask questions, troubleshoot problems, view and post example code, or express your opinions.
It is currently Mon Sep 22, 2014 8:12 am

All times are UTC




Post new topic Reply to topic  [ 6 posts ] 
Author Message
 Post subject: Iconview for buttons?
PostPosted: Thu Aug 23, 2012 5:17 am 
Offline
Familiar Face

Joined: Thu Aug 23, 2012 4:50 am
Posts: 11
Hi all,

I've been playing with Gtk+2.4 for windows and I'm really enjoying it at the moment. Everything seems quite easy to use and set up, but before I go any further in my coding, I just need to ask a couple of basic questions.

I really like the IconView widget as I can scale the container and the icons arrange themselves in a nice line-by-line order. I'm also able to get the customer data from the icons themselves once I've clicked on them, so that's all good too. The only thing I can't seem to work out is if it's possible to get the data about the icon when the mouse is 'over' it rather than 'clicking' on it. I don't think this is possible is it?

If not, then I can move to using Buttons instead of Icons, but the problem then is that I haven't found a container that will auto-sort my buttons when the container is resized. I've only seen buttons added to tables which isn't what I'm after. Does anyone know how this could be achieved?

The container I'd really like would be able to auto-wrap buttons I add to it on a line by line basis. When the buttons then reach the bottom of the container then a vertical scroll bar should appear so the user can scroll up and down. The user shouldn't have to scroll left-right. Hope all that makes sense.

Thanks
6


Top
 Profile  
 
 Post subject: Re: Iconview for buttons?
PostPosted: Thu Aug 23, 2012 6:18 am 
Offline
Never Seen the Sunlight

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

First, I hope you meant that you're using GTK+-2.24 and not GTK+-2.4 (the latter one is probably older than your PC).

You can get the information about item below the mouse cursor by tracking it's position and checking which item lies below. You'll need to connect to the GtkWidget::motion-notify-event and do the checking from it's callback. Code would probably look something like that:

Code:
static gboolean
motion_event (GtkIconView    *iconview,
              GdkEventMotion *event,
              gpointer        data)
{
  int x, y;
  GtkTreePath *path;
  GtkTreeModel *model;
  GtkTreeIter iter;

  gtk_icon_view_convert_widget_to_bin_window_coords (iconview, event->x,
                                                     event->y, &x, &y);
  path = gtk_icon_view_get_path_at_pos (iconview, x, y);
  if (!path)
    return FALSE;

  model = gtk_icon_view_get_model (iconview);
  gtk_tree_model_get_iter (model, &iter, path);
  gtk_tree_path_free (path);

  /* Get data from model using iter and do your stuff */

  return FALSE;
}


Cheers,
Tadej


Top
 Profile  
 
 Post subject: Re: Iconview for buttons?
PostPosted: Thu Aug 23, 2012 11:38 am 
Offline
Familiar Face

Joined: Thu Aug 23, 2012 4:50 am
Posts: 11
Hi tadeboro,

Yeah, sorry, I did mean 2.24. Thanks also for the code, it was a great help. I passed the function to the following callback...

Code:
g_signal_connect (icon_view, "motion-notify-event", G_CALLBACK (motion_event), NULL);


...and everything worked perfectly.

Cheers
6


Top
 Profile  
 
 Post subject: Re: Iconview for buttons?
PostPosted: Tue Aug 28, 2012 3:19 am 
Offline
Familiar Face

Joined: Thu Aug 23, 2012 4:50 am
Posts: 11
Actually I have noticed one issue. The icon_view I have is in a scroll window, and when I scroll the window so the icons move up, the mouse_over no longer returns the correct icon path.

I suspect its due to gtk_icon_view_convert_widget_to_bin_window_coords (iconview, event->x, event->y, &x, &y); not setting x & y to the correct coordinates. Since I'm offsetting the iconview when scrolling, x & y should be offset too, but I'm not sure how to calculate this offset value.

Any ideas anyone?

Thanks
6


Top
 Profile  
 
 Post subject: Re: Iconview for buttons?
PostPosted: Tue Aug 28, 2012 1:42 pm 
Offline
Never Seen the Sunlight

Joined: Wed Jul 23, 2008 10:31 am
Posts: 2406
Location: Slovenia
Hi.

I checked this and you're right, x and y values are incorrect. But fortunately solution is really simple: drop the call to gtk_icon_view_convert_widget_to_bin_window_coords() completely and simply feed event coordinates to the gtk_icon_view_get_path_at_pos().

Reason behind this somewhat complex (it took me some time to find this information in GTK+ source code), but the end result is that coordinates fed into the motion-notify-event handler are already transformed properly for this purpose.

Cheers,
Tadej


Top
 Profile  
 
 Post subject: Re: Iconview for buttons?
PostPosted: Wed Aug 29, 2012 1:04 am 
Offline
Familiar Face

Joined: Thu Aug 23, 2012 4:50 am
Posts: 11
Hi,

Thanks again Tadej, you set me on the right track once more. Using the following snip returned the correct path of an icon in a scrolled window:

Code:
  gdk_window_get_pointer(event->window, &x, &y, NULL);
  path = gtk_icon_view_get_path_at_pos (iconview, x, y);


Cheers
6


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

All times are UTC


Who is online

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