int CDDBaseGrid::ReSort(CString defaultcol) { // Re-perform the previous sort. If there was no previous sort then sort // by defaultcol. if (m_lastSortCol.IsEmpty()) { return SortBy(defaultcol); } // else // Fool the sort direction toggle by toggling back, then // do regular sort. m_sortAscending = !m_sortAscending; return SortBy(m_lastSortCol); }
///////////////////////////////////////////////////////////////////////////// // OnTH_LClicked // Sent whenever the user clicks the left mouse button within the top heading // this message is sent when the button goes down then again when the button goes up // Params: // col, row - coordinates of a cell that received mouse click event // updn - is TRUE if mouse button is 'down' and FALSE if button is 'up' // processed - indicates if current event was processed by other control in the grid. // rect - represents the CDC rectangle of cell in question // point - represents the screen point where the mouse event was detected // Return: // <none> void CDDBaseGrid::OnTH_LClicked(int col,long row,int updn,RECT *rect,POINT *point,BOOL processed) { //UNREFERENCED_PARAMETER(col); UNREFERENCED_PARAMETER(row); UNREFERENCED_PARAMETER(updn); UNREFERENCED_PARAMETER(*rect); UNREFERENCED_PARAMETER(*point); UNREFERENCED_PARAMETER(processed); // Sort by selected column when user clicks in column heading and // did not do a column swap. // If the button-up col does not match the button-down col, then a col swap occurred. // Column sort can be turned on/off by sbuclass grids. Sort only if on. if (m_sortEnabled) { if (updn == TRUE) // Button Down { m_THButtonDownCol = col; } else if (col == m_THButtonDownCol) // Button Up, down & up cols match? { SortBy(col); RedrawAll(); } } }
void AbstractTestModel::sort(int column, Qt::SortOrder order /* = Qt::AscendingOrder */) { m_sortColumn = column; m_sortOrder = order; SortBy(column, order); Q_EMIT SortingChanged(column, order); }
/////////////// // Sorts the list by the current sorting column // Useful, when you're re-filling the list or adding new items void CListview::ReSort() { // Find the column std::vector<CListviewColumn *>::iterator it = tColumns.begin(); int i = 0; for (; it != tColumns.end(); it++, i++) if ((*it)->getSortDirection() != sort_None) break; // Not found if (it == tColumns.end()) return; // Sort SortBy(i, (*it)->getSortDirection() == sort_Ascending); }
///////////////////////////////////////////////////////////////////////////// // OnTH_LClicked // Sent whenever the user clicks the left mouse button within the top heading // this message is sent when the button goes down then again when the button goes up // // 'col' is negative if the area clicked in is not valid // 'updn' TRUE if the button is down FALSE if the button just when up void MyCug::OnTH_LClicked(int col,long row,int updn,RECT *rect,POINT *point,BOOL processed) { if ( !updn ) { if ( m_nSortCol != GetColTranslation( col )) { m_nSortDir = UG_SORT_ASCENDING; } else if ( m_nSortDir == UG_SORT_DESCENDING ) { m_nSortDir = UG_SORT_ASCENDING; } else if ( m_nSortDir = UG_SORT_ASCENDING ) { m_nSortDir = UG_SORT_DESCENDING; } //m_nSortCol = col; m_nSortCol = GetColTranslation( col ); SortBy( col, m_nSortDir ); RedrawAll(); } }
nsresult nsAbView::RefreshTree() { nsresult rv; // The PREF_MAIL_ADDR_BOOK_LASTNAMEFIRST pref affects how the GeneratedName column looks. // so if the GeneratedName is our primary or secondary sort, // we need to resort. // the same applies for kPhoneticNameColumn // // XXX optimize me // PrimaryEmail is always the secondary sort, unless it is currently the // primary sort. So, if PrimaryEmail is the primary sort, // GeneratedName might be the secondary sort. // // One day, we can get fancy and remember what the secondary sort is. // We do that, we can fix this code. At best, it will turn a sort into a invalidate. // // If neither the primary nor the secondary sorts are GeneratedName (or kPhoneticNameColumn), // all we have to do is invalidate (to show the new GeneratedNames), // but the sort will not change. if (mSortColumn.EqualsLiteral(GENERATED_NAME_COLUMN_ID) || mSortColumn.EqualsLiteral(kPriEmailProperty) || mSortColumn.EqualsLiteral(kPhoneticNameColumn)) { rv = SortBy(mSortColumn.get(), mSortDirection.get()); } else { rv = InvalidateTree(ALL_ROWS); // Although the selection hasn't changed, the card that is selected may need // to be displayed differently, therefore pretend that the selection has // changed to force that update. SelectionChanged(); } return rv; }
int CDDBaseGrid::SortBy(int col) { CString colname = this->QuickGetText(col, -1); return SortBy(colname); }
NS_IMETHODIMP nsAbView::SetView(nsIAbDirectory *aAddressBook, nsIAbViewListener *aAbViewListener, const nsAString &aSortColumn, const nsAString &aSortDirection, nsAString &aResult) { // Ensure we are initialized nsresult rv = Initialize(); mAbViewListener = nsnull; if (mTree) { // Try and speed deletion of old cards by disconnecting the tree from us. mTreeSelection->ClearSelection(); mTree->SetView(nsnull); } // Clear out old cards PRInt32 i = mCards.Count(); while(i-- > 0) { rv = RemoveCardAt(i); NS_ASSERTION(NS_SUCCEEDED(rv), "remove card failed\n"); } mDirectory = aAddressBook; rv = EnumerateCards(); NS_ENSURE_SUCCESS(rv, rv); NS_NAMED_LITERAL_STRING(generatedNameColumnId, GENERATED_NAME_COLUMN_ID); // See if the persisted sortColumn is valid. // It may not be, if you migrated from older versions, or switched between // a mozilla build and a commercial build, which have different columns. nsAutoString actualSortColumn; if (!generatedNameColumnId.Equals(aSortColumn) && mCards.Count()) { nsIAbCard *card = ((AbCard *)(mCards.ElementAt(0)))->card; nsString value; // XXX todo // Need to check if _Generic is valid. GetCardValue() will always return NS_OK for _Generic // We're going to have to ask mDirectory if it is. // It might not be. example: _ScreenName is valid in Netscape, but not Mozilla. rv = GetCardValue(card, PromiseFlatString(aSortColumn).get(), value); if (NS_FAILED(rv)) actualSortColumn = generatedNameColumnId; else actualSortColumn = aSortColumn; } else actualSortColumn = aSortColumn; rv = SortBy(actualSortColumn.get(), PromiseFlatString(aSortDirection).get()); NS_ENSURE_SUCCESS(rv, rv); mAbViewListener = aAbViewListener; if (mAbViewListener && !mSuppressCountChange) { rv = mAbViewListener->OnCountChanged(mCards.Count()); NS_ENSURE_SUCCESS(rv, rv); } aResult = actualSortColumn; return NS_OK; }
/////////////////// // Mouse up event int CListview::DoMouseUp(int x, int y, int dx, int dy, MouseButton button, const ModifiersState& modstate) { if(cScrollbar->isMouseDown() && cScrollbar->getVisible()) { cScrollbar->DoMouseUp(x - cScrollbar->getX(), y - cScrollbar->getY(), dx, dy, button, modstate); CContainerWidget::DoMouseUp(x, y, dx, dy, button, modstate); return WID_PROCESSED; } else { fLastMouseUp = AbsTime(); } // Column headers if (bShowColumnHeaders) { if( y >= cBorder.getTopW() && y < tItemArea.y && tLX->currentTime-fLastMouseUp >= 0.15f && iGrabbed <= 0) { fLastMouseUp = tLX->currentTime; iGrabbed = -1; int cur_x = cBorder.getLeftW(); std::vector<CListviewColumn *>::iterator col = tColumns.begin(); for (int i = 0; col != tColumns.end(); col++, i++) { (*col)->setMouseDown(false); // Mouse up over the column if (x >= cur_x && x < cur_x + (*col)->getWidth()) { bool asc = ((*col)->getSortDirection() != sort_Ascending); (*col)->setSortDirection(asc ? sort_Ascending : sort_Descending); SortBy(i, asc); } else (*col)->setSortDirection(sort_None); cur_x += (*col)->getWidth(); } CWidget::DoMouseUp(x, y, dx, dy, button, modstate); return WID_PROCESSED; } iGrabbed = 0; } setSelectedSub(NULL, -1); // // Process the items // // Send the event to the focused widget if (tFocusedSubWidget) { tFocusedSubWidget->DoMouseUp(x, y, dx, dy, button, modstate); } int count = 0; int cur_y = tItemArea.y; std::list<CListviewItem *>::iterator item = tItems.begin(); for(; item != tItems.end(); item++) { if (!(*item)->isVisible()) continue; if(count++ < cScrollbar->getValue()) continue; // Find the max height int h = (*item)->getHeight(); if(y > cur_y && y < cur_y + h) { bool doubleclick = false; if(tSelected && button == /*MBT_LEFT*/0) { if(tSelected == (*item)) { if(tLX->currentTime - fLastMouseUp < 0.5f) { doubleclick = true; fLastMouseUp = AbsTime(); CALL_EVENT(OnDoubleClick, (this, tSelected, count - 1)); } } } // Go through the sub items, check which one was clicked on std::list<CListviewSubitem *>::iterator sub = (*item)->getSubitems().begin(); std::vector<CListviewColumn *>::iterator col = tColumns.begin(); int cur_x = tItemArea.x; int i=0; for(; sub != (*item)->getSubitems().end() && col != tColumns.end(); col++, sub++,i++) { if((*sub)->isVisible()) if(x >= cur_x && x < cur_x + (*col)->getWidth()) setSelectedSub(*sub, i); // HINT: mouseup can receive only focused widget => no need to test events here cur_x += (*col)->getWidth(); } setSelected(item, count - 1); if(!doubleclick) fLastMouseUp = tLX->currentTime; return WID_PROCESSED; } // Check that we don't overflow cur_y += (*item)->getHeight(); if(cur_y >= tItemArea.y + tItemArea.h) break; } CContainerWidget::DoMouseUp(x, y, dx, dy, button, modstate); return WID_PROCESSED; }
/*************************************************** SortBy Sorts the rows in the grid based on the given array of columns. The order in which the column numbers appear in the array determine how the sub-sorts are performed, with [0] being the primary sort. The order of the sort depends on the given flags. Note: This function will not redraw the grid after the sort is performed. Once a redraw is required call CUGCtrl::RedrawAll() new sort features - halfway point checking - row skipping Params cols - column number array to sort the grid by numCols - number of column numbers in the array flags - UG_SORT_ASCENDING or UG_SORT_DESCENDING Return UG_SUCCESS - success UG_ERROR - failure ****************************************************/ int CUGMem::SortBy(int *cols,int numCols,int flags) { return SortBy(0,0x7FFFFFFF,cols,numCols,flags); }
/*************************************************** SortBy Sorts the rows in the grid based on the given column the order of the sort depends on the given flags. Note: This function will not redraw the grid after the sort is performed. Once a redraw is required call CUGCtrl::RedrawAll() Params col - column to sort the grid by flags - UG_SORT_ASCENDING or UG_SORT_DESCENDING Return UG_SUCCESS - success UG_ERROR - failure ****************************************************/ int CUGMem::SortBy(int col,int flags) { return SortBy(&col,1,flags); }