{"id":971,"date":"2014-04-22T21:36:58","date_gmt":"2014-04-22T20:36:58","guid":{"rendered":"http:\/\/tulip-ui.azurewebsites.net\/?page_id=971"},"modified":"2014-04-22T23:17:46","modified_gmt":"2014-04-22T22:17:46","slug":"tulip-ui-pas","status":"publish","type":"page","link":"https:\/\/tulip-ui.azurewebsites.net\/?page_id=971","title":{"rendered":"Tulip.UI.pas"},"content":{"rendered":"<div style=\"background-color: #FFFFFF; width: 680px\">\n<p style=\"text-align: right;\"><a title=\"Source Files\" href=\"http:\/\/tulip-ui.azurewebsites.net\/?page_id=1091\">Source Files<\/a><\/p>\n<p><code><\/p>\n<pre>\r\n{******************************************************************************}\r\n{                                                                              }\r\n{                        Tulip - User Interface Library                        }\r\n{                                                                              }\r\n{         Copyright(c) 2012 - 2013 Marcos Gomes. All rights Reserved.          }\r\n{                                                                              }\r\n{  --------------------------------------------------------------------------  }\r\n{                                                                              }\r\n{  This product is based on Asphyre Sphinx (c) 2000 - 2012  Yuriy Kotsarenko.  }\r\n{       All rights reserved. Official web site: http:\/\/www.afterwarp.net       }\r\n{                                                                              }\r\n{******************************************************************************}\r\n{                                                                              }\r\n{  Important Notice:                                                           }\r\n{                                                                              }\r\n{  If you modify\/use this code or one of its parts either in original or       }\r\n{  modified form, you must comply with Mozilla Public License Version 2.0,     }\r\n{  including section 3, \"Responsibilities\". Failure to do so will result in    }\r\n{  the license breach, which will be resolved in the court. Remember that      }\r\n{  violating author's rights either accidentally or intentionally is           }\r\n{  considered a serious crime in many countries. Thank you!                    }\r\n{                                                                              }\r\n{  !! Please *read* Mozilla Public License 2.0 document located at:            }\r\n{  http:\/\/www.mozilla.org\/MPL\/                                                 }\r\n{                                                                              }\r\n{  --------------------------------------------------------------------------  }\r\n{                                                                              }\r\n{  The contents of this file are subject to the Mozilla Public License         }\r\n{  Version 2.0 (the \"License\"); you may not use this file except in            }\r\n{  compliance with the License. You may obtain a copy of the License at        }\r\n{  http:\/\/www.mozilla.org\/MPL\/                                                 }\r\n{                                                                              }\r\n{  Software distributed under the License is distributed on an \"AS IS\"         }\r\n{  basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the     }\r\n{  License for the specific language governing rights and limitations          }\r\n{  under the License.                                                          }\r\n{                                                                              }\r\n{  The Original Code is Tulip.UI.pas.                                          }\r\n{                                                                              }\r\n{  The Initial Developer of the Original Code is Marcos Gomes.                 }\r\n{  Portions created by Marcos Gomes are Copyright (C) 2012, Marcos Gomes.      }\r\n{  All Rights Reserved.                                                        }\r\n{                                                                              }\r\n{******************************************************************************}\r\n{                                                                              }\r\n{  Tulip.UI.pas                                         Modified: 23-Mar-2013  }\r\n{  --------------------------------------------------------------------------  }\r\n{                                                                              }\r\n{                      User Controls and ControlManager                        }\r\n{                                                                              }\r\n{                                Version 1.03                                  }\r\n{                                                                              }\r\n{******************************************************************************}\r\n\r\nunit Tulip.UI;\r\n\r\ninterface\r\n\r\nuses\r\n  Winapi.Messages, System.Types, System.Classes, Vcl.Controls, Vcl.Forms,\r\n  Vcl.Clipbrd,\r\n  \/\/ Asphyre Units\r\n  AbstractDevices, AbstractCanvas,\r\n  \/\/ Tulip UI Units\r\n  Tulip.UI.Controls, Tulip.UI.Forms, Tulip.UI.Images, Tulip.UI.Labels,\r\n  Tulip.UI.Panels, Tulip.UI.Buttons, Tulip.UI.EditBoxes,\r\n  Tulip.UI.CheckBoxes, Tulip.UI.RadioButtons, Tulip.UI.ProgressBars,\r\n  Tulip.UI.PaintBoxes, Tulip.UI.TrackBars, Tulip.UI.ListBoxes;\r\n\r\ntype\r\n\r\n{$REGION 'TAButton'}\r\n  TAButton = class(TCustomAButton)\r\n  published\r\n    property Antialiased;\r\n    property Border;\r\n    property Caption;\r\n    property Color;\r\n    property ColorHover;\r\n    property ColorPressed;\r\n    property FocusRect;\r\n    property Font;\r\n    property Image;\r\n    property ImageHover;\r\n    property ImagePressed;\r\n    property Margin;\r\n    property Shadow;\r\n    property Transparent;\r\n  end;\r\n\r\n  TAButtonClass = class of TAButton;\r\n{$ENDREGION}\r\n{$REGION 'TACheckBox'}\r\n\r\n  TACheckBox = class(TCustomACheckBox)\r\n  published\r\n    property Antialiased;\r\n    property Border;\r\n    property Box;\r\n    property Caption;\r\n    property Checked;\r\n    property Color;\r\n    property FocusRect;\r\n    property Font;\r\n    property Image;\r\n    property Margin;\r\n    property ReadOnly;\r\n    property Transparent;\r\n  end;\r\n\r\n  TACheckBoxClass = class of TACheckBox;\r\n{$ENDREGION}\r\n{$REGION 'TAEditBox'}\r\n\r\n  TAEditBox = class(TCustomAEditBox)\r\n  published\r\n    property Antialiased;\r\n    property AutoSelect;\r\n    property Border;\r\n    property Color;\r\n    property FocusRect;\r\n    property Font;\r\n    property Image;\r\n    property Margin;\r\n    property MaxLength;\r\n    property ReadOnly;\r\n    property Text;\r\n  end;\r\n\r\n  TAEditboxClass = class of TAEditBox;\r\n{$ENDREGION}\r\n{$REGION 'TAForm'}\r\n\r\n  TAForm = class(TCustomAForm)\r\n  published\r\n    property Antialiased;\r\n    property Border;\r\n    property BoundToScreen;\r\n    property Caption;\r\n    property CanMove;\r\n    property Color;\r\n    property Font;\r\n    property Image;\r\n    property Margin;\r\n    property Shadow;\r\n    property WordWrap;\r\n  end;\r\n\r\n  TAFormClass = class of TAForm;\r\n{$ENDREGION}\r\n{$REGION 'TAImage'}\r\n\r\n  TAImage = class(TCustomAImage)\r\n  published\r\n    property Antialiased;\r\n    property Border;\r\n    property CanMoveHandle;\r\n    property Color;\r\n    property Image;\r\n  end;\r\n\r\n  TAImageClass = class of TAImage;\r\n{$ENDREGION}\r\n{$REGION 'TALabel'}\r\n\r\n  TALabel = class(TCustomALabel)\r\n  published\r\n    property Antialiased;\r\n    property Border;\r\n    property CanMoveHandle;\r\n    property Caption;\r\n    property Color;\r\n    property FocusControl;\r\n    property Font;\r\n    property Image;\r\n    property Margin;\r\n    property Transparent;\r\n    property WordWrap;\r\n  end;\r\n\r\n  TALabelClass = class of TALabel;\r\n{$ENDREGION}\r\n{$REGION 'TAListBox'}\r\n\r\n  TAListBox = class(TCustomAListBox)\r\n  published\r\n    property Antialiased;\r\n    property Border;\r\n    property Color;\r\n    property DownButton;\r\n    property FocusRect;\r\n    property Font;\r\n    property Image;\r\n    property ItemIndex;\r\n    property LineHeight;\r\n    property Lines;\r\n    property Margin;\r\n    property ScrollButton;\r\n    property Transparent;\r\n    property UpButton;\r\n  end;\r\n\r\n  TAListBoxClass = class of TAListBox;\r\n{$ENDREGION}\r\n{$REGION 'TAPaintBox'}\r\n\r\n  TAPaintBox = class(TCustomAPaintBox)\r\n  published\r\n    property Antialiased;\r\n    property CanMoveHandle;\r\n  end;\r\n\r\n  TAPaintBoxClass = class of TAPaintBox;\r\n{$ENDREGION}\r\n{$REGION 'TAPanel'}\r\n\r\n  TAPanel = class(TCustomAPanel)\r\n  published\r\n    property Antialiased;\r\n    property Border;\r\n    property CanMoveHandle;\r\n    property Caption;\r\n    property Color;\r\n    property Font;\r\n    property Image;\r\n    property Margin;\r\n    property Transparent;\r\n  end;\r\n\r\n  TAPanelClass = class of TAPanel;\r\n{$ENDREGION}\r\n{$REGION 'TAProgressBar'}\r\n\r\n  TAProgressBar = class(TCustomAProgressBar)\r\n  published\r\n    property Antialiased;\r\n    property Border;\r\n    property CanMoveHandle;\r\n    property Caption;\r\n    property Color;\r\n    property Display;\r\n    property Font;\r\n    property Image;\r\n    property Margin;\r\n    property Max;\r\n    property Min;\r\n    property Position;\r\n    property ProgressColor;\r\n    property Transparent;\r\n  end;\r\n\r\n  TAProgressBarClass = class of TAProgressBar;\r\n{$ENDREGION}\r\n{$REGION 'TARadioButton'}\r\n\r\n  TARadioButton = class(TCustomARadioButton)\r\n  published\r\n    property Antialiased;\r\n    property Border;\r\n    property Box;\r\n    property Caption;\r\n    property Checked;\r\n    property Color;\r\n    property FocusRect;\r\n    property Font;\r\n    property Image;\r\n    property Margin;\r\n    property ReadOnly;\r\n    property Transparent;\r\n  end;\r\n\r\n  TARadioButtonClass = class of TARadioButton;\r\n{$ENDREGION}\r\n{$REGION 'TATrackBar'}\r\n\r\n  TATrackBar = class(TCustomATrackBar)\r\n  published\r\n    property Antialiased;\r\n    property Border;\r\n    property Button;\r\n    property Color;\r\n    property FocusRect;\r\n    property Image;\r\n    property Increment;\r\n    property Margin;\r\n    property Max;\r\n    property Min;\r\n    property Position;\r\n    property Transparent;\r\n  end;\r\n\r\n  TATrackBarClass = class of TATrackBar;\r\n{$ENDREGION}\r\n{$REGION 'TAControlManager'}\r\n\r\n  TAControlManager = class(TCustomManager)\r\n  private\r\n    procedure AcquireEvents;\r\n    procedure RestoreEvents;\r\n    procedure ShortCut(var Msg: TWMKey; var Handled: Boolean);\r\n  protected\r\n    procedure Click(Sender: TObject); virtual;\r\n    procedure DblClick(Sender: TObject); virtual;\r\n\r\n    procedure KeyDown(Sender: TObject; var Key: Word;\r\n      Shift: TShiftState); virtual;\r\n    procedure KeyPress(Sender: TObject; var Key: Char); virtual;\r\n    procedure KeyUp(Sender: TObject; var Key: Word;\r\n      Shift: TShiftState); virtual;\r\n\r\n    procedure MouseEnter(Sender: TObject); virtual;\r\n    procedure MouseLeave(Sender: TObject); virtual;\r\n\r\n    procedure MouseDown(Sender: TObject; Button: TMouseButton;\r\n      Shift: TShiftState; X, Y: Integer); virtual;\r\n    procedure MouseUp(Sender: TObject; Button: TMouseButton; Shift: TShiftState;\r\n      X, Y: Integer); virtual;\r\n    procedure MouseMove(Sender: TObject; Shift: TShiftState;\r\n      X, Y: Integer); virtual;\r\n\r\n    procedure MouseWheel(Sender: TObject; Shift: TShiftState;\r\n      WheelDelta: Integer; MousePos: TPoint; var Handled: Boolean); virtual;\r\n    procedure MouseWheelDown(Sender: TObject; Shift: TShiftState;\r\n      MousePos: TPoint; var Handled: Boolean); virtual;\r\n    procedure MouseWheelUp(Sender: TObject; Shift: TShiftState;\r\n      MousePos: TPoint; var Handled: Boolean); virtual;\r\n\r\n    procedure SetParent(const AParent: TComponent); override;\r\n  public\r\n    destructor Destroy; override;\r\n\r\n    function GetClipboard: TClipboard;\r\n    function GetParentAsControl: TControl;\r\n\r\n    function AButton(const Parent, Name: String): TAButton;\r\n    function ACheckBox(const Parent, Name: String): TACheckBox;\r\n    function AEditBox(const Parent, Name: String): TAEditBox;\r\n    function AForm(const Name: String): TAForm;\r\n    function AImage(const Parent, Name: String): TAImage;\r\n    function ALabel(const Parent, Name: String): TALabel;\r\n    function AListBox(const Parent, Name: String): TAListBox;\r\n    function APaintBox(const Parent, Name: String): TAPaintBox;\r\n    function APanel(const Parent, Name: String): TAPanel;\r\n    function AProgressBar(const Parent, Name: String): TAProgressBar;\r\n    function ARadioButton(const Parent, Name: String): TARadioButton;\r\n    function ATrackBar(const Parent, Name: String): TATrackBar;\r\n  end;\r\n{$ENDREGION}\r\n\r\nimplementation\r\n\r\n{$REGION 'TAControlManager'}\r\n{ TAControlManager }\r\n\r\nfunction TAControlManager.AButton(const Parent, Name: String): TAButton;\r\nvar\r\n  AControl: TAControl;\r\nbegin\r\n  Result := nil;\r\n\r\n  AControl := Self.Root.FindChildControl(Parent, False);\r\n\r\n  if AControl <> nil then\r\n    if AControl is TAForm then\r\n      AControl := TAForm(AControl).FindChildControl(Name, True);\r\n\r\n  if AControl <> nil then\r\n    if AControl is TAButton then\r\n      Result := TAButton(AControl);\r\nend;\r\n\r\nfunction TAControlManager.ACheckBox(const Parent, Name: String): TACheckBox;\r\nvar\r\n  AControl: TAControl;\r\nbegin\r\n  Result := nil;\r\n\r\n  AControl := Self.Root.FindChildControl(Parent, False);\r\n\r\n  if AControl <> nil then\r\n    if AControl is TAForm then\r\n      AControl := TAForm(AControl).FindChildControl(Name, True);\r\n\r\n  if AControl <> nil then\r\n    if AControl is TACheckBox then\r\n      Result := TACheckBox(AControl);\r\nend;\r\n\r\nprocedure TAControlManager.AcquireEvents;\r\nbegin\r\n  if Parent is TForm then\r\n  begin\r\n    Self.OwnerMouseEnter := TForm(Parent).OnMouseEnter;\r\n    Self.OwnerMouseLeave := TForm(Parent).OnMouseLeave;\r\n    Self.OwnerMouseDown := TForm(Parent).OnMouseDown;\r\n    Self.OwnerMouseUp := TForm(Parent).OnMouseUp;\r\n    Self.OwnerMouseMove := TForm(Parent).OnMouseMove;\r\n    Self.OwnerMouseWheel := TForm(Parent).OnMouseWheel;\r\n    Self.OwnerMouseWheelDown := TForm(Parent).OnMouseWheelDown;\r\n    Self.OwnerMouseWheelUp := TForm(Parent).OnMouseWheelUp;\r\n\r\n    Self.OwnerKeyDown := TForm(Parent).OnKeyDown;\r\n    Self.OwnerKeyUp := TForm(Parent).OnKeyUp;\r\n    Self.OwnerKeyPress := TForm(Parent).OnKeyPress;\r\n    Self.OwnerShortCut := TForm(Parent).OnShortCut;\r\n\r\n    Self.OwnerClick := TForm(Parent).OnClick;\r\n    Self.OwnerDblClick := TForm(Parent).OnDblClick;\r\n\r\n    TForm(Parent).OnMouseDown := MouseDown;\r\n    TForm(Parent).OnMouseUp := MouseUp;\r\n    TForm(Parent).OnMouseMove := MouseMove;\r\n    TForm(Parent).OnMouseEnter := MouseEnter;\r\n    TForm(Parent).OnMouseLeave := MouseLeave;\r\n    TForm(Parent).OnMouseWheel := MouseWheel;\r\n    TForm(Parent).OnMouseWheelDown := MouseWheelDown;\r\n    TForm(Parent).OnMouseWheelUp := MouseWheelUp;\r\n\r\n    TForm(Parent).OnKeyDown := KeyDown;\r\n    TForm(Parent).OnKeyUp := KeyUp;\r\n    TForm(Parent).OnKeyPress := KeyPress;\r\n\r\n    TForm(Parent).OnClick := Click;\r\n    TForm(Parent).OnDblClick := DblClick;\r\n    TForm(Parent).OnShortCut := ShortCut;\r\n\r\n  end;\r\nend;\r\n\r\nfunction TAControlManager.AEditBox(const Parent, Name: String): TAEditBox;\r\nvar\r\n  AControl: TAControl;\r\nbegin\r\n  Result := nil;\r\n\r\n  AControl := Self.Root.FindChildControl(Parent, False);\r\n\r\n  if AControl <> nil then\r\n    if AControl is TAForm then\r\n      AControl := TAForm(AControl).FindChildControl(Name, True);\r\n\r\n  if AControl <> nil then\r\n    if AControl is TAEditBox then\r\n      Result := TAEditBox(AControl);\r\nend;\r\n\r\nfunction TAControlManager.AForm(const Name: String): TAForm;\r\nvar\r\n  AControl: TAControl;\r\nbegin\r\n  Result := nil;\r\n\r\n  AControl := Self.Root.FindChildControl(Name, False);\r\n\r\n  if AControl <> nil then\r\n    if AControl is TAForm then\r\n      Result := TAForm(AControl);\r\nend;\r\n\r\nfunction TAControlManager.AImage(const Parent, Name: String): TAImage;\r\nvar\r\n  AControl: TAControl;\r\nbegin\r\n  Result := nil;\r\n\r\n  AControl := Self.Root.FindChildControl(Parent, False);\r\n\r\n  if AControl <> nil then\r\n    if AControl is TAForm then\r\n      AControl := TAForm(AControl).FindChildControl(Name, True);\r\n\r\n  if AControl <> nil then\r\n    if AControl is TAImage then\r\n      Result := TAImage(AControl);\r\nend;\r\n\r\nfunction TAControlManager.ALabel(const Parent, Name: String): TALabel;\r\nvar\r\n  AControl: TAControl;\r\nbegin\r\n  Result := nil;\r\n\r\n  AControl := Self.Root.FindChildControl(Parent, False);\r\n\r\n  if AControl <> nil then\r\n    if AControl is TAForm then\r\n      AControl := TAForm(AControl).FindChildControl(Name, True);\r\n\r\n  if AControl <> nil then\r\n    if AControl is TALabel then\r\n      Result := TALabel(AControl);\r\nend;\r\n\r\nfunction TAControlManager.AListBox(const Parent, Name: String): TAListBox;\r\nvar\r\n  AControl: TAControl;\r\nbegin\r\n  Result := nil;\r\n\r\n  AControl := Self.Root.FindChildControl(Parent, False);\r\n\r\n  if AControl <> nil then\r\n    if AControl is TAForm then\r\n      AControl := TAForm(AControl).FindChildControl(Name, True);\r\n\r\n  if AControl <> nil then\r\n    if AControl is TAListBox then\r\n      Result := TAListBox(AControl);\r\nend;\r\n\r\nfunction TAControlManager.APaintBox(const Parent, Name: String): TAPaintBox;\r\nvar\r\n  AControl: TAControl;\r\nbegin\r\n  Result := nil;\r\n\r\n  AControl := Self.Root.FindChildControl(Parent, False);\r\n\r\n  if AControl <> nil then\r\n    if AControl is TAForm then\r\n      AControl := TAForm(AControl).FindChildControl(Name, True);\r\n\r\n  if AControl <> nil then\r\n    if AControl is TAPaintBox then\r\n      Result := TAPaintBox(AControl);\r\nend;\r\n\r\nfunction TAControlManager.APanel(const Parent, Name: String): TAPanel;\r\nvar\r\n  AControl: TAControl;\r\nbegin\r\n  Result := nil;\r\n\r\n  AControl := Self.Root.FindChildControl(Parent, False);\r\n\r\n  if AControl <> nil then\r\n    if AControl is TAForm then\r\n      AControl := TAForm(AControl).FindChildControl(Name, True);\r\n\r\n  if AControl <> nil then\r\n    if AControl is TAPanel then\r\n      Result := TAPanel(AControl);\r\nend;\r\n\r\nfunction TAControlManager.AProgressBar(const Parent, Name: String)\r\n  : TAProgressBar;\r\nvar\r\n  AControl: TAControl;\r\nbegin\r\n  Result := nil;\r\n\r\n  AControl := Self.Root.FindChildControl(Parent, False);\r\n\r\n  if AControl <> nil then\r\n    if AControl is TAForm then\r\n      AControl := TAForm(AControl).FindChildControl(Name, True);\r\n\r\n  if AControl <> nil then\r\n    if AControl is TAProgressBar then\r\n      Result := TAProgressBar(AControl);\r\nend;\r\n\r\nfunction TAControlManager.ARadioButton(const Parent, Name: String)\r\n  : TARadioButton;\r\nvar\r\n  AControl: TAControl;\r\nbegin\r\n  Result := nil;\r\n\r\n  AControl := Self.Root.FindChildControl(Parent, False);\r\n\r\n  if AControl <> nil then\r\n    if AControl is TAForm then\r\n      AControl := TAForm(AControl).FindChildControl(Name, True);\r\n\r\n  if AControl <> nil then\r\n    if AControl is TARadioButton then\r\n      Result := TARadioButton(AControl);\r\nend;\r\n\r\nfunction TAControlManager.ATrackBar(const Parent, Name: String): TATrackBar;\r\nvar\r\n  AControl: TAControl;\r\nbegin\r\n  Result := nil;\r\n\r\n  AControl := Self.Root.FindChildControl(Parent, False);\r\n\r\n  if AControl <> nil then\r\n    if AControl is TAForm then\r\n      AControl := TAForm(AControl).FindChildControl(Name, True);\r\n\r\n  if AControl <> nil then\r\n    if AControl is TATrackBar then\r\n      Result := TATrackBar(AControl);\r\nend;\r\n\r\nprocedure TAControlManager.Click(Sender: TObject);\r\nvar\r\n  Control: TAControl;\r\nbegin\r\n  if (Assigned(OwnerClick)) then\r\n    OwnerClick(Sender);\r\n  if (Active) then\r\n  begin\r\n    Control := PreviousControl;\r\n    if (Control <> nil) then\r\n      if (Control.Enabled) and (Control.Visible) then\r\n        Control.Click;\r\n  end;\r\nend;\r\n\r\nprocedure TAControlManager.DblClick(Sender: TObject);\r\nvar\r\n  Control: TAControl;\r\nbegin\r\n  if (Assigned(OwnerDblClick)) then\r\n    OwnerDblClick(Sender);\r\n  if (Active) then\r\n  begin\r\n    Control := PreviousControl;\r\n    if (Control <> nil) then\r\n      if (Control.Enabled) and (Control.Visible) then\r\n        Control.DblClick;\r\n  end;\r\nend;\r\n\r\ndestructor TAControlManager.Destroy;\r\nbegin\r\n  RestoreEvents;\r\n\r\n  inherited;\r\nend;\r\n\r\nprocedure TAControlManager.ShortCut(var Msg: TWMKey; var Handled: Boolean);\r\nvar\r\n  Key: Word;\r\n  Shift: TShiftState;\r\nbegin\r\n  if Msg.CharCode = 9 then\r\n  begin\r\n    Key := Msg.CharCode;\r\n    Shift := KeyDataToShiftState(Msg.KeyData);\r\n    Self.KeyDown(Parent, Key, Shift);\r\n    Handled := True;\r\n  end;\r\nend;\r\n\r\nfunction TAControlManager.GetClipboard: TClipboard;\r\nbegin\r\n  Result := Clipboard;\r\nend;\r\n\r\nfunction TAControlManager.GetParentAsControl: TControl;\r\nbegin\r\n  if Parent is TControl then\r\n    Result := Parent as TControl\r\n  else\r\n    Result := nil;\r\nend;\r\n\r\nprocedure TAControlManager.KeyDown(Sender: TObject; var Key: Word;\r\n  Shift: TShiftState);\r\nvar\r\n  Control: TWControl;\r\nbegin\r\n  if (Assigned(OwnerKeyDown)) then\r\n    OwnerKeyDown(Sender, Key, Shift);\r\n  if (Active) then\r\n  begin\r\n    Control := ActiveControl;\r\n    if Control <> nil then\r\n    begin\r\n      if (Control.Enabled) and (Control.Visible) then\r\n        Control.KeyDown(Key, Shift);\r\n    end\r\n    else if Root.GetWControls <> nil then\r\n      TWControl(Root.GetWControls[Root.GetWControls.Count - 1])\r\n        .KeyDown(Key, Shift)\r\n    else\r\n      Root.KeyDown(Key, Shift);\r\n  end;\r\nend;\r\n\r\nprocedure TAControlManager.KeyPress(Sender: TObject; var Key: Char);\r\nvar\r\n  Control: TWControl;\r\nbegin\r\n  if (Assigned(OwnerKeyPress)) then\r\n    OwnerKeyPress(Sender, Key);\r\n  if (Active) then\r\n  begin\r\n    Control := ActiveControl;\r\n    if Control <> nil then\r\n    begin\r\n      if (Control.Enabled) and (Control.Visible) then\r\n        Control.KeyPress(Key);\r\n    end\r\n    else if Root.GetWControls <> nil then\r\n      TWControl(Root.GetWControls[Root.GetWControls.Count - 1]).KeyPress(Key)\r\n    else\r\n      Root.KeyPress(Key);\r\n  end;\r\nend;\r\n\r\nprocedure TAControlManager.KeyUp(Sender: TObject; var Key: Word;\r\n  Shift: TShiftState);\r\nvar\r\n  Control: TWControl;\r\nbegin\r\n  if (Assigned(OwnerKeyUp)) then\r\n    OwnerKeyUp(Sender, Key, Shift);\r\n  if (Active) then\r\n  begin\r\n    Control := ActiveControl;\r\n    if Control <> nil then\r\n    begin\r\n      if (Control.Enabled) and (Control.Visible) then\r\n        Control.KeyUp(Key, Shift);\r\n    end\r\n    else if Root.GetWControls <> nil then\r\n      TWControl(Root.GetWControls[Root.GetWControls.Count - 1])\r\n        .KeyUp(Key, Shift)\r\n    else\r\n      Root.KeyUp(Key, Shift);\r\n  end;\r\nend;\r\n\r\nprocedure TAControlManager.MouseDown(Sender: TObject; Button: TMouseButton;\r\n  Shift: TShiftState; X, Y: Integer);\r\nvar\r\n  Control: TAControl;\r\nbegin\r\n  \/\/ fixes coordinates when scaled\r\n  if (Self.Parent is TControl) then\r\n  begin\r\n    if Self.Device.SwapChains.Items[0].Width <> TControl(Self.Parent).ClientWidth\r\n    then\r\n      X := Trunc(X * (Self.Device.SwapChains.Items[0].Width \/\r\n        TControl(Self.Parent).ClientWidth));\r\n    if Self.Device.SwapChains.Items[0].Height <> TControl(Self.Parent).ClientHeight\r\n    then\r\n      Y := Trunc(Y * (Self.Device.SwapChains.Items[0].Height \/\r\n        TControl(Self.Parent).ClientHeight));\r\n  end;\r\n\r\n  if (Assigned(OwnerMouseDown)) then\r\n    OwnerMouseDown(Sender, Button, Shift, X, Y);\r\n  if (Active) then\r\n  begin\r\n    Control := Root.ControlAtPos(Point(X, Y), True, True, True);\r\n\r\n    \/\/ Check if is Modal\r\n    if ActiveControl <> nil then\r\n    begin\r\n      if ActiveControl.Handle <> nil then\r\n      begin\r\n        if ActiveControl.Handle is TAForm then\r\n        begin\r\n          if (TAForm(ActiveControl.Handle).IsModal) and\r\n            (ActiveControl.Handle <> Control) then\r\n          begin\r\n            if (Control <> nil) then\r\n            begin\r\n              if ActiveControl.Handle.FindChildControl(Control.Name, True) = nil\r\n              then\r\n                Exit;\r\n            end\r\n            else\r\n            begin\r\n              Exit;\r\n            end;\r\n          end;\r\n        end;\r\n      end;\r\n    end;\r\n\r\n    if (Control <> nil) then\r\n    begin\r\n      if (Control.Enabled = True) then\r\n        Control.MouseDown(Button, Shift, X, Y);\r\n      PreviousControl := Control;\r\n    end;\r\n  end;\r\nend;\r\n\r\nprocedure TAControlManager.MouseEnter(Sender: TObject);\r\nvar\r\n  Control: TAControl;\r\nbegin\r\n  if (Assigned(OwnerMouseEnter)) then\r\n    OwnerMouseEnter(Sender);\r\n  if (Active) then\r\n  begin\r\n    Root.MouseEnter;\r\n    Control := PreviousControl;\r\n    if (Control <> nil) then\r\n      if (Control.Enabled) and (Control.Visible) then\r\n        Control.MouseEnter;\r\n  end;\r\nend;\r\n\r\nprocedure TAControlManager.MouseLeave(Sender: TObject);\r\nvar\r\n  Control: TAControl;\r\nbegin\r\n  if (Assigned(OwnerMouseLeave)) then\r\n    OwnerMouseLeave(Sender);\r\n  if (Active) then\r\n  begin\r\n    Root.MouseLeave;\r\n    Control := PreviousControl;\r\n    if (Control <> nil) then\r\n      if (Control.Enabled) and (Control.Visible) then\r\n        Control.MouseLeave;\r\n  end;\r\nend;\r\n\r\nprocedure TAControlManager.MouseMove(Sender: TObject; Shift: TShiftState;\r\n  X, Y: Integer);\r\nvar\r\n  Control: TAControl;\r\nbegin\r\n  \/\/ fixes coordinates when scaled\r\n  if (Self.Parent is TControl) then\r\n  begin\r\n    if Self.Device.SwapChains.Items[0].Width <> TControl(Self.Parent).ClientWidth\r\n    then\r\n      X := Trunc(X * (Self.Device.SwapChains.Items[0].Width \/\r\n        TControl(Self.Parent).ClientWidth));\r\n    if Self.Device.SwapChains.Items[0].Height <> TControl(Self.Parent).ClientHeight\r\n    then\r\n      Y := Trunc(Y * (Self.Device.SwapChains.Items[0].Height \/\r\n        TControl(Self.Parent).ClientHeight));\r\n  end;\r\n\r\n  if (Assigned(OwnerMouseMove)) then\r\n    OwnerMouseMove(Sender, Shift, X, Y);\r\n\r\n  if (Active) then\r\n  begin\r\n    if Shift = [ssLeft] then\r\n      Control := PreviousControl\r\n    else\r\n      Control := Root.ControlAtPos(Point(X, Y), True, True, True);\r\n\r\n    \/\/ Check if is Modal\r\n    if ActiveControl <> nil then\r\n    begin\r\n      if ActiveControl.Handle <> nil then\r\n      begin\r\n        if ActiveControl.Handle is TAForm then\r\n        begin\r\n          if (TAForm(ActiveControl.Handle).IsModal) and\r\n            (ActiveControl.Handle <> Control) then\r\n          begin\r\n            if (Control <> nil) then\r\n            begin\r\n              if ActiveControl.Handle.FindChildControl(Control.Name, True) = nil\r\n              then\r\n                Exit;\r\n            end\r\n            else\r\n            begin\r\n              Exit;\r\n            end;\r\n          end;\r\n        end;\r\n      end;\r\n    end;\r\n\r\n    if (PreviousControl <> Control) then\r\n    begin\r\n      if (PreviousControl <> nil) then\r\n      begin\r\n        if (PreviousControl.Enabled) and (PreviousControl.Visible) then\r\n          if PreviousControl is TWControl then\r\n          begin\r\n            if Control <> nil then\r\n            begin\r\n              if TWControl(PreviousControl).FindChildControl(Control.Name) = nil\r\n              then\r\n                PreviousControl.MouseLeave;\r\n            end\r\n            else\r\n              PreviousControl.MouseLeave;\r\n          end\r\n          else\r\n            PreviousControl.MouseLeave;\r\n      end;\r\n      if (Control <> nil) then\r\n      begin\r\n        if (Control.Enabled) and (Control.Visible) then\r\n          Control.MouseEnter;\r\n      end;\r\n      PreviousControl := Control;\r\n    end;\r\n\r\n    if (Control <> nil) then\r\n    begin\r\n      if (Control.Enabled) and (Control.Visible) then\r\n        Control.MouseMove(Shift, X, Y);\r\n    end;\r\n\r\n    \/\/ used for tests only\r\n    {\r\n      if Control <> nil then\r\n      TForm(Parent).caption := '(' + Inttostr(X) + ',' + Inttostr(Y)\r\n      + ') - ' + Control.Name\r\n      else\r\n      TForm(Parent).caption := '(' + Inttostr(X) + ',' + Inttostr(Y) + ')';\r\n    }\r\n  end;\r\nend;\r\n\r\nprocedure TAControlManager.MouseUp(Sender: TObject; Button: TMouseButton;\r\n  Shift: TShiftState; X, Y: Integer);\r\nvar\r\n  Control: TAControl;\r\nbegin\r\n  \/\/ fixes coordinates when scaled\r\n  if (Self.Parent is TControl) then\r\n  begin\r\n    if Self.Device.SwapChains.Items[0].Width <> TControl(Self.Parent).ClientWidth\r\n    then\r\n      X := Trunc(X * (Self.Device.SwapChains.Items[0].Width \/\r\n        TControl(Self.Parent).ClientWidth));\r\n    if Self.Device.SwapChains.Items[0].Height <> TControl(Self.Parent).ClientHeight\r\n    then\r\n      Y := Trunc(Y * (Self.Device.SwapChains.Items[0].Height \/\r\n        TControl(Self.Parent).ClientHeight));\r\n  end;\r\n\r\n  if (Assigned(OwnerMouseUp)) then\r\n    OwnerMouseUp(Sender, Button, Shift, X, Y);\r\n  if (Active) then\r\n  begin\r\n    if Button = mbLeft then\r\n    begin\r\n      Control := PreviousControl;\r\n\r\n      \/\/ if (FPrevControl is TADropPanel) then\r\n      \/\/ begin\r\n      \/\/ Control := FRoot.ControlAtPos(Point(X, Y), True, True, True);\r\n      \/\/\r\n      \/\/ if not(Control is TADropPanel) then\r\n      \/\/ begin\r\n      \/\/ Control := FPrevControl;\r\n      \/\/ end;\r\n      \/\/ end;\r\n    end\r\n    else\r\n      Control := Root.ControlAtPos(Point(X, Y), True, True, True);\r\n\r\n    if (Control <> nil) then\r\n    begin\r\n      if (Control.Enabled) and (Control.Visible) then\r\n        Control.MouseUp(Button, Shift, X, Y);\r\n\r\n      \/\/ if (FPrevControl <> Control) and (FPrevControl is TADropPanel) then\r\n      \/\/ TADropPanel(FPrevControl).DragItem := False;\r\n\r\n      PreviousControl := Control;\r\n    end;\r\n  end;\r\nend;\r\n\r\nprocedure TAControlManager.MouseWheel(Sender: TObject; Shift: TShiftState;\r\n  WheelDelta: Integer; MousePos: TPoint; var Handled: Boolean);\r\nvar\r\n  Control: TAControl;\r\nbegin\r\n  if (Assigned(OwnerMouseWheel)) then\r\n    OwnerMouseWheel(Sender, Shift, WheelDelta, MousePos, Handled);\r\n  if (Active) then\r\n  begin\r\n    Control := PreviousControl;\r\n    if (Control <> nil) then\r\n      if (Control.Enabled) and (Control.Visible) then\r\n        Control.MouseWheel(Shift, WheelDelta, MousePos);\r\n  end;\r\nend;\r\n\r\nprocedure TAControlManager.MouseWheelDown(Sender: TObject; Shift: TShiftState;\r\n  MousePos: TPoint; var Handled: Boolean);\r\nvar\r\n  Control: TAControl;\r\nbegin\r\n  if (Assigned(OwnerMouseWheelDown)) then\r\n    OwnerMouseWheelDown(Sender, Shift, MousePos, Handled);\r\n  if (Active) then\r\n  begin\r\n    Control := PreviousControl;\r\n    if (Control <> nil) then\r\n      if (Control.Enabled) and (Control.Visible) then\r\n        Control.MouseWheelDown(Shift, MousePos);\r\n  end;\r\nend;\r\n\r\nprocedure TAControlManager.MouseWheelUp(Sender: TObject; Shift: TShiftState;\r\n  MousePos: TPoint; var Handled: Boolean);\r\nvar\r\n  Control: TAControl;\r\nbegin\r\n  if (Assigned(OwnerMouseWheelUp)) then\r\n    OwnerMouseWheelUp(Sender, Shift, MousePos, Handled);\r\n  if (Active) then\r\n  begin\r\n    Control := PreviousControl;\r\n    if (Control <> nil) then\r\n      if (Control.Enabled) and (Control.Visible) then\r\n        Control.MouseWheelUp(Shift, MousePos);\r\n  end;\r\nend;\r\n\r\nprocedure TAControlManager.RestoreEvents;\r\nbegin\r\n  if Parent is TForm then\r\n  begin\r\n    TForm(Parent).OnMouseDown := Self.OwnerMouseDown;\r\n    TForm(Parent).OnMouseUp := Self.OwnerMouseUp;\r\n    TForm(Parent).OnMouseMove := Self.OwnerMouseMove;\r\n    TForm(Parent).OnMouseEnter := Self.OwnerMouseEnter;\r\n    TForm(Parent).OnMouseLeave := Self.OwnerMouseLeave;\r\n    TForm(Parent).OnMouseWheel := Self.OwnerMouseWheel;\r\n    TForm(Parent).OnMouseWheelDown := Self.OwnerMouseWheelDown;\r\n    TForm(Parent).OnMouseWheelUp := Self.OwnerMouseWheelUp;\r\n\r\n    TForm(Parent).OnKeyDown := Self.OwnerKeyDown;\r\n    TForm(Parent).OnKeyUp := Self.OwnerKeyUp;\r\n    TForm(Parent).OnKeyPress := Self.OwnerKeyPress;\r\n    TForm(Parent).OnShortCut := Self.OwnerShortCut;\r\n\r\n    TForm(Parent).OnClick := Self.OwnerClick;\r\n    TForm(Parent).OnDblClick := Self.OwnerDblClick;\r\n  end;\r\nend;\r\n\r\nprocedure TAControlManager.SetParent(const AParent: TComponent);\r\nbegin\r\n  if FParent <> AParent then\r\n  begin\r\n    if FParent <> nil then\r\n      RestoreEvents;\r\n\r\n    FParent := AParent;\r\n\r\n    if Device <> nil then\r\n      AcquireEvents;\r\n  end;\r\nend;\r\n{$ENDREGION}\r\n\r\ninitialization\r\n\r\nRegisterClasses([TAForm, TAImage, TALabel, TAPanel, TAButton, TAEditBox,\r\n  TACheckBox, TARadioButton, TAProgressBar, TAPaintBox, TATrackBar, TAListBox]);\r\n\r\nfinalization\r\n\r\nUnRegisterClasses([TAForm, TAImage, TALabel, TAPanel, TAButton, TAEditBox,\r\n  TACheckBox, TARadioButton, TAProgressBar, TAPaintBox, TATrackBar, TAListBox]);\r\n\r\nend.\r\n<\/pre>\n<p><\/code>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>Source Files {******************************************************************************} { } { Tulip &#8211; User Interface Library } { } { Copyright(c) 2012 &#8211; 2013 Marcos Gomes. All rights Reserved. } { } { &#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211; } <a class=\"more-link\" href=\"https:\/\/tulip-ui.azurewebsites.net\/?page_id=971\">Continue Reading &rarr;<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"parent":1091,"menu_order":0,"comment_status":"closed","ping_status":"closed","template":"","meta":[],"_links":{"self":[{"href":"https:\/\/tulip-ui.azurewebsites.net\/index.php?rest_route=\/wp\/v2\/pages\/971"}],"collection":[{"href":"https:\/\/tulip-ui.azurewebsites.net\/index.php?rest_route=\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/tulip-ui.azurewebsites.net\/index.php?rest_route=\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/tulip-ui.azurewebsites.net\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/tulip-ui.azurewebsites.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=971"}],"version-history":[{"count":6,"href":"https:\/\/tulip-ui.azurewebsites.net\/index.php?rest_route=\/wp\/v2\/pages\/971\/revisions"}],"predecessor-version":[{"id":1791,"href":"https:\/\/tulip-ui.azurewebsites.net\/index.php?rest_route=\/wp\/v2\/pages\/971\/revisions\/1791"}],"up":[{"embeddable":true,"href":"https:\/\/tulip-ui.azurewebsites.net\/index.php?rest_route=\/wp\/v2\/pages\/1091"}],"wp:attachment":[{"href":"https:\/\/tulip-ui.azurewebsites.net\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=971"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}