ExampleWindow::ExampleWindow(PegRect rect, CPMainFrame
*frame) :CPModuleWindow(rect,0,0,frame)
{
HasLines = false;
SetScrollMode(WSM_AUTOSCROLL);
PegRect r = mClient;
r -= 20; // make the pan window a bit smaller
m_panWin = new PanWindow(r);
Add(m_panWin);
}
Scrolling is now set up to work in ExampleWindow.
When you run WindowsExample, you’ll notice that PanWindow is smaller than
ExampleWindow and there are no scrollbars on startup. However, if you bring up the
soft keyboard, you will see that scrollbars automatically appear thanks to the automatic
scroll mode.
ExamlpeWindow on startup with no scrollbars, and ExampleWindow with automatic scrollbars after
bringing up the soft keyboard.
In both AddText() and OnPointerMove(), PanWindow can change so that scrollbars
might be required. In AddText() the height of PanWindow can grow larger than the
height of ExampleWindow. In OnPointerMove(), PanWindow can be moved outside of
ExampleWindow’s mClient. In both cases we can force ExampleWindow to check its
scrollbars by calling Resize() and passing in its mReal. The following code is used in
both functions:
// Calling Resize with the same size is used as a "trick" to force the
// parent to check for and add or remove scrollbars
Parent()->Resize(Parent()->mReal);
Parent()->Draw();
As the comments say, this is a bit of a “trick” to cause ExampleWindow to realize that it
needs scrollbars to completely hold PanWindow. Try commenting out the Resize() and
42