Ticket #3731: patch
File patch, 20.7 KB (added by , 16 years ago) |
---|
-
src/preferences/fonts/FontView.cpp
6 6 * Mark Hogben 7 7 * DarkWyrm <bpmagic@columbus.rr.com> 8 8 * Axel Dörfler, axeld@pinc-software.de 9 * Philippe St-Pierre, stpere@gmail.com 9 10 */ 10 11 11 12 12 13 #include "FontView.h" 14 #include <GridLayoutBuilder.h> 15 #include <GroupLayoutBuilder.h> 16 #include <SpaceLayoutItem.h> 13 17 14 18 15 FontView::FontView( BRect _rect)16 : BView( _rect, "Fonts", B_FOLLOW_ALL, B_WILL_DRAW)19 FontView::FontView() 20 : BView("Fonts", B_WILL_DRAW ) 17 21 { 18 22 SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR)); 19 BRect rect(Bounds()); 23 24 fPlainView = new FontSelectionView("plain", "Plain Font:"); 20 25 21 f loat labelWidth = StringWidth("Fixed Font:") + 8;26 fBoldView = new FontSelectionView("bold", "Bold Font:"); 22 27 23 fPlainView = new FontSelectionView(rect, "plain", "Plain Font:"); 24 fPlainView->SetDivider(labelWidth); 25 fPlainView->ResizeToPreferred(); 26 AddChild(fPlainView); 28 fFixedView = new FontSelectionView("fixed", "Fixed Font:"); 27 29 28 rect.OffsetBy(0, fPlainView->Bounds().Height() + 10); 29 fBoldView = new FontSelectionView(rect, "bold", "Bold Font:"); 30 fBoldView->SetDivider(labelWidth); 31 fBoldView->ResizeToPreferred(); 32 AddChild(fBoldView); 30 fMenuView = new FontSelectionView("menu", "Menu Font:"); 33 31 34 rect.OffsetBy(0, fPlainView->Bounds().Height() + 10); 35 fFixedView = new FontSelectionView(rect, "fixed", "Fixed Font:"); 36 fFixedView->SetDivider(labelWidth); 37 fFixedView->ResizeToPreferred(); 38 AddChild(fFixedView); 32 SetLayout(new BGroupLayout(B_VERTICAL)); 33 AddChild(BGridLayoutBuilder(5, 5) 34 .Add(fPlainView->CreateFontsLabelLayoutItem(), 0, 0) 35 .Add(fPlainView->CreateFontsMenuBarLayoutItem(), 1, 0) 36 .Add(BSpaceLayoutItem::CreateGlue(), 2, 0) 37 .Add(fPlainView->CreateSizesLabelLayoutItem(), 3, 0) 38 .Add(fPlainView->CreateSizesMenuBarLayoutItem(), 4, 0) 39 .Add(BSpaceLayoutItem::CreateGlue(), 0, 1) 40 .Add(fPlainView->GetPreviewBox(), 1, 1, 4) 39 41 40 rect.OffsetBy(0, fFixedView->Bounds().Height() + 10); 41 fMenuView = new FontSelectionView(rect, "menu", "Menu Font:"); 42 fMenuView->SetDivider(labelWidth); 43 fMenuView->ResizeToPreferred(); 44 AddChild(fMenuView); 42 .Add(fBoldView->CreateFontsLabelLayoutItem(), 0, 2) 43 .Add(fBoldView->CreateFontsMenuBarLayoutItem(), 1, 2) 44 .Add(BSpaceLayoutItem::CreateGlue(), 2, 2) 45 .Add(fBoldView->CreateSizesLabelLayoutItem(), 3, 2) 46 .Add(fBoldView->CreateSizesMenuBarLayoutItem(), 4, 2) 47 .Add(BSpaceLayoutItem::CreateGlue(), 0, 3) 48 .Add(fBoldView->GetPreviewBox(), 1, 3, 4) 49 50 .Add(fFixedView->CreateFontsLabelLayoutItem(), 0, 4) 51 .Add(fFixedView->CreateFontsMenuBarLayoutItem(), 1, 4) 52 .Add(BSpaceLayoutItem::CreateGlue(), 2, 4) 53 .Add(fFixedView->CreateSizesLabelLayoutItem(), 3, 4) 54 .Add(fFixedView->CreateSizesMenuBarLayoutItem(), 4, 4) 55 .Add(BSpaceLayoutItem::CreateGlue(), 0, 5) 56 .Add(fFixedView->GetPreviewBox(), 1, 5, 4) 57 58 .Add(fMenuView->CreateFontsLabelLayoutItem(), 0, 6) 59 .Add(fMenuView->CreateFontsMenuBarLayoutItem(), 1, 6) 60 .Add(BSpaceLayoutItem::CreateGlue(), 2, 6) 61 .Add(fMenuView->CreateSizesLabelLayoutItem(), 3, 6) 62 .Add(fMenuView->CreateSizesMenuBarLayoutItem(), 4, 6) 63 .Add(BSpaceLayoutItem::CreateGlue(), 0, 7) 64 .Add(fMenuView->GetPreviewBox(), 1, 7, 4) 65 .SetInsets(10, 10, 10, 10) 66 ); 45 67 } 46 68 47 69 48 70 void 49 FontView:: GetPreferredSize(float *_width, float *_height)71 FontView::SetDefaults() 50 72 { 51 if (_width) 52 *_width = fPlainView->Bounds().Width(); 53 54 if (_height) 55 *_height = fPlainView->Bounds().Height() * 4 + 40; 73 fPlainView->SetDefaults(); 74 fBoldView->SetDefaults(); 75 fFixedView->SetDefaults(); 76 fMenuView->SetDefaults(); 56 77 } 57 78 58 79 59 80 void 60 FontView:: SetDefaults()81 FontView::MessageReceived(BMessage *msg) 61 82 { 62 for (int32 i = 0; i < CountChildren(); i++) { 63 FontSelectionView* view = dynamic_cast<FontSelectionView *>(ChildAt(i)); 64 if (view == NULL) 65 continue; 83 switch (msg->what) { 84 case kMsgSetSize: 85 case kMsgSetFamily: 86 case kMsgSetStyle: 87 { 88 const char* name; 89 if (msg->FindString("name", &name) != B_OK) 90 break; 66 91 67 view->SetDefaults(); 92 if (!strcmp(name, "plain")) { 93 fPlainView->MessageReceived(msg); 94 } else if (!strcmp(name, "bold")) { 95 fBoldView->MessageReceived(msg); 96 } else if (!strcmp(name, "fixed")) { 97 fFixedView->MessageReceived(msg); 98 } else if (!strcmp(name, "menu")) { 99 fMenuView->MessageReceived(msg); 100 } else { 101 break; 102 } 103 104 Window()->PostMessage(kMsgUpdate); 105 break; 106 } 107 default: 108 BView::MessageReceived(msg); 68 109 } 69 110 } 70 111 71 72 112 void 73 113 FontView::Revert() 74 114 { 75 for (int32 i = 0; i < CountChildren(); i++) { 76 FontSelectionView* view = dynamic_cast<FontSelectionView *>(ChildAt(i)); 77 if (view == NULL) 78 continue; 79 80 view->Revert(); 81 } 115 fPlainView->Revert(); 116 fBoldView->Revert(); 117 fFixedView->Revert(); 118 fMenuView->Revert(); 82 119 } 83 120 84 121 … … 92 129 } 93 130 94 131 95 void96 FontView::RelayoutIfNeeded()97 {98 fPlainView->RelayoutIfNeeded();99 fBoldView->RelayoutIfNeeded();100 fFixedView->RelayoutIfNeeded();101 fMenuView->RelayoutIfNeeded();102 }103 104 105 132 bool 106 133 FontView::IsDefaultable() 107 134 { -
src/preferences/fonts/MainWindow.h
27 27 28 28 virtual bool QuitRequested(); 29 29 virtual void MessageReceived(BMessage *message); 30 virtual void Show(); 30 31 32 31 33 private: 32 void_Center();33 34 void _Center(); 35 bool fCentered; 34 36 BMessageRunner* fRunner; 35 37 FontView* fFontsView; 36 38 BButton* fDefaultsButton; -
src/preferences/fonts/FontView.h
6 6 * Mark Hogben 7 7 * DarkWyrm <bpmagic@columbus.rr.com> 8 8 * Axel Dörfler, axeld@pinc-software.de 9 * Philippe Saint-Pierre, stpere@gmail.com 9 10 */ 10 11 #ifndef FONT_VIEW_H 11 12 #define FONT_VIEW_H 12 13 13 14 14 #include "FontSelectionView.h" 15 #include "MainWindow.h" 16 #include <Message.h> 15 17 16 17 18 class FontView : public BView { 18 19 public: 19 FontView( BRect frame);20 FontView(); 20 21 21 virtual void GetPreferredSize(float *_width, float *_height);22 virtual void MessageReceived(BMessage *msg); 22 23 23 24 void SetDefaults(); 24 25 void Revert(); 25 26 void UpdateFonts(); 26 void RelayoutIfNeeded();27 27 28 28 bool IsDefaultable(); 29 29 bool IsRevertable(); 30 30 31 32 31 33 private: 32 34 FontSelectionView* fPlainView; 33 35 FontSelectionView* fBoldView; … … 35 37 FontSelectionView* fMenuView; 36 38 }; 37 39 40 38 41 #endif /* FONT_VIEW_H */ -
src/preferences/fonts/FontSelectionView.cpp
6 6 * Mark Hogben 7 7 * DarkWyrm <bpmagic@columbus.rr.com> 8 8 * Axel Dörfler, axeld@pinc-software.de 9 * Philippe Saint-Pierre, stpere@gmail.com 9 10 */ 10 11 11 12 … … 18 19 #include <PopUpMenu.h> 19 20 #include <String.h> 20 21 #include <StringView.h> 22 #include <LayoutItem.h> 23 #include <GroupLayoutBuilder.h> 21 24 22 25 #include <stdio.h> 23 26 … … 26 29 // if defined, the system font will be updated immediately, and not 27 30 // only on exit 28 31 29 static const int32 kMsgSetFamily = 'fmly';30 static const int32 kMsgSetStyle = 'styl';31 static const int32 kMsgSetSize = 'size';32 33 32 static const float kMinSize = 8.0; 34 33 static const float kMaxSize = 18.0; 35 34 … … 66 65 // #pragma mark - 67 66 68 67 69 FontSelectionView::FontSelectionView( BRect _rect,const char* name,68 FontSelectionView::FontSelectionView(const char* name, 70 69 const char* label, const BFont* currentFont) 71 : BView( _rect, name, B_FOLLOW_LEFT_RIGHT, B_WILL_DRAW),70 : BView(name, B_WILL_DRAW), 72 71 fSavedFont(currentFont) 73 72 { 74 73 if (currentFont == NULL) { … … 88 87 } else 89 88 fCurrentFont = *currentFont; 90 89 91 fDivider = StringWidth(label) + 5;92 93 90 fSizesMenu = new BPopUpMenu("size menu"); 94 91 _BuildSizesMenu(); 95 92 96 93 fFontsMenu = new BPopUpMenu("font menu"); 97 94 98 95 // font menu 99 BRect rect(Bounds()); 100 fFontsMenuField = new BMenuField(rect, "fonts", label, fFontsMenu, false); 101 fFontsMenuField->SetDivider(fDivider); 96 fFontsMenuField = new BMenuField("fonts", label, fFontsMenu, NULL); 102 97 fFontsMenuField->SetAlignment(B_ALIGN_RIGHT); 103 fFontsMenuField->ResizeToPreferred();104 AddChild(fFontsMenuField);105 98 106 99 // size menu 107 rect.right = rect.left + StringWidth("Size: 99") + 30.0f; 108 fSizesMenuField = new BMenuField(rect, "sizes", "Size:", fSizesMenu, true, 109 B_FOLLOW_TOP | B_FOLLOW_RIGHT); 110 fSizesMenuField->SetDivider(StringWidth(fSizesMenuField->Label()) + 5.0f); 100 fSizesMenuField = new BMenuField("size", "Size:", fSizesMenu, NULL); 111 101 fSizesMenuField->SetAlignment(B_ALIGN_RIGHT); 112 fSizesMenuField->ResizeToPreferred();113 rect = Bounds();114 fSizesMenuField->MoveBy(rect.right - fSizesMenuField->Bounds().Width(), 0);115 AddChild(fSizesMenuField);116 102 117 rect.top += fFontsMenuField->Bounds().Height() + 5; 118 rect.left = fDivider; 119 BFont font = be_plain_font; 120 font.SetSize(kMaxSize); 121 font_height height; 122 font.GetHeight(&height); 123 rect.bottom = rect.top + ceil(height.ascent + height.descent 124 + height.leading) + 5; 103 BView *fPreview = new BView("preview", B_WILL_DRAW); 125 104 126 fPreviewBox = new BBox( rect, "preview", B_FOLLOW_LEFT_RIGHT,127 B_WILL_DRAW | B_FRAME_EVENTS);128 AddChild(fPreviewBox);105 fPreviewBox = new BBox("preview box", B_WILL_DRAW | B_FRAME_EVENTS); 106 fPreviewText = new BStringView("preview text", 107 "The quick brown fox jumps over the lazy dog."); 129 108 130 // Place the text slightly inside the entire box area, so131 // it doesn't overlap the box outline.132 rect = fPreviewBox->Bounds().InsetByCopy(3, 3);133 fPreviewText = new BStringView(rect, "preview text",134 "The quick brown fox jumps over the lazy dog.",135 B_FOLLOW_LEFT_RIGHT);136 109 fPreviewText->SetFont(&fCurrentFont); 137 fPreviewBox->AddChild(fPreviewText); 110 111 fPreviewText->SetExplicitMaxSize(BSize(B_SIZE_UNLIMITED, B_SIZE_UNSET)); 112 fPreview->SetLayout(new BGroupLayout(B_HORIZONTAL)); 113 fPreview->AddChild(BGroupLayoutBuilder(B_HORIZONTAL) 114 .Add(fPreviewText) 115 .SetInsets(3, 3, 3, 3) 116 ); 117 fPreviewBox->AddChild(fPreview); 138 118 } 139 119 140 120 … … 146 126 } 147 127 148 128 149 void 150 FontSelectionView::GetPre ferredSize(float *_width, float *_height)129 BView* 130 FontSelectionView::GetPreviewBox() 151 131 { 152 // don't change the width if it is large enough 153 if (_width) { 154 *_width = fMaxFontNameWidth + 40 + fDivider 155 + fSizesMenuField->Bounds().Width(); 156 157 if (*_width < Bounds().Width()) 158 *_width = Bounds().Width(); 159 } 160 161 if (_height) { 162 BView* view = FindView("preview"); 163 if (view != NULL) 164 *_height = view->Frame().bottom; 165 } 132 return fPreviewBox; 166 133 } 167 134 168 135 169 136 void 170 FontSelectionView::SetDivider(float divider)171 {172 fFontsMenuField->SetDivider(divider);173 174 fPreviewBox->ResizeBy(fDivider - divider, 0);175 fPreviewBox->MoveBy(divider - fDivider, 0);176 177 // if the view is not yet attached to a window, the resizing mode is ignored178 if (Window() == NULL)179 fPreviewText->ResizeBy(fDivider - divider, 0);180 181 fDivider = divider;182 }183 184 185 void186 FontSelectionView::RelayoutIfNeeded()187 {188 float width, height;189 GetPreferredSize(&width, &height);190 191 if (width > Bounds().Width()) {192 fSizesMenuField->MoveTo(fMaxFontNameWidth + fDivider + 40.0f,193 fFontsMenuField->Bounds().top);194 ResizeTo(width, height);195 }196 }197 198 199 void200 FontSelectionView::AttachedToWindow()201 {202 if (Parent() != NULL)203 SetViewColor(Parent()->ViewColor());204 else205 SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR));206 207 fSizesMenu->SetTargetForItems(this);208 UpdateFontsMenu();209 }210 211 212 void213 137 FontSelectionView::MessageReceived(BMessage *msg) 214 138 { 215 139 switch (msg->what) { … … 222 146 223 147 fCurrentFont.SetSize(size); 224 148 _UpdateFontPreview(); 225 226 Window()->PostMessage(kMsgUpdate);227 149 break; 228 150 } 229 151 … … 250 172 _UpdateFontPreview(); 251 173 } 252 174 } 253 254 Window()->PostMessage(kMsgUpdate);255 175 break; 256 176 } 257 177 … … 272 192 273 193 fCurrentFont.SetFamilyAndStyle(family, style); 274 194 _UpdateFontPreview(); 275 276 Window()->PostMessage(kMsgUpdate);277 195 break; 278 196 } 279 197 … … 283 201 } 284 202 285 203 204 BLayoutItem* 205 FontSelectionView::CreateSizesLabelLayoutItem() 206 { 207 return fSizesMenuField->CreateLabelLayoutItem(); 208 } 209 210 211 BLayoutItem* 212 FontSelectionView::CreateSizesMenuBarLayoutItem() 213 { 214 return fSizesMenuField->CreateMenuBarLayoutItem(); 215 } 216 217 218 BLayoutItem* 219 FontSelectionView::CreateFontsLabelLayoutItem() 220 { 221 return fFontsMenuField->CreateLabelLayoutItem(); 222 } 223 224 225 BLayoutItem* 226 FontSelectionView::CreateFontsMenuBarLayoutItem() 227 { 228 return fFontsMenuField->CreateMenuBarLayoutItem(); 229 } 230 231 286 232 void 287 233 FontSelectionView::_BuildSizesMenu() 288 234 { … … 299 245 300 246 BMessage* message = new BMessage(kMsgSetSize); 301 247 message->AddInt32("size", size); 248 message->AddString("name", Name()); 302 249 303 250 BMenuItem* item = new BMenuItem(label, message); 304 251 if (size == fCurrentFont.Size()) … … 495 442 496 443 BMessage* message = new BMessage(kMsgSetFamily); 497 444 message->AddString("family", family); 445 message->AddString("name", Name()); 446 498 447 BMenuItem* familyItem = new BMenuItem(stylesMenu, message); 499 448 fFontsMenu->AddItem(familyItem); 500 449 … … 508 457 message = new BMessage(kMsgSetStyle); 509 458 message->AddString("family", (char*)family); 510 459 message->AddString("style", (char*)style); 460 message->AddString("name", Name()); 511 461 512 462 BMenuItem *item = new BMenuItem(style, message); 513 463 … … 518 468 } 519 469 stylesMenu->AddItem(item); 520 470 } 521 522 stylesMenu->SetTargetForItems(this);523 471 } 524 525 fFontsMenu->SetTargetForItems(this);526 472 } -
src/preferences/fonts/FontSelectionView.h
6 6 * Mark Hogben 7 7 * DarkWyrm <bpmagic@columbus.rr.com> 8 8 * Axel Dörfler, axeld@pinc-software.de 9 * Philippe Saint-Pierre, stpere@gmail.com 9 10 */ 10 11 #ifndef FONT_SELECTION_VIEW_H 11 12 #define FONT_SELECTION_VIEW_H … … 13 14 14 15 #include <View.h> 15 16 17 class BLayoutItem; 16 18 class BBox; 17 19 class BMenuField; 18 20 class BPopUpMenu; 19 21 class BStringView; 20 22 23 static const int32 kMsgSetFamily = 'fmly'; 24 static const int32 kMsgSetStyle = 'styl'; 25 static const int32 kMsgSetSize = 'size'; 21 26 27 22 28 class FontSelectionView : public BView { 23 29 public: 24 FontSelectionView( BRect rect,const char* name,30 FontSelectionView(const char* name, 25 31 const char* label, const BFont* font = NULL); 26 32 virtual ~FontSelectionView(); 27 33 28 virtual void GetPreferredSize(float *_width, float *_height); 29 virtual void AttachedToWindow(); 34 30 35 virtual void MessageReceived(BMessage *msg); 31 36 32 void SetDivider(float divider);33 void RelayoutIfNeeded();34 35 37 void SetDefaults(); 36 38 void Revert(); 37 39 bool IsDefaultable(); … … 39 41 40 42 void UpdateFontsMenu(); 41 43 44 BLayoutItem* CreateSizesLabelLayoutItem(); 45 BLayoutItem* CreateSizesMenuBarLayoutItem(); 46 47 BLayoutItem* CreateFontsLabelLayoutItem(); 48 BLayoutItem* CreateFontsMenuBarLayoutItem(); 49 50 BView* GetPreviewBox(); 51 42 52 private: 43 53 void _SelectCurrentFont(bool select); 44 54 void _SelectCurrentSize(bool select); … … 47 57 void _BuildSizesMenu(); 48 58 49 59 protected: 50 float fDivider;51 52 60 BMenuField* fFontsMenuField; 53 61 BMenuField* fSizesMenuField; 54 62 BPopUpMenu* fFontsMenu; -
src/preferences/fonts/MainWindow.cpp
7 7 * DarkWyrm <bpmagic@columbus.rr.com> 8 8 * Axel Dörfler, axeld@pinc-software.de 9 9 * Andrej Spielmann, <andrej.spielmann@seh.ox.ac.uk> 10 * Philippe Saint-Pierre, stpere@gmail.com 10 11 */ 11 12 12 13 … … 18 19 #include <MessageRunner.h> 19 20 #include <Screen.h> 20 21 #include <TabView.h> 22 #include <GroupLayoutBuilder.h> 23 #include <GridLayoutBuilder.h> 24 #include <SpaceLayoutItem.h> 25 #include <Alert.h> 26 #include <TextView.h> 27 #include <stdio.h> 21 28 22 23 29 static const uint32 kMsgSetDefaults = 'dflt'; 24 30 static const uint32 kMsgRevert = 'rvrt'; 25 31 static const uint32 kMsgCheckFonts = 'chkf'; 26 32 27 33 28 34 MainWindow::MainWindow() 29 : BWindow(BRect(100, 100, 445, 410), "Fonts", B_TITLED_WINDOW, 30 B_ASYNCHRONOUS_CONTROLS | B_NOT_ZOOMABLE) 35 : BWindow(BRect(0, 0, 1, 1), "Fonts", B_TITLED_WINDOW, 36 B_ASYNCHRONOUS_CONTROLS | B_NOT_ZOOMABLE | B_AUTO_UPDATE_SIZE_LIMITS), 37 fCentered(false) 31 38 { 32 BRect rect = Bounds(); 33 BView* view = new BView(rect, "background", B_FOLLOW_ALL, B_WILL_DRAW); 34 view->SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR)); 35 AddChild(view); 36 37 rect.left = 10; 38 rect.top = rect.bottom - 10; 39 fDefaultsButton = new BButton(rect, "defaults", "Defaults", 40 new BMessage(kMsgSetDefaults), B_FOLLOW_LEFT 41 | B_FOLLOW_BOTTOM, B_WILL_DRAW); 42 fDefaultsButton->ResizeToPreferred(); 39 fDefaultsButton = new BButton("defaults", "Defaults", 40 new BMessage(kMsgSetDefaults), B_WILL_DRAW); 43 41 fDefaultsButton->SetEnabled(false); 44 float buttonHeight = fDefaultsButton->Bounds().Height();45 fDefaultsButton->MoveBy(0, -buttonHeight);46 view->AddChild(fDefaultsButton);47 42 48 rect = fDefaultsButton->Frame(); 49 rect.OffsetBy(fDefaultsButton->Bounds().Width() + 10, 0); 43 fRevertButton = new BButton("revert", "Revert", 44 new BMessage(kMsgRevert), B_WILL_DRAW); 45 fRevertButton->SetEnabled(false); 50 46 51 fRevertButton = new BButton(rect, "revert", "Revert", 52 new BMessage(kMsgRevert), B_FOLLOW_LEFT | B_FOLLOW_BOTTOM, B_WILL_DRAW); 53 fRevertButton->ResizeToPreferred(); 54 fRevertButton->SetEnabled(false); 55 view->AddChild(fRevertButton); 47 BTabView *tabView = new BTabView("tabview", B_WIDTH_FROM_LABEL); 56 48 57 rect = Bounds(); 58 rect.top += 5; 59 rect.bottom -= 20 + buttonHeight; 60 rect.left += 5; 61 BTabView *tabView = new BTabView(rect, "tabview", B_WIDTH_FROM_LABEL); 49 fFontsView = new FontView(); 62 50 63 rect = tabView->ContainerView()->Bounds().InsetByCopy(5, 8);64 fFontsView = new FontView(rect);65 66 51 tabView->AddTab(fFontsView); 67 52 68 53 fFontsView->UpdateFonts(); 69 fFontsView->RelayoutIfNeeded();70 float width, height;71 fFontsView->GetPreferredSize(&width, &height);72 54 73 // make sure the tab is large enough for the fonts view 74 float widthDiff = width + 10 75 - tabView->ContainerView()->Bounds().Width(); 76 if (widthDiff > 0) { 77 tabView->ResizeBy(widthDiff, 0); 78 tabView->ContainerView()->ResizeBy(widthDiff, 0); 79 } 55 SetLayout(new BGroupLayout(B_VERTICAL)); 80 56 81 float heightDiff = height + 16 82 - tabView->ContainerView()->Bounds().Height(); 83 if (heightDiff > 0) { 84 tabView->ResizeBy(0, heightDiff); 85 tabView->ContainerView()->ResizeBy(0, heightDiff); 86 } 57 AddChild(BGroupLayoutBuilder(B_VERTICAL) 58 .Add(tabView) 59 .Add(BGroupLayoutBuilder(B_HORIZONTAL) 60 .Add(fDefaultsButton) 61 .Add(fRevertButton) 62 .Add(BSpaceLayoutItem::CreateGlue()) 63 .SetInsets(5, 5, 5, 5) 64 ) 65 .SetInsets(5, 5, 5, 5) 66 ); 87 67 88 ResizeTo(tabView->Bounds().Width() + 10, tabView->Frame().bottom + 2089 + buttonHeight);90 view->AddChild(tabView);91 fFontsView->ResizeToPreferred();92 93 SetSizeLimits(Bounds().Width(), 16347,94 Bounds().Height(), Bounds().Height());95 96 68 if (fSettings.WindowCorner() == BPoint(-1, -1)) { 97 69 // center window on screen 98 _Center();70 fCentered = true; 99 71 } else { 100 72 MoveTo(fSettings.WindowCorner()); 101 73 102 74 // make sure window is on screen 103 75 BScreen screen(this); 104 if (!screen.Frame().InsetByCopy(10, 10).Intersects(Frame())) 105 _Center(); 76 if (!screen.Frame().InsetByCopy(10, 10).Intersects(Frame())) { 77 fCentered = true; 78 } 106 79 } 107 80 81 if (fCentered) { 82 // draw offscreen to avoid flashing windows 83 MoveTo(BPoint(-1000, -1000)); 84 } 85 108 86 fRunner = new BMessageRunner(this, new BMessage(kMsgCheckFonts), 3000000); 109 87 // every 3 seconds 110 88 … … 112 90 } 113 91 114 92 93 void 94 MainWindow::Show() 95 { 96 BWindow::Show(); 97 if (fCentered) { 98 _Center(); 99 } 100 } 101 102 115 103 MainWindow::~MainWindow() 116 104 { 117 105 delete fRunner; … … 132 120 MainWindow::MessageReceived(BMessage *message) 133 121 { 134 122 switch (message->what) { 123 case kMsgSetSize: 124 case kMsgSetFamily: 125 case kMsgSetStyle: 126 fFontsView->MessageReceived(message); 127 break; 128 135 129 case kMsgUpdate: 136 130 fDefaultsButton->SetEnabled(fFontsView->IsDefaultable()); 137 131 fRevertButton->SetEnabled(fFontsView->IsRevertable()); … … 164 158 void 165 159 MainWindow::_Center() 166 160 { 167 B Screen screen;168 BRect screenFrame = screen.Frame();161 BRect screenFrame = BScreen(this).Frame(); 162 BRect windowRect = Frame(); 169 163 170 MoveTo(screenFrame.left + (screenFrame.Width() - Bounds().Width()) / 2, 171 screenFrame.top + (screenFrame.Height() - Bounds().Height()) / 2); 164 MoveTo( 165 (screenFrame.Width() - windowRect.Width()) / 2, 166 (screenFrame.Height() - windowRect.Height()) / 2); 172 167 }