Vijay
Vijay

Reputation: 67291

Identify a step up/down movement of scrollbar in gtk

  1. I have created a gtk scrolled window.
  2. I had attached a gtk tree view to it
  3. I have created gtk adjustment for vertical scrolling purpose
  4. I have created gtk vertical scrollbar and with the adjustment created above.
  5. I filled the treeview with some data.
  6. I tried to catch the signal when the scrollbar is moved up or dowm using :

gtk_signal_connect(GTK_OBJECT(vscrollbar), "value_changed",G_CALLBACK(my_function),NULL);

My signal handler looks like below:

void  my_function(GtkWidget *widget)
{
printf("Hi\n");
}

As seen above it prints a Hi whenever the scrollbar is moved one step up or one step down. But i want to print up when its moved up or down when its moved down.

void  my_function(GtkWidget *widget)
{
if(/*  movement is up, How to identify? */)
printf("UP\n");
if(/* movement is down, How to identify */)
printf("DOWN\n");
}

I am complete new person when it comes to gtk programming. Can anybody please suggest what do i need to do for this?

Upvotes: 0

Views: 358

Answers (1)

Jussi Kukkonen
Jussi Kukkonen

Reputation: 14607

First, a suggestion: check the latest API reference, even if you have to use old libraries. That will help you not write code that is already obsolete (gtk_signal_connect and GTK_OBJECT look quite ... ancient to anyone working with current GTK+). And if you can actually use current GTK+, do so.

As to your problem, you are correct that the API does not tell you the direction or magnitude of the change. You could use a "static gdouble last_value" in your signal handler and compare that to the current value to find out the direction (and don't forget to set last_value after that :)).

Upvotes: 1

Related Questions