~paullo612/unity/unityshell-rotated

« back to all changes in this revision

Viewing changes to plugins/unityshell-rotated/src/LauncherIcon.h

  • Committer: Pavel Golikov
  • Date: 2011-11-23 12:54:52 UTC
  • Revision ID: paullo612@gmail.com-20111123125452-y9d0k2shq5qfr8oh
Changed unityshell-rotated directory name to unityshell to better merging

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
// -*- Mode: C++; indent-tabs-mode: nil; tab-width: 2 -*-
2
 
/*
3
 
 * Copyright (C) 2010 Canonical Ltd
4
 
 *
5
 
 * This program is free software: you can redistribute it and/or modify
6
 
 * it under the terms of the GNU General Public License version 3 as
7
 
 * published by the Free Software Foundation.
8
 
 *
9
 
 * This program is distributed in the hope that it will be useful,
10
 
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11
 
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
 
 * GNU General Public License for more details.
13
 
 *
14
 
 * You should have received a copy of the GNU General Public License
15
 
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
16
 
 *
17
 
 * Authored by: Jason Smith <jason.smith@canonical.com>
18
 
 *
19
 
 */
20
 
 
21
 
#ifndef LAUNCHERICON_H
22
 
#define LAUNCHERICON_H
23
 
 
24
 
#include <set>
25
 
#include <string>
26
 
 
27
 
#include <Nux/Nux.h>
28
 
#include <Nux/BaseWindow.h>
29
 
#include <NuxCore/Math/MathInc.h>
30
 
 
31
 
#include <sigc++/trackable.h>
32
 
#include <sigc++/signal.h>
33
 
#include <sigc++/functors/ptr_fun.h>
34
 
#include <sigc++/functors/mem_fun.h>
35
 
 
36
 
#include <gtk/gtk.h>
37
 
#include <libdbusmenu-glib/client.h>
38
 
#include <libdbusmenu-glib/menuitem.h>
39
 
 
40
 
#include <boost/unordered_map.hpp>
41
 
 
42
 
#include "AbstractLauncherIcon.h"
43
 
#include "Tooltip.h"
44
 
#include "QuicklistView.h"
45
 
#include "Introspectable.h"
46
 
#include "Launcher.h"
47
 
#include "LauncherEntryRemote.h"
48
 
 
49
 
class Launcher;
50
 
 
51
 
class LauncherIcon : public AbstractLauncherIcon, public unity::Introspectable
52
 
{
53
 
  NUX_DECLARE_OBJECT_TYPE(LauncherIcon, AbstractLauncherIcon);
54
 
 
55
 
public:
56
 
  typedef nux::ObjectPtr<nux::BaseTexture> BaseTexturePtr;
57
 
 
58
 
  LauncherIcon(Launcher* launcher);
59
 
 
60
 
  virtual ~LauncherIcon();
61
 
 
62
 
  Launcher* GetLauncher()
63
 
  {
64
 
    return _launcher;
65
 
  };
66
 
 
67
 
  bool SetTooltipText(std::string& target, std::string const& value);
68
 
 
69
 
  void    SetShortcut(guint64 shortcut);
70
 
 
71
 
  guint64 GetShortcut();
72
 
 
73
 
  void SetSortPriority(int priority);
74
 
 
75
 
  void RecvMouseEnter();
76
 
 
77
 
  void RecvMouseLeave();
78
 
 
79
 
  void RecvMouseDown(int button);
80
 
 
81
 
  void RecvMouseUp(int button);
82
 
 
83
 
  void RecvMouseClick(int button);
84
 
 
85
 
  void HideTooltip();
86
 
 
87
 
  bool OpenQuicklist(bool default_to_first_item = false);
88
 
 
89
 
  void        SetCenter(nux::Point3 center);
90
 
 
91
 
  nux::Point3 GetCenter();
92
 
 
93
 
  virtual void Activate(ActionArg arg);
94
 
 
95
 
  void OpenInstance(ActionArg arg);
96
 
 
97
 
  void SaveCenter();
98
 
 
99
 
  int SortPriority();
100
 
 
101
 
  int RelatedWindows();
102
 
 
103
 
  virtual std::vector<Window> RelatedXids () { return std::vector<Window> (); }
104
 
 
105
 
  virtual std::string NameForWindow (Window window) { return std::string(); }
106
 
 
107
 
  bool HasWindowOnViewport();
108
 
 
109
 
  virtual bool IsSpacer()
110
 
  {
111
 
    return false;
112
 
  };
113
 
 
114
 
  float PresentUrgency();
115
 
 
116
 
  float GetProgress();
117
 
 
118
 
  void SetEmblemIconName(const char* name);
119
 
 
120
 
  void SetEmblemText(const char* text);
121
 
 
122
 
  void DeleteEmblem();
123
 
 
124
 
  virtual bool ShowInSwitcher()
125
 
  {
126
 
    return false;
127
 
  };
128
 
 
129
 
  virtual unsigned long long SwitcherPriority()
130
 
  {
131
 
    return 0;
132
 
  }
133
 
 
134
 
  bool GetQuirk(Quirk quirk);
135
 
 
136
 
  void SetQuirk(Quirk quirk, bool value);
137
 
 
138
 
  struct timespec GetQuirkTime(Quirk quirk);
139
 
 
140
 
  IconType Type();
141
 
 
142
 
  virtual nux::Color BackgroundColor();
143
 
 
144
 
  virtual nux::Color GlowColor();
145
 
 
146
 
  const gchar* RemoteUri()
147
 
  {
148
 
    return GetRemoteUri();
149
 
  }
150
 
 
151
 
  nux::BaseTexture* TextureForSize(int size);
152
 
 
153
 
  nux::BaseTexture* Emblem();
154
 
 
155
 
  std::list<DbusmenuMenuitem*> Menus();
156
 
 
157
 
  void InsertEntryRemote(LauncherEntryRemote* remote);
158
 
 
159
 
  void RemoveEntryRemote(LauncherEntryRemote* remote);
160
 
 
161
 
  nux::DndAction QueryAcceptDrop(unity::DndData& dnd_data)
162
 
  {
163
 
    return OnQueryAcceptDrop(dnd_data);
164
 
  }
165
 
 
166
 
  void AcceptDrop(unity::DndData& dnd_data)
167
 
  {
168
 
    return OnAcceptDrop(dnd_data);
169
 
  }
170
 
 
171
 
  void SendDndEnter()
172
 
  {
173
 
    OnDndEnter();
174
 
  }
175
 
 
176
 
  void SendDndLeave()
177
 
  {
178
 
    OnDndLeave();
179
 
  }
180
 
 
181
 
  void SetIconType(IconType type);
182
 
 
183
 
  std::vector<nux::Vector4> & GetTransform(TransformIndex index);
184
 
 
185
 
  static void SetSkipTooltipDelay(gboolean skip_tooltip_delay);
186
 
 
187
 
  sigc::signal<void, LauncherIcon*> remove;
188
 
 
189
 
  sigc::connection needs_redraw_connection;
190
 
  sigc::connection on_icon_added_connection;
191
 
  sigc::connection on_icon_removed_connection;
192
 
  sigc::connection on_order_changed_connection;
193
 
 
194
 
protected:
195
 
  const gchar* GetName();
196
 
 
197
 
  void AddProperties(GVariantBuilder* builder);
198
 
 
199
 
  void UpdateQuirkTimeDelayed(guint ms, Quirk quirk);
200
 
 
201
 
  void UpdateQuirkTime(Quirk quirk);
202
 
 
203
 
  void ResetQuirkTime(Quirk quirk);
204
 
 
205
 
  void SetRelatedWindows(int windows);
206
 
 
207
 
  void Remove();
208
 
 
209
 
  void SetProgress(float progress);
210
 
 
211
 
  void SetHasWindowOnViewport(bool val);
212
 
 
213
 
  void Present(float urgency, int length);
214
 
 
215
 
  void Unpresent();
216
 
 
217
 
  void SetEmblem(BaseTexturePtr const& emblem);
218
 
 
219
 
  virtual std::list<DbusmenuMenuitem*> GetMenus();
220
 
 
221
 
  virtual nux::BaseTexture* GetTextureForSize(int size) = 0;
222
 
 
223
 
  virtual void OnCenterStabilized(nux::Point3 center) {}
224
 
 
225
 
  virtual const gchar* GetRemoteUri()
226
 
  {
227
 
    return 0;
228
 
  }
229
 
 
230
 
  virtual nux::DndAction OnQueryAcceptDrop(unity::DndData& dnd_data)
231
 
  {
232
 
    return nux::DNDACTION_NONE;
233
 
  }
234
 
 
235
 
  virtual void OnAcceptDrop(unity::DndData& dnd_data) {}
236
 
 
237
 
  virtual void OnDndEnter() {}
238
 
 
239
 
  virtual void OnDndLeave() {}
240
 
 
241
 
  virtual void ActivateLauncherIcon(ActionArg arg) {}
242
 
 
243
 
  virtual void OpenInstanceLauncherIcon(ActionArg arg) {}
244
 
 
245
 
  virtual bool HandlesSpread () { return false; }
246
 
 
247
 
  nux::BaseTexture* TextureFromGtkTheme(const char* name, int size, bool update_glow_colors = true);
248
 
 
249
 
  nux::BaseTexture* TextureFromSpecificGtkTheme(GtkIconTheme* theme, const char* name, int size, bool update_glow_colors = true, bool is_default_theme = false);
250
 
 
251
 
  nux::BaseTexture* TextureFromPath(const char* name, int size, bool update_glow_colors = true);
252
 
 
253
 
  static bool        IsMonoDefaultTheme();
254
 
 
255
 
  GtkIconTheme*      GetUnityTheme();
256
 
 
257
 
  void OnRemoteEmblemChanged(LauncherEntryRemote* remote);
258
 
 
259
 
  void OnRemoteCountChanged(LauncherEntryRemote* remote);
260
 
 
261
 
  void OnRemoteProgressChanged(LauncherEntryRemote* remote);
262
 
 
263
 
  void OnRemoteQuicklistChanged(LauncherEntryRemote* remote);
264
 
 
265
 
  void OnRemoteUrgentChanged(LauncherEntryRemote* remote);
266
 
 
267
 
  void OnRemoteEmblemVisibleChanged(LauncherEntryRemote* remote);
268
 
 
269
 
  void OnRemoteCountVisibleChanged(LauncherEntryRemote* remote);
270
 
 
271
 
  void OnRemoteProgressVisibleChanged(LauncherEntryRemote* remote);
272
 
 
273
 
  Launcher* _launcher;
274
 
 
275
 
  nux::Tooltip* _tooltip;
276
 
  QuicklistView* _quicklist;
277
 
 
278
 
  static nux::Tooltip* _current_tooltip;
279
 
  static QuicklistView* _current_quicklist;
280
 
 
281
 
  // This looks like a case for boost::logical::tribool
282
 
  static int _current_theme_is_mono;
283
 
 
284
 
  DbusmenuClient* _menuclient_dynamic_quicklist;
285
 
 
286
 
  friend class Launcher;
287
 
  friend class LauncherController;
288
 
  friend class LauncherModel;
289
 
 
290
 
private:
291
 
  typedef struct
292
 
  {
293
 
    LauncherIcon* self;
294
 
    Quirk quirk;
295
 
  } DelayedUpdateArg;
296
 
 
297
 
  static void ChildRealized(DbusmenuMenuitem* newitem, QuicklistView* quicklist);
298
 
  static void RootChanged(DbusmenuClient* client, DbusmenuMenuitem* newroot, QuicklistView* quicklist);
299
 
  static gboolean OnPresentTimeout(gpointer data);
300
 
  static gboolean OnCenterTimeout(gpointer data);
301
 
  static gboolean OnDelayedUpdateTimeout(gpointer data);
302
 
  static gboolean OnTooltipTimeout(gpointer data);
303
 
 
304
 
  void ColorForIcon(GdkPixbuf* pixbuf, nux::Color& background, nux::Color& glow);
305
 
  void SetTooltipAnchorTip();
306
 
  void SetQuicklistAnchorTip();
307
 
 
308
 
  bool             _has_visible_window;
309
 
  bool             _quicklist_is_initialized;
310
 
  bool             _remote_urgent;
311
 
  float            _present_urgency;
312
 
  float            _progress;
313
 
  guint            _center_stabilize_handle;
314
 
  guint            _present_time_handle;
315
 
  guint            _time_delay_handle;
316
 
  guint            _tooltip_delay_handle;
317
 
  int              _related_windows;
318
 
  int              _sort_priority;
319
 
  nux::Color       _background_color;
320
 
  nux::Color       _glow_color;
321
 
  static gboolean  _skip_tooltip_delay;
322
 
 
323
 
  gint64           _shortcut;
324
 
 
325
 
  nux::Point3      _center;
326
 
  nux::Point3      _last_stable;
327
 
  nux::Point3      _saved_center;
328
 
  IconType         _icon_type;
329
 
 
330
 
  static GtkIconTheme* _unity_theme;
331
 
 
332
 
  BaseTexturePtr _emblem;
333
 
 
334
 
  bool             _quirks[QUIRK_LAST];
335
 
  struct timespec  _quirk_times[QUIRK_LAST];
336
 
 
337
 
  std::list<LauncherEntryRemote*> _entry_list;
338
 
  std::map<TransformIndex, std::vector<nux::Vector4> > transform_map;
339
 
  
340
 
};
341
 
 
342
 
#endif // LAUNCHERICON_H
343