use crate::platform::Platform;
fn platform_as_windows(platform: &dyn Platform) -> Option<&super::WindowsPlatform> {
platform.as_any().downcast_ref::<super::WindowsPlatform>()
}
pub fn try_create_label(
platform: &dyn Platform,
parent: u64,
text: &str,
x: i32,
y: i32,
width: u32,
height: u32,
) -> Option<u64> {
#[cfg(target_os = "windows")]
{
use std::ffi::OsStr;
use std::os::windows::ffi::OsStrExt;
use std::ptr::null_mut;
use winapi::um::commctrl::InitCommonControls;
use winapi::um::winuser::{CreateWindowExW, SS_LEFT, SS_NOPREFIX, WS_CHILD, WS_VISIBLE};
unsafe {
InitCommonControls();
}
let platform_instance = platform_as_windows(platform)?;
let parent_hwnd = platform_instance.get_native_handle(parent)?;
let class: Vec<u16> = OsStr::new("Static").encode_wide().chain(Some(0)).collect();
let text_wide: Vec<u16> = OsStr::new(text).encode_wide().chain(Some(0)).collect();
let hwnd = unsafe {
CreateWindowExW(
0,
class.as_ptr(),
text_wide.as_ptr(),
WS_CHILD | WS_VISIBLE | SS_LEFT | SS_NOPREFIX,
x,
y,
width as i32,
height as i32,
parent_hwnd,
null_mut(),
null_mut(),
null_mut(),
)
};
if hwnd.is_null() {
return None;
}
let widget_id = platform_instance.state.create_widget(
super::types::WindowsHandleKind::Label,
"Label",
x,
y,
width,
height,
);
platform_instance.bind_native_handle(widget_id, hwnd);
Some(widget_id)
}
#[cfg(not(target_os = "windows"))]
{
let _ = (platform, parent, text, x, y, width, height);
None
}
}
pub fn try_create_slider(
platform: &dyn Platform,
parent: u64,
x: i32,
y: i32,
width: u32,
height: u32,
) -> Option<u64> {
let windows = platform_as_windows(platform)?;
<super::WindowsPlatform as super::WindowsPlatformExtSlider>::try_create_slider(
windows, parent, x, y, width, height,
)
}
pub fn try_create_progress_bar(
platform: &dyn Platform,
parent: u64,
x: i32,
y: i32,
width: u32,
height: u32,
) -> Option<u64> {
#[cfg(target_os = "windows")]
{
use std::ffi::OsStr;
use std::os::windows::ffi::OsStrExt;
use std::ptr::null_mut;
use winapi::um::commctrl::{InitCommonControls, PROGRESS_CLASS};
use winapi::um::winuser::{CreateWindowExW, WS_BORDER, WS_CHILD, WS_VISIBLE};
unsafe {
InitCommonControls();
}
let platform_instance = platform_as_windows(platform)?;
let parent_hwnd = platform_instance.get_native_handle(parent)?;
let class: Vec<u16> = OsStr::new(PROGRESS_CLASS).encode_wide().chain(Some(0)).collect();
let hwnd = unsafe {
CreateWindowExW(
0,
class.as_ptr(),
null_mut(),
WS_CHILD | WS_VISIBLE | WS_BORDER,
x,
y,
width as i32,
height as i32,
parent_hwnd,
null_mut(),
null_mut(),
null_mut(),
)
};
if hwnd.is_null() {
return None;
}
let widget_id = platform_instance.state.create_widget(
super::types::WindowsHandleKind::ProgressBar,
"ProgressBar",
x,
y,
width,
height,
);
platform_instance.bind_native_handle(widget_id, hwnd);
Some(widget_id)
}
#[cfg(not(target_os = "windows"))]
{
let _ = (platform, parent, x, y, width, height);
None
}
}
pub fn try_create_group_box(
platform: &dyn Platform,
parent: u64,
title: &str,
x: i32,
y: i32,
width: u32,
height: u32,
) -> Option<u64> {
#[cfg(target_os = "windows")]
{
use std::ptr::null_mut;
use winapi::um::winuser::{CreateWindowExW, BS_GROUPBOX, WS_CHILD, WS_VISIBLE};
let platform_instance = platform_as_windows(platform)?;
let parent_hwnd = platform_instance.get_native_handle(parent)?;
let class = super::WindowsPlatform::to_wide("Button");
let text = super::WindowsPlatform::to_wide(title);
let hwnd = unsafe {
CreateWindowExW(
0,
class.as_ptr(),
text.as_ptr(),
WS_CHILD | WS_VISIBLE | BS_GROUPBOX,
x,
y,
width as i32,
height as i32,
parent_hwnd,
null_mut(),
null_mut(),
null_mut(),
)
};
if hwnd.is_null() {
return None;
}
let widget_id = platform_instance.state.create_widget(
super::types::WindowsHandleKind::GroupBox,
title,
x,
y,
width,
height,
);
platform_instance.bind_native_handle(widget_id, hwnd);
Some(widget_id)
}
#[cfg(not(target_os = "windows"))]
{
let _ = (platform, parent, title, x, y, width, height);
None
}
}
pub fn try_create_frame(
platform: &dyn Platform,
parent: u64,
x: i32,
y: i32,
width: u32,
height: u32,
) -> Option<u64> {
#[cfg(target_os = "windows")]
{
use std::ptr::null_mut;
use winapi::um::winuser::{CreateWindowExW, WS_CHILD, WS_EX_CLIENTEDGE, WS_VISIBLE};
let platform_instance = platform_as_windows(platform)?;
let parent_hwnd = platform_instance.get_native_handle(parent)?;
let class = super::WindowsPlatform::to_wide("Static");
let hwnd = unsafe {
CreateWindowExW(
WS_EX_CLIENTEDGE,
class.as_ptr(),
null_mut(),
WS_CHILD | WS_VISIBLE,
x,
y,
width as i32,
height as i32,
parent_hwnd,
null_mut(),
null_mut(),
null_mut(),
)
};
if hwnd.is_null() {
return None;
}
let widget_id = platform_instance.state.create_widget(
super::types::WindowsHandleKind::Frame,
"Frame",
x,
y,
width,
height,
);
platform_instance.bind_native_handle(widget_id, hwnd);
Some(widget_id)
}
#[cfg(not(target_os = "windows"))]
{
let _ = (platform, parent, x, y, width, height);
None
}
}
pub fn try_create_tab_widget(
platform: &dyn Platform,
parent: u64,
x: i32,
y: i32,
width: u32,
height: u32,
) -> Option<u64> {
#[cfg(target_os = "windows")]
{
use std::ptr::null_mut;
use winapi::um::commctrl::{InitCommonControls, TCITEMW, TCM_INSERTITEMW, WC_TABCONTROL};
use winapi::um::winuser::{CreateWindowExW, SendMessageW, WS_CHILD, WS_VISIBLE};
unsafe {
InitCommonControls();
}
let platform_instance = platform_as_windows(platform)?;
let parent_hwnd = platform_instance.get_native_handle(parent)?;
let class = super::WindowsPlatform::to_wide(WC_TABCONTROL);
let hwnd = unsafe {
CreateWindowExW(
0,
class.as_ptr(),
null_mut(),
WS_CHILD | WS_VISIBLE,
x,
y,
width as i32,
height as i32,
parent_hwnd,
null_mut(),
null_mut(),
null_mut(),
)
};
if hwnd.is_null() {
return None;
}
unsafe {
let mut item: TCITEMW = std::mem::zeroed();
let mut label = super::WindowsPlatform::to_wide("Tab 1");
item.pszText = label.as_mut_ptr();
SendMessageW(hwnd, TCM_INSERTITEMW, 0, &mut item as *mut _ as isize);
}
let widget_id = platform_instance.state.create_widget(
super::types::WindowsHandleKind::TabWidget,
"TabWidget",
x,
y,
width,
height,
);
platform_instance.bind_native_handle(widget_id, hwnd);
Some(widget_id)
}
#[cfg(not(target_os = "windows"))]
{
let _ = (platform, parent, x, y, width, height);
None
}
}
pub fn try_create_splitter(
platform: &dyn Platform,
parent: u64,
x: i32,
y: i32,
width: u32,
height: u32,
) -> Option<u64> {
#[cfg(target_os = "windows")]
{
use std::ptr::null_mut;
use winapi::um::winuser::{CreateWindowExW, WS_CHILD, WS_EX_CLIENTEDGE, WS_VISIBLE};
let platform_instance = platform_as_windows(platform)?;
let parent_hwnd = platform_instance.get_native_handle(parent)?;
let class = super::WindowsPlatform::to_wide("Static");
let hwnd = unsafe {
CreateWindowExW(
WS_EX_CLIENTEDGE,
class.as_ptr(),
null_mut(),
WS_CHILD | WS_VISIBLE,
x,
y,
width as i32,
height as i32,
parent_hwnd,
null_mut(),
null_mut(),
null_mut(),
)
};
if hwnd.is_null() {
return None;
}
let widget_id = platform_instance.state.create_widget(
super::types::WindowsHandleKind::Splitter,
"Splitter",
x,
y,
width,
height,
);
platform_instance.bind_native_handle(widget_id, hwnd);
Some(widget_id)
}
#[cfg(not(target_os = "windows"))]
{
let _ = (platform, parent, x, y, width, height);
None
}
}
pub fn try_create_toggle_button(
platform: &dyn Platform,
parent: u64,
text: &str,
x: i32,
y: i32,
width: u32,
height: u32,
) -> Option<u64> {
#[cfg(target_os = "windows")]
{
use std::ptr::null_mut;
use winapi::um::winuser::{
CreateWindowExW, BS_AUTOCHECKBOX, BS_PUSHLIKE, WS_CHILD, WS_TABSTOP, WS_VISIBLE,
};
let platform_instance = platform_as_windows(platform)?;
let parent_hwnd = platform_instance.get_native_handle(parent)?;
let class = super::WindowsPlatform::to_wide("Button");
let label = super::WindowsPlatform::to_wide(text);
let hwnd = unsafe {
CreateWindowExW(
0,
class.as_ptr(),
label.as_ptr(),
WS_CHILD | WS_VISIBLE | WS_TABSTOP | BS_AUTOCHECKBOX | BS_PUSHLIKE,
x,
y,
width as i32,
height as i32,
parent_hwnd,
null_mut(),
null_mut(),
null_mut(),
)
};
if hwnd.is_null() {
return None;
}
let widget_id = platform_instance.state.create_widget(
super::types::WindowsHandleKind::ToggleButton,
text,
x,
y,
width,
height,
);
platform_instance.bind_native_handle(widget_id, hwnd);
unsafe {
platform_instance.bind_control_command(widget_id, hwnd);
}
Some(widget_id)
}
#[cfg(not(target_os = "windows"))]
{
let _ = (platform, parent, text, x, y, width, height);
None
}
}
pub fn try_create_calendar(
platform: &dyn Platform,
parent: u64,
x: i32,
y: i32,
width: u32,
height: u32,
) -> Option<u64> {
#[cfg(target_os = "windows")]
{
use std::ptr::null_mut;
use winapi::um::commctrl::{InitCommonControls, MONTHCAL_CLASS};
use winapi::um::winuser::{CreateWindowExW, WS_CHILD, WS_VISIBLE};
unsafe {
InitCommonControls();
}
let platform_instance = platform_as_windows(platform)?;
let parent_hwnd = platform_instance.get_native_handle(parent)?;
let class = super::WindowsPlatform::to_wide(MONTHCAL_CLASS);
let hwnd = unsafe {
CreateWindowExW(
0,
class.as_ptr(),
null_mut(),
WS_CHILD | WS_VISIBLE,
x,
y,
width as i32,
height as i32,
parent_hwnd,
null_mut(),
null_mut(),
null_mut(),
)
};
if hwnd.is_null() {
return None;
}
let widget_id = platform_instance.state.create_widget(
super::types::WindowsHandleKind::Calendar,
"Calendar",
x,
y,
width,
height,
);
platform_instance.bind_native_handle(widget_id, hwnd);
Some(widget_id)
}
#[cfg(not(target_os = "windows"))]
{
let _ = (platform, parent, x, y, width, height);
None
}
}
pub fn try_create_scroll_bar(
platform: &dyn Platform,
parent: u64,
x: i32,
y: i32,
width: u32,
height: u32,
) -> Option<u64> {
#[cfg(target_os = "windows")]
{
use std::ptr::null_mut;
use winapi::um::commctrl::{InitCommonControls, TBS_VERT, TRACKBAR_CLASS};
use winapi::um::winuser::{CreateWindowExW, WS_CHILD, WS_VISIBLE};
unsafe {
InitCommonControls();
}
let platform_instance = platform_as_windows(platform)?;
let parent_hwnd = platform_instance.get_native_handle(parent)?;
let class = super::WindowsPlatform::to_wide(TRACKBAR_CLASS);
let hwnd = unsafe {
CreateWindowExW(
0,
class.as_ptr(),
null_mut(),
WS_CHILD | WS_VISIBLE | TBS_VERT,
x,
y,
width as i32,
height as i32,
parent_hwnd,
null_mut(),
null_mut(),
null_mut(),
)
};
if hwnd.is_null() {
return None;
}
let widget_id = platform_instance.state.create_widget(
super::types::WindowsHandleKind::ScrollBar,
"ScrollBar",
x,
y,
width,
height,
);
platform_instance.bind_native_handle(widget_id, hwnd);
Some(widget_id)
}
#[cfg(not(target_os = "windows"))]
{
let _ = (platform, parent, x, y, width, height);
None
}
}
pub fn try_create_double_spin_box(
platform: &dyn Platform,
parent: u64,
x: i32,
y: i32,
width: u32,
height: u32,
) -> Option<u64> {
#[cfg(target_os = "windows")]
{
use std::ptr::null_mut;
use winapi::um::commctrl::{
InitCommonControls, UDS_ALIGNRIGHT, UDS_ARROWKEYS, UDS_SETBUDDYINT, UDS_WRAP,
UPDOWN_CLASS,
};
use winapi::um::winuser::{CreateWindowExW, WS_BORDER, WS_CHILD, WS_VISIBLE};
unsafe {
InitCommonControls();
}
let platform_instance = platform_as_windows(platform)?;
let parent_hwnd = platform_instance.get_native_handle(parent)?;
let class = super::WindowsPlatform::to_wide(UPDOWN_CLASS);
let hwnd = unsafe {
CreateWindowExW(
0,
class.as_ptr(),
null_mut(),
WS_CHILD
| WS_VISIBLE
| WS_BORDER
| UDS_SETBUDDYINT
| UDS_ALIGNRIGHT
| UDS_ARROWKEYS
| UDS_WRAP,
x,
y,
width as i32,
height as i32,
parent_hwnd,
null_mut(),
null_mut(),
null_mut(),
)
};
if hwnd.is_null() {
return None;
}
let widget_id = platform_instance.state.create_widget(
super::types::WindowsHandleKind::DoubleSpinBox,
"DoubleSpinBox",
x,
y,
width,
height,
);
platform_instance.bind_native_handle(widget_id, hwnd);
Some(widget_id)
}
#[cfg(not(target_os = "windows"))]
{
let _ = (platform, parent, x, y, width, height);
None
}
}
pub fn try_create_font_combo_box(
platform: &dyn Platform,
parent: u64,
x: i32,
y: i32,
width: u32,
height: u32,
) -> Option<u64> {
#[cfg(target_os = "windows")]
{
use std::ptr::null_mut;
use winapi::um::commctrl::InitCommonControls;
use winapi::um::winuser::{
CreateWindowExW, CBS_DROPDOWNLIST, CBS_HASSTRINGS, WS_BORDER, WS_CHILD, WS_TABSTOP,
WS_VISIBLE, WS_VSCROLL,
};
unsafe {
InitCommonControls();
}
let platform_instance = platform_as_windows(platform)?;
let parent_hwnd = platform_instance.get_native_handle(parent)?;
let class = super::WindowsPlatform::to_wide("ComboBox");
let hwnd = unsafe {
CreateWindowExW(
0,
class.as_ptr(),
null_mut(),
WS_CHILD
| WS_VISIBLE
| WS_TABSTOP
| WS_BORDER
| WS_VSCROLL
| CBS_DROPDOWNLIST
| CBS_HASSTRINGS,
x,
y,
width as i32,
height as i32,
parent_hwnd,
null_mut(),
null_mut(),
null_mut(),
)
};
if hwnd.is_null() {
return None;
}
let widget_id = platform_instance.state.create_widget(
super::types::WindowsHandleKind::FontComboBox,
"FontComboBox",
x,
y,
width,
height,
);
platform_instance.bind_native_handle(widget_id, hwnd);
unsafe {
platform_instance.bind_control_command(widget_id, hwnd);
}
Some(widget_id)
}
#[cfg(not(target_os = "windows"))]
{
let _ = (platform, parent, x, y, width, height);
None
}
}
pub fn try_create_date_picker(
platform: &dyn Platform,
parent: u64,
x: i32,
y: i32,
width: u32,
height: u32,
) -> Option<u64> {
create_date_time_pick(
platform,
parent,
x,
y,
width,
height,
super::types::WindowsHandleKind::DatePicker,
"DatePicker",
DTS_SHORTDATEFORMAT_VALUE,
)
}
pub fn try_create_time_picker(
platform: &dyn Platform,
parent: u64,
x: i32,
y: i32,
width: u32,
height: u32,
) -> Option<u64> {
create_date_time_pick(
platform,
parent,
x,
y,
width,
height,
super::types::WindowsHandleKind::TimePicker,
"TimePicker",
DTS_TIMEFORMAT_VALUE,
)
}
pub fn try_create_date_time_picker(
platform: &dyn Platform,
parent: u64,
x: i32,
y: i32,
width: u32,
height: u32,
) -> Option<u64> {
create_date_time_pick(
platform,
parent,
x,
y,
width,
height,
super::types::WindowsHandleKind::DateTimePicker,
"DateTimePicker",
DTS_LONGDATEFORMAT_VALUE,
)
}
#[cfg(target_os = "windows")]
const DTS_SHORTDATEFORMAT_VALUE: u32 = 0x0000;
#[cfg(target_os = "windows")]
const DTS_TIMEFORMAT_VALUE: u32 = 0x0009;
#[cfg(target_os = "windows")]
const DTS_LONGDATEFORMAT_VALUE: u32 = 0x0004;
#[cfg(not(target_os = "windows"))]
const DTS_SHORTDATEFORMAT_VALUE: u32 = 0;
#[cfg(not(target_os = "windows"))]
const DTS_TIMEFORMAT_VALUE: u32 = 0;
#[cfg(not(target_os = "windows"))]
const DTS_LONGDATEFORMAT_VALUE: u32 = 0;
#[allow(clippy::too_many_arguments)]
fn create_date_time_pick(
platform: &dyn Platform,
parent: u64,
x: i32,
y: i32,
width: u32,
height: u32,
kind: super::types::WindowsHandleKind,
label: &str,
format_style: u32,
) -> Option<u64> {
#[cfg(target_os = "windows")]
{
use std::ptr::null_mut;
use winapi::um::commctrl::{InitCommonControls, DATETIMEPICK_CLASS};
use winapi::um::winuser::{CreateWindowExW, WS_CHILD, WS_VISIBLE};
unsafe {
InitCommonControls();
}
let platform_instance = platform_as_windows(platform)?;
let parent_hwnd = platform_instance.get_native_handle(parent)?;
let class = super::WindowsPlatform::to_wide(DATETIMEPICK_CLASS);
let hwnd = unsafe {
CreateWindowExW(
0,
class.as_ptr(),
null_mut(),
WS_CHILD | WS_VISIBLE | format_style,
x,
y,
width as i32,
height as i32,
parent_hwnd,
null_mut(),
null_mut(),
null_mut(),
)
};
if hwnd.is_null() {
return None;
}
let widget_id = platform_instance.state.create_widget(kind, label, x, y, width, height);
platform_instance.bind_native_handle(widget_id, hwnd);
Some(widget_id)
}
#[cfg(not(target_os = "windows"))]
{
let _ = (platform, parent, x, y, width, height, kind, label, format_style);
None
}
}
pub fn try_create_activity_indicator(
platform: &dyn Platform,
parent: u64,
x: i32,
y: i32,
width: u32,
height: u32,
) -> Option<u64> {
#[cfg(target_os = "windows")]
{
use std::ptr::null_mut;
use winapi::um::commctrl::{
InitCommonControls, PBM_SETMARQUEE, PBS_MARQUEE, PROGRESS_CLASS,
};
use winapi::um::winuser::{CreateWindowExW, SendMessageW, WS_CHILD, WS_VISIBLE};
unsafe {
InitCommonControls();
}
let platform_instance = platform_as_windows(platform)?;
let parent_hwnd = platform_instance.get_native_handle(parent)?;
let class = super::WindowsPlatform::to_wide(PROGRESS_CLASS);
let hwnd = unsafe {
CreateWindowExW(
0,
class.as_ptr(),
null_mut(),
WS_CHILD | WS_VISIBLE | PBS_MARQUEE,
x,
y,
width as i32,
height as i32,
parent_hwnd,
null_mut(),
null_mut(),
null_mut(),
)
};
if hwnd.is_null() {
return None;
}
unsafe {
SendMessageW(hwnd, PBM_SETMARQUEE, 1, 30);
}
let widget_id = platform_instance.state.create_widget(
super::types::WindowsHandleKind::ActivityIndicator,
"ActivityIndicator",
x,
y,
width,
height,
);
platform_instance.bind_native_handle(widget_id, hwnd);
Some(widget_id)
}
#[cfg(not(target_os = "windows"))]
{
let _ = (platform, parent, x, y, width, height);
None
}
}
pub fn try_create_combo_box(
platform: &dyn Platform,
parent: u64,
x: i32,
y: i32,
width: u32,
height: u32,
) -> Option<u64> {
#[cfg(target_os = "windows")]
{
use std::ptr::null_mut;
use winapi::um::commctrl::InitCommonControls;
use winapi::um::winuser::{
CreateWindowExW, CBS_DROPDOWNLIST, CBS_HASSTRINGS, WS_BORDER, WS_CHILD, WS_TABSTOP,
WS_VISIBLE, WS_VSCROLL,
};
unsafe {
InitCommonControls();
}
let platform_instance = platform_as_windows(platform)?;
let parent_hwnd = platform_instance.get_native_handle(parent)?;
let class = super::WindowsPlatform::to_wide("ComboBox");
let dropdown_height = (height as i32).max(180);
let hwnd = unsafe {
CreateWindowExW(
0,
class.as_ptr(),
null_mut(),
WS_CHILD
| WS_VISIBLE
| WS_TABSTOP
| WS_BORDER
| WS_VSCROLL
| CBS_DROPDOWNLIST
| CBS_HASSTRINGS,
x,
y,
width as i32,
dropdown_height,
parent_hwnd,
null_mut(),
null_mut(),
null_mut(),
)
};
if hwnd.is_null() {
return None;
}
let widget_id = platform_instance.state.create_widget(
super::types::WindowsHandleKind::ComboBox,
"ComboBox",
x,
y,
width,
height,
);
platform_instance.bind_native_handle(widget_id, hwnd);
unsafe {
platform_instance.bind_control_command(widget_id, hwnd);
}
Some(widget_id)
}
#[cfg(not(target_os = "windows"))]
{
let _ = (platform, parent, x, y, width, height);
None
}
}
pub fn try_create_spin_box(
platform: &dyn Platform,
parent: u64,
x: i32,
y: i32,
width: u32,
height: u32,
) -> Option<u64> {
#[cfg(target_os = "windows")]
{
use std::ptr::null_mut;
use winapi::um::commctrl::{
InitCommonControls, UDS_ALIGNRIGHT, UDS_ARROWKEYS, UDS_SETBUDDYINT, UDS_WRAP,
UPDOWN_CLASS,
};
use winapi::um::winuser::{CreateWindowExW, WS_BORDER, WS_CHILD, WS_VISIBLE};
unsafe {
InitCommonControls();
}
let platform_instance = platform_as_windows(platform)?;
let parent_hwnd = platform_instance.get_native_handle(parent)?;
let class = super::WindowsPlatform::to_wide(UPDOWN_CLASS);
let hwnd = unsafe {
CreateWindowExW(
0,
class.as_ptr(),
null_mut(),
WS_CHILD
| WS_VISIBLE
| WS_BORDER
| UDS_SETBUDDYINT
| UDS_ALIGNRIGHT
| UDS_ARROWKEYS
| UDS_WRAP,
x,
y,
width as i32,
height as i32,
parent_hwnd,
null_mut(),
null_mut(),
null_mut(),
)
};
if hwnd.is_null() {
return None;
}
let widget_id = platform_instance.state.create_widget(
super::types::WindowsHandleKind::SpinBox,
"SpinBox",
x,
y,
width,
height,
);
platform_instance.bind_native_handle(widget_id, hwnd);
Some(widget_id)
}
#[cfg(not(target_os = "windows"))]
{
let _ = (platform, parent, x, y, width, height);
None
}
}
pub fn try_create_list_view(
platform: &dyn Platform,
parent: u64,
x: i32,
y: i32,
width: u32,
height: u32,
) -> Option<u64> {
#[cfg(target_os = "windows")]
{
use std::ptr::null_mut;
use winapi::um::commctrl::{
InitCommonControls, LVCF_TEXT, LVCF_WIDTH, LVCOLUMNW, LVM_INSERTCOLUMNW,
LVM_SETEXTENDEDLISTVIEWSTYLE, LVS_EX_FULLROWSELECT, LVS_REPORT, LVS_SHOWSELALWAYS,
LVS_SINGLESEL, WC_LISTVIEW,
};
use winapi::um::winuser::{
CreateWindowExW, SendMessageW, WS_BORDER, WS_CHILD, WS_TABSTOP, WS_VISIBLE,
};
unsafe {
InitCommonControls();
}
let platform_instance = platform_as_windows(platform)?;
let parent_hwnd = platform_instance.get_native_handle(parent)?;
let class = super::WindowsPlatform::to_wide(WC_LISTVIEW);
let hwnd = unsafe {
CreateWindowExW(
0,
class.as_ptr(),
null_mut(),
WS_CHILD
| WS_VISIBLE
| WS_BORDER
| WS_TABSTOP
| LVS_REPORT
| LVS_SINGLESEL
| LVS_SHOWSELALWAYS,
x,
y,
width as i32,
height as i32,
parent_hwnd,
null_mut(),
null_mut(),
null_mut(),
)
};
if hwnd.is_null() {
return None;
}
unsafe {
let mut column: LVCOLUMNW = std::mem::zeroed();
column.mask = LVCF_TEXT | LVCF_WIDTH;
column.cx = width as i32;
let header = super::WindowsPlatform::to_wide("Item");
column.pszText = header.as_ptr() as *mut _;
SendMessageW(hwnd, LVM_INSERTCOLUMNW, 0, &mut column as *mut _ as isize);
SendMessageW(
hwnd,
LVM_SETEXTENDEDLISTVIEWSTYLE,
LVS_EX_FULLROWSELECT as usize,
LVS_EX_FULLROWSELECT as isize,
);
}
let widget_id = platform_instance.state.create_widget(
super::types::WindowsHandleKind::ListView,
"ListView",
x,
y,
width,
height,
);
platform_instance.bind_native_handle(widget_id, hwnd);
unsafe {
platform_instance.bind_control_command(widget_id, hwnd);
}
Some(widget_id)
}
#[cfg(not(target_os = "windows"))]
{
let _ = (platform, parent, x, y, width, height);
None
}
}
pub fn try_create_scroll_area(
platform: &dyn Platform,
parent: u64,
x: i32,
y: i32,
width: u32,
height: u32,
) -> Option<u64> {
#[cfg(target_os = "windows")]
{
use std::ptr::null_mut;
use winapi::um::winuser::{
CreateWindowExW, SetScrollRange, WS_BORDER, WS_CHILD, WS_HSCROLL, WS_VISIBLE,
WS_VSCROLL,
};
let platform_instance = platform_as_windows(platform)?;
let parent_hwnd = platform_instance.get_native_handle(parent)?;
let class = super::WindowsPlatform::to_wide("Static");
let hwnd = unsafe {
CreateWindowExW(
0,
class.as_ptr(),
null_mut(),
WS_CHILD | WS_VISIBLE | WS_BORDER | WS_HSCROLL | WS_VSCROLL,
x,
y,
width as i32,
height as i32,
parent_hwnd,
null_mut(),
null_mut(),
null_mut(),
)
};
if hwnd.is_null() {
return None;
}
unsafe {
const SB_VERT: i32 = 1;
const SB_HORZ: i32 = 0;
SetScrollRange(hwnd, SB_VERT, 0, height as i32, 1);
SetScrollRange(hwnd, SB_HORZ, 0, width as i32, 1);
}
let widget_id = platform_instance.state.create_widget(
super::types::WindowsHandleKind::ScrollArea,
"ScrollArea",
x,
y,
width,
height,
);
platform_instance.bind_native_handle(widget_id, hwnd);
Some(widget_id)
}
#[cfg(not(target_os = "windows"))]
{
let _ = (platform, parent, x, y, width, height);
None
}
}