Appearance and Terminal: Move ColorPreview to shared
Move ColorListView and ColorItem to shared in BPrivate namespace. ColorItem typedef to BPrivate::BColorItem for apps that are already using this class. Gravity screensaver: * ColorItem => BColorItem. * Use make_color() to set colors. Make color drop message name agnostic, check for B_RGB_COLOR_TYPE. Add be:sender and source to drag message. Add _SetTermColors() convenience method to set colors on all tabs. Change-Id: I5a9f55d3ab423ccaa341997cf444603373024553 Reviewed-on: https://review.haiku-os.org/c/haiku/+/8846 Reviewed-by: John Scipione <[email protected]>
This commit is contained in:
committed by
waddlesplash
parent
012d90c553
commit
622853ff8e
@@ -1,148 +0,0 @@
|
||||
/*
|
||||
* Copyright 2016-2022 Haiku, Inc. All rights reserved.
|
||||
* Distributed under the terms of the MIT License.
|
||||
*
|
||||
* Authors:
|
||||
* John Scipione, [email protected]
|
||||
*/
|
||||
|
||||
|
||||
#include "ColorListView.h"
|
||||
|
||||
#include <algorithm>
|
||||
|
||||
#include <math.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include <Bitmap.h>
|
||||
#include <String.h>
|
||||
|
||||
#include "ColorItem.h"
|
||||
#include "ThemeView.h"
|
||||
|
||||
|
||||
// golden ratio
|
||||
#ifdef M_PHI
|
||||
# undef M_PHI
|
||||
#endif
|
||||
#define M_PHI 1.61803398874989484820
|
||||
|
||||
|
||||
// #pragma mark - ColorListView
|
||||
|
||||
|
||||
ColorListView::ColorListView(const char* name,
|
||||
list_view_type type, uint32 flags)
|
||||
:
|
||||
BListView(name, type, flags)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
ColorListView::~ColorListView()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
bool
|
||||
ColorListView::InitiateDrag(BPoint where, int32 index, bool wasSelected)
|
||||
{
|
||||
ColorItem* colorItem
|
||||
= dynamic_cast<ColorItem*>(ItemAt(index));
|
||||
if (colorItem == NULL)
|
||||
return false;
|
||||
|
||||
rgb_color color = colorItem->Color();
|
||||
|
||||
BString hexStr;
|
||||
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(kRGBColor, B_RGB_COLOR_TYPE, &color, sizeof(color));
|
||||
|
||||
float itemHeight = colorItem->Height() - 5;
|
||||
BRect rect(0.0f, 0.0f, roundf(itemHeight * M_PHI) - 1, itemHeight - 1);
|
||||
|
||||
BBitmap* bitmap = new BBitmap(rect, B_RGB32, true);
|
||||
if (bitmap->Lock()) {
|
||||
BView* view = new BView(rect, "", B_FOLLOW_NONE, B_WILL_DRAW);
|
||||
bitmap->AddChild(view);
|
||||
|
||||
view->SetHighColor(B_TRANSPARENT_COLOR);
|
||||
view->FillRect(view->Bounds());
|
||||
|
||||
++rect.top;
|
||||
++rect.left;
|
||||
|
||||
view->SetHighColor(0, 0, 0, 100);
|
||||
view->FillRect(rect);
|
||||
rect.OffsetBy(-1.0f, -1.0f);
|
||||
|
||||
view->SetHighColor(std::min(255, (int)(1.2 * color.red + 40)),
|
||||
std::min(255, (int)(1.2 * color.green + 40)),
|
||||
std::min(255, (int)(1.2 * color.blue + 40)));
|
||||
view->StrokeRect(rect);
|
||||
|
||||
++rect.left;
|
||||
++rect.top;
|
||||
|
||||
view->SetHighColor((int32)(0.8 * color.red),
|
||||
(int32)(0.8 * color.green),
|
||||
(int32)(0.8 * color.blue));
|
||||
view->StrokeRect(rect);
|
||||
|
||||
--rect.right;
|
||||
--rect.bottom;
|
||||
|
||||
view->SetHighColor(color.red, color.green, color.blue);
|
||||
view->FillRect(rect);
|
||||
view->Sync();
|
||||
|
||||
bitmap->Unlock();
|
||||
}
|
||||
|
||||
DragMessage(&message, bitmap, B_OP_ALPHA, BPoint(14.0f, 14.0f));
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
ColorListView::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);
|
||||
ColorItem* item = dynamic_cast<ColorItem*>(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 ThemeView
|
||||
uint32 command = index == CurrentSelection()
|
||||
? MSG_SET_CURRENT_COLOR : MSG_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 == MSG_SET_COLOR)
|
||||
setColorMessage.AddString(kName, item->Text());
|
||||
|
||||
// build messenger and send message
|
||||
BMessenger messenger = BMessenger(Parent());
|
||||
if (messenger.IsValid()) {
|
||||
messenger.SendMessage(&setColorMessage);
|
||||
if (command == MSG_SET_COLOR) {
|
||||
// redraw item, MSG_SET_CURRENT_COLOR does this for us
|
||||
item->SetColor(*color);
|
||||
InvalidateItem(index);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
BListView::MessageReceived(message);
|
||||
}
|
||||
@@ -1,31 +0,0 @@
|
||||
/*
|
||||
* Copyright 2016-2022 Haiku, Inc. All rights reserved.
|
||||
* Distributed under the terms of the MIT License.
|
||||
*
|
||||
* Authors:
|
||||
* John Scipione, [email protected]
|
||||
*/
|
||||
#ifndef COLORWHICH_LIST_VIEW_H
|
||||
#define COLORWHICH_LIST_VIEW_H
|
||||
|
||||
|
||||
#include <ListView.h>
|
||||
|
||||
|
||||
class ColorListView : public BListView
|
||||
{
|
||||
public:
|
||||
ColorListView(const char* name,
|
||||
list_view_type type
|
||||
= B_SINGLE_SELECTION_LIST,
|
||||
uint32 flags = B_WILL_DRAW
|
||||
| B_FRAME_EVENTS | B_NAVIGABLE);
|
||||
virtual ~ColorListView();
|
||||
|
||||
virtual bool InitiateDrag(BPoint where, int32 index,
|
||||
bool wasSelected);
|
||||
virtual void MessageReceived(BMessage* message);
|
||||
};
|
||||
|
||||
|
||||
#endif // COLORWHICH_LIST_VIEW_H
|
||||
@@ -1,284 +0,0 @@
|
||||
/*
|
||||
* Copyright 2002-2022 Haiku, Inc. All rights reserved.
|
||||
* Distributed under the terms of the MIT License.
|
||||
*
|
||||
* Authors:
|
||||
* DarkWyrm, [email protected]
|
||||
* John Scipione, [email protected]
|
||||
*/
|
||||
|
||||
|
||||
#include "ColorPreview.h"
|
||||
|
||||
#include <algorithm>
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
#include <Bitmap.h>
|
||||
#include <Message.h>
|
||||
#include <MessageRunner.h>
|
||||
#include <String.h>
|
||||
#include <View.h>
|
||||
#include <Window.h>
|
||||
|
||||
#include "ThemeView.h"
|
||||
#include "TermConst.h"
|
||||
|
||||
|
||||
static const int32 kMsgMessageRunner = 'MsgR';
|
||||
|
||||
|
||||
// #pragma mark - ColorPreview
|
||||
|
||||
|
||||
ColorPreview::ColorPreview(BMessage* message, uint32 flags)
|
||||
:
|
||||
BControl("ColorPreview", "", message, flags | B_WILL_DRAW),
|
||||
fColor(ui_color(B_PANEL_BACKGROUND_COLOR)),
|
||||
fDisabledColor((rgb_color){ 128, 128, 128 }),
|
||||
fMessageRunner(NULL),
|
||||
fIsRectangle(true)
|
||||
{
|
||||
SetViewColor(B_TRANSPARENT_COLOR);
|
||||
SetLowColor(0, 0, 0);
|
||||
SetExplicitSize(BSize(StringWidth("M") * 8, StringWidth("M") * 7));
|
||||
}
|
||||
|
||||
|
||||
ColorPreview::~ColorPreview(void)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
ColorPreview::Draw(BRect updateRect)
|
||||
{
|
||||
rgb_color color;
|
||||
if (IsEnabled())
|
||||
color = fColor;
|
||||
else
|
||||
color = fDisabledColor;
|
||||
|
||||
if (fIsRectangle) {
|
||||
if (IsEnabled()) {
|
||||
rgb_color background = ui_color(B_PANEL_BACKGROUND_COLOR);
|
||||
rgb_color shadow = tint_color(background, B_DARKEN_1_TINT);
|
||||
rgb_color darkShadow = tint_color(background, B_DARKEN_3_TINT);
|
||||
rgb_color light = tint_color(background, B_LIGHTEN_MAX_TINT);
|
||||
|
||||
BRect bounds(Bounds());
|
||||
|
||||
BeginLineArray(4);
|
||||
AddLine(BPoint(bounds.left, bounds.bottom),
|
||||
BPoint(bounds.left, bounds.top), shadow);
|
||||
AddLine(BPoint(bounds.left + 1.0, bounds.top),
|
||||
BPoint(bounds.right, bounds.top), shadow);
|
||||
AddLine(BPoint(bounds.right, bounds.top + 1.0),
|
||||
BPoint(bounds.right, bounds.bottom), light);
|
||||
AddLine(BPoint(bounds.right - 1.0, bounds.bottom),
|
||||
BPoint(bounds.left + 1.0, bounds.bottom), light);
|
||||
EndLineArray();
|
||||
bounds.InsetBy(1.0, 1.0);
|
||||
|
||||
BeginLineArray(4);
|
||||
AddLine(BPoint(bounds.left, bounds.bottom),
|
||||
BPoint(bounds.left, bounds.top), darkShadow);
|
||||
AddLine(BPoint(bounds.left + 1.0, bounds.top),
|
||||
BPoint(bounds.right, bounds.top), darkShadow);
|
||||
AddLine(BPoint(bounds.right, bounds.top + 1.0),
|
||||
BPoint(bounds.right, bounds.bottom), background);
|
||||
AddLine(BPoint(bounds.right - 1.0, bounds.bottom),
|
||||
BPoint(bounds.left + 1.0, bounds.bottom), background);
|
||||
EndLineArray();
|
||||
bounds.InsetBy(1.0, 1.0);
|
||||
|
||||
SetHighColor(color);
|
||||
FillRect(bounds);
|
||||
} else {
|
||||
SetHighColor(color);
|
||||
FillRect(Bounds());
|
||||
}
|
||||
} else {
|
||||
// fill background
|
||||
SetHighColor(ui_color(B_PANEL_BACKGROUND_COLOR));
|
||||
FillRect(updateRect);
|
||||
|
||||
SetHighColor(color);
|
||||
FillEllipse(Bounds());
|
||||
|
||||
if (IsEnabled())
|
||||
StrokeEllipse(Bounds(), B_SOLID_LOW);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
ColorPreview::MessageReceived(BMessage* message)
|
||||
{
|
||||
// If we received a dropped message, see if it contains color data
|
||||
if (message->WasDropped()) {
|
||||
rgb_color* color;
|
||||
ssize_t size;
|
||||
if (message->FindData(kRGBColor, B_RGB_COLOR_TYPE,
|
||||
(const void**)&color, &size) == B_OK) {
|
||||
BMessage setColorMessage(MSG_SET_CURRENT_COLOR);
|
||||
setColorMessage.AddData(kRGBColor, B_RGB_COLOR_TYPE, color,
|
||||
sizeof(rgb_color));
|
||||
Invoke(&setColorMessage);
|
||||
}
|
||||
} else if ((int32)message->what == kMsgMessageRunner) {
|
||||
BPoint where;
|
||||
uint32 buttons;
|
||||
GetMouse(&where, &buttons);
|
||||
|
||||
_DragColor(where);
|
||||
}
|
||||
|
||||
BControl::MessageReceived(message);
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
ColorPreview::MouseDown(BPoint where)
|
||||
{
|
||||
BWindow* window = Window();
|
||||
if (window != NULL)
|
||||
window->Activate();
|
||||
|
||||
fMessageRunner = new BMessageRunner(this, new BMessage(kMsgMessageRunner),
|
||||
300000, 1);
|
||||
|
||||
SetMouseEventMask(B_POINTER_EVENTS,
|
||||
B_SUSPEND_VIEW_FOCUS | B_LOCK_WINDOW_FOCUS);
|
||||
|
||||
BRect rect = Bounds().InsetByCopy(2.0f, 2.0f);
|
||||
rect.top = roundf(rect.bottom / 2.0f + 1);
|
||||
|
||||
if (rect.Contains(where)) {
|
||||
Invalidate();
|
||||
Invoke();
|
||||
}
|
||||
|
||||
BControl::MouseDown(where);
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
ColorPreview::MouseMoved(BPoint where, uint32 transit, const BMessage* message)
|
||||
{
|
||||
if (fMessageRunner != NULL)
|
||||
_DragColor(where);
|
||||
|
||||
BControl::MouseMoved(where, transit, message);
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
ColorPreview::MouseUp(BPoint where)
|
||||
{
|
||||
delete fMessageRunner;
|
||||
fMessageRunner = NULL;
|
||||
|
||||
BControl::MouseUp(where);
|
||||
}
|
||||
|
||||
|
||||
rgb_color
|
||||
ColorPreview::Color(void) const
|
||||
{
|
||||
return fColor;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
ColorPreview::SetColor(rgb_color color)
|
||||
{
|
||||
color.alpha = 255;
|
||||
|
||||
SetHighColor(color);
|
||||
fColor = color;
|
||||
|
||||
Invalidate();
|
||||
Invoke();
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
ColorPreview::SetColor(uint8 red, uint8 green, uint8 blue)
|
||||
{
|
||||
SetHighColor(red, green, blue);
|
||||
fColor.red = red;
|
||||
fColor.green = green;
|
||||
fColor.blue = blue;
|
||||
fColor.alpha = 255;
|
||||
|
||||
Invalidate();
|
||||
Invoke();
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
ColorPreview::SetMode(bool rectangle)
|
||||
{
|
||||
fIsRectangle = rectangle;
|
||||
}
|
||||
|
||||
|
||||
// #pragma mark - ColorPreview private methods
|
||||
|
||||
|
||||
void
|
||||
ColorPreview::_DragColor(BPoint where)
|
||||
{
|
||||
BString hexStr;
|
||||
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(kRGBColor, B_RGB_COLOR_TYPE, &fColor, sizeof(fColor));
|
||||
|
||||
BRect rect(0.0f, 0.0f, 20.0f, 20.0f);
|
||||
|
||||
BBitmap* bitmap = new BBitmap(rect, B_RGB32, true);
|
||||
if (bitmap->Lock()) {
|
||||
BView* view = new BView(rect, "", B_FOLLOW_NONE, B_WILL_DRAW);
|
||||
bitmap->AddChild(view);
|
||||
|
||||
view->SetHighColor(B_TRANSPARENT_COLOR);
|
||||
view->FillRect(view->Bounds());
|
||||
|
||||
++rect.top;
|
||||
++rect.left;
|
||||
|
||||
view->SetHighColor(0, 0, 0, 100);
|
||||
view->FillRect(rect);
|
||||
rect.OffsetBy(-1.0f, -1.0f);
|
||||
|
||||
view->SetHighColor(std::min(255, (int)(1.2 * fColor.red + 40)),
|
||||
std::min(255, (int)(1.2 * fColor.green + 40)),
|
||||
std::min(255, (int)(1.2 * fColor.blue + 40)));
|
||||
view->StrokeRect(rect);
|
||||
|
||||
++rect.left;
|
||||
++rect.top;
|
||||
|
||||
view->SetHighColor((int32)(0.8 * fColor.red),
|
||||
(int32)(0.8 * fColor.green),
|
||||
(int32)(0.8 * fColor.blue));
|
||||
view->StrokeRect(rect);
|
||||
|
||||
--rect.right;
|
||||
--rect.bottom;
|
||||
|
||||
view->SetHighColor(fColor.red, fColor.green, fColor.blue);
|
||||
view->FillRect(rect);
|
||||
view->Sync();
|
||||
|
||||
bitmap->Unlock();
|
||||
}
|
||||
|
||||
DragMessage(&message, bitmap, B_OP_ALPHA, BPoint(14.0f, 14.0f));
|
||||
|
||||
MouseUp(where);
|
||||
}
|
||||
@@ -1,51 +0,0 @@
|
||||
/*
|
||||
* Copyright 2002-2022 Haiku, Inc. All rights reserved.
|
||||
* Distributed under the terms of the MIT License.
|
||||
*
|
||||
* Authors:
|
||||
* DarkWyrm, [email protected]
|
||||
* John Scipione, [email protected]
|
||||
*/
|
||||
#ifndef COLOR_PREVIEW_H_
|
||||
#define COLOR_PREVIEW_H_
|
||||
|
||||
|
||||
#include <Control.h>
|
||||
|
||||
|
||||
class BMessage;
|
||||
class BMessageRunner;
|
||||
|
||||
|
||||
class ColorPreview : public BControl
|
||||
{
|
||||
public:
|
||||
ColorPreview(BMessage* message,
|
||||
uint32 flags = B_WILL_DRAW);
|
||||
~ColorPreview(void);
|
||||
|
||||
virtual void Draw(BRect updateRect);
|
||||
virtual void MessageReceived(BMessage* message);
|
||||
virtual void MouseDown(BPoint where);
|
||||
virtual void MouseMoved(BPoint where, uint32 transit,
|
||||
const BMessage* message);
|
||||
virtual void MouseUp(BPoint where);
|
||||
|
||||
rgb_color Color(void) const;
|
||||
void SetColor(rgb_color color);
|
||||
void SetColor(uint8 r, uint8 g, uint8 b);
|
||||
|
||||
void SetMode(bool rectangle);
|
||||
|
||||
private:
|
||||
void _DragColor(BPoint where);
|
||||
|
||||
rgb_color fColor;
|
||||
rgb_color fDisabledColor;
|
||||
|
||||
BMessageRunner* fMessageRunner;
|
||||
|
||||
bool fIsRectangle;
|
||||
};
|
||||
|
||||
#endif // COLOR_PREVIEW_H_
|
||||
@@ -11,8 +11,6 @@ Application Terminal :
|
||||
Arguments.cpp
|
||||
BasicTerminalBuffer.cpp
|
||||
Colors.cpp
|
||||
ColorListView.cpp
|
||||
ColorPreview.cpp
|
||||
FindWindow.cpp
|
||||
Globals.cpp
|
||||
HistoryBuffer.cpp
|
||||
|
||||
@@ -1641,14 +1641,6 @@ TermView::MessageReceived(BMessage *message)
|
||||
_DoFileDrop(ref);
|
||||
}
|
||||
return;
|
||||
#if 0
|
||||
} else if (message->FindData("RGBColor", B_RGB_COLOR_TYPE,
|
||||
(const void **)&color, &numBytes) == B_OK
|
||||
&& numBytes == sizeof(color)) {
|
||||
// TODO: handle color drop
|
||||
// maybe only on replicants ?
|
||||
return;
|
||||
#endif
|
||||
} else if (message->FindData("text/plain", B_MIME_TYPE,
|
||||
(const void **)&text, &numBytes) == B_OK) {
|
||||
_WritePTY(text, numBytes);
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2007-2022, Haiku, Inc. All rights reserved.
|
||||
* Copyright 2007-2025 Haiku, Inc. All rights reserved.
|
||||
* Copyright (c) 2004 Daniel Furrer <[email protected]>
|
||||
* Copyright (c) 2003-2004 Kian Duffy <[email protected]>
|
||||
* Copyright (C) 1998,99 Kazuho Okui and Takashi Murai.
|
||||
@@ -26,10 +26,11 @@
|
||||
#include <Alert.h>
|
||||
#include <Application.h>
|
||||
#include <Catalog.h>
|
||||
#include <ControlLook.h>
|
||||
#include <CharacterSet.h>
|
||||
#include <CharacterSetRoster.h>
|
||||
#include <Clipboard.h>
|
||||
#include <ColorListView.h>
|
||||
#include <ControlLook.h>
|
||||
#include <Dragger.h>
|
||||
#include <File.h>
|
||||
#include <FindDirectory.h>
|
||||
@@ -50,8 +51,8 @@
|
||||
#include <ScrollBar.h>
|
||||
#include <ScrollView.h>
|
||||
#include <String.h>
|
||||
#include <UnicodeChar.h>
|
||||
#include <UTF8.h>
|
||||
#include <UnicodeChar.h>
|
||||
|
||||
#include <AutoLocker.h>
|
||||
|
||||
@@ -706,6 +707,9 @@ TermWindow::MessageReceived(BMessage *message)
|
||||
int32 encodingId;
|
||||
bool findresult;
|
||||
|
||||
if (message->WasDropped())
|
||||
_SetTermColors();
|
||||
|
||||
switch (message->what) {
|
||||
case B_KEY_MAP_LOADED:
|
||||
_UpdateKeymap();
|
||||
@@ -1003,18 +1007,12 @@ TermWindow::MessageReceived(BMessage *message)
|
||||
break;
|
||||
|
||||
case MSG_COLOR_SCHEME_CHANGED:
|
||||
case MSG_SET_CURRENT_COLOR:
|
||||
case MSG_SET_COLOR:
|
||||
case BColorListView::B_MESSAGE_SET_CURRENT_COLOR:
|
||||
case BColorListView::B_MESSAGE_SET_COLOR:
|
||||
case MSG_UPDATE_COLOR:
|
||||
{
|
||||
for (int32 i = fTabView->CountTabs() - 1; i >= 0; i--) {
|
||||
TermViewContainerView* container = _TermViewContainerViewAt(i);
|
||||
_SetTermColors(container);
|
||||
container->Invalidate();
|
||||
}
|
||||
_ActiveTermView()->Invalidate();
|
||||
_SetTermColors();
|
||||
break;
|
||||
}
|
||||
|
||||
case MSG_SAVE_AS_DEFAULT:
|
||||
{
|
||||
BPath path;
|
||||
@@ -1220,6 +1218,19 @@ TermWindow::WindowActivated(bool activated)
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
TermWindow::_SetTermColors()
|
||||
{
|
||||
for (int32 index = fTabView->CountTabs() - 1; index >= 0; index--) {
|
||||
TermViewContainerView* container = _TermViewContainerViewAt(index);
|
||||
_SetTermColors(container);
|
||||
container->Invalidate();
|
||||
}
|
||||
|
||||
_ActiveTermView()->Invalidate();
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
TermWindow::_SetTermColors(TermViewContainerView* containerView)
|
||||
{
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2001-2010, Haiku.
|
||||
* Copyright 2001-2025 Haiku, Inc. All rights reserved
|
||||
* Copyright (c) 2003-4 Kian Duffy <[email protected]>
|
||||
* Parts Copyright (C) 1998,99 Kazuho Okui and Takashi Murai.
|
||||
*
|
||||
@@ -136,12 +136,11 @@ private:
|
||||
struct Session;
|
||||
|
||||
private:
|
||||
void _SetTermColors(
|
||||
TermViewContainerView* containerView);
|
||||
void _SetTermColors();
|
||||
void _SetTermColors(TermViewContainerView* containerView);
|
||||
void _InitWindow();
|
||||
void _SetupMenu();
|
||||
static BMenu* _MakeFontSizeMenu(uint32 command,
|
||||
uint8 defaultSize);
|
||||
static BMenu* _MakeFontSizeMenu(uint32 command, uint8 defaultSize);
|
||||
void _UpdateSwitchTerminalsMenuItem();
|
||||
|
||||
status_t _GetWindowPositionFile(BFile* file,
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2022 Haiku, Inc. All rights reserved.
|
||||
* Copyright 2022-2025 Haiku, Inc. All rights reserved.
|
||||
* Distributed under the terms of the MIT License.
|
||||
*/
|
||||
|
||||
@@ -10,6 +10,8 @@
|
||||
|
||||
#include <Alert.h>
|
||||
#include <Catalog.h>
|
||||
#include <ColorItem.h>
|
||||
#include <ColorListView.h>
|
||||
#include <Directory.h>
|
||||
#include <Entry.h>
|
||||
#include <File.h>
|
||||
@@ -23,19 +25,23 @@
|
||||
|
||||
#include "ThemeWindow.h"
|
||||
#include "Colors.h"
|
||||
#include "ColorPreview.h"
|
||||
#include "ColorListView.h"
|
||||
#include "ColorItem.h"
|
||||
#include "TermConst.h"
|
||||
#include "PrefHandler.h"
|
||||
|
||||
|
||||
#undef B_TRANSLATION_CONTEXT
|
||||
#define B_TRANSLATION_CONTEXT "Terminal ThemeView"
|
||||
|
||||
|
||||
#define COLOR_DROPPED 'cldp'
|
||||
#define DECORATOR_CHANGED 'dcch'
|
||||
|
||||
|
||||
using BPrivate::BColorItem;
|
||||
using BPrivate::BColorListView;
|
||||
using BPrivate::BColorPreview;
|
||||
|
||||
|
||||
/* static */ const char*
|
||||
ThemeView::kColorTable[] = {
|
||||
B_TRANSLATE_MARK("Text"),
|
||||
@@ -72,7 +78,7 @@ ThemeView::ThemeView(const char* name, const BMessenger& messenger)
|
||||
SetViewUIColor(B_PANEL_BACKGROUND_COLOR);
|
||||
|
||||
// Set up list of color attributes
|
||||
fAttrList = new ColorListView("AttributeList");
|
||||
fAttrList = new BColorListView("AttributeList");
|
||||
|
||||
fScrollView = new BScrollView("ScrollView", fAttrList, 0, false, true);
|
||||
fScrollView->SetViewUIColor(B_PANEL_BACKGROUND_COLOR);
|
||||
@@ -80,17 +86,14 @@ ThemeView::ThemeView(const char* name, const BMessenger& messenger)
|
||||
PrefHandler* prefHandler = PrefHandler::Default();
|
||||
|
||||
for (const char** table = kColorTable; *table != NULL; ++table) {
|
||||
fAttrList->AddItem(new ColorItem(B_TRANSLATE_NOCOLLECT(*table),
|
||||
prefHandler->getRGB(*table)));
|
||||
fAttrList->AddItem(
|
||||
new BColorItem(B_TRANSLATE_NOCOLLECT(*table), prefHandler->getRGB(*table)));
|
||||
}
|
||||
|
||||
fColorSchemeMenu = new BPopUpMenu("");
|
||||
fColorSchemeField = new BMenuField(B_TRANSLATE("Color scheme:"),
|
||||
fColorSchemeMenu);
|
||||
fColorSchemeField = new BMenuField(B_TRANSLATE("Color scheme:"), fColorSchemeMenu);
|
||||
|
||||
fColorPreview = new ColorPreview(new BMessage(COLOR_DROPPED), 0);
|
||||
fColorPreview->SetExplicitAlignment(BAlignment(B_ALIGN_HORIZONTAL_CENTER,
|
||||
B_ALIGN_VERTICAL_CENTER));
|
||||
fColorPreview = new BColorPreview("color preview", "", new BMessage(COLOR_DROPPED));
|
||||
|
||||
fPicker = new BColorControl(B_ORIGIN, B_CELLS_32x8, 8.0,
|
||||
"picker", new BMessage(MSG_UPDATE_COLOR));
|
||||
@@ -109,8 +112,7 @@ ThemeView::ThemeView(const char* name, const BMessenger& messenger)
|
||||
.AddGlue()
|
||||
.Add(fPicker);
|
||||
|
||||
fColorPreview->Parent()->SetExplicitMaxSize(
|
||||
BSize(B_SIZE_UNSET, fPicker->Bounds().Height()));
|
||||
fColorPreview->Parent()->SetExplicitMaxSize(BSize(B_SIZE_UNSET, fPicker->Bounds().Height()));
|
||||
fAttrList->SetSelectionMessage(new BMessage(MSG_COLOR_ATTRIBUTE_CHOSEN));
|
||||
fScrollView->SetExplicitMinSize(BSize(B_SIZE_UNSET, 22 * 16));
|
||||
fColorSchemeField->SetAlignment(B_ALIGN_RIGHT);
|
||||
@@ -277,45 +279,48 @@ ThemeView::UpdateMenu()
|
||||
|
||||
|
||||
void
|
||||
ThemeView::MessageReceived(BMessage *msg)
|
||||
ThemeView::MessageReceived(BMessage* message)
|
||||
{
|
||||
bool modified = false;
|
||||
|
||||
switch (msg->what) {
|
||||
if (message->WasDropped()) {
|
||||
char* name;
|
||||
type_code type;
|
||||
rgb_color* color;
|
||||
ssize_t size;
|
||||
if (message->GetInfo(B_RGB_COLOR_TYPE, 0, &name, &type) == B_OK
|
||||
&& message->FindData(name, type, (const void**)&color, &size) == B_OK) {
|
||||
_SetCurrentColor(*color);
|
||||
modified = true;
|
||||
}
|
||||
}
|
||||
|
||||
switch (message->what) {
|
||||
case MSG_COLOR_SCHEME_CHANGED:
|
||||
{
|
||||
color_scheme* newScheme = NULL;
|
||||
if (msg->FindPointer("color_scheme",
|
||||
(void**)&newScheme) == B_OK) {
|
||||
if (message->FindPointer("color_scheme", (void**)&newScheme) == B_OK) {
|
||||
_ChangeColorScheme(newScheme);
|
||||
modified = true;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
case MSG_SET_COLOR:
|
||||
case BColorListView::B_MESSAGE_SET_CURRENT_COLOR:
|
||||
case BColorListView::B_MESSAGE_SET_COLOR:
|
||||
{
|
||||
// Received from color list view when color changes
|
||||
char* name;
|
||||
type_code type;
|
||||
rgb_color* color;
|
||||
ssize_t size;
|
||||
const char* name;
|
||||
|
||||
if (msg->FindData(kRGBColor, B_RGB_COLOR_TYPE,
|
||||
(const void**)&color, &size) == B_OK
|
||||
&& msg->FindString(kName, &name) == B_OK) {
|
||||
_SetColor(name, *color);
|
||||
modified = true;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
case MSG_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);
|
||||
if (message->GetInfo(B_RGB_COLOR_TYPE, 0, &name, &type) == B_OK
|
||||
&& message->FindData(name, type, (const void**)&color, &size) == B_OK) {
|
||||
bool current = message->GetBool("current", false);
|
||||
if (current)
|
||||
_SetCurrentColor(*color);
|
||||
else
|
||||
_SetColor(name, *color);
|
||||
modified = true;
|
||||
}
|
||||
break;
|
||||
@@ -345,17 +350,17 @@ ThemeView::MessageReceived(BMessage *msg)
|
||||
|
||||
case MSG_THEME_MODIFIED:
|
||||
_SetCurrentColorScheme();
|
||||
BView::MessageReceived(msg);
|
||||
BView::MessageReceived(message);
|
||||
return;
|
||||
|
||||
default:
|
||||
BView::MessageReceived(msg);
|
||||
BView::MessageReceived(message);
|
||||
break;
|
||||
}
|
||||
|
||||
if (modified) {
|
||||
_UpdateStyle();
|
||||
fTerminalMessenger.SendMessage(msg);
|
||||
fTerminalMessenger.SendMessage(message);
|
||||
|
||||
BMessenger messenger(this);
|
||||
messenger.SendMessage(MSG_THEME_MODIFIED);
|
||||
@@ -370,13 +375,13 @@ ThemeView::SetDefaults()
|
||||
|
||||
int32 count = fAttrList->CountItems();
|
||||
for (int32 index = 0; index < count; ++index) {
|
||||
ColorItem* item = (ColorItem*)fAttrList->ItemAt(index);
|
||||
BColorItem* item = static_cast<BColorItem*>(fAttrList->ItemAt(index));
|
||||
item->SetColor(prefHandler->getRGB(kColorTable[index]));
|
||||
fAttrList->InvalidateItem(index);
|
||||
}
|
||||
|
||||
int32 currentIndex = fAttrList->CurrentSelection();
|
||||
ColorItem* item = (ColorItem*)fAttrList->ItemAt(currentIndex);
|
||||
BColorItem* item = static_cast<BColorItem*>(fAttrList->ItemAt(currentIndex));
|
||||
if (item != NULL) {
|
||||
rgb_color color = item->Color();
|
||||
fPicker->SetValue(color);
|
||||
@@ -430,7 +435,7 @@ ThemeView::_ChangeColorScheme(color_scheme* scheme)
|
||||
|
||||
int32 count = fAttrList->CountItems();
|
||||
for (int32 index = 0; index < count; ++index) {
|
||||
ColorItem* item = static_cast<ColorItem*>(fAttrList->ItemAt(index));
|
||||
BColorItem* item = static_cast<BColorItem*>(fAttrList->ItemAt(index));
|
||||
rgb_color color = pref->getRGB(kColorTable[index]);
|
||||
item->SetColor(color);
|
||||
|
||||
@@ -526,7 +531,7 @@ void
|
||||
ThemeView::_SetCurrentColor(rgb_color color)
|
||||
{
|
||||
int32 currentIndex = fAttrList->CurrentSelection();
|
||||
ColorItem* item = (ColorItem*)fAttrList->ItemAt(currentIndex);
|
||||
BColorItem* item = static_cast<BColorItem*>(fAttrList->ItemAt(currentIndex));
|
||||
if (item != NULL) {
|
||||
item->SetColor(color);
|
||||
fAttrList->InvalidateItem(currentIndex);
|
||||
@@ -536,7 +541,6 @@ ThemeView::_SetCurrentColor(rgb_color color)
|
||||
|
||||
fPicker->SetValue(color);
|
||||
fColorPreview->SetColor(color);
|
||||
fColorPreview->Invalidate();
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2022, Haiku. All rights reserved.
|
||||
* Copyright 2022-2025 Haiku, Inc. All rights reserved.
|
||||
* Distributed under the terms of the MIT License.
|
||||
*/
|
||||
#ifndef THEME_VIEW_H
|
||||
@@ -8,6 +8,7 @@
|
||||
|
||||
#include <Button.h>
|
||||
#include <ColorControl.h>
|
||||
#include <ColorPreview.h>
|
||||
#include <GroupView.h>
|
||||
#include <ListItem.h>
|
||||
#include <ListView.h>
|
||||
@@ -27,18 +28,17 @@
|
||||
#include "Colors.h"
|
||||
|
||||
|
||||
using BPrivate::BColorPreview;
|
||||
|
||||
|
||||
static const uint32 MSG_COLOR_SCHEME_CHANGED = 'mccs';
|
||||
static const uint32 MSG_SET_CURRENT_COLOR = 'sccl';
|
||||
static const uint32 MSG_UPDATE_COLOR = 'upcl';
|
||||
static const uint32 MSG_COLOR_ATTRIBUTE_CHOSEN = 'atch';
|
||||
static const uint32 MSG_THEME_MODIFIED = 'tmdf';
|
||||
static const uint32 MSG_SET_COLOR = 'sclr';
|
||||
|
||||
static const char* const kRGBColor = "RGBColor";
|
||||
static const char* const kName = "name";
|
||||
|
||||
class ThemeWindow;
|
||||
class ColorPreview;
|
||||
class BColorPreview;
|
||||
class BMenu;
|
||||
class BMenuField;
|
||||
class BPopUpMenu;
|
||||
@@ -73,7 +73,7 @@ private:
|
||||
BListView* fAttrList;
|
||||
const char* fName;
|
||||
BScrollView* fScrollView;
|
||||
ColorPreview* fColorPreview;
|
||||
BColorPreview* fColorPreview;
|
||||
BMenuField* fColorSchemeField;
|
||||
BPopUpMenu* fColorSchemeMenu;
|
||||
BTextView* fPreview;
|
||||
|
||||
Reference in New Issue
Block a user