Embedded the Font into the Appearance Preflet
* Copied the essential parts from the Font preflet into the Appearance preflet folder. * Adopted these files to better direct where BMessage arrive and why. The Font preflet just forwarded them from the BWindow handler, which was quite messy. * Embedded the Font preferences as another tab. The first one actually, with the Decor settings also moved in front of the Anti-Aliasing tab. * Refactored the Defaults and Revert button updates in the window code. * AInclude all active settings tabs in the Defaults and Revert handling for consistency. But eventually, the buttons should only affect the currently visible page.
This commit is contained in:
@@ -37,9 +37,9 @@
|
|||||||
#define DECORATOR_CHANGED 'dcch'
|
#define DECORATOR_CHANGED 'dcch'
|
||||||
|
|
||||||
|
|
||||||
APRView::APRView(const char* name, uint32 flags)
|
APRView::APRView(const char* name)
|
||||||
:
|
:
|
||||||
BView(name, flags),
|
BView(name, B_WILL_DRAW),
|
||||||
fDefaultSet(ColorSet::DefaultColorSet())
|
fDefaultSet(ColorSet::DefaultColorSet())
|
||||||
{
|
{
|
||||||
SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR));
|
SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR));
|
||||||
@@ -136,7 +136,7 @@ APRView::MessageReceived(BMessage *msg)
|
|||||||
|
|
||||||
if (msg->FindData("RGBColor", (type_code)'RGBC', (const void**)&color,
|
if (msg->FindData("RGBColor", (type_code)'RGBC', (const void**)&color,
|
||||||
&size) == B_OK) {
|
&size) == B_OK) {
|
||||||
SetCurrentColor(*color);
|
_SetCurrentColor(*color);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -145,7 +145,7 @@ APRView::MessageReceived(BMessage *msg)
|
|||||||
{
|
{
|
||||||
// Received from the color fPicker when its color changes
|
// Received from the color fPicker when its color changes
|
||||||
rgb_color color = fPicker->ValueAsColor();
|
rgb_color color = fPicker->ValueAsColor();
|
||||||
SetCurrentColor(color);
|
_SetCurrentColor(color);
|
||||||
|
|
||||||
Window()->PostMessage(kMsgUpdate);
|
Window()->PostMessage(kMsgUpdate);
|
||||||
break;
|
break;
|
||||||
@@ -161,27 +161,7 @@ APRView::MessageReceived(BMessage *msg)
|
|||||||
|
|
||||||
fWhich = item->ColorWhich();
|
fWhich = item->ColorWhich();
|
||||||
rgb_color color = fCurrentSet.GetColor(fWhich);
|
rgb_color color = fCurrentSet.GetColor(fWhich);
|
||||||
SetCurrentColor(color);
|
_SetCurrentColor(color);
|
||||||
|
|
||||||
Window()->PostMessage(kMsgUpdate);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case REVERT_SETTINGS:
|
|
||||||
{
|
|
||||||
fCurrentSet = fPrevSet;
|
|
||||||
|
|
||||||
UpdateControls();
|
|
||||||
UpdateAllColors();
|
|
||||||
|
|
||||||
Window()->PostMessage(kMsgUpdate);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case DEFAULT_SETTINGS:
|
|
||||||
{
|
|
||||||
fCurrentSet = ColorSet::DefaultColorSet();
|
|
||||||
|
|
||||||
UpdateControls();
|
|
||||||
UpdateAllColors();
|
|
||||||
|
|
||||||
Window()->PostMessage(kMsgUpdate);
|
Window()->PostMessage(kMsgUpdate);
|
||||||
break;
|
break;
|
||||||
@@ -205,6 +185,30 @@ APRView::LoadSettings()
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
APRView::SetDefaults()
|
||||||
|
{
|
||||||
|
fCurrentSet = ColorSet::DefaultColorSet();
|
||||||
|
|
||||||
|
_UpdateControls();
|
||||||
|
_UpdateAllColors();
|
||||||
|
|
||||||
|
Window()->PostMessage(kMsgUpdate);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
APRView::Revert()
|
||||||
|
{
|
||||||
|
fCurrentSet = fPrevSet;
|
||||||
|
|
||||||
|
_UpdateControls();
|
||||||
|
_UpdateAllColors();
|
||||||
|
|
||||||
|
Window()->PostMessage(kMsgUpdate);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
bool
|
bool
|
||||||
APRView::IsDefaultable()
|
APRView::IsDefaultable()
|
||||||
{
|
{
|
||||||
@@ -217,8 +221,39 @@ APRView::IsDefaultable()
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool
|
||||||
|
APRView::IsRevertable()
|
||||||
|
{
|
||||||
|
for (int32 i = 0; i < color_description_count(); i++) {
|
||||||
|
color_which which = get_color_description(i)->which;
|
||||||
|
if (fCurrentSet.GetColor(which) != fPrevSet.GetColor(which))
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
APRView::UpdateAllColors()
|
APRView::_SetCurrentColor(rgb_color color)
|
||||||
|
{
|
||||||
|
fCurrentSet.SetColor(fWhich, color);
|
||||||
|
set_ui_color(fWhich, color);
|
||||||
|
_UpdateControls();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
APRView::_UpdateControls()
|
||||||
|
{
|
||||||
|
rgb_color color = fCurrentSet.GetColor(fWhich);
|
||||||
|
fPicker->SetValue(color);
|
||||||
|
fColorWell->SetColor(color);
|
||||||
|
fColorWell->Invalidate();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
APRView::_UpdateAllColors()
|
||||||
{
|
{
|
||||||
for (int32 i = 0; i < color_description_count(); i++) {
|
for (int32 i = 0; i < color_description_count(); i++) {
|
||||||
color_which which = get_color_description(i)->which;
|
color_which which = get_color_description(i)->which;
|
||||||
@@ -226,22 +261,3 @@ APRView::UpdateAllColors()
|
|||||||
set_ui_color(which, color);
|
set_ui_color(which, color);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
|
||||||
APRView::SetCurrentColor(rgb_color color)
|
|
||||||
{
|
|
||||||
fCurrentSet.SetColor(fWhich, color);
|
|
||||||
set_ui_color(fWhich, color);
|
|
||||||
UpdateControls();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void
|
|
||||||
APRView::UpdateControls()
|
|
||||||
{
|
|
||||||
rgb_color color = fCurrentSet.GetColor(fWhich);
|
|
||||||
fPicker->SetValue(color);
|
|
||||||
fColorWell->SetColor(color);
|
|
||||||
fColorWell->Invalidate();
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -1,10 +1,11 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2002-2008, Haiku. All rights reserved.
|
* Copyright 2002-2012, Haiku. All rights reserved.
|
||||||
* Distributed under the terms of the MIT License.
|
* Distributed under the terms of the MIT License.
|
||||||
*
|
*
|
||||||
* Authors:
|
* Authors:
|
||||||
* DarkWyrm ([email protected])
|
* DarkWyrm ([email protected])
|
||||||
* Rene Gollent ([email protected])
|
* Rene Gollent ([email protected])
|
||||||
|
* Stephan Aßmus <[email protected]>
|
||||||
*/
|
*/
|
||||||
#ifndef APR_VIEW_H_
|
#ifndef APR_VIEW_H_
|
||||||
#define APR_VIEW_H_
|
#define APR_VIEW_H_
|
||||||
@@ -36,29 +37,35 @@ class APRWindow;
|
|||||||
|
|
||||||
class APRView : public BView {
|
class APRView : public BView {
|
||||||
public:
|
public:
|
||||||
APRView(const char *name, uint32 flags);
|
APRView(const char *name);
|
||||||
~APRView(void);
|
virtual ~APRView();
|
||||||
void AttachedToWindow(void);
|
|
||||||
void MessageReceived(BMessage *msg);
|
|
||||||
|
|
||||||
void LoadSettings(void);
|
virtual void AttachedToWindow();
|
||||||
bool IsDefaultable(void);
|
virtual void MessageReceived(BMessage *msg);
|
||||||
|
|
||||||
protected:
|
void LoadSettings();
|
||||||
|
|
||||||
void SetCurrentColor(rgb_color color);
|
void SetDefaults();
|
||||||
void UpdateControls();
|
void Revert();
|
||||||
void UpdateAllColors();
|
|
||||||
|
|
||||||
BColorControl *fPicker;
|
bool IsDefaultable();
|
||||||
|
bool IsRevertable();
|
||||||
|
|
||||||
BListView *fAttrList;
|
private:
|
||||||
|
void _SetCurrentColor(rgb_color color);
|
||||||
|
void _UpdateControls();
|
||||||
|
void _UpdateAllColors();
|
||||||
|
|
||||||
|
private:
|
||||||
|
BColorControl* fPicker;
|
||||||
|
|
||||||
|
BListView* fAttrList;
|
||||||
|
|
||||||
color_which fWhich;
|
color_which fWhich;
|
||||||
|
|
||||||
BScrollView *fScrollView;
|
BScrollView* fScrollView;
|
||||||
|
|
||||||
ColorWell *fColorWell;
|
ColorWell* fColorWell;
|
||||||
|
|
||||||
ColorSet fCurrentSet;
|
ColorSet fCurrentSet;
|
||||||
ColorSet fPrevSet;
|
ColorSet fPrevSet;
|
||||||
|
|||||||
@@ -5,6 +5,7 @@
|
|||||||
* Authors:
|
* Authors:
|
||||||
* DarkWyrm ([email protected])
|
* DarkWyrm ([email protected])
|
||||||
* Alexander von Gluck, [email protected]
|
* Alexander von Gluck, [email protected]
|
||||||
|
* Stephan Aßmus <[email protected]>
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
@@ -18,8 +19,11 @@
|
|||||||
#include <SpaceLayoutItem.h>
|
#include <SpaceLayoutItem.h>
|
||||||
#include <TabView.h>
|
#include <TabView.h>
|
||||||
|
|
||||||
|
#include "AntialiasingSettingsView.h"
|
||||||
#include "APRView.h"
|
#include "APRView.h"
|
||||||
|
#include "DecorSettingsView.h"
|
||||||
#include "defs.h"
|
#include "defs.h"
|
||||||
|
#include "FontView.h"
|
||||||
|
|
||||||
|
|
||||||
#undef B_TRANSLATE_CONTEXT
|
#undef B_TRANSLATE_CONTEXT
|
||||||
@@ -33,9 +37,9 @@ static const uint32 kMsgRevert = 'rvrt';
|
|||||||
APRWindow::APRWindow(BRect frame)
|
APRWindow::APRWindow(BRect frame)
|
||||||
:
|
:
|
||||||
BWindow(frame, B_TRANSLATE_SYSTEM_NAME("Appearance"), B_TITLED_WINDOW,
|
BWindow(frame, B_TRANSLATE_SYSTEM_NAME("Appearance"), B_TITLED_WINDOW,
|
||||||
B_NOT_ZOOMABLE | B_AUTO_UPDATE_SIZE_LIMITS, B_ALL_WORKSPACES)
|
B_NOT_ZOOMABLE | B_AUTO_UPDATE_SIZE_LIMITS | B_QUIT_ON_WINDOW_CLOSE,
|
||||||
|
B_ALL_WORKSPACES)
|
||||||
{
|
{
|
||||||
|
|
||||||
SetLayout(new BGroupLayout(B_HORIZONTAL));
|
SetLayout(new BGroupLayout(B_HORIZONTAL));
|
||||||
|
|
||||||
fDefaultsButton = new BButton("defaults", B_TRANSLATE("Defaults"),
|
fDefaultsButton = new BButton("defaults", B_TRANSLATE("Defaults"),
|
||||||
@@ -46,22 +50,22 @@ APRWindow::APRWindow(BRect frame)
|
|||||||
|
|
||||||
BTabView* tabView = new BTabView("tabview", B_WIDTH_FROM_LABEL);
|
BTabView* tabView = new BTabView("tabview", B_WIDTH_FROM_LABEL);
|
||||||
|
|
||||||
fAntialiasingSettings = new AntialiasingSettingsView(
|
fFontSettings = new FontView(B_TRANSLATE("Fonts"));
|
||||||
B_TRANSLATE("Antialiasing"));
|
|
||||||
|
fColorsView = new APRView(B_TRANSLATE("Colors"));
|
||||||
|
|
||||||
fDecorSettings = new DecorSettingsView(
|
fDecorSettings = new DecorSettingsView(
|
||||||
B_TRANSLATE("Window Decorator"));
|
B_TRANSLATE("Window Decorator"));
|
||||||
|
|
||||||
fColorsView = new APRView(B_TRANSLATE("Colors"), B_WILL_DRAW);
|
fAntialiasingSettings = new AntialiasingSettingsView(
|
||||||
|
B_TRANSLATE("Antialiasing"));
|
||||||
|
|
||||||
|
tabView->AddTab(fFontSettings);
|
||||||
tabView->AddTab(fColorsView);
|
tabView->AddTab(fColorsView);
|
||||||
tabView->AddTab(fAntialiasingSettings);
|
|
||||||
tabView->AddTab(fDecorSettings);
|
tabView->AddTab(fDecorSettings);
|
||||||
|
tabView->AddTab(fAntialiasingSettings);
|
||||||
|
|
||||||
fDefaultsButton->SetEnabled(fColorsView->IsDefaultable()
|
_UpdateButtons();
|
||||||
|| fAntialiasingSettings->IsDefaultable()
|
|
||||||
|| fDecorSettings->IsDefaultable());
|
|
||||||
fRevertButton->SetEnabled(false);
|
|
||||||
|
|
||||||
AddChild(BGroupLayoutBuilder(B_VERTICAL, 0)
|
AddChild(BGroupLayoutBuilder(B_VERTICAL, 0)
|
||||||
.Add(tabView)
|
.Add(tabView)
|
||||||
@@ -81,23 +85,25 @@ APRWindow::MessageReceived(BMessage *message)
|
|||||||
{
|
{
|
||||||
switch (message->what) {
|
switch (message->what) {
|
||||||
case kMsgUpdate:
|
case kMsgUpdate:
|
||||||
fDefaultsButton->SetEnabled(fColorsView->IsDefaultable()
|
_UpdateButtons();
|
||||||
|| fAntialiasingSettings->IsDefaultable());
|
|
||||||
fRevertButton->SetEnabled(true);
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case kMsgSetDefaults:
|
case kMsgSetDefaults:
|
||||||
fColorsView -> MessageReceived(new BMessage(DEFAULT_SETTINGS));
|
fFontSettings->SetDefaults();
|
||||||
|
fColorsView->SetDefaults();
|
||||||
fAntialiasingSettings->SetDefaults();
|
fAntialiasingSettings->SetDefaults();
|
||||||
fDefaultsButton->SetEnabled(false);
|
fDecorSettings->SetDefaults();
|
||||||
fRevertButton->SetEnabled(true);
|
|
||||||
|
_UpdateButtons();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case kMsgRevert:
|
case kMsgRevert:
|
||||||
fColorsView -> MessageReceived(new BMessage(REVERT_SETTINGS));
|
fColorsView->Revert();
|
||||||
fAntialiasingSettings->Revert();
|
fAntialiasingSettings->Revert();
|
||||||
fDefaultsButton->SetEnabled(fColorsView->IsDefaultable()
|
fFontSettings->Revert();
|
||||||
|| fAntialiasingSettings->IsDefaultable());
|
fDecorSettings->Revert();
|
||||||
fRevertButton->SetEnabled(false);
|
|
||||||
|
_UpdateButtons();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
@@ -107,9 +113,37 @@ APRWindow::MessageReceived(BMessage *message)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool
|
void
|
||||||
APRWindow::QuitRequested(void)
|
APRWindow::_UpdateButtons()
|
||||||
{
|
{
|
||||||
be_app->PostMessage(B_QUIT_REQUESTED);
|
fDefaultsButton->SetEnabled(_IsDefaultable());
|
||||||
return(true);
|
fRevertButton->SetEnabled(_IsRevertable());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool
|
||||||
|
APRWindow::_IsDefaultable() const
|
||||||
|
{
|
||||||
|
// printf("fonts defaultable: %d\n", fFontSettings->IsDefaultable());
|
||||||
|
// printf("colors defaultable: %d\n", fColorsView->IsDefaultable());
|
||||||
|
// printf("AA defaultable: %d\n", fAntialiasingSettings->IsDefaultable());
|
||||||
|
// printf("decor defaultable: %d\n", fDecorSettings->IsDefaultable());
|
||||||
|
return fColorsView->IsDefaultable()
|
||||||
|
|| fFontSettings->IsDefaultable()
|
||||||
|
|| fAntialiasingSettings->IsDefaultable()
|
||||||
|
|| fDecorSettings->IsDefaultable();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool
|
||||||
|
APRWindow::_IsRevertable() const
|
||||||
|
{
|
||||||
|
// printf("fonts revertable: %d\n", fFontSettings->IsRevertable());
|
||||||
|
// printf("colors revertable: %d\n", fColorsView->IsRevertable());
|
||||||
|
// printf("AA revertable: %d\n", fAntialiasingSettings->IsRevertable());
|
||||||
|
// printf("decor revertable: %d\n", fDecorSettings->IsRevertable());
|
||||||
|
return fColorsView->IsRevertable()
|
||||||
|
|| fFontSettings->IsRevertable()
|
||||||
|
|| fAntialiasingSettings->IsRevertable()
|
||||||
|
|| fDecorSettings->IsRevertable();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,10 +1,11 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2002-2011, Haiku. All rights reserved.
|
* Copyright 2002-2012, Haiku. All rights reserved.
|
||||||
* Distributed under the terms of the MIT License.
|
* Distributed under the terms of the MIT License.
|
||||||
*
|
*
|
||||||
* Authors:
|
* Authors:
|
||||||
* DarkWyrm ([email protected])
|
* DarkWyrm ([email protected])
|
||||||
* Alexander von Gluck, [email protected]
|
* Alexander von Gluck, [email protected]
|
||||||
|
* Stephan Aßmus <[email protected]>
|
||||||
*/
|
*/
|
||||||
#ifndef APR_WINDOW_H
|
#ifndef APR_WINDOW_H
|
||||||
#define APR_WINDOW_H
|
#define APR_WINDOW_H
|
||||||
@@ -16,27 +17,32 @@
|
|||||||
#include <Message.h>
|
#include <Message.h>
|
||||||
#include <TabView.h>
|
#include <TabView.h>
|
||||||
|
|
||||||
#include "APRView.h"
|
class APRView;
|
||||||
#include "AntialiasingSettingsView.h"
|
class AntialiasingSettingsView;
|
||||||
#include "DecorSettingsView.h"
|
class FontView;
|
||||||
|
class DecorSettingsView;
|
||||||
|
|
||||||
|
|
||||||
class APRWindow : public BWindow
|
class APRWindow : public BWindow {
|
||||||
{
|
|
||||||
public:
|
public:
|
||||||
APRWindow(BRect frame);
|
APRWindow(BRect frame);
|
||||||
bool QuitRequested(void);
|
|
||||||
void MessageReceived(BMessage *message);
|
void MessageReceived(BMessage *message);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
void _UpdateButtons();
|
||||||
|
bool _IsDefaultable() const;
|
||||||
|
bool _IsRevertable() const;
|
||||||
|
|
||||||
APRView* fColorsView;
|
APRView* fColorsView;
|
||||||
BButton* fDefaultsButton;
|
BButton* fDefaultsButton;
|
||||||
BButton* fRevertButton;
|
BButton* fRevertButton;
|
||||||
|
|
||||||
AntialiasingSettingsView* fAntialiasingSettings;
|
AntialiasingSettingsView* fAntialiasingSettings;
|
||||||
|
FontView* fFontSettings;
|
||||||
DecorSettingsView* fDecorSettings;
|
DecorSettingsView* fDecorSettings;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
static const int32 kMsgUpdate = 'updt';
|
static const int32 kMsgUpdate = 'updt';
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,494 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2001-2011, Haiku.
|
||||||
|
* Distributed under the terms of the MIT License.
|
||||||
|
*
|
||||||
|
* Authors:
|
||||||
|
* Mark Hogben
|
||||||
|
* DarkWyrm <[email protected]>
|
||||||
|
* Axel Dörfler, [email protected]
|
||||||
|
* Philippe Saint-Pierre, [email protected]
|
||||||
|
* Stephan Aßmus <[email protected]>
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "FontSelectionView.h"
|
||||||
|
|
||||||
|
#include <Box.h>
|
||||||
|
#include <Catalog.h>
|
||||||
|
#include <Locale.h>
|
||||||
|
#include <MenuField.h>
|
||||||
|
#include <MenuItem.h>
|
||||||
|
#include <PopUpMenu.h>
|
||||||
|
#include <String.h>
|
||||||
|
#include <StringView.h>
|
||||||
|
#include <LayoutItem.h>
|
||||||
|
#include <GroupLayoutBuilder.h>
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
|
|
||||||
|
#undef B_TRANSLATE_CONTEXT
|
||||||
|
#define B_TRANSLATE_CONTEXT "Font Selection view"
|
||||||
|
|
||||||
|
|
||||||
|
#define INSTANT_UPDATE
|
||||||
|
// if defined, the system font will be updated immediately, and not
|
||||||
|
// only on exit
|
||||||
|
|
||||||
|
static const float kMinSize = 8.0;
|
||||||
|
static const float kMaxSize = 18.0;
|
||||||
|
|
||||||
|
|
||||||
|
// private font API
|
||||||
|
extern void _set_system_font_(const char *which, font_family family,
|
||||||
|
font_style style, float size);
|
||||||
|
extern status_t _get_system_default_font_(const char* which,
|
||||||
|
font_family family, font_style style, float* _size);
|
||||||
|
|
||||||
|
|
||||||
|
#ifdef B_BEOS_VERSION_DANO
|
||||||
|
// this call only exists under R5
|
||||||
|
void
|
||||||
|
_set_system_font_(const char *which, font_family family,
|
||||||
|
font_style style, float size)
|
||||||
|
{
|
||||||
|
puts("you don't have _set_system_font_()");
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if !defined(HAIKU_TARGET_PLATFORM_HAIKU) && !defined(HAIKU_TARGET_PLATFORM_LIBBE_TEST)
|
||||||
|
// this call only exists under Haiku (and the test environment)
|
||||||
|
status_t
|
||||||
|
_get_system_default_font_(const char* which, font_family family,
|
||||||
|
font_style style, float* _size)
|
||||||
|
{
|
||||||
|
puts("you don't have _get_system_default_font_()");
|
||||||
|
return B_ERROR;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
// #pragma mark -
|
||||||
|
|
||||||
|
|
||||||
|
FontSelectionView::FontSelectionView(const char* name,
|
||||||
|
const char* label, const BFont* currentFont)
|
||||||
|
:
|
||||||
|
BView(name, B_WILL_DRAW),
|
||||||
|
fMessageTarget(this)
|
||||||
|
{
|
||||||
|
if (currentFont == NULL) {
|
||||||
|
if (!strcmp(Name(), "plain"))
|
||||||
|
fCurrentFont = *be_plain_font;
|
||||||
|
else if (!strcmp(Name(), "bold"))
|
||||||
|
fCurrentFont = *be_bold_font;
|
||||||
|
else if (!strcmp(Name(), "fixed"))
|
||||||
|
fCurrentFont = *be_fixed_font;
|
||||||
|
else if (!strcmp(Name(), "menu")) {
|
||||||
|
menu_info info;
|
||||||
|
get_menu_info(&info);
|
||||||
|
|
||||||
|
fCurrentFont.SetFamilyAndStyle(info.f_family, info.f_style);
|
||||||
|
fCurrentFont.SetSize(info.font_size);
|
||||||
|
}
|
||||||
|
} else
|
||||||
|
fCurrentFont = *currentFont;
|
||||||
|
|
||||||
|
fSavedFont = fCurrentFont;
|
||||||
|
|
||||||
|
fSizesMenu = new BPopUpMenu("size menu");
|
||||||
|
_BuildSizesMenu();
|
||||||
|
|
||||||
|
fFontsMenu = new BPopUpMenu("font menu");
|
||||||
|
|
||||||
|
// font menu
|
||||||
|
fFontsMenuField = new BMenuField("fonts", label, fFontsMenu);
|
||||||
|
fFontsMenuField->SetAlignment(B_ALIGN_RIGHT);
|
||||||
|
|
||||||
|
// size menu
|
||||||
|
fSizesMenuField = new BMenuField("size", B_TRANSLATE("Size:"), fSizesMenu);
|
||||||
|
fSizesMenuField->SetAlignment(B_ALIGN_RIGHT);
|
||||||
|
|
||||||
|
// preview
|
||||||
|
fPreviewText = new BStringView("preview text",
|
||||||
|
B_TRANSLATE_COMMENT("The quick brown fox jumps over the lazy dog.",
|
||||||
|
"Don't translate this literally ! Use a phrase showing all chars "
|
||||||
|
"from A to Z."));
|
||||||
|
|
||||||
|
fPreviewText->SetFont(&fCurrentFont);
|
||||||
|
fPreviewText->SetExplicitMaxSize(BSize(B_SIZE_UNLIMITED, B_SIZE_UNSET));
|
||||||
|
|
||||||
|
// box around preview
|
||||||
|
fPreviewBox = new BBox("preview box", B_WILL_DRAW | B_FRAME_EVENTS);
|
||||||
|
fPreviewBox->AddChild(BGroupLayoutBuilder(B_HORIZONTAL)
|
||||||
|
.Add(fPreviewText)
|
||||||
|
.SetInsets(5, 5, 5, 5)
|
||||||
|
.TopView()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
FontSelectionView::~FontSelectionView()
|
||||||
|
{
|
||||||
|
#ifndef INSTANT_UPDATE
|
||||||
|
_UpdateSystemFont();
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
FontSelectionView::SetTarget(BHandler* messageTarget)
|
||||||
|
{
|
||||||
|
fMessageTarget = messageTarget;
|
||||||
|
fSizesMenu->SetTargetForItems(fMessageTarget);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
BView*
|
||||||
|
FontSelectionView::GetPreviewBox()
|
||||||
|
{
|
||||||
|
return fPreviewBox;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
FontSelectionView::MessageReceived(BMessage *msg)
|
||||||
|
{
|
||||||
|
switch (msg->what) {
|
||||||
|
case kMsgSetSize:
|
||||||
|
{
|
||||||
|
int32 size;
|
||||||
|
if (msg->FindInt32("size", &size) != B_OK
|
||||||
|
|| size == fCurrentFont.Size())
|
||||||
|
break;
|
||||||
|
|
||||||
|
fCurrentFont.SetSize(size);
|
||||||
|
_UpdateFontPreview();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
case kMsgSetFamily:
|
||||||
|
{
|
||||||
|
const char* family;
|
||||||
|
if (msg->FindString("family", &family) != B_OK)
|
||||||
|
break;
|
||||||
|
|
||||||
|
font_style style;
|
||||||
|
fCurrentFont.GetFamilyAndStyle(NULL, &style);
|
||||||
|
|
||||||
|
BMenuItem *familyItem = fFontsMenu->FindItem(family);
|
||||||
|
if (familyItem != NULL) {
|
||||||
|
_SelectCurrentFont(false);
|
||||||
|
|
||||||
|
BMenuItem *item = familyItem->Submenu()->FindItem(style);
|
||||||
|
if (item == NULL)
|
||||||
|
item = familyItem->Submenu()->ItemAt(0);
|
||||||
|
|
||||||
|
if (item != NULL) {
|
||||||
|
item->SetMarked(true);
|
||||||
|
fCurrentFont.SetFamilyAndStyle(family, item->Label());
|
||||||
|
_UpdateFontPreview();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
case kMsgSetStyle:
|
||||||
|
{
|
||||||
|
const char* family;
|
||||||
|
const char* style;
|
||||||
|
if (msg->FindString("family", &family) != B_OK
|
||||||
|
|| msg->FindString("style", &style) != B_OK)
|
||||||
|
break;
|
||||||
|
|
||||||
|
BMenuItem *familyItem = fFontsMenu->FindItem(family);
|
||||||
|
if (!familyItem)
|
||||||
|
break;
|
||||||
|
|
||||||
|
_SelectCurrentFont(false);
|
||||||
|
familyItem->SetMarked(true);
|
||||||
|
|
||||||
|
fCurrentFont.SetFamilyAndStyle(family, style);
|
||||||
|
_UpdateFontPreview();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
default:
|
||||||
|
BView::MessageReceived(msg);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
BLayoutItem*
|
||||||
|
FontSelectionView::CreateSizesLabelLayoutItem()
|
||||||
|
{
|
||||||
|
return fSizesMenuField->CreateLabelLayoutItem();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
BLayoutItem*
|
||||||
|
FontSelectionView::CreateSizesMenuBarLayoutItem()
|
||||||
|
{
|
||||||
|
return fSizesMenuField->CreateMenuBarLayoutItem();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
BLayoutItem*
|
||||||
|
FontSelectionView::CreateFontsLabelLayoutItem()
|
||||||
|
{
|
||||||
|
return fFontsMenuField->CreateLabelLayoutItem();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
BLayoutItem*
|
||||||
|
FontSelectionView::CreateFontsMenuBarLayoutItem()
|
||||||
|
{
|
||||||
|
return fFontsMenuField->CreateMenuBarLayoutItem();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
FontSelectionView::_BuildSizesMenu()
|
||||||
|
{
|
||||||
|
const int32 sizes[] = {7, 8, 9, 10, 11, 12, 13, 14, 18, 21, 24, 0};
|
||||||
|
|
||||||
|
// build size menu
|
||||||
|
for (int32 i = 0; sizes[i]; i++) {
|
||||||
|
int32 size = sizes[i];
|
||||||
|
if (size < kMinSize || size > kMaxSize)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
char label[32];
|
||||||
|
snprintf(label, sizeof(label), "%ld", size);
|
||||||
|
|
||||||
|
BMessage* message = new BMessage(kMsgSetSize);
|
||||||
|
message->AddInt32("size", size);
|
||||||
|
message->AddString("name", Name());
|
||||||
|
|
||||||
|
BMenuItem* item = new BMenuItem(label, message);
|
||||||
|
if (size == fCurrentFont.Size())
|
||||||
|
item->SetMarked(true);
|
||||||
|
|
||||||
|
fSizesMenu->AddItem(item);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
FontSelectionView::_SelectCurrentFont(bool select)
|
||||||
|
{
|
||||||
|
font_family family;
|
||||||
|
font_style style;
|
||||||
|
fCurrentFont.GetFamilyAndStyle(&family, &style);
|
||||||
|
|
||||||
|
BMenuItem *item = fFontsMenu->FindItem(family);
|
||||||
|
if (item != NULL) {
|
||||||
|
item->SetMarked(select);
|
||||||
|
|
||||||
|
if (item->Submenu() != NULL) {
|
||||||
|
item = item->Submenu()->FindItem(style);
|
||||||
|
if (item != NULL)
|
||||||
|
item->SetMarked(select);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
FontSelectionView::_SelectCurrentSize(bool select)
|
||||||
|
{
|
||||||
|
char label[16];
|
||||||
|
snprintf(label, sizeof(label), "%ld", (int32)fCurrentFont.Size());
|
||||||
|
|
||||||
|
BMenuItem* item = fSizesMenu->FindItem(label);
|
||||||
|
if (item != NULL)
|
||||||
|
item->SetMarked(select);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
FontSelectionView::_UpdateFontPreview()
|
||||||
|
{
|
||||||
|
fPreviewText->SetFont(&fCurrentFont);
|
||||||
|
|
||||||
|
#ifdef INSTANT_UPDATE
|
||||||
|
_UpdateSystemFont();
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
FontSelectionView::_UpdateSystemFont()
|
||||||
|
{
|
||||||
|
font_family family;
|
||||||
|
font_style style;
|
||||||
|
fCurrentFont.GetFamilyAndStyle(&family, &style);
|
||||||
|
|
||||||
|
if (strcmp(Name(), "menu") == 0) {
|
||||||
|
// The menu font is not handled as a system font
|
||||||
|
menu_info info;
|
||||||
|
get_menu_info(&info);
|
||||||
|
|
||||||
|
strlcpy(info.f_family, (const char*)family, B_FONT_FAMILY_LENGTH);
|
||||||
|
strlcpy(info.f_style, (const char*)style, B_FONT_STYLE_LENGTH);
|
||||||
|
info.font_size = fCurrentFont.Size();
|
||||||
|
|
||||||
|
set_menu_info(&info);
|
||||||
|
} else
|
||||||
|
_set_system_font_(Name(), family, style, fCurrentFont.Size());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
FontSelectionView::SetDefaults()
|
||||||
|
{
|
||||||
|
font_family family;
|
||||||
|
font_style style;
|
||||||
|
float size;
|
||||||
|
const char* fontName;
|
||||||
|
|
||||||
|
if (strcmp(Name(), "menu") == 0)
|
||||||
|
fontName = "plain";
|
||||||
|
else
|
||||||
|
fontName = Name();
|
||||||
|
|
||||||
|
if (_get_system_default_font_(fontName, family, style, &size) != B_OK) {
|
||||||
|
Revert();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
BFont defaultFont;
|
||||||
|
defaultFont.SetFamilyAndStyle(family, style);
|
||||||
|
defaultFont.SetSize(size);
|
||||||
|
|
||||||
|
if (defaultFont == fCurrentFont)
|
||||||
|
return;
|
||||||
|
|
||||||
|
_SelectCurrentFont(false);
|
||||||
|
|
||||||
|
fCurrentFont = defaultFont;
|
||||||
|
_UpdateFontPreview();
|
||||||
|
|
||||||
|
_SelectCurrentFont(true);
|
||||||
|
_SelectCurrentSize(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
FontSelectionView::Revert()
|
||||||
|
{
|
||||||
|
if (!IsRevertable())
|
||||||
|
return;
|
||||||
|
|
||||||
|
_SelectCurrentFont(false);
|
||||||
|
|
||||||
|
fCurrentFont = fSavedFont;
|
||||||
|
_UpdateFontPreview();
|
||||||
|
|
||||||
|
_SelectCurrentFont(true);
|
||||||
|
_SelectCurrentSize(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool
|
||||||
|
FontSelectionView::IsDefaultable()
|
||||||
|
{
|
||||||
|
font_family defaultFamily;
|
||||||
|
font_style defaultStyle;
|
||||||
|
float defaultSize;
|
||||||
|
const char* fontName;
|
||||||
|
|
||||||
|
if (strcmp(Name(), "menu") == 0)
|
||||||
|
fontName = "plain";
|
||||||
|
else
|
||||||
|
fontName = Name();
|
||||||
|
|
||||||
|
if (_get_system_default_font_(fontName, defaultFamily, defaultStyle,
|
||||||
|
&defaultSize) != B_OK) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
font_family currentFamily;
|
||||||
|
font_style currentStyle;
|
||||||
|
float currentSize;
|
||||||
|
|
||||||
|
fCurrentFont.GetFamilyAndStyle(¤tFamily, ¤tStyle);
|
||||||
|
currentSize = fCurrentFont.Size();
|
||||||
|
|
||||||
|
return strcmp(currentFamily, defaultFamily) != 0
|
||||||
|
|| strcmp(currentStyle, defaultStyle) != 0
|
||||||
|
|| currentSize != defaultSize;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool
|
||||||
|
FontSelectionView::IsRevertable()
|
||||||
|
{
|
||||||
|
return fCurrentFont != fSavedFont;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
FontSelectionView::UpdateFontsMenu()
|
||||||
|
{
|
||||||
|
int32 numFamilies = count_font_families();
|
||||||
|
|
||||||
|
fFontsMenu->RemoveItems(0, fFontsMenu->CountItems(), true);
|
||||||
|
BFont font;
|
||||||
|
fFontsMenu->GetFont(&font);
|
||||||
|
|
||||||
|
font_family currentFamily;
|
||||||
|
font_style currentStyle;
|
||||||
|
fCurrentFont.GetFamilyAndStyle(¤tFamily, ¤tStyle);
|
||||||
|
|
||||||
|
for (int32 i = 0; i < numFamilies; i++) {
|
||||||
|
font_family family;
|
||||||
|
uint32 flags;
|
||||||
|
if (get_font_family(i, &family, &flags) != B_OK)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
// if we're setting the fixed font, we only want to show fixed fonts
|
||||||
|
if (!strcmp(Name(), "fixed") && (flags & B_IS_FIXED) == 0)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
float width = font.StringWidth(family);
|
||||||
|
if (width > fMaxFontNameWidth)
|
||||||
|
fMaxFontNameWidth = width;
|
||||||
|
|
||||||
|
BMenu* stylesMenu = new BMenu(family);
|
||||||
|
stylesMenu->SetRadioMode(true);
|
||||||
|
stylesMenu->SetFont(&font);
|
||||||
|
|
||||||
|
BMessage* message = new BMessage(kMsgSetFamily);
|
||||||
|
message->AddString("family", family);
|
||||||
|
message->AddString("name", Name());
|
||||||
|
|
||||||
|
BMenuItem* familyItem = new BMenuItem(stylesMenu, message);
|
||||||
|
fFontsMenu->AddItem(familyItem);
|
||||||
|
|
||||||
|
int32 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)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
message = new BMessage(kMsgSetStyle);
|
||||||
|
message->AddString("family", (char*)family);
|
||||||
|
message->AddString("style", (char*)style);
|
||||||
|
message->AddString("name", Name());
|
||||||
|
|
||||||
|
BMenuItem *item = new BMenuItem(style, message);
|
||||||
|
|
||||||
|
if (!strcmp(style, currentStyle)
|
||||||
|
&& !strcmp(family, currentFamily)) {
|
||||||
|
item->SetMarked(true);
|
||||||
|
familyItem->SetMarked(true);
|
||||||
|
}
|
||||||
|
stylesMenu->AddItem(item);
|
||||||
|
}
|
||||||
|
|
||||||
|
stylesMenu->SetTargetForItems(fMessageTarget);
|
||||||
|
}
|
||||||
|
|
||||||
|
fFontsMenu->SetTargetForItems(fMessageTarget);
|
||||||
|
}
|
||||||
@@ -0,0 +1,77 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2001-2009, Haiku.
|
||||||
|
* Distributed under the terms of the MIT License.
|
||||||
|
*
|
||||||
|
* Authors:
|
||||||
|
* Mark Hogben
|
||||||
|
* DarkWyrm <[email protected]>
|
||||||
|
* Axel Dörfler, [email protected]
|
||||||
|
* Philippe Saint-Pierre, [email protected]
|
||||||
|
*/
|
||||||
|
#ifndef FONT_SELECTION_VIEW_H
|
||||||
|
#define FONT_SELECTION_VIEW_H
|
||||||
|
|
||||||
|
|
||||||
|
#include <View.h>
|
||||||
|
|
||||||
|
class BLayoutItem;
|
||||||
|
class BBox;
|
||||||
|
class BMenuField;
|
||||||
|
class BPopUpMenu;
|
||||||
|
class BStringView;
|
||||||
|
|
||||||
|
static const int32 kMsgSetFamily = 'fmly';
|
||||||
|
static const int32 kMsgSetStyle = 'styl';
|
||||||
|
static const int32 kMsgSetSize = 'size';
|
||||||
|
|
||||||
|
|
||||||
|
class FontSelectionView : public BView {
|
||||||
|
public:
|
||||||
|
FontSelectionView(const char* name,
|
||||||
|
const char* label,
|
||||||
|
const BFont* font = NULL);
|
||||||
|
virtual ~FontSelectionView();
|
||||||
|
|
||||||
|
virtual void MessageReceived(BMessage* message);
|
||||||
|
|
||||||
|
void SetTarget(BHandler* messageTarget);
|
||||||
|
|
||||||
|
void SetDefaults();
|
||||||
|
void Revert();
|
||||||
|
bool IsDefaultable();
|
||||||
|
bool IsRevertable();
|
||||||
|
|
||||||
|
void UpdateFontsMenu();
|
||||||
|
|
||||||
|
BLayoutItem* CreateSizesLabelLayoutItem();
|
||||||
|
BLayoutItem* CreateSizesMenuBarLayoutItem();
|
||||||
|
|
||||||
|
BLayoutItem* CreateFontsLabelLayoutItem();
|
||||||
|
BLayoutItem* CreateFontsMenuBarLayoutItem();
|
||||||
|
|
||||||
|
BView* GetPreviewBox();
|
||||||
|
|
||||||
|
private:
|
||||||
|
void _SelectCurrentFont(bool select);
|
||||||
|
void _SelectCurrentSize(bool select);
|
||||||
|
void _UpdateFontPreview();
|
||||||
|
void _UpdateSystemFont();
|
||||||
|
void _BuildSizesMenu();
|
||||||
|
|
||||||
|
protected:
|
||||||
|
BHandler* fMessageTarget;
|
||||||
|
|
||||||
|
BMenuField* fFontsMenuField;
|
||||||
|
BMenuField* fSizesMenuField;
|
||||||
|
BPopUpMenu* fFontsMenu;
|
||||||
|
BPopUpMenu* fSizesMenu;
|
||||||
|
|
||||||
|
BBox* fPreviewBox;
|
||||||
|
BStringView* fPreviewText;
|
||||||
|
|
||||||
|
BFont fSavedFont;
|
||||||
|
BFont fCurrentFont;
|
||||||
|
float fMaxFontNameWidth;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // FONT_SELECTION_VIEW_H
|
||||||
@@ -0,0 +1,193 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2001-2012, Haiku.
|
||||||
|
* Distributed under the terms of the MIT License.
|
||||||
|
*
|
||||||
|
* Authors:
|
||||||
|
* Mark Hogben
|
||||||
|
* DarkWyrm <[email protected]>
|
||||||
|
* Axel Dörfler, [email protected]
|
||||||
|
* Philippe St-Pierre, [email protected]
|
||||||
|
* Stephan Aßmus <[email protected]>
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
#include "FontView.h"
|
||||||
|
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
#include <Catalog.h>
|
||||||
|
#include <GridLayoutBuilder.h>
|
||||||
|
#include <GroupLayoutBuilder.h>
|
||||||
|
#include <Locale.h>
|
||||||
|
#include <MessageRunner.h>
|
||||||
|
#include <SpaceLayoutItem.h>
|
||||||
|
|
||||||
|
#include "APRWindow.h"
|
||||||
|
#include "FontSelectionView.h"
|
||||||
|
|
||||||
|
|
||||||
|
#undef B_TRANSLATE_CONTEXT
|
||||||
|
#define B_TRANSLATE_CONTEXT "Font view"
|
||||||
|
|
||||||
|
|
||||||
|
static const uint32 kMsgCheckFonts = 'chkf';
|
||||||
|
|
||||||
|
|
||||||
|
static void
|
||||||
|
add_font_selection_view(BGridLayout* layout, FontSelectionView* view,
|
||||||
|
int32& row, bool withExtraSpace)
|
||||||
|
{
|
||||||
|
layout->AddItem(view->CreateFontsLabelLayoutItem(), 0, row);
|
||||||
|
layout->AddItem(view->CreateFontsMenuBarLayoutItem(), 1, row);
|
||||||
|
|
||||||
|
layout->AddItem(BSpaceLayoutItem::CreateGlue(), 2, row);
|
||||||
|
|
||||||
|
layout->AddItem(view->CreateSizesLabelLayoutItem(), 3, row);
|
||||||
|
layout->AddItem(view->CreateSizesMenuBarLayoutItem(), 4, row);
|
||||||
|
|
||||||
|
row++;
|
||||||
|
|
||||||
|
layout->AddItem(BSpaceLayoutItem::CreateGlue(), 0, row);
|
||||||
|
layout->AddView(view->GetPreviewBox(), 1, row, 4);
|
||||||
|
|
||||||
|
row++;
|
||||||
|
|
||||||
|
if (withExtraSpace) {
|
||||||
|
layout->AddItem(BSpaceLayoutItem::CreateVerticalStrut(5), 0, row, 5);
|
||||||
|
row++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
FontView::FontView(const char* name)
|
||||||
|
:
|
||||||
|
BView(name, B_WILL_DRAW )
|
||||||
|
{
|
||||||
|
SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR));
|
||||||
|
|
||||||
|
fPlainView = new FontSelectionView("plain", B_TRANSLATE("Plain font:"));
|
||||||
|
fBoldView = new FontSelectionView("bold", B_TRANSLATE("Bold font:"));
|
||||||
|
fFixedView = new FontSelectionView("fixed", B_TRANSLATE("Fixed font:"));
|
||||||
|
fMenuView = new FontSelectionView("menu", B_TRANSLATE("Menu font:"));
|
||||||
|
|
||||||
|
BGridLayout* layout = new BGridLayout(5, 5);
|
||||||
|
layout->SetInsets(10, 10, 10, 10);
|
||||||
|
SetLayout(layout);
|
||||||
|
|
||||||
|
int32 row = 0;
|
||||||
|
add_font_selection_view(layout, fPlainView, row, true);
|
||||||
|
add_font_selection_view(layout, fBoldView, row, true);
|
||||||
|
add_font_selection_view(layout, fFixedView, row, true);
|
||||||
|
add_font_selection_view(layout, fMenuView, row, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
FontView::AttachedToWindow()
|
||||||
|
{
|
||||||
|
fPlainView->SetTarget(this);
|
||||||
|
fBoldView->SetTarget(this);
|
||||||
|
fFixedView->SetTarget(this);
|
||||||
|
fMenuView->SetTarget(this);
|
||||||
|
|
||||||
|
UpdateFonts();
|
||||||
|
fRunner = new BMessageRunner(this, new BMessage(kMsgCheckFonts), 3000000);
|
||||||
|
// every 3 seconds
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
FontView::DetachedFromWindow()
|
||||||
|
{
|
||||||
|
delete fRunner;
|
||||||
|
fRunner = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
FontView::SetDefaults()
|
||||||
|
{
|
||||||
|
fPlainView->SetDefaults();
|
||||||
|
fBoldView->SetDefaults();
|
||||||
|
fFixedView->SetDefaults();
|
||||||
|
fMenuView->SetDefaults();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
FontView::MessageReceived(BMessage* message)
|
||||||
|
{
|
||||||
|
switch (message->what) {
|
||||||
|
case kMsgSetSize:
|
||||||
|
case kMsgSetFamily:
|
||||||
|
case kMsgSetStyle:
|
||||||
|
{
|
||||||
|
const char* name;
|
||||||
|
if (message->FindString("name", &name) != B_OK)
|
||||||
|
break;
|
||||||
|
|
||||||
|
if (!strcmp(name, "plain"))
|
||||||
|
fPlainView->MessageReceived(message);
|
||||||
|
else if (!strcmp(name, "bold"))
|
||||||
|
fBoldView->MessageReceived(message);
|
||||||
|
else if (!strcmp(name, "fixed"))
|
||||||
|
fFixedView->MessageReceived(message);
|
||||||
|
else if (!strcmp(name, "menu"))
|
||||||
|
fMenuView->MessageReceived(message);
|
||||||
|
else
|
||||||
|
break;
|
||||||
|
|
||||||
|
Window()->PostMessage(kMsgUpdate);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
case kMsgCheckFonts:
|
||||||
|
if (update_font_families(true))
|
||||||
|
UpdateFonts();
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
BView::MessageReceived(message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
FontView::Revert()
|
||||||
|
{
|
||||||
|
fPlainView->Revert();
|
||||||
|
fBoldView->Revert();
|
||||||
|
fFixedView->Revert();
|
||||||
|
fMenuView->Revert();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
FontView::UpdateFonts()
|
||||||
|
{
|
||||||
|
fPlainView->UpdateFontsMenu();
|
||||||
|
fBoldView->UpdateFontsMenu();
|
||||||
|
fFixedView->UpdateFontsMenu();
|
||||||
|
fMenuView->UpdateFontsMenu();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool
|
||||||
|
FontView::IsDefaultable()
|
||||||
|
{
|
||||||
|
return fPlainView->IsDefaultable()
|
||||||
|
|| fBoldView->IsDefaultable()
|
||||||
|
|| fFixedView->IsDefaultable()
|
||||||
|
|| fMenuView->IsDefaultable();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool
|
||||||
|
FontView::IsRevertable()
|
||||||
|
{
|
||||||
|
return fPlainView->IsRevertable()
|
||||||
|
|| fBoldView->IsRevertable()
|
||||||
|
|| fFixedView->IsRevertable()
|
||||||
|
|| fMenuView->IsRevertable();
|
||||||
|
}
|
||||||
|
|
||||||
@@ -0,0 +1,51 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2001-2012, Haiku.
|
||||||
|
* Distributed under the terms of the MIT License.
|
||||||
|
*
|
||||||
|
* Authors:
|
||||||
|
* Mark Hogben
|
||||||
|
* DarkWyrm <[email protected]>
|
||||||
|
* Axel Dörfler, [email protected]
|
||||||
|
* Philippe Saint-Pierre, [email protected]
|
||||||
|
* Stephan Aßmus <[email protected]>
|
||||||
|
*/
|
||||||
|
#ifndef FONT_VIEW_H
|
||||||
|
#define FONT_VIEW_H
|
||||||
|
|
||||||
|
|
||||||
|
#include <View.h>
|
||||||
|
|
||||||
|
|
||||||
|
class BMessageRunner;
|
||||||
|
class FontSelectionView;
|
||||||
|
|
||||||
|
|
||||||
|
class FontView : public BView {
|
||||||
|
public:
|
||||||
|
FontView(const char* name);
|
||||||
|
|
||||||
|
virtual void AttachedToWindow();
|
||||||
|
virtual void DetachedFromWindow();
|
||||||
|
|
||||||
|
virtual void MessageReceived(BMessage* message);
|
||||||
|
|
||||||
|
void SetDefaults();
|
||||||
|
void Revert();
|
||||||
|
void UpdateFonts();
|
||||||
|
|
||||||
|
bool IsDefaultable();
|
||||||
|
bool IsRevertable();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
private:
|
||||||
|
FontSelectionView* fPlainView;
|
||||||
|
FontSelectionView* fBoldView;
|
||||||
|
FontSelectionView* fFixedView;
|
||||||
|
FontSelectionView* fMenuView;
|
||||||
|
|
||||||
|
BMessageRunner* fRunner;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
#endif /* FONT_VIEW_H */
|
||||||
@@ -7,6 +7,8 @@ Preference Appearance :
|
|||||||
APRMain.cpp
|
APRMain.cpp
|
||||||
AntialiasingSettingsView.cpp
|
AntialiasingSettingsView.cpp
|
||||||
DecorSettingsView.cpp
|
DecorSettingsView.cpp
|
||||||
|
FontSelectionView.cpp
|
||||||
|
FontView.cpp
|
||||||
APRView.cpp
|
APRView.cpp
|
||||||
APRWindow.cpp
|
APRWindow.cpp
|
||||||
ColorSet.cpp
|
ColorSet.cpp
|
||||||
@@ -30,11 +32,13 @@ DoCatalogs Appearance :
|
|||||||
x-vnd.Haiku-Appearance
|
x-vnd.Haiku-Appearance
|
||||||
:
|
:
|
||||||
AntialiasingSettingsView.cpp
|
AntialiasingSettingsView.cpp
|
||||||
DecorSettingsView.cpp
|
|
||||||
APRView.cpp
|
APRView.cpp
|
||||||
APRWindow.cpp
|
APRWindow.cpp
|
||||||
ColorSet.cpp
|
ColorSet.cpp
|
||||||
ColorWell.cpp
|
ColorWell.cpp
|
||||||
ColorWhichItem.cpp
|
ColorWhichItem.cpp
|
||||||
|
DecorSettingsView.cpp
|
||||||
|
FontView.cpp
|
||||||
|
FontSelectionView.cpp
|
||||||
;
|
;
|
||||||
|
|
||||||
|
|||||||
@@ -20,8 +20,6 @@
|
|||||||
#define APPEARANCE_APP_SIGNATURE "application/x-vnd.Haiku-Appearance"
|
#define APPEARANCE_APP_SIGNATURE "application/x-vnd.Haiku-Appearance"
|
||||||
|
|
||||||
#define APPLY_SETTINGS 'aply'
|
#define APPLY_SETTINGS 'aply'
|
||||||
#define REVERT_SETTINGS 'rvrt'
|
|
||||||
#define DEFAULT_SETTINGS 'dflt'
|
|
||||||
#define TRY_SETTINGS 'trys'
|
#define TRY_SETTINGS 'trys'
|
||||||
|
|
||||||
#define ATTRIBUTE_CHOSEN 'atch'
|
#define ATTRIBUTE_CHOSEN 'atch'
|
||||||
|
|||||||
Reference in New Issue
Block a user