* Moved class BStringItem into its own source file.
* Changed BStringItem::Update() to set a better baseline offset and height; this should improve vertical text placement. * Fixed a bug in BStringItem::Update(): it used the owner to determine the width, but must use the font passed in instead. * Coding style cleanup. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@31090 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2006-2007, Haiku, Inc. All Rights Reserved.
|
* Copyright 2006-2009, Haiku, Inc. All Rights Reserved.
|
||||||
* Distributed under the terms of the MIT License.
|
* Distributed under the terms of the MIT License.
|
||||||
*/
|
*/
|
||||||
#ifndef _LIST_ITEM_H
|
#ifndef _LIST_ITEM_H
|
||||||
@@ -17,76 +17,81 @@ class BView;
|
|||||||
|
|
||||||
|
|
||||||
class BListItem : public BArchivable {
|
class BListItem : public BArchivable {
|
||||||
public:
|
public:
|
||||||
BListItem(uint32 outlineLevel = 0,
|
BListItem(uint32 outlineLevel = 0,
|
||||||
bool expanded = true);
|
bool expanded = true);
|
||||||
BListItem(BMessage* archive);
|
BListItem(BMessage* archive);
|
||||||
virtual ~BListItem();
|
virtual ~BListItem();
|
||||||
|
|
||||||
virtual status_t Archive(BMessage* archive, bool deep = true) const;
|
virtual status_t Archive(BMessage* archive, bool deep = true) const;
|
||||||
|
|
||||||
float Height() const;
|
float Height() const;
|
||||||
float Width() const;
|
float Width() const;
|
||||||
bool IsSelected() const;
|
bool IsSelected() const;
|
||||||
void Select();
|
void Select();
|
||||||
void Deselect();
|
void Deselect();
|
||||||
|
|
||||||
virtual void SetEnabled(bool enabled);
|
virtual void SetEnabled(bool enabled);
|
||||||
bool IsEnabled() const;
|
bool IsEnabled() const;
|
||||||
|
|
||||||
void SetHeight(float height);
|
void SetHeight(float height);
|
||||||
void SetWidth(float width);
|
void SetWidth(float width);
|
||||||
virtual void DrawItem(BView* owner, BRect frame,
|
virtual void DrawItem(BView* owner, BRect frame,
|
||||||
bool complete = false) = 0;
|
bool complete = false) = 0;
|
||||||
virtual void Update(BView* owner, const BFont* font);
|
virtual void Update(BView* owner, const BFont* font);
|
||||||
|
|
||||||
virtual status_t Perform(perform_code code, void* arg);
|
virtual status_t Perform(perform_code code, void* arg);
|
||||||
|
|
||||||
bool IsExpanded() const;
|
bool IsExpanded() const;
|
||||||
void SetExpanded(bool expanded);
|
void SetExpanded(bool expanded);
|
||||||
uint32 OutlineLevel() const;
|
uint32 OutlineLevel() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
friend class BOutlineListView;
|
friend class BOutlineListView;
|
||||||
friend class BListView;
|
friend class BListView;
|
||||||
bool HasSubitems() const;
|
|
||||||
|
|
||||||
virtual void _ReservedListItem1();
|
bool HasSubitems() const;
|
||||||
virtual void _ReservedListItem2();
|
|
||||||
|
virtual void _ReservedListItem1();
|
||||||
|
virtual void _ReservedListItem2();
|
||||||
|
|
||||||
BListItem(const BListItem& item);
|
BListItem(const BListItem& item);
|
||||||
BListItem& operator=(const BListItem& item);
|
BListItem& operator=(const BListItem& item);
|
||||||
|
|
||||||
bool IsItemVisible() const;
|
bool IsItemVisible() const;
|
||||||
void SetItemVisible(bool visible);
|
void SetItemVisible(bool visible);
|
||||||
inline float Top() const;
|
inline float Top() const;
|
||||||
inline float Bottom() const;
|
inline float Bottom() const;
|
||||||
void SetTop(float top);
|
void SetTop(float top);
|
||||||
private:
|
|
||||||
float fTop;
|
private:
|
||||||
BList* fTemporaryList;
|
float fTop;
|
||||||
float fWidth;
|
BList* fTemporaryList;
|
||||||
float fHeight;
|
float fWidth;
|
||||||
uint32 fLevel;
|
float fHeight;
|
||||||
bool fSelected;
|
uint32 fLevel;
|
||||||
bool fEnabled;
|
bool fSelected;
|
||||||
bool fExpanded;
|
bool fEnabled;
|
||||||
bool fHasSubitems : 1;
|
bool fExpanded;
|
||||||
bool fVisible : 1;
|
bool fHasSubitems : 1;
|
||||||
|
bool fVisible : 1;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
inline float
|
inline float
|
||||||
BListItem::Top(void) const
|
BListItem::Top(void) const
|
||||||
{
|
{
|
||||||
return fTop;
|
return fTop;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
inline float
|
inline float
|
||||||
BListItem::Bottom(void) const
|
BListItem::Bottom(void) const
|
||||||
{
|
{
|
||||||
return (fTop + ceilf(fHeight) - 1.0);
|
return fTop + ceilf(fHeight) - 1.0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#include <StringItem.h>
|
#include <StringItem.h>
|
||||||
// to maintain source compatibility
|
// to maintain source compatibility
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2006, Haiku, Inc. All Rights Reserved.
|
* Copyright 2006-2009, Haiku, Inc. All Rights Reserved.
|
||||||
* Distributed under the terms of the MIT License.
|
* Distributed under the terms of the MIT License.
|
||||||
*/
|
*/
|
||||||
#ifndef _STRING_ITEM_H
|
#ifndef _STRING_ITEM_H
|
||||||
@@ -10,33 +10,34 @@
|
|||||||
|
|
||||||
|
|
||||||
class BStringItem : public BListItem {
|
class BStringItem : public BListItem {
|
||||||
public:
|
public:
|
||||||
BStringItem(const char* text, uint32 outlineLevel = 0,
|
BStringItem(const char* text,
|
||||||
bool expanded = true);
|
uint32 outlineLevel = 0, bool expanded = true);
|
||||||
BStringItem(BMessage* archive);
|
BStringItem(BMessage* archive);
|
||||||
virtual ~BStringItem();
|
virtual ~BStringItem();
|
||||||
|
|
||||||
static BArchivable* Instantiate(BMessage* archive);
|
static BArchivable* Instantiate(BMessage* archive);
|
||||||
virtual status_t Archive(BMessage* archive, bool deep = true) const;
|
virtual status_t Archive(BMessage* archive, bool deep = true) const;
|
||||||
|
|
||||||
virtual void DrawItem(BView* owner, BRect frame, bool complete = false);
|
virtual void DrawItem(BView* owner, BRect frame,
|
||||||
virtual void SetText(const char* text);
|
bool complete = false);
|
||||||
const char* Text() const;
|
virtual void SetText(const char* text);
|
||||||
|
const char* Text() const;
|
||||||
|
|
||||||
virtual void Update(BView* owner, const BFont* font);
|
virtual void Update(BView* owner, const BFont* font);
|
||||||
|
|
||||||
virtual status_t Perform(perform_code code, void* arg);
|
virtual status_t Perform(perform_code code, void* arg);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
virtual void _ReservedStringItem1();
|
virtual void _ReservedStringItem1();
|
||||||
virtual void _ReservedStringItem2();
|
virtual void _ReservedStringItem2();
|
||||||
|
|
||||||
BStringItem(const BStringItem& item);
|
BStringItem(const BStringItem& item);
|
||||||
BStringItem& operator=(const BStringItem& item);
|
BStringItem& operator=(const BStringItem& item);
|
||||||
|
|
||||||
char* fText;
|
char* fText;
|
||||||
float fBaselineOffset;
|
float fBaselineOffset;
|
||||||
uint32 _reserved[2];
|
uint32 _reserved[2];
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // _STRING_ITEM_H
|
#endif // _STRING_ITEM_H
|
||||||
|
|||||||
@@ -114,6 +114,7 @@ MergeObject <libbe>interface_kit.o :
|
|||||||
SplitLayoutBuilder.cpp
|
SplitLayoutBuilder.cpp
|
||||||
SplitView.cpp
|
SplitView.cpp
|
||||||
StatusBar.cpp
|
StatusBar.cpp
|
||||||
|
StringItem.cpp
|
||||||
StringView.cpp
|
StringView.cpp
|
||||||
TabView.cpp
|
TabView.cpp
|
||||||
TextControl.cpp
|
TextControl.cpp
|
||||||
|
|||||||
+38
-209
@@ -1,67 +1,48 @@
|
|||||||
//------------------------------------------------------------------------------
|
/*
|
||||||
// Copyright (c) 2001-2008, Haiku, Inc.
|
* Copyright 2001-2009, Haiku, Inc. All Rights Reserved.
|
||||||
//
|
* Distributed under the terms of the MIT License.
|
||||||
// Permission is hereby granted, free of charge, to any person obtaining a
|
*
|
||||||
// copy of this software and associated documentation files (the "Software"),
|
* Authors:
|
||||||
// to deal in the Software without restriction, including without limitation
|
* Ulrich Wimboeck
|
||||||
// the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
* Marc Flerackers ([email protected])
|
||||||
// and/or sell copies of the Software, and to permit persons to whom the
|
* Rene Gollent
|
||||||
// Software is furnished to do so, subject to the following conditions:
|
*/
|
||||||
//
|
|
||||||
// The above copyright notice and this permission notice shall be included in
|
|
||||||
// all copies or substantial portions of the Software.
|
|
||||||
//
|
|
||||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
||||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
||||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
||||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
||||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
|
||||||
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
|
||||||
// DEALINGS IN THE SOFTWARE.
|
|
||||||
//
|
|
||||||
// File Name: ListItem.cpp
|
|
||||||
// Author: Ulrich Wimboeck
|
|
||||||
// Marc Flerackers ([email protected])
|
|
||||||
// Rene Gollent
|
|
||||||
// Description: BListItem is the base class for BListView's items,
|
|
||||||
// BStringItem is a subclass of BListItem which draws a string.
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <string.h>
|
|
||||||
|
|
||||||
#include <ListItem.h>
|
#include <ListItem.h>
|
||||||
|
|
||||||
#include <Message.h>
|
#include <Message.h>
|
||||||
#include <View.h>
|
#include <View.h>
|
||||||
|
|
||||||
|
|
||||||
BListItem::BListItem(uint32 level, bool expanded)
|
BListItem::BListItem(uint32 level, bool expanded)
|
||||||
: fTop(0.0),
|
:
|
||||||
fWidth(0),
|
fTop(0.0),
|
||||||
fHeight(0),
|
fWidth(0),
|
||||||
fLevel(level),
|
fHeight(0),
|
||||||
fSelected(false),
|
fLevel(level),
|
||||||
fEnabled(true),
|
fSelected(false),
|
||||||
fExpanded(expanded),
|
fEnabled(true),
|
||||||
fHasSubitems(false),
|
fExpanded(expanded),
|
||||||
fVisible(true)
|
fHasSubitems(false),
|
||||||
|
fVisible(true)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
BListItem::BListItem(BMessage *data)
|
BListItem::BListItem(BMessage* data)
|
||||||
: BArchivable(data),
|
: BArchivable(data),
|
||||||
fTop(0.0),
|
fTop(0.0),
|
||||||
fWidth(0),
|
fWidth(0),
|
||||||
fHeight(0),
|
fHeight(0),
|
||||||
fLevel(0),
|
fLevel(0),
|
||||||
fSelected(false),
|
fSelected(false),
|
||||||
fEnabled(true),
|
fEnabled(true),
|
||||||
fExpanded(false),
|
fExpanded(false),
|
||||||
fHasSubitems(false),
|
fHasSubitems(false),
|
||||||
fVisible(true)
|
fVisible(true)
|
||||||
{
|
{
|
||||||
data->FindBool("_sel", &fSelected);
|
data->FindBool("_sel", &fSelected);
|
||||||
|
|
||||||
if (data->FindBool("_disable", &fEnabled) != B_OK)
|
if (data->FindBool("_disable", &fEnabled) != B_OK)
|
||||||
fEnabled = true;
|
fEnabled = true;
|
||||||
else
|
else
|
||||||
@@ -78,10 +59,9 @@ BListItem::~BListItem()
|
|||||||
|
|
||||||
|
|
||||||
status_t
|
status_t
|
||||||
BListItem::Archive(BMessage *archive, bool deep) const
|
BListItem::Archive(BMessage* archive, bool deep) const
|
||||||
{
|
{
|
||||||
status_t status = BArchivable::Archive(archive, deep);
|
status_t status = BArchivable::Archive(archive, deep);
|
||||||
|
|
||||||
if (status == B_OK && fSelected)
|
if (status == B_OK && fSelected)
|
||||||
status = archive->AddBool("_sel", true);
|
status = archive->AddBool("_sel", true);
|
||||||
|
|
||||||
@@ -162,18 +142,18 @@ BListItem::SetWidth(float width)
|
|||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
BListItem::Update(BView *owner, const BFont *font)
|
BListItem::Update(BView* owner, const BFont* font)
|
||||||
{
|
{
|
||||||
font_height fh;
|
font_height fh;
|
||||||
font->GetHeight(&fh);
|
font->GetHeight(&fh);
|
||||||
|
|
||||||
SetWidth(owner->Bounds().Width());
|
SetWidth(owner->Bounds().Width());
|
||||||
SetHeight(fh.ascent + fh.descent + fh.leading);
|
SetHeight(ceilf(fh.ascent + fh.descent + fh.leading));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
status_t
|
status_t
|
||||||
BListItem::Perform(perform_code d, void *arg)
|
BListItem::Perform(perform_code d, void* arg)
|
||||||
{
|
{
|
||||||
return BArchivable::Perform(d, arg);
|
return BArchivable::Perform(d, arg);
|
||||||
}
|
}
|
||||||
@@ -211,174 +191,23 @@ void BListItem::_ReservedListItem1() {}
|
|||||||
void BListItem::_ReservedListItem2() {}
|
void BListItem::_ReservedListItem2() {}
|
||||||
|
|
||||||
|
|
||||||
BListItem::BListItem(const BListItem &item)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
BListItem &
|
|
||||||
BListItem::operator=(const BListItem &)
|
|
||||||
{
|
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
bool
|
bool
|
||||||
BListItem::IsItemVisible() const
|
BListItem::IsItemVisible() const
|
||||||
{
|
{
|
||||||
return fVisible;
|
return fVisible;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
BListItem::SetTop(float top)
|
BListItem::SetTop(float top)
|
||||||
{
|
{
|
||||||
fTop = top;
|
fTop = top;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
BListItem::SetItemVisible(bool visible)
|
BListItem::SetItemVisible(bool visible)
|
||||||
{
|
{
|
||||||
fVisible = visible;
|
fVisible = visible;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// BStringItem
|
|
||||||
BStringItem::BStringItem(const char *text, uint32 level, bool expanded)
|
|
||||||
: BListItem(level, expanded),
|
|
||||||
fText(NULL),
|
|
||||||
fBaselineOffset(0)
|
|
||||||
{
|
|
||||||
SetText(text);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
BStringItem::BStringItem(BMessage *archive)
|
|
||||||
: BListItem(archive),
|
|
||||||
fText(NULL),
|
|
||||||
fBaselineOffset(0)
|
|
||||||
{
|
|
||||||
const char *string;
|
|
||||||
|
|
||||||
if (archive->FindString("_label", &string) == B_OK)
|
|
||||||
SetText(string);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
BStringItem::~BStringItem()
|
|
||||||
{
|
|
||||||
free(fText);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
BArchivable *
|
|
||||||
BStringItem::Instantiate(BMessage *archive)
|
|
||||||
{
|
|
||||||
if (validate_instantiation(archive, "BStringItem"))
|
|
||||||
return new BStringItem(archive);
|
|
||||||
else
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
status_t
|
|
||||||
BStringItem::Archive(BMessage *archive, bool deep) const
|
|
||||||
{
|
|
||||||
status_t status = BListItem::Archive(archive);
|
|
||||||
|
|
||||||
if (status == B_OK && fText != NULL)
|
|
||||||
status = archive->AddString("_label", fText);
|
|
||||||
|
|
||||||
return status;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void
|
|
||||||
BStringItem::DrawItem(BView *owner, BRect frame, bool complete)
|
|
||||||
{
|
|
||||||
if (fText == NULL)
|
|
||||||
return;
|
|
||||||
|
|
||||||
rgb_color highColor = owner->HighColor();
|
|
||||||
rgb_color lowColor = owner->LowColor();
|
|
||||||
|
|
||||||
if (IsSelected() || complete) {
|
|
||||||
if (IsSelected()) {
|
|
||||||
owner->SetHighColor(tint_color(lowColor, B_DARKEN_2_TINT));
|
|
||||||
owner->SetLowColor(owner->HighColor());
|
|
||||||
} else
|
|
||||||
owner->SetHighColor(lowColor);
|
|
||||||
|
|
||||||
owner->FillRect(frame);
|
|
||||||
}
|
|
||||||
|
|
||||||
owner->MovePenTo(frame.left, frame.top + fBaselineOffset);
|
|
||||||
|
|
||||||
rgb_color black = {0, 0, 0, 255};
|
|
||||||
|
|
||||||
if (!IsEnabled())
|
|
||||||
owner->SetHighColor(tint_color(black, B_LIGHTEN_2_TINT));
|
|
||||||
else
|
|
||||||
owner->SetHighColor(black);
|
|
||||||
|
|
||||||
owner->DrawString(fText);
|
|
||||||
|
|
||||||
owner->SetHighColor(highColor);
|
|
||||||
owner->SetLowColor(lowColor);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void
|
|
||||||
BStringItem::SetText(const char *text)
|
|
||||||
{
|
|
||||||
free(fText);
|
|
||||||
fText = NULL;
|
|
||||||
|
|
||||||
if (text)
|
|
||||||
fText = strdup(text);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
const char *
|
|
||||||
BStringItem::Text() const
|
|
||||||
{
|
|
||||||
return fText;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void
|
|
||||||
BStringItem::Update(BView *owner, const BFont *font)
|
|
||||||
{
|
|
||||||
if (fText)
|
|
||||||
SetWidth(owner->StringWidth(fText));
|
|
||||||
|
|
||||||
font_height fheight;
|
|
||||||
font->GetHeight(&fheight);
|
|
||||||
|
|
||||||
fBaselineOffset = fheight.ascent + 2 + floorf(fheight.leading / 2);
|
|
||||||
|
|
||||||
SetHeight(ceilf(fheight.ascent) + ceilf(fheight.descent)
|
|
||||||
+ ceilf(fheight.leading) + 4);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
status_t
|
|
||||||
BStringItem::Perform(perform_code d, void *arg)
|
|
||||||
{
|
|
||||||
return BListItem::Perform(d, arg);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void BStringItem::_ReservedStringItem1() {}
|
|
||||||
void BStringItem::_ReservedStringItem2() {}
|
|
||||||
|
|
||||||
|
|
||||||
BStringItem::BStringItem(const BStringItem &)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
BStringItem &
|
|
||||||
BStringItem::operator=(const BStringItem &)
|
|
||||||
{
|
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -0,0 +1,158 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2001-2009, Haiku, Inc. All Rights Reserved.
|
||||||
|
* Distributed under the terms of the MIT License.
|
||||||
|
*
|
||||||
|
* Authors:
|
||||||
|
* Ulrich Wimboeck
|
||||||
|
* Marc Flerackers ([email protected])
|
||||||
|
* Rene Gollent
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
#include <StringItem.h>
|
||||||
|
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
#include <Message.h>
|
||||||
|
#include <View.h>
|
||||||
|
|
||||||
|
|
||||||
|
BStringItem::BStringItem(const char* text, uint32 level, bool expanded)
|
||||||
|
: BListItem(level, expanded),
|
||||||
|
fText(NULL),
|
||||||
|
fBaselineOffset(0)
|
||||||
|
{
|
||||||
|
SetText(text);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
BStringItem::BStringItem(BMessage* archive)
|
||||||
|
: BListItem(archive),
|
||||||
|
fText(NULL),
|
||||||
|
fBaselineOffset(0)
|
||||||
|
{
|
||||||
|
const char* string;
|
||||||
|
if (archive->FindString("_label", &string) == B_OK)
|
||||||
|
SetText(string);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
BStringItem::~BStringItem()
|
||||||
|
{
|
||||||
|
free(fText);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
BArchivable*
|
||||||
|
BStringItem::Instantiate(BMessage* archive)
|
||||||
|
{
|
||||||
|
if (validate_instantiation(archive, "BStringItem"))
|
||||||
|
return new BStringItem(archive);
|
||||||
|
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
status_t
|
||||||
|
BStringItem::Archive(BMessage *archive, bool deep) const
|
||||||
|
{
|
||||||
|
status_t status = BListItem::Archive(archive);
|
||||||
|
|
||||||
|
if (status == B_OK && fText != NULL)
|
||||||
|
status = archive->AddString("_label", fText);
|
||||||
|
|
||||||
|
return status;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
BStringItem::DrawItem(BView *owner, BRect frame, bool complete)
|
||||||
|
{
|
||||||
|
if (fText == NULL)
|
||||||
|
return;
|
||||||
|
|
||||||
|
rgb_color highColor = owner->HighColor();
|
||||||
|
rgb_color lowColor = owner->LowColor();
|
||||||
|
|
||||||
|
if (IsSelected() || complete) {
|
||||||
|
if (IsSelected()) {
|
||||||
|
owner->SetHighColor(tint_color(lowColor, B_DARKEN_2_TINT));
|
||||||
|
owner->SetLowColor(owner->HighColor());
|
||||||
|
} else
|
||||||
|
owner->SetHighColor(lowColor);
|
||||||
|
|
||||||
|
owner->FillRect(frame);
|
||||||
|
}
|
||||||
|
|
||||||
|
owner->MovePenTo(frame.left, frame.top + fBaselineOffset);
|
||||||
|
|
||||||
|
rgb_color black = {0, 0, 0, 255};
|
||||||
|
|
||||||
|
if (!IsEnabled())
|
||||||
|
owner->SetHighColor(tint_color(black, B_LIGHTEN_2_TINT));
|
||||||
|
else
|
||||||
|
owner->SetHighColor(black);
|
||||||
|
|
||||||
|
owner->DrawString(fText);
|
||||||
|
|
||||||
|
owner->SetHighColor(highColor);
|
||||||
|
owner->SetLowColor(lowColor);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
BStringItem::SetText(const char *text)
|
||||||
|
{
|
||||||
|
free(fText);
|
||||||
|
fText = NULL;
|
||||||
|
|
||||||
|
if (text)
|
||||||
|
fText = strdup(text);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
const char *
|
||||||
|
BStringItem::Text() const
|
||||||
|
{
|
||||||
|
return fText;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
BStringItem::Update(BView *owner, const BFont *font)
|
||||||
|
{
|
||||||
|
if (fText)
|
||||||
|
SetWidth(font->StringWidth(fText));
|
||||||
|
|
||||||
|
font_height fheight;
|
||||||
|
font->GetHeight(&fheight);
|
||||||
|
|
||||||
|
fBaselineOffset = 2 + ceilf(fheight.ascent + fheight.leading / 2);
|
||||||
|
|
||||||
|
SetHeight(ceilf(fheight.ascent) + ceilf(fheight.descent)
|
||||||
|
+ ceilf(fheight.leading) + 4);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
status_t
|
||||||
|
BStringItem::Perform(perform_code d, void *arg)
|
||||||
|
{
|
||||||
|
return BListItem::Perform(d, arg);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void BStringItem::_ReservedStringItem1() {}
|
||||||
|
void BStringItem::_ReservedStringItem2() {}
|
||||||
|
|
||||||
|
|
||||||
|
BStringItem::BStringItem(const BStringItem &)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
BStringItem &
|
||||||
|
BStringItem::operator=(const BStringItem &)
|
||||||
|
{
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user