void BPose::DeselectWithoutErasingBackground(BRect, BPoseView* poseView) { ASSERT(poseView->ViewMode() != kListMode); ASSERT(!IsSelected()); BPoint location(Location(poseView)); // draw icon directly if (fPercent == -1) DrawIcon(location, poseView, poseView->IconSize(), true); else UpdateIcon(location, poseView); BColumn* column = poseView->FirstColumn(); if (column == NULL) return; BTextWidget* widget = WidgetFor(column->AttrHash()); if (widget == NULL || !widget->IsVisible()) return; // just invalidate the background, don't draw anything poseView->Invalidate(widget->CalcRect(location, 0, poseView)); }
status_t SeqManageRosterWindow::SetConfiguration(const BMessage* config) { ArpASSERT(config); status_t err = SetDimensions(config, this); if (err != B_OK) return err; /* Set the columns */ BColumnListView* table = dynamic_cast<BColumnListView*>( FindView(TABLE_STR) ); if (table) { BMessage colMsg; for (int32 k = 0; config->FindMessage("column", k, &colMsg) == B_OK; k++) { const char* colName; float colW; bool colVis; if (colMsg.FindString("name", &colName) == B_OK && colMsg.FindFloat("width", &colW) == B_OK && colMsg.FindBool("visible", &colVis) == B_OK) { BColumn* col = col_named(colName, table); if (col) { col->SetWidth(colW); col->SetVisible(colVis); } } } } return B_OK; }
bool BPose::PointInPose(BPoint loc, const BPoseView* poseView, BPoint where, BTextWidget** hitWidget) const { if (hitWidget) *hitWidget = NULL; // check intersection with icon BRect rect; rect.left = loc.x + kListOffset; rect.right = rect.left + B_MINI_ICON; rect.bottom = loc.y + poseView->ListElemHeight(); rect.top = rect.bottom - B_MINI_ICON; if (rect.Contains(where)) return true; for (int32 index = 0; ; index++) { BColumn* column = poseView->ColumnAt(index); if (column == NULL) break; BTextWidget* widget = WidgetFor(column->AttrHash()); if (widget && widget->CalcClickRect(loc, column, poseView).Contains(where)) { if (hitWidget) *hitWidget = widget; return true; } } return false; }
void BPose::EditPreviousNextWidgetCommon(BPoseView* poseView, bool next) { bool found = false; int32 delta = next ? 1 : -1; for (int32 index = next ? 0 : poseView->CountColumns() - 1; ; index += delta) { BColumn* column = poseView->ColumnAt(index); if (column == NULL) break; BTextWidget* widget = WidgetFor(column->AttrHash()); if (widget != NULL && widget->IsActive()) { poseView->CommitActivePose(); found = true; continue; } if (found && column->Editable()) { BRect bounds; if (poseView->ViewMode() == kListMode) { int32 poseIndex = poseView->IndexOfPose(this); BPoint poseLoc(0, poseIndex* poseView->ListElemHeight()); bounds = widget->CalcRect(poseLoc, column, poseView); } else bounds = widget->CalcRect(Location(poseView), 0, poseView); widget->StartEdit(bounds, poseView, this); break; } } }
void SeqStudioWindow::ToggleColumn(const char* name) { BColumnListView* table = dynamic_cast<BColumnListView*>( FindView(ENDPOINT_LIST_STR) ); if (!table) return; BColumn* col = column_named(name, table); if (!col) return; if (col->IsVisible() ) col->SetVisible(false); else col->SetVisible(true); }
static BColumn* col_named(const char* name, BColumnListView* table) { BColumn* col; for (int32 k = 0; (col = table->ColumnAt(k)); k++) { BString colName; col->GetColumnName( &colName ); if (strcmp( name, colName.String() ) == 0) return col; } return NULL; }
static BColumn* column_named(const char* name, BColumnListView* fromTable) { if (!fromTable) return NULL; BColumn* col; for (uint32 k = 0; (col = fromTable->ColumnAt(k)); k++) { BString n; col->GetColumnName(&n); if (strcmp( n.String(), name ) == 0) return col; } return NULL; }
void BPose::EditFirstWidget(BPoint poseLoc, BPoseView* poseView) { // find first editable widget BColumn* column; for (int32 i = 0;(column = poseView->ColumnAt(i)) != NULL;i++) { BTextWidget* widget = WidgetFor(column->AttrHash()); if (widget && widget->IsEditable()) { BRect bounds; // ToDo: // fold the three StartEdit code sequences into a cover call if (poseView->ViewMode() == kListMode) bounds = widget->CalcRect(poseLoc, column, poseView); else bounds = widget->CalcRect(Location(poseView), NULL, poseView); widget->StartEdit(bounds, poseView, this); break; } } }
void SeqManageRosterWindow::MenusBeginning() { inherited::MenusBeginning(); BMenuBar* bar = KeyMenuBar(); if (!bar) return; BColumnListView* table = dynamic_cast<BColumnListView*>( FindView(TABLE_STR) ); if (!table) return; BMenu* menu; BMenuItem* item; // Entry menu bool canEdit = false, canDuplicate = false; BString key, filePath; bool readOnly; if (GetSelectionInfo(key, filePath, &readOnly) == B_OK) { canEdit = !readOnly; canDuplicate = true; } if ( (menu = bar->SubmenuAt(ENTRY_MENU_INDEX)) != NULL) { if ( (item = menu->FindItem(EDIT_ENTRY_MSG)) != NULL) item->SetEnabled(canEdit); if ( (item = menu->FindItem(DUPLICATE_ENTRY_MSG)) != NULL) item->SetEnabled(canDuplicate); if ( (item = menu->FindItem(DELETE_ENTRY_MSG)) != NULL) item->SetEnabled(canEdit); } // Attributes menu if ( (menu = bar->SubmenuAt(ATTRIBUTES_MENU_INDEX)) != NULL) { for (int32 k = 0; (item = menu->ItemAt(k)) != NULL; k++) { const char* n; if (item->Message() && item->Message()->FindString(COLUMN_NAME_STR, &n) == B_OK) { BColumn* col = column_named(n, table); if (col && col->IsVisible() ) { if (!item->IsMarked() ) item->SetMarked(true); } else { if (item->IsMarked() ) item->SetMarked(false); } } } } }
void OpenWithPoseView::SetUpDefaultColumnsIfNeeded() { // in case there were errors getting some columns if (fColumnList->CountItems() != 0) return; BColumn* nameColumn = new BColumn(B_TRANSLATE("Name"), kColumnStart, 125, B_ALIGN_LEFT, kAttrStatName, B_STRING_TYPE, true, true); fColumnList->AddItem(nameColumn); BColumn* relationColumn = new BColumn(B_TRANSLATE("Relation"), 180, 100, B_ALIGN_LEFT, kAttrOpenWithRelation, B_STRING_TYPE, false, false); fColumnList->AddItem(relationColumn); fColumnList->AddItem(new BColumn(B_TRANSLATE("Location"), 290, 225, B_ALIGN_LEFT, kAttrPath, B_STRING_TYPE, true, false)); fColumnList->AddItem(new BColumn(B_TRANSLATE("Version"), 525, 70, B_ALIGN_LEFT, kAttrAppVersion, B_STRING_TYPE, false, false)); // sort by relation and by name SetPrimarySort(relationColumn->AttrHash()); SetSecondarySort(nameColumn->AttrHash()); }
BRect BPose::CalcRect(BPoint loc, const BPoseView* poseView, bool minimalRect) const { ASSERT(poseView->ViewMode() == kListMode); BColumn* column = poseView->LastColumn(); BRect rect; rect.left = loc.x; rect.top = loc.y; rect.right = loc.x + column->Offset() + column->Width(); rect.bottom = rect.top + poseView->ListElemHeight(); if (minimalRect) { BTextWidget* widget = WidgetFor(poseView->FirstColumn()->AttrHash()); if (widget != NULL) { rect.right = widget->CalcRect(loc, poseView->FirstColumn(), poseView).right; } } return rect; }
bool TreeTable::GetToolTipAt(BPoint point, BToolTip** _tip) { if (fToolTipProvider == NULL) return AbstractTable::GetToolTipAt(point, _tip); // get the table row BRow* row = RowAt(point); if (row == NULL) return AbstractTable::GetToolTipAt(point, _tip); TreeTableRow* treeRow = dynamic_cast<TreeTableRow*>(row); // get the table column BColumn* column = ColumnAt(point); int32 columnIndex = column != NULL ? column->LogicalFieldNum() : -1; TreeTablePath path; _GetPathForNode(treeRow->Node(), path); return fToolTipProvider->GetToolTipForTablePath(path, columnIndex, _tip); }
void SeqStudioWindow::MenusBeginning() { inherited::MenusBeginning(); BMenuBar* bar = KeyMenuBar(); if (!bar) return; BColumnListView* table = dynamic_cast<BColumnListView*>( FindView(ENDPOINT_LIST_STR) ); if (!table) return; if (mDeviceCtrl && mDeviceCtrl->Menu() ) add_device_menu_items(mDeviceCtrl->Menu() ); // MIDI Port menu if (mPortMenu) { bool deleteEnabled = false; _EndpointRow* r = dynamic_cast<_EndpointRow*>(table->CurrentSelection() ); if (r && !r->mIsValid && r->mEndpoint.channel < 0) deleteEnabled = true; BMenuItem* deleteItem = mPortMenu->FindItem(DELETE_STR); if (deleteItem && deleteItem->IsEnabled() != deleteEnabled) deleteItem->SetEnabled(deleteEnabled); } // Attributes menu BMenu* menu; BMenuItem* item; if ( (menu = bar->SubmenuAt(ATTRIBUTES_MENU_INDEX)) != NULL) { for (int32 k = 0; (item = menu->ItemAt(k)) != NULL; k++) { const char* n; if (item->Message() && item->Message()->FindString(COLUMN_NAME_STR, &n) == B_OK) { BColumn* col = column_named(n, table); if (col && col->IsVisible() ) { if (!item->IsMarked() ) item->SetMarked(true); } else { if (item->IsMarked() ) item->SetMarked(false); } } } } }
status_t SeqManageRosterWindow::GetConfiguration(BMessage* config) { ArpASSERT(config); config->what = ConfigWhat(); status_t err = GetDimensions(config, this); if (err != B_OK) return err; /* Add the columns */ BColumnListView* table = dynamic_cast<BColumnListView*>( FindView(TABLE_STR) ); if (table) { BColumn* col; for( int32 k = 0; (col = table->ColumnAt(k)); k++ ) { BMessage colMsg; BString colName; col->GetColumnName(&colName); if( colMsg.AddString("name", colName.String() ) == B_OK && colMsg.AddFloat("width", col->Width() ) == B_OK && colMsg.AddBool("visible", col->IsVisible() ) == B_OK ) { config->AddMessage("column", &colMsg); } } } return B_OK; }
void BPose::Draw(BRect rect, const BRect& updateRect, BPoseView* poseView, BView* drawView, bool fullDraw, BPoint offset, bool selected) { // If the background wasn't cleared and Draw() is not called after // having edited a name or similar (with fullDraw) if (!fBackgroundClean && !fullDraw) { fBackgroundClean = true; poseView->Invalidate(rect); return; } else fBackgroundClean = false; bool directDraw = (drawView == poseView); bool windowActive = poseView->Window()->IsActive(); bool showSelectionWhenInactive = poseView->fShowSelectionWhenInactive; bool isDrawingSelectionRect = poseView->fIsDrawingSelectionRect; ModelNodeLazyOpener modelOpener(fModel); if (poseView->ViewMode() == kListMode) { uint32 size = poseView->IconSizeInt(); BRect iconRect(rect); iconRect.left += kListOffset; iconRect.right = iconRect.left + size; iconRect.top = iconRect.bottom - size; if (updateRect.Intersects(iconRect)) { iconRect.OffsetBy(offset); DrawIcon(iconRect.LeftTop(), drawView, poseView->IconSize(), directDraw, !windowActive && !showSelectionWhenInactive); } // draw text int32 columnsToDraw = 1; if (fullDraw) columnsToDraw = poseView->CountColumns(); for (int32 index = 0; index < columnsToDraw; index++) { BColumn* column = poseView->ColumnAt(index); if (column == NULL) break; // if widget doesn't exist, create it BTextWidget* widget = WidgetFor(column, poseView, modelOpener); if (widget && widget->IsVisible()) { BRect widgetRect(widget->ColumnRect(rect.LeftTop(), column, poseView)); if (updateRect.Intersects(widgetRect)) { BRect widgetTextRect(widget->CalcRect(rect.LeftTop(), column, poseView)); bool selectDuringDraw = directDraw && selected && windowActive; if (index == 0 && selectDuringDraw) { //draw with dark background to select text drawView->PushState(); drawView->SetLowColor(0, 0, 0); } if (index == 0) { widget->Draw(widgetRect, widgetTextRect, column->Width(), poseView, drawView, selected, fClipboardMode, offset, directDraw); } else { widget->Draw(widgetTextRect, widgetTextRect, column->Width(), poseView, drawView, false, fClipboardMode, offset, directDraw); } if (index == 0 && selectDuringDraw) drawView->PopState(); else if (index == 0 && selected) { if (windowActive || isDrawingSelectionRect) { widgetTextRect.OffsetBy(offset); drawView->InvertRect(widgetTextRect); } else if (!windowActive && showSelectionWhenInactive) { widgetTextRect.OffsetBy(offset); drawView->PushState(); drawView->SetDrawingMode(B_OP_BLEND); drawView->SetHighColor(128, 128, 128, 255); drawView->FillRect(widgetTextRect); drawView->PopState(); } } } } } } else { // draw in icon mode BPoint location(Location(poseView)); BPoint iconOrigin(location); iconOrigin += offset; DrawIcon(iconOrigin, drawView, poseView->IconSize(), directDraw, !windowActive && !showSelectionWhenInactive); BColumn* column = poseView->FirstColumn(); if (column == NULL) return; BTextWidget* widget = WidgetFor(column, poseView, modelOpener); if (widget == NULL || !widget->IsVisible()) return; rect = widget->CalcRect(location, 0, poseView); bool selectDuringDraw = directDraw && selected && (poseView->IsDesktopWindow() || windowActive); if (selectDuringDraw) { // draw with dark background to select text drawView->PushState(); drawView->SetLowColor(0, 0, 0); } widget->Draw(rect, rect, rect.Width(), poseView, drawView, selected, fClipboardMode, offset, directDraw); if (selectDuringDraw) drawView->PopState(); else if (selected && directDraw) { if (windowActive || isDrawingSelectionRect) { rect.OffsetBy(offset); drawView->InvertRect(rect); } else if (!windowActive && showSelectionWhenInactive) { drawView->PushState(); drawView->SetDrawingMode(B_OP_BLEND); drawView->SetHighColor(128, 128, 128, 255); drawView->FillRect(rect); drawView->PopState(); } } } }
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); } } } } }