GTK+ Forums

Discussion forum for GTK+ and Programming. Ask questions, troubleshoot problems, view and post example code, or express your opinions.
It is currently Fri Nov 28, 2014 9:40 pm

All times are UTC




Post new topic Reply to topic  [ 2 posts ] 
Author Message
 Post subject: Port from C++ to C
PostPosted: Thu Nov 22, 2012 9:41 pm 
Offline
Familiar Face

Joined: Thu Nov 22, 2012 3:46 pm
Posts: 22
I have a GTK_LIST packed into a scrollbar window. I want to navigate between the records in the list with the Up/Down arrow keys and always have the selected record "visible".

When I browse through the list, the scrollbar doesn't move so I cannot see the row that I'm selecting... I must move the scrollbar with the mouse but I want to make the scrollbar "follow" the selection automatically.

I want to port this code, that resolve problem, to C. Any help would be nice...

Code:
   void
   MainWindow_ui::
   on_up_clicked ()
   {
      Gtk::TreeModel::iterator iter = m_tree_sel_ref->get_selected ();
      Gtk::TreeModel::Path     path = m_list_store_ref->get_path (iter);

      cout << "--v-- on_up_clicked --v--\n";

   /*   if (iter != children.begin ()) {  doesn't work */

      if (path.to_string () != "0") {
         path.prev ();                             // go to the prev row
         m_tree_sel_ref->select (path);              // select the row
         m_tree_view.scroll_to_row (path);           // scroll to make visible
         m_row = *(path.get_indices ().begin ());    // remember where we are
         autoscroll_up ();
         iter--;
         }
      cout << "--^-- on_up_clicked --^--\n";
   }

   void
   MainWindow_ui::
   on_down_clicked ()
   {
      Gtk::TreeModel::iterator iter = m_tree_sel_ref->get_selected ();
      Gtk::TreeModel::Path     path = m_list_store_ref->get_path (iter);
   
      cout << "--v-- on_down_clicked --v--\n";

      if (!is_last_row (iter)) { // Are we about to hit the end?
         path.next ();
         m_tree_sel_ref->select (path);
         m_tree_view.scroll_to_row (path);           // scroll to make visible
         m_row = *(path.get_indices ().begin ());    // remember where we are
         autoscroll_down ();
         iter++;
         }
      cout << "--^-- on_down_clicked --^--\n";
   }

   void
   MainWindow_ui::
   autoscroll_up ()
   {
      print_adjust_values (m_scrollwin->get_vadjustment ());

      double pg_inc = m_scrollwin->get_vadjustment ()->get_page_increment ();
      double value = m_scrollwin->get_vadjustment ()->get_value ();
      double pg_sz = m_scrollwin->get_vadjustment ()->get_page_size ();

      if (((m_row+1) * m_prh - value) < m_prh) {
         m_scrollwin->get_vadjustment ()->set_value (value - pg_inc/2);
      }
   }

   void
   MainWindow_ui::
   autoscroll_down ()
   {
   //   print_adjust_values (m_scrollwin->get_vadjustment ());

      double foo;
      double pg_inc = m_scrollwin->get_vadjustment ()->get_page_increment ();
      double value = m_scrollwin->get_vadjustment ()->get_value ();
      double pg_sz = m_scrollwin->get_vadjustment ()->get_page_size ();
      double last_page = m_scrollwin->get_vadjustment ()->get_upper () - pg_sz;
      
   //   dump_downward_condition (pg_inc, value, z, foo, pg_sz);

      if (((m_row+1) * m_prh - value) > pg_sz) {
         if ((foo = value + pg_inc/2) > last_page) {
            m_scrollwin->get_vadjustment ()->set_value (last_page);
         }
         else {
            m_scrollwin->get_vadjustment ()->set_value (foo);
         }
      }
   }

Many thanks in advance.


Top
 Profile  
 
 Post subject: Re: Port from C++ to C
PostPosted: Fri Nov 23, 2012 9:09 am 
Offline
Never Seen the Sunlight

Joined: Thu Mar 24, 2011 2:10 pm
Posts: 328
Location: Sydney, Australia
#1 GtkList is depreciated. You may get it working but your program will be old before its even new. Maintaining it will be much harder. Use e.g. GtkTreeView instead. I have a feeling scrolling may well happen automatically and if it doesn't you can use gtk_tree_view_scroll_to_cell.


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 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