void OpenWithContainerWindow::NewAttributeMenu(BMenu* menu) { _inherited::NewAttributeMenu(menu); BMessage* message = new BMessage(kAttributeItem); message->AddString("attr_name", kAttrOpenWithRelation); message->AddInt32("attr_type", B_STRING_TYPE); message->AddInt32("attr_hash", (int32)AttrHashString(kAttrOpenWithRelation, B_STRING_TYPE)); message->AddFloat("attr_width", 180); message->AddInt32("attr_align", B_ALIGN_LEFT); message->AddBool("attr_editable", false); message->AddBool("attr_statfield", false); BMenuItem* item = new BMenuItem(B_TRANSLATE("Relation"), message); menu->AddItem(item); message = new BMessage(kAttributeItem); message->AddString("attr_name", kAttrAppVersion); message->AddInt32("attr_type", B_STRING_TYPE); message->AddInt32("attr_hash", (int32)AttrHashString(kAttrAppVersion, B_STRING_TYPE)); message->AddFloat("attr_width", 70); message->AddInt32("attr_align", B_ALIGN_LEFT); message->AddBool("attr_editable", false); message->AddBool("attr_statfield", false); item = new BMenuItem(B_TRANSLATE("Version"), message); menu->AddItem(item); }
BViewState::BViewState() { fViewMode = kListMode; fLastIconMode = 0; fListOrigin.Set(0, 0); fIconOrigin.Set(0, 0); fPrimarySortAttr = AttrHashString(kAttrStatName, B_STRING_TYPE); fPrimarySortType = B_STRING_TYPE; fSecondarySortAttr = 0; fSecondarySortType = 0; fReverseSort = false; fStateNeedsSaving = false; }
BColumn::BColumn(const char *title, float offset, float width, alignment a, const char *attributeName, uint32 attr_type, bool stat_field, bool editable) : fTitle(title), fAttrName(attributeName) { fOffset = offset; fWidth = width; fAlignment = a; fAttrHash = AttrHashString(attributeName, attr_type); fAttrType = attr_type; fStatField = stat_field; fEditable = editable; }
void BColumn::_Init(const char* title, float offset, float width, alignment align, const char* attributeName, uint32 attrType, const char* displayAs, bool statField, bool editable) { fTitle = title; fAttrName = attributeName; fDisplayAs = displayAs; fOffset = offset; fWidth = width; fAlignment = align; fAttrHash = AttrHashString(attributeName, attrType); fAttrType = attrType; fStatField = statField; fEditable = editable; }
BViewState* BViewState::InstantiateFromStream(BMallocIO* stream, bool endianSwap) { // compare stream header in canonical form uint32 key = AttrHashString("BViewState", B_OBJECT_TYPE); int32 version = kViewStateArchiveVersion; if (endianSwap) { key = SwapUInt32(key); version = SwapInt32(version); } if (!ValidateStream(stream, key, version)) return NULL; return _Sanitize(new (std::nothrow) BViewState(stream, endianSwap)); }
void BViewState::ArchiveToStream(BMallocIO *stream) const { // write class identifier and verison info uint32 key = AttrHashString("BViewState", B_OBJECT_TYPE); stream->Write(&key, sizeof(key)); int32 version = kViewStateArchiveVersion; stream->Write(&version, sizeof(version)); stream->Write(&fViewMode, sizeof(uint32)); stream->Write(&fLastIconMode, sizeof(uint32)); stream->Write(&fListOrigin, sizeof(BPoint)); stream->Write(&fIconOrigin, sizeof(BPoint)); stream->Write(&fPrimarySortAttr, sizeof(uint32)); stream->Write(&fPrimarySortType, sizeof(uint32)); stream->Write(&fSecondarySortAttr, sizeof(uint32)); stream->Write(&fSecondarySortType, sizeof(uint32)); stream->Write(&fReverseSort, sizeof(bool)); }
void BColumn::ArchiveToStream(BMallocIO *stream) const { // write class identifier and version info uint32 key = AttrHashString("BColumn", B_OBJECT_TYPE); stream->Write(&key, sizeof(uint32)); int32 version = kColumnStateArchiveVersion; stream->Write(&version, sizeof(int32)); // PRINT(("ArchiveToStream column, key %x, version %d\n", key, version)); StringToStream(&fTitle, stream); stream->Write(&fOffset, sizeof(float)); stream->Write(&fWidth, sizeof(float)); stream->Write(&fAlignment, sizeof(alignment)); StringToStream(&fAttrName, stream); stream->Write(&fAttrHash, sizeof(uint32)); stream->Write(&fAttrType, sizeof(uint32)); stream->Write(&fStatField, sizeof(bool)); stream->Write(&fEditable, sizeof(bool)); }
BColumn * BColumn::InstantiateFromStream(BMallocIO *stream, bool endianSwap) { // compare stream header in canonical form uint32 key = AttrHashString("BColumn", B_OBJECT_TYPE); int32 version = kColumnStateArchiveVersion; if (endianSwap) { key = SwapUInt32(key); version = SwapInt32(version); } // PRINT(("validating key %x, version %d\n", key, version)); if (!ValidateStream(stream, key, version)) return 0; // PRINT(("instantiating column, %s\n", endianSwap ? "endian swapping," : "")); BColumn *result = new BColumn(stream, endianSwap); // sanity-check the resulting column if (result->fTitle.Length() > 500 || result->fOffset < 0 || result->fOffset > 10000 || result->fWidth < 0 || result->fWidth > 10000 || (int32)result->fAlignment < B_ALIGN_LEFT || (int32)result->fAlignment > B_ALIGN_CENTER || result->fAttrName.Length() > 500) { PRINT(("column data not valid\n")); delete result; return 0; } #if DEBUG else if (endianSwap) PRINT(("Instantiated foreign column ok\n")); #endif return result; }
BViewState * BViewState::InstantiateFromStream(BMallocIO *stream, bool endianSwap) { // compare stream header in canonical form uint32 key = AttrHashString("BViewState", B_OBJECT_TYPE); int32 version = kViewStateArchiveVersion; if (endianSwap) { key = SwapUInt32(key); version = SwapInt32(version); } if (!ValidateStream(stream, key, version)) return NULL; BViewState *result = new BViewState(stream, endianSwap); // do a sanity check here if ((result->fViewMode != kListMode && result->fViewMode != kIconMode && result->fViewMode != kMiniIconMode && result->fViewMode != 0) || (result->fLastIconMode != kListMode && result->fLastIconMode != kIconMode && result->fLastIconMode != kMiniIconMode && result->fLastIconMode != 0)) { PRINT(("Bad data instantiating ViewState, view mode %x, lastIconMode %x\n", result->fViewMode, result->fLastIconMode)); delete result; return NULL; } #if DEBUG else if (endianSwap) PRINT(("Instantiated foreign view state ok\n")); #endif return result; }
BColumn* BColumn::InstantiateFromStream(BMallocIO* stream, bool endianSwap) { // compare stream header in canonical form // we can't use ValidateStream(), as we preserve backwards compatibility int32 version; uint32 key; if (stream->Read(&key, sizeof(uint32)) <= 0 || stream->Read(&version, sizeof(int32)) <=0) return 0; if (endianSwap) { key = SwapUInt32(key); version = SwapInt32(version); } if (key != AttrHashString("BColumn", B_OBJECT_TYPE) || version < kColumnStateMinArchiveVersion) return 0; // PRINT(("instantiating column, %s\n", endianSwap ? "endian swapping," : "")); return _Sanitize(new (std::nothrow) BColumn(stream, version, endianSwap)); }
void BPose::UpdateWidgetAndModel(Model* resolvedModel, const char* attrName, uint32 attrType, int32, BPoint poseLoc, BPoseView* poseView, bool visible) { if (poseView->ViewMode() != kListMode) poseLoc = Location(poseView); ASSERT(resolvedModel == NULL || resolvedModel->IsNodeOpen()); if (attrName != NULL) { // pick up new attributes and find out if icon needs updating if (resolvedModel->AttrChanged(attrName) && visible) UpdateIcon(poseLoc, poseView); // ToDo: the following code is wrong, because this sort of hashing // may overlap and we get aliasing uint32 attrHash = AttrHashString(attrName, attrType); BTextWidget* widget = WidgetFor(attrHash); if (widget) { BColumn* column = poseView->ColumnFor(attrHash); if (column) widget->CheckAndUpdate(poseLoc, column, poseView, visible); } else if (attrType == 0) { // attribute got likely removed, so let's search the // column for the matching attribute name int32 count = fWidgetList.CountItems(); for (int32 i = 0; i < count; i++) { BTextWidget* widget = fWidgetList.ItemAt(i); BColumn* column = poseView->ColumnFor(widget->AttrHash()); if (column != NULL && !strcmp(column->AttrName(), attrName)) { widget->CheckAndUpdate(poseLoc, column, poseView, visible); break; } } } } else { // no attr name means check all widgets for stat info changes // pick up stat changes if (resolvedModel && resolvedModel->StatChanged()) { if (resolvedModel->InitCheck() != B_OK) return; if (visible) UpdateIcon(poseLoc, poseView); } // distribute stat changes for (int32 index = 0; ; index++) { BColumn* column = poseView->ColumnAt(index); if (column == NULL) break; if (column->StatField()) { BTextWidget* widget = WidgetFor(column->AttrHash()); if (widget) { widget->CheckAndUpdate(poseLoc, column, poseView, visible); } } } } }