From 5f700c9b7c995c5f370c800e661d3605eeded407 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stephan=20A=C3=9Fmus?= Date: Thu, 16 Apr 2009 10:11:06 +0000 Subject: [PATCH] Patch in large part by Philippe Saint-Pierre: * Update Font preflet to use the layout-management. This already fixes a lot of issues. * The were more issues with switching to default fonts and reverting fonts. Some fixed by Philippe and some fixed by myself. * The preflet currently contains a work-arround for the problem that the window does not yet have it's final size until after BWindow::Show() has been completed. To be able to center itself anyways, it will open outside screen bounds and center itself then. Note to Philippe: I had to fix some stuff in the Interface Kit to make this more smoothly, so I was able to remove some calls to Invalidate() and such. Also, the preview boxen and the menu fields align correctly now. Sorry if this gave your gripes... :-) git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@30194 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- src/preferences/fonts/FontSelectionView.cpp | 178 +++++++------------- src/preferences/fonts/FontSelectionView.h | 69 ++++---- src/preferences/fonts/FontView.cpp | 131 ++++++++------ src/preferences/fonts/FontView.h | 13 +- src/preferences/fonts/MainWindow.cpp | 125 +++++++------- src/preferences/fonts/MainWindow.h | 8 +- 6 files changed, 255 insertions(+), 269 deletions(-) diff --git a/src/preferences/fonts/FontSelectionView.cpp b/src/preferences/fonts/FontSelectionView.cpp index fb59afcb3e..a287ba807e 100644 --- a/src/preferences/fonts/FontSelectionView.cpp +++ b/src/preferences/fonts/FontSelectionView.cpp @@ -1,14 +1,15 @@ /* - * Copyright 2001-2005, Haiku. + * Copyright 2001-2009, Haiku. * Distributed under the terms of the MIT License. * * Authors: * Mark Hogben * DarkWyrm * Axel Dörfler, axeld@pinc-software.de + * Philippe Saint-Pierre, stpere@gmail.com + * Stephan Aßmus */ - #include "FontSelectionView.h" #include "MainWindow.h" @@ -18,6 +19,8 @@ #include #include #include +#include +#include #include @@ -26,10 +29,6 @@ // if defined, the system font will be updated immediately, and not // only on exit -static const int32 kMsgSetFamily = 'fmly'; -static const int32 kMsgSetStyle = 'styl'; -static const int32 kMsgSetSize = 'size'; - static const float kMinSize = 8.0; static const float kMaxSize = 18.0; @@ -66,10 +65,9 @@ _get_system_default_font_(const char* which, font_family family, // #pragma mark - -FontSelectionView::FontSelectionView(BRect _rect, const char* name, +FontSelectionView::FontSelectionView(const char* name, const char* label, const BFont* currentFont) - : BView(_rect, name, B_FOLLOW_LEFT_RIGHT, B_WILL_DRAW), - fSavedFont(currentFont) + : BView(name, B_WILL_DRAW) { if (currentFont == NULL) { if (!strcmp(Name(), "plain")) @@ -88,7 +86,7 @@ FontSelectionView::FontSelectionView(BRect _rect, const char* name, } else fCurrentFont = *currentFont; - fDivider = StringWidth(label) + 5; + fSavedFont = fCurrentFont; fSizesMenu = new BPopUpMenu("size menu"); _BuildSizesMenu(); @@ -96,45 +94,26 @@ FontSelectionView::FontSelectionView(BRect _rect, const char* name, fFontsMenu = new BPopUpMenu("font menu"); // font menu - BRect rect(Bounds()); - fFontsMenuField = new BMenuField(rect, "fonts", label, fFontsMenu, false); - fFontsMenuField->SetDivider(fDivider); + fFontsMenuField = new BMenuField("fonts", label, fFontsMenu, NULL); fFontsMenuField->SetAlignment(B_ALIGN_RIGHT); - fFontsMenuField->ResizeToPreferred(); - AddChild(fFontsMenuField); // size menu - rect.right = rect.left + StringWidth("Size: 99") + 30.0f; - fSizesMenuField = new BMenuField(rect, "sizes", "Size:", fSizesMenu, true, - B_FOLLOW_TOP | B_FOLLOW_RIGHT); - fSizesMenuField->SetDivider(StringWidth(fSizesMenuField->Label()) + 5.0f); + fSizesMenuField = new BMenuField("size", "Size:", fSizesMenu, NULL); fSizesMenuField->SetAlignment(B_ALIGN_RIGHT); - fSizesMenuField->ResizeToPreferred(); - rect = Bounds(); - fSizesMenuField->MoveBy(rect.right - fSizesMenuField->Bounds().Width(), 0); - AddChild(fSizesMenuField); - rect.top += fFontsMenuField->Bounds().Height() + 5; - rect.left = fDivider; - BFont font = be_plain_font; - font.SetSize(kMaxSize); - font_height height; - font.GetHeight(&height); - rect.bottom = rect.top + ceil(height.ascent + height.descent - + height.leading) + 5; + // preview + fPreviewText = new BStringView("preview text", + "The quick brown fox jumps over the lazy dog."); - fPreviewBox = new BBox(rect, "preview", B_FOLLOW_LEFT_RIGHT, - B_WILL_DRAW | B_FRAME_EVENTS); - AddChild(fPreviewBox); - - // Place the text slightly inside the entire box area, so - // it doesn't overlap the box outline. - rect = fPreviewBox->Bounds().InsetByCopy(3, 3); - fPreviewText = new BStringView(rect, "preview text", - "The quick brown fox jumps over the lazy dog.", - B_FOLLOW_LEFT_RIGHT); fPreviewText->SetFont(&fCurrentFont); - fPreviewBox->AddChild(fPreviewText); + fPreviewText->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) + .SetInsets(5, 5, 5, 5) + ); } @@ -146,66 +125,10 @@ FontSelectionView::~FontSelectionView() } -void -FontSelectionView::GetPreferredSize(float *_width, float *_height) +BView* +FontSelectionView::GetPreviewBox() { - // don't change the width if it is large enough - if (_width) { - *_width = fMaxFontNameWidth + 40 + fDivider - + fSizesMenuField->Bounds().Width(); - - if (*_width < Bounds().Width()) - *_width = Bounds().Width(); - } - - if (_height) { - BView* view = FindView("preview"); - if (view != NULL) - *_height = view->Frame().bottom; - } -} - - -void -FontSelectionView::SetDivider(float divider) -{ - fFontsMenuField->SetDivider(divider); - - fPreviewBox->ResizeBy(fDivider - divider, 0); - fPreviewBox->MoveBy(divider - fDivider, 0); - - // if the view is not yet attached to a window, the resizing mode is ignored - if (Window() == NULL) - fPreviewText->ResizeBy(fDivider - divider, 0); - - fDivider = divider; -} - - -void -FontSelectionView::RelayoutIfNeeded() -{ - float width, height; - GetPreferredSize(&width, &height); - - if (width > Bounds().Width()) { - fSizesMenuField->MoveTo(fMaxFontNameWidth + fDivider + 40.0f, - fFontsMenuField->Bounds().top); - ResizeTo(width, height); - } -} - - -void -FontSelectionView::AttachedToWindow() -{ - if (Parent() != NULL) - SetViewColor(Parent()->ViewColor()); - else - SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR)); - - fSizesMenu->SetTargetForItems(this); - UpdateFontsMenu(); + return fPreviewBox; } @@ -222,8 +145,6 @@ FontSelectionView::MessageReceived(BMessage *msg) fCurrentFont.SetSize(size); _UpdateFontPreview(); - - Window()->PostMessage(kMsgUpdate); break; } @@ -250,8 +171,6 @@ FontSelectionView::MessageReceived(BMessage *msg) _UpdateFontPreview(); } } - - Window()->PostMessage(kMsgUpdate); break; } @@ -272,8 +191,6 @@ FontSelectionView::MessageReceived(BMessage *msg) fCurrentFont.SetFamilyAndStyle(family, style); _UpdateFontPreview(); - - Window()->PostMessage(kMsgUpdate); break; } @@ -283,6 +200,34 @@ FontSelectionView::MessageReceived(BMessage *msg) } +BLayoutItem* +FontSelectionView::CreateSizesLabelLayoutItem() +{ + return fSizesMenuField->CreateLabelLayoutItem(); +} + + +BLayoutItem* +FontSelectionView::CreateSizesMenuBarLayoutItem() +{ + return fSizesMenuField->CreateMenuBarLayoutItem(); +} + + +BLayoutItem* +FontSelectionView::CreateFontsLabelLayoutItem() +{ + return fFontsMenuField->CreateLabelLayoutItem(); +} + + +BLayoutItem* +FontSelectionView::CreateFontsMenuBarLayoutItem() +{ + return fFontsMenuField->CreateMenuBarLayoutItem(); +} + + void FontSelectionView::_BuildSizesMenu() { @@ -299,6 +244,7 @@ FontSelectionView::_BuildSizesMenu() BMessage* message = new BMessage(kMsgSetSize); message->AddInt32("size", size); + message->AddString("name", Name()); BMenuItem* item = new BMenuItem(label, message); if (size == fCurrentFont.Size()) @@ -345,7 +291,6 @@ void FontSelectionView::_UpdateFontPreview() { fPreviewText->SetFont(&fCurrentFont); - fPreviewText->Invalidate(); #ifdef INSTANT_UPDATE _UpdateSystemFont(); @@ -360,7 +305,7 @@ FontSelectionView::_UpdateSystemFont() font_style style; fCurrentFont.GetFamilyAndStyle(&family, &style); - if (!strcmp(Name(), "menu")) { + if (strcmp(Name(), "menu") == 0) { // The menu font is not handled as a system font menu_info info; get_menu_info(&info); @@ -383,7 +328,7 @@ FontSelectionView::SetDefaults() float size; const char* fontName; - if (!strcmp(Name(), "menu")) + if (strcmp(Name(), "menu") == 0) fontName = "plain"; else fontName = Name(); @@ -434,13 +379,15 @@ FontSelectionView::IsDefaultable() float defaultSize; const char* fontName; - if (!strcmp(Name(), "menu")) + if (strcmp(Name(), "menu") == 0) fontName = "plain"; else fontName = Name(); - if (_get_system_default_font_(fontName, defaultFamily, defaultStyle, &defaultSize) != B_OK) + if (_get_system_default_font_(fontName, defaultFamily, defaultStyle, + &defaultSize) != B_OK) { return false; + } font_family currentFamily; font_style currentStyle; @@ -495,6 +442,8 @@ FontSelectionView::UpdateFontsMenu() BMessage* message = new BMessage(kMsgSetFamily); message->AddString("family", family); + message->AddString("name", Name()); + BMenuItem* familyItem = new BMenuItem(stylesMenu, message); fFontsMenu->AddItem(familyItem); @@ -508,6 +457,7 @@ FontSelectionView::UpdateFontsMenu() message = new BMessage(kMsgSetStyle); message->AddString("family", (char*)family); message->AddString("style", (char*)style); + message->AddString("name", Name()); BMenuItem *item = new BMenuItem(style, message); @@ -518,9 +468,5 @@ FontSelectionView::UpdateFontsMenu() } stylesMenu->AddItem(item); } - - stylesMenu->SetTargetForItems(this); } - - fFontsMenu->SetTargetForItems(this); } diff --git a/src/preferences/fonts/FontSelectionView.h b/src/preferences/fonts/FontSelectionView.h index ef85e4475d..5c853abd9c 100644 --- a/src/preferences/fonts/FontSelectionView.h +++ b/src/preferences/fonts/FontSelectionView.h @@ -6,6 +6,7 @@ * Mark Hogben * DarkWyrm * Axel Dörfler, axeld@pinc-software.de + * Philippe Saint-Pierre, stpere@gmail.com */ #ifndef FONT_SELECTION_VIEW_H #define FONT_SELECTION_VIEW_H @@ -13,53 +14,61 @@ #include +class BLayoutItem; class BBox; class BMenuField; class BPopUpMenu; class BStringView; +static const int32 kMsgSetFamily = 'fmly'; +static const int32 kMsgSetStyle = 'styl'; +static const int32 kMsgSetSize = 'size'; + class FontSelectionView : public BView { public: - FontSelectionView(BRect rect, const char* name, - const char* label, const BFont* font = NULL); - virtual ~FontSelectionView(); + FontSelectionView(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); - void SetDivider(float divider); - void RelayoutIfNeeded(); + virtual void MessageReceived(BMessage* message); - void SetDefaults(); - void Revert(); - bool IsDefaultable(); - bool IsRevertable(); + void SetDefaults(); + void Revert(); + bool IsDefaultable(); + bool IsRevertable(); - void UpdateFontsMenu(); + void UpdateFontsMenu(); + BLayoutItem* CreateSizesLabelLayoutItem(); + BLayoutItem* CreateSizesMenuBarLayoutItem(); + + BLayoutItem* CreateFontsLabelLayoutItem(); + BLayoutItem* CreateFontsMenuBarLayoutItem(); + + BView* GetPreviewBox(); + private: - void _SelectCurrentFont(bool select); - void _SelectCurrentSize(bool select); - void _UpdateFontPreview(); - void _UpdateSystemFont(); - void _BuildSizesMenu(); + void _SelectCurrentFont(bool select); + void _SelectCurrentSize(bool select); + void _UpdateFontPreview(); + void _UpdateSystemFont(); + void _BuildSizesMenu(); 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 */ +#endif // FONT_SELECTION_VIEW_H diff --git a/src/preferences/fonts/FontView.cpp b/src/preferences/fonts/FontView.cpp index c27da9684c..dd296b9a7a 100644 --- a/src/preferences/fonts/FontView.cpp +++ b/src/preferences/fonts/FontView.cpp @@ -6,65 +6,103 @@ * Mark Hogben * DarkWyrm * Axel Dörfler, axeld@pinc-software.de + * Philippe St-Pierre, stpere@gmail.com + * Stephan Aßmus */ - #include "FontView.h" +#include +#include +#include -FontView::FontView(BRect _rect) - : BView(_rect, "Fonts", B_FOLLOW_ALL, B_WILL_DRAW) + +static void +add_font_selection_view(BGridLayout* layout, FontSelectionView* view, + int32& row, bool withExtraSpace) { - SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR)); - BRect rect(Bounds()); + layout->AddItem(view->CreateFontsLabelLayoutItem(), 0, row); + layout->AddItem(view->CreateFontsMenuBarLayoutItem(), 1, row); - float labelWidth = StringWidth("Fixed Font:") + 8; + layout->AddItem(BSpaceLayoutItem::CreateGlue(), 2, row); - fPlainView = new FontSelectionView(rect, "plain", "Plain Font:"); - fPlainView->SetDivider(labelWidth); - fPlainView->ResizeToPreferred(); - AddChild(fPlainView); + layout->AddItem(view->CreateSizesLabelLayoutItem(), 3, row); + layout->AddItem(view->CreateSizesMenuBarLayoutItem(), 4, row); - rect.OffsetBy(0, fPlainView->Bounds().Height() + 10); - fBoldView = new FontSelectionView(rect, "bold", "Bold Font:"); - fBoldView->SetDivider(labelWidth); - fBoldView->ResizeToPreferred(); - AddChild(fBoldView); + row++; - rect.OffsetBy(0, fPlainView->Bounds().Height() + 10); - fFixedView = new FontSelectionView(rect, "fixed", "Fixed Font:"); - fFixedView->SetDivider(labelWidth); - fFixedView->ResizeToPreferred(); - AddChild(fFixedView); + layout->AddItem(BSpaceLayoutItem::CreateGlue(), 0, row); + layout->AddView(view->GetPreviewBox(), 1, row, 4); - rect.OffsetBy(0, fFixedView->Bounds().Height() + 10); - fMenuView = new FontSelectionView(rect, "menu", "Menu Font:"); - fMenuView->SetDivider(labelWidth); - fMenuView->ResizeToPreferred(); - AddChild(fMenuView); + row++; + + if (withExtraSpace) { + layout->AddItem(BSpaceLayoutItem::CreateVerticalStrut(5), 0, row, 5); + row++; + } } -void -FontView::GetPreferredSize(float *_width, float *_height) +FontView::FontView() + : BView("Fonts", B_WILL_DRAW ) { - if (_width) - *_width = fPlainView->Bounds().Width(); + SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR)); + + fPlainView = new FontSelectionView("plain", "Plain Font:"); + fBoldView = new FontSelectionView("bold", "Bold Font:"); + fFixedView = new FontSelectionView("fixed", "Fixed Font:"); + fMenuView = new FontSelectionView("menu", "Menu Font:"); - if (_height) - *_height = fPlainView->Bounds().Height() * 4 + 40; + BGridLayout* layout = new BGridLayout(5, 5); + layout->SetInsets(10, 10, 10, 10); + SetLayout(layout); + + int32 row = 0; + add_font_selection_view(layout, fPlainView, row, true); + add_font_selection_view(layout, fBoldView, row, true); + add_font_selection_view(layout, fFixedView, row, true); + add_font_selection_view(layout, fMenuView, row, false); } void FontView::SetDefaults() { - for (int32 i = 0; i < CountChildren(); i++) { - FontSelectionView* view = dynamic_cast(ChildAt(i)); - if (view == NULL) - continue; + fPlainView->SetDefaults(); + fBoldView->SetDefaults(); + fFixedView->SetDefaults(); + fMenuView->SetDefaults(); +} - view->SetDefaults(); + +void +FontView::MessageReceived(BMessage* message) +{ + switch (message->what) { + case kMsgSetSize: + case kMsgSetFamily: + case kMsgSetStyle: + { + const char* name; + if (message->FindString("name", &name) != B_OK) + break; + + if (!strcmp(name, "plain")) + fPlainView->MessageReceived(message); + else if (!strcmp(name, "bold")) + fBoldView->MessageReceived(message); + else if (!strcmp(name, "fixed")) + fFixedView->MessageReceived(message); + else if (!strcmp(name, "menu")) + fMenuView->MessageReceived(message); + else + break; + + Window()->PostMessage(kMsgUpdate); + break; + } + default: + BView::MessageReceived(message); } } @@ -72,13 +110,10 @@ FontView::SetDefaults() void FontView::Revert() { - for (int32 i = 0; i < CountChildren(); i++) { - FontSelectionView* view = dynamic_cast(ChildAt(i)); - if (view == NULL) - continue; - - view->Revert(); - } + fPlainView->Revert(); + fBoldView->Revert(); + fFixedView->Revert(); + fMenuView->Revert(); } @@ -92,16 +127,6 @@ FontView::UpdateFonts() } -void -FontView::RelayoutIfNeeded() -{ - fPlainView->RelayoutIfNeeded(); - fBoldView->RelayoutIfNeeded(); - fFixedView->RelayoutIfNeeded(); - fMenuView->RelayoutIfNeeded(); -} - - bool FontView::IsDefaultable() { diff --git a/src/preferences/fonts/FontView.h b/src/preferences/fonts/FontView.h index a16c88bed5..b1f43cf555 100644 --- a/src/preferences/fonts/FontView.h +++ b/src/preferences/fonts/FontView.h @@ -6,28 +6,30 @@ * Mark Hogben * DarkWyrm * Axel Dörfler, axeld@pinc-software.de + * Philippe Saint-Pierre, stpere@gmail.com */ #ifndef FONT_VIEW_H #define FONT_VIEW_H - #include "FontSelectionView.h" - +#include "MainWindow.h" +#include class FontView : public BView { public: - FontView(BRect frame); + FontView(); - virtual void GetPreferredSize(float *_width, float *_height); + virtual void MessageReceived(BMessage* message); void SetDefaults(); void Revert(); void UpdateFonts(); - void RelayoutIfNeeded(); bool IsDefaultable(); bool IsRevertable(); + + private: FontSelectionView* fPlainView; FontSelectionView* fBoldView; @@ -35,4 +37,5 @@ private: FontSelectionView* fMenuView; }; + #endif /* FONT_VIEW_H */ diff --git a/src/preferences/fonts/MainWindow.cpp b/src/preferences/fonts/MainWindow.cpp index aa61169971..e352a42697 100644 --- a/src/preferences/fonts/MainWindow.cpp +++ b/src/preferences/fonts/MainWindow.cpp @@ -1,5 +1,5 @@ /* - * Copyright 2001-2005, Haiku. + * Copyright 2001-2009, Haiku. * Distributed under the terms of the MIT License. * * Authors: @@ -7,17 +7,25 @@ * DarkWyrm * Axel Dörfler, axeld@pinc-software.de * Andrej Spielmann, + * Philippe Saint-Pierre, stpere@gmail.com */ - -#include "FontView.h" #include "MainWindow.h" +#include + +#include #include #include +#include +#include #include #include +#include #include +#include + +#include "FontView.h" static const uint32 kMsgSetDefaults = 'dflt'; @@ -26,83 +34,57 @@ static const uint32 kMsgCheckFonts = 'chkf'; MainWindow::MainWindow() - : BWindow(BRect(100, 100, 445, 410), "Fonts", B_TITLED_WINDOW, - B_ASYNCHRONOUS_CONTROLS | B_NOT_ZOOMABLE) + : BWindow(BRect(0, 0, 1, 1), "Fonts", B_TITLED_WINDOW, + B_ASYNCHRONOUS_CONTROLS | B_NOT_ZOOMABLE | B_AUTO_UPDATE_SIZE_LIMITS), + fCentered(false) { - BRect rect = Bounds(); - BView* view = new BView(rect, "background", B_FOLLOW_ALL, B_WILL_DRAW); - view->SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR)); - AddChild(view); - - rect.left = 10; - rect.top = rect.bottom - 10; - fDefaultsButton = new BButton(rect, "defaults", "Defaults", - new BMessage(kMsgSetDefaults), B_FOLLOW_LEFT - | B_FOLLOW_BOTTOM, B_WILL_DRAW); - fDefaultsButton->ResizeToPreferred(); + fDefaultsButton = new BButton("defaults", "Defaults", + new BMessage(kMsgSetDefaults), B_WILL_DRAW); fDefaultsButton->SetEnabled(false); - float buttonHeight = fDefaultsButton->Bounds().Height(); - fDefaultsButton->MoveBy(0, -buttonHeight); - view->AddChild(fDefaultsButton); - rect = fDefaultsButton->Frame(); - rect.OffsetBy(fDefaultsButton->Bounds().Width() + 10, 0); + fRevertButton = new BButton("revert", "Revert", + new BMessage(kMsgRevert), B_WILL_DRAW); + fRevertButton->SetEnabled(false); - fRevertButton = new BButton(rect, "revert", "Revert", - new BMessage(kMsgRevert), B_FOLLOW_LEFT | B_FOLLOW_BOTTOM, B_WILL_DRAW); - fRevertButton->ResizeToPreferred(); - fRevertButton->SetEnabled(false); - view->AddChild(fRevertButton); + BTabView* tabView = new BTabView("tabview", B_WIDTH_FROM_LABEL); - rect = Bounds(); - rect.top += 5; - rect.bottom -= 20 + buttonHeight; - rect.left += 5; - BTabView *tabView = new BTabView(rect, "tabview", B_WIDTH_FROM_LABEL); - - rect = tabView->ContainerView()->Bounds().InsetByCopy(5, 8); - fFontsView = new FontView(rect); + fFontsView = new FontView(); tabView->AddTab(fFontsView); fFontsView->UpdateFonts(); - fFontsView->RelayoutIfNeeded(); - float width, height; - fFontsView->GetPreferredSize(&width, &height); - // make sure the tab is large enough for the fonts view - float widthDiff = width + 10 - - tabView->ContainerView()->Bounds().Width(); - if (widthDiff > 0) { - tabView->ResizeBy(widthDiff, 0); - tabView->ContainerView()->ResizeBy(widthDiff, 0); - } + SetLayout(new BGroupLayout(B_VERTICAL)); - float heightDiff = height + 16 - - tabView->ContainerView()->Bounds().Height(); - if (heightDiff > 0) { - tabView->ResizeBy(0, heightDiff); - tabView->ContainerView()->ResizeBy(0, heightDiff); - } + const float kInset = 8; - ResizeTo(tabView->Bounds().Width() + 10, tabView->Frame().bottom + 20 - + buttonHeight); - view->AddChild(tabView); - fFontsView->ResizeToPreferred(); - - SetSizeLimits(Bounds().Width(), 16347, - Bounds().Height(), Bounds().Height()); + AddChild(BGroupLayoutBuilder(B_VERTICAL) + .Add(tabView) + .Add(BSpaceLayoutItem::CreateVerticalStrut(kInset)) + .Add(BGroupLayoutBuilder(B_HORIZONTAL) + .Add(fDefaultsButton) + .Add(BSpaceLayoutItem::CreateHorizontalStrut(kInset)) + .Add(fRevertButton) + .Add(BSpaceLayoutItem::CreateGlue()) + ) + .SetInsets(kInset, kInset, kInset, kInset) + ); if (fSettings.WindowCorner() == BPoint(-1, -1)) { // center window on screen - _Center(); + fCentered = true; } else { MoveTo(fSettings.WindowCorner()); // make sure window is on screen BScreen screen(this); if (!screen.Frame().InsetByCopy(10, 10).Intersects(Frame())) - _Center(); + fCentered = true; + } + + if (fCentered) { + // draw offscreen to avoid flashing windows + MoveTo(BPoint(-1000, -1000)); } fRunner = new BMessageRunner(this, new BMessage(kMsgCheckFonts), 3000000); @@ -112,6 +94,16 @@ MainWindow::MainWindow() } +void +MainWindow::Show() +{ + BWindow::Show(); + + if (fCentered) + _Center(); +} + + MainWindow::~MainWindow() { delete fRunner; @@ -132,6 +124,12 @@ void MainWindow::MessageReceived(BMessage *message) { switch (message->what) { + case kMsgSetSize: + case kMsgSetFamily: + case kMsgSetStyle: + fFontsView->MessageReceived(message); + break; + case kMsgUpdate: fDefaultsButton->SetEnabled(fFontsView->IsDefaultable()); fRevertButton->SetEnabled(fFontsView->IsRevertable()); @@ -164,9 +162,10 @@ MainWindow::MessageReceived(BMessage *message) void MainWindow::_Center() { - BScreen screen; - BRect screenFrame = screen.Frame(); + BRect screenFrame = BScreen(this).Frame(); + BRect windowRect = Frame(); - MoveTo(screenFrame.left + (screenFrame.Width() - Bounds().Width()) / 2, - screenFrame.top + (screenFrame.Height() - Bounds().Height()) / 2); + MoveTo( + (screenFrame.Width() - windowRect.Width()) / 2, + (screenFrame.Height() - windowRect.Height()) / 2); } diff --git a/src/preferences/fonts/MainWindow.h b/src/preferences/fonts/MainWindow.h index 316939f051..c14a9b8c89 100644 --- a/src/preferences/fonts/MainWindow.h +++ b/src/preferences/fonts/MainWindow.h @@ -27,9 +27,13 @@ public: virtual bool QuitRequested(); virtual void MessageReceived(BMessage *message); + virtual void Show(); + private: - void _Center(); + void _Center(); + + bool fCentered; BMessageRunner* fRunner; FontView* fFontsView; @@ -41,4 +45,4 @@ private: static const int32 kMsgUpdate = 'updt'; -#endif /* MAIN_WINDOW_H */ +#endif // MAIN_WINDOW_H