1 /** 2 * Copyright (c) 2014 Roy Lu <roymercadian@gmail.com> 3 * 4 * This program is free software; you can redistribute it and/or modify 5 * it under the terms of the GNU General Public License as published by 6 * the Free Software Foundation; either version 2 of the License, or 7 * (at your option) any later version. 8 * 9 * This program is distributed in the hope that it will be useful, 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 * GNU General Public License for more details. 13 * 14 * You should have received a copy of the GNU General Public License 15 * along with this program; if not, write to the Free Software Foundation, 16 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 17 */ 18 19 #ifndef EDITOR_H 20 #define EDITOR_H 21 22 #ifdef __GNUG__ 23 #pragma interface "editor.h" 24 #endif 25 26 #include "termdata.h" 27 #include "telnetcon.h" 28 #include "termview.h" 29 #include "telnetview.h" 30 #include "editorview.h" 31 #include "site.h" 32 33 #include <string> 34 #include <vector> 35 #include <sstream> 36 #include <iostream> 37 using namespace std; 38 39 class CEditorView; 40 class CEditor: public CTelnetCon 41 { 42 public: 43 CEditor(CTelnetView* tView, CSite& SiteInfo); 44 ~CEditor(); 45 46 void ApplyAnsiColor(int bright, int blink, int fg, int bg); 47 int Send( void* buf, int len ); 48 GetEditorView()49 CEditorView* GetEditorView() { return (CEditorView*) m_pView; } 50 51 enum EditorAction 52 { 53 Init_Ansi_Editor, 54 Move_Up, 55 Move_Down, 56 Move_Left, 57 Move_Right, 58 Move_To_Home, 59 Move_To_End, 60 Move_To_Prev_Page, 61 Move_To_Next_Page, 62 New_Line, 63 Delete_Text, 64 Backspace_Text, 65 Set_Display_Frame_Plus, 66 Set_Display_Frame_Minus, 67 Set_Caret_Pos_X, 68 Set_Caret_Pos_Y, 69 Load_Editor_Text, 70 Load_Ansi_File, 71 Save_Ansi_File, 72 Paste_To_Editor, 73 Clear_Screen 74 }; 75 76 void EditorActions(int action, string arg = ""); 77 //void UpdateEditor(); 78 79 private: 80 void DoInsertText(string &text, const string &newText, int insertCol); 81 void DoDeleteText(string &line, int col); 82 void DoBackspaceText(); 83 84 int GetTextCharCount(const string &str); 85 86 void InitAnsiEditor(); 87 void SetDisplayFrame(int offset = 0); 88 void SetCaretPosX(); 89 void SetCaretPosY(); 90 void PasteToEditor(const string &str); 91 int ParseToRawPos(const string &text, int col, bool checkDBCS = true); 92 93 void MoveUp(); 94 void MoveDown(); 95 void MoveLeft(); 96 void MoveRight(); 97 void MoveToHome(); 98 void MoveToEnd(); 99 void MoveToPrevPage(); 100 void MoveToNextPage(); 101 void NewLine(); 102 void DeleteText(); 103 void BackspaceText(); 104 void LoadEditorText(); 105 void LoadAnsiFile(string filename); 106 void SaveAnsiFile(string filename); 107 void ClearScreen(); 108 109 void SetAnsiColor(int bright, int blink, int fg, int bg); 110 void SetColorToSelection(int bright, int blink, int fg, int bg); 111 void SetSelection(); 112 void SetTextColor(int screenRow, int startCol, int endCol); 113 void SetTextColor(int screenRow, int startCol, int endCol, int bright, int blink, int fg, int bg); 114 115 string GetLineText(int row, bool trim); 116 117 // Member Fields 118 vector<string> m_EditorText; 119 int m_DisplayStart; // indicate which row of m_EditorText should be loaded into screen. 120 int m_DisplayEnd; 121 122 bool m_AnsiBright; 123 bool m_AnsiBlink; 124 int m_AnsiFg; 125 int m_AnsiBg; 126 127 int m_SelectStartRow; 128 int m_SelectStartCol; 129 int m_SelectEndRow; 130 int m_SelectEndCol; 131 }; 132 133 134 #endif // EDITOR_H 135