initiaql check-in, moved repository -- no-longer a fork of

haikuarchives/yab
This commit is contained in:
Jim
2015-04-13 13:40:27 -07:00
parent 9e266ef95f
commit 3e33065a02
234 changed files with 77847 additions and 1 deletions

110
src/column/ColorTools.cpp Normal file
View File

@@ -0,0 +1,110 @@
/*
Open Tracker License
Terms and Conditions
Copyright (c) 1991-2000, Be Incorporated. All rights reserved.
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
of the Software, and to permit persons to whom the Software is furnished to do
so, subject to the following conditions:
The above copyright notice and this permission notice applies to all licensees
and 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 TITLE, MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
BE INCORPORATED 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.
Except as contained in this notice, the name of Be Incorporated shall not be
used in advertising or otherwise to promote the sale, use or other dealings in
this Software without prior written authorization from Be Incorporated.
Tracker(TM), Be(R), BeOS(R), and BeIA(TM) are trademarks or registered trademarks
of Be Incorporated in the United States and other countries. Other brand product
names are registered trademarks or trademarks of their respective holders.
All rights reserved.
*/
/*******************************************************************************
/
/ File: ColorTools.cpp
/
/ Description: Additional experimental color manipulation functions.
/
/ Copyright 2000, Be Incorporated, All Rights Reserved
/
*******************************************************************************/
#include "ColorTools.h"
#if B_BEOS_VERSION <= B_BEOS_VERSION_MAUI
namespace BExperimental {
#if DEBUG
#define DB_INLINE
#else
#define DB_INLINE inline
#endif
static DB_INLINE void mix_color_func(rgb_color* target, const rgb_color other, uint8 amount)
{
target->red = (uint8)( ((int16(other.red)-int16(target->red))*amount)/255
+ target->red );
target->green = (uint8)( ((int16(other.green)-int16(target->green))*amount)/255
+ target->green );
target->blue = (uint8)( ((int16(other.blue)-int16(target->blue))*amount)/255
+ target->blue );
target->alpha = (uint8)( ((int16(other.alpha)-int16(target->alpha))*amount)/255
+ target->alpha );
}
static DB_INLINE void blend_color_func(rgb_color* target, const rgb_color other, uint8 amount)
{
const uint8 alphaMix = (uint8)( ((int16(other.alpha)-int16(255-target->alpha))*amount)/255
+ (255-target->alpha) );
target->red = (uint8)( ((int16(other.red)-int16(target->red))*alphaMix)/255
+ target->red );
target->green = (uint8)( ((int16(other.green)-int16(target->green))*alphaMix)/255
+ target->green );
target->blue = (uint8)( ((int16(other.blue)-int16(target->blue))*alphaMix)/255
+ target->blue );
target->alpha = (uint8)( ((int16(other.alpha)-int16(target->alpha))*amount)/255
+ target->alpha );
}
static DB_INLINE void disable_color_func(rgb_color* target, const rgb_color background)
{
blend_color_func(target, background, 255-70);
}
// --------------------------------------------------------------------------
rgb_color mix_color(rgb_color color1, rgb_color color2, uint8 amount)
{
mix_color_func(&color1, color2, amount);
return color1;
}
rgb_color blend_color(rgb_color color1, rgb_color color2, uint8 amount)
{
blend_color_func(&color1, color2, amount);
return color1;
}
rgb_color disable_color(rgb_color color, rgb_color background)
{
disable_color_func(&color, background);
return color;
}
}
#endif

107
src/column/ColorTools.h Normal file
View File

@@ -0,0 +1,107 @@
/*
Open Tracker License
Terms and Conditions
Copyright (c) 1991-2000, Be Incorporated. All rights reserved.
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
of the Software, and to permit persons to whom the Software is furnished to do
so, subject to the following conditions:
The above copyright notice and this permission notice applies to all licensees
and 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 TITLE, MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
BE INCORPORATED 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.
Except as contained in this notice, the name of Be Incorporated shall not be
used in advertising or otherwise to promote the sale, use or other dealings in
this Software without prior written authorization from Be Incorporated.
Tracker(TM), Be(R), BeOS(R), and BeIA(TM) are trademarks or registered trademarks
of Be Incorporated in the United States and other countries. Other brand product
names are registered trademarks or trademarks of their respective holders.
All rights reserved.
*/
/*******************************************************************************
/
/ File: ColorTools.h
/
/ Description: Additional experimental color manipulation functions.
/
/ Copyright 2000, Be Incorporated, All Rights Reserved
/
*******************************************************************************/
#ifndef _COLOR_TOOLS_H
#define _COLOR_TOOLS_H
#include <GraphicsDefs.h>
#if B_BEOS_VERSION <= B_BEOS_VERSION_MAUI
namespace BExperimental {
// Comparison operators.
inline bool operator==(const rgb_color c1, const rgb_color c2)
{
return (*((uint32*)&c1)) == (*((uint32*)&c2));
}
inline bool operator!=(const rgb_color c1, const rgb_color c2)
{
return (*((uint32*)&c1)) != (*((uint32*)&c2));
}
// Color creation.
#ifndef HAIKU
inline rgb_color make_color(uint8 red, uint8 green, uint8 blue, uint8 alpha=255)
{
rgb_color c;
c.red = red;
c.green = green;
c.blue = blue;
c.alpha = alpha;
return c;
}
#endif
// Mix two colors together, ignoring their relative alpha channels.
// If amount is 0, the result is color1; if 255, the result is color2;
// if another value, it is somewhere in-between. The resulting alpha
// channel is mixed exactly like the other color channels.
rgb_color mix_color(rgb_color color1, rgb_color color2, uint8 amount);
// Blend two colors together, weighting by their relative alpha channels.
// The resulting color is the same as mix_color(), except that the amount
// used from color1 and color2's color channels is dependent on that color's
// alpha channel. For example, if color1.alpha is 0 and color2.alpha is
// 255, the resulting red, green, and blue values will be the same as those
// in color2, regardless of 'amount'.
rgb_color blend_color(rgb_color color1, rgb_color color2, uint8 amount);
// Return a color that is the disabled representation of 'color' when drawn
// on a solid color 'background'.
rgb_color disable_color(rgb_color color, rgb_color background);
} // namespace BExperimental
using namespace BExperimental;
#endif
#endif

File diff suppressed because it is too large Load Diff

409
src/column/ColumnListView.h Normal file
View File

@@ -0,0 +1,409 @@
/*
Open Tracker License
Terms and Conditions
Copyright (c) 1991-2000, Be Incorporated. All rights reserved.
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
of the Software, and to permit persons to whom the Software is furnished to do
so, subject to the following conditions:
The above copyright notice and this permission notice applies to all licensees
and 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 TITLE, MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
BE INCORPORATED 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.
Except as contained in this notice, the name of Be Incorporated shall not be
used in advertising or otherwise to promote the sale, use or other dealings in
this Software without prior written authorization from Be Incorporated.
Tracker(TM), Be(R), BeOS(R), and BeIA(TM) are trademarks or registered trademarks
of Be Incorporated in the United States and other countries. Other brand product
names are registered trademarks or trademarks of their respective holders.
All rights reserved.
*/
/*******************************************************************************
/
/ File: ColumnListView.h
/
/ Description: Experimental multi-column list view.
/
/ Copyright 2000+, Be Incorporated, All Rights Reserved
/
*******************************************************************************/
#ifndef _COLUMN_LIST_VIEW_H
#define _COLUMN_LIST_VIEW_H
#include <BeBuild.h>
#include <View.h>
#include <List.h>
#include <Invoker.h>
#include <ListView.h>
class BScrollBar;
namespace BPrivate {
class OutlineView;
class TitleView;
class BRowContainer;
class RecursiveOutlineIterator;
} // ns BPrivate
class BField;
class BRow;
class BColumn;
class BColumnListView;
enum LatchType {
B_NO_LATCH = 0,
B_OPEN_LATCH = 1,
B_PRESSED_LATCH = 2,
B_CLOSED_LATCH = 3
};
typedef enum {
B_ALLOW_COLUMN_NONE = 0,
B_ALLOW_COLUMN_MOVE = 1,
B_ALLOW_COLUMN_RESIZE = 2,
B_ALLOW_COLUMN_POPUP = 4,
B_ALLOW_COLUMN_REMOVE = 8
} column_flags;
enum ColumnListViewColor {
B_COLOR_BACKGROUND = 0,
B_COLOR_TEXT = 1,
B_COLOR_ROW_DIVIDER = 2,
B_COLOR_SELECTION = 3,
B_COLOR_SELECTION_TEXT = 4,
B_COLOR_NON_FOCUS_SELECTION = 5,
B_COLOR_EDIT_BACKGROUND = 6,
B_COLOR_EDIT_TEXT = 7,
B_COLOR_HEADER_BACKGROUND = 8,
B_COLOR_HEADER_TEXT = 9,
B_COLOR_SEPARATOR_LINE = 10,
B_COLOR_SEPARATOR_BORDER = 11,
B_COLOR_TOTAL = 12
};
enum ColumnListViewFont {
B_FONT_ROW = 0,
B_FONT_HEADER = 1,
B_FONT_TOTAL = 2
};
// A single row/column intersection in the list.
class BField {
public:
BField();
virtual ~BField();
};
// A single line in the list. Each line contains a BField object
// for each column in the list, associated by their "logical field"
// index. Hierarchies are formed by adding other BRow objects as
// a parent of a row, using the AddRow() function in BColumnListView().
class BRow {
public:
BRow(float height = 16.0);
virtual ~BRow();
virtual bool HasLatch() const;
int32 CountFields() const;
BField* GetField(int32 logicalFieldIndex);
const BField* GetField(int32 logicalFieldIndex) const;
void SetField(BField* field,
int32 logicalFieldIndex);
float Height() const;
bool IsExpanded() const;
private:
// Blows up into the debugger if the validation fails.
void ValidateFields() const;
void ValidateField(const BField* field,
int32 logicalFieldIndex) const;
private:
BList fFields;
BPrivate::
BRowContainer* fChildList;
bool fIsExpanded;
float fHeight;
BRow* fNextSelected;
BRow* fPrevSelected;
BRow* fParent;
BColumnListView* fList;
friend class BColumnListView;
friend class BPrivate::RecursiveOutlineIterator;
friend class BPrivate::OutlineView;
};
// Information about a single column in the list. A column knows
// how to display the BField objects that occur at its location in
// each of the list's rows. See ColumnTypes.h for particular
// subclasses of BField and BColumn that handle common data types.
class BColumn {
public:
BColumn(float width, float minWidth,
float maxWidth,
alignment align = B_ALIGN_LEFT);
virtual ~BColumn();
float Width() const;
void SetWidth(float width);
float MinWidth() const;
float MaxWidth() const;
virtual void DrawTitle(BRect rect, BView* targetView);
virtual void DrawField(BField* field, BRect rect,
BView* targetView);
virtual int CompareFields(BField* field1, BField* field2);
virtual void MouseMoved(BColumnListView* parent, BRow* row,
BField* field, BRect fieldRect,
BPoint point, uint32 buttons, int32 code);
virtual void MouseDown(BColumnListView* parent, BRow* row,
BField* field, BRect fieldRect,
BPoint point, uint32 buttons);
virtual void MouseUp(BColumnListView* parent, BRow* row,
BField* field);
virtual void GetColumnName(BString* into) const;
virtual float GetPreferredWidth(BField* field,
BView* parent) const;
bool IsVisible() const;
void SetVisible(bool);
bool WantsEvents() const;
void SetWantsEvents(bool);
bool ShowHeading() const;
void SetShowHeading(bool);
alignment Alignment() const;
void SetAlignment(alignment);
int32 LogicalFieldNum() const;
/*!
\param field The BField derivative to validate.
Implement this function on your BColumn derivatives to validate
BField derivatives that your BColumn will be drawing/manipulating.
This function will be called when BFields are added to the Column,
use dynamic_cast<> to determine if it is of a kind that your
BColumn know how ot handle. return false if it is not.
\note The debugger will be called if you return false from here
with information about what type of BField and BColumn and the
logical field index where it occured.
\note Do not call the inherited version of this, it just returns
true;
*/
virtual bool AcceptsField(const BField* field) const;
private:
float fWidth;
float fMinWidth;
float fMaxWidth;
bool fVisible;
int32 fFieldID;
BColumnListView* fList;
bool fSortAscending;
bool fWantsEvents;
bool fShowHeading;
alignment fAlignment;
friend class BPrivate::OutlineView;
friend class BColumnListView;
friend class BPrivate::TitleView;
};
// The column list view class.
class BColumnListView : public BView, public BInvoker {
public:
BColumnListView(BRect rect,
const char* name, uint32 resizingMode,
uint32 flags, border_style = B_NO_BORDER,
bool showHorizontalScrollbar = true);
BColumnListView(const char* name,
uint32 flags, border_style = B_NO_BORDER,
bool showHorizontalScrollbar = true);
virtual ~BColumnListView();
// Interaction
virtual bool InitiateDrag(BPoint, bool wasSelected);
virtual void MessageDropped(BMessage*, BPoint point);
virtual void ExpandOrCollapse(BRow* row, bool expand);
virtual status_t Invoke(BMessage* message = NULL);
virtual void ItemInvoked();
virtual void SetInvocationMessage(BMessage* message);
BMessage* InvocationMessage() const;
uint32 InvocationCommand() const;
BRow* FocusRow() const;
void SetFocusRow(int32 index, bool select = false);
void SetFocusRow(BRow* row, bool select = false);
void SetMouseTrackingEnabled(bool);
// Selection
list_view_type SelectionMode() const;
void Deselect(BRow* row);
void AddToSelection(BRow* row);
void DeselectAll();
BRow* CurrentSelection(BRow* lastSelected = 0) const;
virtual void SelectionChanged();
virtual void SetSelectionMessage(BMessage* message);
BMessage* SelectionMessage();
uint32 SelectionCommand() const;
void SetSelectionMode(list_view_type type);
// list_view_type is defined in ListView.h.
// Sorting
void SetSortingEnabled(bool);
bool SortingEnabled() const;
void SetSortColumn(BColumn* column, bool add,
bool ascending);
void ClearSortColumns();
// The status view is a little area in the lower left hand corner.
void AddStatusView(BView* view);
BView* RemoveStatusView();
// Column Manipulation
void AddColumn(BColumn* column,
int32 logicalFieldIndex);
void MoveColumn(BColumn* column, int32 index);
void RemoveColumn(BColumn* column);
int32 CountColumns() const;
BColumn* ColumnAt(int32 index) const;
BColumn* ColumnAt(BPoint point) const;
void SetColumnVisible(BColumn* column,
bool isVisible);
void SetColumnVisible(int32, bool);
bool IsColumnVisible(int32) const;
void SetColumnFlags(column_flags flags);
void ResizeColumnToPreferred(int32 index);
void ResizeAllColumnsToPreferred();
// Row manipulation
const BRow* RowAt(int32 index, BRow *parent = 0) const;
BRow* RowAt(int32 index, BRow *parent = 0);
const BRow* RowAt(BPoint) const;
BRow* RowAt(BPoint);
bool GetRowRect(const BRow* row, BRect* _rect) const;
bool FindParent(BRow* row, BRow** _parent,
bool *_isVisible) const;
int32 IndexOf(BRow* row);
int32 CountRows(BRow* parent = 0) const;
void AddRow(BRow* row, BRow* parent = NULL);
void AddRow(BRow* row, int32 index,
BRow* parent = NULL);
void ScrollTo(const BRow* Row);
void ScrollTo(BPoint point);
// Does not delete row or children at this time.
// todo: Make delete row and children
void RemoveRow(BRow* row);
void UpdateRow(BRow* row);
void Clear();
// Appearance (DEPRECATED)
void GetFont(BFont* font) const
{ BView::GetFont(font); }
virtual void SetFont(const BFont* font,
uint32 mask = B_FONT_ALL);
virtual void SetHighColor(rgb_color);
void SetSelectionColor(rgb_color);
void SetBackgroundColor(rgb_color);
void SetEditColor(rgb_color);
const rgb_color SelectionColor() const;
const rgb_color BackgroundColor() const;
const rgb_color EditColor() const;
// Appearance (NEW STYLE)
void SetColor(ColumnListViewColor colorIndex,
rgb_color color);
void SetFont(ColumnListViewFont fontIndex,
const BFont* font,
uint32 mask = B_FONT_ALL);
rgb_color Color(ColumnListViewColor colorIndex) const;
void GetFont(ColumnListViewFont fontIndex,
BFont* font) const;
BPoint SuggestTextPosition(const BRow* row,
const BColumn* column = NULL) const;
void SetLatchWidth(float width);
float LatchWidth() const;
virtual void DrawLatch(BView* view, BRect frame,
LatchType type, BRow* row);
virtual void MakeFocus(bool isfocus = true);
void SaveState(BMessage* archive);
void LoadState(BMessage* archive);
BView* ScrollView() const
{ return (BView*)fOutlineView; }
void SetEditMode(bool state);
void Refresh();
virtual BSize MinSize();
virtual BSize PreferredSize();
virtual BSize MaxSize();
virtual void InvalidateLayout(bool descendants = false);
protected:
virtual void MessageReceived(BMessage* message);
virtual void KeyDown(const char* bytes, int32 numBytes);
virtual void AttachedToWindow();
virtual void WindowActivated(bool active);
virtual void Draw(BRect updateRect);
virtual void DoLayout();
private:
void _Init(bool showHorizontalScrollbar);
void _GetChildViewRects(const BRect& bounds,
bool showHorizontalScrollBar,
BRect& titleRect, BRect& outlineRect,
BRect& vScrollBarRect,
BRect& hScrollBarRect);
rgb_color fColorList[B_COLOR_TOTAL];
BPrivate::TitleView* fTitleView;
BPrivate::OutlineView* fOutlineView;
BList fColumns;
BScrollBar* fHorizontalScrollBar;
BScrollBar* fVerticalScrollBar;
BList fSortColumns;
BView* fStatusView;
BMessage* fSelectionMessage;
bool fSortingEnabled;
float fLatchWidth;
border_style fBorderStyle;
};
#endif // _COLUMN_LIST_VIEW_H

704
src/column/ColumnTypes.cpp Normal file
View File

@@ -0,0 +1,704 @@
/*
Open Tracker License
Terms and Conditions
Copyright (c) 1991-2000, Be Incorporated. All rights reserved.
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
of the Software, and to permit persons to whom the Software is furnished to do
so, subject to the following conditions:
The above copyright notice and this permission notice applies to all licensees
and 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 TITLE, MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
BE INCORPORATED 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.
Except as contained in this notice, the name of Be Incorporated shall not be
used in advertising or otherwise to promote the sale, use or other dealings in
this Software without prior written authorization from Be Incorporated.
Tracker(TM), Be(R), BeOS(R), and BeIA(TM) are trademarks or registered trademarks
of Be Incorporated in the United States and other countries. Other brand product
names are registered trademarks or trademarks of their respective holders.
All rights reserved.
*/
/*******************************************************************************
/
/ File: ColumnTypes.h
/
/ Description: Experimental classes that implement particular column/field
/ data types for use in BColumnListView.
/
/ Copyright 2000+, Be Incorporated, All Rights Reserved
/
*******************************************************************************/
#include "ColumnTypes.h"
#include <stdio.h>
#include <View.h>
#include <parsedate.h>
#define kTEXT_MARGIN 8
//=====================================================================
BTitledColumn::BTitledColumn(const char* title, float width, float minWidth,
float maxWidth, alignment align)
:BColumn(width, minWidth, maxWidth, align),
fTitle(title)
{
font_height fh;
be_plain_font->GetHeight(&fh);
fFontHeight = fh.descent + fh.leading;
}
//--------------------------------------------------------------------
void BTitledColumn::DrawTitle(BRect rect, BView* parent)
{
float width = rect.Width() - (2 * kTEXT_MARGIN);
BString out_string(fTitle);
parent->TruncateString(&out_string, B_TRUNCATE_END, width + 2);
DrawString(out_string.String(), parent, rect);
}
//--------------------------------------------------------------------
void BTitledColumn::GetColumnName(BString* into) const
{
*into = fTitle;
}
//--------------------------------------------------------------------
void BTitledColumn::DrawString(const char* string, BView* parent, BRect rect)
{
float width = rect.Width() - (2 * kTEXT_MARGIN);
float y;
BFont font;
font_height finfo;
parent->GetFont(&font);
font.GetHeight(&finfo);
y = rect.top + ((rect.Height() - (finfo.ascent + finfo.descent + finfo.leading)) / 2) +
(finfo.ascent + finfo.descent) - 2;
switch (Alignment())
{
case B_ALIGN_LEFT:
parent->MovePenTo(rect.left + kTEXT_MARGIN, y);
break;
case B_ALIGN_CENTER:
parent->MovePenTo(rect.left + kTEXT_MARGIN + ((width - font.StringWidth(string)) / 2), y);
break;
case B_ALIGN_RIGHT:
parent->MovePenTo(rect.right - kTEXT_MARGIN - font.StringWidth(string), y);
break;
}
parent->DrawString(string);
}
//--------------------------------------------------------------------
void BTitledColumn::SetTitle(const char* title)
{
fTitle.SetTo(title);
}
//--------------------------------------------------------------------
void BTitledColumn::Title(BString* forTitle) const
{
if (forTitle)
forTitle->SetTo(fTitle.String());
}
//--------------------------------------------------------------------
float BTitledColumn::FontHeight() const
{
return fFontHeight;
}
// #pragma mark -
//=====================================================================
BStringField::BStringField(const char* string)
:fWidth(0),
fString(string),
fClippedString(string)
{
}
//--------------------------------------------------------------------
void BStringField::SetString(const char* val)
{
fString = val;
fClippedString = "";
fWidth = 0;
}
//--------------------------------------------------------------------
const char* BStringField::String() const
{
return fString.String();
}
//--------------------------------------------------------------------
void BStringField::SetWidth(float width)
{
fWidth = width;
}
//--------------------------------------------------------------------
float BStringField::Width()
{
return fWidth;
}
//--------------------------------------------------------------------
void BStringField::SetClippedString(const char* val)
{
fClippedString = val;
}
//--------------------------------------------------------------------
const char* BStringField::ClippedString()
{
return fClippedString.String();
}
// #pragma mark -
//=====================================================================
BStringColumn::BStringColumn(const char* title, float width, float minWidth,
float maxWidth, uint32 truncate, alignment align)
:BTitledColumn(title, width, minWidth, maxWidth, align),
fTruncate(truncate)
{
}
//--------------------------------------------------------------------
void BStringColumn::DrawField(BField* _field, BRect rect, BView* parent)
{
float width = rect.Width() - (2 * kTEXT_MARGIN);
BStringField* field = static_cast<BStringField*>(_field);
if (width != field->Width())
{
BString out_string(field->String());
parent->TruncateString(&out_string, fTruncate, width + 2);
field->SetClippedString(out_string.String());
field->SetWidth(width);
}
DrawString(field->ClippedString(), parent, rect);
}
//--------------------------------------------------------------------
int BStringColumn::CompareFields(BField* field1, BField* field2)
{
return(ICompare(((BStringField*)field1)->String(),
(((BStringField*)field2)->String())));
}
//--------------------------------------------------------------------
bool BStringColumn::AcceptsField(const BField *field) const
{
return static_cast<bool>(dynamic_cast<const BStringField*>(field));
}
// #pragma mark -
//=====================================================================
BDateField::BDateField(time_t *t)
:fTime(*localtime(t)),
fUnixTime(*t),
fSeconds(0),
fClippedString(""),
fWidth(0)
{
fSeconds = mktime(&fTime);
}
//--------------------------------------------------------------------
void BDateField::SetWidth(float width)
{
fWidth = width;
}
//--------------------------------------------------------------------
float BDateField::Width()
{
return fWidth;
}
//--------------------------------------------------------------------
void BDateField::SetClippedString(const char* val)
{
fClippedString = val;
}
//--------------------------------------------------------------------
const char* BDateField::ClippedString()
{
return fClippedString.String();
}
//--------------------------------------------------------------------
time_t BDateField::Seconds()
{
return fSeconds;
}
//--------------------------------------------------------------------
time_t BDateField::UnixTime()
{
return fUnixTime;
}
// #pragma mark -
//=====================================================================
BDateColumn::BDateColumn(const char* title, float width, float minWidth,
float maxWidth, alignment align)
:BTitledColumn(title, width, minWidth, maxWidth, align),
fTitle(title)
{
}
//--------------------------------------------------------------------
const char *kTIME_FORMATS[] = {
"%A, %B %d %Y, %I:%M:%S %p", // Monday, July 09 1997, 05:08:15 PM
"%a, %b %d %Y, %I:%M:%S %p", // Mon, Jul 09 1997, 05:08:15 PM
"%a, %b %d %Y, %I:%M %p", // Mon, Jul 09 1997, 05:08 PM
"%b %d %Y, %I:%M %p", // Jul 09 1997, 05:08 PM
"%m/%d/%y, %I:%M %p", // 07/09/97, 05:08 PM
"%m/%d/%y", // 07/09/97
NULL
};
void BDateColumn::DrawField(BField* _field, BRect rect, BView* parent)
{
float width = rect.Width() - (2 * kTEXT_MARGIN);
BDateField* field = (BDateField*)_field;
if (field->Width() != rect.Width())
{
char dateString[256];
time_t curtime = field->UnixTime();
tm time_data;
BFont font;
parent->GetFont(&font);
localtime_r(&curtime, &time_data);
for (int32 index = 0; ; index++)
{
if (!kTIME_FORMATS[index])
break;
strftime(dateString, 256, kTIME_FORMATS[index], &time_data);
if (font.StringWidth(dateString) <= width)
break;
}
if (font.StringWidth(dateString) > width)
{
BString out_string(dateString);
parent->TruncateString(&out_string, B_TRUNCATE_MIDDLE, width + 2);
strcpy(dateString, out_string.String());
}
field->SetClippedString(dateString);
field->SetWidth(width);
}
DrawString(field->ClippedString(), parent, rect);
}
//--------------------------------------------------------------------
int BDateColumn::CompareFields(BField* field1, BField* field2)
{
return((BDateField*)field1)->Seconds() - ((BDateField*)field2)->Seconds();
}
// #pragma mark -
//=====================================================================
BSizeField::BSizeField(off_t size)
:fSize(size)
{
}
//--------------------------------------------------------------------
void BSizeField::SetSize(off_t size)
{
fSize = size;
}
//--------------------------------------------------------------------
off_t BSizeField::Size()
{
return fSize;
}
// #pragma mark -
//=====================================================================
BSizeColumn::BSizeColumn(const char* title, float width, float minWidth,
float maxWidth, alignment align)
:BTitledColumn(title, width, minWidth, maxWidth, align)
{
}
//--------------------------------------------------------------------
const int64 kKB_SIZE = 1024;
const int64 kMB_SIZE = 1048576;
const int64 kGB_SIZE = 1073741824;
const int64 kTB_SIZE = kGB_SIZE * kKB_SIZE;
const char *kSIZE_FORMATS[] = {
"%.2f %s",
"%.1f %s",
"%.f %s",
"%.f%s",
0
};
void BSizeColumn::DrawField(BField* _field, BRect rect, BView* parent)
{
char str[256];
float width = rect.Width() - (2 * kTEXT_MARGIN);
BFont font;
BString string;
off_t size = ((BSizeField*)_field)->Size();
parent->GetFont(&font);
if (size < kKB_SIZE)
{
sprintf(str, "%Ld bytes", size);
if (font.StringWidth(str) > width)
sprintf(str, "%Ld B", size);
}
else
{
const char* suffix;
float float_value;
if (size >= kTB_SIZE)
{
suffix = "TB";
float_value = (float)size / kTB_SIZE;
}
else if (size >= kGB_SIZE)
{
suffix = "GB";
float_value = (float)size / kGB_SIZE;
}
else if (size >= kMB_SIZE)
{
suffix = "MB";
float_value = (float)size / kMB_SIZE;
}
else
{
suffix = "KB";
float_value = (float)size / kKB_SIZE;
}
for (int32 index = 0; ; index++)
{
if (!kSIZE_FORMATS[index])
break;
sprintf(str, kSIZE_FORMATS[index], float_value, suffix);
// strip off an insignificant zero so we don't get readings
// such as 1.00
char *period = 0;
char *tmp (NULL);
for (tmp = str; *tmp; tmp++)
{
if (*tmp == '.')
period = tmp;
}
if (period && period[1] && period[2] == '0')
// move the rest of the string over the insignificant zero
for (tmp = &period[2]; *tmp; tmp++)
*tmp = tmp[1];
if (font.StringWidth(str) <= width)
break;
}
}
string = str;
parent->TruncateString(&string, B_TRUNCATE_MIDDLE, width + 2);
DrawString(string.String(), parent, rect);
}
//--------------------------------------------------------------------
int BSizeColumn::CompareFields(BField* field1, BField* field2)
{
return ((BSizeField*)field1)->Size() - ((BSizeField*)field2)->Size();
}
// #pragma mark -
//=====================================================================
BIntegerField::BIntegerField(int32 number)
:fInteger(number)
{
}
//--------------------------------------------------------------------
void BIntegerField::SetValue(int32 value)
{
fInteger = value;
}
//--------------------------------------------------------------------
int32 BIntegerField::Value()
{
return fInteger;
}
// #pragma mark -
//=====================================================================
BIntegerColumn::BIntegerColumn(const char* title, float width, float minWidth,
float maxWidth, alignment align)
:BTitledColumn(title, width, minWidth, maxWidth, align)
{
}
//--------------------------------------------------------------------
void BIntegerColumn::DrawField(BField *field, BRect rect, BView* parent)
{
char formatted[256];
float width = rect.Width() - (2 * kTEXT_MARGIN);
BString string;
sprintf(formatted, "%d", (int)((BIntegerField*)field)->Value());
string = formatted;
parent->TruncateString(&string, B_TRUNCATE_MIDDLE, width + 2);
DrawString(string.String(), parent, rect);
}
//--------------------------------------------------------------------
int BIntegerColumn::CompareFields(BField *field1, BField *field2)
{
return (((BIntegerField*)field1)->Value() - ((BIntegerField*)field2)->Value());
}
// #pragma mark -
//=====================================================================
GraphColumn::GraphColumn(const char* name, float width, float minWidth,
float maxWidth, alignment align)
:BIntegerColumn(name, width, minWidth, maxWidth, align)
{
}
//--------------------------------------------------------------------
void GraphColumn::DrawField(BField* field, BRect rect, BView* parent)
{
int number = ((BIntegerField*)field)->Value();
if (number > 100)
number = 100;
else if (number < 0)
number = 0;
BRect graphRect(rect);
graphRect.InsetBy(5, 3);
parent->StrokeRect(graphRect);
if (number > 0) {
graphRect.InsetBy(1, 1);
float val = graphRect.Width() * (float) number / 100;
graphRect.right = graphRect.left + val;
parent->SetHighColor(0, 0, 190);
parent->FillRect(graphRect);
}
parent->SetDrawingMode(B_OP_INVERT);
parent->SetHighColor(128, 128, 128);
char numstr[256];
sprintf(numstr, "%d%%", number);
float width = be_plain_font->StringWidth(numstr);
parent->MovePenTo(rect.left + rect.Width() / 2 - width / 2, rect.bottom - FontHeight());
parent->DrawString(numstr);
}
// #pragma mark -
//=====================================================================
BBitmapField::BBitmapField(BBitmap *bitmap)
:fBitmap(bitmap)
{
}
//--------------------------------------------------------------------
const BBitmap* BBitmapField::Bitmap()
{
return fBitmap;
}
//--------------------------------------------------------------------
void BBitmapField::SetBitmap(BBitmap* bitmap)
{
fBitmap = bitmap;
}
// #pragma mark -
//=====================================================================
BBitmapColumn::BBitmapColumn(const char* title, float width, float minWidth,
float maxWidth, alignment align)
:BTitledColumn(title, width, minWidth, maxWidth, align)
{
}
//--------------------------------------------------------------------
void BBitmapColumn::DrawField(BField* field, BRect rect, BView* parent)
{
BBitmapField *bitmapField = static_cast<BBitmapField *>(field);
const BBitmap *bitmap = bitmapField->Bitmap();
if (bitmap != NULL)
{
float x = 0.0;
float y;
BRect r = bitmap->Bounds();
y = rect.top + ((rect.Height() - r.Height()) / 2);
switch (Alignment())
{
case B_ALIGN_LEFT:
x = rect.left + kTEXT_MARGIN;
break;
case B_ALIGN_CENTER:
x = rect.left + ((rect.Width() - r.Width()) / 2);
break;
case B_ALIGN_RIGHT:
x = rect.right - kTEXT_MARGIN - r.Width();
break;
}
parent->SetDrawingMode(B_OP_ALPHA);
parent->DrawBitmap(bitmap, BPoint(x, y));
parent->SetDrawingMode(B_OP_OVER);
}
}
//--------------------------------------------------------------------
int BBitmapColumn::CompareFields(BField* /*field1*/, BField* /*field2*/)
{
// Comparing bitmaps doesn't really make sense...
return 0;
}
//--------------------------------------------------------------------
bool
BBitmapColumn::AcceptsField(const BField *field) const
{
return static_cast<bool>(dynamic_cast<const BBitmapField*>(field));
}

289
src/column/ColumnTypes.h Normal file
View File

@@ -0,0 +1,289 @@
/*
Open Tracker License
Terms and Conditions
Copyright (c) 1991-2000, Be Incorporated. All rights reserved.
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
of the Software, and to permit persons to whom the Software is furnished to do
so, subject to the following conditions:
The above copyright notice and this permission notice applies to all licensees
and 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 TITLE, MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
BE INCORPORATED 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.
Except as contained in this notice, the name of Be Incorporated shall not be
used in advertising or otherwise to promote the sale, use or other dealings in
this Software without prior written authorization from Be Incorporated.
Tracker(TM), Be(R), BeOS(R), and BeIA(TM) are trademarks or registered trademarks
of Be Incorporated in the United States and other countries. Other brand product
names are registered trademarks or trademarks of their respective holders.
All rights reserved.
*/
/*******************************************************************************
/
/ File: ColumnTypes.h
/
/ Description: Experimental classes that implement particular column/field
/ data types for use in BColumnListView.
/
/ Copyright 2000+, Be Incorporated, All Rights Reserved
/
*******************************************************************************/
#ifndef _COLUMN_TYPES_H
#define _COLUMN_TYPES_H
#include "ColumnListView.h"
#include <String.h>
#include <Font.h>
#include <Bitmap.h>
//=====================================================================
// Common base-class: a column that draws a standard title at its top.
class BTitledColumn : public BColumn
{
public:
BTitledColumn (const char *title,
float width,
float minWidth,
float maxWidth,
alignment align = B_ALIGN_LEFT);
virtual void DrawTitle (BRect rect,
BView* parent);
virtual void GetColumnName (BString* into) const;
void DrawString (const char*,
BView*,
BRect);
void SetTitle (const char* title);
void Title (BString* forTitle) const; // sets the BString arg to be the title
float FontHeight () const;
private:
float fFontHeight;
BString fTitle;
};
//=====================================================================
// Field and column classes for strings.
class BStringField : public BField
{
public:
BStringField (const char* string);
void SetString (const char* string);
const char* String () const;
void SetClippedString (const char* string);
const char* ClippedString ();
void SetWidth (float);
float Width ();
private:
float fWidth;
BString fString;
BString fClippedString;
};
//--------------------------------------------------------------------
class BStringColumn : public BTitledColumn
{
public:
BStringColumn (const char *title,
float width,
float maxWidth,
float minWidth,
uint32 truncate,
alignment align = B_ALIGN_LEFT);
virtual void DrawField (BField* field,
BRect rect,
BView* parent);
virtual int CompareFields (BField* field1,
BField* field2);
virtual bool AcceptsField (const BField* field) const;
private:
uint32 fTruncate;
};
//=====================================================================
// Field and column classes for dates.
class BDateField : public BField
{
public:
BDateField (time_t* t);
void SetWidth (float);
float Width ();
void SetClippedString (const char*);
const char* ClippedString ();
time_t Seconds ();
time_t UnixTime ();
private:
struct tm fTime;
time_t fUnixTime;
time_t fSeconds;
BString fClippedString;
float fWidth;
};
//--------------------------------------------------------------------
class BDateColumn : public BTitledColumn
{
public:
BDateColumn (const char* title,
float width,
float minWidth,
float maxWidth,
alignment align = B_ALIGN_LEFT);
virtual void DrawField (BField* field,
BRect rect,
BView* parent);
virtual int CompareFields (BField* field1,
BField* field2);
private:
BString fTitle;
};
//=====================================================================
// Field and column classes for numeric sizes.
class BSizeField : public BField
{
public:
BSizeField (off_t size);
void SetSize (off_t);
off_t Size ();
private:
off_t fSize;
};
//--------------------------------------------------------------------
class BSizeColumn : public BTitledColumn
{
public:
BSizeColumn (const char* title,
float width,
float minWidth,
float maxWidth,
alignment align = B_ALIGN_LEFT);
virtual void DrawField (BField* field,
BRect rect,
BView* parent);
virtual int CompareFields (BField* field1,
BField* field2);
};
//=====================================================================
// Field and column classes for integers.
class BIntegerField : public BField
{
public:
BIntegerField (int32 number);
void SetValue (int32);
int32 Value ();
private:
int32 fInteger;
};
//--------------------------------------------------------------------
class BIntegerColumn : public BTitledColumn
{
public:
BIntegerColumn (const char* title,
float width,
float minWidth,
float maxWidth,
alignment align = B_ALIGN_LEFT);
virtual void DrawField (BField* field,
BRect rect,
BView* parent);
virtual int CompareFields (BField* field1,
BField* field2);
};
//=====================================================================
// Field and column classes for bitmaps
class BBitmapField : public BField
{
public:
BBitmapField (BBitmap* bitmap);
const BBitmap* Bitmap ();
void SetBitmap (BBitmap* bitmap);
private:
BBitmap* fBitmap;
};
//--------------------------------------------------------------------
class BBitmapColumn : public BTitledColumn
{
public:
BBitmapColumn (const char* title,
float width,
float minWidth,
float maxWidth,
alignment align = B_ALIGN_LEFT);
virtual void DrawField (BField*field,
BRect rect,
BView* parent);
virtual int CompareFields (BField* field1, BField* field2);
virtual bool AcceptsField (const BField* field) const;
};
//=====================================================================
// Column to display BIntegerField objects as a graph.
class GraphColumn : public BIntegerColumn
{
public:
GraphColumn (const char* name,
float width,
float minWidth,
float maxWidth,
alignment align = B_ALIGN_LEFT);
virtual void DrawField (BField*field,
BRect rect,
BView* parent);
};
#endif

800
src/column/ObjectList.h Normal file
View File

@@ -0,0 +1,800 @@
/*
Open Tracker License
Terms and Conditions
Copyright (c) 1991-2000, Be Incorporated. All rights reserved.
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
of the Software, and to permit persons to whom the Software is furnished to do
so, subject to the following conditions:
The above copyright notice and this permission notice applies to all licensees
and 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 TITLE, MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
BE INCORPORATED 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.
Except as contained in this notice, the name of Be Incorporated shall not be
used in advertising or otherwise to promote the sale, use or other dealings in
this Software without prior written authorization from Be Incorporated.
Tracker(TM), Be(R), BeOS(R), and BeIA(TM) are trademarks or registered trademarks
of Be Incorporated in the United States and other countries. Other brand product
names are registered trademarks or trademarks of their respective holders.
All rights reserved.
*/
/****************************************************************************
** WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING **
** **
** DANGER, WILL ROBINSON! **
** **
** The interfaces contained here are part of BeOS's **
** **
** >> PRIVATE NOT FOR PUBLIC USE << **
** **
** implementation. **
** **
** These interfaces WILL CHANGE in future releases. **
** If you use them, your app WILL BREAK at some future time. **
** **
** (And yes, this does mean that binaries built from OpenTracker will not **
** be compatible with some future releases of the OS. When that happens, **
** we will provide an updated version of this file to keep compatibility.) **
** **
** WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING **
****************************************************************************/
//
// ObjectList is a wrapper around BList that adds type safety,
// optional object ownership, search, insert operations, etc.
//
#ifndef __OBJECT_LIST__
#define __OBJECT_LIST__
#ifndef _BE_H
#include <List.h>
#endif
#include <Debug.h>
template<class T> class BObjectList;
template<class T>
struct UnaryPredicate {
virtual int operator()(const T *) const
// virtual could be avoided here if FindBinaryInsertionIndex,
// etc. were member template functions
{ return 0; }
private:
static int _unary_predicate_glue(const void *item, void *context);
friend class BObjectList<T>;
};
template<class T>
int
UnaryPredicate<T>::_unary_predicate_glue(const void *item, void *context)
{
return ((UnaryPredicate<T> *)context)->operator()((const T *)item);
}
class _PointerList_ : public BList {
public:
_PointerList_(const _PointerList_ &list);
_PointerList_(int32 itemsPerBlock = 20, bool owning = false);
~_PointerList_();
typedef void *(* GenericEachFunction)(void *, void *);
typedef int (* GenericCompareFunction)(const void *, const void *);
typedef int (* GenericCompareFunctionWithState)(const void *, const void *,
void *);
typedef int (* UnaryPredicateGlue)(const void *, void *);
void *EachElement(GenericEachFunction, void *);
void SortItems(GenericCompareFunction);
void SortItems(GenericCompareFunctionWithState, void *state);
void HSortItems(GenericCompareFunction);
void HSortItems(GenericCompareFunctionWithState, void *state);
void *BinarySearch(const void *, GenericCompareFunction) const;
void *BinarySearch(const void *, GenericCompareFunctionWithState, void *state) const;
int32 BinarySearchIndex(const void *, GenericCompareFunction) const;
int32 BinarySearchIndex(const void *, GenericCompareFunctionWithState, void *state) const;
int32 BinarySearchIndexByPredicate(const void *, UnaryPredicateGlue) const;
bool Owning() const;
bool ReplaceItem(int32, void *);
protected:
bool owning;
};
template<class T>
class BObjectList : private _PointerList_ {
public:
// iteration and sorting
typedef T *(* EachFunction)(T *, void *);
typedef const T *(* ConstEachFunction)(const T *, void *);
typedef int (* CompareFunction)(const T *, const T *);
typedef int (* CompareFunctionWithState)(const T *, const T *, void *state);
BObjectList(int32 itemsPerBlock = 20, bool owning = false);
BObjectList(const BObjectList &list);
// clones list; if list is owning, makes copies of all
// the items
virtual ~BObjectList();
BObjectList &operator=(const BObjectList &list);
// clones list; if list is owning, makes copies of all
// the items
// adding and removing
// ToDo:
// change Add calls to return const item
bool AddItem(T *);
bool AddItem(T *, int32);
bool AddList(BObjectList *);
bool AddList(BObjectList *, int32);
bool RemoveItem(T *, bool deleteIfOwning = true);
// if owning, deletes the removed item
T *RemoveItemAt(int32);
// returns the removed item
void MakeEmpty();
// item access
T *ItemAt(int32) const;
bool ReplaceItem(int32 index, T *);
// if list is owning, deletes the item at <index> first
T *SwapWithItem(int32 index, T *newItem);
// same as ReplaceItem, except does not delete old item at <index>,
// returns it instead
T *FirstItem() const;
T *LastItem() const;
// misc. getters
int32 IndexOf(const T *) const;
bool HasItem(const T *) const;
bool IsEmpty() const;
int32 CountItems() const;
T *EachElement(EachFunction, void *);
const T *EachElement(ConstEachFunction, void *) const;
void SortItems(CompareFunction);
void SortItems(CompareFunctionWithState, void *state);
void HSortItems(CompareFunction);
void HSortItems(CompareFunctionWithState, void *state);
// linear search, returns first item that matches predicate
const T *FindIf(const UnaryPredicate<T> &) const;
T *FindIf(const UnaryPredicate<T> &);
// list must be sorted with CompareFunction for these to work
const T *BinarySearch(const T &, CompareFunction) const;
const T *BinarySearch(const T &, CompareFunctionWithState, void *state) const;
// Binary insertion - list must be sorted with CompareFunction for
// these to work
// simple insert
void BinaryInsert(T *, CompareFunction);
void BinaryInsert(T *, CompareFunctionWithState, void *state);
void BinaryInsert(T *, const UnaryPredicate<T> &);
// unique insert, returns false if item already in list
bool BinaryInsertUnique(T *, CompareFunction);
bool BinaryInsertUnique(T *, CompareFunctionWithState, void *state);
bool BinaryInsertUnique(T *, const UnaryPredicate<T> &);
// insert a copy of the item, returns new inserted item
T *BinaryInsertCopy(const T &copyThis, CompareFunction);
T *BinaryInsertCopy(const T &copyThis, CompareFunctionWithState, void *state);
// insert a copy of the item if not in list already
// returns new inserted item or existing item in case of a conflict
T *BinaryInsertCopyUnique(const T &copyThis, CompareFunction);
T *BinaryInsertCopyUnique(const T &copyThis, CompareFunctionWithState, void *state);
int32 FindBinaryInsertionIndex(const UnaryPredicate<T> &, bool *alreadyInList = 0) const;
// returns either the index into which a new item should be inserted
// or index of an existing item that matches the predicate
// deprecated API, will go away
BList *AsBList()
{ return this; }
const BList *AsBList() const
{ return this; }
private:
void SetItem(int32, T *);
};
template<class Item, class Result, class Param1>
Result
WhileEachListItem(BObjectList<Item> *list, Result (Item::*func)(Param1), Param1 p1)
{
Result result = 0;
int32 count = list->CountItems();
for (int32 index = 0; index < count; index++)
if ((result = (list->ItemAt(index)->*func)(p1)) != 0)
break;
return result;
}
template<class Item, class Result, class Param1>
Result
WhileEachListItem(BObjectList<Item> *list, Result (*func)(Item *, Param1), Param1 p1)
{
Result result = 0;
int32 count = list->CountItems();
for (int32 index = 0; index < count; index++)
if ((result = (*func)(list->ItemAt(index), p1)) != 0)
break;
return result;
}
template<class Item, class Result, class Param1, class Param2>
Result
WhileEachListItem(BObjectList<Item> *list, Result (Item::*func)(Param1, Param2),
Param1 p1, Param2 p2)
{
Result result = 0;
int32 count = list->CountItems();
for (int32 index = 0; index < count; index++)
if ((result = (list->ItemAt(index)->*func)(p1, p2)) != 0)
break;
return result;
}
template<class Item, class Result, class Param1, class Param2>
Result
WhileEachListItem(BObjectList<Item> *list, Result (*func)(Item *, Param1, Param2),
Param1 p1, Param2 p2)
{
Result result = 0;
int32 count = list->CountItems();
for (int32 index = 0; index < count; index++)
if ((result = (*func)(list->ItemAt(index), p1, p2)) != 0)
break;
return result;
}
template<class Item, class Result, class Param1, class Param2, class Param3, class Param4>
Result
WhileEachListItem(BObjectList<Item> *list, Result (*func)(Item *, Param1, Param2,
Param3, Param4), Param1 p1, Param2 p2, Param3 p3, Param4 p4)
{
Result result = 0;
int32 count = list->CountItems();
for (int32 index = 0; index < count; index++)
if ((result = (*func)(list->ItemAt(index), p1, p2, p3, p4)) != 0)
break;
return result;
}
template<class Item, class Result>
void
EachListItemIgnoreResult(BObjectList<Item> *list, Result (Item::*func)())
{
int32 count = list->CountItems();
for (int32 index = 0; index < count; index++)
(list->ItemAt(index)->*func)();
}
template<class Item, class Param1>
void
EachListItem(BObjectList<Item> *list, void (*func)(Item *, Param1), Param1 p1)
{
int32 count = list->CountItems();
for (int32 index = 0; index < count; index++)
(func)(list->ItemAt(index), p1);
}
template<class Item, class Param1, class Param2>
void
EachListItem(BObjectList<Item> *list, void (Item::*func)(Param1, Param2),
Param1 p1, Param2 p2)
{
int32 count = list->CountItems();
for (int32 index = 0; index < count; index++)
(list->ItemAt(index)->*func)(p1, p2);
}
template<class Item, class Param1, class Param2>
void
EachListItem(BObjectList<Item> *list, void (*func)(Item *,Param1, Param2),
Param1 p1, Param2 p2)
{
int32 count = list->CountItems();
for (int32 index = 0; index < count; index++)
(func)(list->ItemAt(index), p1, p2);
}
template<class Item, class Param1, class Param2, class Param3>
void
EachListItem(BObjectList<Item> *list, void (*func)(Item *,Param1, Param2,
Param3), Param1 p1, Param2 p2, Param3 p3)
{
int32 count = list->CountItems();
for (int32 index = 0; index < count; index++)
(func)(list->ItemAt(index), p1, p2, p3);
}
template<class Item, class Param1, class Param2, class Param3, class Param4>
void
EachListItem(BObjectList<Item> *list, void (*func)(Item *,Param1, Param2,
Param3, Param4), Param1 p1, Param2 p2, Param3 p3, Param4 p4)
{
int32 count = list->CountItems();
for (int32 index = 0; index < count; index++)
(func)(list->ItemAt(index), p1, p2, p3, p4);
}
// inline code
inline bool
_PointerList_::Owning() const
{
return owning;
}
template<class T>
BObjectList<T>::BObjectList(int32 itemsPerBlock, bool isOwning)
: _PointerList_(itemsPerBlock, isOwning)
{
}
template<class T>
BObjectList<T>::BObjectList(const BObjectList<T> &list)
: _PointerList_(list)
{
owning = list.owning;
if (owning) {
// make our own copies in an owning list
int32 count = list.CountItems();
for (int32 index = 0; index < count; index++) {
T *item = list.ItemAt(index);
if (item)
item = new T(*item);
SetItem(index, item);
}
}
}
template<class T>
BObjectList<T>::~BObjectList()
{
if (Owning())
// have to nuke elements first
MakeEmpty();
}
template<class T>
BObjectList<T> &
BObjectList<T>::operator=(const BObjectList<T> &list)
{
owning = list.owning;
BObjectList<T> &result = (BObjectList<T> &)_PointerList_::operator=(list);
if (owning) {
// make our own copies in an owning list
int32 count = list.CountItems();
for (int32 index = 0; index < count; index++) {
T *item = list.ItemAt(index);
if (item)
item = new T(*item);
SetItem(index, item);
}
}
return result;
}
template<class T>
bool
BObjectList<T>::AddItem(T *item)
{
// need to cast to void * to make T work for const pointers
return _PointerList_::AddItem((void *)item);
}
template<class T>
bool
BObjectList<T>::AddItem(T *item, int32 atIndex)
{
return _PointerList_::AddItem((void *)item, atIndex);
}
template<class T>
bool
BObjectList<T>::AddList(BObjectList<T> *newItems)
{
return _PointerList_::AddList(newItems);
}
template<class T>
bool
BObjectList<T>::AddList(BObjectList<T> *newItems, int32 atIndex)
{
return _PointerList_::AddList(newItems, atIndex);
}
template<class T>
bool
BObjectList<T>::RemoveItem(T *item, bool deleteIfOwning)
{
bool result = _PointerList_::RemoveItem((void *)item);
if (result && Owning() && deleteIfOwning)
delete item;
return result;
}
template<class T>
T *
BObjectList<T>::RemoveItemAt(int32 index)
{
return (T *)_PointerList_::RemoveItem(index);
}
template<class T>
inline T *
BObjectList<T>::ItemAt(int32 index) const
{
return (T *)_PointerList_::ItemAt(index);
}
template<class T>
bool
BObjectList<T>::ReplaceItem(int32 index, T *item)
{
if (owning)
delete ItemAt(index);
return _PointerList_::ReplaceItem(index, (void *)item);
}
template<class T>
T *
BObjectList<T>::SwapWithItem(int32 index, T *newItem)
{
T *result = ItemAt(index);
_PointerList_::ReplaceItem(index, (void *)newItem);
return result;
}
template<class T>
void
BObjectList<T>::SetItem(int32 index, T *newItem)
{
_PointerList_::ReplaceItem(index, (void *)newItem);
}
template<class T>
int32
BObjectList<T>::IndexOf(const T *item) const
{
return _PointerList_::IndexOf((void *)const_cast<T *>(item));
}
template<class T>
T *
BObjectList<T>::FirstItem() const
{
return (T *)_PointerList_::FirstItem();
}
template<class T>
T *
BObjectList<T>::LastItem() const
{
return (T *)_PointerList_::LastItem();
}
template<class T>
bool
BObjectList<T>::HasItem(const T *item) const
{
return _PointerList_::HasItem((void *)item);
}
template<class T>
bool
BObjectList<T>::IsEmpty() const
{
return _PointerList_::IsEmpty();
}
template<class T>
int32
BObjectList<T>::CountItems() const
{
return _PointerList_::CountItems();
}
template<class T>
void
BObjectList<T>::MakeEmpty()
{
if (owning) {
int32 count = CountItems();
for (int32 index = 0; index < count; index++)
delete ItemAt(index);
}
_PointerList_::MakeEmpty();
}
template<class T>
T *
BObjectList<T>::EachElement(EachFunction func, void *params)
{
return (T *)_PointerList_::EachElement((GenericEachFunction)func, params);
}
template<class T>
const T *
BObjectList<T>::EachElement(ConstEachFunction func, void *params) const
{
return (const T *)
const_cast<BObjectList<T> *>(this)->_PointerList_::EachElement(
(GenericEachFunction)func, params);
}
template<class T>
const T *
BObjectList<T>::FindIf(const UnaryPredicate<T> &predicate) const
{
int32 count = CountItems();
for (int32 index = 0; index < count; index++)
if (predicate.operator()(ItemAt(index)) == 0)
return ItemAt(index);
return 0;
}
template<class T>
T *
BObjectList<T>::FindIf(const UnaryPredicate<T> &predicate)
{
int32 count = CountItems();
for (int32 index = 0; index < count; index++)
if (predicate.operator()(ItemAt(index)) == 0)
return ItemAt(index);
return 0;
}
template<class T>
void
BObjectList<T>::SortItems(CompareFunction function)
{
_PointerList_::SortItems((GenericCompareFunction)function);
}
template<class T>
void
BObjectList<T>::SortItems(CompareFunctionWithState function, void *state)
{
_PointerList_::SortItems((GenericCompareFunctionWithState)function, state);
}
template<class T>
void
BObjectList<T>::HSortItems(CompareFunction function)
{
_PointerList_::HSortItems((GenericCompareFunction)function);
}
template<class T>
void
BObjectList<T>::HSortItems(CompareFunctionWithState function, void *state)
{
_PointerList_::HSortItems((GenericCompareFunctionWithState)function, state);
}
template<class T>
const T *
BObjectList<T>::BinarySearch(const T &key, CompareFunction func) const
{
return (const T *)_PointerList_::BinarySearch(&key,
(GenericCompareFunction)func);
}
template<class T>
const T *
BObjectList<T>::BinarySearch(const T &key, CompareFunctionWithState func, void *state) const
{
return (const T *)_PointerList_::BinarySearch(&key,
(GenericCompareFunctionWithState)func, state);
}
template<class T>
void
BObjectList<T>::BinaryInsert(T *item, CompareFunction func)
{
int32 index = _PointerList_::BinarySearchIndex(item,
(GenericCompareFunction)func);
if (index >= 0)
// already in list, add after existing
AddItem(item, index + 1);
else
AddItem(item, -index - 1);
}
template<class T>
void
BObjectList<T>::BinaryInsert(T *item, CompareFunctionWithState func, void *state)
{
int32 index = _PointerList_::BinarySearchIndex(item,
(GenericCompareFunctionWithState)func, state);
if (index >= 0)
// already in list, add after existing
AddItem(item, index + 1);
else
AddItem(item, -index - 1);
}
template<class T>
bool
BObjectList<T>::BinaryInsertUnique(T *item, CompareFunction func)
{
int32 index = _PointerList_::BinarySearchIndex(item,
(GenericCompareFunction)func);
if (index >= 0)
return false;
AddItem(item, -index - 1);
return true;
}
template<class T>
bool
BObjectList<T>::BinaryInsertUnique(T *item, CompareFunctionWithState func, void *state)
{
int32 index = _PointerList_::BinarySearchIndex(item,
(GenericCompareFunctionWithState)func, state);
if (index >= 0)
return false;
AddItem(item, -index - 1);
return true;
}
template<class T>
T *
BObjectList<T>::BinaryInsertCopy(const T &copyThis, CompareFunction func)
{
int32 index = _PointerList_::BinarySearchIndex(&copyThis,
(GenericCompareFunction)func);
if (index >= 0)
index++;
else
index = -index - 1;
T *newItem = new T(copyThis);
AddItem(newItem, index);
return newItem;
}
template<class T>
T *
BObjectList<T>::BinaryInsertCopy(const T &copyThis, CompareFunctionWithState func, void *state)
{
int32 index = _PointerList_::BinarySearchIndex(&copyThis,
(GenericCompareFunctionWithState)func, state);
if (index >= 0)
index++;
else
index = -index - 1;
T *newItem = new T(copyThis);
AddItem(newItem, index);
return newItem;
}
template<class T>
T *
BObjectList<T>::BinaryInsertCopyUnique(const T &copyThis, CompareFunction func)
{
int32 index = _PointerList_::BinarySearchIndex(&copyThis,
(GenericCompareFunction)func);
if (index >= 0)
return ItemAt(index);
index = -index - 1;
T *newItem = new T(copyThis);
AddItem(newItem, index);
return newItem;
}
template<class T>
T *
BObjectList<T>::BinaryInsertCopyUnique(const T &copyThis, CompareFunctionWithState func,
void *state)
{
int32 index = _PointerList_::BinarySearchIndex(&copyThis,
(GenericCompareFunctionWithState)func, state);
if (index >= 0)
return ItemAt(index);
index = -index - 1;
T *newItem = new T(copyThis);
AddItem(newItem, index);
return newItem;
}
template<class T>
int32
BObjectList<T>::FindBinaryInsertionIndex(const UnaryPredicate<T> &pred, bool *alreadyInList)
const
{
int32 index = _PointerList_::BinarySearchIndexByPredicate(&pred,
(UnaryPredicateGlue)&UnaryPredicate<T>::_unary_predicate_glue);
if (alreadyInList)
*alreadyInList = index >= 0;
if (index < 0)
index = -index - 1;
return index;
}
template<class T>
void
BObjectList<T>::BinaryInsert(T *item, const UnaryPredicate<T> &pred)
{
int32 index = FindBinaryInsertionIndex(pred);
AddItem(item, index);
}
template<class T>
bool
BObjectList<T>::BinaryInsertUnique(T *item, const UnaryPredicate<T> &pred)
{
bool alreadyInList;
int32 index = FindBinaryInsertionIndex(pred, &alreadyInList);
if (alreadyInList)
return false;
AddItem(item, index);
return true;
}
#endif

View File

@@ -0,0 +1,413 @@
/*
Open Tracker License
Terms and Conditions
Copyright (c) 1991-2000, Be Incorporated. All rights reserved.
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
of the Software, and to permit persons to whom the Software is furnished to do
so, subject to the following conditions:
The above copyright notice and this permission notice applies to all licensees
and 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 TITLE, MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
BE INCORPORATED 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.
Except as contained in this notice, the name of Be Incorporated shall not be
used in advertising or otherwise to promote the sale, use or other dealings in
this Software without prior written authorization from Be Incorporated.
Tracker(TM), Be(R), BeOS(R), and BeIA(TM) are trademarks or registered trademarks
of Be Incorporated in the United States and other countries. Other brand product
names are registered trademarks or trademarks of their respective holders.
All rights reserved.
*/
#include "YabColumnType.h"
#include <stdio.h>
#include <Application.h>
#include <BitmapStream.h>
#include <File.h>
#include <Path.h>
#include <Roster.h>
#include <TranslatorRoster.h>
#include <Translator.h>
#include <View.h>
#include <NodeInfo.h>
#ifdef ZETA
#include <sys_apps/Tracker/Icons.h>
#endif
#define kTEXT_MARGIN 8
#define kIMG_MARGIN 2
//=====================================================================
BTitledColumn::BTitledColumn(const char* title, float width, float minWidth,
float maxWidth, alignment align)
:BColumn(width, minWidth, maxWidth, align),
fTitle(title)
{
font_height fh;
be_plain_font->GetHeight(&fh);
fFontHeight = fh.descent + fh.leading;
}
//--------------------------------------------------------------------
void BTitledColumn::DrawTitle(BRect rect, BView* parent)
{
float width = rect.Width() - (2 * kTEXT_MARGIN);
BString out_string(fTitle);
parent->TruncateString(&out_string, B_TRUNCATE_END, width + 2);
DrawString(out_string.String(), parent, rect);
}
//--------------------------------------------------------------------
void BTitledColumn::GetColumnName(BString* into) const
{
*into = fTitle;
}
//--------------------------------------------------------------------
void BTitledColumn::DrawString(const char* string, BView* parent, BRect rect)
{
float width = rect.Width() - (2 * kTEXT_MARGIN);
float y;
BFont font;
font_height finfo;
parent->GetFont(&font);
font.GetHeight(&finfo);
y = rect.top + ((rect.Height() - (finfo.ascent + finfo.descent + finfo.leading)) / 2) +
(finfo.ascent + finfo.descent) - 2;
switch (Alignment())
{
case B_ALIGN_LEFT:
parent->MovePenTo(rect.left + kTEXT_MARGIN, y);
break;
case B_ALIGN_CENTER:
parent->MovePenTo(rect.left + kTEXT_MARGIN + ((width - font.StringWidth(string)) / 2), y);
break;
case B_ALIGN_RIGHT:
parent->MovePenTo(rect.right - kTEXT_MARGIN - font.StringWidth(string), y);
break;
}
parent->DrawString(string);
}
//--------------------------------------------------------------------
void BTitledColumn::SetTitle(const char* title)
{
fTitle.SetTo(title);
}
//--------------------------------------------------------------------
void BTitledColumn::Title(BString* forTitle) const
{
if (forTitle)
forTitle->SetTo(fTitle.String());
}
//--------------------------------------------------------------------
float BTitledColumn::FontHeight() const
{
return fFontHeight;
}
//=====================================================================
BYabField::BYabField(const char* string)
:fWidth(0), fString(string), fClippedString(string)
{
int n = fString.FindFirst("__Icon__=");
fBitmap = NULL;
if(n==0)
{
BString myPath;
fString.CopyInto(myPath, 9, fString.Length()-9);
BPath AppDirectory;
// app directory
BString ApplicationDirectory("");
app_info appinfo;
if(be_roster->GetRunningAppInfo(be_app->Team(), &appinfo) == B_OK)
{
BEntry ApplicationEntry( &appinfo.ref);
BEntry ApplicationDirectoryEntry;
if( ApplicationEntry.GetParent( &ApplicationDirectoryEntry) == B_OK)
{
if( AppDirectory.SetTo( &ApplicationDirectoryEntry) == B_OK)
{
// strcpy(ApplicationDirectory, AppDirectory.Path());
ApplicationDirectory.SetTo(AppDirectory.Path());
}
}
}
BFile ImageFile;
BPath ImagePath;
if(myPath[0] == '/')
ImageFile.SetTo( myPath.String(), B_READ_ONLY);
else
// App directory.
if(ApplicationDirectory != "")
{
if( ImagePath.SetTo(ApplicationDirectory.String(), myPath.String()) == B_OK)
ImageFile.SetTo( ImagePath.Path(), B_READ_ONLY);
}
if( ImageFile.InitCheck() != B_OK)
ImageFile.SetTo( myPath.String(), B_READ_ONLY);
if( ImageFile.InitCheck() == B_OK)
{
BTranslatorRoster *Roster = BTranslatorRoster::Default();
if( Roster)
{
BBitmapStream Stream;
if( Roster->Translate( &ImageFile, NULL, NULL, &Stream, B_TRANSLATOR_BITMAP) == B_OK)
Stream.DetachBitmap( &fBitmap);
delete Roster;
}
}
}
}
void BYabField::SetString(const char* val, int height)
{
fString = val;
fClippedString = "";
fWidth = 0;
fBitmap = NULL;
if( ! fString.FindFirst("__Icon__=") )
{
BString myPath;
fString.CopyInto(myPath, 9, fString.Length()-9);
BPath AppDirectory;
// app directory
BString ApplicationDirectory("");
app_info appinfo;
if(be_roster->GetRunningAppInfo(be_app->Team(), &appinfo) == B_OK)
{
BEntry ApplicationEntry( &appinfo.ref);
BEntry ApplicationDirectoryEntry;
if( ApplicationEntry.GetParent( &ApplicationDirectoryEntry) == B_OK)
{
if( AppDirectory.SetTo( &ApplicationDirectoryEntry) == B_OK)
{
// strcpy(ApplicationDirectory, AppDirectory.Path());
ApplicationDirectory.SetTo(AppDirectory.Path());
}
}
}
BFile ImageFile;
BPath ImagePath;
if(myPath[0] == '/')
ImageFile.SetTo( myPath.String(), B_READ_ONLY);
else
// App directory.
if(ApplicationDirectory != "")
{
if( ImagePath.SetTo(ApplicationDirectory.String(), myPath.String()) == B_OK)
ImageFile.SetTo( ImagePath.Path(), B_READ_ONLY);
}
if( ImageFile.InitCheck() != B_OK)
ImageFile.SetTo( myPath.String(), B_READ_ONLY);
if( ImageFile.InitCheck() == B_OK)
{
BTranslatorRoster *Roster = BTranslatorRoster::Default();
if( Roster)
{
BBitmapStream Stream;
if( Roster->Translate( &ImageFile, NULL, NULL, &Stream, B_TRANSLATOR_BITMAP) == B_OK)
Stream.DetachBitmap( &fBitmap);
delete Roster;
}
}
}
else if( ! fString.FindFirst("__Mime__=") )
{
BString myPath;
fString.CopyInto(myPath, 9, fString.Length()-9);
fBitmap = new BBitmap(BRect(0, 0, 15,15), B_CMAP8);
BMimeType mime(myPath.String());
mime.GetIcon(fBitmap, B_MINI_ICON);
}
else if( ! fString.FindFirst("__Path__=") )
{
BString myPath;
fString.CopyInto(myPath, 9, fString.Length()-9);
#ifdef ZETA
fBitmap = new BBitmap(BRect(0, 0, 15, 15), B_RGBA32);
BEntry fEntry = BEntry( myPath.String() );
BBitmap icon = &GetTrackerIcon(fEntry, 16);
*fBitmap = icon;
#else
fBitmap = new BBitmap(BRect(0, 0, 31, 31), B_RGBA32);
BNode *fNode = new BNode(myPath.String());
BNodeInfo fInfo(fNode);
fInfo.GetTrackerIcon(fBitmap, B_LARGE_ICON);
delete fNode;
#endif
}
}
const char* BYabField::String() const
{
return fString.String();
}
void BYabField::SetWidth(float width)
{
fWidth = width;
}
float BYabField::Width()
{
return fWidth;
}
void BYabField::SetClippedString(const char* val)
{
fClippedString = val;
}
const char* BYabField::ClippedString()
{
return fClippedString.String();
}
const BBitmap* BYabField::Bitmap()
{
return fBitmap;
}
void BYabField::SetBitmap(BBitmap* bitmap)
{
fBitmap = bitmap;
}
bool BYabField::HasBitmap()
{
if(fBitmap) return true;
return false;
}
//=====================================================================
BYabColumn::BYabColumn(const char* title, float width, float minWidth,
float maxWidth, uint32 truncate, alignment align)
:BTitledColumn(title, width, minWidth, maxWidth, align),
fTruncate(truncate)
{
}
void BYabColumn::DrawField(BField* _field, BRect rect, BView* parent)
{
if(!((BYabField*)_field)->HasBitmap())
{
float width = rect.Width() - (2 * kTEXT_MARGIN);
BYabField* field = static_cast<BYabField*>(_field);
if (width != field->Width())
{
BString out_string(field->String());
parent->TruncateString(&out_string, fTruncate, width + 2);
field->SetClippedString(out_string.String());
field->SetWidth(width);
}
DrawString(field->ClippedString(), parent, rect);
}
else
{
BYabField *bitmapField = static_cast<BYabField *>(_field);
const BBitmap *bitmap = bitmapField->Bitmap();
if (bitmap != NULL)
{
float x = 0.0;
float y;
BRect r = bitmap->Bounds();
y = rect.top + ((rect.Height() - r.Height()) / 2);
switch (Alignment())
{
case B_ALIGN_LEFT:
x = rect.left + kIMG_MARGIN;
break;
case B_ALIGN_CENTER:
x = rect.left + ((rect.Width() - r.Width()) / 2);
break;
case B_ALIGN_RIGHT:
x = rect.right - kIMG_MARGIN - r.Width();
break;
}
parent->SetDrawingMode(B_OP_ALPHA);
parent->DrawBitmap(bitmap, BPoint(x, y));
parent->SetDrawingMode(B_OP_OVER);
}
}
}
int BYabColumn::CompareFields(BField* field1, BField* field2)
{
return(ICompare(((BYabField*)field1)->String(),
(((BYabField*)field2)->String())));
}
bool
BYabColumn::AcceptsField(const BField *field) const
{
return static_cast<bool>(dynamic_cast<const BYabField*>(field));
}

107
src/column/YabColumnType.h Normal file
View File

@@ -0,0 +1,107 @@
/*
Open Tracker License
Terms and Conditions
Copyright (c) 1991-2000, Be Incorporated. All rights reserved.
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
of the Software, and to permit persons to whom the Software is furnished to do
so, subject to the following conditions:
The above copyright notice and this permission notice applies to all licensees
and 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 TITLE, MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
BE INCORPORATED 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.
Except as contained in this notice, the name of Be Incorporated shall not be
used in advertising or otherwise to promote the sale, use or other dealings in
this Software without prior written authorization from Be Incorporated.
Tracker(TM), Be(R), BeOS(R), and BeIA(TM) are trademarks or registered trademarks
of Be Incorporated in the United States and other countries. Other brand product
names are registered trademarks or trademarks of their respective holders.
All rights reserved.
*/
#ifndef YAB_COLUMN_TYPES_H
#define YAB_COLUMN_TYPES_H
#include "../global.h"
#include <String.h>
#include <Font.h>
#include <Bitmap.h>
#include "ColumnListView.h"
//=====================================================================
// Common base-class: a column that draws a standard title at its top.
class BTitledColumn : public BColumn
{
public:
BTitledColumn (const char *title, float width, float minWidth, float maxWidth, alignment align = B_ALIGN_LEFT);
virtual void DrawTitle(BRect rect, BView* parent);
virtual void GetColumnName(BString* into) const;
void DrawString(const char*, BView*, BRect);
void SetTitle(const char* title);
void Title(BString* forTitle) const; // sets the BString arg to be the title
float FontHeight() const;
private:
float fFontHeight;
BString fTitle;
};
//=====================================================================
// Field and column classes for strings.
class BYabField : public BField
{
public:
BYabField (const char* string);
BYabField (BBitmap* bitmap);
void SetString(const char* string, int height);
const char* String() const;
void SetClippedString(const char* string);
const char*ClippedString();
void SetWidth(float);
float Width();
const BBitmap* Bitmap();
void SetBitmap(BBitmap* bitmap);
bool HasBitmap();
private:
BBitmap* fBitmap;
float fWidth;
BString fString;
BString fClippedString;
};
//--------------------------------------------------------------------
class BYabColumn: public BTitledColumn
{
public:
BYabColumn(const char *title, float width, float maxWidth, float minWidth, uint32 truncate, alignment align = B_ALIGN_LEFT);
virtual void DrawField(BField* field, BRect rect, BView* parent);
virtual int CompareFields(BField* field1, BField* field2);
virtual bool AcceptsField(const BField* field) const;
private:
uint32 fTruncate;
};
#endif