1*22c6ae69SDarkWyrm #include "ResFields.h" 2*22c6ae69SDarkWyrm #include "ResourceData.h" 3*22c6ae69SDarkWyrm #include <DataIO.h> 4*22c6ae69SDarkWyrm #include <TranslationUtils.h> 5*22c6ae69SDarkWyrm 6*22c6ae69SDarkWyrm TypeCodeField::TypeCodeField(const type_code &code, ResourceData *data) 7*22c6ae69SDarkWyrm : BStringField(MakeTypeString(code).String()), 8*22c6ae69SDarkWyrm fTypeCode(code), 9*22c6ae69SDarkWyrm fData(data) 10*22c6ae69SDarkWyrm { 11*22c6ae69SDarkWyrm } 12*22c6ae69SDarkWyrm 13*22c6ae69SDarkWyrm 14*22c6ae69SDarkWyrm PreviewField::PreviewField(void) 15*22c6ae69SDarkWyrm { 16*22c6ae69SDarkWyrm } 17*22c6ae69SDarkWyrm 18*22c6ae69SDarkWyrm 19*22c6ae69SDarkWyrm PreviewField::~PreviewField(void) 20*22c6ae69SDarkWyrm { 21*22c6ae69SDarkWyrm } 22*22c6ae69SDarkWyrm 23*22c6ae69SDarkWyrm 24*22c6ae69SDarkWyrm BitmapPreviewField::BitmapPreviewField(BBitmap *bitmap) 25*22c6ae69SDarkWyrm { 26*22c6ae69SDarkWyrm fBitmap = bitmap; 27*22c6ae69SDarkWyrm } 28*22c6ae69SDarkWyrm 29*22c6ae69SDarkWyrm 30*22c6ae69SDarkWyrm BitmapPreviewField::~BitmapPreviewField(void) 31*22c6ae69SDarkWyrm { 32*22c6ae69SDarkWyrm delete fBitmap; 33*22c6ae69SDarkWyrm } 34*22c6ae69SDarkWyrm 35*22c6ae69SDarkWyrm 36*22c6ae69SDarkWyrm void 37*22c6ae69SDarkWyrm BitmapPreviewField::DrawField(BRect rect, BView *parent) 38*22c6ae69SDarkWyrm { 39*22c6ae69SDarkWyrm if (fBitmap) { 40*22c6ae69SDarkWyrm // Scale the fBitmap down to completely fit within the field's height 41*22c6ae69SDarkWyrm BRect drawrect(fBitmap->Bounds().OffsetToCopy(rect.LeftTop())); 42*22c6ae69SDarkWyrm if (drawrect.Height() > rect.Height()) { 43*22c6ae69SDarkWyrm drawrect = rect; 44*22c6ae69SDarkWyrm drawrect.right = drawrect.left + 45*22c6ae69SDarkWyrm (fBitmap->Bounds().Width() * 46*22c6ae69SDarkWyrm (rect.Height() / fBitmap->Bounds().Height())); 47*22c6ae69SDarkWyrm } 48*22c6ae69SDarkWyrm 49*22c6ae69SDarkWyrm parent->SetDrawingMode(B_OP_ALPHA); 50*22c6ae69SDarkWyrm parent->DrawBitmap(fBitmap, fBitmap->Bounds(), drawrect); 51*22c6ae69SDarkWyrm parent->SetDrawingMode(B_OP_COPY); 52*22c6ae69SDarkWyrm 53*22c6ae69SDarkWyrm BString out; 54*22c6ae69SDarkWyrm out << fBitmap->Bounds().IntegerWidth() << " x " 55*22c6ae69SDarkWyrm << fBitmap->Bounds().IntegerHeight() << " x " 56*22c6ae69SDarkWyrm << (int32(fBitmap->BytesPerRow() / fBitmap->Bounds().Width()) * 8); 57*22c6ae69SDarkWyrm 58*22c6ae69SDarkWyrm BRect stringrect = rect; 59*22c6ae69SDarkWyrm stringrect.right -= 10; 60*22c6ae69SDarkWyrm stringrect.left = stringrect.right - parent->StringWidth(out.String()); 61*22c6ae69SDarkWyrm if (stringrect.left < drawrect.right + 5) 62*22c6ae69SDarkWyrm stringrect.left = drawrect.right + 5; 63*22c6ae69SDarkWyrm 64*22c6ae69SDarkWyrm parent->TruncateString(&out, B_TRUNCATE_END, stringrect.Width()); 65*22c6ae69SDarkWyrm parent->DrawString(out.String(), stringrect.LeftTop()); 66*22c6ae69SDarkWyrm } 67*22c6ae69SDarkWyrm } 68*22c6ae69SDarkWyrm 69*22c6ae69SDarkWyrm 70*22c6ae69SDarkWyrm void 71*22c6ae69SDarkWyrm BitmapPreviewField::SetData(char *data, const size_t &length) 72*22c6ae69SDarkWyrm { 73*22c6ae69SDarkWyrm BMemoryIO memio(data,length); 74*22c6ae69SDarkWyrm fBitmap = BTranslationUtils::GetBitmap(&memio); 75*22c6ae69SDarkWyrm } 76*22c6ae69SDarkWyrm 77*22c6ae69SDarkWyrm 78*22c6ae69SDarkWyrm IntegerPreviewField::IntegerPreviewField(const int64 &value) 79*22c6ae69SDarkWyrm { 80*22c6ae69SDarkWyrm fValue = value; 81*22c6ae69SDarkWyrm } 82*22c6ae69SDarkWyrm 83*22c6ae69SDarkWyrm 84*22c6ae69SDarkWyrm IntegerPreviewField::~IntegerPreviewField(void) 85*22c6ae69SDarkWyrm { 86*22c6ae69SDarkWyrm } 87*22c6ae69SDarkWyrm 88*22c6ae69SDarkWyrm 89*22c6ae69SDarkWyrm void 90*22c6ae69SDarkWyrm IntegerPreviewField::DrawField(BRect rect, BView *parent) 91*22c6ae69SDarkWyrm { 92*22c6ae69SDarkWyrm BPoint point(rect.LeftBottom()); 93*22c6ae69SDarkWyrm point.y -= 2; 94*22c6ae69SDarkWyrm 95*22c6ae69SDarkWyrm BString string; 96*22c6ae69SDarkWyrm string << fValue; 97*22c6ae69SDarkWyrm parent->TruncateString(&string, B_TRUNCATE_MIDDLE, rect.Width() - 14); 98*22c6ae69SDarkWyrm parent->DrawString(string.String(), point); 99*22c6ae69SDarkWyrm } 100*22c6ae69SDarkWyrm 101*22c6ae69SDarkWyrm 102*22c6ae69SDarkWyrm void 103*22c6ae69SDarkWyrm IntegerPreviewField::SetData(char *data, const size_t &length) 104*22c6ae69SDarkWyrm { 105*22c6ae69SDarkWyrm switch(length) { 106*22c6ae69SDarkWyrm case 8: { 107*22c6ae69SDarkWyrm fValue = *((int8*)data); 108*22c6ae69SDarkWyrm break; 109*22c6ae69SDarkWyrm } 110*22c6ae69SDarkWyrm case 16: { 111*22c6ae69SDarkWyrm fValue = *((int16*)data); 112*22c6ae69SDarkWyrm break; 113*22c6ae69SDarkWyrm } 114*22c6ae69SDarkWyrm case 32: { 115*22c6ae69SDarkWyrm fValue = *((int32*)data); 116*22c6ae69SDarkWyrm break; 117*22c6ae69SDarkWyrm } 118*22c6ae69SDarkWyrm case 64: { 119*22c6ae69SDarkWyrm fValue = *((int32*)data); 120*22c6ae69SDarkWyrm break; 121*22c6ae69SDarkWyrm } 122*22c6ae69SDarkWyrm default: { 123*22c6ae69SDarkWyrm break; 124*22c6ae69SDarkWyrm } 125*22c6ae69SDarkWyrm } 126*22c6ae69SDarkWyrm } 127*22c6ae69SDarkWyrm 128*22c6ae69SDarkWyrm 129*22c6ae69SDarkWyrm StringPreviewField::StringPreviewField(const char *string) 130*22c6ae69SDarkWyrm { 131*22c6ae69SDarkWyrm fClipped = fString = string; 132*22c6ae69SDarkWyrm } 133*22c6ae69SDarkWyrm 134*22c6ae69SDarkWyrm 135*22c6ae69SDarkWyrm StringPreviewField::~StringPreviewField(void) 136*22c6ae69SDarkWyrm { 137*22c6ae69SDarkWyrm } 138*22c6ae69SDarkWyrm 139*22c6ae69SDarkWyrm 140*22c6ae69SDarkWyrm void 141*22c6ae69SDarkWyrm StringPreviewField::DrawField(BRect rect, BView *parent) 142*22c6ae69SDarkWyrm { 143*22c6ae69SDarkWyrm BPoint point(rect.LeftBottom()); 144*22c6ae69SDarkWyrm point.y -= 2; 145*22c6ae69SDarkWyrm 146*22c6ae69SDarkWyrm fClipped = fString; 147*22c6ae69SDarkWyrm parent->TruncateString(&fClipped, B_TRUNCATE_END, rect.Width() - 14); 148*22c6ae69SDarkWyrm parent->DrawString(fClipped.String(), point); 149*22c6ae69SDarkWyrm } 150*22c6ae69SDarkWyrm 151*22c6ae69SDarkWyrm 152*22c6ae69SDarkWyrm void 153*22c6ae69SDarkWyrm StringPreviewField::SetData(char *data, const size_t &length) 154*22c6ae69SDarkWyrm { 155*22c6ae69SDarkWyrm char *temp = fString.LockBuffer(length + 2); 156*22c6ae69SDarkWyrm if (temp) 157*22c6ae69SDarkWyrm memcpy(temp, data, length); 158*22c6ae69SDarkWyrm temp[length] = '\0'; 159*22c6ae69SDarkWyrm fString.UnlockBuffer(); 160*22c6ae69SDarkWyrm fClipped = fString; 161*22c6ae69SDarkWyrm } 162*22c6ae69SDarkWyrm 163*22c6ae69SDarkWyrm 164*22c6ae69SDarkWyrm BString 165*22c6ae69SDarkWyrm MakeTypeString(int32 type) 166*22c6ae69SDarkWyrm { 167*22c6ae69SDarkWyrm char typestring[7]; 168*22c6ae69SDarkWyrm char *typeptr = (char *) &type; 169*22c6ae69SDarkWyrm typestring[0] = '\''; 170*22c6ae69SDarkWyrm typestring[1] = typeptr[3]; 171*22c6ae69SDarkWyrm typestring[2] = typeptr[2]; 172*22c6ae69SDarkWyrm typestring[3] = typeptr[1]; 173*22c6ae69SDarkWyrm typestring[4] = typeptr[0]; 174*22c6ae69SDarkWyrm typestring[5] = '\''; 175*22c6ae69SDarkWyrm typestring[6] = '\0'; 176*22c6ae69SDarkWyrm return BString(typestring); 177*22c6ae69SDarkWyrm } 178