/// ------------------------------------------------------------------------------------ /// <summary> /// Called when the position in Libronix changed. /// </summary> /// <param name="position">The position.</param> /// <param name="reference">The reference.</param> /// <param name="significance">The significance.</param> /// <param name="navigationID">The navigation ID.</param> /// ------------------------------------------------------------------------------------ private void OnPositionChangedInLibronix(string position, string reference, int significance, string navigationID) { if (m_fProcessingMessage) { return; } m_fProcessingMessage = true; try { int bcvRef = -1; lock (m_Synchronizer) { if (m_libronixApp == null) { return; } int i = 0; for (; i < m_cookies.Count; i++) { // Find the resource window that can display the current position. if (m_cookies[i].Positions.IsValid(position)) { break; } } Debug.Assert(i < m_cookies.Count, "Didn't find any Libronix resource that is able to show current position"); LbxWindowLinkSet linkSet = (LbxWindowLinkSet)m_libronixApp.WindowLinkSets[m_LinkSet]; if (i < m_cookies.Count && linkSet.Windows.Find(m_cookies[i].WindowInfo.Parent) >= 0) { bcvRef = ConvertToBcv(m_cookies[i].WindowInfo.ActiveReference); Debug.WriteLineIf(bcvRef < 0, "Got reference that couldn't be converted: " + m_cookies[i].WindowInfo.ActiveReference); } } if (bcvRef > -1) { RaisePositionChangedEvent(new PositionChangedEventArgs(bcvRef)); } } catch (Exception e) { Debug.Fail("Got exception in OnPositionChanged: " + e.Message); } finally { m_fProcessingMessage = false; } }
/// ------------------------------------------------------------------------------------ /// <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; } }