Author: kallisti5 Date: 2011-07-01 06:46:07 +0200 (Fri, 01 Jul 2011) New Revision: 42356 Changeset: https://dev.haiku-os.org/changeset/42356 Added: haiku/trunk/src/preferences/appearance/DecorSettingsView.cpp haiku/trunk/src/preferences/appearance/DecorSettingsView.h Removed: haiku/trunk/src/preferences/appearance/DecView.cpp haiku/trunk/src/preferences/appearance/DecView.h Modified: haiku/trunk/src/preferences/appearance/APRView.cpp haiku/trunk/src/preferences/appearance/APRView.h haiku/trunk/src/preferences/appearance/APRWindow.cpp haiku/trunk/src/preferences/appearance/APRWindow.h haiku/trunk/src/preferences/appearance/Jamfile Log: * Introduce a new tab to the Appearance Preflet for Decorator * Show Decorator information button * Decorator changes happen in real time on click * Remove *old* OpenBeOS Decerator selection code * Still have a little cleanup todo * Need to give a little focus on revert/default buttons * Decerator test / screenshots? Modified: haiku/trunk/src/preferences/appearance/APRView.cpp =================================================================== --- haiku/trunk/src/preferences/appearance/APRView.cpp 2011-07-01 02:40:16 UTC (rev 42355) +++ haiku/trunk/src/preferences/appearance/APRView.cpp 2011-07-01 04:46:07 UTC (rev 42356) @@ -23,8 +23,6 @@ #include <Path.h> #include <SpaceLayoutItem.h> -#include <DecorInfo.h> - #include "APRWindow.h" #include "defs.h" #include "ColorWell.h" @@ -41,10 +39,8 @@ APRView::APRView(const char* name, uint32 flags) : - BView(name, flags), - fDefaultSet(ColorSet::DefaultColorSet()), - fDecorMenu(NULL), - fDecorUtil(new DecorInfoUtility(false)) + BView(name, flags), + fDefaultSet(ColorSet::DefaultColorSet()) { SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR)); @@ -126,9 +122,6 @@ fAttrList->SetTarget(this); fColorWell->SetTarget(this); - if (fDecorMenu) - fDecorMenu->SetTargetForItems(BMessenger(this)); - LoadSettings(); fAttrList->Select(0); } @@ -148,15 +141,6 @@ } switch (msg->what) { - case DECORATOR_CHANGED: - { - int32 index = fDecorMenu->IndexOf(fDecorMenu->FindMarked()); - #ifdef HAIKU_TARGET_PLATFORM_HAIKU - if (index >= 0) - fDecorUtil->SetDecorator(index); - #endif - break; - } case UPDATE_COLOR: { // Received from the color fPicker when its color changes @@ -199,15 +183,6 @@ UpdateControls(); UpdateAllColors(); - if (fDecorMenu) { - BMenuItem *item = fDecorMenu->FindItem("Default"); - if (item) { - item->SetMarked(true); - #ifdef HAIKU_TARGET_PLATFORM_HAIKU - fDecorUtil->SetDecorator(fDecorMenu->IndexOf(item)); - #endif - } - } Window()->PostMessage(kMsgUpdate); break; } Modified: haiku/trunk/src/preferences/appearance/APRView.h =================================================================== --- haiku/trunk/src/preferences/appearance/APRView.h 2011-07-01 02:40:16 UTC (rev 42355) +++ haiku/trunk/src/preferences/appearance/APRView.h 2011-07-01 04:46:07 UTC (rev 42356) @@ -63,9 +63,6 @@ ColorSet fCurrentSet; ColorSet fPrevSet; ColorSet fDefaultSet; - - BMenu *fDecorMenu; - DecorInfoUtility*fDecorUtil; }; #endif Modified: haiku/trunk/src/preferences/appearance/APRWindow.cpp =================================================================== --- haiku/trunk/src/preferences/appearance/APRWindow.cpp 2011-07-01 02:40:16 UTC (rev 42355) +++ haiku/trunk/src/preferences/appearance/APRWindow.cpp 2011-07-01 04:46:07 UTC (rev 42356) @@ -1,10 +1,13 @@ /* - * Copyright 2002-2006, Haiku. All rights reserved. + * Copyright 2002-2011, Haiku. All rights reserved. * Distributed under the terms of the MIT License. * * Authors: * DarkWyrm (darkwyrm@xxxxxxxxxxxxx) + * Alexander von Gluck, kallisti5@xxxxxxxxxxx */ + + #include "APRWindow.h" #include <Button.h> @@ -18,16 +21,19 @@ #include "APRView.h" #include "defs.h" + #undef B_TRANSLATE_CONTEXT #define B_TRANSLATE_CONTEXT "APRWindow" + static const uint32 kMsgSetDefaults = 'dflt'; static const uint32 kMsgRevert = 'rvrt'; + APRWindow::APRWindow(BRect frame) : BWindow(frame, B_TRANSLATE_SYSTEM_NAME("Appearance"), B_TITLED_WINDOW, - B_NOT_ZOOMABLE | B_AUTO_UPDATE_SIZE_LIMITS, B_ALL_WORKSPACES) + B_NOT_ZOOMABLE | B_AUTO_UPDATE_SIZE_LIMITS, B_ALL_WORKSPACES) { SetLayout(new BGroupLayout(B_HORIZONTAL)); @@ -42,13 +48,19 @@ fAntialiasingSettings = new AntialiasingSettingsView( B_TRANSLATE("Antialiasing")); + + fDecorSettings = new DecorSettingsView( + B_TRANSLATE("Window Decorator")); + fColorsView = new APRView(B_TRANSLATE("Colors"), B_WILL_DRAW); tabView->AddTab(fColorsView); tabView->AddTab(fAntialiasingSettings); + tabView->AddTab(fDecorSettings); fDefaultsButton->SetEnabled(fColorsView->IsDefaultable() - || fAntialiasingSettings->IsDefaultable()); + || fAntialiasingSettings->IsDefaultable() + || fDecorSettings->IsDefaultable()); fRevertButton->SetEnabled(false); AddChild(BGroupLayoutBuilder(B_VERTICAL, 0) Modified: haiku/trunk/src/preferences/appearance/APRWindow.h =================================================================== --- haiku/trunk/src/preferences/appearance/APRWindow.h 2011-07-01 02:40:16 UTC (rev 42355) +++ haiku/trunk/src/preferences/appearance/APRWindow.h 2011-07-01 04:46:07 UTC (rev 42356) @@ -1,13 +1,15 @@ /* - * Copyright 2002-2006, Haiku. All rights reserved. + * Copyright 2002-2011, Haiku. All rights reserved. * Distributed under the terms of the MIT License. * * Authors: * DarkWyrm (darkwyrm@xxxxxxxxxxxxx) + * Alexander von Gluck, kallisti5@xxxxxxxxxxx */ #ifndef APR_WINDOW_H #define APR_WINDOW_H + #include <Application.h> #include <Button.h> #include <Window.h> @@ -16,23 +18,26 @@ #include "APRView.h" #include "AntialiasingSettingsView.h" +#include "DecorSettingsView.h" -class APRWindow : public BWindow + +class APRWindow : public BWindow { public: - APRWindow(BRect frame); - bool QuitRequested(void); - void MessageReceived(BMessage *message); - + APRWindow(BRect frame); + bool QuitRequested(void); + void MessageReceived(BMessage *message); + private: - APRView* fColorsView; - BButton* fDefaultsButton; - BButton* fRevertButton; + APRView* fColorsView; + BButton* fDefaultsButton; + BButton* fRevertButton; - AntialiasingSettingsView* fAntialiasingSettings; - + AntialiasingSettingsView* fAntialiasingSettings; + DecorSettingsView* fDecorSettings; }; static const int32 kMsgUpdate = 'updt'; + #endif Added: haiku/trunk/src/preferences/appearance/DecorSettingsView.cpp =================================================================== --- haiku/trunk/src/preferences/appearance/DecorSettingsView.cpp (rev 0) +++ haiku/trunk/src/preferences/appearance/DecorSettingsView.cpp 2011-07-01 04:46:07 UTC (rev 42356) @@ -0,0 +1,235 @@ +/* + * Copyright 2010-2011 Haiku, Inc. All rights reserved. + * Distributed under the terms of the MIT license. + * + * Authors: + * Alexander von Gluck, kallisti5@xxxxxxxxxxx + */ + + +#include "DecorSettingsView.h" + +#include <stdio.h> +#include <stdlib.h> + +#include <Alert.h> +#include <Box.h> +#include <Catalog.h> +#include <GridLayoutBuilder.h> +#include <GroupLayoutBuilder.h> +#include <Locale.h> +#include <MenuField.h> +#include <MenuItem.h> +#include <PopUpMenu.h> +#include <Slider.h> +#include <SpaceLayoutItem.h> +#include <String.h> +#include <TextView.h> + +#include "APRWindow.h" + + +#undef B_TRANSLATE_CONTEXT +#define B_TRANSLATE_CONTEXT "DecorSettingsView" + + +static const int32 kMsgSetDecor = 'deco'; +static const int32 kMsgDecorInfo = 'idec'; + + +// #pragma mark - + + +DecorSettingsView::DecorSettingsView(const char* name) + : + BView(name, 0) +{ + // Decorator menu + _BuildDecorMenu(); + fDecorMenuField = new BMenuField("decorator", + B_TRANSLATE("Window Decorator:"), fDecorMenu); + + fDecorInfoButton = new BButton(B_TRANSLATE("About"), + new BMessage(kMsgDecorInfo)); + + SetLayout(new BGroupLayout(B_VERTICAL)); + + // control layout + AddChild(BGridLayoutBuilder(10, 10) + .Add(fDecorMenuField->CreateLabelLayoutItem(), 0, 0) + .Add(fDecorMenuField->CreateMenuBarLayoutItem(), 1, 0) + .Add(fDecorInfoButton, 2, 0) + + .Add(BSpaceLayoutItem::CreateGlue(), 0, 3, 2) + .SetInsets(10, 10, 10, 10) + ); + // TODO : Decorator Preview Image? +} + + +DecorSettingsView::~DecorSettingsView() +{ +} + + +void +DecorSettingsView::AttachedToWindow() +{ + if (Parent() != NULL) + SetViewColor(Parent()->ViewColor()); + else + SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR)); + + fDecorMenu->SetTargetForItems(this); + fDecorInfoButton->SetTarget(this); +} + + +void +DecorSettingsView::MessageReceived(BMessage *msg) +{ + switch (msg->what) { + case kMsgSetDecor: + { + BString newDecor; + if (msg->FindString("decor", &newDecor) != B_OK) + break; + + DecorInfoUtility* decorUtility = new DecorInfoUtility(); + if (decorUtility == NULL) + return; + + DecorInfo* decor = decorUtility->FindDecorator(newDecor); + if (decor == NULL) + return; + + fSavedDecor = fCurrentDecor; + fCurrentDecor = (char*)decor->Name().String(); + + decorUtility->SetDecorator(decor); + + Window()->PostMessage(kMsgUpdate); + break; + } + case kMsgDecorInfo: + { + DecorInfoUtility* decorUtility = new DecorInfoUtility(); + if (decorUtility == NULL) + return; + + BString decoratorName(fCurrentDecor); + DecorInfo* decor = decorUtility->FindDecorator(decoratorName); + if (decor == NULL) + return; + + BString authorsText(decor->Authors().String()); + authorsText.ReplaceAll(", ", "\n "); + + BString infoText("Name: %decorName\n" + "Authors:\n %decorAuthors\n" + "URL: %decorURL\n" + "License: %decorLic\n" + "Description:\n %decorDesc\n"); + + infoText.ReplaceFirst("%decorName", decor->Name().String()); + infoText.ReplaceFirst("%decorAuthors", authorsText.String()); + infoText.ReplaceFirst("%decorLic", decor->LicenseName().String()); + infoText.ReplaceFirst("%decorURL", decor->SupportURL().String()); + infoText.ReplaceFirst("%decorDesc", decor->ShortDescription().String()); + + BAlert *infoAlert = new BAlert(B_TRANSLATE("About Decerator"), + infoText.String(), B_TRANSLATE("OK")); + infoAlert->SetShortcut(0, B_ESCAPE); + infoAlert->Go(); + + Window()->PostMessage(kMsgUpdate); + break; + } + default: + BView::MessageReceived(msg); + } +} + + +void +DecorSettingsView::_BuildDecorMenu() +{ + fDecorMenu = new BPopUpMenu(B_TRANSLATE("Choose Decorator")); + DecorInfo* decorator = NULL; + + // collect the current system decor settings + DecorInfoUtility* decorUtility = new DecorInfoUtility(); + + if (decorUtility == NULL) { + return; + } + + int32 count = decorUtility->CountDecorators(); + for (int32 i = 0; i < count; ++i) { + decorator = decorUtility->DecoratorAt(i); + if (decorator == NULL) { + fprintf(stderr, "Decorator : error NULL entry @ %li / %li\n", + i, count); + } + + BString decorName = decorator->Name(); + + if (decorUtility->CurrentDecorator() == decorator) + fCurrentDecor = (char*)decorName.String(); + + BMessage* message = new BMessage(kMsgSetDecor); + message->AddString("decor", decorator->Name()); + + BMenuItem* item + = new BMenuItem(decorator->Name(), message); + + fDecorMenu->AddItem(item); + } + + _SetCurrentDecor(); +} + + +void +DecorSettingsView::_SetCurrentDecor() +{ + BMenuItem *item = fDecorMenu->FindItem(fCurrentDecor); + BString currDecor = fCurrentDecor; + if (item != NULL) + item->SetMarked(true); +} + + +void +DecorSettingsView::SetDefaults() +{ + DecorInfoUtility* decorUtility = new DecorInfoUtility(); + if (decorUtility == NULL) + return; + DecorInfo* defaultDecorator(decorUtility->DefaultDecorator()); + decorUtility->SetDecorator(defaultDecorator); + _BuildDecorMenu(); +} + + +bool +DecorSettingsView::IsDefaultable() +{ + return true; +} + + +bool +DecorSettingsView::IsRevertable() +{ + return fCurrentDecor != fSavedDecor; +} + + +void +DecorSettingsView::Revert() +{ + if (!IsRevertable()) + return; +} + Added: haiku/trunk/src/preferences/appearance/DecorSettingsView.h =================================================================== --- haiku/trunk/src/preferences/appearance/DecorSettingsView.h (rev 0) +++ haiku/trunk/src/preferences/appearance/DecorSettingsView.h 2011-07-01 04:46:07 UTC (rev 42356) @@ -0,0 +1,54 @@ +/* + * Copyright 2010-2011 Haiku, Inc. All rights reserved. + * Distributed under the terms of the MIT license. + * + * Authors: + * Alexander von Gluck, kallisti5@xxxxxxxxxxx + */ +#ifndef DECOR_SETTINGS_VIEW_H +#define DECOR_SETTINGS_VIEW_H + + +#include <Button.h> +#include <GroupView.h> +#include <InterfaceDefs.h> +#include <View.h> + +#include <DecorInfo.h> + + +class BBox; +class BMenuField; +class BPopUpMenu; + + +class DecorSettingsView : public BView { +public: + DecorSettingsView(const char* name); + virtual ~DecorSettingsView(); + + virtual void AttachedToWindow(); + virtual void MessageReceived(BMessage* message); + + void SetDefaults(); + void Revert(); + bool IsDefaultable(); + bool IsRevertable(); + +private: + void _BuildDecorMenu(); + void _SetCurrentDecor(); + + BButton* fDecorInfoButton; + +protected: + float fDivider; + + BMenuField* fDecorMenuField; + BPopUpMenu* fDecorMenu; + + char* fSavedDecor; + char* fCurrentDecor; +}; + +#endif // DECOR_SETTINGS_VIEW_H Modified: haiku/trunk/src/preferences/appearance/Jamfile =================================================================== --- haiku/trunk/src/preferences/appearance/Jamfile 2011-07-01 02:40:16 UTC (rev 42355) +++ haiku/trunk/src/preferences/appearance/Jamfile 2011-07-01 04:46:07 UTC (rev 42356) @@ -6,6 +6,7 @@ Preference Appearance : APRMain.cpp AntialiasingSettingsView.cpp + DecorSettingsView.cpp APRView.cpp APRWindow.cpp ColorSet.cpp @@ -15,14 +16,13 @@ # These are currently disabled while everything else is being worked on #CurView.cpp #CursorWhichItem.cpp - #DecView.cpp #SysCursorAPI.cpp # These exist for post-R1, so they are disabled for now #FontMenu.cpp #MenuView.cpp - : be $(TARGET_LIBSTDC++) $(HAIKU_LOCALE_LIBS) + : be $(TARGET_LIBSTDC++) $(TARGET_LIBSUPC++) $(HAIKU_LOCALE_LIBS) : Appearance.rdef ; @@ -30,6 +30,7 @@ x-vnd.Haiku-Appearance : AntialiasingSettingsView.cpp + DecorSettingsView.cpp APRView.cpp APRWindow.cpp ColorSet.cpp