Пример #1
0
        public void AddHandlersWithLoad(ListChangedEventHandler listChangedEventHandler,
                                        LoadFinishedEventHandler loadFinishedEventHandler,
                                        ListItemChangedEventHandler itemChangedEventHandler)
        {
            #if (CHATTY_DEBUG)
            string msg = "*** HRA LIST AddHandlersWithLoad on : " + this.ToString() + System.Environment.NewLine;
            if (listChangedEventHandler != null)
            {
                msg += "By: " + listChangedEventHandler.Target.ToString();
            }
            else if (loadFinishedEventHandler != null)
            {
                msg += "By: " + loadFinishedEventHandler.Target.ToString();
            }
            else if (itemChangedEventHandler != null)
            {
                msg += "By: " + itemChangedEventHandler.Target.ToString();
            }

            Logger.Instance.DebugToLog(msg);
            #endif

            if (listChangedEventHandler != null)
            {
                if (ListChanged == null)
                {
                    ListChanged += listChangedEventHandler;
                }
                else
                {
                    bool ok = true;
                    foreach (Delegate d in ListChanged.GetInvocationList())
                    {
                        if (d.Target == listChangedEventHandler.Target)
                        {
                            ok = false;
                        }
                    }
                    if (ok)
                    {
                        ListChanged += listChangedEventHandler;
                    }
                }
            }

            if (loadFinishedEventHandler != null)
            {
                if (LoadFinished == null)
                {
                    LoadFinished += loadFinishedEventHandler;
                }
                else
                {
                    bool ok = true;
                    foreach (Delegate d in LoadFinished.GetInvocationList())
                    {
                        if (d.Target == loadFinishedEventHandler.Target)
                        {
                            ok = false;
                        }
                    }
                    if (ok)
                    {
                        LoadFinished += loadFinishedEventHandler;
                    }
                }
            }

            if (itemChangedEventHandler != null)
            {
                if (ListItemChanged == null)
                {
                    ListItemChanged += itemChangedEventHandler;
                }
                else
                {
                    bool ok = true;
                    foreach (Delegate d in ListItemChanged.GetInvocationList())
                    {
                        if (d.Target == loadFinishedEventHandler.Target)
                        {
                            ok = false;
                        }
                    }
                    if (ok)
                    {
                        ListItemChanged += itemChangedEventHandler;
                    }
                }
            }

            if (loaded)
            {
                if (loadFinishedEventHandler != null)
                {
                    HraListLoadedEventArgs args = new HraListLoadedEventArgs();
                    args.sender     = this;
                    args.workerArgs = new RunWorkerCompletedEventArgs(this, null, false);
                    loadFinishedEventHandler.Invoke(args);
                }
            }
            else
            {
                LoadList();
            }
        }
Пример #2
0
        public void OnStateChange(nsIWebProgress progress, nsIRequest request, Int32 status, UInt32 state)
        {
            if (!owner.created)
            {
                owner.created = true;
            }

#if debug
            //OnGeneric ("OnStateChange");

            System.Text.StringBuilder s = new System.Text.StringBuilder();
            if ((state & (uint)StateFlags.Start) != 0)
            {
                s.Append("Start\t");
            }
            if ((state & (uint)StateFlags.Redirecting) != 0)
            {
                s.Append("Redirecting\t");
            }
            if ((state & (uint)StateFlags.Transferring) != 0)
            {
                s.Append("Transferring\t");
            }
            if ((state & (uint)StateFlags.Negotiating) != 0)
            {
                s.Append("Negotiating\t");
            }
            if ((state & (uint)StateFlags.Stop) != 0)
            {
                s.Append("Stop\t");
            }
            if ((state & (uint)StateFlags.IsRequest) != 0)
            {
                s.Append("Request\t");
            }
            if ((state & (uint)StateFlags.IsDocument) != 0)
            {
                s.Append("Document\t");
            }
            if ((state & (uint)StateFlags.IsNetwork) != 0)
            {
                s.Append("Network\t");
            }
            if ((state & (uint)StateFlags.IsWindow) != 0)
            {
                s.Append("Window\t");
            }
            Console.Error.WriteLine(s.ToString());
#endif

            bool _start        = (state & (uint)StateFlags.Start) != 0;
            bool _negotiating  = (state & (uint)StateFlags.Negotiating) != 0;
            bool _transferring = (state & (uint)StateFlags.Transferring) != 0;
            bool _redirecting  = (state & (uint)StateFlags.Redirecting) != 0;
            bool _stop         = (state & (uint)StateFlags.Stop) != 0;
            bool _request      = (state & (uint)StateFlags.IsRequest) != 0;
            bool _document     = (state & (uint)StateFlags.IsDocument) != 0;
            bool _network      = (state & (uint)StateFlags.IsNetwork) != 0;
            bool _window       = (state & (uint)StateFlags.IsWindow) != 0;

            if (_start && _request && _document && !calledLoadStarted)
            {
                nsIDOMWindow win;
                progress.getDOMWindow(out win);
                nsIChannel channel = (nsIChannel)request;
                nsIURI     uri;
                channel.getURI(out uri);
                if (uri == null)
                {
                    currentUri = "about:blank";
                }
                else
                {
                    AsciiString spec = new AsciiString(String.Empty);
                    uri.getSpec(spec.Handle);
                    currentUri = spec.ToString();
                }

                calledLoadStarted = true;
                LoadStartedEventHandler eh = (LoadStartedEventHandler)(owner.Events [WebBrowser.LoadStartedEvent]);
                if (eh != null)
                {
                    AsciiString name = new AsciiString(String.Empty);
                    win.getName(name.Handle);

                    LoadStartedEventArgs e = new LoadStartedEventArgs(currentUri, name.ToString());
                    eh(this, e);
                    if (e.Cancel)
                    {
                        request.cancel(2152398850);                          //NS_BINDING_ABORTED
                    }
                }
                return;
            }

            if (_document && _request && _transferring)
            {
                nsIDOMWindow win;
                progress.getDOMWindow(out win);
                nsIChannel channel = (nsIChannel)request;
                nsIURI     uri;
                channel.getURI(out uri);
                if (uri == null)
                {
                    currentUri = "about:blank";
                }
                else
                {
                    AsciiString spec = new AsciiString(String.Empty);
                    uri.getSpec(spec.Handle);
                    currentUri = spec.ToString();
                }

                nsIDOMWindow topWin;
                win.getTop(out topWin);
                if (topWin == null || topWin.GetHashCode() == win.GetHashCode())
                {
                    owner.Reset();
                    nsIDOMDocument doc;
                    win.getDocument(out doc);
                    if (doc != null)
                    {
                        owner.document = new Mono.Mozilla.DOM.Document(owner, doc);
                    }
                }

                LoadCommitedEventHandler eh = (LoadCommitedEventHandler)(owner.Events[WebBrowser.LoadCommitedEvent]);
                if (eh != null)
                {
                    LoadCommitedEventArgs e = new LoadCommitedEventArgs(currentUri);
                    eh(this, e);
                }
                return;
            }

            if (_document && _request && _redirecting)
            {
                nsIDOMWindow win;
                progress.getDOMWindow(out win);
                nsIChannel channel = (nsIChannel)request;
                nsIURI     uri;
                channel.getURI(out uri);
                if (uri == null)
                {
                    currentUri = "about:blank";
                }
                else
                {
                    AsciiString spec = new AsciiString(String.Empty);
                    uri.getSpec(spec.Handle);
                    currentUri = spec.ToString();
                }
                return;
            }

            if (_stop && !_request && !_document && _network && _window)
            {
                calledLoadStarted = false;
                LoadFinishedEventHandler eh1 = (LoadFinishedEventHandler)(owner.Events[WebBrowser.LoadFinishedEvent]);
                if (eh1 != null)
                {
                    nsIDOMWindow win;
                    progress.getDOMWindow(out win);
                    LoadFinishedEventArgs e = new LoadFinishedEventArgs(currentUri);
                    eh1(this, e);
                }
                return;
            }

            if (_stop && !_request && _document && !_network && !_window)
            {
                nsIDOMWindow win;
                progress.getDOMWindow(out win);
                nsIDOMDocument doc;
                win.getDocument(out doc);
                if (doc != null)
                {
                    int hash = doc.GetHashCode();
                    if (owner.documents.ContainsKey(hash))
                    {
                        DOM.Document document = owner.documents[hash] as DOM.Document;

                        EventHandler eh1 = (EventHandler)(document.Events[DOM.Document.LoadStoppedEvent]);
                        if (eh1 != null)
                        {
                            eh1(this, null);
                        }
                    }
                }
                calledLoadStarted = false;
                return;
            }
#if debug
            Console.Error.WriteLine("{0} completed", s.ToString());
#endif
        }
Пример #3
0
        public void AddHandlersWithLoad(ChangedEventHandler changedEventHandler,
                                        LoadFinishedEventHandler loadFinishedEventHandler,
                                        PersistFinishedEventHandler persistFinishedEventHandler)
        {
            #if (CHATTY_DEBUG)
            string msg = "*** HRA OBJECT AddHandlersWithLoad on : " + this.ToString() + System.Environment.NewLine;
            if (changedEventHandler != null)
            {
                msg += "By: " + changedEventHandler.Target.ToString();
            }
            else if (loadFinishedEventHandler != null)
            {
                msg += "By: " + loadFinishedEventHandler.Target.ToString();
            }
            else if (persistFinishedEventHandler != null)
            {
                msg += "By: " + persistFinishedEventHandler.Target.ToString();
            }

            Logger.Instance.DebugToLog(msg);
            #endif


            if (changedEventHandler != null)
            {
                if (Changed == null)
                {
                    Changed += changedEventHandler;
                }
                else
                {
                    bool ok = true;
                    foreach (Delegate d in Changed.GetInvocationList())
                    {
                        if (d.Target == changedEventHandler.Target)
                        {
                            ok = false;
                        }
                    }
                    if (ok)
                    {
                        Changed += changedEventHandler;
                    }
                }
            }
            if (loadFinishedEventHandler != null)
            {
                if (Loaded == null)
                {
                    Loaded += loadFinishedEventHandler;
                }
                else
                {
                    bool ok = true;
                    foreach (Delegate d in Loaded.GetInvocationList())
                    {
                        if (d.Target == loadFinishedEventHandler.Target)
                        {
                            ok = false;
                        }
                    }
                    if (ok)
                    {
                        Loaded += loadFinishedEventHandler;
                    }
                }
            }
            if (persistFinishedEventHandler != null)
            {
                if (Persisted == null)
                {
                    Persisted += persistFinishedEventHandler;
                }
                else
                {
                    bool ok = true;
                    foreach (Delegate d in Persisted.GetInvocationList())
                    {
                        if (d.Target == persistFinishedEventHandler.Target)
                        {
                            ok = false;
                        }
                    }
                    if (ok)
                    {
                        Persisted += persistFinishedEventHandler;
                    }
                }
            }

            switch (HraState)
            {
            case States.Null:
                LoadObject();
                break;

            case States.Loading:
                break;

            case States.Ready:
                if (loadFinishedEventHandler != null)
                {
                    RunWorkerCompletedEventArgs dummy = new RunWorkerCompletedEventArgs(this, null, false);

                        #if (CHATTY_DEBUG)
                    string msg2 = "*** HRA OBJECT loadFinishedEventHandler Firing on : " + this.ToString() + System.Environment.NewLine;
                    msg2 += "FOR " + loadFinishedEventHandler.Target.ToString();
                    Logger.Instance.DebugToLog(msg2);
                        #endif

                    loadFinishedEventHandler.Invoke(null, dummy);
                }
                break;
            }
        }
Пример #4
0
        public void AddHandlersWithLoad(ChangedEventHandler changedEventHandler,
                                  LoadFinishedEventHandler loadFinishedEventHandler,
                                  PersistFinishedEventHandler persistFinishedEventHandler)
        {
            #if (CHATTY_DEBUG)
            string msg = "*** HRA OBJECT AddHandlersWithLoad on : " + this.ToString() + System.Environment.NewLine;
            if (changedEventHandler != null)
                msg+= "By: " + changedEventHandler.Target.ToString();
            else if (loadFinishedEventHandler != null)
                msg += "By: " + loadFinishedEventHandler.Target.ToString();
            else if (persistFinishedEventHandler != null)
                msg += "By: " + persistFinishedEventHandler.Target.ToString();

            Logger.Instance.DebugToLog(msg);

            #endif

            if (changedEventHandler != null)
            {
                if (Changed == null)
                    Changed += changedEventHandler;
                else
                {
                    bool ok = true;
                    foreach (Delegate d in Changed.GetInvocationList())
                    {
                        if (d.Target == changedEventHandler.Target)
                            ok = false;
                    }
                    if (ok)
                        Changed += changedEventHandler;
                }
            }
            if (loadFinishedEventHandler != null)
            {
                if (Loaded == null)
                    Loaded += loadFinishedEventHandler;
                else
                {
                    bool ok = true;
                    foreach (Delegate d in Loaded.GetInvocationList())
                    {
                        if (d.Target == loadFinishedEventHandler.Target)
                            ok = false;
                    }
                    if (ok)
                        Loaded += loadFinishedEventHandler;
                }
            }
            if (persistFinishedEventHandler != null)
            {
                if (Persisted == null)
                    Persisted += persistFinishedEventHandler;
                else
                {
                    bool ok = true;
                    foreach (Delegate d in Persisted.GetInvocationList())
                    {
                        if (d.Target == persistFinishedEventHandler.Target)
                            ok = false;
                    }
                    if (ok)
                        Persisted += persistFinishedEventHandler;
                }
            }

            switch (HraState)
            {
                case States.Null:
                    LoadObject();
                    break;

                case States.Loading:
                    break;

                case States.Ready:
                    if (loadFinishedEventHandler != null)
                    {
                        RunWorkerCompletedEventArgs dummy = new RunWorkerCompletedEventArgs(this, null, false);

                        #if (CHATTY_DEBUG)
                            string msg2 = "*** HRA OBJECT loadFinishedEventHandler Firing on : " + this.ToString() + System.Environment.NewLine;
                            msg2 += "FOR " + loadFinishedEventHandler.Target.ToString();
                            Logger.Instance.DebugToLog(msg2);
                        #endif

                        loadFinishedEventHandler.Invoke(null, dummy);
                    }
                    break;
            }
        }