How do controls know when to redraw?

When writing the floating textbox (post below) I wondered: how does my control know that it should redraw itself? I’m not telling anybody I’ve created that control.

Well, redrawing of windows is handled by the window server. If you create a window, the window server knows about it. And obviously the framework is requesting redraw events, since otherwise nothing would get drawn. The secret must lie somewhere in the framework, then.

And it does, as we can see from the source code in the 6.0 SDK. When you call CCoeControl::CreateWindowL, something like this happens:

iWin=new(ELeave) RWindow(iCoeEnv->WsSession());

so the handle for the RWindow is the address of the CCoeControl!
CCoeRedrawer is the component that requests redraw events. In it’s RunL it simply does:

        TWsRedrawEvent redraw;
        CCoeControl* window=(CCoeControl*)redraw.Handle();

Presto! Any window created within the app will correctly be asked to redraw itself as necessary. (But be vewy, vewy careful of manually creating RWindows in an app…)

This entry was posted in Symbian. Bookmark the permalink.

Comments are closed.