Added shortcuts to increase and decrease the font size. Since
these key combinations (ALT + +/-) can't be used on many keymaps, we might want to change. Moved view resizing to a private window method. Seems to work, more or less (ticket #1334) git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@23791 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
parent
5cc2ed98e2
commit
58cf7360ca
@ -406,6 +406,14 @@ TermView::SetEncoding(int encoding)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
TermView::GetTermFont(BFont *font) const
|
||||||
|
{
|
||||||
|
if (font != NULL)
|
||||||
|
*font = fHalfFont;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
//! Sets font for terminal
|
//! Sets font for terminal
|
||||||
void
|
void
|
||||||
TermView::SetTermFont(const BFont *font)
|
TermView::SetTermFont(const BFont *font)
|
||||||
|
@ -40,7 +40,9 @@ public:
|
|||||||
|
|
||||||
const char *TerminalName() const;
|
const char *TerminalName() const;
|
||||||
|
|
||||||
|
void GetTermFont(BFont *font) const;
|
||||||
void SetTermFont(const BFont *font);
|
void SetTermFont(const BFont *font);
|
||||||
|
|
||||||
void GetFontSize(int *width, int *height);
|
void GetFontSize(int *width, int *height);
|
||||||
BRect SetTermSize(int rows, int cols, bool resize);
|
BRect SetTermSize(int rows, int cols, bool resize);
|
||||||
|
|
||||||
|
@ -41,9 +41,13 @@
|
|||||||
|
|
||||||
|
|
||||||
const static float kViewOffset = 3;
|
const static float kViewOffset = 3;
|
||||||
|
const static int32 kMaxTabs = 6;
|
||||||
|
|
||||||
|
// messages constants
|
||||||
const static uint32 kNewTab = 'NTab';
|
const static uint32 kNewTab = 'NTab';
|
||||||
const static uint32 kCloseView = 'ClVw';
|
const static uint32 kCloseView = 'ClVw';
|
||||||
const static int32 kMaxTabs = 6;
|
const static uint32 kIncreaseFontSize = 'InFs';
|
||||||
|
const static uint32 kDecreaseFontSize = 'DcFs';
|
||||||
|
|
||||||
|
|
||||||
class CustomTermView : public TermView {
|
class CustomTermView : public TermView {
|
||||||
@ -100,6 +104,9 @@ TermWindow::_InitWindow()
|
|||||||
// make menu bar
|
// make menu bar
|
||||||
_SetupMenu();
|
_SetupMenu();
|
||||||
|
|
||||||
|
AddShortcut('+', B_COMMAND_KEY, new BMessage(kIncreaseFontSize));
|
||||||
|
AddShortcut('-', B_COMMAND_KEY, new BMessage(kDecreaseFontSize));
|
||||||
|
|
||||||
BRect textFrame = Bounds();
|
BRect textFrame = Bounds();
|
||||||
textFrame.top = fMenubar->Bounds().bottom + 1.0;
|
textFrame.top = fMenubar->Bounds().bottom + 1.0;
|
||||||
|
|
||||||
@ -220,6 +227,10 @@ TermWindow::MessageReceived(BMessage *message)
|
|||||||
_ActiveTermView()->SelectAll();
|
_ActiveTermView()->SelectAll();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case B_ABOUT_REQUESTED:
|
||||||
|
be_app->PostMessage(B_ABOUT_REQUESTED);
|
||||||
|
break;
|
||||||
|
|
||||||
case MENU_CLEAR_ALL:
|
case MENU_CLEAR_ALL:
|
||||||
_ActiveTermView()->Clear();
|
_ActiveTermView()->Clear();
|
||||||
break;
|
break;
|
||||||
@ -228,22 +239,6 @@ TermWindow::MessageReceived(BMessage *message)
|
|||||||
be_app->PostMessage(MENU_SWITCH_TERM);
|
be_app->PostMessage(MENU_SWITCH_TERM);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case kNewTab:
|
|
||||||
if (fTabView->CountTabs() < kMaxTabs)
|
|
||||||
_AddTab(NULL);
|
|
||||||
break;
|
|
||||||
|
|
||||||
case kCloseView:
|
|
||||||
{
|
|
||||||
TermView* termView;
|
|
||||||
if (message->FindPointer("termView", (void**)&termView) == B_OK) {
|
|
||||||
int32 index = _IndexOfTermView(termView);
|
|
||||||
if (index >= 0)
|
|
||||||
_RemoveTab(index);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
case MENU_NEW_TERM:
|
case MENU_NEW_TERM:
|
||||||
{
|
{
|
||||||
app_info info;
|
app_info info;
|
||||||
@ -364,27 +359,9 @@ TermWindow::MessageReceived(BMessage *message)
|
|||||||
BFont font;
|
BFont font;
|
||||||
_GetPreferredFont(font);
|
_GetPreferredFont(font);
|
||||||
_ActiveTermView()->SetTermFont(&font);
|
_ActiveTermView()->SetTermFont(&font);
|
||||||
|
|
||||||
int fontWidth, fontHeight;
|
|
||||||
_ActiveTermView()->GetFontSize(&fontWidth, &fontHeight);
|
|
||||||
|
|
||||||
float minimumHeight = 0;
|
_ResizeView(_ActiveTermView());
|
||||||
if (fMenubar)
|
|
||||||
minimumHeight += fMenubar->Bounds().Height();
|
|
||||||
if (fTabView && fTabView->CountTabs() > 1)
|
|
||||||
minimumHeight += fTabView->TabHeight();
|
|
||||||
|
|
||||||
SetSizeLimits(MIN_COLS * fontWidth, MAX_COLS * fontWidth,
|
|
||||||
minimumHeight + MIN_ROWS * fontHeight,
|
|
||||||
minimumHeight + MAX_ROWS * fontHeight);
|
|
||||||
|
|
||||||
float width, height;
|
|
||||||
_ActiveTermView()->GetPreferredSize(&width, &height);
|
|
||||||
width += B_V_SCROLL_BAR_WIDTH + kViewOffset * 2;
|
|
||||||
height += fMenubar->Bounds().Height() + kViewOffset * 2;
|
|
||||||
ResizeTo(width, height);
|
|
||||||
|
|
||||||
_ActiveTermView()->Invalidate();
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case EIGHTYTWENTYFOUR:
|
case EIGHTYTWENTYFOUR:
|
||||||
@ -472,10 +449,49 @@ TermWindow::MessageReceived(BMessage *message)
|
|||||||
_CheckChildren();
|
_CheckChildren();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case B_ABOUT_REQUESTED:
|
case kNewTab:
|
||||||
be_app->PostMessage(B_ABOUT_REQUESTED);
|
if (fTabView->CountTabs() < kMaxTabs)
|
||||||
|
_AddTab(NULL);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case kCloseView:
|
||||||
|
{
|
||||||
|
TermView* termView;
|
||||||
|
if (message->FindPointer("termView", (void**)&termView) == B_OK) {
|
||||||
|
int32 index = _IndexOfTermView(termView);
|
||||||
|
if (index >= 0)
|
||||||
|
_RemoveTab(index);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
case kIncreaseFontSize:
|
||||||
|
case kDecreaseFontSize:
|
||||||
|
{
|
||||||
|
message->PrintToStream();
|
||||||
|
TermView *view = _ActiveTermView();
|
||||||
|
BFont font;
|
||||||
|
view->GetTermFont(&font);
|
||||||
|
|
||||||
|
float size = font.Size();
|
||||||
|
if (message->what == kIncreaseFontSize)
|
||||||
|
size += 1;
|
||||||
|
else
|
||||||
|
size -= 1;
|
||||||
|
|
||||||
|
// limit the font size
|
||||||
|
if (size < 8)
|
||||||
|
size = 8;
|
||||||
|
else if (size > 20)
|
||||||
|
size = 20;
|
||||||
|
|
||||||
|
font.SetSize(size);
|
||||||
|
view->SetTermFont(&font);
|
||||||
|
|
||||||
|
_ResizeView(view);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
default:
|
default:
|
||||||
BWindow::MessageReceived(message);
|
BWindow::MessageReceived(message);
|
||||||
break;
|
break;
|
||||||
@ -686,6 +702,32 @@ TermWindow::_IndexOfTermView(TermView* termView) const
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
TermWindow::_ResizeView(TermView *view)
|
||||||
|
{
|
||||||
|
int fontWidth, fontHeight;
|
||||||
|
view->GetFontSize(&fontWidth, &fontHeight);
|
||||||
|
|
||||||
|
float minimumHeight = 0;
|
||||||
|
if (fMenubar)
|
||||||
|
minimumHeight += fMenubar->Bounds().Height();
|
||||||
|
if (fTabView && fTabView->CountTabs() > 1)
|
||||||
|
minimumHeight += fTabView->TabHeight();
|
||||||
|
|
||||||
|
SetSizeLimits(MIN_COLS * fontWidth, MAX_COLS * fontWidth,
|
||||||
|
minimumHeight + MIN_ROWS * fontHeight,
|
||||||
|
minimumHeight + MAX_ROWS * fontHeight);
|
||||||
|
|
||||||
|
float width, height;
|
||||||
|
view->GetPreferredSize(&width, &height);
|
||||||
|
width += B_V_SCROLL_BAR_WIDTH + kViewOffset * 2;
|
||||||
|
height += fMenubar->Bounds().Height() + kViewOffset * 2;
|
||||||
|
ResizeTo(width, height);
|
||||||
|
|
||||||
|
view->Invalidate();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
TermWindow::_CheckChildren()
|
TermWindow::_CheckChildren()
|
||||||
{
|
{
|
||||||
|
@ -69,6 +69,7 @@ private:
|
|||||||
TermView* _ActiveTermView();
|
TermView* _ActiveTermView();
|
||||||
int32 _IndexOfTermView(TermView* termView) const;
|
int32 _IndexOfTermView(TermView* termView) const;
|
||||||
void _CheckChildren();
|
void _CheckChildren();
|
||||||
|
void _ResizeView(TermView *view);
|
||||||
|
|
||||||
SmartTabView *fTabView;
|
SmartTabView *fTabView;
|
||||||
TermView *fTermView;
|
TermView *fTermView;
|
||||||
|
Loading…
Reference in New Issue
Block a user