void FontSelectionView::_AddStylesToMenu(const BFont& font, BMenu* stylesMenu) const { stylesMenu->RemoveItems(0, stylesMenu->CountItems(), true); stylesMenu->SetRadioMode(true); font_family family; font_style style; font.GetFamilyAndStyle(&family, &style); BString currentStyle(style); int32 numStyles = count_font_styles(family); for (int32 j = 0; j < numStyles; j++) { if (get_font_style(family, j, &style) != B_OK) continue; BMessage* message = new BMessage(kMsgSetStyle); message->AddString("family", (char*)family); message->AddString("style", (char*)style); BMenuItem* item = new BMenuItem(style, message); item->SetMarked(currentStyle == style); stylesMenu->AddItem(item); item->SetTarget(this); } }
void ControlView::_UpdateFontmenus(bool setInitialfont) { BFont font; BMenu* stylemenu = NULL; font_family fontFamilyName, currentFamily; font_style fontStyleName, currentStyle; GetFont(&font); font.GetFamilyAndStyle(¤tFamily, ¤tStyle); const int32 fontfamilies = count_font_families(); fFontFamilyMenu->RemoveItems(0, fFontFamilyMenu->CountItems(), true); for (int32 i = 0; i < fontfamilies; i++) { if (get_font_family(i, &fontFamilyName) == B_OK) { stylemenu = new BMenu(fontFamilyName); const int32 styles = count_font_styles(fontFamilyName); BMessage* familyMsg = new BMessage(FONTFAMILY_CHANGED_MSG); familyMsg->AddString("_family", fontFamilyName); BMenuItem* familyItem = new BMenuItem(stylemenu, familyMsg); fFontFamilyMenu->AddItem(familyItem); for (int32 j = 0; j < styles; j++) { if (get_font_style(fontFamilyName, j, &fontStyleName) == B_OK) { BMessage* fontMsg = new BMessage(FONTSTYLE_CHANGED_MSG); fontMsg->AddString("_family", fontFamilyName); fontMsg->AddString("_style", fontStyleName); BMenuItem* styleItem = new BMenuItem(fontStyleName, fontMsg); styleItem->SetMarked(false); // setInitialfont is used when we attach the FontField if (!strcmp(fontStyleName, currentStyle) && !strcmp(fontFamilyName, currentFamily) && setInitialfont) { styleItem->SetMarked(true); familyItem->SetMarked(true); BString string; string << currentFamily << " " << currentStyle; if (fFontMenuField) fFontMenuField->MenuItem()->SetLabel(string.String()); } stylemenu->AddItem(styleItem); } } } stylemenu->SetRadioMode(true); stylemenu->SetTargetForItems(this); } fFontFamilyMenu->SetLabelFromMarked(true); fFontFamilyMenu->SetTargetForItems(this); }
void FontSelectionView::UpdateFontsMenu() { int32 numFamilies = count_font_families(); fFontsMenu->RemoveItems(0, fFontsMenu->CountItems(), true); BFont font = fCurrentFont; font_family currentFamily; font_style currentStyle; font.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; font.SetFamilyAndFace(family, B_REGULAR_FACE); BMessage* message = new BMessage(kMsgSetFamily); message->AddString("family", family); message->AddString("name", Name()); BMenuItem* familyItem; if (fStylesMenuField != NULL) { familyItem = new BMenuItem(family, message); } else { // Each family item has a submenu with all styles for that font. BMenu* stylesMenu = new BMenu(family); _AddStylesToMenu(font, stylesMenu); familyItem = new BMenuItem(stylesMenu, message); } familyItem->SetMarked(strcmp(family, currentFamily) == 0); fFontsMenu->AddItem(familyItem); familyItem->SetTarget(this); } // Separate styles menu for only the current font. if (fStylesMenuField != NULL) _AddStylesToMenu(fCurrentFont, fStylesMenuField->Menu()); }
// constructor Font::Font(const BFont& font) : fFamily("") , fStyle("") , fSize(font.Size()) , fRotation(font.Rotation()) , fShear(font.Shear()) , fFalseBoldWidth(0.0) , fHinting(true) , fKerning(true) , fSpacing(font.Spacing()) , fCachedFontHeightValid(true) { font_family family; font_style style; font.GetFamilyAndStyle(&family, &style); fFamily = family; fStyle = style; font.GetHeight(&fCachedFontHeight); }
status_t CharacterWindow::_SaveSettings() { BFile file; status_t status = _OpenSettings(file, B_WRITE_ONLY | B_CREATE_FILE | B_ERASE_FILE); if (status < B_OK) return status; BMessage settings('chrm'); status = settings.AddRect("window frame", Frame()); if (status != B_OK) return status; if (status == B_OK) { status = settings.AddBool("show private blocks", fCharacterView->IsShowingPrivateBlocks()); } if (status == B_OK) { status = settings.AddBool("show contained blocks only", fCharacterView->IsShowingContainedBlocksOnly()); } if (status == B_OK) { BFont font = fCharacterView->CharacterFont(); status = settings.AddInt32("font size", font.Size()); font_family family; font_style style; if (status == B_OK) font.GetFamilyAndStyle(&family, &style); if (status == B_OK) status = settings.AddString("font family", family); if (status == B_OK) status = settings.AddString("font style", style); } if (status == B_OK) status = settings.Flatten(&file); return status; }
void TextDocumentTest::_UpdateFontmenus(bool setInitialfont) { BFont font = BFont(); BMenu* stylemenu = NULL; font_family fontFamilyName, currentFamily; font_style fontStyleName, currentStyle; //GetFont(&font); font.GetFamilyAndStyle(¤tFamily, ¤tStyle); const int32 fontfamilies = count_font_families(); fFontFamilyMenu->RemoveItems(0, fFontFamilyMenu->CountItems(), true); for (int32 i = 0; i < fontfamilies; i++) { if (get_font_family(i, &fontFamilyName) == B_OK) { stylemenu = new BPopUpMenu(fontFamilyName); stylemenu->SetLabelFromMarked(false); const int32 styles = count_font_styles(fontFamilyName); //TODO change msg.. to a suitable msg BMessage* familyMsg = new BMessage('todo'); familyMsg->AddString("_family", fontFamilyName); BMenuItem* familyItem = new BMenuItem(stylemenu, familyMsg); fFontFamilyMenu->AddItem(familyItem); for (int32 j = 0; j < styles; j++) { if (get_font_style(fontFamilyName, j, &fontStyleName) == B_OK) { //TODO change msg.. to a suitable msg BMessage* fontMsg = new BMessage('todo'); fontMsg->AddString("_family", fontFamilyName); fontMsg->AddString("_style", fontStyleName); BMenuItem* styleItem = new BMenuItem(fontStyleName, fontMsg); styleItem->SetMarked(false); // setInitialfont is used when we attach the FontField if (!strcmp(fontStyleName, currentStyle) && !strcmp(fontFamilyName, currentFamily) && setInitialfont) { styleItem->SetMarked(true); familyItem->SetMarked(true); BString string; string << currentFamily << " " << currentStyle; if (fFontMenuField) fFontMenuField->MenuItem()->SetLabel(string.String()); } stylemenu->AddItem(styleItem); } } stylemenu->SetRadioMode(true); stylemenu->SetTargetForItems(this); } } fFontFamilyMenu->SetLabelFromMarked(false); fFontFamilyMenu->SetTargetForItems(this); }
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; }
status_t TerminalThemesAddon::ApplyThemeR5(BMessage &theme, uint32 flags) { BMessage termpref; status_t err; struct termprefs tp; err = MyMessage(theme, termpref); if (err) return err; tp.magic = TP_MAGIC; tp.version = TP_VERSION; tp.x = 0; // don't open at specific coords tp.y = 0; if (termpref.FindInt32(TP_COLS, (int32 *)&tp.p.cols) != B_OK) tp.p.cols = 80; if (termpref.FindInt32(TP_ROWS, (int32 *)&tp.p.rows) != B_OK) tp.p.rows = 25; if (termpref.FindInt32(TP_TABWIDTH, (int32 *)&tp.p.tab_width) != B_OK) tp.p.tab_width = 8; 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); strcpy(tp.p.font, ff); strcat(tp.p.font, "/"); strcat(tp.p.font, fs); tp.p.font_size = (uint32)tFont.Size(); } tp.p.cursor_blink_rate = 1000000; tp.p.refresh_rate = 0; if (FindRGBColor(termpref, TP_BG, 0, &tp.p.bg) != B_OK) tp.p.bg = make_color(255,255,255,255); if (FindRGBColor(termpref, TP_FG, 0, &tp.p.fg) != B_OK) tp.p.fg = make_color(0,0,0,255); if (FindRGBColor(termpref, TP_CURBG, 0, &tp.p.curbg) != B_OK) tp.p.curbg = make_color(255,255,255,255); if (FindRGBColor(termpref, TP_CURFG, 0, &tp.p.curfg) != B_OK) tp.p.curfg = make_color(0,0,0,255); if (FindRGBColor(termpref, TP_SELBG, 0, &tp.p.selbg) != B_OK) tp.p.selbg = make_color(0,0,0,255); if (FindRGBColor(termpref, TP_SELFG, 0, &tp.p.selfg) != B_OK) tp.p.selfg = make_color(255,255,255,255); if (termpref.FindInt32(TP_ENCODING, (int32 *)&tp.p.encoding) != B_OK) tp.p.encoding = 0; // UTF-8 if (flags & UI_THEME_SETTINGS_SAVE && AddonFlags() & Z_THEME_ADDON_DO_SAVE) { BPath pTermPref; if (find_directory(B_USER_SETTINGS_DIRECTORY, &pTermPref) < B_OK) return EINVAL; pTermPref.Append("Terminal"); BFile fTermPref(pTermPref.Path(), B_WRITE_ONLY|B_CREATE_FILE|B_ERASE_FILE); if (fTermPref.InitCheck() != B_OK) { return fTermPref.InitCheck(); } fTermPref.Write(&tp, sizeof(struct termprefs)); BNodeInfo ni(&fTermPref); if (ni.InitCheck() == B_OK) ni.SetType("application/x-vnd.Be-pref"); } 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, kBeOSTerminalAppSig)) { err = B_OK; 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", (int32)0); err = msgr.SendMessage(&msg); } } } } return B_OK; }
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; }