Back to index

nux  3.0.0
Public Types | Public Member Functions | Protected Member Functions | Protected Attributes | Static Protected Attributes
nux::BaseKeyboardHandler Class Reference

#include <KeyboardHandler.h>

Collaboration diagram for nux::BaseKeyboardHandler:
Collaboration graph
[legend]

List of all members.

Public Types

enum  eKeyEntryType {
  eAlphaNumeric, eDecimalNumber, eIntegerNumber, eHexadecimalNumber,
  eBinaryNumber
}

Public Member Functions

 BaseKeyboardHandler ()
virtual ~BaseKeyboardHandler ()
virtual long ProcessKey (unsigned long eventType, unsigned long keysym, unsigned long state, char character, const Geometry &g)
NString GetTextLine () const
unsigned int GetLength () const
unsigned int GetCursorPosition () const
bool QueueDraw () const
int GetPositionX () const
int GetPositionY () const
void SetText (const char *str)
void SetText (const tstring &s)
void SetText (const NString &s)
void ClearText ()
void PlaceCaret (unsigned int cp)
void MoveCursorAtStart ()
void MoveCursorAtEnd ()
void SetKeyEntryType (eKeyEntryType keytype)
eKeyEntryType GetKeyEntryType ()
void SetClipRegion (const Geometry &g)
void GetTextSelection (int *start, int *end) const
int GetTextSelectionStart () const
int GetTextSelectionEnd () const
NString GetSelectedText () const
void SelectAllText ()
void UnselectAllText ()
bool IsTextSelected ()
void SetPrefix (NString)
void SetPostfix (NString)
void EnterFocus ()
unsigned int NextWordPosition (unsigned int cp)
unsigned int PrevWordPosition (unsigned int cp)
void ResolveCaretPosition (int x, int y)
void CaretAutoScroll (int x, int y, Geometry geo)
void MouseDown (int x, int y)
void MouseUp (int x, int y)
void MouseDrag (int x, int y)
void SetFont (ObjectPtr< FontTexture > Font)
ObjectPtr< FontTextureGetFont () const

Protected Member Functions

void DeleteSelectionText ()
void InsertChar (unsigned int character)
void AdjustCursorAndTextPosition ()

Protected Attributes

ObjectPtr< FontTexturem_Font
NString m_textline
int m_previous_cursor_position
bool m_need_redraw
int m_text_positionx
int m_text_positiony
Geometry m_clip_region
eKeyEntryType m_KeyType
int m_caret
 Caret position, in characters.
bool m_insert_mode
 If true, control is in insert mode.
int m_selection_start
 Starting position of the selection.
int m_first_visible_char
 First visible character in the edit control.
bool m_entering_focus
bool m_mouse_drag
bool m_mouse_inside_text_area

Static Protected Attributes

static int s_jump_offset_at_borders = 60
 When the caret reaches the left or right border of the control and there are more characters to reveals, the caret jumps back in the opposite direction by a number of pixel at the same moment when new characters are revealed.
static int s_cursor_width = 4

Detailed Description

Definition at line 41 of file KeyboardHandler.h.


Member Enumeration Documentation

Enumerator:
eAlphaNumeric 
eDecimalNumber 
eIntegerNumber 
eHexadecimalNumber 
eBinaryNumber 

Definition at line 44 of file KeyboardHandler.h.


Constructor & Destructor Documentation

Definition at line 35 of file KeyboardHandler.cpp.

Here is the call graph for this function:

Definition at line 52 of file KeyboardHandler.cpp.

  {
  }

Member Function Documentation

Definition at line 720 of file KeyboardHandler.cpp.

  {
    int str_width = GetFont()->GetStringWidth(m_textline.GetTCharPtr());
    NString temp0;

    if (m_caret > 0)
      temp0 = m_textline.GetSubString(0, m_caret - 1).GetTStringRef();
    else
      temp0 = "";

    //      0          1         2
    //      01234567|8901234567890123456789
    //      abcdefgh|ijklmn
    //
    //      Caret pos = 8
    //      temp0 = "abcdefg"
    //      temp1 = "abcdefgh"
    //      temp2 = "abcdefghi"

    NString temp1 = m_textline.GetSubString(0, m_caret).GetTStringRef();
    NString temp2 = m_textline.GetSubString(0, m_caret + 1).GetTStringRef();
    int str_width0 = GetFont()->GetStringWidth(temp0);
    int str_width1 = GetFont()->GetStringWidth(temp1);
    int str_width2 = GetFont()->GetStringWidth(temp2);


    if ((m_text_positionx + str_width1 + s_cursor_width) > m_clip_region.GetWidth())
    {
      // Hitting the end of the text box
      if (m_caret == (int) m_textline.Length())
      {
        m_text_positionx = - (str_width + (int) s_cursor_width - m_clip_region.GetWidth());
      }
      else
      {
        int PreviousCharWidth = str_width1 - str_width0;
        int Offset = Min<int> (s_jump_offset_at_borders, str_width + s_cursor_width - str_width1);

        while (Offset > m_clip_region.GetWidth())
        {
          Offset /= 2;
        }

        if (Offset < PreviousCharWidth)
          Offset = PreviousCharWidth;

        m_text_positionx -= Offset;

        if (m_text_positionx + str_width + s_cursor_width < (int) m_clip_region.GetWidth())
        {
          m_text_positionx = - (str_width + (int) s_cursor_width - m_clip_region.GetWidth());
        }
      }
    }
    else if ((m_text_positionx + str_width1) <= 0)
    {
      // Hitting the start of the text box
      if (m_caret == 0)
      {
        m_text_positionx = 0;
      }
      else
      {
        int NextCharWidth = str_width2 - str_width1;
        int Offset = Min<int> (s_jump_offset_at_borders, str_width1);

        while (Offset > m_clip_region.GetWidth())
        {
          Offset /= 2;
        }

        if (Offset < NextCharWidth)
          Offset = NextCharWidth;

        if (Offset > str_width1)
        {
          m_text_positionx = 0;
          return;
        }

        m_text_positionx += Offset;

        if (m_text_positionx > 0)
        {
          m_text_positionx = 0;
        }
      }
    }
  }

Here is the call graph for this function:

Here is the caller graph for this function:

void nux::BaseKeyboardHandler::CaretAutoScroll ( int  x,
int  y,
Geometry  geo 
)

Definition at line 208 of file KeyboardHandler.cpp.

  {
    if (m_entering_focus)
      return;

    if (m_textline.Length() == 0)
      return;

    int StrLength = (int) m_textline.Length();

    //nuxDebugMsg("[BaseKeyboardHandler::ResolveCaretPosition]");
    if (x < geo.x)
    {
      if (m_mouse_inside_text_area)
      {
        while (m_caret && (GetFont()->GetCharStringWidth(m_textline.GetTCharPtr(), m_caret) + m_text_positionx > 0))
        {
          --m_caret;
          //nuxDebugMsg("Group Add: %c", m_textline[m_caret]);
        }

        m_mouse_inside_text_area = false;
      }
      else if (m_caret)
      {
        --m_caret;
        //nuxDebugMsg("Add Char: %c", m_textline[m_caret]);
      }
      else
      {
        m_caret = 0;
      }
    }
    else if (x > geo.x + geo.GetWidth())
    {
      if (m_mouse_inside_text_area)
      {
        while ((m_caret != StrLength) && (GetFont()->GetCharStringWidth(m_textline.GetTCharPtr(), m_caret) + m_text_positionx < geo.GetWidth()))
        {
          ++m_caret;
          //nuxDebugMsg("Group Add: %c", m_textline[m_caret-1]);
        }

        m_mouse_inside_text_area = false;
      }
      else if (m_caret < StrLength)
      {
        ++m_caret;
        //nuxDebugMsg("Group Add: %c", m_textline[m_caret-1]);
      }
      else
      {
        m_caret = StrLength;
      }
    }

    AdjustCursorAndTextPosition();
  }

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 74 of file KeyboardHandler.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 56 of file KeyboardHandler.cpp.

  {
    int nFirst = Min(m_caret, m_selection_start);
    int nLast = Max(m_caret, m_selection_start);
    // Update caret and selection
    PlaceCaret(nFirst);
    m_selection_start = m_caret;

    // Remove the characters
    for (int i = nFirst; i < nLast; ++i)
      m_textline.Erase(nFirst, 1);
  }

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 152 of file KeyboardHandler.cpp.

  {
    m_entering_focus = true;
  }

Here is the caller graph for this function:

unsigned int nux::BaseKeyboardHandler::GetCursorPosition ( ) const [inline]

Definition at line 73 of file KeyboardHandler.h.

    {
      return m_caret;
    }

Here is the caller graph for this function:

Definition at line 918 of file KeyboardHandler.cpp.

  {
    return m_Font;
  }

Here is the caller graph for this function:

Definition at line 827 of file KeyboardHandler.cpp.

  {
    return m_KeyType;
  }

Here is the caller graph for this function:

unsigned int nux::BaseKeyboardHandler::GetLength ( ) const [inline]

Definition at line 68 of file KeyboardHandler.h.

    {
      return (unsigned int) m_textline.Length();
    }

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 81 of file KeyboardHandler.h.

    {
      return m_text_positionx;
    }

Here is the caller graph for this function:

Definition at line 85 of file KeyboardHandler.h.

    {
      return m_text_positiony;
    }

Definition at line 892 of file KeyboardHandler.cpp.

  {
    if (m_selection_start == m_caret)
    {
      return NString("");
    }
    else
    {
      NString s = m_textline.GetSubString(GetTextSelectionStart(), GetTextSelectionEnd() - GetTextSelectionStart()).GetTStringRef();
      return s;
    }
  }

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 64 of file KeyboardHandler.h.

    {
      return m_textline;
    }

Here is the caller graph for this function:

void nux::BaseKeyboardHandler::GetTextSelection ( int *  start,
int *  end 
) const

Definition at line 864 of file KeyboardHandler.cpp.

Here is the call graph for this function:

Definition at line 875 of file KeyboardHandler.cpp.

  {
    return Max(m_selection_start, m_caret);
  }

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 870 of file KeyboardHandler.cpp.

  {
    return Min(m_selection_start, m_caret);
  }

Here is the call graph for this function:

Here is the caller graph for this function:

void nux::BaseKeyboardHandler::InsertChar ( unsigned int  character) [protected]

Definition at line 69 of file KeyboardHandler.cpp.

  {

  }

Definition at line 905 of file KeyboardHandler.cpp.

  {
    if (m_caret != m_selection_start)
      return true;

    return false;
  }

Here is the caller graph for this function:

void nux::BaseKeyboardHandler::MouseDown ( int  x,
int  y 
)

Definition at line 129 of file KeyboardHandler.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

void nux::BaseKeyboardHandler::MouseDrag ( int  x,
int  y 
)

Definition at line 143 of file KeyboardHandler.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

void nux::BaseKeyboardHandler::MouseUp ( int  x,
int  y 
)

Definition at line 137 of file KeyboardHandler.cpp.

  {
    m_mouse_drag = false;
    m_entering_focus = false;
  }

Here is the caller graph for this function:

Definition at line 815 of file KeyboardHandler.cpp.

  {
    unsigned int StrLength = ( unsigned int) m_textline.Length();
    m_previous_cursor_position = m_caret;
    m_caret = StrLength;
  }

Here is the call graph for this function:

Definition at line 810 of file KeyboardHandler.cpp.

Here is the caller graph for this function:

unsigned int nux::BaseKeyboardHandler::NextWordPosition ( unsigned int  cp)

Definition at line 91 of file KeyboardHandler.cpp.

  {
    unsigned int num_char = (unsigned int) m_textline.Length();

    if (cp == num_char)
      return cp;

    unsigned int c = cp + 1;

    while (c < num_char - 1)
    {
      if (( m_textline[c] == char(' ')) && (m_textline[c+1] != char(' ')))
        return c + 1;

      c++;
    }

    return num_char;
  }

Here is the call graph for this function:

Here is the caller graph for this function:

void nux::BaseKeyboardHandler::PlaceCaret ( unsigned int  cp)

Definition at line 84 of file KeyboardHandler.cpp.

  {
    nuxAssert((nCP >= 0) && (nCP <= (unsigned int) m_textline.Length()));
    m_previous_cursor_position = m_caret;
    m_caret = nCP;
  }

Here is the call graph for this function:

Here is the caller graph for this function:

unsigned int nux::BaseKeyboardHandler::PrevWordPosition ( unsigned int  cp)

Definition at line 111 of file KeyboardHandler.cpp.

  {
    if (cp == 0)
      return 0;

    unsigned int c = cp - 1;

    while (c > 1)
    {
      if (( m_textline[c] != char(' ')) && (m_textline[c-1] == char(' ')))
        return c;

      c--;
    }

    return 0;
  }

Here is the caller graph for this function:

long nux::BaseKeyboardHandler::ProcessKey ( unsigned long  eventType,
unsigned long  keysym,
unsigned long  state,
char  character,
const Geometry g 
) [virtual]

Definition at line 267 of file KeyboardHandler.cpp.

  {
    //if(event.event_type != I_AsciiKey && event.event_type != I_KeyPress && event.event_type != I_KeyRelease)
    if (eventType != NUX_KEYDOWN)
      return 0;

    m_need_redraw = true;
    //unsigned key = event.ascii_code;
    unsigned key = 0;

    if (character != 0)
      key = character;

    long virtual_code = keysym;

    if (key != 0)
    {
      switch(m_KeyType)
      {
        case eDecimalNumber:
        {
          // Check if Key code is in ".0123456789";
          // Be careful because WM_KEYDOWN and WM_KEYUP send a key value
          // that gets here. If key pad 0 is press/released, WM_KEYDOWN/WM_KEYUP will send key = key_kp0.
          // It is WM_CHAR who send key = 0x30 = '0'. Therefore, do not use strchr(".0123456789", key) to test
          // if key is a digit character. When using strchr(".0123456789", key_kp0) we get a positive result
          // and the result is unexpected.
          if ((key >= char('0') && key <= char('9')) || (key == char('.')) || (key == char('-')) || (key == char('+')))
          {
            if ( m_caret != m_selection_start )
            {
              DeleteSelectionText();
            }

            // '-' and '+' can only be at position 0 of the number
            if ((key == char('-')) || (key == char('+')))
            {
              if ((m_caret == 0) && (m_textline[0] != char('+')) && (m_textline[0] != char('-')))
              {
                // If we are in overwrite mode and there is already
                // a char at the caret's position, simply replace it.
                // Otherwise, we insert the char as normal.
                if ( !m_insert_mode && m_caret < (int) m_textline.Length())
                {
                  m_textline[m_caret] = key;
                  PlaceCaret(m_caret + 1 );
                  m_selection_start = m_caret;
                }
                else
                {
                  // Insert the char
                  if ( m_caret <= (int) m_textline.Length())
                  {
                    m_textline.Insert(m_caret, 1, key);
                    PlaceCaret(m_caret + 1 );
                    m_selection_start = m_caret;
                  }
                }
              }
            }
            else
            {
              // If we are in overwrite mode and there is already
              // a char at the caret's position, simply replace it.
              // Otherwise, we insert the char as normal.
              if ( !m_insert_mode && m_caret < (int) m_textline.Length())
              {
                m_textline[m_caret] = key;
                PlaceCaret(m_caret + 1 );
                m_selection_start = m_caret;
              }
              else
              {
                // Insert the char
                if ( m_caret <= (int) m_textline.Length())
                {
                  m_textline.Insert(m_caret, 1, key);
                  PlaceCaret(m_caret + 1 );
                  m_selection_start = m_caret;
                }
              }
            }
          }

          break;
        }
        case eIntegerNumber:
        {
          // Check if Key code is in "0123456789";
          if ((key >= char('0') && key <= char('9')) || (key == char('-')) || (key == char('+')))
          {
            if ( m_caret != m_selection_start )
            {
              DeleteSelectionText();
            }

            // '-' and '+' can only be at position 0 of the number
            if ((key == char('-')) || (key == char('+')))
            {
              // If we are in overwrite mode and there is already
              // a char at the caret's position, simply replace it.
              // Otherwise, we insert the char as normal.
              if (!m_insert_mode && (m_caret < (int) m_textline.Length()))
              {
                m_textline[m_caret] = key;
                PlaceCaret(m_caret + 1 );
                m_selection_start = m_caret;
              }
              else
              {
                // Insert the char
                if ( m_caret <= (int) m_textline.Length())
                {
                  m_textline.Insert(m_caret, 1, key);
                  PlaceCaret(m_caret + 1 );
                  m_selection_start = m_caret;
                }
              }
            }
            else
            {
              // If we are in overwrite mode and there is already
              // a char at the caret's position, simply replace it.
              // Otherwise, we insert the char as normal.
              if (!m_insert_mode && (m_caret < (int) m_textline.Length()))
              {
                m_textline[m_caret] = key;
                PlaceCaret(m_caret + 1 );
                m_selection_start = m_caret;
              }
              else
              {
                // Insert the char
                if (m_caret <= (int) m_textline.Length())
                {
                  m_textline.Insert(m_caret, 1, key);
                  PlaceCaret(m_caret + 1 );
                  m_selection_start = m_caret;
                }
              }
            }
          }

          break;
        }

        case eHexadecimalNumber:
        {
          if ((key >= char('0') && key <= char('9')) || (key >= char('a') && key <= char('f')) || (key >= char('A') && key <= char('F')) || (key == char('-')) || (key == char('+')))
            //if(strchr("0123456789abcdefABCDEF", key))
          {
            if (m_caret != m_selection_start)
            {
              DeleteSelectionText();
            }

            // If we are in overwrite mode and there is already
            // a char at the caret's position, simply replace it.
            // Otherwise, we insert the char as normal.
            if (!m_insert_mode && (m_caret < (int) m_textline.Length()))
            {
              m_textline[m_caret] = key;
              PlaceCaret(m_caret + 1 );
              m_selection_start = m_caret;
            }
            else
            {
              // Insert the char
              if (m_caret <= (int) m_textline.Length())
              {
                m_textline.Insert(m_caret, 1, key);
                PlaceCaret(m_caret + 1 );
                m_selection_start = m_caret;
              }
            }

          }

          break;
        }

        case eBinaryNumber:
        {
          //if(strchr("01", key))
          if ((key >= char('0') && key <= char('1')))
          {
            if ( m_caret != m_selection_start )
            {
              DeleteSelectionText();
            }

            // If we are in overwrite mode and there is already
            // a char at the caret's position, simply replace it.
            // Otherwise, we insert the char as normal.
            if (!m_insert_mode && (m_caret < (int) m_textline.Length()))
            {
              m_textline[m_caret] = key;
              PlaceCaret(m_caret + 1 );
              m_selection_start = m_caret;
            }
            else
            {
              // Insert the char
              if (m_caret <= (int) m_textline.Length())
              {
                m_textline.Insert(m_caret, 1, key);
                PlaceCaret(m_caret + 1 );
                m_selection_start = m_caret;
              }
            }
          }

          break;
        }

        case eAlphaNumeric:
        default:
        {
          if (key > 0x1F && key < 0x7f)
          {
            if (m_caret != m_selection_start)
            {
              DeleteSelectionText();
            }

            // If we are in overwrite mode and there is already
            // a char at the caret's position, simply replace it.
            // Otherwise, we insert the char as normal.
            if (!m_insert_mode && (m_caret < (int) m_textline.Length()))
            {
              m_textline[m_caret] = key;
              PlaceCaret(m_caret + 1 );
              m_selection_start = m_caret;
            }
            else
            {
              // Insert the char
              if (m_caret <= (int) m_textline.Length())
              {
                m_textline.Insert(m_caret, 1, key);
                PlaceCaret(m_caret + 1 );
                m_selection_start = m_caret;
              }
            }

          }

          break;
        }
      }
    }

    // CTRL+C
    if ((virtual_code == NUX_VK_C) && (state & NUX_STATE_CTRL))
    {
      NString s = GetSelectedText();
#if defined(NUX_OS_WINDOWS)
      inlCopyTextToClipboard(s.GetTCharPtr());
#endif
    }

    // CTRL+V
    if ((virtual_code == NUX_VK_V) && (state & NUX_STATE_CTRL))
    {
#if defined(NUX_OS_WINDOWS)
      NString s = inlReadTextToClipboard();
#elif defined(NUX_OS_LINUX)
      NString s = "Paste not implemented yet";
#endif
      unsigned int start = GetTextSelectionStart();
      unsigned int end = GetTextSelectionEnd();
      m_textline.Replace(start, end - start, s.m_string);

      m_caret = start + (unsigned int) s.Length();
      UnselectAllText();
    }

    if ((virtual_code == NUX_VK_ESCAPE))
    {
      // If Text is selected, Unselect
      UnselectAllText();
    }

    if ((virtual_code == NUX_VK_ENTER))
    {
      SelectAllText();
    }

    if (virtual_code == NUX_VK_BACKSPACE)
    {
      if ( m_caret != m_selection_start )
      {
        DeleteSelectionText();
      }
      else
      {
        // Deleting one character
        if ( m_caret > 0 )
        {
          m_textline.Erase(m_caret - 1, 1);
          PlaceCaret(m_caret - 1 );

          m_selection_start = m_caret;
        }
      }
    }
    else if (virtual_code == NUX_VK_DELETE)
    {
      // Check if there is a text selection.
      if ( m_caret != m_selection_start )
      {
        DeleteSelectionText();
      }
      else
      {
        // Deleting one character
        if (m_caret < (int) m_textline.Length())
        {
          m_textline.Erase(m_caret, 1);
        }
      }
    }
    else if (virtual_code == NUX_VK_LEFT)
    {
      if (IsTextSelected() && ((state & NUX_STATE_SHIFT) == 0))
      {
        //m_caret = Min(m_caret, m_selection_start);
        if (m_caret)
          --m_caret;

        UnselectAllText();
      }
      else
      {
        if ( state & NUX_STATE_CTRL )
        {
          // Control is down. Move the caret to a new item
          // instead of a character.
          m_caret = PrevWordPosition( m_caret);
          PlaceCaret(m_caret );
        }
        else if ( m_caret > 0 )
          PlaceCaret(m_caret - 1 );

        if ((state & NUX_STATE_SHIFT) == 0)
        {
          // Shift is not down. Update selection
          // start along with the caret.
          m_selection_start = m_caret;
        }
      }
    }
    else if (virtual_code == NUX_VK_RIGHT)
    {
      if (IsTextSelected() && ((state & NUX_STATE_SHIFT) == 0))
      {
        m_caret = Max(m_caret, m_selection_start);
        UnselectAllText();
      }
      else
      {
        if ( state & NUX_STATE_CTRL)
        {
          // Control is down. Move the caret to a new item
          // instead of a character.
          m_caret = NextWordPosition( m_caret);
          PlaceCaret(m_caret );
        }
        else if (m_caret < (int) m_textline.Length())
          PlaceCaret(m_caret + 1 );

        if ((state & NUX_STATE_SHIFT) == 0)
        {
          // Shift is not down. Update selection
          // start along with the caret.
          m_selection_start = m_caret;
        }
      }
    }
    else if (virtual_code == NUX_VK_HOME)
    {
      if ((state & NUX_STATE_SHIFT) == 0)
      {
        PlaceCaret(0);
        // Shift is not down. Update selection
        // start along with the caret.
        m_selection_start = m_caret;
      }
      else
      {
        PlaceCaret(0 );
      }
    }
    else if (virtual_code == NUX_VK_END)
    {
      if ((state & NUX_STATE_SHIFT) == 0)
      {
        PlaceCaret((unsigned int) m_textline.Length());
        // Shift is not down. Update selection
        // start along with the caret.
        m_selection_start = m_caret;
      }
      else
      {
        PlaceCaret((unsigned int) m_textline.Length());
      }
    }
    else if (virtual_code == NUX_VK_ESCAPE)
    {
      return virtual_code;
    }
    else if ((virtual_code == NUX_VK_ENTER))
    {
      return virtual_code;
    }
    else
    {
      m_need_redraw = false;
    }

    if (virtual_code == NUX_VK_HOME)
    {
      m_text_positionx = 0;
    }
    else if (virtual_code == NUX_VK_END)
    {
      unsigned int str_width = GetFont()->GetStringWidth(m_textline.GetTCharPtr());

      if (str_width + s_cursor_width > (unsigned int) m_clip_region.GetWidth())
        m_text_positionx = m_clip_region.GetWidth() - (str_width + s_cursor_width);
      else
        m_text_positionx = 0;
    }
    else if (m_textline.Length() != 0)
    {
      AdjustCursorAndTextPosition();
      m_need_redraw = true;
    }
    else if (m_textline.Length() == 0)
    {
      ClearText();
      m_need_redraw = true;
    }


    return virtual_code;
  }

Here is the call graph for this function:

Here is the caller graph for this function:

bool nux::BaseKeyboardHandler::QueueDraw ( ) const [inline]

Definition at line 77 of file KeyboardHandler.h.

    {
      return m_need_redraw;
    }

Definition at line 157 of file KeyboardHandler.cpp.

  {
    if (m_entering_focus)
      return;

    if (m_textline.Length() == 0)
      return;

    unsigned int StrLength = (unsigned int) m_textline.Length();
    int total = m_text_positionx;
    unsigned int nCP = StrLength;

    for (unsigned int i = 0; i < StrLength; i++)
    {
      unsigned int cw0 = GetFont()->GetCharWidth(m_textline[i]);
      unsigned int cw1 = 0;

      if (i+1 < StrLength)
      {
        cw1 = GetFont()->GetCharWidth(m_textline[i+1]);
      }

      {
        if (total == x)
        {
          nCP = i;
          break;
        }
        else if (x < total + (int) cw0 / 2)
        {
          nCP = i;
          break;
        }
        else if (x < total + (int) cw1 / 2)
        {
          // I don't quite understand why we need this???
          nCP = i + 1;
          break;
        }
      }
      total += cw0;
    }

    PlaceCaret(nCP);

    if (!m_mouse_drag)
    {
      m_selection_start = m_caret;
    }
  }

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 880 of file KeyboardHandler.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 859 of file KeyboardHandler.cpp.

  {
    m_clip_region = g;
  }

Here is the caller graph for this function:

Definition at line 913 of file KeyboardHandler.cpp.

  {
    m_Font = Font;
  }

Definition at line 822 of file KeyboardHandler.cpp.

  {
    m_KeyType = keytype;
  }

Here is the caller graph for this function:

void nux::BaseKeyboardHandler::SetText ( const char *  str)

Definition at line 832 of file KeyboardHandler.cpp.

  {
    m_textline = str;
    // Every time we set the text, we reposition the cursor at the beginning of the text,
    // and the text position is set to zero with regard to the start of the geometry area.
    MoveCursorAtStart();
    m_selection_start = Min<int> (m_selection_start, (int) StringLength(str));
    m_caret = Min<int> (m_caret, (int) StringLength(str));

    if (m_caret < m_selection_start)
      m_selection_start = Max<int> (m_selection_start, (int) StringLength(str));
    else if (m_caret > m_selection_start)
      m_caret = Max<int> (m_caret, (int) StringLength(str));

    m_text_positionx = 0;
  }

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 849 of file KeyboardHandler.cpp.

  {
    SetText(s.c_str());
  }

Here is the call graph for this function:

Definition at line 854 of file KeyboardHandler.cpp.

  {
    SetText(s.GetTCharPtr());
  }

Here is the call graph for this function:

Definition at line 887 of file KeyboardHandler.cpp.

Here is the caller graph for this function:


Member Data Documentation

Caret position, in characters.

Definition at line 140 of file KeyboardHandler.h.

Definition at line 136 of file KeyboardHandler.h.

Definition at line 150 of file KeyboardHandler.h.

First visible character in the edit control.

Definition at line 143 of file KeyboardHandler.h.

Definition at line 130 of file KeyboardHandler.h.

If true, control is in insert mode.

Else, overwrite mode.

Definition at line 141 of file KeyboardHandler.h.

Definition at line 138 of file KeyboardHandler.h.

Definition at line 151 of file KeyboardHandler.h.

Definition at line 153 of file KeyboardHandler.h.

Definition at line 133 of file KeyboardHandler.h.

Definition at line 132 of file KeyboardHandler.h.

Starting position of the selection.

The caret marks the end.

Definition at line 142 of file KeyboardHandler.h.

Definition at line 134 of file KeyboardHandler.h.

Definition at line 135 of file KeyboardHandler.h.

Definition at line 131 of file KeyboardHandler.h.

int nux::BaseKeyboardHandler::s_cursor_width = 4 [static, protected]

Definition at line 160 of file KeyboardHandler.h.

When the caret reaches the left or right border of the control and there are more characters to reveals, the caret jumps back in the opposite direction by a number of pixel at the same moment when new characters are revealed.

Definition at line 159 of file KeyboardHandler.h.


The documentation for this class was generated from the following files: