Improved error checking, style changes
git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@13028 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
+149
-115
@@ -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"),
|
||||||
@@ -22,28 +22,17 @@
|
|||||||
// File Name: ListItem.cpp
|
// File Name: ListItem.cpp
|
||||||
// Author: Ulrich Wimboeck
|
// Author: Ulrich Wimboeck
|
||||||
// Marc Flerackers ([email protected])
|
// Marc Flerackers ([email protected])
|
||||||
// Description: BListView represents a one-dimensional list view.
|
// Description: BListItem is the base class for BListView's items,
|
||||||
|
// BStringItem is a subclass of BListItem which draws a string.
|
||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
|
|
||||||
// Standard Includes -----------------------------------------------------------
|
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
// System Includes -------------------------------------------------------------
|
|
||||||
#include <ListItem.h>
|
#include <ListItem.h>
|
||||||
#include <View.h>
|
|
||||||
#include <Message.h>
|
#include <Message.h>
|
||||||
#include <Errors.h>
|
#include <View.h>
|
||||||
|
|
||||||
// Project Includes ------------------------------------------------------------
|
|
||||||
|
|
||||||
// Local Includes --------------------------------------------------------------
|
|
||||||
|
|
||||||
// Local Defines ---------------------------------------------------------------
|
|
||||||
|
|
||||||
// Globals ---------------------------------------------------------------------
|
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
BListItem::BListItem(uint32 level, bool expanded)
|
BListItem::BListItem(uint32 level, bool expanded)
|
||||||
: fWidth(0),
|
: fWidth(0),
|
||||||
fHeight(0),
|
fHeight(0),
|
||||||
@@ -55,7 +44,8 @@ BListItem::BListItem(uint32 level, bool expanded)
|
|||||||
fVisible(true)
|
fVisible(true)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
|
|
||||||
BListItem::BListItem(BMessage *data)
|
BListItem::BListItem(BMessage *data)
|
||||||
: BArchivable(data),
|
: BArchivable(data),
|
||||||
fWidth(0),
|
fWidth(0),
|
||||||
@@ -77,77 +67,99 @@ BListItem::BListItem(BMessage *data)
|
|||||||
data->FindBool("_li_expanded", &fExpanded);
|
data->FindBool("_li_expanded", &fExpanded);
|
||||||
data->FindInt32("_li_outline_level", (int32*)&fLevel);
|
data->FindInt32("_li_outline_level", (int32*)&fLevel);
|
||||||
}
|
}
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
|
|
||||||
BListItem::~BListItem()
|
BListItem::~BListItem()
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
status_t BListItem::Archive(BMessage *archive, bool deep) const
|
|
||||||
|
status_t
|
||||||
|
BListItem::Archive(BMessage *archive, bool deep) const
|
||||||
{
|
{
|
||||||
BArchivable::Archive(archive, deep);
|
status_t status = BArchivable::Archive(archive, deep);
|
||||||
|
|
||||||
if (fSelected)
|
if (status == B_OK && fSelected)
|
||||||
archive->AddBool("_sel", true);
|
status = archive->AddBool("_sel", true);
|
||||||
|
|
||||||
if (!fEnabled)
|
if (status == B_OK && !fEnabled)
|
||||||
archive->AddBool("_disable", true);
|
status = archive->AddBool("_disable", true);
|
||||||
|
|
||||||
if (fExpanded)
|
if (status == B_OK && fExpanded)
|
||||||
archive->AddBool("_li_expanded", true);
|
status = archive->AddBool("_li_expanded", true);
|
||||||
|
|
||||||
if (fLevel != 0)
|
if (status == B_OK && fLevel != 0)
|
||||||
archive->AddInt32("_li_outline_level", fLevel);
|
status = archive->AddInt32("_li_outline_level", fLevel);
|
||||||
|
|
||||||
return B_OK;
|
return status;
|
||||||
}
|
}
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
float BListItem::Height() const
|
|
||||||
|
float
|
||||||
|
BListItem::Height() const
|
||||||
{
|
{
|
||||||
return fHeight;
|
return fHeight;
|
||||||
}
|
}
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
float BListItem::Width() const
|
|
||||||
|
float
|
||||||
|
BListItem::Width() const
|
||||||
{
|
{
|
||||||
return fWidth;
|
return fWidth;
|
||||||
}
|
}
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
bool BListItem::IsSelected() const
|
|
||||||
|
bool
|
||||||
|
BListItem::IsSelected() const
|
||||||
{
|
{
|
||||||
return fSelected;
|
return fSelected;
|
||||||
}
|
}
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
void BListItem::Select()
|
|
||||||
|
void
|
||||||
|
BListItem::Select()
|
||||||
{
|
{
|
||||||
fSelected = true;
|
fSelected = true;
|
||||||
}
|
}
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
void BListItem::Deselect()
|
|
||||||
|
void
|
||||||
|
BListItem::Deselect()
|
||||||
{
|
{
|
||||||
fSelected = false;
|
fSelected = false;
|
||||||
}
|
}
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
void BListItem::SetEnabled(bool on)
|
|
||||||
|
void
|
||||||
|
BListItem::SetEnabled(bool on)
|
||||||
{
|
{
|
||||||
fEnabled = on;
|
fEnabled = on;
|
||||||
}
|
}
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
bool BListItem::IsEnabled() const
|
|
||||||
|
bool
|
||||||
|
BListItem::IsEnabled() const
|
||||||
{
|
{
|
||||||
return fEnabled;
|
return fEnabled;
|
||||||
}
|
}
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
void BListItem::SetHeight(float height)
|
|
||||||
|
void
|
||||||
|
BListItem::SetHeight(float height)
|
||||||
{
|
{
|
||||||
fHeight = height;
|
fHeight = height;
|
||||||
}
|
}
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
void BListItem::SetWidth(float width)
|
|
||||||
|
void
|
||||||
|
BListItem::SetWidth(float width)
|
||||||
{
|
{
|
||||||
fWidth = width;
|
fWidth = width;
|
||||||
}
|
}
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
void BListItem::Update(BView *owner, const BFont *font)
|
|
||||||
|
void
|
||||||
|
BListItem::Update(BView *owner, const BFont *font)
|
||||||
{
|
{
|
||||||
font_height fh;
|
font_height fh;
|
||||||
font->GetHeight(&fh);
|
font->GetHeight(&fh);
|
||||||
@@ -155,58 +167,74 @@ void BListItem::Update(BView *owner, const BFont *font)
|
|||||||
SetWidth(owner->Bounds().Width());
|
SetWidth(owner->Bounds().Width());
|
||||||
SetHeight(fh.ascent + fh.descent + fh.leading);
|
SetHeight(fh.ascent + fh.descent + fh.leading);
|
||||||
}
|
}
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
status_t BListItem::Perform(perform_code d, void *arg)
|
|
||||||
|
status_t
|
||||||
|
BListItem::Perform(perform_code d, void *arg)
|
||||||
{
|
{
|
||||||
return BArchivable::Perform(d, arg);
|
return BArchivable::Perform(d, arg);
|
||||||
}
|
}
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
void BListItem::SetExpanded(bool expanded)
|
|
||||||
|
void
|
||||||
|
BListItem::SetExpanded(bool expanded)
|
||||||
{
|
{
|
||||||
fExpanded = expanded;
|
fExpanded = expanded;
|
||||||
}
|
}
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
bool BListItem::IsExpanded() const
|
|
||||||
|
bool
|
||||||
|
BListItem::IsExpanded() const
|
||||||
{
|
{
|
||||||
return fExpanded;
|
return fExpanded;
|
||||||
}
|
}
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
uint32 BListItem::OutlineLevel() const
|
|
||||||
|
uint32
|
||||||
|
BListItem::OutlineLevel() const
|
||||||
{
|
{
|
||||||
return fLevel;
|
return fLevel;
|
||||||
}
|
}
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
bool BListItem::HasSubitems() const
|
|
||||||
|
bool
|
||||||
|
BListItem::HasSubitems() const
|
||||||
{
|
{
|
||||||
return fHasSubitems;
|
return fHasSubitems;
|
||||||
}
|
}
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
|
|
||||||
void BListItem::_ReservedListItem1() {}
|
void BListItem::_ReservedListItem1() {}
|
||||||
void BListItem::_ReservedListItem2() {}
|
void BListItem::_ReservedListItem2() {}
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
|
|
||||||
BListItem::BListItem(const BListItem &item)
|
BListItem::BListItem(const BListItem &item)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
BListItem &BListItem::operator=(const BListItem &)
|
|
||||||
|
BListItem &
|
||||||
|
BListItem::operator=(const BListItem &)
|
||||||
{
|
{
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
bool BListItem::IsItemVisible() const
|
|
||||||
|
bool
|
||||||
|
BListItem::IsItemVisible() const
|
||||||
{
|
{
|
||||||
return fVisible;
|
return fVisible;
|
||||||
}
|
}
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
void BListItem::SetItemVisible(bool visible)
|
|
||||||
|
void
|
||||||
|
BListItem::SetItemVisible(bool visible)
|
||||||
{
|
{
|
||||||
fVisible = visible;
|
fVisible = visible;
|
||||||
}
|
}
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
|
|
||||||
|
|
||||||
|
// BStringItem
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
BStringItem::BStringItem(const char *text, uint32 level, bool expanded)
|
BStringItem::BStringItem(const char *text, uint32 level, bool expanded)
|
||||||
: BListItem(level, expanded),
|
: BListItem(level, expanded),
|
||||||
fText(NULL),
|
fText(NULL),
|
||||||
@@ -214,7 +242,8 @@ BStringItem::BStringItem(const char *text, uint32 level, bool expanded)
|
|||||||
{
|
{
|
||||||
SetText(text);
|
SetText(text);
|
||||||
}
|
}
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
|
|
||||||
BStringItem::BStringItem(BMessage *archive)
|
BStringItem::BStringItem(BMessage *archive)
|
||||||
: BListItem(archive),
|
: BListItem(archive),
|
||||||
fText(NULL),
|
fText(NULL),
|
||||||
@@ -225,32 +254,38 @@ BStringItem::BStringItem(BMessage *archive)
|
|||||||
if (archive->FindString("_label", &string) == B_OK)
|
if (archive->FindString("_label", &string) == B_OK)
|
||||||
SetText(string);
|
SetText(string);
|
||||||
}
|
}
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
|
|
||||||
BStringItem::~BStringItem()
|
BStringItem::~BStringItem()
|
||||||
{
|
{
|
||||||
if (fText)
|
free(fText);
|
||||||
free(fText);
|
|
||||||
}
|
}
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
BArchivable *BStringItem::Instantiate(BMessage *archive)
|
|
||||||
|
BArchivable *
|
||||||
|
BStringItem::Instantiate(BMessage *archive)
|
||||||
{
|
{
|
||||||
if (validate_instantiation(archive, "BStringItem"))
|
if (validate_instantiation(archive, "BStringItem"))
|
||||||
return new BStringItem(archive);
|
return new BStringItem(archive);
|
||||||
else
|
else
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
status_t BStringItem::Archive(BMessage *archive, bool deep) const
|
|
||||||
|
status_t
|
||||||
|
BStringItem::Archive(BMessage *archive, bool deep) const
|
||||||
{
|
{
|
||||||
BListItem::Archive(archive);
|
status_t status = BListItem::Archive(archive);
|
||||||
|
|
||||||
if (fText)
|
if (status == B_OK && fText != NULL)
|
||||||
archive->AddString("_label", fText);
|
status = archive->AddString("_label", fText);
|
||||||
|
|
||||||
return B_OK;
|
return status;
|
||||||
}
|
}
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
void BStringItem::DrawItem(BView *owner, BRect frame, bool complete)
|
|
||||||
|
void
|
||||||
|
BStringItem::DrawItem(BView *owner, BRect frame, bool complete)
|
||||||
{
|
{
|
||||||
if (fText == NULL)
|
if (fText == NULL)
|
||||||
return;
|
return;
|
||||||
@@ -258,8 +293,7 @@ void BStringItem::DrawItem(BView *owner, BRect frame, bool complete)
|
|||||||
rgb_color highColor = owner->HighColor();
|
rgb_color highColor = owner->HighColor();
|
||||||
rgb_color lowColor = owner->LowColor();
|
rgb_color lowColor = owner->LowColor();
|
||||||
|
|
||||||
if (IsSelected() || complete)
|
if (IsSelected() || complete) {
|
||||||
{
|
|
||||||
if (IsSelected())
|
if (IsSelected())
|
||||||
owner->SetHighColor(tint_color(lowColor, B_DARKEN_2_TINT));
|
owner->SetHighColor(tint_color(lowColor, B_DARKEN_2_TINT));
|
||||||
else
|
else
|
||||||
@@ -282,59 +316,59 @@ void BStringItem::DrawItem(BView *owner, BRect frame, bool complete)
|
|||||||
owner->SetHighColor(highColor);
|
owner->SetHighColor(highColor);
|
||||||
owner->SetLowColor(lowColor);
|
owner->SetLowColor(lowColor);
|
||||||
}
|
}
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
void BStringItem::SetText(const char *text)
|
|
||||||
{
|
|
||||||
if (fText)
|
|
||||||
{
|
|
||||||
free(fText);
|
|
||||||
fText = NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
BStringItem::SetText(const char *text)
|
||||||
|
{
|
||||||
|
free(fText);
|
||||||
|
fText = NULL;
|
||||||
|
|
||||||
if (text)
|
if (text)
|
||||||
fText = strdup(text);
|
fText = strdup(text);
|
||||||
}
|
}
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
const char *BStringItem::Text() const
|
|
||||||
|
const char *
|
||||||
|
BStringItem::Text() const
|
||||||
{
|
{
|
||||||
return fText;
|
return fText;
|
||||||
}
|
}
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
void BStringItem::Update(BView *owner, const BFont *font)
|
|
||||||
|
void
|
||||||
|
BStringItem::Update(BView *owner, const BFont *font)
|
||||||
{
|
{
|
||||||
if (fText)
|
if (fText)
|
||||||
SetWidth(owner->StringWidth(fText));
|
SetWidth(owner->StringWidth(fText));
|
||||||
|
|
||||||
font_height fheight;
|
font_height fheight;
|
||||||
|
|
||||||
font->GetHeight(&fheight);
|
font->GetHeight(&fheight);
|
||||||
|
|
||||||
fBaselineOffset = fheight.ascent + fheight.leading;
|
fBaselineOffset = fheight.ascent + fheight.leading;
|
||||||
SetHeight((float)ceil(fheight.ascent + fheight.descent +
|
SetHeight((float)ceil(fheight.ascent + fheight.descent +
|
||||||
fheight.leading) + 4);
|
fheight.leading) + 4);
|
||||||
}
|
}
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
status_t BStringItem::Perform(perform_code d, void *arg)
|
|
||||||
|
status_t
|
||||||
|
BStringItem::Perform(perform_code d, void *arg)
|
||||||
{
|
{
|
||||||
return B_ERROR;
|
return BListItem::Perform(d, arg);
|
||||||
}
|
}
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
|
|
||||||
void BStringItem::_ReservedStringItem1() {}
|
void BStringItem::_ReservedStringItem1() {}
|
||||||
void BStringItem::_ReservedStringItem2() {}
|
void BStringItem::_ReservedStringItem2() {}
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
|
|
||||||
BStringItem::BStringItem(const BStringItem &)
|
BStringItem::BStringItem(const BStringItem &)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
BStringItem &BStringItem::operator=(const BStringItem &)
|
|
||||||
|
BStringItem &
|
||||||
|
BStringItem::operator=(const BStringItem &)
|
||||||
{
|
{
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
|
|
||||||
/*
|
|
||||||
* $Log $
|
|
||||||
*
|
|
||||||
* $Id $
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
|
|||||||
Reference in New Issue
Block a user