The majority of the drawing-related logic is in the "wiggler" Prototype; choose "Tool -> Widgets" from the menu, double-click on the main drawing surface, click "Prototype..." and then choose "Prototype -> Script..." from the menu.
Various other buttons and interactive elements contain their own scripts; from the main view in "Widgets" editing mode you can double-click on the ball-point pen tool and then click "Script..." to see how tool-changing works, for example.