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