/** * @brief Removes one item from the control. * @param[in] index item index. */ void BeColumnListViewAdapter::RemoveItem(SInt32 index) { BColumnListView* listView = getColumnListView(); BRow* row = listView->RowAt(index); listView->RemoveRow(row); delete row; }
/** * @brief Stops or restarts selection changed notification. * @param[in] doStop true to stop, false to restart. */ void BeColumnListViewAdapter::StopSelectionChangedNotification(bool doStop) { BColumnListView* listView = getColumnListView(); if (doStop) { if (0 == stoppedSelectionChangedNotificationCount) { BMessage* message = listView->SelectionMessage(); if (NULL != message) { stoppedSelectionChangedCommand = message->what; message->what = ID_NULL; } } stoppedSelectionChangedNotificationCount++; } else { stoppedSelectionChangedNotificationCount--; if (0 == stoppedSelectionChangedNotificationCount) { BMessage* message = listView->SelectionMessage(); if (NULL != message) { message->what = stoppedSelectionChangedCommand; stoppedSelectionChangedCommand = ID_NULL; } } } }
/** * @brief Sets associated data of specified index. * @param[in] rowIndex item index. * @param[in] data associated data. */ void BeColumnListViewAdapter::SetItemData(SInt32 rowIndex, void* data) { BColumnListView* listView = getColumnListView(); BeDataRow* row = dynamic_cast<BeDataRow*>(listView->RowAt(rowIndex)); if (NULL != row) { return row->SetItemData(data); } }
/** * @brief Gets a string at specified index from the control. * @param[in] rowIndex row index * @param[in] columnIndex column index * @param[out] text a string value is returned. */ void BeColumnListViewAdapter::GetItemText(SInt32 rowIndex, SInt32 columnIndex, MBCString& text) { BColumnListView* listView = getColumnListView(); BRow* row = listView->RowAt(rowIndex); BStringField* field = dynamic_cast<BStringField*>(row->GetField(columnIndex)); if (NULL != field) { text = field->String(); } }
/** * @brief Returns associated data of specified index. * @param[in] rowIndex item index. * @return associated data. */ void* BeColumnListViewAdapter::GetItemData(SInt32 rowIndex) { BColumnListView* listView = getColumnListView(); BeDataRow* row = dynamic_cast<BeDataRow*>(listView->RowAt(rowIndex)); if (NULL != row) { return row->GetItemData(); } else { return NULL; } }
/** * @brief Adds one item to the control. * @param[in] texts item texts for each column. * @param[in] data associated data of adding item. * @return the index of added item. */ SInt32 BeColumnListViewAdapter::AddItem(ConstAStr* texts, void* data) { BColumnListView* listView = getColumnListView(); BeDataRow* row = new BeDataRow(); SInt32 ix; for (ix = 0; ix < columnCount; ++ix) { row->SetField(new BStringField(texts[ix]), ix); } row->SetItemData(data); listView->AddRow(row); return listView->CountRows() - 1; }
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 YabWindow::MessageReceived(BMessage *message) { // if(message) message->PrintToStream(); switch(message->what) { case YABBUTTON: { BString tmpMessage(""); BButton *myButtonPressed; message->FindPointer("source",(void **) &myButtonPressed); tmpMessage += myButtonPressed->Name(); tmpMessage += "|"; messageString += tmpMessage; } break; case YABMENU: { BString tmpMessage(""); BMenuItem *mySelectedMenu; message->FindPointer("source",(void **) &mySelectedMenu); BMenu *myMenu = mySelectedMenu->Menu(); tmpMessage += ((BMenuBar*)myMenu->Supermenu())->Parent()->Name(); tmpMessage += ":"; tmpMessage += myMenu->Name(); tmpMessage += ":"; tmpMessage += mySelectedMenu->Label(); tmpMessage += "|"; messageString += tmpMessage; } break; case YABSUBMENU: { BString tmpMessage(""); BMenuItem *mySelectedMenu; message->FindPointer("source",(void **) &mySelectedMenu); BMenu *myMenu = mySelectedMenu->Menu(); tmpMessage += ((BMenuBar*)myMenu->Supermenu()->Supermenu())->Parent()->Name(); tmpMessage += ":"; tmpMessage += myMenu->Supermenu()->Name(); tmpMessage += ":"; tmpMessage += myMenu->Name(); tmpMessage += ":"; tmpMessage += mySelectedMenu->Label(); tmpMessage += "|"; messageString += tmpMessage; } break; case YABTEXTCONTROL: { BString tmpMessage(""); BTextControl *myTextControl; message->FindPointer("source",(void **) &myTextControl); tmpMessage += myTextControl->Name(); tmpMessage += ":"; tmpMessage += myTextControl->Text(); tmpMessage += "|"; messageString += tmpMessage; } break; case YABCHECKBOX: { BString tmpMessage(""); BCheckBox *myCheckBox; message->FindPointer("source",(void **) &myCheckBox); tmpMessage += myCheckBox->Name(); tmpMessage += ":"; if(myCheckBox->Value()==B_CONTROL_ON) tmpMessage += "ON|"; else tmpMessage += "OFF|"; messageString += tmpMessage; } break; case YABRADIOBUTTON: { BString tmpMessage(""); BRadioButton *myRadioButton; message->FindPointer("source",(void **) &myRadioButton); tmpMessage += myRadioButton->Name(); tmpMessage += "|"; messageString += tmpMessage; } break; case YABLISTBOXINVOKE: { BListView *myList; message->FindPointer("source",(void **) &myList); int i = myList->CurrentSelection(); if(i>=0) { BString tmpMessage(""); tmpMessage += myList->Name(); tmpMessage += ":_Invoke:"; // tmpMessage += ((BStringItem*)(myList->ItemAt(i)))->Text(); tmpMessage << i+1; tmpMessage += "|"; messageString += tmpMessage; } } break; case YABLISTBOXSELECT: { BListView *myList; message->FindPointer("source",(void **) &myList); int i = myList->CurrentSelection(); if(i>=0) { BString tmpMessage(""); tmpMessage += myList->Name(); tmpMessage += ":_Select:"; // tmpMessage += ((BStringItem*)(myList->ItemAt(i)))->Text(); tmpMessage << i+1; tmpMessage += "|"; messageString += tmpMessage; } } break; case YABDROPBOX: { BString tmpMessage(""); BMenuItem *myMenuItem; message->FindPointer("source",(void **) &myMenuItem); tmpMessage += (myMenuItem->Menu())->Supermenu()->Parent()->Name(); tmpMessage += ":"; tmpMessage += myMenuItem->Label(); tmpMessage += "|"; messageString += tmpMessage; } break; case YABSLIDER: { BString tmpMessage(""); BSlider *mySlider; message->FindPointer("source",(void **) &mySlider); tmpMessage += mySlider->Name(); tmpMessage += ":"; tmpMessage << mySlider->Value(); tmpMessage += "|"; messageString += tmpMessage; } break; case YABCOLORCONTROL: { rgb_color col; BString tmpMessage(""); BColorControl *myCControl; message->FindPointer("source",(void **) &myCControl); tmpMessage += myCControl->Name(); tmpMessage += ":"; col = myCControl->ValueAsColor(); tmpMessage << col.red << ":" << col.green << ":" << col.blue; tmpMessage += "|"; messageString += tmpMessage; } break; case YABTREEBOXINVOKE: { BOutlineListView *myList; message->FindPointer("source",(void **) &myList); int i = myList->FullListCurrentSelection(); if(i>=0) { BString tmpMessage(""); const char* txt = ((BStringItem*)(myList->FullListItemAt(i)))->Text(); tmpMessage += myList->Name(); tmpMessage += ":_Invoke:"; tmpMessage << i+1; /* int n = tmpMessage.Length(); BListItem *superitem = myList->Superitem(myList->FullListItemAt(i)); while(superitem) { BString t(""); t << ((BStringItem*)superitem)->Text() << ":"; tmpMessage.Insert(t,n); superitem = myList->Superitem(superitem); } tmpMessage += txt;*/ tmpMessage += "|"; messageString += tmpMessage; } } break; case YABTREEBOXSELECT: { BOutlineListView *myList; message->FindPointer("source",(void **) &myList); int i = myList->FullListCurrentSelection(); if(i>=0) { BString tmpMessage(""); const char* txt = ((BStringItem*)(myList->FullListItemAt(i)))->Text(); tmpMessage += myList->Name(); tmpMessage += ":_Select:"; tmpMessage << i+1; /* int n = tmpMessage.Length(); BListItem *superitem = myList->Superitem(myList->FullListItemAt(i)); while(superitem) { BString t(""); t << ((BStringItem*)superitem)->Text() << ":"; tmpMessage.Insert(t,n); superitem = myList->Superitem(superitem); } tmpMessage += txt;*/ tmpMessage += "|"; messageString += tmpMessage; } } break; case YABFILEBOXSELECT: { BColumnListView *myList; message->FindPointer("source",(void **) &myList); BRow *myRow = NULL; if(myList) myRow = myList->CurrentSelection(); if(myRow) { // if(!myList->IsFocus()) myList->MakeFocus(); BString tmpMessage(""); tmpMessage += myList->Name(); tmpMessage += ":_Select:"; tmpMessage << myList->IndexOf(myRow)+1; tmpMessage += "|"; messageString += tmpMessage; } } break; case YABFILEBOXINVOKE: { BColumnListView *myList; message->FindPointer("source",(void **) &myList); BRow *myRow = NULL; if(myList) myRow = myList->CurrentSelection(); if(myRow) { // if(!myList->IsFocus()) myList->MakeFocus(); BString tmpMessage(""); tmpMessage += myList->Name(); tmpMessage += ":_Invoke:"; tmpMessage << myList->IndexOf(myRow)+1; tmpMessage += "|"; messageString += tmpMessage; } } break; case YABSHORTCUT: { const char* myMsg; if(message->FindString("shortcut", &myMsg) == B_OK) { messageString += myMsg; messageString += "|"; } } break; default: BWindow::MessageReceived(message); break; } }
/** * @brief Returns item count in the control. * @return item count. */ SInt32 BeColumnListViewAdapter::GetCount() { BColumnListView* listView = getColumnListView(); return listView->CountRows(); }
/** * @brief Makes specified item selected. * @param[in] rowIndex item index. if this is -1, no item is selected. */ void BeColumnListViewAdapter::SetSelectedItem(SInt32 rowIndex) { BColumnListView* listView = getColumnListView(); BRow* row = listView->RowAt(rowIndex); listView->AddToSelection(row); }
/** * @brief Returns an index of selected item. * @return item index of selected item. or -1 if no item is selected. */ SInt32 BeColumnListViewAdapter::GetSelectedItem() { BColumnListView* listView = getColumnListView(); BRow* row = listView->CurrentSelection(); return listView->IndexOf(row); }
/** * @brief Removes all item from the control. */ void BeColumnListViewAdapter::RemoveAllItem() { BColumnListView* listView = getColumnListView(); listView->Clear(); }
int main(int argc, char** argv) { BApplication app("application/x-vnd.haiku-look"); BWindow* window = new Window(BRect(50, 50, 100, 100), "Look at these pretty controls!", B_TITLED_WINDOW, B_ASYNCHRONOUS_CONTROLS | B_AUTO_UPDATE_SIZE_LIMITS | B_QUIT_ON_WINDOW_CLOSE); window->SetLayout(new BGroupLayout(B_HORIZONTAL)); // create some controls // BListView BListView* listView = new BListView(); for (int32 i = 0; i < 20; i++) { BString itemLabel("List item "); itemLabel << i + 1; listView->AddItem(new BStringItem(itemLabel.String())); } BScrollView* scrollView = new BScrollView("scroller", listView, 0, true, true); scrollView->SetExplicitMinSize(BSize(300, 140)); // BColumnListView BColumnListView* columnListView = new BColumnListView("clv", 0, B_FANCY_BORDER); // B_PLAIN_BORDER); // B_NO_BORDER); columnListView->AddColumn(new BTitledColumn("Short", 150, 50, 500, B_ALIGN_LEFT), 0); columnListView->AddColumn(new BTitledColumn("Medium Length", 100, 50, 500, B_ALIGN_CENTER), 1); columnListView->AddColumn(new BTitledColumn("Some Long Column Name", 130, 50, 500, B_ALIGN_RIGHT), 2); // for (int32 i = 0; i < 20; i++) { // BString itemLabel("List Item "); // itemLabel << i + 1; // columnListView->AddItem(new BStringItem(itemLabel.String())); // } BGridView* controls = new BGridView(kInset, kInset); BGridLayout* layout = controls->GridLayout(); controls->SetExplicitMaxSize(BSize(B_SIZE_UNLIMITED, B_SIZE_UNLIMITED)); int32 row = 0; add_controls<BButton>(layout, row); add_controls<BCheckBox>(layout, row); add_controls<BRadioButton>(layout, row); add_menu_fields(layout, row); add_text_controls(layout, row); add_sliders(layout, row); add_status_bars(layout, row); BColorControl* colorControl = new BColorControl(B_ORIGIN, B_CELLS_32x8, 8.0f, "color control"); layout->AddView(colorControl, 0, row, 4); BTabView* tabView = new BTabView("tab view", B_WIDTH_FROM_WIDEST); BGroupView* content = new BGroupView(B_VERTICAL, kInset); BLayoutBuilder::Group<>(content) .Add(scrollView) .Add(columnListView) .Add(controls) .SetInsets(kInset, kInset, kInset, kInset); content->SetName("Tab 1"); tabView->AddTab(content); BView* tab2 = new BView("Tab 2", 0); tab2->SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR)); tabView->AddTab(tab2); tabView->AddTab(new BView("Tab 3", 0)); BMenuBar* menuBar = new BMenuBar("menu bar"); BMenu* menu = new BMenu("File"); menu->AddItem(new BMenuItem("Test Open BFilePanel", new BMessage(MSG_TEST_OPEN_FILE_PANEL))); menu->AddItem(new BMenuItem("Test Save BFilePanel", new BMessage(MSG_TEST_SAVE_FILE_PANEL))); menu->AddItem(new BMenuItem("Click me!", NULL)); menu->AddItem(new BMenuItem("Another option", NULL)); menu->AddSeparatorItem(); menu->AddItem(new BMenuItem("Quit", new BMessage(B_QUIT_REQUESTED))); menuBar->AddItem(menu); menu = new BMenu("Edit"); menu->SetEnabled(false); menu->AddItem(new BMenuItem("Cut", NULL)); menu->AddItem(new BMenuItem("Copy", NULL)); menu->AddSeparatorItem(); menu->AddItem(new BMenuItem("Past", NULL)); menuBar->AddItem(menu); menu = new BMenu("One Item"); menu->AddItem(new BMenuItem("Only", NULL)); menuBar->AddItem(menu); menu = new BMenu("Sub Menu"); BMenu* subMenu = new BMenu("Click me"); subMenu->AddItem(new BMenuItem("Either", NULL)); subMenu->AddItem(new BMenuItem("Or", NULL)); subMenu->SetRadioMode(true); menu->AddItem(subMenu); menuBar->AddItem(menu); BButton* okButton = new BButton("OK", new BMessage(B_QUIT_REQUESTED)); BLayoutBuilder::Group<>(window, B_VERTICAL, 0) .Add(menuBar) .AddGroup(B_VERTICAL, kInset) .SetInsets(kInset, kInset, kInset, kInset) .Add(tabView) .AddGroup(B_HORIZONTAL, kInset) .Add(new BButton("Revert", new BMessage(MSG_TOGGLE_LOOK))) .AddGlue() .Add(new BButton("Cancel", NULL)) .Add(okButton); window->SetDefaultButton(okButton); window->Show(); app.Run(); return 0; }