From 4ba14a566d78d5917da51a7da4b17e318edb3d6e Mon Sep 17 00:00:00 2001 From: Alberto Garcia Date: Thu, 7 Aug 2008 22:44:03 +0000 Subject: [PATCH] 2008-08-08 Alberto Garcia * doc/hildon-docs.sgml * src/Makefile.am * src/hildon.h * src/hildon-gtk.h * src/hildon-gtk.c: Convenience functions for standard Gtk widgets, used to easily perform frequent operations. * src/hildon-button-helpers.h * src/hildon-button-helpers.c: Removed in favour of hildon-gtk.[ch] * src/hildon-helper.h * src/hildon-helper.c (hildon_helper_set_theme_size): Renamed to hildon_gtk_widget_set_theme_size and moved to hildon-gtk.h * src/hildon-button.h * src/hildon-button.c: Use the new hildon-gtk.[ch] functions. --- ChangeLog | 19 ++++ doc/hildon-docs.sgml | 1 + src/Makefile.am | 4 +- src/hildon-button-helpers.c | 25 ----- src/hildon-button-helpers.h | 30 ------ src/hildon-button.c | 2 +- src/hildon-button.h | 3 +- src/hildon-gtk.c | 229 +++++++++++++++++++++++++++++++++++++++++++ src/hildon-gtk.h | 71 ++++++++++++++ src/hildon-helper.c | 43 -------- src/hildon-helper.h | 14 --- src/hildon.h | 2 +- 12 files changed, 325 insertions(+), 118 deletions(-) delete mode 100644 src/hildon-button-helpers.c delete mode 100644 src/hildon-button-helpers.h create mode 100644 src/hildon-gtk.c create mode 100644 src/hildon-gtk.h diff --git a/ChangeLog b/ChangeLog index f5941f5..07e20fd 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,22 @@ +2008-08-08 Alberto Garcia + + * doc/hildon-docs.sgml + * src/Makefile.am + * src/hildon.h + * src/hildon-gtk.h + * src/hildon-gtk.c: Convenience functions for standard Gtk + widgets, used to easily perform frequent operations. + + * src/hildon-button-helpers.h + * src/hildon-button-helpers.c: Removed in favour of hildon-gtk.[ch] + + * src/hildon-helper.h + * src/hildon-helper.c (hildon_helper_set_theme_size): Renamed to + hildon_gtk_widget_set_theme_size and moved to hildon-gtk.h + + * src/hildon-button.h + * src/hildon-button.c: Use the new hildon-gtk.[ch] functions. + 2008-08-07 Alberto Garcia * src/hildon-button.c (hildon_button_init) diff --git a/doc/hildon-docs.sgml b/doc/hildon-docs.sgml index 606db42..441ced2 100644 --- a/doc/hildon-docs.sgml +++ b/doc/hildon-docs.sgml @@ -88,6 +88,7 @@ Other + diff --git a/src/Makefile.am b/src/Makefile.am index 8b0f779..0a1a780 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -77,7 +77,7 @@ libhildon_@API_VERSION_MAJOR@_la_SOURCES = \ hildon-bread-crumb-widget.c \ hildon-app-menu.c \ hildon-button.c \ - hildon-button-helpers.c \ + hildon-gtk.c \ hildon-dialog.c libhildon_@API_VERSION_MAJOR@_built_public_headers = \ @@ -137,7 +137,7 @@ libhildon_@API_VERSION_MAJOR@_public_headers = \ hildon-app-menu.h \ hildon-dialog.h \ hildon-button.h \ - hildon-button-helpers.h \ + hildon-gtk.h \ hildon-version.h libhildon_@API_VERSION_MAJOR@_include_HEADERS = \ diff --git a/src/hildon-button-helpers.c b/src/hildon-button-helpers.c deleted file mode 100644 index 4bac7b4..0000000 --- a/src/hildon-button-helpers.c +++ /dev/null @@ -1,25 +0,0 @@ -/* - * This file is a part of hildon - * - * Copyright (C) 2008 Nokia Corporation, all rights reserved. - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU Lesser Public License as published by - * the Free Software Foundation; version 2 of the license. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser Public License for more details. - * - */ - -#include "hildon-button-helpers.h" - -GtkWidget * -hildon_gtk_button_new (HildonSizeType size) -{ - GtkWidget *button = gtk_button_new (); - hildon_helper_set_theme_size (button, size); - return button; -} diff --git a/src/hildon-button-helpers.h b/src/hildon-button-helpers.h deleted file mode 100644 index e9344bf..0000000 --- a/src/hildon-button-helpers.h +++ /dev/null @@ -1,30 +0,0 @@ -/* - * This file is a part of hildon - * - * Copyright (C) 2008 Nokia Corporation, all rights reserved. - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU Lesser Public License as published by - * the Free Software Foundation; version 2 of the license. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser Public License for more details. - * - */ - -#ifndef __HILDON_BUTTON_HELPERS_H__ -#define __HILDON_BUTTON_HELPERS_H__ - -#include -#include "hildon-helper.h" - -G_BEGIN_DECLS - -GtkWidget * -hildon_gtk_button_new (HildonSizeType size); - -G_END_DECLS - -#endif /* __HILDON_BUTTON_HELPERS_H__ */ diff --git a/src/hildon-button.c b/src/hildon-button.c index 36ebdd9..f63b024 100644 --- a/src/hildon-button.c +++ b/src/hildon-button.c @@ -87,7 +87,7 @@ hildon_button_set_property (GObject *object, hildon_button_set_value (button, g_value_get_string (value)); break; case PROP_SIZE: - hildon_helper_set_theme_size (GTK_WIDGET (button), g_value_get_flags (value)); + hildon_gtk_widget_set_theme_size (GTK_WIDGET (button), g_value_get_flags (value)); break; case PROP_ARRANGEMENT: hildon_button_set_arrangement (button, g_value_get_enum (value)); diff --git a/src/hildon-button.h b/src/hildon-button.h index 4ed3693..eaf8ea1 100644 --- a/src/hildon-button.h +++ b/src/hildon-button.h @@ -19,8 +19,7 @@ #ifndef __HILDON_BUTTON_H__ #define __HILDON_BUTTON_H__ -#include -#include "hildon-helper.h" +#include "hildon-gtk.h" G_BEGIN_DECLS diff --git a/src/hildon-gtk.c b/src/hildon-gtk.c new file mode 100644 index 0000000..fa2cacb --- /dev/null +++ b/src/hildon-gtk.c @@ -0,0 +1,229 @@ +/* + * This file is a part of hildon + * + * Copyright (C) 2008 Nokia Corporation, all rights reserved. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU Lesser Public License as published by + * the Free Software Foundation; version 2 of the license. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser Public License for more details. + * + */ + +/** + * SECTION:hildon-gtk + * @short_description: Additional functions for Gtk widgets + * + * Hildon provides some functions to extend the functionality of + * existing Gtk widgets. This also includes convenience functions to + * easily perform frequent tasks. + */ + +#include "hildon-gtk.h" + +#define HILDON_HEIGHT_FINGER 70 + +#define HILDON_HEIGHT_THUMB 105 + +#define HILDON_WIDTH_FULLSCREEN \ + (gdk_screen_get_width (gdk_screen_get_default ())) + +#define HILDON_WIDTH_HALFSCREEN \ + (HILDON_WIDTH_FULLSCREEN / 2) + +/** + * hildon_gtk_widget_set_theme_size + * @widget: A #GtkWidget + * @size: Flags indicating the size of the widget + * + * This function sets the requested size of a widget. + **/ +void +hildon_gtk_widget_set_theme_size (GtkWidget *widget, + HildonSizeType size) +{ + gint width = -1; + gint height = -1; + const gchar *widget_name = NULL; + + g_return_if_fail (GTK_IS_WIDGET (widget)); + + /* Requested height */ + if (size & HILDON_SIZE_FINGER_HEIGHT) { + height = HILDON_HEIGHT_FINGER; + widget_name = "hildon-finger-widget"; + } else if (size & HILDON_SIZE_THUMB_HEIGHT) { + height = HILDON_HEIGHT_THUMB; + widget_name = "hildon-thumb-widget"; + } + + /* Requested width */ + if (size & HILDON_SIZE_HALFSCREEN_WIDTH) { + width = HILDON_WIDTH_HALFSCREEN; + } else if (size & HILDON_SIZE_FULLSCREEN_WIDTH) { + width = HILDON_WIDTH_FULLSCREEN; + } + + gtk_widget_set_size_request (widget, width, height); + + if (widget_name) + gtk_widget_set_name (widget, widget_name); +} + +/** + * hildon_gtk_button_new: + * @size: Flags indicating the size of the new button + * + * This is a convenience function to create a #GtkButton setting its + * size to one of the pre-defined Hildon sizes. + * + * Return value: A newly created #GtkButton widget. + **/ +GtkWidget * +hildon_gtk_button_new (HildonSizeType size) +{ + GtkWidget *button = gtk_button_new (); + hildon_gtk_widget_set_theme_size (button, size); + return button; +} + +/** + * hildon_gtk_toggle_button_new: + * @size: Flags indicating the size of the new button + * + * This is a convenience function to create a #GtkToggleButton setting + * its size to one of the pre-defined Hildon sizes. + * + * Return value: A newly created #GtkToggleButton widget. + **/ +GtkWidget * +hildon_gtk_toggle_button_new (HildonSizeType size) +{ + GtkWidget *button = gtk_toggle_button_new (); + hildon_gtk_widget_set_theme_size (button, size); + return button; +} + +/** + * hildon_gtk_check_button_new: + * @size: Flags indicating the size of the new button + * + * This is a convenience function to create a #GtkCheckButton setting + * its size to one of the pre-defined Hildon sizes. + * + * Return value: A newly created #GtkCheckButton widget. + **/ +GtkWidget * +hildon_gtk_check_button_new (HildonSizeType size) +{ + GtkWidget *button = gtk_check_button_new (); + hildon_gtk_widget_set_theme_size (button, size); + return button; +} + +/** + * hildon_gtk_radio_button_new: + * @size: Flags indicating the size of the new button + * @group: An existing radio button group, or %NULL if you are + * creating a new group + * + * This is a convenience function to create a #GtkRadioButton setting + * its size to one of the pre-defined Hildon sizes. + * + * Return value: A newly created #GtkRadioButton widget. + **/ +GtkWidget * +hildon_gtk_radio_button_new (HildonSizeType size, + GSList *group) +{ + GtkWidget *button = gtk_radio_button_new (group); + hildon_gtk_widget_set_theme_size (button, size); + return button; +} + +/** + * hildon_gtk_radio_button_new_from_widget: + * @size: Flags indicating the size of the new button + * @radio_group_member: widget to get radio group from or %NULL + * + * This is a convenience function to create a #GtkRadioButton setting + * its size to one of the pre-defined Hildon sizes. + * + * Return value: A newly created #GtkRadioButton widget. + **/ +GtkWidget * +hildon_gtk_radio_button_new_from_widget (HildonSizeType size, + GtkRadioButton *radio_group_member) +{ + GtkWidget *button = gtk_radio_button_new_from_widget (radio_group_member); + hildon_gtk_widget_set_theme_size (button, size); + return button; +} + +/** + * hildon_gtk_tree_view_new: + * @mode: the Hildon UI mode + * + * Creates a new #GtkTreeView widget with the Hildon UI mode set to + * @mode + * + * Return value: A newly created #GtkTreeView widget. + **/ +GtkWidget * +hildon_gtk_tree_view_new (HildonUIMode mode) +{ + return g_object_new (GTK_TYPE_TREE_VIEW, "hildon-ui-mode", mode, NULL); +} + +/** + * hildon_gtk_tree_view_new_with_model: + * @mode: the Hildon UI mode + * @model: the model. + * + * Creates a new #GtkTreeView widget with the Hildon UI mode set to + * @mode and the model initialized to @model. + * + * Return value: A newly created #GtkTreeView widget. + **/ +GtkWidget * +hildon_gtk_tree_view_new_with_model (HildonUIMode mode, + GtkTreeModel *model) +{ + return g_object_new (GTK_TYPE_TREE_VIEW, "hildon-ui-mode", mode, "model", model, NULL); +} + +/** + * hildon_gtk_icon_view_new: + * @mode: the Hildon UI mode + * + * Creates a new #GtkIconView widget with the Hildon UI mode set to + * @mode + * + * Return value: A newly created #GtkIconView widget + **/ +GtkWidget * +hildon_gtk_icon_view_new (HildonUIMode mode) +{ + return g_object_new (GTK_TYPE_ICON_VIEW, "hildon-ui-mode", mode, NULL); +} + +/** + * hildon_gtk_icon_view_new_with_model: + * @mode: the Hildon UI mode + * @model: The model. + * + * Creates a new #GtkIconView widget with the Hildon UI mode set to + * @mode and the model intitialized to @model. + * + * Return value: A newly created #GtkIconView widget. + **/ +GtkWidget * +hildon_gtk_icon_view_new_with_model (HildonUIMode mode, + GtkTreeModel *model) +{ + return g_object_new (GTK_TYPE_ICON_VIEW, "hildon-ui-mode", mode, "model", model, NULL); +} diff --git a/src/hildon-gtk.h b/src/hildon-gtk.h new file mode 100644 index 0000000..a506794 --- /dev/null +++ b/src/hildon-gtk.h @@ -0,0 +1,71 @@ +/* + * This file is a part of hildon + * + * Copyright (C) 2008 Nokia Corporation, all rights reserved. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU Lesser Public License as published by + * the Free Software Foundation; version 2 of the license. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser Public License for more details. + * + */ + +#ifndef __HILDON_GTK_H__ +#define __HILDON_GTK_H__ + +#include + +G_BEGIN_DECLS + +typedef enum { + HILDON_SIZE_AUTO_WIDTH = 0 << 0, /* set to automatic width */ + HILDON_SIZE_HALFSCREEN_WIDTH = 1 << 0, /* set to 50% screen width */ + HILDON_SIZE_FULLSCREEN_WIDTH = 2 << 0, /* set to 100% screen width */ + HILDON_SIZE_AUTO_HEIGHT = 0 << 2, /* set to automatic height */ + HILDON_SIZE_FINGER_HEIGHT = 1 << 2, /* set to finger height */ + HILDON_SIZE_THUMB_HEIGHT = 2 << 2, /* set to thumb height */ + HILDON_SIZE_AUTO = (HILDON_SIZE_AUTO_WIDTH | HILDON_SIZE_AUTO_HEIGHT) +} HildonSizeType; + +void +hildon_gtk_widget_set_theme_size (GtkWidget *widget, + HildonSizeType size); + +GtkWidget * +hildon_gtk_button_new (HildonSizeType size); + +GtkWidget * +hildon_gtk_toggle_button_new (HildonSizeType size); + +GtkWidget * +hildon_gtk_check_button_new (HildonSizeType size); + +GtkWidget * +hildon_gtk_radio_button_new (HildonSizeType size, + GSList *group); + +GtkWidget * +hildon_gtk_radio_button_new_from_widget (HildonSizeType size, + GtkRadioButton *radio_group_member); + +GtkWidget * +hildon_gtk_tree_view_new (HildonUIMode mode); + +GtkWidget * +hildon_gtk_tree_view_new_with_model (HildonUIMode mode, + GtkTreeModel *model); + +GtkWidget * +hildon_gtk_icon_view_new (HildonUIMode mode); + +GtkWidget * +hildon_gtk_icon_view_new_with_model (HildonUIMode mode, + GtkTreeModel *model); + +G_END_DECLS + +#endif /* __HILDON_GTK_H__ */ diff --git a/src/hildon-helper.c b/src/hildon-helper.c index a043bc1..0f3608c 100644 --- a/src/hildon-helper.c +++ b/src/hildon-helper.c @@ -40,14 +40,6 @@ #include "hildon-helper.h" #include "hildon-banner.h" -#define HILDON_HEIGHT_FINGER 70 - -#define HILDON_HEIGHT_THUMB 105 - -#define HILDON_WIDTH_FULLSCREEN (gdk_screen_get_width (gdk_screen_get_default ())) - -#define HILDON_WIDTH_HALFSCREEN (HILDON_WIDTH_FULLSCREEN / 2) - #define HILDON_FINGER_PRESSURE_THRESHOLD 0.4 #define HILDON_FINGER_BUTTON 8 @@ -509,41 +501,6 @@ hildon_helper_set_thumb_scrollbar (GtkScrolledWindow *win, gtk_widget_set_name (win->vscrollbar, (thumb) ? "hildon-thumb-scrollbar" : NULL); } -/** - * hildon_helper_set_theme_size - * @widget: A @GtkWidget - * @size: Flags indicating the size of the widget - * - * This function sets the requested size of a widget. - **/ -void -hildon_helper_set_theme_size (GtkWidget *widget, - HildonSizeType size) -{ - gint width = -1; - gint height = -1; - const gchar *widget_name = NULL; - g_return_if_fail (GTK_IS_WIDGET (widget)); - /* Requested height */ - if (size & HILDON_SIZE_FINGER_HEIGHT) { - height = HILDON_HEIGHT_FINGER; - widget_name = "hildon-finger-widget"; - } else if (size & HILDON_SIZE_THUMB_HEIGHT) { - height = HILDON_HEIGHT_THUMB; - widget_name = "hildon-thumb-widget"; - } - /* Requested width */ - if (size & HILDON_SIZE_HALFSCREEN_WIDTH) { - width = HILDON_WIDTH_HALFSCREEN; - } else if (size & HILDON_SIZE_FULLSCREEN_WIDTH) { - width = HILDON_WIDTH_FULLSCREEN; - } - - gtk_widget_set_size_request (widget, width, height); - - if (widget_name) - gtk_widget_set_name (widget, widget_name); -} diff --git a/src/hildon-helper.h b/src/hildon-helper.h index a8d9df1..90a15d3 100644 --- a/src/hildon-helper.h +++ b/src/hildon-helper.h @@ -32,16 +32,6 @@ G_BEGIN_DECLS -typedef enum { - HILDON_SIZE_AUTO_WIDTH = 0 << 0, /* set to automatic width */ - HILDON_SIZE_HALFSCREEN_WIDTH = 1 << 0, /* set to 50% screen width */ - HILDON_SIZE_FULLSCREEN_WIDTH = 2 << 0, /* set to 100% screen width */ - HILDON_SIZE_AUTO_HEIGHT = 0 << 2, /* set to automatic height */ - HILDON_SIZE_FINGER_HEIGHT = 1 << 2, /* set to finger height */ - HILDON_SIZE_THUMB_HEIGHT = 2 << 2, /* set to thumb height */ - HILDON_SIZE_AUTO = (HILDON_SIZE_AUTO_WIDTH | HILDON_SIZE_AUTO_HEIGHT) -} HildonSizeType; - gulong hildon_helper_set_logical_font (GtkWidget *widget, const gchar *logicalfontname); @@ -67,10 +57,6 @@ void hildon_helper_set_thumb_scrollbar (GtkScrolledWindow *win, gboolean thumb); -void -hildon_helper_set_theme_size (GtkWidget *button, - HildonSizeType size); - G_END_DECLS #endif /* __HILDON_HELPER_H__ */ diff --git a/src/hildon.h b/src/hildon.h index 311d8e5..7af7e30 100644 --- a/src/hildon.h +++ b/src/hildon.h @@ -74,7 +74,7 @@ #include "hildon-pannable-area.h" #include "hildon-app-menu.h" #include "hildon-button.h" -#include "hildon-button-helpers.h" +#include "hildon-gtk.h" #include "hildon-dialog.h" #endif -- 1.7.9.5