Sciter: F:/hsmile5/sdk/include/sciter-x-behavior.h Source File

Sciter  3.3.2.5
Sciter API
sciter-x-behavior.h
Go to the documentation of this file.
1 /*
2  * The Sciter Engine of Terra Informatica Software, Inc.
3  * http://sciter.com
4  *
5  * The code and information provided "as-is" without
6  * warranty of any kind, either expressed or implied.
7  *
8  * (C) 2003-2015, Terra Informatica Software, Inc.
9  */
10 
11 /*
12  * Behaviors support (a.k.a windowless controls)
13  */
14 
15 #ifndef __sciter_x_behavior_h__
16 #define __sciter_x_behavior_h__
17 
22 #include "sciter-x-types.h"
23 #include "sciter-x-dom.h"
24 #include "sciter-x-value.h"
25 #include "sciter-x-graphics.h"
26 
27 #pragma pack(push,8)
28 
31   enum EVENT_GROUPS
32  {
33   HANDLE_INITIALIZATION = 0x0000,
34   HANDLE_MOUSE = 0x0001,
35   HANDLE_KEY = 0x0002,
36   HANDLE_FOCUS = 0x0004,
37   HANDLE_SCROLL = 0x0008,
38   HANDLE_TIMER = 0x0010,
39   HANDLE_SIZE = 0x0020,
40   HANDLE_DRAW = 0x0040,
41   HANDLE_DATA_ARRIVED = 0x080,
42   HANDLE_BEHAVIOR_EVENT = 0x0100,
45   HANDLE_METHOD_CALL = 0x0200,
46   HANDLE_SCRIPTING_METHOD_CALL = 0x0400,
47   HANDLE_TISCRIPT_METHOD_CALL = 0x0800,
49   HANDLE_EXCHANGE = 0x1000,
50   HANDLE_GESTURE = 0x2000,
52   HANDLE_ALL = 0xFFFF, /* all of them */
53 
54   SUBSCRIPTIONS_REQUEST = 0xFFFFFFFF,
55  };
56 
65  typedef BOOL SC_CALLBACK ElementEventProc(LPVOID tag, HELEMENT he, UINT evtg, LPVOID prms );
66  typedef ElementEventProc * LPElementEventProc;
67 // signature of the function exported from external behavior/dll.
68  typedef BOOL SC_CALLBACK SciterBehaviorFactory( LPCSTR, HELEMENT, LPElementEventProc*, LPVOID* );
69 
70   enum PHASE_MASK
71  {
72   BUBBLING = 0, // bubbling (emersion) phase
73   SINKING = 0x8000, // capture (immersion) phase, this flag is or'ed with EVENTS codes below
74   HANDLED = 0x10000
75  // see: http://www.w3.org/TR/xml-events/Overview.html#s_intro
76  };
77 
78   enum MOUSE_BUTTONS
79  {
80   MAIN_MOUSE_BUTTON = 1, //aka left button
81   PROP_MOUSE_BUTTON = 2, //aka right button
82   MIDDLE_MOUSE_BUTTON = 4,
83  };
84 
85   enum KEYBOARD_STATES
86  {
87   CONTROL_KEY_PRESSED = 0x1,
88   SHIFT_KEY_PRESSED = 0x2,
89   ALT_KEY_PRESSED = 0x4
90  };
91 
92 // parameters of evtg == HANDLE_INITIALIZATION
93 
94   enum INITIALIZATION_EVENTS
95  {
96   BEHAVIOR_DETACH = 0,
97   BEHAVIOR_ATTACH = 1
98  };
99 
100   struct INITIALIZATION_PARAMS
101  {
102   UINT cmd; // INITIALIZATION_EVENTS
103  };
104 
105   enum DRAGGING_TYPE
106  {
107   NO_DRAGGING,
108   DRAGGING_MOVE,
109   DRAGGING_COPY,
110  };
111 
112 // parameters of evtg == HANDLE_MOUSE
113 
114   enum MOUSE_EVENTS
115  {
116   MOUSE_ENTER = 0,
117   MOUSE_LEAVE,
118   MOUSE_MOVE,
119   MOUSE_UP,
120   MOUSE_DOWN,
121   MOUSE_DCLICK,
122   MOUSE_WHEEL,
123   MOUSE_TICK, // mouse pressed ticks
124   MOUSE_IDLE, // mouse stay idle for some time
125 
126   DROP = 9, // item dropped, target is that dropped item
127   DRAG_ENTER = 0xA, // drag arrived to the target element that is one of current drop targets.
128   DRAG_LEAVE = 0xB, // drag left one of current drop targets. target is the drop target element.
129   DRAG_REQUEST = 0xC, // drag src notification before drag start. To cancel - return true from handler.
130 
131   MOUSE_CLICK = 0xFF, // mouse click event
132 
133   DRAGGING = 0x100, // This flag is 'ORed' with MOUSE_ENTER..MOUSE_DOWN codes if dragging operation is in effect.
134  // E.g. event DRAGGING | MOUSE_MOVE is sent to underlying DOM elements while dragging.
135 
136  };
137 
138   struct MOUSE_PARAMS
139  {
140   UINT cmd; // MOUSE_EVENTS
141   HELEMENT target; // target element
142   POINT pos; // position of cursor, element relative
143   POINT pos_view; // position of cursor, view relative
144   UINT button_state; // MOUSE_BUTTONS
145   UINT alt_state; // KEYBOARD_STATES
146   UINT cursor_type; // CURSOR_TYPE to set, see CURSOR_TYPE
147   BOOL is_on_icon; // mouse is over icon (foreground-image, foreground-repeat:no-repeat)
148 
149   HELEMENT dragging; // element that is being dragged over, this field is not NULL if (cmd & DRAGGING) != 0
150   UINT dragging_mode;// see DRAGGING_TYPE.
151 
152  };
153 
154   enum CURSOR_TYPE
155  {
156   CURSOR_ARROW, //0
157   CURSOR_IBEAM, //1
158   CURSOR_WAIT, //2
159   CURSOR_CROSS, //3
160   CURSOR_UPARROW, //4
161   CURSOR_SIZENWSE, //5
162   CURSOR_SIZENESW, //6
163   CURSOR_SIZEWE, //7
164   CURSOR_SIZENS, //8
165   CURSOR_SIZEALL, //9
166   CURSOR_NO, //10
167   CURSOR_APPSTARTING, //11
168   CURSOR_HELP, //12
169   CURSOR_HAND, //13
170   CURSOR_DRAG_MOVE, //14
171   CURSOR_DRAG_COPY, //15
172  };
173 
174 
175 // parameters of evtg == HANDLE_KEY
176 
177   enum KEY_EVENTS
178  {
179   KEY_DOWN = 0,
180   KEY_UP,
181   KEY_CHAR
182  };
183 
184   struct KEY_PARAMS
185  {
186   UINT cmd; // KEY_EVENTS
187   HELEMENT target; // target element
188   UINT key_code; // key scan code, or character unicode for KEY_CHAR
189   UINT alt_state; // KEYBOARD_STATES
190  };
191 
192 // parameters of evtg == HANDLE_FOCUS
193 
194   enum FOCUS_EVENTS
195  {
196   FOCUS_LOST = 0, // non-bubbling event, target is new focus element
197   FOCUS_GOT = 1, // non-bubbling event, target is old focus element
198   FOCUS_IN = 2, // bubbling event/notification, target is an element that got focus
199   FOCUS_OUT = 3, // bubbling event/notification, target is an element that lost focus
200  };
201 
202   struct FOCUS_PARAMS
203  {
204   UINT cmd; // FOCUS_EVENTS
205   HELEMENT target; // target element, for FOCUS_LOST it is a handle of new focus element
206  // and for FOCUS_GOT it is a handle of old focus element, can be NULL
207   BOOL by_mouse_click; // true if focus is being set by mouse click
208   BOOL cancel; // in FOCUS_LOST phase setting this field to true will cancel transfer focus from old element to the new one.
209  };
210 
211 // parameters of evtg == HANDLE_SCROLL
212 
213   enum SCROLL_EVENTS
214  {
215   SCROLL_HOME = 0,
216   SCROLL_END,
217   SCROLL_STEP_PLUS,
218   SCROLL_STEP_MINUS,
219   SCROLL_PAGE_PLUS,
220   SCROLL_PAGE_MINUS,
221   SCROLL_POS,
222   SCROLL_SLIDER_RELEASED,
223   SCROLL_CORNER_PRESSED,
224   SCROLL_CORNER_RELEASED,
225  };
226 
227   struct SCROLL_PARAMS
228  {
229   UINT cmd; // SCROLL_EVENTS
230   HELEMENT target; // target element
231   INT pos; // scroll position if SCROLL_POS
232   BOOL vertical; // true if from vertical scrollbar
233  };
234 
235   enum GESTURE_CMD
236  {
237   GESTURE_REQUEST = 0, // return true and fill flags if it will handle gestures.
238   GESTURE_ZOOM, // The zoom gesture.
239   GESTURE_PAN, // The pan gesture.
240   GESTURE_ROTATE, // The rotation gesture.
241   GESTURE_TAP1, // The tap gesture.
242   GESTURE_TAP2, // The two-finger tap gesture.
243  };
244   enum GESTURE_STATE
245  {
246   GESTURE_STATE_BEGIN = 1, // starts
247   GESTURE_STATE_INERTIA = 2, // events generated by inertia processor
248   GESTURE_STATE_END = 4, // end, last event of the gesture sequence
249  };
250 
251   enum GESTURE_TYPE_FLAGS // requested
252  {
253   GESTURE_FLAG_ZOOM = 0x0001,
254   GESTURE_FLAG_ROTATE = 0x0002,
255   GESTURE_FLAG_PAN_VERTICAL = 0x0004,
256   GESTURE_FLAG_PAN_HORIZONTAL = 0x0008,
257   GESTURE_FLAG_TAP1 = 0x0010, // press & tap
258   GESTURE_FLAG_TAP2 = 0x0020, // two fingers tap
259 
260   GESTURE_FLAG_PAN_WITH_GUTTER = 0x4000, // PAN_VERTICAL and PAN_HORIZONTAL modifiers
261   GESTURE_FLAG_PAN_WITH_INERTIA = 0x8000, //
262   GESTURE_FLAGS_ALL = 0xFFFF, //
263  };
264 
265   struct GESTURE_PARAMS
266  {
267   UINT cmd; // GESTURE_EVENTS
268   HELEMENT target; // target element
269   POINT pos; // position of cursor, element relative
270   POINT pos_view; // position of cursor, view relative
271   UINT flags; // for GESTURE_REQUEST combination of GESTURE_FLAGs.
272  // for others it is a combination of GESTURE_STATe's
273   UINT delta_time; // period of time from previous event.
274   SIZE delta_xy; // for GESTURE_PAN it is a direction vector
275   double delta_v; // for GESTURE_ROTATE - delta angle (radians)
276  // for GESTURE_ZOOM - zoom value, is less or greater than 1.0
277  };
278 
279   enum DRAW_EVENTS
280  {
281   DRAW_BACKGROUND = 0,
282   DRAW_CONTENT = 1,
283   DRAW_FOREGROUND = 2,
284  };
285 
286   typedef struct SCITER_GRAPHICS SCITER_GRAPHICS;
287 
288   struct DRAW_PARAMS
289  {
290   UINT cmd; // DRAW_EVENTS
291   HGFX gfx; // hdc to paint on
292   RECT area; // element area, to get invalid area to paint use GetClipBox,
293   UINT reserved; // for DRAW_BACKGROUND/DRAW_FOREGROUND - it is a border box
294  // for DRAW_CONTENT - it is a content box
295  };
296 
297   enum CONTENT_CHANGE_BITS { // for CONTENT_CHANGED reason
298   CONTENT_ADDED = 0x01,
299   CONTENT_REMOVED = 0x02,
300  };
301 
302   enum BEHAVIOR_EVENTS
303  {
304   BUTTON_CLICK = 0, // click on button
305   BUTTON_PRESS = 1, // mouse down or key down in button
306   BUTTON_STATE_CHANGED = 2, // checkbox/radio/slider changed its state/value
307   EDIT_VALUE_CHANGING = 3, // before text change
308   EDIT_VALUE_CHANGED = 4, // after text change
309   SELECT_SELECTION_CHANGED = 5, // selection in <select> changed
310   SELECT_STATE_CHANGED = 6, // node in select expanded/collapsed, heTarget is the node
311 
312   POPUP_REQUEST = 7, // request to show popup just received,
313  // here DOM of popup element can be modifed.
314   POPUP_READY = 8, // popup element has been measured and ready to be shown on screen,
315  // here you can use functions like ScrollToView.
316   POPUP_DISMISSED = 9, // popup element is closed,
317  // here DOM of popup element can be modifed again - e.g. some items can be removed
318  // to free memory.
319 
320   MENU_ITEM_ACTIVE = 0xA, // menu item activated by mouse hover or by keyboard,
321   MENU_ITEM_CLICK = 0xB, // menu item click,
322  // BEHAVIOR_EVENT_PARAMS structure layout
323  // BEHAVIOR_EVENT_PARAMS.cmd - MENU_ITEM_CLICK/MENU_ITEM_ACTIVE
324  // BEHAVIOR_EVENT_PARAMS.heTarget - owner(anchor) of the menu
325  // BEHAVIOR_EVENT_PARAMS.he - the menu item, presumably <li> element
326  // BEHAVIOR_EVENT_PARAMS.reason - BY_MOUSE_CLICK | BY_KEY_CLICK
327 
328 
329   CONTEXT_MENU_REQUEST = 0x10, // "right-click", BEHAVIOR_EVENT_PARAMS::he is current popup menu HELEMENT being processed or NULL.
330  // application can provide its own HELEMENT here (if it is NULL) or modify current menu element.
331 
332   VISIUAL_STATUS_CHANGED = 0x11, // broadcast notification, sent to all elements of some container being shown or hidden
333   DISABLED_STATUS_CHANGED = 0x12,// broadcast notification, sent to all elements of some container that got new value of :disabled state
334 
335   POPUP_DISMISSING = 0x13, // popup is about to be closed
336 
337   CONTENT_CHANGED = 0x15, // content has been changed, is posted to the element that gets content changed, reason is combination of CONTENT_CHANGE_BITS.
338  // target == NULL means the window got new document and this event is dispatched only to the window.
339 
340   CLICK = 0x16, // generic click
341   CHANGE = 0x17, // generic change
342 
343  // "grey" event codes - notfications from behaviors from this SDK
344   HYPERLINK_CLICK = 0x80, // hyperlink click
345 
346  //TABLE_HEADER_CLICK, // click on some cell in table header,
347  // // target = the cell,
348  // // reason = index of the cell (column number, 0..n)
349  //TABLE_ROW_CLICK, // click on data row in the table, target is the row
350  // // target = the row,
351  // // reason = index of the row (fixed_rows..n)
352  //TABLE_ROW_DBL_CLICK, // mouse dbl click on data row in the table, target is the row
353  // // target = the row,
354  // // reason = index of the row (fixed_rows..n)
355 
356   ELEMENT_COLLAPSED = 0x90, // element was collapsed, so far only behavior:tabs is sending these two to the panels
357   ELEMENT_EXPANDED, // element was expanded,
358 
359   ACTIVATE_CHILD, // activate (select) child,
360  // used for example by accesskeys behaviors to send activation request, e.g. tab on behavior:tabs.
361 
362  //DO_SWITCH_TAB = ACTIVATE_CHILD,// command to switch tab programmatically, handled by behavior:tabs
363  // // use it as SciterPostEvent(tabsElementOrItsChild, DO_SWITCH_TAB, tabElementToShow, 0);
364 
365   INIT_DATA_VIEW, // request to virtual grid to initialize its view
366 
367   ROWS_DATA_REQUEST, // request from virtual grid to data source behavior to fill data in the table
368  // parameters passed throug DATA_ROWS_PARAMS structure.
369 
370   UI_STATE_CHANGED, // ui state changed, observers shall update their visual states.
371  // is sent for example by behavior:richtext when caret position/selection has changed.
372 
373   FORM_SUBMIT, // behavior:form detected submission event. BEHAVIOR_EVENT_PARAMS::data field contains data to be posted.
374  // BEHAVIOR_EVENT_PARAMS::data is of type T_MAP in this case key/value pairs of data that is about
375  // to be submitted. You can modify the data or discard submission by returning true from the handler.
376   FORM_RESET, // behavior:form detected reset event (from button type=reset). BEHAVIOR_EVENT_PARAMS::data field contains data to be reset.
377  // BEHAVIOR_EVENT_PARAMS::data is of type T_MAP in this case key/value pairs of data that is about
378  // to be rest. You can modify the data or discard reset by returning true from the handler.
379 
380   DOCUMENT_COMPLETE, // document in behavior:frame or root document is complete.
381 
382   HISTORY_PUSH, // requests to behavior:history (commands)
383   HISTORY_DROP,
384   HISTORY_PRIOR,
385   HISTORY_NEXT,
386   HISTORY_STATE_CHANGED, // behavior:history notification - history stack has changed
387 
388   CLOSE_POPUP, // close popup request,
389   REQUEST_TOOLTIP, // request tooltip, evt.source <- is the tooltip element.
390 
391   ANIMATION = 0xA0, // animation started (reason=1) or ended(reason=0) on the element.
392 
393   DOCUMENT_CREATED = 0xC0, // document created, script namespace initialized. target -> the document
394   DOCUMENT_CLOSE_REQUEST = 0xC1, // document is about to be closed, to cancel closing do: evt.data = sciter::value("cancel");
395   DOCUMENT_CLOSE = 0xC2, // last notification before document removal from the DOM
396   DOCUMENT_READY = 0xC3, // document has got DOM structure, styles and behaviors of DOM elements. Script loading run is complete at this moment.
397 
398   VIDEO_INITIALIZED = 0xD1, // <video> "ready" notification
399   VIDEO_STARTED = 0xD2, // <video> playback started notification
400   VIDEO_STOPPED = 0xD3, // <video> playback stoped/paused notification
401   VIDEO_BIND_RQ = 0xD4, // <video> request for frame source binding,
402  // If you want to provide your own video frames source for the given target <video> element do the following:
403  // 1. Handle and consume this VIDEO_BIND_RQ request
404  // 2. You will receive second VIDEO_BIND_RQ request/event for the same <video> element
405  // but this time with the 'reason' field set to an instance of sciter::video_destination interface.
406  // 3. add_ref() it and store it for example in worker thread producing video frames.
407  // 4. call sciter::video_destination::start_streaming(...) providing needed parameters
408  // call sciter::video_destination::render_frame(...) as soon as they are available
409  // call sciter::video_destination::stop_streaming() to stop the rendering (a.k.a. end of movie reached)
410 
411   PAGINATION_STARTS = 0xE0, // behavior:pager starts pagination
412   PAGINATION_PAGE = 0xE1, // behavior:pager paginated page no, reason -> page no
413   PAGINATION_ENDS = 0xE2, // behavior:pager end pagination, reason -> total pages
414 
415   FIRST_APPLICATION_EVENT_CODE = 0x100
416  // all custom event codes shall be greater
417  // than this number. All codes below this will be used
418  // solely by application - Sciter will not intrepret it
419  // and will do just dispatching.
420  // To send event notifications with these codes use
421  // SciterSend/PostEvent API.
422 
423  };
424 
425   enum EVENT_REASON
426  {
427   BY_MOUSE_CLICK,
428   BY_KEY_CLICK,
429   SYNTHESIZED, // synthesized, programmatically generated.
430  };
431 
432   enum EDIT_CHANGED_REASON
433  {
434   BY_INS_CHAR, // single char insertion
435   BY_INS_CHARS, // character range insertion, clipboard
436   BY_DEL_CHAR, // single char deletion
437   BY_DEL_CHARS, // character range deletion (selection)
438  };
439 
440   typedef struct BEHAVIOR_EVENT_PARAMS
441  {
442   UINT cmd; // BEHAVIOR_EVENTS
443   HELEMENT heTarget; // target element handler, in MENU_ITEM_CLICK this is owner element that caused this menu - e.g. context menu owner
444  // In scripting this field named as Event.owner
445   HELEMENT he; // source element e.g. in SELECTION_CHANGED it is new selected <option>, in MENU_ITEM_CLICK it is menu item (LI) element
446   UINT_PTR reason; // EVENT_REASON or EDIT_CHANGED_REASON - UI action causing change.
447  // In case of custom event notifications this may be any
448  // application specific value.
449  SCITER_VALUE
450   data; // auxiliary data accompanied with the event. E.g. FORM_SUBMIT event is using this field to pass collection of values.
451  } BEHAVIOR_EVENT_PARAMS;
452 
453   typedef struct TIMER_PARAMS
454  {
455   UINT_PTR timerId; // timerId that was used to create timer by using SciterSetTimer
456  } TIMER_PARAMS;
457 
458 
459 
460  // identifiers of methods currently supported by intrinsic behaviors,
461  // see function SciterCallBehaviorMethod
462 
463   enum BEHAVIOR_METHOD_IDENTIFIERS
464  {
465   DO_CLICK = 0,
466   GET_TEXT_VALUE = 1,
467   SET_TEXT_VALUE,
468  // p - TEXT_VALUE_PARAMS
469 
470   TEXT_EDIT_GET_SELECTION,
471  // p - TEXT_EDIT_SELECTION_PARAMS
472 
473   TEXT_EDIT_SET_SELECTION,
474  // p - TEXT_EDIT_SELECTION_PARAMS
475 
476  // Replace selection content or insert text at current caret position.
477  // Replaced text will be selected.
478   TEXT_EDIT_REPLACE_SELECTION,
479  // p - TEXT_EDIT_REPLACE_SELECTION_PARAMS
480 
481  // Set value of type="vscrollbar"/"hscrollbar"
482   SCROLL_BAR_GET_VALUE,
483   SCROLL_BAR_SET_VALUE,
484 
485   TEXT_EDIT_GET_CARET_POSITION,
486   TEXT_EDIT_GET_SELECTION_TEXT, // p - TEXT_SELECTION_PARAMS
487   TEXT_EDIT_GET_SELECTION_HTML, // p - TEXT_SELECTION_PARAMS
488   TEXT_EDIT_CHAR_POS_AT_XY, // p - TEXT_EDIT_CHAR_POS_AT_XY_PARAMS
489 
490   IS_EMPTY = 0xFC, // p - IS_EMPTY_PARAMS // set VALUE_PARAMS::is_empty (false/true) reflects :empty state of the element.
491   GET_VALUE = 0xFD, // p - VALUE_PARAMS
492   SET_VALUE = 0xFE, // p - VALUE_PARAMS
493 
494   FIRST_APPLICATION_METHOD_ID = 0x100
495  };
496 
497   typedef struct SCRIPTING_METHOD_PARAMS
498  {
499   LPCSTR name; //< method name
500   SCITER_VALUE* argv; //< vector of arguments
501   UINT argc; //< argument count
502   SCITER_VALUE result; //< return value
503  } SCRIPTING_METHOD_PARAMS;
504 
505   typedef struct TISCRIPT_METHOD_PARAMS
506  {
507   tiscript_VM* vm;
508   tiscript_value tag; //< method id (symbol)
509   tiscript_value result; //< return value
510  // parameters are accessible through tiscript::args.
511  } TISCRIPT_METHOD_PARAMS;
512 
513  // GET_VALUE/SET_VALUE methods params
514   struct VALUE_PARAMS
515  {
516   UINT methodID;
517   SCITER_VALUE val;
518 #ifdef __cplusplus
519  VALUE_PARAMS(bool do_set) { methodID = do_set? SET_VALUE : GET_VALUE; }
520 #endif
521  };
522 
523  // IS_EMPTY method params
524   struct IS_EMPTY_PARAMS
525  {
526   UINT methodID;
527   UINT is_empty; // !0 - is empty
528 #ifdef __cplusplus
529  IS_EMPTY_PARAMS():is_empty(0) { methodID = IS_EMPTY; }
530 #endif
531  };
532 
533  // see SciterRequestElementData
534 
535   typedef struct DATA_ARRIVED_PARAMS
536  {
537   HELEMENT initiator; // element intiator of SciterRequestElementData request,
538   LPCBYTE data; // data buffer
539   UINT dataSize; // size of data
540   UINT dataType; // data type passed "as is" from SciterRequestElementData
541   UINT status; // status = 0 (dataSize == 0) - unknown error.
542  // status = 100..505 - http response status, Note: 200 - OK!
543  // status > 12000 - wininet error code, see ERROR_INTERNET_*** in wininet.h
544   LPCWSTR uri; // requested url
545  } DATA_ARRIVED_PARAMS;
546 
547 
548 
549 #pragma pack(pop)
550 
551 #ifdef __cplusplus
552 
553  #pragma warning(disable:4786) //identifier was truncated...
554  #pragma warning(disable:4100) //unreferenced formal parameter
555 
556  namespace sciter
557  {
558 
559  // event handler which can be attached to any DOM element.
560  // event handler can be attached to the element as a "behavior" (see below)
561  // or by sciter::dom::element::attach( event_handler* eh )
562 
563  struct event_handler
564  {
565  event_handler() // EVENT_GROUPS flags
566  {
567  }
568 
569  virtual void detached (HELEMENT /*he*/ ) { }
570  virtual void attached (HELEMENT /*he*/ ) { }
571 
572  // defines list of event groups this event_handler is subscribed to
573  virtual bool subscription( HELEMENT he, UINT& event_groups )
574  {
575  event_groups = HANDLE_ALL;
576  return true;
577  }
578 
579  // handlers with extended interface
580  // by default they are calling old set of handlers (for compatibility with legacy code)
581 
582  /*virtual bool handle_mouse (HELEMENT he, MOUSE_PARAMS& params ) { return false; }
583  virtual bool handle_key (HELEMENT he, KEY_PARAMS& params ) { return false; }
584  virtual bool handle_focus (HELEMENT he, FOCUS_PARAMS& params ) { return false; }
585  virtual bool handle_timer (HELEMENT he ) { return false; }
586  virtual void handle_size (HELEMENT he ) { }
587  virtual bool handle_draw (HELEMENT he, DRAW_PARAMS& params ) { return false; }
588  virtual bool handle_method_call (HELEMENT he, METHOD_PARAMS& params ) { return false; }
589  virtual bool handle_event (HELEMENT he, BEHAVIOR_EVENT_PARAMS& params ) { return false; }
590  virtual bool handle_data_arrived (HELEMENT he, DATA_ARRIVED_PARAMS& params ) { return false; }
591 
592  virtual bool handle_scripting_call(HELEMENT he, SCRIPTING_METHOD_PARAMS& params )
593  {
594  return false;
595  }*/
596 
597  virtual bool handle_mouse (HELEMENT he, MOUSE_PARAMS& params )
598  {
599  return on_mouse( he, params.target, params.cmd, params.pos, params.button_state, params.alt_state );
600  }
601  virtual bool handle_key (HELEMENT he, KEY_PARAMS& params )
602  {
603  return on_key( he, params.target, params.cmd, params.key_code, params.alt_state );
604  }
605  virtual bool handle_focus (HELEMENT he, FOCUS_PARAMS& params )
606  {
607  return on_focus( he, params.target, params.cmd );
608  }
609  virtual bool handle_timer (HELEMENT he,TIMER_PARAMS& params )
610  {
611  if(params.timerId)
612  return on_timer( he, params.timerId );
613  return on_timer( he );
614  }
615 
616  virtual void handle_size (HELEMENT he )
617  {
618  on_size( he );
619  }
620  virtual bool handle_scroll (HELEMENT he, SCROLL_PARAMS& params )
621  {
622  return on_scroll( he, params.target, (SCROLL_EVENTS)params.cmd, params.pos, params.vertical );
623  }
624 
625  virtual bool handle_gesture (HELEMENT he, GESTURE_PARAMS& params )
626  {
627  return false;
628  }
629 
630  virtual bool handle_draw (HELEMENT he, DRAW_PARAMS& params )
631  {
632  return on_draw(he, params.cmd, params.gfx, params.area );
633  }
634 
635  virtual bool handle_method_call (HELEMENT he, METHOD_PARAMS& params )
636  {
637  return on_method_call(he, UINT(params.methodID), &params );
638  }
639 
640  // notification events from builtin behaviors - synthesized events: BUTTON_CLICK, VALUE_CHANGED
641  // see enum BEHAVIOR_EVENTS
642  virtual bool handle_event (HELEMENT he, BEHAVIOR_EVENT_PARAMS& params )
643  {
644  return on_event(he, params.heTarget, (BEHAVIOR_EVENTS)params.cmd, params.reason );
645  }
646 
647  // notification event: data requested by SciterRequestElementData just delivered
648  virtual bool handle_data_arrived (HELEMENT he, DATA_ARRIVED_PARAMS& params )
649  {
650  return on_data_arrived(he, params.initiator, params.data, params.dataSize, params.dataType );
651  }
652 
653  virtual bool handle_scripting_call(HELEMENT he, SCRIPTING_METHOD_PARAMS& params )
654  {
655  return on_script_call(he, params.name, params.argc, params.argv, params.result);
656  }
657 
658  virtual bool handle_scripting_call(HELEMENT he, TISCRIPT_METHOD_PARAMS& params )
659  {
660  return on_script_call(he, params.vm, params.tag, params.result);
661  }
662 
663 
664  //
665  // alternative set of event handlers (aka old set).
666  //
667  virtual bool on_mouse (HELEMENT he, HELEMENT target, UINT event_type, POINT pt, UINT mouseButtons, UINT keyboardStates ) { return false; }
668  virtual bool on_key (HELEMENT he, HELEMENT target, UINT event_type, UINT code, UINT keyboardStates ) { return false; }
669  virtual bool on_focus (HELEMENT he, HELEMENT target, UINT event_type ) { return false; }
670  virtual bool on_timer (HELEMENT he ) { return false; /*stop this timer*/ }
671  virtual bool on_timer (HELEMENT he, UINT_PTR extTimerId ) { return false; /*stop this timer*/ }
672  virtual bool on_draw (HELEMENT he, UINT draw_type, HGFX hgfx, const RECT& rc ) { return false; /*do default draw*/ }
673  virtual void on_size (HELEMENT he ) { }
674 
675  virtual bool on_method_call (HELEMENT he, UINT methodID, METHOD_PARAMS* params ) { return false; /*not handled*/ }
676 
677  // calls from CSSS! script and TIScript (if it was not handled by method below). Override this if you want your own methods to the CSSS! namespace.
678  // Follwing declaration:
679  // #my-active-on {
680  // when-click: r = self.my-method(1,"one");
681  // }
682  // will end up with on_script_call(he, "my-method" , 2, argv, retval );
683  // where argv[0] will be 1 and argv[1] will be "one".
684  virtual bool on_script_call(HELEMENT he, LPCSTR name, UINT argc, SCITER_VALUE* argv, SCITER_VALUE& retval) { return false; }
685 
686  // Calls from TIScript. Override this if you want your own methods accessible directly from tiscript engine.
687  // Use tiscript::args to access parameters.
688  virtual bool on_script_call(HELEMENT he, tiscript_VM* pvm, tiscript_value tag, tiscript_value& retval) { return false; }
689 
690  // notification events from builtin behaviors - synthesized events: BUTTON_CLICK, VALUE_CHANGED
691  // see enum BEHAVIOR_EVENTS
692  virtual bool on_event (HELEMENT he, HELEMENT target, BEHAVIOR_EVENTS type, UINT_PTR reason ) { return false; }
693 
694  // notification event: data requested by SciterRequestElementData just delivered
695  virtual bool on_data_arrived (HELEMENT he, HELEMENT initiator, LPCBYTE data, UINT dataSize, UINT dataType ) { return false; }
696 
697  virtual bool on_scroll( HELEMENT he, HELEMENT target, SCROLL_EVENTS cmd, INT pos, BOOL isVertical ) { return false; }
698 
699  // ElementEventProc implementeation
700  static BOOL SC_CALLBACK element_proc(LPVOID tag, HELEMENT he, UINT evtg, LPVOID prms )
701  {
702  event_handler* pThis = static_cast<event_handler*>(tag);
703  if( pThis ) switch( evtg )
704  {
705  case SUBSCRIPTIONS_REQUEST:
706  {
707  UINT *p = (UINT *)prms;
708  return pThis->subscription( he, *p );
709  }
710  case HANDLE_INITIALIZATION:
711  {
712  INITIALIZATION_PARAMS *p = (INITIALIZATION_PARAMS *)prms;
713  if(p->cmd == BEHAVIOR_DETACH)
714  pThis->detached(he);
715  else if(p->cmd == BEHAVIOR_ATTACH)
716  pThis->attached(he);
717  return true;
718  }
719  case HANDLE_MOUSE: { MOUSE_PARAMS *p = (MOUSE_PARAMS *)prms; return pThis->handle_mouse( he, *p ); }
720  case HANDLE_KEY: { KEY_PARAMS *p = (KEY_PARAMS *)prms; return pThis->handle_key( he, *p ); }
721  case HANDLE_FOCUS: { FOCUS_PARAMS *p = (FOCUS_PARAMS *)prms; return pThis->handle_focus( he, *p ); }
722  case HANDLE_DRAW: { DRAW_PARAMS *p = (DRAW_PARAMS *)prms; return pThis->handle_draw(he, *p ); }
723  case HANDLE_TIMER: { TIMER_PARAMS *p = (TIMER_PARAMS *)prms; return pThis->handle_timer(he, *p); }
724  case HANDLE_BEHAVIOR_EVENT: { BEHAVIOR_EVENT_PARAMS *p = (BEHAVIOR_EVENT_PARAMS *)prms; return pThis->handle_event(he, *p ); }
725  case HANDLE_METHOD_CALL: { METHOD_PARAMS *p = (METHOD_PARAMS *)prms; return pThis->handle_method_call(he, *p ); }
726  case HANDLE_DATA_ARRIVED: { DATA_ARRIVED_PARAMS *p = (DATA_ARRIVED_PARAMS *)prms; return pThis->handle_data_arrived(he, *p ); }
727  case HANDLE_SCROLL: { SCROLL_PARAMS *p = (SCROLL_PARAMS *)prms; return pThis->handle_scroll(he, *p ); }
728  case HANDLE_SIZE: { pThis->handle_size(he); return false; }
729  // call using sciter::value's (from CSSS!)
730  case HANDLE_SCRIPTING_METHOD_CALL: { SCRIPTING_METHOD_PARAMS* p = (SCRIPTING_METHOD_PARAMS *)prms; return pThis->handle_scripting_call(he, *p ); }
731  // call using tiscript::value's (from the script)
732  case HANDLE_TISCRIPT_METHOD_CALL: { TISCRIPT_METHOD_PARAMS* p = (TISCRIPT_METHOD_PARAMS *)prms; return pThis->handle_scripting_call(he, *p ); }
733  case HANDLE_GESTURE : { GESTURE_PARAMS *p = (GESTURE_PARAMS *)prms; return pThis->handle_gesture(he, *p ); }
734  default:
735  assert(false);
736  }
737  return false;
738  }
739  };
740 
741 
742  //
743  // "behavior" is a named event_handler
744  // behaviors organized into one global list to be processed
745  // automaticly while handling HLN_ATTACH_BEHAVIOR notification
746  //
747 
748  struct behavior_factory
749  {
750  behavior_factory(const char* external_name)
751  :next(0),name(external_name)
752  {
753  // add this implementation to the list (singleton)
754  next = root();
755  root(this);
756  }
757 
758  // needs to be overriden
759  virtual event_handler* create(HELEMENT he) = 0;
760 
761  // behavior list support
762  behavior_factory* next;
763  const char* name; // name must be a pointer to a static string
764 
765  // returns behavior implementation by name.
766  static event_handler* create(const char* name, HELEMENT he)
767  {
768  for(behavior_factory* t = root(); t; t = t->next)
769  if(strcmp(t->name,name)==0)
770  {
771  return t->create(he);
772  }
773  return 0; // not found
774  }
775  // implementation of static list of behaviors
776  static behavior_factory* root(behavior_factory* to_set = 0)
777  {
778  static behavior_factory* _root = 0;
779  if(to_set) _root = to_set;
780  return _root;
781  }
782 
783  };
784 
785  inline void attach_dom_event_handler(HWINDOW hwnd, event_handler* ph)
786  {
787  int r = SciterWindowAttachEventHandler( hwnd, &event_handler::element_proc, ph, HANDLE_ALL );
788  assert(r == SCDOM_OK); r;
789  }
790  inline void detach_dom_event_handler(HWINDOW hwnd, event_handler* ph)
791  {
792  int r = SciterWindowDetachEventHandler( hwnd, &event_handler::element_proc, ph );
793  assert(r == SCDOM_OK); r;
794  }
795 
796 #define BEGIN_FUNCTION_MAP \
797  virtual bool on_script_call(HELEMENT he, LPCSTR name, UINT argc, sciter::value* argv, sciter::value& retval) \
798  { \
799  aux::chars _name = aux::chars_of(name);
800 
801 #define FUNCTION_V(name, method) \
802  if( const_chars(name) == _name ) \
803  { retval = method(argc,argv); return true; }
804 #define FUNCTION_0(name, method) \
805  if( const_chars(name) == _name && argc == 0) \
806  { retval = method(); return true; }
807 #define FUNCTION_1(name, method) \
808  if( const_chars(name) == _name && argc == 1) \
809  { retval = method(argv[0]); return true; }
810 #define FUNCTION_2(name, method) \
811  if( const_chars(name) == _name && argc == 2) \
812  { retval = method(argv[0],argv[1]); return true; }
813 #define FUNCTION_3(name, method) \
814  if( const_chars(name) == _name && argc == 3) \
815  { retval = method(argv[0],argv[1],argv[2]); return true; }
816 #define FUNCTION_4(name, method) \
817  if( const_chars(name) == _name && argc == 4) \
818  { retval = method(argv[0],argv[1],argv[2],argv[3]); return true; }
819 #define FUNCTION_5(name, method) \
820  if( const_chars(name) == _name && argc == 5) \
821  { retval = method(argv[0],argv[1],argv[2],argv[3],argv[4]); return true; }
822 #define CHAIN_FUNCTION_MAP(SUPER_T) \
823  if(SUPER_T::on_script_call(he, name, argc, argv, retval)) return true;
824 
825 #define END_FUNCTION_MAP \
826  return false; }
827 
828 
829  } //namespace sciter
830 
831 #endif //__cplusplus
832 
833 
834 
835 
836 #endif
837 
BOOL SC_CALLBACK ElementEventProc(LPVOID tag, HELEMENT he, UINT evtg, LPVOID prms)
PHASE_MASK
struct TIMER_PARAMS TIMER_PARAMS
CONTENT_CHANGE_BITS
GESTURE_CMD
SCDOM_RESULT SCAPI SciterWindowDetachEventHandler(HWINDOW hwndLayout, LPELEMENT_EVENT_PROC pep, LPVOID tag)
Definition: sciter-x-api.h:524
struct DATA_ARRIVED_PARAMS DATA_ARRIVED_PARAMS
ElementEventProc * LPElementEventProc
BEHAVIOR_EVENTS
HELEMENT target
struct BEHAVIOR_EVENT_PARAMS BEHAVIOR_EVENT_PARAMS
struct TISCRIPT_METHOD_PARAMS TISCRIPT_METHOD_PARAMS
MOUSE_EVENTS
GESTURE_TYPE_FLAGS
struct SCRIPTING_METHOD_PARAMS SCRIPTING_METHOD_PARAMS
gool::graphics * HGFX
SCDOM_RESULT SCAPI SciterWindowAttachEventHandler(HWINDOW hwndLayout, LPELEMENT_EVENT_PROC pep, LPVOID tag, UINT subscription)
Definition: sciter-x-api.h:523
const BYTE * LPCBYTE
KEYBOARD_STATES
FOCUS_EVENTS
Definition: value.h:14
EDIT_CHANGED_REASON
SCROLL_EVENTS
DRAW_EVENTS
EVENT_GROUPS
UINT methodID
Definition: sciter-x-dom.h:80
HELEMENT target
KEY_EVENTS
BEHAVIOR_METHOD_IDENTIFIERS
struct SCITER_GRAPHICS SCITER_GRAPHICS
struct tiscript_VM tiscript_VM
Definition: tiscript.h:27
INITIALIZATION_EVENTS
BOOL SC_CALLBACK SciterBehaviorFactory(LPCSTR, HELEMENT, LPElementEventProc *, LPVOID *)
GESTURE_STATE
#define SCDOM_OK
Definition: sciter-x-dom.h:71
SCITER_VALUE val
EVENT_REASON
const std::vector< sciter::string > & argv()
void * HELEMENT
Definition: sciter-x-dom.h:40
DRAGGING_TYPE
UINT_PTR timerId
HELEMENT dragging
CURSOR_TYPE
UINT64 tiscript_value
Definition: tiscript.h:29
HELEMENT target
MOUSE_BUTTONS

AltStyle によって変換されたページ (->オリジナル) /