Logo Search packages:      
Sourcecode: yudit version File versions

void SEditor::keyPressed ( SWindowListener::SKey  key,
const SString s,
bool  ctrl,
bool  shift,
bool  meta 
) [virtual]

called when a key has been pressed.

Definition at line 111 of file SEditor.cpp.

References SCursorIndex::before, SEncoder::decode(), SEncoder::encode(), fKey(), STextIndex::index, STextIndex::line, pasteText(), redo(), SBinVector< Type >::remove(), SBinVector< Type >::size(), SCursorIndex::textIndex, and undo().

Referenced by SYuditInput::clear(), and SYuditInput::keyPressed().

{
  if (editorIF == 0) return;

  if (key == SWindowListener::Key_Shift_R ||                      key==SWindowListener::Key_Meta_L ||
key==SWindowListener::Key_Meta_R ||
key==SWindowListener::Key_Control_R ||
key==SWindowListener::Key_Control_L ||  
key==SWindowListener::Key_Shift_L)
  {
     return;
  }
  
  /* Whoops - we did not receive keyrelease */
  //Enable selection with SHIFT, 
  // Addition by Maarten van Gompel <proycon@anaproy.homeip.net>
  if (editorIF->isSelecting() && !meta && !shift && !ctrl ) 
  {
   editorIF->endSelect();  
  }
  SString erasedString ;
  SCursorIndex b = editorIF->getCursorIndex();
  SCursorIndex a;
  SCursorIndex ba;
  SUndo::SType std;
  SS_Embedding embd =  editorIF->getDocumentEmbedding();
  cleared = false;
  SString lineBreak = paragBreak;
  if (ctrl||meta) lineBreak = SS_LB_LS;
  
  /* If there's a selection, erase it first before adding new input*/
  if ((key  != SWindowListener::Key_F1) &&
    (key  != SWindowListener::Key_F2) &&
    (key  != SWindowListener::Key_F3) &&
    (key  != SWindowListener::Key_F4) &&
    (key  != SWindowListener::Key_F5) &&
    (key  != SWindowListener::Key_F6) &&
    (key  != SWindowListener::Key_F7) &&
    (key  != SWindowListener::Key_F8) &&
    (key  != SWindowListener::Key_F9) &&
    (key  != SWindowListener::Key_F10) &&
    (key  != SWindowListener::Key_F11) &&
    (key  != SWindowListener::Key_F12) &&
    (key  != SWindowListener::Key_Control_R) &&
    (key  != SWindowListener::Key_Control_L) &&
    (key  != SWindowListener::Key_Meta_R) &&
    (key  != SWindowListener::Key_Meta_L) &&
    (key  != SWindowListener::Key_Alt_R) &&
    (key  != SWindowListener::Key_Alt_L) &&
    (key  != SWindowListener::Key_Left) &&
    (key  != SWindowListener::Key_Right) &&
    (key  != SWindowListener::Key_Up) &&
    (key  != SWindowListener::Key_Down) &&  
    (key  != SWindowListener::Key_Prior) &&
    (key  != SWindowListener::Key_Next) &&
    (key  != SWindowListener::Key_Home) &&
    (key  != SWindowListener::Key_End) &&  
    (key  != SWindowListener::Key_Escape) &&  
    (!ctrl) && (!meta))
  {
    std = SUndo::SS_EraseSelect;
    STextIndex mba = editorIF->getSelectedIndex(true);
    ba = SCursorIndex (mba.line, mba.index);
    erasedString = editorIF->eraseSelectedText();

    if (erasedString.size() != 0)
    {
      a = editorIF->getCursorIndex();
      add (SUndo(std, editorIF->getDirection (), embd, erasedString, b, a, ba));
    } 
  }
  switch (key)
  {
  case SWindowListener::Key_Escape:
   // vi
    if (vimode)
    {
      editorIF->setEditable(!editorIF->isEditable());
    }
    else
    {
      editorIF->focusOut();
    }
    return;
  case SWindowListener::Key_Home:
    if ((shift || ctrl || meta) && !editorIF->isSelecting()) { editorIF->startSelect(); }
    if (ctrl || meta)
    {
      editorIF->setCursorIndex(SCursorIndex(0,0));
      if (editorIF->isSelecting())
      {
        if (meta)
        {
            editorIF->selectText (editorIF->getCursorIndex());
        }
        else // ctrl should just go to end without selecting.
        {
           editorIF->deselectText();
        }
      }
    }
    else
    {
      SCursorIndex ti = editorIF->getCursorIndex();
      ti.textIndex.index = 0;
      ti.before = true;
      editorIF->setCursorIndex(ti);
      if (editorIF->isSelecting())
      {
         editorIF->selectText (editorIF->getCursorIndex());
      }
    }
    break;
  case SWindowListener::Key_End:
    if ((shift || ctrl || meta) && !editorIF->isSelecting()) { editorIF->startSelect(); }
    if (ctrl || meta)
    {
      editorIF->setCursorIndex(SCursorIndex(100000000,100000000));
      if (editorIF->isSelecting())
      {
        if (meta)
        {
           editorIF->selectText (editorIF->getCursorIndex());
        }
        else // ctrl should just go to end without selecting.
        {
           editorIF->deselectText();
        }
      }
    }
    else
    {
      SCursorIndex ti = editorIF->getCursorIndex();
      ti.textIndex.index = 100000000;
      ti.before =true;
      editorIF->setCursorIndex(ti);
      if (editorIF->isSelecting())
      {
         editorIF->selectText (editorIF->getCursorIndex());
      }
    }
    break;
  case SWindowListener::Key_Prior:
    if ((shift || ctrl || meta) && !editorIF->isSelecting()) { editorIF->startSelect(); }
    editorIF->pageUp();
    return;
  case SWindowListener::Key_Next:
    if ((shift || ctrl || meta) && !editorIF->isSelecting()) { editorIF->startSelect(); }
    editorIF->pageDown();
    return;
  case SWindowListener::Key_Up:
    if ((shift || ctrl || meta) && !editorIF->isSelecting()) { editorIF->startSelect(); }
    editorIF->caretUp();
    return;
  case SWindowListener::Key_Down:
    if ((shift || ctrl || meta) && !editorIF->isSelecting()) { editorIF->startSelect(); }
        editorIF->caretDown();
    return;
  case SWindowListener::Key_Left:
    if ((shift || ctrl || meta) && !editorIF->isSelecting()) { editorIF->startSelect(); }
    editorIF->caretLeft();
    return;
  case SWindowListener::Key_Right:
    if ((shift || ctrl || meta) && !editorIF->isSelecting()) { editorIF->startSelect(); }
    editorIF->caretRight();
    return;
  /*SGC*/
  case SWindowListener::Key_BackSpace:
    /* switch - delete a single character */
    if (erasedString.size() == 0)
    {
      std = SUndo::SS_BackSpaceOne;
      erasedString = editorIF->backspace();
      /* not even used */
      ba = editorIF->getCursorIndex();
      add (SUndo(std, editorIF->getDirection (), embd, erasedString, b, ba, ba));
    }
    return;
  case SWindowListener::Key_Delete:
    /* switch - backspace */
    if (erasedString.size() == 0)
    {
      std = SUndo::SS_EraseOne;
      erasedString = editorIF->erase();

      /* not even used */
      ba = editorIF->getCursorIndex();
      add (SUndo(std, editorIF->getDirection (), embd, erasedString, b, ba, ba));
    }
    return;
  case SWindowListener::Key_Enter:
    editorIF->insertDirtyText(lineBreak);
    ba = editorIF->getCursorIndex();
    if (cleared) return;
    a = editorIF->getCursorIndex();
    add (SUndo(SUndo::SS_Insert, editorIF->getDirection (), embd, lineBreak, b, a, ba));
    break;
  case SWindowListener::Key_Return:
    editorIF->insertDirtyText(lineBreak);
    ba = editorIF->getCursorIndex();
    if (cleared) return;
    a = editorIF->getCursorIndex();
    add (SUndo(SUndo::SS_Insert, editorIF->getDirection (), embd, lineBreak, b, a, ba));
    break;
  case SWindowListener::Key_F1:
    fKey (0, ctrl|shift|meta);
    break;
  case SWindowListener::Key_F2:
    fKey (1, ctrl|shift|meta);
    break;
  case SWindowListener::Key_F3:
    fKey (2, ctrl|shift|meta);
    break;
  case SWindowListener::Key_F4:
    fKey (3, ctrl|shift|meta);
    break;
  case SWindowListener::Key_F5:
    fKey (4, ctrl|shift|meta);
    break;
  case SWindowListener::Key_F6:
    fKey (5, ctrl|shift|meta);
    break;
  case SWindowListener::Key_F7:
    fKey (6, ctrl|shift|meta);
    break;
  case SWindowListener::Key_F8:
    fKey (7, ctrl|shift|meta);
    break;
  case SWindowListener::Key_F9:
    fKey (8, ctrl|shift|meta);
    break;
  case SWindowListener::Key_F10:
    fKey (9, ctrl|shift|meta);
    break;
  case SWindowListener::Key_F11:
    fKey (10, ctrl|shift|meta);
    break;
  case SWindowListener::Key_F12:
    fKey (11, ctrl|shift|meta);
    break;
  case SWindowListener::Key_B:
  case SWindowListener::Key_b:
    if (ctrl|meta)
    {
      if (ctrl && editorIF->isSelecting()) editorIF->endSelect();
      editorIF->pageUp ();
      break;
    }
  case SWindowListener::Key_c:
   if (ctrl|meta)
    {
      if (editorIF->isSelecting()) editorIF->endSelect();
      return; /* Automatic copy */
    }
  /* This is used with accelerator anyway - this is never called here */
  case SWindowListener::Key_Y:
  case SWindowListener::Key_y:
   if (ctrl|meta)
    {
      editorIF->setDirection (SS_DR_L);
      break;
    }
  case SWindowListener::Key_D:
  case SWindowListener::Key_d:
   if (ctrl|meta)
    {
      if (editorIF->getDirection () != SS_DR_RO)
      {
        editorIF->setDirection (SS_DR_RO);
      }
      else 
      {
        editorIF->setDirection (SS_DR_LO);
      }
      break;
    }
  /* This is used with accelerator anyway - this is never called here */
  case SWindowListener::Key_E:
  case SWindowListener::Key_e:
   if (ctrl|meta)
    {
      if (editorIF->getDirection () != SS_DR_RE)
      {
        editorIF->setDirection (SS_DR_RE);
      }
      else 
      {
        editorIF->setDirection (SS_DR_LE);
      }
      break;
    }
  case SWindowListener::Key_F:
  case SWindowListener::Key_f:
    if (ctrl|meta)
    {
      if (ctrl && editorIF->isSelecting()) editorIF->endSelect();
      editorIF->pageDown ();
      break;
    }
  case SWindowListener::Key_H:
  case SWindowListener::Key_h:
    if (ctrl|meta)
    {
      if (ctrl && editorIF->isSelecting()) editorIF->endSelect();
      editorIF->caretLeft ();
      break;
    }
  case SWindowListener::Key_J:
  case SWindowListener::Key_j:
  case SWindowListener::Key_N:
  case SWindowListener::Key_n:
    if (ctrl||meta)
    {
      if (ctrl && editorIF->isSelecting()) editorIF->endSelect();
      editorIF->caretDown ();
      break;
    }
  case SWindowListener::Key_K:
  case SWindowListener::Key_k:
    if (ctrl|meta)
    {
      if (ctrl && editorIF->isSelecting()) editorIF->endSelect();
      editorIF->caretUp ();
      break;
    }
  case SWindowListener::Key_L:
  case SWindowListener::Key_l:
    if (ctrl||meta)
    {
      if (ctrl && editorIF->isSelecting()) editorIF->endSelect();
      editorIF->caretRight ();
      break;
    }
  case SWindowListener::Key_M:
  case SWindowListener::Key_m:
    if (ctrl)
    {
      editorIF->endSelect();
      editorIF->setCursorIndex(SCursorIndex(b.textIndex.line, 0));
      STextIndex mba = editorIF->getIndexAfterLineBreak ();
      ba = SCursorIndex (mba.line, mba.index);
      erasedString =  editorIF->eraseText(mba);
      if (cleared) return;
      if (erasedString.size() != 0)
      {
        a = editorIF->getCursorIndex();
        add (SUndo(SUndo::SS_Erase, editorIF->getDirection (), embd,  
             erasedString, b, a, ba));
      }
      break;
    }
  case SWindowListener::Key_R:
  case SWindowListener::Key_r:
    if (ctrl)
    {
      redo ();
      break;
    }
  case SWindowListener::Key_U:
  case SWindowListener::Key_u:
    if (ctrl)
    {
      undo ();
      break;
    }
  case SWindowListener::Key_v:
   if (ctrl) 
    {
      if (editorIF->isSelecting()) editorIF->endSelect();
      pasteText(b);
      return;
    }
  case SWindowListener::Key_V:
    if (ctrl|meta)
    {
      if (editorIF->isSelecting()) editorIF->endSelect();
      pasteText (b);
      return;
    }
  case SWindowListener::Key_X:
  case SWindowListener::Key_x:
    if (ctrl | meta)
    {
      /* switch - delete */
      std = SUndo::SS_EraseSelect;
      STextIndex mba = editorIF->getSelectedIndex(true);
      erasedString = editorIF->eraseSelectedText();
      if (cleared) return;
      if (erasedString.size() != 0)
      {
        a = editorIF->getCursorIndex();
        add (SUndo(std, editorIF->getDirection (), embd,  erasedString, b, a, ba));
      }
      break;
    }
  case SWindowListener::Key_Send:
  default:
    if (vimode && key != SWindowListener::Key_Send &&
        s == ":" && !editorIF->isEditable())
    {
      /* push the focus to the command window. */
      editorIF->focusOut();
      break;
    }
    SEncoder enc;
    SV_UCS4 ustr = enc.decode(s);
    while (ustr.size() && editorIF->addComposing(ustr[0]))
    {
      std = SUndo::SS_ComposeOne;
      a = editorIF->getCursorIndex();
      SS_UCS4 u4 = ustr[0];
      /* hack, string stores u4 */
      add (SUndo(std, editorIF->getDirection (), embd,  
        SString((char*)&u4, sizeof (u4)), a, a, a));
      ustr.remove (0);
    }
    SString sstr = enc.encode (ustr);
    if (sstr.size())
    {
      b = editorIF->getCursorIndex();
      editorIF->insertDirtyText(sstr);
      ba = editorIF->getCursorIndex();
      a = editorIF->getCursorIndex();
      add (SUndo(SUndo::SS_Insert, editorIF->getDirection (), embd,
          sstr, b, a, ba));
    }
    else /* to update glyph info */
    {
      a = editorIF->getCursorIndex();
      editorIF->setCursorIndex(a);
    }
  }


  
}


Generated by  Doxygen 1.6.0   Back to index