use crate::color::Colour;
use crate::event::{Event, EventType, WxEvtHandler};
use crate::font::Font;
use crate::geometry::{Point, Size};
use crate::id::Id;
use crate::window::{WindowHandle, WxWidget};
use std::ffi::CString;
use std::os::raw::c_char;
use wxdragon_sys as ffi;
#[repr(i32)]
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum MarkerSymbol {
Circle = 0,
RoundRect = 1,
Arrow = 2,
SmallRect = 3,
ShortArrow = 4,
Empty = 5,
ArrowDown = 6,
Minus = 7,
Plus = 8,
VLine = 9,
LCorner = 10,
TCorner = 11,
BoxPlus = 12,
BoxPlusConnected = 13,
BoxMinus = 14,
BoxMinusConnected = 15,
LCornerCurve = 16,
TCornerCurve = 17,
CirclePlus = 18,
CirclePlusConnected = 19,
CircleMinus = 20,
CircleMinusConnected = 21,
Background = 22,
DotDotDot = 23,
Arrows = 24,
Pixmap = 25,
FullRect = 26,
LeftRect = 27,
Available = 28,
Underline = 29,
RgbaImage = 30,
Bookmark = 31,
Character = 10000,
}
impl From<MarkerSymbol> for i32 {
fn from(val: MarkerSymbol) -> Self {
val as i32
}
}
#[repr(i32)]
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum SelectionMode {
Stream = 0,
Rectangle = 1,
Lines = 2,
Thin = 3,
}
impl From<SelectionMode> for i32 {
fn from(val: SelectionMode) -> Self {
val as i32
}
}
#[repr(i32)]
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum MarginType {
Symbol = 0,
Number = 1,
Back = 2,
Fore = 3,
Text = 4,
RText = 5,
Colour = 6,
}
impl From<MarginType> for i32 {
fn from(val: MarginType) -> Self {
val as i32
}
}
widget_style_enum!(
name: FindFlags,
doc: "Search flags for find operations in StyledTextCtrl.",
variants: {
None: 0, "No special flags.",
WholeWord: 0x2, "Match whole words only.",
MatchCase: 0x4, "Case-sensitive matching.",
WordStart: 0x00100000, "Match at word start.",
RegExp: 0x00200000, "Use regular expressions.",
Posix: 0x00400000, "Use POSIX regular expressions."
},
default_variant: None
);
impl FindFlags {
pub fn bits_i32(self) -> i32 {
self.bits() as i32
}
}
impl From<FindFlags> for i32 {
fn from(val: FindFlags) -> Self {
val.bits() as i32
}
}
impl From<i32> for FindFlags {
fn from(bits: i32) -> Self {
unsafe { std::mem::transmute(bits as i64) }
}
}
#[repr(i32)]
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum WhiteSpaceView {
Invisible = 0,
VisibleAlways = 1,
VisibleAfterIndent = 2,
VisibleOnlyInIndent = 3,
}
impl From<WhiteSpaceView> for i32 {
fn from(val: WhiteSpaceView) -> Self {
val as i32
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum Lexer {
Null = 0,
Scintilla = 1,
Container = 2,
Cpp = 3,
Python = 4,
Html = 5,
Xml = 6,
Perl = 7,
Sql = 8,
Vb = 9,
Properties = 10,
Errorlist = 11,
Makefile = 12,
Batch = 13,
Xcode = 14,
Latex = 15,
Lua = 16,
Diff = 17,
Conf = 18,
Pascal = 19,
Ave = 20,
Ada = 21,
Lisp = 22,
Ruby = 23,
Eiffel = 24,
Eiffelkw = 25,
Tcl = 26,
Nncrontab = 27,
Bullant = 28,
Vbscript = 29,
Baan = 30,
Matlab = 31,
Scriptol = 32,
Asm = 33,
Cppnocase = 34,
Fortran = 35,
F77 = 36,
Css = 37,
Pov = 38,
Lout = 39,
Escript = 40,
Ps = 41,
Nsis = 42,
Mmixal = 43,
Clw = 44,
Clwnocase = 45,
Lot = 46,
Yaml = 47,
Tex = 48,
Metapost = 49,
Powerbasic = 50,
Forth = 51,
Erlang = 52,
Octave = 53,
Mssql = 54,
Verilog = 55,
Kix = 56,
Gui4cli = 57,
Specman = 58,
Au3 = 59,
Apdl = 60,
Bash = 61,
Asn1 = 62,
Vhdl = 63,
Caml = 64,
Blitzbasic = 65,
Purebasic = 66,
Haskell = 67,
Phpscript = 68,
Tads3 = 69,
Rebol = 70,
Smalltalk = 71,
Flagship = 72,
Csound = 73,
Freebasic = 74,
Innosetup = 75,
Opal = 76,
Spice = 77,
D = 78,
Javascript = 79, Java = 80, }
impl From<Lexer> for i32 {
fn from(val: Lexer) -> Self {
val as i32
}
}
#[repr(i32)]
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum EolMode {
CrLf = 0,
Cr = 1,
Lf = 2,
}
impl From<EolMode> for i32 {
fn from(val: EolMode) -> Self {
val as i32
}
}
#[repr(i32)]
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum WrapMode {
None = 0,
Word = 1,
Char = 2,
Whitespace = 3,
}
impl From<WrapMode> for i32 {
fn from(val: WrapMode) -> Self {
val as i32
}
}
impl From<i32> for WrapMode {
fn from(val: i32) -> Self {
match val {
0 => WrapMode::None,
1 => WrapMode::Word,
2 => WrapMode::Char,
3 => WrapMode::Whitespace,
_ => WrapMode::None,
}
}
}
widget_style_enum!(
name: StyledTextCtrlStyle,
doc: "Style flags for StyledTextCtrl widget.",
variants: {
Default: 0, "Default style."
},
default_variant: Default
);
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum StyledTextCtrlEvent {
Change,
StyleNeeded,
CharAdded,
SavePointReached,
SavePointLeft,
RoModifyAttempt,
DoubleClick,
UpdateUI,
Modified,
MacroRecord,
MarginClick,
NeedShown,
Painted,
UserListSelection,
DwellStart,
DwellEnd,
StartDrag,
DragOver,
DoDrop,
Zoom,
HotspotClick,
HotspotDoubleClick,
CallTipClick,
AutoCompSelection,
IndicatorClick,
IndicatorRelease,
AutoCompCancelled,
AutoCompCharDeleted,
}
#[derive(Debug)]
pub struct StyledTextCtrlEventData {
event: Event,
}
impl StyledTextCtrlEventData {
pub fn new(event: Event) -> Self {
Self { event }
}
pub fn get_id(&self) -> i32 {
self.event.get_id()
}
pub fn skip(&self, skip: bool) {
self.event.skip(skip);
}
pub fn get_string(&self) -> Option<String> {
self.event.get_string()
}
pub fn get_position(&self) -> Option<i32> {
self.event.get_int()
}
pub fn get_key(&self) -> Option<i32> {
self.event.get_key_code()
}
}
#[derive(Clone, Copy)]
pub struct StyledTextCtrl {
handle: WindowHandle,
}
impl StyledTextCtrl {
pub fn builder(parent: &dyn WxWidget) -> StyledTextCtrlBuilder<'_> {
StyledTextCtrlBuilder::new(parent)
}
fn new_impl(parent_ptr: *mut ffi::wxd_Window_t, id: Id, pos: Point, size: Size, style: i64) -> Self {
let ptr = unsafe { ffi::wxd_StyledTextCtrl_Create(parent_ptr, id, pos.into(), size.into(), style as ffi::wxd_Style_t) };
if ptr.is_null() {
panic!("Failed to create StyledTextCtrl widget");
}
StyledTextCtrl {
handle: WindowHandle::new(ptr as *mut ffi::wxd_Window_t),
}
}
#[inline]
fn stc_ptr(&self) -> *mut ffi::wxd_StyledTextCtrl_t {
self.handle
.get_ptr()
.map(|p| p as *mut ffi::wxd_StyledTextCtrl_t)
.unwrap_or(std::ptr::null_mut())
}
fn read_string_with_retry(mut getter: impl FnMut(*mut c_char, i32) -> i32) -> String {
let mut buffer: Vec<c_char> = vec![0; 1024];
let mut len = getter(buffer.as_mut_ptr(), buffer.len() as i32);
if len < 0 {
return String::new();
}
if len as usize >= buffer.len() {
buffer = vec![0; len as usize + 1];
len = getter(buffer.as_mut_ptr(), buffer.len() as i32);
if len < 0 {
return String::new();
}
}
let byte_slice = unsafe { std::slice::from_raw_parts(buffer.as_ptr() as *const u8, len as usize) };
String::from_utf8_lossy(byte_slice).to_string()
}
pub fn set_text(&self, text: &str) {
let ptr = self.stc_ptr();
if ptr.is_null() {
return;
}
let c_text = CString::new(text).unwrap_or_default();
unsafe { ffi::wxd_StyledTextCtrl_SetText(ptr, c_text.as_ptr()) };
}
pub fn get_text(&self) -> String {
let ptr = self.stc_ptr();
if ptr.is_null() {
return String::new();
}
unsafe { Self::read_string_with_retry(|buf, len| ffi::wxd_StyledTextCtrl_GetText(ptr, buf, len)) }
}
pub fn append_text(&self, text: &str) {
let ptr = self.stc_ptr();
if ptr.is_null() {
return;
}
let c_text = CString::new(text).unwrap_or_default();
unsafe { ffi::wxd_StyledTextCtrl_AppendText(ptr, c_text.as_ptr()) };
}
pub fn insert_text(&self, pos: i32, text: &str) {
let ptr = self.stc_ptr();
if ptr.is_null() {
return;
}
let c_text = CString::new(text).unwrap_or_default();
unsafe { ffi::wxd_StyledTextCtrl_InsertText(ptr, pos, c_text.as_ptr()) };
}
pub fn clear_all(&self) {
let ptr = self.stc_ptr();
if ptr.is_null() {
return;
}
unsafe { ffi::wxd_StyledTextCtrl_ClearAll(ptr) };
}
pub fn delete_range(&self, start: i32, length: i32) {
let ptr = self.stc_ptr();
if ptr.is_null() {
return;
}
unsafe { ffi::wxd_StyledTextCtrl_DeleteRange(ptr, start, length) };
}
pub fn get_length(&self) -> i32 {
let ptr = self.stc_ptr();
if ptr.is_null() {
return 0;
}
unsafe { ffi::wxd_StyledTextCtrl_GetLength(ptr) }
}
pub fn get_line_count(&self) -> i32 {
let ptr = self.stc_ptr();
if ptr.is_null() {
return 0;
}
unsafe { ffi::wxd_StyledTextCtrl_GetLineCount(ptr) }
}
pub fn get_char_at(&self, pos: i32) -> i32 {
let ptr = self.stc_ptr();
if ptr.is_null() {
return 0;
}
unsafe { ffi::wxd_StyledTextCtrl_GetCharAt(ptr, pos) }
}
pub fn get_style_at(&self, pos: i32) -> i32 {
let ptr = self.stc_ptr();
if ptr.is_null() {
return 0;
}
unsafe { ffi::wxd_StyledTextCtrl_GetStyleAt(ptr, pos) }
}
pub fn cut(&self) {
let ptr = self.stc_ptr();
if ptr.is_null() {
return;
}
unsafe { ffi::wxd_StyledTextCtrl_Cut(ptr) };
}
pub fn copy(&self) {
let ptr = self.stc_ptr();
if ptr.is_null() {
return;
}
unsafe { ffi::wxd_StyledTextCtrl_Copy(ptr) };
}
pub fn paste(&self) {
let ptr = self.stc_ptr();
if ptr.is_null() {
return;
}
unsafe { ffi::wxd_StyledTextCtrl_Paste(ptr) };
}
pub fn undo(&self) {
let ptr = self.stc_ptr();
if ptr.is_null() {
return;
}
unsafe { ffi::wxd_StyledTextCtrl_Undo(ptr) };
}
pub fn select_all(&self) {
let ptr = self.stc_ptr();
if ptr.is_null() {
return;
}
unsafe { ffi::wxd_StyledTextCtrl_SelectAll(ptr) };
}
pub fn set_read_only(&self, read_only: bool) {
let ptr = self.stc_ptr();
if ptr.is_null() {
return;
}
unsafe { ffi::wxd_StyledTextCtrl_SetReadOnly(ptr, read_only) };
}
pub fn is_read_only(&self) -> bool {
let ptr = self.stc_ptr();
if ptr.is_null() {
return false;
}
unsafe { ffi::wxd_StyledTextCtrl_GetReadOnly(ptr) }
}
pub fn get_current_pos(&self) -> i32 {
let ptr = self.stc_ptr();
if ptr.is_null() {
return 0;
}
unsafe { ffi::wxd_StyledTextCtrl_GetCurrentPos(ptr) }
}
pub fn set_current_pos(&self, pos: i32) {
let ptr = self.stc_ptr();
if ptr.is_null() {
return;
}
unsafe { ffi::wxd_StyledTextCtrl_SetCurrentPos(ptr, pos) };
}
pub fn get_selection(&self) -> (i32, i32) {
let ptr = self.stc_ptr();
if ptr.is_null() {
return (0, 0);
}
let mut start = 0;
let mut end = 0;
unsafe { ffi::wxd_StyledTextCtrl_GetSelection(ptr, &mut start, &mut end) };
(start, end)
}
pub fn set_selection(&self, start: i32, end: i32) {
let ptr = self.stc_ptr();
if ptr.is_null() {
return;
}
unsafe { ffi::wxd_StyledTextCtrl_SetSelection(ptr, start, end) };
}
pub fn get_selection_start(&self) -> i32 {
let ptr = self.stc_ptr();
if ptr.is_null() {
return 0;
}
unsafe { ffi::wxd_StyledTextCtrl_GetSelectionStart(ptr) }
}
pub fn get_selection_end(&self) -> i32 {
let ptr = self.stc_ptr();
if ptr.is_null() {
return 0;
}
unsafe { ffi::wxd_StyledTextCtrl_GetSelectionEnd(ptr) }
}
pub fn get_selected_text(&self) -> String {
let ptr = self.stc_ptr();
if ptr.is_null() {
return String::new();
}
unsafe { Self::read_string_with_retry(|buf, len| ffi::wxd_StyledTextCtrl_GetSelectedText(ptr, buf, len)) }
}
pub fn set_selection_mode(&self, selection_mode: i32) {
let ptr = self.stc_ptr();
if ptr.is_null() {
return;
}
unsafe { ffi::wxd_StyledTextCtrl_SetSelectionMode(ptr, selection_mode) };
}
pub fn set_selection_mode_typed(&self, selection_mode: SelectionMode) {
self.set_selection_mode(selection_mode.into());
}
pub fn get_selection_mode(&self) -> i32 {
let ptr = self.stc_ptr();
if ptr.is_null() {
return 0;
}
unsafe { ffi::wxd_StyledTextCtrl_GetSelectionMode(ptr) }
}
pub fn ensure_caret_visible(&self) {
let ptr = self.stc_ptr();
if ptr.is_null() {
return;
}
unsafe { ffi::wxd_StyledTextCtrl_EnsureCaretVisible(ptr) };
}
pub fn line_scroll(&self, columns: i32, lines: i32) {
let ptr = self.stc_ptr();
if ptr.is_null() {
return;
}
unsafe { ffi::wxd_StyledTextCtrl_LineScroll(ptr, columns, lines) };
}
pub fn scroll_to_line(&self, line: i32) {
let ptr = self.stc_ptr();
if ptr.is_null() {
return;
}
unsafe { ffi::wxd_StyledTextCtrl_ScrollToLine(ptr, line) };
}
pub fn scroll_to_column(&self, column: i32) {
let ptr = self.stc_ptr();
if ptr.is_null() {
return;
}
unsafe { ffi::wxd_StyledTextCtrl_ScrollToColumn(ptr, column) };
}
pub fn line_from_position(&self, pos: i32) -> i32 {
let ptr = self.stc_ptr();
if ptr.is_null() {
return 0;
}
unsafe { ffi::wxd_StyledTextCtrl_LineFromPosition(ptr, pos) }
}
pub fn position_from_line(&self, line: i32) -> i32 {
let ptr = self.stc_ptr();
if ptr.is_null() {
return 0;
}
unsafe { ffi::wxd_StyledTextCtrl_PositionFromLine(ptr, line) }
}
pub fn get_line_text(&self, line: i32) -> String {
let ptr = self.stc_ptr();
if ptr.is_null() {
return String::new();
}
unsafe { Self::read_string_with_retry(|buf, len| ffi::wxd_StyledTextCtrl_GetLineText(ptr, line, buf, len)) }
}
pub fn get_line_length(&self, line: i32) -> i32 {
let ptr = self.stc_ptr();
if ptr.is_null() {
return 0;
}
unsafe { ffi::wxd_StyledTextCtrl_GetLineLength(ptr, line) }
}
pub fn marker_define(&self, marker_number: i32, marker_symbol: i32, foreground: Colour, background: Colour) {
let ptr = self.stc_ptr();
if ptr.is_null() {
return;
}
unsafe { ffi::wxd_StyledTextCtrl_MarkerDefine(ptr, marker_number, marker_symbol, foreground.into(), background.into()) };
}
pub fn marker_define_symbol(&self, marker_number: i32, marker_symbol: MarkerSymbol, foreground: Colour, background: Colour) {
self.marker_define(marker_number, marker_symbol.into(), foreground, background);
}
pub fn marker_add(&self, line: i32, marker_number: i32) -> i32 {
let ptr = self.stc_ptr();
if ptr.is_null() {
return 0;
}
unsafe { ffi::wxd_StyledTextCtrl_MarkerAdd(ptr, line, marker_number) }
}
pub fn marker_delete(&self, line: i32, marker_number: i32) {
let ptr = self.stc_ptr();
if ptr.is_null() {
return;
}
unsafe { ffi::wxd_StyledTextCtrl_MarkerDelete(ptr, line, marker_number) };
}
pub fn marker_delete_all(&self, marker_number: i32) {
let ptr = self.stc_ptr();
if ptr.is_null() {
return;
}
unsafe { ffi::wxd_StyledTextCtrl_MarkerDeleteAll(ptr, marker_number) };
}
pub fn marker_get(&self, line: i32) -> i32 {
let ptr = self.stc_ptr();
if ptr.is_null() {
return 0;
}
unsafe { ffi::wxd_StyledTextCtrl_MarkerGet(ptr, line) }
}
pub fn marker_next(&self, line_start: i32, marker_mask: i32) -> i32 {
let ptr = self.stc_ptr();
if ptr.is_null() {
return 0;
}
unsafe { ffi::wxd_StyledTextCtrl_MarkerNext(ptr, line_start, marker_mask) }
}
pub fn marker_previous(&self, line_start: i32, marker_mask: i32) -> i32 {
let ptr = self.stc_ptr();
if ptr.is_null() {
return 0;
}
unsafe { ffi::wxd_StyledTextCtrl_MarkerPrevious(ptr, line_start, marker_mask) }
}
pub fn marker_set_foreground(&self, marker_number: i32, color: Colour) {
let ptr = self.stc_ptr();
if ptr.is_null() {
return;
}
unsafe { ffi::wxd_StyledTextCtrl_MarkerSetForeground(ptr, marker_number, color.into()) };
}
pub fn marker_set_background(&self, marker_number: i32, color: Colour) {
let ptr = self.stc_ptr();
if ptr.is_null() {
return;
}
unsafe { ffi::wxd_StyledTextCtrl_MarkerSetBackground(ptr, marker_number, color.into()) };
}
pub fn style_set_font(&self, style: i32, font: &Font) {
let ptr = self.stc_ptr();
if ptr.is_null() {
return;
}
unsafe { ffi::wxd_StyledTextCtrl_StyleSetFont(ptr, style, font.as_ptr()) };
}
pub fn style_set_foreground(&self, style: i32, color: Colour) {
let ptr = self.stc_ptr();
if ptr.is_null() {
return;
}
unsafe { ffi::wxd_StyledTextCtrl_StyleSetForeground(ptr, style, color.into()) };
}
pub fn style_set_background(&self, style: i32, color: Colour) {
let ptr = self.stc_ptr();
if ptr.is_null() {
return;
}
unsafe { ffi::wxd_StyledTextCtrl_StyleSetBackground(ptr, style, color.into()) };
}
pub fn style_set_bold(&self, style: i32, bold: bool) {
let ptr = self.stc_ptr();
if ptr.is_null() {
return;
}
unsafe { ffi::wxd_StyledTextCtrl_StyleSetBold(ptr, style, bold) };
}
pub fn style_set_italic(&self, style: i32, italic: bool) {
let ptr = self.stc_ptr();
if ptr.is_null() {
return;
}
unsafe { ffi::wxd_StyledTextCtrl_StyleSetItalic(ptr, style, italic) };
}
pub fn style_set_underline(&self, style: i32, underline: bool) {
let ptr = self.stc_ptr();
if ptr.is_null() {
return;
}
unsafe { ffi::wxd_StyledTextCtrl_StyleSetUnderline(ptr, style, underline) };
}
pub fn style_set_size(&self, style: i32, size: i32) {
let ptr = self.stc_ptr();
if ptr.is_null() {
return;
}
unsafe { ffi::wxd_StyledTextCtrl_StyleSetSize(ptr, style, size) };
}
pub fn style_clear_all(&self) {
let ptr = self.stc_ptr();
if ptr.is_null() {
return;
}
unsafe { ffi::wxd_StyledTextCtrl_StyleClearAll(ptr) };
}
pub fn start_styling(&self, start: i32) {
let ptr = self.stc_ptr();
if ptr.is_null() {
return;
}
unsafe { ffi::wxd_StyledTextCtrl_StartStyling(ptr, start) };
}
pub fn set_styling(&self, length: i32, style: i32) {
let ptr = self.stc_ptr();
if ptr.is_null() {
return;
}
unsafe { ffi::wxd_StyledTextCtrl_SetStyling(ptr, length, style) };
}
pub fn set_lexer(&self, lexer: i32) {
let ptr = self.stc_ptr();
if ptr.is_null() {
return;
}
unsafe { ffi::wxd_StyledTextCtrl_SetLexer(ptr, lexer) };
}
pub fn set_lexer_typed(&self, lexer: Lexer) {
self.set_lexer(lexer.into());
}
pub fn get_lexer(&self) -> i32 {
let ptr = self.stc_ptr();
if ptr.is_null() {
return 0;
}
unsafe { ffi::wxd_StyledTextCtrl_GetLexer(ptr) }
}
pub fn set_lexer_language(&self, language: &str) {
let ptr = self.stc_ptr();
if ptr.is_null() {
return;
}
let c_language = CString::new(language).unwrap_or_default();
unsafe { ffi::wxd_StyledTextCtrl_SetLexerLanguage(ptr, c_language.as_ptr()) };
}
pub fn set_margin_type(&self, margin: i32, margin_type: MarginType) {
let ptr = self.stc_ptr();
if ptr.is_null() {
return;
}
unsafe { ffi::wxd_StyledTextCtrl_SetMarginType(ptr, margin, margin_type as i32) };
}
pub fn set_margin_type_typed(&self, margin: i32, margin_type: MarginType) {
self.set_margin_type(margin, margin_type);
}
pub fn set_margin_width(&self, margin: i32, pixel_width: i32) {
let ptr = self.stc_ptr();
if ptr.is_null() {
return;
}
unsafe { ffi::wxd_StyledTextCtrl_SetMarginWidth(ptr, margin, pixel_width) };
}
pub fn set_margin_line_numbers(&self, margin: i32, line_numbers: bool) {
let ptr = self.stc_ptr();
if ptr.is_null() {
return;
}
unsafe { ffi::wxd_StyledTextCtrl_SetMarginLineNumbers(ptr, margin, line_numbers) };
}
pub fn zoom_in(&self) {
let ptr = self.stc_ptr();
if ptr.is_null() {
return;
}
unsafe { ffi::wxd_StyledTextCtrl_ZoomIn(ptr) };
}
pub fn zoom_out(&self) {
let ptr = self.stc_ptr();
if ptr.is_null() {
return;
}
unsafe { ffi::wxd_StyledTextCtrl_ZoomOut(ptr) };
}
pub fn set_zoom(&self, zoom_level: i32) {
let ptr = self.stc_ptr();
if ptr.is_null() {
return;
}
unsafe { ffi::wxd_StyledTextCtrl_SetZoom(ptr, zoom_level) };
}
pub fn get_zoom(&self) -> i32 {
let ptr = self.stc_ptr();
if ptr.is_null() {
return 0;
}
unsafe { ffi::wxd_StyledTextCtrl_GetZoom(ptr) }
}
pub fn is_modified(&self) -> bool {
let ptr = self.stc_ptr();
if ptr.is_null() {
return false;
}
unsafe { ffi::wxd_StyledTextCtrl_GetModify(ptr) }
}
pub fn set_save_point(&self) {
let ptr = self.stc_ptr();
if ptr.is_null() {
return;
}
unsafe { ffi::wxd_StyledTextCtrl_SetSavePoint(ptr) };
}
pub fn search_anchor(&self) {
let ptr = self.stc_ptr();
if ptr.is_null() {
return;
}
unsafe { ffi::wxd_StyledTextCtrl_SearchAnchor(ptr) }
}
pub fn find_text(&self, min_pos: i32, max_pos: i32, text: &str, flags: FindFlags) -> Option<i32> {
let ptr = self.stc_ptr();
if ptr.is_null() {
return None;
}
let c_text = CString::new(text).unwrap();
let result = unsafe { ffi::wxd_StyledTextCtrl_FindText(ptr, min_pos, max_pos, c_text.as_ptr(), flags.bits_i32()) };
if result >= 0 { Some(result) } else { None }
}
pub fn find_text_typed(&self, min_pos: i32, max_pos: i32, text: &str, flags: FindFlags) -> Option<i32> {
self.find_text(min_pos, max_pos, text, flags)
}
pub fn find_text_combined_flags(&self, min_pos: i32, max_pos: i32, text: &str, flags: i32) -> Option<i32> {
self.find_text(min_pos, max_pos, text, FindFlags::from(flags))
}
pub fn search_next(&self, search_flags: FindFlags, text: &str) -> Option<i32> {
let ptr = self.stc_ptr();
if ptr.is_null() {
return None;
}
let c_text = CString::new(text).unwrap();
let result = unsafe { ffi::wxd_StyledTextCtrl_SearchNext(ptr, search_flags.bits_i32(), c_text.as_ptr()) };
if result >= 0 { Some(result) } else { None }
}
pub fn search_prev(&self, search_flags: FindFlags, text: &str) -> Option<i32> {
let ptr = self.stc_ptr();
if ptr.is_null() {
return None;
}
let c_text = CString::new(text).unwrap();
let result = unsafe { ffi::wxd_StyledTextCtrl_SearchPrev(ptr, search_flags.bits_i32(), c_text.as_ptr()) };
if result >= 0 { Some(result) } else { None }
}
pub fn search_next_typed(&self, search_flags: FindFlags, text: &str) -> Option<i32> {
self.search_next(search_flags, text)
}
pub fn search_prev_typed(&self, search_flags: FindFlags, text: &str) -> Option<i32> {
self.search_prev(search_flags, text)
}
pub fn replace_selection(&self, text: &str) {
let ptr = self.stc_ptr();
if ptr.is_null() {
return;
}
let c_text = CString::new(text).unwrap_or_default();
unsafe { ffi::wxd_StyledTextCtrl_ReplaceSelection(ptr, c_text.as_ptr()) };
}
pub fn replace_target(&self, text: &str) -> i32 {
let ptr = self.stc_ptr();
if ptr.is_null() {
return 0;
}
let c_text = CString::new(text).unwrap_or_default();
unsafe { ffi::wxd_StyledTextCtrl_ReplaceTarget(ptr, c_text.as_ptr()) }
}
pub fn set_target_start(&self, start: i32) {
let ptr = self.stc_ptr();
if ptr.is_null() {
return;
}
unsafe { ffi::wxd_StyledTextCtrl_SetTargetStart(ptr, start) };
}
pub fn set_target_end(&self, end: i32) {
let ptr = self.stc_ptr();
if ptr.is_null() {
return;
}
unsafe { ffi::wxd_StyledTextCtrl_SetTargetEnd(ptr, end) };
}
pub fn get_target_start(&self) -> i32 {
let ptr = self.stc_ptr();
if ptr.is_null() {
return 0;
}
unsafe { ffi::wxd_StyledTextCtrl_GetTargetStart(ptr) }
}
pub fn get_target_end(&self) -> i32 {
let ptr = self.stc_ptr();
if ptr.is_null() {
return 0;
}
unsafe { ffi::wxd_StyledTextCtrl_GetTargetEnd(ptr) }
}
pub fn get_current_line(&self) -> i32 {
let ptr = self.stc_ptr();
if ptr.is_null() {
return 0;
}
unsafe { ffi::wxd_StyledTextCtrl_GetCurrentLine(ptr) }
}
pub fn goto_line(&self, line: i32) {
let ptr = self.stc_ptr();
if ptr.is_null() {
return;
}
unsafe { ffi::wxd_StyledTextCtrl_GotoLine(ptr, line) };
}
pub fn goto_pos(&self, pos: i32) {
let ptr = self.stc_ptr();
if ptr.is_null() {
return;
}
unsafe { ffi::wxd_StyledTextCtrl_GotoPos(ptr, pos) };
}
pub fn set_tab_width(&self, tab_width: i32) {
let ptr = self.stc_ptr();
if ptr.is_null() {
return;
}
unsafe { ffi::wxd_StyledTextCtrl_SetTabWidth(ptr, tab_width) };
}
pub fn get_tab_width(&self) -> i32 {
let ptr = self.stc_ptr();
if ptr.is_null() {
return 0;
}
unsafe { ffi::wxd_StyledTextCtrl_GetTabWidth(ptr) }
}
pub fn set_indent(&self, indent_size: i32) {
let ptr = self.stc_ptr();
if ptr.is_null() {
return;
}
unsafe { ffi::wxd_StyledTextCtrl_SetIndent(ptr, indent_size) };
}
pub fn get_indent(&self) -> i32 {
let ptr = self.stc_ptr();
if ptr.is_null() {
return 0;
}
unsafe { ffi::wxd_StyledTextCtrl_GetIndent(ptr) }
}
pub fn set_use_tabs(&self, use_tabs: bool) {
let ptr = self.stc_ptr();
if ptr.is_null() {
return;
}
unsafe { ffi::wxd_StyledTextCtrl_SetUseTabs(ptr, use_tabs) };
}
pub fn get_use_tabs(&self) -> bool {
let ptr = self.stc_ptr();
if ptr.is_null() {
return false;
}
unsafe { ffi::wxd_StyledTextCtrl_GetUseTabs(ptr) }
}
pub fn set_line_indentation(&self, line: i32, indentation: i32) {
let ptr = self.stc_ptr();
if ptr.is_null() {
return;
}
unsafe { ffi::wxd_StyledTextCtrl_SetLineIndentation(ptr, line, indentation) };
}
pub fn get_line_indentation(&self, line: i32) -> i32 {
let ptr = self.stc_ptr();
if ptr.is_null() {
return 0;
}
unsafe { ffi::wxd_StyledTextCtrl_GetLineIndentation(ptr, line) }
}
pub fn set_view_eol(&self, visible: bool) {
let ptr = self.stc_ptr();
if ptr.is_null() {
return;
}
unsafe { ffi::wxd_StyledTextCtrl_SetViewEOL(ptr, visible) };
}
pub fn get_view_eol(&self) -> bool {
let ptr = self.stc_ptr();
if ptr.is_null() {
return false;
}
unsafe { ffi::wxd_StyledTextCtrl_GetViewEOL(ptr) }
}
pub fn set_view_white_space(&self, view_ws: i32) {
let ptr = self.stc_ptr();
if ptr.is_null() {
return;
}
unsafe { ffi::wxd_StyledTextCtrl_SetViewWhiteSpace(ptr, view_ws) };
}
pub fn set_view_white_space_typed(&self, view_ws: WhiteSpaceView) {
self.set_view_white_space(view_ws.into());
}
pub fn get_view_white_space(&self) -> i32 {
let ptr = self.stc_ptr();
if ptr.is_null() {
return 0;
}
unsafe { ffi::wxd_StyledTextCtrl_GetViewWhiteSpace(ptr) }
}
pub fn set_caret_period(&self, period_ms: i32) {
let ptr = self.stc_ptr();
if ptr.is_null() {
return;
}
unsafe { ffi::wxd_StyledTextCtrl_SetCaretPeriod(ptr, period_ms) };
}
pub fn get_caret_period(&self) -> i32 {
let ptr = self.stc_ptr();
if ptr.is_null() {
return 0;
}
unsafe { ffi::wxd_StyledTextCtrl_GetCaretPeriod(ptr) }
}
pub fn set_caret_width(&self, pixel_width: i32) {
let ptr = self.stc_ptr();
if ptr.is_null() {
return;
}
unsafe { ffi::wxd_StyledTextCtrl_SetCaretWidth(ptr, pixel_width) };
}
pub fn get_caret_width(&self) -> i32 {
let ptr = self.stc_ptr();
if ptr.is_null() {
return 0;
}
unsafe { ffi::wxd_StyledTextCtrl_GetCaretWidth(ptr) }
}
pub fn set_caret_line_visible(&self, show: bool) {
let ptr = self.stc_ptr();
if ptr.is_null() {
return;
}
unsafe { ffi::wxd_StyledTextCtrl_SetCaretLineVisible(ptr, show) };
}
pub fn get_caret_line_visible(&self) -> bool {
let ptr = self.stc_ptr();
if ptr.is_null() {
return false;
}
unsafe { ffi::wxd_StyledTextCtrl_GetCaretLineVisible(ptr) }
}
pub fn set_caret_line_background(&self, color: Colour) {
let ptr = self.stc_ptr();
if ptr.is_null() {
return;
}
let c_color = color.to_raw();
unsafe { ffi::wxd_StyledTextCtrl_SetCaretLineBackground(ptr, c_color) };
}
pub fn redo(&self) {
let ptr = self.stc_ptr();
if ptr.is_null() {
return;
}
unsafe { ffi::wxd_StyledTextCtrl_Redo(ptr) };
}
pub fn can_undo(&self) -> bool {
let ptr = self.stc_ptr();
if ptr.is_null() {
return false;
}
unsafe { ffi::wxd_StyledTextCtrl_CanUndo(ptr) }
}
pub fn can_redo(&self) -> bool {
let ptr = self.stc_ptr();
if ptr.is_null() {
return false;
}
unsafe { ffi::wxd_StyledTextCtrl_CanRedo(ptr) }
}
pub fn empty_undo_buffer(&self) {
let ptr = self.stc_ptr();
if ptr.is_null() {
return;
}
unsafe { ffi::wxd_StyledTextCtrl_EmptyUndoBuffer(ptr) };
}
pub fn auto_comp_show(&self, length_entered: i32, item_list: &str) {
let ptr = self.stc_ptr();
if ptr.is_null() {
return;
}
let c_item_list = CString::new(item_list).unwrap_or_default();
unsafe { ffi::wxd_StyledTextCtrl_AutoCompShow(ptr, length_entered, c_item_list.as_ptr()) };
}
pub fn auto_comp_cancel(&self) {
let ptr = self.stc_ptr();
if ptr.is_null() {
return;
}
unsafe { ffi::wxd_StyledTextCtrl_AutoCompCancel(ptr) };
}
pub fn auto_comp_active(&self) -> bool {
let ptr = self.stc_ptr();
if ptr.is_null() {
return false;
}
unsafe { ffi::wxd_StyledTextCtrl_AutoCompActive(ptr) }
}
pub fn auto_comp_complete(&self) {
let ptr = self.stc_ptr();
if ptr.is_null() {
return;
}
unsafe { ffi::wxd_StyledTextCtrl_AutoCompComplete(ptr) };
}
pub fn auto_comp_set_separator(&self, separator_char: i32) {
let ptr = self.stc_ptr();
if ptr.is_null() {
return;
}
unsafe { ffi::wxd_StyledTextCtrl_AutoCompSetSeparator(ptr, separator_char) };
}
pub fn auto_comp_select(&self, select: &str) {
let ptr = self.stc_ptr();
if ptr.is_null() {
return;
}
let c_select = CString::new(select).unwrap_or_default();
unsafe { ffi::wxd_StyledTextCtrl_AutoCompSelect(ptr, c_select.as_ptr()) };
}
pub fn brace_highlight(&self, pos_a: i32, pos_b: i32) {
let ptr = self.stc_ptr();
if ptr.is_null() {
return;
}
unsafe { ffi::wxd_StyledTextCtrl_BraceHighlight(ptr, pos_a, pos_b) };
}
pub fn brace_bad_light(&self, pos: i32) {
let ptr = self.stc_ptr();
if ptr.is_null() {
return;
}
unsafe { ffi::wxd_StyledTextCtrl_BraceBadLight(ptr, pos) };
}
pub fn brace_match(&self, pos: i32) -> i32 {
let ptr = self.stc_ptr();
if ptr.is_null() {
return 0;
}
unsafe { ffi::wxd_StyledTextCtrl_BraceMatch(ptr, pos) }
}
pub fn call_tip_show(&self, pos: i32, definition: &str) {
let ptr = self.stc_ptr();
if ptr.is_null() {
return;
}
let c_definition = CString::new(definition).unwrap_or_default();
unsafe { ffi::wxd_StyledTextCtrl_CallTipShow(ptr, pos, c_definition.as_ptr()) };
}
pub fn call_tip_cancel(&self) {
let ptr = self.stc_ptr();
if ptr.is_null() {
return;
}
unsafe { ffi::wxd_StyledTextCtrl_CallTipCancel(ptr) };
}
pub fn call_tip_active(&self) -> bool {
let ptr = self.stc_ptr();
if ptr.is_null() {
return false;
}
unsafe { ffi::wxd_StyledTextCtrl_CallTipActive(ptr) }
}
pub fn call_tip_set_highlight(&self, highlight_start: i32, highlight_end: i32) {
let ptr = self.stc_ptr();
if ptr.is_null() {
return;
}
unsafe { ffi::wxd_StyledTextCtrl_CallTipSetHighlight(ptr, highlight_start, highlight_end) };
}
pub fn set_fold_level(&self, line: i32, level: i32) {
let ptr = self.stc_ptr();
if ptr.is_null() {
return;
}
unsafe { ffi::wxd_StyledTextCtrl_SetFoldLevel(ptr, line, level) };
}
pub fn get_fold_level(&self, line: i32) -> i32 {
let ptr = self.stc_ptr();
if ptr.is_null() {
return 0;
}
unsafe { ffi::wxd_StyledTextCtrl_GetFoldLevel(ptr, line) }
}
pub fn toggle_fold(&self, line: i32) {
let ptr = self.stc_ptr();
if ptr.is_null() {
return;
}
unsafe { ffi::wxd_StyledTextCtrl_ToggleFold(ptr, line) };
}
pub fn set_fold_expanded(&self, line: i32, expanded: bool) {
let ptr = self.stc_ptr();
if ptr.is_null() {
return;
}
unsafe { ffi::wxd_StyledTextCtrl_SetFoldExpanded(ptr, line, expanded) };
}
pub fn get_fold_expanded(&self, line: i32) -> bool {
let ptr = self.stc_ptr();
if ptr.is_null() {
return false;
}
unsafe { ffi::wxd_StyledTextCtrl_GetFoldExpanded(ptr, line) }
}
pub fn word_start_position(&self, pos: i32, only_word_chars: bool) -> i32 {
let ptr = self.stc_ptr();
if ptr.is_null() {
return 0;
}
unsafe { ffi::wxd_StyledTextCtrl_WordStartPosition(ptr, pos, only_word_chars) }
}
pub fn word_end_position(&self, pos: i32, only_word_chars: bool) -> i32 {
let ptr = self.stc_ptr();
if ptr.is_null() {
return 0;
}
unsafe { ffi::wxd_StyledTextCtrl_WordEndPosition(ptr, pos, only_word_chars) }
}
pub fn set_wrap_mode(&self, wrap_mode: WrapMode) {
let ptr = self.stc_ptr();
if ptr.is_null() {
return;
}
unsafe { ffi::wxd_StyledTextCtrl_SetWrapMode(ptr, wrap_mode.into()) };
}
pub fn get_wrap_mode(&self) -> WrapMode {
let ptr = self.stc_ptr();
if ptr.is_null() {
return WrapMode::None;
}
let mode = unsafe { ffi::wxd_StyledTextCtrl_GetWrapMode(ptr) };
WrapMode::from(mode)
}
}
impl WxWidget for StyledTextCtrl {
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 StyledTextCtrl {
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
}
}
impl crate::event::WindowEvents for StyledTextCtrl {}
impl crate::scrollable::WxScrollable for StyledTextCtrl {}
widget_builder!(
name: StyledTextCtrl,
parent_type: &'a dyn WxWidget,
style_type: StyledTextCtrlStyle,
fields: {},
build_impl: |slf| {
StyledTextCtrl::new_impl(
slf.parent.handle_ptr(),
slf.id,
slf.pos,
slf.size,
slf.style.bits()
)
}
);
crate::implement_widget_local_event_handlers!(
StyledTextCtrl,
StyledTextCtrlEvent,
StyledTextCtrlEventData,
Change => stc_change, EventType::STC_CHANGE,
StyleNeeded => stc_style_needed, EventType::STC_STYLENEEDED,
CharAdded => stc_char_added, EventType::STC_CHARADDED,
SavePointReached => stc_save_point_reached, EventType::STC_SAVEPOINTREACHED,
SavePointLeft => stc_save_point_left, EventType::STC_SAVEPOINTLEFT,
RoModifyAttempt => stc_ro_modify_attempt, EventType::STC_ROMODIFYATTEMPT,
DoubleClick => stc_double_click, EventType::STC_DOUBLECLICK,
UpdateUI => stc_update_ui, EventType::STC_UPDATEUI,
Modified => stc_modified, EventType::STC_MODIFIED,
MacroRecord => stc_macro_record, EventType::STC_MACRORECORD,
MarginClick => stc_margin_click, EventType::STC_MARGINCLICK,
NeedShown => stc_need_shown, EventType::STC_NEEDSHOWN,
Painted => stc_painted, EventType::STC_PAINTED,
UserListSelection => stc_user_list_selection, EventType::STC_USERLISTSELECTION,
DwellStart => stc_dwell_start, EventType::STC_DWELLSTART,
DwellEnd => stc_dwell_end, EventType::STC_DWELLEND,
StartDrag => stc_start_drag, EventType::STC_START_DRAG,
DragOver => stc_drag_over, EventType::STC_DRAG_OVER,
DoDrop => stc_do_drop, EventType::STC_DO_DROP,
Zoom => stc_zoom, EventType::STC_ZOOM,
HotspotClick => stc_hotspot_click, EventType::STC_HOTSPOT_CLICK,
HotspotDoubleClick => stc_hotspot_double_click, EventType::STC_HOTSPOT_DCLICK,
CallTipClick => stc_call_tip_click, EventType::STC_CALLTIP_CLICK,
AutoCompSelection => stc_autocomp_selection, EventType::STC_AUTOCOMP_SELECTION,
IndicatorClick => stc_indicator_click, EventType::STC_INDICATOR_CLICK,
IndicatorRelease => stc_indicator_release, EventType::STC_INDICATOR_RELEASE,
AutoCompCancelled => stc_autocomp_cancelled, EventType::STC_AUTOCOMP_CANCELLED,
AutoCompCharDeleted => stc_autocomp_char_deleted, EventType::STC_AUTOCOMP_CHAR_DELETED
);
#[cfg(feature = "xrc")]
impl crate::xrc::XrcSupport for StyledTextCtrl {
unsafe fn from_xrc_ptr(ptr: *mut ffi::wxd_Window_t) -> Self {
StyledTextCtrl {
handle: WindowHandle::new(ptr),
}
}
}