Wiley.Symbian.OS.Internals.Real.time.Kernel.Programming.Dec.2005.eBook-DDU (779891), страница 97
Текст из файла (страница 97)
In both cases, thepointers need to be updated to point to the next younger sibling.46011.8.3THE WINDOW SERVERWalking the window treeThere are many occasions when the window tree must be traversed inthe front to back order, for example:• When a window is made invisible and the windows that it wascovering up need to be exposed• When a window is made visible and the windows behind it arecovered up.There is a single algorithm for doing the traversal, which is used in manyplaces throughout WSERV, and which I will discuss in this section.There are two rules that define the front to back order of windows asthey are shown on the display:• A child window is always in front of a parent window• If two windows are children of the same parent then the older is infront of the younger.The first rule has the consequence that the root window is always the backmost window.
One of the root window’s jobs is to clear areas of the displaywhere there are no other windows visible. The color it will use can be setby calling the function RWsSession::SetBackgroundColor().The walk window tree mechanism is implemented in a single function,CWindowBase::WalkWindowTree(), which uses the three pointersthat link all windows to traverse the windows in the correct order.WalkWindowTree() takes a class with a virtual function as a parameter,and on each new window it finds, it calls the virtual function passing thewindow as a parameter.One of the parameters of this function is: TWalkWindowTreeBase&aWalkClass.
Figure 11.4 shows some of the derived classes and thevirtual function on this class – DoIt().TWalkWindowTreeFindInvalidTWalkWindowBaseTWalkWindowTreeSetFadedDolt()TWalkWindowTreeFocusGainedTWalkWindowTreeRegionBaseiRegionDolt2()TWalkWindowTreeCoverFigure 11.4TWalkWindowTreeKillRegionTWalkWindowTreeExposeWalking the window treeWINDOW OBJECTS AND CLASSES461In all, there are over 20 classes deriving from TWalkWindowTreeBase for a variety of different purposes. Some operations only apply tovisible windows, hence the need for TWalkWindowTreeRegionBase.One of the members of this class is a region, which is initialized to thewhole area of the screen. When the operation is applied to each window,the visible area of that window is subtracted from the region and whenthis region becomes empty no more windows are scanned.11.8.4 Class structure of windowsFigure 11.5 shows all the classes that we use to represent windows,on both the server and the client sides.
You can see that the classstructure on the two different sides is not quite the same. The purpose ofRWindowTreeNode and CWindowBase is to represent a window thatclientserverRWindowGroupCWsWindowGroupCWsWindowCWsClientWindowRWindowTreeNodeCWsWindowBaseCWsRootWindowRWindowBaseRBlankWindowCWsBlankWindowCWsTopClientWindowRWindowCWsRedrawMsgWindowRDrawableWindowRBackedUpWindowCWsBackupWindowFigure 11.5Window classesCWsWindowRedraw462THE WINDOW SERVERfits into the window tree at any point. The equivalence of the windowgroup classes is clear.
Yet the other part of the class structure takes avery different shape. On the client side, the class structure is determinedby the drawing functionality that each class provides. On the server side,the class structure is more closely related to the window’s position inthe window tree. The difference in drawing behavior is determined by aplug-in object, which is a class deriving from CWsWindowRedraw.When we consider windows from the drawing point of view, there arethree types of windows: blank windows, bitmap backup windows andredraw windows. I will describe the exact differences between these sortsof windows in later sections of this chapter.The root window, being a derived class of CWsWindow, also has aplug-in drawing object.
Its type is ‘‘blank window’’ since it is only everdrawn with a solid color; this is shown by a dotted line in the figure.11.9Properties of windowsIn this section I will discuss a selection of the properties of the differentclasses of windows. With the exception of the root window, whichWSERV creates during bootup, all other windows are created at therequest of a WSERV client. Clients are said to own the windows theycreate. The owner has control of certain properties of the window, whileothers are assigned by WSERV.11.9.1Properties held by all windowsProperties held by all windows include:• Parent• Oldest or first child• Next sibling• Client handle• Ordinal priority.I’ve discussed the first three of these properties in earlier sections.
Theclient handle is a value that the owner of the window gives to WSERVwhen it is created. It is very important that this value be unique amongstall windows owned by the client, otherwise the client code will not workas expected. In debug builds, WSERV enforces the uniqueness of thevalues, and panics the client if they are duplicated.Ordinal priority is closely related to another window property, knownas ordinal position. Ordinal priority is a value set by the owner of aPROPERTIES OF WINDOWS463window and it is stored on the server side.
Ordinal position concernsa window’s position among the other children of its parent. This valueisn’t stored explicitly, but can be calculated by analyzing the structureof the server-side window classes. The rule is that if two children ofthe same parent have different ordinal priority then the one that has thehighest will always be older and therefore in front of the one with thelowest. If we have a group of children, all with the same priority, thentheir ordinal position will start at zero and increase through consecutivepositive integers.
For example, suppose that a window has five children,two of ordinal priority ten and three of ordinal priority zero. Then the twowith ordinal priority ten will be the oldest, and in front of the others, andtheir ordinal positions will be zero and one. Similarly, the three of ordinalpriority zero will have ordinal positions zero, one and two.One use of ordinal priority is to make sure a group window comesin front (or behind) other group windows. For example, the group window associated with the application picker in the UIQ interface has anegative ordinal priority to ensure that it appears behind all the normalapplications, which by default have zero for their ordinal priority.11.9.2 Properties of group windowsProperties of group windows include:• Name• Identifier• Screen device.The identifier is a number from 1 to 10,000 inclusive that WSERVassigns to each group window.
The numbers are unique across all groupwindows in existence at any one time; they are also allocated cyclicallyso that when a group window is destroyed, it is unlikely that its identifierwill be used again immediately. Identifiers give applications a way ofdiscovering all of the group windows in the system at any time. The APIsin RWsSession use identifiers as a means of referring to group windows:TIntTIntTIntTIntTIntTIntSetWindowGroupOrdinalPosition(TInt aIdentifier, TInt aPosition);GetWindowGroupClientThreadId(TInt aIdentifier, TThreadId &aThreadId);GetWindowGroupHandle(TInt aIdentifier);GetWindowGroupOrdinalPriority(TInt aIdentifier);SendEventToWindowGroup(TInt aIdentifier, const TWsEvent &aEvent);FindWindowGroupIdentifier(TInt aPreviousIdentifier,const TDesC& aMatch, TInt aOffset=0);TInt FindWindowGroupIdentifier(TInt aPreviousIdentifier,TThreadId aThreadId);TInt SendMessageToWindowGroup(TInt aIdentifier,TUid aUid,const TDesC8 &aParams);464THE WINDOW SERVERThese functions allow group windows to be listed, interrogated andre-ordered.There are two API functions for setting and getting a group window’sname in the RWindowGroup class.
In addition, there is one API functionin the RWsSession class:TInt GetWindowGroupNameFromIdentifier(TInt aIdentifier,TDes &aWindowName);Group window names are used so that the system can get a list of runningapplications.It is normal for a WSERV client to create a screen device, CWsScreenDevice, which has an associated object of class DWsScreenDevicecreated in the server. The first screen device created by a client becomesthe primary screen device for that client. This screen device will beassigned to each group window that that client creates. Group windowscreated before the primary screen device are never associated with ascreen device.The association of group windows with screen devices is used insystems with more than one screen size mode. (In future, it will also beused in systems with more than one screen.) In this case, each screendevice has a screen size mode associated with it.