2008-01-12 04:11:45 +03:00
|
|
|
/*
|
|
|
|
* ui_settings ThemesAddon class
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <BeBuild.h>
|
2008-01-12 04:22:47 +03:00
|
|
|
#ifdef B_HAIKU_VERSION_1
|
2008-01-12 04:11:45 +03:00
|
|
|
|
|
|
|
#include <Alert.h>
|
|
|
|
#include <Application.h>
|
|
|
|
#include <InterfaceDefs.h>
|
|
|
|
#include <Entry.h>
|
|
|
|
#include <Font.h>
|
2008-01-25 04:55:46 +03:00
|
|
|
#include <Menu.h>
|
2008-01-12 04:11:45 +03:00
|
|
|
#include <Message.h>
|
|
|
|
#include <Roster.h>
|
2008-01-14 05:00:42 +03:00
|
|
|
#include <Debug.h>
|
2008-01-12 04:11:45 +03:00
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
#include "ThemesAddon.h"
|
|
|
|
#include "UITheme.h"
|
2008-01-14 05:00:42 +03:00
|
|
|
#include "Utils.h"
|
2008-01-12 04:11:45 +03:00
|
|
|
|
|
|
|
#ifdef SINGLE_BINARY
|
2008-01-27 02:27:00 +03:00
|
|
|
#define instantiate_themes_addon instantiate_themes_addon_ui_settings
|
2008-01-12 04:11:45 +03:00
|
|
|
#endif
|
|
|
|
|
2008-01-14 05:00:42 +03:00
|
|
|
#define DEBUG_TA
|
|
|
|
#ifdef DEBUG_TA
|
|
|
|
#define FENTRY PRINT(("*ThemesAddon[%s]::%s()\n", Name(), __FUNCTION__))
|
|
|
|
#else
|
|
|
|
#define FENTRY
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#define DERR(e) { PRINT(("%s: err: %s\n", __FUNCTION__, strerror(e))); }
|
|
|
|
|
|
|
|
// 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);
|
2008-01-12 04:22:47 +03:00
|
|
|
|
|
|
|
|
2008-01-12 04:11:45 +03:00
|
|
|
#define A_NAME "System Colors and Fonts"
|
|
|
|
#define A_MSGNAME Z_THEME_UI_SETTINGS
|
|
|
|
#define A_DESCRIPTION "System colors, fonts and other goodies"
|
|
|
|
|
|
|
|
class UISettingsThemesAddon : public ThemesAddon {
|
|
|
|
public:
|
|
|
|
UISettingsThemesAddon();
|
|
|
|
~UISettingsThemesAddon();
|
|
|
|
|
|
|
|
const char *Description();
|
|
|
|
|
|
|
|
status_t RunPreferencesPanel();
|
|
|
|
|
|
|
|
status_t AddNames(BMessage &names);
|
|
|
|
|
|
|
|
status_t ApplyTheme(BMessage &theme, uint32 flags=0L);
|
|
|
|
status_t MakeTheme(BMessage &theme, uint32 flags=0L);
|
|
|
|
|
|
|
|
status_t ApplyDefaultTheme(uint32 flags=0L);
|
|
|
|
};
|
|
|
|
|
2008-01-14 05:00:42 +03:00
|
|
|
struct ui_color_map {
|
|
|
|
const char *name;
|
|
|
|
color_which id;
|
|
|
|
} gUIColorMap[] = {
|
|
|
|
{ B_UI_PANEL_BACKGROUND_COLOR, B_PANEL_BACKGROUND_COLOR },
|
|
|
|
{ B_UI_PANEL_TEXT_COLOR, B_PANEL_TEXT_COLOR },
|
|
|
|
// { B_UI_PANEL_LINK_COLOR, B_PANEL_LINK_COLOR },
|
|
|
|
{ B_UI_DOCUMENT_BACKGROUND_COLOR, B_DOCUMENT_BACKGROUND_COLOR },
|
|
|
|
{ B_UI_DOCUMENT_TEXT_COLOR, B_DOCUMENT_TEXT_COLOR },
|
|
|
|
// { B_UI_DOCUMENT_LINK_COLOR, B_DOCUMENT_LINK_COLOR },
|
|
|
|
{ B_UI_CONTROL_BACKGROUND_COLOR, B_CONTROL_BACKGROUND_COLOR },
|
|
|
|
{ B_UI_CONTROL_TEXT_COLOR, B_CONTROL_TEXT_COLOR },
|
|
|
|
{ B_UI_CONTROL_BORDER_COLOR, B_CONTROL_BORDER_COLOR },
|
|
|
|
{ B_UI_CONTROL_HIGHLIGHT_COLOR, B_CONTROL_HIGHLIGHT_COLOR },
|
|
|
|
{ B_UI_NAVIGATION_BASE_COLOR, B_NAVIGATION_BASE_COLOR },
|
|
|
|
{ B_UI_NAVIGATION_PULSE_COLOR, B_NAVIGATION_PULSE_COLOR },
|
|
|
|
{ B_UI_SHINE_COLOR, B_SHINE_COLOR },
|
|
|
|
{ B_UI_SHADOW_COLOR, B_SHADOW_COLOR },
|
|
|
|
{ B_UI_TOOLTIP_BACKGROUND_COLOR, B_TOOLTIP_BACKGROUND_COLOR },
|
|
|
|
{ B_UI_TOOLTIP_TEXT_COLOR, B_TOOLTIP_TEXT_COLOR },
|
|
|
|
{ B_UI_MENU_BACKGROUND_COLOR, B_MENU_BACKGROUND_COLOR },
|
|
|
|
{ B_UI_MENU_SELECTED_BACKGROUND_COLOR, B_MENU_SELECTED_BACKGROUND_COLOR },
|
|
|
|
{ B_UI_MENU_ITEM_TEXT_COLOR, B_MENU_ITEM_TEXT_COLOR },
|
|
|
|
{ B_UI_MENU_SELECTED_ITEM_TEXT_COLOR, B_MENU_SELECTED_ITEM_TEXT_COLOR },
|
|
|
|
{ B_UI_MENU_SELECTED_BORDER_COLOR, B_MENU_SELECTED_BORDER_COLOR },
|
|
|
|
{ B_UI_SUCCESS_COLOR, B_SUCCESS_COLOR },
|
|
|
|
{ B_UI_FAILURE_COLOR, B_FAILURE_COLOR },
|
|
|
|
{ NULL, (color_which)-1 }
|
|
|
|
};
|
|
|
|
|
2008-01-12 04:11:45 +03:00
|
|
|
UISettingsThemesAddon::UISettingsThemesAddon()
|
|
|
|
: ThemesAddon(A_NAME, A_MSGNAME)
|
|
|
|
{
|
2008-01-14 05:00:42 +03:00
|
|
|
FENTRY;
|
2008-01-12 04:11:45 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
UISettingsThemesAddon::~UISettingsThemesAddon()
|
|
|
|
{
|
2008-01-14 05:00:42 +03:00
|
|
|
FENTRY;
|
2008-01-12 04:11:45 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
const char *UISettingsThemesAddon::Description()
|
|
|
|
{
|
|
|
|
return A_DESCRIPTION;
|
|
|
|
}
|
|
|
|
|
|
|
|
status_t UISettingsThemesAddon::RunPreferencesPanel()
|
|
|
|
{
|
|
|
|
status_t err = B_OK;
|
|
|
|
entry_ref ref;
|
|
|
|
BEntry ent;
|
2008-01-14 05:00:42 +03:00
|
|
|
FENTRY;
|
2008-01-12 04:11:45 +03:00
|
|
|
/*
|
|
|
|
err = ent.SetTo("/boot/beos/preferences/Colors");
|
|
|
|
if (!err) {
|
|
|
|
err = ent.GetRef(&ref);
|
|
|
|
if (!err) {
|
|
|
|
err = be_roster->Launch(&ref);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
*/
|
|
|
|
if (!err)
|
|
|
|
return B_OK;
|
2008-01-14 05:00:42 +03:00
|
|
|
err = ent.SetTo("/boot/beos/preferences/Appearance");
|
2008-01-12 04:11:45 +03:00
|
|
|
if (!err) {
|
|
|
|
err = ent.GetRef(&ref);
|
|
|
|
if (!err) {
|
|
|
|
err = be_roster->Launch(&ref);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
status_t UISettingsThemesAddon::AddNames(BMessage &names)
|
|
|
|
{
|
2008-01-14 05:00:42 +03:00
|
|
|
FENTRY;
|
2008-01-12 04:11:45 +03:00
|
|
|
|
|
|
|
names.AddString(Z_THEME_UI_SETTINGS, "UI Settings");
|
2008-01-14 05:00:42 +03:00
|
|
|
// Haiku doesn't know about them, wo add them
|
|
|
|
//XXX: use symbolic names.
|
|
|
|
names.AddString("be:c:PanBg", "Panel Background");
|
|
|
|
names.AddString("be:c:PanTx", "Panel Text");
|
|
|
|
names.AddString("be:c:PanLn", "Panel Link");
|
|
|
|
names.AddString("be:c:DocBg", "Document Background");
|
|
|
|
names.AddString("be:c:DocTx", "Document Text");
|
|
|
|
names.AddString("be:c:DocLn", "Document Link");
|
|
|
|
names.AddString("be:c:CtlBg", "Control Background");
|
|
|
|
names.AddString("be:c:CtlTx", "Control Text");
|
|
|
|
names.AddString("be:c:CtlBr", "Control Border");
|
|
|
|
names.AddString("be:c:CtlHg", "Control Highlight");
|
|
|
|
names.AddString("be:c:NavBs", "Navigation Base");
|
|
|
|
names.AddString("be:c:NavPl", "Navigation Pulse");
|
|
|
|
names.AddString("be:c:Shine", "Shine");
|
|
|
|
names.AddString("be:c:Shadow", "Shadow");
|
|
|
|
names.AddString("be:c:TipBg", "ToolTip Background");
|
|
|
|
names.AddString("be:c:TipTx", "ToolTip Text");
|
|
|
|
names.AddString("be:c:MenBg", "Menu Background");
|
|
|
|
names.AddString("be:c:MenSBg", "Menu Selected Background");
|
|
|
|
names.AddString("be:c:MenTx", "Menu Item Text");
|
|
|
|
names.AddString("be:c:MenSTx", "Menu Selected Item Text");
|
|
|
|
names.AddString("be:c:MenSBr", "Menu Selected Border");
|
|
|
|
names.AddString("be:c:Success", "Success");
|
|
|
|
names.AddString("be:c:Failure", "Failure");
|
|
|
|
names.AddString("be:f:MenTx", "Menu Item Text");
|
|
|
|
names.AddString("be:MenSep", "Menu Separator");
|
|
|
|
names.AddString("be:MenTrig", "Show Menu Triggers");
|
|
|
|
names.AddString("be:MenZSnake", "Menu ZSnake");
|
|
|
|
names.AddString("be:f:Tip", "ToolTip");
|
2008-01-12 04:11:45 +03:00
|
|
|
names.AddString("be:f:be_plain_font", "System Plain");
|
|
|
|
names.AddString("be:f:be_bold_font", "System Bold");
|
|
|
|
names.AddString("be:f:be_fixed_font", "System Fixed");
|
|
|
|
return B_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
status_t UISettingsThemesAddon::ApplyTheme(BMessage &theme, uint32 flags)
|
|
|
|
{
|
|
|
|
BMessage uisettings;
|
|
|
|
BFont fnt;
|
2008-01-25 04:55:46 +03:00
|
|
|
struct menu_info menuInfo;
|
2008-01-12 04:11:45 +03:00
|
|
|
status_t err;
|
2008-01-25 04:55:46 +03:00
|
|
|
status_t gmierr = ENOENT;
|
2008-01-14 05:00:42 +03:00
|
|
|
int i;
|
|
|
|
FENTRY;
|
2008-01-12 04:11:45 +03:00
|
|
|
|
2008-01-25 16:52:22 +03:00
|
|
|
if (!(flags & UI_THEME_SETTINGS_SET_ALL) || !(AddonFlags() & Z_THEME_ADDON_DO_SET_ALL))
|
|
|
|
return B_OK;
|
|
|
|
|
2008-01-12 04:11:45 +03:00
|
|
|
err = MyMessage(theme, uisettings);
|
2008-01-14 05:00:42 +03:00
|
|
|
DERR(err);
|
2008-01-12 04:11:45 +03:00
|
|
|
if (err)
|
|
|
|
return err;
|
|
|
|
|
2008-01-14 05:00:42 +03:00
|
|
|
font_family family;
|
|
|
|
font_style style;
|
|
|
|
|
|
|
|
err = FindFont(uisettings, "be:f:be_plain_font", 0, &fnt);
|
2008-01-25 04:55:46 +03:00
|
|
|
//uisettings.RemoveName("be:f:be_plain_font");
|
2008-01-14 05:00:42 +03:00
|
|
|
DERR(err);
|
|
|
|
if (err == B_OK) {
|
|
|
|
fnt.GetFamilyAndStyle(&family, &style);
|
|
|
|
_set_system_font_("plain", family, style, fnt.Size());
|
|
|
|
}
|
2008-01-12 04:11:45 +03:00
|
|
|
|
2008-01-14 05:00:42 +03:00
|
|
|
err = FindFont(uisettings, "be:f:be_bold_font", 0, &fnt);
|
|
|
|
DERR(err);
|
2008-01-25 04:55:46 +03:00
|
|
|
//uisettings.RemoveName("be:f:be_bold_font");
|
2008-01-14 05:00:42 +03:00
|
|
|
if (err == B_OK) {
|
|
|
|
fnt.GetFamilyAndStyle(&family, &style);
|
|
|
|
_set_system_font_("bold", family, style, fnt.Size());
|
|
|
|
}
|
2008-01-12 04:11:45 +03:00
|
|
|
|
2008-01-14 05:00:42 +03:00
|
|
|
err = FindFont(uisettings, "be:f:be_fixed_font", 0, &fnt);
|
|
|
|
DERR(err);
|
2008-01-25 04:55:46 +03:00
|
|
|
//uisettings.RemoveName("be:f:be_fixed_font");
|
2008-01-14 05:00:42 +03:00
|
|
|
if (err == B_OK) {
|
|
|
|
fnt.GetFamilyAndStyle(&family, &style);
|
|
|
|
_set_system_font_("fixed", family, style, fnt.Size());
|
|
|
|
}
|
2008-01-12 04:11:45 +03:00
|
|
|
|
2008-01-25 04:55:46 +03:00
|
|
|
err = FindFont(uisettings, "be:f:Tip", 0, &fnt);
|
|
|
|
DERR(err);
|
|
|
|
//uisettings.RemoveName("be:f:Tip");
|
|
|
|
if (err == B_OK) {
|
|
|
|
fnt.GetFamilyAndStyle(&family, &style);
|
|
|
|
// not implemented yet in Haiku
|
|
|
|
//_set_system_font_("tip", family, style, fnt.Size());
|
|
|
|
//_set_system_font_("tooltip", family, style, fnt.Size());
|
|
|
|
}
|
|
|
|
|
|
|
|
gmierr = get_menu_info(&menuInfo);
|
|
|
|
|
2008-01-14 05:00:42 +03:00
|
|
|
for (i = 0; gUIColorMap[i].name; i++) {
|
|
|
|
rgb_color c;
|
|
|
|
if (FindRGBColor(uisettings, gUIColorMap[i].name, 0, &c) == B_OK) {
|
|
|
|
set_ui_color(gUIColorMap[i].id, c);
|
2008-01-25 04:55:46 +03:00
|
|
|
PRINT(("set_ui_color(%d, #%02x%02x%02x)\n",
|
|
|
|
gUIColorMap[i].id, c.red, c.green, c.blue));
|
|
|
|
if (gUIColorMap[i].id == B_MENU_BACKGROUND_COLOR)
|
|
|
|
menuInfo.background_color = c;
|
2008-01-14 05:00:42 +03:00
|
|
|
}
|
|
|
|
}
|
2008-01-12 04:11:45 +03:00
|
|
|
|
2008-01-25 04:55:46 +03:00
|
|
|
if (gmierr >= B_OK) {
|
|
|
|
bool bval;
|
|
|
|
int32 ival;
|
|
|
|
if (uisettings.FindBool("be:MenTrig", &bval) >= B_OK)
|
|
|
|
menuInfo.triggers_always_shown = bval;
|
|
|
|
if (uisettings.FindInt32("be:MenSep", &ival) >= B_OK)
|
|
|
|
menuInfo.separator = ival;
|
|
|
|
err = FindFont(uisettings, "be:f:MenTx", 0, &fnt);
|
|
|
|
DERR(err);
|
|
|
|
if (err == B_OK) {
|
|
|
|
fnt.GetFamilyAndStyle(&menuInfo.f_family, &menuInfo.f_style);
|
|
|
|
menuInfo.font_size = fnt.Size();
|
|
|
|
}
|
|
|
|
set_menu_info(&menuInfo);
|
|
|
|
}
|
2008-01-12 04:11:45 +03:00
|
|
|
|
|
|
|
return B_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
status_t UISettingsThemesAddon::MakeTheme(BMessage &theme, uint32 flags)
|
|
|
|
{
|
|
|
|
BMessage uisettings;
|
|
|
|
BMessage names;
|
|
|
|
BFont fnt;
|
2008-01-25 04:55:46 +03:00
|
|
|
menu_info menuInfo;
|
2008-01-12 04:11:45 +03:00
|
|
|
status_t err;
|
2008-01-14 05:00:42 +03:00
|
|
|
int i;
|
|
|
|
FENTRY;
|
2008-01-12 04:11:45 +03:00
|
|
|
|
|
|
|
(void)flags;
|
|
|
|
err = MyMessage(theme, uisettings);
|
|
|
|
if (err)
|
|
|
|
uisettings.MakeEmpty();
|
|
|
|
|
2008-01-14 05:00:42 +03:00
|
|
|
for (i = 0; gUIColorMap[i].name; i++) {
|
|
|
|
rgb_color c = ui_color(gUIColorMap[i].id);
|
|
|
|
AddRGBColor(uisettings, gUIColorMap[i].name, c);
|
|
|
|
}
|
2008-01-12 04:11:45 +03:00
|
|
|
|
|
|
|
// hack for legacy fonts
|
2008-01-14 05:00:42 +03:00
|
|
|
AddFont(uisettings, "be:f:be_plain_font", (BFont *)be_plain_font);
|
|
|
|
AddFont(uisettings, "be:f:be_bold_font", (BFont *)be_bold_font);
|
|
|
|
AddFont(uisettings, "be:f:be_fixed_font", (BFont *)be_fixed_font);
|
2008-01-25 04:55:46 +03:00
|
|
|
// XXX: FIXME
|
|
|
|
//AddFont(uisettings, "be:f:Tip", (BFont *)be_tip_font);
|
|
|
|
|
|
|
|
// menu stuff
|
|
|
|
err = get_menu_info(&menuInfo);
|
|
|
|
if (err >= B_OK) {
|
|
|
|
uisettings.AddBool("be:MenTrig", menuInfo.triggers_always_shown);
|
|
|
|
uisettings.AddInt32("be:MenSep", menuInfo.separator);
|
|
|
|
fnt.SetFamilyAndStyle(menuInfo.f_family, menuInfo.f_style);
|
|
|
|
fnt.SetSize(menuInfo.font_size);
|
|
|
|
AddFont(uisettings, "be:f:MenTx", &fnt);
|
|
|
|
}
|
2008-01-12 04:11:45 +03:00
|
|
|
|
|
|
|
err = SetMyMessage(theme, uisettings);
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
status_t UISettingsThemesAddon::ApplyDefaultTheme(uint32 flags)
|
|
|
|
{
|
|
|
|
BMessage theme;
|
|
|
|
BMessage uisettings;
|
2008-01-25 04:55:46 +03:00
|
|
|
rgb_color color;
|
2008-01-14 05:00:42 +03:00
|
|
|
FENTRY;
|
2008-01-12 04:11:45 +03:00
|
|
|
|
2008-01-14 05:00:42 +03:00
|
|
|
/*
|
2008-01-17 01:08:33 +03:00
|
|
|
status_t err;
|
2008-01-12 04:11:45 +03:00
|
|
|
err = get_default_settings(&uisettings);
|
|
|
|
if (err)
|
|
|
|
return err;
|
2008-01-14 05:00:42 +03:00
|
|
|
*/
|
|
|
|
|
|
|
|
font_family family;
|
|
|
|
font_style style;
|
|
|
|
float size;
|
|
|
|
BFont f;
|
|
|
|
if (_get_system_default_font_("plain", family, style, &size) != B_OK)
|
|
|
|
return B_ERROR;
|
|
|
|
f.SetFamilyAndStyle(family, style);
|
|
|
|
f.SetSize(size);
|
|
|
|
AddFont(uisettings, "be:f:be_plain_font", &f);
|
|
|
|
|
|
|
|
if (_get_system_default_font_(Name(), family, style, &size) != B_OK)
|
|
|
|
return B_ERROR;
|
|
|
|
f.SetFamilyAndStyle(family, style);
|
|
|
|
f.SetSize(size);
|
|
|
|
AddFont(uisettings, "be:f:be_plain_font", &f);
|
|
|
|
|
|
|
|
if (_get_system_default_font_(Name(), family, style, &size) != B_OK)
|
|
|
|
return B_ERROR;
|
|
|
|
f.SetFamilyAndStyle(family, style);
|
|
|
|
f.SetSize(size);
|
|
|
|
AddFont(uisettings, "be:f:be_plain_font", &f);
|
2008-01-12 04:11:45 +03:00
|
|
|
|
2008-01-25 04:55:46 +03:00
|
|
|
// menu stuff
|
|
|
|
sprintf(family,"%s","Bitstream Vera Sans");
|
|
|
|
sprintf(style,"%s","Roman");
|
|
|
|
f.SetFamilyAndStyle(family, style);
|
|
|
|
f.SetSize(12.0);
|
|
|
|
AddFont(uisettings, "be:f:MenTx", &f);
|
|
|
|
color.red = 216;
|
|
|
|
color.blue = 216;
|
|
|
|
color.green = 216;
|
|
|
|
color.alpha = 255;
|
|
|
|
AddRGBColor(uisettings, "be:c:MenBg", color);
|
|
|
|
uisettings.AddBool("be:MenTrig", false);
|
|
|
|
uisettings.AddInt32("be:MenSep", 0);
|
|
|
|
|
2008-01-12 04:11:45 +03:00
|
|
|
theme.AddMessage(A_MSGNAME, &uisettings);
|
|
|
|
return ApplyTheme(theme, flags);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-01-27 02:27:00 +03:00
|
|
|
ThemesAddon *instantiate_themes_addon()
|
2008-01-12 04:11:45 +03:00
|
|
|
{
|
|
|
|
return (ThemesAddon *) new UISettingsThemesAddon;
|
|
|
|
}
|
|
|
|
|
2008-01-14 05:00:42 +03:00
|
|
|
#endif /* B_BEOS_VERSION_DANO */
|