Re: Visual Keyboard
- From: Emmanuel Gontcho <gontcho gmail com>
- To: Piñeiro <apinheiro igalia com>
- Cc: gtk-list gnome org
- Subject: Re: Visual Keyboard
- Date: Fri, 26 Nov 2010 02:27:01 +0100
My problem was to be able to insert the on-screen keyboard on a Window of my application. No it to be a floating window. I joined source code of the keyboard. When building a new keyboard, pass it a GtkLabel or a GtkEntry as parameter and from it, you'll be able to retreive your text.
2010/11/25 Piñeiro
<apinheiro igalia com>
From: Emmanuel Gontcho <gontcho gmail com>
> Thank you all for your answer,
>
> I have never tried before to write a widget from scratch, nor now,
> cause I have no time, the software must work before 15th december. So
> quickly I made what you can see in the attachment, using one or two
> functions, GtkTable and buttons, I think it is enough for the
> begining.
As it seems that you are creating a widget for your specific project,
I think that it is worth to comment that there are already some
projects that are creating a keyboard on-screen like Caribou [1]
or Onboard.
[1] http://live.gnome.org/Caribou
===
API (apinheiro igalia com)
--
Emmanuel Mbenga Gontcho
!!!!! Gem !!!!!
gontcho.wordpress.comN'utilisez pas Windows 7. Pour savoir pourquoi :
http://windows7sins.org/
Don't use Windows 7. To know why :
http://windows7sins.org/Membre de l'April - « promouvoir et défendre le logiciel libre » -
http://www.april.org
Rejoignez maintenant plus de 2 500 personnes, associations, entreprises et
collectivités qui soutiennent notre action
/**********************************************************************
*This program is free software: you can redistribute it and/or modify *
*it under the terms of the GNU General Public License as published by *
*the Free Software Foundation, either version 3 of the License, or *
*(at your option) any later version. *
* *
*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 General Public License for more details. *
* *
*You should have received a copy of the GNU General Public License *
*along with this program. If not, see <http://www.gnu.org/licenses/>.*
***********************************************************************/
#include <stdlib.h>
#include <string.h>
#include <gtk/gtk.h>
#include "keyboard.h"
void touch_clicked (GtkWidget *button, GtkWidget *label)
{
char *buffer = NULL;
char *labeltext = NULL;
char *buttontext = NULL;
buttontext = (char *) gtk_button_get_label (GTK_BUTTON (button));
if (GTK_IS_LABEL (label) == TRUE)
labeltext = (char *) gtk_label_get_text (GTK_LABEL (label));
if ( GTK_IS_ENTRY (label) == TRUE)
labeltext = (char *) gtk_entry_get_text (GTK_ENTRY (label));
if (strcmp (buttontext, "BSP") == 0)
{
int size;
size = sizeof (char) * strlen (labeltext);
if (size < 1) return;
buffer = malloc (size);
strncpy (buffer, labeltext, size);
strncpy (buffer + (strlen (labeltext) - 1), "\0", 1);
}
else if (strcmp (buttontext, "ESP") == 0)
{
asprintf (&buffer, "%s%s", labeltext ? labeltext : "", " ");
}
else if (strcmp (buttontext, "DEL") == 0)
{
asprintf (&buffer, "%s", "");
}
else
{
asprintf (&buffer, "%s%s", labeltext ? labeltext : "", buttontext);
}
if (GTK_IS_LABEL (label) == TRUE)
gtk_label_set_text (GTK_LABEL (label), buffer);
if ( GTK_IS_ENTRY (label) == TRUE)
gtk_entry_set_text (GTK_ENTRY (label), buffer);
}
GtkWidget *new_keyboard (GtkWidget *label)
{
GtkWidget *board;
GtkWidget *touch;
int i, j, k;
char *lab;
printf ("abount to launch building table\n");
board = gtk_table_new (3, 9, FALSE);
k = 65;
for (i = 0; i < 4; i++)
{
for (j = 0; j < 9; j++)
{
printf ("about to asprint %c\n", k);
asprintf (&lab, "%c", k++);
touch = gtk_button_new_with_label (k == 92 ? "ESP" : k == 93 ? "BSP" : k == 94 ? "DEL" : lab);
gtk_widget_set_size_request (touch, 50, 50);
gtk_table_attach (GTK_TABLE (board), touch, j, j+1, i, i+1, GTK_FILL, GTK_FILL, 2, 2);
g_signal_connect (G_OBJECT (touch), "clicked", G_CALLBACK (touch_clicked), label);
if (k == 94) break;
}
if (k == 94) break;
}
return board;
}
/**********************************************************************
*This program is free software: you can redistribute it and/or modify *
*it under the terms of the GNU General Public License as published by *
*the Free Software Foundation, either version 3 of the License, or *
*(at your option) any later version. *
* *
*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 General Public License for more details. *
* *
*You should have received a copy of the GNU General Public License *
*along with this program. If not, see <http://www.gnu.org/licenses/>.*
***********************************************************************/
#ifndef KEYBOARD_H_INCLUDED
#define KEYBOARD_H_INCLUDED
#include <gtk/gtk.h>
GtkWidget *new_keyboard (GtkWidget *label);
#endif // KEYBOARD_H_INCLUDED
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]