various fixes to MidiRegionView selection handling, key handling, drawing of ghost...
[ardour2.git] / libs / clearlooks-newer / widget-information.c
blobcbeb00e291901dd90fc04b95a236d588b964ac14
1 #include <gtk/gtk.h>
3 #include "general-support.h"
4 #include "widget-information.h"
5 #include <math.h>
6 #include <string.h>
8 /* Widget Type Lookups/Macros
10 Based on/modified from functions in
11 Smooth-Engine.
12 */
13 gboolean
14 ge_object_is_a (const GObject * object, const gchar * type_name)
16 gboolean result = FALSE;
18 if ((object))
20 GType tmp = g_type_from_name (type_name);
22 if (tmp)
23 result = g_type_check_instance_is_a ((GTypeInstance *) object, tmp);
26 return result;
29 gboolean
30 ge_is_combo_box_entry (GtkWidget * widget)
32 gboolean result = FALSE;
34 if ((widget) && (widget->parent))
36 if (GE_IS_COMBO_BOX_ENTRY (widget->parent))
37 result = TRUE;
38 else
39 result = ge_is_combo_box_entry (widget->parent);
41 return result;
44 static gboolean
45 ge_combo_box_is_using_list (GtkWidget * widget)
47 gboolean result = FALSE;
49 if (GE_IS_COMBO_BOX (widget))
51 gboolean *tmp = NULL;
53 gtk_widget_style_get (widget, "appears-as-list", &result, NULL);
55 if (tmp)
56 result = *tmp;
59 return result;
62 gboolean
63 ge_is_combo_box (GtkWidget * widget, gboolean as_list)
65 gboolean result = FALSE;
67 if ((widget) && (widget->parent))
69 if (GE_IS_COMBO_BOX (widget->parent))
71 if (as_list)
72 result = (ge_combo_box_is_using_list(widget->parent));
73 else
74 result = (!ge_combo_box_is_using_list(widget->parent));
76 else
77 result = ge_is_combo_box (widget->parent, as_list);
79 return result;
82 gboolean
83 ge_is_combo (GtkWidget * widget)
85 gboolean result = FALSE;
87 if ((widget) && (widget->parent))
89 if (GE_IS_COMBO (widget->parent))
90 result = TRUE;
91 else
92 result = ge_is_combo (widget->parent);
94 return result;
97 gboolean
98 ge_is_in_combo_box (GtkWidget * widget)
100 return ((ge_is_combo (widget) || ge_is_combo_box (widget, TRUE) || ge_is_combo_box_entry (widget)));
103 gboolean
104 ge_is_toolbar_item (GtkWidget * widget)
106 gboolean result = FALSE;
108 if ((widget) && (widget->parent)) {
109 if ((GE_IS_BONOBO_TOOLBAR (widget->parent))
110 || (GE_IS_BONOBO_DOCK_ITEM (widget->parent))
111 || (GE_IS_EGG_TOOLBAR (widget->parent))
112 || (GE_IS_TOOLBAR (widget->parent))
113 || (GE_IS_HANDLE_BOX (widget->parent)))
114 result = TRUE;
115 else
116 result = ge_is_toolbar_item (widget->parent);
118 return result;
121 gboolean
122 ge_is_panel_widget_item (GtkWidget * widget)
124 gboolean result = FALSE;
126 if ((widget) && (widget->parent))
128 if (GE_IS_PANEL_WIDGET (widget->parent))
129 result = TRUE;
130 else
131 result = ge_is_panel_widget_item (widget->parent);
133 return result;
136 gboolean
137 ge_is_bonobo_dock_item (GtkWidget * widget)
139 gboolean result = FALSE;
141 if ((widget))
143 if (GE_IS_BONOBO_DOCK_ITEM(widget) || GE_IS_BONOBO_DOCK_ITEM (widget->parent))
144 result = TRUE;
145 else if (GE_IS_BOX(widget) || GE_IS_BOX(widget->parent))
147 GtkContainer *box = GE_IS_BOX(widget)?GTK_CONTAINER(widget):GTK_CONTAINER(widget->parent);
148 GList *children = NULL, *child = NULL;
150 children = gtk_container_get_children(box);
152 for (child = g_list_first(children); child; child = g_list_next(child))
154 if (GE_IS_BONOBO_DOCK_ITEM_GRIP(child->data))
156 result = TRUE;
157 child = NULL;
161 if (children)
162 g_list_free(children);
165 return result;
168 static GtkWidget *
169 ge_find_combo_box_entry_widget (GtkWidget * widget)
171 GtkWidget *result = NULL;
173 if (widget)
175 if (GE_IS_COMBO_BOX_ENTRY (widget))
176 result = widget;
177 else
178 result = ge_find_combo_box_entry_widget (widget->parent);
181 return result;
184 static GtkWidget *
185 ge_find_combo_box_widget (GtkWidget * widget, gboolean as_list)
187 GtkWidget *result = NULL;
189 if (widget)
191 if (GE_IS_COMBO_BOX (widget))
193 if (as_list)
194 result = (ge_combo_box_is_using_list(widget))?widget:NULL;
195 else
196 result = (!ge_combo_box_is_using_list(widget))?widget:NULL;
198 else
199 result = ge_find_combo_box_widget (widget->parent, as_list);
201 return result;
204 static GtkWidget *
205 ge_find_combo_widget (GtkWidget * widget)
207 GtkWidget *result = NULL;
209 if (widget)
211 if (GE_IS_COMBO (widget))
212 result = widget;
213 else
214 result = ge_find_combo_widget(widget->parent);
216 return result;
219 GtkWidget*
220 ge_find_combo_box_widget_parent (GtkWidget * widget)
222 GtkWidget *result = NULL;
224 if (!result)
225 result = ge_find_combo_widget(widget);
227 if (!result)
228 result = ge_find_combo_box_widget(widget, TRUE);
230 if (!result)
231 result = ge_find_combo_box_entry_widget(widget);
233 return result;
236 /***********************************************
237 * option_menu_get_props -
239 * Find Option Menu Size and Spacing
241 * Taken from Smooth
242 ***********************************************/
243 void
244 ge_option_menu_get_props (GtkWidget * widget,
245 GtkRequisition * indicator_size,
246 GtkBorder * indicator_spacing)
248 GtkRequisition default_size = { 9, 5 };
249 GtkBorder default_spacing = { 7, 5, 2, 2 };
250 GtkRequisition *tmp_size = NULL;
251 GtkBorder *tmp_spacing = NULL;
253 if ((widget) && GE_IS_OPTION_MENU(widget))
254 gtk_widget_style_get (widget,
255 "indicator_size", &tmp_size,
256 "indicator_spacing", &tmp_spacing, NULL);
258 if (tmp_size)
260 *indicator_size = *tmp_size;
261 gtk_requisition_free (tmp_size);
263 else
264 *indicator_size = default_size;
266 if (tmp_spacing)
268 *indicator_spacing = *tmp_spacing;
269 gtk_border_free (tmp_spacing);
271 else
272 *indicator_spacing = default_spacing;
275 void
276 ge_button_get_default_border (GtkWidget *widget,
277 GtkBorder *border)
279 GtkBorder default_border = {1, 1, 1, 1};
280 GtkBorder *tmp_border = NULL;
282 if (widget && GE_IS_BUTTON (widget))
283 gtk_widget_style_get (widget, "default-border", &tmp_border, NULL);
285 if (tmp_border)
287 *border = *tmp_border;
288 gtk_border_free (tmp_border);
290 else
292 *border = default_border;
297 gboolean
298 ge_widget_is_ltr (GtkWidget *widget)
300 GtkTextDirection dir = GTK_TEXT_DIR_NONE;
302 if (GE_IS_WIDGET (widget))
303 dir = gtk_widget_get_direction (widget);
305 if (dir == GTK_TEXT_DIR_NONE)
306 dir = gtk_widget_get_default_direction ();
308 if (dir == GTK_TEXT_DIR_RTL)
309 return FALSE;
310 else
311 return TRUE;