Scrollbar woes

Volker Bartheld dr_versaeg at freenet.de
Mon Dec 10 08:29:15 PST 2007


Hi!

I want to show horizontal and/or vertical scrollbars in a wxFrame containing
a single wxScrolledWindow depending on its client size in relation to a
background image and the screen size:
- A horizontal scrollbar should be shown, if the client size is wider
  than the background image.
- A vertical scrollbar should be shown if the client size is higher than
  60% of the screen size.
- No scrollbars at all if none of the above.

After studying   
http://www.wxwidgets.org/manuals/stable/wx_wxwindow.html#wxwindowsetscrollbar and
http://groups.google.de/group/comp.soft-sys.wxwindows/msg/df63dcb511c7c2f4 
, I came up with the solution [1] below. I assume, using
wxScrolledWindow::SetScrollbars() will probably show no benefit over
wxScrolledWindow::SetScrollRate(). This approach works fine on wxMSW and some
Linux derivates, but one wxLin-machine refuses to show *any* scrollbars.

I'm also wondering what to do with wxTextCtrl and the wxTE_MULTILINE-style.
Since this control doesn't inherit from wxScrolledWindow, I'm probably
left alone in the dark when I want to force (or suppress) one or both
flavours of scrollbars (read: get the native Win32 control's handle and
try my best).

What's your hint on the good ol' scrollbar issue?

THX,
Volker



[1]
wxScrolledWindow* MyDialog::m_mainBox;
void MyDialog::Create()
{
  int x, y, dummy;
  GetClientSize(&x, &y);

  int xmax=wxBitmap((const char**)backgnd).GetWidth();      // maximum width is that of the decoration background on top of the popup
  int ymax=0.6*wxSystemSettings::GetMetric(wxSYS_SCREEN_Y); // maximum height is 60% of the screen height
  if(x>xmax && y>ymax)                                      // both dimensions out of bounds
  {
    SetSize(xmax, ymax);                                    // set both dimensions
    m_mainBox->SetScrollRate(10, 10);                       // force both scrollbars
    Fit();
  }
  else if(x>xmax)                                           // too wide
  {
    SetSize(xmax, -1);                                      // set width
    m_mainBox->SetScrollRate(10, 0);                        // and horizontal scrollbar
    Fit();
  }
  else if(y>ymax)                                           // too high
  {
    SetSize(-1, ymax);                                      // set height
    m_mainBox->SetScrollRate(0, 10);                        // and vertical scrollbar
    Fit();
  }
  else m_mainBox->SetScrollRate(0, 0);                      // suppress both scrollbars
}


-- 
mailto:  V B A R T H E L D at G M X dot D E






More information about the wx-users mailing list