use crate::color::Colour;
use crate::event::{Event, EventType, WxEvtHandler};
use crate::font::Font;
use crate::geometry::{Point, Rect, Size};
use crate::id::Id;
use crate::window::{WindowHandle, WxWidget};
use std::ffi::{CStr, CString};
use wxdragon_sys as ffi;
#[derive(Debug, Copy, Clone, PartialEq, Eq)]
#[repr(i32)]
pub enum CellSpan {
Inside = -1,
None = 0,
Main = 1,
}
#[derive(Debug, Copy, Clone, PartialEq, Eq)]
#[repr(i32)]
pub enum TabBehaviour {
Stop = 0,
Wrap = 1,
Leave = 2,
}
#[derive(Debug, Copy, Clone, PartialEq, Eq)]
pub struct GridCellCoords {
pub row: i32,
pub col: i32,
}
#[derive(Debug, Copy, Clone, PartialEq, Eq)]
pub struct GridBlockCoords {
pub top_row: i32,
pub left_col: i32,
pub bottom_row: i32,
pub right_col: i32,
}
#[derive(Debug, Copy, Clone, PartialEq, Eq, Default)]
#[repr(i32)]
pub enum GridSelectionMode {
#[default]
Cells = 0,
Rows = 1,
Columns = 2,
RowsOrColumns = 3,
None = 4,
}
widget_style_enum!(
name: GridStyle,
doc: "Style flags for Grid widget.",
variants: {
Default: 0, "Default grid style."
},
default_variant: Default
);
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum GridEvent {
CellLeftClick,
CellRightClick,
CellLeftDClick,
CellRightDClick,
LabelLeftClick,
LabelRightClick,
LabelLeftDClick,
LabelRightDClick,
CellChanged,
SelectCell,
EditorShown,
EditorHidden,
EditorCreated,
CellBeginDrag,
RowSize,
ColSize,
RangeSelected,
}
#[derive(Debug)]
pub struct GridEventData {
event: Event,
}
impl GridEventData {
pub fn new(event: Event) -> Self {
Self { event }
}
pub fn get_row(&self) -> i32 {
if self.event.is_null() {
return -1;
}
unsafe { ffi::wxd_GridEvent_GetRow(self.event.0) }
}
pub fn get_col(&self) -> i32 {
if self.event.is_null() {
return -1;
}
unsafe { ffi::wxd_GridEvent_GetCol(self.event.0) }
}
pub fn get_position(&self) -> Point {
if self.event.is_null() {
return Point::new(0, 0);
}
let pos = unsafe { ffi::wxd_GridEvent_GetPosition(self.event.0) };
Point::new(pos.x, pos.y)
}
pub fn selecting(&self) -> bool {
if self.event.is_null() {
return false;
}
unsafe { ffi::wxd_GridEvent_Selecting(self.event.0) }
}
pub fn control_down(&self) -> bool {
if self.event.is_null() {
return false;
}
unsafe { ffi::wxd_GridEvent_ControlDown(self.event.0) }
}
pub fn shift_down(&self) -> bool {
if self.event.is_null() {
return false;
}
unsafe { ffi::wxd_GridEvent_ShiftDown(self.event.0) }
}
pub fn alt_down(&self) -> bool {
if self.event.is_null() {
return false;
}
unsafe { ffi::wxd_GridEvent_AltDown(self.event.0) }
}
pub fn meta_down(&self) -> bool {
if self.event.is_null() {
return false;
}
unsafe { ffi::wxd_GridEvent_MetaDown(self.event.0) }
}
}
#[derive(Clone, Copy)]
pub struct Grid {
handle: WindowHandle,
}
impl Grid {
pub fn builder(parent: &dyn WxWidget) -> GridBuilder<'_> {
GridBuilder::new(parent)
}
fn new_impl(parent_ptr: *mut ffi::wxd_Window_t, id: Id, pos: Point, size: Size, style: i64) -> Self {
assert!(!parent_ptr.is_null(), "Grid requires a parent");
let ptr = unsafe { ffi::wxd_Grid_Create(parent_ptr, id, pos.into(), size.into(), style) };
if ptr.is_null() {
panic!("Failed to create Grid: FFI returned null pointer.");
}
Grid {
handle: WindowHandle::new(ptr as *mut ffi::wxd_Window_t),
}
}
#[inline]
fn grid_ptr(&self) -> *mut ffi::wxd_Grid_t {
self.handle
.get_ptr()
.map(|p| p as *mut ffi::wxd_Grid_t)
.unwrap_or(std::ptr::null_mut())
}
pub fn window_handle(&self) -> WindowHandle {
self.handle
}
pub fn create_grid(&self, num_rows: i32, num_cols: i32, selection_mode: GridSelectionMode) -> bool {
let ptr = self.grid_ptr();
if ptr.is_null() {
return false;
}
unsafe { ffi::wxd_Grid_CreateGrid(ptr, num_rows, num_cols, selection_mode as i32) }
}
pub fn get_number_rows(&self) -> i32 {
let ptr = self.grid_ptr();
if ptr.is_null() {
return 0;
}
unsafe { ffi::wxd_Grid_GetNumberRows(ptr) }
}
pub fn get_number_cols(&self) -> i32 {
let ptr = self.grid_ptr();
if ptr.is_null() {
return 0;
}
unsafe { ffi::wxd_Grid_GetNumberCols(ptr) }
}
pub fn insert_rows(&self, pos: i32, num_rows: i32, update_labels: bool) -> bool {
let ptr = self.grid_ptr();
if ptr.is_null() {
return false;
}
unsafe { ffi::wxd_Grid_InsertRows(ptr, pos, num_rows, update_labels) }
}
pub fn append_rows(&self, num_rows: i32, update_labels: bool) -> bool {
let ptr = self.grid_ptr();
if ptr.is_null() {
return false;
}
unsafe { ffi::wxd_Grid_AppendRows(ptr, num_rows, update_labels) }
}
pub fn delete_rows(&self, pos: i32, num_rows: i32, update_labels: bool) -> bool {
let ptr = self.grid_ptr();
if ptr.is_null() {
return false;
}
unsafe { ffi::wxd_Grid_DeleteRows(ptr, pos, num_rows, update_labels) }
}
pub fn insert_cols(&self, pos: i32, num_cols: i32, update_labels: bool) -> bool {
let ptr = self.grid_ptr();
if ptr.is_null() {
return false;
}
unsafe { ffi::wxd_Grid_InsertCols(ptr, pos, num_cols, update_labels) }
}
pub fn append_cols(&self, num_cols: i32, update_labels: bool) -> bool {
let ptr = self.grid_ptr();
if ptr.is_null() {
return false;
}
unsafe { ffi::wxd_Grid_AppendCols(ptr, num_cols, update_labels) }
}
pub fn delete_cols(&self, pos: i32, num_cols: i32, update_labels: bool) -> bool {
let ptr = self.grid_ptr();
if ptr.is_null() {
return false;
}
unsafe { ffi::wxd_Grid_DeleteCols(ptr, pos, num_cols, update_labels) }
}
pub fn get_cell_value(&self, row: i32, col: i32) -> String {
let ptr = self.grid_ptr();
if ptr.is_null() {
return String::new();
}
unsafe {
let len = ffi::wxd_Grid_GetCellValue(ptr, row, col, std::ptr::null_mut(), 0);
if len <= 0 {
return String::new();
}
let mut buffer = vec![0u8; len as usize + 1];
ffi::wxd_Grid_GetCellValue(ptr, row, col, buffer.as_mut_ptr() as *mut i8, buffer.len() as i32);
CStr::from_ptr(buffer.as_ptr() as *const i8).to_string_lossy().into_owned()
}
}
pub fn set_cell_value(&self, row: i32, col: i32, value: &str) {
let ptr = self.grid_ptr();
if ptr.is_null() {
return;
}
let c_value = CString::new(value).unwrap_or_default();
unsafe { ffi::wxd_Grid_SetCellValue(ptr, row, col, c_value.as_ptr()) }
}
pub fn get_row_label_value(&self, row: i32) -> String {
let ptr = self.grid_ptr();
if ptr.is_null() {
return String::new();
}
unsafe {
let len = ffi::wxd_Grid_GetRowLabelValue(ptr, row, std::ptr::null_mut(), 0);
if len <= 0 {
return String::new();
}
let mut buffer = vec![0u8; len as usize + 1];
ffi::wxd_Grid_GetRowLabelValue(ptr, row, buffer.as_mut_ptr() as *mut i8, buffer.len() as i32);
CStr::from_ptr(buffer.as_ptr() as *const i8).to_string_lossy().into_owned()
}
}
pub fn set_row_label_value(&self, row: i32, value: &str) {
let ptr = self.grid_ptr();
if ptr.is_null() {
return;
}
let c_value = CString::new(value).unwrap_or_default();
unsafe { ffi::wxd_Grid_SetRowLabelValue(ptr, row, c_value.as_ptr()) }
}
pub fn get_col_label_value(&self, col: i32) -> String {
let ptr = self.grid_ptr();
if ptr.is_null() {
return String::new();
}
unsafe {
let len = ffi::wxd_Grid_GetColLabelValue(ptr, col, std::ptr::null_mut(), 0);
if len <= 0 {
return String::new();
}
let mut buffer = vec![0u8; len as usize + 1];
ffi::wxd_Grid_GetColLabelValue(ptr, col, buffer.as_mut_ptr() as *mut i8, buffer.len() as i32);
CStr::from_ptr(buffer.as_ptr() as *const i8).to_string_lossy().into_owned()
}
}
pub fn set_col_label_value(&self, col: i32, value: &str) {
let ptr = self.grid_ptr();
if ptr.is_null() {
return;
}
let c_value = CString::new(value).unwrap_or_default();
unsafe { ffi::wxd_Grid_SetColLabelValue(ptr, col, c_value.as_ptr()) }
}
pub fn get_row_label_size(&self) -> i32 {
let ptr = self.grid_ptr();
if ptr.is_null() {
return 0;
}
unsafe { ffi::wxd_Grid_GetRowLabelSize(ptr) }
}
pub fn set_row_label_size(&self, width: i32) {
let ptr = self.grid_ptr();
if ptr.is_null() {
return;
}
unsafe { ffi::wxd_Grid_SetRowLabelSize(ptr, width) }
}
pub fn get_col_label_size(&self) -> i32 {
let ptr = self.grid_ptr();
if ptr.is_null() {
return 0;
}
unsafe { ffi::wxd_Grid_GetColLabelSize(ptr) }
}
pub fn set_col_label_size(&self, height: i32) {
let ptr = self.grid_ptr();
if ptr.is_null() {
return;
}
unsafe { ffi::wxd_Grid_SetColLabelSize(ptr, height) }
}
pub fn hide_row_labels(&self) {
let ptr = self.grid_ptr();
if ptr.is_null() {
return;
}
unsafe { ffi::wxd_Grid_HideRowLabels(ptr) }
}
pub fn hide_col_labels(&self) {
let ptr = self.grid_ptr();
if ptr.is_null() {
return;
}
unsafe { ffi::wxd_Grid_HideColLabels(ptr) }
}
pub fn get_default_row_size(&self) -> i32 {
let ptr = self.grid_ptr();
if ptr.is_null() {
return 0;
}
unsafe { ffi::wxd_Grid_GetDefaultRowSize(ptr) }
}
pub fn get_row_size(&self, row: i32) -> i32 {
let ptr = self.grid_ptr();
if ptr.is_null() {
return 0;
}
unsafe { ffi::wxd_Grid_GetRowSize(ptr, row) }
}
pub fn set_default_row_size(&self, height: i32, resize_existing: bool) {
let ptr = self.grid_ptr();
if ptr.is_null() {
return;
}
unsafe { ffi::wxd_Grid_SetDefaultRowSize(ptr, height, resize_existing) }
}
pub fn set_row_size(&self, row: i32, height: i32) {
let ptr = self.grid_ptr();
if ptr.is_null() {
return;
}
unsafe { ffi::wxd_Grid_SetRowSize(ptr, row, height) }
}
pub fn get_default_col_size(&self) -> i32 {
let ptr = self.grid_ptr();
if ptr.is_null() {
return 0;
}
unsafe { ffi::wxd_Grid_GetDefaultColSize(ptr) }
}
pub fn get_col_size(&self, col: i32) -> i32 {
let ptr = self.grid_ptr();
if ptr.is_null() {
return 0;
}
unsafe { ffi::wxd_Grid_GetColSize(ptr, col) }
}
pub fn set_default_col_size(&self, width: i32, resize_existing: bool) {
let ptr = self.grid_ptr();
if ptr.is_null() {
return;
}
unsafe { ffi::wxd_Grid_SetDefaultColSize(ptr, width, resize_existing) }
}
pub fn set_col_size(&self, col: i32, width: i32) {
let ptr = self.grid_ptr();
if ptr.is_null() {
return;
}
unsafe { ffi::wxd_Grid_SetColSize(ptr, col, width) }
}
pub fn auto_size_column(&self, col: i32, set_as_min: bool) {
let ptr = self.grid_ptr();
if ptr.is_null() {
return;
}
unsafe { ffi::wxd_Grid_AutoSizeColumn(ptr, col, set_as_min) }
}
pub fn auto_size_row(&self, row: i32, set_as_min: bool) {
let ptr = self.grid_ptr();
if ptr.is_null() {
return;
}
unsafe { ffi::wxd_Grid_AutoSizeRow(ptr, row, set_as_min) }
}
pub fn auto_size_columns(&self, set_as_min: bool) {
let ptr = self.grid_ptr();
if ptr.is_null() {
return;
}
unsafe { ffi::wxd_Grid_AutoSizeColumns(ptr, set_as_min) }
}
pub fn auto_size_rows(&self, set_as_min: bool) {
let ptr = self.grid_ptr();
if ptr.is_null() {
return;
}
unsafe { ffi::wxd_Grid_AutoSizeRows(ptr, set_as_min) }
}
pub fn auto_size(&self) {
let ptr = self.grid_ptr();
if ptr.is_null() {
return;
}
unsafe { ffi::wxd_Grid_AutoSize(ptr) }
}
pub fn auto_size_row_label_size(&self, row: i32) {
let ptr = self.grid_ptr();
if ptr.is_null() {
return;
}
unsafe { ffi::wxd_Grid_AutoSizeRowLabelSize(ptr, row) }
}
pub fn auto_size_col_label_size(&self, col: i32) {
let ptr = self.grid_ptr();
if ptr.is_null() {
return;
}
unsafe { ffi::wxd_Grid_AutoSizeColLabelSize(ptr, col) }
}
pub fn get_cell_background_colour(&self, row: i32, col: i32) -> Colour {
let ptr = self.grid_ptr();
if ptr.is_null() {
return Colour::new(255, 255, 255, 255);
}
unsafe {
let c = ffi::wxd_Grid_GetCellBackgroundColour(ptr, row, col);
Colour::new(c.r, c.g, c.b, c.a)
}
}
pub fn set_cell_background_colour(&self, row: i32, col: i32, colour: &Colour) {
let ptr = self.grid_ptr();
if ptr.is_null() {
return;
}
unsafe { ffi::wxd_Grid_SetCellBackgroundColour(ptr, row, col, (*colour).into()) }
}
pub fn get_cell_text_colour(&self, row: i32, col: i32) -> Colour {
let ptr = self.grid_ptr();
if ptr.is_null() {
return Colour::new(0, 0, 0, 255);
}
unsafe {
let c = ffi::wxd_Grid_GetCellTextColour(ptr, row, col);
Colour::new(c.r, c.g, c.b, c.a)
}
}
pub fn set_cell_text_colour(&self, row: i32, col: i32, colour: &Colour) {
let ptr = self.grid_ptr();
if ptr.is_null() {
return;
}
unsafe { ffi::wxd_Grid_SetCellTextColour(ptr, row, col, (*colour).into()) }
}
pub fn get_cell_alignment(&self, row: i32, col: i32) -> (i32, i32) {
let ptr = self.grid_ptr();
if ptr.is_null() {
return (0, 0);
}
let mut horiz = 0;
let mut vert = 0;
unsafe { ffi::wxd_Grid_GetCellAlignment(ptr, row, col, &mut horiz, &mut vert) }
(horiz, vert)
}
pub fn set_cell_alignment(&self, row: i32, col: i32, horiz: i32, vert: i32) {
let ptr = self.grid_ptr();
if ptr.is_null() {
return;
}
unsafe { ffi::wxd_Grid_SetCellAlignment(ptr, row, col, horiz, vert) }
}
pub fn get_default_cell_background_colour(&self) -> Colour {
let ptr = self.grid_ptr();
if ptr.is_null() {
return Colour::new(255, 255, 255, 255);
}
unsafe {
let c = ffi::wxd_Grid_GetDefaultCellBackgroundColour(ptr);
Colour::new(c.r, c.g, c.b, c.a)
}
}
pub fn set_default_cell_background_colour(&self, colour: &Colour) {
let ptr = self.grid_ptr();
if ptr.is_null() {
return;
}
unsafe { ffi::wxd_Grid_SetDefaultCellBackgroundColour(ptr, (*colour).into()) }
}
pub fn get_default_cell_text_colour(&self) -> Colour {
let ptr = self.grid_ptr();
if ptr.is_null() {
return Colour::new(0, 0, 0, 255);
}
unsafe {
let c = ffi::wxd_Grid_GetDefaultCellTextColour(ptr);
Colour::new(c.r, c.g, c.b, c.a)
}
}
pub fn set_default_cell_text_colour(&self, colour: &Colour) {
let ptr = self.grid_ptr();
if ptr.is_null() {
return;
}
unsafe { ffi::wxd_Grid_SetDefaultCellTextColour(ptr, (*colour).into()) }
}
pub fn get_default_cell_alignment(&self) -> (i32, i32) {
let ptr = self.grid_ptr();
if ptr.is_null() {
return (0, 0);
}
let mut horiz = 0;
let mut vert = 0;
unsafe { ffi::wxd_Grid_GetDefaultCellAlignment(ptr, &mut horiz, &mut vert) }
(horiz, vert)
}
pub fn set_default_cell_alignment(&self, horiz: i32, vert: i32) {
let ptr = self.grid_ptr();
if ptr.is_null() {
return;
}
unsafe { ffi::wxd_Grid_SetDefaultCellAlignment(ptr, horiz, vert) }
}
pub fn is_read_only(&self, row: i32, col: i32) -> bool {
let ptr = self.grid_ptr();
if ptr.is_null() {
return false;
}
unsafe { ffi::wxd_Grid_IsReadOnly(ptr, row, col) }
}
pub fn set_read_only(&self, row: i32, col: i32, is_read_only: bool) {
let ptr = self.grid_ptr();
if ptr.is_null() {
return;
}
unsafe { ffi::wxd_Grid_SetReadOnly(ptr, row, col, is_read_only) }
}
pub fn select_row(&self, row: i32, add_to_selected: bool) {
let ptr = self.grid_ptr();
if ptr.is_null() {
return;
}
unsafe { ffi::wxd_Grid_SelectRow(ptr, row, add_to_selected) }
}
pub fn select_col(&self, col: i32, add_to_selected: bool) {
let ptr = self.grid_ptr();
if ptr.is_null() {
return;
}
unsafe { ffi::wxd_Grid_SelectCol(ptr, col, add_to_selected) }
}
pub fn select_block(&self, top_row: i32, left_col: i32, bottom_row: i32, right_col: i32, add_to_selected: bool) {
let ptr = self.grid_ptr();
if ptr.is_null() {
return;
}
unsafe { ffi::wxd_Grid_SelectBlock(ptr, top_row, left_col, bottom_row, right_col, add_to_selected) }
}
pub fn select_all(&self) {
let ptr = self.grid_ptr();
if ptr.is_null() {
return;
}
unsafe { ffi::wxd_Grid_SelectAll(ptr) }
}
pub fn is_selection(&self) -> bool {
let ptr = self.grid_ptr();
if ptr.is_null() {
return false;
}
unsafe { ffi::wxd_Grid_IsSelection(ptr) }
}
pub fn deselect_row(&self, row: i32) {
let ptr = self.grid_ptr();
if ptr.is_null() {
return;
}
unsafe { ffi::wxd_Grid_DeselectRow(ptr, row) }
}
pub fn deselect_col(&self, col: i32) {
let ptr = self.grid_ptr();
if ptr.is_null() {
return;
}
unsafe { ffi::wxd_Grid_DeselectCol(ptr, col) }
}
pub fn deselect_cell(&self, row: i32, col: i32) {
let ptr = self.grid_ptr();
if ptr.is_null() {
return;
}
unsafe { ffi::wxd_Grid_DeselectCell(ptr, row, col) }
}
pub fn clear_selection(&self) {
let ptr = self.grid_ptr();
if ptr.is_null() {
return;
}
unsafe { ffi::wxd_Grid_ClearSelection(ptr) }
}
pub fn is_in_selection(&self, row: i32, col: i32) -> bool {
let ptr = self.grid_ptr();
if ptr.is_null() {
return false;
}
unsafe { ffi::wxd_Grid_IsInSelection(ptr, row, col) }
}
pub fn get_selected_rows(&self) -> Vec<i32> {
let ptr = self.grid_ptr();
if ptr.is_null() {
return Vec::new();
}
unsafe {
let count = ffi::wxd_Grid_GetSelectedRows(ptr, std::ptr::null_mut(), 0);
if count <= 0 {
return Vec::new();
}
let mut buffer = vec![0i32; count as usize];
ffi::wxd_Grid_GetSelectedRows(ptr, buffer.as_mut_ptr(), buffer.len() as i32);
buffer
}
}
pub fn get_selected_cols(&self) -> Vec<i32> {
let ptr = self.grid_ptr();
if ptr.is_null() {
return Vec::new();
}
unsafe {
let count = ffi::wxd_Grid_GetSelectedCols(ptr, std::ptr::null_mut(), 0);
if count <= 0 {
return Vec::new();
}
let mut buffer = vec![0i32; count as usize];
ffi::wxd_Grid_GetSelectedCols(ptr, buffer.as_mut_ptr(), buffer.len() as i32);
buffer
}
}
pub fn get_selected_cells(&self) -> Vec<GridCellCoords> {
let ptr = self.grid_ptr();
if ptr.is_null() {
return Vec::new();
}
unsafe {
let count = ffi::wxd_Grid_GetSelectedCells(ptr, std::ptr::null_mut(), 0);
if count <= 0 {
return Vec::new();
}
let mut buffer = vec![ffi::wxd_GridCellCoords { row: 0, col: 0 }; count as usize];
ffi::wxd_Grid_GetSelectedCells(ptr, buffer.as_mut_ptr(), buffer.len() as i32);
buffer.iter().map(|c| GridCellCoords { row: c.row, col: c.col }).collect()
}
}
pub fn get_selected_blocks(&self) -> Vec<GridBlockCoords> {
let ptr = self.grid_ptr();
if ptr.is_null() {
return Vec::new();
}
unsafe {
let count = ffi::wxd_Grid_GetSelectedBlocks(ptr, std::ptr::null_mut(), 0);
if count <= 0 {
return Vec::new();
}
let mut buffer = vec![
ffi::wxd_GridBlockCoords {
top_row: 0,
left_col: 0,
bottom_row: 0,
right_col: 0,
};
count as usize
];
ffi::wxd_Grid_GetSelectedBlocks(ptr, buffer.as_mut_ptr(), buffer.len() as i32);
buffer
.iter()
.map(|b| GridBlockCoords {
top_row: b.top_row,
left_col: b.left_col,
bottom_row: b.bottom_row,
right_col: b.right_col,
})
.collect()
}
}
pub fn get_selected_row_blocks(&self) -> Vec<GridBlockCoords> {
let ptr = self.grid_ptr();
if ptr.is_null() {
return Vec::new();
}
unsafe {
let count = ffi::wxd_Grid_GetSelectedRowBlocks(ptr, std::ptr::null_mut(), 0);
if count <= 0 {
return Vec::new();
}
let mut buffer = vec![
ffi::wxd_GridBlockCoords {
top_row: 0,
left_col: 0,
bottom_row: 0,
right_col: 0,
};
count as usize
];
ffi::wxd_Grid_GetSelectedRowBlocks(ptr, buffer.as_mut_ptr(), buffer.len() as i32);
buffer
.iter()
.map(|b| GridBlockCoords {
top_row: b.top_row,
left_col: b.left_col,
bottom_row: b.bottom_row,
right_col: b.right_col,
})
.collect()
}
}
pub fn get_selected_col_blocks(&self) -> Vec<GridBlockCoords> {
let ptr = self.grid_ptr();
if ptr.is_null() {
return Vec::new();
}
unsafe {
let count = ffi::wxd_Grid_GetSelectedColBlocks(ptr, std::ptr::null_mut(), 0);
if count <= 0 {
return Vec::new();
}
let mut buffer = vec![
ffi::wxd_GridBlockCoords {
top_row: 0,
left_col: 0,
bottom_row: 0,
right_col: 0,
};
count as usize
];
ffi::wxd_Grid_GetSelectedColBlocks(ptr, buffer.as_mut_ptr(), buffer.len() as i32);
buffer
.iter()
.map(|b| GridBlockCoords {
top_row: b.top_row,
left_col: b.left_col,
bottom_row: b.bottom_row,
right_col: b.right_col,
})
.collect()
}
}
pub fn get_grid_cursor_row(&self) -> i32 {
let ptr = self.grid_ptr();
if ptr.is_null() {
return -1;
}
unsafe { ffi::wxd_Grid_GetGridCursorRow(ptr) }
}
pub fn get_grid_cursor_col(&self) -> i32 {
let ptr = self.grid_ptr();
if ptr.is_null() {
return -1;
}
unsafe { ffi::wxd_Grid_GetGridCursorCol(ptr) }
}
pub fn set_grid_cursor(&self, row: i32, col: i32) {
let ptr = self.grid_ptr();
if ptr.is_null() {
return;
}
unsafe { ffi::wxd_Grid_SetGridCursor(ptr, row, col) }
}
pub fn go_to_cell(&self, row: i32, col: i32) {
let ptr = self.grid_ptr();
if ptr.is_null() {
return;
}
unsafe { ffi::wxd_Grid_GoToCell(ptr, row, col) }
}
pub fn is_visible(&self, row: i32, col: i32, whole_cell_visible: bool) -> bool {
let ptr = self.grid_ptr();
if ptr.is_null() {
return false;
}
unsafe { ffi::wxd_Grid_IsVisible(ptr, row, col, whole_cell_visible) }
}
pub fn make_cell_visible(&self, row: i32, col: i32) {
let ptr = self.grid_ptr();
if ptr.is_null() {
return;
}
unsafe { ffi::wxd_Grid_MakeCellVisible(ptr, row, col) }
}
pub fn is_editable(&self) -> bool {
let ptr = self.grid_ptr();
if ptr.is_null() {
return false;
}
unsafe { ffi::wxd_Grid_IsEditable(ptr) }
}
pub fn enable_editing(&self, edit: bool) {
let ptr = self.grid_ptr();
if ptr.is_null() {
return;
}
unsafe { ffi::wxd_Grid_EnableEditing(ptr, edit) }
}
pub fn enable_cell_edit_control(&self, enable: bool) {
let ptr = self.grid_ptr();
if ptr.is_null() {
return;
}
unsafe { ffi::wxd_Grid_EnableCellEditControl(ptr, enable) }
}
pub fn disable_cell_edit_control(&self) {
let ptr = self.grid_ptr();
if ptr.is_null() {
return;
}
unsafe { ffi::wxd_Grid_DisableCellEditControl(ptr) }
}
pub fn is_cell_edit_control_enabled(&self) -> bool {
let ptr = self.grid_ptr();
if ptr.is_null() {
return false;
}
unsafe { ffi::wxd_Grid_IsCellEditControlEnabled(ptr) }
}
pub fn enable_grid_lines(&self, enable: bool) {
let ptr = self.grid_ptr();
if ptr.is_null() {
return;
}
unsafe { ffi::wxd_Grid_EnableGridLines(ptr, enable) }
}
pub fn grid_lines_enabled(&self) -> bool {
let ptr = self.grid_ptr();
if ptr.is_null() {
return false;
}
unsafe { ffi::wxd_Grid_GridLinesEnabled(ptr) }
}
pub fn get_grid_line_colour(&self) -> Colour {
let ptr = self.grid_ptr();
if ptr.is_null() {
return Colour::new(0, 0, 0, 255);
}
unsafe {
let c = ffi::wxd_Grid_GetGridLineColour(ptr);
Colour::new(c.r, c.g, c.b, c.a)
}
}
pub fn set_grid_line_colour(&self, colour: &Colour) {
let ptr = self.grid_ptr();
if ptr.is_null() {
return;
}
unsafe { ffi::wxd_Grid_SetGridLineColour(ptr, (*colour).into()) }
}
pub fn get_label_background_colour(&self) -> Colour {
let ptr = self.grid_ptr();
if ptr.is_null() {
return Colour::new(192, 192, 192, 255);
}
unsafe {
let c = ffi::wxd_Grid_GetLabelBackgroundColour(ptr);
Colour::new(c.r, c.g, c.b, c.a)
}
}
pub fn set_label_background_colour(&self, colour: &Colour) {
let ptr = self.grid_ptr();
if ptr.is_null() {
return;
}
unsafe { ffi::wxd_Grid_SetLabelBackgroundColour(ptr, (*colour).into()) }
}
pub fn get_label_text_colour(&self) -> Colour {
let ptr = self.grid_ptr();
if ptr.is_null() {
return Colour::new(0, 0, 0, 255);
}
unsafe {
let c = ffi::wxd_Grid_GetLabelTextColour(ptr);
Colour::new(c.r, c.g, c.b, c.a)
}
}
pub fn set_label_text_colour(&self, colour: &Colour) {
let ptr = self.grid_ptr();
if ptr.is_null() {
return;
}
unsafe { ffi::wxd_Grid_SetLabelTextColour(ptr, (*colour).into()) }
}
pub fn begin_batch(&self) {
let ptr = self.grid_ptr();
if ptr.is_null() {
return;
}
unsafe { ffi::wxd_Grid_BeginBatch(ptr) }
}
pub fn end_batch(&self) {
let ptr = self.grid_ptr();
if ptr.is_null() {
return;
}
unsafe { ffi::wxd_Grid_EndBatch(ptr) }
}
pub fn get_batch_count(&self) -> i32 {
let ptr = self.grid_ptr();
if ptr.is_null() {
return 0;
}
unsafe { ffi::wxd_Grid_GetBatchCount(ptr) }
}
pub fn force_refresh(&self) {
let ptr = self.grid_ptr();
if ptr.is_null() {
return;
}
unsafe { ffi::wxd_Grid_ForceRefresh(ptr) }
}
pub fn clear_grid(&self) {
let ptr = self.grid_ptr();
if ptr.is_null() {
return;
}
unsafe { ffi::wxd_Grid_ClearGrid(ptr) }
}
pub fn enable_drag_row_size(&self, enable: bool) {
let ptr = self.grid_ptr();
if ptr.is_null() {
return;
}
unsafe { ffi::wxd_Grid_EnableDragRowSize(ptr, enable) }
}
pub fn enable_drag_col_size(&self, enable: bool) {
let ptr = self.grid_ptr();
if ptr.is_null() {
return;
}
unsafe { ffi::wxd_Grid_EnableDragColSize(ptr, enable) }
}
pub fn enable_drag_cell(&self, enable: bool) {
let ptr = self.grid_ptr();
if ptr.is_null() {
return;
}
unsafe { ffi::wxd_Grid_EnableDragCell(ptr, enable) }
}
pub fn set_selection_mode(&self, mode: GridSelectionMode) {
let ptr = self.grid_ptr();
if ptr.is_null() {
return;
}
unsafe { ffi::wxd_Grid_SetSelectionMode(ptr, mode as i32) }
}
pub fn get_selection_mode(&self) -> GridSelectionMode {
let ptr = self.grid_ptr();
if ptr.is_null() {
return GridSelectionMode::Cells;
}
let mode = unsafe { ffi::wxd_Grid_GetSelectionMode(ptr) };
match mode {
1 => GridSelectionMode::Rows,
2 => GridSelectionMode::Columns,
3 => GridSelectionMode::RowsOrColumns,
4 => GridSelectionMode::None,
_ => GridSelectionMode::Cells,
}
}
pub fn get_selection_background(&self) -> Colour {
let ptr = self.grid_ptr();
if ptr.is_null() {
return Colour::new(0, 0, 128, 255);
}
unsafe {
let c = ffi::wxd_Grid_GetSelectionBackground(ptr);
Colour::new(c.r, c.g, c.b, c.a)
}
}
pub fn set_selection_background(&self, colour: &Colour) {
let ptr = self.grid_ptr();
if ptr.is_null() {
return;
}
unsafe { ffi::wxd_Grid_SetSelectionBackground(ptr, (*colour).into()) }
}
pub fn get_selection_foreground(&self) -> Colour {
let ptr = self.grid_ptr();
if ptr.is_null() {
return Colour::new(255, 255, 255, 255);
}
unsafe {
let c = ffi::wxd_Grid_GetSelectionForeground(ptr);
Colour::new(c.r, c.g, c.b, c.a)
}
}
pub fn set_selection_foreground(&self, colour: &Colour) {
let ptr = self.grid_ptr();
if ptr.is_null() {
return;
}
unsafe { ffi::wxd_Grid_SetSelectionForeground(ptr, (*colour).into()) }
}
pub fn hide_row(&self, row: i32) {
let ptr = self.grid_ptr();
if ptr.is_null() {
return;
}
unsafe { ffi::wxd_Grid_HideRow(ptr, row) }
}
pub fn show_row(&self, row: i32) {
let ptr = self.grid_ptr();
if ptr.is_null() {
return;
}
unsafe { ffi::wxd_Grid_ShowRow(ptr, row) }
}
pub fn is_row_shown(&self, row: i32) -> bool {
let ptr = self.grid_ptr();
if ptr.is_null() {
return false;
}
unsafe { ffi::wxd_Grid_IsRowShown(ptr, row) }
}
pub fn hide_col(&self, col: i32) {
let ptr = self.grid_ptr();
if ptr.is_null() {
return;
}
unsafe { ffi::wxd_Grid_HideCol(ptr, col) }
}
pub fn show_col(&self, col: i32) {
let ptr = self.grid_ptr();
if ptr.is_null() {
return;
}
unsafe { ffi::wxd_Grid_ShowCol(ptr, col) }
}
pub fn is_col_shown(&self, col: i32) -> bool {
let ptr = self.grid_ptr();
if ptr.is_null() {
return false;
}
unsafe { ffi::wxd_Grid_IsColShown(ptr, col) }
}
pub fn get_cell_font(&self, row: i32, col: i32) -> Option<Font> {
let ptr = self.grid_ptr();
if ptr.is_null() {
return None;
}
let font_ptr = unsafe { ffi::wxd_Grid_GetCellFont(ptr, row, col) };
if font_ptr.is_null() {
return None;
}
Some(unsafe { Font::from_ptr(font_ptr, true) })
}
pub fn set_cell_font(&self, row: i32, col: i32, font: &Font) {
let ptr = self.grid_ptr();
if ptr.is_null() {
return;
}
unsafe { ffi::wxd_Grid_SetCellFont(ptr, row, col, font.as_ptr() as *const _) }
}
pub fn get_default_cell_font(&self) -> Option<Font> {
let ptr = self.grid_ptr();
if ptr.is_null() {
return None;
}
let font_ptr = unsafe { ffi::wxd_Grid_GetDefaultCellFont(ptr) };
if font_ptr.is_null() {
return None;
}
Some(unsafe { Font::from_ptr(font_ptr, true) })
}
pub fn set_default_cell_font(&self, font: &Font) {
let ptr = self.grid_ptr();
if ptr.is_null() {
return;
}
unsafe { ffi::wxd_Grid_SetDefaultCellFont(ptr, font.as_ptr() as *const _) }
}
pub fn get_label_font(&self) -> Option<Font> {
let ptr = self.grid_ptr();
if ptr.is_null() {
return None;
}
let font_ptr = unsafe { ffi::wxd_Grid_GetLabelFont(ptr) };
if font_ptr.is_null() {
return None;
}
Some(unsafe { Font::from_ptr(font_ptr, true) })
}
pub fn set_label_font(&self, font: &Font) {
let ptr = self.grid_ptr();
if ptr.is_null() {
return;
}
unsafe { ffi::wxd_Grid_SetLabelFont(ptr, font.as_ptr() as *const _) }
}
pub fn get_col_label_alignment(&self) -> (i32, i32) {
let ptr = self.grid_ptr();
if ptr.is_null() {
return (0, 0);
}
let (mut h, mut v) = (0i32, 0i32);
unsafe { ffi::wxd_Grid_GetColLabelAlignment(ptr, &mut h, &mut v) }
(h, v)
}
pub fn set_col_label_alignment(&self, horiz: i32, vert: i32) {
let ptr = self.grid_ptr();
if ptr.is_null() {
return;
}
unsafe { ffi::wxd_Grid_SetColLabelAlignment(ptr, horiz, vert) }
}
pub fn get_row_label_alignment(&self) -> (i32, i32) {
let ptr = self.grid_ptr();
if ptr.is_null() {
return (0, 0);
}
let (mut h, mut v) = (0i32, 0i32);
unsafe { ffi::wxd_Grid_GetRowLabelAlignment(ptr, &mut h, &mut v) }
(h, v)
}
pub fn set_row_label_alignment(&self, horiz: i32, vert: i32) {
let ptr = self.grid_ptr();
if ptr.is_null() {
return;
}
unsafe { ffi::wxd_Grid_SetRowLabelAlignment(ptr, horiz, vert) }
}
pub fn get_col_label_text_orientation(&self) -> i32 {
let ptr = self.grid_ptr();
if ptr.is_null() {
return 0;
}
unsafe { ffi::wxd_Grid_GetColLabelTextOrientation(ptr) }
}
pub fn set_col_label_text_orientation(&self, orientation: i32) {
let ptr = self.grid_ptr();
if ptr.is_null() {
return;
}
unsafe { ffi::wxd_Grid_SetColLabelTextOrientation(ptr, orientation) }
}
pub fn get_corner_label_value(&self) -> String {
let ptr = self.grid_ptr();
if ptr.is_null() {
return String::new();
}
let needed = unsafe { ffi::wxd_Grid_GetCornerLabelValue(ptr, std::ptr::null_mut(), 0) };
if needed <= 0 {
return String::new();
}
let mut buf = vec![0u8; (needed + 1) as usize];
unsafe { ffi::wxd_Grid_GetCornerLabelValue(ptr, buf.as_mut_ptr() as *mut i8, buf.len() as i32) };
let c_str = unsafe { CStr::from_ptr(buf.as_ptr() as *const i8) };
c_str.to_string_lossy().into_owned()
}
pub fn set_corner_label_value(&self, value: &str) {
let ptr = self.grid_ptr();
if ptr.is_null() {
return;
}
let c_str = CString::new(value).unwrap_or_default();
unsafe { ffi::wxd_Grid_SetCornerLabelValue(ptr, c_str.as_ptr()) }
}
pub fn get_corner_label_alignment(&self) -> (i32, i32) {
let ptr = self.grid_ptr();
if ptr.is_null() {
return (0, 0);
}
let (mut h, mut v) = (0i32, 0i32);
unsafe { ffi::wxd_Grid_GetCornerLabelAlignment(ptr, &mut h, &mut v) }
(h, v)
}
pub fn set_corner_label_alignment(&self, horiz: i32, vert: i32) {
let ptr = self.grid_ptr();
if ptr.is_null() {
return;
}
unsafe { ffi::wxd_Grid_SetCornerLabelAlignment(ptr, horiz, vert) }
}
pub fn get_corner_label_text_orientation(&self) -> i32 {
let ptr = self.grid_ptr();
if ptr.is_null() {
return 0;
}
unsafe { ffi::wxd_Grid_GetCornerLabelTextOrientation(ptr) }
}
pub fn set_corner_label_text_orientation(&self, orientation: i32) {
let ptr = self.grid_ptr();
if ptr.is_null() {
return;
}
unsafe { ffi::wxd_Grid_SetCornerLabelTextOrientation(ptr, orientation) }
}
pub fn set_use_native_col_labels(&self, native_labels: bool) {
let ptr = self.grid_ptr();
if ptr.is_null() {
return;
}
unsafe { ffi::wxd_Grid_SetUseNativeColLabels(ptr, native_labels) }
}
pub fn use_native_col_header(&self, native_header: bool) -> bool {
let ptr = self.grid_ptr();
if ptr.is_null() {
return false;
}
unsafe { ffi::wxd_Grid_UseNativeColHeader(ptr, native_header) }
}
pub fn is_using_native_header(&self) -> bool {
let ptr = self.grid_ptr();
if ptr.is_null() {
return false;
}
unsafe { ffi::wxd_Grid_IsUsingNativeHeader(ptr) }
}
pub fn set_cell_size(&self, row: i32, col: i32, num_rows: i32, num_cols: i32) {
let ptr = self.grid_ptr();
if ptr.is_null() {
return;
}
unsafe { ffi::wxd_Grid_SetCellSize(ptr, row, col, num_rows, num_cols) }
}
pub fn get_cell_size(&self, row: i32, col: i32) -> (CellSpan, i32, i32) {
let ptr = self.grid_ptr();
if ptr.is_null() {
return (CellSpan::None, 1, 1);
}
let (mut nr, mut nc) = (0i32, 0i32);
let span = unsafe { ffi::wxd_Grid_GetCellSize(ptr, row, col, &mut nr, &mut nc) };
let cell_span = match span {
-1 => CellSpan::Inside,
1 => CellSpan::Main,
_ => CellSpan::None,
};
(cell_span, nr, nc)
}
pub fn get_cell_overflow(&self, row: i32, col: i32) -> bool {
let ptr = self.grid_ptr();
if ptr.is_null() {
return true;
}
unsafe { ffi::wxd_Grid_GetCellOverflow(ptr, row, col) }
}
pub fn set_cell_overflow(&self, row: i32, col: i32, allow: bool) {
let ptr = self.grid_ptr();
if ptr.is_null() {
return;
}
unsafe { ffi::wxd_Grid_SetCellOverflow(ptr, row, col, allow) }
}
pub fn get_default_cell_overflow(&self) -> bool {
let ptr = self.grid_ptr();
if ptr.is_null() {
return true;
}
unsafe { ffi::wxd_Grid_GetDefaultCellOverflow(ptr) }
}
pub fn set_default_cell_overflow(&self, allow: bool) {
let ptr = self.grid_ptr();
if ptr.is_null() {
return;
}
unsafe { ffi::wxd_Grid_SetDefaultCellOverflow(ptr, allow) }
}
pub fn set_col_format_bool(&self, col: i32) {
let ptr = self.grid_ptr();
if ptr.is_null() {
return;
}
unsafe { ffi::wxd_Grid_SetColFormatBool(ptr, col) }
}
pub fn set_col_format_number(&self, col: i32) {
let ptr = self.grid_ptr();
if ptr.is_null() {
return;
}
unsafe { ffi::wxd_Grid_SetColFormatNumber(ptr, col) }
}
pub fn set_col_format_float(&self, col: i32, width: i32, precision: i32) {
let ptr = self.grid_ptr();
if ptr.is_null() {
return;
}
unsafe { ffi::wxd_Grid_SetColFormatFloat(ptr, col, width, precision) }
}
pub fn set_col_format_date(&self, col: i32, format: &str) {
let ptr = self.grid_ptr();
if ptr.is_null() {
return;
}
let c_str = CString::new(format).unwrap_or_default();
unsafe { ffi::wxd_Grid_SetColFormatDate(ptr, col, c_str.as_ptr()) }
}
pub fn set_col_format_custom(&self, col: i32, type_name: &str) {
let ptr = self.grid_ptr();
if ptr.is_null() {
return;
}
let c_str = CString::new(type_name).unwrap_or_default();
unsafe { ffi::wxd_Grid_SetColFormatCustom(ptr, col, c_str.as_ptr()) }
}
pub fn get_sorting_column(&self) -> i32 {
let ptr = self.grid_ptr();
if ptr.is_null() {
return -1;
}
unsafe { ffi::wxd_Grid_GetSortingColumn(ptr) }
}
pub fn is_sorting_by(&self, col: i32) -> bool {
let ptr = self.grid_ptr();
if ptr.is_null() {
return false;
}
unsafe { ffi::wxd_Grid_IsSortingBy(ptr, col) }
}
pub fn is_sort_order_ascending(&self) -> bool {
let ptr = self.grid_ptr();
if ptr.is_null() {
return true;
}
unsafe { ffi::wxd_Grid_IsSortOrderAscending(ptr) }
}
pub fn set_sorting_column(&self, col: i32, ascending: bool) {
let ptr = self.grid_ptr();
if ptr.is_null() {
return;
}
unsafe { ffi::wxd_Grid_SetSortingColumn(ptr, col, ascending) }
}
pub fn unset_sorting_column(&self) {
let ptr = self.grid_ptr();
if ptr.is_null() {
return;
}
unsafe { ffi::wxd_Grid_UnsetSortingColumn(ptr) }
}
pub fn set_tab_behaviour(&self, behaviour: TabBehaviour) {
let ptr = self.grid_ptr();
if ptr.is_null() {
return;
}
unsafe { ffi::wxd_Grid_SetTabBehaviour(ptr, behaviour as i32) }
}
pub fn freeze_to(&self, row: i32, col: i32) -> bool {
let ptr = self.grid_ptr();
if ptr.is_null() {
return false;
}
unsafe { ffi::wxd_Grid_FreezeTo(ptr, row, col) }
}
pub fn get_number_frozen_rows(&self) -> i32 {
let ptr = self.grid_ptr();
if ptr.is_null() {
return 0;
}
unsafe { ffi::wxd_Grid_GetNumberFrozenRows(ptr) }
}
pub fn get_number_frozen_cols(&self) -> i32 {
let ptr = self.grid_ptr();
if ptr.is_null() {
return 0;
}
unsafe { ffi::wxd_Grid_GetNumberFrozenCols(ptr) }
}
pub fn get_col_minimal_acceptable_width(&self) -> i32 {
let ptr = self.grid_ptr();
if ptr.is_null() {
return 0;
}
unsafe { ffi::wxd_Grid_GetColMinimalAcceptableWidth(ptr) }
}
pub fn set_col_minimal_acceptable_width(&self, width: i32) {
let ptr = self.grid_ptr();
if ptr.is_null() {
return;
}
unsafe { ffi::wxd_Grid_SetColMinimalAcceptableWidth(ptr, width) }
}
pub fn set_col_minimal_width(&self, col: i32, width: i32) {
let ptr = self.grid_ptr();
if ptr.is_null() {
return;
}
unsafe { ffi::wxd_Grid_SetColMinimalWidth(ptr, col, width) }
}
pub fn get_row_minimal_acceptable_height(&self) -> i32 {
let ptr = self.grid_ptr();
if ptr.is_null() {
return 0;
}
unsafe { ffi::wxd_Grid_GetRowMinimalAcceptableHeight(ptr) }
}
pub fn set_row_minimal_acceptable_height(&self, height: i32) {
let ptr = self.grid_ptr();
if ptr.is_null() {
return;
}
unsafe { ffi::wxd_Grid_SetRowMinimalAcceptableHeight(ptr, height) }
}
pub fn set_row_minimal_height(&self, row: i32, height: i32) {
let ptr = self.grid_ptr();
if ptr.is_null() {
return;
}
unsafe { ffi::wxd_Grid_SetRowMinimalHeight(ptr, row, height) }
}
pub fn get_default_row_label_size(&self) -> i32 {
let ptr = self.grid_ptr();
if ptr.is_null() {
return 0;
}
unsafe { ffi::wxd_Grid_GetDefaultRowLabelSize(ptr) }
}
pub fn get_default_col_label_size(&self) -> i32 {
let ptr = self.grid_ptr();
if ptr.is_null() {
return 0;
}
unsafe { ffi::wxd_Grid_GetDefaultColLabelSize(ptr) }
}
pub fn can_enable_cell_control(&self) -> bool {
let ptr = self.grid_ptr();
if ptr.is_null() {
return false;
}
unsafe { ffi::wxd_Grid_CanEnableCellControl(ptr) }
}
pub fn is_cell_edit_control_shown(&self) -> bool {
let ptr = self.grid_ptr();
if ptr.is_null() {
return false;
}
unsafe { ffi::wxd_Grid_IsCellEditControlShown(ptr) }
}
pub fn is_current_cell_read_only(&self) -> bool {
let ptr = self.grid_ptr();
if ptr.is_null() {
return false;
}
unsafe { ffi::wxd_Grid_IsCurrentCellReadOnly(ptr) }
}
pub fn hide_cell_edit_control(&self) {
let ptr = self.grid_ptr();
if ptr.is_null() {
return;
}
unsafe { ffi::wxd_Grid_HideCellEditControl(ptr) }
}
pub fn show_cell_edit_control(&self) {
let ptr = self.grid_ptr();
if ptr.is_null() {
return;
}
unsafe { ffi::wxd_Grid_ShowCellEditControl(ptr) }
}
pub fn save_edit_control_value(&self) {
let ptr = self.grid_ptr();
if ptr.is_null() {
return;
}
unsafe { ffi::wxd_Grid_SaveEditControlValue(ptr) }
}
pub fn get_cell_highlight_colour(&self) -> Colour {
let ptr = self.grid_ptr();
if ptr.is_null() {
return Colour::new(0, 0, 0, 255);
}
let c = unsafe { ffi::wxd_Grid_GetCellHighlightColour(ptr) };
Colour::new(c.r, c.g, c.b, c.a)
}
pub fn set_cell_highlight_colour(&self, colour: Colour) {
let ptr = self.grid_ptr();
if ptr.is_null() {
return;
}
unsafe { ffi::wxd_Grid_SetCellHighlightColour(ptr, colour.into()) }
}
pub fn get_cell_highlight_pen_width(&self) -> i32 {
let ptr = self.grid_ptr();
if ptr.is_null() {
return 0;
}
unsafe { ffi::wxd_Grid_GetCellHighlightPenWidth(ptr) }
}
pub fn set_cell_highlight_pen_width(&self, width: i32) {
let ptr = self.grid_ptr();
if ptr.is_null() {
return;
}
unsafe { ffi::wxd_Grid_SetCellHighlightPenWidth(ptr, width) }
}
pub fn get_cell_highlight_ro_pen_width(&self) -> i32 {
let ptr = self.grid_ptr();
if ptr.is_null() {
return 0;
}
unsafe { ffi::wxd_Grid_GetCellHighlightROPenWidth(ptr) }
}
pub fn set_cell_highlight_ro_pen_width(&self, width: i32) {
let ptr = self.grid_ptr();
if ptr.is_null() {
return;
}
unsafe { ffi::wxd_Grid_SetCellHighlightROPenWidth(ptr, width) }
}
pub fn set_grid_frozen_border_colour(&self, colour: Colour) {
let ptr = self.grid_ptr();
if ptr.is_null() {
return;
}
unsafe { ffi::wxd_Grid_SetGridFrozenBorderColour(ptr, colour.into()) }
}
pub fn set_grid_frozen_border_pen_width(&self, width: i32) {
let ptr = self.grid_ptr();
if ptr.is_null() {
return;
}
unsafe { ffi::wxd_Grid_SetGridFrozenBorderPenWidth(ptr, width) }
}
pub fn move_cursor_up(&self, expand_selection: bool) -> bool {
let ptr = self.grid_ptr();
if ptr.is_null() {
return false;
}
unsafe { ffi::wxd_Grid_MoveCursorUp(ptr, expand_selection) }
}
pub fn move_cursor_down(&self, expand_selection: bool) -> bool {
let ptr = self.grid_ptr();
if ptr.is_null() {
return false;
}
unsafe { ffi::wxd_Grid_MoveCursorDown(ptr, expand_selection) }
}
pub fn move_cursor_left(&self, expand_selection: bool) -> bool {
let ptr = self.grid_ptr();
if ptr.is_null() {
return false;
}
unsafe { ffi::wxd_Grid_MoveCursorLeft(ptr, expand_selection) }
}
pub fn move_cursor_right(&self, expand_selection: bool) -> bool {
let ptr = self.grid_ptr();
if ptr.is_null() {
return false;
}
unsafe { ffi::wxd_Grid_MoveCursorRight(ptr, expand_selection) }
}
pub fn move_cursor_up_block(&self, expand_selection: bool) -> bool {
let ptr = self.grid_ptr();
if ptr.is_null() {
return false;
}
unsafe { ffi::wxd_Grid_MoveCursorUpBlock(ptr, expand_selection) }
}
pub fn move_cursor_down_block(&self, expand_selection: bool) -> bool {
let ptr = self.grid_ptr();
if ptr.is_null() {
return false;
}
unsafe { ffi::wxd_Grid_MoveCursorDownBlock(ptr, expand_selection) }
}
pub fn move_cursor_left_block(&self, expand_selection: bool) -> bool {
let ptr = self.grid_ptr();
if ptr.is_null() {
return false;
}
unsafe { ffi::wxd_Grid_MoveCursorLeftBlock(ptr, expand_selection) }
}
pub fn move_cursor_right_block(&self, expand_selection: bool) -> bool {
let ptr = self.grid_ptr();
if ptr.is_null() {
return false;
}
unsafe { ffi::wxd_Grid_MoveCursorRightBlock(ptr, expand_selection) }
}
pub fn move_page_up(&self) -> bool {
let ptr = self.grid_ptr();
if ptr.is_null() {
return false;
}
unsafe { ffi::wxd_Grid_MovePageUp(ptr) }
}
pub fn move_page_down(&self) -> bool {
let ptr = self.grid_ptr();
if ptr.is_null() {
return false;
}
unsafe { ffi::wxd_Grid_MovePageDown(ptr) }
}
pub fn get_grid_cursor_coords(&self) -> GridCellCoords {
let ptr = self.grid_ptr();
if ptr.is_null() {
return GridCellCoords { row: -1, col: -1 };
}
let c = unsafe { ffi::wxd_Grid_GetGridCursorCoords(ptr) };
GridCellCoords { row: c.row, col: c.col }
}
pub fn get_scroll_line_x(&self) -> i32 {
let ptr = self.grid_ptr();
if ptr.is_null() {
return 15;
}
unsafe { ffi::wxd_Grid_GetScrollLineX(ptr) }
}
pub fn get_scroll_line_y(&self) -> i32 {
let ptr = self.grid_ptr();
if ptr.is_null() {
return 15;
}
unsafe { ffi::wxd_Grid_GetScrollLineY(ptr) }
}
pub fn set_scroll_line_x(&self, x: i32) {
let ptr = self.grid_ptr();
if ptr.is_null() {
return;
}
unsafe { ffi::wxd_Grid_SetScrollLineX(ptr, x) }
}
pub fn set_scroll_line_y(&self, y: i32) {
let ptr = self.grid_ptr();
if ptr.is_null() {
return;
}
unsafe { ffi::wxd_Grid_SetScrollLineY(ptr, y) }
}
pub fn get_first_fully_visible_row(&self) -> i32 {
let ptr = self.grid_ptr();
if ptr.is_null() {
return -1;
}
unsafe { ffi::wxd_Grid_GetFirstFullyVisibleRow(ptr) }
}
pub fn get_first_fully_visible_column(&self) -> i32 {
let ptr = self.grid_ptr();
if ptr.is_null() {
return -1;
}
unsafe { ffi::wxd_Grid_GetFirstFullyVisibleColumn(ptr) }
}
pub fn x_to_col(&self, x: i32, clip_to_min_max: bool) -> i32 {
let ptr = self.grid_ptr();
if ptr.is_null() {
return -1;
}
unsafe { ffi::wxd_Grid_XToCol(ptr, x, clip_to_min_max) }
}
pub fn y_to_row(&self, y: i32, clip_to_min_max: bool) -> i32 {
let ptr = self.grid_ptr();
if ptr.is_null() {
return -1;
}
unsafe { ffi::wxd_Grid_YToRow(ptr, y, clip_to_min_max) }
}
pub fn x_to_edge_of_col(&self, x: i32) -> i32 {
let ptr = self.grid_ptr();
if ptr.is_null() {
return -1;
}
unsafe { ffi::wxd_Grid_XToEdgeOfCol(ptr, x) }
}
pub fn y_to_edge_of_row(&self, y: i32) -> i32 {
let ptr = self.grid_ptr();
if ptr.is_null() {
return -1;
}
unsafe { ffi::wxd_Grid_YToEdgeOfRow(ptr, y) }
}
pub fn xy_to_cell(&self, x: i32, y: i32) -> GridCellCoords {
let ptr = self.grid_ptr();
if ptr.is_null() {
return GridCellCoords { row: -1, col: -1 };
}
let c = unsafe { ffi::wxd_Grid_XYToCell(ptr, x, y) };
GridCellCoords { row: c.row, col: c.col }
}
pub fn cell_to_rect(&self, row: i32, col: i32) -> Rect {
let ptr = self.grid_ptr();
if ptr.is_null() {
return Rect::new(0, 0, 0, 0);
}
let r = unsafe { ffi::wxd_Grid_CellToRect(ptr, row, col) };
Rect::new(r.x, r.y, r.width, r.height)
}
pub fn block_to_device_rect(&self, top_row: i32, left_col: i32, bottom_row: i32, right_col: i32) -> Rect {
let ptr = self.grid_ptr();
if ptr.is_null() {
return Rect::new(0, 0, 0, 0);
}
let r = unsafe { ffi::wxd_Grid_BlockToDeviceRect(ptr, top_row, left_col, bottom_row, right_col) };
Rect::new(r.x, r.y, r.width, r.height)
}
pub fn are_horz_grid_lines_clipped(&self) -> bool {
let ptr = self.grid_ptr();
if ptr.is_null() {
return true;
}
unsafe { ffi::wxd_Grid_AreHorzGridLinesClipped(ptr) }
}
pub fn are_vert_grid_lines_clipped(&self) -> bool {
let ptr = self.grid_ptr();
if ptr.is_null() {
return true;
}
unsafe { ffi::wxd_Grid_AreVertGridLinesClipped(ptr) }
}
pub fn clip_horz_grid_lines(&self, clip: bool) {
let ptr = self.grid_ptr();
if ptr.is_null() {
return;
}
unsafe { ffi::wxd_Grid_ClipHorzGridLines(ptr, clip) }
}
pub fn clip_vert_grid_lines(&self, clip: bool) {
let ptr = self.grid_ptr();
if ptr.is_null() {
return;
}
unsafe { ffi::wxd_Grid_ClipVertGridLines(ptr, clip) }
}
pub fn can_drag_cell(&self) -> bool {
let ptr = self.grid_ptr();
if ptr.is_null() {
return false;
}
unsafe { ffi::wxd_Grid_CanDragCell(ptr) }
}
pub fn can_drag_col_move(&self) -> bool {
let ptr = self.grid_ptr();
if ptr.is_null() {
return false;
}
unsafe { ffi::wxd_Grid_CanDragColMove(ptr) }
}
pub fn can_drag_grid_size(&self) -> bool {
let ptr = self.grid_ptr();
if ptr.is_null() {
return false;
}
unsafe { ffi::wxd_Grid_CanDragGridSize(ptr) }
}
pub fn enable_drag_col_move(&self, enable: bool) -> bool {
let ptr = self.grid_ptr();
if ptr.is_null() {
return false;
}
unsafe { ffi::wxd_Grid_EnableDragColMove(ptr, enable) }
}
pub fn disable_drag_col_move(&self) {
let ptr = self.grid_ptr();
if ptr.is_null() {
return;
}
unsafe { ffi::wxd_Grid_DisableDragColMove(ptr) }
}
pub fn disable_drag_col_size(&self) {
let ptr = self.grid_ptr();
if ptr.is_null() {
return;
}
unsafe { ffi::wxd_Grid_DisableDragColSize(ptr) }
}
pub fn disable_drag_row_size(&self) {
let ptr = self.grid_ptr();
if ptr.is_null() {
return;
}
unsafe { ffi::wxd_Grid_DisableDragRowSize(ptr) }
}
pub fn disable_drag_grid_size(&self) {
let ptr = self.grid_ptr();
if ptr.is_null() {
return;
}
unsafe { ffi::wxd_Grid_DisableDragGridSize(ptr) }
}
pub fn disable_col_resize(&self, col: i32) {
let ptr = self.grid_ptr();
if ptr.is_null() {
return;
}
unsafe { ffi::wxd_Grid_DisableColResize(ptr, col) }
}
pub fn disable_row_resize(&self, row: i32) {
let ptr = self.grid_ptr();
if ptr.is_null() {
return;
}
unsafe { ffi::wxd_Grid_DisableRowResize(ptr, row) }
}
pub fn get_col_at(&self, pos: i32) -> i32 {
let ptr = self.grid_ptr();
if ptr.is_null() {
return -1;
}
unsafe { ffi::wxd_Grid_GetColAt(ptr, pos) }
}
pub fn get_col_pos(&self, col: i32) -> i32 {
let ptr = self.grid_ptr();
if ptr.is_null() {
return -1;
}
unsafe { ffi::wxd_Grid_GetColPos(ptr, col) }
}
pub fn set_col_pos(&self, col: i32, pos: i32) {
let ptr = self.grid_ptr();
if ptr.is_null() {
return;
}
unsafe { ffi::wxd_Grid_SetColPos(ptr, col, pos) }
}
pub fn reset_col_pos(&self) {
let ptr = self.grid_ptr();
if ptr.is_null() {
return;
}
unsafe { ffi::wxd_Grid_ResetColPos(ptr) }
}
pub fn get_row_at(&self, pos: i32) -> i32 {
let ptr = self.grid_ptr();
if ptr.is_null() {
return -1;
}
unsafe { ffi::wxd_Grid_GetRowAt(ptr, pos) }
}
pub fn get_row_pos(&self, idx: i32) -> i32 {
let ptr = self.grid_ptr();
if ptr.is_null() {
return -1;
}
unsafe { ffi::wxd_Grid_GetRowPos(ptr, idx) }
}
pub fn set_row_pos(&self, idx: i32, pos: i32) {
let ptr = self.grid_ptr();
if ptr.is_null() {
return;
}
unsafe { ffi::wxd_Grid_SetRowPos(ptr, idx, pos) }
}
pub fn reset_row_pos(&self) {
let ptr = self.grid_ptr();
if ptr.is_null() {
return;
}
unsafe { ffi::wxd_Grid_ResetRowPos(ptr) }
}
pub fn set_margins(&self, extra_width: i32, extra_height: i32) {
let ptr = self.grid_ptr();
if ptr.is_null() {
return;
}
unsafe { ffi::wxd_Grid_SetMargins(ptr, extra_width, extra_height) }
}
pub fn refresh_attr(&self, row: i32, col: i32) {
let ptr = self.grid_ptr();
if ptr.is_null() {
return;
}
unsafe { ffi::wxd_Grid_RefreshAttr(ptr, row, col) }
}
pub fn refresh_block(&self, top_row: i32, left_col: i32, bottom_row: i32, right_col: i32) {
let ptr = self.grid_ptr();
if ptr.is_null() {
return;
}
unsafe { ffi::wxd_Grid_RefreshBlock(ptr, top_row, left_col, bottom_row, right_col) }
}
}
impl WxWidget for Grid {
fn handle_ptr(&self) -> *mut ffi::wxd_Window_t {
self.handle.get_ptr().unwrap_or(std::ptr::null_mut())
}
fn is_valid(&self) -> bool {
self.handle.is_valid()
}
}
impl WxEvtHandler for Grid {
unsafe fn get_event_handler_ptr(&self) -> *mut ffi::wxd_EvtHandler_t {
self.handle.get_ptr().unwrap_or(std::ptr::null_mut()) as *mut ffi::wxd_EvtHandler_t
}
}
widget_builder!(
name: Grid,
parent_type: &'a dyn WxWidget,
style_type: GridStyle,
fields: {
num_rows: i32 = 0,
num_cols: i32 = 0,
selection_mode: GridSelectionMode = GridSelectionMode::Cells
},
build_impl: |slf| {
let grid = Grid::new_impl(
slf.parent.handle_ptr(),
slf.id,
slf.pos,
slf.size,
slf.style.bits()
);
if slf.num_rows > 0 && slf.num_cols > 0 {
grid.create_grid(slf.num_rows, slf.num_cols, slf.selection_mode);
}
grid
}
);
impl<'a> GridBuilder<'a> {
pub fn with_rows(mut self, rows: i32) -> Self {
self.num_rows = rows;
self
}
pub fn with_cols(mut self, cols: i32) -> Self {
self.num_cols = cols;
self
}
}
crate::implement_widget_local_event_handlers!(
Grid,
GridEvent,
GridEventData,
CellLeftClick => cell_left_click, EventType::GRID_CELL_LEFT_CLICK,
CellRightClick => cell_right_click, EventType::GRID_CELL_RIGHT_CLICK,
CellLeftDClick => cell_left_dclick, EventType::GRID_CELL_LEFT_DCLICK,
CellRightDClick => cell_right_dclick, EventType::GRID_CELL_RIGHT_DCLICK,
LabelLeftClick => label_left_click, EventType::GRID_LABEL_LEFT_CLICK,
LabelRightClick => label_right_click, EventType::GRID_LABEL_RIGHT_CLICK,
LabelLeftDClick => label_left_dclick, EventType::GRID_LABEL_LEFT_DCLICK,
LabelRightDClick => label_right_dclick, EventType::GRID_LABEL_RIGHT_DCLICK,
CellChanged => cell_changed, EventType::GRID_CELL_CHANGED,
SelectCell => select_cell, EventType::GRID_SELECT_CELL,
EditorShown => editor_shown, EventType::GRID_EDITOR_SHOWN,
EditorHidden => editor_hidden, EventType::GRID_EDITOR_HIDDEN,
EditorCreated => editor_created, EventType::GRID_EDITOR_CREATED,
CellBeginDrag => cell_begin_drag, EventType::GRID_CELL_BEGIN_DRAG,
RowSize => row_size, EventType::GRID_ROW_SIZE,
ColSize => col_size, EventType::GRID_COL_SIZE,
RangeSelected => range_selected, EventType::GRID_RANGE_SELECTED
);
impl crate::window::FromWindowWithClassName for Grid {
fn class_name() -> &'static str {
"wxGrid"
}
unsafe fn from_ptr(ptr: *mut ffi::wxd_Window_t) -> Self {
Grid {
handle: WindowHandle::new(ptr),
}
}
}
#[cfg(feature = "xrc")]
impl crate::xrc::XrcSupport for Grid {
unsafe fn from_xrc_ptr(ptr: *mut ffi::wxd_Window_t) -> Self {
Grid {
handle: WindowHandle::new(ptr),
}
}
}