Add font sizes to Font Size menu in addition to in settings
This commit is contained in:
@@ -94,11 +94,11 @@ AppearancePrefView::AppearancePrefView(const char* name,
|
|||||||
PrefHandler::Default()->getString(PREF_HALF_FONT_FAMILY),
|
PrefHandler::Default()->getString(PREF_HALF_FONT_FAMILY),
|
||||||
PrefHandler::Default()->getString(PREF_HALF_FONT_STYLE));
|
PrefHandler::Default()->getString(PREF_HALF_FONT_STYLE));
|
||||||
|
|
||||||
BMenu* sizeMenu = _MakeSizeMenu(MSG_HALF_SIZE_CHANGED,
|
BMenu* fontSizeMenu = _MakeFontSizeMenu(MSG_HALF_SIZE_CHANGED,
|
||||||
PrefHandler::Default()->getInt32(PREF_HALF_FONT_SIZE));
|
PrefHandler::Default()->getInt32(PREF_HALF_FONT_SIZE));
|
||||||
|
|
||||||
fFont = new BMenuField(B_TRANSLATE("Font:"), fontMenu);
|
fFont = new BMenuField(B_TRANSLATE("Font:"), fontMenu);
|
||||||
fFontSize = new BMenuField(B_TRANSLATE("Size:"), sizeMenu);
|
fFontSize = new BMenuField(B_TRANSLATE("Font size:"), fontSizeMenu);
|
||||||
|
|
||||||
BPopUpMenu* schemesPopUp = _MakeColorSchemeMenu(MSG_COLOR_SCHEME_CHANGED,
|
BPopUpMenu* schemesPopUp = _MakeColorSchemeMenu(MSG_COLOR_SCHEME_CHANGED,
|
||||||
gPredefinedColorSchemes, gPredefinedColorSchemes[0]);
|
gPredefinedColorSchemes, gPredefinedColorSchemes[0]);
|
||||||
@@ -456,7 +456,7 @@ AppearancePrefView::_MakeFontMenu(uint32 command,
|
|||||||
|
|
||||||
|
|
||||||
/*static*/ BMenu*
|
/*static*/ BMenu*
|
||||||
AppearancePrefView::_MakeSizeMenu(uint32 command, uint8 defaultSize)
|
AppearancePrefView::_MakeFontSizeMenu(uint32 command, uint8 defaultSize)
|
||||||
{
|
{
|
||||||
BPopUpMenu* menu = new BPopUpMenu("size");
|
BPopUpMenu* menu = new BPopUpMenu("size");
|
||||||
int32 sizes[] = {9, 10, 11, 12, 14, 16, 18, 0};
|
int32 sizes[] = {9, 10, 11, 12, 14, 16, 18, 0};
|
||||||
@@ -467,7 +467,8 @@ AppearancePrefView::_MakeSizeMenu(uint32 command, uint8 defaultSize)
|
|||||||
BString string;
|
BString string;
|
||||||
string << sizes[i];
|
string << sizes[i];
|
||||||
|
|
||||||
BMenuItem* item = new BMenuItem(string.String(), new BMessage(command));
|
BMenuItem* item = new BMenuItem(string.String(),
|
||||||
|
new BMessage(command));
|
||||||
menu->AddItem(item);
|
menu->AddItem(item);
|
||||||
|
|
||||||
if (sizes[i] == defaultSize) {
|
if (sizes[i] == defaultSize) {
|
||||||
@@ -475,6 +476,7 @@ AppearancePrefView::_MakeSizeMenu(uint32 command, uint8 defaultSize)
|
|||||||
found = true;
|
found = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!found) {
|
if (!found) {
|
||||||
for (uint32 i = 0; sizes[i]; i++) {
|
for (uint32 i = 0; sizes[i]; i++) {
|
||||||
if (sizes[i] > defaultSize) {
|
if (sizes[i] > defaultSize) {
|
||||||
|
|||||||
@@ -62,7 +62,7 @@ private:
|
|||||||
static BMenu* _MakeFontMenu(uint32 command,
|
static BMenu* _MakeFontMenu(uint32 command,
|
||||||
const char* defaultFamily,
|
const char* defaultFamily,
|
||||||
const char* defaultStyle);
|
const char* defaultStyle);
|
||||||
static BMenu* _MakeSizeMenu(uint32 command,
|
static BMenu* _MakeFontSizeMenu(uint32 command,
|
||||||
uint8 defaultSize);
|
uint8 defaultSize);
|
||||||
|
|
||||||
static BPopUpMenu* _MakeMenu(uint32 msg, const char** items,
|
static BPopUpMenu* _MakeMenu(uint32 msg, const char** items,
|
||||||
|
|||||||
@@ -945,8 +945,8 @@ TermView::SetTermFont(const BFont *font)
|
|||||||
fHalfFont.SetSpacing(B_FIXED_SPACING);
|
fHalfFont.SetSpacing(B_FIXED_SPACING);
|
||||||
|
|
||||||
// calculate half font's max width
|
// calculate half font's max width
|
||||||
// Not Bounding, check only A-Z(For case of fHalfFont is KanjiFont. )
|
// Not Bounding, check only A-Z (For case of fHalfFont is KanjiFont.)
|
||||||
for (int c = 0x20 ; c <= 0x7e; c++){
|
for (int c = 0x20; c <= 0x7e; c++) {
|
||||||
char buf[4];
|
char buf[4];
|
||||||
sprintf(buf, "%c", c);
|
sprintf(buf, "%c", c);
|
||||||
int tmpWidth = (int)fHalfFont.StringWidth(buf);
|
int tmpWidth = (int)fHalfFont.StringWidth(buf);
|
||||||
|
|||||||
@@ -11,6 +11,7 @@
|
|||||||
|
|
||||||
#include <new>
|
#include <new>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
|
|
||||||
@@ -449,6 +450,16 @@ TermWindow::_MakeEncodingMenu()
|
|||||||
void
|
void
|
||||||
TermWindow::_SetupMenu()
|
TermWindow::_SetupMenu()
|
||||||
{
|
{
|
||||||
|
fFontSizeMenu = _MakeFontSizeMenu(MSG_HALF_SIZE_CHANGED,
|
||||||
|
PrefHandler::Default()->getInt32(PREF_HALF_FONT_SIZE));
|
||||||
|
fIncreaseFontSizeMenuItem = new BMenuItem(B_TRANSLATE("Increase"),
|
||||||
|
new BMessage(kIncreaseFontSize), '+', B_COMMAND_KEY);
|
||||||
|
fDecreaseFontSizeMenuItem = new BMenuItem(B_TRANSLATE("Decrease"),
|
||||||
|
new BMessage(kDecreaseFontSize), '-', B_COMMAND_KEY);
|
||||||
|
fFontSizeMenu->AddSeparatorItem();
|
||||||
|
fFontSizeMenu->AddItem(fIncreaseFontSizeMenuItem);
|
||||||
|
fFontSizeMenu->AddItem(fDecreaseFontSizeMenuItem);
|
||||||
|
|
||||||
BLayoutBuilder::Menu<>(fMenuBar = new BMenuBar(Bounds(), "mbar"))
|
BLayoutBuilder::Menu<>(fMenuBar = new BMenuBar(Bounds(), "mbar"))
|
||||||
// Terminal
|
// Terminal
|
||||||
.AddMenu(B_TRANSLATE_SYSTEM_NAME("Terminal"))
|
.AddMenu(B_TRANSLATE_SYSTEM_NAME("Terminal"))
|
||||||
@@ -491,14 +502,7 @@ TermWindow::_SetupMenu()
|
|||||||
.AddMenu(B_TRANSLATE("Settings"))
|
.AddMenu(B_TRANSLATE("Settings"))
|
||||||
.AddItem(_MakeWindowSizeMenu())
|
.AddItem(_MakeWindowSizeMenu())
|
||||||
.AddItem(fEncodingMenu = _MakeEncodingMenu())
|
.AddItem(fEncodingMenu = _MakeEncodingMenu())
|
||||||
.AddMenu(B_TRANSLATE("Text size"))
|
.AddItem(fFontSizeMenu)
|
||||||
.AddItem(B_TRANSLATE("Increase"), kIncreaseFontSize, '+',
|
|
||||||
B_COMMAND_KEY)
|
|
||||||
.GetItem(fIncreaseFontSizeMenuItem)
|
|
||||||
.AddItem(B_TRANSLATE("Decrease"), kDecreaseFontSize, '-',
|
|
||||||
B_COMMAND_KEY)
|
|
||||||
.GetItem(fDecreaseFontSizeMenuItem)
|
|
||||||
.End()
|
|
||||||
.AddSeparator()
|
.AddSeparator()
|
||||||
.AddItem(B_TRANSLATE("Settings" B_UTF8_ELLIPSIS), MENU_PREF_OPEN)
|
.AddItem(B_TRANSLATE("Settings" B_UTF8_ELLIPSIS), MENU_PREF_OPEN)
|
||||||
.AddSeparator()
|
.AddSeparator()
|
||||||
@@ -779,10 +783,9 @@ TermWindow::MessageReceived(BMessage *message)
|
|||||||
_ResizeView(_ActiveTermView());
|
_ResizeView(_ActiveTermView());
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
case MSG_HALF_FONT_CHANGED:
|
case MSG_HALF_FONT_CHANGED:
|
||||||
case MSG_FULL_FONT_CHANGED:
|
case MSG_FULL_FONT_CHANGED:
|
||||||
case MSG_HALF_SIZE_CHANGED:
|
|
||||||
case MSG_FULL_SIZE_CHANGED:
|
|
||||||
{
|
{
|
||||||
BFont font;
|
BFont font;
|
||||||
_GetPreferredFont(font);
|
_GetPreferredFont(font);
|
||||||
@@ -792,6 +795,36 @@ TermWindow::MessageReceived(BMessage *message)
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
case MSG_HALF_SIZE_CHANGED:
|
||||||
|
case MSG_FULL_SIZE_CHANGED:
|
||||||
|
{
|
||||||
|
TermView* view = _ActiveTermView();
|
||||||
|
BFont font;
|
||||||
|
view->GetTermFont(&font);
|
||||||
|
|
||||||
|
int32 size;
|
||||||
|
if (message->FindInt32("font size", &size) != B_OK)
|
||||||
|
break;
|
||||||
|
|
||||||
|
// mark the font size menu item
|
||||||
|
for (int32 i = 0; i < fFontSizeMenu->CountItems(); i++) {
|
||||||
|
BMenuItem* item = fFontSizeMenu->ItemAt(i);
|
||||||
|
if (item == NULL)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
item->SetMarked(false);
|
||||||
|
if (atoi(item->Label()) == size)
|
||||||
|
item->SetMarked(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
font.SetSize(size);
|
||||||
|
view->SetTermFont(&font);
|
||||||
|
PrefHandler::Default()->setInt32(PREF_HALF_FONT_SIZE, (int32)size);
|
||||||
|
|
||||||
|
_ResizeView(view);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
case FULLSCREEN:
|
case FULLSCREEN:
|
||||||
if (!fSavedFrame.IsValid()) { // go fullscreen
|
if (!fSavedFrame.IsValid()) { // go fullscreen
|
||||||
_ActiveTermView()->DisableResizeView();
|
_ActiveTermView()->DisableResizeView();
|
||||||
@@ -960,19 +993,30 @@ TermWindow::MessageReceived(BMessage *message)
|
|||||||
TermView* view = _ActiveTermView();
|
TermView* view = _ActiveTermView();
|
||||||
BFont font;
|
BFont font;
|
||||||
view->GetTermFont(&font);
|
view->GetTermFont(&font);
|
||||||
|
|
||||||
float size = font.Size();
|
float size = font.Size();
|
||||||
if (message->what == kIncreaseFontSize)
|
|
||||||
size += 1;
|
|
||||||
else
|
|
||||||
size -= 1;
|
|
||||||
|
|
||||||
// limit the font size
|
if (message->what == kIncreaseFontSize)
|
||||||
|
size < 12 ? size += 1 : size += 2;
|
||||||
|
else
|
||||||
|
size < 14 ? size -= 1 : size -= 2;
|
||||||
|
|
||||||
|
// constrain the font size
|
||||||
if (size < 9)
|
if (size < 9)
|
||||||
size = 9;
|
size = 9;
|
||||||
if (size > 18)
|
if (size > 18)
|
||||||
size = 18;
|
size = 18;
|
||||||
|
|
||||||
|
// mark the font size menu item
|
||||||
|
for (int32 i = 0; i < fFontSizeMenu->CountItems(); i++) {
|
||||||
|
BMenuItem* item = fFontSizeMenu->ItemAt(i);
|
||||||
|
if (item == NULL)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
item->SetMarked(false);
|
||||||
|
if (atoi(item->Label()) == size)
|
||||||
|
item->SetMarked(true);
|
||||||
|
}
|
||||||
|
|
||||||
font.SetSize(size);
|
font.SetSize(size);
|
||||||
view->SetTermFont(&font);
|
view->SetTermFont(&font);
|
||||||
PrefHandler::Default()->setInt32(PREF_HALF_FONT_SIZE, (int32)size);
|
PrefHandler::Default()->setInt32(PREF_HALF_FONT_SIZE, (int32)size);
|
||||||
@@ -1546,8 +1590,7 @@ TermWindow::_ResizeView(TermView *view)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* static */
|
/* static */ BMenu*
|
||||||
BMenu*
|
|
||||||
TermWindow::_MakeWindowSizeMenu()
|
TermWindow::_MakeWindowSizeMenu()
|
||||||
{
|
{
|
||||||
BMenu* menu = new (std::nothrow) BMenu(B_TRANSLATE("Window size"));
|
BMenu* menu = new (std::nothrow) BMenu(B_TRANSLATE("Window size"));
|
||||||
@@ -1581,6 +1624,49 @@ TermWindow::_MakeWindowSizeMenu()
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*static*/ BMenu*
|
||||||
|
TermWindow::_MakeFontSizeMenu(uint32 command, uint8 defaultSize)
|
||||||
|
{
|
||||||
|
BMenu* menu = new (std::nothrow) BMenu(B_TRANSLATE("Font size"));
|
||||||
|
if (menu == NULL)
|
||||||
|
return NULL;
|
||||||
|
|
||||||
|
int32 sizes[] = {9, 10, 11, 12, 14, 16, 18, 0};
|
||||||
|
|
||||||
|
bool found = false;
|
||||||
|
|
||||||
|
for (uint32 i = 0; sizes[i]; i++) {
|
||||||
|
BString string;
|
||||||
|
string << sizes[i];
|
||||||
|
BMessage* message = new BMessage(command);
|
||||||
|
message->AddInt32("font size", sizes[i]);
|
||||||
|
BMenuItem* item = new BMenuItem(string.String(), message);
|
||||||
|
menu->AddItem(item);
|
||||||
|
if (sizes[i] == defaultSize) {
|
||||||
|
item->SetMarked(true);
|
||||||
|
found = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!found) {
|
||||||
|
for (uint32 i = 0; sizes[i]; i++) {
|
||||||
|
if (sizes[i] > defaultSize) {
|
||||||
|
BString string;
|
||||||
|
string << defaultSize;
|
||||||
|
BMessage* message = new BMessage(command);
|
||||||
|
message->AddInt32("font size", sizes[i]);
|
||||||
|
BMenuItem* item = new BMenuItem(string.String(), message);
|
||||||
|
item->SetMarked(true);
|
||||||
|
menu->AddItem(item, i);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return menu;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
TermWindow::_UpdateSwitchTerminalsMenuItem()
|
TermWindow::_UpdateSwitchTerminalsMenuItem()
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -136,6 +136,8 @@ private:
|
|||||||
void _SetupMenu();
|
void _SetupMenu();
|
||||||
static BMenu* _MakeEncodingMenu();
|
static BMenu* _MakeEncodingMenu();
|
||||||
static BMenu* _MakeWindowSizeMenu();
|
static BMenu* _MakeWindowSizeMenu();
|
||||||
|
static BMenu* _MakeFontSizeMenu(uint32 command,
|
||||||
|
uint8 defaultSize);
|
||||||
void _UpdateSwitchTerminalsMenuItem();
|
void _UpdateSwitchTerminalsMenuItem();
|
||||||
|
|
||||||
status_t _GetWindowPositionFile(BFile* file,
|
status_t _GetWindowPositionFile(BFile* file,
|
||||||
@@ -198,6 +200,7 @@ private:
|
|||||||
BMenuBar* fMenuBar;
|
BMenuBar* fMenuBar;
|
||||||
BMenuItem* fSwitchTerminalsMenuItem;
|
BMenuItem* fSwitchTerminalsMenuItem;
|
||||||
BMenu* fEncodingMenu;
|
BMenu* fEncodingMenu;
|
||||||
|
BMenu* fFontSizeMenu;
|
||||||
|
|
||||||
BMessage* fPrintSettings;
|
BMessage* fPrintSettings;
|
||||||
PrefWindow* fPrefWindow;
|
PrefWindow* fPrefWindow;
|
||||||
@@ -212,7 +215,7 @@ private:
|
|||||||
// Saved search parameters
|
// Saved search parameters
|
||||||
BString fFindString;
|
BString fFindString;
|
||||||
BMenuItem* fFindNextMenuItem;
|
BMenuItem* fFindNextMenuItem;
|
||||||
BMenuItem * fFindPreviousMenuItem;
|
BMenuItem* fFindPreviousMenuItem;
|
||||||
BMenuItem* fIncreaseFontSizeMenuItem;
|
BMenuItem* fIncreaseFontSizeMenuItem;
|
||||||
BMenuItem* fDecreaseFontSizeMenuItem;
|
BMenuItem* fDecreaseFontSizeMenuItem;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user