Moving "composite widget" to private since essentially it's just a handy private...
[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.
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                                        <gtk/gtkwidget.h>
31 #include                                        <gtk/gtkwindow.h>
32 #include                                        "hildon-date-editor.h"
33 #include                                        "hildon-time-editor.h"
34
35 /* This function is a private function of hildon. It hadles focus 
36  * changing for composite hildon widgets: HildonDateEditor, 
37  * HildonNumberEditor, HildonTimeEditor, HildonWeekdayPicker. 
38  * Its purpose is to focus the first widget (from left) inside the container 
39  * regardless of where the focus is coming from.
40  */
41 gboolean G_GNUC_INTERNAL
42 hildon_private_composite_focus                  (GtkWidget *widget, 
43                                                  GtkDirectionType direction)
44 {
45     GtkWidget *toplevel = NULL;
46     GtkWidget *focus_widget = NULL;
47
48     /* Get the topmost parent widget */  
49     toplevel = gtk_widget_get_toplevel (widget);
50
51     if (! GTK_IS_WINDOW (toplevel))
52         return GTK_WIDGET_CLASS (g_type_class_peek_parent (
53                     GTK_WIDGET_GET_CLASS (widget)))->focus (widget, direction);
54     /* Get focus widget in the topmost parent widget */
55     focus_widget = GTK_WINDOW (toplevel)->focus_widget;
56
57     if (! GTK_IS_WIDGET (focus_widget))
58         return TRUE;
59
60     if (! gtk_widget_is_ancestor (focus_widget, widget))
61     {
62         gtk_widget_grab_focus (widget);
63     }
64     else
65     {
66         /* Containers grab_focus grabs the focus to the correct widget */
67         switch (direction) {
68             case GTK_DIR_UP:
69             case GTK_DIR_DOWN:
70                 if (HILDON_IS_DATE_EDITOR (widget) || HILDON_IS_TIME_EDITOR(widget))
71                     return FALSE;
72                 else
73                     return GTK_WIDGET_CLASS (g_type_class_peek_parent
74                             (GTK_WIDGET_GET_CLASS(widget)))->focus (widget, direction);
75                 break;
76
77             default:
78                 return GTK_WIDGET_CLASS (g_type_class_peek_parent
79                         (GTK_WIDGET_GET_CLASS(widget)))->focus (widget, direction);
80                 break;
81         }
82     }
83
84     return TRUE;
85 }
86
87