~timo-jyrinki/ubuntu/trusty/maliit-framework/fix_qt52

« back to all changes in this revision

Viewing changes to examples/apps/gtk2/exampleapp-gtk.c

  • Committer: Package Import Robot
  • Author(s): Ricardo Salveti de Araujo, Sergio Schvezov, Ricardo Salveti de Araujo
  • Date: 2013-07-23 19:47:04 UTC
  • mfrom: (1.1.2) (1.2.1 experimental)
  • Revision ID: package-import@ubuntu.com-20130723194704-1lsy1kmlda069cea
Tags: 0.99.0+git20130615+97e8335-0ubuntu1
[ Sergio Schvezov ]
* New build from HEAD 97e8335.
* Packaging import from lp:phablet-extras/maliit-framework.

[ Ricardo Salveti de Araujo ]
* debian/control: adding vcs and fixing dependencies
* General package cleanup

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* * This file is part of Maliit framework *
2
 
 *
3
 
 * Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
4
 
 * All rights reserved.
5
 
 *
6
 
 * Contact: maliit-discuss@lists.maliit.org
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
10
 
 * License version 2.1 as published by the Free Software Foundation
11
 
 * and appearing in the file LICENSE.LGPL included in the packaging
12
 
 * of this file.
13
 
 */
14
 
 
15
 
#include <gtk/gtk.h>
16
 
 
17
 
#include <maliit-glib/maliitinputmethod.h>
18
 
 
19
 
static void
20
 
show_button_clicked(GtkButton *button G_GNUC_UNUSED,
21
 
                    gpointer user_data)
22
 
{
23
 
    MaliitInputMethod *input_method = MALIIT_INPUT_METHOD(user_data);
24
 
 
25
 
    maliit_input_method_show(input_method);
26
 
}
27
 
 
28
 
static void
29
 
hide_button_clicked(GtkButton *button G_GNUC_UNUSED,
30
 
                    gpointer user_data)
31
 
{
32
 
    MaliitInputMethod *input_method = MALIIT_INPUT_METHOD(user_data);
33
 
 
34
 
    maliit_input_method_hide(input_method);
35
 
}
36
 
 
37
 
static void
38
 
input_method_area_changed(MaliitInputMethod *input_method G_GNUC_UNUSED,
39
 
                          int x, int y, int width, int height,
40
 
                          gpointer user_data)
41
 
{
42
 
    GtkLabel *label = GTK_LABEL(user_data);
43
 
    gchar *formatted_string;
44
 
 
45
 
    if (width == 0 || height == 0)
46
 
        formatted_string = g_strdup("Empty Input Method area");
47
 
    else
48
 
        formatted_string = g_strdup_printf("Input Method area: [%d, %d, %d, %d]", x, y, width, height);
49
 
 
50
 
    gtk_label_set_text(label, formatted_string);
51
 
 
52
 
    g_free(formatted_string);
53
 
}
54
 
 
55
 
gint
56
 
main(gint    argc,
57
 
     gchar **argv)
58
 
{
59
 
    GtkWidget *window, *vbox;
60
 
    GtkWidget *show_button, *hide_button, *entry, *text_view, *label;
61
 
    MaliitInputMethod *input_method;
62
 
 
63
 
    gtk_init(&argc, &argv);
64
 
 
65
 
    window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
66
 
    gtk_window_set_title(GTK_WINDOW(window), "Maliit GTK+ example");
67
 
 
68
 
    input_method = maliit_input_method_new();
69
 
 
70
 
    show_button = gtk_button_new_with_label("Show keyboard");
71
 
    g_signal_connect(show_button, "clicked",
72
 
                     G_CALLBACK(show_button_clicked), input_method);
73
 
    hide_button = gtk_button_new_with_label("Hide keyboard");
74
 
    g_signal_connect(hide_button, "clicked",
75
 
                     G_CALLBACK(hide_button_clicked), input_method);
76
 
    entry = gtk_entry_new();
77
 
    text_view = gtk_text_view_new();
78
 
    gtk_widget_set_size_request(text_view, 150, 200);
79
 
 
80
 
    label = gtk_label_new("Empty Input Method area");
81
 
    g_signal_connect(input_method, "area-changed",
82
 
                     G_CALLBACK(input_method_area_changed), label);
83
 
 
84
 
#if GTK_MAJOR_VERSION >= 3
85
 
    vbox = gtk_box_new(GTK_ORIENTATION_VERTICAL, 10);
86
 
#else
87
 
    vbox = gtk_vbox_new(FALSE, 10);
88
 
#endif
89
 
 
90
 
    gtk_box_pack_start(GTK_BOX(vbox), show_button, FALSE, FALSE, 0);
91
 
    gtk_box_pack_start(GTK_BOX(vbox), hide_button, FALSE, FALSE, 0);
92
 
    gtk_box_pack_start(GTK_BOX(vbox), entry, FALSE, FALSE, 0);
93
 
    gtk_box_pack_start(GTK_BOX(vbox), text_view, TRUE, TRUE, 0); /* Expands */
94
 
    gtk_box_pack_start(GTK_BOX(vbox), label, FALSE, FALSE, 0);
95
 
    gtk_container_add(GTK_CONTAINER(window), vbox);
96
 
 
97
 
    g_signal_connect(G_OBJECT(window), "delete-event",
98
 
                     G_CALLBACK(gtk_main_quit), window);
99
 
    gtk_widget_show_all(window);
100
 
 
101
 
    gtk_main();
102
 
 
103
 
    g_object_unref(input_method);
104
 
 
105
 
    return 0;
106
 
}