1 /* 2 * Copyright 2001-2007, Haiku. 3 * Copyright (c) 2003-4 Kian Duffy <myob@users.sourceforge.net> 4 * Parts Copyright (C) 1998,99 Kazuho Okui and Takashi Murai. 5 * 6 * Permission is hereby granted, free of charge, to any person obtaining 7 * a copy of this software and associated documentation files or portions 8 * thereof (the "Software"), to deal in the Software without restriction, 9 * including without limitation the rights to use, copy, modify, merge, 10 * publish, distribute, sublicense, and/or sell copies of the Software, 11 * and to permit persons to whom the Software is furnished to do so, subject 12 * to the following conditions: 13 * 14 * * Redistributions of source code must retain the above copyright notice, 15 * this list of conditions and the following disclaimer. 16 * 17 * * Redistributions in binary form must reproduce the above copyright notice 18 * in the binary, as well as this list of conditions and the following 19 * disclaimer in the documentation and/or other materials provided with 20 * the distribution. 21 * 22 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 23 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 24 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 25 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 26 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 27 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 28 * THE SOFTWARE. 29 * 30 */ 31 #ifndef TERMVIEW_H 32 #define TERMVIEW_H 33 34 35 #include "CurPos.h" 36 #include "TermConst.h" 37 #include "TermWindow.h" 38 39 #include <View.h> 40 #include <String.h> 41 #include <MessageRunner.h> 42 43 /* Cursor Blinking flag */ 44 #define CUROFF 0 45 #define CURON 1 46 47 #define MOUSE_THR_CODE 'mtcd' 48 #define RECT_BUF_SIZE 32 49 50 const unsigned char M_ADD_CURSOR [] = { 51 16, // Size 52 1, // Color depth 53 0, // Hot spot y 54 1, // Hot spot x 55 56 // Cursor image 57 0x70, 0x00, 58 0x48, 0x00, 59 0x48, 0x00, 60 0x27, 0xc0, 61 0x24, 0xb8, 62 0x12, 0x54, 63 0x10, 0x02, 64 0x78, 0x02, 65 0x98, 0x02, 66 0x84, 0x02, 67 0x60, 0x02, 68 0x18, 0x12, 69 0x04, 0x10, 70 0x02, 0x7c, 71 0x00, 0x10, 72 0x00, 0x10, 73 // Mask image 74 0x70, 0x00, 75 0x78, 0x00, 76 0x78, 0x00, 77 0x3f, 0xc0, 78 0x3f, 0xf8, 79 0x1f, 0xfc, 80 0x1f, 0xfe, 81 0x7f, 0xfe, 82 0xff, 0xfe, 83 0xff, 0xfe, 84 0x7f, 0xfe, 85 0x1f, 0xfe, 86 0x07, 0xfc, 87 0x03, 0xfc, 88 0x00, 0x10, 89 0x00, 0x10, 90 }; 91 92 class TermBuffer; 93 class CodeConv; 94 class BPopUpMenu; 95 class BScrollBar; 96 class BString; 97 class Shell; 98 99 class TermView : public BView { 100 public: 101 TermView(BRect frame, CodeConv *inCodeConv); 102 ~TermView(); 103 104 status_t AttachShell(Shell *shell); 105 void DetachShell(); 106 107 void SetTermFont(const BFont *halfFont, const BFont *fullFont); 108 void GetFontSize(int *width, int *height); 109 BRect SetTermSize(int rows, int cols, bool flag); 110 void SetTermColor(); 111 void SetMouseCursor(); 112 // void SetIMAware (bool); 113 void SetScrollBar(BScrollBar *scrbar); 114 BScrollBar *ScrollBar() const { return fScrollBar; }; 115 116 // Output Charactor 117 void PutChar(uchar *string, ushort attr, int width); 118 void PutCR(void); 119 void PutLF(void); 120 void PutNL(int num); 121 void SetInsertMode(int flag); 122 void InsertSpace(int num); 123 124 int TermDraw(const CurPos &start, const CurPos &end); 125 int TermDrawRegion(CurPos start, CurPos end); 126 int TermDrawSelectedRegion(CurPos start, CurPos end); 127 128 // Delete Charactor 129 void EraseBelow(); 130 void DeleteChar(int num); 131 void DeleteColumns(); 132 void DeleteLine(int num); 133 134 // Get and Set Cursor position 135 void SetCurPos(int x, int y); 136 void SetCurX(int x); 137 void SetCurY(int y); 138 139 void GetCurPos(CurPos *inCurPos); 140 int GetCurX(); 141 int GetCurY(); 142 143 void SaveCursor(); 144 void RestoreCursor(); 145 146 // Move Cursor 147 void MoveCurRight(int num); 148 void MoveCurLeft(int num); 149 void MoveCurUp(int num); 150 void MoveCurDown(int num); 151 152 // Cursor setting 153 void DrawCursor(); 154 void BlinkCursor(); 155 void SetCurDraw(bool flag); 156 void SetCurBlinking(bool flag); 157 158 // Scroll region 159 void ScrollRegion(int top, int bot, int dir, int num); 160 void SetScrollRegion(int top, int bot); 161 void ScrollAtCursor(); 162 163 // Other 164 void UpdateSIGWINCH(); 165 void DeviceStatusReport(int); 166 void UpdateLine(); 167 void ScrollScreen(); 168 void ScrollScreenDraw(); 169 void GetFrameSize(float *width, float *height); 170 void GetFontInfo(int *, int*); 171 bool Find(const BString &str, bool forwardSearch, bool matchCase, bool matchWord); 172 void GetSelection(BString &str); 173 174 protected: 175 virtual void AttachedToWindow(void); 176 virtual void Draw(BRect updateRect); 177 virtual void WindowActivated(bool active); 178 virtual void KeyDown(const char*, int32); 179 virtual void MouseDown(BPoint where); 180 virtual void MouseMoved(BPoint, uint32, const BMessage *); 181 182 virtual void FrameResized(float width, float height); 183 virtual void MessageReceived(BMessage* message); 184 185 private: 186 static int32 MouseTracking(void *); 187 188 status_t _InitMouseThread(void); 189 void DrawLines(int , int, ushort, uchar *, int, int, int, BView *); 190 void DoPrint(BRect updateRect); 191 void ResizeScrBarRange (void); 192 void DoFileDrop(entry_ref &ref); 193 194 // edit menu function. 195 void DoCopy(); 196 void DoPaste(); 197 void DoSelectAll(); 198 void DoClearAll(); 199 200 void WritePTY (const uchar *text, int num_byteses); 201 202 // Comunicate Input Method 203 // void DoIMStart (BMessage* message); 204 // void DoIMStop (BMessage* message); 205 // void DoIMChange (BMessage* message); 206 // void DoIMLocation (BMessage* message); 207 // void DoIMConfirm (void); 208 void ConfirmString (const char *, int32); 209 int32 GetCharFromUTF8String (const char *, char *); 210 int32 GetWidthFromUTF8String (const char *); 211 212 // Mouse select 213 void Select(CurPos start, CurPos end); 214 void AddSelectRegion(CurPos); 215 void ResizeSelectRegion(CurPos); 216 217 void DeSelect(); 218 bool HasSelection() const; 219 220 // select word function 221 void SelectWord(BPoint where, int mod); 222 void SelectLine(BPoint where, int mod); 223 224 // point and text offset conversion. 225 CurPos BPointToCurPos(const BPoint &p); 226 BPoint CurPosToBPoint(const CurPos &pos); 227 228 bool CheckSelectedRegion(const CurPos &pos); 229 inline void Redraw(int, int, int, int); 230 231 Shell *fShell; 232 233 // Font and Width 234 BFont fHalfFont; 235 BFont fFullFont; 236 int fFontWidth; 237 int fFontHeight; 238 int fFontAscent; 239 struct escapement_delta fEscapement; 240 241 // Flags 242 243 // Update flag (Set on PutChar). 244 bool fUpdateFlag; 245 246 // Terminal insertmode flag (use PutChar). 247 bool fInsertModeFlag; 248 249 // Scroll count, range. 250 int fScrollUpCount; 251 int fScrollBarRange; 252 253 // Frame Resized flag. 254 bool fFrameResized; 255 256 // Cursor Blinking, draw flag. 257 bool fCursorDrawFlag; 258 bool fCursorStatus; 259 bool fCursorBlinkingFlag; 260 bool fCursorRedrawFlag; 261 262 int fCursorHeight; 263 264 // terminal text attribute flag. 265 bool fInverseFlag; 266 bool fBoldFlag; 267 bool fUnderlineFlag; 268 269 // Cursor position. 270 CurPos fCurPos; 271 CurPos fCurStack; 272 273 int fBufferStartPos; 274 275 // Terminal rows and columns. 276 int fTermRows; 277 int fTermColumns; 278 279 // Terminal view pointer. 280 int fTop; 281 282 // Object pointer. 283 284 TermBuffer *fTextBuffer; 285 CodeConv *fCodeConv; 286 BScrollBar *fScrollBar; 287 288 // Offscreen Bitmap and View. 289 290 BRect fSrcRect; 291 BRect fDstRect; 292 293 // Color and Attribute. 294 295 rgb_color fTextForeColor, fTextBackColor; 296 rgb_color fCursorForeColor, fCursorBackColor; 297 rgb_color fSelectForeColor, fSelectBackColor; 298 uchar fTermAttr; 299 300 // Scroll Region 301 int fScrTop; 302 int fScrBot; 303 int fScrBufSize; 304 bool fScrRegionSet; 305 306 bool fMouseImage; 307 308 BPoint fPreviousMousePoint; 309 310 // view selection 311 CurPos fSelStart; 312 CurPos fSelEnd; 313 bool fMouseTracking; 314 315 // thread ID / flags. 316 thread_id fMouseThread; 317 bool fQuitting; 318 319 // Input Method parameter. 320 int fIMViewPtr; 321 CurPos fIMStartPos; 322 CurPos fIMEndPos; 323 BString fIMString; 324 bool fIMflag; 325 BMessenger fIMMessenger; 326 327 int32 fImCodeState; 328 }; 329 330 331 #endif //TERMVIEW_H 332