diff --git a/headers/os/interface/GraphicsDefs.h b/headers/os/interface/GraphicsDefs.h index 20fa8977a9..b07053ce78 100644 --- a/headers/os/interface/GraphicsDefs.h +++ b/headers/os/interface/GraphicsDefs.h @@ -101,6 +101,12 @@ typedef struct rgb_color { { return *(const uint32 *)this != *(const uint32 *)&other; } + + inline rgb_color& + operator=(const rgb_color& other) + { + return set_to(other.red, other.green, other.blue, other.alpha); + } #endif } rgb_color; diff --git a/src/preferences/appearance/APRView.cpp b/src/preferences/appearance/APRView.cpp index 1947338e7e..c1311507b5 100644 --- a/src/preferences/appearance/APRView.cpp +++ b/src/preferences/appearance/APRView.cpp @@ -1,9 +1,10 @@ /* - * Copyright 2002-2006, Haiku. All rights reserved. + * Copyright 2002-2008, Haiku. All rights reserved. * Distributed under the terms of the MIT License. * * Authors: * DarkWyrm (darkwyrm@earthlink.net) + * Rene Gollent (rene@gollent.com) */ #include #include @@ -33,6 +34,36 @@ #define COLOR_DROPPED 'cldp' #define DECORATOR_CHANGED 'dcch' +int32 sColorConsts[] = { + B_PANEL_BACKGROUND_COLOR, + B_PANEL_TEXT_COLOR, + B_DOCUMENT_BACKGROUND_COLOR, + B_DOCUMENT_TEXT_COLOR, + B_CONTROL_BACKGROUND_COLOR, + B_CONTROL_TEXT_COLOR, + B_CONTROL_BORDER_COLOR, + B_CONTROL_HIGHLIGHT_COLOR, + B_NAVIGATION_BASE_COLOR, + B_NAVIGATION_PULSE_COLOR, + B_SHINE_COLOR, + B_SHADOW_COLOR, + B_MENU_BACKGROUND_COLOR, + B_MENU_SELECTED_BACKGROUND_COLOR, + B_MENU_ITEM_TEXT_COLOR, + B_MENU_SELECTED_ITEM_TEXT_COLOR, + B_MENU_SELECTED_BORDER_COLOR, + B_TOOLTIP_BACKGROUND_COLOR, + B_TOOLTIP_TEXT_COLOR, + B_SUCCESS_COLOR, + B_FAILURE_COLOR, + B_WINDOW_TAB_COLOR, + B_WINDOW_TEXT_COLOR, + B_WINDOW_INACTIVE_TAB_COLOR, + B_WINDOW_INACTIVE_TEXT_COLOR, +}; + +const uint32 sColorCount = sizeof(sColorConsts) / sizeof(int32); + namespace BPrivate { int32 count_decorators(void); @@ -99,32 +130,12 @@ APRView::APRView(const BRect &frame, const char *name, int32 resize, int32 flags fAttrList->SetSelectionMessage(new BMessage(ATTRIBUTE_CHOSEN)); - fAttrList->AddItem(new ColorWhichItem(B_PANEL_BACKGROUND_COLOR)); - fAttrList->AddItem(new ColorWhichItem((color_which)B_PANEL_TEXT_COLOR)); - fAttrList->AddItem(new ColorWhichItem((color_which)B_DOCUMENT_BACKGROUND_COLOR)); - fAttrList->AddItem(new ColorWhichItem((color_which)B_DOCUMENT_TEXT_COLOR)); - fAttrList->AddItem(new ColorWhichItem((color_which)B_CONTROL_BACKGROUND_COLOR)); - fAttrList->AddItem(new ColorWhichItem((color_which)B_CONTROL_TEXT_COLOR)); - fAttrList->AddItem(new ColorWhichItem((color_which)B_CONTROL_BORDER_COLOR)); - fAttrList->AddItem(new ColorWhichItem((color_which)B_CONTROL_HIGHLIGHT_COLOR)); - fAttrList->AddItem(new ColorWhichItem((color_which)B_NAVIGATION_BASE_COLOR)); - fAttrList->AddItem(new ColorWhichItem((color_which)B_NAVIGATION_PULSE_COLOR)); - fAttrList->AddItem(new ColorWhichItem((color_which)B_SHINE_COLOR)); - fAttrList->AddItem(new ColorWhichItem((color_which)B_SHADOW_COLOR)); - fAttrList->AddItem(new ColorWhichItem(B_MENU_BACKGROUND_COLOR)); - fAttrList->AddItem(new ColorWhichItem((color_which)B_MENU_SELECTED_BACKGROUND_COLOR)); - fAttrList->AddItem(new ColorWhichItem(B_MENU_ITEM_TEXT_COLOR)); - fAttrList->AddItem(new ColorWhichItem(B_MENU_SELECTED_ITEM_TEXT_COLOR)); - fAttrList->AddItem(new ColorWhichItem((color_which)B_MENU_SELECTED_BORDER_COLOR)); - fAttrList->AddItem(new ColorWhichItem((color_which)B_TOOLTIP_BACKGROUND_COLOR)); - - fAttrList->AddItem(new ColorWhichItem((color_which)B_SUCCESS_COLOR)); - fAttrList->AddItem(new ColorWhichItem((color_which)B_FAILURE_COLOR)); - fAttrList->AddItem(new ColorWhichItem(B_WINDOW_TAB_COLOR)); - fAttrList->AddItem(new ColorWhichItem((color_which)B_WINDOW_TAB_TEXT_COLOR)); - fAttrList->AddItem(new ColorWhichItem((color_which)B_INACTIVE_WINDOW_TAB_COLOR)); - fAttrList->AddItem(new ColorWhichItem((color_which)B_INACTIVE_WINDOW_TAB_TEXT_COLOR)); + printf("Color count: %lu\n", sColorCount); + for (uint32 i = 0; i < sColorCount; i++) { + printf("Adding color item for which: %ld\n", sColorConsts[i]); + fAttrList->AddItem(new ColorWhichItem((color_which)sColorConsts[i])); + } BRect wellrect(0,0,50,50); wellrect.OffsetTo(rect.right + 30, rect.top + @@ -201,6 +212,7 @@ APRView::MessageReceived(BMessage *msg) fPicker->SetValue(*col); fColorWell->SetColor(*col); fColorWell->Invalidate(); + UpdateCurrentColor(); } } @@ -220,10 +232,11 @@ APRView::MessageReceived(BMessage *msg) fColorWell->SetColor(col); fColorWell->Invalidate(); - + // Update current fAttribute in the settings - fCurrentSet.SetColor(fAttrString.String(),col); - + fCurrentSet.SetColor(fAttribute, col); + UpdateCurrentColor(); + fDefaults->SetEnabled(fCurrentSet.IsDefaultable()); fRevert->SetEnabled(true); @@ -240,23 +253,26 @@ APRView::MessageReceived(BMessage *msg) fAttrString=whichitem->Text(); UpdateControlsFromAttr(whichitem->Text()); - + fDefaults->SetEnabled(fCurrentSet.IsDefaultable()); break; } case REVERT_SETTINGS: { fCurrentSet=fPrevSet; UpdateControlsFromAttr(fAttrString.String()); + UpdateAllColors(); fRevert->SetEnabled(false); break; } case DEFAULT_SETTINGS: { - fCurrentSet.SetToDefaults(); + fCurrentSet = ColorSet::DefaultColorSet(); fDefaults->SetEnabled(false); UpdateControlsFromAttr(fAttrString.String()); + UpdateAllColors(); + BMenuItem *item = fDecorMenu->FindItem("Default"); if (item) { @@ -275,21 +291,31 @@ APRView::MessageReceived(BMessage *msg) void APRView::LoadSettings(void) { - // Load the current GUI color settings from disk. This is done instead of - // getting them from the server at this point for testing purposes. - - // Query the server for the current settings - //BPrivate::get_system_colors(&fCurrentSet); - - // TODO: remove this and enable the get_system_colors() call - if (ColorSet::LoadColorSet("/boot/home/config/settings/app_server/system_colors",&fCurrentSet) != B_OK) { - fCurrentSet.SetToDefaults(); - ColorSet::SaveColorSet("/boot/home/config/settings/app_server/system_colors",fCurrentSet); + printf("Max colors: %lu\n", sColorCount); + for (uint32 i = 0; i < sColorCount; i++) { + printf("getting ui_color for index %lu, constant: %ld\n", i, sColorConsts[i]); + fCurrentSet.SetColor((color_which)sColorConsts[i], ui_color((color_which)sColorConsts[i])); } - + + fCurrentSet.PrintToStream(); + fPrevSet = fCurrentSet; } +void APRView::UpdateAllColors(void) +{ + for (uint32 i = 0; i < sColorCount; i++) + set_ui_color((color_which)sColorConsts[i], + fCurrentSet.AttributeToColor((color_which)sColorConsts[i])); +} + +void APRView::UpdateCurrentColor(void) +{ + rgb_color col=fPicker->ValueAsColor(); + ColorWhichItem *whichitem = (ColorWhichItem *)fAttrList->ItemAt(fAttrList->CurrentSelection()); + set_ui_color(whichitem->GetAttribute(), col); +} + void APRView::UpdateControlsFromAttr(const char *string) { if (!string) diff --git a/src/preferences/appearance/APRView.h b/src/preferences/appearance/APRView.h index 1c6b84fb88..ee715fe809 100644 --- a/src/preferences/appearance/APRView.h +++ b/src/preferences/appearance/APRView.h @@ -1,9 +1,10 @@ /* - * Copyright 2002-2006, Haiku. All rights reserved. + * Copyright 2002-2008, Haiku. All rights reserved. * Distributed under the terms of the MIT License. * * Authors: * DarkWyrm (darkwyrm@earthlink.net) + * Rene Gollent (rene@gollent.com) */ #ifndef APR_VIEW_H_ #define APR_VIEW_H_ @@ -43,6 +44,8 @@ public: protected: void UpdateControlsFromAttr(const char *string); + void UpdateCurrentColor(); + void UpdateAllColors(); BColorControl *fPicker; diff --git a/src/preferences/appearance/ColorSet.cpp b/src/preferences/appearance/ColorSet.cpp index b59dc37f0f..68eef027f1 100644 --- a/src/preferences/appearance/ColorSet.cpp +++ b/src/preferences/appearance/ColorSet.cpp @@ -1,10 +1,11 @@ /* - * Copyright 2001-2006, Haiku. + * Copyright 2001-2008, Haiku. * Distributed under the terms of the MIT License. * * Authors: * DarkWyrm * Stephan Aßmus + * Rene Gollent */ #include @@ -16,17 +17,10 @@ #include #include "ColorSet.h" -static void -set_rgb_color(rgb_color& color, uint8 red, uint8 green, uint8 blue) -{ - color.red = red; - color.green = green; - color.blue = blue; - color.alpha = 255; -} +static ColorSet sDefaults = ColorSet::DefaultColorSet(); +static std::map sColorNames = ColorSet::DefaultColorNames(); - -static bool +bool match_rgb_color(rgb_color& color, uint8 red, uint8 green, uint8 blue) { return color.red == red @@ -71,148 +65,68 @@ ColorSet::operator=(const ColorSet &cs) void ColorSet::SetColors(const ColorSet &cs) { - panel_background=cs.panel_background; - panel_text=cs.panel_text; - - document_background=cs.document_background; - document_text=cs.document_text; - - control_background=cs.control_background; - control_text=cs.control_text; - control_highlight=cs.control_highlight; - control_border=cs.control_border; - - tooltip_background=cs.tooltip_background; - tooltip_text=cs.tooltip_text; - - menu_background=cs.menu_background; - menu_selected_background=cs.menu_selected_background; - menu_text=cs.menu_text; - menu_selected_text=cs.menu_selected_text; - menu_selected_border=cs.menu_selected_border; - - keyboard_navigation_base=cs.keyboard_navigation_base; - keyboard_navigation_pulse=cs.keyboard_navigation_pulse; - - success=cs.success; - failure=cs.failure; - shine=cs.shine; - shadow=cs.shadow; - - window_tab=cs.window_tab; - window_tab_text=cs.window_tab_text; - inactive_window_tab=cs.inactive_window_tab; - inactive_window_tab_text=cs.inactive_window_tab_text; + fColors = cs.fColors; } //! Prints all color set elements to stdout void ColorSet::PrintToStream(void) const { - printf("panel_background "); PrintMember(panel_background); - printf("panel_text "); PrintMember(panel_text); - - printf("document_background "); PrintMember(document_background); - printf("document_text "); PrintMember(document_text); - - printf("control_background "); PrintMember(control_background); - printf("control_text "); PrintMember(control_text); - printf("control_highlight "); PrintMember(control_highlight); - printf("control_border "); PrintMember(control_border); - - printf("tooltip_background "); PrintMember(tooltip_background); - printf("tooltip_text "); PrintMember(tooltip_text); - - printf("menu_background "); PrintMember(menu_background); - printf("menu_selected_background "); PrintMember(menu_selected_background); - printf("menu_text "); PrintMember(menu_text); - printf("menu_selected_text "); PrintMember(menu_selected_text); - printf("menu_selected_border "); PrintMember(menu_selected_border); - - printf("keyboard_navigation_base "); PrintMember(keyboard_navigation_base); - printf("keyboard_navigation_pulse "); PrintMember(keyboard_navigation_pulse); - - printf("success "); PrintMember(success); - printf("failure "); PrintMember(failure); - printf("shine "); PrintMember(shine); - printf("shadow "); PrintMember(shadow); - - printf("window_tab "); PrintMember(window_tab); - printf("window_tab_text "); PrintMember(window_tab_text); - - printf("inactive_window_tab "); PrintMember(inactive_window_tab); - printf("inactive_window_tab_text "); PrintMember(inactive_window_tab_text); + for (std::map::const_iterator it = sColorNames.begin(); it != sColorNames.end(); ++it) { + printf("%s ", it->second.String()); + PrintMember(it->first); + printf("\n"); + } } /*! \brief Assigns the default system colors to the passed ColorSet object \param set The ColorSet object to set to defaults */ -void -ColorSet::SetToDefaults(void) +ColorSet +ColorSet::DefaultColorSet(void) { #ifdef DEBUG_COLORSET printf("Initializing color settings to defaults\n"); #endif - set_rgb_color(panel_background, 216, 216, 216); - set_rgb_color(panel_text, 0, 0, 0); - set_rgb_color(document_background, 255, 255, 255); - set_rgb_color(document_text, 0, 0, 0); - set_rgb_color(control_background, 245, 245, 245); - set_rgb_color(control_text, 0, 0, 0); - set_rgb_color(control_border, 0, 0, 0); - set_rgb_color(control_highlight, 102, 152, 203); - set_rgb_color(keyboard_navigation_base, 0, 0, 229); - set_rgb_color(keyboard_navigation_pulse, 0, 0, 0); - set_rgb_color(shine, 255, 255, 255); - set_rgb_color(shadow, 0, 0, 0); - set_rgb_color(menu_background, 216, 216, 216); - set_rgb_color(menu_selected_background, 115, 120, 184); - set_rgb_color(menu_text, 0, 0, 0); - set_rgb_color(menu_selected_text, 255, 255, 255); - set_rgb_color(menu_selected_border, 0, 0, 0); - set_rgb_color(tooltip_background, 255, 255, 0); - set_rgb_color(tooltip_text, 0, 0, 0); - set_rgb_color(success, 0, 255, 0); - set_rgb_color(failure, 255, 0, 0); - set_rgb_color(window_tab, 255, 203, 0); - set_rgb_color(window_tab_text, 0, 0, 0); - set_rgb_color(inactive_window_tab, 232, 232, 232); - set_rgb_color(inactive_window_tab_text, 80, 80, 80); + ColorSet set; + set.fColors[B_PANEL_BACKGROUND_COLOR] = make_color(216, 216, 216); + set.fColors[B_PANEL_TEXT_COLOR] = make_color(0, 0, 0); + set.fColors[B_DOCUMENT_BACKGROUND_COLOR] = make_color(255,255, 255); + set.fColors[B_DOCUMENT_TEXT_COLOR] = make_color(0, 0, 0); + set.fColors[B_CONTROL_BACKGROUND_COLOR] = make_color(245, 245, 245); + set.fColors[B_CONTROL_TEXT_COLOR] = make_color(0, 0, 0); + set.fColors[B_CONTROL_BORDER_COLOR] = make_color(0, 0, 0); + set.fColors[B_CONTROL_HIGHLIGHT_COLOR] = make_color(102, 152, 203); + set.fColors[B_NAVIGATION_BASE_COLOR] = make_color(0, 0, 229); + set.fColors[B_NAVIGATION_PULSE_COLOR] = make_color(0, 0, 0); + set.fColors[B_SHINE_COLOR] = make_color(255, 255, 255); + set.fColors[B_SHADOW_COLOR] = make_color(0, 0, 0); + set.fColors[B_MENU_BACKGROUND_COLOR] = make_color(216, 216, 216); + set.fColors[B_MENU_SELECTED_BACKGROUND_COLOR] = make_color(115, 120, 184); + set.fColors[B_MENU_ITEM_TEXT_COLOR] = make_color(0, 0, 0); + set.fColors[B_MENU_SELECTED_ITEM_TEXT_COLOR] = make_color(255, 255, 255); + set.fColors[B_MENU_SELECTED_BORDER_COLOR] = make_color(0, 0, 0); + set.fColors[B_TOOLTIP_BACKGROUND_COLOR] = make_color(255, 255, 0); + set.fColors[B_TOOLTIP_TEXT_COLOR] = make_color(0, 0, 0); + set.fColors[B_SUCCESS_COLOR] = make_color(0, 255, 0); + set.fColors[B_FAILURE_COLOR] = make_color(255, 0, 0); + set.fColors[B_WINDOW_TAB_COLOR] = make_color(255, 203, 0); + set.fColors[B_WINDOW_TEXT_COLOR] = make_color(0, 0, 0); + set.fColors[B_WINDOW_INACTIVE_TAB_COLOR] = make_color(232, 232, 232); + set.fColors[B_WINDOW_INACTIVE_TEXT_COLOR] = make_color(80, 80, 80); + + return set; } + /*! \brief Checks if the ColorSet can be set to defaults. */ bool ColorSet::IsDefaultable() { - // TODO: Move all the default color values into constants - return !match_rgb_color(panel_background, 216, 216, 216) - || !match_rgb_color(panel_text, 0, 0, 0) - || !match_rgb_color(document_background, 255, 255, 255) - || !match_rgb_color(document_text, 0, 0, 0) - || !match_rgb_color(control_background, 245, 245, 245) - || !match_rgb_color(control_text, 0, 0, 0) - || !match_rgb_color(control_border, 0, 0, 0) - || !match_rgb_color(control_highlight, 102, 152, 203) - || !match_rgb_color(keyboard_navigation_base, 0, 0, 229) - || !match_rgb_color(keyboard_navigation_pulse, 0, 0, 0) - || !match_rgb_color(shine, 255, 255, 255) - || !match_rgb_color(shadow, 0, 0, 0) - || !match_rgb_color(menu_background, 216, 216, 216) - || !match_rgb_color(menu_selected_background, 115, 120, 184) - || !match_rgb_color(menu_text, 0, 0, 0) - || !match_rgb_color(menu_selected_text, 255, 255, 255) - || !match_rgb_color(menu_selected_border, 0, 0, 0) - || !match_rgb_color(tooltip_background, 255, 255, 0) - || !match_rgb_color(tooltip_text, 0, 0, 0) - || !match_rgb_color(success, 0, 255, 0) - || !match_rgb_color(failure, 255, 0, 0) - || !match_rgb_color(window_tab, 255, 203, 0) - || !match_rgb_color(window_tab_text, 0, 0, 0) - || !match_rgb_color(inactive_window_tab, 232, 232, 232) - || !match_rgb_color(inactive_window_tab_text, 80, 80, 80); + return (*this == sDefaults); } /*! @@ -226,46 +140,16 @@ ColorSet::ConvertToMessage(BMessage *msg) const return false; msg->MakeEmpty(); - - msg->AddData("Panel Background",(type_code)'RGBC',&panel_background, - sizeof(rgb_color) ); - msg->AddData("Panel Text",(type_code)'RGBC',&panel_text,sizeof(rgb_color)); - msg->AddData("Document Background",(type_code)'RGBC',&document_background, - sizeof(rgb_color)); - msg->AddData("Document Text",(type_code)'RGBC',&document_text,sizeof(rgb_color)); - msg->AddData("Control Background",(type_code)'RGBC',&control_background, - sizeof(rgb_color)); - msg->AddData("Control Text",(type_code)'RGBC',&control_text,sizeof(rgb_color)); - msg->AddData("Control Highlight",(type_code)'RGBC',&control_highlight, - sizeof(rgb_color)); - msg->AddData("Control Border",(type_code)'RGBC',&control_border,sizeof(rgb_color)); - msg->AddData("Tooltip Background",(type_code)'RGBC',&tooltip_background, - sizeof(rgb_color)); - msg->AddData("Tooltip Text",(type_code)'RGBC',&tooltip_text,sizeof(rgb_color)); - msg->AddData("Menu Background",(type_code)'RGBC',&menu_background, - sizeof(rgb_color)); - msg->AddData("Selected Menu Item Background",(type_code)'RGBC',&menu_selected_background, - sizeof(rgb_color)); - msg->AddData("Keyboard Navigation Base",(type_code)'RGBC',&keyboard_navigation_base, - sizeof(rgb_color)); - msg->AddData("Keyboard Navigation Pulse",(type_code)'RGBC', - &keyboard_navigation_pulse,sizeof(rgb_color)); - msg->AddData("Menu Item Text",(type_code)'RGBC',&menu_text,sizeof(rgb_color)); - msg->AddData("Selected Menu Item Text",(type_code)'RGBC',&menu_selected_text, - sizeof(rgb_color)); - msg->AddData("Selected Menu Item Border",(type_code)'RGBC',&menu_selected_border, - sizeof(rgb_color)); - msg->AddData("Success",(type_code)'RGBC',&success,sizeof(rgb_color)); - msg->AddData("Failure",(type_code)'RGBC',&failure,sizeof(rgb_color)); - msg->AddData("Shine",(type_code)'RGBC',&shine,sizeof(rgb_color)); - msg->AddData("Shadow",(type_code)'RGBC',&shadow,sizeof(rgb_color)); - msg->AddData("Window Tab",(type_code)'RGBC',&window_tab,sizeof(rgb_color)); - msg->AddData("Window Tab Text",(type_code)'RGBC',&window_tab_text, - sizeof(rgb_color)); - msg->AddData("Inactive Window Tab",(type_code)'RGBC',&inactive_window_tab, - sizeof(rgb_color)); - msg->AddData("Inactive Window Tab Text",(type_code)'RGBC', - &inactive_window_tab_text,sizeof(rgb_color)); + rgb_color color; + + for (std::map::const_iterator it = sColorNames.begin(); it != sColorNames.end(); ++it) { + std::map::const_iterator cit = fColors.find(it->first); + if (cit != fColors.end()) + msg->AddData(it->second.String(), (type_code)'RGBC', &(cit->second), sizeof(rgb_color)); + else + msg->AddData(it->second.String(), (type_code)'RGBC', &color, sizeof(rgb_color)); + } + return true; } @@ -284,59 +168,48 @@ ColorSet::ConvertFromMessage(const BMessage *msg) ssize_t size; BString str; - if(msg->FindData("Panel Background",(type_code)'RGBC',(const void**)&col,&size)==B_OK) - panel_background=*col; - if(msg->FindData("Panel Text",(type_code)'RGBC',(const void**)&col,&size)==B_OK) - panel_text=*col; - if(msg->FindData("Document Background",(type_code)'RGBC',(const void**)&col,&size)==B_OK) - document_background=*col; - if(msg->FindData("Document Text",(type_code)'RGBC',(const void**)&col,&size)==B_OK) - document_text=*col; - if(msg->FindData("Control Background",(type_code)'RGBC',(const void**)&col,&size)==B_OK) - control_background=*col; - if(msg->FindData("Control Text",(type_code)'RGBC',(const void**)&col,&size)==B_OK) - control_text=*col; - if(msg->FindData("Control Highlight",(type_code)'RGBC',(const void**)&col,&size)==B_OK) - control_highlight=*col; - if(msg->FindData("Control Border",(type_code)'RGBC',(const void**)&col,&size)==B_OK) - control_border=*col; - if(msg->FindData("Tooltip Background",(type_code)'RGBC',(const void**)&col,&size)==B_OK) - tooltip_background=*col; - if(msg->FindData("Tooltip Text",(type_code)'RGBC',(const void**)&col,&size)==B_OK) - tooltip_text=*col; - if(msg->FindData("Menu Background",(type_code)'RGBC',(const void**)&col,&size)==B_OK) - menu_background=*col; - if(msg->FindData("Selected Menu Item Background",(type_code)'RGBC',(const void**)&col,&size)==B_OK) - menu_selected_background=*col; - if(msg->FindData("Navigation Base",(type_code)'RGBC',(const void**)&col,&size)==B_OK) - keyboard_navigation_base=*col; - if(msg->FindData("Navigation Pulse",(type_code)'RGBC',(const void**)&col,&size)==B_OK) - keyboard_navigation_pulse=*col; - if(msg->FindData("Menu Item Text",(type_code)'RGBC',(const void**)&col,&size)==B_OK) - menu_text=*col; - if(msg->FindData("Selected Menu Item Text",(type_code)'RGBC',(const void**)&col,&size)==B_OK) - menu_selected_text=*col; - if(msg->FindData("Selected Menu Item Border",(type_code)'RGBC',(const void**)&col,&size)==B_OK) - menu_selected_border=*col; - if(msg->FindData("Success",(type_code)'RGBC',(const void**)&col,&size)==B_OK) - success=*col; - if(msg->FindData("Failure",(type_code)'RGBC',(const void**)&col,&size)==B_OK) - failure=*col; - if(msg->FindData("Shine",(type_code)'RGBC',(const void**)&col,&size)==B_OK) - shine=*col; - if(msg->FindData("Shadow",(type_code)'RGBC',(const void**)&col,&size)==B_OK) - shadow=*col; - if(msg->FindData("Window Tab",(type_code)'RGBC',(const void**)&col,&size)==B_OK) - window_tab=*col; - if(msg->FindData("Window Tab Text",(type_code)'RGBC',(const void**)&col,&size)==B_OK) - window_tab_text=*col; - if(msg->FindData("Inactive Window Tab",(type_code)'RGBC',(const void**)&col,&size)==B_OK) - inactive_window_tab=*col; - if(msg->FindData("Inactive Window Tab Text",(type_code)'RGBC',(const void**)&col,&size)==B_OK) - inactive_window_tab_text=*col; + for (std::map::const_iterator it = sColorNames.begin(); + it != sColorNames.end(); ++it) { + if (msg->FindData(it->second.String(),(type_code)'RGBC',(const void**)&col,&size)==B_OK) + fColors[it->first] = *col; + } + return true; } +std::map +ColorSet::DefaultColorNames(void) +{ + std::map names; + + names[B_PANEL_BACKGROUND_COLOR] = "Panel Background"; + names[B_PANEL_TEXT_COLOR] = "Panel Text"; + names[B_DOCUMENT_BACKGROUND_COLOR] = "Document Background"; + names[B_DOCUMENT_TEXT_COLOR] = "Document Text"; + names[B_CONTROL_BACKGROUND_COLOR] = "Control Background"; + names[B_CONTROL_TEXT_COLOR] = "Control Text"; + names[B_CONTROL_BORDER_COLOR] = "Control Border"; + names[B_CONTROL_HIGHLIGHT_COLOR] = "Control Highlight"; + names[B_NAVIGATION_BASE_COLOR] = "Navigation Base"; + names[B_NAVIGATION_PULSE_COLOR] = "Navigation Pulse"; + names[B_SHINE_COLOR] = "Shine"; + names[B_SHADOW_COLOR] = "Shadow"; + names[B_MENU_BACKGROUND_COLOR] = "Menu Background"; + names[B_MENU_SELECTED_BACKGROUND_COLOR] = "Selected Menu Item Background"; + names[B_MENU_ITEM_TEXT_COLOR] = "Menu Item Text"; + names[B_MENU_SELECTED_ITEM_TEXT_COLOR] = "Selected Menu Item Text"; + names[B_MENU_SELECTED_BORDER_COLOR] = "Selected Menu Item Border"; + names[B_TOOLTIP_BACKGROUND_COLOR] = "Tooltip Background"; + names[B_TOOLTIP_TEXT_COLOR] = "Tooltip Text"; + names[B_SUCCESS_COLOR] = "Success"; + names[B_FAILURE_COLOR] = "Failure"; + names[B_WINDOW_TAB_COLOR] = "Window Tab"; + names[B_WINDOW_TEXT_COLOR] = "Window Tab Text"; + names[B_WINDOW_INACTIVE_TAB_COLOR] = "Inactive Window Tab"; + names[B_WINDOW_INACTIVE_TEXT_COLOR] = "Inactive Window Tab Text"; + + return names; +} /*! \brief Assigns a value to a named color member @@ -344,226 +217,65 @@ ColorSet::ConvertFromMessage(const BMessage *msg) \param value An rgb_color which is the new value of the member */ status_t -ColorSet::SetColor(const char *string, rgb_color value) +ColorSet::SetColor(color_which which, rgb_color value) { - if(!string) - return B_BAD_VALUE; - - rgb_color *col=StringToMember(string); - if(!col) - return B_NAME_NOT_FOUND; - *col=value; + fColors[which] = value; return B_OK; } -/*! - \brief Obtains a color based on a specified string - \param string name of the color to obtain - \return The set's color or (0,0,0,0) if not found -*/ -rgb_color -ColorSet::StringToColor(const char *string) -{ - rgb_color *col=StringToMember(string); - if(!col) { - rgb_color c; - return c; - } - - return *col; -} - /*! \brief Obtains the set's color member based on a specified string \param string name of the color member to obtain \return An RGBColor pointer or NULL if not found */ -rgb_color * -ColorSet::StringToMember(const char *string) + +rgb_color +ColorSet::StringToColor(const char *string) const +{ + rgb_color color; + + if (!string) + return color; + + color_which which = StringToWhich(string); + if (which != -1) { + std::map::const_iterator it = fColors.find(which); + if (it != fColors.end()) + return it->second; + } + + return color; +} + +color_which +ColorSet::StringToWhich(const char *string) const { if(!string) - return NULL; + return (color_which)-1; - if(strcmp(string,"Panel Background")==0) - return &panel_background; - if(strcmp(string,"Panel Text")==0) - return &panel_text; - if(strcmp(string,"Document Background")==0) - return &document_background; - if(strcmp(string,"Document Text")==0) - return &document_text; - if(strcmp(string,"Control Background")==0) - return &control_background; - if(strcmp(string,"Control Text")==0) - return &control_text; - if(strcmp(string,"Control Highlight")==0) - return &control_highlight; - if(strcmp(string,"Control Border")==0) - return &control_border; - if(strcmp(string,"Tooltip Background")==0) - return &tooltip_background; - if(strcmp(string,"Tooltip Text")==0) - return &tooltip_text; - if(strcmp(string,"Menu Background")==0) - return &menu_background; - if(strcmp(string,"Selected Menu Item Background")==0) - return &menu_selected_background; - if(strcmp(string,"Navigation Base")==0) - return &keyboard_navigation_base; - if(strcmp(string,"Navigation Pulse")==0) - return &keyboard_navigation_pulse; - if(strcmp(string,"Menu Item Text")==0) - return &menu_text; - if(strcmp(string,"Selected Menu Item Text")==0) - return &menu_selected_text; - if(strcmp(string,"Selected Menu Item Border")==0) - return &menu_selected_border; - if(strcmp(string,"Success")==0) - return &success; - if(strcmp(string,"Failure")==0) - return &failure; - if(strcmp(string,"Shine")==0) - return &shine; - if(strcmp(string,"Shadow")==0) - return &shadow; - if(strcmp(string,"Window Tab")==0) - return &window_tab; - if(strcmp(string,"Window Tab Text")==0) - return &window_tab_text; - if(strcmp(string,"Inactive Window Tab")==0) - return &inactive_window_tab; - if(strcmp(string,"Inactive Window Tab Text")==0) - return &inactive_window_tab_text; + for (std::map::const_iterator it = sColorNames.begin(); it != sColorNames.end(); ++it) + if (it->second == string) + return it->first; - return NULL; + return (color_which)-1; } rgb_color ColorSet::AttributeToColor(int32 which) { - switch(which) { - case B_PANEL_BACKGROUND_COLOR: { - return panel_background; - break; - } - -#ifndef HAIKU_TARGET_PLATFORM_BEOS - case B_PANEL_TEXT_COLOR: { - return panel_text; - break; - } - case B_DOCUMENT_BACKGROUND_COLOR: { - return document_background; - break; - } - case B_DOCUMENT_TEXT_COLOR: { - return document_text; - break; - } - case B_CONTROL_BACKGROUND_COLOR: { - return control_background; - break; - } - case B_CONTROL_TEXT_COLOR: { - return control_text; - break; - } - case B_CONTROL_BORDER_COLOR: { - return control_border; - break; - } - case B_CONTROL_HIGHLIGHT_COLOR: { - return control_highlight; - break; - } - case B_NAVIGATION_BASE_COLOR: { - return keyboard_navigation_base; - break; - } - case B_NAVIGATION_PULSE_COLOR: { - return keyboard_navigation_pulse; - break; - } - case B_SHINE_COLOR: { - return shine; - break; - } - case B_SHADOW_COLOR: { - return shadow; - break; - } - case B_MENU_SELECTED_BACKGROUND_COLOR: { - return menu_selected_background; - break; - } - case B_MENU_SELECTED_BORDER_COLOR: { - return menu_selected_border; - break; - } - case B_TOOLTIP_BACKGROUND_COLOR: { - return tooltip_background; - break; - } - case B_TOOLTIP_TEXT_COLOR: { - return tooltip_text; - break; - } - case B_SUCCESS_COLOR: { - return success; - break; - } - case B_FAILURE_COLOR: { - return failure; - break; - } -#endif - case B_MENU_BACKGROUND_COLOR: { - return menu_background; - break; - } - case B_MENU_ITEM_TEXT_COLOR: { - return menu_text; - break; - } - case B_MENU_SELECTED_ITEM_TEXT_COLOR: { - return menu_selected_text; - break; - } - case B_WINDOW_TAB_COLOR: { - return window_tab; - break; - } - - // DANGER! DANGER, WILL ROBINSON!! - // These are magic numbers to work around compatibility difficulties while still keeping - // functionality. This __will__ break following R1 - case 22: { - return window_tab_text; - break; - } - case 23: { - return inactive_window_tab; - break; - } - case 24: { - return inactive_window_tab_text; - break; - } - - default: { - rgb_color c; - return c; - break; - } - } + return fColors[(color_which)which]; } void -ColorSet::PrintMember(const rgb_color &color) const +ColorSet::PrintMember(color_which which) const { - printf("rgb_color(%d, %d, %d, %d)",color.red,color.green,color.blue, - color.alpha); + std::map::const_iterator it = fColors.find(which); + if (it != fColors.end()) + printf("rgb_color(%d, %d, %d, %d)", it->second.red,it->second.green,it->second.blue, + it->second.alpha); + else + printf("color (%d) not found\n", which); } @@ -607,3 +319,4 @@ ColorSet::SaveColorSet(const char *path, const ColorSet &set) return msg.Flatten(&file); } + diff --git a/src/preferences/appearance/ColorSet.h b/src/preferences/appearance/ColorSet.h index e5d49094cb..f89b15b4c8 100644 --- a/src/preferences/appearance/ColorSet.h +++ b/src/preferences/appearance/ColorSet.h @@ -1,9 +1,10 @@ /* - * Copyright 2001-2006, Haiku. + * Copyright 2001-2008, Haiku. * Distributed under the terms of the MIT License. * * Authors: * DarkWyrm + * Rene Gollent */ #ifndef COLOR_SET_H #define COLOR_SET_H @@ -14,6 +15,7 @@ #include #include +#include /*! \class ColorSet ColorSet.h @@ -31,56 +33,28 @@ class ColorSet : public BLocker { bool ConvertToMessage(BMessage *msg) const; bool ConvertFromMessage(const BMessage *msg); - void SetToDefaults(void); bool IsDefaultable(void); - rgb_color StringToColor(const char *string); + rgb_color StringToColor(const char *string) const; rgb_color AttributeToColor(int32 which); - status_t SetColor(const char *string, rgb_color value); + status_t SetColor(color_which which, rgb_color value); static status_t LoadColorSet(const char *path, ColorSet *set); static status_t SaveColorSet(const char *path, const ColorSet &set); - - rgb_color panel_background, - panel_text, - - document_background, - document_text, - - control_background, - control_text, - control_highlight, - control_border, - - tooltip_background, - tooltip_text, - - menu_background, - menu_selected_background, - menu_text, - menu_selected_text, - menu_selected_border, - - keyboard_navigation_base, - keyboard_navigation_pulse, - - success, - failure, - shine, - shadow, - window_tab, - - // Not all of these guys do exist in InterfaceDefs.h, - // but we keep them as part of the color set anyway - - // they're important nonetheless - window_tab_text, - inactive_window_tab, - inactive_window_tab_text; + + static ColorSet DefaultColorSet(void); + static std::map DefaultColorNames(void); + + inline bool operator==(const ColorSet &other) + { + return (fColors == other.fColors); + } private: - rgb_color *StringToMember(const char *string); - void PrintMember(const rgb_color &color) const; + color_which StringToWhich(const char *string) const; + void PrintMember(color_which which) const; + std::map fColors; }; #endif // COLOR_SET_H diff --git a/src/preferences/appearance/ColorWhichItem.cpp b/src/preferences/appearance/ColorWhichItem.cpp index a39e387b84..532bf8cad7 100644 --- a/src/preferences/appearance/ColorWhichItem.cpp +++ b/src/preferences/appearance/ColorWhichItem.cpp @@ -1,9 +1,10 @@ /* - * Copyright 2002-2006, Haiku. All rights reserved. + * Copyright 2002-2008, Haiku. All rights reserved. * Distributed under the terms of the MIT License. * * Authors: * DarkWyrm (darkwyrm@earthlink.net) + * Rene Gollent (rene@gollent.com) */ #include "ColorWhichItem.h" #include @@ -134,17 +135,17 @@ ColorWhichItem::SetAttribute(color_which which) SetText("Window Tab"); break; } - case B_WINDOW_TAB_TEXT_COLOR: { + case B_WINDOW_TEXT_COLOR: { attribute=which; - SetText("Window Tab Text"); + SetText("Window Text"); break; } - case B_INACTIVE_WINDOW_TAB_COLOR: { + case B_WINDOW_INACTIVE_TAB_COLOR: { attribute=which; SetText("Inactive Window Tab"); break; } - case B_INACTIVE_WINDOW_TAB_TEXT_COLOR: { + case B_WINDOW_INACTIVE_TEXT_COLOR: { attribute=which; SetText("Inactive Window Tab Text"); break; diff --git a/src/preferences/appearance/ColorWhichItem.h b/src/preferences/appearance/ColorWhichItem.h index 6f776e51da..1c1f8942eb 100644 --- a/src/preferences/appearance/ColorWhichItem.h +++ b/src/preferences/appearance/ColorWhichItem.h @@ -1,9 +1,10 @@ /* - * Copyright 2001-2006, Haiku. + * Copyright 2001-2008, Haiku. * Distributed under the terms of the MIT License. * * Authors: * DarkWyrm + * Rene Gollent (rene@gollent.com) */ #ifndef COLORWHICH_ITEM_H #define COLORWHICH_ITEM_H @@ -11,30 +12,6 @@ #include #include -#define B_INACTIVE_WINDOW_TAB_TEXT_COLOR 'iwtt' -#define B_WINDOW_TAB_TEXT_COLOR 'wttx' -#define B_INACTIVE_WINDOW_TAB_COLOR 'iwtb' - -//#ifdef BUILD_UNDER_R5 - #define B_MENU_SELECTED_BACKGROUND_COLOR B_MENU_SELECTION_BACKGROUND_COLOR - #define B_PANEL_TEXT_COLOR 'ptxt' - #define B_DOCUMENT_BACKGROUND_COLOR 'dbgc' - #define B_DOCUMENT_TEXT_COLOR 'dtxc' - #define B_CONTROL_BACKGROUND_COLOR 'cbgc' - #define B_CONTROL_TEXT_COLOR 'ctxc' - #define B_CONTROL_BORDER_COLOR 'cboc' - #define B_CONTROL_HIGHLIGHT_COLOR 'chic' - #define B_NAVIGATION_BASE_COLOR 'navb' - #define B_NAVIGATION_PULSE_COLOR 'navp' - #define B_SHINE_COLOR 'shin' - #define B_SHADOW_COLOR 'shad' - #define B_MENU_SELECTED_BORDER_COLOR 'msbo' - #define B_TOOLTIP_BACKGROUND_COLOR 'ttbg' - #define B_TOOLTIP_TEXT_COLOR 'tttx' - #define B_SUCCESS_COLOR 'sucs' - #define B_FAILURE_COLOR 'fail' -//#endif - class ColorWhichItem : public BStringItem { public: