use std::fmt::{self , Display, Formatter};
use uiautomation_derive::*;
use windows::Win32::UI::WindowsAndMessaging::SetForegroundWindow;
use super::actions::*;
use super::Result;
use super::UIElement;
use super::errors::ERR_TYPE;
use super::patterns::*;
#[repr(i32)]
#[derive(Debug, Clone, Copy, PartialEq, Eq, EnumConvert)]
pub enum ControlType {
Button = 50000i32,
Calendar = 50001i32,
CheckBox = 50002i32,
ComboBox = 50003i32,
Edit = 50004i32,
Hyperlink = 50005i32,
Image = 50006i32,
ListItem = 50007i32,
List = 50008i32,
Menu = 50009i32,
MenuBar = 50010i32,
MenuItem = 50011i32,
ProgressBar = 50012i32,
RadioButton = 50013i32,
ScrollBar = 50014i32,
Slider = 50015i32,
Spinner = 50016i32,
StatusBar = 50017i32,
Tab = 50018i32,
TabItem = 50019i32,
Text = 50020i32,
ToolBar = 50021i32,
ToolTip = 50022i32,
Tree = 50023i32,
TreeItem = 50024i32,
Custom = 50025i32,
Group = 50026i32,
Thumb = 50027i32,
DataGrid = 50028i32,
DataItem = 50029i32,
Document = 50030i32,
SplitButton = 50031i32,
Window = 50032i32,
Pane = 50033i32,
Header = 50034i32,
HeaderItem = 50035i32,
Table = 50036i32,
TitleBar = 50037i32,
Separator = 50038i32,
SemanticZoom = 50039i32,
AppBar = 50040i32
}
impl From<windows::Win32::UI::Accessibility::UIA_CONTROLTYPE_ID> for ControlType {
fn from(value: windows::Win32::UI::Accessibility::UIA_CONTROLTYPE_ID) -> Self {
value.0.try_into().unwrap()
}
}
impl Into<windows::Win32::UI::Accessibility::UIA_CONTROLTYPE_ID> for ControlType {
fn into(self) -> windows::Win32::UI::Accessibility::UIA_CONTROLTYPE_ID {
windows::Win32::UI::Accessibility::UIA_CONTROLTYPE_ID(self as _)
}
}
pub trait Control {
const TYPE: ControlType;
}
#[derive(Debug, Control, ExpandCollapse, Toggle)]
pub struct AppBarControl {
control: UIElement
}
impl Control for AppBarControl {
const TYPE: ControlType = ControlType::AppBar;
}
#[derive(Debug, Control, Invoke, Value, ExpandCollapse, Toggle)]
pub struct ButtonControl {
control: UIElement
}
impl Control for ButtonControl {
const TYPE: ControlType = ControlType::Button;
}
#[derive(Debug, Control, Grid, Table, Scroll, Selection)]
pub struct CalendarControl {
control: UIElement
}
impl Control for CalendarControl {
const TYPE: ControlType = ControlType::Calendar;
}
#[derive(Debug, Control, Toggle)]
pub struct CheckBoxControl {
control: UIElement
}
impl Control for CheckBoxControl {
const TYPE: ControlType = ControlType::CheckBox;
}
#[derive(Debug, Control, ExpandCollapse, Selection, Value)]
pub struct ComboBoxControl {
control: UIElement
}
impl Control for ComboBoxControl {
const TYPE: ControlType = ControlType::ComboBox;
}
#[derive(Debug, Control, Grid, Scroll, Selection, Table)]
pub struct DataGridControl {
control: UIElement
}
impl Control for DataGridControl {
const TYPE: ControlType = ControlType::DataGrid;
}
#[derive(Debug, Control, SelectionItem, CustomNavigation, ExpandCollapse, GridItem, ScrollItem, TableItem, Toggle, Value)]
pub struct DataItemControl {
control: UIElement
}
impl Control for DataItemControl {
const TYPE: ControlType = ControlType::DataItem;
}
#[derive(Debug, Control, Text, Scroll, Value)]
pub struct DocumentControl {
control: UIElement
}
impl Control for DocumentControl {
const TYPE: ControlType = ControlType::Document;
}
#[derive(Debug, Control, RangeValue, Text, Value)]
pub struct EditControl {
control: UIElement
}
impl Control for EditControl {
const TYPE: ControlType = ControlType::Edit;
}
#[derive(Debug, Control, ExpandCollapse)]
pub struct GroupControl {
control: UIElement
}
impl Control for GroupControl {
const TYPE: ControlType = ControlType::Group;
}
#[derive(Debug, Control, Transform)]
pub struct HeaderControl {
control: UIElement
}
impl Control for HeaderControl {
const TYPE: ControlType = ControlType::Header;
}
#[derive(Debug, Control, CustomNavigation, Invoke, Transform)]
pub struct HeaderItemControl {
control: UIElement
}
impl Control for HeaderItemControl {
const TYPE: ControlType = ControlType::HeaderItem;
}
#[derive(Debug, Control, Invoke, Value)]
pub struct HyperlinkControl {
control: UIElement
}
impl Control for HyperlinkControl {
const TYPE: ControlType = ControlType::Hyperlink;
}
#[derive(Debug, Control, GridItem, TableItem)]
pub struct ImageControl {
control: UIElement
}
impl Control for ImageControl {
const TYPE: ControlType = ControlType::Image;
}
#[derive(Debug, Control, Grid, MultipleView, Scroll, Selection)]
pub struct ListControl {
control: UIElement
}
impl Control for ListControl {
const TYPE: ControlType = ControlType::List;
}
#[derive(Debug, Control, SelectionItem, CustomNavigation, ExpandCollapse, GridItem, Invoke, ScrollItem, Toggle, Value)]
pub struct ListItemControl {
control: UIElement
}
impl Control for ListItemControl {
const TYPE: ControlType = ControlType::ListItem;
}
#[derive(Debug, Control)]
pub struct MenuControl {
control: UIElement
}
impl Control for MenuControl {
const TYPE: ControlType = ControlType::Menu;
}
#[derive(Debug, Control, Dock, ExpandCollapse, Transform)]
pub struct MenuBarControl {
control: UIElement
}
impl Control for MenuBarControl {
const TYPE: ControlType = ControlType::MenuBar;
}
#[derive(Debug, Control, ExpandCollapse, Invoke, SelectionItem, Toggle)]
pub struct MenuItemControl {
control: UIElement
}
impl Control for MenuItemControl {
const TYPE: ControlType = ControlType::MenuItem;
}
#[derive(Debug, Control, Dock, Scroll, Transform, Window)]
pub struct PaneControl {
control: UIElement
}
impl Control for PaneControl {
const TYPE: ControlType = ControlType::Pane;
}
#[derive(Debug, Control, RangeValue, Value)]
pub struct ProgressBarControl {
control: UIElement
}
impl Control for ProgressBarControl {
const TYPE: ControlType = ControlType::ProgressBar;
}
#[derive(Debug, Control, SelectionItem)]
pub struct RadioButtonControl {
control: UIElement
}
impl Control for RadioButtonControl {
const TYPE: ControlType = ControlType::RadioButton;
}
#[derive(Debug, Control, RangeValue)]
pub struct ScrollBarControl {
control: UIElement
}
impl Control for ScrollBarControl {
const TYPE: ControlType = ControlType::ScrollBar;
}
#[derive(Debug, Control, Toggle)]
pub struct SemanticZoomControl {
control: UIElement
}
impl Control for SemanticZoomControl {
const TYPE: ControlType = ControlType::SemanticZoom;
}
#[derive(Debug, Control)]
pub struct SeparatorControl {
control: UIElement
}
impl Control for SeparatorControl {
const TYPE: ControlType = ControlType::Separator;
}
#[derive(Debug, Control, RangeValue, Selection, Value)]
pub struct SliderControl {
control: UIElement
}
impl Control for SliderControl {
const TYPE: ControlType = ControlType::Slider;
}
#[derive(Debug, Control, RangeValue, Selection, Value)]
pub struct SpinnerControl {
control: UIElement
}
impl Control for SpinnerControl {
const TYPE: ControlType = ControlType::Spinner;
}
#[derive(Debug, Control, ExpandCollapse, Invoke)]
pub struct SplitButtonControl {
control: UIElement
}
impl Control for SplitButtonControl {
const TYPE: ControlType = ControlType::SplitButton;
}
#[derive(Debug, Control, Grid)]
pub struct StatusBarControl {
control: UIElement
}
impl Control for StatusBarControl {
const TYPE: ControlType = ControlType::StatusBar;
}
#[derive(Debug, Control, Selection, Scroll)]
pub struct TabControl {
control: UIElement
}
impl Control for TabControl {
const TYPE: ControlType = ControlType::Tab;
}
#[derive(Debug, Control, SelectionItem)]
pub struct TabItemControl {
control: UIElement
}
impl Control for TabItemControl {
const TYPE: ControlType = ControlType::TabItem;
}
#[derive(Debug, Control, Grid, GridItem, Table, TableItem)]
pub struct TableControl {
control: UIElement
}
impl Control for TableControl {
const TYPE: ControlType = ControlType::Table;
}
#[derive(Debug, Control, GridItem, TableItem, Text)]
pub struct TextControl {
control: UIElement
}
impl Control for TextControl {
const TYPE: ControlType = ControlType::Text;
}
#[derive(Debug, Control, Transform)]
pub struct ThumbControl {
control: UIElement
}
impl Control for ThumbControl {
const TYPE: ControlType = ControlType::Thumb;
}
#[derive(Debug, Control)]
pub struct TitleBarControl {
control: UIElement
}
impl Control for TitleBarControl {
const TYPE: ControlType = ControlType::TitleBar;
}
#[derive(Debug, Control, Dock, ExpandCollapse, Transform)]
pub struct ToolBarControl {
control: UIElement
}
impl Control for ToolBarControl {
const TYPE: ControlType = ControlType::ToolBar;
}
#[derive(Debug, Control, Text, Window)]
pub struct ToolTipControl {
control: UIElement
}
impl Control for ToolTipControl {
const TYPE: ControlType = ControlType::ToolTip;
}
#[derive(Debug, Control, Scroll, Selection)]
pub struct TreeControl {
control: UIElement
}
impl Control for TreeControl {
const TYPE: ControlType = ControlType::Tree;
}
#[derive(Debug, Control, ExpandCollapse, Invoke, ScrollItem, SelectionItem, Toggle)]
pub struct TreeItemControl {
control: UIElement
}
impl Control for TreeItemControl {
const TYPE: ControlType = ControlType::TreeItem;
}
#[derive(Debug, Control, Transform, Window, Dock)]
pub struct WindowControl {
control: UIElement
}
impl WindowControl {
pub fn set_foregrand(&self) -> Result<bool> {
let hwnd = self.control.get_native_window_handle()?;
let ret = unsafe {
SetForegroundWindow(hwnd.into())
};
Ok(ret.as_bool())
}
}
impl Control for WindowControl {
const TYPE: ControlType = ControlType::Window;
}