- This topic has 8 replies, 2 voices, and was last updated 6 years, 7 months ago by HeDiBo.
-
AuthorPosts
-
March 9, 2018 at 1:31 pm #37765HeDiBoParticipant
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
March 9, 2018 at 3:25 pm #57676SupportKeymasterALeft and ATop are the absolute coordinates for showing of the popup window (coordinates are not depended from AOwnerControl)
March 9, 2018 at 3:31 pm #57677HeDiBoParticipant'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.
March 10, 2018 at 12:14 pm #57682HeDiBoParticipantNo change in 13.02
March 21, 2018 at 1:55 pm #57721HeDiBoParticipantCan 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?
March 24, 2018 at 9:23 am #57729SupportKeymasterAOwnerControl 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.
March 24, 2018 at 4:58 pm #57744HeDiBoParticipant'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.
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.
March 24, 2018 at 6:26 pm #57746SupportKeymasterJust 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?
March 24, 2018 at 9:53 pm #57749HeDiBoParticipant'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 .
-
AuthorPosts
- You must be logged in to reply to this topic.