home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 5 Edit / 05-Edit.zip / fed0217s.zip / source / editline.cpp < prev    next >
C/C++ Source or Header  |  2000-12-13  |  5KB  |  197 lines

  1. /*
  2. ** Module   :EDITLINE.CPP
  3. ** Abstract :Editable character string implementation
  4. **
  5. ** Copyright (C) Sergey I. Yevtushenko
  6. **
  7. ** Log: Mon  16/06/1997       Created
  8. */
  9.  
  10. #include <string.h>
  11.  
  12. #include <dialog.h>
  13. #include <keynames.h>
  14. #include <version.h>
  15.  
  16. EditLine::EditLine(int Row, int Col, int nRows, int nCols):
  17.     Control(Row, Col, nRows, nCols)
  18. {
  19.     pal_start = CL_EDITLINE_INACTIVE;
  20.     add_line(new Line);
  21.     set_hiliting(0);
  22. };
  23.  
  24. int EditLine::select(int i)
  25. {
  26.     pal_start = (i) ? CL_EDITLINE_ACTIVE : CL_EDITLINE_INACTIVE;
  27.     return Control::select(i);
  28. }
  29.  
  30. void EditLine::get_text(char *buff, int max_len)
  31. {
  32.     PLine ln = line(0);
  33.     int len = ln->len();
  34.     if(len > max_len)
  35.         len = max_len;
  36.     if(len)
  37.         memcpy(buff, ln->str, len);
  38.     buff[len] = 0;
  39. }
  40.  
  41. void EditLine::set_text(char *str)
  42. {
  43.     PLine ln = line(0);
  44.     ln->set(str);
  45.     line_begin(*this);
  46.     mark();
  47.     line_end(*this);
  48. }
  49.  
  50. void EditLine::draw()
  51. {
  52.     Buffer::draw(*this);
  53.  
  54.     if(active)
  55.     {
  56.         vio_cursor_pos(row+get_cur_row(), col+get_cur_col());
  57.         vio_cursor_type((get_ins_mode()) ? Underline:BigCursor);
  58.     }
  59. }
  60.  
  61. void EditLine::do_key(KeyInfo& k)
  62. {
  63. //    track_beg();
  64.     if(k.skey & shIsCtrl)
  65.     {
  66.         switch(k.skey & 0x00FF)
  67.         {
  68.             case kbLeft:
  69.  
  70.                 if(k.skey & shShift)
  71.                     mark();
  72.                 else
  73.                     unmark();
  74.  
  75.                 if(k.skey & shCtrl)
  76.                     word_left(*this);
  77.                 else
  78.                     cursor_left(*this);
  79.                 break;
  80.  
  81.             case kbRight:
  82.                 if(k.skey & shShift)
  83.                     mark();
  84.                 else
  85.                     unmark();
  86.                 if(k.skey & shCtrl)
  87.                     word_right(*this);
  88.                 else
  89.                     cursor_right(*this);
  90.                 break;
  91.  
  92.             case kbIns:
  93.                 if(k.skey & shCtrl) /* Ctlr+Ins */
  94.                 {
  95.                     if(Clipboard)
  96.                         delete Clipboard;
  97.                     Clipboard = copy();
  98.                     break;
  99.                 }
  100.  
  101.                 if(k.skey & shShift) /* Shift+Ins*/
  102.                 {
  103.                     if(get_mark_state())
  104.                     {
  105.                         clear(*this);
  106.                         unmark();
  107.                     }
  108.                     paste(*this, Clipboard);
  109.                     break;
  110.                 }
  111.                 set_ins_mode(1 - get_ins_mode());
  112.                 break;
  113.  
  114.             case kbBksp:
  115.                 if(k.skey & shAlt)
  116.                 {
  117.                     undo(*this);
  118.                     break;
  119.                 }
  120.                 if(k.skey & shCtrl)
  121.                 {
  122.                     del_word_left(*this);
  123.                     break;
  124.                 }
  125.                 back_space(*this);
  126.                 break;
  127.  
  128.             case kbEnd:
  129.                 if(k.skey & shShift)
  130.                     mark();
  131.                 else
  132.                     unmark();
  133.                 line_end(*this);
  134.                 break;
  135.  
  136.             case kbDel:
  137.                 if(k.skey & shShift)
  138.                 {
  139.                     if(Clipboard)
  140.                         delete Clipboard;
  141.                     Clipboard = cut(*this);
  142.                 }
  143.                 else
  144.                 {
  145.                     if(get_mark_state())
  146.                         clear(*this);
  147.                     else
  148.                         del_char(*this);
  149.                 }
  150.                 unmark();
  151.                 break;
  152.  
  153.             case kbHome:
  154.                 if(k.skey & shShift)
  155.                     mark();
  156.                 else
  157.                     unmark();
  158.                 line_begin(*this);
  159.                 break;
  160.  
  161.             case kbT:
  162.                 if(k.skey & shCtrl)
  163.                 {
  164.                     del_word_right(*this);
  165.                 }
  166.                 break;
  167.  
  168.             case kbL:
  169.             case kbU:
  170.                 if(k.skey & shAlt)
  171.                 {
  172.                     if((k.skey & 0xFF) == kbL)
  173.                         tolower(*this);
  174.                     else
  175.                         toupper(*this);
  176.                 }
  177.                 break;
  178.  
  179.             default:
  180.                 track_cancel();
  181.         }
  182.         if(abs_row() != 0)
  183.             goto_line(*this, 0);
  184.     }
  185.     else
  186.     {
  187.         if(get_mark_state())
  188.             clear(*this);
  189.         if(get_ins_mode())
  190.             ins_char(*this, k.key);
  191.         else
  192.             replace_char(*this, k.key);
  193.     }
  194.  
  195.     track_end();
  196. }
  197.