1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
use ::{_API};
use capi::sctypes::*;
use platform::{BaseWindow, OsWindow};
use host::{Host, HostHandler};
use dom::event::{EventHandler};
use eventhandler::*;
use std::rc::Rc;
pub type Flags = SCITER_CREATE_WINDOW_FLAGS;
pub use capi::scdef::{SCITER_CREATE_WINDOW_FLAGS};
pub struct Window
{
base: OsWindow,
host: Rc<Host>,
}
impl Window {
pub fn new() -> Window {
let flags = SCITER_CREATE_WINDOW_FLAGS::main_window(true);
Window::create((0,0,0,0), flags, None)
}
pub fn with_size(size: (i32, i32), flags: SCITER_CREATE_WINDOW_FLAGS) -> Window {
let (w, h) = size;
Window::create((0,0,w,h), flags, None)
}
pub fn with_rect(rect: (i32, i32, i32, i32), flags: SCITER_CREATE_WINDOW_FLAGS) -> Window {
Window::create(rect, flags, None)
}
pub fn create(rect: (i32, i32, i32, i32), flags: SCITER_CREATE_WINDOW_FLAGS, parent: Option<HWINDOW>) -> Window {
let mut base = OsWindow::new();
let hwnd = base.create(rect, flags as UINT, parent.unwrap_or(0 as HWINDOW));
assert!(!hwnd.is_null());
let wnd = Window { base: base, host: Rc::new(Host::attach(hwnd))};
return wnd;
}
pub fn attach(hwnd: HWINDOW) -> Window {
assert!( hwnd.is_null() == false );
Window { base: OsWindow::from(hwnd), host: Rc::new(Host::attach(hwnd)) }
}
pub fn get_host(&self) -> Rc<Host> {
self.host.clone()
}
pub fn sciter_handler<T: HostHandler + Sized>(&mut self, handler: T) {
self.host.setup_callback(self.base.get_hwnd(), handler);
}
pub fn event_handler<T: EventHandler>(&mut self, handler: T) {
let boxed = Box::new( WindowHandler { hwnd: self.base.get_hwnd(), handler: handler } );
let ptr = Box::into_raw(boxed);
(_API.SciterWindowAttachEventHandler)(self.base.get_hwnd(), _event_handler_window_proc::<T>, ptr as LPVOID, ::dom::event::default_events() as UINT);
}
pub fn load_file(&mut self, uri: &str) {
self.host.load_file(uri)
}
pub fn load_html(&mut self, html: &[u8], uri: Option<&str>) {
self.host.load_html(html, uri)
}
pub fn get_hwnd(&self) -> HWINDOW {
self.base.get_hwnd()
}
pub fn collapse(&self, hide: bool) {
self.base.collapse(hide)
}
pub fn expand(&self, maximize: bool) {
self.base.expand(maximize)
}
pub fn dismiss(&self) {
self.base.dismiss()
}
pub fn set_title(&mut self, title: &str) {
self.base.set_title(title)
}
pub fn get_title(&self) -> String {
self.base.get_title()
}
pub fn run_app(&self, show_window: bool) {
if show_window {
self.base.expand(false);
}
self.base.run_app();
}
pub fn quit_app(&self) {
self.base.quit_app()
}
}