void YabTabView::SetFocusTab(int32 tab, bool focused) { if (tab >= CountTabs()) tab = 0; if (tab < 0) tab = CountTabs() - 1; if (focused) { if (tab == fFocus) return; if (fFocus != -1){ if (TabAt (fFocus) != NULL) TabAt(fFocus)->MakeFocus(false); Invalidate(TabFrame(fFocus)); } if (TabAt(tab) != NULL){ TabAt(tab)->MakeFocus(true); Invalidate(TabFrame(tab)); fFocus = tab; } } else if (fFocus != -1) { TabAt(fFocus)->MakeFocus(false); Invalidate(TabFrame(fFocus)); fFocus = -1; } }
void YabTabView::Select(int32 index) { if (index < 0 || index >= CountTabs()) index = Selection(); BView *tab = TabAt(Selection()); if (tab) { Invalidate(); tab->Hide(); } tab = TabAt(index); if (tab) { if (index != 0 && !Bounds().Contains(TabFrame(index))){ if (!Bounds().Contains(TabFrame(index).LeftTop())) fTabOffset += TabFrame(index).left - Bounds().left - 20.0f; else fTabOffset += TabFrame(index).right - Bounds().right + 20.0f; } Invalidate(); tab->Show(); fSelection = index; FocusChanged = index+1; } }
YabTabView::~YabTabView() { for(int i=0; i<CountTabs(); i++) { delete TabAt(i); delete (BString*)fTabNames->RemoveItem(i); } delete fTabList; delete fTabNames; }
void TabView::MouseDown(BPoint where) { BTab* fadeTab = TabAt(0); BRect fadeTabFrame(TabFrame(0)); BTab* modulesTab = TabAt(1); BRect modulesTabFrame(TabFrame(1)); ModulesView* modulesView = dynamic_cast<ModulesView*>(modulesTab->View()); if (fadeTab != NULL && Selection() != 0 && fadeTabFrame.Contains(where) && modulesView != NULL) { // clicked on the fade tab modulesView->SaveState(); modulesView->_CloseSaver(); } else if (modulesTab != NULL && Selection() != 1 && modulesTabFrame.Contains(where) && modulesView != NULL) { // clicked on the modules tab BMessage message(kMsgSaverSelected); modulesView->MessageReceived(&message); } BTabView::MouseDown(where); }
void ControlsView::VolumeTabView::_RemoveVolume(dev_t device) { for (int i = 0; VolumeTab* item = (VolumeTab*)TabAt(i); i++) { if (item->Volume()->Device() == device) { if (i == 0) Select(1); else Select(i - 1); RemoveTab(i); delete item; return; } } }
void ControlsView::VolumeTabView::MessageReceived(BMessage* message) { switch (message->what) { case B_NODE_MONITOR: switch (message->FindInt32("opcode")) { case B_DEVICE_MOUNTED: _AddVolume(message->FindInt32("new device")); break; case B_DEVICE_UNMOUNTED: _RemoveVolume(message->FindInt32("device")); break; } break; case kBtnCancel: case kBtnRescan: ViewForTab(Selection())->MessageReceived(message); break; case B_SIMPLE_DATA: case B_REFS_RECEIVED: { entry_ref ref; for (int i = 0; message->FindRef("refs", i, &ref) == B_OK; i++) { BEntry entry(&ref, true); BPath path; entry.GetPath(&path); dev_t device = dev_for_path(path.Path()); for (int j = 0; VolumeTab* item = (VolumeTab*)TabAt(j); j++) { if (item->Volume()->Device() == device) { Select(j); ((VolumeView*)(item->View()))->SetPath(path); break; } } } break; } default: BTabView::MessageReceived(message); break; } }
BVolume* ControlsView::VolumeTabView::FindDeviceFor(dev_t device, bool invoke) { BVolume* volume = NULL; // Iterate through items looking for a BVolume representing this device. for (int i = 0; VolumeTab* item = (VolumeTab*)TabAt(i); i++) { if (item->Volume()->Device() == device) { volume = item->Volume(); if (invoke) Select(i); break; } } return volume; }
void ArpConfigurePanel::Select(int32 tab) { inherited::Select(tab); if( Parent() ) { BTab* tabobj = TabAt(tab); if( tabobj ) { BView* view = tabobj->View(); BRect frame(Frame()); if( view ) { view->ResizeTo(frame.Width()-mTabWidth, frame.Height()-mTabHeight); } } SendSetPanel(tab); } }
void ControlsView::VolumeTabView::_AddVolume(dev_t device) { // Make sure the volume is not already in the menu. for (int i = 0; VolumeTab* item = (VolumeTab*)TabAt(i); i++) { if (item->Volume()->Device() == device) return; } BVolume* volume = new BVolume(device); VolumeTab* item = new VolumeTab(volume); char name[B_PATH_NAME_LENGTH]; volume->GetName(name); AddTab(new VolumeView(name, volume), item); Invalidate(); }
void ArpConfigurePanel::SendSetPanel(int32 tab) { BTab* tabobj = TabAt(tab); if( tabobj ) { BView* view = tabobj->View(); if( view ) { BMessenger target(view); if( target.IsValid() ) { BMessage setPanel(ARP_SET_CONFIG_PANEL_MSG); setPanel.AddMessenger("panel", BMessenger(this)); target.SendMessage(&setPanel); ArpD(cdb << ADH << "Sent config panel msg: " << setPanel << endl); } else { ArpD(cdb << ADH << "Invalid messenger for view, " << "couldn't send panel message!" << endl); } } } }
BView* PrefletView::PageAt(int32 index) { return TabAt(index)->View(); }
BRect ControlsView::VolumeTabView::TabFrame(int32 index) const { float height = BTabView::TabFrame(index).Height(); float x = 0.0f; float width = 0.0f; float minStringWidth = StringWidth("Haiku"); int32 countTabs = CountTabs(); // calculate the total width if no truncation is made at all float averageWidth = Frame().Width() / countTabs; // margins are the deltas with the average widths float* margins = new float[countTabs]; for (int32 i = 0; i < countTabs; i++) { float tabLabelWidth = StringWidth(TabAt(i)->Label()); if (tabLabelWidth < minStringWidth) tabLabelWidth = minStringWidth; float tabWidth = tabLabelWidth + 3.0f * kSmallHMargin + ((VolumeTab*)TabAt(i))->IconWidth(); margins[i] = tabWidth - averageWidth; width += tabWidth; } // determine how much we should shave to show all tabs (truncating) float toShave = width - Frame().Width(); if (toShave > 0.0f) { // the thinest a tab can be to hold the minimum string float minimumMargin = minStringWidth + 3.0f * kSmallHMargin - averageWidth; float averageToShave; float oldToShave; /* we might have to do multiple passes because of the minimum tab width we are imposing. we could also fail to totally fit all tabs. TODO: allow paging. */ do { averageToShave = toShave / countTabs; oldToShave = toShave; for (int32 i = 0; i < countTabs; i++) { float iconWidth = ((VolumeTab*)TabAt(i))->IconWidth(); float newMargin = max_c(margins[i] - averageToShave, minimumMargin + iconWidth); toShave -= margins[i] - newMargin; margins[i] = newMargin; } } while (toShave > 0 && oldToShave != toShave); } for (int i = 0; i < index; i++) x += averageWidth + margins[i]; float margin = margins[index]; delete[] margins; return BRect(x, 0.0f, x + averageWidth + margin, height); }