/*********************************************************** * Destructor ***********************************************************/ HListView::~HListView() { HPrefs* prefs = ((HApp*)be_app)->Prefs(); for (int16 i = 1; i <= 6; i++) { CLVColumn* col = ColumnAt(i); BString name = "col"; name << (int32)i; int16 width = static_cast<int16>(col->Width()); prefs->SetData(name.String(), width); } SetInvocationMessage(NULL); SetSelectionMessage(NULL); }
// Saves the application settings file to (saveEntry). Because this is a // non-essential file, errors are ignored when writing the settings. void ShortcutsWindow::_SaveWindowSettings(BEntry& saveEntry) { BFile saveTo(&saveEntry, B_WRITE_ONLY | B_CREATE_FILE | B_ERASE_FILE); if (saveTo.InitCheck() != B_OK) return; BMessage saveMsg; saveMsg.AddRect("window frame", Frame()); for (int i = 0; i < fColumnListView->CountColumns(); i++) { CLVColumn* column = fColumnListView->ColumnAt(i); saveMsg.AddFloat("column width", column->Width()); } saveMsg.Flatten(&saveTo); }
void ColumnListView::UpdateColumnSizesDataRectSizeScrollBars() { //Figure out the width float ColumnBegin; float ColumnEnd = -1.0; fDataWidth = 0.0; bool NextPushedByExpander = false; int32 NumberOfColumns = fColumnDisplayList.CountItems(); for(int32 Counter = 0; Counter < NumberOfColumns; Counter++) { CLVColumn* Column = (CLVColumn*)fColumnDisplayList.ItemAt(Counter); if(NextPushedByExpander) Column->fPushedByExpander = true; else Column->fPushedByExpander = false; if(Column->IsShown()) { float ColumnWidth = Column->Width(); ColumnBegin = ColumnEnd + 1.0; ColumnEnd = ColumnBegin + ColumnWidth; Column->fColumnBegin = ColumnBegin; Column->fColumnEnd = ColumnEnd; fDataWidth = Column->fColumnEnd; if(NextPushedByExpander) if(!(Column->fFlags & CLV_PUSH_PASS)) NextPushedByExpander = false; if(Column->fFlags & CLV_EXPANDER) //Set the next column to be pushed NextPushedByExpander = true; } } //Figure out the height fDataHeight = 0.0; int32 NumberOfItems = CountItems(); for(int32 Counter2 = 0; Counter2 < NumberOfItems; Counter2++) fDataHeight += ItemAt(Counter2)->Height()+1.0; if(NumberOfItems > 0) fDataHeight -= 1.0; //Update the scroll bars UpdateScrollBars(); }
// Loads the application settings file from (loadMsg) and resizes the interface // to match the previously saved settings. Because this is a non-essential // file, errors are ignored when loading the settings. void ShortcutsWindow::_LoadWindowSettings(const BMessage& loadMsg) { BRect frame; if (loadMsg.FindRect("window frame", &frame) == B_OK) { // Ensure the frame does not resize below the computed minimum. float width = max_c(Bounds().right, frame.right - frame.left); float height = max_c(Bounds().bottom, frame.bottom - frame.top); ResizeTo(width, height); // Ensure the frame is not placed outside of the screen. BScreen screen(this); float left = min_c(screen.Frame().right - width, frame.left); float top = min_c(screen.Frame().bottom - height, frame.top); MoveTo(left, top); } for (int i = 0; i < fColumnListView->CountColumns(); i++) { CLVColumn* column = fColumnListView->ColumnAt(i); float columnWidth; if (loadMsg.FindFloat("column width", i, &columnWidth) == B_OK) column->SetWidth(max_c(column->Width(), columnWidth)); } }
void ColumnListView::MouseDown(BPoint point) { int prevColumn = _selectedColumn; int32 numberOfColumns = fColumnDisplayList.CountItems(); float xleft = point.x; for(int32 Counter = 0; Counter < numberOfColumns; Counter++) { CLVColumn* Column = (CLVColumn*)fColumnDisplayList.ItemAt(Counter); if(Column->IsShown()) { if (xleft > 0) { xleft -= Column->Width(); if (xleft <= 0) { SetSelectedColumnIndex(GetActualIndexOf(Counter)); break; } } } } int32 ItemIndex = IndexOf(point); if(ItemIndex >= 0) { CLVListItem* ClickedItem = (CLVListItem*)BListView::ItemAt(ItemIndex); if(ClickedItem->fSuperItem) if(ClickedItem->fExpanderButtonRect.Contains(point)) { if(ClickedItem->IsExpanded()) Collapse(ClickedItem); else Expand(ClickedItem); return; } } // If it's a right-click, hoist up the popup-menu const char * selectedText = NULL; CLVColumn * col = ColumnAt(_selectedColumn); if (col) { BPopUpMenu * popup = col->GetPopup(); if (popup) { BMessage * msg = Window()->CurrentMessage(); int32 buttons; if ((msg->FindInt32("buttons", &buttons) == B_NO_ERROR)&&(buttons == B_SECONDARY_MOUSE_BUTTON)) { BPoint where(point); Select(IndexOf(where)); ConvertToScreen(&where); BMenuItem * result = popup->Go(where, false); if (result) selectedText = result->Label(); } } } int prevRow = CurrentSelection(); BListView::MouseDown(point); int curRow = CurrentSelection(); if ((_editMessage != NULL)&&((selectedText)||((_selectedColumn == prevColumn)&&(curRow == prevRow)))) { // Send mouse message... BMessage temp(*_editMessage); temp.AddInt32("column", _selectedColumn); temp.AddInt32("row", CurrentSelection()); if (selectedText) temp.AddString("text", selectedText); else temp.AddInt32("mouseClick", 0); _editTarget.SendMessage(&temp); } }