站内搜索: 请输入搜索关键词
当前页面: 图书首页 > SWT: The Standard Widget Toolkit

4.2 Client Area - SWT: The Standard Widget Toolkit

Previous Section  < Day Day Up >  Next Section

4.2 Client Area

The client area of a Composite, List, or Text control[3] is a rectangle that describes the area within which content may be drawn. In this context, the term client refers to you, the programmer, viewed as a client of services offered by the control, so the client area is the area that you "own." Essentially, it is the area that is not covered by those parts of the control bounds that are considered to be "trimmings" such as borders, scroll bars, and the menu bar.[4] Areas outside of the client area are off limits. Figure 4.2 shows the bounds and client area of a group box.

[3] As of R3.0, client area is defined only for Composite, List, and Text controls but the concept is general enough to be applied to all Control subclasses. It is possible that future versions of SWT will address this issue by moving the client area API to class Control, which is why we are discussing it here.

[4] Both the need for a client area concept and the fact that the menu bar is considered part of the trimmings come from constraints imposed by Microsoft Windows. Modeling them explicitly in SWT was the only effective way to deal with them.

Figure 4.2. The bounds and client area of a group box.

graphics/04fig02.gif


The client area is expressed in pixels, this time in the coordinate system of the control (unlike the bounds that are in the coordinate system of the parent). Very often, the location of the client area within the control is (0, 0), but this is not always the case. Figure 4.3 shows the client area of two group boxes from different platforms, with Windows on the left and GTK on the right. On Windows, the location of the client area is (3, 13). On GTK, it is (0, 0).

Figure 4.3. The location of the client area of a group box on Windows and GTK.

graphics/04fig03.gif


The concept of client area allows SWT to hide these kinds of platform differences neatly. You can determine the client area of a composite using getClientArea().

getClientArea() Returns a rectangle that describes the area of the control that is capable of displaying data.

The client area of a control cannot be modified directly. Instead, moving or resizing the control or changing the trimmings indirectly resizes it. For example, hiding a scroll bar causes the client area to become larger.

    Previous Section  < Day Day Up >  Next Section