~didrocks/unity/launcher-bug-fix-fest

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
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
// -*- Mode: C++; indent-tabs-mode: nil; tab-width: 2 -*-
/*
 * Copyright (C) 2010 Canonical Ltd
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU 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 warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *
 * Authored by: Jay Taoko <jay.taoko@canonical.com>
 * Authored by: Mirco Müller <mirco.mueller@canonical.com
 */

#ifndef QUICKLISTVIEW_H
#define QUICKLISTVIEW_H

#include "Nux/Nux.h"
#include "Nux/BaseWindow.h"
#include "NuxGraphics/GraphicsEngine.h"
#include "Nux/TextureArea.h"
#include "NuxImage/CairoGraphics.h"

#include <pango/pango.h>
#include <pango/pangocairo.h>

#include "QuicklistMenuItem.h"

#include "Introspectable.h"

#define ANCHOR_WIDTH         10.0f
#define ANCHOR_HEIGHT        18.0f
#define HIGH_LIGHT_Y         -30.0f
#define HIGH_LIGHT_MIN_WIDTH 200.0f
#define RADIUS               5.0f
#define BLUR_INTENSITY       8
#define LINE_WIDTH           1.0f
#define PADDING_SIZE         1
#define H_MARGIN             30
#define V_MARGIN             4
#define FONT_FACE            "Ubuntu 13"


class VLayout;
class HLayout;
class SpaceLayout;
class QuicklistMenuItem;
class QuicklistMenuItemLabel;

class QuicklistView : public nux::BaseWindow, public Introspectable
{
  NUX_DECLARE_OBJECT_TYPE (QuicklistView, nux::BaseWindow);
public:
  QuicklistView ();

  ~QuicklistView ();

  long ProcessEvent (nux::IEvent& iEvent,
    long    traverseInfo,
    long    processEventInfo);

  void Draw (nux::GraphicsEngine& gfxContext,
    bool             forceDraw);

  void DrawContent (nux::GraphicsEngine& gfxContext,
    bool             forceDraw);

  void SetText (nux::NString text);
  
  void RemoveAllMenuItem ();
  
  void AddMenuItem (QuicklistMenuItem* item);
  
  void RenderQuicklistView ();

  void ShowQuicklistWithTipAt (int anchor_tip_x, int anchor_tip_y);
  virtual void ShowWindow (bool b, bool StartModal = false);

  void Show ();
  void Hide ();
  
  int GetNumItems ();
  QuicklistMenuItem* GetNthItems (int index);
  QuicklistMenuItemType GetNthType (int index);
  std::list<QuicklistMenuItem*> GetChildren ();
  void DefaultToFirstItem ();

  void TestMenuItems (DbusmenuMenuitem* root);
  
  // Introspection
  const gchar* GetName ();
  void AddProperties (GVariantBuilder *builder);

  void EnableQuicklistForTesting (bool enable_testing);

private:
  void RecvCairoTextChanged (QuicklistMenuItem* item);
  void RecvCairoTextColorChanged (QuicklistMenuItem* item);
  void RecvItemMouseClick (QuicklistMenuItem* item, int x, int y);
  void RecvItemMouseRelease (QuicklistMenuItem* item, int x, int y);
  void RecvItemMouseEnter (QuicklistMenuItem* item);
  void RecvItemMouseLeave (QuicklistMenuItem* item);
  void RecvItemMouseDrag (QuicklistMenuItem* item, int x, int y);

  void RecvMouseDown (int x, int y, unsigned long button_flags, unsigned long key_flags);
  void RecvMouseUp (int x, int y, unsigned long button_flags, unsigned long key_flags);
  void RecvMouseClick (int x, int y, unsigned long button_flags, unsigned long key_flags);
  void RecvMouseMove (int x, int y, int dx, int dy, unsigned long button_flags, unsigned long key_flags);
  void RecvMouseDrag (int x, int y, int dx, int dy, unsigned long button_flags, unsigned long key_flags);
  void RecvMouseDownOutsideOfQuicklist (int x, int y, unsigned long button_flags, unsigned long key_flags);
    
  void RecvKeyPressed (unsigned int  key_sym,
                       unsigned long key_code,
                       unsigned long key_state);

  void RecvStartFocus ();
  void RecvEndFocus ();

  void PreLayoutManagement ();

  long PostLayoutManagement (long layoutResult);

  void PositionChildLayout (float offsetX, float offsetY);

  void LayoutWindowElements ();

  void NotifyConfigurationChange (int width, int height);

  //! A convenience function to fill in the default quicklist with some random items.
  void FillInDefaultItems ();
  
  void CancelItemsPrelightStatus ();
  
  //! Check the mouse up event sent by an item. Detect the item where the mous is and emit the appropriate signal.
  void CheckAndEmitItemSignal (int x, int y);
  
  //nux::CairoGraphics*   _cairo_graphics;
  int                   _anchorX;
  int                   _anchorY;
  nux::NString          _labelText;
  int                   _dpiX;
  int                   _dpiY;
  int                   _top_size; // size of the segment from point 13 to 14. See figure in ql_compute_full_mask_path.

  bool                  _mouse_down;

  //iIf true, suppress the Quicklist behaviour that is expected in Unity.
  // Keep the Quicklist on screen for testing and automation.
  bool                  _enable_quicklist_for_testing;

  cairo_font_options_t* _fontOpts;

  nux::BaseTexture*     _texture_bg;
  nux::BaseTexture*     _texture_mask;
  nux::BaseTexture*     _texture_outline;

  float _anchor_width;
  float _anchor_height;
  float _corner_radius;
  float _padding;
  nux::HLayout *_hlayout;
  nux::VLayout *_vlayout;
  nux::VLayout *_item_layout;
  nux::VLayout *_default_item_layout;
  nux::SpaceLayout *_left_space;  //!< Space from the left of the widget to the left of the text.
  nux::SpaceLayout *_right_space; //!< Space from the right of the text to the right of the widget.
  nux::SpaceLayout *_top_space;  //!< Space from the left of the widget to the left of the text.
  nux::SpaceLayout *_bottom_space; //!< Space from the right of the text to the right of the widget.

  bool _cairo_text_has_changed;
  void UpdateTexture ();
  std::list<QuicklistMenuItem*> _item_list;
  std::list<QuicklistMenuItem*> _default_item_list;
  
  bool _compute_blur_bkg;          //!< If true, compute the blurred background
  nux::ObjectPtr <nux::IOpenGLBaseTexture> bkg_blur_texture;  // Texture holding a blurred copy of the background behind the QuicklistView
  // Introspection
  gchar *_name;

  // used by keyboard/a11y-navigation
  int _current_item_index;
};

#endif // QUICKLISTVIEW_H