Relationship between window controls

When a control draws in the window of another control, the position is relative to that window. If a control owns a window that is a child of another window, that control's position is relative to the parent window; however, if that control is a compound control, its child control's coordinates are relative to its own parent control window position. Top-level window-owning controls are displayed using a position relative to the display. In other words, it uses the physical coordinates of the display.

The following figure illustrates this relationship.

Figure: Relative positions of three controls where the top-level parent owns the window

Consider three controls, A, B, and C (shown in the figure above):

  • A is a top-level control and owns a window

  • Child controls B and C do not create their own windows in this example.

  • B, a child control of A, does not create a window, and it has a child control, C.

    B's window is set calling the CCoeControl::SetContainerWindowL(A) method and C's window is set with CCoeControl::SetContainerWindowL(B). Then C's position (p) is relative to A, since it is the actual window owner. A's position (m) is relative to the display position.

However, if B is a child control of A but also has a window of its own, it is a child window of A's window (as shown in the following figure). Then if C is a child of B and sets its window by calling CCoeControl::SetContainerWindowL(B), the position of C (p') is relative to B's window.

Figure: Relative positions of three controls where a child owns a window

As the example illustrates, a control position depends on the window in which it is drawn. Therefore, you need to know the drawing window for each control. It is an important issue when designing a UI layout. There are some common controls that optionally may have their own window, such as menus, dialogs, and scroll bars. The application framework handles drawing these controls, as long as the appropriate resources and flags have been set. The CCoeControl::OwnsWindow() call can be used to detect whether a control owns a window or not.