private bool SelectFirstRunWord() { Paragraph firstParagraph = Paragraphs.FirstBlock as Paragraph; if (firstParagraph == null) { return(false); } ARun firstWord = firstParagraph.Inlines.FirstInline as ARun; if (IsPlayingOnlyText) { while (firstWord != null && firstWord.IsImage) { firstWord = firstWord.LogicalNext(); } } if (firstWord == null) { return(false); } firstWord.Select(); return(true); }
private void Run_MouseLeave(object sender, MouseEventArgs e) { ARun run = sender as ARun; switch (CurrentState) { case State.Stop: run.Unhover(); break; case State.Play: run.Unhover(); break; case State.Segment: break; case State.Edit: run.Unhover(); break; case State.Caption: break; } }
private void InitiateRun(ARun run) { if (run is RunImage) { foreach (RunWord iRun in (run as RunImage).RunWords) { InitiateRun(iRun); } } run.MouseEnter += Run_MouseEnter; run.MouseLeave += Run_MouseLeave; run.MouseMove += Run_MouseMove; run.MouseLeftButtonDown += Run_MouseLeftButtonDown; }
private void Run_MouseMove(object sender, MouseEventArgs e) { ARun run = sender as ARun; switch (CurrentState) { case State.Stop: run.Cursor = Cursors.Hand; break; case State.Play: run.Cursor = Cursors.Hand; break; case State.Segment: if (run is RunImage) { run.Cursor = Cursors.Hand; break; } RichTextBox rtb = run.IsImage ? ImageCaptionRTB : BookContentRTB; rtb.Focus(); TextPointer pointer = rtb.GetPositionFromPoint(e.GetPosition(run), false); rtb.CaretPosition = pointer; TextPointerContext contextPrev = pointer.GetPointerContext(GoBackward); TextPointerContext contextNext = pointer.GetPointerContext(GoForward); if (contextNext == TextPointerContext.ElementEnd || contextPrev == TextPointerContext.ElementStart) { run.Cursor = Cursors.No; } else if (contextNext == contextPrev && contextNext == TextPointerContext.Text) { run.Cursor = Cursors.UpArrow; } else { run.Cursor = Cursors.Arrow; } break; case State.Edit: run.Cursor = Cursors.Hand; break; case State.Caption: break; } }
private bool SelectPreviousRunWord() { if (CurrentRunWord == null) { return(false); } ARun prevRun = CurrentARun.LogicalPrevious(); if (IsPlayingOnlyText) { while (prevRun != null && prevRun.IsImage) { prevRun = prevRun.LogicalPrevious(); } } if (prevRun == null) { return(false); } prevRun.Select(); return(true); }
private bool SelectNextRunWord() { if (CurrentRunWord == null) { return(false); } ARun nextRun = CurrentARun.LogicalNext(); if (IsPlayingOnlyText) { while (nextRun != null && nextRun.IsImage) { nextRun = nextRun.LogicalNext(); } } if (nextRun == null) { return(false); } nextRun.Select(); return(true); }
private void Run_MouseLeftButtonDown(object sender, MouseButtonEventArgs e) { ARun run = sender as ARun; run.Cursor = Cursors.Wait; switch (CurrentState) { case State.Stop: if (e.ClickCount == 1) { run.Select(); run.PlayCachedSound(); } else if (e.ClickCount == 2) { StopSound(); run.Select(); if (run is RunWord) { CurrentState = State.Edit; } } break; case State.Play: if (e.ClickCount == 1) { CurrentState = State.Stop; StopSound(); run.Select(); run.PlayCachedSound(); } else if (e.ClickCount == 2) { StopSound(); run.Select(); if (run is RunWord) { CurrentState = State.Edit; } } break; case State.Segment: if (e.ClickCount == 1) { if (run is RunImage) { run.Select(); break; } RunWord curRun = run as RunWord; RichTextBox rtb = curRun.IsImage ? ImageCaptionRTB : BookContentRTB; TextPointer curPointer = rtb.GetPositionFromPoint(e.GetPosition(run), false); if (curPointer == null) { return; } TextPointerContext contextPrev = curPointer.GetPointerContext(GoBackward); TextPointerContext contextNext = curPointer.GetPointerContext(GoForward); // MERGE if (contextNext == TextPointerContext.ElementEnd) { curRun.MergeWithNext(); } else if (contextPrev == TextPointerContext.ElementStart) { curRun.MergeWithPrev(); } // SPLIT else if (contextPrev == contextNext && contextNext == TextPointerContext.Text) { RunWord newRun = curRun.SplitAt(curPointer); InitiateRun(newRun); newRun.UpdateBackground(); //newRun.UpdateSegmentedBackground(); } } break; case State.Edit: if (e.ClickCount == 1) { CurrentState = State.Stop; run.Select(); run.PlayCachedSound(); } else if (e.ClickCount == 2) { run.Select(); if (run is RunWord) { CurrentState = State.Edit; } } break; case State.Caption: break; } run.Cursor = Cursors.Hand; }