From 5968be8e9e197647c5eb29ff111213b163428db7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Axel=20D=C3=B6rfler?= Date: Sun, 29 Mar 2009 11:05:56 +0000 Subject: [PATCH] First steps to make the "Menu" preferences superfluous (just what will we do with its fine icon?): * Added the menu font setting to the Fonts preferences app. * Made the window resizable at least in the horizontal direction. * Minor cleanup. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@29774 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- src/preferences/fonts/FontSelectionView.cpp | 43 +++++++++++--- src/preferences/fonts/FontSelectionView.h | 64 ++++++++++----------- src/preferences/fonts/FontView.cpp | 26 ++++++--- src/preferences/fonts/FontView.h | 29 +++++----- src/preferences/fonts/MainWindow.cpp | 5 +- src/preferences/fonts/MainWindow.h | 26 ++++----- 6 files changed, 119 insertions(+), 74 deletions(-) diff --git a/src/preferences/fonts/FontSelectionView.cpp b/src/preferences/fonts/FontSelectionView.cpp index f563c0dbff..8fe5b9a24c 100644 --- a/src/preferences/fonts/FontSelectionView.cpp +++ b/src/preferences/fonts/FontSelectionView.cpp @@ -67,11 +67,27 @@ _get_system_default_font_(const char* which, font_family family, FontSelectionView::FontSelectionView(BRect _rect, const char* name, - const char* label, const BFont& currentFont) + const char* label, const BFont* currentFont) : BView(_rect, name, B_FOLLOW_LEFT_RIGHT, B_WILL_DRAW), - fSavedFont(currentFont), - fCurrentFont(currentFont) + fSavedFont(currentFont) { + if (currentFont == NULL) { + if (!strcmp(Name(), "plain")) + fCurrentFont = *be_plain_font; + else if (!strcmp(Name(), "bold")) + fCurrentFont = *be_bold_font; + else if (!strcmp(Name(), "fixed")) + fCurrentFont = *be_fixed_font; + else if (!strcmp(Name(), "menu")) { + menu_info info; + get_menu_info(&info); + + fCurrentFont.SetFamilyAndStyle(info.f_family, info.f_style); + fCurrentFont.SetSize(info.font_size); + } + } else + fCurrentFont = *currentFont; + fDivider = StringWidth(label) + 5; fSizesMenu = new BPopUpMenu("size menu"); @@ -90,7 +106,7 @@ FontSelectionView::FontSelectionView(BRect _rect, const char* name, // size menu rect.right = rect.left + StringWidth("Size: 99") + 30.0f; fSizesMenuField = new BMenuField(rect, "sizes", "Size:", fSizesMenu, true, - B_FOLLOW_TOP); + B_FOLLOW_TOP | B_FOLLOW_RIGHT); fSizesMenuField->SetDivider(StringWidth(fSizesMenuField->Label()) + 5.0f); fSizesMenuField->SetAlignment(B_ALIGN_RIGHT); fSizesMenuField->ResizeToPreferred(); @@ -104,7 +120,8 @@ FontSelectionView::FontSelectionView(BRect _rect, const char* name, font.SetSize(kMaxSize); font_height height; font.GetHeight(&height); - rect.bottom = rect.top + ceil(height.ascent + height.descent + height.leading) + 5; + rect.bottom = rect.top + ceil(height.ascent + height.descent + + height.leading) + 5; fPreviewBox = new BBox(rect, "preview", B_FOLLOW_LEFT_RIGHT, B_WILL_DRAW | B_FRAME_EVENTS); @@ -343,7 +360,18 @@ FontSelectionView::_UpdateSystemFont() font_style style; fCurrentFont.GetFamilyAndStyle(&family, &style); - _set_system_font_(Name(), family, style, fCurrentFont.Size()); + if (!strcmp(Name(), "menu")) { + // The menu font is not handled as a system font + menu_info info; + get_menu_info(&info); + + strlcpy(info.f_family, (const char*)family, B_FONT_FAMILY_LENGTH); + strlcpy(info.f_style, (const char*)style, B_FONT_STYLE_LENGTH); + info.font_size = fCurrentFont.Size(); + + set_menu_info(&info); + } else + _set_system_font_(Name(), family, style, fCurrentFont.Size()); } @@ -470,7 +498,8 @@ FontSelectionView::UpdateFontsMenu() BMenuItem *item = new BMenuItem(style, message); - if (!strcmp(style, currentStyle) && !strcmp(family, currentFamily)) { + if (!strcmp(style, currentStyle) + && !strcmp(family, currentFamily)) { item->SetMarked(true); familyItem->SetMarked(true); } diff --git a/src/preferences/fonts/FontSelectionView.h b/src/preferences/fonts/FontSelectionView.h index 9b0ec29585..ef85e4475d 100644 --- a/src/preferences/fonts/FontSelectionView.h +++ b/src/preferences/fonts/FontSelectionView.h @@ -1,5 +1,5 @@ /* - * Copyright 2001-2005, Haiku. + * Copyright 2001-2009, Haiku. * Distributed under the terms of the MIT License. * * Authors: @@ -20,46 +20,46 @@ class BStringView; class FontSelectionView : public BView { - public: - FontSelectionView(BRect rect, const char* name, const char* label, - const BFont& currentFont); - virtual ~FontSelectionView(); +public: + FontSelectionView(BRect rect, const char* name, + const char* label, const BFont* font = NULL); + virtual ~FontSelectionView(); - virtual void GetPreferredSize(float *_width, float *_height); - virtual void AttachedToWindow(); - virtual void MessageReceived(BMessage *msg); + virtual void GetPreferredSize(float *_width, float *_height); + virtual void AttachedToWindow(); + virtual void MessageReceived(BMessage *msg); - void SetDivider(float divider); - void RelayoutIfNeeded(); + void SetDivider(float divider); + void RelayoutIfNeeded(); - void SetDefaults(); - void Revert(); - bool IsDefaultable(); - bool IsRevertable(); + void SetDefaults(); + void Revert(); + bool IsDefaultable(); + bool IsRevertable(); - void UpdateFontsMenu(); + void UpdateFontsMenu(); - private: - void _SelectCurrentFont(bool select); - void _SelectCurrentSize(bool select); - void _UpdateFontPreview(); - void _UpdateSystemFont(); - void _BuildSizesMenu(); +private: + void _SelectCurrentFont(bool select); + void _SelectCurrentSize(bool select); + void _UpdateFontPreview(); + void _UpdateSystemFont(); + void _BuildSizesMenu(); - protected: - float fDivider; +protected: + float fDivider; - BMenuField* fFontsMenuField; - BMenuField* fSizesMenuField; - BPopUpMenu* fFontsMenu; - BPopUpMenu* fSizesMenu; + BMenuField* fFontsMenuField; + BMenuField* fSizesMenuField; + BPopUpMenu* fFontsMenu; + BPopUpMenu* fSizesMenu; - BBox* fPreviewBox; - BStringView* fPreviewText; + BBox* fPreviewBox; + BStringView* fPreviewText; - BFont fSavedFont; - BFont fCurrentFont; - float fMaxFontNameWidth; + BFont fSavedFont; + BFont fCurrentFont; + float fMaxFontNameWidth; }; #endif /* FONT_SELECTION_VIEW_H */ diff --git a/src/preferences/fonts/FontView.cpp b/src/preferences/fonts/FontView.cpp index 4e5134aef1..c27da9684c 100644 --- a/src/preferences/fonts/FontView.cpp +++ b/src/preferences/fonts/FontView.cpp @@ -1,5 +1,5 @@ /* - * Copyright 2001-2005, Haiku. + * Copyright 2001-2009, Haiku. * Distributed under the terms of the MIT License. * * Authors: @@ -20,22 +20,28 @@ FontView::FontView(BRect _rect) float labelWidth = StringWidth("Fixed Font:") + 8; - fPlainView = new FontSelectionView(rect, "plain", "Plain Font:", *be_plain_font); + fPlainView = new FontSelectionView(rect, "plain", "Plain Font:"); fPlainView->SetDivider(labelWidth); fPlainView->ResizeToPreferred(); AddChild(fPlainView); rect.OffsetBy(0, fPlainView->Bounds().Height() + 10); - fBoldView = new FontSelectionView(rect, "bold", "Bold Font:", *be_bold_font); + fBoldView = new FontSelectionView(rect, "bold", "Bold Font:"); fBoldView->SetDivider(labelWidth); fBoldView->ResizeToPreferred(); AddChild(fBoldView); rect.OffsetBy(0, fPlainView->Bounds().Height() + 10); - fFixedView = new FontSelectionView(rect, "fixed", "Fixed Font:", *be_fixed_font); + fFixedView = new FontSelectionView(rect, "fixed", "Fixed Font:"); fFixedView->SetDivider(labelWidth); fFixedView->ResizeToPreferred(); AddChild(fFixedView); + + rect.OffsetBy(0, fFixedView->Bounds().Height() + 10); + fMenuView = new FontSelectionView(rect, "menu", "Menu Font:"); + fMenuView->SetDivider(labelWidth); + fMenuView->ResizeToPreferred(); + AddChild(fMenuView); } @@ -46,7 +52,7 @@ FontView::GetPreferredSize(float *_width, float *_height) *_width = fPlainView->Bounds().Width(); if (_height) - *_height = fPlainView->Bounds().Height() * 3 + 20; + *_height = fPlainView->Bounds().Height() * 4 + 40; } @@ -82,6 +88,7 @@ FontView::UpdateFonts() fPlainView->UpdateFontsMenu(); fBoldView->UpdateFontsMenu(); fFixedView->UpdateFontsMenu(); + fMenuView->UpdateFontsMenu(); } @@ -91,21 +98,26 @@ FontView::RelayoutIfNeeded() fPlainView->RelayoutIfNeeded(); fBoldView->RelayoutIfNeeded(); fFixedView->RelayoutIfNeeded(); + fMenuView->RelayoutIfNeeded(); } + bool FontView::IsDefaultable() { return fPlainView->IsDefaultable() || fBoldView->IsDefaultable() - || fFixedView->IsDefaultable(); + || fFixedView->IsDefaultable() + || fMenuView->IsDefaultable(); } + bool FontView::IsRevertable() { return fPlainView->IsRevertable() || fBoldView->IsRevertable() - || fFixedView->IsRevertable(); + || fFixedView->IsRevertable() + || fMenuView->IsRevertable(); } diff --git a/src/preferences/fonts/FontView.h b/src/preferences/fonts/FontView.h index abe58c5b6a..a16c88bed5 100644 --- a/src/preferences/fonts/FontView.h +++ b/src/preferences/fonts/FontView.h @@ -1,5 +1,5 @@ /* - * Copyright 2001-2005, Haiku. + * Copyright 2001-2009, Haiku. * Distributed under the terms of the MIT License. * * Authors: @@ -15,23 +15,24 @@ class FontView : public BView { - public: - FontView(BRect frame); +public: + FontView(BRect frame); - virtual void GetPreferredSize(float *_width, float *_height); + virtual void GetPreferredSize(float *_width, float *_height); - void SetDefaults(); - void Revert(); - void UpdateFonts(); - void RelayoutIfNeeded(); + void SetDefaults(); + void Revert(); + void UpdateFonts(); + void RelayoutIfNeeded(); - bool IsDefaultable(); - bool IsRevertable(); + bool IsDefaultable(); + bool IsRevertable(); - private: - FontSelectionView *fPlainView; - FontSelectionView *fBoldView; - FontSelectionView *fFixedView; +private: + FontSelectionView* fPlainView; + FontSelectionView* fBoldView; + FontSelectionView* fFixedView; + FontSelectionView* fMenuView; }; #endif /* FONT_VIEW_H */ diff --git a/src/preferences/fonts/MainWindow.cpp b/src/preferences/fonts/MainWindow.cpp index 4cdb6eaa71..aa61169971 100644 --- a/src/preferences/fonts/MainWindow.cpp +++ b/src/preferences/fonts/MainWindow.cpp @@ -27,7 +27,7 @@ static const uint32 kMsgCheckFonts = 'chkf'; MainWindow::MainWindow() : BWindow(BRect(100, 100, 445, 410), "Fonts", B_TITLED_WINDOW, - B_NOT_RESIZABLE | B_ASYNCHRONOUS_CONTROLS | B_NOT_ZOOMABLE) + B_ASYNCHRONOUS_CONTROLS | B_NOT_ZOOMABLE) { BRect rect = Bounds(); BView* view = new BView(rect, "background", B_FOLLOW_ALL, B_WILL_DRAW); @@ -89,6 +89,9 @@ MainWindow::MainWindow() + buttonHeight); view->AddChild(tabView); fFontsView->ResizeToPreferred(); + + SetSizeLimits(Bounds().Width(), 16347, + Bounds().Height(), Bounds().Height()); if (fSettings.WindowCorner() == BPoint(-1, -1)) { // center window on screen diff --git a/src/preferences/fonts/MainWindow.h b/src/preferences/fonts/MainWindow.h index 8f800545c0..316939f051 100644 --- a/src/preferences/fonts/MainWindow.h +++ b/src/preferences/fonts/MainWindow.h @@ -1,5 +1,5 @@ /* - * Copyright 2001-2005, Haiku. + * Copyright 2001-2009, Haiku. * Distributed under the terms of the MIT License. * * Authors: @@ -21,22 +21,22 @@ class FontView; class MainWindow : public BWindow { - public: - MainWindow(); - virtual ~MainWindow(); +public: + MainWindow(); + virtual ~MainWindow(); - virtual bool QuitRequested(); - virtual void MessageReceived(BMessage *message); + virtual bool QuitRequested(); + virtual void MessageReceived(BMessage *message); - private: - void _Center(); +private: + void _Center(); - BMessageRunner* fRunner; - FontView* fFontsView; - BButton* fDefaultsButton; - BButton* fRevertButton; + BMessageRunner* fRunner; + FontView* fFontsView; + BButton* fDefaultsButton; + BButton* fRevertButton; - FontsSettings fSettings; + FontsSettings fSettings; }; static const int32 kMsgUpdate = 'updt';