Esempio n. 1
0
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Subscribes to the Position changed event for all windows in current link set.
        /// </summary>
        /// <remarks>NOTE: subscribing to all windows in the link set fires the position changed
        /// event multiple times. However, if we don't do it and the first window happens not to
        /// have the same range as the other resources, then we don't get event.</remarks>
        /// ------------------------------------------------------------------------------------
        private void SetupPositionEvents()
        {
            m_cookies.Clear();
            try
            {
                if (m_libronixApp == null || m_PositionChangedBridge == null)
                {
                    return;
                }

                LbxWindows windows = m_libronixApp.Application.Windows;
                foreach (LbxWindow window in windows)
                {
                    if (window.Type == "resource")
                    {
                        LbxResourceWindowInfo windowInfo = (LbxResourceWindowInfo)window.Info;
                        if (windowInfo.ActiveDataType == "bible")
                        {
                            int                  cookie    = m_PositionChangedBridge.Connect(windowInfo);
                            LbxResourceView      view      = (LbxResourceView)window.View;
                            LbxResource          resource  = (LbxResource)view.Resource;
                            LbxResourcePositions positions =
                                (LbxResourcePositions)resource.get_Positions(null);
                            m_cookies.Add(new LinkInfo(windowInfo, cookie, positions));
                        }
                    }
                }
            }
            catch (COMException e)
            {
                Debug.Fail("Got exception in LibronixPositionHandler.SetupPositionEvents: " + e.Message);
                m_libronixApp = null;
            }
        }
Esempio n. 2
0
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Sends the scroll synchronization message to Libronix for all resource windows in
        /// the current link set.
        /// </summary>
        /// <param name="bcvRef">The reference in BBCCCVVV format.</param>
        /// <developernote>This method is called on the main thread</developernote>
        /// ------------------------------------------------------------------------------------
        public void SetLibronixFocus(int bcvRef)
        {
            if (m_fProcessingMessage)
            {
                return;
            }

            m_fProcessingMessage = true;
            try
            {
                LbxResourceWindowInfo info = null;
                string reference           = null;
                lock (m_Synchronizer)
                {
                    if (m_libronixApp == null)
                    {
                        return;
                    }

                    LbxWindowLinkSet linkSet = (LbxWindowLinkSet)m_libronixApp.WindowLinkSets[m_LinkSet];
                    LbxWindows       windows = m_libronixApp.Application.Windows;
                    foreach (LbxWindow window in windows)
                    {
                        if (window.Type == "resource" && linkSet.Windows.Find(window) >= 0)
                        {
                            info = (LbxResourceWindowInfo)window.Info;
                            if (info.ActiveDataType == "bible")
                            {
                                reference = ConvertFromBcv(bcvRef);
                                break;                                 // don't go on, the last info found may NOT have the right type.
                            }
                        }
                    }
                }
                // don't lock here since calling GoToReference causes a callback from Libronix
                if (info != null && reference != null)
                {
                    info.GoToReference(reference, 0, int.MaxValue, string.Empty, null);
                }
            }
            catch (Exception e)
            {
                // just ignore any errors
                Debug.Fail("Got exception in SetLibronixFocus: " + e.Message);
            }
            finally
            {
                m_fProcessingMessage = false;
            }
        }
Esempio n. 3
0
 /// <summary>
 /// See if we can get a current reference from some linked resource in Libronix.
 /// If so, and if it is different from our current one, raise the appropriate event.
 /// </summary>
 /// <param name="args"></param>
 /// <param name="sender"></param>
 void m_pollTimer_Tick(object sender, EventArgs args)
 {
     try
     {
         int bcvRef = -1;
         lock (m_Synchronizer)
         {
             if (m_libronixApp == null)
             {
                 return;
             }
             LbxWindows windows = m_libronixApp.Application.Windows;
             foreach (LbxWindow window in windows)
             {
                 if (window.Type == "resource")
                 {
                     LbxResourceWindowInfo windowInfo = (LbxResourceWindowInfo)window.Info;
                     if (windowInfo.ActiveDataType == "bible")
                     {
                         bcvRef = ConvertToBcv(windowInfo.ActiveReference);
                         if (bcvRef >= 0)
                         {
                             if (bcvRef != m_bcvRef)
                             {
                                 m_bcvRef = bcvRef;
                                 RaisePositionChangedEvent(new PositionChangedEventArgs(bcvRef));
                             }
                             // It's very important that we return, whether or not the reference is different,
                             // the first time we find a valid reference source. Otherwise, if Libronix is
                             // displaying two relevant windows at different locations, TE starts oscillating,
                             // since each tick one of them has the same reference as last time, so the OTHER
                             // is selected as the one to switch to.
                             return;
                         }
                     }
                 }
             }
         }
     }
     catch (Exception e)
     {
         Debug.Fail("Got exception in m_pollTimer_Tick: " + e.Message);
     }
 }