Merge lp:~canonical-dx-team/unity/unity.qlmenuitems into lp:unity
- unity.qlmenuitems
- Merge into trunk
Status: | Merged |
---|---|
Merged at revision: | 631 |
Proposed branch: | lp:~canonical-dx-team/unity/unity.qlmenuitems |
Merge into: | lp:unity |
Diff against target: |
3670 lines (+2757/-366) (has conflicts) 22 files modified
src/LauncherIcon.cpp (+36/-32) src/LauncherIcon.h (+2/-6) src/QuicklistMenuItem.cpp (+442/-0) src/QuicklistMenuItem.h (+140/-0) src/QuicklistMenuItemCheckmark.cpp (+376/-0) src/QuicklistMenuItemCheckmark.h (+63/-0) src/QuicklistMenuItemLabel.cpp (+258/-0) src/QuicklistMenuItemLabel.h (+63/-0) src/QuicklistMenuItemRadio.cpp (+315/-0) src/QuicklistMenuItemRadio.h (+75/-0) src/QuicklistMenuItemSeparator.cpp (+178/-0) src/QuicklistMenuItemSeparator.h (+65/-0) src/QuicklistView.cpp (+306/-109) src/QuicklistView.h (+26/-10) src/StaticCairoText.cpp (+60/-146) src/StaticCairoText.h (+24/-60) src/Tooltip.cpp (+3/-1) src/Tooltip.h (+4/-2) tests/CMakeLists.txt (+13/-0) tests/unit/TestMain.cpp (+47/-0) tests/unit/TestQuicklistMenuitems.cpp (+238/-0) tests/unit/TestThreadHelper.h (+23/-0) Text conflict in tests/unit/TestMain.cpp |
To merge this branch: | bzr merge lp:~canonical-dx-team/unity/unity.qlmenuitems |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Neil J. Patel (community) | Needs Fixing | ||
Mirco Müller (community) | Needs Resubmitting | ||
Review via email: mp+41684@code.launchpad.net |
Commit message
Description of the change
Quicklist:
* label
* check mark
* separator
* highlight on mouse over
* mouse event hooks
* Unit tests
Still missing: connection to real application indicators for the check mark and radio menu items.
Mirco Müller (macslow) wrote : | # |
I'm working on all these fixes now.
Mirco Müller (macslow) wrote : | # |
> - In + else
> 64 + {
> 65 + QuicklistMenuIt
> (newitem, NUX_TRACKER_
> 66 + quicklist-
> 67 + }
>
> I think you should explicitly check for label item, and in the "else" you
> should warn that we don't support item of type $type
From what I've seen and tried with DBusMenu one can explicitly test for a "plain label"-item. Only can one distinguish between a separator, a checkmark-item and a radiobutton-item. Only when tests against these three fail one can implicitly assume one is dealing with a "plain label" item. I've looked at the DBusMenu-API in devhelp and also at the old unit-test test-dbusmenu-
Mirco Müller (macslow) wrote : | # |
So branch is fixed now. Requesting another review.
Neil J. Patel (njpatel) wrote : | # |
Looks much clearer, some remaining issues:
- Conflict with trunk (as discussed)
- Still multiple implementations of DrawText, should be one implementation in QuicklistMenuItem that has enough options that all the sub-classes can use it
- GetTextExtents has the same issue as DrawText, multiple implementations, should be in QuicklistMenuitem class
- Use GtkSettings to also get the current font name of the desktop
- There are multiple implementations of DrawRoundedRect
Mirco Müller (macslow) wrote : | # |
All remaining issues fixed now.
Neil J. Patel (njpatel) wrote : | # |
Looks good! There are some architecture updates which we can work on next week, so as soon as I get a +1 that this fixes an issue for didrocks, I'll approve :)
Preview Diff
1 | === modified file 'src/LauncherIcon.cpp' (properties changed: -x to +x) |
2 | --- src/LauncherIcon.cpp 2010-11-25 05:40:01 +0000 |
3 | +++ src/LauncherIcon.cpp 2010-11-25 15:47:12 +0000 |
4 | @@ -31,6 +31,12 @@ |
5 | #include "LauncherIcon.h" |
6 | #include "Launcher.h" |
7 | |
8 | +#include "QuicklistMenuItem.h" |
9 | +#include "QuicklistMenuItemLabel.h" |
10 | +#include "QuicklistMenuItemSeparator.h" |
11 | +#include "QuicklistMenuItemCheckmark.h" |
12 | +#include "QuicklistMenuItemRadio.h" |
13 | + |
14 | #define DEFAULT_ICON "application-default-icon" |
15 | |
16 | nux::Tooltip *LauncherIcon::_current_tooltip = 0; |
17 | @@ -227,9 +233,7 @@ |
18 | std::list<DbusmenuClient *>::iterator it; |
19 | for (it = menus_list.begin (); it != menus_list.end (); it++) |
20 | { |
21 | - g_signal_connect(G_OBJECT(*it), DBUSMENU_CLIENT_SIGNAL_ROOT_CHANGED, G_CALLBACK(&LauncherIcon::root_changed), _quicklist); |
22 | - dbusmenu_client_add_type_handler (*it, DBUSMENU_CLIENT_TYPES_DEFAULT, (&LauncherIcon::label_handler)); |
23 | - dbusmenu_client_add_type_handler (*it, DBUSMENU_CLIENT_TYPES_SEPARATOR, (&LauncherIcon::separator_handler)); |
24 | + g_signal_connect(G_OBJECT(*it), DBUSMENU_CLIENT_SIGNAL_ROOT_CHANGED, G_CALLBACK(&LauncherIcon::RootChanged), _quicklist); |
25 | } |
26 | |
27 | _quicklist_is_initialized = true; |
28 | @@ -257,45 +261,45 @@ |
29 | _tooltip->ShowWindow (false); |
30 | } |
31 | |
32 | - |
33 | -gboolean LauncherIcon::label_handler (DbusmenuMenuitem * newitem, DbusmenuMenuitem * parent, DbusmenuClient * client) |
34 | -{ |
35 | - //const gchar* s = dbusmenu_menuitem_property_get (newitem, DBUSMENU_MENUITEM_PROP_LABEL); |
36 | - //printf ("label: %s\n", s); |
37 | - |
38 | - return true; |
39 | -} |
40 | - |
41 | -gboolean LauncherIcon::separator_handler (DbusmenuMenuitem * newitem, DbusmenuMenuitem * parent, DbusmenuClient * client) |
42 | -{ |
43 | - //const gchar* s = dbusmenu_menuitem_property_get (newitem, DBUSMENU_MENUITEM_PROP_LABEL); |
44 | - //printf ("separator: %s\n", s); |
45 | - |
46 | - return true; |
47 | -} |
48 | - |
49 | -void LauncherIcon::child_realized (DbusmenuMenuitem *newitem, QuicklistView *quicklist) |
50 | -{ |
51 | - const gchar* label = dbusmenu_menuitem_property_get (newitem, DBUSMENU_MENUITEM_PROP_LABEL); |
52 | +void LauncherIcon::ChildRealized (DbusmenuMenuitem *newitem, QuicklistView *quicklist) |
53 | +{ |
54 | + g_return_if_fail (newitem); |
55 | + |
56 | const gchar* type = dbusmenu_menuitem_property_get (newitem, DBUSMENU_MENUITEM_PROP_TYPE); |
57 | + const gchar* toggle_type = dbusmenu_menuitem_property_get (newitem, DBUSMENU_MENUITEM_PROP_TOGGLE_TYPE); |
58 | |
59 | if (g_strcmp0 (type, DBUSMENU_CLIENT_TYPES_SEPARATOR) == 0) |
60 | { |
61 | - quicklist->AddMenuItem ("-----------------"); |
62 | - } |
63 | - else |
64 | - { |
65 | - quicklist->AddMenuItem (label); |
66 | - } |
67 | - |
68 | + QuicklistMenuItemSeparator* item = new QuicklistMenuItemSeparator (newitem, NUX_TRACKER_LOCATION); |
69 | + quicklist->AddMenuItem (item); |
70 | + } |
71 | + else if (g_strcmp0 (toggle_type, DBUSMENU_MENUITEM_TOGGLE_CHECK) == 0) |
72 | + { |
73 | + QuicklistMenuItemCheckmark* item = new QuicklistMenuItemCheckmark (newitem, NUX_TRACKER_LOCATION); |
74 | + quicklist->AddMenuItem (item); |
75 | + } |
76 | + else if (g_strcmp0 (toggle_type, DBUSMENU_MENUITEM_TOGGLE_RADIO) == 0) |
77 | + { |
78 | + QuicklistMenuItemRadio* item = new QuicklistMenuItemRadio (newitem, NUX_TRACKER_LOCATION); |
79 | + quicklist->AddMenuItem (item); |
80 | + } |
81 | + else //(g_strcmp0 (type, DBUSMENU_MENUITEM_PROP_LABEL) == 0) |
82 | + { |
83 | + QuicklistMenuItemLabel* item = new QuicklistMenuItemLabel (newitem, NUX_TRACKER_LOCATION); |
84 | + quicklist->AddMenuItem (item); |
85 | + } |
86 | +// else |
87 | +// { |
88 | +// g_warning ("Unknown menu item type in file %s at line %s", G_STRFUNC, G_STRLOC); |
89 | +// } |
90 | } |
91 | |
92 | -void LauncherIcon::root_changed (DbusmenuClient * client, DbusmenuMenuitem * newroot, QuicklistView *quicklist) |
93 | +void LauncherIcon::RootChanged (DbusmenuClient * client, DbusmenuMenuitem * newroot, QuicklistView *quicklist) |
94 | { |
95 | GList * child = NULL; |
96 | for (child = dbusmenu_menuitem_get_children(newroot); child != NULL; child = g_list_next(child)) |
97 | { |
98 | - g_signal_connect(G_OBJECT(child->data), DBUSMENU_MENUITEM_SIGNAL_REALIZED, G_CALLBACK(child_realized), quicklist); |
99 | + g_signal_connect(G_OBJECT(child->data), DBUSMENU_MENUITEM_SIGNAL_REALIZED, G_CALLBACK(ChildRealized), quicklist); |
100 | } |
101 | } |
102 | |
103 | |
104 | === modified file 'src/LauncherIcon.h' |
105 | --- src/LauncherIcon.h 2010-11-25 05:40:01 +0000 |
106 | +++ src/LauncherIcon.h 2010-11-25 15:47:12 +0000 |
107 | @@ -157,12 +157,8 @@ |
108 | friend class LauncherController; |
109 | |
110 | private: |
111 | - |
112 | - static gboolean label_handler (DbusmenuMenuitem * newitem, DbusmenuMenuitem * parent, DbusmenuClient * client); |
113 | - static gboolean separator_handler (DbusmenuMenuitem * newitem, DbusmenuMenuitem * parent, DbusmenuClient * client); |
114 | - |
115 | - static void child_realized (DbusmenuMenuitem *newitem, QuicklistView *quicklist); |
116 | - static void root_changed (DbusmenuClient * client, DbusmenuMenuitem *newroot, QuicklistView *quicklist); |
117 | + static void ChildRealized (DbusmenuMenuitem *newitem, QuicklistView *quicklist); |
118 | + static void RootChanged (DbusmenuClient * client, DbusmenuMenuitem *newroot, QuicklistView *quicklist); |
119 | static gboolean OnPresentTimeout (gpointer data); |
120 | static gboolean OnCenterTimeout (gpointer data); |
121 | |
122 | |
123 | === added file 'src/QuicklistMenuItem.cpp' |
124 | --- src/QuicklistMenuItem.cpp 1970-01-01 00:00:00 +0000 |
125 | +++ src/QuicklistMenuItem.cpp 2010-11-25 15:47:12 +0000 |
126 | @@ -0,0 +1,442 @@ |
127 | +/* |
128 | + * Copyright (C) 2010 Canonical Ltd |
129 | + * |
130 | + * This program is free software: you can redistribute it and/or modify |
131 | + * it under the terms of the GNU General Public License version 3 as |
132 | + * published by the Free Software Foundation. |
133 | + * |
134 | + * This program is distributed in the hope that it will be useful, |
135 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
136 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
137 | + * GNU General Public License for more details. |
138 | + * |
139 | + * You should have received a copy of the GNU General Public License |
140 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
141 | + * |
142 | + * Authored by: Mirco Müller <mirco.mueller@canonical.com> |
143 | + * Authored by: Jay Taoko <jay.taoko@canonical.com> |
144 | + */ |
145 | + |
146 | +#include <gdk/gdk.h> |
147 | +#include <gtk/gtk.h> |
148 | + |
149 | +#include "Nux/Nux.h" |
150 | +#include "QuicklistMenuItem.h" |
151 | + |
152 | +#include <X11/Xlib.h> |
153 | + |
154 | +#define ITEM_INDENT_ABS 20 |
155 | +#define ITEM_CORNER_RADIUS_ABS 4 |
156 | + |
157 | +static void |
158 | +OnPropertyChanged (gchar* property, |
159 | + GValue* value, |
160 | + QuicklistMenuItem* self); |
161 | + |
162 | +static void |
163 | +OnItemActivated (guint timestamp, |
164 | + QuicklistMenuItem* self); |
165 | + |
166 | +QuicklistMenuItem::QuicklistMenuItem (DbusmenuMenuitem* item, |
167 | + NUX_FILE_LINE_DECL) : |
168 | +View (NUX_FILE_LINE_PARAM) |
169 | +{ |
170 | + if (item == 0) |
171 | + { |
172 | + g_warning ("Invalid DbusmenuMenuitem in file %s at line %s.", G_STRFUNC, G_STRLOC); |
173 | + } |
174 | + |
175 | + _text = 0; |
176 | + _color = nux::Color (1.0f, 1.0f, 1.0f, 1.0f); |
177 | + _menuItem = item; |
178 | + _debug = false; |
179 | + _item_type = MENUITEM_TYPE_UNKNOWN; |
180 | + |
181 | + _normalTexture[0] = NULL; |
182 | + _normalTexture[1] = NULL; |
183 | + _prelightTexture[0] = NULL; |
184 | + _prelightTexture[1] = NULL; |
185 | + |
186 | + if (_menuItem) |
187 | + { |
188 | + g_signal_connect (_menuItem, |
189 | + "property-changed", |
190 | + G_CALLBACK (OnPropertyChanged), |
191 | + this); |
192 | + g_signal_connect (_menuItem, |
193 | + "item-activated", |
194 | + G_CALLBACK (OnItemActivated), |
195 | + this); |
196 | + } |
197 | + |
198 | + OnMouseDown.connect (sigc::mem_fun (this, &QuicklistMenuItem::RecvMouseDown)); |
199 | + OnMouseUp.connect (sigc::mem_fun (this, &QuicklistMenuItem::RecvMouseUp)); |
200 | + OnMouseClick.connect (sigc::mem_fun (this, &QuicklistMenuItem::RecvMouseClick)); |
201 | + OnMouseMove.connect (sigc::mem_fun (this, &QuicklistMenuItem::RecvMouseMove)); |
202 | + OnMouseDrag.connect (sigc::mem_fun (this, &QuicklistMenuItem::RecvMouseDrag)); |
203 | + OnMouseEnter.connect (sigc::mem_fun (this, &QuicklistMenuItem::RecvMouseEnter)); |
204 | + OnMouseLeave.connect (sigc::mem_fun (this, &QuicklistMenuItem::RecvMouseLeave)); |
205 | + |
206 | + _prelight = false; |
207 | +} |
208 | + |
209 | +QuicklistMenuItem::QuicklistMenuItem (DbusmenuMenuitem* item, |
210 | + bool debug, |
211 | + NUX_FILE_LINE_DECL) : |
212 | +View (NUX_FILE_LINE_PARAM) |
213 | +{ |
214 | + _text = 0; |
215 | + _color = nux::Color (1.0f, 1.0f, 1.0f, 1.0f); |
216 | + _menuItem = item; |
217 | + _debug = debug; |
218 | + _item_type = MENUITEM_TYPE_UNKNOWN; |
219 | + |
220 | + _normalTexture[0] = NULL; |
221 | + _normalTexture[1] = NULL; |
222 | + _prelightTexture[0] = NULL; |
223 | + _prelightTexture[1] = NULL; |
224 | + |
225 | + if (_menuItem) |
226 | + { |
227 | + g_signal_connect (_menuItem, |
228 | + "property-changed", |
229 | + G_CALLBACK (OnPropertyChanged), |
230 | + this); |
231 | + g_signal_connect (_menuItem, |
232 | + "item-activated", |
233 | + G_CALLBACK (OnItemActivated), |
234 | + this); |
235 | + } |
236 | + |
237 | + OnMouseDown.connect (sigc::mem_fun (this, &QuicklistMenuItem::RecvMouseDown)); |
238 | + OnMouseUp.connect (sigc::mem_fun (this, &QuicklistMenuItem::RecvMouseUp)); |
239 | + OnMouseClick.connect (sigc::mem_fun (this, &QuicklistMenuItem::RecvMouseClick)); |
240 | + OnMouseMove.connect (sigc::mem_fun (this, &QuicklistMenuItem::RecvMouseMove)); |
241 | + OnMouseDrag.connect (sigc::mem_fun (this, &QuicklistMenuItem::RecvMouseDrag)); |
242 | + OnMouseEnter.connect (sigc::mem_fun (this, &QuicklistMenuItem::RecvMouseEnter)); |
243 | + OnMouseLeave.connect (sigc::mem_fun (this, &QuicklistMenuItem::RecvMouseLeave)); |
244 | + |
245 | + _prelight = false; |
246 | +} |
247 | + |
248 | +QuicklistMenuItem::~QuicklistMenuItem () |
249 | +{ |
250 | + if (_text) |
251 | + g_free (_text); |
252 | +} |
253 | + |
254 | +QuicklistMenuItemType QuicklistMenuItem::GetItemType () |
255 | +{ |
256 | + return _item_type; |
257 | +} |
258 | + |
259 | +void |
260 | +QuicklistMenuItem::PreLayoutManagement () |
261 | +{ |
262 | + View::PreLayoutManagement (); |
263 | +} |
264 | + |
265 | +long |
266 | +QuicklistMenuItem::PostLayoutManagement (long layoutResult) |
267 | +{ |
268 | + long result = View::PostLayoutManagement (layoutResult); |
269 | + |
270 | + return result; |
271 | +} |
272 | + |
273 | +long |
274 | +QuicklistMenuItem::ProcessEvent (nux::IEvent& event, |
275 | + long traverseInfo, |
276 | + long processEventInfo) |
277 | +{ |
278 | + long result = traverseInfo; |
279 | + |
280 | + result = nux::View::PostProcessEvent2 (event, result, processEventInfo); |
281 | + return result; |
282 | + |
283 | +} |
284 | + |
285 | +void |
286 | +QuicklistMenuItem::Draw (nux::GraphicsEngine& gfxContext, |
287 | + bool forceDraw) |
288 | +{ |
289 | +} |
290 | + |
291 | +void |
292 | +QuicklistMenuItem::DrawContent (nux::GraphicsEngine& gfxContext, |
293 | + bool forceDraw) |
294 | +{ |
295 | +} |
296 | + |
297 | +void |
298 | +QuicklistMenuItem::PostDraw (nux::GraphicsEngine& gfxContext, |
299 | + bool forceDraw) |
300 | +{ |
301 | +} |
302 | + |
303 | +const gchar* |
304 | +QuicklistMenuItem::GetLabel () |
305 | +{ |
306 | + if (_menuItem == 0) |
307 | + return 0; |
308 | + return dbusmenu_menuitem_property_get (_menuItem, |
309 | + DBUSMENU_MENUITEM_PROP_LABEL); |
310 | +} |
311 | + |
312 | +bool |
313 | +QuicklistMenuItem::GetEnabled () |
314 | +{ |
315 | + if (_menuItem == 0) |
316 | + return false; |
317 | + return dbusmenu_menuitem_property_get_bool (_menuItem, |
318 | + DBUSMENU_MENUITEM_PROP_ENABLED); |
319 | +} |
320 | + |
321 | +bool |
322 | +QuicklistMenuItem::GetActive () |
323 | +{ |
324 | + if (_menuItem == 0) |
325 | + return false; |
326 | + return dbusmenu_menuitem_property_get_bool (_menuItem, |
327 | + DBUSMENU_MENUITEM_PROP_TOGGLE_STATE); |
328 | +} |
329 | + |
330 | +void QuicklistMenuItem::ItemActivated () |
331 | +{ |
332 | + if (_debug) |
333 | + sigChanged.emit (*this); |
334 | + |
335 | + std::cout << "ItemActivated() called" << std::endl; |
336 | +} |
337 | + |
338 | +void QuicklistMenuItem::GetTextExtents (int &width, int &height) |
339 | +{ |
340 | + GtkSettings* settings = gtk_settings_get_default (); // not ref'ed |
341 | + gchar* fontName = NULL; |
342 | + |
343 | + g_object_get (settings, "gtk-font-name", &fontName, NULL); |
344 | + GetTextExtents (fontName, width, height); |
345 | + g_free (fontName); |
346 | +} |
347 | + |
348 | +void QuicklistMenuItem::GetTextExtents (const gchar* font, |
349 | + int& width, |
350 | + int& height) |
351 | +{ |
352 | + cairo_surface_t* surface = NULL; |
353 | + cairo_t* cr = NULL; |
354 | + PangoLayout* layout = NULL; |
355 | + PangoFontDescription* desc = NULL; |
356 | + PangoContext* pangoCtx = NULL; |
357 | + PangoRectangle logRect = {0, 0, 0, 0}; |
358 | + int dpi = 0; |
359 | + GdkScreen* screen = gdk_screen_get_default (); // is not ref'ed |
360 | + GtkSettings* settings = gtk_settings_get_default (); // is not ref'ed |
361 | + |
362 | + // sanity check |
363 | + if (!font) |
364 | + return; |
365 | + |
366 | + surface = cairo_image_surface_create (CAIRO_FORMAT_A1, 1, 1); |
367 | + cr = cairo_create (surface); |
368 | + cairo_set_font_options (cr, gdk_screen_get_font_options (screen)); |
369 | + layout = pango_cairo_create_layout (cr); |
370 | + desc = pango_font_description_from_string (font); |
371 | + pango_font_description_set_weight (desc, PANGO_WEIGHT_NORMAL); |
372 | + pango_layout_set_font_description (layout, desc); |
373 | + pango_layout_set_wrap (layout, PANGO_WRAP_WORD_CHAR); |
374 | + pango_layout_set_ellipsize (layout, PANGO_ELLIPSIZE_END); |
375 | + pango_layout_set_markup (layout, _text, -1); |
376 | + pangoCtx = pango_layout_get_context (layout); // is not ref'ed |
377 | + pango_cairo_context_set_font_options (pangoCtx, |
378 | + gdk_screen_get_font_options (screen)); |
379 | + g_object_get (settings, "gtk-xft-dpi", &dpi, NULL); |
380 | + if (dpi == -1) |
381 | + { |
382 | + // use some default DPI-value |
383 | + pango_cairo_context_set_resolution (pangoCtx, 96.0f); |
384 | + } |
385 | + else |
386 | + { |
387 | + pango_cairo_context_set_resolution (pangoCtx, |
388 | + (float) dpi / (float) PANGO_SCALE); |
389 | + } |
390 | + pango_layout_context_changed (layout); |
391 | + pango_layout_get_extents (layout, NULL, &logRect); |
392 | + |
393 | + width = logRect.width / PANGO_SCALE; |
394 | + height = logRect.height / PANGO_SCALE; |
395 | + |
396 | + // clean up |
397 | + pango_font_description_free (desc); |
398 | + g_object_unref (layout); |
399 | + cairo_destroy (cr); |
400 | + cairo_surface_destroy (surface); |
401 | +} |
402 | + |
403 | +static void |
404 | +OnPropertyChanged (gchar* property, |
405 | + GValue* value, |
406 | + QuicklistMenuItem* self) |
407 | +{ |
408 | + //todo |
409 | + //self->UpdateTexture (); |
410 | +} |
411 | + |
412 | +static void |
413 | +OnItemActivated (guint timestamp, |
414 | + QuicklistMenuItem* self) |
415 | +{ |
416 | + //todo: |
417 | + //self->ItemActivated (); |
418 | +} |
419 | + |
420 | +void QuicklistMenuItem::RecvMouseDown (int x, int y, unsigned long button_flags, unsigned long key_flags) |
421 | +{ |
422 | + |
423 | +} |
424 | + |
425 | +void QuicklistMenuItem::RecvMouseUp (int x, int y, unsigned long button_flags, unsigned long key_flags) |
426 | +{ |
427 | + sigMouseReleased.emit (this); |
428 | +} |
429 | + |
430 | +void QuicklistMenuItem::RecvMouseClick (int x, int y, unsigned long button_flags, unsigned long key_flags) |
431 | +{ |
432 | + if (!GetEnabled ()) |
433 | + { |
434 | + sigMouseClick.emit (this); |
435 | + return; |
436 | + } |
437 | + sigMouseClick.emit (this); |
438 | +} |
439 | + |
440 | +void QuicklistMenuItem::RecvMouseMove (int x, int y, int dx, int dy, unsigned long button_flags, unsigned long key_flags) |
441 | +{ |
442 | + |
443 | +} |
444 | + |
445 | +void QuicklistMenuItem::RecvMouseDrag (int x, int y, int dx, int dy, unsigned long button_flags, unsigned long key_flags) |
446 | +{ |
447 | + |
448 | +} |
449 | + |
450 | +void QuicklistMenuItem::RecvMouseEnter (int x, int y, unsigned long button_flags, unsigned long key_flags) |
451 | +{ |
452 | + _prelight = true; |
453 | + sigMouseEnter.emit (this); |
454 | +} |
455 | + |
456 | +void QuicklistMenuItem::RecvMouseLeave (int x, int y, unsigned long button_flags, unsigned long key_flags) |
457 | +{ |
458 | + _prelight = false; |
459 | + sigMouseLeave.emit (this); |
460 | +} |
461 | + |
462 | +void |
463 | +QuicklistMenuItem::DrawRoundedRectangle (cairo_t* cr, |
464 | + double aspect, |
465 | + double x, |
466 | + double y, |
467 | + double cornerRadius, |
468 | + double width, |
469 | + double height) |
470 | +{ |
471 | + double radius = cornerRadius / aspect; |
472 | + |
473 | + // top-left, right of the corner |
474 | + cairo_move_to (cr, x + radius, y); |
475 | + |
476 | + // top-right, left of the corner |
477 | + cairo_line_to (cr, x + width - radius, y); |
478 | + |
479 | + // top-right, below the corner |
480 | + cairo_arc (cr, |
481 | + x + width - radius, |
482 | + y + radius, |
483 | + radius, |
484 | + -90.0f * G_PI / 180.0f, |
485 | + 0.0f * G_PI / 180.0f); |
486 | + |
487 | + // bottom-right, above the corner |
488 | + cairo_line_to (cr, x + width, y + height - radius); |
489 | + |
490 | + // bottom-right, left of the corner |
491 | + cairo_arc (cr, |
492 | + x + width - radius, |
493 | + y + height - radius, |
494 | + radius, |
495 | + 0.0f * G_PI / 180.0f, |
496 | + 90.0f * G_PI / 180.0f); |
497 | + |
498 | + // bottom-left, right of the corner |
499 | + cairo_line_to (cr, x + radius, y + height); |
500 | + |
501 | + // bottom-left, above the corner |
502 | + cairo_arc (cr, |
503 | + x + radius, |
504 | + y + height - radius, |
505 | + radius, |
506 | + 90.0f * G_PI / 180.0f, |
507 | + 180.0f * G_PI / 180.0f); |
508 | + |
509 | + // top-left, right of the corner |
510 | + cairo_arc (cr, |
511 | + x + radius, |
512 | + y + radius, |
513 | + radius, |
514 | + 180.0f * G_PI / 180.0f, |
515 | + 270.0f * G_PI / 180.0f); |
516 | +} |
517 | + |
518 | +void |
519 | +QuicklistMenuItem::DrawText (cairo_t* cr, |
520 | + int width, |
521 | + int height, |
522 | + nux::Color color) |
523 | +{ |
524 | + int textWidth = 0; |
525 | + int textHeight = 0; |
526 | + PangoLayout* layout = NULL; |
527 | + PangoFontDescription* desc = NULL; |
528 | + PangoContext* pangoCtx = NULL; |
529 | + int dpi = 0; |
530 | + GdkScreen* screen = gdk_screen_get_default (); // not ref'ed |
531 | + GtkSettings* settings = gtk_settings_get_default (); // not ref'ed |
532 | + gchar* fontName = NULL; |
533 | + |
534 | + g_object_get (settings, "gtk-font-name", &fontName, NULL); |
535 | + GetTextExtents (fontName, textWidth, textHeight); |
536 | + |
537 | + cairo_set_font_options (cr, gdk_screen_get_font_options (screen)); |
538 | + layout = pango_cairo_create_layout (cr); |
539 | + desc = pango_font_description_from_string (fontName); |
540 | + pango_layout_set_font_description (layout, desc); |
541 | + pango_layout_set_wrap (layout, PANGO_WRAP_WORD_CHAR); |
542 | + pango_layout_set_ellipsize (layout, PANGO_ELLIPSIZE_END); |
543 | + pango_layout_set_markup (layout, _text, -1); |
544 | + pangoCtx = pango_layout_get_context (layout); // is not ref'ed |
545 | + pango_cairo_context_set_font_options (pangoCtx, |
546 | + gdk_screen_get_font_options (screen)); |
547 | + g_object_get (settings, "gtk-xft-dpi", &dpi, NULL); |
548 | + if (dpi == -1) |
549 | + { |
550 | + // use some default DPI-value |
551 | + pango_cairo_context_set_resolution (pangoCtx, 96.0f); |
552 | + } |
553 | + else |
554 | + { |
555 | + pango_cairo_context_set_resolution (pangoCtx, |
556 | + (float) dpi / (float) PANGO_SCALE); |
557 | + } |
558 | + |
559 | + pango_layout_context_changed (layout); |
560 | + |
561 | + cairo_move_to (cr, ITEM_INDENT_ABS, (float) (height - textHeight) / 2.0f); |
562 | + pango_cairo_show_layout (cr, layout); |
563 | + |
564 | + // clean up |
565 | + pango_font_description_free (desc); |
566 | + g_free (fontName); |
567 | + g_object_unref (layout); |
568 | +} |
569 | |
570 | === added file 'src/QuicklistMenuItem.h' |
571 | --- src/QuicklistMenuItem.h 1970-01-01 00:00:00 +0000 |
572 | +++ src/QuicklistMenuItem.h 2010-11-25 15:47:12 +0000 |
573 | @@ -0,0 +1,140 @@ |
574 | +/* |
575 | + * Copyright (C) 2010 Canonical Ltd |
576 | + * |
577 | + * This program is free software: you can redistribute it and/or modify |
578 | + * it under the terms of the GNU General Public License version 3 as |
579 | + * published by the Free Software Foundation. |
580 | + * |
581 | + * This program is distributed in the hope that it will be useful, |
582 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
583 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
584 | + * GNU General Public License for more details. |
585 | + * |
586 | + * You should have received a copy of the GNU General Public License |
587 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
588 | + * |
589 | + * Authored by: Mirco Müller <mirco.mueller@canonical.com> |
590 | + * Authored by: Jay Taoko <jay.taoko@canonical.com> |
591 | + */ |
592 | + |
593 | +#ifndef QUICKLISTMENUITEM_H |
594 | +#define QUICKLISTMENUITEM_H |
595 | + |
596 | +#include <libdbusmenu-glib/menuitem.h> |
597 | +#include <libdbusmenu-glib/client.h> |
598 | + |
599 | +#include "Nux/Nux.h" |
600 | +#include "Nux/View.h" |
601 | +#include "NuxImage/CairoGraphics.h" |
602 | + |
603 | +#include <pango/pango.h> |
604 | +#include <pango/pangocairo.h> |
605 | + |
606 | +typedef enum |
607 | +{ |
608 | + MENUITEM_TYPE_UNKNOWN = 0, |
609 | + MENUITEM_TYPE_LABEL, |
610 | + MENUITEM_TYPE_SEPARATOR, |
611 | + MENUITEM_TYPE_CHECK, |
612 | + MENUITEM_TYPE_RADIO, |
613 | +} QuicklistMenuItemType; |
614 | + |
615 | +class QuicklistMenuItem : public nux::View |
616 | +{ |
617 | + public: |
618 | + QuicklistMenuItem (DbusmenuMenuitem* item, |
619 | + NUX_FILE_LINE_PROTO); |
620 | + |
621 | + QuicklistMenuItem (DbusmenuMenuitem* item, |
622 | + bool debug, |
623 | + NUX_FILE_LINE_PROTO); |
624 | + |
625 | + virtual ~QuicklistMenuItem (); |
626 | + |
627 | + void PreLayoutManagement (); |
628 | + |
629 | + long PostLayoutManagement (long layoutResult); |
630 | + |
631 | + long ProcessEvent (nux::IEvent& event, |
632 | + long traverseInfo, |
633 | + long processEventInfo); |
634 | + |
635 | + void Draw (nux::GraphicsEngine& gfxContext, |
636 | + bool forceDraw); |
637 | + |
638 | + void DrawContent (nux::GraphicsEngine& gfxContext, |
639 | + bool forceDraw); |
640 | + |
641 | + void PostDraw (nux::GraphicsEngine& gfxContext, |
642 | + bool forceDraw); |
643 | + |
644 | + QuicklistMenuItemType GetItemType (); |
645 | + |
646 | + void ItemActivated (); |
647 | + |
648 | + sigc::signal<void, QuicklistMenuItem&> sigChanged; |
649 | + sigc::signal<void, QuicklistMenuItem*> sigTextChanged; |
650 | + sigc::signal<void, QuicklistMenuItem*> sigColorChanged; |
651 | + |
652 | + virtual const gchar* GetLabel (); |
653 | + |
654 | + virtual bool GetEnabled (); |
655 | + |
656 | + virtual bool GetActive (); |
657 | + |
658 | + protected: |
659 | + |
660 | + gchar* _text; |
661 | + nux::Color _textColor; |
662 | + int _pre_layout_width; |
663 | + int _pre_layout_height; |
664 | + nux::CairoGraphics* _cairoGraphics; |
665 | + |
666 | + nux::BaseTexture* _normalTexture[2]; |
667 | + nux::BaseTexture* _prelightTexture[2]; |
668 | + |
669 | + //! Return the size of the text + size of associated radio button or check box |
670 | + void GetTextExtents (int &width, int &height); |
671 | + void GetTextExtents (const gchar* font, int& width, int& height); |
672 | + virtual void UpdateTexture () = 0; |
673 | + virtual int CairoSurfaceWidth () = 0; |
674 | + |
675 | + void RecvMouseEnter (int x, int y, unsigned long button_flags, unsigned long key_flags); |
676 | + void RecvMouseLeave (int x, int y, unsigned long button_flags, unsigned long key_flags); |
677 | + void RecvMouseDown (int x, int y, unsigned long button_flags, unsigned long key_flags); |
678 | + void RecvMouseUp (int x, int y, unsigned long button_flags, unsigned long key_flags); |
679 | + void RecvMouseClick (int x, int y, unsigned long button_flags, unsigned long key_flags); |
680 | + void RecvMouseMove (int x, int y, int dx, int dy, unsigned long button_flags, unsigned long key_flags); |
681 | + void RecvMouseDrag (int x, int y, int dx, int dy, unsigned long button_flags, unsigned long key_flags); |
682 | + |
683 | + sigc::signal<void, QuicklistMenuItem*> sigMouseEnter; |
684 | + sigc::signal<void, QuicklistMenuItem*> sigMouseLeave; |
685 | + sigc::signal<void, QuicklistMenuItem*> sigMouseReleased; |
686 | + sigc::signal<void, QuicklistMenuItem*> sigMouseClick; |
687 | + |
688 | + DbusmenuMenuitem* _menuItem; |
689 | + QuicklistMenuItemType _item_type; |
690 | + |
691 | + nux::Color _color; //!< Item rendering color factor. |
692 | + bool _debug; |
693 | + |
694 | + |
695 | + bool _prelight; //!< True when the mouse is over the item. |
696 | + |
697 | + void DrawRoundedRectangle (cairo_t* cr, |
698 | + double aspect, |
699 | + double x, |
700 | + double y, |
701 | + double cornerRadius, |
702 | + double width, |
703 | + double height); |
704 | + |
705 | + void DrawText (cairo_t* cr, |
706 | + int width, |
707 | + int height, |
708 | + nux::Color color); |
709 | + |
710 | + friend class QuicklistView; |
711 | +}; |
712 | + |
713 | +#endif // QUICKLISTMENUITEM_H |
714 | |
715 | === added file 'src/QuicklistMenuItemCheckmark.cpp' |
716 | --- src/QuicklistMenuItemCheckmark.cpp 1970-01-01 00:00:00 +0000 |
717 | +++ src/QuicklistMenuItemCheckmark.cpp 2010-11-25 15:47:12 +0000 |
718 | @@ -0,0 +1,376 @@ |
719 | +/* |
720 | + * Copyright (C) 2010 Canonical Ltd |
721 | + * |
722 | + * This program is free software: you can redistribute it and/or modify |
723 | + * it under the terms of the GNU General Public License version 3 as |
724 | + * published by the Free Software Foundation. |
725 | + * |
726 | + * This program is distributed in the hope that it will be useful, |
727 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
728 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
729 | + * GNU General Public License for more details. |
730 | + * |
731 | + * You should have received a copy of the GNU General Public License |
732 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
733 | + * |
734 | + * Authored by: Mirco Müller <mirco.mueller@canonical.com> |
735 | + * Authored by: Jay Taoko <jay.taoko@canonical.com> |
736 | + */ |
737 | + |
738 | +#include <gdk/gdk.h> |
739 | +#include <gtk/gtk.h> |
740 | + |
741 | +#include "Nux/Nux.h" |
742 | +#include "QuicklistMenuItemCheckmark.h" |
743 | + |
744 | +#define ITEM_INDENT_ABS 20 |
745 | +#define ITEM_CORNER_RADIUS_ABS 4 |
746 | + |
747 | +static double |
748 | +_align (double val) |
749 | +{ |
750 | + double fract = val - (int) val; |
751 | + |
752 | + if (fract != 0.5f) |
753 | + return (double) ((int) val + 0.5f); |
754 | + else |
755 | + return val; |
756 | +} |
757 | + |
758 | +QuicklistMenuItemCheckmark::QuicklistMenuItemCheckmark (DbusmenuMenuitem* item, |
759 | + NUX_FILE_LINE_DECL) : |
760 | +QuicklistMenuItem (item, |
761 | + NUX_FILE_LINE_PARAM) |
762 | +{ |
763 | + Initialize (item); |
764 | +} |
765 | + |
766 | +QuicklistMenuItemCheckmark::QuicklistMenuItemCheckmark (DbusmenuMenuitem* item, |
767 | + bool debug, |
768 | + NUX_FILE_LINE_DECL) : |
769 | +QuicklistMenuItem (item, |
770 | + debug, |
771 | + NUX_FILE_LINE_PARAM) |
772 | +{ |
773 | + Initialize (item); |
774 | +} |
775 | + |
776 | +void |
777 | +QuicklistMenuItemCheckmark::Initialize (DbusmenuMenuitem* item) |
778 | +{ |
779 | + _item_type = MENUITEM_TYPE_CHECK; |
780 | + |
781 | + if (item) |
782 | + _text = g_strdup (dbusmenu_menuitem_property_get (item, DBUSMENU_MENUITEM_PROP_LABEL)); |
783 | + else |
784 | + _text = g_strdup ("Check Mark"); |
785 | + |
786 | + int textWidth = 1; |
787 | + int textHeight = 1; |
788 | + GetTextExtents (textWidth, textHeight); |
789 | + SetMinimumSize (textWidth + ITEM_INDENT_ABS, textHeight); |
790 | +} |
791 | + |
792 | +QuicklistMenuItemCheckmark::~QuicklistMenuItemCheckmark () |
793 | +{ |
794 | + if (_normalTexture[0]) |
795 | + _normalTexture[0]->UnReference (); |
796 | + |
797 | + if (_normalTexture[1]) |
798 | + _normalTexture[1]->UnReference (); |
799 | + |
800 | + if (_prelightTexture[0]) |
801 | + _prelightTexture[0]->UnReference (); |
802 | + |
803 | + if (_prelightTexture[1]) |
804 | + _prelightTexture[1]->UnReference (); |
805 | +} |
806 | + |
807 | +void |
808 | +QuicklistMenuItemCheckmark::PreLayoutManagement () |
809 | +{ |
810 | + _pre_layout_width = GetBaseWidth (); |
811 | + _pre_layout_height = GetBaseHeight (); |
812 | + |
813 | + if (_normalTexture[0] == 0) |
814 | + { |
815 | + UpdateTexture (); |
816 | + } |
817 | + |
818 | + QuicklistMenuItem::PreLayoutManagement (); |
819 | +} |
820 | + |
821 | +long |
822 | +QuicklistMenuItemCheckmark::PostLayoutManagement (long layoutResult) |
823 | +{ |
824 | + int w = GetBaseWidth(); |
825 | + int h = GetBaseHeight(); |
826 | + |
827 | + long result = 0; |
828 | + |
829 | + if (_pre_layout_width < w) |
830 | + result |= nux::eLargerWidth; |
831 | + else if (_pre_layout_width > w) |
832 | + result |= nux::eSmallerWidth; |
833 | + else |
834 | + result |= nux::eCompliantWidth; |
835 | + |
836 | + if (_pre_layout_height < h) |
837 | + result |= nux::eLargerHeight; |
838 | + else if (_pre_layout_height > h) |
839 | + result |= nux::eSmallerHeight; |
840 | + else |
841 | + result |= nux::eCompliantHeight; |
842 | + |
843 | + return result; |
844 | +} |
845 | + |
846 | +long |
847 | +QuicklistMenuItemCheckmark::ProcessEvent (nux::IEvent& event, |
848 | + long traverseInfo, |
849 | + long processEventInfo) |
850 | +{ |
851 | + long result = traverseInfo; |
852 | + |
853 | + result = nux::View::PostProcessEvent2 (event, result, processEventInfo); |
854 | + return result; |
855 | +} |
856 | + |
857 | +void |
858 | +QuicklistMenuItemCheckmark::Draw (nux::GraphicsEngine& gfxContext, |
859 | + bool forceDraw) |
860 | +{ |
861 | + nux::IntrusiveSP<nux::IOpenGLBaseTexture> texture; |
862 | + |
863 | + nux::Geometry base = GetGeometry (); |
864 | + |
865 | + gfxContext.PushClippingRectangle (base); |
866 | + |
867 | + nux::TexCoordXForm texxform; |
868 | + texxform.SetWrap (nux::TEXWRAP_REPEAT, nux::TEXWRAP_REPEAT); |
869 | + texxform.SetTexCoordType (nux::TexCoordXForm::OFFSET_COORD); |
870 | + |
871 | + gfxContext.GetRenderStates().SetBlend (true, |
872 | + GL_ONE, |
873 | + GL_ONE_MINUS_SRC_ALPHA); |
874 | + |
875 | + if (GetEnabled ()) |
876 | + { |
877 | + if (GetActive () && _prelight) |
878 | + { |
879 | + texture = _prelightTexture[0]->GetDeviceTexture (); |
880 | + } |
881 | + else if (GetActive ()) |
882 | + { |
883 | + texture = _normalTexture[0]->GetDeviceTexture (); |
884 | + } |
885 | + |
886 | + if ((!GetActive ()) && _prelight) |
887 | + { |
888 | + texture = _prelightTexture[1]->GetDeviceTexture (); |
889 | + } |
890 | + else if (!GetActive ()) |
891 | + { |
892 | + texture = _normalTexture[1]->GetDeviceTexture (); |
893 | + } |
894 | + |
895 | + _color = nux::Color::White; |
896 | + } |
897 | + else |
898 | + { |
899 | + if (GetActive ()) |
900 | + { |
901 | + texture = _prelightTexture[0]->GetDeviceTexture (); |
902 | + } |
903 | + else |
904 | + { |
905 | + texture = _normalTexture[0]->GetDeviceTexture (); |
906 | + } |
907 | + |
908 | + _color = nux::Color::DarkGray; |
909 | + } |
910 | + |
911 | + gfxContext.QRP_GLSL_1Tex (base.x, |
912 | + base.y, |
913 | + base.width, |
914 | + base.height, |
915 | + texture, |
916 | + texxform, |
917 | + _color); |
918 | + |
919 | + gfxContext.GetRenderStates().SetBlend (false); |
920 | + |
921 | + gfxContext.PopClippingRectangle (); |
922 | +} |
923 | + |
924 | +void QuicklistMenuItemCheckmark::DrawContent (nux::GraphicsEngine& gfxContext, |
925 | + bool forceDraw) |
926 | +{ |
927 | +} |
928 | + |
929 | +void QuicklistMenuItemCheckmark::PostDraw (nux::GraphicsEngine& gfxContext, |
930 | + bool forceDraw) |
931 | +{ |
932 | +} |
933 | + |
934 | +void |
935 | +QuicklistMenuItemCheckmark::UpdateTexture () |
936 | +{ |
937 | + nux::Color transparent = nux::Color (0.0f, 0.0f, 0.0f, 0.0f); |
938 | + int width = GetBaseWidth (); |
939 | + int height = GetBaseHeight (); |
940 | + |
941 | + _cairoGraphics = new nux::CairoGraphics (CAIRO_FORMAT_ARGB32, width, height); |
942 | + cairo_t *cr = _cairoGraphics->GetContext (); |
943 | + |
944 | + // draw normal, unchecked version |
945 | + cairo_set_operator (cr, CAIRO_OPERATOR_CLEAR); |
946 | + cairo_paint (cr); |
947 | + |
948 | + cairo_set_operator (cr, CAIRO_OPERATOR_SOURCE); |
949 | + cairo_scale (cr, 1.0f, 1.0f); |
950 | + cairo_set_source_rgba (cr, 1.0f, 1.0f, 1.0f, 1.0f); |
951 | + cairo_set_line_width (cr, 1.0f); |
952 | + |
953 | + DrawText (cr, width, height, nux::Color::White); |
954 | + |
955 | + nux::NBitmapData* bitmap = _cairoGraphics->GetBitmap (); |
956 | + |
957 | + if (_normalTexture[0]) |
958 | + _normalTexture[0]->UnReference (); |
959 | + |
960 | + _normalTexture[0] = nux::GetThreadGLDeviceFactory()->CreateSystemCapableTexture (); |
961 | + _normalTexture[0]->Update (bitmap); |
962 | + |
963 | + // draw normal, checked version |
964 | + cairo_set_operator (cr, CAIRO_OPERATOR_CLEAR); |
965 | + cairo_paint (cr); |
966 | + |
967 | + cairo_set_operator (cr, CAIRO_OPERATOR_SOURCE); |
968 | + cairo_scale (cr, 1.0f, 1.0f); |
969 | + cairo_set_source_rgba (cr, 1.0f, 1.0f, 1.0f, 1.0f); |
970 | + cairo_set_line_width (cr, 1.0f); |
971 | + |
972 | + cairo_save (cr); |
973 | + cairo_translate (cr, |
974 | + _align ((ITEM_INDENT_ABS - 16.0f) / 2.0f), |
975 | + _align (((double) height - 16.0f)/ 2.0f)); |
976 | + |
977 | + cairo_set_source_rgba (cr, 1.0f, 1.0f, 1.0f, 1.0f); |
978 | + |
979 | + cairo_translate (cr, 3.0f, 1.0f); |
980 | + cairo_move_to (cr, 0.0f, 6.0f); |
981 | + cairo_line_to (cr, 0.0f, 8.0f); |
982 | + cairo_line_to (cr, 4.0f, 12.0f); |
983 | + cairo_line_to (cr, 6.0f, 12.0f); |
984 | + cairo_line_to (cr, 15.0f, 1.0f); |
985 | + cairo_line_to (cr, 15.0f, 0.0f); |
986 | + cairo_line_to (cr, 14.0f, 0.0f); |
987 | + cairo_line_to (cr, 5.0f, 9.0f); |
988 | + cairo_line_to (cr, 1.0f, 5.0f); |
989 | + cairo_close_path (cr); |
990 | + cairo_fill (cr); |
991 | + |
992 | + cairo_restore (cr); |
993 | + |
994 | + DrawText (cr, width, height, nux::Color::White); |
995 | + |
996 | + bitmap = _cairoGraphics->GetBitmap (); |
997 | + |
998 | + if (_normalTexture[1]) |
999 | + _normalTexture[1]->UnReference (); |
1000 | + |
1001 | + _normalTexture[1] = nux::GetThreadGLDeviceFactory()->CreateSystemCapableTexture (); |
1002 | + _normalTexture[1]->Update (bitmap); |
1003 | + |
1004 | + // draw active/prelight, unchecked version |
1005 | + cairo_set_operator (cr, CAIRO_OPERATOR_CLEAR); |
1006 | + cairo_paint (cr); |
1007 | + |
1008 | + cairo_set_operator (cr, CAIRO_OPERATOR_SOURCE); |
1009 | + cairo_scale (cr, 1.0f, 1.0f); |
1010 | + cairo_set_source_rgba (cr, 1.0f, 1.0f, 1.0f, 1.0f); |
1011 | + cairo_set_line_width (cr, 1.0f); |
1012 | + |
1013 | + DrawRoundedRectangle (cr, |
1014 | + 1.0f, |
1015 | + 0.5f, |
1016 | + 0.5f, |
1017 | + ITEM_CORNER_RADIUS_ABS, |
1018 | + width - 1.0f, |
1019 | + height - 1.0f); |
1020 | + cairo_fill (cr); |
1021 | + |
1022 | + cairo_set_source_rgba (cr, 0.0f, 0.0f, 0.0f, 0.0f); |
1023 | + |
1024 | + DrawText (cr, width, height, transparent); |
1025 | + |
1026 | + bitmap = _cairoGraphics->GetBitmap (); |
1027 | + |
1028 | + if (_prelightTexture[0]) |
1029 | + _prelightTexture[0]->UnReference (); |
1030 | + |
1031 | + _prelightTexture[0] = nux::GetThreadGLDeviceFactory()->CreateSystemCapableTexture (); |
1032 | + _prelightTexture[0]->Update (bitmap); |
1033 | + |
1034 | + // draw active/prelight, unchecked version |
1035 | + cairo_set_operator (cr, CAIRO_OPERATOR_CLEAR); |
1036 | + cairo_paint (cr); |
1037 | + |
1038 | + cairo_set_operator (cr, CAIRO_OPERATOR_SOURCE); |
1039 | + cairo_scale (cr, 1.0f, 1.0f); |
1040 | + cairo_set_source_rgba (cr, 1.0f, 1.0f, 1.0f, 1.0f); |
1041 | + cairo_set_line_width (cr, 1.0f); |
1042 | + |
1043 | + DrawRoundedRectangle (cr, |
1044 | + 1.0f, |
1045 | + 0.5f, |
1046 | + 0.5f, |
1047 | + ITEM_CORNER_RADIUS_ABS, |
1048 | + width - 1.0f, |
1049 | + height - 1.0f); |
1050 | + cairo_fill (cr); |
1051 | + |
1052 | + cairo_set_source_rgba (cr, 0.0f, 0.0f, 0.0f, 0.0f); |
1053 | + |
1054 | + cairo_save (cr); |
1055 | + cairo_translate (cr, |
1056 | + _align ((ITEM_INDENT_ABS - 16.0f) / 2.0f), |
1057 | + _align (((double) height - 16.0f) / 2.0f)); |
1058 | + |
1059 | + cairo_translate (cr, 3.0f, 1.0f); |
1060 | + cairo_move_to (cr, 0.0f, 6.0f); |
1061 | + cairo_line_to (cr, 0.0f, 8.0f); |
1062 | + cairo_line_to (cr, 4.0f, 12.0f); |
1063 | + cairo_line_to (cr, 6.0f, 12.0f); |
1064 | + cairo_line_to (cr, 15.0f, 1.0f); |
1065 | + cairo_line_to (cr, 15.0f, 0.0f); |
1066 | + cairo_line_to (cr, 14.0f, 0.0f); |
1067 | + cairo_line_to (cr, 5.0f, 9.0f); |
1068 | + cairo_line_to (cr, 1.0f, 5.0f); |
1069 | + cairo_close_path (cr); |
1070 | + cairo_fill (cr); |
1071 | + |
1072 | + cairo_restore (cr); |
1073 | + |
1074 | + DrawText (cr, width, height, transparent); |
1075 | + |
1076 | + bitmap = _cairoGraphics->GetBitmap (); |
1077 | + |
1078 | + if (_prelightTexture[1]) |
1079 | + _prelightTexture[1]->UnReference (); |
1080 | + |
1081 | + _prelightTexture[1] = nux::GetThreadGLDeviceFactory()->CreateSystemCapableTexture (); |
1082 | + _prelightTexture[1]->Update (bitmap); |
1083 | + |
1084 | + // finally clean up |
1085 | + delete _cairoGraphics; |
1086 | +} |
1087 | + |
1088 | +int QuicklistMenuItemCheckmark::CairoSurfaceWidth () |
1089 | +{ |
1090 | + if (_normalTexture[0]) |
1091 | + return _normalTexture[0]->GetWidth (); |
1092 | + |
1093 | + return 0; |
1094 | +} |
1095 | |
1096 | === added file 'src/QuicklistMenuItemCheckmark.h' |
1097 | --- src/QuicklistMenuItemCheckmark.h 1970-01-01 00:00:00 +0000 |
1098 | +++ src/QuicklistMenuItemCheckmark.h 2010-11-25 15:47:12 +0000 |
1099 | @@ -0,0 +1,63 @@ |
1100 | +/* |
1101 | + * Copyright (C) 2010 Canonical Ltd |
1102 | + * |
1103 | + * This program is free software: you can redistribute it and/or modify |
1104 | + * it under the terms of the GNU General Public License version 3 as |
1105 | + * published by the Free Software Foundation. |
1106 | + * |
1107 | + * This program is distributed in the hope that it will be useful, |
1108 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
1109 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
1110 | + * GNU General Public License for more details. |
1111 | + * |
1112 | + * You should have received a copy of the GNU General Public License |
1113 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
1114 | + * |
1115 | + * Authored by: Mirco Müller <mirco.mueller@canonical.com> |
1116 | + * Authored by: Jay Taoko <jay.taoko@canonical.com> |
1117 | + */ |
1118 | + |
1119 | +#ifndef QUICKLISTMENUITEMCHECKMARK_H |
1120 | +#define QUICKLISTMENUITEMCHECKMARK_H |
1121 | + |
1122 | +#include "Nux/Nux.h" |
1123 | +#include "Nux/View.h" |
1124 | +#include "NuxImage/CairoGraphics.h" |
1125 | + |
1126 | +#include "QuicklistMenuItem.h" |
1127 | + |
1128 | +#include <X11/Xlib.h> |
1129 | + |
1130 | +class QuicklistMenuItemCheckmark : public QuicklistMenuItem |
1131 | +{ |
1132 | + public: |
1133 | + QuicklistMenuItemCheckmark (DbusmenuMenuitem* item, |
1134 | + NUX_FILE_LINE_PROTO); |
1135 | + |
1136 | + QuicklistMenuItemCheckmark (DbusmenuMenuitem* item, |
1137 | + bool debug, |
1138 | + NUX_FILE_LINE_PROTO); |
1139 | + |
1140 | + ~QuicklistMenuItemCheckmark (); |
1141 | + |
1142 | + protected: |
1143 | + |
1144 | + void PreLayoutManagement (); |
1145 | + |
1146 | + long PostLayoutManagement (long layoutResult); |
1147 | + |
1148 | + long ProcessEvent (nux::IEvent& event, long traverseInfo, long processEventInfo); |
1149 | + |
1150 | + void Draw (nux::GraphicsEngine& gfxContext, bool forceDraw); |
1151 | + |
1152 | + void DrawContent (nux::GraphicsEngine& gfxContext, bool forceDraw); |
1153 | + |
1154 | + void PostDraw (nux::GraphicsEngine& gfxContext, bool forceDraw); |
1155 | + |
1156 | + void Initialize (DbusmenuMenuitem* item); |
1157 | + |
1158 | + virtual void UpdateTexture (); |
1159 | + virtual int CairoSurfaceWidth (); |
1160 | +}; |
1161 | + |
1162 | +#endif // QUICKLISTMENUITEMCHECKMARK_H |
1163 | |
1164 | === added file 'src/QuicklistMenuItemLabel.cpp' |
1165 | --- src/QuicklistMenuItemLabel.cpp 1970-01-01 00:00:00 +0000 |
1166 | +++ src/QuicklistMenuItemLabel.cpp 2010-11-25 15:47:12 +0000 |
1167 | @@ -0,0 +1,258 @@ |
1168 | +/* |
1169 | + * Copyright (C) 2010 Canonical Ltd |
1170 | + * |
1171 | + * This program is free software: you can redistribute it and/or modify |
1172 | + * it under the terms of the GNU General Public License version 3 as |
1173 | + * published by the Free Software Foundation. |
1174 | + * |
1175 | + * This program is distributed in the hope that it will be useful, |
1176 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
1177 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
1178 | + * GNU General Public License for more details. |
1179 | + * |
1180 | + * You should have received a copy of the GNU General Public License |
1181 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
1182 | + * |
1183 | + * Authored by: Mirco Müller <mirco.mueller@canonical.com> |
1184 | + * Authored by: Jay Taoko <jay.taoko@canonical.com> |
1185 | + */ |
1186 | + |
1187 | +#include <gdk/gdk.h> |
1188 | +#include <gtk/gtk.h> |
1189 | + |
1190 | +#include "Nux/Nux.h" |
1191 | +#include "QuicklistMenuItemLabel.h" |
1192 | + |
1193 | +#define ITEM_INDENT_ABS 20 |
1194 | +#define ITEM_CORNER_RADIUS_ABS 4 |
1195 | + |
1196 | +QuicklistMenuItemLabel::QuicklistMenuItemLabel (DbusmenuMenuitem* item, |
1197 | + NUX_FILE_LINE_DECL) : |
1198 | +QuicklistMenuItem (item, |
1199 | + NUX_FILE_LINE_PARAM) |
1200 | +{ |
1201 | + Initialize (item); |
1202 | +} |
1203 | + |
1204 | +QuicklistMenuItemLabel::QuicklistMenuItemLabel (DbusmenuMenuitem* item, |
1205 | + bool debug, |
1206 | + NUX_FILE_LINE_DECL) : |
1207 | +QuicklistMenuItem (item, |
1208 | + debug, |
1209 | + NUX_FILE_LINE_PARAM) |
1210 | +{ |
1211 | + Initialize (item); |
1212 | +} |
1213 | + |
1214 | +void |
1215 | +QuicklistMenuItemLabel::Initialize (DbusmenuMenuitem* item) |
1216 | +{ |
1217 | + _item_type = MENUITEM_TYPE_LABEL; |
1218 | + |
1219 | + if (item) |
1220 | + _text = g_strdup (dbusmenu_menuitem_property_get (item, DBUSMENU_MENUITEM_PROP_LABEL)); |
1221 | + else |
1222 | + _text = g_strdup ("Label"); |
1223 | + |
1224 | + int textWidth = 1; |
1225 | + int textHeight = 1; |
1226 | + GetTextExtents (textWidth, textHeight); |
1227 | + SetMinimumSize (textWidth + ITEM_INDENT_ABS, textHeight); |
1228 | +} |
1229 | + |
1230 | +QuicklistMenuItemLabel::~QuicklistMenuItemLabel () |
1231 | +{ |
1232 | + if (_normalTexture[0]) |
1233 | + _normalTexture[0]->UnReference (); |
1234 | + |
1235 | + if (_normalTexture[1]) |
1236 | + _normalTexture[1]->UnReference (); |
1237 | + |
1238 | + if (_prelightTexture[0]) |
1239 | + _prelightTexture[0]->UnReference (); |
1240 | + |
1241 | + if (_prelightTexture[1]) |
1242 | + _prelightTexture[1]->UnReference (); |
1243 | +} |
1244 | + |
1245 | +void |
1246 | +QuicklistMenuItemLabel::PreLayoutManagement () |
1247 | +{ |
1248 | + _pre_layout_width = GetBaseWidth (); |
1249 | + _pre_layout_height = GetBaseHeight (); |
1250 | + |
1251 | + if (_normalTexture[0] == 0) |
1252 | + { |
1253 | + UpdateTexture (); |
1254 | + } |
1255 | + |
1256 | + QuicklistMenuItem::PreLayoutManagement (); |
1257 | +} |
1258 | + |
1259 | +long |
1260 | +QuicklistMenuItemLabel::PostLayoutManagement (long layoutResult) |
1261 | +{ |
1262 | + int w = GetBaseWidth(); |
1263 | + int h = GetBaseHeight(); |
1264 | + |
1265 | + long result = 0; |
1266 | + |
1267 | + if (_pre_layout_width < w) |
1268 | + result |= nux::eLargerWidth; |
1269 | + else if (_pre_layout_width > w) |
1270 | + result |= nux::eSmallerWidth; |
1271 | + else |
1272 | + result |= nux::eCompliantWidth; |
1273 | + |
1274 | + if (_pre_layout_height < h) |
1275 | + result |= nux::eLargerHeight; |
1276 | + else if (_pre_layout_height > h) |
1277 | + result |= nux::eSmallerHeight; |
1278 | + else |
1279 | + result |= nux::eCompliantHeight; |
1280 | + |
1281 | + return result; |
1282 | +} |
1283 | + |
1284 | +long |
1285 | +QuicklistMenuItemLabel::ProcessEvent (nux::IEvent& event, |
1286 | + long traverseInfo, |
1287 | + long processEventInfo) |
1288 | +{ |
1289 | + long result = traverseInfo; |
1290 | + |
1291 | + result = nux::View::PostProcessEvent2 (event, result, processEventInfo); |
1292 | + return result; |
1293 | +} |
1294 | + |
1295 | +void |
1296 | +QuicklistMenuItemLabel::Draw (nux::GraphicsEngine& gfxContext, |
1297 | + bool forceDraw) |
1298 | +{ |
1299 | + nux::IntrusiveSP<nux::IOpenGLBaseTexture> texture; |
1300 | + |
1301 | + nux::Geometry base = GetGeometry (); |
1302 | + |
1303 | + gfxContext.PushClippingRectangle (base); |
1304 | + |
1305 | + nux::TexCoordXForm texxform; |
1306 | + texxform.SetWrap (nux::TEXWRAP_REPEAT, nux::TEXWRAP_REPEAT); |
1307 | + texxform.SetTexCoordType (nux::TexCoordXForm::OFFSET_COORD); |
1308 | + |
1309 | + gfxContext.GetRenderStates().SetBlend (true, |
1310 | + GL_ONE, |
1311 | + GL_ONE_MINUS_SRC_ALPHA); |
1312 | + |
1313 | + if (GetEnabled ()) |
1314 | + { |
1315 | + if (_prelight) |
1316 | + { |
1317 | + texture = _prelightTexture[0]->GetDeviceTexture (); |
1318 | + } |
1319 | + else |
1320 | + { |
1321 | + texture = _normalTexture[0]->GetDeviceTexture (); |
1322 | + } |
1323 | + _color = nux::Color::White; |
1324 | + } |
1325 | + else |
1326 | + { |
1327 | + texture = _normalTexture[0]->GetDeviceTexture (); |
1328 | + _color = nux::Color::DarkGray; |
1329 | + } |
1330 | + |
1331 | + gfxContext.QRP_GLSL_1Tex (base.x, |
1332 | + base.y, |
1333 | + base.width, |
1334 | + base.height, |
1335 | + texture, |
1336 | + texxform, |
1337 | + _color); |
1338 | + |
1339 | + gfxContext.GetRenderStates().SetBlend (false); |
1340 | + |
1341 | + gfxContext.PopClippingRectangle (); |
1342 | +} |
1343 | + |
1344 | +void |
1345 | +QuicklistMenuItemLabel::DrawContent (nux::GraphicsEngine& gfxContext, |
1346 | + bool forceDraw) |
1347 | +{ |
1348 | +} |
1349 | + |
1350 | +void |
1351 | +QuicklistMenuItemLabel::PostDraw (nux::GraphicsEngine& gfxContext, |
1352 | + bool forceDraw) |
1353 | +{ |
1354 | +} |
1355 | + |
1356 | +void |
1357 | +QuicklistMenuItemLabel::UpdateTexture () |
1358 | +{ |
1359 | + nux::Color transparent = nux::Color (0.0f, 0.0f, 0.0f, 0.0f); |
1360 | + int width = GetBaseWidth (); |
1361 | + int height = GetBaseHeight (); |
1362 | + |
1363 | + _cairoGraphics = new nux::CairoGraphics (CAIRO_FORMAT_ARGB32, width, height); |
1364 | + cairo_t *cr = _cairoGraphics->GetContext (); |
1365 | + |
1366 | + // draw normal, unchecked version |
1367 | + cairo_set_operator (cr, CAIRO_OPERATOR_CLEAR); |
1368 | + cairo_paint (cr); |
1369 | + |
1370 | + cairo_set_operator (cr, CAIRO_OPERATOR_SOURCE); |
1371 | + cairo_scale (cr, 1.0f, 1.0f); |
1372 | + cairo_set_source_rgba (cr, 1.0f, 1.0f, 1.0f, 1.0f); |
1373 | + cairo_set_line_width (cr, 1.0f); |
1374 | + |
1375 | + DrawText (cr, width, height, nux::Color::White); |
1376 | + |
1377 | + nux::NBitmapData* bitmap = _cairoGraphics->GetBitmap (); |
1378 | + |
1379 | + if (_normalTexture[0]) |
1380 | + _normalTexture[0]->UnReference (); |
1381 | + |
1382 | + _normalTexture[0] = nux::GetThreadGLDeviceFactory()->CreateSystemCapableTexture (); |
1383 | + _normalTexture[0]->Update (bitmap); |
1384 | + |
1385 | + // draw active/prelight, unchecked version |
1386 | + cairo_set_operator (cr, CAIRO_OPERATOR_CLEAR); |
1387 | + cairo_paint (cr); |
1388 | + |
1389 | + cairo_set_operator (cr, CAIRO_OPERATOR_SOURCE); |
1390 | + cairo_scale (cr, 1.0f, 1.0f); |
1391 | + cairo_set_source_rgba (cr, 1.0f, 1.0f, 1.0f, 1.0f); |
1392 | + cairo_set_line_width (cr, 1.0f); |
1393 | + |
1394 | + DrawRoundedRectangle (cr, |
1395 | + 1.0f, |
1396 | + 0.5f, |
1397 | + 0.5f, |
1398 | + ITEM_CORNER_RADIUS_ABS, |
1399 | + width - 1.0f, |
1400 | + height - 1.0f); |
1401 | + cairo_fill (cr); |
1402 | + |
1403 | + cairo_set_source_rgba (cr, 0.0f, 0.0f, 0.0f, 0.0f); |
1404 | + |
1405 | + DrawText (cr, width, height, transparent); |
1406 | + |
1407 | + bitmap = _cairoGraphics->GetBitmap (); |
1408 | + |
1409 | + if (_prelightTexture[0]) |
1410 | + _prelightTexture[0]->UnReference (); |
1411 | + |
1412 | + _prelightTexture[0] = nux::GetThreadGLDeviceFactory()->CreateSystemCapableTexture (); |
1413 | + _prelightTexture[0]->Update (bitmap); |
1414 | + |
1415 | + // finally clean up |
1416 | + delete _cairoGraphics; |
1417 | +} |
1418 | + |
1419 | +int QuicklistMenuItemLabel::CairoSurfaceWidth () |
1420 | +{ |
1421 | + if (_normalTexture[0]) |
1422 | + return _normalTexture[0]->GetWidth (); |
1423 | + |
1424 | + return 0; |
1425 | +} |
1426 | |
1427 | === added file 'src/QuicklistMenuItemLabel.h' |
1428 | --- src/QuicklistMenuItemLabel.h 1970-01-01 00:00:00 +0000 |
1429 | +++ src/QuicklistMenuItemLabel.h 2010-11-25 15:47:12 +0000 |
1430 | @@ -0,0 +1,63 @@ |
1431 | +/* |
1432 | + * Copyright (C) 2010 Canonical Ltd |
1433 | + * |
1434 | + * This program is free software: you can redistribute it and/or modify |
1435 | + * it under the terms of the GNU General Public License version 3 as |
1436 | + * published by the Free Software Foundation. |
1437 | + * |
1438 | + * This program is distributed in the hope that it will be useful, |
1439 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
1440 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
1441 | + * GNU General Public License for more details. |
1442 | + * |
1443 | + * You should have received a copy of the GNU General Public License |
1444 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
1445 | + * |
1446 | + * Authored by: Mirco Müller <mirco.mueller@canonical.com> |
1447 | + * Authored by: Jay Taoko <jay.taoko@canonical.com> |
1448 | + */ |
1449 | + |
1450 | +#ifndef QUICKLISTMENUITEMLABEL_H |
1451 | +#define QUICKLISTMENUITEMLABEL_H |
1452 | + |
1453 | +#include "Nux/Nux.h" |
1454 | +#include "Nux/View.h" |
1455 | +#include "NuxImage/CairoGraphics.h" |
1456 | + |
1457 | +#include "QuicklistMenuItem.h" |
1458 | + |
1459 | +#include <X11/Xlib.h> |
1460 | + |
1461 | +class QuicklistMenuItemLabel : public QuicklistMenuItem |
1462 | +{ |
1463 | + public: |
1464 | + QuicklistMenuItemLabel (DbusmenuMenuitem* item, |
1465 | + NUX_FILE_LINE_PROTO); |
1466 | + |
1467 | + QuicklistMenuItemLabel (DbusmenuMenuitem* item, |
1468 | + bool debug, |
1469 | + NUX_FILE_LINE_PROTO); |
1470 | + |
1471 | + ~QuicklistMenuItemLabel (); |
1472 | + |
1473 | + protected: |
1474 | + |
1475 | + void PreLayoutManagement (); |
1476 | + |
1477 | + long PostLayoutManagement (long layoutResult); |
1478 | + |
1479 | + long ProcessEvent (nux::IEvent& event, long traverseInfo, long processEventInfo); |
1480 | + |
1481 | + void Draw (nux::GraphicsEngine& gfxContext, bool forceDraw); |
1482 | + |
1483 | + void DrawContent (nux::GraphicsEngine& gfxContext, bool forceDraw); |
1484 | + |
1485 | + void PostDraw (nux::GraphicsEngine& gfxContext, bool forceDraw); |
1486 | + |
1487 | + void Initialize (DbusmenuMenuitem* item); |
1488 | + |
1489 | + virtual void UpdateTexture (); |
1490 | + virtual int CairoSurfaceWidth (); |
1491 | +}; |
1492 | + |
1493 | +#endif // QUICKLISTMENUITEMLABEL_H |
1494 | |
1495 | === added file 'src/QuicklistMenuItemRadio.cpp' |
1496 | --- src/QuicklistMenuItemRadio.cpp 1970-01-01 00:00:00 +0000 |
1497 | +++ src/QuicklistMenuItemRadio.cpp 2010-11-25 15:47:12 +0000 |
1498 | @@ -0,0 +1,315 @@ |
1499 | +/* |
1500 | + * Copyright (C) 2010 Canonical Ltd |
1501 | + * |
1502 | + * This program is free software: you can redistribute it and/or modify |
1503 | + * it under the terms of the GNU General Public License version 3 as |
1504 | + * published by the Free Software Foundation. |
1505 | + * |
1506 | + * This program is distributed in the hope that it will be useful, |
1507 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
1508 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
1509 | + * GNU General Public License for more details. |
1510 | + * |
1511 | + * You should have received a copy of the GNU General Public License |
1512 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
1513 | + * |
1514 | + * Authored by: Mirco Müller <mirco.mueller@canonical.com> |
1515 | + */ |
1516 | + |
1517 | +#include <gdk/gdk.h> |
1518 | +#include <gtk/gtk.h> |
1519 | + |
1520 | +#include "Nux/Nux.h" |
1521 | +#include "QuicklistMenuItemRadio.h" |
1522 | + |
1523 | +#define ITEM_INDENT_ABS 20.0f |
1524 | +#define ITEM_CORNER_RADIUS_ABS 4.0f |
1525 | + |
1526 | +static double |
1527 | +_align (double val) |
1528 | +{ |
1529 | + double fract = val - (int) val; |
1530 | + |
1531 | + if (fract != 0.5f) |
1532 | + return (double) ((int) val + 0.5f); |
1533 | + else |
1534 | + return val; |
1535 | +} |
1536 | + |
1537 | +QuicklistMenuItemRadio::QuicklistMenuItemRadio (DbusmenuMenuitem* item, |
1538 | + NUX_FILE_LINE_DECL) : |
1539 | +QuicklistMenuItem (item, |
1540 | + NUX_FILE_LINE_PARAM) |
1541 | +{ |
1542 | + Initialize (item); |
1543 | +} |
1544 | + |
1545 | +QuicklistMenuItemRadio::QuicklistMenuItemRadio (DbusmenuMenuitem* item, |
1546 | + bool debug, |
1547 | + NUX_FILE_LINE_DECL) : |
1548 | +QuicklistMenuItem (item, |
1549 | + debug, |
1550 | + NUX_FILE_LINE_PARAM) |
1551 | +{ |
1552 | + Initialize (item); |
1553 | +} |
1554 | + |
1555 | +void |
1556 | +QuicklistMenuItemRadio::Initialize (DbusmenuMenuitem* item) |
1557 | +{ |
1558 | + _item_type = MENUITEM_TYPE_LABEL; |
1559 | + |
1560 | + if (item) |
1561 | + _text = dbusmenu_menuitem_property_get (item, DBUSMENU_MENUITEM_PROP_LABEL); |
1562 | + else |
1563 | + _text = "QuicklistItem"; |
1564 | + |
1565 | + _normalTexture[0] = NULL; |
1566 | + _normalTexture[1] = NULL; |
1567 | + _prelightTexture[0] = NULL; |
1568 | + _prelightTexture[1] = NULL; |
1569 | + |
1570 | + SetMinimumSize (1, 1); |
1571 | + // make sure _dpiX and _dpiY are initialized correctly |
1572 | +} |
1573 | + |
1574 | +QuicklistMenuItemRadio::~QuicklistMenuItemRadio () |
1575 | +{ |
1576 | + if (_normalTexture[0]) |
1577 | + _normalTexture[0]->UnReference (); |
1578 | + |
1579 | + if (_normalTexture[1]) |
1580 | + _normalTexture[1]->UnReference (); |
1581 | + |
1582 | + if (_prelightTexture[0]) |
1583 | + _prelightTexture[0]->UnReference (); |
1584 | + |
1585 | + if (_prelightTexture[1]) |
1586 | + _prelightTexture[1]->UnReference (); |
1587 | +} |
1588 | + |
1589 | +void |
1590 | +QuicklistMenuItemRadio::PreLayoutManagement () |
1591 | +{ |
1592 | +} |
1593 | + |
1594 | +long |
1595 | +QuicklistMenuItemRadio::PostLayoutManagement (long layoutResult) |
1596 | +{ |
1597 | + int w = GetBaseWidth(); |
1598 | + int h = GetBaseHeight(); |
1599 | + |
1600 | + long result = 0; |
1601 | + |
1602 | + if (_pre_layout_width < w) |
1603 | + result |= nux::eLargerWidth; |
1604 | + else if (_pre_layout_width > w) |
1605 | + result |= nux::eSmallerWidth; |
1606 | + else |
1607 | + result |= nux::eCompliantWidth; |
1608 | + |
1609 | + if (_pre_layout_height < h) |
1610 | + result |= nux::eLargerHeight; |
1611 | + else if (_pre_layout_height > h) |
1612 | + result |= nux::eSmallerHeight; |
1613 | + else |
1614 | + result |= nux::eCompliantHeight; |
1615 | + |
1616 | + return result; |
1617 | +} |
1618 | + |
1619 | +long |
1620 | +QuicklistMenuItemRadio::ProcessEvent (nux::IEvent& event, |
1621 | + long traverseInfo, |
1622 | + long processEventInfo) |
1623 | +{ |
1624 | + long result = traverseInfo; |
1625 | + |
1626 | + result = nux::View::PostProcessEvent2 (event, result, processEventInfo); |
1627 | + return result; |
1628 | +} |
1629 | + |
1630 | +void |
1631 | +QuicklistMenuItemRadio::Draw (nux::GraphicsEngine& gfxContext, |
1632 | + bool forceDraw) |
1633 | +{ |
1634 | + nux::IntrusiveSP<nux::IOpenGLBaseTexture> texture; |
1635 | + |
1636 | + nux::Geometry base = GetGeometry (); |
1637 | + |
1638 | + gfxContext.PushClippingRectangle (base); |
1639 | + |
1640 | + nux::TexCoordXForm texxform; |
1641 | + texxform.SetWrap (nux::TEXWRAP_REPEAT, nux::TEXWRAP_REPEAT); |
1642 | + texxform.SetTexCoordType (nux::TexCoordXForm::OFFSET_COORD); |
1643 | + |
1644 | + gfxContext.GetRenderStates().SetBlend (true, |
1645 | + GL_ONE, |
1646 | + GL_ONE_MINUS_SRC_ALPHA); |
1647 | + |
1648 | + if (GetActive ()) |
1649 | + if (GetEnabled ()) |
1650 | + texture = _prelightTexture[1]->GetDeviceTexture (); |
1651 | + else |
1652 | + texture = _prelightTexture[0]->GetDeviceTexture (); |
1653 | + else |
1654 | + if (GetEnabled ()) |
1655 | + texture = _normalTexture[1]->GetDeviceTexture (); |
1656 | + else |
1657 | + texture = _normalTexture[0]->GetDeviceTexture (); |
1658 | + |
1659 | + gfxContext.QRP_GLSL_1Tex (base.x, |
1660 | + base.y, |
1661 | + base.width, |
1662 | + base.height, |
1663 | + texture, |
1664 | + texxform, |
1665 | + _color); |
1666 | + |
1667 | + gfxContext.GetRenderStates().SetBlend (false); |
1668 | + |
1669 | + gfxContext.PopClippingRectangle (); |
1670 | +} |
1671 | + |
1672 | +void |
1673 | +QuicklistMenuItemRadio::DrawContent (nux::GraphicsEngine& gfxContext, |
1674 | + bool forceDraw) |
1675 | +{ |
1676 | +} |
1677 | + |
1678 | +void |
1679 | +QuicklistMenuItemRadio::PostDraw (nux::GraphicsEngine& gfxContext, |
1680 | + bool forceDraw) |
1681 | +{ |
1682 | +} |
1683 | + |
1684 | +void |
1685 | +QuicklistMenuItemRadio::UpdateTexture () |
1686 | +{ |
1687 | + int width = GetBaseWidth (); |
1688 | + int height = GetBaseHeight (); |
1689 | + |
1690 | + _cairoGraphics = new nux::CairoGraphics (CAIRO_FORMAT_ARGB32, width, height); |
1691 | + cairo_t *cr = _cairoGraphics->GetContext (); |
1692 | + |
1693 | + // draw normal, disabled version |
1694 | + cairo_set_operator (cr, CAIRO_OPERATOR_CLEAR); |
1695 | + cairo_paint (cr); |
1696 | + |
1697 | + cairo_set_operator (cr, CAIRO_OPERATOR_SOURCE); |
1698 | + cairo_scale (cr, 1.0f, 1.0f); |
1699 | + cairo_set_source_rgba (cr, 1.0f, 1.0f, 1.0f, 1.0f); |
1700 | + cairo_set_line_width (cr, 1.0f); |
1701 | + |
1702 | + DrawText (cr, width, height, _textColor); |
1703 | + |
1704 | + nux::NBitmapData* bitmap = _cairoGraphics->GetBitmap (); |
1705 | + |
1706 | + if (_normalTexture[0]) |
1707 | + _normalTexture[0]->UnReference (); |
1708 | + |
1709 | + _normalTexture[0] = nux::GetThreadGLDeviceFactory()->CreateSystemCapableTexture (); |
1710 | + _normalTexture[0]->Update (bitmap); |
1711 | + |
1712 | + // draw normal, enabled version |
1713 | + cairo_set_operator (cr, CAIRO_OPERATOR_CLEAR); |
1714 | + cairo_paint (cr); |
1715 | + |
1716 | + cairo_set_operator (cr, CAIRO_OPERATOR_SOURCE); |
1717 | + cairo_scale (cr, 1.0f, 1.0f); |
1718 | + cairo_set_source_rgba (cr, 1.0f, 1.0f, 1.0f, 1.0f); |
1719 | + cairo_set_line_width (cr, 1.0f); |
1720 | + |
1721 | + double x = _align (ITEM_INDENT_ABS / 2.0f); |
1722 | + double y = _align ((double) height / 2.0f); |
1723 | + double radius = 3.5f; |
1724 | + |
1725 | + cairo_set_source_rgba (cr, 1.0f, 1.0f, 1.0f, 1.0f); |
1726 | + cairo_arc (cr, x, y, radius, 0.0f * (G_PI / 180.0f), 360.0f * (G_PI / 180.0f)); |
1727 | + cairo_fill (cr); |
1728 | + |
1729 | + cairo_set_source_rgba (cr, 1.0f, 1.0f, 1.0f, 1.0f); |
1730 | + DrawText (cr, width, height, _textColor); |
1731 | + |
1732 | + bitmap = _cairoGraphics->GetBitmap (); |
1733 | + |
1734 | + if (_normalTexture[1]) |
1735 | + _normalTexture[1]->UnReference (); |
1736 | + |
1737 | + _normalTexture[1] = nux::GetThreadGLDeviceFactory()->CreateSystemCapableTexture (); |
1738 | + _normalTexture[1]->Update (bitmap); |
1739 | + |
1740 | + // draw active/prelight, unchecked version |
1741 | + cairo_set_operator (cr, CAIRO_OPERATOR_CLEAR); |
1742 | + cairo_paint (cr); |
1743 | + |
1744 | + cairo_set_operator (cr, CAIRO_OPERATOR_SOURCE); |
1745 | + cairo_scale (cr, 1.0f, 1.0f); |
1746 | + cairo_set_source_rgba (cr, 1.0f, 1.0f, 1.0f, 1.0f); |
1747 | + cairo_set_line_width (cr, 1.0f); |
1748 | + |
1749 | + DrawRoundedRectangle (cr, |
1750 | + 1.0f, |
1751 | + 0.5f, |
1752 | + 0.5f, |
1753 | + ITEM_CORNER_RADIUS_ABS, |
1754 | + width - 1.0f, |
1755 | + height - 1.0f); |
1756 | + cairo_fill (cr); |
1757 | + |
1758 | + cairo_set_source_rgba (cr, 0.0f, 0.0f, 0.0f, 0.0f); |
1759 | + |
1760 | + DrawText (cr, width, height, _textColor); |
1761 | + |
1762 | + bitmap = _cairoGraphics->GetBitmap (); |
1763 | + |
1764 | + if (_prelightTexture[0]) |
1765 | + _prelightTexture[0]->UnReference (); |
1766 | + |
1767 | + _prelightTexture[0] = nux::GetThreadGLDeviceFactory()->CreateSystemCapableTexture (); |
1768 | + _prelightTexture[0]->Update (bitmap); |
1769 | + |
1770 | + // draw active/prelight, unchecked version |
1771 | + cairo_set_operator (cr, CAIRO_OPERATOR_CLEAR); |
1772 | + cairo_paint (cr); |
1773 | + |
1774 | + cairo_set_operator (cr, CAIRO_OPERATOR_SOURCE); |
1775 | + cairo_scale (cr, 1.0f, 1.0f); |
1776 | + cairo_set_source_rgba (cr, 1.0f, 1.0f, 1.0f, 1.0f); |
1777 | + cairo_set_line_width (cr, 1.0f); |
1778 | + |
1779 | + DrawRoundedRectangle (cr, |
1780 | + 1.0f, |
1781 | + 0.5f, |
1782 | + 0.5f, |
1783 | + ITEM_CORNER_RADIUS_ABS, |
1784 | + width - 1.0f, |
1785 | + height - 1.0f); |
1786 | + cairo_fill (cr); |
1787 | + |
1788 | + cairo_set_source_rgba (cr, 0.0f, 0.0f, 0.0f, 0.0f); |
1789 | + |
1790 | + cairo_arc (cr, x, y, radius, 0.0f * (G_PI / 180.0f), 360.0f * (G_PI / 180.0f)); |
1791 | + cairo_fill (cr); |
1792 | + |
1793 | + DrawText (cr, width, height, _textColor); |
1794 | + |
1795 | + bitmap = _cairoGraphics->GetBitmap (); |
1796 | + |
1797 | + if (_prelightTexture[1]) |
1798 | + _prelightTexture[1]->UnReference (); |
1799 | + |
1800 | + _prelightTexture[1] = nux::GetThreadGLDeviceFactory()->CreateSystemCapableTexture (); |
1801 | + _prelightTexture[1]->Update (bitmap); |
1802 | + |
1803 | + // finally clean up |
1804 | + delete _cairoGraphics; |
1805 | +} |
1806 | + |
1807 | +int QuicklistMenuItemRadio::CairoSurfaceWidth () |
1808 | +{ |
1809 | + if (_normalTexture[0]) |
1810 | + return _normalTexture[0]->GetWidth (); |
1811 | + |
1812 | + return 0; |
1813 | +} |
1814 | \ No newline at end of file |
1815 | |
1816 | === added file 'src/QuicklistMenuItemRadio.h' |
1817 | --- src/QuicklistMenuItemRadio.h 1970-01-01 00:00:00 +0000 |
1818 | +++ src/QuicklistMenuItemRadio.h 2010-11-25 15:47:12 +0000 |
1819 | @@ -0,0 +1,75 @@ |
1820 | +/* |
1821 | + * Copyright (C) 2010 Canonical Ltd |
1822 | + * |
1823 | + * This program is free software: you can redistribute it and/or modify |
1824 | + * it under the terms of the GNU General Public License version 3 as |
1825 | + * published by the Free Software Foundation. |
1826 | + * |
1827 | + * This program is distributed in the hope that it will be useful, |
1828 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
1829 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
1830 | + * GNU General Public License for more details. |
1831 | + * |
1832 | + * You should have received a copy of the GNU General Public License |
1833 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
1834 | + * |
1835 | + * Authored by: Mirco Müller <mirco.mueller@canonical.com> |
1836 | + */ |
1837 | + |
1838 | +#ifndef QUICKLISTMENUITEMRADIO_H |
1839 | +#define QUICKLISTMENUITEMRADIO_H |
1840 | + |
1841 | +#include "Nux/Nux.h" |
1842 | +#include "Nux/View.h" |
1843 | +#include "NuxImage/CairoGraphics.h" |
1844 | + |
1845 | +#include "QuicklistMenuItem.h" |
1846 | + |
1847 | +#include <X11/Xlib.h> |
1848 | + |
1849 | +class QuicklistMenuItemRadio : public QuicklistMenuItem |
1850 | +{ |
1851 | + public: |
1852 | + QuicklistMenuItemRadio (DbusmenuMenuitem* item, |
1853 | + NUX_FILE_LINE_PROTO); |
1854 | + |
1855 | + QuicklistMenuItemRadio (DbusmenuMenuitem* item, |
1856 | + bool debug, |
1857 | + NUX_FILE_LINE_PROTO); |
1858 | + |
1859 | + ~QuicklistMenuItemRadio (); |
1860 | + |
1861 | + void PreLayoutManagement (); |
1862 | + |
1863 | + long PostLayoutManagement (long layoutResult); |
1864 | + |
1865 | + long ProcessEvent (nux::IEvent& event, |
1866 | + long traverseInfo, |
1867 | + long processEventInfo); |
1868 | + |
1869 | + void Draw (nux::GraphicsEngine& gfxContext, |
1870 | + bool forceDraw); |
1871 | + |
1872 | + void DrawContent (nux::GraphicsEngine& gfxContext, |
1873 | + bool forceDraw); |
1874 | + |
1875 | + void PostDraw (nux::GraphicsEngine& gfxContext, |
1876 | + bool forceDraw); |
1877 | + |
1878 | + private: |
1879 | + nux::NString _text; |
1880 | + nux::Color _textColor; |
1881 | + int _pre_layout_width; |
1882 | + int _pre_layout_height; |
1883 | + nux::CairoGraphics* _cairoGraphics; |
1884 | + |
1885 | + nux::BaseTexture* _normalTexture[2]; |
1886 | + nux::BaseTexture* _prelightTexture[2]; |
1887 | + |
1888 | + void Initialize (DbusmenuMenuitem* item); |
1889 | + |
1890 | + void UpdateTexture (); |
1891 | + virtual int CairoSurfaceWidth (); |
1892 | +}; |
1893 | + |
1894 | +#endif // QUICKLISTMENUITEMRADIO_H |
1895 | |
1896 | === added file 'src/QuicklistMenuItemSeparator.cpp' |
1897 | --- src/QuicklistMenuItemSeparator.cpp 1970-01-01 00:00:00 +0000 |
1898 | +++ src/QuicklistMenuItemSeparator.cpp 2010-11-25 15:47:12 +0000 |
1899 | @@ -0,0 +1,178 @@ |
1900 | +/* |
1901 | + * Copyright (C) 2010 Canonical Ltd |
1902 | + * |
1903 | + * This program is free software: you can redistribute it and/or modify |
1904 | + * it under the terms of the GNU General Public License version 3 as |
1905 | + * published by the Free Software Foundation. |
1906 | + * |
1907 | + * This program is distributed in the hope that it will be useful, |
1908 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
1909 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
1910 | + * GNU General Public License for more details. |
1911 | + * |
1912 | + * You should have received a copy of the GNU General Public License |
1913 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
1914 | + * |
1915 | + * Authored by: Mirco Müller <mirco.mueller@canonical.com> |
1916 | + */ |
1917 | + |
1918 | +#include "Nux/Nux.h" |
1919 | +#include "QuicklistMenuItemSeparator.h" |
1920 | + |
1921 | +QuicklistMenuItemSeparator::QuicklistMenuItemSeparator (DbusmenuMenuitem* item, |
1922 | + NUX_FILE_LINE_DECL) : |
1923 | +QuicklistMenuItem (item, |
1924 | + NUX_FILE_LINE_PARAM) |
1925 | +{ |
1926 | + SetMinimumHeight (3); |
1927 | + SetBaseSize (64, 3); |
1928 | + _normalTexture = NULL; |
1929 | + _item_type = MENUITEM_TYPE_SEPARATOR; |
1930 | +} |
1931 | + |
1932 | +QuicklistMenuItemSeparator::QuicklistMenuItemSeparator (DbusmenuMenuitem* item, |
1933 | + bool debug, |
1934 | + NUX_FILE_LINE_DECL) : |
1935 | +QuicklistMenuItem (item, |
1936 | + debug, |
1937 | + NUX_FILE_LINE_PARAM) |
1938 | +{ |
1939 | + SetMinimumHeight (3); |
1940 | + SetBaseSize (64, 3); |
1941 | + _normalTexture = NULL; |
1942 | + _item_type = MENUITEM_TYPE_SEPARATOR; |
1943 | +} |
1944 | + |
1945 | +QuicklistMenuItemSeparator::~QuicklistMenuItemSeparator () |
1946 | +{ |
1947 | +} |
1948 | + |
1949 | +void |
1950 | +QuicklistMenuItemSeparator::PreLayoutManagement () |
1951 | +{ |
1952 | + _pre_layout_width = GetBaseWidth (); |
1953 | + _pre_layout_height = GetBaseHeight (); |
1954 | + |
1955 | + if((_normalTexture == 0) ) |
1956 | + { |
1957 | + UpdateTexture (); |
1958 | + } |
1959 | + |
1960 | + QuicklistMenuItem::PreLayoutManagement (); |
1961 | +} |
1962 | + |
1963 | +long |
1964 | +QuicklistMenuItemSeparator::PostLayoutManagement (long layoutResult) |
1965 | +{ |
1966 | + int w = GetBaseWidth(); |
1967 | + int h = GetBaseHeight(); |
1968 | + |
1969 | + long result = 0; |
1970 | + |
1971 | + if (_pre_layout_width < w) |
1972 | + result |= nux::eLargerWidth; |
1973 | + else if (_pre_layout_width > w) |
1974 | + result |= nux::eSmallerWidth; |
1975 | + else |
1976 | + result |= nux::eCompliantWidth; |
1977 | + |
1978 | + if (_pre_layout_height < h) |
1979 | + result |= nux::eLargerHeight; |
1980 | + else if (_pre_layout_height > h) |
1981 | + result |= nux::eSmallerHeight; |
1982 | + else |
1983 | + result |= nux::eCompliantHeight; |
1984 | + |
1985 | + return result; |
1986 | +} |
1987 | + |
1988 | +long |
1989 | +QuicklistMenuItemSeparator::ProcessEvent (nux::IEvent& event, |
1990 | + long traverseInfo, |
1991 | + long processEventInfo) |
1992 | +{ |
1993 | + long result = traverseInfo; |
1994 | + |
1995 | + result = nux::View::PostProcessEvent2 (event, result, processEventInfo); |
1996 | + return result; |
1997 | + |
1998 | +} |
1999 | + |
2000 | +void |
2001 | +QuicklistMenuItemSeparator::Draw (nux::GraphicsEngine& gfxContext, |
2002 | + bool forceDraw) |
2003 | +{ |
2004 | + nux::Geometry base = GetGeometry (); |
2005 | + |
2006 | + gfxContext.PushClippingRectangle (base); |
2007 | + |
2008 | + nux::TexCoordXForm texxform; |
2009 | + texxform.SetWrap (nux::TEXWRAP_REPEAT, nux::TEXWRAP_REPEAT); |
2010 | + texxform.SetTexCoordType (nux::TexCoordXForm::OFFSET_COORD); |
2011 | + |
2012 | + gfxContext.GetRenderStates().SetBlend (true, |
2013 | + GL_ONE, |
2014 | + GL_ONE_MINUS_SRC_ALPHA); |
2015 | + |
2016 | + gfxContext.QRP_GLSL_1Tex (base.x, |
2017 | + base.y, |
2018 | + base.width, |
2019 | + base.height, |
2020 | + _normalTexture->GetDeviceTexture(), |
2021 | + texxform, |
2022 | + _color); |
2023 | + |
2024 | + gfxContext.GetRenderStates().SetBlend (false); |
2025 | + |
2026 | + gfxContext.PopClippingRectangle (); |
2027 | +} |
2028 | + |
2029 | +void |
2030 | +QuicklistMenuItemSeparator::DrawContent (nux::GraphicsEngine& gfxContext, |
2031 | + bool forceDraw) |
2032 | +{ |
2033 | +} |
2034 | + |
2035 | +void |
2036 | +QuicklistMenuItemSeparator::PostDraw (nux::GraphicsEngine& gfxContext, |
2037 | + bool forceDraw) |
2038 | +{ |
2039 | +} |
2040 | + |
2041 | +void |
2042 | +QuicklistMenuItemSeparator::UpdateTexture () |
2043 | +{ |
2044 | + int width = GetBaseWidth (); |
2045 | + |
2046 | + _cairoGraphics = new nux::CairoGraphics (CAIRO_FORMAT_ARGB32, |
2047 | + GetBaseWidth (), |
2048 | + GetBaseHeight ()); |
2049 | + cairo_t *cr = _cairoGraphics->GetContext (); |
2050 | + |
2051 | + cairo_set_operator (cr, CAIRO_OPERATOR_SOURCE); |
2052 | + cairo_set_source_rgba (cr, 0.0f, 0.0f, 0.0f, 0.0f); |
2053 | + cairo_paint (cr); |
2054 | + cairo_set_source_rgba (cr, _color.R (), _color.G (), _color.B (), _color.A ()); |
2055 | + cairo_set_line_width (cr, 1.0f); |
2056 | + cairo_move_to (cr, 0.5f, 1.5f); |
2057 | + cairo_line_to (cr, width - 0.5f, 1.5f); |
2058 | + cairo_stroke (cr); |
2059 | + |
2060 | + nux::NBitmapData* bitmap = _cairoGraphics->GetBitmap (); |
2061 | + |
2062 | + if (_normalTexture) |
2063 | + _normalTexture->UnReference (); |
2064 | + |
2065 | + _normalTexture = nux::GetThreadGLDeviceFactory()->CreateSystemCapableTexture (); |
2066 | + _normalTexture->Update (bitmap); |
2067 | + |
2068 | + delete _cairoGraphics; |
2069 | +} |
2070 | + |
2071 | +int QuicklistMenuItemSeparator::CairoSurfaceWidth () |
2072 | +{ |
2073 | + if (_normalTexture) |
2074 | + return _normalTexture->GetWidth (); |
2075 | + |
2076 | + return 0; |
2077 | +} |
2078 | \ No newline at end of file |
2079 | |
2080 | === added file 'src/QuicklistMenuItemSeparator.h' |
2081 | --- src/QuicklistMenuItemSeparator.h 1970-01-01 00:00:00 +0000 |
2082 | +++ src/QuicklistMenuItemSeparator.h 2010-11-25 15:47:12 +0000 |
2083 | @@ -0,0 +1,65 @@ |
2084 | +/* |
2085 | + * Copyright (C) 2010 Canonical Ltd |
2086 | + * |
2087 | + * This program is free software: you can redistribute it and/or modify |
2088 | + * it under the terms of the GNU General Public License version 3 as |
2089 | + * published by the Free Software Foundation. |
2090 | + * |
2091 | + * This program is distributed in the hope that it will be useful, |
2092 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
2093 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
2094 | + * GNU General Public License for more details. |
2095 | + * |
2096 | + * You should have received a copy of the GNU General Public License |
2097 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
2098 | + * |
2099 | + * Authored by: Mirco Müller <mirco.mueller@canonical.com> |
2100 | + */ |
2101 | + |
2102 | +#ifndef QUICKLISTMENUITEMSEPARATOR_H |
2103 | +#define QUICKLISTMENUITEMSEPARATOR_H |
2104 | + |
2105 | +#include "Nux/Nux.h" |
2106 | +#include "Nux/View.h" |
2107 | +#include "NuxImage/CairoGraphics.h" |
2108 | +#include "QuicklistMenuItem.h" |
2109 | + |
2110 | +#include <X11/Xlib.h> |
2111 | + |
2112 | +class QuicklistMenuItemSeparator : public QuicklistMenuItem |
2113 | +{ |
2114 | + public: |
2115 | + QuicklistMenuItemSeparator (DbusmenuMenuitem* item, |
2116 | + NUX_FILE_LINE_PROTO); |
2117 | + |
2118 | + QuicklistMenuItemSeparator (DbusmenuMenuitem* item, |
2119 | + bool debug, |
2120 | + NUX_FILE_LINE_PROTO); |
2121 | + |
2122 | + ~QuicklistMenuItemSeparator (); |
2123 | + |
2124 | + protected: |
2125 | + |
2126 | + void PreLayoutManagement (); |
2127 | + |
2128 | + long PostLayoutManagement (long layoutResult); |
2129 | + |
2130 | + long ProcessEvent (nux::IEvent& event, long traverseInfo, long processEventInfo); |
2131 | + |
2132 | + void Draw (nux::GraphicsEngine& gfxContext, bool forceDraw); |
2133 | + |
2134 | + void DrawContent (nux::GraphicsEngine& gfxContext, bool forceDraw); |
2135 | + |
2136 | + void PostDraw (nux::GraphicsEngine& gfxContext, bool forceDraw); |
2137 | + |
2138 | + nux::BaseTexture* _normalTexture; |
2139 | + |
2140 | + virtual void UpdateTexture (); |
2141 | + |
2142 | + //! Returns the width of the separator line as defined by the size of the _normalTexture. |
2143 | + virtual int CairoSurfaceWidth (); |
2144 | + |
2145 | + friend class QuicklistView; |
2146 | +}; |
2147 | + |
2148 | +#endif // QUICKLISTMENUITEMSEPARATOR_H |
2149 | |
2150 | === modified file 'src/QuicklistView.cpp' (properties changed: -x to +x) |
2151 | --- src/QuicklistView.cpp 2010-11-18 04:09:12 +0000 |
2152 | +++ src/QuicklistView.cpp 2010-11-25 15:47:12 +0000 |
2153 | @@ -29,7 +29,11 @@ |
2154 | #include "NuxImage/CairoGraphics.h" |
2155 | |
2156 | #include "QuicklistView.h" |
2157 | - |
2158 | +#include "QuicklistMenuItem.h" |
2159 | +#include "QuicklistMenuItemLabel.h" |
2160 | +#include "QuicklistMenuItemSeparator.h" |
2161 | +#include "QuicklistMenuItemCheckmark.h" |
2162 | +#include "QuicklistMenuItemRadio.h" |
2163 | |
2164 | NUX_IMPLEMENT_OBJECT_TYPE (QuicklistView); |
2165 | |
2166 | @@ -50,6 +54,7 @@ |
2167 | _padding = 13; |
2168 | _top_size = 4; |
2169 | |
2170 | + SetGeometry (nux::Geometry (0, 0, 1, 1)); |
2171 | _hlayout = new nux::HLayout (TEXT(""), NUX_TRACKER_LOCATION); |
2172 | _vlayout = new nux::VLayout (TEXT(""), NUX_TRACKER_LOCATION); |
2173 | _item_layout = new nux::VLayout (TEXT(""), NUX_TRACKER_LOCATION); |
2174 | @@ -67,22 +72,12 @@ |
2175 | |
2176 | _vlayout->AddLayout (_default_item_layout, 0); |
2177 | |
2178 | - for (int i = 0; i < 2; i++) |
2179 | - { |
2180 | - nux::StaticCairoText* item_text; |
2181 | - item_text = new nux::StaticCairoText (TEXT ("Default Item"), NUX_TRACKER_LOCATION); |
2182 | - |
2183 | - item_text->sigTextChanged.connect (sigc::mem_fun (this, &QuicklistView::RecvCairoTextChanged)); |
2184 | - item_text->sigTextColorChanged.connect (sigc::mem_fun (this, &QuicklistView::RecvCairoTextColorChanged)); |
2185 | - _default_item_layout->AddView(item_text, 1, nux::eCenter, nux::eFull); |
2186 | - _default_item_list.push_back (item_text); |
2187 | - item_text->Reference(); |
2188 | - } |
2189 | + FillInDefaultItems (); |
2190 | |
2191 | _vlayout->AddLayout (_bottom_space, 0); |
2192 | |
2193 | _hlayout->AddLayout (_left_space, 0); |
2194 | - _hlayout->AddLayout (_vlayout, 1, nux::eCenter, nux::eFull); |
2195 | + _hlayout->AddLayout (_vlayout, 0, nux::eCenter, nux::eFull); |
2196 | _hlayout->AddLayout (_right_space, 0); |
2197 | |
2198 | SetWindowSizeMatchLayout (true); |
2199 | @@ -95,21 +90,81 @@ |
2200 | OnMouseMove.connect (sigc::mem_fun (this, &QuicklistView::RecvMouseMove)); |
2201 | OnMouseDrag.connect (sigc::mem_fun (this, &QuicklistView::RecvMouseDrag)); |
2202 | |
2203 | + _mouse_down = false; |
2204 | } |
2205 | |
2206 | QuicklistView::~QuicklistView () |
2207 | { |
2208 | if (_texture_bg) |
2209 | _texture_bg->UnReference (); |
2210 | - |
2211 | - std::list<nux::StaticCairoText*>::iterator it; |
2212 | + |
2213 | + if (_texture_outline) |
2214 | + _texture_outline->UnReference (); |
2215 | + |
2216 | + if (_texture_mask) |
2217 | + _texture_mask->UnReference (); |
2218 | + |
2219 | + std::list<QuicklistMenuItem*>::iterator it; |
2220 | for (it = _item_list.begin(); it != _item_list.end(); it++) |
2221 | { |
2222 | (*it)->UnReference(); |
2223 | } |
2224 | + |
2225 | + for (it = _default_item_list.begin(); it != _default_item_list.end(); it++) |
2226 | + { |
2227 | + (*it)->UnReference(); |
2228 | + } |
2229 | + |
2230 | + _default_item_list.clear (); |
2231 | _item_list.clear (); |
2232 | } |
2233 | |
2234 | +// This function is for testing. It will go eventually |
2235 | +void QuicklistView::FillInDefaultItems () |
2236 | +{ |
2237 | + QuicklistMenuItemCheckmark* item = 0; |
2238 | + DbusmenuMenuitem* dbus_item = 0; |
2239 | + // Enabled and Active Checkmark |
2240 | + dbus_item = dbusmenu_menuitem_new (); |
2241 | + dbusmenu_menuitem_property_set (dbus_item, DBUSMENU_MENUITEM_PROP_TOGGLE_TYPE, DBUSMENU_MENUITEM_TOGGLE_CHECK); |
2242 | + dbusmenu_menuitem_property_set (dbus_item, DBUSMENU_MENUITEM_PROP_LABEL, "check mark 0"); |
2243 | + dbusmenu_menuitem_property_set_bool (dbus_item, DBUSMENU_MENUITEM_PROP_ENABLED, true); |
2244 | + dbusmenu_menuitem_property_set_int (dbus_item, DBUSMENU_MENUITEM_PROP_TOGGLE_STATE, DBUSMENU_MENUITEM_TOGGLE_STATE_UNCHECKED); |
2245 | + |
2246 | + item = new QuicklistMenuItemCheckmark (dbus_item, NUX_TRACKER_LOCATION); |
2247 | + |
2248 | + item->sigTextChanged.connect (sigc::mem_fun (this, &QuicklistView::RecvCairoTextChanged)); |
2249 | + item->sigColorChanged.connect (sigc::mem_fun (this, &QuicklistView::RecvCairoTextColorChanged)); |
2250 | + item->sigMouseClick.connect (sigc::mem_fun (this, &QuicklistView::RecvItemMouseClick)); |
2251 | + item->sigMouseReleased.connect (sigc::mem_fun (this, &QuicklistView::RecvItemMouseRelease)); |
2252 | + item->sigMouseEnter.connect (sigc::mem_fun (this, &QuicklistView::RecvItemMouseEnter)); |
2253 | + item->sigMouseLeave.connect (sigc::mem_fun (this, &QuicklistView::RecvItemMouseLeave)); |
2254 | + |
2255 | + _default_item_layout->AddView(item, 1, nux::eCenter, nux::eFull); |
2256 | + _default_item_list.push_back (item); |
2257 | + item->Reference(); |
2258 | + |
2259 | + // Disabled and Active Checkmark |
2260 | + dbus_item = dbusmenu_menuitem_new (); |
2261 | + dbusmenu_menuitem_property_set (dbus_item, DBUSMENU_MENUITEM_PROP_TOGGLE_TYPE, DBUSMENU_MENUITEM_TOGGLE_CHECK); |
2262 | + dbusmenu_menuitem_property_set (dbus_item, DBUSMENU_MENUITEM_PROP_LABEL, "check mark disabled"); |
2263 | + dbusmenu_menuitem_property_set_bool (dbus_item, DBUSMENU_MENUITEM_PROP_ENABLED, false); |
2264 | + dbusmenu_menuitem_property_set_int (dbus_item, DBUSMENU_MENUITEM_PROP_TOGGLE_STATE, DBUSMENU_MENUITEM_TOGGLE_STATE_UNCHECKED); |
2265 | + |
2266 | + item = new QuicklistMenuItemCheckmark (dbus_item, NUX_TRACKER_LOCATION); |
2267 | + |
2268 | + item->sigTextChanged.connect (sigc::mem_fun (this, &QuicklistView::RecvCairoTextChanged)); |
2269 | + item->sigColorChanged.connect (sigc::mem_fun (this, &QuicklistView::RecvCairoTextColorChanged)); |
2270 | + item->sigMouseClick.connect (sigc::mem_fun (this, &QuicklistView::RecvItemMouseClick)); |
2271 | + item->sigMouseReleased.connect (sigc::mem_fun (this, &QuicklistView::RecvItemMouseRelease)); |
2272 | + item->sigMouseEnter.connect (sigc::mem_fun (this, &QuicklistView::RecvItemMouseEnter)); |
2273 | + item->sigMouseLeave.connect (sigc::mem_fun (this, &QuicklistView::RecvItemMouseLeave)); |
2274 | + |
2275 | + _default_item_layout->AddView(item, 1, nux::eCenter, nux::eFull); |
2276 | + _default_item_list.push_back (item); |
2277 | + item->Reference(); |
2278 | +} |
2279 | + |
2280 | void QuicklistView::ShowQuicklistWithTipAt (int anchor_tip_x, int anchor_tip_y) |
2281 | { |
2282 | int window_width; |
2283 | @@ -133,13 +188,6 @@ |
2284 | void QuicklistView::ShowWindow (bool b, bool start_modal) |
2285 | { |
2286 | BaseWindow::ShowWindow (b, start_modal); |
2287 | - |
2288 | - // Reset all colors to white |
2289 | - std::list<nux::StaticCairoText*>::iterator it; |
2290 | - for (it = _item_list.begin(); it != _item_list.end(); it++) |
2291 | - { |
2292 | - (*it)->SetTextColor (nux::Color::White); |
2293 | - } |
2294 | } |
2295 | |
2296 | long QuicklistView::ProcessEvent (nux::IEvent& ievent, long TraverseInfo, long ProcessEventInfo) |
2297 | @@ -164,15 +212,50 @@ |
2298 | } |
2299 | |
2300 | // We choose to test the quicklist items ourselves instead of processing them as it is usual in nux. |
2301 | - // This is meantto be easier since the quicklist has a atypical way of working. |
2302 | - // if (m_layout) |
2303 | - // ret = m_layout->ProcessEvent (window_event, ret, ProcEvInfo); |
2304 | + // This is meant to be easier since the quicklist has a atypical way of working. |
2305 | + if (m_layout) |
2306 | + ret = m_layout->ProcessEvent (window_event, ret, ProcEvInfo); |
2307 | |
2308 | + if (ievent.e_event == nux::NUX_MOUSE_PRESSED) |
2309 | + { |
2310 | + if (GetGeometry ().IsPointInside (ievent.e_x, ievent.e_y)) |
2311 | + { |
2312 | + _mouse_down = true; |
2313 | + } |
2314 | + else |
2315 | + { |
2316 | + _mouse_down = false; |
2317 | + if (IsVisible ()) |
2318 | + { |
2319 | + CaptureMouseDownAnyWhereElse (false); |
2320 | + ForceStopFocus (1, 1); |
2321 | + UnGrabPointer (); |
2322 | + EnableInputWindow (false); |
2323 | + ShowWindow (false); |
2324 | + } |
2325 | + return nux::eMouseEventSolved; |
2326 | + } |
2327 | + } |
2328 | + else if ((ievent.e_event == nux::NUX_MOUSE_RELEASED) && _mouse_down) |
2329 | + { |
2330 | + |
2331 | + _mouse_down = false; |
2332 | + if (IsVisible ()) |
2333 | + { |
2334 | + CaptureMouseDownAnyWhereElse (false); |
2335 | + ForceStopFocus (1, 1); |
2336 | + UnGrabPointer (); |
2337 | + EnableInputWindow (false); |
2338 | + ShowWindow (false); |
2339 | + } |
2340 | + return nux::eMouseEventSolved; |
2341 | + } |
2342 | + |
2343 | // PostProcessEvent2 must always have its last parameter set to 0 |
2344 | // because the m_BackgroundArea is the real physical limit of the window. |
2345 | // So the previous test about IsPointInside do not prevail over m_BackgroundArea |
2346 | // testing the event by itself. |
2347 | - ret = PostProcessEvent2 (ievent, ret, 0); |
2348 | + //ret = PostProcessEvent2 (ievent, ret, 0); |
2349 | return ret; |
2350 | } |
2351 | |
2352 | @@ -224,7 +307,7 @@ |
2353 | |
2354 | nux::GetGraphicsEngine().GetRenderStates().SetBlend (false); |
2355 | |
2356 | - std::list<nux::StaticCairoText*>::iterator it; |
2357 | + std::list<QuicklistMenuItem*>::iterator it; |
2358 | for (it = _item_list.begin(); it != _item_list.end(); it++) |
2359 | { |
2360 | (*it)->ProcessDraw(gfxContext, forceDraw); |
2361 | @@ -234,7 +317,6 @@ |
2362 | { |
2363 | (*it)->ProcessDraw(gfxContext, forceDraw); |
2364 | } |
2365 | - |
2366 | |
2367 | gfxContext.PopClippingRectangle (); |
2368 | } |
2369 | @@ -249,7 +331,7 @@ |
2370 | int MaxItemWidth = 0; |
2371 | int TotalItemHeight = 0; |
2372 | |
2373 | - std::list<nux::StaticCairoText*>::iterator it; |
2374 | + std::list<QuicklistMenuItem*>::iterator it; |
2375 | for (it = _item_list.begin(); it != _item_list.end(); it++) |
2376 | { |
2377 | int textWidth = 0; |
2378 | @@ -269,12 +351,20 @@ |
2379 | MaxItemWidth = textWidth; |
2380 | TotalItemHeight += textHeight; |
2381 | } |
2382 | - |
2383 | + |
2384 | if(TotalItemHeight < _anchor_height) |
2385 | { |
2386 | _top_space->SetMinMaxSize(1, (_anchor_height - TotalItemHeight)/2 +1 + _padding + _corner_radius); |
2387 | _bottom_space->SetMinMaxSize(1, (_anchor_height - TotalItemHeight)/2 +1 + _padding + _corner_radius); |
2388 | } |
2389 | + else |
2390 | + { |
2391 | + _top_space->SetMinMaxSize(_padding + _corner_radius, _padding + _corner_radius); |
2392 | + _bottom_space->SetMinMaxSize(_padding + _corner_radius, _padding + _corner_radius); |
2393 | + } |
2394 | + |
2395 | + _item_layout->SetMinimumWidth(MaxItemWidth); |
2396 | + _default_item_layout->SetMinimumWidth(MaxItemWidth); |
2397 | |
2398 | BaseWindow::PreLayoutManagement (); |
2399 | } |
2400 | @@ -282,37 +372,101 @@ |
2401 | long QuicklistView::PostLayoutManagement (long LayoutResult) |
2402 | { |
2403 | long result = BaseWindow::PostLayoutManagement (LayoutResult); |
2404 | + |
2405 | UpdateTexture (); |
2406 | |
2407 | int x = _padding + _anchor_width + _corner_radius; |
2408 | int y = _padding + _corner_radius; |
2409 | |
2410 | - std::list<nux::StaticCairoText*>::iterator it; |
2411 | - for (it = _item_list.begin(); it != _item_list.end(); it++) |
2412 | - { |
2413 | - (*it)->SetBaseX (x); |
2414 | - (*it)->SetBaseY (y); |
2415 | - |
2416 | - y += (*it)->GetBaseHeight (); |
2417 | - } |
2418 | - |
2419 | - for (it = _default_item_list.begin(); it != _default_item_list.end(); it++) |
2420 | - { |
2421 | - (*it)->SetBaseX (x); |
2422 | - (*it)->SetBaseY (y); |
2423 | - |
2424 | - y += (*it)->GetBaseHeight (); |
2425 | - } |
2426 | - |
2427 | + std::list<QuicklistMenuItem*>::iterator it; |
2428 | + for (it = _item_list.begin(); it != _item_list.end(); it++) |
2429 | + { |
2430 | + (*it)->SetBaseX (x); |
2431 | + (*it)->SetBaseY (y); |
2432 | + |
2433 | + y += (*it)->GetBaseHeight (); |
2434 | + } |
2435 | + |
2436 | + for (it = _default_item_list.begin(); it != _default_item_list.end(); it++) |
2437 | + { |
2438 | + (*it)->SetBaseX (x); |
2439 | + (*it)->SetBaseY (y); |
2440 | + |
2441 | + y += (*it)->GetBaseHeight (); |
2442 | + } |
2443 | + |
2444 | + // We must correct the width of line separators. The rendering of the separator can be smaller than the width of the |
2445 | + // quicklist. The reason for that is, the quicklist width is determined by the largest entry it contains. That size is |
2446 | + // only after MaxItemWidth is computed in QuicklistView::PreLayoutManagement. |
2447 | + // The setting of the separator width is done here after the Layout cycle for this widget is over. The width of the separator |
2448 | + // has bee set correctly during the layout cycle, but the cairo rendering still need to be adjusted. |
2449 | + int separator_width = nux::Max<int>(_default_item_layout->GetBaseWidth (), _item_layout->GetBaseWidth ()); |
2450 | + |
2451 | + for (it = _item_list.begin(); it != _item_list.end(); it++) |
2452 | + { |
2453 | + QuicklistMenuItem* item = (QuicklistMenuItem*) (*it); |
2454 | + if (item->CairoSurfaceWidth () != separator_width) |
2455 | + { |
2456 | + // Compute textures of the item. |
2457 | + item->UpdateTexture (); |
2458 | + } |
2459 | + } |
2460 | + |
2461 | + for (it = _default_item_list.begin(); it != _default_item_list.end(); it++) |
2462 | + { |
2463 | + QuicklistMenuItem* item = (QuicklistMenuItem*) (*it); |
2464 | + if (item->CairoSurfaceWidth () != separator_width) |
2465 | + { |
2466 | + // Compute textures of the item. |
2467 | + item->UpdateTexture (); |
2468 | + } |
2469 | + } |
2470 | + |
2471 | return result; |
2472 | } |
2473 | |
2474 | -void QuicklistView::RecvCairoTextChanged (nux::StaticCairoText& cairo_text) |
2475 | +void QuicklistView::RecvCairoTextChanged (QuicklistMenuItem* cairo_text) |
2476 | { |
2477 | _cairo_text_has_changed = true; |
2478 | } |
2479 | |
2480 | -void QuicklistView::RecvCairoTextColorChanged (nux::StaticCairoText& cairo_text) |
2481 | +void QuicklistView::RecvCairoTextColorChanged (QuicklistMenuItem* cairo_text) |
2482 | +{ |
2483 | + NeedRedraw (); |
2484 | +} |
2485 | + |
2486 | +void QuicklistView::RecvItemMouseClick (QuicklistMenuItem* item) |
2487 | +{ |
2488 | + _mouse_down = false; |
2489 | + if (IsVisible ()) |
2490 | + { |
2491 | + CaptureMouseDownAnyWhereElse (false); |
2492 | + ForceStopFocus (1, 1); |
2493 | + UnGrabPointer (); |
2494 | + EnableInputWindow (false); |
2495 | + ShowWindow (false); |
2496 | + } |
2497 | +} |
2498 | + |
2499 | +void QuicklistView::RecvItemMouseRelease (QuicklistMenuItem* item) |
2500 | +{ |
2501 | + _mouse_down = false; |
2502 | + if (IsVisible ()) |
2503 | + { |
2504 | + CaptureMouseDownAnyWhereElse (false); |
2505 | + ForceStopFocus (1, 1); |
2506 | + UnGrabPointer (); |
2507 | + EnableInputWindow (false); |
2508 | + ShowWindow (false); |
2509 | + } |
2510 | +} |
2511 | + |
2512 | +void QuicklistView::RecvItemMouseEnter (QuicklistMenuItem* item) |
2513 | +{ |
2514 | + NeedRedraw (); |
2515 | +} |
2516 | + |
2517 | +void QuicklistView::RecvItemMouseLeave (QuicklistMenuItem* item) |
2518 | { |
2519 | NeedRedraw (); |
2520 | } |
2521 | @@ -348,58 +502,12 @@ |
2522 | |
2523 | void QuicklistView::RecvMouseMove (int x, int y, int dx, int dy, unsigned long button_flags, unsigned long key_flags) |
2524 | { |
2525 | - std::list<nux::StaticCairoText*>::iterator it; |
2526 | - for (it = _item_list.begin(); it != _item_list.end(); it++) |
2527 | - { |
2528 | - if ((*it)->GetGeometry ().IsPointInside (x, y)) |
2529 | - { |
2530 | - (*it)->SetTextColor (nux::Color::DarkGray); |
2531 | - } |
2532 | - else |
2533 | - { |
2534 | - (*it)->SetTextColor (nux::Color::White); |
2535 | - } |
2536 | - } |
2537 | - |
2538 | - for (it = _default_item_list.begin(); it != _default_item_list.end(); it++) |
2539 | - { |
2540 | - if ((*it)->GetGeometry ().IsPointInside (x, y)) |
2541 | - { |
2542 | - (*it)->SetTextColor (nux::Color::DarkGray); |
2543 | - } |
2544 | - else |
2545 | - { |
2546 | - (*it)->SetTextColor (nux::Color::White); |
2547 | - } |
2548 | - } |
2549 | + |
2550 | } |
2551 | |
2552 | void QuicklistView::RecvMouseDrag (int x, int y, int dx, int dy, unsigned long button_flags, unsigned long key_flags) |
2553 | { |
2554 | - std::list<nux::StaticCairoText*>::iterator it; |
2555 | - for (it = _item_list.begin(); it != _item_list.end(); it++) |
2556 | - { |
2557 | - if ((*it)->GetGeometry ().IsPointInside (x, y)) |
2558 | - { |
2559 | - (*it)->SetTextColor (nux::Color::DarkGray); |
2560 | - } |
2561 | - else |
2562 | - { |
2563 | - (*it)->SetTextColor (nux::Color::White); |
2564 | - } |
2565 | - } |
2566 | - |
2567 | - for (it = _default_item_list.begin(); it != _default_item_list.end(); it++) |
2568 | - { |
2569 | - if ((*it)->GetGeometry ().IsPointInside (x, y)) |
2570 | - { |
2571 | - (*it)->SetTextColor (nux::Color::DarkGray); |
2572 | - } |
2573 | - else |
2574 | - { |
2575 | - (*it)->SetTextColor (nux::Color::White); |
2576 | - } |
2577 | - } |
2578 | + |
2579 | } |
2580 | |
2581 | void QuicklistView::RecvMouseDownOutsideOfQuicklist (int x, int y, unsigned long button_flags, unsigned long key_flags) |
2582 | @@ -417,21 +525,29 @@ |
2583 | void QuicklistView::RemoveAllMenuItem () |
2584 | { |
2585 | _item_list.clear (); |
2586 | + _default_item_list.clear (); |
2587 | + |
2588 | _item_layout->Clear (); |
2589 | + _default_item_layout->Clear (); |
2590 | _cairo_text_has_changed = true; |
2591 | nux::GetGraphicsThread ()->AddObjectToRefreshList (this); |
2592 | } |
2593 | |
2594 | -void QuicklistView::AddMenuItem (nux::NString str) |
2595 | +void QuicklistView::AddMenuItem (QuicklistMenuItem* item) |
2596 | { |
2597 | - nux::StaticCairoText* item_text; |
2598 | - item_text = new nux::StaticCairoText (str.GetTCharPtr (), NUX_TRACKER_LOCATION); |
2599 | + if (item == 0) |
2600 | + return; |
2601 | |
2602 | - item_text->sigTextChanged.connect (sigc::mem_fun (this, &QuicklistView::RecvCairoTextChanged)); |
2603 | - item_text->sigTextColorChanged.connect (sigc::mem_fun (this, &QuicklistView::RecvCairoTextColorChanged)); |
2604 | - _item_layout->AddView(item_text, 1, nux::eCenter, nux::eFull); |
2605 | - _item_list.push_back (item_text); |
2606 | - item_text->Reference(); |
2607 | + item->sigTextChanged.connect (sigc::mem_fun (this, &QuicklistView::RecvCairoTextChanged)); |
2608 | + item->sigColorChanged.connect (sigc::mem_fun (this, &QuicklistView::RecvCairoTextColorChanged)); |
2609 | + item->sigMouseClick.connect (sigc::mem_fun (this, &QuicklistView::RecvItemMouseClick)); |
2610 | + item->sigMouseReleased.connect (sigc::mem_fun (this, &QuicklistView::RecvItemMouseRelease)); |
2611 | + item->sigMouseEnter.connect (sigc::mem_fun (this, &QuicklistView::RecvItemMouseEnter)); |
2612 | + item->sigMouseLeave.connect (sigc::mem_fun (this, &QuicklistView::RecvItemMouseLeave)); |
2613 | + |
2614 | + _item_layout->AddView(item, 1, nux::eCenter, nux::eFull); |
2615 | + _item_list.push_back (item); |
2616 | + item->Reference(); |
2617 | |
2618 | _cairo_text_has_changed = true; |
2619 | nux::GetGraphicsThread ()->AddObjectToRefreshList (this); |
2620 | @@ -442,10 +558,54 @@ |
2621 | { |
2622 | |
2623 | } |
2624 | - |
2625 | -///////////////////////////////////////////////////////////////////////////////////////////////// |
2626 | -///////////////////////////////////////////////////////////////////////////////////////////////// |
2627 | -///////////////////////////////////////////////////////////////////////////////////////////////// |
2628 | + |
2629 | +int QuicklistView::GetNumItems () |
2630 | +{ |
2631 | + return _item_list.size () + _default_item_list.size (); |
2632 | +} |
2633 | + |
2634 | +QuicklistMenuItem* QuicklistView::GetNthItems (int index) |
2635 | +{ |
2636 | + if (index < (int)_item_list.size ()) |
2637 | + { |
2638 | + int i = 0; |
2639 | + std::list<QuicklistMenuItem*>::iterator it; |
2640 | + for (i = 0, it = _item_list.begin(); it != _item_list.end(); i++, it++) |
2641 | + { |
2642 | + if (i == index) |
2643 | + return *it; |
2644 | + } |
2645 | + } |
2646 | + |
2647 | + if (index < (int)_item_list.size () + (int)_default_item_list.size ()) |
2648 | + { |
2649 | + int i = 0; |
2650 | + if (_item_list.size () > 0) |
2651 | + i = _item_list.size () -1; |
2652 | + std::list<QuicklistMenuItem*>::iterator it; |
2653 | + for (it = _item_list.begin(); it != _item_list.end(); i++, it++) |
2654 | + { |
2655 | + if (i == index) |
2656 | + return *it; |
2657 | + } |
2658 | + } |
2659 | + |
2660 | + return 0; |
2661 | +} |
2662 | + |
2663 | +QuicklistMenuItemType QuicklistView::GetNthType (int index) |
2664 | +{ |
2665 | + QuicklistMenuItem* item = GetNthItems (index); |
2666 | + if (item) |
2667 | + return item->GetItemType (); |
2668 | + return MENUITEM_TYPE_UNKNOWN; |
2669 | +} |
2670 | + |
2671 | +std::list<QuicklistMenuItem*> QuicklistView::GetChildren () |
2672 | +{ |
2673 | + std::list<QuicklistMenuItem*> l; |
2674 | + return l; |
2675 | +} |
2676 | |
2677 | static inline void ql_blurinner (guchar* pixel, |
2678 | gint *zR, |
2679 | @@ -1152,3 +1312,40 @@ |
2680 | _labelText = text; |
2681 | UpdateTexture (); |
2682 | } |
2683 | + |
2684 | +void QuicklistView::TestMenuItems (DbusmenuMenuitem* root) |
2685 | +{ |
2686 | + RemoveAllMenuItem (); |
2687 | + |
2688 | + if (root == 0) |
2689 | + return; |
2690 | + |
2691 | + GList * child = NULL; |
2692 | + for (child = dbusmenu_menuitem_get_children(root); child != NULL; child = g_list_next(child)) |
2693 | + { |
2694 | + const gchar* type = dbusmenu_menuitem_property_get ((DbusmenuMenuitem*)child->data, DBUSMENU_MENUITEM_PROP_TYPE); |
2695 | + const gchar* toggle_type = dbusmenu_menuitem_property_get ((DbusmenuMenuitem*)child->data, DBUSMENU_MENUITEM_PROP_TOGGLE_TYPE); |
2696 | + |
2697 | + if (g_strcmp0 (type, DBUSMENU_CLIENT_TYPES_SEPARATOR) == 0) |
2698 | + { |
2699 | + QuicklistMenuItemSeparator* item = new QuicklistMenuItemSeparator ((DbusmenuMenuitem*)child->data, NUX_TRACKER_LOCATION); |
2700 | + AddMenuItem (item); |
2701 | + } |
2702 | + else if (g_strcmp0 (toggle_type, DBUSMENU_MENUITEM_TOGGLE_CHECK) == 0) |
2703 | + { |
2704 | + QuicklistMenuItemCheckmark* item = new QuicklistMenuItemCheckmark ((DbusmenuMenuitem*)child->data, NUX_TRACKER_LOCATION); |
2705 | + AddMenuItem (item); |
2706 | + } |
2707 | + else if (g_strcmp0 (toggle_type, DBUSMENU_MENUITEM_TOGGLE_RADIO) == 0) |
2708 | + { |
2709 | + QuicklistMenuItemRadio* item = new QuicklistMenuItemRadio ((DbusmenuMenuitem*)child->data, NUX_TRACKER_LOCATION); |
2710 | + AddMenuItem (item); |
2711 | + } |
2712 | + else //if (g_strcmp0 (type, DBUSMENU_MENUITEM_PROP_LABEL) == 0) |
2713 | + { |
2714 | + QuicklistMenuItemLabel* item = new QuicklistMenuItemLabel ((DbusmenuMenuitem*)child->data, NUX_TRACKER_LOCATION); |
2715 | + AddMenuItem (item); |
2716 | + } |
2717 | + } |
2718 | +} |
2719 | + |
2720 | |
2721 | === modified file 'src/QuicklistView.h' (properties changed: -x to +x) |
2722 | --- src/QuicklistView.h 2010-11-18 03:39:39 +0000 |
2723 | +++ src/QuicklistView.h 2010-11-25 15:47:12 +0000 |
2724 | @@ -25,14 +25,11 @@ |
2725 | #include "NuxGraphics/GraphicsEngine.h" |
2726 | #include "Nux/TextureArea.h" |
2727 | #include "NuxImage/CairoGraphics.h" |
2728 | -#include "StaticCairoText.h" |
2729 | |
2730 | #include <pango/pango.h> |
2731 | #include <pango/pangocairo.h> |
2732 | |
2733 | -#if defined(NUX_OS_LINUX) |
2734 | -#include <X11/Xlib.h> |
2735 | -#endif |
2736 | +#include "QuicklistMenuItem.h" |
2737 | |
2738 | #define ANCHOR_WIDTH 10.0f |
2739 | #define ANCHOR_HEIGHT 18.0f |
2740 | @@ -50,6 +47,8 @@ |
2741 | class VLayout; |
2742 | class HLayout; |
2743 | class SpaceLayout; |
2744 | +class QuicklistMenuItem; |
2745 | +class QuicklistMenuItemLabel; |
2746 | |
2747 | class QuicklistView : public nux::BaseWindow |
2748 | { |
2749 | @@ -72,15 +71,28 @@ |
2750 | void SetText (nux::NString text); |
2751 | |
2752 | void RemoveAllMenuItem (); |
2753 | - void AddMenuItem (nux::NString str); |
2754 | + |
2755 | + void AddMenuItem (QuicklistMenuItem* item); |
2756 | + |
2757 | void RenderQuicklistView (); |
2758 | |
2759 | void ShowQuicklistWithTipAt (int anchor_tip_x, int anchor_tip_y); |
2760 | virtual void ShowWindow (bool b, bool StartModal = false); |
2761 | |
2762 | + int GetNumItems (); |
2763 | + QuicklistMenuItem* GetNthItems (int index); |
2764 | + QuicklistMenuItemType GetNthType (int index); |
2765 | + std::list<QuicklistMenuItem*> GetChildren (); |
2766 | + |
2767 | + void TestMenuItems (DbusmenuMenuitem* root); |
2768 | + |
2769 | private: |
2770 | - void RecvCairoTextChanged (nux::StaticCairoText& cairo_text); |
2771 | - void RecvCairoTextColorChanged (nux::StaticCairoText& cairo_text); |
2772 | + void RecvCairoTextChanged (QuicklistMenuItem* item); |
2773 | + void RecvCairoTextColorChanged (QuicklistMenuItem* item); |
2774 | + void RecvItemMouseClick (QuicklistMenuItem* item); |
2775 | + void RecvItemMouseRelease (QuicklistMenuItem* item); |
2776 | + void RecvItemMouseEnter (QuicklistMenuItem* item); |
2777 | + void RecvItemMouseLeave (QuicklistMenuItem* item); |
2778 | |
2779 | void RecvMouseDown (int x, int y, unsigned long button_flags, unsigned long key_flags); |
2780 | void RecvMouseUp (int x, int y, unsigned long button_flags, unsigned long key_flags); |
2781 | @@ -99,6 +111,9 @@ |
2782 | |
2783 | void NotifyConfigurationChange (int width, int height); |
2784 | |
2785 | + //! A convenience function to fill in the default quicklist with some random items. |
2786 | + void FillInDefaultItems (); |
2787 | + |
2788 | //nux::CairoGraphics* _cairo_graphics; |
2789 | int _anchorX; |
2790 | int _anchorY; |
2791 | @@ -107,9 +122,10 @@ |
2792 | int _dpiY; |
2793 | int _top_size; // size of the segment from point 13 to 14. See figure in ql_compute_full_mask_path. |
2794 | |
2795 | + bool _mouse_down; |
2796 | + |
2797 | cairo_font_options_t* _fontOpts; |
2798 | |
2799 | - nux::StaticCairoText* _tooltip_text; |
2800 | nux::BaseTexture* _texture_bg; |
2801 | nux::BaseTexture* _texture_mask; |
2802 | nux::BaseTexture* _texture_outline; |
2803 | @@ -129,8 +145,8 @@ |
2804 | |
2805 | bool _cairo_text_has_changed; |
2806 | void UpdateTexture (); |
2807 | - std::list<nux::StaticCairoText*> _item_list; |
2808 | - std::list<nux::StaticCairoText*> _default_item_list; |
2809 | + std::list<QuicklistMenuItem*> _item_list; |
2810 | + std::list<QuicklistMenuItem*> _default_item_list; |
2811 | }; |
2812 | |
2813 | #endif // QUICKLISTVIEW_H |
2814 | |
2815 | === modified file 'src/StaticCairoText.cpp' |
2816 | --- src/StaticCairoText.cpp 2010-11-17 04:45:59 +0000 |
2817 | +++ src/StaticCairoText.cpp 2010-11-25 15:47:12 +0000 |
2818 | @@ -17,6 +17,9 @@ |
2819 | * Authored by: Mirco Müller <mirco.mueller@canonical.com |
2820 | */ |
2821 | |
2822 | +#include <gdk/gdk.h> |
2823 | +#include <gtk/gtk.h> |
2824 | + |
2825 | #include "Nux/Nux.h" |
2826 | #include "Nux/Layout.h" |
2827 | #include "Nux/HLayout.h" |
2828 | @@ -27,76 +30,32 @@ |
2829 | namespace nux |
2830 | { |
2831 | StaticCairoText::StaticCairoText (const TCHAR* text, |
2832 | - NUX_FILE_LINE_DECL) : |
2833 | + NUX_FILE_LINE_DECL) : |
2834 | View (NUX_FILE_LINE_PARAM) |
2835 | { |
2836 | -#if defined(NUX_OS_WINDOWS) |
2837 | - _fontName = TEXT ("Arial"); |
2838 | -#elif defined(NUX_OS_LINUX) |
2839 | - _fontName = TEXT ("Ubuntu"); |
2840 | -#endif |
2841 | - _fontSize = 12; |
2842 | - _fontStyle = eNormalStyle; |
2843 | - _fontWeight = eNormalWeight; |
2844 | _textColor = Color(1.0f, 1.0f, 1.0f, 1.0f); |
2845 | _text = TEXT (text); |
2846 | - _fontOpts = cairo_font_options_create (); |
2847 | _texture2D = 0; |
2848 | |
2849 | - // FIXME: hard-coding these for the moment, as we don't have |
2850 | - // gsettings-support in place right now |
2851 | - cairo_font_options_set_antialias (_fontOpts, CAIRO_ANTIALIAS_SUBPIXEL); |
2852 | - cairo_font_options_set_hint_metrics (_fontOpts, CAIRO_HINT_METRICS_ON); |
2853 | - cairo_font_options_set_hint_style (_fontOpts, CAIRO_HINT_STYLE_SLIGHT); |
2854 | - cairo_font_options_set_subpixel_order (_fontOpts, CAIRO_SUBPIXEL_ORDER_RGB); |
2855 | - |
2856 | SetMinimumSize (1, 1); |
2857 | - // make sure _dpiX and _dpiY are initialized correctly |
2858 | - GetDPI (); |
2859 | -} |
2860 | - |
2861 | - StaticCairoText::StaticCairoText (const TCHAR* text, |
2862 | - NString fontName, |
2863 | - float fontSize, |
2864 | - eFontStyle fontStyle, |
2865 | - eFontWeight fontWeight, |
2866 | - Color textColor, |
2867 | - NUX_FILE_LINE_DECL) : |
2868 | - View (NUX_FILE_LINE_PARAM) |
2869 | -{ |
2870 | - _text = TEXT (text); |
2871 | - _fontName = fontName; |
2872 | - _fontSize = fontSize; |
2873 | - _fontStyle = fontStyle; |
2874 | - _fontWeight = fontWeight; |
2875 | - _textColor = textColor; |
2876 | - _fontOpts = cairo_font_options_create (); |
2877 | - |
2878 | - // FIXME: hard-coding these for the moment, as we don't have |
2879 | - // gsettings-support in place right now |
2880 | - cairo_font_options_set_antialias (_fontOpts, CAIRO_ANTIALIAS_SUBPIXEL); |
2881 | - cairo_font_options_set_hint_metrics (_fontOpts, CAIRO_HINT_METRICS_ON); |
2882 | - cairo_font_options_set_hint_style (_fontOpts, CAIRO_HINT_STYLE_SLIGHT); |
2883 | - cairo_font_options_set_subpixel_order (_fontOpts, CAIRO_SUBPIXEL_ORDER_RGB); |
2884 | - |
2885 | - // make sure _dpiX and _dpiY are initialized correctly |
2886 | - GetDPI (); |
2887 | } |
2888 | |
2889 | StaticCairoText::~StaticCairoText () |
2890 | { |
2891 | - cairo_font_options_destroy (_fontOpts); |
2892 | delete (_cairoGraphics); |
2893 | delete (_texture2D); |
2894 | } |
2895 | |
2896 | void StaticCairoText::PreLayoutManagement () |
2897 | { |
2898 | - int textWidth = 0; |
2899 | - int textHeight = 0; |
2900 | + int textWidth = 0; |
2901 | + int textHeight = 0; |
2902 | + GtkSettings* settings = gtk_settings_get_default (); // not ref'ed |
2903 | + gchar* fontName = NULL; |
2904 | |
2905 | - NString str = NString::Printf(TEXT("%s %.2f"), _fontName.GetTCharPtr (), _fontSize); |
2906 | - GetTextExtents (str.GetTCharPtr (), textWidth, textHeight); |
2907 | + g_object_get (settings, "gtk-font-name", &fontName, NULL); |
2908 | + GetTextExtents (fontName, textWidth, textHeight); |
2909 | + g_free (fontName); |
2910 | |
2911 | _pre_layout_width = GetBaseWidth (); |
2912 | _pre_layout_height = GetBaseHeight (); |
2913 | @@ -198,51 +157,7 @@ |
2914 | { |
2915 | _text = text; |
2916 | UpdateTexture (); |
2917 | - sigTextChanged.emit (*this); |
2918 | - } |
2919 | -} |
2920 | - |
2921 | -void |
2922 | -StaticCairoText::SetFontName (NString fontName) |
2923 | -{ |
2924 | - if (_fontName != fontName) |
2925 | - { |
2926 | - _fontName = fontName; |
2927 | - UpdateTexture (); |
2928 | - sigTextChanged.emit (*this); |
2929 | - } |
2930 | -} |
2931 | - |
2932 | -void |
2933 | -StaticCairoText::SetFontSize (float fontSize) |
2934 | -{ |
2935 | - if (_fontSize != fontSize) |
2936 | - { |
2937 | - _fontSize = fontSize; |
2938 | - UpdateTexture (); |
2939 | - sigTextChanged.emit (*this); |
2940 | - } |
2941 | -} |
2942 | - |
2943 | -void |
2944 | -StaticCairoText::SetFontWeight (eFontWeight fontWeight) |
2945 | -{ |
2946 | - if (_fontWeight != fontWeight) |
2947 | - { |
2948 | - _fontWeight = fontWeight; |
2949 | - UpdateTexture (); |
2950 | - sigTextChanged.emit (*this); |
2951 | - } |
2952 | -} |
2953 | - |
2954 | -void |
2955 | -StaticCairoText::SetFontStyle (eFontStyle fontStyle) |
2956 | -{ |
2957 | - if (_fontStyle != fontStyle) |
2958 | - { |
2959 | - _fontStyle = fontStyle; |
2960 | - UpdateTexture (); |
2961 | - sigTextChanged.emit (*this); |
2962 | + sigTextChanged.emit (this); |
2963 | } |
2964 | } |
2965 | |
2966 | @@ -252,48 +167,18 @@ |
2967 | if (_textColor != textColor) |
2968 | { |
2969 | _textColor = textColor; |
2970 | - sigTextColorChanged.emit (*this); |
2971 | + sigTextColorChanged.emit (this); |
2972 | } |
2973 | } |
2974 | |
2975 | -void |
2976 | -StaticCairoText::GetDPI () |
2977 | -{ |
2978 | -#if defined(NUX_OS_LINUX) |
2979 | - Display* display = NULL; |
2980 | - int screen = 0; |
2981 | - double dpyWidth = 0.0; |
2982 | - double dpyHeight = 0.0; |
2983 | - double dpyWidthMM = 0.0; |
2984 | - double dpyHeightMM = 0.0; |
2985 | - double dpiX = 0.0; |
2986 | - double dpiY = 0.0; |
2987 | - |
2988 | - display = XOpenDisplay (NULL); |
2989 | - screen = DefaultScreen (display); |
2990 | - |
2991 | - dpyWidth = (double) DisplayWidth (display, screen); |
2992 | - dpyHeight = (double) DisplayHeight (display, screen); |
2993 | - dpyWidthMM = (double) DisplayWidthMM (display, screen); |
2994 | - dpyHeightMM = (double) DisplayHeightMM (display, screen); |
2995 | - |
2996 | - dpiX = dpyWidth * 25.4 / dpyWidthMM; |
2997 | - dpiY = dpyHeight * 25.4 / dpyHeightMM; |
2998 | - |
2999 | - _dpiX = (int) (dpiX + 0.5); |
3000 | - _dpiY = (int) (dpiY + 0.5); |
3001 | - |
3002 | - XCloseDisplay (display); |
3003 | -#elif defined(NUX_OS_WINDOWS) |
3004 | - _dpiX = 72; |
3005 | - _dpiY = 72; |
3006 | -#endif |
3007 | -} |
3008 | - |
3009 | void StaticCairoText::GetTextExtents (int &width, int &height) |
3010 | { |
3011 | - NString str = NString::Printf(TEXT("%s %.2f"), _fontName.GetTCharPtr (), _fontSize); |
3012 | - GetTextExtents (str.GetTCharPtr (), width, height); |
3013 | + GtkSettings* settings = gtk_settings_get_default (); // not ref'ed |
3014 | + gchar* fontName = NULL; |
3015 | + |
3016 | + g_object_get (settings, "gtk-font-name", &fontName, NULL); |
3017 | + GetTextExtents (fontName, width, height); |
3018 | + g_free (fontName); |
3019 | } |
3020 | |
3021 | void StaticCairoText::GetTextExtents (const TCHAR* font, |
3022 | @@ -306,6 +191,9 @@ |
3023 | PangoFontDescription* desc = NULL; |
3024 | PangoContext* pangoCtx = NULL; |
3025 | PangoRectangle logRect = {0, 0, 0, 0}; |
3026 | + int dpi = 0; |
3027 | + GdkScreen* screen = gdk_screen_get_default (); // is not ref'ed |
3028 | + GtkSettings* settings = gtk_settings_get_default (); // is not ref'ed |
3029 | |
3030 | // sanity check |
3031 | if (!font) |
3032 | @@ -313,6 +201,7 @@ |
3033 | |
3034 | surface = cairo_image_surface_create (CAIRO_FORMAT_A1, 1, 1); |
3035 | cr = cairo_create (surface); |
3036 | + cairo_set_font_options (cr, gdk_screen_get_font_options (screen)); |
3037 | layout = pango_cairo_create_layout (cr); |
3038 | desc = pango_font_description_from_string (font); |
3039 | pango_font_description_set_weight (desc, PANGO_WEIGHT_NORMAL); |
3040 | @@ -321,8 +210,19 @@ |
3041 | pango_layout_set_ellipsize (layout, PANGO_ELLIPSIZE_END); |
3042 | pango_layout_set_markup (layout, _text.GetTCharPtr(), -1); |
3043 | pangoCtx = pango_layout_get_context (layout); // is not ref'ed |
3044 | - pango_cairo_context_set_font_options (pangoCtx, _fontOpts); |
3045 | - pango_cairo_context_set_resolution (pangoCtx, _dpiX); |
3046 | + pango_cairo_context_set_font_options (pangoCtx, |
3047 | + gdk_screen_get_font_options (screen)); |
3048 | + g_object_get (settings, "gtk-xft-dpi", &dpi, NULL); |
3049 | + if (dpi == -1) |
3050 | + { |
3051 | + // use some default DPI-value |
3052 | + pango_cairo_context_set_resolution (pangoCtx, 96.0f); |
3053 | + } |
3054 | + else |
3055 | + { |
3056 | + pango_cairo_context_set_resolution (pangoCtx, |
3057 | + (float) dpi / (float) PANGO_SCALE); |
3058 | + } |
3059 | pango_layout_context_changed (layout); |
3060 | pango_layout_get_extents (layout, NULL, &logRect); |
3061 | |
3062 | @@ -346,22 +246,35 @@ |
3063 | PangoLayout* layout = NULL; |
3064 | PangoFontDescription* desc = NULL; |
3065 | PangoContext* pangoCtx = NULL; |
3066 | - |
3067 | - NString str = NString::Printf(TEXT("%s %.2f"), _fontName.GetTCharPtr (), _fontSize); |
3068 | - GetTextExtents (str.GetTCharPtr (), textWidth, textHeight); |
3069 | - |
3070 | - cairo_set_font_options (cr, _fontOpts); |
3071 | + int dpi = 0; |
3072 | + GdkScreen* screen = gdk_screen_get_default (); // not ref'ed |
3073 | + GtkSettings* settings = gtk_settings_get_default (); // not ref'ed |
3074 | + gchar* fontName = NULL; |
3075 | + |
3076 | + g_object_get (settings, "gtk-font-name", &fontName, NULL); |
3077 | + GetTextExtents (fontName, textWidth, textHeight); |
3078 | + |
3079 | + cairo_set_font_options (cr, gdk_screen_get_font_options (screen)); |
3080 | layout = pango_cairo_create_layout (cr); |
3081 | - //desc = pango_font_description_from_string ((char*) FONT_FACE); |
3082 | - desc = pango_font_description_from_string (str.GetTCharPtr ()); |
3083 | - pango_font_description_set_weight (desc, (PangoWeight) _fontWeight); |
3084 | + desc = pango_font_description_from_string (fontName); |
3085 | pango_layout_set_font_description (layout, desc); |
3086 | pango_layout_set_wrap (layout, PANGO_WRAP_WORD_CHAR); |
3087 | pango_layout_set_ellipsize (layout, PANGO_ELLIPSIZE_END); |
3088 | pango_layout_set_markup (layout, _text.GetTCharPtr(), -1); |
3089 | pangoCtx = pango_layout_get_context (layout); // is not ref'ed |
3090 | - pango_cairo_context_set_font_options (pangoCtx, _fontOpts); |
3091 | - pango_cairo_context_set_resolution (pangoCtx, (double) _dpiX); |
3092 | + pango_cairo_context_set_font_options (pangoCtx, |
3093 | + gdk_screen_get_font_options (screen)); |
3094 | + g_object_get (settings, "gtk-xft-dpi", &dpi, NULL); |
3095 | + if (dpi == -1) |
3096 | + { |
3097 | + // use some default DPI-value |
3098 | + pango_cairo_context_set_resolution (pangoCtx, 96.0f); |
3099 | + } |
3100 | + else |
3101 | + { |
3102 | + pango_cairo_context_set_resolution (pangoCtx, |
3103 | + (float) dpi / (float) PANGO_SCALE); |
3104 | + } |
3105 | |
3106 | cairo_set_operator (cr, CAIRO_OPERATOR_SOURCE); |
3107 | cairo_set_source_rgba (cr, 0.0f, 0.0f, 0.0f, 0.0f); |
3108 | @@ -376,6 +289,7 @@ |
3109 | // clean up |
3110 | pango_font_description_free (desc); |
3111 | g_object_unref (layout); |
3112 | + g_free (fontName); |
3113 | } |
3114 | |
3115 | void StaticCairoText::UpdateTexture () |
3116 | |
3117 | === modified file 'src/StaticCairoText.h' |
3118 | --- src/StaticCairoText.h 2010-11-17 04:45:59 +0000 |
3119 | +++ src/StaticCairoText.h 2010-11-25 15:47:12 +0000 |
3120 | @@ -14,7 +14,7 @@ |
3121 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
3122 | * |
3123 | * Authored by: Jay Taoko <jay.taoko@canonical.com> |
3124 | - * Authored by: Mirco Müller <mirco.mueller@canonical.com |
3125 | + * Authored by: Mirco Müller <mirco.mueller@canonical.com> |
3126 | */ |
3127 | |
3128 | #ifndef STATICCAIROTEXT_H |
3129 | @@ -35,20 +35,6 @@ |
3130 | |
3131 | namespace nux |
3132 | { |
3133 | - enum eFontStyle |
3134 | - { |
3135 | - eNormalStyle = PANGO_STYLE_NORMAL, |
3136 | - eObliqueStyle = PANGO_STYLE_OBLIQUE, |
3137 | - eItalicStyle = PANGO_STYLE_ITALIC, |
3138 | - }; |
3139 | - |
3140 | - enum eFontWeight |
3141 | - { |
3142 | - eLightWeight = PANGO_WEIGHT_LIGHT, |
3143 | - eNormalWeight = PANGO_WEIGHT_NORMAL, |
3144 | - eBoldWeight = PANGO_WEIGHT_BOLD, |
3145 | - }; |
3146 | - |
3147 | class Validator; |
3148 | |
3149 | class StaticCairoText : public View |
3150 | @@ -56,14 +42,6 @@ |
3151 | public: |
3152 | StaticCairoText (const TCHAR* text, NUX_FILE_LINE_PROTO); |
3153 | |
3154 | - StaticCairoText (const TCHAR* text, |
3155 | - NString fontName, |
3156 | - float fontSize, |
3157 | - eFontStyle fontStyle, |
3158 | - eFontWeight fontWeight, |
3159 | - Color textColor, |
3160 | - NUX_FILE_LINE_PROTO); |
3161 | - |
3162 | ~StaticCairoText (); |
3163 | |
3164 | void PreLayoutManagement (); |
3165 | @@ -71,59 +49,45 @@ |
3166 | long PostLayoutManagement (long layoutResult); |
3167 | |
3168 | long ProcessEvent (IEvent& event, |
3169 | - long traverseInfo, |
3170 | - long processEventInfo); |
3171 | + long traverseInfo, |
3172 | + long processEventInfo); |
3173 | |
3174 | void Draw (GraphicsEngine& gfxContext, |
3175 | - bool forceDraw); |
3176 | + bool forceDraw); |
3177 | |
3178 | void DrawContent (GraphicsEngine& gfxContext, |
3179 | - bool forceDraw); |
3180 | + bool forceDraw); |
3181 | |
3182 | void PostDraw (GraphicsEngine& gfxContext, |
3183 | - bool forceDraw); |
3184 | + bool forceDraw); |
3185 | |
3186 | // public API |
3187 | void SetText (NString text); |
3188 | |
3189 | - void SetFontName (NString fontName); |
3190 | - |
3191 | - void SetFontSize (float fontSize); |
3192 | - |
3193 | - void SetFontWeight (eFontWeight fontWeight); |
3194 | - |
3195 | - void SetFontStyle (eFontStyle fontStyle); |
3196 | - |
3197 | void SetTextColor (Color textColor); |
3198 | |
3199 | void GetTextExtents (int &width, int &height); |
3200 | |
3201 | - sigc::signal<void, StaticCairoText&> sigTextChanged; |
3202 | - sigc::signal<void, StaticCairoText&> sigTextColorChanged; |
3203 | + sigc::signal<void, StaticCairoText*> sigTextChanged; |
3204 | + sigc::signal<void, StaticCairoText*> sigTextColorChanged; |
3205 | |
3206 | - protected: |
3207 | - |
3208 | private: |
3209 | - NString _text; |
3210 | - NString _fontName; |
3211 | - float _fontSize; |
3212 | - eFontStyle _fontStyle; |
3213 | - eFontWeight _fontWeight; |
3214 | - Color _textColor; |
3215 | - |
3216 | - CairoGraphics* _cairoGraphics; |
3217 | - BaseTexture* _texture2D; |
3218 | - int _dpiX; |
3219 | - int _dpiY; |
3220 | - cairo_font_options_t* _fontOpts; |
3221 | - |
3222 | - int _pre_layout_width; |
3223 | - int _pre_layout_height; |
3224 | - |
3225 | - void GetDPI (); |
3226 | - |
3227 | - void GetTextExtents (const TCHAR* font, int &width, int &height); |
3228 | - void DrawText (cairo_t* cr, int width, int height, Color color); |
3229 | + NString _text; |
3230 | + Color _textColor; |
3231 | + |
3232 | + CairoGraphics* _cairoGraphics; |
3233 | + BaseTexture* _texture2D; |
3234 | + |
3235 | + int _pre_layout_width; |
3236 | + int _pre_layout_height; |
3237 | + |
3238 | + void GetTextExtents (const TCHAR* font, |
3239 | + int& width, |
3240 | + int& height); |
3241 | + void DrawText (cairo_t* cr, |
3242 | + int width, |
3243 | + int height, |
3244 | + Color color); |
3245 | |
3246 | void UpdateTexture (); |
3247 | }; |
3248 | |
3249 | === modified file 'src/Tooltip.cpp' |
3250 | --- src/Tooltip.cpp 2010-11-18 15:13:23 +0000 |
3251 | +++ src/Tooltip.cpp 2010-11-25 15:47:12 +0000 |
3252 | @@ -28,6 +28,8 @@ |
3253 | #include "Nux/TextureArea.h" |
3254 | #include "NuxImage/CairoGraphics.h" |
3255 | |
3256 | +#include "QuicklistMenuItem.h" |
3257 | + |
3258 | #include "Tooltip.h" |
3259 | |
3260 | namespace nux |
3261 | @@ -211,7 +213,7 @@ |
3262 | return result; |
3263 | } |
3264 | |
3265 | - void Tooltip::RecvCairoTextChanged (StaticCairoText& cairo_text) |
3266 | + void Tooltip::RecvCairoTextChanged (StaticCairoText* cairo_text) |
3267 | { |
3268 | _cairo_text_has_changed = true; |
3269 | } |
3270 | |
3271 | === modified file 'src/Tooltip.h' |
3272 | --- src/Tooltip.h 2010-11-18 03:39:39 +0000 |
3273 | +++ src/Tooltip.h 2010-11-25 15:47:12 +0000 |
3274 | @@ -47,12 +47,14 @@ |
3275 | #define V_MARGIN 4 |
3276 | #define FONT_FACE "Ubuntu 13" |
3277 | |
3278 | +class QuicklistMenuItem; |
3279 | + |
3280 | namespace nux |
3281 | { |
3282 | class VLayout; |
3283 | class HLayout; |
3284 | class SpaceLayout; |
3285 | - |
3286 | + |
3287 | class Tooltip : public BaseWindow |
3288 | { |
3289 | NUX_DECLARE_OBJECT_TYPE (Tooltip, BaseWindow); |
3290 | @@ -75,7 +77,7 @@ |
3291 | |
3292 | void ShowTooltipWithTipAt (int anchor_tip_x, int anchor_tip_y); |
3293 | private: |
3294 | - void RecvCairoTextChanged (StaticCairoText& cairo_text); |
3295 | + void RecvCairoTextChanged (StaticCairoText* cairo_text); |
3296 | |
3297 | void PreLayoutManagement (); |
3298 | |
3299 | |
3300 | === modified file 'tests/CMakeLists.txt' |
3301 | --- tests/CMakeLists.txt 2010-11-25 12:09:08 +0000 |
3302 | +++ tests/CMakeLists.txt 2010-11-25 15:47:12 +0000 |
3303 | @@ -34,6 +34,7 @@ |
3304 | add_executable (test-unit |
3305 | unit/TestFavoriteStoreGSettings.cpp |
3306 | unit/TestPanelService.cpp |
3307 | + unit/TestQuicklistMenuitems.cpp |
3308 | unit/TestMain.cpp |
3309 | unit/TestUBus.cpp |
3310 | ../libunity/ubus-server.c |
3311 | @@ -44,6 +45,18 @@ |
3312 | ../src/FavoriteStore.h |
3313 | ../src/FavoriteStoreGSettings.cpp |
3314 | ../src/FavoriteStoreGSettings.h |
3315 | + ../src/QuicklistMenuItem.cpp |
3316 | + ../src/QuicklistMenuItem.h |
3317 | + ../src/QuicklistMenuItemCheckmark.cpp |
3318 | + ../src/QuicklistMenuItemCheckmark.h |
3319 | + ../src/QuicklistMenuItemLabel.cpp |
3320 | + ../src/QuicklistMenuItemLabel.h |
3321 | + ../src/QuicklistMenuItemRadio.cpp |
3322 | + ../src/QuicklistMenuItemRadio.h |
3323 | + ../src/QuicklistMenuItemSeparator.cpp |
3324 | + ../src/QuicklistMenuItemSeparator.h |
3325 | + ../src/QuicklistView.cpp |
3326 | + ../src/QuicklistView.h |
3327 | ) |
3328 | |
3329 | add_executable (test-panel |
3330 | |
3331 | === modified file 'tests/unit/TestMain.cpp' (properties changed: -x to +x) |
3332 | --- tests/unit/TestMain.cpp 2010-11-25 12:08:52 +0000 |
3333 | +++ tests/unit/TestMain.cpp 2010-11-25 15:47:12 +0000 |
3334 | @@ -21,10 +21,44 @@ |
3335 | #include "config.h" |
3336 | #include <glib.h> |
3337 | #include <glib-object.h> |
3338 | +#include "Nux/Nux.h" |
3339 | +#include "Nux/WindowThread.h" |
3340 | |
3341 | void TestFavoriteStoreGSettingsCreateSuite (void); |
3342 | void TestPanelServiceCreateSuite (void); |
3343 | +<<<<<<< TREE |
3344 | void TestUBusCreateSuite (void); |
3345 | +======= |
3346 | +void TestQuicklistMenuitemsCreateSuite (void); |
3347 | + |
3348 | +nux::WindowThread* |
3349 | +createThread () |
3350 | +{ |
3351 | + nux::WindowThread* thread = NULL; |
3352 | + |
3353 | + nux::NuxInitialize (0); |
3354 | + thread = nux::CreateGUIThread (TEXT ("Unit-Test Dummy Window"), |
3355 | + 320, |
3356 | + 240, |
3357 | + 0, |
3358 | + NULL, |
3359 | + 0); |
3360 | + return thread; |
3361 | +} |
3362 | + |
3363 | +void |
3364 | +runThread (nux::WindowThread* thread) |
3365 | +{ |
3366 | + thread->Run (NULL); |
3367 | +} |
3368 | + |
3369 | +void |
3370 | +stopThread (nux::WindowThread* thread) |
3371 | +{ |
3372 | + thread->TerminateThread (); |
3373 | + delete thread; |
3374 | +} |
3375 | +>>>>>>> MERGE-SOURCE |
3376 | |
3377 | int |
3378 | main (int argc, char **argv) |
3379 | @@ -39,7 +73,20 @@ |
3380 | //Keep alphabetical please |
3381 | TestFavoriteStoreGSettingsCreateSuite (); |
3382 | TestPanelServiceCreateSuite (); |
3383 | +<<<<<<< TREE |
3384 | TestUBusCreateSuite (); |
3385 | |
3386 | return g_test_run (); |
3387 | +======= |
3388 | + TestQuicklistMenuitemsCreateSuite (); |
3389 | + |
3390 | + nux::WindowThread* thread = createThread (); |
3391 | + |
3392 | + int ret = g_test_run (); |
3393 | + |
3394 | + stopThread (thread); |
3395 | + |
3396 | + return ret; |
3397 | + |
3398 | +>>>>>>> MERGE-SOURCE |
3399 | } |
3400 | |
3401 | === added file 'tests/unit/TestQuicklistMenuitems.cpp' |
3402 | --- tests/unit/TestQuicklistMenuitems.cpp 1970-01-01 00:00:00 +0000 |
3403 | +++ tests/unit/TestQuicklistMenuitems.cpp 2010-11-25 15:47:12 +0000 |
3404 | @@ -0,0 +1,238 @@ |
3405 | +/* |
3406 | + * Copyright 2010 Canonical Ltd. |
3407 | + * |
3408 | + * This program is free software: you can redistribute it and/or modify it |
3409 | + * under the terms of the GNU General Public License version 3, as published |
3410 | + * by the Free Software Foundation. |
3411 | + * |
3412 | + * This program is distributed in the hope that it will be useful, but |
3413 | + * WITHOUT ANY WARRANTY; without even the implied warranties of |
3414 | + * MERCHANTABILITY, SATISFACTORY QUALITY or FITNESS FOR A PARTICULAR |
3415 | + * PURPOSE. See the GNU General Public License for more details. |
3416 | + * |
3417 | + * You should have received a copy of the GNU General Public License |
3418 | + * version 3 along with this program. If not, see |
3419 | + * <http://www.gnu.org/licenses/> |
3420 | + * |
3421 | + * Authored by: Mirco Müller <mirco.mueller@canonical.com> |
3422 | + * |
3423 | + */ |
3424 | + |
3425 | +#include "config.h" |
3426 | + |
3427 | +#include "QuicklistMenuItem.h" |
3428 | +#include "QuicklistMenuItemCheckmark.h" |
3429 | +#include "QuicklistMenuItemLabel.h" |
3430 | +#include "QuicklistMenuItemRadio.h" |
3431 | +#include "QuicklistMenuItemSeparator.h" |
3432 | + |
3433 | +#include "Nux/Nux.h" |
3434 | +#include "Nux/VLayout.h" |
3435 | +#include "Nux/HLayout.h" |
3436 | +#include "Nux/WindowThread.h" |
3437 | +#include "Nux/WindowCompositor.h" |
3438 | +#include "Nux/BaseWindow.h" |
3439 | + |
3440 | +#include "QuicklistView.h" |
3441 | +#include "TestThreadHelper.h" |
3442 | + |
3443 | +static void TestMenuItemCheckmark (void); |
3444 | +static void TestMenuItemLabel (void); |
3445 | +static void TestMenuItemRadio (void); |
3446 | +static void TestMenuItemSeparator (void); |
3447 | +static void TestQuicklistMenuItem (void); |
3448 | + |
3449 | +nux::WindowThread* thread = NULL; |
3450 | + |
3451 | +void |
3452 | +TestQuicklistMenuitemsCreateSuite () |
3453 | +{ |
3454 | +#define _DOMAIN "/Unit/QuicklistMenuitems" |
3455 | + |
3456 | + g_test_add_func (_DOMAIN"/MenuItemCheckmark", TestMenuItemCheckmark); |
3457 | + g_test_add_func (_DOMAIN"/MenuItemLabel", TestMenuItemLabel); |
3458 | + g_test_add_func (_DOMAIN"/MenuItemRadio", TestMenuItemRadio); |
3459 | + g_test_add_func (_DOMAIN"/MenuItemSeparator", TestMenuItemSeparator); |
3460 | + g_test_add_func (_DOMAIN"/QuicklistMenuItem", TestQuicklistMenuItem); |
3461 | +} |
3462 | + |
3463 | +static void |
3464 | +TestMenuItemCheckmark () |
3465 | +{ |
3466 | + DbusmenuMenuitem* item = NULL; |
3467 | + |
3468 | + |
3469 | + item = dbusmenu_menuitem_new (); |
3470 | + |
3471 | + dbusmenu_menuitem_property_set (item, |
3472 | + DBUSMENU_MENUITEM_PROP_LABEL, |
3473 | + "Unchecked"); |
3474 | + |
3475 | + dbusmenu_menuitem_property_set (item, |
3476 | + DBUSMENU_MENUITEM_PROP_TOGGLE_TYPE, |
3477 | + DBUSMENU_MENUITEM_TOGGLE_CHECK); |
3478 | + |
3479 | + dbusmenu_menuitem_property_set_bool (item, |
3480 | + DBUSMENU_MENUITEM_PROP_ENABLED, |
3481 | + false); |
3482 | + |
3483 | + dbusmenu_menuitem_property_set_int (item, |
3484 | + DBUSMENU_MENUITEM_PROP_TOGGLE_STATE, |
3485 | + DBUSMENU_MENUITEM_TOGGLE_STATE_UNCHECKED); |
3486 | + |
3487 | + QuicklistMenuItemCheckmark* qlCheckmarkItem = NULL; |
3488 | + |
3489 | + qlCheckmarkItem = new QuicklistMenuItemCheckmark (item, true); |
3490 | + |
3491 | + g_assert_cmpstr (qlCheckmarkItem->GetLabel (), ==, "Unchecked"); |
3492 | + g_assert_cmpint (qlCheckmarkItem->GetEnabled (), ==, false); |
3493 | + g_assert_cmpint (qlCheckmarkItem->GetActive (), ==, false); |
3494 | + |
3495 | + //qlCheckmarkItem->sigChanged.connect (sigc::mem_fun (pointerToCallerClass, |
3496 | + // &CallerClass::RecvChanged)); |
3497 | + |
3498 | + |
3499 | + qlCheckmarkItem->Dispose (); |
3500 | + g_object_unref (item); |
3501 | +} |
3502 | + |
3503 | +static void |
3504 | +TestMenuItemLabel () |
3505 | +{ |
3506 | + DbusmenuMenuitem* item = NULL; |
3507 | + |
3508 | + item = dbusmenu_menuitem_new (); |
3509 | + |
3510 | + dbusmenu_menuitem_property_set (item, |
3511 | + DBUSMENU_MENUITEM_PROP_LABEL, |
3512 | + "A Label"); |
3513 | + |
3514 | + dbusmenu_menuitem_property_set_bool (item, |
3515 | + DBUSMENU_MENUITEM_PROP_ENABLED, |
3516 | + true); |
3517 | + |
3518 | + QuicklistMenuItemLabel* qlLabelItem = NULL; |
3519 | + |
3520 | + qlLabelItem = new QuicklistMenuItemLabel (item, true); |
3521 | + |
3522 | + g_assert_cmpstr (qlLabelItem->GetLabel (), ==, "A Label"); |
3523 | + g_assert_cmpint (qlLabelItem->GetEnabled (), ==, true); |
3524 | + |
3525 | + //qlLabelItem->sigChanged.connect (sigc::mem_fun (pointerToCallerClass, |
3526 | + // &CallerClass::RecvChanged)); |
3527 | + |
3528 | + qlLabelItem->Dispose (); |
3529 | + g_object_unref (item); |
3530 | +} |
3531 | + |
3532 | +static void |
3533 | +TestMenuItemRadio () |
3534 | +{ |
3535 | + DbusmenuMenuitem* item = NULL; |
3536 | + |
3537 | + item = dbusmenu_menuitem_new (); |
3538 | + |
3539 | + dbusmenu_menuitem_property_set (item, |
3540 | + DBUSMENU_MENUITEM_PROP_LABEL, |
3541 | + "Radio Active"); |
3542 | + |
3543 | + dbusmenu_menuitem_property_set (item, |
3544 | + DBUSMENU_MENUITEM_PROP_TOGGLE_TYPE, |
3545 | + DBUSMENU_MENUITEM_TOGGLE_RADIO); |
3546 | + |
3547 | + dbusmenu_menuitem_property_set_bool (item, |
3548 | + DBUSMENU_MENUITEM_PROP_ENABLED, |
3549 | + true); |
3550 | + |
3551 | + dbusmenu_menuitem_property_set_int (item, |
3552 | + DBUSMENU_MENUITEM_PROP_TOGGLE_STATE, |
3553 | + DBUSMENU_MENUITEM_TOGGLE_STATE_CHECKED); |
3554 | + |
3555 | + QuicklistMenuItemRadio* qlRadioItem = NULL; |
3556 | + |
3557 | + qlRadioItem = new QuicklistMenuItemRadio (item, true); |
3558 | + |
3559 | + g_assert_cmpstr (qlRadioItem->GetLabel (), ==, "Radio Active"); |
3560 | + g_assert_cmpint (qlRadioItem->GetEnabled (), ==, true); |
3561 | + g_assert_cmpint (qlRadioItem->GetActive (), ==, true); |
3562 | + |
3563 | + //qlRadioItem->sigChanged.connect (sigc::mem_fun (pointerToCallerClass, |
3564 | + // &CallerClass::RecvChanged)); |
3565 | + |
3566 | + qlRadioItem->Dispose (); |
3567 | + g_object_unref (item); |
3568 | +} |
3569 | + |
3570 | +static void |
3571 | +TestMenuItemSeparator () |
3572 | +{ |
3573 | + DbusmenuMenuitem* item = NULL; |
3574 | + |
3575 | + item = dbusmenu_menuitem_new (); |
3576 | + |
3577 | + dbusmenu_menuitem_property_set (item, |
3578 | + "type", |
3579 | + DBUSMENU_CLIENT_TYPES_SEPARATOR); |
3580 | + |
3581 | + dbusmenu_menuitem_property_set_bool (item, |
3582 | + DBUSMENU_MENUITEM_PROP_ENABLED, |
3583 | + true); |
3584 | + |
3585 | + QuicklistMenuItemSeparator* qlSeparatorItem = NULL; |
3586 | + |
3587 | + qlSeparatorItem = new QuicklistMenuItemSeparator (item, true); |
3588 | + |
3589 | + g_assert_cmpint (qlSeparatorItem->GetEnabled (), ==, true); |
3590 | + |
3591 | + qlSeparatorItem->Dispose (); |
3592 | + g_object_unref (item); |
3593 | +} |
3594 | + |
3595 | +static void |
3596 | +TestQuicklistMenuItem () |
3597 | +{ |
3598 | + DbusmenuMenuitem* root = dbusmenu_menuitem_new (); |
3599 | + |
3600 | + dbusmenu_menuitem_set_root (root, true); |
3601 | + |
3602 | + DbusmenuMenuitem* child = dbusmenu_menuitem_new (); |
3603 | + dbusmenu_menuitem_property_set (child, DBUSMENU_MENUITEM_PROP_TYPE, DBUSMENU_MENUITEM_PROP_LABEL); |
3604 | + dbusmenu_menuitem_property_set (child, DBUSMENU_MENUITEM_PROP_LABEL, "label 0"); |
3605 | + dbusmenu_menuitem_property_set_bool (child, DBUSMENU_MENUITEM_PROP_ENABLED, true); |
3606 | + dbusmenu_menuitem_child_append (root, child); |
3607 | + |
3608 | + child = dbusmenu_menuitem_new (); |
3609 | + dbusmenu_menuitem_property_set (child, DBUSMENU_MENUITEM_PROP_TYPE, DBUSMENU_CLIENT_TYPES_SEPARATOR); |
3610 | + dbusmenu_menuitem_property_set_bool (child, DBUSMENU_MENUITEM_PROP_ENABLED, true); |
3611 | + dbusmenu_menuitem_child_append (root, child); |
3612 | + |
3613 | + child = dbusmenu_menuitem_new (); |
3614 | + dbusmenu_menuitem_property_set (child, DBUSMENU_MENUITEM_PROP_TYPE, DBUSMENU_MENUITEM_PROP_LABEL); |
3615 | + dbusmenu_menuitem_property_set (child, DBUSMENU_MENUITEM_PROP_LABEL, "label 1"); |
3616 | + dbusmenu_menuitem_property_set_bool (child, DBUSMENU_MENUITEM_PROP_ENABLED, true); |
3617 | + dbusmenu_menuitem_child_append (root, child); |
3618 | + |
3619 | + child = dbusmenu_menuitem_new (); |
3620 | + dbusmenu_menuitem_property_set (child, DBUSMENU_MENUITEM_PROP_TOGGLE_TYPE, DBUSMENU_MENUITEM_TOGGLE_CHECK); |
3621 | + dbusmenu_menuitem_property_set (child, DBUSMENU_MENUITEM_PROP_LABEL, "check mark 0"); |
3622 | + dbusmenu_menuitem_property_set_bool (child, DBUSMENU_MENUITEM_PROP_ENABLED, true); |
3623 | + dbusmenu_menuitem_property_set_int (child, DBUSMENU_MENUITEM_PROP_TOGGLE_STATE, DBUSMENU_MENUITEM_TOGGLE_STATE_UNCHECKED); |
3624 | + dbusmenu_menuitem_child_append (root, child); |
3625 | + |
3626 | + QuicklistView* quicklist = new QuicklistView (); |
3627 | + |
3628 | + quicklist->TestMenuItems (root); |
3629 | + |
3630 | + g_assert_cmpint (quicklist->GetNumItems (), ==, 4); |
3631 | + g_assert_cmpint (quicklist->GetNthType (0), ==, MENUITEM_TYPE_LABEL); |
3632 | + g_assert_cmpint (quicklist->GetNthType (1), ==, MENUITEM_TYPE_SEPARATOR); |
3633 | + g_assert_cmpint (quicklist->GetNthType (2), ==, MENUITEM_TYPE_LABEL); |
3634 | + g_assert_cmpint (quicklist->GetNthType (3), ==, MENUITEM_TYPE_CHECK); |
3635 | + |
3636 | + g_assert_cmpstr (quicklist->GetNthItems (0)->GetLabel (), ==, "label 0"); |
3637 | + g_assert_cmpstr (quicklist->GetNthItems (2)->GetLabel (), ==, "label 1"); |
3638 | + g_assert_cmpstr (quicklist->GetNthItems (3)->GetLabel (), ==, "check mark 0"); |
3639 | + |
3640 | + |
3641 | + quicklist->Dispose (); |
3642 | +} |
3643 | |
3644 | === added file 'tests/unit/TestThreadHelper.h' |
3645 | --- tests/unit/TestThreadHelper.h 1970-01-01 00:00:00 +0000 |
3646 | +++ tests/unit/TestThreadHelper.h 2010-11-25 15:47:12 +0000 |
3647 | @@ -0,0 +1,23 @@ |
3648 | +/* |
3649 | + * Copyright 2010 Canonical Ltd. |
3650 | + * |
3651 | + * This program is free software: you can redistribute it and/or modify it |
3652 | + * under the terms of the GNU General Public License version 3, as published |
3653 | + * by the Free Software Foundation. |
3654 | + * |
3655 | + * This program is distributed in the hope that it will be useful, but |
3656 | + * WITHOUT ANY WARRANTY; without even the implied warranties of |
3657 | + * MERCHANTABILITY, SATISFACTORY QUALITY or FITNESS FOR A PARTICULAR |
3658 | + * PURPOSE. See the GNU General Public License for more details. |
3659 | + * |
3660 | + * You should have received a copy of the GNU General Public License |
3661 | + * version 3 along with this program. If not, see |
3662 | + * <http://www.gnu.org/licenses/> |
3663 | + * |
3664 | + * Authored by: Mirco Müller <mirco.mueller@canonical.com> |
3665 | + * |
3666 | + */ |
3667 | + |
3668 | +extern nux::WindowThread* createThread (void); |
3669 | +extern void runThread (nux::WindowThread* thread); |
3670 | +extern void stopThread (nux::WindowThread* thread); |
Good stuff, the tests look good and it runs, however I have some comments that I'd like to see addressed before approving:
- There's a conflict in po/unity.pot
- In + else emLabel* item = new QuicklistMenuIt emLabel (newitem, NUX_TRACKER_ LOCATION) ; >AddMenuItem (item);
64 + {
65 + QuicklistMenuIt
66 + quicklist-
67 + }
I think you should explicitly check for label item, and in the "else" you should warn that we don't support item of type $type
- "// enable this once all proper QuicklistMenuitems are fully implemented" why is this code this here?
- You don't need #if defined (NUX_OS_LINUX), it's all we care about
- GetDPI () should get the DPI from GtkSettings
- Do const gchar * checks against NULL, not against 0. Return NULL for a method returning a char pointer, don't return 0
- QuicklistMenuIt em::GetTextExte nts and QuicklistMenuIt em::UpdateTextu re, do they need to be in trunk if they are commented out?
- Why do you need to cache _enabled & _active in QuicklistMenuItem?
- QuicklistMenuItem () with the debug constructor doesn't connect to thee menuitem's signals, so it won't stay up-to-date...
- Why aren't sub-classes using GetLabel() instead of getting information from dbusmenu themselves?
- Tons of commented out lines, if we dont' need them can we drop them?
- QuicklistMenuIt emCheckmark: :DrawText leaking Leaking PangoContext?
- Do we have multiple GetTextExtents? Should they not be in a utility file?
- What is SetFontWeight/Style etc for? Why are exposing this publicly right now?
- Waaay too much copy-and-pasted code, needs to be moved in to a Utils.h/cpp for clarity
- I *really* don't like having to use NStrings everywhere. dbusmenu is handing things to us as const gchar* and that's what we need to feed into cairo/pango, so why do we add NString in between? I'd like this changed to const char* like the rest of the plugin.
- Tests look great!