Skip to content

Commit

Permalink
[WIP][GTK3] Initial hildon-gtk-module
Browse files Browse the repository at this point in the history
Adds initial support for some hildon-gtk specific features (based on the work of freemangordon)
Existing components have some modifications to bring back support for some of these features.

Build Instructions:

To be able to run tests during the build, the *full path* to the created module needs to be present.
There is probably a much better way to do this but for now this works. -d might be needed if control is
still broken :)

GTK_MODULES=/path/to/build/dir/hildon/.libs/libhildon-gtk-3.so  dpkg-buildpackage -rfakeroot -us -uc -b

Initial versions of:
hildon-gtk-entry
hildon-gtk-marshalers
hildon-gtk-textview
hildon-gtk-treeview
hildon-gtk-widget
  • Loading branch information
android-808 committed Mar 2, 2017
1 parent a62f7e0 commit 88586af
Show file tree
Hide file tree
Showing 19 changed files with 1,973 additions and 40 deletions.
8 changes: 6 additions & 2 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ AC_SUBST(GTK_LIBS)
AC_SUBST(GTK_CFLAGS)
AC_SUBST(GTK_VERSION)

PKG_CHECK_MODULES(X11, x11)
AC_SUBST(X11_LIBS)
AC_SUBST(X11_CFLAGS)

# libcanberra is needed for the hildon-note sounds.

PKG_CHECK_MODULES(CANBERRA, libcanberra)
Expand Down Expand Up @@ -209,8 +213,8 @@ AC_SUBST(EXTRA_CFLAGS)
# default vars for the examples
# includes all the low-level flags
# FIXME Add esd and gconf flags
HILDON_OBJ_CFLAGS="\$(CFLAGS) \$(GTK_CFLAGS) \$(CHECK_CFLAGS) \$(GCONF_CFLAGS) -I\$(top_builddir)/hildon/"
HILDON_OBJ_LIBS="\$(top_builddir)/hildon/libhildon-\$(API_VERSION_MAJOR).la \$(GTK_LIBS) \$(GCONF_LIBS) \$(CHECK_LIBS) `pkg-config --libs gthread-2.0`"
HILDON_OBJ_CFLAGS="\$(CFLAGS) \$(GTK_CFLAGS) \$(X11_CFLAGS) \$(CHECK_CFLAGS) \$(GCONF_CFLAGS) -I\$(top_builddir)/hildon/"
HILDON_OBJ_LIBS="\$(top_builddir)/hildon/libhildon-\$(API_VERSION_MAJOR).la \$(top_builddir)/hildon/libhildon-gtk-\$(API_VERSION_MAJOR).la \$(GTK_LIBS) \$(X11_LIBS) \$(GCONF_LIBS) \$(CHECK_LIBS) `pkg-config --libs gthread-2.0`"
AC_SUBST(HILDON_OBJ_CFLAGS)
AC_SUBST(HILDON_OBJ_LIBS)

Expand Down
37 changes: 35 additions & 2 deletions hildon/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,40 @@ CLEANFILES = \

EXTRA_DIST = hildon-marshalers.list

lib_LTLIBRARIES = libhildon-@API_VERSION_MAJOR@.la
lib_LTLIBRARIES = libhildon-gtk-@API_VERSION_MAJOR@.la libhildon-@API_VERSION_MAJOR@.la

libhildon_gtk_@API_VERSION_MAJOR@_la_LDFLAGS = $(HILDON_WIDGETS_LT_LDFLAGS)

libhildon_gtk_@API_VERSION_MAJOR@_la_LIBADD = \
$(GTK_LIBS) \
$(GCONF_LIBS) \
$(X11_LIBS) \
@HILDON_LT_LDFLAGS@

libhildon_gtk_@API_VERSION_MAJOR@_la_CFLAGS = \
$(GTK_CFLAGS) \
$(GCONF_CFLAGS) \
$(EXTRA_CFLAGS)

libhildon_gtk_@API_VERSION_MAJOR@_la_SOURCES = \
hildon-gtk-module.c \
hildon-gtk-widget.c \
hildon-gtk-entry.c \
hildon-gtk-textview.c \
hildon-gtk-treeview.c \
hildon-gtk-marshalers.c

libhildon_gtk_@API_VERSION_MAJOR@_includedir = \
$(includedir)/$(PACKAGE)-$(API_VERSION_MAJOR)/$(PACKAGE)

libhildon_@API_VERSION_MAJOR@_la_LDFLAGS = $(HILDON_WIDGETS_LT_LDFLAGS)

libhildon_@API_VERSION_MAJOR@_la_LIBADD = \
$(GTK_LIBS) \
$(GCONF_LIBS) \
$(CANBERRA_LIBS) \
@HILDON_LT_LDFLAGS@
@HILDON_LT_LDFLAGS@ \
libhildon-gtk-@API_VERSION_MAJOR@.la

libhildon_@API_VERSION_MAJOR@_la_CFLAGS = \
$(GTK_CFLAGS) \
Expand Down Expand Up @@ -236,3 +261,11 @@ hildon-marshalers.c: hildon-marshalers.list hildon-marshalers.h
echo '#include "hildon-marshalers.h"' >hildon-marshalers.c
glib-genmarshal --prefix _hildon_marshal --body hildon-marshalers.list >>hildon-marshalers.c

$(libhildon_gtk_$(API_VERSION_MAJOR)_la_OBJECTS): hildon-enum-types.h hildon-gtk-marshalers.c hildon-gtk-marshalers.h

hildon-gtk-marshalers.h: hildon-gtk-marshalers.list
glib-genmarshal --prefix _hildon_gtk_marshal --header hildon-gtk-marshalers.list >hildon-gtk-marshalers.h

hildon-gtk-marshalers.c: hildon-gtk-marshalers.list hildon-gtk-marshalers.h
echo '#include "hildon-gtk-marshalers.h"' >hildon-gtk-marshalers.c
glib-genmarshal --prefix _hildon_gtk_marshal --body hildon-gtk-marshalers.list >>hildon-gtk-marshalers.c
5 changes: 3 additions & 2 deletions hildon/hildon-entry.c
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
#undef HILDON_DISABLE_DEPRECATED

#include "hildon-entry.h"
#include "hildon-enum-types.h"

G_DEFINE_TYPE (HildonEntry, hildon_entry, GTK_TYPE_ENTRY);

Expand Down Expand Up @@ -131,14 +132,14 @@ hildon_entry_get_text (HildonEntry *entry)
*
* Since: 2.2
*
* Deprecated: Use hildon_gtk_entry_set_placeholder_text() instead
* Deprecated: Use gtk_entry_set_placeholder_text() instead
*/
void
hildon_entry_set_placeholder (HildonEntry *entry,
const gchar *text)
{
g_return_if_fail (HILDON_IS_ENTRY (entry) && text != NULL);
hildon_gtk_entry_set_placeholder_text (GTK_ENTRY (entry), text);
gtk_entry_set_placeholder_text (GTK_ENTRY (entry), text);
}

/**
Expand Down
291 changes: 291 additions & 0 deletions hildon/hildon-gtk-entry.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,291 @@
#include "hildon-gtk.h"
#include "hildon-gtk-entry.h"
#include "hildon-enum-types.h"

#include <gtk/gtk.h>

#include <string.h>

#include <libintl.h>

#ifdef ENABLE_NLS
#define P_(String) g_dgettext("hildon-libs-properties",String)
#else
#define P_(String) (String)
#endif

// Define to remain compatible with fremantle-gtk2 source:
#define GTK_PARAM_READABLE G_PARAM_READABLE|G_PARAM_STATIC_NAME|G_PARAM_STATIC_NICK|G_PARAM_STATIC_BLURB
#define GTK_PARAM_WRITABLE G_PARAM_WRITABLE|G_PARAM_STATIC_NAME|G_PARAM_STATIC_NICK|G_PARAM_STATIC_BLURB
#define GTK_PARAM_READWRITE G_PARAM_READWRITE|G_PARAM_STATIC_NAME|G_PARAM_STATIC_NICK|G_PARAM_STATIC_BLURB

enum {
PROP_HILDON_PLACEHOLDER_TEXT = 43 /* PROP_EDITING_CANCELED + 1 */,
PROP_HILDON_INPUT_MODE,
PROP_HILDON_INPUT_DEFAULT
};

/**
* hildon_gtk_entry_set_placeholder_text:
* @entry: a #GtkEntry
* @placeholder_text: a string to be displayed when @entry is empty
* and unfocused or %NULL to remove current placeholder text.
*
* Sets a text string to be displayed when @entry is empty and unfocused.
* This can be provided to give a visual hint of the expected contents
* of the #GtkEntry.
*
* Since: maemo 5
**/
void
hildon_gtk_entry_set_placeholder_text (GtkEntry *entry,
const gchar *placeholder_text)
{
g_return_if_fail (GTK_IS_ENTRY (entry));

gtk_entry_set_placeholder_text (entry, placeholder_text);

g_object_notify (G_OBJECT (entry), "hildon-placeholder-text");
}

/**
* hildon_gtk_entry_get_placeholder_text:
* @entry: a #GtkEntry
*
* Gets the text to be displayed if @entry is empty and unfocused.
*
* Returns: a string or %NULL if no placeholder text is set
*
* Since: maemo 5
**/
const gchar *
hildon_gtk_entry_get_placeholder_text (GtkEntry *entry)
{
g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);

return gtk_entry_get_placeholder_text (entry);
}

void
hildon_gtk_entry_set_input_mode (GtkEntry *entry,
HildonGtkInputMode mode)
{
g_return_if_fail (GTK_IS_ENTRY (entry));

if (hildon_gtk_entry_get_input_mode (entry) != mode)
{
gtk_entry_set_visibility (entry,
mode & HILDON_GTK_INPUT_MODE_INVISIBLE
? FALSE : TRUE);
// g_object_set (G_OBJECT (entry->im_context),
// "hildon-input-mode", mode, NULL);
g_object_notify (G_OBJECT (entry), "hildon-input-mode");
}
}

HildonGtkInputMode
hildon_gtk_entry_get_input_mode (GtkEntry *entry)
{
HildonGtkInputMode mode;

g_return_val_if_fail (GTK_IS_ENTRY (entry), FALSE);

// g_object_get (G_OBJECT (entry->im_context),
// "hildon-input-mode", &mode, NULL);

return mode;
}

/**
* hildon_gtk_entry_set_input_default:
* @entry: a #GtkEntry
* @mode: a #HildonGtkInputMode
*
* Sets the default input mode of the widget.
*
* Since: maemo 5.0
*/
void
hildon_gtk_entry_set_input_default (GtkEntry *entry,
HildonGtkInputMode mode)
{
g_return_if_fail (GTK_IS_ENTRY (entry));

if (hildon_gtk_entry_get_input_default (entry) != mode)
{
// g_object_set (G_OBJECT (entry->im_context),
// "hildon-input-default", mode, NULL);
g_object_notify (G_OBJECT (entry), "hildon-input-default");
}
}

/**
* hildon_gtk_entry_get_input_default:
* @entry: a #GtkEntry
*
* Gets the default input mode of the widget.
*
* Return value: the default input mode of the widget.
*
* Since: maemo 5.0
*/
HildonGtkInputMode
hildon_gtk_entry_get_input_default (GtkEntry *entry)
{
HildonGtkInputMode mode;

g_return_val_if_fail (GTK_IS_ENTRY (entry), FALSE);

// g_object_get (G_OBJECT (entry->im_context),
// "hildon-input-default", &mode, NULL);

return mode;
}


static void (*old_gtk_entry_set_property)(GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec);
static void (*old_gtk_entry_get_property)(GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec);

static void
hildon_gtk_entry_set_property (GObject *object,
guint prop_id,
const GValue *value,
GParamSpec *pspec)
{
GtkEntry *entry = GTK_ENTRY (object);

if (!strcmp(pspec->name, "visibility"))
{
/* converting to hildon input mode first then through
* that mode changing function to reach compatible with
* the gtk original visibility changing
*/
HildonGtkInputMode mode = hildon_gtk_entry_get_input_mode (entry);

if (g_value_get_boolean (value))
mode &= ~HILDON_GTK_INPUT_MODE_INVISIBLE;
else
mode |= HILDON_GTK_INPUT_MODE_INVISIBLE;

hildon_gtk_entry_set_input_mode (entry, mode);

return;
}

switch (prop_id)
{
case PROP_HILDON_PLACEHOLDER_TEXT:
hildon_gtk_entry_set_placeholder_text (entry, g_value_get_string (value));
break;

case PROP_HILDON_INPUT_MODE:
hildon_gtk_entry_set_input_mode (entry, g_value_get_flags (value));
break;

case PROP_HILDON_INPUT_DEFAULT:
hildon_gtk_entry_set_input_default (entry, g_value_get_flags (value));
break;
default:
old_gtk_entry_set_property(object, prop_id, value, pspec);
break;
}
}

static void
hildon_gtk_entry_get_property (GObject *object,
guint prop_id,
GValue *value,
GParamSpec *pspec)
{
GtkEntry *entry = GTK_ENTRY (object);

switch (prop_id)
{
case PROP_HILDON_PLACEHOLDER_TEXT:
g_value_set_string (value, hildon_gtk_entry_get_placeholder_text (entry));
break;

case PROP_HILDON_INPUT_MODE:
g_value_set_flags (value, hildon_gtk_entry_get_input_mode (entry));
break;

case PROP_HILDON_INPUT_DEFAULT:
g_value_set_flags (value, hildon_gtk_entry_get_input_default (entry));
break;
default:
old_gtk_entry_get_property (object, prop_id, value, pspec);
break;
}
}

void
hildon_subclass_gtk_entry(void)
{
GObjectClass *gobject_class;
GtkEntryClass *entry_class;
GtkEntry *entry;
g_warning("hildon_subclass_gtk_entry");

entry = GTK_ENTRY(gtk_entry_new());
entry_class = GTK_ENTRY_GET_CLASS(entry);
gobject_class = G_OBJECT_CLASS(entry_class);

old_gtk_entry_set_property = gobject_class->set_property;
old_gtk_entry_get_property = gobject_class->get_property;
gobject_class->set_property = hildon_gtk_entry_set_property;
gobject_class->get_property = hildon_gtk_entry_get_property;

/**
* GtkEntry:hildon-placeholder-text:
*
* Text to be displayed in the #GtkEntry when it is empty.
*
* Since: maemo 5
*/
g_object_class_install_property (gobject_class,
PROP_HILDON_PLACEHOLDER_TEXT,
g_param_spec_string ("hildon-placeholder-text",
P_("Hildon Placeholder text"),
P_("Text to be displayed when the entry is empty"),
"",
G_PARAM_READWRITE));

/**
* GtkEntry:hildon-input-mode:
*
* Allowed characters and input mode for the entry. See #HildonGtkInputMode.
*
* Since: maemo 2.0
* Stability: Unstable
**/
g_object_class_install_property (gobject_class,
PROP_HILDON_INPUT_MODE,
g_param_spec_flags ("hildon-input-mode",
P_("Hildon input mode"),
P_("Define widget's input mode"),
HILDON_TYPE_GTK_INPUT_MODE,
HILDON_GTK_INPUT_MODE_FULL |
HILDON_GTK_INPUT_MODE_AUTOCAP |
HILDON_GTK_INPUT_MODE_DICTIONARY,
GTK_PARAM_READWRITE | G_PARAM_CONSTRUCT));

/**
* GtkEntry:hildon-input-default:
*
* Default input mode for this IM context. See #HildonGtkInputMode.
* The default setting for this property is %HILDON_GTK_INPUT_MODE_FULL,
* which means that the default input mode to be used is up to the
* implementation of the IM context.
*
* Since: maemo 5
**/
g_object_class_install_property (gobject_class,
PROP_HILDON_INPUT_DEFAULT,
g_param_spec_flags ("hildon-input-default",
P_("Hildon input default"),
P_("Define widget's default input mode"),
HILDON_TYPE_GTK_INPUT_MODE,
HILDON_GTK_INPUT_MODE_FULL,
GTK_PARAM_READWRITE | G_PARAM_CONSTRUCT));
}

Loading

0 comments on commit 88586af

Please sign in to comment.