Some people pointed me to functions in wxCore, so I could find a solution that works.
The function that does the drawing in the original example is:
onPaint vbitmap dc viewArea
= do mbBitmap <- get vbitmap value
case mbBitmap of
Nothing -> return ()
Just bm -> drawBitmap dc bm pointZero False []
using dcSetUserScale
from wxCore, I was able to modify it to scale that way:
( sw is the scrolledWindow )
onPaint sw img dc viewArea = do
mimg <- get img value
case mimg of
Nothing -> return ()
Just bm -> do
bsize <- get bm size
vsize <- get sw size
let scale = calcScale bsize vsize
dcSetUserScale dc scale scale
drawBitmap dc bm pointZero False []
calcScale :: Size -> Size -> Double
calcScale (Size bw bh) (Size vw vh) = min scalew scaleh
where scalew = fromIntegral vw / fromIntegral bw
scaleh = fromIntegral vh / fromIntegral bh