Merge lp:~3v1n0/unity/quicklist-menuitem-clanup into lp:unity

Proposed by Marco Trevisan (Treviño)
Status: Merged
Approved by: Marco Trevisan (Treviño)
Approved revision: no longer in the source branch.
Merged at revision: 2560
Proposed branch: lp:~3v1n0/unity/quicklist-menuitem-clanup
Merge into: lp:unity
Diff against target: 2896 lines (+711/-1548)
18 files modified
launcher/QuicklistMenuItem.cpp (+240/-342)
launcher/QuicklistMenuItem.h (+53/-80)
launcher/QuicklistMenuItemCheckmark.cpp (+40/-190)
launcher/QuicklistMenuItemCheckmark.h (+6/-29)
launcher/QuicklistMenuItemLabel.cpp (+30/-170)
launcher/QuicklistMenuItemLabel.h (+6/-29)
launcher/QuicklistMenuItemRadio.cpp (+48/-199)
launcher/QuicklistMenuItemRadio.h (+5/-30)
launcher/QuicklistMenuItemSeparator.cpp (+31/-126)
launcher/QuicklistMenuItemSeparator.h (+4/-29)
launcher/QuicklistView.cpp (+11/-55)
launcher/QuicklistView.h (+3/-1)
plugins/unityshell/src/unity-quicklist-menu-item-accessible.cpp (+1/-1)
tests/CMakeLists.txt (+2/-7)
tests/test_quicklist_menu_item.cpp (+107/-0)
tests/test_quicklist_view.cpp (+124/-0)
tests/unit/TestMain.cpp (+0/-2)
tests/unit/TestQuicklistMenuitems.cpp (+0/-258)
To merge this branch: bzr merge lp:~3v1n0/unity/quicklist-menuitem-clanup
Reviewer Review Type Date Requested Status
Tim Penhey (community) Approve
Review via email: mp+119359@code.launchpad.net

Commit message

QuicklistMenuItem: remove debug bits, factorize duplicated code, remove friendship, use smart pointers

  Removed a lot of duplicated code between implementations, use top-level factorized code, use enum class,
  c++ types and better pointer deletions
  Tests updated

Description of the change

Main QuicklistMenuItem cleanup, removing a lot of duplicated code, friendships and using smart pointers and c++ strings...

Tests rewritten and moved to gtest.

To post a comment you must log in.
Revision history for this message
Tim Penhey (thumper) wrote :

On the whole this looks really good.

I'm going to assume that you have actually run and tested all the quick list options.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'launcher/QuicklistMenuItem.cpp'
--- launcher/QuicklistMenuItem.cpp 2012-05-14 02:08:47 +0000
+++ launcher/QuicklistMenuItem.cpp 2012-08-13 14:28:23 +0000
@@ -1,6 +1,6 @@
1// -*- Mode: C++; indent-tabs-mode: nil; tab-width: 2 -*-1// -*- Mode: C++; indent-tabs-mode: nil; tab-width: 2 -*-
2/*2/*
3 * Copyright (C) 2010 Canonical Ltd3 * Copyright (C) 2010-2012 Canonical Ltd
4 *4 *
5 * This program is free software: you can redistribute it and/or modify5 * 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 as6 * it under the terms of the GNU General Public License version 3 as
@@ -16,322 +16,133 @@
16 *16 *
17 * Authored by: Mirco Müller <mirco.mueller@canonical.com>17 * Authored by: Mirco Müller <mirco.mueller@canonical.com>
18 * Jay Taoko <jay.taoko@canonical.com>18 * Jay Taoko <jay.taoko@canonical.com>
19 * Marco Trevisan (Treviño) <3v1n0@ubuntu.com>19 * Marco Trevisan <marco.trevisan@canonical.com>
20 */20 */
2121
22#include <gdk/gdk.h>
23#include <gtk/gtk.h>22#include <gtk/gtk.h>
2423#include <UnityCore/Variant.h>
25#include <Nux/Nux.h>24#include "unity-shared/UBusWrapper.h"
25#include "unity-shared/UBusMessages.h"
2626
27#include "QuicklistMenuItem.h"27#include "QuicklistMenuItem.h"
28#include <UnityCore/Variant.h>
29
30#include <X11/Xlib.h>
3128
32namespace unity29namespace unity
33{30{
3431
35NUX_IMPLEMENT_OBJECT_TYPE(QuicklistMenuItem);32NUX_IMPLEMENT_OBJECT_TYPE(QuicklistMenuItem);
3633
37static void34QuicklistMenuItem::QuicklistMenuItem(QuicklistMenuItemType type, DbusmenuMenuitem* item, NUX_FILE_LINE_DECL)
38OnPropertyChanged(gchar* property,35 : nux::View(NUX_FILE_LINE_PARAM)
39 GValue* value,36 , _item_type(type)
40 QuicklistMenuItem* self);37 , _menu_item(item, glib::AddRef())
4138 , _prelight(false)
42static void39{
43OnItemActivated(guint timestamp,
44 QuicklistMenuItem* self);
45
46QuicklistMenuItem::QuicklistMenuItem(DbusmenuMenuitem* item,
47 NUX_FILE_LINE_DECL) :
48 View(NUX_FILE_LINE_PARAM)
49{
50 if (item == 0)
51 {
52 g_warning("Invalid DbusmenuMenuitem in file %s at line %s.", G_STRFUNC, G_STRLOC);
53 }
54
55 Initialize(item, false);
56}
57
58QuicklistMenuItem::QuicklistMenuItem(DbusmenuMenuitem* item,
59 bool debug,
60 NUX_FILE_LINE_DECL) :
61 View(NUX_FILE_LINE_PARAM)
62{
63 Initialize(item, debug);
64}
65
66void
67QuicklistMenuItem::Initialize(DbusmenuMenuitem* item, bool debug)
68{
69 _text = "";
70 _color = nux::Color(1.0f, 1.0f, 1.0f, 1.0f);
71 _menuItem = DBUSMENU_MENUITEM(g_object_ref(item));
72 _debug = debug;
73 _item_type = MENUITEM_TYPE_UNKNOWN;
74
75 _normalTexture[0] = NULL;
76 _normalTexture[1] = NULL;
77 _prelightTexture[0] = NULL;
78 _prelightTexture[1] = NULL;
79
80 if (_menuItem)
81 {
82 g_signal_connect(_menuItem,
83 "property-changed",
84 G_CALLBACK(OnPropertyChanged),
85 this);
86 g_signal_connect(_menuItem,
87 "item-activated",
88 G_CALLBACK(OnItemActivated),
89 this);
90 }
91
92 mouse_up.connect(sigc::mem_fun(this, &QuicklistMenuItem::RecvMouseUp));40 mouse_up.connect(sigc::mem_fun(this, &QuicklistMenuItem::RecvMouseUp));
93 mouse_click.connect(sigc::mem_fun(this, &QuicklistMenuItem::RecvMouseClick));41 mouse_click.connect(sigc::mem_fun(this, &QuicklistMenuItem::RecvMouseClick));
94 mouse_drag.connect(sigc::mem_fun(this, &QuicklistMenuItem::RecvMouseDrag));42 mouse_drag.connect(sigc::mem_fun(this, &QuicklistMenuItem::RecvMouseDrag));
95 mouse_enter.connect(sigc::mem_fun(this, &QuicklistMenuItem::RecvMouseEnter));43 mouse_enter.connect(sigc::mem_fun(this, &QuicklistMenuItem::RecvMouseEnter));
96 mouse_leave.connect(sigc::mem_fun(this, &QuicklistMenuItem::RecvMouseLeave));44 mouse_leave.connect(sigc::mem_fun(this, &QuicklistMenuItem::RecvMouseLeave));
97
98 _prelight = false;
99}45}
10046
101QuicklistMenuItem::~QuicklistMenuItem()47QuicklistMenuItem::~QuicklistMenuItem()
102{48{}
103 if (_normalTexture[0])49
104 _normalTexture[0]->UnReference();50std::string QuicklistMenuItem::GetDefaultText() const
10551{
106 if (_normalTexture[1])52 return "";
107 _normalTexture[1]->UnReference();53}
10854
109 if (_prelightTexture[0])55void QuicklistMenuItem::InitializeText()
110 _prelightTexture[0]->UnReference();56{
11157 if (_menu_item)
112 if (_prelightTexture[1])
113 _prelightTexture[1]->UnReference();
114
115 if (_menuItem)
116 g_object_unref(_menuItem);
117}
118
119const gchar*
120QuicklistMenuItem::GetDefaultText()
121{
122 return NULL;
123}
124
125void
126QuicklistMenuItem::InitializeText()
127{
128 if (_menuItem)
129 _text = GetText();58 _text = GetText();
130 else59 else
131 _text = GetDefaultText();60 _text = GetDefaultText();
13261
133 int textWidth = 1;62 // This is needed to setup the item size values
134 int textHeight = 1;63 nux::CairoGraphics cairoGraphics(CAIRO_FORMAT_A1, 1, 1);
135 GetTextExtents(textWidth, textHeight);64 DrawText(cairoGraphics, 1, 1, nux::color::White);
136 SetMinimumSize(textWidth + ITEM_INDENT_ABS + 3 * ITEM_MARGIN,
137 textHeight + 2 * ITEM_MARGIN);
138}65}
13966
140QuicklistMenuItemType QuicklistMenuItem::GetItemType()67QuicklistMenuItemType QuicklistMenuItem::GetItemType() const
141{68{
142 return _item_type;69 return _item_type;
143}70}
14471
145void72std::string QuicklistMenuItem::GetLabel() const
146QuicklistMenuItem::PreLayoutManagement()73{
147{74 if (!_menu_item)
148 View::PreLayoutManagement();75 return "";
149}76
15077 const char *label = dbusmenu_menuitem_property_get(_menu_item, DBUSMENU_MENUITEM_PROP_LABEL);
151long78
152QuicklistMenuItem::PostLayoutManagement(long layoutResult)79 return label ? label : "";
153{80}
154 long result = View::PostLayoutManagement(layoutResult);81
15582bool QuicklistMenuItem::GetEnabled() const
156 return result;83{
157}84 if (!_menu_item)
15885 return false;
159void86
160QuicklistMenuItem::Draw(nux::GraphicsEngine& gfxContext,87 return dbusmenu_menuitem_property_get_bool(_menu_item, DBUSMENU_MENUITEM_PROP_ENABLED);
161 bool forceDraw)88}
162{89
163}90bool QuicklistMenuItem::GetActive() const
16491{
165void92 if (!_menu_item)
166QuicklistMenuItem::DrawContent(nux::GraphicsEngine& gfxContext,93 return false;
167 bool forceDraw)94
168{95 int toggle = dbusmenu_menuitem_property_get_int(_menu_item, DBUSMENU_MENUITEM_PROP_TOGGLE_STATE);
169}96
17097 return (toggle == DBUSMENU_MENUITEM_TOGGLE_STATE_CHECKED);
171void98}
172QuicklistMenuItem::PostDraw(nux::GraphicsEngine& gfxContext,99
173 bool forceDraw)100bool QuicklistMenuItem::GetVisible() const
174{101{
175}102 if (!_menu_item)
176103 return false;
177const gchar*104
178QuicklistMenuItem::GetLabel()105 return dbusmenu_menuitem_property_get_bool(_menu_item, DBUSMENU_MENUITEM_PROP_VISIBLE);
179{106}
180 if (_menuItem == 0)107
181 return 0;108bool QuicklistMenuItem::GetSelectable() const
182 return dbusmenu_menuitem_property_get(_menuItem,
183 DBUSMENU_MENUITEM_PROP_LABEL);
184}
185
186bool
187QuicklistMenuItem::GetEnabled()
188{
189 if (_menuItem == 0)
190 return false;
191 return dbusmenu_menuitem_property_get_bool(_menuItem,
192 DBUSMENU_MENUITEM_PROP_ENABLED);
193}
194
195bool
196QuicklistMenuItem::GetActive()
197{
198 if (_menuItem == 0)
199 return false;
200 return dbusmenu_menuitem_property_get_int(_menuItem,
201 DBUSMENU_MENUITEM_PROP_TOGGLE_STATE) == DBUSMENU_MENUITEM_TOGGLE_STATE_CHECKED;
202}
203
204bool
205QuicklistMenuItem::GetVisible()
206{
207 if (_menuItem == 0)
208 return false;
209 return dbusmenu_menuitem_property_get_bool(_menuItem,
210 DBUSMENU_MENUITEM_PROP_VISIBLE);
211}
212
213bool
214QuicklistMenuItem::GetSelectable()
215{109{
216 return GetVisible() && GetEnabled();110 return GetVisible() && GetEnabled();
217}111}
218112
219void QuicklistMenuItem::ItemActivated()113std::string QuicklistMenuItem::GetText() const
220{114{
221 if (_debug)115 std::string const& label = GetLabel();
222 sigChanged.emit(*this);116
223117 if (label.empty())
224 std::cout << "ItemActivated() called" << std::endl;118 return "";
225}
226
227gchar* QuicklistMenuItem::GetText()
228{
229 const gchar *label;
230 gchar *text;
231
232 if (!_menuItem)
233 return NULL;
234
235 label = GetLabel();
236
237 if (!label)
238 return NULL;
239119
240 if (!IsMarkupEnabled())120 if (!IsMarkupEnabled())
241 {121 {
242 text = g_markup_escape_text(label, -1);122 return glib::String(g_markup_escape_text(label.c_str(), -1)).Str();
243 }123 }
244 else124
245 {125 return label;
246 text = g_strdup(label);126}
247 }127
248128void QuicklistMenuItem::Activate() const
249 return text;129{
250}130 if (!_menu_item)
251131 return;
252void QuicklistMenuItem::GetTextExtents(int& width, int& height)132
253{133 dbusmenu_menuitem_handle_event(_menu_item, "clicked", nullptr, 0);
254 GtkSettings* settings = gtk_settings_get_default(); // not ref'ed134 UBusManager manager;
255 gchar* fontName = NULL;135 manager.SendMessage(UBUS_PLACE_VIEW_CLOSE_REQUEST);
256136}
257 g_object_get(settings, "gtk-font-name", &fontName, NULL);137
258 GetTextExtents(fontName, width, height);138void QuicklistMenuItem::Select(bool select)
259 g_free(fontName);139{
260}140 _prelight = select;
261141}
262void QuicklistMenuItem::GetTextExtents(const gchar* font,142
263 int& width,143bool QuicklistMenuItem::IsSelected() const
264 int& height)144{
265{145 return _prelight;
266 cairo_surface_t* surface = NULL;
267 cairo_t* cr = NULL;
268 PangoLayout* layout = NULL;
269 PangoFontDescription* desc = NULL;
270 PangoContext* pangoCtx = NULL;
271 PangoRectangle logRect = {0, 0, 0, 0};
272 int dpi = 0;
273 GdkScreen* screen = gdk_screen_get_default(); // is not ref'ed
274 GtkSettings* settings = gtk_settings_get_default(); // is not ref'ed
275
276 // sanity check
277 if (!font)
278 return;
279
280 if (_text == "")
281 return;
282
283 surface = cairo_image_surface_create(CAIRO_FORMAT_A1, 1, 1);
284 cr = cairo_create(surface);
285 cairo_set_font_options(cr, gdk_screen_get_font_options(screen));
286 layout = pango_cairo_create_layout(cr);
287 desc = pango_font_description_from_string(font);
288 pango_font_description_set_weight(desc, PANGO_WEIGHT_NORMAL);
289 pango_layout_set_font_description(layout, desc);
290 pango_layout_set_wrap(layout, PANGO_WRAP_WORD_CHAR);
291 pango_layout_set_ellipsize(layout, PANGO_ELLIPSIZE_END);
292 pango_layout_set_markup_with_accel(layout, _text.c_str(), -1, '_', NULL);
293 pangoCtx = pango_layout_get_context(layout); // is not ref'ed
294 pango_cairo_context_set_font_options(pangoCtx,
295 gdk_screen_get_font_options(screen));
296 g_object_get(settings, "gtk-xft-dpi", &dpi, NULL);
297 if (dpi == -1)
298 {
299 // use some default DPI-value
300 pango_cairo_context_set_resolution(pangoCtx, 96.0f);
301 }
302 else
303 {
304 pango_cairo_context_set_resolution(pangoCtx,
305 (float) dpi / (float) PANGO_SCALE);
306 }
307 pango_layout_context_changed(layout);
308 pango_layout_get_extents(layout, NULL, &logRect);
309
310 width = logRect.width / PANGO_SCALE;
311 height = logRect.height / PANGO_SCALE;
312
313 // clean up
314 pango_font_description_free(desc);
315 g_object_unref(layout);
316 cairo_destroy(cr);
317 cairo_surface_destroy(surface);
318}
319
320static void
321OnPropertyChanged(gchar* property,
322 GValue* value,
323 QuicklistMenuItem* self)
324{
325 //todo
326 //self->UpdateTexture ();
327}
328
329static void
330OnItemActivated(guint timestamp,
331 QuicklistMenuItem* self)
332{
333 //todo:
334 //self->ItemActivated ();
335}146}
336147
337void QuicklistMenuItem::RecvMouseUp(int x, int y, unsigned long button_flags, unsigned long key_flags)148void QuicklistMenuItem::RecvMouseUp(int x, int y, unsigned long button_flags, unsigned long key_flags)
@@ -342,9 +153,8 @@
342void QuicklistMenuItem::RecvMouseClick(int x, int y, unsigned long button_flags, unsigned long key_flags)153void QuicklistMenuItem::RecvMouseClick(int x, int y, unsigned long button_flags, unsigned long key_flags)
343{154{
344 if (!GetEnabled())155 if (!GetEnabled())
345 {
346 return;156 return;
347 }157
348 sigMouseClick.emit(this, x, y);158 sigMouseClick.emit(this, x, y);
349}159}
350160
@@ -363,38 +173,115 @@
363 sigMouseLeave.emit(this);173 sigMouseLeave.emit(this);
364}174}
365175
366void QuicklistMenuItem::DrawText(nux::CairoGraphics* cairo, int width, int height, nux::Color const& color)176void QuicklistMenuItem::PreLayoutManagement()
367{177{
368 if (_text == "" || cairo == nullptr)178 _pre_layout_width = GetBaseWidth();
369 return;179 _pre_layout_height = GetBaseHeight();
370180
371 cairo_t* cr = cairo->GetContext();181 if (!_normalTexture[0])
372 int textWidth = 0;182 {
373 int textHeight = 0;183 UpdateTexture();
374 PangoLayout* layout = NULL;184 }
375 PangoFontDescription* desc = NULL;185
376 PangoContext* pangoCtx = NULL;186 View::PreLayoutManagement();
377 int dpi = 0;187}
378 GdkScreen* screen = gdk_screen_get_default(); // not ref'ed188
379 GtkSettings* settings = gtk_settings_get_default(); // not ref'ed189long QuicklistMenuItem::PostLayoutManagement(long layoutResult)
380 gchar* fontName = NULL;190{
381191 int w = GetBaseWidth();
382 g_object_get(settings, "gtk-font-name", &fontName, NULL);192 int h = GetBaseHeight();
383 GetTextExtents(fontName, textWidth, textHeight);193
384194 long result = 0;
195
196 if (_pre_layout_width < w)
197 result |= nux::eLargerWidth;
198 else if (_pre_layout_width > w)
199 result |= nux::eSmallerWidth;
200 else
201 result |= nux::eCompliantWidth;
202
203 if (_pre_layout_height < h)
204 result |= nux::eLargerHeight;
205 else if (_pre_layout_height > h)
206 result |= nux::eSmallerHeight;
207 else
208 result |= nux::eCompliantHeight;
209
210 return result;
211}
212
213void QuicklistMenuItem::Draw(nux::GraphicsEngine& gfxContext, bool forceDraw)
214{
215 // Check if the texture have been computed. If they haven't, exit the function.
216 if (!_normalTexture[0] || !_prelightTexture[0])
217 return;
218
219 nux::Geometry const& base = GetGeometry();
220
221 gfxContext.PushClippingRectangle(base);
222
223 nux::TexCoordXForm texxform;
224 texxform.SetWrap(nux::TEXWRAP_REPEAT, nux::TEXWRAP_REPEAT);
225 texxform.SetTexCoordType(nux::TexCoordXForm::OFFSET_COORD);
226
227 gfxContext.GetRenderStates().SetBlend(true);
228 gfxContext.GetRenderStates().SetPremultipliedBlend(nux::SRC_OVER);
229
230 nux::ObjectPtr<nux::IOpenGLBaseTexture> texture;
231 unsigned int texture_idx = GetActive() ? 1 : 0;
232 bool enabled = GetEnabled();
233
234 if (!_prelight || !enabled)
235 {
236 texture = _normalTexture[texture_idx]->GetDeviceTexture();
237 }
238 else
239 {
240 texture = _prelightTexture[texture_idx]->GetDeviceTexture();
241 }
242
243 nux::Color const& color = enabled ? nux::color::White : nux::color::White * 0.35;
244
245 gfxContext.QRP_1Tex(base.x, base.y, base.width, base.height, texture, texxform, color);
246 gfxContext.GetRenderStates().SetBlend(false);
247 gfxContext.PopClippingRectangle();
248}
249
250nux::Size const& QuicklistMenuItem::GetTextExtents() const
251{
252 return _text_extents;
253}
254
255void QuicklistMenuItem::DrawText(nux::CairoGraphics& cairo, int width, int height, nux::Color const& color)
256{
257 if (_text.empty())
258 return;
259
260 GdkScreen* screen = gdk_screen_get_default(); // not ref'ed
261 GtkSettings* settings = gtk_settings_get_default(); // not ref'ed
262
263 glib::String font_name;
264 g_object_get(settings, "gtk-font-name", &font_name, nullptr);
265
266 std::shared_ptr<cairo_t> cairo_context(cairo.GetContext(), cairo_destroy);
267 cairo_t* cr = cairo_context.get();
385 cairo_set_operator(cr, CAIRO_OPERATOR_SOURCE);268 cairo_set_operator(cr, CAIRO_OPERATOR_SOURCE);
386 cairo_set_source_rgba(cr, color.red, color.blue, color.green, color.alpha);269 cairo_set_source_rgba(cr, color.red, color.blue, color.green, color.alpha);
387 cairo_set_font_options(cr, gdk_screen_get_font_options(screen));270 cairo_set_font_options(cr, gdk_screen_get_font_options(screen));
388 layout = pango_cairo_create_layout(cr);271
389 desc = pango_font_description_from_string(fontName);272 glib::Object<PangoLayout> layout(pango_cairo_create_layout(cr));
390 pango_layout_set_font_description(layout, desc);273 std::shared_ptr<PangoFontDescription> desc(pango_font_description_from_string(font_name), pango_font_description_free);
274 pango_layout_set_font_description(layout, desc.get());
391 pango_layout_set_wrap(layout, PANGO_WRAP_WORD_CHAR);275 pango_layout_set_wrap(layout, PANGO_WRAP_WORD_CHAR);
392 pango_layout_set_ellipsize(layout, PANGO_ELLIPSIZE_END);276 pango_layout_set_ellipsize(layout, PANGO_ELLIPSIZE_END);
393 pango_layout_set_markup_with_accel(layout, _text.c_str(), -1, '_', NULL);277 pango_layout_set_markup_with_accel(layout, _text.c_str(), -1, '_', nullptr);
394 pangoCtx = pango_layout_get_context(layout); // is not ref'ed278
395 pango_cairo_context_set_font_options(pangoCtx,279 PangoContext* pangoCtx = pango_layout_get_context(layout); // is not ref'ed
396 gdk_screen_get_font_options(screen));280 pango_cairo_context_set_font_options(pangoCtx, gdk_screen_get_font_options(screen));
397 g_object_get(settings, "gtk-xft-dpi", &dpi, NULL);281
282 int dpi = 0;
283 g_object_get(settings, "gtk-xft-dpi", &dpi, nullptr);
284
398 if (dpi == -1)285 if (dpi == -1)
399 {286 {
400 // use some default DPI-value287 // use some default DPI-value
@@ -402,68 +289,79 @@
402 }289 }
403 else290 else
404 {291 {
405 pango_cairo_context_set_resolution(pangoCtx,292 pango_cairo_context_set_resolution(pangoCtx, static_cast<float>(dpi) / static_cast<float>(PANGO_SCALE));
406 (float) dpi / (float) PANGO_SCALE);
407 }293 }
408294
409 pango_layout_context_changed(layout);295 pango_layout_context_changed(layout);
410296 PangoRectangle log_rect = {0, 0, 0, 0};
411 cairo_move_to(cr,297 pango_layout_get_extents(layout, nullptr, &log_rect);
412 2 * ITEM_MARGIN + ITEM_INDENT_ABS,298
413 (float)(height - textHeight) / 2.0f);299 int text_width = log_rect.width / PANGO_SCALE;
300 int text_height = log_rect.height / PANGO_SCALE;
301
302 _text_extents.width = text_width + ITEM_INDENT_ABS + 3 * ITEM_MARGIN;
303 _text_extents.height = text_height + 2 * ITEM_MARGIN;
304
305 SetMinimumSize(_text_extents.width, _text_extents.height);
306
307 cairo_move_to(cr, 2 * ITEM_MARGIN + ITEM_INDENT_ABS, static_cast<float>(height - text_height) / 2.0f);
414 pango_cairo_show_layout(cr, layout);308 pango_cairo_show_layout(cr, layout);
415
416 // clean up
417 pango_font_description_free(desc);
418 g_free(fontName);
419 g_object_unref(layout);
420 cairo_destroy(cr);
421}309}
422310
423void QuicklistMenuItem::DrawPrelight(nux::CairoGraphics* cairo, int width, int height, nux::Color const& color)311void QuicklistMenuItem::DrawPrelight(nux::CairoGraphics& cairo, int width, int height, nux::Color const& color)
424{312{
425 if (!cairo)313 std::shared_ptr<cairo_t> cairo_context(cairo.GetContext(), cairo_destroy);
426 return;314 cairo_t* cr = cairo_context.get();
427
428 cairo_t* cr = cairo->GetContext();
429315
430 cairo_set_operator(cr, CAIRO_OPERATOR_SOURCE);316 cairo_set_operator(cr, CAIRO_OPERATOR_SOURCE);
431 cairo_set_source_rgba(cr, color.red, color.blue, color.green, color.alpha);317 cairo_set_source_rgba(cr, color.red, color.blue, color.green, color.alpha);
432 cairo->DrawRoundedRectangle(cr, 1.0f, 0.0f, 0.0f, ITEM_CORNER_RADIUS_ABS,318 cairo.DrawRoundedRectangle(cr, 1.0f, 0.0f, 0.0f, ITEM_CORNER_RADIUS_ABS, width, height);
433 width, height);
434 cairo_fill(cr);319 cairo_fill(cr);
435 cairo_destroy(cr);320}
436}321
437322double QuicklistMenuItem::Align(double val)
438void323{
439QuicklistMenuItem::EnableLabelMarkup(bool enabled)324 const double fract = val - static_cast<int>(val);
325
326 if (fract != 0.5f)
327 return static_cast<double>(static_cast<int>(val) + 0.5f);
328 else
329 return val;
330}
331
332void QuicklistMenuItem::EnableLabelMarkup(bool enabled)
440{333{
441 if (IsMarkupEnabled() != enabled)334 if (IsMarkupEnabled() != enabled)
442 {335 {
443 dbusmenu_menuitem_property_set_bool(_menuItem, "unity-use-markup", enabled);336 dbusmenu_menuitem_property_set_bool(_menu_item, "unity-use-markup", enabled);
444337
445 _text = "";338 _text = "";
446 InitializeText();339 InitializeText();
447 }340 }
448}341}
449342
450bool343bool QuicklistMenuItem::IsMarkupEnabled() const
451QuicklistMenuItem::IsMarkupEnabled()
452{344{
453 gboolean markup;345 if (!_menu_item)
454
455 if (!_menuItem)
456 return false;346 return false;
457347
458 markup = dbusmenu_menuitem_property_get_bool(_menuItem, "unity-use-markup");348 gboolean markup = dbusmenu_menuitem_property_get_bool(_menu_item, "unity-use-markup");
459 return (markup != FALSE);349 return (markup != FALSE);
460}350}
461351
352unsigned QuicklistMenuItem::GetCairoSurfaceWidth() const
353{
354 if (!_normalTexture[0])
355 return 0;
356
357 return _normalTexture[0]->GetWidth();
358}
359
462// Introspection360// Introspection
463361
464std::string QuicklistMenuItem::GetName() const362std::string QuicklistMenuItem::GetName() const
465{363{
466 return _name;364 return "QuicklistMenuItem";
467}365}
468366
469void QuicklistMenuItem::AddProperties(GVariantBuilder* builder)367void QuicklistMenuItem::AddProperties(GVariantBuilder* builder)
470368
=== modified file 'launcher/QuicklistMenuItem.h'
--- launcher/QuicklistMenuItem.h 2012-05-25 20:49:27 +0000
+++ launcher/QuicklistMenuItem.h 2012-08-13 14:28:23 +0000
@@ -1,6 +1,6 @@
1// -*- Mode: C++; indent-tabs-mode: nil; tab-width: 2 -*-1// -*- Mode: C++; indent-tabs-mode: nil; tab-width: 2 -*-
2/*2/*
3 * Copyright (C) 2010 Canonical Ltd3 * Copyright (C) 2010-2012 Canonical Ltd
4 *4 *
5 * This program is free software: you can redistribute it and/or modify5 * 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 as6 * it under the terms of the GNU General Public License version 3 as
@@ -15,18 +15,18 @@
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
16 *16 *
17 * Authored by: Mirco Müller <mirco.mueller@canonical.com>17 * Authored by: Mirco Müller <mirco.mueller@canonical.com>
18 * Authored by: Jay Taoko <jay.taoko@canonical.com>18 * Jay Taoko <jay.taoko@canonical.com>
19 * Marco Trevisan <marco.trevisan@canonical.com>
19 */20 */
2021
21#ifndef QUICKLISTMENUITEM_H22#ifndef QUICKLISTMENUITEM_H
22#define QUICKLISTMENUITEM_H23#define QUICKLISTMENUITEM_H
2324
24#include <libdbusmenu-glib/menuitem.h>
25#include <libdbusmenu-glib/client.h>
26
27#include <Nux/Nux.h>25#include <Nux/Nux.h>
28#include <Nux/View.h>26#include <Nux/View.h>
29#include <NuxGraphics/CairoGraphics.h>27#include <NuxGraphics/CairoGraphics.h>
28#include <libdbusmenu-glib/menuitem.h>
29#include <UnityCore/GLibWrapper.h>
3030
31#include <pango/pango.h>31#include <pango/pango.h>
32#include <pango/pangocairo.h>32#include <pango/pangocairo.h>
@@ -36,56 +36,48 @@
36namespace unity36namespace unity
37{37{
3838
39enum QuicklistMenuItemType39enum class QuicklistMenuItemType
40{40{
41 MENUITEM_TYPE_UNKNOWN = 0,41 UNKNOWN = 0,
42 MENUITEM_TYPE_LABEL,42 LABEL,
43 MENUITEM_TYPE_SEPARATOR,43 SEPARATOR,
44 MENUITEM_TYPE_CHECK,44 CHECK,
45 MENUITEM_TYPE_RADIO,45 RADIO
46};46};
4747
48class QuicklistMenuItem : public nux::View, public debug::Introspectable48class QuicklistMenuItem : public nux::View, public debug::Introspectable
49{49{
50 NUX_DECLARE_OBJECT_TYPE(QuicklistMenuItem, nux::View);50 NUX_DECLARE_OBJECT_TYPE(QuicklistMenuItem, nux::View);
51public:51public:
52 QuicklistMenuItem(DbusmenuMenuitem* item,52 QuicklistMenuItem(QuicklistMenuItemType type, DbusmenuMenuitem* item, NUX_FILE_LINE_PROTO);
53 NUX_FILE_LINE_PROTO);
54
55 QuicklistMenuItem(DbusmenuMenuitem* item,
56 bool debug,
57 NUX_FILE_LINE_PROTO);
58
59 virtual ~QuicklistMenuItem();53 virtual ~QuicklistMenuItem();
6054
61 void PreLayoutManagement();55 QuicklistMenuItemType GetItemType() const;
6256 virtual std::string GetLabel() const;
63 long PostLayoutManagement(long layoutResult);57 virtual bool GetEnabled() const;
6458 virtual bool GetActive() const;
65 void Draw(nux::GraphicsEngine& gfxContext,59 virtual bool GetVisible() const;
66 bool forceDraw);60 virtual bool GetSelectable() const;
6761
68 void DrawContent(nux::GraphicsEngine& gfxContext,
69 bool forceDraw);
70
71 void PostDraw(nux::GraphicsEngine& gfxContext,
72 bool forceDraw);
73
74 QuicklistMenuItemType GetItemType();
75
76 void ItemActivated();
77 void EnableLabelMarkup(bool enabled);62 void EnableLabelMarkup(bool enabled);
78 bool IsMarkupEnabled();63 bool IsMarkupEnabled() const;
7964
80 sigc::signal<void, QuicklistMenuItem&> sigChanged;65 void Activate() const;
66
67 void Select(bool select = true);
68 bool IsSelected() const;
69
70 nux::Size const& GetTextExtents() const;
71 virtual void UpdateTexture() = 0;
72 unsigned GetCairoSurfaceWidth() const;
73
81 sigc::signal<void, QuicklistMenuItem*> sigTextChanged;74 sigc::signal<void, QuicklistMenuItem*> sigTextChanged;
82 sigc::signal<void, QuicklistMenuItem*> sigColorChanged;75 sigc::signal<void, QuicklistMenuItem*> sigColorChanged;
8376 sigc::signal<void, QuicklistMenuItem*> sigMouseEnter;
84 virtual const gchar* GetLabel();77 sigc::signal<void, QuicklistMenuItem*> sigMouseLeave;
85 virtual bool GetEnabled();78 sigc::signal<void, QuicklistMenuItem*, int, int> sigMouseReleased;
86 virtual bool GetActive();79 sigc::signal<void, QuicklistMenuItem*, int, int> sigMouseClick;
87 virtual bool GetVisible();80 sigc::signal<void, QuicklistMenuItem*, int, int> sigMouseDrag;
88 virtual bool GetSelectable();
8981
90protected:82protected:
91 // Introspection83 // Introspection
@@ -96,25 +88,12 @@
96 static const int ITEM_CORNER_RADIUS_ABS = 3;88 static const int ITEM_CORNER_RADIUS_ABS = 3;
97 static const int ITEM_MARGIN = 4;89 static const int ITEM_MARGIN = 4;
9890
99 std::string _text;
100 nux::Color _textColor;
101 int _pre_layout_width;
102 int _pre_layout_height;
103 nux::CairoGraphics* _cairoGraphics;
104
105 nux::BaseTexture* _normalTexture[2];
106 nux::BaseTexture* _prelightTexture[2];
107
108 void Initialize(DbusmenuMenuitem* item, bool debug);
109 void InitializeText();91 void InitializeText();
110 virtual const gchar* GetDefaultText();92
11193 virtual std::string GetDefaultText() const;
112 gchar* GetText();94 std::string GetText() const;
113 //! Return the size of the text + size of associated radio button or check box95
114 void GetTextExtents(int& width, int& height);96 static double Align(double val);
115 void GetTextExtents(const gchar* font, int& width, int& height);
116 virtual void UpdateTexture() = 0;
117 virtual int CairoSurfaceWidth() = 0;
11897
119 void RecvMouseEnter(int x, int y, unsigned long button_flags, unsigned long key_flags);98 void RecvMouseEnter(int x, int y, unsigned long button_flags, unsigned long key_flags);
120 void RecvMouseLeave(int x, int y, unsigned long button_flags, unsigned long key_flags);99 void RecvMouseLeave(int x, int y, unsigned long button_flags, unsigned long key_flags);
@@ -122,27 +101,21 @@
122 void RecvMouseClick(int x, int y, unsigned long button_flags, unsigned long key_flags);101 void RecvMouseClick(int x, int y, unsigned long button_flags, unsigned long key_flags);
123 void RecvMouseDrag(int x, int y, int dx, int dy, unsigned long button_flags, unsigned long key_flags);102 void RecvMouseDrag(int x, int y, int dx, int dy, unsigned long button_flags, unsigned long key_flags);
124103
125 sigc::signal<void, QuicklistMenuItem*> sigMouseEnter;104 void PreLayoutManagement();
126 sigc::signal<void, QuicklistMenuItem*> sigMouseLeave;105 long PostLayoutManagement(long layoutResult);
127 sigc::signal<void, QuicklistMenuItem*, int, int> sigMouseReleased;106 void Draw(nux::GraphicsEngine& gfxContext, bool forceDraw);
128 sigc::signal<void, QuicklistMenuItem*, int, int> sigMouseClick;107 void DrawText(nux::CairoGraphics& cairo, int width, int height, nux::Color const& color);
129 sigc::signal<void, QuicklistMenuItem*, int, int> sigMouseDrag;108 void DrawPrelight(nux::CairoGraphics& cairo, int width, int height, nux::Color const& color);
130109
131 DbusmenuMenuitem* _menuItem;110 nux::ObjectPtr<nux::BaseTexture> _normalTexture[2];
111 nux::ObjectPtr<nux::BaseTexture> _prelightTexture[2];
132 QuicklistMenuItemType _item_type;112 QuicklistMenuItemType _item_type;
133113 glib::Object<DbusmenuMenuitem> _menu_item;
134 nux::Color _color; //!< Item rendering color factor.114 bool _prelight;
135 bool _debug;115 int _pre_layout_width;
136116 int _pre_layout_height;
137 bool _prelight; //!< True when the mouse is over the item.117 nux::Size _text_extents;
138118 std::string _text;
139 void DrawText(nux::CairoGraphics* cairo, int width, int height, nux::Color const& color);
140 void DrawPrelight(nux::CairoGraphics* cairo, int width, int height, nux::Color const& color);
141
142 // Introspection
143 std::string _name;
144
145 friend class QuicklistView;
146};119};
147120
148} // NAMESPACE121} // NAMESPACE
149122
=== modified file 'launcher/QuicklistMenuItemCheckmark.cpp'
--- launcher/QuicklistMenuItemCheckmark.cpp 2012-05-07 22:28:17 +0000
+++ launcher/QuicklistMenuItemCheckmark.cpp 2012-08-13 14:28:23 +0000
@@ -1,6 +1,6 @@
1// -*- Mode: C++; indent-tabs-mode: nil; tab-width: 2 -*-1// -*- Mode: C++; indent-tabs-mode: nil; tab-width: 2 -*-
2/*2/*
3 * Copyright (C) 2010 Canonical Ltd3 * Copyright (C) 2010-2012 Canonical Ltd
4 *4 *
5 * This program is free software: you can redistribute it and/or modify5 * 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 as6 * it under the terms of the GNU General Public License version 3 as
@@ -15,165 +15,40 @@
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
16 *16 *
17 * Authored by: Mirco Müller <mirco.mueller@canonical.com>17 * Authored by: Mirco Müller <mirco.mueller@canonical.com>
18 * Authored by: Jay Taoko <jay.taoko@canonical.com>18 * Jay Taoko <jay.taoko@canonical.com>
19 * Marco Trevisan <marco.trevisan@canonical.com>
19 */20 */
2021
21#include <gdk/gdk.h>
22#include <gtk/gtk.h>
23
24#include <Nux/Nux.h>
25
26#include "unity-shared/CairoTexture.h"22#include "unity-shared/CairoTexture.h"
27#include "QuicklistMenuItemCheckmark.h"23#include "QuicklistMenuItemCheckmark.h"
2824
29namespace unity25namespace unity
30{26{
3127
32static double28QuicklistMenuItemCheckmark::QuicklistMenuItemCheckmark(DbusmenuMenuitem* item, NUX_FILE_LINE_DECL)
33_align(double val)29 : QuicklistMenuItem(QuicklistMenuItemType::CHECK, item, NUX_FILE_LINE_PARAM)
34{30{
35 double fract = val - (int) val;31 InitializeText();
3632}
37 if (fract != 0.5f)33
38 return (double)((int) val + 0.5f);34std::string QuicklistMenuItemCheckmark::GetDefaultText() const
39 else
40 return val;
41}
42
43QuicklistMenuItemCheckmark::QuicklistMenuItemCheckmark(DbusmenuMenuitem* item,
44 NUX_FILE_LINE_DECL) :
45 QuicklistMenuItem(item,
46 NUX_FILE_LINE_PARAM)
47{
48 _item_type = MENUITEM_TYPE_CHECK;
49 _name = "QuicklistMenuItemCheckmark";
50 InitializeText();
51}
52
53QuicklistMenuItemCheckmark::QuicklistMenuItemCheckmark(DbusmenuMenuitem* item,
54 bool debug,
55 NUX_FILE_LINE_DECL) :
56 QuicklistMenuItem(item,
57 debug,
58 NUX_FILE_LINE_PARAM)
59{
60 _item_type = MENUITEM_TYPE_CHECK;
61 _name = "QuicklistMenuItemCheckmark";
62 InitializeText();
63}
64
65QuicklistMenuItemCheckmark::~QuicklistMenuItemCheckmark()
66{}
67
68const gchar*
69QuicklistMenuItemCheckmark::GetDefaultText()
70{35{
71 return "Check Mark";36 return "Check Mark";
72}37}
7338
74void39std::string QuicklistMenuItemCheckmark::GetName() const
75QuicklistMenuItemCheckmark::PreLayoutManagement()40{
76{41 return "QuicklistMenuItemCheckmark";
77 _pre_layout_width = GetBaseWidth();42}
78 _pre_layout_height = GetBaseHeight();43
7944void QuicklistMenuItemCheckmark::UpdateTexture()
80 if (_normalTexture[0] == 0)45{
81 {46 int width = GetBaseWidth();
82 UpdateTexture();47 int height = GetBaseHeight();
83 }48
8449 nux::CairoGraphics cairoGraphics(CAIRO_FORMAT_ARGB32, width, height);
85 QuicklistMenuItem::PreLayoutManagement();50 std::shared_ptr<cairo_t> cairo_context(cairoGraphics.GetContext(), cairo_destroy);
86}51 cairo_t* cr = cairo_context.get();
87
88long
89QuicklistMenuItemCheckmark::PostLayoutManagement(long layoutResult)
90{
91 int w = GetBaseWidth();
92 int h = GetBaseHeight();
93
94 long result = 0;
95
96 if (_pre_layout_width < w)
97 result |= nux::eLargerWidth;
98 else if (_pre_layout_width > w)
99 result |= nux::eSmallerWidth;
100 else
101 result |= nux::eCompliantWidth;
102
103 if (_pre_layout_height < h)
104 result |= nux::eLargerHeight;
105 else if (_pre_layout_height > h)
106 result |= nux::eSmallerHeight;
107 else
108 result |= nux::eCompliantHeight;
109
110 return result;
111}
112
113void
114QuicklistMenuItemCheckmark::Draw(nux::GraphicsEngine& gfxContext, bool forceDraw)
115{
116 nux::ObjectPtr<nux::IOpenGLBaseTexture> texture;
117
118 // Check if the texture have been computed. If they haven't, exit the function.
119 if (!_normalTexture[0] || !_prelightTexture[0])
120 return;
121
122 nux::Geometry base = GetGeometry();
123
124 gfxContext.PushClippingRectangle(base);
125
126 nux::TexCoordXForm texxform;
127 texxform.SetWrap(nux::TEXWRAP_REPEAT, nux::TEXWRAP_REPEAT);
128 texxform.SetTexCoordType(nux::TexCoordXForm::OFFSET_COORD);
129
130 gfxContext.GetRenderStates().SetBlend(true);
131 gfxContext.GetRenderStates().SetPremultipliedBlend(nux::SRC_OVER);
132
133 unsigned int texture_idx = GetActive() ? 1 : 0;
134
135 if (!_prelight || !GetEnabled())
136 {
137 texture = _normalTexture[texture_idx]->GetDeviceTexture();
138 }
139 else
140 {
141 texture = _prelightTexture[texture_idx]->GetDeviceTexture();
142 }
143
144 _color = GetEnabled() ? nux::color::White : nux::color::White * 0.35;
145
146 gfxContext.QRP_1Tex(base.x,
147 base.y,
148 base.width,
149 base.height,
150 texture,
151 texxform,
152 _color);
153
154 gfxContext.GetRenderStates().SetBlend(false);
155
156 gfxContext.PopClippingRectangle();
157}
158
159void QuicklistMenuItemCheckmark::DrawContent(nux::GraphicsEngine& gfxContext,
160 bool forceDraw)
161{
162}
163
164void QuicklistMenuItemCheckmark::PostDraw(nux::GraphicsEngine& gfxContext,
165 bool forceDraw)
166{
167}
168
169void
170QuicklistMenuItemCheckmark::UpdateTexture()
171{
172 int width = GetBaseWidth();
173 int height = GetBaseHeight();
174
175 _cairoGraphics = new nux::CairoGraphics(CAIRO_FORMAT_ARGB32, width, height);
176 cairo_t* cr = _cairoGraphics->GetContext();
17752
178 // draw normal, unchecked version53 // draw normal, unchecked version
179 cairo_set_operator(cr, CAIRO_OPERATOR_CLEAR);54 cairo_set_operator(cr, CAIRO_OPERATOR_CLEAR);
@@ -184,11 +59,9 @@
184 cairo_set_source_rgba(cr, 1.0f, 1.0f, 1.0f, 1.0f);59 cairo_set_source_rgba(cr, 1.0f, 1.0f, 1.0f, 1.0f);
185 cairo_set_line_width(cr, 1.0f);60 cairo_set_line_width(cr, 1.0f);
18661
187 DrawText(_cairoGraphics, width, height, nux::color::White);62 DrawText(cairoGraphics, width, height, nux::color::White);
18863
189 if (_normalTexture[0])64 _normalTexture[0].Adopt(texture_from_cairo_graphics(cairoGraphics));
190 _normalTexture[0]->UnReference();
191 _normalTexture[0] = texture_from_cairo_graphics(*_cairoGraphics);
19265
193 // draw normal, checked version66 // draw normal, checked version
194 cairo_set_operator(cr, CAIRO_OPERATOR_CLEAR);67 cairo_set_operator(cr, CAIRO_OPERATOR_CLEAR);
@@ -200,9 +73,8 @@
200 cairo_set_line_width(cr, 1.0f);73 cairo_set_line_width(cr, 1.0f);
20174
202 cairo_save(cr);75 cairo_save(cr);
203 cairo_translate(cr,76 cairo_translate(cr, Align((ITEM_INDENT_ABS - 16.0f + ITEM_MARGIN) / 2.0f),
204 _align((ITEM_INDENT_ABS - 16.0f + ITEM_MARGIN) / 2.0f),77 Align((static_cast<double>(height) - 16.0f) / 2.0f));
205 _align(((double) height - 16.0f) / 2.0f));
20678
207 cairo_set_source_rgba(cr, 1.0f, 1.0f, 1.0f, 1.0f);79 cairo_set_source_rgba(cr, 1.0f, 1.0f, 1.0f, 1.0f);
20880
@@ -221,37 +93,30 @@
22193
222 cairo_restore(cr);94 cairo_restore(cr);
22395
224 DrawText(_cairoGraphics, width, height, nux::color::White);96 DrawText(cairoGraphics, width, height, nux::color::White);
22597
226 if (_normalTexture[1])98 _normalTexture[1].Adopt(texture_from_cairo_graphics(cairoGraphics));
227 _normalTexture[1]->UnReference();
228
229 _normalTexture[1] = texture_from_cairo_graphics(*_cairoGraphics);
23099
231 // draw active/prelight, unchecked version100 // draw active/prelight, unchecked version
232 cairo_set_operator(cr, CAIRO_OPERATOR_CLEAR);101 cairo_set_operator(cr, CAIRO_OPERATOR_CLEAR);
233 cairo_paint(cr);102 cairo_paint(cr);
234103
235 DrawPrelight(_cairoGraphics, width, height, nux::color::White);104 DrawPrelight(cairoGraphics, width, height, nux::color::White);
236 DrawText(_cairoGraphics, width, height, nux::color::White * 0.0f);105 DrawText(cairoGraphics, width, height, nux::color::White * 0.0f);
237106
238 if (_prelightTexture[0])107 _prelightTexture[0].Adopt(texture_from_cairo_graphics(cairoGraphics));
239 _prelightTexture[0]->UnReference();
240
241 _prelightTexture[0] = texture_from_cairo_graphics(*_cairoGraphics);
242108
243 // draw active/prelight, checked version109 // draw active/prelight, checked version
244 cairo_set_operator(cr, CAIRO_OPERATOR_CLEAR);110 cairo_set_operator(cr, CAIRO_OPERATOR_CLEAR);
245 cairo_paint(cr);111 cairo_paint(cr);
246112
247 DrawPrelight(_cairoGraphics, width, height, nux::color::White);113 DrawPrelight(cairoGraphics, width, height, nux::color::White);
248114
249 cairo_set_source_rgba(cr, 0.0f, 0.0f, 0.0f, 0.0f);115 cairo_set_source_rgba(cr, 0.0f, 0.0f, 0.0f, 0.0f);
250116
251 cairo_save(cr);117 cairo_save(cr);
252 cairo_translate(cr,118 cairo_translate(cr, Align((ITEM_INDENT_ABS - 16.0f + ITEM_MARGIN) / 2.0f),
253 _align((ITEM_INDENT_ABS - 16.0f + ITEM_MARGIN) / 2.0f),119 Align((static_cast<double>(height) - 16.0f) / 2.0f));
254 _align(((double) height - 16.0f) / 2.0f));
255120
256 cairo_translate(cr, 3.0f, 1.0f);121 cairo_translate(cr, 3.0f, 1.0f);
257 cairo_move_to(cr, 0.0f, 6.0f);122 cairo_move_to(cr, 0.0f, 6.0f);
@@ -268,24 +133,9 @@
268133
269 cairo_restore(cr);134 cairo_restore(cr);
270135
271 DrawText(_cairoGraphics, width, height, nux::color::White * 0.0f);136 DrawText(cairoGraphics, width, height, nux::color::White * 0.0f);
272137
273 if (_prelightTexture[1])138 _prelightTexture[1].Adopt(texture_from_cairo_graphics(cairoGraphics));
274 _prelightTexture[1]->UnReference();
275
276 _prelightTexture[1] = texture_from_cairo_graphics(*_cairoGraphics);
277
278 // finally clean up
279 cairo_destroy(cr);
280 delete _cairoGraphics;
281}
282
283int QuicklistMenuItemCheckmark::CairoSurfaceWidth()
284{
285 if (_normalTexture[0])
286 return _normalTexture[0]->GetWidth();
287
288 return 0;
289}139}
290140
291}141}
292142
=== modified file 'launcher/QuicklistMenuItemCheckmark.h'
--- launcher/QuicklistMenuItemCheckmark.h 2012-05-25 20:49:27 +0000
+++ launcher/QuicklistMenuItemCheckmark.h 2012-08-13 14:28:23 +0000
@@ -15,51 +15,28 @@
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
16 *16 *
17 * Authored by: Mirco Müller <mirco.mueller@canonical.com>17 * Authored by: Mirco Müller <mirco.mueller@canonical.com>
18 * Authored by: Jay Taoko <jay.taoko@canonical.com>18 * Jay Taoko <jay.taoko@canonical.com>
19 * Marco Trevisan <marco.trevisan@canonical.com>
19 */20 */
2021
21#ifndef QUICKLISTMENUITEMCHECKMARK_H22#ifndef QUICKLISTMENUITEMCHECKMARK_H
22#define QUICKLISTMENUITEMCHECKMARK_H23#define QUICKLISTMENUITEMCHECKMARK_H
2324
24#include <Nux/Nux.h>
25#include <Nux/View.h>
26#include <NuxGraphics/CairoGraphics.h>
27
28#include "QuicklistMenuItem.h"25#include "QuicklistMenuItem.h"
2926
30#include <X11/Xlib.h>
31
32namespace unity27namespace unity
33{28{
3429
35class QuicklistMenuItemCheckmark : public QuicklistMenuItem30class QuicklistMenuItemCheckmark : public QuicklistMenuItem
36{31{
37public:32public:
38 QuicklistMenuItemCheckmark(DbusmenuMenuitem* item,33 QuicklistMenuItemCheckmark(DbusmenuMenuitem* item, NUX_FILE_LINE_PROTO);
39 NUX_FILE_LINE_PROTO);
40
41 QuicklistMenuItemCheckmark(DbusmenuMenuitem* item,
42 bool debug,
43 NUX_FILE_LINE_PROTO);
44
45 ~QuicklistMenuItemCheckmark();
4634
47protected:35protected:
4836 std::string GetName() const;
49 void PreLayoutManagement();37
5038 virtual std::string GetDefaultText() const;
51 long PostLayoutManagement(long layoutResult);
52
53 void Draw(nux::GraphicsEngine& gfxContext, bool forceDraw);
54
55 void DrawContent(nux::GraphicsEngine& gfxContext, bool forceDraw);
56
57 void PostDraw(nux::GraphicsEngine& gfxContext, bool forceDraw);
58
59 virtual const gchar* GetDefaultText();
60
61 virtual void UpdateTexture();39 virtual void UpdateTexture();
62 virtual int CairoSurfaceWidth();
63};40};
6441
65} // NAMESPACE42} // NAMESPACE
6643
=== modified file 'launcher/QuicklistMenuItemLabel.cpp'
--- launcher/QuicklistMenuItemLabel.cpp 2012-05-07 22:28:17 +0000
+++ launcher/QuicklistMenuItemLabel.cpp 2012-08-13 14:28:23 +0000
@@ -1,6 +1,6 @@
1// -*- Mode: C++; indent-tabs-mode: nil; tab-width: 2 -*-1// -*- Mode: C++; indent-tabs-mode: nil; tab-width: 2 -*-
2/*2/*
3 * Copyright (C) 2010 Canonical Ltd3 * Copyright (C) 2010-2012 Canonical Ltd
4 *4 *
5 * This program is free software: you can redistribute it and/or modify5 * 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 as6 * it under the terms of the GNU General Public License version 3 as
@@ -15,197 +15,57 @@
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
16 *16 *
17 * Authored by: Mirco Müller <mirco.mueller@canonical.com>17 * Authored by: Mirco Müller <mirco.mueller@canonical.com>
18 * Authored by: Jay Taoko <jay.taoko@canonical.com>18 * Jay Taoko <jay.taoko@canonical.com>
19 * Marco Trevisan <marco.trevisan@canonical.com>
19 */20 */
2021
21#include <gdk/gdk.h>
22#include <gtk/gtk.h>
23
24#include <Nux/Nux.h>
25
26#include "unity-shared/CairoTexture.h"22#include "unity-shared/CairoTexture.h"
27#include "QuicklistMenuItemLabel.h"23#include "QuicklistMenuItemLabel.h"
2824
29namespace unity25namespace unity
30{26{
3127
32QuicklistMenuItemLabel::QuicklistMenuItemLabel(DbusmenuMenuitem* item,28QuicklistMenuItemLabel::QuicklistMenuItemLabel(DbusmenuMenuitem* item, NUX_FILE_LINE_DECL)
33 NUX_FILE_LINE_DECL) :29 : QuicklistMenuItem(QuicklistMenuItemType::LABEL, item, NUX_FILE_LINE_PARAM)
34 QuicklistMenuItem(item,30{
35 NUX_FILE_LINE_PARAM)31 InitializeText();
36{32}
37 _item_type = MENUITEM_TYPE_LABEL;33
38 _name = "QuicklistMenuItemLabel";34std::string QuicklistMenuItemLabel::GetDefaultText() const
39 InitializeText();
40}
41
42QuicklistMenuItemLabel::QuicklistMenuItemLabel(DbusmenuMenuitem* item,
43 bool debug,
44 NUX_FILE_LINE_DECL) :
45 QuicklistMenuItem(item,
46 debug,
47 NUX_FILE_LINE_PARAM)
48{
49 _item_type = MENUITEM_TYPE_LABEL;
50 _name = "QuicklistMenuItemLabel";
51 InitializeText();
52}
53
54QuicklistMenuItemLabel::~QuicklistMenuItemLabel()
55{}
56
57const gchar*
58QuicklistMenuItemLabel::GetDefaultText()
59{35{
60 return "Label";36 return "Label";
61}37}
6238
63void39std::string QuicklistMenuItemLabel::GetName() const
64QuicklistMenuItemLabel::PreLayoutManagement()40{
65{41 return "QuicklistMenuItemLabel";
66 _pre_layout_width = GetBaseWidth();42}
67 _pre_layout_height = GetBaseHeight();43
6844void QuicklistMenuItemLabel::UpdateTexture()
69 if (_normalTexture[0] == 0)45{
70 {46 int width = GetBaseWidth();
71 UpdateTexture();47 int height = GetBaseHeight();
72 }48
7349 nux::CairoGraphics cairoGraphics(CAIRO_FORMAT_ARGB32, width, height);
74 QuicklistMenuItem::PreLayoutManagement();50 std::shared_ptr<cairo_t> cairo_context(cairoGraphics.GetContext(), cairo_destroy);
75}51 cairo_t* cr = cairo_context.get();
76
77long
78QuicklistMenuItemLabel::PostLayoutManagement(long layoutResult)
79{
80 int w = GetBaseWidth();
81 int h = GetBaseHeight();
82
83 long result = 0;
84
85 if (_pre_layout_width < w)
86 result |= nux::eLargerWidth;
87 else if (_pre_layout_width > w)
88 result |= nux::eSmallerWidth;
89 else
90 result |= nux::eCompliantWidth;
91
92 if (_pre_layout_height < h)
93 result |= nux::eLargerHeight;
94 else if (_pre_layout_height > h)
95 result |= nux::eSmallerHeight;
96 else
97 result |= nux::eCompliantHeight;
98
99 return result;
100}
101
102void
103QuicklistMenuItemLabel::Draw(nux::GraphicsEngine& gfxContext,
104 bool forceDraw)
105{
106 // Check if the texture have been computed. If they haven't, exit the function.
107 if (_normalTexture[0] == NULL)
108 return;
109
110 nux::ObjectPtr<nux::IOpenGLBaseTexture> texture;
111
112 nux::Geometry base = GetGeometry();
113
114 gfxContext.PushClippingRectangle(base);
115
116 nux::TexCoordXForm texxform;
117 texxform.SetWrap(nux::TEXWRAP_REPEAT, nux::TEXWRAP_REPEAT);
118 texxform.SetTexCoordType(nux::TexCoordXForm::OFFSET_COORD);
119
120 gfxContext.GetRenderStates().SetBlend(true);
121 gfxContext.GetRenderStates().SetPremultipliedBlend(nux::SRC_OVER);
122
123 if (GetEnabled())
124 {
125 if (_prelight)
126 {
127 texture = _prelightTexture[0]->GetDeviceTexture();
128 }
129 else
130 {
131 texture = _normalTexture[0]->GetDeviceTexture();
132 }
133 _color = nux::color::White;
134 }
135 else
136 {
137 texture = _normalTexture[0]->GetDeviceTexture();
138 _color = nux::color::White * 0.35;
139 }
140
141 gfxContext.QRP_1Tex(base.x,
142 base.y,
143 base.width,
144 base.height,
145 texture,
146 texxform,
147 _color);
148
149 gfxContext.GetRenderStates().SetBlend(false);
150
151 gfxContext.PopClippingRectangle();
152}
153
154void
155QuicklistMenuItemLabel::DrawContent(nux::GraphicsEngine& gfxContext,
156 bool forceDraw)
157{
158}
159
160void
161QuicklistMenuItemLabel::PostDraw(nux::GraphicsEngine& gfxContext,
162 bool forceDraw)
163{
164}
165
166void
167QuicklistMenuItemLabel::UpdateTexture()
168{
169 int width = GetBaseWidth();
170 int height = GetBaseHeight();
171
172 _cairoGraphics = new nux::CairoGraphics(CAIRO_FORMAT_ARGB32, width, height);
173 cairo_t* cr = _cairoGraphics->GetContext();
17452
175 // draw normal, unchecked version53 // draw normal, unchecked version
176 cairo_set_operator(cr, CAIRO_OPERATOR_CLEAR);54 cairo_set_operator(cr, CAIRO_OPERATOR_CLEAR);
177 cairo_paint(cr);55 cairo_paint(cr);
17856
179 DrawText(_cairoGraphics, width, height, nux::color::White);57 DrawText(cairoGraphics, width, height, nux::color::White);
18058
181 if (_normalTexture[0])59 _normalTexture[0].Adopt(texture_from_cairo_graphics(cairoGraphics));
182 _normalTexture[0]->UnReference();
183
184 _normalTexture[0] = texture_from_cairo_graphics(*_cairoGraphics);
18560
186 // draw active/prelight, unchecked version61 // draw active/prelight, unchecked version
187 cairo_set_operator(cr, CAIRO_OPERATOR_CLEAR);62 cairo_set_operator(cr, CAIRO_OPERATOR_CLEAR);
188 cairo_paint(cr);63 cairo_paint(cr);
18964
190 DrawPrelight(_cairoGraphics, width, height, nux::color::White);65 DrawPrelight(cairoGraphics, width, height, nux::color::White);
191 DrawText(_cairoGraphics, width, height, nux::color::White * 0.0f);66 DrawText(cairoGraphics, width, height, nux::color::White * 0.0f);
19267
193 if (_prelightTexture[0])68 _prelightTexture[0].Adopt(texture_from_cairo_graphics(cairoGraphics));
194 _prelightTexture[0]->UnReference();
195
196 _prelightTexture[0] = texture_from_cairo_graphics(*_cairoGraphics);
197
198 // finally clean up
199 cairo_destroy(cr);
200 delete _cairoGraphics;
201}
202
203int QuicklistMenuItemLabel::CairoSurfaceWidth()
204{
205 if (_normalTexture[0])
206 return _normalTexture[0]->GetWidth();
207
208 return 0;
209}69}
21070
211} // NAMESPACE71} // NAMESPACE
21272
=== modified file 'launcher/QuicklistMenuItemLabel.h'
--- launcher/QuicklistMenuItemLabel.h 2012-05-25 20:49:27 +0000
+++ launcher/QuicklistMenuItemLabel.h 2012-08-13 14:28:23 +0000
@@ -15,51 +15,28 @@
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
16 *16 *
17 * Authored by: Mirco Müller <mirco.mueller@canonical.com>17 * Authored by: Mirco Müller <mirco.mueller@canonical.com>
18 * Authored by: Jay Taoko <jay.taoko@canonical.com>18 * Jay Taoko <jay.taoko@canonical.com>
19 * Marco Trevisan <marco.trevisan@canonical.com>
19 */20 */
2021
21#ifndef QUICKLISTMENUITEMLABEL_H22#ifndef QUICKLISTMENUITEMLABEL_H
22#define QUICKLISTMENUITEMLABEL_H23#define QUICKLISTMENUITEMLABEL_H
2324
24#include <Nux/Nux.h>
25#include <Nux/View.h>
26#include <NuxGraphics/CairoGraphics.h>
27
28#include "QuicklistMenuItem.h"25#include "QuicklistMenuItem.h"
2926
30#include <X11/Xlib.h>
31
32namespace unity27namespace unity
33{28{
3429
35class QuicklistMenuItemLabel : public QuicklistMenuItem30class QuicklistMenuItemLabel : public QuicklistMenuItem
36{31{
37public:32public:
38 QuicklistMenuItemLabel(DbusmenuMenuitem* item,33 QuicklistMenuItemLabel(DbusmenuMenuitem* item, NUX_FILE_LINE_PROTO);
39 NUX_FILE_LINE_PROTO);
40
41 QuicklistMenuItemLabel(DbusmenuMenuitem* item,
42 bool debug,
43 NUX_FILE_LINE_PROTO);
44
45 ~QuicklistMenuItemLabel();
4634
47protected:35protected:
4836 std::string GetName() const;
49 void PreLayoutManagement();37
5038 virtual std::string GetDefaultText() const;
51 long PostLayoutManagement(long layoutResult);
52
53 void Draw(nux::GraphicsEngine& gfxContext, bool forceDraw);
54
55 void DrawContent(nux::GraphicsEngine& gfxContext, bool forceDraw);
56
57 void PostDraw(nux::GraphicsEngine& gfxContext, bool forceDraw);
58
59 virtual const gchar* GetDefaultText();
60
61 virtual void UpdateTexture();39 virtual void UpdateTexture();
62 virtual int CairoSurfaceWidth();
63};40};
6441
65} // NAMESPACE42} // NAMESPACE
6643
=== modified file 'launcher/QuicklistMenuItemRadio.cpp'
--- launcher/QuicklistMenuItemRadio.cpp 2012-05-07 22:28:17 +0000
+++ launcher/QuicklistMenuItemRadio.cpp 2012-08-13 14:28:23 +0000
@@ -1,6 +1,6 @@
1// -*- Mode: C++; indent-tabs-mode: nil; tab-width: 2 -*-1// -*- Mode: C++; indent-tabs-mode: nil; tab-width: 2 -*-
2/*2/*
3 * Copyright (C) 2010 Canonical Ltd3 * Copyright (C) 2010-2012 Canonical Ltd
4 *4 *
5 * This program is free software: you can redistribute it and/or modify5 * 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 as6 * it under the terms of the GNU General Public License version 3 as
@@ -15,177 +15,47 @@
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
16 *16 *
17 * Authored by: Mirco Müller <mirco.mueller@canonical.com>17 * Authored by: Mirco Müller <mirco.mueller@canonical.com>
18 * Marco Trevisan <marco.trevisan@canonical.com>
18 */19 */
1920
20#include <gdk/gdk.h>
21#include <gtk/gtk.h>
22
23#include <Nux/Nux.h>
24
25#include "unity-shared/CairoTexture.h"21#include "unity-shared/CairoTexture.h"
26#include "QuicklistMenuItemRadio.h"22#include "QuicklistMenuItemRadio.h"
2723
28namespace unity24namespace unity
29{25{
3026
31static double27QuicklistMenuItemRadio::QuicklistMenuItemRadio(DbusmenuMenuitem* item, NUX_FILE_LINE_DECL)
32_align(double val)28 : QuicklistMenuItem(QuicklistMenuItemType::RADIO, item, NUX_FILE_LINE_PARAM)
33{29{
34 double fract = val - (int) val;30 InitializeText();
3531}
36 if (fract != 0.5f)32
37 return (double)((int) val + 0.5f);33std::string QuicklistMenuItemRadio::GetDefaultText() const
38 else
39 return val;
40}
41
42QuicklistMenuItemRadio::QuicklistMenuItemRadio(DbusmenuMenuitem* item,
43 NUX_FILE_LINE_DECL) :
44 QuicklistMenuItem(item,
45 NUX_FILE_LINE_PARAM)
46{
47 _item_type = MENUITEM_TYPE_RADIO;
48 _name = "QuicklistMenuItemRadio";
49 InitializeText();
50}
51
52QuicklistMenuItemRadio::QuicklistMenuItemRadio(DbusmenuMenuitem* item,
53 bool debug,
54 NUX_FILE_LINE_DECL) :
55 QuicklistMenuItem(item,
56 debug,
57 NUX_FILE_LINE_PARAM)
58{
59 _item_type = MENUITEM_TYPE_RADIO;
60 _name = "QuicklistMenuItemRadio";
61 InitializeText();
62}
63
64QuicklistMenuItemRadio::~QuicklistMenuItemRadio()
65{}
66
67const gchar*
68QuicklistMenuItemRadio::GetDefaultText()
69{34{
70 return "Radio Button";35 return "Radio Button";
71}36}
7237
73void38std::string QuicklistMenuItemRadio::GetName() const
74QuicklistMenuItemRadio::PreLayoutManagement()39{
75{40 return "QuicklistMenuItemRadio";
76 _pre_layout_width = GetBaseWidth();41}
77 _pre_layout_height = GetBaseHeight();42
7843void QuicklistMenuItemRadio::UpdateTexture()
79 if (_normalTexture[0] == 0)44{
80 {45 int width = GetBaseWidth();
81 UpdateTexture();46 int height = GetBaseHeight();
82 }47
8348 nux::CairoGraphics cairoGraphics(CAIRO_FORMAT_ARGB32, width, height);
84 QuicklistMenuItem::PreLayoutManagement();49 std::shared_ptr<cairo_t> cairo_context(cairoGraphics.GetContext(), cairo_destroy);
85}50 cairo_t* cr = cairo_context.get();
86
87long
88QuicklistMenuItemRadio::PostLayoutManagement(long layoutResult)
89{
90 int w = GetBaseWidth();
91 int h = GetBaseHeight();
92
93 long result = 0;
94
95 if (_pre_layout_width < w)
96 result |= nux::eLargerWidth;
97 else if (_pre_layout_width > w)
98 result |= nux::eSmallerWidth;
99 else
100 result |= nux::eCompliantWidth;
101
102 if (_pre_layout_height < h)
103 result |= nux::eLargerHeight;
104 else if (_pre_layout_height > h)
105 result |= nux::eSmallerHeight;
106 else
107 result |= nux::eCompliantHeight;
108
109 return result;
110}
111
112void
113QuicklistMenuItemRadio::Draw(nux::GraphicsEngine& gfxContext, bool forceDraw)
114{
115 nux::ObjectPtr<nux::IOpenGLBaseTexture> texture;
116
117 // Check if the texture have been computed. If they haven't, exit the function.
118 if (!_normalTexture[0] || !_prelightTexture[0])
119 return;
120
121 nux::Geometry base = GetGeometry();
122
123 gfxContext.PushClippingRectangle(base);
124
125 nux::TexCoordXForm texxform;
126 texxform.SetWrap(nux::TEXWRAP_REPEAT, nux::TEXWRAP_REPEAT);
127 texxform.SetTexCoordType(nux::TexCoordXForm::OFFSET_COORD);
128
129 gfxContext.GetRenderStates().SetBlend(true);
130 gfxContext.GetRenderStates().SetPremultipliedBlend(nux::SRC_OVER);
131
132 unsigned int texture_idx = GetActive() ? 1 : 0;
133
134 if (!_prelight || !GetEnabled())
135 {
136 texture = _normalTexture[texture_idx]->GetDeviceTexture();
137 }
138 else
139 {
140 texture = _prelightTexture[texture_idx]->GetDeviceTexture();
141 }
142
143 _color = GetEnabled() ? nux::color::White : nux::color::White * 0.35;
144
145 gfxContext.QRP_1Tex(base.x,
146 base.y,
147 base.width,
148 base.height,
149 texture,
150 texxform,
151 _color);
152
153 gfxContext.GetRenderStates().SetBlend(false);
154
155 gfxContext.PopClippingRectangle();
156}
157
158void
159QuicklistMenuItemRadio::DrawContent(nux::GraphicsEngine& gfxContext,
160 bool forceDraw)
161{
162}
163
164void
165QuicklistMenuItemRadio::PostDraw(nux::GraphicsEngine& gfxContext,
166 bool forceDraw)
167{
168}
169
170void
171QuicklistMenuItemRadio::UpdateTexture()
172{
173 int width = GetBaseWidth();
174 int height = GetBaseHeight();
175
176 _cairoGraphics = new nux::CairoGraphics(CAIRO_FORMAT_ARGB32, width, height);
177 cairo_t* cr = _cairoGraphics->GetContext();
17851
179 // draw normal, disabled version52 // draw normal, disabled version
180 cairo_set_operator(cr, CAIRO_OPERATOR_CLEAR);53 cairo_set_operator(cr, CAIRO_OPERATOR_CLEAR);
181 cairo_paint(cr);54 cairo_paint(cr);
18255
183 DrawText(_cairoGraphics, width, height, nux::color::White);56 DrawText(cairoGraphics, width, height, nux::color::White);
18457
185 if (_normalTexture[0])58 _normalTexture[0].Adopt(texture_from_cairo_graphics(cairoGraphics));
186 _normalTexture[0]->UnReference();
187
188 _normalTexture[0] = texture_from_cairo_graphics(*_cairoGraphics);
18959
190 // draw normal, enabled version60 // draw normal, enabled version
191 cairo_set_operator(cr, CAIRO_OPERATOR_CLEAR);61 cairo_set_operator(cr, CAIRO_OPERATOR_CLEAR);
@@ -196,62 +66,41 @@
196 cairo_set_source_rgba(cr, 1.0f, 1.0f, 1.0f, 1.0f);66 cairo_set_source_rgba(cr, 1.0f, 1.0f, 1.0f, 1.0f);
197 cairo_set_line_width(cr, 1.0f);67 cairo_set_line_width(cr, 1.0f);
19868
199 double x = _align((ITEM_INDENT_ABS + ITEM_MARGIN) / 2.0f);69 double x = Align((ITEM_INDENT_ABS + ITEM_MARGIN) / 2.0f);
200 double y = _align((double) height / 2.0f);70 double y = Align(static_cast<double>(height) / 2.0f);
201 double radius = 3.5f;71 double radius = 3.5f;
20272
203 cairo_set_source_rgba(cr, 1.0f, 1.0f, 1.0f, 1.0f);73 cairo_set_source_rgba(cr, 1.0f, 1.0f, 1.0f, 1.0f);
204 cairo_arc(cr, x, y, radius, 0.0f * (G_PI / 180.0f), 360.0f * (G_PI / 180.0f));74 cairo_arc(cr, x, y, radius, 0.0f * (G_PI / 180.0f), 360.0f * (G_PI / 180.0f));
205 cairo_fill(cr);75 cairo_fill(cr);
20676
207 DrawText(_cairoGraphics, width, height, nux::color::White);77 DrawText(cairoGraphics, width, height, nux::color::White);
20878
209 if (_normalTexture[1])79 _normalTexture[1].Adopt(texture_from_cairo_graphics(cairoGraphics));
210 _normalTexture[1]->UnReference();80
21181 // draw active/prelight, unchecked version
212 _normalTexture[1] = texture_from_cairo_graphics(*_cairoGraphics);82 cairo_set_operator(cr, CAIRO_OPERATOR_CLEAR);
21383 cairo_paint(cr);
214 // draw active/prelight, unchecked version84
215 cairo_set_operator(cr, CAIRO_OPERATOR_CLEAR);85 DrawPrelight(cairoGraphics, width, height, nux::color::White);
216 cairo_paint(cr);86 DrawText(cairoGraphics, width, height, nux::color::White * 0.0f);
21787
218 DrawPrelight(_cairoGraphics, width, height, nux::color::White);88 _prelightTexture[0].Adopt(texture_from_cairo_graphics(cairoGraphics));
219 DrawText(_cairoGraphics, width, height, nux::color::White * 0.0f);89
22090 // draw active/prelight, unchecked version
221 if (_prelightTexture[0])91 cairo_set_operator(cr, CAIRO_OPERATOR_CLEAR);
222 _prelightTexture[0]->UnReference();92 cairo_paint(cr);
22393
224 _prelightTexture[0] = texture_from_cairo_graphics(*_cairoGraphics);94 DrawPrelight(cairoGraphics, width, height, nux::color::White);
225
226 // draw active/prelight, unchecked version
227 cairo_set_operator(cr, CAIRO_OPERATOR_CLEAR);
228 cairo_paint(cr);
229
230 DrawPrelight(_cairoGraphics, width, height, nux::color::White);
23195
232 cairo_set_source_rgba(cr, 0.0f, 0.0f, 0.0f, 0.0f);96 cairo_set_source_rgba(cr, 0.0f, 0.0f, 0.0f, 0.0f);
23397
234 cairo_arc(cr, x, y, radius, 0.0f * (G_PI / 180.0f), 360.0f * (G_PI / 180.0f));98 cairo_arc(cr, x, y, radius, 0.0f * (G_PI / 180.0f), 360.0f * (G_PI / 180.0f));
235 cairo_fill(cr);99 cairo_fill(cr);
236100
237 DrawText(_cairoGraphics, width, height, nux::color::White * 0.0f);101 DrawText(cairoGraphics, width, height, nux::color::White * 0.0f);
238102
239 if (_prelightTexture[1])103 _prelightTexture[1].Adopt(texture_from_cairo_graphics(cairoGraphics));
240 _prelightTexture[1]->UnReference();
241
242 _prelightTexture[1] = texture_from_cairo_graphics(*_cairoGraphics);
243
244 // finally clean up
245 cairo_destroy(cr);
246 delete _cairoGraphics;
247}
248
249int QuicklistMenuItemRadio::CairoSurfaceWidth()
250{
251 if (_normalTexture[0])
252 return _normalTexture[0]->GetWidth();
253
254 return 0;
255}104}
256105
257} // NAMESPACE106} // NAMESPACE
258107
=== modified file 'launcher/QuicklistMenuItemRadio.h'
--- launcher/QuicklistMenuItemRadio.h 2012-05-25 20:49:27 +0000
+++ launcher/QuicklistMenuItemRadio.h 2012-08-13 14:28:23 +0000
@@ -15,52 +15,27 @@
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
16 *16 *
17 * Authored by: Mirco Müller <mirco.mueller@canonical.com>17 * Authored by: Mirco Müller <mirco.mueller@canonical.com>
18 * Marco Trevisan <marco.trevisan@canonical.com>
18 */19 */
1920
20#ifndef QUICKLISTMENUITEMRADIO_H21#ifndef QUICKLISTMENUITEMRADIO_H
21#define QUICKLISTMENUITEMRADIO_H22#define QUICKLISTMENUITEMRADIO_H
2223
23#include <Nux/Nux.h>
24#include <Nux/View.h>
25#include <NuxGraphics/CairoGraphics.h>
26
27#include "QuicklistMenuItem.h"24#include "QuicklistMenuItem.h"
2825
29#include <X11/Xlib.h>
30
31namespace unity26namespace unity
32{27{
3328
34class QuicklistMenuItemRadio : public QuicklistMenuItem29class QuicklistMenuItemRadio : public QuicklistMenuItem
35{30{
36public:31public:
37 QuicklistMenuItemRadio(DbusmenuMenuitem* item,32 QuicklistMenuItemRadio(DbusmenuMenuitem* item, NUX_FILE_LINE_PROTO);
38 NUX_FILE_LINE_PROTO);
39
40 QuicklistMenuItemRadio(DbusmenuMenuitem* item,
41 bool debug,
42 NUX_FILE_LINE_PROTO);
43
44 ~QuicklistMenuItemRadio();
4533
46protected:34protected:
47 void PreLayoutManagement();35 std::string GetName() const;
4836
49 long PostLayoutManagement(long layoutResult);37 virtual std::string GetDefaultText() const;
50
51 void Draw(nux::GraphicsEngine& gfxContext,
52 bool forceDraw);
53
54 void DrawContent(nux::GraphicsEngine& gfxContext,
55 bool forceDraw);
56
57 void PostDraw(nux::GraphicsEngine& gfxContext,
58 bool forceDraw);
59
60 virtual const gchar* GetDefaultText();
61
62 virtual void UpdateTexture();38 virtual void UpdateTexture();
63 virtual int CairoSurfaceWidth();
64};39};
6540
66} //NAMESPACE41} //NAMESPACE
6742
=== modified file 'launcher/QuicklistMenuItemSeparator.cpp'
--- launcher/QuicklistMenuItemSeparator.cpp 2012-05-07 22:28:17 +0000
+++ launcher/QuicklistMenuItemSeparator.cpp 2012-08-13 14:28:23 +0000
@@ -1,6 +1,6 @@
1// -*- Mode: C++; indent-tabs-mode: nil; tab-width: 2 -*-1// -*- Mode: C++; indent-tabs-mode: nil; tab-width: 2 -*-
2/*2/*
3 * Copyright (C) 2010 Canonical Ltd3 * Copyright (C) 2010-2012 Canonical Ltd
4 *4 *
5 * This program is free software: you can redistribute it and/or modify5 * 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 as6 * it under the terms of the GNU General Public License version 3 as
@@ -15,104 +15,41 @@
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
16 *16 *
17 * Authored by: Mirco Müller <mirco.mueller@canonical.com>17 * Authored by: Mirco Müller <mirco.mueller@canonical.com>
18 * Marco Trevisan <marco.trevisan@canonical.com>
18 */19 */
1920
20#include <Nux/Nux.h>
21
22#include "unity-shared/CairoTexture.h"21#include "unity-shared/CairoTexture.h"
23#include "QuicklistMenuItemSeparator.h"22#include "QuicklistMenuItemSeparator.h"
2423
25namespace unity24namespace unity
26{25{
2726
28QuicklistMenuItemSeparator::QuicklistMenuItemSeparator(DbusmenuMenuitem* item,27QuicklistMenuItemSeparator::QuicklistMenuItemSeparator(DbusmenuMenuitem* item, NUX_FILE_LINE_DECL)
29 NUX_FILE_LINE_DECL) :28 : QuicklistMenuItem(QuicklistMenuItemType::SEPARATOR, item, NUX_FILE_LINE_PARAM)
30 QuicklistMenuItem(item,29 , _color(1.0f, 1.0f, 1.0f, 0.5f)
31 NUX_FILE_LINE_PARAM)30 , _premultiplied_color(0.5f, 0.5f, 0.5f, 0.5f)
32{31{
33 _name = "QuicklistMenuItemSeparator";32 SetMinimumHeight(7);
34 SetMinimumHeight(7);33 SetBaseSize(64, 7);
35 SetBaseSize(64, 7);34}
3635
37 _color = nux::Color(1.0f, 1.0f, 1.0f, 0.5f);36std::string QuicklistMenuItemSeparator::GetName() const
38 _premultiplied_color = nux::Color(0.5f, 0.5f, 0.5f, 0.5f);37{
39 _item_type = MENUITEM_TYPE_SEPARATOR;38 return "QuicklistMenuItemSeparator";
40}39}
4140
42QuicklistMenuItemSeparator::QuicklistMenuItemSeparator(DbusmenuMenuitem* item,41bool QuicklistMenuItemSeparator::GetSelectable()
43 bool debug,
44 NUX_FILE_LINE_DECL) :
45 QuicklistMenuItem(item,
46 debug,
47 NUX_FILE_LINE_PARAM)
48{
49 _name = "QuicklistMenuItemSeparator";
50 SetMinimumHeight(7);
51 SetBaseSize(64, 7);
52 //_normalTexture = NULL;
53 _color = nux::Color(1.0f, 1.0f, 1.0f, 0.5f);
54 _premultiplied_color = nux::Color(0.5f, 0.5f, 0.5f, 0.5f);
55 _item_type = MENUITEM_TYPE_SEPARATOR;
56}
57
58QuicklistMenuItemSeparator::~QuicklistMenuItemSeparator()
59{
60}
61
62bool
63QuicklistMenuItemSeparator::GetSelectable()
64{42{
65 return false;43 return false;
66}44}
6745
68void46void QuicklistMenuItemSeparator::Draw(nux::GraphicsEngine& gfxContext, bool forceDraw)
69QuicklistMenuItemSeparator::PreLayoutManagement()
70{
71 _pre_layout_width = GetBaseWidth();
72 _pre_layout_height = GetBaseHeight();
73
74 if ((_normalTexture[0] == 0))
75 {
76 UpdateTexture();
77 }
78
79 QuicklistMenuItem::PreLayoutManagement();
80}
81
82long
83QuicklistMenuItemSeparator::PostLayoutManagement(long layoutResult)
84{
85 int w = GetBaseWidth();
86 int h = GetBaseHeight();
87
88 long result = 0;
89
90 if (_pre_layout_width < w)
91 result |= nux::eLargerWidth;
92 else if (_pre_layout_width > w)
93 result |= nux::eSmallerWidth;
94 else
95 result |= nux::eCompliantWidth;
96
97 if (_pre_layout_height < h)
98 result |= nux::eLargerHeight;
99 else if (_pre_layout_height > h)
100 result |= nux::eSmallerHeight;
101 else
102 result |= nux::eCompliantHeight;
103
104 return result;
105}
106
107void
108QuicklistMenuItemSeparator::Draw(nux::GraphicsEngine& gfxContext,
109 bool forceDraw)
110{47{
111 // Check if the texture have been computed. If they haven't, exit the function.48 // Check if the texture have been computed. If they haven't, exit the function.
112 if (_normalTexture[0] == 0)49 if (!_normalTexture[0])
113 return;50 return;
11451
115 nux::Geometry base = GetGeometry();52 nux::Geometry const& base = GetGeometry();
11653
117 gfxContext.PushClippingRectangle(base);54 gfxContext.PushClippingRectangle(base);
11855
@@ -123,39 +60,21 @@
123 gfxContext.GetRenderStates().SetBlend(true);60 gfxContext.GetRenderStates().SetBlend(true);
124 gfxContext.GetRenderStates().SetPremultipliedBlend(nux::SRC_OVER);61 gfxContext.GetRenderStates().SetPremultipliedBlend(nux::SRC_OVER);
12562
126 gfxContext.QRP_1Tex(base.x,63 auto const& texture = _normalTexture[0]->GetDeviceTexture();
127 base.y,64 gfxContext.QRP_1Tex(base.x, base.y, base.width, base.height, texture, texxform, _premultiplied_color);
128 base.width,
129 base.height,
130 _normalTexture[0]->GetDeviceTexture(),
131 texxform,
132 _premultiplied_color);
13365
134 gfxContext.GetRenderStates().SetBlend(false);66 gfxContext.GetRenderStates().SetBlend(false);
135
136 gfxContext.PopClippingRectangle();67 gfxContext.PopClippingRectangle();
137}68}
13869
139void70void QuicklistMenuItemSeparator::UpdateTexture()
140QuicklistMenuItemSeparator::DrawContent(nux::GraphicsEngine& gfxContext,71{
141 bool forceDraw)72 int width = GetBaseWidth();
142{73 int height = GetBaseHeight();
143}74
14475 nux::CairoGraphics cairoGraphics(CAIRO_FORMAT_ARGB32, width, height);
145void76 std::shared_ptr<cairo_t> cairo_context(cairoGraphics.GetContext(), cairo_destroy);
146QuicklistMenuItemSeparator::PostDraw(nux::GraphicsEngine& gfxContext,77 cairo_t* cr = cairo_context.get();
147 bool forceDraw)
148{
149}
150
151void
152QuicklistMenuItemSeparator::UpdateTexture()
153{
154 int width = GetBaseWidth();
155 int height = GetBaseHeight();
156
157 _cairoGraphics = new nux::CairoGraphics(CAIRO_FORMAT_ARGB32, width, height);
158 cairo_t* cr = _cairoGraphics->GetContext();
15978
160 cairo_set_operator(cr, CAIRO_OPERATOR_SOURCE);79 cairo_set_operator(cr, CAIRO_OPERATOR_SOURCE);
161 cairo_set_source_rgba(cr, 0.0f, 0.0f, 0.0f, 0.0f);80 cairo_set_source_rgba(cr, 0.0f, 0.0f, 0.0f, 0.0f);
@@ -166,21 +85,7 @@
166 cairo_line_to(cr, width, 3.5f);85 cairo_line_to(cr, width, 3.5f);
167 cairo_stroke(cr);86 cairo_stroke(cr);
16887
169 if (_normalTexture[0])88 _normalTexture[0].Adopt(texture_from_cairo_graphics(cairoGraphics));
170 _normalTexture[0]->UnReference();
171
172 _normalTexture[0] = texture_from_cairo_graphics(*_cairoGraphics);
173
174 cairo_destroy(cr);
175 delete _cairoGraphics;
176}
177
178int QuicklistMenuItemSeparator::CairoSurfaceWidth()
179{
180 if (_normalTexture[0])
181 return _normalTexture[0]->GetWidth();
182
183 return 0;
184}89}
18590
186}91}
18792
=== modified file 'launcher/QuicklistMenuItemSeparator.h'
--- launcher/QuicklistMenuItemSeparator.h 2012-05-25 20:49:27 +0000
+++ launcher/QuicklistMenuItemSeparator.h 2012-08-13 14:28:23 +0000
@@ -15,57 +15,32 @@
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
16 *16 *
17 * Authored by: Mirco Müller <mirco.mueller@canonical.com>17 * Authored by: Mirco Müller <mirco.mueller@canonical.com>
18 * Marco Trevisan <marco.trevisan@canonical.com>
18 */19 */
1920
20#ifndef QUICKLISTMENUITEMSEPARATOR_H21#ifndef QUICKLISTMENUITEMSEPARATOR_H
21#define QUICKLISTMENUITEMSEPARATOR_H22#define QUICKLISTMENUITEMSEPARATOR_H
2223
23#include <Nux/Nux.h>
24#include <Nux/View.h>
25#include <NuxGraphics/CairoGraphics.h>
26
27#include "QuicklistMenuItem.h"24#include "QuicklistMenuItem.h"
2825
29#include <X11/Xlib.h>
30
31namespace unity26namespace unity
32{27{
3328
34class QuicklistMenuItemSeparator : public QuicklistMenuItem29class QuicklistMenuItemSeparator : public QuicklistMenuItem
35{30{
36public:31public:
37 QuicklistMenuItemSeparator(DbusmenuMenuitem* item,32 QuicklistMenuItemSeparator(DbusmenuMenuitem* item, NUX_FILE_LINE_PROTO);
38 NUX_FILE_LINE_PROTO);
39
40 QuicklistMenuItemSeparator(DbusmenuMenuitem* item,
41 bool debug,
42 NUX_FILE_LINE_PROTO);
43
44 ~QuicklistMenuItemSeparator();
4533
46 virtual bool GetSelectable();34 virtual bool GetSelectable();
4735
48protected:36protected:
49
50 void PreLayoutManagement();
51
52 long PostLayoutManagement(long layoutResult);
53
54 void Draw(nux::GraphicsEngine& gfxContext, bool forceDraw);37 void Draw(nux::GraphicsEngine& gfxContext, bool forceDraw);
5538 std::string GetName() const;
56 void DrawContent(nux::GraphicsEngine& gfxContext, bool forceDraw);
57
58 void PostDraw(nux::GraphicsEngine& gfxContext, bool forceDraw);
5939
60 virtual void UpdateTexture();40 virtual void UpdateTexture();
6141
62 //! Returns the width of the separator line as defined by the size of the _normalTexture.
63 virtual int CairoSurfaceWidth();
64
65 friend class QuicklistView;
66
67private:42private:
6843 nux::Color _color;
69 nux::Color _premultiplied_color;44 nux::Color _premultiplied_color;
70};45};
7146
7247
=== modified file 'launcher/QuicklistView.cpp'
--- launcher/QuicklistView.cpp 2012-07-25 16:00:26 +0000
+++ launcher/QuicklistView.cpp 2012-08-13 14:28:23 +0000
@@ -147,7 +147,7 @@
147 if (menu_item)147 if (menu_item)
148 {148 {
149 target_item = index;149 target_item = index;
150 menu_item->_prelight = true;150 menu_item->Select();
151 }151 }
152 }152 }
153153
@@ -448,13 +448,9 @@
448 _item_layout->AddView(item, 1, nux::eCenter, nux::eFull);448 _item_layout->AddView(item, 1, nux::eCenter, nux::eFull);
449 }449 }
450450
451 int textWidth = 0;451 nux::Size const& text_extents = item->GetTextExtents();
452 int textHeight = 0;452 MaxItemWidth = std::max(MaxItemWidth, text_extents.width);
453 item->GetTextExtents(textWidth, textHeight);453 TotalItemHeight += text_extents.height;
454 textHeight += QuicklistMenuItem::ITEM_MARGIN * 2;
455
456 MaxItemWidth = std::max(MaxItemWidth, textWidth);
457 TotalItemHeight += textHeight;
458 }454 }
459455
460 if (TotalItemHeight < _anchor_height)456 if (TotalItemHeight < _anchor_height)
@@ -510,11 +506,11 @@
510 // only after MaxItemWidth is computed in QuicklistView::PreLayoutManagement.506 // only after MaxItemWidth is computed in QuicklistView::PreLayoutManagement.
511 // The setting of the separator width is done here after the Layout cycle for this widget is over. The width of the separator507 // The setting of the separator width is done here after the Layout cycle for this widget is over. The width of the separator
512 // has bee set correctly during the layout cycle, but the cairo rendering still need to be adjusted.508 // has bee set correctly during the layout cycle, but the cairo rendering still need to be adjusted.
513 int separator_width = _item_layout->GetBaseWidth();509 unsigned separator_width = _item_layout->GetBaseWidth();
514510
515 for (auto item : _item_list)511 for (auto item : _item_list)
516 {512 {
517 if (item->GetVisible() && item->CairoSurfaceWidth() != separator_width)513 if (item->GetVisible() && item->GetCairoSurfaceWidth() != separator_width)
518 {514 {
519 // Compute textures of the item.515 // Compute textures of the item.
520 item->UpdateTexture();516 item->UpdateTexture();
@@ -567,14 +563,10 @@
567563
568void QuicklistView::ActivateItem(QuicklistMenuItem* item)564void QuicklistView::ActivateItem(QuicklistMenuItem* item)
569{565{
570 if (item && item->_menuItem)566 if (!item)
571 {567 return;
572 ubus_server_send_message(ubus_server_get_default(),
573 UBUS_PLACE_VIEW_CLOSE_REQUEST,
574 NULL);
575568
576 dbusmenu_menuitem_handle_event(item->_menuItem, "clicked", NULL, 0);569 item->Activate();
577 }
578}570}
579571
580void QuicklistView::RecvItemMouseRelease(QuicklistMenuItem* item, int x, int y)572void QuicklistView::RecvItemMouseRelease(QuicklistMenuItem* item, int x, int y)
@@ -595,7 +587,7 @@
595{587{
596 for (auto item : _item_list)588 for (auto item : _item_list)
597 {589 {
598 item->_prelight = false;590 item->Select(false);
599 }591 }
600}592}
601593
@@ -760,7 +752,7 @@
760 if (item)752 if (item)
761 return item->GetItemType();753 return item->GetItemType();
762754
763 return MENUITEM_TYPE_UNKNOWN;755 return QuicklistMenuItemType::UNKNOWN;
764}756}
765757
766std::list<QuicklistMenuItem*> QuicklistView::GetChildren()758std::list<QuicklistMenuItem*> QuicklistView::GetChildren()
@@ -1310,42 +1302,6 @@
1310 UpdateTexture();1302 UpdateTexture();
1311}1303}
13121304
1313void QuicklistView::TestMenuItems(DbusmenuMenuitem* root)
1314{
1315 RemoveAllMenuItem();
1316
1317 if (root == 0)
1318 return;
1319
1320 GList* child = NULL;
1321 for (child = dbusmenu_menuitem_get_children(root); child != NULL; child = g_list_next(child))
1322 {
1323 const gchar* type = dbusmenu_menuitem_property_get((DbusmenuMenuitem*)child->data, DBUSMENU_MENUITEM_PROP_TYPE);
1324 const gchar* toggle_type = dbusmenu_menuitem_property_get((DbusmenuMenuitem*)child->data, DBUSMENU_MENUITEM_PROP_TOGGLE_TYPE);
1325
1326 if (g_strcmp0(type, DBUSMENU_CLIENT_TYPES_SEPARATOR) == 0)
1327 {
1328 QuicklistMenuItemSeparator* item = new QuicklistMenuItemSeparator((DbusmenuMenuitem*)child->data, NUX_TRACKER_LOCATION);
1329 AddMenuItem(item);
1330 }
1331 else if (g_strcmp0(toggle_type, DBUSMENU_MENUITEM_TOGGLE_CHECK) == 0)
1332 {
1333 QuicklistMenuItemCheckmark* item = new QuicklistMenuItemCheckmark((DbusmenuMenuitem*)child->data, NUX_TRACKER_LOCATION);
1334 AddMenuItem(item);
1335 }
1336 else if (g_strcmp0(toggle_type, DBUSMENU_MENUITEM_TOGGLE_RADIO) == 0)
1337 {
1338 QuicklistMenuItemRadio* item = new QuicklistMenuItemRadio((DbusmenuMenuitem*)child->data, NUX_TRACKER_LOCATION);
1339 AddMenuItem(item);
1340 }
1341 else //if (g_strcmp0 (type, DBUSMENU_MENUITEM_PROP_LABEL) == 0)
1342 {
1343 QuicklistMenuItemLabel* item = new QuicklistMenuItemLabel((DbusmenuMenuitem*)child->data, NUX_TRACKER_LOCATION);
1344 AddMenuItem(item);
1345 }
1346 }
1347}
1348
1349// Introspection1305// Introspection
13501306
1351std::string QuicklistView::GetName() const1307std::string QuicklistView::GetName() const
13521308
=== modified file 'launcher/QuicklistView.h'
--- launcher/QuicklistView.h 2012-07-11 06:21:46 +0000
+++ launcher/QuicklistView.h 2012-08-13 14:28:23 +0000
@@ -22,9 +22,11 @@
22#define QUICKLISTVIEW_H22#define QUICKLISTVIEW_H
2323
24#include <Nux/Nux.h>24#include <Nux/Nux.h>
25#include <Nux/VLayout.h>
26#include <Nux/HLayout.h>
25#include <Nux/BaseWindow.h>27#include <Nux/BaseWindow.h>
28#include <Nux/TextureArea.h>
26#include <NuxGraphics/GraphicsEngine.h>29#include <NuxGraphics/GraphicsEngine.h>
27#include <Nux/TextureArea.h>
28#include <NuxGraphics/CairoGraphics.h>30#include <NuxGraphics/CairoGraphics.h>
2931
30#include <pango/pango.h>32#include <pango/pango.h>
3133
=== modified file 'plugins/unityshell/src/unity-quicklist-menu-item-accessible.cpp'
--- plugins/unityshell/src/unity-quicklist-menu-item-accessible.cpp 2012-03-14 06:24:18 +0000
+++ plugins/unityshell/src/unity-quicklist-menu-item-accessible.cpp 2012-08-13 14:28:23 +0000
@@ -210,7 +210,7 @@
210 menu_item = dynamic_cast<QuicklistMenuItem*>(nux_object_accessible_get_object(NUX_OBJECT_ACCESSIBLE(obj)));210 menu_item = dynamic_cast<QuicklistMenuItem*>(nux_object_accessible_get_object(NUX_OBJECT_ACCESSIBLE(obj)));
211 if (menu_item != NULL)211 if (menu_item != NULL)
212 {212 {
213 name = menu_item->GetLabel();213 name = menu_item->GetLabel().c_str();
214 }214 }
215 }215 }
216216
217217
=== modified file 'tests/CMakeLists.txt'
--- tests/CMakeLists.txt 2012-08-03 09:57:41 +0000
+++ tests/CMakeLists.txt 2012-08-13 14:28:23 +0000
@@ -62,18 +62,11 @@
6262
63add_executable (test-unit63add_executable (test-unit
64 unit/TestMain.cpp64 unit/TestMain.cpp
65 unit/TestQuicklistMenuitems.cpp
66 unit/TestPanelService.cpp65 unit/TestPanelService.cpp
67 unit/TestUBus.cpp66 unit/TestUBus.cpp
68 unit/TestStaticCairoText.cpp67 unit/TestStaticCairoText.cpp
69 ${CMAKE_SOURCE_DIR}/launcher/CairoBaseWindow.cpp68 ${CMAKE_SOURCE_DIR}/launcher/CairoBaseWindow.cpp
70 ${CMAKE_SOURCE_DIR}/unity-shared/Introspectable.cpp69 ${CMAKE_SOURCE_DIR}/unity-shared/Introspectable.cpp
71 ${CMAKE_SOURCE_DIR}/launcher/QuicklistMenuItem.cpp
72 ${CMAKE_SOURCE_DIR}/launcher/QuicklistMenuItemCheckmark.cpp
73 ${CMAKE_SOURCE_DIR}/launcher/QuicklistMenuItemLabel.cpp
74 ${CMAKE_SOURCE_DIR}/launcher/QuicklistMenuItemRadio.cpp
75 ${CMAKE_SOURCE_DIR}/launcher/QuicklistMenuItemSeparator.cpp
76 ${CMAKE_SOURCE_DIR}/launcher/QuicklistView.cpp
77 ${CMAKE_SOURCE_DIR}/unity-shared/StaticCairoText.cpp70 ${CMAKE_SOURCE_DIR}/unity-shared/StaticCairoText.cpp
78 ../services/panel-service.c71 ../services/panel-service.c
79 ${CMAKE_CURRENT_BINARY_DIR}/panel-marshal.c72 ${CMAKE_CURRENT_BINARY_DIR}/panel-marshal.c
@@ -220,6 +213,8 @@
220 test_launcher_controller.cpp213 test_launcher_controller.cpp
221 test_keyboard_util.cpp214 test_keyboard_util.cpp
222 test_panel_style.cpp215 test_panel_style.cpp
216 test_quicklist_menu_item.cpp
217 test_quicklist_view.cpp
223 test_resultviewgrid.cpp218 test_resultviewgrid.cpp
224 test_single_monitor_launcher_icon.cpp219 test_single_monitor_launcher_icon.cpp
225 test_switcher_controller.cpp220 test_switcher_controller.cpp
226221
=== added file 'tests/test_quicklist_menu_item.cpp'
--- tests/test_quicklist_menu_item.cpp 1970-01-01 00:00:00 +0000
+++ tests/test_quicklist_menu_item.cpp 2012-08-13 14:28:23 +0000
@@ -0,0 +1,107 @@
1/*
2 * Copyright 2010-2012 Canonical Ltd.
3 *
4 * This program is free software: you can redistribute it and/or modify it
5 * under the terms of the GNU General Public License version 3, as published
6 * by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranties of
10 * MERCHANTABILITY, SATISFACTORY QUALITY or FITNESS FOR A PARTICULAR
11 * PURPOSE. See the GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * version 3 along with this program. If not, see
15 * <http://www.gnu.org/licenses/>
16 *
17 * Authored by: Marco Trevisan (Treviño) <marco.trevisan@canonical.com>
18 * Mirco Müller <mirco.mueller@canonical.com>
19 */
20
21#include <gmock/gmock.h>
22#include <libdbusmenu-glib/client.h>
23
24#include "QuicklistMenuItem.h"
25#include "QuicklistMenuItemCheckmark.h"
26#include "QuicklistMenuItemLabel.h"
27#include "QuicklistMenuItemRadio.h"
28#include "QuicklistMenuItemSeparator.h"
29
30using namespace unity;
31using namespace testing;
32
33namespace
34{
35
36struct TestQuicklistMenuItem : public Test
37{
38 TestQuicklistMenuItem()
39 : item(dbusmenu_menuitem_new())
40 {}
41
42 glib::Object<DbusmenuMenuitem> item;
43};
44
45TEST_F(TestQuicklistMenuItem, QuicklistMenuItemCheckmark)
46{
47 dbusmenu_menuitem_property_set(item, DBUSMENU_MENUITEM_PROP_LABEL, "Unchecked");
48 dbusmenu_menuitem_property_set(item, DBUSMENU_MENUITEM_PROP_TOGGLE_TYPE,
49 DBUSMENU_MENUITEM_TOGGLE_CHECK);
50 dbusmenu_menuitem_property_set_bool(item, DBUSMENU_MENUITEM_PROP_ENABLED, false);
51 dbusmenu_menuitem_property_set_int(item, DBUSMENU_MENUITEM_PROP_TOGGLE_STATE,
52 DBUSMENU_MENUITEM_TOGGLE_STATE_UNCHECKED);
53
54 nux::ObjectPtr<QuicklistMenuItemCheckmark> qlitem(new QuicklistMenuItemCheckmark(item));
55
56 EXPECT_EQ(qlitem->GetLabel(), "Unchecked");
57 EXPECT_FALSE(qlitem->GetEnabled());
58 EXPECT_FALSE(qlitem->GetActive());
59 EXPECT_FALSE(qlitem->GetSelectable());
60 EXPECT_FALSE(qlitem->IsMarkupEnabled());
61}
62
63TEST_F(TestQuicklistMenuItem, QuicklistMenuItemLabel)
64{
65 dbusmenu_menuitem_property_set(item, DBUSMENU_MENUITEM_PROP_LABEL, "A Label");
66 dbusmenu_menuitem_property_set_bool(item, DBUSMENU_MENUITEM_PROP_ENABLED, true);
67 dbusmenu_menuitem_property_set_bool(item, "unity-use-markup", true);
68
69 nux::ObjectPtr<QuicklistMenuItemLabel> qlitem(new QuicklistMenuItemLabel(item));
70
71 EXPECT_EQ(qlitem->GetLabel(), "A Label");
72 EXPECT_TRUE(qlitem->GetEnabled());
73 EXPECT_TRUE(qlitem->GetSelectable());
74 EXPECT_TRUE(qlitem->IsMarkupEnabled());
75}
76
77TEST_F(TestQuicklistMenuItem, QuicklistMenuItemRadio)
78{
79 dbusmenu_menuitem_property_set(item, DBUSMENU_MENUITEM_PROP_LABEL, "Radio Active");
80 dbusmenu_menuitem_property_set(item, DBUSMENU_MENUITEM_PROP_TOGGLE_TYPE,
81 DBUSMENU_MENUITEM_TOGGLE_RADIO);
82 dbusmenu_menuitem_property_set_bool(item, DBUSMENU_MENUITEM_PROP_ENABLED, true);
83 dbusmenu_menuitem_property_set_int(item, DBUSMENU_MENUITEM_PROP_TOGGLE_STATE,
84 DBUSMENU_MENUITEM_TOGGLE_STATE_CHECKED);
85
86 nux::ObjectPtr<QuicklistMenuItemRadio> qlitem(new QuicklistMenuItemRadio(item));
87 qlitem->EnableLabelMarkup(true);
88
89 EXPECT_EQ(qlitem->GetLabel(), "Radio Active");
90 EXPECT_TRUE(qlitem->GetEnabled());
91 EXPECT_TRUE(qlitem->GetActive());
92 EXPECT_TRUE(qlitem->GetSelectable());
93 EXPECT_TRUE(qlitem->IsMarkupEnabled());
94}
95
96TEST_F(TestQuicklistMenuItem, QuicklistMenuItemSeparator)
97{
98 dbusmenu_menuitem_property_set(item, "type", DBUSMENU_CLIENT_TYPES_SEPARATOR);
99 dbusmenu_menuitem_property_set_bool(item, DBUSMENU_MENUITEM_PROP_ENABLED, true);
100
101 nux::ObjectPtr<QuicklistMenuItemSeparator> qlitem(new QuicklistMenuItemSeparator(item));
102
103 EXPECT_TRUE(qlitem->GetEnabled());
104 EXPECT_FALSE(qlitem->GetSelectable());
105}
106
107}
0108
=== added file 'tests/test_quicklist_view.cpp'
--- tests/test_quicklist_view.cpp 1970-01-01 00:00:00 +0000
+++ tests/test_quicklist_view.cpp 2012-08-13 14:28:23 +0000
@@ -0,0 +1,124 @@
1/*
2 * Copyright 2010-2012 Canonical Ltd.
3 *
4 * This program is free software: you can redistribute it and/or modify it
5 * under the terms of the GNU General Public License version 3, as published
6 * by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranties of
10 * MERCHANTABILITY, SATISFACTORY QUALITY or FITNESS FOR A PARTICULAR
11 * PURPOSE. See the GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * version 3 along with this program. If not, see
15 * <http://www.gnu.org/licenses/>
16 *
17 * Authored by: Marco Trevisan (Treviño) <marco.trevisan@canonical.com>
18 * Mirco Müller <mirco.mueller@canonical.com>
19 */
20
21#include <gmock/gmock.h>
22#include <libdbusmenu-glib/client.h>
23
24#include "QuicklistView.h"
25#include "QuicklistMenuItemCheckmark.h"
26#include "QuicklistMenuItemLabel.h"
27#include "QuicklistMenuItemRadio.h"
28#include "QuicklistMenuItemSeparator.h"
29
30using namespace unity;
31using namespace testing;
32
33namespace
34{
35
36struct TestQuicklistView : public Test
37{
38 TestQuicklistView()
39 : quicklist(new QuicklistView())
40 {}
41
42 void AddMenuItems(DbusmenuMenuitem* root)
43 {
44 quicklist->RemoveAllMenuItem();
45
46 if (!root)
47 return;
48
49 for (GList* child = dbusmenu_menuitem_get_children(root); child; child = child->next)
50 {
51 const gchar* type = dbusmenu_menuitem_property_get((DbusmenuMenuitem*)child->data, DBUSMENU_MENUITEM_PROP_TYPE);
52 const gchar* toggle_type = dbusmenu_menuitem_property_get((DbusmenuMenuitem*)child->data, DBUSMENU_MENUITEM_PROP_TOGGLE_TYPE);
53
54 if (g_strcmp0(type, DBUSMENU_CLIENT_TYPES_SEPARATOR) == 0)
55 {
56 QuicklistMenuItemSeparator* item = new QuicklistMenuItemSeparator((DbusmenuMenuitem*)child->data, NUX_TRACKER_LOCATION);
57 quicklist->AddMenuItem(item);
58 }
59 else if (g_strcmp0(toggle_type, DBUSMENU_MENUITEM_TOGGLE_CHECK) == 0)
60 {
61 QuicklistMenuItemCheckmark* item = new QuicklistMenuItemCheckmark((DbusmenuMenuitem*)child->data, NUX_TRACKER_LOCATION);
62 quicklist->AddMenuItem(item);
63 }
64 else if (g_strcmp0(toggle_type, DBUSMENU_MENUITEM_TOGGLE_RADIO) == 0)
65 {
66 QuicklistMenuItemRadio* item = new QuicklistMenuItemRadio((DbusmenuMenuitem*)child->data, NUX_TRACKER_LOCATION);
67 quicklist->AddMenuItem(item);
68 }
69 else //if (g_strcmp0 (type, DBUSMENU_MENUITEM_PROP_LABEL) == 0)
70 {
71 QuicklistMenuItemLabel* item = new QuicklistMenuItemLabel((DbusmenuMenuitem*)child->data, NUX_TRACKER_LOCATION);
72 quicklist->AddMenuItem(item);
73 }
74 }
75 }
76
77 nux::ObjectPtr<QuicklistView> quicklist;
78};
79
80TEST_F(TestQuicklistView, AddItems)
81{
82 glib::Object<DbusmenuMenuitem> root(dbusmenu_menuitem_new());
83
84 dbusmenu_menuitem_set_root(root, true);
85
86 DbusmenuMenuitem* child = dbusmenu_menuitem_new();
87 dbusmenu_menuitem_property_set(child, DBUSMENU_MENUITEM_PROP_TYPE, DBUSMENU_MENUITEM_PROP_LABEL);
88 dbusmenu_menuitem_property_set(child, DBUSMENU_MENUITEM_PROP_LABEL, "label 0");
89 dbusmenu_menuitem_property_set_bool(child, DBUSMENU_MENUITEM_PROP_ENABLED, true);
90 dbusmenu_menuitem_child_append(root, child);
91
92 child = dbusmenu_menuitem_new();
93 dbusmenu_menuitem_property_set(child, DBUSMENU_MENUITEM_PROP_TYPE, DBUSMENU_CLIENT_TYPES_SEPARATOR);
94 dbusmenu_menuitem_property_set_bool(child, DBUSMENU_MENUITEM_PROP_ENABLED, true);
95 dbusmenu_menuitem_child_append(root, child);
96
97 child = dbusmenu_menuitem_new();
98 dbusmenu_menuitem_property_set(child, DBUSMENU_MENUITEM_PROP_TYPE, DBUSMENU_MENUITEM_PROP_LABEL);
99 dbusmenu_menuitem_property_set(child, DBUSMENU_MENUITEM_PROP_LABEL, "label 1");
100 dbusmenu_menuitem_property_set_bool(child, DBUSMENU_MENUITEM_PROP_ENABLED, true);
101 dbusmenu_menuitem_child_append(root, child);
102
103 child = dbusmenu_menuitem_new();
104 dbusmenu_menuitem_property_set(child, DBUSMENU_MENUITEM_PROP_TOGGLE_TYPE, DBUSMENU_MENUITEM_TOGGLE_CHECK);
105 dbusmenu_menuitem_property_set(child, DBUSMENU_MENUITEM_PROP_LABEL, "check mark 0");
106 dbusmenu_menuitem_property_set_bool(child, DBUSMENU_MENUITEM_PROP_ENABLED, true);
107 dbusmenu_menuitem_property_set_int(child, DBUSMENU_MENUITEM_PROP_TOGGLE_STATE, DBUSMENU_MENUITEM_TOGGLE_STATE_UNCHECKED);
108 dbusmenu_menuitem_child_append(root, child);
109
110 AddMenuItems(root);
111
112 ASSERT_EQ(quicklist->GetChildren().size(), 4);
113 ASSERT_EQ(quicklist->GetNumItems(), 4);
114 EXPECT_EQ(quicklist->GetNthType(0), unity::QuicklistMenuItemType::LABEL);
115 EXPECT_EQ(quicklist->GetNthType(1), unity::QuicklistMenuItemType::SEPARATOR);
116 EXPECT_EQ(quicklist->GetNthType(2), unity::QuicklistMenuItemType::LABEL);
117 EXPECT_EQ(quicklist->GetNthType(3), unity::QuicklistMenuItemType::CHECK);
118
119 EXPECT_EQ(quicklist->GetNthItems(0)->GetLabel(), "label 0");
120 EXPECT_EQ(quicklist->GetNthItems(2)->GetLabel(), "label 1");
121 EXPECT_EQ(quicklist->GetNthItems(3)->GetLabel(), "check mark 0");
122}
123
124}
0125
=== modified file 'tests/unit/TestMain.cpp'
--- tests/unit/TestMain.cpp 2012-01-25 15:59:13 +0000
+++ tests/unit/TestMain.cpp 2012-08-13 14:28:23 +0000
@@ -27,7 +27,6 @@
2727
28void TestPanelServiceCreateSuite();28void TestPanelServiceCreateSuite();
29void TestUBusCreateSuite();29void TestUBusCreateSuite();
30void TestQuicklistMenuitemsCreateSuite();
31void TestStaticCairoTextCreateSuite();30void TestStaticCairoTextCreateSuite();
3231
33nux::WindowThread*32nux::WindowThread*
@@ -71,7 +70,6 @@
7170
72 //Keep alphabetical please71 //Keep alphabetical please
73 TestPanelServiceCreateSuite();72 TestPanelServiceCreateSuite();
74 TestQuicklistMenuitemsCreateSuite();
75 TestStaticCairoTextCreateSuite();73 TestStaticCairoTextCreateSuite();
76 TestUBusCreateSuite();74 TestUBusCreateSuite();
7775
7876
=== removed file 'tests/unit/TestQuicklistMenuitems.cpp'
--- tests/unit/TestQuicklistMenuitems.cpp 2012-04-13 16:02:59 +0000
+++ tests/unit/TestQuicklistMenuitems.cpp 1970-01-01 00:00:00 +0000
@@ -1,258 +0,0 @@
1/*
2 * Copyright 2010 Canonical Ltd.
3 *
4 * This program is free software: you can redistribute it and/or modify it
5 * under the terms of the GNU General Public License version 3, as published
6 * by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranties of
10 * MERCHANTABILITY, SATISFACTORY QUALITY or FITNESS FOR A PARTICULAR
11 * PURPOSE. See the GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * version 3 along with this program. If not, see
15 * <http://www.gnu.org/licenses/>
16 *
17 * Authored by: Mirco Müller <mirco.mueller@canonical.com>
18 *
19 */
20
21#include "config.h"
22
23#include "QuicklistMenuItem.h"
24#include "QuicklistMenuItemCheckmark.h"
25#include "QuicklistMenuItemLabel.h"
26#include "QuicklistMenuItemRadio.h"
27#include "QuicklistMenuItemSeparator.h"
28
29#include "Nux/Nux.h"
30#include "Nux/VLayout.h"
31#include "Nux/HLayout.h"
32#include "Nux/WindowThread.h"
33#include "Nux/WindowCompositor.h"
34#include "Nux/BaseWindow.h"
35
36#include "QuicklistView.h"
37#include "TestThreadHelper.h"
38
39using unity::QuicklistView;
40using unity::QuicklistMenuItem;
41using unity::QuicklistMenuItemCheckmark;
42using unity::QuicklistMenuItemLabel;
43using unity::QuicklistMenuItemRadio;
44using unity::QuicklistMenuItemSeparator;
45
46static void TestMenuItemCheckmark(void);
47static void TestMenuItemLabel(void);
48static void TestMenuItemRadio(void);
49static void TestMenuItemSeparator(void);
50static void TestQuicklistMenuItem(void);
51
52nux::WindowThread* thread = NULL;
53
54void
55TestQuicklistMenuitemsCreateSuite()
56{
57#define _DOMAIN "/Unit/QuicklistMenuitems"
58
59 g_test_add_func(_DOMAIN"/MenuItemCheckmark", TestMenuItemCheckmark);
60 g_test_add_func(_DOMAIN"/MenuItemLabel", TestMenuItemLabel);
61 g_test_add_func(_DOMAIN"/MenuItemRadio", TestMenuItemRadio);
62 g_test_add_func(_DOMAIN"/MenuItemSeparator", TestMenuItemSeparator);
63 g_test_add_func(_DOMAIN"/QuicklistMenuItem", TestQuicklistMenuItem);
64}
65
66static void
67TestMenuItemCheckmark()
68{
69 DbusmenuMenuitem* item = NULL;
70
71
72 item = dbusmenu_menuitem_new();
73
74 dbusmenu_menuitem_property_set(item,
75 DBUSMENU_MENUITEM_PROP_LABEL,
76 "Unchecked");
77
78 dbusmenu_menuitem_property_set(item,
79 DBUSMENU_MENUITEM_PROP_TOGGLE_TYPE,
80 DBUSMENU_MENUITEM_TOGGLE_CHECK);
81
82 dbusmenu_menuitem_property_set_bool(item,
83 DBUSMENU_MENUITEM_PROP_ENABLED,
84 false);
85
86 dbusmenu_menuitem_property_set_int(item,
87 DBUSMENU_MENUITEM_PROP_TOGGLE_STATE,
88 DBUSMENU_MENUITEM_TOGGLE_STATE_UNCHECKED);
89
90 QuicklistMenuItemCheckmark* qlCheckmarkItem = NULL;
91
92 qlCheckmarkItem = new QuicklistMenuItemCheckmark(item, true);
93
94 g_assert_cmpstr(qlCheckmarkItem->GetLabel(), == , "Unchecked");
95 g_assert_cmpint(qlCheckmarkItem->GetEnabled(), == , false);
96 g_assert_cmpint(qlCheckmarkItem->GetActive(), == , false);
97 g_assert_cmpint(qlCheckmarkItem->GetSelectable(), == , false);
98 g_assert_cmpint(qlCheckmarkItem->IsMarkupEnabled(), == , false);
99
100 //qlCheckmarkItem->sigChanged.connect (sigc::mem_fun (pointerToCallerClass,
101 // &CallerClass::RecvChanged));
102
103
104 qlCheckmarkItem->Dispose();
105 g_object_unref(item);
106}
107
108static void
109TestMenuItemLabel()
110{
111 DbusmenuMenuitem* item = NULL;
112
113 item = dbusmenu_menuitem_new();
114
115 dbusmenu_menuitem_property_set(item,
116 DBUSMENU_MENUITEM_PROP_LABEL,
117 "A Label");
118
119 dbusmenu_menuitem_property_set_bool(item,
120 DBUSMENU_MENUITEM_PROP_ENABLED,
121 true);
122
123 dbusmenu_menuitem_property_set_bool(item,
124 "unity-use-markup",
125 true);
126
127 QuicklistMenuItemLabel* qlLabelItem = NULL;
128
129 qlLabelItem = new QuicklistMenuItemLabel(item, true);
130
131 g_assert_cmpstr(qlLabelItem->GetLabel(), == , "A Label");
132 g_assert_cmpint(qlLabelItem->GetEnabled(), == , true);
133 g_assert_cmpint(qlLabelItem->GetSelectable(), == , true);
134 g_assert_cmpint(qlLabelItem->IsMarkupEnabled(), == , true);
135
136 //qlLabelItem->sigChanged.connect (sigc::mem_fun (pointerToCallerClass,
137 // &CallerClass::RecvChanged));
138
139 qlLabelItem->Dispose();
140 g_object_unref(item);
141}
142
143static void
144TestMenuItemRadio()
145{
146 DbusmenuMenuitem* item = NULL;
147
148 item = dbusmenu_menuitem_new();
149
150 dbusmenu_menuitem_property_set(item,
151 DBUSMENU_MENUITEM_PROP_LABEL,
152 "Radio Active");
153
154 dbusmenu_menuitem_property_set(item,
155 DBUSMENU_MENUITEM_PROP_TOGGLE_TYPE,
156 DBUSMENU_MENUITEM_TOGGLE_RADIO);
157
158 dbusmenu_menuitem_property_set_bool(item,
159 DBUSMENU_MENUITEM_PROP_ENABLED,
160 true);
161
162 dbusmenu_menuitem_property_set_int(item,
163 DBUSMENU_MENUITEM_PROP_TOGGLE_STATE,
164 DBUSMENU_MENUITEM_TOGGLE_STATE_CHECKED);
165
166 QuicklistMenuItemRadio* qlRadioItem = NULL;
167
168 qlRadioItem = new QuicklistMenuItemRadio(item, true);
169 qlRadioItem->EnableLabelMarkup(true);
170
171 g_assert_cmpstr(qlRadioItem->GetLabel(), == , "Radio Active");
172 g_assert_cmpint(qlRadioItem->GetEnabled(), == , true);
173 g_assert_cmpint(qlRadioItem->GetActive(), == , true);
174 g_assert_cmpint(qlRadioItem->GetSelectable(), == , true);
175 g_assert_cmpint(qlRadioItem->IsMarkupEnabled(), == , true);
176
177 //qlRadioItem->sigChanged.connect (sigc::mem_fun (pointerToCallerClass,
178 // &CallerClass::RecvChanged));
179
180 qlRadioItem->Dispose();
181 g_object_unref(item);
182}
183
184static void
185TestMenuItemSeparator()
186{
187 DbusmenuMenuitem* item = NULL;
188
189 item = dbusmenu_menuitem_new();
190
191 dbusmenu_menuitem_property_set(item,
192 "type",
193 DBUSMENU_CLIENT_TYPES_SEPARATOR);
194
195 dbusmenu_menuitem_property_set_bool(item,
196 DBUSMENU_MENUITEM_PROP_ENABLED,
197 true);
198
199 QuicklistMenuItemSeparator* qlSeparatorItem = NULL;
200
201 qlSeparatorItem = new QuicklistMenuItemSeparator(item, true);
202
203 g_assert_cmpint(qlSeparatorItem->GetEnabled(), == , true);
204 g_assert_cmpint(qlSeparatorItem->GetSelectable(), == , false);
205
206 qlSeparatorItem->Dispose();
207 g_object_unref(item);
208}
209
210static void
211TestQuicklistMenuItem()
212{
213 DbusmenuMenuitem* root = dbusmenu_menuitem_new();
214
215 dbusmenu_menuitem_set_root(root, true);
216
217 DbusmenuMenuitem* child = dbusmenu_menuitem_new();
218 dbusmenu_menuitem_property_set(child, DBUSMENU_MENUITEM_PROP_TYPE, DBUSMENU_MENUITEM_PROP_LABEL);
219 dbusmenu_menuitem_property_set(child, DBUSMENU_MENUITEM_PROP_LABEL, "label 0");
220 dbusmenu_menuitem_property_set_bool(child, DBUSMENU_MENUITEM_PROP_ENABLED, true);
221 dbusmenu_menuitem_child_append(root, child);
222
223 child = dbusmenu_menuitem_new();
224 dbusmenu_menuitem_property_set(child, DBUSMENU_MENUITEM_PROP_TYPE, DBUSMENU_CLIENT_TYPES_SEPARATOR);
225 dbusmenu_menuitem_property_set_bool(child, DBUSMENU_MENUITEM_PROP_ENABLED, true);
226 dbusmenu_menuitem_child_append(root, child);
227
228 child = dbusmenu_menuitem_new();
229 dbusmenu_menuitem_property_set(child, DBUSMENU_MENUITEM_PROP_TYPE, DBUSMENU_MENUITEM_PROP_LABEL);
230 dbusmenu_menuitem_property_set(child, DBUSMENU_MENUITEM_PROP_LABEL, "label 1");
231 dbusmenu_menuitem_property_set_bool(child, DBUSMENU_MENUITEM_PROP_ENABLED, true);
232 dbusmenu_menuitem_child_append(root, child);
233
234 child = dbusmenu_menuitem_new();
235 dbusmenu_menuitem_property_set(child, DBUSMENU_MENUITEM_PROP_TOGGLE_TYPE, DBUSMENU_MENUITEM_TOGGLE_CHECK);
236 dbusmenu_menuitem_property_set(child, DBUSMENU_MENUITEM_PROP_LABEL, "check mark 0");
237 dbusmenu_menuitem_property_set_bool(child, DBUSMENU_MENUITEM_PROP_ENABLED, true);
238 dbusmenu_menuitem_property_set_int(child, DBUSMENU_MENUITEM_PROP_TOGGLE_STATE, DBUSMENU_MENUITEM_TOGGLE_STATE_UNCHECKED);
239 dbusmenu_menuitem_child_append(root, child);
240
241 QuicklistView* quicklist = new QuicklistView();
242
243 quicklist->TestMenuItems(root);
244
245 g_assert_cmpint(quicklist->GetNumItems(), == , 4);
246 g_assert_cmpint(quicklist->GetNthType(0), == , unity::MENUITEM_TYPE_LABEL);
247 g_assert_cmpint(quicklist->GetNthType(1), == , unity::MENUITEM_TYPE_SEPARATOR);
248 g_assert_cmpint(quicklist->GetNthType(2), == , unity::MENUITEM_TYPE_LABEL);
249 g_assert_cmpint(quicklist->GetNthType(3), == , unity::MENUITEM_TYPE_CHECK);
250
251 g_assert_cmpstr(quicklist->GetNthItems(0)->GetLabel(), == , "label 0");
252 g_assert_cmpstr(quicklist->GetNthItems(2)->GetLabel(), == , "label 1");
253 g_assert_cmpstr(quicklist->GetNthItems(3)->GetLabel(), == , "check mark 0");
254
255 g_assert_cmpint(quicklist->GetChildren().size(), == , 4);
256
257 quicklist->Dispose();
258}