~ubuntu-branches/ubuntu/raring/unity/raring

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
// -*- Mode: C++; indent-tabs-mode: nil; tab-width: 2 -*-
/*
 * Copyright 2011 Canonical Ltd.
 *
 * This program is free software: you can redistribute it and/or modify it
 * under the terms of the GNU Lesser General Public License version 3, as
 * published by the  Free Software Foundation.
 *
 * This program is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranties of
 * MERCHANTABILITY, SATISFACTORY QUALITY or FITNESS FOR A PARTICULAR
 * PURPOSE.  See the applicable version of the GNU Lesser General Public
 * License for more details.
 *
 * You should have received a copy of both the GNU Lesser General Public
 * License version 3 along with this program.  If not, see
 * <http://www.gnu.org/licenses/>
 *
 * Authored by: Gordon Allott <gord.allott@canonical.com>
 *
 */

#ifndef UNITYSHELL_RESULTVIEWGRID_H
#define UNITYSHELL_RESULTVIEWGRID_H

#include <UnityCore/Categories.h>
#include <UnityCore/GLibSource.h>

#include "ResultView.h"
#include "unity-shared/UBusWrapper.h"

namespace unity
{
namespace dash
{

// will order its elements in to a grid that expands horizontally before vertically
class ResultViewGrid : public ResultView
{
public:
  NUX_DECLARE_OBJECT_TYPE(ResultViewGrid, ResultView);

  ResultViewGrid(NUX_FILE_LINE_DECL);

  void SetModelRenderer(ResultRenderer* renderer);

  nux::Property<int> horizontal_spacing;
  nux::Property<int> vertical_spacing;
  nux::Property<int> padding;

  sigc::signal<void> selection_change;

  int GetSelectedIndex();
  virtual unsigned GetIndexAtPosition(int x, int y);

protected:
  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();

  void AddResult(Result& result);
  void RemoveResult(Result& result);

  // This is overridden so we can include position of results.
  virtual debug::Introspectable* CreateResultWrapper(Result const& result, int index);

private:
  typedef std::tuple <int, int> ResultListBounds;
  ResultListBounds GetVisableResults();

  void QueueLazyLoad();
  void QueueViewChanged();
  bool DoLazyLoad();

  int GetItemsPerRow();
  void SizeReallocate();
  std::tuple<int, int> GetResultPosition(const std::string& uri);
  std::tuple<int, int> GetResultPosition(const unsigned int& index);

  unsigned mouse_over_index_;
  int active_index_;
  nux::Property<int> selected_index_;
  std::string focused_uri_;

  std::string activated_uri_;

  unsigned 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_;
};

} // namespace dash
} // namespace unity

#endif // UNITYSHELL_RESULTVIEWGRID_H