Treatment plan for attachment

zhaozj2021-02-17  83

Treatment plan for attachment

Interpretation

The so-called adhesion relationship refers to a control attached to another control, and the graphical operation is performed to connect. For example, the doors and windows are placed on the wall. If the wall moves, the above form is to follow mobile, and the like.

We call it according to the attachment to the child control, which is attached to the parent control. For example: the wall is a parent control, the door and window is a child control.

2. Operation

Due to its attachment, the following operations need special processing:

2.1. Select (SELECT)

The habit of Windows processing is to select only the same level (ie, the same OWNER) can be selected each time. For example, if the form A on the wall A is selected, then other controls can only be the child control of the wall A. If the wall body A is selected first, the sub-control of the wall or other walls cannot be selected (because its Owner is not the same).

Of course, considering that the use of AutoCAD control may be more difficult, you can use a variety of ideas, you can choose, but you can follow Windows habits (ie: assuming only some controls). If the parent control is selected, It is assumed that the child control is also selected).

2.2. Mobile (Move)

Rotation can be seen as a special case of movement.

l When the parent control moves, the child control follows. (Offset relative to the parent window unchanged)

The parent control is not moving when the L sub-control moves. There are two processing logic:

1. The sub-control can be moved to the parent control At this time, the connections of the child control and the parent control are disconnected, and there is no relationship between them. However, the door and window space is logically unable to leave the wall and separately, at this time, it is necessary to judge whether there is no root window (illegal) when the legitimacy is checked. This is very convenient for users.

2, the child control cannot be moved to the external part of the mobile sub-control to judge whether the new location is legal. Really, its workload and situation are similar. He may have to process in MouseMove, and 1 may be processed in MouseDown.

2.3. Change the size (Resize)

When the parent window changes, it cannot cross the boundary of the child control. It doesn't matter.

When the child control is large, the boundary of the parent control cannot be translated. It doesn't matter.

2.4. Copy (COPY)

Copy the parent control, and copy the child control, the newly generated control remains attached.

Copy the child control, do not consider the parent control (assuming its OWNER NULL).

2.5. Delete

Delete the child control When you disconnect the parent control pair sub-control.

Delete the child control at the same time when deleting a parent control.

3. Data structure

A sub-control list (such as: m_listchild) is saved in the parent control.

There is a pointer to the parent control (eg M_POWNER or M_PPARENT).

Note: The child control can only have a parent control, and the parent control can have multiple sub-controls.

4. Implement

Add a virtual function to the base class, called

Vitual LRESULT PERFORM

UINT MSG, // Message ID

WPARAM WPARAM, // First Message Parameter

LParam lParam // Second Message Parameter

);

The parameter of this function imitates the Windows API function SendMessage, which is similar.

For example, as follows:

When the parent control moves, there is a similar code in cparentComponet.onmove (): for (int i = 0; i

M_ListChild [i] .perform (PARENT_MOVED, 0, 0);

}

In CchildComponent (or CDOOR or CWINDOW), the process of processing the Perform method is as follows:

LResult CchildComponent :: Perform (Unit Msg, WPARAM WPARAM, LPARAM LPARAM)

{

Switch (msg)

{

Case Parent_Moved:

Parentmoved (WPARAM, LPARAM);

Break;

Case Parent_copy:

ParentCopy (WPARAM, LPARAM);

Break;

Case ...

Break;

DEFAULT:

Assert (false);

}

}

转载请注明原文地址:https://www.9cbs.com/read-31213.html

New Post(0)