diff --git a/src/apps/terminal/CodeConv.cpp b/src/apps/terminal/CodeConv.cpp index 2af5a842f5..181b354f53 100644 --- a/src/apps/terminal/CodeConv.cpp +++ b/src/apps/terminal/CodeConv.cpp @@ -38,14 +38,11 @@ extern char gUTF8WidthTable[]; // defined in UTF8WidthTbl.c int32 CodeConv::UTF8GetFontWidth(const char *string) { - uchar width, point; - ushort unicode, offset; + ushort unicode = UTF8toUnicode(string); + uchar width = gUTF8WidthTable[unicode >> 3]; + ushort offset = unicode & 0x07; - offset = unicode = UTF8toUnicode(string); - width = gUTF8WidthTable[unicode >> 3]; - offset = offset & 0x07; - - point = 0x80 >> offset; + uchar point = 0x80 >> offset; return (width & point) > 0 ? 2 : 1; } @@ -72,6 +69,9 @@ CodeConv::ConvertFromInternal(const char *src, int32 srclen, char *dst, int codi convert_from_utf8(theCoding, (char *)src, &srclen, (char *)dst, &dstlen, &state, '?'); + // TODO: Apart from this particular case, looks like we could use the + // system api for code conversion... check if this (which looks a lot like a workaround) + // applies to haiku, and if not, get rid of this class and just use the system api directly. if (coding == M_ISO_2022_JP && state != 0) { const char *end_of_jis = ""; strncpy((char *)dst + dstlen, end_of_jis, 3); diff --git a/src/apps/terminal/TermView.cpp b/src/apps/terminal/TermView.cpp index 163f908354..fad404b29e 100644 --- a/src/apps/terminal/TermView.cpp +++ b/src/apps/terminal/TermView.cpp @@ -61,7 +61,7 @@ const static rgb_color kTermColorTable[16] = { }; -TermView::TermView(BRect frame) +TermView::TermView(BRect frame, const char *command) : BView(frame, "termview", B_FOLLOW_ALL, B_WILL_DRAW | B_FRAME_EVENTS), fShell(NULL), fFontWidth(0), @@ -107,13 +107,28 @@ TermView::TermView(BRect frame) SetTermFont(be_plain_font, be_plain_font); //SetIMAware(PrefHandler::Default()->getInt32(PREF_IM_AWARE)); + // Get encoding name (setenv TTYPE in spawn_shell functions) + const char *encoding = longname2shortname(PrefHandler::Default()->getString(PREF_TEXT_ENCODING)); + fShell = new Shell(); + status_t status = fShell->Open(fTermRows, fTermColumns, command, encoding); + if (status < B_OK) + throw status; + + status = AttachShell(fShell); + if (status < B_OK) + throw status; + _InitMouseThread(); } TermView::~TermView() { + DetachShell(); + delete fTextBuffer; + delete fShell; + fQuitting = true; kill_thread(fMouseThread); } @@ -140,6 +155,16 @@ TermView::DetachShell() } +const char * +TermView::TerminalName() const +{ + if (fShell == NULL) + return NULL; + + return fShell->TTYName(); +} + + //! Get width and height for terminal font void TermView::GetFontSize(int* _width, int* _height) @@ -1030,7 +1055,7 @@ TermView::UpdateSIGWINCH() fShell->UpdateWindowSize(fTermRows, fTermColumns); - fFrameResized = 0; + fFrameResized = false; if (fScrRegionSet == 0) fScrBot = fTermRows - 1; } @@ -1381,7 +1406,7 @@ TermView::FrameResized(float width, float height) fTermRows = rows; fTermColumns = cols; - fFrameResized = 1; + fFrameResized = true; } diff --git a/src/apps/terminal/TermView.h b/src/apps/terminal/TermView.h index 69e4f75c3b..73edeb78bc 100644 --- a/src/apps/terminal/TermView.h +++ b/src/apps/terminal/TermView.h @@ -89,20 +89,22 @@ const unsigned char M_ADD_CURSOR [] = { 0x00, 0x10, }; -class TermBuffer; + class BPopUpMenu; class BScrollBar; class BString; class Shell; - +class TermBuffer; class TermView : public BView { public: - TermView(BRect frame); + TermView(BRect frame, const char *command); ~TermView(); status_t AttachShell(Shell *shell); void DetachShell(); + const char *TerminalName() const; + void SetTermFont(const BFont *halfFont, const BFont *fullFont); void GetFontSize(int *width, int *height); BRect SetTermSize(int rows, int cols, bool flag); diff --git a/src/apps/terminal/TermWindow.cpp b/src/apps/terminal/TermWindow.cpp index 7a8aa82374..7741768902 100644 --- a/src/apps/terminal/TermWindow.cpp +++ b/src/apps/terminal/TermWindow.cpp @@ -39,7 +39,6 @@ #include "TermView.h" #include "TermWindow.h" #include "TermConst.h" -#include "Shell.h" // @@ -53,7 +52,6 @@ TermWindow::TermWindow(BRect frame, const char* title, const char *command) : BWindow(frame, title, B_DOCUMENT_WINDOW, B_CURRENT_WORKSPACE|B_QUIT_ON_WINDOW_CLOSE), - fShell(NULL), fMenubar(NULL), fFilemenu(NULL), fEditmenu(NULL), @@ -67,7 +65,7 @@ TermWindow::TermWindow(BRect frame, const char* title, const char *command) fPrefWindow(NULL), fFindPanel(NULL), fWindowUpdate(NULL), - fSavedFrame(0, 0, 0, 0), + fSavedFrame(0, 0, -1, -1), fFindString(""), fFindForwardMenuItem(NULL), fFindBackwardMenuItem(NULL), @@ -76,34 +74,12 @@ TermWindow::TermWindow(BRect frame, const char* title, const char *command) fMatchCase(false), fMatchWord(false) { - int rows = PrefHandler::Default()->getInt32(PREF_ROWS); - if (rows < 1) { - rows = 1; - PrefHandler::Default()->setInt32(PREF_ROWS, rows); - } - - int cols = PrefHandler::Default()->getInt32(PREF_COLS); - if (cols < MIN_COLS) { - cols = MIN_COLS; - PrefHandler::Default()->setInt32(PREF_COLS, cols); - } - - // Get encoding name (setenv TTYPE in spawn_shell functions) - const char *encoding = longname2shortname(PrefHandler::Default()->getString(PREF_TEXT_ENCODING)); - fShell = new Shell(); - status_t status = fShell->Open(rows, cols, command, encoding); - if (status < 0) - throw status; - - InitWindow(); + _InitWindow(command); } TermWindow::~TermWindow() { - fTermView->DetachShell(); - - delete fShell; if (fPrefWindow) fPrefWindow->PostMessage(B_QUIT_REQUESTED); @@ -123,10 +99,10 @@ TermWindow::~TermWindow() /** Initialize Window object. */ void -TermWindow::InitWindow() +TermWindow::_InitWindow(const char *command) { // make menu bar - SetupMenu(); + _SetupMenu(); // Setup font. @@ -155,9 +131,7 @@ TermWindow::InitWindow() BRect textframe = Bounds(); textframe.top = fMenubar->Bounds().bottom + 1.0; - fTermView = new TermView(textframe); - - fTermView->AttachShell(fShell); + fTermView = new TermView(textframe, command); // Initialize TermView. (font, size and color) fTermView->SetTermFont(&halfFont, &fullFont); @@ -216,7 +190,7 @@ TermWindow::MenusBeginning() void -TermWindow::SetupMenu() +TermWindow::_SetupMenu() { PrefHandler menuText; @@ -437,7 +411,7 @@ TermWindow::MessageReceived(BMessage *message) } else if (!strcmp("tty", spe.FindString("property", i))) { BMessage reply(B_REPLY); - reply.AddString("result", fShell->TTYName()); + reply.AddString("result", fTermView->TerminalName()); message->SendReply(&reply); } else { BWindow::MessageReceived(message); @@ -486,7 +460,7 @@ TermWindow::MessageReceived(BMessage *message) r.Height()+fMenubar->Bounds().Height() + VIEW_OFFSET * 2); fTermView->Invalidate(); - break; + break; } case EIGHTYTWENTYFOUR: { PrefHandler::Default()->setString(PREF_COLS, "80"); @@ -530,7 +504,6 @@ TermWindow::MessageReceived(BMessage *message) BScreen screen(this); fTermView->ScrollBar()->Hide(); fMenubar->Hide(); - //fTermView->MoveTo(0,0); fTermView->ResizeBy(B_V_SCROLL_BAR_WIDTH, mbHeight); fSavedLook = Look(); // done before ResizeTo to work around a Dano bug (not erasing the decor) @@ -544,7 +517,6 @@ TermWindow::MessageReceived(BMessage *message) ResizeTo(fSavedFrame.Width(), fSavedFrame.Height()); MoveTo(fSavedFrame.left, fSavedFrame.top); fTermView->ResizeBy(-B_V_SCROLL_BAR_WIDTH, -mbHeight); - //fTermView->MoveTo(0,mbHeight); SetLook(fSavedLook); fSavedFrame = BRect(0,0,-1,-1); } @@ -552,7 +524,7 @@ TermWindow::MessageReceived(BMessage *message) } case MSG_FONT_CHANGED: { PrefHandler::Default()->setString (PREF_HALF_FONT_FAMILY, fNewFontMenu->FindMarked()->Label()); - PostMessage (MSG_HALF_FONT_CHANGED); + PostMessage(MSG_HALF_FONT_CHANGED); break; } case MSG_COLOR_CHANGED: { @@ -567,15 +539,15 @@ TermWindow::MessageReceived(BMessage *message) break; } case MENU_PAGE_SETUP: { - DoPageSetup (); + _DoPageSetup(); break; } case MENU_PRINT: { - DoPrint (); + _DoPrint(); break; } case MSGRUN_WINDOW: { - fTermView->UpdateSIGWINCH (); + fTermView->UpdateSIGWINCH(); break; } case B_ABOUT_REQUESTED: { @@ -668,7 +640,7 @@ TermWindow::ResolveSpecifier(BMessage *msg, int32 index, status_t -TermWindow::DoPageSetup() +TermWindow::_DoPageSetup() { BPrintJob job("PageSetup"); @@ -683,9 +655,9 @@ TermWindow::DoPageSetup() void -TermWindow::DoPrint() +TermWindow::_DoPrint() { - if (!fPrintSettings || (DoPageSetup() != B_NO_ERROR)) { + if (!fPrintSettings || (_DoPageSetup() != B_OK)) { (new BAlert("Cancel", "Print cancelled.", "OK"))->Go(); return; } diff --git a/src/apps/terminal/TermWindow.h b/src/apps/terminal/TermWindow.h index 9c089e46f8..15017c9c82 100644 --- a/src/apps/terminal/TermWindow.h +++ b/src/apps/terminal/TermWindow.h @@ -39,8 +39,6 @@ class BMenuBar; class BMessageRunner; class FindWindow; class PrefWindow; -class Shell; -class TermParse; class TermView; class TermWindow : public BWindow { @@ -62,13 +60,11 @@ protected: const char *property); private: - void InitWindow(); - void SetupMenu(); - status_t DoPageSetup(); - void DoPrint(); + void _InitWindow(const char *command); + void _SetupMenu(); + status_t _DoPageSetup(); + void _DoPrint(); - Shell *fShell; - TermParse *fTermParse; BMenuBar *fMenubar; BMenu *fFilemenu, *fEditmenu,