用于取消(浮动)客户端表单的 Delphi JvDockServer JvDockClient 通知

发布于 2024-12-29 20:29:40 字数 167 浏览 0 评论 0原文

使用 Delphi 中的 JEDI VCL 库,我在主窗体上放置了一个 JvDockServer, 在另一个应该停靠到主窗体上的情况下,我有使用停靠样式 JvDockVIDVCStyle 的 JvDockClient。

虽然停靠效果很好,但我希望在客户端表单从停靠模式更改为非停靠(浮动)模式时收到通知。

Using the JEDI VCL library with Delphi, I put a JvDockServer on the main form,
and on another that should be docked to the main form, I have JvDockClient using dock style JvDockVIDVCStyle.

While Docking works great, I would like to be notified when a client form changes from docked to undocked (floating) mode.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

苦行僧 2025-01-05 20:29:40

更新 JVCL 现已修改为包含此内置功能!当您停靠表单时,现在会触发 TForm 的内置事件。查看 JEDI JVCL 中的 DockingInCode 演示,该演示现在(截至 2012 年 3 月 27 日)包含触发对接和取消对接事件的示例。现在,在对接时会触发 TForm.OnEndDock,在取消对接时也会触发 TForm.OnUnDock。对这些名称感到抱歉,这些区域已经在 TForm 中,但我没有选择它们!

出于历史原因的旧答案:

您希望在表单浮动时收到通知。 TForm 已经具有 OnUnDockOnEndDock,但是(遗憾的是)当您使用 Jedi VCL Dock Manager 停靠和取消停靠时,它们不会被触发。

我能想到的最好方法是修改 JVCL。

修改JvDockSupportControl.pas,方法TJvDockCustomControl.WndProc:

procedure TJvDockCustomControl.WndProc(var Msg: TMessage);
var
  CMUnDockClient: TCMUnDockClient;
  DockableForm: TJvDockableForm;
  allow:Boolean;
begin
  if Msg.Msg = CM_UNDOCKCLIENT then
  begin
    CMUnDockClient := TCMUnDockClient(Msg);
    // new code starts here
    if CMUnDockClient.Client is TForm then begin
      allow := true;
      if Assigned(TForm(CMUnDockClient.Client).OnUnDock) then
        TForm(CMUnDockClient.Client).OnUnDock(Self,CMUnDockClient.Client,TWinControl(nil),allow);
//      if not allow then
//        exit; // currently JvDocking has already deleted you from the dock tree, so we can't honor this.
    end;
    // new code ends here
   if CMUnDockClient.Client is TJvDockableForm then
   begin
    ...

不幸的是,这是组件设计中的疏忽,如果您将其记录在Jedi Bug Tracker,并在此处发布链接。遗憾的是,JvDocking 的内部结构很复杂,但上面的技巧可能会让您从今天开始就可以继续使用。

编辑 JVCL 的替代方法是根据您喜欢使用的 Dock 样式创建您自己的样式,并向其中添加 OnDock 和 OnFloat 事件。例如,如果您使用的是 VID (Visual Interdev) 停靠样式,请将 JvDockVIDStyle.pas 复制到您自己的单元,并将其重命名为其他名称。

在代码中找到这个过程:

    procedure TJvDockVIDTree.WindowProc(var Msg: TMessage);

将现有代码保留在该函数中,并在底部添加以下内容:

if (Msg.msg =CM_UNDOCKCLIENT)and Assigned(FOnUndock) then
    FOnUndock( TObject(Msg.Client))

我认为我应该编写上述内容的更好版本并将其放入 JVCL JvDocking 中,因为它是一个直观的东西。此外,也许应该使 OnEndDock 发挥作用。 OnStartDock 与 JvDocking 不兼容,因此我无法添加它。

Update The JVCL is now modified to contain this feature built in! The TForm's built in events is now fired when you dock a form. Check out the DockingInCode demo in the JEDI JVCL, which now (as of March 27 2012) contains samples of Docking and Undocking events firing. TForm.OnEndDock is now fired when docking, as is TForm.OnUnDock on undocking. Sorry about the names, those area already in TForm and I didn't choose them!

OLD ANSWER for historical reasons:

You would like a notification when a form has been made to float. TForm already has OnUnDock and OnEndDock, but these are (sadly) not fired when you dock and undock using the Jedi VCL Dock Manager.

The best method I can think of to do this is to modify the JVCL.

Modify JvDockSupportControl.pas, method TJvDockCustomControl.WndProc:

procedure TJvDockCustomControl.WndProc(var Msg: TMessage);
var
  CMUnDockClient: TCMUnDockClient;
  DockableForm: TJvDockableForm;
  allow:Boolean;
begin
  if Msg.Msg = CM_UNDOCKCLIENT then
  begin
    CMUnDockClient := TCMUnDockClient(Msg);
    // new code starts here
    if CMUnDockClient.Client is TForm then begin
      allow := true;
      if Assigned(TForm(CMUnDockClient.Client).OnUnDock) then
        TForm(CMUnDockClient.Client).OnUnDock(Self,CMUnDockClient.Client,TWinControl(nil),allow);
//      if not allow then
//        exit; // currently JvDocking has already deleted you from the dock tree, so we can't honor this.
    end;
    // new code ends here
   if CMUnDockClient.Client is TJvDockableForm then
   begin
    ...

Unfortunately this is an oversight in the design of the components, and if you log it in the Jedi Bug Tracker, and post the link to it here. JvDocking internals are complex, sadly, but the above hack might get you going as of today.

Alternative to editing JVCL is to make your own Style, based on the Dock Style that you prefer to use, and add OnDock and OnFloat events to it. For example, if you are using the VID (Visual Interdev) dock style, copy JvDockVIDStyle.pas to your own unit, and rename it to something else.

Find this procedure in the code:

    procedure TJvDockVIDTree.WindowProc(var Msg: TMessage);

leave the existing code in that function and add the following at the bottom:

if (Msg.msg =CM_UNDOCKCLIENT)and Assigned(FOnUndock) then
    FOnUndock( TObject(Msg.Client))

I think that I should write a better version of the above and put it into the JVCL JvDocking, since it's an intuitive thing. In addition OnEndDock should probably be made to function. OnStartDock is incompatible with JvDocking, so I can't add that.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文