2 * Copyright (c) 2005-2010, Haiku, Inc.
3 * Distributed under the terms of the MIT license.
6 * DarkWyrm <darkwyrm@gmail.com>
9 #include "ResourceData.h"
12 #include <TranslationUtils.h>
14 TypeCodeField::TypeCodeField(const type_code
&code
, ResourceData
*data
)
15 : BStringField(MakeTypeString(code
).String()),
22 PreviewField::PreviewField(void)
27 PreviewField::~PreviewField(void)
32 BitmapPreviewField::BitmapPreviewField(BBitmap
*bitmap
)
38 BitmapPreviewField::~BitmapPreviewField(void)
45 BitmapPreviewField::DrawField(BRect rect
, BView
*parent
)
48 // Scale the fBitmap down to completely fit within the field's height
49 BRect
drawrect(fBitmap
->Bounds().OffsetToCopy(rect
.LeftTop()));
50 if (drawrect
.Height() > rect
.Height()) {
52 drawrect
.right
= drawrect
.left
+
53 (fBitmap
->Bounds().Width() *
54 (rect
.Height() / fBitmap
->Bounds().Height()));
57 parent
->SetDrawingMode(B_OP_ALPHA
);
58 parent
->DrawBitmap(fBitmap
, fBitmap
->Bounds(), drawrect
);
59 parent
->SetDrawingMode(B_OP_COPY
);
62 out
<< fBitmap
->Bounds().IntegerWidth() << " x "
63 << fBitmap
->Bounds().IntegerHeight() << " x "
64 << (int32(fBitmap
->BytesPerRow() / fBitmap
->Bounds().Width()) * 8);
66 BRect stringrect
= rect
;
67 stringrect
.right
-= 10;
68 stringrect
.left
= stringrect
.right
- parent
->StringWidth(out
.String());
69 if (stringrect
.left
< drawrect
.right
+ 5)
70 stringrect
.left
= drawrect
.right
+ 5;
72 parent
->TruncateString(&out
, B_TRUNCATE_END
, stringrect
.Width());
73 parent
->DrawString(out
.String(), stringrect
.LeftTop());
79 BitmapPreviewField::SetData(char *data
, const size_t &length
)
81 BMemoryIO
memio(data
, length
);
82 fBitmap
= BTranslationUtils::GetBitmap(&memio
);
86 IntegerPreviewField::IntegerPreviewField(const int64
&value
)
92 IntegerPreviewField::~IntegerPreviewField(void)
98 IntegerPreviewField::DrawField(BRect rect
, BView
*parent
)
100 BPoint
point(rect
.LeftBottom());
105 parent
->TruncateString(&string
, B_TRUNCATE_MIDDLE
, rect
.Width() - 14);
106 parent
->DrawString(string
.String(), point
);
111 IntegerPreviewField::SetData(char *data
, const size_t &length
)
115 fValue
= *((int8
*)data
);
119 fValue
= *((int16
*)data
);
123 fValue
= *((int32
*)data
);
127 fValue
= *((int32
*)data
);
137 StringPreviewField::StringPreviewField(const char *string
)
139 fClipped
= fString
= string
;
143 StringPreviewField::~StringPreviewField(void)
149 StringPreviewField::DrawField(BRect rect
, BView
*parent
)
151 BPoint
point(rect
.LeftBottom());
155 parent
->TruncateString(&fClipped
, B_TRUNCATE_END
, rect
.Width() - 14);
156 parent
->DrawString(fClipped
.String(), point
);
161 StringPreviewField::SetData(char *data
, const size_t &length
)
163 char *temp
= fString
.LockBuffer(length
+ 2);
165 memcpy(temp
, data
, length
);
167 fString
.UnlockBuffer();
173 MakeTypeString(int32 type
)
176 char *typeptr
= (char *) &type
;
177 typestring
[0] = '\'';
178 typestring
[1] = typeptr
[3];
179 typestring
[2] = typeptr
[2];
180 typestring
[3] = typeptr
[1];
181 typestring
[4] = typeptr
[0];
182 typestring
[5] = '\'';
183 typestring
[6] = '\0';
184 return BString(typestring
);