Direct scrolling using Gtk::Viewport (gtkmm3)


I have a custom container which provides scrolling functionality by embedding a Gtk::Grid inside a Gtk::Viewport. The scrolling part works perfectly except for one glitch. Whenever an on_size_allocate event occurs it causes the property_value of the Gtk::Adjustment to reset to 0 causing the scroll position to jump to the top. Since this could happen when any of the children emits a queue resize or even when the top level window loses focus the scroll position sort of never stays where it should. By overriding the containers on_size_allocate handler I confirmed that the property_value of Gtk::Adjustment resets when I call the base classes on_size_allocate. Below is my on_size_allocate handler.

001 void CScrollGrid::on_size_allocate(Gtk::Allocation &oAlloc)
002 {
003  {
004    double dValue = m_refAdjustment->get_value();
006    std::cout << "size allocate (before), value: " << dValue << "\n";
008    Gtk::Widget::on_size_allocate(oAlloc);
010    std::cout
011      << "size allocate (after), value: "
012      << m_refAdjustment->get_value()
013      << "\n";
015    // Update scroll
016    {
017      int nMinimum;
018      int nDummy;
021          == m_eOrientation)
022      {
023        m_oGrid.get_preferred_height(nMinimum,
024                                     nDummy);
025      } else
026      {
027        m_oGrid.get_preferred_width(nMinimum,
028                                    nDummy);
029      }
031      m_refAdjustment->set_upper(nMinimum);
032    }
034    m_refAdjustment->property_value().set_value(dValue);
036    std::cout
037      << "size allocate (before fit), value: "
038      << m_refAdjustment->get_value()
039      << "\n";
041    Fit();
042  }
043 }

At line 006 the stream output prints the correct 'value'. By line 010 the 'value' is reset to 0. As you can see that I have tried to apply the backed up value at line 034 but surprisingly the stream output at line 036 still returns 0!

What am I doing wrong?

NOTE: I didn't use Gtk::ScrolledWindow because of the following reason. The 'rows' inside the scrolled area could be of different heights. Irrespective of that the visible region needs to show the first and last row in full without clipping. When this is not possible, the last row is omitted and the extra space is converted as padding distributed evenly between top and bottom.

Please consider the Environment before printing this e-mail.

The information contained in this message (including any attachments) is confidential and may be privileged or otherwise protected from disclosure.  If you are not the intended recipient, you must not copy this message or attachment or disclose the contents to any other person.  If you have received this transmission in error, please notify the sender immediately by return e-mail and permanently delete this message and any attachments from your system.  Any dissemination, use, review, distribution, printing or copying of this message in whole or in part is strictly prohibited.  Please note that e-mails are susceptible to change.
SKANRAY(including its group of companies) shall not be liable for any omission or error in the message, improper or incomplete transmission of the information contained in this communication or for any delay in its receipt or damage to your system.  SKANRAY(or its group of companies) does not guarantee that the integrity of this communication has been maintained or that this communication is free of viruses, interceptions or interference.

[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]