コード例 #1
0
status_t
TerminalThemesAddon::ApplyThemeHaiku(BMessage &theme, uint32 flags)
{
	BMessage termpref;
	BMessage lines;
	status_t err;
	int32 ival;
	rgb_color color;
	BString s;
	int i;

	err = MyMessage(theme, termpref);
	if (err)
		return err;

	for (i = 0; i < NENTS(sHaikuPrefsMapInt32); i++) {
		if (termpref.FindInt32(sHaikuPrefsMapInt32[i].name, &ival) < B_OK)
			ival = sHaikuPrefsMapInt32[i].def;
		s = "";
		s << ival;
		lines.AddString(sHaikuPrefsMapInt32[i].pref, s.String());
	}

	for (i = 0; i < NENTS(sHaikuPrefsMapColors); i++) {
		if (FindRGBColor(termpref, sHaikuPrefsMapColors[i].name, 0, &color) != B_OK)
			color = sHaikuPrefsMapColors[i].def;
		s = "";
		s << color.red << ", " << color.green << ", " << color.blue;
		lines.AddString(sHaikuPrefsMapColors[i].pref, s.String());
	}

	BFont tFont;
	for (i = 0; FindFont(termpref, TP_FONT, i, &tFont) == B_OK; i++) {
		// at least set the size
		s = "";
		s << (int32)tFont.Size();
		lines.AddString(PREF_HALF_FONT_SIZE, s.String());
		//tFont.PrintToStream();
		//printf("fixed: %d\n", tFont.IsFixed());
		//printf("f&h fixed: %d\n", tFont.IsFullAndHalfFixed());
		// don't even try to set the font if it's not there or not fixed
		if (!tFont.IsFixed() && !tFont.IsFullAndHalfFixed())
			continue;
		font_family ff;
		font_style fs;
		tFont.GetFamilyAndStyle(&ff, &fs);
		s = "";
		s << ff;
		lines.AddString(PREF_HALF_FONT_FAMILY, s.String());
		s = "";
		s << fs;
		lines.AddString(PREF_HALF_FONT_STYLE, s.String());
	}

	if (flags & UI_THEME_SETTINGS_SAVE && AddonFlags() & Z_THEME_ADDON_DO_SAVE) {
		SaveHaikuTerminalSettings(lines);
	}

	if (flags & UI_THEME_SETTINGS_APPLY && AddonFlags() & Z_THEME_ADDON_DO_APPLY) {
		BList teamList;
		app_info ainfo;
		int32 count, i;
		be_roster->GetAppList(&teamList);
		count = teamList.CountItems();
		for (i = 0; i < count; i++) {
			if (be_roster->GetRunningAppInfo((team_id)((addr_t)teamList.ItemAt(i)), &ainfo) == B_OK) {
				if (!strcmp(ainfo.signature, kHaikuTerminalAppSig)) {
					err = B_OK;
					//XXX: WRITEME
/*					BMessage msg(MSG_R5_SET_PREF);
					BMessenger msgr(NULL, ainfo.team);
					tp.x = 0;
					tp.y = 0;
					
					//msg.AddData("", 'UBYT', &(tp.p), sizeof(struct tpref));
					msg.AddData("", 'UBYT', &(tp), sizeof(struct termprefs));
					msg.AddSpecifier("Window", 0L);
					err = msgr.SendMessage(&msg);
*/
				}
			}
		}
	}
	
	return B_OK;
}
コード例 #2
0
ファイル: TerminalAddon.cpp プロジェクト: luciang/haiku
status_t
TerminalThemesAddon::ApplyThemeHaiku(BMessage &theme, uint32 flags)
{
	BMessage termpref;
	BMessage lines;
	status_t err;
	struct termprefs tp;
	int32 ival;
	rgb_color color;
	BString s;

	err = MyMessage(theme, termpref);
	if (err)
		return err;

	if (termpref.FindInt32(TP_COLS, &ival) < B_OK)
		ival = 80;
	s = "";
	s << ival;
	lines.AddString(PREF_COLS, s.String());

	if (termpref.FindInt32(TP_ROWS, &ival) < B_OK)
		ival = 25;
	s = "";
	s << ival;
	lines.AddString(PREF_ROWS, s.String());

	if (termpref.FindInt32(TP_TABWIDTH, &ival) >= B_OK) {
		//XXX: handle that ?
	}

	BFont tFont;
	tp.p.font_size = 12;
	strcpy(tp.p.font, "Courier10 BT/Roman");
	if (FindFont(termpref, TP_FONT, 0, &tFont) == B_OK) {
		font_family ff;
		font_style fs;
		tFont.GetFamilyAndStyle(&ff, &fs);
		s = "";
		s << ff;
		lines.AddString(PREF_HALF_FONT_FAMILY, s.String());
		s = "";
		s << fs;
		lines.AddString(PREF_HALF_FONT_STYLE, s.String());
		s = "";
		s << tFont.Size();
		lines.AddString(PREF_HALF_FONT_SIZE, s.String());
	}
	
	if (FindRGBColor(termpref, TP_BG, 0, &color) != B_OK)
		color = make_color(255,255,255,255);
	s = "";
	s << color.red << ", " << color.green << ", " << color.blue;
	lines.AddString(PREF_TEXT_BACK_COLOR, s.String());
	
	if (FindRGBColor(termpref, TP_FG, 0, &color) != B_OK)
		color = make_color(0,0,0,255);
	s = "";
	s << color.red << ", " << color.green << ", " << color.blue;
	lines.AddString(PREF_TEXT_FORE_COLOR, s.String());

	if (FindRGBColor(termpref, TP_CURBG, 0, &color) != B_OK)
		color = make_color(255,255,255,255);
	s = "";
	s << color.red << ", " << color.green << ", " << color.blue;
	lines.AddString(PREF_CURSOR_BACK_COLOR, s.String());

	if (FindRGBColor(termpref, TP_CURFG, 0, &color) != B_OK)
		color = make_color(0,0,0,255);
	s = "";
	s << color.red << ", " << color.green << ", " << color.blue;
	lines.AddString(PREF_CURSOR_FORE_COLOR, s.String());

	if (FindRGBColor(termpref, TP_SELBG, 0, &color) != B_OK)
		color = make_color(0,0,0,255);
	s = "";
	s << color.red << ", " << color.green << ", " << color.blue;
	lines.AddString(PREF_SELECT_BACK_COLOR, s.String());

	if (FindRGBColor(termpref, TP_SELFG, 0, &color) != B_OK)
		color = make_color(255,255,255,255);
	s = "";
	s << color.red << ", " << color.green << ", " << color.blue;
	lines.AddString(PREF_SELECT_FORE_COLOR, s.String());
	
	/* XXX: handle PREF_IM_FORE_COLOR PREF_IM_BACK_COLOR PREF_IM_SELECT_COLOR */

	
	if (termpref.FindInt32(TP_ENCODING, &ival) != B_OK)
		ival = 0; // UTF-8
	s = "";
	s << ival;
	//XXX: shouldn't really be touched...
	//lines.AddString(, s.String());
	
	if (flags & UI_THEME_SETTINGS_SAVE && AddonFlags() & Z_THEME_ADDON_DO_SAVE) {
		SaveHaikuTerminalSettings(lines);
	}

	if (flags & UI_THEME_SETTINGS_APPLY && AddonFlags() & Z_THEME_ADDON_DO_APPLY) {
		BList teamList;
		app_info ainfo;
		int32 count, i;
		be_roster->GetAppList(&teamList);
		count = teamList.CountItems();
		for (i = 0; i < count; i++) {
			if (be_roster->GetRunningAppInfo((team_id)(teamList.ItemAt(i)), &ainfo) == B_OK) {
				if (!strcmp(ainfo.signature, kHaikuTerminalAppSig)) {
					err = B_OK;
					//XXX: WRITEME
/*					BMessage msg(MSG_R5_SET_PREF);
					BMessenger msgr(NULL, ainfo.team);
					tp.x = 0;
					tp.y = 0;
					
					//msg.AddData("", 'UBYT', &(tp.p), sizeof(struct tpref));
					msg.AddData("", 'UBYT', &(tp), sizeof(struct termprefs));
					msg.AddSpecifier("Window", 0L);
					err = msgr.SendMessage(&msg);
*/
				}
			}
		}
	}
	
	return B_OK;
}