2008-08-14 Alberto Garcia <agarcia@igalia.com>
[hildon] / src / hildon-private.c
1 /*
2  * This file is a part of hildon
3  *
4  * Copyright (C) 2005, 2006 Nokia Corporation, all rights reserved.
5  *
6  * Contact: Michael Dominic Kostrzewa <michael.kostrzewa@nokia.com>
7  *
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
11  * the License, or (at your option) any later version.
12  *
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.
17  *
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
21  * 02110-1301 USA
22  *
23  */
24
25 #ifdef                                          HAVE_CONFIG_H
26 #include                                        <config.h>
27 #endif
28
29 #include                                        "hildon-private.h"
30 #include                                        "hildon-date-editor.h"
31 #include                                        "hildon-time-editor.h"
32
33 /* This function is a private function of hildon. It hadles focus 
34  * changing for composite hildon widgets: HildonDateEditor, 
35  * HildonNumberEditor, HildonTimeEditor, HildonWeekdayPicker. 
36  * Its purpose is to focus the first widget (from left) inside the container 
37  * regardless of where the focus is coming from.
38  */
39 gboolean G_GNUC_INTERNAL
40 hildon_private_composite_focus                  (GtkWidget *widget,
41                                                  GtkDirectionType direction,
42                                                  GtkDirectionType *effective_direction)
43 {
44   GtkWidget *toplevel = NULL;
45   GtkWidget *focus_widget = NULL;
46   gboolean coming_from_outside = FALSE;
47
48   toplevel = gtk_widget_get_toplevel (widget);
49
50   focus_widget = GTK_WINDOW (toplevel)->focus_widget;
51
52   if (focus_widget == NULL || gtk_widget_is_ancestor (focus_widget, widget) == FALSE)
53     {
54       /* When coming from outside we want to give focus to the first
55          item in the widgets */
56       *effective_direction = GTK_DIR_TAB_FORWARD;
57       coming_from_outside = TRUE;
58     }
59   else
60     *effective_direction = direction;
61
62   switch (direction) {
63       case GTK_DIR_UP:
64       case GTK_DIR_DOWN:
65       case GTK_DIR_TAB_FORWARD:
66       case GTK_DIR_TAB_BACKWARD:
67         if ((HILDON_IS_DATE_EDITOR (widget) || HILDON_IS_TIME_EDITOR(widget)) &&
68             !coming_from_outside)
69             return FALSE;
70         /* fall through */
71       default:
72         return TRUE;
73   }
74
75   g_assert_not_reached ();
76   return TRUE;
77 }
78
79