* Style cleanup.
git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@41347 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -1,21 +1,19 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2006-2009, Haiku, Inc. All rights reserved.
|
* Copyright 2006-2011, Haiku, Inc. All rights reserved.
|
||||||
* Distributed under the terms of the MIT License.
|
* Distributed under the terms of the MIT License.
|
||||||
*
|
*
|
||||||
* Authors:
|
* Authors:
|
||||||
* Stephan Aßmus <[email protected]>
|
* Stephan Aßmus <[email protected]>
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
#include "StyleView.h"
|
#include "StyleView.h"
|
||||||
|
|
||||||
#include <new>
|
#include <new>
|
||||||
|
|
||||||
#if __HAIKU__
|
|
||||||
# include "GridLayout.h"
|
|
||||||
# include "GroupLayout.h"
|
|
||||||
# include "SpaceLayoutItem.h"
|
|
||||||
#endif
|
|
||||||
#include <Catalog.h>
|
#include <Catalog.h>
|
||||||
|
#include <GridLayout.h>
|
||||||
|
#include <GroupLayout.h>
|
||||||
#include <Locale.h>
|
#include <Locale.h>
|
||||||
#include <Menu.h>
|
#include <Menu.h>
|
||||||
#include <MenuBar.h>
|
#include <MenuBar.h>
|
||||||
@@ -23,6 +21,7 @@
|
|||||||
#include <MenuItem.h>
|
#include <MenuItem.h>
|
||||||
#include <Message.h>
|
#include <Message.h>
|
||||||
#include <PopUpMenu.h>
|
#include <PopUpMenu.h>
|
||||||
|
#include <SpaceLayoutItem.h>
|
||||||
#include <Window.h>
|
#include <Window.h>
|
||||||
|
|
||||||
#include "CommandStack.h"
|
#include "CommandStack.h"
|
||||||
@@ -52,14 +51,10 @@ enum {
|
|||||||
STYLE_TYPE_GRADIENT,
|
STYLE_TYPE_GRADIENT,
|
||||||
};
|
};
|
||||||
|
|
||||||
// constructor
|
|
||||||
StyleView::StyleView(BRect frame)
|
StyleView::StyleView(BRect frame)
|
||||||
:
|
:
|
||||||
#ifdef __HAIKU__
|
|
||||||
BView("style view", 0),
|
BView("style view", 0),
|
||||||
#else
|
|
||||||
BView(frame, "style view", B_FOLLOW_LEFT | B_FOLLOW_TOP, B_FRAME_EVENTS),
|
|
||||||
#endif
|
|
||||||
fCommandStack(NULL),
|
fCommandStack(NULL),
|
||||||
fCurrentColor(NULL),
|
fCurrentColor(NULL),
|
||||||
fStyle(NULL),
|
fStyle(NULL),
|
||||||
@@ -79,29 +74,10 @@ StyleView::StyleView(BRect frame)
|
|||||||
message->AddInt32("type", STYLE_TYPE_GRADIENT);
|
message->AddInt32("type", STYLE_TYPE_GRADIENT);
|
||||||
menu->AddItem(new BMenuItem(B_TRANSLATE("Gradient"), message));
|
menu->AddItem(new BMenuItem(B_TRANSLATE("Gradient"), message));
|
||||||
|
|
||||||
#ifdef __HAIKU__
|
|
||||||
BGridLayout* layout = new BGridLayout(5, 5);
|
BGridLayout* layout = new BGridLayout(5, 5);
|
||||||
SetLayout(layout);
|
SetLayout(layout);
|
||||||
|
|
||||||
fStyleType = new BMenuField(B_TRANSLATE("Style type"), menu, NULL);
|
fStyleType = new BMenuField(B_TRANSLATE("Style type"), menu);
|
||||||
|
|
||||||
#else
|
|
||||||
frame.OffsetTo(B_ORIGIN);
|
|
||||||
frame.InsetBy(5, 5);
|
|
||||||
frame.bottom = frame.top + 15;
|
|
||||||
|
|
||||||
fStyleType = new BMenuField(frame, "style type", B_TRANSLATE("Style type"),
|
|
||||||
menu, true);
|
|
||||||
AddChild(fStyleType);
|
|
||||||
|
|
||||||
float width;
|
|
||||||
float height;
|
|
||||||
fStyleType->MenuBar()->GetPreferredSize(&width, &height);
|
|
||||||
fStyleType->MenuBar()->ResizeTo(width, height);
|
|
||||||
fStyleType->ResizeTo(frame.Width(), height + 6);
|
|
||||||
fStyleType->SetResizingMode(B_FOLLOW_TOP | B_FOLLOW_LEFT_RIGHT);
|
|
||||||
fStyleType->MenuBar()->SetResizingMode(B_FOLLOW_TOP | B_FOLLOW_LEFT_RIGHT);
|
|
||||||
#endif // __HAIKU__
|
|
||||||
|
|
||||||
// gradient type
|
// gradient type
|
||||||
menu = new BPopUpMenu(B_TRANSLATE("<unavailable>"));
|
menu = new BPopUpMenu(B_TRANSLATE("<unavailable>"));
|
||||||
@@ -118,8 +94,7 @@ StyleView::StyleView(BRect frame)
|
|||||||
message->AddInt32("type", GRADIENT_CONIC);
|
message->AddInt32("type", GRADIENT_CONIC);
|
||||||
menu->AddItem(new BMenuItem(B_TRANSLATE("Conic"), message));
|
menu->AddItem(new BMenuItem(B_TRANSLATE("Conic"), message));
|
||||||
|
|
||||||
#if __HAIKU__
|
fGradientType = new BMenuField(B_TRANSLATE("Gradient type"), menu);
|
||||||
fGradientType = new BMenuField(B_TRANSLATE("Gradient type"), menu, NULL);
|
|
||||||
fGradientControl = new GradientControl(new BMessage(MSG_SET_COLOR), this);
|
fGradientControl = new GradientControl(new BMessage(MSG_SET_COLOR), this);
|
||||||
|
|
||||||
layout->AddItem(BSpaceLayoutItem::CreateVerticalStrut(3), 0, 0, 4);
|
layout->AddItem(BSpaceLayoutItem::CreateVerticalStrut(3), 0, 0, 4);
|
||||||
@@ -136,49 +111,13 @@ StyleView::StyleView(BRect frame)
|
|||||||
layout->AddItem(BSpaceLayoutItem::CreateHorizontalStrut(3), 3, 1, 1, 3);
|
layout->AddItem(BSpaceLayoutItem::CreateHorizontalStrut(3), 3, 1, 1, 3);
|
||||||
layout->AddItem(BSpaceLayoutItem::CreateVerticalStrut(3), 0, 4, 4);
|
layout->AddItem(BSpaceLayoutItem::CreateVerticalStrut(3), 0, 4, 4);
|
||||||
|
|
||||||
#else // !__HAIKU__
|
|
||||||
frame.OffsetBy(0, fStyleType->Frame().Height() + 6);
|
|
||||||
fGradientType = new BMenuField(frame, "gradient type",
|
|
||||||
B_TRANSLATE("Gradient type"), menu, true);
|
|
||||||
AddChild(fGradientType);
|
|
||||||
|
|
||||||
fGradientType->MenuBar()->GetPreferredSize(&width, &height);
|
|
||||||
fGradientType->MenuBar()->ResizeTo(width, height);
|
|
||||||
fGradientType->ResizeTo(frame.Width(), height + 6);
|
|
||||||
fGradientType->SetResizingMode(B_FOLLOW_TOP | B_FOLLOW_LEFT_RIGHT);
|
|
||||||
fGradientType->MenuBar()->SetResizingMode(B_FOLLOW_TOP | B_FOLLOW_LEFT_RIGHT);
|
|
||||||
|
|
||||||
// create gradient control
|
|
||||||
frame.top = fGradientType->Frame().bottom + 8;
|
|
||||||
frame.right = Bounds().right - 5;
|
|
||||||
fGradientControl = new GradientControl(new BMessage(MSG_SET_COLOR),
|
|
||||||
this);
|
|
||||||
|
|
||||||
width = frame.Width();
|
|
||||||
height = max_c(fGradientControl->Frame().Height(), 30);
|
|
||||||
|
|
||||||
fGradientControl->ResizeTo(width, height);
|
|
||||||
fGradientControl->FrameResized(width, height);
|
|
||||||
fGradientControl->MoveTo(frame.left, frame.top);
|
|
||||||
fGradientControl->SetResizingMode(B_FOLLOW_TOP | B_FOLLOW_LEFT_RIGHT);
|
|
||||||
|
|
||||||
AddChild(fGradientControl);
|
|
||||||
|
|
||||||
// align label divider
|
|
||||||
float divider = fGradientType->StringWidth(fGradientType->Label());
|
|
||||||
divider = max_c(divider, fStyleType->StringWidth(fStyleType->Label()));
|
|
||||||
fGradientType->SetDivider(divider + 8);
|
|
||||||
fStyleType->SetDivider(divider + 8);
|
|
||||||
|
|
||||||
#endif // __HAIKU__
|
|
||||||
|
|
||||||
fStyleType->SetEnabled(false);
|
fStyleType->SetEnabled(false);
|
||||||
fGradientType->SetEnabled(false);
|
fGradientType->SetEnabled(false);
|
||||||
fGradientControl->SetEnabled(false);
|
fGradientControl->SetEnabled(false);
|
||||||
fGradientControl->Gradient()->AddObserver(this);
|
fGradientControl->Gradient()->AddObserver(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
// destructor
|
|
||||||
StyleView::~StyleView()
|
StyleView::~StyleView()
|
||||||
{
|
{
|
||||||
SetStyle(NULL);
|
SetStyle(NULL);
|
||||||
@@ -186,7 +125,7 @@ StyleView::~StyleView()
|
|||||||
fGradientControl->Gradient()->RemoveObserver(this);
|
fGradientControl->Gradient()->RemoveObserver(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
// AttachedToWindow
|
|
||||||
void
|
void
|
||||||
StyleView::AttachedToWindow()
|
StyleView::AttachedToWindow()
|
||||||
{
|
{
|
||||||
@@ -194,37 +133,27 @@ StyleView::AttachedToWindow()
|
|||||||
fGradientType->Menu()->SetTargetForItems(this);
|
fGradientType->Menu()->SetTargetForItems(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
// FrameResized
|
|
||||||
void
|
void
|
||||||
StyleView::FrameResized(float width, float height)
|
StyleView::FrameResized(float width, float height)
|
||||||
{
|
{
|
||||||
BRect bounds = Bounds();
|
fPreviousBounds = Bounds();
|
||||||
|
|
||||||
#ifndef __HAIKU__
|
|
||||||
// Grrr, babysit the menubars...
|
|
||||||
BRect dirty = bounds;
|
|
||||||
dirty.left = min_c(bounds.right, fPreviousBounds.right) - 25;
|
|
||||||
fStyleType->ConvertFromParent(&dirty);
|
|
||||||
fStyleType->MenuBar()->ConvertFromParent(&dirty);
|
|
||||||
fStyleType->MenuBar()->Invalidate(dirty);
|
|
||||||
fGradientType->MenuBar()->Invalidate(dirty);
|
|
||||||
#endif // !__HAIKU__
|
|
||||||
|
|
||||||
fPreviousBounds = bounds;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// MessageReceived
|
|
||||||
void
|
void
|
||||||
StyleView::MessageReceived(BMessage* message)
|
StyleView::MessageReceived(BMessage* message)
|
||||||
{
|
{
|
||||||
switch (message->what) {
|
switch (message->what) {
|
||||||
case MSG_SET_STYLE_TYPE: {
|
case MSG_SET_STYLE_TYPE:
|
||||||
|
{
|
||||||
int32 type;
|
int32 type;
|
||||||
if (message->FindInt32("type", &type) == B_OK)
|
if (message->FindInt32("type", &type) == B_OK)
|
||||||
_SetStyleType(type);
|
_SetStyleType(type);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case MSG_SET_GRADIENT_TYPE: {
|
case MSG_SET_GRADIENT_TYPE:
|
||||||
|
{
|
||||||
int32 type;
|
int32 type;
|
||||||
if (message->FindInt32("type", &type) == B_OK)
|
if (message->FindInt32("type", &type) == B_OK)
|
||||||
_SetGradientType(type);
|
_SetGradientType(type);
|
||||||
@@ -241,9 +170,7 @@ StyleView::MessageReceived(BMessage* message)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#if __HAIKU__
|
|
||||||
|
|
||||||
// MinSize
|
|
||||||
BSize
|
BSize
|
||||||
StyleView::MinSize()
|
StyleView::MinSize()
|
||||||
{
|
{
|
||||||
@@ -252,11 +179,10 @@ StyleView::MinSize()
|
|||||||
return minSize;
|
return minSize;
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif // __HAIKU__
|
|
||||||
|
|
||||||
// #pragma mark -
|
// #pragma mark -
|
||||||
|
|
||||||
// ObjectChanged
|
|
||||||
void
|
void
|
||||||
StyleView::ObjectChanged(const Observable* object)
|
StyleView::ObjectChanged(const Observable* object)
|
||||||
{
|
{
|
||||||
@@ -316,9 +242,10 @@ StyleView::ObjectChanged(const Observable* object)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// #pragma mark -
|
// #pragma mark -
|
||||||
|
|
||||||
// StyleView
|
|
||||||
void
|
void
|
||||||
StyleView::SetStyle(Style* style)
|
StyleView::SetStyle(Style* style)
|
||||||
{
|
{
|
||||||
@@ -348,14 +275,14 @@ StyleView::SetStyle(Style* style)
|
|||||||
_SetGradient(gradient, true);
|
_SetGradient(gradient, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
// SetCommandStack
|
|
||||||
void
|
void
|
||||||
StyleView::SetCommandStack(CommandStack* stack)
|
StyleView::SetCommandStack(CommandStack* stack)
|
||||||
{
|
{
|
||||||
fCommandStack = stack;
|
fCommandStack = stack;
|
||||||
}
|
}
|
||||||
|
|
||||||
// SetCurrentColor
|
|
||||||
void
|
void
|
||||||
StyleView::SetCurrentColor(CurrentColor* color)
|
StyleView::SetCurrentColor(CurrentColor* color)
|
||||||
{
|
{
|
||||||
@@ -371,11 +298,13 @@ StyleView::SetCurrentColor(CurrentColor* color)
|
|||||||
fCurrentColor->AddObserver(this);
|
fCurrentColor->AddObserver(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// #pragma mark -
|
// #pragma mark -
|
||||||
|
|
||||||
// _SetGradient
|
|
||||||
void
|
void
|
||||||
StyleView::_SetGradient(Gradient* gradient, bool forceControlUpdate, bool sendMessage)
|
StyleView::_SetGradient(Gradient* gradient, bool forceControlUpdate,
|
||||||
|
bool sendMessage)
|
||||||
{
|
{
|
||||||
if (!forceControlUpdate && fGradient == gradient)
|
if (!forceControlUpdate && fGradient == gradient)
|
||||||
return;
|
return;
|
||||||
@@ -408,7 +337,7 @@ StyleView::_SetGradient(Gradient* gradient, bool forceControlUpdate, bool sendMe
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// _MarkType
|
|
||||||
void
|
void
|
||||||
StyleView::_MarkType(BMenu* menu, int32 type) const
|
StyleView::_MarkType(BMenu* menu, int32 type) const
|
||||||
{
|
{
|
||||||
@@ -423,7 +352,7 @@ StyleView::_MarkType(BMenu* menu, int32 type) const
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// _SetStyleType
|
|
||||||
void
|
void
|
||||||
StyleView::_SetStyleType(int32 type)
|
StyleView::_SetStyleType(int32 type)
|
||||||
{
|
{
|
||||||
@@ -450,14 +379,14 @@ StyleView::_SetStyleType(int32 type)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// _SetGradientType
|
|
||||||
void
|
void
|
||||||
StyleView::_SetGradientType(int32 type)
|
StyleView::_SetGradientType(int32 type)
|
||||||
{
|
{
|
||||||
fGradientControl->Gradient()->SetType((gradients_type)type);
|
fGradientControl->Gradient()->SetType((gradients_type)type);
|
||||||
}
|
}
|
||||||
|
|
||||||
// _AdoptCurrentColor
|
|
||||||
void
|
void
|
||||||
StyleView::_AdoptCurrentColor(rgb_color color)
|
StyleView::_AdoptCurrentColor(rgb_color color)
|
||||||
{
|
{
|
||||||
@@ -479,7 +408,7 @@ StyleView::_AdoptCurrentColor(rgb_color color)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// _TransferGradientStopColor
|
|
||||||
void
|
void
|
||||||
StyleView::_TransferGradientStopColor()
|
StyleView::_TransferGradientStopColor()
|
||||||
{
|
{
|
||||||
@@ -492,4 +421,3 @@ StyleView::_TransferGradientStopColor()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2006-2007, Haiku.
|
* Copyright 2006-2011, Haiku.
|
||||||
* Distributed under the terms of the MIT License.
|
* Distributed under the terms of the MIT License.
|
||||||
*
|
*
|
||||||
* Authors:
|
* Authors:
|
||||||
@@ -35,9 +35,8 @@ enum {
|
|||||||
MSG_STYLE_TYPE_CHANGED = 'stch',
|
MSG_STYLE_TYPE_CHANGED = 'stch',
|
||||||
};
|
};
|
||||||
|
|
||||||
class StyleView : public BView,
|
class StyleView : public BView, public Observer {
|
||||||
public Observer {
|
public:
|
||||||
public:
|
|
||||||
StyleView(BRect frame);
|
StyleView(BRect frame);
|
||||||
virtual ~StyleView();
|
virtual ~StyleView();
|
||||||
|
|
||||||
@@ -46,9 +45,7 @@ class StyleView : public BView,
|
|||||||
virtual void FrameResized(float width, float height);
|
virtual void FrameResized(float width, float height);
|
||||||
virtual void MessageReceived(BMessage* message);
|
virtual void MessageReceived(BMessage* message);
|
||||||
|
|
||||||
#if __HAIKU__
|
|
||||||
virtual BSize MinSize();
|
virtual BSize MinSize();
|
||||||
#endif
|
|
||||||
|
|
||||||
// Observer interface
|
// Observer interface
|
||||||
virtual void ObjectChanged(const Observable* object);
|
virtual void ObjectChanged(const Observable* object);
|
||||||
@@ -58,18 +55,17 @@ class StyleView : public BView,
|
|||||||
void SetCommandStack(CommandStack* stack);
|
void SetCommandStack(CommandStack* stack);
|
||||||
void SetCurrentColor(CurrentColor* color);
|
void SetCurrentColor(CurrentColor* color);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void _SetGradient(Gradient* gradient,
|
void _SetGradient(Gradient* gradient,
|
||||||
bool forceControlUpdate = false,
|
bool forceControlUpdate = false,
|
||||||
bool sendMessage = false);
|
bool sendMessage = false);
|
||||||
void _MarkType(BMenu* menu,
|
void _MarkType(BMenu* menu, int32 type) const;
|
||||||
int32 type) const;
|
|
||||||
void _SetStyleType(int32 type);
|
void _SetStyleType(int32 type);
|
||||||
void _SetGradientType(int32 type);
|
void _SetGradientType(int32 type);
|
||||||
void _AdoptCurrentColor(rgb_color color);
|
void _AdoptCurrentColor(rgb_color color);
|
||||||
void _TransferGradientStopColor();
|
void _TransferGradientStopColor();
|
||||||
|
|
||||||
|
private:
|
||||||
CommandStack* fCommandStack;
|
CommandStack* fCommandStack;
|
||||||
CurrentColor* fCurrentColor;
|
CurrentColor* fCurrentColor;
|
||||||
|
|
||||||
@@ -85,4 +81,5 @@ class StyleView : public BView,
|
|||||||
BRect fPreviousBounds;
|
BRect fPreviousBounds;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
#endif // STYLE_VIEW_H
|
#endif // STYLE_VIEW_H
|
||||||
|
|||||||
Reference in New Issue
Block a user