Back to index

unity  6.0.0
Public Types | Public Member Functions | Public Attributes | Protected Member Functions | Protected Attributes | Private Types | Private Member Functions | Private Attributes
unity::dash::ResultViewGrid Class Reference

#include <ResultViewGrid.h>

Inheritance diagram for unity::dash::ResultViewGrid:
Inheritance graph
[legend]
Collaboration diagram for unity::dash::ResultViewGrid:
Collaboration graph
[legend]

List of all members.

Public Types

typedef std::vector< ResultResultList
typedef std::list
< Introspectable * > 
IntrospectableList

Public Member Functions

 NUX_DECLARE_OBJECT_TYPE (ResultViewGrid, ResultView)
 ResultViewGrid (NUX_FILE_LINE_DECL)
void SetModelRenderer (ResultRenderer *renderer)
void AddResult (Result &result)
void RemoveResult (Result &result)
int GetSelectedIndex ()
virtual uint GetIndexAtPosition (int x, int y)
 NUX_DECLARE_OBJECT_TYPE (ResultView, nux::View)
ResultList GetResultList ()
std::string GetName () const
void AddProperties (GVariantBuilder *builder)
IntrospectableList GetIntrospectableChildren ()
GVariant * Introspect ()
void AddChild (Introspectable *child)
void RemoveChild (Introspectable *child)
guint64 GetIntrospectionId () const

Public Attributes

nux::Property< int > horizontal_spacing
nux::Property< int > vertical_spacing
nux::Property< int > padding
sigc::signal< void > selection_change
nux::Property< bool > expanded
nux::Property< int > results_per_row
sigc::signal< void,
std::string const & > 
UriActivated

Protected Member Functions

void MouseMove (int x, int y, int dx, int dy, unsigned long button_flags, unsigned long key_flags)
void MouseClick (int x, int y, unsigned long button_flags, unsigned long key_flags)
virtual bool DndSourceDragBegin ()
virtual nux::NBitmapData * DndSourceGetDragImage ()
virtual std::list< const char * > DndSourceGetDragTypes ()
virtual const char * DndSourceGetDataForType (const char *type, int *size, int *format)
virtual void DndSourceDragFinished (nux::DndAction result)
virtual bool InspectKeyEvent (unsigned int eventType, unsigned int keysym, const char *character)
virtual bool AcceptKeyNavFocus ()
virtual nux::Area * KeyNavIteration (nux::KeyNavDirection direction)
virtual void OnKeyNavFocusChange (nux::Area *area, bool has_focus, nux::KeyNavDirection direction)
void OnKeyDown (unsigned long event_type, unsigned long event_keysym, unsigned long event_state, const TCHAR *character, unsigned short key_repeat_count)
virtual void Draw (nux::GraphicsEngine &GfxContext, bool force_draw)
virtual void DrawContent (nux::GraphicsEngine &GfxContext, bool force_draw)
virtual long ComputeContentSize ()
virtual std::string GetChildsName () const
 Please don't override this unless you really need to. The only valid reason is if you have a property that simply must be called 'Children'.

Protected Attributes

ResultRendererrenderer_
ResultList results_
IntrospectableList introspectable_children_

Private Types

typedef std::tuple< int, int > ResultListBounds

Private Member Functions

ResultListBounds GetVisableResults ()
void QueueLazyLoad ()
void QueueViewChanged ()
bool DoLazyLoad ()
int GetItemsPerRow ()
void SizeReallocate ()

Private Attributes

uint mouse_over_index_
int active_index_
nux::Property< int > selected_index_
std::string focused_uri_
int last_lazy_loaded_result_
int last_mouse_down_x_
int last_mouse_down_y_
std::string current_drag_uri_
std::string current_drag_icon_name_
int recorded_dash_width_
int recorded_dash_height_
int mouse_last_x_
int mouse_last_y_
int extra_horizontal_spacing_
UBusManager ubus_
glib::Source::UniquePtr lazy_load_source_
glib::Source::UniquePtr view_changed_idle_

Detailed Description

Definition at line 38 of file ResultViewGrid.h.


Member Typedef Documentation

Definition at line 34 of file Introspectable.h.

typedef std::vector<Result> unity::dash::ResultView::ResultList [inherited]

Definition at line 45 of file ResultView.h.

typedef std::tuple<int, int> unity::dash::ResultViewGrid::ResultListBounds [private]

Definition at line 79 of file ResultViewGrid.h.


Constructor & Destructor Documentation

Definition at line 47 of file ResultViewGrid.cpp.

  : ResultView(NUX_FILE_LINE_PARAM)
  , horizontal_spacing(0)
  , vertical_spacing(0)
  , padding(0)
  , mouse_over_index_(-1)
  , active_index_(-1)
  , selected_index_(-1)
  , last_lazy_loaded_result_(0)
  , last_mouse_down_x_(-1)
  , last_mouse_down_y_(-1)
  , recorded_dash_width_(-1)
  , recorded_dash_height_(-1)
  , mouse_last_x_(-1)
  , mouse_last_y_(-1)
  , extra_horizontal_spacing_(0)
{
  SetAcceptKeyNavFocusOnMouseDown(false);

  auto needredraw_lambda = [&](int value) { NeedRedraw(); };
  horizontal_spacing.changed.connect(needredraw_lambda);
  vertical_spacing.changed.connect(needredraw_lambda);
  padding.changed.connect(needredraw_lambda);
  selected_index_.changed.connect(needredraw_lambda);

  key_nav_focus_change.connect(sigc::mem_fun(this, &ResultViewGrid::OnKeyNavFocusChange));
  key_nav_focus_activate.connect([&] (nux::Area *area) { UriActivated.emit (focused_uri_); });
  key_down.connect(sigc::mem_fun(this, &ResultViewGrid::OnKeyDown));
  mouse_move.connect(sigc::mem_fun(this, &ResultViewGrid::MouseMove));
  mouse_click.connect(sigc::mem_fun(this, &ResultViewGrid::MouseClick));

  mouse_down.connect([&](int x, int y, unsigned long mouse_state, unsigned long button_state)
  {
    last_mouse_down_x_ = x;
    last_mouse_down_y_ = y;
    uint index = GetIndexAtPosition(x, y);
    mouse_over_index_ = index;
  });

  mouse_leave.connect([&](int x, int y, unsigned long mouse_state, unsigned long button_state)
  {
    mouse_over_index_ = -1;
    mouse_last_x_ = -1;
    mouse_last_y_ = -1;
    NeedRedraw();
  });

  ubus_.RegisterInterest(UBUS_DASH_SIZE_CHANGED, [this] (GVariant* data) {
    // on dash size changed, we update our stored values, this sucks
    //FIXME in P - make dash size the size of our dash not the entire screen
    g_variant_get (data, "(ii)", &recorded_dash_width_, &recorded_dash_height_);
  });

  SetDndEnabled(true, false);
}

Here is the call graph for this function:


Member Function Documentation

bool unity::dash::ResultViewGrid::AcceptKeyNavFocus ( ) [protected, virtual]

Definition at line 305 of file ResultViewGrid.cpp.

{
  return true;
}

Definition at line 78 of file Introspectable.cpp.

{
  _children.push_back(child);
  child->_parents.push_back(this);
}

Here is the caller graph for this function:

void unity::dash::ResultView::AddProperties ( GVariantBuilder *  builder) [virtual, inherited]

Implements unity::debug::Introspectable.

Definition at line 139 of file ResultView.cpp.

{
  unity::variant::BuilderWrapper(builder)
    .add("expanded", expanded);
}

Here is the call graph for this function:

Reimplemented from unity::dash::ResultView.

Definition at line 200 of file ResultViewGrid.cpp.

{
  results_.push_back(result);
  QueueViewChanged();
}

Here is the call graph for this function:

Here is the caller graph for this function:

long unity::dash::ResultViewGrid::ComputeContentSize ( ) [protected, virtual]

Reimplemented from unity::dash::ResultView.

Definition at line 471 of file ResultViewGrid.cpp.

Here is the call graph for this function:

bool unity::dash::ResultViewGrid::DndSourceDragBegin ( ) [protected, virtual]

Definition at line 671 of file ResultViewGrid.cpp.

{

  uint drag_index = GetIndexAtPosition(last_mouse_down_x_, last_mouse_down_y_);

  if (drag_index >= results_.size())
    return false;

  Reference();

  Result drag_result = results_[drag_index];

  current_drag_uri_ = drag_result.dnd_uri;
  if (current_drag_uri_ == "")
    current_drag_uri_ = drag_result.uri().substr(drag_result.uri().find(":") + 1);

  current_drag_icon_name_ = drag_result.icon_hint;

  LOG_DEBUG (logger) << "Dnd begin at " <<
                     last_mouse_down_x_ << ", " << last_mouse_down_y_ << " - using; "
                     << current_drag_uri_ << " - "
                     << current_drag_icon_name_;

  return true;
}

Here is the call graph for this function:

void unity::dash::ResultViewGrid::DndSourceDragFinished ( nux::DndAction  result) [protected, virtual]

Definition at line 810 of file ResultViewGrid.cpp.

{
  UnReference();
  last_mouse_down_x_ = -1;
  last_mouse_down_y_ = -1;
  current_drag_uri_.clear();
  current_drag_icon_name_.clear();

  // We need this because the drag can start in a ResultViewGrid and can
  // end in another ResultViewGrid
  EmitMouseLeaveSignal(0, 0, 0, 0);

  // We need an extra mouse motion to highlight the icon under the mouse
  // as soon as dnd finish
  Display* display = nux::GetGraphicsDisplay()->GetX11Display();
  if (display)
  {
    XWarpPointer(display, None, None, 0, 0, 0, 0, 0, 0);
    XSync(display, 0);
  }
}
const char * unity::dash::ResultViewGrid::DndSourceGetDataForType ( const char *  type,
int *  size,
int *  format 
) [protected, virtual]

Definition at line 793 of file ResultViewGrid.cpp.

{
  *format = 8;

  if (!current_drag_uri_.empty())
  {
    *size = strlen(current_drag_uri_.c_str());
    return current_drag_uri_.c_str();
  }
  else
  {
    *size = 0;
    return 0;
  }
}
nux::NBitmapData * unity::dash::ResultViewGrid::DndSourceGetDragImage ( ) [protected, virtual]

Definition at line 768 of file ResultViewGrid.cpp.

{
  nux::NBitmapData* result = 0;
  GdkPixbuf* pbuf;
  pbuf = _icon_hint_get_drag_pixbuf (current_drag_icon_name_);

  if (pbuf && GDK_IS_PIXBUF(pbuf))
  {
    // we don't free the pbuf as GdkGraphics will do it for us will do it for us
    nux::GdkGraphics graphics(pbuf);
    result = graphics.GetBitmap();
  }

  return result;
}

Here is the call graph for this function:

std::list< const char * > unity::dash::ResultViewGrid::DndSourceGetDragTypes ( ) [protected, virtual]

Definition at line 785 of file ResultViewGrid.cpp.

{
  std::list<const char*> result;
  result.push_back("text/uri-list");
  return result;
}

Definition at line 127 of file ResultViewGrid.cpp.

{
  // FIXME - so this code was nice, it would only load the visible entries on the screen
  // however nux does not give us a good enough indicator right now that we are scrolling,
  // thus if you scroll more than a screen in one frame, you will end up with at least one frame where
  // no icons are displayed (they have not been preloaded yet) - it sucked. we should fix this next cycle when we can break api
  //~ int index = 0;
//~
  //~ ResultListBounds visible_bounds = GetVisableResults();
  //~ int lower_bound = std::get<0>(visible_bounds);
  //~ int upper_bound = std::get<1>(visible_bounds);
//~
  //~ ResultList::iterator it;
  //~ for (it = results_.begin(); it != results_.end(); it++)
  //~ {
    //~ if (index >= lower_bound && index <= upper_bound)
    //~ {
      //~ renderer_->Preload((*it));
    //~ }
    //~ index++;
  //~ }

  util::Timer timer;
  bool queue_additional_load = false; // if this is set, we will return early and start loading more next frame

  // 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++)
  {
    if ((!expanded && index < items_per_row) || expanded)
    {
      renderer_->Preload((*it));
      last_lazy_loaded_result_ = index;
    }

    if (timer.ElapsedSeconds() > 0.008)
    {
      queue_additional_load = true;
      break;
    }

    if (!expanded && index >= items_per_row)
      break; //early exit

    index++;
  }

  if (queue_additional_load)
  {
    //we didn't load all the results because we exceeded our time budget, so queue another lazy load
    lazy_load_source_.reset(new glib::Timeout(1000/60 - 8));
    lazy_load_source_->Run(sigc::mem_fun(this, &ResultViewGrid::DoLazyLoad));
  }

  QueueDraw();

  return false;
}

Here is the call graph for this function:

Here is the caller graph for this function:

void unity::dash::ResultViewGrid::Draw ( nux::GraphicsEngine &  GfxContext,
bool  force_draw 
) [protected, virtual]

Reimplemented from unity::dash::ResultView.

Definition at line 530 of file ResultViewGrid.cpp.

{
  int items_per_row = GetItemsPerRow();
  uint total_rows = (!expanded) ? 0 : (results_.size() / items_per_row) + 1;

  ResultView::ResultList::iterator it;

  //find the row we start at
  int absolute_y = GetAbsoluteY();
  uint 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++)
  {
    int row_lower_bound = row_index * items_per_row;
    if (row_lower_bound >= std::get<0>(visible_bounds) &&
        row_lower_bound <= std::get<1>(visible_bounds))
    {
      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())
          break;

        ResultRenderer::ResultRendererState state = ResultRenderer::RESULT_RENDERER_NORMAL;
        if ((int)(index) == selected_index_)
        {
          state = ResultRenderer::RESULT_RENDERER_SELECTED;
        }
        else if ((int)(index) == active_index_)
        {
          state = ResultRenderer::RESULT_RENDERER_ACTIVE;
        }

        int half_width = recorded_dash_width_ / 2;
        int half_height = recorded_dash_height_;

        int offset_x, offset_y;

        /* Guard against divide-by-zero. SIGFPEs are not mythological
         * contrary to popular belief */
        if (half_width >= 10)
          offset_x = MAX(MIN((x_position - half_width) / (half_width / 10), 5), -5);
        else
          offset_x = 0;

        if (half_height >= 10)
          offset_y = MAX(MIN(((y_position + absolute_y) - half_height) / (half_height / 10), 5), -5);
        else
          offset_y = 0;

        if (recorded_dash_width_ < 1 || recorded_dash_height_ < 1)
        {
          offset_x = 0;
          offset_y = 0;
        }
        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);

        x_position += renderer_->width + horizontal_spacing + extra_horizontal_spacing_;
      }
    }

    y_position += row_size;
  }
}

Here is the call graph for this function:

void unity::dash::ResultViewGrid::DrawContent ( nux::GraphicsEngine &  GfxContext,
bool  force_draw 
) [protected, virtual]

Reimplemented from unity::dash::ResultView.

Definition at line 602 of file ResultViewGrid.cpp.

{
  nux::Geometry base = GetGeometry();
  GfxContent.PushClippingRectangle(base);

  if (GetCompositionLayout())
  {
    nux::Geometry geo = GetCompositionLayout()->GetGeometry();
    GetCompositionLayout()->ProcessDraw(GfxContent, force_draw);
  }

  GfxContent.PopClippingRectangle();
}
std::string unity::debug::Introspectable::GetChildsName ( ) const [protected, virtual, inherited]

Please don't override this unless you really need to. The only valid reason is if you have a property that simply must be called 'Children'.

Definition at line 92 of file Introspectable.cpp.

{
  return "Children";
}

Here is the caller graph for this function:

uint unity::dash::ResultViewGrid::GetIndexAtPosition ( int  x,
int  y 
) [virtual]

Definition at line 645 of file ResultViewGrid.cpp.

{
  uint items_per_row = GetItemsPerRow();

  uint column_size = renderer_->width + horizontal_spacing + extra_horizontal_spacing_;
  uint row_size = renderer_->height + vertical_spacing;

  int x_bound = items_per_row * column_size + padding;

  if ((x < padding) || (x >= x_bound))
    return -1;

  if (y < padding)
    return -1;

  uint row_number = std::max((y - padding), 0) / row_size ;
  uint column_number = std::max((x - padding), 0) / column_size;

  return (row_number * items_per_row) + column_number;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Reimplemented from unity::debug::Introspectable.

Definition at line 145 of file ResultView.cpp.

{
  ClearIntrospectableWrappers();

  for (auto result: results_)
  {
    introspectable_children_.push_back(new debug::ResultWrapper(result));
  }
  return introspectable_children_;
}

Here is the call graph for this function:

guint64 unity::debug::Introspectable::GetIntrospectionId ( ) const [inherited]

Definition at line 97 of file Introspectable.cpp.

{
  return _id;
}

Here is the caller graph for this function:

Definition at line 188 of file ResultViewGrid.cpp.

{
  int items_per_row = (GetGeometry().width - (padding * 2) + horizontal_spacing) / (renderer_->width + horizontal_spacing);
  return (items_per_row) ? items_per_row : 1; // always at least one item per row
}

Here is the caller graph for this function:

std::string unity::dash::ResultView::GetName ( ) const [virtual, inherited]

Implements unity::debug::Introspectable.

Definition at line 134 of file ResultView.cpp.

{
  return "ResultView";
}

Definition at line 111 of file ResultView.cpp.

{
  return results_;
}

Here is the caller graph for this function:

Definition at line 833 of file ResultViewGrid.cpp.

{
  return selected_index_;
}

Here is the caller graph for this function:

Definition at line 481 of file ResultViewGrid.cpp.

{
  int items_per_row = GetItemsPerRow();
  int start, end;

  if (!expanded)
  {
    // we are not expanded, so the bounds are known
    start = 0;
    end = items_per_row - 1;
  }
  else
  {
    //find the row we start at
    int absolute_y = GetAbsoluteY() - GetToplevel()->GetAbsoluteY();
    uint row_size = renderer_->height + vertical_spacing;

    if (absolute_y < 0)
    {
      // we are scrolled up a little,
      int row_index = abs(absolute_y) / row_size;
      start = row_index * items_per_row;
    }
    else
    {
      start = 0;
    }

    if (absolute_y + GetAbsoluteHeight() > GetToplevel()->GetAbsoluteHeight())
    {
      // our elements overflow the visable viewport
      int visible_height = (GetToplevel()->GetAbsoluteHeight() - std::max(absolute_y, 0));
      visible_height = std::min(visible_height, absolute_y + GetAbsoluteHeight());

      int visible_rows = std::ceil(visible_height / static_cast<float>(row_size));
      end = start + (visible_rows * items_per_row) + items_per_row;
    }
    else
    {
      end = results_.size() - 1;
    }
  }

  start = std::max(start, 0);
  end = std::min(end, static_cast<int>(results_.size()) - 1);

  return ResultListBounds(start, end);
}

Here is the call graph for this function:

Here is the caller graph for this function:

bool unity::dash::ResultViewGrid::InspectKeyEvent ( unsigned int  eventType,
unsigned int  keysym,
const char *  character 
) [protected, virtual]

Definition at line 245 of file ResultViewGrid.cpp.

{
  nux::KeyNavDirection direction = nux::KEY_NAV_NONE;
  switch (keysym)
  {
    case NUX_VK_UP:
      direction = nux::KeyNavDirection::KEY_NAV_UP;
      break;
    case NUX_VK_DOWN:
      direction = nux::KeyNavDirection::KEY_NAV_DOWN;
      break;
    case NUX_VK_LEFT:
      direction = nux::KeyNavDirection::KEY_NAV_LEFT;
      break;
    case NUX_VK_RIGHT:
      direction = nux::KeyNavDirection::KEY_NAV_RIGHT;
      break;
    case NUX_VK_LEFT_TAB:
      direction = nux::KeyNavDirection::KEY_NAV_TAB_PREVIOUS;
      break;
    case NUX_VK_TAB:
      direction = nux::KeyNavDirection::KEY_NAV_TAB_NEXT;
      break;
    case NUX_VK_ENTER:
    case NUX_KP_ENTER:
      direction = nux::KeyNavDirection::KEY_NAV_ENTER;
      break;
    default:
      direction = nux::KeyNavDirection::KEY_NAV_NONE;
      break;
  }

  if (direction == nux::KeyNavDirection::KEY_NAV_NONE
      || direction == nux::KeyNavDirection::KEY_NAV_TAB_NEXT
      || direction == nux::KeyNavDirection::KEY_NAV_TAB_PREVIOUS
      || direction == nux::KeyNavDirection::KEY_NAV_ENTER)
  {
    // we don't handle these cases
    return false;
  }

  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
  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)))
    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.
  else if (direction == nux::KEY_NAV_UP && selected_index_ < items_per_row)
    return false; // key nav up when already on top row
  else if (direction == nux::KEY_NAV_DOWN && selected_index_ >= (total_rows-1) * items_per_row)
    return false; // key nav down when on bottom row

  return true;
}

Here is the call graph for this function:

GVariant * unity::debug::Introspectable::Introspect ( ) [inherited]

Definition at line 47 of file Introspectable.cpp.

{
  GVariantBuilder  builder;
  GVariantBuilder  child_builder;
  gint             n_children = 0;

  g_variant_builder_init(&builder, G_VARIANT_TYPE("a{sv}"));
  g_variant_builder_add(&builder, "{sv}", "id", g_variant_new_uint64(_id));

  AddProperties(&builder);

  g_variant_builder_init(&child_builder, G_VARIANT_TYPE("as"));

  auto children = GetIntrospectableChildren();
  for (auto it = children.begin(); it != children.end(); it++)
  {
    if ((*it)->GetName() != "")
    {
      g_variant_builder_add(&child_builder, "s", (*it)->GetName().c_str());
      n_children++;
    }
  }

  GVariant* child_results = g_variant_builder_end(&child_builder);

  if (n_children > 0)
    g_variant_builder_add(&builder, "{sv}", GetChildsName().c_str(), child_results);
  return g_variant_builder_end(&builder);
}

Here is the call graph for this function:

nux::Area * unity::dash::ResultViewGrid::KeyNavIteration ( nux::KeyNavDirection  direction) [protected, virtual]

Definition at line 414 of file ResultViewGrid.cpp.

{
  return this;
}
void unity::dash::ResultViewGrid::MouseClick ( int  x,
int  y,
unsigned long  button_flags,
unsigned long  key_flags 
) [protected]

Definition at line 631 of file ResultViewGrid.cpp.

{
  uint index = GetIndexAtPosition(x, y);
  mouse_over_index_ = index;
  if (index >= 0 && index < results_.size())
  {
    // we got a click on a button so activate it
    Result result = results_[index];
    selected_index_ = index;
    focused_uri_ = result.uri;
    UriActivated.emit(result.uri);
  }
}

Here is the call graph for this function:

Here is the caller graph for this function:

void unity::dash::ResultViewGrid::MouseMove ( int  x,
int  y,
int  dx,
int  dy,
unsigned long  button_flags,
unsigned long  key_flags 
) [protected]

Definition at line 617 of file ResultViewGrid.cpp.

{
  uint index = GetIndexAtPosition(x, y);

  if (mouse_over_index_ != index)
  {
    selected_index_ = mouse_over_index_ = index;

    nux::GetWindowCompositor().SetKeyFocusArea(this);
  }
  mouse_last_x_ = x;
  mouse_last_y_ = y;
}

Here is the call graph for this function:

Here is the caller graph for this function:

void unity::dash::ResultViewGrid::OnKeyDown ( unsigned long  event_type,
unsigned long  event_keysym,
unsigned long  event_state,
const TCHAR *  character,
unsigned short  key_repeat_count 
) [protected]

Definition at line 310 of file ResultViewGrid.cpp.

{
  nux::KeyNavDirection direction = nux::KEY_NAV_NONE;
  switch (event_keysym)
  {
    case NUX_VK_UP:
      direction = nux::KeyNavDirection::KEY_NAV_UP;
      break;
    case NUX_VK_DOWN:
      direction = nux::KeyNavDirection::KEY_NAV_DOWN;
      break;
    case NUX_VK_LEFT:
      direction = nux::KeyNavDirection::KEY_NAV_LEFT;
      break;
    case NUX_VK_RIGHT:
      direction = nux::KeyNavDirection::KEY_NAV_RIGHT;
      break;
    case NUX_VK_LEFT_TAB:
      direction = nux::KeyNavDirection::KEY_NAV_TAB_PREVIOUS;
      break;
    case NUX_VK_TAB:
      direction = nux::KeyNavDirection::KEY_NAV_TAB_NEXT;
      break;
    case NUX_VK_ENTER:
    case NUX_KP_ENTER:
      direction = nux::KeyNavDirection::KEY_NAV_ENTER;
      break;
    default:
      direction = nux::KeyNavDirection::KEY_NAV_NONE;
      break;
  }

  // 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;

  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
  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)))
    return; // pressed right on the last item, nope. nothing for you

  if (direction == nux::KEY_NAV_RIGHT && !expanded && selected_index_ == items_per_row - 1)
    return; // pressed right on the last item in the first row in non expanded mode. nothing doing.

  switch (direction)
  {
    case (nux::KEY_NAV_LEFT):
    {
      selected_index_ = selected_index_ - 1;
      break;
    }
    case (nux::KEY_NAV_RIGHT):
    {
     selected_index_ = selected_index_ + 1;
      break;
    }
    case (nux::KEY_NAV_UP):
    {
      selected_index_ = selected_index_ - items_per_row;
      break;
    }
    case (nux::KEY_NAV_DOWN):
    {
      selected_index_ = selected_index_ + items_per_row;
      break;
    }
    default:
      break;
  }

  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;

  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);

  ubus_.SendMessage(UBUS_RESULT_VIEW_KEYNAV_CHANGED,
                    g_variant_new("(iiii)", focused_x, focused_y, renderer_->width(), renderer_->height()));
  selection_change.emit();
}

Here is the call graph for this function:

Here is the caller graph for this function:

void unity::dash::ResultViewGrid::OnKeyNavFocusChange ( nux::Area *  area,
bool  has_focus,
nux::KeyNavDirection  direction 
) [protected, virtual]

Definition at line 419 of file ResultViewGrid.cpp.

{
  if (HasKeyFocus())
  {
    if (selected_index_ < 0 and !results_.empty())
    {
        focused_uri_ = results_.front().uri;
        selected_index_ = 0;
    }

    int focused_x = 0;
    int focused_y = 0;

    int items_per_row = GetItemsPerRow();

    if (direction == nux::KEY_NAV_UP && expanded)
    {
      // This View just got focused through keyboard navigation and the
      // 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);
      selected_index_ = items_per_row * (total_rows-1);

      focused_x = (renderer_->width + horizontal_spacing + extra_horizontal_spacing_) * (selected_index_ % items_per_row);
      focused_y = (renderer_->height + vertical_spacing) * (selected_index_ / items_per_row);

    }
    else
    {
      focused_x = (renderer_->width + horizontal_spacing + extra_horizontal_spacing_) * (selected_index_ % items_per_row);
      focused_y = (renderer_->height + vertical_spacing) * (selected_index_ / items_per_row);
    }

    if (direction != nux::KEY_NAV_NONE)
    {
      ubus_.SendMessage(UBUS_RESULT_VIEW_KEYNAV_CHANGED,
                        g_variant_new("(iiii)", focused_x, focused_y, renderer_->width(), renderer_->height()));
    }

    selection_change.emit();

  }
  else
  {
    selected_index_ = -1;
    focused_uri_.clear();

    selection_change.emit();
  }
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 103 of file ResultViewGrid.cpp.

{
  lazy_load_source_.reset(new glib::Idle(glib::Source::Priority::DEFAULT));
  lazy_load_source_->Run(sigc::mem_fun(this, &ResultViewGrid::DoLazyLoad));
  last_lazy_loaded_result_ = 0; // we always want to reset the lazy load index here
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 110 of file ResultViewGrid.cpp.

{
  if (!view_changed_idle_)
  {
    // using glib::Source::Priority::HIGH because this needs to happen *before* next draw
    view_changed_idle_.reset(new glib::Idle(glib::Source::Priority::HIGH));
    view_changed_idle_->Run([&] () {
      SizeReallocate();
      last_lazy_loaded_result_ = 0; // reset the lazy load index
      DoLazyLoad(); // also calls QueueDraw

      view_changed_idle_.reset();
      return false;
    });
  }
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 85 of file Introspectable.cpp.

{
  _children.remove(child);
  child->_parents.remove(this);
}

Here is the caller graph for this function:

Reimplemented from unity::dash::ResultView.

Definition at line 206 of file ResultViewGrid.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

Reimplemented from unity::dash::ResultView.

Definition at line 194 of file ResultViewGrid.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 212 of file ResultViewGrid.cpp.

{
  //FIXME - needs to use the geometry assigned to it, but only after a layout
  int items_per_row = GetItemsPerRow();

  int total_rows = std::ceil(results_.size() / (double)items_per_row) ;
  int total_height = 0;

  if (expanded)
  {
    total_height = (total_rows * renderer_->height) + (total_rows * vertical_spacing);
  }
  else
  {
    total_height = renderer_->height + vertical_spacing;
  }

  int width = (items_per_row * renderer_->width) + (padding*2) + ((items_per_row - 1) * horizontal_spacing);
  int geo_width = GetBaseWidth();
  int extra_width = geo_width - (width + 25-3);

  if (items_per_row != 1)
    extra_horizontal_spacing_ = extra_width / (items_per_row - 1);
  if (extra_horizontal_spacing_ < 0)
    extra_horizontal_spacing_ = 0;

  SetMinimumHeight(total_height + (padding * 2));
  SetMaximumHeight(total_height + (padding * 2));

  mouse_over_index_ = GetIndexAtPosition(mouse_last_x_, mouse_last_y_);
  results_per_row = items_per_row;
}

Here is the call graph for this function:

Here is the caller graph for this function:


Member Data Documentation

Definition at line 90 of file ResultViewGrid.h.

Definition at line 98 of file ResultViewGrid.h.

Definition at line 97 of file ResultViewGrid.h.

nux::Property<bool> unity::dash::ResultView::expanded [inherited]

Definition at line 57 of file ResultView.h.

Definition at line 106 of file ResultViewGrid.h.

Definition at line 92 of file ResultViewGrid.h.

Definition at line 49 of file ResultViewGrid.h.

Definition at line 74 of file ResultView.h.

Definition at line 94 of file ResultViewGrid.h.

Definition at line 95 of file ResultViewGrid.h.

Definition at line 96 of file ResultViewGrid.h.

Definition at line 109 of file ResultViewGrid.h.

Definition at line 103 of file ResultViewGrid.h.

Definition at line 104 of file ResultViewGrid.h.

Definition at line 89 of file ResultViewGrid.h.

Definition at line 51 of file ResultViewGrid.h.

Definition at line 101 of file ResultViewGrid.h.

Definition at line 100 of file ResultViewGrid.h.

Definition at line 72 of file ResultView.h.

Definition at line 73 of file ResultView.h.

nux::Property<int> unity::dash::ResultView::results_per_row [inherited]

Definition at line 58 of file ResultView.h.

nux::Property<int> unity::dash::ResultViewGrid::selected_index_ [private]

Definition at line 91 of file ResultViewGrid.h.

Definition at line 53 of file ResultViewGrid.h.

Definition at line 108 of file ResultViewGrid.h.

sigc::signal<void, std::string const&> unity::dash::ResultView::UriActivated [inherited]

Definition at line 60 of file ResultView.h.

Definition at line 50 of file ResultViewGrid.h.

Definition at line 110 of file ResultViewGrid.h.


The documentation for this class was generated from the following files: