{***************************************************************************}
{ }
{ DelphiUIAutomation }
{ }
{ Copyright 2015-16 JHC Systems Limited }
{ }
{***************************************************************************}
{ }
{ Licensed under the Apache License, Version 2.0 (the "License"); }
{ you may not use this file except in compliance with the License. }
{ You may obtain a copy of the License at }
{ }
{ http://www.apache.org/licenses/LICENSE-2.0 }
{ }
{ Unless required by applicable law or agreed to in writing, software }
{ distributed under the License is distributed on an "AS IS" BASIS, }
{ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. }
{ See the License for the specific language governing permissions and }
{ limitations under the License. }
{ }
{***************************************************************************}
unit DelphiUIAutomation.MenuItem;
interface
uses
DelphiUIAutomation.Base,
generics.collections,
UIAutomationClient_TLB;
type
IAutomationMenuItem = interface (IAutomationBase)
['{CCAE523B-A6D2-4C9C-BC96-C1E1BDCF5705}']
///
/// Clicks the menuitem
///
function Click: HResult;
end;
///
/// Represents a menu item
///
///
/// Models Menu items (root or leaf).
/// SubMenus are themselves are Menu(s).
///
TAutomationMenuItem = class (TAutomationBase, IAutomationMenuItem)
strict private
FItems : TObjectList;
FInvokePattern : IUIAutomationInvokePattern;
FExpandCollapsePattern : IUIAutomationExpandCollapsePattern;
function getItems: TObjectList;
public
///
/// Constructor for menu items.
///
constructor Create(element : IUIAutomationElement); override;
///
/// Destructor.
///
destructor Destroy; override;
///
/// Call the expand property
///
function Expand : HRESULT;
///
/// Call the collapse property
///
function Collapse : HRESULT;
///
/// Clicks the menuitem
///
function Click: HResult;
///
/// Gets the list of items associated with this menu
///
property Items : TObjectList read getItems;
end;
implementation
uses
Winapi.Windows,
Winapi.ActiveX,
DelphiUIAutomation.PropertyIDs,
DelphiUIAutomation.Exception,
DelphiUIAutomation.ControlTypeIDs,
DelphiUIAutomation.PatternIDs,
DelphiUIAutomation.Automation;
constructor TAutomationMenuItem.Create(element: IUIAutomationElement);
var
name : widestring;
begin
inherited create(element);
FElement.Get_CurrentName(name);
FExpandCollapsePattern := GetExpandCollapsePattern;
FInvokePattern := GetInvokePattern;
end;
destructor TAutomationMenuItem.Destroy;
begin
if FItems <> nil then
FItems.free;
inherited;
end;
function TAutomationMenuItem.Expand: HRESULT;
begin
result := FExpandCollapsePattern.Expand;
end;
function TAutomationMenuItem.Collapse: HRESULT;
begin
result := FExpandCollapsePattern.Collapse;
end;
function TAutomationMenuItem.getItems: TObjectList;
begin
result := self.FItems;
end;
function TAutomationMenuItem.Click : HResult;
begin
result := -1;
if (Assigned (FInvokePattern)) then
begin
result := FInvokePattern.Invoke;
end;
end;
end.