Merge lp:~3v1n0/unity/quicklist-menuitem-clanup into lp:unity
- quicklist-menuitem-clanup
- Merge into trunk
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 |
Related bugs: |
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.
Preview Diff
[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1 | === modified file 'launcher/QuicklistMenuItem.cpp' |
2 | --- launcher/QuicklistMenuItem.cpp 2012-05-14 02:08:47 +0000 |
3 | +++ launcher/QuicklistMenuItem.cpp 2012-08-13 14:28:23 +0000 |
4 | @@ -1,6 +1,6 @@ |
5 | // -*- Mode: C++; indent-tabs-mode: nil; tab-width: 2 -*- |
6 | /* |
7 | - * Copyright (C) 2010 Canonical Ltd |
8 | + * Copyright (C) 2010-2012 Canonical Ltd |
9 | * |
10 | * This program is free software: you can redistribute it and/or modify |
11 | * it under the terms of the GNU General Public License version 3 as |
12 | @@ -16,322 +16,133 @@ |
13 | * |
14 | * Authored by: Mirco Müller <mirco.mueller@canonical.com> |
15 | * Jay Taoko <jay.taoko@canonical.com> |
16 | - * Marco Trevisan (Treviño) <3v1n0@ubuntu.com> |
17 | + * Marco Trevisan <marco.trevisan@canonical.com> |
18 | */ |
19 | |
20 | -#include <gdk/gdk.h> |
21 | #include <gtk/gtk.h> |
22 | - |
23 | -#include <Nux/Nux.h> |
24 | +#include <UnityCore/Variant.h> |
25 | +#include "unity-shared/UBusWrapper.h" |
26 | +#include "unity-shared/UBusMessages.h" |
27 | |
28 | #include "QuicklistMenuItem.h" |
29 | -#include <UnityCore/Variant.h> |
30 | - |
31 | -#include <X11/Xlib.h> |
32 | |
33 | namespace unity |
34 | { |
35 | |
36 | NUX_IMPLEMENT_OBJECT_TYPE(QuicklistMenuItem); |
37 | |
38 | -static void |
39 | -OnPropertyChanged(gchar* property, |
40 | - GValue* value, |
41 | - QuicklistMenuItem* self); |
42 | - |
43 | -static void |
44 | -OnItemActivated(guint timestamp, |
45 | - QuicklistMenuItem* self); |
46 | - |
47 | -QuicklistMenuItem::QuicklistMenuItem(DbusmenuMenuitem* item, |
48 | - NUX_FILE_LINE_DECL) : |
49 | - View(NUX_FILE_LINE_PARAM) |
50 | -{ |
51 | - if (item == 0) |
52 | - { |
53 | - g_warning("Invalid DbusmenuMenuitem in file %s at line %s.", G_STRFUNC, G_STRLOC); |
54 | - } |
55 | - |
56 | - Initialize(item, false); |
57 | -} |
58 | - |
59 | -QuicklistMenuItem::QuicklistMenuItem(DbusmenuMenuitem* item, |
60 | - bool debug, |
61 | - NUX_FILE_LINE_DECL) : |
62 | - View(NUX_FILE_LINE_PARAM) |
63 | -{ |
64 | - Initialize(item, debug); |
65 | -} |
66 | - |
67 | -void |
68 | -QuicklistMenuItem::Initialize(DbusmenuMenuitem* item, bool debug) |
69 | -{ |
70 | - _text = ""; |
71 | - _color = nux::Color(1.0f, 1.0f, 1.0f, 1.0f); |
72 | - _menuItem = DBUSMENU_MENUITEM(g_object_ref(item)); |
73 | - _debug = debug; |
74 | - _item_type = MENUITEM_TYPE_UNKNOWN; |
75 | - |
76 | - _normalTexture[0] = NULL; |
77 | - _normalTexture[1] = NULL; |
78 | - _prelightTexture[0] = NULL; |
79 | - _prelightTexture[1] = NULL; |
80 | - |
81 | - if (_menuItem) |
82 | - { |
83 | - g_signal_connect(_menuItem, |
84 | - "property-changed", |
85 | - G_CALLBACK(OnPropertyChanged), |
86 | - this); |
87 | - g_signal_connect(_menuItem, |
88 | - "item-activated", |
89 | - G_CALLBACK(OnItemActivated), |
90 | - this); |
91 | - } |
92 | - |
93 | +QuicklistMenuItem::QuicklistMenuItem(QuicklistMenuItemType type, DbusmenuMenuitem* item, NUX_FILE_LINE_DECL) |
94 | + : nux::View(NUX_FILE_LINE_PARAM) |
95 | + , _item_type(type) |
96 | + , _menu_item(item, glib::AddRef()) |
97 | + , _prelight(false) |
98 | +{ |
99 | mouse_up.connect(sigc::mem_fun(this, &QuicklistMenuItem::RecvMouseUp)); |
100 | mouse_click.connect(sigc::mem_fun(this, &QuicklistMenuItem::RecvMouseClick)); |
101 | mouse_drag.connect(sigc::mem_fun(this, &QuicklistMenuItem::RecvMouseDrag)); |
102 | mouse_enter.connect(sigc::mem_fun(this, &QuicklistMenuItem::RecvMouseEnter)); |
103 | mouse_leave.connect(sigc::mem_fun(this, &QuicklistMenuItem::RecvMouseLeave)); |
104 | - |
105 | - _prelight = false; |
106 | } |
107 | |
108 | QuicklistMenuItem::~QuicklistMenuItem() |
109 | -{ |
110 | - if (_normalTexture[0]) |
111 | - _normalTexture[0]->UnReference(); |
112 | - |
113 | - if (_normalTexture[1]) |
114 | - _normalTexture[1]->UnReference(); |
115 | - |
116 | - if (_prelightTexture[0]) |
117 | - _prelightTexture[0]->UnReference(); |
118 | - |
119 | - if (_prelightTexture[1]) |
120 | - _prelightTexture[1]->UnReference(); |
121 | - |
122 | - if (_menuItem) |
123 | - g_object_unref(_menuItem); |
124 | -} |
125 | - |
126 | -const gchar* |
127 | -QuicklistMenuItem::GetDefaultText() |
128 | -{ |
129 | - return NULL; |
130 | -} |
131 | - |
132 | -void |
133 | -QuicklistMenuItem::InitializeText() |
134 | -{ |
135 | - if (_menuItem) |
136 | +{} |
137 | + |
138 | +std::string QuicklistMenuItem::GetDefaultText() const |
139 | +{ |
140 | + return ""; |
141 | +} |
142 | + |
143 | +void QuicklistMenuItem::InitializeText() |
144 | +{ |
145 | + if (_menu_item) |
146 | _text = GetText(); |
147 | else |
148 | _text = GetDefaultText(); |
149 | |
150 | - int textWidth = 1; |
151 | - int textHeight = 1; |
152 | - GetTextExtents(textWidth, textHeight); |
153 | - SetMinimumSize(textWidth + ITEM_INDENT_ABS + 3 * ITEM_MARGIN, |
154 | - textHeight + 2 * ITEM_MARGIN); |
155 | + // This is needed to setup the item size values |
156 | + nux::CairoGraphics cairoGraphics(CAIRO_FORMAT_A1, 1, 1); |
157 | + DrawText(cairoGraphics, 1, 1, nux::color::White); |
158 | } |
159 | |
160 | -QuicklistMenuItemType QuicklistMenuItem::GetItemType() |
161 | +QuicklistMenuItemType QuicklistMenuItem::GetItemType() const |
162 | { |
163 | return _item_type; |
164 | } |
165 | |
166 | -void |
167 | -QuicklistMenuItem::PreLayoutManagement() |
168 | -{ |
169 | - View::PreLayoutManagement(); |
170 | -} |
171 | - |
172 | -long |
173 | -QuicklistMenuItem::PostLayoutManagement(long layoutResult) |
174 | -{ |
175 | - long result = View::PostLayoutManagement(layoutResult); |
176 | - |
177 | - return result; |
178 | -} |
179 | - |
180 | -void |
181 | -QuicklistMenuItem::Draw(nux::GraphicsEngine& gfxContext, |
182 | - bool forceDraw) |
183 | -{ |
184 | -} |
185 | - |
186 | -void |
187 | -QuicklistMenuItem::DrawContent(nux::GraphicsEngine& gfxContext, |
188 | - bool forceDraw) |
189 | -{ |
190 | -} |
191 | - |
192 | -void |
193 | -QuicklistMenuItem::PostDraw(nux::GraphicsEngine& gfxContext, |
194 | - bool forceDraw) |
195 | -{ |
196 | -} |
197 | - |
198 | -const gchar* |
199 | -QuicklistMenuItem::GetLabel() |
200 | -{ |
201 | - if (_menuItem == 0) |
202 | - return 0; |
203 | - return dbusmenu_menuitem_property_get(_menuItem, |
204 | - DBUSMENU_MENUITEM_PROP_LABEL); |
205 | -} |
206 | - |
207 | -bool |
208 | -QuicklistMenuItem::GetEnabled() |
209 | -{ |
210 | - if (_menuItem == 0) |
211 | - return false; |
212 | - return dbusmenu_menuitem_property_get_bool(_menuItem, |
213 | - DBUSMENU_MENUITEM_PROP_ENABLED); |
214 | -} |
215 | - |
216 | -bool |
217 | -QuicklistMenuItem::GetActive() |
218 | -{ |
219 | - if (_menuItem == 0) |
220 | - return false; |
221 | - return dbusmenu_menuitem_property_get_int(_menuItem, |
222 | - DBUSMENU_MENUITEM_PROP_TOGGLE_STATE) == DBUSMENU_MENUITEM_TOGGLE_STATE_CHECKED; |
223 | -} |
224 | - |
225 | -bool |
226 | -QuicklistMenuItem::GetVisible() |
227 | -{ |
228 | - if (_menuItem == 0) |
229 | - return false; |
230 | - return dbusmenu_menuitem_property_get_bool(_menuItem, |
231 | - DBUSMENU_MENUITEM_PROP_VISIBLE); |
232 | -} |
233 | - |
234 | -bool |
235 | -QuicklistMenuItem::GetSelectable() |
236 | +std::string QuicklistMenuItem::GetLabel() const |
237 | +{ |
238 | + if (!_menu_item) |
239 | + return ""; |
240 | + |
241 | + const char *label = dbusmenu_menuitem_property_get(_menu_item, DBUSMENU_MENUITEM_PROP_LABEL); |
242 | + |
243 | + return label ? label : ""; |
244 | +} |
245 | + |
246 | +bool QuicklistMenuItem::GetEnabled() const |
247 | +{ |
248 | + if (!_menu_item) |
249 | + return false; |
250 | + |
251 | + return dbusmenu_menuitem_property_get_bool(_menu_item, DBUSMENU_MENUITEM_PROP_ENABLED); |
252 | +} |
253 | + |
254 | +bool QuicklistMenuItem::GetActive() const |
255 | +{ |
256 | + if (!_menu_item) |
257 | + return false; |
258 | + |
259 | + int toggle = dbusmenu_menuitem_property_get_int(_menu_item, DBUSMENU_MENUITEM_PROP_TOGGLE_STATE); |
260 | + |
261 | + return (toggle == DBUSMENU_MENUITEM_TOGGLE_STATE_CHECKED); |
262 | +} |
263 | + |
264 | +bool QuicklistMenuItem::GetVisible() const |
265 | +{ |
266 | + if (!_menu_item) |
267 | + return false; |
268 | + |
269 | + return dbusmenu_menuitem_property_get_bool(_menu_item, DBUSMENU_MENUITEM_PROP_VISIBLE); |
270 | +} |
271 | + |
272 | +bool QuicklistMenuItem::GetSelectable() const |
273 | { |
274 | return GetVisible() && GetEnabled(); |
275 | } |
276 | |
277 | -void QuicklistMenuItem::ItemActivated() |
278 | -{ |
279 | - if (_debug) |
280 | - sigChanged.emit(*this); |
281 | - |
282 | - std::cout << "ItemActivated() called" << std::endl; |
283 | -} |
284 | - |
285 | -gchar* QuicklistMenuItem::GetText() |
286 | -{ |
287 | - const gchar *label; |
288 | - gchar *text; |
289 | - |
290 | - if (!_menuItem) |
291 | - return NULL; |
292 | - |
293 | - label = GetLabel(); |
294 | - |
295 | - if (!label) |
296 | - return NULL; |
297 | +std::string QuicklistMenuItem::GetText() const |
298 | +{ |
299 | + std::string const& label = GetLabel(); |
300 | + |
301 | + if (label.empty()) |
302 | + return ""; |
303 | |
304 | if (!IsMarkupEnabled()) |
305 | { |
306 | - text = g_markup_escape_text(label, -1); |
307 | - } |
308 | - else |
309 | - { |
310 | - text = g_strdup(label); |
311 | - } |
312 | - |
313 | - return text; |
314 | -} |
315 | - |
316 | -void QuicklistMenuItem::GetTextExtents(int& width, int& height) |
317 | -{ |
318 | - GtkSettings* settings = gtk_settings_get_default(); // not ref'ed |
319 | - gchar* fontName = NULL; |
320 | - |
321 | - g_object_get(settings, "gtk-font-name", &fontName, NULL); |
322 | - GetTextExtents(fontName, width, height); |
323 | - g_free(fontName); |
324 | -} |
325 | - |
326 | -void QuicklistMenuItem::GetTextExtents(const gchar* font, |
327 | - int& width, |
328 | - int& height) |
329 | -{ |
330 | - cairo_surface_t* surface = NULL; |
331 | - cairo_t* cr = NULL; |
332 | - PangoLayout* layout = NULL; |
333 | - PangoFontDescription* desc = NULL; |
334 | - PangoContext* pangoCtx = NULL; |
335 | - PangoRectangle logRect = {0, 0, 0, 0}; |
336 | - int dpi = 0; |
337 | - GdkScreen* screen = gdk_screen_get_default(); // is not ref'ed |
338 | - GtkSettings* settings = gtk_settings_get_default(); // is not ref'ed |
339 | - |
340 | - // sanity check |
341 | - if (!font) |
342 | - return; |
343 | - |
344 | - if (_text == "") |
345 | - return; |
346 | - |
347 | - surface = cairo_image_surface_create(CAIRO_FORMAT_A1, 1, 1); |
348 | - cr = cairo_create(surface); |
349 | - cairo_set_font_options(cr, gdk_screen_get_font_options(screen)); |
350 | - layout = pango_cairo_create_layout(cr); |
351 | - desc = pango_font_description_from_string(font); |
352 | - pango_font_description_set_weight(desc, PANGO_WEIGHT_NORMAL); |
353 | - pango_layout_set_font_description(layout, desc); |
354 | - pango_layout_set_wrap(layout, PANGO_WRAP_WORD_CHAR); |
355 | - pango_layout_set_ellipsize(layout, PANGO_ELLIPSIZE_END); |
356 | - pango_layout_set_markup_with_accel(layout, _text.c_str(), -1, '_', NULL); |
357 | - pangoCtx = pango_layout_get_context(layout); // is not ref'ed |
358 | - pango_cairo_context_set_font_options(pangoCtx, |
359 | - gdk_screen_get_font_options(screen)); |
360 | - g_object_get(settings, "gtk-xft-dpi", &dpi, NULL); |
361 | - if (dpi == -1) |
362 | - { |
363 | - // use some default DPI-value |
364 | - pango_cairo_context_set_resolution(pangoCtx, 96.0f); |
365 | - } |
366 | - else |
367 | - { |
368 | - pango_cairo_context_set_resolution(pangoCtx, |
369 | - (float) dpi / (float) PANGO_SCALE); |
370 | - } |
371 | - pango_layout_context_changed(layout); |
372 | - pango_layout_get_extents(layout, NULL, &logRect); |
373 | - |
374 | - width = logRect.width / PANGO_SCALE; |
375 | - height = logRect.height / PANGO_SCALE; |
376 | - |
377 | - // clean up |
378 | - pango_font_description_free(desc); |
379 | - g_object_unref(layout); |
380 | - cairo_destroy(cr); |
381 | - cairo_surface_destroy(surface); |
382 | -} |
383 | - |
384 | -static void |
385 | -OnPropertyChanged(gchar* property, |
386 | - GValue* value, |
387 | - QuicklistMenuItem* self) |
388 | -{ |
389 | - //todo |
390 | - //self->UpdateTexture (); |
391 | -} |
392 | - |
393 | -static void |
394 | -OnItemActivated(guint timestamp, |
395 | - QuicklistMenuItem* self) |
396 | -{ |
397 | - //todo: |
398 | - //self->ItemActivated (); |
399 | + return glib::String(g_markup_escape_text(label.c_str(), -1)).Str(); |
400 | + } |
401 | + |
402 | + return label; |
403 | +} |
404 | + |
405 | +void QuicklistMenuItem::Activate() const |
406 | +{ |
407 | + if (!_menu_item) |
408 | + return; |
409 | + |
410 | + dbusmenu_menuitem_handle_event(_menu_item, "clicked", nullptr, 0); |
411 | + UBusManager manager; |
412 | + manager.SendMessage(UBUS_PLACE_VIEW_CLOSE_REQUEST); |
413 | +} |
414 | + |
415 | +void QuicklistMenuItem::Select(bool select) |
416 | +{ |
417 | + _prelight = select; |
418 | +} |
419 | + |
420 | +bool QuicklistMenuItem::IsSelected() const |
421 | +{ |
422 | + return _prelight; |
423 | } |
424 | |
425 | void QuicklistMenuItem::RecvMouseUp(int x, int y, unsigned long button_flags, unsigned long key_flags) |
426 | @@ -342,9 +153,8 @@ |
427 | void QuicklistMenuItem::RecvMouseClick(int x, int y, unsigned long button_flags, unsigned long key_flags) |
428 | { |
429 | if (!GetEnabled()) |
430 | - { |
431 | return; |
432 | - } |
433 | + |
434 | sigMouseClick.emit(this, x, y); |
435 | } |
436 | |
437 | @@ -363,38 +173,115 @@ |
438 | sigMouseLeave.emit(this); |
439 | } |
440 | |
441 | -void QuicklistMenuItem::DrawText(nux::CairoGraphics* cairo, int width, int height, nux::Color const& color) |
442 | -{ |
443 | - if (_text == "" || cairo == nullptr) |
444 | - return; |
445 | - |
446 | - cairo_t* cr = cairo->GetContext(); |
447 | - int textWidth = 0; |
448 | - int textHeight = 0; |
449 | - PangoLayout* layout = NULL; |
450 | - PangoFontDescription* desc = NULL; |
451 | - PangoContext* pangoCtx = NULL; |
452 | - int dpi = 0; |
453 | - GdkScreen* screen = gdk_screen_get_default(); // not ref'ed |
454 | - GtkSettings* settings = gtk_settings_get_default(); // not ref'ed |
455 | - gchar* fontName = NULL; |
456 | - |
457 | - g_object_get(settings, "gtk-font-name", &fontName, NULL); |
458 | - GetTextExtents(fontName, textWidth, textHeight); |
459 | - |
460 | +void QuicklistMenuItem::PreLayoutManagement() |
461 | +{ |
462 | + _pre_layout_width = GetBaseWidth(); |
463 | + _pre_layout_height = GetBaseHeight(); |
464 | + |
465 | + if (!_normalTexture[0]) |
466 | + { |
467 | + UpdateTexture(); |
468 | + } |
469 | + |
470 | + View::PreLayoutManagement(); |
471 | +} |
472 | + |
473 | +long QuicklistMenuItem::PostLayoutManagement(long layoutResult) |
474 | +{ |
475 | + int w = GetBaseWidth(); |
476 | + int h = GetBaseHeight(); |
477 | + |
478 | + long result = 0; |
479 | + |
480 | + if (_pre_layout_width < w) |
481 | + result |= nux::eLargerWidth; |
482 | + else if (_pre_layout_width > w) |
483 | + result |= nux::eSmallerWidth; |
484 | + else |
485 | + result |= nux::eCompliantWidth; |
486 | + |
487 | + if (_pre_layout_height < h) |
488 | + result |= nux::eLargerHeight; |
489 | + else if (_pre_layout_height > h) |
490 | + result |= nux::eSmallerHeight; |
491 | + else |
492 | + result |= nux::eCompliantHeight; |
493 | + |
494 | + return result; |
495 | +} |
496 | + |
497 | +void QuicklistMenuItem::Draw(nux::GraphicsEngine& gfxContext, bool forceDraw) |
498 | +{ |
499 | + // Check if the texture have been computed. If they haven't, exit the function. |
500 | + if (!_normalTexture[0] || !_prelightTexture[0]) |
501 | + return; |
502 | + |
503 | + nux::Geometry const& base = GetGeometry(); |
504 | + |
505 | + gfxContext.PushClippingRectangle(base); |
506 | + |
507 | + nux::TexCoordXForm texxform; |
508 | + texxform.SetWrap(nux::TEXWRAP_REPEAT, nux::TEXWRAP_REPEAT); |
509 | + texxform.SetTexCoordType(nux::TexCoordXForm::OFFSET_COORD); |
510 | + |
511 | + gfxContext.GetRenderStates().SetBlend(true); |
512 | + gfxContext.GetRenderStates().SetPremultipliedBlend(nux::SRC_OVER); |
513 | + |
514 | + nux::ObjectPtr<nux::IOpenGLBaseTexture> texture; |
515 | + unsigned int texture_idx = GetActive() ? 1 : 0; |
516 | + bool enabled = GetEnabled(); |
517 | + |
518 | + if (!_prelight || !enabled) |
519 | + { |
520 | + texture = _normalTexture[texture_idx]->GetDeviceTexture(); |
521 | + } |
522 | + else |
523 | + { |
524 | + texture = _prelightTexture[texture_idx]->GetDeviceTexture(); |
525 | + } |
526 | + |
527 | + nux::Color const& color = enabled ? nux::color::White : nux::color::White * 0.35; |
528 | + |
529 | + gfxContext.QRP_1Tex(base.x, base.y, base.width, base.height, texture, texxform, color); |
530 | + gfxContext.GetRenderStates().SetBlend(false); |
531 | + gfxContext.PopClippingRectangle(); |
532 | +} |
533 | + |
534 | +nux::Size const& QuicklistMenuItem::GetTextExtents() const |
535 | +{ |
536 | + return _text_extents; |
537 | +} |
538 | + |
539 | +void QuicklistMenuItem::DrawText(nux::CairoGraphics& cairo, int width, int height, nux::Color const& color) |
540 | +{ |
541 | + if (_text.empty()) |
542 | + return; |
543 | + |
544 | + GdkScreen* screen = gdk_screen_get_default(); // not ref'ed |
545 | + GtkSettings* settings = gtk_settings_get_default(); // not ref'ed |
546 | + |
547 | + glib::String font_name; |
548 | + g_object_get(settings, "gtk-font-name", &font_name, nullptr); |
549 | + |
550 | + std::shared_ptr<cairo_t> cairo_context(cairo.GetContext(), cairo_destroy); |
551 | + cairo_t* cr = cairo_context.get(); |
552 | cairo_set_operator(cr, CAIRO_OPERATOR_SOURCE); |
553 | cairo_set_source_rgba(cr, color.red, color.blue, color.green, color.alpha); |
554 | cairo_set_font_options(cr, gdk_screen_get_font_options(screen)); |
555 | - layout = pango_cairo_create_layout(cr); |
556 | - desc = pango_font_description_from_string(fontName); |
557 | - pango_layout_set_font_description(layout, desc); |
558 | + |
559 | + glib::Object<PangoLayout> layout(pango_cairo_create_layout(cr)); |
560 | + std::shared_ptr<PangoFontDescription> desc(pango_font_description_from_string(font_name), pango_font_description_free); |
561 | + pango_layout_set_font_description(layout, desc.get()); |
562 | pango_layout_set_wrap(layout, PANGO_WRAP_WORD_CHAR); |
563 | pango_layout_set_ellipsize(layout, PANGO_ELLIPSIZE_END); |
564 | - pango_layout_set_markup_with_accel(layout, _text.c_str(), -1, '_', NULL); |
565 | - pangoCtx = pango_layout_get_context(layout); // is not ref'ed |
566 | - pango_cairo_context_set_font_options(pangoCtx, |
567 | - gdk_screen_get_font_options(screen)); |
568 | - g_object_get(settings, "gtk-xft-dpi", &dpi, NULL); |
569 | + pango_layout_set_markup_with_accel(layout, _text.c_str(), -1, '_', nullptr); |
570 | + |
571 | + PangoContext* pangoCtx = pango_layout_get_context(layout); // is not ref'ed |
572 | + pango_cairo_context_set_font_options(pangoCtx, gdk_screen_get_font_options(screen)); |
573 | + |
574 | + int dpi = 0; |
575 | + g_object_get(settings, "gtk-xft-dpi", &dpi, nullptr); |
576 | + |
577 | if (dpi == -1) |
578 | { |
579 | // use some default DPI-value |
580 | @@ -402,68 +289,79 @@ |
581 | } |
582 | else |
583 | { |
584 | - pango_cairo_context_set_resolution(pangoCtx, |
585 | - (float) dpi / (float) PANGO_SCALE); |
586 | + pango_cairo_context_set_resolution(pangoCtx, static_cast<float>(dpi) / static_cast<float>(PANGO_SCALE)); |
587 | } |
588 | |
589 | pango_layout_context_changed(layout); |
590 | - |
591 | - cairo_move_to(cr, |
592 | - 2 * ITEM_MARGIN + ITEM_INDENT_ABS, |
593 | - (float)(height - textHeight) / 2.0f); |
594 | + PangoRectangle log_rect = {0, 0, 0, 0}; |
595 | + pango_layout_get_extents(layout, nullptr, &log_rect); |
596 | + |
597 | + int text_width = log_rect.width / PANGO_SCALE; |
598 | + int text_height = log_rect.height / PANGO_SCALE; |
599 | + |
600 | + _text_extents.width = text_width + ITEM_INDENT_ABS + 3 * ITEM_MARGIN; |
601 | + _text_extents.height = text_height + 2 * ITEM_MARGIN; |
602 | + |
603 | + SetMinimumSize(_text_extents.width, _text_extents.height); |
604 | + |
605 | + cairo_move_to(cr, 2 * ITEM_MARGIN + ITEM_INDENT_ABS, static_cast<float>(height - text_height) / 2.0f); |
606 | pango_cairo_show_layout(cr, layout); |
607 | - |
608 | - // clean up |
609 | - pango_font_description_free(desc); |
610 | - g_free(fontName); |
611 | - g_object_unref(layout); |
612 | - cairo_destroy(cr); |
613 | } |
614 | |
615 | -void QuicklistMenuItem::DrawPrelight(nux::CairoGraphics* cairo, int width, int height, nux::Color const& color) |
616 | +void QuicklistMenuItem::DrawPrelight(nux::CairoGraphics& cairo, int width, int height, nux::Color const& color) |
617 | { |
618 | - if (!cairo) |
619 | - return; |
620 | - |
621 | - cairo_t* cr = cairo->GetContext(); |
622 | + std::shared_ptr<cairo_t> cairo_context(cairo.GetContext(), cairo_destroy); |
623 | + cairo_t* cr = cairo_context.get(); |
624 | |
625 | cairo_set_operator(cr, CAIRO_OPERATOR_SOURCE); |
626 | cairo_set_source_rgba(cr, color.red, color.blue, color.green, color.alpha); |
627 | - cairo->DrawRoundedRectangle(cr, 1.0f, 0.0f, 0.0f, ITEM_CORNER_RADIUS_ABS, |
628 | - width, height); |
629 | + cairo.DrawRoundedRectangle(cr, 1.0f, 0.0f, 0.0f, ITEM_CORNER_RADIUS_ABS, width, height); |
630 | cairo_fill(cr); |
631 | - cairo_destroy(cr); |
632 | -} |
633 | - |
634 | -void |
635 | -QuicklistMenuItem::EnableLabelMarkup(bool enabled) |
636 | +} |
637 | + |
638 | +double QuicklistMenuItem::Align(double val) |
639 | +{ |
640 | + const double fract = val - static_cast<int>(val); |
641 | + |
642 | + if (fract != 0.5f) |
643 | + return static_cast<double>(static_cast<int>(val) + 0.5f); |
644 | + else |
645 | + return val; |
646 | +} |
647 | + |
648 | +void QuicklistMenuItem::EnableLabelMarkup(bool enabled) |
649 | { |
650 | if (IsMarkupEnabled() != enabled) |
651 | { |
652 | - dbusmenu_menuitem_property_set_bool(_menuItem, "unity-use-markup", enabled); |
653 | + dbusmenu_menuitem_property_set_bool(_menu_item, "unity-use-markup", enabled); |
654 | |
655 | _text = ""; |
656 | InitializeText(); |
657 | } |
658 | } |
659 | |
660 | -bool |
661 | -QuicklistMenuItem::IsMarkupEnabled() |
662 | +bool QuicklistMenuItem::IsMarkupEnabled() const |
663 | { |
664 | - gboolean markup; |
665 | - |
666 | - if (!_menuItem) |
667 | + if (!_menu_item) |
668 | return false; |
669 | |
670 | - markup = dbusmenu_menuitem_property_get_bool(_menuItem, "unity-use-markup"); |
671 | + gboolean markup = dbusmenu_menuitem_property_get_bool(_menu_item, "unity-use-markup"); |
672 | return (markup != FALSE); |
673 | } |
674 | |
675 | +unsigned QuicklistMenuItem::GetCairoSurfaceWidth() const |
676 | +{ |
677 | + if (!_normalTexture[0]) |
678 | + return 0; |
679 | + |
680 | + return _normalTexture[0]->GetWidth(); |
681 | +} |
682 | + |
683 | // Introspection |
684 | |
685 | std::string QuicklistMenuItem::GetName() const |
686 | { |
687 | - return _name; |
688 | + return "QuicklistMenuItem"; |
689 | } |
690 | |
691 | void QuicklistMenuItem::AddProperties(GVariantBuilder* builder) |
692 | |
693 | === modified file 'launcher/QuicklistMenuItem.h' |
694 | --- launcher/QuicklistMenuItem.h 2012-05-25 20:49:27 +0000 |
695 | +++ launcher/QuicklistMenuItem.h 2012-08-13 14:28:23 +0000 |
696 | @@ -1,6 +1,6 @@ |
697 | // -*- Mode: C++; indent-tabs-mode: nil; tab-width: 2 -*- |
698 | /* |
699 | - * Copyright (C) 2010 Canonical Ltd |
700 | + * Copyright (C) 2010-2012 Canonical Ltd |
701 | * |
702 | * This program is free software: you can redistribute it and/or modify |
703 | * it under the terms of the GNU General Public License version 3 as |
704 | @@ -15,18 +15,18 @@ |
705 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
706 | * |
707 | * Authored by: Mirco Müller <mirco.mueller@canonical.com> |
708 | - * Authored by: Jay Taoko <jay.taoko@canonical.com> |
709 | + * Jay Taoko <jay.taoko@canonical.com> |
710 | + * Marco Trevisan <marco.trevisan@canonical.com> |
711 | */ |
712 | |
713 | #ifndef QUICKLISTMENUITEM_H |
714 | #define QUICKLISTMENUITEM_H |
715 | |
716 | -#include <libdbusmenu-glib/menuitem.h> |
717 | -#include <libdbusmenu-glib/client.h> |
718 | - |
719 | #include <Nux/Nux.h> |
720 | #include <Nux/View.h> |
721 | #include <NuxGraphics/CairoGraphics.h> |
722 | +#include <libdbusmenu-glib/menuitem.h> |
723 | +#include <UnityCore/GLibWrapper.h> |
724 | |
725 | #include <pango/pango.h> |
726 | #include <pango/pangocairo.h> |
727 | @@ -36,56 +36,48 @@ |
728 | namespace unity |
729 | { |
730 | |
731 | -enum QuicklistMenuItemType |
732 | +enum class QuicklistMenuItemType |
733 | { |
734 | - MENUITEM_TYPE_UNKNOWN = 0, |
735 | - MENUITEM_TYPE_LABEL, |
736 | - MENUITEM_TYPE_SEPARATOR, |
737 | - MENUITEM_TYPE_CHECK, |
738 | - MENUITEM_TYPE_RADIO, |
739 | + UNKNOWN = 0, |
740 | + LABEL, |
741 | + SEPARATOR, |
742 | + CHECK, |
743 | + RADIO |
744 | }; |
745 | |
746 | class QuicklistMenuItem : public nux::View, public debug::Introspectable |
747 | { |
748 | NUX_DECLARE_OBJECT_TYPE(QuicklistMenuItem, nux::View); |
749 | public: |
750 | - QuicklistMenuItem(DbusmenuMenuitem* item, |
751 | - NUX_FILE_LINE_PROTO); |
752 | - |
753 | - QuicklistMenuItem(DbusmenuMenuitem* item, |
754 | - bool debug, |
755 | - NUX_FILE_LINE_PROTO); |
756 | - |
757 | + QuicklistMenuItem(QuicklistMenuItemType type, DbusmenuMenuitem* item, NUX_FILE_LINE_PROTO); |
758 | virtual ~QuicklistMenuItem(); |
759 | |
760 | - void PreLayoutManagement(); |
761 | - |
762 | - long PostLayoutManagement(long layoutResult); |
763 | - |
764 | - void Draw(nux::GraphicsEngine& gfxContext, |
765 | - bool forceDraw); |
766 | - |
767 | - void DrawContent(nux::GraphicsEngine& gfxContext, |
768 | - bool forceDraw); |
769 | - |
770 | - void PostDraw(nux::GraphicsEngine& gfxContext, |
771 | - bool forceDraw); |
772 | - |
773 | - QuicklistMenuItemType GetItemType(); |
774 | - |
775 | - void ItemActivated(); |
776 | + QuicklistMenuItemType GetItemType() const; |
777 | + virtual std::string GetLabel() const; |
778 | + virtual bool GetEnabled() const; |
779 | + virtual bool GetActive() const; |
780 | + virtual bool GetVisible() const; |
781 | + virtual bool GetSelectable() const; |
782 | + |
783 | void EnableLabelMarkup(bool enabled); |
784 | - bool IsMarkupEnabled(); |
785 | - |
786 | - sigc::signal<void, QuicklistMenuItem&> sigChanged; |
787 | + bool IsMarkupEnabled() const; |
788 | + |
789 | + void Activate() const; |
790 | + |
791 | + void Select(bool select = true); |
792 | + bool IsSelected() const; |
793 | + |
794 | + nux::Size const& GetTextExtents() const; |
795 | + virtual void UpdateTexture() = 0; |
796 | + unsigned GetCairoSurfaceWidth() const; |
797 | + |
798 | sigc::signal<void, QuicklistMenuItem*> sigTextChanged; |
799 | sigc::signal<void, QuicklistMenuItem*> sigColorChanged; |
800 | - |
801 | - virtual const gchar* GetLabel(); |
802 | - virtual bool GetEnabled(); |
803 | - virtual bool GetActive(); |
804 | - virtual bool GetVisible(); |
805 | - virtual bool GetSelectable(); |
806 | + sigc::signal<void, QuicklistMenuItem*> sigMouseEnter; |
807 | + sigc::signal<void, QuicklistMenuItem*> sigMouseLeave; |
808 | + sigc::signal<void, QuicklistMenuItem*, int, int> sigMouseReleased; |
809 | + sigc::signal<void, QuicklistMenuItem*, int, int> sigMouseClick; |
810 | + sigc::signal<void, QuicklistMenuItem*, int, int> sigMouseDrag; |
811 | |
812 | protected: |
813 | // Introspection |
814 | @@ -96,25 +88,12 @@ |
815 | static const int ITEM_CORNER_RADIUS_ABS = 3; |
816 | static const int ITEM_MARGIN = 4; |
817 | |
818 | - std::string _text; |
819 | - nux::Color _textColor; |
820 | - int _pre_layout_width; |
821 | - int _pre_layout_height; |
822 | - nux::CairoGraphics* _cairoGraphics; |
823 | - |
824 | - nux::BaseTexture* _normalTexture[2]; |
825 | - nux::BaseTexture* _prelightTexture[2]; |
826 | - |
827 | - void Initialize(DbusmenuMenuitem* item, bool debug); |
828 | void InitializeText(); |
829 | - virtual const gchar* GetDefaultText(); |
830 | - |
831 | - gchar* GetText(); |
832 | - //! Return the size of the text + size of associated radio button or check box |
833 | - void GetTextExtents(int& width, int& height); |
834 | - void GetTextExtents(const gchar* font, int& width, int& height); |
835 | - virtual void UpdateTexture() = 0; |
836 | - virtual int CairoSurfaceWidth() = 0; |
837 | + |
838 | + virtual std::string GetDefaultText() const; |
839 | + std::string GetText() const; |
840 | + |
841 | + static double Align(double val); |
842 | |
843 | void RecvMouseEnter(int x, int y, unsigned long button_flags, unsigned long key_flags); |
844 | void RecvMouseLeave(int x, int y, unsigned long button_flags, unsigned long key_flags); |
845 | @@ -122,27 +101,21 @@ |
846 | void RecvMouseClick(int x, int y, unsigned long button_flags, unsigned long key_flags); |
847 | void RecvMouseDrag(int x, int y, int dx, int dy, unsigned long button_flags, unsigned long key_flags); |
848 | |
849 | - sigc::signal<void, QuicklistMenuItem*> sigMouseEnter; |
850 | - sigc::signal<void, QuicklistMenuItem*> sigMouseLeave; |
851 | - sigc::signal<void, QuicklistMenuItem*, int, int> sigMouseReleased; |
852 | - sigc::signal<void, QuicklistMenuItem*, int, int> sigMouseClick; |
853 | - sigc::signal<void, QuicklistMenuItem*, int, int> sigMouseDrag; |
854 | + void PreLayoutManagement(); |
855 | + long PostLayoutManagement(long layoutResult); |
856 | + void Draw(nux::GraphicsEngine& gfxContext, bool forceDraw); |
857 | + void DrawText(nux::CairoGraphics& cairo, int width, int height, nux::Color const& color); |
858 | + void DrawPrelight(nux::CairoGraphics& cairo, int width, int height, nux::Color const& color); |
859 | |
860 | - DbusmenuMenuitem* _menuItem; |
861 | + nux::ObjectPtr<nux::BaseTexture> _normalTexture[2]; |
862 | + nux::ObjectPtr<nux::BaseTexture> _prelightTexture[2]; |
863 | QuicklistMenuItemType _item_type; |
864 | - |
865 | - nux::Color _color; //!< Item rendering color factor. |
866 | - bool _debug; |
867 | - |
868 | - bool _prelight; //!< True when the mouse is over the item. |
869 | - |
870 | - void DrawText(nux::CairoGraphics* cairo, int width, int height, nux::Color const& color); |
871 | - void DrawPrelight(nux::CairoGraphics* cairo, int width, int height, nux::Color const& color); |
872 | - |
873 | - // Introspection |
874 | - std::string _name; |
875 | - |
876 | - friend class QuicklistView; |
877 | + glib::Object<DbusmenuMenuitem> _menu_item; |
878 | + bool _prelight; |
879 | + int _pre_layout_width; |
880 | + int _pre_layout_height; |
881 | + nux::Size _text_extents; |
882 | + std::string _text; |
883 | }; |
884 | |
885 | } // NAMESPACE |
886 | |
887 | === modified file 'launcher/QuicklistMenuItemCheckmark.cpp' |
888 | --- launcher/QuicklistMenuItemCheckmark.cpp 2012-05-07 22:28:17 +0000 |
889 | +++ launcher/QuicklistMenuItemCheckmark.cpp 2012-08-13 14:28:23 +0000 |
890 | @@ -1,6 +1,6 @@ |
891 | // -*- Mode: C++; indent-tabs-mode: nil; tab-width: 2 -*- |
892 | /* |
893 | - * Copyright (C) 2010 Canonical Ltd |
894 | + * Copyright (C) 2010-2012 Canonical Ltd |
895 | * |
896 | * This program is free software: you can redistribute it and/or modify |
897 | * it under the terms of the GNU General Public License version 3 as |
898 | @@ -15,165 +15,40 @@ |
899 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
900 | * |
901 | * Authored by: Mirco Müller <mirco.mueller@canonical.com> |
902 | - * Authored by: Jay Taoko <jay.taoko@canonical.com> |
903 | + * Jay Taoko <jay.taoko@canonical.com> |
904 | + * Marco Trevisan <marco.trevisan@canonical.com> |
905 | */ |
906 | |
907 | -#include <gdk/gdk.h> |
908 | -#include <gtk/gtk.h> |
909 | - |
910 | -#include <Nux/Nux.h> |
911 | - |
912 | #include "unity-shared/CairoTexture.h" |
913 | #include "QuicklistMenuItemCheckmark.h" |
914 | |
915 | namespace unity |
916 | { |
917 | |
918 | -static double |
919 | -_align(double val) |
920 | -{ |
921 | - double fract = val - (int) val; |
922 | - |
923 | - if (fract != 0.5f) |
924 | - return (double)((int) val + 0.5f); |
925 | - else |
926 | - return val; |
927 | -} |
928 | - |
929 | -QuicklistMenuItemCheckmark::QuicklistMenuItemCheckmark(DbusmenuMenuitem* item, |
930 | - NUX_FILE_LINE_DECL) : |
931 | - QuicklistMenuItem(item, |
932 | - NUX_FILE_LINE_PARAM) |
933 | -{ |
934 | - _item_type = MENUITEM_TYPE_CHECK; |
935 | - _name = "QuicklistMenuItemCheckmark"; |
936 | - InitializeText(); |
937 | -} |
938 | - |
939 | -QuicklistMenuItemCheckmark::QuicklistMenuItemCheckmark(DbusmenuMenuitem* item, |
940 | - bool debug, |
941 | - NUX_FILE_LINE_DECL) : |
942 | - QuicklistMenuItem(item, |
943 | - debug, |
944 | - NUX_FILE_LINE_PARAM) |
945 | -{ |
946 | - _item_type = MENUITEM_TYPE_CHECK; |
947 | - _name = "QuicklistMenuItemCheckmark"; |
948 | - InitializeText(); |
949 | -} |
950 | - |
951 | -QuicklistMenuItemCheckmark::~QuicklistMenuItemCheckmark() |
952 | -{} |
953 | - |
954 | -const gchar* |
955 | -QuicklistMenuItemCheckmark::GetDefaultText() |
956 | +QuicklistMenuItemCheckmark::QuicklistMenuItemCheckmark(DbusmenuMenuitem* item, NUX_FILE_LINE_DECL) |
957 | + : QuicklistMenuItem(QuicklistMenuItemType::CHECK, item, NUX_FILE_LINE_PARAM) |
958 | +{ |
959 | + InitializeText(); |
960 | +} |
961 | + |
962 | +std::string QuicklistMenuItemCheckmark::GetDefaultText() const |
963 | { |
964 | return "Check Mark"; |
965 | } |
966 | |
967 | -void |
968 | -QuicklistMenuItemCheckmark::PreLayoutManagement() |
969 | -{ |
970 | - _pre_layout_width = GetBaseWidth(); |
971 | - _pre_layout_height = GetBaseHeight(); |
972 | - |
973 | - if (_normalTexture[0] == 0) |
974 | - { |
975 | - UpdateTexture(); |
976 | - } |
977 | - |
978 | - QuicklistMenuItem::PreLayoutManagement(); |
979 | -} |
980 | - |
981 | -long |
982 | -QuicklistMenuItemCheckmark::PostLayoutManagement(long layoutResult) |
983 | -{ |
984 | - int w = GetBaseWidth(); |
985 | - int h = GetBaseHeight(); |
986 | - |
987 | - long result = 0; |
988 | - |
989 | - if (_pre_layout_width < w) |
990 | - result |= nux::eLargerWidth; |
991 | - else if (_pre_layout_width > w) |
992 | - result |= nux::eSmallerWidth; |
993 | - else |
994 | - result |= nux::eCompliantWidth; |
995 | - |
996 | - if (_pre_layout_height < h) |
997 | - result |= nux::eLargerHeight; |
998 | - else if (_pre_layout_height > h) |
999 | - result |= nux::eSmallerHeight; |
1000 | - else |
1001 | - result |= nux::eCompliantHeight; |
1002 | - |
1003 | - return result; |
1004 | -} |
1005 | - |
1006 | -void |
1007 | -QuicklistMenuItemCheckmark::Draw(nux::GraphicsEngine& gfxContext, bool forceDraw) |
1008 | -{ |
1009 | - nux::ObjectPtr<nux::IOpenGLBaseTexture> texture; |
1010 | - |
1011 | - // Check if the texture have been computed. If they haven't, exit the function. |
1012 | - if (!_normalTexture[0] || !_prelightTexture[0]) |
1013 | - return; |
1014 | - |
1015 | - nux::Geometry base = GetGeometry(); |
1016 | - |
1017 | - gfxContext.PushClippingRectangle(base); |
1018 | - |
1019 | - nux::TexCoordXForm texxform; |
1020 | - texxform.SetWrap(nux::TEXWRAP_REPEAT, nux::TEXWRAP_REPEAT); |
1021 | - texxform.SetTexCoordType(nux::TexCoordXForm::OFFSET_COORD); |
1022 | - |
1023 | - gfxContext.GetRenderStates().SetBlend(true); |
1024 | - gfxContext.GetRenderStates().SetPremultipliedBlend(nux::SRC_OVER); |
1025 | - |
1026 | - unsigned int texture_idx = GetActive() ? 1 : 0; |
1027 | - |
1028 | - if (!_prelight || !GetEnabled()) |
1029 | - { |
1030 | - texture = _normalTexture[texture_idx]->GetDeviceTexture(); |
1031 | - } |
1032 | - else |
1033 | - { |
1034 | - texture = _prelightTexture[texture_idx]->GetDeviceTexture(); |
1035 | - } |
1036 | - |
1037 | - _color = GetEnabled() ? nux::color::White : nux::color::White * 0.35; |
1038 | - |
1039 | - gfxContext.QRP_1Tex(base.x, |
1040 | - base.y, |
1041 | - base.width, |
1042 | - base.height, |
1043 | - texture, |
1044 | - texxform, |
1045 | - _color); |
1046 | - |
1047 | - gfxContext.GetRenderStates().SetBlend(false); |
1048 | - |
1049 | - gfxContext.PopClippingRectangle(); |
1050 | -} |
1051 | - |
1052 | -void QuicklistMenuItemCheckmark::DrawContent(nux::GraphicsEngine& gfxContext, |
1053 | - bool forceDraw) |
1054 | -{ |
1055 | -} |
1056 | - |
1057 | -void QuicklistMenuItemCheckmark::PostDraw(nux::GraphicsEngine& gfxContext, |
1058 | - bool forceDraw) |
1059 | -{ |
1060 | -} |
1061 | - |
1062 | -void |
1063 | -QuicklistMenuItemCheckmark::UpdateTexture() |
1064 | -{ |
1065 | - int width = GetBaseWidth(); |
1066 | - int height = GetBaseHeight(); |
1067 | - |
1068 | - _cairoGraphics = new nux::CairoGraphics(CAIRO_FORMAT_ARGB32, width, height); |
1069 | - cairo_t* cr = _cairoGraphics->GetContext(); |
1070 | +std::string QuicklistMenuItemCheckmark::GetName() const |
1071 | +{ |
1072 | + return "QuicklistMenuItemCheckmark"; |
1073 | +} |
1074 | + |
1075 | +void QuicklistMenuItemCheckmark::UpdateTexture() |
1076 | +{ |
1077 | + int width = GetBaseWidth(); |
1078 | + int height = GetBaseHeight(); |
1079 | + |
1080 | + nux::CairoGraphics cairoGraphics(CAIRO_FORMAT_ARGB32, width, height); |
1081 | + std::shared_ptr<cairo_t> cairo_context(cairoGraphics.GetContext(), cairo_destroy); |
1082 | + cairo_t* cr = cairo_context.get(); |
1083 | |
1084 | // draw normal, unchecked version |
1085 | cairo_set_operator(cr, CAIRO_OPERATOR_CLEAR); |
1086 | @@ -184,11 +59,9 @@ |
1087 | cairo_set_source_rgba(cr, 1.0f, 1.0f, 1.0f, 1.0f); |
1088 | cairo_set_line_width(cr, 1.0f); |
1089 | |
1090 | - DrawText(_cairoGraphics, width, height, nux::color::White); |
1091 | + DrawText(cairoGraphics, width, height, nux::color::White); |
1092 | |
1093 | - if (_normalTexture[0]) |
1094 | - _normalTexture[0]->UnReference(); |
1095 | - _normalTexture[0] = texture_from_cairo_graphics(*_cairoGraphics); |
1096 | + _normalTexture[0].Adopt(texture_from_cairo_graphics(cairoGraphics)); |
1097 | |
1098 | // draw normal, checked version |
1099 | cairo_set_operator(cr, CAIRO_OPERATOR_CLEAR); |
1100 | @@ -200,9 +73,8 @@ |
1101 | cairo_set_line_width(cr, 1.0f); |
1102 | |
1103 | cairo_save(cr); |
1104 | - cairo_translate(cr, |
1105 | - _align((ITEM_INDENT_ABS - 16.0f + ITEM_MARGIN) / 2.0f), |
1106 | - _align(((double) height - 16.0f) / 2.0f)); |
1107 | + cairo_translate(cr, Align((ITEM_INDENT_ABS - 16.0f + ITEM_MARGIN) / 2.0f), |
1108 | + Align((static_cast<double>(height) - 16.0f) / 2.0f)); |
1109 | |
1110 | cairo_set_source_rgba(cr, 1.0f, 1.0f, 1.0f, 1.0f); |
1111 | |
1112 | @@ -221,37 +93,30 @@ |
1113 | |
1114 | cairo_restore(cr); |
1115 | |
1116 | - DrawText(_cairoGraphics, width, height, nux::color::White); |
1117 | - |
1118 | - if (_normalTexture[1]) |
1119 | - _normalTexture[1]->UnReference(); |
1120 | - |
1121 | - _normalTexture[1] = texture_from_cairo_graphics(*_cairoGraphics); |
1122 | + DrawText(cairoGraphics, width, height, nux::color::White); |
1123 | + |
1124 | + _normalTexture[1].Adopt(texture_from_cairo_graphics(cairoGraphics)); |
1125 | |
1126 | // draw active/prelight, unchecked version |
1127 | cairo_set_operator(cr, CAIRO_OPERATOR_CLEAR); |
1128 | cairo_paint(cr); |
1129 | |
1130 | - DrawPrelight(_cairoGraphics, width, height, nux::color::White); |
1131 | - DrawText(_cairoGraphics, width, height, nux::color::White * 0.0f); |
1132 | - |
1133 | - if (_prelightTexture[0]) |
1134 | - _prelightTexture[0]->UnReference(); |
1135 | - |
1136 | - _prelightTexture[0] = texture_from_cairo_graphics(*_cairoGraphics); |
1137 | + DrawPrelight(cairoGraphics, width, height, nux::color::White); |
1138 | + DrawText(cairoGraphics, width, height, nux::color::White * 0.0f); |
1139 | + |
1140 | + _prelightTexture[0].Adopt(texture_from_cairo_graphics(cairoGraphics)); |
1141 | |
1142 | // draw active/prelight, checked version |
1143 | cairo_set_operator(cr, CAIRO_OPERATOR_CLEAR); |
1144 | cairo_paint(cr); |
1145 | |
1146 | - DrawPrelight(_cairoGraphics, width, height, nux::color::White); |
1147 | + DrawPrelight(cairoGraphics, width, height, nux::color::White); |
1148 | |
1149 | cairo_set_source_rgba(cr, 0.0f, 0.0f, 0.0f, 0.0f); |
1150 | |
1151 | cairo_save(cr); |
1152 | - cairo_translate(cr, |
1153 | - _align((ITEM_INDENT_ABS - 16.0f + ITEM_MARGIN) / 2.0f), |
1154 | - _align(((double) height - 16.0f) / 2.0f)); |
1155 | + cairo_translate(cr, Align((ITEM_INDENT_ABS - 16.0f + ITEM_MARGIN) / 2.0f), |
1156 | + Align((static_cast<double>(height) - 16.0f) / 2.0f)); |
1157 | |
1158 | cairo_translate(cr, 3.0f, 1.0f); |
1159 | cairo_move_to(cr, 0.0f, 6.0f); |
1160 | @@ -268,24 +133,9 @@ |
1161 | |
1162 | cairo_restore(cr); |
1163 | |
1164 | - DrawText(_cairoGraphics, width, height, nux::color::White * 0.0f); |
1165 | - |
1166 | - if (_prelightTexture[1]) |
1167 | - _prelightTexture[1]->UnReference(); |
1168 | - |
1169 | - _prelightTexture[1] = texture_from_cairo_graphics(*_cairoGraphics); |
1170 | - |
1171 | - // finally clean up |
1172 | - cairo_destroy(cr); |
1173 | - delete _cairoGraphics; |
1174 | -} |
1175 | - |
1176 | -int QuicklistMenuItemCheckmark::CairoSurfaceWidth() |
1177 | -{ |
1178 | - if (_normalTexture[0]) |
1179 | - return _normalTexture[0]->GetWidth(); |
1180 | - |
1181 | - return 0; |
1182 | + DrawText(cairoGraphics, width, height, nux::color::White * 0.0f); |
1183 | + |
1184 | + _prelightTexture[1].Adopt(texture_from_cairo_graphics(cairoGraphics)); |
1185 | } |
1186 | |
1187 | } |
1188 | |
1189 | === modified file 'launcher/QuicklistMenuItemCheckmark.h' |
1190 | --- launcher/QuicklistMenuItemCheckmark.h 2012-05-25 20:49:27 +0000 |
1191 | +++ launcher/QuicklistMenuItemCheckmark.h 2012-08-13 14:28:23 +0000 |
1192 | @@ -15,51 +15,28 @@ |
1193 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
1194 | * |
1195 | * Authored by: Mirco Müller <mirco.mueller@canonical.com> |
1196 | - * Authored by: Jay Taoko <jay.taoko@canonical.com> |
1197 | + * Jay Taoko <jay.taoko@canonical.com> |
1198 | + * Marco Trevisan <marco.trevisan@canonical.com> |
1199 | */ |
1200 | |
1201 | #ifndef QUICKLISTMENUITEMCHECKMARK_H |
1202 | #define QUICKLISTMENUITEMCHECKMARK_H |
1203 | |
1204 | -#include <Nux/Nux.h> |
1205 | -#include <Nux/View.h> |
1206 | -#include <NuxGraphics/CairoGraphics.h> |
1207 | - |
1208 | #include "QuicklistMenuItem.h" |
1209 | |
1210 | -#include <X11/Xlib.h> |
1211 | - |
1212 | namespace unity |
1213 | { |
1214 | |
1215 | class QuicklistMenuItemCheckmark : public QuicklistMenuItem |
1216 | { |
1217 | public: |
1218 | - QuicklistMenuItemCheckmark(DbusmenuMenuitem* item, |
1219 | - NUX_FILE_LINE_PROTO); |
1220 | - |
1221 | - QuicklistMenuItemCheckmark(DbusmenuMenuitem* item, |
1222 | - bool debug, |
1223 | - NUX_FILE_LINE_PROTO); |
1224 | - |
1225 | - ~QuicklistMenuItemCheckmark(); |
1226 | + QuicklistMenuItemCheckmark(DbusmenuMenuitem* item, NUX_FILE_LINE_PROTO); |
1227 | |
1228 | protected: |
1229 | - |
1230 | - void PreLayoutManagement(); |
1231 | - |
1232 | - long PostLayoutManagement(long layoutResult); |
1233 | - |
1234 | - void Draw(nux::GraphicsEngine& gfxContext, bool forceDraw); |
1235 | - |
1236 | - void DrawContent(nux::GraphicsEngine& gfxContext, bool forceDraw); |
1237 | - |
1238 | - void PostDraw(nux::GraphicsEngine& gfxContext, bool forceDraw); |
1239 | - |
1240 | - virtual const gchar* GetDefaultText(); |
1241 | - |
1242 | + std::string GetName() const; |
1243 | + |
1244 | + virtual std::string GetDefaultText() const; |
1245 | virtual void UpdateTexture(); |
1246 | - virtual int CairoSurfaceWidth(); |
1247 | }; |
1248 | |
1249 | } // NAMESPACE |
1250 | |
1251 | === modified file 'launcher/QuicklistMenuItemLabel.cpp' |
1252 | --- launcher/QuicklistMenuItemLabel.cpp 2012-05-07 22:28:17 +0000 |
1253 | +++ launcher/QuicklistMenuItemLabel.cpp 2012-08-13 14:28:23 +0000 |
1254 | @@ -1,6 +1,6 @@ |
1255 | // -*- Mode: C++; indent-tabs-mode: nil; tab-width: 2 -*- |
1256 | /* |
1257 | - * Copyright (C) 2010 Canonical Ltd |
1258 | + * Copyright (C) 2010-2012 Canonical Ltd |
1259 | * |
1260 | * This program is free software: you can redistribute it and/or modify |
1261 | * it under the terms of the GNU General Public License version 3 as |
1262 | @@ -15,197 +15,57 @@ |
1263 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
1264 | * |
1265 | * Authored by: Mirco Müller <mirco.mueller@canonical.com> |
1266 | - * Authored by: Jay Taoko <jay.taoko@canonical.com> |
1267 | + * Jay Taoko <jay.taoko@canonical.com> |
1268 | + * Marco Trevisan <marco.trevisan@canonical.com> |
1269 | */ |
1270 | |
1271 | -#include <gdk/gdk.h> |
1272 | -#include <gtk/gtk.h> |
1273 | - |
1274 | -#include <Nux/Nux.h> |
1275 | - |
1276 | #include "unity-shared/CairoTexture.h" |
1277 | #include "QuicklistMenuItemLabel.h" |
1278 | |
1279 | namespace unity |
1280 | { |
1281 | |
1282 | -QuicklistMenuItemLabel::QuicklistMenuItemLabel(DbusmenuMenuitem* item, |
1283 | - NUX_FILE_LINE_DECL) : |
1284 | - QuicklistMenuItem(item, |
1285 | - NUX_FILE_LINE_PARAM) |
1286 | -{ |
1287 | - _item_type = MENUITEM_TYPE_LABEL; |
1288 | - _name = "QuicklistMenuItemLabel"; |
1289 | - InitializeText(); |
1290 | -} |
1291 | - |
1292 | -QuicklistMenuItemLabel::QuicklistMenuItemLabel(DbusmenuMenuitem* item, |
1293 | - bool debug, |
1294 | - NUX_FILE_LINE_DECL) : |
1295 | - QuicklistMenuItem(item, |
1296 | - debug, |
1297 | - NUX_FILE_LINE_PARAM) |
1298 | -{ |
1299 | - _item_type = MENUITEM_TYPE_LABEL; |
1300 | - _name = "QuicklistMenuItemLabel"; |
1301 | - InitializeText(); |
1302 | -} |
1303 | - |
1304 | -QuicklistMenuItemLabel::~QuicklistMenuItemLabel() |
1305 | -{} |
1306 | - |
1307 | -const gchar* |
1308 | -QuicklistMenuItemLabel::GetDefaultText() |
1309 | +QuicklistMenuItemLabel::QuicklistMenuItemLabel(DbusmenuMenuitem* item, NUX_FILE_LINE_DECL) |
1310 | + : QuicklistMenuItem(QuicklistMenuItemType::LABEL, item, NUX_FILE_LINE_PARAM) |
1311 | +{ |
1312 | + InitializeText(); |
1313 | +} |
1314 | + |
1315 | +std::string QuicklistMenuItemLabel::GetDefaultText() const |
1316 | { |
1317 | return "Label"; |
1318 | } |
1319 | |
1320 | -void |
1321 | -QuicklistMenuItemLabel::PreLayoutManagement() |
1322 | -{ |
1323 | - _pre_layout_width = GetBaseWidth(); |
1324 | - _pre_layout_height = GetBaseHeight(); |
1325 | - |
1326 | - if (_normalTexture[0] == 0) |
1327 | - { |
1328 | - UpdateTexture(); |
1329 | - } |
1330 | - |
1331 | - QuicklistMenuItem::PreLayoutManagement(); |
1332 | -} |
1333 | - |
1334 | -long |
1335 | -QuicklistMenuItemLabel::PostLayoutManagement(long layoutResult) |
1336 | -{ |
1337 | - int w = GetBaseWidth(); |
1338 | - int h = GetBaseHeight(); |
1339 | - |
1340 | - long result = 0; |
1341 | - |
1342 | - if (_pre_layout_width < w) |
1343 | - result |= nux::eLargerWidth; |
1344 | - else if (_pre_layout_width > w) |
1345 | - result |= nux::eSmallerWidth; |
1346 | - else |
1347 | - result |= nux::eCompliantWidth; |
1348 | - |
1349 | - if (_pre_layout_height < h) |
1350 | - result |= nux::eLargerHeight; |
1351 | - else if (_pre_layout_height > h) |
1352 | - result |= nux::eSmallerHeight; |
1353 | - else |
1354 | - result |= nux::eCompliantHeight; |
1355 | - |
1356 | - return result; |
1357 | -} |
1358 | - |
1359 | -void |
1360 | -QuicklistMenuItemLabel::Draw(nux::GraphicsEngine& gfxContext, |
1361 | - bool forceDraw) |
1362 | -{ |
1363 | - // Check if the texture have been computed. If they haven't, exit the function. |
1364 | - if (_normalTexture[0] == NULL) |
1365 | - return; |
1366 | - |
1367 | - nux::ObjectPtr<nux::IOpenGLBaseTexture> texture; |
1368 | - |
1369 | - nux::Geometry base = GetGeometry(); |
1370 | - |
1371 | - gfxContext.PushClippingRectangle(base); |
1372 | - |
1373 | - nux::TexCoordXForm texxform; |
1374 | - texxform.SetWrap(nux::TEXWRAP_REPEAT, nux::TEXWRAP_REPEAT); |
1375 | - texxform.SetTexCoordType(nux::TexCoordXForm::OFFSET_COORD); |
1376 | - |
1377 | - gfxContext.GetRenderStates().SetBlend(true); |
1378 | - gfxContext.GetRenderStates().SetPremultipliedBlend(nux::SRC_OVER); |
1379 | - |
1380 | - if (GetEnabled()) |
1381 | - { |
1382 | - if (_prelight) |
1383 | - { |
1384 | - texture = _prelightTexture[0]->GetDeviceTexture(); |
1385 | - } |
1386 | - else |
1387 | - { |
1388 | - texture = _normalTexture[0]->GetDeviceTexture(); |
1389 | - } |
1390 | - _color = nux::color::White; |
1391 | - } |
1392 | - else |
1393 | - { |
1394 | - texture = _normalTexture[0]->GetDeviceTexture(); |
1395 | - _color = nux::color::White * 0.35; |
1396 | - } |
1397 | - |
1398 | - gfxContext.QRP_1Tex(base.x, |
1399 | - base.y, |
1400 | - base.width, |
1401 | - base.height, |
1402 | - texture, |
1403 | - texxform, |
1404 | - _color); |
1405 | - |
1406 | - gfxContext.GetRenderStates().SetBlend(false); |
1407 | - |
1408 | - gfxContext.PopClippingRectangle(); |
1409 | -} |
1410 | - |
1411 | -void |
1412 | -QuicklistMenuItemLabel::DrawContent(nux::GraphicsEngine& gfxContext, |
1413 | - bool forceDraw) |
1414 | -{ |
1415 | -} |
1416 | - |
1417 | -void |
1418 | -QuicklistMenuItemLabel::PostDraw(nux::GraphicsEngine& gfxContext, |
1419 | - bool forceDraw) |
1420 | -{ |
1421 | -} |
1422 | - |
1423 | -void |
1424 | -QuicklistMenuItemLabel::UpdateTexture() |
1425 | -{ |
1426 | - int width = GetBaseWidth(); |
1427 | - int height = GetBaseHeight(); |
1428 | - |
1429 | - _cairoGraphics = new nux::CairoGraphics(CAIRO_FORMAT_ARGB32, width, height); |
1430 | - cairo_t* cr = _cairoGraphics->GetContext(); |
1431 | +std::string QuicklistMenuItemLabel::GetName() const |
1432 | +{ |
1433 | + return "QuicklistMenuItemLabel"; |
1434 | +} |
1435 | + |
1436 | +void QuicklistMenuItemLabel::UpdateTexture() |
1437 | +{ |
1438 | + int width = GetBaseWidth(); |
1439 | + int height = GetBaseHeight(); |
1440 | + |
1441 | + nux::CairoGraphics cairoGraphics(CAIRO_FORMAT_ARGB32, width, height); |
1442 | + std::shared_ptr<cairo_t> cairo_context(cairoGraphics.GetContext(), cairo_destroy); |
1443 | + cairo_t* cr = cairo_context.get(); |
1444 | |
1445 | // draw normal, unchecked version |
1446 | cairo_set_operator(cr, CAIRO_OPERATOR_CLEAR); |
1447 | cairo_paint(cr); |
1448 | |
1449 | - DrawText(_cairoGraphics, width, height, nux::color::White); |
1450 | - |
1451 | - if (_normalTexture[0]) |
1452 | - _normalTexture[0]->UnReference(); |
1453 | - |
1454 | - _normalTexture[0] = texture_from_cairo_graphics(*_cairoGraphics); |
1455 | + DrawText(cairoGraphics, width, height, nux::color::White); |
1456 | + |
1457 | + _normalTexture[0].Adopt(texture_from_cairo_graphics(cairoGraphics)); |
1458 | |
1459 | // draw active/prelight, unchecked version |
1460 | cairo_set_operator(cr, CAIRO_OPERATOR_CLEAR); |
1461 | cairo_paint(cr); |
1462 | |
1463 | - DrawPrelight(_cairoGraphics, width, height, nux::color::White); |
1464 | - DrawText(_cairoGraphics, width, height, nux::color::White * 0.0f); |
1465 | - |
1466 | - if (_prelightTexture[0]) |
1467 | - _prelightTexture[0]->UnReference(); |
1468 | - |
1469 | - _prelightTexture[0] = texture_from_cairo_graphics(*_cairoGraphics); |
1470 | - |
1471 | - // finally clean up |
1472 | - cairo_destroy(cr); |
1473 | - delete _cairoGraphics; |
1474 | -} |
1475 | - |
1476 | -int QuicklistMenuItemLabel::CairoSurfaceWidth() |
1477 | -{ |
1478 | - if (_normalTexture[0]) |
1479 | - return _normalTexture[0]->GetWidth(); |
1480 | - |
1481 | - return 0; |
1482 | + DrawPrelight(cairoGraphics, width, height, nux::color::White); |
1483 | + DrawText(cairoGraphics, width, height, nux::color::White * 0.0f); |
1484 | + |
1485 | + _prelightTexture[0].Adopt(texture_from_cairo_graphics(cairoGraphics)); |
1486 | } |
1487 | |
1488 | } // NAMESPACE |
1489 | |
1490 | === modified file 'launcher/QuicklistMenuItemLabel.h' |
1491 | --- launcher/QuicklistMenuItemLabel.h 2012-05-25 20:49:27 +0000 |
1492 | +++ launcher/QuicklistMenuItemLabel.h 2012-08-13 14:28:23 +0000 |
1493 | @@ -15,51 +15,28 @@ |
1494 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
1495 | * |
1496 | * Authored by: Mirco Müller <mirco.mueller@canonical.com> |
1497 | - * Authored by: Jay Taoko <jay.taoko@canonical.com> |
1498 | + * Jay Taoko <jay.taoko@canonical.com> |
1499 | + * Marco Trevisan <marco.trevisan@canonical.com> |
1500 | */ |
1501 | |
1502 | #ifndef QUICKLISTMENUITEMLABEL_H |
1503 | #define QUICKLISTMENUITEMLABEL_H |
1504 | |
1505 | -#include <Nux/Nux.h> |
1506 | -#include <Nux/View.h> |
1507 | -#include <NuxGraphics/CairoGraphics.h> |
1508 | - |
1509 | #include "QuicklistMenuItem.h" |
1510 | |
1511 | -#include <X11/Xlib.h> |
1512 | - |
1513 | namespace unity |
1514 | { |
1515 | |
1516 | class QuicklistMenuItemLabel : public QuicklistMenuItem |
1517 | { |
1518 | public: |
1519 | - QuicklistMenuItemLabel(DbusmenuMenuitem* item, |
1520 | - NUX_FILE_LINE_PROTO); |
1521 | - |
1522 | - QuicklistMenuItemLabel(DbusmenuMenuitem* item, |
1523 | - bool debug, |
1524 | - NUX_FILE_LINE_PROTO); |
1525 | - |
1526 | - ~QuicklistMenuItemLabel(); |
1527 | + QuicklistMenuItemLabel(DbusmenuMenuitem* item, NUX_FILE_LINE_PROTO); |
1528 | |
1529 | protected: |
1530 | - |
1531 | - void PreLayoutManagement(); |
1532 | - |
1533 | - long PostLayoutManagement(long layoutResult); |
1534 | - |
1535 | - void Draw(nux::GraphicsEngine& gfxContext, bool forceDraw); |
1536 | - |
1537 | - void DrawContent(nux::GraphicsEngine& gfxContext, bool forceDraw); |
1538 | - |
1539 | - void PostDraw(nux::GraphicsEngine& gfxContext, bool forceDraw); |
1540 | - |
1541 | - virtual const gchar* GetDefaultText(); |
1542 | - |
1543 | + std::string GetName() const; |
1544 | + |
1545 | + virtual std::string GetDefaultText() const; |
1546 | virtual void UpdateTexture(); |
1547 | - virtual int CairoSurfaceWidth(); |
1548 | }; |
1549 | |
1550 | } // NAMESPACE |
1551 | |
1552 | === modified file 'launcher/QuicklistMenuItemRadio.cpp' |
1553 | --- launcher/QuicklistMenuItemRadio.cpp 2012-05-07 22:28:17 +0000 |
1554 | +++ launcher/QuicklistMenuItemRadio.cpp 2012-08-13 14:28:23 +0000 |
1555 | @@ -1,6 +1,6 @@ |
1556 | // -*- Mode: C++; indent-tabs-mode: nil; tab-width: 2 -*- |
1557 | /* |
1558 | - * Copyright (C) 2010 Canonical Ltd |
1559 | + * Copyright (C) 2010-2012 Canonical Ltd |
1560 | * |
1561 | * This program is free software: you can redistribute it and/or modify |
1562 | * it under the terms of the GNU General Public License version 3 as |
1563 | @@ -15,177 +15,47 @@ |
1564 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
1565 | * |
1566 | * Authored by: Mirco Müller <mirco.mueller@canonical.com> |
1567 | + * Marco Trevisan <marco.trevisan@canonical.com> |
1568 | */ |
1569 | |
1570 | -#include <gdk/gdk.h> |
1571 | -#include <gtk/gtk.h> |
1572 | - |
1573 | -#include <Nux/Nux.h> |
1574 | - |
1575 | #include "unity-shared/CairoTexture.h" |
1576 | #include "QuicklistMenuItemRadio.h" |
1577 | |
1578 | namespace unity |
1579 | { |
1580 | |
1581 | -static double |
1582 | -_align(double val) |
1583 | -{ |
1584 | - double fract = val - (int) val; |
1585 | - |
1586 | - if (fract != 0.5f) |
1587 | - return (double)((int) val + 0.5f); |
1588 | - else |
1589 | - return val; |
1590 | -} |
1591 | - |
1592 | -QuicklistMenuItemRadio::QuicklistMenuItemRadio(DbusmenuMenuitem* item, |
1593 | - NUX_FILE_LINE_DECL) : |
1594 | - QuicklistMenuItem(item, |
1595 | - NUX_FILE_LINE_PARAM) |
1596 | -{ |
1597 | - _item_type = MENUITEM_TYPE_RADIO; |
1598 | - _name = "QuicklistMenuItemRadio"; |
1599 | - InitializeText(); |
1600 | -} |
1601 | - |
1602 | -QuicklistMenuItemRadio::QuicklistMenuItemRadio(DbusmenuMenuitem* item, |
1603 | - bool debug, |
1604 | - NUX_FILE_LINE_DECL) : |
1605 | - QuicklistMenuItem(item, |
1606 | - debug, |
1607 | - NUX_FILE_LINE_PARAM) |
1608 | -{ |
1609 | - _item_type = MENUITEM_TYPE_RADIO; |
1610 | - _name = "QuicklistMenuItemRadio"; |
1611 | - InitializeText(); |
1612 | -} |
1613 | - |
1614 | -QuicklistMenuItemRadio::~QuicklistMenuItemRadio() |
1615 | -{} |
1616 | - |
1617 | -const gchar* |
1618 | -QuicklistMenuItemRadio::GetDefaultText() |
1619 | +QuicklistMenuItemRadio::QuicklistMenuItemRadio(DbusmenuMenuitem* item, NUX_FILE_LINE_DECL) |
1620 | + : QuicklistMenuItem(QuicklistMenuItemType::RADIO, item, NUX_FILE_LINE_PARAM) |
1621 | +{ |
1622 | + InitializeText(); |
1623 | +} |
1624 | + |
1625 | +std::string QuicklistMenuItemRadio::GetDefaultText() const |
1626 | { |
1627 | return "Radio Button"; |
1628 | } |
1629 | |
1630 | -void |
1631 | -QuicklistMenuItemRadio::PreLayoutManagement() |
1632 | -{ |
1633 | - _pre_layout_width = GetBaseWidth(); |
1634 | - _pre_layout_height = GetBaseHeight(); |
1635 | - |
1636 | - if (_normalTexture[0] == 0) |
1637 | - { |
1638 | - UpdateTexture(); |
1639 | - } |
1640 | - |
1641 | - QuicklistMenuItem::PreLayoutManagement(); |
1642 | -} |
1643 | - |
1644 | -long |
1645 | -QuicklistMenuItemRadio::PostLayoutManagement(long layoutResult) |
1646 | -{ |
1647 | - int w = GetBaseWidth(); |
1648 | - int h = GetBaseHeight(); |
1649 | - |
1650 | - long result = 0; |
1651 | - |
1652 | - if (_pre_layout_width < w) |
1653 | - result |= nux::eLargerWidth; |
1654 | - else if (_pre_layout_width > w) |
1655 | - result |= nux::eSmallerWidth; |
1656 | - else |
1657 | - result |= nux::eCompliantWidth; |
1658 | - |
1659 | - if (_pre_layout_height < h) |
1660 | - result |= nux::eLargerHeight; |
1661 | - else if (_pre_layout_height > h) |
1662 | - result |= nux::eSmallerHeight; |
1663 | - else |
1664 | - result |= nux::eCompliantHeight; |
1665 | - |
1666 | - return result; |
1667 | -} |
1668 | - |
1669 | -void |
1670 | -QuicklistMenuItemRadio::Draw(nux::GraphicsEngine& gfxContext, bool forceDraw) |
1671 | -{ |
1672 | - nux::ObjectPtr<nux::IOpenGLBaseTexture> texture; |
1673 | - |
1674 | - // Check if the texture have been computed. If they haven't, exit the function. |
1675 | - if (!_normalTexture[0] || !_prelightTexture[0]) |
1676 | - return; |
1677 | - |
1678 | - nux::Geometry base = GetGeometry(); |
1679 | - |
1680 | - gfxContext.PushClippingRectangle(base); |
1681 | - |
1682 | - nux::TexCoordXForm texxform; |
1683 | - texxform.SetWrap(nux::TEXWRAP_REPEAT, nux::TEXWRAP_REPEAT); |
1684 | - texxform.SetTexCoordType(nux::TexCoordXForm::OFFSET_COORD); |
1685 | - |
1686 | - gfxContext.GetRenderStates().SetBlend(true); |
1687 | - gfxContext.GetRenderStates().SetPremultipliedBlend(nux::SRC_OVER); |
1688 | - |
1689 | - unsigned int texture_idx = GetActive() ? 1 : 0; |
1690 | - |
1691 | - if (!_prelight || !GetEnabled()) |
1692 | - { |
1693 | - texture = _normalTexture[texture_idx]->GetDeviceTexture(); |
1694 | - } |
1695 | - else |
1696 | - { |
1697 | - texture = _prelightTexture[texture_idx]->GetDeviceTexture(); |
1698 | - } |
1699 | - |
1700 | - _color = GetEnabled() ? nux::color::White : nux::color::White * 0.35; |
1701 | - |
1702 | - gfxContext.QRP_1Tex(base.x, |
1703 | - base.y, |
1704 | - base.width, |
1705 | - base.height, |
1706 | - texture, |
1707 | - texxform, |
1708 | - _color); |
1709 | - |
1710 | - gfxContext.GetRenderStates().SetBlend(false); |
1711 | - |
1712 | - gfxContext.PopClippingRectangle(); |
1713 | -} |
1714 | - |
1715 | -void |
1716 | -QuicklistMenuItemRadio::DrawContent(nux::GraphicsEngine& gfxContext, |
1717 | - bool forceDraw) |
1718 | -{ |
1719 | -} |
1720 | - |
1721 | -void |
1722 | -QuicklistMenuItemRadio::PostDraw(nux::GraphicsEngine& gfxContext, |
1723 | - bool forceDraw) |
1724 | -{ |
1725 | -} |
1726 | - |
1727 | -void |
1728 | -QuicklistMenuItemRadio::UpdateTexture() |
1729 | -{ |
1730 | - int width = GetBaseWidth(); |
1731 | - int height = GetBaseHeight(); |
1732 | - |
1733 | - _cairoGraphics = new nux::CairoGraphics(CAIRO_FORMAT_ARGB32, width, height); |
1734 | - cairo_t* cr = _cairoGraphics->GetContext(); |
1735 | +std::string QuicklistMenuItemRadio::GetName() const |
1736 | +{ |
1737 | + return "QuicklistMenuItemRadio"; |
1738 | +} |
1739 | + |
1740 | +void QuicklistMenuItemRadio::UpdateTexture() |
1741 | +{ |
1742 | + int width = GetBaseWidth(); |
1743 | + int height = GetBaseHeight(); |
1744 | + |
1745 | + nux::CairoGraphics cairoGraphics(CAIRO_FORMAT_ARGB32, width, height); |
1746 | + std::shared_ptr<cairo_t> cairo_context(cairoGraphics.GetContext(), cairo_destroy); |
1747 | + cairo_t* cr = cairo_context.get(); |
1748 | |
1749 | // draw normal, disabled version |
1750 | cairo_set_operator(cr, CAIRO_OPERATOR_CLEAR); |
1751 | cairo_paint(cr); |
1752 | |
1753 | - DrawText(_cairoGraphics, width, height, nux::color::White); |
1754 | - |
1755 | - if (_normalTexture[0]) |
1756 | - _normalTexture[0]->UnReference(); |
1757 | - |
1758 | - _normalTexture[0] = texture_from_cairo_graphics(*_cairoGraphics); |
1759 | + DrawText(cairoGraphics, width, height, nux::color::White); |
1760 | + |
1761 | + _normalTexture[0].Adopt(texture_from_cairo_graphics(cairoGraphics)); |
1762 | |
1763 | // draw normal, enabled version |
1764 | cairo_set_operator(cr, CAIRO_OPERATOR_CLEAR); |
1765 | @@ -196,62 +66,41 @@ |
1766 | cairo_set_source_rgba(cr, 1.0f, 1.0f, 1.0f, 1.0f); |
1767 | cairo_set_line_width(cr, 1.0f); |
1768 | |
1769 | - double x = _align((ITEM_INDENT_ABS + ITEM_MARGIN) / 2.0f); |
1770 | - double y = _align((double) height / 2.0f); |
1771 | + double x = Align((ITEM_INDENT_ABS + ITEM_MARGIN) / 2.0f); |
1772 | + double y = Align(static_cast<double>(height) / 2.0f); |
1773 | double radius = 3.5f; |
1774 | |
1775 | cairo_set_source_rgba(cr, 1.0f, 1.0f, 1.0f, 1.0f); |
1776 | cairo_arc(cr, x, y, radius, 0.0f * (G_PI / 180.0f), 360.0f * (G_PI / 180.0f)); |
1777 | cairo_fill(cr); |
1778 | |
1779 | - DrawText(_cairoGraphics, width, height, nux::color::White); |
1780 | - |
1781 | - if (_normalTexture[1]) |
1782 | - _normalTexture[1]->UnReference(); |
1783 | - |
1784 | - _normalTexture[1] = texture_from_cairo_graphics(*_cairoGraphics); |
1785 | - |
1786 | - // draw active/prelight, unchecked version |
1787 | - cairo_set_operator(cr, CAIRO_OPERATOR_CLEAR); |
1788 | - cairo_paint(cr); |
1789 | - |
1790 | - DrawPrelight(_cairoGraphics, width, height, nux::color::White); |
1791 | - DrawText(_cairoGraphics, width, height, nux::color::White * 0.0f); |
1792 | - |
1793 | - if (_prelightTexture[0]) |
1794 | - _prelightTexture[0]->UnReference(); |
1795 | - |
1796 | - _prelightTexture[0] = texture_from_cairo_graphics(*_cairoGraphics); |
1797 | - |
1798 | - // draw active/prelight, unchecked version |
1799 | - cairo_set_operator(cr, CAIRO_OPERATOR_CLEAR); |
1800 | - cairo_paint(cr); |
1801 | - |
1802 | - DrawPrelight(_cairoGraphics, width, height, nux::color::White); |
1803 | + DrawText(cairoGraphics, width, height, nux::color::White); |
1804 | + |
1805 | + _normalTexture[1].Adopt(texture_from_cairo_graphics(cairoGraphics)); |
1806 | + |
1807 | + // draw active/prelight, unchecked version |
1808 | + cairo_set_operator(cr, CAIRO_OPERATOR_CLEAR); |
1809 | + cairo_paint(cr); |
1810 | + |
1811 | + DrawPrelight(cairoGraphics, width, height, nux::color::White); |
1812 | + DrawText(cairoGraphics, width, height, nux::color::White * 0.0f); |
1813 | + |
1814 | + _prelightTexture[0].Adopt(texture_from_cairo_graphics(cairoGraphics)); |
1815 | + |
1816 | + // draw active/prelight, unchecked version |
1817 | + cairo_set_operator(cr, CAIRO_OPERATOR_CLEAR); |
1818 | + cairo_paint(cr); |
1819 | + |
1820 | + DrawPrelight(cairoGraphics, width, height, nux::color::White); |
1821 | |
1822 | cairo_set_source_rgba(cr, 0.0f, 0.0f, 0.0f, 0.0f); |
1823 | |
1824 | cairo_arc(cr, x, y, radius, 0.0f * (G_PI / 180.0f), 360.0f * (G_PI / 180.0f)); |
1825 | cairo_fill(cr); |
1826 | |
1827 | - DrawText(_cairoGraphics, width, height, nux::color::White * 0.0f); |
1828 | - |
1829 | - if (_prelightTexture[1]) |
1830 | - _prelightTexture[1]->UnReference(); |
1831 | - |
1832 | - _prelightTexture[1] = texture_from_cairo_graphics(*_cairoGraphics); |
1833 | - |
1834 | - // finally clean up |
1835 | - cairo_destroy(cr); |
1836 | - delete _cairoGraphics; |
1837 | -} |
1838 | - |
1839 | -int QuicklistMenuItemRadio::CairoSurfaceWidth() |
1840 | -{ |
1841 | - if (_normalTexture[0]) |
1842 | - return _normalTexture[0]->GetWidth(); |
1843 | - |
1844 | - return 0; |
1845 | + DrawText(cairoGraphics, width, height, nux::color::White * 0.0f); |
1846 | + |
1847 | + _prelightTexture[1].Adopt(texture_from_cairo_graphics(cairoGraphics)); |
1848 | } |
1849 | |
1850 | } // NAMESPACE |
1851 | |
1852 | === modified file 'launcher/QuicklistMenuItemRadio.h' |
1853 | --- launcher/QuicklistMenuItemRadio.h 2012-05-25 20:49:27 +0000 |
1854 | +++ launcher/QuicklistMenuItemRadio.h 2012-08-13 14:28:23 +0000 |
1855 | @@ -15,52 +15,27 @@ |
1856 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
1857 | * |
1858 | * Authored by: Mirco Müller <mirco.mueller@canonical.com> |
1859 | + * Marco Trevisan <marco.trevisan@canonical.com> |
1860 | */ |
1861 | |
1862 | #ifndef QUICKLISTMENUITEMRADIO_H |
1863 | #define QUICKLISTMENUITEMRADIO_H |
1864 | |
1865 | -#include <Nux/Nux.h> |
1866 | -#include <Nux/View.h> |
1867 | -#include <NuxGraphics/CairoGraphics.h> |
1868 | - |
1869 | #include "QuicklistMenuItem.h" |
1870 | |
1871 | -#include <X11/Xlib.h> |
1872 | - |
1873 | namespace unity |
1874 | { |
1875 | |
1876 | class QuicklistMenuItemRadio : public QuicklistMenuItem |
1877 | { |
1878 | public: |
1879 | - QuicklistMenuItemRadio(DbusmenuMenuitem* item, |
1880 | - NUX_FILE_LINE_PROTO); |
1881 | - |
1882 | - QuicklistMenuItemRadio(DbusmenuMenuitem* item, |
1883 | - bool debug, |
1884 | - NUX_FILE_LINE_PROTO); |
1885 | - |
1886 | - ~QuicklistMenuItemRadio(); |
1887 | + QuicklistMenuItemRadio(DbusmenuMenuitem* item, NUX_FILE_LINE_PROTO); |
1888 | |
1889 | protected: |
1890 | - void PreLayoutManagement(); |
1891 | - |
1892 | - long PostLayoutManagement(long layoutResult); |
1893 | - |
1894 | - void Draw(nux::GraphicsEngine& gfxContext, |
1895 | - bool forceDraw); |
1896 | - |
1897 | - void DrawContent(nux::GraphicsEngine& gfxContext, |
1898 | - bool forceDraw); |
1899 | - |
1900 | - void PostDraw(nux::GraphicsEngine& gfxContext, |
1901 | - bool forceDraw); |
1902 | - |
1903 | - virtual const gchar* GetDefaultText(); |
1904 | - |
1905 | + std::string GetName() const; |
1906 | + |
1907 | + virtual std::string GetDefaultText() const; |
1908 | virtual void UpdateTexture(); |
1909 | - virtual int CairoSurfaceWidth(); |
1910 | }; |
1911 | |
1912 | } //NAMESPACE |
1913 | |
1914 | === modified file 'launcher/QuicklistMenuItemSeparator.cpp' |
1915 | --- launcher/QuicklistMenuItemSeparator.cpp 2012-05-07 22:28:17 +0000 |
1916 | +++ launcher/QuicklistMenuItemSeparator.cpp 2012-08-13 14:28:23 +0000 |
1917 | @@ -1,6 +1,6 @@ |
1918 | // -*- Mode: C++; indent-tabs-mode: nil; tab-width: 2 -*- |
1919 | /* |
1920 | - * Copyright (C) 2010 Canonical Ltd |
1921 | + * Copyright (C) 2010-2012 Canonical Ltd |
1922 | * |
1923 | * This program is free software: you can redistribute it and/or modify |
1924 | * it under the terms of the GNU General Public License version 3 as |
1925 | @@ -15,104 +15,41 @@ |
1926 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
1927 | * |
1928 | * Authored by: Mirco Müller <mirco.mueller@canonical.com> |
1929 | + * Marco Trevisan <marco.trevisan@canonical.com> |
1930 | */ |
1931 | |
1932 | -#include <Nux/Nux.h> |
1933 | - |
1934 | #include "unity-shared/CairoTexture.h" |
1935 | #include "QuicklistMenuItemSeparator.h" |
1936 | |
1937 | namespace unity |
1938 | { |
1939 | |
1940 | -QuicklistMenuItemSeparator::QuicklistMenuItemSeparator(DbusmenuMenuitem* item, |
1941 | - NUX_FILE_LINE_DECL) : |
1942 | - QuicklistMenuItem(item, |
1943 | - NUX_FILE_LINE_PARAM) |
1944 | -{ |
1945 | - _name = "QuicklistMenuItemSeparator"; |
1946 | - SetMinimumHeight(7); |
1947 | - SetBaseSize(64, 7); |
1948 | - |
1949 | - _color = nux::Color(1.0f, 1.0f, 1.0f, 0.5f); |
1950 | - _premultiplied_color = nux::Color(0.5f, 0.5f, 0.5f, 0.5f); |
1951 | - _item_type = MENUITEM_TYPE_SEPARATOR; |
1952 | -} |
1953 | - |
1954 | -QuicklistMenuItemSeparator::QuicklistMenuItemSeparator(DbusmenuMenuitem* item, |
1955 | - bool debug, |
1956 | - NUX_FILE_LINE_DECL) : |
1957 | - QuicklistMenuItem(item, |
1958 | - debug, |
1959 | - NUX_FILE_LINE_PARAM) |
1960 | -{ |
1961 | - _name = "QuicklistMenuItemSeparator"; |
1962 | - SetMinimumHeight(7); |
1963 | - SetBaseSize(64, 7); |
1964 | - //_normalTexture = NULL; |
1965 | - _color = nux::Color(1.0f, 1.0f, 1.0f, 0.5f); |
1966 | - _premultiplied_color = nux::Color(0.5f, 0.5f, 0.5f, 0.5f); |
1967 | - _item_type = MENUITEM_TYPE_SEPARATOR; |
1968 | -} |
1969 | - |
1970 | -QuicklistMenuItemSeparator::~QuicklistMenuItemSeparator() |
1971 | -{ |
1972 | -} |
1973 | - |
1974 | -bool |
1975 | -QuicklistMenuItemSeparator::GetSelectable() |
1976 | +QuicklistMenuItemSeparator::QuicklistMenuItemSeparator(DbusmenuMenuitem* item, NUX_FILE_LINE_DECL) |
1977 | + : QuicklistMenuItem(QuicklistMenuItemType::SEPARATOR, item, NUX_FILE_LINE_PARAM) |
1978 | + , _color(1.0f, 1.0f, 1.0f, 0.5f) |
1979 | + , _premultiplied_color(0.5f, 0.5f, 0.5f, 0.5f) |
1980 | +{ |
1981 | + SetMinimumHeight(7); |
1982 | + SetBaseSize(64, 7); |
1983 | +} |
1984 | + |
1985 | +std::string QuicklistMenuItemSeparator::GetName() const |
1986 | +{ |
1987 | + return "QuicklistMenuItemSeparator"; |
1988 | +} |
1989 | + |
1990 | +bool QuicklistMenuItemSeparator::GetSelectable() |
1991 | { |
1992 | return false; |
1993 | } |
1994 | |
1995 | -void |
1996 | -QuicklistMenuItemSeparator::PreLayoutManagement() |
1997 | -{ |
1998 | - _pre_layout_width = GetBaseWidth(); |
1999 | - _pre_layout_height = GetBaseHeight(); |
2000 | - |
2001 | - if ((_normalTexture[0] == 0)) |
2002 | - { |
2003 | - UpdateTexture(); |
2004 | - } |
2005 | - |
2006 | - QuicklistMenuItem::PreLayoutManagement(); |
2007 | -} |
2008 | - |
2009 | -long |
2010 | -QuicklistMenuItemSeparator::PostLayoutManagement(long layoutResult) |
2011 | -{ |
2012 | - int w = GetBaseWidth(); |
2013 | - int h = GetBaseHeight(); |
2014 | - |
2015 | - long result = 0; |
2016 | - |
2017 | - if (_pre_layout_width < w) |
2018 | - result |= nux::eLargerWidth; |
2019 | - else if (_pre_layout_width > w) |
2020 | - result |= nux::eSmallerWidth; |
2021 | - else |
2022 | - result |= nux::eCompliantWidth; |
2023 | - |
2024 | - if (_pre_layout_height < h) |
2025 | - result |= nux::eLargerHeight; |
2026 | - else if (_pre_layout_height > h) |
2027 | - result |= nux::eSmallerHeight; |
2028 | - else |
2029 | - result |= nux::eCompliantHeight; |
2030 | - |
2031 | - return result; |
2032 | -} |
2033 | - |
2034 | -void |
2035 | -QuicklistMenuItemSeparator::Draw(nux::GraphicsEngine& gfxContext, |
2036 | - bool forceDraw) |
2037 | +void QuicklistMenuItemSeparator::Draw(nux::GraphicsEngine& gfxContext, bool forceDraw) |
2038 | { |
2039 | // Check if the texture have been computed. If they haven't, exit the function. |
2040 | - if (_normalTexture[0] == 0) |
2041 | + if (!_normalTexture[0]) |
2042 | return; |
2043 | |
2044 | - nux::Geometry base = GetGeometry(); |
2045 | + nux::Geometry const& base = GetGeometry(); |
2046 | |
2047 | gfxContext.PushClippingRectangle(base); |
2048 | |
2049 | @@ -123,39 +60,21 @@ |
2050 | gfxContext.GetRenderStates().SetBlend(true); |
2051 | gfxContext.GetRenderStates().SetPremultipliedBlend(nux::SRC_OVER); |
2052 | |
2053 | - gfxContext.QRP_1Tex(base.x, |
2054 | - base.y, |
2055 | - base.width, |
2056 | - base.height, |
2057 | - _normalTexture[0]->GetDeviceTexture(), |
2058 | - texxform, |
2059 | - _premultiplied_color); |
2060 | + auto const& texture = _normalTexture[0]->GetDeviceTexture(); |
2061 | + gfxContext.QRP_1Tex(base.x, base.y, base.width, base.height, texture, texxform, _premultiplied_color); |
2062 | |
2063 | gfxContext.GetRenderStates().SetBlend(false); |
2064 | - |
2065 | gfxContext.PopClippingRectangle(); |
2066 | } |
2067 | |
2068 | -void |
2069 | -QuicklistMenuItemSeparator::DrawContent(nux::GraphicsEngine& gfxContext, |
2070 | - bool forceDraw) |
2071 | -{ |
2072 | -} |
2073 | - |
2074 | -void |
2075 | -QuicklistMenuItemSeparator::PostDraw(nux::GraphicsEngine& gfxContext, |
2076 | - bool forceDraw) |
2077 | -{ |
2078 | -} |
2079 | - |
2080 | -void |
2081 | -QuicklistMenuItemSeparator::UpdateTexture() |
2082 | -{ |
2083 | - int width = GetBaseWidth(); |
2084 | - int height = GetBaseHeight(); |
2085 | - |
2086 | - _cairoGraphics = new nux::CairoGraphics(CAIRO_FORMAT_ARGB32, width, height); |
2087 | - cairo_t* cr = _cairoGraphics->GetContext(); |
2088 | +void QuicklistMenuItemSeparator::UpdateTexture() |
2089 | +{ |
2090 | + int width = GetBaseWidth(); |
2091 | + int height = GetBaseHeight(); |
2092 | + |
2093 | + nux::CairoGraphics cairoGraphics(CAIRO_FORMAT_ARGB32, width, height); |
2094 | + std::shared_ptr<cairo_t> cairo_context(cairoGraphics.GetContext(), cairo_destroy); |
2095 | + cairo_t* cr = cairo_context.get(); |
2096 | |
2097 | cairo_set_operator(cr, CAIRO_OPERATOR_SOURCE); |
2098 | cairo_set_source_rgba(cr, 0.0f, 0.0f, 0.0f, 0.0f); |
2099 | @@ -166,21 +85,7 @@ |
2100 | cairo_line_to(cr, width, 3.5f); |
2101 | cairo_stroke(cr); |
2102 | |
2103 | - if (_normalTexture[0]) |
2104 | - _normalTexture[0]->UnReference(); |
2105 | - |
2106 | - _normalTexture[0] = texture_from_cairo_graphics(*_cairoGraphics); |
2107 | - |
2108 | - cairo_destroy(cr); |
2109 | - delete _cairoGraphics; |
2110 | -} |
2111 | - |
2112 | -int QuicklistMenuItemSeparator::CairoSurfaceWidth() |
2113 | -{ |
2114 | - if (_normalTexture[0]) |
2115 | - return _normalTexture[0]->GetWidth(); |
2116 | - |
2117 | - return 0; |
2118 | + _normalTexture[0].Adopt(texture_from_cairo_graphics(cairoGraphics)); |
2119 | } |
2120 | |
2121 | } |
2122 | |
2123 | === modified file 'launcher/QuicklistMenuItemSeparator.h' |
2124 | --- launcher/QuicklistMenuItemSeparator.h 2012-05-25 20:49:27 +0000 |
2125 | +++ launcher/QuicklistMenuItemSeparator.h 2012-08-13 14:28:23 +0000 |
2126 | @@ -15,57 +15,32 @@ |
2127 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
2128 | * |
2129 | * Authored by: Mirco Müller <mirco.mueller@canonical.com> |
2130 | + * Marco Trevisan <marco.trevisan@canonical.com> |
2131 | */ |
2132 | |
2133 | #ifndef QUICKLISTMENUITEMSEPARATOR_H |
2134 | #define QUICKLISTMENUITEMSEPARATOR_H |
2135 | |
2136 | -#include <Nux/Nux.h> |
2137 | -#include <Nux/View.h> |
2138 | -#include <NuxGraphics/CairoGraphics.h> |
2139 | - |
2140 | #include "QuicklistMenuItem.h" |
2141 | |
2142 | -#include <X11/Xlib.h> |
2143 | - |
2144 | namespace unity |
2145 | { |
2146 | |
2147 | class QuicklistMenuItemSeparator : public QuicklistMenuItem |
2148 | { |
2149 | public: |
2150 | - QuicklistMenuItemSeparator(DbusmenuMenuitem* item, |
2151 | - NUX_FILE_LINE_PROTO); |
2152 | - |
2153 | - QuicklistMenuItemSeparator(DbusmenuMenuitem* item, |
2154 | - bool debug, |
2155 | - NUX_FILE_LINE_PROTO); |
2156 | - |
2157 | - ~QuicklistMenuItemSeparator(); |
2158 | + QuicklistMenuItemSeparator(DbusmenuMenuitem* item, NUX_FILE_LINE_PROTO); |
2159 | |
2160 | virtual bool GetSelectable(); |
2161 | |
2162 | protected: |
2163 | - |
2164 | - void PreLayoutManagement(); |
2165 | - |
2166 | - long PostLayoutManagement(long layoutResult); |
2167 | - |
2168 | void Draw(nux::GraphicsEngine& gfxContext, bool forceDraw); |
2169 | - |
2170 | - void DrawContent(nux::GraphicsEngine& gfxContext, bool forceDraw); |
2171 | - |
2172 | - void PostDraw(nux::GraphicsEngine& gfxContext, bool forceDraw); |
2173 | + std::string GetName() const; |
2174 | |
2175 | virtual void UpdateTexture(); |
2176 | |
2177 | - //! Returns the width of the separator line as defined by the size of the _normalTexture. |
2178 | - virtual int CairoSurfaceWidth(); |
2179 | - |
2180 | - friend class QuicklistView; |
2181 | - |
2182 | private: |
2183 | - |
2184 | + nux::Color _color; |
2185 | nux::Color _premultiplied_color; |
2186 | }; |
2187 | |
2188 | |
2189 | === modified file 'launcher/QuicklistView.cpp' |
2190 | --- launcher/QuicklistView.cpp 2012-07-25 16:00:26 +0000 |
2191 | +++ launcher/QuicklistView.cpp 2012-08-13 14:28:23 +0000 |
2192 | @@ -147,7 +147,7 @@ |
2193 | if (menu_item) |
2194 | { |
2195 | target_item = index; |
2196 | - menu_item->_prelight = true; |
2197 | + menu_item->Select(); |
2198 | } |
2199 | } |
2200 | |
2201 | @@ -448,13 +448,9 @@ |
2202 | _item_layout->AddView(item, 1, nux::eCenter, nux::eFull); |
2203 | } |
2204 | |
2205 | - int textWidth = 0; |
2206 | - int textHeight = 0; |
2207 | - item->GetTextExtents(textWidth, textHeight); |
2208 | - textHeight += QuicklistMenuItem::ITEM_MARGIN * 2; |
2209 | - |
2210 | - MaxItemWidth = std::max(MaxItemWidth, textWidth); |
2211 | - TotalItemHeight += textHeight; |
2212 | + nux::Size const& text_extents = item->GetTextExtents(); |
2213 | + MaxItemWidth = std::max(MaxItemWidth, text_extents.width); |
2214 | + TotalItemHeight += text_extents.height; |
2215 | } |
2216 | |
2217 | if (TotalItemHeight < _anchor_height) |
2218 | @@ -510,11 +506,11 @@ |
2219 | // only after MaxItemWidth is computed in QuicklistView::PreLayoutManagement. |
2220 | // The setting of the separator width is done here after the Layout cycle for this widget is over. The width of the separator |
2221 | // has bee set correctly during the layout cycle, but the cairo rendering still need to be adjusted. |
2222 | - int separator_width = _item_layout->GetBaseWidth(); |
2223 | + unsigned separator_width = _item_layout->GetBaseWidth(); |
2224 | |
2225 | for (auto item : _item_list) |
2226 | { |
2227 | - if (item->GetVisible() && item->CairoSurfaceWidth() != separator_width) |
2228 | + if (item->GetVisible() && item->GetCairoSurfaceWidth() != separator_width) |
2229 | { |
2230 | // Compute textures of the item. |
2231 | item->UpdateTexture(); |
2232 | @@ -567,14 +563,10 @@ |
2233 | |
2234 | void QuicklistView::ActivateItem(QuicklistMenuItem* item) |
2235 | { |
2236 | - if (item && item->_menuItem) |
2237 | - { |
2238 | - ubus_server_send_message(ubus_server_get_default(), |
2239 | - UBUS_PLACE_VIEW_CLOSE_REQUEST, |
2240 | - NULL); |
2241 | + if (!item) |
2242 | + return; |
2243 | |
2244 | - dbusmenu_menuitem_handle_event(item->_menuItem, "clicked", NULL, 0); |
2245 | - } |
2246 | + item->Activate(); |
2247 | } |
2248 | |
2249 | void QuicklistView::RecvItemMouseRelease(QuicklistMenuItem* item, int x, int y) |
2250 | @@ -595,7 +587,7 @@ |
2251 | { |
2252 | for (auto item : _item_list) |
2253 | { |
2254 | - item->_prelight = false; |
2255 | + item->Select(false); |
2256 | } |
2257 | } |
2258 | |
2259 | @@ -760,7 +752,7 @@ |
2260 | if (item) |
2261 | return item->GetItemType(); |
2262 | |
2263 | - return MENUITEM_TYPE_UNKNOWN; |
2264 | + return QuicklistMenuItemType::UNKNOWN; |
2265 | } |
2266 | |
2267 | std::list<QuicklistMenuItem*> QuicklistView::GetChildren() |
2268 | @@ -1310,42 +1302,6 @@ |
2269 | UpdateTexture(); |
2270 | } |
2271 | |
2272 | -void QuicklistView::TestMenuItems(DbusmenuMenuitem* root) |
2273 | -{ |
2274 | - RemoveAllMenuItem(); |
2275 | - |
2276 | - if (root == 0) |
2277 | - return; |
2278 | - |
2279 | - GList* child = NULL; |
2280 | - for (child = dbusmenu_menuitem_get_children(root); child != NULL; child = g_list_next(child)) |
2281 | - { |
2282 | - const gchar* type = dbusmenu_menuitem_property_get((DbusmenuMenuitem*)child->data, DBUSMENU_MENUITEM_PROP_TYPE); |
2283 | - const gchar* toggle_type = dbusmenu_menuitem_property_get((DbusmenuMenuitem*)child->data, DBUSMENU_MENUITEM_PROP_TOGGLE_TYPE); |
2284 | - |
2285 | - if (g_strcmp0(type, DBUSMENU_CLIENT_TYPES_SEPARATOR) == 0) |
2286 | - { |
2287 | - QuicklistMenuItemSeparator* item = new QuicklistMenuItemSeparator((DbusmenuMenuitem*)child->data, NUX_TRACKER_LOCATION); |
2288 | - AddMenuItem(item); |
2289 | - } |
2290 | - else if (g_strcmp0(toggle_type, DBUSMENU_MENUITEM_TOGGLE_CHECK) == 0) |
2291 | - { |
2292 | - QuicklistMenuItemCheckmark* item = new QuicklistMenuItemCheckmark((DbusmenuMenuitem*)child->data, NUX_TRACKER_LOCATION); |
2293 | - AddMenuItem(item); |
2294 | - } |
2295 | - else if (g_strcmp0(toggle_type, DBUSMENU_MENUITEM_TOGGLE_RADIO) == 0) |
2296 | - { |
2297 | - QuicklistMenuItemRadio* item = new QuicklistMenuItemRadio((DbusmenuMenuitem*)child->data, NUX_TRACKER_LOCATION); |
2298 | - AddMenuItem(item); |
2299 | - } |
2300 | - else //if (g_strcmp0 (type, DBUSMENU_MENUITEM_PROP_LABEL) == 0) |
2301 | - { |
2302 | - QuicklistMenuItemLabel* item = new QuicklistMenuItemLabel((DbusmenuMenuitem*)child->data, NUX_TRACKER_LOCATION); |
2303 | - AddMenuItem(item); |
2304 | - } |
2305 | - } |
2306 | -} |
2307 | - |
2308 | // Introspection |
2309 | |
2310 | std::string QuicklistView::GetName() const |
2311 | |
2312 | === modified file 'launcher/QuicklistView.h' |
2313 | --- launcher/QuicklistView.h 2012-07-11 06:21:46 +0000 |
2314 | +++ launcher/QuicklistView.h 2012-08-13 14:28:23 +0000 |
2315 | @@ -22,9 +22,11 @@ |
2316 | #define QUICKLISTVIEW_H |
2317 | |
2318 | #include <Nux/Nux.h> |
2319 | +#include <Nux/VLayout.h> |
2320 | +#include <Nux/HLayout.h> |
2321 | #include <Nux/BaseWindow.h> |
2322 | +#include <Nux/TextureArea.h> |
2323 | #include <NuxGraphics/GraphicsEngine.h> |
2324 | -#include <Nux/TextureArea.h> |
2325 | #include <NuxGraphics/CairoGraphics.h> |
2326 | |
2327 | #include <pango/pango.h> |
2328 | |
2329 | === modified file 'plugins/unityshell/src/unity-quicklist-menu-item-accessible.cpp' |
2330 | --- plugins/unityshell/src/unity-quicklist-menu-item-accessible.cpp 2012-03-14 06:24:18 +0000 |
2331 | +++ plugins/unityshell/src/unity-quicklist-menu-item-accessible.cpp 2012-08-13 14:28:23 +0000 |
2332 | @@ -210,7 +210,7 @@ |
2333 | menu_item = dynamic_cast<QuicklistMenuItem*>(nux_object_accessible_get_object(NUX_OBJECT_ACCESSIBLE(obj))); |
2334 | if (menu_item != NULL) |
2335 | { |
2336 | - name = menu_item->GetLabel(); |
2337 | + name = menu_item->GetLabel().c_str(); |
2338 | } |
2339 | } |
2340 | |
2341 | |
2342 | === modified file 'tests/CMakeLists.txt' |
2343 | --- tests/CMakeLists.txt 2012-08-03 09:57:41 +0000 |
2344 | +++ tests/CMakeLists.txt 2012-08-13 14:28:23 +0000 |
2345 | @@ -62,18 +62,11 @@ |
2346 | |
2347 | add_executable (test-unit |
2348 | unit/TestMain.cpp |
2349 | - unit/TestQuicklistMenuitems.cpp |
2350 | unit/TestPanelService.cpp |
2351 | unit/TestUBus.cpp |
2352 | unit/TestStaticCairoText.cpp |
2353 | ${CMAKE_SOURCE_DIR}/launcher/CairoBaseWindow.cpp |
2354 | ${CMAKE_SOURCE_DIR}/unity-shared/Introspectable.cpp |
2355 | - ${CMAKE_SOURCE_DIR}/launcher/QuicklistMenuItem.cpp |
2356 | - ${CMAKE_SOURCE_DIR}/launcher/QuicklistMenuItemCheckmark.cpp |
2357 | - ${CMAKE_SOURCE_DIR}/launcher/QuicklistMenuItemLabel.cpp |
2358 | - ${CMAKE_SOURCE_DIR}/launcher/QuicklistMenuItemRadio.cpp |
2359 | - ${CMAKE_SOURCE_DIR}/launcher/QuicklistMenuItemSeparator.cpp |
2360 | - ${CMAKE_SOURCE_DIR}/launcher/QuicklistView.cpp |
2361 | ${CMAKE_SOURCE_DIR}/unity-shared/StaticCairoText.cpp |
2362 | ../services/panel-service.c |
2363 | ${CMAKE_CURRENT_BINARY_DIR}/panel-marshal.c |
2364 | @@ -220,6 +213,8 @@ |
2365 | test_launcher_controller.cpp |
2366 | test_keyboard_util.cpp |
2367 | test_panel_style.cpp |
2368 | + test_quicklist_menu_item.cpp |
2369 | + test_quicklist_view.cpp |
2370 | test_resultviewgrid.cpp |
2371 | test_single_monitor_launcher_icon.cpp |
2372 | test_switcher_controller.cpp |
2373 | |
2374 | === added file 'tests/test_quicklist_menu_item.cpp' |
2375 | --- tests/test_quicklist_menu_item.cpp 1970-01-01 00:00:00 +0000 |
2376 | +++ tests/test_quicklist_menu_item.cpp 2012-08-13 14:28:23 +0000 |
2377 | @@ -0,0 +1,107 @@ |
2378 | +/* |
2379 | + * Copyright 2010-2012 Canonical Ltd. |
2380 | + * |
2381 | + * This program is free software: you can redistribute it and/or modify it |
2382 | + * under the terms of the GNU General Public License version 3, as published |
2383 | + * by the Free Software Foundation. |
2384 | + * |
2385 | + * This program is distributed in the hope that it will be useful, but |
2386 | + * WITHOUT ANY WARRANTY; without even the implied warranties of |
2387 | + * MERCHANTABILITY, SATISFACTORY QUALITY or FITNESS FOR A PARTICULAR |
2388 | + * PURPOSE. See the GNU General Public License for more details. |
2389 | + * |
2390 | + * You should have received a copy of the GNU General Public License |
2391 | + * version 3 along with this program. If not, see |
2392 | + * <http://www.gnu.org/licenses/> |
2393 | + * |
2394 | + * Authored by: Marco Trevisan (Treviño) <marco.trevisan@canonical.com> |
2395 | + * Mirco Müller <mirco.mueller@canonical.com> |
2396 | + */ |
2397 | + |
2398 | +#include <gmock/gmock.h> |
2399 | +#include <libdbusmenu-glib/client.h> |
2400 | + |
2401 | +#include "QuicklistMenuItem.h" |
2402 | +#include "QuicklistMenuItemCheckmark.h" |
2403 | +#include "QuicklistMenuItemLabel.h" |
2404 | +#include "QuicklistMenuItemRadio.h" |
2405 | +#include "QuicklistMenuItemSeparator.h" |
2406 | + |
2407 | +using namespace unity; |
2408 | +using namespace testing; |
2409 | + |
2410 | +namespace |
2411 | +{ |
2412 | + |
2413 | +struct TestQuicklistMenuItem : public Test |
2414 | +{ |
2415 | + TestQuicklistMenuItem() |
2416 | + : item(dbusmenu_menuitem_new()) |
2417 | + {} |
2418 | + |
2419 | + glib::Object<DbusmenuMenuitem> item; |
2420 | +}; |
2421 | + |
2422 | +TEST_F(TestQuicklistMenuItem, QuicklistMenuItemCheckmark) |
2423 | +{ |
2424 | + dbusmenu_menuitem_property_set(item, DBUSMENU_MENUITEM_PROP_LABEL, "Unchecked"); |
2425 | + dbusmenu_menuitem_property_set(item, DBUSMENU_MENUITEM_PROP_TOGGLE_TYPE, |
2426 | + DBUSMENU_MENUITEM_TOGGLE_CHECK); |
2427 | + dbusmenu_menuitem_property_set_bool(item, DBUSMENU_MENUITEM_PROP_ENABLED, false); |
2428 | + dbusmenu_menuitem_property_set_int(item, DBUSMENU_MENUITEM_PROP_TOGGLE_STATE, |
2429 | + DBUSMENU_MENUITEM_TOGGLE_STATE_UNCHECKED); |
2430 | + |
2431 | + nux::ObjectPtr<QuicklistMenuItemCheckmark> qlitem(new QuicklistMenuItemCheckmark(item)); |
2432 | + |
2433 | + EXPECT_EQ(qlitem->GetLabel(), "Unchecked"); |
2434 | + EXPECT_FALSE(qlitem->GetEnabled()); |
2435 | + EXPECT_FALSE(qlitem->GetActive()); |
2436 | + EXPECT_FALSE(qlitem->GetSelectable()); |
2437 | + EXPECT_FALSE(qlitem->IsMarkupEnabled()); |
2438 | +} |
2439 | + |
2440 | +TEST_F(TestQuicklistMenuItem, QuicklistMenuItemLabel) |
2441 | +{ |
2442 | + dbusmenu_menuitem_property_set(item, DBUSMENU_MENUITEM_PROP_LABEL, "A Label"); |
2443 | + dbusmenu_menuitem_property_set_bool(item, DBUSMENU_MENUITEM_PROP_ENABLED, true); |
2444 | + dbusmenu_menuitem_property_set_bool(item, "unity-use-markup", true); |
2445 | + |
2446 | + nux::ObjectPtr<QuicklistMenuItemLabel> qlitem(new QuicklistMenuItemLabel(item)); |
2447 | + |
2448 | + EXPECT_EQ(qlitem->GetLabel(), "A Label"); |
2449 | + EXPECT_TRUE(qlitem->GetEnabled()); |
2450 | + EXPECT_TRUE(qlitem->GetSelectable()); |
2451 | + EXPECT_TRUE(qlitem->IsMarkupEnabled()); |
2452 | +} |
2453 | + |
2454 | +TEST_F(TestQuicklistMenuItem, QuicklistMenuItemRadio) |
2455 | +{ |
2456 | + dbusmenu_menuitem_property_set(item, DBUSMENU_MENUITEM_PROP_LABEL, "Radio Active"); |
2457 | + dbusmenu_menuitem_property_set(item, DBUSMENU_MENUITEM_PROP_TOGGLE_TYPE, |
2458 | + DBUSMENU_MENUITEM_TOGGLE_RADIO); |
2459 | + dbusmenu_menuitem_property_set_bool(item, DBUSMENU_MENUITEM_PROP_ENABLED, true); |
2460 | + dbusmenu_menuitem_property_set_int(item, DBUSMENU_MENUITEM_PROP_TOGGLE_STATE, |
2461 | + DBUSMENU_MENUITEM_TOGGLE_STATE_CHECKED); |
2462 | + |
2463 | + nux::ObjectPtr<QuicklistMenuItemRadio> qlitem(new QuicklistMenuItemRadio(item)); |
2464 | + qlitem->EnableLabelMarkup(true); |
2465 | + |
2466 | + EXPECT_EQ(qlitem->GetLabel(), "Radio Active"); |
2467 | + EXPECT_TRUE(qlitem->GetEnabled()); |
2468 | + EXPECT_TRUE(qlitem->GetActive()); |
2469 | + EXPECT_TRUE(qlitem->GetSelectable()); |
2470 | + EXPECT_TRUE(qlitem->IsMarkupEnabled()); |
2471 | +} |
2472 | + |
2473 | +TEST_F(TestQuicklistMenuItem, QuicklistMenuItemSeparator) |
2474 | +{ |
2475 | + dbusmenu_menuitem_property_set(item, "type", DBUSMENU_CLIENT_TYPES_SEPARATOR); |
2476 | + dbusmenu_menuitem_property_set_bool(item, DBUSMENU_MENUITEM_PROP_ENABLED, true); |
2477 | + |
2478 | + nux::ObjectPtr<QuicklistMenuItemSeparator> qlitem(new QuicklistMenuItemSeparator(item)); |
2479 | + |
2480 | + EXPECT_TRUE(qlitem->GetEnabled()); |
2481 | + EXPECT_FALSE(qlitem->GetSelectable()); |
2482 | +} |
2483 | + |
2484 | +} |
2485 | |
2486 | === added file 'tests/test_quicklist_view.cpp' |
2487 | --- tests/test_quicklist_view.cpp 1970-01-01 00:00:00 +0000 |
2488 | +++ tests/test_quicklist_view.cpp 2012-08-13 14:28:23 +0000 |
2489 | @@ -0,0 +1,124 @@ |
2490 | +/* |
2491 | + * Copyright 2010-2012 Canonical Ltd. |
2492 | + * |
2493 | + * This program is free software: you can redistribute it and/or modify it |
2494 | + * under the terms of the GNU General Public License version 3, as published |
2495 | + * by the Free Software Foundation. |
2496 | + * |
2497 | + * This program is distributed in the hope that it will be useful, but |
2498 | + * WITHOUT ANY WARRANTY; without even the implied warranties of |
2499 | + * MERCHANTABILITY, SATISFACTORY QUALITY or FITNESS FOR A PARTICULAR |
2500 | + * PURPOSE. See the GNU General Public License for more details. |
2501 | + * |
2502 | + * You should have received a copy of the GNU General Public License |
2503 | + * version 3 along with this program. If not, see |
2504 | + * <http://www.gnu.org/licenses/> |
2505 | + * |
2506 | + * Authored by: Marco Trevisan (Treviño) <marco.trevisan@canonical.com> |
2507 | + * Mirco Müller <mirco.mueller@canonical.com> |
2508 | + */ |
2509 | + |
2510 | +#include <gmock/gmock.h> |
2511 | +#include <libdbusmenu-glib/client.h> |
2512 | + |
2513 | +#include "QuicklistView.h" |
2514 | +#include "QuicklistMenuItemCheckmark.h" |
2515 | +#include "QuicklistMenuItemLabel.h" |
2516 | +#include "QuicklistMenuItemRadio.h" |
2517 | +#include "QuicklistMenuItemSeparator.h" |
2518 | + |
2519 | +using namespace unity; |
2520 | +using namespace testing; |
2521 | + |
2522 | +namespace |
2523 | +{ |
2524 | + |
2525 | +struct TestQuicklistView : public Test |
2526 | +{ |
2527 | + TestQuicklistView() |
2528 | + : quicklist(new QuicklistView()) |
2529 | + {} |
2530 | + |
2531 | + void AddMenuItems(DbusmenuMenuitem* root) |
2532 | + { |
2533 | + quicklist->RemoveAllMenuItem(); |
2534 | + |
2535 | + if (!root) |
2536 | + return; |
2537 | + |
2538 | + for (GList* child = dbusmenu_menuitem_get_children(root); child; child = child->next) |
2539 | + { |
2540 | + const gchar* type = dbusmenu_menuitem_property_get((DbusmenuMenuitem*)child->data, DBUSMENU_MENUITEM_PROP_TYPE); |
2541 | + const gchar* toggle_type = dbusmenu_menuitem_property_get((DbusmenuMenuitem*)child->data, DBUSMENU_MENUITEM_PROP_TOGGLE_TYPE); |
2542 | + |
2543 | + if (g_strcmp0(type, DBUSMENU_CLIENT_TYPES_SEPARATOR) == 0) |
2544 | + { |
2545 | + QuicklistMenuItemSeparator* item = new QuicklistMenuItemSeparator((DbusmenuMenuitem*)child->data, NUX_TRACKER_LOCATION); |
2546 | + quicklist->AddMenuItem(item); |
2547 | + } |
2548 | + else if (g_strcmp0(toggle_type, DBUSMENU_MENUITEM_TOGGLE_CHECK) == 0) |
2549 | + { |
2550 | + QuicklistMenuItemCheckmark* item = new QuicklistMenuItemCheckmark((DbusmenuMenuitem*)child->data, NUX_TRACKER_LOCATION); |
2551 | + quicklist->AddMenuItem(item); |
2552 | + } |
2553 | + else if (g_strcmp0(toggle_type, DBUSMENU_MENUITEM_TOGGLE_RADIO) == 0) |
2554 | + { |
2555 | + QuicklistMenuItemRadio* item = new QuicklistMenuItemRadio((DbusmenuMenuitem*)child->data, NUX_TRACKER_LOCATION); |
2556 | + quicklist->AddMenuItem(item); |
2557 | + } |
2558 | + else //if (g_strcmp0 (type, DBUSMENU_MENUITEM_PROP_LABEL) == 0) |
2559 | + { |
2560 | + QuicklistMenuItemLabel* item = new QuicklistMenuItemLabel((DbusmenuMenuitem*)child->data, NUX_TRACKER_LOCATION); |
2561 | + quicklist->AddMenuItem(item); |
2562 | + } |
2563 | + } |
2564 | + } |
2565 | + |
2566 | + nux::ObjectPtr<QuicklistView> quicklist; |
2567 | +}; |
2568 | + |
2569 | +TEST_F(TestQuicklistView, AddItems) |
2570 | +{ |
2571 | + glib::Object<DbusmenuMenuitem> root(dbusmenu_menuitem_new()); |
2572 | + |
2573 | + dbusmenu_menuitem_set_root(root, true); |
2574 | + |
2575 | + DbusmenuMenuitem* child = dbusmenu_menuitem_new(); |
2576 | + dbusmenu_menuitem_property_set(child, DBUSMENU_MENUITEM_PROP_TYPE, DBUSMENU_MENUITEM_PROP_LABEL); |
2577 | + dbusmenu_menuitem_property_set(child, DBUSMENU_MENUITEM_PROP_LABEL, "label 0"); |
2578 | + dbusmenu_menuitem_property_set_bool(child, DBUSMENU_MENUITEM_PROP_ENABLED, true); |
2579 | + dbusmenu_menuitem_child_append(root, child); |
2580 | + |
2581 | + child = dbusmenu_menuitem_new(); |
2582 | + dbusmenu_menuitem_property_set(child, DBUSMENU_MENUITEM_PROP_TYPE, DBUSMENU_CLIENT_TYPES_SEPARATOR); |
2583 | + dbusmenu_menuitem_property_set_bool(child, DBUSMENU_MENUITEM_PROP_ENABLED, true); |
2584 | + dbusmenu_menuitem_child_append(root, child); |
2585 | + |
2586 | + child = dbusmenu_menuitem_new(); |
2587 | + dbusmenu_menuitem_property_set(child, DBUSMENU_MENUITEM_PROP_TYPE, DBUSMENU_MENUITEM_PROP_LABEL); |
2588 | + dbusmenu_menuitem_property_set(child, DBUSMENU_MENUITEM_PROP_LABEL, "label 1"); |
2589 | + dbusmenu_menuitem_property_set_bool(child, DBUSMENU_MENUITEM_PROP_ENABLED, true); |
2590 | + dbusmenu_menuitem_child_append(root, child); |
2591 | + |
2592 | + child = dbusmenu_menuitem_new(); |
2593 | + dbusmenu_menuitem_property_set(child, DBUSMENU_MENUITEM_PROP_TOGGLE_TYPE, DBUSMENU_MENUITEM_TOGGLE_CHECK); |
2594 | + dbusmenu_menuitem_property_set(child, DBUSMENU_MENUITEM_PROP_LABEL, "check mark 0"); |
2595 | + dbusmenu_menuitem_property_set_bool(child, DBUSMENU_MENUITEM_PROP_ENABLED, true); |
2596 | + dbusmenu_menuitem_property_set_int(child, DBUSMENU_MENUITEM_PROP_TOGGLE_STATE, DBUSMENU_MENUITEM_TOGGLE_STATE_UNCHECKED); |
2597 | + dbusmenu_menuitem_child_append(root, child); |
2598 | + |
2599 | + AddMenuItems(root); |
2600 | + |
2601 | + ASSERT_EQ(quicklist->GetChildren().size(), 4); |
2602 | + ASSERT_EQ(quicklist->GetNumItems(), 4); |
2603 | + EXPECT_EQ(quicklist->GetNthType(0), unity::QuicklistMenuItemType::LABEL); |
2604 | + EXPECT_EQ(quicklist->GetNthType(1), unity::QuicklistMenuItemType::SEPARATOR); |
2605 | + EXPECT_EQ(quicklist->GetNthType(2), unity::QuicklistMenuItemType::LABEL); |
2606 | + EXPECT_EQ(quicklist->GetNthType(3), unity::QuicklistMenuItemType::CHECK); |
2607 | + |
2608 | + EXPECT_EQ(quicklist->GetNthItems(0)->GetLabel(), "label 0"); |
2609 | + EXPECT_EQ(quicklist->GetNthItems(2)->GetLabel(), "label 1"); |
2610 | + EXPECT_EQ(quicklist->GetNthItems(3)->GetLabel(), "check mark 0"); |
2611 | +} |
2612 | + |
2613 | +} |
2614 | |
2615 | === modified file 'tests/unit/TestMain.cpp' |
2616 | --- tests/unit/TestMain.cpp 2012-01-25 15:59:13 +0000 |
2617 | +++ tests/unit/TestMain.cpp 2012-08-13 14:28:23 +0000 |
2618 | @@ -27,7 +27,6 @@ |
2619 | |
2620 | void TestPanelServiceCreateSuite(); |
2621 | void TestUBusCreateSuite(); |
2622 | -void TestQuicklistMenuitemsCreateSuite(); |
2623 | void TestStaticCairoTextCreateSuite(); |
2624 | |
2625 | nux::WindowThread* |
2626 | @@ -71,7 +70,6 @@ |
2627 | |
2628 | //Keep alphabetical please |
2629 | TestPanelServiceCreateSuite(); |
2630 | - TestQuicklistMenuitemsCreateSuite(); |
2631 | TestStaticCairoTextCreateSuite(); |
2632 | TestUBusCreateSuite(); |
2633 | |
2634 | |
2635 | === removed file 'tests/unit/TestQuicklistMenuitems.cpp' |
2636 | --- tests/unit/TestQuicklistMenuitems.cpp 2012-04-13 16:02:59 +0000 |
2637 | +++ tests/unit/TestQuicklistMenuitems.cpp 1970-01-01 00:00:00 +0000 |
2638 | @@ -1,258 +0,0 @@ |
2639 | -/* |
2640 | - * Copyright 2010 Canonical Ltd. |
2641 | - * |
2642 | - * This program is free software: you can redistribute it and/or modify it |
2643 | - * under the terms of the GNU General Public License version 3, as published |
2644 | - * by the Free Software Foundation. |
2645 | - * |
2646 | - * This program is distributed in the hope that it will be useful, but |
2647 | - * WITHOUT ANY WARRANTY; without even the implied warranties of |
2648 | - * MERCHANTABILITY, SATISFACTORY QUALITY or FITNESS FOR A PARTICULAR |
2649 | - * PURPOSE. See the GNU General Public License for more details. |
2650 | - * |
2651 | - * You should have received a copy of the GNU General Public License |
2652 | - * version 3 along with this program. If not, see |
2653 | - * <http://www.gnu.org/licenses/> |
2654 | - * |
2655 | - * Authored by: Mirco Müller <mirco.mueller@canonical.com> |
2656 | - * |
2657 | - */ |
2658 | - |
2659 | -#include "config.h" |
2660 | - |
2661 | -#include "QuicklistMenuItem.h" |
2662 | -#include "QuicklistMenuItemCheckmark.h" |
2663 | -#include "QuicklistMenuItemLabel.h" |
2664 | -#include "QuicklistMenuItemRadio.h" |
2665 | -#include "QuicklistMenuItemSeparator.h" |
2666 | - |
2667 | -#include "Nux/Nux.h" |
2668 | -#include "Nux/VLayout.h" |
2669 | -#include "Nux/HLayout.h" |
2670 | -#include "Nux/WindowThread.h" |
2671 | -#include "Nux/WindowCompositor.h" |
2672 | -#include "Nux/BaseWindow.h" |
2673 | - |
2674 | -#include "QuicklistView.h" |
2675 | -#include "TestThreadHelper.h" |
2676 | - |
2677 | -using unity::QuicklistView; |
2678 | -using unity::QuicklistMenuItem; |
2679 | -using unity::QuicklistMenuItemCheckmark; |
2680 | -using unity::QuicklistMenuItemLabel; |
2681 | -using unity::QuicklistMenuItemRadio; |
2682 | -using unity::QuicklistMenuItemSeparator; |
2683 | - |
2684 | -static void TestMenuItemCheckmark(void); |
2685 | -static void TestMenuItemLabel(void); |
2686 | -static void TestMenuItemRadio(void); |
2687 | -static void TestMenuItemSeparator(void); |
2688 | -static void TestQuicklistMenuItem(void); |
2689 | - |
2690 | -nux::WindowThread* thread = NULL; |
2691 | - |
2692 | -void |
2693 | -TestQuicklistMenuitemsCreateSuite() |
2694 | -{ |
2695 | -#define _DOMAIN "/Unit/QuicklistMenuitems" |
2696 | - |
2697 | - g_test_add_func(_DOMAIN"/MenuItemCheckmark", TestMenuItemCheckmark); |
2698 | - g_test_add_func(_DOMAIN"/MenuItemLabel", TestMenuItemLabel); |
2699 | - g_test_add_func(_DOMAIN"/MenuItemRadio", TestMenuItemRadio); |
2700 | - g_test_add_func(_DOMAIN"/MenuItemSeparator", TestMenuItemSeparator); |
2701 | - g_test_add_func(_DOMAIN"/QuicklistMenuItem", TestQuicklistMenuItem); |
2702 | -} |
2703 | - |
2704 | -static void |
2705 | -TestMenuItemCheckmark() |
2706 | -{ |
2707 | - DbusmenuMenuitem* item = NULL; |
2708 | - |
2709 | - |
2710 | - item = dbusmenu_menuitem_new(); |
2711 | - |
2712 | - dbusmenu_menuitem_property_set(item, |
2713 | - DBUSMENU_MENUITEM_PROP_LABEL, |
2714 | - "Unchecked"); |
2715 | - |
2716 | - dbusmenu_menuitem_property_set(item, |
2717 | - DBUSMENU_MENUITEM_PROP_TOGGLE_TYPE, |
2718 | - DBUSMENU_MENUITEM_TOGGLE_CHECK); |
2719 | - |
2720 | - dbusmenu_menuitem_property_set_bool(item, |
2721 | - DBUSMENU_MENUITEM_PROP_ENABLED, |
2722 | - false); |
2723 | - |
2724 | - dbusmenu_menuitem_property_set_int(item, |
2725 | - DBUSMENU_MENUITEM_PROP_TOGGLE_STATE, |
2726 | - DBUSMENU_MENUITEM_TOGGLE_STATE_UNCHECKED); |
2727 | - |
2728 | - QuicklistMenuItemCheckmark* qlCheckmarkItem = NULL; |
2729 | - |
2730 | - qlCheckmarkItem = new QuicklistMenuItemCheckmark(item, true); |
2731 | - |
2732 | - g_assert_cmpstr(qlCheckmarkItem->GetLabel(), == , "Unchecked"); |
2733 | - g_assert_cmpint(qlCheckmarkItem->GetEnabled(), == , false); |
2734 | - g_assert_cmpint(qlCheckmarkItem->GetActive(), == , false); |
2735 | - g_assert_cmpint(qlCheckmarkItem->GetSelectable(), == , false); |
2736 | - g_assert_cmpint(qlCheckmarkItem->IsMarkupEnabled(), == , false); |
2737 | - |
2738 | - //qlCheckmarkItem->sigChanged.connect (sigc::mem_fun (pointerToCallerClass, |
2739 | - // &CallerClass::RecvChanged)); |
2740 | - |
2741 | - |
2742 | - qlCheckmarkItem->Dispose(); |
2743 | - g_object_unref(item); |
2744 | -} |
2745 | - |
2746 | -static void |
2747 | -TestMenuItemLabel() |
2748 | -{ |
2749 | - DbusmenuMenuitem* item = NULL; |
2750 | - |
2751 | - item = dbusmenu_menuitem_new(); |
2752 | - |
2753 | - dbusmenu_menuitem_property_set(item, |
2754 | - DBUSMENU_MENUITEM_PROP_LABEL, |
2755 | - "A Label"); |
2756 | - |
2757 | - dbusmenu_menuitem_property_set_bool(item, |
2758 | - DBUSMENU_MENUITEM_PROP_ENABLED, |
2759 | - true); |
2760 | - |
2761 | - dbusmenu_menuitem_property_set_bool(item, |
2762 | - "unity-use-markup", |
2763 | - true); |
2764 | - |
2765 | - QuicklistMenuItemLabel* qlLabelItem = NULL; |
2766 | - |
2767 | - qlLabelItem = new QuicklistMenuItemLabel(item, true); |
2768 | - |
2769 | - g_assert_cmpstr(qlLabelItem->GetLabel(), == , "A Label"); |
2770 | - g_assert_cmpint(qlLabelItem->GetEnabled(), == , true); |
2771 | - g_assert_cmpint(qlLabelItem->GetSelectable(), == , true); |
2772 | - g_assert_cmpint(qlLabelItem->IsMarkupEnabled(), == , true); |
2773 | - |
2774 | - //qlLabelItem->sigChanged.connect (sigc::mem_fun (pointerToCallerClass, |
2775 | - // &CallerClass::RecvChanged)); |
2776 | - |
2777 | - qlLabelItem->Dispose(); |
2778 | - g_object_unref(item); |
2779 | -} |
2780 | - |
2781 | -static void |
2782 | -TestMenuItemRadio() |
2783 | -{ |
2784 | - DbusmenuMenuitem* item = NULL; |
2785 | - |
2786 | - item = dbusmenu_menuitem_new(); |
2787 | - |
2788 | - dbusmenu_menuitem_property_set(item, |
2789 | - DBUSMENU_MENUITEM_PROP_LABEL, |
2790 | - "Radio Active"); |
2791 | - |
2792 | - dbusmenu_menuitem_property_set(item, |
2793 | - DBUSMENU_MENUITEM_PROP_TOGGLE_TYPE, |
2794 | - DBUSMENU_MENUITEM_TOGGLE_RADIO); |
2795 | - |
2796 | - dbusmenu_menuitem_property_set_bool(item, |
2797 | - DBUSMENU_MENUITEM_PROP_ENABLED, |
2798 | - true); |
2799 | - |
2800 | - dbusmenu_menuitem_property_set_int(item, |
2801 | - DBUSMENU_MENUITEM_PROP_TOGGLE_STATE, |
2802 | - DBUSMENU_MENUITEM_TOGGLE_STATE_CHECKED); |
2803 | - |
2804 | - QuicklistMenuItemRadio* qlRadioItem = NULL; |
2805 | - |
2806 | - qlRadioItem = new QuicklistMenuItemRadio(item, true); |
2807 | - qlRadioItem->EnableLabelMarkup(true); |
2808 | - |
2809 | - g_assert_cmpstr(qlRadioItem->GetLabel(), == , "Radio Active"); |
2810 | - g_assert_cmpint(qlRadioItem->GetEnabled(), == , true); |
2811 | - g_assert_cmpint(qlRadioItem->GetActive(), == , true); |
2812 | - g_assert_cmpint(qlRadioItem->GetSelectable(), == , true); |
2813 | - g_assert_cmpint(qlRadioItem->IsMarkupEnabled(), == , true); |
2814 | - |
2815 | - //qlRadioItem->sigChanged.connect (sigc::mem_fun (pointerToCallerClass, |
2816 | - // &CallerClass::RecvChanged)); |
2817 | - |
2818 | - qlRadioItem->Dispose(); |
2819 | - g_object_unref(item); |
2820 | -} |
2821 | - |
2822 | -static void |
2823 | -TestMenuItemSeparator() |
2824 | -{ |
2825 | - DbusmenuMenuitem* item = NULL; |
2826 | - |
2827 | - item = dbusmenu_menuitem_new(); |
2828 | - |
2829 | - dbusmenu_menuitem_property_set(item, |
2830 | - "type", |
2831 | - DBUSMENU_CLIENT_TYPES_SEPARATOR); |
2832 | - |
2833 | - dbusmenu_menuitem_property_set_bool(item, |
2834 | - DBUSMENU_MENUITEM_PROP_ENABLED, |
2835 | - true); |
2836 | - |
2837 | - QuicklistMenuItemSeparator* qlSeparatorItem = NULL; |
2838 | - |
2839 | - qlSeparatorItem = new QuicklistMenuItemSeparator(item, true); |
2840 | - |
2841 | - g_assert_cmpint(qlSeparatorItem->GetEnabled(), == , true); |
2842 | - g_assert_cmpint(qlSeparatorItem->GetSelectable(), == , false); |
2843 | - |
2844 | - qlSeparatorItem->Dispose(); |
2845 | - g_object_unref(item); |
2846 | -} |
2847 | - |
2848 | -static void |
2849 | -TestQuicklistMenuItem() |
2850 | -{ |
2851 | - DbusmenuMenuitem* root = dbusmenu_menuitem_new(); |
2852 | - |
2853 | - dbusmenu_menuitem_set_root(root, true); |
2854 | - |
2855 | - DbusmenuMenuitem* child = dbusmenu_menuitem_new(); |
2856 | - dbusmenu_menuitem_property_set(child, DBUSMENU_MENUITEM_PROP_TYPE, DBUSMENU_MENUITEM_PROP_LABEL); |
2857 | - dbusmenu_menuitem_property_set(child, DBUSMENU_MENUITEM_PROP_LABEL, "label 0"); |
2858 | - dbusmenu_menuitem_property_set_bool(child, DBUSMENU_MENUITEM_PROP_ENABLED, true); |
2859 | - dbusmenu_menuitem_child_append(root, child); |
2860 | - |
2861 | - child = dbusmenu_menuitem_new(); |
2862 | - dbusmenu_menuitem_property_set(child, DBUSMENU_MENUITEM_PROP_TYPE, DBUSMENU_CLIENT_TYPES_SEPARATOR); |
2863 | - dbusmenu_menuitem_property_set_bool(child, DBUSMENU_MENUITEM_PROP_ENABLED, true); |
2864 | - dbusmenu_menuitem_child_append(root, child); |
2865 | - |
2866 | - child = dbusmenu_menuitem_new(); |
2867 | - dbusmenu_menuitem_property_set(child, DBUSMENU_MENUITEM_PROP_TYPE, DBUSMENU_MENUITEM_PROP_LABEL); |
2868 | - dbusmenu_menuitem_property_set(child, DBUSMENU_MENUITEM_PROP_LABEL, "label 1"); |
2869 | - dbusmenu_menuitem_property_set_bool(child, DBUSMENU_MENUITEM_PROP_ENABLED, true); |
2870 | - dbusmenu_menuitem_child_append(root, child); |
2871 | - |
2872 | - child = dbusmenu_menuitem_new(); |
2873 | - dbusmenu_menuitem_property_set(child, DBUSMENU_MENUITEM_PROP_TOGGLE_TYPE, DBUSMENU_MENUITEM_TOGGLE_CHECK); |
2874 | - dbusmenu_menuitem_property_set(child, DBUSMENU_MENUITEM_PROP_LABEL, "check mark 0"); |
2875 | - dbusmenu_menuitem_property_set_bool(child, DBUSMENU_MENUITEM_PROP_ENABLED, true); |
2876 | - dbusmenu_menuitem_property_set_int(child, DBUSMENU_MENUITEM_PROP_TOGGLE_STATE, DBUSMENU_MENUITEM_TOGGLE_STATE_UNCHECKED); |
2877 | - dbusmenu_menuitem_child_append(root, child); |
2878 | - |
2879 | - QuicklistView* quicklist = new QuicklistView(); |
2880 | - |
2881 | - quicklist->TestMenuItems(root); |
2882 | - |
2883 | - g_assert_cmpint(quicklist->GetNumItems(), == , 4); |
2884 | - g_assert_cmpint(quicklist->GetNthType(0), == , unity::MENUITEM_TYPE_LABEL); |
2885 | - g_assert_cmpint(quicklist->GetNthType(1), == , unity::MENUITEM_TYPE_SEPARATOR); |
2886 | - g_assert_cmpint(quicklist->GetNthType(2), == , unity::MENUITEM_TYPE_LABEL); |
2887 | - g_assert_cmpint(quicklist->GetNthType(3), == , unity::MENUITEM_TYPE_CHECK); |
2888 | - |
2889 | - g_assert_cmpstr(quicklist->GetNthItems(0)->GetLabel(), == , "label 0"); |
2890 | - g_assert_cmpstr(quicklist->GetNthItems(2)->GetLabel(), == , "label 1"); |
2891 | - g_assert_cmpstr(quicklist->GetNthItems(3)->GetLabel(), == , "check mark 0"); |
2892 | - |
2893 | - g_assert_cmpint(quicklist->GetChildren().size(), == , 4); |
2894 | - |
2895 | - quicklist->Dispose(); |
2896 | -} |
On the whole this looks really good.
I'm going to assume that you have actually run and tested all the quick list options.