Use a try { } catch block in TermWindow::_AddTab(). Note that this

doesn't fix bug #1392, since TermView::_InitObject() use std::nothrow 
for allocations. Added TermWindow::_GetPreferredFonts() and moved some 
code in there.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@21984 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Stefano Ceccherini
2007-08-16 15:32:09 +00:00
parent a2e2784cf3
commit e7f9f277ef
2 changed files with 76 additions and 66 deletions
+66 -57
View File
@@ -199,6 +199,28 @@ TermWindow::_SetupMenu()
} }
void
TermWindow::_GetPreferredFonts(BFont &fullFont, BFont &halfFont)
{
const char *family = PrefHandler::Default()->getString(PREF_HALF_FONT_FAMILY);
halfFont.SetFamilyAndStyle(family, NULL);
float size = PrefHandler::Default()->getFloat(PREF_HALF_FONT_SIZE);
if (size < 6.0f)
size = 6.0f;
halfFont.SetSize(size);
family = PrefHandler::Default()->getString(PREF_FULL_FONT_FAMILY);
fullFont.SetFamilyAndStyle(family, NULL);
size = PrefHandler::Default()->getFloat(PREF_FULL_FONT_SIZE);
if (size < 6.0f)
size = 6.0f;
fullFont.SetSize(size);
fullFont.SetSpacing(B_FIXED_SPACING);
}
void void
TermWindow::MessageReceived(BMessage *message) TermWindow::MessageReceived(BMessage *message)
{ {
@@ -565,79 +587,66 @@ TermWindow::_DoPrint()
void void
TermWindow::_AddTab(Arguments *args) TermWindow::_AddTab(Arguments *args)
{ {
// Setup font.
const char *family = PrefHandler::Default()->getString(PREF_HALF_FONT_FAMILY);
BFont halfFont;
halfFont.SetFamilyAndStyle(family, NULL);
float size = PrefHandler::Default()->getFloat(PREF_HALF_FONT_SIZE);
if (size < 6.0f)
size = 6.0f;
halfFont.SetSize(size);
family = PrefHandler::Default()->getString(PREF_FULL_FONT_FAMILY);
BFont fullFont;
fullFont.SetFamilyAndStyle(family, NULL);
size = PrefHandler::Default()->getFloat(PREF_FULL_FONT_SIZE);
if (size < 6.0f)
size = 6.0f;
fullFont.SetSize(size);
fullFont.SetSpacing(B_FIXED_SPACING);
// Make Terminal text view.
int argc = 0; int argc = 0;
const char *const *argv = NULL; const char *const *argv = NULL;
if (args != NULL) if (args != NULL)
args->GetShellArguments(argc, argv); args->GetShellArguments(argc, argv);
// Note: I don't pass the Arguments class directly to the termview, try {
// only to avoid adding it as a dependency: in other words, to keep // Note: I don't pass the Arguments class directly to the termview,
// the TermView class as agnostic as possible about the surrounding world. // only to avoid adding it as a dependency: in other words, to keep
CustomTermView *view = new CustomTermView(PrefHandler::Default()->getInt32(PREF_ROWS), // the TermView class as agnostic as possible about the surrounding world.
PrefHandler::Default()->getInt32(PREF_COLS), CustomTermView *view =
argc, (const char **)argv); new CustomTermView(PrefHandler::Default()->getInt32(PREF_ROWS),
PrefHandler::Default()->getInt32(PREF_COLS),
argc, (const char **)argv);
BScrollView *scrollView = new BScrollView("scrollView", view, B_FOLLOW_ALL, BScrollView *scrollView = new BScrollView("scrollView", view, B_FOLLOW_ALL,
B_WILL_DRAW|B_FRAME_EVENTS, false, true); B_WILL_DRAW|B_FRAME_EVENTS, false, true);
BTab *tab = new BTab; BTab *tab = new BTab;
// TODO: Use a better name. For example, do like MacOsX's Terminal // TODO: Use a better name. For example, do like MacOsX's Terminal
// and update the title using the last executed command ? // and update the title using the last executed command ?
// Or like Gnome's Terminal and use the current path ? // Or like Gnome's Terminal and use the current path ?
fTabView->AddTab(scrollView, tab); fTabView->AddTab(scrollView, tab);
tab->SetLabel("Terminal"); tab->SetLabel("Terminal");
view->SetScrollBar(scrollView->ScrollBar(B_VERTICAL)); view->SetScrollBar(scrollView->ScrollBar(B_VERTICAL));
// TODO: Resize the vertical scrollbar to take the window gripping handle into account // Resize the vertical scrollbar to take the window gripping handle into account
// (shouldn't this be done in BScrollView itself ? At least BScrollBar does that). // TODO: shouldn't this be done in BScrollView itself ? At least BScrollBar does that.
scrollView->ScrollBar(B_VERTICAL)->ResizeBy(0, -13); scrollView->ScrollBar(B_VERTICAL)->ResizeBy(0, -13);
view->SetEncoding(longname2id(PrefHandler::Default()->getString(PREF_TEXT_ENCODING)));
view->SetTermFont(&halfFont, &fullFont);
_SetTermColors(view); view->SetEncoding(longname2id(PrefHandler::Default()->getString(PREF_TEXT_ENCODING)));
// If it's the first time we're called, setup the window BFont fullFont, halfFont;
if (fTabView->CountTabs() == 1) { _GetPreferredFonts(fullFont, halfFont);
int width, height; view->SetTermFont(&halfFont, &fullFont);
view->GetFontSize(&width, &height);
SetSizeLimits(MIN_COLS * width, MAX_COLS * width,
MIN_COLS * height, MAX_COLS * height);
float fWidth, fHeight; _SetTermColors(view);
view->GetPreferredSize(&fWidth, &fHeight);
// Resize Window // If it's the first time we're called, setup the window
ResizeTo(fWidth + B_V_SCROLL_BAR_WIDTH, fHeight + fMenubar->Bounds().Height()); if (fTabView->CountTabs() == 1) {
int width, height;
view->GetFontSize(&width, &height);
SetSizeLimits(MIN_COLS * width, MAX_COLS * width,
MIN_COLS * height, MAX_COLS * height);
// TODO: If I don't do this, the view won't show up. float fWidth, fHeight;
// Bug in BTabView or in my code ? view->GetPreferredSize(&fWidth, &fHeight);
fTabView->Select(0);
// Resize Window
ResizeTo(fWidth + B_V_SCROLL_BAR_WIDTH, fHeight + fMenubar->Bounds().Height());
// TODO: If I don't do this, the view won't show up.
// Bug in BTabView or in my code ?
fTabView->Select(0);
}
} catch (...) {
// most probably out of memory. That's bad.
// TODO: Should cleanup, I guess
} }
} }
void void
TermWindow::_RemoveTab(int32 index) TermWindow::_RemoveTab(int32 index)
{ {
+1
View File
@@ -58,6 +58,7 @@ private:
void _SetTermColors(TermView *termView); void _SetTermColors(TermView *termView);
void _InitWindow(); void _InitWindow();
void _SetupMenu(); void _SetupMenu();
void _GetPreferredFonts(BFont &full, BFont &half);
status_t _DoPageSetup(); status_t _DoPageSetup();
void _DoPrint(); void _DoPrint();
void _AddTab(Arguments *args); void _AddTab(Arguments *args);