2 * This file is a part of hildon
4 * Copyright (C) 2005, 2006 Nokia Corporation, all rights reserved.
6 * Contact: Michael Dominic Kostrzewa <michael.kostrzewa@nokia.com>
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public License
10 * as published by the Free Software Foundation; version 2.1 of
13 * This library is distributed in the hope that it will be useful, but
14 * WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
26 #include "hildon-composite-widget.h"
27 #include <gtk/gtkwidget.h>
28 #include <gtk/gtkwindow.h>
29 #include "hildon-date-editor.h"
30 #include "hildon-time-editor.h"
32 /* This function is a private function of hildon. It hadles focus
33 * changing for composite hildon widgets: HildonDateEditor,
34 * HildonNumberEditor, HildonTimeEditor, HildonWeekdayPicker.
35 * Its purpose is to focus the first widget (from left) inside the container
36 * regardless of where the focus is coming from.
39 hildon_composite_widget_focus (GtkWidget *widget, GtkDirectionType direction)
41 GtkWidget *toplevel = NULL;
42 GtkWidget *focus_widget = NULL;
44 /* Get the topmost parent widget */
45 toplevel = gtk_widget_get_toplevel (widget);
46 if (!GTK_IS_WINDOW(toplevel))
47 return GTK_WIDGET_CLASS (g_type_class_peek_parent (
48 GTK_WIDGET_GET_CLASS (widget)))->focus (widget, direction);
49 /* Get focus widget in the topmost parent widget */
50 focus_widget = GTK_WINDOW (toplevel)->focus_widget;
52 if (!GTK_IS_WIDGET (focus_widget))
55 if (!gtk_widget_is_ancestor (focus_widget, widget))
57 gtk_widget_grab_focus (widget);
61 /* Containers grab_focus grabs the focus to the correct widget */
65 if (HILDON_IS_DATE_EDITOR(widget) || HILDON_IS_TIME_EDITOR(widget))
68 return GTK_WIDGET_CLASS (g_type_class_peek_parent
69 (GTK_WIDGET_GET_CLASS(widget)))->focus (widget, direction);
73 return GTK_WIDGET_CLASS (g_type_class_peek_parent
74 (GTK_WIDGET_GET_CLASS(widget)))->focus (widget, direction);