From 36f5422d14f3a68f5a233d3b588ff6d2a09e7e53 Mon Sep 17 00:00:00 2001 From: DarkWyrm Date: Wed, 8 Jun 2005 22:35:44 +0000 Subject: [PATCH] Serious cleanup: Most files updated to style guidelines Panel now updates cache size temporarily disabled revert code while cleaning up the code settings file is now a flattened BMessage for the app_server's sake Unhacking some of the code git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@13020 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- src/prefs/fonts/ButtonView.cpp | 87 ++--- src/prefs/fonts/ButtonView.h | 69 ++-- src/prefs/fonts/CacheView.cpp | 222 ++++++------ src/prefs/fonts/CacheView.h | 107 ++---- src/prefs/fonts/FontSelectionView.cpp | 473 ++++++++++++-------------- src/prefs/fonts/FontSelectionView.h | 237 ++++--------- src/prefs/fonts/FontView.cpp | 99 ++---- src/prefs/fonts/FontView.h | 59 ++-- src/prefs/fonts/FontsSettings.cpp | 68 ++-- src/prefs/fonts/FontsSettings.h | 26 +- src/prefs/fonts/MainWindow.cpp | 262 ++++++-------- src/prefs/fonts/MainWindow.h | 100 ++---- src/prefs/fonts/main.cpp | 78 +---- src/prefs/fonts/main.h | 48 +-- 14 files changed, 772 insertions(+), 1163 deletions(-) diff --git a/src/prefs/fonts/ButtonView.cpp b/src/prefs/fonts/ButtonView.cpp index 30dde41b37..117b746f1e 100644 --- a/src/prefs/fonts/ButtonView.cpp +++ b/src/prefs/fonts/ButtonView.cpp @@ -1,47 +1,36 @@ -/*! \file ButtonView.cpp - * \brief Code for the ButtonView. +/* + * Copyright 2001-2005, Haiku. + * Distributed under the terms of the MIT License. + * */ - -#ifndef BUTTON_VIEW_H +#include "ButtonView.h" - #include "ButtonView.h" - -#endif - -/** - * Constructor - * @param rect The size of the view. - */ ButtonView::ButtonView(BRect rect) - :BView(rect, "ButtonView", B_FOLLOW_ALL, B_WILL_DRAW) + : BView(rect, "ButtonView", B_FOLLOW_ALL, B_WILL_DRAW) { - SetViewColor(216,216,216,0); + SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR)); BRect btnRect(0, 0, 75, 25); btnRect.OffsetBy(10, 8); - BButton *rescanButton = new BButton(btnRect, - "rescanButton", "Rescan", - new BMessage(RESCAN_FONTS_MSG), - B_FOLLOW_LEFT, B_WILL_DRAW); + BButton *rescanButton = new BButton(btnRect, "rescanButton", "Rescan", + new BMessage(RESCAN_FONTS_MSG), + B_FOLLOW_LEFT, B_WILL_DRAW); + AddChild(rescanButton); btnRect.OffsetBy(96, 0); - BButton *defaultsButton = new BButton(btnRect, - "defaultsButton", "Defaults", - new BMessage(RESET_FONTS_MSG), - B_FOLLOW_LEFT, B_WILL_DRAW); + BButton *defaultsButton = new BButton(btnRect, "defaultsButton", + "Defaults", + new BMessage(RESET_FONTS_MSG), + B_FOLLOW_LEFT, B_WILL_DRAW); + AddChild(defaultsButton); btnRect.OffsetBy(85, 0); - revertButton = new BButton(btnRect, - "revertButton", "Revert", - new BMessage(REVERT_MSG), - B_FOLLOW_LEFT, B_WILL_DRAW); - - revertButton->SetEnabled(false); - - AddChild(rescanButton); - AddChild(defaultsButton); + revertButton = new BButton(btnRect, "revertButton", "Revert", + new BMessage(REVERT_MSG), + B_FOLLOW_LEFT, B_WILL_DRAW); AddChild(revertButton); + revertButton->SetEnabled(false); } @@ -51,31 +40,27 @@ ButtonView::Draw(BRect update) rgb_color dark = {100, 100, 100, 255}; rgb_color light = {255, 255, 255, 255}; BRect bounds(Bounds()); + BeginLineArray(6); - AddLine(bounds.LeftTop(), bounds.RightTop(), light); - AddLine(bounds.LeftTop(), bounds.LeftBottom(), light); - AddLine(bounds.RightTop(), bounds.RightBottom(), dark); - AddLine(bounds.RightBottom(), bounds.LeftBottom(), dark); - AddLine(BPoint(95, 9), BPoint(95, 34), dark); - AddLine(BPoint(96, 9), BPoint(96, 34), light); + + AddLine(bounds.LeftTop(), bounds.RightTop(), light); + AddLine(bounds.LeftTop(), bounds.LeftBottom(), light); + AddLine(bounds.RightTop(), bounds.RightBottom(), dark); + AddLine(bounds.RightBottom(), bounds.LeftBottom(), dark); + AddLine(BPoint(95, 9), BPoint(95, 34), dark); + AddLine(BPoint(96, 9), BPoint(96, 34), light); + EndLineArray(); } -/** - * Returns the state of the revert button. - */ -bool ButtonView::RevertState(){ - +bool +ButtonView::RevertState() +{ return revertButton->IsEnabled(); - -}//RevertState - -/** - * Sets the state of the revert button. - */ -void ButtonView::SetRevertState(bool b){ +} +void ButtonView::SetRevertState(bool b) +{ revertButton->SetEnabled(b); - -}//SetRevertState +} diff --git a/src/prefs/fonts/ButtonView.h b/src/prefs/fonts/ButtonView.h index eabcdd1a6b..9a8823dc02 100644 --- a/src/prefs/fonts/ButtonView.h +++ b/src/prefs/fonts/ButtonView.h @@ -1,49 +1,34 @@ -/*! \file ButtonView.h - * \brief Header file for the ButtonView class. +/* + * Copyright 2001-2005, Haiku. + * Distributed under the terms of the MIT License. + * */ - #ifndef BUTTON_VIEW_H +#define BUTTON_VIEW_H + +#include +#include - #define BUTTON_VIEW_H +// Message sent when the rescan button is sent. +#define RESCAN_FONTS_MSG 'rscn' + +// Message sent when the reset button is sent. +#define RESET_FONTS_MSG 'rset' + +// Message sent when the revert button is sent. +#define REVERT_MSG 'rvrt' - /*! - * Message sent when the rescan button is sent. - */ - #define RESCAN_FONTS_MSG 'rscn' - - /*! - * Message sent when the reset button is sent. - */ - #define RESET_FONTS_MSG 'rset' - - /*! - * Message sent when the revert button is sent. - */ - #define REVERT_MSG 'rvrt' - - #include - - #ifndef _BUTTON_H - - #include - - #endif - - class ButtonView : public BView { - - public: - +class ButtonView : public BView +{ +public: ButtonView(BRect frame); - bool RevertState(); - void SetRevertState(bool b); - void Draw(BRect); - private: - - /** - * The revert button. - */ - BButton *revertButton; - - }; + bool RevertState(); + void SetRevertState(bool b); + void Draw(BRect); + +private: + + BButton *revertButton; +}; #endif diff --git a/src/prefs/fonts/CacheView.cpp b/src/prefs/fonts/CacheView.cpp index 9b9b397a8f..febb6aa830 100644 --- a/src/prefs/fonts/CacheView.cpp +++ b/src/prefs/fonts/CacheView.cpp @@ -1,130 +1,147 @@ -/*! \file CacheView.cpp - * \brief The file that contains code for the CacheView. +/* + * Copyright 2001-2005, Haiku. + * Distributed under the terms of the MIT License. + * */ -#ifndef CACHE_VIEW_H +#include "CacheView.h" - #include "CacheView.h" - -#endif #include +#include #include "Pref_Utils.h" -const char *kLabel = "font cache size: "; +#define PRINT_FCS_UPDATE_MSG 'pfum' +#define SCREEN_FCS_UPDATE_MSG 'sfum' +#define PRINT_FCS_MODIFICATION_MSG 'pfmm' +#define SCREEN_FCS_MODIFICATION_MSG 'sfmm' -/** - * Constructor - * @param rect The size of the view. - * @param minVal The minimum value of the cache sliders. - * @param maxVal The maximum value of the cache sliders. - * @param printCurrVal The starting value of the print slider. - * @param screenCurrVal The starting value of the screen slider. - */ -CacheView::CacheView(BRect rect, int minVal, int maxVal, int32 printCurrVal, int32 screenCurrVal) - :BView(rect, "CacheView", B_FOLLOW_ALL, B_WILL_DRAW) + +CacheView::CacheView(const BRect &frame, const int32 &sliderMin, + const int32 &sliderMax, const int32 &printVal, + const int32 &screenVal) + + : BView(frame, "Cache", B_FOLLOW_ALL, B_WILL_DRAW), + fSavedPrintValue(printVal), + fSavedScreenValue(screenVal) { - SetViewColor(216, 216, 216, 0); + SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR)); - origPrintVal = printCurrVal; - origScreenVal = screenCurrVal; + rgb_color fillColor = { 102, 152, 203, 255 }; - rgb_color fillColor; - fillColor.red = 102; - fillColor.blue = 203; - fillColor.green = 152; - - float fontheight = FontHeight(true); - BRect rect(Bounds()); - rect.InsetBy(5.0, 3.0); - rect.top += fontheight; - rect.bottom = rect.top +(fontheight *2.0); - BString labels(B_EMPTY_STRING); - labels << "Screen" << kLabel << screenCurrVal << " kB"; - screenFCS = new BSlider(rect, - "screenFontCache", labels.String(), - new BMessage(SCREEN_FCS_UPDATE_MSG), - minVal, maxVal, B_TRIANGLE_THUMB); - - screenFCS->SetModificationMessage(new BMessage(SCREEN_FCS_MODIFICATION_MSG)); - BString minLabel(B_EMPTY_STRING); BString maxLabel(B_EMPTY_STRING); - minLabel << minVal << " kB"; - maxLabel << maxVal << " kB"; - screenFCS->SetLimitLabels(minLabel.String(), maxLabel.String()); - screenFCS->UseFillColor(TRUE, &fillColor); - screenFCS->SetValue(screenCurrVal); + + float fontheight = FontHeight(true); + + BRect rect( Bounds().InsetByCopy(5.0,3.0) ); + rect.top += fontheight; + rect.bottom = rect.top +(fontheight *2.0); + + BString labels(B_EMPTY_STRING); + labels << "Screen font cache size: " << screenVal << " kB"; + + fScreenSlider = new BSlider(rect, "screenslider", labels.String(), + new BMessage(SCREEN_FCS_UPDATE_MSG), + sliderMin, sliderMax, B_TRIANGLE_THUMB); + + fScreenSlider->SetModificationMessage(new BMessage(SCREEN_FCS_MODIFICATION_MSG)); + AddChild(fScreenSlider); + + minLabel << sliderMin << " kB"; + maxLabel << sliderMax << " kB"; + + fScreenSlider->SetLimitLabels(minLabel.String(), maxLabel.String()); + fScreenSlider->UseFillColor(TRUE, &fillColor); + fScreenSlider->SetValue(screenVal); rect.OffsetTo(rect.left, rect.bottom +(fontheight *2.5)); - labels = ""; - labels << "Printing " << kLabel << printCurrVal << " kB"; + labels = ""; + labels << "Printing font cache size: " << printVal << " kB"; - printFCS = new BSlider(rect, "printFontCache", labels.String(), - new BMessage(PRINT_FCS_UPDATE_MSG), - minVal, maxVal, B_TRIANGLE_THUMB); + fPrintSlider = new BSlider(rect, "printFontCache", labels.String(), + new BMessage(PRINT_FCS_UPDATE_MSG), + sliderMin, sliderMax, B_TRIANGLE_THUMB); + AddChild(fPrintSlider); - printFCS->SetModificationMessage(new BMessage(PRINT_FCS_MODIFICATION_MSG)); + fPrintSlider->SetModificationMessage(new BMessage(PRINT_FCS_MODIFICATION_MSG)); - printFCS->SetLimitLabels(minLabel.String(), maxLabel.String()); - printFCS->UseFillColor(TRUE, &fillColor); - printFCS->SetValue(printCurrVal); + fPrintSlider->SetLimitLabels(minLabel.String(), maxLabel.String()); + fPrintSlider->UseFillColor(TRUE, &fillColor); + fPrintSlider->SetValue(printVal); rect.OffsetTo(rect.left -1.0, rect.bottom +(fontheight *2.0)); rect.right = rect.left +86.0; rect.bottom = rect.top +24.0; - BButton *saveCache = new BButton(rect, - "saveCache", "Save Cache", - NULL, B_FOLLOW_LEFT, B_WILL_DRAW); - - AddChild(screenFCS); - AddChild(printFCS); - AddChild(saveCache); + // TODO: find out what 'Save Cache' does and implement + fSaveCache = new BButton(rect, "saveCache", "Save Cache", + NULL, B_FOLLOW_LEFT, B_WILL_DRAW); + AddChild(fSaveCache); } -/** - * Updates the label on the print slider. - * @param txt The text to update the slider to. - */ -void CacheView::updatePrintFCS(const char* txt){ +void +CacheView::AttachedToWindow(void) +{ + fScreenSlider->SetTarget(this); + fPrintSlider->SetTarget(this); + fSaveCache->SetTarget(this); +} - printFCS->SetLabel(txt); - -}//updatePrintFCS - -/** - * Updates the label on the screen slider. - * @param txt The text to update the slider to. - */ -void CacheView::updateScreenFCS(const char* txt){ - - screenFCS->SetLabel(txt); - -}//updatePrintFCS - -/** - * Gets the current value of the print slider. - */ -int CacheView::getPrintFCSValue(){ - - return int(printFCS->Value()); - -}//getPrintValue - -/** - * Gets the current value of the screen slider. - */ -int CacheView::getScreenFCSValue(){ - - return int(screenFCS->Value()); - -}//getPrintValue +void +CacheView::MessageReceived(BMessage *msg) +{ + switch(msg->what) + { + case PRINT_FCS_MODIFICATION_MSG: + { + struct font_cache_info fontCacheInfo; + + get_font_cache_info(B_PRINTING_FONT_CACHE|B_DEFAULT_CACHE_SETTING, + &fontCacheInfo); + fontCacheInfo.cache_size = fPrintSlider->Value() << 10; + set_font_cache_info(B_PRINTING_FONT_CACHE|B_DEFAULT_CACHE_SETTING, + &fontCacheInfo); + + BString str("Printing font cache size : "); + str << fPrintSlider->Value() << " kB"; + fPrintSlider->SetLabel(str.String()); + + // TODO: set revert state +// buttonView->SetRevertState(true); + break; + } + case SCREEN_FCS_MODIFICATION_MSG: + { + struct font_cache_info fontCacheInfo; + + get_font_cache_info(B_SCREEN_FONT_CACHE|B_DEFAULT_CACHE_SETTING, + &fontCacheInfo); + fontCacheInfo.cache_size = fScreenSlider->Value() << 10; + set_font_cache_info(B_SCREEN_FONT_CACHE|B_DEFAULT_CACHE_SETTING, + &fontCacheInfo); + + BString str("Screen font cache size : "); + str << fScreenSlider->Value() << " kB"; + fScreenSlider->SetLabel(str.String()); + + // TODO: set revert state +// buttonView->SetRevertState(true); + break; + } + default: + { + BView::MessageReceived(msg); + break; + } + } +} /** * Sets the sliders to their original values. */ void CacheView::revertToOriginal(){ - + // TODO: fix +/* BString label; label << "Screen " << kLabel << getScreenFCSValue(); updateScreenFCS(label.String()); @@ -132,20 +149,21 @@ void CacheView::revertToOriginal(){ label = "Printing "; label << kLabel << getPrintFCSValue(); updatePrintFCS(label.String()); - -}//revertToOriginal +*/ +} /** * Sets the sliders to their default values. */ void CacheView::resetToDefaults(){ - BString label; + // TODO: fix +/* BString label; label << "Screen " << kLabel << getScreenFCSValue() << " kB"; updateScreenFCS(label.String()); label = "Printing "; label << kLabel << getPrintFCSValue() << " kB"; updatePrintFCS(label.String()); - -}//revertToOriginal +*/ +} diff --git a/src/prefs/fonts/CacheView.h b/src/prefs/fonts/CacheView.h index 971279ef52..021c40882e 100644 --- a/src/prefs/fonts/CacheView.h +++ b/src/prefs/fonts/CacheView.h @@ -1,86 +1,37 @@ -/*! \file CacheView.h - * \brief Header file for the CacheView class. +/* + * Copyright 2001-2005, Haiku. + * Distributed under the terms of the MIT License. + * */ - #ifndef CACHE_VIEW_H +#define CACHE_VIEW_H + +#include +#include +#include +#include - #define CACHE_VIEW_H +class CacheView : public BView +{ +public: + CacheView(const BRect &frame, const int32 &sliderMin, + const int32 &sliderMax, const int32 &printVal, + const int32 &screenVal); + void AttachedToWindow(void); + void MessageReceived(BMessage *msg); - /*! - * Message sent when the print slider is updated. - */ - #define PRINT_FCS_UPDATE_MSG 'pfum' - - /*! - * Message sent when the screen slider is updated. - */ - #define SCREEN_FCS_UPDATE_MSG 'sfum' - - /*! - * Message sent when the print slider is modified. - */ - #define PRINT_FCS_MODIFICATION_MSG 'pfmm' - - /*! - * Message sent when the screen slider is modified. - */ - #define SCREEN_FCS_MODIFICATION_MSG 'sfmm' - - #ifndef _VIEW_H + void revertToOriginal(); + void resetToDefaults(); + +private: - #include - - #endif - - #ifndef _BOX_H - - #include - - #endif - #ifndef _SLIDER_H - - #include - - #endif - #ifndef _BUTTON_H - - #include - - #endif - - class CacheView : public BView{ - - public: + BSlider *fScreenSlider; + BSlider *fPrintSlider; + BButton *fSaveCache; - CacheView(BRect frame, int minVal, int maxVal, int32 printCurrVal, int32 screenCurrVal); - void updatePrintFCS(const char* txt); - void updateScreenFCS(const char* txt); - int getPrintFCSValue(); - int getScreenFCSValue(); - void revertToOriginal(); - void resetToDefaults(); - private: - - /** - * The screen cache slider. - */ - BSlider *screenFCS; - - /** - * The print cache slider. - */ - BSlider *printFCS; - - /** - * The original print slider value. - */ - int32 origPrintVal; - - /** - * The original screen slider value. - */ - int32 origScreenVal; - - }; + // The original slider values + int32 fSavedPrintValue; + int32 fSavedScreenValue; +}; #endif diff --git a/src/prefs/fonts/FontSelectionView.cpp b/src/prefs/fonts/FontSelectionView.cpp index 0199195f42..260948d45f 100644 --- a/src/prefs/fonts/FontSelectionView.cpp +++ b/src/prefs/fonts/FontSelectionView.cpp @@ -1,84 +1,67 @@ -/*! \file FontSelectionView.cpp - \brief Header for the FontSelectionView class. - -*/ - -#ifndef FONT_SELECTION_VIEW_H - - #include "FontSelectionView.h" - -#endif - +/* + * Copyright 2001-2005, Haiku. + * Distributed under the terms of the MIT License. + * + */ +#include "FontSelectionView.h" #include "Pref_Utils.h" +#define SIZE_CHANGED_MSG 'plsz' +#define FONT_CHANGED_MSG 'plfn' +#define STYLE_CHANGED_MSG 'plst' + // should be changed to allow larger and smaller -#define minSizeIndex 7 -#define maxSizeIndex 12 +#define minSizeIndex 9 +#define maxSizeIndex 14 // constants for labels const char *kPlainFont = "Plain font:"; -const char *kBoldFont = "Bold font:"; +const char *kBoldFont = "Bold font:"; const char *kFixedFont = "Fixed font:"; const char *kSize = "Size: "; -/** - * Constructor - * @param rect The size of the view. - * @param name The name of the view. - * @param type The type of the view: plain, italic, etc. - */ FontSelectionView::FontSelectionView(BRect rect, const char *name, int type) - : BView(rect, name, B_FOLLOW_ALL, B_WILL_DRAW) + : BView(rect, name, B_FOLLOW_ALL, B_WILL_DRAW) { - - switch(type){ - - case PLAIN_FONT_SELECTION_VIEW: - - sprintf(typeLabel, kPlainFont); - origFont = be_plain_font; - workingFont = be_plain_font; - setSizeChangedMessage = PLAIN_SIZE_CHANGED_MSG; - setFontChangedMessage = PLAIN_FONT_CHANGED_MSG; - setStyleChangedMessage = PLAIN_STYLE_CHANGED_MSG; - - defaultFont = new BFont(); - defaultFont->SetFamilyAndStyle("Swis721 BT", "Roman"); - defaultFont->SetSize(10.0); - - break; - + switch(type) + { case BOLD_FONT_SELECTION_VIEW: - + { sprintf(typeLabel, kBoldFont); origFont = be_bold_font; workingFont = be_bold_font; - setSizeChangedMessage = BOLD_SIZE_CHANGED_MSG; - setFontChangedMessage = BOLD_FONT_CHANGED_MSG; - setStyleChangedMessage = BOLD_STYLE_CHANGED_MSG; defaultFont = new BFont(); defaultFont->SetFamilyAndStyle("Swis721 BT", "Bold"); defaultFont->SetSize(12.0); break; - + } case FIXED_FONT_SELECTION_VIEW: - + { sprintf(typeLabel, kFixedFont); origFont = be_fixed_font; workingFont = be_fixed_font; - setSizeChangedMessage = FIXED_SIZE_CHANGED_MSG; - setFontChangedMessage = FIXED_FONT_CHANGED_MSG; - setStyleChangedMessage = FIXED_STYLE_CHANGED_MSG; defaultFont = new BFont(); defaultFont->SetFamilyAndStyle("Courier10 BT", "Roman"); defaultFont->SetSize(12.0); break; + } + default: + { + sprintf(typeLabel, kPlainFont); + origFont = be_plain_font; + workingFont = be_plain_font; - }//switch + defaultFont = new BFont(); + defaultFont->SetFamilyAndStyle("Swis721 BT", "Roman"); + defaultFont->SetSize(10.0); + + break; + } + } float fontheight = FontHeight(false); float divider = StringWidth(kFixedFont); @@ -87,7 +70,8 @@ FontSelectionView::FontSelectionView(BRect rect, const char *name, int type) fontList = new BPopUpMenu("fontList", true, true, B_ITEMS_IN_COLUMN); // create menus - // size box + + // size box rect = Bounds(); float x = StringWidth("999") +16; rect.left = rect.right -(x +StringWidth(kSize)+8.0); @@ -95,7 +79,8 @@ FontSelectionView::FontSelectionView(BRect rect, const char *name, int type) BMenuField *sizeListField = new BMenuField(rect, "fontField", kSize, sizeList, true); sizeListField->SetDivider(StringWidth(kSize)+5.0); sizeListField->SetAlignment(B_ALIGN_RIGHT); - // font menu + + // font menu rect.right = rect.left; rect.left = 1; rect.bottom = fontheight *1.5; @@ -130,152 +115,170 @@ FontSelectionView::FontSelectionView(BRect rect, const char *name, int type) } -/** - * Emptys the menu so it can be rebuilt. - * @param m The menu to empty. - */ -void FontSelectionView::emptyMenu(BPopUpMenu *m){ +FontSelectionView::~FontSelectionView(void) +{ + delete defaultFont; +} - int32 cnt; - int32 numItemsInMenu = m->CountItems(); - - for(cnt = 0;cnt < numItemsInMenu;cnt++){ - - BMenu *tmp; - BMenuItem *tmpI; - int32 cnt2; - int32 numItemsInSubmenu; +void +FontSelectionView::AttachedToWindow(void) +{ +} + +void +FontSelectionView::MessageReceived(BMessage *msg) +{ + switch(msg->what) + { +/* case SIZE_CHANGED_MSG: { - tmpI = m->RemoveItem((int32) 0); - tmp = tmpI->Submenu(); + updateSize(fSelectorView->plainSelectionView); + fButtonView->SetRevertState(true); + break; + } + case FONT_CHANGED_MSG: { - if(tmp != NULL){ + updateFont(fSelectorView->plainSelectionView); + fButtonView->SetRevertState(true); + break; + } + case STYLE_CHANGED_MSG: { - numItemsInSubmenu = tmp->CountItems(); - for(cnt2 = 0;cnt2 < numItemsInSubmenu;cnt2++){ - - BMenuItem *tmpItem; - - tmpItem = tmp->RemoveItem((int32) 0); - delete tmpItem; - - }//for + updateStyle(fSelectorView->plainSelectionView); + fButtonView->SetRevertState(true); + break; + } + case RESCAN_FONTS_MSG: { - }//if + update_font_families(false); + fSelectorView->emptyMenus(); + fSelectorView->buildMenus(); + updateFont(fSelectorView->plainSelectionView); + updateFont(fSelectorView->boldSelectionView); + updateFont(fSelectorView->fixedSelectionView); + break; + } + case RESET_FONTS_MSG: { - delete tmpI; + fSelectorView->resetToDefaults(); + fCacheView->resetToDefaults(); + fButtonView->SetRevertState(true); + break; + } +*/ default: + BView::MessageReceived(msg); + } +} + +void FontSelectionView::emptyMenus(void) +{ + // Empty the font list + for(int32 i = 0; i < fontList->CountItems(); i++) + { + BMenu *menu = fontList->SubmenuAt(0L); + + // We should never have a regular menu item in the font list + if(!menu) + continue; + + for(int32 j=0; j < menu->CountItems(); j++) + { + BMenuItem *item = menu->RemoveItem(0L); + delete item; + } + + fontList->RemoveItem(menu); + delete menu; + } - }//for - -}//emptyMenu - -/** - * Emptys both the font and the size menus. - */ -void FontSelectionView::emptyMenus(){ - - //empty font menu - emptyMenu(fontList); - - //empty size menu - emptyMenu(sizeList); - -}//emptyMenus - -/** - * Builds the font and size menus. - */ -void FontSelectionView::buildMenus(){ + // empty the size list + for(int32 i = 0; i < sizeList->CountItems(); i++) + { + BMenuItem *item = sizeList->RemoveItem(0L); + delete item; + } +} +void FontSelectionView::buildMenus(void) +{ int32 numFamilies; int counter; numFamilies = count_font_families(); - for ( int32 i = 0; i < numFamilies; i++ ) { - + for ( int32 i = 0; i < numFamilies; i++ ) + { font_family family; - uint32 flags; - if ( get_font_family(i, &family, &flags) == B_OK ) { + uint32 flags; + int32 numStyles; + + BMenu *tmpStyleMenu; + bool markFamily; + + if ( get_font_family(i, &family, &flags) != B_OK ) + continue; + + + markFamily = false; + + tmpStyleMenu = new BMenu(family); + tmpStyleMenu->SetRadioMode(true); + numStyles = count_font_styles(family); + + for ( int32 j = 0; j < numStyles; j++ ) + { + font_style style; + BMenuItem *tmpItem; - BMenu *tmpStyleMenu; - int32 numStyles; - bool markFamily; + char workingStyle[64]; + char workingFamily[64]; - markFamily = false; + if (get_font_style(family, j, &style, &flags) != B_OK) + continue; - tmpStyleMenu = new BMenu(family); - tmpStyleMenu->SetRadioMode(true); - numStyles = count_font_styles(family); - for ( int32 j = 0; j < numStyles; j++ ) { - - font_style style; - if ( get_font_style(family, j, &style, &flags) == B_OK ) { - - BMenuItem *tmpItem; - char workingStyle[64]; - char workingFamily[64]; - - workingFont.GetFamilyAndStyle(&workingFamily, &workingStyle); - tmpItem = new BMenuItem(style, new BMessage(setStyleChangedMessage)); - if((strcmp(style, workingStyle) == 0) && (strcmp(family, workingFamily) == 0)){ - - markFamily = true; - tmpItem->SetMarked(true); - - }//if - - tmpStyleMenu->AddItem(tmpItem); - - }//if - }//for + workingFont.GetFamilyAndStyle(&workingFamily, &workingStyle); + tmpItem = new BMenuItem(style, new BMessage(STYLE_CHANGED_MSG)); - fontList->AddItem(new BMenuItem((tmpStyleMenu), new BMessage(setFontChangedMessage))); - - if(markFamily){ - - tmpStyleMenu->Superitem()->SetMarked(true); - - }//if - - }//if - - }//for - - //build size menu - for(counter = minSizeIndex;counter < (maxSizeIndex + 1);counter++){ + if((strcmp(style, workingStyle) == 0) && (strcmp(family, workingFamily) == 0)) + { + markFamily = true; + tmpItem->SetMarked(true); + } + tmpStyleMenu->AddItem(tmpItem); + } + + fontList->AddItem(new BMenuItem((tmpStyleMenu), new BMessage(FONT_CHANGED_MSG))); + + if(markFamily) + tmpStyleMenu->Superitem()->SetMarked(true); + } + // build size menu + for(counter = minSizeIndex; counter < (maxSizeIndex + 1); counter++) + { char buf[1]; BMenuItem *tmp; sprintf(buf, "%d", counter); - sizeList->AddItem(tmp = new BMenuItem(buf, new BMessage(setSizeChangedMessage))); - if(counter == (int) workingFont.Size()){ - + sizeList->AddItem(tmp = new BMenuItem(buf, new BMessage(SIZE_CHANGED_MSG))); + if(counter == (int) workingFont.Size()) tmp->SetMarked(true); - - }//if - - }//for - -}//buildMenus + } +} /** * Writes the test text in the given font. * @param fnt The font to write the test text in. */ -void FontSelectionView::SetTestTextFont(BFont *fnt){ - +void FontSelectionView::SetTestTextFont(BFont *fnt) +{ testText->SetFont(fnt, B_FONT_ALL); testText->Invalidate(); - -}//SetTextTextFont +} -/** - * Gets the current font. - */ -BFont FontSelectionView::GetTestTextFont(){ +BFont FontSelectionView::GetTestTextFont() +{ BFont rtrnFont; @@ -283,94 +286,66 @@ BFont FontSelectionView::GetTestTextFont(){ return rtrnFont; -}//SetTextTextFont - -/** - * Gets the selected size. - */ -float FontSelectionView::GetSelectedSize(){ +} +float +FontSelectionView::GetSelectedSize() +{ return minSizeIndex + sizeList->IndexOf(sizeList->FindMarked()); -}//GetSelectedSize - -/** - * Gets the selected font_family. - * @param family The selected font_family. - */ -void FontSelectionView::GetSelectedFont(font_family *family){ +} +void FontSelectionView::GetSelectedFont(font_family *family) +{ int numFamilies = count_font_families(); - for ( int32 i = 0; i < numFamilies; i++ ) { - + for ( int32 i = 0; i < numFamilies; i++ ) + { font_family fam; uint32 flags; - if ( get_font_family(i, &fam, &flags) == B_OK ) { - - if(strcmp(fam, fontList->FindMarked()->Label()) == 0){ - + if ( get_font_family(i, &fam, &flags) == B_OK ) + { + if(strcmp(fam, fontList->FindMarked()->Label()) == 0) get_font_family(i, family, &flags); - - }//if - - }//if - - }//for - -}//GetSelectedFont - -/** - * Gets the selected style. - * @param style The selected style. - */ -void FontSelectionView::GetSelectedStyle(font_style *style){ + } + } +} +void FontSelectionView::GetSelectedStyle(font_style *style) +{ int numFamilies = count_font_families(); font_family curr; GetSelectedFont(&curr); - for ( int32 i = 0; i < numFamilies; i++ ) { - + for ( int32 i = 0; i < numFamilies; i++ ) + { font_family fam; uint32 flags; - if ( get_font_family(i, &fam, &flags) == B_OK ) { - - if(strcmp(fam, curr) == 0){ - - int32 numStyles = count_font_styles(fam); - for ( int32 j = 0; j < numStyles; j++ ) { - - font_style sty; - if ( get_font_style(fam, j, &sty, &flags) == B_OK ) { - - if(strcmp(sty, fontList->FindMarked()->Submenu()->FindMarked()->Label()) == 0){ - - get_font_style(fam, j, style, &flags); - - }//if - - }//if - - }//for - - }//if - - }//if - - }//for - -}//GetSelectedStyle + if (get_font_family(i, &fam, &flags) == B_OK && strcmp(fam, curr) == 0 ) + { + int32 numStyles = count_font_styles(fam); + for ( int32 j = 0; j < numStyles; j++ ) + { + font_style sty; + if ( get_font_style(fam, j, &sty, &flags) == B_OK ) + { + if(strcmp(sty, fontList->FindMarked()->Submenu()->FindMarked()->Label()) == 0) + get_font_style(fam, j, style, &flags); + } + } + } + } +} /** * If a style is selected, this function is called to update the font menu, * in case the selected style is from a non selected font. It also marks the * selected style, and unmarks all other styles. */ -void FontSelectionView::UpdateFontSelectionFromStyle(){ - +void FontSelectionView::UpdateFontSelectionFromStyle() +{ int i = 0; for(i = 0;i < fontList->CountItems();i++){ @@ -393,38 +368,28 @@ void FontSelectionView::UpdateFontSelectionFromStyle(){ }//for }//for - -}//UpdateFontSelection +} /** * Updates the font menu based on the user selection. */ -void FontSelectionView::UpdateFontSelection(){ - - int i = 0; - - for(i = 0;i < fontList->CountItems();i++){ - - int j = 0; - - for(j = 0;j < fontList->ItemAt(i)->Submenu()->CountItems();j++){ - - if(fontList->ItemAt(i)->Submenu()->ItemAt(j)->IsMarked()){ - - if(strcmp(fontList->ItemAt(i)->Label(), fontList->FindMarked()->Label()) > 0){ - +void FontSelectionView::UpdateFontSelection() +{ + for(int32 i = 0; i < fontList->CountItems();i++) + { + for(int32 j = 0;j < fontList->ItemAt(i)->Submenu()->CountItems();j++) + { + if(fontList->ItemAt(i)->Submenu()->ItemAt(j)->IsMarked()) + { + if(strcmp(fontList->ItemAt(i)->Label(), fontList->FindMarked()->Label()) > 0) + { fontList->ItemAt(i)->Submenu()->FindMarked()->SetMarked(false); fontList->FindMarked()->Submenu()->ItemAt(0)->SetMarked(true); - - }//if - - }//if - - }//for - - }//for - -}//UpdateFontSelection + } + } + } + } +} /** * Updates the font and size menus based on the given font. diff --git a/src/prefs/fonts/FontSelectionView.h b/src/prefs/fonts/FontSelectionView.h index 0c0fba462d..f5bb729738 100644 --- a/src/prefs/fonts/FontSelectionView.h +++ b/src/prefs/fonts/FontSelectionView.h @@ -1,187 +1,64 @@ -/*! \file FontSelectionView.h - \brief Header for the FontSelectionView class. - -*/ - +/* + * Copyright 2001-2005, Haiku. + * Distributed under the terms of the MIT License. + * + */ #ifndef FONT_SELECTION_VIEW_H +#define FONT_SELECTION_VIEW_H + +#include +#include +#include +#include +#include +#include +#include - #define FONT_SELECTION_VIEW_H +enum +{ + PLAIN_FONT_SELECTION_VIEW=1, + BOLD_FONT_SELECTION_VIEW, + FIXED_FONT_SELECTION_VIEW +}; - /*! - * Constant to define that the view is a plain view. - */ - #define PLAIN_FONT_SELECTION_VIEW 1 - /*! - * Constant to define that the view is a bold view. - */ - #define BOLD_FONT_SELECTION_VIEW 2 - /*! - * Constant to define that the view is a fixed view. - */ - #define FIXED_FONT_SELECTION_VIEW 3 - - /*! - * The plain size menu was changed. - */ - #define PLAIN_SIZE_CHANGED_MSG 'plsz' - /*! - * The bold size menu was changed. - */ - #define BOLD_SIZE_CHANGED_MSG 'blsz' - /*! - * The fixed size menu was changed. - */ - #define FIXED_SIZE_CHANGED_MSG 'fxsz' - - /*! - * The plain font menu was changed. - */ - #define PLAIN_FONT_CHANGED_MSG 'plfn' - /*! - * The bold font menu was changed. - */ - #define BOLD_FONT_CHANGED_MSG 'blfn' - /*! - * The fixed font menu was changed. - */ - #define FIXED_FONT_CHANGED_MSG 'fxfn' - - /*! - * The plain style menu was changed. - */ - #define PLAIN_STYLE_CHANGED_MSG 'plst' - /*! - * The bold style menu was changed. - */ - #define BOLD_STYLE_CHANGED_MSG 'blst' - /*! - * The fixed style menu was changed. - */ - #define FIXED_STYLE_CHANGED_MSG 'fxst' - - #ifndef _VIEW_H - - #include - - #endif - - #ifndef _BOX_H - - #include - - #endif - - #ifndef _STRING_VIEW_H - - #include - - #endif - - #ifndef _POP_UP_MENU_H - - #include - - #endif - - #ifndef _MENU_FIELD_H - - #include - - #endif - - #ifndef _MENU_ITEM_H - - #include - - #endif - #ifndef _STDIO_H - - #include - - #endif - - class FontSelectionView : public BView{ - - public: - +class FontSelectionView : public BView +{ +public: FontSelectionView(BRect rect, const char *name, int type); - void SetTestTextFont(BFont *fnt); - BFont GetTestTextFont(); - float GetSelectedSize(); - void GetSelectedFont(font_family *family); - void GetSelectedStyle(font_style *style); - void UpdateFontSelectionFromStyle(); - void UpdateFontSelection(); - void buildMenus(); - void emptyMenus(); - void resetToDefaults(); - void revertToOriginal(); - private: - - /** - * The test text display view. - */ - BStringView *testText; - - /** - * The font menu. - */ - BPopUpMenu *fontList; - - /** - * The size menu. - */ - BPopUpMenu *sizeList; - - /** - * The minimum font size allowed. - */ - int minSizeIndex; - - /** - * The maximum font size allowed. - */ - int maxSizeIndex; - - /** - * The message sent when the size menu is changed. - */ - uint32 setSizeChangedMessage; - - /** - * The message sent when the font menu is changed. - */ - uint32 setFontChangedMessage; - - /** - * The message sent when the style menu is changed. - */ - uint32 setStyleChangedMessage; - - /** - * The label that shows what type the view is. - */ - char typeLabel[30]; - - /** - * The original font, set when the view is instantiated. - */ - BFont origFont; - - /** - * The current font. - */ - BFont workingFont; - - /** - * The default font. - */ - BFont *defaultFont; - - void emptyMenu(BPopUpMenu *m); - void UpdateFontSelection(BFont *fnt); - + ~FontSelectionView(void); + void AttachedToWindow(void); + void MessageReceived(BMessage *msg); - }; + void SetTestTextFont(BFont *fnt); + BFont GetTestTextFont(); + float GetSelectedSize(); + void GetSelectedFont(font_family *family); + void GetSelectedStyle(font_style *style); + void UpdateFontSelectionFromStyle(); + void UpdateFontSelection(); + void resetToDefaults(); + void revertToOriginal(); + +private: + void buildMenus(void); + void emptyMenus(void); + + void EmptyMenu(BPopUpMenu *m); + void UpdateFontSelection(BFont *fnt); + + BStringView *testText; + + BPopUpMenu *fontList; + BPopUpMenu *sizeList; + + int minSizeIndex; + int maxSizeIndex; + + char typeLabel[30]; + + BFont origFont; + BFont workingFont; + BFont *defaultFont; +}; #endif diff --git a/src/prefs/fonts/FontView.cpp b/src/prefs/fonts/FontView.cpp index 730129c4b5..be7294fef0 100644 --- a/src/prefs/fonts/FontView.cpp +++ b/src/prefs/fonts/FontView.cpp @@ -1,95 +1,62 @@ -/*! \file FontView.cpp - \brief Header for the FontView class. - -*/ - -#ifndef FONT_VIEW_H - - #include "FontView.h" - -#endif - +/* + * Copyright 2001-2005, Haiku. + * Distributed under the terms of the MIT License. + * + */ +#include "FontView.h" #include "Pref_Utils.h" -/** - * Constructor. - * @param rect The size of the view. - */ FontView::FontView(BRect rect) - :BView(rect, "FontView", B_FOLLOW_ALL, B_WILL_DRAW) + : BView(rect, "Fonts", B_FOLLOW_ALL, B_WILL_DRAW) { - BRect bounds(Bounds().InsetByCopy(5, 5)); - - BRect rect(bounds); - rect.bottom = rect.top +FontHeight(true) *3.5; - plainSelectionView = new FontSelectionView(rect, "Plain", PLAIN_FONT_SELECTION_VIEW); - rect.OffsetBy(0, rect.Height()+4); - boldSelectionView = new FontSelectionView(rect, "Bold", BOLD_FONT_SELECTION_VIEW); - rect.OffsetBy(0, rect.Height()+4); - fixedSelectionView = new FontSelectionView(rect, "Fixed", FIXED_FONT_SELECTION_VIEW); - - AddChild(plainSelectionView); - AddChild(boldSelectionView); - AddChild(fixedSelectionView); + SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR)); + BRect bounds( Bounds().InsetByCopy(5, 5) ); + BRect rect(bounds); + + rect.bottom = rect.top + FontHeight(true) *3.5; + plainSelectionView = new FontSelectionView(rect, "Plain", + PLAIN_FONT_SELECTION_VIEW); + AddChild(plainSelectionView); + + rect.OffsetBy(0, rect.Height() + 4); + boldSelectionView = new FontSelectionView(rect, "Bold", + BOLD_FONT_SELECTION_VIEW); + AddChild(boldSelectionView); + + rect.OffsetBy(0, rect.Height() + 4); + fixedSelectionView = new FontSelectionView(rect, "Fixed", + FIXED_FONT_SELECTION_VIEW); + AddChild(fixedSelectionView); } void FontView::AttachedToWindow(void) { - if (Parent() != NULL) - SetViewColor(Parent()->ViewColor()); - else - SetViewColor(219, 219, 219, 255); } - -/** - * Calls each FontSelectionView's buildMenus() function to build the - * font and size menus. - */ -void FontView::buildMenus(){ - - plainSelectionView->buildMenus(); - boldSelectionView->buildMenus(); - fixedSelectionView->buildMenus(); - -}//buildMenus - -/** - * Calls each FontSelectionView's emptyMenus() function to clear the - * font and size menus. - */ -void FontView::emptyMenus(){ - - plainSelectionView->emptyMenus(); - boldSelectionView->emptyMenus(); - fixedSelectionView->emptyMenus(); - -}//buildMenus - /** * Calls each FontSelectionView's resetToDefaults() function to reset * the font and size menus to the default font. */ -void FontView::resetToDefaults(){ - +void +FontView::resetToDefaults() +{ plainSelectionView->resetToDefaults(); boldSelectionView->resetToDefaults(); fixedSelectionView->resetToDefaults(); - -}//resetToDefaults +} /** * Calls each FontSelectionView's revertToOriginal() function to reset * the font and size menus to the original font. */ -void FontView::revertToOriginal(){ - +void +FontView::revertToOriginal() +{ plainSelectionView->revertToOriginal(); boldSelectionView->revertToOriginal(); fixedSelectionView->revertToOriginal(); - -}//resetToDefaults +} diff --git a/src/prefs/fonts/FontView.h b/src/prefs/fonts/FontView.h index 5f10a08f41..785dd1a9c3 100644 --- a/src/prefs/fonts/FontView.h +++ b/src/prefs/fonts/FontView.h @@ -1,42 +1,27 @@ -/*! \file FontView.h - \brief Header for the FontView class. - -*/ - +/* + * Copyright 2001-2005, Haiku. + * Distributed under the terms of the MIT License. + * + */ #ifndef FONT_VIEW_H +#define FONT_VIEW_H - #define FONT_VIEW_H - - #ifndef _VIEW_H - - #include - - #endif - - #ifndef FONT_SELECTION_VIEW_H - - #include "FontSelectionView.h" - - #endif - - #ifndef _BOX_H - - #include - - #endif - - class FontView : public BView{ - - public: +#include +#include +#include "FontSelectionView.h" + +class FontView : public BView +{ +public: FontView(BRect frame); - void AttachedToWindow(void); - FontSelectionView *plainSelectionView; - FontSelectionView *boldSelectionView; - FontSelectionView *fixedSelectionView; - void buildMenus(); - void emptyMenus(); - void resetToDefaults(); - void revertToOriginal(); - }; + void AttachedToWindow(void); + + void resetToDefaults(); + void revertToOriginal(); + + FontSelectionView *plainSelectionView; + FontSelectionView *boldSelectionView; + FontSelectionView *fixedSelectionView; +}; #endif diff --git a/src/prefs/fonts/FontsSettings.cpp b/src/prefs/fonts/FontsSettings.cpp index 7f1d7be31b..3dc4786470 100644 --- a/src/prefs/fonts/FontsSettings.cpp +++ b/src/prefs/fonts/FontsSettings.cpp @@ -1,36 +1,38 @@ /* - FontsSettings.cpp -*/ - + * Copyright 2001-2005, Haiku. + * Distributed under the terms of the MIT License. + * + */ #include #include #include #include +#include #include #include +#include #include "FontsSettings.h" -const char FontsSettings::kSettingsFile[] = "Font_Settings"; -const BPoint kDEFAULT = BPoint(100, 100); +static const char kSettingsFile[] = "Font_Settings"; FontsSettings::FontsSettings() { BPath path; + BMessage msg; + if (find_directory(B_USER_SETTINGS_DIRECTORY, &path) == B_OK) { path.Append(kSettingsFile); BFile file(path.Path(), B_READ_ONLY); - if (file.InitCheck() == B_OK) { - float x, y; - if (file.Read(&x, sizeof(float)) != sizeof(float)) { - x = kDEFAULT.x; - } - if (file.Read(&y, sizeof(float)) != sizeof(float)) { - y = kDEFAULT.y; - } - f_corner = BPoint(x, y); - } else { - f_corner = kDEFAULT; + + if (file.InitCheck() != B_OK) + SetDefaults(); + else + if (msg.Unflatten(&file) != B_OK) + SetDefaults(); + else + { + msg.FindPoint("windowlocation",&fCorner); } } } @@ -38,15 +40,32 @@ FontsSettings::FontsSettings() FontsSettings::~FontsSettings() { BPath path; + BMessage msg; + if (find_directory(B_USER_SETTINGS_DIRECTORY, &path) < B_OK) return; + path.Append(kSettingsFile); BFile file(path.Path(), B_WRITE_ONLY|B_CREATE_FILE); + if (file.InitCheck() == B_OK) { - float x = f_corner.x; - float y = f_corner.y; - file.Write(&x, sizeof(float)); - file.Write(&y, sizeof(float)); + msg.AddPoint("windowlocation",fCorner); + + // We need to add this to the settings file so that the app_server + // can get the font cache info on startup. This is the only + // place in the Fonts app that we actually need to do this because + // any other changes made are made through the API + struct font_cache_info cacheInfo; + + get_font_cache_info(B_SCREEN_FONT_CACHE|B_DEFAULT_CACHE_SETTING, + &cacheInfo); + msg.AddInt32("screencachesize",cacheInfo.cache_size); + + get_font_cache_info(B_PRINTING_FONT_CACHE|B_DEFAULT_CACHE_SETTING, + &cacheInfo); + msg.AddInt32("printcachesize",cacheInfo.cache_size); + + msg.Flatten(&file); } } @@ -54,5 +73,12 @@ FontsSettings::~FontsSettings() void FontsSettings::SetWindowCorner(BPoint where) { - f_corner = where; + fCorner = where; } + +void +FontsSettings::SetDefaults(void) +{ + fCorner.Set(100,100); +} + diff --git a/src/prefs/fonts/FontsSettings.h b/src/prefs/fonts/FontsSettings.h index 7c5e1eca51..8d61ce39ee 100644 --- a/src/prefs/fonts/FontsSettings.h +++ b/src/prefs/fonts/FontsSettings.h @@ -1,16 +1,24 @@ +/* + * Copyright 2001-2005, Haiku. + * Distributed under the terms of the MIT License. + * + */ #ifndef FONTS_SETTINGS_H #define FONTS_SETTINGS_H -class FontsSettings { - public: - FontsSettings(void); - ~FontsSettings(void); +class FontsSettings +{ +public: + FontsSettings(void); + ~FontsSettings(void); - BPoint WindowCorner(void) const { return f_corner; } - void SetWindowCorner(BPoint); - private: - static const char kSettingsFile[]; - BPoint f_corner; + BPoint WindowCorner(void) const { return fCorner; } + void SetWindowCorner(BPoint); + + void SetDefaults(void); + +private: + BPoint fCorner; }; #endif //FONTS_SETTINGS_H diff --git a/src/prefs/fonts/MainWindow.cpp b/src/prefs/fonts/MainWindow.cpp index 9982517fd1..fba69f1e8b 100644 --- a/src/prefs/fonts/MainWindow.cpp +++ b/src/prefs/fonts/MainWindow.cpp @@ -1,214 +1,175 @@ -/*! \file MainWindow.cpp - * \brief Code for the main window. +/* + * Copyright 2001-2005, Haiku. + * Distributed under the terms of the MIT License. * - * Displays the main window. - * -*/ - -#ifndef MAIN_WINDOW_H - - #include "MainWindow.h" - -#endif - -/** - * Constructor. - * @param frame The size to make the window. */ -MainWindow::MainWindow(BRect frame) - :BWindow(frame, "Fonts", B_TITLED_WINDOW, B_NOT_RESIZABLE | B_ASYNCHRONOUS_CONTROLS | B_NOT_ZOOMABLE ){ - +#include "MainWindow.h" + +MainWindow::MainWindow(void) + : BWindow( BRect(100,80,445,343) , "Fonts", B_TITLED_WINDOW, B_NOT_RESIZABLE | + B_ASYNCHRONOUS_CONTROLS | B_NOT_ZOOMABLE ) +{ BRect r; BTabView *tabView; - BTab *tab; BBox *topLevelView; double buttonViewHeight = 43.0; + struct font_cache_info cacheInfo; + int32 screenCacheSize, printCacheSize; + + get_font_cache_info(B_SCREEN_FONT_CACHE|B_DEFAULT_CACHE_SETTING, &cacheInfo); + screenCacheSize = cacheInfo.cache_size >> 10; + + get_font_cache_info(B_PRINTING_FONT_CACHE|B_DEFAULT_CACHE_SETTING, &cacheInfo); + printCacheSize = cacheInfo.cache_size >> 10; + r = Bounds(); r.top += 10; r.bottom -= buttonViewHeight+1; - tabView = new BTabView(r, "tab_view", B_WIDTH_FROM_LABEL); - tabView->SetViewColor(216,216,216,0); + tabView = new BTabView(r, "tabview", B_WIDTH_FROM_LABEL); + tabView->SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR)); r = tabView->Bounds(); r.InsetBy(5, 5); r.bottom -= tabView->TabHeight(); r.right -=2; - tab = new BTab(); - tabView->AddTab(fontPanel = new FontView(r), tab); - tab->SetLabel(" Fonts "); - tab = new BTab(); - tabView->AddTab(cachePanel = new CacheView(r, 64, 4096, (int32) 256, (int32) 256), tab); - tab->SetLabel("Cache"); - + + fSelectorView = new FontView(r); + tabView->AddTab(fSelectorView); + + fCacheView = new CacheView(r, 64, 4096, printCacheSize, screenCacheSize); + tabView->AddTab(fCacheView); + r = Bounds(); r.top = r.bottom - buttonViewHeight; - buttonView = new ButtonView(r); + fButtonView = new ButtonView(r); topLevelView = new BBox(Bounds(), "TopLevelView", B_FOLLOW_ALL, B_WILL_DRAW, B_NO_BORDER); AddChild(topLevelView); - topLevelView->AddChild(buttonView); + topLevelView->AddChild(fButtonView); topLevelView->AddChild(tabView); + MoveTo(fSettings.WindowCorner()); } -/** - * Runs when the user quits the application. - */ -bool MainWindow::QuitRequested() +bool +MainWindow::QuitRequested(void) { - BMessage *message = new BMessage(B_QUIT_REQUESTED); - message->AddPoint("corner", Frame().LeftTop()); - be_app->PostMessage(message); + fSettings.SetWindowCorner(Frame().LeftTop()); + + be_app->PostMessage(B_QUIT_REQUESTED); return true; } -/** - * Handles messages sent to the class. - * @param message The message to be handled. - */ -void MainWindow::MessageReceived(BMessage *message){ - - char msg[100]; +void +MainWindow::MessageReceived(BMessage *message) +{ + switch(message->what) { - switch(message->what){ - - case PLAIN_SIZE_CHANGED_MSG: +/* case PLAIN_SIZE_CHANGED_MSG: { - updateSize(fontPanel->plainSelectionView); - buttonView->SetRevertState(true); + updateSize(fSelectorView->plainSelectionView); + fButtonView->SetRevertState(true); break; + } + case BOLD_SIZE_CHANGED_MSG: { - case BOLD_SIZE_CHANGED_MSG: - - updateSize(fontPanel->boldSelectionView); - buttonView->SetRevertState(true); + updateSize(fSelectorView->boldSelectionView); + fButtonView->SetRevertState(true); break; + } + case FIXED_SIZE_CHANGED_MSG: { - case FIXED_SIZE_CHANGED_MSG: - - updateSize(fontPanel->fixedSelectionView); - buttonView->SetRevertState(true); + updateSize(fSelectorView->fixedSelectionView); + fButtonView->SetRevertState(true); break; + } + case PLAIN_FONT_CHANGED_MSG: { - case PLAIN_FONT_CHANGED_MSG: - - updateFont(fontPanel->plainSelectionView); - buttonView->SetRevertState(true); + updateFont(fSelectorView->plainSelectionView); + fButtonView->SetRevertState(true); break; + } + case BOLD_FONT_CHANGED_MSG: { - case BOLD_FONT_CHANGED_MSG: - - updateFont(fontPanel->boldSelectionView); - buttonView->SetRevertState(true); + updateFont(fSelectorView->boldSelectionView); + fButtonView->SetRevertState(true); break; + } + case FIXED_FONT_CHANGED_MSG: { - case FIXED_FONT_CHANGED_MSG: - - updateFont(fontPanel->fixedSelectionView); - buttonView->SetRevertState(true); + updateFont(fSelectorView->fixedSelectionView); + fButtonView->SetRevertState(true); break; - - case PLAIN_STYLE_CHANGED_MSG: + } + case PLAIN_STYLE_CHANGED_MSG: { - updateStyle(fontPanel->plainSelectionView); - buttonView->SetRevertState(true); + updateStyle(fSelectorView->plainSelectionView); + fButtonView->SetRevertState(true); break; + } + case BOLD_STYLE_CHANGED_MSG: { - case BOLD_STYLE_CHANGED_MSG: - - updateStyle(fontPanel->boldSelectionView); - buttonView->SetRevertState(true); + updateStyle(fSelectorView->boldSelectionView); + fButtonView->SetRevertState(true); break; + } + case FIXED_STYLE_CHANGED_MSG: { - case FIXED_STYLE_CHANGED_MSG: - - updateStyle(fontPanel->fixedSelectionView); - buttonView->SetRevertState(true); + updateStyle(fSelectorView->fixedSelectionView); + fButtonView->SetRevertState(true); break; - - case RESCAN_FONTS_MSG: + } + case RESCAN_FONTS_MSG: { update_font_families(false); - fontPanel->emptyMenus(); - fontPanel->buildMenus(); - updateFont(fontPanel->plainSelectionView); - updateFont(fontPanel->boldSelectionView); - updateFont(fontPanel->fixedSelectionView); + fSelectorView->emptyMenus(); + fSelectorView->buildMenus(); + updateFont(fSelectorView->plainSelectionView); + updateFont(fSelectorView->boldSelectionView); + updateFont(fSelectorView->fixedSelectionView); break; - - case RESET_FONTS_MSG: + } + case RESET_FONTS_MSG: { - fontPanel->resetToDefaults(); - cachePanel->resetToDefaults(); - buttonView->SetRevertState(true); + fSelectorView->resetToDefaults(); + fCacheView->resetToDefaults(); + fButtonView->SetRevertState(true); break; - - case REVERT_MSG: + } +*/ case REVERT_MSG: { - fontPanel->revertToOriginal(); - cachePanel->revertToOriginal(); - buttonView->SetRevertState(false); + fSelectorView->revertToOriginal(); + fCacheView->revertToOriginal(); + fButtonView->SetRevertState(false); break; - - case PRINT_FCS_UPDATE_MSG: - - printf("print update message\n"); - //buttonView->SetRevertState(true); - break; - - case PRINT_FCS_MODIFICATION_MSG: - - sprintf(msg, "Printing font cache size : %d kB", cachePanel->getPrintFCSValue()); - cachePanel->updatePrintFCS(msg); - buttonView->SetRevertState(true); - break; - - case SCREEN_FCS_UPDATE_MSG: - - printf("screen update message\n"); - //buttonView->SetRevertState(true); - buttonView->SetRevertState(true); - break; - - case SCREEN_FCS_MODIFICATION_MSG: - - sprintf(msg, "Screen font cache size : %d kB", cachePanel->getScreenFCSValue()); - cachePanel->updateScreenFCS(msg); - buttonView->SetRevertState(true); - break; - - default: - + } + default: { BWindow::MessageReceived(message); - + break; + } } } -/** - * Sets the size of the test text when a new size is picked. - * @param theView The FontSelectionView that is affected. - */ -void MainWindow::updateSize(FontSelectionView *theView){ - +// Sets the size of the test text when a new size is picked. +void +MainWindow::updateSize(FontSelectionView *theView) +{ BFont workingFont; workingFont = theView->GetTestTextFont(); workingFont.SetSize(theView->GetSelectedSize()); theView->SetTestTextFont(&workingFont); - -}//updateSize - -/** - * Updates the test text to the selected font. - * @param theView The FontSelectionView that is affected. - */ -void MainWindow::updateFont(FontSelectionView *theView){ +} +// Updates the test text to the selected font. +void +MainWindow::updateFont(FontSelectionView *theView) +{ BFont workingFont; font_family updateTo; @@ -217,15 +178,12 @@ void MainWindow::updateFont(FontSelectionView *theView){ theView->GetSelectedFont(&updateTo); workingFont.SetFamilyAndStyle(updateTo, NULL); theView->SetTestTextFont(&workingFont); - -}//updateFont - -/** - * Updates the test text to the selected style. - * @param theView The FontSelectionView that is affected. - */ -void MainWindow::updateStyle(FontSelectionView *theView){ +} +// Updates the test text to the selected style. +void +MainWindow::updateStyle(FontSelectionView *theView) +{ BFont workingFont; font_style updateTo; font_family update; @@ -236,5 +194,5 @@ void MainWindow::updateStyle(FontSelectionView *theView){ theView->GetSelectedFont(&update); workingFont.SetFamilyAndStyle(update, updateTo); theView->SetTestTextFont(&workingFont); +} -}//updateStyle diff --git a/src/prefs/fonts/MainWindow.h b/src/prefs/fonts/MainWindow.h index ce327a0e7b..1bd61dce63 100644 --- a/src/prefs/fonts/MainWindow.h +++ b/src/prefs/fonts/MainWindow.h @@ -1,82 +1,40 @@ -/*! \file MainWindow.h - \brief Header for the MainWindow class. - -*/ - +/* + * Copyright 2001-2005, Haiku. + * Distributed under the terms of the MIT License. + * + */ #ifndef MAIN_WINDOW_H +#define MAIN_WINDOW_H - #define MAIN_WINDOW_H +#include +#include +#include +#include - #ifndef _APPLICATION_H +#include "FontView.h" +#include "CacheView.h" +#include "ButtonView.h" +#include "FontsSettings.h" - #include - - #endif - #ifndef _WINDOW_H +class MainWindow : public BWindow +{ +public: + MainWindow(void); + virtual bool QuitRequested(void); + virtual void MessageReceived(BMessage *message); - #include - - #endif - #ifndef _TAB_VIEW_H +private: - #include - - #endif - - #ifndef FONT_VIEW_H + void updateSize(FontSelectionView *theView); + void updateFont(FontSelectionView *theView); + void updateStyle(FontSelectionView *theView); - #include "FontView.h" - - #endif + FontView *fSelectorView; + ButtonView *fButtonView; + CacheView *fCacheView; - #ifndef CACHE_VIEW_H - - #include "CacheView.h" - - #endif - - #ifndef BUTTON_VIEW_H - - #include "ButtonView.h" - - #endif - - #ifndef _BOX_H - - #include - - #endif - - class MainWindow : public BWindow{ - - public: - - MainWindow(BRect frame); - virtual bool QuitRequested(); - virtual void MessageReceived(BMessage *message); - - private: - - /** - * The panel that shows the font selection views. - */ - FontView *fontPanel; - - /** - * The panel that holds the default, revert and rescan buttons. - */ - ButtonView *buttonView; - - /** - * The panel that holds the sliders for adjusting the cache sizes. - */ - CacheView *cachePanel; - - void updateSize(FontSelectionView *theView); - void updateFont(FontSelectionView *theView); - void updateStyle(FontSelectionView *theView); - - }; + FontsSettings fSettings; +}; #endif diff --git a/src/prefs/fonts/main.cpp b/src/prefs/fonts/main.cpp index c962423d8d..748f2e72cc 100644 --- a/src/prefs/fonts/main.cpp +++ b/src/prefs/fonts/main.cpp @@ -1,75 +1,23 @@ -/*! \file main.cpp - \brief Code for the main class. - -*/ - -#ifndef MAIN_WINDOW_H - - #include "MainWindow.h" - -#endif -#ifndef MAIN_H - - #include "main.h" - -#endif - +/* + * Copyright 2001-2005, Haiku. + * Distributed under the terms of the MIT License. + * + */ +#include "MainWindow.h" +#include "main.h" #include "FontsSettings.h" -/** - * Main method. - * - * Starts the whole thing. - */ -int main(int, char**){ - - /** - * An instance of the application. - */ - Font_pref fontApp; - +int main(int, char**) +{ + FontApp fontApp; fontApp.Run(); return(0); - } -/* - * Constructor. - * - * Provides a contstructor for the application. - */ -Font_pref::Font_pref() - :BApplication("application/x-vnd.Haiku-FNPL") { - - f_settings = new FontsSettings(); - BRect MainWindowRect; - MainWindowRect.Set(100, 80, 445, 343); - window = new MainWindow(MainWindowRect); - window->MoveTo(f_settings->WindowCorner()); -} - -Font_pref::~Font_pref() -{ - delete f_settings; -} - - -bool -Font_pref::QuitRequested() -{ - BMessage *message = CurrentMessage(); - BPoint point; - if (message->FindPoint("corner", &point) == B_OK) { - f_settings->SetWindowCorner(point); - } - - return BApplication::QuitRequested(); -} - - -void -Font_pref::ReadyToRun() +FontApp::FontApp() + : BApplication("application/x-vnd.Haiku-FNPL") { + MainWindow *window = new MainWindow(); window->Show(); } diff --git a/src/prefs/fonts/main.h b/src/prefs/fonts/main.h index e4c7bae112..43498483af 100644 --- a/src/prefs/fonts/main.h +++ b/src/prefs/fonts/main.h @@ -1,39 +1,17 @@ -/*! \file main.h - \brief Header file for the main class. - -*/ - +/* + * Copyright 2001-2005, Haiku. + * Distributed under the terms of the MIT License. + * + */ #ifndef MAIN_H +#define MAIN_H - #define MAIN_H - - #ifndef _APPLICATION_H - - #include - - #endif - - class FontsSettings; - class MainWindow; - /** - * Main class. - * - * Gets everything going. - */ - class Font_pref : public BApplication{ - - public: - - /** - * Constructor. - */ - Font_pref(); - ~Font_pref(); - void ReadyToRun(); - bool QuitRequested(); - private: - FontsSettings *f_settings; - MainWindow *window; - }; +#include + +class FontApp : public BApplication +{ +public: + FontApp(void); +}; #endif