-
Notifications
You must be signed in to change notification settings - Fork 4
/
UIUtils.cpp
95 lines (73 loc) · 2.32 KB
/
UIUtils.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
#include "UIUtils.h"
#include <stdio.h>
IconStringField::IconStringField(BBitmap *icon, const char *string):
BStringField(string), fIcon(icon)
{}
IconStringColumn::IconStringColumn(
const char* title, float width,
float minWidth, float maxWidth, uint32 truncate,
alignment align
): BStringColumn(title, width, minWidth, maxWidth, truncate, align)
{}
void IconStringColumn::DrawField(BField* _field, BRect rect, BView* parent)
{
IconStringField *field = (IconStringField*)_field;
parent->PushState();
parent->SetDrawingMode(B_OP_ALPHA);
parent->DrawBitmap(field->Icon(), rect.LeftTop() + BPoint(4, 0));
parent->PopState();
rect.left += field->Icon()->Bounds().Width() + 1;
BStringColumn::DrawField(field, rect, parent);
}
float IconStringColumn::GetPreferredWidth(BField* field, BView* parent) const
{
return BStringColumn::GetPreferredWidth(field, parent) + dynamic_cast<IconStringField*>(field)->Icon()->Bounds().Width() + 1;
}
bool IconStringColumn::AcceptsField(const BField* field) const
{
return dynamic_cast<const IconStringField*>(field) != NULL;
}
HexIntegerColumn::HexIntegerColumn(
const char* title,
float width, float minWidth, float maxWidth,
alignment align
): BTitledColumn(title, width, minWidth, maxWidth, align)
{}
void HexIntegerColumn::DrawField(BField *field, BRect rect, BView* parent)
{
float width = rect.Width() - (2 * 8);
BString string;
if (dynamic_cast<Int64Field*>(field) != NULL)
string.SetToFormat("0x%" B_PRIx64, ((Int64Field*)field)->Value());
else
string.SetToFormat("0x%x", (int)((BIntegerField*)field)->Value());
BFont oldFont;
parent->GetFont(&oldFont);
parent->SetFont(be_fixed_font);
parent->TruncateString(&string, B_TRUNCATE_MIDDLE, width + 2);
DrawString(string.String(), parent, rect);
parent->SetFont(&oldFont);
}
int HexIntegerColumn::CompareFields(BField *field1, BField *field2)
{
if (dynamic_cast<Int64Field*>(field1) != NULL) {
if (((Int64Field*)field1)->Value() == ((Int64Field*)field2)->Value())
return 0;
else if (((Int64Field*)field1)->Value() > ((Int64Field*)field2)->Value())
return 1;
else
return -1;
} else
return (((BIntegerField*)field1)->Value() - ((BIntegerField*)field2)->Value());
}
Int64Field::Int64Field(int64 value): fValue(value)
{
}
void Int64Field::SetValue(int64 value)
{
fValue = value;
}
int64 Int64Field::Value()
{
return fValue;
}