Fixed a bug where Terminal couldn't set itself to fullscreen the first
time. Some minor cleanups. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@21681 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -38,14 +38,11 @@ extern char gUTF8WidthTable[]; // defined in UTF8WidthTbl.c
|
|||||||
int32
|
int32
|
||||||
CodeConv::UTF8GetFontWidth(const char *string)
|
CodeConv::UTF8GetFontWidth(const char *string)
|
||||||
{
|
{
|
||||||
uchar width, point;
|
ushort unicode = UTF8toUnicode(string);
|
||||||
ushort unicode, offset;
|
uchar width = gUTF8WidthTable[unicode >> 3];
|
||||||
|
ushort offset = unicode & 0x07;
|
||||||
|
|
||||||
offset = unicode = UTF8toUnicode(string);
|
uchar point = 0x80 >> offset;
|
||||||
width = gUTF8WidthTable[unicode >> 3];
|
|
||||||
offset = offset & 0x07;
|
|
||||||
|
|
||||||
point = 0x80 >> offset;
|
|
||||||
|
|
||||||
return (width & point) > 0 ? 2 : 1;
|
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,
|
convert_from_utf8(theCoding, (char *)src, &srclen,
|
||||||
(char *)dst, &dstlen, &state, '?');
|
(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) {
|
if (coding == M_ISO_2022_JP && state != 0) {
|
||||||
const char *end_of_jis = "(B";
|
const char *end_of_jis = "(B";
|
||||||
strncpy((char *)dst + dstlen, end_of_jis, 3);
|
strncpy((char *)dst + dstlen, end_of_jis, 3);
|
||||||
|
|||||||
@@ -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),
|
: BView(frame, "termview", B_FOLLOW_ALL, B_WILL_DRAW | B_FRAME_EVENTS),
|
||||||
fShell(NULL),
|
fShell(NULL),
|
||||||
fFontWidth(0),
|
fFontWidth(0),
|
||||||
@@ -107,13 +107,28 @@ TermView::TermView(BRect frame)
|
|||||||
SetTermFont(be_plain_font, be_plain_font);
|
SetTermFont(be_plain_font, be_plain_font);
|
||||||
//SetIMAware(PrefHandler::Default()->getInt32(PREF_IM_AWARE));
|
//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();
|
_InitMouseThread();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
TermView::~TermView()
|
TermView::~TermView()
|
||||||
{
|
{
|
||||||
|
DetachShell();
|
||||||
|
|
||||||
delete fTextBuffer;
|
delete fTextBuffer;
|
||||||
|
delete fShell;
|
||||||
|
|
||||||
fQuitting = true;
|
fQuitting = true;
|
||||||
kill_thread(fMouseThread);
|
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
|
//! Get width and height for terminal font
|
||||||
void
|
void
|
||||||
TermView::GetFontSize(int* _width, int* _height)
|
TermView::GetFontSize(int* _width, int* _height)
|
||||||
@@ -1030,7 +1055,7 @@ TermView::UpdateSIGWINCH()
|
|||||||
|
|
||||||
fShell->UpdateWindowSize(fTermRows, fTermColumns);
|
fShell->UpdateWindowSize(fTermRows, fTermColumns);
|
||||||
|
|
||||||
fFrameResized = 0;
|
fFrameResized = false;
|
||||||
if (fScrRegionSet == 0)
|
if (fScrRegionSet == 0)
|
||||||
fScrBot = fTermRows - 1;
|
fScrBot = fTermRows - 1;
|
||||||
}
|
}
|
||||||
@@ -1381,7 +1406,7 @@ TermView::FrameResized(float width, float height)
|
|||||||
fTermRows = rows;
|
fTermRows = rows;
|
||||||
fTermColumns = cols;
|
fTermColumns = cols;
|
||||||
|
|
||||||
fFrameResized = 1;
|
fFrameResized = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -89,20 +89,22 @@ const unsigned char M_ADD_CURSOR [] = {
|
|||||||
0x00, 0x10,
|
0x00, 0x10,
|
||||||
};
|
};
|
||||||
|
|
||||||
class TermBuffer;
|
|
||||||
class BPopUpMenu;
|
class BPopUpMenu;
|
||||||
class BScrollBar;
|
class BScrollBar;
|
||||||
class BString;
|
class BString;
|
||||||
class Shell;
|
class Shell;
|
||||||
|
class TermBuffer;
|
||||||
class TermView : public BView {
|
class TermView : public BView {
|
||||||
public:
|
public:
|
||||||
TermView(BRect frame);
|
TermView(BRect frame, const char *command);
|
||||||
~TermView();
|
~TermView();
|
||||||
|
|
||||||
status_t AttachShell(Shell *shell);
|
status_t AttachShell(Shell *shell);
|
||||||
void DetachShell();
|
void DetachShell();
|
||||||
|
|
||||||
|
const char *TerminalName() const;
|
||||||
|
|
||||||
void SetTermFont(const BFont *halfFont, const BFont *fullFont);
|
void SetTermFont(const BFont *halfFont, const BFont *fullFont);
|
||||||
void GetFontSize(int *width, int *height);
|
void GetFontSize(int *width, int *height);
|
||||||
BRect SetTermSize(int rows, int cols, bool flag);
|
BRect SetTermSize(int rows, int cols, bool flag);
|
||||||
|
|||||||
@@ -39,7 +39,6 @@
|
|||||||
#include "TermView.h"
|
#include "TermView.h"
|
||||||
#include "TermWindow.h"
|
#include "TermWindow.h"
|
||||||
#include "TermConst.h"
|
#include "TermConst.h"
|
||||||
#include "Shell.h"
|
|
||||||
|
|
||||||
|
|
||||||
//
|
//
|
||||||
@@ -53,7 +52,6 @@
|
|||||||
|
|
||||||
TermWindow::TermWindow(BRect frame, const char* title, const char *command)
|
TermWindow::TermWindow(BRect frame, const char* title, const char *command)
|
||||||
: BWindow(frame, title, B_DOCUMENT_WINDOW, B_CURRENT_WORKSPACE|B_QUIT_ON_WINDOW_CLOSE),
|
: BWindow(frame, title, B_DOCUMENT_WINDOW, B_CURRENT_WORKSPACE|B_QUIT_ON_WINDOW_CLOSE),
|
||||||
fShell(NULL),
|
|
||||||
fMenubar(NULL),
|
fMenubar(NULL),
|
||||||
fFilemenu(NULL),
|
fFilemenu(NULL),
|
||||||
fEditmenu(NULL),
|
fEditmenu(NULL),
|
||||||
@@ -67,7 +65,7 @@ TermWindow::TermWindow(BRect frame, const char* title, const char *command)
|
|||||||
fPrefWindow(NULL),
|
fPrefWindow(NULL),
|
||||||
fFindPanel(NULL),
|
fFindPanel(NULL),
|
||||||
fWindowUpdate(NULL),
|
fWindowUpdate(NULL),
|
||||||
fSavedFrame(0, 0, 0, 0),
|
fSavedFrame(0, 0, -1, -1),
|
||||||
fFindString(""),
|
fFindString(""),
|
||||||
fFindForwardMenuItem(NULL),
|
fFindForwardMenuItem(NULL),
|
||||||
fFindBackwardMenuItem(NULL),
|
fFindBackwardMenuItem(NULL),
|
||||||
@@ -76,34 +74,12 @@ TermWindow::TermWindow(BRect frame, const char* title, const char *command)
|
|||||||
fMatchCase(false),
|
fMatchCase(false),
|
||||||
fMatchWord(false)
|
fMatchWord(false)
|
||||||
{
|
{
|
||||||
int rows = PrefHandler::Default()->getInt32(PREF_ROWS);
|
_InitWindow(command);
|
||||||
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();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
TermWindow::~TermWindow()
|
TermWindow::~TermWindow()
|
||||||
{
|
{
|
||||||
fTermView->DetachShell();
|
|
||||||
|
|
||||||
delete fShell;
|
|
||||||
if (fPrefWindow)
|
if (fPrefWindow)
|
||||||
fPrefWindow->PostMessage(B_QUIT_REQUESTED);
|
fPrefWindow->PostMessage(B_QUIT_REQUESTED);
|
||||||
|
|
||||||
@@ -123,10 +99,10 @@ TermWindow::~TermWindow()
|
|||||||
|
|
||||||
/** Initialize Window object. */
|
/** Initialize Window object. */
|
||||||
void
|
void
|
||||||
TermWindow::InitWindow()
|
TermWindow::_InitWindow(const char *command)
|
||||||
{
|
{
|
||||||
// make menu bar
|
// make menu bar
|
||||||
SetupMenu();
|
_SetupMenu();
|
||||||
|
|
||||||
// Setup font.
|
// Setup font.
|
||||||
|
|
||||||
@@ -155,9 +131,7 @@ TermWindow::InitWindow()
|
|||||||
BRect textframe = Bounds();
|
BRect textframe = Bounds();
|
||||||
textframe.top = fMenubar->Bounds().bottom + 1.0;
|
textframe.top = fMenubar->Bounds().bottom + 1.0;
|
||||||
|
|
||||||
fTermView = new TermView(textframe);
|
fTermView = new TermView(textframe, command);
|
||||||
|
|
||||||
fTermView->AttachShell(fShell);
|
|
||||||
|
|
||||||
// Initialize TermView. (font, size and color)
|
// Initialize TermView. (font, size and color)
|
||||||
fTermView->SetTermFont(&halfFont, &fullFont);
|
fTermView->SetTermFont(&halfFont, &fullFont);
|
||||||
@@ -216,7 +190,7 @@ TermWindow::MenusBeginning()
|
|||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
TermWindow::SetupMenu()
|
TermWindow::_SetupMenu()
|
||||||
{
|
{
|
||||||
PrefHandler menuText;
|
PrefHandler menuText;
|
||||||
|
|
||||||
@@ -437,7 +411,7 @@ TermWindow::MessageReceived(BMessage *message)
|
|||||||
}
|
}
|
||||||
else if (!strcmp("tty", spe.FindString("property", i))) {
|
else if (!strcmp("tty", spe.FindString("property", i))) {
|
||||||
BMessage reply(B_REPLY);
|
BMessage reply(B_REPLY);
|
||||||
reply.AddString("result", fShell->TTYName());
|
reply.AddString("result", fTermView->TerminalName());
|
||||||
message->SendReply(&reply);
|
message->SendReply(&reply);
|
||||||
} else {
|
} else {
|
||||||
BWindow::MessageReceived(message);
|
BWindow::MessageReceived(message);
|
||||||
@@ -486,7 +460,7 @@ TermWindow::MessageReceived(BMessage *message)
|
|||||||
r.Height()+fMenubar->Bounds().Height() + VIEW_OFFSET * 2);
|
r.Height()+fMenubar->Bounds().Height() + VIEW_OFFSET * 2);
|
||||||
|
|
||||||
fTermView->Invalidate();
|
fTermView->Invalidate();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case EIGHTYTWENTYFOUR: {
|
case EIGHTYTWENTYFOUR: {
|
||||||
PrefHandler::Default()->setString(PREF_COLS, "80");
|
PrefHandler::Default()->setString(PREF_COLS, "80");
|
||||||
@@ -530,7 +504,6 @@ TermWindow::MessageReceived(BMessage *message)
|
|||||||
BScreen screen(this);
|
BScreen screen(this);
|
||||||
fTermView->ScrollBar()->Hide();
|
fTermView->ScrollBar()->Hide();
|
||||||
fMenubar->Hide();
|
fMenubar->Hide();
|
||||||
//fTermView->MoveTo(0,0);
|
|
||||||
fTermView->ResizeBy(B_V_SCROLL_BAR_WIDTH, mbHeight);
|
fTermView->ResizeBy(B_V_SCROLL_BAR_WIDTH, mbHeight);
|
||||||
fSavedLook = Look();
|
fSavedLook = Look();
|
||||||
// done before ResizeTo to work around a Dano bug (not erasing the decor)
|
// 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());
|
ResizeTo(fSavedFrame.Width(), fSavedFrame.Height());
|
||||||
MoveTo(fSavedFrame.left, fSavedFrame.top);
|
MoveTo(fSavedFrame.left, fSavedFrame.top);
|
||||||
fTermView->ResizeBy(-B_V_SCROLL_BAR_WIDTH, -mbHeight);
|
fTermView->ResizeBy(-B_V_SCROLL_BAR_WIDTH, -mbHeight);
|
||||||
//fTermView->MoveTo(0,mbHeight);
|
|
||||||
SetLook(fSavedLook);
|
SetLook(fSavedLook);
|
||||||
fSavedFrame = BRect(0,0,-1,-1);
|
fSavedFrame = BRect(0,0,-1,-1);
|
||||||
}
|
}
|
||||||
@@ -552,7 +524,7 @@ TermWindow::MessageReceived(BMessage *message)
|
|||||||
}
|
}
|
||||||
case MSG_FONT_CHANGED: {
|
case MSG_FONT_CHANGED: {
|
||||||
PrefHandler::Default()->setString (PREF_HALF_FONT_FAMILY, fNewFontMenu->FindMarked()->Label());
|
PrefHandler::Default()->setString (PREF_HALF_FONT_FAMILY, fNewFontMenu->FindMarked()->Label());
|
||||||
PostMessage (MSG_HALF_FONT_CHANGED);
|
PostMessage(MSG_HALF_FONT_CHANGED);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case MSG_COLOR_CHANGED: {
|
case MSG_COLOR_CHANGED: {
|
||||||
@@ -567,15 +539,15 @@ TermWindow::MessageReceived(BMessage *message)
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case MENU_PAGE_SETUP: {
|
case MENU_PAGE_SETUP: {
|
||||||
DoPageSetup ();
|
_DoPageSetup();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case MENU_PRINT: {
|
case MENU_PRINT: {
|
||||||
DoPrint ();
|
_DoPrint();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case MSGRUN_WINDOW: {
|
case MSGRUN_WINDOW: {
|
||||||
fTermView->UpdateSIGWINCH ();
|
fTermView->UpdateSIGWINCH();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case B_ABOUT_REQUESTED: {
|
case B_ABOUT_REQUESTED: {
|
||||||
@@ -668,7 +640,7 @@ TermWindow::ResolveSpecifier(BMessage *msg, int32 index,
|
|||||||
|
|
||||||
|
|
||||||
status_t
|
status_t
|
||||||
TermWindow::DoPageSetup()
|
TermWindow::_DoPageSetup()
|
||||||
{
|
{
|
||||||
BPrintJob job("PageSetup");
|
BPrintJob job("PageSetup");
|
||||||
|
|
||||||
@@ -683,9 +655,9 @@ TermWindow::DoPageSetup()
|
|||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
TermWindow::DoPrint()
|
TermWindow::_DoPrint()
|
||||||
{
|
{
|
||||||
if (!fPrintSettings || (DoPageSetup() != B_NO_ERROR)) {
|
if (!fPrintSettings || (_DoPageSetup() != B_OK)) {
|
||||||
(new BAlert("Cancel", "Print cancelled.", "OK"))->Go();
|
(new BAlert("Cancel", "Print cancelled.", "OK"))->Go();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -39,8 +39,6 @@ class BMenuBar;
|
|||||||
class BMessageRunner;
|
class BMessageRunner;
|
||||||
class FindWindow;
|
class FindWindow;
|
||||||
class PrefWindow;
|
class PrefWindow;
|
||||||
class Shell;
|
|
||||||
class TermParse;
|
|
||||||
class TermView;
|
class TermView;
|
||||||
|
|
||||||
class TermWindow : public BWindow {
|
class TermWindow : public BWindow {
|
||||||
@@ -62,13 +60,11 @@ protected:
|
|||||||
const char *property);
|
const char *property);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void InitWindow();
|
void _InitWindow(const char *command);
|
||||||
void SetupMenu();
|
void _SetupMenu();
|
||||||
status_t DoPageSetup();
|
status_t _DoPageSetup();
|
||||||
void DoPrint();
|
void _DoPrint();
|
||||||
|
|
||||||
Shell *fShell;
|
|
||||||
TermParse *fTermParse;
|
|
||||||
BMenuBar *fMenubar;
|
BMenuBar *fMenubar;
|
||||||
BMenu *fFilemenu,
|
BMenu *fFilemenu,
|
||||||
*fEditmenu,
|
*fEditmenu,
|
||||||
|
|||||||
Reference in New Issue
Block a user