[haiku-commits] BRANCH looncraz-github.setviewuicolor [1b38b2e15e61] src/kits/interface headers/os/interface src/servers/app headers/private/interface src

  • From: looncraz-github.setviewuicolor <community@xxxxxxxxxxxx>
  • To: haiku-commits@xxxxxxxxxxxxx
  • Date: Mon, 19 Oct 2015 04:32:06 +0200 (CEST)

added 2 changesets to branch 'refs/remotes/looncraz-github/setviewuicolor'
old head: 9ba036ea48a797987aaa3e9a380a78100e67edae
new head: 1b38b2e15e616122fd673db53af72a33f26b7f81
overview: https://github.com/looncraz/haiku/compare/9ba036ea48a7...1b38b2e15e61

----------------------------------------------------------------------------

394466ade5e0: Redefine constant, update comment

Redefine kColorWhichCount to be relative to the newly defined
kColorWhichLastContinuous (useful for iteration).

Update comments to reflect change.

1b38b2e15e61: BColorSet to BColorMap

More than a skin-deep rename and API shakeup.

Spent some time making it such that its transmittal format and its
storage format were identical, so the data could be directly copied.
Which is to say, I just used a BMessage.

In addition, I enabled "stealing" the data from a BColorMap so that
you would not need to copy it, but merely share its pointer within the
app_server. The object's reference count is incremented by the number
of recipients (windows) and decremented after being sent to the client.
It will self-destruct when there are no more references... though there
is a chance this will not happen if a delayed message failure occurs,
such as when a window is destroyed, so I have to make a special case
to handle that (rare) scenario.

When the message is received by the client window, a BColorMap object
is created purely by copying the BMessage, and its data is then shared
with no further copies to all BViews attached to the window.

The end result is that usage is simple and very fast, and we gain some
flexibility in naming and hiding the implementation details in the
public API (i.e. you have no idea how it's done unless you read this).

Colors can be assigned by int32, color_which, or a BString key.

[ looncraz <looncraz@xxxxxxxxxxxx> ]

----------------------------------------------------------------------------

25 files changed, 1136 insertions(+), 999 deletions(-)
headers/os/interface/ColorMap.h | 94 +++
headers/os/interface/ColorSet.h | 99 ---
headers/os/interface/View.h | 4 +-
headers/private/app/ServerReadOnlyMemory.h | 9 +-
headers/private/interface/ColorMapPrivate.h | 80 ++
headers/private/interface/ColorSetPrivate.h | 42 -
src/apps/aboutsystem/AboutSystem.cpp | 6 +-
src/apps/deskcalc/CalcView.cpp | 9 +-
src/apps/mediaplayer/interface/DurationView.cpp | 7 +-
src/apps/overlayimage/OverlayView.cpp | 10 +-
src/kits/interface/ColorMap.cpp | 843 +++++++++++++++++++
src/kits/interface/ColorSet.cpp | 721 ----------------
src/kits/interface/Jamfile | 2 +-
src/kits/interface/StatusBar.cpp | 11 +-
src/kits/interface/TextControl.cpp | 22 +-
src/kits/interface/View.cpp | 38 +-
src/kits/interface/Window.cpp | 17 +-
.../appearance/AntialiasingSettingsView.cpp | 5 +-
.../datatranslations/DataTranslationsWindow.cpp | 10 +-
src/servers/app/Desktop.cpp | 8 +-
src/servers/app/Desktop.h | 4 +-
src/servers/app/DesktopSettings.cpp | 54 +-
src/servers/app/DesktopSettings.h | 5 +-
src/servers/app/DesktopSettingsPrivate.h | 2 +-
src/servers/app/ServerWindow.cpp | 33 +-

############################################################################

Commit: 394466ade5e0196479a7aa6ca64b0b7aff6e178b
Author: looncraz <looncraz@xxxxxxxxxxxx>
Date: Thu Oct 15 14:08:49 2015 UTC

Redefine constant, update comment

Redefine kColorWhichCount to be relative to the newly defined
kColorWhichLastContinuous (useful for iteration).

Update comments to reflect change.

----------------------------------------------------------------------------

diff --git a/headers/private/app/ServerReadOnlyMemory.h
b/headers/private/app/ServerReadOnlyMemory.h
index 8344b70..f62e3c0 100644
--- a/headers/private/app/ServerReadOnlyMemory.h
+++ b/headers/private/app/ServerReadOnlyMemory.h
@@ -13,12 +13,11 @@
#include <InterfaceDefs.h>


-// Update this constant with 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.
-static const int32 kColorWhichCount = B_LINK_ACTIVE_COLOR + 3;
+// Update kColorWhichLastContinuous with the largest color constant which
+// leaves no gaps in the color_which integer values.
static const int32 kColorWhichLastContinuous = B_LINK_ACTIVE_COLOR;
+static const int32 kColorWhichCount = kColorWhichLastContinuous + 3;
+ // + 1 for index-offset, + 2 for B_SUCCESS_COLOR, B_FAILURE_COLOR


struct server_read_only_memory {

############################################################################

Commit: 1b38b2e15e616122fd673db53af72a33f26b7f81
Author: looncraz <looncraz@xxxxxxxxxxxx>
Date: Mon Oct 19 03:24:16 2015 UTC

BColorSet to BColorMap

More than a skin-deep rename and API shakeup.

Spent some time making it such that its transmittal format and its
storage format were identical, so the data could be directly copied.
Which is to say, I just used a BMessage.

In addition, I enabled "stealing" the data from a BColorMap so that
you would not need to copy it, but merely share its pointer within the
app_server. The object's reference count is incremented by the number
of recipients (windows) and decremented after being sent to the client.
It will self-destruct when there are no more references... though there
is a chance this will not happen if a delayed message failure occurs,
such as when a window is destroyed, so I have to make a special case
to handle that (rare) scenario.

When the message is received by the client window, a BColorMap object
is created purely by copying the BMessage, and its data is then shared
with no further copies to all BViews attached to the window.

The end result is that usage is simple and very fast, and we gain some
flexibility in naming and hiding the implementation details in the
public API (i.e. you have no idea how it's done unless you read this).

Colors can be assigned by int32, color_which, or a BString key.

----------------------------------------------------------------------------

diff --git a/headers/os/interface/ColorMap.h b/headers/os/interface/ColorMap.h
new file mode 100644
index 0000000..a2e70b2
--- /dev/null
+++ b/headers/os/interface/ColorMap.h
@@ -0,0 +1,94 @@
+/*
+ * Copyright 2015 Haiku, Inc. All rights reserved.
+ * Distributed under the terms of the MIT License.
+ */
+#ifndef _B_COLOR_MAP
+#define _B_COLOR_MAP
+
+
+#include <Archivable.h>
+#include <InterfaceDefs.h>
+
+
+namespace BPrivate {
+ class BColorMapData;
+ class BColorMapPrivate;
+};
+
+
+class BColorMap : public BArchivable {
+public:
+ BColorMap();
+ BColorMap(const
BColorMap& other);
+
BColorMap(BMessage* from);
+ virtual ~BColorMap();
+
+ virtual status_t Archive(BMessage* into, bool
deep = true) const;
+ static BArchivable* Instantiate(BMessage* archive);
+
+ // Static methods
+
+ static const BColorMap* DefaultColorMap();
+ static const BColorMap* CurrentColorMap();
+ static status_t Get(const BMessage* message,
int32 key,
+
rgb_color* color = NULL);
+ static status_t Get(const BMessage* message,
color_which which,
+
rgb_color* color = NULL);
+ static status_t Get(const BMessage* message,
+ const
BString& key,
+
rgb_color* color = NULL);
+
+ // Adding and removing colors.
+ // Will fail if key currently in use
+ status_t Add(int32 key,
rgb_color color);
+ status_t Add(color_which which,
rgb_color color);
+ status_t Add(const BString& key,
rgb_color color);
+ status_t Add(const BColorMap&
ColorMap);
+
+ // Will add if key not in use
+ status_t Set(int32 key,
rgb_color color);
+ status_t Set(color_which which,
rgb_color color);
+ status_t Set(const BString& key,
rgb_color color);
+ status_t Set(const BColorMap&
ColorMap);
+
+ status_t Remove(int32 key);
+ status_t Remove(color_which
which);
+ status_t Remove(const BString&
key);
+ status_t Remove(const BColorMap&
ColorMap);
+
+ void MakeEmpty();
+
+ // Retrieve colors
+ status_t Get(int32 key,
rgb_color* color) const;
+ status_t Get(color_which which,
rgb_color* color) const;
+ status_t Get(const BString& key,
rgb_color* color) const;
+
+ status_t GetNext(int32* index,
BString* key,
+
rgb_color* color);
+ // Query
+ bool HasColor(int32 key)
const;
+ bool HasColor(color_which
which) const;
+ bool HasColor(const BString&
key) const;
+
+ status_t InitCheck() const;
+ int32 CountColors() const;
+ bool IsEmpty() const;
+
+ void PrintToStream() const;
+
+private:
+ friend class BPrivate::BColorMapPrivate;
+
+ bool _GetDataAt(int32 index,
BString* key,
+ int32*
data) const;
+ void _Init(BMessage* from);
+ status_t _InitCopyOnWrite();
+
+ typedef BPrivate::BColorMapData* ColorMap;
+ ColorMap fData;
+
+ status_t fInitStatus;
+};
+
+
+#endif // _B_COLOR_MAP
diff --git a/headers/os/interface/ColorSet.h b/headers/os/interface/ColorSet.h
deleted file mode 100644
index 3ba90c2..0000000
--- a/headers/os/interface/ColorSet.h
+++ /dev/null
@@ -1,99 +0,0 @@
-/*
- * Copyright 2015 Haiku, Inc. All rights reserved.
- * Distributed under the terms of the MIT License.
- */
-#ifndef _B_COLOR_SET
-#define _B_COLOR_SET
-
-
-#include <Archivable.h>
-#include <InterfaceDefs.h>
-
-
-namespace BPrivate {
- class BColorSetData;
- class BColorSetPrivate;
-};
-
-
-struct BColorPair {
- int32 key;
- rgb_color color;
-};
-
-
-class BColorSet : public BArchivable {
-public:
- BColorSet();
- BColorSet(const
BColorSet& other);
-
BColorSet(BMessage* from);
- virtual ~BColorSet();
-
- virtual status_t Archive(BMessage* into, bool
deep = true) const;
- static BArchivable* Instantiate(BMessage* archive);
-
- // Static methods
-
- static const BColorSet* DefaultColorSet();
- static const BColorSet* CurrentColorSet();
- static status_t Get(const BMessage* message,
int32 key,
-
rgb_color* color);
- static status_t Get(const BMessage* message,
color_which which,
-
rgb_color* color);
-
- // Adding and removing colors.
- // Will fail if key currently in use
- status_t Add(const BColorPair*
pair);
- status_t Add(int32 key,
rgb_color color);
- status_t Add(color_which which,
rgb_color color);
- status_t Add(const BColorSet&
colorSet);
-
- // Will add if key not in use
- status_t Set(const BColorPair*
pair);
- status_t Set(int32 key,
rgb_color color);
- status_t Set(color_which which,
rgb_color color);
- status_t Set(const BColorSet&
colorSet);
-
- status_t RemoveAt(int32 index);
- status_t Remove(const
BColorPair* pair);
- status_t Remove(int32 key);
- status_t Remove(color_which
which);
- status_t Remove(const BColorSet&
colorSet);
-
- void MakeEmpty();
-
- // Retrieve colors
- rgb_color ColorAt(int32 index)
const;
- int32 ColorKeyAt(int32 index)
const;
- const BColorPair* ColorPairAt(int32 index) const;
- BColorPair* ColorPairAt(int32
index);
-
- const BColorPair* Find(int32 key) const;
- BColorPair* Find(int32 key);
- const BColorPair* Find(color_which which) const;
- BColorPair* Find(color_which which);
-
- // Query
- status_t InitCheck() const;
- bool HasKey(int32 key) const;
- int32 CountColors() const;
- bool IsEmpty() const;
-
- void PrintToStream() const;
-
-private:
- friend class BPrivate::BColorSetPrivate;
-
- status_t _Add(BColorPair* pair);
- void _Init(BMessage* from);
- status_t _InitCopyOnWrite();
-
- typedef BPrivate::BColorSetData* ColorList;
- ColorList fColors;
- bool fSharedData;
-
- status_t fInitStatus;
-};
-
-
-#endif // _B_COLOR_SET
diff --git a/headers/os/interface/View.h b/headers/os/interface/View.h
index 7b94ff0..733fef0 100644
--- a/headers/os/interface/View.h
+++ b/headers/os/interface/View.h
@@ -109,7 +109,7 @@ inline uint32 _rule_(uint32 r1, uint32 r2, uint32 r3,
uint32 r4)


class BBitmap;
-class BColorSet;
+class BColorMap;
class BCursor;
class BLayout;
class BLayoutContext;
@@ -692,7 +692,7 @@ private:
void _Activate(bool state);
void _Attach();
void
_ColorsUpdated(BMessage* message,
- const
BColorSet& colorSet);
+ const
BColorMap& colorSet);
void _Detach();
void _Draw(BRect
screenUpdateRect);
void
_DrawAfterChildren(BRect screenUpdateRect);
diff --git a/headers/private/interface/ColorMapPrivate.h
b/headers/private/interface/ColorMapPrivate.h
new file mode 100644
index 0000000..090b7ca
--- /dev/null
+++ b/headers/private/interface/ColorMapPrivate.h
@@ -0,0 +1,80 @@
+/*
+ * Copyright 2015, Haiku.
+ * Distributed under the terms of the MIT License.
+*/
+#ifndef _B_COLORMAP_PRIVATE_H_
+#define _B_COLORMAP_PRIVATE_H_
+
+
+#include <ColorMap.h>
+#include <Locker.h>
+#include <Message.h>
+#include <Referenceable.h>
+
+
+namespace BPrivate {
+
+
+//! Shared data for BColorMap
+class BColorMapData : public BReferenceable, public BMessage, public BLocker {
+public:
+ BColorMapData();
+
BColorMapData(BMessage* from);
+
BColorMapData(const BColorMapData& other);
+ virtual ~BColorMapData();
+
+ status_t Add(const BString& key,
rgb_color color);
+ status_t Add(const BString& key,
int32 color);
+ void Remove(const BString&
key);
+ void RemoveAll();
+
+ status_t Send(port_id port,
team_id team, int32 token,
+
bigtime_t timeout = 25000);
+
+ // iteration interface for app_server use
+ status_t GetNext(int32* cookie,
color_which* key,
+
rgb_color* color);
+
+ void SetShared(bool shared);
+ bool IsShared() const;
+private:
+ bool fIsShared;
+};
+
+
+//! Data acquisition modes
+enum {
+ B_CM_SHARE_DATA = 0,// Default - just acquire a reference
+ // Copies are made if modifications are made to maps which share
+ // data, however a copy is NOT made if the original is modified,
+ // those changes will propagate.
+
+ B_CM_STEAL_DATA = 1,// Take the data, and reset the colormap
+ // The given color map will get a new, clean, data object, and
+ // the caller will take ownership of the acquired data.
+
+ B_CM_COPY_DATA = 2 // Copy the data, release to destroy
copy
+};
+
+
+//! Provide direct read-only access to private BColorMap data
+class BColorMapPrivate {
+public:
+ static BColorMapData* AcquireData(BColorMap& colorMap,
+ int32
count = 1,
+ uint32
mode = B_CM_SHARE_DATA);
+ static void
ReleaseData(BColorMapData* data,
+ int32
count = 1,
+ bool
ensureDestruction = false);
+
+ static bool AcquireSharedPointer(BColorMap*
pointer,
+
BMessage* message);
+
+ static void ReleaseSharedPointer(BMessage*
message);
+};
+
+
+}; // end namespace BPrivate
+
+
+#endif //_B_COLORMAP_PRIVATE_H_
diff --git a/headers/private/interface/ColorSetPrivate.h
b/headers/private/interface/ColorSetPrivate.h
deleted file mode 100644
index 674154e..0000000
--- a/headers/private/interface/ColorSetPrivate.h
+++ /dev/null
@@ -1,42 +0,0 @@
-/*
- * Copyright 2015, Haiku.
- * Distributed under the terms of the MIT License.
-*/
-#ifndef _B_COLORSET_PRIVATE_H_
-#define _B_COLORSET_PRIVATE_H_
-
-
-#include <ColorSet.h>
-#include <ObjectList.h>
-#include <Referenceable.h>
-
-
-namespace BPrivate {
-
-
-//! Shared data for BColorSet
-class BColorSetData : public BReferenceable, public BObjectList<BColorPair> {
-public:
- BColorSetData();
-
BColorSetData(const BColorSetData& other);
- virtual ~BColorSetData();
-
-};
-
-
-//! Provide direct read-only access to private BColorSet data
-class BColorSetPrivate {
-public:
- static const BObjectList<BColorPair>& GetList(const BColorSet&
colorSet);
-
- static bool AcquireSharedPointer(BColorSet*
pointer,
-
BMessage* message);
-
- static void ReleaseSharedPointer(BMessage*
message);
-};
-
-
-}; // end namespace BPrivate
-
-
-#endif //_B_COLORSET_PRIVATE_H_
diff --git a/src/apps/aboutsystem/AboutSystem.cpp
b/src/apps/aboutsystem/AboutSystem.cpp
index a6b03f3..26f8d77 100644
--- a/src/apps/aboutsystem/AboutSystem.cpp
+++ b/src/apps/aboutsystem/AboutSystem.cpp
@@ -22,7 +22,7 @@
#include <AppFileInfo.h>
#include <Application.h>
#include <Bitmap.h>
-#include <ColorSet.h>
+#include <ColorMap.h>
#include <DateTimeFormat.h>
#include <DurationFormat.h>
#include <File.h>
@@ -671,9 +671,9 @@ AboutView::MessageReceived(BMessage* msg)
switch (msg->what) {
case B_COLORS_UPDATED:
{
- BColorSet colorSet(msg);
- if (colorSet.Find(B_PANEL_TEXT_COLOR) != NULL)
+ if (BColorMap::Get(msg, B_PANEL_TEXT_COLOR) == B_OK)
_AdjustTextColors();
+
break;
}
case SCROLL_CREDITS_VIEW:
diff --git a/src/apps/deskcalc/CalcView.cpp b/src/apps/deskcalc/CalcView.cpp
index ad1933c..4e2b33a 100644
--- a/src/apps/deskcalc/CalcView.cpp
+++ b/src/apps/deskcalc/CalcView.cpp
@@ -26,7 +26,7 @@
#include <Beep.h>
#include <Bitmap.h>
#include <Catalog.h>
-#include <ColorSet.h>
+#include <ColorMap.h>
#include <ControlLook.h>
#include <Clipboard.h>
#include <File.h>
@@ -232,10 +232,9 @@ CalcView::AttachedToWindow()
void
CalcView::MessageReceived(BMessage* message)
{
- if (message->what == B_COLORS_UPDATED) {
- BColorSet colorSet(message);
- if (colorSet.Find(B_PANEL_BACKGROUND_COLOR) != NULL)
- _Colorize();
+ if (message->what == B_COLORS_UPDATED
+ && BColorMap::Get(message, B_PANEL_BACKGROUND_COLOR) == B_OK) {
+ _Colorize();
return;
}

diff --git a/src/apps/mediaplayer/interface/DurationView.cpp
b/src/apps/mediaplayer/interface/DurationView.cpp
index b9f81aa..b2644c6 100644
--- a/src/apps/mediaplayer/interface/DurationView.cpp
+++ b/src/apps/mediaplayer/interface/DurationView.cpp
@@ -6,7 +6,7 @@

#include "DurationView.h"

-#include <ColorSet.h>
+#include <ColorMap.h>
#include <LayoutUtils.h>

#include "DurationToString.h"
@@ -51,9 +51,8 @@ void
DurationView::MessageReceived(BMessage* message)
{
if (message->what == B_COLORS_UPDATED) {
- BColorSet colorSet(message);
- if (colorSet.Find(B_PANEL_BACKGROUND_COLOR) != NULL
- || colorSet.Find(B_PANEL_TEXT_COLOR) != NULL)
+ if (BColorMap::Get(message, B_PANEL_BACKGROUND_COLOR) == B_OK
+ || BColorMap::Get(message, B_PANEL_TEXT_COLOR) == B_OK)
_UpdateTextColor();
}

diff --git a/src/apps/overlayimage/OverlayView.cpp
b/src/apps/overlayimage/OverlayView.cpp
index e5dd01d..be09d7b 100644
--- a/src/apps/overlayimage/OverlayView.cpp
+++ b/src/apps/overlayimage/OverlayView.cpp
@@ -14,7 +14,7 @@
#include "OverlayView.h"

#include <Catalog.h>
-#include <ColorSet.h>
+#include <ColorMap.h>
#include <InterfaceDefs.h>
#include <Locale.h>
#include <String.h>
@@ -122,13 +122,11 @@ OverlayView::MessageReceived(BMessage *msg)
break;
case B_COLORS_UPDATED:
{
- BColorSet colorSet(msg);
- BColorPair* pair = colorSet.Find(B_PANEL_TEXT_COLOR);
-
- if (pair == NULL)
+ rgb_color color;
+ if (BColorMap::Get(msg, B_PANEL_TEXT_COLOR, &color) !=
B_OK)
break;

- fText->SetFontAndColor(be_plain_font, B_FONT_ALL,
&pair->color);
+ fText->SetFontAndColor(be_plain_font, B_FONT_ALL,
&color);
break;
}
default:
diff --git a/src/kits/interface/ColorMap.cpp b/src/kits/interface/ColorMap.cpp
new file mode 100644
index 0000000..3006053
--- /dev/null
+++ b/src/kits/interface/ColorMap.cpp
@@ -0,0 +1,843 @@
+/*
+ * Copyright 2015, Haiku.
+ * Distributed under the terms of the MIT License.
+ *
+ * Authors:
+ * Joseph Groover <looncraz@xxxxxxxxxxxx>
+*/
+#include <stdio.h>
+#include <stdlib.h>
+
+#include <Application.h>
+#include <Autolock.h>
+#include <ColorMap.h>
+#include <Locker.h>
+#include <StringList.h>
+
+#include <ColorMapPrivate.h>
+#include <DefaultColors.h>
+#include <MessagePrivate.h>
+#include <ServerReadOnlyMemory.h>
+
+
+// helpful macros
+#define CHECK_READ_STATUS(X) if (InitCheck() != B_OK) return X ;
+#define CHECK_WRITE_STATUS(X) if (_InitCopyOnWrite() != B_OK) return X ;
+
+
+// not extern'd
+static BLocker be_global_colormap_lock;
+static BColorMap* be_default_colormap = NULL;
+static BColorMap* be_current_colormap = NULL;
+
+
+static const char* kColorMapPointerName = "_be_colormap_pointer_";
+static const rgb_color kFailureColor = make_color(0,0,0,0);
+
+
+BColorMap::BColorMap()
+ :
+ fData(NULL),
+ fInitStatus(B_OK)
+{
+ _Init(NULL);
+}
+
+
+BColorMap::BColorMap(const BColorMap& other)
+ :
+ fData(other.fData),
+ fInitStatus(B_OK)
+{
+ if (fData != NULL) {
+ fData->AcquireReference();
+ fData->SetShared(true);
+ } else
+ fInitStatus = B_BAD_VALUE;
+}
+
+
+BColorMap::BColorMap(BMessage* from)
+ :
+ fData(NULL),
+ fInitStatus(B_OK)
+{
+ _Init(from);
+}
+
+
+BColorMap::~BColorMap()
+{
+ BAutolock _(be_global_colormap_lock);
+ if (this == be_current_colormap)
+ be_current_colormap = NULL;
+ else if (this == be_default_colormap)
+ be_default_colormap = NULL;
+
+ // fData will delete itself when not used
+ if (fData != NULL)
+ fData->ReleaseReference();
+}
+
+
+// #pragma mark Archiving
+
+
+status_t
+BColorMap::Archive(BMessage* into, bool deep) const
+{
+ CHECK_READ_STATUS(fInitStatus);
+
+ if (into == NULL)
+ return B_BAD_VALUE;
+
+ return into->AddMessage("be:colormap", fData);
+}
+
+
+BArchivable*
+BColorMap::Instantiate(BMessage* archive)
+{
+ return new(std::nothrow) BColorMap(archive);
+}
+
+
+// #pragma mark Static
+
+
+const BColorMap*
+BColorMap::DefaultColorMap()
+{
+ BAutolock _(be_global_colormap_lock);
+
+ if (be_default_colormap != NULL)
+ return be_default_colormap;
+
+ be_default_colormap = new(std::nothrow) BColorMap();
+ if (be_default_colormap == NULL) {
+ fprintf(stderr, "no memory!\n");
+ return NULL;
+ }
+
+ for (int32 which = 1; which < kColorWhichLastContinuous + 1; ++which) {
+ be_default_colormap->Add(which, BPrivate::kDefaultColors[
+ color_which_to_index((color_which)which)]);
+ }
+
+ be_default_colormap->Add((int32)B_SUCCESS_COLOR,
+
BPrivate::kDefaultColors[color_which_to_index(B_SUCCESS_COLOR)]);
+ be_default_colormap->Add((int32)B_FAILURE_COLOR,
+
BPrivate::kDefaultColors[color_which_to_index(B_FAILURE_COLOR)]);
+
+ return be_default_colormap;
+}
+
+
+const BColorMap*
+BColorMap::CurrentColorMap()
+{
+ if (be_app == NULL) {
+ printf("BApplication object required to get current color
set!\n");
+ return DefaultColorMap();
+ }
+
+ BAutolock _(be_global_colormap_lock);
+
+ if (be_current_colormap != NULL)
+ return be_current_colormap;
+
+ be_current_colormap = new(std::nothrow) BColorMap();
+ if (be_current_colormap == NULL) {
+ fprintf(stderr, "no memory!\n");
+ return NULL;
+ }
+
+ for (int32 which = 1; which < kColorWhichLastContinuous + 1; ++which)
+ be_current_colormap->Add(which, ui_color((color_which)which));
+
+ be_current_colormap->Add((int32)B_SUCCESS_COLOR,
+ ui_color(B_SUCCESS_COLOR));
+ be_current_colormap->Add((int32)B_FAILURE_COLOR,
+ ui_color(B_FAILURE_COLOR));
+
+ return be_current_colormap;
+}
+
+
+status_t
+BColorMap::Get(const BMessage* message, int32 key, rgb_color* color)
+{
+ BString name;
+ name << key;
+ return BColorMap::Get(message, name, color);
+}
+
+
+status_t
+BColorMap::Get(const BMessage* message, color_which which, rgb_color* color)
+{
+ return BColorMap::Get(message, (int32)which, color);
+}
+
+
+status_t
+BColorMap::Get(const BMessage* message, const BString& key, rgb_color* color)
+{
+ if (message == NULL)
+ return B_BAD_VALUE;
+
+ int32 intColor = 0;
+ status_t error = message->FindInt32(key, &intColor);
+
+ if (error == B_OK && color != NULL) {
+ intColor = B_HOST_TO_BENDIAN_INT32(intColor);
+ *color = *(rgb_color*)&intColor;
+ }
+
+ return error;
+}
+
+
+// #pragma mark Add
+
+
+status_t
+BColorMap::Add(int32 key, rgb_color color)
+{
+ BString name;
+ name << key;
+ return Add(name, color);
+}
+
+
+status_t
+BColorMap::Add(color_which which, rgb_color color)
+{
+ return Add((int32)which, color);
+}
+
+
+status_t
+BColorMap::Add(const BString& key, rgb_color color)
+{
+ CHECK_WRITE_STATUS(fInitStatus);
+ BAutolock _(fData);
+
+ if (HasColor(key))
+ return B_BAD_INDEX;
+
+ return fData->Add(key, color);
+}
+
+
+int32
+BColorMap::Add(const BColorMap& colorMap)
+{
+ CHECK_WRITE_STATUS(fInitStatus);
+ BAutolock _(fData);
+
+ // Technically not an error
+ if (colorMap.CountColors() == 0)
+ return B_OK;
+
+ status_t error = B_OK;
+ BString key;
+ int32 color = 0;
+
+ for (int32 index = 0; index < colorMap.CountColors(); ++index) {
+ if (!colorMap._GetDataAt(index, &key, &color))
+ return B_BAD_DATA;
+
+ error = fData->Add(key, color);
+ if (error != B_OK)
+ break;
+ }
+
+ return error;
+}
+
+
+// #pragma mark Set
+
+
+status_t
+BColorMap::Set(int32 key, rgb_color color)
+{
+ BString name;
+ name << key;
+ return Set(name, color);
+}
+
+
+status_t
+BColorMap::Set(color_which which, rgb_color color)
+{
+ return Set((int32)which, color);
+}
+
+
+status_t
+BColorMap::Set(const BString& key, rgb_color color)
+{
+ CHECK_WRITE_STATUS(fInitStatus);
+ BAutolock _(fData);
+
+ fData->Remove(key);
+ return fData->Add(key, color);
+}
+
+
+status_t
+BColorMap::Set(const BColorMap& colorMap)
+{
+ CHECK_WRITE_STATUS(fInitStatus);
+ BAutolock _(fData);
+
+ // Technically not an error
+ if (colorMap.CountColors() == 0)
+ return B_OK;
+
+ BString key;
+ int32 color = 0;
+
+ status_t error = B_OK;
+ for (int32 index = 0; index < colorMap.CountColors(); ++index) {
+ if (!colorMap._GetDataAt(index, &key, &color))
+ return B_BAD_DATA;
+
+ fData->Remove(key);
+ error = fData->Add(key, color);
+
+ if (error != B_OK)
+ break;
+ }
+
+ return error;
+}
+
+
+// #pragma mark Remove
+
+
+status_t
+BColorMap::Remove(int32 key)
+{
+ BString name;
+ name << key;
+ return Remove(name);
+}
+
+
+status_t
+BColorMap::Remove(color_which which)
+{
+ return Remove((int32)which);
+}
+
+
+status_t
+BColorMap::Remove(const BString& key)
+{
+ CHECK_WRITE_STATUS(fInitStatus);
+ BAutolock _(fData);
+
+ if (!HasColor(key))
+ return B_BAD_VALUE;
+
+ fData->Remove(key);
+ return B_OK;
+}
+
+
+status_t
+BColorMap::Remove(const BColorMap& colorMap)
+{
+ CHECK_WRITE_STATUS(fInitStatus);
+ BAutolock _(fData);
+
+ if (colorMap.CountColors() == 0)
+ return B_OK;
+
+ BString key;
+ int32 color = 0;
+
+ for (int32 index = 0; index < colorMap.CountColors(); ++index) {
+ if (!colorMap._GetDataAt(index, &key, &color))
+ return B_BAD_DATA;
+
+ fData->Remove(key);
+ }
+
+ return B_OK;
+}
+
+
+void
+BColorMap::MakeEmpty()
+{
+ if (fData != NULL && _InitCopyOnWrite() == B_OK) {
+ BAutolock _(fData);
+ fData->RemoveAll();
+ }
+}
+
+
+// #pragma mark Retrieve
+
+
+status_t
+BColorMap::Get(int32 key, rgb_color* color) const
+{
+ BString name;
+ name << key;
+ return Get(name, color);
+}
+
+
+status_t
+BColorMap::Get(color_which which, rgb_color* color) const
+{
+ return Get((int32)which, color);
+}
+
+
+status_t
+BColorMap::Get(const BString& key, rgb_color* color) const
+{
+ CHECK_READ_STATUS(fInitStatus);
+ BAutolock _(fData);
+
+ int32 intColor = 0;
+ status_t error = fData->FindInt32(key.String(), &intColor);
+
+ if (error == B_OK && color != NULL) {
+ intColor = B_HOST_TO_BENDIAN_INT32(intColor);
+ *color = *(rgb_color*)&intColor;
+ }
+
+ return error;
+}
+
+
+status_t
+BColorMap::GetNext(int32* index, BString* key, rgb_color* color)
+{
+ if (index == NULL || key == NULL || *index < 0)
+ return B_BAD_VALUE;
+
+ CHECK_READ_STATUS(fInitStatus);
+ BAutolock _(fData);
+
+ int32 intColor = 0;
+ if (!_GetDataAt(*index, key, &intColor))
+ return B_BAD_INDEX;
+
+ if (color != NULL) {
+ intColor = B_HOST_TO_BENDIAN_INT32(intColor);
+ *color = *(rgb_color*)&intColor;
+ }
+
+ return B_OK;
+}
+
+
+// #pragma mark Query
+
+
+bool
+BColorMap::HasColor(int32 key) const
+{
+ BString name;
+ name << key;
+ return HasColor(name);
+}
+
+
+bool
+BColorMap::HasColor(color_which which) const
+{
+ return HasColor((int32)which);
+}
+
+
+bool
+BColorMap::HasColor(const BString& key) const
+{
+ CHECK_READ_STATUS(false);
+ BAutolock _(fData);
+
+ int32 color = 0;
+ return fData->FindInt32(key.String(), &color) == B_OK;
+}
+
+
+status_t
+BColorMap::InitCheck() const
+{
+ return fInitStatus;
+}
+
+
+int32
+BColorMap::CountColors() const
+{
+ CHECK_READ_STATUS(0);
+ BAutolock _(fData);
+
+ int32 count = fData->CountNames(B_INT32_TYPE);
+ void* ptr = NULL;
+ if (fData->FindPointer(kColorMapPointerName, &ptr) == B_OK)
+ --count;
+
+ return count;
+}
+
+
+bool
+BColorMap::IsEmpty() const
+{
+ return CountColors() == 0;
+}
+
+
+void
+BColorMap::PrintToStream() const
+{
+ if (fData == NULL) {
+ printf("BColorMap: ERROR: NULL DATA!\n");
+ return;
+ }
+
+ BAutolock _(fData);
+
+ printf("BColorMap: %li colors {\n", CountColors());
+
+ BString key;
+ int32 intColor;
+ rgb_color color;
+
+ if (fInitStatus != B_OK)
+ printf("\tINIT FAILURE: %li\n", fInitStatus);
+
+ for (int32 index = 0; index < CountColors(); ++index) {
+ if (!_GetDataAt(index, &key, &intColor)) {
+ printf("\tError @ index %li\n", index);
+ break;
+ }
+ intColor = B_HOST_TO_BENDIAN_INT32(intColor);
+ color = *(rgb_color*)&intColor;
+
+ printf("\t%-5li %-20s rgb_color(%3i, %3i, %3i, %3i)\n", index,
+ key.String(), color.red, color.green, color.blue,
color.alpha);
+ }
+ printf("}\n");
+}
+
+
+// #pragma mark Private
+
+
+bool
+BColorMap::_GetDataAt(int32 index, BString* keyOut, int32* data) const
+{
+ if (index < 0 || index >= CountColors())
+ return false;
+
+ char* name = NULL;
+ type_code type;
+
+ if (fData->GetInfo(B_INT32_TYPE, index, &name, &type) != B_OK)
+ return false;
+
+ if (keyOut != NULL)
+ *keyOut = name;
+
+ if (data != NULL && fData->FindInt32(name, data) != B_OK)
+ return false;
+
+ return true;
+}
+
+
+void
+BColorMap::_Init(BMessage* from)
+{
+ if (from != NULL
+ && from->FindPointer(kColorMapPointerName, (void**)&fData) ==
B_OK) {
+ fData->AcquireReference();
+ fData->SetShared(true);
+ fInitStatus = B_OK;
+ return;
+ }
+
+ BMessage archive;
+
+ if (from == NULL)
+ fData = new(std::nothrow) BPrivate::BColorMapData();
+ else if (from->FindMessage("be:colormap", &archive) == B_OK)
+ fData = new(std::nothrow) BPrivate::BColorMapData(&archive);
+ else
+ fData = new(std::nothrow) BPrivate::BColorMapData(from);
+
+ if (fData == NULL) {
+ fInitStatus = B_NO_MEMORY;
+ return;
+ }
+}
+
+
+status_t
+BColorMap::_InitCopyOnWrite()
+{
+ // If we can't read, we can't copy for writing...
+ CHECK_READ_STATUS(fInitStatus);
+ BAutolock _(fData);
+
+ if (fData->IsShared()) {
+ BPrivate::BColorMapData* newData = new(std::nothrow) BPrivate
+ ::BColorMapData(*fData);
+
+ if (newData == NULL)
+ return B_NO_MEMORY;
+
+ fData->ReleaseReference();
+ fData = newData;
+ return B_OK;
+ }
+
+ return B_OK;
+}
+
+
+// #pragma mark BColorMapData
+
+
+namespace BPrivate {
+
+
+BColorMapData::BColorMapData()
+ :
+ BMessage(B_COLORS_UPDATED),
+ BLocker("BColorMapData", true),
+ fIsShared(false)
+{
+}
+
+
+BColorMapData::BColorMapData(BMessage* message)
+ :
+ BMessage(*message),
+ BLocker("BColorMapData", true),
+ fIsShared(false)
+{
+ what = B_COLORS_UPDATED;
+}
+
+
+BColorMapData::BColorMapData(const BColorMapData& other)
+ :
+ BMessage(other),
+ BLocker("BColorMapData", true),
+ fIsShared(false)
+{
+ what = B_COLORS_UPDATED;
+}
+
+
+BColorMapData::~BColorMapData()
+{
+}
+
+
+status_t
+BColorMapData::Add(const BString& key, rgb_color color)
+{
+ return Add(key, B_BENDIAN_TO_HOST_INT32(*(int32*)&color));
+}
+
+
+status_t
+BColorMapData::Add(const BString& key, int32 color)
+{
+ int32 test = 0;
+ if (FindInt32(key.String(), &test) == B_OK)
+ return B_BAD_INDEX;
+
+ return AddInt32(key.String(), color);
+}
+
+
+void
+BColorMapData::Remove(const BString& key)
+{
+ RemoveName(key.String());
+}
+
+
+void
+BColorMapData::RemoveAll()
+{
+ MakeEmpty();
+}
+
+
+status_t
+BColorMapData::Send(port_id port, team_id team, int32 token,
+ bigtime_t timeout)
+{
+ if (port < 0 || team < 0 || token == B_NULL_TOKEN)
+ return B_BAD_VALUE;
+
+ BMessenger reply;
+ BMessage::Private messagePrivate(this);
+
+ what = B_COLORS_UPDATED;
+ return messagePrivate.SendMessage(port, team, token, timeout, false,
+ reply);
+}
+
+
+status_t
+BColorMapData::GetNext(int32* cookie, color_which* key, rgb_color* color)
+{
+ if (cookie == NULL || key == NULL || color == NULL)
+ return B_BAD_VALUE;
+
+ char* name = NULL;
+ type_code type;
+
+ status_t error = GetInfo(B_INT32_TYPE, *cookie, &name, &type);
+ if (error != B_OK)
+ return error;
+
+ int32 intColor = 0;
+ error = FindInt32(name, &intColor);
+
+ if (error == B_OK) {
+ *key = (color_which)atoi(name);
+ intColor = B_HOST_TO_BENDIAN_INT32(intColor);
+ *color = *(rgb_color*)&intColor;
+ }
+
+ // increment no matter what, some errors may be ignored by the caller...
+ *cookie = *cookie + 1;
+ return error;
+}
+
+
+void
+BColorMapData::SetShared(bool shared)
+{
+ fIsShared = shared;
+}
+
+
+bool
+BColorMapData::IsShared() const
+{
+ return fIsShared;
+}
+
+
+// #pragma mark BColorMapPrivate
+
+
+BColorMapData*
+BColorMapPrivate::AcquireData(BColorMap& colorMap, int32 times,
+ uint32 mode)
+{
+ if (times < 1)
+ return NULL;
+
+ BColorMapData* data = colorMap.fData;
+ if (data != NULL) {
+
+ // Lock the data so it doesn't change, and obtain a reference
so it
+ // isn't deleted until we are done. The order here is
important.
+ data->AcquireReference();
+ BAutolock _(data);
+
+ switch (mode) {
+ case B_CM_SHARE_DATA:
+ break;
+ case B_CM_STEAL_DATA:
+ {
+ BColorMapData* newData = new(std::nothrow)
BColorMapData();
+ if (newData == NULL)
+ return NULL;
+
+ data->ReleaseReference();
+ colorMap.fData = newData;
+ // release BColorMap's default reference
+ break;
+ }
+ case B_CM_COPY_DATA:
+ {
+ data = new(std::nothrow)
BColorMapData(*colorMap.fData);
+ // starts life with one reference, so
all is good!
+
+ if (data == NULL)
+ return NULL;
+ break;
+ }
+ }
+
+ // acquire the reference(s) (minus the one we already hold)
+ // BReferenceable could probably use a facility for this...
+ for (int32 count = 0; count < times - 1; ++count)
+ data->AcquireReference();
+ }
+
+ return data;
+}
+
+
+void
+BColorMapPrivate::ReleaseData(BColorMapData* data, int32 times, bool destroy)
+{
+ if (data != NULL) {
+ if (destroy)
+ times = data->ReleaseReference() - 1;
+
+ for (int32 count = 0; count < times; ++count)
+ data->ReleaseReference();
+ }
+}
+
+
+bool
+BColorMapPrivate::AcquireSharedPointer(BColorMap* colorMap, BMessage* message)
+{
+ if (colorMap == NULL || message == NULL || colorMap->InitCheck() != B_OK
+ || colorMap->fData == NULL)
+ return false;
+
+ BColorMapData* data = colorMap->fData;
+
+ data->AcquireReference();
+ message->RemoveName(kColorMapPointerName);
+
+ if (message->AddPointer(kColorMapPointerName, data) != B_OK) {
+ data->ReleaseReference();
+ return false;
+ }
+
+ return true;
+}
+
+
+void
+BColorMapPrivate::ReleaseSharedPointer(BMessage* message)
+{
+ BColorMapData* pointer = NULL;
+ if (message != NULL && message->FindPointer(kColorMapPointerName,
+ (void**)&pointer) == B_OK
+ && pointer != NULL) {
+
+ pointer->ReleaseReference();
+ message->RemoveName(kColorMapPointerName);
+ }
+}
+
+
+}; // end namespace BPrivate
diff --git a/src/kits/interface/ColorSet.cpp b/src/kits/interface/ColorSet.cpp
deleted file mode 100644
index 465bf6f..0000000
--- a/src/kits/interface/ColorSet.cpp
+++ /dev/null
@@ -1,721 +0,0 @@
-/*
- * Copyright 2015, Haiku.
- * Distributed under the terms of the MIT License.
- *
- * Authors:
- * Joseph Groover <looncraz@xxxxxxxxxxxx>
-*/
-#include <stdio.h>
-#include <stdlib.h>
-
-#include <Application.h>
-#include <Autolock.h>
-#include <ColorSet.h>
-#include <Locker.h>
-#include <StringList.h>
-
-#include <ColorSetPrivate.h>
-#include <DefaultColors.h>
-#include <ServerReadOnlyMemory.h>
-
-
-// helpful macros
-#define CHECK_READ_STATUS(X) if (InitCheck() != B_OK) return X ;
-#define CHECK_WRITE_STATUS(X) if (_InitCopyOnWrite() != B_OK) return X ;
-
-
-// not extern'd
-static BLocker be_global_colorset_lock;
-static BColorSet* be_default_colorset = NULL;
-static BColorSet* be_current_colorset = NULL;
-
-
-static const char* kColorSetPointerName = "_be_colorset_pointer_";
-static const rgb_color kFailureColor = make_color(0,0,0,0);
-
-
-BColorSet::BColorSet()
- :
- fColors(NULL),
- fSharedData(false),
- fInitStatus(B_OK)
-{
- _Init(NULL);
-}
-
-
-BColorSet::BColorSet(const BColorSet& other)
- :
- fColors(other.fColors),
- fSharedData(true),
- fInitStatus(B_OK)
-{
- if (fColors != NULL)
- fColors->AcquireReference();
- else
- fInitStatus = B_BAD_VALUE;
-}
-
-
-BColorSet::BColorSet(BMessage* from)
- :
- fColors(NULL),
- fSharedData(false),
- fInitStatus(B_OK)
-{
- _Init(from);
-}
-
-
-BColorSet::~BColorSet()
-{
- BAutolock _(be_global_colorset_lock);
- if (this == be_current_colorset)
- be_current_colorset = NULL;
- else if (this == be_default_colorset)
- be_default_colorset = NULL;
-
- // fColors will delete itself
- if (fColors != NULL)
- fColors->ReleaseReference();
-}
-
-
-// #pragma mark Archiving
-
-
-status_t
-BColorSet::Archive(BMessage* into, bool deep) const
-{
- CHECK_READ_STATUS(fInitStatus);
-
- if (into == NULL)
- return B_BAD_VALUE;
-
- status_t error = B_OK;
- const BColorPair* pair;
- int32 intColor;
- BString name;
- BStringList storeNames;
-
- for (int32 index = 0; index < CountColors(); ++index) {
- pair = ColorPairAt(index);
- intColor = B_BENDIAN_TO_HOST_INT32(*(int32*)&pair->color);
-
- name.Truncate(0);
- name << pair->key;
- storeNames.Add(name);
-
- error = into->AddInt32(name.String(), intColor);
-
- if (error != B_OK)
- break;
- }
-
- error = into->AddStrings("_keyList", storeNames);
- return error;
-}
-
-
-BArchivable*
-BColorSet::Instantiate(BMessage* archive)
-{
- return new(std::nothrow) BColorSet(archive);
-}
-
-
-// #pragma mark Static
-
-
-const BColorSet*
-BColorSet::DefaultColorSet()
-{
- BAutolock _(be_global_colorset_lock);
-
- if (be_default_colorset != NULL)
- return be_default_colorset;
-
- be_default_colorset = new(std::nothrow) BColorSet();
- if (be_default_colorset == NULL) {
- fprintf(stderr, "no memory!\n");
- return NULL;
- }
-
- for (int32 which = 1; which < kColorWhichLastContinuous + 1; ++which) {
- be_default_colorset->Add(which, BPrivate::kDefaultColors[
- color_which_to_index((color_which)which)]);
- }
-
- be_default_colorset->Add((int32)B_SUCCESS_COLOR,
-
BPrivate::kDefaultColors[color_which_to_index(B_SUCCESS_COLOR)]);
- be_default_colorset->Add((int32)B_FAILURE_COLOR,
-
BPrivate::kDefaultColors[color_which_to_index(B_FAILURE_COLOR)]);
-
- return be_default_colorset;
-}
-
-
-const BColorSet*
-BColorSet::CurrentColorSet()
-{
- if (be_app == NULL) {
- printf("BApplication object required to get current color
set!\n");
- return DefaultColorSet();
- }
-
- BAutolock _(be_global_colorset_lock);
-
- if (be_current_colorset != NULL)
- return be_current_colorset;
-
- be_current_colorset = new(std::nothrow) BColorSet();
- if (be_current_colorset == NULL) {
- fprintf(stderr, "no memory!\n");
- return NULL;
- }
-
- for (int32 which = 1; which < kColorWhichLastContinuous + 1; ++which)
- be_current_colorset->Add(which, ui_color((color_which)which));
-
- be_current_colorset->Add((int32)B_SUCCESS_COLOR,
- ui_color(B_SUCCESS_COLOR));
- be_current_colorset->Add((int32)B_FAILURE_COLOR,
- ui_color(B_FAILURE_COLOR));
-
- return be_current_colorset;
-}
-
-
-status_t
-BColorSet::Get(const BMessage* message, int32 key, rgb_color* color)
-{
- if (message == NULL)
- return B_BAD_VALUE;
-
- BString name;
- name << key;
- int32 intColor = 0;
-
- status_t error = message->FindInt32(name.String(), &intColor);
-
- if (error == B_OK && color != NULL)
- *color = *(rgb_color*)&intColor;
-
- return error;
-}
-
-
-status_t
-BColorSet::Get(const BMessage* message, color_which which, rgb_color* color)
-{
- return BColorSet::Get(message, (int32)which, color);
-}
-
-
-// #pragma mark Add
-
-
-status_t
-BColorSet::Add(const BColorPair* pair)
-{
- CHECK_WRITE_STATUS(fInitStatus);
-
- if (pair == NULL)
- return B_BAD_VALUE;
-
- if (Find(pair->key) != NULL)
- return B_BAD_INDEX;
-
- return _Add(new(std::nothrow) BColorPair(*pair));
-}
-
-
-status_t
-BColorSet::Add(int32 key, rgb_color color)
-{
- CHECK_WRITE_STATUS(fInitStatus);
-
- BColorPair* pair = Find(key);
- if (pair != NULL)
- return B_BAD_INDEX;
-
- return _Add(new(std::nothrow) BColorPair((BColorPair){key, color}));
-}
-
-
-status_t
-BColorSet::Add(color_which which, rgb_color color)
-{
- return Add((int32)which, color);
-}
-
-
-status_t
-BColorSet::Add(const BColorSet& colorSet)
-{
- CHECK_WRITE_STATUS(fInitStatus);
-
- // Technically not an error
- if (colorSet.CountColors() == 0)
- return B_OK;
-
- status_t error = B_OK;
- for (int32 index = 0; index < colorSet.CountColors(); ++index) {
- error = Add(colorSet.ColorPairAt(index));
- if (error != B_OK)
- break;
- }
-
- return error;
-}
-
-
-// #pragma mark Set
-
-status_t
-BColorSet::Set(const BColorPair* pair)
-{
- CHECK_WRITE_STATUS(fInitStatus);
-
- if (pair == NULL)
- return B_BAD_VALUE;
-
- BColorPair* set = Find(pair->key);
- if (set == NULL)
- return Add(pair);
-
- set->color = pair->color;
- return B_OK;
-}
-
-
-status_t
-BColorSet::Set(int32 key, rgb_color color)
-{
- CHECK_WRITE_STATUS(fInitStatus);
-
- BColorPair* pair = Find(key);
- if (pair == NULL)
- return Add(key, color);
-
- pair->color = color;
-
- return B_OK;
-}
-
-
-status_t
-BColorSet::Set(color_which which, rgb_color color)
-{
- return Set((int32)which, color);
-}
-
-
-status_t
-BColorSet::Set(const BColorSet& colorSet)
-{
- CHECK_WRITE_STATUS(fInitStatus);
-
- // Technically not an error
- if (colorSet.CountColors() == 0)
- return B_OK;
-
- status_t error = B_OK;
- for (int32 index = 0; index < colorSet.CountColors(); ++index) {
- error = Set(colorSet.ColorPairAt(index));
- if (error != B_OK)
- break;
- }
-
- return error;
-}
-
-
-// #pragma mark Remove
-
-
-status_t
-BColorSet::RemoveAt(int32 index)
-{
- CHECK_WRITE_STATUS(fInitStatus);
-
- BColorPair* pair = ColorPairAt(index);
-
- if (pair == NULL)
- return B_BAD_INDEX;
-
- return fColors->RemoveItem(pair) ? B_OK : B_ERROR;
-}
-
-
-status_t
-BColorSet::Remove(const BColorPair* pair)
-{
- CHECK_WRITE_STATUS(fInitStatus);
-
- if (pair == NULL)
- return B_BAD_VALUE;
-
- // See if we are being handed our own pointer...
- if (fColors->RemoveItem(const_cast<BColorPair*>(pair)))
- return B_OK;
-
- BColorPair* ours = Find(pair->key);
- if (ours == NULL)
- return B_BAD_INDEX;
-
- return fColors->RemoveItem(ours) ? B_OK : B_ERROR;
-}
-
-
-status_t
-BColorSet::Remove(int32 key)
-{
- return Remove(Find(key));
-}
-
-
-status_t
-BColorSet::Remove(color_which which)
-{
- return Remove((int32)which);
-}
-
-
-status_t
-BColorSet::Remove(const BColorSet& colorSet)
-{
- CHECK_WRITE_STATUS(fInitStatus);
-
- if (colorSet.CountColors() == 0)
- return B_OK;
-
- status_t error = B_OK;
- const BColorPair* pair;
-
- for (int32 index = 0; index < colorSet.CountColors(); ++index) {
- pair = colorSet.ColorPairAt(index);
-
- error = Remove(pair);
- if (error != B_OK)
- break;
- }
-
- return error;
-}
-
-
-void
-BColorSet::MakeEmpty()
-{
- if (fColors != NULL)
- fColors->MakeEmpty();
-}
-
-
-// #pragma mark Retrieve
-
-
-rgb_color
-BColorSet::ColorAt(int32 index) const
-{
- CHECK_READ_STATUS(kFailureColor);
-
- const BColorPair* pair = ColorPairAt(index);
-
- if (pair == NULL)
- return kFailureColor;
-
- return pair->color;
-}
-
-
-int32
-BColorSet::ColorKeyAt(int32 index) const
-{
- CHECK_READ_STATUS((int32)fInitStatus);
-
- const BColorPair* pair = ColorPairAt(index);
-
- if (pair == NULL)
- return B_BAD_INDEX;
-
- return pair->key;
-}
-
-
-const BColorPair*
-BColorSet::ColorPairAt(int32 index) const
-{
- CHECK_READ_STATUS(NULL);
- return fColors->ItemAt(index);
-}
-
-
-BColorPair*
-BColorSet::ColorPairAt(int32 index)
-{
- CHECK_READ_STATUS(NULL);
- return fColors->ItemAt(index);
-}
-
-
-const BColorPair*
-BColorSet::Find(int32 key) const
-{
- CHECK_READ_STATUS(NULL);
-
- const BColorPair* pair;
- for (int32 index = 0; index < CountColors(); ++index) {
- pair = fColors->ItemAt(index);
-
- if (pair->key == key)
- return pair;
- }
-
- return NULL;
-}
-
-
-BColorPair*
-BColorSet::Find(int32 key)
-{
- CHECK_READ_STATUS(NULL);
-
- BColorPair* pair;
- for (int32 index = 0; index < CountColors(); ++index) {
- pair = fColors->ItemAt(index);
-
- if (pair->key == key)
- return pair;
- }
-
- return NULL;
-}
-
-
-const BColorPair*
-BColorSet::Find(color_which which) const
-{
- return Find((int32)which);
-}
-
-
-BColorPair*
-BColorSet::Find(color_which which)
-{
- return Find((int32)which);
-}
-
-
-// #pragma mark Query
-
-
-status_t
-BColorSet::InitCheck() const
-{
- return fInitStatus;
-}
-
-
-bool
-BColorSet::HasKey(int32 key) const
-{
- return Find(key) != NULL;
-}
-
-
-int32
-BColorSet::CountColors() const
-{
- CHECK_READ_STATUS(0);
- return fColors->CountItems();
-}
-
-
-bool
-BColorSet::IsEmpty() const
-{
- return CountColors() == 0;
-}
-
-
-void
-BColorSet::PrintToStream() const
-{
- printf("BColorSet: %li colors {\n", CountColors());
- const BColorPair* pair;
-
- if (fInitStatus != B_OK)
- printf("\tINIT FAILURE: %li\n", fInitStatus);
-
- for (int32 index = 0; index < CountColors(); ++index) {
- pair = ColorPairAt(index);
- printf("\t%-5li %-10li rgb_color(%3i, %3i, %3i, %3i)\n", index,
- pair->key, pair->color.red, pair->color.green,
- pair->color.blue, pair->color.alpha);
- }
- printf("}\n");
-}
-
-
-// #pragma mark Private
-
-
-status_t
-BColorSet::_Add(BColorPair* newPair)
-{
- if (newPair == NULL)
- return B_NO_MEMORY;
-
- if (!fColors->AddItem(newPair)) {
- delete newPair;
- return B_ERROR;
- }
-
- return B_OK;
-}
-
-
-void
-BColorSet::_Init(BMessage* from)
-{
- if (from == NULL) {
- if (fColors == NULL) {
- fColors = new(std::nothrow) BPrivate::BColorSetData();
- fSharedData = false;
-
- if (fColors == NULL)
- fInitStatus = B_NO_MEMORY;
- }
- return;
- }
-
- int32 key;
- rgb_color color;
- int32 intColor;
-
- if (from->FindPointer(kColorSetPointerName, (void**)&fColors) != B_OK) {
- fColors = new(std::nothrow) BPrivate::BColorSetData();
- if (fColors == NULL) {
- fInitStatus = B_NO_MEMORY;
- return;
- }
- } else {
- fSharedData = true;
- fColors->AcquireReference();
- return;
- }
-
- BStringList nameList;
- if (from->FindStrings("_keyList", &nameList) == B_OK
- && nameList.CountStrings() > 0) {
-
- for (int32 index = 0; index < nameList.CountStrings(); ++index)
{
- BString name = nameList.StringAt(index);
-
- if (from->FindInt32(name.String(), &intColor) == B_OK) {
- key = atoi(name.String());
- intColor = B_HOST_TO_BENDIAN_INT32(intColor);
- color = *(rgb_color*)&intColor;
- Add(key, color);
-
- } else {
- fprintf(stderr, "Error instantiating BColorSet
- bad message data!\n");
- fprintf(stderr, "\tError %li at index: %li\n",
fInitStatus, index - 1);
- from->PrintToStream();
- break;
- }
- }
- }
-}
-
-
-status_t
-BColorSet::_InitCopyOnWrite()
-{
- // If we can't read, we can't copy for writing...
- CHECK_READ_STATUS(fInitStatus);
-
- if (fSharedData) {
- BPrivate::BColorSetData* newData = new(std::nothrow) BPrivate
- ::BColorSetData(*fColors);
-
- if (newData == NULL)
- return B_NO_MEMORY;
-
- fSharedData = false;
- return B_OK;
- }
-
- return B_OK;
-}
-
-// #pragma mark BColorSetData
-
-namespace BPrivate {
-
-BColorSetData::BColorSetData()
- :
- BObjectList<BColorPair>(5, true)
-{
-}
-
-
-BColorSetData::BColorSetData(const BColorSetData& other)
- :
- BObjectList<BColorPair>(other)
-{
-}
-
-
-BColorSetData::~BColorSetData()
-{
-}
-
-
-// #pragma mark BColorSetPrivate
-
-
-const BObjectList<BColorPair>&
-BColorSetPrivate::GetList(const BColorSet& colorSet)
-{
- return *colorSet.fColors;
-}
-
-
-bool
-BColorSetPrivate::AcquireSharedPointer(BColorSet* colorSet, BMessage* message)
-{
- if (colorSet == NULL || message == NULL || colorSet->InitCheck() != B_OK
- || colorSet->fColors == NULL)
- return false;
-
- BColorSetData* data = colorSet->fColors;
-
- data->AcquireReference();
- message->RemoveName(kColorSetPointerName);
- if (message->AddPointer(kColorSetPointerName, data) != B_OK) {
- data->ReleaseReference();
- return false;
- }
-
- return true;
-}
-
-
-void
-BColorSetPrivate::ReleaseSharedPointer(BMessage* message)
-{
- BColorSetData* pointer = NULL;
- if (message != NULL && message->FindPointer(kColorSetPointerName,
- (void**)&pointer) == B_OK
- && pointer != NULL) {
-
- pointer->ReleaseReference();
- message->RemoveName(kColorSetPointerName);
- }
-}
-
-
-}; // end namespace BPrivate
diff --git a/src/kits/interface/Jamfile b/src/kits/interface/Jamfile
index 5eb23ee..19cf7f3 100644
--- a/src/kits/interface/Jamfile
+++ b/src/kits/interface/Jamfile
@@ -56,7 +56,7 @@ for architectureObject in [ MultiArchSubDirSetup ] {
CheckBox.cpp
ColorConversion.cpp
ColorControl.cpp
- ColorSet.cpp
+ ColorMap.cpp
Control.cpp
ControlLook.cpp
DecorInfo.cpp
diff --git a/src/kits/interface/StatusBar.cpp b/src/kits/interface/StatusBar.cpp
index f626537..cc34c93 100644
--- a/src/kits/interface/StatusBar.cpp
+++ b/src/kits/interface/StatusBar.cpp
@@ -15,7 +15,7 @@
#include <stdlib.h>
#include <string.h>

-#include <ColorSet.h>
+#include <ColorMap.h>
#include <ControlLook.h>
#include <Layout.h>
#include <LayoutUtils.h>
@@ -434,13 +434,8 @@ BStatusBar::MessageReceived(BMessage *message)
case B_COLORS_UPDATED:
{
// Change the bar color IF we don't have an
application-set color.
- if ((fInternalFlags & kCustomBarColor) == 0) {
- BColorSet colorSet(message);
- BColorPair* pair =
colorSet.Find(B_CONTROL_MARK_COLOR);
-
- if (pair != NULL)
- fBarColor = tint_color(pair->color,
B_DARKEN_1_TINT);
- }
+ if ((fInternalFlags & kCustomBarColor) == 0)
+ BColorMap::Get(message, B_CONTROL_MARK_COLOR,
&fBarColor);

break;
}
diff --git a/src/kits/interface/TextControl.cpp
b/src/kits/interface/TextControl.cpp
index 069d0ff..36aa9b0 100644
--- a/src/kits/interface/TextControl.cpp
+++ b/src/kits/interface/TextControl.cpp
@@ -17,7 +17,7 @@
#include <string.h>

#include <AbstractLayoutItem.h>
-#include <ColorSet.h>
+#include <ColorMap.h>
#include <ControlLook.h>
#include <LayoutUtils.h>
#include <Message.h>
@@ -466,19 +466,13 @@ void
BTextControl::MessageReceived(BMessage* message)
{
if (message->what == B_COLORS_UPDATED) {
- BColorSet colorSet(message);
-
- color_which which = B_NO_COLOR;
- for (int32 index = 0; index < colorSet.CountColors(); ++index) {
- which = (color_which)colorSet.ColorKeyAt(index);
-
- if (which == B_PANEL_BACKGROUND_COLOR
- || which == B_PANEL_TEXT_COLOR
- || which == B_DOCUMENT_BACKGROUND_COLOR
- || which == B_DOCUMENT_TEXT_COLOR) {
- _UpdateTextViewColors(IsEnabled());
- break;
- }
+ BColorMap colorSet(message);
+
+ if (colorSet.HasColor(B_PANEL_BACKGROUND_COLOR)
+ || colorSet.HasColor(B_PANEL_TEXT_COLOR)
+ || colorSet.HasColor(B_DOCUMENT_BACKGROUND_COLOR)
+ || colorSet.HasColor(B_DOCUMENT_TEXT_COLOR)) {
+ _UpdateTextViewColors(IsEnabled());
}
}

diff --git a/src/kits/interface/View.cpp b/src/kits/interface/View.cpp
index 6eb4026..f270acb 100644
--- a/src/kits/interface/View.cpp
+++ b/src/kits/interface/View.cpp
@@ -21,7 +21,7 @@
#include <Application.h>
#include <Bitmap.h>
#include <Button.h>
-#include <ColorSet.h>
+#include <ColorMap.h>
#include <Cursor.h>
#include <File.h>
#include <GradientLinear.h>
@@ -5865,7 +5865,7 @@ BView::_Attach()


void
-BView::_ColorsUpdated(BMessage* message, const BColorSet& colorSet)
+BView::_ColorsUpdated(BMessage* message, const BColorMap& colorMap)
{
if (fTopLevelView
&& fLayoutData->fLayout != NULL
@@ -5874,36 +5874,28 @@ BView::_ColorsUpdated(BMessage* message, const
BColorSet& colorSet)
SetHighUIColor(B_PANEL_TEXT_COLOR);
}

- const BColorPair* pair = NULL;
+ rgb_color color;

- // keep local colors in sync
- for (int32 index = 0; index < colorSet.CountColors(); ++index) {
- pair = colorSet.ColorPairAt(index);
-
- if (fState->which_view_color == (color_which)pair->key) {
- fState->view_color = tint_color(pair->color,
- fState->which_view_color_tint);
- fState->valid_flags |= B_VIEW_VIEW_COLOR_BIT;
- }
+ if (colorMap.Get(fState->which_view_color, &color) == B_OK) {
+ fState->view_color = tint_color(color,
fState->which_view_color_tint);
+ fState->valid_flags |= B_VIEW_VIEW_COLOR_BIT;
+ }

- if (fState->which_high_color == (color_which)pair->key) {
- fState->high_color = tint_color(pair->color,
- fState->which_high_color_tint);
- fState->valid_flags |= B_VIEW_HIGH_COLOR_BIT;
- }
+ if (colorMap.Get(fState->which_low_color, &color) == B_OK) {
+ fState->low_color = tint_color(color,
fState->which_low_color_tint);
+ fState->valid_flags |= B_VIEW_LOW_COLOR_BIT;
+ }

- if (fState->which_low_color == (color_which)pair->key) {
- fState->low_color = tint_color(pair->color,
- fState->which_low_color_tint);
- fState->valid_flags |= B_VIEW_LOW_COLOR_BIT;
- }
+ if (colorMap.Get(fState->which_high_color, &color) == B_OK) {
+ fState->high_color = tint_color(color,
fState->which_high_color_tint);
+ fState->valid_flags |= B_VIEW_HIGH_COLOR_BIT;
}

MessageReceived(message);

for (BView* child = fFirstChild; child != NULL;
child = child->fNextSibling)
- child->_ColorsUpdated(message, colorSet);
+ child->_ColorsUpdated(message, colorMap);

Invalidate();
}
diff --git a/src/kits/interface/Window.cpp b/src/kits/interface/Window.cpp
index 618b09e..071ca70 100644
--- a/src/kits/interface/Window.cpp
+++ b/src/kits/interface/Window.cpp
@@ -21,7 +21,7 @@
#include <Autolock.h>
#include <Bitmap.h>
#include <Button.h>
-#include <ColorSet.h>
+#include <ColorMap.h>
#include <FindDirectory.h>
#include <Layout.h>
#include <LayoutUtils.h>
@@ -40,7 +40,7 @@
#include <AppServerLink.h>
#include <ApplicationPrivate.h>
#include <binary_compatibility/Interface.h>
-#include <ColorSetPrivate.h>
+#include <ColorMapPrivate.h>
#include <DirectMessageTarget.h>
#include <input_globals.h>
#include <InputServerTypes.h>
@@ -1444,16 +1444,15 @@ FrameMoved(origin);

case B_COLORS_UPDATED:
{
- BColorSet colorSet(message);
- if (colorSet.CountColors() == 0)
+ using namespace BPrivate;
+ BColorMap colorMap(message);
+ if (colorMap.CountColors() == 0)
break;

- BPrivate::BColorSetPrivate
- ::AcquireSharedPointer(&colorSet, message);
- fTopView->_ColorsUpdated(message, colorSet);
+ BColorMapPrivate::AcquireSharedPointer(&colorMap,
message);
+ fTopView->_ColorsUpdated(message, colorMap);
target->MessageReceived(message);
- BPrivate::BColorSetPrivate
- ::ReleaseSharedPointer(message);
+ BColorMapPrivate::ReleaseSharedPointer(message);
break;
}

diff --git a/src/preferences/appearance/AntialiasingSettingsView.cpp
b/src/preferences/appearance/AntialiasingSettingsView.cpp
index 9b348b5..3d8465a 100644
--- a/src/preferences/appearance/AntialiasingSettingsView.cpp
+++ b/src/preferences/appearance/AntialiasingSettingsView.cpp
@@ -16,7 +16,7 @@

#include <Box.h>
#include <Catalog.h>
-#include <ColorSet.h>
+#include <ColorMap.h>
#include <GridLayoutBuilder.h>
#include <GroupLayoutBuilder.h>
#include <Locale.h>
@@ -226,8 +226,7 @@ AntialiasingSettingsView::MessageReceived(BMessage *msg)
}
case B_COLORS_UPDATED:
{
- BColorSet colorSet(msg);
- if (colorSet.Find(B_PANEL_BACKGROUND_COLOR) != NULL)
+ if (BColorMap::Get(msg, B_PANEL_BACKGROUND_COLOR) ==
B_OK)
_UpdateColors();
break;
}
diff --git a/src/preferences/datatranslations/DataTranslationsWindow.cpp
b/src/preferences/datatranslations/DataTranslationsWindow.cpp
index 085f6cb..a0b584a 100644
--- a/src/preferences/datatranslations/DataTranslationsWindow.cpp
+++ b/src/preferences/datatranslations/DataTranslationsWindow.cpp
@@ -21,7 +21,7 @@
#include <Bitmap.h>
#include <Box.h>
#include <Catalog.h>
-#include <ColorSet.h>
+#include <ColorMap.h>
#include <ControlLook.h>
#include <Entry.h>
#include <GroupView.h>
@@ -351,11 +351,9 @@ DataTranslationsWindow::MessageReceived(BMessage* message)
|| fInfoText->Parent() == NULL)
break;

- BColorSet colorSet(message);
- BColorPair* pair = colorSet.Find(B_PANEL_TEXT_COLOR);
- if (pair != NULL)
- fInfoText->SetFontAndColor(be_plain_font,
B_FONT_ALL,
- &pair->color);
+ rgb_color color;
+ if (BColorMap::Get(message, B_PANEL_TEXT_COLOR, &color)
== B_OK)
+ fInfoText->SetFontAndColor(be_plain_font,
B_FONT_ALL, &color);
break;
}

diff --git a/src/servers/app/Desktop.cpp b/src/servers/app/Desktop.cpp
index 2f7c6c6..0d603b4 100644
--- a/src/servers/app/Desktop.cpp
+++ b/src/servers/app/Desktop.cpp
@@ -2736,7 +2736,7 @@ Desktop::_DispatchMessage(int32 code,
BPrivate::LinkReceiver& link)
if (link.Read<color_which>(&which) == B_OK
&& link.Read<rgb_color>(&color) ==
B_OK) {

- fPendingColorSet.Set(which, color);
+ fPendingColorMap.Set(which, color);

DelayedMessage delayed(MessagePort(),
AS_SET_UI_COLORS,
DM_60HZ_DELAY, B_RELATIVE_TIMEOUT,
DM_MERGE_CANCEL);
@@ -2755,12 +2755,12 @@ Desktop::_DispatchMessage(int32 code,
BPrivate::LinkReceiver& link)
break;

if (flushPendingOnly) {
- if (fPendingColorSet.CountColors() == 0)
+ if (fPendingColorMap.CountColors() == 0)
break;

LockedDesktopSettings settings(this);
- settings.SetUIColors(fPendingColorSet);
- fPendingColorSet.MakeEmpty();
+ settings.SetUIColors(fPendingColorMap, true);
+ // Our pending color map is now empty
} else {
// TODO: support external color sets here
// ... or directly in ServerApp? or nowhere?
diff --git a/src/servers/app/Desktop.h b/src/servers/app/Desktop.h
index 93cefb9..6d6856d 100644
--- a/src/servers/app/Desktop.h
+++ b/src/servers/app/Desktop.h
@@ -15,7 +15,7 @@


#include <Autolock.h>
-#include <ColorSet.h>
+#include <ColorMap.h>
#include <InterfaceDefs.h>
#include <List.h>
#include <Menu.h>
@@ -375,7 +375,7 @@ private:

StackAndTile fStackAndTile;

- BColorSet fPendingColorSet;
+ BColorMap fPendingColorMap;
};

#endif // DESKTOP_H
diff --git a/src/servers/app/DesktopSettings.cpp
b/src/servers/app/DesktopSettings.cpp
index 5f7e3c3..f652cbf 100644
--- a/src/servers/app/DesktopSettings.cpp
+++ b/src/servers/app/DesktopSettings.cpp
@@ -17,7 +17,7 @@
#include <FindDirectory.h>
#include <Path.h>

-#include <ColorSetPrivate.h>
+#include <ColorMapPrivate.h>
#include <DefaultColors.h>
#include <InterfaceDefs.h>
#include <ServerReadOnlyMemory.h>
@@ -672,29 +672,34 @@ DesktopSettingsPrivate::SetUIColor(color_which which,
const rgb_color color,


void
-DesktopSettingsPrivate::SetUIColors(const BColorSet& colorSet, bool* changed)
+DesktopSettingsPrivate::SetUIColors(BColorMap& colorSet, bool* changed)
{
+ using namespace BPrivate;
if (colorSet.CountColors() <= 0)
return;

- int32 colorIndex = -1;
- const BColorPair* pair = NULL;
+ BColorMapData* data = BColorMapPrivate::AcquireData(colorSet);

- for (int32 index = 0; index < colorSet.CountColors(); ++index) {
- pair = colorSet.ColorPairAt(index);
- colorIndex = color_which_to_index((color_which)pair->key);
+ if (data == NULL)
+ return;
+
+ int32 cookie = 0;
+ int32 colorIndex = 0;
+ color_which which;
+ rgb_color color;

- if (colorIndex < 0
- || colorIndex >= kColorWhichCount)
+ while (data->GetNext(&cookie, &which, &color) == B_OK) {
+ colorIndex = color_which_to_index(which);
+ if (colorIndex < 0 || colorIndex >= kColorWhichCount)
continue;

if (changed != NULL)
- changed[index] = fShared.colors[colorIndex] !=
pair->color;
+ changed[cookie] = fShared.colors[colorIndex] != color;

- fShared.colors[colorIndex] = pair->color;
+ fShared.colors[colorIndex] = color;

- if ((color_which)pair->key == B_MENU_BACKGROUND_COLOR)
- fMenuInfo.background_color = pair->color;
+ if (which == B_MENU_BACKGROUND_COLOR)
+ fMenuInfo.background_color = color;
}

Save(kAppearanceSettings);
@@ -1036,8 +1041,9 @@ LockedDesktopSettings::SetUIColor(color_which which,
const rgb_color color)


void
-LockedDesktopSettings::SetUIColors(const BColorSet& colorSet)
+LockedDesktopSettings::SetUIColors(BColorMap& colorSet, bool moveData)
{
+ using namespace BPrivate;
if (colorSet.CountColors() <= 0)
return;

@@ -1045,12 +1051,24 @@ LockedDesktopSettings::SetUIColors(const BColorSet&
colorSet)
fSettings->SetUIColors(colorSet, &changed[0]);

DelayedMessage delayed(-1, AS_COLOR_SET_UPDATED, DM_MINIMUM_DELAY);
- if (fDesktop->GetAllWindowTargets(delayed) <= 0)
+ int32 count = fDesktop->GetAllWindowTargets(delayed);
+
+ if (count <= 0)
return;

- if (delayed.AttachList(BPrivate::BColorSetPrivate::GetList(colorSet),
- changed) == B_OK)
- delayed.Flush();
+ // Create a single data archive so we don't copy the data to each window
+ BColorMapData* data = BColorMapPrivate::AcquireData(colorSet, count,
+ moveData ? B_CM_STEAL_DATA : B_CM_COPY_DATA);
+
+ if (data == NULL)
+ return;
+
+ // This message will be sent indirectly to all clients, so we set the
'what'
+ // properly here.
+ data->what = B_COLORS_UPDATED;
+
+ if (delayed.Attach<BColorMapData*>(data) != B_OK || delayed.Flush() !=
B_OK)
+ BColorMapPrivate::ReleaseData(data, count, true);
}


diff --git a/src/servers/app/DesktopSettings.h
b/src/servers/app/DesktopSettings.h
index 7c92fe8..23e4fc7 100644
--- a/src/servers/app/DesktopSettings.h
+++ b/src/servers/app/DesktopSettings.h
@@ -10,7 +10,7 @@
#define DESKTOP_SETTINGS_H


-#include <ColorSet.h>
+#include <ColorMap.h>
#include <InterfaceDefs.h>
#include <Menu.h>
#include <Message.h>
@@ -102,7 +102,8 @@ public:

void SetUIColor(color_which
which,
const
rgb_color color);
- void SetUIColors(const
BColorSet& colorSet);
+ void SetUIColors(BColorMap&
colorSet,
+ bool
moveData);

void
SetSubpixelAntialiasing(bool subpix);
void SetHinting(uint8
hinting);
diff --git a/src/servers/app/DesktopSettingsPrivate.h
b/src/servers/app/DesktopSettingsPrivate.h
index ab6c94e..679b1b4 100644
--- a/src/servers/app/DesktopSettingsPrivate.h
+++ b/src/servers/app/DesktopSettingsPrivate.h
@@ -74,7 +74,7 @@ public:
void SetUIColor(color_which
which,
const
rgb_color color,
bool*
changed = NULL);
- void SetUIColors(const
BColorSet& colorSet,
+ void SetUIColors(BColorMap&
colorSet,
bool*
changed = NULL);

[ *** diff truncated: 58 lines dropped *** ]



Other related posts:

  • » [haiku-commits] BRANCH looncraz-github.setviewuicolor [1b38b2e15e61] src/kits/interface headers/os/interface src/servers/app headers/private/interface src - looncraz-github . setviewuicolor