diff options
author | sky@google.com <sky@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2008-10-24 22:58:08 +0000 |
---|---|---|
committer | sky@google.com <sky@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2008-10-24 22:58:08 +0000 |
commit | 62ca321dd5cd95b7e4fc9de922c2ca0703971361 (patch) | |
tree | ce782f196bd0933352bffae1130fd365a626ce25 /chrome/views/table_view.cc | |
parent | 9d6326fae66278988d0eb3f9d5b44e7d9f31870e (diff) | |
download | chromium_src-62ca321dd5cd95b7e4fc9de922c2ca0703971361.zip chromium_src-62ca321dd5cd95b7e4fc9de922c2ca0703971361.tar.gz chromium_src-62ca321dd5cd95b7e4fc9de922c2ca0703971361.tar.bz2 |
Handful of changes to NativeControl, TreeView and TableView I'm going
to need for the bookmark manager. Specifically:
. NativeController now delegates OnContextMenu to the
ContextMenuController.
. TableView allows a NULL model.
. TableView::SetColumns was buggy.
. Added a method that TableView invokes after painting.
. Added methods to TreeView for getting various state information.
BUG=674
TEST=make sure the various places in the UI we uses trees and table
work fine: cookies table, passwords table, task manager, bookmark
editor, search engines.
Review URL: http://codereview.chromium.org/8145
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@3956 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/views/table_view.cc')
-rw-r--r-- | chrome/views/table_view.cc | 69 |
1 files changed, 57 insertions, 12 deletions
diff --git a/chrome/views/table_view.cc b/chrome/views/table_view.cc index fe4a40e..bf35e1b 100644 --- a/chrome/views/table_view.cc +++ b/chrome/views/table_view.cc @@ -98,7 +98,6 @@ TableView::TableView(TableModel* model, table_view_wrapper_(this), custom_cell_font_(NULL), content_offset_(0) { - DCHECK(model); for (std::vector<TableColumn>::const_iterator i = columns.begin(); i != columns.end(); ++i) { AddColumn(*i); @@ -116,8 +115,15 @@ TableView::~TableView() { } void TableView::SetModel(TableModel* model) { + if (model == model_) + return; + + if (list_view_ && model_) + model_->SetObserver(NULL); model_ = model; - if (model_) + if (list_view_ && model_) + model_->SetObserver(this); + if (list_view_) OnModelChanged(); } @@ -303,7 +309,7 @@ void TableView::OnModelChanged() { int current_row_count = ListView_GetItemCount(list_view_); if (current_row_count > 0) OnItemsRemoved(0, current_row_count); - if (model_->RowCount()) + if (model_ && model_->RowCount()) OnItemsAdded(0, model_->RowCount()); } @@ -377,8 +383,14 @@ void TableView::OnItemsRemoved(int start, int length) { SendMessage(list_view_, WM_SETREDRAW, static_cast<WPARAM>(TRUE), 0); - // We don't seem to get notification in this case. - if (table_view_observer_ && had_selection && RowCount() == 0) + // If the row count goes to zero and we had a selection LVN_ITEMCHANGED isn't + // invoked, so we handle it here. + // + // When the model is set to NULL all the rows are removed. We don't notify + // the delegate in this case as setting the model to NULL is usually done as + // the last step before being deleted and callers shouldn't have to deal with + // getting a selection change when the model is being reset. + if (model_ && table_view_observer_ && had_selection && RowCount() == 0) table_view_observer_->OnSelectionChanged(); } @@ -388,7 +400,11 @@ void TableView::AddColumn(const TableColumn& col) { } void TableView::SetColumns(const std::vector<TableColumn>& columns) { - all_columns_.empty(); + // Remove the currently visible columns. + while (!visible_columns_.empty()) + SetColumnVisibility(visible_columns_.front(), false); + + all_columns_.clear(); for (std::vector<TableColumn>::const_iterator i = columns.begin(); i != columns.end(); ++i) { AddColumn(*i); @@ -514,6 +530,13 @@ LRESULT CALLBACK TableView::TableWndProc(HWND window, // resizing. return 1; + case WM_PAINT: { + LRESULT result = CallWindowProc(table_view->original_handler_, window, + message, w_param, l_param); + table_view->PostPaint(); + return result; + } + default: break; } @@ -565,7 +588,6 @@ HWND TableView::CreateNativeControl(HWND parent_container) { style, 0, 0, width(), height(), parent_container, NULL, NULL, NULL); - model_->SetObserver(this); // Make the selection extend across the row. // Reduce overdraw/flicker artifacts by double buffering. @@ -584,8 +606,11 @@ HWND TableView::CreateNativeControl(HWND parent_container) { static_cast<int>(i - visible_columns_.begin())); } + if (model_) + model_->SetObserver(this); + // Add the groups. - if (model_->HasGroups() && + if (model_ && model_->HasGroups() && win_util::GetWinVersion() > win_util::WINVERSION_2000) { ListView_EnableGroupView(list_view_, true); @@ -602,7 +627,8 @@ HWND TableView::CreateNativeControl(HWND parent_container) { } // Set the # of rows. - UpdateListViewCache(0, model_->RowCount(), true); + if (model_) + UpdateListViewCache(0, model_->RowCount(), true); if (table_type_ == ICON_AND_TEXT) { HIMAGELIST image_list = @@ -791,7 +817,10 @@ void TableView::InsertColumn(const TableColumn& tc, int index) { } } -LRESULT TableView::OnNotify(int w_param, NMHDR* hdr) { +LRESULT TableView::OnNotify(int w_param, LPNMHDR hdr) { + if (!model_) + return 0; + switch (hdr->code) { case NM_CUSTOMDRAW: { // Draw notification. dwDragState indicates the current stage of drawing. @@ -898,6 +927,19 @@ int TableView::CompareRows(int model_row1, int model_row2) { return SwapCompareResult(sort_result, sort_descriptors_[0].ascending); } +int TableView::GetColumnWidth(int column_id) { + if (!list_view_) + return -1; + + std::vector<int>::const_iterator i = + std::find(visible_columns_.begin(), visible_columns_.end(), column_id); + if (i == visible_columns_.end()) + return -1; + + return ListView_GetColumnWidth( + list_view_, static_cast<int>(i - visible_columns_.begin())); +} + LRESULT TableView::OnCustomDraw(NMLVCUSTOMDRAW* draw_info) { switch (draw_info->nmcd.dwDrawStage) { case CDDS_PREPAINT: { @@ -975,11 +1017,14 @@ LRESULT TableView::OnCustomDraw(NMLVCUSTOMDRAW* draw_info) { // It seems the state in nmcd.uItemState is not correct. // We'll retrieve it explicitly. - int selected = ListView_GetItemState(list_view_, view_index, - LVIS_SELECTED); + int selected = ListView_GetItemState( + list_view_, view_index, LVIS_SELECTED | LVIS_DROPHILITED); + bool drop_highlight = ((selected & LVIS_DROPHILITED) != 0); int bg_color_index; if (!IsEnabled()) bg_color_index = COLOR_3DFACE; + else if (drop_highlight) + bg_color_index = COLOR_HIGHLIGHT; else if (selected) bg_color_index = HasFocus() ? COLOR_HIGHLIGHT : COLOR_3DFACE; else |