<commit_before>/*
 * Copyright 2000-2008, <NAME>, <<EMAIL>>. All rights reserved.
 * Distributed under the terms of the MIT License.
 */

/*
 * ui_settings ThemesAddon class
 */

#include <BeBuild.h>
#ifdef B_HAIKU_VERSION_1

#include <Alert.h>
#include <Application.h>
#include <InterfaceDefs.h>
#include <Entry.h>
#include <Font.h>
#include <Menu.h>
#include <Message.h>
#include <Roster.h>
#include <Debug.h>

#include <stdio.h>
#include <string.h>

#include "ThemesAddon.h"
#include "UITheme.h"
#include "Utils.h"

#ifdef SINGLE_BINARY
#define instantiate_themes_addon instantiate_themes_addon_ui_settings
#endif

#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);

// default values for colors in Interface Kit
// TODO: use it
namespace BPrivate {
extern const rgb_color* kDefaultColors;
}

#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);
};


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_TOOL_TIP_BACKGROUND_COLOR },
	{ B_UI_TOOLTIP_TEXT_COLOR, B_TOOL_TIP_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 },
	{ B_UI_WINDOW_TAB_COLOR, B_WINDOW_TAB_COLOR },
	{ B_UI_WINDOW_TEXT_COLOR, B_WINDOW_TEXT_COLOR },
	{ B_UI_WINDOW_INACTIVE_TAB_COLOR, B_WINDOW_INACTIVE_TAB_COLOR },
	{ B_UI_WINDOW_INACTIVE_TEXT_COLOR, B_WINDOW_INACTIVE_TEXT_COLOR },
	
	{ NULL, (color_which)-1 }
};


UISettingsThemesAddon::UISettingsThemesAddon()
	: ThemesAddon(A_NAME, A_MSGNAME)
{
	FENTRY;
}


UISettingsThemesAddon::~UISettingsThemesAddon()
{
	FENTRY;
}


const char *
UISettingsThemesAddon::Description()
{
	return A_DESCRIPTION;
}


status_t
UISettingsThemesAddon::RunPreferencesPanel()
{
	status_t err = B_OK;
	entry_ref ref;
	BEntry ent;
	FENTRY;
	/*<commit_msg>haikuui: Fix launching prefs<commit_after>/*
 * Copyright 2000-2008, <NAME>, <<EMAIL>>. All rights reserved.
 * Distributed under the terms of the MIT License.
 */

/*
 * ui_settings ThemesAddon class
 */

#include <BeBuild.h>
#ifdef B_HAIKU_VERSION_1

#include <Alert.h>
#include <Application.h>
#include <InterfaceDefs.h>
#include <Entry.h>
#include <Font.h>
#include <Menu.h>
#include <Message.h>
#include <Roster.h>
#include <Debug.h>

#include <stdio.h>
#include <string.h>

#include "ThemesAddon.h"
#include "UITheme.h"
#include "Utils.h"

#ifdef SINGLE_BINARY
#define instantiate_themes_addon instantiate_themes_addon_ui_settings
#endif

#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);

// default values for colors in Interface Kit
// TODO: use it
namespace BPrivate {
extern const rgb_color* kDefaultColors;
}

#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);
};


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_TOOL_TIP_BACKGROUND_COLOR },
	{ B_UI_TOOLTIP_TEXT_COLOR, B_TOOL_TIP_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 },
	{ B_UI_WINDOW_TAB_COLOR, B_WINDOW_TAB_COLOR },
	{ B_UI_WINDOW_TEXT_COLOR, B_WINDOW_TEXT_COLOR },
	{ B_UI_WINDOW_INACTIVE_TAB_COLOR, B_WINDOW_INACTIVE_TAB_COLOR },
	{ B_UI_WINDOW_INACTIVE_TEXT_COLOR, B_WINDOW_INACTIVE_TEXT_COLOR },
	
	{ NULL, (color_which)-1 }
};


UISettingsThemesAddon::UISettingsThemesAddon()
	: ThemesAddon(A_NAME, A_MSGNAME)
{
	FENTRY;
}


UISettingsThemesAddon::~UISettingsThemesAddon()
{
	FENTRY;
}


const char *
UISettingsThemesAddon::Description()
{
	return A_DESCRIPTION;
}


status_t
UISettingsThemesAddon::RunPreferencesPanel()
{
	status_t err = B_OK;

	if (be_roster->Launch("application/x-vnd.Haiku-Appearance") == B_OK)
		return B_OK;

	entry_ref ref;
	BEntry ent;
	FENTRY;
	/*
{'fraction_non_alphanumeric': 0.10244161358811041, 'fraction_numerical': 0.0050424628450106155, 'mean_word_length': 7.174620390455531, 'pattern_counts': {'":': 0, '<': 33, '<?xml version=': 0, '>': 34, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6183563', 'n_tokens_mistral': 3139, 'n_tokens_neox': 3030, 'n_words': 504}