Strange code in acPopupController

Viewing 9 posts - 1 through 9 (of 9 total)
  • Author
    Posts
  • #37765
    HeDiBo
    Participant

    The code to position a popup window, contains a strange piece of code:

    Code:
    procedure TsPopupController.ShowForm(AForm: TForm; AOwnerControl: TWinControl; ALeft: integer = -1; ATop: integer = -1; Animated: boolean = True);
    .
    .
    GetWindowRect(AOwnerControl.Handle, ctrlRect);
    with TSrcRect(acWorkRect(ctrlRect.TopLeft)), TDstRect(formRect) do begin
    if (ALeft = -1) and (ATop = -1) then begin
    DTop := ctrlRect.Bottom – 2;
    DLeft := ctrlRect.Left;
    end
    else begin
    DTop := ATop; // ????????????????????????
    DLeft := ALeft; // ????????????????????????
    end;
    DBottom := DTop + AForm.Height;
    DRight := DLeft + AForm.Width;
    AForm.SetBounds(DLeft, DTop, AForm.Width, AForm.Height);

    With this code, if ALeft and ATop are not equal to -1, the AOwnerControl does not play any role.

    I think the offending statements should be:

    Code:
    DTop := ctrlRect.Top + ATop;
    DLeft := ctrlRect.Left + ALeft;

    which gives a positioning w.r.t. the AOwnerControl

    #57676
    Support
    Keymaster

    ALeft and ATop are the absolute coordinates for showing of the popup window (coordinates are not depended from AOwnerControl)

    #57677
    HeDiBo
    Participant
    'Support' wrote:

    ALeft and ATop are the absolute coordinates for showing of the popup window (coordinates are not depended from AOwnerControl)

    Yep. And that is strange. What is the purpose of passing an AOwnerControl if it is unused (for that you have the other implementation, passing a ALeftTop TPoint).

    My change made a lot of sense, as a matter of fact, now I can use the procedure where before I had to do a lot of ClientToScreen calculations.

    #57682
    HeDiBo
    Participant

    No change in 13.02

    #57721
    HeDiBo
    Participant

    Can you explain to me what the purpose is of the AOwnerControl parameter?

    What's the benefit compared to the other call to ShowForm without this AOwnerControl?

    #57729
    Support
    Keymaster

    AOwnerControl is an owner component for the popup window.

    This control have changed WindowProc for changing of popup window if state of AOwnerControl is changed.

    Also, sometimes, when state of popup window is changed then state of AOwnerControl is changed too.

    If popup window is closed then AOwnerControl receives the AC_POPUPCLOSED command for additional processing if needed.

    Also, popup window can use the AOwnerControl for automatic calculation of own coordinates.

    So, Popup Window and AOwnerControl has synchronized behavior. AOwnerControl is a PopupCtrl in the acPopupController.pas unit, you can check it more.

    Handling of the AOwnerControl is started in this line:

    Code:
    HandlerIndex := InitFormHandler(AForm, AOwnerControl);

    Example of AOwnerControl is the TsSkinSelector component, work of popup window and combo edit is synchronized there.

    #57744
    HeDiBo
    Participant
    'Support' wrote:

    AOwnerControl is an owner component for the popup window.

    This control have changed WindowProc for changing of popup window if state of AOwnerControl is changed.

    Also, sometimes, when state of popup window is changed then state of AOwnerControl is changed too.

    If popup window is closed then AOwnerControl receives the AC_POPUPCLOSED command for additional processing if needed.

    Also, popup window can use the AOwnerControl for automatic calculation of own coordinates.

    So, Popup Window and AOwnerControl has synchronized behavior. AOwnerControl is a PopupCtrl in the acPopupController.pas unit, you can check it more.

    Handling of the AOwnerControl is started in this line:

    Code:
    HandlerIndex := InitFormHandler(AForm, AOwnerControl);

    Example of AOwnerControl is the TsSkinSelector component, work of popup window and combo edit is synchronized there.

    Thank you for explaining it so extensively.17.gif

    However I still don't understand that the ALeft and ATop parameters are not relative to the control. Because if you don't specify ALeft or ATop then the popup window IS positioned relative to the bottom of the control. If the control governs the popup window, a position relative to that control would be expected.

    #57746
    Support
    Keymaster

    Just absolute coordinates are more universal, I think.

    If you need a relative offset, then you can calculate absolute coordinates with offset.

    But what to do if you need to show a window in the independed coordinates on the screen?

    #57749
    HeDiBo
    Participant
    'Support' wrote:

    Just absolute coordinates are more universal, I think.

    If you need a relative offset, then you can calculate absolute coordinates with offset.

    But what to do if you need to show a window in the independed coordinates on the screen?

    I thought you could use the other form of the call, without the AOwnerControl. But now I understand that's not a full alternative. Thank you for enlightening me umnik.gif.

Viewing 9 posts - 1 through 9 (of 9 total)
  • You must be logged in to reply to this topic.