#![doc(html_logo_url = "https://sciter.com/screenshots/slide-sciter-osx.png",
html_favicon_url = "https://sciter.com/wp-content/themes/sciter/!images/favicon.ico")]
#![cfg_attr(feature = "cargo-clippy", allow(needless_return, let_and_return))]
#[cfg(target_os="macos")]
#[macro_use] extern crate objc;
#[macro_use] extern crate lazy_static;
#[macro_use] mod macros;
mod capi;
pub use capi::scdom::{HELEMENT};
pub use capi::scdef::{SCITER_RT_OPTIONS, GFX_LAYER};
mod platform;
mod eventhandler;
pub mod dom;
pub mod host;
pub mod types;
pub mod utf;
pub mod value;
pub mod video;
pub mod window;
pub use dom::Element;
pub use dom::event::EventHandler;
pub use host::{Archive, Host, HostHandler};
pub use value::{Value, FromValue};
pub use window::Window;
pub type WindowBuilder = window::Builder;
pub use capi::scapi::{ISciterAPI};
#[cfg(windows)]
mod ext {
#![allow(non_snake_case, non_camel_case_types)]
use capi::scapi::{ISciterAPI};
use capi::sctypes::{LPCSTR, LPCVOID, UINT};
type SciterAPI_ptr = extern "system" fn () -> *const ISciterAPI;
extern "system"
{
fn LoadLibraryA(lpFileName: LPCSTR) -> LPCVOID;
fn GetProcAddress(hModule: LPCVOID, lpProcName: LPCSTR) -> LPCVOID;
fn GetLastError() -> UINT;
}
pub unsafe fn SciterAPI() -> *const ISciterAPI {
let dll = LoadLibraryA(b"sciter.dll\0".as_ptr() as LPCSTR);
let err = GetLastError();
if dll.is_null() {
let msg = "Please verify that Sciter SDK is installed and its binaries (SDK/bin, bin.osx or bin.gtk) available in the PATH.";
panic!("fatal: '{}' was not found in PATH (Error {})\n {}", "sciter.dll", err, msg);
}
let func = GetProcAddress(dll, b"SciterAPI\0".as_ptr() as LPCSTR);
if func.is_null() {
panic!("Where is \"SciterAPI\"? It is expected to be in sciter.dll.");
}
let get_api: SciterAPI_ptr = ::std::mem::transmute(func);
return get_api();
}
}
#[cfg(target_os="linux")]
mod ext {
#[link(name="sciter-gtk")]
extern "system" { pub fn SciterAPI() -> *const ::capi::scapi::ISciterAPI; }
}
#[cfg(all(target_os="macos", target_arch="x86_64"))]
mod ext {
#[link(name="sciter-osx-64", kind = "dylib")]
extern "system" { pub fn SciterAPI() -> *const ::capi::scapi::ISciterAPI; }
}
#[allow(non_snake_case)]
#[doc(hidden)]
pub fn SciterAPI<'a>() -> &'a ISciterAPI {
let ap = unsafe {
let p = ext::SciterAPI();
&*p
};
return ap;
}
lazy_static! {
static ref _API: &'static ISciterAPI = { SciterAPI() };
}
pub fn version_num() -> u32 {
let v1 = (_API.SciterVersion)(true);
let v2 = (_API.SciterVersion)(false);
let num = ((v1 >> 16) << 24) | ((v1 & 0xFFFF) << 16) | ((v2 >> 16) << 8) | (v2 & 0xFFFF);
return num;
}
pub fn version() -> String {
let v1 = (_API.SciterVersion)(true);
let v2 = (_API.SciterVersion)(false);
let num = [v1 >> 16, v1 & 0xFFFF, v2 >> 16, v2 & 0xFFFF];
let version = format!("{}.{}.{}.{}", num[0], num[1], num[2], num[3]);
return version;
}
pub enum RuntimeOptions<'a> {
ConnectionTimeout(u32),
OnHttpsError(u8),
GpuBlacklist(&'a str),
ScriptFeatures(u8),
GfxLayer(GFX_LAYER),
DebugMode(bool),
UxTheming(bool),
}
pub fn set_options(options: RuntimeOptions) -> std::result::Result<(), ()> {
use RuntimeOptions::*;
use SCITER_RT_OPTIONS::*;
let (option, value) = match options {
ConnectionTimeout(ms) => (SCITER_CONNECTION_TIMEOUT, ms as usize),
OnHttpsError(behavior) => (SCITER_HTTPS_ERROR, behavior as usize),
GpuBlacklist(json) => (SCITER_SET_GPU_BLACKLIST, json.as_bytes().as_ptr() as usize),
ScriptFeatures(mask) => (SCITER_SET_SCRIPT_RUNTIME_FEATURES, mask as usize),
GfxLayer(backend) => (SCITER_SET_GFX_LAYER, backend as usize),
DebugMode(enable) => (SCITER_SET_DEBUG_MODE, enable as usize),
UxTheming(enable) => (SCITER_SET_UX_THEMING, enable as usize),
};
let ok = (_API.SciterSetOption)(std::ptr::null_mut(), option, value);
if ok != 0 {
Ok(())
} else {
Err(())
}
}
#[deprecated(since = "0.5.40", note = "please use `sciter::set_options()` instead.")]
pub fn set_option(option: SCITER_RT_OPTIONS, value: usize) -> std::result::Result<(), ()> {
let ok = (_API.SciterSetOption)(std::ptr::null_mut(), option, value);
if ok != 0 {
Ok(())
} else {
Err(())
}
}