/// <summary> /// Handles <see cref="Attached"/> event /// </summary> protected override void OnAttached(ElementEventArgs e) { // Scope will free all allocated child elements using (var scope = ElementScope.Create()) { var ctl = e.Element; var children = ctl.Children; var got_one = false; for (int i = children.Count - 1; i >= 0; --i) { var t = children[i]; if (!String.IsNullOrEmpty(t.Attributes["default"]) && !got_one) { t.SetState(ElementState.Current | ElementState.Expanded); got_one = true; } else { t.SetState(ElementState.Collapsed); } } } base.OnAttached(e); }
/// <summary> /// Clears content of the list control /// </summary> private void ClearItems() { if (ElementRef != null) { // Scope will free deleted items as soon as possible using (var scope = ElementScope.Create()) { var container = GetItemsContainer(); var items = new List <Element>(container); foreach (var item in items) { item.Delete(); } } } }
/// <summary> /// Bridge to sciter host callbacks /// </summary> private unsafe static IntPtr Host_NativeCallback(int uMsg, IntPtr wParam, IntPtr pns, IntPtr vParam) { using (var prot = ElementScope.Create()) { var host = InstanceProtector.GetInstance(vParam) as ISciterNotifications; if (host != null) { var ntf = (HL_NMHDR *)pns; switch (ntf->code) { case HTMLAYOUT_NOTIFICATION.HLN_ATTACH_BEHAVIOR: Host_HandleAttachBehavior(host, pns); break; case HTMLAYOUT_NOTIFICATION.HLN_DATA_LOADED: Host_HandleDataLoaded(host, pns); break; case HTMLAYOUT_NOTIFICATION.HLN_LOAD_DATA: Host_HandleLoadData(host, pns); break; case HTMLAYOUT_NOTIFICATION.HLN_DOCUMENT_COMPLETE: Host_HandleDocumentComplete(host, pns); break; case HTMLAYOUT_NOTIFICATION.HLN_BEHAVIOR_CHANGED: case HTMLAYOUT_NOTIFICATION.HLN_CONTROL_CREATED: case HTMLAYOUT_NOTIFICATION.HLN_CREATE_CONTROL: case HTMLAYOUT_NOTIFICATION.HLN_DESTROY_CONTROL: case HTMLAYOUT_NOTIFICATION.HLN_DIALOG_CLOSE_RQ: case HTMLAYOUT_NOTIFICATION.HLN_DIALOG_CREATED: case HTMLAYOUT_NOTIFICATION.HLN_DOCUMENT_LOADED: case HTMLAYOUT_NOTIFICATION.HLN_UPDATE_UI: break; default: //There is a lot of notifications besides the HLN_ //Debug.WriteLine(String.Format("Invalid notification code: {0}", ntf->code)); break; } } Debug.Assert(host != null, "Behavior object has been garbage collected"); return(IntPtr.Zero); } }
/// <summary> /// Bridge to sciter host callbacks /// </summary> private unsafe static uint Host_NativeCallback(IntPtr pns, IntPtr callbackParam) { using (var prot = ElementScope.Create()) { var host = InstanceProtector.GetInstance(callbackParam) as ISciterNotifications; if (host != null) { var ntf = (SCN_CALLBACK_NOTIFICATION *)pns; switch (ntf->code) { case SCITER_NOTIFICATION.SC_ATTACH_BEHAVIOR: Host_HandleAttachBehavior(host, pns); break; case SCITER_NOTIFICATION.SC_DATA_LOADED: Host_HandleDataLoaded(host, pns); break; case SCITER_NOTIFICATION.SC_LOAD_DATA: Host_HandleLoadData(host, pns); break; case SCITER_NOTIFICATION.SC_CALLBACK_HOST: Host_HandleCallbackHost(host, pns); break; case SCITER_NOTIFICATION.SC_DOCUMENT_COMPLETE: Host_HandleDocumentComplete(host, pns); break; default: Debug.Fail(String.Format("Invalid notification code: {0}", ntf->code)); break; } } Debug.Assert(host != null, "Behavior object has been garbage collected"); return(0); } }
/// <summary> /// This is a generic wndproc. It is the callback for all hooked /// windows. If we get into this function, we look up the hwnd in the /// global list of all hooked windows to get its message map. If the /// message received is present in the message map, its callback is /// invoked with the parameters listed here. /// </summary> private IntPtr WindowProc(IntPtr hwnd, int msg, IntPtr wParam, IntPtr lParam) { using (var scope = ElementScope.Create()) { Debug.Assert(_originalWndProc != IntPtr.Zero, "Window hook was not installed"); bool handled = false; var retval = _callback(hwnd, msg, wParam, lParam, ref handled); if (handled) { return(retval); } retval = User32.CallWindowProc(_originalWndProc, hwnd, msg, wParam, lParam); if (msg == User32.WM_DESTROY) { revertWndProc(); } return(retval); } }
/// <summary> /// Bridge to sciter element callbacks /// </summary> private static unsafe bool Behavior_NativeCallback(IntPtr tag, IntPtr he, EVENT_GROUPS evtg, IntPtr prms) { using (var prot = ElementScope.Create()) { bool handled = false; var behavior = InstanceProtector.GetInstance(tag) as ISciterBehavior; if (behavior != null) { // TODO: Timer switch (evtg) { case EVENT_GROUPS.HANDLE_INITIALIZATION: Behavior_HandleInitialization(behavior, he, prms, ref handled); break; case EVENT_GROUPS.HANDLE_MOUSE: Behavior_HandleMouseEvent(behavior, he, prms, ref handled); break; case EVENT_GROUPS.HANDLE_KEY: Behavior_HandleKey(behavior, he, prms, ref handled); break; case EVENT_GROUPS.HANDLE_FOCUS: Behavior_HandleFocusEvent(behavior, he, prms, ref handled); break; case EVENT_GROUPS.HANDLE_SCROLL: Behavior_HandleScroll(behavior, he, prms, ref handled); break; case EVENT_GROUPS.HANDLE_TIMER: Behavior_HandleTimer(behavior, he, prms, ref handled); break; case EVENT_GROUPS.HANDLE_SIZE: Behavior_HandleSize(behavior, he, prms, ref handled); break; case EVENT_GROUPS.HANDLE_DRAW: Behavior_HandleDraw(behavior, he, prms, ref handled); break; case EVENT_GROUPS.HANDLE_DATA_ARRIVED: Behavior_HandleDataArrived(behavior, he, prms, ref handled); break; case EVENT_GROUPS.HANDLE_BEHAVIOR_EVENT: Behavior_HandleBehaviorEvent(behavior, he, prms, ref handled); break; case EVENT_GROUPS.HANDLE_METHOD_CALL: Behavior_HandleMethodCall(behavior, he, prms, ref handled); break; case EVENT_GROUPS.HANDLE_SCRIPTING_METHOD_CALL: Behavior_HandleScriptingMethodCall(behavior, he, prms, ref handled); break; default: break; } } Debug.Assert(behavior != null, "Behavior object has been garbage collected"); return(handled); } }