myinline const rgb_color ArpMessage::GetRGBColor(const char *name, const rgb_color& def, int32 index) const { if( this ) { rgb_color res; if( FindRGBColor(name, index, &res) != B_NO_ERROR ) return def; return res; } return def; }
status_t SoundplayThemesAddon::ApplyTheme(BMessage &theme, uint32 flags) { BMessage uisettings; status_t err; rgb_color panelcol; int32 wincnt = 1; err = theme.FindMessage(Z_THEME_UI_SETTINGS, &uisettings); if (err) return err; if (FindRGBColor(uisettings, B_UI_PANEL_BACKGROUND_COLOR, 0, &panelcol) < B_OK) panelcol = make_color(216,216,216,255); if (flags & UI_THEME_SETTINGS_SAVE && AddonFlags() & Z_THEME_ADDON_DO_SAVE) { // WRITEME } if (flags & UI_THEME_SETTINGS_APPLY && AddonFlags() & Z_THEME_ADDON_DO_APPLY) { BMessenger msgr(kSoundPlaySig); BMessage command(B_COUNT_PROPERTIES); BMessage answer; command.AddSpecifier("Window"); err = msgr.SendMessage(&command, &answer,2000000LL,2000000LL); if(B_OK == err) { if (answer.FindInt32("result", &wincnt) != B_OK) wincnt = 1; } BMessage msg(B_PASTE); AddRGBColor(msg, "RGBColor", panelcol); msg.AddPoint("_drop_point_", BPoint(0,0)); // send to every window (the Playlist window needs it too) for (int32 i = 0; i < wincnt; i++) { BMessage wmsg(msg); wmsg.AddSpecifier("Window", i); msgr.SendMessage(&wmsg, (BHandler *)NULL, 2000000LL); } } return B_OK; }
status_t PeThemesAddon::ApplyTheme(BMessage &theme, uint32 flags) { BMessage uisettings; BMessage peColors; status_t err; BPath PeSPath; rgb_color col; BString text; char buffer[10]; int i; err = theme.FindMessage(Z_THEME_UI_SETTINGS, &uisettings); if (err) return err; for (i = 0; sPeColors[i].pe; i++) { if (FindRGBColor(uisettings, sPeColors[i].dano, 0, &col) < B_OK) if (sPeColors[i].fallback && FindRGBColor(uisettings, sPeColors[i].fallback, 0, &col) < B_OK) continue; sprintf(buffer, "%02x%02x%02x", col.red, col.green, col.blue); text << sPeColors[i].pe << " color=#" << buffer << "\n"; } // apply BMessenger msgrPrefs; if (flags & UI_THEME_SETTINGS_APPLY && AddonFlags() & Z_THEME_ADDON_DO_APPLY && FindPrefWindow(msgrPrefs) == B_OK) { for (i = 0; sPeColors[i].pe; i++) { if (FindRGBColor(uisettings, sPeColors[i].dano, 0, &col) < B_OK) if (FindRGBColor(uisettings, sPeColors[i].fallback, 0, &col) < B_OK) continue; BMessage msgColor(msg_NewColor); msgColor.AddData("color", B_RGB_COLOR_TYPE, &col, sizeof(col)); msgColor.AddSpecifier("View", sPeColors[i].view); msgrPrefs.SendMessage(&msgColor); } // simulate a click on the "Ok" button in prefs // this doesn't seem to work anymore in Haiku !? BMessage click(B_SET_PROPERTY); click.AddSpecifier("Value"); click.AddSpecifier("View", "ok "); click.AddInt32("data", B_CONTROL_ON); msgrPrefs.SendMessage(&click); // just in case click.RemoveName("data"); click.AddInt32("data", B_CONTROL_OFF); msgrPrefs.SendMessage(&click); // instead simulate a button down/up snooze(100000); click.MakeEmpty(); click.what = B_MOUSE_DOWN; click.AddSpecifier("View", "ok "); click.AddSpecifier("View", (int32)0); msgrPrefs.SendMessage(&click); snooze(100000); click.what = B_MOUSE_UP; msgrPrefs.SendMessage(&click); } // save if (flags & UI_THEME_SETTINGS_SAVE && AddonFlags() & Z_THEME_ADDON_DO_SAVE) { if (find_directory(B_USER_SETTINGS_DIRECTORY, &PeSPath) < B_OK) return B_ERROR; PeSPath.Append(PE_SETTINGS_NAME); BFile PeSettings(PeSPath.Path(), B_WRITE_ONLY|B_OPEN_AT_END); if (PeSettings.InitCheck() < B_OK) return PeSettings.InitCheck(); if (PeSettings.Write(text.String(), strlen(text.String())) < B_OK) return B_ERROR; } return B_OK; }
status_t ArpMessage::FindRGBColor(const char *name, rgb_color *col) const { return FindRGBColor(name,(int32)0,col); }
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 BackgroundThemesAddon::ApplyTheme(BMessage &theme, uint32 flags) { BMessage backgrounds; status_t err = B_OK; BPath pDesktop; ssize_t flatSize; char *pAttr; if (!(flags & UI_THEME_SETTINGS_SET_ALL) || !(AddonFlags() & Z_THEME_ADDON_DO_SET_ALL)) return B_OK; err = MyMessage(theme, backgrounds); if (err) return err; // set desktop colors BScreen bs; rgb_color col; //const rgb_color *c; col = bs.DesktopColor(0); // by // should work as the rest of the fields (grouping) for (int i = 0; i < count_workspaces(); i++) { //ssize_t sz = 4; if (FindRGBColor(backgrounds, B__DESKTOP_COLOR, i, &col) != B_OK && i == 0) //if (backgrounds.FindData(B__DESKTOP_COLOR, (type_code)'RGBC', i, (const void **)&c, &sz) != B_OK && i == 0) break; // if no color at all, don't set them bs.SetDesktopColor(col, i, true); } // make sure we don't leave our garbage in the message // as it would offset the next call by adding rgb_colors on existing ones backgrounds.RemoveName(B__DESKTOP_COLOR); BMessenger tracker("application/x-vnd.Be-TRAK"); BMessage m(B_RESTORE_BACKGROUND_IMAGE); if (find_directory(B_DESKTOP_DIRECTORY, &pDesktop) < B_OK) return EINVAL; BNode nDesktop(pDesktop.Path()); if (nDesktop.InitCheck() < B_OK) return nDesktop.InitCheck(); flatSize = backgrounds.FlattenedSize(); pAttr = new char[flatSize]; if (pAttr == NULL) return ENOMEM; err = backgrounds.Flatten(pAttr, flatSize); if (err < B_OK) goto getout; err = nDesktop.WriteAttr(B_BACKGROUND_INFO, B_MESSAGE_TYPE, 0LL, pAttr, flatSize); if (err < B_OK) goto getout; //m.AddSpecifier("Window", "Desktop"); tracker.SendMessage(&m); return B_OK; getout: delete [] pAttr; return err; }
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; }