diff --git a/src/apps/terminal/CurPos.cpp b/src/apps/terminal/CurPos.cpp index d0599fd477..9655268f47 100644 --- a/src/apps/terminal/CurPos.cpp +++ b/src/apps/terminal/CurPos.cpp @@ -1,65 +1,30 @@ /* + * Copyright (c) 2001-2005, Haiku, Inc. * Copyright (c) 2003-4 Kian Duffy * Parts Copyright (C) 1998,99 Kazuho Okui and Takashi Murai. + * Distributed under the terms of the MIT license. * - * Permission is hereby granted, free of charge, to any person obtaining - * a copy of this software and associated documentation files or portions - * thereof (the "Software"), to deal in the Software without restriction, - * including without limitation the rights to use, copy, modify, merge, - * publish, distribute, sublicense, and/or sell copies of the Software, - * and to permit persons to whom the Software is furnished to do so, subject - * to the following conditions: - * - * * Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * - * * Redistributions in binary form must reproduce the above copyright notice - * in the binary, as well as this list of conditions and the following - * disclaimer in the documentation and/or other materials provided with - * the distribution. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS - * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL - * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - * + * Authors: + * Kian Duffy */ - #include "CurPos.h" - - -/************************************************************************* - * - * Constructor and Destructor - * - ************************************************************************/ - CurPos::CurPos() { } - CurPos::CurPos(int32 X, int32 Y) { x = X; y = Y; } - CurPos::CurPos(const CurPos& cp) { x = cp.x; y = cp.y; } -//////////////////////////////////////////////////////////////////////////// -// CurPos -// Operator = -//////////////////////////////////////////////////////////////////////////// CurPos & CurPos::operator=(const CurPos& from) { @@ -68,10 +33,6 @@ CurPos::operator=(const CurPos& from) return *this; } -//////////////////////////////////////////////////////////////////////////// -// CurPos -// Set Function. -//////////////////////////////////////////////////////////////////////////// void CurPos::Set(int32 X, int32 Y) { @@ -79,105 +40,74 @@ CurPos::Set(int32 X, int32 Y) y = Y; } -//////////////////////////////////////////////////////////////////////////// -// CurPos -// Operator != -//////////////////////////////////////////////////////////////////////////// bool CurPos::operator!=(const CurPos& from) const { return ((x != from.x) || (y != from.y)); } -//////////////////////////////////////////////////////////////////////////// -// CurPos -// Operator == -//////////////////////////////////////////////////////////////////////////// bool CurPos::operator==(const CurPos& from) const { return ((x == from.x) && (y == from.y)); } -//////////////////////////////////////////////////////////////////////////// -// CurPos -// Operator + -//////////////////////////////////////////////////////////////////////////// CurPos CurPos::operator+(const CurPos& from) const { return CurPos(x + from.x, y + from.y); } -//////////////////////////////////////////////////////////////////////////// -// CurPos -// Operator - -//////////////////////////////////////////////////////////////////////////// + CurPos CurPos::operator- (const CurPos& from) const { return CurPos(x - from.x, y - from.y); } -//////////////////////////////////////////////////////////////////////////// -// CurPos -// Operator > -//////////////////////////////////////////////////////////////////////////// bool CurPos::operator> (const CurPos& from) const { - if (y > from.y) { - return true; - } else if (y == from.y && x > from.x) { - return true; - } - - return false; + if (y > from.y) + return true; + else + if (y == from.y && x > from.x) + return true; + + return false; } -//////////////////////////////////////////////////////////////////////////// -// CurPos -// Operator >= -//////////////////////////////////////////////////////////////////////////// bool CurPos::operator>= (const CurPos& from) const { - if (y > from.y) { - return true; - } else if (y == from.y && x >= from.x) { - return true; - } - - return false; + if (y > from.y) + return true; + else + if (y == from.y && x >= from.x) + return true; + + return false; } -//////////////////////////////////////////////////////////////////////////// -// CurPos -// Operator < -//////////////////////////////////////////////////////////////////////////// bool CurPos::operator< (const CurPos& from) const { - if (y < from.y) { - return true; - } else if (y == from.y && x < from.x) { - return true; - } - - return false; + if (y < from.y) + return true; + else + if (y == from.y && x < from.x) + return true; + + return false; } -//////////////////////////////////////////////////////////////////////////// -// CurPos -// Operator <= -//////////////////////////////////////////////////////////////////////////// bool CurPos::operator<= (const CurPos& from) const { - if (y < from.y) { - return true; - } else if (y == from.y && x <= from.x) { - return true; - } - - return false; + if (y < from.y) + return true; + else + if (y == from.y && x <= from.x) + return true; + + return false; } diff --git a/src/apps/terminal/CurPos.h b/src/apps/terminal/CurPos.h index 8b1d6f5387..af8681cf2a 100644 --- a/src/apps/terminal/CurPos.h +++ b/src/apps/terminal/CurPos.h @@ -1,33 +1,12 @@ /* + * Copyright (c) 2001-2005, Haiku, Inc. * Copyright (c) 2003-4 Kian Duffy * Parts Copyright (C) 1998,99 Kazuho Okui and Takashi Murai. + * Distributed under the terms of the MIT license. * - * Permission is hereby granted, free of charge, to any person obtaining - * a copy of this software and associated documentation files or portions - * thereof (the "Software"), to deal in the Software without restriction, - * including without limitation the rights to use, copy, modify, merge, - * publish, distribute, sublicense, and/or sell copies of the Software, - * and to permit persons to whom the Software is furnished to do so, subject - * to the following conditions: - * - * * Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * - * * Redistributions in binary form must reproduce the above copyright notice - * in the binary, as well as this list of conditions and the following - * disclaimer in the documentation and/or other materials provided with - * the distribution. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS - * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL - * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - * + * Authors: + * Kian Duffy */ - #ifndef CURPOS_H_INCLUDED #define CURPOS_H_INCLUDED @@ -35,26 +14,25 @@ class CurPos { - public: - int32 x; - int32 y; - - CurPos(); - CurPos(int32 X, int32 Y); - CurPos(const CurPos& cp); - - void Set(int32 X, int32 Y); - - CurPos &operator= (const CurPos &from); - CurPos operator+ (const CurPos&) const; - CurPos operator- (const CurPos&) const; - bool operator!= (const CurPos&) const; - bool operator== (const CurPos&) const; - bool operator> (const CurPos&) const; - bool operator>= (const CurPos&) const; - bool operator< (const CurPos&) const; - bool operator<= (const CurPos&) const; +public: + CurPos(); + CurPos(int32 X, int32 Y); + CurPos(const CurPos& cp); + + void Set(int32 X, int32 Y); + + CurPos &operator= (const CurPos &from); + CurPos operator+ (const CurPos&) const; + CurPos operator- (const CurPos&) const; + bool operator!= (const CurPos&) const; + bool operator== (const CurPos&) const; + bool operator> (const CurPos&) const; + bool operator>= (const CurPos&) const; + bool operator< (const CurPos&) const; + bool operator<= (const CurPos&) const; + int32 x; + int32 y; }; -#endif /* CURPOS_H_INCLUDED */ +#endif diff --git a/src/apps/terminal/MenuUtil.cpp b/src/apps/terminal/MenuUtil.cpp index 03d05a533a..0683893bbc 100644 --- a/src/apps/terminal/MenuUtil.cpp +++ b/src/apps/terminal/MenuUtil.cpp @@ -1,33 +1,12 @@ /* + * Copyright (c) 2001-2005, Haiku, Inc. * Copyright (c) 2003-4 Kian Duffy * Parts Copyright (C) 1998,99 Kazuho Okui and Takashi Murai. + * Distributed under the terms of the MIT license. * - * Permission is hereby granted, free of charge, to any person obtaining - * a copy of this software and associated documentation files or portions - * thereof (the "Software"), to deal in the Software without restriction, - * including without limitation the rights to use, copy, modify, merge, - * publish, distribute, sublicense, and/or sell copies of the Software, - * and to permit persons to whom the Software is furnished to do so, subject - * to the following conditions: - * - * * Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * - * * Redistributions in binary form must reproduce the above copyright notice - * in the binary, as well as this list of conditions and the following - * disclaimer in the documentation and/or other materials provided with - * the distribution. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS - * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL - * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - * + * Authors: + * Kian Duffy */ - #include #include #include @@ -44,7 +23,6 @@ extern PrefHandler *gTermPref; //#define LOCALE_FILE_DIR PREF_FOLDER"menu/" - BPopUpMenu * MakeMenu(ulong msg, const char **items, const char *defaultItemName) { @@ -62,7 +40,6 @@ MakeMenu(ulong msg, const char **items, const char *defaultItemName) return menu; } - int longname2op(const char *longname) { @@ -78,14 +55,12 @@ longname2op(const char *longname) return op; } - const char * op2longname(int op) { return encoding_table[op].name; } - void MakeEncodingMenu(BMenu *eMenu, int coding, bool flag) { @@ -98,22 +73,21 @@ MakeEncodingMenu(BMenu *eMenu, int coding, bool flag) eMenu->AddItem(new BMenuItem(e->name, msg, e->shortcut)); else eMenu->AddItem(new BMenuItem(e->name, msg)); - + if (i == coding) eMenu->ItemAt(i)->SetMarked(true); - + e++; i++; } } - void LoadLocaleFile(PrefHandler *pref) { char name[B_PATH_NAME_LENGTH]; const char *locale; - + locale = gTermPref->getString(PREF_GUI_LANGUAGE); // TODO: this effectively disables any locale support - which is okay for now sprintf(name, "%s%s", /*LOCALE_FILE_DIR*/"", locale); @@ -121,4 +95,3 @@ LoadLocaleFile(PrefHandler *pref) //if (pref->OpenText(name) < B_OK) // pref->OpenText(LOCALE_FILE_DEFAULT); } - diff --git a/src/apps/terminal/MenuUtil.h b/src/apps/terminal/MenuUtil.h index 7cf5161261..4c564cc619 100644 --- a/src/apps/terminal/MenuUtil.h +++ b/src/apps/terminal/MenuUtil.h @@ -1,33 +1,12 @@ /* + * Copyright (c) 2001-2005, Haiku, Inc. * Copyright (c) 2003-4 Kian Duffy * Parts Copyright (C) 1998,99 Kazuho Okui and Takashi Murai. + * Distributed under the terms of the MIT license. * - * Permission is hereby granted, free of charge, to any person obtaining - * a copy of this software and associated documentation files or portions - * thereof (the "Software"), to deal in the Software without restriction, - * including without limitation the rights to use, copy, modify, merge, - * publish, distribute, sublicense, and/or sell copies of the Software, - * and to permit persons to whom the Software is furnished to do so, subject - * to the following conditions: - * - * * Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * - * * Redistributions in binary form must reproduce the above copyright notice - * in the binary, as well as this list of conditions and the following - * disclaimer in the documentation and/or other materials provided with - * the distribution. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS - * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL - * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - * + * Authors: + * Kian Duffy */ - #ifndef MENUUTIL_H_INCLUDED #define MENUUTIL_H_INCLUDED @@ -41,16 +20,15 @@ class BPopUpMenu; class BMenu; class PrefHandler; - BPopUpMenu * MakeMenu(ulong msg, const char **items, +BPopUpMenu * MakeMenu(ulong msg, const char **items, const char *defaultItemName); - - int longname2op(const char *longname); - const char * op2longname(int op); - void MakeEncodingMenu(BMenu *eMenu, int coding, bool flag); - void LoadLocaleFile (PrefHandler *); +int longname2op(const char *longname); +const char * op2longname(int op); +void MakeEncodingMenu(BMenu *eMenu, int coding, bool flag); +void LoadLocaleFile (PrefHandler *); #ifdef __cplusplus } #endif -#endif //MENUUTIL_H_INCLUDED +#endif diff --git a/src/apps/terminal/TermBaseView.cpp b/src/apps/terminal/TermBaseView.cpp index e90988ed8c..4aeccb7987 100644 --- a/src/apps/terminal/TermBaseView.cpp +++ b/src/apps/terminal/TermBaseView.cpp @@ -1,82 +1,36 @@ /* + * Copyright (c) 2001-2005, Haiku, Inc. * Copyright (c) 2003-4 Kian Duffy * Parts Copyright (C) 1998,99 Kazuho Okui and Takashi Murai. + * Distributed under the terms of the MIT license. * - * Permission is hereby granted, free of charge, to any person obtaining - * a copy of this software and associated documentation files or portions - * thereof (the "Software"), to deal in the Software without restriction, - * including without limitation the rights to use, copy, modify, merge, - * publish, distribute, sublicense, and/or sell copies of the Software, - * and to permit persons to whom the Software is furnished to do so, subject - * to the following conditions: - * - * * Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * - * * Redistributions in binary form must reproduce the above copyright notice - * in the binary, as well as this list of conditions and the following - * disclaimer in the documentation and/or other materials provided with - * the distribution. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS - * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL - * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - * + * Authors: + * Kian Duffy */ - #include "TermBaseView.h" #include "TermView.h" -/************************************************************************ - * - * CONSTRUCTOR and DESTRUCTOR - * - ***********************************************************************/ - -//////////////////////////////////////////////////////////////////////////// -// TermBaseView () -// Constructor. -//////////////////////////////////////////////////////////////////////////// TermBaseView::TermBaseView (BRect frame, TermView *inTermView) - :BView (frame, "baseview", B_FOLLOW_ALL_SIDES, - B_WILL_DRAW | B_FRAME_EVENTS) + :BView(frame, "baseview", B_FOLLOW_ALL_SIDES, + B_WILL_DRAW | B_FRAME_EVENTS) { - - fTermView = inTermView; - + fTermView = inTermView; } -//////////////////////////////////////////////////////////////////////////// -// ~TermBaseView () -// Destructor. -//////////////////////////////////////////////////////////////////////////// TermBaseView::~TermBaseView () { } -/* - * PUBLIC MEMBER FUNCTIONS. - */ - -//////////////////////////////////////////////////////////////////////////// -// FrameResized (float, float) -// Dispatch frame resize event. -//////////////////////////////////////////////////////////////////////////// void TermBaseView::FrameResized (float width, float height) { - int font_width, font_height; - int cols, rows; - - fTermView->GetFontInfo (&font_width, &font_height); - - cols = (int)(width - VIEW_OFFSET * 2) / font_width; - rows = (int)(height - VIEW_OFFSET * 2)/ font_height; - - fTermView->ResizeTo (cols * font_width - 1, rows * font_height - 1); - + int font_width, font_height; + int cols, rows; + + fTermView->GetFontInfo (&font_width, &font_height); + + cols = (int)(width - VIEW_OFFSET * 2) / font_width; + rows = (int)(height - VIEW_OFFSET * 2)/ font_height; + + fTermView->ResizeTo (cols * font_width - 1, rows * font_height - 1); } diff --git a/src/apps/terminal/TermBuffer.cpp b/src/apps/terminal/TermBuffer.cpp index 31fbdb82a1..dd434062f4 100644 --- a/src/apps/terminal/TermBuffer.cpp +++ b/src/apps/terminal/TermBuffer.cpp @@ -1,31 +1,11 @@ /* + * Copyright (c) 2001-2005, Haiku, Inc. * Copyright (c) 2003-4 Kian Duffy * Parts Copyright (C) 1998,99 Kazuho Okui and Takashi Murai. + * Distributed under the terms of the MIT license. * - * Permission is hereby granted, free of charge, to any person obtaining - * a copy of this software and associated documentation files or portions - * thereof (the "Software"), to deal in the Software without restriction, - * including without limitation the rights to use, copy, modify, merge, - * publish, distribute, sublicense, and/or sell copies of the Software, - * and to permit persons to whom the Software is furnished to do so, subject - * to the following conditions: - * - * * Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * - * * Redistributions in binary form must reproduce the above copyright notice - * in the binary, as well as this list of conditions and the following - * disclaimer in the documentation and/or other materials provided with - * the distribution. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS - * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL - * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - * + * Authors: + * Kian Duffy */ /************************************************************************ @@ -69,7 +49,7 @@ c. 2byte status buffer. **Language environment. (Not impliment) --- half width character set --- -0 ... Wesern (Latin1 / ISO-8859-1, MacRoman) +0 ... Western (Latin1 / ISO-8859-1, MacRoman) 1 ... Central European(Latin2 / ISO-8859-2) 2 ... Turkish (Latin3 / ISO-8859-3) 3 ... Baltic (Latin4 / ISO-8859-4) @@ -85,7 +65,7 @@ c. 2byte status buffer. --- Universal character set --- 10 ... Unicode (UTF8) - * Varriables is set CodeConv class. + * Variables is set CodeConv class. * Unicode character width sets CodeConv::UTF8FontWidth member. JIS X 0201 (half width kana ideograph) character use 1 column, @@ -109,539 +89,429 @@ but it font is full width font on preference panel. extern PrefHandler *gTermPref; -//////////////////////////////////////////////////////////////////////////// -// -// TermBuffer class -// Constructor and Destructor. -// -//////////////////////////////////////////////////////////////////////////// TermBuffer::TermBuffer(int rows, int cols) { - mColSize = MAX_COLS; - mNowColSize = cols; - mRowSize = rows; - - mRowOffset = 0; - - //buffer_size = ARRAY_SIZE; - buffer_size = gTermPref->getInt32 (PREF_HISTORY_SIZE); - - /* Allocate buffer */ - mBase = (term_buffer**) malloc (sizeof (term_buffer*) * buffer_size); - - for(int i = 0; i < buffer_size; i++){ - mBase[i] = (term_buffer *) calloc (mColSize + 1, sizeof (term_buffer)); - } + mColSize = MAX_COLS; + mNowColSize = cols; + mRowSize = rows; + + mRowOffset = 0; + + //buffer_size = ARRAY_SIZE; + buffer_size = gTermPref->getInt32 (PREF_HISTORY_SIZE); + + // Allocate buffer + mBase = (term_buffer**) malloc (sizeof (term_buffer*) * buffer_size); + + for(int i = 0; i < buffer_size; i++) + mBase[i] = (term_buffer *) calloc (mColSize + 1, sizeof (term_buffer)); } -//////////////////////////////////////////////////////////////////////////// -// TermBuffer Destructer. -// -//////////////////////////////////////////////////////////////////////////// + TermBuffer::~TermBuffer() { - for(int i = 0; i < buffer_size; i++){ - free (mBase[i]); - } + for(int i = 0; i < buffer_size; i++) + free (mBase[i]); free(mBase); - } -//////////////////////////////////////////////////////////////////////////// -// int GetChar (row, col, *buf, attr) -// Get chracter from TermBuffer. -//////////////////////////////////////////////////////////////////////////// -/* This function moved to header file for effeciency */ + +// Gets a character from TermBuffer int TermBuffer::GetChar (int row, int col, uchar *buf, ushort *attr) { - term_buffer *ptr; - - ptr = (mBase[row % buffer_size] + col); - - if (ptr->status == A_CHAR) - memcpy (buf, (char *)(ptr->code), 4); - - *attr = ptr->attr; - - return ptr->status; -} - -//////////////////////////////////////////////////////////////////////////// -// int GetString (row, col, *buf, attr) -// Get String (length = num) from given position. -//////////////////////////////////////////////////////////////////////////// -int -TermBuffer::GetString (int row, int col, int num, - uchar *buf, ushort *attr) -{ - int count = 0, all_count = 0; - term_buffer *ptr; - - ptr = (mBase[row % buffer_size]); - ptr += col; - *attr = ptr->attr; - - if (ptr->status == NO_CHAR) { - /* - * Buffer is empty and No selected by mouse. - */ - do { - if (col >= mNowColSize) return -1; - - col++; - ptr++; - count--; - if (ptr->status == A_CHAR) - return count; - - if (mSelStart.y == row) { - if (col == mSelStart.x) - return count; - } - if (mSelEnd.y == row) { - if (col - 1 == mSelEnd.x) - return count; - } + term_buffer *ptr; - - }while (col <= num); - return count; - } - else if (IS_WIDTH(ptr->attr)) { - memcpy (buf, (char *)ptr->code, 4); - return 2; - } - - while (col <= num) { - memcpy (buf, ptr->code, 4); - all_count++; - - if (*buf == 0) { - *buf = ' '; - *(buf + 1) = '\0'; - } - if (ptr->attr != (ptr + 1)->attr){ - return all_count; - } - - buf = (uchar *)index ((char *)buf, 0x00); - ptr++; - col++; - - if (mSelStart.y == row) { - if (col == mSelStart.x) - return all_count; - } - if (mSelEnd.y == row) { - if (col - 1 == mSelEnd.x) - return all_count; - } - } - - return all_count; + ptr = (mBase[row % buffer_size] + col); + + if (ptr->status == A_CHAR) + memcpy (buf, (char *)(ptr->code), 4); + + *attr = ptr->attr; + + return ptr->status; } -//////////////////////////////////////////////////////////////////////////// -// void WriteChar (const CurPos &, const uchar *, ushort) -// Write character at cursor point. -//////////////////////////////////////////////////////////////////////////// +// Get a string (length = num) from given position. +int +TermBuffer::GetString (int row, int col, int num, uchar *buf, + ushort *attr) +{ + int count = 0, all_count = 0; + term_buffer *ptr; + + ptr = (mBase[row % buffer_size]); + ptr += col; + *attr = ptr->attr; + + if (ptr->status == NO_CHAR) { + + // Buffer is empty and No selected by mouse. + do { + if (col >= mNowColSize) + return -1; + + col++; + ptr++; + count--; + if (ptr->status == A_CHAR) + return count; + + if (mSelStart.y == row) { + if (col == mSelStart.x) + return count; + } + + if (mSelEnd.y == row) { + if (col - 1 == mSelEnd.x) + return count; + } + }while (col <= num); + + return count; + } + else if (IS_WIDTH(ptr->attr)) { + memcpy (buf, (char *)ptr->code, 4); + return 2; + } + + while (col <= num) { + memcpy (buf, ptr->code, 4); + all_count++; + + if (*buf == 0) { + *buf = ' '; + *(buf + 1) = '\0'; + } + if (ptr->attr != (ptr + 1)->attr) + return all_count; + + buf = (uchar *)index ((char *)buf, 0x00); + ptr++; + col++; + + if (mSelStart.y == row) { + if (col == mSelStart.x) + return all_count; + } + if (mSelEnd.y == row) { + if (col - 1 == mSelEnd.x) + return all_count; + } + } + + return all_count; +} + +// Write a character at the cursor point. void TermBuffer::WriteChar (const CurPos &pos, const uchar *u, ushort attr) { - term_buffer *ptr; - - const int row = pos.y; - const int col = pos.x; - - ptr = (mBase[ROW(row)] + col); - memcpy ((char *)ptr->code, u, 4); - if (IS_WIDTH(attr)) - (ptr + 1)->status = IN_STRING; - - ptr->status = A_CHAR; - ptr->attr = attr; - - return; - + term_buffer *ptr; + + const int row = pos.y; + const int col = pos.x; + + ptr = (mBase[ROW(row)] + col); + memcpy ((char *)ptr->code, u, 4); + + if (IS_WIDTH(attr)) + (ptr + 1)->status = IN_STRING; + + ptr->status = A_CHAR; + ptr->attr = attr; } -//////////////////////////////////////////////////////////////////////////// -// void WriteCR (const CurPos &) -// Write CR status to buffer attribute. -//////////////////////////////////////////////////////////////////////////// +// Write CR status to buffer attribute. void TermBuffer::WriteCR (const CurPos &pos) { - int row = pos.y; - int col = pos.x; - - term_buffer *ptr = (mBase[ROW(row)] + col); - ptr->attr |= DUMPCR; - + int row = pos.y; + int col = pos.x; + + term_buffer *ptr = (mBase[ROW(row)] + col); + ptr->attr |= DUMPCR; } -//////////////////////////////////////////////////////////////////////////// -// InsertSpace (const CurPos &, int) -// Insert num space at cursor point. -//////////////////////////////////////////////////////////////////////////// +// Insert 'num' spaces at cursor point. void TermBuffer::InsertSpace (const CurPos &pos, int num) { - const int row = pos.y; - const int col = pos.x; - - for (int i = mNowColSize - num; i >= col; i--) { - *(mBase[ROW(row)] + i + num) = *(mBase[ROW(row)] + i); - } - - memset(mBase[ROW(row)] + col, 0, num * sizeof(term_buffer)); - - return; - + const int row = pos.y; + const int col = pos.x; + + for (int i = mNowColSize - num; i >= col; i--) + *(mBase[ROW(row)] + i + num) = *(mBase[ROW(row)] + i); + + memset(mBase[ROW(row)] + col, 0, num * sizeof(term_buffer)); } -//////////////////////////////////////////////////////////////////////////// -// void DeleteChar (const CurPos &, int) -// Delete num character at cursor point. -//////////////////////////////////////////////////////////////////////////// + +// Delete 'num' characters at cursor point. void TermBuffer::DeleteChar(const CurPos &pos, int num) { - const int row = pos.y; - const int col = pos.x; - - term_buffer *ptr = mBase[ROW(row)]; - size_t movesize = mNowColSize - (col + num); - - memmove (ptr + col, ptr + col + num, movesize * sizeof(term_buffer)); - memset (ptr + (mNowColSize - num), 0, num * sizeof(term_buffer)); - - return; - + const int row = pos.y; + const int col = pos.x; + + term_buffer *ptr = mBase[ROW(row)]; + size_t movesize = mNowColSize - (col + num); + + memmove (ptr + col, ptr + col + num, movesize * sizeof(term_buffer)); + memset (ptr + (mNowColSize - num), 0, num * sizeof(term_buffer)); } -//////////////////////////////////////////////////////////////////////////// -// EraseBelow (const CurPos &) -// Erase below character from cursor position. -//////////////////////////////////////////////////////////////////////////// +// Erase characters below cursor position. void TermBuffer::EraseBelow(const CurPos &pos) { - const int row = pos.y; - const int col = pos.x; - - memset (mBase[ROW(row)] + col, 0, (mColSize - col ) * sizeof (term_buffer)); - - for (int i = row; i < mRowSize; i++) - EraseLine (i); + const int row = pos.y; + const int col = pos.x; + + memset (mBase[ROW(row)] + col, 0, (mColSize - col ) * sizeof (term_buffer)); + + for (int i = row; i < mRowSize; i++) + EraseLine (i); } -//////////////////////////////////////////////////////////////////////////// -// ScrollRegion (int, int, int, int) -// Scroll terminal buffer region. -//////////////////////////////////////////////////////////////////////////// +// Scroll the terminal buffer region void TermBuffer::ScrollRegion(int top, int bot, int dir, int num) { - - if(dir == SCRUP){ - for(int i = 0; i < num; i++){ - - term_buffer *ptr = mBase[ROW(top)]; - - for(int j = top; j < bot; j++){ - mBase[ROW(j)] = mBase[ROW(j+1)]; - } - mBase[ROW(bot)] = ptr; - - EraseLine(bot); - } - }else{ - // scroll up - for(int i = 0; i < num; i++){ - term_buffer *ptr = mBase[ROW(bot)]; - - for(int j = bot; j > top; j--){ - mBase[ROW(j)] = mBase[ROW(j-1)]; - } - mBase[ROW(top)] = ptr; - - EraseLine(top); - } - } + if(dir == SCRUP) { + for(int i = 0; i < num; i++){ + + term_buffer *ptr = mBase[ROW(top)]; + + for(int j = top; j < bot; j++) + mBase[ROW(j)] = mBase[ROW(j+1)]; + + mBase[ROW(bot)] = ptr; + + EraseLine(bot); + } + } else { + // scroll up + for(int i = 0; i < num; i++){ + term_buffer *ptr = mBase[ROW(bot)]; + + for(int j = bot; j > top; j--) + mBase[ROW(j)] = mBase[ROW(j-1)]; + + mBase[ROW(top)] = ptr; + + EraseLine(top); + } + } } -//////////////////////////////////////////////////////////////////////////// -// ScrollLine (void) -// Scroll terminal buffer. -//////////////////////////////////////////////////////////////////////////// +// Scroll the terminal buffer. void TermBuffer::ScrollLine(void) { - for (int i = mRowSize; i < mRowSize * 2; i++) { - EraseLine (i); - } - - mRowOffset++; - - return; - + for (int i = mRowSize; i < mRowSize * 2; i++) + EraseLine (i); + + mRowOffset++; } -//////////////////////////////////////////////////////////////////////////// -// ResizeTo (int, int, int) -// Resize terminal buffer. -//////////////////////////////////////////////////////////////////////////// + +// Resize the terminal buffer. void TermBuffer::ResizeTo(int newRows, int newCols, int offset) { - int i; - + + // TODO: Why is this code #if 0'd? It should either be fixed or removed #if 0 - if (newCols > mColSize) { - for (i = 0; i < buffer_size; i++) { - mBase[i] = (ulong *) realloc (mBase[i], sizeof(ulong) * newCols); - base = mBase[i] + mColSize; - for (j= 0; j < newCols - mColSize; j++) { - *base++ = 0; - } - } - mColSize = newCols; - } + if (newCols > mColSize) { + for (i = 0; i < buffer_size; i++) { + mBase[i] = (ulong *) realloc (mBase[i], sizeof(ulong) * newCols); + base = mBase[i] + mColSize; + for (j= 0; j < newCols - mColSize; j++) + *base++ = 0; + } + mColSize = newCols; + } #endif - if ( newRows <= mRowSize) { - for (i = newRows; i <= mRowSize; i++) { - EraseLine (i); - } - } else { - for (i = mRowSize; i <= newRows * 2; i++) { - EraseLine (i); - } - } - - mNowColSize = newCols; - mRowOffset += offset; - mRowSize = newRows; - - return; - + if ( newRows <= mRowSize) { + for (i = newRows; i <= mRowSize; i++) + EraseLine (i); + } else { + for (i = mRowSize; i <= newRows * 2; i++) + EraseLine (i); + } + + mNowColSize = newCols; + mRowOffset += offset; + mRowSize = newRows; } -//////////////////////////////////////////////////////////////////////////// -// GetArraySize (void) -// Get buffer size. -//////////////////////////////////////////////////////////////////////////// +// Get the buffer's size. int32 TermBuffer::GetArraySize (void) { - return buffer_size; + return buffer_size; } -/* - * PRIVATE MEMBER FUNCTIONS. - */ - -//////////////////////////////////////////////////////////////////////////// -// EraseLine (int) -// Erase one column. -//////////////////////////////////////////////////////////////////////////// +// Erase one column. void TermBuffer::EraseLine (int row) { - memset (mBase[ROW(row)], 0, mColSize * sizeof (term_buffer)); - - return; + memset (mBase[ROW(row)], 0, mColSize * sizeof (term_buffer)); } -//////////////////////////////////////////////////////////////////////////// -// ClearAll() -// Clear contents of TermBuffer. -//////////////////////////////////////////////////////////////////////////// + +// Clear the contents of the TermBuffer. void TermBuffer::ClearAll (void) { - for(int i = 0; i < buffer_size; i++){ - memset (mBase[i], 0, mColSize * sizeof (term_buffer)); - } - mRowOffset = 0; - this->DeSelect (); + for(int i = 0; i < buffer_size; i++) + memset (mBase[i], 0, mColSize * sizeof (term_buffer)); + + mRowOffset = 0; + DeSelect (); } -//////////////////////////////////////////////////////////////////////////// -// Select() -// Mark Text Selected to given range. -//////////////////////////////////////////////////////////////////////////// + +// Mark text in the given range as selected void TermBuffer::Select(const CurPos &start, const CurPos &end) { - - if (end < start) { - mSelStart = end; - mSelEnd = start; - } - else { - mSelStart = start; - mSelEnd = end; - } - return; - + if (end < start) { + mSelStart = end; + mSelEnd = start; + } else { + mSelStart = start; + mSelEnd = end; + } } -//////////////////////////////////////////////////////////////////////////// -// DeSelect() -// Mark Text UnSelected to given range. -//////////////////////////////////////////////////////////////////////////// + +// Mark text in the given range as not selected void TermBuffer::DeSelect (void) { - - mSelStart.Set (-1, -1); - mSelEnd.Set (-1, -1); - return; - + mSelStart.Set (-1, -1); + mSelEnd.Set (-1, -1); } -//////////////////////////////////////////////////////////////////////////// -// CheckSelectedRegion (CurPos &) -// Check cursor position which be including selected area. -//////////////////////////////////////////////////////////////////////////// + +// Check cursor position which be including selected area. int TermBuffer::CheckSelectedRegion (const CurPos &pos) { - - if (mSelStart.y == pos.y || mSelEnd.y == pos.y) { - return true; - } - return false; - + return (mSelStart.y == pos.y || mSelEnd.y == pos.y); } -//////////////////////////////////////////////////////////////////////////// -// FindWord (CurPos &, CurPos *, CurPos *) -// Find word from TermBuffer -//////////////////////////////////////////////////////////////////////////// + +// Find a word in the TermBuffer bool TermBuffer::FindWord(const CurPos &pos, CurPos *start, CurPos *end) { - uchar buf[5]; - ushort attr; - int x, y, start_x; - - y = pos.y; - - // Search start point - for(x = pos.x - 1; x >= 0; x--){ - if((this->GetChar (y, x, buf, &attr) == NO_CHAR) || (*buf == ' ')){ - ++x; - break; - } - } - start_x = x; - - // Search end point - for(x = pos.x; x < mColSize; x++){ - if((this->GetChar (y, x, buf, &attr) == NO_CHAR) || (*buf == ' ')){ - --x; - break; - } - } - - if (start_x > x) return false; - - mSelStart.Set(start_x, y); - if (start != NULL){ - start->Set(start_x, y); - } - - mSelEnd.Set(x, y); - if (end != NULL){ - end->Set(x, y); - } - - return true; - + uchar buf[5]; + ushort attr; + int x, y, start_x; + + y = pos.y; + + // Search start point + for(x = pos.x - 1; x >= 0; x--){ + if((this->GetChar (y, x, buf, &attr) == NO_CHAR) || (*buf == ' ')){ + ++x; + break; + } + } + start_x = x; + + // Search end point + for(x = pos.x; x < mColSize; x++){ + if( (GetChar(y, x, buf, &attr) == NO_CHAR) || (*buf == ' ')) { + --x; + break; + } + } + + if(start_x > x) + return false; + + mSelStart.Set(start_x, y); + if(start != NULL) + start->Set(start_x, y); + + mSelEnd.Set(x, y); + if(end != NULL) + end->Set(x, y); + + return true; } -//////////////////////////////////////////////////////////////////////////// -// GetCharFromRegion (int, int, BString) -// Get one character from selected region. -//////////////////////////////////////////////////////////////////////////// + +// Get one character from the selected region. void TermBuffer::GetCharFromRegion (int x, int y, BString &str) { - uchar buf[5]; - ushort attr; - int status; - - status = GetChar(y, x, buf, &attr); - - switch(status){ - case NO_CHAR: - if (IS_CR (attr)) { - str += '\n'; - } else { - str += ' '; - } - - break; - - case IN_STRING: - break; - - default: - str += (const char *)&buf; - break; - } + uchar buf[5]; + ushort attr; + int status; + + status = GetChar(y, x, buf, &attr); + + switch(status) { + + case NO_CHAR: + if (IS_CR (attr)) + str += '\n'; + else + str += ' '; + break; + + case IN_STRING: + break; + + default: + str += (const char *)&buf; + break; + } } -//////////////////////////////////////////////////////////////////////////// -// AvoidWaste (BString str) -// Delete useless char at end of line, and convert LF code. -//////////////////////////////////////////////////////////////////////////// +// Delete useless char at end of line and convert LF code. inline void TermBuffer::AvoidWaste (BString &str) { - int32 len, point; - - start: - len = str.Length() - 1; - point = str.FindLast (' '); - - if (len > 0 && len == point) { - str.RemoveLast (" "); - goto start; - } - - // str += '\n'; - return; - + // TODO: Remove the goto + + int32 len, point; + + start: + + len = str.Length() - 1; + point = str.FindLast (' '); + + if (len > 0 && len == point) { + str.RemoveLast (" "); + goto start; + } + // str += '\n'; } -//////////////////////////////////////////////////////////////////////////// -// GetStringFromRegion (BString str) -// Get string from selected region. -//////////////////////////////////////////////////////////////////////////// +// Get a string from selected region. void TermBuffer::GetStringFromRegion(BString &str) { - int y; - - if(mSelStart.y == mSelEnd.y){ - y = mSelStart.y; - for(int x = mSelStart.x ; x <= mSelEnd.x; x++){ - GetCharFromRegion (x, y, str); - } - }else{ - y = mSelStart.y; - for(int x = mSelStart.x ; x < mNowColSize; x++){ - GetCharFromRegion (x, y, str); - } - AvoidWaste (str); - - for(y = mSelStart.y + 1 ; y < mSelEnd.y; y++){ - for(int x = 0 ; x < mNowColSize; x++){ - GetCharFromRegion (x, y, str); - } - AvoidWaste (str); - } - y = mSelEnd.y; - for(int x = 0 ; x <= mSelEnd.x; x++){ - GetCharFromRegion (x, y, str); - } - } + int y; + + if(mSelStart.y == mSelEnd.y) { + y = mSelStart.y; + for(int x = mSelStart.x ; x <= mSelEnd.x; x++) + GetCharFromRegion (x, y, str); + } else { + y = mSelStart.y; + for(int x = mSelStart.x ; x < mNowColSize; x++) + GetCharFromRegion (x, y, str); + AvoidWaste (str); + + for(y = mSelStart.y + 1 ; y < mSelEnd.y; y++){ + for(int x = 0 ; x < mNowColSize; x++) + GetCharFromRegion (x, y, str); + AvoidWaste (str); + } + + y = mSelEnd.y; + for(int x = 0 ; x <= mSelEnd.x; x++) + GetCharFromRegion (x, y, str); + } } diff --git a/src/apps/terminal/TermView.cpp b/src/apps/terminal/TermView.cpp index c52b61f626..61458722f2 100644 --- a/src/apps/terminal/TermView.cpp +++ b/src/apps/terminal/TermView.cpp @@ -1,33 +1,12 @@ /* + * Copyright (c) 2001-2005, Haiku, Inc. * Copyright (c) 2003-4 Kian Duffy * Parts Copyright (C) 1998,99 Kazuho Okui and Takashi Murai. + * Distributed under the terms of the MIT license. * - * Permission is hereby granted, free of charge, to any person obtaining - * a copy of this software and associated documentation files or portions - * thereof (the "Software"), to deal in the Software without restriction, - * including without limitation the rights to use, copy, modify, merge, - * publish, distribute, sublicense, and/or sell copies of the Software, - * and to permit persons to whom the Software is furnished to do so, subject - * to the following conditions: - * - * * Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * - * * Redistributions in binary form must reproduce the above copyright notice - * in the binary, as well as this list of conditions and the following - * disclaimer in the documentation and/or other materials provided with - * the distribution. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS - * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL - * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - * + * Authors: + * Kian Duffy */ - #include #include #include @@ -75,1743 +54,1448 @@ rgb_color gTermColorTable[16] = { {255, 255, 255, 0}, }; -extern PrefHandler *gTermPref; /* Global Preference Handler */ +// Global Preference Handler +extern PrefHandler *gTermPref; -/*************************************************************************** - * - * Constructor and Destructor. - * - **************************************************************************/ - -//////////////////////////////////////////////////////////////////////////// -// TermView () -// Constructor. -//////////////////////////////////////////////////////////////////////////// -TermView::TermView (BRect frame, CodeConv *inCodeConv) - :BView (frame, "termview", +TermView::TermView(BRect frame, CodeConv *inCodeConv) + :BView(frame, "termview", B_FOLLOW_NONE, B_WILL_DRAW | B_FRAME_EVENTS) { - int rows, cols; - - // Cursor reset. - fCurPos.Set(0, 0); - fCurStack.Set(0, 0); - fBufferStartPos = -1; - - rows = gTermPref->getInt32 (PREF_ROWS); - cols = gTermPref->getInt32 (PREF_COLS); - - fTermRows = rows; - fTermColumns = cols; - - fCodeConv = inCodeConv; - - // scroll pointer. - fTop = 0; - - // create TermBuffer and CodeConv Class. - fTextBuffer = new TermBuffer(rows, cols); - - // cursor Blinking and draw flag. - fCursorStatus = CURON; - fCursorDrawFlag = CURON; - fUpdateFlag = false; - fCursorBlinkingFlag = CURON; - - fSelStart.Set (-1, -1); - fSelEnd.Set (-1, -1); - fSelected = false; - fMouseTracking = false; - - // scroll bar varriables. - fScrollUpCount = 0; - fScrollBarRange = 0; - fScrRegionSet = 0; - fScrBufSize = gTermPref->getInt32 (PREF_HISTORY_SIZE); - - // resize flag. - fFrameResized = 0; - - // terminal mode flag. - fInsertModeFlag = MODE_OVER; - fInverseFlag = fBoldFlag = fUnderlineFlag = 0; - - // terminal scroll flag. - fScrTop = 0; - fScrBot = rows - 1; - - fPopMenu = NULL; - this->SetMouseButton (); - this->SetMouseCursor (); - fPreviousMousePoint.Set (0, 0); - - // SetIMAware (gTermPref->getInt32 (PREF_IM_AWARE)); - fIMflag = false; - - fViewThread = -1; - fMouseThread = -1; - fQuitting = 1; - this->InitViewThread(); - - fDrawRect_p = 0; + int rows, cols; + + // Cursor reset. + fCurPos.Set(0, 0); + fCurStack.Set(0, 0); + fBufferStartPos = -1; + + rows = gTermPref->getInt32(PREF_ROWS); + cols = gTermPref->getInt32(PREF_COLS); + + fTermRows = rows; + fTermColumns = cols; + + fCodeConv = inCodeConv; + + // scroll pointer. + fTop = 0; + + // create TermBuffer and CodeConv Class. + fTextBuffer = new TermBuffer(rows, cols); + + // cursor Blinking and draw flag. + fCursorStatus = CURON; + fCursorDrawFlag = CURON; + fUpdateFlag = false; + fCursorBlinkingFlag = CURON; + + fSelStart.Set(-1, -1); + fSelEnd.Set(-1, -1); + fSelected = false; + fMouseTracking = false; + + // scroll bar varriables. + fScrollUpCount = 0; + fScrollBarRange = 0; + fScrRegionSet = 0; + fScrBufSize = gTermPref->getInt32(PREF_HISTORY_SIZE); + + // resize flag. + fFrameResized = 0; + + // terminal mode flag. + fInsertModeFlag = MODE_OVER; + fInverseFlag = fBoldFlag = fUnderlineFlag = 0; + + // terminal scroll flag. + fScrTop = 0; + fScrBot = rows - 1; + + fPopMenu = NULL; + SetMouseButton(); + SetMouseCursor(); + fPreviousMousePoint.Set(0, 0); + + // SetIMAware(gTermPref->getInt32(PREF_IM_AWARE)); + fIMflag = false; + + fViewThread = -1; + fMouseThread = -1; + fQuitting = 1; + InitViewThread(); + + fDrawRect_p = 0; } -//////////////////////////////////////////////////////////////////////////// -// ~TermView () -// Destructor. -//////////////////////////////////////////////////////////////////////////// -TermView::~TermView () +TermView::~TermView() { // delete InputMessenger; delete fTextBuffer; fQuitting = 0; - kill_thread (fViewThread); - kill_thread (fMouseThread); - delete_sem (fDrawRectSem); + kill_thread(fViewThread); + kill_thread(fMouseThread); + delete_sem(fDrawRectSem); } -/*************************************************************************** - * - * Public Member Functions: - * - **************************************************************************/ - -//////////////////////////////////////////////////////////////////////////// -// GetFontSize (int &, int &) -// Get terminal font width and height size. -//////////////////////////////////////////////////////////////////////////// +// Get width and height for terminal font void -TermView::GetFontSize (int *width, int *height) +TermView::GetFontSize(int *width, int *height) { *width = fFontWidth; *height = fFontHeight; } -//////////////////////////////////////////////////////////////////////////// -// SetTermSize() -// Sets terninal rows and cols. -//////////////////////////////////////////////////////////////////////////// +// Set number of rows and columns in terminal BRect -TermView::SetTermSize (int rows, int cols, bool flag) +TermView::SetTermSize(int rows, int cols, bool flag) { - if (rows) fTermRows = rows; - if (cols) fTermColumns = cols; - - fTextBuffer->ResizeTo (fTermRows, fTermColumns, 0); - - fScrTop = 0; - fScrBot = fTermRows - 1; - - BRect r(0, 0, - fTermColumns * fFontWidth, - fTermRows * fFontHeight); - if (flag) { - ResizeTo (fTermColumns * fFontWidth -1, - fTermRows * fFontHeight -1); - } - - this->Invalidate (this->Frame()); - - return r; - + if(rows) + fTermRows = rows; + if(cols) + fTermColumns = cols; + + fTextBuffer->ResizeTo(fTermRows, fTermColumns, 0); + + fScrTop = 0; + fScrBot = fTermRows - 1; + + BRect r(0, 0, + fTermColumns * fFontWidth, + fTermRows * fFontHeight); + + if(flag) { + ResizeTo(fTermColumns * fFontWidth -1, + fTermRows * fFontHeight -1); + } + Invalidate(Frame()); + + return r; } -//////////////////////////////////////////////////////////////////////////// -// SetMouseButton() -// Sets mouse button assignment. -//////////////////////////////////////////////////////////////////////////// +// Set mouse button assignments void -TermView::SetMouseButton (void) +TermView::SetMouseButton(void) { - mSelectButton = - SetupMouseButton (gTermPref->getString(PREF_SELECT_MBUTTON)); - mSubMenuButton = - SetupMouseButton (gTermPref->getString(PREF_SUBMENU_MBUTTON)); - mPasteMenuButton = - SetupMouseButton (gTermPref->getString(PREF_PASTE_MBUTTON)); - - return; - + mSelectButton = SetupMouseButton(gTermPref->getString(PREF_SELECT_MBUTTON)); + mSubMenuButton = SetupMouseButton(gTermPref->getString(PREF_SUBMENU_MBUTTON)); + mPasteMenuButton = SetupMouseButton(gTermPref->getString(PREF_PASTE_MBUTTON)); } -//////////////////////////////////////////////////////////////////////////// -// SetMouseCursor() -// Sets mouse cursor image. -//////////////////////////////////////////////////////////////////////////// + +// Sets the mouse cursor image void -TermView::SetMouseCursor (void) +TermView::SetMouseCursor(void) { - if (!strcmp (gTermPref->getString (PREF_MOUSE_IMAGE), "Hand cursor")) - fMouseImage = false; - else - fMouseImage = true; - - return; - + if(!strcmp(gTermPref->getString(PREF_MOUSE_IMAGE), "Hand cursor")) + fMouseImage = false; + else + fMouseImage = true; } -//////////////////////////////////////////////////////////////////////////// -// SetTermColor() -// Sets terninal rows and cols. -//////////////////////////////////////////////////////////////////////////// +// Sets colors for the terminal void -TermView::SetTermColor (void) +TermView::SetTermColor(void) { - - fTextForeColor = gTermPref->getRGB (PREF_TEXT_FORE_COLOR); - fTextBackColor = gTermPref->getRGB (PREF_TEXT_BACK_COLOR); - fSelectForeColor = gTermPref->getRGB(PREF_SELECT_FORE_COLOR); - fSelectBackColor = gTermPref->getRGB(PREF_SELECT_BACK_COLOR); - fCursorForeColor = gTermPref->getRGB(PREF_CURSOR_FORE_COLOR); - fCursorBackColor = gTermPref->getRGB(PREF_CURSOR_BACK_COLOR); - - SetLowColor (fTextBackColor); - SetViewColor (fTextBackColor); - - return; - + fTextForeColor = gTermPref->getRGB(PREF_TEXT_FORE_COLOR); + fTextBackColor = gTermPref->getRGB(PREF_TEXT_BACK_COLOR); + fSelectForeColor = gTermPref->getRGB(PREF_SELECT_FORE_COLOR); + fSelectBackColor = gTermPref->getRGB(PREF_SELECT_BACK_COLOR); + fCursorForeColor = gTermPref->getRGB(PREF_CURSOR_FORE_COLOR); + fCursorBackColor = gTermPref->getRGB(PREF_CURSOR_BACK_COLOR); + + SetLowColor(fTextBackColor); + SetViewColor(fTextBackColor); } -//////////////////////////////////////////////////////////////////////////// -// SetTermFont() -// Sets Terninal fonts. (half and full) -//////////////////////////////////////////////////////////////////////////// +// Sets half and full fonts for terminal void -TermView::SetTermFont (BFont *halfFont, BFont *fullFont) +TermView::SetTermFont(BFont *halfFont, BFont *fullFont) { - char buf[4]; - int halfWidth = 0; - - fHalfFont = halfFont; - fFullFont = fullFont; - - // calc half font's max width - // Not Bounding, check only A-Z (For case of fHalfFont is KanjiFont. ) - for(int c = 0x20 ; c <= 0x7e; c++){ - sprintf(buf, "%c", c); - int tmpWidth = (int)fHalfFont.StringWidth(buf); - if(tmpWidth > halfWidth) halfWidth = tmpWidth; - } - // How to calculate FullWidth ? - fFontWidth = halfWidth; - - // Second, Calc Font Height - font_height fh, hh; - fHalfFont.GetHeight(&hh); - fFullFont.GetHeight(&fh); - - int font_ascent, font_descent,font_leading; - - font_ascent = (int)((fh.ascent > hh.ascent) ? fh.ascent : hh.ascent); - font_descent = (int)((fh.descent > hh.descent) ? fh.descent : hh.descent); - font_leading = (int)((fh.leading > hh.leading) ? fh.leading : hh.leading); - - if (font_leading == 0) font_leading = 1; - - if (fTop) - fTop = fTop / fFontHeight; - - fFontHeight = font_ascent + font_descent + font_leading + 1; - - fTop = fTop * fFontHeight; - - fFontAscent = font_ascent; - fCursorHeight = font_ascent + font_descent + font_leading + 1; - - return; - + char buf[4]; + int halfWidth = 0; + + fHalfFont = halfFont; + fFullFont = fullFont; + + // calculate half font's max width + // Not Bounding, check only A-Z(For case of fHalfFont is KanjiFont. ) + for(int c = 0x20 ; c <= 0x7e; c++){ + sprintf(buf, "%c", c); + int tmpWidth =(int)fHalfFont.StringWidth(buf); + if(tmpWidth > halfWidth) + halfWidth = tmpWidth; + } + // How to calculate FullWidth ? + fFontWidth = halfWidth; + + // Second, Calc Font Height + font_height fh, hh; + fHalfFont.GetHeight(&hh); + fFullFont.GetHeight(&fh); + + int font_ascent, font_descent,font_leading; + + font_ascent =(int)((fh.ascent > hh.ascent) ? fh.ascent : hh.ascent); + font_descent =(int)((fh.descent > hh.descent) ? fh.descent : hh.descent); + font_leading =(int)((fh.leading > hh.leading) ? fh.leading : hh.leading); + + if(font_leading == 0) + font_leading = 1; + + if(fTop) + fTop = fTop / fFontHeight; + + fFontHeight = font_ascent + font_descent + font_leading + 1; + + fTop = fTop * fFontHeight; + + fFontAscent = font_ascent; + fCursorHeight = font_ascent + font_descent + font_leading + 1; } -//////////////////////////////////////////////////////////////////////////// -// void SetScrollBar (BScrollBar *scrbar) -// Set scrollbar object. -//////////////////////////////////////////////////////////////////////////// +// set scrollbar object to assigned value void -TermView::SetScrollBar (BScrollBar *scrbar) +TermView::SetScrollBar(BScrollBar *scrbar) { - - fScrollBar = scrbar; + fScrollBar = scrbar; } -//////////////////////////////////////////////////////////////////////////// -// void PutChar (uchar *string, ushort attr, int width) -// Put one charactor. -//////////////////////////////////////////////////////////////////////////// +// Print one character void -TermView::PutChar (uchar *string, ushort attr, int width) +TermView::PutChar(uchar *string, ushort attr, int width) { - - if (width == FULL_WIDTH) attr |= A_WIDTH; - - /* check column over flow. */ - if ((fCurPos.x + width) > fTermColumns) { - this->UpdateLine (); - fCurPos.x = 0; - - if (fCurPos.y == fTermRows -1) { - this->ScrollScreen (); - } else { - fCurPos.y++; - } - } - - if (fInsertModeFlag == MODE_INSERT) { - fTextBuffer->InsertSpace (fCurPos, width); - } - fTextBuffer->WriteChar (fCurPos, string, attr); - - if (fUpdateFlag == false) { - fBufferStartPos = fCurPos.x; - } - - fCurPos.x += width; - fUpdateFlag = true; - - return; + if(width == FULL_WIDTH) + attr |= A_WIDTH; + + // check column over flow. + if((fCurPos.x + width) > fTermColumns) { + UpdateLine(); + fCurPos.x = 0; + + if(fCurPos.y == fTermRows -1) + ScrollScreen(); + else + fCurPos.y++; + } + + if(fInsertModeFlag == MODE_INSERT) + fTextBuffer->InsertSpace(fCurPos, width); + fTextBuffer->WriteChar(fCurPos, string, attr); + + if(fUpdateFlag == false) + fBufferStartPos = fCurPos.x; + + fCurPos.x += width; + fUpdateFlag = true; } -//////////////////////////////////////////////////////////////////////////// -// PutCR () -// Put CR and cursor move. -//////////////////////////////////////////////////////////////////////////// + +// Print a CR and move the cursor void -TermView::PutCR (void) +TermView::PutCR(void) { - this->UpdateLine (); - fTextBuffer->WriteCR (fCurPos); - fCurPos.x = 0; - - return; + UpdateLine(); + fTextBuffer->WriteCR(fCurPos); + fCurPos.x = 0; } -//////////////////////////////////////////////////////////////////////////// -// PutLF () -// Put LF and cursor screen move. -//////////////////////////////////////////////////////////////////////////// + +// Print a LF and move the cursor void -TermView::PutLF (void) +TermView::PutLF(void) { - - this->UpdateLine (); - - if (fScrRegionSet) - if (fCurPos.y == fScrBot) { - this->ScrollRegion (-1, -1, SCRUP, 1); - return; - } - - if (fCurPos.x != fTermColumns){ - if (fCurPos.y == fTermRows -1) { - this->ScrollScreen (); - } else { - fCurPos.y++; - } + UpdateLine(); + + if(fScrRegionSet) + if(fCurPos.y == fScrBot) { + ScrollRegion(-1, -1, SCRUP, 1); + return; + } + + if(fCurPos.x != fTermColumns){ + if(fCurPos.y == fTermRows -1) + ScrollScreen(); + else + fCurPos.y++; + } } - return; -} -//////////////////////////////////////////////////////////////////////////// -// PutNL () -// Put New line after cursor rows. -//////////////////////////////////////////////////////////////////////////// +// Print a NL and move the cursor void -TermView::PutNL (int num) +TermView::PutNL(int num) { - - this->ScrollRegion (fCurPos.y, -1, SCRDOWN, num); - return; - + ScrollRegion(fCurPos.y, -1, SCRDOWN, num); } -//////////////////////////////////////////////////////////////////////////// -// InsertSpace (int num) -// Put space. -//////////////////////////////////////////////////////////////////////////// + +// Print a space void -TermView::InsertSpace (int num) +TermView::InsertSpace(int num) { - this->UpdateLine (); - - fTextBuffer->InsertSpace (fCurPos, num); - this->TermDraw (fCurPos, CurPos(fTermColumns - 1, fCurPos.y)); - - return; - + UpdateLine(); + + fTextBuffer->InsertSpace(fCurPos, num); + TermDraw(fCurPos, CurPos(fTermColumns - 1, fCurPos.y)); } -//////////////////////////////////////////////////////////////////////////// -// SetInsertMode (int flag) -// Set and Reset Insert Mode -//////////////////////////////////////////////////////////////////////////// + +// Set or reset Insert mode void -TermView::SetInsertMode (int flag) +TermView::SetInsertMode(int flag) { - this->UpdateLine(); - fInsertModeFlag = flag; - - return; + UpdateLine(); + fInsertModeFlag = flag; } -//////////////////////////////////////////////////////////////////////////// -// TermDraw (const CurPos start, const CurPos end) -// Draw Region -//////////////////////////////////////////////////////////////////////////// +// Draw region inline int -TermView::TermDraw (const CurPos &start, const CurPos &end) +TermView::TermDraw(const CurPos &start, const CurPos &end) { - int x1 = start.x; - int y1 = start.y; - int x2 = end.x; - int y2 = end.y; - /* - * Send Draw Rectangle data to Draw Engine Thread. - */ - SendDataToDrawEngine (x1, y1 + fTop / fFontHeight, - x2, y2 + fTop / fFontHeight); - - return 0; + int x1 = start.x; + int y1 = start.y; + int x2 = end.x; + int y2 = end.y; + + // Send Draw Rectangle data to Draw Engine thread. + SendDataToDrawEngine(x1, y1 + fTop / fFontHeight, + x2, y2 + fTop / fFontHeight); + return 0; } -//////////////////////////////////////////////////////////////////////////// -// TermDrawSelectedRegion (CurPos start, CurPos end) -// Draw Region -//////////////////////////////////////////////////////////////////////////// +// Draw region int -TermView::TermDrawSelectedRegion (CurPos start, CurPos end) +TermView::TermDrawSelectedRegion(CurPos start, CurPos end) { - CurPos inPos; - - if (end < start) { - inPos = start; - start = end; - end = inPos; - } - - if (start.y == end.y) { - SendDataToDrawEngine (start.x, start.y, - end.x, end.y); - - } else { - SendDataToDrawEngine (start.x, start.y, - fTermColumns, start.y); - - if (end.y - start.y > 0) { - SendDataToDrawEngine (0, start.y + 1, - fTermColumns, end.y - 1); - } - SendDataToDrawEngine (0, end.y, - end.x, end.y); - - } - - return 0; + CurPos inPos; + + if(end < start) { + inPos = start; + start = end; + end = inPos; + } + + if(start.y == end.y) { + SendDataToDrawEngine(start.x, start.y, + end.x, end.y); + } else { + SendDataToDrawEngine(start.x, start.y, + fTermColumns, start.y); + + if(end.y - start.y > 0) + SendDataToDrawEngine(0, start.y + 1, fTermColumns, end.y - 1); + + SendDataToDrawEngine(0, end.y, + end.x, end.y); + } + + return 0; } -//////////////////////////////////////////////////////////////////////////// -// TermDrawRegion (CurPos start, CurPos end) -// Draw Region -//////////////////////////////////////////////////////////////////////////// +// Draw region int -TermView::TermDrawRegion (CurPos start, CurPos end) +TermView::TermDrawRegion(CurPos start, CurPos end) { - CurPos inPos; - int top = fTop / fFontHeight; - - if (end < start) { - inPos = start; - start = end; - end = inPos; - } - - start.y += top; - end.y += top; - - if (start.y == end.y) { - SendDataToDrawEngine (start.x, start.y, - end.x, end.y); - - } else { - SendDataToDrawEngine (start.x, start.y, - fTermColumns - 1, start.y); - - if (end.y - start.y > 0) { - SendDataToDrawEngine (0, start.y + 1, - fTermColumns - 1, end.y - 1); - } - SendDataToDrawEngine (0, end.y, - end.x, end.y); - - } - - return 0; + CurPos inPos; + int top = fTop / fFontHeight; + + if(end < start) { + inPos = start; + start = end; + end = inPos; + } + + start.y += top; + end.y += top; + + if(start.y == end.y) { + SendDataToDrawEngine(start.x, start.y, + end.x, end.y); + } else { + SendDataToDrawEngine(start.x, start.y, + fTermColumns - 1, start.y); + + if(end.y - start.y > 0) { + SendDataToDrawEngine(0, start.y + 1, + fTermColumns - 1, end.y - 1); + } + SendDataToDrawEngine(0, end.y, + end.x, end.y); + } + + return 0; } -//////////////////////////////////////////////////////////////////////////// -// EraseBelow (void) -// Erase cursor below. -//////////////////////////////////////////////////////////////////////////// +// Erase below cursor below. void -TermView::EraseBelow (void) +TermView::EraseBelow(void) { - this->UpdateLine (); - - fTextBuffer->EraseBelow (fCurPos); - this->TermDraw (fCurPos, CurPos(fTermColumns - 1, fCurPos.y)); - if (fCurPos.y != fTermRows - 1) { - this->TermDraw (CurPos(0, fCurPos.y + 1), CurPos(fTermColumns - 1, fTermRows - 1)); - } - return; + UpdateLine(); + + fTextBuffer->EraseBelow(fCurPos); + TermDraw(fCurPos, CurPos(fTermColumns - 1, fCurPos.y)); + if(fCurPos.y != fTermRows - 1) + TermDraw(CurPos(0, fCurPos.y + 1), CurPos(fTermColumns - 1, fTermRows - 1)); } -//////////////////////////////////////////////////////////////////////////// -// DeleteChar (int num) -// Delete num Chars from Current Position. -//////////////////////////////////////////////////////////////////////////// +// Delete num characters from current position. void -TermView::DeleteChar (int num) +TermView::DeleteChar(int num) { - this->UpdateLine (); - - fTextBuffer->DeleteChar(fCurPos, num); - this->TermDraw (fCurPos, CurPos(fTermColumns - 1, fCurPos.y)); - - return; -} -//////////////////////////////////////////////////////////////////////////// -// DeleteColumn (void) -// Delete cursor right charactors. -//////////////////////////////////////////////////////////////////////////// -void -TermView::DeleteColumns (void) -{ - this->UpdateLine (); - - fTextBuffer->DeleteChar (fCurPos, fTermColumns - fCurPos.x); - this->TermDraw (fCurPos, CurPos(fTermColumns - 1, fCurPos.y)); - - return; -} -//////////////////////////////////////////////////////////////////////////// -// DeleteLine (int num) -// Delete num Lines from Current Position with scrolling. -//////////////////////////////////////////////////////////////////////////// -void -TermView::DeleteLine (int num) -{ - this->ScrollRegion (fCurPos.y, -1, SCRUP, num); + UpdateLine(); + + fTextBuffer->DeleteChar(fCurPos, num); + TermDraw(fCurPos, CurPos(fTermColumns - 1, fCurPos.y)); } -/* - * Cursor position get and set functions. - */ -//////////////////////////////////////////////////////////////////////////// -// SetCurPos (int x, int y) -// Sets Cursor to (X, Y) -//////////////////////////////////////////////////////////////////////////// +// Delete cursor right characters. void -TermView::SetCurPos (int x, int y) +TermView::DeleteColumns(void) { - this->UpdateLine (); + UpdateLine(); + + fTextBuffer->DeleteChar(fCurPos, fTermColumns - fCurPos.x); + TermDraw(fCurPos, CurPos(fTermColumns - 1, fCurPos.y)); +} - if (x >= 0 && x < fTermColumns) +// Delete 'num' lines from current position with scrolling. +void +TermView::DeleteLine(int num) +{ + ScrollRegion(fCurPos.y, -1, SCRUP, num); +} + +// Sets cursor position +void +TermView::SetCurPos(int x, int y) +{ + UpdateLine(); + + if(x >= 0 && x < fTermColumns) fCurPos.x = x; - if (y >= 0 && y < fTermRows) + if(y >= 0 && y < fTermRows) fCurPos.y = y; return; } -//////////////////////////////////////////////////////////////////////////// -// SetCurX (int x) -// Sets Cursor X Coordinate. -//////////////////////////////////////////////////////////////////////////// +// Sets cursor x position void -TermView::SetCurX (int x) +TermView::SetCurX(int x) { - if (x >= 0 && x < fTermRows) { - this->UpdateLine (); - fCurPos.x = x; - } - return; -} -//////////////////////////////////////////////////////////////////////////// -// SetCurY (int y) -// Sets Cursor Y Coordinate. -//////////////////////////////////////////////////////////////////////////// -void -TermView::SetCurY (int y) -{ - if (y >= 0 && y < fTermColumns) { - this->UpdateLine (); - fCurPos.y = y; - } - return; + if(x >= 0 && x < fTermRows) { + UpdateLine(); + fCurPos.x = x; + } } -//////////////////////////////////////////////////////////////////////////// -// GetCurPos (CurPos *) -// Get cursor position. -//////////////////////////////////////////////////////////////////////////// +// Sets cursor y position void -TermView::GetCurPos (CurPos *inCurPos) +TermView::SetCurY(int y) { - inCurPos->x = fCurPos.x; - inCurPos->y = fCurPos.y; + if(y >= 0 && y < fTermColumns) { + UpdateLine(); + fCurPos.y = y; + } } -//////////////////////////////////////////////////////////////////////////// -// GetCurX (void) -// Get cursor X position. -//////////////////////////////////////////////////////////////////////////// + +// Gets cursor position +void +TermView::GetCurPos(CurPos *inCurPos) +{ + inCurPos->x = fCurPos.x; + inCurPos->y = fCurPos.y; +} + +// Gets cursor x position int -TermView::GetCurX (void) +TermView::GetCurX(void) { - return fCurPos.x; + return fCurPos.x; } -//////////////////////////////////////////////////////////////////////////// -// GetCurY (void) -// Get cursor Y position. -//////////////////////////////////////////////////////////////////////////// + +// Gets cursor y position int -TermView::GetCurY (void) +TermView::GetCurY(void) { - return fCurPos.y; -} -//////////////////////////////////////////////////////////////////////////// -// SaveCursor (void) -// Save cursor position. -//////////////////////////////////////////////////////////////////////////// -void -TermView::SaveCursor (void) -{ - fCurStack = fCurPos; - return; -} -//////////////////////////////////////////////////////////////////////////// -// RestoreCursor (void) -// Restore cursor position. -//////////////////////////////////////////////////////////////////////////// -void -TermView::RestoreCursor (void) -{ - this->UpdateLine (); - fCurPos = fCurStack; - - return; + return fCurPos.y; } - -/* - * Cursor Movement. - */ -//////////////////////////////////////////////////////////////////////////// -// MoveCurRight (int num) -// Move cursor to right by num steps. -//////////////////////////////////////////////////////////////////////////// +// Saves cursor position void -TermView::MoveCurRight (int num) +TermView::SaveCursor(void) { - - this->UpdateLine (); - - if (fCurPos.x + num >= fTermColumns) { - /* Wrap around */ - fCurPos.x = 0; - PutCR (); - PutLF (); - } else { - fCurPos.x += num; - } - - return; + fCurStack = fCurPos; } -//////////////////////////////////////////////////////////////////////////// -// MoveCurLeft (int num) -// Move cursor to left by num steps. -//////////////////////////////////////////////////////////////////////////// -void -TermView::MoveCurLeft (int num) -{ - this->UpdateLine (); +// Restores cursor position +void +TermView::RestoreCursor(void) +{ + UpdateLine(); + fCurPos = fCurStack; +} + +// Move cursor right by 'num' steps. +void +TermView::MoveCurRight(int num) +{ + UpdateLine(); + + if(fCurPos.x + num >= fTermColumns) { + // Wrap around + fCurPos.x = 0; + PutCR(); + PutLF(); + } else { + fCurPos.x += num; + } +} + +// Move cursor left by 'num' steps. +void +TermView::MoveCurLeft(int num) +{ + UpdateLine(); + + fCurPos.x -= num; + if(fCurPos.x < 0) + fCurPos.x = 0; +} + +// Move cursor up by 'num' steps. +void +TermView::MoveCurUp(int num) +{ + UpdateLine(); + + fCurPos.y -= num; + + if(fCurPos.y < 0) + fCurPos.y = 0; +} + +// Move cursor down by 'num' steps. +void +TermView::MoveCurDown(int num) +{ + UpdateLine(); + + fCurPos.y += num; + + if(fCurPos.y >= fTermRows) + fCurPos.y = fTermRows - 1; +} + +void +TermView::DrawCursor(void) +{ + CURSOR_RECT; + uchar buf[4]; + ushort attr; + + int top = fTop / fFontHeight; + int m_flag = false; + + m_flag = CheckSelectedRegion(CurPos(fCurPos.x, + fCurPos.y + fTop / fFontHeight)); + if(fTextBuffer-> + GetChar(fCurPos.y + top, fCurPos.x, buf, &attr) == A_CHAR) { + + int width; + if(IS_WIDTH(attr)) + width = 2; + else + width = 1; + + DrawLines(fCurPos.x * fFontWidth, + fCurPos.y * fFontHeight + fTop, + attr, buf, width, m_flag, true, this); + } else { + if(m_flag) + SetHighColor(fSelectBackColor); + else + SetHighColor(fCursorBackColor); + + FillRect(r); + } + + Sync(); +} + +void +TermView::BlinkCursor(void) +{ + if(fCursorDrawFlag == CURON + && fCursorBlinkingFlag == CURON + && Window()->IsActive()) { + + if(fCursorStatus == CURON) + TermDraw(fCurPos, fCurPos); + else + DrawCursor(); + + fCursorStatus =(fCursorStatus == CURON) ? CUROFF : CURON; + } +} + +// Draw / Clear cursor. +void +TermView::SetCurDraw(bool flag) +{ + if(flag == CUROFF) { + if(fCursorStatus == CURON) + TermDraw(fCurPos, fCurPos); + + fCursorStatus = CUROFF; + fCursorDrawFlag = CUROFF; + } else { + if(fCursorDrawFlag == CUROFF) { + fCursorDrawFlag = CURON; + fCursorStatus = CURON; + + if(LockLooper()) { + DrawCursor(); + UnlockLooper(); + } + } + } +} + +// Sets cursor Blinking flag. +void +TermView::SetCurBlinking(bool flag) +{ + fCursorBlinkingFlag = flag; +} + +// Scroll terminal dir directory by 'num' steps. +void +TermView::ScrollRegion(int top, int bot, int dir, int num) +{ + UpdateLine(); + + if(top == -1) + top = fScrTop; + + if(bot == -1) + bot = fScrBot; + + if(top < fScrTop) + top = fScrTop; + + if(bot > fScrBot) + bot = fScrBot; + + fTextBuffer->ScrollRegion(top, bot , dir ,num); + TermDraw(CurPos(0, top), CurPos(fTermColumns - 1, bot)); +} + +// Sets terminal scroll region. +void +TermView::SetScrollRegion(int top, int bot) +{ + if(top >= 0 && top < fTermRows) { + if(bot >= 0 && bot < fTermRows) { + if(top > bot) { + fScrTop = bot; + fScrBot = top; + } + else if( top < bot ) { + fScrTop = top; + fScrBot = bot; + } + } + } + + if(fScrTop != 0 || fScrBot != fTermRows -1 ) + fScrRegionSet = 1; + else + fScrRegionSet = 0; - fCurPos.x -= num; - if (fCurPos.x < 0) - fCurPos.x = 0; - - return; } -//////////////////////////////////////////////////////////////////////////// -// MoveCurUp (int num) -// Move cursor up by num steps. -//////////////////////////////////////////////////////////////////////////// -void -TermView::MoveCurUp (int num) -{ - this->UpdateLine (); +// Scroll to cursor position. +void +TermView::ScrollAtCursor(void) +{ + if(LockLooper()) { + ResizeScrBarRange(); + fScrollUpCount = 0; + ScrollTo(0, fTop); + UnlockLooper(); + } +} + +thread_id +TermView::InitViewThread(void) +{ + // spwan Draw Engine thread. + if(fViewThread < 0) { + fViewThread = spawn_thread(ViewThread, "DrawEngine", + B_DISPLAY_PRIORITY, this); + } + else + return B_BAD_THREAD_ID; + + fDrawRectSem = create_sem(0, "draw_engine_sem"); + resume_thread(fViewThread); + + + // spawn Mouse Tracking thread. + if(fMouseThread < 0) { + fMouseThread = spawn_thread(MouseTracking, "MouseTracking", + B_NORMAL_PRIORITY,this); + } + else + return B_BAD_THREAD_ID; + + resume_thread(fMouseThread); + + return(fViewThread); +} + + +// Thread of Draw Character to View. +int32 +TermView::ViewThread(void *data) +{ + int width, height; + sDrawRect pos; + + //#define INVALIDATE + #ifndef INVALIDATE + int i, j, count; + int m_flag; + ushort attr; + uchar buf[256]; + BRect eraseRect; + #endif + + int inDrawRect_p = 0; + + TermView *theObj =(TermView *)data; + + while(theObj->fQuitting) { + + // Wait semaphore + acquire_sem(theObj->fDrawRectSem); + + pos = theObj->fDrawRectBuffer[inDrawRect_p]; + inDrawRect_p++; + inDrawRect_p %= RECT_BUF_SIZE; + + width = theObj->fFontWidth; + height = theObj->fFontHeight; + + #ifdef INVALIDATE + BRect r(pos.x1 * width, pos.y1 * height, + (pos.x2 + 1) * width -1,(pos.y2 + 1) * height -1); + + if(theObj->LockLooper()) { + theObj->Invalidate(r); + theObj->UnlockLooper(); + } + #else + + if(theObj->LockLooper()) { + + for(j = pos.y1; j <= pos.y2; j++) { + + for(i = pos.x1; i <= pos.x2;) { + + count = theObj->fTextBuffer->GetString(j, i, pos.x2, buf, &attr); + m_flag = theObj->CheckSelectedRegion(CurPos(i, j)); + + if(count < 0) { + eraseRect.Set(width * i, + height * j, + width *(i - count) - 1, + height *(j + 1) - 1); + + if(m_flag) + theObj->SetHighColor(theObj->fSelectBackColor); + else + theObj->SetHighColor(theObj->fTextBackColor); + + theObj->FillRect(eraseRect); + count = -count; + + } else { + theObj->DrawLines( width * i, height * j, + attr, buf, count, m_flag, false, theObj); + } + i += count; + } + } + theObj->UnlockLooper(); + } + #endif + + } // end while() + + exit_thread(B_OK); + return 0; +} + +// Thread for tracking mouse. +int32 +TermView::MouseTracking(void *data) +{ + int32 code, selected = false; + uint32 button; + thread_id sender; + CurPos stpos, edpos; + BPoint stpoint, edpoint; + float scr_start, scr_end, scr_pos; + + TermView *theObj =(TermView *)data; + + while(theObj->fQuitting) { - fCurPos.y -= num; - - if (fCurPos.y < 0) - fCurPos.y = 0; - - return; -} -//////////////////////////////////////////////////////////////////////////// -// MoveCurDown (int num) -// Move cursor down by num steps. -//////////////////////////////////////////////////////////////////////////// -void -TermView::MoveCurDown (int num) -{ - - this->UpdateLine (); - - fCurPos.y += num; - - if (fCurPos.y >= fTermRows) { - fCurPos.y = fTermRows - 1; - } - - return; -} - -//////////////////////////////////////////////////////////////////////////// -// DrawCursor (void) -// Draw Cursor. -//////////////////////////////////////////////////////////////////////////// -void -TermView::DrawCursor (void) -{ - CURSOR_RECT; - uchar buf[4]; - ushort attr; - int top = fTop / fFontHeight; - int m_flag = false; - - m_flag = CheckSelectedRegion (CurPos(fCurPos.x, - fCurPos.y + fTop / fFontHeight)); - if (fTextBuffer-> - GetChar (fCurPos.y + top, fCurPos.x, buf, &attr) == A_CHAR) { - - int width; - if (IS_WIDTH(attr)) - width = 2; - else - width = 1; - - DrawLines (fCurPos.x * fFontWidth, - fCurPos.y * fFontHeight + fTop, - attr, buf, width, m_flag, true, this); - } else { - if (m_flag) - SetHighColor (fSelectBackColor); - else - SetHighColor (fCursorBackColor); - - FillRect (r); - } - - Sync(); - - return; -} -//////////////////////////////////////////////////////////////////////////// -// BlinkCursor (void) -// Cursor Blinking -//////////////////////////////////////////////////////////////////////////// -void -TermView::BlinkCursor (void) -{ - if (fCursorDrawFlag == CURON && - fCursorBlinkingFlag == CURON && - Window()->IsActive()){ - if (fCursorStatus == CURON) { - this->TermDraw (fCurPos, fCurPos); + if(1) { +#ifdef CHANGE_CURSOR_IMAGE + if(!has_data(find_thread(NULL))) { + BRect r; + + if(theObj->fSelected + && ( gTermPref->getInt32(PREF_DRAGN_COPY) + || modifiers() & B_CONTROL_KEY)) { + + if(theObj->LockLooper()) { + theObj->GetMouse(&stpoint, &button); + r = theObj->Bounds(); + theObj->UnlockLooper(); + } + if(r.Contains(stpoint)) { + CurPos tmppos = theObj->BPointToCurPos(stpoint); + if(theObj->fSelStart > theObj->fSelEnd) { + stpos = theObj->fSelEnd; + edpos = theObj->fSelStart; + } else { + stpos = theObj->fSelStart; + edpos = theObj->fSelEnd; + } + + if(tmppos > stpos && tmppos < edpos) + be_app->SetCursor(M_ADD_CURSOR); + else + be_app->SetCursor(B_HAND_CURSOR); + } + } + snooze(50 * 1000); + continue; } else { - DrawCursor(); - } - fCursorStatus = (fCursorStatus == CURON) ? CUROFF : CURON; - } -} - -//////////////////////////////////////////////////////////////////////////// -// SetCurDraw (bool flag) -// Draw / Clear cursor. -//////////////////////////////////////////////////////////////////////////// -void -TermView::SetCurDraw (bool flag) -{ - - if (flag == CUROFF) { - if (fCursorStatus == CURON) { - this->TermDraw (fCurPos, fCurPos); - } - fCursorStatus = CUROFF; - fCursorDrawFlag = CUROFF; - } - else { - if (fCursorDrawFlag == CUROFF) { - fCursorDrawFlag = CURON; - fCursorStatus = CURON; - - if (this -> LockLooper ()) { - DrawCursor (); - this -> UnlockLooper (); - } - } - } - - return; - -} -//////////////////////////////////////////////////////////////////////////// -// SetCurBlinking (bool flag) -// Sets cursor Blinking flag. -//////////////////////////////////////////////////////////////////////////// -void -TermView::SetCurBlinking (bool flag) -{ - fCursorBlinkingFlag = flag; -} - -/* - * Scroll screen. - */ -//////////////////////////////////////////////////////////////////////////// -// ScrollRegion ( top, bot, dir, num) -// Scroll terminal dir directory by num of steps. -//////////////////////////////////////////////////////////////////////////// -void -TermView::ScrollRegion (int top, int bot, int dir, int num) -{ - - this->UpdateLine (); - - if (top == -1) - top = fScrTop; - - if (bot == -1) - bot = fScrBot; - - if (top < fScrTop) - top = fScrTop; - - if (bot > fScrBot) - bot = fScrBot; - - - fTextBuffer->ScrollRegion(top, bot , dir ,num); - this->TermDraw (CurPos(0, top), CurPos(fTermColumns - 1, bot)); - return; - -} -//////////////////////////////////////////////////////////////////////////// -// SetScrollRegion (top, bot) -// Sets terminal scroll region. -//////////////////////////////////////////////////////////////////////////// -void -TermView::SetScrollRegion (int top, int bot) -{ - if (top >= 0 && top < fTermRows) { - if (bot >= 0 && bot < fTermRows) { - if (top > bot) { - fScrTop = bot; - fScrBot = top; - } - else if ( top < bot ) { - fScrTop = top; - fScrBot = bot; - } - } - } - if (fScrTop != 0 || fScrBot != fTermRows -1 ) - fScrRegionSet = 1; - else - fScrRegionSet = 0; - -} -//////////////////////////////////////////////////////////////////////////// -// ScrollAtCursor (void) -// Scroll to cursor position. -//////////////////////////////////////////////////////////////////////////// -void -TermView::ScrollAtCursor (void) -{ - if (this->LockLooper()) { - this->ResizeScrBarRange (); - fScrollUpCount = 0; - ScrollTo (0, fTop); - this->UnlockLooper(); - } - - return; -} - -/************************************************************************ - * - * private member functions. - * - ***********************************************************************/ - -//////////////////////////////////////////////////////////////////////////// -// thread_id InitViewThread (void) -// Init View Thread. -//////////////////////////////////////////////////////////////////////////// -thread_id -TermView::InitViewThread (void) -{ - - /* - * spwan Draw Engine thread. - */ - if (fViewThread < 0) { - fViewThread = spawn_thread (ViewThread, - "DrawEngine", - B_DISPLAY_PRIORITY, - this); - } - else { - return B_BAD_THREAD_ID; - } - fDrawRectSem = create_sem (0, "draw_engine_sem"); - resume_thread (fViewThread); - - - /* - * spwan Mouse Tracking thread. - */ - if (fMouseThread < 0) { - fMouseThread = spawn_thread (MouseTracking, - "MouseTracking", - B_NORMAL_PRIORITY, - this); - } - else { - return B_BAD_THREAD_ID; - } - resume_thread (fMouseThread); - - return (fViewThread); -} - - -//////////////////////////////////////////////////////////////////////////// -// static int32 ViewThread (void *) -// Thread of Draw Character to View. -//////////////////////////////////////////////////////////////////////////// - -int32 -TermView::ViewThread (void *data) -{ - int width, height; - sDrawRect pos; - -//#define INVALIDATE -#ifndef INVALIDATE - int i, j, count; - int m_flag; - ushort attr; - uchar buf[256]; - BRect eraseRect; #endif - - int inDrawRect_p = 0; - - TermView *theObj = (TermView *)data; - - while (theObj->fQuitting) { - - // Wait semaphore - acquire_sem (theObj->fDrawRectSem); - - pos = theObj->fDrawRectBuffer[inDrawRect_p]; - inDrawRect_p++; - inDrawRect_p %= RECT_BUF_SIZE; - - width = theObj->fFontWidth; - height = theObj->fFontHeight; - -#ifdef INVALIDATE - BRect r(pos.x1 * width, pos.y1 * height, - (pos.x2 + 1) * width -1, (pos.y2 + 1) * height -1); - if (theObj->LockLooper()) { - theObj->Invalidate (r); - theObj->UnlockLooper(); - } - -#else - - if (theObj->LockLooper()) { - - for (j = pos.y1; j <= pos.y2; j++) { - for (i = pos.x1; i <= pos.x2;) { - count = theObj->fTextBuffer->GetString (j, i, pos.x2, buf, &attr); - m_flag = theObj->CheckSelectedRegion (CurPos(i, j)); - - if (count < 0) { - eraseRect.Set (width * i, - height * j, - width * (i - count) - 1, - height * (j + 1) - 1); - if (m_flag) { - theObj->SetHighColor (theObj->fSelectBackColor); - } else { - theObj->SetHighColor (theObj->fTextBackColor); - } - - theObj->FillRect (eraseRect); - count = -count; - } - else { - theObj->DrawLines ( width * i, height * j, - attr, buf, count, m_flag, false, theObj); - } - i += count; + code = receive_data(&sender,(void *)&stpoint, sizeof(BPoint)); } - } - theObj->UnlockLooper(); - } -#endif - } - exit_thread (B_OK); - return 0; + if(code != MOUSE_THR_CODE) + continue; + + selected = theObj->fSelected; + edpoint.Set(-1, -1); + + stpos = theObj->BPointToCurPos(stpoint); + + do { + + snooze(40 * 1000); + + if(theObj->LockLooper()) { + theObj->GetMouse(&edpoint, &button); + theObj->UnlockLooper(); + } + + edpos = theObj->BPointToCurPos(edpoint); + + if(stpoint == edpoint) { + continue; + } else { + if(!selected) { + theObj->Select(stpos, edpos); + selected = true; + } else { + + // Align cursor point to text. + if(stpos == edpos) + continue; + + if(edpos > stpos) { + edpoint.x -= theObj->fFontWidth / 2; + edpos = theObj->BPointToCurPos(edpoint); + //edpos.x--; + if(edpos.x < 0) + edpos.x = 0; + } + else + if(edpos < stpos) { + edpoint.x += theObj->fFontWidth / 2; + edpos = theObj->BPointToCurPos(edpoint); + //edpos.x++; + if(edpos.x > theObj->fTermColumns) + edpos.x = theObj->fTermColumns; + } + + // Scroll check + if(theObj->LockLooper()) { + + // Get now scroll point + theObj->fScrollBar->GetRange(&scr_start, &scr_end); + scr_pos = theObj->fScrollBar->Value(); + + if(edpoint.y < theObj->Bounds().LeftTop().y ) + + // mouse point left of window + if(scr_pos != scr_start) + theObj->ScrollTo(0, edpoint.y); + + if(edpoint.y > theObj->Bounds().LeftBottom().y) { + + // mouse point left of window + if(scr_pos != scr_end) + theObj->ScrollTo(0, edpoint.y); + } + theObj->UnlockLooper(); + } + theObj->ResizeSelectRegion(edpos); + } + } + } while(button); + theObj->fMouseTracking = false; + } + + exit_thread(B_OK); + return 0; } -//////////////////////////////////////////////////////////////////////////// -// static int32 MouseTracking (void *) -// Thread of Tracking Mouse. -//////////////////////////////////////////////////////////////////////////// - -int32 -TermView::MouseTracking (void *data) +// Draw character on offscreen bitmap. +void +TermView::DrawLines(int x1, int y1, ushort attr, uchar *buf, + int width, int mouse, int cursor, BView *inView) { - int32 code, selected = false; - uint32 button; - thread_id sender; - CurPos stpos, edpos; - BPoint stpoint, edpoint; - float scr_start, scr_end, scr_pos; - - TermView *theObj = (TermView *)data; - - - while (theObj->fQuitting) { - if (1) { -#ifdef CHANGE_CURSOR_IMAGE - if (!has_data (find_thread (NULL))) { - BRect r; - - if (theObj->fSelected && - ( gTermPref->getInt32 (PREF_DRAGN_COPY) || - modifiers() & B_CONTROL_KEY)) { - if (theObj->LockLooper ()) { - theObj->GetMouse (&stpoint, &button); - r = theObj->Bounds(); - theObj->UnlockLooper(); + // int width; + int x2, y2; + int forecolor, backcolor; + rgb_color rgb_fore = fTextForeColor, rgb_back = fTextBackColor, rgb_tmp; + + // Set Font. + if(IS_WIDTH(attr)) + inView->SetFont(&fFullFont); + else + inView->SetFont(&fHalfFont); + + // Set pen point + x2 = x1 + fFontWidth * width; + y2 = y1 + fFontHeight; + + // color attribute + forecolor = IS_FORECOLOR(attr); + backcolor = IS_BACKCOLOR(attr); + + if(IS_FORESET(attr)) + rgb_fore = gTermColorTable[forecolor]; + + if(IS_BACKSET(attr)) + rgb_back = gTermColorTable[backcolor]; + + // Selection check. + if(cursor) { + rgb_fore = fCursorForeColor; + rgb_back = fCursorBackColor; } - if (r.Contains (stpoint)) { - CurPos tmppos = theObj->BPointToCurPos (stpoint); - if (theObj->fSelStart > theObj->fSelEnd) { - stpos = theObj->fSelEnd; - edpos = theObj->fSelStart; - } else { - stpos = theObj->fSelStart; - edpos = theObj->fSelEnd; - } - if (tmppos > stpos && tmppos < edpos) { - be_app->SetCursor (M_ADD_CURSOR); - } - else { - be_app->SetCursor (B_HAND_CURSOR); - } - } - } - snooze (50 * 1000); - continue; - } - else { -#endif - code = receive_data (&sender, (void *)&stpoint, sizeof(BPoint)); - } - - if (code != MOUSE_THR_CODE) continue; - - selected = theObj->fSelected; - edpoint.Set (-1, -1); - - stpos = theObj->BPointToCurPos (stpoint); - - do { - snooze (40 * 1000); - if (theObj->LockLooper()) { - theObj->GetMouse (&edpoint, &button); - theObj->UnlockLooper(); - } - - edpos = theObj->BPointToCurPos (edpoint); - - if (stpoint == edpoint) { - continue; - } else { - if (!selected) { - theObj->Select (stpos, edpos); - selected = true; + else + if(mouse){ + rgb_fore = fSelectForeColor; + rgb_back = fSelectBackColor; + } else { - /* - * Align cursor point to text. - */ - if (stpos == edpos) continue; - - if (edpos > stpos) { - edpoint.x -= theObj->fFontWidth / 2; - edpos = theObj->BPointToCurPos (edpoint); - //edpos.x--; - if (edpos.x < 0) edpos.x = 0; - } - else if (edpos < stpos) { - edpoint.x += theObj->fFontWidth / 2; - edpos = theObj->BPointToCurPos (edpoint); - //edpos.x++; - if (edpos.x > theObj->fTermColumns) edpos.x = theObj->fTermColumns; - } - - /* - * Scroll check - */ - if (theObj->LockLooper()) { - - /* Get now scroll point */ - theObj->fScrollBar->GetRange (&scr_start, &scr_end); - scr_pos = theObj->fScrollBar->Value(); - - if (edpoint.y < theObj->Bounds().LeftTop().y ) - /* mouse point left of window */ - if (scr_pos != scr_start) - theObj->ScrollTo (0, edpoint.y); - - if (edpoint.y > theObj->Bounds().LeftBottom().y) { - /* mouse point left of window */ - if (scr_pos != scr_end) - theObj->ScrollTo (0, edpoint.y); - } - theObj->UnlockLooper(); - } - theObj->ResizeSelectRegion (edpos); + + // Reverse attribute(If selected area, don't reverse color). + if(IS_INVERSE(attr)) { + rgb_tmp = rgb_fore; + rgb_fore = rgb_back; + rgb_back = rgb_tmp; + } } - } - } while (button); - theObj->fMouseTracking = false; - } - - exit_thread (B_OK); - return 0; -} - -//////////////////////////////////////////////////////////////////////////// -// void DrawLines (int, int, ushort, uchar *, int, int, int, BView *) -// Draw Character on offscreen bitmap. -//////////////////////////////////////////////////////////////////////////// -void -TermView::DrawLines (int x1, int y1, - ushort attr, uchar *buf, - int width, int mouse, int cursor, - BView *inView) -{ - // int width; - int x2, y2; - int forecolor, backcolor; - rgb_color rgb_fore = fTextForeColor, rgb_back = fTextBackColor, rgb_tmp; - - /* - * Set Font. - */ - if (IS_WIDTH(attr)) { - inView->SetFont (&fFullFont); - } else { - inView->SetFont (&fHalfFont); - } - - /* - * Set pen point. - */ - x2 = x1 + fFontWidth * width; - y2 = y1 + fFontHeight; - /* - * color attribute - */ - forecolor = IS_FORECOLOR(attr); - backcolor = IS_BACKCOLOR(attr); - - if (IS_FORESET (attr)) { - rgb_fore = gTermColorTable[forecolor]; - } - if (IS_BACKSET (attr)) { - rgb_back = gTermColorTable[backcolor]; - } - - /* - * Selection check. - */ - if (cursor) { - rgb_fore = fCursorForeColor; - rgb_back = fCursorBackColor; - } - else if (mouse){ - rgb_fore = fSelectForeColor; - rgb_back = fSelectBackColor; - - } else { - /* - * Reverse attribute (If selected area, don't reverse color). - */ - if (IS_INVERSE (attr)) { - rgb_tmp = rgb_fore; - rgb_fore = rgb_back; - rgb_back = rgb_tmp; - } - } - - /* - * Fill color at Background color and set low color. - */ - inView->SetHighColor (rgb_back); - inView->FillRect (BRect (x1, y1, x2 - 1, y2 - 1)); - inView->SetLowColor (rgb_back); - - inView->SetHighColor (rgb_fore); - - /* - * Draw character. - */ - inView->MovePenTo (x1, y1 + fFontAscent); - inView->DrawString ((char *) buf); - - /* - * bold attribute. - */ - if (IS_BOLD (attr)) { - inView->MovePenTo (x1 + 1, y1 + fFontAscent); - - inView->SetDrawingMode (B_OP_OVER); - inView->DrawString ((char *)buf); - inView->SetDrawingMode (B_OP_COPY); - } + // Fill color at Background color and set low color. + inView->SetHighColor(rgb_back); + inView->FillRect(BRect(x1, y1, x2 - 1, y2 - 1)); + inView->SetLowColor(rgb_back); - /* - * underline attribute - */ - if (IS_UNDER (attr)) { - inView->MovePenTo (x1, y1 + fFontAscent); - inView->StrokeLine (BPoint (x1 , y1 + fFontAscent), - BPoint (x2 , y1 + fFontAscent)); - } - - return; - + inView->SetHighColor(rgb_fore); + + // Draw character. + inView->MovePenTo(x1, y1 + fFontAscent); + inView->DrawString((char *) buf); + + // bold attribute. + if(IS_BOLD(attr)) { + inView->MovePenTo(x1 + 1, y1 + fFontAscent); + + inView->SetDrawingMode(B_OP_OVER); + inView->DrawString((char *)buf); + inView->SetDrawingMode(B_OP_COPY); + } + + // underline attribute + if(IS_UNDER(attr)) { + inView->MovePenTo(x1, y1 + fFontAscent); + inView->StrokeLine(BPoint(x1 , y1 + fFontAscent), + BPoint(x2 , y1 + fFontAscent)); + } } -//////////////////////////////////////////////////////////////////////////// -// ResizeScrBarRange (void) -// Resize scroll bar range and knob size. -//////////////////////////////////////////////////////////////////////////// +// Resize scroll bar range and knob size. void -TermView::ResizeScrBarRange (void) +TermView::ResizeScrBarRange(void) { - float viewheight, start_pos; - - viewheight = fTermRows * fFontHeight; - start_pos = fTop - (fScrBufSize - fTermRows *2) * fFontHeight; - - if (start_pos > 0) { - fScrollBar->SetRange (start_pos, viewheight + fTop - fFontHeight); - } - else { - fScrollBar->SetRange(0, viewheight + fTop - fFontHeight); - fScrollBar->SetProportion ( viewheight / (viewheight + fTop)); - } + float viewheight, start_pos; + + viewheight = fTermRows * fFontHeight; + start_pos = fTop -(fScrBufSize - fTermRows *2) * fFontHeight; + + if(start_pos > 0) { + fScrollBar->SetRange(start_pos, viewheight + fTop - fFontHeight); + + } else { + fScrollBar->SetRange(0, viewheight + fTop - fFontHeight); + fScrollBar->SetProportion( viewheight /(viewheight + fTop)); + } } -//////////////////////////////////////////////////////////////////////////// -// ScrollScreen (void) -// Scrolls screen. -//////////////////////////////////////////////////////////////////////////// +// Scrolls screen. void -TermView::ScrollScreen (void) +TermView::ScrollScreen(void) { - fTop += fFontHeight; - fScrollUpCount++; - fTextBuffer->ScrollLine (); - - if (fScrollUpCount > fTermRows ) { - if (this->LockLooper()) { - this->ResizeScrBarRange (); - fScrollBarRange += fScrollUpCount; - fScrollUpCount = 0; - ScrollTo (0, fTop); - this->UnlockLooper(); - } - } - - return; + fTop += fFontHeight; + fScrollUpCount++; + fTextBuffer->ScrollLine(); + + if(fScrollUpCount > fTermRows ) { + if(LockLooper()) { + ResizeScrBarRange(); + fScrollBarRange += fScrollUpCount; + fScrollUpCount = 0; + ScrollTo(0, fTop); + UnlockLooper(); + } + } } -//////////////////////////////////////////////////////////////////////////// -// ScrollScreenDraw (void) -// Scrolls screen. -//////////////////////////////////////////////////////////////////////////// +// Scrolls screen. void -TermView::ScrollScreenDraw (void) +TermView::ScrollScreenDraw(void) { - if (fScrollUpCount){ - if (this->LockLooper()) { - this->ResizeScrBarRange (); - - fScrollBarRange += fScrollUpCount; - fScrollUpCount = 0; - ScrollTo (0, fTop); - this->UnlockLooper(); - } - } + if(fScrollUpCount){ + if(LockLooper()) { + ResizeScrBarRange(); + + fScrollBarRange += fScrollUpCount; + fScrollUpCount = 0; + ScrollTo(0, fTop); + UnlockLooper(); + } + } } -//////////////////////////////////////////////////////////////////////////// -// UpdateSIGWINCH (void) -// SIGWINCH Handler. -//////////////////////////////////////////////////////////////////////////// +// Handler for SIGWINCH void TermView::UpdateSIGWINCH() { - struct winsize ws; - - if (fFrameResized) { - if (fSelected) - this->TermDrawSelectedRegion (fSelStart, fSelEnd); - ScrollTo (0, fTop); - this->ResizeScrBarRange (); - - ws.ws_row = fTermRows; - ws.ws_col = fTermColumns; - ioctl (pfd, TIOCSWINSZ, &ws); - kill (-sh_pid, SIGWINCH); - - fFrameResized = 0; - if (fScrRegionSet == 0) { - fScrBot = fTermRows - 1; - } - } - + struct winsize ws; + + if(fFrameResized) { + if(fSelected) + TermDrawSelectedRegion(fSelStart, fSelEnd); + ScrollTo(0, fTop); + ResizeScrBarRange(); + + ws.ws_row = fTermRows; + ws.ws_col = fTermColumns; + ioctl(pfd, TIOCSWINSZ, &ws); + kill(-sh_pid, SIGWINCH); + + fFrameResized = 0; + if(fScrRegionSet == 0) + fScrBot = fTermRows - 1; + } } -//////////////////////////////////////////////////////////////////////////// -// DeviceStatusReport (int) -// Device Status. -//////////////////////////////////////////////////////////////////////////// -// Q & D hack by Y.Hayakawa (hida@sawada.riec.tohoku.ac.jp) +// Device Status. +// Q & D hack by Y.Hayakawa(hida@sawada.riec.tohoku.ac.jp) // 21-JUL-99 void TermView::DeviceStatusReport(int n) { - char sbuf[16] ; - int len; - - switch (n) { - case 5: - len = sprintf(sbuf,"\033[0n") ; - write (pfd, sbuf, len); - break ; - case 6: - len = sprintf(sbuf,"\033[%d;%dR",fTermRows,fTermColumns) ; - write (pfd, sbuf, len); - break ; - default: - return; - } - return ; -} - -//////////////////////////////////////////////////////////////////////////// -// UpdateLine (void) -// Update line buffer. -//////////////////////////////////////////////////////////////////////////// -void -TermView::UpdateLine (void) -{ - - if (fUpdateFlag == true) { - if (fInsertModeFlag == MODE_INSERT) { - this->TermDraw (CurPos(fBufferStartPos, fCurPos.y), - CurPos(fTermColumns - 1, fCurPos.y)); - } else { - this->TermDraw (CurPos(fBufferStartPos, fCurPos.y), - CurPos(fCurPos.x - 1, fCurPos.y)); - } - fUpdateFlag = false; - } - - return; -} - -/* - * Private Member Functions (hook functions). - */ -//////////////////////////////////////////////////////////////////////////// -// AttachedToWindow -// -//////////////////////////////////////////////////////////////////////////// -void -TermView::AttachedToWindow (void) -{ - this->SetFont (&fHalfFont); - this->MakeFocus(true); - fScrollBar->SetSteps (fFontHeight, fFontHeight * fTermRows); - -} -///////////////////////////////////////////////////////////////////////////// -// Draw -// updates view. -///////////////////////////////////////////////////////////////////////////// -void -TermView::Draw (BRect updateRect) -{ - - if (IsPrinting()){ - DoPrint(updateRect); - return; - } - - int x1, x2, y1, y2; - int i, j, k, count; - ushort attr; - uchar buf[256]; - int m_flag; - BRect eraseRect; - - x1 = (int)updateRect.left / fFontWidth; - x2 = (int)updateRect.right / fFontWidth; - - y1 = (int)updateRect.top / fFontHeight; - y2 = (int)updateRect.bottom / fFontHeight; - - Window()->BeginViewTransaction(); - - for (j = y1; j <= y2; j++) { - /* - * If (x1, y1) Buffer is in string full width character, - * allinment start position. - */ - k = x1; - if (fTextBuffer->GetChar (j, k, buf, &attr) == IN_STRING) { - k--; - } - if (k < 0) k = 0; - - for (i = k; i <= x2;) { - - count = fTextBuffer->GetString (j, i, x2, buf, &attr); - - m_flag = CheckSelectedRegion (CurPos(i, j)); - - if (count < 0) { - if (m_flag) { - - eraseRect.Set (fFontWidth * i, - fFontHeight * j, - fFontWidth * (i - count) -1, - fFontHeight * (j + 1) -1); - - SetHighColor (fSelectBackColor); - FillRect (eraseRect); + char sbuf[16] ; + int len; + + switch(n) { + case 5: + len = sprintf(sbuf,"\033[0n") ; + write(pfd, sbuf, len); + break ; + case 6: + len = sprintf(sbuf,"\033[%d;%dR",fTermRows,fTermColumns) ; + write(pfd, sbuf, len); + break ; + default: + return; } - i += abs (count); - continue; - } - - DrawLines (fFontWidth * i, fFontHeight * j, - attr, buf, count, m_flag, false, this); - i += count; - if (i >= fTermColumns) break; - - } - } - - if (fCursorStatus == CURON) { - DrawCursor(); - } - Window()->EndViewTransaction(); - - - return; } -///////////////////////////////////////////////////////////////////////////// -// Draw view on printer. -// -///////////////////////////////////////////////////////////////////////////// + +// Update line buffer. +void +TermView::UpdateLine(void) +{ + if(fUpdateFlag == true) { + + if(fInsertModeFlag == MODE_INSERT) { + TermDraw(CurPos(fBufferStartPos, fCurPos.y), + CurPos(fTermColumns - 1, fCurPos.y)); + + } else { + TermDraw(CurPos(fBufferStartPos, fCurPos.y), + CurPos(fCurPos.x - 1, fCurPos.y)); + } + fUpdateFlag = false; + } +} + +void +TermView::AttachedToWindow(void) +{ + SetFont(&fHalfFont); + MakeFocus(true); + fScrollBar->SetSteps(fFontHeight, fFontHeight * fTermRows); +} + +void +TermView::Draw(BRect updateRect) +{ + if(IsPrinting()) { + DoPrint(updateRect); + return; + } + + int x1, x2, y1, y2; + int i, j, k, count; + ushort attr; + uchar buf[256]; + int m_flag; + BRect eraseRect; + + x1 =(int)updateRect.left / fFontWidth; + x2 =(int)updateRect.right / fFontWidth; + + y1 =(int)updateRect.top / fFontHeight; + y2 =(int)updateRect.bottom / fFontHeight; + + Window()->BeginViewTransaction(); + + for(j = y1; j <= y2; j++) { + + // If(x1, y1) Buffer is in string full width character, + // alignment start position. + + k = x1; + if(fTextBuffer->GetChar(j, k, buf, &attr) == IN_STRING) + k--; + + if(k < 0) + k = 0; + + for(i = k; i <= x2;) { + + count = fTextBuffer->GetString(j, i, x2, buf, &attr); + m_flag = CheckSelectedRegion(CurPos(i, j)); + + if(count < 0) { + + if(m_flag) { + + eraseRect.Set(fFontWidth * i, + fFontHeight * j, + fFontWidth *(i - count) -1, + fFontHeight *(j + 1) -1); + + SetHighColor(fSelectBackColor); + FillRect(eraseRect); + } + i += abs(count); + continue; + } + + DrawLines(fFontWidth * i, fFontHeight * j, + attr, buf, count, m_flag, false, this); + i += count; + if(i >= fTermColumns) + break; + + } + } + + if(fCursorStatus == CURON) + DrawCursor(); + + Window()->EndViewTransaction(); +} + + void TermView::DoPrint(BRect updateRect) { -#if 1 - ushort attr; - uchar buf[256]; - - const int numLines = (int)((updateRect.Height()) / fFontHeight); - - int y1 = (int)updateRect.top / fFontHeight; - y1 = y1 - (fScrBufSize - numLines * 2); - if(y1 < 0) y1 = 0; - - const int y2 = y1 + numLines -1; - - const int x1 = (int)updateRect.left / fFontWidth; - const int x2 = (int)updateRect.right / fFontWidth; - - for (int j = y1; j <= y2; j++) { - /* - * If (x1, y1) Buffer is in string full width character, - * allinment start position. - */ - int k = x1; - if (fTextBuffer->GetChar (j, k, buf, &attr) == IN_STRING) { - k--; - } - if (k < 0) k = 0; - - for (int i = k; i <= x2;) { - - int count = fTextBuffer->GetString (j, i, x2, buf, &attr); - if (count < 0) { - i += abs (count); - continue; - } - - DrawLines (fFontWidth * i, fFontHeight * j, - attr, buf, count, false, false, this); - i += count; - } - } - -#endif + ushort attr; + uchar buf[256]; + + const int numLines =(int)((updateRect.Height()) / fFontHeight); + + int y1 =(int)updateRect.top / fFontHeight; + y1 = y1 -(fScrBufSize - numLines * 2); + if(y1 < 0) + y1 = 0; + + const int y2 = y1 + numLines -1; + + const int x1 =(int)updateRect.left / fFontWidth; + const int x2 =(int)updateRect.right / fFontWidth; + + for(int j = y1; j <= y2; j++) { + + // If(x1, y1) Buffer is in string full width character, + // alignment start position. + + int k = x1; + if(fTextBuffer->GetChar(j, k, buf, &attr) == IN_STRING) + k--; + + if(k < 0) + k = 0; + + for(int i = k; i <= x2;) { + + int count = fTextBuffer->GetString(j, i, x2, buf, &attr); + if(count < 0) { + i += abs(count); + continue; + } + + DrawLines(fFontWidth * i, fFontHeight * j, + attr, buf, count, false, false, this); + i += count; + } + } } -////////////////////////////////////////////////////////////////////////////// -// WindowActivated -// -////////////////////////////////////////////////////////////////////////////// -void -TermView::WindowActivated (bool active) -{ - if (active == false) { - // DoIMConfirm (); - } - if (active && fMouseImage) { - be_app->SetCursor (B_I_BEAM_CURSOR); - } +void +TermView::WindowActivated(bool active) +{ + if(active == false) { + // DoIMConfirm(); + } + + if(active && fMouseImage) { + be_app->SetCursor(B_I_BEAM_CURSOR); + } } -////////////////////////////////////////////////////////////////////////////// -// KeyDown -// Key down event. -////////////////////////////////////////////////////////////////////////////// void -TermView::KeyDown (const char *bytes, int32 numBytes) +TermView::KeyDown(const char *bytes, int32 numBytes) { - char c; - struct termios tio; - int32 key, mod; - - uchar dstbuf[1024]; - this->Looper()->CurrentMessage()->FindInt32("modifiers", &mod); - this->Looper()->CurrentMessage()->FindInt32("key", &key); - - if (fIMflag) - return; - - /* - * If bytes[0] equal intr charactor, - * send signal to shell process group. - */ - tcgetattr (pfd, &tio); - if (*bytes == tio.c_cc[VINTR]) { - if (tio.c_lflag & ISIG) { - kill (-sh_pid, SIGINT); - } - } - - /* - * MuTerminal changes RET, ENTER, F1...F12, and ARROW key code. - */ - - if (numBytes == 1) { - if (mod & B_OPTION_KEY) { - c = *bytes; - c |= 0x80; - write (pfd, &c, 1); - return; - } - - switch (*bytes) { - case B_RETURN: - c = 0x0d; - if (key == RETURN_KEY || key == ENTER_KEY) { - write (pfd, &c, 1); - return; - } - else { - write (pfd, bytes, numBytes); - return; - } - - case B_LEFT_ARROW: - if (key == LEFT_ARROW_KEY) { - write (pfd, LEFT_ARROW_KEY_CODE, sizeof(LEFT_ARROW_KEY_CODE)-1); - return; - } - break; - - case B_RIGHT_ARROW: - if (key == RIGHT_ARROW_KEY) { - write (pfd, RIGHT_ARROW_KEY_CODE, sizeof(RIGHT_ARROW_KEY_CODE)-1); - return; - } - break; - - case B_UP_ARROW: - if (mod & B_SHIFT_KEY) { - if (Bounds().top <= 0) - return; - ScrollBy (0, -fFontHeight); - Window()->UpdateIfNeeded(); - return; - } - - if (key == UP_ARROW_KEY) { - write (pfd, UP_ARROW_KEY_CODE, sizeof(UP_ARROW_KEY_CODE)-1); - return; - } - break; - - case B_DOWN_ARROW: - if (mod & B_SHIFT_KEY) { - ScrollBy (0, fFontHeight); - Window()->UpdateIfNeeded(); - return; - } - - if (key == DOWN_ARROW_KEY) { - write (pfd, DOWN_ARROW_KEY_CODE, sizeof(DOWN_ARROW_KEY_CODE)-1); - return; - } - break; - - case B_INSERT: - if (key == INSERT_KEY) { - write (pfd, INSERT_KEY_CODE, sizeof(INSERT_KEY_CODE)-1); - return; - } - - case B_HOME: - if (key == HOME_KEY) { - write (pfd, HOME_KEY_CODE, sizeof(HOME_KEY_CODE)-1); - return; - } - - case B_PAGE_UP: - if (mod & B_SHIFT_KEY) { - if (Bounds().top <= 0) - return; - ScrollBy (0, -fFontHeight * fTermRows ); - Window()->UpdateIfNeeded(); - return; - } - - if (key == PAGE_UP_KEY) { - write (pfd, PAGE_UP_KEY_CODE, sizeof(PAGE_UP_KEY_CODE)-1); - return; - } - - case B_PAGE_DOWN: - if (mod & B_SHIFT_KEY) { - ScrollBy (0, fFontHeight * fTermRows); - Window()->UpdateIfNeeded(); - return; - } - - if (key == PAGE_DOWN_KEY) { - write (pfd, PAGE_DOWN_KEY_CODE, sizeof(PAGE_DOWN_KEY_CODE)-1); - return; - } - - case B_END: - if (key == END_KEY) { - write (pfd, END_KEY_CODE, sizeof(END_KEY_CODE)-1); - return; - } - - - case B_FUNCTION_KEY: - for (c = 0; c < 12; c++) { - if (key == function_keycode_table[c]) { - write (pfd, function_key_char_table[c], 5); - return; - } - } - break; - - default: - break; - } - } - else { - /* input multibyte character */ - - if (gNowCoding != M_UTF8) { - int cnum = fCodeConv->ConvertFromInternal - ((uchar *)bytes, dstbuf, gNowCoding); - write (pfd, dstbuf, cnum); - return; - } - } - - - write (pfd, bytes, numBytes); - return; - + char c; + struct termios tio; + int32 key, mod; + + uchar dstbuf[1024]; + Looper()->CurrentMessage()->FindInt32("modifiers", &mod); + Looper()->CurrentMessage()->FindInt32("key", &key); + + if(fIMflag) + return; + + // If bytes[0] equal intr charactor, + // send signal to shell process group. + tcgetattr(pfd, &tio); + if(*bytes == tio.c_cc[VINTR]) { + + if(tio.c_lflag & ISIG) + kill(-sh_pid, SIGINT); + } + + // Terminal changes RET, ENTER, F1...F12, and ARROW key code. + + if(numBytes == 1) { + + if(mod & B_OPTION_KEY) { + c = *bytes; + c |= 0x80; + write(pfd, &c, 1); + return; + } + + switch(*bytes) { + + case B_RETURN: + c = 0x0d; + + if(key == RETURN_KEY || key == ENTER_KEY) { + write(pfd, &c, 1); + return; + + } else { + write(pfd, bytes, numBytes); + return; + } + + break; + + case B_LEFT_ARROW: + + if(key == LEFT_ARROW_KEY) { + write(pfd, LEFT_ARROW_KEY_CODE, sizeof(LEFT_ARROW_KEY_CODE)-1); + return; + } + break; + + case B_RIGHT_ARROW: + + if(key == RIGHT_ARROW_KEY) { + write(pfd, RIGHT_ARROW_KEY_CODE, sizeof(RIGHT_ARROW_KEY_CODE)-1); + return; + } + break; + + case B_UP_ARROW: + + if(mod & B_SHIFT_KEY) { + if(Bounds().top <= 0) + return; + ScrollBy(0, -fFontHeight); + Window()->UpdateIfNeeded(); + return; + } + + if(key == UP_ARROW_KEY) { + write(pfd, UP_ARROW_KEY_CODE, sizeof(UP_ARROW_KEY_CODE)-1); + return; + } + break; + + case B_DOWN_ARROW: + + if(mod & B_SHIFT_KEY) { + ScrollBy(0, fFontHeight); + Window()->UpdateIfNeeded(); + return; + } + + if(key == DOWN_ARROW_KEY) { + write(pfd, DOWN_ARROW_KEY_CODE, sizeof(DOWN_ARROW_KEY_CODE)-1); + return; + } + break; + + case B_INSERT: + + if(key == INSERT_KEY) { + write(pfd, INSERT_KEY_CODE, sizeof(INSERT_KEY_CODE)-1); + return; + } + break; + + case B_HOME: + + if(key == HOME_KEY) { + write(pfd, HOME_KEY_CODE, sizeof(HOME_KEY_CODE)-1); + return; + } + break; + + case B_PAGE_UP: + + if(mod & B_SHIFT_KEY) { + if(Bounds().top <= 0) + return; + ScrollBy(0, -fFontHeight * fTermRows ); + Window()->UpdateIfNeeded(); + return; + } + + if(key == PAGE_UP_KEY) { + write(pfd, PAGE_UP_KEY_CODE, sizeof(PAGE_UP_KEY_CODE)-1); + return; + } + break; + + case B_PAGE_DOWN: + + if(mod & B_SHIFT_KEY) { + ScrollBy(0, fFontHeight * fTermRows); + Window()->UpdateIfNeeded(); + return; + } + + if(key == PAGE_DOWN_KEY) { + write(pfd, PAGE_DOWN_KEY_CODE, sizeof(PAGE_DOWN_KEY_CODE)-1); + return; + } + break; + + case B_END: + + if(key == END_KEY) { + write(pfd, END_KEY_CODE, sizeof(END_KEY_CODE)-1); + return; + } + break; + + case B_FUNCTION_KEY: + + for(c = 0; c < 12; c++) { + if(key == function_keycode_table[c]) { + write(pfd, function_key_char_table[c], 5); + return; + } + } + break; + + default: + break; + } + + } else { + // input multibyte character + + if(gNowCoding != M_UTF8) { + int cnum = fCodeConv->ConvertFromInternal + ((uchar *)bytes, dstbuf, gNowCoding); + write(pfd, dstbuf, cnum); + return; + } + } + + write(pfd, bytes, numBytes); } -///////////////////////////////////////////////////////////////////////////// -// FrameResized -// -///////////////////////////////////////////////////////////////////////////// - void -TermView::FrameResized (float width, float height) +TermView::FrameResized(float width, float height) { - - const int cols = ((int)width + 1) / fFontWidth; - const int rows = ((int)height + 1) / fFontHeight; - - int offset = 0; - - if (rows < fCurPos.y + 1) { - fTop += (fCurPos.y + 1 - rows) * fFontHeight; - offset = fCurPos.y + 1 - rows; - fCurPos.y = rows - 1; - } - fTextBuffer->ResizeTo (rows, cols, offset); - fTermRows = rows; - fTermColumns = cols; - - fFrameResized = 1; - - return; - + const int cols =((int)width + 1) / fFontWidth; + const int rows =((int)height + 1) / fFontHeight; + + int offset = 0; + + if(rows < fCurPos.y + 1) { + fTop +=(fCurPos.y + 1 - rows) * fFontHeight; + offset = fCurPos.y + 1 - rows; + fCurPos.y = rows - 1; + } + fTextBuffer->ResizeTo(rows, cols, offset); + fTermRows = rows; + fTermColumns = cols; + + fFrameResized = 1; } -//////////////////////////////////////////////////////////////////////////// -// MessageReceived -// -//////////////////////////////////////////////////////////////////////////// void TermView::MessageReceived(BMessage *msg) { @@ -1825,10 +1509,10 @@ TermView::MessageReceived(BMessage *msg) int32 i=0; if(msg->FindRef("refs", i++, &ref) == B_OK) { - this->DoFileDrop(ref); + DoFileDrop(ref); while(msg->FindRef("refs", i++, &ref) == B_OK) - this->DoFileDrop(ref); + DoFileDrop(ref); } else { @@ -1842,46 +1526,46 @@ TermView::MessageReceived(BMessage *msg) int32 num_bytes; status_t sts; - if (msg->WasDropped()) + if(msg->WasDropped()) { - sts = msg->FindData ((const char *)"text/plain", + sts = msg->FindData((const char *)"text/plain", (type_code)B_MIME_TYPE, (const void **)&text, &num_bytes); - if (sts != B_OK) + if(sts != B_OK) break; // Clipboard text doesn't attached EOF? text[num_bytes] = '\0'; - WritePTY ((uchar *)text, num_bytes); + WritePTY((uchar *)text, num_bytes); } break; } case B_COPY: { - this->DoCopy(); + DoCopy(); break; } case B_PASTE: { int32 code; - if (msg->FindInt32 ("index", &code) == B_OK) - this->DoPaste(); + if(msg->FindInt32("index", &code) == B_OK) + DoPaste(); break; } case B_SELECT_ALL: { - this->DoSelectAll(); + DoSelectAll(); break; } case MENU_CLEAR_ALL: { - this->DoClearAll(); - write (pfd, ctrl_l, 1); + DoClearAll(); + write(pfd, ctrl_l, 1); break; } case MSGRUN_CURSOR: { - this->BlinkCursor(); + BlinkCursor(); break; } @@ -1891,19 +1575,19 @@ TermView::MessageReceived(BMessage *msg) // msg->FindInt32("be:opcode", &op); // switch(op){ // case B_INPUT_METHOD_STARTED: - //this->DoIMStart(msg); + //DoIMStart(msg); // break; // case B_INPUT_METHOD_STOPPED: -// this->DoIMStop(msg); +// DoIMStop(msg); // break; // case B_INPUT_METHOD_CHANGED: -// this->DoIMChange(msg); +// DoIMChange(msg); // break; // case B_INPUT_METHOD_LOCATION_REQUEST: -// this->DoIMLocation(msg); +// DoIMLocation(msg); // break; // } // } @@ -1914,10 +1598,8 @@ TermView::MessageReceived(BMessage *msg) } } } -//////////////////////////////////////////////////////////////////////////// -// DoFileDrop -// Gets dropped file full path and display it at cursor position. -//////////////////////////////////////////////////////////////////////////// + +// Gets dropped file full path and display it at cursor position. void TermView::DoFileDrop(entry_ref &ref) { @@ -1927,335 +1609,319 @@ TermView::DoFileDrop(entry_ref &ref) string.CharacterEscape(" ~`#$&*()\\|[]{};'\"<>?!",'\\'); string+=" "; - WritePTY ((const uchar *)string.String(), string.Length()); - - return; - + WritePTY((const uchar *)string.String(), string.Length()); } -//////////////////////////////////////////////////////////////////////////// -// DoCopy() -// Copy selection text to Clipboard. -//////////////////////////////////////////////////////////////////////////// + +// Copy selected text to Clipboard. void TermView::DoCopy() { - if(!fSelected) return; - - BString copyStr(""); - - fTextBuffer->GetStringFromRegion (copyStr); - - if (be_clipboard->Lock()) { - BMessage *clipMsg = NULL; - be_clipboard->Clear(); - if ((clipMsg = be_clipboard->Data()) != NULL) { - clipMsg->AddData("text/plain", B_MIME_TYPE, copyStr.String(), copyStr.Length()); - be_clipboard->Commit(); - } - be_clipboard->Unlock(); - } - + if(!fSelected) + return; + + BString copyStr(""); + + fTextBuffer->GetStringFromRegion(copyStr); + + if(be_clipboard->Lock()) { + + BMessage *clipMsg = NULL; + be_clipboard->Clear(); + + if((clipMsg = be_clipboard->Data()) != NULL) { + + clipMsg->AddData("text/plain", B_MIME_TYPE, copyStr.String(), + copyStr.Length()); + be_clipboard->Commit(); + } + be_clipboard->Unlock(); + } + // Deselecting the current selection is not the behavior that // R5's Terminal app displays. We want to mimic the behavior, so we will // no longer do the deselection -// if (!fMouseTracking) { -// this->DeSelect (); -// } - +// if(!fMouseTracking) +// DeSelect(); } -//////////////////////////////////////////////////////////////////////////// -// DoPaste() -// Inserts text of Clipboard at cursor position. -//////////////////////////////////////////////////////////////////////////// + +// Paste clipboard text at cursor position. void TermView::DoPaste(void) { - if ( be_clipboard->Lock() ) { - BMessage *clipMsg = be_clipboard->Data(); - char *text; - ssize_t num_bytes; - - if ( clipMsg->FindData((const char *)"text/plain", - (type_code) B_MIME_TYPE, - (const void **)&text, - &num_bytes) == B_OK ) { - - /* Clipboard text doesn't attached EOF? */ - text[num_bytes] = '\0'; - - WritePTY ((uchar *)text, num_bytes); - } - - be_clipboard->Unlock(); - } - + if( be_clipboard->Lock() ) { + + BMessage *clipMsg = be_clipboard->Data(); + char *text; + ssize_t num_bytes; + + if( clipMsg->FindData((const char *)"text/plain", + (type_code) B_MIME_TYPE, + (const void **)&text, + &num_bytes) == B_OK ) { + + // Clipboard text doesn't attached EOF? + text[num_bytes] = '\0'; + + WritePTY((uchar *)text, num_bytes); + } + + be_clipboard->Unlock(); + } } -//////////////////////////////////////////////////////////////////////////// -// DoSelectAll() -// Select all displayed text and text /in buffer. -//////////////////////////////////////////////////////////////////////////// + +// Select all displayed text and text /in buffer. void TermView::DoSelectAll(void) { - CurPos start, end; - int screen_top; - int viewheight, start_pos; - - screen_top = fTop / fFontHeight; - viewheight = fTermRows; - - start_pos = screen_top - (fScrBufSize - viewheight * 2); - - start.x = 0; - end.x = fTermColumns -1; - - if (start_pos > 0) { - start.y = start_pos; - } - else { - start.y = 0; - } - end.y = fCurPos.y + screen_top; - - this->Select (start, end); + CurPos start, end; + int screen_top; + int viewheight, start_pos; + + screen_top = fTop / fFontHeight; + viewheight = fTermRows; + + start_pos = screen_top -(fScrBufSize - viewheight * 2); + + start.x = 0; + end.x = fTermColumns -1; + + if(start_pos > 0) + start.y = start_pos; + else + start.y = 0; + + end.y = fCurPos.y + screen_top; + + Select(start, end); } -//////////////////////////////////////////////////////////////////////////// -// DoClearAll() -// Clear display and text buffer, then moves Cursorr at home position. -//////////////////////////////////////////////////////////////////////////// + +// Clear display and text buffer, then moves Cursorr at home position. void TermView::DoClearAll(void) { - this->DeSelect (); - fTextBuffer->ClearAll(); - - fTop = 0; - ScrollTo (0, 0); - - if (this -> LockLooper ()) { - SetHighColor (fTextBackColor); - - FillRect (Bounds()); - SetHighColor (fTextForeColor); - this -> UnlockLooper (); - } - - // reset cursor pos - this->SetCurPos (0, 0); - - // reset selection. - fSelected = false; - - fScrollBar->SetRange(0, 0); - fScrollBar->SetProportion (1); - -} -//////////////////////////////////////////////////////////////////////////// -// SubstMetaChar (char *, char *) -// Substitution meta character. -//////////////////////////////////////////////////////////////////////////// -int -TermView::SubstMetaChar (const char *p, char *q) -{ - char *metachar = " ~`#$&*()\\|[]{};'\"<>?!"; - int num_char = 0; - - while (*p) { - char *mp = metachar; - for (int i = 0; i < 22; i++){ - if (*p == *mp++) { - *q++ = '\\'; - num_char++; - break; - } - } - *q++ = *p++; - num_char++; - } - /* Add null string. */ - *q = *p; - return (num_char + 1); - -} - -//////////////////////////////////////////////////////////////////////////// -// WritePTY (const uchar *) -// Write strings to PTY device. If coding system isn't UTF8, change -// coding to UTF8 before writting PTY. -//////////////////////////////////////////////////////////////////////////// -void -TermView::WritePTY (const uchar *text, int num_bytes) -{ - if (gNowCoding != M_UTF8) { - uchar *dstbuf = (uchar *)malloc (num_bytes * 3); - num_bytes = fCodeConv->ConvertFromInternal(text, dstbuf, gNowCoding); - write (pfd, dstbuf, num_bytes); - free (dstbuf); - } else{ - write (pfd, text, num_bytes); - } - -} - -//////////////////////////////////////////////////////////////////////////// -// SetupPop() -// Make encoding pop up menu (make copy of window's one.) -//////////////////////////////////////////////////////////////////////////// -void -TermView::SetupPop (void) -{ - fPopMenu = new BPopUpMenu(""); - MakeEncodingMenu(fPopMenu, gNowCoding, true); - fPopMenu->SetTargetForItems(Window()); -} -//////////////////////////////////////////////////////////////////////////// -// SetupMouseButton() -// convert button name to number. -//////////////////////////////////////////////////////////////////////////// -int32 -TermView::SetupMouseButton (const char *bname) -{ - if (!strcmp (bname, "Disable")){ - return 0; - }else if (!strcmp (bname, "Button 1")){ - return B_PRIMARY_MOUSE_BUTTON; - }else if (!strcmp (bname, "Button 2")){ - return B_SECONDARY_MOUSE_BUTTON; - }else if (!strcmp (bname, "Button 3")){ - return B_TERTIARY_MOUSE_BUTTON; - }else{ - return 0; //Disable - } -} -//////////////////////////////////////////////////////////////////////////// -// MouseDown() -// Handle mouse button operation. -//////////////////////////////////////////////////////////////////////////// -void -TermView::MouseDown (BPoint where) -{ - int32 buttons = 0, clicks = 0; - int32 mod; - BPoint inPoint; - ssize_t num_bytes; - - Window()->CurrentMessage()->FindInt32("buttons", &buttons); - - /* - * paste button - */ - if(buttons == mPasteMenuButton) { - if (fSelected) { - /* If selected region, copy text from region. */ - BString copyStr (""); - - fTextBuffer->GetStringFromRegion (copyStr); - - num_bytes = copyStr.Length (); - WritePTY ((uchar *)copyStr.String (), num_bytes); - - } - else { - /* If don't selected, copy text from clipboard. */ - DoPaste (); - } - - return; - } - - /* - * Select Region - */ - if (buttons == mSelectButton) { - - Window()->CurrentMessage()->FindInt32 ("modifiers", &mod); - Window()->CurrentMessage()->FindInt32 ("clicks", &clicks); - - if (fSelected) { - CurPos inPos, stPos, edPos; - if (fSelStart < fSelEnd) { - stPos = fSelStart; - edPos = fSelEnd; - } - else { - stPos = fSelEnd; - edPos = fSelStart; - } - inPos = BPointToCurPos (where); - - /* - * If mouse pointer is avove selected Region, start Drag'n Copy. - */ - if (inPos > stPos && inPos < edPos) { - if (mod & B_CONTROL_KEY || gTermPref->getInt32 (PREF_DRAGN_COPY)) { - - BPoint p; - uint32 bt; - - do { - GetMouse (&p, &bt); - if (bt == 0) { - this->DeSelect(); - return; - } - - snooze (40 * 1000); - } while (abs((int)(where.x - p.x)) < 4 - && abs((int)(where.y - p.y)) < 4); - - - BString copyStr (""); - fTextBuffer->GetStringFromRegion (copyStr); + DeSelect(); + fTextBuffer->ClearAll(); - BMessage msg(B_MIME_TYPE); - msg.AddData ("text/plain", - B_MIME_TYPE, - copyStr.String(), - copyStr.Length()); - - BPoint st = CurPosToBPoint (stPos); - BPoint ed = CurPosToBPoint (edPos); - BRect r; - - if (stPos.y == edPos.y) { - r.Set (st.x, st.y - fTop, - ed.x + fFontWidth, ed.y + fFontHeight - fTop); - } - else { - r.Set (0, st.y - fTop, - fTermColumns * fFontWidth, ed.y + fFontHeight - fTop); - } - r = r & Bounds(); + fTop = 0; + ScrollTo(0, 0); - DragMessage (&msg, r); - return; + if(LockLooper()) { + SetHighColor(fTextBackColor); + + FillRect(Bounds()); + SetHighColor(fTextForeColor); + UnlockLooper(); } - } - } + + // reset cursor pos + SetCurPos(0, 0); + + // reset selection. + fSelected = false; + + fScrollBar->SetRange(0, 0); + fScrollBar->SetProportion(1); +} - /* If mouse has a lot of movement, disable double/triple - click. */ +// Substitution meta character +int +TermView::SubstMetaChar(const char *p, char *q) +{ + char *metachar = " ~`#$&*()\\|[]{};'\"<>?!"; + int num_char = 0; + + while(*p) { + + char *mp = metachar; + for(int i = 0; i < 22; i++){ + + if(*p == *mp++) { + *q++ = '\\'; + num_char++; + break; + } + } + + *q++ = *p++; + num_char++; + } + + // Add null string + *q = *p; + return(num_char + 1); +} + +// Write strings to PTY device. If encoding system isn't UTF8, change +// encoding to UTF8 before writing PTY. +void +TermView::WritePTY(const uchar *text, int num_bytes) +{ + if(gNowCoding != M_UTF8) { + uchar *dstbuf =(uchar *)malloc(num_bytes * 3); + num_bytes = fCodeConv->ConvertFromInternal(text, dstbuf, gNowCoding); + write(pfd, dstbuf, num_bytes); + free(dstbuf); + + } else { + write(pfd, text, num_bytes); + } +} + +// Make encoding pop up menu (make copy of window's one.) +void +TermView::SetupPop(void) +{ + fPopMenu = new BPopUpMenu(""); + MakeEncodingMenu(fPopMenu, gNowCoding, true); + fPopMenu->SetTargetForItems(Window()); +} + +// convert button name to number. +int32 +TermView::SetupMouseButton(const char *bname) +{ + if(!strcmp(bname, "Disable")) { + return 0; + } + else if(!strcmp(bname, "Button 1")) { + return B_PRIMARY_MOUSE_BUTTON; + } + else if(!strcmp(bname, "Button 2")) { + return B_SECONDARY_MOUSE_BUTTON; + } + else if(!strcmp(bname, "Button 3")) { + return B_TERTIARY_MOUSE_BUTTON; + + } else { + + return 0; //Disable + } +} + +void +TermView::MouseDown(BPoint where) +{ + int32 buttons = 0, clicks = 0; + int32 mod; + BPoint inPoint; + ssize_t num_bytes; + + Window()->CurrentMessage()->FindInt32("buttons", &buttons); + + // paste button + if(buttons == mPasteMenuButton) { + + if(fSelected) { + // If selected region, copy text from region. + BString copyStr(""); + + fTextBuffer->GetStringFromRegion(copyStr); + + num_bytes = copyStr.Length(); + WritePTY((uchar *)copyStr.String(), num_bytes); + } + else { + // If don't selected, copy text from clipboard. + DoPaste(); + } + return; + } + + // Select Region + if(buttons == mSelectButton) { + + Window()->CurrentMessage()->FindInt32("modifiers", &mod); + Window()->CurrentMessage()->FindInt32("clicks", &clicks); + + if(fSelected) { + + CurPos inPos, stPos, edPos; + + if(fSelStart < fSelEnd) { + stPos = fSelStart; + edPos = fSelEnd; + + } else { + stPos = fSelEnd; + edPos = fSelStart; + } + + inPos = BPointToCurPos(where); + + // If mouse pointer is avove selected Region, start Drag'n Copy. + if(inPos > stPos && inPos < edPos) { + if(mod & B_CONTROL_KEY || gTermPref->getInt32(PREF_DRAGN_COPY)) { + + BPoint p; + uint32 bt; + + do { + + GetMouse(&p, &bt); + + if(bt == 0) { + DeSelect(); + return; + } + + snooze(40 * 1000); + + } while(abs((int)(where.x - p.x)) < 4 + && abs((int)(where.y - p.y)) < 4); + + BString copyStr(""); + fTextBuffer->GetStringFromRegion(copyStr); + + BMessage msg(B_MIME_TYPE); + msg.AddData("text/plain", + B_MIME_TYPE, + copyStr.String(), + copyStr.Length()); + + BPoint st = CurPosToBPoint(stPos); + BPoint ed = CurPosToBPoint(edPos); + BRect r; + + if(stPos.y == edPos.y) { + r.Set(st.x, st.y - fTop, + ed.x + fFontWidth, ed.y + fFontHeight - fTop); + + } else { + + r.Set(0, st.y - fTop, + fTermColumns * fFontWidth, ed.y + fFontHeight - fTop); + } + + r = r & Bounds(); + + DragMessage(&msg, r); + return; + } + } + } + + // If mouse has a lot of movement, disable double/triple click. inPoint = fPreviousMousePoint - where; - if (abs ((int)inPoint.x) > 16 || abs ((int)inPoint.y) > 16) clicks = 1; + if(abs((int)inPoint.x) > 16 || abs((int)inPoint.y) > 16) clicks = 1; fPreviousMousePoint = where; - if (mod & B_SHIFT_KEY) { - AddSelectRegion (BPointToCurPos (where)); + if(mod & B_SHIFT_KEY) { + AddSelectRegion(BPointToCurPos(where)); } else { - this->DeSelect (); + DeSelect(); } - /* If clicks larger than 3, reset mouse click counter. */ + // If clicks larger than 3, reset mouse click counter. clicks = clicks % 3; - if (clicks == 0) clicks = 3; + if(clicks == 0) clicks = 3; - switch (clicks){ + switch(clicks){ case 1: fMouseTracking = true; - send_data (fMouseThread, + send_data(fMouseThread, MOUSE_THR_CODE, - (void *)&where, - sizeof (BPoint)); + (void *)&where, + sizeof(BPoint)); break; case 2: @@ -2269,382 +1935,354 @@ TermView::MouseDown (BPoint where) return; } - /* - * Sub menu (coding popup menu) - */ - if (buttons == mSubMenuButton){ - ConvertToScreen(&where); - this->SetupPop(); - fPopMenu->Go (where, true); - delete fPopMenu; - return; - } - - BView::MouseDown (where); - - return; + // Sub menu(coding popup menu) + if(buttons == mSubMenuButton){ + ConvertToScreen(&where); + SetupPop(); + fPopMenu->Go(where, true); + delete fPopMenu; + return; + } + + BView::MouseDown(where); } -//////////////////////////////////////////////////////////////////////////// -// MouseMoved() -// -//////////////////////////////////////////////////////////////////////////// void -TermView::MouseMoved (BPoint /*point*/, uint32 transit, - const BMessage */*message*/) +TermView::MouseMoved(BPoint, uint32 transit, const BMessage *) { - if (fMouseImage && Window()->IsActive ()) { - if (transit == B_ENTERED_VIEW) - be_app->SetCursor (B_I_BEAM_CURSOR); - if (transit == B_EXITED_VIEW) - be_app->SetCursor (B_HAND_CURSOR); - } - return; - + if(fMouseImage && Window()->IsActive()) { + + if(transit == B_ENTERED_VIEW) + be_app->SetCursor(B_I_BEAM_CURSOR); + if(transit == B_EXITED_VIEW) + be_app->SetCursor(B_HAND_CURSOR); + } } -//////////////////////////////////////////////////////////////////////////// -// Select // Select a range of text -//////////////////////////////////////////////////////////////////////////// void -TermView::Select (CurPos start, CurPos end) +TermView::Select(CurPos start, CurPos end) { - - uchar buf[4]; - ushort attr; - - if (start.x < 0) - start.x = 0; - if (end.x >= fTermColumns) - end.x = fTermColumns - 1; - - if (fTextBuffer->GetChar (start.y, start.x, buf, &attr) == IN_STRING) { - start.x--; - if (start.x < 0) start.x = 0; - } - if (fTextBuffer->GetChar (end.y, end.x, buf, &attr) == IN_STRING) { - end.x++; - if (end.x >= fTermColumns) end.x = fTermColumns; - } - - fSelStart = start; - fSelEnd = end; - - fTextBuffer->Select(fSelStart, fSelEnd); - this->TermDrawSelectedRegion (fSelStart, fSelEnd); - fSelected = true; + uchar buf[4]; + ushort attr; + + if(start.x < 0) + start.x = 0; + if(end.x >= fTermColumns) + end.x = fTermColumns - 1; + + if(fTextBuffer->GetChar(start.y, start.x, buf, &attr) == IN_STRING) { + start.x--; + if(start.x < 0) start.x = 0; + } + + if(fTextBuffer->GetChar(end.y, end.x, buf, &attr) == IN_STRING) { + end.x++; + if(end.x >= fTermColumns) end.x = fTermColumns; + } + + fSelStart = start; + fSelEnd = end; + + fTextBuffer->Select(fSelStart, fSelEnd); + TermDrawSelectedRegion(fSelStart, fSelEnd); + fSelected = true; } -//////////////////////////////////////////////////////////////////////////// -// AddSelectRegion -// Add select region (shift + mouse click) -//////////////////////////////////////////////////////////////////////////// +// Add select region(shift + mouse click) void -TermView::AddSelectRegion (CurPos pos) +TermView::AddSelectRegion(CurPos pos) { - uchar buf[4]; - ushort attr; - CurPos start, end, inPos; - - if (!fSelected) return; - - /* - * error check, and if mouse point to a plase full width character, - * select point decliment. - */ - if (pos.x >= fTermColumns) - pos.x = fTermColumns - 1; - else if (pos.x < 0) - pos.x = 0; - - if (pos.y < 0) - pos.y = 0; - - if (fTextBuffer->GetChar (pos.y, pos.x, buf, &attr) == IN_STRING) { - pos.x++; - if (pos.x >= fTermColumns) pos.x = fTermColumns - 1; - } - - start = fSelStart; - end = fSelEnd; - - /* - * Mouse point is same as selected line. - */ - if (pos.y == fSelStart.y && pos.y == fSelEnd.y) { - if (abs (pos.x - start.x) > abs (pos.x - end.x)) { - fSelStart = start; - fSelEnd = pos; - inPos = end; - } else { - fSelStart = end; - fSelEnd = pos; - inPos = start; - } - } - /* - * else, End point set to near the start or end point. - */ - else if (abs (pos.y - start.y) > abs (pos.y - end.y)) { - fSelStart = start; - fSelEnd = pos; - inPos = end; - } else if (abs (pos.y - start.y) > abs (pos.y - end.y)) { - fSelStart = end; - fSelEnd = pos; - inPos = start; - } else { - if (start > end) { - inPos = start; - start = end; - end = inPos; - } - - if (pos.y < start.y) { - fSelStart = end; - fSelEnd = pos; - inPos = start; - } else { - fSelStart = start; - fSelEnd = pos; - inPos = end; - } - } - - fTextBuffer->Select (fSelStart, fSelEnd); - this->TermDrawSelectedRegion (inPos, fSelEnd); - + uchar buf[4]; + ushort attr; + CurPos start, end, inPos; + + if(!fSelected) + return; + + // error check, and if mouse point to a plase full width character, + // select point decliment. + if(pos.x >= fTermColumns) + pos.x = fTermColumns - 1; + else + if(pos.x < 0) + pos.x = 0; + + if(pos.y < 0) + pos.y = 0; + + if(fTextBuffer->GetChar(pos.y, pos.x, buf, &attr) == IN_STRING) { + pos.x++; + if(pos.x >= fTermColumns) + pos.x = fTermColumns - 1; + } + + start = fSelStart; + end = fSelEnd; + + // Mouse point is same as selected line. + if(pos.y == fSelStart.y && pos.y == fSelEnd.y) { + + if(abs(pos.x - start.x) > abs(pos.x - end.x)) { + + fSelStart = start; + fSelEnd = pos; + inPos = end; + + } else { + + fSelStart = end; + fSelEnd = pos; + inPos = start; + } + } + + // else, End point set to near the start or end point. + else + if(abs(pos.y - start.y) > abs(pos.y - end.y)) { + fSelStart = start; + fSelEnd = pos; + inPos = end; + } + else if(abs(pos.y - start.y) > abs(pos.y - end.y)) { + fSelStart = end; + fSelEnd = pos; + inPos = start; + + } else { + + if(start > end) { + inPos = start; + start = end; + end = inPos; + } + + if(pos.y < start.y) { + fSelStart = end; + fSelEnd = pos; + inPos = start; + } else { + fSelStart = start; + fSelEnd = pos; + inPos = end; + } + } + + fTextBuffer->Select(fSelStart, fSelEnd); + TermDrawSelectedRegion(inPos, fSelEnd); } -//////////////////////////////////////////////////////////////////////////// -// ResizeSelectRegion -// Resize select region (mouse drag) -//////////////////////////////////////////////////////////////////////////// +// Resize select region (mouse drag) void -TermView::ResizeSelectRegion (CurPos pos) +TermView::ResizeSelectRegion(CurPos pos) { - CurPos inPos; - uchar buf[4]; - ushort attr; - - inPos = fSelEnd; - - /* - * error check, and if mouse point to a plase full width character, - * select point decliment. - */ - if (pos.x >= fTermColumns) - pos.x = fTermColumns - 1; - else if (pos.x < 0) - pos.x = 0; - - if (pos.y < 0) - pos.y = 0; - - if (fTextBuffer->GetChar (pos.y, pos.x, buf, &attr) == IN_STRING) { - pos.x++; - if (pos == inPos) return; - if (pos.x >= fTermColumns) pos.x = fTermColumns - 1; - } - - fSelEnd = pos; - - fTextBuffer->Select (fSelStart, pos); - this->TermDrawSelectedRegion (inPos, pos); - + CurPos inPos; + uchar buf[4]; + ushort attr; + + inPos = fSelEnd; + + // error check, and if mouse point to a plase full width character, + // select point decliment. + if(pos.x >= fTermColumns) + pos.x = fTermColumns - 1; + else + if(pos.x < 0) + pos.x = 0; + + if(pos.y < 0) + pos.y = 0; + + if(fTextBuffer->GetChar(pos.y, pos.x, buf, &attr) == IN_STRING) { + + pos.x++; + + if(pos == inPos) + return; + + if(pos.x >= fTermColumns) + pos.x = fTermColumns - 1; + } + fSelEnd = pos; + + fTextBuffer->Select(fSelStart, pos); + TermDrawSelectedRegion(inPos, pos); } -//////////////////////////////////////////////////////////////////////////// -// DeSelect // DeSelect a range of text -//////////////////////////////////////////////////////////////////////////// void -TermView::DeSelect (void) +TermView::DeSelect(void) { - CurPos start, end; - - if (!fSelected) return; - - fTextBuffer->DeSelect (); - - start = fSelStart; - end = fSelEnd; - - fSelStart.Set (-1, -1); - fSelEnd.Set (-1, -1); - - this->TermDrawSelectedRegion (start, end); - - fSelected = false; - + CurPos start, end; + + if(!fSelected) + return; + + fTextBuffer->DeSelect(); + + start = fSelStart; + end = fSelEnd; + + fSelStart.Set(-1, -1); + fSelEnd.Set(-1, -1); + + TermDrawSelectedRegion(start, end); + + fSelected = false; } -//////////////////////////////////////////////////////////////////////////// -// SelectWord -// Hilite a word -//////////////////////////////////////////////////////////////////////////// + void TermView::SelectWord(BPoint where, int mod) { - CurPos start, end, pos; - bool flag; - - pos = BPointToCurPos (where); - flag = fTextBuffer->FindWord(pos, &start, &end); - - if (mod & B_SHIFT_KEY) { - if (flag) { - if (start < fSelStart) { - AddSelectRegion (start); - } else if (end > fSelEnd) { - AddSelectRegion (end); - } - } else { - AddSelectRegion (pos); - } - } else { - this->DeSelect (); - if (flag) - this->Select (start, end); - } + CurPos start, end, pos; + bool flag; + + pos = BPointToCurPos(where); + flag = fTextBuffer->FindWord(pos, &start, &end); + + if(mod & B_SHIFT_KEY) { + + if(flag) { + + if(start < fSelStart) { + AddSelectRegion(start); + } + else + if(end > fSelEnd) { + AddSelectRegion(end); + } + + } else { + AddSelectRegion(pos); + } + + } else { + DeSelect(); + if(flag) + Select(start, end); + } } -//////////////////////////////////////////////////////////////////////////// -// SelectLine -// Hilite a Line -//////////////////////////////////////////////////////////////////////////// void TermView::SelectLine(BPoint where, int mod) { - CurPos start, end, pos; - - pos = BPointToCurPos (where); - - if (mod & B_SHIFT_KEY) { - start = CurPos(0, pos.y); - end = CurPos (fTermColumns - 1, pos.y); - if (start < fSelStart) { - AddSelectRegion (start); - } else if (end > fSelEnd) { - AddSelectRegion (end); - } - } - else { - this->DeSelect (); - this->Select (CurPos (0, pos.y), CurPos (fTermColumns - 1, pos.y)); - } - + CurPos start, end, pos; + + pos = BPointToCurPos(where); + + if(mod & B_SHIFT_KEY) { + + start = CurPos(0, pos.y); + end = CurPos(fTermColumns - 1, pos.y); + + if(start < fSelStart) { + AddSelectRegion(start); + } + else + if(end > fSelEnd) { + AddSelectRegion(end); + } + + } else { + DeSelect(); + Select(CurPos(0, pos.y), CurPos(fTermColumns - 1, pos.y)); + } } -//////////////////////////////////////////////////////////////////////////// -// BPointToCurPos + // Convert View visible area corrdination to cursor position. -//////////////////////////////////////////////////////////////////////////// CurPos -TermView::BPointToCurPos (const BPoint &p) +TermView::BPointToCurPos(const BPoint &p) { - - return CurPos (p.x / fFontWidth, - p.y / fFontHeight); - + return CurPos(p.x / fFontWidth, p.y / fFontHeight); } -//////////////////////////////////////////////////////////////////////////// -// CurPosToBPoint + // Convert cursor position to view coordination. -//////////////////////////////////////////////////////////////////////////// BPoint -TermView::CurPosToBPoint (const CurPos &pos) +TermView::CurPosToBPoint(const CurPos &pos) { - return BPoint(fFontWidth * pos.x, - pos.y * fFontHeight + fTop); + return BPoint(fFontWidth * pos.x, pos.y * fFontHeight + fTop); } -//////////////////////////////////////////////////////////////////////////// -// CheckSelectedRegion -// -//////////////////////////////////////////////////////////////////////////// + bool -TermView::CheckSelectedRegion (const CurPos &pos) +TermView::CheckSelectedRegion(const CurPos &pos) { - - CurPos start, end; - - if (fSelStart > fSelEnd) { - start = fSelEnd; - end = fSelStart; - } - else { - start = fSelStart; - end = fSelEnd; - } - - if (pos >= start && pos <= end) - return true; - - return false; + CurPos start, end; + + if(fSelStart > fSelEnd) { + start = fSelEnd; + end = fSelStart; + + } else { + + start = fSelStart; + end = fSelEnd; + } + + if(pos >= start && pos <= end) + return true; + + return false; } -//////////////////////////////////////////////////////////////////////////// -// GetFrameSize -// -//////////////////////////////////////////////////////////////////////////// + void -TermView::GetFrameSize (float *width, float *height) +TermView::GetFrameSize(float *width, float *height) { - if(width != NULL) *width = fTermColumns * fFontWidth; - if(height == NULL) return; - - if (!fTop){ - *height = fTermRows * fFontHeight; - return; - } - - if (fTop - fTermRows * fFontHeight > fScrBufSize * fFontHeight){ - *height = fScrBufSize * fFontHeight; - return; - } - - *height = fTop + fTermRows * fFontHeight; + if(width != NULL) + *width = fTermColumns * fFontWidth; + + if(height == NULL) + return; + + if(!fTop){ + *height = fTermRows * fFontHeight; + return; + } + + if(fTop - fTermRows * fFontHeight > fScrBufSize * fFontHeight) { + + *height = fScrBufSize * fFontHeight; + return; + } + + *height = fTop + fTermRows * fFontHeight; } -//////////////////////////////////////////////////////////////////////////// -// GetFontInfo (int *, int*) -// Sets terninal rows and cols. -//////////////////////////////////////////////////////////////////////////// +// Sets terninal rows and cols. void -TermView::GetFontInfo (int *width, int *height) +TermView::GetFontInfo(int *width, int *height) { - *width = fFontWidth; - *height = fFontHeight; - return; + *width = fFontWidth; + *height = fFontHeight; } -//////////////////////////////////////////////////////////////////////////// -// SendDataToDrawEngine (int, int, int, int) -// Send DrawRect data to Draw Engline thread. -//////////////////////////////////////////////////////////////////////////// +// Send DrawRect data to Draw Engine thread. inline void -TermView::SendDataToDrawEngine (int x1, int y1, int x2, int y2) +TermView::SendDataToDrawEngine(int x1, int y1, int x2, int y2) { - - sem_info info; - - retry: - get_sem_info(fDrawRectSem, &info); - if ((RECT_BUF_SIZE - info.count) < 2) { - snooze (10 * 1000); - goto retry; - } - - fDrawRectBuffer[fDrawRect_p].x1 = x1; - fDrawRectBuffer[fDrawRect_p].x2 = x2; - fDrawRectBuffer[fDrawRect_p].y1 = y1; - fDrawRectBuffer[fDrawRect_p].y2 = y2; - - fDrawRect_p++; - fDrawRect_p %= RECT_BUF_SIZE; - - release_sem (fDrawRectSem); - - return; + // TODO: remove the goto + + sem_info info; + + retry: + + get_sem_info(fDrawRectSem, &info); + + if((RECT_BUF_SIZE - info.count) < 2) { + + snooze(10 * 1000); + goto retry; + } + + fDrawRectBuffer[fDrawRect_p].x1 = x1; + fDrawRectBuffer[fDrawRect_p].x2 = x2; + fDrawRectBuffer[fDrawRect_p].y1 = y1; + fDrawRectBuffer[fDrawRect_p].y2 = y2; + + fDrawRect_p++; + fDrawRect_p %= RECT_BUF_SIZE; + + release_sem(fDrawRectSem); }