diff --git a/headers/os/interface/InterfaceDefs.h b/headers/os/interface/InterfaceDefs.h index 02b9add674..38587d13b2 100644 --- a/headers/os/interface/InterfaceDefs.h +++ b/headers/os/interface/InterfaceDefs.h @@ -331,9 +331,15 @@ enum color_which { B_KEYBOARD_NAVIGATION_COLOR = B_NAVIGATION_BASE_COLOR, B_MENU_SELECTION_BACKGROUND_COLOR = B_MENU_SELECTED_BACKGROUND_COLOR, - // These are deprecated -- do not use in new code. See BScreen for - // the replacement for B_DESKTOP_COLOR. + // Update this constant to be the largest color constant excluding + // B_SUCCESS_COLOR and B_FAILURE_COLOR. + // If you add a constant with index greater than 100 you'll have to add + // to the second operand below and also update ServerReadOnlyMemory.h + B_COLOR_WHICH_COUNT = B_SCROLL_BAR_THUMB_COLOR + 3, + + // The following constants are deprecated, do not use in new code. B_DESKTOP_COLOR = 5 + // see BScreen class for B_DESKTOP_COLOR replacement }; diff --git a/headers/private/app/ServerReadOnlyMemory.h b/headers/private/app/ServerReadOnlyMemory.h index 46f925ec4e..1401467f63 100644 --- a/headers/private/app/ServerReadOnlyMemory.h +++ b/headers/private/app/ServerReadOnlyMemory.h @@ -13,23 +13,18 @@ #include -static const int32 kNumColors = 35; - struct server_read_only_memory { - rgb_color colors[kNumColors]; + rgb_color colors[B_COLOR_WHICH_COUNT]; }; -// NOTE: these functions must be kept in sync with InterfaceDefs.h color_which! - static inline int32 color_which_to_index(color_which which) { - // NOTE: this must be kept in sync with InterfaceDefs.h color_which! - if (which <= B_SCROLL_BAR_THUMB_COLOR) + if (which <= B_COLOR_WHICH_COUNT - 3) return which - 1; if (which >= B_SUCCESS_COLOR && which <= B_FAILURE_COLOR) - return which - B_SUCCESS_COLOR + B_SCROLL_BAR_THUMB_COLOR; + return which - B_SUCCESS_COLOR + B_COLOR_WHICH_COUNT - 3; return -1; } @@ -38,12 +33,12 @@ color_which_to_index(color_which which) static inline color_which index_to_color_which(int32 index) { - if (index >= 0 && index < kNumColors) { - if ((color_which)index < B_SCROLL_BAR_THUMB_COLOR) + if (index >= 0 && index < B_COLOR_WHICH_COUNT) { + if ((color_which)index < B_COLOR_WHICH_COUNT - 3) return (color_which)(index + 1); else { return (color_which)(index + B_SUCCESS_COLOR - - B_SCROLL_BAR_THUMB_COLOR); + - B_COLOR_WHICH_COUNT - 3); } } diff --git a/src/kits/interface/InterfaceDefs.cpp b/src/kits/interface/InterfaceDefs.cpp index 0019676f4a..7744821143 100644 --- a/src/kits/interface/InterfaceDefs.cpp +++ b/src/kits/interface/InterfaceDefs.cpp @@ -69,7 +69,7 @@ menu_info *_menu_info_ptr_; extern "C" const char B_NOTIFICATION_SENDER[] = "be:sender"; -static const rgb_color _kDefaultColors[kNumColors] = { +static const rgb_color _kDefaultColors[B_COLOR_WHICH_COUNT] = { {216, 216, 216, 255}, // B_PANEL_BACKGROUND_COLOR {216, 216, 216, 255}, // B_MENU_BACKGROUND_COLOR {255, 203, 0, 255}, // B_WINDOW_TAB_COLOR @@ -1071,7 +1071,7 @@ rgb_color ui_color(color_which which) { int32 index = color_which_to_index(which); - if (index < 0 || index >= kNumColors) { + if (index < 0 || index >= B_COLOR_WHICH_COUNT) { fprintf(stderr, "ui_color(): unknown color_which %d\n", which); return make_color(0, 0, 0); } @@ -1090,7 +1090,7 @@ void set_ui_color(const color_which &which, const rgb_color &color) { int32 index = color_which_to_index(which); - if (index < 0 || index >= kNumColors) { + if (index < 0 || index >= B_COLOR_WHICH_COUNT) { fprintf(stderr, "set_ui_color(): unknown color_which %d\n", which); return; } diff --git a/src/servers/app/DesktopSettings.cpp b/src/servers/app/DesktopSettings.cpp index f5660b914b..12646ae9f3 100644 --- a/src/servers/app/DesktopSettings.cpp +++ b/src/servers/app/DesktopSettings.cpp @@ -18,6 +18,7 @@ #include #include +#include #include #include "Desktop.h" @@ -77,7 +78,7 @@ DesktopSettingsPrivate::_SetDefaults() fWorkspacesRows = 2; memcpy(fShared.colors, BPrivate::kDefaultColors, - sizeof(rgb_color) * kNumColors); + sizeof(rgb_color) * B_COLOR_WHICH_COUNT); gSubpixelAntialiasing = false; gDefaultHintingMode = HINTING_MODE_ON; @@ -291,7 +292,7 @@ DesktopSettingsPrivate::_Load() } // colors - for (int32 i = 0; i < kNumColors; i++) { + for (int32 i = 0; i < B_COLOR_WHICH_COUNT; i++) { char colorName[12]; snprintf(colorName, sizeof(colorName), "color%" B_PRId32, (int32)index_to_color_which(i)); @@ -436,7 +437,7 @@ DesktopSettingsPrivate::Save(uint32 mask) settings.AddInt8("subpixel average weight", gSubpixelAverageWeight); settings.AddBool("subpixel ordering", gSubpixelOrderingRGB); - for (int32 i = 0; i < kNumColors; i++) { + for (int32 i = 0; i < B_COLOR_WHICH_COUNT; i++) { char colorName[12]; snprintf(colorName, sizeof(colorName), "color%" B_PRId32, (int32)index_to_color_which(i)); @@ -648,10 +649,10 @@ DesktopSettingsPrivate::WorkspacesMessage(int32 index) const void DesktopSettingsPrivate::SetUIColor(color_which which, const rgb_color color) { - // int32 index = color_which_to_index(which); - if (index < 0 || index >= kNumColors) + if (index < 0 || index >= B_COLOR_WHICH_COUNT) return; + fShared.colors[index] = color; // TODO: deprecate the background_color member of the menu_info struct, // otherwise we have to keep this duplication... @@ -666,7 +667,7 @@ DesktopSettingsPrivate::UIColor(color_which which) const { static const rgb_color invalidColor = {0, 0, 0, 0}; int32 index = color_which_to_index(which); - if (index < 0 || index >= kNumColors) + if (index < 0 || index >= B_COLOR_WHICH_COUNT) return invalidColor; return fShared.colors[index]; }