diff options
| -rw-r--r-- | UnityCore/ResultIterator.cpp | 8 | ||||
| -rw-r--r-- | dash/LensView.cpp | 8 | ||||
| -rw-r--r-- | dash/ResultView.cpp | 79 | ||||
| -rw-r--r-- | dash/ResultView.h | 21 | ||||
| -rw-r--r-- | dash/ResultViewGrid.cpp | 83 | ||||
| -rw-r--r-- | dash/ResultViewGrid.h | 5 | ||||
| -rw-r--r-- | plugins/unityshell/src/unity-rvgrid-accessible.cpp | 7 |
7 files changed, 130 insertions, 81 deletions
diff --git a/UnityCore/ResultIterator.cpp b/UnityCore/ResultIterator.cpp index 9a7387f7a..d4a5d1971 100644 --- a/UnityCore/ResultIterator.cpp +++ b/UnityCore/ResultIterator.cpp @@ -30,8 +30,8 @@ namespace } ResultIterator::ResultIterator(glib::Object<DeeModel> model) - : model_(model, glib::AddRef()) - , iter_(dee_model_get_first_iter(model)) + : model_(model) + , iter_(model ? dee_model_get_first_iter(model) : NULL) , tag_(NULL) , iter_result_(model_, iter_, tag_) , cache_invalidated_(false) @@ -39,7 +39,7 @@ ResultIterator::ResultIterator(glib::Object<DeeModel> model) } ResultIterator::ResultIterator(glib::Object<DeeModel> model, DeeModelIter* iter, DeeModelTag* tag) - : model_(model, glib::AddRef()) + : model_(model) , iter_(iter) , tag_(tag) , iter_result_(model_, iter_, tag_) @@ -138,11 +138,13 @@ Result const& ResultIterator::operator*() bool const ResultIterator::IsLast() { + if (!model_) return true; return (dee_model_is_last(model_, iter_)); } bool const ResultIterator::IsFirst() { + if (!model_) return true; return (dee_model_is_first(model_, iter_)); } diff --git a/dash/LensView.cpp b/dash/LensView.cpp index 9e8c7ac08..487128431 100644 --- a/dash/LensView.cpp +++ b/dash/LensView.cpp @@ -303,12 +303,12 @@ void LensView::OnResultAdded(Result const& result) { try { PlacesGroup* group = categories_.at(result.category_index); - ResultViewGrid* grid = static_cast<ResultViewGrid*>(group->GetChildView()); + //ResultViewGrid* grid = static_cast<ResultViewGrid*>(group->GetChildView()); std::string uri = result.uri; LOG_TRACE(logger) << "Result added: " << uri; - grid->AddResult(const_cast<Result&>(result)); + //grid->AddResult(const_cast<Result&>(result)); counts_[group]++; UpdateCounts(group); // make sure we don't display the no-results-hint if we do have results @@ -327,12 +327,12 @@ void LensView::OnResultRemoved(Result const& result) { try { PlacesGroup* group = categories_.at(result.category_index); - ResultViewGrid* grid = static_cast<ResultViewGrid*>(group->GetChildView()); + //ResultViewGrid* grid = static_cast<ResultViewGrid*>(group->GetChildView()); std::string uri = result.uri; LOG_TRACE(logger) << "Result removed: " << uri; - grid->RemoveResult(const_cast<Result&>(result)); + //grid->RemoveResult(const_cast<Result&>(result)); counts_[group]--; UpdateCounts(group); } catch (std::out_of_range& oor) { diff --git a/dash/ResultView.cpp b/dash/ResultView.cpp index c25c9810f..b3707038d 100644 --- a/dash/ResultView.cpp +++ b/dash/ResultView.cpp @@ -56,9 +56,13 @@ ResultView::~ResultView() { ClearIntrospectableWrappers(); - for (auto result : results_) + if (result_model_) { - renderer_->Unload(result); + for (ResultIterator iter(result_model_); !iter.IsLast(); ++iter) + { + Result result(*iter); + renderer_->Unload(result); + } } renderer_->UnReference(); @@ -86,7 +90,6 @@ void ResultView::SetModelRenderer(ResultRenderer* renderer) void ResultView::AddResult(Result& result) { - results_.push_back(result); renderer_->Preload(result); NeedRedraw(); @@ -94,25 +97,65 @@ void ResultView::AddResult(Result& result) void ResultView::RemoveResult(Result& result) { - ResultList::iterator it; - std::string uri = result.uri; + renderer_->Unload(result); +} + +void ResultView::OnRowAdded(DeeModel* model, DeeModelIter* iter) +{ + Result result(model, iter, renderer_tag_); + AddResult(result); +} - for (it = results_.begin(); it != results_.end(); ++it) +void ResultView::OnRowRemoved(DeeModel* model, DeeModelIter* iter) +{ + Result result(model, iter, renderer_tag_); + RemoveResult(result); +} + +void ResultView::SetModel(glib::Object<DeeModel> const& model, DeeModelTag* tag) +{ + // cleanup + if (result_model_) { - if (result.uri == (*it).uri) - { - results_.erase(it); - break; - } + sig_manager_.Disconnect(result_model_.RawPtr(), "row-added"); + sig_manager_.Disconnect(result_model_.RawPtr(), "row-removed"); + } + + result_model_ = model; + renderer_tag_ = tag; + + if (model) + { + typedef glib::Signal<void, DeeModel*, DeeModelIter*> RowSignalType; + + sig_manager_.Add(new RowSignalType(model, + "row-added", + sigc::mem_fun(this, &ResultView::OnRowAdded))); + sig_manager_.Add(new RowSignalType(model, + "row-removed", + sigc::mem_fun(this, &ResultView::OnRowRemoved))); + } - renderer_->Unload(result); } -ResultView::ResultList ResultView::GetResultList() +int ResultView::GetNumResults() { - return results_; + if (result_model_) + return static_cast<int>(dee_model_get_n_rows(result_model_)); + + return 0; } +ResultIterator ResultView::GetIteratorAtRow(int row) +{ + DeeModelIter* iter = NULL; + if (result_model_) + { + iter = row > 0 ? dee_model_get_iter_at_row(result_model_, row) : + dee_model_get_first_iter(result_model_); + } + return ResultIterator(result_model_, iter, renderer_tag_); +} long ResultView::ComputeContentSize() { @@ -146,10 +189,14 @@ debug::Introspectable::IntrospectableList ResultView::GetIntrospectableChildren( { ClearIntrospectableWrappers(); - for (auto result: results_) + if (result_model_) { - introspectable_children_.push_back(new debug::ResultWrapper(result)); + for (ResultIterator iter(result_model_); !iter.IsLast(); ++iter) + { + introspectable_children_.push_back(new debug::ResultWrapper(*iter)); + } } + return introspectable_children_; } diff --git a/dash/ResultView.h b/dash/ResultView.h index 224d11637..6366ae2c7 100644 --- a/dash/ResultView.h +++ b/dash/ResultView.h @@ -29,6 +29,7 @@ #include <UnityCore/GLibSignal.h> #include <UnityCore/Results.h> +#include <UnityCore/ResultIterator.h> #include "unity-shared/Introspectable.h" #include "ResultRenderer.h" @@ -42,17 +43,11 @@ class ResultView : public nux::View, public debug::Introspectable public: NUX_DECLARE_OBJECT_TYPE(ResultView, nux::View); - typedef std::vector<Result> ResultList; - ResultView(NUX_FILE_LINE_DECL); virtual ~ResultView(); void SetModelRenderer(ResultRenderer* renderer); - - void AddResult(Result& result); - void RemoveResult(Result& result); - - ResultList GetResultList (); + void SetModel(glib::Object<DeeModel> const& model, DeeModelTag* tag); nux::Property<bool> expanded; nux::Property<int> results_per_row; @@ -60,6 +55,7 @@ public: sigc::signal<void, std::string const&> UriActivated; std::string GetName() const; + ResultIterator GetIteratorAtRow(int row); void AddProperties(GVariantBuilder* builder); IntrospectableList GetIntrospectableChildren(); @@ -68,12 +64,21 @@ protected: virtual void DrawContent(nux::GraphicsEngine& GfxContext, bool force_draw); virtual long ComputeContentSize(); + virtual void AddResult(Result& result); + virtual void RemoveResult(Result& result); + + int GetNumResults(); + // properties ResultRenderer* renderer_; - ResultList results_; + glib::Object<DeeModel> result_model_; + DeeModelTag* renderer_tag_; + glib::SignalManager sig_manager_; IntrospectableList introspectable_children_; private: + void OnRowAdded(DeeModel* model, DeeModelIter* iter); + void OnRowRemoved(DeeModel* model, DeeModelIter* iter); void ClearIntrospectableWrappers(); }; diff --git a/dash/ResultViewGrid.cpp b/dash/ResultViewGrid.cpp index a322c8126..540234ba2 100644 --- a/dash/ResultViewGrid.cpp +++ b/dash/ResultViewGrid.cpp @@ -152,11 +152,12 @@ bool ResultViewGrid::DoLazyLoad() // instead we will just pre-load all the items if expanded or just one row if not int index = 0; int items_per_row = GetItemsPerRow(); - for (auto it = results_.begin() + last_lazy_loaded_result_; it != results_.end(); it++) + for (ResultIterator it(GetIteratorAtRow(last_lazy_loaded_result_)); !it.IsLast(); ++it) { if ((!expanded && index < items_per_row) || expanded) { - renderer_->Preload((*it)); + Result result(*it); + renderer_->Preload(result); last_lazy_loaded_result_ = index; } @@ -199,7 +200,6 @@ void ResultViewGrid::SetModelRenderer(ResultRenderer* renderer) void ResultViewGrid::AddResult(Result& result) { - results_.push_back(result); QueueViewChanged(); } @@ -213,8 +213,9 @@ void ResultViewGrid::SizeReallocate() { //FIXME - needs to use the geometry assigned to it, but only after a layout int items_per_row = GetItemsPerRow(); + int num_results = GetNumResults(); - int total_rows = std::ceil(results_.size() / (double)items_per_row) ; + int total_rows = std::ceil(num_results / (double)items_per_row) ; int total_height = 0; if (expanded) @@ -284,13 +285,14 @@ bool ResultViewGrid::InspectKeyEvent(unsigned int eventType, unsigned int keysym } int items_per_row = GetItemsPerRow(); - int total_rows = std::ceil(results_.size() / static_cast<float>(items_per_row)); // items per row is always at least 1 + int num_results = GetNumResults(); + int total_rows = std::ceil(num_results / static_cast<float>(items_per_row)); // items per row is always at least 1 total_rows = (expanded) ? total_rows : 1; // restrict to one row if not expanded // check for edge cases where we want the keynav to bubble up if (direction == nux::KEY_NAV_LEFT && (selected_index_ % items_per_row == 0)) return false; // pressed left on the first item, no diiice - else if (direction == nux::KEY_NAV_RIGHT && (selected_index_ == static_cast<int>(results_.size() - 1))) + else if (direction == nux::KEY_NAV_RIGHT && (selected_index_ == static_cast<int>(num_results - 1))) return false; // pressed right on the last item, nope. nothing for you else if (direction == nux::KEY_NAV_RIGHT && (selected_index_ % items_per_row) == (items_per_row - 1)) return false; // pressed right on the last item in the first row in non expanded mode. nothing doing. @@ -343,31 +345,19 @@ void ResultViewGrid::OnKeyDown (unsigned long event_type, unsigned long event_ke // if we got this far, we definately got a keynav signal - ResultList::iterator current_focused_result = results_.end(); if (focused_uri_.empty()) - focused_uri_ = results_.front().uri; + focused_uri_ = (*GetIteratorAtRow(0)).uri; std::string next_focused_uri; - ResultList::iterator it; int items_per_row = GetItemsPerRow(); - int total_rows = std::ceil(results_.size() / static_cast<float>(items_per_row)); // items per row is always at least 1 + int num_results = GetNumResults(); + int total_rows = std::ceil(num_results / static_cast<float>(items_per_row)); // items per row is always at least 1 total_rows = (expanded) ? total_rows : 1; // restrict to one row if not expanded - // find the currently focused item - for (it = results_.begin(); it != results_.end(); ++it) - { - std::string result_uri = (*it).uri; - if (result_uri == focused_uri_) - { - current_focused_result = it; - break; - } - } - if (direction == nux::KEY_NAV_LEFT && (selected_index_ == 0)) return; // pressed left on the first item, no diiice - if (direction == nux::KEY_NAV_RIGHT && (selected_index_ == static_cast<int>(results_.size() - 1))) + if (direction == nux::KEY_NAV_RIGHT && (selected_index_ == (num_results - 1))) return; // pressed right on the last item, nope. nothing for you if (direction == nux::KEY_NAV_RIGHT && !expanded && selected_index_ == items_per_row - 1) @@ -400,8 +390,9 @@ void ResultViewGrid::OnKeyDown (unsigned long event_type, unsigned long event_ke } selected_index_ = std::max(0, selected_index_()); - selected_index_ = std::min(static_cast<int>(results_.size() - 1), selected_index_()); - focused_uri_ = results_[selected_index_].uri; + selected_index_ = std::min(num_results - 1, selected_index_()); + ResultIterator iter(GetIteratorAtRow(selected_index_)); + focused_uri_ = (*iter).uri; int focused_x = (renderer_->width + horizontal_spacing + extra_horizontal_spacing_) * (selected_index_ % items_per_row); int focused_y = (renderer_->height + vertical_spacing) * (selected_index_ / items_per_row); @@ -420,16 +411,18 @@ void ResultViewGrid::OnKeyNavFocusChange(nux::Area *area, bool has_focus, nux::K { if (HasKeyFocus()) { - if (selected_index_ < 0 and !results_.empty()) + if (selected_index_ < 0 && GetNumResults()) { - focused_uri_ = results_.front().uri; - selected_index_ = 0; + ResultIterator first_iter(result_model_); + focused_uri_ = (*first_iter).uri; + selected_index_ = 0; } int focused_x = 0; int focused_y = 0; int items_per_row = GetItemsPerRow(); + int num_results = GetNumResults(); if (direction == nux::KEY_NAV_UP && expanded) { @@ -437,7 +430,7 @@ void ResultViewGrid::OnKeyNavFocusChange(nux::Area *area, bool has_focus, nux::K // focus is comming from the bottom. We want to focus the // first item (on the left) of the last row in this grid. - int total_rows = std::ceil(results_.size() / (double)items_per_row); + int total_rows = std::ceil(num_results / (double)items_per_row); selected_index_ = items_per_row * (total_rows-1); focused_x = (renderer_->width + horizontal_spacing + extra_horizontal_spacing_) * (selected_index_ % items_per_row); @@ -481,6 +474,7 @@ typedef std::tuple <int, int> ResultListBounds; ResultListBounds ResultViewGrid::GetVisableResults() { int items_per_row = GetItemsPerRow(); + int num_results = GetNumResults(); int start, end; if (!expanded) @@ -517,12 +511,12 @@ ResultListBounds ResultViewGrid::GetVisableResults() } else { - end = results_.size() - 1; + end = num_results - 1; } } start = std::max(start, 0); - end = std::min(end, static_cast<int>(results_.size()) - 1); + end = std::min(end, num_results - 1); return ResultListBounds(start, end); } @@ -530,19 +524,18 @@ ResultListBounds ResultViewGrid::GetVisableResults() void ResultViewGrid::Draw(nux::GraphicsEngine& GfxContext, bool force_draw) { int items_per_row = GetItemsPerRow(); - uint total_rows = (!expanded) ? 0 : (results_.size() / items_per_row) + 1; - - ResultView::ResultList::iterator it; + int num_results = GetNumResults(); + int total_rows = (!expanded) ? 0 : (num_results / items_per_row) + 1; //find the row we start at int absolute_y = GetAbsoluteY(); - uint row_size = renderer_->height + vertical_spacing; + int row_size = renderer_->height + vertical_spacing; int y_position = padding + GetGeometry().y; ResultListBounds visible_bounds = GetVisableResults(); - for (uint row_index = 0; row_index <= total_rows; row_index++) + for (int row_index = 0; row_index <= total_rows; row_index++) { int row_lower_bound = row_index * items_per_row; if (row_lower_bound >= std::get<0>(visible_bounds) && @@ -551,8 +544,8 @@ void ResultViewGrid::Draw(nux::GraphicsEngine& GfxContext, bool force_draw) int x_position = padding + GetGeometry().x; for (int column_index = 0; column_index < items_per_row; column_index++) { - uint index = (row_index * items_per_row) + column_index; - if (index >= results_.size()) + int index = (row_index * items_per_row) + column_index; + if (index >= num_results) break; ResultRenderer::ResultRendererState state = ResultRenderer::RESULT_RENDERER_NORMAL; @@ -589,7 +582,8 @@ void ResultViewGrid::Draw(nux::GraphicsEngine& GfxContext, bool force_draw) } nux::Geometry render_geo(x_position, y_position, renderer_->width, renderer_->height); //nux::GetPainter().Paint2DQuadColor(GfxContext, render_geo, nux::color::Blue*0.20); - renderer_->Render(GfxContext, results_[index], state, render_geo, offset_x, offset_y); + Result result(*GetIteratorAtRow(index)); + renderer_->Render(GfxContext, result, state, render_geo, offset_x, offset_y); x_position += renderer_->width + horizontal_spacing + extra_horizontal_spacing_; } @@ -630,12 +624,14 @@ void ResultViewGrid::MouseMove(int x, int y, int dx, int dy, unsigned long butto void ResultViewGrid::MouseClick(int x, int y, unsigned long button_flags, unsigned long key_flags) { + uint num_results = static_cast<uint>(GetNumResults()); uint index = GetIndexAtPosition(x, y); mouse_over_index_ = index; - if (index >= 0 && index < results_.size()) + if (index >= 0 && index < num_results) { // we got a click on a button so activate it - Result result = results_[index]; + ResultIterator it(GetIteratorAtRow(index)); + Result result = *(it); selected_index_ = index; focused_uri_ = result.uri; UriActivated.emit(result.uri); @@ -670,15 +666,16 @@ uint ResultViewGrid::GetIndexAtPosition(int x, int y) bool ResultViewGrid::DndSourceDragBegin() { - + uint num_results = static_cast<uint>(GetNumResults()); uint drag_index = GetIndexAtPosition(last_mouse_down_x_, last_mouse_down_y_); - if (drag_index >= results_.size()) + if (drag_index >= num_results) return false; Reference(); - Result drag_result = results_[drag_index]; + ResultIterator iter(GetIteratorAtRow(drag_index)); + Result drag_result = *iter; current_drag_uri_ = drag_result.dnd_uri; if (current_drag_uri_ == "") diff --git a/dash/ResultViewGrid.h b/dash/ResultViewGrid.h index 7a33d38d1..ff8b02bc9 100644 --- a/dash/ResultViewGrid.h +++ b/dash/ResultViewGrid.h @@ -43,8 +43,6 @@ public: ResultViewGrid(NUX_FILE_LINE_DECL); void SetModelRenderer(ResultRenderer* renderer); - void AddResult(Result& result); - void RemoveResult(Result& result); nux::Property<int> horizontal_spacing; nux::Property<int> vertical_spacing; @@ -75,6 +73,9 @@ protected: virtual void DrawContent(nux::GraphicsEngine& GfxContext, bool force_draw); virtual long ComputeContentSize(); + void AddResult(Result& result); + void RemoveResult(Result& result); + private: typedef std::tuple <int, int> ResultListBounds; ResultListBounds GetVisableResults(); diff --git a/plugins/unityshell/src/unity-rvgrid-accessible.cpp b/plugins/unityshell/src/unity-rvgrid-accessible.cpp index 0cc379419..4f7058843 100644 --- a/plugins/unityshell/src/unity-rvgrid-accessible.cpp +++ b/plugins/unityshell/src/unity-rvgrid-accessible.cpp @@ -146,8 +146,6 @@ check_selection(UnityRvgridAccessible* self) { AtkObject* child = NULL; gint index = 0; - ResultView::ResultList result_list; - Result* result; nux::Object* object = NULL; ResultViewGrid* rvgrid = NULL; std::string name; @@ -162,13 +160,12 @@ check_selection(UnityRvgridAccessible* self) rvgrid = dynamic_cast<ResultViewGrid*>(object); - result_list = rvgrid->GetResultList(); index = rvgrid->GetSelectedIndex(); if (index >= 0) { - result = &result_list[index]; - name = result->name; + Result result(*rvgrid->GetIteratorAtRow(index)); + name = result.name; child = ATK_OBJECT(self->priv->result); self->priv->has_selection = TRUE; |
