sciter/capi/
scbehavior.rs

1//! C interface for behaviors support (a.k.a windowless controls).
2
3#![allow(non_camel_case_types, non_snake_case)]
4#![allow(dead_code)]
5
6use capi::sctypes::*;
7use capi::scdom::*;
8use capi::scvalue::{VALUE};
9use capi::scgraphics::{HGFX};
10use capi::scom::{som_asset_t, som_passport_t};
11
12#[repr(C)]
13pub struct BEHAVIOR_EVENT_PARAMS
14{
15	/// Behavior event code. See [`BEHAVIOR_EVENTS`](enum.BEHAVIOR_EVENTS.html).
16	pub cmd: UINT,
17
18	/// Target element handler.
19	pub heTarget: HELEMENT,
20
21	/// Source element.
22	pub he: HELEMENT,
23
24	/// UI action causing change.
25	pub reason: UINT_PTR,
26
27	/// Auxiliary data accompanied with the event.
28	pub data: VALUE,
29
30	/// Name of the custom event (when `cmd` is [`BEHAVIOR_EVENTS::CUSTOM`](enum.BEHAVIOR_EVENTS.html#variant.CUSTOM)).
31	/// Since 4.2.8.
32	pub name: LPCWSTR,
33}
34
35
36#[repr(C)]
37#[derive(Copy, Clone)]
38#[derive(Debug, PartialOrd, PartialEq)]
39pub enum INITIALIZATION_EVENTS
40{
41	BEHAVIOR_DETACH = 0,
42	BEHAVIOR_ATTACH = 1,
43}
44
45#[repr(C)]
46pub struct INITIALIZATION_PARAMS
47{
48	pub cmd: INITIALIZATION_EVENTS,
49}
50
51#[repr(C)]
52#[derive(Copy, Clone)]
53#[derive(Debug, PartialOrd, PartialEq)]
54pub enum SOM_EVENTS
55{
56	SOM_GET_PASSPORT = 0,
57	SOM_GET_ASSET = 1,
58}
59
60#[repr(C)]
61pub union SOM_PARAMS_DATA
62{
63	pub asset: *const som_asset_t,
64	pub passport: *const som_passport_t,
65}
66
67#[repr(C)]
68pub struct SOM_PARAMS
69{
70	pub cmd: SOM_EVENTS,
71	pub result: SOM_PARAMS_DATA,
72}
73
74/// Identifiers of methods currently supported by intrinsic behaviors.
75#[repr(C)]
76#[derive(Debug)]
77pub enum BEHAVIOR_METHOD_IDENTIFIERS {
78  /// Raise a click event.
79  DO_CLICK = 1,
80
81  /// `IS_EMPTY_PARAMS::is_empty` reflects the `:empty` state of the element.
82  IS_EMPTY = 0xFC,
83
84  /// `VALUE_PARAMS`
85  GET_VALUE = 0xFD,
86  /// `VALUE_PARAMS`
87  SET_VALUE = 0xFE,
88
89  /// User method identifier used in custom behaviors.
90  ///
91  /// All custom event codes shall be greater than this number.
92  /// All codes below this will be used solely by application - Sciter will not intrepret it
93  /// and will do just dispatching. To send event notifications with  these codes use
94  /// `SciterCallBehaviorMethod` API.
95  FIRST_APPLICATION_METHOD_ID = 0x100,
96}
97
98/// Method arguments used in `SciterCallBehaviorMethod()` or `HANDLE_METHOD_CALL`.
99#[repr(C)]
100pub struct METHOD_PARAMS {
101  /// [`BEHAVIOR_METHOD_IDENTIFIERS`](enum.BEHAVIOR_METHOD_IDENTIFIERS.html) or user identifiers.
102  pub method: UINT,
103}
104
105#[repr(C)]
106pub struct IS_EMPTY_PARAMS {
107  pub method: UINT,
108  pub is_empty: UINT,
109}
110
111#[repr(C)]
112pub struct VALUE_PARAMS {
113  pub method: UINT,
114  pub value: VALUE,
115}
116
117#[repr(C)]
118pub struct SCRIPTING_METHOD_PARAMS
119{
120	pub name: LPCSTR,
121	pub argv: *const VALUE,
122	pub argc: UINT,
123	pub result: VALUE,
124}
125
126#[repr(C)]
127pub struct TIMER_PARAMS
128{
129	pub timerId: UINT_PTR,
130}
131
132#[repr(C)]
133pub struct DRAW_PARAMS {
134	/// Element layer to draw.
135	pub layer: DRAW_EVENTS,
136
137	/// Graphics context.
138	pub gfx: HGFX,
139
140	/// Element area.
141	pub area: RECT,
142
143	/// Zero at the moment.
144	pub reserved: UINT,
145}
146
147/// Layer to draw.
148#[repr(C)]
149#[derive(Copy, Clone)]
150#[derive(Debug, PartialEq)]
151pub enum DRAW_EVENTS {
152	DRAW_BACKGROUND = 0,
153	DRAW_CONTENT,
154	DRAW_FOREGROUND,
155	/// Note: since 4.2.3.
156	DRAW_OUTLINE,
157}
158
159
160/// Event groups for subscription.
161#[repr(C)]
162#[derive(Copy, Clone)]
163#[derive(Debug, PartialOrd, PartialEq)]
164pub enum EVENT_GROUPS
165{ /// Attached/detached.
166	HANDLE_INITIALIZATION = 0x0000,
167	/// Mouse events.
168	HANDLE_MOUSE = 0x0001,
169	/// Key events.
170	HANDLE_KEY = 0x0002,
171	/// Focus events, if this flag is set it also means that element it attached to is focusable.
172	HANDLE_FOCUS = 0x0004,
173	/// Scroll events.
174	HANDLE_SCROLL = 0x0008,
175	/// Timer event.
176	HANDLE_TIMER = 0x0010,
177	/// Size changed event.
178	HANDLE_SIZE = 0x0020,
179	/// Drawing request (event).
180	HANDLE_DRAW = 0x0040,
181	/// Requested data has been delivered.
182	HANDLE_DATA_ARRIVED = 0x080,
183
184	/// Logical, synthetic events:
185  /// `BUTTON_CLICK`, `HYPERLINK_CLICK`, etc.,
186	/// a.k.a. notifications from intrinsic behaviors.
187	HANDLE_BEHAVIOR_EVENT        = 0x0100,
188	 /// Behavior specific methods.
189	HANDLE_METHOD_CALL           = 0x0200,
190	/// Behavior specific methods.
191	HANDLE_SCRIPTING_METHOD_CALL = 0x0400,
192
193	/// Behavior specific methods using direct `tiscript::value`'s.
194	#[deprecated(since="Sciter 4.4.3.24", note="TIScript native API is gone, use SOM instead.")]
195	HANDLE_TISCRIPT_METHOD_CALL  = 0x0800,
196
197	/// System drag-n-drop.
198	HANDLE_EXCHANGE              = 0x1000,
199	/// Touch input events.
200	HANDLE_GESTURE               = 0x2000,
201	/// SOM passport and asset requests.
202	HANDLE_SOM                   = 0x8000,
203
204	/// All of them.
205	HANDLE_ALL                   = 0xFFFF,
206
207	/// Special value for getting subscription flags.
208	SUBSCRIPTIONS_REQUEST        = -1,
209}
210
211#[repr(C)]
212#[derive(Copy, Clone)]
213#[derive(Debug, PartialOrd, PartialEq)]
214/// Event propagation schema.
215pub enum PHASE_MASK
216{
217	/// Bubbling phase – direction: from a child element to all its containers.
218	BUBBLING 				= 0,
219	/// Sinking phase – direction: from containers to target child element.
220	SINKING  				= 0x0_8000,
221	/// Bubbling event consumed by some element.
222	BUBBLING_HANDLED= 0x1_0000,
223	/// Sinking event consumed by some child.
224	SINKING_HANDLED = 0x1_8000,
225}
226
227#[repr(C)]
228#[derive(Copy, Clone)]
229#[derive(Debug, PartialOrd, PartialEq)]
230/// Mouse buttons.
231pub enum MOUSE_BUTTONS
232{
233	NONE = 0,
234
235	/// Left button.
236	MAIN = 1,
237	/// Right button.
238	PROP = 2,
239	/// Middle button.
240	MIDDLE = 3,
241}
242
243#[repr(C)]
244#[derive(Copy, Clone)]
245#[derive(Debug, Default, PartialOrd, PartialEq)]
246/// Keyboard modifier buttons state.
247pub struct KEYBOARD_STATES(u32);
248
249impl KEYBOARD_STATES {
250	pub const CONTROL_KEY_PRESSED: u32 = 0x01;
251	pub const SHIFT_KEY_PRESSED: u32 = 0x02;
252	pub const ALT_KEY_PRESSED: u32 = 0x04;
253	pub const RIGHT_SHIFT_KEY_PRESSED: u32 = 0x08;
254	pub const CMD_KEY_PRESSED: u32 = 0x10;
255}
256
257impl std::convert::From<u32> for KEYBOARD_STATES {
258	fn from(u: u32) -> Self {
259		Self(u)
260	}
261}
262
263#[repr(C)]
264#[derive(Copy, Clone)]
265#[derive(Debug, PartialOrd, PartialEq)]
266/// Keyboard input events.
267pub enum KEY_EVENTS
268{
269	KEY_DOWN = 0,
270	KEY_UP,
271	KEY_CHAR,
272}
273
274#[repr(C)]
275#[derive(Copy, Clone)]
276#[derive(Debug, PartialOrd, PartialEq)]
277/// Mouse events.
278pub enum MOUSE_EVENTS
279{
280	MOUSE_ENTER = 0,
281	MOUSE_LEAVE,
282	MOUSE_MOVE,
283	MOUSE_UP,
284	MOUSE_DOWN,
285	MOUSE_DCLICK,
286	MOUSE_WHEEL,
287	/// mouse pressed ticks
288	MOUSE_TICK,
289	/// mouse stay idle for some time
290	MOUSE_IDLE,
291
292	/// item dropped, target is that dropped item
293	DROP        = 9,
294	/// drag arrived to the target element that is one of current drop targets.
295	DRAG_ENTER  = 0xA,
296	/// drag left one of current drop targets. target is the drop target element.
297	DRAG_LEAVE  = 0xB,
298	/// drag src notification before drag start. To cancel - return true from handler.
299	DRAG_REQUEST = 0xC,
300
301	/// mouse triple click.
302	MOUSE_TCLICK = 0xF,
303
304	/// mouse click event
305	MOUSE_CLICK = 0xFF,
306
307	/// This flag is `OR`ed with `MOUSE_ENTER..MOUSE_DOWN` codes if dragging operation is in effect.
308	/// E.g. event `DRAGGING | MOUSE_MOVE` is sent to underlying DOM elements while dragging.
309	DRAGGING = 0x100,
310}
311
312#[repr(C)]
313#[derive(Copy, Clone)]
314#[derive(Debug, PartialOrd, PartialEq)]
315#[allow(missing_docs)]
316/// General event source triggers
317pub enum CLICK_REASON
318{
319  /// By mouse button.
320	BY_MOUSE_CLICK,
321  /// By keyboard (e.g. spacebar).
322	BY_KEY_CLICK,
323  /// Synthesized, by code.
324	SYNTHESIZED,
325  /// Icon click, e.g. arrow icon on drop-down select.
326	BY_MOUSE_ON_ICON,
327}
328
329#[repr(C)]
330#[derive(Copy, Clone)]
331#[derive(Debug, PartialOrd, PartialEq)]
332/// Edit control change trigger.
333pub enum EDIT_CHANGED_REASON
334{
335	/// Single char insertion.
336	BY_INS_CHAR,
337	/// Character range insertion, clipboard.
338	BY_INS_CHARS,
339	/// Single char deletion.
340	BY_DEL_CHAR,
341	/// Character range (selection) deletion.
342	BY_DEL_CHARS,
343	/// Undo/redo.
344	BY_UNDO_REDO,
345	/// Single char insertion, previous character was inserted in previous position.
346	CHANGE_BY_INS_CONSECUTIVE_CHAR,
347	/// Single char removal, previous character was removed in previous position
348	CHANGE_BY_DEL_CONSECUTIVE_CHAR,
349	CHANGE_BY_CODE,
350}
351
352#[repr(C)]
353#[derive(Copy, Clone)]
354#[derive(Debug, PartialOrd, PartialEq)]
355/// Behavior event codes.
356pub enum BEHAVIOR_EVENTS
357{
358	/// click on button
359	BUTTON_CLICK = 0,
360	/// mouse down or key down in button
361	BUTTON_PRESS,
362	/// checkbox/radio/slider changed its state/value
363	BUTTON_STATE_CHANGED,
364	/// before text change
365	EDIT_VALUE_CHANGING,
366	/// after text change
367	EDIT_VALUE_CHANGED,
368	/// selection in `<select>` is changed
369	SELECT_SELECTION_CHANGED,
370	// node in select expanded/collapsed, heTarget is the node - OBSOLETE since 4.4.4.9
371	// SELECT_STATE_CHANGED,
372	/// value of `<select>` is changed
373	SELECT_VALUE_CHANGED,
374
375	/// request to show popup just received,
376	///     here DOM of popup element can be modifed.
377	POPUP_REQUEST,
378
379	/// popup element has been measured and ready to be shown on screen,
380	///     here you can use functions like `ScrollToView`.
381	POPUP_READY,
382
383	/// popup element is closed,
384	///     here DOM of popup element can be modifed again - e.g. some items can be removed to free memory.
385	POPUP_DISMISSED,
386
387	/// menu item activated by mouse hover or by keyboard,
388	MENU_ITEM_ACTIVE,
389
390	/// menu item click,
391	///   BEHAVIOR_EVENT_PARAMS structure layout
392	///   BEHAVIOR_EVENT_PARAMS.cmd - MENU_ITEM_CLICK/MENU_ITEM_ACTIVE
393	///   BEHAVIOR_EVENT_PARAMS.heTarget - owner(anchor) of the menu
394	///   BEHAVIOR_EVENT_PARAMS.he - the menu item, presumably `<li>` element
395	///   BEHAVIOR_EVENT_PARAMS.reason - BY_MOUSE_CLICK | BY_KEY_CLICK
396	MENU_ITEM_CLICK,
397
398
399
400
401
402
403
404	/// "right-click", BEHAVIOR_EVENT_PARAMS::he is current popup menu `HELEMENT` being processed or `NULL`.
405	/// application can provide its own `HELEMENT` here (if it is `NULL`) or modify current menu element.
406	CONTEXT_MENU_REQUEST = 0x10,
407
408
409	/// broadcast notification, sent to all elements of some container being shown or hidden
410	VISIUAL_STATUS_CHANGED,
411	/// broadcast notification, sent to all elements of some container that got new value of `:disabled` state
412	DISABLED_STATUS_CHANGED,
413
414	/// popup is about to be closed
415	POPUP_DISMISSING,
416
417	/// content has been changed, is posted to the element that gets content changed,  reason is combination of `CONTENT_CHANGE_BITS`.
418	/// `target == NULL` means the window got new document and this event is dispatched only to the window.
419	CONTENT_CHANGED = 0x15,
420
421
422	/// generic click
423	CLICK = 0x16,
424	/// generic change
425	CHANGE = 0x17,
426
427	/// media changed (screen resolution, number of displays, etc.)
428	MEDIA_CHANGED = 0x18,
429	/// input language has changed, data is iso lang-country string
430	INPUT_LANGUAGE_CHANGED = 0x19,
431	/// editable content has changed
432	CONTENT_MODIFIED = 0x1A,
433	/// a broadcast notification being posted to all elements of some container
434	/// that changes its `:read-only` state.
435	READONLY_STATUS_CHANGED = 0x1B,
436	/// change in `aria-live="polite|assertive"`
437	ARIA_LIVE_AREA_CHANGED = 0x1C,
438
439	// "grey" event codes  - notfications from behaviors from this SDK
440	/// hyperlink click
441	HYPERLINK_CLICK = 0x80,
442
443	PASTE_TEXT = 0x8E,
444	PASTE_HTML = 0x8F,
445
446	/// element was collapsed, so far only `behavior:tabs` is sending these two to the panels
447	ELEMENT_COLLAPSED = 0x90,
448	/// element was expanded,
449	ELEMENT_EXPANDED,
450
451	/// activate (select) child,
452	/// used, for example, by `accesskeys` behaviors to send activation request, e.g. tab on `behavior:tabs`.
453	ACTIVATE_CHILD,
454
455	/// ui state changed, observers shall update their visual states.
456	/// is sent, for example, by `behavior:richtext` when caret position/selection has changed.
457	UI_STATE_CHANGED = 0x95,
458
459
460	/// `behavior:form` detected submission event. `BEHAVIOR_EVENT_PARAMS::data` field contains data to be posted.
461	/// `BEHAVIOR_EVENT_PARAMS::data` is of type `T_MAP` in this case key/value pairs of data that is about
462	/// to be submitted. You can modify the data or discard submission by returning true from the handler.
463	FORM_SUBMIT,
464
465
466	/// `behavior:form` detected reset event (from `button type=reset`). `BEHAVIOR_EVENT_PARAMS::data` field contains data to be reset.
467	/// `BEHAVIOR_EVENT_PARAMS::data` is of type `T_MAP` in this case key/value pairs of data that is about
468	/// to be rest. You can modify the data or discard reset by returning true from the handler.
469	FORM_RESET,
470
471
472
473	/// document in `behavior:frame` or root document is complete.
474	DOCUMENT_COMPLETE,
475
476	/// requests to `behavior:history` (commands)
477	HISTORY_PUSH,
478	HISTORY_DROP,
479	HISTORY_PRIOR,
480	HISTORY_NEXT,
481	/// `behavior:history` notification - history stack has changed
482	HISTORY_STATE_CHANGED,
483
484	/// close popup request,
485	CLOSE_POPUP,
486	/// request tooltip, `evt.source` <- is the tooltip element.
487	TOOLTIP_REQUEST,
488
489	/// animation started (`reason=1`) or ended(`reason=0`) on the element.
490	ANIMATION         = 0xA0,
491
492	/// document created, script namespace initialized. `target` -> the document
493	DOCUMENT_CREATED  = 0xC0,
494	/// document is about to be closed, to cancel closing do: `evt.data = sciter::Value("cancel")`;
495	DOCUMENT_CLOSE_REQUEST,
496	/// last notification before document removal from the DOM
497	DOCUMENT_CLOSE,
498	/// document has got DOM structure, styles and behaviors of DOM elements. Script loading run is complete at this moment.
499	DOCUMENT_READY,
500	/// document just finished parsing - has got DOM structure. This event is generated before the `DOCUMENT_READY`.
501	/// Since 4.0.3.
502	DOCUMENT_PARSED   = 0xC4,
503
504	/// `<video>` "ready" notification
505	VIDEO_INITIALIZED = 0xD1,
506	/// `<video>` playback started notification
507	VIDEO_STARTED,
508	/// `<video>` playback stoped/paused notification
509	VIDEO_STOPPED,
510	/// `<video>` request for frame source binding,
511	///   If you want to provide your own video frames source for the given target `<video>` element do the following:
512	///
513	///   1. Handle and consume this `VIDEO_BIND_RQ` request
514	///   2. You will receive second `VIDEO_BIND_RQ` request/event for the same `<video>` element
515	///      but this time with the `reason` field set to an instance of `sciter::video_destination` interface.
516	///   3. `add_ref()` it and store it, for example, in a worker thread producing video frames.
517	///   4. call `sciter::video_destination::start_streaming(...)` providing needed parameters
518	///      call `sciter::video_destination::render_frame(...)` as soon as they are available
519	///      call `sciter::video_destination::stop_streaming()` to stop the rendering (a.k.a. end of movie reached)
520	VIDEO_BIND_RQ,
521
522
523	/// `behavior:pager` starts pagination
524	PAGINATION_STARTS  = 0xE0,
525	/// `behavior:pager` paginated page no, reason -> page no
526	PAGINATION_PAGE,
527	/// `behavior:pager` end pagination, reason -> total pages
528	PAGINATION_ENDS,
529
530	/// event with custom name.
531	/// Since 4.2.8.
532	CUSTOM						 = 0xF0,
533
534	/// SSX, delayed mount_component
535	MOUNT_COMPONENT    = 0xF1,
536
537	/// all custom event codes shall be greater than this number. All codes below this will be used
538	/// solely by application - Sciter will not intrepret it and will do just dispatching.
539	/// To send event notifications with  these codes use `SciterSend`/`PostEvent` API.
540	FIRST_APPLICATION_EVENT_CODE = 0x100,
541
542}
543
544
545impl ::std::ops::BitOr for EVENT_GROUPS {
546  type Output = EVENT_GROUPS;
547  fn bitor(self, rhs: Self::Output) -> Self::Output {
548    let rn = (self as UINT) | (rhs as UINT);
549    unsafe { ::std::mem::transmute(rn) }
550  }
551}