-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathResultViewGrid.h
140 lines (106 loc) · 4.71 KB
/
ResultViewGrid.h
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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
// -*- 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/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;
virtual int GetSelectedIndex() const;
virtual void SetSelectedIndex(int index);
virtual unsigned GetIndexAtPosition(int x, int y);
virtual void Activate(LocalResult const& local_result, int index, ActivateType type);
virtual void RenderResultTexture(ResultViewTexture::Ptr const& result_texture);
virtual void GetResultDimensions(int& rows, int& columns);
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);
void MouseDoubleClick(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 void UpdateRenderTextures();
virtual void AddResult(Result const& result);
virtual void RemoveResult(Result const& result);
// This is overridden so we can include position of results.
virtual debug::ResultWrapper* CreateResultWrapper(Result const& result, int index);
virtual void UpdateResultWrapper(debug::ResultWrapper* wrapper, Result const& result, int index);
private:
typedef std::tuple <int, int> ResultListBounds;
ResultListBounds GetVisableResults();
void DrawRow(nux::GraphicsEngine& GfxContext, ResultListBounds const& visible_bounds, int row_index, int y_position, nux::Geometry const& absolute_position);
void QueueLazyLoad();
void QueueResultsChanged();
bool DoLazyLoad();
void UpdateScale(double scale);
int GetItemsPerRow();
void SizeReallocate();
std::tuple<int, int> GetResultPosition(LocalResult const& local_result);
std::tuple<int, int> GetResultPosition(const unsigned int& index);
unsigned mouse_over_index_;
int active_index_;
nux::Property<int> selected_index_;
LocalResult focused_result_;
LocalResult activated_result_;
unsigned last_lazy_loaded_result_;
bool all_results_preloaded_;
int last_mouse_down_x_;
int last_mouse_down_y_;
LocalResult current_drag_result_;
unsigned drag_index_;
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 results_changed_idle_;
glib::Source::UniquePtr activate_timer_;
};
} // namespace dash
} // namespace unity
#endif // UNITYSHELL_RESULTVIEWGRID_H