void StringAttributeText::FitValue(BString *result, const BPoseView *view) { if (fValueDirty) ReadValue(&fFullValueText); fOldWidth = fColumn->Width(); fTruncatedWidth = TruncString(result, fFullValueText.String(), fFullValueText.Length(), view, fOldWidth); fDirty = false; }
void RatingAttributeText::FitValue(BString* ratingString, const BPoseView* view) { if (fValueDirty) ReadValue(&fFullValueText); fOldWidth = fColumn->Width(); fDirty = false; int64 rating; if (fValueIsDefined) { switch (fColumn->AttrType()) { case B_INT8_TYPE: rating = fValue.int8t; break; case B_INT16_TYPE: rating = fValue.int16t; break; case B_INT32_TYPE: rating = fValue.int32t; break; default: rating = 0; break; } } else rating = 0; if (rating > fMax) rating = fMax; if (rating < 0) rating = 0; int32 steps = fMax / fCount; fFullValueText = ""; for (int32 i = 0; i < fCount; i++) { int64 n = i * steps; if (rating > n) fFullValueText += "★"; else fFullValueText += "☆"; } fTruncatedWidth = TruncString(ratingString, fFullValueText.String(), fFullValueText.Length(), view, fOldWidth); }
void OpenWithRelationAttributeText::FitValue(BString* outString, const BPoseView* view) { if (fValueDirty) ReadValue(); ASSERT(view == fPoseView); const OpenWithPoseView* launchWithView = dynamic_cast<const OpenWithPoseView*>(view); if (launchWithView != NULL) launchWithView->OpenWithRelationDescription(fModel, &fRelationText); fOldWidth = fColumn->Width(); fTruncatedWidth = TruncString(outString, fRelationText.String(), fRelationText.Length(), view, fOldWidth, B_TRUNCATE_END); fDirty = false; }
void DurationAttributeText::FitValue(BString* outString, const BPoseView* view) { if (fValueDirty) ReadValue(&fFullValueText); fOldWidth = fColumn->Width(); fDirty = false; if (!fValueIsDefined) { *outString = "-"; fTruncatedWidth = TruncString(outString, fFullValueText.String(), fFullValueText.Length(), view, fOldWidth); return; } int64 time = 0; switch (fColumn->AttrType()) { case B_TIME_TYPE: time = fValue.time_tt * 1000000LL; break; case B_INT8_TYPE: time = fValue.int8t * 1000000LL; break; case B_INT16_TYPE: time = fValue.int16t * 1000000LL; break; case B_INT32_TYPE: time = fValue.int32t * 1000000LL; break; case B_INT64_TYPE: time = fValue.int64t; break; } // TODO: ignores micro seconds for now int32 seconds = time / 1000000LL; bool negative = seconds < 0; if (negative) seconds = -seconds; int32 hours = seconds / 3600; seconds -= hours * 3600; int32 minutes = seconds / 60; seconds = seconds % 60; char buffer[256]; if (hours > 0) { snprintf(buffer, sizeof(buffer), "%s%" B_PRId32 ":%02" B_PRId32 ":%02" B_PRId32, negative ? "-" : "", hours, minutes, seconds); } else { snprintf(buffer, sizeof(buffer), "%s%" B_PRId32 ":%02" B_PRId32, negative ? "-" : "", minutes, seconds); } fFullValueText = buffer; fTruncatedWidth = TruncString(outString, fFullValueText.String(), fFullValueText.Length(), view, fOldWidth); }
void GenericAttributeText::FitValue(BString* outString, const BPoseView* view) { if (fValueDirty) ReadValue(&fFullValueText); fOldWidth = fColumn->Width(); if (!fValueIsDefined) { *outString = "-"; fTruncatedWidth = TruncString(outString, fFullValueText.String(), fFullValueText.Length(), view, fOldWidth); fDirty = false; return; } char buffer[256]; switch (fColumn->AttrType()) { case B_SIZE_T_TYPE: TruncFileSizeBase(outString, fValue.int32t, view, fOldWidth); return; case B_SSIZE_T_TYPE: if (fValue.int32t > 0) { TruncFileSizeBase(outString, fValue.int32t, view, fOldWidth); return; } sprintf(buffer, "%s", strerror(fValue.int32t)); fFullValueText = buffer; break; case B_STRING_TYPE: fTruncatedWidth = TruncString(outString, fFullValueText.String(), fFullValueText.Length(), view, fOldWidth); fDirty = false; return; case B_OFF_T_TYPE: // As a side effect update the fFullValueText to the string // representation of value TruncFileSize(&fFullValueText, fValue.off_tt, view, 100000); fTruncatedWidth = TruncFileSize(outString, fValue.off_tt, view, fOldWidth); fDirty = false; return; case B_TIME_TYPE: // As a side effect update the fFullValueText to the string // representation of value TruncTime(&fFullValueText, fValue.time_tt, view, 100000); fTruncatedWidth = TruncTime(outString, fValue.time_tt, view, fOldWidth); fDirty = false; return; case B_BOOL_TYPE: // For now use true/false, would be nice to be able to set // the value text sprintf(buffer, "%s", fValue.boolt ? "true" : "false"); fFullValueText = buffer; break; case B_CHAR_TYPE: // Make sure no non-printable characters are displayed: if (!isprint(fValue.uint8t)) { *outString = "-"; fTruncatedWidth = TruncString(outString, fFullValueText.String(), fFullValueText.Length(), view, fOldWidth); fDirty = false; return; } sprintf(buffer, "%c", fValue.uint8t); fFullValueText = buffer; break; case B_INT8_TYPE: sprintf(buffer, "%d", fValue.int8t); fFullValueText = buffer; break; case B_UINT8_TYPE: sprintf(buffer, "%d", fValue.uint8t); fFullValueText = buffer; break; case B_INT16_TYPE: sprintf(buffer, "%d", fValue.int16t); fFullValueText = buffer; break; case B_UINT16_TYPE: sprintf(buffer, "%d", fValue.uint16t); fFullValueText = buffer; break; case B_INT32_TYPE: sprintf(buffer, "%" B_PRId32, fValue.int32t); fFullValueText = buffer; break; case B_UINT32_TYPE: sprintf(buffer, "%" B_PRId32, fValue.uint32t); fFullValueText = buffer; break; case B_INT64_TYPE: sprintf(buffer, "%" B_PRId64, fValue.int64t); fFullValueText = buffer; break; case B_UINT64_TYPE: sprintf(buffer, "%" B_PRId64, fValue.uint64t); fFullValueText = buffer; break; case B_FLOAT_TYPE: snprintf(buffer, sizeof(buffer), "%g", fValue.floatt); fFullValueText = buffer; break; case B_DOUBLE_TYPE: snprintf(buffer, sizeof(buffer), "%g", fValue.doublet); fFullValueText = buffer; break; default: *outString = "-"; fTruncatedWidth = TruncString(outString, fFullValueText.String(), fFullValueText.Length(), view, fOldWidth); fDirty = false; return; } fTruncatedWidth = TruncString(outString, buffer, (ssize_t)strlen(buffer), view, fOldWidth); fDirty = false; }
ModelMenuItem * BNavMenu::NewModelItem(Model *model, const BMessage *invokeMessage, const BMessenger &target, bool suppressFolderHierarchy, BContainerWindow *parentWindow, const BObjectList<BString> *typeslist, TrackingHookData *hook) { if (model->InitCheck() != B_OK) return 0; entry_ref ref; bool container = false; if (model->IsSymLink()) { Model *newResolvedModel = 0; Model *result = model->LinkTo(); if (!result) { newResolvedModel = new Model(model->EntryRef(), true, true); if (newResolvedModel->InitCheck() != B_OK) { // broken link, still can show though, bail delete newResolvedModel; result = 0; } else result = newResolvedModel; } if (result) { BModelOpener opener(result); // open the model, if it ain't open already PoseInfo poseInfo; ssize_t size = -1; if (result->Node()) size = result->Node()->ReadAttr(kAttrPoseInfo, B_RAW_TYPE, 0, &poseInfo, sizeof(poseInfo)); result->CloseNode(); if (size == sizeof(poseInfo) && !BPoseView::PoseVisible(result, &poseInfo, false)) { // link target sez it doesn't want to be visible, // don't show the link PRINT(("not showing hidden item %s\n", model->Name())); delete newResolvedModel; return 0; } ref = *result->EntryRef(); container = result->IsContainer(); } model->SetLinkTo(result); } else { ref = *model->EntryRef(); container = model->IsContainer(); } BMessage *message = new BMessage(*invokeMessage); message->AddRef("refs", model->EntryRef()); // Truncate the name if necessary BString truncatedString; TruncString(be_plain_font, model->Name(), truncatedString, GetMaxMenuWidth()); ModelMenuItem *item = NULL; if (!container || suppressFolderHierarchy) { item = new ModelMenuItem(model, truncatedString.String(), message); if (invokeMessage->what != B_REFS_RECEIVED) item->SetEnabled(false); // the above is broken for FavoritesMenu::AddNextItem, which uses a // workaround - should fix this } else { BNavMenu *menu = new BNavMenu(truncatedString.String(), invokeMessage->what, target, parentWindow, typeslist); menu->SetNavDir(&ref); if (hook) menu->InitTrackingHook(hook->fTrackingHook, &(hook->fTarget), hook->fDragMessage); item = new ModelMenuItem(model, menu); item->SetMessage(message); } return item; }