Appearance Prefs: drag and drop between ColorWhichItems
Fixes final piece of #8618 Already added support for list items to drag colors out and you can drag and drop between the list items and preview. but, what was missing was drag and drop between list items. Updated ColorWhichListItem to also accept color drops through their parent ColorWhichListView. Also included some related style fixes, use B_RGB_COLOR_TYPE constant in place of (type_code)'RGBC'. 80-char limit fixes. Simplify similar code in ColorPreview class to parse out rgb_color from message. ColorPreview passes dropped color along to APRView APRView no longer accepts color drops, this is handled by ListView and ColorPreview now. Consolidated "RGBColor" and "which" message name strings into constants defined in defs.h. Change-Id: I88ec2a4ffe077620ec4cc3b032196cbff0f09615
This commit is contained in:
committed by
waddlesplash
parent
5d898e77d2
commit
e88a89e676
@@ -130,19 +130,35 @@ APRView::AttachedToWindow()
|
|||||||
void
|
void
|
||||||
APRView::MessageReceived(BMessage *msg)
|
APRView::MessageReceived(BMessage *msg)
|
||||||
{
|
{
|
||||||
if (msg->WasDropped()) {
|
|
||||||
rgb_color* color = NULL;
|
|
||||||
ssize_t size = 0;
|
|
||||||
|
|
||||||
if (msg->FindData("RGBColor", (type_code)'RGBC', (const void**)&color,
|
|
||||||
&size) == B_OK) {
|
|
||||||
_SetCurrentColor(*color);
|
|
||||||
|
|
||||||
Window()->PostMessage(kMsgUpdate);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
switch (msg->what) {
|
switch (msg->what) {
|
||||||
|
case SET_COLOR:
|
||||||
|
{
|
||||||
|
rgb_color* color;
|
||||||
|
ssize_t size;
|
||||||
|
color_which which;
|
||||||
|
|
||||||
|
if (msg->FindData(kRGBColor, B_RGB_COLOR_TYPE,
|
||||||
|
(const void**)&color, &size) == B_OK
|
||||||
|
&& msg->FindUInt32(kWhich, (uint32*)&which) == B_OK) {
|
||||||
|
_SetColor(which, *color);
|
||||||
|
Window()->PostMessage(kMsgUpdate);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
case SET_CURRENT_COLOR:
|
||||||
|
{
|
||||||
|
rgb_color* color;
|
||||||
|
ssize_t size;
|
||||||
|
|
||||||
|
if (msg->FindData(kRGBColor, B_RGB_COLOR_TYPE,
|
||||||
|
(const void**)&color, &size) == B_OK) {
|
||||||
|
_SetCurrentColor(*color);
|
||||||
|
Window()->PostMessage(kMsgUpdate);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
case UPDATE_COLOR:
|
case UPDATE_COLOR:
|
||||||
{
|
{
|
||||||
// Received from the color fPicker when its color changes
|
// Received from the color fPicker when its color changes
|
||||||
@@ -232,11 +248,18 @@ APRView::IsRevertable()
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
APRView::_SetColor(color_which which, rgb_color color)
|
||||||
|
{
|
||||||
|
set_ui_color(which, color);
|
||||||
|
fCurrentColors.SetColor(ui_color_name(which), color);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
APRView::_SetCurrentColor(rgb_color color)
|
APRView::_SetCurrentColor(rgb_color color)
|
||||||
{
|
{
|
||||||
set_ui_color(fWhich, color);
|
_SetColor(fWhich, color);
|
||||||
fCurrentColors.SetColor(ui_color_name(fWhich), color);
|
|
||||||
|
|
||||||
int32 currentIndex = fAttrList->CurrentSelection();
|
int32 currentIndex = fAttrList->CurrentSelection();
|
||||||
ColorWhichItem* item = (ColorWhichItem*)fAttrList->ItemAt(currentIndex);
|
ColorWhichItem* item = (ColorWhichItem*)fAttrList->ItemAt(currentIndex);
|
||||||
|
|||||||
@@ -50,6 +50,7 @@ public:
|
|||||||
bool IsRevertable();
|
bool IsRevertable();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
void _SetColor(color_which which, rgb_color color);
|
||||||
void _SetCurrentColor(rgb_color color);
|
void _SetCurrentColor(rgb_color color);
|
||||||
void _SetUIColors(const BMessage& colors);
|
void _SetUIColors(const BMessage& colors);
|
||||||
void _UpdatePreviews(const BMessage& colors);
|
void _UpdatePreviews(const BMessage& colors);
|
||||||
|
|||||||
@@ -21,6 +21,8 @@
|
|||||||
#include <View.h>
|
#include <View.h>
|
||||||
#include <Window.h>
|
#include <Window.h>
|
||||||
|
|
||||||
|
#include "defs.h"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
static const int32 kMsgMessageRunner = 'MsgR';
|
static const int32 kMsgMessageRunner = 'MsgR';
|
||||||
@@ -116,13 +118,14 @@ ColorPreview::MessageReceived(BMessage* message)
|
|||||||
{
|
{
|
||||||
// If we received a dropped message, see if it contains color data
|
// If we received a dropped message, see if it contains color data
|
||||||
if (message->WasDropped()) {
|
if (message->WasDropped()) {
|
||||||
rgb_color* col;
|
rgb_color* color;
|
||||||
uint8* ptr;
|
|
||||||
ssize_t size;
|
ssize_t size;
|
||||||
if (message->FindData("RGBColor", (type_code)'RGBC',
|
if (message->FindData(kRGBColor, B_RGB_COLOR_TYPE,
|
||||||
(const void**)&ptr,&size) == B_OK) {
|
(const void**)&color, &size) == B_OK) {
|
||||||
col = (rgb_color*)ptr;
|
BMessage setColorMessage(SET_CURRENT_COLOR);
|
||||||
SetHighColor(*col);
|
setColorMessage.AddData(kRGBColor, B_RGB_COLOR_TYPE, color,
|
||||||
|
sizeof(color));
|
||||||
|
Invoke(&setColorMessage);
|
||||||
}
|
}
|
||||||
} else if ((int32)message->what == kMsgMessageRunner) {
|
} else if ((int32)message->what == kMsgMessageRunner) {
|
||||||
BPoint where;
|
BPoint where;
|
||||||
@@ -232,8 +235,9 @@ ColorPreview::_DragColor(BPoint where)
|
|||||||
hexStr.SetToFormat("#%.2X%.2X%.2X", fColor.red, fColor.green, fColor.blue);
|
hexStr.SetToFormat("#%.2X%.2X%.2X", fColor.red, fColor.green, fColor.blue);
|
||||||
|
|
||||||
BMessage message(B_PASTE);
|
BMessage message(B_PASTE);
|
||||||
message.AddData("text/plain", B_MIME_TYPE, hexStr.String(), hexStr.Length());
|
message.AddData("text/plain", B_MIME_TYPE, hexStr.String(),
|
||||||
message.AddData("RGBColor", B_RGB_COLOR_TYPE, &fColor, sizeof(fColor));
|
hexStr.Length());
|
||||||
|
message.AddData(kRGBColor, B_RGB_COLOR_TYPE, &fColor, sizeof(fColor));
|
||||||
|
|
||||||
BRect rect(0.0f, 0.0f, 20.0f, 20.0f);
|
BRect rect(0.0f, 0.0f, 20.0f, 20.0f);
|
||||||
|
|
||||||
|
|||||||
@@ -18,6 +18,7 @@
|
|||||||
#include <String.h>
|
#include <String.h>
|
||||||
|
|
||||||
#include "ColorWhichItem.h"
|
#include "ColorWhichItem.h"
|
||||||
|
#include "defs.h"
|
||||||
|
|
||||||
|
|
||||||
// golden ratio
|
// golden ratio
|
||||||
@@ -57,8 +58,9 @@ ColorWhichListView::InitiateDrag(BPoint where, int32 index, bool wasSelected)
|
|||||||
hexStr.SetToFormat("#%.2X%.2X%.2X", color.red, color.green, color.blue);
|
hexStr.SetToFormat("#%.2X%.2X%.2X", color.red, color.green, color.blue);
|
||||||
|
|
||||||
BMessage message(B_PASTE);
|
BMessage message(B_PASTE);
|
||||||
message.AddData("text/plain", B_MIME_TYPE, hexStr.String(), hexStr.Length());
|
message.AddData("text/plain", B_MIME_TYPE, hexStr.String(),
|
||||||
message.AddData("RGBColor", B_RGB_COLOR_TYPE, &color, sizeof(color));
|
hexStr.Length());
|
||||||
|
message.AddData(kRGBColor, B_RGB_COLOR_TYPE, &color, sizeof(color));
|
||||||
|
|
||||||
float itemHeight = colorWhichItem->Height() - 5;
|
float itemHeight = colorWhichItem->Height() - 5;
|
||||||
BRect rect(0.0f, 0.0f, roundf(itemHeight * M_PHI) - 1, itemHeight - 1);
|
BRect rect(0.0f, 0.0f, roundf(itemHeight * M_PHI) - 1, itemHeight - 1);
|
||||||
@@ -105,3 +107,42 @@ ColorWhichListView::InitiateDrag(BPoint where, int32 index, bool wasSelected)
|
|||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
ColorWhichListView::MessageReceived(BMessage* message)
|
||||||
|
{
|
||||||
|
// if we received a dropped message, see if it contains color data
|
||||||
|
if (message->WasDropped()) {
|
||||||
|
BPoint dropPoint = message->DropPoint();
|
||||||
|
ConvertFromScreen(&dropPoint);
|
||||||
|
int32 index = IndexOf(dropPoint);
|
||||||
|
ColorWhichItem* item = dynamic_cast<ColorWhichItem*>(ItemAt(index));
|
||||||
|
rgb_color* color;
|
||||||
|
ssize_t size;
|
||||||
|
if (item != NULL && message->FindData(kRGBColor, B_RGB_COLOR_TYPE,
|
||||||
|
(const void**)&color, &size) == B_OK) {
|
||||||
|
// build message to send to APRView
|
||||||
|
int32 command = index == CurrentSelection()
|
||||||
|
? SET_CURRENT_COLOR : SET_COLOR;
|
||||||
|
BMessage setColorMessage = BMessage(command);
|
||||||
|
setColorMessage.AddData(kRGBColor, B_RGB_COLOR_TYPE, color, size);
|
||||||
|
// if setting different color, add which color to set
|
||||||
|
if (command == SET_COLOR)
|
||||||
|
setColorMessage.AddUInt32(kWhich, (uint32)item->ColorWhich());
|
||||||
|
|
||||||
|
// build messenger and send message
|
||||||
|
BMessenger messenger = BMessenger(Parent());
|
||||||
|
if (messenger.IsValid()) {
|
||||||
|
messenger.SendMessage(&setColorMessage);
|
||||||
|
if (command == SET_COLOR) {
|
||||||
|
// redraw item, SET_CURRENT_COLOR does this for us
|
||||||
|
item->SetColor(*color);
|
||||||
|
InvalidateItem(index);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
BListView::MessageReceived(message);
|
||||||
|
}
|
||||||
|
|||||||
@@ -24,6 +24,8 @@ public:
|
|||||||
|
|
||||||
virtual bool InitiateDrag(BPoint where, int32 index,
|
virtual bool InitiateDrag(BPoint where, int32 index,
|
||||||
bool wasSelected);
|
bool wasSelected);
|
||||||
|
virtual void MessageReceived(BMessage* message);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
#endif // COLORWHICH_LIST_VIEW_H
|
#endif // COLORWHICH_LIST_VIEW_H
|
||||||
|
|||||||
@@ -19,10 +19,13 @@
|
|||||||
|
|
||||||
#define APPEARANCE_APP_SIGNATURE "application/x-vnd.Haiku-Appearance"
|
#define APPEARANCE_APP_SIGNATURE "application/x-vnd.Haiku-Appearance"
|
||||||
|
|
||||||
|
// message commands
|
||||||
#define APPLY_SETTINGS 'aply'
|
#define APPLY_SETTINGS 'aply'
|
||||||
#define TRY_SETTINGS 'trys'
|
#define TRY_SETTINGS 'trys'
|
||||||
|
|
||||||
#define ATTRIBUTE_CHOSEN 'atch'
|
#define ATTRIBUTE_CHOSEN 'atch'
|
||||||
|
#define SET_COLOR 'sclr'
|
||||||
|
#define SET_CURRENT_COLOR 'sccl'
|
||||||
#define UPDATE_COLOR 'upcl'
|
#define UPDATE_COLOR 'upcl'
|
||||||
#define DECORATOR_CHOSEN 'dcch'
|
#define DECORATOR_CHOSEN 'dcch'
|
||||||
#define UPDATE_DECORATOR 'updc'
|
#define UPDATE_DECORATOR 'updc'
|
||||||
@@ -34,6 +37,10 @@
|
|||||||
#define SET_UI_COLORS 'suic'
|
#define SET_UI_COLORS 'suic'
|
||||||
#define PREFS_CHOSEN 'prch'
|
#define PREFS_CHOSEN 'prch'
|
||||||
|
|
||||||
|
// constants
|
||||||
|
static const char* const kRGBColor = "RGBColor";
|
||||||
|
static const char* const kWhich = "which";
|
||||||
|
|
||||||
// user interface
|
// user interface
|
||||||
const uint32 kBorderSpace = 10;
|
const uint32 kBorderSpace = 10;
|
||||||
const uint32 kItemSpace = 7;
|
const uint32 kItemSpace = 7;
|
||||||
|
|||||||
Reference in New Issue
Block a user