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:
parent
5d898e77d2
commit
e88a89e676
|
@ -130,19 +130,35 @@ APRView::AttachedToWindow()
|
|||
void
|
||||
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);
|
||||
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;
|
||||
}
|
||||
|
||||
switch (msg->what) {
|
||||
case UPDATE_COLOR:
|
||||
{
|
||||
// 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
|
||||
APRView::_SetCurrentColor(rgb_color color)
|
||||
{
|
||||
set_ui_color(fWhich, color);
|
||||
fCurrentColors.SetColor(ui_color_name(fWhich), color);
|
||||
_SetColor(fWhich, color);
|
||||
|
||||
int32 currentIndex = fAttrList->CurrentSelection();
|
||||
ColorWhichItem* item = (ColorWhichItem*)fAttrList->ItemAt(currentIndex);
|
||||
|
|
|
@ -50,6 +50,7 @@ public:
|
|||
bool IsRevertable();
|
||||
|
||||
private:
|
||||
void _SetColor(color_which which, rgb_color color);
|
||||
void _SetCurrentColor(rgb_color color);
|
||||
void _SetUIColors(const BMessage& colors);
|
||||
void _UpdatePreviews(const BMessage& colors);
|
||||
|
|
|
@ -21,6 +21,8 @@
|
|||
#include <View.h>
|
||||
#include <Window.h>
|
||||
|
||||
#include "defs.h"
|
||||
|
||||
|
||||
|
||||
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 (message->WasDropped()) {
|
||||
rgb_color* col;
|
||||
uint8* ptr;
|
||||
rgb_color* color;
|
||||
ssize_t size;
|
||||
if (message->FindData("RGBColor", (type_code)'RGBC',
|
||||
(const void**)&ptr,&size) == B_OK) {
|
||||
col = (rgb_color*)ptr;
|
||||
SetHighColor(*col);
|
||||
if (message->FindData(kRGBColor, B_RGB_COLOR_TYPE,
|
||||
(const void**)&color, &size) == B_OK) {
|
||||
BMessage setColorMessage(SET_CURRENT_COLOR);
|
||||
setColorMessage.AddData(kRGBColor, B_RGB_COLOR_TYPE, color,
|
||||
sizeof(color));
|
||||
Invoke(&setColorMessage);
|
||||
}
|
||||
} else if ((int32)message->what == kMsgMessageRunner) {
|
||||
BPoint where;
|
||||
|
@ -232,8 +235,9 @@ ColorPreview::_DragColor(BPoint where)
|
|||
hexStr.SetToFormat("#%.2X%.2X%.2X", fColor.red, fColor.green, fColor.blue);
|
||||
|
||||
BMessage message(B_PASTE);
|
||||
message.AddData("text/plain", B_MIME_TYPE, hexStr.String(), hexStr.Length());
|
||||
message.AddData("RGBColor", B_RGB_COLOR_TYPE, &fColor, sizeof(fColor));
|
||||
message.AddData("text/plain", B_MIME_TYPE, hexStr.String(),
|
||||
hexStr.Length());
|
||||
message.AddData(kRGBColor, B_RGB_COLOR_TYPE, &fColor, sizeof(fColor));
|
||||
|
||||
BRect rect(0.0f, 0.0f, 20.0f, 20.0f);
|
||||
|
||||
|
|
|
@ -18,6 +18,7 @@
|
|||
#include <String.h>
|
||||
|
||||
#include "ColorWhichItem.h"
|
||||
#include "defs.h"
|
||||
|
||||
|
||||
// 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);
|
||||
|
||||
BMessage message(B_PASTE);
|
||||
message.AddData("text/plain", B_MIME_TYPE, hexStr.String(), hexStr.Length());
|
||||
message.AddData("RGBColor", B_RGB_COLOR_TYPE, &color, sizeof(color));
|
||||
message.AddData("text/plain", B_MIME_TYPE, hexStr.String(),
|
||||
hexStr.Length());
|
||||
message.AddData(kRGBColor, B_RGB_COLOR_TYPE, &color, sizeof(color));
|
||||
|
||||
float itemHeight = colorWhichItem->Height() - 5;
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
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,
|
||||
bool wasSelected);
|
||||
virtual void MessageReceived(BMessage* message);
|
||||
};
|
||||
|
||||
|
||||
#endif // COLORWHICH_LIST_VIEW_H
|
||||
|
|
|
@ -19,10 +19,13 @@
|
|||
|
||||
#define APPEARANCE_APP_SIGNATURE "application/x-vnd.Haiku-Appearance"
|
||||
|
||||
// message commands
|
||||
#define APPLY_SETTINGS 'aply'
|
||||
#define TRY_SETTINGS 'trys'
|
||||
|
||||
#define ATTRIBUTE_CHOSEN 'atch'
|
||||
#define SET_COLOR 'sclr'
|
||||
#define SET_CURRENT_COLOR 'sccl'
|
||||
#define UPDATE_COLOR 'upcl'
|
||||
#define DECORATOR_CHOSEN 'dcch'
|
||||
#define UPDATE_DECORATOR 'updc'
|
||||
|
@ -34,6 +37,10 @@
|
|||
#define SET_UI_COLORS 'suic'
|
||||
#define PREFS_CHOSEN 'prch'
|
||||
|
||||
// constants
|
||||
static const char* const kRGBColor = "RGBColor";
|
||||
static const char* const kWhich = "which";
|
||||
|
||||
// user interface
|
||||
const uint32 kBorderSpace = 10;
|
||||
const uint32 kItemSpace = 7;
|
||||
|
|
Loading…
Reference in New Issue