More fixes to the prefs panel. In fact, for all practical purposes, it should be done.

Added private function _set_system_font_() to not use R5's hack


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@13031 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
DarkWyrm
2005-06-09 16:08:39 +00:00
parent c7acd48895
commit 4b31e304e7
13 changed files with 480 additions and 572 deletions
+32
View File
@@ -107,6 +107,38 @@ _font_control_(BFont *font, int32 cmd, void *data)
link.Read<uint32>(&font->fFlags); link.Read<uint32>(&font->fFlags);
} }
/*!
\brief Private function used to replace the R5 hack which sets a system font
\param which string denoting which font to set
\param family the new family for the system font
\param style the new style for the system font
\param size the size for the system font to have
R5 used a global area offset table to set the system fonts in the Font
preferences panel. Bleah.
*/
void
_set_system_font_(const char *which, font_family family, font_style style,
float size)
{
if(!which)
return;
if( (strcmp(which,"plain")==0) ||
(strcmp(which,"bold")==0) ||
(strcmp(which,"fixed")==0) )
{
BPrivate::BAppServerLink link;
link.StartMessage(AS_SET_SYSTEM_FONT);
link.AttachString(which);
link.AttachString(family);
link.AttachString(style);
link.Attach<float>(size);
link.Flush();
}
}
/*! /*!
\brief Returns the number of installed font families \brief Returns the number of installed font families
+11 -10
View File
@@ -4,6 +4,7 @@
* *
*/ */
#include "ButtonView.h" #include "ButtonView.h"
#include "MainWindow.h"
ButtonView::ButtonView(BRect rect) ButtonView::ButtonView(BRect rect)
: BView(rect, "ButtonView", B_FOLLOW_ALL, B_WILL_DRAW) : BView(rect, "ButtonView", B_FOLLOW_ALL, B_WILL_DRAW)
@@ -13,24 +14,24 @@ ButtonView::ButtonView(BRect rect)
BRect btnRect(0, 0, 75, 25); BRect btnRect(0, 0, 75, 25);
btnRect.OffsetBy(10, 8); btnRect.OffsetBy(10, 8);
BButton *rescanButton = new BButton(btnRect, "rescanButton", "Rescan", BButton *rescanButton = new BButton(btnRect, "rescanButton", "Rescan",
new BMessage(RESCAN_FONTS_MSG), new BMessage(M_RESCAN_FONTS),
B_FOLLOW_LEFT, B_WILL_DRAW); B_FOLLOW_LEFT, B_WILL_DRAW);
AddChild(rescanButton); AddChild(rescanButton);
btnRect.OffsetBy(96, 0); btnRect.OffsetBy(96, 0);
BButton *defaultsButton = new BButton(btnRect, "defaultsButton", BButton *defaultsButton = new BButton(btnRect, "defaultsButton",
"Defaults", "Defaults",
new BMessage(RESET_FONTS_MSG), new BMessage(M_SET_DEFAULTS),
B_FOLLOW_LEFT, B_WILL_DRAW); B_FOLLOW_LEFT, B_WILL_DRAW);
AddChild(defaultsButton); AddChild(defaultsButton);
btnRect.OffsetBy(85, 0); btnRect.OffsetBy(85, 0);
revertButton = new BButton(btnRect, "revertButton", "Revert", fRevertButton = new BButton(btnRect, "fRevertButton", "Revert",
new BMessage(REVERT_MSG), new BMessage(M_REVERT),
B_FOLLOW_LEFT, B_WILL_DRAW); B_FOLLOW_LEFT, B_WILL_DRAW);
AddChild(revertButton); AddChild(fRevertButton);
revertButton->SetEnabled(false); fRevertButton->SetEnabled(false);
} }
@@ -55,12 +56,12 @@ ButtonView::Draw(BRect update)
bool bool
ButtonView::RevertState() ButtonView::RevertState(void) const
{ {
return revertButton->IsEnabled(); return fRevertButton->IsEnabled();
} }
void ButtonView::SetRevertState(bool b) void ButtonView::SetRevertState(bool value)
{ {
revertButton->SetEnabled(b); fRevertButton->SetEnabled(value);
} }
+3 -9
View File
@@ -10,25 +10,19 @@
#include <Button.h> #include <Button.h>
// Message sent when the rescan button is sent. // Message sent when the rescan button is sent.
#define RESCAN_FONTS_MSG 'rscn' #define M_RESCAN_FONTS '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'
class ButtonView : public BView class ButtonView : public BView
{ {
public: public:
ButtonView(BRect frame); ButtonView(BRect frame);
bool RevertState(); bool RevertState() const;
void SetRevertState(bool b); void SetRevertState(bool b);
void Draw(BRect); void Draw(BRect);
private: private:
BButton *revertButton; BButton *fRevertButton;
}; };
#endif #endif
+52 -55
View File
@@ -7,6 +7,7 @@
#include <String.h> #include <String.h>
#include <stdio.h> #include <stdio.h>
#include "MainWindow.h"
#include "Pref_Utils.h" #include "Pref_Utils.h"
#define PRINT_FCS_UPDATE_MSG 'pfum' #define PRINT_FCS_UPDATE_MSG 'pfum'
@@ -73,10 +74,13 @@ CacheView::CacheView(const BRect &frame, const int32 &sliderMin,
rect.right = rect.left +86.0; rect.right = rect.left +86.0;
rect.bottom = rect.top +24.0; rect.bottom = rect.top +24.0;
// TODO: find out what 'Save Cache' does and implement // TODO: figure out what to do with 'Save Cache' on R5. According to the
// BeOS Bible, it allocates a block of memory to disk, which is loaded on
// next boot. FreeType does better than this.
fSaveCache = new BButton(rect, "saveCache", "Save Cache", fSaveCache = new BButton(rect, "saveCache", "Save Cache",
NULL, B_FOLLOW_LEFT, B_WILL_DRAW); NULL, B_FOLLOW_LEFT, B_WILL_DRAW);
AddChild(fSaveCache); AddChild(fSaveCache);
fSaveCache->SetEnabled(false);
} }
void void
@@ -94,38 +98,15 @@ CacheView::MessageReceived(BMessage *msg)
{ {
case PRINT_FCS_MODIFICATION_MSG: case PRINT_FCS_MODIFICATION_MSG:
{ {
struct font_cache_info fontCacheInfo; UpdatePrintSettings(fPrintSlider->Value());
get_font_cache_info(B_PRINTING_FONT_CACHE|B_DEFAULT_CACHE_SETTING, Window()->PostMessage(M_ENABLE_REVERT);
&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; break;
} }
case SCREEN_FCS_MODIFICATION_MSG: case SCREEN_FCS_MODIFICATION_MSG:
{ {
struct font_cache_info fontCacheInfo; UpdateScreenSettings(fScreenSlider->Value());
Window()->PostMessage(M_ENABLE_REVERT);
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; break;
} }
default: default:
@@ -136,34 +117,50 @@ CacheView::MessageReceived(BMessage *msg)
} }
} }
/** void CacheView::Revert(void)
* Sets the sliders to their original values. {
*/ fPrintSlider->SetValue(fSavedPrintValue);
void CacheView::revertToOriginal(){ fScreenSlider->SetValue(fSavedScreenValue);
// TODO: fix UpdatePrintSettings(fSavedPrintValue);
/* UpdateScreenSettings(fSavedScreenValue);
BString label;
label << "Screen " << kLabel << getScreenFCSValue();
updateScreenFCS(label.String());
label = "Printing ";
label << kLabel << getPrintFCSValue();
updatePrintFCS(label.String());
*/
} }
/** void CacheView::SetDefaults(void)
* Sets the sliders to their default values. {
*/ fPrintSlider->SetValue(256);
void CacheView::resetToDefaults(){ fScreenSlider->SetValue(256);
// TODO: fix UpdatePrintSettings(256);
/* BString label; UpdateScreenSettings(256);
label << "Screen " << kLabel << getScreenFCSValue() << " kB"; }
updateScreenFCS(label.String());
void
CacheView::UpdatePrintSettings(int32 value)
{
struct font_cache_info fontCacheInfo;
label = "Printing "; get_font_cache_info(B_PRINTING_FONT_CACHE|B_DEFAULT_CACHE_SETTING,
label << kLabel << getPrintFCSValue() << " kB"; &fontCacheInfo);
updatePrintFCS(label.String()); fontCacheInfo.cache_size = value << 10;
*/ set_font_cache_info(B_PRINTING_FONT_CACHE|B_DEFAULT_CACHE_SETTING,
&fontCacheInfo);
BString str("Printing font cache size : ");
str << value << " kB";
fPrintSlider->SetLabel(str.String());
} }
void
CacheView::UpdateScreenSettings(int32 value)
{
struct font_cache_info fontCacheInfo;
get_font_cache_info(B_SCREEN_FONT_CACHE|B_DEFAULT_CACHE_SETTING,
&fontCacheInfo);
fontCacheInfo.cache_size = value << 10;
set_font_cache_info(B_SCREEN_FONT_CACHE|B_DEFAULT_CACHE_SETTING,
&fontCacheInfo);
BString str("Screen font cache size : ");
str << value << " kB";
fScreenSlider->SetLabel(str.String());
}
+5 -4
View File
@@ -20,16 +20,17 @@ public:
void AttachedToWindow(void); void AttachedToWindow(void);
void MessageReceived(BMessage *msg); void MessageReceived(BMessage *msg);
void revertToOriginal(); void Revert(void);
void resetToDefaults(); void SetDefaults(void);
private: private:
void UpdatePrintSettings(int32 value);
void UpdateScreenSettings(int32 value);
BSlider *fScreenSlider; BSlider *fScreenSlider;
BSlider *fPrintSlider; BSlider *fPrintSlider;
BButton *fSaveCache; BButton *fSaveCache;
// The original slider values
int32 fSavedPrintValue; int32 fSavedPrintValue;
int32 fSavedScreenValue; int32 fSavedScreenValue;
}; };
+297 -310
View File
@@ -4,125 +4,145 @@
* *
*/ */
#include "FontSelectionView.h" #include "FontSelectionView.h"
#include "MainWindow.h"
#include "Pref_Utils.h" #include "Pref_Utils.h"
#include <String.h>
#define SIZE_CHANGED_MSG 'plsz' #define SIZE_CHANGED_MSG 'plsz'
#define FONT_CHANGED_MSG 'plfn' #define FONT_CHANGED_MSG 'plfn'
#define STYLE_CHANGED_MSG 'plst' #define STYLE_CHANGED_MSG 'plst'
// should be changed to allow larger and smaller // should be changed to allow larger and smaller
#define minSizeIndex 9 #define MIN_SIZE_INDEX 9
#define maxSizeIndex 14 #define MAX_SIZE_INDEX 14
// constants for labels extern void _set_system_font_(const char *which, font_family family, font_style style, float size);
const char *kPlainFont = "Plain font:";
const char *kBoldFont = "Bold font:";
const char *kFixedFont = "Fixed font:";
const char *kSize = "Size: ";
FontSelectionView::FontSelectionView(BRect rect, const char *name, int type) 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),
fType(type)
{ {
switch(type) SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR));
BString typelabel;
switch(fType)
{ {
case BOLD_FONT_SELECTION_VIEW: case BOLD_FONT_SELECTION_VIEW:
{ {
sprintf(typeLabel, kBoldFont); typelabel="Bold font:";
origFont = be_bold_font; fSavedFont = be_bold_font;
workingFont = be_bold_font; fCurrentFont = be_bold_font;
defaultFont = new BFont(); fDefaultFont.SetFamilyAndStyle("Swis721 BT", "Bold");
defaultFont->SetFamilyAndStyle("Swis721 BT", "Bold"); fDefaultFont.SetSize(12.0);
defaultFont->SetSize(12.0);
break; break;
} }
case FIXED_FONT_SELECTION_VIEW: case FIXED_FONT_SELECTION_VIEW:
{ {
sprintf(typeLabel, kFixedFont); typelabel="Fixed font:";
origFont = be_fixed_font; fSavedFont = be_fixed_font;
workingFont = be_fixed_font; fCurrentFont = be_fixed_font;
defaultFont = new BFont(); fDefaultFont = new BFont();
defaultFont->SetFamilyAndStyle("Courier10 BT", "Roman"); fDefaultFont.SetFamilyAndStyle("Courier10 BT", "Roman");
defaultFont->SetSize(12.0); fDefaultFont.SetSize(12.0);
break; break;
} }
default: default:
{ {
sprintf(typeLabel, kPlainFont); typelabel="Plain font:";
origFont = be_plain_font; fSavedFont = be_plain_font;
workingFont = be_plain_font; fCurrentFont = be_plain_font;
defaultFont = new BFont(); fDefaultFont = new BFont();
defaultFont->SetFamilyAndStyle("Swis721 BT", "Roman"); fDefaultFont.SetFamilyAndStyle("Swis721 BT", "Roman");
defaultFont->SetSize(10.0); fDefaultFont.SetSize(10.0);
break; break;
} }
} }
float fontheight = FontHeight(false); float fontheight = FontHeight(false);
float divider = StringWidth(kFixedFont); float divider = StringWidth("Fixed font:");
sizeList = new BPopUpMenu("sizeList", true, true, B_ITEMS_IN_COLUMN); fSizeMenu = new BPopUpMenu("fSizeMenu", true, true, B_ITEMS_IN_COLUMN);
fontList = new BPopUpMenu("fontList", true, true, B_ITEMS_IN_COLUMN); fFontMenu = new BPopUpMenu("fFontMenu", true, true, B_ITEMS_IN_COLUMN);
// create menus
// size box // size box
rect = Bounds(); BRect r( Bounds() );
float x = StringWidth("999") +16;
rect.left = rect.right -(x +StringWidth(kSize)+8.0); float x = StringWidth("999") + 16;
rect.bottom = fontheight +5; r.left = r.right -( x + StringWidth("Size: ") + 8.0 );
BMenuField *sizeListField = new BMenuField(rect, "fontField", kSize, sizeList, true); r.bottom = fontheight +5;
sizeListField->SetDivider(StringWidth(kSize)+5.0);
sizeListField->SetAlignment(B_ALIGN_RIGHT); BMenuField *fSizeMenuField = new BMenuField(r, "fontField", "Size: ", fSizeMenu, true);
fSizeMenuField->SetDivider( StringWidth("Size: ") + 5.0 );
fSizeMenuField->SetAlignment(B_ALIGN_RIGHT);
AddChild(fSizeMenuField);
// font menu // font menu
rect.right = rect.left; r.right = r.left;
rect.left = 1; r.left = 1;
rect.bottom = fontheight *1.5; r.bottom = fontheight *1.5;
BMenuField *fontListField = new BMenuField(rect, "fontField", typeLabel, fontList, false); BMenuField *fFontMenuField = new BMenuField(r, "fontField", typelabel.String(), fFontMenu, false);
fontListField->SetDivider(divider +6.0); fFontMenuField->SetDivider(divider + 6.0);
fontListField->SetAlignment(B_ALIGN_RIGHT); fFontMenuField->SetAlignment(B_ALIGN_RIGHT);
AddChild(fFontMenuField);
rect = Bounds(); r = Bounds();
rect.left = divider +8.0; r.left = divider +8.0;
rect.top = fontheight *1.5 +4; r.top = fontheight *1.5 +4;
rect.InsetBy(1, 1); r.InsetBy(1, 1);
BBox *testTextBox = new BBox(rect, "TestTextBox", B_FOLLOW_ALL, B_WILL_DRAW, B_FANCY_BORDER); BBox *fPreviewTextBox = new BBox(r, "TestTextBox", B_FOLLOW_ALL, B_WILL_DRAW, B_FANCY_BORDER);
AddChild(fPreviewTextBox);
// Place the text slightly inside the entire box area, so it doesn't overlap the box outline. // Place the text slightly inside the entire box area, so it doesn't overlap the box outline.
rect = testTextBox->Bounds().InsetByCopy(2, 2); r = fPreviewTextBox->Bounds().InsetByCopy(2, 2);
rect.right -= 2; r.right -= 2;
BRect testTextRect(rect); BRect fPreviewTextRect(r);
testText = new BStringView(testTextRect, "testText", "The quick brown fox jumps over the lazy dog.", fPreviewText = new BStringView(fPreviewTextRect, "fPreviewText", "The quick brown fox jumps over the lazy dog.",
B_FOLLOW_ALL, B_WILL_DRAW); B_FOLLOW_ALL, B_WILL_DRAW);
testText->SetFont(&workingFont); fPreviewText->SetFont(&fCurrentFont);
fPreviewTextBox->AddChild(fPreviewText);
fontList->SetLabelFromMarked(true);
buildMenus();
SetViewColor(216, 216, 216, 0);
AddChild(testTextBox);
testTextBox->AddChild(testText);
AddChild(sizeListField);
AddChild(fontListField);
} }
FontSelectionView::~FontSelectionView(void) FontSelectionView::~FontSelectionView(void)
{ {
delete defaultFont; font_family family;
font_style style;
fCurrentFont.GetFamilyAndStyle(&family,&style);
switch(fType)
{
case PLAIN_FONT_SELECTION_VIEW:
{
_set_system_font_("plain", family, style, fCurrentFont.Size());
break;
}
case BOLD_FONT_SELECTION_VIEW:
{
_set_system_font_("bold", family, style, fCurrentFont.Size());
break;
}
case FIXED_FONT_SELECTION_VIEW:
{
_set_system_font_("fixed", family, style, fCurrentFont.Size());
break;
}
default:
{
break;
}
}
} }
void void
FontSelectionView::AttachedToWindow(void) FontSelectionView::AttachedToWindow(void)
{ {
BuildMenus();
} }
void void
@@ -130,52 +150,109 @@ FontSelectionView::MessageReceived(BMessage *msg)
{ {
switch(msg->what) switch(msg->what)
{ {
/* case SIZE_CHANGED_MSG: { case SIZE_CHANGED_MSG:
{
updateSize(fSelectorView->plainSelectionView); int32 size;
fButtonView->SetRevertState(true); if(msg->FindInt32("size",&size)!=B_OK)
break;
BString str(B_EMPTY_STRING);
str << size;
BMenuItem *item=fSizeMenu->FindItem(str.String());
if(item)
{
item->SetMarked(true);
fCurrentFont.SetSize(size);
fPreviewText->SetFont(&fCurrentFont, B_FONT_ALL);
fPreviewText->Invalidate();
}
NotifyFontChange();
Window()->PostMessage(M_ENABLE_REVERT);
break; break;
} }
case FONT_CHANGED_MSG: { case FONT_CHANGED_MSG:
{
updateFont(fSelectorView->plainSelectionView); BString str;
fButtonView->SetRevertState(true); if(msg->FindString("family",&str)!=B_OK)
break;
font_family family;
sprintf(family,"%s",str.String());
BMenuItem *menu=fFontMenu->FindItem(family);
if(menu)
{
menu->SetMarked(true);
fCurrentFont.SetFamilyAndFace(family,B_REGULAR_FACE);
font_style style;
fCurrentFont.GetFamilyAndStyle(&family,&style);
BMenuItem *item=menu->Submenu()->FindItem(style);
if(item)
{
fCurrentStyle->SetMarked(false);
item->SetMarked(true);
fCurrentStyle=item;
fPreviewText->SetFont(&fCurrentFont, B_FONT_ALL);
fPreviewText->Invalidate();
}
}
NotifyFontChange();
Window()->PostMessage(M_ENABLE_REVERT);
break; break;
} }
case STYLE_CHANGED_MSG: { case STYLE_CHANGED_MSG:
{
updateStyle(fSelectorView->plainSelectionView); BString str;
fButtonView->SetRevertState(true); if(msg->FindString("family",&str)!=B_OK)
break;
font_family family;
font_style style;
sprintf(family,"%s",str.String());
if(msg->FindString("style",&str)!=B_OK)
break;
sprintf(style,"%s",str.String());
BMenuItem *menu=fFontMenu->FindItem(family);
if(!menu)
break;
BMenuItem *item=menu->Submenu()->FindItem(style);
if(item)
{
fCurrentStyle->SetMarked(false);
menu->SetMarked(true);
item->SetMarked(true);
fCurrentStyle=item;
fCurrentFont.SetFamilyAndStyle(family,style);
fPreviewText->SetFont(&fCurrentFont, B_FONT_ALL);
fPreviewText->Invalidate();
}
NotifyFontChange();
Window()->PostMessage(M_ENABLE_REVERT);
break; break;
} }
case RESCAN_FONTS_MSG: { default:
update_font_families(false);
fSelectorView->emptyMenus();
fSelectorView->buildMenus();
updateFont(fSelectorView->plainSelectionView);
updateFont(fSelectorView->boldSelectionView);
updateFont(fSelectorView->fixedSelectionView);
break;
}
case RESET_FONTS_MSG: {
fSelectorView->resetToDefaults();
fCacheView->resetToDefaults();
fButtonView->SetRevertState(true);
break;
}
*/ default:
BView::MessageReceived(msg); BView::MessageReceived(msg);
} }
} }
void FontSelectionView::emptyMenus(void) void
FontSelectionView::EmptyMenus(void)
{ {
// Empty the font list // Empty the font list
for(int32 i = 0; i < fontList->CountItems(); i++) for(int32 i = 0; i < fFontMenu->CountItems(); i++)
{ {
BMenu *menu = fontList->SubmenuAt(0L); BMenu *menu = fFontMenu->SubmenuAt(0L);
// We should never have a regular menu item in the font list // We should never have a regular menu item in the font list
if(!menu) if(!menu)
@@ -187,24 +264,27 @@ void FontSelectionView::emptyMenus(void)
delete item; delete item;
} }
fontList->RemoveItem(menu); fFontMenu->RemoveItem(menu);
delete menu; delete menu;
} }
// empty the size list // empty the size list
for(int32 i = 0; i < sizeList->CountItems(); i++) for(int32 i = 0; i < fSizeMenu->CountItems(); i++)
{ {
BMenuItem *item = sizeList->RemoveItem(0L); BMenuItem *item = fSizeMenu->RemoveItem(0L);
delete item; delete item;
} }
} }
void FontSelectionView::buildMenus(void) void
FontSelectionView::BuildMenus(void)
{ {
int32 numFamilies; int32 numFamilies;
int counter; int counter;
BMessage *msg;
numFamilies = count_font_families(); numFamilies = count_font_families();
for ( int32 i = 0; i < numFamilies; i++ ) for ( int32 i = 0; i < numFamilies; i++ )
{ {
font_family family; font_family family;
@@ -218,7 +298,6 @@ void FontSelectionView::buildMenus(void)
if ( get_font_family(i, &family, &flags) != B_OK ) if ( get_font_family(i, &family, &flags) != B_OK )
continue; continue;
markFamily = false; markFamily = false;
tmpStyleMenu = new BMenu(family); tmpStyleMenu = new BMenu(family);
@@ -236,246 +315,154 @@ void FontSelectionView::buildMenus(void)
if (get_font_style(family, j, &style, &flags) != B_OK) if (get_font_style(family, j, &style, &flags) != B_OK)
continue; continue;
fCurrentFont.GetFamilyAndStyle(&workingFamily, &workingStyle);
workingFont.GetFamilyAndStyle(&workingFamily, &workingStyle); msg = new BMessage(STYLE_CHANGED_MSG);
tmpItem = new BMenuItem(style, new BMessage(STYLE_CHANGED_MSG)); msg->AddString("family",(char*)family);
msg->AddString("style",(char*)style);
tmpItem = new BMenuItem(style, msg);
if((strcmp(style, workingStyle) == 0) && (strcmp(family, workingFamily) == 0)) if((strcmp(style, workingStyle) == 0) && (strcmp(family, workingFamily) == 0))
{ {
markFamily = true; markFamily = true;
tmpItem->SetMarked(true); tmpItem->SetMarked(true);
fCurrentStyle=tmpItem;
} }
tmpStyleMenu->AddItem(tmpItem); tmpStyleMenu->AddItem(tmpItem);
} }
fontList->AddItem(new BMenuItem((tmpStyleMenu), new BMessage(FONT_CHANGED_MSG))); msg = new BMessage(FONT_CHANGED_MSG);
msg->AddString("family",family);
fFontMenu->AddItem(new BMenuItem((tmpStyleMenu), msg));
tmpStyleMenu->SetTargetForItems(this);
if(markFamily) if(markFamily)
tmpStyleMenu->Superitem()->SetMarked(true); tmpStyleMenu->Superitem()->SetMarked(true);
} }
fFontMenu->SetTargetForItems(this);
// build size menu // build size menu
for(counter = minSizeIndex; counter < (maxSizeIndex + 1); counter++) for(counter = MIN_SIZE_INDEX; counter < (MAX_SIZE_INDEX + 1); counter++)
{ {
char buf[1]; char buf[1];
BMenuItem *tmp; BMenuItem *tmp;
sprintf(buf, "%d", counter); sprintf(buf, "%d", counter);
sizeList->AddItem(tmp = new BMenuItem(buf, new BMessage(SIZE_CHANGED_MSG))); msg = new BMessage(SIZE_CHANGED_MSG);
if(counter == (int) workingFont.Size()) msg->AddInt32("size",counter);
fSizeMenu->AddItem(tmp = new BMenuItem(buf, msg));
if(counter == (int) fCurrentFont.Size())
tmp->SetMarked(true); tmp->SetMarked(true);
} }
fSizeMenu->SetTargetForItems(this);
} }
/** // This method is called by outsiders only. As a result,
* Writes the test text in the given font. // the owning window is NOT notified
* @param fnt The font to write the test text in. void
*/ FontSelectionView::SetDefaults(void)
void FontSelectionView::SetTestTextFont(BFont *fnt)
{ {
testText->SetFont(fnt, B_FONT_ALL); font_family family;
testText->Invalidate(); font_style style;
}
BFont FontSelectionView::GetTestTextFont()
{
BFont rtrnFont;
testText->GetFont(&rtrnFont); fDefaultFont.GetFamilyAndStyle(&family, &style);
return rtrnFont; BMenuItem *menu=fFontMenu->FindItem(family);
if(!menu)
} return;
float
FontSelectionView::GetSelectedSize()
{
return minSizeIndex + sizeList->IndexOf(sizeList->FindMarked());
}
void FontSelectionView::GetSelectedFont(font_family *family)
{
int numFamilies = count_font_families();
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)
get_font_family(i, family, &flags);
}
}
}
void FontSelectionView::GetSelectedStyle(font_style *style)
{
int numFamilies = count_font_families();
font_family curr;
GetSelectedFont(&curr);
for ( int32 i = 0; i < numFamilies; i++ )
{
font_family fam;
uint32 flags;
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()
{
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){ BMenuItem *item=menu->Submenu()->FindItem(style);
if(!item)
fontList->FindMarked()->Submenu()->FindMarked()->SetMarked(false); return;
fontList->ItemAt(i)->SetMarked(true);
fCurrentStyle->SetMarked(false);
}//if menu->SetMarked(true);
item->SetMarked(true);
}//if fCurrentStyle=item;
}//for char string[5];
sprintf(string,"%d",(int)fDefaultFont.Size());
}//for item = fSizeMenu->FindItem(string);
if(item)
item->SetMarked(true);
fCurrentFont=fDefaultFont;
fPreviewText->SetFont(&fCurrentFont, B_FONT_ALL);
fPreviewText->Invalidate();
} }
/** // This method is called by outsiders only. As a result,
* Updates the font menu based on the user selection. // the owning window is NOT notified
*/ void
void FontSelectionView::UpdateFontSelection() FontSelectionView::Revert(void)
{ {
for(int32 i = 0; i < fontList->CountItems();i++) font_family family;
font_style style;
fSavedFont.GetFamilyAndStyle(&family, &style);
BMenuItem *menu=fFontMenu->FindItem(family);
if(!menu)
return;
BMenuItem *item=menu->Submenu()->FindItem(style);
if(!item)
return;
fCurrentStyle->SetMarked(false);
menu->SetMarked(true);
item->SetMarked(true);
fCurrentStyle=item;
char string[5];
sprintf(string,"%d",(int)fSavedFont.Size());
item = fSizeMenu->FindItem(string);
if(item)
item->SetMarked(true);
fCurrentFont=fSavedFont;
fPreviewText->SetFont(&fCurrentFont, B_FONT_ALL);
fPreviewText->Invalidate();
}
void
FontSelectionView::NotifyFontChange(void)
{
BMessage msg;
switch(fType)
{ {
for(int32 j = 0;j < fontList->ItemAt(i)->Submenu()->CountItems();j++) case BOLD_FONT_SELECTION_VIEW:
{ {
if(fontList->ItemAt(i)->Submenu()->ItemAt(j)->IsMarked()) msg.what=M_SET_BOLD;
{ break;
if(strcmp(fontList->ItemAt(i)->Label(), fontList->FindMarked()->Label()) > 0) }
{ case FIXED_FONT_SELECTION_VIEW:
fontList->ItemAt(i)->Submenu()->FindMarked()->SetMarked(false); {
fontList->FindMarked()->Submenu()->ItemAt(0)->SetMarked(true); msg.what=M_SET_FIXED;
} break;
} }
default:
{
msg.what=M_SET_PLAIN;
break;
} }
} }
font_family family;
font_style style;
fCurrentFont.GetFamilyAndStyle(&family,&style);
msg.AddInt32("size",fCurrentFont.Size());
msg.AddString("family",family);
msg.AddString("style",style);
Window()->PostMessage(&msg);
} }
/** void
* Updates the font and size menus based on the given font. FontSelectionView::RescanFonts(void)
* @param fnt The font to set the menus to. {
* \note This methd needs rewriting BADLY - it's horribly written EmptyMenus();
*/ BuildMenus();
void FontSelectionView::UpdateFontSelection(BFont *fnt){ }
int i = 0;
char style[64];
char family[64];
fnt->GetFamilyAndStyle(&family, &style);
for(i = 0;i < fontList->CountItems();i++){
int j = 0;
if(strcmp(fontList->ItemAt(i)->Label(), family) == 0){
fontList->ItemAt(i)->SetMarked(true);
}//if
for(j = 0;j < fontList->ItemAt(i)->Submenu()->CountItems();j++){
if(fontList->ItemAt(i)->Submenu()->ItemAt(j)->IsMarked()){
fontList->ItemAt(i)->Submenu()->ItemAt(j)->SetMarked(false);
}//if
if(strcmp(fontList->ItemAt(i)->Label(), family) == 0){
if(strcmp(fontList->ItemAt(i)->Submenu()->ItemAt(j)->Label(), style) == 0){
fontList->ItemAt(i)->Submenu()->ItemAt(j)->SetMarked(true);
}//if
}//if
}//for
}//for
//Update size menu
for(i = 0;i < sizeList->CountItems();i++){
char size[1];
sprintf(size, "%d", (int)fnt->Size());
if(strcmp(sizeList->ItemAt(i)->Label(), size) == 0){
sizeList->ItemAt(i)->SetMarked(true);
break;
}//if
}//for
}//UpdateFontSelection
/**
* Resets the test text to the default font.
*/
void FontSelectionView::resetToDefaults(){
//Update menus
UpdateFontSelection(defaultFont);
//Update test text
SetTestTextFont(defaultFont);
}//resetToDefaults
/**
* Resets the test text to the original font.
*/
void FontSelectionView::revertToOriginal(){
//Update menus
UpdateFontSelection(&origFont);
//Update test text
SetTestTextFont(&origFont);
}//resetToDefaults
+18 -26
View File
@@ -13,6 +13,7 @@
#include <MenuField.h> #include <MenuField.h>
#include <MenuItem.h> #include <MenuItem.h>
#include <stdio.h> #include <stdio.h>
#include <String.h>
enum enum
{ {
@@ -29,36 +30,27 @@ public:
void AttachedToWindow(void); void AttachedToWindow(void);
void MessageReceived(BMessage *msg); void MessageReceived(BMessage *msg);
void SetTestTextFont(BFont *fnt); void SetDefaults(void);
BFont GetTestTextFont(); void Revert(void);
float GetSelectedSize(); void RescanFonts(void);
void GetSelectedFont(font_family *family);
void GetSelectedStyle(font_style *style);
void UpdateFontSelectionFromStyle();
void UpdateFontSelection();
void resetToDefaults();
void revertToOriginal();
private: private:
void buildMenus(void); void BuildMenus(void);
void emptyMenus(void); void EmptyMenus(void);
void NotifyFontChange(void);
void EmptyMenu(BPopUpMenu *m); BStringView *fPreviewText;
void UpdateFontSelection(BFont *fnt);
BStringView *testText; BPopUpMenu *fFontMenu;
BPopUpMenu *fSizeMenu;
int fType;
BPopUpMenu *fontList; BFont fSavedFont;
BPopUpMenu *sizeList; BFont fCurrentFont;
BFont fDefaultFont;
int minSizeIndex;
int maxSizeIndex; BMenuItem *fCurrentStyle;
char typeLabel[30];
BFont origFont;
BFont workingFont;
BFont *defaultFont;
}; };
#endif #endif
+18 -23
View File
@@ -15,48 +15,43 @@ FontView::FontView(BRect rect)
BRect rect(bounds); BRect rect(bounds);
rect.bottom = rect.top + FontHeight(true) *3.5; rect.bottom = rect.top + FontHeight(true) *3.5;
plainSelectionView = new FontSelectionView(rect, "Plain", fPlainView = new FontSelectionView(rect, "Plain",
PLAIN_FONT_SELECTION_VIEW); PLAIN_FONT_SELECTION_VIEW);
AddChild(plainSelectionView); AddChild(fPlainView);
rect.OffsetBy(0, rect.Height() + 4); rect.OffsetBy(0, rect.Height() + 4);
boldSelectionView = new FontSelectionView(rect, "Bold", fBoldView = new FontSelectionView(rect, "Bold",
BOLD_FONT_SELECTION_VIEW); BOLD_FONT_SELECTION_VIEW);
AddChild(boldSelectionView); AddChild(fBoldView);
rect.OffsetBy(0, rect.Height() + 4); rect.OffsetBy(0, rect.Height() + 4);
fixedSelectionView = new FontSelectionView(rect, "Fixed", fFixedView = new FontSelectionView(rect, "Fixed",
FIXED_FONT_SELECTION_VIEW); FIXED_FONT_SELECTION_VIEW);
AddChild(fixedSelectionView); AddChild(fFixedView);
} }
void void
FontView::AttachedToWindow(void) FontView::SetDefaults(void)
{ {
fPlainView->SetDefaults();
fBoldView->SetDefaults();
fFixedView->SetDefaults();
} }
/**
* Calls each FontSelectionView's resetToDefaults() function to reset
* the font and size menus to the default font.
*/
void void
FontView::resetToDefaults() FontView::Revert(void)
{ {
plainSelectionView->resetToDefaults(); fPlainView->Revert();
boldSelectionView->resetToDefaults(); fBoldView->Revert();
fixedSelectionView->resetToDefaults(); fFixedView->Revert();
} }
/**
* Calls each FontSelectionView's revertToOriginal() function to reset
* the font and size menus to the original font.
*/
void void
FontView::revertToOriginal() FontView::RescanFonts(void)
{ {
plainSelectionView->revertToOriginal(); fPlainView->RescanFonts();
boldSelectionView->revertToOriginal(); fBoldView->RescanFonts();
fixedSelectionView->revertToOriginal(); fFixedView->RescanFonts();
} }
+9 -8
View File
@@ -14,14 +14,15 @@ class FontView : public BView
{ {
public: public:
FontView(BRect frame); FontView(BRect frame);
void AttachedToWindow(void); void SetDefaults(void);
void Revert(void);
void resetToDefaults(); void RescanFonts(void);
void revertToOriginal();
private:
FontSelectionView *plainSelectionView;
FontSelectionView *boldSelectionView; FontSelectionView *fPlainView;
FontSelectionView *fixedSelectionView; FontSelectionView *fBoldView;
FontSelectionView *fFixedView;
}; };
#endif #endif
+1 -1
View File
@@ -21,4 +21,4 @@ private:
BPoint fCorner; BPoint fCorner;
}; };
#endif //FONTS_SETTINGS_H #endif
+19 -115
View File
@@ -67,132 +67,36 @@ MainWindow::QuitRequested(void)
void void
MainWindow::MessageReceived(BMessage *message) MainWindow::MessageReceived(BMessage *message)
{ {
switch(message->what) { switch(message->what)
{
/* case PLAIN_SIZE_CHANGED_MSG: { case M_ENABLE_REVERT:
{
updateSize(fSelectorView->plainSelectionView);
fButtonView->SetRevertState(true); fButtonView->SetRevertState(true);
break; break;
} }
case BOLD_SIZE_CHANGED_MSG: { case M_RESCAN_FONTS:
{
updateSize(fSelectorView->boldSelectionView); fSelectorView->RescanFonts();
break;
}
case M_SET_DEFAULTS:
{
fSelectorView->SetDefaults();
fCacheView->SetDefaults();
fButtonView->SetRevertState(true); fButtonView->SetRevertState(true);
break; break;
} }
case FIXED_SIZE_CHANGED_MSG: { case M_REVERT:
{
updateSize(fSelectorView->fixedSelectionView); fSelectorView->Revert();
fButtonView->SetRevertState(true); fCacheView->Revert();
break;
}
case PLAIN_FONT_CHANGED_MSG: {
updateFont(fSelectorView->plainSelectionView);
fButtonView->SetRevertState(true);
break;
}
case BOLD_FONT_CHANGED_MSG: {
updateFont(fSelectorView->boldSelectionView);
fButtonView->SetRevertState(true);
break;
}
case FIXED_FONT_CHANGED_MSG: {
updateFont(fSelectorView->fixedSelectionView);
fButtonView->SetRevertState(true);
break;
}
case PLAIN_STYLE_CHANGED_MSG: {
updateStyle(fSelectorView->plainSelectionView);
fButtonView->SetRevertState(true);
break;
}
case BOLD_STYLE_CHANGED_MSG: {
updateStyle(fSelectorView->boldSelectionView);
fButtonView->SetRevertState(true);
break;
}
case FIXED_STYLE_CHANGED_MSG: {
updateStyle(fSelectorView->fixedSelectionView);
fButtonView->SetRevertState(true);
break;
}
case RESCAN_FONTS_MSG: {
update_font_families(false);
fSelectorView->emptyMenus();
fSelectorView->buildMenus();
updateFont(fSelectorView->plainSelectionView);
updateFont(fSelectorView->boldSelectionView);
updateFont(fSelectorView->fixedSelectionView);
break;
}
case RESET_FONTS_MSG: {
fSelectorView->resetToDefaults();
fCacheView->resetToDefaults();
fButtonView->SetRevertState(true);
break;
}
*/ case REVERT_MSG: {
fSelectorView->revertToOriginal();
fCacheView->revertToOriginal();
fButtonView->SetRevertState(false); fButtonView->SetRevertState(false);
break; break;
} }
default: { default:
{
BWindow::MessageReceived(message); BWindow::MessageReceived(message);
break; break;
} }
} }
} }
// 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);
}
// Updates the test text to the selected font.
void
MainWindow::updateFont(FontSelectionView *theView)
{
BFont workingFont;
font_family updateTo;
theView->UpdateFontSelection();
workingFont = theView->GetTestTextFont();
theView->GetSelectedFont(&updateTo);
workingFont.SetFamilyAndStyle(updateTo, NULL);
theView->SetTestTextFont(&workingFont);
}
// Updates the test text to the selected style.
void
MainWindow::updateStyle(FontSelectionView *theView)
{
BFont workingFont;
font_style updateTo;
font_family update;
theView->UpdateFontSelectionFromStyle();
workingFont = theView->GetTestTextFont();
theView->GetSelectedStyle(&updateTo);
theView->GetSelectedFont(&update);
workingFont.SetFamilyAndStyle(update, updateTo);
theView->SetTestTextFont(&workingFont);
}
+13 -9
View File
@@ -15,7 +15,15 @@
#include "CacheView.h" #include "CacheView.h"
#include "ButtonView.h" #include "ButtonView.h"
#include "FontsSettings.h" #include "FontsSettings.h"
#define M_ENABLE_REVERT 'enrv'
#define M_REVERT 'rvrt'
#define M_SET_DEFAULTS 'stdf'
#define M_SET_PLAIN 'stpl'
#define M_SET_BOLD 'stbl'
#define M_SET_FIXED 'stfx'
class MainWindow : public BWindow class MainWindow : public BWindow
{ {
public: public:
@@ -24,16 +32,12 @@ public:
virtual void MessageReceived(BMessage *message); virtual void MessageReceived(BMessage *message);
private: private:
void updateSize(FontSelectionView *theView);
void updateFont(FontSelectionView *theView);
void updateStyle(FontSelectionView *theView);
FontView *fSelectorView; FontView *fSelectorView;
ButtonView *fButtonView; ButtonView *fButtonView;
CacheView *fCacheView; CacheView *fCacheView;
FontsSettings fSettings; FontsSettings fSettings;
}; };
#endif #endif
+2 -2
View File
@@ -4,7 +4,7 @@
#include <Screen.h> #include <Screen.h>
#include <View.h> #include <View.h>
float FontHeight(bool full, BView* view = NULL); float FontHeight(bool full, BView* view = NULL);
color_map* ColorMap(); color_map* ColorMap();
#endif #endif