diff --git a/src/preferences/appearance/FontSelectionView.cpp b/src/preferences/appearance/FontSelectionView.cpp index 8b7ce5a025..f9f6242b30 100644 --- a/src/preferences/appearance/FontSelectionView.cpp +++ b/src/preferences/appearance/FontSelectionView.cpp @@ -23,6 +23,7 @@ #include #include #include +#include #include @@ -38,7 +39,12 @@ // only on exit static const float kMinSize = 8.0; -static const float kMaxSize = 24.0; +static const float kMaxSize = 72.0; + +static const char *kPreviewText = B_TRANSLATE_COMMENT( + "The quick brown fox jumps over the lazy dog.", + "Don't translate this literally ! Use a phrase showing all chars " + "from A to Z."); // private font API @@ -98,36 +104,38 @@ FontSelectionView::FontSelectionView(const char* name, fSavedFont = fCurrentFont; - fSizesMenu = new BPopUpMenu("size menu"); - _BuildSizesMenu(); - fFontsMenu = new BPopUpMenu("font menu"); // font menu fFontsMenuField = new BMenuField("fonts", label, fFontsMenu); fFontsMenuField->SetAlignment(B_ALIGN_RIGHT); - // size menu - fSizesMenuField = new BMenuField("size", B_TRANSLATE("Size:"), fSizesMenu); - fSizesMenuField->SetAlignment(B_ALIGN_RIGHT); + // font size + BMessage* fontSizeMessage = new BMessage(kMsgSetSize); + fontSizeMessage->AddString("name", Name()); + + fFontSizeSpinner = new BSpinner("font size", B_TRANSLATE("Size:"), + fontSizeMessage); + + fFontSizeSpinner->SetRange(kMinSize, kMaxSize); + fFontSizeSpinner->SetExplicitMaxSize(BSize(B_SIZE_UNLIMITED, B_SIZE_UNSET)); // preview - fPreviewText = new BStringView("preview text", - B_TRANSLATE_COMMENT("The quick brown fox jumps over the lazy dog.", - "Don't translate this literally ! Use a phrase showing all chars " - "from A to Z.")); + fPreviewTextView = new BStringView("preview text", kPreviewText); - fPreviewText->SetFont(&fCurrentFont); - fPreviewText->SetExplicitMaxSize(BSize(B_SIZE_UNLIMITED, B_SIZE_UNSET)); + fPreviewTextView->SetFont(&fCurrentFont); + fPreviewTextView->SetExplicitMaxSize(BSize(B_SIZE_UNLIMITED, B_SIZE_UNSET)); // box around preview fPreviewBox = new BBox("preview box", B_WILL_DRAW | B_FRAME_EVENTS); fPreviewBox->AddChild(BGroupLayoutBuilder(B_HORIZONTAL) - .Add(fPreviewText) + .Add(fPreviewTextView) .SetInsets(B_USE_SMALL_SPACING, B_USE_SMALL_SPACING, B_USE_SMALL_SPACING, B_USE_SMALL_SPACING) .TopView() ); + + _SelectCurrentSize(); } @@ -143,26 +151,18 @@ void FontSelectionView::SetTarget(BHandler* messageTarget) { fMessageTarget = messageTarget; - fSizesMenu->SetTargetForItems(fMessageTarget); -} - - -BView* -FontSelectionView::GetPreviewBox() -{ - return fPreviewBox; + fFontSizeSpinner->SetTarget(messageTarget); } void -FontSelectionView::MessageReceived(BMessage *msg) +FontSelectionView::MessageReceived(BMessage* msg) { switch (msg->what) { case kMsgSetSize: { - int32 size; - if (msg->FindInt32("size", &size) != B_OK - || size == fCurrentFont.Size()) + int32 size = fFontSizeSpinner->Value(); + if (size == fCurrentFont.Size()) break; fCurrentFont.SetSize(size); @@ -179,11 +179,11 @@ FontSelectionView::MessageReceived(BMessage *msg) font_style style; fCurrentFont.GetFamilyAndStyle(NULL, &style); - BMenuItem *familyItem = fFontsMenu->FindItem(family); + BMenuItem* familyItem = fFontsMenu->FindItem(family); if (familyItem != NULL) { _SelectCurrentFont(false); - BMenuItem *item = familyItem->Submenu()->FindItem(style); + BMenuItem* item = familyItem->Submenu()->FindItem(style); if (item == NULL) item = familyItem->Submenu()->ItemAt(0); @@ -221,63 +221,34 @@ FontSelectionView::MessageReceived(BMessage *msg) } } - -BLayoutItem* -FontSelectionView::CreateSizesLabelLayoutItem() +BView* +FontSelectionView::GetPreviewBox() const { - return fSizesMenuField->CreateLabelLayoutItem(); + return fPreviewBox; +} + + +BView* +FontSelectionView::GetFontSizeSpinner() const +{ + return fFontSizeSpinner; } BLayoutItem* -FontSelectionView::CreateSizesMenuBarLayoutItem() -{ - return fSizesMenuField->CreateMenuBarLayoutItem(); -} - - -BLayoutItem* -FontSelectionView::CreateFontsLabelLayoutItem() +FontSelectionView::CreateFontsLabelLayoutItem() const { return fFontsMenuField->CreateLabelLayoutItem(); } BLayoutItem* -FontSelectionView::CreateFontsMenuBarLayoutItem() +FontSelectionView::CreateFontsMenuBarLayoutItem() const { return fFontsMenuField->CreateMenuBarLayoutItem(); } -void -FontSelectionView::_BuildSizesMenu() -{ - const int32 sizes[] = {7, 8, 9, 10, 11, 12, 13, 14, 16, 18, 19, 20, - 21, 24, 0}; - - // build size menu - for (int32 i = 0; sizes[i]; i++) { - int32 size = sizes[i]; - if (size < kMinSize || size > kMaxSize) - continue; - - char label[32]; - snprintf(label, sizeof(label), "%" B_PRId32, size); - - BMessage* message = new BMessage(kMsgSetSize); - message->AddInt32("size", size); - message->AddString("name", Name()); - - BMenuItem* item = new BMenuItem(label, message); - if (size == fCurrentFont.Size()) - item->SetMarked(true); - - fSizesMenu->AddItem(item); - } -} - - void FontSelectionView::_SelectCurrentFont(bool select) { @@ -299,21 +270,19 @@ FontSelectionView::_SelectCurrentFont(bool select) void -FontSelectionView::_SelectCurrentSize(bool select) +FontSelectionView::_SelectCurrentSize() { - char label[16]; - snprintf(label, sizeof(label), "%" B_PRId32, (int32)fCurrentFont.Size()); - - BMenuItem* item = fSizesMenu->FindItem(label); - if (item != NULL) - item->SetMarked(select); + fFontSizeSpinner->SetValue((int32)fCurrentFont.Size()); } - void FontSelectionView::_UpdateFontPreview() { - fPreviewText->SetFont(&fCurrentFont); + const BRect textFrame = fPreviewTextView->Bounds(); + BString text = BString(kPreviewText); + fCurrentFont.TruncateString(&text, B_TRUNCATE_END, textFrame.Width()); + fPreviewTextView->SetFont(&fCurrentFont); + fPreviewTextView->SetText(text); #ifdef INSTANT_UPDATE _UpdateSystemFont(); @@ -374,7 +343,7 @@ FontSelectionView::SetDefaults() _UpdateFontPreview(); _SelectCurrentFont(true); - _SelectCurrentSize(true); + _SelectCurrentSize(); } @@ -390,7 +359,7 @@ FontSelectionView::Revert() _UpdateFontPreview(); _SelectCurrentFont(true); - _SelectCurrentSize(true); + _SelectCurrentSize(); } @@ -486,7 +455,7 @@ FontSelectionView::UpdateFontsMenu() message->AddString("style", (char*)style); message->AddString("name", Name()); - BMenuItem *item = new BMenuItem(style, message); + BMenuItem* item = new BMenuItem(style, message); if (!strcmp(style, currentStyle) && !strcmp(family, currentFamily)) { diff --git a/src/preferences/appearance/FontSelectionView.h b/src/preferences/appearance/FontSelectionView.h index 130a8fe19f..215206aede 100644 --- a/src/preferences/appearance/FontSelectionView.h +++ b/src/preferences/appearance/FontSelectionView.h @@ -19,6 +19,7 @@ class BBox; class BMenuField; class BPopUpMenu; class BStringView; +class BSpinner; static const int32 kMsgSetFamily = 'fmly'; static const int32 kMsgSetStyle = 'styl'; @@ -43,17 +44,14 @@ public: void UpdateFontsMenu(); - BLayoutItem* CreateSizesLabelLayoutItem(); - BLayoutItem* CreateSizesMenuBarLayoutItem(); + BLayoutItem* CreateFontsLabelLayoutItem() const; + BLayoutItem* CreateFontsMenuBarLayoutItem() const; + BView* GetFontSizeSpinner() const; + BView* GetPreviewBox() const; - BLayoutItem* CreateFontsLabelLayoutItem(); - BLayoutItem* CreateFontsMenuBarLayoutItem(); - - BView* GetPreviewBox(); - private: void _SelectCurrentFont(bool select); - void _SelectCurrentSize(bool select); + void _SelectCurrentSize(); void _UpdateFontPreview(); void _UpdateSystemFont(); void _BuildSizesMenu(); @@ -62,12 +60,12 @@ protected: BHandler* fMessageTarget; BMenuField* fFontsMenuField; - BMenuField* fSizesMenuField; BPopUpMenu* fFontsMenu; - BPopUpMenu* fSizesMenu; + + BSpinner* fFontSizeSpinner; BBox* fPreviewBox; - BStringView* fPreviewText; + BStringView* fPreviewTextView; BFont fSavedFont; BFont fCurrentFont; diff --git a/src/preferences/appearance/FontView.cpp b/src/preferences/appearance/FontView.cpp index fea39f5f8d..4649541d37 100644 --- a/src/preferences/appearance/FontView.cpp +++ b/src/preferences/appearance/FontView.cpp @@ -26,7 +26,6 @@ #include "APRWindow.h" #include "FontSelectionView.h" - #undef B_TRANSLATION_CONTEXT #define B_TRANSLATION_CONTEXT "Font view" @@ -43,8 +42,7 @@ add_font_selection_view(BGridLayout* layout, FontSelectionView* view, layout->AddItem(BSpaceLayoutItem::CreateGlue(), 2, row); - layout->AddItem(view->CreateSizesLabelLayoutItem(), 3, row); - layout->AddItem(view->CreateSizesMenuBarLayoutItem(), 4, row); + layout->AddView(view->GetFontSizeSpinner(), 4, row); row++;