1 | /* |
2 | * Copyright (C) 2017 Igalia S.L. |
3 | * |
4 | * This library is free software; you can redistribute it and/or |
5 | * modify it under the terms of the GNU Library General Public |
6 | * License as published by the Free Software Foundation; either |
7 | * version 2 of the License, or (at your option) any later version. |
8 | * |
9 | * This library is distributed in the hope that it will be useful, |
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
12 | * Library General Public License for more details. |
13 | * |
14 | * You should have received a copy of the GNU Library General Public License |
15 | * along with this library; see the file COPYING.LIB. If not, write to |
16 | * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
17 | * Boston, MA 02110-1301, USA. |
18 | */ |
19 | |
20 | #include "config.h" |
21 | #include "WebKitOptionMenuItem.h" |
22 | |
23 | #include "WebKitOptionMenuItemPrivate.h" |
24 | |
25 | using namespace WebKit; |
26 | |
27 | /** |
28 | * SECTION: WebKitOptionMenuItem |
29 | * @Short_description: One item of the #WebKitOptionMenu |
30 | * @Title: WebKitOptionMenuItem |
31 | * |
32 | * The #WebKitOptionMenu is composed of WebKitOptionMenuItem<!-- -->s. |
33 | * A WebKitOptionMenuItem always has a label and can contain a tooltip text. |
34 | * You can use the WebKitOptionMenuItem of a #WebKitOptionMenu to build your |
35 | * own menus. |
36 | * |
37 | * Since: 2.18 |
38 | */ |
39 | |
40 | G_DEFINE_BOXED_TYPE(WebKitOptionMenuItem, webkit_option_menu_item, webkit_option_menu_item_copy, webkit_option_menu_item_free) |
41 | |
42 | /** |
43 | * webkit_option_menu_item_copy: |
44 | * @item: a #WebKitOptionMenuItem |
45 | * |
46 | * Make a copy of the #WebKitOptionMenuItem. |
47 | * |
48 | * Returns: (transfer full): A copy of passed in #WebKitOptionMenuItem |
49 | * |
50 | * Since: 2.18 |
51 | */ |
52 | WebKitOptionMenuItem* (WebKitOptionMenuItem* item) |
53 | { |
54 | g_return_val_if_fail(item, nullptr); |
55 | |
56 | auto* copyItem = static_cast<WebKitOptionMenuItem*>(fastMalloc(sizeof(WebKitOptionMenuItem))); |
57 | new (copyItem) WebKitOptionMenuItem(item); |
58 | return copyItem; |
59 | } |
60 | |
61 | /** |
62 | * webkit_option_menu_item_free: |
63 | * @item: A #WebKitOptionMenuItem |
64 | * |
65 | * Free the #WebKitOptionMenuItem. |
66 | * |
67 | * Since: 2.18 |
68 | */ |
69 | void (WebKitOptionMenuItem* item) |
70 | { |
71 | g_return_if_fail(item); |
72 | |
73 | item->~WebKitOptionMenuItem(); |
74 | fastFree(item); |
75 | } |
76 | |
77 | /** |
78 | * webkit_option_menu_item_get_label: |
79 | * @item: a #WebKitOptionMenuItem |
80 | * |
81 | * Get the label of a #WebKitOptionMenuItem. |
82 | * |
83 | * Returns: The label of @item. |
84 | * |
85 | * Since: 2.18 |
86 | */ |
87 | const gchar* (WebKitOptionMenuItem* item) |
88 | { |
89 | g_return_val_if_fail(item, nullptr); |
90 | |
91 | return item->label.data(); |
92 | } |
93 | |
94 | /** |
95 | * webkit_option_menu_item_get_tooltip: |
96 | * @item: a #WebKitOptionMenuItem |
97 | * |
98 | * Get the tooltip of a #WebKitOptionMenuItem. |
99 | * |
100 | * Returns: The tooltip of @item, or %NULL. |
101 | * |
102 | * Since: 2.18 |
103 | */ |
104 | const gchar* (WebKitOptionMenuItem* item) |
105 | { |
106 | g_return_val_if_fail(item, nullptr); |
107 | |
108 | return item->tooltip.isNull() ? nullptr : item->tooltip.data(); |
109 | } |
110 | |
111 | /** |
112 | * webkit_option_menu_item_is_group_label: |
113 | * @item: a #WebKitOptionMenuItem |
114 | * |
115 | * Whether a #WebKitOptionMenuItem is a group label. |
116 | * |
117 | * Returns: %TRUE if the @item is a group label or %FALSE otherwise. |
118 | * |
119 | * Since: 2.18 |
120 | */ |
121 | gboolean (WebKitOptionMenuItem* item) |
122 | { |
123 | g_return_val_if_fail(item, FALSE); |
124 | |
125 | return item->isGroupLabel; |
126 | } |
127 | |
128 | /** |
129 | * webkit_option_menu_item_is_group_child: |
130 | * @item: a #WebKitOptionMenuItem |
131 | * |
132 | * Whether a #WebKitOptionMenuItem is a group child. |
133 | * |
134 | * Returns: %TRUE if the @item is a group child or %FALSE otherwise. |
135 | * |
136 | * Since: 2.18 |
137 | */ |
138 | gboolean (WebKitOptionMenuItem* item) |
139 | { |
140 | g_return_val_if_fail(item, FALSE); |
141 | |
142 | return item->isGroupChild; |
143 | } |
144 | |
145 | /** |
146 | * webkit_option_menu_item_is_enabled: |
147 | * @item: a #WebKitOptionMenuItem |
148 | * |
149 | * Whether a #WebKitOptionMenuItem is enabled. |
150 | * |
151 | * Returns: %TRUE if the @item is enabled or %FALSE otherwise. |
152 | * |
153 | * Since: 2.18 |
154 | */ |
155 | gboolean (WebKitOptionMenuItem* item) |
156 | { |
157 | g_return_val_if_fail(item, FALSE); |
158 | |
159 | return item->isEnabled; |
160 | } |
161 | |
162 | /** |
163 | * webkit_option_menu_item_is_selected: |
164 | * @item: a #WebKitOptionMenuItem |
165 | * |
166 | * Whether a #WebKitOptionMenuItem is the currently selected one. |
167 | * |
168 | * Returns: %TRUE if the @item is selected or %FALSE otherwise. |
169 | * |
170 | * Since: 2.18 |
171 | */ |
172 | gboolean (WebKitOptionMenuItem* item) |
173 | { |
174 | g_return_val_if_fail(item, FALSE); |
175 | |
176 | return item->isSelected; |
177 | } |
178 | |