SetBorder() shouldn't crash if the BBox isn't attached.

Style changes.

git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@13024 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Stefano Ceccherini
2005-06-09 08:27:31 +00:00
parent 2ed35bc88c
commit 491e6111d4
+142 -105
View File
@@ -1,5 +1,5 @@
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
// Copyright (c) 2001-2002, OpenBeOS // Copyright (c) 2001-2005, Haiku, Inc.
// //
// Permission is hereby granted, free of charge, to any person obtaining a // Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the "Software"), // copy of this software and associated documentation files (the "Software"),
@@ -24,25 +24,13 @@
// Description: BBox objects group views together and draw a border // Description: BBox objects group views together and draw a border
// around them. // around them.
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
// Standard Includes -----------------------------------------------------------
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
// System Includes -------------------------------------------------------------
#include <Box.h> #include <Box.h>
#include <Errors.h>
#include <Message.h> #include <Message.h>
// Project Includes ------------------------------------------------------------
// Local Includes --------------------------------------------------------------
// Local Defines ---------------------------------------------------------------
// Globals ---------------------------------------------------------------------
//------------------------------------------------------------------------------
BBox::BBox(BRect frame, const char *name, uint32 resizingMode, uint32 flags, BBox::BBox(BRect frame, const char *name, uint32 resizingMode, uint32 flags,
border_style border) border_style border)
: BView(frame, name, resizingMode, flags | B_FRAME_EVENTS), : BView(frame, name, resizingMode, flags | B_FRAME_EVENTS),
@@ -53,12 +41,14 @@ BBox::BBox(BRect frame, const char *name, uint32 resizingMode, uint32 flags,
InitObject(); InitObject();
} }
//------------------------------------------------------------------------------
BBox::~BBox() BBox::~BBox()
{ {
ClearAnyLabel(); ClearAnyLabel();
} }
//------------------------------------------------------------------------------
BBox::BBox(BMessage *archive) BBox::BBox(BMessage *archive)
: BView(archive) : BView(archive)
{ {
@@ -80,16 +70,20 @@ BBox::BBox(BMessage *archive)
if (archive->FindBool("_lblview", &aBool) == B_OK) if (archive->FindBool("_lblview", &aBool) == B_OK)
fLabelView = ChildAt(0); fLabelView = ChildAt(0);
} }
//------------------------------------------------------------------------------
BArchivable *BBox::Instantiate(BMessage *archive)
BArchivable *
BBox::Instantiate(BMessage *archive)
{ {
if (validate_instantiation(archive, "BBox")) if (validate_instantiation(archive, "BBox"))
return new BBox(archive); return new BBox(archive);
else else
return NULL; return NULL;
} }
//------------------------------------------------------------------------------
status_t BBox::Archive(BMessage *archive, bool deep) const
status_t
BBox::Archive(BMessage *archive, bool deep) const
{ {
BView::Archive(archive, deep); BView::Archive(archive, deep);
@@ -104,27 +98,33 @@ status_t BBox::Archive(BMessage *archive, bool deep) const
return B_OK; return B_OK;
} }
//------------------------------------------------------------------------------
void BBox::SetBorder(border_style border)
void
BBox::SetBorder(border_style border)
{ {
fStyle = border; fStyle = border;
LockLooper(); if (Window() != NULL && LockLooper()) {
Invalidate(); Invalidate();
UnlockLooper(); UnlockLooper();
}
} }
//------------------------------------------------------------------------------
border_style BBox::Border() const
border_style
BBox::Border() const
{ {
return fStyle; return fStyle;
} }
//------------------------------------------------------------------------------
void BBox::SetLabel(const char *string)
void
BBox::SetLabel(const char *string)
{ {
ClearAnyLabel(); ClearAnyLabel();
if (string) if (string) {
{
// Update fBounds // Update fBounds
fBounds = Bounds(); fBounds = Bounds();
font_height fh; font_height fh;
@@ -138,13 +138,14 @@ void BBox::SetLabel(const char *string)
if (Window()) if (Window())
Invalidate(); Invalidate();
} }
//------------------------------------------------------------------------------
status_t BBox::SetLabel(BView *viewLabel)
status_t
BBox::SetLabel(BView *viewLabel)
{ {
ClearAnyLabel(); ClearAnyLabel();
if (viewLabel) if (viewLabel) {
{
// Update fBounds // Update fBounds
fBounds = Bounds(); fBounds = Bounds();
@@ -160,21 +161,26 @@ status_t BBox::SetLabel(BView *viewLabel)
return B_OK; return B_OK;
} }
//------------------------------------------------------------------------------
const char *BBox::Label() const
const char *
BBox::Label() const
{ {
return fLabel; return fLabel;
} }
//------------------------------------------------------------------------------
BView *BBox::LabelView() const
BView *
BBox::LabelView() const
{ {
return fLabelView; return fLabelView;
} }
//------------------------------------------------------------------------------
void BBox::Draw(BRect updateRect)
void
BBox::Draw(BRect updateRect)
{ {
switch (fStyle) switch (fStyle) {
{
case B_FANCY_BORDER: case B_FANCY_BORDER:
DrawFancy(); DrawFancy();
break; break;
@@ -187,8 +193,7 @@ void BBox::Draw(BRect updateRect)
break; break;
} }
if (fLabel) if (fLabel) {
{
font_height fh; font_height fh;
GetFontHeight(&fh); GetFontHeight(&fh);
@@ -202,32 +207,40 @@ void BBox::Draw(BRect updateRect)
+ 1.0f)); + 1.0f));
} }
} }
//------------------------------------------------------------------------------
void BBox::AttachedToWindow() void BBox::AttachedToWindow()
{ {
if (Parent()) if (Parent()) {
{
SetViewColor(Parent()->ViewColor()); SetViewColor(Parent()->ViewColor());
SetLowColor(Parent()->ViewColor()); SetLowColor(Parent()->ViewColor());
} }
} }
//------------------------------------------------------------------------------
void BBox::DetachedFromWindow()
void
BBox::DetachedFromWindow()
{ {
BView::DetachedFromWindow(); BView::DetachedFromWindow();
} }
//------------------------------------------------------------------------------
void BBox::AllAttached()
void
BBox::AllAttached()
{ {
BView::AllAttached(); BView::AllAttached();
} }
//------------------------------------------------------------------------------
void BBox::AllDetached()
void
BBox::AllDetached()
{ {
BView::AllDetached(); BView::AllDetached();
} }
//------------------------------------------------------------------------------
void BBox::FrameResized(float width, float height)
void
BBox::FrameResized(float width, float height)
{ {
BRect bounds(Bounds()); BRect bounds(Bounds());
@@ -238,50 +251,68 @@ void BBox::FrameResized(float width, float height)
Invalidate(); Invalidate();
} }
//------------------------------------------------------------------------------
void BBox::MessageReceived(BMessage *message)
void
BBox::MessageReceived(BMessage *message)
{ {
BView::MessageReceived(message); BView::MessageReceived(message);
} }
//------------------------------------------------------------------------------
void BBox::MouseDown(BPoint point)
void
BBox::MouseDown(BPoint point)
{ {
BView::MouseDown(point); BView::MouseDown(point);
} }
//------------------------------------------------------------------------------
void BBox::MouseUp(BPoint point)
void
BBox::MouseUp(BPoint point)
{ {
BView::MouseUp(point); BView::MouseUp(point);
} }
//------------------------------------------------------------------------------
void BBox::WindowActivated(bool active)
void
BBox::WindowActivated(bool active)
{ {
BView::WindowActivated(active); BView::WindowActivated(active);
} }
//------------------------------------------------------------------------------
void BBox::MouseMoved(BPoint point, uint32 transit, const BMessage *message)
void
BBox::MouseMoved(BPoint point, uint32 transit, const BMessage *message)
{ {
BView::MouseMoved(point, transit, message); BView::MouseMoved(point, transit, message);
} }
//------------------------------------------------------------------------------
void BBox::FrameMoved(BPoint newLocation)
void
BBox::FrameMoved(BPoint newLocation)
{ {
BView::FrameMoved(newLocation); BView::FrameMoved(newLocation);
} }
//------------------------------------------------------------------------------
BHandler *BBox::ResolveSpecifier(BMessage *message, int32 index,
BHandler *
BBox::ResolveSpecifier(BMessage *message, int32 index,
BMessage *specifier, int32 what, BMessage *specifier, int32 what,
const char *property) const char *property)
{ {
return BView::ResolveSpecifier(message, index, specifier, what, property); return BView::ResolveSpecifier(message, index, specifier, what, property);
} }
//------------------------------------------------------------------------------
void BBox::ResizeToPreferred()
void
BBox::ResizeToPreferred()
{ {
BView::ResizeToPreferred(); BView::ResizeToPreferred();
} }
//------------------------------------------------------------------------------
void BBox::GetPreferredSize(float *width, float *height)
void
BBox::GetPreferredSize(float *width, float *height)
{ {
/* BRect rect(0,0,99,99); /* BRect rect(0,0,99,99);
@@ -296,31 +327,42 @@ void BBox::GetPreferredSize(float *width, float *height)
BView::GetPreferredSize(width, height); BView::GetPreferredSize(width, height);
} }
//------------------------------------------------------------------------------
void BBox::MakeFocus(bool focused)
void
BBox::MakeFocus(bool focused)
{ {
BView::MakeFocus(focused); BView::MakeFocus(focused);
} }
//------------------------------------------------------------------------------
status_t BBox::GetSupportedSuites(BMessage *message)
status_t
BBox::GetSupportedSuites(BMessage *message)
{ {
return BView::GetSupportedSuites(message); return BView::GetSupportedSuites(message);
} }
//------------------------------------------------------------------------------
status_t BBox::Perform(perform_code d, void *arg)
status_t
BBox::Perform(perform_code d, void *arg)
{ {
return BView::Perform(d, arg); return BView::Perform(d, arg);
} }
//------------------------------------------------------------------------------
void BBox::_ReservedBox1() {} void BBox::_ReservedBox1() {}
void BBox::_ReservedBox2() {} void BBox::_ReservedBox2() {}
//------------------------------------------------------------------------------
BBox &BBox::operator=(const BBox &)
BBox &
BBox::operator=(const BBox &)
{ {
return *this; return *this;
} }
//------------------------------------------------------------------------------
void BBox::InitObject(BMessage *data)
void
BBox::InitObject(BMessage *data)
{ {
fLabel = NULL; fLabel = NULL;
fBounds = Bounds(); fBounds = Bounds();
@@ -331,16 +373,18 @@ void BBox::InitObject(BMessage *data)
BFont font(be_bold_font); BFont font(be_bold_font);
if (!data || !data->HasString("_fname")) if (!data || !data->HasString("_fname"))
flags = 1; flags = B_FONT_FAMILY_AND_STYLE;
if (!data || !data->HasFloat("_fflt")) if (!data || !data->HasFloat("_fflt"))
flags |= 2; flags |= B_FONT_SIZE;
if (flags != 0) if (flags != 0)
SetFont(&font, flags); SetFont(&font, flags);
} }
//------------------------------------------------------------------------------
void BBox::DrawPlain()
void
BBox::DrawPlain()
{ {
BRect r = fBounds; BRect r = fBounds;
@@ -358,8 +402,10 @@ void BBox::DrawPlain()
BPoint(r.right, r.top + 1.0f), shadow); BPoint(r.right, r.top + 1.0f), shadow);
EndLineArray(); EndLineArray();
} }
//------------------------------------------------------------------------------
void BBox::DrawFancy()
void
BBox::DrawFancy()
{ {
BRect r = fBounds; BRect r = fBounds;
@@ -388,26 +434,17 @@ void BBox::DrawFancy()
BPoint(r.right, r.top + 1.0f), shadow); BPoint(r.right, r.top + 1.0f), shadow);
EndLineArray(); EndLineArray();
} }
//------------------------------------------------------------------------------
void BBox::ClearAnyLabel()
void
BBox::ClearAnyLabel()
{ {
if (fLabel) if (fLabel) {
{
free(fLabel); free(fLabel);
fLabel = NULL; fLabel = NULL;
} } else if (fLabelView) {
else if (fLabelView)
{
fLabelView->RemoveSelf(); fLabelView->RemoveSelf();
delete fLabelView; delete fLabelView;
fLabelView = NULL; fLabelView = NULL;
} }
} }
//------------------------------------------------------------------------------
/*
* $Log $
*
* $Id $
*
*/