context: /*  * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  *																		*
  *	Copyright (C) 2007  Ahmet BUTUN (butun180@hotmail.com)				*
  *	http://www.ahmetbutun.net									        *
  *																		*
  *	This program is free software; you can redistribute it and/or		*
  *	modify it under the terms of the GNU General Public License as		*
  *	published by the Free Software Foundation; either version 2 of		*
  *	the License, or (at your option) any later version.					*
  *																		*
  *	This program is distributed in the hope that it will be useful,		*
  *	but WITHOUT ANY WARRANTY; without even the implied warranty of		*
  *	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU	*
  *	General Public License for more details.							*
  *																		*
  *	You should have received a copy of the GNU General Public License	*
  *	along with this program; if not, write to the Free Software			*
  *	Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.			*
  *																		*
  * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *  */
  
  using System;
  using System.ComponentModel;
  using System.Collections.Generic;
  using System.Text;
  using System.Windows.Forms;
  using System.Drawing;
  using System.Drawing.Drawing2D;
  
  namespace ActiveType.CustomControls
  {
      // IndexChanged Delegate
      public delegate void LetterIndexChangedEventHandler(object sender, EventArgs e);
  
      public class LessonOutputBox : RichTextBox
      {
          // IndexChanged Event
          public event LetterIndexChangedEventHandler LetterChanged = null;
  
          private LetterInputBox userLetterInputBox_ = null;
          private KeyboardLayout keyboardLayout_ = null;
  
          private int maxFontSize_ = 20;
          private int minFontSize_ = 8;
  
          private Color borderColor_ = Color.Black;
          private int borderWidth_ = 1;
  
          private string previousLetter_;
          private string currentLetter_;
          private string nextLetter_;
  
          private int letterIndex_ = 0;
  
          private Color selectionBackBolor_;
          private Font selectionFont_;
          private Font defaultSelectionFont_ = new Font("Verdana", 14, FontStyle.Regular);
          private Color selectionColor_;
  
          #region Constructor Logic
  
          public LessonOutputBox()
          {
              // set default properties
              base.BorderStyle = BorderStyle.None;
              base.BackColor = Color.White;
              base.ForeColor = Color.Black;
              base.Font = new Font("Verdana", 20, FontStyle.Regular);
  
              BaseSelectionColor = Color.Red;
              BaseSelectionBackColor = Color.Yellow;
              BaseSelectionFont = defaultSelectionFont_;
          }
  
          #endregion
  
          #region Public Properties
  
          [RefreshProperties(RefreshProperties.Repaint)]
          public Color BorderColor
          {
              get
              {
                  return borderColor_;
              }
              set
              {
                  if (borderColor_ != value)
                  {
                      borderColor_ = value;
  
                      Invalidate();
                  }
              }
          }
  
          [RefreshProperties(RefreshProperties.Repaint)]
          [DefaultValue(1)]
          public int BorderWidth
          {
              get
              {
                  return borderWidth_;
              }
              set
              {
                  if (borderWidth_ != value && value != 0)
                  {
                      borderWidth_ = value;
  
                      Invalidate();
                  }
              }
          }
  
          public KeyboardLayout KeyboardLayout
          {
              get
              {
                  return keyboardLayout_;
              }
              set
              {
                  keyboardLayout_ = value;
              }
          }
  
          public LetterInputBox UserLetterInputBox
          {
              get
              {
                  return userLetterInputBox_;
              }
              set
              {
                  userLetterInputBox_ = value;
              }
          }
  
          public int MaxFontSize
          {
              get
              {
                  return this.maxFontSize_;
              }
          }
  
          public int MinFontSize
          {
              get
              {
                  return this.minFontSize_;
              }
          }
  
          [Browsable(false)]
          public string PreviousLetter
          {
              get
              {
                  return previousLetter_;
              }
              set
              {
                  previousLetter_ = value;
              }
          }
  
          [Browsable(false)]
          public string CurrentLetter
          {
              get
              {
                  return currentLetter_;
              }
              set
              {
                  currentLetter_ = value;
  
                  if (this.KeyboardLayout != null)
                      this.KeyboardLayout.ExpectedKeyCodes = this.KeyboardLayout.GetKeyCodeQueue(currentLetter_);
              }
          }
  
          [Browsable(false)]
          public string NextLetter
          {
              get
              {
                  return nextLetter_;
              }
              set
              {
                  nextLetter_ = value;
              }
          }
  
          [Browsable(false)]
          public int LetterIndex
          {
              get
              {
                  return letterIndex_;
              }
              set
              {
                  if (value >= 0 && value < Text.Length)
                  {
                      letterIndex_ = value;
  
                      EventArgs e = new EventArgs();
  
                      // if letter index changed, update the properties, stats etc.
                      OnLetterIndexChanged(e);
  
                      // fire the event
  
gt:                     if (LetterChanged != null)