sciter/capi/scdom.rs
1//! DOM access methods, C interface.
2
3#![allow(non_camel_case_types, non_snake_case)]
4
5use capi::sctypes::*;
6
7MAKE_HANDLE!(#[doc = "Element native handle."] HELEMENT, _HELEMENT);
8MAKE_HANDLE!(#[doc = "Node native handle."] HNODE, _HNODE);
9
10#[repr(C)]
11#[derive(Debug, PartialOrd, PartialEq)]
12/// Type of the result value for Sciter DOM functions.
13pub enum SCDOM_RESULT {
14 /// Function completed successfully.
15 OK = 0,
16 /// Invalid `HWINDOW`.
17 INVALID_HWND = 1,
18 /// Invalid `HELEMENT`.
19 INVALID_HANDLE = 2,
20 /// Attempt to use `HELEMENT` which is not attached to document.
21 PASSIVE_HANDLE = 3,
22 /// Parameter is invalid, e.g. pointer is null.
23 INVALID_PARAMETER = 4,
24 /// Operation failed, e.g. invalid html passed.
25 OPERATION_FAILED = 5,
26 /// Function completed successfully, but no result (e.g. no such attribute at element).
27 OK_NOT_HANDLED = -1,
28}
29
30impl std::error::Error for SCDOM_RESULT {}
31
32impl std::fmt::Display for SCDOM_RESULT {
33 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
34 write!(f, "{:?}", self)
35 }
36}
37
38#[repr(C)]
39#[derive(Debug, PartialOrd, PartialEq)]
40/// `dom::Element.set_html()` options.
41pub enum SET_ELEMENT_HTML
42{
43 SIH_REPLACE_CONTENT = 0,
44 SIH_INSERT_AT_START = 1,
45 SIH_APPEND_AFTER_LAST = 2,
46 SOH_REPLACE = 3,
47 SOH_INSERT_BEFORE = 4,
48 SOH_INSERT_AFTER = 5,
49}
50
51/// Bounding rectangle of the element.
52#[repr(C)]
53#[derive(Debug, PartialOrd, PartialEq)]
54pub enum ELEMENT_AREAS {
55
56 /// `or` this flag if you want to get Sciter window relative coordinates,
57 /// otherwise it will use nearest windowed container e.g. popup window.
58 ROOT_RELATIVE = 0x01,
59
60 /// `or` this flag if you want to get coordinates relative to the origin of element iself.
61 SELF_RELATIVE = 0x02,
62
63 /// Position inside immediate container.
64 CONTAINER_RELATIVE = 0x03,
65
66 /// Position relative to view - Sciter window.
67 VIEW_RELATIVE = 0x04,
68
69 /// Content (inner) box.
70 CONTENT_BOX = 0x00,
71
72 /// Content + paddings.
73 PADDING_BOX = 0x10,
74
75 /// Content + paddings + border.
76 BORDER_BOX = 0x20,
77
78 /// Content + paddings + border + margins.
79 MARGIN_BOX = 0x30,
80
81 /// Relative to content origin - location of background image (if it set `no-repeat`).
82 BACK_IMAGE_AREA = 0x40,
83
84 /// Relative to content origin - location of foreground image (if it set `no-repeat`).
85 FORE_IMAGE_AREA = 0x50,
86
87 /// Scroll_area - scrollable area in content box.
88 SCROLLABLE_AREA = 0x60,
89}
90
91impl ELEMENT_AREAS {
92 /// Size of content (i.e `(0, 0, width, height)`).
93 pub fn self_content() -> u32 {
94 ELEMENT_AREAS::SELF_RELATIVE as u32
95 }
96
97 /// Size of rect (i.e `(left, top, width, height)`)
98 pub fn self_rect() -> u32 {
99 ELEMENT_AREAS::ROOT_RELATIVE as u32
100 }
101}
102
103/// Collection of states (runtime flags) of a DOM element.
104///
105/// They reflect CSS pseudo-classes that are used in selectors,
106/// e.g. `STATE_HOVER` is `:hover`, `STATE_ACTIVE` is `:active`, and so on.
107///
108/// Implements `|` and `&` bitwise operators.
109#[repr(C)]
110#[derive(Debug, PartialOrd, PartialEq)]
111pub enum ELEMENT_STATE_BITS
112{
113 /// Zero state.
114 STATE_NONE = 0x00000000,
115
116 /// Element is a link.
117 ///
118 /// E.g. `<a href`.
119 STATE_LINK = 0x00000001,
120
121 /// Mouse over the element at the moment.
122 STATE_HOVER = 0x00000002,
123 /// Element is pressed.
124 ///
125 /// Commonly used by `<button>` or `<a>` elements.
126 STATE_ACTIVE = 0x00000004,
127 /// Element is focused.
128 STATE_FOCUS = 0x00000008,
129
130 /// Element was visited.
131 ///
132 /// For example, a link that was clicked.
133 STATE_VISITED = 0x00000010,
134 /// Current (hot) item.
135 STATE_CURRENT = 0x00000020,
136 /// Element is checked (or selected).
137 STATE_CHECKED = 0x00000040,
138 /// Element is disabled.
139 STATE_DISABLED = 0x00000080,
140 /// Readonly input element.
141 STATE_READONLY = 0x00000100,
142
143 /// Expanded state - e.g. nodes in tree view.
144 ///
145 /// Mutually exclusive with `STATE_COLLAPSED`.
146 STATE_EXPANDED = 0x00000200,
147
148 /// Collapsed state - e.g. nodes in tree view.
149 ///
150 /// Mutually exclusive with `STATE_EXPANDED`.
151 STATE_COLLAPSED = 0x00000400,
152
153 /// One of fore/back images was requested but is not delivered.
154 STATE_INCOMPLETE = 0x00000800,
155 /// Is animating currently.
156 STATE_ANIMATING = 0x00001000,
157 /// Will accept focus.
158 STATE_FOCUSABLE = 0x00002000,
159
160 /// Anchor in selection (used with current in selects).
161 STATE_ANCHOR = 0x00004000,
162 /// This is a synthetic element - i.e. don't emit it's head/tail.
163 STATE_SYNTHETIC = 0x00008000,
164 /// A popup element is shown for this particular element.
165 STATE_OWNS_POPUP = 0x00010000,
166
167 /// Focus gained by tab traversal.
168 STATE_TABFOCUS = 0x00020000,
169
170 /// Element is empty.
171 ///
172 /// i.e. the element has no text content nor children nodes.
173 ///
174 /// If element has a behavior attached then the behavior is responsible for the value of this flag.
175 STATE_EMPTY = 0x00040000,
176
177 /// Busy or loading.
178 STATE_BUSY = 0x00080000,
179
180 /// Drag over the block that can accept it (so is a current drop target).
181 ///
182 /// Flag is set for the drop target block.
183 STATE_DRAG_OVER = 0x00100000,
184 /// Active drop target.
185 STATE_DROP_TARGET = 0x00200000,
186 /// Dragging/moving - the flag is set for the moving block.
187 STATE_MOVING = 0x00400000,
188 /// Dragging/copying - the flag is set for the copying block.
189 STATE_COPYING = 0x00800000,
190 /// Element that is a drag source.
191 STATE_DRAG_SOURCE = 0x01000000,
192 /// Element is drop marker.
193 STATE_DROP_MARKER = 0x02000000,
194
195 /// Close to `STATE_ACTIVE` but has wider life span.
196 ///
197 /// E.g. in `MOUSE_UP` it is still on;
198 /// so behavior can check it in `MOUSE_UP` to discover the `CLICK` condition.
199 STATE_PRESSED = 0x04000000,
200
201 /// This element is out of flow.
202 STATE_POPUP = 0x08000000,
203
204 /// The element or one of its containers has `dir=ltr` declared.
205 STATE_IS_LTR = 0x10000000,
206 /// The element or one of its containers has `dir=rtl` declared.
207 STATE_IS_RTL = 0x20000000,
208
209 /// Element is ready (behavior has finished initialization).
210 STATE_READY = 0x40000000,
211}
212
213/// Flags can be OR'ed.
214impl ::std::ops::BitOr for ELEMENT_STATE_BITS {
215 type Output = ELEMENT_STATE_BITS;
216 fn bitor(self, rhs: Self::Output) -> Self::Output {
217 let rn = (self as UINT) | (rhs as UINT);
218 unsafe { ::std::mem::transmute(rn) }
219 }
220}
221
222/// Flags can be AND'ed.
223impl ::std::ops::BitAnd for ELEMENT_STATE_BITS {
224 type Output = ELEMENT_STATE_BITS;
225 fn bitand(self, rhs: Self::Output) -> Self::Output {
226 let rn = (self as UINT) & (rhs as UINT);
227 unsafe { ::std::mem::transmute(rn) }
228 }
229}
230
231pub type SciterElementCallback = extern "system" fn (he: HELEMENT, param: LPVOID) -> BOOL;
232
233pub type ELEMENT_COMPARATOR = extern "system" fn (he1: HELEMENT, he2: HELEMENT, param: LPVOID) -> INT;